1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
10 #include <linux/module.h>
12 #include <linux/stringify.h>
13 #include <linux/kernel.h>
14 #include <linux/timer.h>
15 #include <linux/errno.h>
16 #include <linux/ioport.h>
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/interrupt.h>
20 #include <linux/pci.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/bitops.h>
27 #include <linux/irq.h>
28 #include <linux/delay.h>
29 #include <asm/byteorder.h>
31 #include <linux/time.h>
32 #include <linux/mii.h>
34 #include <linux/if_vlan.h>
35 #include <linux/rtc.h>
39 #include <net/checksum.h>
40 #include <net/ip6_checksum.h>
41 #include <net/udp_tunnel.h>
42 #include <linux/workqueue.h>
43 #include <linux/prefetch.h>
44 #include <linux/cache.h>
45 #include <linux/log2.h>
46 #include <linux/aer.h>
47 #include <linux/bitmap.h>
48 #include <linux/cpu_rmap.h>
53 #include "bnxt_sriov.h"
54 #include "bnxt_ethtool.h"
57 #define BNXT_TX_TIMEOUT (5 * HZ)
59 static const char version[] =
60 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
62 MODULE_LICENSE("GPL");
63 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
64 MODULE_VERSION(DRV_MODULE_VERSION);
66 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
67 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
68 #define BNXT_RX_COPY_THRESH 256
70 #define BNXT_TX_PUSH_THRESH 164
103 /* indexed by enum above */
104 static const struct {
107 { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
108 { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
109 { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
110 { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
111 { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
112 { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
113 { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
114 { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
115 { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
116 { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
117 { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
118 { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
119 { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
120 { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
121 { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
122 { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
123 { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
124 { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
125 { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
126 { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
127 { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
128 { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
129 { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
130 { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
131 { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
132 { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
133 { "Broadcom NetXtreme-E Ethernet Virtual Function" },
134 { "Broadcom NetXtreme-C Ethernet Virtual Function" },
137 static const struct pci_device_id bnxt_pci_tbl[] = {
138 { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
139 { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
140 { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
141 { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
142 { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
143 { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
144 { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
145 { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
146 { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
147 { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
148 { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
149 { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
150 { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
151 { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
152 { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
153 { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
154 { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
155 { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
156 { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
157 { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
158 { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
159 { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
160 { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
161 { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
162 { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
163 { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
164 { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
165 { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
166 { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
167 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
168 #ifdef CONFIG_BNXT_SRIOV
169 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
170 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
171 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
172 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
173 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
174 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
179 MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
181 static const u16 bnxt_vf_req_snif[] = {
184 HWRM_CFA_L2_FILTER_ALLOC,
187 static const u16 bnxt_async_events_arr[] = {
188 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
189 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
190 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
191 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
192 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
195 static bool bnxt_vf_pciid(enum board_idx idx)
197 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF);
200 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
201 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
202 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
204 #define BNXT_CP_DB_REARM(db, raw_cons) \
205 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
207 #define BNXT_CP_DB(db, raw_cons) \
208 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
210 #define BNXT_CP_DB_IRQ_DIS(db) \
211 writel(DB_CP_IRQ_DIS_FLAGS, db)
213 static inline u32 bnxt_tx_avail(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
215 /* Tell compiler to fetch tx indices from memory. */
218 return bp->tx_ring_size -
219 ((txr->tx_prod - txr->tx_cons) & bp->tx_ring_mask);
222 static const u16 bnxt_lhint_arr[] = {
223 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
224 TX_BD_FLAGS_LHINT_512_TO_1023,
225 TX_BD_FLAGS_LHINT_1024_TO_2047,
226 TX_BD_FLAGS_LHINT_1024_TO_2047,
227 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
228 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
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,
244 static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
246 struct bnxt *bp = netdev_priv(dev);
248 struct tx_bd_ext *txbd1;
249 struct netdev_queue *txq;
252 unsigned int length, pad = 0;
253 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
255 struct pci_dev *pdev = bp->pdev;
256 struct bnxt_tx_ring_info *txr;
257 struct bnxt_sw_tx_bd *tx_buf;
259 i = skb_get_queue_mapping(skb);
260 if (unlikely(i >= bp->tx_nr_rings)) {
261 dev_kfree_skb_any(skb);
265 txq = netdev_get_tx_queue(dev, i);
266 txr = &bp->tx_ring[bp->tx_ring_map[i]];
269 free_size = bnxt_tx_avail(bp, txr);
270 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
271 netif_tx_stop_queue(txq);
272 return NETDEV_TX_BUSY;
276 len = skb_headlen(skb);
277 last_frag = skb_shinfo(skb)->nr_frags;
279 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
281 txbd->tx_bd_opaque = prod;
283 tx_buf = &txr->tx_buf_ring[prod];
285 tx_buf->nr_frags = last_frag;
289 if (skb_vlan_tag_present(skb)) {
290 vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
291 skb_vlan_tag_get(skb);
292 /* Currently supports 8021Q, 8021AD vlan offloads
293 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
295 if (skb->vlan_proto == htons(ETH_P_8021Q))
296 vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
299 if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
300 struct tx_push_buffer *tx_push_buf = txr->tx_push;
301 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
302 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
303 void *pdata = tx_push_buf->data;
307 /* Set COAL_NOW to be ready quickly for the next push */
308 tx_push->tx_bd_len_flags_type =
309 cpu_to_le32((length << TX_BD_LEN_SHIFT) |
310 TX_BD_TYPE_LONG_TX_BD |
311 TX_BD_FLAGS_LHINT_512_AND_SMALLER |
312 TX_BD_FLAGS_COAL_NOW |
313 TX_BD_FLAGS_PACKET_END |
314 (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
316 if (skb->ip_summed == CHECKSUM_PARTIAL)
317 tx_push1->tx_bd_hsize_lflags =
318 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
320 tx_push1->tx_bd_hsize_lflags = 0;
322 tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
323 tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
325 end = pdata + length;
326 end = PTR_ALIGN(end, 8) - 1;
329 skb_copy_from_linear_data(skb, pdata, len);
331 for (j = 0; j < last_frag; j++) {
332 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
335 fptr = skb_frag_address_safe(frag);
339 memcpy(pdata, fptr, skb_frag_size(frag));
340 pdata += skb_frag_size(frag);
343 txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
344 txbd->tx_bd_haddr = txr->data_mapping;
345 prod = NEXT_TX(prod);
346 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
347 memcpy(txbd, tx_push1, sizeof(*txbd));
348 prod = NEXT_TX(prod);
350 cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
354 netdev_tx_sent_queue(txq, skb->len);
355 wmb(); /* Sync is_push and byte queue before pushing data */
357 push_len = (length + sizeof(*tx_push) + 7) / 8;
359 __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
360 __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
361 (push_len - 16) << 1);
363 __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
371 if (length < BNXT_MIN_PKT_SIZE) {
372 pad = BNXT_MIN_PKT_SIZE - length;
373 if (skb_pad(skb, pad)) {
374 /* SKB already freed. */
378 length = BNXT_MIN_PKT_SIZE;
381 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
383 if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
384 dev_kfree_skb_any(skb);
389 dma_unmap_addr_set(tx_buf, mapping, mapping);
390 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
391 ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
393 txbd->tx_bd_haddr = cpu_to_le64(mapping);
395 prod = NEXT_TX(prod);
396 txbd1 = (struct tx_bd_ext *)
397 &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
399 txbd1->tx_bd_hsize_lflags = 0;
400 if (skb_is_gso(skb)) {
403 if (skb->encapsulation)
404 hdr_len = skb_inner_network_offset(skb) +
405 skb_inner_network_header_len(skb) +
406 inner_tcp_hdrlen(skb);
408 hdr_len = skb_transport_offset(skb) +
411 txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
413 (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
414 length = skb_shinfo(skb)->gso_size;
415 txbd1->tx_bd_mss = cpu_to_le32(length);
417 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
418 txbd1->tx_bd_hsize_lflags =
419 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
420 txbd1->tx_bd_mss = 0;
424 flags |= bnxt_lhint_arr[length];
425 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
427 txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
428 txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
429 for (i = 0; i < last_frag; i++) {
430 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
432 prod = NEXT_TX(prod);
433 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
435 len = skb_frag_size(frag);
436 mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
439 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
442 tx_buf = &txr->tx_buf_ring[prod];
443 dma_unmap_addr_set(tx_buf, mapping, mapping);
445 txbd->tx_bd_haddr = cpu_to_le64(mapping);
447 flags = len << TX_BD_LEN_SHIFT;
448 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
452 txbd->tx_bd_len_flags_type =
453 cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
454 TX_BD_FLAGS_PACKET_END);
456 netdev_tx_sent_queue(txq, skb->len);
458 /* Sync BD data before updating doorbell */
461 prod = NEXT_TX(prod);
464 writel(DB_KEY_TX | prod, txr->tx_doorbell);
465 writel(DB_KEY_TX | prod, txr->tx_doorbell);
471 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
472 netif_tx_stop_queue(txq);
474 /* netif_tx_stop_queue() must be done before checking
475 * tx index in bnxt_tx_avail() below, because in
476 * bnxt_tx_int(), we update tx index before checking for
477 * netif_tx_queue_stopped().
480 if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
481 netif_tx_wake_queue(txq);
488 /* start back at beginning and unmap skb */
490 tx_buf = &txr->tx_buf_ring[prod];
492 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
493 skb_headlen(skb), PCI_DMA_TODEVICE);
494 prod = NEXT_TX(prod);
496 /* unmap remaining mapped pages */
497 for (i = 0; i < last_frag; i++) {
498 prod = NEXT_TX(prod);
499 tx_buf = &txr->tx_buf_ring[prod];
500 dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
501 skb_frag_size(&skb_shinfo(skb)->frags[i]),
505 dev_kfree_skb_any(skb);
509 static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
511 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
512 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
513 u16 cons = txr->tx_cons;
514 struct pci_dev *pdev = bp->pdev;
516 unsigned int tx_bytes = 0;
518 for (i = 0; i < nr_pkts; i++) {
519 struct bnxt_sw_tx_bd *tx_buf;
523 tx_buf = &txr->tx_buf_ring[cons];
524 cons = NEXT_TX(cons);
528 if (tx_buf->is_push) {
533 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
534 skb_headlen(skb), PCI_DMA_TODEVICE);
535 last = tx_buf->nr_frags;
537 for (j = 0; j < last; j++) {
538 cons = NEXT_TX(cons);
539 tx_buf = &txr->tx_buf_ring[cons];
542 dma_unmap_addr(tx_buf, mapping),
543 skb_frag_size(&skb_shinfo(skb)->frags[j]),
548 cons = NEXT_TX(cons);
550 tx_bytes += skb->len;
551 dev_kfree_skb_any(skb);
554 netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
557 /* Need to make the tx_cons update visible to bnxt_start_xmit()
558 * before checking for netif_tx_queue_stopped(). Without the
559 * memory barrier, there is a small possibility that bnxt_start_xmit()
560 * will miss it and cause the queue to be stopped forever.
564 if (unlikely(netif_tx_queue_stopped(txq)) &&
565 (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
566 __netif_tx_lock(txq, smp_processor_id());
567 if (netif_tx_queue_stopped(txq) &&
568 bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
569 txr->dev_state != BNXT_DEV_STATE_CLOSING)
570 netif_tx_wake_queue(txq);
571 __netif_tx_unlock(txq);
575 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
578 struct device *dev = &bp->pdev->dev;
581 page = alloc_page(gfp);
585 *mapping = dma_map_page(dev, page, 0, PAGE_SIZE, bp->rx_dir);
586 if (dma_mapping_error(dev, *mapping)) {
590 *mapping += bp->rx_dma_offset;
594 static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
598 struct pci_dev *pdev = bp->pdev;
600 data = kmalloc(bp->rx_buf_size, gfp);
604 *mapping = dma_map_single(&pdev->dev, data + bp->rx_dma_offset,
605 bp->rx_buf_use_size, bp->rx_dir);
607 if (dma_mapping_error(&pdev->dev, *mapping)) {
614 static inline int bnxt_alloc_rx_data(struct bnxt *bp,
615 struct bnxt_rx_ring_info *rxr,
618 struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
619 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
622 if (BNXT_RX_PAGE_MODE(bp)) {
623 struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
629 rx_buf->data_ptr = page_address(page) + bp->rx_offset;
631 u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
637 rx_buf->data_ptr = data + bp->rx_offset;
639 rx_buf->mapping = mapping;
641 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
645 static void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons,
648 u16 prod = rxr->rx_prod;
649 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
650 struct rx_bd *cons_bd, *prod_bd;
652 prod_rx_buf = &rxr->rx_buf_ring[prod];
653 cons_rx_buf = &rxr->rx_buf_ring[cons];
655 prod_rx_buf->data = data;
656 prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
658 prod_rx_buf->mapping = cons_rx_buf->mapping;
660 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
661 cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
663 prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
666 static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
668 u16 next, max = rxr->rx_agg_bmap_size;
670 next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
672 next = find_first_zero_bit(rxr->rx_agg_bmap, max);
676 static inline int bnxt_alloc_rx_page(struct bnxt *bp,
677 struct bnxt_rx_ring_info *rxr,
681 &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
682 struct bnxt_sw_rx_agg_bd *rx_agg_buf;
683 struct pci_dev *pdev = bp->pdev;
686 u16 sw_prod = rxr->rx_sw_agg_prod;
687 unsigned int offset = 0;
689 if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
692 page = alloc_page(gfp);
696 rxr->rx_page_offset = 0;
698 offset = rxr->rx_page_offset;
699 rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
700 if (rxr->rx_page_offset == PAGE_SIZE)
705 page = alloc_page(gfp);
710 mapping = dma_map_page(&pdev->dev, page, offset, BNXT_RX_PAGE_SIZE,
712 if (dma_mapping_error(&pdev->dev, mapping)) {
717 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
718 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
720 __set_bit(sw_prod, rxr->rx_agg_bmap);
721 rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
722 rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
724 rx_agg_buf->page = page;
725 rx_agg_buf->offset = offset;
726 rx_agg_buf->mapping = mapping;
727 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
728 rxbd->rx_bd_opaque = sw_prod;
732 static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
735 struct bnxt *bp = bnapi->bp;
736 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
737 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
738 u16 prod = rxr->rx_agg_prod;
739 u16 sw_prod = rxr->rx_sw_agg_prod;
742 for (i = 0; i < agg_bufs; i++) {
744 struct rx_agg_cmp *agg;
745 struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
746 struct rx_bd *prod_bd;
749 agg = (struct rx_agg_cmp *)
750 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
751 cons = agg->rx_agg_cmp_opaque;
752 __clear_bit(cons, rxr->rx_agg_bmap);
754 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
755 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
757 __set_bit(sw_prod, rxr->rx_agg_bmap);
758 prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
759 cons_rx_buf = &rxr->rx_agg_ring[cons];
761 /* It is possible for sw_prod to be equal to cons, so
762 * set cons_rx_buf->page to NULL first.
764 page = cons_rx_buf->page;
765 cons_rx_buf->page = NULL;
766 prod_rx_buf->page = page;
767 prod_rx_buf->offset = cons_rx_buf->offset;
769 prod_rx_buf->mapping = cons_rx_buf->mapping;
771 prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
773 prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
774 prod_bd->rx_bd_opaque = sw_prod;
776 prod = NEXT_RX_AGG(prod);
777 sw_prod = NEXT_RX_AGG(sw_prod);
778 cp_cons = NEXT_CMP(cp_cons);
780 rxr->rx_agg_prod = prod;
781 rxr->rx_sw_agg_prod = sw_prod;
784 static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
785 struct bnxt_rx_ring_info *rxr,
786 u16 cons, void *data, u8 *data_ptr,
788 unsigned int offset_and_len)
790 unsigned int payload = offset_and_len >> 16;
791 unsigned int len = offset_and_len & 0xffff;
792 struct skb_frag_struct *frag;
793 struct page *page = data;
794 u16 prod = rxr->rx_prod;
798 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
800 bnxt_reuse_rx_data(rxr, cons, data);
803 dma_addr -= bp->rx_dma_offset;
804 dma_unmap_page(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir);
806 if (unlikely(!payload))
807 payload = eth_get_headlen(data_ptr, len);
809 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
815 off = (void *)data_ptr - page_address(page);
816 skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
817 memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
818 payload + NET_IP_ALIGN);
820 frag = &skb_shinfo(skb)->frags[0];
821 skb_frag_size_sub(frag, payload);
822 frag->page_offset += payload;
823 skb->data_len -= payload;
824 skb->tail += payload;
829 static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
830 struct bnxt_rx_ring_info *rxr, u16 cons,
831 void *data, u8 *data_ptr,
833 unsigned int offset_and_len)
835 u16 prod = rxr->rx_prod;
839 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
841 bnxt_reuse_rx_data(rxr, cons, data);
845 skb = build_skb(data, 0);
846 dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
853 skb_reserve(skb, bp->rx_offset);
854 skb_put(skb, offset_and_len & 0xffff);
858 static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
859 struct sk_buff *skb, u16 cp_cons,
862 struct pci_dev *pdev = bp->pdev;
863 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
864 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
865 u16 prod = rxr->rx_agg_prod;
868 for (i = 0; i < agg_bufs; i++) {
870 struct rx_agg_cmp *agg;
871 struct bnxt_sw_rx_agg_bd *cons_rx_buf;
875 agg = (struct rx_agg_cmp *)
876 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
877 cons = agg->rx_agg_cmp_opaque;
878 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
879 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
881 cons_rx_buf = &rxr->rx_agg_ring[cons];
882 skb_fill_page_desc(skb, i, cons_rx_buf->page,
883 cons_rx_buf->offset, frag_len);
884 __clear_bit(cons, rxr->rx_agg_bmap);
886 /* It is possible for bnxt_alloc_rx_page() to allocate
887 * a sw_prod index that equals the cons index, so we
888 * need to clear the cons entry now.
890 mapping = cons_rx_buf->mapping;
891 page = cons_rx_buf->page;
892 cons_rx_buf->page = NULL;
894 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
895 struct skb_shared_info *shinfo;
896 unsigned int nr_frags;
898 shinfo = skb_shinfo(skb);
899 nr_frags = --shinfo->nr_frags;
900 __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
904 cons_rx_buf->page = page;
906 /* Update prod since possibly some pages have been
909 rxr->rx_agg_prod = prod;
910 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
914 dma_unmap_page(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
917 skb->data_len += frag_len;
918 skb->len += frag_len;
919 skb->truesize += PAGE_SIZE;
921 prod = NEXT_RX_AGG(prod);
922 cp_cons = NEXT_CMP(cp_cons);
924 rxr->rx_agg_prod = prod;
928 static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
929 u8 agg_bufs, u32 *raw_cons)
932 struct rx_agg_cmp *agg;
934 *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
935 last = RING_CMP(*raw_cons);
936 agg = (struct rx_agg_cmp *)
937 &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
938 return RX_AGG_CMP_VALID(agg, *raw_cons);
941 static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
945 struct bnxt *bp = bnapi->bp;
946 struct pci_dev *pdev = bp->pdev;
949 skb = napi_alloc_skb(&bnapi->napi, len);
953 dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
956 memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
959 dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
966 static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
967 u32 *raw_cons, void *cmp)
969 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
970 struct rx_cmp *rxcmp = cmp;
971 u32 tmp_raw_cons = *raw_cons;
972 u8 cmp_type, agg_bufs = 0;
974 cmp_type = RX_CMP_TYPE(rxcmp);
976 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
977 agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
979 RX_CMP_AGG_BUFS_SHIFT;
980 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
981 struct rx_tpa_end_cmp *tpa_end = cmp;
983 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
984 RX_TPA_END_CMP_AGG_BUFS) >>
985 RX_TPA_END_CMP_AGG_BUFS_SHIFT;
989 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
992 *raw_cons = tmp_raw_cons;
996 static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
998 if (!rxr->bnapi->in_reset) {
999 rxr->bnapi->in_reset = true;
1000 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
1001 schedule_work(&bp->sp_task);
1003 rxr->rx_next_cons = 0xffff;
1006 static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1007 struct rx_tpa_start_cmp *tpa_start,
1008 struct rx_tpa_start_cmp_ext *tpa_start1)
1010 u8 agg_id = TPA_START_AGG_ID(tpa_start);
1012 struct bnxt_tpa_info *tpa_info;
1013 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1014 struct rx_bd *prod_bd;
1017 cons = tpa_start->rx_tpa_start_cmp_opaque;
1018 prod = rxr->rx_prod;
1019 cons_rx_buf = &rxr->rx_buf_ring[cons];
1020 prod_rx_buf = &rxr->rx_buf_ring[prod];
1021 tpa_info = &rxr->rx_tpa[agg_id];
1023 if (unlikely(cons != rxr->rx_next_cons)) {
1024 bnxt_sched_reset(bp, rxr);
1028 prod_rx_buf->data = tpa_info->data;
1029 prod_rx_buf->data_ptr = tpa_info->data_ptr;
1031 mapping = tpa_info->mapping;
1032 prod_rx_buf->mapping = mapping;
1034 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1036 prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
1038 tpa_info->data = cons_rx_buf->data;
1039 tpa_info->data_ptr = cons_rx_buf->data_ptr;
1040 cons_rx_buf->data = NULL;
1041 tpa_info->mapping = cons_rx_buf->mapping;
1044 le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
1045 RX_TPA_START_CMP_LEN_SHIFT;
1046 if (likely(TPA_START_HASH_VALID(tpa_start))) {
1047 u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
1049 tpa_info->hash_type = PKT_HASH_TYPE_L4;
1050 tpa_info->gso_type = SKB_GSO_TCPV4;
1051 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1053 tpa_info->gso_type = SKB_GSO_TCPV6;
1054 tpa_info->rss_hash =
1055 le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
1057 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
1058 tpa_info->gso_type = 0;
1059 if (netif_msg_rx_err(bp))
1060 netdev_warn(bp->dev, "TPA packet without valid hash\n");
1062 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
1063 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
1064 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
1066 rxr->rx_prod = NEXT_RX(prod);
1067 cons = NEXT_RX(cons);
1068 rxr->rx_next_cons = NEXT_RX(cons);
1069 cons_rx_buf = &rxr->rx_buf_ring[cons];
1071 bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
1072 rxr->rx_prod = NEXT_RX(rxr->rx_prod);
1073 cons_rx_buf->data = NULL;
1076 static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1077 u16 cp_cons, u32 agg_bufs)
1080 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1083 static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
1084 int payload_off, int tcp_ts,
1085 struct sk_buff *skb)
1090 u16 outer_ip_off, inner_ip_off, inner_mac_off;
1091 u32 hdr_info = tpa_info->hdr_info;
1092 bool loopback = false;
1094 inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1095 inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1096 outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1098 /* If the packet is an internal loopback packet, the offsets will
1099 * have an extra 4 bytes.
1101 if (inner_mac_off == 4) {
1103 } else if (inner_mac_off > 4) {
1104 __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
1107 /* We only support inner iPv4/ipv6. If we don't see the
1108 * correct protocol ID, it must be a loopback packet where
1109 * the offsets are off by 4.
1111 if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
1115 /* internal loopback packet, subtract all offsets by 4 */
1121 nw_off = inner_ip_off - ETH_HLEN;
1122 skb_set_network_header(skb, nw_off);
1123 if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
1124 struct ipv6hdr *iph = ipv6_hdr(skb);
1126 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1127 len = skb->len - skb_transport_offset(skb);
1129 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1131 struct iphdr *iph = ip_hdr(skb);
1133 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1134 len = skb->len - skb_transport_offset(skb);
1136 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1139 if (inner_mac_off) { /* tunnel */
1140 struct udphdr *uh = NULL;
1141 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1144 if (proto == htons(ETH_P_IP)) {
1145 struct iphdr *iph = (struct iphdr *)skb->data;
1147 if (iph->protocol == IPPROTO_UDP)
1148 uh = (struct udphdr *)(iph + 1);
1150 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1152 if (iph->nexthdr == IPPROTO_UDP)
1153 uh = (struct udphdr *)(iph + 1);
1157 skb_shinfo(skb)->gso_type |=
1158 SKB_GSO_UDP_TUNNEL_CSUM;
1160 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1167 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1168 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1170 static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
1171 int payload_off, int tcp_ts,
1172 struct sk_buff *skb)
1176 int len, nw_off, tcp_opt_len = 0;
1181 if (tpa_info->gso_type == SKB_GSO_TCPV4) {
1184 nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
1186 skb_set_network_header(skb, nw_off);
1188 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1189 len = skb->len - skb_transport_offset(skb);
1191 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1192 } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
1193 struct ipv6hdr *iph;
1195 nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
1197 skb_set_network_header(skb, nw_off);
1198 iph = ipv6_hdr(skb);
1199 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1200 len = skb->len - skb_transport_offset(skb);
1202 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1204 dev_kfree_skb_any(skb);
1208 if (nw_off) { /* tunnel */
1209 struct udphdr *uh = NULL;
1211 if (skb->protocol == htons(ETH_P_IP)) {
1212 struct iphdr *iph = (struct iphdr *)skb->data;
1214 if (iph->protocol == IPPROTO_UDP)
1215 uh = (struct udphdr *)(iph + 1);
1217 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1219 if (iph->nexthdr == IPPROTO_UDP)
1220 uh = (struct udphdr *)(iph + 1);
1224 skb_shinfo(skb)->gso_type |=
1225 SKB_GSO_UDP_TUNNEL_CSUM;
1227 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1234 static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
1235 struct bnxt_tpa_info *tpa_info,
1236 struct rx_tpa_end_cmp *tpa_end,
1237 struct rx_tpa_end_cmp_ext *tpa_end1,
1238 struct sk_buff *skb)
1244 segs = TPA_END_TPA_SEGS(tpa_end);
1248 NAPI_GRO_CB(skb)->count = segs;
1249 skb_shinfo(skb)->gso_size =
1250 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
1251 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1252 payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1253 RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1254 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1255 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
1257 tcp_gro_complete(skb);
1262 static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1263 struct bnxt_napi *bnapi,
1265 struct rx_tpa_end_cmp *tpa_end,
1266 struct rx_tpa_end_cmp_ext *tpa_end1,
1269 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1270 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1271 u8 agg_id = TPA_END_AGG_ID(tpa_end);
1272 u8 *data_ptr, agg_bufs;
1273 u16 cp_cons = RING_CMP(*raw_cons);
1275 struct bnxt_tpa_info *tpa_info;
1277 struct sk_buff *skb;
1280 if (unlikely(bnapi->in_reset)) {
1281 int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1284 return ERR_PTR(-EBUSY);
1288 tpa_info = &rxr->rx_tpa[agg_id];
1289 data = tpa_info->data;
1290 data_ptr = tpa_info->data_ptr;
1292 len = tpa_info->len;
1293 mapping = tpa_info->mapping;
1295 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1296 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1299 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1300 return ERR_PTR(-EBUSY);
1302 *event |= BNXT_AGG_EVENT;
1303 cp_cons = NEXT_CMP(cp_cons);
1306 if (unlikely(agg_bufs > MAX_SKB_FRAGS)) {
1307 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1308 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1309 agg_bufs, (int)MAX_SKB_FRAGS);
1313 if (len <= bp->rx_copy_thresh) {
1314 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
1316 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1321 dma_addr_t new_mapping;
1323 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
1325 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1329 tpa_info->data = new_data;
1330 tpa_info->data_ptr = new_data + bp->rx_offset;
1331 tpa_info->mapping = new_mapping;
1333 skb = build_skb(data, 0);
1334 dma_unmap_single(&bp->pdev->dev, mapping, bp->rx_buf_use_size,
1339 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1342 skb_reserve(skb, bp->rx_offset);
1347 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1349 /* Page reuse already handled by bnxt_rx_pages(). */
1353 skb->protocol = eth_type_trans(skb, bp->dev);
1355 if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
1356 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
1358 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1359 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1360 u16 vlan_proto = tpa_info->metadata >>
1361 RX_CMP_FLAGS2_METADATA_TPID_SFT;
1362 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK;
1364 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1367 skb_checksum_none_assert(skb);
1368 if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
1369 skb->ip_summed = CHECKSUM_UNNECESSARY;
1371 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
1374 if (TPA_END_GRO(tpa_end))
1375 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
1380 /* returns the following:
1381 * 1 - 1 packet successfully received
1382 * 0 - successful TPA_START, packet not completed yet
1383 * -EBUSY - completion ring does not have all the agg buffers yet
1384 * -ENOMEM - packet aborted due to out of memory
1385 * -EIO - packet aborted due to hw error indicated in BD
1387 static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
1390 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1391 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1392 struct net_device *dev = bp->dev;
1393 struct rx_cmp *rxcmp;
1394 struct rx_cmp_ext *rxcmp1;
1395 u32 tmp_raw_cons = *raw_cons;
1396 u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
1397 struct bnxt_sw_rx_bd *rx_buf;
1399 u8 *data_ptr, agg_bufs, cmp_type;
1400 dma_addr_t dma_addr;
1401 struct sk_buff *skb;
1406 rxcmp = (struct rx_cmp *)
1407 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1409 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1410 cp_cons = RING_CMP(tmp_raw_cons);
1411 rxcmp1 = (struct rx_cmp_ext *)
1412 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1414 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1417 cmp_type = RX_CMP_TYPE(rxcmp);
1419 prod = rxr->rx_prod;
1421 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
1422 bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
1423 (struct rx_tpa_start_cmp_ext *)rxcmp1);
1425 *event |= BNXT_RX_EVENT;
1426 goto next_rx_no_prod;
1428 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1429 skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1430 (struct rx_tpa_end_cmp *)rxcmp,
1431 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
1433 if (unlikely(IS_ERR(skb)))
1438 skb_record_rx_queue(skb, bnapi->index);
1439 napi_gro_receive(&bnapi->napi, skb);
1442 *event |= BNXT_RX_EVENT;
1443 goto next_rx_no_prod;
1446 cons = rxcmp->rx_cmp_opaque;
1447 rx_buf = &rxr->rx_buf_ring[cons];
1448 data = rx_buf->data;
1449 data_ptr = rx_buf->data_ptr;
1450 if (unlikely(cons != rxr->rx_next_cons)) {
1451 int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1453 bnxt_sched_reset(bp, rxr);
1458 misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
1459 agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
1462 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1465 cp_cons = NEXT_CMP(cp_cons);
1466 *event |= BNXT_AGG_EVENT;
1468 *event |= BNXT_RX_EVENT;
1470 rx_buf->data = NULL;
1471 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
1472 bnxt_reuse_rx_data(rxr, cons, data);
1474 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1480 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
1481 dma_addr = rx_buf->mapping;
1483 if (len <= bp->rx_copy_thresh) {
1484 skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
1485 bnxt_reuse_rx_data(rxr, cons, data);
1493 payload = misc & RX_CMP_PAYLOAD_OFFSET;
1494 skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
1503 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1510 if (RX_CMP_HASH_VALID(rxcmp)) {
1511 u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
1512 enum pkt_hash_types type = PKT_HASH_TYPE_L4;
1514 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1515 if (hash_type != 1 && hash_type != 3)
1516 type = PKT_HASH_TYPE_L3;
1517 skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
1520 skb->protocol = eth_type_trans(skb, dev);
1522 if ((rxcmp1->rx_cmp_flags2 &
1523 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1524 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1525 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
1526 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK;
1527 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1529 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1532 skb_checksum_none_assert(skb);
1533 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1534 if (dev->features & NETIF_F_RXCSUM) {
1535 skb->ip_summed = CHECKSUM_UNNECESSARY;
1536 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1539 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1540 if (dev->features & NETIF_F_RXCSUM)
1541 cpr->rx_l4_csum_errors++;
1545 skb_record_rx_queue(skb, bnapi->index);
1546 napi_gro_receive(&bnapi->napi, skb);
1550 rxr->rx_prod = NEXT_RX(prod);
1551 rxr->rx_next_cons = NEXT_RX(cons);
1554 *raw_cons = tmp_raw_cons;
1559 #define BNXT_GET_EVENT_PORT(data) \
1561 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
1563 static int bnxt_async_event_process(struct bnxt *bp,
1564 struct hwrm_async_event_cmpl *cmpl)
1566 u16 event_id = le16_to_cpu(cmpl->event_id);
1568 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1570 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
1571 u32 data1 = le32_to_cpu(cmpl->event_data1);
1572 struct bnxt_link_info *link_info = &bp->link_info;
1575 goto async_event_process_exit;
1576 if (data1 & 0x20000) {
1577 u16 fw_speed = link_info->force_link_speed;
1578 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1580 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1583 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
1586 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
1587 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
1589 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
1590 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
1592 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
1593 u32 data1 = le32_to_cpu(cmpl->event_data1);
1594 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1599 if (bp->pf.port_id != port_id)
1602 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1605 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
1607 goto async_event_process_exit;
1608 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1611 goto async_event_process_exit;
1613 schedule_work(&bp->sp_task);
1614 async_event_process_exit:
1615 bnxt_ulp_async_events(bp, cmpl);
1619 static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1621 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1622 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1623 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1624 (struct hwrm_fwd_req_cmpl *)txcmp;
1626 switch (cmpl_type) {
1627 case CMPL_BASE_TYPE_HWRM_DONE:
1628 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1629 if (seq_id == bp->hwrm_intr_seq_id)
1630 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1632 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1635 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1636 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1638 if ((vf_id < bp->pf.first_vf_id) ||
1639 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1640 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1645 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1646 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
1647 schedule_work(&bp->sp_task);
1650 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1651 bnxt_async_event_process(bp,
1652 (struct hwrm_async_event_cmpl *)txcmp);
1661 static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1663 struct bnxt_napi *bnapi = dev_instance;
1664 struct bnxt *bp = bnapi->bp;
1665 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1666 u32 cons = RING_CMP(cpr->cp_raw_cons);
1668 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1669 napi_schedule(&bnapi->napi);
1673 static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1675 u32 raw_cons = cpr->cp_raw_cons;
1676 u16 cons = RING_CMP(raw_cons);
1677 struct tx_cmp *txcmp;
1679 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1681 return TX_CMP_VALID(txcmp, raw_cons);
1684 static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1686 struct bnxt_napi *bnapi = dev_instance;
1687 struct bnxt *bp = bnapi->bp;
1688 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1689 u32 cons = RING_CMP(cpr->cp_raw_cons);
1692 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1694 if (!bnxt_has_work(bp, cpr)) {
1695 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
1696 /* return if erroneous interrupt */
1697 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1701 /* disable ring IRQ */
1702 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1704 /* Return here if interrupt is shared and is disabled. */
1705 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1708 napi_schedule(&bnapi->napi);
1712 static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1714 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1715 u32 raw_cons = cpr->cp_raw_cons;
1720 struct tx_cmp *txcmp;
1725 cons = RING_CMP(raw_cons);
1726 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1728 if (!TX_CMP_VALID(txcmp, raw_cons))
1731 /* The valid test of the entry must be done first before
1732 * reading any further.
1735 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1737 /* return full budget so NAPI will complete. */
1738 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1740 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1741 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1742 if (likely(rc >= 0))
1744 else if (rc == -EBUSY) /* partial completion */
1746 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1747 CMPL_BASE_TYPE_HWRM_DONE) ||
1748 (TX_CMP_TYPE(txcmp) ==
1749 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1750 (TX_CMP_TYPE(txcmp) ==
1751 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1752 bnxt_hwrm_handler(bp, txcmp);
1754 raw_cons = NEXT_RAW_CMP(raw_cons);
1756 if (rx_pkts == budget)
1760 cpr->cp_raw_cons = raw_cons;
1761 /* ACK completion ring before freeing tx ring and producing new
1762 * buffers in rx/agg rings to prevent overflowing the completion
1765 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1768 bnxt_tx_int(bp, bnapi, tx_pkts);
1770 if (event & BNXT_RX_EVENT) {
1771 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1773 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1774 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1775 if (event & BNXT_AGG_EVENT) {
1776 writel(DB_KEY_RX | rxr->rx_agg_prod,
1777 rxr->rx_agg_doorbell);
1778 writel(DB_KEY_RX | rxr->rx_agg_prod,
1779 rxr->rx_agg_doorbell);
1785 static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1787 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1788 struct bnxt *bp = bnapi->bp;
1789 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1790 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1791 struct tx_cmp *txcmp;
1792 struct rx_cmp_ext *rxcmp1;
1793 u32 cp_cons, tmp_raw_cons;
1794 u32 raw_cons = cpr->cp_raw_cons;
1801 cp_cons = RING_CMP(raw_cons);
1802 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1804 if (!TX_CMP_VALID(txcmp, raw_cons))
1807 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1808 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1809 cp_cons = RING_CMP(tmp_raw_cons);
1810 rxcmp1 = (struct rx_cmp_ext *)
1811 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1813 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1816 /* force an error to recycle the buffer */
1817 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1818 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1820 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1821 if (likely(rc == -EIO))
1823 else if (rc == -EBUSY) /* partial completion */
1825 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1826 CMPL_BASE_TYPE_HWRM_DONE)) {
1827 bnxt_hwrm_handler(bp, txcmp);
1830 "Invalid completion received on special ring\n");
1832 raw_cons = NEXT_RAW_CMP(raw_cons);
1834 if (rx_pkts == budget)
1838 cpr->cp_raw_cons = raw_cons;
1839 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1840 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1841 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1843 if (event & BNXT_AGG_EVENT) {
1844 writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
1845 writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
1848 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
1849 napi_complete_done(napi, rx_pkts);
1850 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
1855 static int bnxt_poll(struct napi_struct *napi, int budget)
1857 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1858 struct bnxt *bp = bnapi->bp;
1859 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1863 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
1865 if (work_done >= budget)
1868 if (!bnxt_has_work(bp, cpr)) {
1869 if (napi_complete_done(napi, work_done))
1870 BNXT_CP_DB_REARM(cpr->cp_doorbell,
1879 static void bnxt_free_tx_skbs(struct bnxt *bp)
1882 struct pci_dev *pdev = bp->pdev;
1887 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
1888 for (i = 0; i < bp->tx_nr_rings; i++) {
1889 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
1892 for (j = 0; j < max_idx;) {
1893 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
1894 struct sk_buff *skb = tx_buf->skb;
1904 if (tx_buf->is_push) {
1910 dma_unmap_single(&pdev->dev,
1911 dma_unmap_addr(tx_buf, mapping),
1915 last = tx_buf->nr_frags;
1917 for (k = 0; k < last; k++, j++) {
1918 int ring_idx = j & bp->tx_ring_mask;
1919 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
1921 tx_buf = &txr->tx_buf_ring[ring_idx];
1924 dma_unmap_addr(tx_buf, mapping),
1925 skb_frag_size(frag), PCI_DMA_TODEVICE);
1929 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
1933 static void bnxt_free_rx_skbs(struct bnxt *bp)
1935 int i, max_idx, max_agg_idx;
1936 struct pci_dev *pdev = bp->pdev;
1941 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
1942 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
1943 for (i = 0; i < bp->rx_nr_rings; i++) {
1944 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
1948 for (j = 0; j < MAX_TPA; j++) {
1949 struct bnxt_tpa_info *tpa_info =
1951 u8 *data = tpa_info->data;
1956 dma_unmap_single(&pdev->dev, tpa_info->mapping,
1957 bp->rx_buf_use_size,
1960 tpa_info->data = NULL;
1966 for (j = 0; j < max_idx; j++) {
1967 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
1968 void *data = rx_buf->data;
1973 dma_unmap_single(&pdev->dev, rx_buf->mapping,
1974 bp->rx_buf_use_size, bp->rx_dir);
1976 rx_buf->data = NULL;
1978 if (BNXT_RX_PAGE_MODE(bp))
1984 for (j = 0; j < max_agg_idx; j++) {
1985 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
1986 &rxr->rx_agg_ring[j];
1987 struct page *page = rx_agg_buf->page;
1992 dma_unmap_page(&pdev->dev, rx_agg_buf->mapping,
1993 BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE);
1995 rx_agg_buf->page = NULL;
1996 __clear_bit(j, rxr->rx_agg_bmap);
2001 __free_page(rxr->rx_page);
2002 rxr->rx_page = NULL;
2007 static void bnxt_free_skbs(struct bnxt *bp)
2009 bnxt_free_tx_skbs(bp);
2010 bnxt_free_rx_skbs(bp);
2013 static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2015 struct pci_dev *pdev = bp->pdev;
2018 for (i = 0; i < ring->nr_pages; i++) {
2019 if (!ring->pg_arr[i])
2022 dma_free_coherent(&pdev->dev, ring->page_size,
2023 ring->pg_arr[i], ring->dma_arr[i]);
2025 ring->pg_arr[i] = NULL;
2028 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2029 ring->pg_tbl, ring->pg_tbl_map);
2030 ring->pg_tbl = NULL;
2032 if (ring->vmem_size && *ring->vmem) {
2038 static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2041 struct pci_dev *pdev = bp->pdev;
2043 if (ring->nr_pages > 1) {
2044 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2052 for (i = 0; i < ring->nr_pages; i++) {
2053 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2057 if (!ring->pg_arr[i])
2060 if (ring->nr_pages > 1)
2061 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2064 if (ring->vmem_size) {
2065 *ring->vmem = vzalloc(ring->vmem_size);
2072 static void bnxt_free_rx_rings(struct bnxt *bp)
2079 for (i = 0; i < bp->rx_nr_rings; i++) {
2080 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2081 struct bnxt_ring_struct *ring;
2086 kfree(rxr->rx_agg_bmap);
2087 rxr->rx_agg_bmap = NULL;
2089 ring = &rxr->rx_ring_struct;
2090 bnxt_free_ring(bp, ring);
2092 ring = &rxr->rx_agg_ring_struct;
2093 bnxt_free_ring(bp, ring);
2097 static int bnxt_alloc_rx_rings(struct bnxt *bp)
2099 int i, rc, agg_rings = 0, tpa_rings = 0;
2104 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2107 if (bp->flags & BNXT_FLAG_TPA)
2110 for (i = 0; i < bp->rx_nr_rings; i++) {
2111 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
2112 struct bnxt_ring_struct *ring;
2114 ring = &rxr->rx_ring_struct;
2116 rc = bnxt_alloc_ring(bp, ring);
2123 ring = &rxr->rx_agg_ring_struct;
2124 rc = bnxt_alloc_ring(bp, ring);
2128 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2129 mem_size = rxr->rx_agg_bmap_size / 8;
2130 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2131 if (!rxr->rx_agg_bmap)
2135 rxr->rx_tpa = kcalloc(MAX_TPA,
2136 sizeof(struct bnxt_tpa_info),
2146 static void bnxt_free_tx_rings(struct bnxt *bp)
2149 struct pci_dev *pdev = bp->pdev;
2154 for (i = 0; i < bp->tx_nr_rings; i++) {
2155 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2156 struct bnxt_ring_struct *ring;
2159 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2160 txr->tx_push, txr->tx_push_mapping);
2161 txr->tx_push = NULL;
2164 ring = &txr->tx_ring_struct;
2166 bnxt_free_ring(bp, ring);
2170 static int bnxt_alloc_tx_rings(struct bnxt *bp)
2173 struct pci_dev *pdev = bp->pdev;
2175 bp->tx_push_size = 0;
2176 if (bp->tx_push_thresh) {
2179 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2180 bp->tx_push_thresh);
2182 if (push_size > 256) {
2184 bp->tx_push_thresh = 0;
2187 bp->tx_push_size = push_size;
2190 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
2191 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2192 struct bnxt_ring_struct *ring;
2194 ring = &txr->tx_ring_struct;
2196 rc = bnxt_alloc_ring(bp, ring);
2200 if (bp->tx_push_size) {
2203 /* One pre-allocated DMA buffer to backup
2206 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2208 &txr->tx_push_mapping,
2214 mapping = txr->tx_push_mapping +
2215 sizeof(struct tx_push_bd);
2216 txr->data_mapping = cpu_to_le64(mapping);
2218 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
2220 ring->queue_id = bp->q_info[j].queue_id;
2221 if (i < bp->tx_nr_rings_xdp)
2223 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2229 static void bnxt_free_cp_rings(struct bnxt *bp)
2236 for (i = 0; i < bp->cp_nr_rings; i++) {
2237 struct bnxt_napi *bnapi = bp->bnapi[i];
2238 struct bnxt_cp_ring_info *cpr;
2239 struct bnxt_ring_struct *ring;
2244 cpr = &bnapi->cp_ring;
2245 ring = &cpr->cp_ring_struct;
2247 bnxt_free_ring(bp, ring);
2251 static int bnxt_alloc_cp_rings(struct bnxt *bp)
2255 for (i = 0; i < bp->cp_nr_rings; i++) {
2256 struct bnxt_napi *bnapi = bp->bnapi[i];
2257 struct bnxt_cp_ring_info *cpr;
2258 struct bnxt_ring_struct *ring;
2263 cpr = &bnapi->cp_ring;
2264 ring = &cpr->cp_ring_struct;
2266 rc = bnxt_alloc_ring(bp, ring);
2273 static void bnxt_init_ring_struct(struct bnxt *bp)
2277 for (i = 0; i < bp->cp_nr_rings; i++) {
2278 struct bnxt_napi *bnapi = bp->bnapi[i];
2279 struct bnxt_cp_ring_info *cpr;
2280 struct bnxt_rx_ring_info *rxr;
2281 struct bnxt_tx_ring_info *txr;
2282 struct bnxt_ring_struct *ring;
2287 cpr = &bnapi->cp_ring;
2288 ring = &cpr->cp_ring_struct;
2289 ring->nr_pages = bp->cp_nr_pages;
2290 ring->page_size = HW_CMPD_RING_SIZE;
2291 ring->pg_arr = (void **)cpr->cp_desc_ring;
2292 ring->dma_arr = cpr->cp_desc_mapping;
2293 ring->vmem_size = 0;
2295 rxr = bnapi->rx_ring;
2299 ring = &rxr->rx_ring_struct;
2300 ring->nr_pages = bp->rx_nr_pages;
2301 ring->page_size = HW_RXBD_RING_SIZE;
2302 ring->pg_arr = (void **)rxr->rx_desc_ring;
2303 ring->dma_arr = rxr->rx_desc_mapping;
2304 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2305 ring->vmem = (void **)&rxr->rx_buf_ring;
2307 ring = &rxr->rx_agg_ring_struct;
2308 ring->nr_pages = bp->rx_agg_nr_pages;
2309 ring->page_size = HW_RXBD_RING_SIZE;
2310 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2311 ring->dma_arr = rxr->rx_agg_desc_mapping;
2312 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2313 ring->vmem = (void **)&rxr->rx_agg_ring;
2316 txr = bnapi->tx_ring;
2320 ring = &txr->tx_ring_struct;
2321 ring->nr_pages = bp->tx_nr_pages;
2322 ring->page_size = HW_RXBD_RING_SIZE;
2323 ring->pg_arr = (void **)txr->tx_desc_ring;
2324 ring->dma_arr = txr->tx_desc_mapping;
2325 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2326 ring->vmem = (void **)&txr->tx_buf_ring;
2330 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2334 struct rx_bd **rx_buf_ring;
2336 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2337 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2341 rxbd = rx_buf_ring[i];
2345 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2346 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2347 rxbd->rx_bd_opaque = prod;
2352 static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2354 struct net_device *dev = bp->dev;
2355 struct bnxt_rx_ring_info *rxr;
2356 struct bnxt_ring_struct *ring;
2360 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2361 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2363 if (NET_IP_ALIGN == 2)
2364 type |= RX_BD_FLAGS_SOP;
2366 rxr = &bp->rx_ring[ring_nr];
2367 ring = &rxr->rx_ring_struct;
2368 bnxt_init_rxbd_pages(ring, type);
2370 prod = rxr->rx_prod;
2371 for (i = 0; i < bp->rx_ring_size; i++) {
2372 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2373 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2374 ring_nr, i, bp->rx_ring_size);
2377 prod = NEXT_RX(prod);
2379 rxr->rx_prod = prod;
2380 ring->fw_ring_id = INVALID_HW_RING_ID;
2382 ring = &rxr->rx_agg_ring_struct;
2383 ring->fw_ring_id = INVALID_HW_RING_ID;
2385 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2388 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
2389 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2391 bnxt_init_rxbd_pages(ring, type);
2393 prod = rxr->rx_agg_prod;
2394 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2395 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2396 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2397 ring_nr, i, bp->rx_ring_size);
2400 prod = NEXT_RX_AGG(prod);
2402 rxr->rx_agg_prod = prod;
2404 if (bp->flags & BNXT_FLAG_TPA) {
2409 for (i = 0; i < MAX_TPA; i++) {
2410 data = __bnxt_alloc_rx_data(bp, &mapping,
2415 rxr->rx_tpa[i].data = data;
2416 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
2417 rxr->rx_tpa[i].mapping = mapping;
2420 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2428 static int bnxt_init_rx_rings(struct bnxt *bp)
2432 if (BNXT_RX_PAGE_MODE(bp)) {
2433 bp->rx_offset = NET_IP_ALIGN;
2434 bp->rx_dma_offset = 0;
2436 bp->rx_offset = BNXT_RX_OFFSET;
2437 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2440 for (i = 0; i < bp->rx_nr_rings; i++) {
2441 rc = bnxt_init_one_rx_ring(bp, i);
2449 static int bnxt_init_tx_rings(struct bnxt *bp)
2453 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2456 for (i = 0; i < bp->tx_nr_rings; i++) {
2457 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
2458 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2460 ring->fw_ring_id = INVALID_HW_RING_ID;
2466 static void bnxt_free_ring_grps(struct bnxt *bp)
2468 kfree(bp->grp_info);
2469 bp->grp_info = NULL;
2472 static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2477 bp->grp_info = kcalloc(bp->cp_nr_rings,
2478 sizeof(struct bnxt_ring_grp_info),
2483 for (i = 0; i < bp->cp_nr_rings; i++) {
2485 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2486 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2487 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2488 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2489 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2494 static void bnxt_free_vnics(struct bnxt *bp)
2496 kfree(bp->vnic_info);
2497 bp->vnic_info = NULL;
2501 static int bnxt_alloc_vnics(struct bnxt *bp)
2505 #ifdef CONFIG_RFS_ACCEL
2506 if (bp->flags & BNXT_FLAG_RFS)
2507 num_vnics += bp->rx_nr_rings;
2510 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2513 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2518 bp->nr_vnics = num_vnics;
2522 static void bnxt_init_vnics(struct bnxt *bp)
2526 for (i = 0; i < bp->nr_vnics; i++) {
2527 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2529 vnic->fw_vnic_id = INVALID_HW_RING_ID;
2530 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2531 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
2532 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2534 if (bp->vnic_info[i].rss_hash_key) {
2536 prandom_bytes(vnic->rss_hash_key,
2539 memcpy(vnic->rss_hash_key,
2540 bp->vnic_info[0].rss_hash_key,
2546 static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2550 pages = ring_size / desc_per_pg;
2557 while (pages & (pages - 1))
2563 static void bnxt_set_tpa_flags(struct bnxt *bp)
2565 bp->flags &= ~BNXT_FLAG_TPA;
2566 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2568 if (bp->dev->features & NETIF_F_LRO)
2569 bp->flags |= BNXT_FLAG_LRO;
2570 if (bp->dev->features & NETIF_F_GRO)
2571 bp->flags |= BNXT_FLAG_GRO;
2574 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2577 void bnxt_set_ring_params(struct bnxt *bp)
2579 u32 ring_size, rx_size, rx_space;
2580 u32 agg_factor = 0, agg_ring_size = 0;
2582 /* 8 for CRC and VLAN */
2583 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2585 rx_space = rx_size + NET_SKB_PAD +
2586 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2588 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2589 ring_size = bp->rx_ring_size;
2590 bp->rx_agg_ring_size = 0;
2591 bp->rx_agg_nr_pages = 0;
2593 if (bp->flags & BNXT_FLAG_TPA)
2594 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
2596 bp->flags &= ~BNXT_FLAG_JUMBO;
2597 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
2600 bp->flags |= BNXT_FLAG_JUMBO;
2601 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2602 if (jumbo_factor > agg_factor)
2603 agg_factor = jumbo_factor;
2605 agg_ring_size = ring_size * agg_factor;
2607 if (agg_ring_size) {
2608 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2610 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2611 u32 tmp = agg_ring_size;
2613 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2614 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2615 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2616 tmp, agg_ring_size);
2618 bp->rx_agg_ring_size = agg_ring_size;
2619 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2620 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2621 rx_space = rx_size + NET_SKB_PAD +
2622 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2625 bp->rx_buf_use_size = rx_size;
2626 bp->rx_buf_size = rx_space;
2628 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2629 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2631 ring_size = bp->tx_ring_size;
2632 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2633 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2635 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2636 bp->cp_ring_size = ring_size;
2638 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2639 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2640 bp->cp_nr_pages = MAX_CP_PAGES;
2641 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2642 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2643 ring_size, bp->cp_ring_size);
2645 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2646 bp->cp_ring_mask = bp->cp_bit - 1;
2649 int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
2652 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2654 bp->dev->max_mtu = BNXT_MAX_PAGE_MODE_MTU;
2655 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2656 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
2657 bp->dev->hw_features &= ~NETIF_F_LRO;
2658 bp->dev->features &= ~NETIF_F_LRO;
2659 bp->rx_dir = DMA_BIDIRECTIONAL;
2660 bp->rx_skb_func = bnxt_rx_page_skb;
2662 bp->dev->max_mtu = BNXT_MAX_MTU;
2663 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2664 bp->rx_dir = DMA_FROM_DEVICE;
2665 bp->rx_skb_func = bnxt_rx_skb;
2670 static void bnxt_free_vnic_attributes(struct bnxt *bp)
2673 struct bnxt_vnic_info *vnic;
2674 struct pci_dev *pdev = bp->pdev;
2679 for (i = 0; i < bp->nr_vnics; i++) {
2680 vnic = &bp->vnic_info[i];
2682 kfree(vnic->fw_grp_ids);
2683 vnic->fw_grp_ids = NULL;
2685 kfree(vnic->uc_list);
2686 vnic->uc_list = NULL;
2688 if (vnic->mc_list) {
2689 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2690 vnic->mc_list, vnic->mc_list_mapping);
2691 vnic->mc_list = NULL;
2694 if (vnic->rss_table) {
2695 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2697 vnic->rss_table_dma_addr);
2698 vnic->rss_table = NULL;
2701 vnic->rss_hash_key = NULL;
2706 static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2708 int i, rc = 0, size;
2709 struct bnxt_vnic_info *vnic;
2710 struct pci_dev *pdev = bp->pdev;
2713 for (i = 0; i < bp->nr_vnics; i++) {
2714 vnic = &bp->vnic_info[i];
2716 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2717 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2720 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2721 if (!vnic->uc_list) {
2728 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2729 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2731 dma_alloc_coherent(&pdev->dev,
2733 &vnic->mc_list_mapping,
2735 if (!vnic->mc_list) {
2741 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2742 max_rings = bp->rx_nr_rings;
2746 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2747 if (!vnic->fw_grp_ids) {
2752 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2753 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2756 /* Allocate rss table and hash key */
2757 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2758 &vnic->rss_table_dma_addr,
2760 if (!vnic->rss_table) {
2765 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2767 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2768 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2776 static void bnxt_free_hwrm_resources(struct bnxt *bp)
2778 struct pci_dev *pdev = bp->pdev;
2780 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
2781 bp->hwrm_cmd_resp_dma_addr);
2783 bp->hwrm_cmd_resp_addr = NULL;
2784 if (bp->hwrm_dbg_resp_addr) {
2785 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
2786 bp->hwrm_dbg_resp_addr,
2787 bp->hwrm_dbg_resp_dma_addr);
2789 bp->hwrm_dbg_resp_addr = NULL;
2793 static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2795 struct pci_dev *pdev = bp->pdev;
2797 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2798 &bp->hwrm_cmd_resp_dma_addr,
2800 if (!bp->hwrm_cmd_resp_addr)
2802 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
2803 HWRM_DBG_REG_BUF_SIZE,
2804 &bp->hwrm_dbg_resp_dma_addr,
2806 if (!bp->hwrm_dbg_resp_addr)
2807 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
2812 static void bnxt_free_stats(struct bnxt *bp)
2815 struct pci_dev *pdev = bp->pdev;
2817 if (bp->hw_rx_port_stats) {
2818 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
2819 bp->hw_rx_port_stats,
2820 bp->hw_rx_port_stats_map);
2821 bp->hw_rx_port_stats = NULL;
2822 bp->flags &= ~BNXT_FLAG_PORT_STATS;
2828 size = sizeof(struct ctx_hw_stats);
2830 for (i = 0; i < bp->cp_nr_rings; i++) {
2831 struct bnxt_napi *bnapi = bp->bnapi[i];
2832 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2834 if (cpr->hw_stats) {
2835 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
2837 cpr->hw_stats = NULL;
2842 static int bnxt_alloc_stats(struct bnxt *bp)
2845 struct pci_dev *pdev = bp->pdev;
2847 size = sizeof(struct ctx_hw_stats);
2849 for (i = 0; i < bp->cp_nr_rings; i++) {
2850 struct bnxt_napi *bnapi = bp->bnapi[i];
2851 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2853 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
2859 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
2862 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
2863 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
2864 sizeof(struct tx_port_stats) + 1024;
2866 bp->hw_rx_port_stats =
2867 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
2868 &bp->hw_rx_port_stats_map,
2870 if (!bp->hw_rx_port_stats)
2873 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
2875 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
2876 sizeof(struct rx_port_stats) + 512;
2877 bp->flags |= BNXT_FLAG_PORT_STATS;
2882 static void bnxt_clear_ring_indices(struct bnxt *bp)
2889 for (i = 0; i < bp->cp_nr_rings; i++) {
2890 struct bnxt_napi *bnapi = bp->bnapi[i];
2891 struct bnxt_cp_ring_info *cpr;
2892 struct bnxt_rx_ring_info *rxr;
2893 struct bnxt_tx_ring_info *txr;
2898 cpr = &bnapi->cp_ring;
2899 cpr->cp_raw_cons = 0;
2901 txr = bnapi->tx_ring;
2907 rxr = bnapi->rx_ring;
2910 rxr->rx_agg_prod = 0;
2911 rxr->rx_sw_agg_prod = 0;
2912 rxr->rx_next_cons = 0;
2917 static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
2919 #ifdef CONFIG_RFS_ACCEL
2922 /* Under rtnl_lock and all our NAPIs have been disabled. It's
2923 * safe to delete the hash table.
2925 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
2926 struct hlist_head *head;
2927 struct hlist_node *tmp;
2928 struct bnxt_ntuple_filter *fltr;
2930 head = &bp->ntp_fltr_hash_tbl[i];
2931 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
2932 hlist_del(&fltr->hash);
2937 kfree(bp->ntp_fltr_bmap);
2938 bp->ntp_fltr_bmap = NULL;
2940 bp->ntp_fltr_count = 0;
2944 static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
2946 #ifdef CONFIG_RFS_ACCEL
2949 if (!(bp->flags & BNXT_FLAG_RFS))
2952 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
2953 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
2955 bp->ntp_fltr_count = 0;
2956 bp->ntp_fltr_bmap = kzalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
2959 if (!bp->ntp_fltr_bmap)
2968 static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
2970 bnxt_free_vnic_attributes(bp);
2971 bnxt_free_tx_rings(bp);
2972 bnxt_free_rx_rings(bp);
2973 bnxt_free_cp_rings(bp);
2974 bnxt_free_ntp_fltrs(bp, irq_re_init);
2976 bnxt_free_stats(bp);
2977 bnxt_free_ring_grps(bp);
2978 bnxt_free_vnics(bp);
2979 kfree(bp->tx_ring_map);
2980 bp->tx_ring_map = NULL;
2988 bnxt_clear_ring_indices(bp);
2992 static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
2994 int i, j, rc, size, arr_size;
2998 /* Allocate bnapi mem pointer array and mem block for
3001 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3003 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3004 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3010 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3011 bp->bnapi[i] = bnapi;
3012 bp->bnapi[i]->index = i;
3013 bp->bnapi[i]->bp = bp;
3016 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3017 sizeof(struct bnxt_rx_ring_info),
3022 for (i = 0; i < bp->rx_nr_rings; i++) {
3023 bp->rx_ring[i].bnapi = bp->bnapi[i];
3024 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3027 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3028 sizeof(struct bnxt_tx_ring_info),
3033 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3036 if (!bp->tx_ring_map)
3039 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3042 j = bp->rx_nr_rings;
3044 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3045 bp->tx_ring[i].bnapi = bp->bnapi[j];
3046 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
3047 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
3048 if (i >= bp->tx_nr_rings_xdp)
3049 bp->tx_ring[i].txq_index = i -
3050 bp->tx_nr_rings_xdp;
3053 rc = bnxt_alloc_stats(bp);
3057 rc = bnxt_alloc_ntp_fltrs(bp);
3061 rc = bnxt_alloc_vnics(bp);
3066 bnxt_init_ring_struct(bp);
3068 rc = bnxt_alloc_rx_rings(bp);
3072 rc = bnxt_alloc_tx_rings(bp);
3076 rc = bnxt_alloc_cp_rings(bp);
3080 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3081 BNXT_VNIC_UCAST_FLAG;
3082 rc = bnxt_alloc_vnic_attributes(bp);
3088 bnxt_free_mem(bp, true);
3092 static void bnxt_disable_int(struct bnxt *bp)
3099 for (i = 0; i < bp->cp_nr_rings; i++) {
3100 struct bnxt_napi *bnapi = bp->bnapi[i];
3101 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3103 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
3107 static void bnxt_disable_int_sync(struct bnxt *bp)
3111 atomic_inc(&bp->intr_sem);
3113 bnxt_disable_int(bp);
3114 for (i = 0; i < bp->cp_nr_rings; i++)
3115 synchronize_irq(bp->irq_tbl[i].vector);
3118 static void bnxt_enable_int(struct bnxt *bp)
3122 atomic_set(&bp->intr_sem, 0);
3123 for (i = 0; i < bp->cp_nr_rings; i++) {
3124 struct bnxt_napi *bnapi = bp->bnapi[i];
3125 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3127 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3131 void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3132 u16 cmpl_ring, u16 target_id)
3134 struct input *req = request;
3136 req->req_type = cpu_to_le16(req_type);
3137 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3138 req->target_id = cpu_to_le16(target_id);
3139 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3142 static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3143 int timeout, bool silent)
3145 int i, intr_process, rc, tmo_count;
3146 struct input *req = msg;
3148 __le32 *resp_len, *valid;
3149 u16 cp_ring_id, len = 0;
3150 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
3152 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
3153 memset(resp, 0, PAGE_SIZE);
3154 cp_ring_id = le16_to_cpu(req->cmpl_ring);
3155 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3157 /* Write request msg to hwrm channel */
3158 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3160 for (i = msg_len; i < BNXT_HWRM_MAX_REQ_LEN; i += 4)
3161 writel(0, bp->bar0 + i);
3163 /* currently supports only one outstanding message */
3165 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
3167 /* Ring channel doorbell */
3168 writel(1, bp->bar0 + 0x100);
3171 timeout = DFLT_HWRM_CMD_TIMEOUT;
3174 tmo_count = timeout * 40;
3176 /* Wait until hwrm response cmpl interrupt is processed */
3177 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
3179 usleep_range(25, 40);
3182 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3183 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
3184 le16_to_cpu(req->req_type));
3188 /* Check if response len is updated */
3189 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
3190 for (i = 0; i < tmo_count; i++) {
3191 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3195 usleep_range(25, 40);
3198 if (i >= tmo_count) {
3199 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
3200 timeout, le16_to_cpu(req->req_type),
3201 le16_to_cpu(req->seq_id), len);
3205 /* Last word of resp contains valid bit */
3206 valid = bp->hwrm_cmd_resp_addr + len - 4;
3207 for (i = 0; i < 5; i++) {
3208 if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK)
3214 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
3215 timeout, le16_to_cpu(req->req_type),
3216 le16_to_cpu(req->seq_id), len, *valid);
3221 rc = le16_to_cpu(resp->error_code);
3223 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3224 le16_to_cpu(resp->req_type),
3225 le16_to_cpu(resp->seq_id), rc);
3229 int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3231 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
3234 int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3238 mutex_lock(&bp->hwrm_cmd_lock);
3239 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3240 mutex_unlock(&bp->hwrm_cmd_lock);
3244 int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3249 mutex_lock(&bp->hwrm_cmd_lock);
3250 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3251 mutex_unlock(&bp->hwrm_cmd_lock);
3255 int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3258 struct hwrm_func_drv_rgtr_input req = {0};
3259 DECLARE_BITMAP(async_events_bmap, 256);
3260 u32 *events = (u32 *)async_events_bmap;
3263 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3266 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
3268 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3269 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3270 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3272 if (bmap && bmap_size) {
3273 for (i = 0; i < bmap_size; i++) {
3274 if (test_bit(i, bmap))
3275 __set_bit(i, async_events_bmap);
3279 for (i = 0; i < 8; i++)
3280 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3282 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3285 static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3287 struct hwrm_func_drv_rgtr_input req = {0};
3289 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3292 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3293 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3295 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
3296 req.ver_maj = DRV_VER_MAJ;
3297 req.ver_min = DRV_VER_MIN;
3298 req.ver_upd = DRV_VER_UPD;
3301 DECLARE_BITMAP(vf_req_snif_bmap, 256);
3302 u32 *data = (u32 *)vf_req_snif_bmap;
3305 memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap));
3306 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++)
3307 __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap);
3309 for (i = 0; i < 8; i++)
3310 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3313 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3316 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3319 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3321 struct hwrm_func_drv_unrgtr_input req = {0};
3323 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3324 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3327 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3330 struct hwrm_tunnel_dst_port_free_input req = {0};
3332 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3333 req.tunnel_type = tunnel_type;
3335 switch (tunnel_type) {
3336 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3337 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3339 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3340 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3346 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3348 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3353 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3357 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3358 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3360 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3362 req.tunnel_type = tunnel_type;
3363 req.tunnel_dst_port_val = port;
3365 mutex_lock(&bp->hwrm_cmd_lock);
3366 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3368 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3373 switch (tunnel_type) {
3374 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
3375 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3377 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
3378 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
3385 mutex_unlock(&bp->hwrm_cmd_lock);
3389 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3391 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3392 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3394 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
3395 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
3397 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3398 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3399 req.mask = cpu_to_le32(vnic->rx_mask);
3400 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3403 #ifdef CONFIG_RFS_ACCEL
3404 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3405 struct bnxt_ntuple_filter *fltr)
3407 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3409 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3410 req.ntuple_filter_id = fltr->filter_id;
3411 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3414 #define BNXT_NTP_FLTR_FLAGS \
3415 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3416 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3417 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3418 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3419 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3420 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3421 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3422 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3423 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3424 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3425 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3426 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3427 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
3428 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
3430 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3431 struct bnxt_ntuple_filter *fltr)
3434 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3435 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3436 bp->hwrm_cmd_resp_addr;
3437 struct flow_keys *keys = &fltr->fkeys;
3438 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3440 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
3441 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
3443 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3445 req.ethertype = htons(ETH_P_IP);
3446 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
3447 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
3448 req.ip_protocol = keys->basic.ip_proto;
3450 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3453 req.ethertype = htons(ETH_P_IPV6);
3455 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3456 *(struct in6_addr *)&req.src_ipaddr[0] =
3457 keys->addrs.v6addrs.src;
3458 *(struct in6_addr *)&req.dst_ipaddr[0] =
3459 keys->addrs.v6addrs.dst;
3460 for (i = 0; i < 4; i++) {
3461 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3462 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3465 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3466 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3467 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3468 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3471 req.src_port = keys->ports.src;
3472 req.src_port_mask = cpu_to_be16(0xffff);
3473 req.dst_port = keys->ports.dst;
3474 req.dst_port_mask = cpu_to_be16(0xffff);
3476 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
3477 mutex_lock(&bp->hwrm_cmd_lock);
3478 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3480 fltr->filter_id = resp->ntuple_filter_id;
3481 mutex_unlock(&bp->hwrm_cmd_lock);
3486 static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3490 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3491 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3493 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
3494 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3495 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3497 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
3498 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
3500 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
3501 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
3502 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3503 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3504 req.l2_addr_mask[0] = 0xff;
3505 req.l2_addr_mask[1] = 0xff;
3506 req.l2_addr_mask[2] = 0xff;
3507 req.l2_addr_mask[3] = 0xff;
3508 req.l2_addr_mask[4] = 0xff;
3509 req.l2_addr_mask[5] = 0xff;
3511 mutex_lock(&bp->hwrm_cmd_lock);
3512 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3514 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3516 mutex_unlock(&bp->hwrm_cmd_lock);
3520 static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3522 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3525 /* Any associated ntuple filters will also be cleared by firmware. */
3526 mutex_lock(&bp->hwrm_cmd_lock);
3527 for (i = 0; i < num_of_vnics; i++) {
3528 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3530 for (j = 0; j < vnic->uc_filter_count; j++) {
3531 struct hwrm_cfa_l2_filter_free_input req = {0};
3533 bnxt_hwrm_cmd_hdr_init(bp, &req,
3534 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3536 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3538 rc = _hwrm_send_message(bp, &req, sizeof(req),
3541 vnic->uc_filter_count = 0;
3543 mutex_unlock(&bp->hwrm_cmd_lock);
3548 static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3550 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3551 struct hwrm_vnic_tpa_cfg_input req = {0};
3553 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3556 u16 mss = bp->dev->mtu - 40;
3557 u32 nsegs, n, segs = 0, flags;
3559 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3560 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3561 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3562 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3563 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3564 if (tpa_flags & BNXT_FLAG_GRO)
3565 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3567 req.flags = cpu_to_le32(flags);
3570 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
3571 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3572 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
3574 /* Number of segs are log2 units, and first packet is not
3575 * included as part of this units.
3577 if (mss <= BNXT_RX_PAGE_SIZE) {
3578 n = BNXT_RX_PAGE_SIZE / mss;
3579 nsegs = (MAX_SKB_FRAGS - 1) * n;
3581 n = mss / BNXT_RX_PAGE_SIZE;
3582 if (mss & (BNXT_RX_PAGE_SIZE - 1))
3584 nsegs = (MAX_SKB_FRAGS - n) / n;
3587 segs = ilog2(nsegs);
3588 req.max_agg_segs = cpu_to_le16(segs);
3589 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
3591 req.min_agg_len = cpu_to_le32(512);
3593 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3595 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3598 static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3600 u32 i, j, max_rings;
3601 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3602 struct hwrm_vnic_rss_cfg_input req = {0};
3604 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
3607 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3609 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
3610 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3611 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3612 max_rings = bp->rx_nr_rings - 1;
3614 max_rings = bp->rx_nr_rings;
3619 /* Fill the RSS indirection table with ring group ids */
3620 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3623 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3626 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3627 req.hash_key_tbl_addr =
3628 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3630 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
3631 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3634 static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3636 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3637 struct hwrm_vnic_plcmodes_cfg_input req = {0};
3639 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
3640 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
3641 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
3642 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
3644 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
3645 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
3646 /* thresholds not implemented in firmware yet */
3647 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
3648 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
3649 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
3650 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3653 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
3656 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
3658 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
3659 req.rss_cos_lb_ctx_id =
3660 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
3662 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3663 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
3666 static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
3670 for (i = 0; i < bp->nr_vnics; i++) {
3671 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3673 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
3674 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
3675 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
3678 bp->rsscos_nr_ctxs = 0;
3681 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
3684 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
3685 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
3686 bp->hwrm_cmd_resp_addr;
3688 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
3691 mutex_lock(&bp->hwrm_cmd_lock);
3692 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3694 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
3695 le16_to_cpu(resp->rss_cos_lb_ctx_id);
3696 mutex_unlock(&bp->hwrm_cmd_lock);
3701 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
3703 unsigned int ring = 0, grp_idx;
3704 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3705 struct hwrm_vnic_cfg_input req = {0};
3708 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
3710 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
3711 /* Only RSS support for now TBD: COS & LB */
3712 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
3713 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
3714 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3715 VNIC_CFG_REQ_ENABLES_MRU);
3716 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
3718 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
3719 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3720 VNIC_CFG_REQ_ENABLES_MRU);
3721 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
3723 req.rss_rule = cpu_to_le16(0xffff);
3726 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
3727 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
3728 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
3729 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
3731 req.cos_rule = cpu_to_le16(0xffff);
3734 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
3736 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
3738 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
3739 ring = bp->rx_nr_rings - 1;
3741 grp_idx = bp->rx_ring[ring].bnapi->index;
3742 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3743 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
3745 req.lb_rule = cpu_to_le16(0xffff);
3746 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
3749 #ifdef CONFIG_BNXT_SRIOV
3751 def_vlan = bp->vf.vlan;
3753 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
3754 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
3755 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
3757 cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE);
3759 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3762 static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
3766 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
3767 struct hwrm_vnic_free_input req = {0};
3769 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
3771 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
3773 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3776 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
3781 static void bnxt_hwrm_vnic_free(struct bnxt *bp)
3785 for (i = 0; i < bp->nr_vnics; i++)
3786 bnxt_hwrm_vnic_free_one(bp, i);
3789 static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
3790 unsigned int start_rx_ring_idx,
3791 unsigned int nr_rings)
3794 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
3795 struct hwrm_vnic_alloc_input req = {0};
3796 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3798 /* map ring groups to this vnic */
3799 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
3800 grp_idx = bp->rx_ring[i].bnapi->index;
3801 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
3802 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
3806 bp->vnic_info[vnic_id].fw_grp_ids[j] =
3807 bp->grp_info[grp_idx].fw_grp_id;
3810 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
3811 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
3813 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
3815 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
3817 mutex_lock(&bp->hwrm_cmd_lock);
3818 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3820 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
3821 mutex_unlock(&bp->hwrm_cmd_lock);
3825 static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
3827 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3828 struct hwrm_vnic_qcaps_input req = {0};
3831 if (bp->hwrm_spec_code < 0x10600)
3834 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
3835 mutex_lock(&bp->hwrm_cmd_lock);
3836 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3839 cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
3840 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
3842 mutex_unlock(&bp->hwrm_cmd_lock);
3846 static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
3851 mutex_lock(&bp->hwrm_cmd_lock);
3852 for (i = 0; i < bp->rx_nr_rings; i++) {
3853 struct hwrm_ring_grp_alloc_input req = {0};
3854 struct hwrm_ring_grp_alloc_output *resp =
3855 bp->hwrm_cmd_resp_addr;
3856 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
3858 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
3860 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
3861 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
3862 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
3863 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
3865 rc = _hwrm_send_message(bp, &req, sizeof(req),
3870 bp->grp_info[grp_idx].fw_grp_id =
3871 le32_to_cpu(resp->ring_group_id);
3873 mutex_unlock(&bp->hwrm_cmd_lock);
3877 static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
3881 struct hwrm_ring_grp_free_input req = {0};
3886 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
3888 mutex_lock(&bp->hwrm_cmd_lock);
3889 for (i = 0; i < bp->cp_nr_rings; i++) {
3890 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
3893 cpu_to_le32(bp->grp_info[i].fw_grp_id);
3895 rc = _hwrm_send_message(bp, &req, sizeof(req),
3899 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
3901 mutex_unlock(&bp->hwrm_cmd_lock);
3905 static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
3906 struct bnxt_ring_struct *ring,
3907 u32 ring_type, u32 map_index,
3910 int rc = 0, err = 0;
3911 struct hwrm_ring_alloc_input req = {0};
3912 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3915 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
3918 if (ring->nr_pages > 1) {
3919 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
3920 /* Page size is in log2 units */
3921 req.page_size = BNXT_PAGE_SHIFT;
3922 req.page_tbl_depth = 1;
3924 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
3927 /* Association of ring index with doorbell index and MSIX number */
3928 req.logical_id = cpu_to_le16(map_index);
3930 switch (ring_type) {
3931 case HWRM_RING_ALLOC_TX:
3932 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
3933 /* Association of transmit ring with completion ring */
3935 cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id);
3936 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
3937 req.stat_ctx_id = cpu_to_le32(stats_ctx_id);
3938 req.queue_id = cpu_to_le16(ring->queue_id);
3940 case HWRM_RING_ALLOC_RX:
3941 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
3942 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
3944 case HWRM_RING_ALLOC_AGG:
3945 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
3946 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
3948 case HWRM_RING_ALLOC_CMPL:
3949 req.ring_type = RING_ALLOC_REQ_RING_TYPE_CMPL;
3950 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
3951 if (bp->flags & BNXT_FLAG_USING_MSIX)
3952 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
3955 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
3960 mutex_lock(&bp->hwrm_cmd_lock);
3961 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3962 err = le16_to_cpu(resp->error_code);
3963 ring_id = le16_to_cpu(resp->ring_id);
3964 mutex_unlock(&bp->hwrm_cmd_lock);
3967 switch (ring_type) {
3968 case RING_FREE_REQ_RING_TYPE_CMPL:
3969 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
3973 case RING_FREE_REQ_RING_TYPE_RX:
3974 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
3978 case RING_FREE_REQ_RING_TYPE_TX:
3979 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
3984 netdev_err(bp->dev, "Invalid ring\n");
3988 ring->fw_ring_id = ring_id;
3992 static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
3997 struct hwrm_func_cfg_input req = {0};
3999 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4000 req.fid = cpu_to_le16(0xffff);
4001 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4002 req.async_event_cr = cpu_to_le16(idx);
4003 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4005 struct hwrm_func_vf_cfg_input req = {0};
4007 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4009 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4010 req.async_event_cr = cpu_to_le16(idx);
4011 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4016 static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4020 for (i = 0; i < bp->cp_nr_rings; i++) {
4021 struct bnxt_napi *bnapi = bp->bnapi[i];
4022 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4023 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4025 cpr->cp_doorbell = bp->bar1 + i * 0x80;
4026 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
4027 INVALID_STATS_CTX_ID);
4030 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4031 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
4034 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4036 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4040 for (i = 0; i < bp->tx_nr_rings; i++) {
4041 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4042 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4043 u32 map_idx = txr->bnapi->index;
4044 u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
4046 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4047 map_idx, fw_stats_ctx);
4050 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
4053 for (i = 0; i < bp->rx_nr_rings; i++) {
4054 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4055 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
4056 u32 map_idx = rxr->bnapi->index;
4058 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4059 map_idx, INVALID_STATS_CTX_ID);
4062 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
4063 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
4064 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
4067 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4068 for (i = 0; i < bp->rx_nr_rings; i++) {
4069 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4070 struct bnxt_ring_struct *ring =
4071 &rxr->rx_agg_ring_struct;
4072 u32 grp_idx = rxr->bnapi->index;
4073 u32 map_idx = grp_idx + bp->rx_nr_rings;
4075 rc = hwrm_ring_alloc_send_msg(bp, ring,
4076 HWRM_RING_ALLOC_AGG,
4078 INVALID_STATS_CTX_ID);
4082 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
4083 writel(DB_KEY_RX | rxr->rx_agg_prod,
4084 rxr->rx_agg_doorbell);
4085 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
4092 static int hwrm_ring_free_send_msg(struct bnxt *bp,
4093 struct bnxt_ring_struct *ring,
4094 u32 ring_type, int cmpl_ring_id)
4097 struct hwrm_ring_free_input req = {0};
4098 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4101 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
4102 req.ring_type = ring_type;
4103 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4105 mutex_lock(&bp->hwrm_cmd_lock);
4106 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4107 error_code = le16_to_cpu(resp->error_code);
4108 mutex_unlock(&bp->hwrm_cmd_lock);
4110 if (rc || error_code) {
4111 switch (ring_type) {
4112 case RING_FREE_REQ_RING_TYPE_CMPL:
4113 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4116 case RING_FREE_REQ_RING_TYPE_RX:
4117 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4120 case RING_FREE_REQ_RING_TYPE_TX:
4121 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4125 netdev_err(bp->dev, "Invalid ring\n");
4132 static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
4139 for (i = 0; i < bp->tx_nr_rings; i++) {
4140 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4141 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4142 u32 grp_idx = txr->bnapi->index;
4143 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4145 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4146 hwrm_ring_free_send_msg(bp, ring,
4147 RING_FREE_REQ_RING_TYPE_TX,
4148 close_path ? cmpl_ring_id :
4149 INVALID_HW_RING_ID);
4150 ring->fw_ring_id = INVALID_HW_RING_ID;
4154 for (i = 0; i < bp->rx_nr_rings; i++) {
4155 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4156 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
4157 u32 grp_idx = rxr->bnapi->index;
4158 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4160 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4161 hwrm_ring_free_send_msg(bp, ring,
4162 RING_FREE_REQ_RING_TYPE_RX,
4163 close_path ? cmpl_ring_id :
4164 INVALID_HW_RING_ID);
4165 ring->fw_ring_id = INVALID_HW_RING_ID;
4166 bp->grp_info[grp_idx].rx_fw_ring_id =
4171 for (i = 0; i < bp->rx_nr_rings; i++) {
4172 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4173 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
4174 u32 grp_idx = rxr->bnapi->index;
4175 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
4177 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4178 hwrm_ring_free_send_msg(bp, ring,
4179 RING_FREE_REQ_RING_TYPE_RX,
4180 close_path ? cmpl_ring_id :
4181 INVALID_HW_RING_ID);
4182 ring->fw_ring_id = INVALID_HW_RING_ID;
4183 bp->grp_info[grp_idx].agg_fw_ring_id =
4188 /* The completion rings are about to be freed. After that the
4189 * IRQ doorbell will not work anymore. So we need to disable
4192 bnxt_disable_int_sync(bp);
4194 for (i = 0; i < bp->cp_nr_rings; i++) {
4195 struct bnxt_napi *bnapi = bp->bnapi[i];
4196 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4197 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4199 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4200 hwrm_ring_free_send_msg(bp, ring,
4201 RING_FREE_REQ_RING_TYPE_CMPL,
4202 INVALID_HW_RING_ID);
4203 ring->fw_ring_id = INVALID_HW_RING_ID;
4204 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
4209 /* Caller must hold bp->hwrm_cmd_lock */
4210 int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4212 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4213 struct hwrm_func_qcfg_input req = {0};
4216 if (bp->hwrm_spec_code < 0x10601)
4219 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4220 req.fid = cpu_to_le16(fid);
4221 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4223 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4228 static int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings)
4230 struct hwrm_func_cfg_input req = {0};
4233 if (bp->hwrm_spec_code < 0x10601)
4239 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4240 req.fid = cpu_to_le16(0xffff);
4241 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS);
4242 req.num_tx_rings = cpu_to_le16(*tx_rings);
4243 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4247 mutex_lock(&bp->hwrm_cmd_lock);
4248 rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings);
4249 mutex_unlock(&bp->hwrm_cmd_lock);
4253 static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs,
4254 u32 buf_tmrs, u16 flags,
4255 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4257 req->flags = cpu_to_le16(flags);
4258 req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs);
4259 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16);
4260 req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs);
4261 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16);
4262 /* Minimum time between 2 interrupts set to buf_tmr x 2 */
4263 req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2);
4264 req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4);
4265 req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4);
4268 int bnxt_hwrm_set_coal(struct bnxt *bp)
4271 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4273 u16 max_buf, max_buf_irq;
4274 u16 buf_tmr, buf_tmr_irq;
4277 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4278 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4279 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4280 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4282 /* Each rx completion (2 records) should be DMAed immediately.
4283 * DMA 1/4 of the completion buffers at a time.
4285 max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2);
4286 /* max_buf must not be zero */
4287 max_buf = clamp_t(u16, max_buf, 1, 63);
4288 max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63);
4289 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks);
4290 /* buf timer set to 1/4 of interrupt timer */
4291 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4292 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq);
4293 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4295 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4297 /* RING_IDLE generates more IRQs for lower latency. Enable it only
4298 * if coal_ticks is less than 25 us.
4300 if (bp->rx_coal_ticks < 25)
4301 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
4303 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4304 buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
4306 /* max_buf must not be zero */
4307 max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63);
4308 max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63);
4309 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks);
4310 /* buf timer set to 1/4 of interrupt timer */
4311 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4312 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq);
4313 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4315 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4316 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4317 buf_tmr_irq << 16 | buf_tmr, flags, &req_tx);
4319 mutex_lock(&bp->hwrm_cmd_lock);
4320 for (i = 0; i < bp->cp_nr_rings; i++) {
4321 struct bnxt_napi *bnapi = bp->bnapi[i];
4324 if (!bnapi->rx_ring)
4326 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
4328 rc = _hwrm_send_message(bp, req, sizeof(*req),
4333 mutex_unlock(&bp->hwrm_cmd_lock);
4337 static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
4340 struct hwrm_stat_ctx_free_input req = {0};
4345 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4348 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
4350 mutex_lock(&bp->hwrm_cmd_lock);
4351 for (i = 0; i < bp->cp_nr_rings; i++) {
4352 struct bnxt_napi *bnapi = bp->bnapi[i];
4353 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4355 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
4356 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
4358 rc = _hwrm_send_message(bp, &req, sizeof(req),
4363 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
4366 mutex_unlock(&bp->hwrm_cmd_lock);
4370 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
4373 struct hwrm_stat_ctx_alloc_input req = {0};
4374 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4376 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4379 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
4381 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
4383 mutex_lock(&bp->hwrm_cmd_lock);
4384 for (i = 0; i < bp->cp_nr_rings; i++) {
4385 struct bnxt_napi *bnapi = bp->bnapi[i];
4386 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4388 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
4390 rc = _hwrm_send_message(bp, &req, sizeof(req),
4395 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
4397 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
4399 mutex_unlock(&bp->hwrm_cmd_lock);
4403 static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
4405 struct hwrm_func_qcfg_input req = {0};
4406 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4409 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4410 req.fid = cpu_to_le16(0xffff);
4411 mutex_lock(&bp->hwrm_cmd_lock);
4412 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4414 goto func_qcfg_exit;
4416 #ifdef CONFIG_BNXT_SRIOV
4418 struct bnxt_vf_info *vf = &bp->vf;
4420 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
4423 switch (resp->port_partition_type) {
4424 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
4425 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
4426 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
4427 bp->port_partition_type = resp->port_partition_type;
4432 mutex_unlock(&bp->hwrm_cmd_lock);
4436 static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
4439 struct hwrm_func_qcaps_input req = {0};
4440 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4442 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
4443 req.fid = cpu_to_le16(0xffff);
4445 mutex_lock(&bp->hwrm_cmd_lock);
4446 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4448 goto hwrm_func_qcaps_exit;
4450 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED))
4451 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
4452 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED))
4453 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
4455 bp->tx_push_thresh = 0;
4457 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED))
4458 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
4461 struct bnxt_pf_info *pf = &bp->pf;
4463 pf->fw_fid = le16_to_cpu(resp->fid);
4464 pf->port_id = le16_to_cpu(resp->port_id);
4465 bp->dev->dev_port = pf->port_id;
4466 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
4467 memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN);
4468 pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4469 pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4470 pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
4471 pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
4472 pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4473 if (!pf->max_hw_ring_grps)
4474 pf->max_hw_ring_grps = pf->max_tx_rings;
4475 pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4476 pf->max_vnics = le16_to_cpu(resp->max_vnics);
4477 pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
4478 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
4479 pf->max_vfs = le16_to_cpu(resp->max_vfs);
4480 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
4481 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
4482 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
4483 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
4484 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
4485 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
4487 #ifdef CONFIG_BNXT_SRIOV
4488 struct bnxt_vf_info *vf = &bp->vf;
4490 vf->fw_fid = le16_to_cpu(resp->fid);
4492 vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4493 vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4494 vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
4495 vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
4496 vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4497 if (!vf->max_hw_ring_grps)
4498 vf->max_hw_ring_grps = vf->max_tx_rings;
4499 vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4500 vf->max_vnics = le16_to_cpu(resp->max_vnics);
4501 vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
4503 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
4504 mutex_unlock(&bp->hwrm_cmd_lock);
4506 if (is_valid_ether_addr(vf->mac_addr)) {
4507 /* overwrite netdev dev_adr with admin VF MAC */
4508 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
4510 random_ether_addr(bp->dev->dev_addr);
4511 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
4517 hwrm_func_qcaps_exit:
4518 mutex_unlock(&bp->hwrm_cmd_lock);
4522 static int bnxt_hwrm_func_reset(struct bnxt *bp)
4524 struct hwrm_func_reset_input req = {0};
4526 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
4529 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
4532 static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
4535 struct hwrm_queue_qportcfg_input req = {0};
4536 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
4539 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
4541 mutex_lock(&bp->hwrm_cmd_lock);
4542 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4546 if (!resp->max_configurable_queues) {
4550 bp->max_tc = resp->max_configurable_queues;
4551 bp->max_lltc = resp->max_configurable_lossless_queues;
4552 if (bp->max_tc > BNXT_MAX_QUEUE)
4553 bp->max_tc = BNXT_MAX_QUEUE;
4555 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
4558 if (bp->max_lltc > bp->max_tc)
4559 bp->max_lltc = bp->max_tc;
4561 qptr = &resp->queue_id0;
4562 for (i = 0; i < bp->max_tc; i++) {
4563 bp->q_info[i].queue_id = *qptr++;
4564 bp->q_info[i].queue_profile = *qptr++;
4568 mutex_unlock(&bp->hwrm_cmd_lock);
4572 static int bnxt_hwrm_ver_get(struct bnxt *bp)
4575 struct hwrm_ver_get_input req = {0};
4576 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
4578 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
4579 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
4580 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
4581 req.hwrm_intf_min = HWRM_VERSION_MINOR;
4582 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
4583 mutex_lock(&bp->hwrm_cmd_lock);
4584 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4586 goto hwrm_ver_get_exit;
4588 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
4590 bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 |
4591 resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd;
4592 if (resp->hwrm_intf_maj < 1) {
4593 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
4594 resp->hwrm_intf_maj, resp->hwrm_intf_min,
4595 resp->hwrm_intf_upd);
4596 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
4598 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d/%d.%d.%d",
4599 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld,
4600 resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd);
4602 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
4603 if (!bp->hwrm_cmd_timeout)
4604 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
4606 if (resp->hwrm_intf_maj >= 1)
4607 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
4609 bp->chip_num = le16_to_cpu(resp->chip_num);
4610 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
4612 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
4615 mutex_unlock(&bp->hwrm_cmd_lock);
4619 int bnxt_hwrm_fw_set_time(struct bnxt *bp)
4621 #if IS_ENABLED(CONFIG_RTC_LIB)
4622 struct hwrm_fw_set_time_input req = {0};
4626 if (bp->hwrm_spec_code < 0x10400)
4629 do_gettimeofday(&tv);
4630 rtc_time_to_tm(tv.tv_sec, &tm);
4631 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
4632 req.year = cpu_to_le16(1900 + tm.tm_year);
4633 req.month = 1 + tm.tm_mon;
4634 req.day = tm.tm_mday;
4635 req.hour = tm.tm_hour;
4636 req.minute = tm.tm_min;
4637 req.second = tm.tm_sec;
4638 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4644 static int bnxt_hwrm_port_qstats(struct bnxt *bp)
4647 struct bnxt_pf_info *pf = &bp->pf;
4648 struct hwrm_port_qstats_input req = {0};
4650 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
4653 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
4654 req.port_id = cpu_to_le16(pf->port_id);
4655 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
4656 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
4657 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4661 static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
4663 if (bp->vxlan_port_cnt) {
4664 bnxt_hwrm_tunnel_dst_port_free(
4665 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
4667 bp->vxlan_port_cnt = 0;
4668 if (bp->nge_port_cnt) {
4669 bnxt_hwrm_tunnel_dst_port_free(
4670 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
4672 bp->nge_port_cnt = 0;
4675 static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
4681 tpa_flags = bp->flags & BNXT_FLAG_TPA;
4682 for (i = 0; i < bp->nr_vnics; i++) {
4683 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
4685 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
4693 static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
4697 for (i = 0; i < bp->nr_vnics; i++)
4698 bnxt_hwrm_vnic_set_rss(bp, i, false);
4701 static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
4704 if (bp->vnic_info) {
4705 bnxt_hwrm_clear_vnic_filter(bp);
4706 /* clear all RSS setting before free vnic ctx */
4707 bnxt_hwrm_clear_vnic_rss(bp);
4708 bnxt_hwrm_vnic_ctx_free(bp);
4709 /* before free the vnic, undo the vnic tpa settings */
4710 if (bp->flags & BNXT_FLAG_TPA)
4711 bnxt_set_tpa(bp, false);
4712 bnxt_hwrm_vnic_free(bp);
4714 bnxt_hwrm_ring_free(bp, close_path);
4715 bnxt_hwrm_ring_grp_free(bp);
4717 bnxt_hwrm_stat_ctx_free(bp);
4718 bnxt_hwrm_free_tunnel_ports(bp);
4722 static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
4724 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4727 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
4730 /* allocate context for vnic */
4731 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
4733 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4735 goto vnic_setup_err;
4737 bp->rsscos_nr_ctxs++;
4739 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
4740 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
4742 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
4744 goto vnic_setup_err;
4746 bp->rsscos_nr_ctxs++;
4750 /* configure default vnic, ring grp */
4751 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
4753 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
4755 goto vnic_setup_err;
4758 /* Enable RSS hashing on vnic */
4759 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
4761 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
4763 goto vnic_setup_err;
4766 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4767 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
4769 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
4778 static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
4780 #ifdef CONFIG_RFS_ACCEL
4783 for (i = 0; i < bp->rx_nr_rings; i++) {
4784 struct bnxt_vnic_info *vnic;
4785 u16 vnic_id = i + 1;
4788 if (vnic_id >= bp->nr_vnics)
4791 vnic = &bp->vnic_info[vnic_id];
4792 vnic->flags |= BNXT_VNIC_RFS_FLAG;
4793 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
4794 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
4795 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
4797 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4801 rc = bnxt_setup_vnic(bp, vnic_id);
4811 /* Allow PF and VF with default VLAN to be in promiscuous mode */
4812 static bool bnxt_promisc_ok(struct bnxt *bp)
4814 #ifdef CONFIG_BNXT_SRIOV
4815 if (BNXT_VF(bp) && !bp->vf.vlan)
4821 static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
4823 unsigned int rc = 0;
4825 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
4827 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
4832 rc = bnxt_hwrm_vnic_cfg(bp, 1);
4834 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
4841 static int bnxt_cfg_rx_mode(struct bnxt *);
4842 static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
4844 static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
4846 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
4848 unsigned int rx_nr_rings = bp->rx_nr_rings;
4851 rc = bnxt_hwrm_stat_ctx_alloc(bp);
4853 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
4859 rc = bnxt_hwrm_ring_alloc(bp);
4861 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
4865 rc = bnxt_hwrm_ring_grp_alloc(bp);
4867 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
4871 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4874 /* default vnic 0 */
4875 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
4877 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
4881 rc = bnxt_setup_vnic(bp, 0);
4885 if (bp->flags & BNXT_FLAG_RFS) {
4886 rc = bnxt_alloc_rfs_vnics(bp);
4891 if (bp->flags & BNXT_FLAG_TPA) {
4892 rc = bnxt_set_tpa(bp, true);
4898 bnxt_update_vf_mac(bp);
4900 /* Filter for default vnic 0 */
4901 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
4903 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
4906 vnic->uc_filter_count = 1;
4908 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
4910 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
4911 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
4913 if (bp->dev->flags & IFF_ALLMULTI) {
4914 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
4915 vnic->mc_list_count = 0;
4919 bnxt_mc_list_updated(bp, &mask);
4920 vnic->rx_mask |= mask;
4923 rc = bnxt_cfg_rx_mode(bp);
4927 rc = bnxt_hwrm_set_coal(bp);
4929 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
4932 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
4933 rc = bnxt_setup_nitroa0_vnic(bp);
4935 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
4940 bnxt_hwrm_func_qcfg(bp);
4941 netdev_update_features(bp->dev);
4947 bnxt_hwrm_resource_free(bp, 0, true);
4952 static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
4954 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
4958 static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
4960 bnxt_init_rx_rings(bp);
4961 bnxt_init_tx_rings(bp);
4962 bnxt_init_ring_grps(bp, irq_re_init);
4963 bnxt_init_vnics(bp);
4965 return bnxt_init_chip(bp, irq_re_init);
4968 static int bnxt_set_real_num_queues(struct bnxt *bp)
4971 struct net_device *dev = bp->dev;
4973 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
4974 bp->tx_nr_rings_xdp);
4978 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
4982 #ifdef CONFIG_RFS_ACCEL
4983 if (bp->flags & BNXT_FLAG_RFS)
4984 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
4990 static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4993 int _rx = *rx, _tx = *tx;
4996 *rx = min_t(int, _rx, max);
4997 *tx = min_t(int, _tx, max);
5002 while (_rx + _tx > max) {
5003 if (_rx > _tx && _rx > 1)
5014 static void bnxt_setup_msix(struct bnxt *bp)
5016 const int len = sizeof(bp->irq_tbl[0].name);
5017 struct net_device *dev = bp->dev;
5020 tcs = netdev_get_num_tc(dev);
5024 for (i = 0; i < tcs; i++) {
5025 count = bp->tx_nr_rings_per_tc;
5027 netdev_set_tc_queue(dev, i, count, off);
5031 for (i = 0; i < bp->cp_nr_rings; i++) {
5034 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5036 else if (i < bp->rx_nr_rings)
5041 snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr,
5043 bp->irq_tbl[i].handler = bnxt_msix;
5047 static void bnxt_setup_inta(struct bnxt *bp)
5049 const int len = sizeof(bp->irq_tbl[0].name);
5051 if (netdev_get_num_tc(bp->dev))
5052 netdev_reset_tc(bp->dev);
5054 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5056 bp->irq_tbl[0].handler = bnxt_inta;
5059 static int bnxt_setup_int_mode(struct bnxt *bp)
5063 if (bp->flags & BNXT_FLAG_USING_MSIX)
5064 bnxt_setup_msix(bp);
5066 bnxt_setup_inta(bp);
5068 rc = bnxt_set_real_num_queues(bp);
5072 #ifdef CONFIG_RFS_ACCEL
5073 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5075 #if defined(CONFIG_BNXT_SRIOV)
5077 return bp->vf.max_rsscos_ctxs;
5079 return bp->pf.max_rsscos_ctxs;
5082 static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5084 #if defined(CONFIG_BNXT_SRIOV)
5086 return bp->vf.max_vnics;
5088 return bp->pf.max_vnics;
5092 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5094 #if defined(CONFIG_BNXT_SRIOV)
5096 return bp->vf.max_stat_ctxs;
5098 return bp->pf.max_stat_ctxs;
5101 void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5103 #if defined(CONFIG_BNXT_SRIOV)
5105 bp->vf.max_stat_ctxs = max;
5108 bp->pf.max_stat_ctxs = max;
5111 unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5113 #if defined(CONFIG_BNXT_SRIOV)
5115 return bp->vf.max_cp_rings;
5117 return bp->pf.max_cp_rings;
5120 void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5122 #if defined(CONFIG_BNXT_SRIOV)
5124 bp->vf.max_cp_rings = max;
5127 bp->pf.max_cp_rings = max;
5130 static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
5132 #if defined(CONFIG_BNXT_SRIOV)
5134 return bp->vf.max_irqs;
5136 return bp->pf.max_irqs;
5139 void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5141 #if defined(CONFIG_BNXT_SRIOV)
5143 bp->vf.max_irqs = max_irqs;
5146 bp->pf.max_irqs = max_irqs;
5149 static int bnxt_init_msix(struct bnxt *bp)
5151 int i, total_vecs, rc = 0, min = 1;
5152 struct msix_entry *msix_ent;
5154 total_vecs = bnxt_get_max_func_irqs(bp);
5155 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5159 for (i = 0; i < total_vecs; i++) {
5160 msix_ent[i].entry = i;
5161 msix_ent[i].vector = 0;
5164 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5167 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
5168 if (total_vecs < 0) {
5170 goto msix_setup_exit;
5173 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5175 for (i = 0; i < total_vecs; i++)
5176 bp->irq_tbl[i].vector = msix_ent[i].vector;
5178 bp->total_irqs = total_vecs;
5179 /* Trim rings based upon num of vectors allocated */
5180 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
5181 total_vecs, min == 1);
5183 goto msix_setup_exit;
5185 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5186 bp->cp_nr_rings = (min == 1) ?
5187 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5188 bp->tx_nr_rings + bp->rx_nr_rings;
5192 goto msix_setup_exit;
5194 bp->flags |= BNXT_FLAG_USING_MSIX;
5199 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
5202 pci_disable_msix(bp->pdev);
5207 static int bnxt_init_inta(struct bnxt *bp)
5209 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
5214 bp->rx_nr_rings = 1;
5215 bp->tx_nr_rings = 1;
5216 bp->cp_nr_rings = 1;
5217 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5218 bp->flags |= BNXT_FLAG_SHARED_RINGS;
5219 bp->irq_tbl[0].vector = bp->pdev->irq;
5223 static int bnxt_init_int_mode(struct bnxt *bp)
5227 if (bp->flags & BNXT_FLAG_MSIX_CAP)
5228 rc = bnxt_init_msix(bp);
5230 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
5231 /* fallback to INTA */
5232 rc = bnxt_init_inta(bp);
5237 static void bnxt_clear_int_mode(struct bnxt *bp)
5239 if (bp->flags & BNXT_FLAG_USING_MSIX)
5240 pci_disable_msix(bp->pdev);
5244 bp->flags &= ~BNXT_FLAG_USING_MSIX;
5247 static void bnxt_free_irq(struct bnxt *bp)
5249 struct bnxt_irq *irq;
5252 #ifdef CONFIG_RFS_ACCEL
5253 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
5254 bp->dev->rx_cpu_rmap = NULL;
5259 for (i = 0; i < bp->cp_nr_rings; i++) {
5260 irq = &bp->irq_tbl[i];
5262 free_irq(irq->vector, bp->bnapi[i]);
5267 static int bnxt_request_irq(struct bnxt *bp)
5270 unsigned long flags = 0;
5271 #ifdef CONFIG_RFS_ACCEL
5272 struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap;
5275 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
5276 flags = IRQF_SHARED;
5278 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
5279 struct bnxt_irq *irq = &bp->irq_tbl[i];
5280 #ifdef CONFIG_RFS_ACCEL
5281 if (rmap && bp->bnapi[i]->rx_ring) {
5282 rc = irq_cpu_rmap_add(rmap, irq->vector);
5284 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
5289 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
5299 static void bnxt_del_napi(struct bnxt *bp)
5306 for (i = 0; i < bp->cp_nr_rings; i++) {
5307 struct bnxt_napi *bnapi = bp->bnapi[i];
5309 napi_hash_del(&bnapi->napi);
5310 netif_napi_del(&bnapi->napi);
5312 /* We called napi_hash_del() before netif_napi_del(), we need
5313 * to respect an RCU grace period before freeing napi structures.
5318 static void bnxt_init_napi(struct bnxt *bp)
5321 unsigned int cp_nr_rings = bp->cp_nr_rings;
5322 struct bnxt_napi *bnapi;
5324 if (bp->flags & BNXT_FLAG_USING_MSIX) {
5325 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5327 for (i = 0; i < cp_nr_rings; i++) {
5328 bnapi = bp->bnapi[i];
5329 netif_napi_add(bp->dev, &bnapi->napi,
5332 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5333 bnapi = bp->bnapi[cp_nr_rings];
5334 netif_napi_add(bp->dev, &bnapi->napi,
5335 bnxt_poll_nitroa0, 64);
5338 bnapi = bp->bnapi[0];
5339 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
5343 static void bnxt_disable_napi(struct bnxt *bp)
5350 for (i = 0; i < bp->cp_nr_rings; i++)
5351 napi_disable(&bp->bnapi[i]->napi);
5354 static void bnxt_enable_napi(struct bnxt *bp)
5358 for (i = 0; i < bp->cp_nr_rings; i++) {
5359 bp->bnapi[i]->in_reset = false;
5360 napi_enable(&bp->bnapi[i]->napi);
5364 void bnxt_tx_disable(struct bnxt *bp)
5367 struct bnxt_tx_ring_info *txr;
5368 struct netdev_queue *txq;
5371 for (i = 0; i < bp->tx_nr_rings; i++) {
5372 txr = &bp->tx_ring[i];
5373 txq = netdev_get_tx_queue(bp->dev, i);
5374 txr->dev_state = BNXT_DEV_STATE_CLOSING;
5377 /* Stop all TX queues */
5378 netif_tx_disable(bp->dev);
5379 netif_carrier_off(bp->dev);
5382 void bnxt_tx_enable(struct bnxt *bp)
5385 struct bnxt_tx_ring_info *txr;
5386 struct netdev_queue *txq;
5388 for (i = 0; i < bp->tx_nr_rings; i++) {
5389 txr = &bp->tx_ring[i];
5390 txq = netdev_get_tx_queue(bp->dev, i);
5393 netif_tx_wake_all_queues(bp->dev);
5394 if (bp->link_info.link_up)
5395 netif_carrier_on(bp->dev);
5398 static void bnxt_report_link(struct bnxt *bp)
5400 if (bp->link_info.link_up) {
5402 const char *flow_ctrl;
5405 netif_carrier_on(bp->dev);
5406 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
5410 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
5411 flow_ctrl = "ON - receive & transmit";
5412 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
5413 flow_ctrl = "ON - transmit";
5414 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
5415 flow_ctrl = "ON - receive";
5418 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
5419 netdev_info(bp->dev, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
5420 speed, duplex, flow_ctrl);
5421 if (bp->flags & BNXT_FLAG_EEE_CAP)
5422 netdev_info(bp->dev, "EEE is %s\n",
5423 bp->eee.eee_active ? "active" :
5426 netif_carrier_off(bp->dev);
5427 netdev_err(bp->dev, "NIC Link is Down\n");
5431 static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
5434 struct hwrm_port_phy_qcaps_input req = {0};
5435 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5436 struct bnxt_link_info *link_info = &bp->link_info;
5438 if (bp->hwrm_spec_code < 0x10201)
5441 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
5443 mutex_lock(&bp->hwrm_cmd_lock);
5444 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5446 goto hwrm_phy_qcaps_exit;
5448 if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) {
5449 struct ethtool_eee *eee = &bp->eee;
5450 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
5452 bp->flags |= BNXT_FLAG_EEE_CAP;
5453 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5454 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
5455 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
5456 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
5457 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
5459 link_info->support_auto_speeds =
5460 le16_to_cpu(resp->supported_speeds_auto_mode);
5462 hwrm_phy_qcaps_exit:
5463 mutex_unlock(&bp->hwrm_cmd_lock);
5467 static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
5470 struct bnxt_link_info *link_info = &bp->link_info;
5471 struct hwrm_port_phy_qcfg_input req = {0};
5472 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5473 u8 link_up = link_info->link_up;
5476 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
5478 mutex_lock(&bp->hwrm_cmd_lock);
5479 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5481 mutex_unlock(&bp->hwrm_cmd_lock);
5485 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
5486 link_info->phy_link_status = resp->link;
5487 link_info->duplex = resp->duplex;
5488 link_info->pause = resp->pause;
5489 link_info->auto_mode = resp->auto_mode;
5490 link_info->auto_pause_setting = resp->auto_pause;
5491 link_info->lp_pause = resp->link_partner_adv_pause;
5492 link_info->force_pause_setting = resp->force_pause;
5493 link_info->duplex_setting = resp->duplex;
5494 if (link_info->phy_link_status == BNXT_LINK_LINK)
5495 link_info->link_speed = le16_to_cpu(resp->link_speed);
5497 link_info->link_speed = 0;
5498 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
5499 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
5500 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
5501 link_info->lp_auto_link_speeds =
5502 le16_to_cpu(resp->link_partner_adv_speeds);
5503 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
5504 link_info->phy_ver[0] = resp->phy_maj;
5505 link_info->phy_ver[1] = resp->phy_min;
5506 link_info->phy_ver[2] = resp->phy_bld;
5507 link_info->media_type = resp->media_type;
5508 link_info->phy_type = resp->phy_type;
5509 link_info->transceiver = resp->xcvr_pkg_type;
5510 link_info->phy_addr = resp->eee_config_phy_addr &
5511 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
5512 link_info->module_status = resp->module_status;
5514 if (bp->flags & BNXT_FLAG_EEE_CAP) {
5515 struct ethtool_eee *eee = &bp->eee;
5518 eee->eee_active = 0;
5519 if (resp->eee_config_phy_addr &
5520 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
5521 eee->eee_active = 1;
5522 fw_speeds = le16_to_cpu(
5523 resp->link_partner_adv_eee_link_speed_mask);
5524 eee->lp_advertised =
5525 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5528 /* Pull initial EEE config */
5529 if (!chng_link_state) {
5530 if (resp->eee_config_phy_addr &
5531 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
5532 eee->eee_enabled = 1;
5534 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
5536 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5538 if (resp->eee_config_phy_addr &
5539 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
5542 eee->tx_lpi_enabled = 1;
5543 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
5544 eee->tx_lpi_timer = le32_to_cpu(tmr) &
5545 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
5549 /* TODO: need to add more logic to report VF link */
5550 if (chng_link_state) {
5551 if (link_info->phy_link_status == BNXT_LINK_LINK)
5552 link_info->link_up = 1;
5554 link_info->link_up = 0;
5555 if (link_up != link_info->link_up)
5556 bnxt_report_link(bp);
5558 /* alwasy link down if not require to update link state */
5559 link_info->link_up = 0;
5561 mutex_unlock(&bp->hwrm_cmd_lock);
5563 diff = link_info->support_auto_speeds ^ link_info->advertising;
5564 if ((link_info->support_auto_speeds | diff) !=
5565 link_info->support_auto_speeds) {
5566 /* An advertised speed is no longer supported, so we need to
5567 * update the advertisement settings. Caller holds RTNL
5568 * so we can modify link settings.
5570 link_info->advertising = link_info->support_auto_speeds;
5571 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
5572 bnxt_hwrm_set_link_setting(bp, true, false);
5577 static void bnxt_get_port_module_status(struct bnxt *bp)
5579 struct bnxt_link_info *link_info = &bp->link_info;
5580 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
5583 if (bnxt_update_link(bp, true))
5586 module_status = link_info->module_status;
5587 switch (module_status) {
5588 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
5589 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
5590 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
5591 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
5593 if (bp->hwrm_spec_code >= 0x10201) {
5594 netdev_warn(bp->dev, "Module part number %s\n",
5595 resp->phy_vendor_partnumber);
5597 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
5598 netdev_warn(bp->dev, "TX is disabled\n");
5599 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
5600 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
5605 bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
5607 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
5608 if (bp->hwrm_spec_code >= 0x10201)
5610 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
5611 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5612 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
5613 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
5614 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
5616 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5618 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5619 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
5620 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
5621 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
5623 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
5624 if (bp->hwrm_spec_code >= 0x10201) {
5625 req->auto_pause = req->force_pause;
5626 req->enables |= cpu_to_le32(
5627 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5632 static void bnxt_hwrm_set_link_common(struct bnxt *bp,
5633 struct hwrm_port_phy_cfg_input *req)
5635 u8 autoneg = bp->link_info.autoneg;
5636 u16 fw_link_speed = bp->link_info.req_link_speed;
5637 u16 advertising = bp->link_info.advertising;
5639 if (autoneg & BNXT_AUTONEG_SPEED) {
5641 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
5643 req->enables |= cpu_to_le32(
5644 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
5645 req->auto_link_speed_mask = cpu_to_le16(advertising);
5647 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
5649 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
5651 req->force_link_speed = cpu_to_le16(fw_link_speed);
5652 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
5655 /* tell chimp that the setting takes effect immediately */
5656 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
5659 int bnxt_hwrm_set_pause(struct bnxt *bp)
5661 struct hwrm_port_phy_cfg_input req = {0};
5664 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5665 bnxt_hwrm_set_pause_common(bp, &req);
5667 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
5668 bp->link_info.force_link_chng)
5669 bnxt_hwrm_set_link_common(bp, &req);
5671 mutex_lock(&bp->hwrm_cmd_lock);
5672 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5673 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
5674 /* since changing of pause setting doesn't trigger any link
5675 * change event, the driver needs to update the current pause
5676 * result upon successfully return of the phy_cfg command
5678 bp->link_info.pause =
5679 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
5680 bp->link_info.auto_pause_setting = 0;
5681 if (!bp->link_info.force_link_chng)
5682 bnxt_report_link(bp);
5684 bp->link_info.force_link_chng = false;
5685 mutex_unlock(&bp->hwrm_cmd_lock);
5689 static void bnxt_hwrm_set_eee(struct bnxt *bp,
5690 struct hwrm_port_phy_cfg_input *req)
5692 struct ethtool_eee *eee = &bp->eee;
5694 if (eee->eee_enabled) {
5696 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
5698 if (eee->tx_lpi_enabled)
5699 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
5701 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
5703 req->flags |= cpu_to_le32(flags);
5704 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
5705 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
5706 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
5708 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
5712 int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
5714 struct hwrm_port_phy_cfg_input req = {0};
5716 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5718 bnxt_hwrm_set_pause_common(bp, &req);
5720 bnxt_hwrm_set_link_common(bp, &req);
5723 bnxt_hwrm_set_eee(bp, &req);
5724 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5727 static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
5729 struct hwrm_port_phy_cfg_input req = {0};
5731 if (!BNXT_SINGLE_PF(bp))
5734 if (pci_num_vf(bp->pdev))
5737 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5738 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
5739 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5742 static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
5744 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5745 struct hwrm_port_led_qcaps_input req = {0};
5746 struct bnxt_pf_info *pf = &bp->pf;
5749 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
5752 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
5753 req.port_id = cpu_to_le16(pf->port_id);
5754 mutex_lock(&bp->hwrm_cmd_lock);
5755 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5757 mutex_unlock(&bp->hwrm_cmd_lock);
5760 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
5763 bp->num_leds = resp->num_leds;
5764 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
5766 for (i = 0; i < bp->num_leds; i++) {
5767 struct bnxt_led_info *led = &bp->leds[i];
5768 __le16 caps = led->led_state_caps;
5770 if (!led->led_group_id ||
5771 !BNXT_LED_ALT_BLINK_CAP(caps)) {
5777 mutex_unlock(&bp->hwrm_cmd_lock);
5781 static bool bnxt_eee_config_ok(struct bnxt *bp)
5783 struct ethtool_eee *eee = &bp->eee;
5784 struct bnxt_link_info *link_info = &bp->link_info;
5786 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
5789 if (eee->eee_enabled) {
5791 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
5793 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
5794 eee->eee_enabled = 0;
5797 if (eee->advertised & ~advertising) {
5798 eee->advertised = advertising & eee->supported;
5805 static int bnxt_update_phy_setting(struct bnxt *bp)
5808 bool update_link = false;
5809 bool update_pause = false;
5810 bool update_eee = false;
5811 struct bnxt_link_info *link_info = &bp->link_info;
5813 rc = bnxt_update_link(bp, true);
5815 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
5819 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
5820 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
5821 link_info->req_flow_ctrl)
5822 update_pause = true;
5823 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
5824 link_info->force_pause_setting != link_info->req_flow_ctrl)
5825 update_pause = true;
5826 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
5827 if (BNXT_AUTO_MODE(link_info->auto_mode))
5829 if (link_info->req_link_speed != link_info->force_link_speed)
5831 if (link_info->req_duplex != link_info->duplex_setting)
5834 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
5836 if (link_info->advertising != link_info->auto_link_speeds)
5840 /* The last close may have shutdown the link, so need to call
5841 * PHY_CFG to bring it back up.
5843 if (!netif_carrier_ok(bp->dev))
5846 if (!bnxt_eee_config_ok(bp))
5850 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
5851 else if (update_pause)
5852 rc = bnxt_hwrm_set_pause(bp);
5854 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
5862 /* Common routine to pre-map certain register block to different GRC window.
5863 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
5864 * in PF and 3 windows in VF that can be customized to map in different
5867 static void bnxt_preset_reg_win(struct bnxt *bp)
5870 /* CAG registers map to GRC window #4 */
5871 writel(BNXT_CAG_REG_BASE,
5872 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
5876 static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
5880 bnxt_preset_reg_win(bp);
5881 netif_carrier_off(bp->dev);
5883 rc = bnxt_setup_int_mode(bp);
5885 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
5890 if ((bp->flags & BNXT_FLAG_RFS) &&
5891 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
5892 /* disable RFS if falling back to INTA */
5893 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
5894 bp->flags &= ~BNXT_FLAG_RFS;
5897 rc = bnxt_alloc_mem(bp, irq_re_init);
5899 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
5900 goto open_err_free_mem;
5905 rc = bnxt_request_irq(bp);
5907 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
5912 bnxt_enable_napi(bp);
5914 rc = bnxt_init_nic(bp, irq_re_init);
5916 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
5921 rc = bnxt_update_phy_setting(bp);
5923 netdev_warn(bp->dev, "failed to update phy settings\n");
5927 udp_tunnel_get_rx_info(bp->dev);
5929 set_bit(BNXT_STATE_OPEN, &bp->state);
5930 bnxt_enable_int(bp);
5931 /* Enable TX queues */
5933 mod_timer(&bp->timer, jiffies + bp->current_interval);
5934 /* Poll link status and check for SFP+ module status */
5935 bnxt_get_port_module_status(bp);
5940 bnxt_disable_napi(bp);
5946 bnxt_free_mem(bp, true);
5950 /* rtnl_lock held */
5951 int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
5955 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
5957 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
5963 static int bnxt_open(struct net_device *dev)
5965 struct bnxt *bp = netdev_priv(dev);
5967 return __bnxt_open_nic(bp, true, true);
5970 int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
5974 #ifdef CONFIG_BNXT_SRIOV
5975 if (bp->sriov_cfg) {
5976 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
5978 BNXT_SRIOV_CFG_WAIT_TMO);
5980 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
5983 /* Change device state to avoid TX queue wake up's */
5984 bnxt_tx_disable(bp);
5986 clear_bit(BNXT_STATE_OPEN, &bp->state);
5987 smp_mb__after_atomic();
5988 while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state))
5991 /* Flush rings and and disable interrupts */
5992 bnxt_shutdown_nic(bp, irq_re_init);
5994 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
5996 bnxt_disable_napi(bp);
5997 del_timer_sync(&bp->timer);
6004 bnxt_free_mem(bp, irq_re_init);
6008 static int bnxt_close(struct net_device *dev)
6010 struct bnxt *bp = netdev_priv(dev);
6012 bnxt_close_nic(bp, true, true);
6013 bnxt_hwrm_shutdown_link(bp);
6017 /* rtnl_lock held */
6018 static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6024 if (!netif_running(dev))
6031 if (!netif_running(dev))
6044 bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6047 struct bnxt *bp = netdev_priv(dev);
6052 /* TODO check if we need to synchronize with bnxt_close path */
6053 for (i = 0; i < bp->cp_nr_rings; i++) {
6054 struct bnxt_napi *bnapi = bp->bnapi[i];
6055 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6056 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
6058 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
6059 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
6060 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
6062 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
6063 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
6064 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
6066 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
6067 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
6068 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
6070 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
6071 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
6072 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
6074 stats->rx_missed_errors +=
6075 le64_to_cpu(hw_stats->rx_discard_pkts);
6077 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
6079 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
6082 if (bp->flags & BNXT_FLAG_PORT_STATS) {
6083 struct rx_port_stats *rx = bp->hw_rx_port_stats;
6084 struct tx_port_stats *tx = bp->hw_tx_port_stats;
6086 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
6087 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
6088 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
6089 le64_to_cpu(rx->rx_ovrsz_frames) +
6090 le64_to_cpu(rx->rx_runt_frames);
6091 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
6092 le64_to_cpu(rx->rx_jbr_frames);
6093 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
6094 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
6095 stats->tx_errors = le64_to_cpu(tx->tx_err);
6099 static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
6101 struct net_device *dev = bp->dev;
6102 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6103 struct netdev_hw_addr *ha;
6106 bool update = false;
6109 netdev_for_each_mc_addr(ha, dev) {
6110 if (mc_count >= BNXT_MAX_MC_ADDRS) {
6111 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6112 vnic->mc_list_count = 0;
6116 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
6117 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
6124 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
6126 if (mc_count != vnic->mc_list_count) {
6127 vnic->mc_list_count = mc_count;
6133 static bool bnxt_uc_list_updated(struct bnxt *bp)
6135 struct net_device *dev = bp->dev;
6136 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6137 struct netdev_hw_addr *ha;
6140 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
6143 netdev_for_each_uc_addr(ha, dev) {
6144 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
6152 static void bnxt_set_rx_mode(struct net_device *dev)
6154 struct bnxt *bp = netdev_priv(dev);
6155 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6156 u32 mask = vnic->rx_mask;
6157 bool mc_update = false;
6160 if (!netif_running(dev))
6163 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
6164 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
6165 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
6167 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
6168 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6170 uc_update = bnxt_uc_list_updated(bp);
6172 if (dev->flags & IFF_ALLMULTI) {
6173 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6174 vnic->mc_list_count = 0;
6176 mc_update = bnxt_mc_list_updated(bp, &mask);
6179 if (mask != vnic->rx_mask || uc_update || mc_update) {
6180 vnic->rx_mask = mask;
6182 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
6183 schedule_work(&bp->sp_task);
6187 static int bnxt_cfg_rx_mode(struct bnxt *bp)
6189 struct net_device *dev = bp->dev;
6190 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6191 struct netdev_hw_addr *ha;
6195 netif_addr_lock_bh(dev);
6196 uc_update = bnxt_uc_list_updated(bp);
6197 netif_addr_unlock_bh(dev);
6202 mutex_lock(&bp->hwrm_cmd_lock);
6203 for (i = 1; i < vnic->uc_filter_count; i++) {
6204 struct hwrm_cfa_l2_filter_free_input req = {0};
6206 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
6209 req.l2_filter_id = vnic->fw_l2_filter_id[i];
6211 rc = _hwrm_send_message(bp, &req, sizeof(req),
6214 mutex_unlock(&bp->hwrm_cmd_lock);
6216 vnic->uc_filter_count = 1;
6218 netif_addr_lock_bh(dev);
6219 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
6220 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6222 netdev_for_each_uc_addr(ha, dev) {
6223 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
6225 vnic->uc_filter_count++;
6228 netif_addr_unlock_bh(dev);
6230 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
6231 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
6233 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
6235 vnic->uc_filter_count = i;
6241 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
6243 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
6249 /* If the chip and firmware supports RFS */
6250 static bool bnxt_rfs_supported(struct bnxt *bp)
6252 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
6254 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6259 /* If runtime conditions support RFS */
6260 static bool bnxt_rfs_capable(struct bnxt *bp)
6262 #ifdef CONFIG_RFS_ACCEL
6263 int vnics, max_vnics, max_rss_ctxs;
6265 if (BNXT_VF(bp) || !(bp->flags & BNXT_FLAG_MSIX_CAP))
6268 vnics = 1 + bp->rx_nr_rings;
6269 max_vnics = bnxt_get_max_func_vnics(bp);
6270 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
6272 /* RSS contexts not a limiting factor */
6273 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6274 max_rss_ctxs = max_vnics;
6275 if (vnics > max_vnics || vnics > max_rss_ctxs) {
6276 netdev_warn(bp->dev,
6277 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
6278 min(max_rss_ctxs - 1, max_vnics - 1));
6288 static netdev_features_t bnxt_fix_features(struct net_device *dev,
6289 netdev_features_t features)
6291 struct bnxt *bp = netdev_priv(dev);
6293 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
6294 features &= ~NETIF_F_NTUPLE;
6296 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
6297 * turned on or off together.
6299 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
6300 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
6301 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
6302 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6303 NETIF_F_HW_VLAN_STAG_RX);
6305 features |= NETIF_F_HW_VLAN_CTAG_RX |
6306 NETIF_F_HW_VLAN_STAG_RX;
6308 #ifdef CONFIG_BNXT_SRIOV
6311 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6312 NETIF_F_HW_VLAN_STAG_RX);
6319 static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
6321 struct bnxt *bp = netdev_priv(dev);
6322 u32 flags = bp->flags;
6325 bool re_init = false;
6326 bool update_tpa = false;
6328 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
6329 if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
6330 flags |= BNXT_FLAG_GRO;
6331 if (features & NETIF_F_LRO)
6332 flags |= BNXT_FLAG_LRO;
6334 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
6335 flags &= ~BNXT_FLAG_TPA;
6337 if (features & NETIF_F_HW_VLAN_CTAG_RX)
6338 flags |= BNXT_FLAG_STRIP_VLAN;
6340 if (features & NETIF_F_NTUPLE)
6341 flags |= BNXT_FLAG_RFS;
6343 changes = flags ^ bp->flags;
6344 if (changes & BNXT_FLAG_TPA) {
6346 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
6347 (flags & BNXT_FLAG_TPA) == 0)
6351 if (changes & ~BNXT_FLAG_TPA)
6354 if (flags != bp->flags) {
6355 u32 old_flags = bp->flags;
6359 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6361 bnxt_set_ring_params(bp);
6366 bnxt_close_nic(bp, false, false);
6368 bnxt_set_ring_params(bp);
6370 return bnxt_open_nic(bp, false, false);
6373 rc = bnxt_set_tpa(bp,
6374 (flags & BNXT_FLAG_TPA) ?
6377 bp->flags = old_flags;
6383 static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
6385 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
6386 int i = bnapi->index;
6391 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
6392 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
6396 static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
6398 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
6399 int i = bnapi->index;
6404 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",
6405 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
6406 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
6407 rxr->rx_sw_agg_prod);
6410 static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
6412 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6413 int i = bnapi->index;
6415 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
6416 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
6419 static void bnxt_dbg_dump_states(struct bnxt *bp)
6422 struct bnxt_napi *bnapi;
6424 for (i = 0; i < bp->cp_nr_rings; i++) {
6425 bnapi = bp->bnapi[i];
6426 if (netif_msg_drv(bp)) {
6427 bnxt_dump_tx_sw_state(bnapi);
6428 bnxt_dump_rx_sw_state(bnapi);
6429 bnxt_dump_cp_sw_state(bnapi);
6434 static void bnxt_reset_task(struct bnxt *bp, bool silent)
6437 bnxt_dbg_dump_states(bp);
6438 if (netif_running(bp->dev)) {
6439 bnxt_close_nic(bp, false, false);
6440 bnxt_open_nic(bp, false, false);
6444 static void bnxt_tx_timeout(struct net_device *dev)
6446 struct bnxt *bp = netdev_priv(dev);
6448 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
6449 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
6450 schedule_work(&bp->sp_task);
6453 #ifdef CONFIG_NET_POLL_CONTROLLER
6454 static void bnxt_poll_controller(struct net_device *dev)
6456 struct bnxt *bp = netdev_priv(dev);
6459 for (i = 0; i < bp->cp_nr_rings; i++) {
6460 struct bnxt_irq *irq = &bp->irq_tbl[i];
6462 disable_irq(irq->vector);
6463 irq->handler(irq->vector, bp->bnapi[i]);
6464 enable_irq(irq->vector);
6469 static void bnxt_timer(unsigned long data)
6471 struct bnxt *bp = (struct bnxt *)data;
6472 struct net_device *dev = bp->dev;
6474 if (!netif_running(dev))
6477 if (atomic_read(&bp->intr_sem) != 0)
6478 goto bnxt_restart_timer;
6480 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) {
6481 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
6482 schedule_work(&bp->sp_task);
6485 mod_timer(&bp->timer, jiffies + bp->current_interval);
6488 static void bnxt_rtnl_lock_sp(struct bnxt *bp)
6490 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
6491 * set. If the device is being closed, bnxt_close() may be holding
6492 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
6493 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
6495 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6499 static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
6501 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6505 /* Only called from bnxt_sp_task() */
6506 static void bnxt_reset(struct bnxt *bp, bool silent)
6508 bnxt_rtnl_lock_sp(bp);
6509 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6510 bnxt_reset_task(bp, silent);
6511 bnxt_rtnl_unlock_sp(bp);
6514 static void bnxt_cfg_ntp_filters(struct bnxt *);
6516 static void bnxt_sp_task(struct work_struct *work)
6518 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
6520 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6521 smp_mb__after_atomic();
6522 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6523 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6527 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
6528 bnxt_cfg_rx_mode(bp);
6530 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
6531 bnxt_cfg_ntp_filters(bp);
6532 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
6533 bnxt_hwrm_exec_fwd_req(bp);
6534 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6535 bnxt_hwrm_tunnel_dst_port_alloc(
6537 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6539 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6540 bnxt_hwrm_tunnel_dst_port_free(
6541 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6543 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6544 bnxt_hwrm_tunnel_dst_port_alloc(
6546 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6548 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6549 bnxt_hwrm_tunnel_dst_port_free(
6550 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6552 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event))
6553 bnxt_hwrm_port_qstats(bp);
6555 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
6556 * must be the last functions to be called before exiting.
6558 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
6561 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
6563 bnxt_hwrm_phy_qcaps(bp);
6565 bnxt_rtnl_lock_sp(bp);
6566 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6567 rc = bnxt_update_link(bp, true);
6568 bnxt_rtnl_unlock_sp(bp);
6570 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
6573 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
6574 bnxt_rtnl_lock_sp(bp);
6575 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6576 bnxt_get_port_module_status(bp);
6577 bnxt_rtnl_unlock_sp(bp);
6579 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
6580 bnxt_reset(bp, false);
6582 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
6583 bnxt_reset(bp, true);
6585 smp_mb__before_atomic();
6586 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6589 /* Under rtnl_lock */
6590 int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, int tcs, int tx_xdp)
6592 int max_rx, max_tx, tx_sets = 1;
6593 int tx_rings_needed;
6597 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
6603 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
6610 tx_rings_needed = tx * tx_sets + tx_xdp;
6611 if (max_tx < tx_rings_needed)
6614 if (bnxt_hwrm_reserve_tx_rings(bp, &tx_rings_needed) ||
6615 tx_rings_needed < (tx * tx_sets + tx_xdp))
6620 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
6623 struct bnxt *bp = netdev_priv(dev);
6625 SET_NETDEV_DEV(dev, &pdev->dev);
6627 /* enable device (incl. PCI PM wakeup), and bus-mastering */
6628 rc = pci_enable_device(pdev);
6630 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
6634 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
6636 "Cannot find PCI device base address, aborting\n");
6638 goto init_err_disable;
6641 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
6643 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
6644 goto init_err_disable;
6647 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
6648 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
6649 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
6650 goto init_err_disable;
6653 pci_set_master(pdev);
6658 bp->bar0 = pci_ioremap_bar(pdev, 0);
6660 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
6662 goto init_err_release;
6665 bp->bar1 = pci_ioremap_bar(pdev, 2);
6667 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
6669 goto init_err_release;
6672 bp->bar2 = pci_ioremap_bar(pdev, 4);
6674 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
6676 goto init_err_release;
6679 pci_enable_pcie_error_reporting(pdev);
6681 INIT_WORK(&bp->sp_task, bnxt_sp_task);
6683 spin_lock_init(&bp->ntp_fltr_lock);
6685 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
6686 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
6688 /* tick values in micro seconds */
6689 bp->rx_coal_ticks = 12;
6690 bp->rx_coal_bufs = 30;
6691 bp->rx_coal_ticks_irq = 1;
6692 bp->rx_coal_bufs_irq = 2;
6694 bp->tx_coal_ticks = 25;
6695 bp->tx_coal_bufs = 30;
6696 bp->tx_coal_ticks_irq = 2;
6697 bp->tx_coal_bufs_irq = 2;
6699 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
6701 init_timer(&bp->timer);
6702 bp->timer.data = (unsigned long)bp;
6703 bp->timer.function = bnxt_timer;
6704 bp->current_interval = BNXT_TIMER_INTERVAL;
6706 clear_bit(BNXT_STATE_OPEN, &bp->state);
6712 pci_iounmap(pdev, bp->bar2);
6717 pci_iounmap(pdev, bp->bar1);
6722 pci_iounmap(pdev, bp->bar0);
6726 pci_release_regions(pdev);
6729 pci_disable_device(pdev);
6735 /* rtnl_lock held */
6736 static int bnxt_change_mac_addr(struct net_device *dev, void *p)
6738 struct sockaddr *addr = p;
6739 struct bnxt *bp = netdev_priv(dev);
6742 if (!is_valid_ether_addr(addr->sa_data))
6743 return -EADDRNOTAVAIL;
6745 rc = bnxt_approve_mac(bp, addr->sa_data);
6749 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
6752 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
6753 if (netif_running(dev)) {
6754 bnxt_close_nic(bp, false, false);
6755 rc = bnxt_open_nic(bp, false, false);
6761 /* rtnl_lock held */
6762 static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
6764 struct bnxt *bp = netdev_priv(dev);
6766 if (netif_running(dev))
6767 bnxt_close_nic(bp, false, false);
6770 bnxt_set_ring_params(bp);
6772 if (netif_running(dev))
6773 return bnxt_open_nic(bp, false, false);
6778 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
6780 struct bnxt *bp = netdev_priv(dev);
6784 if (tc > bp->max_tc) {
6785 netdev_err(dev, "too many traffic classes requested: %d Max supported is %d\n",
6790 if (netdev_get_num_tc(dev) == tc)
6793 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
6796 rc = bnxt_reserve_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
6797 tc, bp->tx_nr_rings_xdp);
6801 /* Needs to close the device and do hw resource re-allocations */
6802 if (netif_running(bp->dev))
6803 bnxt_close_nic(bp, true, false);
6806 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
6807 netdev_set_num_tc(dev, tc);
6809 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
6810 netdev_reset_tc(dev);
6812 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
6813 bp->tx_nr_rings + bp->rx_nr_rings;
6814 bp->num_stat_ctxs = bp->cp_nr_rings;
6816 if (netif_running(bp->dev))
6817 return bnxt_open_nic(bp, true, false);
6822 static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
6823 struct tc_to_netdev *ntc)
6825 if (ntc->type != TC_SETUP_MQPRIO)
6828 return bnxt_setup_mq_tc(dev, ntc->tc);
6831 #ifdef CONFIG_RFS_ACCEL
6832 static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
6833 struct bnxt_ntuple_filter *f2)
6835 struct flow_keys *keys1 = &f1->fkeys;
6836 struct flow_keys *keys2 = &f2->fkeys;
6838 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
6839 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
6840 keys1->ports.ports == keys2->ports.ports &&
6841 keys1->basic.ip_proto == keys2->basic.ip_proto &&
6842 keys1->basic.n_proto == keys2->basic.n_proto &&
6843 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
6844 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
6850 static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
6851 u16 rxq_index, u32 flow_id)
6853 struct bnxt *bp = netdev_priv(dev);
6854 struct bnxt_ntuple_filter *fltr, *new_fltr;
6855 struct flow_keys *fkeys;
6856 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
6857 int rc = 0, idx, bit_id, l2_idx = 0;
6858 struct hlist_head *head;
6860 if (skb->encapsulation)
6861 return -EPROTONOSUPPORT;
6863 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
6864 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6867 netif_addr_lock_bh(dev);
6868 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
6869 if (ether_addr_equal(eth->h_dest,
6870 vnic->uc_list + off)) {
6875 netif_addr_unlock_bh(dev);
6879 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
6883 fkeys = &new_fltr->fkeys;
6884 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
6885 rc = -EPROTONOSUPPORT;
6889 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
6890 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
6891 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
6892 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
6893 rc = -EPROTONOSUPPORT;
6896 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
6897 bp->hwrm_spec_code < 0x10601) {
6898 rc = -EPROTONOSUPPORT;
6902 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
6903 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
6905 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
6906 head = &bp->ntp_fltr_hash_tbl[idx];
6908 hlist_for_each_entry_rcu(fltr, head, hash) {
6909 if (bnxt_fltr_match(fltr, new_fltr)) {
6917 spin_lock_bh(&bp->ntp_fltr_lock);
6918 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
6919 BNXT_NTP_FLTR_MAX_FLTR, 0);
6921 spin_unlock_bh(&bp->ntp_fltr_lock);
6926 new_fltr->sw_id = (u16)bit_id;
6927 new_fltr->flow_id = flow_id;
6928 new_fltr->l2_fltr_idx = l2_idx;
6929 new_fltr->rxq = rxq_index;
6930 hlist_add_head_rcu(&new_fltr->hash, head);
6931 bp->ntp_fltr_count++;
6932 spin_unlock_bh(&bp->ntp_fltr_lock);
6934 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
6935 schedule_work(&bp->sp_task);
6937 return new_fltr->sw_id;
6944 static void bnxt_cfg_ntp_filters(struct bnxt *bp)
6948 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
6949 struct hlist_head *head;
6950 struct hlist_node *tmp;
6951 struct bnxt_ntuple_filter *fltr;
6954 head = &bp->ntp_fltr_hash_tbl[i];
6955 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
6958 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
6959 if (rps_may_expire_flow(bp->dev, fltr->rxq,
6962 bnxt_hwrm_cfa_ntuple_filter_free(bp,
6967 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
6972 set_bit(BNXT_FLTR_VALID, &fltr->state);
6976 spin_lock_bh(&bp->ntp_fltr_lock);
6977 hlist_del_rcu(&fltr->hash);
6978 bp->ntp_fltr_count--;
6979 spin_unlock_bh(&bp->ntp_fltr_lock);
6981 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
6986 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
6987 netdev_info(bp->dev, "Receive PF driver unload event!");
6992 static void bnxt_cfg_ntp_filters(struct bnxt *bp)
6996 #endif /* CONFIG_RFS_ACCEL */
6998 static void bnxt_udp_tunnel_add(struct net_device *dev,
6999 struct udp_tunnel_info *ti)
7001 struct bnxt *bp = netdev_priv(dev);
7003 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7006 if (!netif_running(dev))
7010 case UDP_TUNNEL_TYPE_VXLAN:
7011 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
7014 bp->vxlan_port_cnt++;
7015 if (bp->vxlan_port_cnt == 1) {
7016 bp->vxlan_port = ti->port;
7017 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
7018 schedule_work(&bp->sp_task);
7021 case UDP_TUNNEL_TYPE_GENEVE:
7022 if (bp->nge_port_cnt && bp->nge_port != ti->port)
7026 if (bp->nge_port_cnt == 1) {
7027 bp->nge_port = ti->port;
7028 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
7035 schedule_work(&bp->sp_task);
7038 static void bnxt_udp_tunnel_del(struct net_device *dev,
7039 struct udp_tunnel_info *ti)
7041 struct bnxt *bp = netdev_priv(dev);
7043 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7046 if (!netif_running(dev))
7050 case UDP_TUNNEL_TYPE_VXLAN:
7051 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
7053 bp->vxlan_port_cnt--;
7055 if (bp->vxlan_port_cnt != 0)
7058 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
7060 case UDP_TUNNEL_TYPE_GENEVE:
7061 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
7065 if (bp->nge_port_cnt != 0)
7068 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
7074 schedule_work(&bp->sp_task);
7077 static const struct net_device_ops bnxt_netdev_ops = {
7078 .ndo_open = bnxt_open,
7079 .ndo_start_xmit = bnxt_start_xmit,
7080 .ndo_stop = bnxt_close,
7081 .ndo_get_stats64 = bnxt_get_stats64,
7082 .ndo_set_rx_mode = bnxt_set_rx_mode,
7083 .ndo_do_ioctl = bnxt_ioctl,
7084 .ndo_validate_addr = eth_validate_addr,
7085 .ndo_set_mac_address = bnxt_change_mac_addr,
7086 .ndo_change_mtu = bnxt_change_mtu,
7087 .ndo_fix_features = bnxt_fix_features,
7088 .ndo_set_features = bnxt_set_features,
7089 .ndo_tx_timeout = bnxt_tx_timeout,
7090 #ifdef CONFIG_BNXT_SRIOV
7091 .ndo_get_vf_config = bnxt_get_vf_config,
7092 .ndo_set_vf_mac = bnxt_set_vf_mac,
7093 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
7094 .ndo_set_vf_rate = bnxt_set_vf_bw,
7095 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
7096 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
7098 #ifdef CONFIG_NET_POLL_CONTROLLER
7099 .ndo_poll_controller = bnxt_poll_controller,
7101 .ndo_setup_tc = bnxt_setup_tc,
7102 #ifdef CONFIG_RFS_ACCEL
7103 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
7105 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
7106 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
7109 static void bnxt_remove_one(struct pci_dev *pdev)
7111 struct net_device *dev = pci_get_drvdata(pdev);
7112 struct bnxt *bp = netdev_priv(dev);
7115 bnxt_sriov_disable(bp);
7117 pci_disable_pcie_error_reporting(pdev);
7118 unregister_netdev(dev);
7119 cancel_work_sync(&bp->sp_task);
7122 bnxt_clear_int_mode(bp);
7123 bnxt_hwrm_func_drv_unrgtr(bp);
7124 bnxt_free_hwrm_resources(bp);
7126 pci_iounmap(pdev, bp->bar2);
7127 pci_iounmap(pdev, bp->bar1);
7128 pci_iounmap(pdev, bp->bar0);
7133 pci_release_regions(pdev);
7134 pci_disable_device(pdev);
7137 static int bnxt_probe_phy(struct bnxt *bp)
7140 struct bnxt_link_info *link_info = &bp->link_info;
7142 rc = bnxt_hwrm_phy_qcaps(bp);
7144 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
7149 rc = bnxt_update_link(bp, false);
7151 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
7156 /* Older firmware does not have supported_auto_speeds, so assume
7157 * that all supported speeds can be autonegotiated.
7159 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
7160 link_info->support_auto_speeds = link_info->support_speeds;
7162 /*initialize the ethool setting copy with NVM settings */
7163 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
7164 link_info->autoneg = BNXT_AUTONEG_SPEED;
7165 if (bp->hwrm_spec_code >= 0x10201) {
7166 if (link_info->auto_pause_setting &
7167 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
7168 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7170 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7172 link_info->advertising = link_info->auto_link_speeds;
7174 link_info->req_link_speed = link_info->force_link_speed;
7175 link_info->req_duplex = link_info->duplex_setting;
7177 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
7178 link_info->req_flow_ctrl =
7179 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
7181 link_info->req_flow_ctrl = link_info->force_pause_setting;
7185 static int bnxt_get_max_irq(struct pci_dev *pdev)
7189 if (!pdev->msix_cap)
7192 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
7193 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
7196 static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7199 int max_ring_grps = 0;
7201 #ifdef CONFIG_BNXT_SRIOV
7203 *max_tx = bp->vf.max_tx_rings;
7204 *max_rx = bp->vf.max_rx_rings;
7205 *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings);
7206 *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs);
7207 max_ring_grps = bp->vf.max_hw_ring_grps;
7211 *max_tx = bp->pf.max_tx_rings;
7212 *max_rx = bp->pf.max_rx_rings;
7213 *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings);
7214 *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs);
7215 max_ring_grps = bp->pf.max_hw_ring_grps;
7217 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
7221 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7223 *max_rx = min_t(int, *max_rx, max_ring_grps);
7226 int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
7230 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
7231 if (!rx || !tx || !cp)
7236 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
7239 static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7244 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
7245 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
7246 /* Not enough rings, try disabling agg rings. */
7247 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
7248 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
7251 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
7252 bp->dev->hw_features &= ~NETIF_F_LRO;
7253 bp->dev->features &= ~NETIF_F_LRO;
7254 bnxt_set_ring_params(bp);
7257 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
7258 int max_cp, max_stat, max_irq;
7260 /* Reserve minimum resources for RoCE */
7261 max_cp = bnxt_get_max_func_cp_rings(bp);
7262 max_stat = bnxt_get_max_func_stat_ctxs(bp);
7263 max_irq = bnxt_get_max_func_irqs(bp);
7264 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
7265 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
7266 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
7269 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
7270 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
7271 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
7272 max_cp = min_t(int, max_cp, max_irq);
7273 max_cp = min_t(int, max_cp, max_stat);
7274 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
7281 static int bnxt_set_dflt_rings(struct bnxt *bp)
7283 int dflt_rings, max_rx_rings, max_tx_rings, rc;
7287 bp->flags |= BNXT_FLAG_SHARED_RINGS;
7288 dflt_rings = netif_get_num_default_rss_queues();
7289 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
7292 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
7293 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
7295 rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc);
7297 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
7299 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7300 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7301 bp->tx_nr_rings + bp->rx_nr_rings;
7302 bp->num_stat_ctxs = bp->cp_nr_rings;
7303 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
7310 void bnxt_restore_pf_fw_resources(struct bnxt *bp)
7313 bnxt_hwrm_func_qcaps(bp);
7314 bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP);
7317 static void bnxt_parse_log_pcie_link(struct bnxt *bp)
7319 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
7320 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
7322 if (pcie_get_minimum_link(bp->pdev, &speed, &width) ||
7323 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
7324 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
7326 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
7327 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
7328 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
7329 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
7333 static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7335 static int version_printed;
7336 struct net_device *dev;
7340 if (pdev->device == 0x16cd && pci_is_bridge(pdev))
7343 if (version_printed++ == 0)
7344 pr_info("%s", version);
7346 max_irqs = bnxt_get_max_irq(pdev);
7347 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
7351 bp = netdev_priv(dev);
7353 if (bnxt_vf_pciid(ent->driver_data))
7354 bp->flags |= BNXT_FLAG_VF;
7357 bp->flags |= BNXT_FLAG_MSIX_CAP;
7359 rc = bnxt_init_board(pdev, dev);
7363 dev->netdev_ops = &bnxt_netdev_ops;
7364 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
7365 dev->ethtool_ops = &bnxt_ethtool_ops;
7367 pci_set_drvdata(pdev, dev);
7369 rc = bnxt_alloc_hwrm_resources(bp);
7373 mutex_init(&bp->hwrm_cmd_lock);
7374 rc = bnxt_hwrm_ver_get(bp);
7378 bnxt_hwrm_fw_set_time(bp);
7380 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7381 NETIF_F_TSO | NETIF_F_TSO6 |
7382 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
7383 NETIF_F_GSO_IPXIP4 |
7384 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7385 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
7386 NETIF_F_RXCSUM | NETIF_F_GRO;
7388 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
7389 dev->hw_features |= NETIF_F_LRO;
7391 dev->hw_enc_features =
7392 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7393 NETIF_F_TSO | NETIF_F_TSO6 |
7394 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
7395 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7396 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
7397 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
7398 NETIF_F_GSO_GRE_CSUM;
7399 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
7400 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7401 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
7402 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
7403 dev->priv_flags |= IFF_UNICAST_FLT;
7405 /* MTU range: 60 - 9500 */
7406 dev->min_mtu = ETH_ZLEN;
7407 dev->max_mtu = BNXT_MAX_MTU;
7411 #ifdef CONFIG_BNXT_SRIOV
7412 init_waitqueue_head(&bp->sriov_cfg_wait);
7414 bp->gro_func = bnxt_gro_func_5730x;
7415 if (BNXT_CHIP_NUM_57X1X(bp->chip_num))
7416 bp->gro_func = bnxt_gro_func_5731x;
7418 rc = bnxt_hwrm_func_drv_rgtr(bp);
7422 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
7426 bp->ulp_probe = bnxt_ulp_probe;
7428 /* Get the MAX capabilities for this function */
7429 rc = bnxt_hwrm_func_qcaps(bp);
7431 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
7437 rc = bnxt_hwrm_queue_qportcfg(bp);
7439 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
7445 bnxt_hwrm_func_qcfg(bp);
7446 bnxt_hwrm_port_led_qcaps(bp);
7448 bnxt_set_rx_skb_mode(bp, false);
7449 bnxt_set_tpa_flags(bp);
7450 bnxt_set_ring_params(bp);
7451 bnxt_set_max_func_irqs(bp, max_irqs);
7452 rc = bnxt_set_dflt_rings(bp);
7454 netdev_err(bp->dev, "Not enough rings available.\n");
7459 /* Default RSS hash cfg. */
7460 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
7461 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
7462 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
7463 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
7464 if (!BNXT_CHIP_NUM_57X0X(bp->chip_num) &&
7465 !BNXT_CHIP_TYPE_NITRO_A0(bp) &&
7466 bp->hwrm_spec_code >= 0x10501) {
7467 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
7468 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
7469 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
7472 bnxt_hwrm_vnic_qcaps(bp);
7473 if (bnxt_rfs_supported(bp)) {
7474 dev->hw_features |= NETIF_F_NTUPLE;
7475 if (bnxt_rfs_capable(bp)) {
7476 bp->flags |= BNXT_FLAG_RFS;
7477 dev->features |= NETIF_F_NTUPLE;
7481 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
7482 bp->flags |= BNXT_FLAG_STRIP_VLAN;
7484 rc = bnxt_probe_phy(bp);
7488 rc = bnxt_hwrm_func_reset(bp);
7492 rc = bnxt_init_int_mode(bp);
7496 rc = register_netdev(dev);
7498 goto init_err_clr_int;
7500 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
7501 board_info[ent->driver_data].name,
7502 (long)pci_resource_start(pdev, 0), dev->dev_addr);
7504 bnxt_parse_log_pcie_link(bp);
7509 bnxt_clear_int_mode(bp);
7512 pci_iounmap(pdev, bp->bar0);
7513 pci_release_regions(pdev);
7514 pci_disable_device(pdev);
7522 * bnxt_io_error_detected - called when PCI error is detected
7523 * @pdev: Pointer to PCI device
7524 * @state: The current pci connection state
7526 * This function is called after a PCI bus error affecting
7527 * this device has been detected.
7529 static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
7530 pci_channel_state_t state)
7532 struct net_device *netdev = pci_get_drvdata(pdev);
7533 struct bnxt *bp = netdev_priv(netdev);
7535 netdev_info(netdev, "PCI I/O error detected\n");
7538 netif_device_detach(netdev);
7542 if (state == pci_channel_io_perm_failure) {
7544 return PCI_ERS_RESULT_DISCONNECT;
7547 if (netif_running(netdev))
7550 pci_disable_device(pdev);
7553 /* Request a slot slot reset. */
7554 return PCI_ERS_RESULT_NEED_RESET;
7558 * bnxt_io_slot_reset - called after the pci bus has been reset.
7559 * @pdev: Pointer to PCI device
7561 * Restart the card from scratch, as if from a cold-boot.
7562 * At this point, the card has exprienced a hard reset,
7563 * followed by fixups by BIOS, and has its config space
7564 * set up identically to what it was at cold boot.
7566 static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
7568 struct net_device *netdev = pci_get_drvdata(pdev);
7569 struct bnxt *bp = netdev_priv(netdev);
7571 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
7573 netdev_info(bp->dev, "PCI Slot Reset\n");
7577 if (pci_enable_device(pdev)) {
7579 "Cannot re-enable PCI device after reset.\n");
7581 pci_set_master(pdev);
7583 err = bnxt_hwrm_func_reset(bp);
7584 if (!err && netif_running(netdev))
7585 err = bnxt_open(netdev);
7588 result = PCI_ERS_RESULT_RECOVERED;
7593 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
7598 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7601 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
7602 err); /* non-fatal, continue */
7605 return PCI_ERS_RESULT_RECOVERED;
7609 * bnxt_io_resume - called when traffic can start flowing again.
7610 * @pdev: Pointer to PCI device
7612 * This callback is called when the error recovery driver tells
7613 * us that its OK to resume normal operation.
7615 static void bnxt_io_resume(struct pci_dev *pdev)
7617 struct net_device *netdev = pci_get_drvdata(pdev);
7621 netif_device_attach(netdev);
7626 static const struct pci_error_handlers bnxt_err_handler = {
7627 .error_detected = bnxt_io_error_detected,
7628 .slot_reset = bnxt_io_slot_reset,
7629 .resume = bnxt_io_resume
7632 static struct pci_driver bnxt_pci_driver = {
7633 .name = DRV_MODULE_NAME,
7634 .id_table = bnxt_pci_tbl,
7635 .probe = bnxt_init_one,
7636 .remove = bnxt_remove_one,
7637 .err_handler = &bnxt_err_handler,
7638 #if defined(CONFIG_BNXT_SRIOV)
7639 .sriov_configure = bnxt_sriov_configure,
7643 module_pci_driver(bnxt_pci_driver);