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