New upstream version 18.02
[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_driver.h>
44 #include <rte_memory.h>
45 #include <rte_lcore.h>
46 #include <rte_spinlock.h>
47 #include <rte_time.h>
48
49 #include "bnxt_cpr.h"
50
51 #define BNXT_MAX_MTU            9500
52 #define VLAN_TAG_SIZE           4
53 #define BNXT_MAX_LED            4
54
55 struct bnxt_led_info {
56         uint8_t      led_id;
57         uint8_t      led_type;
58         uint8_t      led_group_id;
59         uint8_t      unused;
60         uint16_t  led_state_caps;
61 #define BNXT_LED_ALT_BLINK_CAP(x)       ((x) &  \
62         rte_cpu_to_le_16(HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_BLINKALT))
63
64         uint16_t  led_color_caps;
65 };
66
67 struct bnxt_led_cfg {
68         uint8_t led_id;
69         uint8_t led_state;
70         uint8_t led_color;
71         uint8_t unused;
72         uint16_t led_blink_on;
73         uint16_t led_blink_off;
74         uint8_t led_group_id;
75         uint8_t rsvd;
76 };
77
78 #define BNXT_LED_DFLT_ENA                               \
79         (HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_ID |             \
80          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_STATE |          \
81          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_BLINK_ON |       \
82          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_BLINK_OFF |      \
83          HWRM_PORT_LED_CFG_INPUT_ENABLES_LED0_GROUP_ID)
84
85 #define BNXT_LED_DFLT_ENA_SHIFT         6
86
87 #define BNXT_LED_DFLT_ENABLES(x)                        \
88         rte_cpu_to_le_32(BNXT_LED_DFLT_ENA << (BNXT_LED_DFLT_ENA_SHIFT * (x)))
89
90 enum bnxt_hw_context {
91         HW_CONTEXT_NONE     = 0,
92         HW_CONTEXT_IS_RSS   = 1,
93         HW_CONTEXT_IS_COS   = 2,
94         HW_CONTEXT_IS_LB    = 3,
95 };
96
97 struct bnxt_vlan_table_entry {
98         uint16_t                tpid;
99         uint16_t                vid;
100 } __attribute__((packed));
101
102 struct bnxt_vlan_antispoof_table_entry {
103         uint16_t                tpid;
104         uint16_t                vid;
105         uint16_t                mask;
106 } __attribute__((packed));
107
108 struct bnxt_child_vf_info {
109         void                    *req_buf;
110         struct bnxt_vlan_table_entry    *vlan_table;
111         struct bnxt_vlan_antispoof_table_entry  *vlan_as_table;
112         STAILQ_HEAD(, bnxt_filter_info) filter;
113         uint32_t                func_cfg_flags;
114         uint32_t                l2_rx_mask;
115         uint16_t                fid;
116         uint16_t                max_tx_rate;
117         uint16_t                dflt_vlan;
118         uint16_t                vlan_count;
119         uint8_t                 mac_spoof_en;
120         uint8_t                 vlan_spoof_en;
121         bool                    random_mac;
122         bool                    persist_stats;
123 };
124
125 struct bnxt_pf_info {
126 #define BNXT_FIRST_PF_FID       1
127 #define BNXT_MAX_VFS(bp)        (bp->pf.max_vfs)
128 #define BNXT_FIRST_VF_FID       128
129 #define BNXT_PF_RINGS_USED(bp)  bnxt_get_num_queues(bp)
130 #define BNXT_PF_RINGS_AVAIL(bp) (bp->pf.max_cp_rings - BNXT_PF_RINGS_USED(bp))
131         uint16_t                port_id;
132         uint16_t                first_vf_id;
133         uint16_t                active_vfs;
134         uint16_t                max_vfs;
135         uint32_t                func_cfg_flags;
136         void                    *vf_req_buf;
137         rte_iova_t              vf_req_buf_dma_addr;
138         uint32_t                vf_req_fwd[8];
139         uint16_t                total_vnics;
140         struct bnxt_child_vf_info       *vf_info;
141 #define BNXT_EVB_MODE_NONE      0
142 #define BNXT_EVB_MODE_VEB       1
143 #define BNXT_EVB_MODE_VEPA      2
144         uint8_t                 evb_mode;
145 };
146
147 /* Max wait time is 10 * 100ms = 1s */
148 #define BNXT_LINK_WAIT_CNT      10
149 #define BNXT_LINK_WAIT_INTERVAL 100
150 struct bnxt_link_info {
151         uint32_t                phy_flags;
152         uint8_t                 mac_type;
153         uint8_t                 phy_link_status;
154         uint8_t                 loop_back;
155         uint8_t                 link_up;
156         uint8_t                 duplex;
157         uint8_t                 pause;
158         uint8_t                 force_pause;
159         uint8_t                 auto_pause;
160         uint8_t                 auto_mode;
161 #define PHY_VER_LEN             3
162         uint8_t                 phy_ver[PHY_VER_LEN];
163         uint16_t                link_speed;
164         uint16_t                support_speeds;
165         uint16_t                auto_link_speed;
166         uint16_t                force_link_speed;
167         uint16_t                auto_link_speed_mask;
168         uint32_t                preemphasis;
169         uint8_t                 phy_type;
170         uint8_t                 media_type;
171 };
172
173 #define BNXT_COS_QUEUE_COUNT    8
174 struct bnxt_cos_queue_info {
175         uint8_t id;
176         uint8_t profile;
177 };
178
179 struct rte_flow {
180         STAILQ_ENTRY(rte_flow) next;
181         struct bnxt_filter_info *filter;
182         struct bnxt_vnic_info   *vnic;
183 };
184
185 struct bnxt_ptp_cfg {
186 #define BNXT_GRCPF_REG_WINDOW_BASE_OUT  0x400
187 #define BNXT_GRCPF_REG_SYNC_TIME        0x480
188 #define BNXT_CYCLECOUNTER_MASK   0xffffffffffffffffULL
189         struct rte_timecounter      tc;
190         struct rte_timecounter      tx_tstamp_tc;
191         struct rte_timecounter      rx_tstamp_tc;
192         struct bnxt             *bp;
193 #define BNXT_MAX_TX_TS  1
194         uint16_t                        rxctl;
195 #define BNXT_PTP_MSG_SYNC                       (1 << 0)
196 #define BNXT_PTP_MSG_DELAY_REQ                  (1 << 1)
197 #define BNXT_PTP_MSG_PDELAY_REQ                 (1 << 2)
198 #define BNXT_PTP_MSG_PDELAY_RESP                (1 << 3)
199 #define BNXT_PTP_MSG_FOLLOW_UP                  (1 << 8)
200 #define BNXT_PTP_MSG_DELAY_RESP                 (1 << 9)
201 #define BNXT_PTP_MSG_PDELAY_RESP_FOLLOW_UP      (1 << 10)
202 #define BNXT_PTP_MSG_ANNOUNCE                   (1 << 11)
203 #define BNXT_PTP_MSG_SIGNALING                  (1 << 12)
204 #define BNXT_PTP_MSG_MANAGEMENT                 (1 << 13)
205 #define BNXT_PTP_MSG_EVENTS             (BNXT_PTP_MSG_SYNC |            \
206                                          BNXT_PTP_MSG_DELAY_REQ |       \
207                                          BNXT_PTP_MSG_PDELAY_REQ |      \
208                                          BNXT_PTP_MSG_PDELAY_RESP)
209         uint8_t                 tx_tstamp_en:1;
210         int                     rx_filter;
211
212 #define BNXT_PTP_RX_TS_L        0
213 #define BNXT_PTP_RX_TS_H        1
214 #define BNXT_PTP_RX_SEQ         2
215 #define BNXT_PTP_RX_FIFO        3
216 #define BNXT_PTP_RX_FIFO_PENDING 0x1
217 #define BNXT_PTP_RX_FIFO_ADV    4
218 #define BNXT_PTP_RX_REGS        5
219
220 #define BNXT_PTP_TX_TS_L        0
221 #define BNXT_PTP_TX_TS_H        1
222 #define BNXT_PTP_TX_SEQ         2
223 #define BNXT_PTP_TX_FIFO        3
224 #define BNXT_PTP_TX_FIFO_EMPTY   0x2
225 #define BNXT_PTP_TX_REGS        4
226         uint32_t                        rx_regs[BNXT_PTP_RX_REGS];
227         uint32_t                        rx_mapped_regs[BNXT_PTP_RX_REGS];
228         uint32_t                        tx_regs[BNXT_PTP_TX_REGS];
229         uint32_t                        tx_mapped_regs[BNXT_PTP_TX_REGS];
230 };
231
232 #define BNXT_HWRM_SHORT_REQ_LEN         sizeof(struct hwrm_short_input)
233 struct bnxt {
234         void                            *bar0;
235
236         struct rte_eth_dev              *eth_dev;
237         struct rte_eth_rss_conf         rss_conf;
238         struct rte_pci_device           *pdev;
239
240         uint32_t                flags;
241 #define BNXT_FLAG_REGISTERED    (1 << 0)
242 #define BNXT_FLAG_VF            (1 << 1)
243 #define BNXT_FLAG_PORT_STATS    (1 << 2)
244 #define BNXT_FLAG_JUMBO         (1 << 3)
245 #define BNXT_FLAG_SHORT_CMD     (1 << 4)
246 #define BNXT_FLAG_UPDATE_HASH   (1 << 5)
247 #define BNXT_FLAG_PTP_SUPPORTED (1 << 6)
248 #define BNXT_FLAG_MULTI_HOST    (1 << 7)
249 #define BNXT_FLAG_INIT_DONE     (1 << 31)
250 #define BNXT_PF(bp)             (!((bp)->flags & BNXT_FLAG_VF))
251 #define BNXT_VF(bp)             ((bp)->flags & BNXT_FLAG_VF)
252 #define BNXT_NPAR(bp)           ((bp)->port_partition_type)
253 #define BNXT_MH(bp)             ((bp)->flags & BNXT_FLAG_MULTI_HOST)
254 #define BNXT_SINGLE_PF(bp)      (BNXT_PF(bp) && !BNXT_NPAR(bp) && !BNXT_MH(bp))
255
256         unsigned int            rx_nr_rings;
257         unsigned int            rx_cp_nr_rings;
258         struct bnxt_rx_queue **rx_queues;
259         const void              *rx_mem_zone;
260         struct rx_port_stats    *hw_rx_port_stats;
261         rte_iova_t              hw_rx_port_stats_map;
262
263         unsigned int            tx_nr_rings;
264         unsigned int            tx_cp_nr_rings;
265         struct bnxt_tx_queue **tx_queues;
266         const void              *tx_mem_zone;
267         struct tx_port_stats    *hw_tx_port_stats;
268         rte_iova_t              hw_tx_port_stats_map;
269
270         /* Default completion ring */
271         struct bnxt_cp_ring_info        *def_cp_ring;
272         uint32_t                max_ring_grps;
273         struct bnxt_ring_grp_info       *grp_info;
274
275         unsigned int            nr_vnics;
276
277         struct bnxt_vnic_info   *vnic_info;
278         STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;
279
280         struct bnxt_filter_info *filter_info;
281         STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
282
283         /* VNIC pointer for flow filter (VMDq) pools */
284 #define MAX_FF_POOLS    256
285         STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
286
287         struct bnxt_irq         *irq_tbl;
288
289 #define MAX_NUM_MAC_ADDR        32
290         uint8_t                 mac_addr[ETHER_ADDR_LEN];
291
292         uint16_t                        hwrm_cmd_seq;
293         void                            *hwrm_cmd_resp_addr;
294         rte_iova_t                      hwrm_cmd_resp_dma_addr;
295         void                            *hwrm_short_cmd_req_addr;
296         rte_iova_t                      hwrm_short_cmd_req_dma_addr;
297         rte_spinlock_t                  hwrm_lock;
298         uint16_t                        max_req_len;
299         uint16_t                        max_resp_len;
300
301         struct bnxt_link_info   link_info;
302         struct bnxt_cos_queue_info      cos_queue[BNXT_COS_QUEUE_COUNT];
303
304         uint16_t                fw_fid;
305         uint8_t                 dflt_mac_addr[ETHER_ADDR_LEN];
306         uint16_t                max_rsscos_ctx;
307         uint16_t                max_cp_rings;
308         uint16_t                max_tx_rings;
309         uint16_t                max_rx_rings;
310         uint16_t                max_l2_ctx;
311         uint16_t                max_vnics;
312         uint16_t                max_stat_ctx;
313         uint16_t                vlan;
314         struct bnxt_pf_info             pf;
315         uint8_t                 port_partition_type;
316         uint8_t                 dev_stopped;
317         uint8_t                 vxlan_port_cnt;
318         uint8_t                 geneve_port_cnt;
319         uint16_t                vxlan_port;
320         uint16_t                geneve_port;
321         uint16_t                vxlan_fw_dst_port_id;
322         uint16_t                geneve_fw_dst_port_id;
323         uint32_t                fw_ver;
324         rte_atomic64_t          rx_mbuf_alloc_fail;
325
326         struct bnxt_led_info    leds[BNXT_MAX_LED];
327         uint8_t                 num_leds;
328         struct bnxt_ptp_cfg     *ptp_cfg;
329 };
330
331 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete);
332 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg);
333
334 #define RX_PROD_AGG_BD_TYPE_RX_PROD_AGG         0x6
335
336 bool is_bnxt_supported(struct rte_eth_dev *dev);
337 extern const struct rte_flow_ops bnxt_flow_ops;
338
339 extern int bnxt_logtype_driver;
340 #define PMD_DRV_LOG_RAW(level, fmt, args...) \
341         rte_log(RTE_LOG_ ## level, bnxt_logtype_driver, "%s(): " fmt, \
342                 __func__, ## args)
343
344 #define PMD_DRV_LOG(level, fmt, args...) \
345         PMD_DRV_LOG_RAW(level, fmt, ## args)
346 #endif