1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2017 Broadcom Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
11 #include <linux/module.h>
13 #include <linux/stringify.h>
14 #include <linux/kernel.h>
15 #include <linux/timer.h>
16 #include <linux/errno.h>
17 #include <linux/ioport.h>
18 #include <linux/slab.h>
19 #include <linux/vmalloc.h>
20 #include <linux/interrupt.h>
21 #include <linux/pci.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/bitops.h>
28 #include <linux/irq.h>
29 #include <linux/delay.h>
30 #include <asm/byteorder.h>
32 #include <linux/time.h>
33 #include <linux/mii.h>
35 #include <linux/if_vlan.h>
36 #include <linux/rtc.h>
37 #include <linux/bpf.h>
41 #include <net/checksum.h>
42 #include <net/ip6_checksum.h>
43 #include <net/udp_tunnel.h>
44 #include <linux/workqueue.h>
45 #include <linux/prefetch.h>
46 #include <linux/cache.h>
47 #include <linux/log2.h>
48 #include <linux/aer.h>
49 #include <linux/bitmap.h>
50 #include <linux/cpu_rmap.h>
55 #include "bnxt_sriov.h"
56 #include "bnxt_ethtool.h"
60 #define BNXT_TX_TIMEOUT (5 * HZ)
62 static const char version[] =
63 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
65 MODULE_LICENSE("GPL");
66 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
67 MODULE_VERSION(DRV_MODULE_VERSION);
69 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
70 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
71 #define BNXT_RX_COPY_THRESH 256
73 #define BNXT_TX_PUSH_THRESH 164
108 /* indexed by enum above */
109 static const struct {
112 { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
113 { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
114 { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
115 { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
116 { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
117 { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
118 { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
119 { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
120 { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
121 { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
122 { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
123 { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
124 { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
125 { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
126 { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
127 { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
128 { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
129 { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
130 { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
131 { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
132 { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
133 { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
134 { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
135 { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
136 { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
137 { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
138 { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
139 { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
140 { "Broadcom NetXtreme-E Ethernet Virtual Function" },
141 { "Broadcom NetXtreme-C Ethernet Virtual Function" },
144 static const struct pci_device_id bnxt_pci_tbl[] = {
145 { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
146 { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
147 { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
148 { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
149 { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
150 { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
151 { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
152 { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
153 { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
154 { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
155 { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
156 { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
157 { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
158 { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
159 { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
160 { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
161 { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
162 { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
163 { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
164 { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
165 { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
166 { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
167 { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
168 { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
169 { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
170 { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
171 { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
172 { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
173 { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
174 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
175 { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
176 { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
177 #ifdef CONFIG_BNXT_SRIOV
178 { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
179 { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
180 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
181 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
182 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
183 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
184 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
185 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
190 MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
192 static const u16 bnxt_vf_req_snif[] = {
195 HWRM_CFA_L2_FILTER_ALLOC,
198 static const u16 bnxt_async_events_arr[] = {
199 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
200 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
201 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
202 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
203 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
206 static bool bnxt_vf_pciid(enum board_idx idx)
208 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF);
211 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
212 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
213 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
215 #define BNXT_CP_DB_REARM(db, raw_cons) \
216 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
218 #define BNXT_CP_DB(db, raw_cons) \
219 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
221 #define BNXT_CP_DB_IRQ_DIS(db) \
222 writel(DB_CP_IRQ_DIS_FLAGS, db)
224 const u16 bnxt_lhint_arr[] = {
225 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
226 TX_BD_FLAGS_LHINT_512_TO_1023,
227 TX_BD_FLAGS_LHINT_1024_TO_2047,
228 TX_BD_FLAGS_LHINT_1024_TO_2047,
229 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
230 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
231 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
232 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
233 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
234 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
235 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
236 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
237 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
238 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
239 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
240 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
241 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
242 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
243 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
246 static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
248 struct bnxt *bp = netdev_priv(dev);
250 struct tx_bd_ext *txbd1;
251 struct netdev_queue *txq;
254 unsigned int length, pad = 0;
255 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
257 struct pci_dev *pdev = bp->pdev;
258 struct bnxt_tx_ring_info *txr;
259 struct bnxt_sw_tx_bd *tx_buf;
261 i = skb_get_queue_mapping(skb);
262 if (unlikely(i >= bp->tx_nr_rings)) {
263 dev_kfree_skb_any(skb);
267 txq = netdev_get_tx_queue(dev, i);
268 txr = &bp->tx_ring[bp->tx_ring_map[i]];
271 free_size = bnxt_tx_avail(bp, txr);
272 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
273 netif_tx_stop_queue(txq);
274 return NETDEV_TX_BUSY;
278 len = skb_headlen(skb);
279 last_frag = skb_shinfo(skb)->nr_frags;
281 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
283 txbd->tx_bd_opaque = prod;
285 tx_buf = &txr->tx_buf_ring[prod];
287 tx_buf->nr_frags = last_frag;
291 if (skb_vlan_tag_present(skb)) {
292 vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
293 skb_vlan_tag_get(skb);
294 /* Currently supports 8021Q, 8021AD vlan offloads
295 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
297 if (skb->vlan_proto == htons(ETH_P_8021Q))
298 vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
301 if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
302 struct tx_push_buffer *tx_push_buf = txr->tx_push;
303 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
304 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
305 void *pdata = tx_push_buf->data;
309 /* Set COAL_NOW to be ready quickly for the next push */
310 tx_push->tx_bd_len_flags_type =
311 cpu_to_le32((length << TX_BD_LEN_SHIFT) |
312 TX_BD_TYPE_LONG_TX_BD |
313 TX_BD_FLAGS_LHINT_512_AND_SMALLER |
314 TX_BD_FLAGS_COAL_NOW |
315 TX_BD_FLAGS_PACKET_END |
316 (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
318 if (skb->ip_summed == CHECKSUM_PARTIAL)
319 tx_push1->tx_bd_hsize_lflags =
320 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
322 tx_push1->tx_bd_hsize_lflags = 0;
324 tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
325 tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
327 end = pdata + length;
328 end = PTR_ALIGN(end, 8) - 1;
331 skb_copy_from_linear_data(skb, pdata, len);
333 for (j = 0; j < last_frag; j++) {
334 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
337 fptr = skb_frag_address_safe(frag);
341 memcpy(pdata, fptr, skb_frag_size(frag));
342 pdata += skb_frag_size(frag);
345 txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
346 txbd->tx_bd_haddr = txr->data_mapping;
347 prod = NEXT_TX(prod);
348 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
349 memcpy(txbd, tx_push1, sizeof(*txbd));
350 prod = NEXT_TX(prod);
352 cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
356 netdev_tx_sent_queue(txq, skb->len);
357 wmb(); /* Sync is_push and byte queue before pushing data */
359 push_len = (length + sizeof(*tx_push) + 7) / 8;
361 __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
362 __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
363 (push_len - 16) << 1);
365 __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
373 if (length < BNXT_MIN_PKT_SIZE) {
374 pad = BNXT_MIN_PKT_SIZE - length;
375 if (skb_pad(skb, pad)) {
376 /* SKB already freed. */
380 length = BNXT_MIN_PKT_SIZE;
383 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
385 if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
386 dev_kfree_skb_any(skb);
391 dma_unmap_addr_set(tx_buf, mapping, mapping);
392 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
393 ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
395 txbd->tx_bd_haddr = cpu_to_le64(mapping);
397 prod = NEXT_TX(prod);
398 txbd1 = (struct tx_bd_ext *)
399 &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
401 txbd1->tx_bd_hsize_lflags = 0;
402 if (skb_is_gso(skb)) {
405 if (skb->encapsulation)
406 hdr_len = skb_inner_network_offset(skb) +
407 skb_inner_network_header_len(skb) +
408 inner_tcp_hdrlen(skb);
410 hdr_len = skb_transport_offset(skb) +
413 txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
415 (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
416 length = skb_shinfo(skb)->gso_size;
417 txbd1->tx_bd_mss = cpu_to_le32(length);
419 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
420 txbd1->tx_bd_hsize_lflags =
421 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
422 txbd1->tx_bd_mss = 0;
426 flags |= bnxt_lhint_arr[length];
427 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
429 txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
430 txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
431 for (i = 0; i < last_frag; i++) {
432 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
434 prod = NEXT_TX(prod);
435 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
437 len = skb_frag_size(frag);
438 mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
441 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
444 tx_buf = &txr->tx_buf_ring[prod];
445 dma_unmap_addr_set(tx_buf, mapping, mapping);
447 txbd->tx_bd_haddr = cpu_to_le64(mapping);
449 flags = len << TX_BD_LEN_SHIFT;
450 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
454 txbd->tx_bd_len_flags_type =
455 cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
456 TX_BD_FLAGS_PACKET_END);
458 netdev_tx_sent_queue(txq, skb->len);
460 /* Sync BD data before updating doorbell */
463 prod = NEXT_TX(prod);
466 if (!skb->xmit_more || netif_xmit_stopped(txq))
467 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
473 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
474 if (skb->xmit_more && !tx_buf->is_push)
475 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
477 netif_tx_stop_queue(txq);
479 /* netif_tx_stop_queue() must be done before checking
480 * tx index in bnxt_tx_avail() below, because in
481 * bnxt_tx_int(), we update tx index before checking for
482 * netif_tx_queue_stopped().
485 if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
486 netif_tx_wake_queue(txq);
493 /* start back at beginning and unmap skb */
495 tx_buf = &txr->tx_buf_ring[prod];
497 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
498 skb_headlen(skb), PCI_DMA_TODEVICE);
499 prod = NEXT_TX(prod);
501 /* unmap remaining mapped pages */
502 for (i = 0; i < last_frag; i++) {
503 prod = NEXT_TX(prod);
504 tx_buf = &txr->tx_buf_ring[prod];
505 dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
506 skb_frag_size(&skb_shinfo(skb)->frags[i]),
510 dev_kfree_skb_any(skb);
514 static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
516 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
517 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
518 u16 cons = txr->tx_cons;
519 struct pci_dev *pdev = bp->pdev;
521 unsigned int tx_bytes = 0;
523 for (i = 0; i < nr_pkts; i++) {
524 struct bnxt_sw_tx_bd *tx_buf;
528 tx_buf = &txr->tx_buf_ring[cons];
529 cons = NEXT_TX(cons);
533 if (tx_buf->is_push) {
538 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
539 skb_headlen(skb), PCI_DMA_TODEVICE);
540 last = tx_buf->nr_frags;
542 for (j = 0; j < last; j++) {
543 cons = NEXT_TX(cons);
544 tx_buf = &txr->tx_buf_ring[cons];
547 dma_unmap_addr(tx_buf, mapping),
548 skb_frag_size(&skb_shinfo(skb)->frags[j]),
553 cons = NEXT_TX(cons);
555 tx_bytes += skb->len;
556 dev_kfree_skb_any(skb);
559 netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
562 /* Need to make the tx_cons update visible to bnxt_start_xmit()
563 * before checking for netif_tx_queue_stopped(). Without the
564 * memory barrier, there is a small possibility that bnxt_start_xmit()
565 * will miss it and cause the queue to be stopped forever.
569 if (unlikely(netif_tx_queue_stopped(txq)) &&
570 (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
571 __netif_tx_lock(txq, smp_processor_id());
572 if (netif_tx_queue_stopped(txq) &&
573 bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
574 txr->dev_state != BNXT_DEV_STATE_CLOSING)
575 netif_tx_wake_queue(txq);
576 __netif_tx_unlock(txq);
580 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
583 struct device *dev = &bp->pdev->dev;
586 page = alloc_page(gfp);
590 *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
591 DMA_ATTR_WEAK_ORDERING);
592 if (dma_mapping_error(dev, *mapping)) {
596 *mapping += bp->rx_dma_offset;
600 static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
604 struct pci_dev *pdev = bp->pdev;
606 data = kmalloc(bp->rx_buf_size, gfp);
610 *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset,
611 bp->rx_buf_use_size, bp->rx_dir,
612 DMA_ATTR_WEAK_ORDERING);
614 if (dma_mapping_error(&pdev->dev, *mapping)) {
621 int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
624 struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
625 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
628 if (BNXT_RX_PAGE_MODE(bp)) {
629 struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
635 rx_buf->data_ptr = page_address(page) + bp->rx_offset;
637 u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
643 rx_buf->data_ptr = data + bp->rx_offset;
645 rx_buf->mapping = mapping;
647 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
651 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
653 u16 prod = rxr->rx_prod;
654 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
655 struct rx_bd *cons_bd, *prod_bd;
657 prod_rx_buf = &rxr->rx_buf_ring[prod];
658 cons_rx_buf = &rxr->rx_buf_ring[cons];
660 prod_rx_buf->data = data;
661 prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
663 prod_rx_buf->mapping = cons_rx_buf->mapping;
665 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
666 cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
668 prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
671 static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
673 u16 next, max = rxr->rx_agg_bmap_size;
675 next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
677 next = find_first_zero_bit(rxr->rx_agg_bmap, max);
681 static inline int bnxt_alloc_rx_page(struct bnxt *bp,
682 struct bnxt_rx_ring_info *rxr,
686 &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
687 struct bnxt_sw_rx_agg_bd *rx_agg_buf;
688 struct pci_dev *pdev = bp->pdev;
691 u16 sw_prod = rxr->rx_sw_agg_prod;
692 unsigned int offset = 0;
694 if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
697 page = alloc_page(gfp);
701 rxr->rx_page_offset = 0;
703 offset = rxr->rx_page_offset;
704 rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
705 if (rxr->rx_page_offset == PAGE_SIZE)
710 page = alloc_page(gfp);
715 mapping = dma_map_page_attrs(&pdev->dev, page, offset,
716 BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
717 DMA_ATTR_WEAK_ORDERING);
718 if (dma_mapping_error(&pdev->dev, mapping)) {
723 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
724 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
726 __set_bit(sw_prod, rxr->rx_agg_bmap);
727 rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
728 rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
730 rx_agg_buf->page = page;
731 rx_agg_buf->offset = offset;
732 rx_agg_buf->mapping = mapping;
733 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
734 rxbd->rx_bd_opaque = sw_prod;
738 static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
741 struct bnxt *bp = bnapi->bp;
742 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
743 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
744 u16 prod = rxr->rx_agg_prod;
745 u16 sw_prod = rxr->rx_sw_agg_prod;
748 for (i = 0; i < agg_bufs; i++) {
750 struct rx_agg_cmp *agg;
751 struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
752 struct rx_bd *prod_bd;
755 agg = (struct rx_agg_cmp *)
756 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
757 cons = agg->rx_agg_cmp_opaque;
758 __clear_bit(cons, rxr->rx_agg_bmap);
760 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
761 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
763 __set_bit(sw_prod, rxr->rx_agg_bmap);
764 prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
765 cons_rx_buf = &rxr->rx_agg_ring[cons];
767 /* It is possible for sw_prod to be equal to cons, so
768 * set cons_rx_buf->page to NULL first.
770 page = cons_rx_buf->page;
771 cons_rx_buf->page = NULL;
772 prod_rx_buf->page = page;
773 prod_rx_buf->offset = cons_rx_buf->offset;
775 prod_rx_buf->mapping = cons_rx_buf->mapping;
777 prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
779 prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
780 prod_bd->rx_bd_opaque = sw_prod;
782 prod = NEXT_RX_AGG(prod);
783 sw_prod = NEXT_RX_AGG(sw_prod);
784 cp_cons = NEXT_CMP(cp_cons);
786 rxr->rx_agg_prod = prod;
787 rxr->rx_sw_agg_prod = sw_prod;
790 static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
791 struct bnxt_rx_ring_info *rxr,
792 u16 cons, void *data, u8 *data_ptr,
794 unsigned int offset_and_len)
796 unsigned int payload = offset_and_len >> 16;
797 unsigned int len = offset_and_len & 0xffff;
798 struct skb_frag_struct *frag;
799 struct page *page = data;
800 u16 prod = rxr->rx_prod;
804 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
806 bnxt_reuse_rx_data(rxr, cons, data);
809 dma_addr -= bp->rx_dma_offset;
810 dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir,
811 DMA_ATTR_WEAK_ORDERING);
813 if (unlikely(!payload))
814 payload = eth_get_headlen(data_ptr, len);
816 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
822 off = (void *)data_ptr - page_address(page);
823 skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
824 memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
825 payload + NET_IP_ALIGN);
827 frag = &skb_shinfo(skb)->frags[0];
828 skb_frag_size_sub(frag, payload);
829 frag->page_offset += payload;
830 skb->data_len -= payload;
831 skb->tail += payload;
836 static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
837 struct bnxt_rx_ring_info *rxr, u16 cons,
838 void *data, u8 *data_ptr,
840 unsigned int offset_and_len)
842 u16 prod = rxr->rx_prod;
846 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
848 bnxt_reuse_rx_data(rxr, cons, data);
852 skb = build_skb(data, 0);
853 dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
854 bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
860 skb_reserve(skb, bp->rx_offset);
861 skb_put(skb, offset_and_len & 0xffff);
865 static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
866 struct sk_buff *skb, u16 cp_cons,
869 struct pci_dev *pdev = bp->pdev;
870 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
871 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
872 u16 prod = rxr->rx_agg_prod;
875 for (i = 0; i < agg_bufs; i++) {
877 struct rx_agg_cmp *agg;
878 struct bnxt_sw_rx_agg_bd *cons_rx_buf;
882 agg = (struct rx_agg_cmp *)
883 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
884 cons = agg->rx_agg_cmp_opaque;
885 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
886 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
888 cons_rx_buf = &rxr->rx_agg_ring[cons];
889 skb_fill_page_desc(skb, i, cons_rx_buf->page,
890 cons_rx_buf->offset, frag_len);
891 __clear_bit(cons, rxr->rx_agg_bmap);
893 /* It is possible for bnxt_alloc_rx_page() to allocate
894 * a sw_prod index that equals the cons index, so we
895 * need to clear the cons entry now.
897 mapping = cons_rx_buf->mapping;
898 page = cons_rx_buf->page;
899 cons_rx_buf->page = NULL;
901 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
902 struct skb_shared_info *shinfo;
903 unsigned int nr_frags;
905 shinfo = skb_shinfo(skb);
906 nr_frags = --shinfo->nr_frags;
907 __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
911 cons_rx_buf->page = page;
913 /* Update prod since possibly some pages have been
916 rxr->rx_agg_prod = prod;
917 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
921 dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
923 DMA_ATTR_WEAK_ORDERING);
925 skb->data_len += frag_len;
926 skb->len += frag_len;
927 skb->truesize += PAGE_SIZE;
929 prod = NEXT_RX_AGG(prod);
930 cp_cons = NEXT_CMP(cp_cons);
932 rxr->rx_agg_prod = prod;
936 static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
937 u8 agg_bufs, u32 *raw_cons)
940 struct rx_agg_cmp *agg;
942 *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
943 last = RING_CMP(*raw_cons);
944 agg = (struct rx_agg_cmp *)
945 &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
946 return RX_AGG_CMP_VALID(agg, *raw_cons);
949 static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
953 struct bnxt *bp = bnapi->bp;
954 struct pci_dev *pdev = bp->pdev;
957 skb = napi_alloc_skb(&bnapi->napi, len);
961 dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
964 memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
967 dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
974 static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
975 u32 *raw_cons, void *cmp)
977 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
978 struct rx_cmp *rxcmp = cmp;
979 u32 tmp_raw_cons = *raw_cons;
980 u8 cmp_type, agg_bufs = 0;
982 cmp_type = RX_CMP_TYPE(rxcmp);
984 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
985 agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
987 RX_CMP_AGG_BUFS_SHIFT;
988 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
989 struct rx_tpa_end_cmp *tpa_end = cmp;
991 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
992 RX_TPA_END_CMP_AGG_BUFS) >>
993 RX_TPA_END_CMP_AGG_BUFS_SHIFT;
997 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1000 *raw_cons = tmp_raw_cons;
1004 static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
1006 if (!rxr->bnapi->in_reset) {
1007 rxr->bnapi->in_reset = true;
1008 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
1009 schedule_work(&bp->sp_task);
1011 rxr->rx_next_cons = 0xffff;
1014 static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1015 struct rx_tpa_start_cmp *tpa_start,
1016 struct rx_tpa_start_cmp_ext *tpa_start1)
1018 u8 agg_id = TPA_START_AGG_ID(tpa_start);
1020 struct bnxt_tpa_info *tpa_info;
1021 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1022 struct rx_bd *prod_bd;
1025 cons = tpa_start->rx_tpa_start_cmp_opaque;
1026 prod = rxr->rx_prod;
1027 cons_rx_buf = &rxr->rx_buf_ring[cons];
1028 prod_rx_buf = &rxr->rx_buf_ring[prod];
1029 tpa_info = &rxr->rx_tpa[agg_id];
1031 if (unlikely(cons != rxr->rx_next_cons)) {
1032 bnxt_sched_reset(bp, rxr);
1036 prod_rx_buf->data = tpa_info->data;
1037 prod_rx_buf->data_ptr = tpa_info->data_ptr;
1039 mapping = tpa_info->mapping;
1040 prod_rx_buf->mapping = mapping;
1042 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1044 prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
1046 tpa_info->data = cons_rx_buf->data;
1047 tpa_info->data_ptr = cons_rx_buf->data_ptr;
1048 cons_rx_buf->data = NULL;
1049 tpa_info->mapping = cons_rx_buf->mapping;
1052 le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
1053 RX_TPA_START_CMP_LEN_SHIFT;
1054 if (likely(TPA_START_HASH_VALID(tpa_start))) {
1055 u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
1057 tpa_info->hash_type = PKT_HASH_TYPE_L4;
1058 tpa_info->gso_type = SKB_GSO_TCPV4;
1059 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1061 tpa_info->gso_type = SKB_GSO_TCPV6;
1062 tpa_info->rss_hash =
1063 le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
1065 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
1066 tpa_info->gso_type = 0;
1067 if (netif_msg_rx_err(bp))
1068 netdev_warn(bp->dev, "TPA packet without valid hash\n");
1070 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
1071 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
1072 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
1074 rxr->rx_prod = NEXT_RX(prod);
1075 cons = NEXT_RX(cons);
1076 rxr->rx_next_cons = NEXT_RX(cons);
1077 cons_rx_buf = &rxr->rx_buf_ring[cons];
1079 bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
1080 rxr->rx_prod = NEXT_RX(rxr->rx_prod);
1081 cons_rx_buf->data = NULL;
1084 static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1085 u16 cp_cons, u32 agg_bufs)
1088 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1091 static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
1092 int payload_off, int tcp_ts,
1093 struct sk_buff *skb)
1098 u16 outer_ip_off, inner_ip_off, inner_mac_off;
1099 u32 hdr_info = tpa_info->hdr_info;
1100 bool loopback = false;
1102 inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1103 inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1104 outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1106 /* If the packet is an internal loopback packet, the offsets will
1107 * have an extra 4 bytes.
1109 if (inner_mac_off == 4) {
1111 } else if (inner_mac_off > 4) {
1112 __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
1115 /* We only support inner iPv4/ipv6. If we don't see the
1116 * correct protocol ID, it must be a loopback packet where
1117 * the offsets are off by 4.
1119 if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
1123 /* internal loopback packet, subtract all offsets by 4 */
1129 nw_off = inner_ip_off - ETH_HLEN;
1130 skb_set_network_header(skb, nw_off);
1131 if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
1132 struct ipv6hdr *iph = ipv6_hdr(skb);
1134 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1135 len = skb->len - skb_transport_offset(skb);
1137 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1139 struct iphdr *iph = ip_hdr(skb);
1141 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1142 len = skb->len - skb_transport_offset(skb);
1144 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1147 if (inner_mac_off) { /* tunnel */
1148 struct udphdr *uh = NULL;
1149 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1152 if (proto == htons(ETH_P_IP)) {
1153 struct iphdr *iph = (struct iphdr *)skb->data;
1155 if (iph->protocol == IPPROTO_UDP)
1156 uh = (struct udphdr *)(iph + 1);
1158 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1160 if (iph->nexthdr == IPPROTO_UDP)
1161 uh = (struct udphdr *)(iph + 1);
1165 skb_shinfo(skb)->gso_type |=
1166 SKB_GSO_UDP_TUNNEL_CSUM;
1168 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1175 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1176 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1178 static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
1179 int payload_off, int tcp_ts,
1180 struct sk_buff *skb)
1184 int len, nw_off, tcp_opt_len = 0;
1189 if (tpa_info->gso_type == SKB_GSO_TCPV4) {
1192 nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
1194 skb_set_network_header(skb, nw_off);
1196 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1197 len = skb->len - skb_transport_offset(skb);
1199 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1200 } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
1201 struct ipv6hdr *iph;
1203 nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
1205 skb_set_network_header(skb, nw_off);
1206 iph = ipv6_hdr(skb);
1207 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1208 len = skb->len - skb_transport_offset(skb);
1210 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1212 dev_kfree_skb_any(skb);
1216 if (nw_off) { /* tunnel */
1217 struct udphdr *uh = NULL;
1219 if (skb->protocol == htons(ETH_P_IP)) {
1220 struct iphdr *iph = (struct iphdr *)skb->data;
1222 if (iph->protocol == IPPROTO_UDP)
1223 uh = (struct udphdr *)(iph + 1);
1225 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1227 if (iph->nexthdr == IPPROTO_UDP)
1228 uh = (struct udphdr *)(iph + 1);
1232 skb_shinfo(skb)->gso_type |=
1233 SKB_GSO_UDP_TUNNEL_CSUM;
1235 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1242 static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
1243 struct bnxt_tpa_info *tpa_info,
1244 struct rx_tpa_end_cmp *tpa_end,
1245 struct rx_tpa_end_cmp_ext *tpa_end1,
1246 struct sk_buff *skb)
1252 segs = TPA_END_TPA_SEGS(tpa_end);
1256 NAPI_GRO_CB(skb)->count = segs;
1257 skb_shinfo(skb)->gso_size =
1258 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
1259 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1260 payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1261 RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1262 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1263 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
1265 tcp_gro_complete(skb);
1270 static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1271 struct bnxt_napi *bnapi,
1273 struct rx_tpa_end_cmp *tpa_end,
1274 struct rx_tpa_end_cmp_ext *tpa_end1,
1277 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1278 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1279 u8 agg_id = TPA_END_AGG_ID(tpa_end);
1280 u8 *data_ptr, agg_bufs;
1281 u16 cp_cons = RING_CMP(*raw_cons);
1283 struct bnxt_tpa_info *tpa_info;
1285 struct sk_buff *skb;
1288 if (unlikely(bnapi->in_reset)) {
1289 int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1292 return ERR_PTR(-EBUSY);
1296 tpa_info = &rxr->rx_tpa[agg_id];
1297 data = tpa_info->data;
1298 data_ptr = tpa_info->data_ptr;
1300 len = tpa_info->len;
1301 mapping = tpa_info->mapping;
1303 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1304 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1307 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1308 return ERR_PTR(-EBUSY);
1310 *event |= BNXT_AGG_EVENT;
1311 cp_cons = NEXT_CMP(cp_cons);
1314 if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) {
1315 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1316 if (agg_bufs > MAX_SKB_FRAGS)
1317 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1318 agg_bufs, (int)MAX_SKB_FRAGS);
1322 if (len <= bp->rx_copy_thresh) {
1323 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
1325 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1330 dma_addr_t new_mapping;
1332 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
1334 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1338 tpa_info->data = new_data;
1339 tpa_info->data_ptr = new_data + bp->rx_offset;
1340 tpa_info->mapping = new_mapping;
1342 skb = build_skb(data, 0);
1343 dma_unmap_single_attrs(&bp->pdev->dev, mapping,
1344 bp->rx_buf_use_size, bp->rx_dir,
1345 DMA_ATTR_WEAK_ORDERING);
1349 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1352 skb_reserve(skb, bp->rx_offset);
1357 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1359 /* Page reuse already handled by bnxt_rx_pages(). */
1363 skb->protocol = eth_type_trans(skb, bp->dev);
1365 if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
1366 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
1368 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1369 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1370 u16 vlan_proto = tpa_info->metadata >>
1371 RX_CMP_FLAGS2_METADATA_TPID_SFT;
1372 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK;
1374 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1377 skb_checksum_none_assert(skb);
1378 if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
1379 skb->ip_summed = CHECKSUM_UNNECESSARY;
1381 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
1384 if (TPA_END_GRO(tpa_end))
1385 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
1390 /* returns the following:
1391 * 1 - 1 packet successfully received
1392 * 0 - successful TPA_START, packet not completed yet
1393 * -EBUSY - completion ring does not have all the agg buffers yet
1394 * -ENOMEM - packet aborted due to out of memory
1395 * -EIO - packet aborted due to hw error indicated in BD
1397 static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
1400 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1401 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1402 struct net_device *dev = bp->dev;
1403 struct rx_cmp *rxcmp;
1404 struct rx_cmp_ext *rxcmp1;
1405 u32 tmp_raw_cons = *raw_cons;
1406 u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
1407 struct bnxt_sw_rx_bd *rx_buf;
1409 u8 *data_ptr, agg_bufs, cmp_type;
1410 dma_addr_t dma_addr;
1411 struct sk_buff *skb;
1416 rxcmp = (struct rx_cmp *)
1417 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1419 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1420 cp_cons = RING_CMP(tmp_raw_cons);
1421 rxcmp1 = (struct rx_cmp_ext *)
1422 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1424 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1427 cmp_type = RX_CMP_TYPE(rxcmp);
1429 prod = rxr->rx_prod;
1431 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
1432 bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
1433 (struct rx_tpa_start_cmp_ext *)rxcmp1);
1435 *event |= BNXT_RX_EVENT;
1436 goto next_rx_no_prod;
1438 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1439 skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1440 (struct rx_tpa_end_cmp *)rxcmp,
1441 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
1443 if (unlikely(IS_ERR(skb)))
1448 skb_record_rx_queue(skb, bnapi->index);
1449 napi_gro_receive(&bnapi->napi, skb);
1452 *event |= BNXT_RX_EVENT;
1453 goto next_rx_no_prod;
1456 cons = rxcmp->rx_cmp_opaque;
1457 rx_buf = &rxr->rx_buf_ring[cons];
1458 data = rx_buf->data;
1459 data_ptr = rx_buf->data_ptr;
1460 if (unlikely(cons != rxr->rx_next_cons)) {
1461 int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1463 bnxt_sched_reset(bp, rxr);
1468 misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
1469 agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
1472 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1475 cp_cons = NEXT_CMP(cp_cons);
1476 *event |= BNXT_AGG_EVENT;
1478 *event |= BNXT_RX_EVENT;
1480 rx_buf->data = NULL;
1481 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
1482 bnxt_reuse_rx_data(rxr, cons, data);
1484 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1490 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
1491 dma_addr = rx_buf->mapping;
1493 if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
1498 if (len <= bp->rx_copy_thresh) {
1499 skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
1500 bnxt_reuse_rx_data(rxr, cons, data);
1508 if (rx_buf->data_ptr == data_ptr)
1509 payload = misc & RX_CMP_PAYLOAD_OFFSET;
1512 skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
1521 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1528 if (RX_CMP_HASH_VALID(rxcmp)) {
1529 u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
1530 enum pkt_hash_types type = PKT_HASH_TYPE_L4;
1532 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1533 if (hash_type != 1 && hash_type != 3)
1534 type = PKT_HASH_TYPE_L3;
1535 skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
1538 skb->protocol = eth_type_trans(skb, dev);
1540 if ((rxcmp1->rx_cmp_flags2 &
1541 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1542 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1543 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
1544 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK;
1545 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1547 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1550 skb_checksum_none_assert(skb);
1551 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1552 if (dev->features & NETIF_F_RXCSUM) {
1553 skb->ip_summed = CHECKSUM_UNNECESSARY;
1554 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1557 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1558 if (dev->features & NETIF_F_RXCSUM)
1559 cpr->rx_l4_csum_errors++;
1563 skb_record_rx_queue(skb, bnapi->index);
1564 napi_gro_receive(&bnapi->napi, skb);
1568 rxr->rx_prod = NEXT_RX(prod);
1569 rxr->rx_next_cons = NEXT_RX(cons);
1572 *raw_cons = tmp_raw_cons;
1577 /* In netpoll mode, if we are using a combined completion ring, we need to
1578 * discard the rx packets and recycle the buffers.
1580 static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi,
1581 u32 *raw_cons, u8 *event)
1583 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1584 u32 tmp_raw_cons = *raw_cons;
1585 struct rx_cmp_ext *rxcmp1;
1586 struct rx_cmp *rxcmp;
1590 cp_cons = RING_CMP(tmp_raw_cons);
1591 rxcmp = (struct rx_cmp *)
1592 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1594 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1595 cp_cons = RING_CMP(tmp_raw_cons);
1596 rxcmp1 = (struct rx_cmp_ext *)
1597 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1599 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1602 cmp_type = RX_CMP_TYPE(rxcmp);
1603 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1604 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1605 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1606 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1607 struct rx_tpa_end_cmp_ext *tpa_end1;
1609 tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1;
1610 tpa_end1->rx_tpa_end_cmp_errors_v2 |=
1611 cpu_to_le32(RX_TPA_END_CMP_ERRORS);
1613 return bnxt_rx_pkt(bp, bnapi, raw_cons, event);
1616 #define BNXT_GET_EVENT_PORT(data) \
1618 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
1620 static int bnxt_async_event_process(struct bnxt *bp,
1621 struct hwrm_async_event_cmpl *cmpl)
1623 u16 event_id = le16_to_cpu(cmpl->event_id);
1625 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1627 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
1628 u32 data1 = le32_to_cpu(cmpl->event_data1);
1629 struct bnxt_link_info *link_info = &bp->link_info;
1632 goto async_event_process_exit;
1633 if (data1 & 0x20000) {
1634 u16 fw_speed = link_info->force_link_speed;
1635 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1637 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1640 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
1643 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
1644 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
1646 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
1647 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
1649 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
1650 u32 data1 = le32_to_cpu(cmpl->event_data1);
1651 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1656 if (bp->pf.port_id != port_id)
1659 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1662 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
1664 goto async_event_process_exit;
1665 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1668 goto async_event_process_exit;
1670 schedule_work(&bp->sp_task);
1671 async_event_process_exit:
1672 bnxt_ulp_async_events(bp, cmpl);
1676 static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1678 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1679 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1680 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1681 (struct hwrm_fwd_req_cmpl *)txcmp;
1683 switch (cmpl_type) {
1684 case CMPL_BASE_TYPE_HWRM_DONE:
1685 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1686 if (seq_id == bp->hwrm_intr_seq_id)
1687 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1689 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1692 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1693 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1695 if ((vf_id < bp->pf.first_vf_id) ||
1696 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1697 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1702 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1703 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
1704 schedule_work(&bp->sp_task);
1707 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1708 bnxt_async_event_process(bp,
1709 (struct hwrm_async_event_cmpl *)txcmp);
1718 static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1720 struct bnxt_napi *bnapi = dev_instance;
1721 struct bnxt *bp = bnapi->bp;
1722 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1723 u32 cons = RING_CMP(cpr->cp_raw_cons);
1725 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1726 napi_schedule(&bnapi->napi);
1730 static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1732 u32 raw_cons = cpr->cp_raw_cons;
1733 u16 cons = RING_CMP(raw_cons);
1734 struct tx_cmp *txcmp;
1736 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1738 return TX_CMP_VALID(txcmp, raw_cons);
1741 static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1743 struct bnxt_napi *bnapi = dev_instance;
1744 struct bnxt *bp = bnapi->bp;
1745 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1746 u32 cons = RING_CMP(cpr->cp_raw_cons);
1749 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1751 if (!bnxt_has_work(bp, cpr)) {
1752 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
1753 /* return if erroneous interrupt */
1754 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1758 /* disable ring IRQ */
1759 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1761 /* Return here if interrupt is shared and is disabled. */
1762 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1765 napi_schedule(&bnapi->napi);
1769 static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1771 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1772 u32 raw_cons = cpr->cp_raw_cons;
1777 struct tx_cmp *txcmp;
1782 cons = RING_CMP(raw_cons);
1783 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1785 if (!TX_CMP_VALID(txcmp, raw_cons))
1788 /* The valid test of the entry must be done first before
1789 * reading any further.
1792 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1794 /* return full budget so NAPI will complete. */
1795 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1797 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1799 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1801 rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons,
1803 if (likely(rc >= 0))
1805 else if (rc == -EBUSY) /* partial completion */
1807 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1808 CMPL_BASE_TYPE_HWRM_DONE) ||
1809 (TX_CMP_TYPE(txcmp) ==
1810 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1811 (TX_CMP_TYPE(txcmp) ==
1812 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1813 bnxt_hwrm_handler(bp, txcmp);
1815 raw_cons = NEXT_RAW_CMP(raw_cons);
1817 if (rx_pkts == budget)
1821 if (event & BNXT_TX_EVENT) {
1822 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1823 void __iomem *db = txr->tx_doorbell;
1824 u16 prod = txr->tx_prod;
1826 /* Sync BD data before updating doorbell */
1829 bnxt_db_write(bp, db, DB_KEY_TX | prod);
1832 cpr->cp_raw_cons = raw_cons;
1833 /* ACK completion ring before freeing tx ring and producing new
1834 * buffers in rx/agg rings to prevent overflowing the completion
1837 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1840 bnapi->tx_int(bp, bnapi, tx_pkts);
1842 if (event & BNXT_RX_EVENT) {
1843 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1845 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1846 if (event & BNXT_AGG_EVENT)
1847 bnxt_db_write(bp, rxr->rx_agg_doorbell,
1848 DB_KEY_RX | rxr->rx_agg_prod);
1853 static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1855 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1856 struct bnxt *bp = bnapi->bp;
1857 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1858 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1859 struct tx_cmp *txcmp;
1860 struct rx_cmp_ext *rxcmp1;
1861 u32 cp_cons, tmp_raw_cons;
1862 u32 raw_cons = cpr->cp_raw_cons;
1869 cp_cons = RING_CMP(raw_cons);
1870 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1872 if (!TX_CMP_VALID(txcmp, raw_cons))
1875 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1876 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1877 cp_cons = RING_CMP(tmp_raw_cons);
1878 rxcmp1 = (struct rx_cmp_ext *)
1879 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1881 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1884 /* force an error to recycle the buffer */
1885 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1886 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1888 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1889 if (likely(rc == -EIO))
1891 else if (rc == -EBUSY) /* partial completion */
1893 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1894 CMPL_BASE_TYPE_HWRM_DONE)) {
1895 bnxt_hwrm_handler(bp, txcmp);
1898 "Invalid completion received on special ring\n");
1900 raw_cons = NEXT_RAW_CMP(raw_cons);
1902 if (rx_pkts == budget)
1906 cpr->cp_raw_cons = raw_cons;
1907 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1908 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1910 if (event & BNXT_AGG_EVENT)
1911 bnxt_db_write(bp, rxr->rx_agg_doorbell,
1912 DB_KEY_RX | rxr->rx_agg_prod);
1914 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
1915 napi_complete_done(napi, rx_pkts);
1916 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
1921 static int bnxt_poll(struct napi_struct *napi, int budget)
1923 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1924 struct bnxt *bp = bnapi->bp;
1925 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1929 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
1931 if (work_done >= budget)
1934 if (!bnxt_has_work(bp, cpr)) {
1935 if (napi_complete_done(napi, work_done))
1936 BNXT_CP_DB_REARM(cpr->cp_doorbell,
1945 static void bnxt_free_tx_skbs(struct bnxt *bp)
1948 struct pci_dev *pdev = bp->pdev;
1953 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
1954 for (i = 0; i < bp->tx_nr_rings; i++) {
1955 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
1958 for (j = 0; j < max_idx;) {
1959 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
1960 struct sk_buff *skb = tx_buf->skb;
1970 if (tx_buf->is_push) {
1976 dma_unmap_single(&pdev->dev,
1977 dma_unmap_addr(tx_buf, mapping),
1981 last = tx_buf->nr_frags;
1983 for (k = 0; k < last; k++, j++) {
1984 int ring_idx = j & bp->tx_ring_mask;
1985 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
1987 tx_buf = &txr->tx_buf_ring[ring_idx];
1990 dma_unmap_addr(tx_buf, mapping),
1991 skb_frag_size(frag), PCI_DMA_TODEVICE);
1995 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
1999 static void bnxt_free_rx_skbs(struct bnxt *bp)
2001 int i, max_idx, max_agg_idx;
2002 struct pci_dev *pdev = bp->pdev;
2007 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2008 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2009 for (i = 0; i < bp->rx_nr_rings; i++) {
2010 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2014 for (j = 0; j < MAX_TPA; j++) {
2015 struct bnxt_tpa_info *tpa_info =
2017 u8 *data = tpa_info->data;
2022 dma_unmap_single_attrs(&pdev->dev,
2024 bp->rx_buf_use_size,
2026 DMA_ATTR_WEAK_ORDERING);
2028 tpa_info->data = NULL;
2034 for (j = 0; j < max_idx; j++) {
2035 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
2036 dma_addr_t mapping = rx_buf->mapping;
2037 void *data = rx_buf->data;
2042 rx_buf->data = NULL;
2044 if (BNXT_RX_PAGE_MODE(bp)) {
2045 mapping -= bp->rx_dma_offset;
2046 dma_unmap_page_attrs(&pdev->dev, mapping,
2047 PAGE_SIZE, bp->rx_dir,
2048 DMA_ATTR_WEAK_ORDERING);
2051 dma_unmap_single_attrs(&pdev->dev, mapping,
2052 bp->rx_buf_use_size,
2054 DMA_ATTR_WEAK_ORDERING);
2059 for (j = 0; j < max_agg_idx; j++) {
2060 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2061 &rxr->rx_agg_ring[j];
2062 struct page *page = rx_agg_buf->page;
2067 dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2070 DMA_ATTR_WEAK_ORDERING);
2072 rx_agg_buf->page = NULL;
2073 __clear_bit(j, rxr->rx_agg_bmap);
2078 __free_page(rxr->rx_page);
2079 rxr->rx_page = NULL;
2084 static void bnxt_free_skbs(struct bnxt *bp)
2086 bnxt_free_tx_skbs(bp);
2087 bnxt_free_rx_skbs(bp);
2090 static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2092 struct pci_dev *pdev = bp->pdev;
2095 for (i = 0; i < ring->nr_pages; i++) {
2096 if (!ring->pg_arr[i])
2099 dma_free_coherent(&pdev->dev, ring->page_size,
2100 ring->pg_arr[i], ring->dma_arr[i]);
2102 ring->pg_arr[i] = NULL;
2105 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2106 ring->pg_tbl, ring->pg_tbl_map);
2107 ring->pg_tbl = NULL;
2109 if (ring->vmem_size && *ring->vmem) {
2115 static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2118 struct pci_dev *pdev = bp->pdev;
2120 if (ring->nr_pages > 1) {
2121 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2129 for (i = 0; i < ring->nr_pages; i++) {
2130 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2134 if (!ring->pg_arr[i])
2137 if (ring->nr_pages > 1)
2138 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2141 if (ring->vmem_size) {
2142 *ring->vmem = vzalloc(ring->vmem_size);
2149 static void bnxt_free_rx_rings(struct bnxt *bp)
2156 for (i = 0; i < bp->rx_nr_rings; i++) {
2157 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2158 struct bnxt_ring_struct *ring;
2161 bpf_prog_put(rxr->xdp_prog);
2166 kfree(rxr->rx_agg_bmap);
2167 rxr->rx_agg_bmap = NULL;
2169 ring = &rxr->rx_ring_struct;
2170 bnxt_free_ring(bp, ring);
2172 ring = &rxr->rx_agg_ring_struct;
2173 bnxt_free_ring(bp, ring);
2177 static int bnxt_alloc_rx_rings(struct bnxt *bp)
2179 int i, rc, agg_rings = 0, tpa_rings = 0;
2184 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2187 if (bp->flags & BNXT_FLAG_TPA)
2190 for (i = 0; i < bp->rx_nr_rings; i++) {
2191 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2192 struct bnxt_ring_struct *ring;
2194 ring = &rxr->rx_ring_struct;
2196 rc = bnxt_alloc_ring(bp, ring);
2203 ring = &rxr->rx_agg_ring_struct;
2204 rc = bnxt_alloc_ring(bp, ring);
2208 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2209 mem_size = rxr->rx_agg_bmap_size / 8;
2210 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2211 if (!rxr->rx_agg_bmap)
2215 rxr->rx_tpa = kcalloc(MAX_TPA,
2216 sizeof(struct bnxt_tpa_info),
2226 static void bnxt_free_tx_rings(struct bnxt *bp)
2229 struct pci_dev *pdev = bp->pdev;
2234 for (i = 0; i < bp->tx_nr_rings; i++) {
2235 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2236 struct bnxt_ring_struct *ring;
2239 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2240 txr->tx_push, txr->tx_push_mapping);
2241 txr->tx_push = NULL;
2244 ring = &txr->tx_ring_struct;
2246 bnxt_free_ring(bp, ring);
2250 static int bnxt_alloc_tx_rings(struct bnxt *bp)
2253 struct pci_dev *pdev = bp->pdev;
2255 bp->tx_push_size = 0;
2256 if (bp->tx_push_thresh) {
2259 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2260 bp->tx_push_thresh);
2262 if (push_size > 256) {
2264 bp->tx_push_thresh = 0;
2267 bp->tx_push_size = push_size;
2270 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
2271 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2272 struct bnxt_ring_struct *ring;
2274 ring = &txr->tx_ring_struct;
2276 rc = bnxt_alloc_ring(bp, ring);
2280 if (bp->tx_push_size) {
2283 /* One pre-allocated DMA buffer to backup
2286 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2288 &txr->tx_push_mapping,
2294 mapping = txr->tx_push_mapping +
2295 sizeof(struct tx_push_bd);
2296 txr->data_mapping = cpu_to_le64(mapping);
2298 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
2300 ring->queue_id = bp->q_info[j].queue_id;
2301 if (i < bp->tx_nr_rings_xdp)
2303 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2309 static void bnxt_free_cp_rings(struct bnxt *bp)
2316 for (i = 0; i < bp->cp_nr_rings; i++) {
2317 struct bnxt_napi *bnapi = bp->bnapi[i];
2318 struct bnxt_cp_ring_info *cpr;
2319 struct bnxt_ring_struct *ring;
2324 cpr = &bnapi->cp_ring;
2325 ring = &cpr->cp_ring_struct;
2327 bnxt_free_ring(bp, ring);
2331 static int bnxt_alloc_cp_rings(struct bnxt *bp)
2335 for (i = 0; i < bp->cp_nr_rings; i++) {
2336 struct bnxt_napi *bnapi = bp->bnapi[i];
2337 struct bnxt_cp_ring_info *cpr;
2338 struct bnxt_ring_struct *ring;
2343 cpr = &bnapi->cp_ring;
2344 ring = &cpr->cp_ring_struct;
2346 rc = bnxt_alloc_ring(bp, ring);
2353 static void bnxt_init_ring_struct(struct bnxt *bp)
2357 for (i = 0; i < bp->cp_nr_rings; i++) {
2358 struct bnxt_napi *bnapi = bp->bnapi[i];
2359 struct bnxt_cp_ring_info *cpr;
2360 struct bnxt_rx_ring_info *rxr;
2361 struct bnxt_tx_ring_info *txr;
2362 struct bnxt_ring_struct *ring;
2367 cpr = &bnapi->cp_ring;
2368 ring = &cpr->cp_ring_struct;
2369 ring->nr_pages = bp->cp_nr_pages;
2370 ring->page_size = HW_CMPD_RING_SIZE;
2371 ring->pg_arr = (void **)cpr->cp_desc_ring;
2372 ring->dma_arr = cpr->cp_desc_mapping;
2373 ring->vmem_size = 0;
2375 rxr = bnapi->rx_ring;
2379 ring = &rxr->rx_ring_struct;
2380 ring->nr_pages = bp->rx_nr_pages;
2381 ring->page_size = HW_RXBD_RING_SIZE;
2382 ring->pg_arr = (void **)rxr->rx_desc_ring;
2383 ring->dma_arr = rxr->rx_desc_mapping;
2384 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2385 ring->vmem = (void **)&rxr->rx_buf_ring;
2387 ring = &rxr->rx_agg_ring_struct;
2388 ring->nr_pages = bp->rx_agg_nr_pages;
2389 ring->page_size = HW_RXBD_RING_SIZE;
2390 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2391 ring->dma_arr = rxr->rx_agg_desc_mapping;
2392 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2393 ring->vmem = (void **)&rxr->rx_agg_ring;
2396 txr = bnapi->tx_ring;
2400 ring = &txr->tx_ring_struct;
2401 ring->nr_pages = bp->tx_nr_pages;
2402 ring->page_size = HW_RXBD_RING_SIZE;
2403 ring->pg_arr = (void **)txr->tx_desc_ring;
2404 ring->dma_arr = txr->tx_desc_mapping;
2405 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2406 ring->vmem = (void **)&txr->tx_buf_ring;
2410 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2414 struct rx_bd **rx_buf_ring;
2416 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2417 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2421 rxbd = rx_buf_ring[i];
2425 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2426 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2427 rxbd->rx_bd_opaque = prod;
2432 static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2434 struct net_device *dev = bp->dev;
2435 struct bnxt_rx_ring_info *rxr;
2436 struct bnxt_ring_struct *ring;
2440 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2441 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2443 if (NET_IP_ALIGN == 2)
2444 type |= RX_BD_FLAGS_SOP;
2446 rxr = &bp->rx_ring[ring_nr];
2447 ring = &rxr->rx_ring_struct;
2448 bnxt_init_rxbd_pages(ring, type);
2450 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2451 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2452 if (IS_ERR(rxr->xdp_prog)) {
2453 int rc = PTR_ERR(rxr->xdp_prog);
2455 rxr->xdp_prog = NULL;
2459 prod = rxr->rx_prod;
2460 for (i = 0; i < bp->rx_ring_size; i++) {
2461 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2462 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2463 ring_nr, i, bp->rx_ring_size);
2466 prod = NEXT_RX(prod);
2468 rxr->rx_prod = prod;
2469 ring->fw_ring_id = INVALID_HW_RING_ID;
2471 ring = &rxr->rx_agg_ring_struct;
2472 ring->fw_ring_id = INVALID_HW_RING_ID;
2474 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2477 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
2478 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2480 bnxt_init_rxbd_pages(ring, type);
2482 prod = rxr->rx_agg_prod;
2483 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2484 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2485 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2486 ring_nr, i, bp->rx_ring_size);
2489 prod = NEXT_RX_AGG(prod);
2491 rxr->rx_agg_prod = prod;
2493 if (bp->flags & BNXT_FLAG_TPA) {
2498 for (i = 0; i < MAX_TPA; i++) {
2499 data = __bnxt_alloc_rx_data(bp, &mapping,
2504 rxr->rx_tpa[i].data = data;
2505 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
2506 rxr->rx_tpa[i].mapping = mapping;
2509 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2517 static void bnxt_init_cp_rings(struct bnxt *bp)
2521 for (i = 0; i < bp->cp_nr_rings; i++) {
2522 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2523 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2525 ring->fw_ring_id = INVALID_HW_RING_ID;
2529 static int bnxt_init_rx_rings(struct bnxt *bp)
2533 if (BNXT_RX_PAGE_MODE(bp)) {
2534 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2535 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
2537 bp->rx_offset = BNXT_RX_OFFSET;
2538 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2541 for (i = 0; i < bp->rx_nr_rings; i++) {
2542 rc = bnxt_init_one_rx_ring(bp, i);
2550 static int bnxt_init_tx_rings(struct bnxt *bp)
2554 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2557 for (i = 0; i < bp->tx_nr_rings; i++) {
2558 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2559 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2561 ring->fw_ring_id = INVALID_HW_RING_ID;
2567 static void bnxt_free_ring_grps(struct bnxt *bp)
2569 kfree(bp->grp_info);
2570 bp->grp_info = NULL;
2573 static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2578 bp->grp_info = kcalloc(bp->cp_nr_rings,
2579 sizeof(struct bnxt_ring_grp_info),
2584 for (i = 0; i < bp->cp_nr_rings; i++) {
2586 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2587 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2588 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2589 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2590 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2595 static void bnxt_free_vnics(struct bnxt *bp)
2597 kfree(bp->vnic_info);
2598 bp->vnic_info = NULL;
2602 static int bnxt_alloc_vnics(struct bnxt *bp)
2606 #ifdef CONFIG_RFS_ACCEL
2607 if (bp->flags & BNXT_FLAG_RFS)
2608 num_vnics += bp->rx_nr_rings;
2611 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2614 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2619 bp->nr_vnics = num_vnics;
2623 static void bnxt_init_vnics(struct bnxt *bp)
2627 for (i = 0; i < bp->nr_vnics; i++) {
2628 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2630 vnic->fw_vnic_id = INVALID_HW_RING_ID;
2631 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2632 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
2633 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2635 if (bp->vnic_info[i].rss_hash_key) {
2637 prandom_bytes(vnic->rss_hash_key,
2640 memcpy(vnic->rss_hash_key,
2641 bp->vnic_info[0].rss_hash_key,
2647 static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2651 pages = ring_size / desc_per_pg;
2658 while (pages & (pages - 1))
2664 void bnxt_set_tpa_flags(struct bnxt *bp)
2666 bp->flags &= ~BNXT_FLAG_TPA;
2667 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2669 if (bp->dev->features & NETIF_F_LRO)
2670 bp->flags |= BNXT_FLAG_LRO;
2671 if (bp->dev->features & NETIF_F_GRO)
2672 bp->flags |= BNXT_FLAG_GRO;
2675 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2678 void bnxt_set_ring_params(struct bnxt *bp)
2680 u32 ring_size, rx_size, rx_space;
2681 u32 agg_factor = 0, agg_ring_size = 0;
2683 /* 8 for CRC and VLAN */
2684 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2686 rx_space = rx_size + NET_SKB_PAD +
2687 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2689 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2690 ring_size = bp->rx_ring_size;
2691 bp->rx_agg_ring_size = 0;
2692 bp->rx_agg_nr_pages = 0;
2694 if (bp->flags & BNXT_FLAG_TPA)
2695 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
2697 bp->flags &= ~BNXT_FLAG_JUMBO;
2698 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
2701 bp->flags |= BNXT_FLAG_JUMBO;
2702 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2703 if (jumbo_factor > agg_factor)
2704 agg_factor = jumbo_factor;
2706 agg_ring_size = ring_size * agg_factor;
2708 if (agg_ring_size) {
2709 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2711 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2712 u32 tmp = agg_ring_size;
2714 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2715 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2716 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2717 tmp, agg_ring_size);
2719 bp->rx_agg_ring_size = agg_ring_size;
2720 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2721 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2722 rx_space = rx_size + NET_SKB_PAD +
2723 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2726 bp->rx_buf_use_size = rx_size;
2727 bp->rx_buf_size = rx_space;
2729 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2730 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2732 ring_size = bp->tx_ring_size;
2733 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2734 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2736 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2737 bp->cp_ring_size = ring_size;
2739 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2740 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2741 bp->cp_nr_pages = MAX_CP_PAGES;
2742 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2743 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2744 ring_size, bp->cp_ring_size);
2746 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2747 bp->cp_ring_mask = bp->cp_bit - 1;
2750 int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
2753 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2755 bp->dev->max_mtu = BNXT_MAX_PAGE_MODE_MTU;
2756 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2757 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
2758 bp->dev->hw_features &= ~NETIF_F_LRO;
2759 bp->dev->features &= ~NETIF_F_LRO;
2760 bp->rx_dir = DMA_BIDIRECTIONAL;
2761 bp->rx_skb_func = bnxt_rx_page_skb;
2763 bp->dev->max_mtu = BNXT_MAX_MTU;
2764 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2765 bp->rx_dir = DMA_FROM_DEVICE;
2766 bp->rx_skb_func = bnxt_rx_skb;
2771 static void bnxt_free_vnic_attributes(struct bnxt *bp)
2774 struct bnxt_vnic_info *vnic;
2775 struct pci_dev *pdev = bp->pdev;
2780 for (i = 0; i < bp->nr_vnics; i++) {
2781 vnic = &bp->vnic_info[i];
2783 kfree(vnic->fw_grp_ids);
2784 vnic->fw_grp_ids = NULL;
2786 kfree(vnic->uc_list);
2787 vnic->uc_list = NULL;
2789 if (vnic->mc_list) {
2790 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2791 vnic->mc_list, vnic->mc_list_mapping);
2792 vnic->mc_list = NULL;
2795 if (vnic->rss_table) {
2796 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2798 vnic->rss_table_dma_addr);
2799 vnic->rss_table = NULL;
2802 vnic->rss_hash_key = NULL;
2807 static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2809 int i, rc = 0, size;
2810 struct bnxt_vnic_info *vnic;
2811 struct pci_dev *pdev = bp->pdev;
2814 for (i = 0; i < bp->nr_vnics; i++) {
2815 vnic = &bp->vnic_info[i];
2817 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2818 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2821 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2822 if (!vnic->uc_list) {
2829 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2830 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2832 dma_alloc_coherent(&pdev->dev,
2834 &vnic->mc_list_mapping,
2836 if (!vnic->mc_list) {
2842 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2843 max_rings = bp->rx_nr_rings;
2847 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2848 if (!vnic->fw_grp_ids) {
2853 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2854 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2857 /* Allocate rss table and hash key */
2858 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2859 &vnic->rss_table_dma_addr,
2861 if (!vnic->rss_table) {
2866 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2868 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2869 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2877 static void bnxt_free_hwrm_resources(struct bnxt *bp)
2879 struct pci_dev *pdev = bp->pdev;
2881 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
2882 bp->hwrm_cmd_resp_dma_addr);
2884 bp->hwrm_cmd_resp_addr = NULL;
2885 if (bp->hwrm_dbg_resp_addr) {
2886 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
2887 bp->hwrm_dbg_resp_addr,
2888 bp->hwrm_dbg_resp_dma_addr);
2890 bp->hwrm_dbg_resp_addr = NULL;
2894 static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2896 struct pci_dev *pdev = bp->pdev;
2898 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2899 &bp->hwrm_cmd_resp_dma_addr,
2901 if (!bp->hwrm_cmd_resp_addr)
2903 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
2904 HWRM_DBG_REG_BUF_SIZE,
2905 &bp->hwrm_dbg_resp_dma_addr,
2907 if (!bp->hwrm_dbg_resp_addr)
2908 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
2913 static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
2915 if (bp->hwrm_short_cmd_req_addr) {
2916 struct pci_dev *pdev = bp->pdev;
2918 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
2919 bp->hwrm_short_cmd_req_addr,
2920 bp->hwrm_short_cmd_req_dma_addr);
2921 bp->hwrm_short_cmd_req_addr = NULL;
2925 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
2927 struct pci_dev *pdev = bp->pdev;
2929 bp->hwrm_short_cmd_req_addr =
2930 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
2931 &bp->hwrm_short_cmd_req_dma_addr,
2933 if (!bp->hwrm_short_cmd_req_addr)
2939 static void bnxt_free_stats(struct bnxt *bp)
2942 struct pci_dev *pdev = bp->pdev;
2944 if (bp->hw_rx_port_stats) {
2945 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
2946 bp->hw_rx_port_stats,
2947 bp->hw_rx_port_stats_map);
2948 bp->hw_rx_port_stats = NULL;
2949 bp->flags &= ~BNXT_FLAG_PORT_STATS;
2955 size = sizeof(struct ctx_hw_stats);
2957 for (i = 0; i < bp->cp_nr_rings; i++) {
2958 struct bnxt_napi *bnapi = bp->bnapi[i];
2959 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2961 if (cpr->hw_stats) {
2962 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
2964 cpr->hw_stats = NULL;
2969 static int bnxt_alloc_stats(struct bnxt *bp)
2972 struct pci_dev *pdev = bp->pdev;
2974 size = sizeof(struct ctx_hw_stats);
2976 for (i = 0; i < bp->cp_nr_rings; i++) {
2977 struct bnxt_napi *bnapi = bp->bnapi[i];
2978 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2980 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
2986 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
2989 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
2990 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
2991 sizeof(struct tx_port_stats) + 1024;
2993 bp->hw_rx_port_stats =
2994 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
2995 &bp->hw_rx_port_stats_map,
2997 if (!bp->hw_rx_port_stats)
3000 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3002 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3003 sizeof(struct rx_port_stats) + 512;
3004 bp->flags |= BNXT_FLAG_PORT_STATS;
3009 static void bnxt_clear_ring_indices(struct bnxt *bp)
3016 for (i = 0; i < bp->cp_nr_rings; i++) {
3017 struct bnxt_napi *bnapi = bp->bnapi[i];
3018 struct bnxt_cp_ring_info *cpr;
3019 struct bnxt_rx_ring_info *rxr;
3020 struct bnxt_tx_ring_info *txr;
3025 cpr = &bnapi->cp_ring;
3026 cpr->cp_raw_cons = 0;
3028 txr = bnapi->tx_ring;
3034 rxr = bnapi->rx_ring;
3037 rxr->rx_agg_prod = 0;
3038 rxr->rx_sw_agg_prod = 0;
3039 rxr->rx_next_cons = 0;
3044 static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3046 #ifdef CONFIG_RFS_ACCEL
3049 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3050 * safe to delete the hash table.
3052 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3053 struct hlist_head *head;
3054 struct hlist_node *tmp;
3055 struct bnxt_ntuple_filter *fltr;
3057 head = &bp->ntp_fltr_hash_tbl[i];
3058 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3059 hlist_del(&fltr->hash);
3064 kfree(bp->ntp_fltr_bmap);
3065 bp->ntp_fltr_bmap = NULL;
3067 bp->ntp_fltr_count = 0;
3071 static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3073 #ifdef CONFIG_RFS_ACCEL
3076 if (!(bp->flags & BNXT_FLAG_RFS))
3079 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3080 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3082 bp->ntp_fltr_count = 0;
3083 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3087 if (!bp->ntp_fltr_bmap)
3096 static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3098 bnxt_free_vnic_attributes(bp);
3099 bnxt_free_tx_rings(bp);
3100 bnxt_free_rx_rings(bp);
3101 bnxt_free_cp_rings(bp);
3102 bnxt_free_ntp_fltrs(bp, irq_re_init);
3104 bnxt_free_stats(bp);
3105 bnxt_free_ring_grps(bp);
3106 bnxt_free_vnics(bp);
3107 kfree(bp->tx_ring_map);
3108 bp->tx_ring_map = NULL;
3116 bnxt_clear_ring_indices(bp);
3120 static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3122 int i, j, rc, size, arr_size;
3126 /* Allocate bnapi mem pointer array and mem block for
3129 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3131 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3132 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3138 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3139 bp->bnapi[i] = bnapi;
3140 bp->bnapi[i]->index = i;
3141 bp->bnapi[i]->bp = bp;
3144 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3145 sizeof(struct bnxt_rx_ring_info),
3150 for (i = 0; i < bp->rx_nr_rings; i++) {
3151 bp->rx_ring[i].bnapi = bp->bnapi[i];
3152 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3155 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3156 sizeof(struct bnxt_tx_ring_info),
3161 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3164 if (!bp->tx_ring_map)
3167 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3170 j = bp->rx_nr_rings;
3172 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3173 bp->tx_ring[i].bnapi = bp->bnapi[j];
3174 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
3175 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
3176 if (i >= bp->tx_nr_rings_xdp) {
3177 bp->tx_ring[i].txq_index = i -
3178 bp->tx_nr_rings_xdp;
3179 bp->bnapi[j]->tx_int = bnxt_tx_int;
3181 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
3182 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3186 rc = bnxt_alloc_stats(bp);
3190 rc = bnxt_alloc_ntp_fltrs(bp);
3194 rc = bnxt_alloc_vnics(bp);
3199 bnxt_init_ring_struct(bp);
3201 rc = bnxt_alloc_rx_rings(bp);
3205 rc = bnxt_alloc_tx_rings(bp);
3209 rc = bnxt_alloc_cp_rings(bp);
3213 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3214 BNXT_VNIC_UCAST_FLAG;
3215 rc = bnxt_alloc_vnic_attributes(bp);
3221 bnxt_free_mem(bp, true);
3225 static void bnxt_disable_int(struct bnxt *bp)
3232 for (i = 0; i < bp->cp_nr_rings; i++) {
3233 struct bnxt_napi *bnapi = bp->bnapi[i];
3234 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3235 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
3237 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3238 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
3242 static void bnxt_disable_int_sync(struct bnxt *bp)
3246 atomic_inc(&bp->intr_sem);
3248 bnxt_disable_int(bp);
3249 for (i = 0; i < bp->cp_nr_rings; i++)
3250 synchronize_irq(bp->irq_tbl[i].vector);
3253 static void bnxt_enable_int(struct bnxt *bp)
3257 atomic_set(&bp->intr_sem, 0);
3258 for (i = 0; i < bp->cp_nr_rings; i++) {
3259 struct bnxt_napi *bnapi = bp->bnapi[i];
3260 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3262 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3266 void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3267 u16 cmpl_ring, u16 target_id)
3269 struct input *req = request;
3271 req->req_type = cpu_to_le16(req_type);
3272 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3273 req->target_id = cpu_to_le16(target_id);
3274 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3277 static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3278 int timeout, bool silent)
3280 int i, intr_process, rc, tmo_count;
3281 struct input *req = msg;
3283 __le32 *resp_len, *valid;
3284 u16 cp_ring_id, len = 0;
3285 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
3286 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
3288 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
3289 memset(resp, 0, PAGE_SIZE);
3290 cp_ring_id = le16_to_cpu(req->cmpl_ring);
3291 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3293 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3294 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
3295 struct hwrm_short_input short_input = {0};
3297 memcpy(short_cmd_req, req, msg_len);
3298 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3301 short_input.req_type = req->req_type;
3302 short_input.signature =
3303 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3304 short_input.size = cpu_to_le16(msg_len);
3305 short_input.req_addr =
3306 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3308 data = (u32 *)&short_input;
3309 msg_len = sizeof(short_input);
3311 /* Sync memory write before updating doorbell */
3314 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3317 /* Write request msg to hwrm channel */
3318 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3320 for (i = msg_len; i < max_req_len; i += 4)
3321 writel(0, bp->bar0 + i);
3323 /* currently supports only one outstanding message */
3325 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
3327 /* Ring channel doorbell */
3328 writel(1, bp->bar0 + 0x100);
3331 timeout = DFLT_HWRM_CMD_TIMEOUT;
3334 tmo_count = timeout * 40;
3336 /* Wait until hwrm response cmpl interrupt is processed */
3337 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
3339 usleep_range(25, 40);
3342 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3343 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
3344 le16_to_cpu(req->req_type));
3348 /* Check if response len is updated */
3349 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
3350 for (i = 0; i < tmo_count; i++) {
3351 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3355 usleep_range(25, 40);
3358 if (i >= tmo_count) {
3359 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
3360 timeout, le16_to_cpu(req->req_type),
3361 le16_to_cpu(req->seq_id), len);
3365 /* Last word of resp contains valid bit */
3366 valid = bp->hwrm_cmd_resp_addr + len - 4;
3367 for (i = 0; i < 5; i++) {
3368 if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK)
3374 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
3375 timeout, le16_to_cpu(req->req_type),
3376 le16_to_cpu(req->seq_id), len, *valid);
3381 rc = le16_to_cpu(resp->error_code);
3383 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3384 le16_to_cpu(resp->req_type),
3385 le16_to_cpu(resp->seq_id), rc);
3389 int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3391 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
3394 int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3398 mutex_lock(&bp->hwrm_cmd_lock);
3399 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3400 mutex_unlock(&bp->hwrm_cmd_lock);
3404 int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3409 mutex_lock(&bp->hwrm_cmd_lock);
3410 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3411 mutex_unlock(&bp->hwrm_cmd_lock);
3415 int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3418 struct hwrm_func_drv_rgtr_input req = {0};
3419 DECLARE_BITMAP(async_events_bmap, 256);
3420 u32 *events = (u32 *)async_events_bmap;
3423 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3426 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
3428 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3429 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3430 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3432 if (bmap && bmap_size) {
3433 for (i = 0; i < bmap_size; i++) {
3434 if (test_bit(i, bmap))
3435 __set_bit(i, async_events_bmap);
3439 for (i = 0; i < 8; i++)
3440 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3442 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3445 static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3447 struct hwrm_func_drv_rgtr_input req = {0};
3449 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3452 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3453 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3455 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
3456 req.ver_maj = DRV_VER_MAJ;
3457 req.ver_min = DRV_VER_MIN;
3458 req.ver_upd = DRV_VER_UPD;
3464 memset(data, 0, sizeof(data));
3465 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
3466 u16 cmd = bnxt_vf_req_snif[i];
3467 unsigned int bit, idx;
3471 data[idx] |= 1 << bit;
3474 for (i = 0; i < 8; i++)
3475 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3478 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3481 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3484 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3486 struct hwrm_func_drv_unrgtr_input req = {0};
3488 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3489 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3492 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3495 struct hwrm_tunnel_dst_port_free_input req = {0};
3497 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3498 req.tunnel_type = tunnel_type;
3500 switch (tunnel_type) {
3501 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3502 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3504 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3505 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3511 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3513 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3518 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3522 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3523 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3525 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3527 req.tunnel_type = tunnel_type;
3528 req.tunnel_dst_port_val = port;
3530 mutex_lock(&bp->hwrm_cmd_lock);
3531 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3533 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3538 switch (tunnel_type) {
3539 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
3540 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3542 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
3543 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
3550 mutex_unlock(&bp->hwrm_cmd_lock);
3554 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3556 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3557 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3559 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
3560 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
3562 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3563 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3564 req.mask = cpu_to_le32(vnic->rx_mask);
3565 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3568 #ifdef CONFIG_RFS_ACCEL
3569 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3570 struct bnxt_ntuple_filter *fltr)
3572 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3574 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3575 req.ntuple_filter_id = fltr->filter_id;
3576 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3579 #define BNXT_NTP_FLTR_FLAGS \
3580 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3581 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3582 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3583 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3584 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3585 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3586 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3587 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3588 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3589 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3590 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3591 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3592 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
3593 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
3595 #define BNXT_NTP_TUNNEL_FLTR_FLAG \
3596 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3598 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3599 struct bnxt_ntuple_filter *fltr)
3602 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3603 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3604 bp->hwrm_cmd_resp_addr;
3605 struct flow_keys *keys = &fltr->fkeys;
3606 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3608 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
3609 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
3611 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3613 req.ethertype = htons(ETH_P_IP);
3614 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
3615 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
3616 req.ip_protocol = keys->basic.ip_proto;
3618 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3621 req.ethertype = htons(ETH_P_IPV6);
3623 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3624 *(struct in6_addr *)&req.src_ipaddr[0] =
3625 keys->addrs.v6addrs.src;
3626 *(struct in6_addr *)&req.dst_ipaddr[0] =
3627 keys->addrs.v6addrs.dst;
3628 for (i = 0; i < 4; i++) {
3629 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3630 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3633 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3634 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3635 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3636 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3638 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3639 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3641 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3644 req.src_port = keys->ports.src;
3645 req.src_port_mask = cpu_to_be16(0xffff);
3646 req.dst_port = keys->ports.dst;
3647 req.dst_port_mask = cpu_to_be16(0xffff);
3649 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
3650 mutex_lock(&bp->hwrm_cmd_lock);
3651 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3653 fltr->filter_id = resp->ntuple_filter_id;
3654 mutex_unlock(&bp->hwrm_cmd_lock);
3659 static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3663 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3664 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3666 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
3667 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3668 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3670 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
3671 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
3673 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
3674 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
3675 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3676 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3677 req.l2_addr_mask[0] = 0xff;
3678 req.l2_addr_mask[1] = 0xff;
3679 req.l2_addr_mask[2] = 0xff;
3680 req.l2_addr_mask[3] = 0xff;
3681 req.l2_addr_mask[4] = 0xff;
3682 req.l2_addr_mask[5] = 0xff;
3684 mutex_lock(&bp->hwrm_cmd_lock);
3685 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3687 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3689 mutex_unlock(&bp->hwrm_cmd_lock);
3693 static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3695 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3698 /* Any associated ntuple filters will also be cleared by firmware. */
3699 mutex_lock(&bp->hwrm_cmd_lock);
3700 for (i = 0; i < num_of_vnics; i++) {
3701 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3703 for (j = 0; j < vnic->uc_filter_count; j++) {
3704 struct hwrm_cfa_l2_filter_free_input req = {0};
3706 bnxt_hwrm_cmd_hdr_init(bp, &req,
3707 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3709 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3711 rc = _hwrm_send_message(bp, &req, sizeof(req),
3714 vnic->uc_filter_count = 0;
3716 mutex_unlock(&bp->hwrm_cmd_lock);
3721 static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3723 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3724 struct hwrm_vnic_tpa_cfg_input req = {0};
3726 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3729 u16 mss = bp->dev->mtu - 40;
3730 u32 nsegs, n, segs = 0, flags;
3732 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3733 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3734 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3735 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3736 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3737 if (tpa_flags & BNXT_FLAG_GRO)
3738 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3740 req.flags = cpu_to_le32(flags);
3743 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
3744 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3745 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
3747 /* Number of segs are log2 units, and first packet is not
3748 * included as part of this units.
3750 if (mss <= BNXT_RX_PAGE_SIZE) {
3751 n = BNXT_RX_PAGE_SIZE / mss;
3752 nsegs = (MAX_SKB_FRAGS - 1) * n;
3754 n = mss / BNXT_RX_PAGE_SIZE;
3755 if (mss & (BNXT_RX_PAGE_SIZE - 1))
3757 nsegs = (MAX_SKB_FRAGS - n) / n;
3760 segs = ilog2(nsegs);
3761 req.max_agg_segs = cpu_to_le16(segs);
3762 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
3764 req.min_agg_len = cpu_to_le32(512);
3766 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3768 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3771 static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3773 u32 i, j, max_rings;
3774 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3775 struct hwrm_vnic_rss_cfg_input req = {0};
3777 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
3780 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3782 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
3783 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3784 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3785 max_rings = bp->rx_nr_rings - 1;
3787 max_rings = bp->rx_nr_rings;
3792 /* Fill the RSS indirection table with ring group ids */
3793 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3796 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3799 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3800 req.hash_key_tbl_addr =
3801 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3803 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
3804 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3807 static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3809 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3810 struct hwrm_vnic_plcmodes_cfg_input req = {0};
3812 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
3813 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
3814 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
3815 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
3817 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
3818 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
3819 /* thresholds not implemented in firmware yet */
3820 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
3821 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
3822 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
3823 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3826 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
3829 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
3831 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
3832 req.rss_cos_lb_ctx_id =
3833 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
3835 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3836 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
3839 static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
3843 for (i = 0; i < bp->nr_vnics; i++) {
3844 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3846 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
3847 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
3848 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
3851 bp->rsscos_nr_ctxs = 0;
3854 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
3857 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
3858 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
3859 bp->hwrm_cmd_resp_addr;
3861 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
3864 mutex_lock(&bp->hwrm_cmd_lock);
3865 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3867 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
3868 le16_to_cpu(resp->rss_cos_lb_ctx_id);
3869 mutex_unlock(&bp->hwrm_cmd_lock);
3874 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
3876 unsigned int ring = 0, grp_idx;
3877 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3878 struct hwrm_vnic_cfg_input req = {0};
3881 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
3883 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
3884 /* Only RSS support for now TBD: COS & LB */
3885 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
3886 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
3887 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3888 VNIC_CFG_REQ_ENABLES_MRU);
3889 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
3891 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
3892 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3893 VNIC_CFG_REQ_ENABLES_MRU);
3894 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
3896 req.rss_rule = cpu_to_le16(0xffff);
3899 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
3900 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
3901 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
3902 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
3904 req.cos_rule = cpu_to_le16(0xffff);
3907 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
3909 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
3911 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
3912 ring = bp->rx_nr_rings - 1;
3914 grp_idx = bp->rx_ring[ring].bnapi->index;
3915 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3916 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
3918 req.lb_rule = cpu_to_le16(0xffff);
3919 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
3922 #ifdef CONFIG_BNXT_SRIOV
3924 def_vlan = bp->vf.vlan;
3926 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
3927 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
3928 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
3930 cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE);
3932 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3935 static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
3939 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
3940 struct hwrm_vnic_free_input req = {0};
3942 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
3944 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
3946 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3949 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
3954 static void bnxt_hwrm_vnic_free(struct bnxt *bp)
3958 for (i = 0; i < bp->nr_vnics; i++)
3959 bnxt_hwrm_vnic_free_one(bp, i);
3962 static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
3963 unsigned int start_rx_ring_idx,
3964 unsigned int nr_rings)
3967 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
3968 struct hwrm_vnic_alloc_input req = {0};
3969 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3971 /* map ring groups to this vnic */
3972 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
3973 grp_idx = bp->rx_ring[i].bnapi->index;
3974 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
3975 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
3979 bp->vnic_info[vnic_id].fw_grp_ids[j] =
3980 bp->grp_info[grp_idx].fw_grp_id;
3983 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
3984 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
3986 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
3988 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
3990 mutex_lock(&bp->hwrm_cmd_lock);
3991 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3993 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
3994 mutex_unlock(&bp->hwrm_cmd_lock);
3998 static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
4000 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4001 struct hwrm_vnic_qcaps_input req = {0};
4004 if (bp->hwrm_spec_code < 0x10600)
4007 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
4008 mutex_lock(&bp->hwrm_cmd_lock);
4009 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4012 cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
4013 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
4015 mutex_unlock(&bp->hwrm_cmd_lock);
4019 static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
4024 mutex_lock(&bp->hwrm_cmd_lock);
4025 for (i = 0; i < bp->rx_nr_rings; i++) {
4026 struct hwrm_ring_grp_alloc_input req = {0};
4027 struct hwrm_ring_grp_alloc_output *resp =
4028 bp->hwrm_cmd_resp_addr;
4029 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
4031 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
4033 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4034 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
4035 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
4036 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
4038 rc = _hwrm_send_message(bp, &req, sizeof(req),
4043 bp->grp_info[grp_idx].fw_grp_id =
4044 le32_to_cpu(resp->ring_group_id);
4046 mutex_unlock(&bp->hwrm_cmd_lock);
4050 static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4054 struct hwrm_ring_grp_free_input req = {0};
4059 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4061 mutex_lock(&bp->hwrm_cmd_lock);
4062 for (i = 0; i < bp->cp_nr_rings; i++) {
4063 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4066 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4068 rc = _hwrm_send_message(bp, &req, sizeof(req),
4072 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4074 mutex_unlock(&bp->hwrm_cmd_lock);
4078 static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4079 struct bnxt_ring_struct *ring,
4080 u32 ring_type, u32 map_index,
4083 int rc = 0, err = 0;
4084 struct hwrm_ring_alloc_input req = {0};
4085 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4088 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4091 if (ring->nr_pages > 1) {
4092 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4093 /* Page size is in log2 units */
4094 req.page_size = BNXT_PAGE_SHIFT;
4095 req.page_tbl_depth = 1;
4097 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4100 /* Association of ring index with doorbell index and MSIX number */
4101 req.logical_id = cpu_to_le16(map_index);
4103 switch (ring_type) {
4104 case HWRM_RING_ALLOC_TX:
4105 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4106 /* Association of transmit ring with completion ring */
4108 cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id);
4109 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
4110 req.stat_ctx_id = cpu_to_le32(stats_ctx_id);
4111 req.queue_id = cpu_to_le16(ring->queue_id);
4113 case HWRM_RING_ALLOC_RX:
4114 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4115 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4117 case HWRM_RING_ALLOC_AGG:
4118 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4119 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4121 case HWRM_RING_ALLOC_CMPL:
4122 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
4123 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4124 if (bp->flags & BNXT_FLAG_USING_MSIX)
4125 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4128 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4133 mutex_lock(&bp->hwrm_cmd_lock);
4134 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4135 err = le16_to_cpu(resp->error_code);
4136 ring_id = le16_to_cpu(resp->ring_id);
4137 mutex_unlock(&bp->hwrm_cmd_lock);
4140 switch (ring_type) {
4141 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
4142 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
4146 case RING_FREE_REQ_RING_TYPE_RX:
4147 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
4151 case RING_FREE_REQ_RING_TYPE_TX:
4152 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
4157 netdev_err(bp->dev, "Invalid ring\n");
4161 ring->fw_ring_id = ring_id;
4165 static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4170 struct hwrm_func_cfg_input req = {0};
4172 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4173 req.fid = cpu_to_le16(0xffff);
4174 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4175 req.async_event_cr = cpu_to_le16(idx);
4176 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4178 struct hwrm_func_vf_cfg_input req = {0};
4180 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4182 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4183 req.async_event_cr = cpu_to_le16(idx);
4184 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4189 static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4193 for (i = 0; i < bp->cp_nr_rings; i++) {
4194 struct bnxt_napi *bnapi = bp->bnapi[i];
4195 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4196 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4198 cpr->cp_doorbell = bp->bar1 + i * 0x80;
4199 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
4200 INVALID_STATS_CTX_ID);
4203 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4204 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
4207 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4209 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4213 for (i = 0; i < bp->tx_nr_rings; i++) {
4214 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4215 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4216 u32 map_idx = txr->bnapi->index;
4217 u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
4219 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4220 map_idx, fw_stats_ctx);
4223 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
4226 for (i = 0; i < bp->rx_nr_rings; i++) {
4227 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4228 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
4229 u32 map_idx = rxr->bnapi->index;
4231 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4232 map_idx, INVALID_STATS_CTX_ID);
4235 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
4236 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
4237 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
4240 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4241 for (i = 0; i < bp->rx_nr_rings; i++) {
4242 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4243 struct bnxt_ring_struct *ring =
4244 &rxr->rx_agg_ring_struct;
4245 u32 grp_idx = rxr->bnapi->index;
4246 u32 map_idx = grp_idx + bp->rx_nr_rings;
4248 rc = hwrm_ring_alloc_send_msg(bp, ring,
4249 HWRM_RING_ALLOC_AGG,
4251 INVALID_STATS_CTX_ID);
4255 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
4256 writel(DB_KEY_RX | rxr->rx_agg_prod,
4257 rxr->rx_agg_doorbell);
4258 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
4265 static int hwrm_ring_free_send_msg(struct bnxt *bp,
4266 struct bnxt_ring_struct *ring,
4267 u32 ring_type, int cmpl_ring_id)
4270 struct hwrm_ring_free_input req = {0};
4271 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4274 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
4275 req.ring_type = ring_type;
4276 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4278 mutex_lock(&bp->hwrm_cmd_lock);
4279 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4280 error_code = le16_to_cpu(resp->error_code);
4281 mutex_unlock(&bp->hwrm_cmd_lock);
4283 if (rc || error_code) {
4284 switch (ring_type) {
4285 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
4286 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4289 case RING_FREE_REQ_RING_TYPE_RX:
4290 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4293 case RING_FREE_REQ_RING_TYPE_TX:
4294 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4298 netdev_err(bp->dev, "Invalid ring\n");
4305 static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
4312 for (i = 0; i < bp->tx_nr_rings; i++) {
4313 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4314 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4315 u32 grp_idx = txr->bnapi->index;
4316 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4318 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4319 hwrm_ring_free_send_msg(bp, ring,
4320 RING_FREE_REQ_RING_TYPE_TX,
4321 close_path ? cmpl_ring_id :
4322 INVALID_HW_RING_ID);
4323 ring->fw_ring_id = INVALID_HW_RING_ID;
4327 for (i = 0; i < bp->rx_nr_rings; i++) {
4328 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4329 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
4330 u32 grp_idx = rxr->bnapi->index;
4331 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4333 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4334 hwrm_ring_free_send_msg(bp, ring,
4335 RING_FREE_REQ_RING_TYPE_RX,
4336 close_path ? cmpl_ring_id :
4337 INVALID_HW_RING_ID);
4338 ring->fw_ring_id = INVALID_HW_RING_ID;
4339 bp->grp_info[grp_idx].rx_fw_ring_id =
4344 for (i = 0; i < bp->rx_nr_rings; i++) {
4345 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4346 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
4347 u32 grp_idx = rxr->bnapi->index;
4348 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4350 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4351 hwrm_ring_free_send_msg(bp, ring,
4352 RING_FREE_REQ_RING_TYPE_RX,
4353 close_path ? cmpl_ring_id :
4354 INVALID_HW_RING_ID);
4355 ring->fw_ring_id = INVALID_HW_RING_ID;
4356 bp->grp_info[grp_idx].agg_fw_ring_id =
4361 /* The completion rings are about to be freed. After that the
4362 * IRQ doorbell will not work anymore. So we need to disable
4365 bnxt_disable_int_sync(bp);
4367 for (i = 0; i < bp->cp_nr_rings; i++) {
4368 struct bnxt_napi *bnapi = bp->bnapi[i];
4369 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4370 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4372 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4373 hwrm_ring_free_send_msg(bp, ring,
4374 RING_FREE_REQ_RING_TYPE_L2_CMPL,
4375 INVALID_HW_RING_ID);
4376 ring->fw_ring_id = INVALID_HW_RING_ID;
4377 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
4382 /* Caller must hold bp->hwrm_cmd_lock */
4383 int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4385 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4386 struct hwrm_func_qcfg_input req = {0};
4389 if (bp->hwrm_spec_code < 0x10601)
4392 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4393 req.fid = cpu_to_le16(fid);
4394 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4396 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4401 static int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings)
4403 struct hwrm_func_cfg_input req = {0};
4406 if (bp->hwrm_spec_code < 0x10601)
4412 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4413 req.fid = cpu_to_le16(0xffff);
4414 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS);
4415 req.num_tx_rings = cpu_to_le16(*tx_rings);
4416 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4420 mutex_lock(&bp->hwrm_cmd_lock);
4421 rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings);
4422 mutex_unlock(&bp->hwrm_cmd_lock);
4426 static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs,
4427 u32 buf_tmrs, u16 flags,
4428 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4430 req->flags = cpu_to_le16(flags);
4431 req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs);
4432 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16);
4433 req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs);
4434 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16);
4435 /* Minimum time between 2 interrupts set to buf_tmr x 2 */
4436 req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2);
4437 req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4);
4438 req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4);
4441 int bnxt_hwrm_set_coal(struct bnxt *bp)
4444 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4446 u16 max_buf, max_buf_irq;
4447 u16 buf_tmr, buf_tmr_irq;
4450 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4451 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4452 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4453 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4455 /* Each rx completion (2 records) should be DMAed immediately.
4456 * DMA 1/4 of the completion buffers at a time.
4458 max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2);
4459 /* max_buf must not be zero */
4460 max_buf = clamp_t(u16, max_buf, 1, 63);
4461 max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63);
4462 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks);
4463 /* buf timer set to 1/4 of interrupt timer */
4464 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4465 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq);
4466 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4468 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4470 /* RING_IDLE generates more IRQs for lower latency. Enable it only
4471 * if coal_ticks is less than 25 us.
4473 if (bp->rx_coal_ticks < 25)
4474 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
4476 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4477 buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
4479 /* max_buf must not be zero */
4480 max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63);
4481 max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63);
4482 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks);
4483 /* buf timer set to 1/4 of interrupt timer */
4484 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4485 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq);
4486 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4488 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4489 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4490 buf_tmr_irq << 16 | buf_tmr, flags, &req_tx);
4492 mutex_lock(&bp->hwrm_cmd_lock);
4493 for (i = 0; i < bp->cp_nr_rings; i++) {
4494 struct bnxt_napi *bnapi = bp->bnapi[i];
4497 if (!bnapi->rx_ring)
4499 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
4501 rc = _hwrm_send_message(bp, req, sizeof(*req),
4506 mutex_unlock(&bp->hwrm_cmd_lock);
4510 static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
4513 struct hwrm_stat_ctx_free_input req = {0};
4518 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4521 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
4523 mutex_lock(&bp->hwrm_cmd_lock);
4524 for (i = 0; i < bp->cp_nr_rings; i++) {
4525 struct bnxt_napi *bnapi = bp->bnapi[i];
4526 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4528 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
4529 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
4531 rc = _hwrm_send_message(bp, &req, sizeof(req),
4536 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
4539 mutex_unlock(&bp->hwrm_cmd_lock);
4543 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
4546 struct hwrm_stat_ctx_alloc_input req = {0};
4547 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4549 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4552 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
4554 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
4556 mutex_lock(&bp->hwrm_cmd_lock);
4557 for (i = 0; i < bp->cp_nr_rings; i++) {
4558 struct bnxt_napi *bnapi = bp->bnapi[i];
4559 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4561 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
4563 rc = _hwrm_send_message(bp, &req, sizeof(req),
4568 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
4570 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
4572 mutex_unlock(&bp->hwrm_cmd_lock);
4576 static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
4578 struct hwrm_func_qcfg_input req = {0};
4579 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4582 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4583 req.fid = cpu_to_le16(0xffff);
4584 mutex_lock(&bp->hwrm_cmd_lock);
4585 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4587 goto func_qcfg_exit;
4589 #ifdef CONFIG_BNXT_SRIOV
4591 struct bnxt_vf_info *vf = &bp->vf;
4593 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
4597 u16 flags = le16_to_cpu(resp->flags);
4599 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
4600 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED))
4601 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
4602 if (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)
4603 bp->flags |= BNXT_FLAG_MULTI_HOST;
4606 switch (resp->port_partition_type) {
4607 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
4608 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
4609 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
4610 bp->port_partition_type = resp->port_partition_type;
4615 mutex_unlock(&bp->hwrm_cmd_lock);
4619 static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
4622 struct hwrm_func_qcaps_input req = {0};
4623 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4625 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
4626 req.fid = cpu_to_le16(0xffff);
4628 mutex_lock(&bp->hwrm_cmd_lock);
4629 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4631 goto hwrm_func_qcaps_exit;
4633 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED))
4634 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
4635 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED))
4636 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
4638 bp->tx_push_thresh = 0;
4640 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED))
4641 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
4644 struct bnxt_pf_info *pf = &bp->pf;
4646 pf->fw_fid = le16_to_cpu(resp->fid);
4647 pf->port_id = le16_to_cpu(resp->port_id);
4648 bp->dev->dev_port = pf->port_id;
4649 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
4650 pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4651 pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4652 pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
4653 pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
4654 pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4655 if (!pf->max_hw_ring_grps)
4656 pf->max_hw_ring_grps = pf->max_tx_rings;
4657 pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4658 pf->max_vnics = le16_to_cpu(resp->max_vnics);
4659 pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
4660 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
4661 pf->max_vfs = le16_to_cpu(resp->max_vfs);
4662 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
4663 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
4664 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
4665 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
4666 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
4667 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
4669 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED))
4670 bp->flags |= BNXT_FLAG_WOL_CAP;
4672 #ifdef CONFIG_BNXT_SRIOV
4673 struct bnxt_vf_info *vf = &bp->vf;
4675 vf->fw_fid = le16_to_cpu(resp->fid);
4677 vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4678 vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4679 vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
4680 vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
4681 vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4682 if (!vf->max_hw_ring_grps)
4683 vf->max_hw_ring_grps = vf->max_tx_rings;
4684 vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4685 vf->max_vnics = le16_to_cpu(resp->max_vnics);
4686 vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
4688 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
4692 hwrm_func_qcaps_exit:
4693 mutex_unlock(&bp->hwrm_cmd_lock);
4697 static int bnxt_hwrm_func_reset(struct bnxt *bp)
4699 struct hwrm_func_reset_input req = {0};
4701 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
4704 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
4707 static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
4710 struct hwrm_queue_qportcfg_input req = {0};
4711 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
4714 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
4716 mutex_lock(&bp->hwrm_cmd_lock);
4717 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4721 if (!resp->max_configurable_queues) {
4725 bp->max_tc = resp->max_configurable_queues;
4726 bp->max_lltc = resp->max_configurable_lossless_queues;
4727 if (bp->max_tc > BNXT_MAX_QUEUE)
4728 bp->max_tc = BNXT_MAX_QUEUE;
4730 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
4733 if (bp->max_lltc > bp->max_tc)
4734 bp->max_lltc = bp->max_tc;
4736 qptr = &resp->queue_id0;
4737 for (i = 0; i < bp->max_tc; i++) {
4738 bp->q_info[i].queue_id = *qptr++;
4739 bp->q_info[i].queue_profile = *qptr++;
4743 mutex_unlock(&bp->hwrm_cmd_lock);
4747 static int bnxt_hwrm_ver_get(struct bnxt *bp)
4750 struct hwrm_ver_get_input req = {0};
4751 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
4754 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
4755 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
4756 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
4757 req.hwrm_intf_min = HWRM_VERSION_MINOR;
4758 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
4759 mutex_lock(&bp->hwrm_cmd_lock);
4760 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4762 goto hwrm_ver_get_exit;
4764 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
4766 bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 |
4767 resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd;
4768 if (resp->hwrm_intf_maj < 1) {
4769 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
4770 resp->hwrm_intf_maj, resp->hwrm_intf_min,
4771 resp->hwrm_intf_upd);
4772 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
4774 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d/%d.%d.%d",
4775 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld,
4776 resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd);
4778 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
4779 if (!bp->hwrm_cmd_timeout)
4780 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
4782 if (resp->hwrm_intf_maj >= 1)
4783 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
4785 bp->chip_num = le16_to_cpu(resp->chip_num);
4786 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
4788 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
4790 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
4791 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
4792 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
4793 bp->flags |= BNXT_FLAG_SHORT_CMD;
4796 mutex_unlock(&bp->hwrm_cmd_lock);
4800 int bnxt_hwrm_fw_set_time(struct bnxt *bp)
4802 #if IS_ENABLED(CONFIG_RTC_LIB)
4803 struct hwrm_fw_set_time_input req = {0};
4807 if (bp->hwrm_spec_code < 0x10400)
4810 do_gettimeofday(&tv);
4811 rtc_time_to_tm(tv.tv_sec, &tm);
4812 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
4813 req.year = cpu_to_le16(1900 + tm.tm_year);
4814 req.month = 1 + tm.tm_mon;
4815 req.day = tm.tm_mday;
4816 req.hour = tm.tm_hour;
4817 req.minute = tm.tm_min;
4818 req.second = tm.tm_sec;
4819 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4825 static int bnxt_hwrm_port_qstats(struct bnxt *bp)
4828 struct bnxt_pf_info *pf = &bp->pf;
4829 struct hwrm_port_qstats_input req = {0};
4831 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
4834 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
4835 req.port_id = cpu_to_le16(pf->port_id);
4836 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
4837 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
4838 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4842 static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
4844 if (bp->vxlan_port_cnt) {
4845 bnxt_hwrm_tunnel_dst_port_free(
4846 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
4848 bp->vxlan_port_cnt = 0;
4849 if (bp->nge_port_cnt) {
4850 bnxt_hwrm_tunnel_dst_port_free(
4851 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
4853 bp->nge_port_cnt = 0;
4856 static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
4862 tpa_flags = bp->flags & BNXT_FLAG_TPA;
4863 for (i = 0; i < bp->nr_vnics; i++) {
4864 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
4866 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
4874 static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
4878 for (i = 0; i < bp->nr_vnics; i++)
4879 bnxt_hwrm_vnic_set_rss(bp, i, false);
4882 static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
4885 if (bp->vnic_info) {
4886 bnxt_hwrm_clear_vnic_filter(bp);
4887 /* clear all RSS setting before free vnic ctx */
4888 bnxt_hwrm_clear_vnic_rss(bp);
4889 bnxt_hwrm_vnic_ctx_free(bp);
4890 /* before free the vnic, undo the vnic tpa settings */
4891 if (bp->flags & BNXT_FLAG_TPA)
4892 bnxt_set_tpa(bp, false);
4893 bnxt_hwrm_vnic_free(bp);
4895 bnxt_hwrm_ring_free(bp, close_path);
4896 bnxt_hwrm_ring_grp_free(bp);
4898 bnxt_hwrm_stat_ctx_free(bp);
4899 bnxt_hwrm_free_tunnel_ports(bp);
4903 static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
4905 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4908 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
4911 /* allocate context for vnic */
4912 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
4914 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4916 goto vnic_setup_err;
4918 bp->rsscos_nr_ctxs++;
4920 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
4921 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
4923 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
4925 goto vnic_setup_err;
4927 bp->rsscos_nr_ctxs++;
4931 /* configure default vnic, ring grp */
4932 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
4934 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
4936 goto vnic_setup_err;
4939 /* Enable RSS hashing on vnic */
4940 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
4942 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
4944 goto vnic_setup_err;
4947 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4948 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
4950 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
4959 static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
4961 #ifdef CONFIG_RFS_ACCEL
4964 for (i = 0; i < bp->rx_nr_rings; i++) {
4965 struct bnxt_vnic_info *vnic;
4966 u16 vnic_id = i + 1;
4969 if (vnic_id >= bp->nr_vnics)
4972 vnic = &bp->vnic_info[vnic_id];
4973 vnic->flags |= BNXT_VNIC_RFS_FLAG;
4974 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
4975 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
4976 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
4978 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4982 rc = bnxt_setup_vnic(bp, vnic_id);
4992 /* Allow PF and VF with default VLAN to be in promiscuous mode */
4993 static bool bnxt_promisc_ok(struct bnxt *bp)
4995 #ifdef CONFIG_BNXT_SRIOV
4996 if (BNXT_VF(bp) && !bp->vf.vlan)
5002 static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
5004 unsigned int rc = 0;
5006 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
5008 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5013 rc = bnxt_hwrm_vnic_cfg(bp, 1);
5015 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5022 static int bnxt_cfg_rx_mode(struct bnxt *);
5023 static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
5025 static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
5027 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
5029 unsigned int rx_nr_rings = bp->rx_nr_rings;
5032 rc = bnxt_hwrm_stat_ctx_alloc(bp);
5034 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5040 rc = bnxt_hwrm_ring_alloc(bp);
5042 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5046 rc = bnxt_hwrm_ring_grp_alloc(bp);
5048 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5052 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5055 /* default vnic 0 */
5056 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
5058 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5062 rc = bnxt_setup_vnic(bp, 0);
5066 if (bp->flags & BNXT_FLAG_RFS) {
5067 rc = bnxt_alloc_rfs_vnics(bp);
5072 if (bp->flags & BNXT_FLAG_TPA) {
5073 rc = bnxt_set_tpa(bp, true);
5079 bnxt_update_vf_mac(bp);
5081 /* Filter for default vnic 0 */
5082 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5084 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5087 vnic->uc_filter_count = 1;
5089 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
5091 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
5092 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5094 if (bp->dev->flags & IFF_ALLMULTI) {
5095 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5096 vnic->mc_list_count = 0;
5100 bnxt_mc_list_updated(bp, &mask);
5101 vnic->rx_mask |= mask;
5104 rc = bnxt_cfg_rx_mode(bp);
5108 rc = bnxt_hwrm_set_coal(bp);
5110 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
5113 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5114 rc = bnxt_setup_nitroa0_vnic(bp);
5116 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5121 bnxt_hwrm_func_qcfg(bp);
5122 netdev_update_features(bp->dev);
5128 bnxt_hwrm_resource_free(bp, 0, true);
5133 static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5135 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5139 static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5141 bnxt_init_cp_rings(bp);
5142 bnxt_init_rx_rings(bp);
5143 bnxt_init_tx_rings(bp);
5144 bnxt_init_ring_grps(bp, irq_re_init);
5145 bnxt_init_vnics(bp);
5147 return bnxt_init_chip(bp, irq_re_init);
5150 static int bnxt_set_real_num_queues(struct bnxt *bp)
5153 struct net_device *dev = bp->dev;
5155 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5156 bp->tx_nr_rings_xdp);
5160 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5164 #ifdef CONFIG_RFS_ACCEL
5165 if (bp->flags & BNXT_FLAG_RFS)
5166 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
5172 static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5175 int _rx = *rx, _tx = *tx;
5178 *rx = min_t(int, _rx, max);
5179 *tx = min_t(int, _tx, max);
5184 while (_rx + _tx > max) {
5185 if (_rx > _tx && _rx > 1)
5196 static void bnxt_setup_msix(struct bnxt *bp)
5198 const int len = sizeof(bp->irq_tbl[0].name);
5199 struct net_device *dev = bp->dev;
5202 tcs = netdev_get_num_tc(dev);
5206 for (i = 0; i < tcs; i++) {
5207 count = bp->tx_nr_rings_per_tc;
5209 netdev_set_tc_queue(dev, i, count, off);
5213 for (i = 0; i < bp->cp_nr_rings; i++) {
5216 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5218 else if (i < bp->rx_nr_rings)
5223 snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr,
5225 bp->irq_tbl[i].handler = bnxt_msix;
5229 static void bnxt_setup_inta(struct bnxt *bp)
5231 const int len = sizeof(bp->irq_tbl[0].name);
5233 if (netdev_get_num_tc(bp->dev))
5234 netdev_reset_tc(bp->dev);
5236 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5238 bp->irq_tbl[0].handler = bnxt_inta;
5241 static int bnxt_setup_int_mode(struct bnxt *bp)
5245 if (bp->flags & BNXT_FLAG_USING_MSIX)
5246 bnxt_setup_msix(bp);
5248 bnxt_setup_inta(bp);
5250 rc = bnxt_set_real_num_queues(bp);
5254 #ifdef CONFIG_RFS_ACCEL
5255 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5257 #if defined(CONFIG_BNXT_SRIOV)
5259 return bp->vf.max_rsscos_ctxs;
5261 return bp->pf.max_rsscos_ctxs;
5264 static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5266 #if defined(CONFIG_BNXT_SRIOV)
5268 return bp->vf.max_vnics;
5270 return bp->pf.max_vnics;
5274 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5276 #if defined(CONFIG_BNXT_SRIOV)
5278 return bp->vf.max_stat_ctxs;
5280 return bp->pf.max_stat_ctxs;
5283 void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5285 #if defined(CONFIG_BNXT_SRIOV)
5287 bp->vf.max_stat_ctxs = max;
5290 bp->pf.max_stat_ctxs = max;
5293 unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5295 #if defined(CONFIG_BNXT_SRIOV)
5297 return bp->vf.max_cp_rings;
5299 return bp->pf.max_cp_rings;
5302 void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5304 #if defined(CONFIG_BNXT_SRIOV)
5306 bp->vf.max_cp_rings = max;
5309 bp->pf.max_cp_rings = max;
5312 static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
5314 #if defined(CONFIG_BNXT_SRIOV)
5316 return min_t(unsigned int, bp->vf.max_irqs,
5317 bp->vf.max_cp_rings);
5319 return min_t(unsigned int, bp->pf.max_irqs, bp->pf.max_cp_rings);
5322 void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5324 #if defined(CONFIG_BNXT_SRIOV)
5326 bp->vf.max_irqs = max_irqs;
5329 bp->pf.max_irqs = max_irqs;
5332 static int bnxt_init_msix(struct bnxt *bp)
5334 int i, total_vecs, rc = 0, min = 1;
5335 struct msix_entry *msix_ent;
5337 total_vecs = bnxt_get_max_func_irqs(bp);
5338 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5342 for (i = 0; i < total_vecs; i++) {
5343 msix_ent[i].entry = i;
5344 msix_ent[i].vector = 0;
5347 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5350 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
5351 if (total_vecs < 0) {
5353 goto msix_setup_exit;
5356 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5358 for (i = 0; i < total_vecs; i++)
5359 bp->irq_tbl[i].vector = msix_ent[i].vector;
5361 bp->total_irqs = total_vecs;
5362 /* Trim rings based upon num of vectors allocated */
5363 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
5364 total_vecs, min == 1);
5366 goto msix_setup_exit;
5368 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5369 bp->cp_nr_rings = (min == 1) ?
5370 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5371 bp->tx_nr_rings + bp->rx_nr_rings;
5375 goto msix_setup_exit;
5377 bp->flags |= BNXT_FLAG_USING_MSIX;
5382 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
5385 pci_disable_msix(bp->pdev);
5390 static int bnxt_init_inta(struct bnxt *bp)
5392 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
5397 bp->rx_nr_rings = 1;
5398 bp->tx_nr_rings = 1;
5399 bp->cp_nr_rings = 1;
5400 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5401 bp->flags |= BNXT_FLAG_SHARED_RINGS;
5402 bp->irq_tbl[0].vector = bp->pdev->irq;
5406 static int bnxt_init_int_mode(struct bnxt *bp)
5410 if (bp->flags & BNXT_FLAG_MSIX_CAP)
5411 rc = bnxt_init_msix(bp);
5413 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
5414 /* fallback to INTA */
5415 rc = bnxt_init_inta(bp);
5420 static void bnxt_clear_int_mode(struct bnxt *bp)
5422 if (bp->flags & BNXT_FLAG_USING_MSIX)
5423 pci_disable_msix(bp->pdev);
5427 bp->flags &= ~BNXT_FLAG_USING_MSIX;
5430 static void bnxt_free_irq(struct bnxt *bp)
5432 struct bnxt_irq *irq;
5435 #ifdef CONFIG_RFS_ACCEL
5436 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
5437 bp->dev->rx_cpu_rmap = NULL;
5442 for (i = 0; i < bp->cp_nr_rings; i++) {
5443 irq = &bp->irq_tbl[i];
5445 free_irq(irq->vector, bp->bnapi[i]);
5450 static int bnxt_request_irq(struct bnxt *bp)
5453 unsigned long flags = 0;
5454 #ifdef CONFIG_RFS_ACCEL
5455 struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap;
5458 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
5459 flags = IRQF_SHARED;
5461 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
5462 struct bnxt_irq *irq = &bp->irq_tbl[i];
5463 #ifdef CONFIG_RFS_ACCEL
5464 if (rmap && bp->bnapi[i]->rx_ring) {
5465 rc = irq_cpu_rmap_add(rmap, irq->vector);
5467 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
5472 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
5482 static void bnxt_del_napi(struct bnxt *bp)
5489 for (i = 0; i < bp->cp_nr_rings; i++) {
5490 struct bnxt_napi *bnapi = bp->bnapi[i];
5492 napi_hash_del(&bnapi->napi);
5493 netif_napi_del(&bnapi->napi);
5495 /* We called napi_hash_del() before netif_napi_del(), we need
5496 * to respect an RCU grace period before freeing napi structures.
5501 static void bnxt_init_napi(struct bnxt *bp)
5504 unsigned int cp_nr_rings = bp->cp_nr_rings;
5505 struct bnxt_napi *bnapi;
5507 if (bp->flags & BNXT_FLAG_USING_MSIX) {
5508 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5510 for (i = 0; i < cp_nr_rings; i++) {
5511 bnapi = bp->bnapi[i];
5512 netif_napi_add(bp->dev, &bnapi->napi,
5515 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5516 bnapi = bp->bnapi[cp_nr_rings];
5517 netif_napi_add(bp->dev, &bnapi->napi,
5518 bnxt_poll_nitroa0, 64);
5521 bnapi = bp->bnapi[0];
5522 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
5526 static void bnxt_disable_napi(struct bnxt *bp)
5533 for (i = 0; i < bp->cp_nr_rings; i++)
5534 napi_disable(&bp->bnapi[i]->napi);
5537 static void bnxt_enable_napi(struct bnxt *bp)
5541 for (i = 0; i < bp->cp_nr_rings; i++) {
5542 bp->bnapi[i]->in_reset = false;
5543 napi_enable(&bp->bnapi[i]->napi);
5547 void bnxt_tx_disable(struct bnxt *bp)
5550 struct bnxt_tx_ring_info *txr;
5551 struct netdev_queue *txq;
5554 for (i = 0; i < bp->tx_nr_rings; i++) {
5555 txr = &bp->tx_ring[i];
5556 txq = netdev_get_tx_queue(bp->dev, i);
5557 txr->dev_state = BNXT_DEV_STATE_CLOSING;
5560 /* Stop all TX queues */
5561 netif_tx_disable(bp->dev);
5562 netif_carrier_off(bp->dev);
5565 void bnxt_tx_enable(struct bnxt *bp)
5568 struct bnxt_tx_ring_info *txr;
5569 struct netdev_queue *txq;
5571 for (i = 0; i < bp->tx_nr_rings; i++) {
5572 txr = &bp->tx_ring[i];
5573 txq = netdev_get_tx_queue(bp->dev, i);
5576 netif_tx_wake_all_queues(bp->dev);
5577 if (bp->link_info.link_up)
5578 netif_carrier_on(bp->dev);
5581 static void bnxt_report_link(struct bnxt *bp)
5583 if (bp->link_info.link_up) {
5585 const char *flow_ctrl;
5589 netif_carrier_on(bp->dev);
5590 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
5594 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
5595 flow_ctrl = "ON - receive & transmit";
5596 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
5597 flow_ctrl = "ON - transmit";
5598 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
5599 flow_ctrl = "ON - receive";
5602 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
5603 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
5604 speed, duplex, flow_ctrl);
5605 if (bp->flags & BNXT_FLAG_EEE_CAP)
5606 netdev_info(bp->dev, "EEE is %s\n",
5607 bp->eee.eee_active ? "active" :
5609 fec = bp->link_info.fec_cfg;
5610 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
5611 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
5612 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
5613 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
5614 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
5616 netif_carrier_off(bp->dev);
5617 netdev_err(bp->dev, "NIC Link is Down\n");
5621 static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
5624 struct hwrm_port_phy_qcaps_input req = {0};
5625 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5626 struct bnxt_link_info *link_info = &bp->link_info;
5628 if (bp->hwrm_spec_code < 0x10201)
5631 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
5633 mutex_lock(&bp->hwrm_cmd_lock);
5634 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5636 goto hwrm_phy_qcaps_exit;
5638 if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) {
5639 struct ethtool_eee *eee = &bp->eee;
5640 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
5642 bp->flags |= BNXT_FLAG_EEE_CAP;
5643 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5644 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
5645 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
5646 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
5647 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
5649 if (resp->supported_speeds_auto_mode)
5650 link_info->support_auto_speeds =
5651 le16_to_cpu(resp->supported_speeds_auto_mode);
5653 hwrm_phy_qcaps_exit:
5654 mutex_unlock(&bp->hwrm_cmd_lock);
5658 static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
5661 struct bnxt_link_info *link_info = &bp->link_info;
5662 struct hwrm_port_phy_qcfg_input req = {0};
5663 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5664 u8 link_up = link_info->link_up;
5667 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
5669 mutex_lock(&bp->hwrm_cmd_lock);
5670 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5672 mutex_unlock(&bp->hwrm_cmd_lock);
5676 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
5677 link_info->phy_link_status = resp->link;
5678 link_info->duplex = resp->duplex;
5679 link_info->pause = resp->pause;
5680 link_info->auto_mode = resp->auto_mode;
5681 link_info->auto_pause_setting = resp->auto_pause;
5682 link_info->lp_pause = resp->link_partner_adv_pause;
5683 link_info->force_pause_setting = resp->force_pause;
5684 link_info->duplex_setting = resp->duplex;
5685 if (link_info->phy_link_status == BNXT_LINK_LINK)
5686 link_info->link_speed = le16_to_cpu(resp->link_speed);
5688 link_info->link_speed = 0;
5689 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
5690 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
5691 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
5692 link_info->lp_auto_link_speeds =
5693 le16_to_cpu(resp->link_partner_adv_speeds);
5694 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
5695 link_info->phy_ver[0] = resp->phy_maj;
5696 link_info->phy_ver[1] = resp->phy_min;
5697 link_info->phy_ver[2] = resp->phy_bld;
5698 link_info->media_type = resp->media_type;
5699 link_info->phy_type = resp->phy_type;
5700 link_info->transceiver = resp->xcvr_pkg_type;
5701 link_info->phy_addr = resp->eee_config_phy_addr &
5702 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
5703 link_info->module_status = resp->module_status;
5705 if (bp->flags & BNXT_FLAG_EEE_CAP) {
5706 struct ethtool_eee *eee = &bp->eee;
5709 eee->eee_active = 0;
5710 if (resp->eee_config_phy_addr &
5711 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
5712 eee->eee_active = 1;
5713 fw_speeds = le16_to_cpu(
5714 resp->link_partner_adv_eee_link_speed_mask);
5715 eee->lp_advertised =
5716 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5719 /* Pull initial EEE config */
5720 if (!chng_link_state) {
5721 if (resp->eee_config_phy_addr &
5722 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
5723 eee->eee_enabled = 1;
5725 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
5727 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5729 if (resp->eee_config_phy_addr &
5730 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
5733 eee->tx_lpi_enabled = 1;
5734 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
5735 eee->tx_lpi_timer = le32_to_cpu(tmr) &
5736 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
5741 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
5742 if (bp->hwrm_spec_code >= 0x10504)
5743 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
5745 /* TODO: need to add more logic to report VF link */
5746 if (chng_link_state) {
5747 if (link_info->phy_link_status == BNXT_LINK_LINK)
5748 link_info->link_up = 1;
5750 link_info->link_up = 0;
5751 if (link_up != link_info->link_up)
5752 bnxt_report_link(bp);
5754 /* alwasy link down if not require to update link state */
5755 link_info->link_up = 0;
5757 mutex_unlock(&bp->hwrm_cmd_lock);
5759 diff = link_info->support_auto_speeds ^ link_info->advertising;
5760 if ((link_info->support_auto_speeds | diff) !=
5761 link_info->support_auto_speeds) {
5762 /* An advertised speed is no longer supported, so we need to
5763 * update the advertisement settings. Caller holds RTNL
5764 * so we can modify link settings.
5766 link_info->advertising = link_info->support_auto_speeds;
5767 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
5768 bnxt_hwrm_set_link_setting(bp, true, false);
5773 static void bnxt_get_port_module_status(struct bnxt *bp)
5775 struct bnxt_link_info *link_info = &bp->link_info;
5776 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
5779 if (bnxt_update_link(bp, true))
5782 module_status = link_info->module_status;
5783 switch (module_status) {
5784 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
5785 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
5786 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
5787 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
5789 if (bp->hwrm_spec_code >= 0x10201) {
5790 netdev_warn(bp->dev, "Module part number %s\n",
5791 resp->phy_vendor_partnumber);
5793 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
5794 netdev_warn(bp->dev, "TX is disabled\n");
5795 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
5796 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
5801 bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
5803 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
5804 if (bp->hwrm_spec_code >= 0x10201)
5806 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
5807 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5808 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
5809 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
5810 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
5812 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5814 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5815 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
5816 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
5817 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
5819 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
5820 if (bp->hwrm_spec_code >= 0x10201) {
5821 req->auto_pause = req->force_pause;
5822 req->enables |= cpu_to_le32(
5823 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5828 static void bnxt_hwrm_set_link_common(struct bnxt *bp,
5829 struct hwrm_port_phy_cfg_input *req)
5831 u8 autoneg = bp->link_info.autoneg;
5832 u16 fw_link_speed = bp->link_info.req_link_speed;
5833 u16 advertising = bp->link_info.advertising;
5835 if (autoneg & BNXT_AUTONEG_SPEED) {
5837 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
5839 req->enables |= cpu_to_le32(
5840 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
5841 req->auto_link_speed_mask = cpu_to_le16(advertising);
5843 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
5845 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
5847 req->force_link_speed = cpu_to_le16(fw_link_speed);
5848 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
5851 /* tell chimp that the setting takes effect immediately */
5852 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
5855 int bnxt_hwrm_set_pause(struct bnxt *bp)
5857 struct hwrm_port_phy_cfg_input req = {0};
5860 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5861 bnxt_hwrm_set_pause_common(bp, &req);
5863 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
5864 bp->link_info.force_link_chng)
5865 bnxt_hwrm_set_link_common(bp, &req);
5867 mutex_lock(&bp->hwrm_cmd_lock);
5868 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5869 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
5870 /* since changing of pause setting doesn't trigger any link
5871 * change event, the driver needs to update the current pause
5872 * result upon successfully return of the phy_cfg command
5874 bp->link_info.pause =
5875 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
5876 bp->link_info.auto_pause_setting = 0;
5877 if (!bp->link_info.force_link_chng)
5878 bnxt_report_link(bp);
5880 bp->link_info.force_link_chng = false;
5881 mutex_unlock(&bp->hwrm_cmd_lock);
5885 static void bnxt_hwrm_set_eee(struct bnxt *bp,
5886 struct hwrm_port_phy_cfg_input *req)
5888 struct ethtool_eee *eee = &bp->eee;
5890 if (eee->eee_enabled) {
5892 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
5894 if (eee->tx_lpi_enabled)
5895 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
5897 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
5899 req->flags |= cpu_to_le32(flags);
5900 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
5901 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
5902 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
5904 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
5908 int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
5910 struct hwrm_port_phy_cfg_input req = {0};
5912 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5914 bnxt_hwrm_set_pause_common(bp, &req);
5916 bnxt_hwrm_set_link_common(bp, &req);
5919 bnxt_hwrm_set_eee(bp, &req);
5920 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5923 static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
5925 struct hwrm_port_phy_cfg_input req = {0};
5927 if (!BNXT_SINGLE_PF(bp))
5930 if (pci_num_vf(bp->pdev))
5933 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5934 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
5935 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5938 static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
5940 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5941 struct hwrm_port_led_qcaps_input req = {0};
5942 struct bnxt_pf_info *pf = &bp->pf;
5945 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
5948 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
5949 req.port_id = cpu_to_le16(pf->port_id);
5950 mutex_lock(&bp->hwrm_cmd_lock);
5951 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5953 mutex_unlock(&bp->hwrm_cmd_lock);
5956 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
5959 bp->num_leds = resp->num_leds;
5960 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
5962 for (i = 0; i < bp->num_leds; i++) {
5963 struct bnxt_led_info *led = &bp->leds[i];
5964 __le16 caps = led->led_state_caps;
5966 if (!led->led_group_id ||
5967 !BNXT_LED_ALT_BLINK_CAP(caps)) {
5973 mutex_unlock(&bp->hwrm_cmd_lock);
5977 int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
5979 struct hwrm_wol_filter_alloc_input req = {0};
5980 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5983 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
5984 req.port_id = cpu_to_le16(bp->pf.port_id);
5985 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
5986 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
5987 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
5988 mutex_lock(&bp->hwrm_cmd_lock);
5989 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5991 bp->wol_filter_id = resp->wol_filter_id;
5992 mutex_unlock(&bp->hwrm_cmd_lock);
5996 int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
5998 struct hwrm_wol_filter_free_input req = {0};
6001 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
6002 req.port_id = cpu_to_le16(bp->pf.port_id);
6003 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
6004 req.wol_filter_id = bp->wol_filter_id;
6005 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6009 static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
6011 struct hwrm_wol_filter_qcfg_input req = {0};
6012 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6013 u16 next_handle = 0;
6016 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
6017 req.port_id = cpu_to_le16(bp->pf.port_id);
6018 req.handle = cpu_to_le16(handle);
6019 mutex_lock(&bp->hwrm_cmd_lock);
6020 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6022 next_handle = le16_to_cpu(resp->next_handle);
6023 if (next_handle != 0) {
6024 if (resp->wol_type ==
6025 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
6027 bp->wol_filter_id = resp->wol_filter_id;
6031 mutex_unlock(&bp->hwrm_cmd_lock);
6035 static void bnxt_get_wol_settings(struct bnxt *bp)
6039 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6043 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6044 } while (handle && handle != 0xffff);
6047 static bool bnxt_eee_config_ok(struct bnxt *bp)
6049 struct ethtool_eee *eee = &bp->eee;
6050 struct bnxt_link_info *link_info = &bp->link_info;
6052 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6055 if (eee->eee_enabled) {
6057 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6059 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6060 eee->eee_enabled = 0;
6063 if (eee->advertised & ~advertising) {
6064 eee->advertised = advertising & eee->supported;
6071 static int bnxt_update_phy_setting(struct bnxt *bp)
6074 bool update_link = false;
6075 bool update_pause = false;
6076 bool update_eee = false;
6077 struct bnxt_link_info *link_info = &bp->link_info;
6079 rc = bnxt_update_link(bp, true);
6081 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6085 if (!BNXT_SINGLE_PF(bp))
6088 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6089 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6090 link_info->req_flow_ctrl)
6091 update_pause = true;
6092 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6093 link_info->force_pause_setting != link_info->req_flow_ctrl)
6094 update_pause = true;
6095 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6096 if (BNXT_AUTO_MODE(link_info->auto_mode))
6098 if (link_info->req_link_speed != link_info->force_link_speed)
6100 if (link_info->req_duplex != link_info->duplex_setting)
6103 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6105 if (link_info->advertising != link_info->auto_link_speeds)
6109 /* The last close may have shutdown the link, so need to call
6110 * PHY_CFG to bring it back up.
6112 if (!netif_carrier_ok(bp->dev))
6115 if (!bnxt_eee_config_ok(bp))
6119 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
6120 else if (update_pause)
6121 rc = bnxt_hwrm_set_pause(bp);
6123 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6131 /* Common routine to pre-map certain register block to different GRC window.
6132 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6133 * in PF and 3 windows in VF that can be customized to map in different
6136 static void bnxt_preset_reg_win(struct bnxt *bp)
6139 /* CAG registers map to GRC window #4 */
6140 writel(BNXT_CAG_REG_BASE,
6141 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6145 static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6149 bnxt_preset_reg_win(bp);
6150 netif_carrier_off(bp->dev);
6152 rc = bnxt_setup_int_mode(bp);
6154 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6159 if ((bp->flags & BNXT_FLAG_RFS) &&
6160 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6161 /* disable RFS if falling back to INTA */
6162 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6163 bp->flags &= ~BNXT_FLAG_RFS;
6166 rc = bnxt_alloc_mem(bp, irq_re_init);
6168 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6169 goto open_err_free_mem;
6174 rc = bnxt_request_irq(bp);
6176 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6181 bnxt_enable_napi(bp);
6183 rc = bnxt_init_nic(bp, irq_re_init);
6185 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6190 rc = bnxt_update_phy_setting(bp);
6192 netdev_warn(bp->dev, "failed to update phy settings\n");
6196 udp_tunnel_get_rx_info(bp->dev);
6198 set_bit(BNXT_STATE_OPEN, &bp->state);
6199 bnxt_enable_int(bp);
6200 /* Enable TX queues */
6202 mod_timer(&bp->timer, jiffies + bp->current_interval);
6203 /* Poll link status and check for SFP+ module status */
6204 bnxt_get_port_module_status(bp);
6209 bnxt_disable_napi(bp);
6215 bnxt_free_mem(bp, true);
6219 /* rtnl_lock held */
6220 int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6224 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6226 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6232 /* rtnl_lock held, open the NIC half way by allocating all resources, but
6233 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6236 int bnxt_half_open_nic(struct bnxt *bp)
6240 rc = bnxt_alloc_mem(bp, false);
6242 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6245 rc = bnxt_init_nic(bp, false);
6247 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6254 bnxt_free_mem(bp, false);
6259 /* rtnl_lock held, this call can only be made after a previous successful
6260 * call to bnxt_half_open_nic().
6262 void bnxt_half_close_nic(struct bnxt *bp)
6264 bnxt_hwrm_resource_free(bp, false, false);
6266 bnxt_free_mem(bp, false);
6269 static int bnxt_open(struct net_device *dev)
6271 struct bnxt *bp = netdev_priv(dev);
6273 return __bnxt_open_nic(bp, true, true);
6276 static bool bnxt_drv_busy(struct bnxt *bp)
6278 return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
6279 test_bit(BNXT_STATE_READ_STATS, &bp->state));
6282 int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6286 #ifdef CONFIG_BNXT_SRIOV
6287 if (bp->sriov_cfg) {
6288 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
6290 BNXT_SRIOV_CFG_WAIT_TMO);
6292 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
6295 /* Change device state to avoid TX queue wake up's */
6296 bnxt_tx_disable(bp);
6298 clear_bit(BNXT_STATE_OPEN, &bp->state);
6299 smp_mb__after_atomic();
6300 while (bnxt_drv_busy(bp))
6303 /* Flush rings and and disable interrupts */
6304 bnxt_shutdown_nic(bp, irq_re_init);
6306 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
6308 bnxt_disable_napi(bp);
6309 del_timer_sync(&bp->timer);
6316 bnxt_free_mem(bp, irq_re_init);
6320 static int bnxt_close(struct net_device *dev)
6322 struct bnxt *bp = netdev_priv(dev);
6324 bnxt_close_nic(bp, true, true);
6325 bnxt_hwrm_shutdown_link(bp);
6329 /* rtnl_lock held */
6330 static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6336 if (!netif_running(dev))
6343 if (!netif_running(dev))
6356 bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6359 struct bnxt *bp = netdev_priv(dev);
6361 set_bit(BNXT_STATE_READ_STATS, &bp->state);
6362 /* Make sure bnxt_close_nic() sees that we are reading stats before
6363 * we check the BNXT_STATE_OPEN flag.
6365 smp_mb__after_atomic();
6366 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6367 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
6371 /* TODO check if we need to synchronize with bnxt_close path */
6372 for (i = 0; i < bp->cp_nr_rings; i++) {
6373 struct bnxt_napi *bnapi = bp->bnapi[i];
6374 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6375 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
6377 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
6378 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
6379 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
6381 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
6382 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
6383 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
6385 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
6386 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
6387 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
6389 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
6390 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
6391 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
6393 stats->rx_missed_errors +=
6394 le64_to_cpu(hw_stats->rx_discard_pkts);
6396 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
6398 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
6401 if (bp->flags & BNXT_FLAG_PORT_STATS) {
6402 struct rx_port_stats *rx = bp->hw_rx_port_stats;
6403 struct tx_port_stats *tx = bp->hw_tx_port_stats;
6405 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
6406 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
6407 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
6408 le64_to_cpu(rx->rx_ovrsz_frames) +
6409 le64_to_cpu(rx->rx_runt_frames);
6410 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
6411 le64_to_cpu(rx->rx_jbr_frames);
6412 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
6413 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
6414 stats->tx_errors = le64_to_cpu(tx->tx_err);
6416 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
6419 static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
6421 struct net_device *dev = bp->dev;
6422 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6423 struct netdev_hw_addr *ha;
6426 bool update = false;
6429 netdev_for_each_mc_addr(ha, dev) {
6430 if (mc_count >= BNXT_MAX_MC_ADDRS) {
6431 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6432 vnic->mc_list_count = 0;
6436 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
6437 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
6444 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
6446 if (mc_count != vnic->mc_list_count) {
6447 vnic->mc_list_count = mc_count;
6453 static bool bnxt_uc_list_updated(struct bnxt *bp)
6455 struct net_device *dev = bp->dev;
6456 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6457 struct netdev_hw_addr *ha;
6460 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
6463 netdev_for_each_uc_addr(ha, dev) {
6464 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
6472 static void bnxt_set_rx_mode(struct net_device *dev)
6474 struct bnxt *bp = netdev_priv(dev);
6475 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6476 u32 mask = vnic->rx_mask;
6477 bool mc_update = false;
6480 if (!netif_running(dev))
6483 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
6484 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
6485 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
6487 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
6488 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6490 uc_update = bnxt_uc_list_updated(bp);
6492 if (dev->flags & IFF_ALLMULTI) {
6493 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6494 vnic->mc_list_count = 0;
6496 mc_update = bnxt_mc_list_updated(bp, &mask);
6499 if (mask != vnic->rx_mask || uc_update || mc_update) {
6500 vnic->rx_mask = mask;
6502 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
6503 schedule_work(&bp->sp_task);
6507 static int bnxt_cfg_rx_mode(struct bnxt *bp)
6509 struct net_device *dev = bp->dev;
6510 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6511 struct netdev_hw_addr *ha;
6515 netif_addr_lock_bh(dev);
6516 uc_update = bnxt_uc_list_updated(bp);
6517 netif_addr_unlock_bh(dev);
6522 mutex_lock(&bp->hwrm_cmd_lock);
6523 for (i = 1; i < vnic->uc_filter_count; i++) {
6524 struct hwrm_cfa_l2_filter_free_input req = {0};
6526 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
6529 req.l2_filter_id = vnic->fw_l2_filter_id[i];
6531 rc = _hwrm_send_message(bp, &req, sizeof(req),
6534 mutex_unlock(&bp->hwrm_cmd_lock);
6536 vnic->uc_filter_count = 1;
6538 netif_addr_lock_bh(dev);
6539 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
6540 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6542 netdev_for_each_uc_addr(ha, dev) {
6543 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
6545 vnic->uc_filter_count++;
6548 netif_addr_unlock_bh(dev);
6550 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
6551 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
6553 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
6555 vnic->uc_filter_count = i;
6561 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
6563 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
6569 /* If the chip and firmware supports RFS */
6570 static bool bnxt_rfs_supported(struct bnxt *bp)
6572 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
6574 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6579 /* If runtime conditions support RFS */
6580 static bool bnxt_rfs_capable(struct bnxt *bp)
6582 #ifdef CONFIG_RFS_ACCEL
6583 int vnics, max_vnics, max_rss_ctxs;
6585 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
6588 vnics = 1 + bp->rx_nr_rings;
6589 max_vnics = bnxt_get_max_func_vnics(bp);
6590 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
6592 /* RSS contexts not a limiting factor */
6593 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6594 max_rss_ctxs = max_vnics;
6595 if (vnics > max_vnics || vnics > max_rss_ctxs) {
6596 netdev_warn(bp->dev,
6597 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
6598 min(max_rss_ctxs - 1, max_vnics - 1));
6608 static netdev_features_t bnxt_fix_features(struct net_device *dev,
6609 netdev_features_t features)
6611 struct bnxt *bp = netdev_priv(dev);
6613 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
6614 features &= ~NETIF_F_NTUPLE;
6616 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
6617 * turned on or off together.
6619 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
6620 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
6621 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
6622 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6623 NETIF_F_HW_VLAN_STAG_RX);
6625 features |= NETIF_F_HW_VLAN_CTAG_RX |
6626 NETIF_F_HW_VLAN_STAG_RX;
6628 #ifdef CONFIG_BNXT_SRIOV
6631 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6632 NETIF_F_HW_VLAN_STAG_RX);
6639 static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
6641 struct bnxt *bp = netdev_priv(dev);
6642 u32 flags = bp->flags;
6645 bool re_init = false;
6646 bool update_tpa = false;
6648 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
6649 if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
6650 flags |= BNXT_FLAG_GRO;
6651 if (features & NETIF_F_LRO)
6652 flags |= BNXT_FLAG_LRO;
6654 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
6655 flags &= ~BNXT_FLAG_TPA;
6657 if (features & NETIF_F_HW_VLAN_CTAG_RX)
6658 flags |= BNXT_FLAG_STRIP_VLAN;
6660 if (features & NETIF_F_NTUPLE)
6661 flags |= BNXT_FLAG_RFS;
6663 changes = flags ^ bp->flags;
6664 if (changes & BNXT_FLAG_TPA) {
6666 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
6667 (flags & BNXT_FLAG_TPA) == 0)
6671 if (changes & ~BNXT_FLAG_TPA)
6674 if (flags != bp->flags) {
6675 u32 old_flags = bp->flags;
6679 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6681 bnxt_set_ring_params(bp);
6686 bnxt_close_nic(bp, false, false);
6688 bnxt_set_ring_params(bp);
6690 return bnxt_open_nic(bp, false, false);
6693 rc = bnxt_set_tpa(bp,
6694 (flags & BNXT_FLAG_TPA) ?
6697 bp->flags = old_flags;
6703 static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
6705 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
6706 int i = bnapi->index;
6711 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
6712 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
6716 static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
6718 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
6719 int i = bnapi->index;
6724 netdev_info(bnapi->bp->dev, "[%d]: rx{fw_ring: %d prod: %x} rx_agg{fw_ring: %d agg_prod: %x sw_agg_prod: %x}\n",
6725 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
6726 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
6727 rxr->rx_sw_agg_prod);
6730 static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
6732 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6733 int i = bnapi->index;
6735 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
6736 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
6739 static void bnxt_dbg_dump_states(struct bnxt *bp)
6742 struct bnxt_napi *bnapi;
6744 for (i = 0; i < bp->cp_nr_rings; i++) {
6745 bnapi = bp->bnapi[i];
6746 if (netif_msg_drv(bp)) {
6747 bnxt_dump_tx_sw_state(bnapi);
6748 bnxt_dump_rx_sw_state(bnapi);
6749 bnxt_dump_cp_sw_state(bnapi);
6754 static void bnxt_reset_task(struct bnxt *bp, bool silent)
6757 bnxt_dbg_dump_states(bp);
6758 if (netif_running(bp->dev)) {
6763 bnxt_close_nic(bp, false, false);
6764 rc = bnxt_open_nic(bp, false, false);
6770 static void bnxt_tx_timeout(struct net_device *dev)
6772 struct bnxt *bp = netdev_priv(dev);
6774 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
6775 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
6776 schedule_work(&bp->sp_task);
6779 #ifdef CONFIG_NET_POLL_CONTROLLER
6780 static void bnxt_poll_controller(struct net_device *dev)
6782 struct bnxt *bp = netdev_priv(dev);
6785 /* Only process tx rings/combined rings in netpoll mode. */
6786 for (i = 0; i < bp->tx_nr_rings; i++) {
6787 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
6789 napi_schedule(&txr->bnapi->napi);
6794 static void bnxt_timer(unsigned long data)
6796 struct bnxt *bp = (struct bnxt *)data;
6797 struct net_device *dev = bp->dev;
6799 if (!netif_running(dev))
6802 if (atomic_read(&bp->intr_sem) != 0)
6803 goto bnxt_restart_timer;
6805 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) {
6806 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
6807 schedule_work(&bp->sp_task);
6810 mod_timer(&bp->timer, jiffies + bp->current_interval);
6813 static void bnxt_rtnl_lock_sp(struct bnxt *bp)
6815 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
6816 * set. If the device is being closed, bnxt_close() may be holding
6817 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
6818 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
6820 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6824 static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
6826 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6830 /* Only called from bnxt_sp_task() */
6831 static void bnxt_reset(struct bnxt *bp, bool silent)
6833 bnxt_rtnl_lock_sp(bp);
6834 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6835 bnxt_reset_task(bp, silent);
6836 bnxt_rtnl_unlock_sp(bp);
6839 static void bnxt_cfg_ntp_filters(struct bnxt *);
6841 static void bnxt_sp_task(struct work_struct *work)
6843 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
6845 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6846 smp_mb__after_atomic();
6847 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6848 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6852 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
6853 bnxt_cfg_rx_mode(bp);
6855 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
6856 bnxt_cfg_ntp_filters(bp);
6857 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
6858 bnxt_hwrm_exec_fwd_req(bp);
6859 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6860 bnxt_hwrm_tunnel_dst_port_alloc(
6862 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6864 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6865 bnxt_hwrm_tunnel_dst_port_free(
6866 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6868 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6869 bnxt_hwrm_tunnel_dst_port_alloc(
6871 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6873 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6874 bnxt_hwrm_tunnel_dst_port_free(
6875 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6877 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event))
6878 bnxt_hwrm_port_qstats(bp);
6880 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
6881 * must be the last functions to be called before exiting.
6883 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
6886 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
6888 bnxt_hwrm_phy_qcaps(bp);
6890 bnxt_rtnl_lock_sp(bp);
6891 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6892 rc = bnxt_update_link(bp, true);
6893 bnxt_rtnl_unlock_sp(bp);
6895 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
6898 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
6899 bnxt_rtnl_lock_sp(bp);
6900 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6901 bnxt_get_port_module_status(bp);
6902 bnxt_rtnl_unlock_sp(bp);
6904 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
6905 bnxt_reset(bp, false);
6907 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
6908 bnxt_reset(bp, true);
6910 smp_mb__before_atomic();
6911 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6914 /* Under rtnl_lock */
6915 int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
6918 int max_rx, max_tx, tx_sets = 1;
6919 int tx_rings_needed;
6925 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
6932 tx_rings_needed = tx * tx_sets + tx_xdp;
6933 if (max_tx < tx_rings_needed)
6936 if (bnxt_hwrm_reserve_tx_rings(bp, &tx_rings_needed) ||
6937 tx_rings_needed < (tx * tx_sets + tx_xdp))
6942 static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
6945 pci_iounmap(pdev, bp->bar2);
6950 pci_iounmap(pdev, bp->bar1);
6955 pci_iounmap(pdev, bp->bar0);
6960 static void bnxt_cleanup_pci(struct bnxt *bp)
6962 bnxt_unmap_bars(bp, bp->pdev);
6963 pci_release_regions(bp->pdev);
6964 pci_disable_device(bp->pdev);
6967 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
6970 struct bnxt *bp = netdev_priv(dev);
6972 SET_NETDEV_DEV(dev, &pdev->dev);
6974 /* enable device (incl. PCI PM wakeup), and bus-mastering */
6975 rc = pci_enable_device(pdev);
6977 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
6981 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
6983 "Cannot find PCI device base address, aborting\n");
6985 goto init_err_disable;
6988 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
6990 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
6991 goto init_err_disable;
6994 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
6995 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
6996 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
6997 goto init_err_disable;
7000 pci_set_master(pdev);
7005 bp->bar0 = pci_ioremap_bar(pdev, 0);
7007 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
7009 goto init_err_release;
7012 bp->bar1 = pci_ioremap_bar(pdev, 2);
7014 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
7016 goto init_err_release;
7019 bp->bar2 = pci_ioremap_bar(pdev, 4);
7021 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
7023 goto init_err_release;
7026 pci_enable_pcie_error_reporting(pdev);
7028 INIT_WORK(&bp->sp_task, bnxt_sp_task);
7030 spin_lock_init(&bp->ntp_fltr_lock);
7032 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
7033 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
7035 /* tick values in micro seconds */
7036 bp->rx_coal_ticks = 12;
7037 bp->rx_coal_bufs = 30;
7038 bp->rx_coal_ticks_irq = 1;
7039 bp->rx_coal_bufs_irq = 2;
7041 bp->tx_coal_ticks = 25;
7042 bp->tx_coal_bufs = 30;
7043 bp->tx_coal_ticks_irq = 2;
7044 bp->tx_coal_bufs_irq = 2;
7046 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7048 init_timer(&bp->timer);
7049 bp->timer.data = (unsigned long)bp;
7050 bp->timer.function = bnxt_timer;
7051 bp->current_interval = BNXT_TIMER_INTERVAL;
7053 clear_bit(BNXT_STATE_OPEN, &bp->state);
7057 bnxt_unmap_bars(bp, pdev);
7058 pci_release_regions(pdev);
7061 pci_disable_device(pdev);
7067 /* rtnl_lock held */
7068 static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7070 struct sockaddr *addr = p;
7071 struct bnxt *bp = netdev_priv(dev);
7074 if (!is_valid_ether_addr(addr->sa_data))
7075 return -EADDRNOTAVAIL;
7077 rc = bnxt_approve_mac(bp, addr->sa_data);
7081 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7084 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7085 if (netif_running(dev)) {
7086 bnxt_close_nic(bp, false, false);
7087 rc = bnxt_open_nic(bp, false, false);
7093 /* rtnl_lock held */
7094 static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7096 struct bnxt *bp = netdev_priv(dev);
7098 if (netif_running(dev))
7099 bnxt_close_nic(bp, false, false);
7102 bnxt_set_ring_params(bp);
7104 if (netif_running(dev))
7105 return bnxt_open_nic(bp, false, false);
7110 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
7112 struct bnxt *bp = netdev_priv(dev);
7116 if (tc > bp->max_tc) {
7117 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
7122 if (netdev_get_num_tc(dev) == tc)
7125 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7128 rc = bnxt_reserve_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7129 sh, tc, bp->tx_nr_rings_xdp);
7133 /* Needs to close the device and do hw resource re-allocations */
7134 if (netif_running(bp->dev))
7135 bnxt_close_nic(bp, true, false);
7138 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7139 netdev_set_num_tc(dev, tc);
7141 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7142 netdev_reset_tc(dev);
7144 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
7145 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7146 bp->tx_nr_rings + bp->rx_nr_rings;
7147 bp->num_stat_ctxs = bp->cp_nr_rings;
7149 if (netif_running(bp->dev))
7150 return bnxt_open_nic(bp, true, false);
7155 static int bnxt_setup_tc(struct net_device *dev, u32 handle, u32 chain_index,
7156 __be16 proto, struct tc_to_netdev *ntc)
7158 if (ntc->type != TC_SETUP_MQPRIO)
7161 ntc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7163 return bnxt_setup_mq_tc(dev, ntc->mqprio->num_tc);
7166 #ifdef CONFIG_RFS_ACCEL
7167 static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7168 struct bnxt_ntuple_filter *f2)
7170 struct flow_keys *keys1 = &f1->fkeys;
7171 struct flow_keys *keys2 = &f2->fkeys;
7173 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7174 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7175 keys1->ports.ports == keys2->ports.ports &&
7176 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7177 keys1->basic.n_proto == keys2->basic.n_proto &&
7178 keys1->control.flags == keys2->control.flags &&
7179 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7180 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
7186 static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
7187 u16 rxq_index, u32 flow_id)
7189 struct bnxt *bp = netdev_priv(dev);
7190 struct bnxt_ntuple_filter *fltr, *new_fltr;
7191 struct flow_keys *fkeys;
7192 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
7193 int rc = 0, idx, bit_id, l2_idx = 0;
7194 struct hlist_head *head;
7196 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
7197 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7200 netif_addr_lock_bh(dev);
7201 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
7202 if (ether_addr_equal(eth->h_dest,
7203 vnic->uc_list + off)) {
7208 netif_addr_unlock_bh(dev);
7212 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
7216 fkeys = &new_fltr->fkeys;
7217 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
7218 rc = -EPROTONOSUPPORT;
7222 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
7223 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
7224 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
7225 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
7226 rc = -EPROTONOSUPPORT;
7229 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
7230 bp->hwrm_spec_code < 0x10601) {
7231 rc = -EPROTONOSUPPORT;
7234 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
7235 bp->hwrm_spec_code < 0x10601) {
7236 rc = -EPROTONOSUPPORT;
7240 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
7241 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
7243 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
7244 head = &bp->ntp_fltr_hash_tbl[idx];
7246 hlist_for_each_entry_rcu(fltr, head, hash) {
7247 if (bnxt_fltr_match(fltr, new_fltr)) {
7255 spin_lock_bh(&bp->ntp_fltr_lock);
7256 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
7257 BNXT_NTP_FLTR_MAX_FLTR, 0);
7259 spin_unlock_bh(&bp->ntp_fltr_lock);
7264 new_fltr->sw_id = (u16)bit_id;
7265 new_fltr->flow_id = flow_id;
7266 new_fltr->l2_fltr_idx = l2_idx;
7267 new_fltr->rxq = rxq_index;
7268 hlist_add_head_rcu(&new_fltr->hash, head);
7269 bp->ntp_fltr_count++;
7270 spin_unlock_bh(&bp->ntp_fltr_lock);
7272 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
7273 schedule_work(&bp->sp_task);
7275 return new_fltr->sw_id;
7282 static void bnxt_cfg_ntp_filters(struct bnxt *bp)
7286 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
7287 struct hlist_head *head;
7288 struct hlist_node *tmp;
7289 struct bnxt_ntuple_filter *fltr;
7292 head = &bp->ntp_fltr_hash_tbl[i];
7293 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
7296 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
7297 if (rps_may_expire_flow(bp->dev, fltr->rxq,
7300 bnxt_hwrm_cfa_ntuple_filter_free(bp,
7305 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
7310 set_bit(BNXT_FLTR_VALID, &fltr->state);
7314 spin_lock_bh(&bp->ntp_fltr_lock);
7315 hlist_del_rcu(&fltr->hash);
7316 bp->ntp_fltr_count--;
7317 spin_unlock_bh(&bp->ntp_fltr_lock);
7319 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
7324 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
7325 netdev_info(bp->dev, "Receive PF driver unload event!");
7330 static void bnxt_cfg_ntp_filters(struct bnxt *bp)
7334 #endif /* CONFIG_RFS_ACCEL */
7336 static void bnxt_udp_tunnel_add(struct net_device *dev,
7337 struct udp_tunnel_info *ti)
7339 struct bnxt *bp = netdev_priv(dev);
7341 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7344 if (!netif_running(dev))
7348 case UDP_TUNNEL_TYPE_VXLAN:
7349 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
7352 bp->vxlan_port_cnt++;
7353 if (bp->vxlan_port_cnt == 1) {
7354 bp->vxlan_port = ti->port;
7355 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
7356 schedule_work(&bp->sp_task);
7359 case UDP_TUNNEL_TYPE_GENEVE:
7360 if (bp->nge_port_cnt && bp->nge_port != ti->port)
7364 if (bp->nge_port_cnt == 1) {
7365 bp->nge_port = ti->port;
7366 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
7373 schedule_work(&bp->sp_task);
7376 static void bnxt_udp_tunnel_del(struct net_device *dev,
7377 struct udp_tunnel_info *ti)
7379 struct bnxt *bp = netdev_priv(dev);
7381 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7384 if (!netif_running(dev))
7388 case UDP_TUNNEL_TYPE_VXLAN:
7389 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
7391 bp->vxlan_port_cnt--;
7393 if (bp->vxlan_port_cnt != 0)
7396 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
7398 case UDP_TUNNEL_TYPE_GENEVE:
7399 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
7403 if (bp->nge_port_cnt != 0)
7406 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
7412 schedule_work(&bp->sp_task);
7415 static const struct net_device_ops bnxt_netdev_ops = {
7416 .ndo_open = bnxt_open,
7417 .ndo_start_xmit = bnxt_start_xmit,
7418 .ndo_stop = bnxt_close,
7419 .ndo_get_stats64 = bnxt_get_stats64,
7420 .ndo_set_rx_mode = bnxt_set_rx_mode,
7421 .ndo_do_ioctl = bnxt_ioctl,
7422 .ndo_validate_addr = eth_validate_addr,
7423 .ndo_set_mac_address = bnxt_change_mac_addr,
7424 .ndo_change_mtu = bnxt_change_mtu,
7425 .ndo_fix_features = bnxt_fix_features,
7426 .ndo_set_features = bnxt_set_features,
7427 .ndo_tx_timeout = bnxt_tx_timeout,
7428 #ifdef CONFIG_BNXT_SRIOV
7429 .ndo_get_vf_config = bnxt_get_vf_config,
7430 .ndo_set_vf_mac = bnxt_set_vf_mac,
7431 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
7432 .ndo_set_vf_rate = bnxt_set_vf_bw,
7433 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
7434 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
7436 #ifdef CONFIG_NET_POLL_CONTROLLER
7437 .ndo_poll_controller = bnxt_poll_controller,
7439 .ndo_setup_tc = bnxt_setup_tc,
7440 #ifdef CONFIG_RFS_ACCEL
7441 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
7443 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
7444 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
7445 .ndo_xdp = bnxt_xdp,
7448 static void bnxt_remove_one(struct pci_dev *pdev)
7450 struct net_device *dev = pci_get_drvdata(pdev);
7451 struct bnxt *bp = netdev_priv(dev);
7454 bnxt_sriov_disable(bp);
7456 pci_disable_pcie_error_reporting(pdev);
7457 unregister_netdev(dev);
7458 cancel_work_sync(&bp->sp_task);
7461 bnxt_clear_int_mode(bp);
7462 bnxt_hwrm_func_drv_unrgtr(bp);
7463 bnxt_free_hwrm_resources(bp);
7464 bnxt_free_hwrm_short_cmd_req(bp);
7465 bnxt_ethtool_free(bp);
7470 bpf_prog_put(bp->xdp_prog);
7471 bnxt_cleanup_pci(bp);
7475 static int bnxt_probe_phy(struct bnxt *bp)
7478 struct bnxt_link_info *link_info = &bp->link_info;
7480 rc = bnxt_hwrm_phy_qcaps(bp);
7482 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
7487 rc = bnxt_update_link(bp, false);
7489 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
7494 /* Older firmware does not have supported_auto_speeds, so assume
7495 * that all supported speeds can be autonegotiated.
7497 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
7498 link_info->support_auto_speeds = link_info->support_speeds;
7500 /*initialize the ethool setting copy with NVM settings */
7501 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
7502 link_info->autoneg = BNXT_AUTONEG_SPEED;
7503 if (bp->hwrm_spec_code >= 0x10201) {
7504 if (link_info->auto_pause_setting &
7505 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
7506 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7508 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7510 link_info->advertising = link_info->auto_link_speeds;
7512 link_info->req_link_speed = link_info->force_link_speed;
7513 link_info->req_duplex = link_info->duplex_setting;
7515 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
7516 link_info->req_flow_ctrl =
7517 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
7519 link_info->req_flow_ctrl = link_info->force_pause_setting;
7523 static int bnxt_get_max_irq(struct pci_dev *pdev)
7527 if (!pdev->msix_cap)
7530 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
7531 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
7534 static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7537 int max_ring_grps = 0;
7539 #ifdef CONFIG_BNXT_SRIOV
7541 *max_tx = bp->vf.max_tx_rings;
7542 *max_rx = bp->vf.max_rx_rings;
7543 *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings);
7544 *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs);
7545 max_ring_grps = bp->vf.max_hw_ring_grps;
7549 *max_tx = bp->pf.max_tx_rings;
7550 *max_rx = bp->pf.max_rx_rings;
7551 *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings);
7552 *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs);
7553 max_ring_grps = bp->pf.max_hw_ring_grps;
7555 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
7559 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7561 *max_rx = min_t(int, *max_rx, max_ring_grps);
7564 int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
7568 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
7569 if (!rx || !tx || !cp)
7574 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
7577 static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7582 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
7583 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
7584 /* Not enough rings, try disabling agg rings. */
7585 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
7586 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
7589 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
7590 bp->dev->hw_features &= ~NETIF_F_LRO;
7591 bp->dev->features &= ~NETIF_F_LRO;
7592 bnxt_set_ring_params(bp);
7595 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
7596 int max_cp, max_stat, max_irq;
7598 /* Reserve minimum resources for RoCE */
7599 max_cp = bnxt_get_max_func_cp_rings(bp);
7600 max_stat = bnxt_get_max_func_stat_ctxs(bp);
7601 max_irq = bnxt_get_max_func_irqs(bp);
7602 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
7603 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
7604 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
7607 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
7608 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
7609 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
7610 max_cp = min_t(int, max_cp, max_irq);
7611 max_cp = min_t(int, max_cp, max_stat);
7612 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
7619 static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
7621 int dflt_rings, max_rx_rings, max_tx_rings, rc;
7624 bp->flags |= BNXT_FLAG_SHARED_RINGS;
7625 dflt_rings = netif_get_num_default_rss_queues();
7626 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
7629 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
7630 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
7632 rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc);
7634 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
7636 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7637 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7638 bp->tx_nr_rings + bp->rx_nr_rings;
7639 bp->num_stat_ctxs = bp->cp_nr_rings;
7640 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
7647 void bnxt_restore_pf_fw_resources(struct bnxt *bp)
7650 bnxt_hwrm_func_qcaps(bp);
7651 bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP);
7654 static int bnxt_init_mac_addr(struct bnxt *bp)
7659 memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
7661 #ifdef CONFIG_BNXT_SRIOV
7662 struct bnxt_vf_info *vf = &bp->vf;
7664 if (is_valid_ether_addr(vf->mac_addr)) {
7665 /* overwrite netdev dev_adr with admin VF MAC */
7666 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
7668 eth_hw_addr_random(bp->dev);
7669 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
7676 static void bnxt_parse_log_pcie_link(struct bnxt *bp)
7678 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
7679 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
7681 if (pcie_get_minimum_link(bp->pdev, &speed, &width) ||
7682 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
7683 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
7685 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
7686 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
7687 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
7688 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
7692 static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7694 static int version_printed;
7695 struct net_device *dev;
7699 if (pci_is_bridge(pdev))
7702 if (version_printed++ == 0)
7703 pr_info("%s", version);
7705 max_irqs = bnxt_get_max_irq(pdev);
7706 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
7710 bp = netdev_priv(dev);
7712 if (bnxt_vf_pciid(ent->driver_data))
7713 bp->flags |= BNXT_FLAG_VF;
7716 bp->flags |= BNXT_FLAG_MSIX_CAP;
7718 rc = bnxt_init_board(pdev, dev);
7722 dev->netdev_ops = &bnxt_netdev_ops;
7723 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
7724 dev->ethtool_ops = &bnxt_ethtool_ops;
7725 pci_set_drvdata(pdev, dev);
7727 rc = bnxt_alloc_hwrm_resources(bp);
7729 goto init_err_pci_clean;
7731 mutex_init(&bp->hwrm_cmd_lock);
7732 rc = bnxt_hwrm_ver_get(bp);
7734 goto init_err_pci_clean;
7736 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
7737 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
7739 goto init_err_pci_clean;
7742 rc = bnxt_hwrm_func_reset(bp);
7744 goto init_err_pci_clean;
7746 bnxt_hwrm_fw_set_time(bp);
7748 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7749 NETIF_F_TSO | NETIF_F_TSO6 |
7750 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
7751 NETIF_F_GSO_IPXIP4 |
7752 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7753 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
7754 NETIF_F_RXCSUM | NETIF_F_GRO;
7756 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
7757 dev->hw_features |= NETIF_F_LRO;
7759 dev->hw_enc_features =
7760 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7761 NETIF_F_TSO | NETIF_F_TSO6 |
7762 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
7763 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7764 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
7765 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
7766 NETIF_F_GSO_GRE_CSUM;
7767 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
7768 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7769 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
7770 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
7771 dev->priv_flags |= IFF_UNICAST_FLT;
7773 /* MTU range: 60 - 9500 */
7774 dev->min_mtu = ETH_ZLEN;
7775 dev->max_mtu = BNXT_MAX_MTU;
7777 #ifdef CONFIG_BNXT_SRIOV
7778 init_waitqueue_head(&bp->sriov_cfg_wait);
7780 bp->gro_func = bnxt_gro_func_5730x;
7781 if (BNXT_CHIP_P4_PLUS(bp))
7782 bp->gro_func = bnxt_gro_func_5731x;
7784 bp->flags |= BNXT_FLAG_DOUBLE_DB;
7786 rc = bnxt_hwrm_func_drv_rgtr(bp);
7788 goto init_err_pci_clean;
7790 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
7792 goto init_err_pci_clean;
7794 bp->ulp_probe = bnxt_ulp_probe;
7796 /* Get the MAX capabilities for this function */
7797 rc = bnxt_hwrm_func_qcaps(bp);
7799 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
7802 goto init_err_pci_clean;
7804 rc = bnxt_init_mac_addr(bp);
7806 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
7807 rc = -EADDRNOTAVAIL;
7808 goto init_err_pci_clean;
7810 rc = bnxt_hwrm_queue_qportcfg(bp);
7812 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
7815 goto init_err_pci_clean;
7818 bnxt_hwrm_func_qcfg(bp);
7819 bnxt_hwrm_port_led_qcaps(bp);
7820 bnxt_ethtool_init(bp);
7823 bnxt_set_rx_skb_mode(bp, false);
7824 bnxt_set_tpa_flags(bp);
7825 bnxt_set_ring_params(bp);
7826 bnxt_set_max_func_irqs(bp, max_irqs);
7827 rc = bnxt_set_dflt_rings(bp, true);
7829 netdev_err(bp->dev, "Not enough rings available.\n");
7831 goto init_err_pci_clean;
7834 /* Default RSS hash cfg. */
7835 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
7836 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
7837 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
7838 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
7839 if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
7840 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
7841 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
7842 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
7845 bnxt_hwrm_vnic_qcaps(bp);
7846 if (bnxt_rfs_supported(bp)) {
7847 dev->hw_features |= NETIF_F_NTUPLE;
7848 if (bnxt_rfs_capable(bp)) {
7849 bp->flags |= BNXT_FLAG_RFS;
7850 dev->features |= NETIF_F_NTUPLE;
7854 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
7855 bp->flags |= BNXT_FLAG_STRIP_VLAN;
7857 rc = bnxt_probe_phy(bp);
7859 goto init_err_pci_clean;
7861 rc = bnxt_init_int_mode(bp);
7863 goto init_err_pci_clean;
7865 bnxt_get_wol_settings(bp);
7866 if (bp->flags & BNXT_FLAG_WOL_CAP)
7867 device_set_wakeup_enable(&pdev->dev, bp->wol);
7869 device_set_wakeup_capable(&pdev->dev, false);
7871 rc = register_netdev(dev);
7873 goto init_err_clr_int;
7875 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
7876 board_info[ent->driver_data].name,
7877 (long)pci_resource_start(pdev, 0), dev->dev_addr);
7879 bnxt_parse_log_pcie_link(bp);
7884 bnxt_clear_int_mode(bp);
7887 bnxt_cleanup_pci(bp);
7894 static void bnxt_shutdown(struct pci_dev *pdev)
7896 struct net_device *dev = pci_get_drvdata(pdev);
7903 bp = netdev_priv(dev);
7907 if (netif_running(dev))
7910 if (system_state == SYSTEM_POWER_OFF) {
7911 bnxt_ulp_shutdown(bp);
7912 bnxt_clear_int_mode(bp);
7913 pci_wake_from_d3(pdev, bp->wol);
7914 pci_set_power_state(pdev, PCI_D3hot);
7921 #ifdef CONFIG_PM_SLEEP
7922 static int bnxt_suspend(struct device *device)
7924 struct pci_dev *pdev = to_pci_dev(device);
7925 struct net_device *dev = pci_get_drvdata(pdev);
7926 struct bnxt *bp = netdev_priv(dev);
7930 if (netif_running(dev)) {
7931 netif_device_detach(dev);
7932 rc = bnxt_close(dev);
7934 bnxt_hwrm_func_drv_unrgtr(bp);
7939 static int bnxt_resume(struct device *device)
7941 struct pci_dev *pdev = to_pci_dev(device);
7942 struct net_device *dev = pci_get_drvdata(pdev);
7943 struct bnxt *bp = netdev_priv(dev);
7947 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
7951 rc = bnxt_hwrm_func_reset(bp);
7956 bnxt_get_wol_settings(bp);
7957 if (netif_running(dev)) {
7958 rc = bnxt_open(dev);
7960 netif_device_attach(dev);
7968 static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
7969 #define BNXT_PM_OPS (&bnxt_pm_ops)
7973 #define BNXT_PM_OPS NULL
7975 #endif /* CONFIG_PM_SLEEP */
7978 * bnxt_io_error_detected - called when PCI error is detected
7979 * @pdev: Pointer to PCI device
7980 * @state: The current pci connection state
7982 * This function is called after a PCI bus error affecting
7983 * this device has been detected.
7985 static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
7986 pci_channel_state_t state)
7988 struct net_device *netdev = pci_get_drvdata(pdev);
7989 struct bnxt *bp = netdev_priv(netdev);
7991 netdev_info(netdev, "PCI I/O error detected\n");
7994 netif_device_detach(netdev);
7998 if (state == pci_channel_io_perm_failure) {
8000 return PCI_ERS_RESULT_DISCONNECT;
8003 if (netif_running(netdev))
8006 pci_disable_device(pdev);
8009 /* Request a slot slot reset. */
8010 return PCI_ERS_RESULT_NEED_RESET;
8014 * bnxt_io_slot_reset - called after the pci bus has been reset.
8015 * @pdev: Pointer to PCI device
8017 * Restart the card from scratch, as if from a cold-boot.
8018 * At this point, the card has exprienced a hard reset,
8019 * followed by fixups by BIOS, and has its config space
8020 * set up identically to what it was at cold boot.
8022 static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
8024 struct net_device *netdev = pci_get_drvdata(pdev);
8025 struct bnxt *bp = netdev_priv(netdev);
8027 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
8029 netdev_info(bp->dev, "PCI Slot Reset\n");
8033 if (pci_enable_device(pdev)) {
8035 "Cannot re-enable PCI device after reset.\n");
8037 pci_set_master(pdev);
8039 err = bnxt_hwrm_func_reset(bp);
8040 if (!err && netif_running(netdev))
8041 err = bnxt_open(netdev);
8044 result = PCI_ERS_RESULT_RECOVERED;
8049 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
8054 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8057 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8058 err); /* non-fatal, continue */
8061 return PCI_ERS_RESULT_RECOVERED;
8065 * bnxt_io_resume - called when traffic can start flowing again.
8066 * @pdev: Pointer to PCI device
8068 * This callback is called when the error recovery driver tells
8069 * us that its OK to resume normal operation.
8071 static void bnxt_io_resume(struct pci_dev *pdev)
8073 struct net_device *netdev = pci_get_drvdata(pdev);
8077 netif_device_attach(netdev);
8082 static const struct pci_error_handlers bnxt_err_handler = {
8083 .error_detected = bnxt_io_error_detected,
8084 .slot_reset = bnxt_io_slot_reset,
8085 .resume = bnxt_io_resume
8088 static struct pci_driver bnxt_pci_driver = {
8089 .name = DRV_MODULE_NAME,
8090 .id_table = bnxt_pci_tbl,
8091 .probe = bnxt_init_one,
8092 .remove = bnxt_remove_one,
8093 .shutdown = bnxt_shutdown,
8094 .driver.pm = BNXT_PM_OPS,
8095 .err_handler = &bnxt_err_handler,
8096 #if defined(CONFIG_BNXT_SRIOV)
8097 .sriov_configure = bnxt_sriov_configure,
8101 module_pci_driver(bnxt_pci_driver);