blob: 290f42669ba5b19c821cdd23d000bc5d7cbc4a28 [file] [log] [blame]
Michael Chanc0c050c2015-10-22 16:01:17 -04001/* Broadcom NetXtreme-C/E network driver.
2 *
Michael Chan11f15ed2016-04-05 14:08:55 -04003 * Copyright (c) 2014-2016 Broadcom Corporation
Michael Chan894aa692018-01-17 03:21:03 -05004 * Copyright (c) 2016-2018 Broadcom Limited
Michael Chanc0c050c2015-10-22 16:01:17 -04005 *
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"
Michael Chan31d357c2018-10-14 07:02:37 -040015#define DRV_MODULE_VERSION "1.10.0"
Michael Chanc0c050c2015-10-22 16:01:17 -040016
Michael Chanc1935542015-12-27 18:19:28 -050017#define DRV_VER_MAJ 1
Michael Chan31d357c2018-10-14 07:02:37 -040018#define DRV_VER_MIN 10
19#define DRV_VER_UPD 0
Michael Chanc0c050c2015-10-22 16:01:17 -040020
Florian Westphal282ccf62017-03-29 17:17:31 +020021#include <linux/interrupt.h>
Sathya Perla2ae74082017-08-28 13:40:33 -040022#include <linux/rhashtable.h>
Michael Chand6295222019-05-22 19:12:56 -040023#include <linux/crash_dump.h>
Sathya Perla4ab0c6a2017-07-24 12:34:27 -040024#include <net/devlink.h>
Sathya Perlaee5c7fb2017-07-24 12:34:28 -040025#include <net/dst_metadata.h>
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +010026#include <net/xdp.h>
Tal Gilboa4f75da32019-01-10 17:33:17 +020027#include <linux/dim.h>
Florian Westphal282ccf62017-03-29 17:17:31 +020028
Andy Gospodarek322b87c2019-07-08 17:53:04 -040029struct page_pool;
30
Michael Chanc0c050c2015-10-22 16:01:17 -040031struct tx_bd {
32 __le32 tx_bd_len_flags_type;
33 #define TX_BD_TYPE (0x3f << 0)
34 #define TX_BD_TYPE_SHORT_TX_BD (0x00 << 0)
35 #define TX_BD_TYPE_LONG_TX_BD (0x10 << 0)
36 #define TX_BD_FLAGS_PACKET_END (1 << 6)
37 #define TX_BD_FLAGS_NO_CMPL (1 << 7)
38 #define TX_BD_FLAGS_BD_CNT (0x1f << 8)
39 #define TX_BD_FLAGS_BD_CNT_SHIFT 8
40 #define TX_BD_FLAGS_LHINT (3 << 13)
41 #define TX_BD_FLAGS_LHINT_SHIFT 13
42 #define TX_BD_FLAGS_LHINT_512_AND_SMALLER (0 << 13)
43 #define TX_BD_FLAGS_LHINT_512_TO_1023 (1 << 13)
44 #define TX_BD_FLAGS_LHINT_1024_TO_2047 (2 << 13)
45 #define TX_BD_FLAGS_LHINT_2048_AND_LARGER (3 << 13)
46 #define TX_BD_FLAGS_COAL_NOW (1 << 15)
47 #define TX_BD_LEN (0xffff << 16)
48 #define TX_BD_LEN_SHIFT 16
49
50 u32 tx_bd_opaque;
51 __le64 tx_bd_haddr;
52} __packed;
53
54struct tx_bd_ext {
55 __le32 tx_bd_hsize_lflags;
56 #define TX_BD_FLAGS_TCP_UDP_CHKSUM (1 << 0)
57 #define TX_BD_FLAGS_IP_CKSUM (1 << 1)
58 #define TX_BD_FLAGS_NO_CRC (1 << 2)
59 #define TX_BD_FLAGS_STAMP (1 << 3)
60 #define TX_BD_FLAGS_T_IP_CHKSUM (1 << 4)
61 #define TX_BD_FLAGS_LSO (1 << 5)
62 #define TX_BD_FLAGS_IPID_FMT (1 << 6)
63 #define TX_BD_FLAGS_T_IPID (1 << 7)
64 #define TX_BD_HSIZE (0xff << 16)
65 #define TX_BD_HSIZE_SHIFT 16
66
67 __le32 tx_bd_mss;
68 __le32 tx_bd_cfa_action;
69 #define TX_BD_CFA_ACTION (0xffff << 16)
70 #define TX_BD_CFA_ACTION_SHIFT 16
71
72 __le32 tx_bd_cfa_meta;
73 #define TX_BD_CFA_META_MASK 0xfffffff
74 #define TX_BD_CFA_META_VID_MASK 0xfff
75 #define TX_BD_CFA_META_PRI_MASK (0xf << 12)
76 #define TX_BD_CFA_META_PRI_SHIFT 12
77 #define TX_BD_CFA_META_TPID_MASK (3 << 16)
78 #define TX_BD_CFA_META_TPID_SHIFT 16
79 #define TX_BD_CFA_META_KEY (0xf << 28)
80 #define TX_BD_CFA_META_KEY_SHIFT 28
81 #define TX_BD_CFA_META_KEY_VLAN (1 << 28)
82};
83
84struct rx_bd {
85 __le32 rx_bd_len_flags_type;
86 #define RX_BD_TYPE (0x3f << 0)
87 #define RX_BD_TYPE_RX_PACKET_BD 0x4
88 #define RX_BD_TYPE_RX_BUFFER_BD 0x5
89 #define RX_BD_TYPE_RX_AGG_BD 0x6
90 #define RX_BD_TYPE_16B_BD_SIZE (0 << 4)
91 #define RX_BD_TYPE_32B_BD_SIZE (1 << 4)
92 #define RX_BD_TYPE_48B_BD_SIZE (2 << 4)
93 #define RX_BD_TYPE_64B_BD_SIZE (3 << 4)
94 #define RX_BD_FLAGS_SOP (1 << 6)
95 #define RX_BD_FLAGS_EOP (1 << 7)
96 #define RX_BD_FLAGS_BUFFERS (3 << 8)
97 #define RX_BD_FLAGS_1_BUFFER_PACKET (0 << 8)
98 #define RX_BD_FLAGS_2_BUFFER_PACKET (1 << 8)
99 #define RX_BD_FLAGS_3_BUFFER_PACKET (2 << 8)
100 #define RX_BD_FLAGS_4_BUFFER_PACKET (3 << 8)
101 #define RX_BD_LEN (0xffff << 16)
102 #define RX_BD_LEN_SHIFT 16
103
104 u32 rx_bd_opaque;
105 __le64 rx_bd_haddr;
106};
107
108struct tx_cmp {
109 __le32 tx_cmp_flags_type;
110 #define CMP_TYPE (0x3f << 0)
111 #define CMP_TYPE_TX_L2_CMP 0
112 #define CMP_TYPE_RX_L2_CMP 17
113 #define CMP_TYPE_RX_AGG_CMP 18
114 #define CMP_TYPE_RX_L2_TPA_START_CMP 19
115 #define CMP_TYPE_RX_L2_TPA_END_CMP 21
Michael Chan218a8a72019-07-29 06:10:19 -0400116 #define CMP_TYPE_RX_TPA_AGG_CMP 22
Michael Chanc0c050c2015-10-22 16:01:17 -0400117 #define CMP_TYPE_STATUS_CMP 32
118 #define CMP_TYPE_REMOTE_DRIVER_REQ 34
119 #define CMP_TYPE_REMOTE_DRIVER_RESP 36
120 #define CMP_TYPE_ERROR_STATUS 48
Michael Chan441cabb2016-09-19 03:58:02 -0400121 #define CMPL_BASE_TYPE_STAT_EJECT 0x1aUL
122 #define CMPL_BASE_TYPE_HWRM_DONE 0x20UL
123 #define CMPL_BASE_TYPE_HWRM_FWD_REQ 0x22UL
124 #define CMPL_BASE_TYPE_HWRM_FWD_RESP 0x24UL
125 #define CMPL_BASE_TYPE_HWRM_ASYNC_EVENT 0x2eUL
Michael Chanc0c050c2015-10-22 16:01:17 -0400126
127 #define TX_CMP_FLAGS_ERROR (1 << 6)
128 #define TX_CMP_FLAGS_PUSH (1 << 7)
129
130 u32 tx_cmp_opaque;
131 __le32 tx_cmp_errors_v;
132 #define TX_CMP_V (1 << 0)
133 #define TX_CMP_ERRORS_BUFFER_ERROR (7 << 1)
134 #define TX_CMP_ERRORS_BUFFER_ERROR_NO_ERROR 0
135 #define TX_CMP_ERRORS_BUFFER_ERROR_BAD_FORMAT 2
136 #define TX_CMP_ERRORS_BUFFER_ERROR_INVALID_STAG 4
137 #define TX_CMP_ERRORS_BUFFER_ERROR_STAG_BOUNDS 5
138 #define TX_CMP_ERRORS_ZERO_LENGTH_PKT (1 << 4)
139 #define TX_CMP_ERRORS_EXCESSIVE_BD_LEN (1 << 5)
140 #define TX_CMP_ERRORS_DMA_ERROR (1 << 6)
141 #define TX_CMP_ERRORS_HINT_TOO_SHORT (1 << 7)
142
143 __le32 tx_cmp_unsed_3;
144};
145
146struct rx_cmp {
147 __le32 rx_cmp_len_flags_type;
148 #define RX_CMP_CMP_TYPE (0x3f << 0)
149 #define RX_CMP_FLAGS_ERROR (1 << 6)
150 #define RX_CMP_FLAGS_PLACEMENT (7 << 7)
151 #define RX_CMP_FLAGS_RSS_VALID (1 << 10)
152 #define RX_CMP_FLAGS_UNUSED (1 << 11)
153 #define RX_CMP_FLAGS_ITYPES_SHIFT 12
154 #define RX_CMP_FLAGS_ITYPE_UNKNOWN (0 << 12)
155 #define RX_CMP_FLAGS_ITYPE_IP (1 << 12)
156 #define RX_CMP_FLAGS_ITYPE_TCP (2 << 12)
157 #define RX_CMP_FLAGS_ITYPE_UDP (3 << 12)
158 #define RX_CMP_FLAGS_ITYPE_FCOE (4 << 12)
159 #define RX_CMP_FLAGS_ITYPE_ROCE (5 << 12)
160 #define RX_CMP_FLAGS_ITYPE_PTP_WO_TS (8 << 12)
161 #define RX_CMP_FLAGS_ITYPE_PTP_W_TS (9 << 12)
162 #define RX_CMP_LEN (0xffff << 16)
163 #define RX_CMP_LEN_SHIFT 16
164
165 u32 rx_cmp_opaque;
166 __le32 rx_cmp_misc_v1;
167 #define RX_CMP_V1 (1 << 0)
168 #define RX_CMP_AGG_BUFS (0x1f << 1)
169 #define RX_CMP_AGG_BUFS_SHIFT 1
170 #define RX_CMP_RSS_HASH_TYPE (0x7f << 9)
171 #define RX_CMP_RSS_HASH_TYPE_SHIFT 9
172 #define RX_CMP_PAYLOAD_OFFSET (0xff << 16)
173 #define RX_CMP_PAYLOAD_OFFSET_SHIFT 16
174
175 __le32 rx_cmp_rss_hash;
176};
177
178#define RX_CMP_HASH_VALID(rxcmp) \
179 ((rxcmp)->rx_cmp_len_flags_type & cpu_to_le32(RX_CMP_FLAGS_RSS_VALID))
180
Michael Chan614388c2015-11-05 16:25:48 -0500181#define RSS_PROFILE_ID_MASK 0x1f
182
Michael Chanc0c050c2015-10-22 16:01:17 -0400183#define RX_CMP_HASH_TYPE(rxcmp) \
Michael Chan614388c2015-11-05 16:25:48 -0500184 (((le32_to_cpu((rxcmp)->rx_cmp_misc_v1) & RX_CMP_RSS_HASH_TYPE) >>\
185 RX_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
Michael Chanc0c050c2015-10-22 16:01:17 -0400186
187struct rx_cmp_ext {
188 __le32 rx_cmp_flags2;
189 #define RX_CMP_FLAGS2_IP_CS_CALC 0x1
190 #define RX_CMP_FLAGS2_L4_CS_CALC (0x1 << 1)
191 #define RX_CMP_FLAGS2_T_IP_CS_CALC (0x1 << 2)
192 #define RX_CMP_FLAGS2_T_L4_CS_CALC (0x1 << 3)
193 #define RX_CMP_FLAGS2_META_FORMAT_VLAN (0x1 << 4)
194 __le32 rx_cmp_meta_data;
Michael Chaned7bc6022018-03-09 23:46:06 -0500195 #define RX_CMP_FLAGS2_METADATA_TCI_MASK 0xffff
Michael Chanc0c050c2015-10-22 16:01:17 -0400196 #define RX_CMP_FLAGS2_METADATA_VID_MASK 0xfff
197 #define RX_CMP_FLAGS2_METADATA_TPID_MASK 0xffff0000
198 #define RX_CMP_FLAGS2_METADATA_TPID_SFT 16
199 __le32 rx_cmp_cfa_code_errors_v2;
200 #define RX_CMP_V (1 << 0)
201 #define RX_CMPL_ERRORS_MASK (0x7fff << 1)
202 #define RX_CMPL_ERRORS_SFT 1
203 #define RX_CMPL_ERRORS_BUFFER_ERROR_MASK (0x7 << 1)
204 #define RX_CMPL_ERRORS_BUFFER_ERROR_NO_BUFFER (0x0 << 1)
205 #define RX_CMPL_ERRORS_BUFFER_ERROR_DID_NOT_FIT (0x1 << 1)
206 #define RX_CMPL_ERRORS_BUFFER_ERROR_NOT_ON_CHIP (0x2 << 1)
207 #define RX_CMPL_ERRORS_BUFFER_ERROR_BAD_FORMAT (0x3 << 1)
208 #define RX_CMPL_ERRORS_IP_CS_ERROR (0x1 << 4)
209 #define RX_CMPL_ERRORS_L4_CS_ERROR (0x1 << 5)
210 #define RX_CMPL_ERRORS_T_IP_CS_ERROR (0x1 << 6)
211 #define RX_CMPL_ERRORS_T_L4_CS_ERROR (0x1 << 7)
212 #define RX_CMPL_ERRORS_CRC_ERROR (0x1 << 8)
213 #define RX_CMPL_ERRORS_T_PKT_ERROR_MASK (0x7 << 9)
214 #define RX_CMPL_ERRORS_T_PKT_ERROR_NO_ERROR (0x0 << 9)
215 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_VERSION (0x1 << 9)
216 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_HDR_LEN (0x2 << 9)
217 #define RX_CMPL_ERRORS_T_PKT_ERROR_TUNNEL_TOTAL_ERROR (0x3 << 9)
218 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_IP_TOTAL_ERROR (0x4 << 9)
219 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_UDP_TOTAL_ERROR (0x5 << 9)
220 #define RX_CMPL_ERRORS_T_PKT_ERROR_T_L3_BAD_TTL (0x6 << 9)
221 #define RX_CMPL_ERRORS_PKT_ERROR_MASK (0xf << 12)
222 #define RX_CMPL_ERRORS_PKT_ERROR_NO_ERROR (0x0 << 12)
223 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_VERSION (0x1 << 12)
224 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_HDR_LEN (0x2 << 12)
225 #define RX_CMPL_ERRORS_PKT_ERROR_L3_BAD_TTL (0x3 << 12)
226 #define RX_CMPL_ERRORS_PKT_ERROR_IP_TOTAL_ERROR (0x4 << 12)
227 #define RX_CMPL_ERRORS_PKT_ERROR_UDP_TOTAL_ERROR (0x5 << 12)
228 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN (0x6 << 12)
229 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_HDR_LEN_TOO_SMALL (0x7 << 12)
230 #define RX_CMPL_ERRORS_PKT_ERROR_L4_BAD_OPT_LEN (0x8 << 12)
231
232 #define RX_CMPL_CFA_CODE_MASK (0xffff << 16)
233 #define RX_CMPL_CFA_CODE_SFT 16
234
235 __le32 rx_cmp_unused3;
236};
237
238#define RX_CMP_L2_ERRORS \
239 cpu_to_le32(RX_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_CMPL_ERRORS_CRC_ERROR)
240
241#define RX_CMP_L4_CS_BITS \
242 (cpu_to_le32(RX_CMP_FLAGS2_L4_CS_CALC | RX_CMP_FLAGS2_T_L4_CS_CALC))
243
244#define RX_CMP_L4_CS_ERR_BITS \
245 (cpu_to_le32(RX_CMPL_ERRORS_L4_CS_ERROR | RX_CMPL_ERRORS_T_L4_CS_ERROR))
246
247#define RX_CMP_L4_CS_OK(rxcmp1) \
248 (((rxcmp1)->rx_cmp_flags2 & RX_CMP_L4_CS_BITS) && \
249 !((rxcmp1)->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS))
250
251#define RX_CMP_ENCAP(rxcmp1) \
252 ((le32_to_cpu((rxcmp1)->rx_cmp_flags2) & \
253 RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3)
254
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400255#define RX_CMP_CFA_CODE(rxcmpl1) \
256 ((le32_to_cpu((rxcmpl1)->rx_cmp_cfa_code_errors_v2) & \
257 RX_CMPL_CFA_CODE_MASK) >> RX_CMPL_CFA_CODE_SFT)
258
Michael Chanc0c050c2015-10-22 16:01:17 -0400259struct rx_agg_cmp {
260 __le32 rx_agg_cmp_len_flags_type;
261 #define RX_AGG_CMP_TYPE (0x3f << 0)
262 #define RX_AGG_CMP_LEN (0xffff << 16)
263 #define RX_AGG_CMP_LEN_SHIFT 16
264 u32 rx_agg_cmp_opaque;
265 __le32 rx_agg_cmp_v;
266 #define RX_AGG_CMP_V (1 << 0)
Michael Chan218a8a72019-07-29 06:10:19 -0400267 #define RX_AGG_CMP_AGG_ID (0xffff << 16)
268 #define RX_AGG_CMP_AGG_ID_SHIFT 16
Michael Chanc0c050c2015-10-22 16:01:17 -0400269 __le32 rx_agg_cmp_unused;
270};
271
Michael Chan218a8a72019-07-29 06:10:19 -0400272#define TPA_AGG_AGG_ID(rx_agg) \
273 ((le32_to_cpu((rx_agg)->rx_agg_cmp_v) & \
274 RX_AGG_CMP_AGG_ID) >> RX_AGG_CMP_AGG_ID_SHIFT)
275
Michael Chanc0c050c2015-10-22 16:01:17 -0400276struct rx_tpa_start_cmp {
277 __le32 rx_tpa_start_cmp_len_flags_type;
278 #define RX_TPA_START_CMP_TYPE (0x3f << 0)
279 #define RX_TPA_START_CMP_FLAGS (0x3ff << 6)
280 #define RX_TPA_START_CMP_FLAGS_SHIFT 6
Michael Chan218a8a72019-07-29 06:10:19 -0400281 #define RX_TPA_START_CMP_FLAGS_ERROR (0x1 << 6)
Michael Chanc0c050c2015-10-22 16:01:17 -0400282 #define RX_TPA_START_CMP_FLAGS_PLACEMENT (0x7 << 7)
283 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_SHIFT 7
284 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_JUMBO (0x1 << 7)
285 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_HDS (0x2 << 7)
286 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_JUMBO (0x5 << 7)
287 #define RX_TPA_START_CMP_FLAGS_PLACEMENT_GRO_HDS (0x6 << 7)
288 #define RX_TPA_START_CMP_FLAGS_RSS_VALID (0x1 << 10)
Michael Chan218a8a72019-07-29 06:10:19 -0400289 #define RX_TPA_START_CMP_FLAGS_TIMESTAMP (0x1 << 11)
Michael Chanc0c050c2015-10-22 16:01:17 -0400290 #define RX_TPA_START_CMP_FLAGS_ITYPES (0xf << 12)
291 #define RX_TPA_START_CMP_FLAGS_ITYPES_SHIFT 12
292 #define RX_TPA_START_CMP_FLAGS_ITYPE_TCP (0x2 << 12)
293 #define RX_TPA_START_CMP_LEN (0xffff << 16)
294 #define RX_TPA_START_CMP_LEN_SHIFT 16
295
296 u32 rx_tpa_start_cmp_opaque;
297 __le32 rx_tpa_start_cmp_misc_v1;
298 #define RX_TPA_START_CMP_V1 (0x1 << 0)
299 #define RX_TPA_START_CMP_RSS_HASH_TYPE (0x7f << 9)
300 #define RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT 9
301 #define RX_TPA_START_CMP_AGG_ID (0x7f << 25)
302 #define RX_TPA_START_CMP_AGG_ID_SHIFT 25
Michael Chan218a8a72019-07-29 06:10:19 -0400303 #define RX_TPA_START_CMP_AGG_ID_P5 (0xffff << 16)
304 #define RX_TPA_START_CMP_AGG_ID_SHIFT_P5 16
Michael Chanc0c050c2015-10-22 16:01:17 -0400305
306 __le32 rx_tpa_start_cmp_rss_hash;
307};
308
309#define TPA_START_HASH_VALID(rx_tpa_start) \
310 ((rx_tpa_start)->rx_tpa_start_cmp_len_flags_type & \
311 cpu_to_le32(RX_TPA_START_CMP_FLAGS_RSS_VALID))
312
313#define TPA_START_HASH_TYPE(rx_tpa_start) \
Michael Chan614388c2015-11-05 16:25:48 -0500314 (((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) & \
315 RX_TPA_START_CMP_RSS_HASH_TYPE) >> \
316 RX_TPA_START_CMP_RSS_HASH_TYPE_SHIFT) & RSS_PROFILE_ID_MASK)
Michael Chanc0c050c2015-10-22 16:01:17 -0400317
318#define TPA_START_AGG_ID(rx_tpa_start) \
319 ((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) & \
320 RX_TPA_START_CMP_AGG_ID) >> RX_TPA_START_CMP_AGG_ID_SHIFT)
321
Michael Chan218a8a72019-07-29 06:10:19 -0400322#define TPA_START_AGG_ID_P5(rx_tpa_start) \
323 ((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_misc_v1) & \
324 RX_TPA_START_CMP_AGG_ID_P5) >> RX_TPA_START_CMP_AGG_ID_SHIFT_P5)
325
326#define TPA_START_ERROR(rx_tpa_start) \
327 ((rx_tpa_start)->rx_tpa_start_cmp_len_flags_type & \
328 cpu_to_le32(RX_TPA_START_CMP_FLAGS_ERROR))
329
Michael Chanc0c050c2015-10-22 16:01:17 -0400330struct rx_tpa_start_cmp_ext {
331 __le32 rx_tpa_start_cmp_flags2;
332 #define RX_TPA_START_CMP_FLAGS2_IP_CS_CALC (0x1 << 0)
333 #define RX_TPA_START_CMP_FLAGS2_L4_CS_CALC (0x1 << 1)
334 #define RX_TPA_START_CMP_FLAGS2_T_IP_CS_CALC (0x1 << 2)
335 #define RX_TPA_START_CMP_FLAGS2_T_L4_CS_CALC (0x1 << 3)
Michael Chan94758f82016-06-13 02:25:35 -0400336 #define RX_TPA_START_CMP_FLAGS2_IP_TYPE (0x1 << 8)
Michael Chan218a8a72019-07-29 06:10:19 -0400337 #define RX_TPA_START_CMP_FLAGS2_CSUM_CMPL_VALID (0x1 << 9)
338 #define RX_TPA_START_CMP_FLAGS2_EXT_META_FORMAT (0x3 << 10)
339 #define RX_TPA_START_CMP_FLAGS2_EXT_META_FORMAT_SHIFT 10
340 #define RX_TPA_START_CMP_FLAGS2_CSUM_CMPL (0xffff << 16)
341 #define RX_TPA_START_CMP_FLAGS2_CSUM_CMPL_SHIFT 16
Michael Chanc0c050c2015-10-22 16:01:17 -0400342
343 __le32 rx_tpa_start_cmp_metadata;
344 __le32 rx_tpa_start_cmp_cfa_code_v2;
345 #define RX_TPA_START_CMP_V2 (0x1 << 0)
Michael Chan218a8a72019-07-29 06:10:19 -0400346 #define RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_MASK (0x7 << 1)
347 #define RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_SHIFT 1
348 #define RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_NO_BUFFER (0x0 << 1)
349 #define RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_BAD_FORMAT (0x3 << 1)
350 #define RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_FLUSH (0x5 << 1)
Michael Chanc0c050c2015-10-22 16:01:17 -0400351 #define RX_TPA_START_CMP_CFA_CODE (0xffff << 16)
352 #define RX_TPA_START_CMPL_CFA_CODE_SHIFT 16
Michael Chan94758f82016-06-13 02:25:35 -0400353 __le32 rx_tpa_start_cmp_hdr_info;
Michael Chanc0c050c2015-10-22 16:01:17 -0400354};
355
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400356#define TPA_START_CFA_CODE(rx_tpa_start) \
357 ((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_cfa_code_v2) & \
358 RX_TPA_START_CMP_CFA_CODE) >> RX_TPA_START_CMPL_CFA_CODE_SHIFT)
359
Michael Chan50f011b2018-08-05 16:51:51 -0400360#define TPA_START_IS_IPV6(rx_tpa_start) \
361 (!!((rx_tpa_start)->rx_tpa_start_cmp_flags2 & \
362 cpu_to_le32(RX_TPA_START_CMP_FLAGS2_IP_TYPE)))
363
Michael Chan218a8a72019-07-29 06:10:19 -0400364#define TPA_START_ERROR_CODE(rx_tpa_start) \
365 ((le32_to_cpu((rx_tpa_start)->rx_tpa_start_cmp_cfa_code_v2) & \
366 RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_MASK) >> \
367 RX_TPA_START_CMP_ERRORS_BUFFER_ERROR_SHIFT)
368
Michael Chanc0c050c2015-10-22 16:01:17 -0400369struct rx_tpa_end_cmp {
370 __le32 rx_tpa_end_cmp_len_flags_type;
371 #define RX_TPA_END_CMP_TYPE (0x3f << 0)
372 #define RX_TPA_END_CMP_FLAGS (0x3ff << 6)
373 #define RX_TPA_END_CMP_FLAGS_SHIFT 6
374 #define RX_TPA_END_CMP_FLAGS_PLACEMENT (0x7 << 7)
375 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_SHIFT 7
376 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_JUMBO (0x1 << 7)
377 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_HDS (0x2 << 7)
378 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO (0x5 << 7)
379 #define RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS (0x6 << 7)
380 #define RX_TPA_END_CMP_FLAGS_RSS_VALID (0x1 << 10)
381 #define RX_TPA_END_CMP_FLAGS_ITYPES (0xf << 12)
382 #define RX_TPA_END_CMP_FLAGS_ITYPES_SHIFT 12
383 #define RX_TPA_END_CMP_FLAGS_ITYPE_TCP (0x2 << 12)
384 #define RX_TPA_END_CMP_LEN (0xffff << 16)
385 #define RX_TPA_END_CMP_LEN_SHIFT 16
386
387 u32 rx_tpa_end_cmp_opaque;
388 __le32 rx_tpa_end_cmp_misc_v1;
389 #define RX_TPA_END_CMP_V1 (0x1 << 0)
390 #define RX_TPA_END_CMP_AGG_BUFS (0x3f << 1)
391 #define RX_TPA_END_CMP_AGG_BUFS_SHIFT 1
392 #define RX_TPA_END_CMP_TPA_SEGS (0xff << 8)
393 #define RX_TPA_END_CMP_TPA_SEGS_SHIFT 8
394 #define RX_TPA_END_CMP_PAYLOAD_OFFSET (0xff << 16)
395 #define RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT 16
396 #define RX_TPA_END_CMP_AGG_ID (0x7f << 25)
397 #define RX_TPA_END_CMP_AGG_ID_SHIFT 25
Michael Chan218a8a72019-07-29 06:10:19 -0400398 #define RX_TPA_END_CMP_AGG_ID_P5 (0xffff << 16)
399 #define RX_TPA_END_CMP_AGG_ID_SHIFT_P5 16
Michael Chanc0c050c2015-10-22 16:01:17 -0400400
401 __le32 rx_tpa_end_cmp_tsdelta;
402 #define RX_TPA_END_GRO_TS (0x1 << 31)
403};
404
405#define TPA_END_AGG_ID(rx_tpa_end) \
406 ((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) & \
407 RX_TPA_END_CMP_AGG_ID) >> RX_TPA_END_CMP_AGG_ID_SHIFT)
408
Michael Chan218a8a72019-07-29 06:10:19 -0400409#define TPA_END_AGG_ID_P5(rx_tpa_end) \
410 ((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) & \
411 RX_TPA_END_CMP_AGG_ID_P5) >> RX_TPA_END_CMP_AGG_ID_SHIFT_P5)
412
413#define TPA_END_PAYLOAD_OFF(rx_tpa_end) \
414 ((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) & \
415 RX_TPA_END_CMP_PAYLOAD_OFFSET) >> RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT)
416
417#define TPA_END_AGG_BUFS(rx_tpa_end) \
418 ((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) & \
419 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT)
420
Michael Chanc0c050c2015-10-22 16:01:17 -0400421#define TPA_END_TPA_SEGS(rx_tpa_end) \
422 ((le32_to_cpu((rx_tpa_end)->rx_tpa_end_cmp_misc_v1) & \
423 RX_TPA_END_CMP_TPA_SEGS) >> RX_TPA_END_CMP_TPA_SEGS_SHIFT)
424
425#define RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO \
426 cpu_to_le32(RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_JUMBO & \
427 RX_TPA_END_CMP_FLAGS_PLACEMENT_GRO_HDS)
428
429#define TPA_END_GRO(rx_tpa_end) \
430 ((rx_tpa_end)->rx_tpa_end_cmp_len_flags_type & \
431 RX_TPA_END_CMP_FLAGS_PLACEMENT_ANY_GRO)
432
433#define TPA_END_GRO_TS(rx_tpa_end) \
Michael Chana58a3e62016-07-01 18:46:20 -0400434 (!!((rx_tpa_end)->rx_tpa_end_cmp_tsdelta & \
435 cpu_to_le32(RX_TPA_END_GRO_TS)))
Michael Chanc0c050c2015-10-22 16:01:17 -0400436
437struct rx_tpa_end_cmp_ext {
438 __le32 rx_tpa_end_cmp_dup_acks;
439 #define RX_TPA_END_CMP_TPA_DUP_ACKS (0xf << 0)
Michael Chan218a8a72019-07-29 06:10:19 -0400440 #define RX_TPA_END_CMP_PAYLOAD_OFFSET_P5 (0xff << 16)
441 #define RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT_P5 16
442 #define RX_TPA_END_CMP_AGG_BUFS_P5 (0xff << 24)
443 #define RX_TPA_END_CMP_AGG_BUFS_SHIFT_P5 24
Michael Chanc0c050c2015-10-22 16:01:17 -0400444
445 __le32 rx_tpa_end_cmp_seg_len;
446 #define RX_TPA_END_CMP_TPA_SEG_LEN (0xffff << 0)
447
448 __le32 rx_tpa_end_cmp_errors_v2;
449 #define RX_TPA_END_CMP_V2 (0x1 << 0)
Michael Chan69c149e2017-06-23 14:01:00 -0400450 #define RX_TPA_END_CMP_ERRORS (0x3 << 1)
Michael Chan218a8a72019-07-29 06:10:19 -0400451 #define RX_TPA_END_CMP_ERRORS_P5 (0x7 << 1)
Michael Chanc0c050c2015-10-22 16:01:17 -0400452 #define RX_TPA_END_CMPL_ERRORS_SHIFT 1
Michael Chan218a8a72019-07-29 06:10:19 -0400453 #define RX_TPA_END_CMP_ERRORS_BUFFER_ERROR_NO_BUFFER (0x0 << 1)
454 #define RX_TPA_END_CMP_ERRORS_BUFFER_ERROR_NOT_ON_CHIP (0x2 << 1)
455 #define RX_TPA_END_CMP_ERRORS_BUFFER_ERROR_BAD_FORMAT (0x3 << 1)
456 #define RX_TPA_END_CMP_ERRORS_BUFFER_ERROR_RSV_ERROR (0x4 << 1)
457 #define RX_TPA_END_CMP_ERRORS_BUFFER_ERROR_FLUSH (0x5 << 1)
Michael Chanc0c050c2015-10-22 16:01:17 -0400458
459 u32 rx_tpa_end_cmp_start_opaque;
460};
461
Michael Chan69c149e2017-06-23 14:01:00 -0400462#define TPA_END_ERRORS(rx_tpa_end_ext) \
463 ((rx_tpa_end_ext)->rx_tpa_end_cmp_errors_v2 & \
464 cpu_to_le32(RX_TPA_END_CMP_ERRORS))
465
Michael Chan218a8a72019-07-29 06:10:19 -0400466#define TPA_END_PAYLOAD_OFF_P5(rx_tpa_end_ext) \
467 ((le32_to_cpu((rx_tpa_end_ext)->rx_tpa_end_cmp_dup_acks) & \
468 RX_TPA_END_CMP_PAYLOAD_OFFSET_P5) >> \
469 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT_P5)
470
471#define TPA_END_AGG_BUFS_P5(rx_tpa_end_ext) \
472 ((le32_to_cpu((rx_tpa_end_ext)->rx_tpa_end_cmp_dup_acks) & \
473 RX_TPA_END_CMP_AGG_BUFS_P5) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT_P5)
474
Michael Chane38287b2018-10-14 07:02:45 -0400475struct nqe_cn {
476 __le16 type;
477 #define NQ_CN_TYPE_MASK 0x3fUL
478 #define NQ_CN_TYPE_SFT 0
479 #define NQ_CN_TYPE_CQ_NOTIFICATION 0x30UL
480 #define NQ_CN_TYPE_LAST NQ_CN_TYPE_CQ_NOTIFICATION
481 __le16 reserved16;
482 __le32 cq_handle_low;
483 __le32 v;
484 #define NQ_CN_V 0x1UL
485 __le32 cq_handle_high;
486};
487
Michael Chanc0c050c2015-10-22 16:01:17 -0400488#define DB_IDX_MASK 0xffffff
489#define DB_IDX_VALID (0x1 << 26)
490#define DB_IRQ_DIS (0x1 << 27)
491#define DB_KEY_TX (0x0 << 28)
492#define DB_KEY_RX (0x1 << 28)
493#define DB_KEY_CP (0x2 << 28)
494#define DB_KEY_ST (0x3 << 28)
495#define DB_KEY_TX_PUSH (0x4 << 28)
496#define DB_LONG_TX_PUSH (0x2 << 24)
497
Michael Chane4060d32016-12-07 00:26:19 -0500498#define BNXT_MIN_ROCE_CP_RINGS 2
499#define BNXT_MIN_ROCE_STAT_CTXS 1
500
Michael Chane38287b2018-10-14 07:02:45 -0400501/* 64-bit doorbell */
502#define DBR_INDEX_MASK 0x0000000000ffffffULL
503#define DBR_XID_MASK 0x000fffff00000000ULL
504#define DBR_XID_SFT 32
505#define DBR_PATH_L2 (0x1ULL << 56)
506#define DBR_TYPE_SQ (0x0ULL << 60)
507#define DBR_TYPE_RQ (0x1ULL << 60)
508#define DBR_TYPE_SRQ (0x2ULL << 60)
509#define DBR_TYPE_SRQ_ARM (0x3ULL << 60)
510#define DBR_TYPE_CQ (0x4ULL << 60)
511#define DBR_TYPE_CQ_ARMSE (0x5ULL << 60)
512#define DBR_TYPE_CQ_ARMALL (0x6ULL << 60)
513#define DBR_TYPE_CQ_ARMENA (0x7ULL << 60)
514#define DBR_TYPE_SRQ_ARMENA (0x8ULL << 60)
515#define DBR_TYPE_CQ_CUTOFF_ACK (0x9ULL << 60)
516#define DBR_TYPE_NQ (0xaULL << 60)
517#define DBR_TYPE_NQ_ARM (0xbULL << 60)
518#define DBR_TYPE_NULL (0xfULL << 60)
519
Michael Chanc0c050c2015-10-22 16:01:17 -0400520#define INVALID_HW_RING_ID ((u16)-1)
521
Michael Chanc0c050c2015-10-22 16:01:17 -0400522/* The hardware supports certain page sizes. Use the supported page sizes
523 * to allocate the rings.
524 */
525#if (PAGE_SHIFT < 12)
526#define BNXT_PAGE_SHIFT 12
527#elif (PAGE_SHIFT <= 13)
528#define BNXT_PAGE_SHIFT PAGE_SHIFT
529#elif (PAGE_SHIFT < 16)
530#define BNXT_PAGE_SHIFT 13
531#else
532#define BNXT_PAGE_SHIFT 16
533#endif
534
535#define BNXT_PAGE_SIZE (1 << BNXT_PAGE_SHIFT)
536
Michael Chan2839f282016-04-25 02:30:50 -0400537/* The RXBD length is 16-bit so we can only support page sizes < 64K */
538#if (PAGE_SHIFT > 15)
539#define BNXT_RX_PAGE_SHIFT 15
540#else
541#define BNXT_RX_PAGE_SHIFT PAGE_SHIFT
542#endif
543
544#define BNXT_RX_PAGE_SIZE (1 << BNXT_RX_PAGE_SHIFT)
545
Michael Chanc61fb992017-02-06 16:55:36 -0500546#define BNXT_MAX_MTU 9500
547#define BNXT_MAX_PAGE_MODE_MTU \
Michael Chanc6d30e82017-02-06 16:55:42 -0500548 ((unsigned int)PAGE_SIZE - VLAN_ETH_HLEN - NET_IP_ALIGN - \
549 XDP_PACKET_HEADROOM)
Michael Chanc61fb992017-02-06 16:55:36 -0500550
Michael Chan4ffcd582016-09-19 03:58:07 -0400551#define BNXT_MIN_PKT_SIZE 52
Michael Chanc0c050c2015-10-22 16:01:17 -0400552
Michael Chan51dd55b2016-02-10 17:33:50 -0500553#define BNXT_DEFAULT_RX_RING_SIZE 511
554#define BNXT_DEFAULT_TX_RING_SIZE 511
Michael Chanc0c050c2015-10-22 16:01:17 -0400555
556#define MAX_TPA 64
Michael Chan79632e92019-07-29 06:10:21 -0400557#define MAX_TPA_P5 256
558#define MAX_TPA_SEGS_P5 0x3f
Michael Chanc0c050c2015-10-22 16:01:17 -0400559
Michael Chand0a42d62016-05-15 03:04:46 -0400560#if (BNXT_PAGE_SHIFT == 16)
561#define MAX_RX_PAGES 1
562#define MAX_RX_AGG_PAGES 4
563#define MAX_TX_PAGES 1
564#define MAX_CP_PAGES 8
565#else
Michael Chanc0c050c2015-10-22 16:01:17 -0400566#define MAX_RX_PAGES 8
567#define MAX_RX_AGG_PAGES 32
568#define MAX_TX_PAGES 8
569#define MAX_CP_PAGES 64
Michael Chand0a42d62016-05-15 03:04:46 -0400570#endif
Michael Chanc0c050c2015-10-22 16:01:17 -0400571
572#define RX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct rx_bd))
573#define TX_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_bd))
574#define CP_DESC_CNT (BNXT_PAGE_SIZE / sizeof(struct tx_cmp))
575
576#define SW_RXBD_RING_SIZE (sizeof(struct bnxt_sw_rx_bd) * RX_DESC_CNT)
577#define HW_RXBD_RING_SIZE (sizeof(struct rx_bd) * RX_DESC_CNT)
578
579#define SW_RXBD_AGG_RING_SIZE (sizeof(struct bnxt_sw_rx_agg_bd) * RX_DESC_CNT)
580
581#define SW_TXBD_RING_SIZE (sizeof(struct bnxt_sw_tx_bd) * TX_DESC_CNT)
582#define HW_TXBD_RING_SIZE (sizeof(struct tx_bd) * TX_DESC_CNT)
583
584#define HW_CMPD_RING_SIZE (sizeof(struct tx_cmp) * CP_DESC_CNT)
585
586#define BNXT_MAX_RX_DESC_CNT (RX_DESC_CNT * MAX_RX_PAGES - 1)
587#define BNXT_MAX_RX_JUM_DESC_CNT (RX_DESC_CNT * MAX_RX_AGG_PAGES - 1)
588#define BNXT_MAX_TX_DESC_CNT (TX_DESC_CNT * MAX_TX_PAGES - 1)
589
590#define RX_RING(x) (((x) & ~(RX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
591#define RX_IDX(x) ((x) & (RX_DESC_CNT - 1))
592
593#define TX_RING(x) (((x) & ~(TX_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
594#define TX_IDX(x) ((x) & (TX_DESC_CNT - 1))
595
596#define CP_RING(x) (((x) & ~(CP_DESC_CNT - 1)) >> (BNXT_PAGE_SHIFT - 4))
597#define CP_IDX(x) ((x) & (CP_DESC_CNT - 1))
598
599#define TX_CMP_VALID(txcmp, raw_cons) \
600 (!!((txcmp)->tx_cmp_errors_v & cpu_to_le32(TX_CMP_V)) == \
601 !((raw_cons) & bp->cp_bit))
602
603#define RX_CMP_VALID(rxcmp1, raw_cons) \
604 (!!((rxcmp1)->rx_cmp_cfa_code_errors_v2 & cpu_to_le32(RX_CMP_V)) ==\
605 !((raw_cons) & bp->cp_bit))
606
607#define RX_AGG_CMP_VALID(agg, raw_cons) \
608 (!!((agg)->rx_agg_cmp_v & cpu_to_le32(RX_AGG_CMP_V)) == \
609 !((raw_cons) & bp->cp_bit))
610
Michael Chan0fcec982018-10-14 07:02:58 -0400611#define NQ_CMP_VALID(nqcmp, raw_cons) \
612 (!!((nqcmp)->v & cpu_to_le32(NQ_CN_V)) == !((raw_cons) & bp->cp_bit))
613
Michael Chanc0c050c2015-10-22 16:01:17 -0400614#define TX_CMP_TYPE(txcmp) \
615 (le32_to_cpu((txcmp)->tx_cmp_flags_type) & CMP_TYPE)
616
617#define RX_CMP_TYPE(rxcmp) \
618 (le32_to_cpu((rxcmp)->rx_cmp_len_flags_type) & RX_CMP_CMP_TYPE)
619
620#define NEXT_RX(idx) (((idx) + 1) & bp->rx_ring_mask)
621
622#define NEXT_RX_AGG(idx) (((idx) + 1) & bp->rx_agg_ring_mask)
623
624#define NEXT_TX(idx) (((idx) + 1) & bp->tx_ring_mask)
625
626#define ADV_RAW_CMP(idx, n) ((idx) + (n))
627#define NEXT_RAW_CMP(idx) ADV_RAW_CMP(idx, 1)
628#define RING_CMP(idx) ((idx) & bp->cp_ring_mask)
629#define NEXT_CMP(idx) RING_CMP(ADV_RAW_CMP(idx, 1))
630
Michael Chane6ef2692016-03-28 19:46:05 -0400631#define BNXT_HWRM_MAX_REQ_LEN (bp->hwrm_max_req_len)
Deepak Khungare605db82017-05-29 19:06:04 -0400632#define BNXT_HWRM_SHORT_REQ_LEN sizeof(struct hwrm_short_input)
Michael Chanff4fe812016-02-26 04:00:04 -0500633#define DFLT_HWRM_CMD_TIMEOUT 500
634#define HWRM_CMD_TIMEOUT (bp->hwrm_cmd_timeout)
Michael Chanc0c050c2015-10-22 16:01:17 -0400635#define HWRM_RESET_TIMEOUT ((HWRM_CMD_TIMEOUT) * 4)
636#define HWRM_RESP_ERR_CODE_MASK 0xffff
Michael Chana8643e12016-02-26 04:00:05 -0500637#define HWRM_RESP_LEN_OFFSET 4
Michael Chanc0c050c2015-10-22 16:01:17 -0400638#define HWRM_RESP_LEN_MASK 0xffff0000
639#define HWRM_RESP_LEN_SFT 16
640#define HWRM_RESP_VALID_MASK 0xff000000
641#define BNXT_HWRM_REQ_MAX_SIZE 128
642#define BNXT_HWRM_REQS_PER_PAGE (BNXT_PAGE_SIZE / \
643 BNXT_HWRM_REQ_MAX_SIZE)
Andy Gospodarek9751e8e2018-04-26 17:44:39 -0400644#define HWRM_SHORT_MIN_TIMEOUT 3
645#define HWRM_SHORT_MAX_TIMEOUT 10
646#define HWRM_SHORT_TIMEOUT_COUNTER 5
647
648#define HWRM_MIN_TIMEOUT 25
649#define HWRM_MAX_TIMEOUT 40
Michael Chanc0c050c2015-10-22 16:01:17 -0400650
Michael Chancc559c12018-05-08 03:18:38 -0400651#define HWRM_TOTAL_TIMEOUT(n) (((n) <= HWRM_SHORT_TIMEOUT_COUNTER) ? \
652 ((n) * HWRM_SHORT_MIN_TIMEOUT) : \
653 (HWRM_SHORT_TIMEOUT_COUNTER * HWRM_SHORT_MIN_TIMEOUT + \
654 ((n) - HWRM_SHORT_TIMEOUT_COUNTER) * HWRM_MIN_TIMEOUT))
655
Michael Chan0000b812019-02-20 19:07:32 -0500656#define HWRM_VALID_BIT_DELAY_USEC 150
Michael Chancc559c12018-05-08 03:18:38 -0400657
Venkat Duvvuru760b6d32018-12-20 03:38:48 -0500658#define BNXT_HWRM_CHNL_CHIMP 0
659#define BNXT_HWRM_CHNL_KONG 1
660
Andy Gospodarekf18c2b72019-07-08 17:53:03 -0400661#define BNXT_RX_EVENT 1
662#define BNXT_AGG_EVENT 2
663#define BNXT_TX_EVENT 4
664#define BNXT_REDIRECT_EVENT 8
Michael Chan4e5dbbda2017-02-06 16:55:37 -0500665
Michael Chanc0c050c2015-10-22 16:01:17 -0400666struct bnxt_sw_tx_bd {
Andy Gospodarekf18c2b72019-07-08 17:53:03 -0400667 union {
668 struct sk_buff *skb;
669 struct xdp_frame *xdpf;
670 };
Michael Chanc0c050c2015-10-22 16:01:17 -0400671 DEFINE_DMA_UNMAP_ADDR(mapping);
Andy Gospodarekf18c2b72019-07-08 17:53:03 -0400672 DEFINE_DMA_UNMAP_LEN(len);
Michael Chanc0c050c2015-10-22 16:01:17 -0400673 u8 is_gso;
674 u8 is_push;
Michael Chanc1ba92a2019-07-08 17:53:02 -0400675 u8 action;
Michael Chan38413402017-02-06 16:55:43 -0500676 union {
677 unsigned short nr_frags;
678 u16 rx_prod;
679 };
Michael Chanc0c050c2015-10-22 16:01:17 -0400680};
681
682struct bnxt_sw_rx_bd {
Michael Chan6bb19472017-02-06 16:55:32 -0500683 void *data;
684 u8 *data_ptr;
Michael Chan11cd1192017-02-06 16:55:33 -0500685 dma_addr_t mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400686};
687
688struct bnxt_sw_rx_agg_bd {
689 struct page *page;
Michael Chan89d0a062016-04-25 02:30:51 -0400690 unsigned int offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400691 dma_addr_t mapping;
692};
693
Michael Chan6fe19882018-10-14 07:02:41 -0400694struct bnxt_ring_mem_info {
Michael Chanc0c050c2015-10-22 16:01:17 -0400695 int nr_pages;
696 int page_size;
Michael Chan4f49b2b2018-12-20 03:38:49 -0500697 u16 flags;
Michael Chan66cca202018-10-14 07:02:42 -0400698#define BNXT_RMEM_VALID_PTE_FLAG 1
699#define BNXT_RMEM_RING_PTE_FLAG 2
Michael Chan4f49b2b2018-12-20 03:38:49 -0500700#define BNXT_RMEM_USE_FULL_PAGE_FLAG 4
701
702 u16 depth;
Michael Chan66cca202018-10-14 07:02:42 -0400703
Michael Chanc0c050c2015-10-22 16:01:17 -0400704 void **pg_arr;
705 dma_addr_t *dma_arr;
706
707 __le64 *pg_tbl;
708 dma_addr_t pg_tbl_map;
709
710 int vmem_size;
711 void **vmem;
Michael Chan6fe19882018-10-14 07:02:41 -0400712};
713
714struct bnxt_ring_struct {
715 struct bnxt_ring_mem_info ring_mem;
Michael Chanc0c050c2015-10-22 16:01:17 -0400716
717 u16 fw_ring_id; /* Ring id filled by Chimp FW */
Michael Chan9899bb52018-03-31 13:54:16 -0400718 union {
719 u16 grp_idx;
720 u16 map_idx; /* Used by cmpl rings */
721 };
Michael Chan23aefdd2018-10-14 07:02:51 -0400722 u32 handle;
Michael Chanc0c050c2015-10-22 16:01:17 -0400723 u8 queue_id;
724};
725
726struct tx_push_bd {
727 __le32 doorbell;
Michael Chan4419dbe2016-02-10 17:33:49 -0500728 __le32 tx_bd_len_flags_type;
729 u32 tx_bd_opaque;
Michael Chanc0c050c2015-10-22 16:01:17 -0400730 struct tx_bd_ext txbd2;
731};
732
Michael Chan4419dbe2016-02-10 17:33:49 -0500733struct tx_push_buffer {
734 struct tx_push_bd push_bd;
735 u32 data[25];
736};
737
Michael Chan697197e2018-10-14 07:02:46 -0400738struct bnxt_db_info {
739 void __iomem *doorbell;
740 union {
741 u64 db_key64;
742 u32 db_key32;
743 };
744};
745
Michael Chanc0c050c2015-10-22 16:01:17 -0400746struct bnxt_tx_ring_info {
Michael Chanb6ab4b02016-01-02 23:44:59 -0500747 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -0400748 u16 tx_prod;
749 u16 tx_cons;
Michael Chana960dec2017-02-06 16:55:39 -0500750 u16 txq_index;
Michael Chan697197e2018-10-14 07:02:46 -0400751 struct bnxt_db_info tx_db;
Michael Chanc0c050c2015-10-22 16:01:17 -0400752
753 struct tx_bd *tx_desc_ring[MAX_TX_PAGES];
754 struct bnxt_sw_tx_bd *tx_buf_ring;
755
756 dma_addr_t tx_desc_mapping[MAX_TX_PAGES];
757
Michael Chan4419dbe2016-02-10 17:33:49 -0500758 struct tx_push_buffer *tx_push;
Michael Chanc0c050c2015-10-22 16:01:17 -0400759 dma_addr_t tx_push_mapping;
Michael Chan4419dbe2016-02-10 17:33:49 -0500760 __le64 data_mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400761
762#define BNXT_DEV_STATE_CLOSING 0x1
763 u32 dev_state;
764
765 struct bnxt_ring_struct tx_ring_struct;
766};
767
Michael Chan74706af2018-10-14 07:02:40 -0400768#define BNXT_LEGACY_COAL_CMPL_PARAMS \
769 (RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN | \
770 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MAX | \
771 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET | \
772 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE | \
773 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR | \
774 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT | \
775 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_CMPL_AGGR_DMA_TMR | \
776 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_CMPL_AGGR_DMA_TMR_DURING_INT | \
777 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_AGGR_INT)
778
779#define BNXT_COAL_CMPL_ENABLES \
780 (RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_NUM_CMPL_DMA_AGGR | \
781 RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_CMPL_AGGR_DMA_TMR | \
782 RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_INT_LAT_TMR_MAX | \
783 RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_NUM_CMPL_AGGR_INT)
784
785#define BNXT_COAL_CMPL_MIN_TMR_ENABLE \
786 RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_INT_LAT_TMR_MIN
787
788#define BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE \
789 RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_ENABLES_NUM_CMPL_DMA_AGGR_DURING_INT
790
791struct bnxt_coal_cap {
792 u32 cmpl_params;
793 u32 nq_params;
794 u16 num_cmpl_dma_aggr_max;
795 u16 num_cmpl_dma_aggr_during_int_max;
796 u16 cmpl_aggr_dma_tmr_max;
797 u16 cmpl_aggr_dma_tmr_during_int_max;
798 u16 int_lat_tmr_min_max;
799 u16 int_lat_tmr_max_max;
800 u16 num_cmpl_aggr_int_max;
801 u16 timer_units;
802};
803
Andy Gospodarek6a8788f2018-01-09 16:06:20 -0500804struct bnxt_coal {
805 u16 coal_ticks;
806 u16 coal_ticks_irq;
807 u16 coal_bufs;
808 u16 coal_bufs_irq;
809 /* RING_IDLE enabled when coal ticks < idle_thresh */
810 u16 idle_thresh;
811 u8 bufs_per_record;
812 u8 budget;
813};
814
Michael Chanc0c050c2015-10-22 16:01:17 -0400815struct bnxt_tpa_info {
Michael Chan6bb19472017-02-06 16:55:32 -0500816 void *data;
817 u8 *data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -0400818 dma_addr_t mapping;
819 u16 len;
820 unsigned short gso_type;
821 u32 flags2;
822 u32 metadata;
823 enum pkt_hash_types hash_type;
824 u32 rss_hash;
Michael Chan94758f82016-06-13 02:25:35 -0400825 u32 hdr_info;
826
827#define BNXT_TPA_L4_SIZE(hdr_info) \
828 (((hdr_info) & 0xf8000000) ? ((hdr_info) >> 27) : 32)
829
830#define BNXT_TPA_INNER_L3_OFF(hdr_info) \
831 (((hdr_info) >> 18) & 0x1ff)
832
833#define BNXT_TPA_INNER_L2_OFF(hdr_info) \
834 (((hdr_info) >> 9) & 0x1ff)
835
836#define BNXT_TPA_OUTER_L3_OFF(hdr_info) \
837 ((hdr_info) & 0x1ff)
Sathya Perla4ab0c6a2017-07-24 12:34:27 -0400838
839 u16 cfa_code; /* cfa_code in TPA start compl */
Michael Chan79632e92019-07-29 06:10:21 -0400840 u8 agg_count;
841 struct rx_agg_cmp *agg_arr;
Michael Chanc0c050c2015-10-22 16:01:17 -0400842};
843
844struct bnxt_rx_ring_info {
Michael Chanb6ab4b02016-01-02 23:44:59 -0500845 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -0400846 u16 rx_prod;
847 u16 rx_agg_prod;
848 u16 rx_sw_agg_prod;
Michael Chan376a5b82016-05-10 19:17:59 -0400849 u16 rx_next_cons;
Michael Chan697197e2018-10-14 07:02:46 -0400850 struct bnxt_db_info rx_db;
851 struct bnxt_db_info rx_agg_db;
Michael Chanc0c050c2015-10-22 16:01:17 -0400852
Michael Chanc6d30e82017-02-06 16:55:42 -0500853 struct bpf_prog *xdp_prog;
854
Michael Chanc0c050c2015-10-22 16:01:17 -0400855 struct rx_bd *rx_desc_ring[MAX_RX_PAGES];
856 struct bnxt_sw_rx_bd *rx_buf_ring;
857
858 struct rx_bd *rx_agg_desc_ring[MAX_RX_AGG_PAGES];
859 struct bnxt_sw_rx_agg_bd *rx_agg_ring;
860
861 unsigned long *rx_agg_bmap;
862 u16 rx_agg_bmap_size;
863
Michael Chan89d0a062016-04-25 02:30:51 -0400864 struct page *rx_page;
865 unsigned int rx_page_offset;
866
Michael Chanc0c050c2015-10-22 16:01:17 -0400867 dma_addr_t rx_desc_mapping[MAX_RX_PAGES];
868 dma_addr_t rx_agg_desc_mapping[MAX_RX_AGG_PAGES];
869
870 struct bnxt_tpa_info *rx_tpa;
871
872 struct bnxt_ring_struct rx_ring_struct;
873 struct bnxt_ring_struct rx_agg_ring_struct;
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +0100874 struct xdp_rxq_info xdp_rxq;
Andy Gospodarek322b87c2019-07-08 17:53:04 -0400875 struct page_pool *page_pool;
Michael Chanc0c050c2015-10-22 16:01:17 -0400876};
877
878struct bnxt_cp_ring_info {
Michael Chan50e3ab72018-10-14 07:02:49 -0400879 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -0400880 u32 cp_raw_cons;
Michael Chan697197e2018-10-14 07:02:46 -0400881 struct bnxt_db_info cp_db;
Michael Chanc0c050c2015-10-22 16:01:17 -0400882
Michael Chan3675b922018-10-14 07:02:57 -0400883 u8 had_work_done:1;
Michael Chan0fcec982018-10-14 07:02:58 -0400884 u8 has_more_work:1;
Michael Chan3675b922018-10-14 07:02:57 -0400885
Michael Chanffd77622018-11-15 03:25:40 -0500886 u32 last_cp_raw_cons;
887
Andy Gospodarek6a8788f2018-01-09 16:06:20 -0500888 struct bnxt_coal rx_ring_coal;
889 u64 rx_packets;
890 u64 rx_bytes;
891 u64 event_ctr;
892
Tal Gilboa8960b382019-01-31 16:44:48 +0200893 struct dim dim;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -0500894
Michael Chane38287b2018-10-14 07:02:45 -0400895 union {
896 struct tx_cmp *cp_desc_ring[MAX_CP_PAGES];
897 struct nqe_cn *nq_desc_ring[MAX_CP_PAGES];
898 };
Michael Chanc0c050c2015-10-22 16:01:17 -0400899
900 dma_addr_t cp_desc_mapping[MAX_CP_PAGES];
901
902 struct ctx_hw_stats *hw_stats;
903 dma_addr_t hw_stats_map;
904 u32 hw_stats_ctx_id;
905 u64 rx_l4_csum_errors;
Michael Chan83eb5c52018-11-15 03:25:41 -0500906 u64 missed_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -0400907
908 struct bnxt_ring_struct cp_ring_struct;
Michael Chane38287b2018-10-14 07:02:45 -0400909
910 struct bnxt_cp_ring_info *cp_ring_arr[2];
Michael Chan50e3ab72018-10-14 07:02:49 -0400911#define BNXT_RX_HDL 0
912#define BNXT_TX_HDL 1
Michael Chanc0c050c2015-10-22 16:01:17 -0400913};
914
915struct bnxt_napi {
916 struct napi_struct napi;
917 struct bnxt *bp;
918
919 int index;
920 struct bnxt_cp_ring_info cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500921 struct bnxt_rx_ring_info *rx_ring;
922 struct bnxt_tx_ring_info *tx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400923
Michael Chanfa3e93e2017-02-06 16:55:41 -0500924 void (*tx_int)(struct bnxt *, struct bnxt_napi *,
925 int);
Michael Chan3675b922018-10-14 07:02:57 -0400926 int tx_pkts;
927 u8 events;
928
Michael Chanfa3e93e2017-02-06 16:55:41 -0500929 u32 flags;
930#define BNXT_NAPI_FLAG_XDP 0x1
931
Michael Chanfa7e2812016-05-10 19:18:00 -0400932 bool in_reset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400933};
934
Michael Chanc0c050c2015-10-22 16:01:17 -0400935struct bnxt_irq {
936 irq_handler_t handler;
937 unsigned int vector;
Vasundhara Volam56f0fd82017-08-28 13:40:27 -0400938 u8 requested:1;
939 u8 have_cpumask:1;
Michael Chanc0c050c2015-10-22 16:01:17 -0400940 char name[IFNAMSIZ + 2];
Vasundhara Volam56f0fd82017-08-28 13:40:27 -0400941 cpumask_var_t cpu_mask;
Michael Chanc0c050c2015-10-22 16:01:17 -0400942};
943
944#define HWRM_RING_ALLOC_TX 0x1
945#define HWRM_RING_ALLOC_RX 0x2
946#define HWRM_RING_ALLOC_AGG 0x4
947#define HWRM_RING_ALLOC_CMPL 0x8
Michael Chan697197e2018-10-14 07:02:46 -0400948#define HWRM_RING_ALLOC_NQ 0x10
Michael Chanc0c050c2015-10-22 16:01:17 -0400949
950#define INVALID_STATS_CTX_ID -1
951
Michael Chanc0c050c2015-10-22 16:01:17 -0400952struct bnxt_ring_grp_info {
953 u16 fw_stats_ctx;
954 u16 fw_grp_id;
955 u16 rx_fw_ring_id;
956 u16 agg_fw_ring_id;
957 u16 cp_fw_ring_id;
958};
959
960struct bnxt_vnic_info {
961 u16 fw_vnic_id; /* returned by Chimp during alloc */
Michael Chan44c6f722018-10-14 07:02:53 -0400962#define BNXT_MAX_CTX_PER_VNIC 8
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -0400963 u16 fw_rss_cos_lb_ctx[BNXT_MAX_CTX_PER_VNIC];
Michael Chanc0c050c2015-10-22 16:01:17 -0400964 u16 fw_l2_ctx_id;
965#define BNXT_MAX_UC_ADDRS 4
966 __le64 fw_l2_filter_id[BNXT_MAX_UC_ADDRS];
967 /* index 0 always dev_addr */
968 u16 uc_filter_count;
969 u8 *uc_list;
970
971 u16 *fw_grp_ids;
Michael Chanc0c050c2015-10-22 16:01:17 -0400972 dma_addr_t rss_table_dma_addr;
973 __le16 *rss_table;
974 dma_addr_t rss_hash_key_dma_addr;
975 u64 *rss_hash_key;
976 u32 rx_mask;
977
978 u8 *mc_list;
979 int mc_list_size;
980 int mc_list_count;
981 dma_addr_t mc_list_mapping;
982#define BNXT_MAX_MC_ADDRS 16
983
984 u32 flags;
985#define BNXT_VNIC_RSS_FLAG 1
986#define BNXT_VNIC_RFS_FLAG 2
987#define BNXT_VNIC_MCAST_FLAG 4
988#define BNXT_VNIC_UCAST_FLAG 8
Michael Chanae10ae72016-12-29 12:13:38 -0500989#define BNXT_VNIC_RFS_NEW_RSS_FLAG 0x10
Michael Chanc0c050c2015-10-22 16:01:17 -0400990};
991
Michael Chan6a4f2942018-01-17 03:21:06 -0500992struct bnxt_hw_resc {
993 u16 min_rsscos_ctxs;
994 u16 max_rsscos_ctxs;
995 u16 min_cp_rings;
996 u16 max_cp_rings;
997 u16 resv_cp_rings;
998 u16 min_tx_rings;
999 u16 max_tx_rings;
1000 u16 resv_tx_rings;
Michael Chandb4723b2018-03-31 13:54:13 -04001001 u16 max_tx_sch_inputs;
Michael Chan6a4f2942018-01-17 03:21:06 -05001002 u16 min_rx_rings;
1003 u16 max_rx_rings;
1004 u16 resv_rx_rings;
1005 u16 min_hw_ring_grps;
1006 u16 max_hw_ring_grps;
1007 u16 resv_hw_ring_grps;
1008 u16 min_l2_ctxs;
1009 u16 max_l2_ctxs;
1010 u16 min_vnics;
1011 u16 max_vnics;
1012 u16 resv_vnics;
1013 u16 min_stat_ctxs;
1014 u16 max_stat_ctxs;
Vasundhara Volam780baad2018-12-16 18:46:23 -05001015 u16 resv_stat_ctxs;
Michael Chanf7588cd2018-12-16 18:46:19 -05001016 u16 max_nqs;
Michael Chan6a4f2942018-01-17 03:21:06 -05001017 u16 max_irqs;
Michael Chan75720e62018-12-09 07:01:00 -05001018 u16 resv_irqs;
Michael Chan6a4f2942018-01-17 03:21:06 -05001019};
1020
Michael Chanc0c050c2015-10-22 16:01:17 -04001021#if defined(CONFIG_BNXT_SRIOV)
1022struct bnxt_vf_info {
1023 u16 fw_fid;
Vasundhara Volam91cdda42018-01-17 03:21:14 -05001024 u8 mac_addr[ETH_ALEN]; /* PF assigned MAC Address */
1025 u8 vf_mac_addr[ETH_ALEN]; /* VF assigned MAC address, only
1026 * stored by PF.
1027 */
Michael Chanc0c050c2015-10-22 16:01:17 -04001028 u16 vlan;
Michael Chan2a516442019-02-19 05:31:14 -05001029 u16 func_qcfg_flags;
Michael Chanc0c050c2015-10-22 16:01:17 -04001030 u32 flags;
1031#define BNXT_VF_QOS 0x1
1032#define BNXT_VF_SPOOFCHK 0x2
1033#define BNXT_VF_LINK_FORCED 0x4
1034#define BNXT_VF_LINK_UP 0x8
Vasundhara Volam746df132018-03-31 13:54:10 -04001035#define BNXT_VF_TRUST 0x10
Michael Chanc0c050c2015-10-22 16:01:17 -04001036 u32 func_flags; /* func cfg flags */
1037 u32 min_tx_rate;
1038 u32 max_tx_rate;
1039 void *hwrm_cmd_req_addr;
1040 dma_addr_t hwrm_cmd_req_dma_addr;
1041};
Michael Chan379a80a2015-10-23 15:06:19 -04001042#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04001043
1044struct bnxt_pf_info {
1045#define BNXT_FIRST_PF_FID 1
1046#define BNXT_FIRST_VF_FID 128
Michael Chana58a3e62016-07-01 18:46:20 -04001047 u16 fw_fid;
1048 u16 port_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04001049 u8 mac_addr[ETH_ALEN];
Michael Chanc0c050c2015-10-22 16:01:17 -04001050 u32 first_vf_id;
1051 u16 active_vfs;
1052 u16 max_vfs;
1053 u32 max_encap_records;
1054 u32 max_decap_records;
1055 u32 max_tx_em_flows;
1056 u32 max_tx_wm_flows;
1057 u32 max_rx_em_flows;
1058 u32 max_rx_wm_flows;
1059 unsigned long *vf_event_bmap;
1060 u16 hwrm_cmd_req_pages;
Michael Chan4673d662018-01-17 03:21:11 -05001061 u8 vf_resv_strategy;
1062#define BNXT_VF_RESV_STRATEGY_MAXIMAL 0
1063#define BNXT_VF_RESV_STRATEGY_MINIMAL 1
Michael Chanbf827362018-08-05 16:51:50 -04001064#define BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC 2
Michael Chanc0c050c2015-10-22 16:01:17 -04001065 void *hwrm_cmd_req_addr[4];
1066 dma_addr_t hwrm_cmd_req_dma_addr[4];
1067 struct bnxt_vf_info *vf;
1068};
Michael Chanc0c050c2015-10-22 16:01:17 -04001069
1070struct bnxt_ntuple_filter {
1071 struct hlist_node hash;
Michael Chana54c4d72016-07-25 12:33:35 -04001072 u8 dst_mac_addr[ETH_ALEN];
Michael Chanc0c050c2015-10-22 16:01:17 -04001073 u8 src_mac_addr[ETH_ALEN];
1074 struct flow_keys fkeys;
1075 __le64 filter_id;
1076 u16 sw_id;
Michael Chana54c4d72016-07-25 12:33:35 -04001077 u8 l2_fltr_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04001078 u16 rxq;
1079 u32 flow_id;
1080 unsigned long state;
1081#define BNXT_FLTR_VALID 0
1082#define BNXT_FLTR_UPDATE 1
1083};
1084
Michael Chanc0c050c2015-10-22 16:01:17 -04001085struct bnxt_link_info {
Michael Chan03efbec2016-04-11 04:11:11 -04001086 u8 phy_type;
Michael Chanc0c050c2015-10-22 16:01:17 -04001087 u8 media_type;
1088 u8 transceiver;
1089 u8 phy_addr;
1090 u8 phy_link_status;
1091#define BNXT_LINK_NO_LINK PORT_PHY_QCFG_RESP_LINK_NO_LINK
1092#define BNXT_LINK_SIGNAL PORT_PHY_QCFG_RESP_LINK_SIGNAL
1093#define BNXT_LINK_LINK PORT_PHY_QCFG_RESP_LINK_LINK
1094 u8 wire_speed;
1095 u8 loop_back;
1096 u8 link_up;
1097 u8 duplex;
Michael Chanacb20052017-07-24 12:34:20 -04001098#define BNXT_LINK_DUPLEX_HALF PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF
1099#define BNXT_LINK_DUPLEX_FULL PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL
Michael Chanc0c050c2015-10-22 16:01:17 -04001100 u8 pause;
1101#define BNXT_LINK_PAUSE_TX PORT_PHY_QCFG_RESP_PAUSE_TX
1102#define BNXT_LINK_PAUSE_RX PORT_PHY_QCFG_RESP_PAUSE_RX
1103#define BNXT_LINK_PAUSE_BOTH (PORT_PHY_QCFG_RESP_PAUSE_RX | \
1104 PORT_PHY_QCFG_RESP_PAUSE_TX)
Michael Chan32773602016-03-07 15:38:42 -05001105 u8 lp_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04001106 u8 auto_pause_setting;
1107 u8 force_pause_setting;
1108 u8 duplex_setting;
1109 u8 auto_mode;
1110#define BNXT_AUTO_MODE(mode) ((mode) > BNXT_LINK_AUTO_NONE && \
1111 (mode) <= BNXT_LINK_AUTO_MSK)
1112#define BNXT_LINK_AUTO_NONE PORT_PHY_QCFG_RESP_AUTO_MODE_NONE
1113#define BNXT_LINK_AUTO_ALLSPDS PORT_PHY_QCFG_RESP_AUTO_MODE_ALL_SPEEDS
1114#define BNXT_LINK_AUTO_ONESPD PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_SPEED
1115#define BNXT_LINK_AUTO_ONEORBELOW PORT_PHY_QCFG_RESP_AUTO_MODE_ONE_OR_BELOW
Michael Chan11f15ed2016-04-05 14:08:55 -04001116#define BNXT_LINK_AUTO_MSK PORT_PHY_QCFG_RESP_AUTO_MODE_SPEED_MASK
Michael Chanc0c050c2015-10-22 16:01:17 -04001117#define PHY_VER_LEN 3
1118 u8 phy_ver[PHY_VER_LEN];
1119 u16 link_speed;
1120#define BNXT_LINK_SPEED_100MB PORT_PHY_QCFG_RESP_LINK_SPEED_100MB
1121#define BNXT_LINK_SPEED_1GB PORT_PHY_QCFG_RESP_LINK_SPEED_1GB
1122#define BNXT_LINK_SPEED_2GB PORT_PHY_QCFG_RESP_LINK_SPEED_2GB
1123#define BNXT_LINK_SPEED_2_5GB PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB
1124#define BNXT_LINK_SPEED_10GB PORT_PHY_QCFG_RESP_LINK_SPEED_10GB
1125#define BNXT_LINK_SPEED_20GB PORT_PHY_QCFG_RESP_LINK_SPEED_20GB
1126#define BNXT_LINK_SPEED_25GB PORT_PHY_QCFG_RESP_LINK_SPEED_25GB
1127#define BNXT_LINK_SPEED_40GB PORT_PHY_QCFG_RESP_LINK_SPEED_40GB
1128#define BNXT_LINK_SPEED_50GB PORT_PHY_QCFG_RESP_LINK_SPEED_50GB
Deepak Khungar38a21b32017-04-21 20:11:24 -04001129#define BNXT_LINK_SPEED_100GB PORT_PHY_QCFG_RESP_LINK_SPEED_100GB
Michael Chanc0c050c2015-10-22 16:01:17 -04001130 u16 support_speeds;
Michael Chan68515a12016-12-29 12:13:34 -05001131 u16 auto_link_speeds; /* fw adv setting */
Michael Chanc0c050c2015-10-22 16:01:17 -04001132#define BNXT_LINK_SPEED_MSK_100MB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_100MB
1133#define BNXT_LINK_SPEED_MSK_1GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_1GB
1134#define BNXT_LINK_SPEED_MSK_2GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2GB
1135#define BNXT_LINK_SPEED_MSK_10GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_10GB
1136#define BNXT_LINK_SPEED_MSK_2_5GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_2_5GB
1137#define BNXT_LINK_SPEED_MSK_20GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_20GB
1138#define BNXT_LINK_SPEED_MSK_25GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_25GB
1139#define BNXT_LINK_SPEED_MSK_40GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_40GB
1140#define BNXT_LINK_SPEED_MSK_50GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_50GB
Deepak Khungar38a21b32017-04-21 20:11:24 -04001141#define BNXT_LINK_SPEED_MSK_100GB PORT_PHY_QCFG_RESP_SUPPORT_SPEEDS_100GB
Michael Chan93ed8112016-06-13 02:25:37 -04001142 u16 support_auto_speeds;
Michael Chan32773602016-03-07 15:38:42 -05001143 u16 lp_auto_link_speeds;
Michael Chanc0c050c2015-10-22 16:01:17 -04001144 u16 force_link_speed;
1145 u32 preemphasis;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04001146 u8 module_status;
Michael Chane70c7522017-02-12 19:18:16 -05001147 u16 fec_cfg;
1148#define BNXT_FEC_AUTONEG PORT_PHY_QCFG_RESP_FEC_CFG_FEC_AUTONEG_ENABLED
1149#define BNXT_FEC_ENC_BASE_R PORT_PHY_QCFG_RESP_FEC_CFG_FEC_CLAUSE74_ENABLED
1150#define BNXT_FEC_ENC_RS PORT_PHY_QCFG_RESP_FEC_CFG_FEC_CLAUSE91_ENABLED
Michael Chanc0c050c2015-10-22 16:01:17 -04001151
1152 /* copy of requested setting from ethtool cmd */
1153 u8 autoneg;
1154#define BNXT_AUTONEG_SPEED 1
1155#define BNXT_AUTONEG_FLOW_CTRL 2
1156 u8 req_duplex;
1157 u8 req_flow_ctrl;
1158 u16 req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05001159 u16 advertising; /* user adv setting */
Michael Chanc0c050c2015-10-22 16:01:17 -04001160 bool force_link_chng;
Michael Chan4bb13ab2016-04-05 14:09:01 -04001161
Michael Chana1ef4a792018-08-05 16:51:49 -04001162 bool phy_retry;
1163 unsigned long phy_retry_expires;
1164
Michael Chanc0c050c2015-10-22 16:01:17 -04001165 /* a copy of phy_qcfg output used to report link
1166 * info to VF
1167 */
1168 struct hwrm_port_phy_qcfg_output phy_qcfg_resp;
1169};
1170
1171#define BNXT_MAX_QUEUE 8
1172
1173struct bnxt_queue_info {
1174 u8 queue_id;
1175 u8 queue_profile;
1176};
1177
Michael Chan5ad2cbe2017-01-13 01:32:03 -05001178#define BNXT_MAX_LED 4
1179
1180struct bnxt_led_info {
1181 u8 led_id;
1182 u8 led_type;
1183 u8 led_group_id;
1184 u8 unused;
1185 __le16 led_state_caps;
1186#define BNXT_LED_ALT_BLINK_CAP(x) ((x) & \
1187 cpu_to_le16(PORT_LED_QCAPS_RESP_LED0_STATE_CAPS_BLINK_ALT_SUPPORTED))
1188
1189 __le16 led_color_caps;
1190};
1191
Michael Chaneb513652017-04-04 18:14:12 -04001192#define BNXT_MAX_TEST 8
1193
1194struct bnxt_test_info {
1195 u8 offline_mask;
Michael Chan55fd0cf2018-08-05 16:51:48 -04001196 u8 flags;
1197#define BNXT_TEST_FL_EXT_LPBK 0x1
Michael Chaneb513652017-04-04 18:14:12 -04001198 u16 timeout;
1199 char string[BNXT_MAX_TEST][ETH_GSTRING_LEN];
1200};
1201
Venkat Duvvuru2e9ee392018-12-20 03:38:45 -05001202#define BNXT_GRCPF_REG_CHIMP_COMM 0x0
1203#define BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER 0x100
1204#define BNXT_GRCPF_REG_WINDOW_BASE_OUT 0x400
1205#define BNXT_CAG_REG_LEGACY_INT_STATUS 0x4014
1206#define BNXT_CAG_REG_BASE 0x300000
Jeffrey Huang11809492015-11-05 16:25:49 -05001207
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001208#define BNXT_GRCPF_REG_KONG_COMM 0xA00
1209#define BNXT_GRCPF_REG_KONG_COMM_TRIGGER 0xB00
1210
Sathya Perla5a84acb2017-10-26 11:51:31 -04001211struct bnxt_tc_flow_stats {
1212 u64 packets;
1213 u64 bytes;
1214};
1215
Sathya Perla2ae74082017-08-28 13:40:33 -04001216struct bnxt_tc_info {
1217 bool enabled;
1218
1219 /* hash table to store TC offloaded flows */
1220 struct rhashtable flow_table;
1221 struct rhashtable_params flow_ht_params;
1222
1223 /* hash table to store L2 keys of TC flows */
1224 struct rhashtable l2_table;
1225 struct rhashtable_params l2_ht_params;
Sathya Perla8c95f772017-10-26 11:51:29 -04001226 /* hash table to store L2 keys for TC tunnel decap */
1227 struct rhashtable decap_l2_table;
1228 struct rhashtable_params decap_l2_ht_params;
1229 /* hash table to store tunnel decap entries */
1230 struct rhashtable decap_table;
1231 struct rhashtable_params decap_ht_params;
1232 /* hash table to store tunnel encap entries */
1233 struct rhashtable encap_table;
1234 struct rhashtable_params encap_ht_params;
Sathya Perla2ae74082017-08-28 13:40:33 -04001235
1236 /* lock to atomically add/del an l2 node when a flow is
1237 * added or deleted.
1238 */
1239 struct mutex lock;
1240
Sathya Perla5a84acb2017-10-26 11:51:31 -04001241 /* Fields used for batching stats query */
1242 struct rhashtable_iter iter;
1243#define BNXT_FLOW_STATS_BATCH_MAX 10
1244 struct bnxt_tc_stats_batch {
1245 void *flow_node;
1246 struct bnxt_tc_flow_stats hw_stats;
1247 } stats_batch[BNXT_FLOW_STATS_BATCH_MAX];
1248
Sathya Perla2ae74082017-08-28 13:40:33 -04001249 /* Stat counter mask (width) */
1250 u64 bytes_mask;
1251 u64 packets_mask;
1252};
1253
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04001254struct bnxt_vf_rep_stats {
1255 u64 packets;
1256 u64 bytes;
1257 u64 dropped;
1258};
1259
1260struct bnxt_vf_rep {
1261 struct bnxt *bp;
1262 struct net_device *dev;
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001263 struct metadata_dst *dst;
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04001264 u16 vf_idx;
1265 u16 tx_cfa_action;
1266 u16 rx_cfa_code;
1267
1268 struct bnxt_vf_rep_stats rx_stats;
1269 struct bnxt_vf_rep_stats tx_stats;
1270};
1271
Michael Chan66cca202018-10-14 07:02:42 -04001272#define PTU_PTE_VALID 0x1UL
1273#define PTU_PTE_LAST 0x2UL
1274#define PTU_PTE_NEXT_TO_LAST 0x4UL
1275
Michael Chan98f04cf2018-10-14 07:02:43 -04001276#define MAX_CTX_PAGES (BNXT_PAGE_SIZE / 8)
Michael Chan08fe9d12018-12-20 03:38:50 -05001277#define MAX_CTX_TOTAL_PAGES (MAX_CTX_PAGES * MAX_CTX_PAGES)
Michael Chan98f04cf2018-10-14 07:02:43 -04001278
1279struct bnxt_ctx_pg_info {
1280 u32 entries;
Michael Chan08fe9d12018-12-20 03:38:50 -05001281 u32 nr_pages;
Michael Chan98f04cf2018-10-14 07:02:43 -04001282 void *ctx_pg_arr[MAX_CTX_PAGES];
1283 dma_addr_t ctx_dma_arr[MAX_CTX_PAGES];
1284 struct bnxt_ring_mem_info ring_mem;
Michael Chan08fe9d12018-12-20 03:38:50 -05001285 struct bnxt_ctx_pg_info **ctx_pg_tbl;
Michael Chan98f04cf2018-10-14 07:02:43 -04001286};
1287
1288struct bnxt_ctx_mem_info {
1289 u32 qp_max_entries;
1290 u16 qp_min_qp1_entries;
1291 u16 qp_max_l2_entries;
1292 u16 qp_entry_size;
1293 u16 srq_max_l2_entries;
1294 u32 srq_max_entries;
1295 u16 srq_entry_size;
1296 u16 cq_max_l2_entries;
1297 u32 cq_max_entries;
1298 u16 cq_entry_size;
1299 u16 vnic_max_vnic_entries;
1300 u16 vnic_max_ring_table_entries;
1301 u16 vnic_entry_size;
1302 u32 stat_max_entries;
1303 u16 stat_entry_size;
1304 u16 tqm_entry_size;
1305 u32 tqm_min_entries_per_ring;
1306 u32 tqm_max_entries_per_ring;
1307 u32 mrav_max_entries;
1308 u16 mrav_entry_size;
1309 u16 tim_entry_size;
1310 u32 tim_max_entries;
Devesh Sharma53579e32019-05-05 07:17:04 -04001311 u16 mrav_num_entries_units;
Michael Chan98f04cf2018-10-14 07:02:43 -04001312 u8 tqm_entries_multiple;
1313
1314 u32 flags;
1315 #define BNXT_CTX_FLAG_INITED 0x01
1316
1317 struct bnxt_ctx_pg_info qp_mem;
1318 struct bnxt_ctx_pg_info srq_mem;
1319 struct bnxt_ctx_pg_info cq_mem;
1320 struct bnxt_ctx_pg_info vnic_mem;
1321 struct bnxt_ctx_pg_info stat_mem;
Michael Chancf6daed2018-12-20 03:38:51 -05001322 struct bnxt_ctx_pg_info mrav_mem;
1323 struct bnxt_ctx_pg_info tim_mem;
Michael Chan98f04cf2018-10-14 07:02:43 -04001324 struct bnxt_ctx_pg_info *tqm_mem[9];
1325};
1326
Michael Chanc0c050c2015-10-22 16:01:17 -04001327struct bnxt {
1328 void __iomem *bar0;
1329 void __iomem *bar1;
1330 void __iomem *bar2;
1331
1332 u32 reg_base;
Michael Chan659c8052016-06-13 02:25:33 -04001333 u16 chip_num;
1334#define CHIP_NUM_57301 0x16c8
1335#define CHIP_NUM_57302 0x16c9
1336#define CHIP_NUM_57304 0x16ca
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04001337#define CHIP_NUM_58700 0x16cd
Michael Chan659c8052016-06-13 02:25:33 -04001338#define CHIP_NUM_57402 0x16d0
1339#define CHIP_NUM_57404 0x16d1
1340#define CHIP_NUM_57406 0x16d2
Michael Chan3284f9e2017-05-29 19:06:07 -04001341#define CHIP_NUM_57407 0x16d5
Michael Chan659c8052016-06-13 02:25:33 -04001342
1343#define CHIP_NUM_57311 0x16ce
1344#define CHIP_NUM_57312 0x16cf
1345#define CHIP_NUM_57314 0x16df
Michael Chan3284f9e2017-05-29 19:06:07 -04001346#define CHIP_NUM_57317 0x16e0
Michael Chan659c8052016-06-13 02:25:33 -04001347#define CHIP_NUM_57412 0x16d6
1348#define CHIP_NUM_57414 0x16d7
1349#define CHIP_NUM_57416 0x16d8
1350#define CHIP_NUM_57417 0x16d9
Michael Chan3284f9e2017-05-29 19:06:07 -04001351#define CHIP_NUM_57412L 0x16da
1352#define CHIP_NUM_57414L 0x16db
1353
1354#define CHIP_NUM_5745X 0xd730
Michael Chan659c8052016-06-13 02:25:33 -04001355
Michael Chane38287b2018-10-14 07:02:45 -04001356#define CHIP_NUM_57500 0x1750
1357
Ray Jui4a581392017-08-28 13:40:28 -04001358#define CHIP_NUM_58802 0xd802
Ray Jui8ed693b2017-10-26 11:51:20 -04001359#define CHIP_NUM_58804 0xd804
Ray Jui4a581392017-08-28 13:40:28 -04001360#define CHIP_NUM_58808 0xd808
1361
Michael Chan659c8052016-06-13 02:25:33 -04001362#define BNXT_CHIP_NUM_5730X(chip_num) \
1363 ((chip_num) >= CHIP_NUM_57301 && \
1364 (chip_num) <= CHIP_NUM_57304)
1365
1366#define BNXT_CHIP_NUM_5740X(chip_num) \
Michael Chan3284f9e2017-05-29 19:06:07 -04001367 (((chip_num) >= CHIP_NUM_57402 && \
1368 (chip_num) <= CHIP_NUM_57406) || \
1369 (chip_num) == CHIP_NUM_57407)
Michael Chan659c8052016-06-13 02:25:33 -04001370
1371#define BNXT_CHIP_NUM_5731X(chip_num) \
1372 ((chip_num) == CHIP_NUM_57311 || \
1373 (chip_num) == CHIP_NUM_57312 || \
Michael Chan3284f9e2017-05-29 19:06:07 -04001374 (chip_num) == CHIP_NUM_57314 || \
1375 (chip_num) == CHIP_NUM_57317)
Michael Chan659c8052016-06-13 02:25:33 -04001376
1377#define BNXT_CHIP_NUM_5741X(chip_num) \
1378 ((chip_num) >= CHIP_NUM_57412 && \
Michael Chan3284f9e2017-05-29 19:06:07 -04001379 (chip_num) <= CHIP_NUM_57414L)
1380
1381#define BNXT_CHIP_NUM_58700(chip_num) \
1382 ((chip_num) == CHIP_NUM_58700)
1383
1384#define BNXT_CHIP_NUM_5745X(chip_num) \
1385 ((chip_num) == CHIP_NUM_5745X)
Michael Chan659c8052016-06-13 02:25:33 -04001386
1387#define BNXT_CHIP_NUM_57X0X(chip_num) \
1388 (BNXT_CHIP_NUM_5730X(chip_num) || BNXT_CHIP_NUM_5740X(chip_num))
1389
1390#define BNXT_CHIP_NUM_57X1X(chip_num) \
1391 (BNXT_CHIP_NUM_5731X(chip_num) || BNXT_CHIP_NUM_5741X(chip_num))
Michael Chanc0c050c2015-10-22 16:01:17 -04001392
Ray Jui4a581392017-08-28 13:40:28 -04001393#define BNXT_CHIP_NUM_588XX(chip_num) \
1394 ((chip_num) == CHIP_NUM_58802 || \
Ray Jui8ed693b2017-10-26 11:51:20 -04001395 (chip_num) == CHIP_NUM_58804 || \
Ray Jui4a581392017-08-28 13:40:28 -04001396 (chip_num) == CHIP_NUM_58808)
1397
Michael Chanc0c050c2015-10-22 16:01:17 -04001398 struct net_device *dev;
1399 struct pci_dev *pdev;
1400
1401 atomic_t intr_sem;
1402
1403 u32 flags;
Michael Chane38287b2018-10-14 07:02:45 -04001404 #define BNXT_FLAG_CHIP_P5 0x1
Michael Chanc0c050c2015-10-22 16:01:17 -04001405 #define BNXT_FLAG_VF 0x2
1406 #define BNXT_FLAG_LRO 0x4
Michael Chand1611c32015-10-25 22:27:57 -04001407#ifdef CONFIG_INET
Michael Chanc0c050c2015-10-22 16:01:17 -04001408 #define BNXT_FLAG_GRO 0x8
Michael Chand1611c32015-10-25 22:27:57 -04001409#else
1410 /* Cannot support hardware GRO if CONFIG_INET is not set */
1411 #define BNXT_FLAG_GRO 0x0
1412#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04001413 #define BNXT_FLAG_TPA (BNXT_FLAG_LRO | BNXT_FLAG_GRO)
1414 #define BNXT_FLAG_JUMBO 0x10
1415 #define BNXT_FLAG_STRIP_VLAN 0x20
1416 #define BNXT_FLAG_AGG_RINGS (BNXT_FLAG_JUMBO | BNXT_FLAG_GRO | \
1417 BNXT_FLAG_LRO)
1418 #define BNXT_FLAG_USING_MSIX 0x40
1419 #define BNXT_FLAG_MSIX_CAP 0x80
1420 #define BNXT_FLAG_RFS 0x100
Michael Chan6e6c5a52016-01-02 23:45:02 -05001421 #define BNXT_FLAG_SHARED_RINGS 0x200
Michael Chan3bdf56c2016-03-07 15:38:45 -05001422 #define BNXT_FLAG_PORT_STATS 0x400
Michael Chan87da7f72016-11-16 21:13:09 -05001423 #define BNXT_FLAG_UDP_RSS_CAP 0x800
Michael Chan170ce012016-04-05 14:08:57 -04001424 #define BNXT_FLAG_EEE_CAP 0x1000
Michael Chan8fdefd62016-12-29 12:13:36 -05001425 #define BNXT_FLAG_NEW_RSS_CAP 0x2000
Michael Chanc1ef1462017-04-04 18:14:07 -04001426 #define BNXT_FLAG_WOL_CAP 0x4000
Michael Chane4060d32016-12-07 00:26:19 -05001427 #define BNXT_FLAG_ROCEV1_CAP 0x8000
1428 #define BNXT_FLAG_ROCEV2_CAP 0x10000
1429 #define BNXT_FLAG_ROCE_CAP (BNXT_FLAG_ROCEV1_CAP | \
1430 BNXT_FLAG_ROCEV2_CAP)
Michael Chanbdbd1eb2016-12-29 12:13:43 -05001431 #define BNXT_FLAG_NO_AGG_RINGS 0x20000
Michael Chanc61fb992017-02-06 16:55:36 -05001432 #define BNXT_FLAG_RX_PAGE_MODE 0x40000
Deepak Khungar9e54e322017-04-21 20:11:26 -04001433 #define BNXT_FLAG_MULTI_HOST 0x100000
Michael Chan434c9752017-05-29 19:06:08 -04001434 #define BNXT_FLAG_DOUBLE_DB 0x400000
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04001435 #define BNXT_FLAG_CHIP_NITRO_A0 0x1000000
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001436 #define BNXT_FLAG_DIM 0x2000000
Michael Chanabe93ad2018-03-31 13:54:08 -04001437 #define BNXT_FLAG_ROCE_MIRROR_CAP 0x4000000
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04001438 #define BNXT_FLAG_PORT_STATS_EXT 0x10000000
Vasundhara Volam55e43982019-05-05 07:17:00 -04001439 #define BNXT_FLAG_PCIE_STATS 0x40000000
Michael Chan6e6c5a52016-01-02 23:45:02 -05001440
Michael Chanc0c050c2015-10-22 16:01:17 -04001441 #define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA | \
1442 BNXT_FLAG_RFS | \
1443 BNXT_FLAG_STRIP_VLAN)
1444
1445#define BNXT_PF(bp) (!((bp)->flags & BNXT_FLAG_VF))
1446#define BNXT_VF(bp) ((bp)->flags & BNXT_FLAG_VF)
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04001447#define BNXT_NPAR(bp) ((bp)->port_partition_type)
Deepak Khungar9e54e322017-04-21 20:11:26 -04001448#define BNXT_MH(bp) ((bp)->flags & BNXT_FLAG_MULTI_HOST)
1449#define BNXT_SINGLE_PF(bp) (BNXT_PF(bp) && !BNXT_NPAR(bp) && !BNXT_MH(bp))
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04001450#define BNXT_CHIP_TYPE_NITRO_A0(bp) ((bp)->flags & BNXT_FLAG_CHIP_NITRO_A0)
Michael Chanc61fb992017-02-06 16:55:36 -05001451#define BNXT_RX_PAGE_MODE(bp) ((bp)->flags & BNXT_FLAG_RX_PAGE_MODE)
Michael Chane38287b2018-10-14 07:02:45 -04001452#define BNXT_SUPPORTS_TPA(bp) (!BNXT_CHIP_TYPE_NITRO_A0(bp) && \
Michael Chand6295222019-05-22 19:12:56 -04001453 !(bp->flags & BNXT_FLAG_CHIP_P5) && \
1454 !is_kdump_kernel())
Michael Chanc0c050c2015-10-22 16:01:17 -04001455
Michael Chane38287b2018-10-14 07:02:45 -04001456/* Chip class phase 5 */
1457#define BNXT_CHIP_P5(bp) \
1458 ((bp)->chip_num == CHIP_NUM_57500)
1459
1460/* Chip class phase 4.x */
1461#define BNXT_CHIP_P4(bp) \
Michael Chan3284f9e2017-05-29 19:06:07 -04001462 (BNXT_CHIP_NUM_57X1X((bp)->chip_num) || \
1463 BNXT_CHIP_NUM_5745X((bp)->chip_num) || \
Ray Jui4a581392017-08-28 13:40:28 -04001464 BNXT_CHIP_NUM_588XX((bp)->chip_num) || \
Michael Chan3284f9e2017-05-29 19:06:07 -04001465 (BNXT_CHIP_NUM_58700((bp)->chip_num) && \
1466 !BNXT_CHIP_TYPE_NITRO_A0(bp)))
1467
Michael Chane38287b2018-10-14 07:02:45 -04001468#define BNXT_CHIP_P4_PLUS(bp) \
1469 (BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp))
1470
Michael Chana588e452016-12-07 00:26:21 -05001471 struct bnxt_en_dev *edev;
1472 struct bnxt_en_dev * (*ulp_probe)(struct net_device *);
1473
Michael Chanc0c050c2015-10-22 16:01:17 -04001474 struct bnxt_napi **bnapi;
1475
Michael Chanb6ab4b02016-01-02 23:44:59 -05001476 struct bnxt_rx_ring_info *rx_ring;
1477 struct bnxt_tx_ring_info *tx_ring;
Michael Chana960dec2017-02-06 16:55:39 -05001478 u16 *tx_ring_map;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001479
Michael Chan309369c2016-06-13 02:25:34 -04001480 struct sk_buff * (*gro_func)(struct bnxt_tpa_info *, int, int,
1481 struct sk_buff *);
1482
Michael Chan6bb19472017-02-06 16:55:32 -05001483 struct sk_buff * (*rx_skb_func)(struct bnxt *,
1484 struct bnxt_rx_ring_info *,
1485 u16, void *, u8 *, dma_addr_t,
1486 unsigned int);
1487
Michael Chan79632e92019-07-29 06:10:21 -04001488 u16 max_tpa_v2;
1489 u16 max_tpa;
Michael Chanc0c050c2015-10-22 16:01:17 -04001490 u32 rx_buf_size;
1491 u32 rx_buf_use_size; /* useable size */
Michael Chanb3dba772017-02-06 16:55:35 -05001492 u16 rx_offset;
1493 u16 rx_dma_offset;
Michael Chan745fc052017-02-06 16:55:34 -05001494 enum dma_data_direction rx_dir;
Michael Chanc0c050c2015-10-22 16:01:17 -04001495 u32 rx_ring_size;
1496 u32 rx_agg_ring_size;
1497 u32 rx_copy_thresh;
1498 u32 rx_ring_mask;
1499 u32 rx_agg_ring_mask;
1500 int rx_nr_pages;
1501 int rx_agg_nr_pages;
1502 int rx_nr_rings;
1503 int rsscos_nr_ctxs;
1504
1505 u32 tx_ring_size;
1506 u32 tx_ring_mask;
1507 int tx_nr_pages;
1508 int tx_nr_rings;
1509 int tx_nr_rings_per_tc;
Michael Chan5f449242017-02-06 16:55:40 -05001510 int tx_nr_rings_xdp;
Michael Chanc0c050c2015-10-22 16:01:17 -04001511
1512 int tx_wake_thresh;
1513 int tx_push_thresh;
1514 int tx_push_size;
1515
1516 u32 cp_ring_size;
1517 u32 cp_ring_mask;
1518 u32 cp_bit;
1519 int cp_nr_pages;
1520 int cp_nr_rings;
1521
Michael Chanb81a90d2016-01-02 23:45:01 -05001522 /* grp_info indexed by completion ring index */
Michael Chanc0c050c2015-10-22 16:01:17 -04001523 struct bnxt_ring_grp_info *grp_info;
1524 struct bnxt_vnic_info *vnic_info;
1525 int nr_vnics;
Michael Chan87da7f72016-11-16 21:13:09 -05001526 u32 rss_hash_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04001527
Michael Chan7eb9bb32017-10-26 11:51:25 -04001528 u16 max_mtu;
Michael Chanc0c050c2015-10-22 16:01:17 -04001529 u8 max_tc;
Michael Chan87c374d2016-12-02 21:17:16 -05001530 u8 max_lltc; /* lossless TCs */
Michael Chanc0c050c2015-10-22 16:01:17 -04001531 struct bnxt_queue_info q_info[BNXT_MAX_QUEUE];
Michael Chan2e8ef772018-04-26 17:44:31 -04001532 u8 tc_to_qidx[BNXT_MAX_QUEUE];
Michael Chan98f04cf2018-10-14 07:02:43 -04001533 u8 q_ids[BNXT_MAX_QUEUE];
1534 u8 max_q;
Michael Chanc0c050c2015-10-22 16:01:17 -04001535
1536 unsigned int current_interval;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001537#define BNXT_TIMER_INTERVAL HZ
Michael Chanc0c050c2015-10-22 16:01:17 -04001538
1539 struct timer_list timer;
1540
Michael Chancaefe522015-12-09 19:35:42 -05001541 unsigned long state;
1542#define BNXT_STATE_OPEN 0
Michael Chan4cebdce2015-12-09 19:35:43 -05001543#define BNXT_STATE_IN_SP_TASK 1
Michael Chanf9b76eb2017-07-11 13:05:34 -04001544#define BNXT_STATE_READ_STATS 2
Michael Chanc0c050c2015-10-22 16:01:17 -04001545
1546 struct bnxt_irq *irq_tbl;
Michael Chan78095922016-12-07 00:26:16 -05001547 int total_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04001548 u8 mac_addr[ETH_ALEN];
1549
Michael Chan7df4ae92016-12-02 21:17:17 -05001550#ifdef CONFIG_BNXT_DCB
1551 struct ieee_pfc *ieee_pfc;
1552 struct ieee_ets *ieee_ets;
1553 u8 dcbx_cap;
1554 u8 default_pri;
Michael Chanafdc8a82018-08-05 16:51:57 -04001555 u8 max_dscp_value;
Michael Chan7df4ae92016-12-02 21:17:17 -05001556#endif /* CONFIG_BNXT_DCB */
1557
Michael Chanc0c050c2015-10-22 16:01:17 -04001558 u32 msg_enable;
1559
Michael Chan97381a12018-08-05 16:51:54 -04001560 u32 fw_cap;
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001561 #define BNXT_FW_CAP_SHORT_CMD 0x00000001
1562 #define BNXT_FW_CAP_LLDP_AGENT 0x00000002
1563 #define BNXT_FW_CAP_DCBX_AGENT 0x00000004
1564 #define BNXT_FW_CAP_NEW_RM 0x00000008
1565 #define BNXT_FW_CAP_IF_CHANGE 0x00000010
1566 #define BNXT_FW_CAP_KONG_MB_CHNL 0x00000080
Venkat Duvvuruabd43a12018-12-20 03:38:52 -05001567 #define BNXT_FW_CAP_OVS_64BIT_HANDLE 0x00000400
Michael Chan2a516442019-02-19 05:31:14 -05001568 #define BNXT_FW_CAP_TRUSTED_VF 0x00000800
Vasundhara Volam691aa622019-05-05 07:17:02 -04001569 #define BNXT_FW_CAP_PKG_VER 0x00004000
Michael Chane969ae52019-05-05 07:17:06 -04001570 #define BNXT_FW_CAP_CFA_ADV_FLOW 0x00008000
1571 #define BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX 0x00010000
Vasundhara Volam55e43982019-05-05 07:17:00 -04001572 #define BNXT_FW_CAP_PCIE_STATS_SUPPORTED 0x00020000
Vasundhara Volam61545322019-05-05 07:17:01 -04001573 #define BNXT_FW_CAP_EXT_STATS_SUPPORTED 0x00040000
Michael Chan97381a12018-08-05 16:51:54 -04001574
1575#define BNXT_NEW_RM(bp) ((bp)->fw_cap & BNXT_FW_CAP_NEW_RM)
Michael Chan11f15ed2016-04-05 14:08:55 -04001576 u32 hwrm_spec_code;
Michael Chanc0c050c2015-10-22 16:01:17 -04001577 u16 hwrm_cmd_seq;
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001578 u16 hwrm_cmd_kong_seq;
Venkat Duvvurufc718bb2018-12-20 03:38:44 -05001579 u16 hwrm_intr_seq_id;
Deepak Khungare605db82017-05-29 19:06:04 -04001580 void *hwrm_short_cmd_req_addr;
1581 dma_addr_t hwrm_short_cmd_req_dma_addr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001582 void *hwrm_cmd_resp_addr;
1583 dma_addr_t hwrm_cmd_resp_dma_addr;
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001584 void *hwrm_cmd_kong_resp_addr;
1585 dma_addr_t hwrm_cmd_kong_resp_dma_addr;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001586
Michael Chanb8875ca2018-12-16 18:46:29 -05001587 struct rtnl_link_stats64 net_stats_prev;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001588 struct rx_port_stats *hw_rx_port_stats;
1589 struct tx_port_stats *hw_tx_port_stats;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04001590 struct rx_port_stats_ext *hw_rx_port_stats_ext;
Dan Carpenter35b842f2018-10-18 11:02:39 +03001591 struct tx_port_stats_ext *hw_tx_port_stats_ext;
Vasundhara Volam55e43982019-05-05 07:17:00 -04001592 struct pcie_ctx_hw_stats *hw_pcie_stats;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001593 dma_addr_t hw_rx_port_stats_map;
1594 dma_addr_t hw_tx_port_stats_map;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04001595 dma_addr_t hw_rx_port_stats_ext_map;
Michael Chan36e53342018-10-14 07:02:38 -04001596 dma_addr_t hw_tx_port_stats_ext_map;
Vasundhara Volam55e43982019-05-05 07:17:00 -04001597 dma_addr_t hw_pcie_stats_map;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001598 int hw_port_stats_size;
Michael Chan36e53342018-10-14 07:02:38 -04001599 u16 fw_rx_stats_ext_size;
1600 u16 fw_tx_stats_ext_size;
Michael Chane37fed72018-12-16 18:46:26 -05001601 u8 pri2cos[8];
1602 u8 pri2cos_valid;
Michael Chan3bdf56c2016-03-07 15:38:45 -05001603
Michael Chane6ef2692016-03-28 19:46:05 -04001604 u16 hwrm_max_req_len;
Michael Chan1dfddc42018-10-14 07:02:39 -04001605 u16 hwrm_max_ext_req_len;
Michael Chanff4fe812016-02-26 04:00:04 -05001606 int hwrm_cmd_timeout;
Michael Chanc0c050c2015-10-22 16:01:17 -04001607 struct mutex hwrm_cmd_lock; /* serialize hwrm messages */
1608 struct hwrm_ver_get_output ver_resp;
1609#define FW_VER_STR_LEN 32
1610#define BC_HWRM_STR_LEN 21
1611#define PHY_VER_STR_LEN (FW_VER_STR_LEN - BC_HWRM_STR_LEN)
1612 char fw_ver_str[FW_VER_STR_LEN];
1613 __be16 vxlan_port;
1614 u8 vxlan_port_cnt;
1615 __le16 vxlan_fw_dst_port_id;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07001616 __be16 nge_port;
Michael Chanc0c050c2015-10-22 16:01:17 -04001617 u8 nge_port_cnt;
1618 __le16 nge_fw_dst_port_id;
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04001619 u8 port_partition_type;
Michael Chand5430d32017-08-28 13:40:31 -04001620 u8 port_count;
Michael Chan32e8239c2017-07-24 12:34:21 -04001621 u16 br_mode;
Michael Chandfc9c942016-02-26 04:00:03 -05001622
Michael Chan74706af2018-10-14 07:02:40 -04001623 struct bnxt_coal_cap coal_cap;
Michael Chan18775aa2017-10-26 11:51:27 -04001624 struct bnxt_coal rx_coal;
1625 struct bnxt_coal tx_coal;
Michael Chanc0c050c2015-10-22 16:01:17 -04001626
Michael Chan51f30782016-07-01 18:46:29 -04001627 u32 stats_coal_ticks;
1628#define BNXT_DEF_STATS_COAL_TICKS 1000000
1629#define BNXT_MIN_STATS_COAL_TICKS 250000
1630#define BNXT_MAX_STATS_COAL_TICKS 1000000
1631
Michael Chanc0c050c2015-10-22 16:01:17 -04001632 struct work_struct sp_task;
1633 unsigned long sp_event;
1634#define BNXT_RX_MASK_SP_EVENT 0
1635#define BNXT_RX_NTP_FLTR_SP_EVENT 1
1636#define BNXT_LINK_CHNG_SP_EVENT 2
Jeffrey Huangc5d77742015-11-05 16:25:47 -05001637#define BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT 3
1638#define BNXT_VXLAN_ADD_PORT_SP_EVENT 4
1639#define BNXT_VXLAN_DEL_PORT_SP_EVENT 5
1640#define BNXT_RESET_TASK_SP_EVENT 6
1641#define BNXT_RST_RING_SP_EVENT 7
Jeffrey Huang19241362016-02-26 04:00:00 -05001642#define BNXT_HWRM_PF_UNLOAD_SP_EVENT 8
Michael Chan3bdf56c2016-03-07 15:38:45 -05001643#define BNXT_PERIODIC_STATS_SP_EVENT 9
Michael Chan4bb13ab2016-04-05 14:09:01 -04001644#define BNXT_HWRM_PORT_MODULE_SP_EVENT 10
Michael Chanfc0f1922016-06-13 02:25:30 -04001645#define BNXT_RESET_TASK_SILENT_SP_EVENT 11
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07001646#define BNXT_GENEVE_ADD_PORT_SP_EVENT 12
1647#define BNXT_GENEVE_DEL_PORT_SP_EVENT 13
Michael Chan286ef9d2016-11-16 21:13:08 -05001648#define BNXT_LINK_SPEED_CHNG_SP_EVENT 14
Sathya Perla5a84acb2017-10-26 11:51:31 -04001649#define BNXT_FLOW_STATS_SP_EVENT 15
Michael Chana1ef4a792018-08-05 16:51:49 -04001650#define BNXT_UPDATE_PHY_SP_EVENT 16
Michael Chanffd77622018-11-15 03:25:40 -05001651#define BNXT_RING_COAL_NOW_SP_EVENT 17
Michael Chanc0c050c2015-10-22 16:01:17 -04001652
Michael Chan6a4f2942018-01-17 03:21:06 -05001653 struct bnxt_hw_resc hw_resc;
Michael Chan379a80a2015-10-23 15:06:19 -04001654 struct bnxt_pf_info pf;
Michael Chan98f04cf2018-10-14 07:02:43 -04001655 struct bnxt_ctx_mem_info *ctx;
Michael Chanc0c050c2015-10-22 16:01:17 -04001656#ifdef CONFIG_BNXT_SRIOV
1657 int nr_vfs;
Michael Chanc0c050c2015-10-22 16:01:17 -04001658 struct bnxt_vf_info vf;
1659 wait_queue_head_t sriov_cfg_wait;
1660 bool sriov_cfg;
1661#define BNXT_SRIOV_CFG_WAIT_TMO msecs_to_jiffies(10000)
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04001662
1663 /* lock to protect VF-rep creation/cleanup via
1664 * multiple paths such as ->sriov_configure() and
1665 * devlink ->eswitch_mode_set()
1666 */
1667 struct mutex sriov_lock;
Michael Chanc0c050c2015-10-22 16:01:17 -04001668#endif
1669
Michael Chan697197e2018-10-14 07:02:46 -04001670#if BITS_PER_LONG == 32
1671 /* ensure atomic 64-bit doorbell writes on 32-bit systems. */
1672 spinlock_t db_lock;
1673#endif
1674
Michael Chanc0c050c2015-10-22 16:01:17 -04001675#define BNXT_NTP_FLTR_MAX_FLTR 4096
1676#define BNXT_NTP_FLTR_HASH_SIZE 512
1677#define BNXT_NTP_FLTR_HASH_MASK (BNXT_NTP_FLTR_HASH_SIZE - 1)
1678 struct hlist_head ntp_fltr_hash_tbl[BNXT_NTP_FLTR_HASH_SIZE];
1679 spinlock_t ntp_fltr_lock; /* for hash table add, del */
1680
1681 unsigned long *ntp_fltr_bmap;
1682 int ntp_fltr_count;
1683
Michael Chane2dc9b62017-10-13 21:09:30 -04001684 /* To protect link related settings during link changes and
1685 * ethtool settings changes.
1686 */
1687 struct mutex link_lock;
Michael Chanc0c050c2015-10-22 16:01:17 -04001688 struct bnxt_link_info link_info;
Michael Chan170ce012016-04-05 14:08:57 -04001689 struct ethtool_eee eee;
1690 u32 lpi_tmr_lo;
1691 u32 lpi_tmr_hi;
Michael Chan5ad2cbe2017-01-13 01:32:03 -05001692
Michael Chaneb513652017-04-04 18:14:12 -04001693 u8 num_tests;
1694 struct bnxt_test_info *test_info;
1695
Michael Chanc1ef1462017-04-04 18:14:07 -04001696 u8 wol_filter_id;
1697 u8 wol;
1698
Michael Chan5ad2cbe2017-01-13 01:32:03 -05001699 u8 num_leds;
1700 struct bnxt_led_info leds[BNXT_MAX_LED];
Michael Chanc6d30e82017-02-06 16:55:42 -05001701
1702 struct bpf_prog *xdp_prog;
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04001703
1704 /* devlink interface and vf-rep structs */
1705 struct devlink *dl;
Vasundhara Volam782a6242019-01-28 18:00:27 +05301706 struct devlink_port dl_port;
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04001707 enum devlink_eswitch_mode eswitch_mode;
1708 struct bnxt_vf_rep **vf_reps; /* array of vf-rep ptrs */
1709 u16 *cfa_code_map; /* cfa_code -> vf_idx map */
Sathya Perladd4ea1d2018-01-17 03:21:16 -05001710 u8 switch_id[8];
Sathya Perlacd663582017-10-26 11:51:32 -04001711 struct bnxt_tc_info *tc_info;
Andy Gospodarekcabfb092018-04-26 17:44:40 -04001712 struct dentry *debugfs_pdev;
1713 struct dentry *debugfs_dim;
Vasundhara Volamcde49a42018-08-05 16:51:56 -04001714 struct device *hwmon_dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04001715};
1716
Michael Chanc77192f2016-12-02 21:17:18 -05001717#define BNXT_RX_STATS_OFFSET(counter) \
1718 (offsetof(struct rx_port_stats, counter) / 8)
1719
1720#define BNXT_TX_STATS_OFFSET(counter) \
1721 ((offsetof(struct tx_port_stats, counter) + \
1722 sizeof(struct rx_port_stats) + 512) / 8)
1723
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04001724#define BNXT_RX_STATS_EXT_OFFSET(counter) \
1725 (offsetof(struct rx_port_stats_ext, counter) / 8)
1726
Michael Chan36e53342018-10-14 07:02:38 -04001727#define BNXT_TX_STATS_EXT_OFFSET(counter) \
1728 (offsetof(struct tx_port_stats_ext, counter) / 8)
1729
Vasundhara Volam55e43982019-05-05 07:17:00 -04001730#define BNXT_PCIE_STATS_OFFSET(counter) \
1731 (offsetof(struct pcie_ctx_hw_stats, counter) / 8)
1732
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04001733#define I2C_DEV_ADDR_A0 0xa0
1734#define I2C_DEV_ADDR_A2 0xa2
Vasundhara Volam7328a232018-05-08 03:18:40 -04001735#define SFF_DIAG_SUPPORT_OFFSET 0x5c
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04001736#define SFF_MODULE_ID_SFP 0x3
1737#define SFF_MODULE_ID_QSFP 0xc
1738#define SFF_MODULE_ID_QSFP_PLUS 0xd
1739#define SFF_MODULE_ID_QSFP28 0x11
1740#define BNXT_MAX_PHY_I2C_RESP_SIZE 64
1741
Michael Chan38413402017-02-06 16:55:43 -05001742static inline u32 bnxt_tx_avail(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
1743{
1744 /* Tell compiler to fetch tx indices from memory. */
1745 barrier();
1746
1747 return bp->tx_ring_size -
1748 ((txr->tx_prod - txr->tx_cons) & bp->tx_ring_mask);
1749}
1750
Michael Chan697197e2018-10-14 07:02:46 -04001751#if BITS_PER_LONG == 32
1752#define writeq(val64, db) \
1753do { \
1754 spin_lock(&bp->db_lock); \
1755 writel((val64) & 0xffffffff, db); \
1756 writel((val64) >> 32, (db) + 4); \
1757 spin_unlock(&bp->db_lock); \
1758} while (0)
1759
1760#define writeq_relaxed writeq
1761#endif
1762
Sinan Kayafd141fa2018-03-25 10:39:20 -04001763/* For TX and RX ring doorbells with no ordering guarantee*/
Michael Chan697197e2018-10-14 07:02:46 -04001764static inline void bnxt_db_write_relaxed(struct bnxt *bp,
1765 struct bnxt_db_info *db, u32 idx)
Sinan Kayafd141fa2018-03-25 10:39:20 -04001766{
Michael Chan697197e2018-10-14 07:02:46 -04001767 if (bp->flags & BNXT_FLAG_CHIP_P5) {
1768 writeq_relaxed(db->db_key64 | idx, db->doorbell);
1769 } else {
1770 u32 db_val = db->db_key32 | idx;
1771
1772 writel_relaxed(db_val, db->doorbell);
1773 if (bp->flags & BNXT_FLAG_DOUBLE_DB)
1774 writel_relaxed(db_val, db->doorbell);
1775 }
Sinan Kayafd141fa2018-03-25 10:39:20 -04001776}
1777
Michael Chan434c9752017-05-29 19:06:08 -04001778/* For TX and RX ring doorbells */
Michael Chan697197e2018-10-14 07:02:46 -04001779static inline void bnxt_db_write(struct bnxt *bp, struct bnxt_db_info *db,
1780 u32 idx)
Michael Chan434c9752017-05-29 19:06:08 -04001781{
Michael Chan697197e2018-10-14 07:02:46 -04001782 if (bp->flags & BNXT_FLAG_CHIP_P5) {
1783 writeq(db->db_key64 | idx, db->doorbell);
1784 } else {
1785 u32 db_val = db->db_key32 | idx;
1786
1787 writel(db_val, db->doorbell);
1788 if (bp->flags & BNXT_FLAG_DOUBLE_DB)
1789 writel(db_val, db->doorbell);
1790 }
Michael Chan434c9752017-05-29 19:06:08 -04001791}
1792
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001793static inline bool bnxt_cfa_hwrm_message(u16 req_type)
Venkat Duvvuru5c209fc2018-12-20 03:38:47 -05001794{
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001795 switch (req_type) {
1796 case HWRM_CFA_ENCAP_RECORD_ALLOC:
1797 case HWRM_CFA_ENCAP_RECORD_FREE:
1798 case HWRM_CFA_DECAP_FILTER_ALLOC:
1799 case HWRM_CFA_DECAP_FILTER_FREE:
1800 case HWRM_CFA_NTUPLE_FILTER_ALLOC:
1801 case HWRM_CFA_NTUPLE_FILTER_FREE:
1802 case HWRM_CFA_NTUPLE_FILTER_CFG:
1803 case HWRM_CFA_EM_FLOW_ALLOC:
1804 case HWRM_CFA_EM_FLOW_FREE:
1805 case HWRM_CFA_EM_FLOW_CFG:
1806 case HWRM_CFA_FLOW_ALLOC:
1807 case HWRM_CFA_FLOW_FREE:
1808 case HWRM_CFA_FLOW_INFO:
1809 case HWRM_CFA_FLOW_FLUSH:
1810 case HWRM_CFA_FLOW_STATS:
1811 case HWRM_CFA_METER_PROFILE_ALLOC:
1812 case HWRM_CFA_METER_PROFILE_FREE:
1813 case HWRM_CFA_METER_PROFILE_CFG:
1814 case HWRM_CFA_METER_INSTANCE_ALLOC:
1815 case HWRM_CFA_METER_INSTANCE_FREE:
1816 return true;
1817 default:
1818 return false;
1819 }
Venkat Duvvuru5c209fc2018-12-20 03:38:47 -05001820}
1821
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001822static inline bool bnxt_kong_hwrm_message(struct bnxt *bp, struct input *req)
1823{
1824 return (bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL &&
1825 bnxt_cfa_hwrm_message(le16_to_cpu(req->req_type)));
1826}
1827
1828static inline bool bnxt_hwrm_kong_chnl(struct bnxt *bp, struct input *req)
1829{
1830 return (bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL &&
1831 req->resp_addr == cpu_to_le64(bp->hwrm_cmd_kong_resp_dma_addr));
1832}
1833
1834static inline void *bnxt_get_hwrm_resp_addr(struct bnxt *bp, void *req)
1835{
1836 if (bnxt_hwrm_kong_chnl(bp, (struct input *)req))
1837 return bp->hwrm_cmd_kong_resp_addr;
1838 else
1839 return bp->hwrm_cmd_resp_addr;
1840}
1841
1842static inline u16 bnxt_get_hwrm_seq_id(struct bnxt *bp, u16 dst)
Venkat Duvvuru5c209fc2018-12-20 03:38:47 -05001843{
1844 u16 seq_id;
1845
Venkat Duvvuru760b6d32018-12-20 03:38:48 -05001846 if (dst == BNXT_HWRM_CHNL_CHIMP)
1847 seq_id = bp->hwrm_cmd_seq++;
1848 else
1849 seq_id = bp->hwrm_cmd_kong_seq++;
Venkat Duvvuru5c209fc2018-12-20 03:38:47 -05001850 return seq_id;
1851}
1852
Michael Chan38413402017-02-06 16:55:43 -05001853extern const u16 bnxt_lhint_arr[];
1854
1855int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1856 u16 prod, gfp_t gfp);
Michael Chanc6d30e82017-02-06 16:55:42 -05001857void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data);
1858void bnxt_set_tpa_flags(struct bnxt *bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001859void bnxt_set_ring_params(struct bnxt *);
Michael Chanc61fb992017-02-06 16:55:36 -05001860int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode);
Michael Chanc0c050c2015-10-22 16:01:17 -04001861void bnxt_hwrm_cmd_hdr_init(struct bnxt *, void *, u16, u16, u16);
1862int _hwrm_send_message(struct bnxt *, void *, u32, int);
Michael Chancc72f3b2017-10-13 21:09:33 -04001863int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 len, int timeout);
Michael Chanc0c050c2015-10-22 16:01:17 -04001864int hwrm_send_message(struct bnxt *, void *, u32, int);
Michael Chan90e209212016-02-26 04:00:08 -05001865int hwrm_send_message_silent(struct bnxt *, void *, u32, int);
Michael Chana1653b12016-12-07 00:26:20 -05001866int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
1867 int bmap_size);
Michael Chana588e452016-12-07 00:26:21 -05001868int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id);
Michael Chan391be5c2016-12-29 12:13:41 -05001869int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);
Michael Chanb16b6892018-12-16 18:46:25 -05001870int bnxt_nq_rings_in_use(struct bnxt *bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001871int bnxt_hwrm_set_coal(struct bnxt *);
Michael Chane4060d32016-12-07 00:26:19 -05001872unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
Vasundhara Volamc027c6b2018-12-16 18:46:21 -05001873unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp);
Michael Chane4060d32016-12-07 00:26:19 -05001874unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);
Michael Chane916b082018-12-16 18:46:20 -05001875unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt *bp);
Michael Chanfbcfc8e2018-03-31 13:54:20 -04001876int bnxt_get_avail_msix(struct bnxt *bp, int num);
Michael Chan1b3f0b72019-05-22 19:12:55 -04001877int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init);
Michael Chan7df4ae92016-12-02 21:17:17 -05001878void bnxt_tx_disable(struct bnxt *bp);
1879void bnxt_tx_enable(struct bnxt *bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001880int bnxt_hwrm_set_pause(struct bnxt *);
Michael Chan939f7f02016-04-05 14:08:58 -04001881int bnxt_hwrm_set_link_setting(struct bnxt *, bool, bool);
Michael Chan5282db62017-04-04 18:14:10 -04001882int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp);
1883int bnxt_hwrm_free_wol_fltr(struct bnxt *bp);
Michael Chandb4723b2018-03-31 13:54:13 -04001884int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all);
Rob Swindell5ac67d82016-09-19 03:58:03 -04001885int bnxt_hwrm_fw_set_time(struct bnxt *);
Michael Chanc0c050c2015-10-22 16:01:17 -04001886int bnxt_open_nic(struct bnxt *, bool, bool);
Michael Chanf7dc1ea2017-04-04 18:14:13 -04001887int bnxt_half_open_nic(struct bnxt *bp);
1888void bnxt_half_close_nic(struct bnxt *bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001889int bnxt_close_nic(struct bnxt *, bool, bool);
Michael Chan98fdbe72017-08-28 13:40:26 -04001890int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
1891 int tx_xdp);
Michael Chanc5e3deb2016-12-02 21:17:15 -05001892int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
Michael Chan6e6c5a52016-01-02 23:45:02 -05001893int bnxt_get_max_rings(struct bnxt *, int *, int *, bool);
Michael Chan80fcaf42018-01-17 03:21:05 -05001894int bnxt_restore_pf_fw_resources(struct bnxt *bp);
Florian Fainelli52d52542019-02-06 09:45:36 -08001895int bnxt_get_port_parent_id(struct net_device *dev,
1896 struct netdev_phys_item_id *ppid);
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001897void bnxt_dim_work(struct work_struct *work);
1898int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi);
1899
Michael Chanc0c050c2015-10-22 16:01:17 -04001900#endif