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>
38 #include <net/checksum.h>
39 #include <net/ip6_checksum.h>
40 #if defined(CONFIG_VXLAN) || defined(CONFIG_VXLAN_MODULE)
41 #include <net/vxlan.h>
43 #ifdef CONFIG_NET_RX_BUSY_POLL
44 #include <net/busy_poll.h>
46 #include <linux/workqueue.h>
47 #include <linux/prefetch.h>
48 #include <linux/cache.h>
49 #include <linux/log2.h>
50 #include <linux/aer.h>
51 #include <linux/bitmap.h>
52 #include <linux/cpu_rmap.h>
56 #include "bnxt_sriov.h"
57 #include "bnxt_ethtool.h"
59 #define BNXT_TX_TIMEOUT (5 * HZ)
61 static const char version
[] =
62 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME
" v" DRV_MODULE_VERSION
"\n";
64 MODULE_LICENSE("GPL");
65 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
66 MODULE_VERSION(DRV_MODULE_VERSION
);
68 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
69 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
70 #define BNXT_RX_COPY_THRESH 256
72 #define BNXT_TX_PUSH_THRESH 164
85 /* indexed by enum above */
89 { "Broadcom BCM57301 NetXtreme-C Single-port 10Gb Ethernet" },
90 { "Broadcom BCM57302 NetXtreme-C Dual-port 10Gb/25Gb Ethernet" },
91 { "Broadcom BCM57304 NetXtreme-C Dual-port 10Gb/25Gb/40Gb/50Gb Ethernet" },
92 { "Broadcom BCM57402 NetXtreme-E Dual-port 10Gb Ethernet" },
93 { "Broadcom BCM57404 NetXtreme-E Dual-port 10Gb/25Gb Ethernet" },
94 { "Broadcom BCM57406 NetXtreme-E Dual-port 10GBase-T Ethernet" },
95 { "Broadcom BCM57304 NetXtreme-C Ethernet Virtual Function" },
96 { "Broadcom BCM57404 NetXtreme-E Ethernet Virtual Function" },
99 static const struct pci_device_id bnxt_pci_tbl
[] = {
100 { PCI_VDEVICE(BROADCOM
, 0x16c8), .driver_data
= BCM57301
},
101 { PCI_VDEVICE(BROADCOM
, 0x16c9), .driver_data
= BCM57302
},
102 { PCI_VDEVICE(BROADCOM
, 0x16ca), .driver_data
= BCM57304
},
103 { PCI_VDEVICE(BROADCOM
, 0x16d0), .driver_data
= BCM57402
},
104 { PCI_VDEVICE(BROADCOM
, 0x16d1), .driver_data
= BCM57404
},
105 { PCI_VDEVICE(BROADCOM
, 0x16d2), .driver_data
= BCM57406
},
106 #ifdef CONFIG_BNXT_SRIOV
107 { PCI_VDEVICE(BROADCOM
, 0x16cb), .driver_data
= BCM57304_VF
},
108 { PCI_VDEVICE(BROADCOM
, 0x16d3), .driver_data
= BCM57404_VF
},
113 MODULE_DEVICE_TABLE(pci
, bnxt_pci_tbl
);
115 static const u16 bnxt_vf_req_snif
[] = {
118 HWRM_CFA_L2_FILTER_ALLOC
,
121 static const u16 bnxt_async_events_arr
[] = {
122 HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
,
123 HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
,
126 static bool bnxt_vf_pciid(enum board_idx idx
)
128 return (idx
== BCM57304_VF
|| idx
== BCM57404_VF
);
131 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
132 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
133 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
135 #define BNXT_CP_DB_REARM(db, raw_cons) \
136 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
138 #define BNXT_CP_DB(db, raw_cons) \
139 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
141 #define BNXT_CP_DB_IRQ_DIS(db) \
142 writel(DB_CP_IRQ_DIS_FLAGS, db)
144 static inline u32
bnxt_tx_avail(struct bnxt
*bp
, struct bnxt_tx_ring_info
*txr
)
146 /* Tell compiler to fetch tx indices from memory. */
149 return bp
->tx_ring_size
-
150 ((txr
->tx_prod
- txr
->tx_cons
) & bp
->tx_ring_mask
);
153 static const u16 bnxt_lhint_arr
[] = {
154 TX_BD_FLAGS_LHINT_512_AND_SMALLER
,
155 TX_BD_FLAGS_LHINT_512_TO_1023
,
156 TX_BD_FLAGS_LHINT_1024_TO_2047
,
157 TX_BD_FLAGS_LHINT_1024_TO_2047
,
158 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
159 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
160 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
161 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
162 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
163 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
164 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
165 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
166 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
167 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
168 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
169 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
170 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
171 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
172 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
175 static netdev_tx_t
bnxt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
177 struct bnxt
*bp
= netdev_priv(dev
);
179 struct tx_bd_ext
*txbd1
;
180 struct netdev_queue
*txq
;
183 unsigned int length
, pad
= 0;
184 u32 len
, free_size
, vlan_tag_flags
, cfa_action
, flags
;
186 struct pci_dev
*pdev
= bp
->pdev
;
187 struct bnxt_tx_ring_info
*txr
;
188 struct bnxt_sw_tx_bd
*tx_buf
;
190 i
= skb_get_queue_mapping(skb
);
191 if (unlikely(i
>= bp
->tx_nr_rings
)) {
192 dev_kfree_skb_any(skb
);
196 txr
= &bp
->tx_ring
[i
];
197 txq
= netdev_get_tx_queue(dev
, i
);
200 free_size
= bnxt_tx_avail(bp
, txr
);
201 if (unlikely(free_size
< skb_shinfo(skb
)->nr_frags
+ 2)) {
202 netif_tx_stop_queue(txq
);
203 return NETDEV_TX_BUSY
;
207 len
= skb_headlen(skb
);
208 last_frag
= skb_shinfo(skb
)->nr_frags
;
210 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
212 txbd
->tx_bd_opaque
= prod
;
214 tx_buf
= &txr
->tx_buf_ring
[prod
];
216 tx_buf
->nr_frags
= last_frag
;
220 if (skb_vlan_tag_present(skb
)) {
221 vlan_tag_flags
= TX_BD_CFA_META_KEY_VLAN
|
222 skb_vlan_tag_get(skb
);
223 /* Currently supports 8021Q, 8021AD vlan offloads
224 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
226 if (skb
->vlan_proto
== htons(ETH_P_8021Q
))
227 vlan_tag_flags
|= 1 << TX_BD_CFA_META_TPID_SHIFT
;
230 if (free_size
== bp
->tx_ring_size
&& length
<= bp
->tx_push_thresh
) {
231 struct tx_push_buffer
*tx_push_buf
= txr
->tx_push
;
232 struct tx_push_bd
*tx_push
= &tx_push_buf
->push_bd
;
233 struct tx_bd_ext
*tx_push1
= &tx_push
->txbd2
;
234 void *pdata
= tx_push_buf
->data
;
238 /* Set COAL_NOW to be ready quickly for the next push */
239 tx_push
->tx_bd_len_flags_type
=
240 cpu_to_le32((length
<< TX_BD_LEN_SHIFT
) |
241 TX_BD_TYPE_LONG_TX_BD
|
242 TX_BD_FLAGS_LHINT_512_AND_SMALLER
|
243 TX_BD_FLAGS_COAL_NOW
|
244 TX_BD_FLAGS_PACKET_END
|
245 (2 << TX_BD_FLAGS_BD_CNT_SHIFT
));
247 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
248 tx_push1
->tx_bd_hsize_lflags
=
249 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
251 tx_push1
->tx_bd_hsize_lflags
= 0;
253 tx_push1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
254 tx_push1
->tx_bd_cfa_action
= cpu_to_le32(cfa_action
);
256 end
= pdata
+ length
;
257 end
= PTR_ALIGN(end
, 8) - 1;
260 skb_copy_from_linear_data(skb
, pdata
, len
);
262 for (j
= 0; j
< last_frag
; j
++) {
263 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[j
];
266 fptr
= skb_frag_address_safe(frag
);
270 memcpy(pdata
, fptr
, skb_frag_size(frag
));
271 pdata
+= skb_frag_size(frag
);
274 txbd
->tx_bd_len_flags_type
= tx_push
->tx_bd_len_flags_type
;
275 txbd
->tx_bd_haddr
= txr
->data_mapping
;
276 prod
= NEXT_TX(prod
);
277 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
278 memcpy(txbd
, tx_push1
, sizeof(*txbd
));
279 prod
= NEXT_TX(prod
);
281 cpu_to_le32(DB_KEY_TX_PUSH
| DB_LONG_TX_PUSH
| prod
);
284 netdev_tx_sent_queue(txq
, skb
->len
);
286 push_len
= (length
+ sizeof(*tx_push
) + 7) / 8;
288 __iowrite64_copy(txr
->tx_doorbell
, tx_push_buf
, 16);
289 __iowrite64_copy(txr
->tx_doorbell
+ 4, tx_push_buf
+ 1,
292 __iowrite64_copy(txr
->tx_doorbell
, tx_push_buf
,
301 if (length
< BNXT_MIN_PKT_SIZE
) {
302 pad
= BNXT_MIN_PKT_SIZE
- length
;
303 if (skb_pad(skb
, pad
)) {
304 /* SKB already freed. */
308 length
= BNXT_MIN_PKT_SIZE
;
311 mapping
= dma_map_single(&pdev
->dev
, skb
->data
, len
, DMA_TO_DEVICE
);
313 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
))) {
314 dev_kfree_skb_any(skb
);
319 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
320 flags
= (len
<< TX_BD_LEN_SHIFT
) | TX_BD_TYPE_LONG_TX_BD
|
321 ((last_frag
+ 2) << TX_BD_FLAGS_BD_CNT_SHIFT
);
323 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
325 prod
= NEXT_TX(prod
);
326 txbd1
= (struct tx_bd_ext
*)
327 &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
329 txbd1
->tx_bd_hsize_lflags
= 0;
330 if (skb_is_gso(skb
)) {
333 if (skb
->encapsulation
)
334 hdr_len
= skb_inner_network_offset(skb
) +
335 skb_inner_network_header_len(skb
) +
336 inner_tcp_hdrlen(skb
);
338 hdr_len
= skb_transport_offset(skb
) +
341 txbd1
->tx_bd_hsize_lflags
= cpu_to_le32(TX_BD_FLAGS_LSO
|
343 (hdr_len
<< (TX_BD_HSIZE_SHIFT
- 1)));
344 length
= skb_shinfo(skb
)->gso_size
;
345 txbd1
->tx_bd_mss
= cpu_to_le32(length
);
347 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
348 txbd1
->tx_bd_hsize_lflags
=
349 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
350 txbd1
->tx_bd_mss
= 0;
354 flags
|= bnxt_lhint_arr
[length
];
355 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
357 txbd1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
358 txbd1
->tx_bd_cfa_action
= cpu_to_le32(cfa_action
);
359 for (i
= 0; i
< last_frag
; i
++) {
360 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
362 prod
= NEXT_TX(prod
);
363 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
365 len
= skb_frag_size(frag
);
366 mapping
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, len
,
369 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
)))
372 tx_buf
= &txr
->tx_buf_ring
[prod
];
373 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
375 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
377 flags
= len
<< TX_BD_LEN_SHIFT
;
378 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
382 txbd
->tx_bd_len_flags_type
=
383 cpu_to_le32(((len
+ pad
) << TX_BD_LEN_SHIFT
) | flags
|
384 TX_BD_FLAGS_PACKET_END
);
386 netdev_tx_sent_queue(txq
, skb
->len
);
388 /* Sync BD data before updating doorbell */
391 prod
= NEXT_TX(prod
);
394 writel(DB_KEY_TX
| prod
, txr
->tx_doorbell
);
395 writel(DB_KEY_TX
| prod
, txr
->tx_doorbell
);
401 if (unlikely(bnxt_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
+ 1)) {
402 netif_tx_stop_queue(txq
);
404 /* netif_tx_stop_queue() must be done before checking
405 * tx index in bnxt_tx_avail() below, because in
406 * bnxt_tx_int(), we update tx index before checking for
407 * netif_tx_queue_stopped().
410 if (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
411 netif_tx_wake_queue(txq
);
418 /* start back at beginning and unmap skb */
420 tx_buf
= &txr
->tx_buf_ring
[prod
];
422 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
423 skb_headlen(skb
), PCI_DMA_TODEVICE
);
424 prod
= NEXT_TX(prod
);
426 /* unmap remaining mapped pages */
427 for (i
= 0; i
< last_frag
; i
++) {
428 prod
= NEXT_TX(prod
);
429 tx_buf
= &txr
->tx_buf_ring
[prod
];
430 dma_unmap_page(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
431 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
435 dev_kfree_skb_any(skb
);
439 static void bnxt_tx_int(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int nr_pkts
)
441 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
442 int index
= txr
- &bp
->tx_ring
[0];
443 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, index
);
444 u16 cons
= txr
->tx_cons
;
445 struct pci_dev
*pdev
= bp
->pdev
;
447 unsigned int tx_bytes
= 0;
449 for (i
= 0; i
< nr_pkts
; i
++) {
450 struct bnxt_sw_tx_bd
*tx_buf
;
454 tx_buf
= &txr
->tx_buf_ring
[cons
];
455 cons
= NEXT_TX(cons
);
459 if (tx_buf
->is_push
) {
464 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
465 skb_headlen(skb
), PCI_DMA_TODEVICE
);
466 last
= tx_buf
->nr_frags
;
468 for (j
= 0; j
< last
; j
++) {
469 cons
= NEXT_TX(cons
);
470 tx_buf
= &txr
->tx_buf_ring
[cons
];
473 dma_unmap_addr(tx_buf
, mapping
),
474 skb_frag_size(&skb_shinfo(skb
)->frags
[j
]),
479 cons
= NEXT_TX(cons
);
481 tx_bytes
+= skb
->len
;
482 dev_kfree_skb_any(skb
);
485 netdev_tx_completed_queue(txq
, nr_pkts
, tx_bytes
);
488 /* Need to make the tx_cons update visible to bnxt_start_xmit()
489 * before checking for netif_tx_queue_stopped(). Without the
490 * memory barrier, there is a small possibility that bnxt_start_xmit()
491 * will miss it and cause the queue to be stopped forever.
495 if (unlikely(netif_tx_queue_stopped(txq
)) &&
496 (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
497 __netif_tx_lock(txq
, smp_processor_id());
498 if (netif_tx_queue_stopped(txq
) &&
499 bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
&&
500 txr
->dev_state
!= BNXT_DEV_STATE_CLOSING
)
501 netif_tx_wake_queue(txq
);
502 __netif_tx_unlock(txq
);
506 static inline u8
*__bnxt_alloc_rx_data(struct bnxt
*bp
, dma_addr_t
*mapping
,
510 struct pci_dev
*pdev
= bp
->pdev
;
512 data
= kmalloc(bp
->rx_buf_size
, gfp
);
516 *mapping
= dma_map_single(&pdev
->dev
, data
+ BNXT_RX_DMA_OFFSET
,
517 bp
->rx_buf_use_size
, PCI_DMA_FROMDEVICE
);
519 if (dma_mapping_error(&pdev
->dev
, *mapping
)) {
526 static inline int bnxt_alloc_rx_data(struct bnxt
*bp
,
527 struct bnxt_rx_ring_info
*rxr
,
530 struct rx_bd
*rxbd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
531 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[prod
];
535 data
= __bnxt_alloc_rx_data(bp
, &mapping
, gfp
);
540 dma_unmap_addr_set(rx_buf
, mapping
, mapping
);
542 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
547 static void bnxt_reuse_rx_data(struct bnxt_rx_ring_info
*rxr
, u16 cons
,
550 u16 prod
= rxr
->rx_prod
;
551 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
552 struct rx_bd
*cons_bd
, *prod_bd
;
554 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
555 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
557 prod_rx_buf
->data
= data
;
559 dma_unmap_addr_set(prod_rx_buf
, mapping
,
560 dma_unmap_addr(cons_rx_buf
, mapping
));
562 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
563 cons_bd
= &rxr
->rx_desc_ring
[RX_RING(cons
)][RX_IDX(cons
)];
565 prod_bd
->rx_bd_haddr
= cons_bd
->rx_bd_haddr
;
568 static inline u16
bnxt_find_next_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
570 u16 next
, max
= rxr
->rx_agg_bmap_size
;
572 next
= find_next_zero_bit(rxr
->rx_agg_bmap
, max
, idx
);
574 next
= find_first_zero_bit(rxr
->rx_agg_bmap
, max
);
578 static inline int bnxt_alloc_rx_page(struct bnxt
*bp
,
579 struct bnxt_rx_ring_info
*rxr
,
583 &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
584 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
;
585 struct pci_dev
*pdev
= bp
->pdev
;
588 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
590 page
= alloc_page(gfp
);
594 mapping
= dma_map_page(&pdev
->dev
, page
, 0, PAGE_SIZE
,
596 if (dma_mapping_error(&pdev
->dev
, mapping
)) {
601 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
602 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
604 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
605 rx_agg_buf
= &rxr
->rx_agg_ring
[sw_prod
];
606 rxr
->rx_sw_agg_prod
= NEXT_RX_AGG(sw_prod
);
608 rx_agg_buf
->page
= page
;
609 rx_agg_buf
->mapping
= mapping
;
610 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
611 rxbd
->rx_bd_opaque
= sw_prod
;
615 static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi
*bnapi
, u16 cp_cons
,
618 struct bnxt
*bp
= bnapi
->bp
;
619 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
620 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
621 u16 prod
= rxr
->rx_agg_prod
;
622 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
625 for (i
= 0; i
< agg_bufs
; i
++) {
627 struct rx_agg_cmp
*agg
;
628 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
, *prod_rx_buf
;
629 struct rx_bd
*prod_bd
;
632 agg
= (struct rx_agg_cmp
*)
633 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
634 cons
= agg
->rx_agg_cmp_opaque
;
635 __clear_bit(cons
, rxr
->rx_agg_bmap
);
637 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
638 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
640 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
641 prod_rx_buf
= &rxr
->rx_agg_ring
[sw_prod
];
642 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
644 /* It is possible for sw_prod to be equal to cons, so
645 * set cons_rx_buf->page to NULL first.
647 page
= cons_rx_buf
->page
;
648 cons_rx_buf
->page
= NULL
;
649 prod_rx_buf
->page
= page
;
651 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
653 prod_bd
= &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
655 prod_bd
->rx_bd_haddr
= cpu_to_le64(cons_rx_buf
->mapping
);
656 prod_bd
->rx_bd_opaque
= sw_prod
;
658 prod
= NEXT_RX_AGG(prod
);
659 sw_prod
= NEXT_RX_AGG(sw_prod
);
660 cp_cons
= NEXT_CMP(cp_cons
);
662 rxr
->rx_agg_prod
= prod
;
663 rxr
->rx_sw_agg_prod
= sw_prod
;
666 static struct sk_buff
*bnxt_rx_skb(struct bnxt
*bp
,
667 struct bnxt_rx_ring_info
*rxr
, u16 cons
,
668 u16 prod
, u8
*data
, dma_addr_t dma_addr
,
674 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
676 bnxt_reuse_rx_data(rxr
, cons
, data
);
680 skb
= build_skb(data
, 0);
681 dma_unmap_single(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
688 skb_reserve(skb
, BNXT_RX_OFFSET
);
693 static struct sk_buff
*bnxt_rx_pages(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
694 struct sk_buff
*skb
, u16 cp_cons
,
697 struct pci_dev
*pdev
= bp
->pdev
;
698 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
699 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
700 u16 prod
= rxr
->rx_agg_prod
;
703 for (i
= 0; i
< agg_bufs
; i
++) {
705 struct rx_agg_cmp
*agg
;
706 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
;
710 agg
= (struct rx_agg_cmp
*)
711 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
712 cons
= agg
->rx_agg_cmp_opaque
;
713 frag_len
= (le32_to_cpu(agg
->rx_agg_cmp_len_flags_type
) &
714 RX_AGG_CMP_LEN
) >> RX_AGG_CMP_LEN_SHIFT
;
716 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
717 skb_fill_page_desc(skb
, i
, cons_rx_buf
->page
, 0, frag_len
);
718 __clear_bit(cons
, rxr
->rx_agg_bmap
);
720 /* It is possible for bnxt_alloc_rx_page() to allocate
721 * a sw_prod index that equals the cons index, so we
722 * need to clear the cons entry now.
724 mapping
= dma_unmap_addr(cons_rx_buf
, mapping
);
725 page
= cons_rx_buf
->page
;
726 cons_rx_buf
->page
= NULL
;
728 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_ATOMIC
) != 0) {
729 struct skb_shared_info
*shinfo
;
730 unsigned int nr_frags
;
732 shinfo
= skb_shinfo(skb
);
733 nr_frags
= --shinfo
->nr_frags
;
734 __skb_frag_set_page(&shinfo
->frags
[nr_frags
], NULL
);
738 cons_rx_buf
->page
= page
;
740 /* Update prod since possibly some pages have been
743 rxr
->rx_agg_prod
= prod
;
744 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
- i
);
748 dma_unmap_page(&pdev
->dev
, mapping
, PAGE_SIZE
,
751 skb
->data_len
+= frag_len
;
752 skb
->len
+= frag_len
;
753 skb
->truesize
+= PAGE_SIZE
;
755 prod
= NEXT_RX_AGG(prod
);
756 cp_cons
= NEXT_CMP(cp_cons
);
758 rxr
->rx_agg_prod
= prod
;
762 static int bnxt_agg_bufs_valid(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
763 u8 agg_bufs
, u32
*raw_cons
)
766 struct rx_agg_cmp
*agg
;
768 *raw_cons
= ADV_RAW_CMP(*raw_cons
, agg_bufs
);
769 last
= RING_CMP(*raw_cons
);
770 agg
= (struct rx_agg_cmp
*)
771 &cpr
->cp_desc_ring
[CP_RING(last
)][CP_IDX(last
)];
772 return RX_AGG_CMP_VALID(agg
, *raw_cons
);
775 static inline struct sk_buff
*bnxt_copy_skb(struct bnxt_napi
*bnapi
, u8
*data
,
779 struct bnxt
*bp
= bnapi
->bp
;
780 struct pci_dev
*pdev
= bp
->pdev
;
783 skb
= napi_alloc_skb(&bnapi
->napi
, len
);
787 dma_sync_single_for_cpu(&pdev
->dev
, mapping
,
788 bp
->rx_copy_thresh
, PCI_DMA_FROMDEVICE
);
790 memcpy(skb
->data
- BNXT_RX_OFFSET
, data
, len
+ BNXT_RX_OFFSET
);
792 dma_sync_single_for_device(&pdev
->dev
, mapping
,
800 static void bnxt_tpa_start(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
801 struct rx_tpa_start_cmp
*tpa_start
,
802 struct rx_tpa_start_cmp_ext
*tpa_start1
)
804 u8 agg_id
= TPA_START_AGG_ID(tpa_start
);
806 struct bnxt_tpa_info
*tpa_info
;
807 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
808 struct rx_bd
*prod_bd
;
811 cons
= tpa_start
->rx_tpa_start_cmp_opaque
;
813 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
814 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
815 tpa_info
= &rxr
->rx_tpa
[agg_id
];
817 prod_rx_buf
->data
= tpa_info
->data
;
819 mapping
= tpa_info
->mapping
;
820 dma_unmap_addr_set(prod_rx_buf
, mapping
, mapping
);
822 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
824 prod_bd
->rx_bd_haddr
= cpu_to_le64(mapping
);
826 tpa_info
->data
= cons_rx_buf
->data
;
827 cons_rx_buf
->data
= NULL
;
828 tpa_info
->mapping
= dma_unmap_addr(cons_rx_buf
, mapping
);
831 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_len_flags_type
) >>
832 RX_TPA_START_CMP_LEN_SHIFT
;
833 if (likely(TPA_START_HASH_VALID(tpa_start
))) {
834 u32 hash_type
= TPA_START_HASH_TYPE(tpa_start
);
836 tpa_info
->hash_type
= PKT_HASH_TYPE_L4
;
837 tpa_info
->gso_type
= SKB_GSO_TCPV4
;
838 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
840 tpa_info
->gso_type
= SKB_GSO_TCPV6
;
842 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_rss_hash
);
844 tpa_info
->hash_type
= PKT_HASH_TYPE_NONE
;
845 tpa_info
->gso_type
= 0;
846 if (netif_msg_rx_err(bp
))
847 netdev_warn(bp
->dev
, "TPA packet without valid hash\n");
849 tpa_info
->flags2
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_flags2
);
850 tpa_info
->metadata
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_metadata
);
852 rxr
->rx_prod
= NEXT_RX(prod
);
853 cons
= NEXT_RX(cons
);
854 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
856 bnxt_reuse_rx_data(rxr
, cons
, cons_rx_buf
->data
);
857 rxr
->rx_prod
= NEXT_RX(rxr
->rx_prod
);
858 cons_rx_buf
->data
= NULL
;
861 static void bnxt_abort_tpa(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
862 u16 cp_cons
, u32 agg_bufs
)
865 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
);
868 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
869 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
871 static inline struct sk_buff
*bnxt_gro_skb(struct bnxt_tpa_info
*tpa_info
,
872 struct rx_tpa_end_cmp
*tpa_end
,
873 struct rx_tpa_end_cmp_ext
*tpa_end1
,
878 int payload_off
, tcp_opt_len
= 0;
882 segs
= TPA_END_TPA_SEGS(tpa_end
);
886 NAPI_GRO_CB(skb
)->count
= segs
;
887 skb_shinfo(skb
)->gso_size
=
888 le32_to_cpu(tpa_end1
->rx_tpa_end_cmp_seg_len
);
889 skb_shinfo(skb
)->gso_type
= tpa_info
->gso_type
;
890 payload_off
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
891 RX_TPA_END_CMP_PAYLOAD_OFFSET
) >>
892 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT
;
893 if (TPA_END_GRO_TS(tpa_end
))
896 if (tpa_info
->gso_type
== SKB_GSO_TCPV4
) {
899 nw_off
= payload_off
- BNXT_IPV4_HDR_SIZE
- tcp_opt_len
-
901 skb_set_network_header(skb
, nw_off
);
903 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
904 len
= skb
->len
- skb_transport_offset(skb
);
906 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
907 } else if (tpa_info
->gso_type
== SKB_GSO_TCPV6
) {
910 nw_off
= payload_off
- BNXT_IPV6_HDR_SIZE
- tcp_opt_len
-
912 skb_set_network_header(skb
, nw_off
);
914 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
915 len
= skb
->len
- skb_transport_offset(skb
);
917 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
919 dev_kfree_skb_any(skb
);
922 tcp_gro_complete(skb
);
924 if (nw_off
) { /* tunnel */
925 struct udphdr
*uh
= NULL
;
927 if (skb
->protocol
== htons(ETH_P_IP
)) {
928 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
930 if (iph
->protocol
== IPPROTO_UDP
)
931 uh
= (struct udphdr
*)(iph
+ 1);
933 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
935 if (iph
->nexthdr
== IPPROTO_UDP
)
936 uh
= (struct udphdr
*)(iph
+ 1);
940 skb_shinfo(skb
)->gso_type
|=
941 SKB_GSO_UDP_TUNNEL_CSUM
;
943 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
950 static inline struct sk_buff
*bnxt_tpa_end(struct bnxt
*bp
,
951 struct bnxt_napi
*bnapi
,
953 struct rx_tpa_end_cmp
*tpa_end
,
954 struct rx_tpa_end_cmp_ext
*tpa_end1
,
957 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
958 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
959 u8 agg_id
= TPA_END_AGG_ID(tpa_end
);
961 u16 cp_cons
= RING_CMP(*raw_cons
);
963 struct bnxt_tpa_info
*tpa_info
;
967 tpa_info
= &rxr
->rx_tpa
[agg_id
];
968 data
= tpa_info
->data
;
971 mapping
= tpa_info
->mapping
;
973 agg_bufs
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
974 RX_TPA_END_CMP_AGG_BUFS
) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT
;
977 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, raw_cons
))
978 return ERR_PTR(-EBUSY
);
981 cp_cons
= NEXT_CMP(cp_cons
);
984 if (unlikely(agg_bufs
> MAX_SKB_FRAGS
)) {
985 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
986 netdev_warn(bp
->dev
, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
987 agg_bufs
, (int)MAX_SKB_FRAGS
);
991 if (len
<= bp
->rx_copy_thresh
) {
992 skb
= bnxt_copy_skb(bnapi
, data
, len
, mapping
);
994 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
999 dma_addr_t new_mapping
;
1001 new_data
= __bnxt_alloc_rx_data(bp
, &new_mapping
, GFP_ATOMIC
);
1003 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1007 tpa_info
->data
= new_data
;
1008 tpa_info
->mapping
= new_mapping
;
1010 skb
= build_skb(data
, 0);
1011 dma_unmap_single(&bp
->pdev
->dev
, mapping
, bp
->rx_buf_use_size
,
1012 PCI_DMA_FROMDEVICE
);
1016 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1019 skb_reserve(skb
, BNXT_RX_OFFSET
);
1024 skb
= bnxt_rx_pages(bp
, bnapi
, skb
, cp_cons
, agg_bufs
);
1026 /* Page reuse already handled by bnxt_rx_pages(). */
1030 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
1032 if (tpa_info
->hash_type
!= PKT_HASH_TYPE_NONE
)
1033 skb_set_hash(skb
, tpa_info
->rss_hash
, tpa_info
->hash_type
);
1035 if (tpa_info
->flags2
& RX_CMP_FLAGS2_META_FORMAT_VLAN
) {
1036 netdev_features_t features
= skb
->dev
->features
;
1037 u16 vlan_proto
= tpa_info
->metadata
>>
1038 RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1040 if (((features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
1041 vlan_proto
== ETH_P_8021Q
) ||
1042 ((features
& NETIF_F_HW_VLAN_STAG_RX
) &&
1043 vlan_proto
== ETH_P_8021AD
)) {
1044 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
),
1045 tpa_info
->metadata
&
1046 RX_CMP_FLAGS2_METADATA_VID_MASK
);
1050 skb_checksum_none_assert(skb
);
1051 if (likely(tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_L4_CS_CALC
)) {
1052 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1054 (tpa_info
->flags2
& RX_CMP_FLAGS2_T_L4_CS_CALC
) >> 3;
1057 if (TPA_END_GRO(tpa_end
))
1058 skb
= bnxt_gro_skb(tpa_info
, tpa_end
, tpa_end1
, skb
);
1063 /* returns the following:
1064 * 1 - 1 packet successfully received
1065 * 0 - successful TPA_START, packet not completed yet
1066 * -EBUSY - completion ring does not have all the agg buffers yet
1067 * -ENOMEM - packet aborted due to out of memory
1068 * -EIO - packet aborted due to hw error indicated in BD
1070 static int bnxt_rx_pkt(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, u32
*raw_cons
,
1073 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1074 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1075 struct net_device
*dev
= bp
->dev
;
1076 struct rx_cmp
*rxcmp
;
1077 struct rx_cmp_ext
*rxcmp1
;
1078 u32 tmp_raw_cons
= *raw_cons
;
1079 u16 cons
, prod
, cp_cons
= RING_CMP(tmp_raw_cons
);
1080 struct bnxt_sw_rx_bd
*rx_buf
;
1082 u8
*data
, agg_bufs
, cmp_type
;
1083 dma_addr_t dma_addr
;
1084 struct sk_buff
*skb
;
1087 rxcmp
= (struct rx_cmp
*)
1088 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1090 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1091 cp_cons
= RING_CMP(tmp_raw_cons
);
1092 rxcmp1
= (struct rx_cmp_ext
*)
1093 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1095 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1098 cmp_type
= RX_CMP_TYPE(rxcmp
);
1100 prod
= rxr
->rx_prod
;
1102 if (cmp_type
== CMP_TYPE_RX_L2_TPA_START_CMP
) {
1103 bnxt_tpa_start(bp
, rxr
, (struct rx_tpa_start_cmp
*)rxcmp
,
1104 (struct rx_tpa_start_cmp_ext
*)rxcmp1
);
1106 goto next_rx_no_prod
;
1108 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1109 skb
= bnxt_tpa_end(bp
, bnapi
, &tmp_raw_cons
,
1110 (struct rx_tpa_end_cmp
*)rxcmp
,
1111 (struct rx_tpa_end_cmp_ext
*)rxcmp1
,
1114 if (unlikely(IS_ERR(skb
)))
1119 skb_record_rx_queue(skb
, bnapi
->index
);
1120 skb_mark_napi_id(skb
, &bnapi
->napi
);
1121 if (bnxt_busy_polling(bnapi
))
1122 netif_receive_skb(skb
);
1124 napi_gro_receive(&bnapi
->napi
, skb
);
1127 goto next_rx_no_prod
;
1130 cons
= rxcmp
->rx_cmp_opaque
;
1131 rx_buf
= &rxr
->rx_buf_ring
[cons
];
1132 data
= rx_buf
->data
;
1135 agg_bufs
= (le32_to_cpu(rxcmp
->rx_cmp_misc_v1
) & RX_CMP_AGG_BUFS
) >>
1136 RX_CMP_AGG_BUFS_SHIFT
;
1139 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1142 cp_cons
= NEXT_CMP(cp_cons
);
1146 rx_buf
->data
= NULL
;
1147 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L2_ERRORS
) {
1148 bnxt_reuse_rx_data(rxr
, cons
, data
);
1150 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
);
1156 len
= le32_to_cpu(rxcmp
->rx_cmp_len_flags_type
) >> RX_CMP_LEN_SHIFT
;
1157 dma_addr
= dma_unmap_addr(rx_buf
, mapping
);
1159 if (len
<= bp
->rx_copy_thresh
) {
1160 skb
= bnxt_copy_skb(bnapi
, data
, len
, dma_addr
);
1161 bnxt_reuse_rx_data(rxr
, cons
, data
);
1167 skb
= bnxt_rx_skb(bp
, rxr
, cons
, prod
, data
, dma_addr
, len
);
1175 skb
= bnxt_rx_pages(bp
, bnapi
, skb
, cp_cons
, agg_bufs
);
1182 if (RX_CMP_HASH_VALID(rxcmp
)) {
1183 u32 hash_type
= RX_CMP_HASH_TYPE(rxcmp
);
1184 enum pkt_hash_types type
= PKT_HASH_TYPE_L4
;
1186 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1187 if (hash_type
!= 1 && hash_type
!= 3)
1188 type
= PKT_HASH_TYPE_L3
;
1189 skb_set_hash(skb
, le32_to_cpu(rxcmp
->rx_cmp_rss_hash
), type
);
1192 skb
->protocol
= eth_type_trans(skb
, dev
);
1194 if (rxcmp1
->rx_cmp_flags2
&
1195 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN
)) {
1196 netdev_features_t features
= skb
->dev
->features
;
1197 u32 meta_data
= le32_to_cpu(rxcmp1
->rx_cmp_meta_data
);
1198 u16 vlan_proto
= meta_data
>> RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1200 if (((features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
1201 vlan_proto
== ETH_P_8021Q
) ||
1202 ((features
& NETIF_F_HW_VLAN_STAG_RX
) &&
1203 vlan_proto
== ETH_P_8021AD
))
1204 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
),
1206 RX_CMP_FLAGS2_METADATA_VID_MASK
);
1209 skb_checksum_none_assert(skb
);
1210 if (RX_CMP_L4_CS_OK(rxcmp1
)) {
1211 if (dev
->features
& NETIF_F_RXCSUM
) {
1212 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1213 skb
->csum_level
= RX_CMP_ENCAP(rxcmp1
);
1216 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L4_CS_ERR_BITS
) {
1217 if (dev
->features
& NETIF_F_RXCSUM
)
1218 cpr
->rx_l4_csum_errors
++;
1222 skb_record_rx_queue(skb
, bnapi
->index
);
1223 skb_mark_napi_id(skb
, &bnapi
->napi
);
1224 if (bnxt_busy_polling(bnapi
))
1225 netif_receive_skb(skb
);
1227 napi_gro_receive(&bnapi
->napi
, skb
);
1231 rxr
->rx_prod
= NEXT_RX(prod
);
1234 *raw_cons
= tmp_raw_cons
;
1239 static int bnxt_async_event_process(struct bnxt
*bp
,
1240 struct hwrm_async_event_cmpl
*cmpl
)
1242 u16 event_id
= le16_to_cpu(cmpl
->event_id
);
1244 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1246 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
:
1247 set_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
);
1249 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
:
1250 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
);
1253 netdev_err(bp
->dev
, "unhandled ASYNC event (id 0x%x)\n",
1255 goto async_event_process_exit
;
1257 schedule_work(&bp
->sp_task
);
1258 async_event_process_exit
:
1262 static int bnxt_hwrm_handler(struct bnxt
*bp
, struct tx_cmp
*txcmp
)
1264 u16 cmpl_type
= TX_CMP_TYPE(txcmp
), vf_id
, seq_id
;
1265 struct hwrm_cmpl
*h_cmpl
= (struct hwrm_cmpl
*)txcmp
;
1266 struct hwrm_fwd_req_cmpl
*fwd_req_cmpl
=
1267 (struct hwrm_fwd_req_cmpl
*)txcmp
;
1269 switch (cmpl_type
) {
1270 case CMPL_BASE_TYPE_HWRM_DONE
:
1271 seq_id
= le16_to_cpu(h_cmpl
->sequence_id
);
1272 if (seq_id
== bp
->hwrm_intr_seq_id
)
1273 bp
->hwrm_intr_seq_id
= HWRM_SEQ_ID_INVALID
;
1275 netdev_err(bp
->dev
, "Invalid hwrm seq id %d\n", seq_id
);
1278 case CMPL_BASE_TYPE_HWRM_FWD_REQ
:
1279 vf_id
= le16_to_cpu(fwd_req_cmpl
->source_id
);
1281 if ((vf_id
< bp
->pf
.first_vf_id
) ||
1282 (vf_id
>= bp
->pf
.first_vf_id
+ bp
->pf
.active_vfs
)) {
1283 netdev_err(bp
->dev
, "Msg contains invalid VF id %x\n",
1288 set_bit(vf_id
- bp
->pf
.first_vf_id
, bp
->pf
.vf_event_bmap
);
1289 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
);
1290 schedule_work(&bp
->sp_task
);
1293 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
:
1294 bnxt_async_event_process(bp
,
1295 (struct hwrm_async_event_cmpl
*)txcmp
);
1304 static irqreturn_t
bnxt_msix(int irq
, void *dev_instance
)
1306 struct bnxt_napi
*bnapi
= dev_instance
;
1307 struct bnxt
*bp
= bnapi
->bp
;
1308 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1309 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1311 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1312 napi_schedule(&bnapi
->napi
);
1316 static inline int bnxt_has_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
)
1318 u32 raw_cons
= cpr
->cp_raw_cons
;
1319 u16 cons
= RING_CMP(raw_cons
);
1320 struct tx_cmp
*txcmp
;
1322 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1324 return TX_CMP_VALID(txcmp
, raw_cons
);
1327 static irqreturn_t
bnxt_inta(int irq
, void *dev_instance
)
1329 struct bnxt_napi
*bnapi
= dev_instance
;
1330 struct bnxt
*bp
= bnapi
->bp
;
1331 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1332 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1335 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1337 if (!bnxt_has_work(bp
, cpr
)) {
1338 int_status
= readl(bp
->bar0
+ BNXT_CAG_REG_LEGACY_INT_STATUS
);
1339 /* return if erroneous interrupt */
1340 if (!(int_status
& (0x10000 << cpr
->cp_ring_struct
.fw_ring_id
)))
1344 /* disable ring IRQ */
1345 BNXT_CP_DB_IRQ_DIS(cpr
->cp_doorbell
);
1347 /* Return here if interrupt is shared and is disabled. */
1348 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
1351 napi_schedule(&bnapi
->napi
);
1355 static int bnxt_poll_work(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int budget
)
1357 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1358 u32 raw_cons
= cpr
->cp_raw_cons
;
1362 bool rx_event
= false;
1363 bool agg_event
= false;
1364 struct tx_cmp
*txcmp
;
1369 cons
= RING_CMP(raw_cons
);
1370 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1372 if (!TX_CMP_VALID(txcmp
, raw_cons
))
1375 if (TX_CMP_TYPE(txcmp
) == CMP_TYPE_TX_L2_CMP
) {
1377 /* return full budget so NAPI will complete. */
1378 if (unlikely(tx_pkts
> bp
->tx_wake_thresh
))
1380 } else if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
1381 rc
= bnxt_rx_pkt(bp
, bnapi
, &raw_cons
, &agg_event
);
1382 if (likely(rc
>= 0))
1384 else if (rc
== -EBUSY
) /* partial completion */
1387 } else if (unlikely((TX_CMP_TYPE(txcmp
) ==
1388 CMPL_BASE_TYPE_HWRM_DONE
) ||
1389 (TX_CMP_TYPE(txcmp
) ==
1390 CMPL_BASE_TYPE_HWRM_FWD_REQ
) ||
1391 (TX_CMP_TYPE(txcmp
) ==
1392 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
))) {
1393 bnxt_hwrm_handler(bp
, txcmp
);
1395 raw_cons
= NEXT_RAW_CMP(raw_cons
);
1397 if (rx_pkts
== budget
)
1401 cpr
->cp_raw_cons
= raw_cons
;
1402 /* ACK completion ring before freeing tx ring and producing new
1403 * buffers in rx/agg rings to prevent overflowing the completion
1406 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
1409 bnxt_tx_int(bp
, bnapi
, tx_pkts
);
1412 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1414 writel(DB_KEY_RX
| rxr
->rx_prod
, rxr
->rx_doorbell
);
1415 writel(DB_KEY_RX
| rxr
->rx_prod
, rxr
->rx_doorbell
);
1417 writel(DB_KEY_RX
| rxr
->rx_agg_prod
,
1418 rxr
->rx_agg_doorbell
);
1419 writel(DB_KEY_RX
| rxr
->rx_agg_prod
,
1420 rxr
->rx_agg_doorbell
);
1426 static int bnxt_poll(struct napi_struct
*napi
, int budget
)
1428 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
1429 struct bnxt
*bp
= bnapi
->bp
;
1430 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1433 if (!bnxt_lock_napi(bnapi
))
1437 work_done
+= bnxt_poll_work(bp
, bnapi
, budget
- work_done
);
1439 if (work_done
>= budget
)
1442 if (!bnxt_has_work(bp
, cpr
)) {
1443 napi_complete(napi
);
1444 BNXT_CP_DB_REARM(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
1449 bnxt_unlock_napi(bnapi
);
1453 #ifdef CONFIG_NET_RX_BUSY_POLL
1454 static int bnxt_busy_poll(struct napi_struct
*napi
)
1456 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
1457 struct bnxt
*bp
= bnapi
->bp
;
1458 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1459 int rx_work
, budget
= 4;
1461 if (atomic_read(&bp
->intr_sem
) != 0)
1462 return LL_FLUSH_FAILED
;
1464 if (!bnxt_lock_poll(bnapi
))
1465 return LL_FLUSH_BUSY
;
1467 rx_work
= bnxt_poll_work(bp
, bnapi
, budget
);
1469 BNXT_CP_DB_REARM(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
1471 bnxt_unlock_poll(bnapi
);
1476 static void bnxt_free_tx_skbs(struct bnxt
*bp
)
1479 struct pci_dev
*pdev
= bp
->pdev
;
1484 max_idx
= bp
->tx_nr_pages
* TX_DESC_CNT
;
1485 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
1486 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
1489 for (j
= 0; j
< max_idx
;) {
1490 struct bnxt_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
1491 struct sk_buff
*skb
= tx_buf
->skb
;
1501 if (tx_buf
->is_push
) {
1507 dma_unmap_single(&pdev
->dev
,
1508 dma_unmap_addr(tx_buf
, mapping
),
1512 last
= tx_buf
->nr_frags
;
1514 for (k
= 0; k
< last
; k
++, j
++) {
1515 int ring_idx
= j
& bp
->tx_ring_mask
;
1516 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[k
];
1518 tx_buf
= &txr
->tx_buf_ring
[ring_idx
];
1521 dma_unmap_addr(tx_buf
, mapping
),
1522 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
1526 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
1530 static void bnxt_free_rx_skbs(struct bnxt
*bp
)
1532 int i
, max_idx
, max_agg_idx
;
1533 struct pci_dev
*pdev
= bp
->pdev
;
1538 max_idx
= bp
->rx_nr_pages
* RX_DESC_CNT
;
1539 max_agg_idx
= bp
->rx_agg_nr_pages
* RX_DESC_CNT
;
1540 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
1541 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
1545 for (j
= 0; j
< MAX_TPA
; j
++) {
1546 struct bnxt_tpa_info
*tpa_info
=
1548 u8
*data
= tpa_info
->data
;
1555 dma_unmap_addr(tpa_info
, mapping
),
1556 bp
->rx_buf_use_size
,
1557 PCI_DMA_FROMDEVICE
);
1559 tpa_info
->data
= NULL
;
1565 for (j
= 0; j
< max_idx
; j
++) {
1566 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[j
];
1567 u8
*data
= rx_buf
->data
;
1572 dma_unmap_single(&pdev
->dev
,
1573 dma_unmap_addr(rx_buf
, mapping
),
1574 bp
->rx_buf_use_size
,
1575 PCI_DMA_FROMDEVICE
);
1577 rx_buf
->data
= NULL
;
1582 for (j
= 0; j
< max_agg_idx
; j
++) {
1583 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
=
1584 &rxr
->rx_agg_ring
[j
];
1585 struct page
*page
= rx_agg_buf
->page
;
1590 dma_unmap_page(&pdev
->dev
,
1591 dma_unmap_addr(rx_agg_buf
, mapping
),
1592 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
1594 rx_agg_buf
->page
= NULL
;
1595 __clear_bit(j
, rxr
->rx_agg_bmap
);
1602 static void bnxt_free_skbs(struct bnxt
*bp
)
1604 bnxt_free_tx_skbs(bp
);
1605 bnxt_free_rx_skbs(bp
);
1608 static void bnxt_free_ring(struct bnxt
*bp
, struct bnxt_ring_struct
*ring
)
1610 struct pci_dev
*pdev
= bp
->pdev
;
1613 for (i
= 0; i
< ring
->nr_pages
; i
++) {
1614 if (!ring
->pg_arr
[i
])
1617 dma_free_coherent(&pdev
->dev
, ring
->page_size
,
1618 ring
->pg_arr
[i
], ring
->dma_arr
[i
]);
1620 ring
->pg_arr
[i
] = NULL
;
1623 dma_free_coherent(&pdev
->dev
, ring
->nr_pages
* 8,
1624 ring
->pg_tbl
, ring
->pg_tbl_map
);
1625 ring
->pg_tbl
= NULL
;
1627 if (ring
->vmem_size
&& *ring
->vmem
) {
1633 static int bnxt_alloc_ring(struct bnxt
*bp
, struct bnxt_ring_struct
*ring
)
1636 struct pci_dev
*pdev
= bp
->pdev
;
1638 if (ring
->nr_pages
> 1) {
1639 ring
->pg_tbl
= dma_alloc_coherent(&pdev
->dev
,
1647 for (i
= 0; i
< ring
->nr_pages
; i
++) {
1648 ring
->pg_arr
[i
] = dma_alloc_coherent(&pdev
->dev
,
1652 if (!ring
->pg_arr
[i
])
1655 if (ring
->nr_pages
> 1)
1656 ring
->pg_tbl
[i
] = cpu_to_le64(ring
->dma_arr
[i
]);
1659 if (ring
->vmem_size
) {
1660 *ring
->vmem
= vzalloc(ring
->vmem_size
);
1667 static void bnxt_free_rx_rings(struct bnxt
*bp
)
1674 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
1675 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
1676 struct bnxt_ring_struct
*ring
;
1681 kfree(rxr
->rx_agg_bmap
);
1682 rxr
->rx_agg_bmap
= NULL
;
1684 ring
= &rxr
->rx_ring_struct
;
1685 bnxt_free_ring(bp
, ring
);
1687 ring
= &rxr
->rx_agg_ring_struct
;
1688 bnxt_free_ring(bp
, ring
);
1692 static int bnxt_alloc_rx_rings(struct bnxt
*bp
)
1694 int i
, rc
, agg_rings
= 0, tpa_rings
= 0;
1699 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
1702 if (bp
->flags
& BNXT_FLAG_TPA
)
1705 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
1706 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
1707 struct bnxt_ring_struct
*ring
;
1709 ring
= &rxr
->rx_ring_struct
;
1711 rc
= bnxt_alloc_ring(bp
, ring
);
1718 ring
= &rxr
->rx_agg_ring_struct
;
1719 rc
= bnxt_alloc_ring(bp
, ring
);
1723 rxr
->rx_agg_bmap_size
= bp
->rx_agg_ring_mask
+ 1;
1724 mem_size
= rxr
->rx_agg_bmap_size
/ 8;
1725 rxr
->rx_agg_bmap
= kzalloc(mem_size
, GFP_KERNEL
);
1726 if (!rxr
->rx_agg_bmap
)
1730 rxr
->rx_tpa
= kcalloc(MAX_TPA
,
1731 sizeof(struct bnxt_tpa_info
),
1741 static void bnxt_free_tx_rings(struct bnxt
*bp
)
1744 struct pci_dev
*pdev
= bp
->pdev
;
1749 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
1750 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
1751 struct bnxt_ring_struct
*ring
;
1754 dma_free_coherent(&pdev
->dev
, bp
->tx_push_size
,
1755 txr
->tx_push
, txr
->tx_push_mapping
);
1756 txr
->tx_push
= NULL
;
1759 ring
= &txr
->tx_ring_struct
;
1761 bnxt_free_ring(bp
, ring
);
1765 static int bnxt_alloc_tx_rings(struct bnxt
*bp
)
1768 struct pci_dev
*pdev
= bp
->pdev
;
1770 bp
->tx_push_size
= 0;
1771 if (bp
->tx_push_thresh
) {
1774 push_size
= L1_CACHE_ALIGN(sizeof(struct tx_push_bd
) +
1775 bp
->tx_push_thresh
);
1777 if (push_size
> 256) {
1779 bp
->tx_push_thresh
= 0;
1782 bp
->tx_push_size
= push_size
;
1785 for (i
= 0, j
= 0; i
< bp
->tx_nr_rings
; i
++) {
1786 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
1787 struct bnxt_ring_struct
*ring
;
1789 ring
= &txr
->tx_ring_struct
;
1791 rc
= bnxt_alloc_ring(bp
, ring
);
1795 if (bp
->tx_push_size
) {
1798 /* One pre-allocated DMA buffer to backup
1801 txr
->tx_push
= dma_alloc_coherent(&pdev
->dev
,
1803 &txr
->tx_push_mapping
,
1809 mapping
= txr
->tx_push_mapping
+
1810 sizeof(struct tx_push_bd
);
1811 txr
->data_mapping
= cpu_to_le64(mapping
);
1813 memset(txr
->tx_push
, 0, sizeof(struct tx_push_bd
));
1815 ring
->queue_id
= bp
->q_info
[j
].queue_id
;
1816 if (i
% bp
->tx_nr_rings_per_tc
== (bp
->tx_nr_rings_per_tc
- 1))
1822 static void bnxt_free_cp_rings(struct bnxt
*bp
)
1829 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
1830 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
1831 struct bnxt_cp_ring_info
*cpr
;
1832 struct bnxt_ring_struct
*ring
;
1837 cpr
= &bnapi
->cp_ring
;
1838 ring
= &cpr
->cp_ring_struct
;
1840 bnxt_free_ring(bp
, ring
);
1844 static int bnxt_alloc_cp_rings(struct bnxt
*bp
)
1848 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
1849 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
1850 struct bnxt_cp_ring_info
*cpr
;
1851 struct bnxt_ring_struct
*ring
;
1856 cpr
= &bnapi
->cp_ring
;
1857 ring
= &cpr
->cp_ring_struct
;
1859 rc
= bnxt_alloc_ring(bp
, ring
);
1866 static void bnxt_init_ring_struct(struct bnxt
*bp
)
1870 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
1871 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
1872 struct bnxt_cp_ring_info
*cpr
;
1873 struct bnxt_rx_ring_info
*rxr
;
1874 struct bnxt_tx_ring_info
*txr
;
1875 struct bnxt_ring_struct
*ring
;
1880 cpr
= &bnapi
->cp_ring
;
1881 ring
= &cpr
->cp_ring_struct
;
1882 ring
->nr_pages
= bp
->cp_nr_pages
;
1883 ring
->page_size
= HW_CMPD_RING_SIZE
;
1884 ring
->pg_arr
= (void **)cpr
->cp_desc_ring
;
1885 ring
->dma_arr
= cpr
->cp_desc_mapping
;
1886 ring
->vmem_size
= 0;
1888 rxr
= bnapi
->rx_ring
;
1892 ring
= &rxr
->rx_ring_struct
;
1893 ring
->nr_pages
= bp
->rx_nr_pages
;
1894 ring
->page_size
= HW_RXBD_RING_SIZE
;
1895 ring
->pg_arr
= (void **)rxr
->rx_desc_ring
;
1896 ring
->dma_arr
= rxr
->rx_desc_mapping
;
1897 ring
->vmem_size
= SW_RXBD_RING_SIZE
* bp
->rx_nr_pages
;
1898 ring
->vmem
= (void **)&rxr
->rx_buf_ring
;
1900 ring
= &rxr
->rx_agg_ring_struct
;
1901 ring
->nr_pages
= bp
->rx_agg_nr_pages
;
1902 ring
->page_size
= HW_RXBD_RING_SIZE
;
1903 ring
->pg_arr
= (void **)rxr
->rx_agg_desc_ring
;
1904 ring
->dma_arr
= rxr
->rx_agg_desc_mapping
;
1905 ring
->vmem_size
= SW_RXBD_AGG_RING_SIZE
* bp
->rx_agg_nr_pages
;
1906 ring
->vmem
= (void **)&rxr
->rx_agg_ring
;
1909 txr
= bnapi
->tx_ring
;
1913 ring
= &txr
->tx_ring_struct
;
1914 ring
->nr_pages
= bp
->tx_nr_pages
;
1915 ring
->page_size
= HW_RXBD_RING_SIZE
;
1916 ring
->pg_arr
= (void **)txr
->tx_desc_ring
;
1917 ring
->dma_arr
= txr
->tx_desc_mapping
;
1918 ring
->vmem_size
= SW_TXBD_RING_SIZE
* bp
->tx_nr_pages
;
1919 ring
->vmem
= (void **)&txr
->tx_buf_ring
;
1923 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct
*ring
, u32 type
)
1927 struct rx_bd
**rx_buf_ring
;
1929 rx_buf_ring
= (struct rx_bd
**)ring
->pg_arr
;
1930 for (i
= 0, prod
= 0; i
< ring
->nr_pages
; i
++) {
1934 rxbd
= rx_buf_ring
[i
];
1938 for (j
= 0; j
< RX_DESC_CNT
; j
++, rxbd
++, prod
++) {
1939 rxbd
->rx_bd_len_flags_type
= cpu_to_le32(type
);
1940 rxbd
->rx_bd_opaque
= prod
;
1945 static int bnxt_init_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
1947 struct net_device
*dev
= bp
->dev
;
1948 struct bnxt_rx_ring_info
*rxr
;
1949 struct bnxt_ring_struct
*ring
;
1953 type
= (bp
->rx_buf_use_size
<< RX_BD_LEN_SHIFT
) |
1954 RX_BD_TYPE_RX_PACKET_BD
| RX_BD_FLAGS_EOP
;
1956 if (NET_IP_ALIGN
== 2)
1957 type
|= RX_BD_FLAGS_SOP
;
1959 rxr
= &bp
->rx_ring
[ring_nr
];
1960 ring
= &rxr
->rx_ring_struct
;
1961 bnxt_init_rxbd_pages(ring
, type
);
1963 prod
= rxr
->rx_prod
;
1964 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
1965 if (bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
1966 netdev_warn(dev
, "init'ed rx ring %d with %d/%d skbs only\n",
1967 ring_nr
, i
, bp
->rx_ring_size
);
1970 prod
= NEXT_RX(prod
);
1972 rxr
->rx_prod
= prod
;
1973 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
1975 ring
= &rxr
->rx_agg_ring_struct
;
1976 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
1978 if (!(bp
->flags
& BNXT_FLAG_AGG_RINGS
))
1981 type
= ((u32
)PAGE_SIZE
<< RX_BD_LEN_SHIFT
) |
1982 RX_BD_TYPE_RX_AGG_BD
| RX_BD_FLAGS_SOP
;
1984 bnxt_init_rxbd_pages(ring
, type
);
1986 prod
= rxr
->rx_agg_prod
;
1987 for (i
= 0; i
< bp
->rx_agg_ring_size
; i
++) {
1988 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
1989 netdev_warn(dev
, "init'ed rx ring %d with %d/%d pages only\n",
1990 ring_nr
, i
, bp
->rx_ring_size
);
1993 prod
= NEXT_RX_AGG(prod
);
1995 rxr
->rx_agg_prod
= prod
;
1997 if (bp
->flags
& BNXT_FLAG_TPA
) {
2002 for (i
= 0; i
< MAX_TPA
; i
++) {
2003 data
= __bnxt_alloc_rx_data(bp
, &mapping
,
2008 rxr
->rx_tpa
[i
].data
= data
;
2009 rxr
->rx_tpa
[i
].mapping
= mapping
;
2012 netdev_err(bp
->dev
, "No resource allocated for LRO/GRO\n");
2020 static int bnxt_init_rx_rings(struct bnxt
*bp
)
2024 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2025 rc
= bnxt_init_one_rx_ring(bp
, i
);
2033 static int bnxt_init_tx_rings(struct bnxt
*bp
)
2037 bp
->tx_wake_thresh
= max_t(int, bp
->tx_ring_size
/ 2,
2040 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2041 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2042 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
2044 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2050 static void bnxt_free_ring_grps(struct bnxt
*bp
)
2052 kfree(bp
->grp_info
);
2053 bp
->grp_info
= NULL
;
2056 static int bnxt_init_ring_grps(struct bnxt
*bp
, bool irq_re_init
)
2061 bp
->grp_info
= kcalloc(bp
->cp_nr_rings
,
2062 sizeof(struct bnxt_ring_grp_info
),
2067 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2069 bp
->grp_info
[i
].fw_stats_ctx
= INVALID_HW_RING_ID
;
2070 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
2071 bp
->grp_info
[i
].rx_fw_ring_id
= INVALID_HW_RING_ID
;
2072 bp
->grp_info
[i
].agg_fw_ring_id
= INVALID_HW_RING_ID
;
2073 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
2078 static void bnxt_free_vnics(struct bnxt
*bp
)
2080 kfree(bp
->vnic_info
);
2081 bp
->vnic_info
= NULL
;
2085 static int bnxt_alloc_vnics(struct bnxt
*bp
)
2089 #ifdef CONFIG_RFS_ACCEL
2090 if (bp
->flags
& BNXT_FLAG_RFS
)
2091 num_vnics
+= bp
->rx_nr_rings
;
2094 bp
->vnic_info
= kcalloc(num_vnics
, sizeof(struct bnxt_vnic_info
),
2099 bp
->nr_vnics
= num_vnics
;
2103 static void bnxt_init_vnics(struct bnxt
*bp
)
2107 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2108 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
2110 vnic
->fw_vnic_id
= INVALID_HW_RING_ID
;
2111 vnic
->fw_rss_cos_lb_ctx
= INVALID_HW_RING_ID
;
2112 vnic
->fw_l2_ctx_id
= INVALID_HW_RING_ID
;
2114 if (bp
->vnic_info
[i
].rss_hash_key
) {
2116 prandom_bytes(vnic
->rss_hash_key
,
2119 memcpy(vnic
->rss_hash_key
,
2120 bp
->vnic_info
[0].rss_hash_key
,
2126 static int bnxt_calc_nr_ring_pages(u32 ring_size
, int desc_per_pg
)
2130 pages
= ring_size
/ desc_per_pg
;
2137 while (pages
& (pages
- 1))
2143 static void bnxt_set_tpa_flags(struct bnxt
*bp
)
2145 bp
->flags
&= ~BNXT_FLAG_TPA
;
2146 if (bp
->dev
->features
& NETIF_F_LRO
)
2147 bp
->flags
|= BNXT_FLAG_LRO
;
2148 if ((bp
->dev
->features
& NETIF_F_GRO
) && (bp
->pdev
->revision
> 0))
2149 bp
->flags
|= BNXT_FLAG_GRO
;
2152 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2155 void bnxt_set_ring_params(struct bnxt
*bp
)
2157 u32 ring_size
, rx_size
, rx_space
;
2158 u32 agg_factor
= 0, agg_ring_size
= 0;
2160 /* 8 for CRC and VLAN */
2161 rx_size
= SKB_DATA_ALIGN(bp
->dev
->mtu
+ ETH_HLEN
+ NET_IP_ALIGN
+ 8);
2163 rx_space
= rx_size
+ NET_SKB_PAD
+
2164 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
2166 bp
->rx_copy_thresh
= BNXT_RX_COPY_THRESH
;
2167 ring_size
= bp
->rx_ring_size
;
2168 bp
->rx_agg_ring_size
= 0;
2169 bp
->rx_agg_nr_pages
= 0;
2171 if (bp
->flags
& BNXT_FLAG_TPA
)
2174 bp
->flags
&= ~BNXT_FLAG_JUMBO
;
2175 if (rx_space
> PAGE_SIZE
) {
2178 bp
->flags
|= BNXT_FLAG_JUMBO
;
2179 jumbo_factor
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
2180 if (jumbo_factor
> agg_factor
)
2181 agg_factor
= jumbo_factor
;
2183 agg_ring_size
= ring_size
* agg_factor
;
2185 if (agg_ring_size
) {
2186 bp
->rx_agg_nr_pages
= bnxt_calc_nr_ring_pages(agg_ring_size
,
2188 if (bp
->rx_agg_nr_pages
> MAX_RX_AGG_PAGES
) {
2189 u32 tmp
= agg_ring_size
;
2191 bp
->rx_agg_nr_pages
= MAX_RX_AGG_PAGES
;
2192 agg_ring_size
= MAX_RX_AGG_PAGES
* RX_DESC_CNT
- 1;
2193 netdev_warn(bp
->dev
, "rx agg ring size %d reduced to %d.\n",
2194 tmp
, agg_ring_size
);
2196 bp
->rx_agg_ring_size
= agg_ring_size
;
2197 bp
->rx_agg_ring_mask
= (bp
->rx_agg_nr_pages
* RX_DESC_CNT
) - 1;
2198 rx_size
= SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH
+ NET_IP_ALIGN
);
2199 rx_space
= rx_size
+ NET_SKB_PAD
+
2200 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
2203 bp
->rx_buf_use_size
= rx_size
;
2204 bp
->rx_buf_size
= rx_space
;
2206 bp
->rx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, RX_DESC_CNT
);
2207 bp
->rx_ring_mask
= (bp
->rx_nr_pages
* RX_DESC_CNT
) - 1;
2209 ring_size
= bp
->tx_ring_size
;
2210 bp
->tx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, TX_DESC_CNT
);
2211 bp
->tx_ring_mask
= (bp
->tx_nr_pages
* TX_DESC_CNT
) - 1;
2213 ring_size
= bp
->rx_ring_size
* (2 + agg_factor
) + bp
->tx_ring_size
;
2214 bp
->cp_ring_size
= ring_size
;
2216 bp
->cp_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, CP_DESC_CNT
);
2217 if (bp
->cp_nr_pages
> MAX_CP_PAGES
) {
2218 bp
->cp_nr_pages
= MAX_CP_PAGES
;
2219 bp
->cp_ring_size
= MAX_CP_PAGES
* CP_DESC_CNT
- 1;
2220 netdev_warn(bp
->dev
, "completion ring size %d reduced to %d.\n",
2221 ring_size
, bp
->cp_ring_size
);
2223 bp
->cp_bit
= bp
->cp_nr_pages
* CP_DESC_CNT
;
2224 bp
->cp_ring_mask
= bp
->cp_bit
- 1;
2227 static void bnxt_free_vnic_attributes(struct bnxt
*bp
)
2230 struct bnxt_vnic_info
*vnic
;
2231 struct pci_dev
*pdev
= bp
->pdev
;
2236 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2237 vnic
= &bp
->vnic_info
[i
];
2239 kfree(vnic
->fw_grp_ids
);
2240 vnic
->fw_grp_ids
= NULL
;
2242 kfree(vnic
->uc_list
);
2243 vnic
->uc_list
= NULL
;
2245 if (vnic
->mc_list
) {
2246 dma_free_coherent(&pdev
->dev
, vnic
->mc_list_size
,
2247 vnic
->mc_list
, vnic
->mc_list_mapping
);
2248 vnic
->mc_list
= NULL
;
2251 if (vnic
->rss_table
) {
2252 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
2254 vnic
->rss_table_dma_addr
);
2255 vnic
->rss_table
= NULL
;
2258 vnic
->rss_hash_key
= NULL
;
2263 static int bnxt_alloc_vnic_attributes(struct bnxt
*bp
)
2265 int i
, rc
= 0, size
;
2266 struct bnxt_vnic_info
*vnic
;
2267 struct pci_dev
*pdev
= bp
->pdev
;
2270 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2271 vnic
= &bp
->vnic_info
[i
];
2273 if (vnic
->flags
& BNXT_VNIC_UCAST_FLAG
) {
2274 int mem_size
= (BNXT_MAX_UC_ADDRS
- 1) * ETH_ALEN
;
2277 vnic
->uc_list
= kmalloc(mem_size
, GFP_KERNEL
);
2278 if (!vnic
->uc_list
) {
2285 if (vnic
->flags
& BNXT_VNIC_MCAST_FLAG
) {
2286 vnic
->mc_list_size
= BNXT_MAX_MC_ADDRS
* ETH_ALEN
;
2288 dma_alloc_coherent(&pdev
->dev
,
2290 &vnic
->mc_list_mapping
,
2292 if (!vnic
->mc_list
) {
2298 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
2299 max_rings
= bp
->rx_nr_rings
;
2303 vnic
->fw_grp_ids
= kcalloc(max_rings
, sizeof(u16
), GFP_KERNEL
);
2304 if (!vnic
->fw_grp_ids
) {
2309 /* Allocate rss table and hash key */
2310 vnic
->rss_table
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
2311 &vnic
->rss_table_dma_addr
,
2313 if (!vnic
->rss_table
) {
2318 size
= L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE
* sizeof(u16
));
2320 vnic
->rss_hash_key
= ((void *)vnic
->rss_table
) + size
;
2321 vnic
->rss_hash_key_dma_addr
= vnic
->rss_table_dma_addr
+ size
;
2329 static void bnxt_free_hwrm_resources(struct bnxt
*bp
)
2331 struct pci_dev
*pdev
= bp
->pdev
;
2333 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
, bp
->hwrm_cmd_resp_addr
,
2334 bp
->hwrm_cmd_resp_dma_addr
);
2336 bp
->hwrm_cmd_resp_addr
= NULL
;
2337 if (bp
->hwrm_dbg_resp_addr
) {
2338 dma_free_coherent(&pdev
->dev
, HWRM_DBG_REG_BUF_SIZE
,
2339 bp
->hwrm_dbg_resp_addr
,
2340 bp
->hwrm_dbg_resp_dma_addr
);
2342 bp
->hwrm_dbg_resp_addr
= NULL
;
2346 static int bnxt_alloc_hwrm_resources(struct bnxt
*bp
)
2348 struct pci_dev
*pdev
= bp
->pdev
;
2350 bp
->hwrm_cmd_resp_addr
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
2351 &bp
->hwrm_cmd_resp_dma_addr
,
2353 if (!bp
->hwrm_cmd_resp_addr
)
2355 bp
->hwrm_dbg_resp_addr
= dma_alloc_coherent(&pdev
->dev
,
2356 HWRM_DBG_REG_BUF_SIZE
,
2357 &bp
->hwrm_dbg_resp_dma_addr
,
2359 if (!bp
->hwrm_dbg_resp_addr
)
2360 netdev_warn(bp
->dev
, "fail to alloc debug register dma mem\n");
2365 static void bnxt_free_stats(struct bnxt
*bp
)
2368 struct pci_dev
*pdev
= bp
->pdev
;
2370 if (bp
->hw_rx_port_stats
) {
2371 dma_free_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
2372 bp
->hw_rx_port_stats
,
2373 bp
->hw_rx_port_stats_map
);
2374 bp
->hw_rx_port_stats
= NULL
;
2375 bp
->flags
&= ~BNXT_FLAG_PORT_STATS
;
2381 size
= sizeof(struct ctx_hw_stats
);
2383 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2384 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2385 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2387 if (cpr
->hw_stats
) {
2388 dma_free_coherent(&pdev
->dev
, size
, cpr
->hw_stats
,
2390 cpr
->hw_stats
= NULL
;
2395 static int bnxt_alloc_stats(struct bnxt
*bp
)
2398 struct pci_dev
*pdev
= bp
->pdev
;
2400 size
= sizeof(struct ctx_hw_stats
);
2402 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2403 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2404 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2406 cpr
->hw_stats
= dma_alloc_coherent(&pdev
->dev
, size
,
2412 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
2416 bp
->hw_port_stats_size
= sizeof(struct rx_port_stats
) +
2417 sizeof(struct tx_port_stats
) + 1024;
2419 bp
->hw_rx_port_stats
=
2420 dma_alloc_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
2421 &bp
->hw_rx_port_stats_map
,
2423 if (!bp
->hw_rx_port_stats
)
2426 bp
->hw_tx_port_stats
= (void *)(bp
->hw_rx_port_stats
+ 1) +
2428 bp
->hw_tx_port_stats_map
= bp
->hw_rx_port_stats_map
+
2429 sizeof(struct rx_port_stats
) + 512;
2430 bp
->flags
|= BNXT_FLAG_PORT_STATS
;
2435 static void bnxt_clear_ring_indices(struct bnxt
*bp
)
2442 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2443 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2444 struct bnxt_cp_ring_info
*cpr
;
2445 struct bnxt_rx_ring_info
*rxr
;
2446 struct bnxt_tx_ring_info
*txr
;
2451 cpr
= &bnapi
->cp_ring
;
2452 cpr
->cp_raw_cons
= 0;
2454 txr
= bnapi
->tx_ring
;
2460 rxr
= bnapi
->rx_ring
;
2463 rxr
->rx_agg_prod
= 0;
2464 rxr
->rx_sw_agg_prod
= 0;
2469 static void bnxt_free_ntp_fltrs(struct bnxt
*bp
, bool irq_reinit
)
2471 #ifdef CONFIG_RFS_ACCEL
2474 /* Under rtnl_lock and all our NAPIs have been disabled. It's
2475 * safe to delete the hash table.
2477 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
2478 struct hlist_head
*head
;
2479 struct hlist_node
*tmp
;
2480 struct bnxt_ntuple_filter
*fltr
;
2482 head
= &bp
->ntp_fltr_hash_tbl
[i
];
2483 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
2484 hlist_del(&fltr
->hash
);
2489 kfree(bp
->ntp_fltr_bmap
);
2490 bp
->ntp_fltr_bmap
= NULL
;
2492 bp
->ntp_fltr_count
= 0;
2496 static int bnxt_alloc_ntp_fltrs(struct bnxt
*bp
)
2498 #ifdef CONFIG_RFS_ACCEL
2501 if (!(bp
->flags
& BNXT_FLAG_RFS
))
2504 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++)
2505 INIT_HLIST_HEAD(&bp
->ntp_fltr_hash_tbl
[i
]);
2507 bp
->ntp_fltr_count
= 0;
2508 bp
->ntp_fltr_bmap
= kzalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR
),
2511 if (!bp
->ntp_fltr_bmap
)
2520 static void bnxt_free_mem(struct bnxt
*bp
, bool irq_re_init
)
2522 bnxt_free_vnic_attributes(bp
);
2523 bnxt_free_tx_rings(bp
);
2524 bnxt_free_rx_rings(bp
);
2525 bnxt_free_cp_rings(bp
);
2526 bnxt_free_ntp_fltrs(bp
, irq_re_init
);
2528 bnxt_free_stats(bp
);
2529 bnxt_free_ring_grps(bp
);
2530 bnxt_free_vnics(bp
);
2538 bnxt_clear_ring_indices(bp
);
2542 static int bnxt_alloc_mem(struct bnxt
*bp
, bool irq_re_init
)
2544 int i
, j
, rc
, size
, arr_size
;
2548 /* Allocate bnapi mem pointer array and mem block for
2551 arr_size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
*) *
2553 size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
));
2554 bnapi
= kzalloc(arr_size
+ size
* bp
->cp_nr_rings
, GFP_KERNEL
);
2560 for (i
= 0; i
< bp
->cp_nr_rings
; i
++, bnapi
+= size
) {
2561 bp
->bnapi
[i
] = bnapi
;
2562 bp
->bnapi
[i
]->index
= i
;
2563 bp
->bnapi
[i
]->bp
= bp
;
2566 bp
->rx_ring
= kcalloc(bp
->rx_nr_rings
,
2567 sizeof(struct bnxt_rx_ring_info
),
2572 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2573 bp
->rx_ring
[i
].bnapi
= bp
->bnapi
[i
];
2574 bp
->bnapi
[i
]->rx_ring
= &bp
->rx_ring
[i
];
2577 bp
->tx_ring
= kcalloc(bp
->tx_nr_rings
,
2578 sizeof(struct bnxt_tx_ring_info
),
2583 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
2586 j
= bp
->rx_nr_rings
;
2588 for (i
= 0; i
< bp
->tx_nr_rings
; i
++, j
++) {
2589 bp
->tx_ring
[i
].bnapi
= bp
->bnapi
[j
];
2590 bp
->bnapi
[j
]->tx_ring
= &bp
->tx_ring
[i
];
2593 rc
= bnxt_alloc_stats(bp
);
2597 rc
= bnxt_alloc_ntp_fltrs(bp
);
2601 rc
= bnxt_alloc_vnics(bp
);
2606 bnxt_init_ring_struct(bp
);
2608 rc
= bnxt_alloc_rx_rings(bp
);
2612 rc
= bnxt_alloc_tx_rings(bp
);
2616 rc
= bnxt_alloc_cp_rings(bp
);
2620 bp
->vnic_info
[0].flags
|= BNXT_VNIC_RSS_FLAG
| BNXT_VNIC_MCAST_FLAG
|
2621 BNXT_VNIC_UCAST_FLAG
;
2622 rc
= bnxt_alloc_vnic_attributes(bp
);
2628 bnxt_free_mem(bp
, true);
2632 void bnxt_hwrm_cmd_hdr_init(struct bnxt
*bp
, void *request
, u16 req_type
,
2633 u16 cmpl_ring
, u16 target_id
)
2635 struct input
*req
= request
;
2637 req
->req_type
= cpu_to_le16(req_type
);
2638 req
->cmpl_ring
= cpu_to_le16(cmpl_ring
);
2639 req
->target_id
= cpu_to_le16(target_id
);
2640 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_resp_dma_addr
);
2643 static int bnxt_hwrm_do_send_msg(struct bnxt
*bp
, void *msg
, u32 msg_len
,
2644 int timeout
, bool silent
)
2646 int i
, intr_process
, rc
;
2647 struct input
*req
= msg
;
2649 __le32
*resp_len
, *valid
;
2650 u16 cp_ring_id
, len
= 0;
2651 struct hwrm_err_output
*resp
= bp
->hwrm_cmd_resp_addr
;
2653 req
->seq_id
= cpu_to_le16(bp
->hwrm_cmd_seq
++);
2654 memset(resp
, 0, PAGE_SIZE
);
2655 cp_ring_id
= le16_to_cpu(req
->cmpl_ring
);
2656 intr_process
= (cp_ring_id
== INVALID_HW_RING_ID
) ? 0 : 1;
2658 /* Write request msg to hwrm channel */
2659 __iowrite32_copy(bp
->bar0
, data
, msg_len
/ 4);
2661 for (i
= msg_len
; i
< BNXT_HWRM_MAX_REQ_LEN
; i
+= 4)
2662 writel(0, bp
->bar0
+ i
);
2664 /* currently supports only one outstanding message */
2666 bp
->hwrm_intr_seq_id
= le16_to_cpu(req
->seq_id
);
2668 /* Ring channel doorbell */
2669 writel(1, bp
->bar0
+ 0x100);
2672 timeout
= DFLT_HWRM_CMD_TIMEOUT
;
2676 /* Wait until hwrm response cmpl interrupt is processed */
2677 while (bp
->hwrm_intr_seq_id
!= HWRM_SEQ_ID_INVALID
&&
2679 usleep_range(600, 800);
2682 if (bp
->hwrm_intr_seq_id
!= HWRM_SEQ_ID_INVALID
) {
2683 netdev_err(bp
->dev
, "Resp cmpl intr err msg: 0x%x\n",
2684 le16_to_cpu(req
->req_type
));
2688 /* Check if response len is updated */
2689 resp_len
= bp
->hwrm_cmd_resp_addr
+ HWRM_RESP_LEN_OFFSET
;
2690 for (i
= 0; i
< timeout
; i
++) {
2691 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
2695 usleep_range(600, 800);
2699 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
2700 timeout
, le16_to_cpu(req
->req_type
),
2701 le16_to_cpu(req
->seq_id
), *resp_len
);
2705 /* Last word of resp contains valid bit */
2706 valid
= bp
->hwrm_cmd_resp_addr
+ len
- 4;
2707 for (i
= 0; i
< timeout
; i
++) {
2708 if (le32_to_cpu(*valid
) & HWRM_RESP_VALID_MASK
)
2710 usleep_range(600, 800);
2714 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
2715 timeout
, le16_to_cpu(req
->req_type
),
2716 le16_to_cpu(req
->seq_id
), len
, *valid
);
2721 rc
= le16_to_cpu(resp
->error_code
);
2723 netdev_err(bp
->dev
, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
2724 le16_to_cpu(resp
->req_type
),
2725 le16_to_cpu(resp
->seq_id
), rc
);
2729 int _hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
2731 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, false);
2734 int hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
2738 mutex_lock(&bp
->hwrm_cmd_lock
);
2739 rc
= _hwrm_send_message(bp
, msg
, msg_len
, timeout
);
2740 mutex_unlock(&bp
->hwrm_cmd_lock
);
2744 int hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
2749 mutex_lock(&bp
->hwrm_cmd_lock
);
2750 rc
= bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
2751 mutex_unlock(&bp
->hwrm_cmd_lock
);
2755 static int bnxt_hwrm_func_drv_rgtr(struct bnxt
*bp
)
2757 struct hwrm_func_drv_rgtr_input req
= {0};
2759 DECLARE_BITMAP(async_events_bmap
, 256);
2760 u32
*events
= (u32
*)async_events_bmap
;
2762 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
2765 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE
|
2766 FUNC_DRV_RGTR_REQ_ENABLES_VER
|
2767 FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
2769 memset(async_events_bmap
, 0, sizeof(async_events_bmap
));
2770 for (i
= 0; i
< ARRAY_SIZE(bnxt_async_events_arr
); i
++)
2771 __set_bit(bnxt_async_events_arr
[i
], async_events_bmap
);
2773 for (i
= 0; i
< 8; i
++)
2774 req
.async_event_fwd
[i
] |= cpu_to_le32(events
[i
]);
2776 req
.os_type
= cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX
);
2777 req
.ver_maj
= DRV_VER_MAJ
;
2778 req
.ver_min
= DRV_VER_MIN
;
2779 req
.ver_upd
= DRV_VER_UPD
;
2782 DECLARE_BITMAP(vf_req_snif_bmap
, 256);
2783 u32
*data
= (u32
*)vf_req_snif_bmap
;
2785 memset(vf_req_snif_bmap
, 0, sizeof(vf_req_snif_bmap
));
2786 for (i
= 0; i
< ARRAY_SIZE(bnxt_vf_req_snif
); i
++)
2787 __set_bit(bnxt_vf_req_snif
[i
], vf_req_snif_bmap
);
2789 for (i
= 0; i
< 8; i
++)
2790 req
.vf_req_fwd
[i
] = cpu_to_le32(data
[i
]);
2793 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD
);
2796 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2799 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt
*bp
)
2801 struct hwrm_func_drv_unrgtr_input req
= {0};
2803 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_UNRGTR
, -1, -1);
2804 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2807 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt
*bp
, u8 tunnel_type
)
2810 struct hwrm_tunnel_dst_port_free_input req
= {0};
2812 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_FREE
, -1, -1);
2813 req
.tunnel_type
= tunnel_type
;
2815 switch (tunnel_type
) {
2816 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
:
2817 req
.tunnel_dst_port_id
= bp
->vxlan_fw_dst_port_id
;
2819 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
:
2820 req
.tunnel_dst_port_id
= bp
->nge_fw_dst_port_id
;
2826 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2828 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
2833 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt
*bp
, __be16 port
,
2837 struct hwrm_tunnel_dst_port_alloc_input req
= {0};
2838 struct hwrm_tunnel_dst_port_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
2840 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_ALLOC
, -1, -1);
2842 req
.tunnel_type
= tunnel_type
;
2843 req
.tunnel_dst_port_val
= port
;
2845 mutex_lock(&bp
->hwrm_cmd_lock
);
2846 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2848 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
2853 if (tunnel_type
& TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN
)
2854 bp
->vxlan_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
2856 else if (tunnel_type
& TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE
)
2857 bp
->nge_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
2859 mutex_unlock(&bp
->hwrm_cmd_lock
);
2863 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt
*bp
, u16 vnic_id
)
2865 struct hwrm_cfa_l2_set_rx_mask_input req
= {0};
2866 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
2868 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_SET_RX_MASK
, -1, -1);
2869 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
2871 req
.num_mc_entries
= cpu_to_le32(vnic
->mc_list_count
);
2872 req
.mc_tbl_addr
= cpu_to_le64(vnic
->mc_list_mapping
);
2873 req
.mask
= cpu_to_le32(vnic
->rx_mask
);
2874 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2877 #ifdef CONFIG_RFS_ACCEL
2878 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt
*bp
,
2879 struct bnxt_ntuple_filter
*fltr
)
2881 struct hwrm_cfa_ntuple_filter_free_input req
= {0};
2883 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_FREE
, -1, -1);
2884 req
.ntuple_filter_id
= fltr
->filter_id
;
2885 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2888 #define BNXT_NTP_FLTR_FLAGS \
2889 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
2890 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
2891 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
2892 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
2893 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
2894 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
2895 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
2896 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
2897 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
2898 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
2899 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
2900 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
2901 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
2902 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
2904 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt
*bp
,
2905 struct bnxt_ntuple_filter
*fltr
)
2908 struct hwrm_cfa_ntuple_filter_alloc_input req
= {0};
2909 struct hwrm_cfa_ntuple_filter_alloc_output
*resp
=
2910 bp
->hwrm_cmd_resp_addr
;
2911 struct flow_keys
*keys
= &fltr
->fkeys
;
2912 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[fltr
->rxq
+ 1];
2914 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_ALLOC
, -1, -1);
2915 req
.l2_filter_id
= bp
->vnic_info
[0].fw_l2_filter_id
[0];
2917 req
.enables
= cpu_to_le32(BNXT_NTP_FLTR_FLAGS
);
2919 req
.ethertype
= htons(ETH_P_IP
);
2920 memcpy(req
.src_macaddr
, fltr
->src_mac_addr
, ETH_ALEN
);
2921 req
.ip_addr_type
= CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4
;
2922 req
.ip_protocol
= keys
->basic
.ip_proto
;
2924 req
.src_ipaddr
[0] = keys
->addrs
.v4addrs
.src
;
2925 req
.src_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
2926 req
.dst_ipaddr
[0] = keys
->addrs
.v4addrs
.dst
;
2927 req
.dst_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
2929 req
.src_port
= keys
->ports
.src
;
2930 req
.src_port_mask
= cpu_to_be16(0xffff);
2931 req
.dst_port
= keys
->ports
.dst
;
2932 req
.dst_port_mask
= cpu_to_be16(0xffff);
2934 req
.dst_id
= cpu_to_le16(vnic
->fw_vnic_id
);
2935 mutex_lock(&bp
->hwrm_cmd_lock
);
2936 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2938 fltr
->filter_id
= resp
->ntuple_filter_id
;
2939 mutex_unlock(&bp
->hwrm_cmd_lock
);
2944 static int bnxt_hwrm_set_vnic_filter(struct bnxt
*bp
, u16 vnic_id
, u16 idx
,
2948 struct hwrm_cfa_l2_filter_alloc_input req
= {0};
2949 struct hwrm_cfa_l2_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
2951 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_ALLOC
, -1, -1);
2952 req
.flags
= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX
|
2953 CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST
);
2954 req
.dst_id
= cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
2956 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR
|
2957 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID
|
2958 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK
);
2959 memcpy(req
.l2_addr
, mac_addr
, ETH_ALEN
);
2960 req
.l2_addr_mask
[0] = 0xff;
2961 req
.l2_addr_mask
[1] = 0xff;
2962 req
.l2_addr_mask
[2] = 0xff;
2963 req
.l2_addr_mask
[3] = 0xff;
2964 req
.l2_addr_mask
[4] = 0xff;
2965 req
.l2_addr_mask
[5] = 0xff;
2967 mutex_lock(&bp
->hwrm_cmd_lock
);
2968 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2970 bp
->vnic_info
[vnic_id
].fw_l2_filter_id
[idx
] =
2972 mutex_unlock(&bp
->hwrm_cmd_lock
);
2976 static int bnxt_hwrm_clear_vnic_filter(struct bnxt
*bp
)
2978 u16 i
, j
, num_of_vnics
= 1; /* only vnic 0 supported */
2981 /* Any associated ntuple filters will also be cleared by firmware. */
2982 mutex_lock(&bp
->hwrm_cmd_lock
);
2983 for (i
= 0; i
< num_of_vnics
; i
++) {
2984 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
2986 for (j
= 0; j
< vnic
->uc_filter_count
; j
++) {
2987 struct hwrm_cfa_l2_filter_free_input req
= {0};
2989 bnxt_hwrm_cmd_hdr_init(bp
, &req
,
2990 HWRM_CFA_L2_FILTER_FREE
, -1, -1);
2992 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[j
];
2994 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
2997 vnic
->uc_filter_count
= 0;
2999 mutex_unlock(&bp
->hwrm_cmd_lock
);
3004 static int bnxt_hwrm_vnic_set_tpa(struct bnxt
*bp
, u16 vnic_id
, u32 tpa_flags
)
3006 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3007 struct hwrm_vnic_tpa_cfg_input req
= {0};
3009 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_TPA_CFG
, -1, -1);
3012 u16 mss
= bp
->dev
->mtu
- 40;
3013 u32 nsegs
, n
, segs
= 0, flags
;
3015 flags
= VNIC_TPA_CFG_REQ_FLAGS_TPA
|
3016 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA
|
3017 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE
|
3018 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN
|
3019 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ
;
3020 if (tpa_flags
& BNXT_FLAG_GRO
)
3021 flags
|= VNIC_TPA_CFG_REQ_FLAGS_GRO
;
3023 req
.flags
= cpu_to_le32(flags
);
3026 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS
|
3027 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS
|
3028 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN
);
3030 /* Number of segs are log2 units, and first packet is not
3031 * included as part of this units.
3033 if (mss
<= PAGE_SIZE
) {
3034 n
= PAGE_SIZE
/ mss
;
3035 nsegs
= (MAX_SKB_FRAGS
- 1) * n
;
3037 n
= mss
/ PAGE_SIZE
;
3038 if (mss
& (PAGE_SIZE
- 1))
3040 nsegs
= (MAX_SKB_FRAGS
- n
) / n
;
3043 segs
= ilog2(nsegs
);
3044 req
.max_agg_segs
= cpu_to_le16(segs
);
3045 req
.max_aggs
= cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX
);
3047 req
.min_agg_len
= cpu_to_le32(512);
3049 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
3051 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3054 static int bnxt_hwrm_vnic_set_rss(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
3056 u32 i
, j
, max_rings
;
3057 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3058 struct hwrm_vnic_rss_cfg_input req
= {0};
3060 if (vnic
->fw_rss_cos_lb_ctx
== INVALID_HW_RING_ID
)
3063 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
3065 vnic
->hash_type
= BNXT_RSS_HASH_TYPE_FLAG_IPV4
|
3066 BNXT_RSS_HASH_TYPE_FLAG_TCP_IPV4
|
3067 BNXT_RSS_HASH_TYPE_FLAG_IPV6
|
3068 BNXT_RSS_HASH_TYPE_FLAG_TCP_IPV6
;
3070 req
.hash_type
= cpu_to_le32(vnic
->hash_type
);
3072 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3073 max_rings
= bp
->rx_nr_rings
;
3077 /* Fill the RSS indirection table with ring group ids */
3078 for (i
= 0, j
= 0; i
< HW_HASH_INDEX_SIZE
; i
++, j
++) {
3081 vnic
->rss_table
[i
] = cpu_to_le16(vnic
->fw_grp_ids
[j
]);
3084 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
3085 req
.hash_key_tbl_addr
=
3086 cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
3088 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
);
3089 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3092 static int bnxt_hwrm_vnic_set_hds(struct bnxt
*bp
, u16 vnic_id
)
3094 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3095 struct hwrm_vnic_plcmodes_cfg_input req
= {0};
3097 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_PLCMODES_CFG
, -1, -1);
3098 req
.flags
= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT
|
3099 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4
|
3100 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6
);
3102 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID
|
3103 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID
);
3104 /* thresholds not implemented in firmware yet */
3105 req
.jumbo_thresh
= cpu_to_le16(bp
->rx_copy_thresh
);
3106 req
.hds_threshold
= cpu_to_le16(bp
->rx_copy_thresh
);
3107 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
3108 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3111 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt
*bp
, u16 vnic_id
)
3113 struct hwrm_vnic_rss_cos_lb_ctx_free_input req
= {0};
3115 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_FREE
, -1, -1);
3116 req
.rss_cos_lb_ctx_id
=
3117 cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
);
3119 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3120 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
= INVALID_HW_RING_ID
;
3123 static void bnxt_hwrm_vnic_ctx_free(struct bnxt
*bp
)
3127 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3128 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
3130 if (vnic
->fw_rss_cos_lb_ctx
!= INVALID_HW_RING_ID
)
3131 bnxt_hwrm_vnic_ctx_free_one(bp
, i
);
3133 bp
->rsscos_nr_ctxs
= 0;
3136 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt
*bp
, u16 vnic_id
)
3139 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req
= {0};
3140 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output
*resp
=
3141 bp
->hwrm_cmd_resp_addr
;
3143 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC
, -1,
3146 mutex_lock(&bp
->hwrm_cmd_lock
);
3147 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3149 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
=
3150 le16_to_cpu(resp
->rss_cos_lb_ctx_id
);
3151 mutex_unlock(&bp
->hwrm_cmd_lock
);
3156 static int bnxt_hwrm_vnic_cfg(struct bnxt
*bp
, u16 vnic_id
)
3158 unsigned int ring
= 0, grp_idx
;
3159 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3160 struct hwrm_vnic_cfg_input req
= {0};
3162 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_CFG
, -1, -1);
3163 /* Only RSS support for now TBD: COS & LB */
3164 req
.enables
= cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP
|
3165 VNIC_CFG_REQ_ENABLES_RSS_RULE
);
3166 req
.rss_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
);
3167 req
.cos_rule
= cpu_to_le16(0xffff);
3168 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3170 else if (vnic
->flags
& BNXT_VNIC_RFS_FLAG
)
3173 grp_idx
= bp
->rx_ring
[ring
].bnapi
->index
;
3174 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
3175 req
.dflt_ring_grp
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_grp_id
);
3177 req
.lb_rule
= cpu_to_le16(0xffff);
3178 req
.mru
= cpu_to_le16(bp
->dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+
3181 if (bp
->flags
& BNXT_FLAG_STRIP_VLAN
)
3182 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE
);
3184 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3187 static int bnxt_hwrm_vnic_free_one(struct bnxt
*bp
, u16 vnic_id
)
3191 if (bp
->vnic_info
[vnic_id
].fw_vnic_id
!= INVALID_HW_RING_ID
) {
3192 struct hwrm_vnic_free_input req
= {0};
3194 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_FREE
, -1, -1);
3196 cpu_to_le32(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
3198 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3201 bp
->vnic_info
[vnic_id
].fw_vnic_id
= INVALID_HW_RING_ID
;
3206 static void bnxt_hwrm_vnic_free(struct bnxt
*bp
)
3210 for (i
= 0; i
< bp
->nr_vnics
; i
++)
3211 bnxt_hwrm_vnic_free_one(bp
, i
);
3214 static int bnxt_hwrm_vnic_alloc(struct bnxt
*bp
, u16 vnic_id
,
3215 unsigned int start_rx_ring_idx
,
3216 unsigned int nr_rings
)
3219 unsigned int i
, j
, grp_idx
, end_idx
= start_rx_ring_idx
+ nr_rings
;
3220 struct hwrm_vnic_alloc_input req
= {0};
3221 struct hwrm_vnic_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3223 /* map ring groups to this vnic */
3224 for (i
= start_rx_ring_idx
, j
= 0; i
< end_idx
; i
++, j
++) {
3225 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
3226 if (bp
->grp_info
[grp_idx
].fw_grp_id
== INVALID_HW_RING_ID
) {
3227 netdev_err(bp
->dev
, "Not enough ring groups avail:%x req:%x\n",
3231 bp
->vnic_info
[vnic_id
].fw_grp_ids
[j
] =
3232 bp
->grp_info
[grp_idx
].fw_grp_id
;
3235 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
= INVALID_HW_RING_ID
;
3237 req
.flags
= cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT
);
3239 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_ALLOC
, -1, -1);
3241 mutex_lock(&bp
->hwrm_cmd_lock
);
3242 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3244 bp
->vnic_info
[vnic_id
].fw_vnic_id
= le32_to_cpu(resp
->vnic_id
);
3245 mutex_unlock(&bp
->hwrm_cmd_lock
);
3249 static int bnxt_hwrm_ring_grp_alloc(struct bnxt
*bp
)
3254 mutex_lock(&bp
->hwrm_cmd_lock
);
3255 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3256 struct hwrm_ring_grp_alloc_input req
= {0};
3257 struct hwrm_ring_grp_alloc_output
*resp
=
3258 bp
->hwrm_cmd_resp_addr
;
3259 unsigned int grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
3261 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_ALLOC
, -1, -1);
3263 req
.cr
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
3264 req
.rr
= cpu_to_le16(bp
->grp_info
[grp_idx
].rx_fw_ring_id
);
3265 req
.ar
= cpu_to_le16(bp
->grp_info
[grp_idx
].agg_fw_ring_id
);
3266 req
.sc
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_stats_ctx
);
3268 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
3273 bp
->grp_info
[grp_idx
].fw_grp_id
=
3274 le32_to_cpu(resp
->ring_group_id
);
3276 mutex_unlock(&bp
->hwrm_cmd_lock
);
3280 static int bnxt_hwrm_ring_grp_free(struct bnxt
*bp
)
3284 struct hwrm_ring_grp_free_input req
= {0};
3289 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_FREE
, -1, -1);
3291 mutex_lock(&bp
->hwrm_cmd_lock
);
3292 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3293 if (bp
->grp_info
[i
].fw_grp_id
== INVALID_HW_RING_ID
)
3296 cpu_to_le32(bp
->grp_info
[i
].fw_grp_id
);
3298 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
3302 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
3304 mutex_unlock(&bp
->hwrm_cmd_lock
);
3308 static int hwrm_ring_alloc_send_msg(struct bnxt
*bp
,
3309 struct bnxt_ring_struct
*ring
,
3310 u32 ring_type
, u32 map_index
,
3313 int rc
= 0, err
= 0;
3314 struct hwrm_ring_alloc_input req
= {0};
3315 struct hwrm_ring_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3318 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_ALLOC
, -1, -1);
3321 if (ring
->nr_pages
> 1) {
3322 req
.page_tbl_addr
= cpu_to_le64(ring
->pg_tbl_map
);
3323 /* Page size is in log2 units */
3324 req
.page_size
= BNXT_PAGE_SHIFT
;
3325 req
.page_tbl_depth
= 1;
3327 req
.page_tbl_addr
= cpu_to_le64(ring
->dma_arr
[0]);
3330 /* Association of ring index with doorbell index and MSIX number */
3331 req
.logical_id
= cpu_to_le16(map_index
);
3333 switch (ring_type
) {
3334 case HWRM_RING_ALLOC_TX
:
3335 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_TX
;
3336 /* Association of transmit ring with completion ring */
3338 cpu_to_le16(bp
->grp_info
[map_index
].cp_fw_ring_id
);
3339 req
.length
= cpu_to_le32(bp
->tx_ring_mask
+ 1);
3340 req
.stat_ctx_id
= cpu_to_le32(stats_ctx_id
);
3341 req
.queue_id
= cpu_to_le16(ring
->queue_id
);
3343 case HWRM_RING_ALLOC_RX
:
3344 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
3345 req
.length
= cpu_to_le32(bp
->rx_ring_mask
+ 1);
3347 case HWRM_RING_ALLOC_AGG
:
3348 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
3349 req
.length
= cpu_to_le32(bp
->rx_agg_ring_mask
+ 1);
3351 case HWRM_RING_ALLOC_CMPL
:
3352 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_CMPL
;
3353 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
3354 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
3355 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
3358 netdev_err(bp
->dev
, "hwrm alloc invalid ring type %d\n",
3363 mutex_lock(&bp
->hwrm_cmd_lock
);
3364 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3365 err
= le16_to_cpu(resp
->error_code
);
3366 ring_id
= le16_to_cpu(resp
->ring_id
);
3367 mutex_unlock(&bp
->hwrm_cmd_lock
);
3370 switch (ring_type
) {
3371 case RING_FREE_REQ_RING_TYPE_CMPL
:
3372 netdev_err(bp
->dev
, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
3376 case RING_FREE_REQ_RING_TYPE_RX
:
3377 netdev_err(bp
->dev
, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
3381 case RING_FREE_REQ_RING_TYPE_TX
:
3382 netdev_err(bp
->dev
, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
3387 netdev_err(bp
->dev
, "Invalid ring\n");
3391 ring
->fw_ring_id
= ring_id
;
3395 static int bnxt_hwrm_ring_alloc(struct bnxt
*bp
)
3399 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3400 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3401 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3402 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3404 cpr
->cp_doorbell
= bp
->bar1
+ i
* 0x80;
3405 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_CMPL
, i
,
3406 INVALID_STATS_CTX_ID
);
3409 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
3410 bp
->grp_info
[i
].cp_fw_ring_id
= ring
->fw_ring_id
;
3413 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
3414 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3415 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
3416 u32 map_idx
= txr
->bnapi
->index
;
3417 u16 fw_stats_ctx
= bp
->grp_info
[map_idx
].fw_stats_ctx
;
3419 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_TX
,
3420 map_idx
, fw_stats_ctx
);
3423 txr
->tx_doorbell
= bp
->bar1
+ map_idx
* 0x80;
3426 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3427 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3428 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
3429 u32 map_idx
= rxr
->bnapi
->index
;
3431 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_RX
,
3432 map_idx
, INVALID_STATS_CTX_ID
);
3435 rxr
->rx_doorbell
= bp
->bar1
+ map_idx
* 0x80;
3436 writel(DB_KEY_RX
| rxr
->rx_prod
, rxr
->rx_doorbell
);
3437 bp
->grp_info
[map_idx
].rx_fw_ring_id
= ring
->fw_ring_id
;
3440 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
3441 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3442 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3443 struct bnxt_ring_struct
*ring
=
3444 &rxr
->rx_agg_ring_struct
;
3445 u32 grp_idx
= rxr
->bnapi
->index
;
3446 u32 map_idx
= grp_idx
+ bp
->rx_nr_rings
;
3448 rc
= hwrm_ring_alloc_send_msg(bp
, ring
,
3449 HWRM_RING_ALLOC_AGG
,
3451 INVALID_STATS_CTX_ID
);
3455 rxr
->rx_agg_doorbell
= bp
->bar1
+ map_idx
* 0x80;
3456 writel(DB_KEY_RX
| rxr
->rx_agg_prod
,
3457 rxr
->rx_agg_doorbell
);
3458 bp
->grp_info
[grp_idx
].agg_fw_ring_id
= ring
->fw_ring_id
;
3465 static int hwrm_ring_free_send_msg(struct bnxt
*bp
,
3466 struct bnxt_ring_struct
*ring
,
3467 u32 ring_type
, int cmpl_ring_id
)
3470 struct hwrm_ring_free_input req
= {0};
3471 struct hwrm_ring_free_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3474 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_FREE
, cmpl_ring_id
, -1);
3475 req
.ring_type
= ring_type
;
3476 req
.ring_id
= cpu_to_le16(ring
->fw_ring_id
);
3478 mutex_lock(&bp
->hwrm_cmd_lock
);
3479 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3480 error_code
= le16_to_cpu(resp
->error_code
);
3481 mutex_unlock(&bp
->hwrm_cmd_lock
);
3483 if (rc
|| error_code
) {
3484 switch (ring_type
) {
3485 case RING_FREE_REQ_RING_TYPE_CMPL
:
3486 netdev_err(bp
->dev
, "hwrm_ring_free cp failed. rc:%d\n",
3489 case RING_FREE_REQ_RING_TYPE_RX
:
3490 netdev_err(bp
->dev
, "hwrm_ring_free rx failed. rc:%d\n",
3493 case RING_FREE_REQ_RING_TYPE_TX
:
3494 netdev_err(bp
->dev
, "hwrm_ring_free tx failed. rc:%d\n",
3498 netdev_err(bp
->dev
, "Invalid ring\n");
3505 static void bnxt_hwrm_ring_free(struct bnxt
*bp
, bool close_path
)
3512 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
3513 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3514 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
3515 u32 grp_idx
= txr
->bnapi
->index
;
3516 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
3518 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
3519 hwrm_ring_free_send_msg(bp
, ring
,
3520 RING_FREE_REQ_RING_TYPE_TX
,
3521 close_path
? cmpl_ring_id
:
3522 INVALID_HW_RING_ID
);
3523 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3527 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3528 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3529 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
3530 u32 grp_idx
= rxr
->bnapi
->index
;
3531 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
3533 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
3534 hwrm_ring_free_send_msg(bp
, ring
,
3535 RING_FREE_REQ_RING_TYPE_RX
,
3536 close_path
? cmpl_ring_id
:
3537 INVALID_HW_RING_ID
);
3538 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3539 bp
->grp_info
[grp_idx
].rx_fw_ring_id
=
3544 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3545 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3546 struct bnxt_ring_struct
*ring
= &rxr
->rx_agg_ring_struct
;
3547 u32 grp_idx
= rxr
->bnapi
->index
;
3548 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
3550 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
3551 hwrm_ring_free_send_msg(bp
, ring
,
3552 RING_FREE_REQ_RING_TYPE_RX
,
3553 close_path
? cmpl_ring_id
:
3554 INVALID_HW_RING_ID
);
3555 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3556 bp
->grp_info
[grp_idx
].agg_fw_ring_id
=
3561 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3562 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3563 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3564 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3566 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
3567 hwrm_ring_free_send_msg(bp
, ring
,
3568 RING_FREE_REQ_RING_TYPE_CMPL
,
3569 INVALID_HW_RING_ID
);
3570 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3571 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
3576 static void bnxt_hwrm_set_coal_params(struct bnxt
*bp
, u32 max_bufs
,
3577 u32 buf_tmrs
, u16 flags
,
3578 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input
*req
)
3580 req
->flags
= cpu_to_le16(flags
);
3581 req
->num_cmpl_dma_aggr
= cpu_to_le16((u16
)max_bufs
);
3582 req
->num_cmpl_dma_aggr_during_int
= cpu_to_le16(max_bufs
>> 16);
3583 req
->cmpl_aggr_dma_tmr
= cpu_to_le16((u16
)buf_tmrs
);
3584 req
->cmpl_aggr_dma_tmr_during_int
= cpu_to_le16(buf_tmrs
>> 16);
3585 /* Minimum time between 2 interrupts set to buf_tmr x 2 */
3586 req
->int_lat_tmr_min
= cpu_to_le16((u16
)buf_tmrs
* 2);
3587 req
->int_lat_tmr_max
= cpu_to_le16((u16
)buf_tmrs
* 4);
3588 req
->num_cmpl_aggr_int
= cpu_to_le16((u16
)max_bufs
* 4);
3591 int bnxt_hwrm_set_coal(struct bnxt
*bp
)
3594 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0},
3596 u16 max_buf
, max_buf_irq
;
3597 u16 buf_tmr
, buf_tmr_irq
;
3600 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
3601 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
3602 bnxt_hwrm_cmd_hdr_init(bp
, &req_tx
,
3603 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
3605 /* Each rx completion (2 records) should be DMAed immediately.
3606 * DMA 1/4 of the completion buffers at a time.
3608 max_buf
= min_t(u16
, bp
->rx_coal_bufs
/ 4, 2);
3609 /* max_buf must not be zero */
3610 max_buf
= clamp_t(u16
, max_buf
, 1, 63);
3611 max_buf_irq
= clamp_t(u16
, bp
->rx_coal_bufs_irq
, 1, 63);
3612 buf_tmr
= BNXT_USEC_TO_COAL_TIMER(bp
->rx_coal_ticks
);
3613 /* buf timer set to 1/4 of interrupt timer */
3614 buf_tmr
= max_t(u16
, buf_tmr
/ 4, 1);
3615 buf_tmr_irq
= BNXT_USEC_TO_COAL_TIMER(bp
->rx_coal_ticks_irq
);
3616 buf_tmr_irq
= max_t(u16
, buf_tmr_irq
, 1);
3618 flags
= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
3620 /* RING_IDLE generates more IRQs for lower latency. Enable it only
3621 * if coal_ticks is less than 25 us.
3623 if (bp
->rx_coal_ticks
< 25)
3624 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE
;
3626 bnxt_hwrm_set_coal_params(bp
, max_buf_irq
<< 16 | max_buf
,
3627 buf_tmr_irq
<< 16 | buf_tmr
, flags
, &req_rx
);
3629 /* max_buf must not be zero */
3630 max_buf
= clamp_t(u16
, bp
->tx_coal_bufs
, 1, 63);
3631 max_buf_irq
= clamp_t(u16
, bp
->tx_coal_bufs_irq
, 1, 63);
3632 buf_tmr
= BNXT_USEC_TO_COAL_TIMER(bp
->tx_coal_ticks
);
3633 /* buf timer set to 1/4 of interrupt timer */
3634 buf_tmr
= max_t(u16
, buf_tmr
/ 4, 1);
3635 buf_tmr_irq
= BNXT_USEC_TO_COAL_TIMER(bp
->tx_coal_ticks_irq
);
3636 buf_tmr_irq
= max_t(u16
, buf_tmr_irq
, 1);
3638 flags
= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
3639 bnxt_hwrm_set_coal_params(bp
, max_buf_irq
<< 16 | max_buf
,
3640 buf_tmr_irq
<< 16 | buf_tmr
, flags
, &req_tx
);
3642 mutex_lock(&bp
->hwrm_cmd_lock
);
3643 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3644 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3647 if (!bnapi
->rx_ring
)
3649 req
->ring_id
= cpu_to_le16(bp
->grp_info
[i
].cp_fw_ring_id
);
3651 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
3656 mutex_unlock(&bp
->hwrm_cmd_lock
);
3660 static int bnxt_hwrm_stat_ctx_free(struct bnxt
*bp
)
3663 struct hwrm_stat_ctx_free_input req
= {0};
3668 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_FREE
, -1, -1);
3670 mutex_lock(&bp
->hwrm_cmd_lock
);
3671 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3672 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3673 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3675 if (cpr
->hw_stats_ctx_id
!= INVALID_STATS_CTX_ID
) {
3676 req
.stat_ctx_id
= cpu_to_le32(cpr
->hw_stats_ctx_id
);
3678 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
3683 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
3686 mutex_unlock(&bp
->hwrm_cmd_lock
);
3690 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt
*bp
)
3693 struct hwrm_stat_ctx_alloc_input req
= {0};
3694 struct hwrm_stat_ctx_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3696 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_ALLOC
, -1, -1);
3698 req
.update_period_ms
= cpu_to_le32(1000);
3700 mutex_lock(&bp
->hwrm_cmd_lock
);
3701 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3702 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3703 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3705 req
.stats_dma_addr
= cpu_to_le64(cpr
->hw_stats_map
);
3707 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
3712 cpr
->hw_stats_ctx_id
= le32_to_cpu(resp
->stat_ctx_id
);
3714 bp
->grp_info
[i
].fw_stats_ctx
= cpr
->hw_stats_ctx_id
;
3716 mutex_unlock(&bp
->hwrm_cmd_lock
);
3720 int bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
3723 struct hwrm_func_qcaps_input req
= {0};
3724 struct hwrm_func_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3726 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCAPS
, -1, -1);
3727 req
.fid
= cpu_to_le16(0xffff);
3729 mutex_lock(&bp
->hwrm_cmd_lock
);
3730 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3732 goto hwrm_func_qcaps_exit
;
3735 struct bnxt_pf_info
*pf
= &bp
->pf
;
3737 pf
->fw_fid
= le16_to_cpu(resp
->fid
);
3738 pf
->port_id
= le16_to_cpu(resp
->port_id
);
3739 memcpy(pf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
3740 memcpy(bp
->dev
->dev_addr
, pf
->mac_addr
, ETH_ALEN
);
3741 pf
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
3742 pf
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
3743 pf
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
3744 pf
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
3745 pf
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
3746 if (!pf
->max_hw_ring_grps
)
3747 pf
->max_hw_ring_grps
= pf
->max_tx_rings
;
3748 pf
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
3749 pf
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
3750 pf
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
3751 pf
->first_vf_id
= le16_to_cpu(resp
->first_vf_id
);
3752 pf
->max_vfs
= le16_to_cpu(resp
->max_vfs
);
3753 pf
->max_encap_records
= le32_to_cpu(resp
->max_encap_records
);
3754 pf
->max_decap_records
= le32_to_cpu(resp
->max_decap_records
);
3755 pf
->max_tx_em_flows
= le32_to_cpu(resp
->max_tx_em_flows
);
3756 pf
->max_tx_wm_flows
= le32_to_cpu(resp
->max_tx_wm_flows
);
3757 pf
->max_rx_em_flows
= le32_to_cpu(resp
->max_rx_em_flows
);
3758 pf
->max_rx_wm_flows
= le32_to_cpu(resp
->max_rx_wm_flows
);
3760 #ifdef CONFIG_BNXT_SRIOV
3761 struct bnxt_vf_info
*vf
= &bp
->vf
;
3763 vf
->fw_fid
= le16_to_cpu(resp
->fid
);
3764 memcpy(vf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
3765 if (is_valid_ether_addr(vf
->mac_addr
))
3766 /* overwrite netdev dev_adr with admin VF MAC */
3767 memcpy(bp
->dev
->dev_addr
, vf
->mac_addr
, ETH_ALEN
);
3769 random_ether_addr(bp
->dev
->dev_addr
);
3771 vf
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
3772 vf
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
3773 vf
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
3774 vf
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
3775 vf
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
3776 if (!vf
->max_hw_ring_grps
)
3777 vf
->max_hw_ring_grps
= vf
->max_tx_rings
;
3778 vf
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
3779 vf
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
3780 vf
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
3784 bp
->tx_push_thresh
= 0;
3786 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED
))
3787 bp
->tx_push_thresh
= BNXT_TX_PUSH_THRESH
;
3789 hwrm_func_qcaps_exit
:
3790 mutex_unlock(&bp
->hwrm_cmd_lock
);
3794 static int bnxt_hwrm_func_reset(struct bnxt
*bp
)
3796 struct hwrm_func_reset_input req
= {0};
3798 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESET
, -1, -1);
3801 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_RESET_TIMEOUT
);
3804 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
)
3807 struct hwrm_queue_qportcfg_input req
= {0};
3808 struct hwrm_queue_qportcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3811 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_QUEUE_QPORTCFG
, -1, -1);
3813 mutex_lock(&bp
->hwrm_cmd_lock
);
3814 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3818 if (!resp
->max_configurable_queues
) {
3822 bp
->max_tc
= resp
->max_configurable_queues
;
3823 if (bp
->max_tc
> BNXT_MAX_QUEUE
)
3824 bp
->max_tc
= BNXT_MAX_QUEUE
;
3826 qptr
= &resp
->queue_id0
;
3827 for (i
= 0; i
< bp
->max_tc
; i
++) {
3828 bp
->q_info
[i
].queue_id
= *qptr
++;
3829 bp
->q_info
[i
].queue_profile
= *qptr
++;
3833 mutex_unlock(&bp
->hwrm_cmd_lock
);
3837 static int bnxt_hwrm_ver_get(struct bnxt
*bp
)
3840 struct hwrm_ver_get_input req
= {0};
3841 struct hwrm_ver_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3843 bp
->hwrm_max_req_len
= HWRM_MAX_REQ_LEN
;
3844 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VER_GET
, -1, -1);
3845 req
.hwrm_intf_maj
= HWRM_VERSION_MAJOR
;
3846 req
.hwrm_intf_min
= HWRM_VERSION_MINOR
;
3847 req
.hwrm_intf_upd
= HWRM_VERSION_UPDATE
;
3848 mutex_lock(&bp
->hwrm_cmd_lock
);
3849 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3851 goto hwrm_ver_get_exit
;
3853 memcpy(&bp
->ver_resp
, resp
, sizeof(struct hwrm_ver_get_output
));
3855 bp
->hwrm_spec_code
= resp
->hwrm_intf_maj
<< 16 |
3856 resp
->hwrm_intf_min
<< 8 | resp
->hwrm_intf_upd
;
3857 if (resp
->hwrm_intf_maj
< 1) {
3858 netdev_warn(bp
->dev
, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
3859 resp
->hwrm_intf_maj
, resp
->hwrm_intf_min
,
3860 resp
->hwrm_intf_upd
);
3861 netdev_warn(bp
->dev
, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
3863 snprintf(bp
->fw_ver_str
, BC_HWRM_STR_LEN
, "%d.%d.%d/%d.%d.%d",
3864 resp
->hwrm_fw_maj
, resp
->hwrm_fw_min
, resp
->hwrm_fw_bld
,
3865 resp
->hwrm_intf_maj
, resp
->hwrm_intf_min
, resp
->hwrm_intf_upd
);
3867 bp
->hwrm_cmd_timeout
= le16_to_cpu(resp
->def_req_timeout
);
3868 if (!bp
->hwrm_cmd_timeout
)
3869 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
3871 if (resp
->hwrm_intf_maj
>= 1)
3872 bp
->hwrm_max_req_len
= le16_to_cpu(resp
->max_req_win_len
);
3875 mutex_unlock(&bp
->hwrm_cmd_lock
);
3879 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
)
3882 struct bnxt_pf_info
*pf
= &bp
->pf
;
3883 struct hwrm_port_qstats_input req
= {0};
3885 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS
))
3888 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS
, -1, -1);
3889 req
.port_id
= cpu_to_le16(pf
->port_id
);
3890 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_map
);
3891 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_map
);
3892 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3896 static void bnxt_hwrm_free_tunnel_ports(struct bnxt
*bp
)
3898 if (bp
->vxlan_port_cnt
) {
3899 bnxt_hwrm_tunnel_dst_port_free(
3900 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
3902 bp
->vxlan_port_cnt
= 0;
3903 if (bp
->nge_port_cnt
) {
3904 bnxt_hwrm_tunnel_dst_port_free(
3905 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
3907 bp
->nge_port_cnt
= 0;
3910 static int bnxt_set_tpa(struct bnxt
*bp
, bool set_tpa
)
3916 tpa_flags
= bp
->flags
& BNXT_FLAG_TPA
;
3917 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3918 rc
= bnxt_hwrm_vnic_set_tpa(bp
, i
, tpa_flags
);
3920 netdev_err(bp
->dev
, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
3928 static void bnxt_hwrm_clear_vnic_rss(struct bnxt
*bp
)
3932 for (i
= 0; i
< bp
->nr_vnics
; i
++)
3933 bnxt_hwrm_vnic_set_rss(bp
, i
, false);
3936 static void bnxt_hwrm_resource_free(struct bnxt
*bp
, bool close_path
,
3939 if (bp
->vnic_info
) {
3940 bnxt_hwrm_clear_vnic_filter(bp
);
3941 /* clear all RSS setting before free vnic ctx */
3942 bnxt_hwrm_clear_vnic_rss(bp
);
3943 bnxt_hwrm_vnic_ctx_free(bp
);
3944 /* before free the vnic, undo the vnic tpa settings */
3945 if (bp
->flags
& BNXT_FLAG_TPA
)
3946 bnxt_set_tpa(bp
, false);
3947 bnxt_hwrm_vnic_free(bp
);
3949 bnxt_hwrm_ring_free(bp
, close_path
);
3950 bnxt_hwrm_ring_grp_free(bp
);
3952 bnxt_hwrm_stat_ctx_free(bp
);
3953 bnxt_hwrm_free_tunnel_ports(bp
);
3957 static int bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
3961 /* allocate context for vnic */
3962 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
);
3964 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
3966 goto vnic_setup_err
;
3968 bp
->rsscos_nr_ctxs
++;
3970 /* configure default vnic, ring grp */
3971 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
3973 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
3975 goto vnic_setup_err
;
3978 /* Enable RSS hashing on vnic */
3979 rc
= bnxt_hwrm_vnic_set_rss(bp
, vnic_id
, true);
3981 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %x\n",
3983 goto vnic_setup_err
;
3986 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
3987 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
3989 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
3998 static int bnxt_alloc_rfs_vnics(struct bnxt
*bp
)
4000 #ifdef CONFIG_RFS_ACCEL
4003 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4004 u16 vnic_id
= i
+ 1;
4007 if (vnic_id
>= bp
->nr_vnics
)
4010 bp
->vnic_info
[vnic_id
].flags
|= BNXT_VNIC_RFS_FLAG
;
4011 rc
= bnxt_hwrm_vnic_alloc(bp
, vnic_id
, ring_id
, 1);
4013 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
4017 rc
= bnxt_setup_vnic(bp
, vnic_id
);
4027 static int bnxt_cfg_rx_mode(struct bnxt
*);
4029 static int bnxt_init_chip(struct bnxt
*bp
, bool irq_re_init
)
4034 rc
= bnxt_hwrm_stat_ctx_alloc(bp
);
4036 netdev_err(bp
->dev
, "hwrm stat ctx alloc failure rc: %x\n",
4042 rc
= bnxt_hwrm_ring_alloc(bp
);
4044 netdev_err(bp
->dev
, "hwrm ring alloc failure rc: %x\n", rc
);
4048 rc
= bnxt_hwrm_ring_grp_alloc(bp
);
4050 netdev_err(bp
->dev
, "hwrm_ring_grp alloc failure: %x\n", rc
);
4054 /* default vnic 0 */
4055 rc
= bnxt_hwrm_vnic_alloc(bp
, 0, 0, bp
->rx_nr_rings
);
4057 netdev_err(bp
->dev
, "hwrm vnic alloc failure rc: %x\n", rc
);
4061 rc
= bnxt_setup_vnic(bp
, 0);
4065 if (bp
->flags
& BNXT_FLAG_RFS
) {
4066 rc
= bnxt_alloc_rfs_vnics(bp
);
4071 if (bp
->flags
& BNXT_FLAG_TPA
) {
4072 rc
= bnxt_set_tpa(bp
, true);
4078 bnxt_update_vf_mac(bp
);
4080 /* Filter for default vnic 0 */
4081 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, 0, bp
->dev
->dev_addr
);
4083 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n", rc
);
4086 bp
->vnic_info
[0].uc_filter_count
= 1;
4088 bp
->vnic_info
[0].rx_mask
= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
4090 if ((bp
->dev
->flags
& IFF_PROMISC
) && BNXT_PF(bp
))
4091 bp
->vnic_info
[0].rx_mask
|=
4092 CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
4094 rc
= bnxt_cfg_rx_mode(bp
);
4098 rc
= bnxt_hwrm_set_coal(bp
);
4100 netdev_warn(bp
->dev
, "HWRM set coalescing failure rc: %x\n",
4106 bnxt_hwrm_resource_free(bp
, 0, true);
4111 static int bnxt_shutdown_nic(struct bnxt
*bp
, bool irq_re_init
)
4113 bnxt_hwrm_resource_free(bp
, 1, irq_re_init
);
4117 static int bnxt_init_nic(struct bnxt
*bp
, bool irq_re_init
)
4119 bnxt_init_rx_rings(bp
);
4120 bnxt_init_tx_rings(bp
);
4121 bnxt_init_ring_grps(bp
, irq_re_init
);
4122 bnxt_init_vnics(bp
);
4124 return bnxt_init_chip(bp
, irq_re_init
);
4127 static void bnxt_disable_int(struct bnxt
*bp
)
4134 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4135 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4136 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4138 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
4142 static void bnxt_enable_int(struct bnxt
*bp
)
4146 atomic_set(&bp
->intr_sem
, 0);
4147 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4148 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4149 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4151 BNXT_CP_DB_REARM(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
4155 static int bnxt_set_real_num_queues(struct bnxt
*bp
)
4158 struct net_device
*dev
= bp
->dev
;
4160 rc
= netif_set_real_num_tx_queues(dev
, bp
->tx_nr_rings
);
4164 rc
= netif_set_real_num_rx_queues(dev
, bp
->rx_nr_rings
);
4168 #ifdef CONFIG_RFS_ACCEL
4169 if (bp
->flags
& BNXT_FLAG_RFS
)
4170 dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(bp
->rx_nr_rings
);
4176 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
4179 int _rx
= *rx
, _tx
= *tx
;
4182 *rx
= min_t(int, _rx
, max
);
4183 *tx
= min_t(int, _tx
, max
);
4188 while (_rx
+ _tx
> max
) {
4189 if (_rx
> _tx
&& _rx
> 1)
4200 static int bnxt_setup_msix(struct bnxt
*bp
)
4202 struct msix_entry
*msix_ent
;
4203 struct net_device
*dev
= bp
->dev
;
4204 int i
, total_vecs
, rc
= 0, min
= 1;
4205 const int len
= sizeof(bp
->irq_tbl
[0].name
);
4207 bp
->flags
&= ~BNXT_FLAG_USING_MSIX
;
4208 total_vecs
= bp
->cp_nr_rings
;
4210 msix_ent
= kcalloc(total_vecs
, sizeof(struct msix_entry
), GFP_KERNEL
);
4214 for (i
= 0; i
< total_vecs
; i
++) {
4215 msix_ent
[i
].entry
= i
;
4216 msix_ent
[i
].vector
= 0;
4219 if (!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
))
4222 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
, min
, total_vecs
);
4223 if (total_vecs
< 0) {
4225 goto msix_setup_exit
;
4228 bp
->irq_tbl
= kcalloc(total_vecs
, sizeof(struct bnxt_irq
), GFP_KERNEL
);
4232 /* Trim rings based upon num of vectors allocated */
4233 rc
= bnxt_trim_rings(bp
, &bp
->rx_nr_rings
, &bp
->tx_nr_rings
,
4234 total_vecs
, min
== 1);
4236 goto msix_setup_exit
;
4238 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
4239 tcs
= netdev_get_num_tc(dev
);
4241 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
/ tcs
;
4242 if (bp
->tx_nr_rings_per_tc
== 0) {
4243 netdev_reset_tc(dev
);
4244 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
4248 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tcs
;
4249 for (i
= 0; i
< tcs
; i
++) {
4250 count
= bp
->tx_nr_rings_per_tc
;
4252 netdev_set_tc_queue(dev
, i
, count
, off
);
4256 bp
->cp_nr_rings
= total_vecs
;
4258 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4261 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
4262 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
4264 else if (i
< bp
->rx_nr_rings
)
4269 snprintf(bp
->irq_tbl
[i
].name
, len
,
4270 "%s-%s-%d", dev
->name
, attr
, i
);
4271 bp
->irq_tbl
[i
].handler
= bnxt_msix
;
4273 rc
= bnxt_set_real_num_queues(bp
);
4275 goto msix_setup_exit
;
4278 goto msix_setup_exit
;
4280 bp
->flags
|= BNXT_FLAG_USING_MSIX
;
4285 netdev_err(bp
->dev
, "bnxt_setup_msix err: %x\n", rc
);
4286 pci_disable_msix(bp
->pdev
);
4291 static int bnxt_setup_inta(struct bnxt
*bp
)
4294 const int len
= sizeof(bp
->irq_tbl
[0].name
);
4296 if (netdev_get_num_tc(bp
->dev
))
4297 netdev_reset_tc(bp
->dev
);
4299 bp
->irq_tbl
= kcalloc(1, sizeof(struct bnxt_irq
), GFP_KERNEL
);
4304 bp
->rx_nr_rings
= 1;
4305 bp
->tx_nr_rings
= 1;
4306 bp
->cp_nr_rings
= 1;
4307 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
4308 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
4309 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
4310 snprintf(bp
->irq_tbl
[0].name
, len
,
4311 "%s-%s-%d", bp
->dev
->name
, "TxRx", 0);
4312 bp
->irq_tbl
[0].handler
= bnxt_inta
;
4313 rc
= bnxt_set_real_num_queues(bp
);
4317 static int bnxt_setup_int_mode(struct bnxt
*bp
)
4321 if (bp
->flags
& BNXT_FLAG_MSIX_CAP
)
4322 rc
= bnxt_setup_msix(bp
);
4324 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
4325 /* fallback to INTA */
4326 rc
= bnxt_setup_inta(bp
);
4331 static void bnxt_free_irq(struct bnxt
*bp
)
4333 struct bnxt_irq
*irq
;
4336 #ifdef CONFIG_RFS_ACCEL
4337 free_irq_cpu_rmap(bp
->dev
->rx_cpu_rmap
);
4338 bp
->dev
->rx_cpu_rmap
= NULL
;
4343 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4344 irq
= &bp
->irq_tbl
[i
];
4346 free_irq(irq
->vector
, bp
->bnapi
[i
]);
4349 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
4350 pci_disable_msix(bp
->pdev
);
4355 static int bnxt_request_irq(struct bnxt
*bp
)
4358 unsigned long flags
= 0;
4359 #ifdef CONFIG_RFS_ACCEL
4360 struct cpu_rmap
*rmap
= bp
->dev
->rx_cpu_rmap
;
4363 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
))
4364 flags
= IRQF_SHARED
;
4366 for (i
= 0, j
= 0; i
< bp
->cp_nr_rings
; i
++) {
4367 struct bnxt_irq
*irq
= &bp
->irq_tbl
[i
];
4368 #ifdef CONFIG_RFS_ACCEL
4369 if (rmap
&& bp
->bnapi
[i
]->rx_ring
) {
4370 rc
= irq_cpu_rmap_add(rmap
, irq
->vector
);
4372 netdev_warn(bp
->dev
, "failed adding irq rmap for ring %d\n",
4377 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
4387 static void bnxt_del_napi(struct bnxt
*bp
)
4394 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4395 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4397 napi_hash_del(&bnapi
->napi
);
4398 netif_napi_del(&bnapi
->napi
);
4402 static void bnxt_init_napi(struct bnxt
*bp
)
4405 struct bnxt_napi
*bnapi
;
4407 if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
4408 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4409 bnapi
= bp
->bnapi
[i
];
4410 netif_napi_add(bp
->dev
, &bnapi
->napi
,
4414 bnapi
= bp
->bnapi
[0];
4415 netif_napi_add(bp
->dev
, &bnapi
->napi
, bnxt_poll
, 64);
4419 static void bnxt_disable_napi(struct bnxt
*bp
)
4426 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4427 napi_disable(&bp
->bnapi
[i
]->napi
);
4428 bnxt_disable_poll(bp
->bnapi
[i
]);
4432 static void bnxt_enable_napi(struct bnxt
*bp
)
4436 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4437 bnxt_enable_poll(bp
->bnapi
[i
]);
4438 napi_enable(&bp
->bnapi
[i
]->napi
);
4442 static void bnxt_tx_disable(struct bnxt
*bp
)
4445 struct bnxt_tx_ring_info
*txr
;
4446 struct netdev_queue
*txq
;
4449 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
4450 txr
= &bp
->tx_ring
[i
];
4451 txq
= netdev_get_tx_queue(bp
->dev
, i
);
4452 __netif_tx_lock(txq
, smp_processor_id());
4453 txr
->dev_state
= BNXT_DEV_STATE_CLOSING
;
4454 __netif_tx_unlock(txq
);
4457 /* Stop all TX queues */
4458 netif_tx_disable(bp
->dev
);
4459 netif_carrier_off(bp
->dev
);
4462 static void bnxt_tx_enable(struct bnxt
*bp
)
4465 struct bnxt_tx_ring_info
*txr
;
4466 struct netdev_queue
*txq
;
4468 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
4469 txr
= &bp
->tx_ring
[i
];
4470 txq
= netdev_get_tx_queue(bp
->dev
, i
);
4473 netif_tx_wake_all_queues(bp
->dev
);
4474 if (bp
->link_info
.link_up
)
4475 netif_carrier_on(bp
->dev
);
4478 static void bnxt_report_link(struct bnxt
*bp
)
4480 if (bp
->link_info
.link_up
) {
4482 const char *flow_ctrl
;
4485 netif_carrier_on(bp
->dev
);
4486 if (bp
->link_info
.duplex
== BNXT_LINK_DUPLEX_FULL
)
4490 if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_BOTH
)
4491 flow_ctrl
= "ON - receive & transmit";
4492 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_TX
)
4493 flow_ctrl
= "ON - transmit";
4494 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_RX
)
4495 flow_ctrl
= "ON - receive";
4498 speed
= bnxt_fw_to_ethtool_speed(bp
->link_info
.link_speed
);
4499 netdev_info(bp
->dev
, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
4500 speed
, duplex
, flow_ctrl
);
4501 if (bp
->flags
& BNXT_FLAG_EEE_CAP
)
4502 netdev_info(bp
->dev
, "EEE is %s\n",
4503 bp
->eee
.eee_active
? "active" :
4506 netif_carrier_off(bp
->dev
);
4507 netdev_err(bp
->dev
, "NIC Link is Down\n");
4511 static int bnxt_hwrm_phy_qcaps(struct bnxt
*bp
)
4514 struct hwrm_port_phy_qcaps_input req
= {0};
4515 struct hwrm_port_phy_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4517 if (bp
->hwrm_spec_code
< 0x10201)
4520 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCAPS
, -1, -1);
4522 mutex_lock(&bp
->hwrm_cmd_lock
);
4523 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4525 goto hwrm_phy_qcaps_exit
;
4527 if (resp
->eee_supported
& PORT_PHY_QCAPS_RESP_EEE_SUPPORTED
) {
4528 struct ethtool_eee
*eee
= &bp
->eee
;
4529 u16 fw_speeds
= le16_to_cpu(resp
->supported_speeds_eee_mode
);
4531 bp
->flags
|= BNXT_FLAG_EEE_CAP
;
4532 eee
->supported
= _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
4533 bp
->lpi_tmr_lo
= le32_to_cpu(resp
->tx_lpi_timer_low
) &
4534 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK
;
4535 bp
->lpi_tmr_hi
= le32_to_cpu(resp
->valid_tx_lpi_timer_high
) &
4536 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK
;
4539 hwrm_phy_qcaps_exit
:
4540 mutex_unlock(&bp
->hwrm_cmd_lock
);
4544 static int bnxt_update_link(struct bnxt
*bp
, bool chng_link_state
)
4547 struct bnxt_link_info
*link_info
= &bp
->link_info
;
4548 struct hwrm_port_phy_qcfg_input req
= {0};
4549 struct hwrm_port_phy_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4550 u8 link_up
= link_info
->link_up
;
4552 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCFG
, -1, -1);
4554 mutex_lock(&bp
->hwrm_cmd_lock
);
4555 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4557 mutex_unlock(&bp
->hwrm_cmd_lock
);
4561 memcpy(&link_info
->phy_qcfg_resp
, resp
, sizeof(*resp
));
4562 link_info
->phy_link_status
= resp
->link
;
4563 link_info
->duplex
= resp
->duplex
;
4564 link_info
->pause
= resp
->pause
;
4565 link_info
->auto_mode
= resp
->auto_mode
;
4566 link_info
->auto_pause_setting
= resp
->auto_pause
;
4567 link_info
->lp_pause
= resp
->link_partner_adv_pause
;
4568 link_info
->force_pause_setting
= resp
->force_pause
;
4569 link_info
->duplex_setting
= resp
->duplex
;
4570 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
4571 link_info
->link_speed
= le16_to_cpu(resp
->link_speed
);
4573 link_info
->link_speed
= 0;
4574 link_info
->force_link_speed
= le16_to_cpu(resp
->force_link_speed
);
4575 link_info
->support_speeds
= le16_to_cpu(resp
->support_speeds
);
4576 link_info
->auto_link_speeds
= le16_to_cpu(resp
->auto_link_speed_mask
);
4577 link_info
->lp_auto_link_speeds
=
4578 le16_to_cpu(resp
->link_partner_adv_speeds
);
4579 link_info
->preemphasis
= le32_to_cpu(resp
->preemphasis
);
4580 link_info
->phy_ver
[0] = resp
->phy_maj
;
4581 link_info
->phy_ver
[1] = resp
->phy_min
;
4582 link_info
->phy_ver
[2] = resp
->phy_bld
;
4583 link_info
->media_type
= resp
->media_type
;
4584 link_info
->transceiver
= resp
->xcvr_pkg_type
;
4585 link_info
->phy_addr
= resp
->eee_config_phy_addr
&
4586 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK
;
4588 if (bp
->flags
& BNXT_FLAG_EEE_CAP
) {
4589 struct ethtool_eee
*eee
= &bp
->eee
;
4592 eee
->eee_active
= 0;
4593 if (resp
->eee_config_phy_addr
&
4594 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE
) {
4595 eee
->eee_active
= 1;
4596 fw_speeds
= le16_to_cpu(
4597 resp
->link_partner_adv_eee_link_speed_mask
);
4598 eee
->lp_advertised
=
4599 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
4602 /* Pull initial EEE config */
4603 if (!chng_link_state
) {
4604 if (resp
->eee_config_phy_addr
&
4605 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED
)
4606 eee
->eee_enabled
= 1;
4608 fw_speeds
= le16_to_cpu(resp
->adv_eee_link_speed_mask
);
4610 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
4612 if (resp
->eee_config_phy_addr
&
4613 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI
) {
4616 eee
->tx_lpi_enabled
= 1;
4617 tmr
= resp
->xcvr_identifier_type_tx_lpi_timer
;
4618 eee
->tx_lpi_timer
= le32_to_cpu(tmr
) &
4619 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK
;
4623 /* TODO: need to add more logic to report VF link */
4624 if (chng_link_state
) {
4625 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
4626 link_info
->link_up
= 1;
4628 link_info
->link_up
= 0;
4629 if (link_up
!= link_info
->link_up
)
4630 bnxt_report_link(bp
);
4632 /* alwasy link down if not require to update link state */
4633 link_info
->link_up
= 0;
4635 mutex_unlock(&bp
->hwrm_cmd_lock
);
4640 bnxt_hwrm_set_pause_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
4642 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) {
4643 if (bp
->hwrm_spec_code
>= 0x10201)
4645 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
4646 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
4647 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX
;
4648 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
4649 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX
;
4651 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
4653 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
4654 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX
;
4655 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
4656 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX
;
4658 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE
);
4659 if (bp
->hwrm_spec_code
>= 0x10201) {
4660 req
->auto_pause
= req
->force_pause
;
4661 req
->enables
|= cpu_to_le32(
4662 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
4667 static void bnxt_hwrm_set_link_common(struct bnxt
*bp
,
4668 struct hwrm_port_phy_cfg_input
*req
)
4670 u8 autoneg
= bp
->link_info
.autoneg
;
4671 u16 fw_link_speed
= bp
->link_info
.req_link_speed
;
4672 u32 advertising
= bp
->link_info
.advertising
;
4674 if (autoneg
& BNXT_AUTONEG_SPEED
) {
4676 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK
;
4678 req
->enables
|= cpu_to_le32(
4679 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK
);
4680 req
->auto_link_speed_mask
= cpu_to_le16(advertising
);
4682 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE
);
4684 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG
);
4686 req
->force_link_speed
= cpu_to_le16(fw_link_speed
);
4687 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE
);
4690 /* tell chimp that the setting takes effect immediately */
4691 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY
);
4694 int bnxt_hwrm_set_pause(struct bnxt
*bp
)
4696 struct hwrm_port_phy_cfg_input req
= {0};
4699 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
4700 bnxt_hwrm_set_pause_common(bp
, &req
);
4702 if ((bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) ||
4703 bp
->link_info
.force_link_chng
)
4704 bnxt_hwrm_set_link_common(bp
, &req
);
4706 mutex_lock(&bp
->hwrm_cmd_lock
);
4707 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4708 if (!rc
&& !(bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
)) {
4709 /* since changing of pause setting doesn't trigger any link
4710 * change event, the driver needs to update the current pause
4711 * result upon successfully return of the phy_cfg command
4713 bp
->link_info
.pause
=
4714 bp
->link_info
.force_pause_setting
= bp
->link_info
.req_flow_ctrl
;
4715 bp
->link_info
.auto_pause_setting
= 0;
4716 if (!bp
->link_info
.force_link_chng
)
4717 bnxt_report_link(bp
);
4719 bp
->link_info
.force_link_chng
= false;
4720 mutex_unlock(&bp
->hwrm_cmd_lock
);
4724 static void bnxt_hwrm_set_eee(struct bnxt
*bp
,
4725 struct hwrm_port_phy_cfg_input
*req
)
4727 struct ethtool_eee
*eee
= &bp
->eee
;
4729 if (eee
->eee_enabled
) {
4731 u32 flags
= PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE
;
4733 if (eee
->tx_lpi_enabled
)
4734 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE
;
4736 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE
;
4738 req
->flags
|= cpu_to_le32(flags
);
4739 eee_speeds
= bnxt_get_fw_auto_link_speeds(eee
->advertised
);
4740 req
->eee_link_speed_mask
= cpu_to_le16(eee_speeds
);
4741 req
->tx_lpi_timer
= cpu_to_le32(eee
->tx_lpi_timer
);
4743 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE
);
4747 int bnxt_hwrm_set_link_setting(struct bnxt
*bp
, bool set_pause
, bool set_eee
)
4749 struct hwrm_port_phy_cfg_input req
= {0};
4751 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
4753 bnxt_hwrm_set_pause_common(bp
, &req
);
4755 bnxt_hwrm_set_link_common(bp
, &req
);
4758 bnxt_hwrm_set_eee(bp
, &req
);
4759 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4762 static bool bnxt_eee_config_ok(struct bnxt
*bp
)
4764 struct ethtool_eee
*eee
= &bp
->eee
;
4765 struct bnxt_link_info
*link_info
= &bp
->link_info
;
4767 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
4770 if (eee
->eee_enabled
) {
4772 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
4774 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
4775 eee
->eee_enabled
= 0;
4778 if (eee
->advertised
& ~advertising
) {
4779 eee
->advertised
= advertising
& eee
->supported
;
4786 static int bnxt_update_phy_setting(struct bnxt
*bp
)
4789 bool update_link
= false;
4790 bool update_pause
= false;
4791 bool update_eee
= false;
4792 struct bnxt_link_info
*link_info
= &bp
->link_info
;
4794 rc
= bnxt_update_link(bp
, true);
4796 netdev_err(bp
->dev
, "failed to update link (rc: %x)\n",
4800 if ((link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
4801 (link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
) !=
4802 link_info
->req_flow_ctrl
)
4803 update_pause
= true;
4804 if (!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
4805 link_info
->force_pause_setting
!= link_info
->req_flow_ctrl
)
4806 update_pause
= true;
4807 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
4808 if (BNXT_AUTO_MODE(link_info
->auto_mode
))
4810 if (link_info
->req_link_speed
!= link_info
->force_link_speed
)
4812 if (link_info
->req_duplex
!= link_info
->duplex_setting
)
4815 if (link_info
->auto_mode
== BNXT_LINK_AUTO_NONE
)
4817 if (link_info
->advertising
!= link_info
->auto_link_speeds
)
4821 if (!bnxt_eee_config_ok(bp
))
4825 rc
= bnxt_hwrm_set_link_setting(bp
, update_pause
, update_eee
);
4826 else if (update_pause
)
4827 rc
= bnxt_hwrm_set_pause(bp
);
4829 netdev_err(bp
->dev
, "failed to update phy setting (rc: %x)\n",
4837 /* Common routine to pre-map certain register block to different GRC window.
4838 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
4839 * in PF and 3 windows in VF that can be customized to map in different
4842 static void bnxt_preset_reg_win(struct bnxt
*bp
)
4845 /* CAG registers map to GRC window #4 */
4846 writel(BNXT_CAG_REG_BASE
,
4847 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 12);
4851 static int __bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
4855 bnxt_preset_reg_win(bp
);
4856 netif_carrier_off(bp
->dev
);
4858 rc
= bnxt_setup_int_mode(bp
);
4860 netdev_err(bp
->dev
, "bnxt_setup_int_mode err: %x\n",
4865 if ((bp
->flags
& BNXT_FLAG_RFS
) &&
4866 !(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
4867 /* disable RFS if falling back to INTA */
4868 bp
->dev
->hw_features
&= ~NETIF_F_NTUPLE
;
4869 bp
->flags
&= ~BNXT_FLAG_RFS
;
4872 rc
= bnxt_alloc_mem(bp
, irq_re_init
);
4874 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
4875 goto open_err_free_mem
;
4880 rc
= bnxt_request_irq(bp
);
4882 netdev_err(bp
->dev
, "bnxt_request_irq err: %x\n", rc
);
4887 bnxt_enable_napi(bp
);
4889 rc
= bnxt_init_nic(bp
, irq_re_init
);
4891 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
4896 rc
= bnxt_update_phy_setting(bp
);
4898 netdev_warn(bp
->dev
, "failed to update phy settings\n");
4902 #if defined(CONFIG_VXLAN) || defined(CONFIG_VXLAN_MODULE)
4903 vxlan_get_rx_port(bp
->dev
);
4905 if (!bnxt_hwrm_tunnel_dst_port_alloc(
4907 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
))
4908 bp
->nge_port_cnt
= 1;
4911 set_bit(BNXT_STATE_OPEN
, &bp
->state
);
4912 bnxt_enable_int(bp
);
4913 /* Enable TX queues */
4915 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
4916 bnxt_update_link(bp
, true);
4921 bnxt_disable_napi(bp
);
4927 bnxt_free_mem(bp
, true);
4931 /* rtnl_lock held */
4932 int bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
4936 rc
= __bnxt_open_nic(bp
, irq_re_init
, link_re_init
);
4938 netdev_err(bp
->dev
, "nic open fail (rc: %x)\n", rc
);
4944 static int bnxt_open(struct net_device
*dev
)
4946 struct bnxt
*bp
= netdev_priv(dev
);
4949 rc
= bnxt_hwrm_func_reset(bp
);
4951 netdev_err(bp
->dev
, "hwrm chip reset failure rc: %x\n",
4956 return __bnxt_open_nic(bp
, true, true);
4959 static void bnxt_disable_int_sync(struct bnxt
*bp
)
4963 atomic_inc(&bp
->intr_sem
);
4964 if (!netif_running(bp
->dev
))
4967 bnxt_disable_int(bp
);
4968 for (i
= 0; i
< bp
->cp_nr_rings
; i
++)
4969 synchronize_irq(bp
->irq_tbl
[i
].vector
);
4972 int bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
4976 #ifdef CONFIG_BNXT_SRIOV
4977 if (bp
->sriov_cfg
) {
4978 rc
= wait_event_interruptible_timeout(bp
->sriov_cfg_wait
,
4980 BNXT_SRIOV_CFG_WAIT_TMO
);
4982 netdev_warn(bp
->dev
, "timeout waiting for SRIOV config operation to complete!\n");
4985 /* Change device state to avoid TX queue wake up's */
4986 bnxt_tx_disable(bp
);
4988 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
4989 smp_mb__after_atomic();
4990 while (test_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
))
4993 /* Flush rings before disabling interrupts */
4994 bnxt_shutdown_nic(bp
, irq_re_init
);
4996 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
4998 bnxt_disable_napi(bp
);
4999 bnxt_disable_int_sync(bp
);
5000 del_timer_sync(&bp
->timer
);
5007 bnxt_free_mem(bp
, irq_re_init
);
5011 static int bnxt_close(struct net_device
*dev
)
5013 struct bnxt
*bp
= netdev_priv(dev
);
5015 bnxt_close_nic(bp
, true, true);
5019 /* rtnl_lock held */
5020 static int bnxt_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
5026 if (!netif_running(dev
))
5033 if (!netif_running(dev
))
5045 static struct rtnl_link_stats64
*
5046 bnxt_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
5049 struct bnxt
*bp
= netdev_priv(dev
);
5051 memset(stats
, 0, sizeof(struct rtnl_link_stats64
));
5056 /* TODO check if we need to synchronize with bnxt_close path */
5057 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5058 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5059 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5060 struct ctx_hw_stats
*hw_stats
= cpr
->hw_stats
;
5062 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_ucast_pkts
);
5063 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
5064 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_bcast_pkts
);
5066 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_ucast_pkts
);
5067 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_mcast_pkts
);
5068 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_bcast_pkts
);
5070 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_ucast_bytes
);
5071 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_mcast_bytes
);
5072 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_bcast_bytes
);
5074 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_ucast_bytes
);
5075 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_mcast_bytes
);
5076 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_bcast_bytes
);
5078 stats
->rx_missed_errors
+=
5079 le64_to_cpu(hw_stats
->rx_discard_pkts
);
5081 stats
->multicast
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
5083 stats
->tx_dropped
+= le64_to_cpu(hw_stats
->tx_drop_pkts
);
5086 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
5087 struct rx_port_stats
*rx
= bp
->hw_rx_port_stats
;
5088 struct tx_port_stats
*tx
= bp
->hw_tx_port_stats
;
5090 stats
->rx_crc_errors
= le64_to_cpu(rx
->rx_fcs_err_frames
);
5091 stats
->rx_frame_errors
= le64_to_cpu(rx
->rx_align_err_frames
);
5092 stats
->rx_length_errors
= le64_to_cpu(rx
->rx_undrsz_frames
) +
5093 le64_to_cpu(rx
->rx_ovrsz_frames
) +
5094 le64_to_cpu(rx
->rx_runt_frames
);
5095 stats
->rx_errors
= le64_to_cpu(rx
->rx_false_carrier_frames
) +
5096 le64_to_cpu(rx
->rx_jbr_frames
);
5097 stats
->collisions
= le64_to_cpu(tx
->tx_total_collisions
);
5098 stats
->tx_fifo_errors
= le64_to_cpu(tx
->tx_fifo_underruns
);
5099 stats
->tx_errors
= le64_to_cpu(tx
->tx_err
);
5105 static bool bnxt_mc_list_updated(struct bnxt
*bp
, u32
*rx_mask
)
5107 struct net_device
*dev
= bp
->dev
;
5108 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
5109 struct netdev_hw_addr
*ha
;
5112 bool update
= false;
5115 netdev_for_each_mc_addr(ha
, dev
) {
5116 if (mc_count
>= BNXT_MAX_MC_ADDRS
) {
5117 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
5118 vnic
->mc_list_count
= 0;
5122 if (!ether_addr_equal(haddr
, vnic
->mc_list
+ off
)) {
5123 memcpy(vnic
->mc_list
+ off
, haddr
, ETH_ALEN
);
5130 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
;
5132 if (mc_count
!= vnic
->mc_list_count
) {
5133 vnic
->mc_list_count
= mc_count
;
5139 static bool bnxt_uc_list_updated(struct bnxt
*bp
)
5141 struct net_device
*dev
= bp
->dev
;
5142 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
5143 struct netdev_hw_addr
*ha
;
5146 if (netdev_uc_count(dev
) != (vnic
->uc_filter_count
- 1))
5149 netdev_for_each_uc_addr(ha
, dev
) {
5150 if (!ether_addr_equal(ha
->addr
, vnic
->uc_list
+ off
))
5158 static void bnxt_set_rx_mode(struct net_device
*dev
)
5160 struct bnxt
*bp
= netdev_priv(dev
);
5161 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
5162 u32 mask
= vnic
->rx_mask
;
5163 bool mc_update
= false;
5166 if (!netif_running(dev
))
5169 mask
&= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
|
5170 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
|
5171 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
);
5173 /* Only allow PF to be in promiscuous mode */
5174 if ((dev
->flags
& IFF_PROMISC
) && BNXT_PF(bp
))
5175 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
5177 uc_update
= bnxt_uc_list_updated(bp
);
5179 if (dev
->flags
& IFF_ALLMULTI
) {
5180 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
5181 vnic
->mc_list_count
= 0;
5183 mc_update
= bnxt_mc_list_updated(bp
, &mask
);
5186 if (mask
!= vnic
->rx_mask
|| uc_update
|| mc_update
) {
5187 vnic
->rx_mask
= mask
;
5189 set_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
);
5190 schedule_work(&bp
->sp_task
);
5194 static int bnxt_cfg_rx_mode(struct bnxt
*bp
)
5196 struct net_device
*dev
= bp
->dev
;
5197 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
5198 struct netdev_hw_addr
*ha
;
5202 netif_addr_lock_bh(dev
);
5203 uc_update
= bnxt_uc_list_updated(bp
);
5204 netif_addr_unlock_bh(dev
);
5209 mutex_lock(&bp
->hwrm_cmd_lock
);
5210 for (i
= 1; i
< vnic
->uc_filter_count
; i
++) {
5211 struct hwrm_cfa_l2_filter_free_input req
= {0};
5213 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_FREE
, -1,
5216 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[i
];
5218 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5221 mutex_unlock(&bp
->hwrm_cmd_lock
);
5223 vnic
->uc_filter_count
= 1;
5225 netif_addr_lock_bh(dev
);
5226 if (netdev_uc_count(dev
) > (BNXT_MAX_UC_ADDRS
- 1)) {
5227 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
5229 netdev_for_each_uc_addr(ha
, dev
) {
5230 memcpy(vnic
->uc_list
+ off
, ha
->addr
, ETH_ALEN
);
5232 vnic
->uc_filter_count
++;
5235 netif_addr_unlock_bh(dev
);
5237 for (i
= 1, off
= 0; i
< vnic
->uc_filter_count
; i
++, off
+= ETH_ALEN
) {
5238 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, i
, vnic
->uc_list
+ off
);
5240 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n",
5242 vnic
->uc_filter_count
= i
;
5248 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
5250 netdev_err(bp
->dev
, "HWRM cfa l2 rx mask failure rc: %x\n",
5256 static bool bnxt_rfs_capable(struct bnxt
*bp
)
5258 #ifdef CONFIG_RFS_ACCEL
5259 struct bnxt_pf_info
*pf
= &bp
->pf
;
5262 if (BNXT_VF(bp
) || !(bp
->flags
& BNXT_FLAG_MSIX_CAP
))
5265 vnics
= 1 + bp
->rx_nr_rings
;
5266 if (vnics
> pf
->max_rsscos_ctxs
|| vnics
> pf
->max_vnics
)
5275 static netdev_features_t
bnxt_fix_features(struct net_device
*dev
,
5276 netdev_features_t features
)
5278 struct bnxt
*bp
= netdev_priv(dev
);
5280 if (!bnxt_rfs_capable(bp
))
5281 features
&= ~NETIF_F_NTUPLE
;
5285 static int bnxt_set_features(struct net_device
*dev
, netdev_features_t features
)
5287 struct bnxt
*bp
= netdev_priv(dev
);
5288 u32 flags
= bp
->flags
;
5291 bool re_init
= false;
5292 bool update_tpa
= false;
5294 flags
&= ~BNXT_FLAG_ALL_CONFIG_FEATS
;
5295 if ((features
& NETIF_F_GRO
) && (bp
->pdev
->revision
> 0))
5296 flags
|= BNXT_FLAG_GRO
;
5297 if (features
& NETIF_F_LRO
)
5298 flags
|= BNXT_FLAG_LRO
;
5300 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
5301 flags
|= BNXT_FLAG_STRIP_VLAN
;
5303 if (features
& NETIF_F_NTUPLE
)
5304 flags
|= BNXT_FLAG_RFS
;
5306 changes
= flags
^ bp
->flags
;
5307 if (changes
& BNXT_FLAG_TPA
) {
5309 if ((bp
->flags
& BNXT_FLAG_TPA
) == 0 ||
5310 (flags
& BNXT_FLAG_TPA
) == 0)
5314 if (changes
& ~BNXT_FLAG_TPA
)
5317 if (flags
!= bp
->flags
) {
5318 u32 old_flags
= bp
->flags
;
5322 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
5324 bnxt_set_ring_params(bp
);
5329 bnxt_close_nic(bp
, false, false);
5331 bnxt_set_ring_params(bp
);
5333 return bnxt_open_nic(bp
, false, false);
5336 rc
= bnxt_set_tpa(bp
,
5337 (flags
& BNXT_FLAG_TPA
) ?
5340 bp
->flags
= old_flags
;
5346 static void bnxt_dump_tx_sw_state(struct bnxt_napi
*bnapi
)
5348 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
5349 int i
= bnapi
->index
;
5354 netdev_info(bnapi
->bp
->dev
, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
5355 i
, txr
->tx_ring_struct
.fw_ring_id
, txr
->tx_prod
,
5359 static void bnxt_dump_rx_sw_state(struct bnxt_napi
*bnapi
)
5361 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
5362 int i
= bnapi
->index
;
5367 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",
5368 i
, rxr
->rx_ring_struct
.fw_ring_id
, rxr
->rx_prod
,
5369 rxr
->rx_agg_ring_struct
.fw_ring_id
, rxr
->rx_agg_prod
,
5370 rxr
->rx_sw_agg_prod
);
5373 static void bnxt_dump_cp_sw_state(struct bnxt_napi
*bnapi
)
5375 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5376 int i
= bnapi
->index
;
5378 netdev_info(bnapi
->bp
->dev
, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
5379 i
, cpr
->cp_ring_struct
.fw_ring_id
, cpr
->cp_raw_cons
);
5382 static void bnxt_dbg_dump_states(struct bnxt
*bp
)
5385 struct bnxt_napi
*bnapi
;
5387 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5388 bnapi
= bp
->bnapi
[i
];
5389 if (netif_msg_drv(bp
)) {
5390 bnxt_dump_tx_sw_state(bnapi
);
5391 bnxt_dump_rx_sw_state(bnapi
);
5392 bnxt_dump_cp_sw_state(bnapi
);
5397 static void bnxt_reset_task(struct bnxt
*bp
)
5399 bnxt_dbg_dump_states(bp
);
5400 if (netif_running(bp
->dev
)) {
5401 bnxt_close_nic(bp
, false, false);
5402 bnxt_open_nic(bp
, false, false);
5406 static void bnxt_tx_timeout(struct net_device
*dev
)
5408 struct bnxt
*bp
= netdev_priv(dev
);
5410 netdev_err(bp
->dev
, "TX timeout detected, starting reset task!\n");
5411 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
5412 schedule_work(&bp
->sp_task
);
5415 #ifdef CONFIG_NET_POLL_CONTROLLER
5416 static void bnxt_poll_controller(struct net_device
*dev
)
5418 struct bnxt
*bp
= netdev_priv(dev
);
5421 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5422 struct bnxt_irq
*irq
= &bp
->irq_tbl
[i
];
5424 disable_irq(irq
->vector
);
5425 irq
->handler(irq
->vector
, bp
->bnapi
[i
]);
5426 enable_irq(irq
->vector
);
5431 static void bnxt_timer(unsigned long data
)
5433 struct bnxt
*bp
= (struct bnxt
*)data
;
5434 struct net_device
*dev
= bp
->dev
;
5436 if (!netif_running(dev
))
5439 if (atomic_read(&bp
->intr_sem
) != 0)
5440 goto bnxt_restart_timer
;
5442 if (bp
->link_info
.link_up
&& (bp
->flags
& BNXT_FLAG_PORT_STATS
)) {
5443 set_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
);
5444 schedule_work(&bp
->sp_task
);
5447 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
5450 static void bnxt_cfg_ntp_filters(struct bnxt
*);
5452 static void bnxt_sp_task(struct work_struct
*work
)
5454 struct bnxt
*bp
= container_of(work
, struct bnxt
, sp_task
);
5457 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
5458 smp_mb__after_atomic();
5459 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
5460 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
5464 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
))
5465 bnxt_cfg_rx_mode(bp
);
5467 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
))
5468 bnxt_cfg_ntp_filters(bp
);
5469 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
)) {
5470 rc
= bnxt_update_link(bp
, true);
5472 netdev_err(bp
->dev
, "SP task can't update link (rc: %x)\n",
5475 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
))
5476 bnxt_hwrm_exec_fwd_req(bp
);
5477 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
5478 bnxt_hwrm_tunnel_dst_port_alloc(
5480 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
5482 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
5483 bnxt_hwrm_tunnel_dst_port_free(
5484 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
5486 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
)) {
5487 /* bnxt_reset_task() calls bnxt_close_nic() which waits
5488 * for BNXT_STATE_IN_SP_TASK to clear.
5490 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
5492 bnxt_reset_task(bp
);
5493 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
5497 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
))
5498 bnxt_hwrm_port_qstats(bp
);
5500 smp_mb__before_atomic();
5501 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
5504 static int bnxt_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
5507 struct bnxt
*bp
= netdev_priv(dev
);
5509 SET_NETDEV_DEV(dev
, &pdev
->dev
);
5511 /* enable device (incl. PCI PM wakeup), and bus-mastering */
5512 rc
= pci_enable_device(pdev
);
5514 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
5518 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
5520 "Cannot find PCI device base address, aborting\n");
5522 goto init_err_disable
;
5525 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
5527 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
5528 goto init_err_disable
;
5531 if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64)) != 0 &&
5532 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)) != 0) {
5533 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
5534 goto init_err_disable
;
5537 pci_set_master(pdev
);
5542 bp
->bar0
= pci_ioremap_bar(pdev
, 0);
5544 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
5546 goto init_err_release
;
5549 bp
->bar1
= pci_ioremap_bar(pdev
, 2);
5551 dev_err(&pdev
->dev
, "Cannot map doorbell registers, aborting\n");
5553 goto init_err_release
;
5556 bp
->bar2
= pci_ioremap_bar(pdev
, 4);
5558 dev_err(&pdev
->dev
, "Cannot map bar4 registers, aborting\n");
5560 goto init_err_release
;
5563 pci_enable_pcie_error_reporting(pdev
);
5565 INIT_WORK(&bp
->sp_task
, bnxt_sp_task
);
5567 spin_lock_init(&bp
->ntp_fltr_lock
);
5569 bp
->rx_ring_size
= BNXT_DEFAULT_RX_RING_SIZE
;
5570 bp
->tx_ring_size
= BNXT_DEFAULT_TX_RING_SIZE
;
5572 /* tick values in micro seconds */
5573 bp
->rx_coal_ticks
= 12;
5574 bp
->rx_coal_bufs
= 30;
5575 bp
->rx_coal_ticks_irq
= 1;
5576 bp
->rx_coal_bufs_irq
= 2;
5578 bp
->tx_coal_ticks
= 25;
5579 bp
->tx_coal_bufs
= 30;
5580 bp
->tx_coal_ticks_irq
= 2;
5581 bp
->tx_coal_bufs_irq
= 2;
5583 init_timer(&bp
->timer
);
5584 bp
->timer
.data
= (unsigned long)bp
;
5585 bp
->timer
.function
= bnxt_timer
;
5586 bp
->current_interval
= BNXT_TIMER_INTERVAL
;
5588 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
5594 pci_iounmap(pdev
, bp
->bar2
);
5599 pci_iounmap(pdev
, bp
->bar1
);
5604 pci_iounmap(pdev
, bp
->bar0
);
5608 pci_release_regions(pdev
);
5611 pci_disable_device(pdev
);
5617 /* rtnl_lock held */
5618 static int bnxt_change_mac_addr(struct net_device
*dev
, void *p
)
5620 struct sockaddr
*addr
= p
;
5621 struct bnxt
*bp
= netdev_priv(dev
);
5624 if (!is_valid_ether_addr(addr
->sa_data
))
5625 return -EADDRNOTAVAIL
;
5627 #ifdef CONFIG_BNXT_SRIOV
5628 if (BNXT_VF(bp
) && is_valid_ether_addr(bp
->vf
.mac_addr
))
5629 return -EADDRNOTAVAIL
;
5632 if (ether_addr_equal(addr
->sa_data
, dev
->dev_addr
))
5635 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
5636 if (netif_running(dev
)) {
5637 bnxt_close_nic(bp
, false, false);
5638 rc
= bnxt_open_nic(bp
, false, false);
5644 /* rtnl_lock held */
5645 static int bnxt_change_mtu(struct net_device
*dev
, int new_mtu
)
5647 struct bnxt
*bp
= netdev_priv(dev
);
5649 if (new_mtu
< 60 || new_mtu
> 9000)
5652 if (netif_running(dev
))
5653 bnxt_close_nic(bp
, false, false);
5656 bnxt_set_ring_params(bp
);
5658 if (netif_running(dev
))
5659 return bnxt_open_nic(bp
, false, false);
5664 static int bnxt_setup_tc(struct net_device
*dev
, u32 handle
, __be16 proto
,
5665 struct tc_to_netdev
*ntc
)
5667 struct bnxt
*bp
= netdev_priv(dev
);
5670 if (ntc
->type
!= TC_SETUP_MQPRIO
)
5675 if (tc
> bp
->max_tc
) {
5676 netdev_err(dev
, "too many traffic classes requested: %d Max supported is %d\n",
5681 if (netdev_get_num_tc(dev
) == tc
)
5685 int max_rx_rings
, max_tx_rings
, rc
;
5688 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
5691 rc
= bnxt_get_max_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
5692 if (rc
|| bp
->tx_nr_rings_per_tc
* tc
> max_tx_rings
)
5696 /* Needs to close the device and do hw resource re-allocations */
5697 if (netif_running(bp
->dev
))
5698 bnxt_close_nic(bp
, true, false);
5701 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tc
;
5702 netdev_set_num_tc(dev
, tc
);
5704 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
5705 netdev_reset_tc(dev
);
5707 bp
->cp_nr_rings
= max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
);
5708 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
5710 if (netif_running(bp
->dev
))
5711 return bnxt_open_nic(bp
, true, false);
5716 #ifdef CONFIG_RFS_ACCEL
5717 static bool bnxt_fltr_match(struct bnxt_ntuple_filter
*f1
,
5718 struct bnxt_ntuple_filter
*f2
)
5720 struct flow_keys
*keys1
= &f1
->fkeys
;
5721 struct flow_keys
*keys2
= &f2
->fkeys
;
5723 if (keys1
->addrs
.v4addrs
.src
== keys2
->addrs
.v4addrs
.src
&&
5724 keys1
->addrs
.v4addrs
.dst
== keys2
->addrs
.v4addrs
.dst
&&
5725 keys1
->ports
.ports
== keys2
->ports
.ports
&&
5726 keys1
->basic
.ip_proto
== keys2
->basic
.ip_proto
&&
5727 keys1
->basic
.n_proto
== keys2
->basic
.n_proto
&&
5728 ether_addr_equal(f1
->src_mac_addr
, f2
->src_mac_addr
))
5734 static int bnxt_rx_flow_steer(struct net_device
*dev
, const struct sk_buff
*skb
,
5735 u16 rxq_index
, u32 flow_id
)
5737 struct bnxt
*bp
= netdev_priv(dev
);
5738 struct bnxt_ntuple_filter
*fltr
, *new_fltr
;
5739 struct flow_keys
*fkeys
;
5740 struct ethhdr
*eth
= (struct ethhdr
*)skb_mac_header(skb
);
5741 int rc
= 0, idx
, bit_id
;
5742 struct hlist_head
*head
;
5744 if (skb
->encapsulation
)
5745 return -EPROTONOSUPPORT
;
5747 new_fltr
= kzalloc(sizeof(*new_fltr
), GFP_ATOMIC
);
5751 fkeys
= &new_fltr
->fkeys
;
5752 if (!skb_flow_dissect_flow_keys(skb
, fkeys
, 0)) {
5753 rc
= -EPROTONOSUPPORT
;
5757 if ((fkeys
->basic
.n_proto
!= htons(ETH_P_IP
)) ||
5758 ((fkeys
->basic
.ip_proto
!= IPPROTO_TCP
) &&
5759 (fkeys
->basic
.ip_proto
!= IPPROTO_UDP
))) {
5760 rc
= -EPROTONOSUPPORT
;
5764 memcpy(new_fltr
->src_mac_addr
, eth
->h_source
, ETH_ALEN
);
5766 idx
= skb_get_hash_raw(skb
) & BNXT_NTP_FLTR_HASH_MASK
;
5767 head
= &bp
->ntp_fltr_hash_tbl
[idx
];
5769 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
5770 if (bnxt_fltr_match(fltr
, new_fltr
)) {
5778 spin_lock_bh(&bp
->ntp_fltr_lock
);
5779 bit_id
= bitmap_find_free_region(bp
->ntp_fltr_bmap
,
5780 BNXT_NTP_FLTR_MAX_FLTR
, 0);
5782 spin_unlock_bh(&bp
->ntp_fltr_lock
);
5787 new_fltr
->sw_id
= (u16
)bit_id
;
5788 new_fltr
->flow_id
= flow_id
;
5789 new_fltr
->rxq
= rxq_index
;
5790 hlist_add_head_rcu(&new_fltr
->hash
, head
);
5791 bp
->ntp_fltr_count
++;
5792 spin_unlock_bh(&bp
->ntp_fltr_lock
);
5794 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
5795 schedule_work(&bp
->sp_task
);
5797 return new_fltr
->sw_id
;
5804 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
5808 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
5809 struct hlist_head
*head
;
5810 struct hlist_node
*tmp
;
5811 struct bnxt_ntuple_filter
*fltr
;
5814 head
= &bp
->ntp_fltr_hash_tbl
[i
];
5815 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
5818 if (test_bit(BNXT_FLTR_VALID
, &fltr
->state
)) {
5819 if (rps_may_expire_flow(bp
->dev
, fltr
->rxq
,
5822 bnxt_hwrm_cfa_ntuple_filter_free(bp
,
5827 rc
= bnxt_hwrm_cfa_ntuple_filter_alloc(bp
,
5832 set_bit(BNXT_FLTR_VALID
, &fltr
->state
);
5836 spin_lock_bh(&bp
->ntp_fltr_lock
);
5837 hlist_del_rcu(&fltr
->hash
);
5838 bp
->ntp_fltr_count
--;
5839 spin_unlock_bh(&bp
->ntp_fltr_lock
);
5841 clear_bit(fltr
->sw_id
, bp
->ntp_fltr_bmap
);
5846 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
))
5847 netdev_info(bp
->dev
, "Receive PF driver unload event!");
5852 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
5856 #endif /* CONFIG_RFS_ACCEL */
5858 static void bnxt_add_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
5861 struct bnxt
*bp
= netdev_priv(dev
);
5863 if (!netif_running(dev
))
5866 if (sa_family
!= AF_INET6
&& sa_family
!= AF_INET
)
5869 if (bp
->vxlan_port_cnt
&& bp
->vxlan_port
!= port
)
5872 bp
->vxlan_port_cnt
++;
5873 if (bp
->vxlan_port_cnt
== 1) {
5874 bp
->vxlan_port
= port
;
5875 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
5876 schedule_work(&bp
->sp_task
);
5880 static void bnxt_del_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
5883 struct bnxt
*bp
= netdev_priv(dev
);
5885 if (!netif_running(dev
))
5888 if (sa_family
!= AF_INET6
&& sa_family
!= AF_INET
)
5891 if (bp
->vxlan_port_cnt
&& bp
->vxlan_port
== port
) {
5892 bp
->vxlan_port_cnt
--;
5894 if (bp
->vxlan_port_cnt
== 0) {
5895 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
5896 schedule_work(&bp
->sp_task
);
5901 static const struct net_device_ops bnxt_netdev_ops
= {
5902 .ndo_open
= bnxt_open
,
5903 .ndo_start_xmit
= bnxt_start_xmit
,
5904 .ndo_stop
= bnxt_close
,
5905 .ndo_get_stats64
= bnxt_get_stats64
,
5906 .ndo_set_rx_mode
= bnxt_set_rx_mode
,
5907 .ndo_do_ioctl
= bnxt_ioctl
,
5908 .ndo_validate_addr
= eth_validate_addr
,
5909 .ndo_set_mac_address
= bnxt_change_mac_addr
,
5910 .ndo_change_mtu
= bnxt_change_mtu
,
5911 .ndo_fix_features
= bnxt_fix_features
,
5912 .ndo_set_features
= bnxt_set_features
,
5913 .ndo_tx_timeout
= bnxt_tx_timeout
,
5914 #ifdef CONFIG_BNXT_SRIOV
5915 .ndo_get_vf_config
= bnxt_get_vf_config
,
5916 .ndo_set_vf_mac
= bnxt_set_vf_mac
,
5917 .ndo_set_vf_vlan
= bnxt_set_vf_vlan
,
5918 .ndo_set_vf_rate
= bnxt_set_vf_bw
,
5919 .ndo_set_vf_link_state
= bnxt_set_vf_link_state
,
5920 .ndo_set_vf_spoofchk
= bnxt_set_vf_spoofchk
,
5922 #ifdef CONFIG_NET_POLL_CONTROLLER
5923 .ndo_poll_controller
= bnxt_poll_controller
,
5925 .ndo_setup_tc
= bnxt_setup_tc
,
5926 #ifdef CONFIG_RFS_ACCEL
5927 .ndo_rx_flow_steer
= bnxt_rx_flow_steer
,
5929 .ndo_add_vxlan_port
= bnxt_add_vxlan_port
,
5930 .ndo_del_vxlan_port
= bnxt_del_vxlan_port
,
5931 #ifdef CONFIG_NET_RX_BUSY_POLL
5932 .ndo_busy_poll
= bnxt_busy_poll
,
5936 static void bnxt_remove_one(struct pci_dev
*pdev
)
5938 struct net_device
*dev
= pci_get_drvdata(pdev
);
5939 struct bnxt
*bp
= netdev_priv(dev
);
5942 bnxt_sriov_disable(bp
);
5944 pci_disable_pcie_error_reporting(pdev
);
5945 unregister_netdev(dev
);
5946 cancel_work_sync(&bp
->sp_task
);
5949 bnxt_hwrm_func_drv_unrgtr(bp
);
5950 bnxt_free_hwrm_resources(bp
);
5951 pci_iounmap(pdev
, bp
->bar2
);
5952 pci_iounmap(pdev
, bp
->bar1
);
5953 pci_iounmap(pdev
, bp
->bar0
);
5956 pci_release_regions(pdev
);
5957 pci_disable_device(pdev
);
5960 static int bnxt_probe_phy(struct bnxt
*bp
)
5963 struct bnxt_link_info
*link_info
= &bp
->link_info
;
5965 rc
= bnxt_hwrm_phy_qcaps(bp
);
5967 netdev_err(bp
->dev
, "Probe phy can't get phy capabilities (rc: %x)\n",
5972 rc
= bnxt_update_link(bp
, false);
5974 netdev_err(bp
->dev
, "Probe phy can't update link (rc: %x)\n",
5979 /*initialize the ethool setting copy with NVM settings */
5980 if (BNXT_AUTO_MODE(link_info
->auto_mode
)) {
5981 link_info
->autoneg
= BNXT_AUTONEG_SPEED
;
5982 if (bp
->hwrm_spec_code
>= 0x10201) {
5983 if (link_info
->auto_pause_setting
&
5984 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
)
5985 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
5987 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
5989 link_info
->advertising
= link_info
->auto_link_speeds
;
5991 link_info
->req_link_speed
= link_info
->force_link_speed
;
5992 link_info
->req_duplex
= link_info
->duplex_setting
;
5994 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
5995 link_info
->req_flow_ctrl
=
5996 link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
;
5998 link_info
->req_flow_ctrl
= link_info
->force_pause_setting
;
6002 static int bnxt_get_max_irq(struct pci_dev
*pdev
)
6006 if (!pdev
->msix_cap
)
6009 pci_read_config_word(pdev
, pdev
->msix_cap
+ PCI_MSIX_FLAGS
, &ctrl
);
6010 return (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
6013 static void _bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
6016 int max_ring_grps
= 0;
6018 #ifdef CONFIG_BNXT_SRIOV
6020 *max_tx
= bp
->vf
.max_tx_rings
;
6021 *max_rx
= bp
->vf
.max_rx_rings
;
6022 *max_cp
= min_t(int, bp
->vf
.max_irqs
, bp
->vf
.max_cp_rings
);
6023 *max_cp
= min_t(int, *max_cp
, bp
->vf
.max_stat_ctxs
);
6024 max_ring_grps
= bp
->vf
.max_hw_ring_grps
;
6028 *max_tx
= bp
->pf
.max_tx_rings
;
6029 *max_rx
= bp
->pf
.max_rx_rings
;
6030 *max_cp
= min_t(int, bp
->pf
.max_irqs
, bp
->pf
.max_cp_rings
);
6031 *max_cp
= min_t(int, *max_cp
, bp
->pf
.max_stat_ctxs
);
6032 max_ring_grps
= bp
->pf
.max_hw_ring_grps
;
6035 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
6037 *max_rx
= min_t(int, *max_rx
, max_ring_grps
);
6040 int bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
, bool shared
)
6044 _bnxt_get_max_rings(bp
, &rx
, &tx
, &cp
);
6045 if (!rx
|| !tx
|| !cp
)
6050 return bnxt_trim_rings(bp
, max_rx
, max_tx
, cp
, shared
);
6053 static int bnxt_set_dflt_rings(struct bnxt
*bp
)
6055 int dflt_rings
, max_rx_rings
, max_tx_rings
, rc
;
6059 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
6060 dflt_rings
= netif_get_num_default_rss_queues();
6061 rc
= bnxt_get_max_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
6064 bp
->rx_nr_rings
= min_t(int, dflt_rings
, max_rx_rings
);
6065 bp
->tx_nr_rings_per_tc
= min_t(int, dflt_rings
, max_tx_rings
);
6066 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
6067 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
6068 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
6069 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
6073 static int bnxt_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
6075 static int version_printed
;
6076 struct net_device
*dev
;
6080 if (version_printed
++ == 0)
6081 pr_info("%s", version
);
6083 max_irqs
= bnxt_get_max_irq(pdev
);
6084 dev
= alloc_etherdev_mq(sizeof(*bp
), max_irqs
);
6088 bp
= netdev_priv(dev
);
6090 if (bnxt_vf_pciid(ent
->driver_data
))
6091 bp
->flags
|= BNXT_FLAG_VF
;
6094 bp
->flags
|= BNXT_FLAG_MSIX_CAP
;
6096 rc
= bnxt_init_board(pdev
, dev
);
6100 dev
->netdev_ops
= &bnxt_netdev_ops
;
6101 dev
->watchdog_timeo
= BNXT_TX_TIMEOUT
;
6102 dev
->ethtool_ops
= &bnxt_ethtool_ops
;
6104 pci_set_drvdata(pdev
, dev
);
6106 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
6107 NETIF_F_TSO
| NETIF_F_TSO6
|
6108 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
6109 NETIF_F_GSO_IPIP
| NETIF_F_GSO_SIT
|
6111 NETIF_F_RXCSUM
| NETIF_F_LRO
| NETIF_F_GRO
;
6113 dev
->hw_enc_features
=
6114 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
6115 NETIF_F_TSO
| NETIF_F_TSO6
|
6116 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
6117 NETIF_F_GSO_IPIP
| NETIF_F_GSO_SIT
;
6118 dev
->vlan_features
= dev
->hw_features
| NETIF_F_HIGHDMA
;
6119 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_CTAG_TX
|
6120 NETIF_F_HW_VLAN_STAG_RX
| NETIF_F_HW_VLAN_STAG_TX
;
6121 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
6122 dev
->priv_flags
|= IFF_UNICAST_FLT
;
6124 #ifdef CONFIG_BNXT_SRIOV
6125 init_waitqueue_head(&bp
->sriov_cfg_wait
);
6127 rc
= bnxt_alloc_hwrm_resources(bp
);
6131 mutex_init(&bp
->hwrm_cmd_lock
);
6132 bnxt_hwrm_ver_get(bp
);
6134 rc
= bnxt_hwrm_func_drv_rgtr(bp
);
6138 /* Get the MAX capabilities for this function */
6139 rc
= bnxt_hwrm_func_qcaps(bp
);
6141 netdev_err(bp
->dev
, "hwrm query capability failure rc: %x\n",
6147 rc
= bnxt_hwrm_queue_qportcfg(bp
);
6149 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %x\n",
6155 bnxt_set_tpa_flags(bp
);
6156 bnxt_set_ring_params(bp
);
6158 bp
->pf
.max_irqs
= max_irqs
;
6159 #if defined(CONFIG_BNXT_SRIOV)
6161 bp
->vf
.max_irqs
= max_irqs
;
6163 bnxt_set_dflt_rings(bp
);
6166 dev
->hw_features
|= NETIF_F_NTUPLE
;
6167 if (bnxt_rfs_capable(bp
)) {
6168 bp
->flags
|= BNXT_FLAG_RFS
;
6169 dev
->features
|= NETIF_F_NTUPLE
;
6173 if (dev
->hw_features
& NETIF_F_HW_VLAN_CTAG_RX
)
6174 bp
->flags
|= BNXT_FLAG_STRIP_VLAN
;
6176 rc
= bnxt_probe_phy(bp
);
6180 rc
= register_netdev(dev
);
6184 netdev_info(dev
, "%s found at mem %lx, node addr %pM\n",
6185 board_info
[ent
->driver_data
].name
,
6186 (long)pci_resource_start(pdev
, 0), dev
->dev_addr
);
6191 pci_iounmap(pdev
, bp
->bar0
);
6192 pci_release_regions(pdev
);
6193 pci_disable_device(pdev
);
6201 * bnxt_io_error_detected - called when PCI error is detected
6202 * @pdev: Pointer to PCI device
6203 * @state: The current pci connection state
6205 * This function is called after a PCI bus error affecting
6206 * this device has been detected.
6208 static pci_ers_result_t
bnxt_io_error_detected(struct pci_dev
*pdev
,
6209 pci_channel_state_t state
)
6211 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6213 netdev_info(netdev
, "PCI I/O error detected\n");
6216 netif_device_detach(netdev
);
6218 if (state
== pci_channel_io_perm_failure
) {
6220 return PCI_ERS_RESULT_DISCONNECT
;
6223 if (netif_running(netdev
))
6226 pci_disable_device(pdev
);
6229 /* Request a slot slot reset. */
6230 return PCI_ERS_RESULT_NEED_RESET
;
6234 * bnxt_io_slot_reset - called after the pci bus has been reset.
6235 * @pdev: Pointer to PCI device
6237 * Restart the card from scratch, as if from a cold-boot.
6238 * At this point, the card has exprienced a hard reset,
6239 * followed by fixups by BIOS, and has its config space
6240 * set up identically to what it was at cold boot.
6242 static pci_ers_result_t
bnxt_io_slot_reset(struct pci_dev
*pdev
)
6244 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6245 struct bnxt
*bp
= netdev_priv(netdev
);
6247 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
6249 netdev_info(bp
->dev
, "PCI Slot Reset\n");
6253 if (pci_enable_device(pdev
)) {
6255 "Cannot re-enable PCI device after reset.\n");
6257 pci_set_master(pdev
);
6259 if (netif_running(netdev
))
6260 err
= bnxt_open(netdev
);
6263 result
= PCI_ERS_RESULT_RECOVERED
;
6266 if (result
!= PCI_ERS_RESULT_RECOVERED
&& netif_running(netdev
))
6271 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
6274 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
6275 err
); /* non-fatal, continue */
6278 return PCI_ERS_RESULT_RECOVERED
;
6282 * bnxt_io_resume - called when traffic can start flowing again.
6283 * @pdev: Pointer to PCI device
6285 * This callback is called when the error recovery driver tells
6286 * us that its OK to resume normal operation.
6288 static void bnxt_io_resume(struct pci_dev
*pdev
)
6290 struct net_device
*netdev
= pci_get_drvdata(pdev
);
6294 netif_device_attach(netdev
);
6299 static const struct pci_error_handlers bnxt_err_handler
= {
6300 .error_detected
= bnxt_io_error_detected
,
6301 .slot_reset
= bnxt_io_slot_reset
,
6302 .resume
= bnxt_io_resume
6305 static struct pci_driver bnxt_pci_driver
= {
6306 .name
= DRV_MODULE_NAME
,
6307 .id_table
= bnxt_pci_tbl
,
6308 .probe
= bnxt_init_one
,
6309 .remove
= bnxt_remove_one
,
6310 .err_handler
= &bnxt_err_handler
,
6311 #if defined(CONFIG_BNXT_SRIOV)
6312 .sriov_configure
= bnxt_sriov_configure
,
6316 module_pci_driver(bnxt_pci_driver
);