1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2019 Broadcom Limited
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.
11 #include <linux/module.h>
13 #include <linux/stringify.h>
14 #include <linux/kernel.h>
15 #include <linux/timer.h>
16 #include <linux/errno.h>
17 #include <linux/ioport.h>
18 #include <linux/slab.h>
19 #include <linux/vmalloc.h>
20 #include <linux/interrupt.h>
21 #include <linux/pci.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/bitops.h>
28 #include <linux/irq.h>
29 #include <linux/delay.h>
30 #include <asm/byteorder.h>
32 #include <linux/time.h>
33 #include <linux/mii.h>
34 #include <linux/mdio.h>
36 #include <linux/if_vlan.h>
37 #include <linux/if_bridge.h>
38 #include <linux/rtc.h>
39 #include <linux/bpf.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <net/udp_tunnel.h>
46 #include <linux/workqueue.h>
47 #include <linux/prefetch.h>
48 #include <linux/cache.h>
49 #include <linux/log2.h>
50 #include <linux/aer.h>
51 #include <linux/bitmap.h>
52 #include <linux/ptp_clock_kernel.h>
53 #include <linux/timecounter.h>
54 #include <linux/cpu_rmap.h>
55 #include <linux/cpumask.h>
56 #include <net/pkt_cls.h>
57 #include <linux/hwmon.h>
58 #include <linux/hwmon-sysfs.h>
59 #include <net/page_pool.h>
64 #include "bnxt_sriov.h"
65 #include "bnxt_ethtool.h"
71 #include "bnxt_devlink.h"
72 #include "bnxt_debugfs.h"
74 #define BNXT_TX_TIMEOUT (5 * HZ)
75 #define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW)
77 MODULE_LICENSE("GPL");
78 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
80 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
81 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
82 #define BNXT_RX_COPY_THRESH 256
84 #define BNXT_TX_PUSH_THRESH 164
131 NETXTREME_E_P5_VF_HV
,
134 /* indexed by enum above */
135 static const struct {
138 [BCM57301
] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
139 [BCM57302
] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
140 [BCM57304
] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
141 [BCM57417_NPAR
] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
142 [BCM58700
] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
143 [BCM57311
] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
144 [BCM57312
] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
145 [BCM57402
] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
146 [BCM57404
] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
147 [BCM57406
] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
148 [BCM57402_NPAR
] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
149 [BCM57407
] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
150 [BCM57412
] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
151 [BCM57414
] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
152 [BCM57416
] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
153 [BCM57417
] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
154 [BCM57412_NPAR
] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
155 [BCM57314
] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
156 [BCM57417_SFP
] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
157 [BCM57416_SFP
] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
158 [BCM57404_NPAR
] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
159 [BCM57406_NPAR
] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
160 [BCM57407_SFP
] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
161 [BCM57407_NPAR
] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
162 [BCM57414_NPAR
] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
163 [BCM57416_NPAR
] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
164 [BCM57452
] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
165 [BCM57454
] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
166 [BCM5745x_NPAR
] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
167 [BCM57508
] = { "Broadcom BCM57508 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
168 [BCM57504
] = { "Broadcom BCM57504 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
169 [BCM57502
] = { "Broadcom BCM57502 NetXtreme-E 10Gb/25Gb/50Gb Ethernet" },
170 [BCM57508_NPAR
] = { "Broadcom BCM57508 NetXtreme-E Ethernet Partition" },
171 [BCM57504_NPAR
] = { "Broadcom BCM57504 NetXtreme-E Ethernet Partition" },
172 [BCM57502_NPAR
] = { "Broadcom BCM57502 NetXtreme-E Ethernet Partition" },
173 [BCM58802
] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
174 [BCM58804
] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
175 [BCM58808
] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
176 [NETXTREME_E_VF
] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
177 [NETXTREME_C_VF
] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
178 [NETXTREME_S_VF
] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
179 [NETXTREME_C_VF_HV
] = { "Broadcom NetXtreme-C Virtual Function for Hyper-V" },
180 [NETXTREME_E_VF_HV
] = { "Broadcom NetXtreme-E Virtual Function for Hyper-V" },
181 [NETXTREME_E_P5_VF
] = { "Broadcom BCM5750X NetXtreme-E Ethernet Virtual Function" },
182 [NETXTREME_E_P5_VF_HV
] = { "Broadcom BCM5750X NetXtreme-E Virtual Function for Hyper-V" },
185 static const struct pci_device_id bnxt_pci_tbl
[] = {
186 { PCI_VDEVICE(BROADCOM
, 0x1604), .driver_data
= BCM5745x_NPAR
},
187 { PCI_VDEVICE(BROADCOM
, 0x1605), .driver_data
= BCM5745x_NPAR
},
188 { PCI_VDEVICE(BROADCOM
, 0x1614), .driver_data
= BCM57454
},
189 { PCI_VDEVICE(BROADCOM
, 0x16c0), .driver_data
= BCM57417_NPAR
},
190 { PCI_VDEVICE(BROADCOM
, 0x16c8), .driver_data
= BCM57301
},
191 { PCI_VDEVICE(BROADCOM
, 0x16c9), .driver_data
= BCM57302
},
192 { PCI_VDEVICE(BROADCOM
, 0x16ca), .driver_data
= BCM57304
},
193 { PCI_VDEVICE(BROADCOM
, 0x16cc), .driver_data
= BCM57417_NPAR
},
194 { PCI_VDEVICE(BROADCOM
, 0x16cd), .driver_data
= BCM58700
},
195 { PCI_VDEVICE(BROADCOM
, 0x16ce), .driver_data
= BCM57311
},
196 { PCI_VDEVICE(BROADCOM
, 0x16cf), .driver_data
= BCM57312
},
197 { PCI_VDEVICE(BROADCOM
, 0x16d0), .driver_data
= BCM57402
},
198 { PCI_VDEVICE(BROADCOM
, 0x16d1), .driver_data
= BCM57404
},
199 { PCI_VDEVICE(BROADCOM
, 0x16d2), .driver_data
= BCM57406
},
200 { PCI_VDEVICE(BROADCOM
, 0x16d4), .driver_data
= BCM57402_NPAR
},
201 { PCI_VDEVICE(BROADCOM
, 0x16d5), .driver_data
= BCM57407
},
202 { PCI_VDEVICE(BROADCOM
, 0x16d6), .driver_data
= BCM57412
},
203 { PCI_VDEVICE(BROADCOM
, 0x16d7), .driver_data
= BCM57414
},
204 { PCI_VDEVICE(BROADCOM
, 0x16d8), .driver_data
= BCM57416
},
205 { PCI_VDEVICE(BROADCOM
, 0x16d9), .driver_data
= BCM57417
},
206 { PCI_VDEVICE(BROADCOM
, 0x16de), .driver_data
= BCM57412_NPAR
},
207 { PCI_VDEVICE(BROADCOM
, 0x16df), .driver_data
= BCM57314
},
208 { PCI_VDEVICE(BROADCOM
, 0x16e2), .driver_data
= BCM57417_SFP
},
209 { PCI_VDEVICE(BROADCOM
, 0x16e3), .driver_data
= BCM57416_SFP
},
210 { PCI_VDEVICE(BROADCOM
, 0x16e7), .driver_data
= BCM57404_NPAR
},
211 { PCI_VDEVICE(BROADCOM
, 0x16e8), .driver_data
= BCM57406_NPAR
},
212 { PCI_VDEVICE(BROADCOM
, 0x16e9), .driver_data
= BCM57407_SFP
},
213 { PCI_VDEVICE(BROADCOM
, 0x16ea), .driver_data
= BCM57407_NPAR
},
214 { PCI_VDEVICE(BROADCOM
, 0x16eb), .driver_data
= BCM57412_NPAR
},
215 { PCI_VDEVICE(BROADCOM
, 0x16ec), .driver_data
= BCM57414_NPAR
},
216 { PCI_VDEVICE(BROADCOM
, 0x16ed), .driver_data
= BCM57414_NPAR
},
217 { PCI_VDEVICE(BROADCOM
, 0x16ee), .driver_data
= BCM57416_NPAR
},
218 { PCI_VDEVICE(BROADCOM
, 0x16ef), .driver_data
= BCM57416_NPAR
},
219 { PCI_VDEVICE(BROADCOM
, 0x16f0), .driver_data
= BCM58808
},
220 { PCI_VDEVICE(BROADCOM
, 0x16f1), .driver_data
= BCM57452
},
221 { PCI_VDEVICE(BROADCOM
, 0x1750), .driver_data
= BCM57508
},
222 { PCI_VDEVICE(BROADCOM
, 0x1751), .driver_data
= BCM57504
},
223 { PCI_VDEVICE(BROADCOM
, 0x1752), .driver_data
= BCM57502
},
224 { PCI_VDEVICE(BROADCOM
, 0x1800), .driver_data
= BCM57508_NPAR
},
225 { PCI_VDEVICE(BROADCOM
, 0x1801), .driver_data
= BCM57504_NPAR
},
226 { PCI_VDEVICE(BROADCOM
, 0x1802), .driver_data
= BCM57502_NPAR
},
227 { PCI_VDEVICE(BROADCOM
, 0x1803), .driver_data
= BCM57508_NPAR
},
228 { PCI_VDEVICE(BROADCOM
, 0x1804), .driver_data
= BCM57504_NPAR
},
229 { PCI_VDEVICE(BROADCOM
, 0x1805), .driver_data
= BCM57502_NPAR
},
230 { PCI_VDEVICE(BROADCOM
, 0xd802), .driver_data
= BCM58802
},
231 { PCI_VDEVICE(BROADCOM
, 0xd804), .driver_data
= BCM58804
},
232 #ifdef CONFIG_BNXT_SRIOV
233 { PCI_VDEVICE(BROADCOM
, 0x1606), .driver_data
= NETXTREME_E_VF
},
234 { PCI_VDEVICE(BROADCOM
, 0x1607), .driver_data
= NETXTREME_E_VF_HV
},
235 { PCI_VDEVICE(BROADCOM
, 0x1608), .driver_data
= NETXTREME_E_VF_HV
},
236 { PCI_VDEVICE(BROADCOM
, 0x1609), .driver_data
= NETXTREME_E_VF
},
237 { PCI_VDEVICE(BROADCOM
, 0x16bd), .driver_data
= NETXTREME_E_VF_HV
},
238 { PCI_VDEVICE(BROADCOM
, 0x16c1), .driver_data
= NETXTREME_E_VF
},
239 { PCI_VDEVICE(BROADCOM
, 0x16c2), .driver_data
= NETXTREME_C_VF_HV
},
240 { PCI_VDEVICE(BROADCOM
, 0x16c3), .driver_data
= NETXTREME_C_VF_HV
},
241 { PCI_VDEVICE(BROADCOM
, 0x16c4), .driver_data
= NETXTREME_E_VF_HV
},
242 { PCI_VDEVICE(BROADCOM
, 0x16c5), .driver_data
= NETXTREME_E_VF_HV
},
243 { PCI_VDEVICE(BROADCOM
, 0x16cb), .driver_data
= NETXTREME_C_VF
},
244 { PCI_VDEVICE(BROADCOM
, 0x16d3), .driver_data
= NETXTREME_E_VF
},
245 { PCI_VDEVICE(BROADCOM
, 0x16dc), .driver_data
= NETXTREME_E_VF
},
246 { PCI_VDEVICE(BROADCOM
, 0x16e1), .driver_data
= NETXTREME_C_VF
},
247 { PCI_VDEVICE(BROADCOM
, 0x16e5), .driver_data
= NETXTREME_C_VF
},
248 { PCI_VDEVICE(BROADCOM
, 0x16e6), .driver_data
= NETXTREME_C_VF_HV
},
249 { PCI_VDEVICE(BROADCOM
, 0x1806), .driver_data
= NETXTREME_E_P5_VF
},
250 { PCI_VDEVICE(BROADCOM
, 0x1807), .driver_data
= NETXTREME_E_P5_VF
},
251 { PCI_VDEVICE(BROADCOM
, 0x1808), .driver_data
= NETXTREME_E_P5_VF_HV
},
252 { PCI_VDEVICE(BROADCOM
, 0x1809), .driver_data
= NETXTREME_E_P5_VF_HV
},
253 { PCI_VDEVICE(BROADCOM
, 0xd800), .driver_data
= NETXTREME_S_VF
},
258 MODULE_DEVICE_TABLE(pci
, bnxt_pci_tbl
);
260 static const u16 bnxt_vf_req_snif
[] = {
264 HWRM_CFA_L2_FILTER_ALLOC
,
267 static const u16 bnxt_async_events_arr
[] = {
268 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
,
269 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE
,
270 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
,
271 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
,
272 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
,
273 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
,
274 ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE
,
275 ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY
,
276 ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
,
277 ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION
,
278 ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG
,
279 ASYNC_EVENT_CMPL_EVENT_ID_ECHO_REQUEST
,
282 static struct workqueue_struct
*bnxt_pf_wq
;
284 static bool bnxt_vf_pciid(enum board_idx idx
)
286 return (idx
== NETXTREME_C_VF
|| idx
== NETXTREME_E_VF
||
287 idx
== NETXTREME_S_VF
|| idx
== NETXTREME_C_VF_HV
||
288 idx
== NETXTREME_E_VF_HV
|| idx
== NETXTREME_E_P5_VF
||
289 idx
== NETXTREME_E_P5_VF_HV
);
292 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
293 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
294 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
296 #define BNXT_CP_DB_IRQ_DIS(db) \
297 writel(DB_CP_IRQ_DIS_FLAGS, db)
299 #define BNXT_DB_CQ(db, idx) \
300 writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
302 #define BNXT_DB_NQ_P5(db, idx) \
303 writeq((db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), (db)->doorbell)
305 #define BNXT_DB_CQ_ARM(db, idx) \
306 writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
308 #define BNXT_DB_NQ_ARM_P5(db, idx) \
309 writeq((db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx), (db)->doorbell)
311 static void bnxt_db_nq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
313 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
314 BNXT_DB_NQ_P5(db
, idx
);
319 static void bnxt_db_nq_arm(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
321 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
322 BNXT_DB_NQ_ARM_P5(db
, idx
);
324 BNXT_DB_CQ_ARM(db
, idx
);
327 static void bnxt_db_cq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
329 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
330 writeq(db
->db_key64
| DBR_TYPE_CQ_ARMALL
| RING_CMP(idx
),
336 const u16 bnxt_lhint_arr
[] = {
337 TX_BD_FLAGS_LHINT_512_AND_SMALLER
,
338 TX_BD_FLAGS_LHINT_512_TO_1023
,
339 TX_BD_FLAGS_LHINT_1024_TO_2047
,
340 TX_BD_FLAGS_LHINT_1024_TO_2047
,
341 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
342 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
343 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
344 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
345 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
346 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
347 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
348 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
349 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
350 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
351 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
352 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
353 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
354 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
355 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
358 static u16
bnxt_xmit_get_cfa_action(struct sk_buff
*skb
)
360 struct metadata_dst
*md_dst
= skb_metadata_dst(skb
);
362 if (!md_dst
|| md_dst
->type
!= METADATA_HW_PORT_MUX
)
365 return md_dst
->u
.port_info
.port_id
;
368 static netdev_tx_t
bnxt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
370 struct bnxt
*bp
= netdev_priv(dev
);
372 struct tx_bd_ext
*txbd1
;
373 struct netdev_queue
*txq
;
376 unsigned int length
, pad
= 0;
377 u32 len
, free_size
, vlan_tag_flags
, cfa_action
, flags
;
379 struct pci_dev
*pdev
= bp
->pdev
;
380 struct bnxt_tx_ring_info
*txr
;
381 struct bnxt_sw_tx_bd
*tx_buf
;
384 i
= skb_get_queue_mapping(skb
);
385 if (unlikely(i
>= bp
->tx_nr_rings
)) {
386 dev_kfree_skb_any(skb
);
390 txq
= netdev_get_tx_queue(dev
, i
);
391 txr
= &bp
->tx_ring
[bp
->tx_ring_map
[i
]];
394 free_size
= bnxt_tx_avail(bp
, txr
);
395 if (unlikely(free_size
< skb_shinfo(skb
)->nr_frags
+ 2)) {
396 netif_tx_stop_queue(txq
);
397 return NETDEV_TX_BUSY
;
401 len
= skb_headlen(skb
);
402 last_frag
= skb_shinfo(skb
)->nr_frags
;
404 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
406 txbd
->tx_bd_opaque
= prod
;
408 tx_buf
= &txr
->tx_buf_ring
[prod
];
410 tx_buf
->nr_frags
= last_frag
;
413 cfa_action
= bnxt_xmit_get_cfa_action(skb
);
414 if (skb_vlan_tag_present(skb
)) {
415 vlan_tag_flags
= TX_BD_CFA_META_KEY_VLAN
|
416 skb_vlan_tag_get(skb
);
417 /* Currently supports 8021Q, 8021AD vlan offloads
418 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
420 if (skb
->vlan_proto
== htons(ETH_P_8021Q
))
421 vlan_tag_flags
|= 1 << TX_BD_CFA_META_TPID_SHIFT
;
424 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_HW_TSTAMP
)) {
425 struct bnxt_ptp_cfg
*ptp
= bp
->ptp_cfg
;
427 if (ptp
&& ptp
->tx_tstamp_en
&& !skb_is_gso(skb
) &&
428 atomic_dec_if_positive(&ptp
->tx_avail
) >= 0) {
429 if (!bnxt_ptp_parse(skb
, &ptp
->tx_seqid
,
432 ptp
->tx_hdr_off
+= VLAN_HLEN
;
433 lflags
|= cpu_to_le32(TX_BD_FLAGS_STAMP
);
434 skb_shinfo(skb
)->tx_flags
|= SKBTX_IN_PROGRESS
;
436 atomic_inc(&bp
->ptp_cfg
->tx_avail
);
441 if (unlikely(skb
->no_fcs
))
442 lflags
|= cpu_to_le32(TX_BD_FLAGS_NO_CRC
);
444 if (free_size
== bp
->tx_ring_size
&& length
<= bp
->tx_push_thresh
&&
446 struct tx_push_buffer
*tx_push_buf
= txr
->tx_push
;
447 struct tx_push_bd
*tx_push
= &tx_push_buf
->push_bd
;
448 struct tx_bd_ext
*tx_push1
= &tx_push
->txbd2
;
449 void __iomem
*db
= txr
->tx_db
.doorbell
;
450 void *pdata
= tx_push_buf
->data
;
454 /* Set COAL_NOW to be ready quickly for the next push */
455 tx_push
->tx_bd_len_flags_type
=
456 cpu_to_le32((length
<< TX_BD_LEN_SHIFT
) |
457 TX_BD_TYPE_LONG_TX_BD
|
458 TX_BD_FLAGS_LHINT_512_AND_SMALLER
|
459 TX_BD_FLAGS_COAL_NOW
|
460 TX_BD_FLAGS_PACKET_END
|
461 (2 << TX_BD_FLAGS_BD_CNT_SHIFT
));
463 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
464 tx_push1
->tx_bd_hsize_lflags
=
465 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
467 tx_push1
->tx_bd_hsize_lflags
= 0;
469 tx_push1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
470 tx_push1
->tx_bd_cfa_action
=
471 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
473 end
= pdata
+ length
;
474 end
= PTR_ALIGN(end
, 8) - 1;
477 skb_copy_from_linear_data(skb
, pdata
, len
);
479 for (j
= 0; j
< last_frag
; j
++) {
480 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[j
];
483 fptr
= skb_frag_address_safe(frag
);
487 memcpy(pdata
, fptr
, skb_frag_size(frag
));
488 pdata
+= skb_frag_size(frag
);
491 txbd
->tx_bd_len_flags_type
= tx_push
->tx_bd_len_flags_type
;
492 txbd
->tx_bd_haddr
= txr
->data_mapping
;
493 prod
= NEXT_TX(prod
);
494 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
495 memcpy(txbd
, tx_push1
, sizeof(*txbd
));
496 prod
= NEXT_TX(prod
);
498 cpu_to_le32(DB_KEY_TX_PUSH
| DB_LONG_TX_PUSH
| prod
);
502 netdev_tx_sent_queue(txq
, skb
->len
);
503 wmb(); /* Sync is_push and byte queue before pushing data */
505 push_len
= (length
+ sizeof(*tx_push
) + 7) / 8;
507 __iowrite64_copy(db
, tx_push_buf
, 16);
508 __iowrite32_copy(db
+ 4, tx_push_buf
+ 1,
509 (push_len
- 16) << 1);
511 __iowrite64_copy(db
, tx_push_buf
, push_len
);
518 if (length
< BNXT_MIN_PKT_SIZE
) {
519 pad
= BNXT_MIN_PKT_SIZE
- length
;
520 if (skb_pad(skb
, pad
)) {
521 /* SKB already freed. */
525 length
= BNXT_MIN_PKT_SIZE
;
528 mapping
= dma_map_single(&pdev
->dev
, skb
->data
, len
, DMA_TO_DEVICE
);
530 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
))) {
531 dev_kfree_skb_any(skb
);
536 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
537 flags
= (len
<< TX_BD_LEN_SHIFT
) | TX_BD_TYPE_LONG_TX_BD
|
538 ((last_frag
+ 2) << TX_BD_FLAGS_BD_CNT_SHIFT
);
540 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
542 prod
= NEXT_TX(prod
);
543 txbd1
= (struct tx_bd_ext
*)
544 &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
546 txbd1
->tx_bd_hsize_lflags
= lflags
;
547 if (skb_is_gso(skb
)) {
550 if (skb
->encapsulation
)
551 hdr_len
= skb_inner_network_offset(skb
) +
552 skb_inner_network_header_len(skb
) +
553 inner_tcp_hdrlen(skb
);
555 hdr_len
= skb_transport_offset(skb
) +
558 txbd1
->tx_bd_hsize_lflags
|= cpu_to_le32(TX_BD_FLAGS_LSO
|
560 (hdr_len
<< (TX_BD_HSIZE_SHIFT
- 1)));
561 length
= skb_shinfo(skb
)->gso_size
;
562 txbd1
->tx_bd_mss
= cpu_to_le32(length
);
564 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
565 txbd1
->tx_bd_hsize_lflags
|=
566 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
567 txbd1
->tx_bd_mss
= 0;
571 if (unlikely(length
>= ARRAY_SIZE(bnxt_lhint_arr
))) {
572 dev_warn_ratelimited(&pdev
->dev
, "Dropped oversize %d bytes TX packet.\n",
577 flags
|= bnxt_lhint_arr
[length
];
578 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
580 txbd1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
581 txbd1
->tx_bd_cfa_action
=
582 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
583 for (i
= 0; i
< last_frag
; i
++) {
584 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
586 prod
= NEXT_TX(prod
);
587 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
589 len
= skb_frag_size(frag
);
590 mapping
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, len
,
593 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
)))
596 tx_buf
= &txr
->tx_buf_ring
[prod
];
597 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
599 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
601 flags
= len
<< TX_BD_LEN_SHIFT
;
602 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
606 txbd
->tx_bd_len_flags_type
=
607 cpu_to_le32(((len
+ pad
) << TX_BD_LEN_SHIFT
) | flags
|
608 TX_BD_FLAGS_PACKET_END
);
610 netdev_tx_sent_queue(txq
, skb
->len
);
612 skb_tx_timestamp(skb
);
614 /* Sync BD data before updating doorbell */
617 prod
= NEXT_TX(prod
);
620 if (!netdev_xmit_more() || netif_xmit_stopped(txq
))
621 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
625 if (unlikely(bnxt_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
+ 1)) {
626 if (netdev_xmit_more() && !tx_buf
->is_push
)
627 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
629 netif_tx_stop_queue(txq
);
631 /* netif_tx_stop_queue() must be done before checking
632 * tx index in bnxt_tx_avail() below, because in
633 * bnxt_tx_int(), we update tx index before checking for
634 * netif_tx_queue_stopped().
637 if (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
638 netif_tx_wake_queue(txq
);
643 if (BNXT_TX_PTP_IS_SET(lflags
))
644 atomic_inc(&bp
->ptp_cfg
->tx_avail
);
648 /* start back at beginning and unmap skb */
650 tx_buf
= &txr
->tx_buf_ring
[prod
];
652 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
653 skb_headlen(skb
), PCI_DMA_TODEVICE
);
654 prod
= NEXT_TX(prod
);
656 /* unmap remaining mapped pages */
657 for (i
= 0; i
< last_frag
; i
++) {
658 prod
= NEXT_TX(prod
);
659 tx_buf
= &txr
->tx_buf_ring
[prod
];
660 dma_unmap_page(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
661 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
665 dev_kfree_skb_any(skb
);
669 static void bnxt_tx_int(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int nr_pkts
)
671 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
672 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, txr
->txq_index
);
673 u16 cons
= txr
->tx_cons
;
674 struct pci_dev
*pdev
= bp
->pdev
;
676 unsigned int tx_bytes
= 0;
678 for (i
= 0; i
< nr_pkts
; i
++) {
679 struct bnxt_sw_tx_bd
*tx_buf
;
680 bool compl_deferred
= false;
684 tx_buf
= &txr
->tx_buf_ring
[cons
];
685 cons
= NEXT_TX(cons
);
689 if (tx_buf
->is_push
) {
694 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
695 skb_headlen(skb
), PCI_DMA_TODEVICE
);
696 last
= tx_buf
->nr_frags
;
698 for (j
= 0; j
< last
; j
++) {
699 cons
= NEXT_TX(cons
);
700 tx_buf
= &txr
->tx_buf_ring
[cons
];
703 dma_unmap_addr(tx_buf
, mapping
),
704 skb_frag_size(&skb_shinfo(skb
)->frags
[j
]),
707 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_IN_PROGRESS
)) {
708 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
709 if (!bnxt_get_tx_ts_p5(bp
, skb
))
710 compl_deferred
= true;
712 atomic_inc(&bp
->ptp_cfg
->tx_avail
);
717 cons
= NEXT_TX(cons
);
719 tx_bytes
+= skb
->len
;
721 dev_kfree_skb_any(skb
);
724 netdev_tx_completed_queue(txq
, nr_pkts
, tx_bytes
);
727 /* Need to make the tx_cons update visible to bnxt_start_xmit()
728 * before checking for netif_tx_queue_stopped(). Without the
729 * memory barrier, there is a small possibility that bnxt_start_xmit()
730 * will miss it and cause the queue to be stopped forever.
734 if (unlikely(netif_tx_queue_stopped(txq
)) &&
735 (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
736 __netif_tx_lock(txq
, smp_processor_id());
737 if (netif_tx_queue_stopped(txq
) &&
738 bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
&&
739 txr
->dev_state
!= BNXT_DEV_STATE_CLOSING
)
740 netif_tx_wake_queue(txq
);
741 __netif_tx_unlock(txq
);
745 static struct page
*__bnxt_alloc_rx_page(struct bnxt
*bp
, dma_addr_t
*mapping
,
746 struct bnxt_rx_ring_info
*rxr
,
749 struct device
*dev
= &bp
->pdev
->dev
;
752 page
= page_pool_dev_alloc_pages(rxr
->page_pool
);
756 *mapping
= dma_map_page_attrs(dev
, page
, 0, PAGE_SIZE
, bp
->rx_dir
,
757 DMA_ATTR_WEAK_ORDERING
);
758 if (dma_mapping_error(dev
, *mapping
)) {
759 page_pool_recycle_direct(rxr
->page_pool
, page
);
762 *mapping
+= bp
->rx_dma_offset
;
766 static inline u8
*__bnxt_alloc_rx_data(struct bnxt
*bp
, dma_addr_t
*mapping
,
770 struct pci_dev
*pdev
= bp
->pdev
;
772 data
= kmalloc(bp
->rx_buf_size
, gfp
);
776 *mapping
= dma_map_single_attrs(&pdev
->dev
, data
+ bp
->rx_dma_offset
,
777 bp
->rx_buf_use_size
, bp
->rx_dir
,
778 DMA_ATTR_WEAK_ORDERING
);
780 if (dma_mapping_error(&pdev
->dev
, *mapping
)) {
787 int bnxt_alloc_rx_data(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
790 struct rx_bd
*rxbd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
791 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[prod
];
794 if (BNXT_RX_PAGE_MODE(bp
)) {
796 __bnxt_alloc_rx_page(bp
, &mapping
, rxr
, gfp
);
802 rx_buf
->data_ptr
= page_address(page
) + bp
->rx_offset
;
804 u8
*data
= __bnxt_alloc_rx_data(bp
, &mapping
, gfp
);
810 rx_buf
->data_ptr
= data
+ bp
->rx_offset
;
812 rx_buf
->mapping
= mapping
;
814 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
818 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info
*rxr
, u16 cons
, void *data
)
820 u16 prod
= rxr
->rx_prod
;
821 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
822 struct rx_bd
*cons_bd
, *prod_bd
;
824 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
825 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
827 prod_rx_buf
->data
= data
;
828 prod_rx_buf
->data_ptr
= cons_rx_buf
->data_ptr
;
830 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
832 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
833 cons_bd
= &rxr
->rx_desc_ring
[RX_RING(cons
)][RX_IDX(cons
)];
835 prod_bd
->rx_bd_haddr
= cons_bd
->rx_bd_haddr
;
838 static inline u16
bnxt_find_next_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
840 u16 next
, max
= rxr
->rx_agg_bmap_size
;
842 next
= find_next_zero_bit(rxr
->rx_agg_bmap
, max
, idx
);
844 next
= find_first_zero_bit(rxr
->rx_agg_bmap
, max
);
848 static inline int bnxt_alloc_rx_page(struct bnxt
*bp
,
849 struct bnxt_rx_ring_info
*rxr
,
853 &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
854 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
;
855 struct pci_dev
*pdev
= bp
->pdev
;
858 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
859 unsigned int offset
= 0;
861 if (PAGE_SIZE
> BNXT_RX_PAGE_SIZE
) {
864 page
= alloc_page(gfp
);
868 rxr
->rx_page_offset
= 0;
870 offset
= rxr
->rx_page_offset
;
871 rxr
->rx_page_offset
+= BNXT_RX_PAGE_SIZE
;
872 if (rxr
->rx_page_offset
== PAGE_SIZE
)
877 page
= alloc_page(gfp
);
882 mapping
= dma_map_page_attrs(&pdev
->dev
, page
, offset
,
883 BNXT_RX_PAGE_SIZE
, PCI_DMA_FROMDEVICE
,
884 DMA_ATTR_WEAK_ORDERING
);
885 if (dma_mapping_error(&pdev
->dev
, mapping
)) {
890 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
891 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
893 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
894 rx_agg_buf
= &rxr
->rx_agg_ring
[sw_prod
];
895 rxr
->rx_sw_agg_prod
= NEXT_RX_AGG(sw_prod
);
897 rx_agg_buf
->page
= page
;
898 rx_agg_buf
->offset
= offset
;
899 rx_agg_buf
->mapping
= mapping
;
900 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
901 rxbd
->rx_bd_opaque
= sw_prod
;
905 static struct rx_agg_cmp
*bnxt_get_agg(struct bnxt
*bp
,
906 struct bnxt_cp_ring_info
*cpr
,
907 u16 cp_cons
, u16 curr
)
909 struct rx_agg_cmp
*agg
;
911 cp_cons
= RING_CMP(ADV_RAW_CMP(cp_cons
, curr
));
912 agg
= (struct rx_agg_cmp
*)
913 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
917 static struct rx_agg_cmp
*bnxt_get_tpa_agg_p5(struct bnxt
*bp
,
918 struct bnxt_rx_ring_info
*rxr
,
919 u16 agg_id
, u16 curr
)
921 struct bnxt_tpa_info
*tpa_info
= &rxr
->rx_tpa
[agg_id
];
923 return &tpa_info
->agg_arr
[curr
];
926 static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info
*cpr
, u16 idx
,
927 u16 start
, u32 agg_bufs
, bool tpa
)
929 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
930 struct bnxt
*bp
= bnapi
->bp
;
931 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
932 u16 prod
= rxr
->rx_agg_prod
;
933 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
937 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && tpa
)
940 for (i
= 0; i
< agg_bufs
; i
++) {
942 struct rx_agg_cmp
*agg
;
943 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
, *prod_rx_buf
;
944 struct rx_bd
*prod_bd
;
948 agg
= bnxt_get_tpa_agg_p5(bp
, rxr
, idx
, start
+ i
);
950 agg
= bnxt_get_agg(bp
, cpr
, idx
, start
+ i
);
951 cons
= agg
->rx_agg_cmp_opaque
;
952 __clear_bit(cons
, rxr
->rx_agg_bmap
);
954 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
955 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
957 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
958 prod_rx_buf
= &rxr
->rx_agg_ring
[sw_prod
];
959 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
961 /* It is possible for sw_prod to be equal to cons, so
962 * set cons_rx_buf->page to NULL first.
964 page
= cons_rx_buf
->page
;
965 cons_rx_buf
->page
= NULL
;
966 prod_rx_buf
->page
= page
;
967 prod_rx_buf
->offset
= cons_rx_buf
->offset
;
969 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
971 prod_bd
= &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
973 prod_bd
->rx_bd_haddr
= cpu_to_le64(cons_rx_buf
->mapping
);
974 prod_bd
->rx_bd_opaque
= sw_prod
;
976 prod
= NEXT_RX_AGG(prod
);
977 sw_prod
= NEXT_RX_AGG(sw_prod
);
979 rxr
->rx_agg_prod
= prod
;
980 rxr
->rx_sw_agg_prod
= sw_prod
;
983 static struct sk_buff
*bnxt_rx_page_skb(struct bnxt
*bp
,
984 struct bnxt_rx_ring_info
*rxr
,
985 u16 cons
, void *data
, u8
*data_ptr
,
987 unsigned int offset_and_len
)
989 unsigned int payload
= offset_and_len
>> 16;
990 unsigned int len
= offset_and_len
& 0xffff;
992 struct page
*page
= data
;
993 u16 prod
= rxr
->rx_prod
;
997 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
999 bnxt_reuse_rx_data(rxr
, cons
, data
);
1002 dma_addr
-= bp
->rx_dma_offset
;
1003 dma_unmap_page_attrs(&bp
->pdev
->dev
, dma_addr
, PAGE_SIZE
, bp
->rx_dir
,
1004 DMA_ATTR_WEAK_ORDERING
);
1005 page_pool_release_page(rxr
->page_pool
, page
);
1007 if (unlikely(!payload
))
1008 payload
= eth_get_headlen(bp
->dev
, data_ptr
, len
);
1010 skb
= napi_alloc_skb(&rxr
->bnapi
->napi
, payload
);
1016 off
= (void *)data_ptr
- page_address(page
);
1017 skb_add_rx_frag(skb
, 0, page
, off
, len
, PAGE_SIZE
);
1018 memcpy(skb
->data
- NET_IP_ALIGN
, data_ptr
- NET_IP_ALIGN
,
1019 payload
+ NET_IP_ALIGN
);
1021 frag
= &skb_shinfo(skb
)->frags
[0];
1022 skb_frag_size_sub(frag
, payload
);
1023 skb_frag_off_add(frag
, payload
);
1024 skb
->data_len
-= payload
;
1025 skb
->tail
+= payload
;
1030 static struct sk_buff
*bnxt_rx_skb(struct bnxt
*bp
,
1031 struct bnxt_rx_ring_info
*rxr
, u16 cons
,
1032 void *data
, u8
*data_ptr
,
1033 dma_addr_t dma_addr
,
1034 unsigned int offset_and_len
)
1036 u16 prod
= rxr
->rx_prod
;
1037 struct sk_buff
*skb
;
1040 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
1041 if (unlikely(err
)) {
1042 bnxt_reuse_rx_data(rxr
, cons
, data
);
1046 skb
= build_skb(data
, 0);
1047 dma_unmap_single_attrs(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
1048 bp
->rx_dir
, DMA_ATTR_WEAK_ORDERING
);
1054 skb_reserve(skb
, bp
->rx_offset
);
1055 skb_put(skb
, offset_and_len
& 0xffff);
1059 static struct sk_buff
*bnxt_rx_pages(struct bnxt
*bp
,
1060 struct bnxt_cp_ring_info
*cpr
,
1061 struct sk_buff
*skb
, u16 idx
,
1062 u32 agg_bufs
, bool tpa
)
1064 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1065 struct pci_dev
*pdev
= bp
->pdev
;
1066 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1067 u16 prod
= rxr
->rx_agg_prod
;
1068 bool p5_tpa
= false;
1071 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && tpa
)
1074 for (i
= 0; i
< agg_bufs
; i
++) {
1076 struct rx_agg_cmp
*agg
;
1077 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
;
1082 agg
= bnxt_get_tpa_agg_p5(bp
, rxr
, idx
, i
);
1084 agg
= bnxt_get_agg(bp
, cpr
, idx
, i
);
1085 cons
= agg
->rx_agg_cmp_opaque
;
1086 frag_len
= (le32_to_cpu(agg
->rx_agg_cmp_len_flags_type
) &
1087 RX_AGG_CMP_LEN
) >> RX_AGG_CMP_LEN_SHIFT
;
1089 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
1090 skb_fill_page_desc(skb
, i
, cons_rx_buf
->page
,
1091 cons_rx_buf
->offset
, frag_len
);
1092 __clear_bit(cons
, rxr
->rx_agg_bmap
);
1094 /* It is possible for bnxt_alloc_rx_page() to allocate
1095 * a sw_prod index that equals the cons index, so we
1096 * need to clear the cons entry now.
1098 mapping
= cons_rx_buf
->mapping
;
1099 page
= cons_rx_buf
->page
;
1100 cons_rx_buf
->page
= NULL
;
1102 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_ATOMIC
) != 0) {
1103 struct skb_shared_info
*shinfo
;
1104 unsigned int nr_frags
;
1106 shinfo
= skb_shinfo(skb
);
1107 nr_frags
= --shinfo
->nr_frags
;
1108 __skb_frag_set_page(&shinfo
->frags
[nr_frags
], NULL
);
1112 cons_rx_buf
->page
= page
;
1114 /* Update prod since possibly some pages have been
1115 * allocated already.
1117 rxr
->rx_agg_prod
= prod
;
1118 bnxt_reuse_rx_agg_bufs(cpr
, idx
, i
, agg_bufs
- i
, tpa
);
1122 dma_unmap_page_attrs(&pdev
->dev
, mapping
, BNXT_RX_PAGE_SIZE
,
1124 DMA_ATTR_WEAK_ORDERING
);
1126 skb
->data_len
+= frag_len
;
1127 skb
->len
+= frag_len
;
1128 skb
->truesize
+= PAGE_SIZE
;
1130 prod
= NEXT_RX_AGG(prod
);
1132 rxr
->rx_agg_prod
= prod
;
1136 static int bnxt_agg_bufs_valid(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1137 u8 agg_bufs
, u32
*raw_cons
)
1140 struct rx_agg_cmp
*agg
;
1142 *raw_cons
= ADV_RAW_CMP(*raw_cons
, agg_bufs
);
1143 last
= RING_CMP(*raw_cons
);
1144 agg
= (struct rx_agg_cmp
*)
1145 &cpr
->cp_desc_ring
[CP_RING(last
)][CP_IDX(last
)];
1146 return RX_AGG_CMP_VALID(agg
, *raw_cons
);
1149 static inline struct sk_buff
*bnxt_copy_skb(struct bnxt_napi
*bnapi
, u8
*data
,
1153 struct bnxt
*bp
= bnapi
->bp
;
1154 struct pci_dev
*pdev
= bp
->pdev
;
1155 struct sk_buff
*skb
;
1157 skb
= napi_alloc_skb(&bnapi
->napi
, len
);
1161 dma_sync_single_for_cpu(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1164 memcpy(skb
->data
- NET_IP_ALIGN
, data
- NET_IP_ALIGN
,
1165 len
+ NET_IP_ALIGN
);
1167 dma_sync_single_for_device(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1174 static int bnxt_discard_rx(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1175 u32
*raw_cons
, void *cmp
)
1177 struct rx_cmp
*rxcmp
= cmp
;
1178 u32 tmp_raw_cons
= *raw_cons
;
1179 u8 cmp_type
, agg_bufs
= 0;
1181 cmp_type
= RX_CMP_TYPE(rxcmp
);
1183 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1184 agg_bufs
= (le32_to_cpu(rxcmp
->rx_cmp_misc_v1
) &
1186 RX_CMP_AGG_BUFS_SHIFT
;
1187 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1188 struct rx_tpa_end_cmp
*tpa_end
= cmp
;
1190 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
1193 agg_bufs
= TPA_END_AGG_BUFS(tpa_end
);
1197 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1200 *raw_cons
= tmp_raw_cons
;
1204 static void bnxt_queue_fw_reset_work(struct bnxt
*bp
, unsigned long delay
)
1206 if (!(test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)))
1210 queue_delayed_work(bnxt_pf_wq
, &bp
->fw_reset_task
, delay
);
1212 schedule_delayed_work(&bp
->fw_reset_task
, delay
);
1215 static void bnxt_queue_sp_work(struct bnxt
*bp
)
1218 queue_work(bnxt_pf_wq
, &bp
->sp_task
);
1220 schedule_work(&bp
->sp_task
);
1223 static void bnxt_sched_reset(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
1225 if (!rxr
->bnapi
->in_reset
) {
1226 rxr
->bnapi
->in_reset
= true;
1227 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
1228 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
1230 set_bit(BNXT_RST_RING_SP_EVENT
, &bp
->sp_event
);
1231 bnxt_queue_sp_work(bp
);
1233 rxr
->rx_next_cons
= 0xffff;
1236 static u16
bnxt_alloc_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 agg_id
)
1238 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1239 u16 idx
= agg_id
& MAX_TPA_P5_MASK
;
1241 if (test_bit(idx
, map
->agg_idx_bmap
))
1242 idx
= find_first_zero_bit(map
->agg_idx_bmap
,
1243 BNXT_AGG_IDX_BMAP_SIZE
);
1244 __set_bit(idx
, map
->agg_idx_bmap
);
1245 map
->agg_id_tbl
[agg_id
] = idx
;
1249 static void bnxt_free_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
1251 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1253 __clear_bit(idx
, map
->agg_idx_bmap
);
1256 static u16
bnxt_lookup_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 agg_id
)
1258 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1260 return map
->agg_id_tbl
[agg_id
];
1263 static void bnxt_tpa_start(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1264 struct rx_tpa_start_cmp
*tpa_start
,
1265 struct rx_tpa_start_cmp_ext
*tpa_start1
)
1267 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
1268 struct bnxt_tpa_info
*tpa_info
;
1269 u16 cons
, prod
, agg_id
;
1270 struct rx_bd
*prod_bd
;
1273 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
1274 agg_id
= TPA_START_AGG_ID_P5(tpa_start
);
1275 agg_id
= bnxt_alloc_agg_idx(rxr
, agg_id
);
1277 agg_id
= TPA_START_AGG_ID(tpa_start
);
1279 cons
= tpa_start
->rx_tpa_start_cmp_opaque
;
1280 prod
= rxr
->rx_prod
;
1281 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1282 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
1283 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1285 if (unlikely(cons
!= rxr
->rx_next_cons
||
1286 TPA_START_ERROR(tpa_start
))) {
1287 netdev_warn(bp
->dev
, "TPA cons %x, expected cons %x, error code %x\n",
1288 cons
, rxr
->rx_next_cons
,
1289 TPA_START_ERROR_CODE(tpa_start1
));
1290 bnxt_sched_reset(bp
, rxr
);
1293 /* Store cfa_code in tpa_info to use in tpa_end
1294 * completion processing.
1296 tpa_info
->cfa_code
= TPA_START_CFA_CODE(tpa_start1
);
1297 prod_rx_buf
->data
= tpa_info
->data
;
1298 prod_rx_buf
->data_ptr
= tpa_info
->data_ptr
;
1300 mapping
= tpa_info
->mapping
;
1301 prod_rx_buf
->mapping
= mapping
;
1303 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
1305 prod_bd
->rx_bd_haddr
= cpu_to_le64(mapping
);
1307 tpa_info
->data
= cons_rx_buf
->data
;
1308 tpa_info
->data_ptr
= cons_rx_buf
->data_ptr
;
1309 cons_rx_buf
->data
= NULL
;
1310 tpa_info
->mapping
= cons_rx_buf
->mapping
;
1313 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_len_flags_type
) >>
1314 RX_TPA_START_CMP_LEN_SHIFT
;
1315 if (likely(TPA_START_HASH_VALID(tpa_start
))) {
1316 u32 hash_type
= TPA_START_HASH_TYPE(tpa_start
);
1318 tpa_info
->hash_type
= PKT_HASH_TYPE_L4
;
1319 tpa_info
->gso_type
= SKB_GSO_TCPV4
;
1320 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1321 if (hash_type
== 3 || TPA_START_IS_IPV6(tpa_start1
))
1322 tpa_info
->gso_type
= SKB_GSO_TCPV6
;
1323 tpa_info
->rss_hash
=
1324 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_rss_hash
);
1326 tpa_info
->hash_type
= PKT_HASH_TYPE_NONE
;
1327 tpa_info
->gso_type
= 0;
1328 netif_warn(bp
, rx_err
, bp
->dev
, "TPA packet without valid hash\n");
1330 tpa_info
->flags2
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_flags2
);
1331 tpa_info
->metadata
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_metadata
);
1332 tpa_info
->hdr_info
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_hdr_info
);
1333 tpa_info
->agg_count
= 0;
1335 rxr
->rx_prod
= NEXT_RX(prod
);
1336 cons
= NEXT_RX(cons
);
1337 rxr
->rx_next_cons
= NEXT_RX(cons
);
1338 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1340 bnxt_reuse_rx_data(rxr
, cons
, cons_rx_buf
->data
);
1341 rxr
->rx_prod
= NEXT_RX(rxr
->rx_prod
);
1342 cons_rx_buf
->data
= NULL
;
1345 static void bnxt_abort_tpa(struct bnxt_cp_ring_info
*cpr
, u16 idx
, u32 agg_bufs
)
1348 bnxt_reuse_rx_agg_bufs(cpr
, idx
, 0, agg_bufs
, true);
1352 static void bnxt_gro_tunnel(struct sk_buff
*skb
, __be16 ip_proto
)
1354 struct udphdr
*uh
= NULL
;
1356 if (ip_proto
== htons(ETH_P_IP
)) {
1357 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1359 if (iph
->protocol
== IPPROTO_UDP
)
1360 uh
= (struct udphdr
*)(iph
+ 1);
1362 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1364 if (iph
->nexthdr
== IPPROTO_UDP
)
1365 uh
= (struct udphdr
*)(iph
+ 1);
1369 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL_CSUM
;
1371 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1376 static struct sk_buff
*bnxt_gro_func_5731x(struct bnxt_tpa_info
*tpa_info
,
1377 int payload_off
, int tcp_ts
,
1378 struct sk_buff
*skb
)
1383 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1384 u32 hdr_info
= tpa_info
->hdr_info
;
1385 bool loopback
= false;
1387 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1388 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1389 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1391 /* If the packet is an internal loopback packet, the offsets will
1392 * have an extra 4 bytes.
1394 if (inner_mac_off
== 4) {
1396 } else if (inner_mac_off
> 4) {
1397 __be16 proto
= *((__be16
*)(skb
->data
+ inner_ip_off
-
1400 /* We only support inner iPv4/ipv6. If we don't see the
1401 * correct protocol ID, it must be a loopback packet where
1402 * the offsets are off by 4.
1404 if (proto
!= htons(ETH_P_IP
) && proto
!= htons(ETH_P_IPV6
))
1408 /* internal loopback packet, subtract all offsets by 4 */
1414 nw_off
= inner_ip_off
- ETH_HLEN
;
1415 skb_set_network_header(skb
, nw_off
);
1416 if (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) {
1417 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
1419 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1420 len
= skb
->len
- skb_transport_offset(skb
);
1422 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1424 struct iphdr
*iph
= ip_hdr(skb
);
1426 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1427 len
= skb
->len
- skb_transport_offset(skb
);
1429 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1432 if (inner_mac_off
) { /* tunnel */
1433 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1436 bnxt_gro_tunnel(skb
, proto
);
1442 static struct sk_buff
*bnxt_gro_func_5750x(struct bnxt_tpa_info
*tpa_info
,
1443 int payload_off
, int tcp_ts
,
1444 struct sk_buff
*skb
)
1447 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1448 u32 hdr_info
= tpa_info
->hdr_info
;
1449 int iphdr_len
, nw_off
;
1451 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1452 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1453 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1455 nw_off
= inner_ip_off
- ETH_HLEN
;
1456 skb_set_network_header(skb
, nw_off
);
1457 iphdr_len
= (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) ?
1458 sizeof(struct ipv6hdr
) : sizeof(struct iphdr
);
1459 skb_set_transport_header(skb
, nw_off
+ iphdr_len
);
1461 if (inner_mac_off
) { /* tunnel */
1462 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1465 bnxt_gro_tunnel(skb
, proto
);
1471 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1472 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1474 static struct sk_buff
*bnxt_gro_func_5730x(struct bnxt_tpa_info
*tpa_info
,
1475 int payload_off
, int tcp_ts
,
1476 struct sk_buff
*skb
)
1480 int len
, nw_off
, tcp_opt_len
= 0;
1485 if (tpa_info
->gso_type
== SKB_GSO_TCPV4
) {
1488 nw_off
= payload_off
- BNXT_IPV4_HDR_SIZE
- tcp_opt_len
-
1490 skb_set_network_header(skb
, nw_off
);
1492 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1493 len
= skb
->len
- skb_transport_offset(skb
);
1495 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1496 } else if (tpa_info
->gso_type
== SKB_GSO_TCPV6
) {
1497 struct ipv6hdr
*iph
;
1499 nw_off
= payload_off
- BNXT_IPV6_HDR_SIZE
- tcp_opt_len
-
1501 skb_set_network_header(skb
, nw_off
);
1502 iph
= ipv6_hdr(skb
);
1503 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1504 len
= skb
->len
- skb_transport_offset(skb
);
1506 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1508 dev_kfree_skb_any(skb
);
1512 if (nw_off
) /* tunnel */
1513 bnxt_gro_tunnel(skb
, skb
->protocol
);
1518 static inline struct sk_buff
*bnxt_gro_skb(struct bnxt
*bp
,
1519 struct bnxt_tpa_info
*tpa_info
,
1520 struct rx_tpa_end_cmp
*tpa_end
,
1521 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1522 struct sk_buff
*skb
)
1528 segs
= TPA_END_TPA_SEGS(tpa_end
);
1532 NAPI_GRO_CB(skb
)->count
= segs
;
1533 skb_shinfo(skb
)->gso_size
=
1534 le32_to_cpu(tpa_end1
->rx_tpa_end_cmp_seg_len
);
1535 skb_shinfo(skb
)->gso_type
= tpa_info
->gso_type
;
1536 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
1537 payload_off
= TPA_END_PAYLOAD_OFF_P5(tpa_end1
);
1539 payload_off
= TPA_END_PAYLOAD_OFF(tpa_end
);
1540 skb
= bp
->gro_func(tpa_info
, payload_off
, TPA_END_GRO_TS(tpa_end
), skb
);
1542 tcp_gro_complete(skb
);
1547 /* Given the cfa_code of a received packet determine which
1548 * netdev (vf-rep or PF) the packet is destined to.
1550 static struct net_device
*bnxt_get_pkt_dev(struct bnxt
*bp
, u16 cfa_code
)
1552 struct net_device
*dev
= bnxt_get_vf_rep(bp
, cfa_code
);
1554 /* if vf-rep dev is NULL, the must belongs to the PF */
1555 return dev
? dev
: bp
->dev
;
1558 static inline struct sk_buff
*bnxt_tpa_end(struct bnxt
*bp
,
1559 struct bnxt_cp_ring_info
*cpr
,
1561 struct rx_tpa_end_cmp
*tpa_end
,
1562 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1565 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1566 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1567 u8
*data_ptr
, agg_bufs
;
1569 struct bnxt_tpa_info
*tpa_info
;
1571 struct sk_buff
*skb
;
1572 u16 idx
= 0, agg_id
;
1576 if (unlikely(bnapi
->in_reset
)) {
1577 int rc
= bnxt_discard_rx(bp
, cpr
, raw_cons
, tpa_end
);
1580 return ERR_PTR(-EBUSY
);
1584 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
1585 agg_id
= TPA_END_AGG_ID_P5(tpa_end
);
1586 agg_id
= bnxt_lookup_agg_idx(rxr
, agg_id
);
1587 agg_bufs
= TPA_END_AGG_BUFS_P5(tpa_end1
);
1588 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1589 if (unlikely(agg_bufs
!= tpa_info
->agg_count
)) {
1590 netdev_warn(bp
->dev
, "TPA end agg_buf %d != expected agg_bufs %d\n",
1591 agg_bufs
, tpa_info
->agg_count
);
1592 agg_bufs
= tpa_info
->agg_count
;
1594 tpa_info
->agg_count
= 0;
1595 *event
|= BNXT_AGG_EVENT
;
1596 bnxt_free_agg_idx(rxr
, agg_id
);
1598 gro
= !!(bp
->flags
& BNXT_FLAG_GRO
);
1600 agg_id
= TPA_END_AGG_ID(tpa_end
);
1601 agg_bufs
= TPA_END_AGG_BUFS(tpa_end
);
1602 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1603 idx
= RING_CMP(*raw_cons
);
1605 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, raw_cons
))
1606 return ERR_PTR(-EBUSY
);
1608 *event
|= BNXT_AGG_EVENT
;
1609 idx
= NEXT_CMP(idx
);
1611 gro
= !!TPA_END_GRO(tpa_end
);
1613 data
= tpa_info
->data
;
1614 data_ptr
= tpa_info
->data_ptr
;
1616 len
= tpa_info
->len
;
1617 mapping
= tpa_info
->mapping
;
1619 if (unlikely(agg_bufs
> MAX_SKB_FRAGS
|| TPA_END_ERRORS(tpa_end1
))) {
1620 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1621 if (agg_bufs
> MAX_SKB_FRAGS
)
1622 netdev_warn(bp
->dev
, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1623 agg_bufs
, (int)MAX_SKB_FRAGS
);
1627 if (len
<= bp
->rx_copy_thresh
) {
1628 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, mapping
);
1630 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1635 dma_addr_t new_mapping
;
1637 new_data
= __bnxt_alloc_rx_data(bp
, &new_mapping
, GFP_ATOMIC
);
1639 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1643 tpa_info
->data
= new_data
;
1644 tpa_info
->data_ptr
= new_data
+ bp
->rx_offset
;
1645 tpa_info
->mapping
= new_mapping
;
1647 skb
= build_skb(data
, 0);
1648 dma_unmap_single_attrs(&bp
->pdev
->dev
, mapping
,
1649 bp
->rx_buf_use_size
, bp
->rx_dir
,
1650 DMA_ATTR_WEAK_ORDERING
);
1654 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1657 skb_reserve(skb
, bp
->rx_offset
);
1662 skb
= bnxt_rx_pages(bp
, cpr
, skb
, idx
, agg_bufs
, true);
1664 /* Page reuse already handled by bnxt_rx_pages(). */
1670 eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, tpa_info
->cfa_code
));
1672 if (tpa_info
->hash_type
!= PKT_HASH_TYPE_NONE
)
1673 skb_set_hash(skb
, tpa_info
->rss_hash
, tpa_info
->hash_type
);
1675 if ((tpa_info
->flags2
& RX_CMP_FLAGS2_META_FORMAT_VLAN
) &&
1676 (skb
->dev
->features
& BNXT_HW_FEATURE_VLAN_ALL_RX
)) {
1677 __be16 vlan_proto
= htons(tpa_info
->metadata
>>
1678 RX_CMP_FLAGS2_METADATA_TPID_SFT
);
1679 u16 vtag
= tpa_info
->metadata
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1681 if (eth_type_vlan(vlan_proto
)) {
1682 __vlan_hwaccel_put_tag(skb
, vlan_proto
, vtag
);
1689 skb_checksum_none_assert(skb
);
1690 if (likely(tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_L4_CS_CALC
)) {
1691 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1693 (tpa_info
->flags2
& RX_CMP_FLAGS2_T_L4_CS_CALC
) >> 3;
1697 skb
= bnxt_gro_skb(bp
, tpa_info
, tpa_end
, tpa_end1
, skb
);
1702 static void bnxt_tpa_agg(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1703 struct rx_agg_cmp
*rx_agg
)
1705 u16 agg_id
= TPA_AGG_AGG_ID(rx_agg
);
1706 struct bnxt_tpa_info
*tpa_info
;
1708 agg_id
= bnxt_lookup_agg_idx(rxr
, agg_id
);
1709 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1710 BUG_ON(tpa_info
->agg_count
>= MAX_SKB_FRAGS
);
1711 tpa_info
->agg_arr
[tpa_info
->agg_count
++] = *rx_agg
;
1714 static void bnxt_deliver_skb(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1715 struct sk_buff
*skb
)
1717 if (skb
->dev
!= bp
->dev
) {
1718 /* this packet belongs to a vf-rep */
1719 bnxt_vf_rep_rx(bp
, skb
);
1722 skb_record_rx_queue(skb
, bnapi
->index
);
1723 napi_gro_receive(&bnapi
->napi
, skb
);
1726 /* returns the following:
1727 * 1 - 1 packet successfully received
1728 * 0 - successful TPA_START, packet not completed yet
1729 * -EBUSY - completion ring does not have all the agg buffers yet
1730 * -ENOMEM - packet aborted due to out of memory
1731 * -EIO - packet aborted due to hw error indicated in BD
1733 static int bnxt_rx_pkt(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1734 u32
*raw_cons
, u8
*event
)
1736 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1737 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1738 struct net_device
*dev
= bp
->dev
;
1739 struct rx_cmp
*rxcmp
;
1740 struct rx_cmp_ext
*rxcmp1
;
1741 u32 tmp_raw_cons
= *raw_cons
;
1742 u16 cfa_code
, cons
, prod
, cp_cons
= RING_CMP(tmp_raw_cons
);
1743 struct bnxt_sw_rx_bd
*rx_buf
;
1745 u8
*data_ptr
, agg_bufs
, cmp_type
;
1746 dma_addr_t dma_addr
;
1747 struct sk_buff
*skb
;
1752 rxcmp
= (struct rx_cmp
*)
1753 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1755 cmp_type
= RX_CMP_TYPE(rxcmp
);
1757 if (cmp_type
== CMP_TYPE_RX_TPA_AGG_CMP
) {
1758 bnxt_tpa_agg(bp
, rxr
, (struct rx_agg_cmp
*)rxcmp
);
1759 goto next_rx_no_prod_no_len
;
1762 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1763 cp_cons
= RING_CMP(tmp_raw_cons
);
1764 rxcmp1
= (struct rx_cmp_ext
*)
1765 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1767 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1770 prod
= rxr
->rx_prod
;
1772 if (cmp_type
== CMP_TYPE_RX_L2_TPA_START_CMP
) {
1773 bnxt_tpa_start(bp
, rxr
, (struct rx_tpa_start_cmp
*)rxcmp
,
1774 (struct rx_tpa_start_cmp_ext
*)rxcmp1
);
1776 *event
|= BNXT_RX_EVENT
;
1777 goto next_rx_no_prod_no_len
;
1779 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1780 skb
= bnxt_tpa_end(bp
, cpr
, &tmp_raw_cons
,
1781 (struct rx_tpa_end_cmp
*)rxcmp
,
1782 (struct rx_tpa_end_cmp_ext
*)rxcmp1
, event
);
1789 bnxt_deliver_skb(bp
, bnapi
, skb
);
1792 *event
|= BNXT_RX_EVENT
;
1793 goto next_rx_no_prod_no_len
;
1796 cons
= rxcmp
->rx_cmp_opaque
;
1797 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1798 int rc1
= bnxt_discard_rx(bp
, cpr
, &tmp_raw_cons
, rxcmp
);
1800 /* 0xffff is forced error, don't print it */
1801 if (rxr
->rx_next_cons
!= 0xffff)
1802 netdev_warn(bp
->dev
, "RX cons %x != expected cons %x\n",
1803 cons
, rxr
->rx_next_cons
);
1804 bnxt_sched_reset(bp
, rxr
);
1807 goto next_rx_no_prod_no_len
;
1809 rx_buf
= &rxr
->rx_buf_ring
[cons
];
1810 data
= rx_buf
->data
;
1811 data_ptr
= rx_buf
->data_ptr
;
1814 misc
= le32_to_cpu(rxcmp
->rx_cmp_misc_v1
);
1815 agg_bufs
= (misc
& RX_CMP_AGG_BUFS
) >> RX_CMP_AGG_BUFS_SHIFT
;
1818 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1821 cp_cons
= NEXT_CMP(cp_cons
);
1822 *event
|= BNXT_AGG_EVENT
;
1824 *event
|= BNXT_RX_EVENT
;
1826 rx_buf
->data
= NULL
;
1827 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L2_ERRORS
) {
1828 u32 rx_err
= le32_to_cpu(rxcmp1
->rx_cmp_cfa_code_errors_v2
);
1830 bnxt_reuse_rx_data(rxr
, cons
, data
);
1832 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, 0, agg_bufs
,
1836 if (rx_err
& RX_CMPL_ERRORS_BUFFER_ERROR_MASK
) {
1837 bnapi
->cp_ring
.sw_stats
.rx
.rx_buf_errors
++;
1838 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
) &&
1839 !(bp
->fw_cap
& BNXT_FW_CAP_RING_MONITOR
)) {
1840 netdev_warn_once(bp
->dev
, "RX buffer error %x\n",
1842 bnxt_sched_reset(bp
, rxr
);
1845 goto next_rx_no_len
;
1848 flags
= le32_to_cpu(rxcmp
->rx_cmp_len_flags_type
);
1849 len
= flags
>> RX_CMP_LEN_SHIFT
;
1850 dma_addr
= rx_buf
->mapping
;
1852 if (bnxt_rx_xdp(bp
, rxr
, cons
, data
, &data_ptr
, &len
, event
)) {
1857 if (len
<= bp
->rx_copy_thresh
) {
1858 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, dma_addr
);
1859 bnxt_reuse_rx_data(rxr
, cons
, data
);
1862 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, 0,
1870 if (rx_buf
->data_ptr
== data_ptr
)
1871 payload
= misc
& RX_CMP_PAYLOAD_OFFSET
;
1874 skb
= bp
->rx_skb_func(bp
, rxr
, cons
, data
, data_ptr
, dma_addr
,
1883 skb
= bnxt_rx_pages(bp
, cpr
, skb
, cp_cons
, agg_bufs
, false);
1890 if (RX_CMP_HASH_VALID(rxcmp
)) {
1891 u32 hash_type
= RX_CMP_HASH_TYPE(rxcmp
);
1892 enum pkt_hash_types type
= PKT_HASH_TYPE_L4
;
1894 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1895 if (hash_type
!= 1 && hash_type
!= 3)
1896 type
= PKT_HASH_TYPE_L3
;
1897 skb_set_hash(skb
, le32_to_cpu(rxcmp
->rx_cmp_rss_hash
), type
);
1900 cfa_code
= RX_CMP_CFA_CODE(rxcmp1
);
1901 skb
->protocol
= eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, cfa_code
));
1903 if ((rxcmp1
->rx_cmp_flags2
&
1904 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN
)) &&
1905 (skb
->dev
->features
& BNXT_HW_FEATURE_VLAN_ALL_RX
)) {
1906 u32 meta_data
= le32_to_cpu(rxcmp1
->rx_cmp_meta_data
);
1907 u16 vtag
= meta_data
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1908 __be16 vlan_proto
= htons(meta_data
>>
1909 RX_CMP_FLAGS2_METADATA_TPID_SFT
);
1911 if (eth_type_vlan(vlan_proto
)) {
1912 __vlan_hwaccel_put_tag(skb
, vlan_proto
, vtag
);
1919 skb_checksum_none_assert(skb
);
1920 if (RX_CMP_L4_CS_OK(rxcmp1
)) {
1921 if (dev
->features
& NETIF_F_RXCSUM
) {
1922 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1923 skb
->csum_level
= RX_CMP_ENCAP(rxcmp1
);
1926 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L4_CS_ERR_BITS
) {
1927 if (dev
->features
& NETIF_F_RXCSUM
)
1928 bnapi
->cp_ring
.sw_stats
.rx
.rx_l4_csum_errors
++;
1932 if (unlikely((flags
& RX_CMP_FLAGS_ITYPES_MASK
) ==
1933 RX_CMP_FLAGS_ITYPE_PTP_W_TS
)) {
1934 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
1935 u32 cmpl_ts
= le32_to_cpu(rxcmp1
->rx_cmp_timestamp
);
1938 if (!bnxt_get_rx_ts_p5(bp
, &ts
, cmpl_ts
)) {
1939 struct bnxt_ptp_cfg
*ptp
= bp
->ptp_cfg
;
1941 spin_lock_bh(&ptp
->ptp_lock
);
1942 ns
= timecounter_cyc2time(&ptp
->tc
, ts
);
1943 spin_unlock_bh(&ptp
->ptp_lock
);
1944 memset(skb_hwtstamps(skb
), 0,
1945 sizeof(*skb_hwtstamps(skb
)));
1946 skb_hwtstamps(skb
)->hwtstamp
= ns_to_ktime(ns
);
1950 bnxt_deliver_skb(bp
, bnapi
, skb
);
1954 cpr
->rx_packets
+= 1;
1955 cpr
->rx_bytes
+= len
;
1958 rxr
->rx_prod
= NEXT_RX(prod
);
1959 rxr
->rx_next_cons
= NEXT_RX(cons
);
1961 next_rx_no_prod_no_len
:
1962 *raw_cons
= tmp_raw_cons
;
1967 /* In netpoll mode, if we are using a combined completion ring, we need to
1968 * discard the rx packets and recycle the buffers.
1970 static int bnxt_force_rx_discard(struct bnxt
*bp
,
1971 struct bnxt_cp_ring_info
*cpr
,
1972 u32
*raw_cons
, u8
*event
)
1974 u32 tmp_raw_cons
= *raw_cons
;
1975 struct rx_cmp_ext
*rxcmp1
;
1976 struct rx_cmp
*rxcmp
;
1980 cp_cons
= RING_CMP(tmp_raw_cons
);
1981 rxcmp
= (struct rx_cmp
*)
1982 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1984 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1985 cp_cons
= RING_CMP(tmp_raw_cons
);
1986 rxcmp1
= (struct rx_cmp_ext
*)
1987 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1989 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1992 cmp_type
= RX_CMP_TYPE(rxcmp
);
1993 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1994 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
1995 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
1996 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1997 struct rx_tpa_end_cmp_ext
*tpa_end1
;
1999 tpa_end1
= (struct rx_tpa_end_cmp_ext
*)rxcmp1
;
2000 tpa_end1
->rx_tpa_end_cmp_errors_v2
|=
2001 cpu_to_le32(RX_TPA_END_CMP_ERRORS
);
2003 return bnxt_rx_pkt(bp
, cpr
, raw_cons
, event
);
2006 u32
bnxt_fw_health_readl(struct bnxt
*bp
, int reg_idx
)
2008 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
2009 u32 reg
= fw_health
->regs
[reg_idx
];
2010 u32 reg_type
, reg_off
, val
= 0;
2012 reg_type
= BNXT_FW_HEALTH_REG_TYPE(reg
);
2013 reg_off
= BNXT_FW_HEALTH_REG_OFF(reg
);
2015 case BNXT_FW_HEALTH_REG_TYPE_CFG
:
2016 pci_read_config_dword(bp
->pdev
, reg_off
, &val
);
2018 case BNXT_FW_HEALTH_REG_TYPE_GRC
:
2019 reg_off
= fw_health
->mapped_regs
[reg_idx
];
2021 case BNXT_FW_HEALTH_REG_TYPE_BAR0
:
2022 val
= readl(bp
->bar0
+ reg_off
);
2024 case BNXT_FW_HEALTH_REG_TYPE_BAR1
:
2025 val
= readl(bp
->bar1
+ reg_off
);
2028 if (reg_idx
== BNXT_FW_RESET_INPROG_REG
)
2029 val
&= fw_health
->fw_reset_inprog_reg_mask
;
2033 static u16
bnxt_agg_ring_id_to_grp_idx(struct bnxt
*bp
, u16 ring_id
)
2037 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2038 u16 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
2039 struct bnxt_ring_grp_info
*grp_info
;
2041 grp_info
= &bp
->grp_info
[grp_idx
];
2042 if (grp_info
->agg_fw_ring_id
== ring_id
)
2045 return INVALID_HW_RING_ID
;
2048 #define BNXT_GET_EVENT_PORT(data) \
2050 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
2052 #define BNXT_EVENT_RING_TYPE(data2) \
2054 ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_MASK)
2056 #define BNXT_EVENT_RING_TYPE_RX(data2) \
2057 (BNXT_EVENT_RING_TYPE(data2) == \
2058 ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_RX)
2060 static int bnxt_async_event_process(struct bnxt
*bp
,
2061 struct hwrm_async_event_cmpl
*cmpl
)
2063 u16 event_id
= le16_to_cpu(cmpl
->event_id
);
2064 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
2065 u32 data2
= le32_to_cpu(cmpl
->event_data2
);
2067 /* TODO CHIMP_FW: Define event id's for link change, error etc */
2069 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
: {
2070 struct bnxt_link_info
*link_info
= &bp
->link_info
;
2073 goto async_event_process_exit
;
2075 /* print unsupported speed warning in forced speed mode only */
2076 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
) &&
2077 (data1
& 0x20000)) {
2078 u16 fw_speed
= link_info
->force_link_speed
;
2079 u32 speed
= bnxt_fw_to_ethtool_speed(fw_speed
);
2081 if (speed
!= SPEED_UNKNOWN
)
2082 netdev_warn(bp
->dev
, "Link speed %d no longer supported\n",
2085 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
, &bp
->sp_event
);
2088 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE
:
2089 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE
:
2090 set_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT
, &bp
->sp_event
);
2092 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
:
2093 set_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
);
2095 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
:
2096 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
);
2098 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
: {
2099 u16 port_id
= BNXT_GET_EVENT_PORT(data1
);
2104 if (bp
->pf
.port_id
!= port_id
)
2107 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
);
2110 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
:
2112 goto async_event_process_exit
;
2113 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
);
2115 case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY
: {
2116 char *fatal_str
= "non-fatal";
2119 goto async_event_process_exit
;
2121 bp
->fw_reset_timestamp
= jiffies
;
2122 bp
->fw_reset_min_dsecs
= cmpl
->timestamp_lo
;
2123 if (!bp
->fw_reset_min_dsecs
)
2124 bp
->fw_reset_min_dsecs
= BNXT_DFLT_FW_RST_MIN_DSECS
;
2125 bp
->fw_reset_max_dsecs
= le16_to_cpu(cmpl
->timestamp_hi
);
2126 if (!bp
->fw_reset_max_dsecs
)
2127 bp
->fw_reset_max_dsecs
= BNXT_DFLT_FW_RST_MAX_DSECS
;
2128 if (EVENT_DATA1_RESET_NOTIFY_FATAL(data1
)) {
2129 fatal_str
= "fatal";
2130 set_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
2132 netif_warn(bp
, hw
, bp
->dev
,
2133 "Firmware %s reset event, data1: 0x%x, data2: 0x%x, min wait %u ms, max wait %u ms\n",
2134 fatal_str
, data1
, data2
,
2135 bp
->fw_reset_min_dsecs
* 100,
2136 bp
->fw_reset_max_dsecs
* 100);
2137 set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT
, &bp
->sp_event
);
2140 case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
: {
2141 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
2144 goto async_event_process_exit
;
2146 fw_health
->enabled
= EVENT_DATA1_RECOVERY_ENABLED(data1
);
2147 fw_health
->master
= EVENT_DATA1_RECOVERY_MASTER_FUNC(data1
);
2148 if (!fw_health
->enabled
) {
2149 netif_info(bp
, drv
, bp
->dev
,
2150 "Error recovery info: error recovery[0]\n");
2153 fw_health
->tmr_multiplier
=
2154 DIV_ROUND_UP(fw_health
->polling_dsecs
* HZ
,
2155 bp
->current_interval
* 10);
2156 fw_health
->tmr_counter
= fw_health
->tmr_multiplier
;
2157 fw_health
->last_fw_heartbeat
=
2158 bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
2159 fw_health
->last_fw_reset_cnt
=
2160 bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
2161 netif_info(bp
, drv
, bp
->dev
,
2162 "Error recovery info: error recovery[1], master[%d], reset count[%u], health status: 0x%x\n",
2163 fw_health
->master
, fw_health
->last_fw_reset_cnt
,
2164 bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
));
2165 goto async_event_process_exit
;
2167 case ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION
:
2168 netif_notice(bp
, hw
, bp
->dev
,
2169 "Received firmware debug notification, data1: 0x%x, data2: 0x%x\n",
2171 goto async_event_process_exit
;
2172 case ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG
: {
2173 struct bnxt_rx_ring_info
*rxr
;
2176 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
2177 goto async_event_process_exit
;
2179 netdev_warn(bp
->dev
, "Ring monitor event, ring type %lu id 0x%x\n",
2180 BNXT_EVENT_RING_TYPE(data2
), data1
);
2181 if (!BNXT_EVENT_RING_TYPE_RX(data2
))
2182 goto async_event_process_exit
;
2184 grp_idx
= bnxt_agg_ring_id_to_grp_idx(bp
, data1
);
2185 if (grp_idx
== INVALID_HW_RING_ID
) {
2186 netdev_warn(bp
->dev
, "Unknown RX agg ring id 0x%x\n",
2188 goto async_event_process_exit
;
2190 rxr
= bp
->bnapi
[grp_idx
]->rx_ring
;
2191 bnxt_sched_reset(bp
, rxr
);
2192 goto async_event_process_exit
;
2194 case ASYNC_EVENT_CMPL_EVENT_ID_ECHO_REQUEST
: {
2195 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
2197 netif_notice(bp
, hw
, bp
->dev
,
2198 "Received firmware echo request, data1: 0x%x, data2: 0x%x\n",
2201 fw_health
->echo_req_data1
= data1
;
2202 fw_health
->echo_req_data2
= data2
;
2203 set_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT
, &bp
->sp_event
);
2206 goto async_event_process_exit
;
2209 goto async_event_process_exit
;
2211 bnxt_queue_sp_work(bp
);
2212 async_event_process_exit
:
2213 bnxt_ulp_async_events(bp
, cmpl
);
2217 static int bnxt_hwrm_handler(struct bnxt
*bp
, struct tx_cmp
*txcmp
)
2219 u16 cmpl_type
= TX_CMP_TYPE(txcmp
), vf_id
, seq_id
;
2220 struct hwrm_cmpl
*h_cmpl
= (struct hwrm_cmpl
*)txcmp
;
2221 struct hwrm_fwd_req_cmpl
*fwd_req_cmpl
=
2222 (struct hwrm_fwd_req_cmpl
*)txcmp
;
2224 switch (cmpl_type
) {
2225 case CMPL_BASE_TYPE_HWRM_DONE
:
2226 seq_id
= le16_to_cpu(h_cmpl
->sequence_id
);
2227 if (seq_id
== bp
->hwrm_intr_seq_id
)
2228 bp
->hwrm_intr_seq_id
= (u16
)~bp
->hwrm_intr_seq_id
;
2230 netdev_err(bp
->dev
, "Invalid hwrm seq id %d\n", seq_id
);
2233 case CMPL_BASE_TYPE_HWRM_FWD_REQ
:
2234 vf_id
= le16_to_cpu(fwd_req_cmpl
->source_id
);
2236 if ((vf_id
< bp
->pf
.first_vf_id
) ||
2237 (vf_id
>= bp
->pf
.first_vf_id
+ bp
->pf
.active_vfs
)) {
2238 netdev_err(bp
->dev
, "Msg contains invalid VF id %x\n",
2243 set_bit(vf_id
- bp
->pf
.first_vf_id
, bp
->pf
.vf_event_bmap
);
2244 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
);
2245 bnxt_queue_sp_work(bp
);
2248 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
:
2249 bnxt_async_event_process(bp
,
2250 (struct hwrm_async_event_cmpl
*)txcmp
);
2260 static irqreturn_t
bnxt_msix(int irq
, void *dev_instance
)
2262 struct bnxt_napi
*bnapi
= dev_instance
;
2263 struct bnxt
*bp
= bnapi
->bp
;
2264 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2265 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
2268 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
2269 napi_schedule(&bnapi
->napi
);
2273 static inline int bnxt_has_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
)
2275 u32 raw_cons
= cpr
->cp_raw_cons
;
2276 u16 cons
= RING_CMP(raw_cons
);
2277 struct tx_cmp
*txcmp
;
2279 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2281 return TX_CMP_VALID(txcmp
, raw_cons
);
2284 static irqreturn_t
bnxt_inta(int irq
, void *dev_instance
)
2286 struct bnxt_napi
*bnapi
= dev_instance
;
2287 struct bnxt
*bp
= bnapi
->bp
;
2288 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2289 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
2292 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
2294 if (!bnxt_has_work(bp
, cpr
)) {
2295 int_status
= readl(bp
->bar0
+ BNXT_CAG_REG_LEGACY_INT_STATUS
);
2296 /* return if erroneous interrupt */
2297 if (!(int_status
& (0x10000 << cpr
->cp_ring_struct
.fw_ring_id
)))
2301 /* disable ring IRQ */
2302 BNXT_CP_DB_IRQ_DIS(cpr
->cp_db
.doorbell
);
2304 /* Return here if interrupt is shared and is disabled. */
2305 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
2308 napi_schedule(&bnapi
->napi
);
2312 static int __bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
2315 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
2316 u32 raw_cons
= cpr
->cp_raw_cons
;
2321 struct tx_cmp
*txcmp
;
2323 cpr
->has_more_work
= 0;
2324 cpr
->had_work_done
= 1;
2328 cons
= RING_CMP(raw_cons
);
2329 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2331 if (!TX_CMP_VALID(txcmp
, raw_cons
))
2334 /* The valid test of the entry must be done first before
2335 * reading any further.
2338 if (TX_CMP_TYPE(txcmp
) == CMP_TYPE_TX_L2_CMP
) {
2340 /* return full budget so NAPI will complete. */
2341 if (unlikely(tx_pkts
> bp
->tx_wake_thresh
)) {
2343 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2345 cpr
->has_more_work
= 1;
2348 } else if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
2350 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
2352 rc
= bnxt_force_rx_discard(bp
, cpr
, &raw_cons
,
2354 if (likely(rc
>= 0))
2356 /* Increment rx_pkts when rc is -ENOMEM to count towards
2357 * the NAPI budget. Otherwise, we may potentially loop
2358 * here forever if we consistently cannot allocate
2361 else if (rc
== -ENOMEM
&& budget
)
2363 else if (rc
== -EBUSY
) /* partial completion */
2365 } else if (unlikely((TX_CMP_TYPE(txcmp
) ==
2366 CMPL_BASE_TYPE_HWRM_DONE
) ||
2367 (TX_CMP_TYPE(txcmp
) ==
2368 CMPL_BASE_TYPE_HWRM_FWD_REQ
) ||
2369 (TX_CMP_TYPE(txcmp
) ==
2370 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
))) {
2371 bnxt_hwrm_handler(bp
, txcmp
);
2373 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2375 if (rx_pkts
&& rx_pkts
== budget
) {
2376 cpr
->has_more_work
= 1;
2381 if (event
& BNXT_REDIRECT_EVENT
)
2384 if (event
& BNXT_TX_EVENT
) {
2385 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
2386 u16 prod
= txr
->tx_prod
;
2388 /* Sync BD data before updating doorbell */
2391 bnxt_db_write_relaxed(bp
, &txr
->tx_db
, prod
);
2394 cpr
->cp_raw_cons
= raw_cons
;
2395 bnapi
->tx_pkts
+= tx_pkts
;
2396 bnapi
->events
|= event
;
2400 static void __bnxt_poll_work_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
2402 if (bnapi
->tx_pkts
) {
2403 bnapi
->tx_int(bp
, bnapi
, bnapi
->tx_pkts
);
2407 if ((bnapi
->events
& BNXT_RX_EVENT
) && !(bnapi
->in_reset
)) {
2408 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2410 if (bnapi
->events
& BNXT_AGG_EVENT
)
2411 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2412 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2417 static int bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
2420 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
2423 rx_pkts
= __bnxt_poll_work(bp
, cpr
, budget
);
2425 /* ACK completion ring before freeing tx ring and producing new
2426 * buffers in rx/agg rings to prevent overflowing the completion
2429 bnxt_db_cq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
2431 __bnxt_poll_work_done(bp
, bnapi
);
2435 static int bnxt_poll_nitroa0(struct napi_struct
*napi
, int budget
)
2437 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2438 struct bnxt
*bp
= bnapi
->bp
;
2439 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2440 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2441 struct tx_cmp
*txcmp
;
2442 struct rx_cmp_ext
*rxcmp1
;
2443 u32 cp_cons
, tmp_raw_cons
;
2444 u32 raw_cons
= cpr
->cp_raw_cons
;
2451 cp_cons
= RING_CMP(raw_cons
);
2452 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2454 if (!TX_CMP_VALID(txcmp
, raw_cons
))
2457 if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
2458 tmp_raw_cons
= NEXT_RAW_CMP(raw_cons
);
2459 cp_cons
= RING_CMP(tmp_raw_cons
);
2460 rxcmp1
= (struct rx_cmp_ext
*)
2461 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2463 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
2466 /* force an error to recycle the buffer */
2467 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
2468 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
2470 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
2471 if (likely(rc
== -EIO
) && budget
)
2473 else if (rc
== -EBUSY
) /* partial completion */
2475 } else if (unlikely(TX_CMP_TYPE(txcmp
) ==
2476 CMPL_BASE_TYPE_HWRM_DONE
)) {
2477 bnxt_hwrm_handler(bp
, txcmp
);
2480 "Invalid completion received on special ring\n");
2482 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2484 if (rx_pkts
== budget
)
2488 cpr
->cp_raw_cons
= raw_cons
;
2489 BNXT_DB_CQ(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2490 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2492 if (event
& BNXT_AGG_EVENT
)
2493 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2495 if (!bnxt_has_work(bp
, cpr
) && rx_pkts
< budget
) {
2496 napi_complete_done(napi
, rx_pkts
);
2497 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2502 static int bnxt_poll(struct napi_struct
*napi
, int budget
)
2504 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2505 struct bnxt
*bp
= bnapi
->bp
;
2506 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2509 if (unlikely(test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))) {
2510 napi_complete(napi
);
2514 work_done
+= bnxt_poll_work(bp
, cpr
, budget
- work_done
);
2516 if (work_done
>= budget
) {
2518 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2522 if (!bnxt_has_work(bp
, cpr
)) {
2523 if (napi_complete_done(napi
, work_done
))
2524 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2528 if (bp
->flags
& BNXT_FLAG_DIM
) {
2529 struct dim_sample dim_sample
= {};
2531 dim_update_sample(cpr
->event_ctr
,
2535 net_dim(&cpr
->dim
, dim_sample
);
2540 static int __bnxt_poll_cqs(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int budget
)
2542 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2543 int i
, work_done
= 0;
2545 for (i
= 0; i
< 2; i
++) {
2546 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2549 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2550 budget
- work_done
);
2551 cpr
->has_more_work
|= cpr2
->has_more_work
;
2557 static void __bnxt_poll_cqs_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
2560 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2563 for (i
= 0; i
< 2; i
++) {
2564 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2565 struct bnxt_db_info
*db
;
2567 if (cpr2
&& cpr2
->had_work_done
) {
2569 writeq(db
->db_key64
| dbr_type
|
2570 RING_CMP(cpr2
->cp_raw_cons
), db
->doorbell
);
2571 cpr2
->had_work_done
= 0;
2574 __bnxt_poll_work_done(bp
, bnapi
);
2577 static int bnxt_poll_p5(struct napi_struct
*napi
, int budget
)
2579 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2580 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2581 u32 raw_cons
= cpr
->cp_raw_cons
;
2582 struct bnxt
*bp
= bnapi
->bp
;
2583 struct nqe_cn
*nqcmp
;
2587 if (unlikely(test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))) {
2588 napi_complete(napi
);
2591 if (cpr
->has_more_work
) {
2592 cpr
->has_more_work
= 0;
2593 work_done
= __bnxt_poll_cqs(bp
, bnapi
, budget
);
2596 cons
= RING_CMP(raw_cons
);
2597 nqcmp
= &cpr
->nq_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2599 if (!NQ_CMP_VALID(nqcmp
, raw_cons
)) {
2600 if (cpr
->has_more_work
)
2603 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ_ARMALL
);
2604 cpr
->cp_raw_cons
= raw_cons
;
2605 if (napi_complete_done(napi
, work_done
))
2606 BNXT_DB_NQ_ARM_P5(&cpr
->cp_db
,
2611 /* The valid test of the entry must be done first before
2612 * reading any further.
2616 if (nqcmp
->type
== cpu_to_le16(NQ_CN_TYPE_CQ_NOTIFICATION
)) {
2617 u32 idx
= le32_to_cpu(nqcmp
->cq_handle_low
);
2618 struct bnxt_cp_ring_info
*cpr2
;
2620 cpr2
= cpr
->cp_ring_arr
[idx
];
2621 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2622 budget
- work_done
);
2623 cpr
->has_more_work
|= cpr2
->has_more_work
;
2625 bnxt_hwrm_handler(bp
, (struct tx_cmp
*)nqcmp
);
2627 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2629 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ
);
2630 if (raw_cons
!= cpr
->cp_raw_cons
) {
2631 cpr
->cp_raw_cons
= raw_cons
;
2632 BNXT_DB_NQ_P5(&cpr
->cp_db
, raw_cons
);
2637 static void bnxt_free_tx_skbs(struct bnxt
*bp
)
2640 struct pci_dev
*pdev
= bp
->pdev
;
2645 max_idx
= bp
->tx_nr_pages
* TX_DESC_CNT
;
2646 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2647 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2650 for (j
= 0; j
< max_idx
;) {
2651 struct bnxt_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
2652 struct sk_buff
*skb
;
2655 if (i
< bp
->tx_nr_rings_xdp
&&
2656 tx_buf
->action
== XDP_REDIRECT
) {
2657 dma_unmap_single(&pdev
->dev
,
2658 dma_unmap_addr(tx_buf
, mapping
),
2659 dma_unmap_len(tx_buf
, len
),
2661 xdp_return_frame(tx_buf
->xdpf
);
2663 tx_buf
->xdpf
= NULL
;
2676 if (tx_buf
->is_push
) {
2682 dma_unmap_single(&pdev
->dev
,
2683 dma_unmap_addr(tx_buf
, mapping
),
2687 last
= tx_buf
->nr_frags
;
2689 for (k
= 0; k
< last
; k
++, j
++) {
2690 int ring_idx
= j
& bp
->tx_ring_mask
;
2691 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[k
];
2693 tx_buf
= &txr
->tx_buf_ring
[ring_idx
];
2696 dma_unmap_addr(tx_buf
, mapping
),
2697 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
2701 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
2705 static void bnxt_free_one_rx_ring_skbs(struct bnxt
*bp
, int ring_nr
)
2707 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[ring_nr
];
2708 struct pci_dev
*pdev
= bp
->pdev
;
2709 struct bnxt_tpa_idx_map
*map
;
2710 int i
, max_idx
, max_agg_idx
;
2712 max_idx
= bp
->rx_nr_pages
* RX_DESC_CNT
;
2713 max_agg_idx
= bp
->rx_agg_nr_pages
* RX_DESC_CNT
;
2715 goto skip_rx_tpa_free
;
2717 for (i
= 0; i
< bp
->max_tpa
; i
++) {
2718 struct bnxt_tpa_info
*tpa_info
= &rxr
->rx_tpa
[i
];
2719 u8
*data
= tpa_info
->data
;
2724 dma_unmap_single_attrs(&pdev
->dev
, tpa_info
->mapping
,
2725 bp
->rx_buf_use_size
, bp
->rx_dir
,
2726 DMA_ATTR_WEAK_ORDERING
);
2728 tpa_info
->data
= NULL
;
2734 for (i
= 0; i
< max_idx
; i
++) {
2735 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[i
];
2736 dma_addr_t mapping
= rx_buf
->mapping
;
2737 void *data
= rx_buf
->data
;
2742 rx_buf
->data
= NULL
;
2743 if (BNXT_RX_PAGE_MODE(bp
)) {
2744 mapping
-= bp
->rx_dma_offset
;
2745 dma_unmap_page_attrs(&pdev
->dev
, mapping
, PAGE_SIZE
,
2747 DMA_ATTR_WEAK_ORDERING
);
2748 page_pool_recycle_direct(rxr
->page_pool
, data
);
2750 dma_unmap_single_attrs(&pdev
->dev
, mapping
,
2751 bp
->rx_buf_use_size
, bp
->rx_dir
,
2752 DMA_ATTR_WEAK_ORDERING
);
2756 for (i
= 0; i
< max_agg_idx
; i
++) {
2757 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
= &rxr
->rx_agg_ring
[i
];
2758 struct page
*page
= rx_agg_buf
->page
;
2763 dma_unmap_page_attrs(&pdev
->dev
, rx_agg_buf
->mapping
,
2764 BNXT_RX_PAGE_SIZE
, PCI_DMA_FROMDEVICE
,
2765 DMA_ATTR_WEAK_ORDERING
);
2767 rx_agg_buf
->page
= NULL
;
2768 __clear_bit(i
, rxr
->rx_agg_bmap
);
2773 __free_page(rxr
->rx_page
);
2774 rxr
->rx_page
= NULL
;
2776 map
= rxr
->rx_tpa_idx_map
;
2778 memset(map
->agg_idx_bmap
, 0, sizeof(map
->agg_idx_bmap
));
2781 static void bnxt_free_rx_skbs(struct bnxt
*bp
)
2788 for (i
= 0; i
< bp
->rx_nr_rings
; i
++)
2789 bnxt_free_one_rx_ring_skbs(bp
, i
);
2792 static void bnxt_free_skbs(struct bnxt
*bp
)
2794 bnxt_free_tx_skbs(bp
);
2795 bnxt_free_rx_skbs(bp
);
2798 static void bnxt_init_ctx_mem(struct bnxt_mem_init
*mem_init
, void *p
, int len
)
2800 u8 init_val
= mem_init
->init_val
;
2801 u16 offset
= mem_init
->offset
;
2807 if (offset
== BNXT_MEM_INVALID_OFFSET
) {
2808 memset(p
, init_val
, len
);
2811 for (i
= 0; i
< len
; i
+= mem_init
->size
)
2812 *(p2
+ i
+ offset
) = init_val
;
2815 static void bnxt_free_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2817 struct pci_dev
*pdev
= bp
->pdev
;
2820 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2821 if (!rmem
->pg_arr
[i
])
2824 dma_free_coherent(&pdev
->dev
, rmem
->page_size
,
2825 rmem
->pg_arr
[i
], rmem
->dma_arr
[i
]);
2827 rmem
->pg_arr
[i
] = NULL
;
2830 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2832 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2833 pg_tbl_size
= rmem
->page_size
;
2834 dma_free_coherent(&pdev
->dev
, pg_tbl_size
,
2835 rmem
->pg_tbl
, rmem
->pg_tbl_map
);
2836 rmem
->pg_tbl
= NULL
;
2838 if (rmem
->vmem_size
&& *rmem
->vmem
) {
2844 static int bnxt_alloc_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2846 struct pci_dev
*pdev
= bp
->pdev
;
2850 if (rmem
->flags
& (BNXT_RMEM_VALID_PTE_FLAG
| BNXT_RMEM_RING_PTE_FLAG
))
2851 valid_bit
= PTU_PTE_VALID
;
2852 if ((rmem
->nr_pages
> 1 || rmem
->depth
> 0) && !rmem
->pg_tbl
) {
2853 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2855 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2856 pg_tbl_size
= rmem
->page_size
;
2857 rmem
->pg_tbl
= dma_alloc_coherent(&pdev
->dev
, pg_tbl_size
,
2864 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2865 u64 extra_bits
= valid_bit
;
2867 rmem
->pg_arr
[i
] = dma_alloc_coherent(&pdev
->dev
,
2871 if (!rmem
->pg_arr
[i
])
2875 bnxt_init_ctx_mem(rmem
->mem_init
, rmem
->pg_arr
[i
],
2877 if (rmem
->nr_pages
> 1 || rmem
->depth
> 0) {
2878 if (i
== rmem
->nr_pages
- 2 &&
2879 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2880 extra_bits
|= PTU_PTE_NEXT_TO_LAST
;
2881 else if (i
== rmem
->nr_pages
- 1 &&
2882 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2883 extra_bits
|= PTU_PTE_LAST
;
2885 cpu_to_le64(rmem
->dma_arr
[i
] | extra_bits
);
2889 if (rmem
->vmem_size
) {
2890 *rmem
->vmem
= vzalloc(rmem
->vmem_size
);
2897 static void bnxt_free_tpa_info(struct bnxt
*bp
)
2901 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2902 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2904 kfree(rxr
->rx_tpa_idx_map
);
2905 rxr
->rx_tpa_idx_map
= NULL
;
2907 kfree(rxr
->rx_tpa
[0].agg_arr
);
2908 rxr
->rx_tpa
[0].agg_arr
= NULL
;
2915 static int bnxt_alloc_tpa_info(struct bnxt
*bp
)
2917 int i
, j
, total_aggs
= 0;
2919 bp
->max_tpa
= MAX_TPA
;
2920 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
2921 if (!bp
->max_tpa_v2
)
2923 bp
->max_tpa
= max_t(u16
, bp
->max_tpa_v2
, MAX_TPA_P5
);
2924 total_aggs
= bp
->max_tpa
* MAX_SKB_FRAGS
;
2927 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2928 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2929 struct rx_agg_cmp
*agg
;
2931 rxr
->rx_tpa
= kcalloc(bp
->max_tpa
, sizeof(struct bnxt_tpa_info
),
2936 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
2938 agg
= kcalloc(total_aggs
, sizeof(*agg
), GFP_KERNEL
);
2939 rxr
->rx_tpa
[0].agg_arr
= agg
;
2942 for (j
= 1; j
< bp
->max_tpa
; j
++)
2943 rxr
->rx_tpa
[j
].agg_arr
= agg
+ j
* MAX_SKB_FRAGS
;
2944 rxr
->rx_tpa_idx_map
= kzalloc(sizeof(*rxr
->rx_tpa_idx_map
),
2946 if (!rxr
->rx_tpa_idx_map
)
2952 static void bnxt_free_rx_rings(struct bnxt
*bp
)
2959 bnxt_free_tpa_info(bp
);
2960 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2961 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2962 struct bnxt_ring_struct
*ring
;
2965 bpf_prog_put(rxr
->xdp_prog
);
2967 if (xdp_rxq_info_is_reg(&rxr
->xdp_rxq
))
2968 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
2970 page_pool_destroy(rxr
->page_pool
);
2971 rxr
->page_pool
= NULL
;
2973 kfree(rxr
->rx_agg_bmap
);
2974 rxr
->rx_agg_bmap
= NULL
;
2976 ring
= &rxr
->rx_ring_struct
;
2977 bnxt_free_ring(bp
, &ring
->ring_mem
);
2979 ring
= &rxr
->rx_agg_ring_struct
;
2980 bnxt_free_ring(bp
, &ring
->ring_mem
);
2984 static int bnxt_alloc_rx_page_pool(struct bnxt
*bp
,
2985 struct bnxt_rx_ring_info
*rxr
)
2987 struct page_pool_params pp
= { 0 };
2989 pp
.pool_size
= bp
->rx_ring_size
;
2990 pp
.nid
= dev_to_node(&bp
->pdev
->dev
);
2991 pp
.dev
= &bp
->pdev
->dev
;
2992 pp
.dma_dir
= DMA_BIDIRECTIONAL
;
2994 rxr
->page_pool
= page_pool_create(&pp
);
2995 if (IS_ERR(rxr
->page_pool
)) {
2996 int err
= PTR_ERR(rxr
->page_pool
);
2998 rxr
->page_pool
= NULL
;
3004 static int bnxt_alloc_rx_rings(struct bnxt
*bp
)
3006 int i
, rc
= 0, agg_rings
= 0;
3011 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
3014 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3015 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3016 struct bnxt_ring_struct
*ring
;
3018 ring
= &rxr
->rx_ring_struct
;
3020 rc
= bnxt_alloc_rx_page_pool(bp
, rxr
);
3024 rc
= xdp_rxq_info_reg(&rxr
->xdp_rxq
, bp
->dev
, i
, 0);
3028 rc
= xdp_rxq_info_reg_mem_model(&rxr
->xdp_rxq
,
3032 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
3036 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
3044 ring
= &rxr
->rx_agg_ring_struct
;
3045 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
3050 rxr
->rx_agg_bmap_size
= bp
->rx_agg_ring_mask
+ 1;
3051 mem_size
= rxr
->rx_agg_bmap_size
/ 8;
3052 rxr
->rx_agg_bmap
= kzalloc(mem_size
, GFP_KERNEL
);
3053 if (!rxr
->rx_agg_bmap
)
3057 if (bp
->flags
& BNXT_FLAG_TPA
)
3058 rc
= bnxt_alloc_tpa_info(bp
);
3062 static void bnxt_free_tx_rings(struct bnxt
*bp
)
3065 struct pci_dev
*pdev
= bp
->pdev
;
3070 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
3071 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3072 struct bnxt_ring_struct
*ring
;
3075 dma_free_coherent(&pdev
->dev
, bp
->tx_push_size
,
3076 txr
->tx_push
, txr
->tx_push_mapping
);
3077 txr
->tx_push
= NULL
;
3080 ring
= &txr
->tx_ring_struct
;
3082 bnxt_free_ring(bp
, &ring
->ring_mem
);
3086 static int bnxt_alloc_tx_rings(struct bnxt
*bp
)
3089 struct pci_dev
*pdev
= bp
->pdev
;
3091 bp
->tx_push_size
= 0;
3092 if (bp
->tx_push_thresh
) {
3095 push_size
= L1_CACHE_ALIGN(sizeof(struct tx_push_bd
) +
3096 bp
->tx_push_thresh
);
3098 if (push_size
> 256) {
3100 bp
->tx_push_thresh
= 0;
3103 bp
->tx_push_size
= push_size
;
3106 for (i
= 0, j
= 0; i
< bp
->tx_nr_rings
; i
++) {
3107 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3108 struct bnxt_ring_struct
*ring
;
3111 ring
= &txr
->tx_ring_struct
;
3113 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
3117 ring
->grp_idx
= txr
->bnapi
->index
;
3118 if (bp
->tx_push_size
) {
3121 /* One pre-allocated DMA buffer to backup
3124 txr
->tx_push
= dma_alloc_coherent(&pdev
->dev
,
3126 &txr
->tx_push_mapping
,
3132 mapping
= txr
->tx_push_mapping
+
3133 sizeof(struct tx_push_bd
);
3134 txr
->data_mapping
= cpu_to_le64(mapping
);
3136 qidx
= bp
->tc_to_qidx
[j
];
3137 ring
->queue_id
= bp
->q_info
[qidx
].queue_id
;
3138 if (i
< bp
->tx_nr_rings_xdp
)
3140 if (i
% bp
->tx_nr_rings_per_tc
== (bp
->tx_nr_rings_per_tc
- 1))
3146 static void bnxt_free_cp_rings(struct bnxt
*bp
)
3153 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3154 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3155 struct bnxt_cp_ring_info
*cpr
;
3156 struct bnxt_ring_struct
*ring
;
3162 cpr
= &bnapi
->cp_ring
;
3163 ring
= &cpr
->cp_ring_struct
;
3165 bnxt_free_ring(bp
, &ring
->ring_mem
);
3167 for (j
= 0; j
< 2; j
++) {
3168 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
3171 ring
= &cpr2
->cp_ring_struct
;
3172 bnxt_free_ring(bp
, &ring
->ring_mem
);
3174 cpr
->cp_ring_arr
[j
] = NULL
;
3180 static struct bnxt_cp_ring_info
*bnxt_alloc_cp_sub_ring(struct bnxt
*bp
)
3182 struct bnxt_ring_mem_info
*rmem
;
3183 struct bnxt_ring_struct
*ring
;
3184 struct bnxt_cp_ring_info
*cpr
;
3187 cpr
= kzalloc(sizeof(*cpr
), GFP_KERNEL
);
3191 ring
= &cpr
->cp_ring_struct
;
3192 rmem
= &ring
->ring_mem
;
3193 rmem
->nr_pages
= bp
->cp_nr_pages
;
3194 rmem
->page_size
= HW_CMPD_RING_SIZE
;
3195 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
3196 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
3197 rmem
->flags
= BNXT_RMEM_RING_PTE_FLAG
;
3198 rc
= bnxt_alloc_ring(bp
, rmem
);
3200 bnxt_free_ring(bp
, rmem
);
3207 static int bnxt_alloc_cp_rings(struct bnxt
*bp
)
3209 bool sh
= !!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
);
3210 int i
, rc
, ulp_base_vec
, ulp_msix
;
3212 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
3213 ulp_base_vec
= bnxt_get_ulp_msix_base(bp
);
3214 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3215 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3216 struct bnxt_cp_ring_info
*cpr
;
3217 struct bnxt_ring_struct
*ring
;
3222 cpr
= &bnapi
->cp_ring
;
3224 ring
= &cpr
->cp_ring_struct
;
3226 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
3230 if (ulp_msix
&& i
>= ulp_base_vec
)
3231 ring
->map_idx
= i
+ ulp_msix
;
3235 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
3238 if (i
< bp
->rx_nr_rings
) {
3239 struct bnxt_cp_ring_info
*cpr2
=
3240 bnxt_alloc_cp_sub_ring(bp
);
3242 cpr
->cp_ring_arr
[BNXT_RX_HDL
] = cpr2
;
3245 cpr2
->bnapi
= bnapi
;
3247 if ((sh
&& i
< bp
->tx_nr_rings
) ||
3248 (!sh
&& i
>= bp
->rx_nr_rings
)) {
3249 struct bnxt_cp_ring_info
*cpr2
=
3250 bnxt_alloc_cp_sub_ring(bp
);
3252 cpr
->cp_ring_arr
[BNXT_TX_HDL
] = cpr2
;
3255 cpr2
->bnapi
= bnapi
;
3261 static void bnxt_init_ring_struct(struct bnxt
*bp
)
3265 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3266 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3267 struct bnxt_ring_mem_info
*rmem
;
3268 struct bnxt_cp_ring_info
*cpr
;
3269 struct bnxt_rx_ring_info
*rxr
;
3270 struct bnxt_tx_ring_info
*txr
;
3271 struct bnxt_ring_struct
*ring
;
3276 cpr
= &bnapi
->cp_ring
;
3277 ring
= &cpr
->cp_ring_struct
;
3278 rmem
= &ring
->ring_mem
;
3279 rmem
->nr_pages
= bp
->cp_nr_pages
;
3280 rmem
->page_size
= HW_CMPD_RING_SIZE
;
3281 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
3282 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
3283 rmem
->vmem_size
= 0;
3285 rxr
= bnapi
->rx_ring
;
3289 ring
= &rxr
->rx_ring_struct
;
3290 rmem
= &ring
->ring_mem
;
3291 rmem
->nr_pages
= bp
->rx_nr_pages
;
3292 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3293 rmem
->pg_arr
= (void **)rxr
->rx_desc_ring
;
3294 rmem
->dma_arr
= rxr
->rx_desc_mapping
;
3295 rmem
->vmem_size
= SW_RXBD_RING_SIZE
* bp
->rx_nr_pages
;
3296 rmem
->vmem
= (void **)&rxr
->rx_buf_ring
;
3298 ring
= &rxr
->rx_agg_ring_struct
;
3299 rmem
= &ring
->ring_mem
;
3300 rmem
->nr_pages
= bp
->rx_agg_nr_pages
;
3301 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3302 rmem
->pg_arr
= (void **)rxr
->rx_agg_desc_ring
;
3303 rmem
->dma_arr
= rxr
->rx_agg_desc_mapping
;
3304 rmem
->vmem_size
= SW_RXBD_AGG_RING_SIZE
* bp
->rx_agg_nr_pages
;
3305 rmem
->vmem
= (void **)&rxr
->rx_agg_ring
;
3308 txr
= bnapi
->tx_ring
;
3312 ring
= &txr
->tx_ring_struct
;
3313 rmem
= &ring
->ring_mem
;
3314 rmem
->nr_pages
= bp
->tx_nr_pages
;
3315 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3316 rmem
->pg_arr
= (void **)txr
->tx_desc_ring
;
3317 rmem
->dma_arr
= txr
->tx_desc_mapping
;
3318 rmem
->vmem_size
= SW_TXBD_RING_SIZE
* bp
->tx_nr_pages
;
3319 rmem
->vmem
= (void **)&txr
->tx_buf_ring
;
3323 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct
*ring
, u32 type
)
3327 struct rx_bd
**rx_buf_ring
;
3329 rx_buf_ring
= (struct rx_bd
**)ring
->ring_mem
.pg_arr
;
3330 for (i
= 0, prod
= 0; i
< ring
->ring_mem
.nr_pages
; i
++) {
3334 rxbd
= rx_buf_ring
[i
];
3338 for (j
= 0; j
< RX_DESC_CNT
; j
++, rxbd
++, prod
++) {
3339 rxbd
->rx_bd_len_flags_type
= cpu_to_le32(type
);
3340 rxbd
->rx_bd_opaque
= prod
;
3345 static int bnxt_alloc_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
3347 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[ring_nr
];
3348 struct net_device
*dev
= bp
->dev
;
3352 prod
= rxr
->rx_prod
;
3353 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
3354 if (bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_KERNEL
)) {
3355 netdev_warn(dev
, "init'ed rx ring %d with %d/%d skbs only\n",
3356 ring_nr
, i
, bp
->rx_ring_size
);
3359 prod
= NEXT_RX(prod
);
3361 rxr
->rx_prod
= prod
;
3363 if (!(bp
->flags
& BNXT_FLAG_AGG_RINGS
))
3366 prod
= rxr
->rx_agg_prod
;
3367 for (i
= 0; i
< bp
->rx_agg_ring_size
; i
++) {
3368 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_KERNEL
)) {
3369 netdev_warn(dev
, "init'ed rx ring %d with %d/%d pages only\n",
3370 ring_nr
, i
, bp
->rx_ring_size
);
3373 prod
= NEXT_RX_AGG(prod
);
3375 rxr
->rx_agg_prod
= prod
;
3381 for (i
= 0; i
< bp
->max_tpa
; i
++) {
3382 data
= __bnxt_alloc_rx_data(bp
, &mapping
, GFP_KERNEL
);
3386 rxr
->rx_tpa
[i
].data
= data
;
3387 rxr
->rx_tpa
[i
].data_ptr
= data
+ bp
->rx_offset
;
3388 rxr
->rx_tpa
[i
].mapping
= mapping
;
3394 static int bnxt_init_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
3396 struct bnxt_rx_ring_info
*rxr
;
3397 struct bnxt_ring_struct
*ring
;
3400 type
= (bp
->rx_buf_use_size
<< RX_BD_LEN_SHIFT
) |
3401 RX_BD_TYPE_RX_PACKET_BD
| RX_BD_FLAGS_EOP
;
3403 if (NET_IP_ALIGN
== 2)
3404 type
|= RX_BD_FLAGS_SOP
;
3406 rxr
= &bp
->rx_ring
[ring_nr
];
3407 ring
= &rxr
->rx_ring_struct
;
3408 bnxt_init_rxbd_pages(ring
, type
);
3410 if (BNXT_RX_PAGE_MODE(bp
) && bp
->xdp_prog
) {
3411 bpf_prog_add(bp
->xdp_prog
, 1);
3412 rxr
->xdp_prog
= bp
->xdp_prog
;
3414 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3416 ring
= &rxr
->rx_agg_ring_struct
;
3417 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3419 if ((bp
->flags
& BNXT_FLAG_AGG_RINGS
)) {
3420 type
= ((u32
)BNXT_RX_PAGE_SIZE
<< RX_BD_LEN_SHIFT
) |
3421 RX_BD_TYPE_RX_AGG_BD
| RX_BD_FLAGS_SOP
;
3423 bnxt_init_rxbd_pages(ring
, type
);
3426 return bnxt_alloc_one_rx_ring(bp
, ring_nr
);
3429 static void bnxt_init_cp_rings(struct bnxt
*bp
)
3433 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3434 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
3435 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3437 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3438 cpr
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
3439 cpr
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
3440 for (j
= 0; j
< 2; j
++) {
3441 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
3446 ring
= &cpr2
->cp_ring_struct
;
3447 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3448 cpr2
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
3449 cpr2
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
3454 static int bnxt_init_rx_rings(struct bnxt
*bp
)
3458 if (BNXT_RX_PAGE_MODE(bp
)) {
3459 bp
->rx_offset
= NET_IP_ALIGN
+ XDP_PACKET_HEADROOM
;
3460 bp
->rx_dma_offset
= XDP_PACKET_HEADROOM
;
3462 bp
->rx_offset
= BNXT_RX_OFFSET
;
3463 bp
->rx_dma_offset
= BNXT_RX_DMA_OFFSET
;
3466 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3467 rc
= bnxt_init_one_rx_ring(bp
, i
);
3475 static int bnxt_init_tx_rings(struct bnxt
*bp
)
3479 bp
->tx_wake_thresh
= max_t(int, bp
->tx_ring_size
/ 2,
3482 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
3483 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3484 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
3486 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3492 static void bnxt_free_ring_grps(struct bnxt
*bp
)
3494 kfree(bp
->grp_info
);
3495 bp
->grp_info
= NULL
;
3498 static int bnxt_init_ring_grps(struct bnxt
*bp
, bool irq_re_init
)
3503 bp
->grp_info
= kcalloc(bp
->cp_nr_rings
,
3504 sizeof(struct bnxt_ring_grp_info
),
3509 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3511 bp
->grp_info
[i
].fw_stats_ctx
= INVALID_HW_RING_ID
;
3512 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
3513 bp
->grp_info
[i
].rx_fw_ring_id
= INVALID_HW_RING_ID
;
3514 bp
->grp_info
[i
].agg_fw_ring_id
= INVALID_HW_RING_ID
;
3515 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
3520 static void bnxt_free_vnics(struct bnxt
*bp
)
3522 kfree(bp
->vnic_info
);
3523 bp
->vnic_info
= NULL
;
3527 static int bnxt_alloc_vnics(struct bnxt
*bp
)
3531 #ifdef CONFIG_RFS_ACCEL
3532 if ((bp
->flags
& (BNXT_FLAG_RFS
| BNXT_FLAG_CHIP_P5
)) == BNXT_FLAG_RFS
)
3533 num_vnics
+= bp
->rx_nr_rings
;
3536 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
3539 bp
->vnic_info
= kcalloc(num_vnics
, sizeof(struct bnxt_vnic_info
),
3544 bp
->nr_vnics
= num_vnics
;
3548 static void bnxt_init_vnics(struct bnxt
*bp
)
3552 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3553 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
3556 vnic
->fw_vnic_id
= INVALID_HW_RING_ID
;
3557 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++)
3558 vnic
->fw_rss_cos_lb_ctx
[j
] = INVALID_HW_RING_ID
;
3560 vnic
->fw_l2_ctx_id
= INVALID_HW_RING_ID
;
3562 if (bp
->vnic_info
[i
].rss_hash_key
) {
3564 prandom_bytes(vnic
->rss_hash_key
,
3567 memcpy(vnic
->rss_hash_key
,
3568 bp
->vnic_info
[0].rss_hash_key
,
3574 static int bnxt_calc_nr_ring_pages(u32 ring_size
, int desc_per_pg
)
3578 pages
= ring_size
/ desc_per_pg
;
3585 while (pages
& (pages
- 1))
3591 void bnxt_set_tpa_flags(struct bnxt
*bp
)
3593 bp
->flags
&= ~BNXT_FLAG_TPA
;
3594 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
3596 if (bp
->dev
->features
& NETIF_F_LRO
)
3597 bp
->flags
|= BNXT_FLAG_LRO
;
3598 else if (bp
->dev
->features
& NETIF_F_GRO_HW
)
3599 bp
->flags
|= BNXT_FLAG_GRO
;
3602 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
3605 void bnxt_set_ring_params(struct bnxt
*bp
)
3607 u32 ring_size
, rx_size
, rx_space
, max_rx_cmpl
;
3608 u32 agg_factor
= 0, agg_ring_size
= 0;
3610 /* 8 for CRC and VLAN */
3611 rx_size
= SKB_DATA_ALIGN(bp
->dev
->mtu
+ ETH_HLEN
+ NET_IP_ALIGN
+ 8);
3613 rx_space
= rx_size
+ NET_SKB_PAD
+
3614 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3616 bp
->rx_copy_thresh
= BNXT_RX_COPY_THRESH
;
3617 ring_size
= bp
->rx_ring_size
;
3618 bp
->rx_agg_ring_size
= 0;
3619 bp
->rx_agg_nr_pages
= 0;
3621 if (bp
->flags
& BNXT_FLAG_TPA
)
3622 agg_factor
= min_t(u32
, 4, 65536 / BNXT_RX_PAGE_SIZE
);
3624 bp
->flags
&= ~BNXT_FLAG_JUMBO
;
3625 if (rx_space
> PAGE_SIZE
&& !(bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)) {
3628 bp
->flags
|= BNXT_FLAG_JUMBO
;
3629 jumbo_factor
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
3630 if (jumbo_factor
> agg_factor
)
3631 agg_factor
= jumbo_factor
;
3633 agg_ring_size
= ring_size
* agg_factor
;
3635 if (agg_ring_size
) {
3636 bp
->rx_agg_nr_pages
= bnxt_calc_nr_ring_pages(agg_ring_size
,
3638 if (bp
->rx_agg_nr_pages
> MAX_RX_AGG_PAGES
) {
3639 u32 tmp
= agg_ring_size
;
3641 bp
->rx_agg_nr_pages
= MAX_RX_AGG_PAGES
;
3642 agg_ring_size
= MAX_RX_AGG_PAGES
* RX_DESC_CNT
- 1;
3643 netdev_warn(bp
->dev
, "rx agg ring size %d reduced to %d.\n",
3644 tmp
, agg_ring_size
);
3646 bp
->rx_agg_ring_size
= agg_ring_size
;
3647 bp
->rx_agg_ring_mask
= (bp
->rx_agg_nr_pages
* RX_DESC_CNT
) - 1;
3648 rx_size
= SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH
+ NET_IP_ALIGN
);
3649 rx_space
= rx_size
+ NET_SKB_PAD
+
3650 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3653 bp
->rx_buf_use_size
= rx_size
;
3654 bp
->rx_buf_size
= rx_space
;
3656 bp
->rx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, RX_DESC_CNT
);
3657 bp
->rx_ring_mask
= (bp
->rx_nr_pages
* RX_DESC_CNT
) - 1;
3659 ring_size
= bp
->tx_ring_size
;
3660 bp
->tx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, TX_DESC_CNT
);
3661 bp
->tx_ring_mask
= (bp
->tx_nr_pages
* TX_DESC_CNT
) - 1;
3663 max_rx_cmpl
= bp
->rx_ring_size
;
3664 /* MAX TPA needs to be added because TPA_START completions are
3665 * immediately recycled, so the TPA completions are not bound by
3668 if (bp
->flags
& BNXT_FLAG_TPA
)
3669 max_rx_cmpl
+= bp
->max_tpa
;
3670 /* RX and TPA completions are 32-byte, all others are 16-byte */
3671 ring_size
= max_rx_cmpl
* 2 + agg_ring_size
+ bp
->tx_ring_size
;
3672 bp
->cp_ring_size
= ring_size
;
3674 bp
->cp_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, CP_DESC_CNT
);
3675 if (bp
->cp_nr_pages
> MAX_CP_PAGES
) {
3676 bp
->cp_nr_pages
= MAX_CP_PAGES
;
3677 bp
->cp_ring_size
= MAX_CP_PAGES
* CP_DESC_CNT
- 1;
3678 netdev_warn(bp
->dev
, "completion ring size %d reduced to %d.\n",
3679 ring_size
, bp
->cp_ring_size
);
3681 bp
->cp_bit
= bp
->cp_nr_pages
* CP_DESC_CNT
;
3682 bp
->cp_ring_mask
= bp
->cp_bit
- 1;
3685 /* Changing allocation mode of RX rings.
3686 * TODO: Update when extending xdp_rxq_info to support allocation modes.
3688 int bnxt_set_rx_skb_mode(struct bnxt
*bp
, bool page_mode
)
3691 if (bp
->dev
->mtu
> BNXT_MAX_PAGE_MODE_MTU
)
3694 min_t(u16
, bp
->max_mtu
, BNXT_MAX_PAGE_MODE_MTU
);
3695 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
3696 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
| BNXT_FLAG_RX_PAGE_MODE
;
3697 bp
->rx_dir
= DMA_BIDIRECTIONAL
;
3698 bp
->rx_skb_func
= bnxt_rx_page_skb
;
3699 /* Disable LRO or GRO_HW */
3700 netdev_update_features(bp
->dev
);
3702 bp
->dev
->max_mtu
= bp
->max_mtu
;
3703 bp
->flags
&= ~BNXT_FLAG_RX_PAGE_MODE
;
3704 bp
->rx_dir
= DMA_FROM_DEVICE
;
3705 bp
->rx_skb_func
= bnxt_rx_skb
;
3710 static void bnxt_free_vnic_attributes(struct bnxt
*bp
)
3713 struct bnxt_vnic_info
*vnic
;
3714 struct pci_dev
*pdev
= bp
->pdev
;
3719 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3720 vnic
= &bp
->vnic_info
[i
];
3722 kfree(vnic
->fw_grp_ids
);
3723 vnic
->fw_grp_ids
= NULL
;
3725 kfree(vnic
->uc_list
);
3726 vnic
->uc_list
= NULL
;
3728 if (vnic
->mc_list
) {
3729 dma_free_coherent(&pdev
->dev
, vnic
->mc_list_size
,
3730 vnic
->mc_list
, vnic
->mc_list_mapping
);
3731 vnic
->mc_list
= NULL
;
3734 if (vnic
->rss_table
) {
3735 dma_free_coherent(&pdev
->dev
, vnic
->rss_table_size
,
3737 vnic
->rss_table_dma_addr
);
3738 vnic
->rss_table
= NULL
;
3741 vnic
->rss_hash_key
= NULL
;
3746 static int bnxt_alloc_vnic_attributes(struct bnxt
*bp
)
3748 int i
, rc
= 0, size
;
3749 struct bnxt_vnic_info
*vnic
;
3750 struct pci_dev
*pdev
= bp
->pdev
;
3753 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3754 vnic
= &bp
->vnic_info
[i
];
3756 if (vnic
->flags
& BNXT_VNIC_UCAST_FLAG
) {
3757 int mem_size
= (BNXT_MAX_UC_ADDRS
- 1) * ETH_ALEN
;
3760 vnic
->uc_list
= kmalloc(mem_size
, GFP_KERNEL
);
3761 if (!vnic
->uc_list
) {
3768 if (vnic
->flags
& BNXT_VNIC_MCAST_FLAG
) {
3769 vnic
->mc_list_size
= BNXT_MAX_MC_ADDRS
* ETH_ALEN
;
3771 dma_alloc_coherent(&pdev
->dev
,
3773 &vnic
->mc_list_mapping
,
3775 if (!vnic
->mc_list
) {
3781 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
3782 goto vnic_skip_grps
;
3784 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3785 max_rings
= bp
->rx_nr_rings
;
3789 vnic
->fw_grp_ids
= kcalloc(max_rings
, sizeof(u16
), GFP_KERNEL
);
3790 if (!vnic
->fw_grp_ids
) {
3795 if ((bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
3796 !(vnic
->flags
& BNXT_VNIC_RSS_FLAG
))
3799 /* Allocate rss table and hash key */
3800 size
= L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE
* sizeof(u16
));
3801 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
3802 size
= L1_CACHE_ALIGN(BNXT_MAX_RSS_TABLE_SIZE_P5
);
3804 vnic
->rss_table_size
= size
+ HW_HASH_KEY_SIZE
;
3805 vnic
->rss_table
= dma_alloc_coherent(&pdev
->dev
,
3806 vnic
->rss_table_size
,
3807 &vnic
->rss_table_dma_addr
,
3809 if (!vnic
->rss_table
) {
3814 vnic
->rss_hash_key
= ((void *)vnic
->rss_table
) + size
;
3815 vnic
->rss_hash_key_dma_addr
= vnic
->rss_table_dma_addr
+ size
;
3823 static void bnxt_free_hwrm_resources(struct bnxt
*bp
)
3825 struct pci_dev
*pdev
= bp
->pdev
;
3827 if (bp
->hwrm_cmd_resp_addr
) {
3828 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
, bp
->hwrm_cmd_resp_addr
,
3829 bp
->hwrm_cmd_resp_dma_addr
);
3830 bp
->hwrm_cmd_resp_addr
= NULL
;
3833 if (bp
->hwrm_cmd_kong_resp_addr
) {
3834 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
3835 bp
->hwrm_cmd_kong_resp_addr
,
3836 bp
->hwrm_cmd_kong_resp_dma_addr
);
3837 bp
->hwrm_cmd_kong_resp_addr
= NULL
;
3841 static int bnxt_alloc_kong_hwrm_resources(struct bnxt
*bp
)
3843 struct pci_dev
*pdev
= bp
->pdev
;
3845 if (bp
->hwrm_cmd_kong_resp_addr
)
3848 bp
->hwrm_cmd_kong_resp_addr
=
3849 dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3850 &bp
->hwrm_cmd_kong_resp_dma_addr
,
3852 if (!bp
->hwrm_cmd_kong_resp_addr
)
3858 static int bnxt_alloc_hwrm_resources(struct bnxt
*bp
)
3860 struct pci_dev
*pdev
= bp
->pdev
;
3862 bp
->hwrm_cmd_resp_addr
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3863 &bp
->hwrm_cmd_resp_dma_addr
,
3865 if (!bp
->hwrm_cmd_resp_addr
)
3871 static void bnxt_free_hwrm_short_cmd_req(struct bnxt
*bp
)
3873 if (bp
->hwrm_short_cmd_req_addr
) {
3874 struct pci_dev
*pdev
= bp
->pdev
;
3876 dma_free_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3877 bp
->hwrm_short_cmd_req_addr
,
3878 bp
->hwrm_short_cmd_req_dma_addr
);
3879 bp
->hwrm_short_cmd_req_addr
= NULL
;
3883 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt
*bp
)
3885 struct pci_dev
*pdev
= bp
->pdev
;
3887 if (bp
->hwrm_short_cmd_req_addr
)
3890 bp
->hwrm_short_cmd_req_addr
=
3891 dma_alloc_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3892 &bp
->hwrm_short_cmd_req_dma_addr
,
3894 if (!bp
->hwrm_short_cmd_req_addr
)
3900 static void bnxt_free_stats_mem(struct bnxt
*bp
, struct bnxt_stats_mem
*stats
)
3902 kfree(stats
->hw_masks
);
3903 stats
->hw_masks
= NULL
;
3904 kfree(stats
->sw_stats
);
3905 stats
->sw_stats
= NULL
;
3906 if (stats
->hw_stats
) {
3907 dma_free_coherent(&bp
->pdev
->dev
, stats
->len
, stats
->hw_stats
,
3908 stats
->hw_stats_map
);
3909 stats
->hw_stats
= NULL
;
3913 static int bnxt_alloc_stats_mem(struct bnxt
*bp
, struct bnxt_stats_mem
*stats
,
3916 stats
->hw_stats
= dma_alloc_coherent(&bp
->pdev
->dev
, stats
->len
,
3917 &stats
->hw_stats_map
, GFP_KERNEL
);
3918 if (!stats
->hw_stats
)
3921 stats
->sw_stats
= kzalloc(stats
->len
, GFP_KERNEL
);
3922 if (!stats
->sw_stats
)
3926 stats
->hw_masks
= kzalloc(stats
->len
, GFP_KERNEL
);
3927 if (!stats
->hw_masks
)
3933 bnxt_free_stats_mem(bp
, stats
);
3937 static void bnxt_fill_masks(u64
*mask_arr
, u64 mask
, int count
)
3941 for (i
= 0; i
< count
; i
++)
3945 static void bnxt_copy_hw_masks(u64
*mask_arr
, __le64
*hw_mask_arr
, int count
)
3949 for (i
= 0; i
< count
; i
++)
3950 mask_arr
[i
] = le64_to_cpu(hw_mask_arr
[i
]);
3953 static int bnxt_hwrm_func_qstat_ext(struct bnxt
*bp
,
3954 struct bnxt_stats_mem
*stats
)
3956 struct hwrm_func_qstats_ext_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3957 struct hwrm_func_qstats_ext_input req
= {0};
3961 if (!(bp
->fw_cap
& BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED
) ||
3962 !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
3965 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QSTATS_EXT
, -1, -1);
3966 req
.fid
= cpu_to_le16(0xffff);
3967 req
.flags
= FUNC_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK
;
3968 mutex_lock(&bp
->hwrm_cmd_lock
);
3969 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3973 hw_masks
= &resp
->rx_ucast_pkts
;
3974 bnxt_copy_hw_masks(stats
->hw_masks
, hw_masks
, stats
->len
/ 8);
3977 mutex_unlock(&bp
->hwrm_cmd_lock
);
3981 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
, u8 flags
);
3982 static int bnxt_hwrm_port_qstats_ext(struct bnxt
*bp
, u8 flags
);
3984 static void bnxt_init_stats(struct bnxt
*bp
)
3986 struct bnxt_napi
*bnapi
= bp
->bnapi
[0];
3987 struct bnxt_cp_ring_info
*cpr
;
3988 struct bnxt_stats_mem
*stats
;
3989 __le64
*rx_stats
, *tx_stats
;
3990 int rc
, rx_count
, tx_count
;
3991 u64
*rx_masks
, *tx_masks
;
3995 cpr
= &bnapi
->cp_ring
;
3996 stats
= &cpr
->stats
;
3997 rc
= bnxt_hwrm_func_qstat_ext(bp
, stats
);
3999 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4000 mask
= (1ULL << 48) - 1;
4003 bnxt_fill_masks(stats
->hw_masks
, mask
, stats
->len
/ 8);
4005 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
4006 stats
= &bp
->port_stats
;
4007 rx_stats
= stats
->hw_stats
;
4008 rx_masks
= stats
->hw_masks
;
4009 rx_count
= sizeof(struct rx_port_stats
) / 8;
4010 tx_stats
= rx_stats
+ BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
4011 tx_masks
= rx_masks
+ BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
4012 tx_count
= sizeof(struct tx_port_stats
) / 8;
4014 flags
= PORT_QSTATS_REQ_FLAGS_COUNTER_MASK
;
4015 rc
= bnxt_hwrm_port_qstats(bp
, flags
);
4017 mask
= (1ULL << 40) - 1;
4019 bnxt_fill_masks(rx_masks
, mask
, rx_count
);
4020 bnxt_fill_masks(tx_masks
, mask
, tx_count
);
4022 bnxt_copy_hw_masks(rx_masks
, rx_stats
, rx_count
);
4023 bnxt_copy_hw_masks(tx_masks
, tx_stats
, tx_count
);
4024 bnxt_hwrm_port_qstats(bp
, 0);
4027 if (bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
) {
4028 stats
= &bp
->rx_port_stats_ext
;
4029 rx_stats
= stats
->hw_stats
;
4030 rx_masks
= stats
->hw_masks
;
4031 rx_count
= sizeof(struct rx_port_stats_ext
) / 8;
4032 stats
= &bp
->tx_port_stats_ext
;
4033 tx_stats
= stats
->hw_stats
;
4034 tx_masks
= stats
->hw_masks
;
4035 tx_count
= sizeof(struct tx_port_stats_ext
) / 8;
4037 flags
= PORT_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK
;
4038 rc
= bnxt_hwrm_port_qstats_ext(bp
, flags
);
4040 mask
= (1ULL << 40) - 1;
4042 bnxt_fill_masks(rx_masks
, mask
, rx_count
);
4044 bnxt_fill_masks(tx_masks
, mask
, tx_count
);
4046 bnxt_copy_hw_masks(rx_masks
, rx_stats
, rx_count
);
4048 bnxt_copy_hw_masks(tx_masks
, tx_stats
,
4050 bnxt_hwrm_port_qstats_ext(bp
, 0);
4055 static void bnxt_free_port_stats(struct bnxt
*bp
)
4057 bp
->flags
&= ~BNXT_FLAG_PORT_STATS
;
4058 bp
->flags
&= ~BNXT_FLAG_PORT_STATS_EXT
;
4060 bnxt_free_stats_mem(bp
, &bp
->port_stats
);
4061 bnxt_free_stats_mem(bp
, &bp
->rx_port_stats_ext
);
4062 bnxt_free_stats_mem(bp
, &bp
->tx_port_stats_ext
);
4065 static void bnxt_free_ring_stats(struct bnxt
*bp
)
4072 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4073 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4074 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4076 bnxt_free_stats_mem(bp
, &cpr
->stats
);
4080 static int bnxt_alloc_stats(struct bnxt
*bp
)
4085 size
= bp
->hw_ring_stats_size
;
4087 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4088 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4089 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4091 cpr
->stats
.len
= size
;
4092 rc
= bnxt_alloc_stats_mem(bp
, &cpr
->stats
, !i
);
4096 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
4099 if (BNXT_VF(bp
) || bp
->chip_num
== CHIP_NUM_58700
)
4102 if (bp
->port_stats
.hw_stats
)
4103 goto alloc_ext_stats
;
4105 bp
->port_stats
.len
= BNXT_PORT_STATS_SIZE
;
4106 rc
= bnxt_alloc_stats_mem(bp
, &bp
->port_stats
, true);
4110 bp
->flags
|= BNXT_FLAG_PORT_STATS
;
4113 /* Display extended statistics only if FW supports it */
4114 if (bp
->hwrm_spec_code
< 0x10804 || bp
->hwrm_spec_code
== 0x10900)
4115 if (!(bp
->fw_cap
& BNXT_FW_CAP_EXT_STATS_SUPPORTED
))
4118 if (bp
->rx_port_stats_ext
.hw_stats
)
4119 goto alloc_tx_ext_stats
;
4121 bp
->rx_port_stats_ext
.len
= sizeof(struct rx_port_stats_ext
);
4122 rc
= bnxt_alloc_stats_mem(bp
, &bp
->rx_port_stats_ext
, true);
4123 /* Extended stats are optional */
4128 if (bp
->tx_port_stats_ext
.hw_stats
)
4131 if (bp
->hwrm_spec_code
>= 0x10902 ||
4132 (bp
->fw_cap
& BNXT_FW_CAP_EXT_STATS_SUPPORTED
)) {
4133 bp
->tx_port_stats_ext
.len
= sizeof(struct tx_port_stats_ext
);
4134 rc
= bnxt_alloc_stats_mem(bp
, &bp
->tx_port_stats_ext
, true);
4135 /* Extended stats are optional */
4139 bp
->flags
|= BNXT_FLAG_PORT_STATS_EXT
;
4143 static void bnxt_clear_ring_indices(struct bnxt
*bp
)
4150 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4151 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4152 struct bnxt_cp_ring_info
*cpr
;
4153 struct bnxt_rx_ring_info
*rxr
;
4154 struct bnxt_tx_ring_info
*txr
;
4159 cpr
= &bnapi
->cp_ring
;
4160 cpr
->cp_raw_cons
= 0;
4162 txr
= bnapi
->tx_ring
;
4168 rxr
= bnapi
->rx_ring
;
4171 rxr
->rx_agg_prod
= 0;
4172 rxr
->rx_sw_agg_prod
= 0;
4173 rxr
->rx_next_cons
= 0;
4178 static void bnxt_free_ntp_fltrs(struct bnxt
*bp
, bool irq_reinit
)
4180 #ifdef CONFIG_RFS_ACCEL
4183 /* Under rtnl_lock and all our NAPIs have been disabled. It's
4184 * safe to delete the hash table.
4186 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
4187 struct hlist_head
*head
;
4188 struct hlist_node
*tmp
;
4189 struct bnxt_ntuple_filter
*fltr
;
4191 head
= &bp
->ntp_fltr_hash_tbl
[i
];
4192 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
4193 hlist_del(&fltr
->hash
);
4198 kfree(bp
->ntp_fltr_bmap
);
4199 bp
->ntp_fltr_bmap
= NULL
;
4201 bp
->ntp_fltr_count
= 0;
4205 static int bnxt_alloc_ntp_fltrs(struct bnxt
*bp
)
4207 #ifdef CONFIG_RFS_ACCEL
4210 if (!(bp
->flags
& BNXT_FLAG_RFS
))
4213 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++)
4214 INIT_HLIST_HEAD(&bp
->ntp_fltr_hash_tbl
[i
]);
4216 bp
->ntp_fltr_count
= 0;
4217 bp
->ntp_fltr_bmap
= kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR
),
4221 if (!bp
->ntp_fltr_bmap
)
4230 static void bnxt_free_mem(struct bnxt
*bp
, bool irq_re_init
)
4232 bnxt_free_vnic_attributes(bp
);
4233 bnxt_free_tx_rings(bp
);
4234 bnxt_free_rx_rings(bp
);
4235 bnxt_free_cp_rings(bp
);
4236 bnxt_free_ntp_fltrs(bp
, irq_re_init
);
4238 bnxt_free_ring_stats(bp
);
4239 if (!(bp
->phy_flags
& BNXT_PHY_FL_PORT_STATS_NO_RESET
) ||
4240 test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
4241 bnxt_free_port_stats(bp
);
4242 bnxt_free_ring_grps(bp
);
4243 bnxt_free_vnics(bp
);
4244 kfree(bp
->tx_ring_map
);
4245 bp
->tx_ring_map
= NULL
;
4253 bnxt_clear_ring_indices(bp
);
4257 static int bnxt_alloc_mem(struct bnxt
*bp
, bool irq_re_init
)
4259 int i
, j
, rc
, size
, arr_size
;
4263 /* Allocate bnapi mem pointer array and mem block for
4266 arr_size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
*) *
4268 size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
));
4269 bnapi
= kzalloc(arr_size
+ size
* bp
->cp_nr_rings
, GFP_KERNEL
);
4275 for (i
= 0; i
< bp
->cp_nr_rings
; i
++, bnapi
+= size
) {
4276 bp
->bnapi
[i
] = bnapi
;
4277 bp
->bnapi
[i
]->index
= i
;
4278 bp
->bnapi
[i
]->bp
= bp
;
4279 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4280 struct bnxt_cp_ring_info
*cpr
=
4281 &bp
->bnapi
[i
]->cp_ring
;
4283 cpr
->cp_ring_struct
.ring_mem
.flags
=
4284 BNXT_RMEM_RING_PTE_FLAG
;
4288 bp
->rx_ring
= kcalloc(bp
->rx_nr_rings
,
4289 sizeof(struct bnxt_rx_ring_info
),
4294 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4295 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
4297 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4298 rxr
->rx_ring_struct
.ring_mem
.flags
=
4299 BNXT_RMEM_RING_PTE_FLAG
;
4300 rxr
->rx_agg_ring_struct
.ring_mem
.flags
=
4301 BNXT_RMEM_RING_PTE_FLAG
;
4303 rxr
->bnapi
= bp
->bnapi
[i
];
4304 bp
->bnapi
[i
]->rx_ring
= &bp
->rx_ring
[i
];
4307 bp
->tx_ring
= kcalloc(bp
->tx_nr_rings
,
4308 sizeof(struct bnxt_tx_ring_info
),
4313 bp
->tx_ring_map
= kcalloc(bp
->tx_nr_rings
, sizeof(u16
),
4316 if (!bp
->tx_ring_map
)
4319 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
4322 j
= bp
->rx_nr_rings
;
4324 for (i
= 0; i
< bp
->tx_nr_rings
; i
++, j
++) {
4325 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
4327 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4328 txr
->tx_ring_struct
.ring_mem
.flags
=
4329 BNXT_RMEM_RING_PTE_FLAG
;
4330 txr
->bnapi
= bp
->bnapi
[j
];
4331 bp
->bnapi
[j
]->tx_ring
= txr
;
4332 bp
->tx_ring_map
[i
] = bp
->tx_nr_rings_xdp
+ i
;
4333 if (i
>= bp
->tx_nr_rings_xdp
) {
4334 txr
->txq_index
= i
- bp
->tx_nr_rings_xdp
;
4335 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int
;
4337 bp
->bnapi
[j
]->flags
|= BNXT_NAPI_FLAG_XDP
;
4338 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int_xdp
;
4342 rc
= bnxt_alloc_stats(bp
);
4345 bnxt_init_stats(bp
);
4347 rc
= bnxt_alloc_ntp_fltrs(bp
);
4351 rc
= bnxt_alloc_vnics(bp
);
4356 bnxt_init_ring_struct(bp
);
4358 rc
= bnxt_alloc_rx_rings(bp
);
4362 rc
= bnxt_alloc_tx_rings(bp
);
4366 rc
= bnxt_alloc_cp_rings(bp
);
4370 bp
->vnic_info
[0].flags
|= BNXT_VNIC_RSS_FLAG
| BNXT_VNIC_MCAST_FLAG
|
4371 BNXT_VNIC_UCAST_FLAG
;
4372 rc
= bnxt_alloc_vnic_attributes(bp
);
4378 bnxt_free_mem(bp
, true);
4382 static void bnxt_disable_int(struct bnxt
*bp
)
4389 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4390 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4391 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4392 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
4394 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
)
4395 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
4399 static int bnxt_cp_num_to_irq_num(struct bnxt
*bp
, int n
)
4401 struct bnxt_napi
*bnapi
= bp
->bnapi
[n
];
4402 struct bnxt_cp_ring_info
*cpr
;
4404 cpr
= &bnapi
->cp_ring
;
4405 return cpr
->cp_ring_struct
.map_idx
;
4408 static void bnxt_disable_int_sync(struct bnxt
*bp
)
4415 atomic_inc(&bp
->intr_sem
);
4417 bnxt_disable_int(bp
);
4418 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4419 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
4421 synchronize_irq(bp
->irq_tbl
[map_idx
].vector
);
4425 static void bnxt_enable_int(struct bnxt
*bp
)
4429 atomic_set(&bp
->intr_sem
, 0);
4430 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4431 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4432 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4434 bnxt_db_nq_arm(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
4438 void bnxt_hwrm_cmd_hdr_init(struct bnxt
*bp
, void *request
, u16 req_type
,
4439 u16 cmpl_ring
, u16 target_id
)
4441 struct input
*req
= request
;
4443 req
->req_type
= cpu_to_le16(req_type
);
4444 req
->cmpl_ring
= cpu_to_le16(cmpl_ring
);
4445 req
->target_id
= cpu_to_le16(target_id
);
4446 if (bnxt_kong_hwrm_message(bp
, req
))
4447 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_kong_resp_dma_addr
);
4449 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_resp_dma_addr
);
4452 static int bnxt_hwrm_to_stderr(u32 hwrm_err
)
4455 case HWRM_ERR_CODE_SUCCESS
:
4457 case HWRM_ERR_CODE_RESOURCE_LOCKED
:
4459 case HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED
:
4461 case HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR
:
4463 case HWRM_ERR_CODE_INVALID_PARAMS
:
4464 case HWRM_ERR_CODE_INVALID_FLAGS
:
4465 case HWRM_ERR_CODE_INVALID_ENABLES
:
4466 case HWRM_ERR_CODE_UNSUPPORTED_TLV
:
4467 case HWRM_ERR_CODE_UNSUPPORTED_OPTION_ERR
:
4469 case HWRM_ERR_CODE_NO_BUFFER
:
4471 case HWRM_ERR_CODE_HOT_RESET_PROGRESS
:
4472 case HWRM_ERR_CODE_BUSY
:
4474 case HWRM_ERR_CODE_CMD_NOT_SUPPORTED
:
4481 static int bnxt_hwrm_do_send_msg(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4482 int timeout
, bool silent
)
4484 int i
, intr_process
, rc
, tmo_count
;
4485 struct input
*req
= msg
;
4488 u16 cp_ring_id
, len
= 0;
4489 struct hwrm_err_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4490 u16 max_req_len
= BNXT_HWRM_MAX_REQ_LEN
;
4491 struct hwrm_short_input short_input
= {0};
4492 u32 doorbell_offset
= BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER
;
4493 u32 bar_offset
= BNXT_GRCPF_REG_CHIMP_COMM
;
4494 u16 dst
= BNXT_HWRM_CHNL_CHIMP
;
4496 if (BNXT_NO_FW_ACCESS(bp
) &&
4497 le16_to_cpu(req
->req_type
) != HWRM_FUNC_RESET
)
4500 if (msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
4501 if (msg_len
> bp
->hwrm_max_ext_req_len
||
4502 !bp
->hwrm_short_cmd_req_addr
)
4506 if (bnxt_hwrm_kong_chnl(bp
, req
)) {
4507 dst
= BNXT_HWRM_CHNL_KONG
;
4508 bar_offset
= BNXT_GRCPF_REG_KONG_COMM
;
4509 doorbell_offset
= BNXT_GRCPF_REG_KONG_COMM_TRIGGER
;
4510 resp
= bp
->hwrm_cmd_kong_resp_addr
;
4513 memset(resp
, 0, PAGE_SIZE
);
4514 cp_ring_id
= le16_to_cpu(req
->cmpl_ring
);
4515 intr_process
= (cp_ring_id
== INVALID_HW_RING_ID
) ? 0 : 1;
4517 req
->seq_id
= cpu_to_le16(bnxt_get_hwrm_seq_id(bp
, dst
));
4518 /* currently supports only one outstanding message */
4520 bp
->hwrm_intr_seq_id
= le16_to_cpu(req
->seq_id
);
4522 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
4523 msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
4524 void *short_cmd_req
= bp
->hwrm_short_cmd_req_addr
;
4527 /* Set boundary for maximum extended request length for short
4528 * cmd format. If passed up from device use the max supported
4529 * internal req length.
4531 max_msg_len
= bp
->hwrm_max_ext_req_len
;
4533 memcpy(short_cmd_req
, req
, msg_len
);
4534 if (msg_len
< max_msg_len
)
4535 memset(short_cmd_req
+ msg_len
, 0,
4536 max_msg_len
- msg_len
);
4538 short_input
.req_type
= req
->req_type
;
4539 short_input
.signature
=
4540 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD
);
4541 short_input
.size
= cpu_to_le16(msg_len
);
4542 short_input
.req_addr
=
4543 cpu_to_le64(bp
->hwrm_short_cmd_req_dma_addr
);
4545 data
= (u32
*)&short_input
;
4546 msg_len
= sizeof(short_input
);
4548 /* Sync memory write before updating doorbell */
4551 max_req_len
= BNXT_HWRM_SHORT_REQ_LEN
;
4554 /* Write request msg to hwrm channel */
4555 __iowrite32_copy(bp
->bar0
+ bar_offset
, data
, msg_len
/ 4);
4557 for (i
= msg_len
; i
< max_req_len
; i
+= 4)
4558 writel(0, bp
->bar0
+ bar_offset
+ i
);
4560 /* Ring channel doorbell */
4561 writel(1, bp
->bar0
+ doorbell_offset
);
4563 if (!pci_is_enabled(bp
->pdev
))
4567 timeout
= DFLT_HWRM_CMD_TIMEOUT
;
4568 /* Limit timeout to an upper limit */
4569 timeout
= min(timeout
, HWRM_CMD_MAX_TIMEOUT
);
4570 /* convert timeout to usec */
4574 /* Short timeout for the first few iterations:
4575 * number of loops = number of loops for short timeout +
4576 * number of loops for standard timeout.
4578 tmo_count
= HWRM_SHORT_TIMEOUT_COUNTER
;
4579 timeout
= timeout
- HWRM_SHORT_MIN_TIMEOUT
* HWRM_SHORT_TIMEOUT_COUNTER
;
4580 tmo_count
+= DIV_ROUND_UP(timeout
, HWRM_MIN_TIMEOUT
);
4583 u16 seq_id
= bp
->hwrm_intr_seq_id
;
4585 /* Wait until hwrm response cmpl interrupt is processed */
4586 while (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
&&
4588 /* Abort the wait for completion if the FW health
4591 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
4593 /* on first few passes, just barely sleep */
4594 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
) {
4595 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
4596 HWRM_SHORT_MAX_TIMEOUT
);
4598 if (HWRM_WAIT_MUST_ABORT(bp
, req
))
4600 usleep_range(HWRM_MIN_TIMEOUT
,
4605 if (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
) {
4607 netdev_err(bp
->dev
, "Resp cmpl intr err msg: 0x%x\n",
4608 le16_to_cpu(req
->req_type
));
4611 len
= le16_to_cpu(resp
->resp_len
);
4612 valid
= ((u8
*)resp
) + len
- 1;
4616 /* Check if response len is updated */
4617 for (i
= 0; i
< tmo_count
; i
++) {
4618 /* Abort the wait for completion if the FW health
4621 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
4623 len
= le16_to_cpu(resp
->resp_len
);
4626 /* on first few passes, just barely sleep */
4627 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
) {
4628 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
4629 HWRM_SHORT_MAX_TIMEOUT
);
4631 if (HWRM_WAIT_MUST_ABORT(bp
, req
))
4633 usleep_range(HWRM_MIN_TIMEOUT
,
4638 if (i
>= tmo_count
) {
4641 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
4642 HWRM_TOTAL_TIMEOUT(i
),
4643 le16_to_cpu(req
->req_type
),
4644 le16_to_cpu(req
->seq_id
), len
);
4648 /* Last byte of resp contains valid bit */
4649 valid
= ((u8
*)resp
) + len
- 1;
4650 for (j
= 0; j
< HWRM_VALID_BIT_DELAY_USEC
; j
++) {
4651 /* make sure we read from updated DMA memory */
4658 if (j
>= HWRM_VALID_BIT_DELAY_USEC
) {
4660 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
4661 HWRM_TOTAL_TIMEOUT(i
),
4662 le16_to_cpu(req
->req_type
),
4663 le16_to_cpu(req
->seq_id
), len
,
4669 /* Zero valid bit for compatibility. Valid bit in an older spec
4670 * may become a new field in a newer spec. We must make sure that
4671 * a new field not implemented by old spec will read zero.
4674 rc
= le16_to_cpu(resp
->error_code
);
4676 netdev_err(bp
->dev
, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
4677 le16_to_cpu(resp
->req_type
),
4678 le16_to_cpu(resp
->seq_id
), rc
);
4679 return bnxt_hwrm_to_stderr(rc
);
4682 int _hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
4684 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, false);
4687 int _hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4690 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
4693 int hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
4697 mutex_lock(&bp
->hwrm_cmd_lock
);
4698 rc
= _hwrm_send_message(bp
, msg
, msg_len
, timeout
);
4699 mutex_unlock(&bp
->hwrm_cmd_lock
);
4703 int hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4708 mutex_lock(&bp
->hwrm_cmd_lock
);
4709 rc
= bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
4710 mutex_unlock(&bp
->hwrm_cmd_lock
);
4714 int bnxt_hwrm_func_drv_rgtr(struct bnxt
*bp
, unsigned long *bmap
, int bmap_size
,
4717 struct hwrm_func_drv_rgtr_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4718 struct hwrm_func_drv_rgtr_input req
= {0};
4719 DECLARE_BITMAP(async_events_bmap
, 256);
4720 u32
*events
= (u32
*)async_events_bmap
;
4724 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
4727 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE
|
4728 FUNC_DRV_RGTR_REQ_ENABLES_VER
|
4729 FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
4731 req
.os_type
= cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX
);
4732 flags
= FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE
;
4733 if (bp
->fw_cap
& BNXT_FW_CAP_HOT_RESET
)
4734 flags
|= FUNC_DRV_RGTR_REQ_FLAGS_HOT_RESET_SUPPORT
;
4735 if (bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
)
4736 flags
|= FUNC_DRV_RGTR_REQ_FLAGS_ERROR_RECOVERY_SUPPORT
|
4737 FUNC_DRV_RGTR_REQ_FLAGS_MASTER_SUPPORT
;
4738 req
.flags
= cpu_to_le32(flags
);
4739 req
.ver_maj_8b
= DRV_VER_MAJ
;
4740 req
.ver_min_8b
= DRV_VER_MIN
;
4741 req
.ver_upd_8b
= DRV_VER_UPD
;
4742 req
.ver_maj
= cpu_to_le16(DRV_VER_MAJ
);
4743 req
.ver_min
= cpu_to_le16(DRV_VER_MIN
);
4744 req
.ver_upd
= cpu_to_le16(DRV_VER_UPD
);
4750 memset(data
, 0, sizeof(data
));
4751 for (i
= 0; i
< ARRAY_SIZE(bnxt_vf_req_snif
); i
++) {
4752 u16 cmd
= bnxt_vf_req_snif
[i
];
4753 unsigned int bit
, idx
;
4757 data
[idx
] |= 1 << bit
;
4760 for (i
= 0; i
< 8; i
++)
4761 req
.vf_req_fwd
[i
] = cpu_to_le32(data
[i
]);
4764 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD
);
4767 if (bp
->fw_cap
& BNXT_FW_CAP_OVS_64BIT_HANDLE
)
4768 req
.flags
|= cpu_to_le32(
4769 FUNC_DRV_RGTR_REQ_FLAGS_FLOW_HANDLE_64BIT_MODE
);
4771 memset(async_events_bmap
, 0, sizeof(async_events_bmap
));
4772 for (i
= 0; i
< ARRAY_SIZE(bnxt_async_events_arr
); i
++) {
4773 u16 event_id
= bnxt_async_events_arr
[i
];
4775 if (event_id
== ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
&&
4776 !(bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
))
4778 __set_bit(bnxt_async_events_arr
[i
], async_events_bmap
);
4780 if (bmap
&& bmap_size
) {
4781 for (i
= 0; i
< bmap_size
; i
++) {
4782 if (test_bit(i
, bmap
))
4783 __set_bit(i
, async_events_bmap
);
4786 for (i
= 0; i
< 8; i
++)
4787 req
.async_event_fwd
[i
] |= cpu_to_le32(events
[i
]);
4791 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
4793 mutex_lock(&bp
->hwrm_cmd_lock
);
4794 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4796 set_bit(BNXT_STATE_DRV_REGISTERED
, &bp
->state
);
4798 cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED
))
4799 bp
->fw_cap
|= BNXT_FW_CAP_IF_CHANGE
;
4801 mutex_unlock(&bp
->hwrm_cmd_lock
);
4805 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt
*bp
)
4807 struct hwrm_func_drv_unrgtr_input req
= {0};
4809 if (!test_and_clear_bit(BNXT_STATE_DRV_REGISTERED
, &bp
->state
))
4812 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_UNRGTR
, -1, -1);
4813 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4816 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt
*bp
, u8 tunnel_type
)
4819 struct hwrm_tunnel_dst_port_free_input req
= {0};
4821 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_FREE
, -1, -1);
4822 req
.tunnel_type
= tunnel_type
;
4824 switch (tunnel_type
) {
4825 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
:
4826 req
.tunnel_dst_port_id
= cpu_to_le16(bp
->vxlan_fw_dst_port_id
);
4827 bp
->vxlan_fw_dst_port_id
= INVALID_HW_RING_ID
;
4829 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
:
4830 req
.tunnel_dst_port_id
= cpu_to_le16(bp
->nge_fw_dst_port_id
);
4831 bp
->nge_fw_dst_port_id
= INVALID_HW_RING_ID
;
4837 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4839 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
4844 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt
*bp
, __be16 port
,
4848 struct hwrm_tunnel_dst_port_alloc_input req
= {0};
4849 struct hwrm_tunnel_dst_port_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4851 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_ALLOC
, -1, -1);
4853 req
.tunnel_type
= tunnel_type
;
4854 req
.tunnel_dst_port_val
= port
;
4856 mutex_lock(&bp
->hwrm_cmd_lock
);
4857 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4859 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
4864 switch (tunnel_type
) {
4865 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN
:
4866 bp
->vxlan_fw_dst_port_id
=
4867 le16_to_cpu(resp
->tunnel_dst_port_id
);
4869 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE
:
4870 bp
->nge_fw_dst_port_id
= le16_to_cpu(resp
->tunnel_dst_port_id
);
4877 mutex_unlock(&bp
->hwrm_cmd_lock
);
4881 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt
*bp
, u16 vnic_id
)
4883 struct hwrm_cfa_l2_set_rx_mask_input req
= {0};
4884 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4886 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_SET_RX_MASK
, -1, -1);
4887 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4889 req
.num_mc_entries
= cpu_to_le32(vnic
->mc_list_count
);
4890 req
.mc_tbl_addr
= cpu_to_le64(vnic
->mc_list_mapping
);
4891 req
.mask
= cpu_to_le32(vnic
->rx_mask
);
4892 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4895 #ifdef CONFIG_RFS_ACCEL
4896 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt
*bp
,
4897 struct bnxt_ntuple_filter
*fltr
)
4899 struct hwrm_cfa_ntuple_filter_free_input req
= {0};
4901 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_FREE
, -1, -1);
4902 req
.ntuple_filter_id
= fltr
->filter_id
;
4903 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4906 #define BNXT_NTP_FLTR_FLAGS \
4907 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
4908 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
4909 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
4910 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
4911 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
4912 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
4913 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
4914 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
4915 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
4916 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
4917 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
4918 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
4919 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
4920 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
4922 #define BNXT_NTP_TUNNEL_FLTR_FLAG \
4923 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
4925 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt
*bp
,
4926 struct bnxt_ntuple_filter
*fltr
)
4928 struct hwrm_cfa_ntuple_filter_alloc_input req
= {0};
4929 struct hwrm_cfa_ntuple_filter_alloc_output
*resp
;
4930 struct flow_keys
*keys
= &fltr
->fkeys
;
4931 struct bnxt_vnic_info
*vnic
;
4935 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_ALLOC
, -1, -1);
4936 req
.l2_filter_id
= bp
->vnic_info
[0].fw_l2_filter_id
[fltr
->l2_fltr_idx
];
4938 if (bp
->fw_cap
& BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2
) {
4939 flags
= CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DEST_RFS_RING_IDX
;
4940 req
.dst_id
= cpu_to_le16(fltr
->rxq
);
4942 vnic
= &bp
->vnic_info
[fltr
->rxq
+ 1];
4943 req
.dst_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4945 req
.flags
= cpu_to_le32(flags
);
4946 req
.enables
= cpu_to_le32(BNXT_NTP_FLTR_FLAGS
);
4948 req
.ethertype
= htons(ETH_P_IP
);
4949 memcpy(req
.src_macaddr
, fltr
->src_mac_addr
, ETH_ALEN
);
4950 req
.ip_addr_type
= CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4
;
4951 req
.ip_protocol
= keys
->basic
.ip_proto
;
4953 if (keys
->basic
.n_proto
== htons(ETH_P_IPV6
)) {
4956 req
.ethertype
= htons(ETH_P_IPV6
);
4958 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6
;
4959 *(struct in6_addr
*)&req
.src_ipaddr
[0] =
4960 keys
->addrs
.v6addrs
.src
;
4961 *(struct in6_addr
*)&req
.dst_ipaddr
[0] =
4962 keys
->addrs
.v6addrs
.dst
;
4963 for (i
= 0; i
< 4; i
++) {
4964 req
.src_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4965 req
.dst_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4968 req
.src_ipaddr
[0] = keys
->addrs
.v4addrs
.src
;
4969 req
.src_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4970 req
.dst_ipaddr
[0] = keys
->addrs
.v4addrs
.dst
;
4971 req
.dst_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4973 if (keys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) {
4974 req
.enables
|= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG
);
4976 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL
;
4979 req
.src_port
= keys
->ports
.src
;
4980 req
.src_port_mask
= cpu_to_be16(0xffff);
4981 req
.dst_port
= keys
->ports
.dst
;
4982 req
.dst_port_mask
= cpu_to_be16(0xffff);
4984 mutex_lock(&bp
->hwrm_cmd_lock
);
4985 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4987 resp
= bnxt_get_hwrm_resp_addr(bp
, &req
);
4988 fltr
->filter_id
= resp
->ntuple_filter_id
;
4990 mutex_unlock(&bp
->hwrm_cmd_lock
);
4995 static int bnxt_hwrm_set_vnic_filter(struct bnxt
*bp
, u16 vnic_id
, u16 idx
,
4999 struct hwrm_cfa_l2_filter_alloc_input req
= {0};
5000 struct hwrm_cfa_l2_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5002 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_ALLOC
, -1, -1);
5003 req
.flags
= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX
);
5004 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
5006 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST
);
5007 req
.dst_id
= cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
5009 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR
|
5010 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID
|
5011 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK
);
5012 memcpy(req
.l2_addr
, mac_addr
, ETH_ALEN
);
5013 req
.l2_addr_mask
[0] = 0xff;
5014 req
.l2_addr_mask
[1] = 0xff;
5015 req
.l2_addr_mask
[2] = 0xff;
5016 req
.l2_addr_mask
[3] = 0xff;
5017 req
.l2_addr_mask
[4] = 0xff;
5018 req
.l2_addr_mask
[5] = 0xff;
5020 mutex_lock(&bp
->hwrm_cmd_lock
);
5021 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5023 bp
->vnic_info
[vnic_id
].fw_l2_filter_id
[idx
] =
5025 mutex_unlock(&bp
->hwrm_cmd_lock
);
5029 static int bnxt_hwrm_clear_vnic_filter(struct bnxt
*bp
)
5031 u16 i
, j
, num_of_vnics
= 1; /* only vnic 0 supported */
5034 /* Any associated ntuple filters will also be cleared by firmware. */
5035 mutex_lock(&bp
->hwrm_cmd_lock
);
5036 for (i
= 0; i
< num_of_vnics
; i
++) {
5037 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
5039 for (j
= 0; j
< vnic
->uc_filter_count
; j
++) {
5040 struct hwrm_cfa_l2_filter_free_input req
= {0};
5042 bnxt_hwrm_cmd_hdr_init(bp
, &req
,
5043 HWRM_CFA_L2_FILTER_FREE
, -1, -1);
5045 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[j
];
5047 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5050 vnic
->uc_filter_count
= 0;
5052 mutex_unlock(&bp
->hwrm_cmd_lock
);
5057 static int bnxt_hwrm_vnic_set_tpa(struct bnxt
*bp
, u16 vnic_id
, u32 tpa_flags
)
5059 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5060 u16 max_aggs
= VNIC_TPA_CFG_REQ_MAX_AGGS_MAX
;
5061 struct hwrm_vnic_tpa_cfg_input req
= {0};
5063 if (vnic
->fw_vnic_id
== INVALID_HW_RING_ID
)
5066 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_TPA_CFG
, -1, -1);
5069 u16 mss
= bp
->dev
->mtu
- 40;
5070 u32 nsegs
, n
, segs
= 0, flags
;
5072 flags
= VNIC_TPA_CFG_REQ_FLAGS_TPA
|
5073 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA
|
5074 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE
|
5075 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN
|
5076 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ
;
5077 if (tpa_flags
& BNXT_FLAG_GRO
)
5078 flags
|= VNIC_TPA_CFG_REQ_FLAGS_GRO
;
5080 req
.flags
= cpu_to_le32(flags
);
5083 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS
|
5084 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS
|
5085 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN
);
5087 /* Number of segs are log2 units, and first packet is not
5088 * included as part of this units.
5090 if (mss
<= BNXT_RX_PAGE_SIZE
) {
5091 n
= BNXT_RX_PAGE_SIZE
/ mss
;
5092 nsegs
= (MAX_SKB_FRAGS
- 1) * n
;
5094 n
= mss
/ BNXT_RX_PAGE_SIZE
;
5095 if (mss
& (BNXT_RX_PAGE_SIZE
- 1))
5097 nsegs
= (MAX_SKB_FRAGS
- n
) / n
;
5100 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5101 segs
= MAX_TPA_SEGS_P5
;
5102 max_aggs
= bp
->max_tpa
;
5104 segs
= ilog2(nsegs
);
5106 req
.max_agg_segs
= cpu_to_le16(segs
);
5107 req
.max_aggs
= cpu_to_le16(max_aggs
);
5109 req
.min_agg_len
= cpu_to_le32(512);
5111 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
5113 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5116 static u16
bnxt_cp_ring_from_grp(struct bnxt
*bp
, struct bnxt_ring_struct
*ring
)
5118 struct bnxt_ring_grp_info
*grp_info
;
5120 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5121 return grp_info
->cp_fw_ring_id
;
5124 static u16
bnxt_cp_ring_for_rx(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
5126 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5127 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
5128 struct bnxt_cp_ring_info
*cpr
;
5130 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_RX_HDL
];
5131 return cpr
->cp_ring_struct
.fw_ring_id
;
5133 return bnxt_cp_ring_from_grp(bp
, &rxr
->rx_ring_struct
);
5137 static u16
bnxt_cp_ring_for_tx(struct bnxt
*bp
, struct bnxt_tx_ring_info
*txr
)
5139 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5140 struct bnxt_napi
*bnapi
= txr
->bnapi
;
5141 struct bnxt_cp_ring_info
*cpr
;
5143 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_TX_HDL
];
5144 return cpr
->cp_ring_struct
.fw_ring_id
;
5146 return bnxt_cp_ring_from_grp(bp
, &txr
->tx_ring_struct
);
5150 static int bnxt_alloc_rss_indir_tbl(struct bnxt
*bp
)
5154 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5155 entries
= BNXT_MAX_RSS_TABLE_ENTRIES_P5
;
5157 entries
= HW_HASH_INDEX_SIZE
;
5159 bp
->rss_indir_tbl_entries
= entries
;
5160 bp
->rss_indir_tbl
= kmalloc_array(entries
, sizeof(*bp
->rss_indir_tbl
),
5162 if (!bp
->rss_indir_tbl
)
5167 static void bnxt_set_dflt_rss_indir_tbl(struct bnxt
*bp
)
5169 u16 max_rings
, max_entries
, pad
, i
;
5171 if (!bp
->rx_nr_rings
)
5174 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5175 max_rings
= bp
->rx_nr_rings
- 1;
5177 max_rings
= bp
->rx_nr_rings
;
5179 max_entries
= bnxt_get_rxfh_indir_size(bp
->dev
);
5181 for (i
= 0; i
< max_entries
; i
++)
5182 bp
->rss_indir_tbl
[i
] = ethtool_rxfh_indir_default(i
, max_rings
);
5184 pad
= bp
->rss_indir_tbl_entries
- max_entries
;
5186 memset(&bp
->rss_indir_tbl
[i
], 0, pad
* sizeof(u16
));
5189 static u16
bnxt_get_max_rss_ring(struct bnxt
*bp
)
5191 u16 i
, tbl_size
, max_ring
= 0;
5193 if (!bp
->rss_indir_tbl
)
5196 tbl_size
= bnxt_get_rxfh_indir_size(bp
->dev
);
5197 for (i
= 0; i
< tbl_size
; i
++)
5198 max_ring
= max(max_ring
, bp
->rss_indir_tbl
[i
]);
5202 int bnxt_get_nr_rss_ctxs(struct bnxt
*bp
, int rx_rings
)
5204 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5205 return DIV_ROUND_UP(rx_rings
, BNXT_RSS_TABLE_ENTRIES_P5
);
5206 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5211 static void __bnxt_fill_hw_rss_tbl(struct bnxt
*bp
, struct bnxt_vnic_info
*vnic
)
5213 bool no_rss
= !(vnic
->flags
& BNXT_VNIC_RSS_FLAG
);
5216 /* Fill the RSS indirection table with ring group ids */
5217 for (i
= 0, j
= 0; i
< HW_HASH_INDEX_SIZE
; i
++) {
5219 j
= bp
->rss_indir_tbl
[i
];
5220 vnic
->rss_table
[i
] = cpu_to_le16(vnic
->fw_grp_ids
[j
]);
5224 static void __bnxt_fill_hw_rss_tbl_p5(struct bnxt
*bp
,
5225 struct bnxt_vnic_info
*vnic
)
5227 __le16
*ring_tbl
= vnic
->rss_table
;
5228 struct bnxt_rx_ring_info
*rxr
;
5231 tbl_size
= bnxt_get_rxfh_indir_size(bp
->dev
);
5233 for (i
= 0; i
< tbl_size
; i
++) {
5236 j
= bp
->rss_indir_tbl
[i
];
5237 rxr
= &bp
->rx_ring
[j
];
5239 ring_id
= rxr
->rx_ring_struct
.fw_ring_id
;
5240 *ring_tbl
++ = cpu_to_le16(ring_id
);
5241 ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5242 *ring_tbl
++ = cpu_to_le16(ring_id
);
5246 static void bnxt_fill_hw_rss_tbl(struct bnxt
*bp
, struct bnxt_vnic_info
*vnic
)
5248 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5249 __bnxt_fill_hw_rss_tbl_p5(bp
, vnic
);
5251 __bnxt_fill_hw_rss_tbl(bp
, vnic
);
5254 static int bnxt_hwrm_vnic_set_rss(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
5256 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5257 struct hwrm_vnic_rss_cfg_input req
= {0};
5259 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) ||
5260 vnic
->fw_rss_cos_lb_ctx
[0] == INVALID_HW_RING_ID
)
5263 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
5265 bnxt_fill_hw_rss_tbl(bp
, vnic
);
5266 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
5267 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
5268 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
5269 req
.hash_key_tbl_addr
=
5270 cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
5272 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
5273 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5276 static int bnxt_hwrm_vnic_set_rss_p5(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
5278 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5279 struct hwrm_vnic_rss_cfg_input req
= {0};
5280 dma_addr_t ring_tbl_map
;
5283 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
5284 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
5286 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5289 bnxt_fill_hw_rss_tbl(bp
, vnic
);
5290 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
5291 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
5292 req
.hash_key_tbl_addr
= cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
5293 ring_tbl_map
= vnic
->rss_table_dma_addr
;
5294 nr_ctxs
= bnxt_get_nr_rss_ctxs(bp
, bp
->rx_nr_rings
);
5295 for (i
= 0; i
< nr_ctxs
; ring_tbl_map
+= BNXT_RSS_TABLE_SIZE_P5
, i
++) {
5298 req
.ring_grp_tbl_addr
= cpu_to_le64(ring_tbl_map
);
5299 req
.ring_table_pair_index
= i
;
5300 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[i
]);
5301 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5308 static int bnxt_hwrm_vnic_set_hds(struct bnxt
*bp
, u16 vnic_id
)
5310 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5311 struct hwrm_vnic_plcmodes_cfg_input req
= {0};
5313 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_PLCMODES_CFG
, -1, -1);
5314 req
.flags
= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT
|
5315 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4
|
5316 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6
);
5318 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID
|
5319 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID
);
5320 /* thresholds not implemented in firmware yet */
5321 req
.jumbo_thresh
= cpu_to_le16(bp
->rx_copy_thresh
);
5322 req
.hds_threshold
= cpu_to_le16(bp
->rx_copy_thresh
);
5323 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
5324 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5327 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt
*bp
, u16 vnic_id
,
5330 struct hwrm_vnic_rss_cos_lb_ctx_free_input req
= {0};
5332 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_FREE
, -1, -1);
5333 req
.rss_cos_lb_ctx_id
=
5334 cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
]);
5336 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5337 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] = INVALID_HW_RING_ID
;
5340 static void bnxt_hwrm_vnic_ctx_free(struct bnxt
*bp
)
5344 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
5345 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
5347 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++) {
5348 if (vnic
->fw_rss_cos_lb_ctx
[j
] != INVALID_HW_RING_ID
)
5349 bnxt_hwrm_vnic_ctx_free_one(bp
, i
, j
);
5352 bp
->rsscos_nr_ctxs
= 0;
5355 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt
*bp
, u16 vnic_id
, u16 ctx_idx
)
5358 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req
= {0};
5359 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output
*resp
=
5360 bp
->hwrm_cmd_resp_addr
;
5362 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC
, -1,
5365 mutex_lock(&bp
->hwrm_cmd_lock
);
5366 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5368 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] =
5369 le16_to_cpu(resp
->rss_cos_lb_ctx_id
);
5370 mutex_unlock(&bp
->hwrm_cmd_lock
);
5375 static u32
bnxt_get_roce_vnic_mode(struct bnxt
*bp
)
5377 if (bp
->flags
& BNXT_FLAG_ROCE_MIRROR_CAP
)
5378 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE
;
5379 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE
;
5382 int bnxt_hwrm_vnic_cfg(struct bnxt
*bp
, u16 vnic_id
)
5384 unsigned int ring
= 0, grp_idx
;
5385 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5386 struct hwrm_vnic_cfg_input req
= {0};
5389 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_CFG
, -1, -1);
5391 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5392 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[0];
5394 req
.default_rx_ring_id
=
5395 cpu_to_le16(rxr
->rx_ring_struct
.fw_ring_id
);
5396 req
.default_cmpl_ring_id
=
5397 cpu_to_le16(bnxt_cp_ring_for_rx(bp
, rxr
));
5399 cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID
|
5400 VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID
);
5403 req
.enables
= cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP
);
5404 /* Only RSS support for now TBD: COS & LB */
5405 if (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
) {
5406 req
.rss_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
5407 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
5408 VNIC_CFG_REQ_ENABLES_MRU
);
5409 } else if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
) {
5411 cpu_to_le16(bp
->vnic_info
[0].fw_rss_cos_lb_ctx
[0]);
5412 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
5413 VNIC_CFG_REQ_ENABLES_MRU
);
5414 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE
);
5416 req
.rss_rule
= cpu_to_le16(0xffff);
5419 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) &&
5420 (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
)) {
5421 req
.cos_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[1]);
5422 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE
);
5424 req
.cos_rule
= cpu_to_le16(0xffff);
5427 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
5429 else if (vnic
->flags
& BNXT_VNIC_RFS_FLAG
)
5431 else if ((vnic_id
== 1) && BNXT_CHIP_TYPE_NITRO_A0(bp
))
5432 ring
= bp
->rx_nr_rings
- 1;
5434 grp_idx
= bp
->rx_ring
[ring
].bnapi
->index
;
5435 req
.dflt_ring_grp
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_grp_id
);
5436 req
.lb_rule
= cpu_to_le16(0xffff);
5438 req
.mru
= cpu_to_le16(bp
->dev
->mtu
+ ETH_HLEN
+ VLAN_HLEN
);
5440 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
5441 #ifdef CONFIG_BNXT_SRIOV
5443 def_vlan
= bp
->vf
.vlan
;
5445 if ((bp
->flags
& BNXT_FLAG_STRIP_VLAN
) || def_vlan
)
5446 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE
);
5447 if (!vnic_id
&& bnxt_ulp_registered(bp
->edev
, BNXT_ROCE_ULP
))
5448 req
.flags
|= cpu_to_le32(bnxt_get_roce_vnic_mode(bp
));
5450 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5453 static void bnxt_hwrm_vnic_free_one(struct bnxt
*bp
, u16 vnic_id
)
5455 if (bp
->vnic_info
[vnic_id
].fw_vnic_id
!= INVALID_HW_RING_ID
) {
5456 struct hwrm_vnic_free_input req
= {0};
5458 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_FREE
, -1, -1);
5460 cpu_to_le32(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
5462 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5463 bp
->vnic_info
[vnic_id
].fw_vnic_id
= INVALID_HW_RING_ID
;
5467 static void bnxt_hwrm_vnic_free(struct bnxt
*bp
)
5471 for (i
= 0; i
< bp
->nr_vnics
; i
++)
5472 bnxt_hwrm_vnic_free_one(bp
, i
);
5475 static int bnxt_hwrm_vnic_alloc(struct bnxt
*bp
, u16 vnic_id
,
5476 unsigned int start_rx_ring_idx
,
5477 unsigned int nr_rings
)
5480 unsigned int i
, j
, grp_idx
, end_idx
= start_rx_ring_idx
+ nr_rings
;
5481 struct hwrm_vnic_alloc_input req
= {0};
5482 struct hwrm_vnic_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5483 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5485 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5486 goto vnic_no_ring_grps
;
5488 /* map ring groups to this vnic */
5489 for (i
= start_rx_ring_idx
, j
= 0; i
< end_idx
; i
++, j
++) {
5490 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
5491 if (bp
->grp_info
[grp_idx
].fw_grp_id
== INVALID_HW_RING_ID
) {
5492 netdev_err(bp
->dev
, "Not enough ring groups avail:%x req:%x\n",
5496 vnic
->fw_grp_ids
[j
] = bp
->grp_info
[grp_idx
].fw_grp_id
;
5500 for (i
= 0; i
< BNXT_MAX_CTX_PER_VNIC
; i
++)
5501 vnic
->fw_rss_cos_lb_ctx
[i
] = INVALID_HW_RING_ID
;
5503 req
.flags
= cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT
);
5505 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_ALLOC
, -1, -1);
5507 mutex_lock(&bp
->hwrm_cmd_lock
);
5508 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5510 vnic
->fw_vnic_id
= le32_to_cpu(resp
->vnic_id
);
5511 mutex_unlock(&bp
->hwrm_cmd_lock
);
5515 static int bnxt_hwrm_vnic_qcaps(struct bnxt
*bp
)
5517 struct hwrm_vnic_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5518 struct hwrm_vnic_qcaps_input req
= {0};
5521 bp
->hw_ring_stats_size
= sizeof(struct ctx_hw_stats
);
5522 bp
->flags
&= ~(BNXT_FLAG_NEW_RSS_CAP
| BNXT_FLAG_ROCE_MIRROR_CAP
);
5523 if (bp
->hwrm_spec_code
< 0x10600)
5526 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_QCAPS
, -1, -1);
5527 mutex_lock(&bp
->hwrm_cmd_lock
);
5528 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5530 u32 flags
= le32_to_cpu(resp
->flags
);
5532 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
) &&
5533 (flags
& VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP
))
5534 bp
->flags
|= BNXT_FLAG_NEW_RSS_CAP
;
5536 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP
)
5537 bp
->flags
|= BNXT_FLAG_ROCE_MIRROR_CAP
;
5539 /* Older P5 fw before EXT_HW_STATS support did not set
5540 * VLAN_STRIP_CAP properly.
5542 if ((flags
& VNIC_QCAPS_RESP_FLAGS_VLAN_STRIP_CAP
) ||
5543 (BNXT_CHIP_P5_THOR(bp
) &&
5544 !(bp
->fw_cap
& BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED
)))
5545 bp
->fw_cap
|= BNXT_FW_CAP_VLAN_RX_STRIP
;
5546 bp
->max_tpa_v2
= le16_to_cpu(resp
->max_aggs_supported
);
5547 if (bp
->max_tpa_v2
) {
5548 if (BNXT_CHIP_P5_THOR(bp
))
5549 bp
->hw_ring_stats_size
= BNXT_RING_STATS_SIZE_P5
;
5551 bp
->hw_ring_stats_size
= BNXT_RING_STATS_SIZE_P5_SR2
;
5554 mutex_unlock(&bp
->hwrm_cmd_lock
);
5558 static int bnxt_hwrm_ring_grp_alloc(struct bnxt
*bp
)
5563 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5566 mutex_lock(&bp
->hwrm_cmd_lock
);
5567 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5568 struct hwrm_ring_grp_alloc_input req
= {0};
5569 struct hwrm_ring_grp_alloc_output
*resp
=
5570 bp
->hwrm_cmd_resp_addr
;
5571 unsigned int grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
5573 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_ALLOC
, -1, -1);
5575 req
.cr
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
5576 req
.rr
= cpu_to_le16(bp
->grp_info
[grp_idx
].rx_fw_ring_id
);
5577 req
.ar
= cpu_to_le16(bp
->grp_info
[grp_idx
].agg_fw_ring_id
);
5578 req
.sc
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_stats_ctx
);
5580 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5585 bp
->grp_info
[grp_idx
].fw_grp_id
=
5586 le32_to_cpu(resp
->ring_group_id
);
5588 mutex_unlock(&bp
->hwrm_cmd_lock
);
5592 static void bnxt_hwrm_ring_grp_free(struct bnxt
*bp
)
5595 struct hwrm_ring_grp_free_input req
= {0};
5597 if (!bp
->grp_info
|| (bp
->flags
& BNXT_FLAG_CHIP_P5
))
5600 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_FREE
, -1, -1);
5602 mutex_lock(&bp
->hwrm_cmd_lock
);
5603 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5604 if (bp
->grp_info
[i
].fw_grp_id
== INVALID_HW_RING_ID
)
5607 cpu_to_le32(bp
->grp_info
[i
].fw_grp_id
);
5609 _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5610 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
5612 mutex_unlock(&bp
->hwrm_cmd_lock
);
5615 static int hwrm_ring_alloc_send_msg(struct bnxt
*bp
,
5616 struct bnxt_ring_struct
*ring
,
5617 u32 ring_type
, u32 map_index
)
5619 int rc
= 0, err
= 0;
5620 struct hwrm_ring_alloc_input req
= {0};
5621 struct hwrm_ring_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5622 struct bnxt_ring_mem_info
*rmem
= &ring
->ring_mem
;
5623 struct bnxt_ring_grp_info
*grp_info
;
5626 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_ALLOC
, -1, -1);
5629 if (rmem
->nr_pages
> 1) {
5630 req
.page_tbl_addr
= cpu_to_le64(rmem
->pg_tbl_map
);
5631 /* Page size is in log2 units */
5632 req
.page_size
= BNXT_PAGE_SHIFT
;
5633 req
.page_tbl_depth
= 1;
5635 req
.page_tbl_addr
= cpu_to_le64(rmem
->dma_arr
[0]);
5638 /* Association of ring index with doorbell index and MSIX number */
5639 req
.logical_id
= cpu_to_le16(map_index
);
5641 switch (ring_type
) {
5642 case HWRM_RING_ALLOC_TX
: {
5643 struct bnxt_tx_ring_info
*txr
;
5645 txr
= container_of(ring
, struct bnxt_tx_ring_info
,
5647 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_TX
;
5648 /* Association of transmit ring with completion ring */
5649 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5650 req
.cmpl_ring_id
= cpu_to_le16(bnxt_cp_ring_for_tx(bp
, txr
));
5651 req
.length
= cpu_to_le32(bp
->tx_ring_mask
+ 1);
5652 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5653 req
.queue_id
= cpu_to_le16(ring
->queue_id
);
5656 case HWRM_RING_ALLOC_RX
:
5657 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
5658 req
.length
= cpu_to_le32(bp
->rx_ring_mask
+ 1);
5659 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5662 /* Association of rx ring with stats context */
5663 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5664 req
.rx_buf_size
= cpu_to_le16(bp
->rx_buf_use_size
);
5665 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5666 req
.enables
|= cpu_to_le32(
5667 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
5668 if (NET_IP_ALIGN
== 2)
5669 flags
= RING_ALLOC_REQ_FLAGS_RX_SOP_PAD
;
5670 req
.flags
= cpu_to_le16(flags
);
5673 case HWRM_RING_ALLOC_AGG
:
5674 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5675 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX_AGG
;
5676 /* Association of agg ring with rx ring */
5677 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5678 req
.rx_ring_id
= cpu_to_le16(grp_info
->rx_fw_ring_id
);
5679 req
.rx_buf_size
= cpu_to_le16(BNXT_RX_PAGE_SIZE
);
5680 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5681 req
.enables
|= cpu_to_le32(
5682 RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID
|
5683 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
5685 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
5687 req
.length
= cpu_to_le32(bp
->rx_agg_ring_mask
+ 1);
5689 case HWRM_RING_ALLOC_CMPL
:
5690 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_L2_CMPL
;
5691 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
5692 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5693 /* Association of cp ring with nq */
5694 grp_info
= &bp
->grp_info
[map_index
];
5695 req
.nq_ring_id
= cpu_to_le16(grp_info
->cp_fw_ring_id
);
5696 req
.cq_handle
= cpu_to_le64(ring
->handle
);
5697 req
.enables
|= cpu_to_le32(
5698 RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID
);
5699 } else if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
5700 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
5703 case HWRM_RING_ALLOC_NQ
:
5704 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_NQ
;
5705 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
5706 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
5707 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
5710 netdev_err(bp
->dev
, "hwrm alloc invalid ring type %d\n",
5715 mutex_lock(&bp
->hwrm_cmd_lock
);
5716 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5717 err
= le16_to_cpu(resp
->error_code
);
5718 ring_id
= le16_to_cpu(resp
->ring_id
);
5719 mutex_unlock(&bp
->hwrm_cmd_lock
);
5722 netdev_err(bp
->dev
, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
5723 ring_type
, rc
, err
);
5726 ring
->fw_ring_id
= ring_id
;
5730 static int bnxt_hwrm_set_async_event_cr(struct bnxt
*bp
, int idx
)
5735 struct hwrm_func_cfg_input req
= {0};
5737 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
5738 req
.fid
= cpu_to_le16(0xffff);
5739 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
5740 req
.async_event_cr
= cpu_to_le16(idx
);
5741 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5743 struct hwrm_func_vf_cfg_input req
= {0};
5745 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_VF_CFG
, -1, -1);
5747 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
5748 req
.async_event_cr
= cpu_to_le16(idx
);
5749 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5754 static void bnxt_set_db(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 ring_type
,
5755 u32 map_idx
, u32 xid
)
5757 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5759 db
->doorbell
= bp
->bar1
+ DB_PF_OFFSET_P5
;
5761 db
->doorbell
= bp
->bar1
+ DB_VF_OFFSET_P5
;
5762 switch (ring_type
) {
5763 case HWRM_RING_ALLOC_TX
:
5764 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SQ
;
5766 case HWRM_RING_ALLOC_RX
:
5767 case HWRM_RING_ALLOC_AGG
:
5768 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SRQ
;
5770 case HWRM_RING_ALLOC_CMPL
:
5771 db
->db_key64
= DBR_PATH_L2
;
5773 case HWRM_RING_ALLOC_NQ
:
5774 db
->db_key64
= DBR_PATH_L2
;
5777 db
->db_key64
|= (u64
)xid
<< DBR_XID_SFT
;
5779 db
->doorbell
= bp
->bar1
+ map_idx
* 0x80;
5780 switch (ring_type
) {
5781 case HWRM_RING_ALLOC_TX
:
5782 db
->db_key32
= DB_KEY_TX
;
5784 case HWRM_RING_ALLOC_RX
:
5785 case HWRM_RING_ALLOC_AGG
:
5786 db
->db_key32
= DB_KEY_RX
;
5788 case HWRM_RING_ALLOC_CMPL
:
5789 db
->db_key32
= DB_KEY_CP
;
5795 static int bnxt_hwrm_ring_alloc(struct bnxt
*bp
)
5797 bool agg_rings
= !!(bp
->flags
& BNXT_FLAG_AGG_RINGS
);
5801 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5802 type
= HWRM_RING_ALLOC_NQ
;
5804 type
= HWRM_RING_ALLOC_CMPL
;
5805 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5806 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5807 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5808 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
5809 u32 map_idx
= ring
->map_idx
;
5810 unsigned int vector
;
5812 vector
= bp
->irq_tbl
[map_idx
].vector
;
5813 disable_irq_nosync(vector
);
5814 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5819 bnxt_set_db(bp
, &cpr
->cp_db
, type
, map_idx
, ring
->fw_ring_id
);
5820 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
5822 bp
->grp_info
[i
].cp_fw_ring_id
= ring
->fw_ring_id
;
5825 rc
= bnxt_hwrm_set_async_event_cr(bp
, ring
->fw_ring_id
);
5827 netdev_warn(bp
->dev
, "Failed to set async event completion ring.\n");
5831 type
= HWRM_RING_ALLOC_TX
;
5832 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5833 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5834 struct bnxt_ring_struct
*ring
;
5837 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5838 struct bnxt_napi
*bnapi
= txr
->bnapi
;
5839 struct bnxt_cp_ring_info
*cpr
, *cpr2
;
5840 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5842 cpr
= &bnapi
->cp_ring
;
5843 cpr2
= cpr
->cp_ring_arr
[BNXT_TX_HDL
];
5844 ring
= &cpr2
->cp_ring_struct
;
5845 ring
->handle
= BNXT_TX_HDL
;
5846 map_idx
= bnapi
->index
;
5847 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5850 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5852 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5854 ring
= &txr
->tx_ring_struct
;
5856 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5859 bnxt_set_db(bp
, &txr
->tx_db
, type
, map_idx
, ring
->fw_ring_id
);
5862 type
= HWRM_RING_ALLOC_RX
;
5863 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5864 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5865 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5866 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
5867 u32 map_idx
= bnapi
->index
;
5869 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5872 bnxt_set_db(bp
, &rxr
->rx_db
, type
, map_idx
, ring
->fw_ring_id
);
5873 /* If we have agg rings, post agg buffers first. */
5875 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
5876 bp
->grp_info
[map_idx
].rx_fw_ring_id
= ring
->fw_ring_id
;
5877 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5878 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5879 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5880 struct bnxt_cp_ring_info
*cpr2
;
5882 cpr2
= cpr
->cp_ring_arr
[BNXT_RX_HDL
];
5883 ring
= &cpr2
->cp_ring_struct
;
5884 ring
->handle
= BNXT_RX_HDL
;
5885 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5888 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5890 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5895 type
= HWRM_RING_ALLOC_AGG
;
5896 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5897 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5898 struct bnxt_ring_struct
*ring
=
5899 &rxr
->rx_agg_ring_struct
;
5900 u32 grp_idx
= ring
->grp_idx
;
5901 u32 map_idx
= grp_idx
+ bp
->rx_nr_rings
;
5903 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5907 bnxt_set_db(bp
, &rxr
->rx_agg_db
, type
, map_idx
,
5909 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
5910 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
5911 bp
->grp_info
[grp_idx
].agg_fw_ring_id
= ring
->fw_ring_id
;
5918 static int hwrm_ring_free_send_msg(struct bnxt
*bp
,
5919 struct bnxt_ring_struct
*ring
,
5920 u32 ring_type
, int cmpl_ring_id
)
5923 struct hwrm_ring_free_input req
= {0};
5924 struct hwrm_ring_free_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5927 if (BNXT_NO_FW_ACCESS(bp
))
5930 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_FREE
, cmpl_ring_id
, -1);
5931 req
.ring_type
= ring_type
;
5932 req
.ring_id
= cpu_to_le16(ring
->fw_ring_id
);
5934 mutex_lock(&bp
->hwrm_cmd_lock
);
5935 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5936 error_code
= le16_to_cpu(resp
->error_code
);
5937 mutex_unlock(&bp
->hwrm_cmd_lock
);
5939 if (rc
|| error_code
) {
5940 netdev_err(bp
->dev
, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
5941 ring_type
, rc
, error_code
);
5947 static void bnxt_hwrm_ring_free(struct bnxt
*bp
, bool close_path
)
5955 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5956 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5957 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
5959 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5960 u32 cmpl_ring_id
= bnxt_cp_ring_for_tx(bp
, txr
);
5962 hwrm_ring_free_send_msg(bp
, ring
,
5963 RING_FREE_REQ_RING_TYPE_TX
,
5964 close_path
? cmpl_ring_id
:
5965 INVALID_HW_RING_ID
);
5966 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5970 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5971 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5972 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5973 u32 grp_idx
= rxr
->bnapi
->index
;
5975 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5976 u32 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5978 hwrm_ring_free_send_msg(bp
, ring
,
5979 RING_FREE_REQ_RING_TYPE_RX
,
5980 close_path
? cmpl_ring_id
:
5981 INVALID_HW_RING_ID
);
5982 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5983 bp
->grp_info
[grp_idx
].rx_fw_ring_id
=
5988 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5989 type
= RING_FREE_REQ_RING_TYPE_RX_AGG
;
5991 type
= RING_FREE_REQ_RING_TYPE_RX
;
5992 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5993 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5994 struct bnxt_ring_struct
*ring
= &rxr
->rx_agg_ring_struct
;
5995 u32 grp_idx
= rxr
->bnapi
->index
;
5997 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5998 u32 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
6000 hwrm_ring_free_send_msg(bp
, ring
, type
,
6001 close_path
? cmpl_ring_id
:
6002 INVALID_HW_RING_ID
);
6003 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
6004 bp
->grp_info
[grp_idx
].agg_fw_ring_id
=
6009 /* The completion rings are about to be freed. After that the
6010 * IRQ doorbell will not work anymore. So we need to disable
6013 bnxt_disable_int_sync(bp
);
6015 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
6016 type
= RING_FREE_REQ_RING_TYPE_NQ
;
6018 type
= RING_FREE_REQ_RING_TYPE_L2_CMPL
;
6019 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6020 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6021 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6022 struct bnxt_ring_struct
*ring
;
6025 for (j
= 0; j
< 2; j
++) {
6026 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
6029 ring
= &cpr2
->cp_ring_struct
;
6030 if (ring
->fw_ring_id
== INVALID_HW_RING_ID
)
6032 hwrm_ring_free_send_msg(bp
, ring
,
6033 RING_FREE_REQ_RING_TYPE_L2_CMPL
,
6034 INVALID_HW_RING_ID
);
6035 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
6038 ring
= &cpr
->cp_ring_struct
;
6039 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
6040 hwrm_ring_free_send_msg(bp
, ring
, type
,
6041 INVALID_HW_RING_ID
);
6042 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
6043 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
6048 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
6051 static int bnxt_hwrm_get_rings(struct bnxt
*bp
)
6053 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6054 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6055 struct hwrm_func_qcfg_input req
= {0};
6058 if (bp
->hwrm_spec_code
< 0x10601)
6061 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
6062 req
.fid
= cpu_to_le16(0xffff);
6063 mutex_lock(&bp
->hwrm_cmd_lock
);
6064 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6066 mutex_unlock(&bp
->hwrm_cmd_lock
);
6070 hw_resc
->resv_tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
6071 if (BNXT_NEW_RM(bp
)) {
6074 hw_resc
->resv_rx_rings
= le16_to_cpu(resp
->alloc_rx_rings
);
6075 hw_resc
->resv_hw_ring_grps
=
6076 le32_to_cpu(resp
->alloc_hw_ring_grps
);
6077 hw_resc
->resv_vnics
= le16_to_cpu(resp
->alloc_vnics
);
6078 cp
= le16_to_cpu(resp
->alloc_cmpl_rings
);
6079 stats
= le16_to_cpu(resp
->alloc_stat_ctx
);
6080 hw_resc
->resv_irqs
= cp
;
6081 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6082 int rx
= hw_resc
->resv_rx_rings
;
6083 int tx
= hw_resc
->resv_tx_rings
;
6085 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6087 if (cp
< (rx
+ tx
)) {
6088 bnxt_trim_rings(bp
, &rx
, &tx
, cp
, false);
6089 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6091 hw_resc
->resv_rx_rings
= rx
;
6092 hw_resc
->resv_tx_rings
= tx
;
6094 hw_resc
->resv_irqs
= le16_to_cpu(resp
->alloc_msix
);
6095 hw_resc
->resv_hw_ring_grps
= rx
;
6097 hw_resc
->resv_cp_rings
= cp
;
6098 hw_resc
->resv_stat_ctxs
= stats
;
6100 mutex_unlock(&bp
->hwrm_cmd_lock
);
6104 /* Caller must hold bp->hwrm_cmd_lock */
6105 int __bnxt_hwrm_get_tx_rings(struct bnxt
*bp
, u16 fid
, int *tx_rings
)
6107 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6108 struct hwrm_func_qcfg_input req
= {0};
6111 if (bp
->hwrm_spec_code
< 0x10601)
6114 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
6115 req
.fid
= cpu_to_le16(fid
);
6116 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6118 *tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
6123 static bool bnxt_rfs_supported(struct bnxt
*bp
);
6126 __bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, struct hwrm_func_cfg_input
*req
,
6127 int tx_rings
, int rx_rings
, int ring_grps
,
6128 int cp_rings
, int stats
, int vnics
)
6132 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_CFG
, -1, -1);
6133 req
->fid
= cpu_to_le16(0xffff);
6134 enables
|= tx_rings
? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
6135 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
6136 if (BNXT_NEW_RM(bp
)) {
6137 enables
|= rx_rings
? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS
: 0;
6138 enables
|= stats
? FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
6139 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6140 enables
|= cp_rings
? FUNC_CFG_REQ_ENABLES_NUM_MSIX
: 0;
6141 enables
|= tx_rings
+ ring_grps
?
6142 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
6143 enables
|= rx_rings
?
6144 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
6146 enables
|= cp_rings
?
6147 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
6148 enables
|= ring_grps
?
6149 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
|
6150 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
6152 enables
|= vnics
? FUNC_CFG_REQ_ENABLES_NUM_VNICS
: 0;
6154 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
6155 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6156 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
6157 req
->num_msix
= cpu_to_le16(cp_rings
);
6158 req
->num_rsscos_ctxs
=
6159 cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
6161 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
6162 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
6163 req
->num_rsscos_ctxs
= cpu_to_le16(1);
6164 if (!(bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
6165 bnxt_rfs_supported(bp
))
6166 req
->num_rsscos_ctxs
=
6167 cpu_to_le16(ring_grps
+ 1);
6169 req
->num_stat_ctxs
= cpu_to_le16(stats
);
6170 req
->num_vnics
= cpu_to_le16(vnics
);
6172 req
->enables
= cpu_to_le32(enables
);
6176 __bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
,
6177 struct hwrm_func_vf_cfg_input
*req
, int tx_rings
,
6178 int rx_rings
, int ring_grps
, int cp_rings
,
6179 int stats
, int vnics
)
6183 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_VF_CFG
, -1, -1);
6184 enables
|= tx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
6185 enables
|= rx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS
|
6186 FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
6187 enables
|= stats
? FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
6188 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6189 enables
|= tx_rings
+ ring_grps
?
6190 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
6192 enables
|= cp_rings
?
6193 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
6194 enables
|= ring_grps
?
6195 FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
: 0;
6197 enables
|= vnics
? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS
: 0;
6198 enables
|= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS
;
6200 req
->num_l2_ctxs
= cpu_to_le16(BNXT_VF_MAX_L2_CTX
);
6201 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
6202 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
6203 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6204 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
6205 req
->num_rsscos_ctxs
= cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
6207 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
6208 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
6209 req
->num_rsscos_ctxs
= cpu_to_le16(BNXT_VF_MAX_RSS_CTX
);
6211 req
->num_stat_ctxs
= cpu_to_le16(stats
);
6212 req
->num_vnics
= cpu_to_le16(vnics
);
6214 req
->enables
= cpu_to_le32(enables
);
6218 bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6219 int ring_grps
, int cp_rings
, int stats
, int vnics
)
6221 struct hwrm_func_cfg_input req
= {0};
6224 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6225 cp_rings
, stats
, vnics
);
6229 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6233 if (bp
->hwrm_spec_code
< 0x10601)
6234 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
6236 return bnxt_hwrm_get_rings(bp
);
6240 bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6241 int ring_grps
, int cp_rings
, int stats
, int vnics
)
6243 struct hwrm_func_vf_cfg_input req
= {0};
6246 if (!BNXT_NEW_RM(bp
)) {
6247 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
6251 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6252 cp_rings
, stats
, vnics
);
6253 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6257 return bnxt_hwrm_get_rings(bp
);
6260 static int bnxt_hwrm_reserve_rings(struct bnxt
*bp
, int tx
, int rx
, int grp
,
6261 int cp
, int stat
, int vnic
)
6264 return bnxt_hwrm_reserve_pf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
6267 return bnxt_hwrm_reserve_vf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
6271 int bnxt_nq_rings_in_use(struct bnxt
*bp
)
6273 int cp
= bp
->cp_nr_rings
;
6274 int ulp_msix
, ulp_base
;
6276 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
6278 ulp_base
= bnxt_get_ulp_msix_base(bp
);
6280 if ((ulp_base
+ ulp_msix
) > cp
)
6281 cp
= ulp_base
+ ulp_msix
;
6286 static int bnxt_cp_rings_in_use(struct bnxt
*bp
)
6290 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6291 return bnxt_nq_rings_in_use(bp
);
6293 cp
= bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
6297 static int bnxt_get_func_stat_ctxs(struct bnxt
*bp
)
6299 int ulp_stat
= bnxt_get_ulp_stat_ctxs(bp
);
6300 int cp
= bp
->cp_nr_rings
;
6305 if (bnxt_nq_rings_in_use(bp
) > cp
+ bnxt_get_ulp_msix_num(bp
))
6306 return bnxt_get_ulp_msix_base(bp
) + ulp_stat
;
6308 return cp
+ ulp_stat
;
6311 /* Check if a default RSS map needs to be setup. This function is only
6312 * used on older firmware that does not require reserving RX rings.
6314 static void bnxt_check_rss_tbl_no_rmgr(struct bnxt
*bp
)
6316 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6318 /* The RSS map is valid for RX rings set to resv_rx_rings */
6319 if (hw_resc
->resv_rx_rings
!= bp
->rx_nr_rings
) {
6320 hw_resc
->resv_rx_rings
= bp
->rx_nr_rings
;
6321 if (!netif_is_rxfh_configured(bp
->dev
))
6322 bnxt_set_dflt_rss_indir_tbl(bp
);
6326 static bool bnxt_need_reserve_rings(struct bnxt
*bp
)
6328 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6329 int cp
= bnxt_cp_rings_in_use(bp
);
6330 int nq
= bnxt_nq_rings_in_use(bp
);
6331 int rx
= bp
->rx_nr_rings
, stat
;
6332 int vnic
= 1, grp
= rx
;
6334 if (hw_resc
->resv_tx_rings
!= bp
->tx_nr_rings
&&
6335 bp
->hwrm_spec_code
>= 0x10601)
6338 /* Old firmware does not need RX ring reservations but we still
6339 * need to setup a default RSS map when needed. With new firmware
6340 * we go through RX ring reservations first and then set up the
6341 * RSS map for the successfully reserved RX rings when needed.
6343 if (!BNXT_NEW_RM(bp
)) {
6344 bnxt_check_rss_tbl_no_rmgr(bp
);
6347 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6349 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6351 stat
= bnxt_get_func_stat_ctxs(bp
);
6352 if (hw_resc
->resv_rx_rings
!= rx
|| hw_resc
->resv_cp_rings
!= cp
||
6353 hw_resc
->resv_vnics
!= vnic
|| hw_resc
->resv_stat_ctxs
!= stat
||
6354 (hw_resc
->resv_hw_ring_grps
!= grp
&&
6355 !(bp
->flags
& BNXT_FLAG_CHIP_P5
)))
6357 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && BNXT_PF(bp
) &&
6358 hw_resc
->resv_irqs
!= nq
)
6363 static int __bnxt_reserve_rings(struct bnxt
*bp
)
6365 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6366 int cp
= bnxt_nq_rings_in_use(bp
);
6367 int tx
= bp
->tx_nr_rings
;
6368 int rx
= bp
->rx_nr_rings
;
6369 int grp
, rx_rings
, rc
;
6373 if (!bnxt_need_reserve_rings(bp
))
6376 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
6378 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6380 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6382 grp
= bp
->rx_nr_rings
;
6383 stat
= bnxt_get_func_stat_ctxs(bp
);
6385 rc
= bnxt_hwrm_reserve_rings(bp
, tx
, rx
, grp
, cp
, stat
, vnic
);
6389 tx
= hw_resc
->resv_tx_rings
;
6390 if (BNXT_NEW_RM(bp
)) {
6391 rx
= hw_resc
->resv_rx_rings
;
6392 cp
= hw_resc
->resv_irqs
;
6393 grp
= hw_resc
->resv_hw_ring_grps
;
6394 vnic
= hw_resc
->resv_vnics
;
6395 stat
= hw_resc
->resv_stat_ctxs
;
6399 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
6403 if (netif_running(bp
->dev
))
6406 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
6407 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
6408 bp
->dev
->hw_features
&= ~NETIF_F_LRO
;
6409 bp
->dev
->features
&= ~NETIF_F_LRO
;
6410 bnxt_set_ring_params(bp
);
6413 rx_rings
= min_t(int, rx_rings
, grp
);
6414 cp
= min_t(int, cp
, bp
->cp_nr_rings
);
6415 if (stat
> bnxt_get_ulp_stat_ctxs(bp
))
6416 stat
-= bnxt_get_ulp_stat_ctxs(bp
);
6417 cp
= min_t(int, cp
, stat
);
6418 rc
= bnxt_trim_rings(bp
, &rx_rings
, &tx
, cp
, sh
);
6419 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6421 cp
= sh
? max_t(int, tx
, rx_rings
) : tx
+ rx_rings
;
6422 bp
->tx_nr_rings
= tx
;
6424 /* If we cannot reserve all the RX rings, reset the RSS map only
6425 * if absolutely necessary
6427 if (rx_rings
!= bp
->rx_nr_rings
) {
6428 netdev_warn(bp
->dev
, "Able to reserve only %d out of %d requested RX rings\n",
6429 rx_rings
, bp
->rx_nr_rings
);
6430 if ((bp
->dev
->priv_flags
& IFF_RXFH_CONFIGURED
) &&
6431 (bnxt_get_nr_rss_ctxs(bp
, bp
->rx_nr_rings
) !=
6432 bnxt_get_nr_rss_ctxs(bp
, rx_rings
) ||
6433 bnxt_get_max_rss_ring(bp
) >= rx_rings
)) {
6434 netdev_warn(bp
->dev
, "RSS table entries reverting to default\n");
6435 bp
->dev
->priv_flags
&= ~IFF_RXFH_CONFIGURED
;
6438 bp
->rx_nr_rings
= rx_rings
;
6439 bp
->cp_nr_rings
= cp
;
6441 if (!tx
|| !rx
|| !cp
|| !grp
|| !vnic
|| !stat
)
6444 if (!netif_is_rxfh_configured(bp
->dev
))
6445 bnxt_set_dflt_rss_indir_tbl(bp
);
6450 static int bnxt_hwrm_check_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6451 int ring_grps
, int cp_rings
, int stats
,
6454 struct hwrm_func_vf_cfg_input req
= {0};
6457 if (!BNXT_NEW_RM(bp
))
6460 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6461 cp_rings
, stats
, vnics
);
6462 flags
= FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST
|
6463 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
6464 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
6465 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
6466 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
|
6467 FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
;
6468 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6469 flags
|= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
6471 req
.flags
= cpu_to_le32(flags
);
6472 return hwrm_send_message_silent(bp
, &req
, sizeof(req
),
6476 static int bnxt_hwrm_check_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6477 int ring_grps
, int cp_rings
, int stats
,
6480 struct hwrm_func_cfg_input req
= {0};
6483 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6484 cp_rings
, stats
, vnics
);
6485 flags
= FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST
;
6486 if (BNXT_NEW_RM(bp
)) {
6487 flags
|= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
6488 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
6489 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
6490 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
;
6491 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
6492 flags
|= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
|
6493 FUNC_CFG_REQ_FLAGS_NQ_ASSETS_TEST
;
6495 flags
|= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
6498 req
.flags
= cpu_to_le32(flags
);
6499 return hwrm_send_message_silent(bp
, &req
, sizeof(req
),
6503 static int bnxt_hwrm_check_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6504 int ring_grps
, int cp_rings
, int stats
,
6507 if (bp
->hwrm_spec_code
< 0x10801)
6511 return bnxt_hwrm_check_pf_rings(bp
, tx_rings
, rx_rings
,
6512 ring_grps
, cp_rings
, stats
,
6515 return bnxt_hwrm_check_vf_rings(bp
, tx_rings
, rx_rings
, ring_grps
,
6516 cp_rings
, stats
, vnics
);
6519 static void bnxt_hwrm_coal_params_qcaps(struct bnxt
*bp
)
6521 struct hwrm_ring_aggint_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6522 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6523 struct hwrm_ring_aggint_qcaps_input req
= {0};
6526 coal_cap
->cmpl_params
= BNXT_LEGACY_COAL_CMPL_PARAMS
;
6527 coal_cap
->num_cmpl_dma_aggr_max
= 63;
6528 coal_cap
->num_cmpl_dma_aggr_during_int_max
= 63;
6529 coal_cap
->cmpl_aggr_dma_tmr_max
= 65535;
6530 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
= 65535;
6531 coal_cap
->int_lat_tmr_min_max
= 65535;
6532 coal_cap
->int_lat_tmr_max_max
= 65535;
6533 coal_cap
->num_cmpl_aggr_int_max
= 65535;
6534 coal_cap
->timer_units
= 80;
6536 if (bp
->hwrm_spec_code
< 0x10902)
6539 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_AGGINT_QCAPS
, -1, -1);
6540 mutex_lock(&bp
->hwrm_cmd_lock
);
6541 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6543 coal_cap
->cmpl_params
= le32_to_cpu(resp
->cmpl_params
);
6544 coal_cap
->nq_params
= le32_to_cpu(resp
->nq_params
);
6545 coal_cap
->num_cmpl_dma_aggr_max
=
6546 le16_to_cpu(resp
->num_cmpl_dma_aggr_max
);
6547 coal_cap
->num_cmpl_dma_aggr_during_int_max
=
6548 le16_to_cpu(resp
->num_cmpl_dma_aggr_during_int_max
);
6549 coal_cap
->cmpl_aggr_dma_tmr_max
=
6550 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_max
);
6551 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
=
6552 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_during_int_max
);
6553 coal_cap
->int_lat_tmr_min_max
=
6554 le16_to_cpu(resp
->int_lat_tmr_min_max
);
6555 coal_cap
->int_lat_tmr_max_max
=
6556 le16_to_cpu(resp
->int_lat_tmr_max_max
);
6557 coal_cap
->num_cmpl_aggr_int_max
=
6558 le16_to_cpu(resp
->num_cmpl_aggr_int_max
);
6559 coal_cap
->timer_units
= le16_to_cpu(resp
->timer_units
);
6561 mutex_unlock(&bp
->hwrm_cmd_lock
);
6564 static u16
bnxt_usec_to_coal_tmr(struct bnxt
*bp
, u16 usec
)
6566 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6568 return usec
* 1000 / coal_cap
->timer_units
;
6571 static void bnxt_hwrm_set_coal_params(struct bnxt
*bp
,
6572 struct bnxt_coal
*hw_coal
,
6573 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input
*req
)
6575 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6576 u32 cmpl_params
= coal_cap
->cmpl_params
;
6577 u16 val
, tmr
, max
, flags
= 0;
6579 max
= hw_coal
->bufs_per_record
* 128;
6580 if (hw_coal
->budget
)
6581 max
= hw_coal
->bufs_per_record
* hw_coal
->budget
;
6582 max
= min_t(u16
, max
, coal_cap
->num_cmpl_aggr_int_max
);
6584 val
= clamp_t(u16
, hw_coal
->coal_bufs
, 1, max
);
6585 req
->num_cmpl_aggr_int
= cpu_to_le16(val
);
6587 val
= min_t(u16
, val
, coal_cap
->num_cmpl_dma_aggr_max
);
6588 req
->num_cmpl_dma_aggr
= cpu_to_le16(val
);
6590 val
= clamp_t(u16
, hw_coal
->coal_bufs_irq
, 1,
6591 coal_cap
->num_cmpl_dma_aggr_during_int_max
);
6592 req
->num_cmpl_dma_aggr_during_int
= cpu_to_le16(val
);
6594 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
);
6595 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_max_max
);
6596 req
->int_lat_tmr_max
= cpu_to_le16(tmr
);
6598 /* min timer set to 1/2 of interrupt timer */
6599 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN
) {
6601 val
= clamp_t(u16
, val
, 1, coal_cap
->int_lat_tmr_min_max
);
6602 req
->int_lat_tmr_min
= cpu_to_le16(val
);
6603 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
6606 /* buf timer set to 1/4 of interrupt timer */
6607 val
= clamp_t(u16
, tmr
/ 4, 1, coal_cap
->cmpl_aggr_dma_tmr_max
);
6608 req
->cmpl_aggr_dma_tmr
= cpu_to_le16(val
);
6611 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT
) {
6612 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks_irq
);
6613 val
= clamp_t(u16
, tmr
, 1,
6614 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
);
6615 req
->cmpl_aggr_dma_tmr_during_int
= cpu_to_le16(val
);
6617 cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE
);
6620 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET
)
6621 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
6622 if ((cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE
) &&
6623 hw_coal
->idle_thresh
&& hw_coal
->coal_ticks
< hw_coal
->idle_thresh
)
6624 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE
;
6625 req
->flags
= cpu_to_le16(flags
);
6626 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_ENABLES
);
6629 /* Caller holds bp->hwrm_cmd_lock */
6630 static int __bnxt_hwrm_set_coal_nq(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
6631 struct bnxt_coal
*hw_coal
)
6633 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req
= {0};
6634 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6635 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6636 u32 nq_params
= coal_cap
->nq_params
;
6639 if (!(nq_params
& RING_AGGINT_QCAPS_RESP_NQ_PARAMS_INT_LAT_TMR_MIN
))
6642 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
,
6644 req
.ring_id
= cpu_to_le16(cpr
->cp_ring_struct
.fw_ring_id
);
6646 cpu_to_le16(RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_IS_NQ
);
6648 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
) / 2;
6649 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_min_max
);
6650 req
.int_lat_tmr_min
= cpu_to_le16(tmr
);
6651 req
.enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
6652 return _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6655 int bnxt_hwrm_set_ring_coal(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
6657 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0};
6658 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6659 struct bnxt_coal coal
;
6661 /* Tick values in micro seconds.
6662 * 1 coal_buf x bufs_per_record = 1 completion record.
6664 memcpy(&coal
, &bp
->rx_coal
, sizeof(struct bnxt_coal
));
6666 coal
.coal_ticks
= cpr
->rx_ring_coal
.coal_ticks
;
6667 coal
.coal_bufs
= cpr
->rx_ring_coal
.coal_bufs
;
6669 if (!bnapi
->rx_ring
)
6672 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
6673 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6675 bnxt_hwrm_set_coal_params(bp
, &coal
, &req_rx
);
6677 req_rx
.ring_id
= cpu_to_le16(bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
));
6679 return hwrm_send_message(bp
, &req_rx
, sizeof(req_rx
),
6683 int bnxt_hwrm_set_coal(struct bnxt
*bp
)
6686 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0},
6689 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
6690 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6691 bnxt_hwrm_cmd_hdr_init(bp
, &req_tx
,
6692 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6694 bnxt_hwrm_set_coal_params(bp
, &bp
->rx_coal
, &req_rx
);
6695 bnxt_hwrm_set_coal_params(bp
, &bp
->tx_coal
, &req_tx
);
6697 mutex_lock(&bp
->hwrm_cmd_lock
);
6698 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6699 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6700 struct bnxt_coal
*hw_coal
;
6704 if (!bnapi
->rx_ring
) {
6705 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
6708 ring_id
= bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
);
6710 req
->ring_id
= cpu_to_le16(ring_id
);
6712 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
6717 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6720 if (bnapi
->rx_ring
&& bnapi
->tx_ring
) {
6722 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
6723 req
->ring_id
= cpu_to_le16(ring_id
);
6724 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
6730 hw_coal
= &bp
->rx_coal
;
6732 hw_coal
= &bp
->tx_coal
;
6733 __bnxt_hwrm_set_coal_nq(bp
, bnapi
, hw_coal
);
6735 mutex_unlock(&bp
->hwrm_cmd_lock
);
6739 static void bnxt_hwrm_stat_ctx_free(struct bnxt
*bp
)
6741 struct hwrm_stat_ctx_clr_stats_input req0
= {0};
6742 struct hwrm_stat_ctx_free_input req
= {0};
6748 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6751 bnxt_hwrm_cmd_hdr_init(bp
, &req0
, HWRM_STAT_CTX_CLR_STATS
, -1, -1);
6752 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_FREE
, -1, -1);
6754 mutex_lock(&bp
->hwrm_cmd_lock
);
6755 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6756 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6757 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6759 if (cpr
->hw_stats_ctx_id
!= INVALID_STATS_CTX_ID
) {
6760 req
.stat_ctx_id
= cpu_to_le32(cpr
->hw_stats_ctx_id
);
6761 if (BNXT_FW_MAJ(bp
) <= 20) {
6762 req0
.stat_ctx_id
= req
.stat_ctx_id
;
6763 _hwrm_send_message(bp
, &req0
, sizeof(req0
),
6766 _hwrm_send_message(bp
, &req
, sizeof(req
),
6769 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
6772 mutex_unlock(&bp
->hwrm_cmd_lock
);
6775 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt
*bp
)
6778 struct hwrm_stat_ctx_alloc_input req
= {0};
6779 struct hwrm_stat_ctx_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6781 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6784 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_ALLOC
, -1, -1);
6786 req
.stats_dma_length
= cpu_to_le16(bp
->hw_ring_stats_size
);
6787 req
.update_period_ms
= cpu_to_le32(bp
->stats_coal_ticks
/ 1000);
6789 mutex_lock(&bp
->hwrm_cmd_lock
);
6790 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6791 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6792 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6794 req
.stats_dma_addr
= cpu_to_le64(cpr
->stats
.hw_stats_map
);
6796 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
6801 cpr
->hw_stats_ctx_id
= le32_to_cpu(resp
->stat_ctx_id
);
6803 bp
->grp_info
[i
].fw_stats_ctx
= cpr
->hw_stats_ctx_id
;
6805 mutex_unlock(&bp
->hwrm_cmd_lock
);
6809 static int bnxt_hwrm_func_qcfg(struct bnxt
*bp
)
6811 struct hwrm_func_qcfg_input req
= {0};
6812 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6813 u32 min_db_offset
= 0;
6817 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
6818 req
.fid
= cpu_to_le16(0xffff);
6819 mutex_lock(&bp
->hwrm_cmd_lock
);
6820 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6822 goto func_qcfg_exit
;
6824 #ifdef CONFIG_BNXT_SRIOV
6826 struct bnxt_vf_info
*vf
= &bp
->vf
;
6828 vf
->vlan
= le16_to_cpu(resp
->vlan
) & VLAN_VID_MASK
;
6830 bp
->pf
.registered_vfs
= le16_to_cpu(resp
->registered_vfs
);
6833 flags
= le16_to_cpu(resp
->flags
);
6834 if (flags
& (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
|
6835 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED
)) {
6836 bp
->fw_cap
|= BNXT_FW_CAP_LLDP_AGENT
;
6837 if (flags
& FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
)
6838 bp
->fw_cap
|= BNXT_FW_CAP_DCBX_AGENT
;
6840 if (BNXT_PF(bp
) && (flags
& FUNC_QCFG_RESP_FLAGS_MULTI_HOST
))
6841 bp
->flags
|= BNXT_FLAG_MULTI_HOST
;
6842 if (flags
& FUNC_QCFG_RESP_FLAGS_RING_MONITOR_ENABLED
)
6843 bp
->fw_cap
|= BNXT_FW_CAP_RING_MONITOR
;
6845 switch (resp
->port_partition_type
) {
6846 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0
:
6847 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5
:
6848 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0
:
6849 bp
->port_partition_type
= resp
->port_partition_type
;
6852 if (bp
->hwrm_spec_code
< 0x10707 ||
6853 resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEB
)
6854 bp
->br_mode
= BRIDGE_MODE_VEB
;
6855 else if (resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEPA
)
6856 bp
->br_mode
= BRIDGE_MODE_VEPA
;
6858 bp
->br_mode
= BRIDGE_MODE_UNDEF
;
6860 bp
->max_mtu
= le16_to_cpu(resp
->max_mtu_configured
);
6862 bp
->max_mtu
= BNXT_MAX_MTU
;
6865 goto func_qcfg_exit
;
6867 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6869 min_db_offset
= DB_PF_OFFSET_P5
;
6871 min_db_offset
= DB_VF_OFFSET_P5
;
6873 bp
->db_size
= PAGE_ALIGN(le16_to_cpu(resp
->l2_doorbell_bar_size_kb
) *
6875 if (!bp
->db_size
|| bp
->db_size
> pci_resource_len(bp
->pdev
, 2) ||
6876 bp
->db_size
<= min_db_offset
)
6877 bp
->db_size
= pci_resource_len(bp
->pdev
, 2);
6880 mutex_unlock(&bp
->hwrm_cmd_lock
);
6884 static void bnxt_init_ctx_initializer(struct bnxt_ctx_mem_info
*ctx
,
6885 struct hwrm_func_backing_store_qcaps_output
*resp
)
6887 struct bnxt_mem_init
*mem_init
;
6893 init_val
= resp
->ctx_kind_initializer
;
6894 init_mask
= le16_to_cpu(resp
->ctx_init_mask
);
6895 offset
= &resp
->qp_init_offset
;
6896 mem_init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_QP
];
6897 for (i
= 0; i
< BNXT_CTX_MEM_INIT_MAX
; i
++, mem_init
++, offset
++) {
6898 mem_init
->init_val
= init_val
;
6899 mem_init
->offset
= BNXT_MEM_INVALID_OFFSET
;
6902 if (i
== BNXT_CTX_MEM_INIT_STAT
)
6903 offset
= &resp
->stat_init_offset
;
6904 if (init_mask
& (1 << i
))
6905 mem_init
->offset
= *offset
* 4;
6907 mem_init
->init_val
= 0;
6909 ctx
->mem_init
[BNXT_CTX_MEM_INIT_QP
].size
= ctx
->qp_entry_size
;
6910 ctx
->mem_init
[BNXT_CTX_MEM_INIT_SRQ
].size
= ctx
->srq_entry_size
;
6911 ctx
->mem_init
[BNXT_CTX_MEM_INIT_CQ
].size
= ctx
->cq_entry_size
;
6912 ctx
->mem_init
[BNXT_CTX_MEM_INIT_VNIC
].size
= ctx
->vnic_entry_size
;
6913 ctx
->mem_init
[BNXT_CTX_MEM_INIT_STAT
].size
= ctx
->stat_entry_size
;
6914 ctx
->mem_init
[BNXT_CTX_MEM_INIT_MRAV
].size
= ctx
->mrav_entry_size
;
6917 static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt
*bp
)
6919 struct hwrm_func_backing_store_qcaps_input req
= {0};
6920 struct hwrm_func_backing_store_qcaps_output
*resp
=
6921 bp
->hwrm_cmd_resp_addr
;
6924 if (bp
->hwrm_spec_code
< 0x10902 || BNXT_VF(bp
) || bp
->ctx
)
6927 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_QCAPS
, -1, -1);
6928 mutex_lock(&bp
->hwrm_cmd_lock
);
6929 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6931 struct bnxt_ctx_pg_info
*ctx_pg
;
6932 struct bnxt_ctx_mem_info
*ctx
;
6935 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
6940 ctx
->qp_max_entries
= le32_to_cpu(resp
->qp_max_entries
);
6941 ctx
->qp_min_qp1_entries
= le16_to_cpu(resp
->qp_min_qp1_entries
);
6942 ctx
->qp_max_l2_entries
= le16_to_cpu(resp
->qp_max_l2_entries
);
6943 ctx
->qp_entry_size
= le16_to_cpu(resp
->qp_entry_size
);
6944 ctx
->srq_max_l2_entries
= le16_to_cpu(resp
->srq_max_l2_entries
);
6945 ctx
->srq_max_entries
= le32_to_cpu(resp
->srq_max_entries
);
6946 ctx
->srq_entry_size
= le16_to_cpu(resp
->srq_entry_size
);
6947 ctx
->cq_max_l2_entries
= le16_to_cpu(resp
->cq_max_l2_entries
);
6948 ctx
->cq_max_entries
= le32_to_cpu(resp
->cq_max_entries
);
6949 ctx
->cq_entry_size
= le16_to_cpu(resp
->cq_entry_size
);
6950 ctx
->vnic_max_vnic_entries
=
6951 le16_to_cpu(resp
->vnic_max_vnic_entries
);
6952 ctx
->vnic_max_ring_table_entries
=
6953 le16_to_cpu(resp
->vnic_max_ring_table_entries
);
6954 ctx
->vnic_entry_size
= le16_to_cpu(resp
->vnic_entry_size
);
6955 ctx
->stat_max_entries
= le32_to_cpu(resp
->stat_max_entries
);
6956 ctx
->stat_entry_size
= le16_to_cpu(resp
->stat_entry_size
);
6957 ctx
->tqm_entry_size
= le16_to_cpu(resp
->tqm_entry_size
);
6958 ctx
->tqm_min_entries_per_ring
=
6959 le32_to_cpu(resp
->tqm_min_entries_per_ring
);
6960 ctx
->tqm_max_entries_per_ring
=
6961 le32_to_cpu(resp
->tqm_max_entries_per_ring
);
6962 ctx
->tqm_entries_multiple
= resp
->tqm_entries_multiple
;
6963 if (!ctx
->tqm_entries_multiple
)
6964 ctx
->tqm_entries_multiple
= 1;
6965 ctx
->mrav_max_entries
= le32_to_cpu(resp
->mrav_max_entries
);
6966 ctx
->mrav_entry_size
= le16_to_cpu(resp
->mrav_entry_size
);
6967 ctx
->mrav_num_entries_units
=
6968 le16_to_cpu(resp
->mrav_num_entries_units
);
6969 ctx
->tim_entry_size
= le16_to_cpu(resp
->tim_entry_size
);
6970 ctx
->tim_max_entries
= le32_to_cpu(resp
->tim_max_entries
);
6972 bnxt_init_ctx_initializer(ctx
, resp
);
6974 ctx
->tqm_fp_rings_count
= resp
->tqm_fp_rings_count
;
6975 if (!ctx
->tqm_fp_rings_count
)
6976 ctx
->tqm_fp_rings_count
= bp
->max_q
;
6977 else if (ctx
->tqm_fp_rings_count
> BNXT_MAX_TQM_FP_RINGS
)
6978 ctx
->tqm_fp_rings_count
= BNXT_MAX_TQM_FP_RINGS
;
6980 tqm_rings
= ctx
->tqm_fp_rings_count
+ BNXT_MAX_TQM_SP_RINGS
;
6981 ctx_pg
= kcalloc(tqm_rings
, sizeof(*ctx_pg
), GFP_KERNEL
);
6987 for (i
= 0; i
< tqm_rings
; i
++, ctx_pg
++)
6988 ctx
->tqm_mem
[i
] = ctx_pg
;
6994 mutex_unlock(&bp
->hwrm_cmd_lock
);
6998 static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info
*rmem
, u8
*pg_attr
,
7001 if (!rmem
->nr_pages
)
7004 BNXT_SET_CTX_PAGE_ATTR(*pg_attr
);
7005 if (rmem
->depth
>= 1) {
7006 if (rmem
->depth
== 2)
7010 *pg_dir
= cpu_to_le64(rmem
->pg_tbl_map
);
7012 *pg_dir
= cpu_to_le64(rmem
->dma_arr
[0]);
7016 #define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \
7017 (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \
7018 FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \
7019 FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \
7020 FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \
7021 FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT)
7023 static int bnxt_hwrm_func_backing_store_cfg(struct bnxt
*bp
, u32 enables
)
7025 struct hwrm_func_backing_store_cfg_input req
= {0};
7026 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
7027 struct bnxt_ctx_pg_info
*ctx_pg
;
7028 u32 req_len
= sizeof(req
);
7029 __le32
*num_entries
;
7039 if (req_len
> bp
->hwrm_max_ext_req_len
)
7040 req_len
= BNXT_BACKING_STORE_CFG_LEGACY_LEN
;
7041 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_CFG
, -1, -1);
7042 req
.enables
= cpu_to_le32(enables
);
7044 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP
) {
7045 ctx_pg
= &ctx
->qp_mem
;
7046 req
.qp_num_entries
= cpu_to_le32(ctx_pg
->entries
);
7047 req
.qp_num_qp1_entries
= cpu_to_le16(ctx
->qp_min_qp1_entries
);
7048 req
.qp_num_l2_entries
= cpu_to_le16(ctx
->qp_max_l2_entries
);
7049 req
.qp_entry_size
= cpu_to_le16(ctx
->qp_entry_size
);
7050 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7051 &req
.qpc_pg_size_qpc_lvl
,
7054 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ
) {
7055 ctx_pg
= &ctx
->srq_mem
;
7056 req
.srq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
7057 req
.srq_num_l2_entries
= cpu_to_le16(ctx
->srq_max_l2_entries
);
7058 req
.srq_entry_size
= cpu_to_le16(ctx
->srq_entry_size
);
7059 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7060 &req
.srq_pg_size_srq_lvl
,
7063 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ
) {
7064 ctx_pg
= &ctx
->cq_mem
;
7065 req
.cq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
7066 req
.cq_num_l2_entries
= cpu_to_le16(ctx
->cq_max_l2_entries
);
7067 req
.cq_entry_size
= cpu_to_le16(ctx
->cq_entry_size
);
7068 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, &req
.cq_pg_size_cq_lvl
,
7071 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC
) {
7072 ctx_pg
= &ctx
->vnic_mem
;
7073 req
.vnic_num_vnic_entries
=
7074 cpu_to_le16(ctx
->vnic_max_vnic_entries
);
7075 req
.vnic_num_ring_table_entries
=
7076 cpu_to_le16(ctx
->vnic_max_ring_table_entries
);
7077 req
.vnic_entry_size
= cpu_to_le16(ctx
->vnic_entry_size
);
7078 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7079 &req
.vnic_pg_size_vnic_lvl
,
7080 &req
.vnic_page_dir
);
7082 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT
) {
7083 ctx_pg
= &ctx
->stat_mem
;
7084 req
.stat_num_entries
= cpu_to_le32(ctx
->stat_max_entries
);
7085 req
.stat_entry_size
= cpu_to_le16(ctx
->stat_entry_size
);
7086 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7087 &req
.stat_pg_size_stat_lvl
,
7088 &req
.stat_page_dir
);
7090 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
) {
7091 ctx_pg
= &ctx
->mrav_mem
;
7092 req
.mrav_num_entries
= cpu_to_le32(ctx_pg
->entries
);
7093 if (ctx
->mrav_num_entries_units
)
7095 FUNC_BACKING_STORE_CFG_REQ_FLAGS_MRAV_RESERVATION_SPLIT
;
7096 req
.mrav_entry_size
= cpu_to_le16(ctx
->mrav_entry_size
);
7097 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7098 &req
.mrav_pg_size_mrav_lvl
,
7099 &req
.mrav_page_dir
);
7101 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
) {
7102 ctx_pg
= &ctx
->tim_mem
;
7103 req
.tim_num_entries
= cpu_to_le32(ctx_pg
->entries
);
7104 req
.tim_entry_size
= cpu_to_le16(ctx
->tim_entry_size
);
7105 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
7106 &req
.tim_pg_size_tim_lvl
,
7109 for (i
= 0, num_entries
= &req
.tqm_sp_num_entries
,
7110 pg_attr
= &req
.tqm_sp_pg_size_tqm_sp_lvl
,
7111 pg_dir
= &req
.tqm_sp_page_dir
,
7112 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
;
7113 i
< BNXT_MAX_TQM_RINGS
;
7114 i
++, num_entries
++, pg_attr
++, pg_dir
++, ena
<<= 1) {
7115 if (!(enables
& ena
))
7118 req
.tqm_entry_size
= cpu_to_le16(ctx
->tqm_entry_size
);
7119 ctx_pg
= ctx
->tqm_mem
[i
];
7120 *num_entries
= cpu_to_le32(ctx_pg
->entries
);
7121 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, pg_attr
, pg_dir
);
7123 req
.flags
= cpu_to_le32(flags
);
7124 return hwrm_send_message(bp
, &req
, req_len
, HWRM_CMD_TIMEOUT
);
7127 static int bnxt_alloc_ctx_mem_blk(struct bnxt
*bp
,
7128 struct bnxt_ctx_pg_info
*ctx_pg
)
7130 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
7132 rmem
->page_size
= BNXT_PAGE_SIZE
;
7133 rmem
->pg_arr
= ctx_pg
->ctx_pg_arr
;
7134 rmem
->dma_arr
= ctx_pg
->ctx_dma_arr
;
7135 rmem
->flags
= BNXT_RMEM_VALID_PTE_FLAG
;
7136 if (rmem
->depth
>= 1)
7137 rmem
->flags
|= BNXT_RMEM_USE_FULL_PAGE_FLAG
;
7138 return bnxt_alloc_ring(bp
, rmem
);
7141 static int bnxt_alloc_ctx_pg_tbls(struct bnxt
*bp
,
7142 struct bnxt_ctx_pg_info
*ctx_pg
, u32 mem_size
,
7143 u8 depth
, struct bnxt_mem_init
*mem_init
)
7145 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
7151 ctx_pg
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
7152 if (ctx_pg
->nr_pages
> MAX_CTX_TOTAL_PAGES
) {
7153 ctx_pg
->nr_pages
= 0;
7156 if (ctx_pg
->nr_pages
> MAX_CTX_PAGES
|| depth
> 1) {
7160 ctx_pg
->ctx_pg_tbl
= kcalloc(MAX_CTX_PAGES
, sizeof(ctx_pg
),
7162 if (!ctx_pg
->ctx_pg_tbl
)
7164 nr_tbls
= DIV_ROUND_UP(ctx_pg
->nr_pages
, MAX_CTX_PAGES
);
7165 rmem
->nr_pages
= nr_tbls
;
7166 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
7169 for (i
= 0; i
< nr_tbls
; i
++) {
7170 struct bnxt_ctx_pg_info
*pg_tbl
;
7172 pg_tbl
= kzalloc(sizeof(*pg_tbl
), GFP_KERNEL
);
7175 ctx_pg
->ctx_pg_tbl
[i
] = pg_tbl
;
7176 rmem
= &pg_tbl
->ring_mem
;
7177 rmem
->pg_tbl
= ctx_pg
->ctx_pg_arr
[i
];
7178 rmem
->pg_tbl_map
= ctx_pg
->ctx_dma_arr
[i
];
7180 rmem
->nr_pages
= MAX_CTX_PAGES
;
7181 rmem
->mem_init
= mem_init
;
7182 if (i
== (nr_tbls
- 1)) {
7183 int rem
= ctx_pg
->nr_pages
% MAX_CTX_PAGES
;
7186 rmem
->nr_pages
= rem
;
7188 rc
= bnxt_alloc_ctx_mem_blk(bp
, pg_tbl
);
7193 rmem
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
7194 if (rmem
->nr_pages
> 1 || depth
)
7196 rmem
->mem_init
= mem_init
;
7197 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
7202 static void bnxt_free_ctx_pg_tbls(struct bnxt
*bp
,
7203 struct bnxt_ctx_pg_info
*ctx_pg
)
7205 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
7207 if (rmem
->depth
> 1 || ctx_pg
->nr_pages
> MAX_CTX_PAGES
||
7208 ctx_pg
->ctx_pg_tbl
) {
7209 int i
, nr_tbls
= rmem
->nr_pages
;
7211 for (i
= 0; i
< nr_tbls
; i
++) {
7212 struct bnxt_ctx_pg_info
*pg_tbl
;
7213 struct bnxt_ring_mem_info
*rmem2
;
7215 pg_tbl
= ctx_pg
->ctx_pg_tbl
[i
];
7218 rmem2
= &pg_tbl
->ring_mem
;
7219 bnxt_free_ring(bp
, rmem2
);
7220 ctx_pg
->ctx_pg_arr
[i
] = NULL
;
7222 ctx_pg
->ctx_pg_tbl
[i
] = NULL
;
7224 kfree(ctx_pg
->ctx_pg_tbl
);
7225 ctx_pg
->ctx_pg_tbl
= NULL
;
7227 bnxt_free_ring(bp
, rmem
);
7228 ctx_pg
->nr_pages
= 0;
7231 static void bnxt_free_ctx_mem(struct bnxt
*bp
)
7233 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
7239 if (ctx
->tqm_mem
[0]) {
7240 for (i
= 0; i
< ctx
->tqm_fp_rings_count
+ 1; i
++)
7241 bnxt_free_ctx_pg_tbls(bp
, ctx
->tqm_mem
[i
]);
7242 kfree(ctx
->tqm_mem
[0]);
7243 ctx
->tqm_mem
[0] = NULL
;
7246 bnxt_free_ctx_pg_tbls(bp
, &ctx
->tim_mem
);
7247 bnxt_free_ctx_pg_tbls(bp
, &ctx
->mrav_mem
);
7248 bnxt_free_ctx_pg_tbls(bp
, &ctx
->stat_mem
);
7249 bnxt_free_ctx_pg_tbls(bp
, &ctx
->vnic_mem
);
7250 bnxt_free_ctx_pg_tbls(bp
, &ctx
->cq_mem
);
7251 bnxt_free_ctx_pg_tbls(bp
, &ctx
->srq_mem
);
7252 bnxt_free_ctx_pg_tbls(bp
, &ctx
->qp_mem
);
7253 ctx
->flags
&= ~BNXT_CTX_FLAG_INITED
;
7256 static int bnxt_alloc_ctx_mem(struct bnxt
*bp
)
7258 struct bnxt_ctx_pg_info
*ctx_pg
;
7259 struct bnxt_ctx_mem_info
*ctx
;
7260 struct bnxt_mem_init
*init
;
7261 u32 mem_size
, ena
, entries
;
7262 u32 entries_sp
, min
;
7269 rc
= bnxt_hwrm_func_backing_store_qcaps(bp
);
7271 netdev_err(bp
->dev
, "Failed querying context mem capability, rc = %d.\n",
7276 if (!ctx
|| (ctx
->flags
& BNXT_CTX_FLAG_INITED
))
7279 if ((bp
->flags
& BNXT_FLAG_ROCE_CAP
) && !is_kdump_kernel()) {
7285 ctx_pg
= &ctx
->qp_mem
;
7286 ctx_pg
->entries
= ctx
->qp_min_qp1_entries
+ ctx
->qp_max_l2_entries
+
7288 if (ctx
->qp_entry_size
) {
7289 mem_size
= ctx
->qp_entry_size
* ctx_pg
->entries
;
7290 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_QP
];
7291 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
, init
);
7296 ctx_pg
= &ctx
->srq_mem
;
7297 ctx_pg
->entries
= ctx
->srq_max_l2_entries
+ extra_srqs
;
7298 if (ctx
->srq_entry_size
) {
7299 mem_size
= ctx
->srq_entry_size
* ctx_pg
->entries
;
7300 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_SRQ
];
7301 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
, init
);
7306 ctx_pg
= &ctx
->cq_mem
;
7307 ctx_pg
->entries
= ctx
->cq_max_l2_entries
+ extra_qps
* 2;
7308 if (ctx
->cq_entry_size
) {
7309 mem_size
= ctx
->cq_entry_size
* ctx_pg
->entries
;
7310 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_CQ
];
7311 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
, init
);
7316 ctx_pg
= &ctx
->vnic_mem
;
7317 ctx_pg
->entries
= ctx
->vnic_max_vnic_entries
+
7318 ctx
->vnic_max_ring_table_entries
;
7319 if (ctx
->vnic_entry_size
) {
7320 mem_size
= ctx
->vnic_entry_size
* ctx_pg
->entries
;
7321 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_VNIC
];
7322 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1, init
);
7327 ctx_pg
= &ctx
->stat_mem
;
7328 ctx_pg
->entries
= ctx
->stat_max_entries
;
7329 if (ctx
->stat_entry_size
) {
7330 mem_size
= ctx
->stat_entry_size
* ctx_pg
->entries
;
7331 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_STAT
];
7332 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1, init
);
7338 if (!(bp
->flags
& BNXT_FLAG_ROCE_CAP
))
7341 ctx_pg
= &ctx
->mrav_mem
;
7342 /* 128K extra is needed to accommodate static AH context
7343 * allocation by f/w.
7345 num_mr
= 1024 * 256;
7346 num_ah
= 1024 * 128;
7347 ctx_pg
->entries
= num_mr
+ num_ah
;
7348 if (ctx
->mrav_entry_size
) {
7349 mem_size
= ctx
->mrav_entry_size
* ctx_pg
->entries
;
7350 init
= &ctx
->mem_init
[BNXT_CTX_MEM_INIT_MRAV
];
7351 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 2, init
);
7355 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
;
7356 if (ctx
->mrav_num_entries_units
)
7358 ((num_mr
/ ctx
->mrav_num_entries_units
) << 16) |
7359 (num_ah
/ ctx
->mrav_num_entries_units
);
7361 ctx_pg
= &ctx
->tim_mem
;
7362 ctx_pg
->entries
= ctx
->qp_mem
.entries
;
7363 if (ctx
->tim_entry_size
) {
7364 mem_size
= ctx
->tim_entry_size
* ctx_pg
->entries
;
7365 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1, NULL
);
7369 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
;
7372 min
= ctx
->tqm_min_entries_per_ring
;
7373 entries_sp
= ctx
->vnic_max_vnic_entries
+ ctx
->qp_max_l2_entries
+
7374 2 * (extra_qps
+ ctx
->qp_min_qp1_entries
) + min
;
7375 entries_sp
= roundup(entries_sp
, ctx
->tqm_entries_multiple
);
7376 entries
= ctx
->qp_max_l2_entries
+ 2 * (extra_qps
+ ctx
->qp_min_qp1_entries
);
7377 entries
= roundup(entries
, ctx
->tqm_entries_multiple
);
7378 entries
= clamp_t(u32
, entries
, min
, ctx
->tqm_max_entries_per_ring
);
7379 for (i
= 0; i
< ctx
->tqm_fp_rings_count
+ 1; i
++) {
7380 ctx_pg
= ctx
->tqm_mem
[i
];
7381 ctx_pg
->entries
= i
? entries
: entries_sp
;
7382 if (ctx
->tqm_entry_size
) {
7383 mem_size
= ctx
->tqm_entry_size
* ctx_pg
->entries
;
7384 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1,
7389 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
<< i
;
7391 ena
|= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES
;
7392 rc
= bnxt_hwrm_func_backing_store_cfg(bp
, ena
);
7394 netdev_err(bp
->dev
, "Failed configuring context mem, rc = %d.\n",
7398 ctx
->flags
|= BNXT_CTX_FLAG_INITED
;
7402 int bnxt_hwrm_func_resc_qcaps(struct bnxt
*bp
, bool all
)
7404 struct hwrm_func_resource_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7405 struct hwrm_func_resource_qcaps_input req
= {0};
7406 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7409 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESOURCE_QCAPS
, -1, -1);
7410 req
.fid
= cpu_to_le16(0xffff);
7412 mutex_lock(&bp
->hwrm_cmd_lock
);
7413 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
),
7416 goto hwrm_func_resc_qcaps_exit
;
7418 hw_resc
->max_tx_sch_inputs
= le16_to_cpu(resp
->max_tx_scheduler_inputs
);
7420 goto hwrm_func_resc_qcaps_exit
;
7422 hw_resc
->min_rsscos_ctxs
= le16_to_cpu(resp
->min_rsscos_ctx
);
7423 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
7424 hw_resc
->min_cp_rings
= le16_to_cpu(resp
->min_cmpl_rings
);
7425 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
7426 hw_resc
->min_tx_rings
= le16_to_cpu(resp
->min_tx_rings
);
7427 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
7428 hw_resc
->min_rx_rings
= le16_to_cpu(resp
->min_rx_rings
);
7429 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
7430 hw_resc
->min_hw_ring_grps
= le16_to_cpu(resp
->min_hw_ring_grps
);
7431 hw_resc
->max_hw_ring_grps
= le16_to_cpu(resp
->max_hw_ring_grps
);
7432 hw_resc
->min_l2_ctxs
= le16_to_cpu(resp
->min_l2_ctxs
);
7433 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
7434 hw_resc
->min_vnics
= le16_to_cpu(resp
->min_vnics
);
7435 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
7436 hw_resc
->min_stat_ctxs
= le16_to_cpu(resp
->min_stat_ctx
);
7437 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
7439 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
7440 u16 max_msix
= le16_to_cpu(resp
->max_msix
);
7442 hw_resc
->max_nqs
= max_msix
;
7443 hw_resc
->max_hw_ring_grps
= hw_resc
->max_rx_rings
;
7447 struct bnxt_pf_info
*pf
= &bp
->pf
;
7449 pf
->vf_resv_strategy
=
7450 le16_to_cpu(resp
->vf_reservation_strategy
);
7451 if (pf
->vf_resv_strategy
> BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC
)
7452 pf
->vf_resv_strategy
= BNXT_VF_RESV_STRATEGY_MAXIMAL
;
7454 hwrm_func_resc_qcaps_exit
:
7455 mutex_unlock(&bp
->hwrm_cmd_lock
);
7459 /* bp->hwrm_cmd_lock already held. */
7460 static int __bnxt_hwrm_ptp_qcfg(struct bnxt
*bp
)
7462 struct hwrm_port_mac_ptp_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7463 struct hwrm_port_mac_ptp_qcfg_input req
= {0};
7464 struct bnxt_ptp_cfg
*ptp
= bp
->ptp_cfg
;
7468 if (bp
->hwrm_spec_code
< 0x10801) {
7473 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
7474 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_MAC_PTP_QCFG
, -1, -1);
7475 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7479 flags
= resp
->flags
;
7480 if (!(flags
& PORT_MAC_PTP_QCFG_RESP_FLAGS_HWRM_ACCESS
)) {
7485 ptp
= kzalloc(sizeof(*ptp
), GFP_KERNEL
);
7491 if (flags
& PORT_MAC_PTP_QCFG_RESP_FLAGS_PARTIAL_DIRECT_ACCESS_REF_CLOCK
) {
7492 ptp
->refclk_regs
[0] = le32_to_cpu(resp
->ts_ref_clock_reg_lower
);
7493 ptp
->refclk_regs
[1] = le32_to_cpu(resp
->ts_ref_clock_reg_upper
);
7494 } else if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
7495 ptp
->refclk_regs
[0] = BNXT_TS_REG_TIMESYNC_TS0_LOWER
;
7496 ptp
->refclk_regs
[1] = BNXT_TS_REG_TIMESYNC_TS0_UPPER
;
7509 static int __bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
7512 struct hwrm_func_qcaps_input req
= {0};
7513 struct hwrm_func_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7514 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7515 u32 flags
, flags_ext
;
7517 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCAPS
, -1, -1);
7518 req
.fid
= cpu_to_le16(0xffff);
7520 mutex_lock(&bp
->hwrm_cmd_lock
);
7521 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7523 goto hwrm_func_qcaps_exit
;
7525 flags
= le32_to_cpu(resp
->flags
);
7526 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED
)
7527 bp
->flags
|= BNXT_FLAG_ROCEV1_CAP
;
7528 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED
)
7529 bp
->flags
|= BNXT_FLAG_ROCEV2_CAP
;
7530 if (flags
& FUNC_QCAPS_RESP_FLAGS_PCIE_STATS_SUPPORTED
)
7531 bp
->fw_cap
|= BNXT_FW_CAP_PCIE_STATS_SUPPORTED
;
7532 if (flags
& FUNC_QCAPS_RESP_FLAGS_HOT_RESET_CAPABLE
)
7533 bp
->fw_cap
|= BNXT_FW_CAP_HOT_RESET
;
7534 if (flags
& FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED
)
7535 bp
->fw_cap
|= BNXT_FW_CAP_EXT_STATS_SUPPORTED
;
7536 if (flags
& FUNC_QCAPS_RESP_FLAGS_ERROR_RECOVERY_CAPABLE
)
7537 bp
->fw_cap
|= BNXT_FW_CAP_ERROR_RECOVERY
;
7538 if (flags
& FUNC_QCAPS_RESP_FLAGS_ERR_RECOVER_RELOAD
)
7539 bp
->fw_cap
|= BNXT_FW_CAP_ERR_RECOVER_RELOAD
;
7540 if (!(flags
& FUNC_QCAPS_RESP_FLAGS_VLAN_ACCELERATION_TX_DISABLED
))
7541 bp
->fw_cap
|= BNXT_FW_CAP_VLAN_TX_INSERT
;
7543 flags_ext
= le32_to_cpu(resp
->flags_ext
);
7544 if (flags_ext
& FUNC_QCAPS_RESP_FLAGS_EXT_EXT_HW_STATS_SUPPORTED
)
7545 bp
->fw_cap
|= BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED
;
7547 bp
->tx_push_thresh
= 0;
7548 if ((flags
& FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED
) &&
7549 BNXT_FW_MAJ(bp
) > 217)
7550 bp
->tx_push_thresh
= BNXT_TX_PUSH_THRESH
;
7552 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
7553 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
7554 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
7555 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
7556 hw_resc
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
7557 if (!hw_resc
->max_hw_ring_grps
)
7558 hw_resc
->max_hw_ring_grps
= hw_resc
->max_tx_rings
;
7559 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
7560 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
7561 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
7564 struct bnxt_pf_info
*pf
= &bp
->pf
;
7566 pf
->fw_fid
= le16_to_cpu(resp
->fid
);
7567 pf
->port_id
= le16_to_cpu(resp
->port_id
);
7568 memcpy(pf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
7569 pf
->first_vf_id
= le16_to_cpu(resp
->first_vf_id
);
7570 pf
->max_vfs
= le16_to_cpu(resp
->max_vfs
);
7571 pf
->max_encap_records
= le32_to_cpu(resp
->max_encap_records
);
7572 pf
->max_decap_records
= le32_to_cpu(resp
->max_decap_records
);
7573 pf
->max_tx_em_flows
= le32_to_cpu(resp
->max_tx_em_flows
);
7574 pf
->max_tx_wm_flows
= le32_to_cpu(resp
->max_tx_wm_flows
);
7575 pf
->max_rx_em_flows
= le32_to_cpu(resp
->max_rx_em_flows
);
7576 pf
->max_rx_wm_flows
= le32_to_cpu(resp
->max_rx_wm_flows
);
7577 bp
->flags
&= ~BNXT_FLAG_WOL_CAP
;
7578 if (flags
& FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED
)
7579 bp
->flags
|= BNXT_FLAG_WOL_CAP
;
7580 if (flags
& FUNC_QCAPS_RESP_FLAGS_PTP_SUPPORTED
) {
7581 __bnxt_hwrm_ptp_qcfg(bp
);
7587 #ifdef CONFIG_BNXT_SRIOV
7588 struct bnxt_vf_info
*vf
= &bp
->vf
;
7590 vf
->fw_fid
= le16_to_cpu(resp
->fid
);
7591 memcpy(vf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
7595 hwrm_func_qcaps_exit
:
7596 mutex_unlock(&bp
->hwrm_cmd_lock
);
7600 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
);
7602 static int bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
7606 rc
= __bnxt_hwrm_func_qcaps(bp
);
7609 rc
= bnxt_hwrm_queue_qportcfg(bp
);
7611 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %d\n", rc
);
7614 if (bp
->hwrm_spec_code
>= 0x10803) {
7615 rc
= bnxt_alloc_ctx_mem(bp
);
7618 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
7620 bp
->fw_cap
|= BNXT_FW_CAP_NEW_RM
;
7625 static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt
*bp
)
7627 struct hwrm_cfa_adv_flow_mgnt_qcaps_input req
= {0};
7628 struct hwrm_cfa_adv_flow_mgnt_qcaps_output
*resp
;
7632 if (!(bp
->fw_cap
& BNXT_FW_CAP_CFA_ADV_FLOW
))
7635 resp
= bp
->hwrm_cmd_resp_addr
;
7636 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_ADV_FLOW_MGNT_QCAPS
, -1, -1);
7638 mutex_lock(&bp
->hwrm_cmd_lock
);
7639 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7641 goto hwrm_cfa_adv_qcaps_exit
;
7643 flags
= le32_to_cpu(resp
->flags
);
7645 CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_V2_SUPPORTED
)
7646 bp
->fw_cap
|= BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2
;
7648 hwrm_cfa_adv_qcaps_exit
:
7649 mutex_unlock(&bp
->hwrm_cmd_lock
);
7653 static int __bnxt_alloc_fw_health(struct bnxt
*bp
)
7658 bp
->fw_health
= kzalloc(sizeof(*bp
->fw_health
), GFP_KERNEL
);
7665 static int bnxt_alloc_fw_health(struct bnxt
*bp
)
7669 if (!(bp
->fw_cap
& BNXT_FW_CAP_HOT_RESET
) &&
7670 !(bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
))
7673 rc
= __bnxt_alloc_fw_health(bp
);
7675 bp
->fw_cap
&= ~BNXT_FW_CAP_HOT_RESET
;
7676 bp
->fw_cap
&= ~BNXT_FW_CAP_ERROR_RECOVERY
;
7683 static void __bnxt_map_fw_health_reg(struct bnxt
*bp
, u32 reg
)
7685 writel(reg
& BNXT_GRC_BASE_MASK
, bp
->bar0
+
7686 BNXT_GRCPF_REG_WINDOW_BASE_OUT
+
7687 BNXT_FW_HEALTH_WIN_MAP_OFF
);
7690 bool bnxt_is_fw_healthy(struct bnxt
*bp
)
7692 if (bp
->fw_health
&& bp
->fw_health
->status_reliable
) {
7695 fw_status
= bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
);
7696 if (fw_status
&& !BNXT_FW_IS_HEALTHY(fw_status
))
7703 static void bnxt_inv_fw_health_reg(struct bnxt
*bp
)
7705 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
7708 if (!fw_health
|| !fw_health
->status_reliable
)
7711 reg_type
= BNXT_FW_HEALTH_REG_TYPE(fw_health
->regs
[BNXT_FW_HEALTH_REG
]);
7712 if (reg_type
== BNXT_FW_HEALTH_REG_TYPE_GRC
)
7713 fw_health
->status_reliable
= false;
7716 static void bnxt_try_map_fw_health_reg(struct bnxt
*bp
)
7724 bp
->fw_health
->status_reliable
= false;
7726 __bnxt_map_fw_health_reg(bp
, HCOMM_STATUS_STRUCT_LOC
);
7727 hs
= bp
->bar0
+ BNXT_FW_HEALTH_WIN_OFF(HCOMM_STATUS_STRUCT_LOC
);
7729 sig
= readl(hs
+ offsetof(struct hcomm_status
, sig_ver
));
7730 if ((sig
& HCOMM_STATUS_SIGNATURE_MASK
) != HCOMM_STATUS_SIGNATURE_VAL
) {
7731 if (!bp
->chip_num
) {
7732 __bnxt_map_fw_health_reg(bp
, BNXT_GRC_REG_BASE
);
7733 bp
->chip_num
= readl(bp
->bar0
+
7734 BNXT_FW_HEALTH_WIN_BASE
+
7735 BNXT_GRC_REG_CHIP_NUM
);
7737 if (!BNXT_CHIP_P5(bp
))
7740 status_loc
= BNXT_GRC_REG_STATUS_P5
|
7741 BNXT_FW_HEALTH_REG_TYPE_BAR0
;
7743 status_loc
= readl(hs
+ offsetof(struct hcomm_status
,
7747 if (__bnxt_alloc_fw_health(bp
)) {
7748 netdev_warn(bp
->dev
, "no memory for firmware status checks\n");
7752 bp
->fw_health
->regs
[BNXT_FW_HEALTH_REG
] = status_loc
;
7753 reg_type
= BNXT_FW_HEALTH_REG_TYPE(status_loc
);
7754 if (reg_type
== BNXT_FW_HEALTH_REG_TYPE_GRC
) {
7755 __bnxt_map_fw_health_reg(bp
, status_loc
);
7756 bp
->fw_health
->mapped_regs
[BNXT_FW_HEALTH_REG
] =
7757 BNXT_FW_HEALTH_WIN_OFF(status_loc
);
7760 bp
->fw_health
->status_reliable
= true;
7763 static int bnxt_map_fw_health_regs(struct bnxt
*bp
)
7765 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
7766 u32 reg_base
= 0xffffffff;
7769 bp
->fw_health
->status_reliable
= false;
7770 /* Only pre-map the monitoring GRC registers using window 3 */
7771 for (i
= 0; i
< 4; i
++) {
7772 u32 reg
= fw_health
->regs
[i
];
7774 if (BNXT_FW_HEALTH_REG_TYPE(reg
) != BNXT_FW_HEALTH_REG_TYPE_GRC
)
7776 if (reg_base
== 0xffffffff)
7777 reg_base
= reg
& BNXT_GRC_BASE_MASK
;
7778 if ((reg
& BNXT_GRC_BASE_MASK
) != reg_base
)
7780 fw_health
->mapped_regs
[i
] = BNXT_FW_HEALTH_WIN_OFF(reg
);
7782 bp
->fw_health
->status_reliable
= true;
7783 if (reg_base
== 0xffffffff)
7786 __bnxt_map_fw_health_reg(bp
, reg_base
);
7790 static int bnxt_hwrm_error_recovery_qcfg(struct bnxt
*bp
)
7792 struct hwrm_error_recovery_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7793 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
7794 struct hwrm_error_recovery_qcfg_input req
= {0};
7797 if (!(bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
))
7800 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_ERROR_RECOVERY_QCFG
, -1, -1);
7801 mutex_lock(&bp
->hwrm_cmd_lock
);
7802 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7804 goto err_recovery_out
;
7805 fw_health
->flags
= le32_to_cpu(resp
->flags
);
7806 if ((fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
) &&
7807 !(bp
->fw_cap
& BNXT_FW_CAP_KONG_MB_CHNL
)) {
7809 goto err_recovery_out
;
7811 fw_health
->polling_dsecs
= le32_to_cpu(resp
->driver_polling_freq
);
7812 fw_health
->master_func_wait_dsecs
=
7813 le32_to_cpu(resp
->master_func_wait_period
);
7814 fw_health
->normal_func_wait_dsecs
=
7815 le32_to_cpu(resp
->normal_func_wait_period
);
7816 fw_health
->post_reset_wait_dsecs
=
7817 le32_to_cpu(resp
->master_func_wait_period_after_reset
);
7818 fw_health
->post_reset_max_wait_dsecs
=
7819 le32_to_cpu(resp
->max_bailout_time_after_reset
);
7820 fw_health
->regs
[BNXT_FW_HEALTH_REG
] =
7821 le32_to_cpu(resp
->fw_health_status_reg
);
7822 fw_health
->regs
[BNXT_FW_HEARTBEAT_REG
] =
7823 le32_to_cpu(resp
->fw_heartbeat_reg
);
7824 fw_health
->regs
[BNXT_FW_RESET_CNT_REG
] =
7825 le32_to_cpu(resp
->fw_reset_cnt_reg
);
7826 fw_health
->regs
[BNXT_FW_RESET_INPROG_REG
] =
7827 le32_to_cpu(resp
->reset_inprogress_reg
);
7828 fw_health
->fw_reset_inprog_reg_mask
=
7829 le32_to_cpu(resp
->reset_inprogress_reg_mask
);
7830 fw_health
->fw_reset_seq_cnt
= resp
->reg_array_cnt
;
7831 if (fw_health
->fw_reset_seq_cnt
>= 16) {
7833 goto err_recovery_out
;
7835 for (i
= 0; i
< fw_health
->fw_reset_seq_cnt
; i
++) {
7836 fw_health
->fw_reset_seq_regs
[i
] =
7837 le32_to_cpu(resp
->reset_reg
[i
]);
7838 fw_health
->fw_reset_seq_vals
[i
] =
7839 le32_to_cpu(resp
->reset_reg_val
[i
]);
7840 fw_health
->fw_reset_seq_delay_msec
[i
] =
7841 resp
->delay_after_reset
[i
];
7844 mutex_unlock(&bp
->hwrm_cmd_lock
);
7846 rc
= bnxt_map_fw_health_regs(bp
);
7848 bp
->fw_cap
&= ~BNXT_FW_CAP_ERROR_RECOVERY
;
7852 static int bnxt_hwrm_func_reset(struct bnxt
*bp
)
7854 struct hwrm_func_reset_input req
= {0};
7856 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESET
, -1, -1);
7859 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_RESET_TIMEOUT
);
7862 static void bnxt_nvm_cfg_ver_get(struct bnxt
*bp
)
7864 struct hwrm_nvm_get_dev_info_output nvm_info
;
7866 if (!bnxt_hwrm_nvm_get_dev_info(bp
, &nvm_info
))
7867 snprintf(bp
->nvm_cfg_ver
, FW_VER_STR_LEN
, "%d.%d.%d",
7868 nvm_info
.nvm_cfg_ver_maj
, nvm_info
.nvm_cfg_ver_min
,
7869 nvm_info
.nvm_cfg_ver_upd
);
7872 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
)
7875 struct hwrm_queue_qportcfg_input req
= {0};
7876 struct hwrm_queue_qportcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7880 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_QUEUE_QPORTCFG
, -1, -1);
7882 mutex_lock(&bp
->hwrm_cmd_lock
);
7883 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7887 if (!resp
->max_configurable_queues
) {
7891 bp
->max_tc
= resp
->max_configurable_queues
;
7892 bp
->max_lltc
= resp
->max_configurable_lossless_queues
;
7893 if (bp
->max_tc
> BNXT_MAX_QUEUE
)
7894 bp
->max_tc
= BNXT_MAX_QUEUE
;
7896 no_rdma
= !(bp
->flags
& BNXT_FLAG_ROCE_CAP
);
7897 qptr
= &resp
->queue_id0
;
7898 for (i
= 0, j
= 0; i
< bp
->max_tc
; i
++) {
7899 bp
->q_info
[j
].queue_id
= *qptr
;
7900 bp
->q_ids
[i
] = *qptr
++;
7901 bp
->q_info
[j
].queue_profile
= *qptr
++;
7902 bp
->tc_to_qidx
[j
] = j
;
7903 if (!BNXT_CNPQ(bp
->q_info
[j
].queue_profile
) ||
7904 (no_rdma
&& BNXT_PF(bp
)))
7907 bp
->max_q
= bp
->max_tc
;
7908 bp
->max_tc
= max_t(u8
, j
, 1);
7910 if (resp
->queue_cfg_info
& QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG
)
7913 if (bp
->max_lltc
> bp
->max_tc
)
7914 bp
->max_lltc
= bp
->max_tc
;
7917 mutex_unlock(&bp
->hwrm_cmd_lock
);
7921 static int __bnxt_hwrm_ver_get(struct bnxt
*bp
, bool silent
)
7923 struct hwrm_ver_get_input req
= {0};
7926 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VER_GET
, -1, -1);
7927 req
.hwrm_intf_maj
= HWRM_VERSION_MAJOR
;
7928 req
.hwrm_intf_min
= HWRM_VERSION_MINOR
;
7929 req
.hwrm_intf_upd
= HWRM_VERSION_UPDATE
;
7931 rc
= bnxt_hwrm_do_send_msg(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
,
7936 static int bnxt_hwrm_ver_get(struct bnxt
*bp
)
7938 struct hwrm_ver_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7939 u16 fw_maj
, fw_min
, fw_bld
, fw_rsv
;
7940 u32 dev_caps_cfg
, hwrm_ver
;
7943 bp
->hwrm_max_req_len
= HWRM_MAX_REQ_LEN
;
7944 mutex_lock(&bp
->hwrm_cmd_lock
);
7945 rc
= __bnxt_hwrm_ver_get(bp
, false);
7947 goto hwrm_ver_get_exit
;
7949 memcpy(&bp
->ver_resp
, resp
, sizeof(struct hwrm_ver_get_output
));
7951 bp
->hwrm_spec_code
= resp
->hwrm_intf_maj_8b
<< 16 |
7952 resp
->hwrm_intf_min_8b
<< 8 |
7953 resp
->hwrm_intf_upd_8b
;
7954 if (resp
->hwrm_intf_maj_8b
< 1) {
7955 netdev_warn(bp
->dev
, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
7956 resp
->hwrm_intf_maj_8b
, resp
->hwrm_intf_min_8b
,
7957 resp
->hwrm_intf_upd_8b
);
7958 netdev_warn(bp
->dev
, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
7961 hwrm_ver
= HWRM_VERSION_MAJOR
<< 16 | HWRM_VERSION_MINOR
<< 8 |
7962 HWRM_VERSION_UPDATE
;
7964 if (bp
->hwrm_spec_code
> hwrm_ver
)
7965 snprintf(bp
->hwrm_ver_supp
, FW_VER_STR_LEN
, "%d.%d.%d",
7966 HWRM_VERSION_MAJOR
, HWRM_VERSION_MINOR
,
7967 HWRM_VERSION_UPDATE
);
7969 snprintf(bp
->hwrm_ver_supp
, FW_VER_STR_LEN
, "%d.%d.%d",
7970 resp
->hwrm_intf_maj_8b
, resp
->hwrm_intf_min_8b
,
7971 resp
->hwrm_intf_upd_8b
);
7973 fw_maj
= le16_to_cpu(resp
->hwrm_fw_major
);
7974 if (bp
->hwrm_spec_code
> 0x10803 && fw_maj
) {
7975 fw_min
= le16_to_cpu(resp
->hwrm_fw_minor
);
7976 fw_bld
= le16_to_cpu(resp
->hwrm_fw_build
);
7977 fw_rsv
= le16_to_cpu(resp
->hwrm_fw_patch
);
7978 len
= FW_VER_STR_LEN
;
7980 fw_maj
= resp
->hwrm_fw_maj_8b
;
7981 fw_min
= resp
->hwrm_fw_min_8b
;
7982 fw_bld
= resp
->hwrm_fw_bld_8b
;
7983 fw_rsv
= resp
->hwrm_fw_rsvd_8b
;
7984 len
= BC_HWRM_STR_LEN
;
7986 bp
->fw_ver_code
= BNXT_FW_VER_CODE(fw_maj
, fw_min
, fw_bld
, fw_rsv
);
7987 snprintf(bp
->fw_ver_str
, len
, "%d.%d.%d.%d", fw_maj
, fw_min
, fw_bld
,
7990 if (strlen(resp
->active_pkg_name
)) {
7991 int fw_ver_len
= strlen(bp
->fw_ver_str
);
7993 snprintf(bp
->fw_ver_str
+ fw_ver_len
,
7994 FW_VER_STR_LEN
- fw_ver_len
- 1, "/pkg %s",
7995 resp
->active_pkg_name
);
7996 bp
->fw_cap
|= BNXT_FW_CAP_PKG_VER
;
7999 bp
->hwrm_cmd_timeout
= le16_to_cpu(resp
->def_req_timeout
);
8000 if (!bp
->hwrm_cmd_timeout
)
8001 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
8003 if (resp
->hwrm_intf_maj_8b
>= 1) {
8004 bp
->hwrm_max_req_len
= le16_to_cpu(resp
->max_req_win_len
);
8005 bp
->hwrm_max_ext_req_len
= le16_to_cpu(resp
->max_ext_req_len
);
8007 if (bp
->hwrm_max_ext_req_len
< HWRM_MAX_REQ_LEN
)
8008 bp
->hwrm_max_ext_req_len
= HWRM_MAX_REQ_LEN
;
8010 bp
->chip_num
= le16_to_cpu(resp
->chip_num
);
8011 bp
->chip_rev
= resp
->chip_rev
;
8012 if (bp
->chip_num
== CHIP_NUM_58700
&& !resp
->chip_rev
&&
8014 bp
->flags
|= BNXT_FLAG_CHIP_NITRO_A0
;
8016 dev_caps_cfg
= le32_to_cpu(resp
->dev_caps_cfg
);
8017 if ((dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED
) &&
8018 (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED
))
8019 bp
->fw_cap
|= BNXT_FW_CAP_SHORT_CMD
;
8021 if (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED
)
8022 bp
->fw_cap
|= BNXT_FW_CAP_KONG_MB_CHNL
;
8025 VER_GET_RESP_DEV_CAPS_CFG_FLOW_HANDLE_64BIT_SUPPORTED
)
8026 bp
->fw_cap
|= BNXT_FW_CAP_OVS_64BIT_HANDLE
;
8029 VER_GET_RESP_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED
)
8030 bp
->fw_cap
|= BNXT_FW_CAP_TRUSTED_VF
;
8033 VER_GET_RESP_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED
)
8034 bp
->fw_cap
|= BNXT_FW_CAP_CFA_ADV_FLOW
;
8037 mutex_unlock(&bp
->hwrm_cmd_lock
);
8041 int bnxt_hwrm_fw_set_time(struct bnxt
*bp
)
8043 struct hwrm_fw_set_time_input req
= {0};
8045 time64_t now
= ktime_get_real_seconds();
8047 if ((BNXT_VF(bp
) && bp
->hwrm_spec_code
< 0x10901) ||
8048 bp
->hwrm_spec_code
< 0x10400)
8051 time64_to_tm(now
, 0, &tm
);
8052 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_SET_TIME
, -1, -1);
8053 req
.year
= cpu_to_le16(1900 + tm
.tm_year
);
8054 req
.month
= 1 + tm
.tm_mon
;
8055 req
.day
= tm
.tm_mday
;
8056 req
.hour
= tm
.tm_hour
;
8057 req
.minute
= tm
.tm_min
;
8058 req
.second
= tm
.tm_sec
;
8059 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8062 static void bnxt_add_one_ctr(u64 hw
, u64
*sw
, u64 mask
)
8067 sw_tmp
= (*sw
& ~mask
) | hw
;
8068 if (hw
< (*sw
& mask
))
8070 WRITE_ONCE(*sw
, sw_tmp
);
8073 static void __bnxt_accumulate_stats(__le64
*hw_stats
, u64
*sw_stats
, u64
*masks
,
8074 int count
, bool ignore_zero
)
8078 for (i
= 0; i
< count
; i
++) {
8079 u64 hw
= le64_to_cpu(READ_ONCE(hw_stats
[i
]));
8081 if (ignore_zero
&& !hw
)
8084 if (masks
[i
] == -1ULL)
8087 bnxt_add_one_ctr(hw
, &sw_stats
[i
], masks
[i
]);
8091 static void bnxt_accumulate_stats(struct bnxt_stats_mem
*stats
)
8093 if (!stats
->hw_stats
)
8096 __bnxt_accumulate_stats(stats
->hw_stats
, stats
->sw_stats
,
8097 stats
->hw_masks
, stats
->len
/ 8, false);
8100 static void bnxt_accumulate_all_stats(struct bnxt
*bp
)
8102 struct bnxt_stats_mem
*ring0_stats
;
8103 bool ignore_zero
= false;
8106 /* Chip bug. Counter intermittently becomes 0. */
8107 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8110 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8111 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
8112 struct bnxt_cp_ring_info
*cpr
;
8113 struct bnxt_stats_mem
*stats
;
8115 cpr
= &bnapi
->cp_ring
;
8116 stats
= &cpr
->stats
;
8118 ring0_stats
= stats
;
8119 __bnxt_accumulate_stats(stats
->hw_stats
, stats
->sw_stats
,
8120 ring0_stats
->hw_masks
,
8121 ring0_stats
->len
/ 8, ignore_zero
);
8123 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
8124 struct bnxt_stats_mem
*stats
= &bp
->port_stats
;
8125 __le64
*hw_stats
= stats
->hw_stats
;
8126 u64
*sw_stats
= stats
->sw_stats
;
8127 u64
*masks
= stats
->hw_masks
;
8130 cnt
= sizeof(struct rx_port_stats
) / 8;
8131 __bnxt_accumulate_stats(hw_stats
, sw_stats
, masks
, cnt
, false);
8133 hw_stats
+= BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
8134 sw_stats
+= BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
8135 masks
+= BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
8136 cnt
= sizeof(struct tx_port_stats
) / 8;
8137 __bnxt_accumulate_stats(hw_stats
, sw_stats
, masks
, cnt
, false);
8139 if (bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
) {
8140 bnxt_accumulate_stats(&bp
->rx_port_stats_ext
);
8141 bnxt_accumulate_stats(&bp
->tx_port_stats_ext
);
8145 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
, u8 flags
)
8147 struct bnxt_pf_info
*pf
= &bp
->pf
;
8148 struct hwrm_port_qstats_input req
= {0};
8150 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS
))
8153 if (flags
&& !(bp
->fw_cap
& BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED
))
8157 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS
, -1, -1);
8158 req
.port_id
= cpu_to_le16(pf
->port_id
);
8159 req
.tx_stat_host_addr
= cpu_to_le64(bp
->port_stats
.hw_stats_map
+
8160 BNXT_TX_PORT_STATS_BYTE_OFFSET
);
8161 req
.rx_stat_host_addr
= cpu_to_le64(bp
->port_stats
.hw_stats_map
);
8162 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8165 static int bnxt_hwrm_port_qstats_ext(struct bnxt
*bp
, u8 flags
)
8167 struct hwrm_port_qstats_ext_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8168 struct hwrm_queue_pri2cos_qcfg_input req2
= {0};
8169 struct hwrm_port_qstats_ext_input req
= {0};
8170 struct bnxt_pf_info
*pf
= &bp
->pf
;
8174 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
))
8177 if (flags
&& !(bp
->fw_cap
& BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED
))
8180 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS_EXT
, -1, -1);
8182 req
.port_id
= cpu_to_le16(pf
->port_id
);
8183 req
.rx_stat_size
= cpu_to_le16(sizeof(struct rx_port_stats_ext
));
8184 req
.rx_stat_host_addr
= cpu_to_le64(bp
->rx_port_stats_ext
.hw_stats_map
);
8185 tx_stat_size
= bp
->tx_port_stats_ext
.hw_stats
?
8186 sizeof(struct tx_port_stats_ext
) : 0;
8187 req
.tx_stat_size
= cpu_to_le16(tx_stat_size
);
8188 req
.tx_stat_host_addr
= cpu_to_le64(bp
->tx_port_stats_ext
.hw_stats_map
);
8189 mutex_lock(&bp
->hwrm_cmd_lock
);
8190 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8192 bp
->fw_rx_stats_ext_size
= le16_to_cpu(resp
->rx_stat_size
) / 8;
8193 bp
->fw_tx_stats_ext_size
= tx_stat_size
?
8194 le16_to_cpu(resp
->tx_stat_size
) / 8 : 0;
8196 bp
->fw_rx_stats_ext_size
= 0;
8197 bp
->fw_tx_stats_ext_size
= 0;
8202 if (bp
->fw_tx_stats_ext_size
<=
8203 offsetof(struct tx_port_stats_ext
, pfc_pri0_tx_duration_us
) / 8) {
8204 mutex_unlock(&bp
->hwrm_cmd_lock
);
8205 bp
->pri2cos_valid
= 0;
8209 bnxt_hwrm_cmd_hdr_init(bp
, &req2
, HWRM_QUEUE_PRI2COS_QCFG
, -1, -1);
8210 req2
.flags
= cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN
);
8212 rc
= _hwrm_send_message(bp
, &req2
, sizeof(req2
), HWRM_CMD_TIMEOUT
);
8214 struct hwrm_queue_pri2cos_qcfg_output
*resp2
;
8218 resp2
= bp
->hwrm_cmd_resp_addr
;
8219 pri2cos
= &resp2
->pri0_cos_queue_id
;
8220 for (i
= 0; i
< 8; i
++) {
8221 u8 queue_id
= pri2cos
[i
];
8224 /* Per port queue IDs start from 0, 10, 20, etc */
8225 queue_idx
= queue_id
% 10;
8226 if (queue_idx
> BNXT_MAX_QUEUE
) {
8227 bp
->pri2cos_valid
= false;
8230 for (j
= 0; j
< bp
->max_q
; j
++) {
8231 if (bp
->q_ids
[j
] == queue_id
)
8232 bp
->pri2cos_idx
[i
] = queue_idx
;
8235 bp
->pri2cos_valid
= 1;
8238 mutex_unlock(&bp
->hwrm_cmd_lock
);
8242 static void bnxt_hwrm_free_tunnel_ports(struct bnxt
*bp
)
8244 if (bp
->vxlan_fw_dst_port_id
!= INVALID_HW_RING_ID
)
8245 bnxt_hwrm_tunnel_dst_port_free(
8246 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
8247 if (bp
->nge_fw_dst_port_id
!= INVALID_HW_RING_ID
)
8248 bnxt_hwrm_tunnel_dst_port_free(
8249 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
8252 static int bnxt_set_tpa(struct bnxt
*bp
, bool set_tpa
)
8258 tpa_flags
= bp
->flags
& BNXT_FLAG_TPA
;
8259 else if (BNXT_NO_FW_ACCESS(bp
))
8261 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
8262 rc
= bnxt_hwrm_vnic_set_tpa(bp
, i
, tpa_flags
);
8264 netdev_err(bp
->dev
, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
8272 static void bnxt_hwrm_clear_vnic_rss(struct bnxt
*bp
)
8276 for (i
= 0; i
< bp
->nr_vnics
; i
++)
8277 bnxt_hwrm_vnic_set_rss(bp
, i
, false);
8280 static void bnxt_clear_vnic(struct bnxt
*bp
)
8285 bnxt_hwrm_clear_vnic_filter(bp
);
8286 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
)) {
8287 /* clear all RSS setting before free vnic ctx */
8288 bnxt_hwrm_clear_vnic_rss(bp
);
8289 bnxt_hwrm_vnic_ctx_free(bp
);
8291 /* before free the vnic, undo the vnic tpa settings */
8292 if (bp
->flags
& BNXT_FLAG_TPA
)
8293 bnxt_set_tpa(bp
, false);
8294 bnxt_hwrm_vnic_free(bp
);
8295 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8296 bnxt_hwrm_vnic_ctx_free(bp
);
8299 static void bnxt_hwrm_resource_free(struct bnxt
*bp
, bool close_path
,
8302 bnxt_clear_vnic(bp
);
8303 bnxt_hwrm_ring_free(bp
, close_path
);
8304 bnxt_hwrm_ring_grp_free(bp
);
8306 bnxt_hwrm_stat_ctx_free(bp
);
8307 bnxt_hwrm_free_tunnel_ports(bp
);
8311 static int bnxt_hwrm_set_br_mode(struct bnxt
*bp
, u16 br_mode
)
8313 struct hwrm_func_cfg_input req
= {0};
8315 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
8316 req
.fid
= cpu_to_le16(0xffff);
8317 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE
);
8318 if (br_mode
== BRIDGE_MODE_VEB
)
8319 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEB
;
8320 else if (br_mode
== BRIDGE_MODE_VEPA
)
8321 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEPA
;
8324 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8327 static int bnxt_hwrm_set_cache_line_size(struct bnxt
*bp
, int size
)
8329 struct hwrm_func_cfg_input req
= {0};
8331 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10803)
8334 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
8335 req
.fid
= cpu_to_le16(0xffff);
8336 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE
);
8337 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64
;
8339 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128
;
8341 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8344 static int __bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
8346 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
8349 if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
)
8352 /* allocate context for vnic */
8353 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 0);
8355 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
8357 goto vnic_setup_err
;
8359 bp
->rsscos_nr_ctxs
++;
8361 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
8362 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 1);
8364 netdev_err(bp
->dev
, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
8366 goto vnic_setup_err
;
8368 bp
->rsscos_nr_ctxs
++;
8372 /* configure default vnic, ring grp */
8373 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
8375 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
8377 goto vnic_setup_err
;
8380 /* Enable RSS hashing on vnic */
8381 rc
= bnxt_hwrm_vnic_set_rss(bp
, vnic_id
, true);
8383 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %x\n",
8385 goto vnic_setup_err
;
8388 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
8389 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
8391 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
8400 static int __bnxt_setup_vnic_p5(struct bnxt
*bp
, u16 vnic_id
)
8404 nr_ctxs
= bnxt_get_nr_rss_ctxs(bp
, bp
->rx_nr_rings
);
8405 for (i
= 0; i
< nr_ctxs
; i
++) {
8406 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, i
);
8408 netdev_err(bp
->dev
, "hwrm vnic %d ctx %d alloc failure rc: %x\n",
8412 bp
->rsscos_nr_ctxs
++;
8417 rc
= bnxt_hwrm_vnic_set_rss_p5(bp
, vnic_id
, true);
8419 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %d\n",
8423 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
8425 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
8429 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
8430 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
8432 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
8439 static int bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
8441 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8442 return __bnxt_setup_vnic_p5(bp
, vnic_id
);
8444 return __bnxt_setup_vnic(bp
, vnic_id
);
8447 static int bnxt_alloc_rfs_vnics(struct bnxt
*bp
)
8449 #ifdef CONFIG_RFS_ACCEL
8452 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8455 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
8456 struct bnxt_vnic_info
*vnic
;
8457 u16 vnic_id
= i
+ 1;
8460 if (vnic_id
>= bp
->nr_vnics
)
8463 vnic
= &bp
->vnic_info
[vnic_id
];
8464 vnic
->flags
|= BNXT_VNIC_RFS_FLAG
;
8465 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
8466 vnic
->flags
|= BNXT_VNIC_RFS_NEW_RSS_FLAG
;
8467 rc
= bnxt_hwrm_vnic_alloc(bp
, vnic_id
, ring_id
, 1);
8469 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
8473 rc
= bnxt_setup_vnic(bp
, vnic_id
);
8483 /* Allow PF, trusted VFs and VFs with default VLAN to be in promiscuous mode */
8484 static bool bnxt_promisc_ok(struct bnxt
*bp
)
8486 #ifdef CONFIG_BNXT_SRIOV
8487 if (BNXT_VF(bp
) && !bp
->vf
.vlan
&& !bnxt_is_trusted_vf(bp
, &bp
->vf
))
8493 static int bnxt_setup_nitroa0_vnic(struct bnxt
*bp
)
8495 unsigned int rc
= 0;
8497 rc
= bnxt_hwrm_vnic_alloc(bp
, 1, bp
->rx_nr_rings
- 1, 1);
8499 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
8504 rc
= bnxt_hwrm_vnic_cfg(bp
, 1);
8506 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
8513 static int bnxt_cfg_rx_mode(struct bnxt
*);
8514 static bool bnxt_mc_list_updated(struct bnxt
*, u32
*);
8516 static int bnxt_init_chip(struct bnxt
*bp
, bool irq_re_init
)
8518 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8520 unsigned int rx_nr_rings
= bp
->rx_nr_rings
;
8523 rc
= bnxt_hwrm_stat_ctx_alloc(bp
);
8525 netdev_err(bp
->dev
, "hwrm stat ctx alloc failure rc: %x\n",
8531 rc
= bnxt_hwrm_ring_alloc(bp
);
8533 netdev_err(bp
->dev
, "hwrm ring alloc failure rc: %x\n", rc
);
8537 rc
= bnxt_hwrm_ring_grp_alloc(bp
);
8539 netdev_err(bp
->dev
, "hwrm_ring_grp alloc failure: %x\n", rc
);
8543 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
8546 /* default vnic 0 */
8547 rc
= bnxt_hwrm_vnic_alloc(bp
, 0, 0, rx_nr_rings
);
8549 netdev_err(bp
->dev
, "hwrm vnic alloc failure rc: %x\n", rc
);
8553 rc
= bnxt_setup_vnic(bp
, 0);
8557 if (bp
->flags
& BNXT_FLAG_RFS
) {
8558 rc
= bnxt_alloc_rfs_vnics(bp
);
8563 if (bp
->flags
& BNXT_FLAG_TPA
) {
8564 rc
= bnxt_set_tpa(bp
, true);
8570 bnxt_update_vf_mac(bp
);
8572 /* Filter for default vnic 0 */
8573 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, 0, bp
->dev
->dev_addr
);
8575 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n", rc
);
8578 vnic
->uc_filter_count
= 1;
8581 if (bp
->dev
->flags
& IFF_BROADCAST
)
8582 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
8584 if (bp
->dev
->flags
& IFF_PROMISC
)
8585 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
8587 if (bp
->dev
->flags
& IFF_ALLMULTI
) {
8588 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
8589 vnic
->mc_list_count
= 0;
8593 bnxt_mc_list_updated(bp
, &mask
);
8594 vnic
->rx_mask
|= mask
;
8597 rc
= bnxt_cfg_rx_mode(bp
);
8601 rc
= bnxt_hwrm_set_coal(bp
);
8603 netdev_warn(bp
->dev
, "HWRM set coalescing failure rc: %x\n",
8606 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
8607 rc
= bnxt_setup_nitroa0_vnic(bp
);
8609 netdev_err(bp
->dev
, "Special vnic setup failure for NS2 A0 rc: %x\n",
8614 bnxt_hwrm_func_qcfg(bp
);
8615 netdev_update_features(bp
->dev
);
8621 bnxt_hwrm_resource_free(bp
, 0, true);
8626 static int bnxt_shutdown_nic(struct bnxt
*bp
, bool irq_re_init
)
8628 bnxt_hwrm_resource_free(bp
, 1, irq_re_init
);
8632 static int bnxt_init_nic(struct bnxt
*bp
, bool irq_re_init
)
8634 bnxt_init_cp_rings(bp
);
8635 bnxt_init_rx_rings(bp
);
8636 bnxt_init_tx_rings(bp
);
8637 bnxt_init_ring_grps(bp
, irq_re_init
);
8638 bnxt_init_vnics(bp
);
8640 return bnxt_init_chip(bp
, irq_re_init
);
8643 static int bnxt_set_real_num_queues(struct bnxt
*bp
)
8646 struct net_device
*dev
= bp
->dev
;
8648 rc
= netif_set_real_num_tx_queues(dev
, bp
->tx_nr_rings
-
8649 bp
->tx_nr_rings_xdp
);
8653 rc
= netif_set_real_num_rx_queues(dev
, bp
->rx_nr_rings
);
8657 #ifdef CONFIG_RFS_ACCEL
8658 if (bp
->flags
& BNXT_FLAG_RFS
)
8659 dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(bp
->rx_nr_rings
);
8665 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
8668 int _rx
= *rx
, _tx
= *tx
;
8671 *rx
= min_t(int, _rx
, max
);
8672 *tx
= min_t(int, _tx
, max
);
8677 while (_rx
+ _tx
> max
) {
8678 if (_rx
> _tx
&& _rx
> 1)
8689 static void bnxt_setup_msix(struct bnxt
*bp
)
8691 const int len
= sizeof(bp
->irq_tbl
[0].name
);
8692 struct net_device
*dev
= bp
->dev
;
8695 tcs
= netdev_get_num_tc(dev
);
8699 for (i
= 0; i
< tcs
; i
++) {
8700 count
= bp
->tx_nr_rings_per_tc
;
8702 netdev_set_tc_queue(dev
, i
, count
, off
);
8706 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8707 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
8710 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
8712 else if (i
< bp
->rx_nr_rings
)
8717 snprintf(bp
->irq_tbl
[map_idx
].name
, len
, "%s-%s-%d", dev
->name
,
8719 bp
->irq_tbl
[map_idx
].handler
= bnxt_msix
;
8723 static void bnxt_setup_inta(struct bnxt
*bp
)
8725 const int len
= sizeof(bp
->irq_tbl
[0].name
);
8727 if (netdev_get_num_tc(bp
->dev
))
8728 netdev_reset_tc(bp
->dev
);
8730 snprintf(bp
->irq_tbl
[0].name
, len
, "%s-%s-%d", bp
->dev
->name
, "TxRx",
8732 bp
->irq_tbl
[0].handler
= bnxt_inta
;
8735 static int bnxt_init_int_mode(struct bnxt
*bp
);
8737 static int bnxt_setup_int_mode(struct bnxt
*bp
)
8742 rc
= bnxt_init_int_mode(bp
);
8743 if (rc
|| !bp
->irq_tbl
)
8744 return rc
?: -ENODEV
;
8747 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
8748 bnxt_setup_msix(bp
);
8750 bnxt_setup_inta(bp
);
8752 rc
= bnxt_set_real_num_queues(bp
);
8756 #ifdef CONFIG_RFS_ACCEL
8757 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt
*bp
)
8759 return bp
->hw_resc
.max_rsscos_ctxs
;
8762 static unsigned int bnxt_get_max_func_vnics(struct bnxt
*bp
)
8764 return bp
->hw_resc
.max_vnics
;
8768 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt
*bp
)
8770 return bp
->hw_resc
.max_stat_ctxs
;
8773 unsigned int bnxt_get_max_func_cp_rings(struct bnxt
*bp
)
8775 return bp
->hw_resc
.max_cp_rings
;
8778 static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt
*bp
)
8780 unsigned int cp
= bp
->hw_resc
.max_cp_rings
;
8782 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
8783 cp
-= bnxt_get_ulp_msix_num(bp
);
8788 static unsigned int bnxt_get_max_func_irqs(struct bnxt
*bp
)
8790 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
8792 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8793 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_nqs
);
8795 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_cp_rings
);
8798 static void bnxt_set_max_func_irqs(struct bnxt
*bp
, unsigned int max_irqs
)
8800 bp
->hw_resc
.max_irqs
= max_irqs
;
8803 unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt
*bp
)
8807 cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
8808 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8809 return cp
- bp
->rx_nr_rings
- bp
->tx_nr_rings
;
8811 return cp
- bp
->cp_nr_rings
;
8814 unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt
*bp
)
8816 return bnxt_get_max_func_stat_ctxs(bp
) - bnxt_get_func_stat_ctxs(bp
);
8819 int bnxt_get_avail_msix(struct bnxt
*bp
, int num
)
8821 int max_cp
= bnxt_get_max_func_cp_rings(bp
);
8822 int max_irq
= bnxt_get_max_func_irqs(bp
);
8823 int total_req
= bp
->cp_nr_rings
+ num
;
8824 int max_idx
, avail_msix
;
8826 max_idx
= bp
->total_irqs
;
8827 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
8828 max_idx
= min_t(int, bp
->total_irqs
, max_cp
);
8829 avail_msix
= max_idx
- bp
->cp_nr_rings
;
8830 if (!BNXT_NEW_RM(bp
) || avail_msix
>= num
)
8833 if (max_irq
< total_req
) {
8834 num
= max_irq
- bp
->cp_nr_rings
;
8841 static int bnxt_get_num_msix(struct bnxt
*bp
)
8843 if (!BNXT_NEW_RM(bp
))
8844 return bnxt_get_max_func_irqs(bp
);
8846 return bnxt_nq_rings_in_use(bp
);
8849 static int bnxt_init_msix(struct bnxt
*bp
)
8851 int i
, total_vecs
, max
, rc
= 0, min
= 1, ulp_msix
;
8852 struct msix_entry
*msix_ent
;
8854 total_vecs
= bnxt_get_num_msix(bp
);
8855 max
= bnxt_get_max_func_irqs(bp
);
8856 if (total_vecs
> max
)
8862 msix_ent
= kcalloc(total_vecs
, sizeof(struct msix_entry
), GFP_KERNEL
);
8866 for (i
= 0; i
< total_vecs
; i
++) {
8867 msix_ent
[i
].entry
= i
;
8868 msix_ent
[i
].vector
= 0;
8871 if (!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
))
8874 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
, min
, total_vecs
);
8875 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
8876 if (total_vecs
< 0 || total_vecs
< ulp_msix
) {
8878 goto msix_setup_exit
;
8881 bp
->irq_tbl
= kcalloc(total_vecs
, sizeof(struct bnxt_irq
), GFP_KERNEL
);
8883 for (i
= 0; i
< total_vecs
; i
++)
8884 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
8886 bp
->total_irqs
= total_vecs
;
8887 /* Trim rings based upon num of vectors allocated */
8888 rc
= bnxt_trim_rings(bp
, &bp
->rx_nr_rings
, &bp
->tx_nr_rings
,
8889 total_vecs
- ulp_msix
, min
== 1);
8891 goto msix_setup_exit
;
8893 bp
->cp_nr_rings
= (min
== 1) ?
8894 max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
8895 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
8899 goto msix_setup_exit
;
8901 bp
->flags
|= BNXT_FLAG_USING_MSIX
;
8906 netdev_err(bp
->dev
, "bnxt_init_msix err: %x\n", rc
);
8909 pci_disable_msix(bp
->pdev
);
8914 static int bnxt_init_inta(struct bnxt
*bp
)
8916 bp
->irq_tbl
= kzalloc(sizeof(struct bnxt_irq
), GFP_KERNEL
);
8921 bp
->rx_nr_rings
= 1;
8922 bp
->tx_nr_rings
= 1;
8923 bp
->cp_nr_rings
= 1;
8924 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
8925 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
8929 static int bnxt_init_int_mode(struct bnxt
*bp
)
8933 if (bp
->flags
& BNXT_FLAG_MSIX_CAP
)
8934 rc
= bnxt_init_msix(bp
);
8936 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
) && BNXT_PF(bp
)) {
8937 /* fallback to INTA */
8938 rc
= bnxt_init_inta(bp
);
8943 static void bnxt_clear_int_mode(struct bnxt
*bp
)
8945 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
8946 pci_disable_msix(bp
->pdev
);
8950 bp
->flags
&= ~BNXT_FLAG_USING_MSIX
;
8953 int bnxt_reserve_rings(struct bnxt
*bp
, bool irq_re_init
)
8955 int tcs
= netdev_get_num_tc(bp
->dev
);
8956 bool irq_cleared
= false;
8959 if (!bnxt_need_reserve_rings(bp
))
8962 if (irq_re_init
&& BNXT_NEW_RM(bp
) &&
8963 bnxt_get_num_msix(bp
) != bp
->total_irqs
) {
8964 bnxt_ulp_irq_stop(bp
);
8965 bnxt_clear_int_mode(bp
);
8968 rc
= __bnxt_reserve_rings(bp
);
8971 rc
= bnxt_init_int_mode(bp
);
8972 bnxt_ulp_irq_restart(bp
, rc
);
8975 netdev_err(bp
->dev
, "ring reservation/IRQ init failure rc: %d\n", rc
);
8978 if (tcs
&& (bp
->tx_nr_rings_per_tc
* tcs
!= bp
->tx_nr_rings
)) {
8979 netdev_err(bp
->dev
, "tx ring reservation failure\n");
8980 netdev_reset_tc(bp
->dev
);
8981 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
8987 static void bnxt_free_irq(struct bnxt
*bp
)
8989 struct bnxt_irq
*irq
;
8992 #ifdef CONFIG_RFS_ACCEL
8993 free_irq_cpu_rmap(bp
->dev
->rx_cpu_rmap
);
8994 bp
->dev
->rx_cpu_rmap
= NULL
;
8996 if (!bp
->irq_tbl
|| !bp
->bnapi
)
8999 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9000 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
9002 irq
= &bp
->irq_tbl
[map_idx
];
9003 if (irq
->requested
) {
9004 if (irq
->have_cpumask
) {
9005 irq_set_affinity_hint(irq
->vector
, NULL
);
9006 free_cpumask_var(irq
->cpu_mask
);
9007 irq
->have_cpumask
= 0;
9009 free_irq(irq
->vector
, bp
->bnapi
[i
]);
9016 static int bnxt_request_irq(struct bnxt
*bp
)
9019 unsigned long flags
= 0;
9020 #ifdef CONFIG_RFS_ACCEL
9021 struct cpu_rmap
*rmap
;
9024 rc
= bnxt_setup_int_mode(bp
);
9026 netdev_err(bp
->dev
, "bnxt_setup_int_mode err: %x\n",
9030 #ifdef CONFIG_RFS_ACCEL
9031 rmap
= bp
->dev
->rx_cpu_rmap
;
9033 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
))
9034 flags
= IRQF_SHARED
;
9036 for (i
= 0, j
= 0; i
< bp
->cp_nr_rings
; i
++) {
9037 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
9038 struct bnxt_irq
*irq
= &bp
->irq_tbl
[map_idx
];
9040 #ifdef CONFIG_RFS_ACCEL
9041 if (rmap
&& bp
->bnapi
[i
]->rx_ring
) {
9042 rc
= irq_cpu_rmap_add(rmap
, irq
->vector
);
9044 netdev_warn(bp
->dev
, "failed adding irq rmap for ring %d\n",
9049 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
9056 if (zalloc_cpumask_var(&irq
->cpu_mask
, GFP_KERNEL
)) {
9057 int numa_node
= dev_to_node(&bp
->pdev
->dev
);
9059 irq
->have_cpumask
= 1;
9060 cpumask_set_cpu(cpumask_local_spread(i
, numa_node
),
9062 rc
= irq_set_affinity_hint(irq
->vector
, irq
->cpu_mask
);
9064 netdev_warn(bp
->dev
,
9065 "Set affinity failed, IRQ = %d\n",
9074 static void bnxt_del_napi(struct bnxt
*bp
)
9081 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9082 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
9084 __netif_napi_del(&bnapi
->napi
);
9086 /* We called __netif_napi_del(), we need
9087 * to respect an RCU grace period before freeing napi structures.
9092 static void bnxt_init_napi(struct bnxt
*bp
)
9095 unsigned int cp_nr_rings
= bp
->cp_nr_rings
;
9096 struct bnxt_napi
*bnapi
;
9098 if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
9099 int (*poll_fn
)(struct napi_struct
*, int) = bnxt_poll
;
9101 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
9102 poll_fn
= bnxt_poll_p5
;
9103 else if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
9105 for (i
= 0; i
< cp_nr_rings
; i
++) {
9106 bnapi
= bp
->bnapi
[i
];
9107 netif_napi_add(bp
->dev
, &bnapi
->napi
, poll_fn
, 64);
9109 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
9110 bnapi
= bp
->bnapi
[cp_nr_rings
];
9111 netif_napi_add(bp
->dev
, &bnapi
->napi
,
9112 bnxt_poll_nitroa0
, 64);
9115 bnapi
= bp
->bnapi
[0];
9116 netif_napi_add(bp
->dev
, &bnapi
->napi
, bnxt_poll
, 64);
9120 static void bnxt_disable_napi(struct bnxt
*bp
)
9125 test_and_set_bit(BNXT_STATE_NAPI_DISABLED
, &bp
->state
))
9128 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9129 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
9131 if (bp
->bnapi
[i
]->rx_ring
)
9132 cancel_work_sync(&cpr
->dim
.work
);
9134 napi_disable(&bp
->bnapi
[i
]->napi
);
9138 static void bnxt_enable_napi(struct bnxt
*bp
)
9142 clear_bit(BNXT_STATE_NAPI_DISABLED
, &bp
->state
);
9143 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9144 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
9145 struct bnxt_cp_ring_info
*cpr
;
9147 cpr
= &bnapi
->cp_ring
;
9148 if (bnapi
->in_reset
)
9149 cpr
->sw_stats
.rx
.rx_resets
++;
9150 bnapi
->in_reset
= false;
9152 if (bnapi
->rx_ring
) {
9153 INIT_WORK(&cpr
->dim
.work
, bnxt_dim_work
);
9154 cpr
->dim
.mode
= DIM_CQ_PERIOD_MODE_START_FROM_EQE
;
9156 napi_enable(&bnapi
->napi
);
9160 void bnxt_tx_disable(struct bnxt
*bp
)
9163 struct bnxt_tx_ring_info
*txr
;
9166 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
9167 txr
= &bp
->tx_ring
[i
];
9168 txr
->dev_state
= BNXT_DEV_STATE_CLOSING
;
9171 /* Drop carrier first to prevent TX timeout */
9172 netif_carrier_off(bp
->dev
);
9173 /* Stop all TX queues */
9174 netif_tx_disable(bp
->dev
);
9177 void bnxt_tx_enable(struct bnxt
*bp
)
9180 struct bnxt_tx_ring_info
*txr
;
9182 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
9183 txr
= &bp
->tx_ring
[i
];
9186 netif_tx_wake_all_queues(bp
->dev
);
9187 if (bp
->link_info
.link_up
)
9188 netif_carrier_on(bp
->dev
);
9191 static char *bnxt_report_fec(struct bnxt_link_info
*link_info
)
9193 u8 active_fec
= link_info
->active_fec_sig_mode
&
9194 PORT_PHY_QCFG_RESP_ACTIVE_FEC_MASK
;
9196 switch (active_fec
) {
9198 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_NONE_ACTIVE
:
9200 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE74_ACTIVE
:
9201 return "Clause 74 BaseR";
9202 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE91_ACTIVE
:
9203 return "Clause 91 RS(528,514)";
9204 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_1XN_ACTIVE
:
9205 return "Clause 91 RS544_1XN";
9206 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_IEEE_ACTIVE
:
9207 return "Clause 91 RS(544,514)";
9208 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_1XN_ACTIVE
:
9209 return "Clause 91 RS272_1XN";
9210 case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_IEEE_ACTIVE
:
9211 return "Clause 91 RS(272,257)";
9215 static void bnxt_report_link(struct bnxt
*bp
)
9217 if (bp
->link_info
.link_up
) {
9218 const char *signal
= "";
9219 const char *flow_ctrl
;
9224 netif_carrier_on(bp
->dev
);
9225 speed
= bnxt_fw_to_ethtool_speed(bp
->link_info
.link_speed
);
9226 if (speed
== SPEED_UNKNOWN
) {
9227 netdev_info(bp
->dev
, "NIC Link is Up, speed unknown\n");
9230 if (bp
->link_info
.duplex
== BNXT_LINK_DUPLEX_FULL
)
9234 if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_BOTH
)
9235 flow_ctrl
= "ON - receive & transmit";
9236 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_TX
)
9237 flow_ctrl
= "ON - transmit";
9238 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_RX
)
9239 flow_ctrl
= "ON - receive";
9242 if (bp
->link_info
.phy_qcfg_resp
.option_flags
&
9243 PORT_PHY_QCFG_RESP_OPTION_FLAGS_SIGNAL_MODE_KNOWN
) {
9244 u8 sig_mode
= bp
->link_info
.active_fec_sig_mode
&
9245 PORT_PHY_QCFG_RESP_SIGNAL_MODE_MASK
;
9247 case PORT_PHY_QCFG_RESP_SIGNAL_MODE_NRZ
:
9250 case PORT_PHY_QCFG_RESP_SIGNAL_MODE_PAM4
:
9257 netdev_info(bp
->dev
, "NIC Link is Up, %u Mbps %s%s duplex, Flow control: %s\n",
9258 speed
, signal
, duplex
, flow_ctrl
);
9259 if (bp
->phy_flags
& BNXT_PHY_FL_EEE_CAP
)
9260 netdev_info(bp
->dev
, "EEE is %s\n",
9261 bp
->eee
.eee_active
? "active" :
9263 fec
= bp
->link_info
.fec_cfg
;
9264 if (!(fec
& PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
))
9265 netdev_info(bp
->dev
, "FEC autoneg %s encoding: %s\n",
9266 (fec
& BNXT_FEC_AUTONEG
) ? "on" : "off",
9267 bnxt_report_fec(&bp
->link_info
));
9269 netif_carrier_off(bp
->dev
);
9270 netdev_err(bp
->dev
, "NIC Link is Down\n");
9274 static bool bnxt_phy_qcaps_no_speed(struct hwrm_port_phy_qcaps_output
*resp
)
9276 if (!resp
->supported_speeds_auto_mode
&&
9277 !resp
->supported_speeds_force_mode
&&
9278 !resp
->supported_pam4_speeds_auto_mode
&&
9279 !resp
->supported_pam4_speeds_force_mode
)
9284 static int bnxt_hwrm_phy_qcaps(struct bnxt
*bp
)
9287 struct hwrm_port_phy_qcaps_input req
= {0};
9288 struct hwrm_port_phy_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9289 struct bnxt_link_info
*link_info
= &bp
->link_info
;
9291 if (bp
->hwrm_spec_code
< 0x10201)
9294 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCAPS
, -1, -1);
9296 mutex_lock(&bp
->hwrm_cmd_lock
);
9297 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9299 goto hwrm_phy_qcaps_exit
;
9301 bp
->phy_flags
= resp
->flags
;
9302 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED
) {
9303 struct ethtool_eee
*eee
= &bp
->eee
;
9304 u16 fw_speeds
= le16_to_cpu(resp
->supported_speeds_eee_mode
);
9306 eee
->supported
= _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
9307 bp
->lpi_tmr_lo
= le32_to_cpu(resp
->tx_lpi_timer_low
) &
9308 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK
;
9309 bp
->lpi_tmr_hi
= le32_to_cpu(resp
->valid_tx_lpi_timer_high
) &
9310 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK
;
9313 if (bp
->hwrm_spec_code
>= 0x10a01) {
9314 if (bnxt_phy_qcaps_no_speed(resp
)) {
9315 link_info
->phy_state
= BNXT_PHY_STATE_DISABLED
;
9316 netdev_warn(bp
->dev
, "Ethernet link disabled\n");
9317 } else if (link_info
->phy_state
== BNXT_PHY_STATE_DISABLED
) {
9318 link_info
->phy_state
= BNXT_PHY_STATE_ENABLED
;
9319 netdev_info(bp
->dev
, "Ethernet link enabled\n");
9320 /* Phy re-enabled, reprobe the speeds */
9321 link_info
->support_auto_speeds
= 0;
9322 link_info
->support_pam4_auto_speeds
= 0;
9325 if (resp
->supported_speeds_auto_mode
)
9326 link_info
->support_auto_speeds
=
9327 le16_to_cpu(resp
->supported_speeds_auto_mode
);
9328 if (resp
->supported_pam4_speeds_auto_mode
)
9329 link_info
->support_pam4_auto_speeds
=
9330 le16_to_cpu(resp
->supported_pam4_speeds_auto_mode
);
9332 bp
->port_count
= resp
->port_cnt
;
9334 hwrm_phy_qcaps_exit
:
9335 mutex_unlock(&bp
->hwrm_cmd_lock
);
9339 static bool bnxt_support_dropped(u16 advertising
, u16 supported
)
9341 u16 diff
= advertising
^ supported
;
9343 return ((supported
| diff
) != supported
);
9346 int bnxt_update_link(struct bnxt
*bp
, bool chng_link_state
)
9349 struct bnxt_link_info
*link_info
= &bp
->link_info
;
9350 struct hwrm_port_phy_qcfg_input req
= {0};
9351 struct hwrm_port_phy_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9352 u8 link_up
= link_info
->link_up
;
9353 bool support_changed
= false;
9355 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCFG
, -1, -1);
9357 mutex_lock(&bp
->hwrm_cmd_lock
);
9358 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9360 mutex_unlock(&bp
->hwrm_cmd_lock
);
9364 memcpy(&link_info
->phy_qcfg_resp
, resp
, sizeof(*resp
));
9365 link_info
->phy_link_status
= resp
->link
;
9366 link_info
->duplex
= resp
->duplex_cfg
;
9367 if (bp
->hwrm_spec_code
>= 0x10800)
9368 link_info
->duplex
= resp
->duplex_state
;
9369 link_info
->pause
= resp
->pause
;
9370 link_info
->auto_mode
= resp
->auto_mode
;
9371 link_info
->auto_pause_setting
= resp
->auto_pause
;
9372 link_info
->lp_pause
= resp
->link_partner_adv_pause
;
9373 link_info
->force_pause_setting
= resp
->force_pause
;
9374 link_info
->duplex_setting
= resp
->duplex_cfg
;
9375 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
9376 link_info
->link_speed
= le16_to_cpu(resp
->link_speed
);
9378 link_info
->link_speed
= 0;
9379 link_info
->force_link_speed
= le16_to_cpu(resp
->force_link_speed
);
9380 link_info
->force_pam4_link_speed
=
9381 le16_to_cpu(resp
->force_pam4_link_speed
);
9382 link_info
->support_speeds
= le16_to_cpu(resp
->support_speeds
);
9383 link_info
->support_pam4_speeds
= le16_to_cpu(resp
->support_pam4_speeds
);
9384 link_info
->auto_link_speeds
= le16_to_cpu(resp
->auto_link_speed_mask
);
9385 link_info
->auto_pam4_link_speeds
=
9386 le16_to_cpu(resp
->auto_pam4_link_speed_mask
);
9387 link_info
->lp_auto_link_speeds
=
9388 le16_to_cpu(resp
->link_partner_adv_speeds
);
9389 link_info
->lp_auto_pam4_link_speeds
=
9390 resp
->link_partner_pam4_adv_speeds
;
9391 link_info
->preemphasis
= le32_to_cpu(resp
->preemphasis
);
9392 link_info
->phy_ver
[0] = resp
->phy_maj
;
9393 link_info
->phy_ver
[1] = resp
->phy_min
;
9394 link_info
->phy_ver
[2] = resp
->phy_bld
;
9395 link_info
->media_type
= resp
->media_type
;
9396 link_info
->phy_type
= resp
->phy_type
;
9397 link_info
->transceiver
= resp
->xcvr_pkg_type
;
9398 link_info
->phy_addr
= resp
->eee_config_phy_addr
&
9399 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK
;
9400 link_info
->module_status
= resp
->module_status
;
9402 if (bp
->phy_flags
& BNXT_PHY_FL_EEE_CAP
) {
9403 struct ethtool_eee
*eee
= &bp
->eee
;
9406 eee
->eee_active
= 0;
9407 if (resp
->eee_config_phy_addr
&
9408 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE
) {
9409 eee
->eee_active
= 1;
9410 fw_speeds
= le16_to_cpu(
9411 resp
->link_partner_adv_eee_link_speed_mask
);
9412 eee
->lp_advertised
=
9413 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
9416 /* Pull initial EEE config */
9417 if (!chng_link_state
) {
9418 if (resp
->eee_config_phy_addr
&
9419 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED
)
9420 eee
->eee_enabled
= 1;
9422 fw_speeds
= le16_to_cpu(resp
->adv_eee_link_speed_mask
);
9424 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
9426 if (resp
->eee_config_phy_addr
&
9427 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI
) {
9430 eee
->tx_lpi_enabled
= 1;
9431 tmr
= resp
->xcvr_identifier_type_tx_lpi_timer
;
9432 eee
->tx_lpi_timer
= le32_to_cpu(tmr
) &
9433 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK
;
9438 link_info
->fec_cfg
= PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
;
9439 if (bp
->hwrm_spec_code
>= 0x10504) {
9440 link_info
->fec_cfg
= le16_to_cpu(resp
->fec_cfg
);
9441 link_info
->active_fec_sig_mode
= resp
->active_fec_signal_mode
;
9443 /* TODO: need to add more logic to report VF link */
9444 if (chng_link_state
) {
9445 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
9446 link_info
->link_up
= 1;
9448 link_info
->link_up
= 0;
9449 if (link_up
!= link_info
->link_up
)
9450 bnxt_report_link(bp
);
9452 /* alwasy link down if not require to update link state */
9453 link_info
->link_up
= 0;
9455 mutex_unlock(&bp
->hwrm_cmd_lock
);
9457 if (!BNXT_PHY_CFG_ABLE(bp
))
9460 /* Check if any advertised speeds are no longer supported. The caller
9461 * holds the link_lock mutex, so we can modify link_info settings.
9463 if (bnxt_support_dropped(link_info
->advertising
,
9464 link_info
->support_auto_speeds
)) {
9465 link_info
->advertising
= link_info
->support_auto_speeds
;
9466 support_changed
= true;
9468 if (bnxt_support_dropped(link_info
->advertising_pam4
,
9469 link_info
->support_pam4_auto_speeds
)) {
9470 link_info
->advertising_pam4
= link_info
->support_pam4_auto_speeds
;
9471 support_changed
= true;
9473 if (support_changed
&& (link_info
->autoneg
& BNXT_AUTONEG_SPEED
))
9474 bnxt_hwrm_set_link_setting(bp
, true, false);
9478 static void bnxt_get_port_module_status(struct bnxt
*bp
)
9480 struct bnxt_link_info
*link_info
= &bp
->link_info
;
9481 struct hwrm_port_phy_qcfg_output
*resp
= &link_info
->phy_qcfg_resp
;
9484 if (bnxt_update_link(bp
, true))
9487 module_status
= link_info
->module_status
;
9488 switch (module_status
) {
9489 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
:
9490 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
:
9491 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
:
9492 netdev_warn(bp
->dev
, "Unqualified SFP+ module detected on port %d\n",
9494 if (bp
->hwrm_spec_code
>= 0x10201) {
9495 netdev_warn(bp
->dev
, "Module part number %s\n",
9496 resp
->phy_vendor_partnumber
);
9498 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
)
9499 netdev_warn(bp
->dev
, "TX is disabled\n");
9500 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
)
9501 netdev_warn(bp
->dev
, "SFP+ module is shutdown\n");
9506 bnxt_hwrm_set_pause_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
9508 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) {
9509 if (bp
->hwrm_spec_code
>= 0x10201)
9511 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
9512 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
9513 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX
;
9514 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
9515 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX
;
9517 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
9519 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
9520 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX
;
9521 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
9522 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX
;
9524 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE
);
9525 if (bp
->hwrm_spec_code
>= 0x10201) {
9526 req
->auto_pause
= req
->force_pause
;
9527 req
->enables
|= cpu_to_le32(
9528 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
9533 static void bnxt_hwrm_set_link_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
9535 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_SPEED
) {
9536 req
->auto_mode
|= PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK
;
9537 if (bp
->link_info
.advertising
) {
9538 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK
);
9539 req
->auto_link_speed_mask
= cpu_to_le16(bp
->link_info
.advertising
);
9541 if (bp
->link_info
.advertising_pam4
) {
9543 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAM4_LINK_SPEED_MASK
);
9544 req
->auto_link_pam4_speed_mask
=
9545 cpu_to_le16(bp
->link_info
.advertising_pam4
);
9547 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE
);
9548 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG
);
9550 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE
);
9551 if (bp
->link_info
.req_signal_mode
== BNXT_SIG_MODE_PAM4
) {
9552 req
->force_pam4_link_speed
= cpu_to_le16(bp
->link_info
.req_link_speed
);
9553 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAM4_LINK_SPEED
);
9555 req
->force_link_speed
= cpu_to_le16(bp
->link_info
.req_link_speed
);
9559 /* tell chimp that the setting takes effect immediately */
9560 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY
);
9563 int bnxt_hwrm_set_pause(struct bnxt
*bp
)
9565 struct hwrm_port_phy_cfg_input req
= {0};
9568 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
9569 bnxt_hwrm_set_pause_common(bp
, &req
);
9571 if ((bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) ||
9572 bp
->link_info
.force_link_chng
)
9573 bnxt_hwrm_set_link_common(bp
, &req
);
9575 mutex_lock(&bp
->hwrm_cmd_lock
);
9576 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9577 if (!rc
&& !(bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
)) {
9578 /* since changing of pause setting doesn't trigger any link
9579 * change event, the driver needs to update the current pause
9580 * result upon successfully return of the phy_cfg command
9582 bp
->link_info
.pause
=
9583 bp
->link_info
.force_pause_setting
= bp
->link_info
.req_flow_ctrl
;
9584 bp
->link_info
.auto_pause_setting
= 0;
9585 if (!bp
->link_info
.force_link_chng
)
9586 bnxt_report_link(bp
);
9588 bp
->link_info
.force_link_chng
= false;
9589 mutex_unlock(&bp
->hwrm_cmd_lock
);
9593 static void bnxt_hwrm_set_eee(struct bnxt
*bp
,
9594 struct hwrm_port_phy_cfg_input
*req
)
9596 struct ethtool_eee
*eee
= &bp
->eee
;
9598 if (eee
->eee_enabled
) {
9600 u32 flags
= PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE
;
9602 if (eee
->tx_lpi_enabled
)
9603 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE
;
9605 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE
;
9607 req
->flags
|= cpu_to_le32(flags
);
9608 eee_speeds
= bnxt_get_fw_auto_link_speeds(eee
->advertised
);
9609 req
->eee_link_speed_mask
= cpu_to_le16(eee_speeds
);
9610 req
->tx_lpi_timer
= cpu_to_le32(eee
->tx_lpi_timer
);
9612 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE
);
9616 int bnxt_hwrm_set_link_setting(struct bnxt
*bp
, bool set_pause
, bool set_eee
)
9618 struct hwrm_port_phy_cfg_input req
= {0};
9620 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
9622 bnxt_hwrm_set_pause_common(bp
, &req
);
9624 bnxt_hwrm_set_link_common(bp
, &req
);
9627 bnxt_hwrm_set_eee(bp
, &req
);
9628 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9631 static int bnxt_hwrm_shutdown_link(struct bnxt
*bp
)
9633 struct hwrm_port_phy_cfg_input req
= {0};
9635 if (!BNXT_SINGLE_PF(bp
))
9638 if (pci_num_vf(bp
->pdev
) &&
9639 !(bp
->phy_flags
& BNXT_PHY_FL_FW_MANAGED_LKDN
))
9642 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
9643 req
.flags
= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN
);
9644 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9647 static int bnxt_fw_init_one(struct bnxt
*bp
);
9649 static int bnxt_fw_reset_via_optee(struct bnxt
*bp
)
9651 #ifdef CONFIG_TEE_BNXT_FW
9652 int rc
= tee_bnxt_fw_load();
9655 netdev_err(bp
->dev
, "Failed FW reset via OP-TEE, rc=%d\n", rc
);
9659 netdev_err(bp
->dev
, "OP-TEE not supported\n");
9664 static int bnxt_try_recover_fw(struct bnxt
*bp
)
9666 if (bp
->fw_health
&& bp
->fw_health
->status_reliable
) {
9670 mutex_lock(&bp
->hwrm_cmd_lock
);
9672 sts
= bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
);
9673 rc
= __bnxt_hwrm_ver_get(bp
, true);
9674 if (!BNXT_FW_IS_BOOTING(sts
) &&
9675 !BNXT_FW_IS_RECOVERING(sts
))
9678 } while (rc
== -EBUSY
&& retry
< BNXT_FW_RETRY
);
9679 mutex_unlock(&bp
->hwrm_cmd_lock
);
9681 if (!BNXT_FW_IS_HEALTHY(sts
)) {
9683 "Firmware not responding, status: 0x%x\n",
9687 if (sts
& FW_STATUS_REG_CRASHED_NO_MASTER
) {
9688 netdev_warn(bp
->dev
, "Firmware recover via OP-TEE requested\n");
9689 return bnxt_fw_reset_via_optee(bp
);
9697 static int bnxt_hwrm_if_change(struct bnxt
*bp
, bool up
)
9699 struct hwrm_func_drv_if_change_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9700 struct hwrm_func_drv_if_change_input req
= {0};
9701 bool fw_reset
= !bp
->irq_tbl
;
9702 bool resc_reinit
= false;
9706 if (!(bp
->fw_cap
& BNXT_FW_CAP_IF_CHANGE
))
9709 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_IF_CHANGE
, -1, -1);
9711 req
.flags
= cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP
);
9712 mutex_lock(&bp
->hwrm_cmd_lock
);
9713 while (retry
< BNXT_FW_IF_RETRY
) {
9714 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
9723 flags
= le32_to_cpu(resp
->flags
);
9724 mutex_unlock(&bp
->hwrm_cmd_lock
);
9729 rc
= bnxt_try_recover_fw(bp
);
9736 bnxt_inv_fw_health_reg(bp
);
9740 if (flags
& FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE
)
9742 if (flags
& FUNC_DRV_IF_CHANGE_RESP_FLAGS_HOT_FW_RESET_DONE
)
9744 else if (bp
->fw_health
&& !bp
->fw_health
->status_reliable
)
9745 bnxt_try_map_fw_health_reg(bp
);
9747 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
) && !fw_reset
) {
9748 netdev_err(bp
->dev
, "RESET_DONE not set during FW reset.\n");
9749 set_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
9752 if (resc_reinit
|| fw_reset
) {
9754 set_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
);
9755 if (!test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
9757 bnxt_free_ctx_mem(bp
);
9761 rc
= bnxt_fw_init_one(bp
);
9763 clear_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
);
9764 set_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
9767 bnxt_clear_int_mode(bp
);
9768 rc
= bnxt_init_int_mode(bp
);
9770 clear_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
);
9771 netdev_err(bp
->dev
, "init int mode failed\n");
9775 if (BNXT_NEW_RM(bp
)) {
9776 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
9778 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
9780 netdev_err(bp
->dev
, "resc_qcaps failed\n");
9782 hw_resc
->resv_cp_rings
= 0;
9783 hw_resc
->resv_stat_ctxs
= 0;
9784 hw_resc
->resv_irqs
= 0;
9785 hw_resc
->resv_tx_rings
= 0;
9786 hw_resc
->resv_rx_rings
= 0;
9787 hw_resc
->resv_hw_ring_grps
= 0;
9788 hw_resc
->resv_vnics
= 0;
9790 bp
->tx_nr_rings
= 0;
9791 bp
->rx_nr_rings
= 0;
9798 static int bnxt_hwrm_port_led_qcaps(struct bnxt
*bp
)
9800 struct hwrm_port_led_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9801 struct hwrm_port_led_qcaps_input req
= {0};
9802 struct bnxt_pf_info
*pf
= &bp
->pf
;
9806 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10601)
9809 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_LED_QCAPS
, -1, -1);
9810 req
.port_id
= cpu_to_le16(pf
->port_id
);
9811 mutex_lock(&bp
->hwrm_cmd_lock
);
9812 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9814 mutex_unlock(&bp
->hwrm_cmd_lock
);
9817 if (resp
->num_leds
> 0 && resp
->num_leds
< BNXT_MAX_LED
) {
9820 bp
->num_leds
= resp
->num_leds
;
9821 memcpy(bp
->leds
, &resp
->led0_id
, sizeof(bp
->leds
[0]) *
9823 for (i
= 0; i
< bp
->num_leds
; i
++) {
9824 struct bnxt_led_info
*led
= &bp
->leds
[i
];
9825 __le16 caps
= led
->led_state_caps
;
9827 if (!led
->led_group_id
||
9828 !BNXT_LED_ALT_BLINK_CAP(caps
)) {
9834 mutex_unlock(&bp
->hwrm_cmd_lock
);
9838 int bnxt_hwrm_alloc_wol_fltr(struct bnxt
*bp
)
9840 struct hwrm_wol_filter_alloc_input req
= {0};
9841 struct hwrm_wol_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9844 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_ALLOC
, -1, -1);
9845 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
9846 req
.wol_type
= WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
;
9847 req
.enables
= cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS
);
9848 memcpy(req
.mac_address
, bp
->dev
->dev_addr
, ETH_ALEN
);
9849 mutex_lock(&bp
->hwrm_cmd_lock
);
9850 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9852 bp
->wol_filter_id
= resp
->wol_filter_id
;
9853 mutex_unlock(&bp
->hwrm_cmd_lock
);
9857 int bnxt_hwrm_free_wol_fltr(struct bnxt
*bp
)
9859 struct hwrm_wol_filter_free_input req
= {0};
9861 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_FREE
, -1, -1);
9862 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
9863 req
.enables
= cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID
);
9864 req
.wol_filter_id
= bp
->wol_filter_id
;
9865 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9868 static u16
bnxt_hwrm_get_wol_fltrs(struct bnxt
*bp
, u16 handle
)
9870 struct hwrm_wol_filter_qcfg_input req
= {0};
9871 struct hwrm_wol_filter_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9872 u16 next_handle
= 0;
9875 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_QCFG
, -1, -1);
9876 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
9877 req
.handle
= cpu_to_le16(handle
);
9878 mutex_lock(&bp
->hwrm_cmd_lock
);
9879 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9881 next_handle
= le16_to_cpu(resp
->next_handle
);
9882 if (next_handle
!= 0) {
9883 if (resp
->wol_type
==
9884 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
) {
9886 bp
->wol_filter_id
= resp
->wol_filter_id
;
9890 mutex_unlock(&bp
->hwrm_cmd_lock
);
9894 static void bnxt_get_wol_settings(struct bnxt
*bp
)
9899 if (!BNXT_PF(bp
) || !(bp
->flags
& BNXT_FLAG_WOL_CAP
))
9903 handle
= bnxt_hwrm_get_wol_fltrs(bp
, handle
);
9904 } while (handle
&& handle
!= 0xffff);
9907 #ifdef CONFIG_BNXT_HWMON
9908 static ssize_t
bnxt_show_temp(struct device
*dev
,
9909 struct device_attribute
*devattr
, char *buf
)
9911 struct hwrm_temp_monitor_query_input req
= {0};
9912 struct hwrm_temp_monitor_query_output
*resp
;
9913 struct bnxt
*bp
= dev_get_drvdata(dev
);
9917 resp
= bp
->hwrm_cmd_resp_addr
;
9918 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TEMP_MONITOR_QUERY
, -1, -1);
9919 mutex_lock(&bp
->hwrm_cmd_lock
);
9920 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9922 len
= sprintf(buf
, "%u\n", resp
->temp
* 1000); /* display millidegree */
9923 mutex_unlock(&bp
->hwrm_cmd_lock
);
9928 static SENSOR_DEVICE_ATTR(temp1_input
, 0444, bnxt_show_temp
, NULL
, 0);
9930 static struct attribute
*bnxt_attrs
[] = {
9931 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
9934 ATTRIBUTE_GROUPS(bnxt
);
9936 static void bnxt_hwmon_close(struct bnxt
*bp
)
9938 if (bp
->hwmon_dev
) {
9939 hwmon_device_unregister(bp
->hwmon_dev
);
9940 bp
->hwmon_dev
= NULL
;
9944 static void bnxt_hwmon_open(struct bnxt
*bp
)
9946 struct hwrm_temp_monitor_query_input req
= {0};
9947 struct pci_dev
*pdev
= bp
->pdev
;
9950 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TEMP_MONITOR_QUERY
, -1, -1);
9951 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9952 if (rc
== -EACCES
|| rc
== -EOPNOTSUPP
) {
9953 bnxt_hwmon_close(bp
);
9960 bp
->hwmon_dev
= hwmon_device_register_with_groups(&pdev
->dev
,
9961 DRV_MODULE_NAME
, bp
,
9963 if (IS_ERR(bp
->hwmon_dev
)) {
9964 bp
->hwmon_dev
= NULL
;
9965 dev_warn(&pdev
->dev
, "Cannot register hwmon device\n");
9969 static void bnxt_hwmon_close(struct bnxt
*bp
)
9973 static void bnxt_hwmon_open(struct bnxt
*bp
)
9978 static bool bnxt_eee_config_ok(struct bnxt
*bp
)
9980 struct ethtool_eee
*eee
= &bp
->eee
;
9981 struct bnxt_link_info
*link_info
= &bp
->link_info
;
9983 if (!(bp
->phy_flags
& BNXT_PHY_FL_EEE_CAP
))
9986 if (eee
->eee_enabled
) {
9988 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
9990 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
9991 eee
->eee_enabled
= 0;
9994 if (eee
->advertised
& ~advertising
) {
9995 eee
->advertised
= advertising
& eee
->supported
;
10002 static int bnxt_update_phy_setting(struct bnxt
*bp
)
10005 bool update_link
= false;
10006 bool update_pause
= false;
10007 bool update_eee
= false;
10008 struct bnxt_link_info
*link_info
= &bp
->link_info
;
10010 rc
= bnxt_update_link(bp
, true);
10012 netdev_err(bp
->dev
, "failed to update link (rc: %x)\n",
10016 if (!BNXT_SINGLE_PF(bp
))
10019 if ((link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
10020 (link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
) !=
10021 link_info
->req_flow_ctrl
)
10022 update_pause
= true;
10023 if (!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
10024 link_info
->force_pause_setting
!= link_info
->req_flow_ctrl
)
10025 update_pause
= true;
10026 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
10027 if (BNXT_AUTO_MODE(link_info
->auto_mode
))
10028 update_link
= true;
10029 if (link_info
->req_signal_mode
== BNXT_SIG_MODE_NRZ
&&
10030 link_info
->req_link_speed
!= link_info
->force_link_speed
)
10031 update_link
= true;
10032 else if (link_info
->req_signal_mode
== BNXT_SIG_MODE_PAM4
&&
10033 link_info
->req_link_speed
!= link_info
->force_pam4_link_speed
)
10034 update_link
= true;
10035 if (link_info
->req_duplex
!= link_info
->duplex_setting
)
10036 update_link
= true;
10038 if (link_info
->auto_mode
== BNXT_LINK_AUTO_NONE
)
10039 update_link
= true;
10040 if (link_info
->advertising
!= link_info
->auto_link_speeds
||
10041 link_info
->advertising_pam4
!= link_info
->auto_pam4_link_speeds
)
10042 update_link
= true;
10045 /* The last close may have shutdown the link, so need to call
10046 * PHY_CFG to bring it back up.
10048 if (!bp
->link_info
.link_up
)
10049 update_link
= true;
10051 if (!bnxt_eee_config_ok(bp
))
10055 rc
= bnxt_hwrm_set_link_setting(bp
, update_pause
, update_eee
);
10056 else if (update_pause
)
10057 rc
= bnxt_hwrm_set_pause(bp
);
10059 netdev_err(bp
->dev
, "failed to update phy setting (rc: %x)\n",
10067 /* Common routine to pre-map certain register block to different GRC window.
10068 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
10069 * in PF and 3 windows in VF that can be customized to map in different
10072 static void bnxt_preset_reg_win(struct bnxt
*bp
)
10075 /* CAG registers map to GRC window #4 */
10076 writel(BNXT_CAG_REG_BASE
,
10077 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 12);
10081 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
);
10083 static int bnxt_reinit_after_abort(struct bnxt
*bp
)
10087 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
10090 if (bp
->dev
->reg_state
== NETREG_UNREGISTERED
)
10093 rc
= bnxt_fw_init_one(bp
);
10095 bnxt_clear_int_mode(bp
);
10096 rc
= bnxt_init_int_mode(bp
);
10098 clear_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
10099 set_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
);
10105 static int __bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
10109 bnxt_preset_reg_win(bp
);
10110 netif_carrier_off(bp
->dev
);
10112 /* Reserve rings now if none were reserved at driver probe. */
10113 rc
= bnxt_init_dflt_ring_mode(bp
);
10115 netdev_err(bp
->dev
, "Failed to reserve default rings at open\n");
10119 rc
= bnxt_reserve_rings(bp
, irq_re_init
);
10122 if ((bp
->flags
& BNXT_FLAG_RFS
) &&
10123 !(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
10124 /* disable RFS if falling back to INTA */
10125 bp
->dev
->hw_features
&= ~NETIF_F_NTUPLE
;
10126 bp
->flags
&= ~BNXT_FLAG_RFS
;
10129 rc
= bnxt_alloc_mem(bp
, irq_re_init
);
10131 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
10132 goto open_err_free_mem
;
10136 bnxt_init_napi(bp
);
10137 rc
= bnxt_request_irq(bp
);
10139 netdev_err(bp
->dev
, "bnxt_request_irq err: %x\n", rc
);
10144 rc
= bnxt_init_nic(bp
, irq_re_init
);
10146 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
10150 bnxt_enable_napi(bp
);
10151 bnxt_debug_dev_init(bp
);
10153 if (link_re_init
) {
10154 mutex_lock(&bp
->link_lock
);
10155 rc
= bnxt_update_phy_setting(bp
);
10156 mutex_unlock(&bp
->link_lock
);
10158 netdev_warn(bp
->dev
, "failed to update phy settings\n");
10159 if (BNXT_SINGLE_PF(bp
)) {
10160 bp
->link_info
.phy_retry
= true;
10161 bp
->link_info
.phy_retry_expires
=
10168 udp_tunnel_nic_reset_ntf(bp
->dev
);
10170 set_bit(BNXT_STATE_OPEN
, &bp
->state
);
10171 bnxt_enable_int(bp
);
10172 /* Enable TX queues */
10173 bnxt_tx_enable(bp
);
10174 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
10175 /* Poll link status and check for SFP+ module status */
10176 bnxt_get_port_module_status(bp
);
10178 /* VF-reps may need to be re-opened after the PF is re-opened */
10180 bnxt_vf_reps_open(bp
);
10187 bnxt_free_skbs(bp
);
10189 bnxt_free_mem(bp
, true);
10193 /* rtnl_lock held */
10194 int bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
10198 if (test_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
))
10201 rc
= __bnxt_open_nic(bp
, irq_re_init
, link_re_init
);
10203 netdev_err(bp
->dev
, "nic open fail (rc: %x)\n", rc
);
10204 dev_close(bp
->dev
);
10209 /* rtnl_lock held, open the NIC half way by allocating all resources, but
10210 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
10213 int bnxt_half_open_nic(struct bnxt
*bp
)
10217 if (test_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
)) {
10218 netdev_err(bp
->dev
, "A previous firmware reset has not completed, aborting half open\n");
10220 goto half_open_err
;
10223 rc
= bnxt_alloc_mem(bp
, false);
10225 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
10226 goto half_open_err
;
10228 rc
= bnxt_init_nic(bp
, false);
10230 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
10231 goto half_open_err
;
10236 bnxt_free_skbs(bp
);
10237 bnxt_free_mem(bp
, false);
10238 dev_close(bp
->dev
);
10242 /* rtnl_lock held, this call can only be made after a previous successful
10243 * call to bnxt_half_open_nic().
10245 void bnxt_half_close_nic(struct bnxt
*bp
)
10247 bnxt_hwrm_resource_free(bp
, false, false);
10248 bnxt_free_skbs(bp
);
10249 bnxt_free_mem(bp
, false);
10252 static void bnxt_reenable_sriov(struct bnxt
*bp
)
10255 struct bnxt_pf_info
*pf
= &bp
->pf
;
10256 int n
= pf
->active_vfs
;
10259 bnxt_cfg_hw_sriov(bp
, &n
, true);
10263 static int bnxt_open(struct net_device
*dev
)
10265 struct bnxt
*bp
= netdev_priv(dev
);
10268 if (test_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
)) {
10269 rc
= bnxt_reinit_after_abort(bp
);
10272 netdev_err(bp
->dev
, "A previous firmware reset has not completed, aborting\n");
10274 netdev_err(bp
->dev
, "Failed to reinitialize after aborted firmware reset\n");
10279 rc
= bnxt_hwrm_if_change(bp
, true);
10283 if (bnxt_ptp_init(bp
)) {
10284 netdev_warn(dev
, "PTP initialization failed.\n");
10285 kfree(bp
->ptp_cfg
);
10286 bp
->ptp_cfg
= NULL
;
10288 rc
= __bnxt_open_nic(bp
, true, true);
10290 bnxt_hwrm_if_change(bp
, false);
10291 bnxt_ptp_clear(bp
);
10293 if (test_and_clear_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
)) {
10294 if (!test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
10295 bnxt_ulp_start(bp
, 0);
10296 bnxt_reenable_sriov(bp
);
10299 bnxt_hwmon_open(bp
);
10305 static bool bnxt_drv_busy(struct bnxt
*bp
)
10307 return (test_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
) ||
10308 test_bit(BNXT_STATE_READ_STATS
, &bp
->state
));
10311 static void bnxt_get_ring_stats(struct bnxt
*bp
,
10312 struct rtnl_link_stats64
*stats
);
10314 static void __bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
,
10317 /* Close the VF-reps before closing PF */
10319 bnxt_vf_reps_close(bp
);
10321 /* Change device state to avoid TX queue wake up's */
10322 bnxt_tx_disable(bp
);
10324 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
10325 smp_mb__after_atomic();
10326 while (bnxt_drv_busy(bp
))
10329 /* Flush rings and and disable interrupts */
10330 bnxt_shutdown_nic(bp
, irq_re_init
);
10332 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
10334 bnxt_debug_dev_exit(bp
);
10335 bnxt_disable_napi(bp
);
10336 del_timer_sync(&bp
->timer
);
10337 bnxt_free_skbs(bp
);
10339 /* Save ring stats before shutdown */
10340 if (bp
->bnapi
&& irq_re_init
)
10341 bnxt_get_ring_stats(bp
, &bp
->net_stats_prev
);
10346 bnxt_free_mem(bp
, irq_re_init
);
10349 int bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
10353 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
10354 /* If we get here, it means firmware reset is in progress
10355 * while we are trying to close. We can safely proceed with
10356 * the close because we are holding rtnl_lock(). Some firmware
10357 * messages may fail as we proceed to close. We set the
10358 * ABORT_ERR flag here so that the FW reset thread will later
10359 * abort when it gets the rtnl_lock() and sees the flag.
10361 netdev_warn(bp
->dev
, "FW reset in progress during close, FW reset will be aborted\n");
10362 set_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
10365 #ifdef CONFIG_BNXT_SRIOV
10366 if (bp
->sriov_cfg
) {
10367 rc
= wait_event_interruptible_timeout(bp
->sriov_cfg_wait
,
10369 BNXT_SRIOV_CFG_WAIT_TMO
);
10371 netdev_warn(bp
->dev
, "timeout waiting for SRIOV config operation to complete!\n");
10374 __bnxt_close_nic(bp
, irq_re_init
, link_re_init
);
10378 static int bnxt_close(struct net_device
*dev
)
10380 struct bnxt
*bp
= netdev_priv(dev
);
10382 bnxt_ptp_clear(bp
);
10383 bnxt_hwmon_close(bp
);
10384 bnxt_close_nic(bp
, true, true);
10385 bnxt_hwrm_shutdown_link(bp
);
10386 bnxt_hwrm_if_change(bp
, false);
10390 static int bnxt_hwrm_port_phy_read(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
10393 struct hwrm_port_phy_mdio_read_output
*resp
= bp
->hwrm_cmd_resp_addr
;
10394 struct hwrm_port_phy_mdio_read_input req
= {0};
10397 if (bp
->hwrm_spec_code
< 0x10a00)
10398 return -EOPNOTSUPP
;
10400 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_READ
, -1, -1);
10401 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
10402 req
.phy_addr
= phy_addr
;
10403 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
10404 if (mdio_phy_id_is_c45(phy_addr
)) {
10406 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
10407 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
10408 req
.reg_addr
= cpu_to_le16(reg
);
10411 mutex_lock(&bp
->hwrm_cmd_lock
);
10412 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
10414 *val
= le16_to_cpu(resp
->reg_data
);
10415 mutex_unlock(&bp
->hwrm_cmd_lock
);
10419 static int bnxt_hwrm_port_phy_write(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
10422 struct hwrm_port_phy_mdio_write_input req
= {0};
10424 if (bp
->hwrm_spec_code
< 0x10a00)
10425 return -EOPNOTSUPP
;
10427 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_WRITE
, -1, -1);
10428 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
10429 req
.phy_addr
= phy_addr
;
10430 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
10431 if (mdio_phy_id_is_c45(phy_addr
)) {
10433 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
10434 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
10435 req
.reg_addr
= cpu_to_le16(reg
);
10437 req
.reg_data
= cpu_to_le16(val
);
10439 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
10442 /* rtnl_lock held */
10443 static int bnxt_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
10445 struct mii_ioctl_data
*mdio
= if_mii(ifr
);
10446 struct bnxt
*bp
= netdev_priv(dev
);
10451 mdio
->phy_id
= bp
->link_info
.phy_addr
;
10454 case SIOCGMIIREG
: {
10455 u16 mii_regval
= 0;
10457 if (!netif_running(dev
))
10460 rc
= bnxt_hwrm_port_phy_read(bp
, mdio
->phy_id
, mdio
->reg_num
,
10462 mdio
->val_out
= mii_regval
;
10467 if (!netif_running(dev
))
10470 return bnxt_hwrm_port_phy_write(bp
, mdio
->phy_id
, mdio
->reg_num
,
10473 case SIOCSHWTSTAMP
:
10474 return bnxt_hwtstamp_set(dev
, ifr
);
10476 case SIOCGHWTSTAMP
:
10477 return bnxt_hwtstamp_get(dev
, ifr
);
10483 return -EOPNOTSUPP
;
10486 static void bnxt_get_ring_stats(struct bnxt
*bp
,
10487 struct rtnl_link_stats64
*stats
)
10491 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
10492 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
10493 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
10494 u64
*sw
= cpr
->stats
.sw_stats
;
10496 stats
->rx_packets
+= BNXT_GET_RING_STATS64(sw
, rx_ucast_pkts
);
10497 stats
->rx_packets
+= BNXT_GET_RING_STATS64(sw
, rx_mcast_pkts
);
10498 stats
->rx_packets
+= BNXT_GET_RING_STATS64(sw
, rx_bcast_pkts
);
10500 stats
->tx_packets
+= BNXT_GET_RING_STATS64(sw
, tx_ucast_pkts
);
10501 stats
->tx_packets
+= BNXT_GET_RING_STATS64(sw
, tx_mcast_pkts
);
10502 stats
->tx_packets
+= BNXT_GET_RING_STATS64(sw
, tx_bcast_pkts
);
10504 stats
->rx_bytes
+= BNXT_GET_RING_STATS64(sw
, rx_ucast_bytes
);
10505 stats
->rx_bytes
+= BNXT_GET_RING_STATS64(sw
, rx_mcast_bytes
);
10506 stats
->rx_bytes
+= BNXT_GET_RING_STATS64(sw
, rx_bcast_bytes
);
10508 stats
->tx_bytes
+= BNXT_GET_RING_STATS64(sw
, tx_ucast_bytes
);
10509 stats
->tx_bytes
+= BNXT_GET_RING_STATS64(sw
, tx_mcast_bytes
);
10510 stats
->tx_bytes
+= BNXT_GET_RING_STATS64(sw
, tx_bcast_bytes
);
10512 stats
->rx_missed_errors
+=
10513 BNXT_GET_RING_STATS64(sw
, rx_discard_pkts
);
10515 stats
->multicast
+= BNXT_GET_RING_STATS64(sw
, rx_mcast_pkts
);
10517 stats
->tx_dropped
+= BNXT_GET_RING_STATS64(sw
, tx_error_pkts
);
10521 static void bnxt_add_prev_stats(struct bnxt
*bp
,
10522 struct rtnl_link_stats64
*stats
)
10524 struct rtnl_link_stats64
*prev_stats
= &bp
->net_stats_prev
;
10526 stats
->rx_packets
+= prev_stats
->rx_packets
;
10527 stats
->tx_packets
+= prev_stats
->tx_packets
;
10528 stats
->rx_bytes
+= prev_stats
->rx_bytes
;
10529 stats
->tx_bytes
+= prev_stats
->tx_bytes
;
10530 stats
->rx_missed_errors
+= prev_stats
->rx_missed_errors
;
10531 stats
->multicast
+= prev_stats
->multicast
;
10532 stats
->tx_dropped
+= prev_stats
->tx_dropped
;
10536 bnxt_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
10538 struct bnxt
*bp
= netdev_priv(dev
);
10540 set_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
10541 /* Make sure bnxt_close_nic() sees that we are reading stats before
10542 * we check the BNXT_STATE_OPEN flag.
10544 smp_mb__after_atomic();
10545 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
10546 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
10547 *stats
= bp
->net_stats_prev
;
10551 bnxt_get_ring_stats(bp
, stats
);
10552 bnxt_add_prev_stats(bp
, stats
);
10554 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
10555 u64
*rx
= bp
->port_stats
.sw_stats
;
10556 u64
*tx
= bp
->port_stats
.sw_stats
+
10557 BNXT_TX_PORT_STATS_BYTE_OFFSET
/ 8;
10559 stats
->rx_crc_errors
=
10560 BNXT_GET_RX_PORT_STATS64(rx
, rx_fcs_err_frames
);
10561 stats
->rx_frame_errors
=
10562 BNXT_GET_RX_PORT_STATS64(rx
, rx_align_err_frames
);
10563 stats
->rx_length_errors
=
10564 BNXT_GET_RX_PORT_STATS64(rx
, rx_undrsz_frames
) +
10565 BNXT_GET_RX_PORT_STATS64(rx
, rx_ovrsz_frames
) +
10566 BNXT_GET_RX_PORT_STATS64(rx
, rx_runt_frames
);
10568 BNXT_GET_RX_PORT_STATS64(rx
, rx_false_carrier_frames
) +
10569 BNXT_GET_RX_PORT_STATS64(rx
, rx_jbr_frames
);
10570 stats
->collisions
=
10571 BNXT_GET_TX_PORT_STATS64(tx
, tx_total_collisions
);
10572 stats
->tx_fifo_errors
=
10573 BNXT_GET_TX_PORT_STATS64(tx
, tx_fifo_underruns
);
10574 stats
->tx_errors
= BNXT_GET_TX_PORT_STATS64(tx
, tx_err
);
10576 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
10579 static bool bnxt_mc_list_updated(struct bnxt
*bp
, u32
*rx_mask
)
10581 struct net_device
*dev
= bp
->dev
;
10582 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
10583 struct netdev_hw_addr
*ha
;
10586 bool update
= false;
10589 netdev_for_each_mc_addr(ha
, dev
) {
10590 if (mc_count
>= BNXT_MAX_MC_ADDRS
) {
10591 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
10592 vnic
->mc_list_count
= 0;
10596 if (!ether_addr_equal(haddr
, vnic
->mc_list
+ off
)) {
10597 memcpy(vnic
->mc_list
+ off
, haddr
, ETH_ALEN
);
10604 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
;
10606 if (mc_count
!= vnic
->mc_list_count
) {
10607 vnic
->mc_list_count
= mc_count
;
10613 static bool bnxt_uc_list_updated(struct bnxt
*bp
)
10615 struct net_device
*dev
= bp
->dev
;
10616 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
10617 struct netdev_hw_addr
*ha
;
10620 if (netdev_uc_count(dev
) != (vnic
->uc_filter_count
- 1))
10623 netdev_for_each_uc_addr(ha
, dev
) {
10624 if (!ether_addr_equal(ha
->addr
, vnic
->uc_list
+ off
))
10632 static void bnxt_set_rx_mode(struct net_device
*dev
)
10634 struct bnxt
*bp
= netdev_priv(dev
);
10635 struct bnxt_vnic_info
*vnic
;
10636 bool mc_update
= false;
10640 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
))
10643 vnic
= &bp
->vnic_info
[0];
10644 mask
= vnic
->rx_mask
;
10645 mask
&= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
|
10646 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
|
10647 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
|
10648 CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
);
10650 if (dev
->flags
& IFF_PROMISC
)
10651 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
10653 uc_update
= bnxt_uc_list_updated(bp
);
10655 if (dev
->flags
& IFF_BROADCAST
)
10656 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
10657 if (dev
->flags
& IFF_ALLMULTI
) {
10658 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
10659 vnic
->mc_list_count
= 0;
10661 mc_update
= bnxt_mc_list_updated(bp
, &mask
);
10664 if (mask
!= vnic
->rx_mask
|| uc_update
|| mc_update
) {
10665 vnic
->rx_mask
= mask
;
10667 set_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
);
10668 bnxt_queue_sp_work(bp
);
10672 static int bnxt_cfg_rx_mode(struct bnxt
*bp
)
10674 struct net_device
*dev
= bp
->dev
;
10675 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
10676 struct netdev_hw_addr
*ha
;
10677 int i
, off
= 0, rc
;
10680 netif_addr_lock_bh(dev
);
10681 uc_update
= bnxt_uc_list_updated(bp
);
10682 netif_addr_unlock_bh(dev
);
10687 mutex_lock(&bp
->hwrm_cmd_lock
);
10688 for (i
= 1; i
< vnic
->uc_filter_count
; i
++) {
10689 struct hwrm_cfa_l2_filter_free_input req
= {0};
10691 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_FREE
, -1,
10694 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[i
];
10696 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
10699 mutex_unlock(&bp
->hwrm_cmd_lock
);
10701 vnic
->uc_filter_count
= 1;
10703 netif_addr_lock_bh(dev
);
10704 if (netdev_uc_count(dev
) > (BNXT_MAX_UC_ADDRS
- 1)) {
10705 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
10707 netdev_for_each_uc_addr(ha
, dev
) {
10708 memcpy(vnic
->uc_list
+ off
, ha
->addr
, ETH_ALEN
);
10710 vnic
->uc_filter_count
++;
10713 netif_addr_unlock_bh(dev
);
10715 for (i
= 1, off
= 0; i
< vnic
->uc_filter_count
; i
++, off
+= ETH_ALEN
) {
10716 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, i
, vnic
->uc_list
+ off
);
10718 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n",
10720 vnic
->uc_filter_count
= i
;
10726 if ((vnic
->rx_mask
& CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
) &&
10727 !bnxt_promisc_ok(bp
))
10728 vnic
->rx_mask
&= ~CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
10729 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
10730 if (rc
&& vnic
->mc_list_count
) {
10731 netdev_info(bp
->dev
, "Failed setting MC filters rc: %d, turning on ALL_MCAST mode\n",
10733 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
10734 vnic
->mc_list_count
= 0;
10735 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
10738 netdev_err(bp
->dev
, "HWRM cfa l2 rx mask failure rc: %d\n",
10744 static bool bnxt_can_reserve_rings(struct bnxt
*bp
)
10746 #ifdef CONFIG_BNXT_SRIOV
10747 if (BNXT_NEW_RM(bp
) && BNXT_VF(bp
)) {
10748 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
10750 /* No minimum rings were provisioned by the PF. Don't
10751 * reserve rings by default when device is down.
10753 if (hw_resc
->min_tx_rings
|| hw_resc
->resv_tx_rings
)
10756 if (!netif_running(bp
->dev
))
10763 /* If the chip and firmware supports RFS */
10764 static bool bnxt_rfs_supported(struct bnxt
*bp
)
10766 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
10767 if (bp
->fw_cap
& BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2
)
10771 if (BNXT_PF(bp
) && !BNXT_CHIP_TYPE_NITRO_A0(bp
))
10773 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
10778 /* If runtime conditions support RFS */
10779 static bool bnxt_rfs_capable(struct bnxt
*bp
)
10781 #ifdef CONFIG_RFS_ACCEL
10782 int vnics
, max_vnics
, max_rss_ctxs
;
10784 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
10785 return bnxt_rfs_supported(bp
);
10786 if (!(bp
->flags
& BNXT_FLAG_MSIX_CAP
) || !bnxt_can_reserve_rings(bp
))
10789 vnics
= 1 + bp
->rx_nr_rings
;
10790 max_vnics
= bnxt_get_max_func_vnics(bp
);
10791 max_rss_ctxs
= bnxt_get_max_func_rss_ctxs(bp
);
10793 /* RSS contexts not a limiting factor */
10794 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
10795 max_rss_ctxs
= max_vnics
;
10796 if (vnics
> max_vnics
|| vnics
> max_rss_ctxs
) {
10797 if (bp
->rx_nr_rings
> 1)
10798 netdev_warn(bp
->dev
,
10799 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
10800 min(max_rss_ctxs
- 1, max_vnics
- 1));
10804 if (!BNXT_NEW_RM(bp
))
10807 if (vnics
== bp
->hw_resc
.resv_vnics
)
10810 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, vnics
);
10811 if (vnics
<= bp
->hw_resc
.resv_vnics
)
10814 netdev_warn(bp
->dev
, "Unable to reserve resources to support NTUPLE filters.\n");
10815 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, 1);
10822 static netdev_features_t
bnxt_fix_features(struct net_device
*dev
,
10823 netdev_features_t features
)
10825 struct bnxt
*bp
= netdev_priv(dev
);
10826 netdev_features_t vlan_features
;
10828 if ((features
& NETIF_F_NTUPLE
) && !bnxt_rfs_capable(bp
))
10829 features
&= ~NETIF_F_NTUPLE
;
10831 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
10832 features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
10834 if (!(features
& NETIF_F_GRO
))
10835 features
&= ~NETIF_F_GRO_HW
;
10837 if (features
& NETIF_F_GRO_HW
)
10838 features
&= ~NETIF_F_LRO
;
10840 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
10841 * turned on or off together.
10843 vlan_features
= features
& BNXT_HW_FEATURE_VLAN_ALL_RX
;
10844 if (vlan_features
!= BNXT_HW_FEATURE_VLAN_ALL_RX
) {
10845 if (dev
->features
& BNXT_HW_FEATURE_VLAN_ALL_RX
)
10846 features
&= ~BNXT_HW_FEATURE_VLAN_ALL_RX
;
10847 else if (vlan_features
)
10848 features
|= BNXT_HW_FEATURE_VLAN_ALL_RX
;
10850 #ifdef CONFIG_BNXT_SRIOV
10851 if (BNXT_VF(bp
) && bp
->vf
.vlan
)
10852 features
&= ~BNXT_HW_FEATURE_VLAN_ALL_RX
;
10857 static int bnxt_set_features(struct net_device
*dev
, netdev_features_t features
)
10859 struct bnxt
*bp
= netdev_priv(dev
);
10860 u32 flags
= bp
->flags
;
10863 bool re_init
= false;
10864 bool update_tpa
= false;
10866 flags
&= ~BNXT_FLAG_ALL_CONFIG_FEATS
;
10867 if (features
& NETIF_F_GRO_HW
)
10868 flags
|= BNXT_FLAG_GRO
;
10869 else if (features
& NETIF_F_LRO
)
10870 flags
|= BNXT_FLAG_LRO
;
10872 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
10873 flags
&= ~BNXT_FLAG_TPA
;
10875 if (features
& BNXT_HW_FEATURE_VLAN_ALL_RX
)
10876 flags
|= BNXT_FLAG_STRIP_VLAN
;
10878 if (features
& NETIF_F_NTUPLE
)
10879 flags
|= BNXT_FLAG_RFS
;
10881 changes
= flags
^ bp
->flags
;
10882 if (changes
& BNXT_FLAG_TPA
) {
10884 if ((bp
->flags
& BNXT_FLAG_TPA
) == 0 ||
10885 (flags
& BNXT_FLAG_TPA
) == 0 ||
10886 (bp
->flags
& BNXT_FLAG_CHIP_P5
))
10890 if (changes
& ~BNXT_FLAG_TPA
)
10893 if (flags
!= bp
->flags
) {
10894 u32 old_flags
= bp
->flags
;
10896 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
10899 bnxt_set_ring_params(bp
);
10904 bnxt_close_nic(bp
, false, false);
10907 bnxt_set_ring_params(bp
);
10909 return bnxt_open_nic(bp
, false, false);
10913 rc
= bnxt_set_tpa(bp
,
10914 (flags
& BNXT_FLAG_TPA
) ?
10917 bp
->flags
= old_flags
;
10923 static bool bnxt_exthdr_check(struct bnxt
*bp
, struct sk_buff
*skb
, int nw_off
,
10926 struct ipv6hdr
*ip6h
= (struct ipv6hdr
*)(skb
->data
+ nw_off
);
10931 /* Check that there are at most 2 IPv6 extension headers, no
10932 * fragment header, and each is <= 64 bytes.
10934 start
= nw_off
+ sizeof(*ip6h
);
10935 nexthdr
= &ip6h
->nexthdr
;
10936 while (ipv6_ext_hdr(*nexthdr
)) {
10937 struct ipv6_opt_hdr
*hp
;
10940 if (hdr_count
>= 3 || *nexthdr
== NEXTHDR_NONE
||
10941 *nexthdr
== NEXTHDR_FRAGMENT
)
10943 hp
= __skb_header_pointer(NULL
, start
, sizeof(*hp
), skb
->data
,
10944 skb_headlen(skb
), NULL
);
10947 if (*nexthdr
== NEXTHDR_AUTH
)
10948 hdrlen
= ipv6_authlen(hp
);
10950 hdrlen
= ipv6_optlen(hp
);
10954 nexthdr
= &hp
->nexthdr
;
10959 /* Caller will check inner protocol */
10960 if (skb
->encapsulation
) {
10966 /* Only support TCP/UDP for non-tunneled ipv6 and inner ipv6 */
10967 return *nexthdr
== IPPROTO_TCP
|| *nexthdr
== IPPROTO_UDP
;
10970 /* For UDP, we can only handle 1 Vxlan port and 1 Geneve port. */
10971 static bool bnxt_udp_tunl_check(struct bnxt
*bp
, struct sk_buff
*skb
)
10973 struct udphdr
*uh
= udp_hdr(skb
);
10974 __be16 udp_port
= uh
->dest
;
10976 if (udp_port
!= bp
->vxlan_port
&& udp_port
!= bp
->nge_port
)
10978 if (skb
->inner_protocol_type
== ENCAP_TYPE_ETHER
) {
10979 struct ethhdr
*eh
= inner_eth_hdr(skb
);
10981 switch (eh
->h_proto
) {
10982 case htons(ETH_P_IP
):
10984 case htons(ETH_P_IPV6
):
10985 return bnxt_exthdr_check(bp
, skb
,
10986 skb_inner_network_offset(skb
),
10993 static bool bnxt_tunl_check(struct bnxt
*bp
, struct sk_buff
*skb
, u8 l4_proto
)
10995 switch (l4_proto
) {
10997 return bnxt_udp_tunl_check(bp
, skb
);
11000 case IPPROTO_GRE
: {
11001 switch (skb
->inner_protocol
) {
11004 case htons(ETH_P_IP
):
11006 case htons(ETH_P_IPV6
):
11011 /* Check ext headers of inner ipv6 */
11012 return bnxt_exthdr_check(bp
, skb
, skb_inner_network_offset(skb
),
11018 static netdev_features_t
bnxt_features_check(struct sk_buff
*skb
,
11019 struct net_device
*dev
,
11020 netdev_features_t features
)
11022 struct bnxt
*bp
= netdev_priv(dev
);
11025 features
= vlan_features_check(skb
, features
);
11026 switch (vlan_get_protocol(skb
)) {
11027 case htons(ETH_P_IP
):
11028 if (!skb
->encapsulation
)
11030 l4_proto
= &ip_hdr(skb
)->protocol
;
11031 if (bnxt_tunl_check(bp
, skb
, *l4_proto
))
11034 case htons(ETH_P_IPV6
):
11035 if (!bnxt_exthdr_check(bp
, skb
, skb_network_offset(skb
),
11038 if (!l4_proto
|| bnxt_tunl_check(bp
, skb
, *l4_proto
))
11042 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
11045 int bnxt_dbg_hwrm_rd_reg(struct bnxt
*bp
, u32 reg_off
, u16 num_words
,
11048 struct hwrm_dbg_read_direct_output
*resp
= bp
->hwrm_cmd_resp_addr
;
11049 struct hwrm_dbg_read_direct_input req
= {0};
11050 __le32
*dbg_reg_buf
;
11051 dma_addr_t mapping
;
11054 dbg_reg_buf
= dma_alloc_coherent(&bp
->pdev
->dev
, num_words
* 4,
11055 &mapping
, GFP_KERNEL
);
11058 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_DBG_READ_DIRECT
, -1, -1);
11059 req
.host_dest_addr
= cpu_to_le64(mapping
);
11060 req
.read_addr
= cpu_to_le32(reg_off
+ CHIMP_REG_VIEW_ADDR
);
11061 req
.read_len32
= cpu_to_le32(num_words
);
11062 mutex_lock(&bp
->hwrm_cmd_lock
);
11063 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
11064 if (rc
|| resp
->error_code
) {
11066 goto dbg_rd_reg_exit
;
11068 for (i
= 0; i
< num_words
; i
++)
11069 reg_buf
[i
] = le32_to_cpu(dbg_reg_buf
[i
]);
11072 mutex_unlock(&bp
->hwrm_cmd_lock
);
11073 dma_free_coherent(&bp
->pdev
->dev
, num_words
* 4, dbg_reg_buf
, mapping
);
11077 static int bnxt_dbg_hwrm_ring_info_get(struct bnxt
*bp
, u8 ring_type
,
11078 u32 ring_id
, u32
*prod
, u32
*cons
)
11080 struct hwrm_dbg_ring_info_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
11081 struct hwrm_dbg_ring_info_get_input req
= {0};
11084 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_DBG_RING_INFO_GET
, -1, -1);
11085 req
.ring_type
= ring_type
;
11086 req
.fw_ring_id
= cpu_to_le32(ring_id
);
11087 mutex_lock(&bp
->hwrm_cmd_lock
);
11088 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
11090 *prod
= le32_to_cpu(resp
->producer_index
);
11091 *cons
= le32_to_cpu(resp
->consumer_index
);
11093 mutex_unlock(&bp
->hwrm_cmd_lock
);
11097 static void bnxt_dump_tx_sw_state(struct bnxt_napi
*bnapi
)
11099 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
11100 int i
= bnapi
->index
;
11105 netdev_info(bnapi
->bp
->dev
, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
11106 i
, txr
->tx_ring_struct
.fw_ring_id
, txr
->tx_prod
,
11110 static void bnxt_dump_rx_sw_state(struct bnxt_napi
*bnapi
)
11112 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
11113 int i
= bnapi
->index
;
11118 netdev_info(bnapi
->bp
->dev
, "[%d]: rx{fw_ring: %d prod: %x} rx_agg{fw_ring: %d agg_prod: %x sw_agg_prod: %x}\n",
11119 i
, rxr
->rx_ring_struct
.fw_ring_id
, rxr
->rx_prod
,
11120 rxr
->rx_agg_ring_struct
.fw_ring_id
, rxr
->rx_agg_prod
,
11121 rxr
->rx_sw_agg_prod
);
11124 static void bnxt_dump_cp_sw_state(struct bnxt_napi
*bnapi
)
11126 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
11127 int i
= bnapi
->index
;
11129 netdev_info(bnapi
->bp
->dev
, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
11130 i
, cpr
->cp_ring_struct
.fw_ring_id
, cpr
->cp_raw_cons
);
11133 static void bnxt_dbg_dump_states(struct bnxt
*bp
)
11136 struct bnxt_napi
*bnapi
;
11138 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
11139 bnapi
= bp
->bnapi
[i
];
11140 if (netif_msg_drv(bp
)) {
11141 bnxt_dump_tx_sw_state(bnapi
);
11142 bnxt_dump_rx_sw_state(bnapi
);
11143 bnxt_dump_cp_sw_state(bnapi
);
11148 static int bnxt_hwrm_rx_ring_reset(struct bnxt
*bp
, int ring_nr
)
11150 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[ring_nr
];
11151 struct hwrm_ring_reset_input req
= {0};
11152 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
11153 struct bnxt_cp_ring_info
*cpr
;
11156 cpr
= &bnapi
->cp_ring
;
11157 cp_ring_id
= cpr
->cp_ring_struct
.fw_ring_id
;
11158 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_RESET
, cp_ring_id
, -1);
11159 req
.ring_type
= RING_RESET_REQ_RING_TYPE_RX_RING_GRP
;
11160 req
.ring_id
= cpu_to_le16(bp
->grp_info
[bnapi
->index
].fw_grp_id
);
11161 return hwrm_send_message_silent(bp
, &req
, sizeof(req
),
11165 static void bnxt_reset_task(struct bnxt
*bp
, bool silent
)
11168 bnxt_dbg_dump_states(bp
);
11169 if (netif_running(bp
->dev
)) {
11173 bnxt_close_nic(bp
, false, false);
11174 bnxt_open_nic(bp
, false, false);
11177 bnxt_close_nic(bp
, true, false);
11178 rc
= bnxt_open_nic(bp
, true, false);
11179 bnxt_ulp_start(bp
, rc
);
11184 static void bnxt_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
11186 struct bnxt
*bp
= netdev_priv(dev
);
11188 netdev_err(bp
->dev
, "TX timeout detected, starting reset task!\n");
11189 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
11190 bnxt_queue_sp_work(bp
);
11193 static void bnxt_fw_health_check(struct bnxt
*bp
)
11195 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11198 if (!fw_health
->enabled
|| test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
11201 if (fw_health
->tmr_counter
) {
11202 fw_health
->tmr_counter
--;
11206 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
11207 if (val
== fw_health
->last_fw_heartbeat
)
11210 fw_health
->last_fw_heartbeat
= val
;
11212 val
= bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
11213 if (val
!= fw_health
->last_fw_reset_cnt
)
11216 fw_health
->tmr_counter
= fw_health
->tmr_multiplier
;
11220 set_bit(BNXT_FW_EXCEPTION_SP_EVENT
, &bp
->sp_event
);
11221 bnxt_queue_sp_work(bp
);
11224 static void bnxt_timer(struct timer_list
*t
)
11226 struct bnxt
*bp
= from_timer(bp
, t
, timer
);
11227 struct net_device
*dev
= bp
->dev
;
11229 if (!netif_running(dev
) || !test_bit(BNXT_STATE_OPEN
, &bp
->state
))
11232 if (atomic_read(&bp
->intr_sem
) != 0)
11233 goto bnxt_restart_timer
;
11235 if (bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
)
11236 bnxt_fw_health_check(bp
);
11238 if (bp
->link_info
.link_up
&& bp
->stats_coal_ticks
) {
11239 set_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
);
11240 bnxt_queue_sp_work(bp
);
11243 if (bnxt_tc_flower_enabled(bp
)) {
11244 set_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
);
11245 bnxt_queue_sp_work(bp
);
11248 #ifdef CONFIG_RFS_ACCEL
11249 if ((bp
->flags
& BNXT_FLAG_RFS
) && bp
->ntp_fltr_count
) {
11250 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
11251 bnxt_queue_sp_work(bp
);
11253 #endif /*CONFIG_RFS_ACCEL*/
11255 if (bp
->link_info
.phy_retry
) {
11256 if (time_after(jiffies
, bp
->link_info
.phy_retry_expires
)) {
11257 bp
->link_info
.phy_retry
= false;
11258 netdev_warn(bp
->dev
, "failed to update phy settings after maximum retries.\n");
11260 set_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
);
11261 bnxt_queue_sp_work(bp
);
11265 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && !bp
->chip_rev
&&
11266 netif_carrier_ok(dev
)) {
11267 set_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
);
11268 bnxt_queue_sp_work(bp
);
11270 bnxt_restart_timer
:
11271 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
11274 static void bnxt_rtnl_lock_sp(struct bnxt
*bp
)
11276 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
11277 * set. If the device is being closed, bnxt_close() may be holding
11278 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
11279 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
11281 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
11285 static void bnxt_rtnl_unlock_sp(struct bnxt
*bp
)
11287 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
11291 /* Only called from bnxt_sp_task() */
11292 static void bnxt_reset(struct bnxt
*bp
, bool silent
)
11294 bnxt_rtnl_lock_sp(bp
);
11295 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
))
11296 bnxt_reset_task(bp
, silent
);
11297 bnxt_rtnl_unlock_sp(bp
);
11300 /* Only called from bnxt_sp_task() */
11301 static void bnxt_rx_ring_reset(struct bnxt
*bp
)
11305 bnxt_rtnl_lock_sp(bp
);
11306 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
11307 bnxt_rtnl_unlock_sp(bp
);
11310 /* Disable and flush TPA before resetting the RX ring */
11311 if (bp
->flags
& BNXT_FLAG_TPA
)
11312 bnxt_set_tpa(bp
, false);
11313 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
11314 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
11315 struct bnxt_cp_ring_info
*cpr
;
11318 if (!rxr
->bnapi
->in_reset
)
11321 rc
= bnxt_hwrm_rx_ring_reset(bp
, i
);
11323 if (rc
== -EINVAL
|| rc
== -EOPNOTSUPP
)
11324 netdev_info_once(bp
->dev
, "RX ring reset not supported by firmware, falling back to global reset\n");
11326 netdev_warn(bp
->dev
, "RX ring reset failed, rc = %d, falling back to global reset\n",
11328 bnxt_reset_task(bp
, true);
11331 bnxt_free_one_rx_ring_skbs(bp
, i
);
11333 rxr
->rx_agg_prod
= 0;
11334 rxr
->rx_sw_agg_prod
= 0;
11335 rxr
->rx_next_cons
= 0;
11336 rxr
->bnapi
->in_reset
= false;
11337 bnxt_alloc_one_rx_ring(bp
, i
);
11338 cpr
= &rxr
->bnapi
->cp_ring
;
11339 cpr
->sw_stats
.rx
.rx_resets
++;
11340 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
11341 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
11342 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
11344 if (bp
->flags
& BNXT_FLAG_TPA
)
11345 bnxt_set_tpa(bp
, true);
11346 bnxt_rtnl_unlock_sp(bp
);
11349 static void bnxt_fw_reset_close(struct bnxt
*bp
)
11352 /* When firmware is in fatal state, quiesce device and disable
11353 * bus master to prevent any potential bad DMAs before freeing
11356 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
)) {
11359 pci_read_config_word(bp
->pdev
, PCI_SUBSYSTEM_ID
, &val
);
11361 bp
->fw_reset_min_dsecs
= 0;
11362 bnxt_tx_disable(bp
);
11363 bnxt_disable_napi(bp
);
11364 bnxt_disable_int_sync(bp
);
11366 bnxt_clear_int_mode(bp
);
11367 pci_disable_device(bp
->pdev
);
11369 bnxt_ptp_clear(bp
);
11370 __bnxt_close_nic(bp
, true, false);
11371 bnxt_vf_reps_free(bp
);
11372 bnxt_clear_int_mode(bp
);
11373 bnxt_hwrm_func_drv_unrgtr(bp
);
11374 if (pci_is_enabled(bp
->pdev
))
11375 pci_disable_device(bp
->pdev
);
11376 bnxt_free_ctx_mem(bp
);
11381 static bool is_bnxt_fw_ok(struct bnxt
*bp
)
11383 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11384 bool no_heartbeat
= false, has_reset
= false;
11387 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
11388 if (val
== fw_health
->last_fw_heartbeat
)
11389 no_heartbeat
= true;
11391 val
= bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
11392 if (val
!= fw_health
->last_fw_reset_cnt
)
11395 if (!no_heartbeat
&& has_reset
)
11401 /* rtnl_lock is acquired before calling this function */
11402 static void bnxt_force_fw_reset(struct bnxt
*bp
)
11404 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11407 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
) ||
11408 test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
11411 set_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
11412 bnxt_fw_reset_close(bp
);
11413 wait_dsecs
= fw_health
->master_func_wait_dsecs
;
11414 if (fw_health
->master
) {
11415 if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
)
11417 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_RESET_FW
;
11419 bp
->fw_reset_timestamp
= jiffies
+ wait_dsecs
* HZ
/ 10;
11420 wait_dsecs
= fw_health
->normal_func_wait_dsecs
;
11421 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
11424 bp
->fw_reset_min_dsecs
= fw_health
->post_reset_wait_dsecs
;
11425 bp
->fw_reset_max_dsecs
= fw_health
->post_reset_max_wait_dsecs
;
11426 bnxt_queue_fw_reset_work(bp
, wait_dsecs
* HZ
/ 10);
11429 void bnxt_fw_exception(struct bnxt
*bp
)
11431 netdev_warn(bp
->dev
, "Detected firmware fatal condition, initiating reset\n");
11432 set_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
11433 bnxt_rtnl_lock_sp(bp
);
11434 bnxt_force_fw_reset(bp
);
11435 bnxt_rtnl_unlock_sp(bp
);
11438 /* Returns the number of registered VFs, or 1 if VF configuration is pending, or
11441 static int bnxt_get_registered_vfs(struct bnxt
*bp
)
11443 #ifdef CONFIG_BNXT_SRIOV
11449 rc
= bnxt_hwrm_func_qcfg(bp
);
11451 netdev_err(bp
->dev
, "func_qcfg cmd failed, rc = %d\n", rc
);
11454 if (bp
->pf
.registered_vfs
)
11455 return bp
->pf
.registered_vfs
;
11462 void bnxt_fw_reset(struct bnxt
*bp
)
11464 bnxt_rtnl_lock_sp(bp
);
11465 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
) &&
11466 !test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
11469 set_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
11470 if (bp
->pf
.active_vfs
&&
11471 !test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
11472 n
= bnxt_get_registered_vfs(bp
);
11474 netdev_err(bp
->dev
, "Firmware reset aborted, rc = %d\n",
11476 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
11477 dev_close(bp
->dev
);
11478 goto fw_reset_exit
;
11479 } else if (n
> 0) {
11480 u16 vf_tmo_dsecs
= n
* 10;
11482 if (bp
->fw_reset_max_dsecs
< vf_tmo_dsecs
)
11483 bp
->fw_reset_max_dsecs
= vf_tmo_dsecs
;
11484 bp
->fw_reset_state
=
11485 BNXT_FW_RESET_STATE_POLL_VF
;
11486 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
11487 goto fw_reset_exit
;
11489 bnxt_fw_reset_close(bp
);
11490 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
11491 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW_DOWN
;
11494 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
11495 tmo
= bp
->fw_reset_min_dsecs
* HZ
/ 10;
11497 bnxt_queue_fw_reset_work(bp
, tmo
);
11500 bnxt_rtnl_unlock_sp(bp
);
11503 static void bnxt_chk_missed_irq(struct bnxt
*bp
)
11507 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
11510 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
11511 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
11512 struct bnxt_cp_ring_info
*cpr
;
11519 cpr
= &bnapi
->cp_ring
;
11520 for (j
= 0; j
< 2; j
++) {
11521 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
11524 if (!cpr2
|| cpr2
->has_more_work
||
11525 !bnxt_has_work(bp
, cpr2
))
11528 if (cpr2
->cp_raw_cons
!= cpr2
->last_cp_raw_cons
) {
11529 cpr2
->last_cp_raw_cons
= cpr2
->cp_raw_cons
;
11532 fw_ring_id
= cpr2
->cp_ring_struct
.fw_ring_id
;
11533 bnxt_dbg_hwrm_ring_info_get(bp
,
11534 DBG_RING_INFO_GET_REQ_RING_TYPE_L2_CMPL
,
11535 fw_ring_id
, &val
[0], &val
[1]);
11536 cpr
->sw_stats
.cmn
.missed_irqs
++;
11541 static void bnxt_cfg_ntp_filters(struct bnxt
*);
11543 static void bnxt_init_ethtool_link_settings(struct bnxt
*bp
)
11545 struct bnxt_link_info
*link_info
= &bp
->link_info
;
11547 if (BNXT_AUTO_MODE(link_info
->auto_mode
)) {
11548 link_info
->autoneg
= BNXT_AUTONEG_SPEED
;
11549 if (bp
->hwrm_spec_code
>= 0x10201) {
11550 if (link_info
->auto_pause_setting
&
11551 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
)
11552 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
11554 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
11556 link_info
->advertising
= link_info
->auto_link_speeds
;
11557 link_info
->advertising_pam4
= link_info
->auto_pam4_link_speeds
;
11559 link_info
->req_link_speed
= link_info
->force_link_speed
;
11560 link_info
->req_signal_mode
= BNXT_SIG_MODE_NRZ
;
11561 if (link_info
->force_pam4_link_speed
) {
11562 link_info
->req_link_speed
=
11563 link_info
->force_pam4_link_speed
;
11564 link_info
->req_signal_mode
= BNXT_SIG_MODE_PAM4
;
11566 link_info
->req_duplex
= link_info
->duplex_setting
;
11568 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
11569 link_info
->req_flow_ctrl
=
11570 link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
;
11572 link_info
->req_flow_ctrl
= link_info
->force_pause_setting
;
11575 static void bnxt_fw_echo_reply(struct bnxt
*bp
)
11577 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11578 struct hwrm_func_echo_response_input req
= {0};
11580 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_ECHO_RESPONSE
, -1, -1);
11581 req
.event_data1
= cpu_to_le32(fw_health
->echo_req_data1
);
11582 req
.event_data2
= cpu_to_le32(fw_health
->echo_req_data2
);
11583 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
11586 static void bnxt_sp_task(struct work_struct
*work
)
11588 struct bnxt
*bp
= container_of(work
, struct bnxt
, sp_task
);
11590 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
11591 smp_mb__after_atomic();
11592 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
11593 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
11597 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
))
11598 bnxt_cfg_rx_mode(bp
);
11600 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
))
11601 bnxt_cfg_ntp_filters(bp
);
11602 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
))
11603 bnxt_hwrm_exec_fwd_req(bp
);
11604 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
)) {
11605 bnxt_hwrm_port_qstats(bp
, 0);
11606 bnxt_hwrm_port_qstats_ext(bp
, 0);
11607 bnxt_accumulate_all_stats(bp
);
11610 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
)) {
11613 mutex_lock(&bp
->link_lock
);
11614 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
,
11616 bnxt_hwrm_phy_qcaps(bp
);
11618 rc
= bnxt_update_link(bp
, true);
11620 netdev_err(bp
->dev
, "SP task can't update link (rc: %x)\n",
11623 if (test_and_clear_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT
,
11625 bnxt_init_ethtool_link_settings(bp
);
11626 mutex_unlock(&bp
->link_lock
);
11628 if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
)) {
11631 mutex_lock(&bp
->link_lock
);
11632 rc
= bnxt_update_phy_setting(bp
);
11633 mutex_unlock(&bp
->link_lock
);
11635 netdev_warn(bp
->dev
, "update phy settings retry failed\n");
11637 bp
->link_info
.phy_retry
= false;
11638 netdev_info(bp
->dev
, "update phy settings retry succeeded\n");
11641 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
)) {
11642 mutex_lock(&bp
->link_lock
);
11643 bnxt_get_port_module_status(bp
);
11644 mutex_unlock(&bp
->link_lock
);
11647 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
))
11648 bnxt_tc_flow_stats_work(bp
);
11650 if (test_and_clear_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
))
11651 bnxt_chk_missed_irq(bp
);
11653 if (test_and_clear_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT
, &bp
->sp_event
))
11654 bnxt_fw_echo_reply(bp
);
11656 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
11657 * must be the last functions to be called before exiting.
11659 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
))
11660 bnxt_reset(bp
, false);
11662 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
))
11663 bnxt_reset(bp
, true);
11665 if (test_and_clear_bit(BNXT_RST_RING_SP_EVENT
, &bp
->sp_event
))
11666 bnxt_rx_ring_reset(bp
);
11668 if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT
, &bp
->sp_event
))
11669 bnxt_devlink_health_report(bp
, BNXT_FW_RESET_NOTIFY_SP_EVENT
);
11671 if (test_and_clear_bit(BNXT_FW_EXCEPTION_SP_EVENT
, &bp
->sp_event
)) {
11672 if (!is_bnxt_fw_ok(bp
))
11673 bnxt_devlink_health_report(bp
,
11674 BNXT_FW_EXCEPTION_SP_EVENT
);
11677 smp_mb__before_atomic();
11678 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
11681 /* Under rtnl_lock */
11682 int bnxt_check_rings(struct bnxt
*bp
, int tx
, int rx
, bool sh
, int tcs
,
11685 int max_rx
, max_tx
, tx_sets
= 1;
11686 int tx_rings_needed
, stats
;
11693 rc
= bnxt_get_max_rings(bp
, &max_rx
, &max_tx
, sh
);
11700 tx_rings_needed
= tx
* tx_sets
+ tx_xdp
;
11701 if (max_tx
< tx_rings_needed
)
11705 if ((bp
->flags
& (BNXT_FLAG_RFS
| BNXT_FLAG_CHIP_P5
)) == BNXT_FLAG_RFS
)
11708 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
11710 cp
= sh
? max_t(int, tx_rings_needed
, rx
) : tx_rings_needed
+ rx
;
11712 if (BNXT_NEW_RM(bp
)) {
11713 cp
+= bnxt_get_ulp_msix_num(bp
);
11714 stats
+= bnxt_get_ulp_stat_ctxs(bp
);
11716 return bnxt_hwrm_check_rings(bp
, tx_rings_needed
, rx_rings
, rx
, cp
,
11720 static void bnxt_unmap_bars(struct bnxt
*bp
, struct pci_dev
*pdev
)
11723 pci_iounmap(pdev
, bp
->bar2
);
11728 pci_iounmap(pdev
, bp
->bar1
);
11733 pci_iounmap(pdev
, bp
->bar0
);
11738 static void bnxt_cleanup_pci(struct bnxt
*bp
)
11740 bnxt_unmap_bars(bp
, bp
->pdev
);
11741 pci_release_regions(bp
->pdev
);
11742 if (pci_is_enabled(bp
->pdev
))
11743 pci_disable_device(bp
->pdev
);
11746 static void bnxt_init_dflt_coal(struct bnxt
*bp
)
11748 struct bnxt_coal
*coal
;
11750 /* Tick values in micro seconds.
11751 * 1 coal_buf x bufs_per_record = 1 completion record.
11753 coal
= &bp
->rx_coal
;
11754 coal
->coal_ticks
= 10;
11755 coal
->coal_bufs
= 30;
11756 coal
->coal_ticks_irq
= 1;
11757 coal
->coal_bufs_irq
= 2;
11758 coal
->idle_thresh
= 50;
11759 coal
->bufs_per_record
= 2;
11760 coal
->budget
= 64; /* NAPI budget */
11762 coal
= &bp
->tx_coal
;
11763 coal
->coal_ticks
= 28;
11764 coal
->coal_bufs
= 30;
11765 coal
->coal_ticks_irq
= 2;
11766 coal
->coal_bufs_irq
= 2;
11767 coal
->bufs_per_record
= 1;
11769 bp
->stats_coal_ticks
= BNXT_DEF_STATS_COAL_TICKS
;
11772 static int bnxt_fw_init_one_p1(struct bnxt
*bp
)
11777 rc
= bnxt_hwrm_ver_get(bp
);
11778 bnxt_try_map_fw_health_reg(bp
);
11780 rc
= bnxt_try_recover_fw(bp
);
11783 rc
= bnxt_hwrm_ver_get(bp
);
11788 if (bp
->fw_cap
& BNXT_FW_CAP_KONG_MB_CHNL
) {
11789 rc
= bnxt_alloc_kong_hwrm_resources(bp
);
11791 bp
->fw_cap
&= ~BNXT_FW_CAP_KONG_MB_CHNL
;
11794 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
11795 bp
->hwrm_max_ext_req_len
> BNXT_HWRM_MAX_REQ_LEN
) {
11796 rc
= bnxt_alloc_hwrm_short_cmd_req(bp
);
11800 bnxt_nvm_cfg_ver_get(bp
);
11802 rc
= bnxt_hwrm_func_reset(bp
);
11806 bnxt_hwrm_fw_set_time(bp
);
11810 static int bnxt_fw_init_one_p2(struct bnxt
*bp
)
11814 /* Get the MAX capabilities for this function */
11815 rc
= bnxt_hwrm_func_qcaps(bp
);
11817 netdev_err(bp
->dev
, "hwrm query capability failure rc: %x\n",
11822 rc
= bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(bp
);
11824 netdev_warn(bp
->dev
, "hwrm query adv flow mgnt failure rc: %d\n",
11827 if (bnxt_alloc_fw_health(bp
)) {
11828 netdev_warn(bp
->dev
, "no memory for firmware error recovery\n");
11830 rc
= bnxt_hwrm_error_recovery_qcfg(bp
);
11832 netdev_warn(bp
->dev
, "hwrm query error recovery failure rc: %d\n",
11836 rc
= bnxt_hwrm_func_drv_rgtr(bp
, NULL
, 0, false);
11840 bnxt_hwrm_func_qcfg(bp
);
11841 bnxt_hwrm_vnic_qcaps(bp
);
11842 bnxt_hwrm_port_led_qcaps(bp
);
11843 bnxt_ethtool_init(bp
);
11848 static void bnxt_set_dflt_rss_hash_type(struct bnxt
*bp
)
11850 bp
->flags
&= ~BNXT_FLAG_UDP_RSS_CAP
;
11851 bp
->rss_hash_cfg
= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
|
11852 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
|
11853 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
|
11854 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
11855 if (BNXT_CHIP_P4_PLUS(bp
) && bp
->hwrm_spec_code
>= 0x10501) {
11856 bp
->flags
|= BNXT_FLAG_UDP_RSS_CAP
;
11857 bp
->rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
|
11858 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
11862 static void bnxt_set_dflt_rfs(struct bnxt
*bp
)
11864 struct net_device
*dev
= bp
->dev
;
11866 dev
->hw_features
&= ~NETIF_F_NTUPLE
;
11867 dev
->features
&= ~NETIF_F_NTUPLE
;
11868 bp
->flags
&= ~BNXT_FLAG_RFS
;
11869 if (bnxt_rfs_supported(bp
)) {
11870 dev
->hw_features
|= NETIF_F_NTUPLE
;
11871 if (bnxt_rfs_capable(bp
)) {
11872 bp
->flags
|= BNXT_FLAG_RFS
;
11873 dev
->features
|= NETIF_F_NTUPLE
;
11878 static void bnxt_fw_init_one_p3(struct bnxt
*bp
)
11880 struct pci_dev
*pdev
= bp
->pdev
;
11882 bnxt_set_dflt_rss_hash_type(bp
);
11883 bnxt_set_dflt_rfs(bp
);
11885 bnxt_get_wol_settings(bp
);
11886 if (bp
->flags
& BNXT_FLAG_WOL_CAP
)
11887 device_set_wakeup_enable(&pdev
->dev
, bp
->wol
);
11889 device_set_wakeup_capable(&pdev
->dev
, false);
11891 bnxt_hwrm_set_cache_line_size(bp
, cache_line_size());
11892 bnxt_hwrm_coal_params_qcaps(bp
);
11895 static int bnxt_probe_phy(struct bnxt
*bp
, bool fw_dflt
);
11897 static int bnxt_fw_init_one(struct bnxt
*bp
)
11901 rc
= bnxt_fw_init_one_p1(bp
);
11903 netdev_err(bp
->dev
, "Firmware init phase 1 failed\n");
11906 rc
= bnxt_fw_init_one_p2(bp
);
11908 netdev_err(bp
->dev
, "Firmware init phase 2 failed\n");
11911 rc
= bnxt_probe_phy(bp
, false);
11914 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, false);
11918 /* In case fw capabilities have changed, destroy the unneeded
11919 * reporters and create newly capable ones.
11921 bnxt_dl_fw_reporters_destroy(bp
, false);
11922 bnxt_dl_fw_reporters_create(bp
);
11923 bnxt_fw_init_one_p3(bp
);
11927 static void bnxt_fw_reset_writel(struct bnxt
*bp
, int reg_idx
)
11929 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11930 u32 reg
= fw_health
->fw_reset_seq_regs
[reg_idx
];
11931 u32 val
= fw_health
->fw_reset_seq_vals
[reg_idx
];
11932 u32 reg_type
, reg_off
, delay_msecs
;
11934 delay_msecs
= fw_health
->fw_reset_seq_delay_msec
[reg_idx
];
11935 reg_type
= BNXT_FW_HEALTH_REG_TYPE(reg
);
11936 reg_off
= BNXT_FW_HEALTH_REG_OFF(reg
);
11937 switch (reg_type
) {
11938 case BNXT_FW_HEALTH_REG_TYPE_CFG
:
11939 pci_write_config_dword(bp
->pdev
, reg_off
, val
);
11941 case BNXT_FW_HEALTH_REG_TYPE_GRC
:
11942 writel(reg_off
& BNXT_GRC_BASE_MASK
,
11943 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 4);
11944 reg_off
= (reg_off
& BNXT_GRC_OFFSET_MASK
) + 0x2000;
11946 case BNXT_FW_HEALTH_REG_TYPE_BAR0
:
11947 writel(val
, bp
->bar0
+ reg_off
);
11949 case BNXT_FW_HEALTH_REG_TYPE_BAR1
:
11950 writel(val
, bp
->bar1
+ reg_off
);
11954 pci_read_config_dword(bp
->pdev
, 0, &val
);
11955 msleep(delay_msecs
);
11959 static void bnxt_reset_all(struct bnxt
*bp
)
11961 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
11964 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
11965 bnxt_fw_reset_via_optee(bp
);
11966 bp
->fw_reset_timestamp
= jiffies
;
11970 if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_HOST
) {
11971 for (i
= 0; i
< fw_health
->fw_reset_seq_cnt
; i
++)
11972 bnxt_fw_reset_writel(bp
, i
);
11973 } else if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
) {
11974 struct hwrm_fw_reset_input req
= {0};
11976 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_RESET
, -1, -1);
11977 req
.resp_addr
= cpu_to_le64(bp
->hwrm_cmd_kong_resp_dma_addr
);
11978 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP
;
11979 req
.selfrst_status
= FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP
;
11980 req
.flags
= FW_RESET_REQ_FLAGS_RESET_GRACEFUL
;
11981 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
11983 netdev_warn(bp
->dev
, "Unable to reset FW rc=%d\n", rc
);
11985 bp
->fw_reset_timestamp
= jiffies
;
11988 static bool bnxt_fw_reset_timeout(struct bnxt
*bp
)
11990 return time_after(jiffies
, bp
->fw_reset_timestamp
+
11991 (bp
->fw_reset_max_dsecs
* HZ
/ 10));
11994 static void bnxt_fw_reset_abort(struct bnxt
*bp
, int rc
)
11996 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
11997 if (bp
->fw_reset_state
!= BNXT_FW_RESET_STATE_POLL_VF
) {
11998 bnxt_ulp_start(bp
, rc
);
11999 bnxt_dl_health_status_update(bp
, false);
12001 bp
->fw_reset_state
= 0;
12002 dev_close(bp
->dev
);
12005 static void bnxt_fw_reset_task(struct work_struct
*work
)
12007 struct bnxt
*bp
= container_of(work
, struct bnxt
, fw_reset_task
.work
);
12010 if (!test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
12011 netdev_err(bp
->dev
, "bnxt_fw_reset_task() called when not in fw reset mode!\n");
12015 switch (bp
->fw_reset_state
) {
12016 case BNXT_FW_RESET_STATE_POLL_VF
: {
12017 int n
= bnxt_get_registered_vfs(bp
);
12021 netdev_err(bp
->dev
, "Firmware reset aborted, subsequent func_qcfg cmd failed, rc = %d, %d msecs since reset timestamp\n",
12022 n
, jiffies_to_msecs(jiffies
-
12023 bp
->fw_reset_timestamp
));
12024 goto fw_reset_abort
;
12025 } else if (n
> 0) {
12026 if (bnxt_fw_reset_timeout(bp
)) {
12027 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
12028 bp
->fw_reset_state
= 0;
12029 netdev_err(bp
->dev
, "Firmware reset aborted, bnxt_get_registered_vfs() returns %d\n",
12033 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
12036 bp
->fw_reset_timestamp
= jiffies
;
12038 if (test_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
)) {
12039 bnxt_fw_reset_abort(bp
, rc
);
12043 bnxt_fw_reset_close(bp
);
12044 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
12045 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW_DOWN
;
12048 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
12049 tmo
= bp
->fw_reset_min_dsecs
* HZ
/ 10;
12052 bnxt_queue_fw_reset_work(bp
, tmo
);
12055 case BNXT_FW_RESET_STATE_POLL_FW_DOWN
: {
12058 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
);
12059 if (!(val
& BNXT_FW_STATUS_SHUTDOWN
) &&
12060 !bnxt_fw_reset_timeout(bp
)) {
12061 bnxt_queue_fw_reset_work(bp
, HZ
/ 5);
12065 if (!bp
->fw_health
->master
) {
12066 u32 wait_dsecs
= bp
->fw_health
->normal_func_wait_dsecs
;
12068 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
12069 bnxt_queue_fw_reset_work(bp
, wait_dsecs
* HZ
/ 10);
12072 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_RESET_FW
;
12075 case BNXT_FW_RESET_STATE_RESET_FW
:
12076 bnxt_reset_all(bp
);
12077 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
12078 bnxt_queue_fw_reset_work(bp
, bp
->fw_reset_min_dsecs
* HZ
/ 10);
12080 case BNXT_FW_RESET_STATE_ENABLE_DEV
:
12081 bnxt_inv_fw_health_reg(bp
);
12082 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
) &&
12083 !bp
->fw_reset_min_dsecs
) {
12086 pci_read_config_word(bp
->pdev
, PCI_SUBSYSTEM_ID
, &val
);
12087 if (val
== 0xffff) {
12088 if (bnxt_fw_reset_timeout(bp
)) {
12089 netdev_err(bp
->dev
, "Firmware reset aborted, PCI config space invalid\n");
12091 goto fw_reset_abort
;
12093 bnxt_queue_fw_reset_work(bp
, HZ
/ 1000);
12097 clear_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
12098 if (pci_enable_device(bp
->pdev
)) {
12099 netdev_err(bp
->dev
, "Cannot re-enable PCI device\n");
12101 goto fw_reset_abort
;
12103 pci_set_master(bp
->pdev
);
12104 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW
;
12106 case BNXT_FW_RESET_STATE_POLL_FW
:
12107 bp
->hwrm_cmd_timeout
= SHORT_HWRM_CMD_TIMEOUT
;
12108 rc
= __bnxt_hwrm_ver_get(bp
, true);
12110 if (bnxt_fw_reset_timeout(bp
)) {
12111 netdev_err(bp
->dev
, "Firmware reset aborted\n");
12112 goto fw_reset_abort_status
;
12114 bnxt_queue_fw_reset_work(bp
, HZ
/ 5);
12117 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
12118 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_OPENING
;
12120 case BNXT_FW_RESET_STATE_OPENING
:
12121 while (!rtnl_trylock()) {
12122 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
12125 rc
= bnxt_open(bp
->dev
);
12127 netdev_err(bp
->dev
, "bnxt_open() failed during FW reset\n");
12128 bnxt_fw_reset_abort(bp
, rc
);
12133 bp
->fw_reset_state
= 0;
12134 /* Make sure fw_reset_state is 0 before clearing the flag */
12135 smp_mb__before_atomic();
12136 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
12137 bnxt_ulp_start(bp
, 0);
12138 bnxt_reenable_sriov(bp
);
12139 bnxt_vf_reps_alloc(bp
);
12140 bnxt_vf_reps_open(bp
);
12141 bnxt_dl_health_recovery_done(bp
);
12142 bnxt_dl_health_status_update(bp
, true);
12148 fw_reset_abort_status
:
12149 if (bp
->fw_health
->status_reliable
||
12150 (bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
)) {
12151 u32 sts
= bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
);
12153 netdev_err(bp
->dev
, "fw_health_status 0x%x\n", sts
);
12157 bnxt_fw_reset_abort(bp
, rc
);
12161 static int bnxt_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
12164 struct bnxt
*bp
= netdev_priv(dev
);
12166 SET_NETDEV_DEV(dev
, &pdev
->dev
);
12168 /* enable device (incl. PCI PM wakeup), and bus-mastering */
12169 rc
= pci_enable_device(pdev
);
12171 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
12175 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
12176 dev_err(&pdev
->dev
,
12177 "Cannot find PCI device base address, aborting\n");
12179 goto init_err_disable
;
12182 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
12184 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
12185 goto init_err_disable
;
12188 if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64)) != 0 &&
12189 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)) != 0) {
12190 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
12192 goto init_err_release
;
12195 pci_set_master(pdev
);
12200 /* Doorbell BAR bp->bar1 is mapped after bnxt_fw_init_one_p2()
12201 * determines the BAR size.
12203 bp
->bar0
= pci_ioremap_bar(pdev
, 0);
12205 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
12207 goto init_err_release
;
12210 bp
->bar2
= pci_ioremap_bar(pdev
, 4);
12212 dev_err(&pdev
->dev
, "Cannot map bar4 registers, aborting\n");
12214 goto init_err_release
;
12217 pci_enable_pcie_error_reporting(pdev
);
12219 INIT_WORK(&bp
->sp_task
, bnxt_sp_task
);
12220 INIT_DELAYED_WORK(&bp
->fw_reset_task
, bnxt_fw_reset_task
);
12222 spin_lock_init(&bp
->ntp_fltr_lock
);
12223 #if BITS_PER_LONG == 32
12224 spin_lock_init(&bp
->db_lock
);
12227 bp
->rx_ring_size
= BNXT_DEFAULT_RX_RING_SIZE
;
12228 bp
->tx_ring_size
= BNXT_DEFAULT_TX_RING_SIZE
;
12230 bnxt_init_dflt_coal(bp
);
12232 timer_setup(&bp
->timer
, bnxt_timer
, 0);
12233 bp
->current_interval
= BNXT_TIMER_INTERVAL
;
12235 bp
->vxlan_fw_dst_port_id
= INVALID_HW_RING_ID
;
12236 bp
->nge_fw_dst_port_id
= INVALID_HW_RING_ID
;
12238 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
12242 bnxt_unmap_bars(bp
, pdev
);
12243 pci_release_regions(pdev
);
12246 pci_disable_device(pdev
);
12252 /* rtnl_lock held */
12253 static int bnxt_change_mac_addr(struct net_device
*dev
, void *p
)
12255 struct sockaddr
*addr
= p
;
12256 struct bnxt
*bp
= netdev_priv(dev
);
12259 if (!is_valid_ether_addr(addr
->sa_data
))
12260 return -EADDRNOTAVAIL
;
12262 if (ether_addr_equal(addr
->sa_data
, dev
->dev_addr
))
12265 rc
= bnxt_approve_mac(bp
, addr
->sa_data
, true);
12269 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
12270 if (netif_running(dev
)) {
12271 bnxt_close_nic(bp
, false, false);
12272 rc
= bnxt_open_nic(bp
, false, false);
12278 /* rtnl_lock held */
12279 static int bnxt_change_mtu(struct net_device
*dev
, int new_mtu
)
12281 struct bnxt
*bp
= netdev_priv(dev
);
12283 if (netif_running(dev
))
12284 bnxt_close_nic(bp
, true, false);
12286 dev
->mtu
= new_mtu
;
12287 bnxt_set_ring_params(bp
);
12289 if (netif_running(dev
))
12290 return bnxt_open_nic(bp
, true, false);
12295 int bnxt_setup_mq_tc(struct net_device
*dev
, u8 tc
)
12297 struct bnxt
*bp
= netdev_priv(dev
);
12301 if (tc
> bp
->max_tc
) {
12302 netdev_err(dev
, "Too many traffic classes requested: %d. Max supported is %d.\n",
12307 if (netdev_get_num_tc(dev
) == tc
)
12310 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
12313 rc
= bnxt_check_rings(bp
, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
,
12314 sh
, tc
, bp
->tx_nr_rings_xdp
);
12318 /* Needs to close the device and do hw resource re-allocations */
12319 if (netif_running(bp
->dev
))
12320 bnxt_close_nic(bp
, true, false);
12323 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tc
;
12324 netdev_set_num_tc(dev
, tc
);
12326 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
12327 netdev_reset_tc(dev
);
12329 bp
->tx_nr_rings
+= bp
->tx_nr_rings_xdp
;
12330 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
12331 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
12333 if (netif_running(bp
->dev
))
12334 return bnxt_open_nic(bp
, true, false);
12339 static int bnxt_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
12342 struct bnxt
*bp
= cb_priv
;
12344 if (!bnxt_tc_flower_enabled(bp
) ||
12345 !tc_cls_can_offload_and_chain0(bp
->dev
, type_data
))
12346 return -EOPNOTSUPP
;
12349 case TC_SETUP_CLSFLOWER
:
12350 return bnxt_tc_setup_flower(bp
, bp
->pf
.fw_fid
, type_data
);
12352 return -EOPNOTSUPP
;
12356 LIST_HEAD(bnxt_block_cb_list
);
12358 static int bnxt_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
12361 struct bnxt
*bp
= netdev_priv(dev
);
12364 case TC_SETUP_BLOCK
:
12365 return flow_block_cb_setup_simple(type_data
,
12366 &bnxt_block_cb_list
,
12367 bnxt_setup_tc_block_cb
,
12369 case TC_SETUP_QDISC_MQPRIO
: {
12370 struct tc_mqprio_qopt
*mqprio
= type_data
;
12372 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
12374 return bnxt_setup_mq_tc(dev
, mqprio
->num_tc
);
12377 return -EOPNOTSUPP
;
12381 #ifdef CONFIG_RFS_ACCEL
12382 static bool bnxt_fltr_match(struct bnxt_ntuple_filter
*f1
,
12383 struct bnxt_ntuple_filter
*f2
)
12385 struct flow_keys
*keys1
= &f1
->fkeys
;
12386 struct flow_keys
*keys2
= &f2
->fkeys
;
12388 if (keys1
->basic
.n_proto
!= keys2
->basic
.n_proto
||
12389 keys1
->basic
.ip_proto
!= keys2
->basic
.ip_proto
)
12392 if (keys1
->basic
.n_proto
== htons(ETH_P_IP
)) {
12393 if (keys1
->addrs
.v4addrs
.src
!= keys2
->addrs
.v4addrs
.src
||
12394 keys1
->addrs
.v4addrs
.dst
!= keys2
->addrs
.v4addrs
.dst
)
12397 if (memcmp(&keys1
->addrs
.v6addrs
.src
, &keys2
->addrs
.v6addrs
.src
,
12398 sizeof(keys1
->addrs
.v6addrs
.src
)) ||
12399 memcmp(&keys1
->addrs
.v6addrs
.dst
, &keys2
->addrs
.v6addrs
.dst
,
12400 sizeof(keys1
->addrs
.v6addrs
.dst
)))
12404 if (keys1
->ports
.ports
== keys2
->ports
.ports
&&
12405 keys1
->control
.flags
== keys2
->control
.flags
&&
12406 ether_addr_equal(f1
->src_mac_addr
, f2
->src_mac_addr
) &&
12407 ether_addr_equal(f1
->dst_mac_addr
, f2
->dst_mac_addr
))
12413 static int bnxt_rx_flow_steer(struct net_device
*dev
, const struct sk_buff
*skb
,
12414 u16 rxq_index
, u32 flow_id
)
12416 struct bnxt
*bp
= netdev_priv(dev
);
12417 struct bnxt_ntuple_filter
*fltr
, *new_fltr
;
12418 struct flow_keys
*fkeys
;
12419 struct ethhdr
*eth
= (struct ethhdr
*)skb_mac_header(skb
);
12420 int rc
= 0, idx
, bit_id
, l2_idx
= 0;
12421 struct hlist_head
*head
;
12424 if (!ether_addr_equal(dev
->dev_addr
, eth
->h_dest
)) {
12425 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
12428 netif_addr_lock_bh(dev
);
12429 for (j
= 0; j
< vnic
->uc_filter_count
; j
++, off
+= ETH_ALEN
) {
12430 if (ether_addr_equal(eth
->h_dest
,
12431 vnic
->uc_list
+ off
)) {
12436 netif_addr_unlock_bh(dev
);
12440 new_fltr
= kzalloc(sizeof(*new_fltr
), GFP_ATOMIC
);
12444 fkeys
= &new_fltr
->fkeys
;
12445 if (!skb_flow_dissect_flow_keys(skb
, fkeys
, 0)) {
12446 rc
= -EPROTONOSUPPORT
;
12450 if ((fkeys
->basic
.n_proto
!= htons(ETH_P_IP
) &&
12451 fkeys
->basic
.n_proto
!= htons(ETH_P_IPV6
)) ||
12452 ((fkeys
->basic
.ip_proto
!= IPPROTO_TCP
) &&
12453 (fkeys
->basic
.ip_proto
!= IPPROTO_UDP
))) {
12454 rc
= -EPROTONOSUPPORT
;
12457 if (fkeys
->basic
.n_proto
== htons(ETH_P_IPV6
) &&
12458 bp
->hwrm_spec_code
< 0x10601) {
12459 rc
= -EPROTONOSUPPORT
;
12462 flags
= fkeys
->control
.flags
;
12463 if (((flags
& FLOW_DIS_ENCAPSULATION
) &&
12464 bp
->hwrm_spec_code
< 0x10601) || (flags
& FLOW_DIS_IS_FRAGMENT
)) {
12465 rc
= -EPROTONOSUPPORT
;
12469 memcpy(new_fltr
->dst_mac_addr
, eth
->h_dest
, ETH_ALEN
);
12470 memcpy(new_fltr
->src_mac_addr
, eth
->h_source
, ETH_ALEN
);
12472 idx
= skb_get_hash_raw(skb
) & BNXT_NTP_FLTR_HASH_MASK
;
12473 head
= &bp
->ntp_fltr_hash_tbl
[idx
];
12475 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
12476 if (bnxt_fltr_match(fltr
, new_fltr
)) {
12484 spin_lock_bh(&bp
->ntp_fltr_lock
);
12485 bit_id
= bitmap_find_free_region(bp
->ntp_fltr_bmap
,
12486 BNXT_NTP_FLTR_MAX_FLTR
, 0);
12488 spin_unlock_bh(&bp
->ntp_fltr_lock
);
12493 new_fltr
->sw_id
= (u16
)bit_id
;
12494 new_fltr
->flow_id
= flow_id
;
12495 new_fltr
->l2_fltr_idx
= l2_idx
;
12496 new_fltr
->rxq
= rxq_index
;
12497 hlist_add_head_rcu(&new_fltr
->hash
, head
);
12498 bp
->ntp_fltr_count
++;
12499 spin_unlock_bh(&bp
->ntp_fltr_lock
);
12501 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
12502 bnxt_queue_sp_work(bp
);
12504 return new_fltr
->sw_id
;
12511 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
12515 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
12516 struct hlist_head
*head
;
12517 struct hlist_node
*tmp
;
12518 struct bnxt_ntuple_filter
*fltr
;
12521 head
= &bp
->ntp_fltr_hash_tbl
[i
];
12522 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
12525 if (test_bit(BNXT_FLTR_VALID
, &fltr
->state
)) {
12526 if (rps_may_expire_flow(bp
->dev
, fltr
->rxq
,
12529 bnxt_hwrm_cfa_ntuple_filter_free(bp
,
12534 rc
= bnxt_hwrm_cfa_ntuple_filter_alloc(bp
,
12539 set_bit(BNXT_FLTR_VALID
, &fltr
->state
);
12543 spin_lock_bh(&bp
->ntp_fltr_lock
);
12544 hlist_del_rcu(&fltr
->hash
);
12545 bp
->ntp_fltr_count
--;
12546 spin_unlock_bh(&bp
->ntp_fltr_lock
);
12548 clear_bit(fltr
->sw_id
, bp
->ntp_fltr_bmap
);
12553 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
))
12554 netdev_info(bp
->dev
, "Receive PF driver unload event!\n");
12559 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
12563 #endif /* CONFIG_RFS_ACCEL */
12565 static int bnxt_udp_tunnel_sync(struct net_device
*netdev
, unsigned int table
)
12567 struct bnxt
*bp
= netdev_priv(netdev
);
12568 struct udp_tunnel_info ti
;
12571 udp_tunnel_nic_get_port(netdev
, table
, 0, &ti
);
12572 if (ti
.type
== UDP_TUNNEL_TYPE_VXLAN
) {
12573 bp
->vxlan_port
= ti
.port
;
12574 cmd
= TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
;
12576 bp
->nge_port
= ti
.port
;
12577 cmd
= TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
;
12581 return bnxt_hwrm_tunnel_dst_port_alloc(bp
, ti
.port
, cmd
);
12583 return bnxt_hwrm_tunnel_dst_port_free(bp
, cmd
);
12586 static const struct udp_tunnel_nic_info bnxt_udp_tunnels
= {
12587 .sync_table
= bnxt_udp_tunnel_sync
,
12588 .flags
= UDP_TUNNEL_NIC_INFO_MAY_SLEEP
|
12589 UDP_TUNNEL_NIC_INFO_OPEN_ONLY
,
12591 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_VXLAN
, },
12592 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_GENEVE
, },
12596 static int bnxt_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
12597 struct net_device
*dev
, u32 filter_mask
,
12600 struct bnxt
*bp
= netdev_priv(dev
);
12602 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, bp
->br_mode
, 0, 0,
12603 nlflags
, filter_mask
, NULL
);
12606 static int bnxt_bridge_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
,
12607 u16 flags
, struct netlink_ext_ack
*extack
)
12609 struct bnxt
*bp
= netdev_priv(dev
);
12610 struct nlattr
*attr
, *br_spec
;
12613 if (bp
->hwrm_spec_code
< 0x10708 || !BNXT_SINGLE_PF(bp
))
12614 return -EOPNOTSUPP
;
12616 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
12620 nla_for_each_nested(attr
, br_spec
, rem
) {
12623 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
12626 if (nla_len(attr
) < sizeof(mode
))
12629 mode
= nla_get_u16(attr
);
12630 if (mode
== bp
->br_mode
)
12633 rc
= bnxt_hwrm_set_br_mode(bp
, mode
);
12635 bp
->br_mode
= mode
;
12641 int bnxt_get_port_parent_id(struct net_device
*dev
,
12642 struct netdev_phys_item_id
*ppid
)
12644 struct bnxt
*bp
= netdev_priv(dev
);
12646 if (bp
->eswitch_mode
!= DEVLINK_ESWITCH_MODE_SWITCHDEV
)
12647 return -EOPNOTSUPP
;
12649 /* The PF and it's VF-reps only support the switchdev framework */
12650 if (!BNXT_PF(bp
) || !(bp
->flags
& BNXT_FLAG_DSN_VALID
))
12651 return -EOPNOTSUPP
;
12653 ppid
->id_len
= sizeof(bp
->dsn
);
12654 memcpy(ppid
->id
, bp
->dsn
, ppid
->id_len
);
12659 static struct devlink_port
*bnxt_get_devlink_port(struct net_device
*dev
)
12661 struct bnxt
*bp
= netdev_priv(dev
);
12663 return &bp
->dl_port
;
12666 static const struct net_device_ops bnxt_netdev_ops
= {
12667 .ndo_open
= bnxt_open
,
12668 .ndo_start_xmit
= bnxt_start_xmit
,
12669 .ndo_stop
= bnxt_close
,
12670 .ndo_get_stats64
= bnxt_get_stats64
,
12671 .ndo_set_rx_mode
= bnxt_set_rx_mode
,
12672 .ndo_do_ioctl
= bnxt_ioctl
,
12673 .ndo_validate_addr
= eth_validate_addr
,
12674 .ndo_set_mac_address
= bnxt_change_mac_addr
,
12675 .ndo_change_mtu
= bnxt_change_mtu
,
12676 .ndo_fix_features
= bnxt_fix_features
,
12677 .ndo_set_features
= bnxt_set_features
,
12678 .ndo_features_check
= bnxt_features_check
,
12679 .ndo_tx_timeout
= bnxt_tx_timeout
,
12680 #ifdef CONFIG_BNXT_SRIOV
12681 .ndo_get_vf_config
= bnxt_get_vf_config
,
12682 .ndo_set_vf_mac
= bnxt_set_vf_mac
,
12683 .ndo_set_vf_vlan
= bnxt_set_vf_vlan
,
12684 .ndo_set_vf_rate
= bnxt_set_vf_bw
,
12685 .ndo_set_vf_link_state
= bnxt_set_vf_link_state
,
12686 .ndo_set_vf_spoofchk
= bnxt_set_vf_spoofchk
,
12687 .ndo_set_vf_trust
= bnxt_set_vf_trust
,
12689 .ndo_setup_tc
= bnxt_setup_tc
,
12690 #ifdef CONFIG_RFS_ACCEL
12691 .ndo_rx_flow_steer
= bnxt_rx_flow_steer
,
12693 .ndo_bpf
= bnxt_xdp
,
12694 .ndo_xdp_xmit
= bnxt_xdp_xmit
,
12695 .ndo_bridge_getlink
= bnxt_bridge_getlink
,
12696 .ndo_bridge_setlink
= bnxt_bridge_setlink
,
12697 .ndo_get_devlink_port
= bnxt_get_devlink_port
,
12700 static void bnxt_remove_one(struct pci_dev
*pdev
)
12702 struct net_device
*dev
= pci_get_drvdata(pdev
);
12703 struct bnxt
*bp
= netdev_priv(dev
);
12706 bnxt_sriov_disable(bp
);
12709 devlink_port_type_clear(&bp
->dl_port
);
12711 pci_disable_pcie_error_reporting(pdev
);
12712 unregister_netdev(dev
);
12713 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
12714 /* Flush any pending tasks */
12715 cancel_work_sync(&bp
->sp_task
);
12716 cancel_delayed_work_sync(&bp
->fw_reset_task
);
12719 bnxt_dl_fw_reporters_destroy(bp
, true);
12720 bnxt_dl_unregister(bp
);
12721 bnxt_shutdown_tc(bp
);
12723 bnxt_clear_int_mode(bp
);
12724 bnxt_hwrm_func_drv_unrgtr(bp
);
12725 bnxt_free_hwrm_resources(bp
);
12726 bnxt_free_hwrm_short_cmd_req(bp
);
12727 bnxt_ethtool_free(bp
);
12731 kfree(bp
->ptp_cfg
);
12732 bp
->ptp_cfg
= NULL
;
12733 kfree(bp
->fw_health
);
12734 bp
->fw_health
= NULL
;
12735 bnxt_cleanup_pci(bp
);
12736 bnxt_free_ctx_mem(bp
);
12739 kfree(bp
->rss_indir_tbl
);
12740 bp
->rss_indir_tbl
= NULL
;
12741 bnxt_free_port_stats(bp
);
12745 static int bnxt_probe_phy(struct bnxt
*bp
, bool fw_dflt
)
12748 struct bnxt_link_info
*link_info
= &bp
->link_info
;
12751 rc
= bnxt_hwrm_phy_qcaps(bp
);
12753 netdev_err(bp
->dev
, "Probe phy can't get phy capabilities (rc: %x)\n",
12757 if (bp
->phy_flags
& BNXT_PHY_FL_NO_FCS
)
12758 bp
->dev
->priv_flags
|= IFF_SUPP_NOFCS
;
12760 bp
->dev
->priv_flags
&= ~IFF_SUPP_NOFCS
;
12764 rc
= bnxt_update_link(bp
, false);
12766 netdev_err(bp
->dev
, "Probe phy can't update link (rc: %x)\n",
12771 /* Older firmware does not have supported_auto_speeds, so assume
12772 * that all supported speeds can be autonegotiated.
12774 if (link_info
->auto_link_speeds
&& !link_info
->support_auto_speeds
)
12775 link_info
->support_auto_speeds
= link_info
->support_speeds
;
12777 bnxt_init_ethtool_link_settings(bp
);
12781 static int bnxt_get_max_irq(struct pci_dev
*pdev
)
12785 if (!pdev
->msix_cap
)
12788 pci_read_config_word(pdev
, pdev
->msix_cap
+ PCI_MSIX_FLAGS
, &ctrl
);
12789 return (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
12792 static void _bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
12795 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
12796 int max_ring_grps
= 0, max_irq
;
12798 *max_tx
= hw_resc
->max_tx_rings
;
12799 *max_rx
= hw_resc
->max_rx_rings
;
12800 *max_cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
12801 max_irq
= min_t(int, bnxt_get_max_func_irqs(bp
) -
12802 bnxt_get_ulp_msix_num(bp
),
12803 hw_resc
->max_stat_ctxs
- bnxt_get_ulp_stat_ctxs(bp
));
12804 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
12805 *max_cp
= min_t(int, *max_cp
, max_irq
);
12806 max_ring_grps
= hw_resc
->max_hw_ring_grps
;
12807 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) && BNXT_PF(bp
)) {
12811 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
12813 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
12814 bnxt_trim_rings(bp
, max_rx
, max_tx
, *max_cp
, false);
12815 /* On P5 chips, max_cp output param should be available NQs */
12818 *max_rx
= min_t(int, *max_rx
, max_ring_grps
);
12821 int bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
, bool shared
)
12825 _bnxt_get_max_rings(bp
, &rx
, &tx
, &cp
);
12828 if (!rx
|| !tx
|| !cp
)
12831 return bnxt_trim_rings(bp
, max_rx
, max_tx
, cp
, shared
);
12834 static int bnxt_get_dflt_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
12839 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
12840 if (rc
&& (bp
->flags
& BNXT_FLAG_AGG_RINGS
)) {
12841 /* Not enough rings, try disabling agg rings. */
12842 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
12843 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
12845 /* set BNXT_FLAG_AGG_RINGS back for consistency */
12846 bp
->flags
|= BNXT_FLAG_AGG_RINGS
;
12849 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
12850 bp
->dev
->hw_features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
12851 bp
->dev
->features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
12852 bnxt_set_ring_params(bp
);
12855 if (bp
->flags
& BNXT_FLAG_ROCE_CAP
) {
12856 int max_cp
, max_stat
, max_irq
;
12858 /* Reserve minimum resources for RoCE */
12859 max_cp
= bnxt_get_max_func_cp_rings(bp
);
12860 max_stat
= bnxt_get_max_func_stat_ctxs(bp
);
12861 max_irq
= bnxt_get_max_func_irqs(bp
);
12862 if (max_cp
<= BNXT_MIN_ROCE_CP_RINGS
||
12863 max_irq
<= BNXT_MIN_ROCE_CP_RINGS
||
12864 max_stat
<= BNXT_MIN_ROCE_STAT_CTXS
)
12867 max_cp
-= BNXT_MIN_ROCE_CP_RINGS
;
12868 max_irq
-= BNXT_MIN_ROCE_CP_RINGS
;
12869 max_stat
-= BNXT_MIN_ROCE_STAT_CTXS
;
12870 max_cp
= min_t(int, max_cp
, max_irq
);
12871 max_cp
= min_t(int, max_cp
, max_stat
);
12872 rc
= bnxt_trim_rings(bp
, max_rx
, max_tx
, max_cp
, shared
);
12879 /* In initial default shared ring setting, each shared ring must have a
12882 static void bnxt_trim_dflt_sh_rings(struct bnxt
*bp
)
12884 bp
->cp_nr_rings
= min_t(int, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
);
12885 bp
->rx_nr_rings
= bp
->cp_nr_rings
;
12886 bp
->tx_nr_rings_per_tc
= bp
->cp_nr_rings
;
12887 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
12890 static int bnxt_set_dflt_rings(struct bnxt
*bp
, bool sh
)
12892 int dflt_rings
, max_rx_rings
, max_tx_rings
, rc
;
12894 if (!bnxt_can_reserve_rings(bp
))
12898 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
12899 dflt_rings
= is_kdump_kernel() ? 1 : netif_get_num_default_rss_queues();
12900 /* Reduce default rings on multi-port cards so that total default
12901 * rings do not exceed CPU count.
12903 if (bp
->port_count
> 1) {
12905 max_t(int, num_online_cpus() / bp
->port_count
, 1);
12907 dflt_rings
= min_t(int, dflt_rings
, max_rings
);
12909 rc
= bnxt_get_dflt_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
12912 bp
->rx_nr_rings
= min_t(int, dflt_rings
, max_rx_rings
);
12913 bp
->tx_nr_rings_per_tc
= min_t(int, dflt_rings
, max_tx_rings
);
12915 bnxt_trim_dflt_sh_rings(bp
);
12917 bp
->cp_nr_rings
= bp
->tx_nr_rings_per_tc
+ bp
->rx_nr_rings
;
12918 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
12920 rc
= __bnxt_reserve_rings(bp
);
12922 netdev_warn(bp
->dev
, "Unable to reserve tx rings\n");
12923 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
12925 bnxt_trim_dflt_sh_rings(bp
);
12927 /* Rings may have been trimmed, re-reserve the trimmed rings. */
12928 if (bnxt_need_reserve_rings(bp
)) {
12929 rc
= __bnxt_reserve_rings(bp
);
12931 netdev_warn(bp
->dev
, "2nd rings reservation failed.\n");
12932 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
12934 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
12939 bp
->tx_nr_rings
= 0;
12940 bp
->rx_nr_rings
= 0;
12945 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
)
12949 if (bp
->tx_nr_rings
)
12952 bnxt_ulp_irq_stop(bp
);
12953 bnxt_clear_int_mode(bp
);
12954 rc
= bnxt_set_dflt_rings(bp
, true);
12956 netdev_err(bp
->dev
, "Not enough rings available.\n");
12957 goto init_dflt_ring_err
;
12959 rc
= bnxt_init_int_mode(bp
);
12961 goto init_dflt_ring_err
;
12963 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
12964 if (bnxt_rfs_supported(bp
) && bnxt_rfs_capable(bp
)) {
12965 bp
->flags
|= BNXT_FLAG_RFS
;
12966 bp
->dev
->features
|= NETIF_F_NTUPLE
;
12968 init_dflt_ring_err
:
12969 bnxt_ulp_irq_restart(bp
, rc
);
12973 int bnxt_restore_pf_fw_resources(struct bnxt
*bp
)
12978 bnxt_hwrm_func_qcaps(bp
);
12980 if (netif_running(bp
->dev
))
12981 __bnxt_close_nic(bp
, true, false);
12983 bnxt_ulp_irq_stop(bp
);
12984 bnxt_clear_int_mode(bp
);
12985 rc
= bnxt_init_int_mode(bp
);
12986 bnxt_ulp_irq_restart(bp
, rc
);
12988 if (netif_running(bp
->dev
)) {
12990 dev_close(bp
->dev
);
12992 rc
= bnxt_open_nic(bp
, true, false);
12998 static int bnxt_init_mac_addr(struct bnxt
*bp
)
13003 memcpy(bp
->dev
->dev_addr
, bp
->pf
.mac_addr
, ETH_ALEN
);
13005 #ifdef CONFIG_BNXT_SRIOV
13006 struct bnxt_vf_info
*vf
= &bp
->vf
;
13007 bool strict_approval
= true;
13009 if (is_valid_ether_addr(vf
->mac_addr
)) {
13010 /* overwrite netdev dev_addr with admin VF MAC */
13011 memcpy(bp
->dev
->dev_addr
, vf
->mac_addr
, ETH_ALEN
);
13012 /* Older PF driver or firmware may not approve this
13015 strict_approval
= false;
13017 eth_hw_addr_random(bp
->dev
);
13019 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, strict_approval
);
13025 #define BNXT_VPD_LEN 512
13026 static void bnxt_vpd_read_info(struct bnxt
*bp
)
13028 struct pci_dev
*pdev
= bp
->pdev
;
13029 int i
, len
, pos
, ro_size
, size
;
13033 vpd_data
= kmalloc(BNXT_VPD_LEN
, GFP_KERNEL
);
13037 vpd_size
= pci_read_vpd(pdev
, 0, BNXT_VPD_LEN
, vpd_data
);
13038 if (vpd_size
<= 0) {
13039 netdev_err(bp
->dev
, "Unable to read VPD\n");
13043 i
= pci_vpd_find_tag(vpd_data
, vpd_size
, PCI_VPD_LRDT_RO_DATA
);
13045 netdev_err(bp
->dev
, "VPD READ-Only not found\n");
13049 ro_size
= pci_vpd_lrdt_size(&vpd_data
[i
]);
13050 i
+= PCI_VPD_LRDT_TAG_SIZE
;
13051 if (i
+ ro_size
> vpd_size
)
13054 pos
= pci_vpd_find_info_keyword(vpd_data
, i
, ro_size
,
13055 PCI_VPD_RO_KEYWORD_PARTNO
);
13059 len
= pci_vpd_info_field_size(&vpd_data
[pos
]);
13060 pos
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
13061 if (len
+ pos
> vpd_size
)
13064 size
= min(len
, BNXT_VPD_FLD_LEN
- 1);
13065 memcpy(bp
->board_partno
, &vpd_data
[pos
], size
);
13068 pos
= pci_vpd_find_info_keyword(vpd_data
, i
, ro_size
,
13069 PCI_VPD_RO_KEYWORD_SERIALNO
);
13073 len
= pci_vpd_info_field_size(&vpd_data
[pos
]);
13074 pos
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
13075 if (len
+ pos
> vpd_size
)
13078 size
= min(len
, BNXT_VPD_FLD_LEN
- 1);
13079 memcpy(bp
->board_serialno
, &vpd_data
[pos
], size
);
13084 static int bnxt_pcie_dsn_get(struct bnxt
*bp
, u8 dsn
[])
13086 struct pci_dev
*pdev
= bp
->pdev
;
13089 qword
= pci_get_dsn(pdev
);
13091 netdev_info(bp
->dev
, "Unable to read adapter's DSN\n");
13092 return -EOPNOTSUPP
;
13095 put_unaligned_le64(qword
, dsn
);
13097 bp
->flags
|= BNXT_FLAG_DSN_VALID
;
13101 static int bnxt_map_db_bar(struct bnxt
*bp
)
13105 bp
->bar1
= pci_iomap(bp
->pdev
, 2, bp
->db_size
);
13111 static int bnxt_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
13113 struct net_device
*dev
;
13117 if (pci_is_bridge(pdev
))
13120 /* Clear any pending DMA transactions from crash kernel
13121 * while loading driver in capture kernel.
13123 if (is_kdump_kernel()) {
13124 pci_clear_master(pdev
);
13128 max_irqs
= bnxt_get_max_irq(pdev
);
13129 dev
= alloc_etherdev_mq(sizeof(*bp
), max_irqs
);
13133 bp
= netdev_priv(dev
);
13134 bp
->msg_enable
= BNXT_DEF_MSG_ENABLE
;
13135 bnxt_set_max_func_irqs(bp
, max_irqs
);
13137 if (bnxt_vf_pciid(ent
->driver_data
))
13138 bp
->flags
|= BNXT_FLAG_VF
;
13140 if (pdev
->msix_cap
)
13141 bp
->flags
|= BNXT_FLAG_MSIX_CAP
;
13143 rc
= bnxt_init_board(pdev
, dev
);
13145 goto init_err_free
;
13147 dev
->netdev_ops
= &bnxt_netdev_ops
;
13148 dev
->watchdog_timeo
= BNXT_TX_TIMEOUT
;
13149 dev
->ethtool_ops
= &bnxt_ethtool_ops
;
13150 pci_set_drvdata(pdev
, dev
);
13152 rc
= bnxt_alloc_hwrm_resources(bp
);
13154 goto init_err_pci_clean
;
13156 mutex_init(&bp
->hwrm_cmd_lock
);
13157 mutex_init(&bp
->link_lock
);
13159 rc
= bnxt_fw_init_one_p1(bp
);
13161 goto init_err_pci_clean
;
13164 bnxt_vpd_read_info(bp
);
13166 if (BNXT_CHIP_P5(bp
)) {
13167 bp
->flags
|= BNXT_FLAG_CHIP_P5
;
13168 if (BNXT_CHIP_SR2(bp
))
13169 bp
->flags
|= BNXT_FLAG_CHIP_SR2
;
13172 rc
= bnxt_alloc_rss_indir_tbl(bp
);
13174 goto init_err_pci_clean
;
13176 rc
= bnxt_fw_init_one_p2(bp
);
13178 goto init_err_pci_clean
;
13180 rc
= bnxt_map_db_bar(bp
);
13182 dev_err(&pdev
->dev
, "Cannot map doorbell BAR rc = %d, aborting\n",
13184 goto init_err_pci_clean
;
13187 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
13188 NETIF_F_TSO
| NETIF_F_TSO6
|
13189 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
13190 NETIF_F_GSO_IPXIP4
|
13191 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
13192 NETIF_F_GSO_PARTIAL
| NETIF_F_RXHASH
|
13193 NETIF_F_RXCSUM
| NETIF_F_GRO
;
13195 if (BNXT_SUPPORTS_TPA(bp
))
13196 dev
->hw_features
|= NETIF_F_LRO
;
13198 dev
->hw_enc_features
=
13199 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
13200 NETIF_F_TSO
| NETIF_F_TSO6
|
13201 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
13202 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
13203 NETIF_F_GSO_IPXIP4
| NETIF_F_GSO_PARTIAL
;
13204 dev
->udp_tunnel_nic_info
= &bnxt_udp_tunnels
;
13206 dev
->gso_partial_features
= NETIF_F_GSO_UDP_TUNNEL_CSUM
|
13207 NETIF_F_GSO_GRE_CSUM
;
13208 dev
->vlan_features
= dev
->hw_features
| NETIF_F_HIGHDMA
;
13209 if (bp
->fw_cap
& BNXT_FW_CAP_VLAN_RX_STRIP
)
13210 dev
->hw_features
|= BNXT_HW_FEATURE_VLAN_ALL_RX
;
13211 if (bp
->fw_cap
& BNXT_FW_CAP_VLAN_TX_INSERT
)
13212 dev
->hw_features
|= BNXT_HW_FEATURE_VLAN_ALL_TX
;
13213 if (BNXT_SUPPORTS_TPA(bp
))
13214 dev
->hw_features
|= NETIF_F_GRO_HW
;
13215 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
13216 if (dev
->features
& NETIF_F_GRO_HW
)
13217 dev
->features
&= ~NETIF_F_LRO
;
13218 dev
->priv_flags
|= IFF_UNICAST_FLT
;
13220 #ifdef CONFIG_BNXT_SRIOV
13221 init_waitqueue_head(&bp
->sriov_cfg_wait
);
13222 mutex_init(&bp
->sriov_lock
);
13224 if (BNXT_SUPPORTS_TPA(bp
)) {
13225 bp
->gro_func
= bnxt_gro_func_5730x
;
13226 if (BNXT_CHIP_P4(bp
))
13227 bp
->gro_func
= bnxt_gro_func_5731x
;
13228 else if (BNXT_CHIP_P5(bp
))
13229 bp
->gro_func
= bnxt_gro_func_5750x
;
13231 if (!BNXT_CHIP_P4_PLUS(bp
))
13232 bp
->flags
|= BNXT_FLAG_DOUBLE_DB
;
13234 rc
= bnxt_init_mac_addr(bp
);
13236 dev_err(&pdev
->dev
, "Unable to initialize mac address.\n");
13237 rc
= -EADDRNOTAVAIL
;
13238 goto init_err_pci_clean
;
13242 /* Read the adapter's DSN to use as the eswitch switch_id */
13243 rc
= bnxt_pcie_dsn_get(bp
, bp
->dsn
);
13246 /* MTU range: 60 - FW defined max */
13247 dev
->min_mtu
= ETH_ZLEN
;
13248 dev
->max_mtu
= bp
->max_mtu
;
13250 rc
= bnxt_probe_phy(bp
, true);
13252 goto init_err_pci_clean
;
13254 bnxt_set_rx_skb_mode(bp
, false);
13255 bnxt_set_tpa_flags(bp
);
13256 bnxt_set_ring_params(bp
);
13257 rc
= bnxt_set_dflt_rings(bp
, true);
13259 netdev_err(bp
->dev
, "Not enough rings available.\n");
13261 goto init_err_pci_clean
;
13264 bnxt_fw_init_one_p3(bp
);
13266 if (dev
->hw_features
& BNXT_HW_FEATURE_VLAN_ALL_RX
)
13267 bp
->flags
|= BNXT_FLAG_STRIP_VLAN
;
13269 rc
= bnxt_init_int_mode(bp
);
13271 goto init_err_pci_clean
;
13273 /* No TC has been set yet and rings may have been trimmed due to
13274 * limited MSIX, so we re-initialize the TX rings per TC.
13276 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
13281 create_singlethread_workqueue("bnxt_pf_wq");
13283 dev_err(&pdev
->dev
, "Unable to create workqueue.\n");
13285 goto init_err_pci_clean
;
13288 rc
= bnxt_init_tc(bp
);
13290 netdev_err(dev
, "Failed to initialize TC flower offload, err = %d.\n",
13294 bnxt_inv_fw_health_reg(bp
);
13295 bnxt_dl_register(bp
);
13297 rc
= register_netdev(dev
);
13299 goto init_err_cleanup
;
13302 devlink_port_type_eth_set(&bp
->dl_port
, bp
->dev
);
13303 bnxt_dl_fw_reporters_create(bp
);
13305 netdev_info(dev
, "%s found at mem %lx, node addr %pM\n",
13306 board_info
[ent
->driver_data
].name
,
13307 (long)pci_resource_start(pdev
, 0), dev
->dev_addr
);
13308 pcie_print_link_status(pdev
);
13310 pci_save_state(pdev
);
13314 bnxt_dl_unregister(bp
);
13315 bnxt_shutdown_tc(bp
);
13316 bnxt_clear_int_mode(bp
);
13318 init_err_pci_clean
:
13319 bnxt_hwrm_func_drv_unrgtr(bp
);
13320 bnxt_free_hwrm_short_cmd_req(bp
);
13321 bnxt_free_hwrm_resources(bp
);
13322 bnxt_ethtool_free(bp
);
13323 kfree(bp
->ptp_cfg
);
13324 bp
->ptp_cfg
= NULL
;
13325 kfree(bp
->fw_health
);
13326 bp
->fw_health
= NULL
;
13327 bnxt_cleanup_pci(bp
);
13328 bnxt_free_ctx_mem(bp
);
13331 kfree(bp
->rss_indir_tbl
);
13332 bp
->rss_indir_tbl
= NULL
;
13339 static void bnxt_shutdown(struct pci_dev
*pdev
)
13341 struct net_device
*dev
= pci_get_drvdata(pdev
);
13348 bp
= netdev_priv(dev
);
13350 goto shutdown_exit
;
13352 if (netif_running(dev
))
13355 bnxt_ulp_shutdown(bp
);
13356 bnxt_clear_int_mode(bp
);
13357 pci_disable_device(pdev
);
13359 if (system_state
== SYSTEM_POWER_OFF
) {
13360 pci_wake_from_d3(pdev
, bp
->wol
);
13361 pci_set_power_state(pdev
, PCI_D3hot
);
13368 #ifdef CONFIG_PM_SLEEP
13369 static int bnxt_suspend(struct device
*device
)
13371 struct net_device
*dev
= dev_get_drvdata(device
);
13372 struct bnxt
*bp
= netdev_priv(dev
);
13377 if (netif_running(dev
)) {
13378 netif_device_detach(dev
);
13379 rc
= bnxt_close(dev
);
13381 bnxt_hwrm_func_drv_unrgtr(bp
);
13382 pci_disable_device(bp
->pdev
);
13383 bnxt_free_ctx_mem(bp
);
13390 static int bnxt_resume(struct device
*device
)
13392 struct net_device
*dev
= dev_get_drvdata(device
);
13393 struct bnxt
*bp
= netdev_priv(dev
);
13397 rc
= pci_enable_device(bp
->pdev
);
13399 netdev_err(dev
, "Cannot re-enable PCI device during resume, err = %d\n",
13403 pci_set_master(bp
->pdev
);
13404 if (bnxt_hwrm_ver_get(bp
)) {
13408 rc
= bnxt_hwrm_func_reset(bp
);
13414 rc
= bnxt_hwrm_func_qcaps(bp
);
13418 if (bnxt_hwrm_func_drv_rgtr(bp
, NULL
, 0, false)) {
13423 bnxt_get_wol_settings(bp
);
13424 if (netif_running(dev
)) {
13425 rc
= bnxt_open(dev
);
13427 netif_device_attach(dev
);
13431 bnxt_ulp_start(bp
, rc
);
13433 bnxt_reenable_sriov(bp
);
13438 static SIMPLE_DEV_PM_OPS(bnxt_pm_ops
, bnxt_suspend
, bnxt_resume
);
13439 #define BNXT_PM_OPS (&bnxt_pm_ops)
13443 #define BNXT_PM_OPS NULL
13445 #endif /* CONFIG_PM_SLEEP */
13448 * bnxt_io_error_detected - called when PCI error is detected
13449 * @pdev: Pointer to PCI device
13450 * @state: The current pci connection state
13452 * This function is called after a PCI bus error affecting
13453 * this device has been detected.
13455 static pci_ers_result_t
bnxt_io_error_detected(struct pci_dev
*pdev
,
13456 pci_channel_state_t state
)
13458 struct net_device
*netdev
= pci_get_drvdata(pdev
);
13459 struct bnxt
*bp
= netdev_priv(netdev
);
13461 netdev_info(netdev
, "PCI I/O error detected\n");
13464 netif_device_detach(netdev
);
13468 if (state
== pci_channel_io_perm_failure
) {
13470 return PCI_ERS_RESULT_DISCONNECT
;
13473 if (state
== pci_channel_io_frozen
)
13474 set_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN
, &bp
->state
);
13476 if (netif_running(netdev
))
13477 bnxt_close(netdev
);
13479 if (pci_is_enabled(pdev
))
13480 pci_disable_device(pdev
);
13481 bnxt_free_ctx_mem(bp
);
13486 /* Request a slot slot reset. */
13487 return PCI_ERS_RESULT_NEED_RESET
;
13491 * bnxt_io_slot_reset - called after the pci bus has been reset.
13492 * @pdev: Pointer to PCI device
13494 * Restart the card from scratch, as if from a cold-boot.
13495 * At this point, the card has exprienced a hard reset,
13496 * followed by fixups by BIOS, and has its config space
13497 * set up identically to what it was at cold boot.
13499 static pci_ers_result_t
bnxt_io_slot_reset(struct pci_dev
*pdev
)
13501 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
13502 struct net_device
*netdev
= pci_get_drvdata(pdev
);
13503 struct bnxt
*bp
= netdev_priv(netdev
);
13506 netdev_info(bp
->dev
, "PCI Slot Reset\n");
13510 if (pci_enable_device(pdev
)) {
13511 dev_err(&pdev
->dev
,
13512 "Cannot re-enable PCI device after reset.\n");
13514 pci_set_master(pdev
);
13515 /* Upon fatal error, our device internal logic that latches to
13516 * BAR value is getting reset and will restore only upon
13517 * rewritting the BARs.
13519 * As pci_restore_state() does not re-write the BARs if the
13520 * value is same as saved value earlier, driver needs to
13521 * write the BARs to 0 to force restore, in case of fatal error.
13523 if (test_and_clear_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN
,
13525 for (off
= PCI_BASE_ADDRESS_0
;
13526 off
<= PCI_BASE_ADDRESS_5
; off
+= 4)
13527 pci_write_config_dword(bp
->pdev
, off
, 0);
13529 pci_restore_state(pdev
);
13530 pci_save_state(pdev
);
13532 err
= bnxt_hwrm_func_reset(bp
);
13534 result
= PCI_ERS_RESULT_RECOVERED
;
13543 * bnxt_io_resume - called when traffic can start flowing again.
13544 * @pdev: Pointer to PCI device
13546 * This callback is called when the error recovery driver tells
13547 * us that its OK to resume normal operation.
13549 static void bnxt_io_resume(struct pci_dev
*pdev
)
13551 struct net_device
*netdev
= pci_get_drvdata(pdev
);
13552 struct bnxt
*bp
= netdev_priv(netdev
);
13555 netdev_info(bp
->dev
, "PCI Slot Resume\n");
13558 err
= bnxt_hwrm_func_qcaps(bp
);
13559 if (!err
&& netif_running(netdev
))
13560 err
= bnxt_open(netdev
);
13562 bnxt_ulp_start(bp
, err
);
13564 bnxt_reenable_sriov(bp
);
13565 netif_device_attach(netdev
);
13571 static const struct pci_error_handlers bnxt_err_handler
= {
13572 .error_detected
= bnxt_io_error_detected
,
13573 .slot_reset
= bnxt_io_slot_reset
,
13574 .resume
= bnxt_io_resume
13577 static struct pci_driver bnxt_pci_driver
= {
13578 .name
= DRV_MODULE_NAME
,
13579 .id_table
= bnxt_pci_tbl
,
13580 .probe
= bnxt_init_one
,
13581 .remove
= bnxt_remove_one
,
13582 .shutdown
= bnxt_shutdown
,
13583 .driver
.pm
= BNXT_PM_OPS
,
13584 .err_handler
= &bnxt_err_handler
,
13585 #if defined(CONFIG_BNXT_SRIOV)
13586 .sriov_configure
= bnxt_sriov_configure
,
13590 static int __init
bnxt_init(void)
13593 return pci_register_driver(&bnxt_pci_driver
);
13596 static void __exit
bnxt_exit(void)
13598 pci_unregister_driver(&bnxt_pci_driver
);
13600 destroy_workqueue(bnxt_pf_wq
);
13604 module_init(bnxt_init
);
13605 module_exit(bnxt_exit
);