1 /* Broadcom NetXtreme-C/E network driver.
2  *
3  * Copyright (c) 2014-2016 Broadcom Corporation
4  * Copyright (c) 2016-2018 Broadcom Limited
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation.
9  */
10 
11 #ifndef BNXT_H
12 #define BNXT_H
13 
14 #define DRV_MODULE_NAME		"bnxt_en"
15 #define DRV_MODULE_VERSION	"1.9.1"
16 
17 #define DRV_VER_MAJ	1
18 #define DRV_VER_MIN	9
19 #define DRV_VER_UPD	1
20 
21 #include <linux/interrupt.h>
22 #include <linux/rhashtable.h>
23 #include <net/devlink.h>
24 #include <net/dst_metadata.h>
25 #include <net/switchdev.h>
26 #include <net/xdp.h>
27 #include <linux/net_dim.h>
28 
29 struct tx_bd {
30 	__le32 tx_bd_len_flags_type;
31 	#define TX_BD_TYPE					(0x3f << 0)
32 	 #define TX_BD_TYPE_SHORT_TX_BD				 (0x00 << 0)
33 	 #define TX_BD_TYPE_LONG_TX_BD				 (0x10 << 0)
34 	#define TX_BD_FLAGS_PACKET_END				(1 << 6)
35 	#define TX_BD_FLAGS_NO_CMPL				(1 << 7)
36 	#define TX_BD_FLAGS_BD_CNT				(0x1f << 8)
37 	 #define TX_BD_FLAGS_BD_CNT_SHIFT			 8
38 	#define TX_BD_FLAGS_LHINT				(3 << 13)
39 	 #define TX_BD_FLAGS_LHINT_SHIFT			 13
40 	 #define TX_BD_FLAGS_LHINT_512_AND_SMALLER		 (0 << 13)
41 	 #define TX_BD_FLAGS_LHINT_512_TO_1023			 (1 << 13)
42 	 #define TX_BD_FLAGS_LHINT_1024_TO_2047			 (2 << 13)
43 	 #define TX_BD_FLAGS_LHINT_2048_AND_LARGER		 (3 << 13)
44 	#define TX_BD_FLAGS_COAL_NOW				(1 << 15)
45 	#define TX_BD_LEN					(0xffff << 16)
46 	 #define TX_BD_LEN_SHIFT				 16
47 
48 	u32 tx_bd_opaque;
49 	__le64 tx_bd_haddr;
50 } __packed;
51 
52 struct tx_bd_ext {
53 	__le32 tx_bd_hsize_lflags;
54 	#define TX_BD_FLAGS_TCP_UDP_CHKSUM			(1 << 0)
55 	#define TX_BD_FLAGS_IP_CKSUM				(1 << 1)
56 	#define TX_BD_FLAGS_NO_CRC				(1 << 2)
57 	#define TX_BD_FLAGS_STAMP				(1 << 3)
58 	#define TX_BD_FLAGS_T_IP_CHKSUM				(1 << 4)
59 	#define TX_BD_FLAGS_LSO					(1 << 5)
60 	#define TX_BD_FLAGS_IPID_FMT				(1 << 6)
61 	#define TX_BD_FLAGS_T_IPID				(1 << 7)
62 	#define TX_BD_HSIZE					(0xff << 16)
63 	 #define TX_BD_HSIZE_SHIFT				 16
64 
65 	__le32 tx_bd_mss;
66 	__le32 tx_bd_cfa_action;
67 	#define TX_BD_CFA_ACTION				(0xffff << 16)
68 	 #define TX_BD_CFA_ACTION_SHIFT				 16
69 
70 	__le32 tx_bd_cfa_meta;
71 	#define TX_BD_CFA_META_MASK                             0xfffffff
72 	#define TX_BD_CFA_META_VID_MASK                         0xfff
73 	#define TX_BD_CFA_META_PRI_MASK                         (0xf << 12)
74 	 #define TX_BD_CFA_META_PRI_SHIFT                        12
75 	#define TX_BD_CFA_META_TPID_MASK                        (3 << 16)
76 	 #define TX_BD_CFA_META_TPID_SHIFT                       16
77 	#define TX_BD_CFA_META_KEY                              (0xf << 28)
78 	 #define TX_BD_CFA_META_KEY_SHIFT			 28
79 	#define TX_BD_CFA_META_KEY_VLAN                         (1 << 28)
80 };
81 
82 struct rx_bd {
83 	__le32 rx_bd_len_flags_type;
84 	#define RX_BD_TYPE					(0x3f << 0)
85 	 #define RX_BD_TYPE_RX_PACKET_BD			 0x4
86 	 #define RX_BD_TYPE_RX_BUFFER_BD			 0x5
87 	 #define RX_BD_TYPE_RX_AGG_BD				 0x6
88 	 #define RX_BD_TYPE_16B_BD_SIZE				 (0 << 4)
89 	 #define RX_BD_TYPE_32B_BD_SIZE				 (1 << 4)
90 	 #define RX_BD_TYPE_48B_BD_SIZE				 (2 << 4)
91 	 #define RX_BD_TYPE_64B_BD_SIZE				 (3 << 4)
92 	#define RX_BD_FLAGS_SOP					(1 << 6)
93 	#define RX_BD_FLAGS_EOP					(1 << 7)
94 	#define RX_BD_FLAGS_BUFFERS				(3 << 8)
95 	 #define RX_BD_FLAGS_1_BUFFER_PACKET			 (0 << 8)
96 	 #define RX_BD_FLAGS_2_BUFFER_PACKET			 (1 << 8)
97 	 #define RX_BD_FLAGS_3_BUFFER_PACKET			 (2 << 8)
98 	 #define RX_BD_FLAGS_4_BUFFER_PACKET			 (3 << 8)
99 	#define RX_BD_LEN					(0xffff << 16)
100 	 #define RX_BD_LEN_SHIFT				 16
101 
102 	u32 rx_bd_opaque;
103 	__le64 rx_bd_haddr;
104 };
105 
106 struct tx_cmp {
107 	__le32 tx_cmp_flags_type;
108 	#define CMP_TYPE					(0x3f << 0)
109 	 #define CMP_TYPE_TX_L2_CMP				 0
110 	 #define CMP_TYPE_RX_L2_CMP				 17
111 	 #define CMP_TYPE_RX_AGG_CMP				 18
112 	 #define CMP_TYPE_RX_L2_TPA_START_CMP			 19
113 	 #define CMP_TYPE_RX_L2_TPA_END_CMP			 21
114 	 #define CMP_TYPE_STATUS_CMP				 32
115 	 #define CMP_TYPE_REMOTE_DRIVER_REQ			 34
116 	 #define CMP_TYPE_REMOTE_DRIVER_RESP			 36
117 	 #define CMP_TYPE_ERROR_STATUS				 48
118 	 #define CMPL_BASE_TYPE_STAT_EJECT			 0x1aUL
119 	 #define CMPL_BASE_TYPE_HWRM_DONE			 0x20UL
120 	 #define CMPL_BASE_TYPE_HWRM_FWD_REQ			 0x22UL
121 	 #define CMPL_BASE_TYPE_HWRM_FWD_RESP			 0x24UL
122 	 #define CMPL_BASE_TYPE_HWRM_ASYNC_EVENT		 0x2eUL
123 
124 	#define TX_CMP_FLAGS_ERROR				(1 << 6)
125 	#define TX_CMP_FLAGS_PUSH				(1 << 7)
126 
127 	u32 tx_cmp_opaque;
128 	__le32 tx_cmp_errors_v;
129 	#define TX_CMP_V					(1 << 0)
130 	#define TX_CMP_ERRORS_BUFFER_ERROR			(7 << 1)
131 	 #define TX_CMP_ERRORS_BUFFER_ERROR_NO_ERROR		 0
132 	 #define TX_CMP_ERRORS_BUFFER_ERROR_BAD_FORMAT		 2
133 	 #define TX_CMP_ERRORS_BUFFER_ERROR_INVALID_STAG	 4
134 	 #define TX_CMP_ERRORS_BUFFER_ERROR_STAG_BOUNDS		 5
135 	 #define TX_CMP_ERRORS_ZERO_LENGTH_PKT			 (1 << 4)
136 	 #define TX_CMP_ERRORS_EXCESSIVE_BD_LEN			 (1 << 5)
137 	 #define TX_CMP_ERRORS_DMA_ERROR			 (1 << 6)
138 	 #define TX_CMP_ERRORS_HINT_TOO_SHORT			 (1 << 7)
139 
140 	__le32 tx_cmp_unsed_3;
141 };
142 
143 struct rx_cmp {
144 	__le32 rx_cmp_len_flags_type;
145 	#define RX_CMP_CMP_TYPE					(0x3f << 0)
146 	#define RX_CMP_FLAGS_ERROR				(1 << 6)
147 	#define RX_CMP_FLAGS_PLACEMENT				(7 << 7)
148 	#define RX_CMP_FLAGS_RSS_VALID				(1 << 10)
149 	#define RX_CMP_FLAGS_UNUSED				(1 << 11)
150 	 #define RX_CMP_FLAGS_ITYPES_SHIFT			 12
151 	 #define RX_CMP_FLAGS_ITYPE_UNKNOWN			 (0 << 12)
152 	 #define RX_CMP_FLAGS_ITYPE_IP				 (1 << 12)
153 	 #define RX_CMP_FLAGS_ITYPE_TCP				 (2 << 12)
154 	 #define RX_CMP_FLAGS_ITYPE_UDP				 (3 << 12)
155 	 #define RX_CMP_FLAGS_ITYPE_FCOE			 (4 << 12)
156 	 #define RX_CMP_FLAGS_ITYPE_ROCE			 (5 << 12)
157 	 #define RX_CMP_FLAGS_ITYPE_PTP_WO_TS			 (8 << 12)
158 	 #define RX_CMP_FLAGS_ITYPE_PTP_W_TS			 (9 << 12)
159 	#define RX_CMP_LEN					(0xffff << 16)
160 	 #define RX_CMP_LEN_SHIFT				 16
161 
162 	u32 rx_cmp_opaque;
163 	__le32 rx_cmp_misc_v1;
164 	#define RX_CMP_V1					(1 << 0)
165 	#define RX_CMP_AGG_BUFS					(0x1f << 1)
166 	 #define RX_CMP_AGG_BUFS_SHIFT				 1
167 	#define RX_CMP_RSS_HASH_TYPE				(0x7f << 9)
168 	 #define RX_CMP_RSS_HASH_TYPE_SHIFT			 9
169 	#define RX_CMP_PAYLOAD_OFFSET				(0xff << 16)
170 	 #define RX_CMP_PAYLOAD_OFFSET_SHIFT			 16
171 
172 	__le32 rx_cmp_rss_hash;
173 };
174 
175 #define RX_CMP_HASH_VALID(rxcmp)				\
176 	((rxcmp)->rx_cmp_len_flags_type & cpu_to_le32(RX_CMP_FLAGS_RSS_VALID))
177 
178 #define RSS_PROFILE_ID_MASK	0x1f
179 
180 #define RX_CMP_HASH_TYPE(rxcmp)					\
181 	(((le32_to_cpu((rxcmp)->rx_cmp_misc_v1) & RX_CMP_RSS_HASH_TYPE) >>\
182 	  RX_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
183 
184 struct rx_cmp_ext {
185 	__le32 rx_cmp_flags2;
186 	#define RX_CMP_FLAGS2_IP_CS_CALC			0x1
187 	#define RX_CMP_FLAGS2_L4_CS_CALC			(0x1 << 1)
188 	#define RX_CMP_FLAGS2_T_IP_CS_CALC			(0x1 << 2)
189 	#define RX_CMP_FLAGS2_T_L4_CS_CALC			(0x1 << 3)
190 	#define RX_CMP_FLAGS2_META_FORMAT_VLAN			(0x1 << 4)
191 	__le32 rx_cmp_meta_data;
192 	#define RX_CMP_FLAGS2_METADATA_TCI_MASK			0xffff
193 	#define RX_CMP_FLAGS2_METADATA_VID_MASK			0xfff
194 	#define RX_CMP_FLAGS2_METADATA_TPID_MASK		0xffff0000
195 	 #define RX_CMP_FLAGS2_METADATA_TPID_SFT		 16
196 	__le32 rx_cmp_cfa_code_errors_v2;
197 	#define RX_CMP_V					(1 << 0)
198 	#define RX_CMPL_ERRORS_MASK				(0x7fff << 1)
199 	 #define RX_CMPL_ERRORS_SFT				 1
200 	#define RX_CMPL_ERRORS_BUFFER_ERROR_MASK		(0x7 << 1)
201 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_NO_BUFFER		 (0x0 << 1)
202 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_DID_NOT_FIT	 (0x1 << 1)
203 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_NOT_ON_CHIP	 (0x2 << 1)
204 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_BAD_FORMAT		 (0x3 << 1)
205 	#define RX_CMPL_ERRORS_IP_CS_ERROR			(0x1 << 4)
206 	#define RX_CMPL_ERRORS_L4_CS_ERROR			(0x1 << 5)
207 	#define RX_CMPL_ERRORS_T_IP_CS_ERROR			(0x1 << 6)
208 	#define RX_CMPL_ERRORS_T_L4_CS_ERROR			(0x1 << 7)
209 	#define RX_CMPL_ERRORS_CRC_ERROR			(0x1 << 8)
210 	#define RX_CMPL_ERRORS_T_PKT_ERROR_MASK			(0x7 << 9)
211 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_NO_ERROR		 (0x0 << 9)
212 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_VERSION	 (0x1 << 9)
213 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_HDR_LEN	 (0x2 << 9)
214 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_TUNNEL_TOTAL_ERROR	 (0x3 << 9)
215 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_IP_TOTAL_ERROR	 (0x4 << 9)
216 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_UDP_TOTAL_ERROR	 (0x5 << 9)
217 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_TTL	 (0x6 << 9)
218 	#define RX_CMPL_ERRORS_PKT_ERROR_MASK			(0xf << 12)
219 	 #define RX_CMPL_ERRORS_PKT_ERROR_NO_ERROR		 (0x0 << 12)
220 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_VERSION	 (0x1 << 12)
221 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_HDR_LEN	 (0x2 << 12)
222 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_TTL		 (0x3 << 12)
223 	 #define RX_CMPL_ERRORS_PKT_ERROR_IP_TOTAL_ERROR	 (0x4 << 12)
224 	 #define RX_CMPL_ERRORS_PKT_ERROR_UDP_TOTAL_ERROR	 (0x5 << 12)
225 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN	 (0x6 << 12)
226 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN_TOO_SMALL (0x7 << 12)
227 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_OPT_LEN	 (0x8 << 12)
228 
229 	#define RX_CMPL_CFA_CODE_MASK				(0xffff << 16)
230 	 #define RX_CMPL_CFA_CODE_SFT				 16
231 
232 	__le32 rx_cmp_unused3;
233 };
234 
235 #define RX_CMP_L2_ERRORS						\
236 	cpu_to_le32(RX_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_CMPL_ERRORS_CRC_ERROR)
237 
238 #define RX_CMP_L4_CS_BITS						\
239 	(cpu_to_le32(RX_CMP_FLAGS2_L4_CS_CALC | RX_CMP_FLAGS2_T_L4_CS_CALC))
240 
241 #define RX_CMP_L4_CS_ERR_BITS						\
242 	(cpu_to_le32(RX_CMPL_ERRORS_L4_CS_ERROR | RX_CMPL_ERRORS_T_L4_CS_ERROR))
243 
244 #define RX_CMP_L4_CS_OK(rxcmp1)						\
245 	    (((rxcmp1)->rx_cmp_flags2 &	RX_CMP_L4_CS_BITS) &&		\
246 	     !((rxcmp1)->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS))
247 
248 #define RX_CMP_ENCAP(rxcmp1)						\
249 	    ((le32_to_cpu((rxcmp1)->rx_cmp_flags2) &			\
250 	     RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3)
251 
252 #define RX_CMP_CFA_CODE(rxcmpl1)					\
253 	((le32_to_cpu((rxcmpl1)->rx_cmp_cfa_code_errors_v2) &		\
254 	  RX_CMPL_CFA_CODE_MASK) >> RX_CMPL_CFA_CODE_SFT)
255 
256 struct rx_agg_cmp {
257 	__le32 rx_agg_cmp_len_flags_type;
258 	#define RX_AGG_CMP_TYPE					(0x3f << 0)
259 	#define RX_AGG_CMP_LEN					(0xffff << 16)
260 	 #define RX_AGG_CMP_LEN_SHIFT				 16
261 	u32 rx_agg_cmp_opaque;
262 	__le32 rx_agg_cmp_v;
263 	#define RX_AGG_CMP_V					(1 << 0)
264 	__le32 rx_agg_cmp_unused;
265 };
266 
267 struct rx_tpa_start_cmp {
268 	__le32 rx_tpa_start_cmp_len_flags_type;
269 	#define RX_TPA_START_CMP_TYPE				(0x3f << 0)
270 	#define RX_TPA_START_CMP_FLAGS				(0x3ff << 6)
271 	 #define RX_TPA_START_CMP_FLAGS_SHIFT			 6
272 	#define RX_TPA_START_CMP_FLAGS_PLACEMENT		(0x7 << 7)
273 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_SHIFT		 7
274 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_JUMBO		 (0x1 << 7)
275 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_HDS		 (0x2 << 7)
276 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_JUMBO	 (0x5 << 7)
277 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_HDS	 (0x6 << 7)
278 	#define RX_TPA_START_CMP_FLAGS_RSS_VALID		(0x1 << 10)
279 	#define RX_TPA_START_CMP_FLAGS_ITYPES			(0xf << 12)
280 	 #define RX_TPA_START_CMP_FLAGS_ITYPES_SHIFT		 12
281 	 #define RX_TPA_START_CMP_FLAGS_ITYPE_TCP		 (0x2 << 12)
282 	#define RX_TPA_START_CMP_LEN				(0xffff << 16)
283 	 #define RX_TPA_START_CMP_LEN_SHIFT			 16
284 
285 	u32 rx_tpa_start_cmp_opaque;
286 	__le32 rx_tpa_start_cmp_misc_v1;
287 	#define RX_TPA_START_CMP_V1				(0x1 << 0)
288 	#define RX_TPA_START_CMP_RSS_HASH_TYPE			(0x7f << 9)
289 	 #define RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT		 9
290 	#define RX_TPA_START_CMP_AGG_ID				(0x7f << 25)
291 	 #define RX_TPA_START_CMP_AGG_ID_SHIFT			 25
292 
293 	__le32 rx_tpa_start_cmp_rss_hash;
294 };
295 
296 #define TPA_START_HASH_VALID(rx_tpa_start)				\
297 	((rx_tpa_start)->rx_tpa_start_cmp_len_flags_type &		\
298 	 cpu_to_le32(RX_TPA_START_CMP_FLAGS_RSS_VALID))
299 
300 #define TPA_START_HASH_TYPE(rx_tpa_start)				\
301 	(((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) &	\
302 	   RX_TPA_START_CMP_RSS_HASH_TYPE) >>				\
303 	  RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
304 
305 #define TPA_START_AGG_ID(rx_tpa_start)					\
306 	((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) &	\
307 	 RX_TPA_START_CMP_AGG_ID) >> RX_TPA_START_CMP_AGG_ID_SHIFT)
308 
309 struct rx_tpa_start_cmp_ext {
310 	__le32 rx_tpa_start_cmp_flags2;
311 	#define RX_TPA_START_CMP_FLAGS2_IP_CS_CALC		(0x1 << 0)
312 	#define RX_TPA_START_CMP_FLAGS2_L4_CS_CALC		(0x1 << 1)
313 	#define RX_TPA_START_CMP_FLAGS2_T_IP_CS_CALC		(0x1 << 2)
314 	#define RX_TPA_START_CMP_FLAGS2_T_L4_CS_CALC		(0x1 << 3)
315 	#define RX_TPA_START_CMP_FLAGS2_IP_TYPE			(0x1 << 8)
316 
317 	__le32 rx_tpa_start_cmp_metadata;
318 	__le32 rx_tpa_start_cmp_cfa_code_v2;
319 	#define RX_TPA_START_CMP_V2				(0x1 << 0)
320 	#define RX_TPA_START_CMP_CFA_CODE			(0xffff << 16)
321 	 #define RX_TPA_START_CMPL_CFA_CODE_SHIFT		 16
322 	__le32 rx_tpa_start_cmp_hdr_info;
323 };
324 
325 #define TPA_START_CFA_CODE(rx_tpa_start)				\
326 	((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_cfa_code_v2) &	\
327 	 RX_TPA_START_CMP_CFA_CODE) >> RX_TPA_START_CMPL_CFA_CODE_SHIFT)
328 
329 struct rx_tpa_end_cmp {
330 	__le32 rx_tpa_end_cmp_len_flags_type;
331 	#define RX_TPA_END_CMP_TYPE				(0x3f << 0)
332 	#define RX_TPA_END_CMP_FLAGS				(0x3ff << 6)
333 	 #define RX_TPA_END_CMP_FLAGS_SHIFT			 6
334 	#define RX_TPA_END_CMP_FLAGS_PLACEMENT			(0x7 << 7)
335 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_SHIFT		 7
336 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_JUMBO		 (0x1 << 7)
337 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_HDS		 (0x2 << 7)
338 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO	 (0x5 << 7)
339 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS		 (0x6 << 7)
340 	#define RX_TPA_END_CMP_FLAGS_RSS_VALID			(0x1 << 10)
341 	#define RX_TPA_END_CMP_FLAGS_ITYPES			(0xf << 12)
342 	 #define RX_TPA_END_CMP_FLAGS_ITYPES_SHIFT		 12
343 	 #define RX_TPA_END_CMP_FLAGS_ITYPE_TCP			 (0x2 << 12)
344 	#define RX_TPA_END_CMP_LEN				(0xffff << 16)
345 	 #define RX_TPA_END_CMP_LEN_SHIFT			 16
346 
347 	u32 rx_tpa_end_cmp_opaque;
348 	__le32 rx_tpa_end_cmp_misc_v1;
349 	#define RX_TPA_END_CMP_V1				(0x1 << 0)
350 	#define RX_TPA_END_CMP_AGG_BUFS				(0x3f << 1)
351 	 #define RX_TPA_END_CMP_AGG_BUFS_SHIFT			 1
352 	#define RX_TPA_END_CMP_TPA_SEGS				(0xff << 8)
353 	 #define RX_TPA_END_CMP_TPA_SEGS_SHIFT			 8
354 	#define RX_TPA_END_CMP_PAYLOAD_OFFSET			(0xff << 16)
355 	 #define RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT		 16
356 	#define RX_TPA_END_CMP_AGG_ID				(0x7f << 25)
357 	 #define RX_TPA_END_CMP_AGG_ID_SHIFT			 25
358 
359 	__le32 rx_tpa_end_cmp_tsdelta;
360 	#define RX_TPA_END_GRO_TS				(0x1 << 31)
361 };
362 
363 #define TPA_END_AGG_ID(rx_tpa_end)					\
364 	((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) &		\
365 	 RX_TPA_END_CMP_AGG_ID) >> RX_TPA_END_CMP_AGG_ID_SHIFT)
366 
367 #define TPA_END_TPA_SEGS(rx_tpa_end)					\
368 	((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) &		\
369 	 RX_TPA_END_CMP_TPA_SEGS) >> RX_TPA_END_CMP_TPA_SEGS_SHIFT)
370 
371 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO				\
372 	cpu_to_le32(RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO &		\
373 		    RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS)
374 
375 #define TPA_END_GRO(rx_tpa_end)						\
376 	((rx_tpa_end)->rx_tpa_end_cmp_len_flags_type &			\
377 	 RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO)
378 
379 #define TPA_END_GRO_TS(rx_tpa_end)					\
380 	(!!((rx_tpa_end)->rx_tpa_end_cmp_tsdelta &			\
381 	    cpu_to_le32(RX_TPA_END_GRO_TS)))
382 
383 struct rx_tpa_end_cmp_ext {
384 	__le32 rx_tpa_end_cmp_dup_acks;
385 	#define RX_TPA_END_CMP_TPA_DUP_ACKS			(0xf << 0)
386 
387 	__le32 rx_tpa_end_cmp_seg_len;
388 	#define RX_TPA_END_CMP_TPA_SEG_LEN			(0xffff << 0)
389 
390 	__le32 rx_tpa_end_cmp_errors_v2;
391 	#define RX_TPA_END_CMP_V2				(0x1 << 0)
392 	#define RX_TPA_END_CMP_ERRORS				(0x3 << 1)
393 	#define RX_TPA_END_CMPL_ERRORS_SHIFT			 1
394 
395 	u32 rx_tpa_end_cmp_start_opaque;
396 };
397 
398 #define TPA_END_ERRORS(rx_tpa_end_ext)					\
399 	((rx_tpa_end_ext)->rx_tpa_end_cmp_errors_v2 &			\
400 	 cpu_to_le32(RX_TPA_END_CMP_ERRORS))
401 
402 #define DB_IDX_MASK						0xffffff
403 #define DB_IDX_VALID						(0x1 << 26)
404 #define DB_IRQ_DIS						(0x1 << 27)
405 #define DB_KEY_TX						(0x0 << 28)
406 #define DB_KEY_RX						(0x1 << 28)
407 #define DB_KEY_CP						(0x2 << 28)
408 #define DB_KEY_ST						(0x3 << 28)
409 #define DB_KEY_TX_PUSH						(0x4 << 28)
410 #define DB_LONG_TX_PUSH						(0x2 << 24)
411 
412 #define BNXT_MIN_ROCE_CP_RINGS	2
413 #define BNXT_MIN_ROCE_STAT_CTXS	1
414 
415 #define INVALID_HW_RING_ID	((u16)-1)
416 
417 /* The hardware supports certain page sizes.  Use the supported page sizes
418  * to allocate the rings.
419  */
420 #if (PAGE_SHIFT < 12)
421 #define BNXT_PAGE_SHIFT	12
422 #elif (PAGE_SHIFT <= 13)
423 #define BNXT_PAGE_SHIFT	PAGE_SHIFT
424 #elif (PAGE_SHIFT < 16)
425 #define BNXT_PAGE_SHIFT	13
426 #else
427 #define BNXT_PAGE_SHIFT	16
428 #endif
429 
430 #define BNXT_PAGE_SIZE	(1 << BNXT_PAGE_SHIFT)
431 
432 /* The RXBD length is 16-bit so we can only support page sizes < 64K */
433 #if (PAGE_SHIFT > 15)
434 #define BNXT_RX_PAGE_SHIFT 15
435 #else
436 #define BNXT_RX_PAGE_SHIFT PAGE_SHIFT
437 #endif
438 
439 #define BNXT_RX_PAGE_SIZE (1 << BNXT_RX_PAGE_SHIFT)
440 
441 #define BNXT_MAX_MTU		9500
442 #define BNXT_MAX_PAGE_MODE_MTU	\
443 	((unsigned int)PAGE_SIZE - VLAN_ETH_HLEN - NET_IP_ALIGN -	\
444 	 XDP_PACKET_HEADROOM)
445 
446 #define BNXT_MIN_PKT_SIZE	52
447 
448 #define BNXT_DEFAULT_RX_RING_SIZE	511
449 #define BNXT_DEFAULT_TX_RING_SIZE	511
450 
451 #define MAX_TPA		64
452 
453 #if (BNXT_PAGE_SHIFT == 16)
454 #define MAX_RX_PAGES	1
455 #define MAX_RX_AGG_PAGES	4
456 #define MAX_TX_PAGES	1
457 #define MAX_CP_PAGES	8
458 #else
459 #define MAX_RX_PAGES	8
460 #define MAX_RX_AGG_PAGES	32
461 #define MAX_TX_PAGES	8
462 #define MAX_CP_PAGES	64
463 #endif
464 
465 #define RX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct rx_bd))
466 #define TX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_bd))
467 #define CP_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_cmp))
468 
469 #define SW_RXBD_RING_SIZE (sizeof(struct bnxt_sw_rx_bd) * RX_DESC_CNT)
470 #define HW_RXBD_RING_SIZE (sizeof(struct rx_bd) * RX_DESC_CNT)
471 
472 #define SW_RXBD_AGG_RING_SIZE (sizeof(struct bnxt_sw_rx_agg_bd) * RX_DESC_CNT)
473 
474 #define SW_TXBD_RING_SIZE (sizeof(struct bnxt_sw_tx_bd) * TX_DESC_CNT)
475 #define HW_TXBD_RING_SIZE (sizeof(struct tx_bd) * TX_DESC_CNT)
476 
477 #define HW_CMPD_RING_SIZE (sizeof(struct tx_cmp) * CP_DESC_CNT)
478 
479 #define BNXT_MAX_RX_DESC_CNT		(RX_DESC_CNT * MAX_RX_PAGES - 1)
480 #define BNXT_MAX_RX_JUM_DESC_CNT	(RX_DESC_CNT * MAX_RX_AGG_PAGES - 1)
481 #define BNXT_MAX_TX_DESC_CNT		(TX_DESC_CNT * MAX_TX_PAGES - 1)
482 
483 #define RX_RING(x)	(((x) & ~(RX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
484 #define RX_IDX(x)	((x) & (RX_DESC_CNT - 1))
485 
486 #define TX_RING(x)	(((x) & ~(TX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
487 #define TX_IDX(x)	((x) & (TX_DESC_CNT - 1))
488 
489 #define CP_RING(x)	(((x) & ~(CP_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
490 #define CP_IDX(x)	((x) & (CP_DESC_CNT - 1))
491 
492 #define TX_CMP_VALID(txcmp, raw_cons)					\
493 	(!!((txcmp)->tx_cmp_errors_v & cpu_to_le32(TX_CMP_V)) ==	\
494 	 !((raw_cons) & bp->cp_bit))
495 
496 #define RX_CMP_VALID(rxcmp1, raw_cons)					\
497 	(!!((rxcmp1)->rx_cmp_cfa_code_errors_v2 & cpu_to_le32(RX_CMP_V)) ==\
498 	 !((raw_cons) & bp->cp_bit))
499 
500 #define RX_AGG_CMP_VALID(agg, raw_cons)				\
501 	(!!((agg)->rx_agg_cmp_v & cpu_to_le32(RX_AGG_CMP_V)) ==	\
502 	 !((raw_cons) & bp->cp_bit))
503 
504 #define TX_CMP_TYPE(txcmp)					\
505 	(le32_to_cpu((txcmp)->tx_cmp_flags_type) & CMP_TYPE)
506 
507 #define RX_CMP_TYPE(rxcmp)					\
508 	(le32_to_cpu((rxcmp)->rx_cmp_len_flags_type) & RX_CMP_CMP_TYPE)
509 
510 #define NEXT_RX(idx)		(((idx) + 1) & bp->rx_ring_mask)
511 
512 #define NEXT_RX_AGG(idx)	(((idx) + 1) & bp->rx_agg_ring_mask)
513 
514 #define NEXT_TX(idx)		(((idx) + 1) & bp->tx_ring_mask)
515 
516 #define ADV_RAW_CMP(idx, n)	((idx) + (n))
517 #define NEXT_RAW_CMP(idx)	ADV_RAW_CMP(idx, 1)
518 #define RING_CMP(idx)		((idx) & bp->cp_ring_mask)
519 #define NEXT_CMP(idx)		RING_CMP(ADV_RAW_CMP(idx, 1))
520 
521 #define BNXT_HWRM_MAX_REQ_LEN		(bp->hwrm_max_req_len)
522 #define BNXT_HWRM_SHORT_REQ_LEN		sizeof(struct hwrm_short_input)
523 #define DFLT_HWRM_CMD_TIMEOUT		500
524 #define HWRM_CMD_TIMEOUT		(bp->hwrm_cmd_timeout)
525 #define HWRM_RESET_TIMEOUT		((HWRM_CMD_TIMEOUT) * 4)
526 #define HWRM_RESP_ERR_CODE_MASK		0xffff
527 #define HWRM_RESP_LEN_OFFSET		4
528 #define HWRM_RESP_LEN_MASK		0xffff0000
529 #define HWRM_RESP_LEN_SFT		16
530 #define HWRM_RESP_VALID_MASK		0xff000000
531 #define HWRM_SEQ_ID_INVALID		-1
532 #define BNXT_HWRM_REQ_MAX_SIZE		128
533 #define BNXT_HWRM_REQS_PER_PAGE		(BNXT_PAGE_SIZE /	\
534 					 BNXT_HWRM_REQ_MAX_SIZE)
535 #define HWRM_SHORT_MIN_TIMEOUT		3
536 #define HWRM_SHORT_MAX_TIMEOUT		10
537 #define HWRM_SHORT_TIMEOUT_COUNTER	5
538 
539 #define HWRM_MIN_TIMEOUT		25
540 #define HWRM_MAX_TIMEOUT		40
541 
542 #define HWRM_TOTAL_TIMEOUT(n)	(((n) <= HWRM_SHORT_TIMEOUT_COUNTER) ?	\
543 	((n) * HWRM_SHORT_MIN_TIMEOUT) :				\
544 	(HWRM_SHORT_TIMEOUT_COUNTER * HWRM_SHORT_MIN_TIMEOUT +		\
545 	 ((n) - HWRM_SHORT_TIMEOUT_COUNTER) * HWRM_MIN_TIMEOUT))
546 
547 #define HWRM_VALID_BIT_DELAY_USEC	20
548 
549 #define BNXT_RX_EVENT	1
550 #define BNXT_AGG_EVENT	2
551 #define BNXT_TX_EVENT	4
552 
553 struct bnxt_sw_tx_bd {
554 	struct sk_buff		*skb;
555 	DEFINE_DMA_UNMAP_ADDR(mapping);
556 	u8			is_gso;
557 	u8			is_push;
558 	union {
559 		unsigned short		nr_frags;
560 		u16			rx_prod;
561 	};
562 };
563 
564 struct bnxt_sw_rx_bd {
565 	void			*data;
566 	u8			*data_ptr;
567 	dma_addr_t		mapping;
568 };
569 
570 struct bnxt_sw_rx_agg_bd {
571 	struct page		*page;
572 	unsigned int		offset;
573 	dma_addr_t		mapping;
574 };
575 
576 struct bnxt_ring_struct {
577 	int			nr_pages;
578 	int			page_size;
579 	void			**pg_arr;
580 	dma_addr_t		*dma_arr;
581 
582 	__le64			*pg_tbl;
583 	dma_addr_t		pg_tbl_map;
584 
585 	int			vmem_size;
586 	void			**vmem;
587 
588 	u16			fw_ring_id; /* Ring id filled by Chimp FW */
589 	union {
590 		u16		grp_idx;
591 		u16		map_idx; /* Used by cmpl rings */
592 	};
593 	u8			queue_id;
594 };
595 
596 struct tx_push_bd {
597 	__le32			doorbell;
598 	__le32			tx_bd_len_flags_type;
599 	u32			tx_bd_opaque;
600 	struct tx_bd_ext	txbd2;
601 };
602 
603 struct tx_push_buffer {
604 	struct tx_push_bd	push_bd;
605 	u32			data[25];
606 };
607 
608 struct bnxt_tx_ring_info {
609 	struct bnxt_napi	*bnapi;
610 	u16			tx_prod;
611 	u16			tx_cons;
612 	u16			txq_index;
613 	void __iomem		*tx_doorbell;
614 
615 	struct tx_bd		*tx_desc_ring[MAX_TX_PAGES];
616 	struct bnxt_sw_tx_bd	*tx_buf_ring;
617 
618 	dma_addr_t		tx_desc_mapping[MAX_TX_PAGES];
619 
620 	struct tx_push_buffer	*tx_push;
621 	dma_addr_t		tx_push_mapping;
622 	__le64			data_mapping;
623 
624 #define BNXT_DEV_STATE_CLOSING	0x1
625 	u32			dev_state;
626 
627 	struct bnxt_ring_struct	tx_ring_struct;
628 };
629 
630 struct bnxt_coal {
631 	u16			coal_ticks;
632 	u16			coal_ticks_irq;
633 	u16			coal_bufs;
634 	u16			coal_bufs_irq;
635 			/* RING_IDLE enabled when coal ticks < idle_thresh  */
636 	u16			idle_thresh;
637 	u8			bufs_per_record;
638 	u8			budget;
639 };
640 
641 struct bnxt_tpa_info {
642 	void			*data;
643 	u8			*data_ptr;
644 	dma_addr_t		mapping;
645 	u16			len;
646 	unsigned short		gso_type;
647 	u32			flags2;
648 	u32			metadata;
649 	enum pkt_hash_types	hash_type;
650 	u32			rss_hash;
651 	u32			hdr_info;
652 
653 #define BNXT_TPA_L4_SIZE(hdr_info)	\
654 	(((hdr_info) & 0xf8000000) ? ((hdr_info) >> 27) : 32)
655 
656 #define BNXT_TPA_INNER_L3_OFF(hdr_info)	\
657 	(((hdr_info) >> 18) & 0x1ff)
658 
659 #define BNXT_TPA_INNER_L2_OFF(hdr_info)	\
660 	(((hdr_info) >> 9) & 0x1ff)
661 
662 #define BNXT_TPA_OUTER_L3_OFF(hdr_info)	\
663 	((hdr_info) & 0x1ff)
664 
665 	u16			cfa_code; /* cfa_code in TPA start compl */
666 };
667 
668 struct bnxt_rx_ring_info {
669 	struct bnxt_napi	*bnapi;
670 	u16			rx_prod;
671 	u16			rx_agg_prod;
672 	u16			rx_sw_agg_prod;
673 	u16			rx_next_cons;
674 	void __iomem		*rx_doorbell;
675 	void __iomem		*rx_agg_doorbell;
676 
677 	struct bpf_prog		*xdp_prog;
678 
679 	struct rx_bd		*rx_desc_ring[MAX_RX_PAGES];
680 	struct bnxt_sw_rx_bd	*rx_buf_ring;
681 
682 	struct rx_bd		*rx_agg_desc_ring[MAX_RX_AGG_PAGES];
683 	struct bnxt_sw_rx_agg_bd	*rx_agg_ring;
684 
685 	unsigned long		*rx_agg_bmap;
686 	u16			rx_agg_bmap_size;
687 
688 	struct page		*rx_page;
689 	unsigned int		rx_page_offset;
690 
691 	dma_addr_t		rx_desc_mapping[MAX_RX_PAGES];
692 	dma_addr_t		rx_agg_desc_mapping[MAX_RX_AGG_PAGES];
693 
694 	struct bnxt_tpa_info	*rx_tpa;
695 
696 	struct bnxt_ring_struct	rx_ring_struct;
697 	struct bnxt_ring_struct	rx_agg_ring_struct;
698 	struct xdp_rxq_info	xdp_rxq;
699 };
700 
701 struct bnxt_cp_ring_info {
702 	u32			cp_raw_cons;
703 	void __iomem		*cp_doorbell;
704 
705 	struct bnxt_coal	rx_ring_coal;
706 	u64			rx_packets;
707 	u64			rx_bytes;
708 	u64			event_ctr;
709 
710 	struct net_dim		dim;
711 
712 	struct tx_cmp		*cp_desc_ring[MAX_CP_PAGES];
713 
714 	dma_addr_t		cp_desc_mapping[MAX_CP_PAGES];
715 
716 	struct ctx_hw_stats	*hw_stats;
717 	dma_addr_t		hw_stats_map;
718 	u32			hw_stats_ctx_id;
719 	u64			rx_l4_csum_errors;
720 
721 	struct bnxt_ring_struct	cp_ring_struct;
722 };
723 
724 struct bnxt_napi {
725 	struct napi_struct	napi;
726 	struct bnxt		*bp;
727 
728 	int			index;
729 	struct bnxt_cp_ring_info	cp_ring;
730 	struct bnxt_rx_ring_info	*rx_ring;
731 	struct bnxt_tx_ring_info	*tx_ring;
732 
733 	void			(*tx_int)(struct bnxt *, struct bnxt_napi *,
734 					  int);
735 	u32			flags;
736 #define BNXT_NAPI_FLAG_XDP	0x1
737 
738 	bool			in_reset;
739 };
740 
741 struct bnxt_irq {
742 	irq_handler_t	handler;
743 	unsigned int	vector;
744 	u8		requested:1;
745 	u8		have_cpumask:1;
746 	char		name[IFNAMSIZ + 2];
747 	cpumask_var_t	cpu_mask;
748 };
749 
750 #define HWRM_RING_ALLOC_TX	0x1
751 #define HWRM_RING_ALLOC_RX	0x2
752 #define HWRM_RING_ALLOC_AGG	0x4
753 #define HWRM_RING_ALLOC_CMPL	0x8
754 
755 #define INVALID_STATS_CTX_ID	-1
756 
757 struct bnxt_ring_grp_info {
758 	u16	fw_stats_ctx;
759 	u16	fw_grp_id;
760 	u16	rx_fw_ring_id;
761 	u16	agg_fw_ring_id;
762 	u16	cp_fw_ring_id;
763 };
764 
765 struct bnxt_vnic_info {
766 	u16		fw_vnic_id; /* returned by Chimp during alloc */
767 #define BNXT_MAX_CTX_PER_VNIC	2
768 	u16		fw_rss_cos_lb_ctx[BNXT_MAX_CTX_PER_VNIC];
769 	u16		fw_l2_ctx_id;
770 #define BNXT_MAX_UC_ADDRS	4
771 	__le64		fw_l2_filter_id[BNXT_MAX_UC_ADDRS];
772 				/* index 0 always dev_addr */
773 	u16		uc_filter_count;
774 	u8		*uc_list;
775 
776 	u16		*fw_grp_ids;
777 	dma_addr_t	rss_table_dma_addr;
778 	__le16		*rss_table;
779 	dma_addr_t	rss_hash_key_dma_addr;
780 	u64		*rss_hash_key;
781 	u32		rx_mask;
782 
783 	u8		*mc_list;
784 	int		mc_list_size;
785 	int		mc_list_count;
786 	dma_addr_t	mc_list_mapping;
787 #define BNXT_MAX_MC_ADDRS	16
788 
789 	u32		flags;
790 #define BNXT_VNIC_RSS_FLAG	1
791 #define BNXT_VNIC_RFS_FLAG	2
792 #define BNXT_VNIC_MCAST_FLAG	4
793 #define BNXT_VNIC_UCAST_FLAG	8
794 #define BNXT_VNIC_RFS_NEW_RSS_FLAG	0x10
795 };
796 
797 struct bnxt_hw_resc {
798 	u16	min_rsscos_ctxs;
799 	u16	max_rsscos_ctxs;
800 	u16	min_cp_rings;
801 	u16	max_cp_rings;
802 	u16	resv_cp_rings;
803 	u16	min_tx_rings;
804 	u16	max_tx_rings;
805 	u16	resv_tx_rings;
806 	u16	max_tx_sch_inputs;
807 	u16	min_rx_rings;
808 	u16	max_rx_rings;
809 	u16	resv_rx_rings;
810 	u16	min_hw_ring_grps;
811 	u16	max_hw_ring_grps;
812 	u16	resv_hw_ring_grps;
813 	u16	min_l2_ctxs;
814 	u16	max_l2_ctxs;
815 	u16	min_vnics;
816 	u16	max_vnics;
817 	u16	resv_vnics;
818 	u16	min_stat_ctxs;
819 	u16	max_stat_ctxs;
820 	u16	max_irqs;
821 };
822 
823 #if defined(CONFIG_BNXT_SRIOV)
824 struct bnxt_vf_info {
825 	u16	fw_fid;
826 	u8	mac_addr[ETH_ALEN];	/* PF assigned MAC Address */
827 	u8	vf_mac_addr[ETH_ALEN];	/* VF assigned MAC address, only
828 					 * stored by PF.
829 					 */
830 	u16	vlan;
831 	u32	flags;
832 #define BNXT_VF_QOS		0x1
833 #define BNXT_VF_SPOOFCHK	0x2
834 #define BNXT_VF_LINK_FORCED	0x4
835 #define BNXT_VF_LINK_UP		0x8
836 #define BNXT_VF_TRUST		0x10
837 	u32	func_flags; /* func cfg flags */
838 	u32	min_tx_rate;
839 	u32	max_tx_rate;
840 	void	*hwrm_cmd_req_addr;
841 	dma_addr_t	hwrm_cmd_req_dma_addr;
842 };
843 #endif
844 
845 struct bnxt_pf_info {
846 #define BNXT_FIRST_PF_FID	1
847 #define BNXT_FIRST_VF_FID	128
848 	u16	fw_fid;
849 	u16	port_id;
850 	u8	mac_addr[ETH_ALEN];
851 	u32	first_vf_id;
852 	u16	active_vfs;
853 	u16	max_vfs;
854 	u32	max_encap_records;
855 	u32	max_decap_records;
856 	u32	max_tx_em_flows;
857 	u32	max_tx_wm_flows;
858 	u32	max_rx_em_flows;
859 	u32	max_rx_wm_flows;
860 	unsigned long	*vf_event_bmap;
861 	u16	hwrm_cmd_req_pages;
862 	u8	vf_resv_strategy;
863 #define BNXT_VF_RESV_STRATEGY_MAXIMAL	0
864 #define BNXT_VF_RESV_STRATEGY_MINIMAL	1
865 	void			*hwrm_cmd_req_addr[4];
866 	dma_addr_t		hwrm_cmd_req_dma_addr[4];
867 	struct bnxt_vf_info	*vf;
868 };
869 
870 struct bnxt_ntuple_filter {
871 	struct hlist_node	hash;
872 	u8			dst_mac_addr[ETH_ALEN];
873 	u8			src_mac_addr[ETH_ALEN];
874 	struct flow_keys	fkeys;
875 	__le64			filter_id;
876 	u16			sw_id;
877 	u8			l2_fltr_idx;
878 	u16			rxq;
879 	u32			flow_id;
880 	unsigned long		state;
881 #define BNXT_FLTR_VALID		0
882 #define BNXT_FLTR_UPDATE	1
883 };
884 
885 struct bnxt_link_info {
886 	u8			phy_type;
887 	u8			media_type;
888 	u8			transceiver;
889 	u8			phy_addr;
890 	u8			phy_link_status;
891 #define BNXT_LINK_NO_LINK	PORT_PHY_QCFG_RESP_LINK_NO_LINK
892 #define BNXT_LINK_SIGNAL	PORT_PHY_QCFG_RESP_LINK_SIGNAL
893 #define BNXT_LINK_LINK		PORT_PHY_QCFG_RESP_LINK_LINK
894 	u8			wire_speed;
895 	u8			loop_back;
896 	u8			link_up;
897 	u8			duplex;
898 #define BNXT_LINK_DUPLEX_HALF	PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF
899 #define BNXT_LINK_DUPLEX_FULL	PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL
900 	u8			pause;
901 #define BNXT_LINK_PAUSE_TX	PORT_PHY_QCFG_RESP_PAUSE_TX
902 #define BNXT_LINK_PAUSE_RX	PORT_PHY_QCFG_RESP_PAUSE_RX
903 #define BNXT_LINK_PAUSE_BOTH	(PORT_PHY_QCFG_RESP_PAUSE_RX | \
904 				 PORT_PHY_QCFG_RESP_PAUSE_TX)
905 	u8			lp_pause;
906 	u8			auto_pause_setting;
907 	u8			force_pause_setting;
908 	u8			duplex_setting;
909 	u8			auto_mode;
910 #define BNXT_AUTO_MODE(mode)	((mode) > BNXT_LINK_AUTO_NONE && \
911 				 (mode) <= BNXT_LINK_AUTO_MSK)
912 #define BNXT_LINK_AUTO_NONE     PORT_PHY_QCFG_RESP_AUTO_MODE_NONE
913 #define BNXT_LINK_AUTO_ALLSPDS	PORT_PHY_QCFG_RESP_AUTO_MODE_ALL_SPEEDS
914 #define BNXT_LINK_AUTO_ONESPD	PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_SPEED
915 #define BNXT_LINK_AUTO_ONEORBELOW PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_OR_BELOW
916 #define BNXT_LINK_AUTO_MSK	PORT_PHY_QCFG_RESP_AUTO_MODE_SPEED_MASK
917 #define PHY_VER_LEN		3
918 	u8			phy_ver[PHY_VER_LEN];
919 	u16			link_speed;
920 #define BNXT_LINK_SPEED_100MB	PORT_PHY_QCFG_RESP_LINK_SPEED_100MB
921 #define BNXT_LINK_SPEED_1GB	PORT_PHY_QCFG_RESP_LINK_SPEED_1GB
922 #define BNXT_LINK_SPEED_2GB	PORT_PHY_QCFG_RESP_LINK_SPEED_2GB
923 #define BNXT_LINK_SPEED_2_5GB	PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB
924 #define BNXT_LINK_SPEED_10GB	PORT_PHY_QCFG_RESP_LINK_SPEED_10GB
925 #define BNXT_LINK_SPEED_20GB	PORT_PHY_QCFG_RESP_LINK_SPEED_20GB
926 #define BNXT_LINK_SPEED_25GB	PORT_PHY_QCFG_RESP_LINK_SPEED_25GB
927 #define BNXT_LINK_SPEED_40GB	PORT_PHY_QCFG_RESP_LINK_SPEED_40GB
928 #define BNXT_LINK_SPEED_50GB	PORT_PHY_QCFG_RESP_LINK_SPEED_50GB
929 #define BNXT_LINK_SPEED_100GB	PORT_PHY_QCFG_RESP_LINK_SPEED_100GB
930 	u16			support_speeds;
931 	u16			auto_link_speeds;	/* fw adv setting */
932 #define BNXT_LINK_SPEED_MSK_100MB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_100MB
933 #define BNXT_LINK_SPEED_MSK_1GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_1GB
934 #define BNXT_LINK_SPEED_MSK_2GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2GB
935 #define BNXT_LINK_SPEED_MSK_10GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_10GB
936 #define BNXT_LINK_SPEED_MSK_2_5GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2_5GB
937 #define BNXT_LINK_SPEED_MSK_20GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_20GB
938 #define BNXT_LINK_SPEED_MSK_25GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_25GB
939 #define BNXT_LINK_SPEED_MSK_40GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_40GB
940 #define BNXT_LINK_SPEED_MSK_50GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_50GB
941 #define BNXT_LINK_SPEED_MSK_100GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_100GB
942 	u16			support_auto_speeds;
943 	u16			lp_auto_link_speeds;
944 	u16			force_link_speed;
945 	u32			preemphasis;
946 	u8			module_status;
947 	u16			fec_cfg;
948 #define BNXT_FEC_AUTONEG	PORT_PHY_QCFG_RESP_FEC_CFG_FEC_AUTONEG_ENABLED
949 #define BNXT_FEC_ENC_BASE_R	PORT_PHY_QCFG_RESP_FEC_CFG_FEC_CLAUSE74_ENABLED
950 #define BNXT_FEC_ENC_RS		PORT_PHY_QCFG_RESP_FEC_CFG_FEC_CLAUSE91_ENABLED
951 
952 	/* copy of requested setting from ethtool cmd */
953 	u8			autoneg;
954 #define BNXT_AUTONEG_SPEED		1
955 #define BNXT_AUTONEG_FLOW_CTRL		2
956 	u8			req_duplex;
957 	u8			req_flow_ctrl;
958 	u16			req_link_speed;
959 	u16			advertising;	/* user adv setting */
960 	bool			force_link_chng;
961 
962 	/* a copy of phy_qcfg output used to report link
963 	 * info to VF
964 	 */
965 	struct hwrm_port_phy_qcfg_output phy_qcfg_resp;
966 };
967 
968 #define BNXT_MAX_QUEUE	8
969 
970 struct bnxt_queue_info {
971 	u8	queue_id;
972 	u8	queue_profile;
973 };
974 
975 #define BNXT_MAX_LED			4
976 
977 struct bnxt_led_info {
978 	u8	led_id;
979 	u8	led_type;
980 	u8	led_group_id;
981 	u8	unused;
982 	__le16	led_state_caps;
983 #define BNXT_LED_ALT_BLINK_CAP(x)	((x) &	\
984 	cpu_to_le16(PORT_LED_QCAPS_RESP_LED0_STATE_CAPS_BLINK_ALT_SUPPORTED))
985 
986 	__le16	led_color_caps;
987 };
988 
989 #define BNXT_MAX_TEST	8
990 
991 struct bnxt_test_info {
992 	u8 offline_mask;
993 	u16 timeout;
994 	char string[BNXT_MAX_TEST][ETH_GSTRING_LEN];
995 };
996 
997 #define BNXT_GRCPF_REG_WINDOW_BASE_OUT	0x400
998 #define BNXT_CAG_REG_LEGACY_INT_STATUS	0x4014
999 #define BNXT_CAG_REG_BASE		0x300000
1000 
1001 struct bnxt_tc_flow_stats {
1002 	u64		packets;
1003 	u64		bytes;
1004 };
1005 
1006 struct bnxt_tc_info {
1007 	bool				enabled;
1008 
1009 	/* hash table to store TC offloaded flows */
1010 	struct rhashtable		flow_table;
1011 	struct rhashtable_params	flow_ht_params;
1012 
1013 	/* hash table to store L2 keys of TC flows */
1014 	struct rhashtable		l2_table;
1015 	struct rhashtable_params	l2_ht_params;
1016 	/* hash table to store L2 keys for TC tunnel decap */
1017 	struct rhashtable		decap_l2_table;
1018 	struct rhashtable_params	decap_l2_ht_params;
1019 	/* hash table to store tunnel decap entries */
1020 	struct rhashtable		decap_table;
1021 	struct rhashtable_params	decap_ht_params;
1022 	/* hash table to store tunnel encap entries */
1023 	struct rhashtable		encap_table;
1024 	struct rhashtable_params	encap_ht_params;
1025 
1026 	/* lock to atomically add/del an l2 node when a flow is
1027 	 * added or deleted.
1028 	 */
1029 	struct mutex			lock;
1030 
1031 	/* Fields used for batching stats query */
1032 	struct rhashtable_iter		iter;
1033 #define BNXT_FLOW_STATS_BATCH_MAX	10
1034 	struct bnxt_tc_stats_batch {
1035 		void			  *flow_node;
1036 		struct bnxt_tc_flow_stats hw_stats;
1037 	} stats_batch[BNXT_FLOW_STATS_BATCH_MAX];
1038 
1039 	/* Stat counter mask (width) */
1040 	u64				bytes_mask;
1041 	u64				packets_mask;
1042 };
1043 
1044 struct bnxt_vf_rep_stats {
1045 	u64			packets;
1046 	u64			bytes;
1047 	u64			dropped;
1048 };
1049 
1050 struct bnxt_vf_rep {
1051 	struct bnxt			*bp;
1052 	struct net_device		*dev;
1053 	struct metadata_dst		*dst;
1054 	u16				vf_idx;
1055 	u16				tx_cfa_action;
1056 	u16				rx_cfa_code;
1057 
1058 	struct bnxt_vf_rep_stats	rx_stats;
1059 	struct bnxt_vf_rep_stats	tx_stats;
1060 };
1061 
1062 struct bnxt {
1063 	void __iomem		*bar0;
1064 	void __iomem		*bar1;
1065 	void __iomem		*bar2;
1066 
1067 	u32			reg_base;
1068 	u16			chip_num;
1069 #define CHIP_NUM_57301		0x16c8
1070 #define CHIP_NUM_57302		0x16c9
1071 #define CHIP_NUM_57304		0x16ca
1072 #define CHIP_NUM_58700		0x16cd
1073 #define CHIP_NUM_57402		0x16d0
1074 #define CHIP_NUM_57404		0x16d1
1075 #define CHIP_NUM_57406		0x16d2
1076 #define CHIP_NUM_57407		0x16d5
1077 
1078 #define CHIP_NUM_57311		0x16ce
1079 #define CHIP_NUM_57312		0x16cf
1080 #define CHIP_NUM_57314		0x16df
1081 #define CHIP_NUM_57317		0x16e0
1082 #define CHIP_NUM_57412		0x16d6
1083 #define CHIP_NUM_57414		0x16d7
1084 #define CHIP_NUM_57416		0x16d8
1085 #define CHIP_NUM_57417		0x16d9
1086 #define CHIP_NUM_57412L		0x16da
1087 #define CHIP_NUM_57414L		0x16db
1088 
1089 #define CHIP_NUM_5745X		0xd730
1090 
1091 #define CHIP_NUM_58802		0xd802
1092 #define CHIP_NUM_58804		0xd804
1093 #define CHIP_NUM_58808		0xd808
1094 
1095 #define BNXT_CHIP_NUM_5730X(chip_num)		\
1096 	((chip_num) >= CHIP_NUM_57301 &&	\
1097 	 (chip_num) <= CHIP_NUM_57304)
1098 
1099 #define BNXT_CHIP_NUM_5740X(chip_num)		\
1100 	(((chip_num) >= CHIP_NUM_57402 &&	\
1101 	  (chip_num) <= CHIP_NUM_57406) ||	\
1102 	 (chip_num) == CHIP_NUM_57407)
1103 
1104 #define BNXT_CHIP_NUM_5731X(chip_num)		\
1105 	((chip_num) == CHIP_NUM_57311 ||	\
1106 	 (chip_num) == CHIP_NUM_57312 ||	\
1107 	 (chip_num) == CHIP_NUM_57314 ||	\
1108 	 (chip_num) == CHIP_NUM_57317)
1109 
1110 #define BNXT_CHIP_NUM_5741X(chip_num)		\
1111 	((chip_num) >= CHIP_NUM_57412 &&	\
1112 	 (chip_num) <= CHIP_NUM_57414L)
1113 
1114 #define BNXT_CHIP_NUM_58700(chip_num)		\
1115 	 ((chip_num) == CHIP_NUM_58700)
1116 
1117 #define BNXT_CHIP_NUM_5745X(chip_num)		\
1118 	 ((chip_num) == CHIP_NUM_5745X)
1119 
1120 #define BNXT_CHIP_NUM_57X0X(chip_num)		\
1121 	(BNXT_CHIP_NUM_5730X(chip_num) || BNXT_CHIP_NUM_5740X(chip_num))
1122 
1123 #define BNXT_CHIP_NUM_57X1X(chip_num)		\
1124 	(BNXT_CHIP_NUM_5731X(chip_num) || BNXT_CHIP_NUM_5741X(chip_num))
1125 
1126 #define BNXT_CHIP_NUM_588XX(chip_num)		\
1127 	((chip_num) == CHIP_NUM_58802 ||	\
1128 	 (chip_num) == CHIP_NUM_58804 ||        \
1129 	 (chip_num) == CHIP_NUM_58808)
1130 
1131 	struct net_device	*dev;
1132 	struct pci_dev		*pdev;
1133 
1134 	atomic_t		intr_sem;
1135 
1136 	u32			flags;
1137 	#define BNXT_FLAG_DCB_ENABLED	0x1
1138 	#define BNXT_FLAG_VF		0x2
1139 	#define BNXT_FLAG_LRO		0x4
1140 #ifdef CONFIG_INET
1141 	#define BNXT_FLAG_GRO		0x8
1142 #else
1143 	/* Cannot support hardware GRO if CONFIG_INET is not set */
1144 	#define BNXT_FLAG_GRO		0x0
1145 #endif
1146 	#define BNXT_FLAG_TPA		(BNXT_FLAG_LRO | BNXT_FLAG_GRO)
1147 	#define BNXT_FLAG_JUMBO		0x10
1148 	#define BNXT_FLAG_STRIP_VLAN	0x20
1149 	#define BNXT_FLAG_AGG_RINGS	(BNXT_FLAG_JUMBO | BNXT_FLAG_GRO | \
1150 					 BNXT_FLAG_LRO)
1151 	#define BNXT_FLAG_USING_MSIX	0x40
1152 	#define BNXT_FLAG_MSIX_CAP	0x80
1153 	#define BNXT_FLAG_RFS		0x100
1154 	#define BNXT_FLAG_SHARED_RINGS	0x200
1155 	#define BNXT_FLAG_PORT_STATS	0x400
1156 	#define BNXT_FLAG_UDP_RSS_CAP	0x800
1157 	#define BNXT_FLAG_EEE_CAP	0x1000
1158 	#define BNXT_FLAG_NEW_RSS_CAP	0x2000
1159 	#define BNXT_FLAG_WOL_CAP	0x4000
1160 	#define BNXT_FLAG_ROCEV1_CAP	0x8000
1161 	#define BNXT_FLAG_ROCEV2_CAP	0x10000
1162 	#define BNXT_FLAG_ROCE_CAP	(BNXT_FLAG_ROCEV1_CAP |	\
1163 					 BNXT_FLAG_ROCEV2_CAP)
1164 	#define BNXT_FLAG_NO_AGG_RINGS	0x20000
1165 	#define BNXT_FLAG_RX_PAGE_MODE	0x40000
1166 	#define BNXT_FLAG_FW_LLDP_AGENT	0x80000
1167 	#define BNXT_FLAG_MULTI_HOST	0x100000
1168 	#define BNXT_FLAG_SHORT_CMD	0x200000
1169 	#define BNXT_FLAG_DOUBLE_DB	0x400000
1170 	#define BNXT_FLAG_FW_DCBX_AGENT	0x800000
1171 	#define BNXT_FLAG_CHIP_NITRO_A0	0x1000000
1172 	#define BNXT_FLAG_DIM		0x2000000
1173 	#define BNXT_FLAG_ROCE_MIRROR_CAP	0x4000000
1174 	#define BNXT_FLAG_NEW_RM	0x8000000
1175 	#define BNXT_FLAG_PORT_STATS_EXT	0x10000000
1176 
1177 	#define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA |		\
1178 					    BNXT_FLAG_RFS |		\
1179 					    BNXT_FLAG_STRIP_VLAN)
1180 
1181 #define BNXT_PF(bp)		(!((bp)->flags & BNXT_FLAG_VF))
1182 #define BNXT_VF(bp)		((bp)->flags & BNXT_FLAG_VF)
1183 #define BNXT_NPAR(bp)		((bp)->port_partition_type)
1184 #define BNXT_MH(bp)		((bp)->flags & BNXT_FLAG_MULTI_HOST)
1185 #define BNXT_SINGLE_PF(bp)	(BNXT_PF(bp) && !BNXT_NPAR(bp) && !BNXT_MH(bp))
1186 #define BNXT_CHIP_TYPE_NITRO_A0(bp) ((bp)->flags & BNXT_FLAG_CHIP_NITRO_A0)
1187 #define BNXT_RX_PAGE_MODE(bp)	((bp)->flags & BNXT_FLAG_RX_PAGE_MODE)
1188 
1189 /* Chip class phase 4 and later */
1190 #define BNXT_CHIP_P4_PLUS(bp)			\
1191 	(BNXT_CHIP_NUM_57X1X((bp)->chip_num) ||	\
1192 	 BNXT_CHIP_NUM_5745X((bp)->chip_num) ||	\
1193 	 BNXT_CHIP_NUM_588XX((bp)->chip_num) ||	\
1194 	 (BNXT_CHIP_NUM_58700((bp)->chip_num) &&	\
1195 	  !BNXT_CHIP_TYPE_NITRO_A0(bp)))
1196 
1197 	struct bnxt_en_dev	*edev;
1198 	struct bnxt_en_dev *	(*ulp_probe)(struct net_device *);
1199 
1200 	struct bnxt_napi	**bnapi;
1201 
1202 	struct bnxt_rx_ring_info	*rx_ring;
1203 	struct bnxt_tx_ring_info	*tx_ring;
1204 	u16			*tx_ring_map;
1205 
1206 	struct sk_buff *	(*gro_func)(struct bnxt_tpa_info *, int, int,
1207 					    struct sk_buff *);
1208 
1209 	struct sk_buff *	(*rx_skb_func)(struct bnxt *,
1210 					       struct bnxt_rx_ring_info *,
1211 					       u16, void *, u8 *, dma_addr_t,
1212 					       unsigned int);
1213 
1214 	u32			rx_buf_size;
1215 	u32			rx_buf_use_size;	/* useable size */
1216 	u16			rx_offset;
1217 	u16			rx_dma_offset;
1218 	enum dma_data_direction	rx_dir;
1219 	u32			rx_ring_size;
1220 	u32			rx_agg_ring_size;
1221 	u32			rx_copy_thresh;
1222 	u32			rx_ring_mask;
1223 	u32			rx_agg_ring_mask;
1224 	int			rx_nr_pages;
1225 	int			rx_agg_nr_pages;
1226 	int			rx_nr_rings;
1227 	int			rsscos_nr_ctxs;
1228 
1229 	u32			tx_ring_size;
1230 	u32			tx_ring_mask;
1231 	int			tx_nr_pages;
1232 	int			tx_nr_rings;
1233 	int			tx_nr_rings_per_tc;
1234 	int			tx_nr_rings_xdp;
1235 
1236 	int			tx_wake_thresh;
1237 	int			tx_push_thresh;
1238 	int			tx_push_size;
1239 
1240 	u32			cp_ring_size;
1241 	u32			cp_ring_mask;
1242 	u32			cp_bit;
1243 	int			cp_nr_pages;
1244 	int			cp_nr_rings;
1245 
1246 	int			num_stat_ctxs;
1247 
1248 	/* grp_info indexed by completion ring index */
1249 	struct bnxt_ring_grp_info	*grp_info;
1250 	struct bnxt_vnic_info	*vnic_info;
1251 	int			nr_vnics;
1252 	u32			rss_hash_cfg;
1253 
1254 	u16			max_mtu;
1255 	u8			max_tc;
1256 	u8			max_lltc;	/* lossless TCs */
1257 	struct bnxt_queue_info	q_info[BNXT_MAX_QUEUE];
1258 	u8			tc_to_qidx[BNXT_MAX_QUEUE];
1259 
1260 	unsigned int		current_interval;
1261 #define BNXT_TIMER_INTERVAL	HZ
1262 
1263 	struct timer_list	timer;
1264 
1265 	unsigned long		state;
1266 #define BNXT_STATE_OPEN		0
1267 #define BNXT_STATE_IN_SP_TASK	1
1268 #define BNXT_STATE_READ_STATS	2
1269 
1270 	struct bnxt_irq	*irq_tbl;
1271 	int			total_irqs;
1272 	u8			mac_addr[ETH_ALEN];
1273 
1274 #ifdef CONFIG_BNXT_DCB
1275 	struct ieee_pfc		*ieee_pfc;
1276 	struct ieee_ets		*ieee_ets;
1277 	u8			dcbx_cap;
1278 	u8			default_pri;
1279 #endif /* CONFIG_BNXT_DCB */
1280 
1281 	u32			msg_enable;
1282 
1283 	u32			hwrm_spec_code;
1284 	u16			hwrm_cmd_seq;
1285 	u32			hwrm_intr_seq_id;
1286 	void			*hwrm_short_cmd_req_addr;
1287 	dma_addr_t		hwrm_short_cmd_req_dma_addr;
1288 	void			*hwrm_cmd_resp_addr;
1289 	dma_addr_t		hwrm_cmd_resp_dma_addr;
1290 
1291 	struct rx_port_stats	*hw_rx_port_stats;
1292 	struct tx_port_stats	*hw_tx_port_stats;
1293 	struct rx_port_stats_ext	*hw_rx_port_stats_ext;
1294 	dma_addr_t		hw_rx_port_stats_map;
1295 	dma_addr_t		hw_tx_port_stats_map;
1296 	dma_addr_t		hw_rx_port_stats_ext_map;
1297 	int			hw_port_stats_size;
1298 
1299 	u16			hwrm_max_req_len;
1300 	int			hwrm_cmd_timeout;
1301 	struct mutex		hwrm_cmd_lock;	/* serialize hwrm messages */
1302 	struct hwrm_ver_get_output	ver_resp;
1303 #define FW_VER_STR_LEN		32
1304 #define BC_HWRM_STR_LEN		21
1305 #define PHY_VER_STR_LEN         (FW_VER_STR_LEN - BC_HWRM_STR_LEN)
1306 	char			fw_ver_str[FW_VER_STR_LEN];
1307 	__be16			vxlan_port;
1308 	u8			vxlan_port_cnt;
1309 	__le16			vxlan_fw_dst_port_id;
1310 	__be16			nge_port;
1311 	u8			nge_port_cnt;
1312 	__le16			nge_fw_dst_port_id;
1313 	u8			port_partition_type;
1314 	u8			port_count;
1315 	u16			br_mode;
1316 
1317 	struct bnxt_coal	rx_coal;
1318 	struct bnxt_coal	tx_coal;
1319 
1320 #define BNXT_USEC_TO_COAL_TIMER(x)	((x) * 25 / 2)
1321 
1322 	u32			stats_coal_ticks;
1323 #define BNXT_DEF_STATS_COAL_TICKS	 1000000
1324 #define BNXT_MIN_STATS_COAL_TICKS	  250000
1325 #define BNXT_MAX_STATS_COAL_TICKS	 1000000
1326 
1327 	struct work_struct	sp_task;
1328 	unsigned long		sp_event;
1329 #define BNXT_RX_MASK_SP_EVENT		0
1330 #define BNXT_RX_NTP_FLTR_SP_EVENT	1
1331 #define BNXT_LINK_CHNG_SP_EVENT		2
1332 #define BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT	3
1333 #define BNXT_VXLAN_ADD_PORT_SP_EVENT	4
1334 #define BNXT_VXLAN_DEL_PORT_SP_EVENT	5
1335 #define BNXT_RESET_TASK_SP_EVENT	6
1336 #define BNXT_RST_RING_SP_EVENT		7
1337 #define BNXT_HWRM_PF_UNLOAD_SP_EVENT	8
1338 #define BNXT_PERIODIC_STATS_SP_EVENT	9
1339 #define BNXT_HWRM_PORT_MODULE_SP_EVENT	10
1340 #define BNXT_RESET_TASK_SILENT_SP_EVENT	11
1341 #define BNXT_GENEVE_ADD_PORT_SP_EVENT	12
1342 #define BNXT_GENEVE_DEL_PORT_SP_EVENT	13
1343 #define BNXT_LINK_SPEED_CHNG_SP_EVENT	14
1344 #define BNXT_FLOW_STATS_SP_EVENT	15
1345 
1346 	struct bnxt_hw_resc	hw_resc;
1347 	struct bnxt_pf_info	pf;
1348 #ifdef CONFIG_BNXT_SRIOV
1349 	int			nr_vfs;
1350 	struct bnxt_vf_info	vf;
1351 	wait_queue_head_t	sriov_cfg_wait;
1352 	bool			sriov_cfg;
1353 #define BNXT_SRIOV_CFG_WAIT_TMO	msecs_to_jiffies(10000)
1354 
1355 	/* lock to protect VF-rep creation/cleanup via
1356 	 * multiple paths such as ->sriov_configure() and
1357 	 * devlink ->eswitch_mode_set()
1358 	 */
1359 	struct mutex		sriov_lock;
1360 #endif
1361 
1362 #define BNXT_NTP_FLTR_MAX_FLTR	4096
1363 #define BNXT_NTP_FLTR_HASH_SIZE	512
1364 #define BNXT_NTP_FLTR_HASH_MASK	(BNXT_NTP_FLTR_HASH_SIZE - 1)
1365 	struct hlist_head	ntp_fltr_hash_tbl[BNXT_NTP_FLTR_HASH_SIZE];
1366 	spinlock_t		ntp_fltr_lock;	/* for hash table add, del */
1367 
1368 	unsigned long		*ntp_fltr_bmap;
1369 	int			ntp_fltr_count;
1370 
1371 	/* To protect link related settings during link changes and
1372 	 * ethtool settings changes.
1373 	 */
1374 	struct mutex		link_lock;
1375 	struct bnxt_link_info	link_info;
1376 	struct ethtool_eee	eee;
1377 	u32			lpi_tmr_lo;
1378 	u32			lpi_tmr_hi;
1379 
1380 	u8			num_tests;
1381 	struct bnxt_test_info	*test_info;
1382 
1383 	u8			wol_filter_id;
1384 	u8			wol;
1385 
1386 	u8			num_leds;
1387 	struct bnxt_led_info	leds[BNXT_MAX_LED];
1388 
1389 	struct bpf_prog		*xdp_prog;
1390 
1391 	/* devlink interface and vf-rep structs */
1392 	struct devlink		*dl;
1393 	enum devlink_eswitch_mode eswitch_mode;
1394 	struct bnxt_vf_rep	**vf_reps; /* array of vf-rep ptrs */
1395 	u16			*cfa_code_map; /* cfa_code -> vf_idx map */
1396 	u8			switch_id[8];
1397 	struct bnxt_tc_info	*tc_info;
1398 	struct dentry		*debugfs_pdev;
1399 	struct dentry		*debugfs_dim;
1400 };
1401 
1402 #define BNXT_RX_STATS_OFFSET(counter)			\
1403 	(offsetof(struct rx_port_stats, counter) / 8)
1404 
1405 #define BNXT_TX_STATS_OFFSET(counter)			\
1406 	((offsetof(struct tx_port_stats, counter) +	\
1407 	  sizeof(struct rx_port_stats) + 512) / 8)
1408 
1409 #define BNXT_RX_STATS_EXT_OFFSET(counter)		\
1410 	(offsetof(struct rx_port_stats_ext, counter) / 8)
1411 
1412 #define I2C_DEV_ADDR_A0				0xa0
1413 #define I2C_DEV_ADDR_A2				0xa2
1414 #define SFF_DIAG_SUPPORT_OFFSET			0x5c
1415 #define SFF_MODULE_ID_SFP			0x3
1416 #define SFF_MODULE_ID_QSFP			0xc
1417 #define SFF_MODULE_ID_QSFP_PLUS			0xd
1418 #define SFF_MODULE_ID_QSFP28			0x11
1419 #define BNXT_MAX_PHY_I2C_RESP_SIZE		64
1420 
1421 static inline u32 bnxt_tx_avail(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
1422 {
1423 	/* Tell compiler to fetch tx indices from memory. */
1424 	barrier();
1425 
1426 	return bp->tx_ring_size -
1427 		((txr->tx_prod - txr->tx_cons) & bp->tx_ring_mask);
1428 }
1429 
1430 /* For TX and RX ring doorbells with no ordering guarantee*/
1431 static inline void bnxt_db_write_relaxed(struct bnxt *bp, void __iomem *db,
1432 					 u32 val)
1433 {
1434 	writel_relaxed(val, db);
1435 	if (bp->flags & BNXT_FLAG_DOUBLE_DB)
1436 		writel_relaxed(val, db);
1437 }
1438 
1439 /* For TX and RX ring doorbells */
1440 static inline void bnxt_db_write(struct bnxt *bp, void __iomem *db, u32 val)
1441 {
1442 	writel(val, db);
1443 	if (bp->flags & BNXT_FLAG_DOUBLE_DB)
1444 		writel(val, db);
1445 }
1446 
1447 extern const u16 bnxt_lhint_arr[];
1448 
1449 int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1450 		       u16 prod, gfp_t gfp);
1451 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data);
1452 void bnxt_set_tpa_flags(struct bnxt *bp);
1453 void bnxt_set_ring_params(struct bnxt *);
1454 int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode);
1455 void bnxt_hwrm_cmd_hdr_init(struct bnxt *, void *, u16, u16, u16);
1456 int _hwrm_send_message(struct bnxt *, void *, u32, int);
1457 int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 len, int timeout);
1458 int hwrm_send_message(struct bnxt *, void *, u32, int);
1459 int hwrm_send_message_silent(struct bnxt *, void *, u32, int);
1460 int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
1461 				     int bmap_size);
1462 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id);
1463 int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);
1464 int bnxt_hwrm_set_coal(struct bnxt *);
1465 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
1466 void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max);
1467 unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);
1468 void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max);
1469 unsigned int bnxt_get_max_func_irqs(struct bnxt *bp);
1470 int bnxt_get_avail_msix(struct bnxt *bp, int num);
1471 int bnxt_reserve_rings(struct bnxt *bp);
1472 void bnxt_tx_disable(struct bnxt *bp);
1473 void bnxt_tx_enable(struct bnxt *bp);
1474 int bnxt_hwrm_set_pause(struct bnxt *);
1475 int bnxt_hwrm_set_link_setting(struct bnxt *, bool, bool);
1476 int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp);
1477 int bnxt_hwrm_free_wol_fltr(struct bnxt *bp);
1478 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all);
1479 int bnxt_hwrm_fw_set_time(struct bnxt *);
1480 int bnxt_open_nic(struct bnxt *, bool, bool);
1481 int bnxt_half_open_nic(struct bnxt *bp);
1482 void bnxt_half_close_nic(struct bnxt *bp);
1483 int bnxt_close_nic(struct bnxt *, bool, bool);
1484 int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
1485 		     int tx_xdp);
1486 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
1487 int bnxt_get_max_rings(struct bnxt *, int *, int *, bool);
1488 int bnxt_restore_pf_fw_resources(struct bnxt *bp);
1489 int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr);
1490 void bnxt_dim_work(struct work_struct *work);
1491 int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi);
1492 
1493 #endif
1494