hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/ethernet/broadcom/bnxt/bnxt.c
....@@ -1,7 +1,7 @@
11 /* Broadcom NetXtreme-C/E network driver.
22 *
33 * Copyright (c) 2014-2016 Broadcom Corporation
4
- * Copyright (c) 2016-2018 Broadcom Limited
4
+ * Copyright (c) 2016-2019 Broadcom Limited
55 *
66 * This program is free software; you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License as published by
....@@ -31,6 +31,7 @@
3131 #include <asm/page.h>
3232 #include <linux/time.h>
3333 #include <linux/mii.h>
34
+#include <linux/mdio.h>
3435 #include <linux/if.h>
3536 #include <linux/if_vlan.h>
3637 #include <linux/if_bridge.h>
....@@ -53,6 +54,7 @@
5354 #include <net/pkt_cls.h>
5455 #include <linux/hwmon.h>
5556 #include <linux/hwmon-sysfs.h>
57
+#include <net/page_pool.h>
5658
5759 #include "bnxt_hsi.h"
5860 #include "bnxt.h"
....@@ -67,13 +69,11 @@
6769 #include "bnxt_debugfs.h"
6870
6971 #define BNXT_TX_TIMEOUT (5 * HZ)
70
-
71
-static const char version[] =
72
- "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
72
+#define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \
73
+ NETIF_MSG_TX_ERR)
7374
7475 MODULE_LICENSE("GPL");
7576 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
76
-MODULE_VERSION(DRV_MODULE_VERSION);
7777
7878 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
7979 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
....@@ -111,12 +111,22 @@
111111 BCM57452,
112112 BCM57454,
113113 BCM5745x_NPAR,
114
+ BCM57508,
115
+ BCM57504,
116
+ BCM57502,
117
+ BCM57508_NPAR,
118
+ BCM57504_NPAR,
119
+ BCM57502_NPAR,
114120 BCM58802,
115121 BCM58804,
116122 BCM58808,
117123 NETXTREME_E_VF,
118124 NETXTREME_C_VF,
119125 NETXTREME_S_VF,
126
+ NETXTREME_C_VF_HV,
127
+ NETXTREME_E_VF_HV,
128
+ NETXTREME_E_P5_VF,
129
+ NETXTREME_E_P5_VF_HV,
120130 };
121131
122132 /* indexed by enum above */
....@@ -152,12 +162,22 @@
152162 [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
153163 [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
154164 [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
165
+ [BCM57508] = { "Broadcom BCM57508 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
166
+ [BCM57504] = { "Broadcom BCM57504 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
167
+ [BCM57502] = { "Broadcom BCM57502 NetXtreme-E 10Gb/25Gb/50Gb Ethernet" },
168
+ [BCM57508_NPAR] = { "Broadcom BCM57508 NetXtreme-E Ethernet Partition" },
169
+ [BCM57504_NPAR] = { "Broadcom BCM57504 NetXtreme-E Ethernet Partition" },
170
+ [BCM57502_NPAR] = { "Broadcom BCM57502 NetXtreme-E Ethernet Partition" },
155171 [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
156172 [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
157173 [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
158174 [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
159175 [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
160176 [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
177
+ [NETXTREME_C_VF_HV] = { "Broadcom NetXtreme-C Virtual Function for Hyper-V" },
178
+ [NETXTREME_E_VF_HV] = { "Broadcom NetXtreme-E Virtual Function for Hyper-V" },
179
+ [NETXTREME_E_P5_VF] = { "Broadcom BCM5750X NetXtreme-E Ethernet Virtual Function" },
180
+ [NETXTREME_E_P5_VF_HV] = { "Broadcom BCM5750X NetXtreme-E Virtual Function for Hyper-V" },
161181 };
162182
163183 static const struct pci_device_id bnxt_pci_tbl[] = {
....@@ -196,17 +216,38 @@
196216 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
197217 { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 },
198218 { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
219
+ { PCI_VDEVICE(BROADCOM, 0x1750), .driver_data = BCM57508 },
220
+ { PCI_VDEVICE(BROADCOM, 0x1751), .driver_data = BCM57504 },
221
+ { PCI_VDEVICE(BROADCOM, 0x1752), .driver_data = BCM57502 },
222
+ { PCI_VDEVICE(BROADCOM, 0x1800), .driver_data = BCM57508_NPAR },
223
+ { PCI_VDEVICE(BROADCOM, 0x1801), .driver_data = BCM57504_NPAR },
224
+ { PCI_VDEVICE(BROADCOM, 0x1802), .driver_data = BCM57502_NPAR },
225
+ { PCI_VDEVICE(BROADCOM, 0x1803), .driver_data = BCM57508_NPAR },
226
+ { PCI_VDEVICE(BROADCOM, 0x1804), .driver_data = BCM57504_NPAR },
227
+ { PCI_VDEVICE(BROADCOM, 0x1805), .driver_data = BCM57502_NPAR },
199228 { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 },
200229 { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 },
201230 #ifdef CONFIG_BNXT_SRIOV
202231 { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
232
+ { PCI_VDEVICE(BROADCOM, 0x1607), .driver_data = NETXTREME_E_VF_HV },
233
+ { PCI_VDEVICE(BROADCOM, 0x1608), .driver_data = NETXTREME_E_VF_HV },
203234 { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
235
+ { PCI_VDEVICE(BROADCOM, 0x16bd), .driver_data = NETXTREME_E_VF_HV },
204236 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
237
+ { PCI_VDEVICE(BROADCOM, 0x16c2), .driver_data = NETXTREME_C_VF_HV },
238
+ { PCI_VDEVICE(BROADCOM, 0x16c3), .driver_data = NETXTREME_C_VF_HV },
239
+ { PCI_VDEVICE(BROADCOM, 0x16c4), .driver_data = NETXTREME_E_VF_HV },
240
+ { PCI_VDEVICE(BROADCOM, 0x16c5), .driver_data = NETXTREME_E_VF_HV },
205241 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
206242 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
207243 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
208244 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
209245 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
246
+ { PCI_VDEVICE(BROADCOM, 0x16e6), .driver_data = NETXTREME_C_VF_HV },
247
+ { PCI_VDEVICE(BROADCOM, 0x1806), .driver_data = NETXTREME_E_P5_VF },
248
+ { PCI_VDEVICE(BROADCOM, 0x1807), .driver_data = NETXTREME_E_P5_VF },
249
+ { PCI_VDEVICE(BROADCOM, 0x1808), .driver_data = NETXTREME_E_P5_VF_HV },
250
+ { PCI_VDEVICE(BROADCOM, 0x1809), .driver_data = NETXTREME_E_P5_VF_HV },
210251 { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF },
211252 #endif
212253 { 0 }
....@@ -223,10 +264,16 @@
223264
224265 static const u16 bnxt_async_events_arr[] = {
225266 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
267
+ ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE,
226268 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
227269 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
228270 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
229271 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
272
+ ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE,
273
+ ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY,
274
+ ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY,
275
+ ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION,
276
+ ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG,
230277 };
231278
232279 static struct workqueue_struct *bnxt_pf_wq;
....@@ -234,21 +281,54 @@
234281 static bool bnxt_vf_pciid(enum board_idx idx)
235282 {
236283 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF ||
237
- idx == NETXTREME_S_VF);
284
+ idx == NETXTREME_S_VF || idx == NETXTREME_C_VF_HV ||
285
+ idx == NETXTREME_E_VF_HV || idx == NETXTREME_E_P5_VF ||
286
+ idx == NETXTREME_E_P5_VF_HV);
238287 }
239288
240289 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
241290 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
242291 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
243292
244
-#define BNXT_CP_DB_REARM(db, raw_cons) \
245
- writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
246
-
247
-#define BNXT_CP_DB(db, raw_cons) \
248
- writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
249
-
250293 #define BNXT_CP_DB_IRQ_DIS(db) \
251294 writel(DB_CP_IRQ_DIS_FLAGS, db)
295
+
296
+#define BNXT_DB_CQ(db, idx) \
297
+ writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
298
+
299
+#define BNXT_DB_NQ_P5(db, idx) \
300
+ writeq((db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), (db)->doorbell)
301
+
302
+#define BNXT_DB_CQ_ARM(db, idx) \
303
+ writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
304
+
305
+#define BNXT_DB_NQ_ARM_P5(db, idx) \
306
+ writeq((db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx), (db)->doorbell)
307
+
308
+static void bnxt_db_nq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
309
+{
310
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
311
+ BNXT_DB_NQ_P5(db, idx);
312
+ else
313
+ BNXT_DB_CQ(db, idx);
314
+}
315
+
316
+static void bnxt_db_nq_arm(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
317
+{
318
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
319
+ BNXT_DB_NQ_ARM_P5(db, idx);
320
+ else
321
+ BNXT_DB_CQ_ARM(db, idx);
322
+}
323
+
324
+static void bnxt_db_cq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
325
+{
326
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
327
+ writeq(db->db_key64 | DBR_TYPE_CQ_ARMALL | RING_CMP(idx),
328
+ db->doorbell);
329
+ else
330
+ BNXT_DB_CQ(db, idx);
331
+}
252332
253333 const u16 bnxt_lhint_arr[] = {
254334 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
....@@ -280,6 +360,13 @@
280360 return 0;
281361
282362 return md_dst->u.port_info.port_id;
363
+}
364
+
365
+static void bnxt_txr_db_kick(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
366
+ u16 prod)
367
+{
368
+ bnxt_db_write(bp, &txr->tx_db, prod);
369
+ txr->kick_pending = 0;
283370 }
284371
285372 static bool bnxt_txr_netif_try_stop_queue(struct bnxt *bp,
....@@ -320,6 +407,7 @@
320407 i = skb_get_queue_mapping(skb);
321408 if (unlikely(i >= bp->tx_nr_rings)) {
322409 dev_kfree_skb_any(skb);
410
+ atomic_long_inc(&dev->tx_dropped);
323411 return NETDEV_TX_OK;
324412 }
325413
....@@ -329,6 +417,10 @@
329417
330418 free_size = bnxt_tx_avail(bp, txr);
331419 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
420
+ /* We must have raced with NAPI cleanup */
421
+ if (net_ratelimit() && txr->kick_pending)
422
+ netif_warn(bp, tx_err, dev,
423
+ "bnxt: ring busy w/ flush pending!\n");
332424 if (bnxt_txr_netif_try_stop_queue(bp, txr, txq))
333425 return NETDEV_TX_BUSY;
334426 }
....@@ -361,6 +453,7 @@
361453 struct tx_push_buffer *tx_push_buf = txr->tx_push;
362454 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
363455 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
456
+ void __iomem *db = txr->tx_db.doorbell;
364457 void *pdata = tx_push_buf->data;
365458 u64 *end;
366459 int j, push_len;
....@@ -418,12 +511,11 @@
418511
419512 push_len = (length + sizeof(*tx_push) + 7) / 8;
420513 if (push_len > 16) {
421
- __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
422
- __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
514
+ __iowrite64_copy(db, tx_push_buf, 16);
515
+ __iowrite32_copy(db + 4, tx_push_buf + 1,
423516 (push_len - 16) << 1);
424517 } else {
425
- __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
426
- push_len);
518
+ __iowrite64_copy(db, tx_push_buf, push_len);
427519 }
428520
429521 goto tx_done;
....@@ -432,21 +524,16 @@
432524 normal_tx:
433525 if (length < BNXT_MIN_PKT_SIZE) {
434526 pad = BNXT_MIN_PKT_SIZE - length;
435
- if (skb_pad(skb, pad)) {
527
+ if (skb_pad(skb, pad))
436528 /* SKB already freed. */
437
- tx_buf->skb = NULL;
438
- return NETDEV_TX_OK;
439
- }
529
+ goto tx_kick_pending;
440530 length = BNXT_MIN_PKT_SIZE;
441531 }
442532
443533 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
444534
445
- if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
446
- dev_kfree_skb_any(skb);
447
- tx_buf->skb = NULL;
448
- return NETDEV_TX_OK;
449
- }
535
+ if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
536
+ goto tx_free;
450537
451538 dma_unmap_addr_set(tx_buf, mapping, mapping);
452539 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
....@@ -530,16 +617,16 @@
530617 prod = NEXT_TX(prod);
531618 txr->tx_prod = prod;
532619
533
- if (!skb->xmit_more || netif_xmit_stopped(txq))
534
- bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
620
+ if (!netdev_xmit_more() || netif_xmit_stopped(txq))
621
+ bnxt_txr_db_kick(bp, txr, prod);
622
+ else
623
+ txr->kick_pending = 1;
535624
536625 tx_done:
537626
538
- mmiowb();
539
-
540627 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
541
- if (skb->xmit_more && !tx_buf->is_push)
542
- bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
628
+ if (netdev_xmit_more() && !tx_buf->is_push)
629
+ bnxt_txr_db_kick(bp, txr, prod);
543630
544631 bnxt_txr_netif_try_stop_queue(bp, txr, txq);
545632 }
....@@ -551,7 +638,6 @@
551638 /* start back at beginning and unmap skb */
552639 prod = txr->tx_prod;
553640 tx_buf = &txr->tx_buf_ring[prod];
554
- tx_buf->skb = NULL;
555641 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
556642 skb_headlen(skb), PCI_DMA_TODEVICE);
557643 prod = NEXT_TX(prod);
....@@ -565,7 +651,13 @@
565651 PCI_DMA_TODEVICE);
566652 }
567653
654
+tx_free:
568655 dev_kfree_skb_any(skb);
656
+tx_kick_pending:
657
+ if (txr->kick_pending)
658
+ bnxt_txr_db_kick(bp, txr, txr->tx_prod);
659
+ txr->tx_buf_ring[txr->tx_prod].skb = NULL;
660
+ atomic_long_inc(&dev->tx_dropped);
569661 return NETDEV_TX_OK;
570662 }
571663
....@@ -631,19 +723,20 @@
631723 }
632724
633725 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
726
+ struct bnxt_rx_ring_info *rxr,
634727 gfp_t gfp)
635728 {
636729 struct device *dev = &bp->pdev->dev;
637730 struct page *page;
638731
639
- page = alloc_page(gfp);
732
+ page = page_pool_dev_alloc_pages(rxr->page_pool);
640733 if (!page)
641734 return NULL;
642735
643736 *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
644737 DMA_ATTR_WEAK_ORDERING);
645738 if (dma_mapping_error(dev, *mapping)) {
646
- __free_page(page);
739
+ page_pool_recycle_direct(rxr->page_pool, page);
647740 return NULL;
648741 }
649742 *mapping += bp->rx_dma_offset;
....@@ -679,7 +772,8 @@
679772 dma_addr_t mapping;
680773
681774 if (BNXT_RX_PAGE_MODE(bp)) {
682
- struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
775
+ struct page *page =
776
+ __bnxt_alloc_rx_page(bp, &mapping, rxr, gfp);
683777
684778 if (!page)
685779 return -ENOMEM;
....@@ -788,15 +882,40 @@
788882 return 0;
789883 }
790884
791
-static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
792
- u32 agg_bufs)
885
+static struct rx_agg_cmp *bnxt_get_agg(struct bnxt *bp,
886
+ struct bnxt_cp_ring_info *cpr,
887
+ u16 cp_cons, u16 curr)
793888 {
889
+ struct rx_agg_cmp *agg;
890
+
891
+ cp_cons = RING_CMP(ADV_RAW_CMP(cp_cons, curr));
892
+ agg = (struct rx_agg_cmp *)
893
+ &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
894
+ return agg;
895
+}
896
+
897
+static struct rx_agg_cmp *bnxt_get_tpa_agg_p5(struct bnxt *bp,
898
+ struct bnxt_rx_ring_info *rxr,
899
+ u16 agg_id, u16 curr)
900
+{
901
+ struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[agg_id];
902
+
903
+ return &tpa_info->agg_arr[curr];
904
+}
905
+
906
+static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
907
+ u16 start, u32 agg_bufs, bool tpa)
908
+{
909
+ struct bnxt_napi *bnapi = cpr->bnapi;
794910 struct bnxt *bp = bnapi->bp;
795
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
796911 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
797912 u16 prod = rxr->rx_agg_prod;
798913 u16 sw_prod = rxr->rx_sw_agg_prod;
914
+ bool p5_tpa = false;
799915 u32 i;
916
+
917
+ if ((bp->flags & BNXT_FLAG_CHIP_P5) && tpa)
918
+ p5_tpa = true;
800919
801920 for (i = 0; i < agg_bufs; i++) {
802921 u16 cons;
....@@ -805,8 +924,10 @@
805924 struct rx_bd *prod_bd;
806925 struct page *page;
807926
808
- agg = (struct rx_agg_cmp *)
809
- &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
927
+ if (p5_tpa)
928
+ agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, start + i);
929
+ else
930
+ agg = bnxt_get_agg(bp, cpr, idx, start + i);
810931 cons = agg->rx_agg_cmp_opaque;
811932 __clear_bit(cons, rxr->rx_agg_bmap);
812933
....@@ -834,7 +955,6 @@
834955
835956 prod = NEXT_RX_AGG(prod);
836957 sw_prod = NEXT_RX_AGG(sw_prod);
837
- cp_cons = NEXT_CMP(cp_cons);
838958 }
839959 rxr->rx_agg_prod = prod;
840960 rxr->rx_sw_agg_prod = sw_prod;
....@@ -848,7 +968,7 @@
848968 {
849969 unsigned int payload = offset_and_len >> 16;
850970 unsigned int len = offset_and_len & 0xffff;
851
- struct skb_frag_struct *frag;
971
+ skb_frag_t *frag;
852972 struct page *page = data;
853973 u16 prod = rxr->rx_prod;
854974 struct sk_buff *skb;
....@@ -862,9 +982,10 @@
862982 dma_addr -= bp->rx_dma_offset;
863983 dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir,
864984 DMA_ATTR_WEAK_ORDERING);
985
+ page_pool_release_page(rxr->page_pool, page);
865986
866987 if (unlikely(!payload))
867
- payload = eth_get_headlen(data_ptr, len);
988
+ payload = eth_get_headlen(bp->dev, data_ptr, len);
868989
869990 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
870991 if (!skb) {
....@@ -879,7 +1000,7 @@
8791000
8801001 frag = &skb_shinfo(skb)->frags[0];
8811002 skb_frag_size_sub(frag, payload);
882
- frag->page_offset += payload;
1003
+ skb_frag_off_add(frag, payload);
8831004 skb->data_len -= payload;
8841005 skb->tail += payload;
8851006
....@@ -915,15 +1036,20 @@
9151036 return skb;
9161037 }
9171038
918
-static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
919
- struct sk_buff *skb, u16 cp_cons,
920
- u32 agg_bufs)
1039
+static struct sk_buff *bnxt_rx_pages(struct bnxt *bp,
1040
+ struct bnxt_cp_ring_info *cpr,
1041
+ struct sk_buff *skb, u16 idx,
1042
+ u32 agg_bufs, bool tpa)
9211043 {
1044
+ struct bnxt_napi *bnapi = cpr->bnapi;
9221045 struct pci_dev *pdev = bp->pdev;
923
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
9241046 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
9251047 u16 prod = rxr->rx_agg_prod;
1048
+ bool p5_tpa = false;
9261049 u32 i;
1050
+
1051
+ if ((bp->flags & BNXT_FLAG_CHIP_P5) && tpa)
1052
+ p5_tpa = true;
9271053
9281054 for (i = 0; i < agg_bufs; i++) {
9291055 u16 cons, frag_len;
....@@ -932,8 +1058,10 @@
9321058 struct page *page;
9331059 dma_addr_t mapping;
9341060
935
- agg = (struct rx_agg_cmp *)
936
- &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1061
+ if (p5_tpa)
1062
+ agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
1063
+ else
1064
+ agg = bnxt_get_agg(bp, cpr, idx, i);
9371065 cons = agg->rx_agg_cmp_opaque;
9381066 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
9391067 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
....@@ -967,7 +1095,7 @@
9671095 * allocated already.
9681096 */
9691097 rxr->rx_agg_prod = prod;
970
- bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
1098
+ bnxt_reuse_rx_agg_bufs(cpr, idx, i, agg_bufs - i, tpa);
9711099 return NULL;
9721100 }
9731101
....@@ -980,7 +1108,6 @@
9801108 skb->truesize += PAGE_SIZE;
9811109
9821110 prod = NEXT_RX_AGG(prod);
983
- cp_cons = NEXT_CMP(cp_cons);
9841111 }
9851112 rxr->rx_agg_prod = prod;
9861113 return skb;
....@@ -1024,10 +1151,9 @@
10241151 return skb;
10251152 }
10261153
1027
-static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
1154
+static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
10281155 u32 *raw_cons, void *cmp)
10291156 {
1030
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
10311157 struct rx_cmp *rxcmp = cmp;
10321158 u32 tmp_raw_cons = *raw_cons;
10331159 u8 cmp_type, agg_bufs = 0;
....@@ -1041,9 +1167,10 @@
10411167 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
10421168 struct rx_tpa_end_cmp *tpa_end = cmp;
10431169
1044
- agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1045
- RX_TPA_END_CMP_AGG_BUFS) >>
1046
- RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1170
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
1171
+ return 0;
1172
+
1173
+ agg_bufs = TPA_END_AGG_BUFS(tpa_end);
10471174 }
10481175
10491176 if (agg_bufs) {
....@@ -1054,6 +1181,17 @@
10541181 return 0;
10551182 }
10561183
1184
+static void bnxt_queue_fw_reset_work(struct bnxt *bp, unsigned long delay)
1185
+{
1186
+ if (!(test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)))
1187
+ return;
1188
+
1189
+ if (BNXT_PF(bp))
1190
+ queue_delayed_work(bnxt_pf_wq, &bp->fw_reset_task, delay);
1191
+ else
1192
+ schedule_delayed_work(&bp->fw_reset_task, delay);
1193
+}
1194
+
10571195 static void bnxt_queue_sp_work(struct bnxt *bp)
10581196 {
10591197 if (BNXT_PF(bp))
....@@ -1062,44 +1200,73 @@
10621200 schedule_work(&bp->sp_task);
10631201 }
10641202
1065
-static void bnxt_cancel_sp_work(struct bnxt *bp)
1066
-{
1067
- if (BNXT_PF(bp))
1068
- flush_workqueue(bnxt_pf_wq);
1069
- else
1070
- cancel_work_sync(&bp->sp_task);
1071
-}
1072
-
10731203 static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
10741204 {
10751205 if (!rxr->bnapi->in_reset) {
10761206 rxr->bnapi->in_reset = true;
1077
- set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
1207
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
1208
+ set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
1209
+ else
1210
+ set_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event);
10781211 bnxt_queue_sp_work(bp);
10791212 }
10801213 rxr->rx_next_cons = 0xffff;
1214
+}
1215
+
1216
+static u16 bnxt_alloc_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
1217
+{
1218
+ struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
1219
+ u16 idx = agg_id & MAX_TPA_P5_MASK;
1220
+
1221
+ if (test_bit(idx, map->agg_idx_bmap))
1222
+ idx = find_first_zero_bit(map->agg_idx_bmap,
1223
+ BNXT_AGG_IDX_BMAP_SIZE);
1224
+ __set_bit(idx, map->agg_idx_bmap);
1225
+ map->agg_id_tbl[agg_id] = idx;
1226
+ return idx;
1227
+}
1228
+
1229
+static void bnxt_free_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
1230
+{
1231
+ struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
1232
+
1233
+ __clear_bit(idx, map->agg_idx_bmap);
1234
+}
1235
+
1236
+static u16 bnxt_lookup_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
1237
+{
1238
+ struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
1239
+
1240
+ return map->agg_id_tbl[agg_id];
10811241 }
10821242
10831243 static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
10841244 struct rx_tpa_start_cmp *tpa_start,
10851245 struct rx_tpa_start_cmp_ext *tpa_start1)
10861246 {
1087
- u8 agg_id = TPA_START_AGG_ID(tpa_start);
1088
- u16 cons, prod;
1089
- struct bnxt_tpa_info *tpa_info;
10901247 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1248
+ struct bnxt_tpa_info *tpa_info;
1249
+ u16 cons, prod, agg_id;
10911250 struct rx_bd *prod_bd;
10921251 dma_addr_t mapping;
10931252
1253
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
1254
+ agg_id = TPA_START_AGG_ID_P5(tpa_start);
1255
+ agg_id = bnxt_alloc_agg_idx(rxr, agg_id);
1256
+ } else {
1257
+ agg_id = TPA_START_AGG_ID(tpa_start);
1258
+ }
10941259 cons = tpa_start->rx_tpa_start_cmp_opaque;
10951260 prod = rxr->rx_prod;
10961261 cons_rx_buf = &rxr->rx_buf_ring[cons];
10971262 prod_rx_buf = &rxr->rx_buf_ring[prod];
10981263 tpa_info = &rxr->rx_tpa[agg_id];
10991264
1100
- if (unlikely(cons != rxr->rx_next_cons)) {
1101
- netdev_warn(bp->dev, "TPA cons %x != expected cons %x\n",
1102
- cons, rxr->rx_next_cons);
1265
+ if (unlikely(cons != rxr->rx_next_cons ||
1266
+ TPA_START_ERROR(tpa_start))) {
1267
+ netdev_warn(bp->dev, "TPA cons %x, expected cons %x, error code %x\n",
1268
+ cons, rxr->rx_next_cons,
1269
+ TPA_START_ERROR_CODE(tpa_start1));
11031270 bnxt_sched_reset(bp, rxr);
11041271 return;
11051272 }
....@@ -1138,12 +1305,12 @@
11381305 } else {
11391306 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
11401307 tpa_info->gso_type = 0;
1141
- if (netif_msg_rx_err(bp))
1142
- netdev_warn(bp->dev, "TPA packet without valid hash\n");
1308
+ netif_warn(bp, rx_err, bp->dev, "TPA packet without valid hash\n");
11431309 }
11441310 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
11451311 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
11461312 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
1313
+ tpa_info->agg_count = 0;
11471314
11481315 rxr->rx_prod = NEXT_RX(prod);
11491316 cons = NEXT_RX(cons);
....@@ -1155,12 +1322,36 @@
11551322 cons_rx_buf->data = NULL;
11561323 }
11571324
1158
-static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1159
- u16 cp_cons, u32 agg_bufs)
1325
+static void bnxt_abort_tpa(struct bnxt_cp_ring_info *cpr, u16 idx, u32 agg_bufs)
11601326 {
11611327 if (agg_bufs)
1162
- bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1328
+ bnxt_reuse_rx_agg_bufs(cpr, idx, 0, agg_bufs, true);
11631329 }
1330
+
1331
+#ifdef CONFIG_INET
1332
+static void bnxt_gro_tunnel(struct sk_buff *skb, __be16 ip_proto)
1333
+{
1334
+ struct udphdr *uh = NULL;
1335
+
1336
+ if (ip_proto == htons(ETH_P_IP)) {
1337
+ struct iphdr *iph = (struct iphdr *)skb->data;
1338
+
1339
+ if (iph->protocol == IPPROTO_UDP)
1340
+ uh = (struct udphdr *)(iph + 1);
1341
+ } else {
1342
+ struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1343
+
1344
+ if (iph->nexthdr == IPPROTO_UDP)
1345
+ uh = (struct udphdr *)(iph + 1);
1346
+ }
1347
+ if (uh) {
1348
+ if (uh->check)
1349
+ skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
1350
+ else
1351
+ skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1352
+ }
1353
+}
1354
+#endif
11641355
11651356 static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
11661357 int payload_off, int tcp_ts,
....@@ -1219,28 +1410,39 @@
12191410 }
12201411
12211412 if (inner_mac_off) { /* tunnel */
1222
- struct udphdr *uh = NULL;
12231413 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
12241414 ETH_HLEN - 2));
12251415
1226
- if (proto == htons(ETH_P_IP)) {
1227
- struct iphdr *iph = (struct iphdr *)skb->data;
1416
+ bnxt_gro_tunnel(skb, proto);
1417
+ }
1418
+#endif
1419
+ return skb;
1420
+}
12281421
1229
- if (iph->protocol == IPPROTO_UDP)
1230
- uh = (struct udphdr *)(iph + 1);
1231
- } else {
1232
- struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1422
+static struct sk_buff *bnxt_gro_func_5750x(struct bnxt_tpa_info *tpa_info,
1423
+ int payload_off, int tcp_ts,
1424
+ struct sk_buff *skb)
1425
+{
1426
+#ifdef CONFIG_INET
1427
+ u16 outer_ip_off, inner_ip_off, inner_mac_off;
1428
+ u32 hdr_info = tpa_info->hdr_info;
1429
+ int iphdr_len, nw_off;
12331430
1234
- if (iph->nexthdr == IPPROTO_UDP)
1235
- uh = (struct udphdr *)(iph + 1);
1236
- }
1237
- if (uh) {
1238
- if (uh->check)
1239
- skb_shinfo(skb)->gso_type |=
1240
- SKB_GSO_UDP_TUNNEL_CSUM;
1241
- else
1242
- skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1243
- }
1431
+ inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1432
+ inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1433
+ outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1434
+
1435
+ nw_off = inner_ip_off - ETH_HLEN;
1436
+ skb_set_network_header(skb, nw_off);
1437
+ iphdr_len = (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) ?
1438
+ sizeof(struct ipv6hdr) : sizeof(struct iphdr);
1439
+ skb_set_transport_header(skb, nw_off + iphdr_len);
1440
+
1441
+ if (inner_mac_off) { /* tunnel */
1442
+ __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1443
+ ETH_HLEN - 2));
1444
+
1445
+ bnxt_gro_tunnel(skb, proto);
12441446 }
12451447 #endif
12461448 return skb;
....@@ -1287,28 +1489,8 @@
12871489 return NULL;
12881490 }
12891491
1290
- if (nw_off) { /* tunnel */
1291
- struct udphdr *uh = NULL;
1292
-
1293
- if (skb->protocol == htons(ETH_P_IP)) {
1294
- struct iphdr *iph = (struct iphdr *)skb->data;
1295
-
1296
- if (iph->protocol == IPPROTO_UDP)
1297
- uh = (struct udphdr *)(iph + 1);
1298
- } else {
1299
- struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1300
-
1301
- if (iph->nexthdr == IPPROTO_UDP)
1302
- uh = (struct udphdr *)(iph + 1);
1303
- }
1304
- if (uh) {
1305
- if (uh->check)
1306
- skb_shinfo(skb)->gso_type |=
1307
- SKB_GSO_UDP_TUNNEL_CSUM;
1308
- else
1309
- skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1310
- }
1311
- }
1492
+ if (nw_off) /* tunnel */
1493
+ bnxt_gro_tunnel(skb, skb->protocol);
13121494 #endif
13131495 return skb;
13141496 }
....@@ -1331,9 +1513,10 @@
13311513 skb_shinfo(skb)->gso_size =
13321514 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
13331515 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1334
- payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1335
- RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1336
- RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1516
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
1517
+ payload_off = TPA_END_PAYLOAD_OFF_P5(tpa_end1);
1518
+ else
1519
+ payload_off = TPA_END_PAYLOAD_OFF(tpa_end);
13371520 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
13381521 if (likely(skb))
13391522 tcp_gro_complete(skb);
....@@ -1353,51 +1536,68 @@
13531536 }
13541537
13551538 static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1356
- struct bnxt_napi *bnapi,
1539
+ struct bnxt_cp_ring_info *cpr,
13571540 u32 *raw_cons,
13581541 struct rx_tpa_end_cmp *tpa_end,
13591542 struct rx_tpa_end_cmp_ext *tpa_end1,
13601543 u8 *event)
13611544 {
1362
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1545
+ struct bnxt_napi *bnapi = cpr->bnapi;
13631546 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1364
- u8 agg_id = TPA_END_AGG_ID(tpa_end);
13651547 u8 *data_ptr, agg_bufs;
1366
- u16 cp_cons = RING_CMP(*raw_cons);
13671548 unsigned int len;
13681549 struct bnxt_tpa_info *tpa_info;
13691550 dma_addr_t mapping;
13701551 struct sk_buff *skb;
1552
+ u16 idx = 0, agg_id;
13711553 void *data;
1554
+ bool gro;
13721555
13731556 if (unlikely(bnapi->in_reset)) {
1374
- int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1557
+ int rc = bnxt_discard_rx(bp, cpr, raw_cons, tpa_end);
13751558
13761559 if (rc < 0)
13771560 return ERR_PTR(-EBUSY);
13781561 return NULL;
13791562 }
13801563
1381
- tpa_info = &rxr->rx_tpa[agg_id];
1564
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
1565
+ agg_id = TPA_END_AGG_ID_P5(tpa_end);
1566
+ agg_id = bnxt_lookup_agg_idx(rxr, agg_id);
1567
+ agg_bufs = TPA_END_AGG_BUFS_P5(tpa_end1);
1568
+ tpa_info = &rxr->rx_tpa[agg_id];
1569
+ if (unlikely(agg_bufs != tpa_info->agg_count)) {
1570
+ netdev_warn(bp->dev, "TPA end agg_buf %d != expected agg_bufs %d\n",
1571
+ agg_bufs, tpa_info->agg_count);
1572
+ agg_bufs = tpa_info->agg_count;
1573
+ }
1574
+ tpa_info->agg_count = 0;
1575
+ *event |= BNXT_AGG_EVENT;
1576
+ bnxt_free_agg_idx(rxr, agg_id);
1577
+ idx = agg_id;
1578
+ gro = !!(bp->flags & BNXT_FLAG_GRO);
1579
+ } else {
1580
+ agg_id = TPA_END_AGG_ID(tpa_end);
1581
+ agg_bufs = TPA_END_AGG_BUFS(tpa_end);
1582
+ tpa_info = &rxr->rx_tpa[agg_id];
1583
+ idx = RING_CMP(*raw_cons);
1584
+ if (agg_bufs) {
1585
+ if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1586
+ return ERR_PTR(-EBUSY);
1587
+
1588
+ *event |= BNXT_AGG_EVENT;
1589
+ idx = NEXT_CMP(idx);
1590
+ }
1591
+ gro = !!TPA_END_GRO(tpa_end);
1592
+ }
13821593 data = tpa_info->data;
13831594 data_ptr = tpa_info->data_ptr;
13841595 prefetch(data_ptr);
13851596 len = tpa_info->len;
13861597 mapping = tpa_info->mapping;
13871598
1388
- agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1389
- RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1390
-
1391
- if (agg_bufs) {
1392
- if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1393
- return ERR_PTR(-EBUSY);
1394
-
1395
- *event |= BNXT_AGG_EVENT;
1396
- cp_cons = NEXT_CMP(cp_cons);
1397
- }
1398
-
13991599 if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) {
1400
- bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1600
+ bnxt_abort_tpa(cpr, idx, agg_bufs);
14011601 if (agg_bufs > MAX_SKB_FRAGS)
14021602 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
14031603 agg_bufs, (int)MAX_SKB_FRAGS);
....@@ -1407,7 +1607,7 @@
14071607 if (len <= bp->rx_copy_thresh) {
14081608 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
14091609 if (!skb) {
1410
- bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1610
+ bnxt_abort_tpa(cpr, idx, agg_bufs);
14111611 return NULL;
14121612 }
14131613 } else {
....@@ -1416,7 +1616,7 @@
14161616
14171617 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
14181618 if (!new_data) {
1419
- bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1619
+ bnxt_abort_tpa(cpr, idx, agg_bufs);
14201620 return NULL;
14211621 }
14221622
....@@ -1431,7 +1631,7 @@
14311631
14321632 if (!skb) {
14331633 kfree(data);
1434
- bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1634
+ bnxt_abort_tpa(cpr, idx, agg_bufs);
14351635 return NULL;
14361636 }
14371637 skb_reserve(skb, bp->rx_offset);
....@@ -1439,7 +1639,7 @@
14391639 }
14401640
14411641 if (agg_bufs) {
1442
- skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1642
+ skb = bnxt_rx_pages(bp, cpr, skb, idx, agg_bufs, true);
14431643 if (!skb) {
14441644 /* Page reuse already handled by bnxt_rx_pages(). */
14451645 return NULL;
....@@ -1453,12 +1653,17 @@
14531653 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
14541654
14551655 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1456
- (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1457
- u16 vlan_proto = tpa_info->metadata >>
1458
- RX_CMP_FLAGS2_METADATA_TPID_SFT;
1656
+ (skb->dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
1657
+ __be16 vlan_proto = htons(tpa_info->metadata >>
1658
+ RX_CMP_FLAGS2_METADATA_TPID_SFT);
14591659 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
14601660
1461
- __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1661
+ if (eth_type_vlan(vlan_proto)) {
1662
+ __vlan_hwaccel_put_tag(skb, vlan_proto, vtag);
1663
+ } else {
1664
+ dev_kfree_skb(skb);
1665
+ return NULL;
1666
+ }
14621667 }
14631668
14641669 skb_checksum_none_assert(skb);
....@@ -1468,10 +1673,22 @@
14681673 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
14691674 }
14701675
1471
- if (TPA_END_GRO(tpa_end))
1676
+ if (gro)
14721677 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
14731678
14741679 return skb;
1680
+}
1681
+
1682
+static void bnxt_tpa_agg(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1683
+ struct rx_agg_cmp *rx_agg)
1684
+{
1685
+ u16 agg_id = TPA_AGG_AGG_ID(rx_agg);
1686
+ struct bnxt_tpa_info *tpa_info;
1687
+
1688
+ agg_id = bnxt_lookup_agg_idx(rxr, agg_id);
1689
+ tpa_info = &rxr->rx_tpa[agg_id];
1690
+ BUG_ON(tpa_info->agg_count >= MAX_SKB_FRAGS);
1691
+ tpa_info->agg_arr[tpa_info->agg_count++] = *rx_agg;
14751692 }
14761693
14771694 static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
....@@ -1493,10 +1710,10 @@
14931710 * -ENOMEM - packet aborted due to out of memory
14941711 * -EIO - packet aborted due to hw error indicated in BD
14951712 */
1496
-static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
1497
- u8 *event)
1713
+static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1714
+ u32 *raw_cons, u8 *event)
14981715 {
1499
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1716
+ struct bnxt_napi *bnapi = cpr->bnapi;
15001717 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
15011718 struct net_device *dev = bp->dev;
15021719 struct rx_cmp *rxcmp;
....@@ -1515,6 +1732,13 @@
15151732 rxcmp = (struct rx_cmp *)
15161733 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
15171734
1735
+ cmp_type = RX_CMP_TYPE(rxcmp);
1736
+
1737
+ if (cmp_type == CMP_TYPE_RX_TPA_AGG_CMP) {
1738
+ bnxt_tpa_agg(bp, rxr, (struct rx_agg_cmp *)rxcmp);
1739
+ goto next_rx_no_prod_no_len;
1740
+ }
1741
+
15181742 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
15191743 cp_cons = RING_CMP(tmp_raw_cons);
15201744 rxcmp1 = (struct rx_cmp_ext *)
....@@ -1523,8 +1747,10 @@
15231747 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
15241748 return -EBUSY;
15251749
1526
- cmp_type = RX_CMP_TYPE(rxcmp);
1527
-
1750
+ /* The valid test of the entry must be done first before
1751
+ * reading any further.
1752
+ */
1753
+ dma_rmb();
15281754 prod = rxr->rx_prod;
15291755
15301756 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
....@@ -1535,7 +1761,7 @@
15351761 goto next_rx_no_prod_no_len;
15361762
15371763 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1538
- skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1764
+ skb = bnxt_tpa_end(bp, cpr, &tmp_raw_cons,
15391765 (struct rx_tpa_end_cmp *)rxcmp,
15401766 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
15411767
....@@ -1553,12 +1779,16 @@
15531779
15541780 cons = rxcmp->rx_cmp_opaque;
15551781 if (unlikely(cons != rxr->rx_next_cons)) {
1556
- int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1782
+ int rc1 = bnxt_discard_rx(bp, cpr, &tmp_raw_cons, rxcmp);
15571783
1558
- netdev_warn(bp->dev, "RX cons %x != expected cons %x\n",
1559
- cons, rxr->rx_next_cons);
1784
+ /* 0xffff is forced error, don't print it */
1785
+ if (rxr->rx_next_cons != 0xffff)
1786
+ netdev_warn(bp->dev, "RX cons %x != expected cons %x\n",
1787
+ cons, rxr->rx_next_cons);
15601788 bnxt_sched_reset(bp, rxr);
1561
- return rc1;
1789
+ if (rc1)
1790
+ return rc1;
1791
+ goto next_rx_no_prod_no_len;
15621792 }
15631793 rx_buf = &rxr->rx_buf_ring[cons];
15641794 data = rx_buf->data;
....@@ -1583,12 +1813,18 @@
15831813
15841814 bnxt_reuse_rx_data(rxr, cons, data);
15851815 if (agg_bufs)
1586
- bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1816
+ bnxt_reuse_rx_agg_bufs(cpr, cp_cons, 0, agg_bufs,
1817
+ false);
15871818
15881819 rc = -EIO;
15891820 if (rx_err & RX_CMPL_ERRORS_BUFFER_ERROR_MASK) {
1590
- netdev_warn(bp->dev, "RX buffer error %x\n", rx_err);
1591
- bnxt_sched_reset(bp, rxr);
1821
+ bnapi->cp_ring.sw_stats.rx.rx_buf_errors++;
1822
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5) &&
1823
+ !(bp->fw_cap & BNXT_FW_CAP_RING_MONITOR)) {
1824
+ netdev_warn_once(bp->dev, "RX buffer error %x\n",
1825
+ rx_err);
1826
+ bnxt_sched_reset(bp, rxr);
1827
+ }
15921828 }
15931829 goto next_rx_no_len;
15941830 }
....@@ -1606,7 +1842,8 @@
16061842 bnxt_reuse_rx_data(rxr, cons, data);
16071843 if (!skb) {
16081844 if (agg_bufs)
1609
- bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1845
+ bnxt_reuse_rx_agg_bufs(cpr, cp_cons, 0,
1846
+ agg_bufs, false);
16101847 rc = -ENOMEM;
16111848 goto next_rx;
16121849 }
....@@ -1626,7 +1863,7 @@
16261863 }
16271864
16281865 if (agg_bufs) {
1629
- skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1866
+ skb = bnxt_rx_pages(bp, cpr, skb, cp_cons, agg_bufs, false);
16301867 if (!skb) {
16311868 rc = -ENOMEM;
16321869 goto next_rx;
....@@ -1648,12 +1885,18 @@
16481885
16491886 if ((rxcmp1->rx_cmp_flags2 &
16501887 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1651
- (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1888
+ (skb->dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
16521889 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
16531890 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
1654
- u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1891
+ __be16 vlan_proto = htons(meta_data >>
1892
+ RX_CMP_FLAGS2_METADATA_TPID_SFT);
16551893
1656
- __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1894
+ if (eth_type_vlan(vlan_proto)) {
1895
+ __vlan_hwaccel_put_tag(skb, vlan_proto, vtag);
1896
+ } else {
1897
+ dev_kfree_skb(skb);
1898
+ goto next_rx;
1899
+ }
16571900 }
16581901
16591902 skb_checksum_none_assert(skb);
....@@ -1665,7 +1908,7 @@
16651908 } else {
16661909 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
16671910 if (dev->features & NETIF_F_RXCSUM)
1668
- cpr->rx_l4_csum_errors++;
1911
+ bnapi->cp_ring.sw_stats.rx.rx_l4_csum_errors++;
16691912 }
16701913 }
16711914
....@@ -1689,10 +1932,10 @@
16891932 /* In netpoll mode, if we are using a combined completion ring, we need to
16901933 * discard the rx packets and recycle the buffers.
16911934 */
1692
-static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi,
1935
+static int bnxt_force_rx_discard(struct bnxt *bp,
1936
+ struct bnxt_cp_ring_info *cpr,
16931937 u32 *raw_cons, u8 *event)
16941938 {
1695
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
16961939 u32 tmp_raw_cons = *raw_cons;
16971940 struct rx_cmp_ext *rxcmp1;
16981941 struct rx_cmp *rxcmp;
....@@ -1711,6 +1954,10 @@
17111954 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
17121955 return -EBUSY;
17131956
1957
+ /* The valid test of the entry must be done first before
1958
+ * reading any further.
1959
+ */
1960
+ dma_rmb();
17141961 cmp_type = RX_CMP_TYPE(rxcmp);
17151962 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
17161963 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
....@@ -1722,22 +1969,73 @@
17221969 tpa_end1->rx_tpa_end_cmp_errors_v2 |=
17231970 cpu_to_le32(RX_TPA_END_CMP_ERRORS);
17241971 }
1725
- return bnxt_rx_pkt(bp, bnapi, raw_cons, event);
1972
+ return bnxt_rx_pkt(bp, cpr, raw_cons, event);
1973
+}
1974
+
1975
+u32 bnxt_fw_health_readl(struct bnxt *bp, int reg_idx)
1976
+{
1977
+ struct bnxt_fw_health *fw_health = bp->fw_health;
1978
+ u32 reg = fw_health->regs[reg_idx];
1979
+ u32 reg_type, reg_off, val = 0;
1980
+
1981
+ reg_type = BNXT_FW_HEALTH_REG_TYPE(reg);
1982
+ reg_off = BNXT_FW_HEALTH_REG_OFF(reg);
1983
+ switch (reg_type) {
1984
+ case BNXT_FW_HEALTH_REG_TYPE_CFG:
1985
+ pci_read_config_dword(bp->pdev, reg_off, &val);
1986
+ break;
1987
+ case BNXT_FW_HEALTH_REG_TYPE_GRC:
1988
+ reg_off = fw_health->mapped_regs[reg_idx];
1989
+ fallthrough;
1990
+ case BNXT_FW_HEALTH_REG_TYPE_BAR0:
1991
+ val = readl(bp->bar0 + reg_off);
1992
+ break;
1993
+ case BNXT_FW_HEALTH_REG_TYPE_BAR1:
1994
+ val = readl(bp->bar1 + reg_off);
1995
+ break;
1996
+ }
1997
+ if (reg_idx == BNXT_FW_RESET_INPROG_REG)
1998
+ val &= fw_health->fw_reset_inprog_reg_mask;
1999
+ return val;
2000
+}
2001
+
2002
+static u16 bnxt_agg_ring_id_to_grp_idx(struct bnxt *bp, u16 ring_id)
2003
+{
2004
+ int i;
2005
+
2006
+ for (i = 0; i < bp->rx_nr_rings; i++) {
2007
+ u16 grp_idx = bp->rx_ring[i].bnapi->index;
2008
+ struct bnxt_ring_grp_info *grp_info;
2009
+
2010
+ grp_info = &bp->grp_info[grp_idx];
2011
+ if (grp_info->agg_fw_ring_id == ring_id)
2012
+ return grp_idx;
2013
+ }
2014
+ return INVALID_HW_RING_ID;
17262015 }
17272016
17282017 #define BNXT_GET_EVENT_PORT(data) \
17292018 ((data) & \
17302019 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
17312020
2021
+#define BNXT_EVENT_RING_TYPE(data2) \
2022
+ ((data2) & \
2023
+ ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_MASK)
2024
+
2025
+#define BNXT_EVENT_RING_TYPE_RX(data2) \
2026
+ (BNXT_EVENT_RING_TYPE(data2) == \
2027
+ ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_RX)
2028
+
17322029 static int bnxt_async_event_process(struct bnxt *bp,
17332030 struct hwrm_async_event_cmpl *cmpl)
17342031 {
17352032 u16 event_id = le16_to_cpu(cmpl->event_id);
2033
+ u32 data1 = le32_to_cpu(cmpl->event_data1);
2034
+ u32 data2 = le32_to_cpu(cmpl->event_data2);
17362035
17372036 /* TODO CHIMP_FW: Define event id's for link change, error etc */
17382037 switch (event_id) {
17392038 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
1740
- u32 data1 = le32_to_cpu(cmpl->event_data1);
17412039 struct bnxt_link_info *link_info = &bp->link_info;
17422040
17432041 if (BNXT_VF(bp))
....@@ -1755,7 +2053,11 @@
17552053 }
17562054 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
17572055 }
1758
- /* fall through */
2056
+ fallthrough;
2057
+ case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
2058
+ case ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE:
2059
+ set_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT, &bp->sp_event);
2060
+ fallthrough;
17592061 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
17602062 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
17612063 break;
....@@ -1763,7 +2065,6 @@
17632065 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
17642066 break;
17652067 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
1766
- u32 data1 = le32_to_cpu(cmpl->event_data1);
17672068 u16 port_id = BNXT_GET_EVENT_PORT(data1);
17682069
17692070 if (BNXT_VF(bp))
....@@ -1780,6 +2081,93 @@
17802081 goto async_event_process_exit;
17812082 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
17822083 break;
2084
+ case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY: {
2085
+ char *fatal_str = "non-fatal";
2086
+
2087
+ if (!bp->fw_health)
2088
+ goto async_event_process_exit;
2089
+
2090
+ bp->fw_reset_timestamp = jiffies;
2091
+ bp->fw_reset_min_dsecs = cmpl->timestamp_lo;
2092
+ if (!bp->fw_reset_min_dsecs)
2093
+ bp->fw_reset_min_dsecs = BNXT_DFLT_FW_RST_MIN_DSECS;
2094
+ bp->fw_reset_max_dsecs = le16_to_cpu(cmpl->timestamp_hi);
2095
+ if (!bp->fw_reset_max_dsecs)
2096
+ bp->fw_reset_max_dsecs = BNXT_DFLT_FW_RST_MAX_DSECS;
2097
+ if (EVENT_DATA1_RESET_NOTIFY_FATAL(data1)) {
2098
+ fatal_str = "fatal";
2099
+ set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
2100
+ }
2101
+ netif_warn(bp, hw, bp->dev,
2102
+ "Firmware %s reset event, data1: 0x%x, data2: 0x%x, min wait %u ms, max wait %u ms\n",
2103
+ fatal_str, data1, data2,
2104
+ bp->fw_reset_min_dsecs * 100,
2105
+ bp->fw_reset_max_dsecs * 100);
2106
+ set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event);
2107
+ break;
2108
+ }
2109
+ case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY: {
2110
+ struct bnxt_fw_health *fw_health = bp->fw_health;
2111
+
2112
+ if (!fw_health)
2113
+ goto async_event_process_exit;
2114
+
2115
+ if (!EVENT_DATA1_RECOVERY_ENABLED(data1)) {
2116
+ fw_health->enabled = false;
2117
+ netif_info(bp, drv, bp->dev,
2118
+ "Error recovery info: error recovery[0]\n");
2119
+ break;
2120
+ }
2121
+ fw_health->master = EVENT_DATA1_RECOVERY_MASTER_FUNC(data1);
2122
+ fw_health->tmr_multiplier =
2123
+ DIV_ROUND_UP(fw_health->polling_dsecs * HZ,
2124
+ bp->current_interval * 10);
2125
+ fw_health->tmr_counter = fw_health->tmr_multiplier;
2126
+ if (!fw_health->enabled)
2127
+ fw_health->last_fw_heartbeat =
2128
+ bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
2129
+ fw_health->last_fw_reset_cnt =
2130
+ bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
2131
+ netif_info(bp, drv, bp->dev,
2132
+ "Error recovery info: error recovery[1], master[%d], reset count[%u], health status: 0x%x\n",
2133
+ fw_health->master, fw_health->last_fw_reset_cnt,
2134
+ bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG));
2135
+ if (!fw_health->enabled) {
2136
+ /* Make sure tmr_counter is set and visible to
2137
+ * bnxt_health_check() before setting enabled to true.
2138
+ */
2139
+ smp_wmb();
2140
+ fw_health->enabled = true;
2141
+ }
2142
+ goto async_event_process_exit;
2143
+ }
2144
+ case ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION:
2145
+ netif_notice(bp, hw, bp->dev,
2146
+ "Received firmware debug notification, data1: 0x%x, data2: 0x%x\n",
2147
+ data1, data2);
2148
+ goto async_event_process_exit;
2149
+ case ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG: {
2150
+ struct bnxt_rx_ring_info *rxr;
2151
+ u16 grp_idx;
2152
+
2153
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
2154
+ goto async_event_process_exit;
2155
+
2156
+ netdev_warn(bp->dev, "Ring monitor event, ring type %lu id 0x%x\n",
2157
+ BNXT_EVENT_RING_TYPE(data2), data1);
2158
+ if (!BNXT_EVENT_RING_TYPE_RX(data2))
2159
+ goto async_event_process_exit;
2160
+
2161
+ grp_idx = bnxt_agg_ring_id_to_grp_idx(bp, data1);
2162
+ if (grp_idx == INVALID_HW_RING_ID) {
2163
+ netdev_warn(bp->dev, "Unknown RX agg ring id 0x%x\n",
2164
+ data1);
2165
+ goto async_event_process_exit;
2166
+ }
2167
+ rxr = bp->bnapi[grp_idx]->rx_ring;
2168
+ bnxt_sched_reset(bp, rxr);
2169
+ goto async_event_process_exit;
2170
+ }
17832171 default:
17842172 goto async_event_process_exit;
17852173 }
....@@ -1800,7 +2188,7 @@
18002188 case CMPL_BASE_TYPE_HWRM_DONE:
18012189 seq_id = le16_to_cpu(h_cmpl->sequence_id);
18022190 if (seq_id == bp->hwrm_intr_seq_id)
1803
- bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
2191
+ bp->hwrm_intr_seq_id = (u16)~bp->hwrm_intr_seq_id;
18042192 else
18052193 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
18062194 break;
....@@ -1873,7 +2261,7 @@
18732261 }
18742262
18752263 /* disable ring IRQ */
1876
- BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
2264
+ BNXT_CP_DB_IRQ_DIS(cpr->cp_db.doorbell);
18772265
18782266 /* Return here if interrupt is shared and is disabled. */
18792267 if (unlikely(atomic_read(&bp->intr_sem) != 0))
....@@ -1883,9 +2271,10 @@
18832271 return IRQ_HANDLED;
18842272 }
18852273
1886
-static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
2274
+static int __bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2275
+ int budget)
18872276 {
1888
- struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2277
+ struct bnxt_napi *bnapi = cpr->bnapi;
18892278 u32 raw_cons = cpr->cp_raw_cons;
18902279 u32 cons;
18912280 int tx_pkts = 0;
....@@ -1893,6 +2282,8 @@
18932282 u8 event = 0;
18942283 struct tx_cmp *txcmp;
18952284
2285
+ cpr->has_more_work = 0;
2286
+ cpr->had_work_done = 1;
18962287 while (1) {
18972288 int rc;
18982289
....@@ -1912,13 +2303,15 @@
19122303 if (unlikely(tx_pkts >= bp->tx_wake_thresh)) {
19132304 rx_pkts = budget;
19142305 raw_cons = NEXT_RAW_CMP(raw_cons);
2306
+ if (budget)
2307
+ cpr->has_more_work = 1;
19152308 break;
19162309 }
19172310 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
19182311 if (likely(budget))
1919
- rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
2312
+ rc = bnxt_rx_pkt(bp, cpr, &raw_cons, &event);
19202313 else
1921
- rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons,
2314
+ rc = bnxt_force_rx_discard(bp, cpr, &raw_cons,
19222315 &event);
19232316 if (likely(rc >= 0))
19242317 rx_pkts += rc;
....@@ -1941,39 +2334,63 @@
19412334 }
19422335 raw_cons = NEXT_RAW_CMP(raw_cons);
19432336
1944
- if (rx_pkts && rx_pkts == budget)
2337
+ if (rx_pkts && rx_pkts == budget) {
2338
+ cpr->has_more_work = 1;
19452339 break;
2340
+ }
19462341 }
2342
+
2343
+ if (event & BNXT_REDIRECT_EVENT)
2344
+ xdp_do_flush_map();
19472345
19482346 if (event & BNXT_TX_EVENT) {
19492347 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1950
- void __iomem *db = txr->tx_doorbell;
19512348 u16 prod = txr->tx_prod;
19522349
19532350 /* Sync BD data before updating doorbell */
19542351 wmb();
19552352
1956
- bnxt_db_write_relaxed(bp, db, DB_KEY_TX | prod);
2353
+ bnxt_db_write_relaxed(bp, &txr->tx_db, prod);
19572354 }
19582355
19592356 cpr->cp_raw_cons = raw_cons;
2357
+ bnapi->tx_pkts += tx_pkts;
2358
+ bnapi->events |= event;
2359
+ return rx_pkts;
2360
+}
2361
+
2362
+static void __bnxt_poll_work_done(struct bnxt *bp, struct bnxt_napi *bnapi)
2363
+{
2364
+ if (bnapi->tx_pkts) {
2365
+ bnapi->tx_int(bp, bnapi, bnapi->tx_pkts);
2366
+ bnapi->tx_pkts = 0;
2367
+ }
2368
+
2369
+ if ((bnapi->events & BNXT_RX_EVENT) && !(bnapi->in_reset)) {
2370
+ struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
2371
+
2372
+ if (bnapi->events & BNXT_AGG_EVENT)
2373
+ bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
2374
+ bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
2375
+ }
2376
+ bnapi->events = 0;
2377
+}
2378
+
2379
+static int bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2380
+ int budget)
2381
+{
2382
+ struct bnxt_napi *bnapi = cpr->bnapi;
2383
+ int rx_pkts;
2384
+
2385
+ rx_pkts = __bnxt_poll_work(bp, cpr, budget);
2386
+
19602387 /* ACK completion ring before freeing tx ring and producing new
19612388 * buffers in rx/agg rings to prevent overflowing the completion
19622389 * ring.
19632390 */
1964
- BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
2391
+ bnxt_db_cq(bp, &cpr->cp_db, cpr->cp_raw_cons);
19652392
1966
- if (tx_pkts)
1967
- bnapi->tx_int(bp, bnapi, tx_pkts);
1968
-
1969
- if (event & BNXT_RX_EVENT) {
1970
- struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1971
-
1972
- bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1973
- if (event & BNXT_AGG_EVENT)
1974
- bnxt_db_write(bp, rxr->rx_agg_doorbell,
1975
- DB_KEY_RX | rxr->rx_agg_prod);
1976
- }
2393
+ __bnxt_poll_work_done(bp, bnapi);
19772394 return rx_pkts;
19782395 }
19792396
....@@ -1999,6 +2416,10 @@
19992416 if (!TX_CMP_VALID(txcmp, raw_cons))
20002417 break;
20012418
2419
+ /* The valid test of the entry must be done first before
2420
+ * reading any further.
2421
+ */
2422
+ dma_rmb();
20022423 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
20032424 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
20042425 cp_cons = RING_CMP(tmp_raw_cons);
....@@ -2012,7 +2433,7 @@
20122433 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
20132434 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
20142435
2015
- rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
2436
+ rc = bnxt_rx_pkt(bp, cpr, &raw_cons, &event);
20162437 if (likely(rc == -EIO) && budget)
20172438 rx_pkts++;
20182439 else if (rc == -EBUSY) /* partial completion */
....@@ -2031,16 +2452,15 @@
20312452 }
20322453
20332454 cpr->cp_raw_cons = raw_cons;
2034
- BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
2035
- bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
2455
+ BNXT_DB_CQ(&cpr->cp_db, cpr->cp_raw_cons);
2456
+ bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
20362457
20372458 if (event & BNXT_AGG_EVENT)
2038
- bnxt_db_write(bp, rxr->rx_agg_doorbell,
2039
- DB_KEY_RX | rxr->rx_agg_prod);
2459
+ bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
20402460
20412461 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
20422462 napi_complete_done(napi, rx_pkts);
2043
- BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
2463
+ BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
20442464 }
20452465 return rx_pkts;
20462466 }
....@@ -2053,32 +2473,126 @@
20532473 int work_done = 0;
20542474
20552475 while (1) {
2056
- work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
2476
+ work_done += bnxt_poll_work(bp, cpr, budget - work_done);
20572477
20582478 if (work_done >= budget) {
20592479 if (!budget)
2060
- BNXT_CP_DB_REARM(cpr->cp_doorbell,
2061
- cpr->cp_raw_cons);
2480
+ BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
20622481 break;
20632482 }
20642483
20652484 if (!bnxt_has_work(bp, cpr)) {
20662485 if (napi_complete_done(napi, work_done))
2067
- BNXT_CP_DB_REARM(cpr->cp_doorbell,
2068
- cpr->cp_raw_cons);
2486
+ BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
20692487 break;
20702488 }
20712489 }
20722490 if (bp->flags & BNXT_FLAG_DIM) {
2073
- struct net_dim_sample dim_sample;
2491
+ struct dim_sample dim_sample = {};
20742492
2075
- net_dim_sample(cpr->event_ctr,
2076
- cpr->rx_packets,
2077
- cpr->rx_bytes,
2078
- &dim_sample);
2493
+ dim_update_sample(cpr->event_ctr,
2494
+ cpr->rx_packets,
2495
+ cpr->rx_bytes,
2496
+ &dim_sample);
20792497 net_dim(&cpr->dim, dim_sample);
20802498 }
2081
- mmiowb();
2499
+ return work_done;
2500
+}
2501
+
2502
+static int __bnxt_poll_cqs(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
2503
+{
2504
+ struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2505
+ int i, work_done = 0;
2506
+
2507
+ for (i = 0; i < 2; i++) {
2508
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
2509
+
2510
+ if (cpr2) {
2511
+ work_done += __bnxt_poll_work(bp, cpr2,
2512
+ budget - work_done);
2513
+ cpr->has_more_work |= cpr2->has_more_work;
2514
+ }
2515
+ }
2516
+ return work_done;
2517
+}
2518
+
2519
+static void __bnxt_poll_cqs_done(struct bnxt *bp, struct bnxt_napi *bnapi,
2520
+ u64 dbr_type)
2521
+{
2522
+ struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2523
+ int i;
2524
+
2525
+ for (i = 0; i < 2; i++) {
2526
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
2527
+ struct bnxt_db_info *db;
2528
+
2529
+ if (cpr2 && cpr2->had_work_done) {
2530
+ db = &cpr2->cp_db;
2531
+ writeq(db->db_key64 | dbr_type |
2532
+ RING_CMP(cpr2->cp_raw_cons), db->doorbell);
2533
+ cpr2->had_work_done = 0;
2534
+ }
2535
+ }
2536
+ __bnxt_poll_work_done(bp, bnapi);
2537
+}
2538
+
2539
+static int bnxt_poll_p5(struct napi_struct *napi, int budget)
2540
+{
2541
+ struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
2542
+ struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2543
+ u32 raw_cons = cpr->cp_raw_cons;
2544
+ struct bnxt *bp = bnapi->bp;
2545
+ struct nqe_cn *nqcmp;
2546
+ int work_done = 0;
2547
+ u32 cons;
2548
+
2549
+ if (cpr->has_more_work) {
2550
+ cpr->has_more_work = 0;
2551
+ work_done = __bnxt_poll_cqs(bp, bnapi, budget);
2552
+ }
2553
+ while (1) {
2554
+ cons = RING_CMP(raw_cons);
2555
+ nqcmp = &cpr->nq_desc_ring[CP_RING(cons)][CP_IDX(cons)];
2556
+
2557
+ if (!NQ_CMP_VALID(nqcmp, raw_cons)) {
2558
+ if (cpr->has_more_work)
2559
+ break;
2560
+
2561
+ __bnxt_poll_cqs_done(bp, bnapi, DBR_TYPE_CQ_ARMALL);
2562
+ cpr->cp_raw_cons = raw_cons;
2563
+ if (napi_complete_done(napi, work_done))
2564
+ BNXT_DB_NQ_ARM_P5(&cpr->cp_db,
2565
+ cpr->cp_raw_cons);
2566
+ return work_done;
2567
+ }
2568
+
2569
+ /* The valid test of the entry must be done first before
2570
+ * reading any further.
2571
+ */
2572
+ dma_rmb();
2573
+
2574
+ if (nqcmp->type == cpu_to_le16(NQ_CN_TYPE_CQ_NOTIFICATION)) {
2575
+ u32 idx = le32_to_cpu(nqcmp->cq_handle_low);
2576
+ struct bnxt_cp_ring_info *cpr2;
2577
+
2578
+ /* No more budget for RX work */
2579
+ if (budget && work_done >= budget && idx == BNXT_RX_HDL)
2580
+ break;
2581
+
2582
+ cpr2 = cpr->cp_ring_arr[idx];
2583
+ work_done += __bnxt_poll_work(bp, cpr2,
2584
+ budget - work_done);
2585
+ cpr->has_more_work |= cpr2->has_more_work;
2586
+ } else {
2587
+ bnxt_hwrm_handler(bp, (struct tx_cmp *)nqcmp);
2588
+ }
2589
+ raw_cons = NEXT_RAW_CMP(raw_cons);
2590
+ }
2591
+ __bnxt_poll_cqs_done(bp, bnapi, DBR_TYPE_CQ);
2592
+ if (raw_cons != cpr->cp_raw_cons) {
2593
+ cpr->cp_raw_cons = raw_cons;
2594
+ BNXT_DB_NQ_P5(&cpr->cp_db, raw_cons);
2595
+ }
20822596 return work_done;
20832597 }
20842598
....@@ -2095,11 +2609,28 @@
20952609 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
20962610 int j;
20972611
2612
+ if (!txr->tx_buf_ring)
2613
+ continue;
2614
+
20982615 for (j = 0; j < max_idx;) {
20992616 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
2100
- struct sk_buff *skb = tx_buf->skb;
2617
+ struct sk_buff *skb;
21012618 int k, last;
21022619
2620
+ if (i < bp->tx_nr_rings_xdp &&
2621
+ tx_buf->action == XDP_REDIRECT) {
2622
+ dma_unmap_single(&pdev->dev,
2623
+ dma_unmap_addr(tx_buf, mapping),
2624
+ dma_unmap_len(tx_buf, len),
2625
+ PCI_DMA_TODEVICE);
2626
+ xdp_return_frame(tx_buf->xdpf);
2627
+ tx_buf->action = 0;
2628
+ tx_buf->xdpf = NULL;
2629
+ j++;
2630
+ continue;
2631
+ }
2632
+
2633
+ skb = tx_buf->skb;
21032634 if (!skb) {
21042635 j++;
21052636 continue;
....@@ -2136,89 +2667,101 @@
21362667 }
21372668 }
21382669
2670
+static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
2671
+{
2672
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
2673
+ struct pci_dev *pdev = bp->pdev;
2674
+ struct bnxt_tpa_idx_map *map;
2675
+ int i, max_idx, max_agg_idx;
2676
+
2677
+ max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2678
+ max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2679
+ if (!rxr->rx_tpa)
2680
+ goto skip_rx_tpa_free;
2681
+
2682
+ for (i = 0; i < bp->max_tpa; i++) {
2683
+ struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[i];
2684
+ u8 *data = tpa_info->data;
2685
+
2686
+ if (!data)
2687
+ continue;
2688
+
2689
+ dma_unmap_single_attrs(&pdev->dev, tpa_info->mapping,
2690
+ bp->rx_buf_use_size, bp->rx_dir,
2691
+ DMA_ATTR_WEAK_ORDERING);
2692
+
2693
+ tpa_info->data = NULL;
2694
+
2695
+ kfree(data);
2696
+ }
2697
+
2698
+skip_rx_tpa_free:
2699
+ if (!rxr->rx_buf_ring)
2700
+ goto skip_rx_buf_free;
2701
+
2702
+ for (i = 0; i < max_idx; i++) {
2703
+ struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
2704
+ dma_addr_t mapping = rx_buf->mapping;
2705
+ void *data = rx_buf->data;
2706
+
2707
+ if (!data)
2708
+ continue;
2709
+
2710
+ rx_buf->data = NULL;
2711
+ if (BNXT_RX_PAGE_MODE(bp)) {
2712
+ mapping -= bp->rx_dma_offset;
2713
+ dma_unmap_page_attrs(&pdev->dev, mapping, PAGE_SIZE,
2714
+ bp->rx_dir,
2715
+ DMA_ATTR_WEAK_ORDERING);
2716
+ page_pool_recycle_direct(rxr->page_pool, data);
2717
+ } else {
2718
+ dma_unmap_single_attrs(&pdev->dev, mapping,
2719
+ bp->rx_buf_use_size, bp->rx_dir,
2720
+ DMA_ATTR_WEAK_ORDERING);
2721
+ kfree(data);
2722
+ }
2723
+ }
2724
+
2725
+skip_rx_buf_free:
2726
+ if (!rxr->rx_agg_ring)
2727
+ goto skip_rx_agg_free;
2728
+
2729
+ for (i = 0; i < max_agg_idx; i++) {
2730
+ struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
2731
+ struct page *page = rx_agg_buf->page;
2732
+
2733
+ if (!page)
2734
+ continue;
2735
+
2736
+ dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2737
+ BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
2738
+ DMA_ATTR_WEAK_ORDERING);
2739
+
2740
+ rx_agg_buf->page = NULL;
2741
+ __clear_bit(i, rxr->rx_agg_bmap);
2742
+
2743
+ __free_page(page);
2744
+ }
2745
+
2746
+skip_rx_agg_free:
2747
+ if (rxr->rx_page) {
2748
+ __free_page(rxr->rx_page);
2749
+ rxr->rx_page = NULL;
2750
+ }
2751
+ map = rxr->rx_tpa_idx_map;
2752
+ if (map)
2753
+ memset(map->agg_idx_bmap, 0, sizeof(map->agg_idx_bmap));
2754
+}
2755
+
21392756 static void bnxt_free_rx_skbs(struct bnxt *bp)
21402757 {
2141
- int i, max_idx, max_agg_idx;
2142
- struct pci_dev *pdev = bp->pdev;
2758
+ int i;
21432759
21442760 if (!bp->rx_ring)
21452761 return;
21462762
2147
- max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2148
- max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2149
- for (i = 0; i < bp->rx_nr_rings; i++) {
2150
- struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2151
- int j;
2152
-
2153
- if (rxr->rx_tpa) {
2154
- for (j = 0; j < MAX_TPA; j++) {
2155
- struct bnxt_tpa_info *tpa_info =
2156
- &rxr->rx_tpa[j];
2157
- u8 *data = tpa_info->data;
2158
-
2159
- if (!data)
2160
- continue;
2161
-
2162
- dma_unmap_single_attrs(&pdev->dev,
2163
- tpa_info->mapping,
2164
- bp->rx_buf_use_size,
2165
- bp->rx_dir,
2166
- DMA_ATTR_WEAK_ORDERING);
2167
-
2168
- tpa_info->data = NULL;
2169
-
2170
- kfree(data);
2171
- }
2172
- }
2173
-
2174
- for (j = 0; j < max_idx; j++) {
2175
- struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
2176
- dma_addr_t mapping = rx_buf->mapping;
2177
- void *data = rx_buf->data;
2178
-
2179
- if (!data)
2180
- continue;
2181
-
2182
- rx_buf->data = NULL;
2183
-
2184
- if (BNXT_RX_PAGE_MODE(bp)) {
2185
- mapping -= bp->rx_dma_offset;
2186
- dma_unmap_page_attrs(&pdev->dev, mapping,
2187
- PAGE_SIZE, bp->rx_dir,
2188
- DMA_ATTR_WEAK_ORDERING);
2189
- __free_page(data);
2190
- } else {
2191
- dma_unmap_single_attrs(&pdev->dev, mapping,
2192
- bp->rx_buf_use_size,
2193
- bp->rx_dir,
2194
- DMA_ATTR_WEAK_ORDERING);
2195
- kfree(data);
2196
- }
2197
- }
2198
-
2199
- for (j = 0; j < max_agg_idx; j++) {
2200
- struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2201
- &rxr->rx_agg_ring[j];
2202
- struct page *page = rx_agg_buf->page;
2203
-
2204
- if (!page)
2205
- continue;
2206
-
2207
- dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2208
- BNXT_RX_PAGE_SIZE,
2209
- PCI_DMA_FROMDEVICE,
2210
- DMA_ATTR_WEAK_ORDERING);
2211
-
2212
- rx_agg_buf->page = NULL;
2213
- __clear_bit(j, rxr->rx_agg_bmap);
2214
-
2215
- __free_page(page);
2216
- }
2217
- if (rxr->rx_page) {
2218
- __free_page(rxr->rx_page);
2219
- rxr->rx_page = NULL;
2220
- }
2221
- }
2763
+ for (i = 0; i < bp->rx_nr_rings; i++)
2764
+ bnxt_free_one_rx_ring_skbs(bp, i);
22222765 }
22232766
22242767 static void bnxt_free_skbs(struct bnxt *bp)
....@@ -2227,60 +2770,138 @@
22272770 bnxt_free_rx_skbs(bp);
22282771 }
22292772
2230
-static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2773
+static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
22312774 {
22322775 struct pci_dev *pdev = bp->pdev;
22332776 int i;
22342777
2235
- for (i = 0; i < ring->nr_pages; i++) {
2236
- if (!ring->pg_arr[i])
2778
+ for (i = 0; i < rmem->nr_pages; i++) {
2779
+ if (!rmem->pg_arr[i])
22372780 continue;
22382781
2239
- dma_free_coherent(&pdev->dev, ring->page_size,
2240
- ring->pg_arr[i], ring->dma_arr[i]);
2782
+ dma_free_coherent(&pdev->dev, rmem->page_size,
2783
+ rmem->pg_arr[i], rmem->dma_arr[i]);
22412784
2242
- ring->pg_arr[i] = NULL;
2785
+ rmem->pg_arr[i] = NULL;
22432786 }
2244
- if (ring->pg_tbl) {
2245
- dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2246
- ring->pg_tbl, ring->pg_tbl_map);
2247
- ring->pg_tbl = NULL;
2787
+ if (rmem->pg_tbl) {
2788
+ size_t pg_tbl_size = rmem->nr_pages * 8;
2789
+
2790
+ if (rmem->flags & BNXT_RMEM_USE_FULL_PAGE_FLAG)
2791
+ pg_tbl_size = rmem->page_size;
2792
+ dma_free_coherent(&pdev->dev, pg_tbl_size,
2793
+ rmem->pg_tbl, rmem->pg_tbl_map);
2794
+ rmem->pg_tbl = NULL;
22482795 }
2249
- if (ring->vmem_size && *ring->vmem) {
2250
- vfree(*ring->vmem);
2251
- *ring->vmem = NULL;
2796
+ if (rmem->vmem_size && *rmem->vmem) {
2797
+ vfree(*rmem->vmem);
2798
+ *rmem->vmem = NULL;
22522799 }
22532800 }
22542801
2255
-static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2802
+static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
2803
+{
2804
+ struct pci_dev *pdev = bp->pdev;
2805
+ u64 valid_bit = 0;
2806
+ int i;
2807
+
2808
+ if (rmem->flags & (BNXT_RMEM_VALID_PTE_FLAG | BNXT_RMEM_RING_PTE_FLAG))
2809
+ valid_bit = PTU_PTE_VALID;
2810
+ if ((rmem->nr_pages > 1 || rmem->depth > 0) && !rmem->pg_tbl) {
2811
+ size_t pg_tbl_size = rmem->nr_pages * 8;
2812
+
2813
+ if (rmem->flags & BNXT_RMEM_USE_FULL_PAGE_FLAG)
2814
+ pg_tbl_size = rmem->page_size;
2815
+ rmem->pg_tbl = dma_alloc_coherent(&pdev->dev, pg_tbl_size,
2816
+ &rmem->pg_tbl_map,
2817
+ GFP_KERNEL);
2818
+ if (!rmem->pg_tbl)
2819
+ return -ENOMEM;
2820
+ }
2821
+
2822
+ for (i = 0; i < rmem->nr_pages; i++) {
2823
+ u64 extra_bits = valid_bit;
2824
+
2825
+ rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2826
+ rmem->page_size,
2827
+ &rmem->dma_arr[i],
2828
+ GFP_KERNEL);
2829
+ if (!rmem->pg_arr[i])
2830
+ return -ENOMEM;
2831
+
2832
+ if (rmem->init_val)
2833
+ memset(rmem->pg_arr[i], rmem->init_val,
2834
+ rmem->page_size);
2835
+ if (rmem->nr_pages > 1 || rmem->depth > 0) {
2836
+ if (i == rmem->nr_pages - 2 &&
2837
+ (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
2838
+ extra_bits |= PTU_PTE_NEXT_TO_LAST;
2839
+ else if (i == rmem->nr_pages - 1 &&
2840
+ (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
2841
+ extra_bits |= PTU_PTE_LAST;
2842
+ rmem->pg_tbl[i] =
2843
+ cpu_to_le64(rmem->dma_arr[i] | extra_bits);
2844
+ }
2845
+ }
2846
+
2847
+ if (rmem->vmem_size) {
2848
+ *rmem->vmem = vzalloc(rmem->vmem_size);
2849
+ if (!(*rmem->vmem))
2850
+ return -ENOMEM;
2851
+ }
2852
+ return 0;
2853
+}
2854
+
2855
+static void bnxt_free_tpa_info(struct bnxt *bp)
22562856 {
22572857 int i;
2258
- struct pci_dev *pdev = bp->pdev;
22592858
2260
- if (ring->nr_pages > 1) {
2261
- ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2262
- ring->nr_pages * 8,
2263
- &ring->pg_tbl_map,
2264
- GFP_KERNEL);
2265
- if (!ring->pg_tbl)
2266
- return -ENOMEM;
2859
+ for (i = 0; i < bp->rx_nr_rings; i++) {
2860
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2861
+
2862
+ kfree(rxr->rx_tpa_idx_map);
2863
+ rxr->rx_tpa_idx_map = NULL;
2864
+ if (rxr->rx_tpa) {
2865
+ kfree(rxr->rx_tpa[0].agg_arr);
2866
+ rxr->rx_tpa[0].agg_arr = NULL;
2867
+ }
2868
+ kfree(rxr->rx_tpa);
2869
+ rxr->rx_tpa = NULL;
2870
+ }
2871
+}
2872
+
2873
+static int bnxt_alloc_tpa_info(struct bnxt *bp)
2874
+{
2875
+ int i, j, total_aggs = 0;
2876
+
2877
+ bp->max_tpa = MAX_TPA;
2878
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
2879
+ if (!bp->max_tpa_v2)
2880
+ return 0;
2881
+ bp->max_tpa = max_t(u16, bp->max_tpa_v2, MAX_TPA_P5);
2882
+ total_aggs = bp->max_tpa * MAX_SKB_FRAGS;
22672883 }
22682884
2269
- for (i = 0; i < ring->nr_pages; i++) {
2270
- ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2271
- ring->page_size,
2272
- &ring->dma_arr[i],
2273
- GFP_KERNEL);
2274
- if (!ring->pg_arr[i])
2885
+ for (i = 0; i < bp->rx_nr_rings; i++) {
2886
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2887
+ struct rx_agg_cmp *agg;
2888
+
2889
+ rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
2890
+ GFP_KERNEL);
2891
+ if (!rxr->rx_tpa)
22752892 return -ENOMEM;
22762893
2277
- if (ring->nr_pages > 1)
2278
- ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2279
- }
2280
-
2281
- if (ring->vmem_size) {
2282
- *ring->vmem = vzalloc(ring->vmem_size);
2283
- if (!(*ring->vmem))
2894
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
2895
+ continue;
2896
+ agg = kcalloc(total_aggs, sizeof(*agg), GFP_KERNEL);
2897
+ rxr->rx_tpa[0].agg_arr = agg;
2898
+ if (!agg)
2899
+ return -ENOMEM;
2900
+ for (j = 1; j < bp->max_tpa; j++)
2901
+ rxr->rx_tpa[j].agg_arr = agg + j * MAX_SKB_FRAGS;
2902
+ rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
2903
+ GFP_KERNEL);
2904
+ if (!rxr->rx_tpa_idx_map)
22842905 return -ENOMEM;
22852906 }
22862907 return 0;
....@@ -2293,6 +2914,7 @@
22932914 if (!bp->rx_ring)
22942915 return;
22952916
2917
+ bnxt_free_tpa_info(bp);
22962918 for (i = 0; i < bp->rx_nr_rings; i++) {
22972919 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
22982920 struct bnxt_ring_struct *ring;
....@@ -2303,23 +2925,43 @@
23032925 if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
23042926 xdp_rxq_info_unreg(&rxr->xdp_rxq);
23052927
2306
- kfree(rxr->rx_tpa);
2307
- rxr->rx_tpa = NULL;
2928
+ page_pool_destroy(rxr->page_pool);
2929
+ rxr->page_pool = NULL;
23082930
23092931 kfree(rxr->rx_agg_bmap);
23102932 rxr->rx_agg_bmap = NULL;
23112933
23122934 ring = &rxr->rx_ring_struct;
2313
- bnxt_free_ring(bp, ring);
2935
+ bnxt_free_ring(bp, &ring->ring_mem);
23142936
23152937 ring = &rxr->rx_agg_ring_struct;
2316
- bnxt_free_ring(bp, ring);
2938
+ bnxt_free_ring(bp, &ring->ring_mem);
23172939 }
2940
+}
2941
+
2942
+static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
2943
+ struct bnxt_rx_ring_info *rxr)
2944
+{
2945
+ struct page_pool_params pp = { 0 };
2946
+
2947
+ pp.pool_size = bp->rx_ring_size;
2948
+ pp.nid = dev_to_node(&bp->pdev->dev);
2949
+ pp.dev = &bp->pdev->dev;
2950
+ pp.dma_dir = DMA_BIDIRECTIONAL;
2951
+
2952
+ rxr->page_pool = page_pool_create(&pp);
2953
+ if (IS_ERR(rxr->page_pool)) {
2954
+ int err = PTR_ERR(rxr->page_pool);
2955
+
2956
+ rxr->page_pool = NULL;
2957
+ return err;
2958
+ }
2959
+ return 0;
23182960 }
23192961
23202962 static int bnxt_alloc_rx_rings(struct bnxt *bp)
23212963 {
2322
- int i, rc, agg_rings = 0, tpa_rings = 0;
2964
+ int i, rc = 0, agg_rings = 0;
23232965
23242966 if (!bp->rx_ring)
23252967 return -ENOMEM;
....@@ -2327,28 +2969,38 @@
23272969 if (bp->flags & BNXT_FLAG_AGG_RINGS)
23282970 agg_rings = 1;
23292971
2330
- if (bp->flags & BNXT_FLAG_TPA)
2331
- tpa_rings = 1;
2332
-
23332972 for (i = 0; i < bp->rx_nr_rings; i++) {
23342973 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
23352974 struct bnxt_ring_struct *ring;
23362975
23372976 ring = &rxr->rx_ring_struct;
23382977
2978
+ rc = bnxt_alloc_rx_page_pool(bp, rxr);
2979
+ if (rc)
2980
+ return rc;
2981
+
23392982 rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
23402983 if (rc < 0)
23412984 return rc;
23422985
2343
- rc = bnxt_alloc_ring(bp, ring);
2986
+ rc = xdp_rxq_info_reg_mem_model(&rxr->xdp_rxq,
2987
+ MEM_TYPE_PAGE_POOL,
2988
+ rxr->page_pool);
2989
+ if (rc) {
2990
+ xdp_rxq_info_unreg(&rxr->xdp_rxq);
2991
+ return rc;
2992
+ }
2993
+
2994
+ rc = bnxt_alloc_ring(bp, &ring->ring_mem);
23442995 if (rc)
23452996 return rc;
23462997
2998
+ ring->grp_idx = i;
23472999 if (agg_rings) {
23483000 u16 mem_size;
23493001
23503002 ring = &rxr->rx_agg_ring_struct;
2351
- rc = bnxt_alloc_ring(bp, ring);
3003
+ rc = bnxt_alloc_ring(bp, &ring->ring_mem);
23523004 if (rc)
23533005 return rc;
23543006
....@@ -2358,17 +3010,11 @@
23583010 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
23593011 if (!rxr->rx_agg_bmap)
23603012 return -ENOMEM;
2361
-
2362
- if (tpa_rings) {
2363
- rxr->rx_tpa = kcalloc(MAX_TPA,
2364
- sizeof(struct bnxt_tpa_info),
2365
- GFP_KERNEL);
2366
- if (!rxr->rx_tpa)
2367
- return -ENOMEM;
2368
- }
23693013 }
23703014 }
2371
- return 0;
3015
+ if (bp->flags & BNXT_FLAG_TPA)
3016
+ rc = bnxt_alloc_tpa_info(bp);
3017
+ return rc;
23723018 }
23733019
23743020 static void bnxt_free_tx_rings(struct bnxt *bp)
....@@ -2391,7 +3037,7 @@
23913037
23923038 ring = &txr->tx_ring_struct;
23933039
2394
- bnxt_free_ring(bp, ring);
3040
+ bnxt_free_ring(bp, &ring->ring_mem);
23953041 }
23963042 }
23973043
....@@ -2422,7 +3068,7 @@
24223068
24233069 ring = &txr->tx_ring_struct;
24243070
2425
- rc = bnxt_alloc_ring(bp, ring);
3071
+ rc = bnxt_alloc_ring(bp, &ring->ring_mem);
24263072 if (rc)
24273073 return rc;
24283074
....@@ -2444,8 +3090,6 @@
24443090 mapping = txr->tx_push_mapping +
24453091 sizeof(struct tx_push_bd);
24463092 txr->data_mapping = cpu_to_le64(mapping);
2447
-
2448
- memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
24493093 }
24503094 qidx = bp->tc_to_qidx[j];
24513095 ring->queue_id = bp->q_info[qidx].queue_id;
....@@ -2468,6 +3112,7 @@
24683112 struct bnxt_napi *bnapi = bp->bnapi[i];
24693113 struct bnxt_cp_ring_info *cpr;
24703114 struct bnxt_ring_struct *ring;
3115
+ int j;
24713116
24723117 if (!bnapi)
24733118 continue;
....@@ -2475,12 +3120,51 @@
24753120 cpr = &bnapi->cp_ring;
24763121 ring = &cpr->cp_ring_struct;
24773122
2478
- bnxt_free_ring(bp, ring);
3123
+ bnxt_free_ring(bp, &ring->ring_mem);
3124
+
3125
+ for (j = 0; j < 2; j++) {
3126
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
3127
+
3128
+ if (cpr2) {
3129
+ ring = &cpr2->cp_ring_struct;
3130
+ bnxt_free_ring(bp, &ring->ring_mem);
3131
+ kfree(cpr2);
3132
+ cpr->cp_ring_arr[j] = NULL;
3133
+ }
3134
+ }
24793135 }
3136
+}
3137
+
3138
+static struct bnxt_cp_ring_info *bnxt_alloc_cp_sub_ring(struct bnxt *bp)
3139
+{
3140
+ struct bnxt_ring_mem_info *rmem;
3141
+ struct bnxt_ring_struct *ring;
3142
+ struct bnxt_cp_ring_info *cpr;
3143
+ int rc;
3144
+
3145
+ cpr = kzalloc(sizeof(*cpr), GFP_KERNEL);
3146
+ if (!cpr)
3147
+ return NULL;
3148
+
3149
+ ring = &cpr->cp_ring_struct;
3150
+ rmem = &ring->ring_mem;
3151
+ rmem->nr_pages = bp->cp_nr_pages;
3152
+ rmem->page_size = HW_CMPD_RING_SIZE;
3153
+ rmem->pg_arr = (void **)cpr->cp_desc_ring;
3154
+ rmem->dma_arr = cpr->cp_desc_mapping;
3155
+ rmem->flags = BNXT_RMEM_RING_PTE_FLAG;
3156
+ rc = bnxt_alloc_ring(bp, rmem);
3157
+ if (rc) {
3158
+ bnxt_free_ring(bp, rmem);
3159
+ kfree(cpr);
3160
+ cpr = NULL;
3161
+ }
3162
+ return cpr;
24803163 }
24813164
24823165 static int bnxt_alloc_cp_rings(struct bnxt *bp)
24833166 {
3167
+ bool sh = !!(bp->flags & BNXT_FLAG_SHARED_RINGS);
24843168 int i, rc, ulp_base_vec, ulp_msix;
24853169
24863170 ulp_msix = bnxt_get_ulp_msix_num(bp);
....@@ -2494,9 +3178,10 @@
24943178 continue;
24953179
24963180 cpr = &bnapi->cp_ring;
3181
+ cpr->bnapi = bnapi;
24973182 ring = &cpr->cp_ring_struct;
24983183
2499
- rc = bnxt_alloc_ring(bp, ring);
3184
+ rc = bnxt_alloc_ring(bp, &ring->ring_mem);
25003185 if (rc)
25013186 return rc;
25023187
....@@ -2504,6 +3189,29 @@
25043189 ring->map_idx = i + ulp_msix;
25053190 else
25063191 ring->map_idx = i;
3192
+
3193
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
3194
+ continue;
3195
+
3196
+ if (i < bp->rx_nr_rings) {
3197
+ struct bnxt_cp_ring_info *cpr2 =
3198
+ bnxt_alloc_cp_sub_ring(bp);
3199
+
3200
+ cpr->cp_ring_arr[BNXT_RX_HDL] = cpr2;
3201
+ if (!cpr2)
3202
+ return -ENOMEM;
3203
+ cpr2->bnapi = bnapi;
3204
+ }
3205
+ if ((sh && i < bp->tx_nr_rings) ||
3206
+ (!sh && i >= bp->rx_nr_rings)) {
3207
+ struct bnxt_cp_ring_info *cpr2 =
3208
+ bnxt_alloc_cp_sub_ring(bp);
3209
+
3210
+ cpr->cp_ring_arr[BNXT_TX_HDL] = cpr2;
3211
+ if (!cpr2)
3212
+ return -ENOMEM;
3213
+ cpr2->bnapi = bnapi;
3214
+ }
25073215 }
25083216 return 0;
25093217 }
....@@ -2514,6 +3222,7 @@
25143222
25153223 for (i = 0; i < bp->cp_nr_rings; i++) {
25163224 struct bnxt_napi *bnapi = bp->bnapi[i];
3225
+ struct bnxt_ring_mem_info *rmem;
25173226 struct bnxt_cp_ring_info *cpr;
25183227 struct bnxt_rx_ring_info *rxr;
25193228 struct bnxt_tx_ring_info *txr;
....@@ -2524,31 +3233,34 @@
25243233
25253234 cpr = &bnapi->cp_ring;
25263235 ring = &cpr->cp_ring_struct;
2527
- ring->nr_pages = bp->cp_nr_pages;
2528
- ring->page_size = HW_CMPD_RING_SIZE;
2529
- ring->pg_arr = (void **)cpr->cp_desc_ring;
2530
- ring->dma_arr = cpr->cp_desc_mapping;
2531
- ring->vmem_size = 0;
3236
+ rmem = &ring->ring_mem;
3237
+ rmem->nr_pages = bp->cp_nr_pages;
3238
+ rmem->page_size = HW_CMPD_RING_SIZE;
3239
+ rmem->pg_arr = (void **)cpr->cp_desc_ring;
3240
+ rmem->dma_arr = cpr->cp_desc_mapping;
3241
+ rmem->vmem_size = 0;
25323242
25333243 rxr = bnapi->rx_ring;
25343244 if (!rxr)
25353245 goto skip_rx;
25363246
25373247 ring = &rxr->rx_ring_struct;
2538
- ring->nr_pages = bp->rx_nr_pages;
2539
- ring->page_size = HW_RXBD_RING_SIZE;
2540
- ring->pg_arr = (void **)rxr->rx_desc_ring;
2541
- ring->dma_arr = rxr->rx_desc_mapping;
2542
- ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2543
- ring->vmem = (void **)&rxr->rx_buf_ring;
3248
+ rmem = &ring->ring_mem;
3249
+ rmem->nr_pages = bp->rx_nr_pages;
3250
+ rmem->page_size = HW_RXBD_RING_SIZE;
3251
+ rmem->pg_arr = (void **)rxr->rx_desc_ring;
3252
+ rmem->dma_arr = rxr->rx_desc_mapping;
3253
+ rmem->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
3254
+ rmem->vmem = (void **)&rxr->rx_buf_ring;
25443255
25453256 ring = &rxr->rx_agg_ring_struct;
2546
- ring->nr_pages = bp->rx_agg_nr_pages;
2547
- ring->page_size = HW_RXBD_RING_SIZE;
2548
- ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2549
- ring->dma_arr = rxr->rx_agg_desc_mapping;
2550
- ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2551
- ring->vmem = (void **)&rxr->rx_agg_ring;
3257
+ rmem = &ring->ring_mem;
3258
+ rmem->nr_pages = bp->rx_agg_nr_pages;
3259
+ rmem->page_size = HW_RXBD_RING_SIZE;
3260
+ rmem->pg_arr = (void **)rxr->rx_agg_desc_ring;
3261
+ rmem->dma_arr = rxr->rx_agg_desc_mapping;
3262
+ rmem->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
3263
+ rmem->vmem = (void **)&rxr->rx_agg_ring;
25523264
25533265 skip_rx:
25543266 txr = bnapi->tx_ring;
....@@ -2556,12 +3268,13 @@
25563268 continue;
25573269
25583270 ring = &txr->tx_ring_struct;
2559
- ring->nr_pages = bp->tx_nr_pages;
2560
- ring->page_size = HW_RXBD_RING_SIZE;
2561
- ring->pg_arr = (void **)txr->tx_desc_ring;
2562
- ring->dma_arr = txr->tx_desc_mapping;
2563
- ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2564
- ring->vmem = (void **)&txr->tx_buf_ring;
3271
+ rmem = &ring->ring_mem;
3272
+ rmem->nr_pages = bp->tx_nr_pages;
3273
+ rmem->page_size = HW_RXBD_RING_SIZE;
3274
+ rmem->pg_arr = (void **)txr->tx_desc_ring;
3275
+ rmem->dma_arr = txr->tx_desc_mapping;
3276
+ rmem->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
3277
+ rmem->vmem = (void **)&txr->tx_buf_ring;
25653278 }
25663279 }
25673280
....@@ -2571,8 +3284,8 @@
25713284 u32 prod;
25723285 struct rx_bd **rx_buf_ring;
25733286
2574
- rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2575
- for (i = 0, prod = 0; i < ring->nr_pages; i++) {
3287
+ rx_buf_ring = (struct rx_bd **)ring->ring_mem.pg_arr;
3288
+ for (i = 0, prod = 0; i < ring->ring_mem.nr_pages; i++) {
25763289 int j;
25773290 struct rx_bd *rxbd;
25783291
....@@ -2587,13 +3300,60 @@
25873300 }
25883301 }
25893302
3303
+static int bnxt_alloc_one_rx_ring(struct bnxt *bp, int ring_nr)
3304
+{
3305
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
3306
+ struct net_device *dev = bp->dev;
3307
+ u32 prod;
3308
+ int i;
3309
+
3310
+ prod = rxr->rx_prod;
3311
+ for (i = 0; i < bp->rx_ring_size; i++) {
3312
+ if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL)) {
3313
+ netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
3314
+ ring_nr, i, bp->rx_ring_size);
3315
+ break;
3316
+ }
3317
+ prod = NEXT_RX(prod);
3318
+ }
3319
+ rxr->rx_prod = prod;
3320
+
3321
+ if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
3322
+ return 0;
3323
+
3324
+ prod = rxr->rx_agg_prod;
3325
+ for (i = 0; i < bp->rx_agg_ring_size; i++) {
3326
+ if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL)) {
3327
+ netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
3328
+ ring_nr, i, bp->rx_ring_size);
3329
+ break;
3330
+ }
3331
+ prod = NEXT_RX_AGG(prod);
3332
+ }
3333
+ rxr->rx_agg_prod = prod;
3334
+
3335
+ if (rxr->rx_tpa) {
3336
+ dma_addr_t mapping;
3337
+ u8 *data;
3338
+
3339
+ for (i = 0; i < bp->max_tpa; i++) {
3340
+ data = __bnxt_alloc_rx_data(bp, &mapping, GFP_KERNEL);
3341
+ if (!data)
3342
+ return -ENOMEM;
3343
+
3344
+ rxr->rx_tpa[i].data = data;
3345
+ rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
3346
+ rxr->rx_tpa[i].mapping = mapping;
3347
+ }
3348
+ }
3349
+ return 0;
3350
+}
3351
+
25903352 static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
25913353 {
2592
- struct net_device *dev = bp->dev;
25933354 struct bnxt_rx_ring_info *rxr;
25943355 struct bnxt_ring_struct *ring;
2595
- u32 prod, type;
2596
- int i;
3356
+ u32 type;
25973357
25983358 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
25993359 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
....@@ -2606,75 +3366,27 @@
26063366 bnxt_init_rxbd_pages(ring, type);
26073367
26083368 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2609
- rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2610
- if (IS_ERR(rxr->xdp_prog)) {
2611
- int rc = PTR_ERR(rxr->xdp_prog);
2612
-
2613
- rxr->xdp_prog = NULL;
2614
- return rc;
2615
- }
3369
+ bpf_prog_add(bp->xdp_prog, 1);
3370
+ rxr->xdp_prog = bp->xdp_prog;
26163371 }
2617
- prod = rxr->rx_prod;
2618
- for (i = 0; i < bp->rx_ring_size; i++) {
2619
- if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2620
- netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2621
- ring_nr, i, bp->rx_ring_size);
2622
- break;
2623
- }
2624
- prod = NEXT_RX(prod);
2625
- }
2626
- rxr->rx_prod = prod;
26273372 ring->fw_ring_id = INVALID_HW_RING_ID;
26283373
26293374 ring = &rxr->rx_agg_ring_struct;
26303375 ring->fw_ring_id = INVALID_HW_RING_ID;
26313376
2632
- if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2633
- return 0;
3377
+ if ((bp->flags & BNXT_FLAG_AGG_RINGS)) {
3378
+ type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
3379
+ RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
26343380
2635
- type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
2636
- RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2637
-
2638
- bnxt_init_rxbd_pages(ring, type);
2639
-
2640
- prod = rxr->rx_agg_prod;
2641
- for (i = 0; i < bp->rx_agg_ring_size; i++) {
2642
- if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2643
- netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2644
- ring_nr, i, bp->rx_ring_size);
2645
- break;
2646
- }
2647
- prod = NEXT_RX_AGG(prod);
2648
- }
2649
- rxr->rx_agg_prod = prod;
2650
-
2651
- if (bp->flags & BNXT_FLAG_TPA) {
2652
- if (rxr->rx_tpa) {
2653
- u8 *data;
2654
- dma_addr_t mapping;
2655
-
2656
- for (i = 0; i < MAX_TPA; i++) {
2657
- data = __bnxt_alloc_rx_data(bp, &mapping,
2658
- GFP_KERNEL);
2659
- if (!data)
2660
- return -ENOMEM;
2661
-
2662
- rxr->rx_tpa[i].data = data;
2663
- rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
2664
- rxr->rx_tpa[i].mapping = mapping;
2665
- }
2666
- } else {
2667
- netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2668
- return -ENOMEM;
2669
- }
3381
+ bnxt_init_rxbd_pages(ring, type);
26703382 }
26713383
2672
- return 0;
3384
+ return bnxt_alloc_one_rx_ring(bp, ring_nr);
26733385 }
26743386
26753387 static void bnxt_init_cp_rings(struct bnxt *bp)
26763388 {
2677
- int i;
3389
+ int i, j;
26783390
26793391 for (i = 0; i < bp->cp_nr_rings; i++) {
26803392 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
....@@ -2683,6 +3395,17 @@
26833395 ring->fw_ring_id = INVALID_HW_RING_ID;
26843396 cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
26853397 cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
3398
+ for (j = 0; j < 2; j++) {
3399
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
3400
+
3401
+ if (!cpr2)
3402
+ continue;
3403
+
3404
+ ring = &cpr2->cp_ring_struct;
3405
+ ring->fw_ring_id = INVALID_HW_RING_ID;
3406
+ cpr2->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
3407
+ cpr2->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
3408
+ }
26863409 }
26873410 }
26883411
....@@ -2764,7 +3487,7 @@
27643487 int num_vnics = 1;
27653488
27663489 #ifdef CONFIG_RFS_ACCEL
2767
- if (bp->flags & BNXT_FLAG_RFS)
3490
+ if ((bp->flags & (BNXT_FLAG_RFS | BNXT_FLAG_CHIP_P5)) == BNXT_FLAG_RFS)
27683491 num_vnics += bp->rx_nr_rings;
27693492 #endif
27703493
....@@ -2786,10 +3509,12 @@
27863509
27873510 for (i = 0; i < bp->nr_vnics; i++) {
27883511 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3512
+ int j;
27893513
27903514 vnic->fw_vnic_id = INVALID_HW_RING_ID;
2791
- vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2792
- vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
3515
+ for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++)
3516
+ vnic->fw_rss_cos_lb_ctx[j] = INVALID_HW_RING_ID;
3517
+
27933518 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
27943519
27953520 if (bp->vnic_info[i].rss_hash_key) {
....@@ -2837,7 +3562,7 @@
28373562 */
28383563 void bnxt_set_ring_params(struct bnxt *bp)
28393564 {
2840
- u32 ring_size, rx_size, rx_space;
3565
+ u32 ring_size, rx_size, rx_space, max_rx_cmpl;
28413566 u32 agg_factor = 0, agg_ring_size = 0;
28423567
28433568 /* 8 for CRC and VLAN */
....@@ -2893,7 +3618,15 @@
28933618 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
28943619 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
28953620
2896
- ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
3621
+ max_rx_cmpl = bp->rx_ring_size;
3622
+ /* MAX TPA needs to be added because TPA_START completions are
3623
+ * immediately recycled, so the TPA completions are not bound by
3624
+ * the RX ring size.
3625
+ */
3626
+ if (bp->flags & BNXT_FLAG_TPA)
3627
+ max_rx_cmpl += bp->max_tpa;
3628
+ /* RX and TPA completions are 32-byte, all others are 16-byte */
3629
+ ring_size = max_rx_cmpl * 2 + agg_ring_size + bp->tx_ring_size;
28973630 bp->cp_ring_size = ring_size;
28983631
28993632 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
....@@ -2957,7 +3690,7 @@
29573690 }
29583691
29593692 if (vnic->rss_table) {
2960
- dma_free_coherent(&pdev->dev, PAGE_SIZE,
3693
+ dma_free_coherent(&pdev->dev, vnic->rss_table_size,
29613694 vnic->rss_table,
29623695 vnic->rss_table_dma_addr);
29633696 vnic->rss_table = NULL;
....@@ -3003,6 +3736,9 @@
30033736 }
30043737 }
30053738
3739
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
3740
+ goto vnic_skip_grps;
3741
+
30063742 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
30073743 max_rings = bp->rx_nr_rings;
30083744 else
....@@ -3013,21 +3749,25 @@
30133749 rc = -ENOMEM;
30143750 goto out;
30153751 }
3016
-
3752
+vnic_skip_grps:
30173753 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
30183754 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
30193755 continue;
30203756
30213757 /* Allocate rss table and hash key */
3022
- vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3758
+ size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
3759
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
3760
+ size = L1_CACHE_ALIGN(BNXT_MAX_RSS_TABLE_SIZE_P5);
3761
+
3762
+ vnic->rss_table_size = size + HW_HASH_KEY_SIZE;
3763
+ vnic->rss_table = dma_alloc_coherent(&pdev->dev,
3764
+ vnic->rss_table_size,
30233765 &vnic->rss_table_dma_addr,
30243766 GFP_KERNEL);
30253767 if (!vnic->rss_table) {
30263768 rc = -ENOMEM;
30273769 goto out;
30283770 }
3029
-
3030
- size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
30313771
30323772 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
30333773 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
....@@ -3047,6 +3787,30 @@
30473787 bp->hwrm_cmd_resp_dma_addr);
30483788 bp->hwrm_cmd_resp_addr = NULL;
30493789 }
3790
+
3791
+ if (bp->hwrm_cmd_kong_resp_addr) {
3792
+ dma_free_coherent(&pdev->dev, PAGE_SIZE,
3793
+ bp->hwrm_cmd_kong_resp_addr,
3794
+ bp->hwrm_cmd_kong_resp_dma_addr);
3795
+ bp->hwrm_cmd_kong_resp_addr = NULL;
3796
+ }
3797
+}
3798
+
3799
+static int bnxt_alloc_kong_hwrm_resources(struct bnxt *bp)
3800
+{
3801
+ struct pci_dev *pdev = bp->pdev;
3802
+
3803
+ if (bp->hwrm_cmd_kong_resp_addr)
3804
+ return 0;
3805
+
3806
+ bp->hwrm_cmd_kong_resp_addr =
3807
+ dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3808
+ &bp->hwrm_cmd_kong_resp_dma_addr,
3809
+ GFP_KERNEL);
3810
+ if (!bp->hwrm_cmd_kong_resp_addr)
3811
+ return -ENOMEM;
3812
+
3813
+ return 0;
30503814 }
30513815
30523816 static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
....@@ -3067,7 +3831,7 @@
30673831 if (bp->hwrm_short_cmd_req_addr) {
30683832 struct pci_dev *pdev = bp->pdev;
30693833
3070
- dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3834
+ dma_free_coherent(&pdev->dev, bp->hwrm_max_ext_req_len,
30713835 bp->hwrm_short_cmd_req_addr,
30723836 bp->hwrm_short_cmd_req_dma_addr);
30733837 bp->hwrm_short_cmd_req_addr = NULL;
....@@ -3078,8 +3842,11 @@
30783842 {
30793843 struct pci_dev *pdev = bp->pdev;
30803844
3845
+ if (bp->hwrm_short_cmd_req_addr)
3846
+ return 0;
3847
+
30813848 bp->hwrm_short_cmd_req_addr =
3082
- dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3849
+ dma_alloc_coherent(&pdev->dev, bp->hwrm_max_ext_req_len,
30833850 &bp->hwrm_short_cmd_req_dma_addr,
30843851 GFP_KERNEL);
30853852 if (!bp->hwrm_short_cmd_req_addr)
....@@ -3088,97 +3855,246 @@
30883855 return 0;
30893856 }
30903857
3091
-static void bnxt_free_stats(struct bnxt *bp)
3858
+static void bnxt_free_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats)
30923859 {
3093
- u32 size, i;
3094
- struct pci_dev *pdev = bp->pdev;
3860
+ kfree(stats->hw_masks);
3861
+ stats->hw_masks = NULL;
3862
+ kfree(stats->sw_stats);
3863
+ stats->sw_stats = NULL;
3864
+ if (stats->hw_stats) {
3865
+ dma_free_coherent(&bp->pdev->dev, stats->len, stats->hw_stats,
3866
+ stats->hw_stats_map);
3867
+ stats->hw_stats = NULL;
3868
+ }
3869
+}
30953870
3871
+static int bnxt_alloc_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats,
3872
+ bool alloc_masks)
3873
+{
3874
+ stats->hw_stats = dma_alloc_coherent(&bp->pdev->dev, stats->len,
3875
+ &stats->hw_stats_map, GFP_KERNEL);
3876
+ if (!stats->hw_stats)
3877
+ return -ENOMEM;
3878
+
3879
+ stats->sw_stats = kzalloc(stats->len, GFP_KERNEL);
3880
+ if (!stats->sw_stats)
3881
+ goto stats_mem_err;
3882
+
3883
+ if (alloc_masks) {
3884
+ stats->hw_masks = kzalloc(stats->len, GFP_KERNEL);
3885
+ if (!stats->hw_masks)
3886
+ goto stats_mem_err;
3887
+ }
3888
+ return 0;
3889
+
3890
+stats_mem_err:
3891
+ bnxt_free_stats_mem(bp, stats);
3892
+ return -ENOMEM;
3893
+}
3894
+
3895
+static void bnxt_fill_masks(u64 *mask_arr, u64 mask, int count)
3896
+{
3897
+ int i;
3898
+
3899
+ for (i = 0; i < count; i++)
3900
+ mask_arr[i] = mask;
3901
+}
3902
+
3903
+static void bnxt_copy_hw_masks(u64 *mask_arr, __le64 *hw_mask_arr, int count)
3904
+{
3905
+ int i;
3906
+
3907
+ for (i = 0; i < count; i++)
3908
+ mask_arr[i] = le64_to_cpu(hw_mask_arr[i]);
3909
+}
3910
+
3911
+static int bnxt_hwrm_func_qstat_ext(struct bnxt *bp,
3912
+ struct bnxt_stats_mem *stats)
3913
+{
3914
+ struct hwrm_func_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
3915
+ struct hwrm_func_qstats_ext_input req = {0};
3916
+ __le64 *hw_masks;
3917
+ int rc;
3918
+
3919
+ if (!(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED) ||
3920
+ !(bp->flags & BNXT_FLAG_CHIP_P5))
3921
+ return -EOPNOTSUPP;
3922
+
3923
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QSTATS_EXT, -1, -1);
3924
+ req.fid = cpu_to_le16(0xffff);
3925
+ req.flags = FUNC_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK;
3926
+ mutex_lock(&bp->hwrm_cmd_lock);
3927
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3928
+ if (rc)
3929
+ goto qstat_exit;
3930
+
3931
+ hw_masks = &resp->rx_ucast_pkts;
3932
+ bnxt_copy_hw_masks(stats->hw_masks, hw_masks, stats->len / 8);
3933
+
3934
+qstat_exit:
3935
+ mutex_unlock(&bp->hwrm_cmd_lock);
3936
+ return rc;
3937
+}
3938
+
3939
+static int bnxt_hwrm_port_qstats(struct bnxt *bp, u8 flags);
3940
+static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp, u8 flags);
3941
+
3942
+static void bnxt_init_stats(struct bnxt *bp)
3943
+{
3944
+ struct bnxt_napi *bnapi = bp->bnapi[0];
3945
+ struct bnxt_cp_ring_info *cpr;
3946
+ struct bnxt_stats_mem *stats;
3947
+ __le64 *rx_stats, *tx_stats;
3948
+ int rc, rx_count, tx_count;
3949
+ u64 *rx_masks, *tx_masks;
3950
+ u64 mask;
3951
+ u8 flags;
3952
+
3953
+ cpr = &bnapi->cp_ring;
3954
+ stats = &cpr->stats;
3955
+ rc = bnxt_hwrm_func_qstat_ext(bp, stats);
3956
+ if (rc) {
3957
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
3958
+ mask = (1ULL << 48) - 1;
3959
+ else
3960
+ mask = -1ULL;
3961
+ bnxt_fill_masks(stats->hw_masks, mask, stats->len / 8);
3962
+ }
3963
+ if (bp->flags & BNXT_FLAG_PORT_STATS) {
3964
+ stats = &bp->port_stats;
3965
+ rx_stats = stats->hw_stats;
3966
+ rx_masks = stats->hw_masks;
3967
+ rx_count = sizeof(struct rx_port_stats) / 8;
3968
+ tx_stats = rx_stats + BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
3969
+ tx_masks = rx_masks + BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
3970
+ tx_count = sizeof(struct tx_port_stats) / 8;
3971
+
3972
+ flags = PORT_QSTATS_REQ_FLAGS_COUNTER_MASK;
3973
+ rc = bnxt_hwrm_port_qstats(bp, flags);
3974
+ if (rc) {
3975
+ mask = (1ULL << 40) - 1;
3976
+
3977
+ bnxt_fill_masks(rx_masks, mask, rx_count);
3978
+ bnxt_fill_masks(tx_masks, mask, tx_count);
3979
+ } else {
3980
+ bnxt_copy_hw_masks(rx_masks, rx_stats, rx_count);
3981
+ bnxt_copy_hw_masks(tx_masks, tx_stats, tx_count);
3982
+ bnxt_hwrm_port_qstats(bp, 0);
3983
+ }
3984
+ }
3985
+ if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
3986
+ stats = &bp->rx_port_stats_ext;
3987
+ rx_stats = stats->hw_stats;
3988
+ rx_masks = stats->hw_masks;
3989
+ rx_count = sizeof(struct rx_port_stats_ext) / 8;
3990
+ stats = &bp->tx_port_stats_ext;
3991
+ tx_stats = stats->hw_stats;
3992
+ tx_masks = stats->hw_masks;
3993
+ tx_count = sizeof(struct tx_port_stats_ext) / 8;
3994
+
3995
+ flags = PORT_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK;
3996
+ rc = bnxt_hwrm_port_qstats_ext(bp, flags);
3997
+ if (rc) {
3998
+ mask = (1ULL << 40) - 1;
3999
+
4000
+ bnxt_fill_masks(rx_masks, mask, rx_count);
4001
+ if (tx_stats)
4002
+ bnxt_fill_masks(tx_masks, mask, tx_count);
4003
+ } else {
4004
+ bnxt_copy_hw_masks(rx_masks, rx_stats, rx_count);
4005
+ if (tx_stats)
4006
+ bnxt_copy_hw_masks(tx_masks, tx_stats,
4007
+ tx_count);
4008
+ bnxt_hwrm_port_qstats_ext(bp, 0);
4009
+ }
4010
+ }
4011
+}
4012
+
4013
+static void bnxt_free_port_stats(struct bnxt *bp)
4014
+{
30964015 bp->flags &= ~BNXT_FLAG_PORT_STATS;
30974016 bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
30984017
3099
- if (bp->hw_rx_port_stats) {
3100
- dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
3101
- bp->hw_rx_port_stats,
3102
- bp->hw_rx_port_stats_map);
3103
- bp->hw_rx_port_stats = NULL;
3104
- }
4018
+ bnxt_free_stats_mem(bp, &bp->port_stats);
4019
+ bnxt_free_stats_mem(bp, &bp->rx_port_stats_ext);
4020
+ bnxt_free_stats_mem(bp, &bp->tx_port_stats_ext);
4021
+}
31054022
3106
- if (bp->hw_rx_port_stats_ext) {
3107
- dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext),
3108
- bp->hw_rx_port_stats_ext,
3109
- bp->hw_rx_port_stats_ext_map);
3110
- bp->hw_rx_port_stats_ext = NULL;
3111
- }
4023
+static void bnxt_free_ring_stats(struct bnxt *bp)
4024
+{
4025
+ int i;
31124026
31134027 if (!bp->bnapi)
31144028 return;
3115
-
3116
- size = sizeof(struct ctx_hw_stats);
31174029
31184030 for (i = 0; i < bp->cp_nr_rings; i++) {
31194031 struct bnxt_napi *bnapi = bp->bnapi[i];
31204032 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
31214033
3122
- if (cpr->hw_stats) {
3123
- dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
3124
- cpr->hw_stats_map);
3125
- cpr->hw_stats = NULL;
3126
- }
4034
+ bnxt_free_stats_mem(bp, &cpr->stats);
31274035 }
31284036 }
31294037
31304038 static int bnxt_alloc_stats(struct bnxt *bp)
31314039 {
31324040 u32 size, i;
3133
- struct pci_dev *pdev = bp->pdev;
4041
+ int rc;
31344042
3135
- size = sizeof(struct ctx_hw_stats);
4043
+ size = bp->hw_ring_stats_size;
31364044
31374045 for (i = 0; i < bp->cp_nr_rings; i++) {
31384046 struct bnxt_napi *bnapi = bp->bnapi[i];
31394047 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
31404048
3141
- cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
3142
- &cpr->hw_stats_map,
3143
- GFP_KERNEL);
3144
- if (!cpr->hw_stats)
3145
- return -ENOMEM;
4049
+ cpr->stats.len = size;
4050
+ rc = bnxt_alloc_stats_mem(bp, &cpr->stats, !i);
4051
+ if (rc)
4052
+ return rc;
31464053
31474054 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
31484055 }
31494056
3150
- if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
3151
- bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
3152
- sizeof(struct tx_port_stats) + 1024;
4057
+ if (BNXT_VF(bp) || bp->chip_num == CHIP_NUM_58700)
4058
+ return 0;
31534059
3154
- bp->hw_rx_port_stats =
3155
- dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
3156
- &bp->hw_rx_port_stats_map,
3157
- GFP_KERNEL);
3158
- if (!bp->hw_rx_port_stats)
3159
- return -ENOMEM;
4060
+ if (bp->port_stats.hw_stats)
4061
+ goto alloc_ext_stats;
31604062
3161
- bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3162
- 512;
3163
- bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3164
- sizeof(struct rx_port_stats) + 512;
3165
- bp->flags |= BNXT_FLAG_PORT_STATS;
4063
+ bp->port_stats.len = BNXT_PORT_STATS_SIZE;
4064
+ rc = bnxt_alloc_stats_mem(bp, &bp->port_stats, true);
4065
+ if (rc)
4066
+ return rc;
31664067
3167
- /* Display extended statistics only if FW supports it */
3168
- if (bp->hwrm_spec_code < 0x10804 ||
3169
- bp->hwrm_spec_code == 0x10900)
4068
+ bp->flags |= BNXT_FLAG_PORT_STATS;
4069
+
4070
+alloc_ext_stats:
4071
+ /* Display extended statistics only if FW supports it */
4072
+ if (bp->hwrm_spec_code < 0x10804 || bp->hwrm_spec_code == 0x10900)
4073
+ if (!(bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED))
31704074 return 0;
31714075
3172
- bp->hw_rx_port_stats_ext =
3173
- dma_zalloc_coherent(&pdev->dev,
3174
- sizeof(struct rx_port_stats_ext),
3175
- &bp->hw_rx_port_stats_ext_map,
3176
- GFP_KERNEL);
3177
- if (!bp->hw_rx_port_stats_ext)
3178
- return 0;
4076
+ if (bp->rx_port_stats_ext.hw_stats)
4077
+ goto alloc_tx_ext_stats;
31794078
3180
- bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
4079
+ bp->rx_port_stats_ext.len = sizeof(struct rx_port_stats_ext);
4080
+ rc = bnxt_alloc_stats_mem(bp, &bp->rx_port_stats_ext, true);
4081
+ /* Extended stats are optional */
4082
+ if (rc)
4083
+ return 0;
4084
+
4085
+alloc_tx_ext_stats:
4086
+ if (bp->tx_port_stats_ext.hw_stats)
4087
+ return 0;
4088
+
4089
+ if (bp->hwrm_spec_code >= 0x10902 ||
4090
+ (bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED)) {
4091
+ bp->tx_port_stats_ext.len = sizeof(struct tx_port_stats_ext);
4092
+ rc = bnxt_alloc_stats_mem(bp, &bp->tx_port_stats_ext, true);
4093
+ /* Extended stats are optional */
4094
+ if (rc)
4095
+ return 0;
31814096 }
4097
+ bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
31824098 return 0;
31834099 }
31844100
....@@ -3277,7 +4193,10 @@
32774193 bnxt_free_cp_rings(bp);
32784194 bnxt_free_ntp_fltrs(bp, irq_re_init);
32794195 if (irq_re_init) {
3280
- bnxt_free_stats(bp);
4196
+ bnxt_free_ring_stats(bp);
4197
+ if (!(bp->fw_cap & BNXT_FW_CAP_PORT_STATS_NO_RESET) ||
4198
+ test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
4199
+ bnxt_free_port_stats(bp);
32814200 bnxt_free_ring_grps(bp);
32824201 bnxt_free_vnics(bp);
32834202 kfree(bp->tx_ring_map);
....@@ -3315,6 +4234,13 @@
33154234 bp->bnapi[i] = bnapi;
33164235 bp->bnapi[i]->index = i;
33174236 bp->bnapi[i]->bp = bp;
4237
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
4238
+ struct bnxt_cp_ring_info *cpr =
4239
+ &bp->bnapi[i]->cp_ring;
4240
+
4241
+ cpr->cp_ring_struct.ring_mem.flags =
4242
+ BNXT_RMEM_RING_PTE_FLAG;
4243
+ }
33184244 }
33194245
33204246 bp->rx_ring = kcalloc(bp->rx_nr_rings,
....@@ -3324,7 +4250,15 @@
33244250 return -ENOMEM;
33254251
33264252 for (i = 0; i < bp->rx_nr_rings; i++) {
3327
- bp->rx_ring[i].bnapi = bp->bnapi[i];
4253
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4254
+
4255
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
4256
+ rxr->rx_ring_struct.ring_mem.flags =
4257
+ BNXT_RMEM_RING_PTE_FLAG;
4258
+ rxr->rx_agg_ring_struct.ring_mem.flags =
4259
+ BNXT_RMEM_RING_PTE_FLAG;
4260
+ }
4261
+ rxr->bnapi = bp->bnapi[i];
33284262 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
33294263 }
33304264
....@@ -3346,12 +4280,16 @@
33464280 j = bp->rx_nr_rings;
33474281
33484282 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3349
- bp->tx_ring[i].bnapi = bp->bnapi[j];
3350
- bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
4283
+ struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4284
+
4285
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
4286
+ txr->tx_ring_struct.ring_mem.flags =
4287
+ BNXT_RMEM_RING_PTE_FLAG;
4288
+ txr->bnapi = bp->bnapi[j];
4289
+ bp->bnapi[j]->tx_ring = txr;
33514290 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
33524291 if (i >= bp->tx_nr_rings_xdp) {
3353
- bp->tx_ring[i].txq_index = i -
3354
- bp->tx_nr_rings_xdp;
4292
+ txr->txq_index = i - bp->tx_nr_rings_xdp;
33554293 bp->bnapi[j]->tx_int = bnxt_tx_int;
33564294 } else {
33574295 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
....@@ -3362,6 +4300,7 @@
33624300 rc = bnxt_alloc_stats(bp);
33634301 if (rc)
33644302 goto alloc_mem_err;
4303
+ bnxt_init_stats(bp);
33654304
33664305 rc = bnxt_alloc_ntp_fltrs(bp);
33674306 if (rc)
....@@ -3411,7 +4350,7 @@
34114350 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
34124351
34134352 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3414
- BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4353
+ bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons);
34154354 }
34164355 }
34174356
....@@ -3447,7 +4386,7 @@
34474386 struct bnxt_napi *bnapi = bp->bnapi[i];
34484387 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
34494388
3450
- BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
4389
+ bnxt_db_nq_arm(bp, &cpr->cp_db, cpr->cp_raw_cons);
34514390 }
34524391 }
34534392
....@@ -3459,7 +4398,39 @@
34594398 req->req_type = cpu_to_le16(req_type);
34604399 req->cmpl_ring = cpu_to_le16(cmpl_ring);
34614400 req->target_id = cpu_to_le16(target_id);
3462
- req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
4401
+ if (bnxt_kong_hwrm_message(bp, req))
4402
+ req->resp_addr = cpu_to_le64(bp->hwrm_cmd_kong_resp_dma_addr);
4403
+ else
4404
+ req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
4405
+}
4406
+
4407
+static int bnxt_hwrm_to_stderr(u32 hwrm_err)
4408
+{
4409
+ switch (hwrm_err) {
4410
+ case HWRM_ERR_CODE_SUCCESS:
4411
+ return 0;
4412
+ case HWRM_ERR_CODE_RESOURCE_LOCKED:
4413
+ return -EROFS;
4414
+ case HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED:
4415
+ return -EACCES;
4416
+ case HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR:
4417
+ return -ENOSPC;
4418
+ case HWRM_ERR_CODE_INVALID_PARAMS:
4419
+ case HWRM_ERR_CODE_INVALID_FLAGS:
4420
+ case HWRM_ERR_CODE_INVALID_ENABLES:
4421
+ case HWRM_ERR_CODE_UNSUPPORTED_TLV:
4422
+ case HWRM_ERR_CODE_UNSUPPORTED_OPTION_ERR:
4423
+ return -EINVAL;
4424
+ case HWRM_ERR_CODE_NO_BUFFER:
4425
+ return -ENOMEM;
4426
+ case HWRM_ERR_CODE_HOT_RESET_PROGRESS:
4427
+ case HWRM_ERR_CODE_BUSY:
4428
+ return -EAGAIN;
4429
+ case HWRM_ERR_CODE_CMD_NOT_SUPPORTED:
4430
+ return -EOPNOTSUPP;
4431
+ default:
4432
+ return -EIO;
4433
+ }
34634434 }
34644435
34654436 static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
....@@ -3468,24 +4439,56 @@
34684439 int i, intr_process, rc, tmo_count;
34694440 struct input *req = msg;
34704441 u32 *data = msg;
3471
- __le32 *resp_len;
34724442 u8 *valid;
34734443 u16 cp_ring_id, len = 0;
34744444 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
34754445 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
34764446 struct hwrm_short_input short_input = {0};
4447
+ u32 doorbell_offset = BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER;
4448
+ u32 bar_offset = BNXT_GRCPF_REG_CHIMP_COMM;
4449
+ u16 dst = BNXT_HWRM_CHNL_CHIMP;
34774450
3478
- req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
4451
+ if (BNXT_NO_FW_ACCESS(bp) &&
4452
+ le16_to_cpu(req->req_type) != HWRM_FUNC_RESET)
4453
+ return -EBUSY;
4454
+
4455
+ if (msg_len > BNXT_HWRM_MAX_REQ_LEN) {
4456
+ if (msg_len > bp->hwrm_max_ext_req_len ||
4457
+ !bp->hwrm_short_cmd_req_addr)
4458
+ return -EINVAL;
4459
+ }
4460
+
4461
+ if (bnxt_hwrm_kong_chnl(bp, req)) {
4462
+ dst = BNXT_HWRM_CHNL_KONG;
4463
+ bar_offset = BNXT_GRCPF_REG_KONG_COMM;
4464
+ doorbell_offset = BNXT_GRCPF_REG_KONG_COMM_TRIGGER;
4465
+ resp = bp->hwrm_cmd_kong_resp_addr;
4466
+ }
4467
+
34794468 memset(resp, 0, PAGE_SIZE);
34804469 cp_ring_id = le16_to_cpu(req->cmpl_ring);
34814470 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
34824471
3483
- if (bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) {
4472
+ req->seq_id = cpu_to_le16(bnxt_get_hwrm_seq_id(bp, dst));
4473
+ /* currently supports only one outstanding message */
4474
+ if (intr_process)
4475
+ bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
4476
+
4477
+ if ((bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) ||
4478
+ msg_len > BNXT_HWRM_MAX_REQ_LEN) {
34844479 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
4480
+ u16 max_msg_len;
4481
+
4482
+ /* Set boundary for maximum extended request length for short
4483
+ * cmd format. If passed up from device use the max supported
4484
+ * internal req length.
4485
+ */
4486
+ max_msg_len = bp->hwrm_max_ext_req_len;
34854487
34864488 memcpy(short_cmd_req, req, msg_len);
3487
- memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3488
- msg_len);
4489
+ if (msg_len < max_msg_len)
4490
+ memset(short_cmd_req + msg_len, 0,
4491
+ max_msg_len - msg_len);
34894492
34904493 short_input.req_type = req->req_type;
34914494 short_input.signature =
....@@ -3504,17 +4507,16 @@
35044507 }
35054508
35064509 /* Write request msg to hwrm channel */
3507
- __iowrite32_copy(bp->bar0, data, msg_len / 4);
4510
+ __iowrite32_copy(bp->bar0 + bar_offset, data, msg_len / 4);
35084511
35094512 for (i = msg_len; i < max_req_len; i += 4)
3510
- writel(0, bp->bar0 + i);
3511
-
3512
- /* currently supports only one outstanding message */
3513
- if (intr_process)
3514
- bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
4513
+ writel(0, bp->bar0 + bar_offset + i);
35154514
35164515 /* Ring channel doorbell */
3517
- writel(1, bp->bar0 + 0x100);
4516
+ writel(1, bp->bar0 + doorbell_offset);
4517
+
4518
+ if (!pci_is_enabled(bp->pdev))
4519
+ return 0;
35184520
35194521 if (!timeout)
35204522 timeout = DFLT_HWRM_CMD_TIMEOUT;
....@@ -3529,11 +4531,18 @@
35294531 tmo_count = HWRM_SHORT_TIMEOUT_COUNTER;
35304532 timeout = timeout - HWRM_SHORT_MIN_TIMEOUT * HWRM_SHORT_TIMEOUT_COUNTER;
35314533 tmo_count += DIV_ROUND_UP(timeout, HWRM_MIN_TIMEOUT);
3532
- resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
4534
+
35334535 if (intr_process) {
4536
+ u16 seq_id = bp->hwrm_intr_seq_id;
4537
+
35344538 /* Wait until hwrm response cmpl interrupt is processed */
3535
- while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
4539
+ while (bp->hwrm_intr_seq_id != (u16)~seq_id &&
35364540 i++ < tmo_count) {
4541
+ /* Abort the wait for completion if the FW health
4542
+ * check has failed.
4543
+ */
4544
+ if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
4545
+ return -EBUSY;
35374546 /* on first few passes, just barely sleep */
35384547 if (i < HWRM_SHORT_TIMEOUT_COUNTER)
35394548 usleep_range(HWRM_SHORT_MIN_TIMEOUT,
....@@ -3543,21 +4552,25 @@
35434552 HWRM_MAX_TIMEOUT);
35444553 }
35454554
3546
- if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3547
- netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
3548
- le16_to_cpu(req->req_type));
3549
- return -1;
4555
+ if (bp->hwrm_intr_seq_id != (u16)~seq_id) {
4556
+ if (!silent)
4557
+ netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
4558
+ le16_to_cpu(req->req_type));
4559
+ return -EBUSY;
35504560 }
3551
- len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3552
- HWRM_RESP_LEN_SFT;
3553
- valid = bp->hwrm_cmd_resp_addr + len - 1;
4561
+ len = le16_to_cpu(resp->resp_len);
4562
+ valid = ((u8 *)resp) + len - 1;
35544563 } else {
35554564 int j;
35564565
35574566 /* Check if response len is updated */
35584567 for (i = 0; i < tmo_count; i++) {
3559
- len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3560
- HWRM_RESP_LEN_SFT;
4568
+ /* Abort the wait for completion if the FW health
4569
+ * check has failed.
4570
+ */
4571
+ if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
4572
+ return -EBUSY;
4573
+ len = le16_to_cpu(resp->resp_len);
35614574 if (len)
35624575 break;
35634576 /* on first few passes, just barely sleep */
....@@ -3570,15 +4583,16 @@
35704583 }
35714584
35724585 if (i >= tmo_count) {
3573
- netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
3574
- HWRM_TOTAL_TIMEOUT(i),
3575
- le16_to_cpu(req->req_type),
3576
- le16_to_cpu(req->seq_id), len);
3577
- return -1;
4586
+ if (!silent)
4587
+ netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
4588
+ HWRM_TOTAL_TIMEOUT(i),
4589
+ le16_to_cpu(req->req_type),
4590
+ le16_to_cpu(req->seq_id), len);
4591
+ return -EBUSY;
35784592 }
35794593
35804594 /* Last byte of resp contains valid bit */
3581
- valid = bp->hwrm_cmd_resp_addr + len - 1;
4595
+ valid = ((u8 *)resp) + len - 1;
35824596 for (j = 0; j < HWRM_VALID_BIT_DELAY_USEC; j++) {
35834597 /* make sure we read from updated DMA memory */
35844598 dma_rmb();
....@@ -3588,11 +4602,13 @@
35884602 }
35894603
35904604 if (j >= HWRM_VALID_BIT_DELAY_USEC) {
3591
- netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
3592
- HWRM_TOTAL_TIMEOUT(i),
3593
- le16_to_cpu(req->req_type),
3594
- le16_to_cpu(req->seq_id), len, *valid);
3595
- return -1;
4605
+ if (!silent)
4606
+ netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
4607
+ HWRM_TOTAL_TIMEOUT(i),
4608
+ le16_to_cpu(req->req_type),
4609
+ le16_to_cpu(req->seq_id), len,
4610
+ *valid);
4611
+ return -EBUSY;
35964612 }
35974613 }
35984614
....@@ -3606,7 +4622,7 @@
36064622 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
36074623 le16_to_cpu(resp->req_type),
36084624 le16_to_cpu(resp->seq_id), rc);
3609
- return rc;
4625
+ return bnxt_hwrm_to_stderr(rc);
36104626 }
36114627
36124628 int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
....@@ -3641,50 +4657,31 @@
36414657 return rc;
36424658 }
36434659
3644
-int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3645
- int bmap_size)
3646
-{
3647
- struct hwrm_func_drv_rgtr_input req = {0};
3648
- DECLARE_BITMAP(async_events_bmap, 256);
3649
- u32 *events = (u32 *)async_events_bmap;
3650
- int i;
3651
-
3652
- bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3653
-
3654
- req.enables =
3655
- cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
3656
-
3657
- memset(async_events_bmap, 0, sizeof(async_events_bmap));
3658
- for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3659
- __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3660
-
3661
- if (bmap && bmap_size) {
3662
- for (i = 0; i < bmap_size; i++) {
3663
- if (test_bit(i, bmap))
3664
- __set_bit(i, async_events_bmap);
3665
- }
3666
- }
3667
-
3668
- for (i = 0; i < 8; i++)
3669
- req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3670
-
3671
- return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3672
-}
3673
-
3674
-static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
4660
+int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp, unsigned long *bmap, int bmap_size,
4661
+ bool async_only)
36754662 {
36764663 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
36774664 struct hwrm_func_drv_rgtr_input req = {0};
3678
- int rc;
4665
+ DECLARE_BITMAP(async_events_bmap, 256);
4666
+ u32 *events = (u32 *)async_events_bmap;
4667
+ u32 flags;
4668
+ int rc, i;
36794669
36804670 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
36814671
36824672 req.enables =
36834673 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3684
- FUNC_DRV_RGTR_REQ_ENABLES_VER);
4674
+ FUNC_DRV_RGTR_REQ_ENABLES_VER |
4675
+ FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
36854676
36864677 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
3687
- req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE);
4678
+ flags = FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE;
4679
+ if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
4680
+ flags |= FUNC_DRV_RGTR_REQ_FLAGS_HOT_RESET_SUPPORT;
4681
+ if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
4682
+ flags |= FUNC_DRV_RGTR_REQ_FLAGS_ERROR_RECOVERY_SUPPORT |
4683
+ FUNC_DRV_RGTR_REQ_FLAGS_MASTER_SUPPORT;
4684
+ req.flags = cpu_to_le32(flags);
36884685 req.ver_maj_8b = DRV_VER_MAJ;
36894686 req.ver_min_8b = DRV_VER_MIN;
36904687 req.ver_upd_8b = DRV_VER_UPD;
....@@ -3713,13 +4710,40 @@
37134710 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
37144711 }
37154712
4713
+ if (bp->fw_cap & BNXT_FW_CAP_OVS_64BIT_HANDLE)
4714
+ req.flags |= cpu_to_le32(
4715
+ FUNC_DRV_RGTR_REQ_FLAGS_FLOW_HANDLE_64BIT_MODE);
4716
+
4717
+ memset(async_events_bmap, 0, sizeof(async_events_bmap));
4718
+ for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) {
4719
+ u16 event_id = bnxt_async_events_arr[i];
4720
+
4721
+ if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY &&
4722
+ !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
4723
+ continue;
4724
+ __set_bit(bnxt_async_events_arr[i], async_events_bmap);
4725
+ }
4726
+ if (bmap && bmap_size) {
4727
+ for (i = 0; i < bmap_size; i++) {
4728
+ if (test_bit(i, bmap))
4729
+ __set_bit(i, async_events_bmap);
4730
+ }
4731
+ }
4732
+ for (i = 0; i < 8; i++)
4733
+ req.async_event_fwd[i] |= cpu_to_le32(events[i]);
4734
+
4735
+ if (async_only)
4736
+ req.enables =
4737
+ cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
4738
+
37164739 mutex_lock(&bp->hwrm_cmd_lock);
37174740 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3718
- if (rc)
3719
- rc = -EIO;
3720
- else if (resp->flags &
3721
- cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED))
3722
- bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
4741
+ if (!rc) {
4742
+ set_bit(BNXT_STATE_DRV_REGISTERED, &bp->state);
4743
+ if (resp->flags &
4744
+ cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED))
4745
+ bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
4746
+ }
37234747 mutex_unlock(&bp->hwrm_cmd_lock);
37244748 return rc;
37254749 }
....@@ -3727,6 +4751,9 @@
37274751 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
37284752 {
37294753 struct hwrm_func_drv_unrgtr_input req = {0};
4754
+
4755
+ if (!test_and_clear_bit(BNXT_STATE_DRV_REGISTERED, &bp->state))
4756
+ return 0;
37304757
37314758 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
37324759 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
....@@ -3742,10 +4769,12 @@
37424769
37434770 switch (tunnel_type) {
37444771 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3745
- req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
4772
+ req.tunnel_dst_port_id = cpu_to_le16(bp->vxlan_fw_dst_port_id);
4773
+ bp->vxlan_fw_dst_port_id = INVALID_HW_RING_ID;
37464774 break;
37474775 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3748
- req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
4776
+ req.tunnel_dst_port_id = cpu_to_le16(bp->nge_fw_dst_port_id);
4777
+ bp->nge_fw_dst_port_id = INVALID_HW_RING_ID;
37494778 break;
37504779 default:
37514780 break;
....@@ -3780,10 +4809,11 @@
37804809
37814810 switch (tunnel_type) {
37824811 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
3783
- bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
4812
+ bp->vxlan_fw_dst_port_id =
4813
+ le16_to_cpu(resp->tunnel_dst_port_id);
37844814 break;
37854815 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
3786
- bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
4816
+ bp->nge_fw_dst_port_id = le16_to_cpu(resp->tunnel_dst_port_id);
37874817 break;
37884818 default:
37894819 break;
....@@ -3841,16 +4871,24 @@
38414871 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
38424872 struct bnxt_ntuple_filter *fltr)
38434873 {
3844
- int rc = 0;
38454874 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3846
- struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3847
- bp->hwrm_cmd_resp_addr;
4875
+ struct hwrm_cfa_ntuple_filter_alloc_output *resp;
38484876 struct flow_keys *keys = &fltr->fkeys;
3849
- struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
4877
+ struct bnxt_vnic_info *vnic;
4878
+ u32 flags = 0;
4879
+ int rc = 0;
38504880
38514881 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
38524882 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
38534883
4884
+ if (bp->fw_cap & BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2) {
4885
+ flags = CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DEST_RFS_RING_IDX;
4886
+ req.dst_id = cpu_to_le16(fltr->rxq);
4887
+ } else {
4888
+ vnic = &bp->vnic_info[fltr->rxq + 1];
4889
+ req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
4890
+ }
4891
+ req.flags = cpu_to_le32(flags);
38544892 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
38554893
38564894 req.ethertype = htons(ETH_P_IP);
....@@ -3889,11 +4927,12 @@
38894927 req.dst_port = keys->ports.dst;
38904928 req.dst_port_mask = cpu_to_be16(0xffff);
38914929
3892
- req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
38934930 mutex_lock(&bp->hwrm_cmd_lock);
38944931 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3895
- if (!rc)
4932
+ if (!rc) {
4933
+ resp = bnxt_get_hwrm_resp_addr(bp, &req);
38964934 fltr->filter_id = resp->ntuple_filter_id;
4935
+ }
38974936 mutex_unlock(&bp->hwrm_cmd_lock);
38984937 return rc;
38994938 }
....@@ -3964,6 +5003,7 @@
39645003 static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
39655004 {
39665005 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
5006
+ u16 max_aggs = VNIC_TPA_CFG_REQ_MAX_AGGS_MAX;
39675007 struct hwrm_vnic_tpa_cfg_input req = {0};
39685008
39695009 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
....@@ -4003,9 +5043,14 @@
40035043 nsegs = (MAX_SKB_FRAGS - n) / n;
40045044 }
40055045
4006
- segs = ilog2(nsegs);
5046
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5047
+ segs = MAX_TPA_SEGS_P5;
5048
+ max_aggs = bp->max_tpa;
5049
+ } else {
5050
+ segs = ilog2(nsegs);
5051
+ }
40075052 req.max_agg_segs = cpu_to_le16(segs);
4008
- req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
5053
+ req.max_aggs = cpu_to_le16(max_aggs);
40095054
40105055 req.min_agg_len = cpu_to_le32(512);
40115056 }
....@@ -4014,41 +5059,196 @@
40145059 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
40155060 }
40165061
5062
+static u16 bnxt_cp_ring_from_grp(struct bnxt *bp, struct bnxt_ring_struct *ring)
5063
+{
5064
+ struct bnxt_ring_grp_info *grp_info;
5065
+
5066
+ grp_info = &bp->grp_info[ring->grp_idx];
5067
+ return grp_info->cp_fw_ring_id;
5068
+}
5069
+
5070
+static u16 bnxt_cp_ring_for_rx(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
5071
+{
5072
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5073
+ struct bnxt_napi *bnapi = rxr->bnapi;
5074
+ struct bnxt_cp_ring_info *cpr;
5075
+
5076
+ cpr = bnapi->cp_ring.cp_ring_arr[BNXT_RX_HDL];
5077
+ return cpr->cp_ring_struct.fw_ring_id;
5078
+ } else {
5079
+ return bnxt_cp_ring_from_grp(bp, &rxr->rx_ring_struct);
5080
+ }
5081
+}
5082
+
5083
+static u16 bnxt_cp_ring_for_tx(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
5084
+{
5085
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5086
+ struct bnxt_napi *bnapi = txr->bnapi;
5087
+ struct bnxt_cp_ring_info *cpr;
5088
+
5089
+ cpr = bnapi->cp_ring.cp_ring_arr[BNXT_TX_HDL];
5090
+ return cpr->cp_ring_struct.fw_ring_id;
5091
+ } else {
5092
+ return bnxt_cp_ring_from_grp(bp, &txr->tx_ring_struct);
5093
+ }
5094
+}
5095
+
5096
+static int bnxt_alloc_rss_indir_tbl(struct bnxt *bp)
5097
+{
5098
+ int entries;
5099
+
5100
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5101
+ entries = BNXT_MAX_RSS_TABLE_ENTRIES_P5;
5102
+ else
5103
+ entries = HW_HASH_INDEX_SIZE;
5104
+
5105
+ bp->rss_indir_tbl_entries = entries;
5106
+ bp->rss_indir_tbl = kmalloc_array(entries, sizeof(*bp->rss_indir_tbl),
5107
+ GFP_KERNEL);
5108
+ if (!bp->rss_indir_tbl)
5109
+ return -ENOMEM;
5110
+ return 0;
5111
+}
5112
+
5113
+static void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp)
5114
+{
5115
+ u16 max_rings, max_entries, pad, i;
5116
+
5117
+ if (!bp->rx_nr_rings)
5118
+ return;
5119
+
5120
+ if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5121
+ max_rings = bp->rx_nr_rings - 1;
5122
+ else
5123
+ max_rings = bp->rx_nr_rings;
5124
+
5125
+ max_entries = bnxt_get_rxfh_indir_size(bp->dev);
5126
+
5127
+ for (i = 0; i < max_entries; i++)
5128
+ bp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, max_rings);
5129
+
5130
+ pad = bp->rss_indir_tbl_entries - max_entries;
5131
+ if (pad)
5132
+ memset(&bp->rss_indir_tbl[i], 0, pad * sizeof(u16));
5133
+}
5134
+
5135
+static u16 bnxt_get_max_rss_ring(struct bnxt *bp)
5136
+{
5137
+ u16 i, tbl_size, max_ring = 0;
5138
+
5139
+ if (!bp->rss_indir_tbl)
5140
+ return 0;
5141
+
5142
+ tbl_size = bnxt_get_rxfh_indir_size(bp->dev);
5143
+ for (i = 0; i < tbl_size; i++)
5144
+ max_ring = max(max_ring, bp->rss_indir_tbl[i]);
5145
+ return max_ring;
5146
+}
5147
+
5148
+int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings)
5149
+{
5150
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5151
+ return DIV_ROUND_UP(rx_rings, BNXT_RSS_TABLE_ENTRIES_P5);
5152
+ if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5153
+ return 2;
5154
+ return 1;
5155
+}
5156
+
5157
+static void __bnxt_fill_hw_rss_tbl(struct bnxt *bp, struct bnxt_vnic_info *vnic)
5158
+{
5159
+ bool no_rss = !(vnic->flags & BNXT_VNIC_RSS_FLAG);
5160
+ u16 i, j;
5161
+
5162
+ /* Fill the RSS indirection table with ring group ids */
5163
+ for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
5164
+ if (!no_rss)
5165
+ j = bp->rss_indir_tbl[i];
5166
+ vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
5167
+ }
5168
+}
5169
+
5170
+static void __bnxt_fill_hw_rss_tbl_p5(struct bnxt *bp,
5171
+ struct bnxt_vnic_info *vnic)
5172
+{
5173
+ __le16 *ring_tbl = vnic->rss_table;
5174
+ struct bnxt_rx_ring_info *rxr;
5175
+ u16 tbl_size, i;
5176
+
5177
+ tbl_size = bnxt_get_rxfh_indir_size(bp->dev);
5178
+
5179
+ for (i = 0; i < tbl_size; i++) {
5180
+ u16 ring_id, j;
5181
+
5182
+ j = bp->rss_indir_tbl[i];
5183
+ rxr = &bp->rx_ring[j];
5184
+
5185
+ ring_id = rxr->rx_ring_struct.fw_ring_id;
5186
+ *ring_tbl++ = cpu_to_le16(ring_id);
5187
+ ring_id = bnxt_cp_ring_for_rx(bp, rxr);
5188
+ *ring_tbl++ = cpu_to_le16(ring_id);
5189
+ }
5190
+}
5191
+
5192
+static void bnxt_fill_hw_rss_tbl(struct bnxt *bp, struct bnxt_vnic_info *vnic)
5193
+{
5194
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5195
+ __bnxt_fill_hw_rss_tbl_p5(bp, vnic);
5196
+ else
5197
+ __bnxt_fill_hw_rss_tbl(bp, vnic);
5198
+}
5199
+
40175200 static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
40185201 {
4019
- u32 i, j, max_rings;
40205202 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
40215203 struct hwrm_vnic_rss_cfg_input req = {0};
40225204
4023
- if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
5205
+ if ((bp->flags & BNXT_FLAG_CHIP_P5) ||
5206
+ vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
40245207 return 0;
40255208
40265209 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
40275210 if (set_rss) {
5211
+ bnxt_fill_hw_rss_tbl(bp, vnic);
40285212 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
40295213 req.hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT;
4030
- if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
4031
- if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4032
- max_rings = bp->rx_nr_rings - 1;
4033
- else
4034
- max_rings = bp->rx_nr_rings;
4035
- } else {
4036
- max_rings = 1;
4037
- }
4038
-
4039
- /* Fill the RSS indirection table with ring group ids */
4040
- for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
4041
- if (j == max_rings)
4042
- j = 0;
4043
- vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
4044
- }
4045
-
40465214 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
40475215 req.hash_key_tbl_addr =
40485216 cpu_to_le64(vnic->rss_hash_key_dma_addr);
40495217 }
40505218 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
40515219 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5220
+}
5221
+
5222
+static int bnxt_hwrm_vnic_set_rss_p5(struct bnxt *bp, u16 vnic_id, bool set_rss)
5223
+{
5224
+ struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
5225
+ struct hwrm_vnic_rss_cfg_input req = {0};
5226
+ dma_addr_t ring_tbl_map;
5227
+ u32 i, nr_ctxs;
5228
+
5229
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
5230
+ req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
5231
+ if (!set_rss) {
5232
+ hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5233
+ return 0;
5234
+ }
5235
+ bnxt_fill_hw_rss_tbl(bp, vnic);
5236
+ req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
5237
+ req.hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT;
5238
+ req.hash_key_tbl_addr = cpu_to_le64(vnic->rss_hash_key_dma_addr);
5239
+ ring_tbl_map = vnic->rss_table_dma_addr;
5240
+ nr_ctxs = bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings);
5241
+ for (i = 0; i < nr_ctxs; ring_tbl_map += BNXT_RSS_TABLE_SIZE_P5, i++) {
5242
+ int rc;
5243
+
5244
+ req.ring_grp_tbl_addr = cpu_to_le64(ring_tbl_map);
5245
+ req.ring_table_pair_index = i;
5246
+ req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[i]);
5247
+ rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5248
+ if (rc)
5249
+ return rc;
5250
+ }
5251
+ return 0;
40525252 }
40535253
40545254 static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
....@@ -4134,6 +5334,18 @@
41345334
41355335 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
41365336
5337
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5338
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0];
5339
+
5340
+ req.default_rx_ring_id =
5341
+ cpu_to_le16(rxr->rx_ring_struct.fw_ring_id);
5342
+ req.default_cmpl_ring_id =
5343
+ cpu_to_le16(bnxt_cp_ring_for_rx(bp, rxr));
5344
+ req.enables =
5345
+ cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID |
5346
+ VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID);
5347
+ goto vnic_mru;
5348
+ }
41375349 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
41385350 /* Only RSS support for now TBD: COS & LB */
41395351 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
....@@ -4166,13 +5378,12 @@
41665378 ring = bp->rx_nr_rings - 1;
41675379
41685380 grp_idx = bp->rx_ring[ring].bnapi->index;
4169
- req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
41705381 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
4171
-
41725382 req.lb_rule = cpu_to_le16(0xffff);
4173
- req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
4174
- VLAN_HLEN);
5383
+vnic_mru:
5384
+ req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + VLAN_HLEN);
41755385
5386
+ req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
41765387 #ifdef CONFIG_BNXT_SRIOV
41775388 if (BNXT_VF(bp))
41785389 def_vlan = bp->vf.vlan;
....@@ -4185,10 +5396,8 @@
41855396 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
41865397 }
41875398
4188
-static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
5399
+static void bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
41895400 {
4190
- u32 rc = 0;
4191
-
41925401 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
41935402 struct hwrm_vnic_free_input req = {0};
41945403
....@@ -4196,12 +5405,9 @@
41965405 req.vnic_id =
41975406 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
41985407
4199
- rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4200
- if (rc)
4201
- return rc;
5408
+ hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
42025409 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
42035410 }
4204
- return rc;
42055411 }
42065412
42075413 static void bnxt_hwrm_vnic_free(struct bnxt *bp)
....@@ -4220,6 +5426,10 @@
42205426 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
42215427 struct hwrm_vnic_alloc_input req = {0};
42225428 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5429
+ struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
5430
+
5431
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5432
+ goto vnic_no_ring_grps;
42235433
42245434 /* map ring groups to this vnic */
42255435 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
....@@ -4229,12 +5439,12 @@
42295439 j, nr_rings);
42305440 break;
42315441 }
4232
- bp->vnic_info[vnic_id].fw_grp_ids[j] =
4233
- bp->grp_info[grp_idx].fw_grp_id;
5442
+ vnic->fw_grp_ids[j] = bp->grp_info[grp_idx].fw_grp_id;
42345443 }
42355444
4236
- bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
4237
- bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
5445
+vnic_no_ring_grps:
5446
+ for (i = 0; i < BNXT_MAX_CTX_PER_VNIC; i++)
5447
+ vnic->fw_rss_cos_lb_ctx[i] = INVALID_HW_RING_ID;
42385448 if (vnic_id == 0)
42395449 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
42405450
....@@ -4243,7 +5453,7 @@
42435453 mutex_lock(&bp->hwrm_cmd_lock);
42445454 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
42455455 if (!rc)
4246
- bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
5456
+ vnic->fw_vnic_id = le32_to_cpu(resp->vnic_id);
42475457 mutex_unlock(&bp->hwrm_cmd_lock);
42485458 return rc;
42495459 }
....@@ -4254,6 +5464,8 @@
42545464 struct hwrm_vnic_qcaps_input req = {0};
42555465 int rc;
42565466
5467
+ bp->hw_ring_stats_size = sizeof(struct ctx_hw_stats);
5468
+ bp->flags &= ~(BNXT_FLAG_NEW_RSS_CAP | BNXT_FLAG_ROCE_MIRROR_CAP);
42575469 if (bp->hwrm_spec_code < 0x10600)
42585470 return 0;
42595471
....@@ -4263,11 +5475,27 @@
42635475 if (!rc) {
42645476 u32 flags = le32_to_cpu(resp->flags);
42655477
4266
- if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)
5478
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5) &&
5479
+ (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
42675480 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
42685481 if (flags &
42695482 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
42705483 bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
5484
+
5485
+ /* Older P5 fw before EXT_HW_STATS support did not set
5486
+ * VLAN_STRIP_CAP properly.
5487
+ */
5488
+ if ((flags & VNIC_QCAPS_RESP_FLAGS_VLAN_STRIP_CAP) ||
5489
+ (BNXT_CHIP_P5_THOR(bp) &&
5490
+ !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED)))
5491
+ bp->fw_cap |= BNXT_FW_CAP_VLAN_RX_STRIP;
5492
+ bp->max_tpa_v2 = le16_to_cpu(resp->max_aggs_supported);
5493
+ if (bp->max_tpa_v2) {
5494
+ if (BNXT_CHIP_P5_THOR(bp))
5495
+ bp->hw_ring_stats_size = BNXT_RING_STATS_SIZE_P5;
5496
+ else
5497
+ bp->hw_ring_stats_size = BNXT_RING_STATS_SIZE_P5_SR2;
5498
+ }
42715499 }
42725500 mutex_unlock(&bp->hwrm_cmd_lock);
42735501 return rc;
....@@ -4277,6 +5505,9 @@
42775505 {
42785506 u16 i;
42795507 u32 rc = 0;
5508
+
5509
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5510
+ return 0;
42805511
42815512 mutex_lock(&bp->hwrm_cmd_lock);
42825513 for (i = 0; i < bp->rx_nr_rings; i++) {
....@@ -4304,14 +5535,13 @@
43045535 return rc;
43055536 }
43065537
4307
-static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
5538
+static void bnxt_hwrm_ring_grp_free(struct bnxt *bp)
43085539 {
43095540 u16 i;
4310
- u32 rc = 0;
43115541 struct hwrm_ring_grp_free_input req = {0};
43125542
4313
- if (!bp->grp_info)
4314
- return 0;
5543
+ if (!bp->grp_info || (bp->flags & BNXT_FLAG_CHIP_P5))
5544
+ return;
43155545
43165546 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
43175547
....@@ -4322,14 +5552,10 @@
43225552 req.ring_group_id =
43235553 cpu_to_le32(bp->grp_info[i].fw_grp_id);
43245554
4325
- rc = _hwrm_send_message(bp, &req, sizeof(req),
4326
- HWRM_CMD_TIMEOUT);
4327
- if (rc)
4328
- break;
5555
+ _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
43295556 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
43305557 }
43315558 mutex_unlock(&bp->hwrm_cmd_lock);
4332
- return rc;
43335559 }
43345560
43355561 static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
....@@ -4339,44 +5565,89 @@
43395565 int rc = 0, err = 0;
43405566 struct hwrm_ring_alloc_input req = {0};
43415567 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5568
+ struct bnxt_ring_mem_info *rmem = &ring->ring_mem;
43425569 struct bnxt_ring_grp_info *grp_info;
43435570 u16 ring_id;
43445571
43455572 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
43465573
43475574 req.enables = 0;
4348
- if (ring->nr_pages > 1) {
4349
- req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
5575
+ if (rmem->nr_pages > 1) {
5576
+ req.page_tbl_addr = cpu_to_le64(rmem->pg_tbl_map);
43505577 /* Page size is in log2 units */
43515578 req.page_size = BNXT_PAGE_SHIFT;
43525579 req.page_tbl_depth = 1;
43535580 } else {
4354
- req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
5581
+ req.page_tbl_addr = cpu_to_le64(rmem->dma_arr[0]);
43555582 }
43565583 req.fbo = 0;
43575584 /* Association of ring index with doorbell index and MSIX number */
43585585 req.logical_id = cpu_to_le16(map_index);
43595586
43605587 switch (ring_type) {
4361
- case HWRM_RING_ALLOC_TX:
5588
+ case HWRM_RING_ALLOC_TX: {
5589
+ struct bnxt_tx_ring_info *txr;
5590
+
5591
+ txr = container_of(ring, struct bnxt_tx_ring_info,
5592
+ tx_ring_struct);
43625593 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
43635594 /* Association of transmit ring with completion ring */
43645595 grp_info = &bp->grp_info[ring->grp_idx];
4365
- req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
5596
+ req.cmpl_ring_id = cpu_to_le16(bnxt_cp_ring_for_tx(bp, txr));
43665597 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
43675598 req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
43685599 req.queue_id = cpu_to_le16(ring->queue_id);
43695600 break;
5601
+ }
43705602 case HWRM_RING_ALLOC_RX:
43715603 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
43725604 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
5605
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5606
+ u16 flags = 0;
5607
+
5608
+ /* Association of rx ring with stats context */
5609
+ grp_info = &bp->grp_info[ring->grp_idx];
5610
+ req.rx_buf_size = cpu_to_le16(bp->rx_buf_use_size);
5611
+ req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
5612
+ req.enables |= cpu_to_le32(
5613
+ RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
5614
+ if (NET_IP_ALIGN == 2)
5615
+ flags = RING_ALLOC_REQ_FLAGS_RX_SOP_PAD;
5616
+ req.flags = cpu_to_le16(flags);
5617
+ }
43735618 break;
43745619 case HWRM_RING_ALLOC_AGG:
4375
- req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
5620
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5621
+ req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX_AGG;
5622
+ /* Association of agg ring with rx ring */
5623
+ grp_info = &bp->grp_info[ring->grp_idx];
5624
+ req.rx_ring_id = cpu_to_le16(grp_info->rx_fw_ring_id);
5625
+ req.rx_buf_size = cpu_to_le16(BNXT_RX_PAGE_SIZE);
5626
+ req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
5627
+ req.enables |= cpu_to_le32(
5628
+ RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID |
5629
+ RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
5630
+ } else {
5631
+ req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
5632
+ }
43765633 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
43775634 break;
43785635 case HWRM_RING_ALLOC_CMPL:
43795636 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
5637
+ req.length = cpu_to_le32(bp->cp_ring_mask + 1);
5638
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5639
+ /* Association of cp ring with nq */
5640
+ grp_info = &bp->grp_info[map_index];
5641
+ req.nq_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
5642
+ req.cq_handle = cpu_to_le64(ring->handle);
5643
+ req.enables |= cpu_to_le32(
5644
+ RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID);
5645
+ } else if (bp->flags & BNXT_FLAG_USING_MSIX) {
5646
+ req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
5647
+ }
5648
+ break;
5649
+ case HWRM_RING_ALLOC_NQ:
5650
+ req.ring_type = RING_ALLOC_REQ_RING_TYPE_NQ;
43805651 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
43815652 if (bp->flags & BNXT_FLAG_USING_MSIX)
43825653 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
....@@ -4426,22 +5697,74 @@
44265697 return rc;
44275698 }
44285699
5700
+static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
5701
+ u32 map_idx, u32 xid)
5702
+{
5703
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5704
+ if (BNXT_PF(bp))
5705
+ db->doorbell = bp->bar1 + DB_PF_OFFSET_P5;
5706
+ else
5707
+ db->doorbell = bp->bar1 + DB_VF_OFFSET_P5;
5708
+ switch (ring_type) {
5709
+ case HWRM_RING_ALLOC_TX:
5710
+ db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SQ;
5711
+ break;
5712
+ case HWRM_RING_ALLOC_RX:
5713
+ case HWRM_RING_ALLOC_AGG:
5714
+ db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SRQ;
5715
+ break;
5716
+ case HWRM_RING_ALLOC_CMPL:
5717
+ db->db_key64 = DBR_PATH_L2;
5718
+ break;
5719
+ case HWRM_RING_ALLOC_NQ:
5720
+ db->db_key64 = DBR_PATH_L2;
5721
+ break;
5722
+ }
5723
+ db->db_key64 |= (u64)xid << DBR_XID_SFT;
5724
+ } else {
5725
+ db->doorbell = bp->bar1 + map_idx * 0x80;
5726
+ switch (ring_type) {
5727
+ case HWRM_RING_ALLOC_TX:
5728
+ db->db_key32 = DB_KEY_TX;
5729
+ break;
5730
+ case HWRM_RING_ALLOC_RX:
5731
+ case HWRM_RING_ALLOC_AGG:
5732
+ db->db_key32 = DB_KEY_RX;
5733
+ break;
5734
+ case HWRM_RING_ALLOC_CMPL:
5735
+ db->db_key32 = DB_KEY_CP;
5736
+ break;
5737
+ }
5738
+ }
5739
+}
5740
+
44295741 static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
44305742 {
5743
+ bool agg_rings = !!(bp->flags & BNXT_FLAG_AGG_RINGS);
44315744 int i, rc = 0;
5745
+ u32 type;
44325746
5747
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5748
+ type = HWRM_RING_ALLOC_NQ;
5749
+ else
5750
+ type = HWRM_RING_ALLOC_CMPL;
44335751 for (i = 0; i < bp->cp_nr_rings; i++) {
44345752 struct bnxt_napi *bnapi = bp->bnapi[i];
44355753 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
44365754 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
44375755 u32 map_idx = ring->map_idx;
5756
+ unsigned int vector;
44385757
4439
- cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4440
- rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4441
- map_idx);
4442
- if (rc)
5758
+ vector = bp->irq_tbl[map_idx].vector;
5759
+ disable_irq_nosync(vector);
5760
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
5761
+ if (rc) {
5762
+ enable_irq(vector);
44435763 goto err_out;
4444
- BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
5764
+ }
5765
+ bnxt_set_db(bp, &cpr->cp_db, type, map_idx, ring->fw_ring_id);
5766
+ bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons);
5767
+ enable_irq(vector);
44455768 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
44465769
44475770 if (!i) {
....@@ -4451,33 +5774,71 @@
44515774 }
44525775 }
44535776
5777
+ type = HWRM_RING_ALLOC_TX;
44545778 for (i = 0; i < bp->tx_nr_rings; i++) {
44555779 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4456
- struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4457
- u32 map_idx = i;
5780
+ struct bnxt_ring_struct *ring;
5781
+ u32 map_idx;
44585782
4459
- rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4460
- map_idx);
5783
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5784
+ struct bnxt_napi *bnapi = txr->bnapi;
5785
+ struct bnxt_cp_ring_info *cpr, *cpr2;
5786
+ u32 type2 = HWRM_RING_ALLOC_CMPL;
5787
+
5788
+ cpr = &bnapi->cp_ring;
5789
+ cpr2 = cpr->cp_ring_arr[BNXT_TX_HDL];
5790
+ ring = &cpr2->cp_ring_struct;
5791
+ ring->handle = BNXT_TX_HDL;
5792
+ map_idx = bnapi->index;
5793
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx);
5794
+ if (rc)
5795
+ goto err_out;
5796
+ bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
5797
+ ring->fw_ring_id);
5798
+ bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons);
5799
+ }
5800
+ ring = &txr->tx_ring_struct;
5801
+ map_idx = i;
5802
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
44615803 if (rc)
44625804 goto err_out;
4463
- txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
5805
+ bnxt_set_db(bp, &txr->tx_db, type, map_idx, ring->fw_ring_id);
44645806 }
44655807
5808
+ type = HWRM_RING_ALLOC_RX;
44665809 for (i = 0; i < bp->rx_nr_rings; i++) {
44675810 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
44685811 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
4469
- u32 map_idx = rxr->bnapi->index;
5812
+ struct bnxt_napi *bnapi = rxr->bnapi;
5813
+ u32 map_idx = bnapi->index;
44705814
4471
- rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4472
- map_idx);
5815
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
44735816 if (rc)
44745817 goto err_out;
4475
- rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
4476
- writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
5818
+ bnxt_set_db(bp, &rxr->rx_db, type, map_idx, ring->fw_ring_id);
5819
+ /* If we have agg rings, post agg buffers first. */
5820
+ if (!agg_rings)
5821
+ bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
44775822 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
5823
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
5824
+ struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5825
+ u32 type2 = HWRM_RING_ALLOC_CMPL;
5826
+ struct bnxt_cp_ring_info *cpr2;
5827
+
5828
+ cpr2 = cpr->cp_ring_arr[BNXT_RX_HDL];
5829
+ ring = &cpr2->cp_ring_struct;
5830
+ ring->handle = BNXT_RX_HDL;
5831
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx);
5832
+ if (rc)
5833
+ goto err_out;
5834
+ bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
5835
+ ring->fw_ring_id);
5836
+ bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons);
5837
+ }
44785838 }
44795839
4480
- if (bp->flags & BNXT_FLAG_AGG_RINGS) {
5840
+ if (agg_rings) {
5841
+ type = HWRM_RING_ALLOC_AGG;
44815842 for (i = 0; i < bp->rx_nr_rings; i++) {
44825843 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
44835844 struct bnxt_ring_struct *ring =
....@@ -4485,15 +5846,14 @@
44855846 u32 grp_idx = ring->grp_idx;
44865847 u32 map_idx = grp_idx + bp->rx_nr_rings;
44875848
4488
- rc = hwrm_ring_alloc_send_msg(bp, ring,
4489
- HWRM_RING_ALLOC_AGG,
4490
- map_idx);
5849
+ rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
44915850 if (rc)
44925851 goto err_out;
44935852
4494
- rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
4495
- writel(DB_KEY_RX | rxr->rx_agg_prod,
4496
- rxr->rx_agg_doorbell);
5853
+ bnxt_set_db(bp, &rxr->rx_agg_db, type, map_idx,
5854
+ ring->fw_ring_id);
5855
+ bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
5856
+ bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
44975857 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
44985858 }
44995859 }
....@@ -4509,6 +5869,9 @@
45095869 struct hwrm_ring_free_input req = {0};
45105870 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
45115871 u16 error_code;
5872
+
5873
+ if (BNXT_NO_FW_ACCESS(bp))
5874
+ return 0;
45125875
45135876 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
45145877 req.ring_type = ring_type;
....@@ -4529,6 +5892,7 @@
45295892
45305893 static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
45315894 {
5895
+ u32 type;
45325896 int i;
45335897
45345898 if (!bp->bnapi)
....@@ -4537,10 +5901,10 @@
45375901 for (i = 0; i < bp->tx_nr_rings; i++) {
45385902 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
45395903 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4540
- u32 grp_idx = txr->bnapi->index;
4541
- u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
45425904
45435905 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
5906
+ u32 cmpl_ring_id = bnxt_cp_ring_for_tx(bp, txr);
5907
+
45445908 hwrm_ring_free_send_msg(bp, ring,
45455909 RING_FREE_REQ_RING_TYPE_TX,
45465910 close_path ? cmpl_ring_id :
....@@ -4553,9 +5917,10 @@
45535917 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
45545918 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
45555919 u32 grp_idx = rxr->bnapi->index;
4556
- u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
45575920
45585921 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
5922
+ u32 cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
5923
+
45595924 hwrm_ring_free_send_msg(bp, ring,
45605925 RING_FREE_REQ_RING_TYPE_RX,
45615926 close_path ? cmpl_ring_id :
....@@ -4566,15 +5931,19 @@
45665931 }
45675932 }
45685933
5934
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5935
+ type = RING_FREE_REQ_RING_TYPE_RX_AGG;
5936
+ else
5937
+ type = RING_FREE_REQ_RING_TYPE_RX;
45695938 for (i = 0; i < bp->rx_nr_rings; i++) {
45705939 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
45715940 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
45725941 u32 grp_idx = rxr->bnapi->index;
4573
- u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
45745942
45755943 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4576
- hwrm_ring_free_send_msg(bp, ring,
4577
- RING_FREE_REQ_RING_TYPE_RX,
5944
+ u32 cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
5945
+
5946
+ hwrm_ring_free_send_msg(bp, ring, type,
45785947 close_path ? cmpl_ring_id :
45795948 INVALID_HW_RING_ID);
45805949 ring->fw_ring_id = INVALID_HW_RING_ID;
....@@ -4589,20 +5958,41 @@
45895958 */
45905959 bnxt_disable_int_sync(bp);
45915960
5961
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
5962
+ type = RING_FREE_REQ_RING_TYPE_NQ;
5963
+ else
5964
+ type = RING_FREE_REQ_RING_TYPE_L2_CMPL;
45925965 for (i = 0; i < bp->cp_nr_rings; i++) {
45935966 struct bnxt_napi *bnapi = bp->bnapi[i];
45945967 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4595
- struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
5968
+ struct bnxt_ring_struct *ring;
5969
+ int j;
45965970
5971
+ for (j = 0; j < 2; j++) {
5972
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
5973
+
5974
+ if (cpr2) {
5975
+ ring = &cpr2->cp_ring_struct;
5976
+ if (ring->fw_ring_id == INVALID_HW_RING_ID)
5977
+ continue;
5978
+ hwrm_ring_free_send_msg(bp, ring,
5979
+ RING_FREE_REQ_RING_TYPE_L2_CMPL,
5980
+ INVALID_HW_RING_ID);
5981
+ ring->fw_ring_id = INVALID_HW_RING_ID;
5982
+ }
5983
+ }
5984
+ ring = &cpr->cp_ring_struct;
45975985 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4598
- hwrm_ring_free_send_msg(bp, ring,
4599
- RING_FREE_REQ_RING_TYPE_L2_CMPL,
5986
+ hwrm_ring_free_send_msg(bp, ring, type,
46005987 INVALID_HW_RING_ID);
46015988 ring->fw_ring_id = INVALID_HW_RING_ID;
46025989 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
46035990 }
46045991 }
46055992 }
5993
+
5994
+static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5995
+ bool shared);
46065996
46075997 static int bnxt_hwrm_get_rings(struct bnxt *bp)
46085998 {
....@@ -4620,7 +6010,7 @@
46206010 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
46216011 if (rc) {
46226012 mutex_unlock(&bp->hwrm_cmd_lock);
4623
- return -EIO;
6013
+ return rc;
46246014 }
46256015
46266016 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
....@@ -4633,8 +6023,25 @@
46336023 hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
46346024 cp = le16_to_cpu(resp->alloc_cmpl_rings);
46356025 stats = le16_to_cpu(resp->alloc_stat_ctx);
4636
- cp = min_t(u16, cp, stats);
6026
+ hw_resc->resv_irqs = cp;
6027
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6028
+ int rx = hw_resc->resv_rx_rings;
6029
+ int tx = hw_resc->resv_tx_rings;
6030
+
6031
+ if (bp->flags & BNXT_FLAG_AGG_RINGS)
6032
+ rx >>= 1;
6033
+ if (cp < (rx + tx)) {
6034
+ bnxt_trim_rings(bp, &rx, &tx, cp, false);
6035
+ if (bp->flags & BNXT_FLAG_AGG_RINGS)
6036
+ rx <<= 1;
6037
+ hw_resc->resv_rx_rings = rx;
6038
+ hw_resc->resv_tx_rings = tx;
6039
+ }
6040
+ hw_resc->resv_irqs = le16_to_cpu(resp->alloc_msix);
6041
+ hw_resc->resv_hw_ring_grps = rx;
6042
+ }
46376043 hw_resc->resv_cp_rings = cp;
6044
+ hw_resc->resv_stat_ctxs = stats;
46386045 }
46396046 mutex_unlock(&bp->hwrm_cmd_lock);
46406047 return 0;
....@@ -4659,10 +6066,12 @@
46596066 return rc;
46606067 }
46616068
6069
+static bool bnxt_rfs_supported(struct bnxt *bp);
6070
+
46626071 static void
46636072 __bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
46646073 int tx_rings, int rx_rings, int ring_grps,
4665
- int cp_rings, int vnics)
6074
+ int cp_rings, int stats, int vnics)
46666075 {
46676076 u32 enables = 0;
46686077
....@@ -4672,16 +6081,38 @@
46726081 req->num_tx_rings = cpu_to_le16(tx_rings);
46736082 if (BNXT_NEW_RM(bp)) {
46746083 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4675
- enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4676
- FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4677
- enables |= ring_grps ?
4678
- FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
6084
+ enables |= stats ? FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
6085
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6086
+ enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_MSIX : 0;
6087
+ enables |= tx_rings + ring_grps ?
6088
+ FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
6089
+ enables |= rx_rings ?
6090
+ FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
6091
+ } else {
6092
+ enables |= cp_rings ?
6093
+ FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
6094
+ enables |= ring_grps ?
6095
+ FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS |
6096
+ FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
6097
+ }
46796098 enables |= vnics ? FUNC_CFG_REQ_ENABLES_NUM_VNICS : 0;
46806099
46816100 req->num_rx_rings = cpu_to_le16(rx_rings);
4682
- req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4683
- req->num_cmpl_rings = cpu_to_le16(cp_rings);
4684
- req->num_stat_ctxs = req->num_cmpl_rings;
6101
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6102
+ req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps);
6103
+ req->num_msix = cpu_to_le16(cp_rings);
6104
+ req->num_rsscos_ctxs =
6105
+ cpu_to_le16(DIV_ROUND_UP(ring_grps, 64));
6106
+ } else {
6107
+ req->num_cmpl_rings = cpu_to_le16(cp_rings);
6108
+ req->num_hw_ring_grps = cpu_to_le16(ring_grps);
6109
+ req->num_rsscos_ctxs = cpu_to_le16(1);
6110
+ if (!(bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
6111
+ bnxt_rfs_supported(bp))
6112
+ req->num_rsscos_ctxs =
6113
+ cpu_to_le16(ring_grps + 1);
6114
+ }
6115
+ req->num_stat_ctxs = cpu_to_le16(stats);
46856116 req->num_vnics = cpu_to_le16(vnics);
46866117 }
46876118 req->enables = cpu_to_le32(enables);
....@@ -4691,23 +6122,39 @@
46916122 __bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
46926123 struct hwrm_func_vf_cfg_input *req, int tx_rings,
46936124 int rx_rings, int ring_grps, int cp_rings,
4694
- int vnics)
6125
+ int stats, int vnics)
46956126 {
46966127 u32 enables = 0;
46976128
46986129 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
46996130 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4700
- enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4701
- enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4702
- FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4703
- enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
6131
+ enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS |
6132
+ FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
6133
+ enables |= stats ? FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
6134
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6135
+ enables |= tx_rings + ring_grps ?
6136
+ FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
6137
+ } else {
6138
+ enables |= cp_rings ?
6139
+ FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
6140
+ enables |= ring_grps ?
6141
+ FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
6142
+ }
47046143 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
6144
+ enables |= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS;
47056145
6146
+ req->num_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX);
47066147 req->num_tx_rings = cpu_to_le16(tx_rings);
47076148 req->num_rx_rings = cpu_to_le16(rx_rings);
4708
- req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4709
- req->num_cmpl_rings = cpu_to_le16(cp_rings);
4710
- req->num_stat_ctxs = req->num_cmpl_rings;
6149
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6150
+ req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps);
6151
+ req->num_rsscos_ctxs = cpu_to_le16(DIV_ROUND_UP(ring_grps, 64));
6152
+ } else {
6153
+ req->num_cmpl_rings = cpu_to_le16(cp_rings);
6154
+ req->num_hw_ring_grps = cpu_to_le16(ring_grps);
6155
+ req->num_rsscos_ctxs = cpu_to_le16(BNXT_VF_MAX_RSS_CTX);
6156
+ }
6157
+ req->num_stat_ctxs = cpu_to_le16(stats);
47116158 req->num_vnics = cpu_to_le16(vnics);
47126159
47136160 req->enables = cpu_to_le32(enables);
....@@ -4715,30 +6162,29 @@
47156162
47166163 static int
47176164 bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4718
- int ring_grps, int cp_rings, int vnics)
6165
+ int ring_grps, int cp_rings, int stats, int vnics)
47196166 {
47206167 struct hwrm_func_cfg_input req = {0};
47216168 int rc;
47226169
47236170 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4724
- cp_rings, vnics);
6171
+ cp_rings, stats, vnics);
47256172 if (!req.enables)
47266173 return 0;
47276174
47286175 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
47296176 if (rc)
4730
- return -ENOMEM;
6177
+ return rc;
47316178
47326179 if (bp->hwrm_spec_code < 0x10601)
47336180 bp->hw_resc.resv_tx_rings = tx_rings;
47346181
4735
- rc = bnxt_hwrm_get_rings(bp);
4736
- return rc;
6182
+ return bnxt_hwrm_get_rings(bp);
47376183 }
47386184
47396185 static int
47406186 bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4741
- int ring_grps, int cp_rings, int vnics)
6187
+ int ring_grps, int cp_rings, int stats, int vnics)
47426188 {
47436189 struct hwrm_func_vf_cfg_input req = {0};
47446190 int rc;
....@@ -4749,29 +6195,26 @@
47496195 }
47506196
47516197 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4752
- cp_rings, vnics);
4753
- req.enables |= cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS |
4754
- FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS);
4755
- req.num_rsscos_ctxs = cpu_to_le16(BNXT_VF_MAX_RSS_CTX);
4756
- req.num_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX);
6198
+ cp_rings, stats, vnics);
47576199 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
47586200 if (rc)
4759
- return -ENOMEM;
6201
+ return rc;
47606202
4761
- rc = bnxt_hwrm_get_rings(bp);
4762
- return rc;
6203
+ return bnxt_hwrm_get_rings(bp);
47636204 }
47646205
47656206 static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
4766
- int cp, int vnic)
6207
+ int cp, int stat, int vnic)
47676208 {
47686209 if (BNXT_PF(bp))
4769
- return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic);
6210
+ return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, stat,
6211
+ vnic);
47706212 else
4771
- return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic);
6213
+ return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, stat,
6214
+ vnic);
47726215 }
47736216
4774
-static int bnxt_cp_rings_in_use(struct bnxt *bp)
6217
+int bnxt_nq_rings_in_use(struct bnxt *bp)
47756218 {
47766219 int cp = bp->cp_nr_rings;
47776220 int ulp_msix, ulp_base;
....@@ -4786,64 +6229,116 @@
47866229 return cp;
47876230 }
47886231
6232
+static int bnxt_cp_rings_in_use(struct bnxt *bp)
6233
+{
6234
+ int cp;
6235
+
6236
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
6237
+ return bnxt_nq_rings_in_use(bp);
6238
+
6239
+ cp = bp->tx_nr_rings + bp->rx_nr_rings;
6240
+ return cp;
6241
+}
6242
+
6243
+static int bnxt_get_func_stat_ctxs(struct bnxt *bp)
6244
+{
6245
+ int ulp_stat = bnxt_get_ulp_stat_ctxs(bp);
6246
+ int cp = bp->cp_nr_rings;
6247
+
6248
+ if (!ulp_stat)
6249
+ return cp;
6250
+
6251
+ if (bnxt_nq_rings_in_use(bp) > cp + bnxt_get_ulp_msix_num(bp))
6252
+ return bnxt_get_ulp_msix_base(bp) + ulp_stat;
6253
+
6254
+ return cp + ulp_stat;
6255
+}
6256
+
6257
+/* Check if a default RSS map needs to be setup. This function is only
6258
+ * used on older firmware that does not require reserving RX rings.
6259
+ */
6260
+static void bnxt_check_rss_tbl_no_rmgr(struct bnxt *bp)
6261
+{
6262
+ struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
6263
+
6264
+ /* The RSS map is valid for RX rings set to resv_rx_rings */
6265
+ if (hw_resc->resv_rx_rings != bp->rx_nr_rings) {
6266
+ hw_resc->resv_rx_rings = bp->rx_nr_rings;
6267
+ if (!netif_is_rxfh_configured(bp->dev))
6268
+ bnxt_set_dflt_rss_indir_tbl(bp);
6269
+ }
6270
+}
6271
+
47896272 static bool bnxt_need_reserve_rings(struct bnxt *bp)
47906273 {
47916274 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
47926275 int cp = bnxt_cp_rings_in_use(bp);
4793
- int rx = bp->rx_nr_rings;
6276
+ int nq = bnxt_nq_rings_in_use(bp);
6277
+ int rx = bp->rx_nr_rings, stat;
47946278 int vnic = 1, grp = rx;
47956279
4796
- if (bp->hwrm_spec_code < 0x10601)
4797
- return false;
4798
-
4799
- if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
6280
+ if (hw_resc->resv_tx_rings != bp->tx_nr_rings &&
6281
+ bp->hwrm_spec_code >= 0x10601)
48006282 return true;
48016283
4802
- if (bp->flags & BNXT_FLAG_RFS)
6284
+ /* Old firmware does not need RX ring reservations but we still
6285
+ * need to setup a default RSS map when needed. With new firmware
6286
+ * we go through RX ring reservations first and then set up the
6287
+ * RSS map for the successfully reserved RX rings when needed.
6288
+ */
6289
+ if (!BNXT_NEW_RM(bp)) {
6290
+ bnxt_check_rss_tbl_no_rmgr(bp);
6291
+ return false;
6292
+ }
6293
+ if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5))
48036294 vnic = rx + 1;
48046295 if (bp->flags & BNXT_FLAG_AGG_RINGS)
48056296 rx <<= 1;
4806
- if (BNXT_NEW_RM(bp) &&
4807
- (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
4808
- hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
6297
+ stat = bnxt_get_func_stat_ctxs(bp);
6298
+ if (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
6299
+ hw_resc->resv_vnics != vnic || hw_resc->resv_stat_ctxs != stat ||
6300
+ (hw_resc->resv_hw_ring_grps != grp &&
6301
+ !(bp->flags & BNXT_FLAG_CHIP_P5)))
6302
+ return true;
6303
+ if ((bp->flags & BNXT_FLAG_CHIP_P5) && BNXT_PF(bp) &&
6304
+ hw_resc->resv_irqs != nq)
48096305 return true;
48106306 return false;
48116307 }
48126308
4813
-static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4814
- bool shared);
4815
-
48166309 static int __bnxt_reserve_rings(struct bnxt *bp)
48176310 {
48186311 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4819
- int cp = bnxt_cp_rings_in_use(bp);
6312
+ int cp = bnxt_nq_rings_in_use(bp);
48206313 int tx = bp->tx_nr_rings;
48216314 int rx = bp->rx_nr_rings;
48226315 int grp, rx_rings, rc;
6316
+ int vnic = 1, stat;
48236317 bool sh = false;
4824
- int vnic = 1;
48256318
48266319 if (!bnxt_need_reserve_rings(bp))
48276320 return 0;
48286321
48296322 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
48306323 sh = true;
4831
- if (bp->flags & BNXT_FLAG_RFS)
6324
+ if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5))
48326325 vnic = rx + 1;
48336326 if (bp->flags & BNXT_FLAG_AGG_RINGS)
48346327 rx <<= 1;
48356328 grp = bp->rx_nr_rings;
6329
+ stat = bnxt_get_func_stat_ctxs(bp);
48366330
4837
- rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
6331
+ rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, stat, vnic);
48386332 if (rc)
48396333 return rc;
48406334
48416335 tx = hw_resc->resv_tx_rings;
48426336 if (BNXT_NEW_RM(bp)) {
48436337 rx = hw_resc->resv_rx_rings;
4844
- cp = hw_resc->resv_cp_rings;
6338
+ cp = hw_resc->resv_irqs;
48456339 grp = hw_resc->resv_hw_ring_grps;
48466340 vnic = hw_resc->resv_vnics;
6341
+ stat = hw_resc->resv_stat_ctxs;
48476342 }
48486343
48496344 rx_rings = rx;
....@@ -4862,124 +6357,245 @@
48626357 }
48636358 }
48646359 rx_rings = min_t(int, rx_rings, grp);
6360
+ cp = min_t(int, cp, bp->cp_nr_rings);
6361
+ if (stat > bnxt_get_ulp_stat_ctxs(bp))
6362
+ stat -= bnxt_get_ulp_stat_ctxs(bp);
6363
+ cp = min_t(int, cp, stat);
48656364 rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
48666365 if (bp->flags & BNXT_FLAG_AGG_RINGS)
48676366 rx = rx_rings << 1;
48686367 cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
48696368 bp->tx_nr_rings = tx;
6369
+
6370
+ /* If we cannot reserve all the RX rings, reset the RSS map only
6371
+ * if absolutely necessary
6372
+ */
6373
+ if (rx_rings != bp->rx_nr_rings) {
6374
+ netdev_warn(bp->dev, "Able to reserve only %d out of %d requested RX rings\n",
6375
+ rx_rings, bp->rx_nr_rings);
6376
+ if ((bp->dev->priv_flags & IFF_RXFH_CONFIGURED) &&
6377
+ (bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) !=
6378
+ bnxt_get_nr_rss_ctxs(bp, rx_rings) ||
6379
+ bnxt_get_max_rss_ring(bp) >= rx_rings)) {
6380
+ netdev_warn(bp->dev, "RSS table entries reverting to default\n");
6381
+ bp->dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
6382
+ }
6383
+ }
48706384 bp->rx_nr_rings = rx_rings;
48716385 bp->cp_nr_rings = cp;
48726386
4873
- if (!tx || !rx || !cp || !grp || !vnic)
6387
+ if (!tx || !rx || !cp || !grp || !vnic || !stat)
48746388 return -ENOMEM;
6389
+
6390
+ if (!netif_is_rxfh_configured(bp->dev))
6391
+ bnxt_set_dflt_rss_indir_tbl(bp);
48756392
48766393 return rc;
48776394 }
48786395
48796396 static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4880
- int ring_grps, int cp_rings, int vnics)
6397
+ int ring_grps, int cp_rings, int stats,
6398
+ int vnics)
48816399 {
48826400 struct hwrm_func_vf_cfg_input req = {0};
48836401 u32 flags;
4884
- int rc;
48856402
48866403 if (!BNXT_NEW_RM(bp))
48876404 return 0;
48886405
48896406 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4890
- cp_rings, vnics);
6407
+ cp_rings, stats, vnics);
48916408 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
48926409 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
48936410 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4894
- FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
48956411 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4896
- FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
6412
+ FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST |
6413
+ FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST;
6414
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
6415
+ flags |= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST;
48976416
48986417 req.flags = cpu_to_le32(flags);
4899
- rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4900
- if (rc)
4901
- return -ENOMEM;
4902
- return 0;
6418
+ return hwrm_send_message_silent(bp, &req, sizeof(req),
6419
+ HWRM_CMD_TIMEOUT);
49036420 }
49046421
49056422 static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4906
- int ring_grps, int cp_rings, int vnics)
6423
+ int ring_grps, int cp_rings, int stats,
6424
+ int vnics)
49076425 {
49086426 struct hwrm_func_cfg_input req = {0};
49096427 u32 flags;
4910
- int rc;
49116428
49126429 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4913
- cp_rings, vnics);
6430
+ cp_rings, stats, vnics);
49146431 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
4915
- if (BNXT_NEW_RM(bp))
6432
+ if (BNXT_NEW_RM(bp)) {
49166433 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
49176434 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4918
- FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
49196435 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
49206436 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
6437
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
6438
+ flags |= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST |
6439
+ FUNC_CFG_REQ_FLAGS_NQ_ASSETS_TEST;
6440
+ else
6441
+ flags |= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST;
6442
+ }
49216443
49226444 req.flags = cpu_to_le32(flags);
4923
- rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4924
- if (rc)
4925
- return -ENOMEM;
4926
- return 0;
6445
+ return hwrm_send_message_silent(bp, &req, sizeof(req),
6446
+ HWRM_CMD_TIMEOUT);
49276447 }
49286448
49296449 static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4930
- int ring_grps, int cp_rings, int vnics)
6450
+ int ring_grps, int cp_rings, int stats,
6451
+ int vnics)
49316452 {
49326453 if (bp->hwrm_spec_code < 0x10801)
49336454 return 0;
49346455
49356456 if (BNXT_PF(bp))
49366457 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
4937
- ring_grps, cp_rings, vnics);
6458
+ ring_grps, cp_rings, stats,
6459
+ vnics);
49386460
49396461 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
4940
- cp_rings, vnics);
6462
+ cp_rings, stats, vnics);
49416463 }
49426464
4943
-static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
6465
+static void bnxt_hwrm_coal_params_qcaps(struct bnxt *bp)
6466
+{
6467
+ struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6468
+ struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
6469
+ struct hwrm_ring_aggint_qcaps_input req = {0};
6470
+ int rc;
6471
+
6472
+ coal_cap->cmpl_params = BNXT_LEGACY_COAL_CMPL_PARAMS;
6473
+ coal_cap->num_cmpl_dma_aggr_max = 63;
6474
+ coal_cap->num_cmpl_dma_aggr_during_int_max = 63;
6475
+ coal_cap->cmpl_aggr_dma_tmr_max = 65535;
6476
+ coal_cap->cmpl_aggr_dma_tmr_during_int_max = 65535;
6477
+ coal_cap->int_lat_tmr_min_max = 65535;
6478
+ coal_cap->int_lat_tmr_max_max = 65535;
6479
+ coal_cap->num_cmpl_aggr_int_max = 65535;
6480
+ coal_cap->timer_units = 80;
6481
+
6482
+ if (bp->hwrm_spec_code < 0x10902)
6483
+ return;
6484
+
6485
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_AGGINT_QCAPS, -1, -1);
6486
+ mutex_lock(&bp->hwrm_cmd_lock);
6487
+ rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6488
+ if (!rc) {
6489
+ coal_cap->cmpl_params = le32_to_cpu(resp->cmpl_params);
6490
+ coal_cap->nq_params = le32_to_cpu(resp->nq_params);
6491
+ coal_cap->num_cmpl_dma_aggr_max =
6492
+ le16_to_cpu(resp->num_cmpl_dma_aggr_max);
6493
+ coal_cap->num_cmpl_dma_aggr_during_int_max =
6494
+ le16_to_cpu(resp->num_cmpl_dma_aggr_during_int_max);
6495
+ coal_cap->cmpl_aggr_dma_tmr_max =
6496
+ le16_to_cpu(resp->cmpl_aggr_dma_tmr_max);
6497
+ coal_cap->cmpl_aggr_dma_tmr_during_int_max =
6498
+ le16_to_cpu(resp->cmpl_aggr_dma_tmr_during_int_max);
6499
+ coal_cap->int_lat_tmr_min_max =
6500
+ le16_to_cpu(resp->int_lat_tmr_min_max);
6501
+ coal_cap->int_lat_tmr_max_max =
6502
+ le16_to_cpu(resp->int_lat_tmr_max_max);
6503
+ coal_cap->num_cmpl_aggr_int_max =
6504
+ le16_to_cpu(resp->num_cmpl_aggr_int_max);
6505
+ coal_cap->timer_units = le16_to_cpu(resp->timer_units);
6506
+ }
6507
+ mutex_unlock(&bp->hwrm_cmd_lock);
6508
+}
6509
+
6510
+static u16 bnxt_usec_to_coal_tmr(struct bnxt *bp, u16 usec)
6511
+{
6512
+ struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
6513
+
6514
+ return usec * 1000 / coal_cap->timer_units;
6515
+}
6516
+
6517
+static void bnxt_hwrm_set_coal_params(struct bnxt *bp,
6518
+ struct bnxt_coal *hw_coal,
49446519 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
49456520 {
4946
- u16 val, tmr, max, flags;
6521
+ struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
6522
+ u32 cmpl_params = coal_cap->cmpl_params;
6523
+ u16 val, tmr, max, flags = 0;
49476524
49486525 max = hw_coal->bufs_per_record * 128;
49496526 if (hw_coal->budget)
49506527 max = hw_coal->bufs_per_record * hw_coal->budget;
6528
+ max = min_t(u16, max, coal_cap->num_cmpl_aggr_int_max);
49516529
49526530 val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
49536531 req->num_cmpl_aggr_int = cpu_to_le16(val);
49546532
4955
- /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4956
- val = min_t(u16, val, 63);
6533
+ val = min_t(u16, val, coal_cap->num_cmpl_dma_aggr_max);
49576534 req->num_cmpl_dma_aggr = cpu_to_le16(val);
49586535
4959
- /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4960
- val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63);
6536
+ val = clamp_t(u16, hw_coal->coal_bufs_irq, 1,
6537
+ coal_cap->num_cmpl_dma_aggr_during_int_max);
49616538 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
49626539
4963
- tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4964
- tmr = max_t(u16, tmr, 1);
6540
+ tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks);
6541
+ tmr = clamp_t(u16, tmr, 1, coal_cap->int_lat_tmr_max_max);
49656542 req->int_lat_tmr_max = cpu_to_le16(tmr);
49666543
49676544 /* min timer set to 1/2 of interrupt timer */
4968
- val = tmr / 2;
4969
- req->int_lat_tmr_min = cpu_to_le16(val);
6545
+ if (cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN) {
6546
+ val = tmr / 2;
6547
+ val = clamp_t(u16, val, 1, coal_cap->int_lat_tmr_min_max);
6548
+ req->int_lat_tmr_min = cpu_to_le16(val);
6549
+ req->enables |= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE);
6550
+ }
49706551
49716552 /* buf timer set to 1/4 of interrupt timer */
4972
- val = max_t(u16, tmr / 4, 1);
6553
+ val = clamp_t(u16, tmr / 4, 1, coal_cap->cmpl_aggr_dma_tmr_max);
49736554 req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
49746555
4975
- tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4976
- tmr = max_t(u16, tmr, 1);
4977
- req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
6556
+ if (cmpl_params &
6557
+ RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT) {
6558
+ tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks_irq);
6559
+ val = clamp_t(u16, tmr, 1,
6560
+ coal_cap->cmpl_aggr_dma_tmr_during_int_max);
6561
+ req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(val);
6562
+ req->enables |=
6563
+ cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE);
6564
+ }
49786565
4979
- flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4980
- if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
6566
+ if (cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET)
6567
+ flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
6568
+ if ((cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE) &&
6569
+ hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
49816570 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
49826571 req->flags = cpu_to_le16(flags);
6572
+ req->enables |= cpu_to_le16(BNXT_COAL_CMPL_ENABLES);
6573
+}
6574
+
6575
+/* Caller holds bp->hwrm_cmd_lock */
6576
+static int __bnxt_hwrm_set_coal_nq(struct bnxt *bp, struct bnxt_napi *bnapi,
6577
+ struct bnxt_coal *hw_coal)
6578
+{
6579
+ struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
6580
+ struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6581
+ struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
6582
+ u32 nq_params = coal_cap->nq_params;
6583
+ u16 tmr;
6584
+
6585
+ if (!(nq_params & RING_AGGINT_QCAPS_RESP_NQ_PARAMS_INT_LAT_TMR_MIN))
6586
+ return 0;
6587
+
6588
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
6589
+ -1, -1);
6590
+ req.ring_id = cpu_to_le16(cpr->cp_ring_struct.fw_ring_id);
6591
+ req.flags =
6592
+ cpu_to_le16(RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_IS_NQ);
6593
+
6594
+ tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks) / 2;
6595
+ tmr = clamp_t(u16, tmr, 1, coal_cap->int_lat_tmr_min_max);
6596
+ req.int_lat_tmr_min = cpu_to_le16(tmr);
6597
+ req.enables |= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE);
6598
+ return _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
49836599 }
49846600
49856601 int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
....@@ -4987,7 +6603,6 @@
49876603 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0};
49886604 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
49896605 struct bnxt_coal coal;
4990
- unsigned int grp_idx;
49916606
49926607 /* Tick values in micro seconds.
49936608 * 1 coal_buf x bufs_per_record = 1 completion record.
....@@ -5003,10 +6618,9 @@
50036618 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
50046619 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
50056620
5006
- bnxt_hwrm_set_coal_params(&coal, &req_rx);
6621
+ bnxt_hwrm_set_coal_params(bp, &coal, &req_rx);
50076622
5008
- grp_idx = bnapi->index;
5009
- req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
6623
+ req_rx.ring_id = cpu_to_le16(bnxt_cp_ring_for_rx(bp, bnapi->rx_ring));
50106624
50116625 return hwrm_send_message(bp, &req_rx, sizeof(req_rx),
50126626 HWRM_CMD_TIMEOUT);
....@@ -5023,38 +6637,64 @@
50236637 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
50246638 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
50256639
5026
- bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
5027
- bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
6640
+ bnxt_hwrm_set_coal_params(bp, &bp->rx_coal, &req_rx);
6641
+ bnxt_hwrm_set_coal_params(bp, &bp->tx_coal, &req_tx);
50286642
50296643 mutex_lock(&bp->hwrm_cmd_lock);
50306644 for (i = 0; i < bp->cp_nr_rings; i++) {
50316645 struct bnxt_napi *bnapi = bp->bnapi[i];
6646
+ struct bnxt_coal *hw_coal;
6647
+ u16 ring_id;
50326648
50336649 req = &req_rx;
5034
- if (!bnapi->rx_ring)
6650
+ if (!bnapi->rx_ring) {
6651
+ ring_id = bnxt_cp_ring_for_tx(bp, bnapi->tx_ring);
50356652 req = &req_tx;
5036
- req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
6653
+ } else {
6654
+ ring_id = bnxt_cp_ring_for_rx(bp, bnapi->rx_ring);
6655
+ }
6656
+ req->ring_id = cpu_to_le16(ring_id);
50376657
50386658 rc = _hwrm_send_message(bp, req, sizeof(*req),
50396659 HWRM_CMD_TIMEOUT);
50406660 if (rc)
50416661 break;
6662
+
6663
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
6664
+ continue;
6665
+
6666
+ if (bnapi->rx_ring && bnapi->tx_ring) {
6667
+ req = &req_tx;
6668
+ ring_id = bnxt_cp_ring_for_tx(bp, bnapi->tx_ring);
6669
+ req->ring_id = cpu_to_le16(ring_id);
6670
+ rc = _hwrm_send_message(bp, req, sizeof(*req),
6671
+ HWRM_CMD_TIMEOUT);
6672
+ if (rc)
6673
+ break;
6674
+ }
6675
+ if (bnapi->rx_ring)
6676
+ hw_coal = &bp->rx_coal;
6677
+ else
6678
+ hw_coal = &bp->tx_coal;
6679
+ __bnxt_hwrm_set_coal_nq(bp, bnapi, hw_coal);
50426680 }
50436681 mutex_unlock(&bp->hwrm_cmd_lock);
50446682 return rc;
50456683 }
50466684
5047
-static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
6685
+static void bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
50486686 {
5049
- int rc = 0, i;
6687
+ struct hwrm_stat_ctx_clr_stats_input req0 = {0};
50506688 struct hwrm_stat_ctx_free_input req = {0};
6689
+ int i;
50516690
50526691 if (!bp->bnapi)
5053
- return 0;
6692
+ return;
50546693
50556694 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5056
- return 0;
6695
+ return;
50576696
6697
+ bnxt_hwrm_cmd_hdr_init(bp, &req0, HWRM_STAT_CTX_CLR_STATS, -1, -1);
50586698 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
50596699
50606700 mutex_lock(&bp->hwrm_cmd_lock);
....@@ -5064,17 +6704,18 @@
50646704
50656705 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
50666706 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
5067
-
5068
- rc = _hwrm_send_message(bp, &req, sizeof(req),
5069
- HWRM_CMD_TIMEOUT);
5070
- if (rc)
5071
- break;
6707
+ if (BNXT_FW_MAJ(bp) <= 20) {
6708
+ req0.stat_ctx_id = req.stat_ctx_id;
6709
+ _hwrm_send_message(bp, &req0, sizeof(req0),
6710
+ HWRM_CMD_TIMEOUT);
6711
+ }
6712
+ _hwrm_send_message(bp, &req, sizeof(req),
6713
+ HWRM_CMD_TIMEOUT);
50726714
50736715 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
50746716 }
50756717 }
50766718 mutex_unlock(&bp->hwrm_cmd_lock);
5077
- return rc;
50786719 }
50796720
50806721 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
....@@ -5088,6 +6729,7 @@
50886729
50896730 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
50906731
6732
+ req.stats_dma_length = cpu_to_le16(bp->hw_ring_stats_size);
50916733 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
50926734
50936735 mutex_lock(&bp->hwrm_cmd_lock);
....@@ -5095,7 +6737,7 @@
50956737 struct bnxt_napi *bnapi = bp->bnapi[i];
50966738 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
50976739
5098
- req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
6740
+ req.stats_dma_addr = cpu_to_le64(cpr->stats.hw_stats_map);
50996741
51006742 rc = _hwrm_send_message(bp, &req, sizeof(req),
51016743 HWRM_CMD_TIMEOUT);
....@@ -5114,6 +6756,7 @@
51146756 {
51156757 struct hwrm_func_qcfg_input req = {0};
51166758 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6759
+ u32 min_db_offset = 0;
51176760 u16 flags;
51186761 int rc;
51196762
....@@ -5129,6 +6772,8 @@
51296772 struct bnxt_vf_info *vf = &bp->vf;
51306773
51316774 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
6775
+ } else {
6776
+ bp->pf.registered_vfs = le16_to_cpu(resp->registered_vfs);
51326777 }
51336778 #endif
51346779 flags = le16_to_cpu(resp->flags);
....@@ -5140,6 +6785,8 @@
51406785 }
51416786 if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
51426787 bp->flags |= BNXT_FLAG_MULTI_HOST;
6788
+ if (flags & FUNC_QCFG_RESP_FLAGS_RING_MONITOR_ENABLED)
6789
+ bp->fw_cap |= BNXT_FW_CAP_RING_MONITOR;
51436790
51446791 switch (resp->port_partition_type) {
51456792 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
....@@ -5160,9 +6807,479 @@
51606807 if (!bp->max_mtu)
51616808 bp->max_mtu = BNXT_MAX_MTU;
51626809
6810
+ if (bp->db_size)
6811
+ goto func_qcfg_exit;
6812
+
6813
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
6814
+ if (BNXT_PF(bp))
6815
+ min_db_offset = DB_PF_OFFSET_P5;
6816
+ else
6817
+ min_db_offset = DB_VF_OFFSET_P5;
6818
+ }
6819
+ bp->db_size = PAGE_ALIGN(le16_to_cpu(resp->l2_doorbell_bar_size_kb) *
6820
+ 1024);
6821
+ if (!bp->db_size || bp->db_size > pci_resource_len(bp->pdev, 2) ||
6822
+ bp->db_size <= min_db_offset)
6823
+ bp->db_size = pci_resource_len(bp->pdev, 2);
6824
+
51636825 func_qcfg_exit:
51646826 mutex_unlock(&bp->hwrm_cmd_lock);
51656827 return rc;
6828
+}
6829
+
6830
+static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
6831
+{
6832
+ struct hwrm_func_backing_store_qcaps_input req = {0};
6833
+ struct hwrm_func_backing_store_qcaps_output *resp =
6834
+ bp->hwrm_cmd_resp_addr;
6835
+ int rc;
6836
+
6837
+ if (bp->hwrm_spec_code < 0x10902 || BNXT_VF(bp) || bp->ctx)
6838
+ return 0;
6839
+
6840
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BACKING_STORE_QCAPS, -1, -1);
6841
+ mutex_lock(&bp->hwrm_cmd_lock);
6842
+ rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6843
+ if (!rc) {
6844
+ struct bnxt_ctx_pg_info *ctx_pg;
6845
+ struct bnxt_ctx_mem_info *ctx;
6846
+ int i, tqm_rings;
6847
+
6848
+ ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
6849
+ if (!ctx) {
6850
+ rc = -ENOMEM;
6851
+ goto ctx_err;
6852
+ }
6853
+ ctx->qp_max_entries = le32_to_cpu(resp->qp_max_entries);
6854
+ ctx->qp_min_qp1_entries = le16_to_cpu(resp->qp_min_qp1_entries);
6855
+ ctx->qp_max_l2_entries = le16_to_cpu(resp->qp_max_l2_entries);
6856
+ ctx->qp_entry_size = le16_to_cpu(resp->qp_entry_size);
6857
+ ctx->srq_max_l2_entries = le16_to_cpu(resp->srq_max_l2_entries);
6858
+ ctx->srq_max_entries = le32_to_cpu(resp->srq_max_entries);
6859
+ ctx->srq_entry_size = le16_to_cpu(resp->srq_entry_size);
6860
+ ctx->cq_max_l2_entries = le16_to_cpu(resp->cq_max_l2_entries);
6861
+ ctx->cq_max_entries = le32_to_cpu(resp->cq_max_entries);
6862
+ ctx->cq_entry_size = le16_to_cpu(resp->cq_entry_size);
6863
+ ctx->vnic_max_vnic_entries =
6864
+ le16_to_cpu(resp->vnic_max_vnic_entries);
6865
+ ctx->vnic_max_ring_table_entries =
6866
+ le16_to_cpu(resp->vnic_max_ring_table_entries);
6867
+ ctx->vnic_entry_size = le16_to_cpu(resp->vnic_entry_size);
6868
+ ctx->stat_max_entries = le32_to_cpu(resp->stat_max_entries);
6869
+ ctx->stat_entry_size = le16_to_cpu(resp->stat_entry_size);
6870
+ ctx->tqm_entry_size = le16_to_cpu(resp->tqm_entry_size);
6871
+ ctx->tqm_min_entries_per_ring =
6872
+ le32_to_cpu(resp->tqm_min_entries_per_ring);
6873
+ ctx->tqm_max_entries_per_ring =
6874
+ le32_to_cpu(resp->tqm_max_entries_per_ring);
6875
+ ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
6876
+ if (!ctx->tqm_entries_multiple)
6877
+ ctx->tqm_entries_multiple = 1;
6878
+ ctx->mrav_max_entries = le32_to_cpu(resp->mrav_max_entries);
6879
+ ctx->mrav_entry_size = le16_to_cpu(resp->mrav_entry_size);
6880
+ ctx->mrav_num_entries_units =
6881
+ le16_to_cpu(resp->mrav_num_entries_units);
6882
+ ctx->tim_entry_size = le16_to_cpu(resp->tim_entry_size);
6883
+ ctx->tim_max_entries = le32_to_cpu(resp->tim_max_entries);
6884
+ ctx->ctx_kind_initializer = resp->ctx_kind_initializer;
6885
+ ctx->tqm_fp_rings_count = resp->tqm_fp_rings_count;
6886
+ if (!ctx->tqm_fp_rings_count)
6887
+ ctx->tqm_fp_rings_count = bp->max_q;
6888
+ else if (ctx->tqm_fp_rings_count > BNXT_MAX_TQM_FP_RINGS)
6889
+ ctx->tqm_fp_rings_count = BNXT_MAX_TQM_FP_RINGS;
6890
+
6891
+ tqm_rings = ctx->tqm_fp_rings_count + BNXT_MAX_TQM_SP_RINGS;
6892
+ ctx_pg = kcalloc(tqm_rings, sizeof(*ctx_pg), GFP_KERNEL);
6893
+ if (!ctx_pg) {
6894
+ kfree(ctx);
6895
+ rc = -ENOMEM;
6896
+ goto ctx_err;
6897
+ }
6898
+ for (i = 0; i < tqm_rings; i++, ctx_pg++)
6899
+ ctx->tqm_mem[i] = ctx_pg;
6900
+ bp->ctx = ctx;
6901
+ } else {
6902
+ rc = 0;
6903
+ }
6904
+ctx_err:
6905
+ mutex_unlock(&bp->hwrm_cmd_lock);
6906
+ return rc;
6907
+}
6908
+
6909
+static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem, u8 *pg_attr,
6910
+ __le64 *pg_dir)
6911
+{
6912
+ BNXT_SET_CTX_PAGE_ATTR(*pg_attr);
6913
+ if (rmem->depth >= 1) {
6914
+ if (rmem->depth == 2)
6915
+ *pg_attr |= 2;
6916
+ else
6917
+ *pg_attr |= 1;
6918
+ *pg_dir = cpu_to_le64(rmem->pg_tbl_map);
6919
+ } else {
6920
+ *pg_dir = cpu_to_le64(rmem->dma_arr[0]);
6921
+ }
6922
+}
6923
+
6924
+#define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \
6925
+ (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \
6926
+ FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \
6927
+ FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \
6928
+ FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \
6929
+ FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT)
6930
+
6931
+static int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, u32 enables)
6932
+{
6933
+ struct hwrm_func_backing_store_cfg_input req = {0};
6934
+ struct bnxt_ctx_mem_info *ctx = bp->ctx;
6935
+ struct bnxt_ctx_pg_info *ctx_pg;
6936
+ __le32 *num_entries;
6937
+ __le64 *pg_dir;
6938
+ u32 flags = 0;
6939
+ u8 *pg_attr;
6940
+ u32 ena;
6941
+ int i;
6942
+
6943
+ if (!ctx)
6944
+ return 0;
6945
+
6946
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BACKING_STORE_CFG, -1, -1);
6947
+ req.enables = cpu_to_le32(enables);
6948
+
6949
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP) {
6950
+ ctx_pg = &ctx->qp_mem;
6951
+ req.qp_num_entries = cpu_to_le32(ctx_pg->entries);
6952
+ req.qp_num_qp1_entries = cpu_to_le16(ctx->qp_min_qp1_entries);
6953
+ req.qp_num_l2_entries = cpu_to_le16(ctx->qp_max_l2_entries);
6954
+ req.qp_entry_size = cpu_to_le16(ctx->qp_entry_size);
6955
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
6956
+ &req.qpc_pg_size_qpc_lvl,
6957
+ &req.qpc_page_dir);
6958
+ }
6959
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ) {
6960
+ ctx_pg = &ctx->srq_mem;
6961
+ req.srq_num_entries = cpu_to_le32(ctx_pg->entries);
6962
+ req.srq_num_l2_entries = cpu_to_le16(ctx->srq_max_l2_entries);
6963
+ req.srq_entry_size = cpu_to_le16(ctx->srq_entry_size);
6964
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
6965
+ &req.srq_pg_size_srq_lvl,
6966
+ &req.srq_page_dir);
6967
+ }
6968
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ) {
6969
+ ctx_pg = &ctx->cq_mem;
6970
+ req.cq_num_entries = cpu_to_le32(ctx_pg->entries);
6971
+ req.cq_num_l2_entries = cpu_to_le16(ctx->cq_max_l2_entries);
6972
+ req.cq_entry_size = cpu_to_le16(ctx->cq_entry_size);
6973
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, &req.cq_pg_size_cq_lvl,
6974
+ &req.cq_page_dir);
6975
+ }
6976
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC) {
6977
+ ctx_pg = &ctx->vnic_mem;
6978
+ req.vnic_num_vnic_entries =
6979
+ cpu_to_le16(ctx->vnic_max_vnic_entries);
6980
+ req.vnic_num_ring_table_entries =
6981
+ cpu_to_le16(ctx->vnic_max_ring_table_entries);
6982
+ req.vnic_entry_size = cpu_to_le16(ctx->vnic_entry_size);
6983
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
6984
+ &req.vnic_pg_size_vnic_lvl,
6985
+ &req.vnic_page_dir);
6986
+ }
6987
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT) {
6988
+ ctx_pg = &ctx->stat_mem;
6989
+ req.stat_num_entries = cpu_to_le32(ctx->stat_max_entries);
6990
+ req.stat_entry_size = cpu_to_le16(ctx->stat_entry_size);
6991
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
6992
+ &req.stat_pg_size_stat_lvl,
6993
+ &req.stat_page_dir);
6994
+ }
6995
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV) {
6996
+ ctx_pg = &ctx->mrav_mem;
6997
+ req.mrav_num_entries = cpu_to_le32(ctx_pg->entries);
6998
+ if (ctx->mrav_num_entries_units)
6999
+ flags |=
7000
+ FUNC_BACKING_STORE_CFG_REQ_FLAGS_MRAV_RESERVATION_SPLIT;
7001
+ req.mrav_entry_size = cpu_to_le16(ctx->mrav_entry_size);
7002
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7003
+ &req.mrav_pg_size_mrav_lvl,
7004
+ &req.mrav_page_dir);
7005
+ }
7006
+ if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM) {
7007
+ ctx_pg = &ctx->tim_mem;
7008
+ req.tim_num_entries = cpu_to_le32(ctx_pg->entries);
7009
+ req.tim_entry_size = cpu_to_le16(ctx->tim_entry_size);
7010
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7011
+ &req.tim_pg_size_tim_lvl,
7012
+ &req.tim_page_dir);
7013
+ }
7014
+ for (i = 0, num_entries = &req.tqm_sp_num_entries,
7015
+ pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl,
7016
+ pg_dir = &req.tqm_sp_page_dir,
7017
+ ena = FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP;
7018
+ i < BNXT_MAX_TQM_RINGS;
7019
+ i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
7020
+ if (!(enables & ena))
7021
+ continue;
7022
+
7023
+ req.tqm_entry_size = cpu_to_le16(ctx->tqm_entry_size);
7024
+ ctx_pg = ctx->tqm_mem[i];
7025
+ *num_entries = cpu_to_le32(ctx_pg->entries);
7026
+ bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
7027
+ }
7028
+ req.flags = cpu_to_le32(flags);
7029
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7030
+}
7031
+
7032
+static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
7033
+ struct bnxt_ctx_pg_info *ctx_pg)
7034
+{
7035
+ struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
7036
+
7037
+ rmem->page_size = BNXT_PAGE_SIZE;
7038
+ rmem->pg_arr = ctx_pg->ctx_pg_arr;
7039
+ rmem->dma_arr = ctx_pg->ctx_dma_arr;
7040
+ rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
7041
+ if (rmem->depth >= 1)
7042
+ rmem->flags |= BNXT_RMEM_USE_FULL_PAGE_FLAG;
7043
+ return bnxt_alloc_ring(bp, rmem);
7044
+}
7045
+
7046
+static int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp,
7047
+ struct bnxt_ctx_pg_info *ctx_pg, u32 mem_size,
7048
+ u8 depth, bool use_init_val)
7049
+{
7050
+ struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
7051
+ int rc;
7052
+
7053
+ if (!mem_size)
7054
+ return -EINVAL;
7055
+
7056
+ ctx_pg->nr_pages = DIV_ROUND_UP(mem_size, BNXT_PAGE_SIZE);
7057
+ if (ctx_pg->nr_pages > MAX_CTX_TOTAL_PAGES) {
7058
+ ctx_pg->nr_pages = 0;
7059
+ return -EINVAL;
7060
+ }
7061
+ if (ctx_pg->nr_pages > MAX_CTX_PAGES || depth > 1) {
7062
+ int nr_tbls, i;
7063
+
7064
+ rmem->depth = 2;
7065
+ ctx_pg->ctx_pg_tbl = kcalloc(MAX_CTX_PAGES, sizeof(ctx_pg),
7066
+ GFP_KERNEL);
7067
+ if (!ctx_pg->ctx_pg_tbl)
7068
+ return -ENOMEM;
7069
+ nr_tbls = DIV_ROUND_UP(ctx_pg->nr_pages, MAX_CTX_PAGES);
7070
+ rmem->nr_pages = nr_tbls;
7071
+ rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg);
7072
+ if (rc)
7073
+ return rc;
7074
+ for (i = 0; i < nr_tbls; i++) {
7075
+ struct bnxt_ctx_pg_info *pg_tbl;
7076
+
7077
+ pg_tbl = kzalloc(sizeof(*pg_tbl), GFP_KERNEL);
7078
+ if (!pg_tbl)
7079
+ return -ENOMEM;
7080
+ ctx_pg->ctx_pg_tbl[i] = pg_tbl;
7081
+ rmem = &pg_tbl->ring_mem;
7082
+ rmem->pg_tbl = ctx_pg->ctx_pg_arr[i];
7083
+ rmem->pg_tbl_map = ctx_pg->ctx_dma_arr[i];
7084
+ rmem->depth = 1;
7085
+ rmem->nr_pages = MAX_CTX_PAGES;
7086
+ if (use_init_val)
7087
+ rmem->init_val = bp->ctx->ctx_kind_initializer;
7088
+ if (i == (nr_tbls - 1)) {
7089
+ int rem = ctx_pg->nr_pages % MAX_CTX_PAGES;
7090
+
7091
+ if (rem)
7092
+ rmem->nr_pages = rem;
7093
+ }
7094
+ rc = bnxt_alloc_ctx_mem_blk(bp, pg_tbl);
7095
+ if (rc)
7096
+ break;
7097
+ }
7098
+ } else {
7099
+ rmem->nr_pages = DIV_ROUND_UP(mem_size, BNXT_PAGE_SIZE);
7100
+ if (rmem->nr_pages > 1 || depth)
7101
+ rmem->depth = 1;
7102
+ if (use_init_val)
7103
+ rmem->init_val = bp->ctx->ctx_kind_initializer;
7104
+ rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg);
7105
+ }
7106
+ return rc;
7107
+}
7108
+
7109
+static void bnxt_free_ctx_pg_tbls(struct bnxt *bp,
7110
+ struct bnxt_ctx_pg_info *ctx_pg)
7111
+{
7112
+ struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
7113
+
7114
+ if (rmem->depth > 1 || ctx_pg->nr_pages > MAX_CTX_PAGES ||
7115
+ ctx_pg->ctx_pg_tbl) {
7116
+ int i, nr_tbls = rmem->nr_pages;
7117
+
7118
+ for (i = 0; i < nr_tbls; i++) {
7119
+ struct bnxt_ctx_pg_info *pg_tbl;
7120
+ struct bnxt_ring_mem_info *rmem2;
7121
+
7122
+ pg_tbl = ctx_pg->ctx_pg_tbl[i];
7123
+ if (!pg_tbl)
7124
+ continue;
7125
+ rmem2 = &pg_tbl->ring_mem;
7126
+ bnxt_free_ring(bp, rmem2);
7127
+ ctx_pg->ctx_pg_arr[i] = NULL;
7128
+ kfree(pg_tbl);
7129
+ ctx_pg->ctx_pg_tbl[i] = NULL;
7130
+ }
7131
+ kfree(ctx_pg->ctx_pg_tbl);
7132
+ ctx_pg->ctx_pg_tbl = NULL;
7133
+ }
7134
+ bnxt_free_ring(bp, rmem);
7135
+ ctx_pg->nr_pages = 0;
7136
+}
7137
+
7138
+static void bnxt_free_ctx_mem(struct bnxt *bp)
7139
+{
7140
+ struct bnxt_ctx_mem_info *ctx = bp->ctx;
7141
+ int i;
7142
+
7143
+ if (!ctx)
7144
+ return;
7145
+
7146
+ if (ctx->tqm_mem[0]) {
7147
+ for (i = 0; i < ctx->tqm_fp_rings_count + 1; i++)
7148
+ bnxt_free_ctx_pg_tbls(bp, ctx->tqm_mem[i]);
7149
+ kfree(ctx->tqm_mem[0]);
7150
+ ctx->tqm_mem[0] = NULL;
7151
+ }
7152
+
7153
+ bnxt_free_ctx_pg_tbls(bp, &ctx->tim_mem);
7154
+ bnxt_free_ctx_pg_tbls(bp, &ctx->mrav_mem);
7155
+ bnxt_free_ctx_pg_tbls(bp, &ctx->stat_mem);
7156
+ bnxt_free_ctx_pg_tbls(bp, &ctx->vnic_mem);
7157
+ bnxt_free_ctx_pg_tbls(bp, &ctx->cq_mem);
7158
+ bnxt_free_ctx_pg_tbls(bp, &ctx->srq_mem);
7159
+ bnxt_free_ctx_pg_tbls(bp, &ctx->qp_mem);
7160
+ ctx->flags &= ~BNXT_CTX_FLAG_INITED;
7161
+}
7162
+
7163
+static int bnxt_alloc_ctx_mem(struct bnxt *bp)
7164
+{
7165
+ struct bnxt_ctx_pg_info *ctx_pg;
7166
+ struct bnxt_ctx_mem_info *ctx;
7167
+ u32 mem_size, ena, entries;
7168
+ u32 entries_sp, min;
7169
+ u32 num_mr, num_ah;
7170
+ u32 extra_srqs = 0;
7171
+ u32 extra_qps = 0;
7172
+ u8 pg_lvl = 1;
7173
+ int i, rc;
7174
+
7175
+ rc = bnxt_hwrm_func_backing_store_qcaps(bp);
7176
+ if (rc) {
7177
+ netdev_err(bp->dev, "Failed querying context mem capability, rc = %d.\n",
7178
+ rc);
7179
+ return rc;
7180
+ }
7181
+ ctx = bp->ctx;
7182
+ if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED))
7183
+ return 0;
7184
+
7185
+ if ((bp->flags & BNXT_FLAG_ROCE_CAP) && !is_kdump_kernel()) {
7186
+ pg_lvl = 2;
7187
+ extra_qps = 65536;
7188
+ extra_srqs = 8192;
7189
+ }
7190
+
7191
+ ctx_pg = &ctx->qp_mem;
7192
+ ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries +
7193
+ extra_qps;
7194
+ mem_size = ctx->qp_entry_size * ctx_pg->entries;
7195
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, true);
7196
+ if (rc)
7197
+ return rc;
7198
+
7199
+ ctx_pg = &ctx->srq_mem;
7200
+ ctx_pg->entries = ctx->srq_max_l2_entries + extra_srqs;
7201
+ mem_size = ctx->srq_entry_size * ctx_pg->entries;
7202
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, true);
7203
+ if (rc)
7204
+ return rc;
7205
+
7206
+ ctx_pg = &ctx->cq_mem;
7207
+ ctx_pg->entries = ctx->cq_max_l2_entries + extra_qps * 2;
7208
+ mem_size = ctx->cq_entry_size * ctx_pg->entries;
7209
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, true);
7210
+ if (rc)
7211
+ return rc;
7212
+
7213
+ ctx_pg = &ctx->vnic_mem;
7214
+ ctx_pg->entries = ctx->vnic_max_vnic_entries +
7215
+ ctx->vnic_max_ring_table_entries;
7216
+ mem_size = ctx->vnic_entry_size * ctx_pg->entries;
7217
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, true);
7218
+ if (rc)
7219
+ return rc;
7220
+
7221
+ ctx_pg = &ctx->stat_mem;
7222
+ ctx_pg->entries = ctx->stat_max_entries;
7223
+ mem_size = ctx->stat_entry_size * ctx_pg->entries;
7224
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, true);
7225
+ if (rc)
7226
+ return rc;
7227
+
7228
+ ena = 0;
7229
+ if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
7230
+ goto skip_rdma;
7231
+
7232
+ ctx_pg = &ctx->mrav_mem;
7233
+ /* 128K extra is needed to accommodate static AH context
7234
+ * allocation by f/w.
7235
+ */
7236
+ num_mr = 1024 * 256;
7237
+ num_ah = 1024 * 128;
7238
+ ctx_pg->entries = num_mr + num_ah;
7239
+ mem_size = ctx->mrav_entry_size * ctx_pg->entries;
7240
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 2, true);
7241
+ if (rc)
7242
+ return rc;
7243
+ ena = FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV;
7244
+ if (ctx->mrav_num_entries_units)
7245
+ ctx_pg->entries =
7246
+ ((num_mr / ctx->mrav_num_entries_units) << 16) |
7247
+ (num_ah / ctx->mrav_num_entries_units);
7248
+
7249
+ ctx_pg = &ctx->tim_mem;
7250
+ ctx_pg->entries = ctx->qp_mem.entries;
7251
+ mem_size = ctx->tim_entry_size * ctx_pg->entries;
7252
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, false);
7253
+ if (rc)
7254
+ return rc;
7255
+ ena |= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM;
7256
+
7257
+skip_rdma:
7258
+ min = ctx->tqm_min_entries_per_ring;
7259
+ entries_sp = ctx->vnic_max_vnic_entries + ctx->qp_max_l2_entries +
7260
+ 2 * (extra_qps + ctx->qp_min_qp1_entries) + min;
7261
+ entries_sp = roundup(entries_sp, ctx->tqm_entries_multiple);
7262
+ entries = ctx->qp_max_l2_entries + 2 * (extra_qps + ctx->qp_min_qp1_entries);
7263
+ entries = roundup(entries, ctx->tqm_entries_multiple);
7264
+ entries = clamp_t(u32, entries, min, ctx->tqm_max_entries_per_ring);
7265
+ for (i = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
7266
+ ctx_pg = ctx->tqm_mem[i];
7267
+ ctx_pg->entries = i ? entries : entries_sp;
7268
+ mem_size = ctx->tqm_entry_size * ctx_pg->entries;
7269
+ rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, false);
7270
+ if (rc)
7271
+ return rc;
7272
+ ena |= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP << i;
7273
+ }
7274
+ ena |= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES;
7275
+ rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
7276
+ if (rc) {
7277
+ netdev_err(bp->dev, "Failed configuring context mem, rc = %d.\n",
7278
+ rc);
7279
+ return rc;
7280
+ }
7281
+ ctx->flags |= BNXT_CTX_FLAG_INITED;
7282
+ return 0;
51667283 }
51677284
51687285 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
....@@ -5176,11 +7293,10 @@
51767293 req.fid = cpu_to_le16(0xffff);
51777294
51787295 mutex_lock(&bp->hwrm_cmd_lock);
5179
- rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5180
- if (rc) {
5181
- rc = -EIO;
7296
+ rc = _hwrm_send_message_silent(bp, &req, sizeof(req),
7297
+ HWRM_CMD_TIMEOUT);
7298
+ if (rc)
51827299 goto hwrm_func_resc_qcaps_exit;
5183
- }
51847300
51857301 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
51867302 if (!all)
....@@ -5203,6 +7319,13 @@
52037319 hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
52047320 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
52057321
7322
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
7323
+ u16 max_msix = le16_to_cpu(resp->max_msix);
7324
+
7325
+ hw_resc->max_nqs = max_msix;
7326
+ hw_resc->max_hw_ring_grps = hw_resc->max_rx_rings;
7327
+ }
7328
+
52067329 if (BNXT_PF(bp)) {
52077330 struct bnxt_pf_info *pf = &bp->pf;
52087331
....@@ -5222,7 +7345,7 @@
52227345 struct hwrm_func_qcaps_input req = {0};
52237346 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
52247347 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5225
- u32 flags;
7348
+ u32 flags, flags_ext;
52267349
52277350 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
52287351 req.fid = cpu_to_le16(0xffff);
....@@ -5237,9 +7360,26 @@
52377360 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
52387361 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
52397362 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
7363
+ if (flags & FUNC_QCAPS_RESP_FLAGS_PCIE_STATS_SUPPORTED)
7364
+ bp->fw_cap |= BNXT_FW_CAP_PCIE_STATS_SUPPORTED;
7365
+ if (flags & FUNC_QCAPS_RESP_FLAGS_HOT_RESET_CAPABLE)
7366
+ bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
7367
+ if (flags & FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED)
7368
+ bp->fw_cap |= BNXT_FW_CAP_EXT_STATS_SUPPORTED;
7369
+ if (flags & FUNC_QCAPS_RESP_FLAGS_ERROR_RECOVERY_CAPABLE)
7370
+ bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
7371
+ if (flags & FUNC_QCAPS_RESP_FLAGS_ERR_RECOVER_RELOAD)
7372
+ bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
7373
+ if (!(flags & FUNC_QCAPS_RESP_FLAGS_VLAN_ACCELERATION_TX_DISABLED))
7374
+ bp->fw_cap |= BNXT_FW_CAP_VLAN_TX_INSERT;
7375
+
7376
+ flags_ext = le32_to_cpu(resp->flags_ext);
7377
+ if (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_EXT_HW_STATS_SUPPORTED)
7378
+ bp->fw_cap |= BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED;
52407379
52417380 bp->tx_push_thresh = 0;
5242
- if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)
7381
+ if ((flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) &&
7382
+ BNXT_FW_MAJ(bp) > 217)
52437383 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
52447384
52457385 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
....@@ -5267,6 +7407,7 @@
52677407 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
52687408 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
52697409 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
7410
+ bp->flags &= ~BNXT_FLAG_WOL_CAP;
52707411 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
52717412 bp->flags |= BNXT_FLAG_WOL_CAP;
52727413 } else {
....@@ -5283,6 +7424,8 @@
52837424 return rc;
52847425 }
52857426
7427
+static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp);
7428
+
52867429 static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
52877430 {
52887431 int rc;
....@@ -5290,12 +7433,206 @@
52907433 rc = __bnxt_hwrm_func_qcaps(bp);
52917434 if (rc)
52927435 return rc;
7436
+ rc = bnxt_hwrm_queue_qportcfg(bp);
7437
+ if (rc) {
7438
+ netdev_err(bp->dev, "hwrm query qportcfg failure rc: %d\n", rc);
7439
+ return rc;
7440
+ }
52937441 if (bp->hwrm_spec_code >= 0x10803) {
7442
+ rc = bnxt_alloc_ctx_mem(bp);
7443
+ if (rc)
7444
+ return rc;
52947445 rc = bnxt_hwrm_func_resc_qcaps(bp, true);
52957446 if (!rc)
52967447 bp->fw_cap |= BNXT_FW_CAP_NEW_RM;
52977448 }
52987449 return 0;
7450
+}
7451
+
7452
+static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt *bp)
7453
+{
7454
+ struct hwrm_cfa_adv_flow_mgnt_qcaps_input req = {0};
7455
+ struct hwrm_cfa_adv_flow_mgnt_qcaps_output *resp;
7456
+ int rc = 0;
7457
+ u32 flags;
7458
+
7459
+ if (!(bp->fw_cap & BNXT_FW_CAP_CFA_ADV_FLOW))
7460
+ return 0;
7461
+
7462
+ resp = bp->hwrm_cmd_resp_addr;
7463
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_ADV_FLOW_MGNT_QCAPS, -1, -1);
7464
+
7465
+ mutex_lock(&bp->hwrm_cmd_lock);
7466
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7467
+ if (rc)
7468
+ goto hwrm_cfa_adv_qcaps_exit;
7469
+
7470
+ flags = le32_to_cpu(resp->flags);
7471
+ if (flags &
7472
+ CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_V2_SUPPORTED)
7473
+ bp->fw_cap |= BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2;
7474
+
7475
+hwrm_cfa_adv_qcaps_exit:
7476
+ mutex_unlock(&bp->hwrm_cmd_lock);
7477
+ return rc;
7478
+}
7479
+
7480
+static int __bnxt_alloc_fw_health(struct bnxt *bp)
7481
+{
7482
+ if (bp->fw_health)
7483
+ return 0;
7484
+
7485
+ bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL);
7486
+ if (!bp->fw_health)
7487
+ return -ENOMEM;
7488
+
7489
+ return 0;
7490
+}
7491
+
7492
+static int bnxt_alloc_fw_health(struct bnxt *bp)
7493
+{
7494
+ int rc;
7495
+
7496
+ if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) &&
7497
+ !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
7498
+ return 0;
7499
+
7500
+ rc = __bnxt_alloc_fw_health(bp);
7501
+ if (rc) {
7502
+ bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET;
7503
+ bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
7504
+ return rc;
7505
+ }
7506
+
7507
+ return 0;
7508
+}
7509
+
7510
+static void __bnxt_map_fw_health_reg(struct bnxt *bp, u32 reg)
7511
+{
7512
+ writel(reg & BNXT_GRC_BASE_MASK, bp->bar0 +
7513
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT +
7514
+ BNXT_FW_HEALTH_WIN_MAP_OFF);
7515
+}
7516
+
7517
+static void bnxt_try_map_fw_health_reg(struct bnxt *bp)
7518
+{
7519
+ void __iomem *hs;
7520
+ u32 status_loc;
7521
+ u32 reg_type;
7522
+ u32 sig;
7523
+
7524
+ __bnxt_map_fw_health_reg(bp, HCOMM_STATUS_STRUCT_LOC);
7525
+ hs = bp->bar0 + BNXT_FW_HEALTH_WIN_OFF(HCOMM_STATUS_STRUCT_LOC);
7526
+
7527
+ sig = readl(hs + offsetof(struct hcomm_status, sig_ver));
7528
+ if ((sig & HCOMM_STATUS_SIGNATURE_MASK) != HCOMM_STATUS_SIGNATURE_VAL) {
7529
+ if (bp->fw_health)
7530
+ bp->fw_health->status_reliable = false;
7531
+ return;
7532
+ }
7533
+
7534
+ if (__bnxt_alloc_fw_health(bp)) {
7535
+ netdev_warn(bp->dev, "no memory for firmware status checks\n");
7536
+ return;
7537
+ }
7538
+
7539
+ status_loc = readl(hs + offsetof(struct hcomm_status, fw_status_loc));
7540
+ bp->fw_health->regs[BNXT_FW_HEALTH_REG] = status_loc;
7541
+ reg_type = BNXT_FW_HEALTH_REG_TYPE(status_loc);
7542
+ if (reg_type == BNXT_FW_HEALTH_REG_TYPE_GRC) {
7543
+ __bnxt_map_fw_health_reg(bp, status_loc);
7544
+ bp->fw_health->mapped_regs[BNXT_FW_HEALTH_REG] =
7545
+ BNXT_FW_HEALTH_WIN_OFF(status_loc);
7546
+ }
7547
+
7548
+ bp->fw_health->status_reliable = true;
7549
+}
7550
+
7551
+static int bnxt_map_fw_health_regs(struct bnxt *bp)
7552
+{
7553
+ struct bnxt_fw_health *fw_health = bp->fw_health;
7554
+ u32 reg_base = 0xffffffff;
7555
+ int i;
7556
+
7557
+ /* Only pre-map the monitoring GRC registers using window 3 */
7558
+ for (i = 0; i < 4; i++) {
7559
+ u32 reg = fw_health->regs[i];
7560
+
7561
+ if (BNXT_FW_HEALTH_REG_TYPE(reg) != BNXT_FW_HEALTH_REG_TYPE_GRC)
7562
+ continue;
7563
+ if (reg_base == 0xffffffff)
7564
+ reg_base = reg & BNXT_GRC_BASE_MASK;
7565
+ if ((reg & BNXT_GRC_BASE_MASK) != reg_base)
7566
+ return -ERANGE;
7567
+ fw_health->mapped_regs[i] = BNXT_FW_HEALTH_WIN_OFF(reg);
7568
+ }
7569
+ if (reg_base == 0xffffffff)
7570
+ return 0;
7571
+
7572
+ __bnxt_map_fw_health_reg(bp, reg_base);
7573
+ return 0;
7574
+}
7575
+
7576
+static int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
7577
+{
7578
+ struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
7579
+ struct bnxt_fw_health *fw_health = bp->fw_health;
7580
+ struct hwrm_error_recovery_qcfg_input req = {0};
7581
+ int rc, i;
7582
+
7583
+ if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
7584
+ return 0;
7585
+
7586
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_ERROR_RECOVERY_QCFG, -1, -1);
7587
+ mutex_lock(&bp->hwrm_cmd_lock);
7588
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7589
+ if (rc)
7590
+ goto err_recovery_out;
7591
+ fw_health->flags = le32_to_cpu(resp->flags);
7592
+ if ((fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) &&
7593
+ !(bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL)) {
7594
+ rc = -EINVAL;
7595
+ goto err_recovery_out;
7596
+ }
7597
+ fw_health->polling_dsecs = le32_to_cpu(resp->driver_polling_freq);
7598
+ fw_health->master_func_wait_dsecs =
7599
+ le32_to_cpu(resp->master_func_wait_period);
7600
+ fw_health->normal_func_wait_dsecs =
7601
+ le32_to_cpu(resp->normal_func_wait_period);
7602
+ fw_health->post_reset_wait_dsecs =
7603
+ le32_to_cpu(resp->master_func_wait_period_after_reset);
7604
+ fw_health->post_reset_max_wait_dsecs =
7605
+ le32_to_cpu(resp->max_bailout_time_after_reset);
7606
+ fw_health->regs[BNXT_FW_HEALTH_REG] =
7607
+ le32_to_cpu(resp->fw_health_status_reg);
7608
+ fw_health->regs[BNXT_FW_HEARTBEAT_REG] =
7609
+ le32_to_cpu(resp->fw_heartbeat_reg);
7610
+ fw_health->regs[BNXT_FW_RESET_CNT_REG] =
7611
+ le32_to_cpu(resp->fw_reset_cnt_reg);
7612
+ fw_health->regs[BNXT_FW_RESET_INPROG_REG] =
7613
+ le32_to_cpu(resp->reset_inprogress_reg);
7614
+ fw_health->fw_reset_inprog_reg_mask =
7615
+ le32_to_cpu(resp->reset_inprogress_reg_mask);
7616
+ fw_health->fw_reset_seq_cnt = resp->reg_array_cnt;
7617
+ if (fw_health->fw_reset_seq_cnt >= 16) {
7618
+ rc = -EINVAL;
7619
+ goto err_recovery_out;
7620
+ }
7621
+ for (i = 0; i < fw_health->fw_reset_seq_cnt; i++) {
7622
+ fw_health->fw_reset_seq_regs[i] =
7623
+ le32_to_cpu(resp->reset_reg[i]);
7624
+ fw_health->fw_reset_seq_vals[i] =
7625
+ le32_to_cpu(resp->reset_reg_val[i]);
7626
+ fw_health->fw_reset_seq_delay_msec[i] =
7627
+ resp->delay_after_reset[i];
7628
+ }
7629
+err_recovery_out:
7630
+ mutex_unlock(&bp->hwrm_cmd_lock);
7631
+ if (!rc)
7632
+ rc = bnxt_map_fw_health_regs(bp);
7633
+ if (rc)
7634
+ bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
7635
+ return rc;
52997636 }
53007637
53017638 static int bnxt_hwrm_func_reset(struct bnxt *bp)
....@@ -5306,6 +7643,16 @@
53067643 req.enables = 0;
53077644
53087645 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
7646
+}
7647
+
7648
+static void bnxt_nvm_cfg_ver_get(struct bnxt *bp)
7649
+{
7650
+ struct hwrm_nvm_get_dev_info_output nvm_info;
7651
+
7652
+ if (!bnxt_hwrm_nvm_get_dev_info(bp, &nvm_info))
7653
+ snprintf(bp->nvm_cfg_ver, FW_VER_STR_LEN, "%d.%d.%d",
7654
+ nvm_info.nvm_cfg_ver_maj, nvm_info.nvm_cfg_ver_min,
7655
+ nvm_info.nvm_cfg_ver_upd);
53097656 }
53107657
53117658 static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
....@@ -5335,13 +7682,15 @@
53357682 no_rdma = !(bp->flags & BNXT_FLAG_ROCE_CAP);
53367683 qptr = &resp->queue_id0;
53377684 for (i = 0, j = 0; i < bp->max_tc; i++) {
5338
- bp->q_info[j].queue_id = *qptr++;
7685
+ bp->q_info[j].queue_id = *qptr;
7686
+ bp->q_ids[i] = *qptr++;
53397687 bp->q_info[j].queue_profile = *qptr++;
53407688 bp->tc_to_qidx[j] = j;
53417689 if (!BNXT_CNPQ(bp->q_info[j].queue_profile) ||
53427690 (no_rdma && BNXT_PF(bp)))
53437691 j++;
53447692 }
7693
+ bp->max_q = bp->max_tc;
53457694 bp->max_tc = max_t(u8, j, 1);
53467695
53477696 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
....@@ -5355,20 +7704,31 @@
53557704 return rc;
53567705 }
53577706
5358
-static int bnxt_hwrm_ver_get(struct bnxt *bp)
7707
+static int __bnxt_hwrm_ver_get(struct bnxt *bp, bool silent)
53597708 {
5360
- int rc;
53617709 struct hwrm_ver_get_input req = {0};
5362
- struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
5363
- u32 dev_caps_cfg;
7710
+ int rc;
53647711
5365
- bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
53667712 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
53677713 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
53687714 req.hwrm_intf_min = HWRM_VERSION_MINOR;
53697715 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
7716
+
7717
+ rc = bnxt_hwrm_do_send_msg(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT,
7718
+ silent);
7719
+ return rc;
7720
+}
7721
+
7722
+static int bnxt_hwrm_ver_get(struct bnxt *bp)
7723
+{
7724
+ struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
7725
+ u16 fw_maj, fw_min, fw_bld, fw_rsv;
7726
+ u32 dev_caps_cfg, hwrm_ver;
7727
+ int rc, len;
7728
+
7729
+ bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
53707730 mutex_lock(&bp->hwrm_cmd_lock);
5371
- rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7731
+ rc = __bnxt_hwrm_ver_get(bp, false);
53727732 if (rc)
53737733 goto hwrm_ver_get_exit;
53747734
....@@ -5383,18 +7743,58 @@
53837743 resp->hwrm_intf_upd_8b);
53847744 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
53857745 }
5386
- snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d",
5387
- resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b,
5388
- resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b);
7746
+
7747
+ hwrm_ver = HWRM_VERSION_MAJOR << 16 | HWRM_VERSION_MINOR << 8 |
7748
+ HWRM_VERSION_UPDATE;
7749
+
7750
+ if (bp->hwrm_spec_code > hwrm_ver)
7751
+ snprintf(bp->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
7752
+ HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR,
7753
+ HWRM_VERSION_UPDATE);
7754
+ else
7755
+ snprintf(bp->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
7756
+ resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
7757
+ resp->hwrm_intf_upd_8b);
7758
+
7759
+ fw_maj = le16_to_cpu(resp->hwrm_fw_major);
7760
+ if (bp->hwrm_spec_code > 0x10803 && fw_maj) {
7761
+ fw_min = le16_to_cpu(resp->hwrm_fw_minor);
7762
+ fw_bld = le16_to_cpu(resp->hwrm_fw_build);
7763
+ fw_rsv = le16_to_cpu(resp->hwrm_fw_patch);
7764
+ len = FW_VER_STR_LEN;
7765
+ } else {
7766
+ fw_maj = resp->hwrm_fw_maj_8b;
7767
+ fw_min = resp->hwrm_fw_min_8b;
7768
+ fw_bld = resp->hwrm_fw_bld_8b;
7769
+ fw_rsv = resp->hwrm_fw_rsvd_8b;
7770
+ len = BC_HWRM_STR_LEN;
7771
+ }
7772
+ bp->fw_ver_code = BNXT_FW_VER_CODE(fw_maj, fw_min, fw_bld, fw_rsv);
7773
+ snprintf(bp->fw_ver_str, len, "%d.%d.%d.%d", fw_maj, fw_min, fw_bld,
7774
+ fw_rsv);
7775
+
7776
+ if (strlen(resp->active_pkg_name)) {
7777
+ int fw_ver_len = strlen(bp->fw_ver_str);
7778
+
7779
+ snprintf(bp->fw_ver_str + fw_ver_len,
7780
+ FW_VER_STR_LEN - fw_ver_len - 1, "/pkg %s",
7781
+ resp->active_pkg_name);
7782
+ bp->fw_cap |= BNXT_FW_CAP_PKG_VER;
7783
+ }
53897784
53907785 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
53917786 if (!bp->hwrm_cmd_timeout)
53927787 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
53937788
5394
- if (resp->hwrm_intf_maj_8b >= 1)
7789
+ if (resp->hwrm_intf_maj_8b >= 1) {
53957790 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
7791
+ bp->hwrm_max_ext_req_len = le16_to_cpu(resp->max_ext_req_len);
7792
+ }
7793
+ if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
7794
+ bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
53967795
53977796 bp->chip_num = le16_to_cpu(resp->chip_num);
7797
+ bp->chip_rev = resp->chip_rev;
53987798 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
53997799 !resp->chip_metal)
54007800 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
....@@ -5403,6 +7803,21 @@
54037803 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
54047804 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
54057805 bp->fw_cap |= BNXT_FW_CAP_SHORT_CMD;
7806
+
7807
+ if (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED)
7808
+ bp->fw_cap |= BNXT_FW_CAP_KONG_MB_CHNL;
7809
+
7810
+ if (dev_caps_cfg &
7811
+ VER_GET_RESP_DEV_CAPS_CFG_FLOW_HANDLE_64BIT_SUPPORTED)
7812
+ bp->fw_cap |= BNXT_FW_CAP_OVS_64BIT_HANDLE;
7813
+
7814
+ if (dev_caps_cfg &
7815
+ VER_GET_RESP_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
7816
+ bp->fw_cap |= BNXT_FW_CAP_TRUSTED_VF;
7817
+
7818
+ if (dev_caps_cfg &
7819
+ VER_GET_RESP_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED)
7820
+ bp->fw_cap |= BNXT_FW_CAP_CFA_ADV_FLOW;
54067821
54077822 hwrm_ver_get_exit:
54087823 mutex_unlock(&bp->hwrm_cmd_lock);
....@@ -5430,50 +7845,194 @@
54307845 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
54317846 }
54327847
5433
-static int bnxt_hwrm_port_qstats(struct bnxt *bp)
7848
+static void bnxt_add_one_ctr(u64 hw, u64 *sw, u64 mask)
54347849 {
5435
- int rc;
7850
+ u64 sw_tmp;
7851
+
7852
+ hw &= mask;
7853
+ sw_tmp = (*sw & ~mask) | hw;
7854
+ if (hw < (*sw & mask))
7855
+ sw_tmp += mask + 1;
7856
+ WRITE_ONCE(*sw, sw_tmp);
7857
+}
7858
+
7859
+static void __bnxt_accumulate_stats(__le64 *hw_stats, u64 *sw_stats, u64 *masks,
7860
+ int count, bool ignore_zero)
7861
+{
7862
+ int i;
7863
+
7864
+ for (i = 0; i < count; i++) {
7865
+ u64 hw = le64_to_cpu(READ_ONCE(hw_stats[i]));
7866
+
7867
+ if (ignore_zero && !hw)
7868
+ continue;
7869
+
7870
+ if (masks[i] == -1ULL)
7871
+ sw_stats[i] = hw;
7872
+ else
7873
+ bnxt_add_one_ctr(hw, &sw_stats[i], masks[i]);
7874
+ }
7875
+}
7876
+
7877
+static void bnxt_accumulate_stats(struct bnxt_stats_mem *stats)
7878
+{
7879
+ if (!stats->hw_stats)
7880
+ return;
7881
+
7882
+ __bnxt_accumulate_stats(stats->hw_stats, stats->sw_stats,
7883
+ stats->hw_masks, stats->len / 8, false);
7884
+}
7885
+
7886
+static void bnxt_accumulate_all_stats(struct bnxt *bp)
7887
+{
7888
+ struct bnxt_stats_mem *ring0_stats;
7889
+ bool ignore_zero = false;
7890
+ int i;
7891
+
7892
+ /* Chip bug. Counter intermittently becomes 0. */
7893
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
7894
+ ignore_zero = true;
7895
+
7896
+ for (i = 0; i < bp->cp_nr_rings; i++) {
7897
+ struct bnxt_napi *bnapi = bp->bnapi[i];
7898
+ struct bnxt_cp_ring_info *cpr;
7899
+ struct bnxt_stats_mem *stats;
7900
+
7901
+ cpr = &bnapi->cp_ring;
7902
+ stats = &cpr->stats;
7903
+ if (!i)
7904
+ ring0_stats = stats;
7905
+ __bnxt_accumulate_stats(stats->hw_stats, stats->sw_stats,
7906
+ ring0_stats->hw_masks,
7907
+ ring0_stats->len / 8, ignore_zero);
7908
+ }
7909
+ if (bp->flags & BNXT_FLAG_PORT_STATS) {
7910
+ struct bnxt_stats_mem *stats = &bp->port_stats;
7911
+ __le64 *hw_stats = stats->hw_stats;
7912
+ u64 *sw_stats = stats->sw_stats;
7913
+ u64 *masks = stats->hw_masks;
7914
+ int cnt;
7915
+
7916
+ cnt = sizeof(struct rx_port_stats) / 8;
7917
+ __bnxt_accumulate_stats(hw_stats, sw_stats, masks, cnt, false);
7918
+
7919
+ hw_stats += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
7920
+ sw_stats += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
7921
+ masks += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
7922
+ cnt = sizeof(struct tx_port_stats) / 8;
7923
+ __bnxt_accumulate_stats(hw_stats, sw_stats, masks, cnt, false);
7924
+ }
7925
+ if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
7926
+ bnxt_accumulate_stats(&bp->rx_port_stats_ext);
7927
+ bnxt_accumulate_stats(&bp->tx_port_stats_ext);
7928
+ }
7929
+}
7930
+
7931
+static int bnxt_hwrm_port_qstats(struct bnxt *bp, u8 flags)
7932
+{
54367933 struct bnxt_pf_info *pf = &bp->pf;
54377934 struct hwrm_port_qstats_input req = {0};
54387935
54397936 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
54407937 return 0;
54417938
7939
+ if (flags && !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED))
7940
+ return -EOPNOTSUPP;
7941
+
7942
+ req.flags = flags;
54427943 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
54437944 req.port_id = cpu_to_le16(pf->port_id);
5444
- req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
5445
- req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
5446
- rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5447
- return rc;
7945
+ req.tx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map +
7946
+ BNXT_TX_PORT_STATS_BYTE_OFFSET);
7947
+ req.rx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map);
7948
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
54487949 }
54497950
5450
-static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
7951
+static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp, u8 flags)
54517952 {
7953
+ struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
7954
+ struct hwrm_queue_pri2cos_qcfg_input req2 = {0};
54527955 struct hwrm_port_qstats_ext_input req = {0};
54537956 struct bnxt_pf_info *pf = &bp->pf;
7957
+ u32 tx_stat_size;
7958
+ int rc;
54547959
54557960 if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
54567961 return 0;
54577962
7963
+ if (flags && !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED))
7964
+ return -EOPNOTSUPP;
7965
+
54587966 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
7967
+ req.flags = flags;
54597968 req.port_id = cpu_to_le16(pf->port_id);
54607969 req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
5461
- req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map);
5462
- return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7970
+ req.rx_stat_host_addr = cpu_to_le64(bp->rx_port_stats_ext.hw_stats_map);
7971
+ tx_stat_size = bp->tx_port_stats_ext.hw_stats ?
7972
+ sizeof(struct tx_port_stats_ext) : 0;
7973
+ req.tx_stat_size = cpu_to_le16(tx_stat_size);
7974
+ req.tx_stat_host_addr = cpu_to_le64(bp->tx_port_stats_ext.hw_stats_map);
7975
+ mutex_lock(&bp->hwrm_cmd_lock);
7976
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
7977
+ if (!rc) {
7978
+ bp->fw_rx_stats_ext_size = le16_to_cpu(resp->rx_stat_size) / 8;
7979
+ bp->fw_tx_stats_ext_size = tx_stat_size ?
7980
+ le16_to_cpu(resp->tx_stat_size) / 8 : 0;
7981
+ } else {
7982
+ bp->fw_rx_stats_ext_size = 0;
7983
+ bp->fw_tx_stats_ext_size = 0;
7984
+ }
7985
+ if (flags)
7986
+ goto qstats_done;
7987
+
7988
+ if (bp->fw_tx_stats_ext_size <=
7989
+ offsetof(struct tx_port_stats_ext, pfc_pri0_tx_duration_us) / 8) {
7990
+ mutex_unlock(&bp->hwrm_cmd_lock);
7991
+ bp->pri2cos_valid = 0;
7992
+ return rc;
7993
+ }
7994
+
7995
+ bnxt_hwrm_cmd_hdr_init(bp, &req2, HWRM_QUEUE_PRI2COS_QCFG, -1, -1);
7996
+ req2.flags = cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN);
7997
+
7998
+ rc = _hwrm_send_message(bp, &req2, sizeof(req2), HWRM_CMD_TIMEOUT);
7999
+ if (!rc) {
8000
+ struct hwrm_queue_pri2cos_qcfg_output *resp2;
8001
+ u8 *pri2cos;
8002
+ int i, j;
8003
+
8004
+ resp2 = bp->hwrm_cmd_resp_addr;
8005
+ pri2cos = &resp2->pri0_cos_queue_id;
8006
+ for (i = 0; i < 8; i++) {
8007
+ u8 queue_id = pri2cos[i];
8008
+ u8 queue_idx;
8009
+
8010
+ /* Per port queue IDs start from 0, 10, 20, etc */
8011
+ queue_idx = queue_id % 10;
8012
+ if (queue_idx > BNXT_MAX_QUEUE) {
8013
+ bp->pri2cos_valid = false;
8014
+ goto qstats_done;
8015
+ }
8016
+ for (j = 0; j < bp->max_q; j++) {
8017
+ if (bp->q_ids[j] == queue_id)
8018
+ bp->pri2cos_idx[i] = queue_idx;
8019
+ }
8020
+ }
8021
+ bp->pri2cos_valid = 1;
8022
+ }
8023
+qstats_done:
8024
+ mutex_unlock(&bp->hwrm_cmd_lock);
8025
+ return rc;
54638026 }
54648027
54658028 static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
54668029 {
5467
- if (bp->vxlan_port_cnt) {
8030
+ if (bp->vxlan_fw_dst_port_id != INVALID_HW_RING_ID)
54688031 bnxt_hwrm_tunnel_dst_port_free(
54698032 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
5470
- }
5471
- bp->vxlan_port_cnt = 0;
5472
- if (bp->nge_port_cnt) {
8033
+ if (bp->nge_fw_dst_port_id != INVALID_HW_RING_ID)
54738034 bnxt_hwrm_tunnel_dst_port_free(
54748035 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
5475
- }
5476
- bp->nge_port_cnt = 0;
54778036 }
54788037
54798038 static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
....@@ -5483,6 +8042,8 @@
54838042
54848043 if (set_tpa)
54858044 tpa_flags = bp->flags & BNXT_FLAG_TPA;
8045
+ else if (BNXT_NO_FW_ACCESS(bp))
8046
+ return 0;
54868047 for (i = 0; i < bp->nr_vnics; i++) {
54878048 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
54888049 if (rc) {
....@@ -5502,19 +8063,29 @@
55028063 bnxt_hwrm_vnic_set_rss(bp, i, false);
55038064 }
55048065
5505
-static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
5506
- bool irq_re_init)
8066
+static void bnxt_clear_vnic(struct bnxt *bp)
55078067 {
5508
- if (bp->vnic_info) {
5509
- bnxt_hwrm_clear_vnic_filter(bp);
8068
+ if (!bp->vnic_info)
8069
+ return;
8070
+
8071
+ bnxt_hwrm_clear_vnic_filter(bp);
8072
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5)) {
55108073 /* clear all RSS setting before free vnic ctx */
55118074 bnxt_hwrm_clear_vnic_rss(bp);
55128075 bnxt_hwrm_vnic_ctx_free(bp);
5513
- /* before free the vnic, undo the vnic tpa settings */
5514
- if (bp->flags & BNXT_FLAG_TPA)
5515
- bnxt_set_tpa(bp, false);
5516
- bnxt_hwrm_vnic_free(bp);
55178076 }
8077
+ /* before free the vnic, undo the vnic tpa settings */
8078
+ if (bp->flags & BNXT_FLAG_TPA)
8079
+ bnxt_set_tpa(bp, false);
8080
+ bnxt_hwrm_vnic_free(bp);
8081
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8082
+ bnxt_hwrm_vnic_ctx_free(bp);
8083
+}
8084
+
8085
+static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
8086
+ bool irq_re_init)
8087
+{
8088
+ bnxt_clear_vnic(bp);
55188089 bnxt_hwrm_ring_free(bp, close_path);
55198090 bnxt_hwrm_ring_grp_free(bp);
55208091 if (irq_re_init) {
....@@ -5526,7 +8097,6 @@
55268097 static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
55278098 {
55288099 struct hwrm_func_cfg_input req = {0};
5529
- int rc;
55308100
55318101 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
55328102 req.fid = cpu_to_le16(0xffff);
....@@ -5537,16 +8107,12 @@
55378107 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
55388108 else
55398109 return -EINVAL;
5540
- rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5541
- if (rc)
5542
- rc = -EIO;
5543
- return rc;
8110
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
55448111 }
55458112
55468113 static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
55478114 {
55488115 struct hwrm_func_cfg_input req = {0};
5549
- int rc;
55508116
55518117 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
55528118 return 0;
....@@ -5558,13 +8124,10 @@
55588124 if (size == 128)
55598125 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
55608126
5561
- rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5562
- if (rc)
5563
- rc = -EIO;
5564
- return rc;
8127
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
55658128 }
55668129
5567
-static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
8130
+static int __bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
55688131 {
55698132 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
55708133 int rc;
....@@ -5620,10 +8183,60 @@
56208183 return rc;
56218184 }
56228185
8186
+static int __bnxt_setup_vnic_p5(struct bnxt *bp, u16 vnic_id)
8187
+{
8188
+ int rc, i, nr_ctxs;
8189
+
8190
+ nr_ctxs = bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings);
8191
+ for (i = 0; i < nr_ctxs; i++) {
8192
+ rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, i);
8193
+ if (rc) {
8194
+ netdev_err(bp->dev, "hwrm vnic %d ctx %d alloc failure rc: %x\n",
8195
+ vnic_id, i, rc);
8196
+ break;
8197
+ }
8198
+ bp->rsscos_nr_ctxs++;
8199
+ }
8200
+ if (i < nr_ctxs)
8201
+ return -ENOMEM;
8202
+
8203
+ rc = bnxt_hwrm_vnic_set_rss_p5(bp, vnic_id, true);
8204
+ if (rc) {
8205
+ netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %d\n",
8206
+ vnic_id, rc);
8207
+ return rc;
8208
+ }
8209
+ rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
8210
+ if (rc) {
8211
+ netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
8212
+ vnic_id, rc);
8213
+ return rc;
8214
+ }
8215
+ if (bp->flags & BNXT_FLAG_AGG_RINGS) {
8216
+ rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
8217
+ if (rc) {
8218
+ netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
8219
+ vnic_id, rc);
8220
+ }
8221
+ }
8222
+ return rc;
8223
+}
8224
+
8225
+static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
8226
+{
8227
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8228
+ return __bnxt_setup_vnic_p5(bp, vnic_id);
8229
+ else
8230
+ return __bnxt_setup_vnic(bp, vnic_id);
8231
+}
8232
+
56238233 static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
56248234 {
56258235 #ifdef CONFIG_RFS_ACCEL
56268236 int i, rc = 0;
8237
+
8238
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8239
+ return 0;
56278240
56288241 for (i = 0; i < bp->rx_nr_rings; i++) {
56298242 struct bnxt_vnic_info *vnic;
....@@ -5905,9 +8518,17 @@
59058518 bp->irq_tbl[0].handler = bnxt_inta;
59068519 }
59078520
8521
+static int bnxt_init_int_mode(struct bnxt *bp);
8522
+
59088523 static int bnxt_setup_int_mode(struct bnxt *bp)
59098524 {
59108525 int rc;
8526
+
8527
+ if (!bp->irq_tbl) {
8528
+ rc = bnxt_init_int_mode(bp);
8529
+ if (rc || !bp->irq_tbl)
8530
+ return rc ?: -ENODEV;
8531
+ }
59118532
59128533 if (bp->flags & BNXT_FLAG_USING_MSIX)
59138534 bnxt_setup_msix(bp);
....@@ -5935,24 +8556,27 @@
59358556 return bp->hw_resc.max_stat_ctxs;
59368557 }
59378558
5938
-void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5939
-{
5940
- bp->hw_resc.max_stat_ctxs = max;
5941
-}
5942
-
59438559 unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
59448560 {
59458561 return bp->hw_resc.max_cp_rings;
59468562 }
59478563
5948
-unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp)
8564
+static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp)
59498565 {
5950
- return bp->hw_resc.max_cp_rings - bnxt_get_ulp_msix_num(bp);
8566
+ unsigned int cp = bp->hw_resc.max_cp_rings;
8567
+
8568
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
8569
+ cp -= bnxt_get_ulp_msix_num(bp);
8570
+
8571
+ return cp;
59518572 }
59528573
59538574 static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
59548575 {
59558576 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
8577
+
8578
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8579
+ return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_nqs);
59568580
59578581 return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
59588582 }
....@@ -5962,6 +8586,22 @@
59628586 bp->hw_resc.max_irqs = max_irqs;
59638587 }
59648588
8589
+unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt *bp)
8590
+{
8591
+ unsigned int cp;
8592
+
8593
+ cp = bnxt_get_max_func_cp_rings_for_en(bp);
8594
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8595
+ return cp - bp->rx_nr_rings - bp->tx_nr_rings;
8596
+ else
8597
+ return cp - bp->cp_nr_rings;
8598
+}
8599
+
8600
+unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp)
8601
+{
8602
+ return bnxt_get_max_func_stat_ctxs(bp) - bnxt_get_func_stat_ctxs(bp);
8603
+}
8604
+
59658605 int bnxt_get_avail_msix(struct bnxt *bp, int num)
59668606 {
59678607 int max_cp = bnxt_get_max_func_cp_rings(bp);
....@@ -5969,7 +8609,9 @@
59698609 int total_req = bp->cp_nr_rings + num;
59708610 int max_idx, avail_msix;
59718611
5972
- max_idx = min_t(int, bp->total_irqs, max_cp);
8612
+ max_idx = bp->total_irqs;
8613
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
8614
+ max_idx = min_t(int, bp->total_irqs, max_cp);
59738615 avail_msix = max_idx - bp->cp_nr_rings;
59748616 if (!BNXT_NEW_RM(bp) || avail_msix >= num)
59758617 return avail_msix;
....@@ -5987,7 +8629,7 @@
59878629 if (!BNXT_NEW_RM(bp))
59888630 return bnxt_get_max_func_irqs(bp);
59898631
5990
- return bnxt_cp_rings_in_use(bp);
8632
+ return bnxt_nq_rings_in_use(bp);
59918633 }
59928634
59938635 static int bnxt_init_msix(struct bnxt *bp)
....@@ -6072,7 +8714,7 @@
60728714
60738715 static int bnxt_init_int_mode(struct bnxt *bp)
60748716 {
6075
- int rc = 0;
8717
+ int rc = -ENODEV;
60768718
60778719 if (bp->flags & BNXT_FLAG_MSIX_CAP)
60788720 rc = bnxt_init_msix(bp);
....@@ -6094,22 +8736,23 @@
60948736 bp->flags &= ~BNXT_FLAG_USING_MSIX;
60958737 }
60968738
6097
-int bnxt_reserve_rings(struct bnxt *bp)
8739
+int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
60988740 {
60998741 int tcs = netdev_get_num_tc(bp->dev);
6100
- bool reinit_irq = false;
8742
+ bool irq_cleared = false;
61018743 int rc;
61028744
61038745 if (!bnxt_need_reserve_rings(bp))
61048746 return 0;
61058747
6106
- if (BNXT_NEW_RM(bp) && (bnxt_get_num_msix(bp) != bp->total_irqs)) {
8748
+ if (irq_re_init && BNXT_NEW_RM(bp) &&
8749
+ bnxt_get_num_msix(bp) != bp->total_irqs) {
61078750 bnxt_ulp_irq_stop(bp);
61088751 bnxt_clear_int_mode(bp);
6109
- reinit_irq = true;
8752
+ irq_cleared = true;
61108753 }
61118754 rc = __bnxt_reserve_rings(bp);
6112
- if (reinit_irq) {
8755
+ if (irq_cleared) {
61138756 if (!rc)
61148757 rc = bnxt_init_int_mode(bp);
61158758 bnxt_ulp_irq_restart(bp, rc);
....@@ -6124,7 +8767,6 @@
61248767 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
61258768 return -ENOMEM;
61268769 }
6127
- bp->num_stat_ctxs = bp->cp_nr_rings;
61288770 return 0;
61298771 }
61308772
....@@ -6225,10 +8867,9 @@
62258867 for (i = 0; i < bp->cp_nr_rings; i++) {
62268868 struct bnxt_napi *bnapi = bp->bnapi[i];
62278869
6228
- napi_hash_del(&bnapi->napi);
6229
- netif_napi_del(&bnapi->napi);
8870
+ __netif_napi_del(&bnapi->napi);
62308871 }
6231
- /* We called napi_hash_del() before netif_napi_del(), we need
8872
+ /* We called __netif_napi_del(), we need
62328873 * to respect an RCU grace period before freeing napi structures.
62338874 */
62348875 synchronize_net();
....@@ -6241,12 +8882,15 @@
62418882 struct bnxt_napi *bnapi;
62428883
62438884 if (bp->flags & BNXT_FLAG_USING_MSIX) {
6244
- if (BNXT_CHIP_TYPE_NITRO_A0(bp))
8885
+ int (*poll_fn)(struct napi_struct *, int) = bnxt_poll;
8886
+
8887
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
8888
+ poll_fn = bnxt_poll_p5;
8889
+ else if (BNXT_CHIP_TYPE_NITRO_A0(bp))
62458890 cp_nr_rings--;
62468891 for (i = 0; i < cp_nr_rings; i++) {
62478892 bnapi = bp->bnapi[i];
6248
- netif_napi_add(bp->dev, &bnapi->napi,
6249
- bnxt_poll, 64);
8893
+ netif_napi_add(bp->dev, &bnapi->napi, poll_fn, 64);
62508894 }
62518895 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
62528896 bnapi = bp->bnapi[cp_nr_rings];
....@@ -6280,14 +8924,19 @@
62808924 int i;
62818925
62828926 for (i = 0; i < bp->cp_nr_rings; i++) {
6283
- struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
6284
- bp->bnapi[i]->in_reset = false;
8927
+ struct bnxt_napi *bnapi = bp->bnapi[i];
8928
+ struct bnxt_cp_ring_info *cpr;
62858929
6286
- if (bp->bnapi[i]->rx_ring) {
8930
+ cpr = &bnapi->cp_ring;
8931
+ if (bnapi->in_reset)
8932
+ cpr->sw_stats.rx.rx_resets++;
8933
+ bnapi->in_reset = false;
8934
+
8935
+ if (bnapi->rx_ring) {
62878936 INIT_WORK(&cpr->dim.work, bnxt_dim_work);
6288
- cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE;
8937
+ cpr->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
62898938 }
6290
- napi_enable(&bp->bnapi[i]->napi);
8939
+ napi_enable(&bnapi->napi);
62918940 }
62928941 }
62938942
....@@ -6326,6 +8975,30 @@
63268975 netif_carrier_on(bp->dev);
63278976 }
63288977
8978
+static char *bnxt_report_fec(struct bnxt_link_info *link_info)
8979
+{
8980
+ u8 active_fec = link_info->active_fec_sig_mode &
8981
+ PORT_PHY_QCFG_RESP_ACTIVE_FEC_MASK;
8982
+
8983
+ switch (active_fec) {
8984
+ default:
8985
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_NONE_ACTIVE:
8986
+ return "None";
8987
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE74_ACTIVE:
8988
+ return "Clause 74 BaseR";
8989
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE91_ACTIVE:
8990
+ return "Clause 91 RS(528,514)";
8991
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_1XN_ACTIVE:
8992
+ return "Clause 91 RS544_1XN";
8993
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_IEEE_ACTIVE:
8994
+ return "Clause 91 RS(544,514)";
8995
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_1XN_ACTIVE:
8996
+ return "Clause 91 RS272_1XN";
8997
+ case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_IEEE_ACTIVE:
8998
+ return "Clause 91 RS(272,257)";
8999
+ }
9000
+}
9001
+
63299002 static void bnxt_report_link(struct bnxt *bp)
63309003 {
63319004 if (bp->link_info.link_up) {
....@@ -6360,14 +9033,23 @@
63609033 "not active");
63619034 fec = bp->link_info.fec_cfg;
63629035 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
6363
- netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
9036
+ netdev_info(bp->dev, "FEC autoneg %s encoding: %s\n",
63649037 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
6365
- (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
6366
- (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
9038
+ bnxt_report_fec(&bp->link_info));
63679039 } else {
63689040 netif_carrier_off(bp->dev);
63699041 netdev_err(bp->dev, "NIC Link is Down\n");
63709042 }
9043
+}
9044
+
9045
+static bool bnxt_phy_qcaps_no_speed(struct hwrm_port_phy_qcaps_output *resp)
9046
+{
9047
+ if (!resp->supported_speeds_auto_mode &&
9048
+ !resp->supported_speeds_force_mode &&
9049
+ !resp->supported_pam4_speeds_auto_mode &&
9050
+ !resp->supported_pam4_speeds_force_mode)
9051
+ return true;
9052
+ return false;
63719053 }
63729054
63739055 static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
....@@ -6377,6 +9059,10 @@
63779059 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
63789060 struct bnxt_link_info *link_info = &bp->link_info;
63799061
9062
+ bp->flags &= ~BNXT_FLAG_EEE_CAP;
9063
+ if (bp->test_info)
9064
+ bp->test_info->flags &= ~(BNXT_TEST_FL_EXT_LPBK |
9065
+ BNXT_TEST_FL_AN_PHY_LPBK);
63809066 if (bp->hwrm_spec_code < 0x10201)
63819067 return 0;
63829068
....@@ -6402,9 +9088,35 @@
64029088 if (bp->test_info)
64039089 bp->test_info->flags |= BNXT_TEST_FL_EXT_LPBK;
64049090 }
9091
+ if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_AUTONEG_LPBK_SUPPORTED) {
9092
+ if (bp->test_info)
9093
+ bp->test_info->flags |= BNXT_TEST_FL_AN_PHY_LPBK;
9094
+ }
9095
+ if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_SHARED_PHY_CFG_SUPPORTED) {
9096
+ if (BNXT_PF(bp))
9097
+ bp->fw_cap |= BNXT_FW_CAP_SHARED_PORT_CFG;
9098
+ }
9099
+ if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_CUMULATIVE_COUNTERS_ON_RESET)
9100
+ bp->fw_cap |= BNXT_FW_CAP_PORT_STATS_NO_RESET;
9101
+
9102
+ if (bp->hwrm_spec_code >= 0x10a01) {
9103
+ if (bnxt_phy_qcaps_no_speed(resp)) {
9104
+ link_info->phy_state = BNXT_PHY_STATE_DISABLED;
9105
+ netdev_warn(bp->dev, "Ethernet link disabled\n");
9106
+ } else if (link_info->phy_state == BNXT_PHY_STATE_DISABLED) {
9107
+ link_info->phy_state = BNXT_PHY_STATE_ENABLED;
9108
+ netdev_info(bp->dev, "Ethernet link enabled\n");
9109
+ /* Phy re-enabled, reprobe the speeds */
9110
+ link_info->support_auto_speeds = 0;
9111
+ link_info->support_pam4_auto_speeds = 0;
9112
+ }
9113
+ }
64059114 if (resp->supported_speeds_auto_mode)
64069115 link_info->support_auto_speeds =
64079116 le16_to_cpu(resp->supported_speeds_auto_mode);
9117
+ if (resp->supported_pam4_speeds_auto_mode)
9118
+ link_info->support_pam4_auto_speeds =
9119
+ le16_to_cpu(resp->supported_pam4_speeds_auto_mode);
64089120
64099121 bp->port_count = resp->port_cnt;
64109122
....@@ -6413,14 +9125,21 @@
64139125 return rc;
64149126 }
64159127
6416
-static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
9128
+static bool bnxt_support_dropped(u16 advertising, u16 supported)
9129
+{
9130
+ u16 diff = advertising ^ supported;
9131
+
9132
+ return ((supported | diff) != supported);
9133
+}
9134
+
9135
+int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
64179136 {
64189137 int rc = 0;
64199138 struct bnxt_link_info *link_info = &bp->link_info;
64209139 struct hwrm_port_phy_qcfg_input req = {0};
64219140 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
64229141 u8 link_up = link_info->link_up;
6423
- u16 diff;
9142
+ bool support_changed = false;
64249143
64259144 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
64269145
....@@ -6447,10 +9166,17 @@
64479166 else
64489167 link_info->link_speed = 0;
64499168 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
9169
+ link_info->force_pam4_link_speed =
9170
+ le16_to_cpu(resp->force_pam4_link_speed);
64509171 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
9172
+ link_info->support_pam4_speeds = le16_to_cpu(resp->support_pam4_speeds);
64519173 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
9174
+ link_info->auto_pam4_link_speeds =
9175
+ le16_to_cpu(resp->auto_pam4_link_speed_mask);
64529176 link_info->lp_auto_link_speeds =
64539177 le16_to_cpu(resp->link_partner_adv_speeds);
9178
+ link_info->lp_auto_pam4_link_speeds =
9179
+ resp->link_partner_pam4_adv_speeds;
64549180 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
64559181 link_info->phy_ver[0] = resp->phy_maj;
64569182 link_info->phy_ver[1] = resp->phy_min;
....@@ -6499,9 +9225,10 @@
64999225 }
65009226
65019227 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
6502
- if (bp->hwrm_spec_code >= 0x10504)
9228
+ if (bp->hwrm_spec_code >= 0x10504) {
65039229 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
6504
-
9230
+ link_info->active_fec_sig_mode = resp->active_fec_signal_mode;
9231
+ }
65059232 /* TODO: need to add more logic to report VF link */
65069233 if (chng_link_state) {
65079234 if (link_info->phy_link_status == BNXT_LINK_LINK)
....@@ -6516,20 +9243,24 @@
65169243 }
65179244 mutex_unlock(&bp->hwrm_cmd_lock);
65189245
6519
- if (!BNXT_SINGLE_PF(bp))
9246
+ if (!BNXT_PHY_CFG_ABLE(bp))
65209247 return 0;
65219248
6522
- diff = link_info->support_auto_speeds ^ link_info->advertising;
6523
- if ((link_info->support_auto_speeds | diff) !=
6524
- link_info->support_auto_speeds) {
6525
- /* An advertised speed is no longer supported, so we need to
6526
- * update the advertisement settings. Caller holds RTNL
6527
- * so we can modify link settings.
6528
- */
9249
+ /* Check if any advertised speeds are no longer supported. The caller
9250
+ * holds the link_lock mutex, so we can modify link_info settings.
9251
+ */
9252
+ if (bnxt_support_dropped(link_info->advertising,
9253
+ link_info->support_auto_speeds)) {
65299254 link_info->advertising = link_info->support_auto_speeds;
6530
- if (link_info->autoneg & BNXT_AUTONEG_SPEED)
6531
- bnxt_hwrm_set_link_setting(bp, true, false);
9255
+ support_changed = true;
65329256 }
9257
+ if (bnxt_support_dropped(link_info->advertising_pam4,
9258
+ link_info->support_pam4_auto_speeds)) {
9259
+ link_info->advertising_pam4 = link_info->support_pam4_auto_speeds;
9260
+ support_changed = true;
9261
+ }
9262
+ if (support_changed && (link_info->autoneg & BNXT_AUTONEG_SPEED))
9263
+ bnxt_hwrm_set_link_setting(bp, true, false);
65339264 return 0;
65349265 }
65359266
....@@ -6588,27 +9319,30 @@
65889319 }
65899320 }
65909321
6591
-static void bnxt_hwrm_set_link_common(struct bnxt *bp,
6592
- struct hwrm_port_phy_cfg_input *req)
9322
+static void bnxt_hwrm_set_link_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
65939323 {
6594
- u8 autoneg = bp->link_info.autoneg;
6595
- u16 fw_link_speed = bp->link_info.req_link_speed;
6596
- u16 advertising = bp->link_info.advertising;
6597
-
6598
- if (autoneg & BNXT_AUTONEG_SPEED) {
6599
- req->auto_mode |=
6600
- PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
6601
-
6602
- req->enables |= cpu_to_le32(
6603
- PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
6604
- req->auto_link_speed_mask = cpu_to_le16(advertising);
6605
-
9324
+ if (bp->link_info.autoneg & BNXT_AUTONEG_SPEED) {
9325
+ req->auto_mode |= PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
9326
+ if (bp->link_info.advertising) {
9327
+ req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
9328
+ req->auto_link_speed_mask = cpu_to_le16(bp->link_info.advertising);
9329
+ }
9330
+ if (bp->link_info.advertising_pam4) {
9331
+ req->enables |=
9332
+ cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAM4_LINK_SPEED_MASK);
9333
+ req->auto_link_pam4_speed_mask =
9334
+ cpu_to_le16(bp->link_info.advertising_pam4);
9335
+ }
66069336 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
6607
- req->flags |=
6608
- cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
9337
+ req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
66099338 } else {
6610
- req->force_link_speed = cpu_to_le16(fw_link_speed);
66119339 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
9340
+ if (bp->link_info.req_signal_mode == BNXT_SIG_MODE_PAM4) {
9341
+ req->force_pam4_link_speed = cpu_to_le16(bp->link_info.req_link_speed);
9342
+ req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAM4_LINK_SPEED);
9343
+ } else {
9344
+ req->force_link_speed = cpu_to_le16(bp->link_info.req_link_speed);
9345
+ }
66129346 }
66139347
66149348 /* tell chimp that the setting takes effect immediately */
....@@ -6698,11 +9432,15 @@
66989432 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
66999433 }
67009434
9435
+static int bnxt_fw_init_one(struct bnxt *bp);
9436
+
67019437 static int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
67029438 {
67039439 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
67049440 struct hwrm_func_drv_if_change_input req = {0};
9441
+ bool fw_reset = !bp->irq_tbl;
67059442 bool resc_reinit = false;
9443
+ u32 flags = 0;
67069444 int rc;
67079445
67089446 if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
....@@ -6713,24 +9451,64 @@
67139451 req.flags = cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP);
67149452 mutex_lock(&bp->hwrm_cmd_lock);
67159453 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6716
- if (!rc && (resp->flags &
6717
- cpu_to_le32(FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE)))
6718
- resc_reinit = true;
9454
+ if (!rc)
9455
+ flags = le32_to_cpu(resp->flags);
67199456 mutex_unlock(&bp->hwrm_cmd_lock);
9457
+ if (rc)
9458
+ return rc;
67209459
6721
- if (up && resc_reinit && BNXT_NEW_RM(bp)) {
6722
- struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
9460
+ if (!up)
9461
+ return 0;
67239462
6724
- rc = bnxt_hwrm_func_resc_qcaps(bp, true);
6725
- hw_resc->resv_cp_rings = 0;
6726
- hw_resc->resv_tx_rings = 0;
6727
- hw_resc->resv_rx_rings = 0;
6728
- hw_resc->resv_hw_ring_grps = 0;
6729
- hw_resc->resv_vnics = 0;
6730
- bp->tx_nr_rings = 0;
6731
- bp->rx_nr_rings = 0;
9463
+ if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE)
9464
+ resc_reinit = true;
9465
+ if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_HOT_FW_RESET_DONE)
9466
+ fw_reset = true;
9467
+
9468
+ if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) && !fw_reset) {
9469
+ netdev_err(bp->dev, "RESET_DONE not set during FW reset.\n");
9470
+ set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
9471
+ return -ENODEV;
67329472 }
6733
- return rc;
9473
+ if (resc_reinit || fw_reset) {
9474
+ if (fw_reset) {
9475
+ if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
9476
+ bnxt_ulp_stop(bp);
9477
+ bnxt_free_ctx_mem(bp);
9478
+ kfree(bp->ctx);
9479
+ bp->ctx = NULL;
9480
+ bnxt_dcb_free(bp);
9481
+ rc = bnxt_fw_init_one(bp);
9482
+ if (rc) {
9483
+ set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
9484
+ return rc;
9485
+ }
9486
+ bnxt_clear_int_mode(bp);
9487
+ rc = bnxt_init_int_mode(bp);
9488
+ if (rc) {
9489
+ netdev_err(bp->dev, "init int mode failed\n");
9490
+ return rc;
9491
+ }
9492
+ set_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
9493
+ }
9494
+ if (BNXT_NEW_RM(bp)) {
9495
+ struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
9496
+
9497
+ rc = bnxt_hwrm_func_resc_qcaps(bp, true);
9498
+ hw_resc->resv_cp_rings = 0;
9499
+ hw_resc->resv_stat_ctxs = 0;
9500
+ hw_resc->resv_irqs = 0;
9501
+ hw_resc->resv_tx_rings = 0;
9502
+ hw_resc->resv_rx_rings = 0;
9503
+ hw_resc->resv_hw_ring_grps = 0;
9504
+ hw_resc->resv_vnics = 0;
9505
+ if (!fw_reset) {
9506
+ bp->tx_nr_rings = 0;
9507
+ bp->rx_nr_rings = 0;
9508
+ }
9509
+ }
9510
+ }
9511
+ return 0;
67349512 }
67359513
67369514 static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
....@@ -6740,6 +9518,7 @@
67409518 struct bnxt_pf_info *pf = &bp->pf;
67419519 int rc;
67429520
9521
+ bp->num_leds = 0;
67439522 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
67449523 return 0;
67459524
....@@ -6794,14 +9573,12 @@
67949573 int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
67959574 {
67969575 struct hwrm_wol_filter_free_input req = {0};
6797
- int rc;
67989576
67999577 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
68009578 req.port_id = cpu_to_le16(bp->pf.port_id);
68019579 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
68029580 req.wol_filter_id = bp->wol_filter_id;
6803
- rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6804
- return rc;
9581
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
68059582 }
68069583
68079584 static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
....@@ -6834,6 +9611,7 @@
68349611 {
68359612 u16 handle = 0;
68369613
9614
+ bp->wol = 0;
68379615 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
68389616 return;
68399617
....@@ -6891,6 +9669,9 @@
68919669 bnxt_hwmon_close(bp);
68929670 return;
68939671 }
9672
+
9673
+ if (bp->hwmon_dev)
9674
+ return;
68949675
68959676 bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
68969677 DRV_MODULE_NAME, bp,
....@@ -6961,21 +9742,26 @@
69619742 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
69629743 if (BNXT_AUTO_MODE(link_info->auto_mode))
69639744 update_link = true;
6964
- if (link_info->req_link_speed != link_info->force_link_speed)
9745
+ if (link_info->req_signal_mode == BNXT_SIG_MODE_NRZ &&
9746
+ link_info->req_link_speed != link_info->force_link_speed)
9747
+ update_link = true;
9748
+ else if (link_info->req_signal_mode == BNXT_SIG_MODE_PAM4 &&
9749
+ link_info->req_link_speed != link_info->force_pam4_link_speed)
69659750 update_link = true;
69669751 if (link_info->req_duplex != link_info->duplex_setting)
69679752 update_link = true;
69689753 } else {
69699754 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
69709755 update_link = true;
6971
- if (link_info->advertising != link_info->auto_link_speeds)
9756
+ if (link_info->advertising != link_info->auto_link_speeds ||
9757
+ link_info->advertising_pam4 != link_info->auto_pam4_link_speeds)
69729758 update_link = true;
69739759 }
69749760
69759761 /* The last close may have shutdown the link, so need to call
69769762 * PHY_CFG to bring it back up.
69779763 */
6978
- if (!netif_carrier_ok(bp->dev))
9764
+ if (!bp->link_info.link_up)
69799765 update_link = true;
69809766
69819767 if (!bnxt_eee_config_ok(bp))
....@@ -7023,10 +9809,10 @@
70239809 netdev_err(bp->dev, "Failed to reserve default rings at open\n");
70249810 return rc;
70259811 }
7026
- rc = bnxt_reserve_rings(bp);
7027
- if (rc)
7028
- return rc;
70299812 }
9813
+ rc = bnxt_reserve_rings(bp, irq_re_init);
9814
+ if (rc)
9815
+ return rc;
70309816 if ((bp->flags & BNXT_FLAG_RFS) &&
70319817 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
70329818 /* disable RFS if falling back to INTA */
....@@ -7073,7 +9859,7 @@
70739859 }
70749860
70759861 if (irq_re_init)
7076
- udp_tunnel_get_rx_info(bp->dev);
9862
+ udp_tunnel_nic_reset_ntf(bp->dev);
70779863
70789864 set_bit(BNXT_STATE_OPEN, &bp->state);
70799865 bnxt_enable_int(bp);
....@@ -7103,7 +9889,10 @@
71039889 {
71049890 int rc = 0;
71059891
7106
- rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
9892
+ if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state))
9893
+ rc = -EIO;
9894
+ if (!rc)
9895
+ rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
71079896 if (rc) {
71089897 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
71099898 dev_close(bp->dev);
....@@ -7118,6 +9907,12 @@
71189907 int bnxt_half_open_nic(struct bnxt *bp)
71199908 {
71209909 int rc = 0;
9910
+
9911
+ if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
9912
+ netdev_err(bp->dev, "A previous firmware reset has not completed, aborting half open\n");
9913
+ rc = -ENODEV;
9914
+ goto half_open_err;
9915
+ }
71219916
71229917 rc = bnxt_alloc_mem(bp, false);
71239918 if (rc) {
....@@ -7148,17 +9943,42 @@
71489943 bnxt_free_mem(bp, false);
71499944 }
71509945
9946
+static void bnxt_reenable_sriov(struct bnxt *bp)
9947
+{
9948
+ if (BNXT_PF(bp)) {
9949
+ struct bnxt_pf_info *pf = &bp->pf;
9950
+ int n = pf->active_vfs;
9951
+
9952
+ if (n)
9953
+ bnxt_cfg_hw_sriov(bp, &n, true);
9954
+ }
9955
+}
9956
+
71519957 static int bnxt_open(struct net_device *dev)
71529958 {
71539959 struct bnxt *bp = netdev_priv(dev);
71549960 int rc;
71559961
7156
- bnxt_hwrm_if_change(bp, true);
7157
- rc = __bnxt_open_nic(bp, true, true);
7158
- if (rc)
7159
- bnxt_hwrm_if_change(bp, false);
9962
+ if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
9963
+ netdev_err(bp->dev, "A previous firmware reset did not complete, aborting\n");
9964
+ return -ENODEV;
9965
+ }
71609966
7161
- bnxt_hwmon_open(bp);
9967
+ rc = bnxt_hwrm_if_change(bp, true);
9968
+ if (rc)
9969
+ return rc;
9970
+ rc = __bnxt_open_nic(bp, true, true);
9971
+ if (rc) {
9972
+ bnxt_hwrm_if_change(bp, false);
9973
+ } else {
9974
+ if (test_and_clear_bit(BNXT_STATE_FW_RESET_DET, &bp->state)) {
9975
+ if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
9976
+ bnxt_ulp_start(bp, 0);
9977
+ bnxt_reenable_sriov(bp);
9978
+ }
9979
+ }
9980
+ bnxt_hwmon_open(bp);
9981
+ }
71629982
71639983 return rc;
71649984 }
....@@ -7211,6 +10031,18 @@
721110031 {
721210032 int rc = 0;
721310033
10034
+ if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
10035
+ /* If we get here, it means firmware reset is in progress
10036
+ * while we are trying to close. We can safely proceed with
10037
+ * the close because we are holding rtnl_lock(). Some firmware
10038
+ * messages may fail as we proceed to close. We set the
10039
+ * ABORT_ERR flag here so that the FW reset thread will later
10040
+ * abort when it gets the rtnl_lock() and sees the flag.
10041
+ */
10042
+ netdev_warn(bp->dev, "FW reset in progress during close, FW reset will be aborted\n");
10043
+ set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
10044
+ }
10045
+
721410046 #ifdef CONFIG_BNXT_SRIOV
721510047 if (bp->sriov_cfg) {
721610048 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
....@@ -7235,24 +10067,88 @@
723510067 return 0;
723610068 }
723710069
10070
+static int bnxt_hwrm_port_phy_read(struct bnxt *bp, u16 phy_addr, u16 reg,
10071
+ u16 *val)
10072
+{
10073
+ struct hwrm_port_phy_mdio_read_output *resp = bp->hwrm_cmd_resp_addr;
10074
+ struct hwrm_port_phy_mdio_read_input req = {0};
10075
+ int rc;
10076
+
10077
+ if (bp->hwrm_spec_code < 0x10a00)
10078
+ return -EOPNOTSUPP;
10079
+
10080
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_MDIO_READ, -1, -1);
10081
+ req.port_id = cpu_to_le16(bp->pf.port_id);
10082
+ req.phy_addr = phy_addr;
10083
+ req.reg_addr = cpu_to_le16(reg & 0x1f);
10084
+ if (mdio_phy_id_is_c45(phy_addr)) {
10085
+ req.cl45_mdio = 1;
10086
+ req.phy_addr = mdio_phy_id_prtad(phy_addr);
10087
+ req.dev_addr = mdio_phy_id_devad(phy_addr);
10088
+ req.reg_addr = cpu_to_le16(reg);
10089
+ }
10090
+
10091
+ mutex_lock(&bp->hwrm_cmd_lock);
10092
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
10093
+ if (!rc)
10094
+ *val = le16_to_cpu(resp->reg_data);
10095
+ mutex_unlock(&bp->hwrm_cmd_lock);
10096
+ return rc;
10097
+}
10098
+
10099
+static int bnxt_hwrm_port_phy_write(struct bnxt *bp, u16 phy_addr, u16 reg,
10100
+ u16 val)
10101
+{
10102
+ struct hwrm_port_phy_mdio_write_input req = {0};
10103
+
10104
+ if (bp->hwrm_spec_code < 0x10a00)
10105
+ return -EOPNOTSUPP;
10106
+
10107
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_MDIO_WRITE, -1, -1);
10108
+ req.port_id = cpu_to_le16(bp->pf.port_id);
10109
+ req.phy_addr = phy_addr;
10110
+ req.reg_addr = cpu_to_le16(reg & 0x1f);
10111
+ if (mdio_phy_id_is_c45(phy_addr)) {
10112
+ req.cl45_mdio = 1;
10113
+ req.phy_addr = mdio_phy_id_prtad(phy_addr);
10114
+ req.dev_addr = mdio_phy_id_devad(phy_addr);
10115
+ req.reg_addr = cpu_to_le16(reg);
10116
+ }
10117
+ req.reg_data = cpu_to_le16(val);
10118
+
10119
+ return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
10120
+}
10121
+
723810122 /* rtnl_lock held */
723910123 static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
724010124 {
10125
+ struct mii_ioctl_data *mdio = if_mii(ifr);
10126
+ struct bnxt *bp = netdev_priv(dev);
10127
+ int rc;
10128
+
724110129 switch (cmd) {
724210130 case SIOCGMIIPHY:
7243
- /* fallthru */
10131
+ mdio->phy_id = bp->link_info.phy_addr;
10132
+
10133
+ fallthrough;
724410134 case SIOCGMIIREG: {
10135
+ u16 mii_regval = 0;
10136
+
724510137 if (!netif_running(dev))
724610138 return -EAGAIN;
724710139
7248
- return 0;
10140
+ rc = bnxt_hwrm_port_phy_read(bp, mdio->phy_id, mdio->reg_num,
10141
+ &mii_regval);
10142
+ mdio->val_out = mii_regval;
10143
+ return rc;
724910144 }
725010145
725110146 case SIOCSMIIREG:
725210147 if (!netif_running(dev))
725310148 return -EAGAIN;
725410149
7255
- return 0;
10150
+ return bnxt_hwrm_port_phy_write(bp, mdio->phy_id, mdio->reg_num,
10151
+ mdio->val_in);
725610152
725710153 default:
725810154 /* do nothing */
....@@ -7266,34 +10162,33 @@
726610162 {
726710163 int i;
726810164
7269
-
727010165 for (i = 0; i < bp->cp_nr_rings; i++) {
727110166 struct bnxt_napi *bnapi = bp->bnapi[i];
727210167 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7273
- struct ctx_hw_stats *hw_stats = cpr->hw_stats;
10168
+ u64 *sw = cpr->stats.sw_stats;
727410169
7275
- stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
7276
- stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
7277
- stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
10170
+ stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_ucast_pkts);
10171
+ stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
10172
+ stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_bcast_pkts);
727810173
7279
- stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
7280
- stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
7281
- stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
10174
+ stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
10175
+ stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_mcast_pkts);
10176
+ stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_bcast_pkts);
728210177
7283
- stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
7284
- stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
7285
- stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
10178
+ stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_ucast_bytes);
10179
+ stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_mcast_bytes);
10180
+ stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_bcast_bytes);
728610181
7287
- stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
7288
- stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
7289
- stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
10182
+ stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
10183
+ stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
10184
+ stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
729010185
729110186 stats->rx_missed_errors +=
7292
- le64_to_cpu(hw_stats->rx_discard_pkts);
10187
+ BNXT_GET_RING_STATS64(sw, rx_discard_pkts);
729310188
7294
- stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
10189
+ stats->multicast += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
729510190
7296
- stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
10191
+ stats->tx_dropped += BNXT_GET_RING_STATS64(sw, tx_error_pkts);
729710192 }
729810193 }
729910194
....@@ -7331,19 +10226,26 @@
733110226 bnxt_add_prev_stats(bp, stats);
733210227
733310228 if (bp->flags & BNXT_FLAG_PORT_STATS) {
7334
- struct rx_port_stats *rx = bp->hw_rx_port_stats;
7335
- struct tx_port_stats *tx = bp->hw_tx_port_stats;
10229
+ u64 *rx = bp->port_stats.sw_stats;
10230
+ u64 *tx = bp->port_stats.sw_stats +
10231
+ BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
733610232
7337
- stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
7338
- stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
7339
- stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
7340
- le64_to_cpu(rx->rx_ovrsz_frames) +
7341
- le64_to_cpu(rx->rx_runt_frames);
7342
- stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
7343
- le64_to_cpu(rx->rx_jbr_frames);
7344
- stats->collisions = le64_to_cpu(tx->tx_total_collisions);
7345
- stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
7346
- stats->tx_errors = le64_to_cpu(tx->tx_err);
10233
+ stats->rx_crc_errors =
10234
+ BNXT_GET_RX_PORT_STATS64(rx, rx_fcs_err_frames);
10235
+ stats->rx_frame_errors =
10236
+ BNXT_GET_RX_PORT_STATS64(rx, rx_align_err_frames);
10237
+ stats->rx_length_errors =
10238
+ BNXT_GET_RX_PORT_STATS64(rx, rx_undrsz_frames) +
10239
+ BNXT_GET_RX_PORT_STATS64(rx, rx_ovrsz_frames) +
10240
+ BNXT_GET_RX_PORT_STATS64(rx, rx_runt_frames);
10241
+ stats->rx_errors =
10242
+ BNXT_GET_RX_PORT_STATS64(rx, rx_false_carrier_frames) +
10243
+ BNXT_GET_RX_PORT_STATS64(rx, rx_jbr_frames);
10244
+ stats->collisions =
10245
+ BNXT_GET_TX_PORT_STATS64(tx, tx_total_collisions);
10246
+ stats->tx_fifo_errors =
10247
+ BNXT_GET_TX_PORT_STATS64(tx, tx_fifo_underruns);
10248
+ stats->tx_errors = BNXT_GET_TX_PORT_STATS64(tx, tx_err);
734710249 }
734810250 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
734910251 }
....@@ -7404,14 +10306,16 @@
740410306 static void bnxt_set_rx_mode(struct net_device *dev)
740510307 {
740610308 struct bnxt *bp = netdev_priv(dev);
7407
- struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7408
- u32 mask = vnic->rx_mask;
10309
+ struct bnxt_vnic_info *vnic;
740910310 bool mc_update = false;
741010311 bool uc_update;
10312
+ u32 mask;
741110313
7412
- if (!netif_running(dev))
10314
+ if (!test_bit(BNXT_STATE_OPEN, &bp->state))
741310315 return;
741410316
10317
+ vnic = &bp->vnic_info[0];
10318
+ mask = vnic->rx_mask;
741510319 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
741610320 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
741710321 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST |
....@@ -7530,6 +10434,14 @@
753010434 /* If the chip and firmware supports RFS */
753110435 static bool bnxt_rfs_supported(struct bnxt *bp)
753210436 {
10437
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
10438
+ if (bp->fw_cap & BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2)
10439
+ return true;
10440
+ return false;
10441
+ }
10442
+ /* 212 firmware is broken for aRFS */
10443
+ if (BNXT_FW_MAJ(bp) == 212)
10444
+ return false;
753310445 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
753410446 return true;
753510447 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
....@@ -7543,7 +10455,9 @@
754310455 #ifdef CONFIG_RFS_ACCEL
754410456 int vnics, max_vnics, max_rss_ctxs;
754510457
7546
- if (!(bp->flags & BNXT_FLAG_MSIX_CAP) || !bnxt_can_reserve_rings(bp))
10458
+ if (bp->flags & BNXT_FLAG_CHIP_P5)
10459
+ return bnxt_rfs_supported(bp);
10460
+ if (!(bp->flags & BNXT_FLAG_MSIX_CAP) || !bnxt_can_reserve_rings(bp) || !bp->rx_nr_rings)
754710461 return false;
754810462
754910463 vnics = 1 + bp->rx_nr_rings;
....@@ -7567,12 +10481,12 @@
756710481 if (vnics == bp->hw_resc.resv_vnics)
756810482 return true;
756910483
7570
- bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics);
10484
+ bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, vnics);
757110485 if (vnics <= bp->hw_resc.resv_vnics)
757210486 return true;
757310487
757410488 netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
7575
- bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1);
10489
+ bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, 1);
757610490 return false;
757710491 #else
757810492 return false;
....@@ -7600,24 +10514,16 @@
760010514 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
760110515 * turned on or off together.
760210516 */
7603
- vlan_features = features & (NETIF_F_HW_VLAN_CTAG_RX |
7604
- NETIF_F_HW_VLAN_STAG_RX);
7605
- if (vlan_features != (NETIF_F_HW_VLAN_CTAG_RX |
7606
- NETIF_F_HW_VLAN_STAG_RX)) {
7607
- if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
7608
- features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7609
- NETIF_F_HW_VLAN_STAG_RX);
10517
+ vlan_features = features & BNXT_HW_FEATURE_VLAN_ALL_RX;
10518
+ if (vlan_features != BNXT_HW_FEATURE_VLAN_ALL_RX) {
10519
+ if (dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)
10520
+ features &= ~BNXT_HW_FEATURE_VLAN_ALL_RX;
761010521 else if (vlan_features)
7611
- features |= NETIF_F_HW_VLAN_CTAG_RX |
7612
- NETIF_F_HW_VLAN_STAG_RX;
10522
+ features |= BNXT_HW_FEATURE_VLAN_ALL_RX;
761310523 }
761410524 #ifdef CONFIG_BNXT_SRIOV
7615
- if (BNXT_VF(bp)) {
7616
- if (bp->vf.vlan) {
7617
- features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7618
- NETIF_F_HW_VLAN_STAG_RX);
7619
- }
7620
- }
10525
+ if (BNXT_VF(bp) && bp->vf.vlan)
10526
+ features &= ~BNXT_HW_FEATURE_VLAN_ALL_RX;
762110527 #endif
762210528 return features;
762310529 }
....@@ -7640,7 +10546,7 @@
764010546 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
764110547 flags &= ~BNXT_FLAG_TPA;
764210548
7643
- if (features & NETIF_F_HW_VLAN_CTAG_RX)
10549
+ if (features & BNXT_HW_FEATURE_VLAN_ALL_RX)
764410550 flags |= BNXT_FLAG_STRIP_VLAN;
764510551
764610552 if (features & NETIF_F_NTUPLE)
....@@ -7650,7 +10556,8 @@
765010556 if (changes & BNXT_FLAG_TPA) {
765110557 update_tpa = true;
765210558 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
7653
- (flags & BNXT_FLAG_TPA) == 0)
10559
+ (flags & BNXT_FLAG_TPA) == 0 ||
10560
+ (bp->flags & BNXT_FLAG_CHIP_P5))
765410561 re_init = true;
765510562 }
765610563
....@@ -7660,9 +10567,8 @@
766010567 if (flags != bp->flags) {
766110568 u32 old_flags = bp->flags;
766210569
7663
- bp->flags = flags;
7664
-
766510570 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
10571
+ bp->flags = flags;
766610572 if (update_tpa)
766710573 bnxt_set_ring_params(bp);
766810574 return rc;
....@@ -7670,12 +10576,14 @@
767010576
767110577 if (re_init) {
767210578 bnxt_close_nic(bp, false, false);
10579
+ bp->flags = flags;
767310580 if (update_tpa)
767410581 bnxt_set_ring_params(bp);
767510582
767610583 return bnxt_open_nic(bp, false, false);
767710584 }
767810585 if (update_tpa) {
10586
+ bp->flags = flags;
767910587 rc = bnxt_set_tpa(bp,
768010588 (flags & BNXT_FLAG_TPA) ?
768110589 true : false);
....@@ -7683,6 +10591,58 @@
768310591 bp->flags = old_flags;
768410592 }
768510593 }
10594
+ return rc;
10595
+}
10596
+
10597
+int bnxt_dbg_hwrm_rd_reg(struct bnxt *bp, u32 reg_off, u16 num_words,
10598
+ u32 *reg_buf)
10599
+{
10600
+ struct hwrm_dbg_read_direct_output *resp = bp->hwrm_cmd_resp_addr;
10601
+ struct hwrm_dbg_read_direct_input req = {0};
10602
+ __le32 *dbg_reg_buf;
10603
+ dma_addr_t mapping;
10604
+ int rc, i;
10605
+
10606
+ dbg_reg_buf = dma_alloc_coherent(&bp->pdev->dev, num_words * 4,
10607
+ &mapping, GFP_KERNEL);
10608
+ if (!dbg_reg_buf)
10609
+ return -ENOMEM;
10610
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_READ_DIRECT, -1, -1);
10611
+ req.host_dest_addr = cpu_to_le64(mapping);
10612
+ req.read_addr = cpu_to_le32(reg_off + CHIMP_REG_VIEW_ADDR);
10613
+ req.read_len32 = cpu_to_le32(num_words);
10614
+ mutex_lock(&bp->hwrm_cmd_lock);
10615
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
10616
+ if (rc || resp->error_code) {
10617
+ rc = -EIO;
10618
+ goto dbg_rd_reg_exit;
10619
+ }
10620
+ for (i = 0; i < num_words; i++)
10621
+ reg_buf[i] = le32_to_cpu(dbg_reg_buf[i]);
10622
+
10623
+dbg_rd_reg_exit:
10624
+ mutex_unlock(&bp->hwrm_cmd_lock);
10625
+ dma_free_coherent(&bp->pdev->dev, num_words * 4, dbg_reg_buf, mapping);
10626
+ return rc;
10627
+}
10628
+
10629
+static int bnxt_dbg_hwrm_ring_info_get(struct bnxt *bp, u8 ring_type,
10630
+ u32 ring_id, u32 *prod, u32 *cons)
10631
+{
10632
+ struct hwrm_dbg_ring_info_get_output *resp = bp->hwrm_cmd_resp_addr;
10633
+ struct hwrm_dbg_ring_info_get_input req = {0};
10634
+ int rc;
10635
+
10636
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_RING_INFO_GET, -1, -1);
10637
+ req.ring_type = ring_type;
10638
+ req.fw_ring_id = cpu_to_le32(ring_id);
10639
+ mutex_lock(&bp->hwrm_cmd_lock);
10640
+ rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
10641
+ if (!rc) {
10642
+ *prod = le32_to_cpu(resp->producer_index);
10643
+ *cons = le32_to_cpu(resp->consumer_index);
10644
+ }
10645
+ mutex_unlock(&bp->hwrm_cmd_lock);
768610646 return rc;
768710647 }
768810648
....@@ -7737,6 +10697,23 @@
773710697 }
773810698 }
773910699
10700
+static int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int ring_nr)
10701
+{
10702
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
10703
+ struct hwrm_ring_reset_input req = {0};
10704
+ struct bnxt_napi *bnapi = rxr->bnapi;
10705
+ struct bnxt_cp_ring_info *cpr;
10706
+ u16 cp_ring_id;
10707
+
10708
+ cpr = &bnapi->cp_ring;
10709
+ cp_ring_id = cpr->cp_ring_struct.fw_ring_id;
10710
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_RESET, cp_ring_id, -1);
10711
+ req.ring_type = RING_RESET_REQ_RING_TYPE_RX_RING_GRP;
10712
+ req.ring_id = cpu_to_le16(bp->grp_info[bnapi->index].fw_grp_id);
10713
+ return hwrm_send_message_silent(bp, &req, sizeof(req),
10714
+ HWRM_CMD_TIMEOUT);
10715
+}
10716
+
774010717 static void bnxt_reset_task(struct bnxt *bp, bool silent)
774110718 {
774210719 if (!silent)
....@@ -7744,16 +10721,19 @@
774410721 if (netif_running(bp->dev)) {
774510722 int rc;
774610723
7747
- if (!silent)
10724
+ if (silent) {
10725
+ bnxt_close_nic(bp, false, false);
10726
+ bnxt_open_nic(bp, false, false);
10727
+ } else {
774810728 bnxt_ulp_stop(bp);
7749
- bnxt_close_nic(bp, false, false);
7750
- rc = bnxt_open_nic(bp, false, false);
7751
- if (!silent && !rc)
7752
- bnxt_ulp_start(bp);
10729
+ bnxt_close_nic(bp, true, false);
10730
+ rc = bnxt_open_nic(bp, true, false);
10731
+ bnxt_ulp_start(bp, rc);
10732
+ }
775310733 }
775410734 }
775510735
7756
-static void bnxt_tx_timeout(struct net_device *dev)
10736
+static void bnxt_tx_timeout(struct net_device *dev, unsigned int txqueue)
775710737 {
775810738 struct bnxt *bp = netdev_priv(dev);
775910739
....@@ -7762,19 +10742,54 @@
776210742 bnxt_queue_sp_work(bp);
776310743 }
776410744
10745
+static void bnxt_fw_health_check(struct bnxt *bp)
10746
+{
10747
+ struct bnxt_fw_health *fw_health = bp->fw_health;
10748
+ u32 val;
10749
+
10750
+ if (!fw_health->enabled || test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
10751
+ return;
10752
+
10753
+ /* Make sure it is enabled before checking the tmr_counter. */
10754
+ smp_rmb();
10755
+ if (fw_health->tmr_counter) {
10756
+ fw_health->tmr_counter--;
10757
+ return;
10758
+ }
10759
+
10760
+ val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
10761
+ if (val == fw_health->last_fw_heartbeat)
10762
+ goto fw_reset;
10763
+
10764
+ fw_health->last_fw_heartbeat = val;
10765
+
10766
+ val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
10767
+ if (val != fw_health->last_fw_reset_cnt)
10768
+ goto fw_reset;
10769
+
10770
+ fw_health->tmr_counter = fw_health->tmr_multiplier;
10771
+ return;
10772
+
10773
+fw_reset:
10774
+ set_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event);
10775
+ bnxt_queue_sp_work(bp);
10776
+}
10777
+
776510778 static void bnxt_timer(struct timer_list *t)
776610779 {
776710780 struct bnxt *bp = from_timer(bp, t, timer);
776810781 struct net_device *dev = bp->dev;
776910782
7770
- if (!netif_running(dev))
10783
+ if (!netif_running(dev) || !test_bit(BNXT_STATE_OPEN, &bp->state))
777110784 return;
777210785
777310786 if (atomic_read(&bp->intr_sem) != 0)
777410787 goto bnxt_restart_timer;
777510788
7776
- if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
7777
- bp->stats_coal_ticks) {
10789
+ if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
10790
+ bnxt_fw_health_check(bp);
10791
+
10792
+ if (bp->link_info.link_up && bp->stats_coal_ticks) {
777810793 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
777910794 bnxt_queue_sp_work(bp);
778010795 }
....@@ -7784,14 +10799,27 @@
778410799 bnxt_queue_sp_work(bp);
778510800 }
778610801
10802
+#ifdef CONFIG_RFS_ACCEL
10803
+ if ((bp->flags & BNXT_FLAG_RFS) && bp->ntp_fltr_count) {
10804
+ set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
10805
+ bnxt_queue_sp_work(bp);
10806
+ }
10807
+#endif /*CONFIG_RFS_ACCEL*/
10808
+
778710809 if (bp->link_info.phy_retry) {
778810810 if (time_after(jiffies, bp->link_info.phy_retry_expires)) {
7789
- bp->link_info.phy_retry = 0;
10811
+ bp->link_info.phy_retry = false;
779010812 netdev_warn(bp->dev, "failed to update phy settings after maximum retries.\n");
779110813 } else {
779210814 set_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event);
779310815 bnxt_queue_sp_work(bp);
779410816 }
10817
+ }
10818
+
10819
+ if ((bp->flags & BNXT_FLAG_CHIP_P5) && !bp->chip_rev &&
10820
+ netif_carrier_ok(dev)) {
10821
+ set_bit(BNXT_RING_COAL_NOW_SP_EVENT, &bp->sp_event);
10822
+ bnxt_queue_sp_work(bp);
779510823 }
779610824 bnxt_restart_timer:
779710825 mod_timer(&bp->timer, jiffies + bp->current_interval);
....@@ -7823,7 +10851,266 @@
782310851 bnxt_rtnl_unlock_sp(bp);
782410852 }
782510853
10854
+/* Only called from bnxt_sp_task() */
10855
+static void bnxt_rx_ring_reset(struct bnxt *bp)
10856
+{
10857
+ int i;
10858
+
10859
+ bnxt_rtnl_lock_sp(bp);
10860
+ if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
10861
+ bnxt_rtnl_unlock_sp(bp);
10862
+ return;
10863
+ }
10864
+ /* Disable and flush TPA before resetting the RX ring */
10865
+ if (bp->flags & BNXT_FLAG_TPA)
10866
+ bnxt_set_tpa(bp, false);
10867
+ for (i = 0; i < bp->rx_nr_rings; i++) {
10868
+ struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
10869
+ struct bnxt_cp_ring_info *cpr;
10870
+ int rc;
10871
+
10872
+ if (!rxr->bnapi->in_reset)
10873
+ continue;
10874
+
10875
+ rc = bnxt_hwrm_rx_ring_reset(bp, i);
10876
+ if (rc) {
10877
+ if (rc == -EINVAL || rc == -EOPNOTSUPP)
10878
+ netdev_info_once(bp->dev, "RX ring reset not supported by firmware, falling back to global reset\n");
10879
+ else
10880
+ netdev_warn(bp->dev, "RX ring reset failed, rc = %d, falling back to global reset\n",
10881
+ rc);
10882
+ bnxt_reset_task(bp, true);
10883
+ break;
10884
+ }
10885
+ bnxt_free_one_rx_ring_skbs(bp, i);
10886
+ rxr->rx_prod = 0;
10887
+ rxr->rx_agg_prod = 0;
10888
+ rxr->rx_sw_agg_prod = 0;
10889
+ rxr->rx_next_cons = 0;
10890
+ rxr->bnapi->in_reset = false;
10891
+ bnxt_alloc_one_rx_ring(bp, i);
10892
+ cpr = &rxr->bnapi->cp_ring;
10893
+ cpr->sw_stats.rx.rx_resets++;
10894
+ if (bp->flags & BNXT_FLAG_AGG_RINGS)
10895
+ bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
10896
+ bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
10897
+ }
10898
+ if (bp->flags & BNXT_FLAG_TPA)
10899
+ bnxt_set_tpa(bp, true);
10900
+ bnxt_rtnl_unlock_sp(bp);
10901
+}
10902
+
10903
+static void bnxt_fw_reset_close(struct bnxt *bp)
10904
+{
10905
+ bnxt_ulp_stop(bp);
10906
+ /* When firmware is fatal state, disable PCI device to prevent
10907
+ * any potential bad DMAs before freeing kernel memory.
10908
+ */
10909
+ if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
10910
+ pci_disable_device(bp->pdev);
10911
+ __bnxt_close_nic(bp, true, false);
10912
+ bnxt_clear_int_mode(bp);
10913
+ bnxt_hwrm_func_drv_unrgtr(bp);
10914
+ if (pci_is_enabled(bp->pdev))
10915
+ pci_disable_device(bp->pdev);
10916
+ bnxt_free_ctx_mem(bp);
10917
+ kfree(bp->ctx);
10918
+ bp->ctx = NULL;
10919
+}
10920
+
10921
+static bool is_bnxt_fw_ok(struct bnxt *bp)
10922
+{
10923
+ struct bnxt_fw_health *fw_health = bp->fw_health;
10924
+ bool no_heartbeat = false, has_reset = false;
10925
+ u32 val;
10926
+
10927
+ val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
10928
+ if (val == fw_health->last_fw_heartbeat)
10929
+ no_heartbeat = true;
10930
+
10931
+ val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
10932
+ if (val != fw_health->last_fw_reset_cnt)
10933
+ has_reset = true;
10934
+
10935
+ if (!no_heartbeat && has_reset)
10936
+ return true;
10937
+
10938
+ return false;
10939
+}
10940
+
10941
+/* rtnl_lock is acquired before calling this function */
10942
+static void bnxt_force_fw_reset(struct bnxt *bp)
10943
+{
10944
+ struct bnxt_fw_health *fw_health = bp->fw_health;
10945
+ u32 wait_dsecs;
10946
+
10947
+ if (!test_bit(BNXT_STATE_OPEN, &bp->state) ||
10948
+ test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
10949
+ return;
10950
+
10951
+ set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
10952
+ bnxt_fw_reset_close(bp);
10953
+ wait_dsecs = fw_health->master_func_wait_dsecs;
10954
+ if (fw_health->master) {
10955
+ if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU)
10956
+ wait_dsecs = 0;
10957
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW;
10958
+ } else {
10959
+ bp->fw_reset_timestamp = jiffies + wait_dsecs * HZ / 10;
10960
+ wait_dsecs = fw_health->normal_func_wait_dsecs;
10961
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
10962
+ }
10963
+
10964
+ bp->fw_reset_min_dsecs = fw_health->post_reset_wait_dsecs;
10965
+ bp->fw_reset_max_dsecs = fw_health->post_reset_max_wait_dsecs;
10966
+ bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10);
10967
+}
10968
+
10969
+void bnxt_fw_exception(struct bnxt *bp)
10970
+{
10971
+ netdev_warn(bp->dev, "Detected firmware fatal condition, initiating reset\n");
10972
+ set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
10973
+ bnxt_rtnl_lock_sp(bp);
10974
+ bnxt_force_fw_reset(bp);
10975
+ bnxt_rtnl_unlock_sp(bp);
10976
+}
10977
+
10978
+/* Returns the number of registered VFs, or 1 if VF configuration is pending, or
10979
+ * < 0 on error.
10980
+ */
10981
+static int bnxt_get_registered_vfs(struct bnxt *bp)
10982
+{
10983
+#ifdef CONFIG_BNXT_SRIOV
10984
+ int rc;
10985
+
10986
+ if (!BNXT_PF(bp))
10987
+ return 0;
10988
+
10989
+ rc = bnxt_hwrm_func_qcfg(bp);
10990
+ if (rc) {
10991
+ netdev_err(bp->dev, "func_qcfg cmd failed, rc = %d\n", rc);
10992
+ return rc;
10993
+ }
10994
+ if (bp->pf.registered_vfs)
10995
+ return bp->pf.registered_vfs;
10996
+ if (bp->sriov_cfg)
10997
+ return 1;
10998
+#endif
10999
+ return 0;
11000
+}
11001
+
11002
+void bnxt_fw_reset(struct bnxt *bp)
11003
+{
11004
+ bnxt_rtnl_lock_sp(bp);
11005
+ if (test_bit(BNXT_STATE_OPEN, &bp->state) &&
11006
+ !test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
11007
+ int n = 0, tmo;
11008
+
11009
+ set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11010
+ if (bp->pf.active_vfs &&
11011
+ !test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
11012
+ n = bnxt_get_registered_vfs(bp);
11013
+ if (n < 0) {
11014
+ netdev_err(bp->dev, "Firmware reset aborted, rc = %d\n",
11015
+ n);
11016
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11017
+ dev_close(bp->dev);
11018
+ goto fw_reset_exit;
11019
+ } else if (n > 0) {
11020
+ u16 vf_tmo_dsecs = n * 10;
11021
+
11022
+ if (bp->fw_reset_max_dsecs < vf_tmo_dsecs)
11023
+ bp->fw_reset_max_dsecs = vf_tmo_dsecs;
11024
+ bp->fw_reset_state =
11025
+ BNXT_FW_RESET_STATE_POLL_VF;
11026
+ bnxt_queue_fw_reset_work(bp, HZ / 10);
11027
+ goto fw_reset_exit;
11028
+ }
11029
+ bnxt_fw_reset_close(bp);
11030
+ if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
11031
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW_DOWN;
11032
+ tmo = HZ / 10;
11033
+ } else {
11034
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
11035
+ tmo = bp->fw_reset_min_dsecs * HZ / 10;
11036
+ }
11037
+ bnxt_queue_fw_reset_work(bp, tmo);
11038
+ }
11039
+fw_reset_exit:
11040
+ bnxt_rtnl_unlock_sp(bp);
11041
+}
11042
+
11043
+static void bnxt_chk_missed_irq(struct bnxt *bp)
11044
+{
11045
+ int i;
11046
+
11047
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
11048
+ return;
11049
+
11050
+ for (i = 0; i < bp->cp_nr_rings; i++) {
11051
+ struct bnxt_napi *bnapi = bp->bnapi[i];
11052
+ struct bnxt_cp_ring_info *cpr;
11053
+ u32 fw_ring_id;
11054
+ int j;
11055
+
11056
+ if (!bnapi)
11057
+ continue;
11058
+
11059
+ cpr = &bnapi->cp_ring;
11060
+ for (j = 0; j < 2; j++) {
11061
+ struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
11062
+ u32 val[2];
11063
+
11064
+ if (!cpr2 || cpr2->has_more_work ||
11065
+ !bnxt_has_work(bp, cpr2))
11066
+ continue;
11067
+
11068
+ if (cpr2->cp_raw_cons != cpr2->last_cp_raw_cons) {
11069
+ cpr2->last_cp_raw_cons = cpr2->cp_raw_cons;
11070
+ continue;
11071
+ }
11072
+ fw_ring_id = cpr2->cp_ring_struct.fw_ring_id;
11073
+ bnxt_dbg_hwrm_ring_info_get(bp,
11074
+ DBG_RING_INFO_GET_REQ_RING_TYPE_L2_CMPL,
11075
+ fw_ring_id, &val[0], &val[1]);
11076
+ cpr->sw_stats.cmn.missed_irqs++;
11077
+ }
11078
+ }
11079
+}
11080
+
782611081 static void bnxt_cfg_ntp_filters(struct bnxt *);
11082
+
11083
+static void bnxt_init_ethtool_link_settings(struct bnxt *bp)
11084
+{
11085
+ struct bnxt_link_info *link_info = &bp->link_info;
11086
+
11087
+ if (BNXT_AUTO_MODE(link_info->auto_mode)) {
11088
+ link_info->autoneg = BNXT_AUTONEG_SPEED;
11089
+ if (bp->hwrm_spec_code >= 0x10201) {
11090
+ if (link_info->auto_pause_setting &
11091
+ PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
11092
+ link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
11093
+ } else {
11094
+ link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
11095
+ }
11096
+ link_info->advertising = link_info->auto_link_speeds;
11097
+ link_info->advertising_pam4 = link_info->auto_pam4_link_speeds;
11098
+ } else {
11099
+ link_info->req_link_speed = link_info->force_link_speed;
11100
+ link_info->req_signal_mode = BNXT_SIG_MODE_NRZ;
11101
+ if (link_info->force_pam4_link_speed) {
11102
+ link_info->req_link_speed =
11103
+ link_info->force_pam4_link_speed;
11104
+ link_info->req_signal_mode = BNXT_SIG_MODE_PAM4;
11105
+ }
11106
+ link_info->req_duplex = link_info->duplex_setting;
11107
+ }
11108
+ if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
11109
+ link_info->req_flow_ctrl =
11110
+ link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
11111
+ else
11112
+ link_info->req_flow_ctrl = link_info->force_pause_setting;
11113
+}
782711114
782811115 static void bnxt_sp_task(struct work_struct *work)
782911116 {
....@@ -7843,27 +11130,10 @@
784311130 bnxt_cfg_ntp_filters(bp);
784411131 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
784511132 bnxt_hwrm_exec_fwd_req(bp);
7846
- if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7847
- bnxt_hwrm_tunnel_dst_port_alloc(
7848
- bp, bp->vxlan_port,
7849
- TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7850
- }
7851
- if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7852
- bnxt_hwrm_tunnel_dst_port_free(
7853
- bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7854
- }
7855
- if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7856
- bnxt_hwrm_tunnel_dst_port_alloc(
7857
- bp, bp->nge_port,
7858
- TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7859
- }
7860
- if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7861
- bnxt_hwrm_tunnel_dst_port_free(
7862
- bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7863
- }
786411133 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
7865
- bnxt_hwrm_port_qstats(bp);
7866
- bnxt_hwrm_port_qstats_ext(bp);
11134
+ bnxt_hwrm_port_qstats(bp, 0);
11135
+ bnxt_hwrm_port_qstats_ext(bp, 0);
11136
+ bnxt_accumulate_all_stats(bp);
786711137 }
786811138
786911139 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
....@@ -7875,10 +11145,14 @@
787511145 bnxt_hwrm_phy_qcaps(bp);
787611146
787711147 rc = bnxt_update_link(bp, true);
7878
- mutex_unlock(&bp->link_lock);
787911148 if (rc)
788011149 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
788111150 rc);
11151
+
11152
+ if (test_and_clear_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT,
11153
+ &bp->sp_event))
11154
+ bnxt_init_ethtool_link_settings(bp);
11155
+ mutex_unlock(&bp->link_lock);
788211156 }
788311157 if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event)) {
788411158 int rc;
....@@ -7902,6 +11176,9 @@
790211176 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
790311177 bnxt_tc_flow_stats_work(bp);
790411178
11179
+ if (test_and_clear_bit(BNXT_RING_COAL_NOW_SP_EVENT, &bp->sp_event))
11180
+ bnxt_chk_missed_irq(bp);
11181
+
790511182 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
790611183 * must be the last functions to be called before exiting.
790711184 */
....@@ -7910,6 +11187,18 @@
791011187
791111188 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
791211189 bnxt_reset(bp, true);
11190
+
11191
+ if (test_and_clear_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event))
11192
+ bnxt_rx_ring_reset(bp);
11193
+
11194
+ if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event))
11195
+ bnxt_devlink_health_report(bp, BNXT_FW_RESET_NOTIFY_SP_EVENT);
11196
+
11197
+ if (test_and_clear_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event)) {
11198
+ if (!is_bnxt_fw_ok(bp))
11199
+ bnxt_devlink_health_report(bp,
11200
+ BNXT_FW_EXCEPTION_SP_EVENT);
11201
+ }
791311202
791411203 smp_mb__before_atomic();
791511204 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
....@@ -7920,7 +11209,7 @@
792011209 int tx_xdp)
792111210 {
792211211 int max_rx, max_tx, tx_sets = 1;
7923
- int tx_rings_needed;
11212
+ int tx_rings_needed, stats;
792411213 int rx_rings = rx;
792511214 int cp, vnics, rc;
792611215
....@@ -7939,16 +11228,19 @@
793911228 return -ENOMEM;
794011229
794111230 vnics = 1;
7942
- if (bp->flags & BNXT_FLAG_RFS)
11231
+ if ((bp->flags & (BNXT_FLAG_RFS | BNXT_FLAG_CHIP_P5)) == BNXT_FLAG_RFS)
794311232 vnics += rx_rings;
794411233
794511234 if (bp->flags & BNXT_FLAG_AGG_RINGS)
794611235 rx_rings <<= 1;
794711236 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
7948
- if (BNXT_NEW_RM(bp))
11237
+ stats = cp;
11238
+ if (BNXT_NEW_RM(bp)) {
794911239 cp += bnxt_get_ulp_msix_num(bp);
11240
+ stats += bnxt_get_ulp_stat_ctxs(bp);
11241
+ }
795011242 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7951
- vnics);
11243
+ stats, vnics);
795211244 }
795311245
795411246 static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
....@@ -7973,7 +11265,8 @@
797311265 {
797411266 bnxt_unmap_bars(bp, bp->pdev);
797511267 pci_release_regions(bp->pdev);
7976
- pci_disable_device(bp->pdev);
11268
+ if (pci_is_enabled(bp->pdev))
11269
+ pci_disable_device(bp->pdev);
797711270 }
797811271
797911272 static void bnxt_init_dflt_coal(struct bnxt *bp)
....@@ -7984,7 +11277,7 @@
798411277 * 1 coal_buf x bufs_per_record = 1 completion record.
798511278 */
798611279 coal = &bp->rx_coal;
7987
- coal->coal_ticks = 14;
11280
+ coal->coal_ticks = 10;
798811281 coal->coal_bufs = 30;
798911282 coal->coal_ticks_irq = 1;
799011283 coal->coal_bufs_irq = 2;
....@@ -8000,6 +11293,403 @@
800011293 coal->bufs_per_record = 1;
800111294
800211295 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
11296
+}
11297
+
11298
+static int bnxt_fw_reset_via_optee(struct bnxt *bp)
11299
+{
11300
+#ifdef CONFIG_TEE_BNXT_FW
11301
+ int rc = tee_bnxt_fw_load();
11302
+
11303
+ if (rc)
11304
+ netdev_err(bp->dev, "Failed FW reset via OP-TEE, rc=%d\n", rc);
11305
+
11306
+ return rc;
11307
+#else
11308
+ netdev_err(bp->dev, "OP-TEE not supported\n");
11309
+ return -ENODEV;
11310
+#endif
11311
+}
11312
+
11313
+static int bnxt_fw_init_one_p1(struct bnxt *bp)
11314
+{
11315
+ int rc;
11316
+
11317
+ bp->fw_cap = 0;
11318
+ rc = bnxt_hwrm_ver_get(bp);
11319
+ bnxt_try_map_fw_health_reg(bp);
11320
+ if (rc) {
11321
+ if (bp->fw_health && bp->fw_health->status_reliable) {
11322
+ u32 sts = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
11323
+
11324
+ netdev_err(bp->dev,
11325
+ "Firmware not responding, status: 0x%x\n",
11326
+ sts);
11327
+ if (sts & FW_STATUS_REG_CRASHED_NO_MASTER) {
11328
+ netdev_warn(bp->dev, "Firmware recover via OP-TEE requested\n");
11329
+ rc = bnxt_fw_reset_via_optee(bp);
11330
+ if (!rc)
11331
+ rc = bnxt_hwrm_ver_get(bp);
11332
+ }
11333
+ }
11334
+ if (rc)
11335
+ return rc;
11336
+ }
11337
+
11338
+ if (bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL) {
11339
+ rc = bnxt_alloc_kong_hwrm_resources(bp);
11340
+ if (rc)
11341
+ bp->fw_cap &= ~BNXT_FW_CAP_KONG_MB_CHNL;
11342
+ }
11343
+
11344
+ if ((bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) ||
11345
+ bp->hwrm_max_ext_req_len > BNXT_HWRM_MAX_REQ_LEN) {
11346
+ rc = bnxt_alloc_hwrm_short_cmd_req(bp);
11347
+ if (rc)
11348
+ return rc;
11349
+ }
11350
+ bnxt_nvm_cfg_ver_get(bp);
11351
+
11352
+ rc = bnxt_hwrm_func_reset(bp);
11353
+ if (rc)
11354
+ return -ENODEV;
11355
+
11356
+ bnxt_hwrm_fw_set_time(bp);
11357
+ return 0;
11358
+}
11359
+
11360
+static int bnxt_fw_init_one_p2(struct bnxt *bp)
11361
+{
11362
+ int rc;
11363
+
11364
+ /* Get the MAX capabilities for this function */
11365
+ rc = bnxt_hwrm_func_qcaps(bp);
11366
+ if (rc) {
11367
+ netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
11368
+ rc);
11369
+ return -ENODEV;
11370
+ }
11371
+
11372
+ rc = bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(bp);
11373
+ if (rc)
11374
+ netdev_warn(bp->dev, "hwrm query adv flow mgnt failure rc: %d\n",
11375
+ rc);
11376
+
11377
+ if (bnxt_alloc_fw_health(bp)) {
11378
+ netdev_warn(bp->dev, "no memory for firmware error recovery\n");
11379
+ } else {
11380
+ rc = bnxt_hwrm_error_recovery_qcfg(bp);
11381
+ if (rc)
11382
+ netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n",
11383
+ rc);
11384
+ }
11385
+
11386
+ rc = bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false);
11387
+ if (rc)
11388
+ return -ENODEV;
11389
+
11390
+ bnxt_hwrm_func_qcfg(bp);
11391
+ bnxt_hwrm_vnic_qcaps(bp);
11392
+ bnxt_hwrm_port_led_qcaps(bp);
11393
+ bnxt_ethtool_init(bp);
11394
+ bnxt_dcb_init(bp);
11395
+ return 0;
11396
+}
11397
+
11398
+static void bnxt_set_dflt_rss_hash_type(struct bnxt *bp)
11399
+{
11400
+ bp->flags &= ~BNXT_FLAG_UDP_RSS_CAP;
11401
+ bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
11402
+ VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
11403
+ VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
11404
+ VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
11405
+ if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
11406
+ bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
11407
+ bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
11408
+ VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
11409
+ }
11410
+}
11411
+
11412
+static void bnxt_set_dflt_rfs(struct bnxt *bp)
11413
+{
11414
+ struct net_device *dev = bp->dev;
11415
+
11416
+ dev->hw_features &= ~NETIF_F_NTUPLE;
11417
+ dev->features &= ~NETIF_F_NTUPLE;
11418
+ bp->flags &= ~BNXT_FLAG_RFS;
11419
+ if (bnxt_rfs_supported(bp)) {
11420
+ dev->hw_features |= NETIF_F_NTUPLE;
11421
+ if (bnxt_rfs_capable(bp)) {
11422
+ bp->flags |= BNXT_FLAG_RFS;
11423
+ dev->features |= NETIF_F_NTUPLE;
11424
+ }
11425
+ }
11426
+}
11427
+
11428
+static void bnxt_fw_init_one_p3(struct bnxt *bp)
11429
+{
11430
+ struct pci_dev *pdev = bp->pdev;
11431
+
11432
+ bnxt_set_dflt_rss_hash_type(bp);
11433
+ bnxt_set_dflt_rfs(bp);
11434
+
11435
+ bnxt_get_wol_settings(bp);
11436
+ if (bp->flags & BNXT_FLAG_WOL_CAP)
11437
+ device_set_wakeup_enable(&pdev->dev, bp->wol);
11438
+ else
11439
+ device_set_wakeup_capable(&pdev->dev, false);
11440
+
11441
+ bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
11442
+ bnxt_hwrm_coal_params_qcaps(bp);
11443
+}
11444
+
11445
+static int bnxt_probe_phy(struct bnxt *bp, bool fw_dflt);
11446
+
11447
+static int bnxt_fw_init_one(struct bnxt *bp)
11448
+{
11449
+ int rc;
11450
+
11451
+ rc = bnxt_fw_init_one_p1(bp);
11452
+ if (rc) {
11453
+ netdev_err(bp->dev, "Firmware init phase 1 failed\n");
11454
+ return rc;
11455
+ }
11456
+ rc = bnxt_fw_init_one_p2(bp);
11457
+ if (rc) {
11458
+ netdev_err(bp->dev, "Firmware init phase 2 failed\n");
11459
+ return rc;
11460
+ }
11461
+ rc = bnxt_probe_phy(bp, false);
11462
+ if (rc)
11463
+ return rc;
11464
+ rc = bnxt_approve_mac(bp, bp->dev->dev_addr, false);
11465
+ if (rc)
11466
+ return rc;
11467
+
11468
+ /* In case fw capabilities have changed, destroy the unneeded
11469
+ * reporters and create newly capable ones.
11470
+ */
11471
+ bnxt_dl_fw_reporters_destroy(bp, false);
11472
+ bnxt_dl_fw_reporters_create(bp);
11473
+ bnxt_fw_init_one_p3(bp);
11474
+ return 0;
11475
+}
11476
+
11477
+static void bnxt_fw_reset_writel(struct bnxt *bp, int reg_idx)
11478
+{
11479
+ struct bnxt_fw_health *fw_health = bp->fw_health;
11480
+ u32 reg = fw_health->fw_reset_seq_regs[reg_idx];
11481
+ u32 val = fw_health->fw_reset_seq_vals[reg_idx];
11482
+ u32 reg_type, reg_off, delay_msecs;
11483
+
11484
+ delay_msecs = fw_health->fw_reset_seq_delay_msec[reg_idx];
11485
+ reg_type = BNXT_FW_HEALTH_REG_TYPE(reg);
11486
+ reg_off = BNXT_FW_HEALTH_REG_OFF(reg);
11487
+ switch (reg_type) {
11488
+ case BNXT_FW_HEALTH_REG_TYPE_CFG:
11489
+ pci_write_config_dword(bp->pdev, reg_off, val);
11490
+ break;
11491
+ case BNXT_FW_HEALTH_REG_TYPE_GRC:
11492
+ writel(reg_off & BNXT_GRC_BASE_MASK,
11493
+ bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
11494
+ reg_off = (reg_off & BNXT_GRC_OFFSET_MASK) + 0x2000;
11495
+ fallthrough;
11496
+ case BNXT_FW_HEALTH_REG_TYPE_BAR0:
11497
+ writel(val, bp->bar0 + reg_off);
11498
+ break;
11499
+ case BNXT_FW_HEALTH_REG_TYPE_BAR1:
11500
+ writel(val, bp->bar1 + reg_off);
11501
+ break;
11502
+ }
11503
+ if (delay_msecs) {
11504
+ pci_read_config_dword(bp->pdev, 0, &val);
11505
+ msleep(delay_msecs);
11506
+ }
11507
+}
11508
+
11509
+static void bnxt_reset_all(struct bnxt *bp)
11510
+{
11511
+ struct bnxt_fw_health *fw_health = bp->fw_health;
11512
+ int i, rc;
11513
+
11514
+ if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
11515
+ bnxt_fw_reset_via_optee(bp);
11516
+ bp->fw_reset_timestamp = jiffies;
11517
+ return;
11518
+ }
11519
+
11520
+ if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_HOST) {
11521
+ for (i = 0; i < fw_health->fw_reset_seq_cnt; i++)
11522
+ bnxt_fw_reset_writel(bp, i);
11523
+ } else if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) {
11524
+ struct hwrm_fw_reset_input req = {0};
11525
+
11526
+ bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
11527
+ req.resp_addr = cpu_to_le64(bp->hwrm_cmd_kong_resp_dma_addr);
11528
+ req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP;
11529
+ req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP;
11530
+ req.flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL;
11531
+ rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
11532
+ if (rc)
11533
+ netdev_warn(bp->dev, "Unable to reset FW rc=%d\n", rc);
11534
+ }
11535
+ bp->fw_reset_timestamp = jiffies;
11536
+}
11537
+
11538
+static void bnxt_fw_reset_task(struct work_struct *work)
11539
+{
11540
+ struct bnxt *bp = container_of(work, struct bnxt, fw_reset_task.work);
11541
+ int rc;
11542
+
11543
+ if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
11544
+ netdev_err(bp->dev, "bnxt_fw_reset_task() called when not in fw reset mode!\n");
11545
+ return;
11546
+ }
11547
+
11548
+ switch (bp->fw_reset_state) {
11549
+ case BNXT_FW_RESET_STATE_POLL_VF: {
11550
+ int n = bnxt_get_registered_vfs(bp);
11551
+ int tmo;
11552
+
11553
+ if (n < 0) {
11554
+ netdev_err(bp->dev, "Firmware reset aborted, subsequent func_qcfg cmd failed, rc = %d, %d msecs since reset timestamp\n",
11555
+ n, jiffies_to_msecs(jiffies -
11556
+ bp->fw_reset_timestamp));
11557
+ goto fw_reset_abort;
11558
+ } else if (n > 0) {
11559
+ if (time_after(jiffies, bp->fw_reset_timestamp +
11560
+ (bp->fw_reset_max_dsecs * HZ / 10))) {
11561
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11562
+ bp->fw_reset_state = 0;
11563
+ netdev_err(bp->dev, "Firmware reset aborted, bnxt_get_registered_vfs() returns %d\n",
11564
+ n);
11565
+ return;
11566
+ }
11567
+ bnxt_queue_fw_reset_work(bp, HZ / 10);
11568
+ return;
11569
+ }
11570
+ bp->fw_reset_timestamp = jiffies;
11571
+ rtnl_lock();
11572
+ if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
11573
+ rtnl_unlock();
11574
+ goto fw_reset_abort;
11575
+ }
11576
+ bnxt_fw_reset_close(bp);
11577
+ if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
11578
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW_DOWN;
11579
+ tmo = HZ / 10;
11580
+ } else {
11581
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
11582
+ tmo = bp->fw_reset_min_dsecs * HZ / 10;
11583
+ }
11584
+ rtnl_unlock();
11585
+ bnxt_queue_fw_reset_work(bp, tmo);
11586
+ return;
11587
+ }
11588
+ case BNXT_FW_RESET_STATE_POLL_FW_DOWN: {
11589
+ u32 val;
11590
+
11591
+ val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
11592
+ if (!(val & BNXT_FW_STATUS_SHUTDOWN) &&
11593
+ !time_after(jiffies, bp->fw_reset_timestamp +
11594
+ (bp->fw_reset_max_dsecs * HZ / 10))) {
11595
+ bnxt_queue_fw_reset_work(bp, HZ / 5);
11596
+ return;
11597
+ }
11598
+
11599
+ if (!bp->fw_health->master) {
11600
+ u32 wait_dsecs = bp->fw_health->normal_func_wait_dsecs;
11601
+
11602
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
11603
+ bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10);
11604
+ return;
11605
+ }
11606
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW;
11607
+ }
11608
+ fallthrough;
11609
+ case BNXT_FW_RESET_STATE_RESET_FW:
11610
+ bnxt_reset_all(bp);
11611
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
11612
+ bnxt_queue_fw_reset_work(bp, bp->fw_reset_min_dsecs * HZ / 10);
11613
+ return;
11614
+ case BNXT_FW_RESET_STATE_ENABLE_DEV:
11615
+ if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) {
11616
+ u32 val;
11617
+
11618
+ val = bnxt_fw_health_readl(bp,
11619
+ BNXT_FW_RESET_INPROG_REG);
11620
+ if (val)
11621
+ netdev_warn(bp->dev, "FW reset inprog %x after min wait time.\n",
11622
+ val);
11623
+ }
11624
+ clear_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
11625
+ if (pci_enable_device(bp->pdev)) {
11626
+ netdev_err(bp->dev, "Cannot re-enable PCI device\n");
11627
+ goto fw_reset_abort;
11628
+ }
11629
+ pci_set_master(bp->pdev);
11630
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW;
11631
+ fallthrough;
11632
+ case BNXT_FW_RESET_STATE_POLL_FW:
11633
+ bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
11634
+ rc = __bnxt_hwrm_ver_get(bp, true);
11635
+ if (rc) {
11636
+ if (time_after(jiffies, bp->fw_reset_timestamp +
11637
+ (bp->fw_reset_max_dsecs * HZ / 10))) {
11638
+ netdev_err(bp->dev, "Firmware reset aborted\n");
11639
+ goto fw_reset_abort_status;
11640
+ }
11641
+ bnxt_queue_fw_reset_work(bp, HZ / 5);
11642
+ return;
11643
+ }
11644
+ bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
11645
+ bp->fw_reset_state = BNXT_FW_RESET_STATE_OPENING;
11646
+ fallthrough;
11647
+ case BNXT_FW_RESET_STATE_OPENING:
11648
+ while (!rtnl_trylock()) {
11649
+ bnxt_queue_fw_reset_work(bp, HZ / 10);
11650
+ return;
11651
+ }
11652
+ rc = bnxt_open(bp->dev);
11653
+ if (rc) {
11654
+ netdev_err(bp->dev, "bnxt_open_nic() failed\n");
11655
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11656
+ dev_close(bp->dev);
11657
+ }
11658
+
11659
+ if ((bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) &&
11660
+ bp->fw_health->enabled) {
11661
+ bp->fw_health->last_fw_reset_cnt =
11662
+ bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
11663
+ }
11664
+ bp->fw_reset_state = 0;
11665
+ /* Make sure fw_reset_state is 0 before clearing the flag */
11666
+ smp_mb__before_atomic();
11667
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11668
+ bnxt_ulp_start(bp, rc);
11669
+ if (!rc)
11670
+ bnxt_reenable_sriov(bp);
11671
+ bnxt_dl_health_recovery_done(bp);
11672
+ bnxt_dl_health_status_update(bp, true);
11673
+ rtnl_unlock();
11674
+ break;
11675
+ }
11676
+ return;
11677
+
11678
+fw_reset_abort_status:
11679
+ if (bp->fw_health->status_reliable ||
11680
+ (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) {
11681
+ u32 sts = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
11682
+
11683
+ netdev_err(bp->dev, "fw_health_status 0x%x\n", sts);
11684
+ }
11685
+fw_reset_abort:
11686
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
11687
+ if (bp->fw_reset_state != BNXT_FW_RESET_STATE_POLL_VF)
11688
+ bnxt_dl_health_status_update(bp, false);
11689
+ bp->fw_reset_state = 0;
11690
+ rtnl_lock();
11691
+ dev_close(bp->dev);
11692
+ rtnl_unlock();
800311693 }
800411694
800511695 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
....@@ -8041,16 +11731,12 @@
804111731 bp->dev = dev;
804211732 bp->pdev = pdev;
804311733
11734
+ /* Doorbell BAR bp->bar1 is mapped after bnxt_fw_init_one_p2()
11735
+ * determines the BAR size.
11736
+ */
804411737 bp->bar0 = pci_ioremap_bar(pdev, 0);
804511738 if (!bp->bar0) {
804611739 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
8047
- rc = -ENOMEM;
8048
- goto init_err_release;
8049
- }
8050
-
8051
- bp->bar1 = pci_ioremap_bar(pdev, 2);
8052
- if (!bp->bar1) {
8053
- dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
805411740 rc = -ENOMEM;
805511741 goto init_err_release;
805611742 }
....@@ -8065,8 +11751,12 @@
806511751 pci_enable_pcie_error_reporting(pdev);
806611752
806711753 INIT_WORK(&bp->sp_task, bnxt_sp_task);
11754
+ INIT_DELAYED_WORK(&bp->fw_reset_task, bnxt_fw_reset_task);
806811755
806911756 spin_lock_init(&bp->ntp_fltr_lock);
11757
+#if BITS_PER_LONG == 32
11758
+ spin_lock_init(&bp->db_lock);
11759
+#endif
807011760
807111761 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
807211762 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
....@@ -8075,6 +11765,9 @@
807511765
807611766 timer_setup(&bp->timer, bnxt_timer, 0);
807711767 bp->current_interval = BNXT_TIMER_INTERVAL;
11768
+
11769
+ bp->vxlan_fw_dst_port_id = INVALID_HW_RING_ID;
11770
+ bp->nge_fw_dst_port_id = INVALID_HW_RING_ID;
807811771
807911772 clear_bit(BNXT_STATE_OPEN, &bp->state);
808011773 return 0;
....@@ -8170,7 +11863,6 @@
817011863 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
817111864 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
817211865 bp->tx_nr_rings + bp->rx_nr_rings;
8173
- bp->num_stat_ctxs = bp->cp_nr_rings;
817411866
817511867 if (netif_running(bp->dev))
817611868 return bnxt_open_nic(bp, true, false);
....@@ -8195,32 +11887,19 @@
819511887 }
819611888 }
819711889
8198
-static int bnxt_setup_tc_block(struct net_device *dev,
8199
- struct tc_block_offload *f)
8200
-{
8201
- struct bnxt *bp = netdev_priv(dev);
8202
-
8203
- if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
8204
- return -EOPNOTSUPP;
8205
-
8206
- switch (f->command) {
8207
- case TC_BLOCK_BIND:
8208
- return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
8209
- bp, bp, f->extack);
8210
- case TC_BLOCK_UNBIND:
8211
- tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
8212
- return 0;
8213
- default:
8214
- return -EOPNOTSUPP;
8215
- }
8216
-}
11890
+LIST_HEAD(bnxt_block_cb_list);
821711891
821811892 static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
821911893 void *type_data)
822011894 {
11895
+ struct bnxt *bp = netdev_priv(dev);
11896
+
822111897 switch (type) {
822211898 case TC_SETUP_BLOCK:
8223
- return bnxt_setup_tc_block(dev, type_data);
11899
+ return flow_block_cb_setup_simple(type_data,
11900
+ &bnxt_block_cb_list,
11901
+ bnxt_setup_tc_block_cb,
11902
+ bp, bp, true);
822411903 case TC_SETUP_QDISC_MQPRIO: {
822511904 struct tc_mqprio_qopt *mqprio = type_data;
822611905
....@@ -8274,6 +11953,7 @@
827411953 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
827511954 int rc = 0, idx, bit_id, l2_idx = 0;
827611955 struct hlist_head *head;
11956
+ u32 flags;
827711957
827811958 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
827911959 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
....@@ -8313,8 +11993,9 @@
831311993 rc = -EPROTONOSUPPORT;
831411994 goto err_free;
831511995 }
8316
- if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
8317
- bp->hwrm_spec_code < 0x10601) {
11996
+ flags = fkeys->control.flags;
11997
+ if (((flags & FLOW_DIS_ENCAPSULATION) &&
11998
+ bp->hwrm_spec_code < 0x10601) || (flags & FLOW_DIS_IS_FRAGMENT)) {
831811999 rc = -EPROTONOSUPPORT;
831912000 goto err_free;
832012001 }
....@@ -8327,8 +12008,8 @@
832712008 rcu_read_lock();
832812009 hlist_for_each_entry_rcu(fltr, head, hash) {
832912010 if (bnxt_fltr_match(fltr, new_fltr)) {
12011
+ rc = fltr->sw_id;
833012012 rcu_read_unlock();
8331
- rc = 0;
833212013 goto err_free;
833312014 }
833412015 }
....@@ -8404,7 +12085,7 @@
840412085 }
840512086 }
840612087 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
8407
- netdev_info(bp->dev, "Receive PF driver unload event!");
12088
+ netdev_info(bp->dev, "Receive PF driver unload event!\n");
840812089 }
840912090
841012091 #else
....@@ -8415,84 +12096,33 @@
841512096
841612097 #endif /* CONFIG_RFS_ACCEL */
841712098
8418
-static void bnxt_udp_tunnel_add(struct net_device *dev,
8419
- struct udp_tunnel_info *ti)
12099
+static int bnxt_udp_tunnel_sync(struct net_device *netdev, unsigned int table)
842012100 {
8421
- struct bnxt *bp = netdev_priv(dev);
12101
+ struct bnxt *bp = netdev_priv(netdev);
12102
+ struct udp_tunnel_info ti;
12103
+ unsigned int cmd;
842212104
8423
- if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8424
- return;
12105
+ udp_tunnel_nic_get_port(netdev, table, 0, &ti);
12106
+ if (ti.type == UDP_TUNNEL_TYPE_VXLAN)
12107
+ cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN;
12108
+ else
12109
+ cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE;
842512110
8426
- if (!netif_running(dev))
8427
- return;
12111
+ if (ti.port)
12112
+ return bnxt_hwrm_tunnel_dst_port_alloc(bp, ti.port, cmd);
842812113
8429
- switch (ti->type) {
8430
- case UDP_TUNNEL_TYPE_VXLAN:
8431
- if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
8432
- return;
8433
-
8434
- bp->vxlan_port_cnt++;
8435
- if (bp->vxlan_port_cnt == 1) {
8436
- bp->vxlan_port = ti->port;
8437
- set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
8438
- bnxt_queue_sp_work(bp);
8439
- }
8440
- break;
8441
- case UDP_TUNNEL_TYPE_GENEVE:
8442
- if (bp->nge_port_cnt && bp->nge_port != ti->port)
8443
- return;
8444
-
8445
- bp->nge_port_cnt++;
8446
- if (bp->nge_port_cnt == 1) {
8447
- bp->nge_port = ti->port;
8448
- set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
8449
- }
8450
- break;
8451
- default:
8452
- return;
8453
- }
8454
-
8455
- bnxt_queue_sp_work(bp);
12114
+ return bnxt_hwrm_tunnel_dst_port_free(bp, cmd);
845612115 }
845712116
8458
-static void bnxt_udp_tunnel_del(struct net_device *dev,
8459
- struct udp_tunnel_info *ti)
8460
-{
8461
- struct bnxt *bp = netdev_priv(dev);
8462
-
8463
- if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8464
- return;
8465
-
8466
- if (!netif_running(dev))
8467
- return;
8468
-
8469
- switch (ti->type) {
8470
- case UDP_TUNNEL_TYPE_VXLAN:
8471
- if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
8472
- return;
8473
- bp->vxlan_port_cnt--;
8474
-
8475
- if (bp->vxlan_port_cnt != 0)
8476
- return;
8477
-
8478
- set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
8479
- break;
8480
- case UDP_TUNNEL_TYPE_GENEVE:
8481
- if (!bp->nge_port_cnt || bp->nge_port != ti->port)
8482
- return;
8483
- bp->nge_port_cnt--;
8484
-
8485
- if (bp->nge_port_cnt != 0)
8486
- return;
8487
-
8488
- set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
8489
- break;
8490
- default:
8491
- return;
8492
- }
8493
-
8494
- bnxt_queue_sp_work(bp);
8495
-}
12117
+static const struct udp_tunnel_nic_info bnxt_udp_tunnels = {
12118
+ .sync_table = bnxt_udp_tunnel_sync,
12119
+ .flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP |
12120
+ UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
12121
+ .tables = {
12122
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
12123
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_GENEVE, },
12124
+ },
12125
+};
849612126
849712127 static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
849812128 struct net_device *dev, u32 filter_mask,
....@@ -8505,7 +12135,7 @@
850512135 }
850612136
850712137 static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8508
- u16 flags)
12138
+ u16 flags, struct netlink_ext_ack *extack)
850912139 {
851012140 struct bnxt *bp = netdev_priv(dev);
851112141 struct nlattr *attr, *br_spec;
....@@ -8539,52 +12169,30 @@
853912169 return rc;
854012170 }
854112171
8542
-static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
8543
- size_t len)
12172
+int bnxt_get_port_parent_id(struct net_device *dev,
12173
+ struct netdev_phys_item_id *ppid)
854412174 {
854512175 struct bnxt *bp = netdev_priv(dev);
8546
- int rc;
854712176
8548
- /* The PF and it's VF-reps only support the switchdev framework */
8549
- if (!BNXT_PF(bp))
8550
- return -EOPNOTSUPP;
8551
-
8552
- rc = snprintf(buf, len, "p%d", bp->pf.port_id);
8553
-
8554
- if (rc >= len)
8555
- return -EOPNOTSUPP;
8556
- return 0;
8557
-}
8558
-
8559
-int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
8560
-{
856112177 if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
856212178 return -EOPNOTSUPP;
856312179
856412180 /* The PF and it's VF-reps only support the switchdev framework */
8565
- if (!BNXT_PF(bp))
12181
+ if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_DSN_VALID))
856612182 return -EOPNOTSUPP;
856712183
8568
- switch (attr->id) {
8569
- case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
8570
- attr->u.ppid.id_len = sizeof(bp->switch_id);
8571
- memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
8572
- break;
8573
- default:
8574
- return -EOPNOTSUPP;
8575
- }
12184
+ ppid->id_len = sizeof(bp->dsn);
12185
+ memcpy(ppid->id, bp->dsn, ppid->id_len);
12186
+
857612187 return 0;
857712188 }
857812189
8579
-static int bnxt_swdev_port_attr_get(struct net_device *dev,
8580
- struct switchdev_attr *attr)
12190
+static struct devlink_port *bnxt_get_devlink_port(struct net_device *dev)
858112191 {
8582
- return bnxt_port_attr_get(netdev_priv(dev), attr);
8583
-}
12192
+ struct bnxt *bp = netdev_priv(dev);
858412193
8585
-static const struct switchdev_ops bnxt_switchdev_ops = {
8586
- .switchdev_port_attr_get = bnxt_swdev_port_attr_get
8587
-};
12194
+ return &bp->dl_port;
12195
+}
858812196
858912197 static const struct net_device_ops bnxt_netdev_ops = {
859012198 .ndo_open = bnxt_open,
....@@ -8612,12 +12220,13 @@
861212220 #ifdef CONFIG_RFS_ACCEL
861312221 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
861412222 #endif
8615
- .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
8616
- .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
12223
+ .ndo_udp_tunnel_add = udp_tunnel_nic_add_port,
12224
+ .ndo_udp_tunnel_del = udp_tunnel_nic_del_port,
861712225 .ndo_bpf = bnxt_xdp,
12226
+ .ndo_xdp_xmit = bnxt_xdp_xmit,
861812227 .ndo_bridge_getlink = bnxt_bridge_getlink,
861912228 .ndo_bridge_setlink = bnxt_bridge_setlink,
8620
- .ndo_get_phys_port_name = bnxt_get_phys_port_name
12229
+ .ndo_get_devlink_port = bnxt_get_devlink_port,
862112230 };
862212231
862312232 static void bnxt_remove_one(struct pci_dev *pdev)
....@@ -8625,16 +12234,22 @@
862512234 struct net_device *dev = pci_get_drvdata(pdev);
862612235 struct bnxt *bp = netdev_priv(dev);
862712236
8628
- if (BNXT_PF(bp)) {
12237
+ if (BNXT_PF(bp))
862912238 bnxt_sriov_disable(bp);
8630
- bnxt_dl_unregister(bp);
8631
- }
863212239
12240
+ if (BNXT_PF(bp))
12241
+ devlink_port_type_clear(&bp->dl_port);
863312242 pci_disable_pcie_error_reporting(pdev);
863412243 unregister_netdev(dev);
8635
- bnxt_shutdown_tc(bp);
8636
- bnxt_cancel_sp_work(bp);
12244
+ clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
12245
+ /* Flush any pending tasks */
12246
+ cancel_work_sync(&bp->sp_task);
12247
+ cancel_delayed_work_sync(&bp->fw_reset_task);
863712248 bp->sp_event = 0;
12249
+
12250
+ bnxt_dl_fw_reporters_destroy(bp, true);
12251
+ bnxt_dl_unregister(bp);
12252
+ bnxt_shutdown_tc(bp);
863812253
863912254 bnxt_clear_int_mode(bp);
864012255 bnxt_hwrm_func_drv_unrgtr(bp);
....@@ -8644,11 +12259,19 @@
864412259 bnxt_dcb_free(bp);
864512260 kfree(bp->edev);
864612261 bp->edev = NULL;
12262
+ kfree(bp->fw_health);
12263
+ bp->fw_health = NULL;
864712264 bnxt_cleanup_pci(bp);
12265
+ bnxt_free_ctx_mem(bp);
12266
+ kfree(bp->ctx);
12267
+ bp->ctx = NULL;
12268
+ kfree(bp->rss_indir_tbl);
12269
+ bp->rss_indir_tbl = NULL;
12270
+ bnxt_free_port_stats(bp);
864812271 free_netdev(dev);
864912272 }
865012273
8651
-static int bnxt_probe_phy(struct bnxt *bp)
12274
+static int bnxt_probe_phy(struct bnxt *bp, bool fw_dflt)
865212275 {
865312276 int rc = 0;
865412277 struct bnxt_link_info *link_info = &bp->link_info;
....@@ -8659,7 +12282,8 @@
865912282 rc);
866012283 return rc;
866112284 }
8662
- mutex_init(&bp->link_lock);
12285
+ if (!fw_dflt)
12286
+ return 0;
866312287
866412288 rc = bnxt_update_link(bp, false);
866512289 if (rc) {
....@@ -8674,27 +12298,8 @@
867412298 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
867512299 link_info->support_auto_speeds = link_info->support_speeds;
867612300
8677
- /*initialize the ethool setting copy with NVM settings */
8678
- if (BNXT_AUTO_MODE(link_info->auto_mode)) {
8679
- link_info->autoneg = BNXT_AUTONEG_SPEED;
8680
- if (bp->hwrm_spec_code >= 0x10201) {
8681
- if (link_info->auto_pause_setting &
8682
- PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
8683
- link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8684
- } else {
8685
- link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8686
- }
8687
- link_info->advertising = link_info->auto_link_speeds;
8688
- } else {
8689
- link_info->req_link_speed = link_info->force_link_speed;
8690
- link_info->req_duplex = link_info->duplex_setting;
8691
- }
8692
- if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
8693
- link_info->req_flow_ctrl =
8694
- link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
8695
- else
8696
- link_info->req_flow_ctrl = link_info->force_pause_setting;
8697
- return rc;
12301
+ bnxt_init_ethtool_link_settings(bp);
12302
+ return 0;
869812303 }
869912304
870012305 static int bnxt_get_max_irq(struct pci_dev *pdev)
....@@ -8712,13 +12317,16 @@
871212317 int *max_cp)
871312318 {
871412319 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
8715
- int max_ring_grps = 0;
12320
+ int max_ring_grps = 0, max_irq;
871612321
871712322 *max_tx = hw_resc->max_tx_rings;
871812323 *max_rx = hw_resc->max_rx_rings;
8719
- *max_cp = min_t(int, bnxt_get_max_func_cp_rings_for_en(bp),
8720
- hw_resc->max_irqs - bnxt_get_ulp_msix_num(bp));
8721
- *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
12324
+ *max_cp = bnxt_get_max_func_cp_rings_for_en(bp);
12325
+ max_irq = min_t(int, bnxt_get_max_func_irqs(bp) -
12326
+ bnxt_get_ulp_msix_num(bp),
12327
+ hw_resc->max_stat_ctxs - bnxt_get_ulp_stat_ctxs(bp));
12328
+ if (!(bp->flags & BNXT_FLAG_CHIP_P5))
12329
+ *max_cp = min_t(int, *max_cp, max_irq);
872212330 max_ring_grps = hw_resc->max_hw_ring_grps;
872312331 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
872412332 *max_cp -= 1;
....@@ -8726,6 +12334,11 @@
872612334 }
872712335 if (bp->flags & BNXT_FLAG_AGG_RINGS)
872812336 *max_rx >>= 1;
12337
+ if (bp->flags & BNXT_FLAG_CHIP_P5) {
12338
+ bnxt_trim_rings(bp, max_rx, max_tx, *max_cp, false);
12339
+ /* On P5 chips, max_cp output param should be available NQs */
12340
+ *max_cp = max_irq;
12341
+ }
872912342 *max_rx = min_t(int, *max_rx, max_ring_grps);
873012343 }
873112344
....@@ -8807,7 +12420,7 @@
880712420
880812421 if (sh)
880912422 bp->flags |= BNXT_FLAG_SHARED_RINGS;
8810
- dflt_rings = netif_get_num_default_rss_queues();
12423
+ dflt_rings = is_kdump_kernel() ? 1 : netif_get_num_default_rss_queues();
881112424 /* Reduce default rings on multi-port cards so that total default
881212425 * rings do not exceed CPU count.
881312426 */
....@@ -8842,7 +12455,6 @@
884212455 netdev_warn(bp->dev, "2nd rings reservation failed.\n");
884312456 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
884412457 }
8845
- bp->num_stat_ctxs = bp->cp_nr_rings;
884612458 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
884712459 bp->rx_nr_rings++;
884812460 bp->cp_nr_rings++;
....@@ -8873,10 +12485,9 @@
887312485 goto init_dflt_ring_err;
887412486
887512487 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8876
- if (bnxt_rfs_supported(bp) && bnxt_rfs_capable(bp)) {
8877
- bp->flags |= BNXT_FLAG_RFS;
8878
- bp->dev->features |= NETIF_F_NTUPLE;
8879
- }
12488
+
12489
+ bnxt_set_dflt_rfs(bp);
12490
+
888012491 init_dflt_ring_err:
888112492 bnxt_ulp_irq_restart(bp, rc);
888212493 return rc;
....@@ -8934,9 +12545,94 @@
893412545 return rc;
893512546 }
893612547
12548
+#define BNXT_VPD_LEN 512
12549
+static void bnxt_vpd_read_info(struct bnxt *bp)
12550
+{
12551
+ struct pci_dev *pdev = bp->pdev;
12552
+ int i, len, pos, ro_size, size;
12553
+ ssize_t vpd_size;
12554
+ u8 *vpd_data;
12555
+
12556
+ vpd_data = kmalloc(BNXT_VPD_LEN, GFP_KERNEL);
12557
+ if (!vpd_data)
12558
+ return;
12559
+
12560
+ vpd_size = pci_read_vpd(pdev, 0, BNXT_VPD_LEN, vpd_data);
12561
+ if (vpd_size <= 0) {
12562
+ netdev_err(bp->dev, "Unable to read VPD\n");
12563
+ goto exit;
12564
+ }
12565
+
12566
+ i = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
12567
+ if (i < 0) {
12568
+ netdev_err(bp->dev, "VPD READ-Only not found\n");
12569
+ goto exit;
12570
+ }
12571
+
12572
+ ro_size = pci_vpd_lrdt_size(&vpd_data[i]);
12573
+ i += PCI_VPD_LRDT_TAG_SIZE;
12574
+ if (i + ro_size > vpd_size)
12575
+ goto exit;
12576
+
12577
+ pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size,
12578
+ PCI_VPD_RO_KEYWORD_PARTNO);
12579
+ if (pos < 0)
12580
+ goto read_sn;
12581
+
12582
+ len = pci_vpd_info_field_size(&vpd_data[pos]);
12583
+ pos += PCI_VPD_INFO_FLD_HDR_SIZE;
12584
+ if (len + pos > vpd_size)
12585
+ goto read_sn;
12586
+
12587
+ size = min(len, BNXT_VPD_FLD_LEN - 1);
12588
+ memcpy(bp->board_partno, &vpd_data[pos], size);
12589
+
12590
+read_sn:
12591
+ pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size,
12592
+ PCI_VPD_RO_KEYWORD_SERIALNO);
12593
+ if (pos < 0)
12594
+ goto exit;
12595
+
12596
+ len = pci_vpd_info_field_size(&vpd_data[pos]);
12597
+ pos += PCI_VPD_INFO_FLD_HDR_SIZE;
12598
+ if (len + pos > vpd_size)
12599
+ goto exit;
12600
+
12601
+ size = min(len, BNXT_VPD_FLD_LEN - 1);
12602
+ memcpy(bp->board_serialno, &vpd_data[pos], size);
12603
+exit:
12604
+ kfree(vpd_data);
12605
+}
12606
+
12607
+static int bnxt_pcie_dsn_get(struct bnxt *bp, u8 dsn[])
12608
+{
12609
+ struct pci_dev *pdev = bp->pdev;
12610
+ u64 qword;
12611
+
12612
+ qword = pci_get_dsn(pdev);
12613
+ if (!qword) {
12614
+ netdev_info(bp->dev, "Unable to read adapter's DSN\n");
12615
+ return -EOPNOTSUPP;
12616
+ }
12617
+
12618
+ put_unaligned_le64(qword, dsn);
12619
+
12620
+ bp->flags |= BNXT_FLAG_DSN_VALID;
12621
+ return 0;
12622
+}
12623
+
12624
+static int bnxt_map_db_bar(struct bnxt *bp)
12625
+{
12626
+ if (!bp->db_size)
12627
+ return -ENODEV;
12628
+ bp->bar1 = pci_iomap(bp->pdev, 2, bp->db_size);
12629
+ if (!bp->bar1)
12630
+ return -ENOMEM;
12631
+ return 0;
12632
+}
12633
+
893712634 static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
893812635 {
8939
- static int version_printed;
894012636 struct net_device *dev;
894112637 struct bnxt *bp;
894212638 int rc, max_irqs;
....@@ -8944,8 +12640,13 @@
894412640 if (pci_is_bridge(pdev))
894512641 return -ENODEV;
894612642
8947
- if (version_printed++ == 0)
8948
- pr_info("%s", version);
12643
+ /* Clear any pending DMA transactions from crash kernel
12644
+ * while loading driver in capture kernel.
12645
+ */
12646
+ if (is_kdump_kernel()) {
12647
+ pci_clear_master(pdev);
12648
+ pcie_flr(pdev);
12649
+ }
894912650
895012651 max_irqs = bnxt_get_max_irq(pdev);
895112652 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
....@@ -8953,6 +12654,8 @@
895312654 return -ENOMEM;
895412655
895512656 bp = netdev_priv(dev);
12657
+ bp->msg_enable = BNXT_DEF_MSG_ENABLE;
12658
+ bnxt_set_max_func_irqs(bp, max_irqs);
895612659
895712660 if (bnxt_vf_pciid(ent->driver_data))
895812661 bp->flags |= BNXT_FLAG_VF;
....@@ -8967,29 +12670,42 @@
896712670 dev->netdev_ops = &bnxt_netdev_ops;
896812671 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
896912672 dev->ethtool_ops = &bnxt_ethtool_ops;
8970
- SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
897112673 pci_set_drvdata(pdev, dev);
12674
+
12675
+ if (BNXT_PF(bp))
12676
+ bnxt_vpd_read_info(bp);
897212677
897312678 rc = bnxt_alloc_hwrm_resources(bp);
897412679 if (rc)
897512680 goto init_err_pci_clean;
897612681
897712682 mutex_init(&bp->hwrm_cmd_lock);
8978
- rc = bnxt_hwrm_ver_get(bp);
12683
+ mutex_init(&bp->link_lock);
12684
+
12685
+ rc = bnxt_fw_init_one_p1(bp);
897912686 if (rc)
898012687 goto init_err_pci_clean;
898112688
8982
- if (bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) {
8983
- rc = bnxt_alloc_hwrm_short_cmd_req(bp);
8984
- if (rc)
8985
- goto init_err_pci_clean;
12689
+ if (BNXT_CHIP_P5(bp)) {
12690
+ bp->flags |= BNXT_FLAG_CHIP_P5;
12691
+ if (BNXT_CHIP_SR2(bp))
12692
+ bp->flags |= BNXT_FLAG_CHIP_SR2;
898612693 }
898712694
8988
- rc = bnxt_hwrm_func_reset(bp);
12695
+ rc = bnxt_alloc_rss_indir_tbl(bp);
898912696 if (rc)
899012697 goto init_err_pci_clean;
899112698
8992
- bnxt_hwrm_fw_set_time(bp);
12699
+ rc = bnxt_fw_init_one_p2(bp);
12700
+ if (rc)
12701
+ goto init_err_pci_clean;
12702
+
12703
+ rc = bnxt_map_db_bar(bp);
12704
+ if (rc) {
12705
+ dev_err(&pdev->dev, "Cannot map doorbell BAR rc = %d, aborting\n",
12706
+ rc);
12707
+ goto init_err_pci_clean;
12708
+ }
899312709
899412710 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
899512711 NETIF_F_TSO | NETIF_F_TSO6 |
....@@ -8999,7 +12715,7 @@
899912715 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
900012716 NETIF_F_RXCSUM | NETIF_F_GRO;
900112717
9002
- if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
12718
+ if (BNXT_SUPPORTS_TPA(bp))
900312719 dev->hw_features |= NETIF_F_LRO;
900412720
900512721 dev->hw_enc_features =
....@@ -9008,12 +12724,16 @@
900812724 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
900912725 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
901012726 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
12727
+ dev->udp_tunnel_nic_info = &bnxt_udp_tunnels;
12728
+
901112729 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
901212730 NETIF_F_GSO_GRE_CSUM;
901312731 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
9014
- dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
9015
- NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
9016
- if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
12732
+ if (bp->fw_cap & BNXT_FW_CAP_VLAN_RX_STRIP)
12733
+ dev->hw_features |= BNXT_HW_FEATURE_VLAN_ALL_RX;
12734
+ if (bp->fw_cap & BNXT_FW_CAP_VLAN_TX_INSERT)
12735
+ dev->hw_features |= BNXT_HW_FEATURE_VLAN_ALL_TX;
12736
+ if (BNXT_SUPPORTS_TPA(bp))
901712737 dev->hw_features |= NETIF_F_GRO_HW;
901812738 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
901912739 if (dev->features & NETIF_F_GRO_HW)
....@@ -9024,61 +12744,41 @@
902412744 init_waitqueue_head(&bp->sriov_cfg_wait);
902512745 mutex_init(&bp->sriov_lock);
902612746 #endif
9027
- bp->gro_func = bnxt_gro_func_5730x;
9028
- if (BNXT_CHIP_P4_PLUS(bp))
9029
- bp->gro_func = bnxt_gro_func_5731x;
9030
- else
12747
+ if (BNXT_SUPPORTS_TPA(bp)) {
12748
+ bp->gro_func = bnxt_gro_func_5730x;
12749
+ if (BNXT_CHIP_P4(bp))
12750
+ bp->gro_func = bnxt_gro_func_5731x;
12751
+ else if (BNXT_CHIP_P5(bp))
12752
+ bp->gro_func = bnxt_gro_func_5750x;
12753
+ }
12754
+ if (!BNXT_CHIP_P4_PLUS(bp))
903112755 bp->flags |= BNXT_FLAG_DOUBLE_DB;
9032
-
9033
- rc = bnxt_hwrm_func_drv_rgtr(bp);
9034
- if (rc)
9035
- goto init_err_pci_clean;
9036
-
9037
- rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
9038
- if (rc)
9039
- goto init_err_pci_clean;
904012756
904112757 bp->ulp_probe = bnxt_ulp_probe;
904212758
9043
- /* Get the MAX capabilities for this function */
9044
- rc = bnxt_hwrm_func_qcaps(bp);
9045
- if (rc) {
9046
- netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
9047
- rc);
9048
- rc = -1;
9049
- goto init_err_pci_clean;
9050
- }
905112759 rc = bnxt_init_mac_addr(bp);
905212760 if (rc) {
905312761 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
905412762 rc = -EADDRNOTAVAIL;
905512763 goto init_err_pci_clean;
905612764 }
9057
- rc = bnxt_hwrm_queue_qportcfg(bp);
9058
- if (rc) {
9059
- netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
9060
- rc);
9061
- rc = -1;
9062
- goto init_err_pci_clean;
9063
- }
906412765
9065
- bnxt_hwrm_func_qcfg(bp);
9066
- bnxt_hwrm_port_led_qcaps(bp);
9067
- bnxt_ethtool_init(bp);
9068
- bnxt_dcb_init(bp);
12766
+ if (BNXT_PF(bp)) {
12767
+ /* Read the adapter's DSN to use as the eswitch switch_id */
12768
+ rc = bnxt_pcie_dsn_get(bp, bp->dsn);
12769
+ }
906912770
907012771 /* MTU range: 60 - FW defined max */
907112772 dev->min_mtu = ETH_ZLEN;
907212773 dev->max_mtu = bp->max_mtu;
907312774
9074
- rc = bnxt_probe_phy(bp);
12775
+ rc = bnxt_probe_phy(bp, true);
907512776 if (rc)
907612777 goto init_err_pci_clean;
907712778
907812779 bnxt_set_rx_skb_mode(bp, false);
907912780 bnxt_set_tpa_flags(bp);
908012781 bnxt_set_ring_params(bp);
9081
- bnxt_set_max_func_irqs(bp, max_irqs);
908212782 rc = bnxt_set_dflt_rings(bp, true);
908312783 if (rc) {
908412784 netdev_err(bp->dev, "Not enough rings available.\n");
....@@ -9086,27 +12786,9 @@
908612786 goto init_err_pci_clean;
908712787 }
908812788
9089
- /* Default RSS hash cfg. */
9090
- bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
9091
- VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
9092
- VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
9093
- VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
9094
- if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
9095
- bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
9096
- bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
9097
- VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
9098
- }
12789
+ bnxt_fw_init_one_p3(bp);
909912790
9100
- bnxt_hwrm_vnic_qcaps(bp);
9101
- if (bnxt_rfs_supported(bp)) {
9102
- dev->hw_features |= NETIF_F_NTUPLE;
9103
- if (bnxt_rfs_capable(bp)) {
9104
- bp->flags |= BNXT_FLAG_RFS;
9105
- dev->features |= NETIF_F_NTUPLE;
9106
- }
9107
- }
9108
-
9109
- if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
12791
+ if (dev->hw_features & BNXT_HW_FEATURE_VLAN_ALL_RX)
911012792 bp->flags |= BNXT_FLAG_STRIP_VLAN;
911112793
911212794 rc = bnxt_init_int_mode(bp);
....@@ -9118,14 +12800,6 @@
911812800 */
911912801 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
912012802
9121
- bnxt_get_wol_settings(bp);
9122
- if (bp->flags & BNXT_FLAG_WOL_CAP)
9123
- device_set_wakeup_enable(&pdev->dev, bp->wol);
9124
- else
9125
- device_set_wakeup_capable(&pdev->dev, false);
9126
-
9127
- bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
9128
-
912912803 if (BNXT_PF(bp)) {
913012804 if (!bnxt_pf_wq) {
913112805 bnxt_pf_wq =
....@@ -9136,15 +12810,21 @@
913612810 goto init_err_pci_clean;
913712811 }
913812812 }
9139
- bnxt_init_tc(bp);
12813
+ rc = bnxt_init_tc(bp);
12814
+ if (rc)
12815
+ netdev_err(dev, "Failed to initialize TC flower offload, err = %d.\n",
12816
+ rc);
914012817 }
12818
+
12819
+ bnxt_dl_register(bp);
914112820
914212821 rc = register_netdev(dev);
914312822 if (rc)
9144
- goto init_err_cleanup_tc;
12823
+ goto init_err_cleanup;
914512824
914612825 if (BNXT_PF(bp))
9147
- bnxt_dl_register(bp);
12826
+ devlink_port_type_eth_set(&bp->dl_port, bp->dev);
12827
+ bnxt_dl_fw_reporters_create(bp);
914812828
914912829 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
915012830 board_info[ent->driver_data].name,
....@@ -9154,14 +12834,24 @@
915412834 pci_save_state(pdev);
915512835 return 0;
915612836
9157
-init_err_cleanup_tc:
12837
+init_err_cleanup:
12838
+ bnxt_dl_unregister(bp);
915812839 bnxt_shutdown_tc(bp);
915912840 bnxt_clear_int_mode(bp);
916012841
916112842 init_err_pci_clean:
12843
+ bnxt_hwrm_func_drv_unrgtr(bp);
916212844 bnxt_free_hwrm_short_cmd_req(bp);
916312845 bnxt_free_hwrm_resources(bp);
12846
+ bnxt_ethtool_free(bp);
12847
+ kfree(bp->fw_health);
12848
+ bp->fw_health = NULL;
916412849 bnxt_cleanup_pci(bp);
12850
+ bnxt_free_ctx_mem(bp);
12851
+ kfree(bp->ctx);
12852
+ bp->ctx = NULL;
12853
+ kfree(bp->rss_indir_tbl);
12854
+ bp->rss_indir_tbl = NULL;
916512855
916612856 init_err_free:
916712857 free_netdev(dev);
....@@ -9185,9 +12875,10 @@
918512875 dev_close(dev);
918612876
918712877 bnxt_ulp_shutdown(bp);
12878
+ bnxt_clear_int_mode(bp);
12879
+ pci_disable_device(pdev);
918812880
918912881 if (system_state == SYSTEM_POWER_OFF) {
9190
- bnxt_clear_int_mode(bp);
919112882 pci_wake_from_d3(pdev, bp->wol);
919212883 pci_set_power_state(pdev, PCI_D3hot);
919312884 }
....@@ -9199,30 +12890,40 @@
919912890 #ifdef CONFIG_PM_SLEEP
920012891 static int bnxt_suspend(struct device *device)
920112892 {
9202
- struct pci_dev *pdev = to_pci_dev(device);
9203
- struct net_device *dev = pci_get_drvdata(pdev);
12893
+ struct net_device *dev = dev_get_drvdata(device);
920412894 struct bnxt *bp = netdev_priv(dev);
920512895 int rc = 0;
920612896
920712897 rtnl_lock();
12898
+ bnxt_ulp_stop(bp);
920812899 if (netif_running(dev)) {
920912900 netif_device_detach(dev);
921012901 rc = bnxt_close(dev);
921112902 }
921212903 bnxt_hwrm_func_drv_unrgtr(bp);
12904
+ pci_disable_device(bp->pdev);
12905
+ bnxt_free_ctx_mem(bp);
12906
+ kfree(bp->ctx);
12907
+ bp->ctx = NULL;
921312908 rtnl_unlock();
921412909 return rc;
921512910 }
921612911
921712912 static int bnxt_resume(struct device *device)
921812913 {
9219
- struct pci_dev *pdev = to_pci_dev(device);
9220
- struct net_device *dev = pci_get_drvdata(pdev);
12914
+ struct net_device *dev = dev_get_drvdata(device);
922112915 struct bnxt *bp = netdev_priv(dev);
922212916 int rc = 0;
922312917
922412918 rtnl_lock();
9225
- if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
12919
+ rc = pci_enable_device(bp->pdev);
12920
+ if (rc) {
12921
+ netdev_err(dev, "Cannot re-enable PCI device during resume, err = %d\n",
12922
+ rc);
12923
+ goto resume_exit;
12924
+ }
12925
+ pci_set_master(bp->pdev);
12926
+ if (bnxt_hwrm_ver_get(bp)) {
922612927 rc = -ENODEV;
922712928 goto resume_exit;
922812929 }
....@@ -9231,6 +12932,16 @@
923112932 rc = -EBUSY;
923212933 goto resume_exit;
923312934 }
12935
+
12936
+ rc = bnxt_hwrm_func_qcaps(bp);
12937
+ if (rc)
12938
+ goto resume_exit;
12939
+
12940
+ if (bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false)) {
12941
+ rc = -ENODEV;
12942
+ goto resume_exit;
12943
+ }
12944
+
923412945 bnxt_get_wol_settings(bp);
923512946 if (netif_running(dev)) {
923612947 rc = bnxt_open(dev);
....@@ -9239,6 +12950,9 @@
923912950 }
924012951
924112952 resume_exit:
12953
+ bnxt_ulp_start(bp, rc);
12954
+ if (!rc)
12955
+ bnxt_reenable_sriov(bp);
924212956 rtnl_unlock();
924312957 return rc;
924412958 }
....@@ -9278,10 +12992,17 @@
927812992 return PCI_ERS_RESULT_DISCONNECT;
927912993 }
928012994
12995
+ if (state == pci_channel_io_frozen)
12996
+ set_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state);
12997
+
928112998 if (netif_running(netdev))
928212999 bnxt_close(netdev);
928313000
9284
- pci_disable_device(pdev);
13001
+ if (pci_is_enabled(pdev))
13002
+ pci_disable_device(pdev);
13003
+ bnxt_free_ctx_mem(bp);
13004
+ kfree(bp->ctx);
13005
+ bp->ctx = NULL;
928513006 rtnl_unlock();
928613007
928713008 /* Request a slot slot reset. */
....@@ -9299,10 +13020,10 @@
929913020 */
930013021 static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
930113022 {
13023
+ pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
930213024 struct net_device *netdev = pci_get_drvdata(pdev);
930313025 struct bnxt *bp = netdev_priv(netdev);
9304
- int err = 0;
9305
- pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
13026
+ int err = 0, off;
930613027
930713028 netdev_info(bp->dev, "PCI Slot Reset\n");
930813029
....@@ -9313,33 +13034,29 @@
931313034 "Cannot re-enable PCI device after reset.\n");
931413035 } else {
931513036 pci_set_master(pdev);
13037
+ /* Upon fatal error, our device internal logic that latches to
13038
+ * BAR value is getting reset and will restore only upon
13039
+ * rewritting the BARs.
13040
+ *
13041
+ * As pci_restore_state() does not re-write the BARs if the
13042
+ * value is same as saved value earlier, driver needs to
13043
+ * write the BARs to 0 to force restore, in case of fatal error.
13044
+ */
13045
+ if (test_and_clear_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN,
13046
+ &bp->state)) {
13047
+ for (off = PCI_BASE_ADDRESS_0;
13048
+ off <= PCI_BASE_ADDRESS_5; off += 4)
13049
+ pci_write_config_dword(bp->pdev, off, 0);
13050
+ }
931613051 pci_restore_state(pdev);
931713052 pci_save_state(pdev);
931813053
931913054 err = bnxt_hwrm_func_reset(bp);
9320
- if (!err && netif_running(netdev))
9321
- err = bnxt_open(netdev);
9322
-
9323
- if (!err) {
13055
+ if (!err)
932413056 result = PCI_ERS_RESULT_RECOVERED;
9325
- bnxt_ulp_start(bp);
9326
- }
9327
- }
9328
-
9329
- if (result != PCI_ERS_RESULT_RECOVERED) {
9330
- if (netif_running(netdev))
9331
- dev_close(netdev);
9332
- pci_disable_device(pdev);
933313057 }
933413058
933513059 rtnl_unlock();
9336
-
9337
- err = pci_cleanup_aer_uncorrect_error_status(pdev);
9338
- if (err) {
9339
- dev_err(&pdev->dev,
9340
- "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9341
- err); /* non-fatal, continue */
9342
- }
934313060
934413061 return result;
934513062 }
....@@ -9354,10 +13071,21 @@
935413071 static void bnxt_io_resume(struct pci_dev *pdev)
935513072 {
935613073 struct net_device *netdev = pci_get_drvdata(pdev);
13074
+ struct bnxt *bp = netdev_priv(netdev);
13075
+ int err;
935713076
13077
+ netdev_info(bp->dev, "PCI Slot Resume\n");
935813078 rtnl_lock();
935913079
9360
- netif_device_attach(netdev);
13080
+ err = bnxt_hwrm_func_qcaps(bp);
13081
+ if (!err && netif_running(netdev))
13082
+ err = bnxt_open(netdev);
13083
+
13084
+ bnxt_ulp_start(bp, err);
13085
+ if (!err) {
13086
+ bnxt_reenable_sriov(bp);
13087
+ netif_device_attach(netdev);
13088
+ }
936113089
936213090 rtnl_unlock();
936313091 }
....@@ -9383,8 +13111,16 @@
938313111
938413112 static int __init bnxt_init(void)
938513113 {
13114
+ int err;
13115
+
938613116 bnxt_debug_init();
9387
- return pci_register_driver(&bnxt_pci_driver);
13117
+ err = pci_register_driver(&bnxt_pci_driver);
13118
+ if (err) {
13119
+ bnxt_debug_exit();
13120
+ return err;
13121
+ }
13122
+
13123
+ return 0;
938813124 }
938913125
939013126 static void __exit bnxt_exit(void)