net/bnxt: refactor the query stats
[dpdk.git] / drivers / net / bnxt / bnxt.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_H_
35 #define _BNXT_H_
36
37 #include <inttypes.h>
38 #include <stdbool.h>
39 #include <sys/queue.h>
40
41 #include <rte_ethdev.h>
42 #include <rte_memory.h>
43 #include <rte_lcore.h>
44 #include <rte_spinlock.h>
45
46 #include "bnxt_cpr.h"
47
48 #define BNXT_MAX_MTU            9500
49 #define VLAN_TAG_SIZE           4
50
51 enum bnxt_hw_context {
52         HW_CONTEXT_NONE     = 0,
53         HW_CONTEXT_IS_RSS   = 1,
54         HW_CONTEXT_IS_COS   = 2,
55         HW_CONTEXT_IS_LB    = 3,
56 };
57
58 struct bnxt_vlan_table_entry {
59         uint16_t                tpid;
60         uint16_t                vid;
61 } __attribute__((packed));
62
63 struct bnxt_child_vf_info {
64         void                    *req_buf;
65         struct bnxt_vlan_table_entry    *vlan_table;
66         STAILQ_HEAD(, bnxt_filter_info) filter;
67         uint32_t                func_cfg_flags;
68         uint32_t                l2_rx_mask;
69         uint16_t                fid;
70         uint16_t                dflt_vlan;
71         bool                    random_mac;
72 };
73
74 struct bnxt_pf_info {
75 #define BNXT_FIRST_PF_FID       1
76 #define BNXT_MAX_VFS(bp)        (bp->pf.max_vfs)
77 #define BNXT_FIRST_VF_FID       128
78 #define BNXT_PF_RINGS_USED(bp)  bnxt_get_num_queues(bp)
79 #define BNXT_PF_RINGS_AVAIL(bp) (bp->pf.max_cp_rings - BNXT_PF_RINGS_USED(bp))
80         uint8_t                 port_id;
81         uint16_t                first_vf_id;
82         uint16_t                active_vfs;
83         uint16_t                max_vfs;
84         uint32_t                func_cfg_flags;
85         void                    *vf_req_buf;
86         phys_addr_t             vf_req_buf_dma_addr;
87         uint32_t                vf_req_fwd[8];
88         uint16_t                total_vnics;
89         struct bnxt_child_vf_info       *vf_info;
90 #define BNXT_EVB_MODE_NONE      0
91 #define BNXT_EVB_MODE_VEB       1
92 #define BNXT_EVB_MODE_VEPA      2
93         uint8_t                 evb_mode;
94 };
95
96 /* Max wait time is 10 * 100ms = 1s */
97 #define BNXT_LINK_WAIT_CNT      10
98 #define BNXT_LINK_WAIT_INTERVAL 100
99 struct bnxt_link_info {
100         uint32_t                phy_flags;
101         uint8_t                 mac_type;
102         uint8_t                 phy_link_status;
103         uint8_t                 loop_back;
104         uint8_t                 link_up;
105         uint8_t                 duplex;
106         uint8_t                 pause;
107         uint8_t                 force_pause;
108         uint8_t                 auto_pause;
109         uint8_t                 auto_mode;
110 #define PHY_VER_LEN             3
111         uint8_t                 phy_ver[PHY_VER_LEN];
112         uint16_t                link_speed;
113         uint16_t                support_speeds;
114         uint16_t                auto_link_speed;
115         uint16_t                auto_link_speed_mask;
116         uint32_t                preemphasis;
117 };
118
119 #define BNXT_COS_QUEUE_COUNT    8
120 struct bnxt_cos_queue_info {
121         uint8_t id;
122         uint8_t profile;
123 };
124
125 struct bnxt {
126         void                            *bar0;
127
128         struct rte_eth_dev              *eth_dev;
129         struct rte_pci_device           *pdev;
130
131         uint32_t                flags;
132 #define BNXT_FLAG_REGISTERED    (1 << 0)
133 #define BNXT_FLAG_VF            (1 << 1)
134 #define BNXT_FLAG_PORT_STATS    (1 << 2)
135 #define BNXT_FLAG_JUMBO         (1 << 3)
136 #define BNXT_PF(bp)             (!((bp)->flags & BNXT_FLAG_VF))
137 #define BNXT_VF(bp)             ((bp)->flags & BNXT_FLAG_VF)
138 #define BNXT_NPAR_ENABLED(bp)   ((bp)->port_partition_type)
139 #define BNXT_NPAR_PF(bp)        (BNXT_PF(bp) && BNXT_NPAR_ENABLED(bp))
140
141         unsigned int            rx_nr_rings;
142         unsigned int            rx_cp_nr_rings;
143         struct bnxt_rx_queue **rx_queues;
144         const void              *rx_mem_zone;
145         struct rx_port_stats    *hw_rx_port_stats;
146         phys_addr_t             hw_rx_port_stats_map;
147
148         unsigned int            tx_nr_rings;
149         unsigned int            tx_cp_nr_rings;
150         struct bnxt_tx_queue **tx_queues;
151         const void              *tx_mem_zone;
152         struct tx_port_stats    *hw_tx_port_stats;
153         phys_addr_t             hw_tx_port_stats_map;
154
155         /* Default completion ring */
156         struct bnxt_cp_ring_info        *def_cp_ring;
157         uint32_t                max_ring_grps;
158         struct bnxt_ring_grp_info       *grp_info;
159
160         unsigned int            nr_vnics;
161
162         struct bnxt_vnic_info   *vnic_info;
163         STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;
164
165         struct bnxt_filter_info *filter_info;
166         STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
167
168         /* VNIC pointer for flow filter (VMDq) pools */
169 #define MAX_FF_POOLS    ETH_64_POOLS
170         STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
171
172         struct bnxt_irq         *irq_tbl;
173
174 #define MAX_NUM_MAC_ADDR        32
175         uint8_t                 mac_addr[ETHER_ADDR_LEN];
176
177         uint16_t                        hwrm_cmd_seq;
178         void                            *hwrm_cmd_resp_addr;
179         phys_addr_t                     hwrm_cmd_resp_dma_addr;
180         rte_spinlock_t                  hwrm_lock;
181         uint16_t                        max_req_len;
182         uint16_t                        max_resp_len;
183
184         struct bnxt_link_info   link_info;
185         struct bnxt_cos_queue_info      cos_queue[BNXT_COS_QUEUE_COUNT];
186
187         uint16_t                fw_fid;
188         uint8_t                 dflt_mac_addr[ETHER_ADDR_LEN];
189         uint16_t                max_rsscos_ctx;
190         uint16_t                max_cp_rings;
191         uint16_t                max_tx_rings;
192         uint16_t                max_rx_rings;
193         uint16_t                max_l2_ctx;
194         uint16_t                max_vnics;
195         uint16_t                max_stat_ctx;
196         uint16_t                vlan;
197         struct bnxt_pf_info             pf;
198         uint8_t                 port_partition_type;
199         uint8_t                 dev_stopped;
200         uint8_t                 vxlan_port_cnt;
201         uint8_t                 geneve_port_cnt;
202         uint16_t                vxlan_port;
203         uint16_t                geneve_port;
204         uint16_t                vxlan_fw_dst_port_id;
205         uint16_t                geneve_fw_dst_port_id;
206         uint32_t                fw_ver;
207         rte_atomic64_t          rx_mbuf_alloc_fail;
208 };
209
210 /*
211  * Response sent back to the caller after callback
212  */
213 enum rte_pmd_bnxt_mb_event_rsp {
214         RTE_PMD_BNXT_MB_EVENT_NOOP_ACK,  /**< skip mbox request and ACK */
215         RTE_PMD_BNXT_MB_EVENT_NOOP_NACK, /**< skip mbox request and NACK */
216         RTE_PMD_BNXT_MB_EVENT_PROCEED,  /**< proceed with mbox request  */
217         RTE_PMD_BNXT_MB_EVENT_MAX       /**< max value of this enum */
218 };
219
220 /* mailbox message types */
221 #define BNXT_VF_RESET                   0x01 /* VF requests reset */
222 #define BNXT_VF_SET_MAC_ADDR    0x02 /* VF requests PF to set MAC addr */
223 #define BNXT_VF_SET_VLAN                0x03 /* VF requests PF to set VLAN */
224 #define BNXT_VF_SET_MTU                 0x04 /* VF requests PF to set MTU */
225 #define BNXT_VF_SET_MRU                 0x05 /* VF requests PF to set MRU */
226
227 /*
228  * Data sent to the caller when the callback is executed.
229  */
230 struct rte_pmd_bnxt_mb_event_param {
231         uint16_t vf_id; /* Virtual Function number */
232         int     retval; /* return value */
233         void    *msg;   /* pointer to message */
234 };
235
236 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete);
237 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg);
238
239 #define RX_PROD_AGG_BD_TYPE_RX_PROD_AGG         0x6
240 #endif