New upstream version 17.11.1
[deb_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_pci.h>
42 #include <rte_bus_pci.h>
43 #include <rte_ethdev.h>
44 #include <rte_memory.h>
45 #include <rte_lcore.h>
46 #include <rte_spinlock.h>
47
48 #include "bnxt_cpr.h"
49
50 #define BNXT_MAX_MTU            9500
51 #define VLAN_TAG_SIZE           4
52 #define BNXT_MAX_LED            4
53
54 struct bnxt_led_info {
55         uint8_t      led_id;
56         uint8_t      led_type;
57         uint8_t      led_group_id;
58         uint8_t      unused;
59         uint16_t  led_state_caps;
60 #define BNXT_LED_ALT_BLINK_CAP(x)       ((x) &  \
61         rte_cpu_to_le_16(HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_BLINKALT))
62
63         uint16_t  led_color_caps;
64 };
65
66 struct bnxt_led_cfg {
67         uint8_t led_id;
68         uint8_t led_state;
69         uint8_t led_color;
70         uint8_t unused;
71         uint16_t led_blink_on;
72         uint16_t led_blink_off;
73         uint8_t led_group_id;
74         uint8_t rsvd;
75 };
76
77 #define BNXT_LED_DFLT_ENA                               \
78         (HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_ID |             \
79          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_STATE |          \
80          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_BLINK_ON |       \
81          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_BLINK_OFF |      \
82          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_GROUP_ID)
83
84 #define BNXT_LED_DFLT_ENA_SHIFT         6
85
86 #define BNXT_LED_DFLT_ENABLES(x)                        \
87         rte_cpu_to_le_32(BNXT_LED_DFLT_ENA << (BNXT_LED_DFLT_ENA_SHIFT * (x)))
88
89 enum bnxt_hw_context {
90         HW_CONTEXT_NONE     = 0,
91         HW_CONTEXT_IS_RSS   = 1,
92         HW_CONTEXT_IS_COS   = 2,
93         HW_CONTEXT_IS_LB    = 3,
94 };
95
96 struct bnxt_vlan_table_entry {
97         uint16_t                tpid;
98         uint16_t                vid;
99 } __attribute__((packed));
100
101 struct bnxt_vlan_antispoof_table_entry {
102         uint16_t                tpid;
103         uint16_t                vid;
104         uint16_t                mask;
105 } __attribute__((packed));
106
107 struct bnxt_child_vf_info {
108         void                    *req_buf;
109         struct bnxt_vlan_table_entry    *vlan_table;
110         struct bnxt_vlan_antispoof_table_entry  *vlan_as_table;
111         STAILQ_HEAD(, bnxt_filter_info) filter;
112         uint32_t                func_cfg_flags;
113         uint32_t                l2_rx_mask;
114         uint16_t                fid;
115         uint16_t                max_tx_rate;
116         uint16_t                dflt_vlan;
117         uint16_t                vlan_count;
118         uint8_t                 mac_spoof_en;
119         uint8_t                 vlan_spoof_en;
120         bool                    random_mac;
121         bool                    persist_stats;
122 };
123
124 struct bnxt_pf_info {
125 #define BNXT_FIRST_PF_FID       1
126 #define BNXT_MAX_VFS(bp)        (bp->pf.max_vfs)
127 #define BNXT_FIRST_VF_FID       128
128 #define BNXT_PF_RINGS_USED(bp)  bnxt_get_num_queues(bp)
129 #define BNXT_PF_RINGS_AVAIL(bp) (bp->pf.max_cp_rings - BNXT_PF_RINGS_USED(bp))
130         uint16_t                port_id;
131         uint16_t                first_vf_id;
132         uint16_t                active_vfs;
133         uint16_t                max_vfs;
134         uint32_t                func_cfg_flags;
135         void                    *vf_req_buf;
136         rte_iova_t              vf_req_buf_dma_addr;
137         uint32_t                vf_req_fwd[8];
138         uint16_t                total_vnics;
139         struct bnxt_child_vf_info       *vf_info;
140 #define BNXT_EVB_MODE_NONE      0
141 #define BNXT_EVB_MODE_VEB       1
142 #define BNXT_EVB_MODE_VEPA      2
143         uint8_t                 evb_mode;
144 };
145
146 /* Max wait time is 10 * 100ms = 1s */
147 #define BNXT_LINK_WAIT_CNT      10
148 #define BNXT_LINK_WAIT_INTERVAL 100
149 struct bnxt_link_info {
150         uint32_t                phy_flags;
151         uint8_t                 mac_type;
152         uint8_t                 phy_link_status;
153         uint8_t                 loop_back;
154         uint8_t                 link_up;
155         uint8_t                 duplex;
156         uint8_t                 pause;
157         uint8_t                 force_pause;
158         uint8_t                 auto_pause;
159         uint8_t                 auto_mode;
160 #define PHY_VER_LEN             3
161         uint8_t                 phy_ver[PHY_VER_LEN];
162         uint16_t                link_speed;
163         uint16_t                support_speeds;
164         uint16_t                auto_link_speed;
165         uint16_t                force_link_speed;
166         uint16_t                auto_link_speed_mask;
167         uint32_t                preemphasis;
168         uint8_t                 phy_type;
169         uint8_t                 media_type;
170 };
171
172 #define BNXT_COS_QUEUE_COUNT    8
173 struct bnxt_cos_queue_info {
174         uint8_t id;
175         uint8_t profile;
176 };
177
178 struct rte_flow {
179         STAILQ_ENTRY(rte_flow) next;
180         struct bnxt_filter_info *filter;
181         struct bnxt_vnic_info   *vnic;
182 };
183
184 #define BNXT_HWRM_SHORT_REQ_LEN         sizeof(struct hwrm_short_input)
185 struct bnxt {
186         void                            *bar0;
187
188         struct rte_eth_dev              *eth_dev;
189         struct rte_eth_rss_conf         rss_conf;
190         struct rte_pci_device           *pdev;
191
192         uint32_t                flags;
193 #define BNXT_FLAG_REGISTERED    (1 << 0)
194 #define BNXT_FLAG_VF            (1 << 1)
195 #define BNXT_FLAG_PORT_STATS    (1 << 2)
196 #define BNXT_FLAG_JUMBO         (1 << 3)
197 #define BNXT_FLAG_SHORT_CMD     (1 << 4)
198 #define BNXT_FLAG_UPDATE_HASH   (1 << 5)
199 #define BNXT_PF(bp)             (!((bp)->flags & BNXT_FLAG_VF))
200 #define BNXT_VF(bp)             ((bp)->flags & BNXT_FLAG_VF)
201 #define BNXT_NPAR_ENABLED(bp)   ((bp)->port_partition_type)
202 #define BNXT_NPAR_PF(bp)        (BNXT_PF(bp) && BNXT_NPAR_ENABLED(bp))
203
204         unsigned int            rx_nr_rings;
205         unsigned int            rx_cp_nr_rings;
206         struct bnxt_rx_queue **rx_queues;
207         const void              *rx_mem_zone;
208         struct rx_port_stats    *hw_rx_port_stats;
209         rte_iova_t              hw_rx_port_stats_map;
210
211         unsigned int            tx_nr_rings;
212         unsigned int            tx_cp_nr_rings;
213         struct bnxt_tx_queue **tx_queues;
214         const void              *tx_mem_zone;
215         struct tx_port_stats    *hw_tx_port_stats;
216         rte_iova_t              hw_tx_port_stats_map;
217
218         /* Default completion ring */
219         struct bnxt_cp_ring_info        *def_cp_ring;
220         uint32_t                max_ring_grps;
221         struct bnxt_ring_grp_info       *grp_info;
222
223         unsigned int            nr_vnics;
224
225         struct bnxt_vnic_info   *vnic_info;
226         STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;
227
228         struct bnxt_filter_info *filter_info;
229         STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
230
231         /* VNIC pointer for flow filter (VMDq) pools */
232 #define MAX_FF_POOLS    256
233         STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
234
235         struct bnxt_irq         *irq_tbl;
236
237 #define MAX_NUM_MAC_ADDR        32
238         uint8_t                 mac_addr[ETHER_ADDR_LEN];
239
240         uint16_t                        hwrm_cmd_seq;
241         void                            *hwrm_cmd_resp_addr;
242         rte_iova_t                      hwrm_cmd_resp_dma_addr;
243         void                            *hwrm_short_cmd_req_addr;
244         rte_iova_t                      hwrm_short_cmd_req_dma_addr;
245         rte_spinlock_t                  hwrm_lock;
246         uint16_t                        max_req_len;
247         uint16_t                        max_resp_len;
248
249         struct bnxt_link_info   link_info;
250         struct bnxt_cos_queue_info      cos_queue[BNXT_COS_QUEUE_COUNT];
251
252         uint16_t                fw_fid;
253         uint8_t                 dflt_mac_addr[ETHER_ADDR_LEN];
254         uint16_t                max_rsscos_ctx;
255         uint16_t                max_cp_rings;
256         uint16_t                max_tx_rings;
257         uint16_t                max_rx_rings;
258         uint16_t                max_l2_ctx;
259         uint16_t                max_vnics;
260         uint16_t                max_stat_ctx;
261         uint16_t                vlan;
262         struct bnxt_pf_info             pf;
263         uint8_t                 port_partition_type;
264         uint8_t                 dev_stopped;
265         uint8_t                 vxlan_port_cnt;
266         uint8_t                 geneve_port_cnt;
267         uint16_t                vxlan_port;
268         uint16_t                geneve_port;
269         uint16_t                vxlan_fw_dst_port_id;
270         uint16_t                geneve_fw_dst_port_id;
271         uint32_t                fw_ver;
272         rte_atomic64_t          rx_mbuf_alloc_fail;
273
274         struct bnxt_led_info    leds[BNXT_MAX_LED];
275         uint8_t                 num_leds;
276 };
277
278 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete);
279 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg);
280
281 #define RX_PROD_AGG_BD_TYPE_RX_PROD_AGG         0x6
282
283 bool is_bnxt_supported(struct rte_eth_dev *dev);
284 extern const struct rte_flow_ops bnxt_flow_ops;
285 #endif