• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Broadcom NetXtreme-C/E network driver.
2  *
3  * Copyright (c) 2014-2015 Broadcom Corporation
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation.
8  */
9 
10 #ifndef BNXT_H
11 #define BNXT_H
12 
13 #define DRV_MODULE_NAME		"bnxt_en"
14 #define DRV_MODULE_VERSION	"0.1.24"
15 
16 #define DRV_VER_MAJ	0
17 #define DRV_VER_MIN	1
18 #define DRV_VER_UPD	24
19 
20 struct tx_bd {
21 	__le32 tx_bd_len_flags_type;
22 	#define TX_BD_TYPE					(0x3f << 0)
23 	 #define TX_BD_TYPE_SHORT_TX_BD				 (0x00 << 0)
24 	 #define TX_BD_TYPE_LONG_TX_BD				 (0x10 << 0)
25 	#define TX_BD_FLAGS_PACKET_END				(1 << 6)
26 	#define TX_BD_FLAGS_NO_CMPL				(1 << 7)
27 	#define TX_BD_FLAGS_BD_CNT				(0x1f << 8)
28 	 #define TX_BD_FLAGS_BD_CNT_SHIFT			 8
29 	#define TX_BD_FLAGS_LHINT				(3 << 13)
30 	 #define TX_BD_FLAGS_LHINT_SHIFT			 13
31 	 #define TX_BD_FLAGS_LHINT_512_AND_SMALLER		 (0 << 13)
32 	 #define TX_BD_FLAGS_LHINT_512_TO_1023			 (1 << 13)
33 	 #define TX_BD_FLAGS_LHINT_1024_TO_2047			 (2 << 13)
34 	 #define TX_BD_FLAGS_LHINT_2048_AND_LARGER		 (3 << 13)
35 	#define TX_BD_FLAGS_COAL_NOW				(1 << 15)
36 	#define TX_BD_LEN					(0xffff << 16)
37 	 #define TX_BD_LEN_SHIFT				 16
38 
39 	u32 tx_bd_opaque;
40 	__le64 tx_bd_haddr;
41 } __packed;
42 
43 struct tx_bd_ext {
44 	__le32 tx_bd_hsize_lflags;
45 	#define TX_BD_FLAGS_TCP_UDP_CHKSUM			(1 << 0)
46 	#define TX_BD_FLAGS_IP_CKSUM				(1 << 1)
47 	#define TX_BD_FLAGS_NO_CRC				(1 << 2)
48 	#define TX_BD_FLAGS_STAMP				(1 << 3)
49 	#define TX_BD_FLAGS_T_IP_CHKSUM				(1 << 4)
50 	#define TX_BD_FLAGS_LSO					(1 << 5)
51 	#define TX_BD_FLAGS_IPID_FMT				(1 << 6)
52 	#define TX_BD_FLAGS_T_IPID				(1 << 7)
53 	#define TX_BD_HSIZE					(0xff << 16)
54 	 #define TX_BD_HSIZE_SHIFT				 16
55 
56 	__le32 tx_bd_mss;
57 	__le32 tx_bd_cfa_action;
58 	#define TX_BD_CFA_ACTION				(0xffff << 16)
59 	 #define TX_BD_CFA_ACTION_SHIFT				 16
60 
61 	__le32 tx_bd_cfa_meta;
62 	#define TX_BD_CFA_META_MASK                             0xfffffff
63 	#define TX_BD_CFA_META_VID_MASK                         0xfff
64 	#define TX_BD_CFA_META_PRI_MASK                         (0xf << 12)
65 	 #define TX_BD_CFA_META_PRI_SHIFT                        12
66 	#define TX_BD_CFA_META_TPID_MASK                        (3 << 16)
67 	 #define TX_BD_CFA_META_TPID_SHIFT                       16
68 	#define TX_BD_CFA_META_KEY                              (0xf << 28)
69 	 #define TX_BD_CFA_META_KEY_SHIFT			 28
70 	#define TX_BD_CFA_META_KEY_VLAN                         (1 << 28)
71 };
72 
73 struct rx_bd {
74 	__le32 rx_bd_len_flags_type;
75 	#define RX_BD_TYPE					(0x3f << 0)
76 	 #define RX_BD_TYPE_RX_PACKET_BD			 0x4
77 	 #define RX_BD_TYPE_RX_BUFFER_BD			 0x5
78 	 #define RX_BD_TYPE_RX_AGG_BD				 0x6
79 	 #define RX_BD_TYPE_16B_BD_SIZE				 (0 << 4)
80 	 #define RX_BD_TYPE_32B_BD_SIZE				 (1 << 4)
81 	 #define RX_BD_TYPE_48B_BD_SIZE				 (2 << 4)
82 	 #define RX_BD_TYPE_64B_BD_SIZE				 (3 << 4)
83 	#define RX_BD_FLAGS_SOP					(1 << 6)
84 	#define RX_BD_FLAGS_EOP					(1 << 7)
85 	#define RX_BD_FLAGS_BUFFERS				(3 << 8)
86 	 #define RX_BD_FLAGS_1_BUFFER_PACKET			 (0 << 8)
87 	 #define RX_BD_FLAGS_2_BUFFER_PACKET			 (1 << 8)
88 	 #define RX_BD_FLAGS_3_BUFFER_PACKET			 (2 << 8)
89 	 #define RX_BD_FLAGS_4_BUFFER_PACKET			 (3 << 8)
90 	#define RX_BD_LEN					(0xffff << 16)
91 	 #define RX_BD_LEN_SHIFT				 16
92 
93 	u32 rx_bd_opaque;
94 	__le64 rx_bd_haddr;
95 };
96 
97 struct tx_cmp {
98 	__le32 tx_cmp_flags_type;
99 	#define CMP_TYPE					(0x3f << 0)
100 	 #define CMP_TYPE_TX_L2_CMP				 0
101 	 #define CMP_TYPE_RX_L2_CMP				 17
102 	 #define CMP_TYPE_RX_AGG_CMP				 18
103 	 #define CMP_TYPE_RX_L2_TPA_START_CMP			 19
104 	 #define CMP_TYPE_RX_L2_TPA_END_CMP			 21
105 	 #define CMP_TYPE_STATUS_CMP				 32
106 	 #define CMP_TYPE_REMOTE_DRIVER_REQ			 34
107 	 #define CMP_TYPE_REMOTE_DRIVER_RESP			 36
108 	 #define CMP_TYPE_ERROR_STATUS				 48
109 	 #define CMPL_BASE_TYPE_STAT_EJECT			 (0x1aUL << 0)
110 	 #define CMPL_BASE_TYPE_HWRM_DONE			 (0x20UL << 0)
111 	 #define CMPL_BASE_TYPE_HWRM_FWD_REQ			 (0x22UL << 0)
112 	 #define CMPL_BASE_TYPE_HWRM_FWD_RESP			 (0x24UL << 0)
113 	 #define CMPL_BASE_TYPE_HWRM_ASYNC_EVENT		 (0x2eUL << 0)
114 
115 	#define TX_CMP_FLAGS_ERROR				(1 << 6)
116 	#define TX_CMP_FLAGS_PUSH				(1 << 7)
117 
118 	u32 tx_cmp_opaque;
119 	__le32 tx_cmp_errors_v;
120 	#define TX_CMP_V					(1 << 0)
121 	#define TX_CMP_ERRORS_BUFFER_ERROR			(7 << 1)
122 	 #define TX_CMP_ERRORS_BUFFER_ERROR_NO_ERROR		 0
123 	 #define TX_CMP_ERRORS_BUFFER_ERROR_BAD_FORMAT		 2
124 	 #define TX_CMP_ERRORS_BUFFER_ERROR_INVALID_STAG	 4
125 	 #define TX_CMP_ERRORS_BUFFER_ERROR_STAG_BOUNDS		 5
126 	 #define TX_CMP_ERRORS_ZERO_LENGTH_PKT			 (1 << 4)
127 	 #define TX_CMP_ERRORS_EXCESSIVE_BD_LEN			 (1 << 5)
128 	 #define TX_CMP_ERRORS_DMA_ERROR			 (1 << 6)
129 	 #define TX_CMP_ERRORS_HINT_TOO_SHORT			 (1 << 7)
130 
131 	__le32 tx_cmp_unsed_3;
132 };
133 
134 struct rx_cmp {
135 	__le32 rx_cmp_len_flags_type;
136 	#define RX_CMP_CMP_TYPE					(0x3f << 0)
137 	#define RX_CMP_FLAGS_ERROR				(1 << 6)
138 	#define RX_CMP_FLAGS_PLACEMENT				(7 << 7)
139 	#define RX_CMP_FLAGS_RSS_VALID				(1 << 10)
140 	#define RX_CMP_FLAGS_UNUSED				(1 << 11)
141 	 #define RX_CMP_FLAGS_ITYPES_SHIFT			 12
142 	 #define RX_CMP_FLAGS_ITYPE_UNKNOWN			 (0 << 12)
143 	 #define RX_CMP_FLAGS_ITYPE_IP				 (1 << 12)
144 	 #define RX_CMP_FLAGS_ITYPE_TCP				 (2 << 12)
145 	 #define RX_CMP_FLAGS_ITYPE_UDP				 (3 << 12)
146 	 #define RX_CMP_FLAGS_ITYPE_FCOE			 (4 << 12)
147 	 #define RX_CMP_FLAGS_ITYPE_ROCE			 (5 << 12)
148 	 #define RX_CMP_FLAGS_ITYPE_PTP_WO_TS			 (8 << 12)
149 	 #define RX_CMP_FLAGS_ITYPE_PTP_W_TS			 (9 << 12)
150 	#define RX_CMP_LEN					(0xffff << 16)
151 	 #define RX_CMP_LEN_SHIFT				 16
152 
153 	u32 rx_cmp_opaque;
154 	__le32 rx_cmp_misc_v1;
155 	#define RX_CMP_V1					(1 << 0)
156 	#define RX_CMP_AGG_BUFS					(0x1f << 1)
157 	 #define RX_CMP_AGG_BUFS_SHIFT				 1
158 	#define RX_CMP_RSS_HASH_TYPE				(0x7f << 9)
159 	 #define RX_CMP_RSS_HASH_TYPE_SHIFT			 9
160 	#define RX_CMP_PAYLOAD_OFFSET				(0xff << 16)
161 	 #define RX_CMP_PAYLOAD_OFFSET_SHIFT			 16
162 
163 	__le32 rx_cmp_rss_hash;
164 };
165 
166 #define RX_CMP_HASH_VALID(rxcmp)				\
167 	((rxcmp)->rx_cmp_len_flags_type & cpu_to_le32(RX_CMP_FLAGS_RSS_VALID))
168 
169 #define RSS_PROFILE_ID_MASK	0x1f
170 
171 #define RX_CMP_HASH_TYPE(rxcmp)					\
172 	(((le32_to_cpu((rxcmp)->rx_cmp_misc_v1) & RX_CMP_RSS_HASH_TYPE) >>\
173 	  RX_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
174 
175 struct rx_cmp_ext {
176 	__le32 rx_cmp_flags2;
177 	#define RX_CMP_FLAGS2_IP_CS_CALC			0x1
178 	#define RX_CMP_FLAGS2_L4_CS_CALC			(0x1 << 1)
179 	#define RX_CMP_FLAGS2_T_IP_CS_CALC			(0x1 << 2)
180 	#define RX_CMP_FLAGS2_T_L4_CS_CALC			(0x1 << 3)
181 	#define RX_CMP_FLAGS2_META_FORMAT_VLAN			(0x1 << 4)
182 	__le32 rx_cmp_meta_data;
183 	#define RX_CMP_FLAGS2_METADATA_VID_MASK			0xfff
184 	#define RX_CMP_FLAGS2_METADATA_TPID_MASK		0xffff0000
185 	 #define RX_CMP_FLAGS2_METADATA_TPID_SFT		 16
186 	__le32 rx_cmp_cfa_code_errors_v2;
187 	#define RX_CMP_V					(1 << 0)
188 	#define RX_CMPL_ERRORS_MASK				(0x7fff << 1)
189 	 #define RX_CMPL_ERRORS_SFT				 1
190 	#define RX_CMPL_ERRORS_BUFFER_ERROR_MASK		(0x7 << 1)
191 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_NO_BUFFER		 (0x0 << 1)
192 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_DID_NOT_FIT	 (0x1 << 1)
193 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_NOT_ON_CHIP	 (0x2 << 1)
194 	 #define RX_CMPL_ERRORS_BUFFER_ERROR_BAD_FORMAT		 (0x3 << 1)
195 	#define RX_CMPL_ERRORS_IP_CS_ERROR			(0x1 << 4)
196 	#define RX_CMPL_ERRORS_L4_CS_ERROR			(0x1 << 5)
197 	#define RX_CMPL_ERRORS_T_IP_CS_ERROR			(0x1 << 6)
198 	#define RX_CMPL_ERRORS_T_L4_CS_ERROR			(0x1 << 7)
199 	#define RX_CMPL_ERRORS_CRC_ERROR			(0x1 << 8)
200 	#define RX_CMPL_ERRORS_T_PKT_ERROR_MASK			(0x7 << 9)
201 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_NO_ERROR		 (0x0 << 9)
202 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_VERSION	 (0x1 << 9)
203 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_HDR_LEN	 (0x2 << 9)
204 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_TUNNEL_TOTAL_ERROR	 (0x3 << 9)
205 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_IP_TOTAL_ERROR	 (0x4 << 9)
206 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_UDP_TOTAL_ERROR	 (0x5 << 9)
207 	 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_TTL	 (0x6 << 9)
208 	#define RX_CMPL_ERRORS_PKT_ERROR_MASK			(0xf << 12)
209 	 #define RX_CMPL_ERRORS_PKT_ERROR_NO_ERROR		 (0x0 << 12)
210 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_VERSION	 (0x1 << 12)
211 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_HDR_LEN	 (0x2 << 12)
212 	 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_TTL		 (0x3 << 12)
213 	 #define RX_CMPL_ERRORS_PKT_ERROR_IP_TOTAL_ERROR	 (0x4 << 12)
214 	 #define RX_CMPL_ERRORS_PKT_ERROR_UDP_TOTAL_ERROR	 (0x5 << 12)
215 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN	 (0x6 << 12)
216 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN_TOO_SMALL (0x7 << 12)
217 	 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_OPT_LEN	 (0x8 << 12)
218 
219 	#define RX_CMPL_CFA_CODE_MASK				(0xffff << 16)
220 	 #define RX_CMPL_CFA_CODE_SFT				 16
221 
222 	__le32 rx_cmp_unused3;
223 };
224 
225 #define RX_CMP_L2_ERRORS						\
226 	cpu_to_le32(RX_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_CMPL_ERRORS_CRC_ERROR)
227 
228 #define RX_CMP_L4_CS_BITS						\
229 	(cpu_to_le32(RX_CMP_FLAGS2_L4_CS_CALC | RX_CMP_FLAGS2_T_L4_CS_CALC))
230 
231 #define RX_CMP_L4_CS_ERR_BITS						\
232 	(cpu_to_le32(RX_CMPL_ERRORS_L4_CS_ERROR | RX_CMPL_ERRORS_T_L4_CS_ERROR))
233 
234 #define RX_CMP_L4_CS_OK(rxcmp1)						\
235 	    (((rxcmp1)->rx_cmp_flags2 &	RX_CMP_L4_CS_BITS) &&		\
236 	     !((rxcmp1)->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS))
237 
238 #define RX_CMP_ENCAP(rxcmp1)						\
239 	    ((le32_to_cpu((rxcmp1)->rx_cmp_flags2) &			\
240 	     RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3)
241 
242 struct rx_agg_cmp {
243 	__le32 rx_agg_cmp_len_flags_type;
244 	#define RX_AGG_CMP_TYPE					(0x3f << 0)
245 	#define RX_AGG_CMP_LEN					(0xffff << 16)
246 	 #define RX_AGG_CMP_LEN_SHIFT				 16
247 	u32 rx_agg_cmp_opaque;
248 	__le32 rx_agg_cmp_v;
249 	#define RX_AGG_CMP_V					(1 << 0)
250 	__le32 rx_agg_cmp_unused;
251 };
252 
253 struct rx_tpa_start_cmp {
254 	__le32 rx_tpa_start_cmp_len_flags_type;
255 	#define RX_TPA_START_CMP_TYPE				(0x3f << 0)
256 	#define RX_TPA_START_CMP_FLAGS				(0x3ff << 6)
257 	 #define RX_TPA_START_CMP_FLAGS_SHIFT			 6
258 	#define RX_TPA_START_CMP_FLAGS_PLACEMENT		(0x7 << 7)
259 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_SHIFT		 7
260 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_JUMBO		 (0x1 << 7)
261 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_HDS		 (0x2 << 7)
262 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_JUMBO	 (0x5 << 7)
263 	 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_HDS	 (0x6 << 7)
264 	#define RX_TPA_START_CMP_FLAGS_RSS_VALID		(0x1 << 10)
265 	#define RX_TPA_START_CMP_FLAGS_ITYPES			(0xf << 12)
266 	 #define RX_TPA_START_CMP_FLAGS_ITYPES_SHIFT		 12
267 	 #define RX_TPA_START_CMP_FLAGS_ITYPE_TCP		 (0x2 << 12)
268 	#define RX_TPA_START_CMP_LEN				(0xffff << 16)
269 	 #define RX_TPA_START_CMP_LEN_SHIFT			 16
270 
271 	u32 rx_tpa_start_cmp_opaque;
272 	__le32 rx_tpa_start_cmp_misc_v1;
273 	#define RX_TPA_START_CMP_V1				(0x1 << 0)
274 	#define RX_TPA_START_CMP_RSS_HASH_TYPE			(0x7f << 9)
275 	 #define RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT		 9
276 	#define RX_TPA_START_CMP_AGG_ID				(0x7f << 25)
277 	 #define RX_TPA_START_CMP_AGG_ID_SHIFT			 25
278 
279 	__le32 rx_tpa_start_cmp_rss_hash;
280 };
281 
282 #define TPA_START_HASH_VALID(rx_tpa_start)				\
283 	((rx_tpa_start)->rx_tpa_start_cmp_len_flags_type &		\
284 	 cpu_to_le32(RX_TPA_START_CMP_FLAGS_RSS_VALID))
285 
286 #define TPA_START_HASH_TYPE(rx_tpa_start)				\
287 	(((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) &	\
288 	   RX_TPA_START_CMP_RSS_HASH_TYPE) >>				\
289 	  RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
290 
291 #define TPA_START_AGG_ID(rx_tpa_start)					\
292 	((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) &	\
293 	 RX_TPA_START_CMP_AGG_ID) >> RX_TPA_START_CMP_AGG_ID_SHIFT)
294 
295 struct rx_tpa_start_cmp_ext {
296 	__le32 rx_tpa_start_cmp_flags2;
297 	#define RX_TPA_START_CMP_FLAGS2_IP_CS_CALC		(0x1 << 0)
298 	#define RX_TPA_START_CMP_FLAGS2_L4_CS_CALC		(0x1 << 1)
299 	#define RX_TPA_START_CMP_FLAGS2_T_IP_CS_CALC		(0x1 << 2)
300 	#define RX_TPA_START_CMP_FLAGS2_T_L4_CS_CALC		(0x1 << 3)
301 
302 	__le32 rx_tpa_start_cmp_metadata;
303 	__le32 rx_tpa_start_cmp_cfa_code_v2;
304 	#define RX_TPA_START_CMP_V2				(0x1 << 0)
305 	#define RX_TPA_START_CMP_CFA_CODE			(0xffff << 16)
306 	 #define RX_TPA_START_CMPL_CFA_CODE_SHIFT		 16
307 	__le32 rx_tpa_start_cmp_unused5;
308 };
309 
310 struct rx_tpa_end_cmp {
311 	__le32 rx_tpa_end_cmp_len_flags_type;
312 	#define RX_TPA_END_CMP_TYPE				(0x3f << 0)
313 	#define RX_TPA_END_CMP_FLAGS				(0x3ff << 6)
314 	 #define RX_TPA_END_CMP_FLAGS_SHIFT			 6
315 	#define RX_TPA_END_CMP_FLAGS_PLACEMENT			(0x7 << 7)
316 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_SHIFT		 7
317 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_JUMBO		 (0x1 << 7)
318 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_HDS		 (0x2 << 7)
319 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO	 (0x5 << 7)
320 	 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS		 (0x6 << 7)
321 	#define RX_TPA_END_CMP_FLAGS_RSS_VALID			(0x1 << 10)
322 	#define RX_TPA_END_CMP_FLAGS_ITYPES			(0xf << 12)
323 	 #define RX_TPA_END_CMP_FLAGS_ITYPES_SHIFT		 12
324 	 #define RX_TPA_END_CMP_FLAGS_ITYPE_TCP			 (0x2 << 12)
325 	#define RX_TPA_END_CMP_LEN				(0xffff << 16)
326 	 #define RX_TPA_END_CMP_LEN_SHIFT			 16
327 
328 	u32 rx_tpa_end_cmp_opaque;
329 	__le32 rx_tpa_end_cmp_misc_v1;
330 	#define RX_TPA_END_CMP_V1				(0x1 << 0)
331 	#define RX_TPA_END_CMP_AGG_BUFS				(0x3f << 1)
332 	 #define RX_TPA_END_CMP_AGG_BUFS_SHIFT			 1
333 	#define RX_TPA_END_CMP_TPA_SEGS				(0xff << 8)
334 	 #define RX_TPA_END_CMP_TPA_SEGS_SHIFT			 8
335 	#define RX_TPA_END_CMP_PAYLOAD_OFFSET			(0xff << 16)
336 	 #define RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT		 16
337 	#define RX_TPA_END_CMP_AGG_ID				(0x7f << 25)
338 	 #define RX_TPA_END_CMP_AGG_ID_SHIFT			 25
339 
340 	__le32 rx_tpa_end_cmp_tsdelta;
341 	#define RX_TPA_END_GRO_TS				(0x1 << 31)
342 };
343 
344 #define TPA_END_AGG_ID(rx_tpa_end)					\
345 	((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) &		\
346 	 RX_TPA_END_CMP_AGG_ID) >> RX_TPA_END_CMP_AGG_ID_SHIFT)
347 
348 #define TPA_END_TPA_SEGS(rx_tpa_end)					\
349 	((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) &		\
350 	 RX_TPA_END_CMP_TPA_SEGS) >> RX_TPA_END_CMP_TPA_SEGS_SHIFT)
351 
352 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO				\
353 	cpu_to_le32(RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO &		\
354 		    RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS)
355 
356 #define TPA_END_GRO(rx_tpa_end)						\
357 	((rx_tpa_end)->rx_tpa_end_cmp_len_flags_type &			\
358 	 RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO)
359 
360 #define TPA_END_GRO_TS(rx_tpa_end)					\
361 	((rx_tpa_end)->rx_tpa_end_cmp_tsdelta & cpu_to_le32(RX_TPA_END_GRO_TS))
362 
363 struct rx_tpa_end_cmp_ext {
364 	__le32 rx_tpa_end_cmp_dup_acks;
365 	#define RX_TPA_END_CMP_TPA_DUP_ACKS			(0xf << 0)
366 
367 	__le32 rx_tpa_end_cmp_seg_len;
368 	#define RX_TPA_END_CMP_TPA_SEG_LEN			(0xffff << 0)
369 
370 	__le32 rx_tpa_end_cmp_errors_v2;
371 	#define RX_TPA_END_CMP_V2				(0x1 << 0)
372 	#define RX_TPA_END_CMP_ERRORS				(0x7fff << 1)
373 	#define RX_TPA_END_CMPL_ERRORS_SHIFT			 1
374 
375 	u32 rx_tpa_end_cmp_start_opaque;
376 };
377 
378 #define DB_IDX_MASK						0xffffff
379 #define DB_IDX_VALID						(0x1 << 26)
380 #define DB_IRQ_DIS						(0x1 << 27)
381 #define DB_KEY_TX						(0x0 << 28)
382 #define DB_KEY_RX						(0x1 << 28)
383 #define DB_KEY_CP						(0x2 << 28)
384 #define DB_KEY_ST						(0x3 << 28)
385 #define DB_KEY_TX_PUSH						(0x4 << 28)
386 #define DB_LONG_TX_PUSH						(0x2 << 24)
387 
388 #define INVALID_HW_RING_ID	((u16)-1)
389 
390 #define BNXT_RSS_HASH_TYPE_FLAG_IPV4		0x01
391 #define BNXT_RSS_HASH_TYPE_FLAG_TCP_IPV4	0x02
392 #define BNXT_RSS_HASH_TYPE_FLAG_IPV6		0x04
393 #define BNXT_RSS_HASH_TYPE_FLAG_TCP_IPV6	0x08
394 
395 /* The hardware supports certain page sizes.  Use the supported page sizes
396  * to allocate the rings.
397  */
398 #if (PAGE_SHIFT < 12)
399 #define BNXT_PAGE_SHIFT	12
400 #elif (PAGE_SHIFT <= 13)
401 #define BNXT_PAGE_SHIFT	PAGE_SHIFT
402 #elif (PAGE_SHIFT < 16)
403 #define BNXT_PAGE_SHIFT	13
404 #else
405 #define BNXT_PAGE_SHIFT	16
406 #endif
407 
408 #define BNXT_PAGE_SIZE	(1 << BNXT_PAGE_SHIFT)
409 
410 #define BNXT_MIN_PKT_SIZE	45
411 
412 #define BNXT_NUM_TESTS(bp)	0
413 
414 #define BNXT_DEFAULT_RX_RING_SIZE	1023
415 #define BNXT_DEFAULT_TX_RING_SIZE	512
416 
417 #define MAX_TPA		64
418 
419 #define MAX_RX_PAGES	8
420 #define MAX_RX_AGG_PAGES	32
421 #define MAX_TX_PAGES	8
422 #define MAX_CP_PAGES	64
423 
424 #define RX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct rx_bd))
425 #define TX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_bd))
426 #define CP_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_cmp))
427 
428 #define SW_RXBD_RING_SIZE (sizeof(struct bnxt_sw_rx_bd) * RX_DESC_CNT)
429 #define HW_RXBD_RING_SIZE (sizeof(struct rx_bd) * RX_DESC_CNT)
430 
431 #define SW_RXBD_AGG_RING_SIZE (sizeof(struct bnxt_sw_rx_agg_bd) * RX_DESC_CNT)
432 
433 #define SW_TXBD_RING_SIZE (sizeof(struct bnxt_sw_tx_bd) * TX_DESC_CNT)
434 #define HW_TXBD_RING_SIZE (sizeof(struct tx_bd) * TX_DESC_CNT)
435 
436 #define HW_CMPD_RING_SIZE (sizeof(struct tx_cmp) * CP_DESC_CNT)
437 
438 #define BNXT_MAX_RX_DESC_CNT		(RX_DESC_CNT * MAX_RX_PAGES - 1)
439 #define BNXT_MAX_RX_JUM_DESC_CNT	(RX_DESC_CNT * MAX_RX_AGG_PAGES - 1)
440 #define BNXT_MAX_TX_DESC_CNT		(TX_DESC_CNT * MAX_TX_PAGES - 1)
441 
442 #define RX_RING(x)	(((x) & ~(RX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
443 #define RX_IDX(x)	((x) & (RX_DESC_CNT - 1))
444 
445 #define TX_RING(x)	(((x) & ~(TX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
446 #define TX_IDX(x)	((x) & (TX_DESC_CNT - 1))
447 
448 #define CP_RING(x)	(((x) & ~(CP_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
449 #define CP_IDX(x)	((x) & (CP_DESC_CNT - 1))
450 
451 #define TX_CMP_VALID(txcmp, raw_cons)					\
452 	(!!((txcmp)->tx_cmp_errors_v & cpu_to_le32(TX_CMP_V)) ==	\
453 	 !((raw_cons) & bp->cp_bit))
454 
455 #define RX_CMP_VALID(rxcmp1, raw_cons)					\
456 	(!!((rxcmp1)->rx_cmp_cfa_code_errors_v2 & cpu_to_le32(RX_CMP_V)) ==\
457 	 !((raw_cons) & bp->cp_bit))
458 
459 #define RX_AGG_CMP_VALID(agg, raw_cons)				\
460 	(!!((agg)->rx_agg_cmp_v & cpu_to_le32(RX_AGG_CMP_V)) ==	\
461 	 !((raw_cons) & bp->cp_bit))
462 
463 #define TX_CMP_TYPE(txcmp)					\
464 	(le32_to_cpu((txcmp)->tx_cmp_flags_type) & CMP_TYPE)
465 
466 #define RX_CMP_TYPE(rxcmp)					\
467 	(le32_to_cpu((rxcmp)->rx_cmp_len_flags_type) & RX_CMP_CMP_TYPE)
468 
469 #define NEXT_RX(idx)		(((idx) + 1) & bp->rx_ring_mask)
470 
471 #define NEXT_RX_AGG(idx)	(((idx) + 1) & bp->rx_agg_ring_mask)
472 
473 #define NEXT_TX(idx)		(((idx) + 1) & bp->tx_ring_mask)
474 
475 #define ADV_RAW_CMP(idx, n)	((idx) + (n))
476 #define NEXT_RAW_CMP(idx)	ADV_RAW_CMP(idx, 1)
477 #define RING_CMP(idx)		((idx) & bp->cp_ring_mask)
478 #define NEXT_CMP(idx)		RING_CMP(ADV_RAW_CMP(idx, 1))
479 
480 #define HWRM_CMD_TIMEOUT		500
481 #define HWRM_RESET_TIMEOUT		((HWRM_CMD_TIMEOUT) * 4)
482 #define HWRM_RESP_ERR_CODE_MASK		0xffff
483 #define HWRM_RESP_LEN_MASK		0xffff0000
484 #define HWRM_RESP_LEN_SFT		16
485 #define HWRM_RESP_VALID_MASK		0xff000000
486 #define BNXT_HWRM_REQ_MAX_SIZE		128
487 #define BNXT_HWRM_REQS_PER_PAGE		(BNXT_PAGE_SIZE /	\
488 					 BNXT_HWRM_REQ_MAX_SIZE)
489 
490 struct bnxt_sw_tx_bd {
491 	struct sk_buff		*skb;
492 	DEFINE_DMA_UNMAP_ADDR(mapping);
493 	u8			is_gso;
494 	u8			is_push;
495 	unsigned short		nr_frags;
496 };
497 
498 struct bnxt_sw_rx_bd {
499 	u8			*data;
500 	DEFINE_DMA_UNMAP_ADDR(mapping);
501 };
502 
503 struct bnxt_sw_rx_agg_bd {
504 	struct page		*page;
505 	dma_addr_t		mapping;
506 };
507 
508 struct bnxt_ring_struct {
509 	int			nr_pages;
510 	int			page_size;
511 	void			**pg_arr;
512 	dma_addr_t		*dma_arr;
513 
514 	__le64			*pg_tbl;
515 	dma_addr_t		pg_tbl_map;
516 
517 	int			vmem_size;
518 	void			**vmem;
519 
520 	u16			fw_ring_id; /* Ring id filled by Chimp FW */
521 	u8			queue_id;
522 };
523 
524 struct tx_push_bd {
525 	__le32			doorbell;
526 	struct tx_bd		txbd1;
527 	struct tx_bd_ext	txbd2;
528 };
529 
530 struct bnxt_tx_ring_info {
531 	u16			tx_prod;
532 	u16			tx_cons;
533 	void __iomem		*tx_doorbell;
534 
535 	struct tx_bd		*tx_desc_ring[MAX_TX_PAGES];
536 	struct bnxt_sw_tx_bd	*tx_buf_ring;
537 
538 	dma_addr_t		tx_desc_mapping[MAX_TX_PAGES];
539 
540 	struct tx_push_bd	*tx_push;
541 	dma_addr_t		tx_push_mapping;
542 
543 #define BNXT_DEV_STATE_CLOSING	0x1
544 	u32			dev_state;
545 
546 	struct bnxt_ring_struct	tx_ring_struct;
547 };
548 
549 struct bnxt_tpa_info {
550 	u8			*data;
551 	dma_addr_t		mapping;
552 	u16			len;
553 	unsigned short		gso_type;
554 	u32			flags2;
555 	u32			metadata;
556 	enum pkt_hash_types	hash_type;
557 	u32			rss_hash;
558 };
559 
560 struct bnxt_rx_ring_info {
561 	u16			rx_prod;
562 	u16			rx_agg_prod;
563 	u16			rx_sw_agg_prod;
564 	void __iomem		*rx_doorbell;
565 	void __iomem		*rx_agg_doorbell;
566 
567 	struct rx_bd		*rx_desc_ring[MAX_RX_PAGES];
568 	struct bnxt_sw_rx_bd	*rx_buf_ring;
569 
570 	struct rx_bd		*rx_agg_desc_ring[MAX_RX_AGG_PAGES];
571 	struct bnxt_sw_rx_agg_bd	*rx_agg_ring;
572 
573 	unsigned long		*rx_agg_bmap;
574 	u16			rx_agg_bmap_size;
575 
576 	dma_addr_t		rx_desc_mapping[MAX_RX_PAGES];
577 	dma_addr_t		rx_agg_desc_mapping[MAX_RX_AGG_PAGES];
578 
579 	struct bnxt_tpa_info	*rx_tpa;
580 
581 	struct bnxt_ring_struct	rx_ring_struct;
582 	struct bnxt_ring_struct	rx_agg_ring_struct;
583 };
584 
585 struct bnxt_cp_ring_info {
586 	u32			cp_raw_cons;
587 	void __iomem		*cp_doorbell;
588 
589 	struct tx_cmp		*cp_desc_ring[MAX_CP_PAGES];
590 
591 	dma_addr_t		cp_desc_mapping[MAX_CP_PAGES];
592 
593 	struct ctx_hw_stats	*hw_stats;
594 	dma_addr_t		hw_stats_map;
595 	u32			hw_stats_ctx_id;
596 	u64			rx_l4_csum_errors;
597 
598 	struct bnxt_ring_struct	cp_ring_struct;
599 };
600 
601 struct bnxt_napi {
602 	struct napi_struct	napi;
603 	struct bnxt		*bp;
604 
605 	int			index;
606 	struct bnxt_cp_ring_info	cp_ring;
607 	struct bnxt_rx_ring_info	rx_ring;
608 	struct bnxt_tx_ring_info	tx_ring;
609 
610 #ifdef CONFIG_NET_RX_BUSY_POLL
611 	atomic_t		poll_state;
612 #endif
613 };
614 
615 #ifdef CONFIG_NET_RX_BUSY_POLL
616 enum bnxt_poll_state_t {
617 	BNXT_STATE_IDLE = 0,
618 	BNXT_STATE_NAPI,
619 	BNXT_STATE_POLL,
620 	BNXT_STATE_DISABLE,
621 };
622 #endif
623 
624 struct bnxt_irq {
625 	irq_handler_t	handler;
626 	unsigned int	vector;
627 	u8		requested;
628 	char		name[IFNAMSIZ + 2];
629 };
630 
631 #define HWRM_RING_ALLOC_TX	0x1
632 #define HWRM_RING_ALLOC_RX	0x2
633 #define HWRM_RING_ALLOC_AGG	0x4
634 #define HWRM_RING_ALLOC_CMPL	0x8
635 
636 #define INVALID_STATS_CTX_ID	-1
637 
638 struct hwrm_cmd_req_hdr {
639 #define HWRM_CMPL_RING_MASK	0xffff0000
640 #define HWRM_CMPL_RING_SFT	16
641 	__le32	cmpl_ring_req_type;
642 #define HWRM_SEQ_ID_MASK	0xffff
643 #define HWRM_SEQ_ID_INVALID -1
644 #define HWRM_RESP_LEN_OFFSET	4
645 #define HWRM_TARGET_FID_MASK	0xffff0000
646 #define HWRM_TARGET_FID_SFT	16
647 	__le32	target_id_seq_id;
648 	__le64	resp_addr;
649 };
650 
651 struct bnxt_ring_grp_info {
652 	u16	fw_stats_ctx;
653 	u16	fw_grp_id;
654 	u16	rx_fw_ring_id;
655 	u16	agg_fw_ring_id;
656 	u16	cp_fw_ring_id;
657 };
658 
659 struct bnxt_vnic_info {
660 	u16		fw_vnic_id; /* returned by Chimp during alloc */
661 	u16		fw_rss_cos_lb_ctx;
662 	u16		fw_l2_ctx_id;
663 #define BNXT_MAX_UC_ADDRS	4
664 	__le64		fw_l2_filter_id[BNXT_MAX_UC_ADDRS];
665 				/* index 0 always dev_addr */
666 	u16		uc_filter_count;
667 	u8		*uc_list;
668 
669 	u16		*fw_grp_ids;
670 	u16		hash_type;
671 	dma_addr_t	rss_table_dma_addr;
672 	__le16		*rss_table;
673 	dma_addr_t	rss_hash_key_dma_addr;
674 	u64		*rss_hash_key;
675 	u32		rx_mask;
676 
677 	u8		*mc_list;
678 	int		mc_list_size;
679 	int		mc_list_count;
680 	dma_addr_t	mc_list_mapping;
681 #define BNXT_MAX_MC_ADDRS	16
682 
683 	u32		flags;
684 #define BNXT_VNIC_RSS_FLAG	1
685 #define BNXT_VNIC_RFS_FLAG	2
686 #define BNXT_VNIC_MCAST_FLAG	4
687 #define BNXT_VNIC_UCAST_FLAG	8
688 };
689 
690 #if defined(CONFIG_BNXT_SRIOV)
691 struct bnxt_vf_info {
692 	u16	fw_fid;
693 	u8	mac_addr[ETH_ALEN];
694 	u16	max_rsscos_ctxs;
695 	u16	max_cp_rings;
696 	u16	max_tx_rings;
697 	u16	max_rx_rings;
698 	u16	max_l2_ctxs;
699 	u16	max_irqs;
700 	u16	max_vnics;
701 	u16	max_stat_ctxs;
702 	u16	vlan;
703 	u32	flags;
704 #define BNXT_VF_QOS		0x1
705 #define BNXT_VF_SPOOFCHK	0x2
706 #define BNXT_VF_LINK_FORCED	0x4
707 #define BNXT_VF_LINK_UP		0x8
708 	u32	func_flags; /* func cfg flags */
709 	u32	min_tx_rate;
710 	u32	max_tx_rate;
711 	void	*hwrm_cmd_req_addr;
712 	dma_addr_t	hwrm_cmd_req_dma_addr;
713 };
714 #endif
715 
716 struct bnxt_pf_info {
717 #define BNXT_FIRST_PF_FID	1
718 #define BNXT_FIRST_VF_FID	128
719 	u32	fw_fid;
720 	u8	port_id;
721 	u8	mac_addr[ETH_ALEN];
722 	u16	max_rsscos_ctxs;
723 	u16	max_cp_rings;
724 	u16	max_tx_rings; /* HW assigned max tx rings for this PF */
725 	u16	max_pf_tx_rings; /* runtime max tx rings owned by PF */
726 	u16	max_rx_rings; /* HW assigned max rx rings for this PF */
727 	u16	max_pf_rx_rings; /* runtime max rx rings owned by PF */
728 	u16	max_irqs;
729 	u16	max_l2_ctxs;
730 	u16	max_vnics;
731 	u16	max_stat_ctxs;
732 	u32	first_vf_id;
733 	u16	active_vfs;
734 	u16	max_vfs;
735 	u32	max_encap_records;
736 	u32	max_decap_records;
737 	u32	max_tx_em_flows;
738 	u32	max_tx_wm_flows;
739 	u32	max_rx_em_flows;
740 	u32	max_rx_wm_flows;
741 	unsigned long	*vf_event_bmap;
742 	u16	hwrm_cmd_req_pages;
743 	void			*hwrm_cmd_req_addr[4];
744 	dma_addr_t		hwrm_cmd_req_dma_addr[4];
745 	struct bnxt_vf_info	*vf;
746 };
747 
748 struct bnxt_ntuple_filter {
749 	struct hlist_node	hash;
750 	u8			src_mac_addr[ETH_ALEN];
751 	struct flow_keys	fkeys;
752 	__le64			filter_id;
753 	u16			sw_id;
754 	u16			rxq;
755 	u32			flow_id;
756 	unsigned long		state;
757 #define BNXT_FLTR_VALID		0
758 #define BNXT_FLTR_UPDATE	1
759 };
760 
761 #define BNXT_ALL_COPPER_ETHTOOL_SPEED				\
762 	(ADVERTISED_100baseT_Full | ADVERTISED_1000baseT_Full |	\
763 	 ADVERTISED_10000baseT_Full)
764 
765 struct bnxt_link_info {
766 	u8			media_type;
767 	u8			transceiver;
768 	u8			phy_addr;
769 	u8			phy_link_status;
770 #define BNXT_LINK_NO_LINK	PORT_PHY_QCFG_RESP_LINK_NO_LINK
771 #define BNXT_LINK_SIGNAL	PORT_PHY_QCFG_RESP_LINK_SIGNAL
772 #define BNXT_LINK_LINK		PORT_PHY_QCFG_RESP_LINK_LINK
773 	u8			wire_speed;
774 	u8			loop_back;
775 	u8			link_up;
776 	u8			duplex;
777 #define BNXT_LINK_DUPLEX_HALF	PORT_PHY_QCFG_RESP_DUPLEX_HALF
778 #define BNXT_LINK_DUPLEX_FULL	PORT_PHY_QCFG_RESP_DUPLEX_FULL
779 	u8			pause;
780 #define BNXT_LINK_PAUSE_TX	PORT_PHY_QCFG_RESP_PAUSE_TX
781 #define BNXT_LINK_PAUSE_RX	PORT_PHY_QCFG_RESP_PAUSE_RX
782 #define BNXT_LINK_PAUSE_BOTH	(PORT_PHY_QCFG_RESP_PAUSE_RX | \
783 				 PORT_PHY_QCFG_RESP_PAUSE_TX)
784 	u8			auto_pause_setting;
785 	u8			force_pause_setting;
786 	u8			duplex_setting;
787 	u8			auto_mode;
788 #define BNXT_AUTO_MODE(mode)	((mode) > BNXT_LINK_AUTO_NONE && \
789 				 (mode) <= BNXT_LINK_AUTO_MSK)
790 #define BNXT_LINK_AUTO_NONE     PORT_PHY_QCFG_RESP_AUTO_MODE_NONE
791 #define BNXT_LINK_AUTO_ALLSPDS	PORT_PHY_QCFG_RESP_AUTO_MODE_ALL_SPEEDS
792 #define BNXT_LINK_AUTO_ONESPD	PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_SPEED
793 #define BNXT_LINK_AUTO_ONEORBELOW PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_OR_BELOW
794 #define BNXT_LINK_AUTO_MSK	PORT_PHY_QCFG_RESP_AUTO_MODE_MASK
795 #define PHY_VER_LEN		3
796 	u8			phy_ver[PHY_VER_LEN];
797 	u16			link_speed;
798 #define BNXT_LINK_SPEED_100MB	PORT_PHY_QCFG_RESP_LINK_SPEED_100MB
799 #define BNXT_LINK_SPEED_1GB	PORT_PHY_QCFG_RESP_LINK_SPEED_1GB
800 #define BNXT_LINK_SPEED_2GB	PORT_PHY_QCFG_RESP_LINK_SPEED_2GB
801 #define BNXT_LINK_SPEED_2_5GB	PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB
802 #define BNXT_LINK_SPEED_10GB	PORT_PHY_QCFG_RESP_LINK_SPEED_10GB
803 #define BNXT_LINK_SPEED_20GB	PORT_PHY_QCFG_RESP_LINK_SPEED_20GB
804 #define BNXT_LINK_SPEED_25GB	PORT_PHY_QCFG_RESP_LINK_SPEED_25GB
805 #define BNXT_LINK_SPEED_40GB	PORT_PHY_QCFG_RESP_LINK_SPEED_40GB
806 #define BNXT_LINK_SPEED_50GB	PORT_PHY_QCFG_RESP_LINK_SPEED_50GB
807 	u16			support_speeds;
808 	u16			auto_link_speeds;
809 #define BNXT_LINK_SPEED_MSK_100MB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_100MB
810 #define BNXT_LINK_SPEED_MSK_1GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_1GB
811 #define BNXT_LINK_SPEED_MSK_2GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2GB
812 #define BNXT_LINK_SPEED_MSK_10GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_10GB
813 #define BNXT_LINK_SPEED_MSK_2_5GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2_5GB
814 #define BNXT_LINK_SPEED_MSK_20GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_20GB
815 #define BNXT_LINK_SPEED_MSK_25GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_25GB
816 #define BNXT_LINK_SPEED_MSK_40GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_40GB
817 #define BNXT_LINK_SPEED_MSK_50GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_50GB
818 	u16			auto_link_speed;
819 	u16			force_link_speed;
820 	u32			preemphasis;
821 
822 	/* copy of requested setting from ethtool cmd */
823 	u8			autoneg;
824 #define BNXT_AUTONEG_SPEED		1
825 #define BNXT_AUTONEG_FLOW_CTRL		2
826 	u8			req_duplex;
827 	u8			req_flow_ctrl;
828 	u16			req_link_speed;
829 	u32			advertising;
830 	bool			force_link_chng;
831 	/* a copy of phy_qcfg output used to report link
832 	 * info to VF
833 	 */
834 	struct hwrm_port_phy_qcfg_output phy_qcfg_resp;
835 };
836 
837 #define BNXT_MAX_QUEUE	8
838 
839 struct bnxt_queue_info {
840 	u8	queue_id;
841 	u8	queue_profile;
842 };
843 
844 #define BNXT_GRCPF_REG_WINDOW_BASE_OUT	0x400
845 #define BNXT_CAG_REG_LEGACY_INT_STATUS	0x4014
846 #define BNXT_CAG_REG_BASE		0x300000
847 
848 struct bnxt {
849 	void __iomem		*bar0;
850 	void __iomem		*bar1;
851 	void __iomem		*bar2;
852 
853 	u32			reg_base;
854 
855 	struct net_device	*dev;
856 	struct pci_dev		*pdev;
857 
858 	atomic_t		intr_sem;
859 
860 	u32			flags;
861 	#define BNXT_FLAG_DCB_ENABLED	0x1
862 	#define BNXT_FLAG_VF		0x2
863 	#define BNXT_FLAG_LRO		0x4
864 #ifdef CONFIG_INET
865 	#define BNXT_FLAG_GRO		0x8
866 #else
867 	/* Cannot support hardware GRO if CONFIG_INET is not set */
868 	#define BNXT_FLAG_GRO		0x0
869 #endif
870 	#define BNXT_FLAG_TPA		(BNXT_FLAG_LRO | BNXT_FLAG_GRO)
871 	#define BNXT_FLAG_JUMBO		0x10
872 	#define BNXT_FLAG_STRIP_VLAN	0x20
873 	#define BNXT_FLAG_AGG_RINGS	(BNXT_FLAG_JUMBO | BNXT_FLAG_GRO | \
874 					 BNXT_FLAG_LRO)
875 	#define BNXT_FLAG_USING_MSIX	0x40
876 	#define BNXT_FLAG_MSIX_CAP	0x80
877 	#define BNXT_FLAG_RFS		0x100
878 	#define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA |		\
879 					    BNXT_FLAG_RFS |		\
880 					    BNXT_FLAG_STRIP_VLAN)
881 
882 #define BNXT_PF(bp)		(!((bp)->flags & BNXT_FLAG_VF))
883 #define BNXT_VF(bp)		((bp)->flags & BNXT_FLAG_VF)
884 
885 	struct bnxt_napi	**bnapi;
886 
887 	u32			rx_buf_size;
888 	u32			rx_buf_use_size;	/* useable size */
889 	u32			rx_ring_size;
890 	u32			rx_agg_ring_size;
891 	u32			rx_copy_thresh;
892 	u32			rx_ring_mask;
893 	u32			rx_agg_ring_mask;
894 	int			rx_nr_pages;
895 	int			rx_agg_nr_pages;
896 	int			rx_nr_rings;
897 	int			rsscos_nr_ctxs;
898 
899 	u32			tx_ring_size;
900 	u32			tx_ring_mask;
901 	int			tx_nr_pages;
902 	int			tx_nr_rings;
903 	int			tx_nr_rings_per_tc;
904 
905 	int			tx_wake_thresh;
906 	int			tx_push_thresh;
907 	int			tx_push_size;
908 
909 	u32			cp_ring_size;
910 	u32			cp_ring_mask;
911 	u32			cp_bit;
912 	int			cp_nr_pages;
913 	int			cp_nr_rings;
914 
915 	int			num_stat_ctxs;
916 	struct bnxt_ring_grp_info	*grp_info;
917 	struct bnxt_vnic_info	*vnic_info;
918 	int			nr_vnics;
919 
920 	u8			max_tc;
921 	struct bnxt_queue_info	q_info[BNXT_MAX_QUEUE];
922 
923 	unsigned int		current_interval;
924 #define BNXT_TIMER_INTERVAL	(HZ / 2)
925 
926 	struct timer_list	timer;
927 
928 	unsigned long		state;
929 #define BNXT_STATE_OPEN		0
930 #define BNXT_STATE_IN_SP_TASK	1
931 
932 	struct bnxt_irq	*irq_tbl;
933 	u8			mac_addr[ETH_ALEN];
934 
935 	u32			msg_enable;
936 
937 	u16			hwrm_cmd_seq;
938 	u32			hwrm_intr_seq_id;
939 	void			*hwrm_cmd_resp_addr;
940 	dma_addr_t		hwrm_cmd_resp_dma_addr;
941 	void			*hwrm_dbg_resp_addr;
942 	dma_addr_t		hwrm_dbg_resp_dma_addr;
943 #define HWRM_DBG_REG_BUF_SIZE	128
944 	struct mutex		hwrm_cmd_lock;	/* serialize hwrm messages */
945 	struct hwrm_ver_get_output	ver_resp;
946 #define FW_VER_STR_LEN		32
947 #define BC_HWRM_STR_LEN		21
948 #define PHY_VER_STR_LEN         (FW_VER_STR_LEN - BC_HWRM_STR_LEN)
949 	char			fw_ver_str[FW_VER_STR_LEN];
950 	__be16			vxlan_port;
951 	u8			vxlan_port_cnt;
952 	__le16			vxlan_fw_dst_port_id;
953 	u8			nge_port_cnt;
954 	__le16			nge_fw_dst_port_id;
955 	u16			coal_ticks;
956 	u16			coal_ticks_irq;
957 	u16			coal_bufs;
958 	u16			coal_bufs_irq;
959 
960 #define BNXT_USEC_TO_COAL_TIMER(x)	((x) * 25 / 2)
961 #define BNXT_COAL_TIMER_TO_USEC(x) ((x) * 2 / 25)
962 
963 	struct work_struct	sp_task;
964 	unsigned long		sp_event;
965 #define BNXT_RX_MASK_SP_EVENT		0
966 #define BNXT_RX_NTP_FLTR_SP_EVENT	1
967 #define BNXT_LINK_CHNG_SP_EVENT		2
968 #define BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT	3
969 #define BNXT_VXLAN_ADD_PORT_SP_EVENT	4
970 #define BNXT_VXLAN_DEL_PORT_SP_EVENT	5
971 #define BNXT_RESET_TASK_SP_EVENT	6
972 #define BNXT_RST_RING_SP_EVENT		7
973 
974 	struct bnxt_pf_info	pf;
975 #ifdef CONFIG_BNXT_SRIOV
976 	int			nr_vfs;
977 	struct bnxt_vf_info	vf;
978 	wait_queue_head_t	sriov_cfg_wait;
979 	bool			sriov_cfg;
980 #define BNXT_SRIOV_CFG_WAIT_TMO	msecs_to_jiffies(10000)
981 #endif
982 
983 #define BNXT_NTP_FLTR_MAX_FLTR	4096
984 #define BNXT_NTP_FLTR_HASH_SIZE	512
985 #define BNXT_NTP_FLTR_HASH_MASK	(BNXT_NTP_FLTR_HASH_SIZE - 1)
986 	struct hlist_head	ntp_fltr_hash_tbl[BNXT_NTP_FLTR_HASH_SIZE];
987 	spinlock_t		ntp_fltr_lock;	/* for hash table add, del */
988 
989 	unsigned long		*ntp_fltr_bmap;
990 	int			ntp_fltr_count;
991 
992 	struct bnxt_link_info	link_info;
993 };
994 
995 #ifdef CONFIG_NET_RX_BUSY_POLL
bnxt_enable_poll(struct bnxt_napi * bnapi)996 static inline void bnxt_enable_poll(struct bnxt_napi *bnapi)
997 {
998 	atomic_set(&bnapi->poll_state, BNXT_STATE_IDLE);
999 }
1000 
1001 /* called from the NAPI poll routine to get ownership of a bnapi */
bnxt_lock_napi(struct bnxt_napi * bnapi)1002 static inline bool bnxt_lock_napi(struct bnxt_napi *bnapi)
1003 {
1004 	int rc = atomic_cmpxchg(&bnapi->poll_state, BNXT_STATE_IDLE,
1005 				BNXT_STATE_NAPI);
1006 
1007 	return rc == BNXT_STATE_IDLE;
1008 }
1009 
bnxt_unlock_napi(struct bnxt_napi * bnapi)1010 static inline void bnxt_unlock_napi(struct bnxt_napi *bnapi)
1011 {
1012 	atomic_set(&bnapi->poll_state, BNXT_STATE_IDLE);
1013 }
1014 
1015 /* called from the busy poll routine to get ownership of a bnapi */
bnxt_lock_poll(struct bnxt_napi * bnapi)1016 static inline bool bnxt_lock_poll(struct bnxt_napi *bnapi)
1017 {
1018 	int rc = atomic_cmpxchg(&bnapi->poll_state, BNXT_STATE_IDLE,
1019 				BNXT_STATE_POLL);
1020 
1021 	return rc == BNXT_STATE_IDLE;
1022 }
1023 
bnxt_unlock_poll(struct bnxt_napi * bnapi)1024 static inline void bnxt_unlock_poll(struct bnxt_napi *bnapi)
1025 {
1026 	atomic_set(&bnapi->poll_state, BNXT_STATE_IDLE);
1027 }
1028 
bnxt_busy_polling(struct bnxt_napi * bnapi)1029 static inline bool bnxt_busy_polling(struct bnxt_napi *bnapi)
1030 {
1031 	return atomic_read(&bnapi->poll_state) == BNXT_STATE_POLL;
1032 }
1033 
bnxt_disable_poll(struct bnxt_napi * bnapi)1034 static inline void bnxt_disable_poll(struct bnxt_napi *bnapi)
1035 {
1036 	int old;
1037 
1038 	while (1) {
1039 		old = atomic_cmpxchg(&bnapi->poll_state, BNXT_STATE_IDLE,
1040 				     BNXT_STATE_DISABLE);
1041 		if (old == BNXT_STATE_IDLE)
1042 			break;
1043 		usleep_range(500, 5000);
1044 	}
1045 }
1046 
1047 #else
1048 
bnxt_enable_poll(struct bnxt_napi * bnapi)1049 static inline void bnxt_enable_poll(struct bnxt_napi *bnapi)
1050 {
1051 }
1052 
bnxt_lock_napi(struct bnxt_napi * bnapi)1053 static inline bool bnxt_lock_napi(struct bnxt_napi *bnapi)
1054 {
1055 	return true;
1056 }
1057 
bnxt_unlock_napi(struct bnxt_napi * bnapi)1058 static inline void bnxt_unlock_napi(struct bnxt_napi *bnapi)
1059 {
1060 }
1061 
bnxt_lock_poll(struct bnxt_napi * bnapi)1062 static inline bool bnxt_lock_poll(struct bnxt_napi *bnapi)
1063 {
1064 	return false;
1065 }
1066 
bnxt_unlock_poll(struct bnxt_napi * bnapi)1067 static inline void bnxt_unlock_poll(struct bnxt_napi *bnapi)
1068 {
1069 }
1070 
bnxt_busy_polling(struct bnxt_napi * bnapi)1071 static inline bool bnxt_busy_polling(struct bnxt_napi *bnapi)
1072 {
1073 	return false;
1074 }
1075 
bnxt_disable_poll(struct bnxt_napi * bnapi)1076 static inline void bnxt_disable_poll(struct bnxt_napi *bnapi)
1077 {
1078 }
1079 
1080 #endif
1081 
1082 void bnxt_set_ring_params(struct bnxt *);
1083 void bnxt_hwrm_cmd_hdr_init(struct bnxt *, void *, u16, u16, u16);
1084 int _hwrm_send_message(struct bnxt *, void *, u32, int);
1085 int hwrm_send_message(struct bnxt *, void *, u32, int);
1086 int bnxt_hwrm_set_coal(struct bnxt *);
1087 int bnxt_hwrm_set_pause(struct bnxt *);
1088 int bnxt_hwrm_set_link_setting(struct bnxt *, bool);
1089 int bnxt_open_nic(struct bnxt *, bool, bool);
1090 int bnxt_close_nic(struct bnxt *, bool, bool);
1091 void bnxt_get_max_rings(struct bnxt *, int *, int *);
1092 #endif
1093