New upstream version 16.11.7
[deb_dpdk.git] / drivers / net / bnxt / bnxt_ring.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Broadcom Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _BNXT_RING_H_
35 #define _BNXT_RING_H_
36
37 #include <inttypes.h>
38
39 #include <rte_memory.h>
40
41 #define RING_NEXT(ring, idx)            (((idx) + 1) & (ring)->ring_mask)
42
43 #define RTE_MBUF_DATA_DMA_ADDR(mb) \
44         ((uint64_t)((mb)->buf_physaddr + (mb)->data_off))
45
46 #define DB_IDX_MASK                                             0xffffff
47 #define DB_IDX_VALID                                            (0x1 << 26)
48 #define DB_IRQ_DIS                                              (0x1 << 27)
49 #define DB_KEY_TX                                               (0x0 << 28)
50 #define DB_KEY_RX                                               (0x1 << 28)
51 #define DB_KEY_CP                                               (0x2 << 28)
52 #define DB_KEY_ST                                               (0x3 << 28)
53 #define DB_KEY_TX_PUSH                                          (0x4 << 28)
54 #define DB_LONG_TX_PUSH                                         (0x2 << 24)
55
56 #define DEFAULT_CP_RING_SIZE    256
57 #define DEFAULT_RX_RING_SIZE    256
58 #define DEFAULT_TX_RING_SIZE    256
59
60 #define MAX_TPA         128
61
62 /* These assume 4k pages */
63 #define MAX_RX_DESC_CNT (8 * 1024)
64 #define MAX_TX_DESC_CNT (4 * 1024)
65 #define MAX_CP_DESC_CNT (16 * 1024)
66
67 #define INVALID_HW_RING_ID      ((uint16_t)-1)
68 #define INVALID_STATS_CTX_ID    ((uint16_t)-1)
69
70 struct bnxt_ring {
71         void                    *bd;
72         phys_addr_t             bd_dma;
73         uint32_t                ring_size;
74         uint32_t                ring_mask;
75
76         int                     vmem_size;
77         void                    **vmem;
78
79         uint16_t                fw_ring_id; /* Ring id filled by Chimp FW */
80         const void              *mem_zone;
81 };
82
83 struct bnxt_ring_grp_info {
84         uint16_t        fw_stats_ctx;
85         uint16_t        fw_grp_id;
86         uint16_t        rx_fw_ring_id;
87         uint16_t        cp_fw_ring_id;
88         uint16_t        ag_fw_ring_id;
89 };
90
91 struct bnxt;
92 struct bnxt_tx_ring_info;
93 struct bnxt_rx_ring_info;
94 struct bnxt_cp_ring_info;
95 void bnxt_free_ring(struct bnxt_ring *ring);
96 int bnxt_init_ring_grps(struct bnxt *bp);
97 int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
98                             struct bnxt_tx_queue *txq,
99                             struct bnxt_rx_queue *rxq,
100                             struct bnxt_cp_ring_info *cp_ring_info,
101                             const char *suffix);
102 int bnxt_alloc_hwrm_rings(struct bnxt *bp);
103
104 #endif