1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2018 Broadcom Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
11 #include <linux/module.h>
13 #include <linux/stringify.h>
14 #include <linux/kernel.h>
15 #include <linux/timer.h>
16 #include <linux/errno.h>
17 #include <linux/ioport.h>
18 #include <linux/slab.h>
19 #include <linux/vmalloc.h>
20 #include <linux/interrupt.h>
21 #include <linux/pci.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/bitops.h>
28 #include <linux/irq.h>
29 #include <linux/delay.h>
30 #include <asm/byteorder.h>
32 #include <linux/time.h>
33 #include <linux/mii.h>
35 #include <linux/if_vlan.h>
36 #include <linux/if_bridge.h>
37 #include <linux/rtc.h>
38 #include <linux/bpf.h>
42 #include <net/checksum.h>
43 #include <net/ip6_checksum.h>
44 #include <net/udp_tunnel.h>
45 #include <linux/workqueue.h>
46 #include <linux/prefetch.h>
47 #include <linux/cache.h>
48 #include <linux/log2.h>
49 #include <linux/aer.h>
50 #include <linux/bitmap.h>
51 #include <linux/cpu_rmap.h>
52 #include <linux/cpumask.h>
53 #include <net/pkt_cls.h>
54 #include <linux/hwmon.h>
55 #include <linux/hwmon-sysfs.h>
60 #include "bnxt_sriov.h"
61 #include "bnxt_ethtool.h"
66 #include "bnxt_devlink.h"
67 #include "bnxt_debugfs.h"
69 #define BNXT_TX_TIMEOUT (5 * HZ)
71 static const char version
[] =
72 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME
" v" DRV_MODULE_VERSION
"\n";
74 MODULE_LICENSE("GPL");
75 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
76 MODULE_VERSION(DRV_MODULE_VERSION
);
78 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
79 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
80 #define BNXT_RX_COPY_THRESH 256
82 #define BNXT_TX_PUSH_THRESH 164
122 /* indexed by enum above */
123 static const struct {
126 [BCM57301
] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
127 [BCM57302
] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
128 [BCM57304
] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
129 [BCM57417_NPAR
] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
130 [BCM58700
] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
131 [BCM57311
] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
132 [BCM57312
] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
133 [BCM57402
] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
134 [BCM57404
] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
135 [BCM57406
] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
136 [BCM57402_NPAR
] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
137 [BCM57407
] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
138 [BCM57412
] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
139 [BCM57414
] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
140 [BCM57416
] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
141 [BCM57417
] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
142 [BCM57412_NPAR
] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
143 [BCM57314
] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
144 [BCM57417_SFP
] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
145 [BCM57416_SFP
] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
146 [BCM57404_NPAR
] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
147 [BCM57406_NPAR
] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
148 [BCM57407_SFP
] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
149 [BCM57407_NPAR
] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
150 [BCM57414_NPAR
] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
151 [BCM57416_NPAR
] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
152 [BCM57452
] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
153 [BCM57454
] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
154 [BCM5745x_NPAR
] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
155 [BCM58802
] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
156 [BCM58804
] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
157 [BCM58808
] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
158 [NETXTREME_E_VF
] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
159 [NETXTREME_C_VF
] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
160 [NETXTREME_S_VF
] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
163 static const struct pci_device_id bnxt_pci_tbl
[] = {
164 { PCI_VDEVICE(BROADCOM
, 0x1604), .driver_data
= BCM5745x_NPAR
},
165 { PCI_VDEVICE(BROADCOM
, 0x1605), .driver_data
= BCM5745x_NPAR
},
166 { PCI_VDEVICE(BROADCOM
, 0x1614), .driver_data
= BCM57454
},
167 { PCI_VDEVICE(BROADCOM
, 0x16c0), .driver_data
= BCM57417_NPAR
},
168 { PCI_VDEVICE(BROADCOM
, 0x16c8), .driver_data
= BCM57301
},
169 { PCI_VDEVICE(BROADCOM
, 0x16c9), .driver_data
= BCM57302
},
170 { PCI_VDEVICE(BROADCOM
, 0x16ca), .driver_data
= BCM57304
},
171 { PCI_VDEVICE(BROADCOM
, 0x16cc), .driver_data
= BCM57417_NPAR
},
172 { PCI_VDEVICE(BROADCOM
, 0x16cd), .driver_data
= BCM58700
},
173 { PCI_VDEVICE(BROADCOM
, 0x16ce), .driver_data
= BCM57311
},
174 { PCI_VDEVICE(BROADCOM
, 0x16cf), .driver_data
= BCM57312
},
175 { PCI_VDEVICE(BROADCOM
, 0x16d0), .driver_data
= BCM57402
},
176 { PCI_VDEVICE(BROADCOM
, 0x16d1), .driver_data
= BCM57404
},
177 { PCI_VDEVICE(BROADCOM
, 0x16d2), .driver_data
= BCM57406
},
178 { PCI_VDEVICE(BROADCOM
, 0x16d4), .driver_data
= BCM57402_NPAR
},
179 { PCI_VDEVICE(BROADCOM
, 0x16d5), .driver_data
= BCM57407
},
180 { PCI_VDEVICE(BROADCOM
, 0x16d6), .driver_data
= BCM57412
},
181 { PCI_VDEVICE(BROADCOM
, 0x16d7), .driver_data
= BCM57414
},
182 { PCI_VDEVICE(BROADCOM
, 0x16d8), .driver_data
= BCM57416
},
183 { PCI_VDEVICE(BROADCOM
, 0x16d9), .driver_data
= BCM57417
},
184 { PCI_VDEVICE(BROADCOM
, 0x16de), .driver_data
= BCM57412_NPAR
},
185 { PCI_VDEVICE(BROADCOM
, 0x16df), .driver_data
= BCM57314
},
186 { PCI_VDEVICE(BROADCOM
, 0x16e2), .driver_data
= BCM57417_SFP
},
187 { PCI_VDEVICE(BROADCOM
, 0x16e3), .driver_data
= BCM57416_SFP
},
188 { PCI_VDEVICE(BROADCOM
, 0x16e7), .driver_data
= BCM57404_NPAR
},
189 { PCI_VDEVICE(BROADCOM
, 0x16e8), .driver_data
= BCM57406_NPAR
},
190 { PCI_VDEVICE(BROADCOM
, 0x16e9), .driver_data
= BCM57407_SFP
},
191 { PCI_VDEVICE(BROADCOM
, 0x16ea), .driver_data
= BCM57407_NPAR
},
192 { PCI_VDEVICE(BROADCOM
, 0x16eb), .driver_data
= BCM57412_NPAR
},
193 { PCI_VDEVICE(BROADCOM
, 0x16ec), .driver_data
= BCM57414_NPAR
},
194 { PCI_VDEVICE(BROADCOM
, 0x16ed), .driver_data
= BCM57414_NPAR
},
195 { PCI_VDEVICE(BROADCOM
, 0x16ee), .driver_data
= BCM57416_NPAR
},
196 { PCI_VDEVICE(BROADCOM
, 0x16ef), .driver_data
= BCM57416_NPAR
},
197 { PCI_VDEVICE(BROADCOM
, 0x16f0), .driver_data
= BCM58808
},
198 { PCI_VDEVICE(BROADCOM
, 0x16f1), .driver_data
= BCM57452
},
199 { PCI_VDEVICE(BROADCOM
, 0xd802), .driver_data
= BCM58802
},
200 { PCI_VDEVICE(BROADCOM
, 0xd804), .driver_data
= BCM58804
},
201 #ifdef CONFIG_BNXT_SRIOV
202 { PCI_VDEVICE(BROADCOM
, 0x1606), .driver_data
= NETXTREME_E_VF
},
203 { PCI_VDEVICE(BROADCOM
, 0x1609), .driver_data
= NETXTREME_E_VF
},
204 { PCI_VDEVICE(BROADCOM
, 0x16c1), .driver_data
= NETXTREME_E_VF
},
205 { PCI_VDEVICE(BROADCOM
, 0x16cb), .driver_data
= NETXTREME_C_VF
},
206 { PCI_VDEVICE(BROADCOM
, 0x16d3), .driver_data
= NETXTREME_E_VF
},
207 { PCI_VDEVICE(BROADCOM
, 0x16dc), .driver_data
= NETXTREME_E_VF
},
208 { PCI_VDEVICE(BROADCOM
, 0x16e1), .driver_data
= NETXTREME_C_VF
},
209 { PCI_VDEVICE(BROADCOM
, 0x16e5), .driver_data
= NETXTREME_C_VF
},
210 { PCI_VDEVICE(BROADCOM
, 0xd800), .driver_data
= NETXTREME_S_VF
},
215 MODULE_DEVICE_TABLE(pci
, bnxt_pci_tbl
);
217 static const u16 bnxt_vf_req_snif
[] = {
221 HWRM_CFA_L2_FILTER_ALLOC
,
224 static const u16 bnxt_async_events_arr
[] = {
225 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
,
226 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
,
227 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
,
228 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
,
229 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
,
232 static struct workqueue_struct
*bnxt_pf_wq
;
234 static bool bnxt_vf_pciid(enum board_idx idx
)
236 return (idx
== NETXTREME_C_VF
|| idx
== NETXTREME_E_VF
||
237 idx
== NETXTREME_S_VF
);
240 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
241 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
242 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
244 #define BNXT_CP_DB_REARM(db, raw_cons) \
245 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
247 #define BNXT_CP_DB(db, raw_cons) \
248 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
250 #define BNXT_CP_DB_IRQ_DIS(db) \
251 writel(DB_CP_IRQ_DIS_FLAGS, db)
253 const u16 bnxt_lhint_arr
[] = {
254 TX_BD_FLAGS_LHINT_512_AND_SMALLER
,
255 TX_BD_FLAGS_LHINT_512_TO_1023
,
256 TX_BD_FLAGS_LHINT_1024_TO_2047
,
257 TX_BD_FLAGS_LHINT_1024_TO_2047
,
258 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
259 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
260 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
261 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
262 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
263 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
264 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
265 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
266 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
267 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
268 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
269 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
270 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
271 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
272 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
275 static u16
bnxt_xmit_get_cfa_action(struct sk_buff
*skb
)
277 struct metadata_dst
*md_dst
= skb_metadata_dst(skb
);
279 if (!md_dst
|| md_dst
->type
!= METADATA_HW_PORT_MUX
)
282 return md_dst
->u
.port_info
.port_id
;
285 static netdev_tx_t
bnxt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
287 struct bnxt
*bp
= netdev_priv(dev
);
289 struct tx_bd_ext
*txbd1
;
290 struct netdev_queue
*txq
;
293 unsigned int length
, pad
= 0;
294 u32 len
, free_size
, vlan_tag_flags
, cfa_action
, flags
;
296 struct pci_dev
*pdev
= bp
->pdev
;
297 struct bnxt_tx_ring_info
*txr
;
298 struct bnxt_sw_tx_bd
*tx_buf
;
300 i
= skb_get_queue_mapping(skb
);
301 if (unlikely(i
>= bp
->tx_nr_rings
)) {
302 dev_kfree_skb_any(skb
);
306 txq
= netdev_get_tx_queue(dev
, i
);
307 txr
= &bp
->tx_ring
[bp
->tx_ring_map
[i
]];
310 free_size
= bnxt_tx_avail(bp
, txr
);
311 if (unlikely(free_size
< skb_shinfo(skb
)->nr_frags
+ 2)) {
312 netif_tx_stop_queue(txq
);
313 return NETDEV_TX_BUSY
;
317 len
= skb_headlen(skb
);
318 last_frag
= skb_shinfo(skb
)->nr_frags
;
320 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
322 txbd
->tx_bd_opaque
= prod
;
324 tx_buf
= &txr
->tx_buf_ring
[prod
];
326 tx_buf
->nr_frags
= last_frag
;
329 cfa_action
= bnxt_xmit_get_cfa_action(skb
);
330 if (skb_vlan_tag_present(skb
)) {
331 vlan_tag_flags
= TX_BD_CFA_META_KEY_VLAN
|
332 skb_vlan_tag_get(skb
);
333 /* Currently supports 8021Q, 8021AD vlan offloads
334 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
336 if (skb
->vlan_proto
== htons(ETH_P_8021Q
))
337 vlan_tag_flags
|= 1 << TX_BD_CFA_META_TPID_SHIFT
;
340 if (free_size
== bp
->tx_ring_size
&& length
<= bp
->tx_push_thresh
) {
341 struct tx_push_buffer
*tx_push_buf
= txr
->tx_push
;
342 struct tx_push_bd
*tx_push
= &tx_push_buf
->push_bd
;
343 struct tx_bd_ext
*tx_push1
= &tx_push
->txbd2
;
344 void *pdata
= tx_push_buf
->data
;
348 /* Set COAL_NOW to be ready quickly for the next push */
349 tx_push
->tx_bd_len_flags_type
=
350 cpu_to_le32((length
<< TX_BD_LEN_SHIFT
) |
351 TX_BD_TYPE_LONG_TX_BD
|
352 TX_BD_FLAGS_LHINT_512_AND_SMALLER
|
353 TX_BD_FLAGS_COAL_NOW
|
354 TX_BD_FLAGS_PACKET_END
|
355 (2 << TX_BD_FLAGS_BD_CNT_SHIFT
));
357 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
358 tx_push1
->tx_bd_hsize_lflags
=
359 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
361 tx_push1
->tx_bd_hsize_lflags
= 0;
363 tx_push1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
364 tx_push1
->tx_bd_cfa_action
=
365 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
367 end
= pdata
+ length
;
368 end
= PTR_ALIGN(end
, 8) - 1;
371 skb_copy_from_linear_data(skb
, pdata
, len
);
373 for (j
= 0; j
< last_frag
; j
++) {
374 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[j
];
377 fptr
= skb_frag_address_safe(frag
);
381 memcpy(pdata
, fptr
, skb_frag_size(frag
));
382 pdata
+= skb_frag_size(frag
);
385 txbd
->tx_bd_len_flags_type
= tx_push
->tx_bd_len_flags_type
;
386 txbd
->tx_bd_haddr
= txr
->data_mapping
;
387 prod
= NEXT_TX(prod
);
388 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
389 memcpy(txbd
, tx_push1
, sizeof(*txbd
));
390 prod
= NEXT_TX(prod
);
392 cpu_to_le32(DB_KEY_TX_PUSH
| DB_LONG_TX_PUSH
| prod
);
396 netdev_tx_sent_queue(txq
, skb
->len
);
397 wmb(); /* Sync is_push and byte queue before pushing data */
399 push_len
= (length
+ sizeof(*tx_push
) + 7) / 8;
401 __iowrite64_copy(txr
->tx_doorbell
, tx_push_buf
, 16);
402 __iowrite32_copy(txr
->tx_doorbell
+ 4, tx_push_buf
+ 1,
403 (push_len
- 16) << 1);
405 __iowrite64_copy(txr
->tx_doorbell
, tx_push_buf
,
413 if (length
< BNXT_MIN_PKT_SIZE
) {
414 pad
= BNXT_MIN_PKT_SIZE
- length
;
415 if (skb_pad(skb
, pad
)) {
416 /* SKB already freed. */
420 length
= BNXT_MIN_PKT_SIZE
;
423 mapping
= dma_map_single(&pdev
->dev
, skb
->data
, len
, DMA_TO_DEVICE
);
425 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
))) {
426 dev_kfree_skb_any(skb
);
431 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
432 flags
= (len
<< TX_BD_LEN_SHIFT
) | TX_BD_TYPE_LONG_TX_BD
|
433 ((last_frag
+ 2) << TX_BD_FLAGS_BD_CNT_SHIFT
);
435 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
437 prod
= NEXT_TX(prod
);
438 txbd1
= (struct tx_bd_ext
*)
439 &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
441 txbd1
->tx_bd_hsize_lflags
= 0;
442 if (skb_is_gso(skb
)) {
445 if (skb
->encapsulation
)
446 hdr_len
= skb_inner_network_offset(skb
) +
447 skb_inner_network_header_len(skb
) +
448 inner_tcp_hdrlen(skb
);
450 hdr_len
= skb_transport_offset(skb
) +
453 txbd1
->tx_bd_hsize_lflags
= cpu_to_le32(TX_BD_FLAGS_LSO
|
455 (hdr_len
<< (TX_BD_HSIZE_SHIFT
- 1)));
456 length
= skb_shinfo(skb
)->gso_size
;
457 txbd1
->tx_bd_mss
= cpu_to_le32(length
);
459 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
460 txbd1
->tx_bd_hsize_lflags
=
461 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
462 txbd1
->tx_bd_mss
= 0;
466 flags
|= bnxt_lhint_arr
[length
];
467 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
469 txbd1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
470 txbd1
->tx_bd_cfa_action
=
471 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
472 for (i
= 0; i
< last_frag
; i
++) {
473 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
475 prod
= NEXT_TX(prod
);
476 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
478 len
= skb_frag_size(frag
);
479 mapping
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, len
,
482 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
)))
485 tx_buf
= &txr
->tx_buf_ring
[prod
];
486 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
488 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
490 flags
= len
<< TX_BD_LEN_SHIFT
;
491 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
495 txbd
->tx_bd_len_flags_type
=
496 cpu_to_le32(((len
+ pad
) << TX_BD_LEN_SHIFT
) | flags
|
497 TX_BD_FLAGS_PACKET_END
);
499 netdev_tx_sent_queue(txq
, skb
->len
);
501 /* Sync BD data before updating doorbell */
504 prod
= NEXT_TX(prod
);
507 if (!skb
->xmit_more
|| netif_xmit_stopped(txq
))
508 bnxt_db_write(bp
, txr
->tx_doorbell
, DB_KEY_TX
| prod
);
514 if (unlikely(bnxt_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
+ 1)) {
515 if (skb
->xmit_more
&& !tx_buf
->is_push
)
516 bnxt_db_write(bp
, txr
->tx_doorbell
, DB_KEY_TX
| prod
);
518 netif_tx_stop_queue(txq
);
520 /* netif_tx_stop_queue() must be done before checking
521 * tx index in bnxt_tx_avail() below, because in
522 * bnxt_tx_int(), we update tx index before checking for
523 * netif_tx_queue_stopped().
526 if (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
527 netif_tx_wake_queue(txq
);
534 /* start back at beginning and unmap skb */
536 tx_buf
= &txr
->tx_buf_ring
[prod
];
538 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
539 skb_headlen(skb
), PCI_DMA_TODEVICE
);
540 prod
= NEXT_TX(prod
);
542 /* unmap remaining mapped pages */
543 for (i
= 0; i
< last_frag
; i
++) {
544 prod
= NEXT_TX(prod
);
545 tx_buf
= &txr
->tx_buf_ring
[prod
];
546 dma_unmap_page(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
547 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
551 dev_kfree_skb_any(skb
);
555 static void bnxt_tx_int(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int nr_pkts
)
557 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
558 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, txr
->txq_index
);
559 u16 cons
= txr
->tx_cons
;
560 struct pci_dev
*pdev
= bp
->pdev
;
562 unsigned int tx_bytes
= 0;
564 for (i
= 0; i
< nr_pkts
; i
++) {
565 struct bnxt_sw_tx_bd
*tx_buf
;
569 tx_buf
= &txr
->tx_buf_ring
[cons
];
570 cons
= NEXT_TX(cons
);
574 if (tx_buf
->is_push
) {
579 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
580 skb_headlen(skb
), PCI_DMA_TODEVICE
);
581 last
= tx_buf
->nr_frags
;
583 for (j
= 0; j
< last
; j
++) {
584 cons
= NEXT_TX(cons
);
585 tx_buf
= &txr
->tx_buf_ring
[cons
];
588 dma_unmap_addr(tx_buf
, mapping
),
589 skb_frag_size(&skb_shinfo(skb
)->frags
[j
]),
594 cons
= NEXT_TX(cons
);
596 tx_bytes
+= skb
->len
;
597 dev_kfree_skb_any(skb
);
600 netdev_tx_completed_queue(txq
, nr_pkts
, tx_bytes
);
603 /* Need to make the tx_cons update visible to bnxt_start_xmit()
604 * before checking for netif_tx_queue_stopped(). Without the
605 * memory barrier, there is a small possibility that bnxt_start_xmit()
606 * will miss it and cause the queue to be stopped forever.
610 if (unlikely(netif_tx_queue_stopped(txq
)) &&
611 (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
612 __netif_tx_lock(txq
, smp_processor_id());
613 if (netif_tx_queue_stopped(txq
) &&
614 bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
&&
615 txr
->dev_state
!= BNXT_DEV_STATE_CLOSING
)
616 netif_tx_wake_queue(txq
);
617 __netif_tx_unlock(txq
);
621 static struct page
*__bnxt_alloc_rx_page(struct bnxt
*bp
, dma_addr_t
*mapping
,
624 struct device
*dev
= &bp
->pdev
->dev
;
627 page
= alloc_page(gfp
);
631 *mapping
= dma_map_page_attrs(dev
, page
, 0, PAGE_SIZE
, bp
->rx_dir
,
632 DMA_ATTR_WEAK_ORDERING
);
633 if (dma_mapping_error(dev
, *mapping
)) {
637 *mapping
+= bp
->rx_dma_offset
;
641 static inline u8
*__bnxt_alloc_rx_data(struct bnxt
*bp
, dma_addr_t
*mapping
,
645 struct pci_dev
*pdev
= bp
->pdev
;
647 data
= kmalloc(bp
->rx_buf_size
, gfp
);
651 *mapping
= dma_map_single_attrs(&pdev
->dev
, data
+ bp
->rx_dma_offset
,
652 bp
->rx_buf_use_size
, bp
->rx_dir
,
653 DMA_ATTR_WEAK_ORDERING
);
655 if (dma_mapping_error(&pdev
->dev
, *mapping
)) {
662 int bnxt_alloc_rx_data(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
665 struct rx_bd
*rxbd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
666 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[prod
];
669 if (BNXT_RX_PAGE_MODE(bp
)) {
670 struct page
*page
= __bnxt_alloc_rx_page(bp
, &mapping
, gfp
);
676 rx_buf
->data_ptr
= page_address(page
) + bp
->rx_offset
;
678 u8
*data
= __bnxt_alloc_rx_data(bp
, &mapping
, gfp
);
684 rx_buf
->data_ptr
= data
+ bp
->rx_offset
;
686 rx_buf
->mapping
= mapping
;
688 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
692 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info
*rxr
, u16 cons
, void *data
)
694 u16 prod
= rxr
->rx_prod
;
695 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
696 struct rx_bd
*cons_bd
, *prod_bd
;
698 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
699 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
701 prod_rx_buf
->data
= data
;
702 prod_rx_buf
->data_ptr
= cons_rx_buf
->data_ptr
;
704 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
706 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
707 cons_bd
= &rxr
->rx_desc_ring
[RX_RING(cons
)][RX_IDX(cons
)];
709 prod_bd
->rx_bd_haddr
= cons_bd
->rx_bd_haddr
;
712 static inline u16
bnxt_find_next_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
714 u16 next
, max
= rxr
->rx_agg_bmap_size
;
716 next
= find_next_zero_bit(rxr
->rx_agg_bmap
, max
, idx
);
718 next
= find_first_zero_bit(rxr
->rx_agg_bmap
, max
);
722 static inline int bnxt_alloc_rx_page(struct bnxt
*bp
,
723 struct bnxt_rx_ring_info
*rxr
,
727 &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
728 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
;
729 struct pci_dev
*pdev
= bp
->pdev
;
732 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
733 unsigned int offset
= 0;
735 if (PAGE_SIZE
> BNXT_RX_PAGE_SIZE
) {
738 page
= alloc_page(gfp
);
742 rxr
->rx_page_offset
= 0;
744 offset
= rxr
->rx_page_offset
;
745 rxr
->rx_page_offset
+= BNXT_RX_PAGE_SIZE
;
746 if (rxr
->rx_page_offset
== PAGE_SIZE
)
751 page
= alloc_page(gfp
);
756 mapping
= dma_map_page_attrs(&pdev
->dev
, page
, offset
,
757 BNXT_RX_PAGE_SIZE
, PCI_DMA_FROMDEVICE
,
758 DMA_ATTR_WEAK_ORDERING
);
759 if (dma_mapping_error(&pdev
->dev
, mapping
)) {
764 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
765 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
767 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
768 rx_agg_buf
= &rxr
->rx_agg_ring
[sw_prod
];
769 rxr
->rx_sw_agg_prod
= NEXT_RX_AGG(sw_prod
);
771 rx_agg_buf
->page
= page
;
772 rx_agg_buf
->offset
= offset
;
773 rx_agg_buf
->mapping
= mapping
;
774 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
775 rxbd
->rx_bd_opaque
= sw_prod
;
779 static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi
*bnapi
, u16 cp_cons
,
782 struct bnxt
*bp
= bnapi
->bp
;
783 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
784 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
785 u16 prod
= rxr
->rx_agg_prod
;
786 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
789 for (i
= 0; i
< agg_bufs
; i
++) {
791 struct rx_agg_cmp
*agg
;
792 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
, *prod_rx_buf
;
793 struct rx_bd
*prod_bd
;
796 agg
= (struct rx_agg_cmp
*)
797 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
798 cons
= agg
->rx_agg_cmp_opaque
;
799 __clear_bit(cons
, rxr
->rx_agg_bmap
);
801 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
802 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
804 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
805 prod_rx_buf
= &rxr
->rx_agg_ring
[sw_prod
];
806 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
808 /* It is possible for sw_prod to be equal to cons, so
809 * set cons_rx_buf->page to NULL first.
811 page
= cons_rx_buf
->page
;
812 cons_rx_buf
->page
= NULL
;
813 prod_rx_buf
->page
= page
;
814 prod_rx_buf
->offset
= cons_rx_buf
->offset
;
816 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
818 prod_bd
= &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
820 prod_bd
->rx_bd_haddr
= cpu_to_le64(cons_rx_buf
->mapping
);
821 prod_bd
->rx_bd_opaque
= sw_prod
;
823 prod
= NEXT_RX_AGG(prod
);
824 sw_prod
= NEXT_RX_AGG(sw_prod
);
825 cp_cons
= NEXT_CMP(cp_cons
);
827 rxr
->rx_agg_prod
= prod
;
828 rxr
->rx_sw_agg_prod
= sw_prod
;
831 static struct sk_buff
*bnxt_rx_page_skb(struct bnxt
*bp
,
832 struct bnxt_rx_ring_info
*rxr
,
833 u16 cons
, void *data
, u8
*data_ptr
,
835 unsigned int offset_and_len
)
837 unsigned int payload
= offset_and_len
>> 16;
838 unsigned int len
= offset_and_len
& 0xffff;
839 struct skb_frag_struct
*frag
;
840 struct page
*page
= data
;
841 u16 prod
= rxr
->rx_prod
;
845 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
847 bnxt_reuse_rx_data(rxr
, cons
, data
);
850 dma_addr
-= bp
->rx_dma_offset
;
851 dma_unmap_page_attrs(&bp
->pdev
->dev
, dma_addr
, PAGE_SIZE
, bp
->rx_dir
,
852 DMA_ATTR_WEAK_ORDERING
);
854 if (unlikely(!payload
))
855 payload
= eth_get_headlen(data_ptr
, len
);
857 skb
= napi_alloc_skb(&rxr
->bnapi
->napi
, payload
);
863 off
= (void *)data_ptr
- page_address(page
);
864 skb_add_rx_frag(skb
, 0, page
, off
, len
, PAGE_SIZE
);
865 memcpy(skb
->data
- NET_IP_ALIGN
, data_ptr
- NET_IP_ALIGN
,
866 payload
+ NET_IP_ALIGN
);
868 frag
= &skb_shinfo(skb
)->frags
[0];
869 skb_frag_size_sub(frag
, payload
);
870 frag
->page_offset
+= payload
;
871 skb
->data_len
-= payload
;
872 skb
->tail
+= payload
;
877 static struct sk_buff
*bnxt_rx_skb(struct bnxt
*bp
,
878 struct bnxt_rx_ring_info
*rxr
, u16 cons
,
879 void *data
, u8
*data_ptr
,
881 unsigned int offset_and_len
)
883 u16 prod
= rxr
->rx_prod
;
887 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
889 bnxt_reuse_rx_data(rxr
, cons
, data
);
893 skb
= build_skb(data
, 0);
894 dma_unmap_single_attrs(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
895 bp
->rx_dir
, DMA_ATTR_WEAK_ORDERING
);
901 skb_reserve(skb
, bp
->rx_offset
);
902 skb_put(skb
, offset_and_len
& 0xffff);
906 static struct sk_buff
*bnxt_rx_pages(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
907 struct sk_buff
*skb
, u16 cp_cons
,
910 struct pci_dev
*pdev
= bp
->pdev
;
911 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
912 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
913 u16 prod
= rxr
->rx_agg_prod
;
916 for (i
= 0; i
< agg_bufs
; i
++) {
918 struct rx_agg_cmp
*agg
;
919 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
;
923 agg
= (struct rx_agg_cmp
*)
924 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
925 cons
= agg
->rx_agg_cmp_opaque
;
926 frag_len
= (le32_to_cpu(agg
->rx_agg_cmp_len_flags_type
) &
927 RX_AGG_CMP_LEN
) >> RX_AGG_CMP_LEN_SHIFT
;
929 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
930 skb_fill_page_desc(skb
, i
, cons_rx_buf
->page
,
931 cons_rx_buf
->offset
, frag_len
);
932 __clear_bit(cons
, rxr
->rx_agg_bmap
);
934 /* It is possible for bnxt_alloc_rx_page() to allocate
935 * a sw_prod index that equals the cons index, so we
936 * need to clear the cons entry now.
938 mapping
= cons_rx_buf
->mapping
;
939 page
= cons_rx_buf
->page
;
940 cons_rx_buf
->page
= NULL
;
942 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_ATOMIC
) != 0) {
943 struct skb_shared_info
*shinfo
;
944 unsigned int nr_frags
;
946 shinfo
= skb_shinfo(skb
);
947 nr_frags
= --shinfo
->nr_frags
;
948 __skb_frag_set_page(&shinfo
->frags
[nr_frags
], NULL
);
952 cons_rx_buf
->page
= page
;
954 /* Update prod since possibly some pages have been
957 rxr
->rx_agg_prod
= prod
;
958 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
- i
);
962 dma_unmap_page_attrs(&pdev
->dev
, mapping
, BNXT_RX_PAGE_SIZE
,
964 DMA_ATTR_WEAK_ORDERING
);
966 skb
->data_len
+= frag_len
;
967 skb
->len
+= frag_len
;
968 skb
->truesize
+= PAGE_SIZE
;
970 prod
= NEXT_RX_AGG(prod
);
971 cp_cons
= NEXT_CMP(cp_cons
);
973 rxr
->rx_agg_prod
= prod
;
977 static int bnxt_agg_bufs_valid(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
978 u8 agg_bufs
, u32
*raw_cons
)
981 struct rx_agg_cmp
*agg
;
983 *raw_cons
= ADV_RAW_CMP(*raw_cons
, agg_bufs
);
984 last
= RING_CMP(*raw_cons
);
985 agg
= (struct rx_agg_cmp
*)
986 &cpr
->cp_desc_ring
[CP_RING(last
)][CP_IDX(last
)];
987 return RX_AGG_CMP_VALID(agg
, *raw_cons
);
990 static inline struct sk_buff
*bnxt_copy_skb(struct bnxt_napi
*bnapi
, u8
*data
,
994 struct bnxt
*bp
= bnapi
->bp
;
995 struct pci_dev
*pdev
= bp
->pdev
;
998 skb
= napi_alloc_skb(&bnapi
->napi
, len
);
1002 dma_sync_single_for_cpu(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1005 memcpy(skb
->data
- NET_IP_ALIGN
, data
- NET_IP_ALIGN
,
1006 len
+ NET_IP_ALIGN
);
1008 dma_sync_single_for_device(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1015 static int bnxt_discard_rx(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1016 u32
*raw_cons
, void *cmp
)
1018 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1019 struct rx_cmp
*rxcmp
= cmp
;
1020 u32 tmp_raw_cons
= *raw_cons
;
1021 u8 cmp_type
, agg_bufs
= 0;
1023 cmp_type
= RX_CMP_TYPE(rxcmp
);
1025 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1026 agg_bufs
= (le32_to_cpu(rxcmp
->rx_cmp_misc_v1
) &
1028 RX_CMP_AGG_BUFS_SHIFT
;
1029 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1030 struct rx_tpa_end_cmp
*tpa_end
= cmp
;
1032 agg_bufs
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1033 RX_TPA_END_CMP_AGG_BUFS
) >>
1034 RX_TPA_END_CMP_AGG_BUFS_SHIFT
;
1038 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1041 *raw_cons
= tmp_raw_cons
;
1045 static void bnxt_queue_sp_work(struct bnxt
*bp
)
1048 queue_work(bnxt_pf_wq
, &bp
->sp_task
);
1050 schedule_work(&bp
->sp_task
);
1053 static void bnxt_cancel_sp_work(struct bnxt
*bp
)
1056 flush_workqueue(bnxt_pf_wq
);
1058 cancel_work_sync(&bp
->sp_task
);
1061 static void bnxt_sched_reset(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
1063 if (!rxr
->bnapi
->in_reset
) {
1064 rxr
->bnapi
->in_reset
= true;
1065 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
1066 bnxt_queue_sp_work(bp
);
1068 rxr
->rx_next_cons
= 0xffff;
1071 static void bnxt_tpa_start(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1072 struct rx_tpa_start_cmp
*tpa_start
,
1073 struct rx_tpa_start_cmp_ext
*tpa_start1
)
1075 u8 agg_id
= TPA_START_AGG_ID(tpa_start
);
1077 struct bnxt_tpa_info
*tpa_info
;
1078 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
1079 struct rx_bd
*prod_bd
;
1082 cons
= tpa_start
->rx_tpa_start_cmp_opaque
;
1083 prod
= rxr
->rx_prod
;
1084 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1085 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
1086 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1088 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1089 bnxt_sched_reset(bp
, rxr
);
1092 /* Store cfa_code in tpa_info to use in tpa_end
1093 * completion processing.
1095 tpa_info
->cfa_code
= TPA_START_CFA_CODE(tpa_start1
);
1096 prod_rx_buf
->data
= tpa_info
->data
;
1097 prod_rx_buf
->data_ptr
= tpa_info
->data_ptr
;
1099 mapping
= tpa_info
->mapping
;
1100 prod_rx_buf
->mapping
= mapping
;
1102 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
1104 prod_bd
->rx_bd_haddr
= cpu_to_le64(mapping
);
1106 tpa_info
->data
= cons_rx_buf
->data
;
1107 tpa_info
->data_ptr
= cons_rx_buf
->data_ptr
;
1108 cons_rx_buf
->data
= NULL
;
1109 tpa_info
->mapping
= cons_rx_buf
->mapping
;
1112 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_len_flags_type
) >>
1113 RX_TPA_START_CMP_LEN_SHIFT
;
1114 if (likely(TPA_START_HASH_VALID(tpa_start
))) {
1115 u32 hash_type
= TPA_START_HASH_TYPE(tpa_start
);
1117 tpa_info
->hash_type
= PKT_HASH_TYPE_L4
;
1118 tpa_info
->gso_type
= SKB_GSO_TCPV4
;
1119 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1120 if (hash_type
== 3 || TPA_START_IS_IPV6(tpa_start1
))
1121 tpa_info
->gso_type
= SKB_GSO_TCPV6
;
1122 tpa_info
->rss_hash
=
1123 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_rss_hash
);
1125 tpa_info
->hash_type
= PKT_HASH_TYPE_NONE
;
1126 tpa_info
->gso_type
= 0;
1127 if (netif_msg_rx_err(bp
))
1128 netdev_warn(bp
->dev
, "TPA packet without valid hash\n");
1130 tpa_info
->flags2
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_flags2
);
1131 tpa_info
->metadata
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_metadata
);
1132 tpa_info
->hdr_info
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_hdr_info
);
1134 rxr
->rx_prod
= NEXT_RX(prod
);
1135 cons
= NEXT_RX(cons
);
1136 rxr
->rx_next_cons
= NEXT_RX(cons
);
1137 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1139 bnxt_reuse_rx_data(rxr
, cons
, cons_rx_buf
->data
);
1140 rxr
->rx_prod
= NEXT_RX(rxr
->rx_prod
);
1141 cons_rx_buf
->data
= NULL
;
1144 static void bnxt_abort_tpa(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1145 u16 cp_cons
, u32 agg_bufs
)
1148 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
);
1151 static struct sk_buff
*bnxt_gro_func_5731x(struct bnxt_tpa_info
*tpa_info
,
1152 int payload_off
, int tcp_ts
,
1153 struct sk_buff
*skb
)
1158 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1159 u32 hdr_info
= tpa_info
->hdr_info
;
1160 bool loopback
= false;
1162 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1163 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1164 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1166 /* If the packet is an internal loopback packet, the offsets will
1167 * have an extra 4 bytes.
1169 if (inner_mac_off
== 4) {
1171 } else if (inner_mac_off
> 4) {
1172 __be16 proto
= *((__be16
*)(skb
->data
+ inner_ip_off
-
1175 /* We only support inner iPv4/ipv6. If we don't see the
1176 * correct protocol ID, it must be a loopback packet where
1177 * the offsets are off by 4.
1179 if (proto
!= htons(ETH_P_IP
) && proto
!= htons(ETH_P_IPV6
))
1183 /* internal loopback packet, subtract all offsets by 4 */
1189 nw_off
= inner_ip_off
- ETH_HLEN
;
1190 skb_set_network_header(skb
, nw_off
);
1191 if (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) {
1192 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
1194 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1195 len
= skb
->len
- skb_transport_offset(skb
);
1197 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1199 struct iphdr
*iph
= ip_hdr(skb
);
1201 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1202 len
= skb
->len
- skb_transport_offset(skb
);
1204 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1207 if (inner_mac_off
) { /* tunnel */
1208 struct udphdr
*uh
= NULL
;
1209 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1212 if (proto
== htons(ETH_P_IP
)) {
1213 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1215 if (iph
->protocol
== IPPROTO_UDP
)
1216 uh
= (struct udphdr
*)(iph
+ 1);
1218 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1220 if (iph
->nexthdr
== IPPROTO_UDP
)
1221 uh
= (struct udphdr
*)(iph
+ 1);
1225 skb_shinfo(skb
)->gso_type
|=
1226 SKB_GSO_UDP_TUNNEL_CSUM
;
1228 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1235 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1236 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1238 static struct sk_buff
*bnxt_gro_func_5730x(struct bnxt_tpa_info
*tpa_info
,
1239 int payload_off
, int tcp_ts
,
1240 struct sk_buff
*skb
)
1244 int len
, nw_off
, tcp_opt_len
= 0;
1249 if (tpa_info
->gso_type
== SKB_GSO_TCPV4
) {
1252 nw_off
= payload_off
- BNXT_IPV4_HDR_SIZE
- tcp_opt_len
-
1254 skb_set_network_header(skb
, nw_off
);
1256 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1257 len
= skb
->len
- skb_transport_offset(skb
);
1259 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1260 } else if (tpa_info
->gso_type
== SKB_GSO_TCPV6
) {
1261 struct ipv6hdr
*iph
;
1263 nw_off
= payload_off
- BNXT_IPV6_HDR_SIZE
- tcp_opt_len
-
1265 skb_set_network_header(skb
, nw_off
);
1266 iph
= ipv6_hdr(skb
);
1267 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1268 len
= skb
->len
- skb_transport_offset(skb
);
1270 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1272 dev_kfree_skb_any(skb
);
1276 if (nw_off
) { /* tunnel */
1277 struct udphdr
*uh
= NULL
;
1279 if (skb
->protocol
== htons(ETH_P_IP
)) {
1280 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1282 if (iph
->protocol
== IPPROTO_UDP
)
1283 uh
= (struct udphdr
*)(iph
+ 1);
1285 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1287 if (iph
->nexthdr
== IPPROTO_UDP
)
1288 uh
= (struct udphdr
*)(iph
+ 1);
1292 skb_shinfo(skb
)->gso_type
|=
1293 SKB_GSO_UDP_TUNNEL_CSUM
;
1295 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1302 static inline struct sk_buff
*bnxt_gro_skb(struct bnxt
*bp
,
1303 struct bnxt_tpa_info
*tpa_info
,
1304 struct rx_tpa_end_cmp
*tpa_end
,
1305 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1306 struct sk_buff
*skb
)
1312 segs
= TPA_END_TPA_SEGS(tpa_end
);
1316 NAPI_GRO_CB(skb
)->count
= segs
;
1317 skb_shinfo(skb
)->gso_size
=
1318 le32_to_cpu(tpa_end1
->rx_tpa_end_cmp_seg_len
);
1319 skb_shinfo(skb
)->gso_type
= tpa_info
->gso_type
;
1320 payload_off
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1321 RX_TPA_END_CMP_PAYLOAD_OFFSET
) >>
1322 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT
;
1323 skb
= bp
->gro_func(tpa_info
, payload_off
, TPA_END_GRO_TS(tpa_end
), skb
);
1325 tcp_gro_complete(skb
);
1330 /* Given the cfa_code of a received packet determine which
1331 * netdev (vf-rep or PF) the packet is destined to.
1333 static struct net_device
*bnxt_get_pkt_dev(struct bnxt
*bp
, u16 cfa_code
)
1335 struct net_device
*dev
= bnxt_get_vf_rep(bp
, cfa_code
);
1337 /* if vf-rep dev is NULL, the must belongs to the PF */
1338 return dev
? dev
: bp
->dev
;
1341 static inline struct sk_buff
*bnxt_tpa_end(struct bnxt
*bp
,
1342 struct bnxt_napi
*bnapi
,
1344 struct rx_tpa_end_cmp
*tpa_end
,
1345 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1348 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1349 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1350 u8 agg_id
= TPA_END_AGG_ID(tpa_end
);
1351 u8
*data_ptr
, agg_bufs
;
1352 u16 cp_cons
= RING_CMP(*raw_cons
);
1354 struct bnxt_tpa_info
*tpa_info
;
1356 struct sk_buff
*skb
;
1359 if (unlikely(bnapi
->in_reset
)) {
1360 int rc
= bnxt_discard_rx(bp
, bnapi
, raw_cons
, tpa_end
);
1363 return ERR_PTR(-EBUSY
);
1367 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1368 data
= tpa_info
->data
;
1369 data_ptr
= tpa_info
->data_ptr
;
1371 len
= tpa_info
->len
;
1372 mapping
= tpa_info
->mapping
;
1374 agg_bufs
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1375 RX_TPA_END_CMP_AGG_BUFS
) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT
;
1378 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, raw_cons
))
1379 return ERR_PTR(-EBUSY
);
1381 *event
|= BNXT_AGG_EVENT
;
1382 cp_cons
= NEXT_CMP(cp_cons
);
1385 if (unlikely(agg_bufs
> MAX_SKB_FRAGS
|| TPA_END_ERRORS(tpa_end1
))) {
1386 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1387 if (agg_bufs
> MAX_SKB_FRAGS
)
1388 netdev_warn(bp
->dev
, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1389 agg_bufs
, (int)MAX_SKB_FRAGS
);
1393 if (len
<= bp
->rx_copy_thresh
) {
1394 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, mapping
);
1396 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1401 dma_addr_t new_mapping
;
1403 new_data
= __bnxt_alloc_rx_data(bp
, &new_mapping
, GFP_ATOMIC
);
1405 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1409 tpa_info
->data
= new_data
;
1410 tpa_info
->data_ptr
= new_data
+ bp
->rx_offset
;
1411 tpa_info
->mapping
= new_mapping
;
1413 skb
= build_skb(data
, 0);
1414 dma_unmap_single_attrs(&bp
->pdev
->dev
, mapping
,
1415 bp
->rx_buf_use_size
, bp
->rx_dir
,
1416 DMA_ATTR_WEAK_ORDERING
);
1420 bnxt_abort_tpa(bp
, bnapi
, cp_cons
, agg_bufs
);
1423 skb_reserve(skb
, bp
->rx_offset
);
1428 skb
= bnxt_rx_pages(bp
, bnapi
, skb
, cp_cons
, agg_bufs
);
1430 /* Page reuse already handled by bnxt_rx_pages(). */
1436 eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, tpa_info
->cfa_code
));
1438 if (tpa_info
->hash_type
!= PKT_HASH_TYPE_NONE
)
1439 skb_set_hash(skb
, tpa_info
->rss_hash
, tpa_info
->hash_type
);
1441 if ((tpa_info
->flags2
& RX_CMP_FLAGS2_META_FORMAT_VLAN
) &&
1442 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1443 u16 vlan_proto
= tpa_info
->metadata
>>
1444 RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1445 u16 vtag
= tpa_info
->metadata
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1447 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1450 skb_checksum_none_assert(skb
);
1451 if (likely(tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_L4_CS_CALC
)) {
1452 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1454 (tpa_info
->flags2
& RX_CMP_FLAGS2_T_L4_CS_CALC
) >> 3;
1457 if (TPA_END_GRO(tpa_end
))
1458 skb
= bnxt_gro_skb(bp
, tpa_info
, tpa_end
, tpa_end1
, skb
);
1463 static void bnxt_deliver_skb(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1464 struct sk_buff
*skb
)
1466 if (skb
->dev
!= bp
->dev
) {
1467 /* this packet belongs to a vf-rep */
1468 bnxt_vf_rep_rx(bp
, skb
);
1471 skb_record_rx_queue(skb
, bnapi
->index
);
1472 napi_gro_receive(&bnapi
->napi
, skb
);
1475 /* returns the following:
1476 * 1 - 1 packet successfully received
1477 * 0 - successful TPA_START, packet not completed yet
1478 * -EBUSY - completion ring does not have all the agg buffers yet
1479 * -ENOMEM - packet aborted due to out of memory
1480 * -EIO - packet aborted due to hw error indicated in BD
1482 static int bnxt_rx_pkt(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, u32
*raw_cons
,
1485 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1486 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1487 struct net_device
*dev
= bp
->dev
;
1488 struct rx_cmp
*rxcmp
;
1489 struct rx_cmp_ext
*rxcmp1
;
1490 u32 tmp_raw_cons
= *raw_cons
;
1491 u16 cfa_code
, cons
, prod
, cp_cons
= RING_CMP(tmp_raw_cons
);
1492 struct bnxt_sw_rx_bd
*rx_buf
;
1494 u8
*data_ptr
, agg_bufs
, cmp_type
;
1495 dma_addr_t dma_addr
;
1496 struct sk_buff
*skb
;
1501 rxcmp
= (struct rx_cmp
*)
1502 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1504 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1505 cp_cons
= RING_CMP(tmp_raw_cons
);
1506 rxcmp1
= (struct rx_cmp_ext
*)
1507 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1509 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1512 cmp_type
= RX_CMP_TYPE(rxcmp
);
1514 prod
= rxr
->rx_prod
;
1516 if (cmp_type
== CMP_TYPE_RX_L2_TPA_START_CMP
) {
1517 bnxt_tpa_start(bp
, rxr
, (struct rx_tpa_start_cmp
*)rxcmp
,
1518 (struct rx_tpa_start_cmp_ext
*)rxcmp1
);
1520 *event
|= BNXT_RX_EVENT
;
1521 goto next_rx_no_prod_no_len
;
1523 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1524 skb
= bnxt_tpa_end(bp
, bnapi
, &tmp_raw_cons
,
1525 (struct rx_tpa_end_cmp
*)rxcmp
,
1526 (struct rx_tpa_end_cmp_ext
*)rxcmp1
, event
);
1533 bnxt_deliver_skb(bp
, bnapi
, skb
);
1536 *event
|= BNXT_RX_EVENT
;
1537 goto next_rx_no_prod_no_len
;
1540 cons
= rxcmp
->rx_cmp_opaque
;
1541 rx_buf
= &rxr
->rx_buf_ring
[cons
];
1542 data
= rx_buf
->data
;
1543 data_ptr
= rx_buf
->data_ptr
;
1544 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1545 int rc1
= bnxt_discard_rx(bp
, bnapi
, raw_cons
, rxcmp
);
1547 bnxt_sched_reset(bp
, rxr
);
1552 misc
= le32_to_cpu(rxcmp
->rx_cmp_misc_v1
);
1553 agg_bufs
= (misc
& RX_CMP_AGG_BUFS
) >> RX_CMP_AGG_BUFS_SHIFT
;
1556 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1559 cp_cons
= NEXT_CMP(cp_cons
);
1560 *event
|= BNXT_AGG_EVENT
;
1562 *event
|= BNXT_RX_EVENT
;
1564 rx_buf
->data
= NULL
;
1565 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L2_ERRORS
) {
1566 bnxt_reuse_rx_data(rxr
, cons
, data
);
1568 bnxt_reuse_rx_agg_bufs(bnapi
, cp_cons
, agg_bufs
);
1574 len
= le32_to_cpu(rxcmp
->rx_cmp_len_flags_type
) >> RX_CMP_LEN_SHIFT
;
1575 dma_addr
= rx_buf
->mapping
;
1577 if (bnxt_rx_xdp(bp
, rxr
, cons
, data
, &data_ptr
, &len
, event
)) {
1582 if (len
<= bp
->rx_copy_thresh
) {
1583 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, dma_addr
);
1584 bnxt_reuse_rx_data(rxr
, cons
, data
);
1592 if (rx_buf
->data_ptr
== data_ptr
)
1593 payload
= misc
& RX_CMP_PAYLOAD_OFFSET
;
1596 skb
= bp
->rx_skb_func(bp
, rxr
, cons
, data
, data_ptr
, dma_addr
,
1605 skb
= bnxt_rx_pages(bp
, bnapi
, skb
, cp_cons
, agg_bufs
);
1612 if (RX_CMP_HASH_VALID(rxcmp
)) {
1613 u32 hash_type
= RX_CMP_HASH_TYPE(rxcmp
);
1614 enum pkt_hash_types type
= PKT_HASH_TYPE_L4
;
1616 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1617 if (hash_type
!= 1 && hash_type
!= 3)
1618 type
= PKT_HASH_TYPE_L3
;
1619 skb_set_hash(skb
, le32_to_cpu(rxcmp
->rx_cmp_rss_hash
), type
);
1622 cfa_code
= RX_CMP_CFA_CODE(rxcmp1
);
1623 skb
->protocol
= eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, cfa_code
));
1625 if ((rxcmp1
->rx_cmp_flags2
&
1626 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN
)) &&
1627 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1628 u32 meta_data
= le32_to_cpu(rxcmp1
->rx_cmp_meta_data
);
1629 u16 vtag
= meta_data
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1630 u16 vlan_proto
= meta_data
>> RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1632 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1635 skb_checksum_none_assert(skb
);
1636 if (RX_CMP_L4_CS_OK(rxcmp1
)) {
1637 if (dev
->features
& NETIF_F_RXCSUM
) {
1638 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1639 skb
->csum_level
= RX_CMP_ENCAP(rxcmp1
);
1642 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L4_CS_ERR_BITS
) {
1643 if (dev
->features
& NETIF_F_RXCSUM
)
1644 cpr
->rx_l4_csum_errors
++;
1648 bnxt_deliver_skb(bp
, bnapi
, skb
);
1652 rxr
->rx_prod
= NEXT_RX(prod
);
1653 rxr
->rx_next_cons
= NEXT_RX(cons
);
1655 cpr
->rx_packets
+= 1;
1656 cpr
->rx_bytes
+= len
;
1658 next_rx_no_prod_no_len
:
1659 *raw_cons
= tmp_raw_cons
;
1664 /* In netpoll mode, if we are using a combined completion ring, we need to
1665 * discard the rx packets and recycle the buffers.
1667 static int bnxt_force_rx_discard(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1668 u32
*raw_cons
, u8
*event
)
1670 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1671 u32 tmp_raw_cons
= *raw_cons
;
1672 struct rx_cmp_ext
*rxcmp1
;
1673 struct rx_cmp
*rxcmp
;
1677 cp_cons
= RING_CMP(tmp_raw_cons
);
1678 rxcmp
= (struct rx_cmp
*)
1679 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1681 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1682 cp_cons
= RING_CMP(tmp_raw_cons
);
1683 rxcmp1
= (struct rx_cmp_ext
*)
1684 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1686 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1689 cmp_type
= RX_CMP_TYPE(rxcmp
);
1690 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1691 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
1692 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
1693 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1694 struct rx_tpa_end_cmp_ext
*tpa_end1
;
1696 tpa_end1
= (struct rx_tpa_end_cmp_ext
*)rxcmp1
;
1697 tpa_end1
->rx_tpa_end_cmp_errors_v2
|=
1698 cpu_to_le32(RX_TPA_END_CMP_ERRORS
);
1700 return bnxt_rx_pkt(bp
, bnapi
, raw_cons
, event
);
1703 #define BNXT_GET_EVENT_PORT(data) \
1705 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
1707 static int bnxt_async_event_process(struct bnxt
*bp
,
1708 struct hwrm_async_event_cmpl
*cmpl
)
1710 u16 event_id
= le16_to_cpu(cmpl
->event_id
);
1712 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1714 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
: {
1715 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1716 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1719 goto async_event_process_exit
;
1721 /* print unsupported speed warning in forced speed mode only */
1722 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
) &&
1723 (data1
& 0x20000)) {
1724 u16 fw_speed
= link_info
->force_link_speed
;
1725 u32 speed
= bnxt_fw_to_ethtool_speed(fw_speed
);
1727 if (speed
!= SPEED_UNKNOWN
)
1728 netdev_warn(bp
->dev
, "Link speed %d no longer supported\n",
1731 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
, &bp
->sp_event
);
1734 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
:
1735 set_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
);
1737 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
:
1738 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
);
1740 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
: {
1741 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1742 u16 port_id
= BNXT_GET_EVENT_PORT(data1
);
1747 if (bp
->pf
.port_id
!= port_id
)
1750 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
);
1753 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
:
1755 goto async_event_process_exit
;
1756 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
);
1759 goto async_event_process_exit
;
1761 bnxt_queue_sp_work(bp
);
1762 async_event_process_exit
:
1763 bnxt_ulp_async_events(bp
, cmpl
);
1767 static int bnxt_hwrm_handler(struct bnxt
*bp
, struct tx_cmp
*txcmp
)
1769 u16 cmpl_type
= TX_CMP_TYPE(txcmp
), vf_id
, seq_id
;
1770 struct hwrm_cmpl
*h_cmpl
= (struct hwrm_cmpl
*)txcmp
;
1771 struct hwrm_fwd_req_cmpl
*fwd_req_cmpl
=
1772 (struct hwrm_fwd_req_cmpl
*)txcmp
;
1774 switch (cmpl_type
) {
1775 case CMPL_BASE_TYPE_HWRM_DONE
:
1776 seq_id
= le16_to_cpu(h_cmpl
->sequence_id
);
1777 if (seq_id
== bp
->hwrm_intr_seq_id
)
1778 bp
->hwrm_intr_seq_id
= HWRM_SEQ_ID_INVALID
;
1780 netdev_err(bp
->dev
, "Invalid hwrm seq id %d\n", seq_id
);
1783 case CMPL_BASE_TYPE_HWRM_FWD_REQ
:
1784 vf_id
= le16_to_cpu(fwd_req_cmpl
->source_id
);
1786 if ((vf_id
< bp
->pf
.first_vf_id
) ||
1787 (vf_id
>= bp
->pf
.first_vf_id
+ bp
->pf
.active_vfs
)) {
1788 netdev_err(bp
->dev
, "Msg contains invalid VF id %x\n",
1793 set_bit(vf_id
- bp
->pf
.first_vf_id
, bp
->pf
.vf_event_bmap
);
1794 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
);
1795 bnxt_queue_sp_work(bp
);
1798 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
:
1799 bnxt_async_event_process(bp
,
1800 (struct hwrm_async_event_cmpl
*)txcmp
);
1809 static irqreturn_t
bnxt_msix(int irq
, void *dev_instance
)
1811 struct bnxt_napi
*bnapi
= dev_instance
;
1812 struct bnxt
*bp
= bnapi
->bp
;
1813 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1814 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1817 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1818 napi_schedule(&bnapi
->napi
);
1822 static inline int bnxt_has_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
)
1824 u32 raw_cons
= cpr
->cp_raw_cons
;
1825 u16 cons
= RING_CMP(raw_cons
);
1826 struct tx_cmp
*txcmp
;
1828 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1830 return TX_CMP_VALID(txcmp
, raw_cons
);
1833 static irqreturn_t
bnxt_inta(int irq
, void *dev_instance
)
1835 struct bnxt_napi
*bnapi
= dev_instance
;
1836 struct bnxt
*bp
= bnapi
->bp
;
1837 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1838 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1841 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1843 if (!bnxt_has_work(bp
, cpr
)) {
1844 int_status
= readl(bp
->bar0
+ BNXT_CAG_REG_LEGACY_INT_STATUS
);
1845 /* return if erroneous interrupt */
1846 if (!(int_status
& (0x10000 << cpr
->cp_ring_struct
.fw_ring_id
)))
1850 /* disable ring IRQ */
1851 BNXT_CP_DB_IRQ_DIS(cpr
->cp_doorbell
);
1853 /* Return here if interrupt is shared and is disabled. */
1854 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
1857 napi_schedule(&bnapi
->napi
);
1861 static int bnxt_poll_work(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int budget
)
1863 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1864 u32 raw_cons
= cpr
->cp_raw_cons
;
1869 struct tx_cmp
*txcmp
;
1874 cons
= RING_CMP(raw_cons
);
1875 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1877 if (!TX_CMP_VALID(txcmp
, raw_cons
))
1880 /* The valid test of the entry must be done first before
1881 * reading any further.
1884 if (TX_CMP_TYPE(txcmp
) == CMP_TYPE_TX_L2_CMP
) {
1886 /* return full budget so NAPI will complete. */
1887 if (unlikely(tx_pkts
> bp
->tx_wake_thresh
)) {
1889 raw_cons
= NEXT_RAW_CMP(raw_cons
);
1892 } else if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
1894 rc
= bnxt_rx_pkt(bp
, bnapi
, &raw_cons
, &event
);
1896 rc
= bnxt_force_rx_discard(bp
, bnapi
, &raw_cons
,
1898 if (likely(rc
>= 0))
1900 /* Increment rx_pkts when rc is -ENOMEM to count towards
1901 * the NAPI budget. Otherwise, we may potentially loop
1902 * here forever if we consistently cannot allocate
1905 else if (rc
== -ENOMEM
&& budget
)
1907 else if (rc
== -EBUSY
) /* partial completion */
1909 } else if (unlikely((TX_CMP_TYPE(txcmp
) ==
1910 CMPL_BASE_TYPE_HWRM_DONE
) ||
1911 (TX_CMP_TYPE(txcmp
) ==
1912 CMPL_BASE_TYPE_HWRM_FWD_REQ
) ||
1913 (TX_CMP_TYPE(txcmp
) ==
1914 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
))) {
1915 bnxt_hwrm_handler(bp
, txcmp
);
1917 raw_cons
= NEXT_RAW_CMP(raw_cons
);
1919 if (rx_pkts
&& rx_pkts
== budget
)
1923 if (event
& BNXT_TX_EVENT
) {
1924 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
1925 void __iomem
*db
= txr
->tx_doorbell
;
1926 u16 prod
= txr
->tx_prod
;
1928 /* Sync BD data before updating doorbell */
1931 bnxt_db_write_relaxed(bp
, db
, DB_KEY_TX
| prod
);
1934 cpr
->cp_raw_cons
= raw_cons
;
1935 /* ACK completion ring before freeing tx ring and producing new
1936 * buffers in rx/agg rings to prevent overflowing the completion
1939 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
1942 bnapi
->tx_int(bp
, bnapi
, tx_pkts
);
1944 if (event
& BNXT_RX_EVENT
) {
1945 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1947 bnxt_db_write(bp
, rxr
->rx_doorbell
, DB_KEY_RX
| rxr
->rx_prod
);
1948 if (event
& BNXT_AGG_EVENT
)
1949 bnxt_db_write(bp
, rxr
->rx_agg_doorbell
,
1950 DB_KEY_RX
| rxr
->rx_agg_prod
);
1955 static int bnxt_poll_nitroa0(struct napi_struct
*napi
, int budget
)
1957 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
1958 struct bnxt
*bp
= bnapi
->bp
;
1959 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1960 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1961 struct tx_cmp
*txcmp
;
1962 struct rx_cmp_ext
*rxcmp1
;
1963 u32 cp_cons
, tmp_raw_cons
;
1964 u32 raw_cons
= cpr
->cp_raw_cons
;
1971 cp_cons
= RING_CMP(raw_cons
);
1972 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1974 if (!TX_CMP_VALID(txcmp
, raw_cons
))
1977 if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
1978 tmp_raw_cons
= NEXT_RAW_CMP(raw_cons
);
1979 cp_cons
= RING_CMP(tmp_raw_cons
);
1980 rxcmp1
= (struct rx_cmp_ext
*)
1981 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1983 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1986 /* force an error to recycle the buffer */
1987 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
1988 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
1990 rc
= bnxt_rx_pkt(bp
, bnapi
, &raw_cons
, &event
);
1991 if (likely(rc
== -EIO
) && budget
)
1993 else if (rc
== -EBUSY
) /* partial completion */
1995 } else if (unlikely(TX_CMP_TYPE(txcmp
) ==
1996 CMPL_BASE_TYPE_HWRM_DONE
)) {
1997 bnxt_hwrm_handler(bp
, txcmp
);
2000 "Invalid completion received on special ring\n");
2002 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2004 if (rx_pkts
== budget
)
2008 cpr
->cp_raw_cons
= raw_cons
;
2009 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
2010 bnxt_db_write(bp
, rxr
->rx_doorbell
, DB_KEY_RX
| rxr
->rx_prod
);
2012 if (event
& BNXT_AGG_EVENT
)
2013 bnxt_db_write(bp
, rxr
->rx_agg_doorbell
,
2014 DB_KEY_RX
| rxr
->rx_agg_prod
);
2016 if (!bnxt_has_work(bp
, cpr
) && rx_pkts
< budget
) {
2017 napi_complete_done(napi
, rx_pkts
);
2018 BNXT_CP_DB_REARM(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
2023 static int bnxt_poll(struct napi_struct
*napi
, int budget
)
2025 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2026 struct bnxt
*bp
= bnapi
->bp
;
2027 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2031 work_done
+= bnxt_poll_work(bp
, bnapi
, budget
- work_done
);
2033 if (work_done
>= budget
) {
2035 BNXT_CP_DB_REARM(cpr
->cp_doorbell
,
2040 if (!bnxt_has_work(bp
, cpr
)) {
2041 if (napi_complete_done(napi
, work_done
))
2042 BNXT_CP_DB_REARM(cpr
->cp_doorbell
,
2047 if (bp
->flags
& BNXT_FLAG_DIM
) {
2048 struct net_dim_sample dim_sample
;
2050 net_dim_sample(cpr
->event_ctr
,
2054 net_dim(&cpr
->dim
, dim_sample
);
2060 static void bnxt_free_tx_skbs(struct bnxt
*bp
)
2063 struct pci_dev
*pdev
= bp
->pdev
;
2068 max_idx
= bp
->tx_nr_pages
* TX_DESC_CNT
;
2069 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2070 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2073 for (j
= 0; j
< max_idx
;) {
2074 struct bnxt_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
2075 struct sk_buff
*skb
= tx_buf
->skb
;
2085 if (tx_buf
->is_push
) {
2091 dma_unmap_single(&pdev
->dev
,
2092 dma_unmap_addr(tx_buf
, mapping
),
2096 last
= tx_buf
->nr_frags
;
2098 for (k
= 0; k
< last
; k
++, j
++) {
2099 int ring_idx
= j
& bp
->tx_ring_mask
;
2100 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[k
];
2102 tx_buf
= &txr
->tx_buf_ring
[ring_idx
];
2105 dma_unmap_addr(tx_buf
, mapping
),
2106 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
2110 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
2114 static void bnxt_free_rx_skbs(struct bnxt
*bp
)
2116 int i
, max_idx
, max_agg_idx
;
2117 struct pci_dev
*pdev
= bp
->pdev
;
2122 max_idx
= bp
->rx_nr_pages
* RX_DESC_CNT
;
2123 max_agg_idx
= bp
->rx_agg_nr_pages
* RX_DESC_CNT
;
2124 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2125 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2129 for (j
= 0; j
< MAX_TPA
; j
++) {
2130 struct bnxt_tpa_info
*tpa_info
=
2132 u8
*data
= tpa_info
->data
;
2137 dma_unmap_single_attrs(&pdev
->dev
,
2139 bp
->rx_buf_use_size
,
2141 DMA_ATTR_WEAK_ORDERING
);
2143 tpa_info
->data
= NULL
;
2149 for (j
= 0; j
< max_idx
; j
++) {
2150 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[j
];
2151 dma_addr_t mapping
= rx_buf
->mapping
;
2152 void *data
= rx_buf
->data
;
2157 rx_buf
->data
= NULL
;
2159 if (BNXT_RX_PAGE_MODE(bp
)) {
2160 mapping
-= bp
->rx_dma_offset
;
2161 dma_unmap_page_attrs(&pdev
->dev
, mapping
,
2162 PAGE_SIZE
, bp
->rx_dir
,
2163 DMA_ATTR_WEAK_ORDERING
);
2166 dma_unmap_single_attrs(&pdev
->dev
, mapping
,
2167 bp
->rx_buf_use_size
,
2169 DMA_ATTR_WEAK_ORDERING
);
2174 for (j
= 0; j
< max_agg_idx
; j
++) {
2175 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
=
2176 &rxr
->rx_agg_ring
[j
];
2177 struct page
*page
= rx_agg_buf
->page
;
2182 dma_unmap_page_attrs(&pdev
->dev
, rx_agg_buf
->mapping
,
2185 DMA_ATTR_WEAK_ORDERING
);
2187 rx_agg_buf
->page
= NULL
;
2188 __clear_bit(j
, rxr
->rx_agg_bmap
);
2193 __free_page(rxr
->rx_page
);
2194 rxr
->rx_page
= NULL
;
2199 static void bnxt_free_skbs(struct bnxt
*bp
)
2201 bnxt_free_tx_skbs(bp
);
2202 bnxt_free_rx_skbs(bp
);
2205 static void bnxt_free_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2207 struct pci_dev
*pdev
= bp
->pdev
;
2210 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2211 if (!rmem
->pg_arr
[i
])
2214 dma_free_coherent(&pdev
->dev
, rmem
->page_size
,
2215 rmem
->pg_arr
[i
], rmem
->dma_arr
[i
]);
2217 rmem
->pg_arr
[i
] = NULL
;
2220 dma_free_coherent(&pdev
->dev
, rmem
->nr_pages
* 8,
2221 rmem
->pg_tbl
, rmem
->pg_tbl_map
);
2222 rmem
->pg_tbl
= NULL
;
2224 if (rmem
->vmem_size
&& *rmem
->vmem
) {
2230 static int bnxt_alloc_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2232 struct pci_dev
*pdev
= bp
->pdev
;
2236 if (rmem
->flags
& (BNXT_RMEM_VALID_PTE_FLAG
| BNXT_RMEM_RING_PTE_FLAG
))
2237 valid_bit
= PTU_PTE_VALID
;
2238 if (rmem
->nr_pages
> 1) {
2239 rmem
->pg_tbl
= dma_alloc_coherent(&pdev
->dev
,
2247 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2248 u64 extra_bits
= valid_bit
;
2250 rmem
->pg_arr
[i
] = dma_alloc_coherent(&pdev
->dev
,
2254 if (!rmem
->pg_arr
[i
])
2257 if (rmem
->nr_pages
> 1) {
2258 if (i
== rmem
->nr_pages
- 2 &&
2259 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2260 extra_bits
|= PTU_PTE_NEXT_TO_LAST
;
2261 else if (i
== rmem
->nr_pages
- 1 &&
2262 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2263 extra_bits
|= PTU_PTE_LAST
;
2265 cpu_to_le64(rmem
->dma_arr
[i
] | extra_bits
);
2269 if (rmem
->vmem_size
) {
2270 *rmem
->vmem
= vzalloc(rmem
->vmem_size
);
2277 static void bnxt_free_rx_rings(struct bnxt
*bp
)
2284 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2285 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2286 struct bnxt_ring_struct
*ring
;
2289 bpf_prog_put(rxr
->xdp_prog
);
2291 if (xdp_rxq_info_is_reg(&rxr
->xdp_rxq
))
2292 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
2297 kfree(rxr
->rx_agg_bmap
);
2298 rxr
->rx_agg_bmap
= NULL
;
2300 ring
= &rxr
->rx_ring_struct
;
2301 bnxt_free_ring(bp
, &ring
->ring_mem
);
2303 ring
= &rxr
->rx_agg_ring_struct
;
2304 bnxt_free_ring(bp
, &ring
->ring_mem
);
2308 static int bnxt_alloc_rx_rings(struct bnxt
*bp
)
2310 int i
, rc
, agg_rings
= 0, tpa_rings
= 0;
2315 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
2318 if (bp
->flags
& BNXT_FLAG_TPA
)
2321 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2322 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2323 struct bnxt_ring_struct
*ring
;
2325 ring
= &rxr
->rx_ring_struct
;
2327 rc
= xdp_rxq_info_reg(&rxr
->xdp_rxq
, bp
->dev
, i
);
2331 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2338 ring
= &rxr
->rx_agg_ring_struct
;
2339 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2344 rxr
->rx_agg_bmap_size
= bp
->rx_agg_ring_mask
+ 1;
2345 mem_size
= rxr
->rx_agg_bmap_size
/ 8;
2346 rxr
->rx_agg_bmap
= kzalloc(mem_size
, GFP_KERNEL
);
2347 if (!rxr
->rx_agg_bmap
)
2351 rxr
->rx_tpa
= kcalloc(MAX_TPA
,
2352 sizeof(struct bnxt_tpa_info
),
2362 static void bnxt_free_tx_rings(struct bnxt
*bp
)
2365 struct pci_dev
*pdev
= bp
->pdev
;
2370 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2371 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2372 struct bnxt_ring_struct
*ring
;
2375 dma_free_coherent(&pdev
->dev
, bp
->tx_push_size
,
2376 txr
->tx_push
, txr
->tx_push_mapping
);
2377 txr
->tx_push
= NULL
;
2380 ring
= &txr
->tx_ring_struct
;
2382 bnxt_free_ring(bp
, &ring
->ring_mem
);
2386 static int bnxt_alloc_tx_rings(struct bnxt
*bp
)
2389 struct pci_dev
*pdev
= bp
->pdev
;
2391 bp
->tx_push_size
= 0;
2392 if (bp
->tx_push_thresh
) {
2395 push_size
= L1_CACHE_ALIGN(sizeof(struct tx_push_bd
) +
2396 bp
->tx_push_thresh
);
2398 if (push_size
> 256) {
2400 bp
->tx_push_thresh
= 0;
2403 bp
->tx_push_size
= push_size
;
2406 for (i
= 0, j
= 0; i
< bp
->tx_nr_rings
; i
++) {
2407 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2408 struct bnxt_ring_struct
*ring
;
2411 ring
= &txr
->tx_ring_struct
;
2413 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2417 ring
->grp_idx
= txr
->bnapi
->index
;
2418 if (bp
->tx_push_size
) {
2421 /* One pre-allocated DMA buffer to backup
2424 txr
->tx_push
= dma_alloc_coherent(&pdev
->dev
,
2426 &txr
->tx_push_mapping
,
2432 mapping
= txr
->tx_push_mapping
+
2433 sizeof(struct tx_push_bd
);
2434 txr
->data_mapping
= cpu_to_le64(mapping
);
2436 memset(txr
->tx_push
, 0, sizeof(struct tx_push_bd
));
2438 qidx
= bp
->tc_to_qidx
[j
];
2439 ring
->queue_id
= bp
->q_info
[qidx
].queue_id
;
2440 if (i
< bp
->tx_nr_rings_xdp
)
2442 if (i
% bp
->tx_nr_rings_per_tc
== (bp
->tx_nr_rings_per_tc
- 1))
2448 static void bnxt_free_cp_rings(struct bnxt
*bp
)
2455 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2456 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2457 struct bnxt_cp_ring_info
*cpr
;
2458 struct bnxt_ring_struct
*ring
;
2463 cpr
= &bnapi
->cp_ring
;
2464 ring
= &cpr
->cp_ring_struct
;
2466 bnxt_free_ring(bp
, &ring
->ring_mem
);
2470 static int bnxt_alloc_cp_rings(struct bnxt
*bp
)
2472 int i
, rc
, ulp_base_vec
, ulp_msix
;
2474 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
2475 ulp_base_vec
= bnxt_get_ulp_msix_base(bp
);
2476 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2477 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2478 struct bnxt_cp_ring_info
*cpr
;
2479 struct bnxt_ring_struct
*ring
;
2484 cpr
= &bnapi
->cp_ring
;
2485 ring
= &cpr
->cp_ring_struct
;
2487 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2491 if (ulp_msix
&& i
>= ulp_base_vec
)
2492 ring
->map_idx
= i
+ ulp_msix
;
2499 static void bnxt_init_ring_struct(struct bnxt
*bp
)
2503 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2504 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2505 struct bnxt_ring_mem_info
*rmem
;
2506 struct bnxt_cp_ring_info
*cpr
;
2507 struct bnxt_rx_ring_info
*rxr
;
2508 struct bnxt_tx_ring_info
*txr
;
2509 struct bnxt_ring_struct
*ring
;
2514 cpr
= &bnapi
->cp_ring
;
2515 ring
= &cpr
->cp_ring_struct
;
2516 rmem
= &ring
->ring_mem
;
2517 rmem
->nr_pages
= bp
->cp_nr_pages
;
2518 rmem
->page_size
= HW_CMPD_RING_SIZE
;
2519 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
2520 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
2521 rmem
->vmem_size
= 0;
2523 rxr
= bnapi
->rx_ring
;
2527 ring
= &rxr
->rx_ring_struct
;
2528 rmem
= &ring
->ring_mem
;
2529 rmem
->nr_pages
= bp
->rx_nr_pages
;
2530 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2531 rmem
->pg_arr
= (void **)rxr
->rx_desc_ring
;
2532 rmem
->dma_arr
= rxr
->rx_desc_mapping
;
2533 rmem
->vmem_size
= SW_RXBD_RING_SIZE
* bp
->rx_nr_pages
;
2534 rmem
->vmem
= (void **)&rxr
->rx_buf_ring
;
2536 ring
= &rxr
->rx_agg_ring_struct
;
2537 rmem
= &ring
->ring_mem
;
2538 rmem
->nr_pages
= bp
->rx_agg_nr_pages
;
2539 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2540 rmem
->pg_arr
= (void **)rxr
->rx_agg_desc_ring
;
2541 rmem
->dma_arr
= rxr
->rx_agg_desc_mapping
;
2542 rmem
->vmem_size
= SW_RXBD_AGG_RING_SIZE
* bp
->rx_agg_nr_pages
;
2543 rmem
->vmem
= (void **)&rxr
->rx_agg_ring
;
2546 txr
= bnapi
->tx_ring
;
2550 ring
= &txr
->tx_ring_struct
;
2551 rmem
= &ring
->ring_mem
;
2552 rmem
->nr_pages
= bp
->tx_nr_pages
;
2553 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2554 rmem
->pg_arr
= (void **)txr
->tx_desc_ring
;
2555 rmem
->dma_arr
= txr
->tx_desc_mapping
;
2556 rmem
->vmem_size
= SW_TXBD_RING_SIZE
* bp
->tx_nr_pages
;
2557 rmem
->vmem
= (void **)&txr
->tx_buf_ring
;
2561 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct
*ring
, u32 type
)
2565 struct rx_bd
**rx_buf_ring
;
2567 rx_buf_ring
= (struct rx_bd
**)ring
->ring_mem
.pg_arr
;
2568 for (i
= 0, prod
= 0; i
< ring
->ring_mem
.nr_pages
; i
++) {
2572 rxbd
= rx_buf_ring
[i
];
2576 for (j
= 0; j
< RX_DESC_CNT
; j
++, rxbd
++, prod
++) {
2577 rxbd
->rx_bd_len_flags_type
= cpu_to_le32(type
);
2578 rxbd
->rx_bd_opaque
= prod
;
2583 static int bnxt_init_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
2585 struct net_device
*dev
= bp
->dev
;
2586 struct bnxt_rx_ring_info
*rxr
;
2587 struct bnxt_ring_struct
*ring
;
2591 type
= (bp
->rx_buf_use_size
<< RX_BD_LEN_SHIFT
) |
2592 RX_BD_TYPE_RX_PACKET_BD
| RX_BD_FLAGS_EOP
;
2594 if (NET_IP_ALIGN
== 2)
2595 type
|= RX_BD_FLAGS_SOP
;
2597 rxr
= &bp
->rx_ring
[ring_nr
];
2598 ring
= &rxr
->rx_ring_struct
;
2599 bnxt_init_rxbd_pages(ring
, type
);
2601 if (BNXT_RX_PAGE_MODE(bp
) && bp
->xdp_prog
) {
2602 rxr
->xdp_prog
= bpf_prog_add(bp
->xdp_prog
, 1);
2603 if (IS_ERR(rxr
->xdp_prog
)) {
2604 int rc
= PTR_ERR(rxr
->xdp_prog
);
2606 rxr
->xdp_prog
= NULL
;
2610 prod
= rxr
->rx_prod
;
2611 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
2612 if (bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
2613 netdev_warn(dev
, "init'ed rx ring %d with %d/%d skbs only\n",
2614 ring_nr
, i
, bp
->rx_ring_size
);
2617 prod
= NEXT_RX(prod
);
2619 rxr
->rx_prod
= prod
;
2620 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2622 ring
= &rxr
->rx_agg_ring_struct
;
2623 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2625 if (!(bp
->flags
& BNXT_FLAG_AGG_RINGS
))
2628 type
= ((u32
)BNXT_RX_PAGE_SIZE
<< RX_BD_LEN_SHIFT
) |
2629 RX_BD_TYPE_RX_AGG_BD
| RX_BD_FLAGS_SOP
;
2631 bnxt_init_rxbd_pages(ring
, type
);
2633 prod
= rxr
->rx_agg_prod
;
2634 for (i
= 0; i
< bp
->rx_agg_ring_size
; i
++) {
2635 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
2636 netdev_warn(dev
, "init'ed rx ring %d with %d/%d pages only\n",
2637 ring_nr
, i
, bp
->rx_ring_size
);
2640 prod
= NEXT_RX_AGG(prod
);
2642 rxr
->rx_agg_prod
= prod
;
2644 if (bp
->flags
& BNXT_FLAG_TPA
) {
2649 for (i
= 0; i
< MAX_TPA
; i
++) {
2650 data
= __bnxt_alloc_rx_data(bp
, &mapping
,
2655 rxr
->rx_tpa
[i
].data
= data
;
2656 rxr
->rx_tpa
[i
].data_ptr
= data
+ bp
->rx_offset
;
2657 rxr
->rx_tpa
[i
].mapping
= mapping
;
2660 netdev_err(bp
->dev
, "No resource allocated for LRO/GRO\n");
2668 static void bnxt_init_cp_rings(struct bnxt
*bp
)
2672 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2673 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
2674 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
2676 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2677 cpr
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
2678 cpr
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
2682 static int bnxt_init_rx_rings(struct bnxt
*bp
)
2686 if (BNXT_RX_PAGE_MODE(bp
)) {
2687 bp
->rx_offset
= NET_IP_ALIGN
+ XDP_PACKET_HEADROOM
;
2688 bp
->rx_dma_offset
= XDP_PACKET_HEADROOM
;
2690 bp
->rx_offset
= BNXT_RX_OFFSET
;
2691 bp
->rx_dma_offset
= BNXT_RX_DMA_OFFSET
;
2694 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2695 rc
= bnxt_init_one_rx_ring(bp
, i
);
2703 static int bnxt_init_tx_rings(struct bnxt
*bp
)
2707 bp
->tx_wake_thresh
= max_t(int, bp
->tx_ring_size
/ 2,
2710 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2711 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2712 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
2714 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2720 static void bnxt_free_ring_grps(struct bnxt
*bp
)
2722 kfree(bp
->grp_info
);
2723 bp
->grp_info
= NULL
;
2726 static int bnxt_init_ring_grps(struct bnxt
*bp
, bool irq_re_init
)
2731 bp
->grp_info
= kcalloc(bp
->cp_nr_rings
,
2732 sizeof(struct bnxt_ring_grp_info
),
2737 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2739 bp
->grp_info
[i
].fw_stats_ctx
= INVALID_HW_RING_ID
;
2740 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
2741 bp
->grp_info
[i
].rx_fw_ring_id
= INVALID_HW_RING_ID
;
2742 bp
->grp_info
[i
].agg_fw_ring_id
= INVALID_HW_RING_ID
;
2743 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
2748 static void bnxt_free_vnics(struct bnxt
*bp
)
2750 kfree(bp
->vnic_info
);
2751 bp
->vnic_info
= NULL
;
2755 static int bnxt_alloc_vnics(struct bnxt
*bp
)
2759 #ifdef CONFIG_RFS_ACCEL
2760 if (bp
->flags
& BNXT_FLAG_RFS
)
2761 num_vnics
+= bp
->rx_nr_rings
;
2764 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
2767 bp
->vnic_info
= kcalloc(num_vnics
, sizeof(struct bnxt_vnic_info
),
2772 bp
->nr_vnics
= num_vnics
;
2776 static void bnxt_init_vnics(struct bnxt
*bp
)
2780 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2781 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
2783 vnic
->fw_vnic_id
= INVALID_HW_RING_ID
;
2784 vnic
->fw_rss_cos_lb_ctx
[0] = INVALID_HW_RING_ID
;
2785 vnic
->fw_rss_cos_lb_ctx
[1] = INVALID_HW_RING_ID
;
2786 vnic
->fw_l2_ctx_id
= INVALID_HW_RING_ID
;
2788 if (bp
->vnic_info
[i
].rss_hash_key
) {
2790 prandom_bytes(vnic
->rss_hash_key
,
2793 memcpy(vnic
->rss_hash_key
,
2794 bp
->vnic_info
[0].rss_hash_key
,
2800 static int bnxt_calc_nr_ring_pages(u32 ring_size
, int desc_per_pg
)
2804 pages
= ring_size
/ desc_per_pg
;
2811 while (pages
& (pages
- 1))
2817 void bnxt_set_tpa_flags(struct bnxt
*bp
)
2819 bp
->flags
&= ~BNXT_FLAG_TPA
;
2820 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
2822 if (bp
->dev
->features
& NETIF_F_LRO
)
2823 bp
->flags
|= BNXT_FLAG_LRO
;
2824 else if (bp
->dev
->features
& NETIF_F_GRO_HW
)
2825 bp
->flags
|= BNXT_FLAG_GRO
;
2828 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2831 void bnxt_set_ring_params(struct bnxt
*bp
)
2833 u32 ring_size
, rx_size
, rx_space
;
2834 u32 agg_factor
= 0, agg_ring_size
= 0;
2836 /* 8 for CRC and VLAN */
2837 rx_size
= SKB_DATA_ALIGN(bp
->dev
->mtu
+ ETH_HLEN
+ NET_IP_ALIGN
+ 8);
2839 rx_space
= rx_size
+ NET_SKB_PAD
+
2840 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
2842 bp
->rx_copy_thresh
= BNXT_RX_COPY_THRESH
;
2843 ring_size
= bp
->rx_ring_size
;
2844 bp
->rx_agg_ring_size
= 0;
2845 bp
->rx_agg_nr_pages
= 0;
2847 if (bp
->flags
& BNXT_FLAG_TPA
)
2848 agg_factor
= min_t(u32
, 4, 65536 / BNXT_RX_PAGE_SIZE
);
2850 bp
->flags
&= ~BNXT_FLAG_JUMBO
;
2851 if (rx_space
> PAGE_SIZE
&& !(bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)) {
2854 bp
->flags
|= BNXT_FLAG_JUMBO
;
2855 jumbo_factor
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
2856 if (jumbo_factor
> agg_factor
)
2857 agg_factor
= jumbo_factor
;
2859 agg_ring_size
= ring_size
* agg_factor
;
2861 if (agg_ring_size
) {
2862 bp
->rx_agg_nr_pages
= bnxt_calc_nr_ring_pages(agg_ring_size
,
2864 if (bp
->rx_agg_nr_pages
> MAX_RX_AGG_PAGES
) {
2865 u32 tmp
= agg_ring_size
;
2867 bp
->rx_agg_nr_pages
= MAX_RX_AGG_PAGES
;
2868 agg_ring_size
= MAX_RX_AGG_PAGES
* RX_DESC_CNT
- 1;
2869 netdev_warn(bp
->dev
, "rx agg ring size %d reduced to %d.\n",
2870 tmp
, agg_ring_size
);
2872 bp
->rx_agg_ring_size
= agg_ring_size
;
2873 bp
->rx_agg_ring_mask
= (bp
->rx_agg_nr_pages
* RX_DESC_CNT
) - 1;
2874 rx_size
= SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH
+ NET_IP_ALIGN
);
2875 rx_space
= rx_size
+ NET_SKB_PAD
+
2876 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
2879 bp
->rx_buf_use_size
= rx_size
;
2880 bp
->rx_buf_size
= rx_space
;
2882 bp
->rx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, RX_DESC_CNT
);
2883 bp
->rx_ring_mask
= (bp
->rx_nr_pages
* RX_DESC_CNT
) - 1;
2885 ring_size
= bp
->tx_ring_size
;
2886 bp
->tx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, TX_DESC_CNT
);
2887 bp
->tx_ring_mask
= (bp
->tx_nr_pages
* TX_DESC_CNT
) - 1;
2889 ring_size
= bp
->rx_ring_size
* (2 + agg_factor
) + bp
->tx_ring_size
;
2890 bp
->cp_ring_size
= ring_size
;
2892 bp
->cp_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, CP_DESC_CNT
);
2893 if (bp
->cp_nr_pages
> MAX_CP_PAGES
) {
2894 bp
->cp_nr_pages
= MAX_CP_PAGES
;
2895 bp
->cp_ring_size
= MAX_CP_PAGES
* CP_DESC_CNT
- 1;
2896 netdev_warn(bp
->dev
, "completion ring size %d reduced to %d.\n",
2897 ring_size
, bp
->cp_ring_size
);
2899 bp
->cp_bit
= bp
->cp_nr_pages
* CP_DESC_CNT
;
2900 bp
->cp_ring_mask
= bp
->cp_bit
- 1;
2903 /* Changing allocation mode of RX rings.
2904 * TODO: Update when extending xdp_rxq_info to support allocation modes.
2906 int bnxt_set_rx_skb_mode(struct bnxt
*bp
, bool page_mode
)
2909 if (bp
->dev
->mtu
> BNXT_MAX_PAGE_MODE_MTU
)
2912 min_t(u16
, bp
->max_mtu
, BNXT_MAX_PAGE_MODE_MTU
);
2913 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
2914 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
| BNXT_FLAG_RX_PAGE_MODE
;
2915 bp
->rx_dir
= DMA_BIDIRECTIONAL
;
2916 bp
->rx_skb_func
= bnxt_rx_page_skb
;
2917 /* Disable LRO or GRO_HW */
2918 netdev_update_features(bp
->dev
);
2920 bp
->dev
->max_mtu
= bp
->max_mtu
;
2921 bp
->flags
&= ~BNXT_FLAG_RX_PAGE_MODE
;
2922 bp
->rx_dir
= DMA_FROM_DEVICE
;
2923 bp
->rx_skb_func
= bnxt_rx_skb
;
2928 static void bnxt_free_vnic_attributes(struct bnxt
*bp
)
2931 struct bnxt_vnic_info
*vnic
;
2932 struct pci_dev
*pdev
= bp
->pdev
;
2937 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2938 vnic
= &bp
->vnic_info
[i
];
2940 kfree(vnic
->fw_grp_ids
);
2941 vnic
->fw_grp_ids
= NULL
;
2943 kfree(vnic
->uc_list
);
2944 vnic
->uc_list
= NULL
;
2946 if (vnic
->mc_list
) {
2947 dma_free_coherent(&pdev
->dev
, vnic
->mc_list_size
,
2948 vnic
->mc_list
, vnic
->mc_list_mapping
);
2949 vnic
->mc_list
= NULL
;
2952 if (vnic
->rss_table
) {
2953 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
2955 vnic
->rss_table_dma_addr
);
2956 vnic
->rss_table
= NULL
;
2959 vnic
->rss_hash_key
= NULL
;
2964 static int bnxt_alloc_vnic_attributes(struct bnxt
*bp
)
2966 int i
, rc
= 0, size
;
2967 struct bnxt_vnic_info
*vnic
;
2968 struct pci_dev
*pdev
= bp
->pdev
;
2971 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
2972 vnic
= &bp
->vnic_info
[i
];
2974 if (vnic
->flags
& BNXT_VNIC_UCAST_FLAG
) {
2975 int mem_size
= (BNXT_MAX_UC_ADDRS
- 1) * ETH_ALEN
;
2978 vnic
->uc_list
= kmalloc(mem_size
, GFP_KERNEL
);
2979 if (!vnic
->uc_list
) {
2986 if (vnic
->flags
& BNXT_VNIC_MCAST_FLAG
) {
2987 vnic
->mc_list_size
= BNXT_MAX_MC_ADDRS
* ETH_ALEN
;
2989 dma_alloc_coherent(&pdev
->dev
,
2991 &vnic
->mc_list_mapping
,
2993 if (!vnic
->mc_list
) {
2999 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3000 max_rings
= bp
->rx_nr_rings
;
3004 vnic
->fw_grp_ids
= kcalloc(max_rings
, sizeof(u16
), GFP_KERNEL
);
3005 if (!vnic
->fw_grp_ids
) {
3010 if ((bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
3011 !(vnic
->flags
& BNXT_VNIC_RSS_FLAG
))
3014 /* Allocate rss table and hash key */
3015 vnic
->rss_table
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3016 &vnic
->rss_table_dma_addr
,
3018 if (!vnic
->rss_table
) {
3023 size
= L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE
* sizeof(u16
));
3025 vnic
->rss_hash_key
= ((void *)vnic
->rss_table
) + size
;
3026 vnic
->rss_hash_key_dma_addr
= vnic
->rss_table_dma_addr
+ size
;
3034 static void bnxt_free_hwrm_resources(struct bnxt
*bp
)
3036 struct pci_dev
*pdev
= bp
->pdev
;
3038 if (bp
->hwrm_cmd_resp_addr
) {
3039 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
, bp
->hwrm_cmd_resp_addr
,
3040 bp
->hwrm_cmd_resp_dma_addr
);
3041 bp
->hwrm_cmd_resp_addr
= NULL
;
3045 static int bnxt_alloc_hwrm_resources(struct bnxt
*bp
)
3047 struct pci_dev
*pdev
= bp
->pdev
;
3049 bp
->hwrm_cmd_resp_addr
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3050 &bp
->hwrm_cmd_resp_dma_addr
,
3052 if (!bp
->hwrm_cmd_resp_addr
)
3058 static void bnxt_free_hwrm_short_cmd_req(struct bnxt
*bp
)
3060 if (bp
->hwrm_short_cmd_req_addr
) {
3061 struct pci_dev
*pdev
= bp
->pdev
;
3063 dma_free_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3064 bp
->hwrm_short_cmd_req_addr
,
3065 bp
->hwrm_short_cmd_req_dma_addr
);
3066 bp
->hwrm_short_cmd_req_addr
= NULL
;
3070 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt
*bp
)
3072 struct pci_dev
*pdev
= bp
->pdev
;
3074 bp
->hwrm_short_cmd_req_addr
=
3075 dma_alloc_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3076 &bp
->hwrm_short_cmd_req_dma_addr
,
3078 if (!bp
->hwrm_short_cmd_req_addr
)
3084 static void bnxt_free_stats(struct bnxt
*bp
)
3087 struct pci_dev
*pdev
= bp
->pdev
;
3089 bp
->flags
&= ~BNXT_FLAG_PORT_STATS
;
3090 bp
->flags
&= ~BNXT_FLAG_PORT_STATS_EXT
;
3092 if (bp
->hw_rx_port_stats
) {
3093 dma_free_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3094 bp
->hw_rx_port_stats
,
3095 bp
->hw_rx_port_stats_map
);
3096 bp
->hw_rx_port_stats
= NULL
;
3099 if (bp
->hw_tx_port_stats_ext
) {
3100 dma_free_coherent(&pdev
->dev
, sizeof(struct tx_port_stats_ext
),
3101 bp
->hw_tx_port_stats_ext
,
3102 bp
->hw_tx_port_stats_ext_map
);
3103 bp
->hw_tx_port_stats_ext
= NULL
;
3106 if (bp
->hw_rx_port_stats_ext
) {
3107 dma_free_coherent(&pdev
->dev
, sizeof(struct rx_port_stats_ext
),
3108 bp
->hw_rx_port_stats_ext
,
3109 bp
->hw_rx_port_stats_ext_map
);
3110 bp
->hw_rx_port_stats_ext
= NULL
;
3116 size
= sizeof(struct ctx_hw_stats
);
3118 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3119 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3120 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3122 if (cpr
->hw_stats
) {
3123 dma_free_coherent(&pdev
->dev
, size
, cpr
->hw_stats
,
3125 cpr
->hw_stats
= NULL
;
3130 static int bnxt_alloc_stats(struct bnxt
*bp
)
3133 struct pci_dev
*pdev
= bp
->pdev
;
3135 size
= sizeof(struct ctx_hw_stats
);
3137 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3138 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3139 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3141 cpr
->hw_stats
= dma_alloc_coherent(&pdev
->dev
, size
,
3147 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
3150 if (BNXT_PF(bp
) && bp
->chip_num
!= CHIP_NUM_58700
) {
3151 bp
->hw_port_stats_size
= sizeof(struct rx_port_stats
) +
3152 sizeof(struct tx_port_stats
) + 1024;
3154 bp
->hw_rx_port_stats
=
3155 dma_alloc_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3156 &bp
->hw_rx_port_stats_map
,
3158 if (!bp
->hw_rx_port_stats
)
3161 bp
->hw_tx_port_stats
= (void *)(bp
->hw_rx_port_stats
+ 1) +
3163 bp
->hw_tx_port_stats_map
= bp
->hw_rx_port_stats_map
+
3164 sizeof(struct rx_port_stats
) + 512;
3165 bp
->flags
|= BNXT_FLAG_PORT_STATS
;
3167 /* Display extended statistics only if FW supports it */
3168 if (bp
->hwrm_spec_code
< 0x10804 ||
3169 bp
->hwrm_spec_code
== 0x10900)
3172 bp
->hw_rx_port_stats_ext
=
3173 dma_zalloc_coherent(&pdev
->dev
,
3174 sizeof(struct rx_port_stats_ext
),
3175 &bp
->hw_rx_port_stats_ext_map
,
3177 if (!bp
->hw_rx_port_stats_ext
)
3180 if (bp
->hwrm_spec_code
>= 0x10902) {
3181 bp
->hw_tx_port_stats_ext
=
3182 dma_zalloc_coherent(&pdev
->dev
,
3183 sizeof(struct tx_port_stats_ext
),
3184 &bp
->hw_tx_port_stats_ext_map
,
3187 bp
->flags
|= BNXT_FLAG_PORT_STATS_EXT
;
3192 static void bnxt_clear_ring_indices(struct bnxt
*bp
)
3199 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3200 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3201 struct bnxt_cp_ring_info
*cpr
;
3202 struct bnxt_rx_ring_info
*rxr
;
3203 struct bnxt_tx_ring_info
*txr
;
3208 cpr
= &bnapi
->cp_ring
;
3209 cpr
->cp_raw_cons
= 0;
3211 txr
= bnapi
->tx_ring
;
3217 rxr
= bnapi
->rx_ring
;
3220 rxr
->rx_agg_prod
= 0;
3221 rxr
->rx_sw_agg_prod
= 0;
3222 rxr
->rx_next_cons
= 0;
3227 static void bnxt_free_ntp_fltrs(struct bnxt
*bp
, bool irq_reinit
)
3229 #ifdef CONFIG_RFS_ACCEL
3232 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3233 * safe to delete the hash table.
3235 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
3236 struct hlist_head
*head
;
3237 struct hlist_node
*tmp
;
3238 struct bnxt_ntuple_filter
*fltr
;
3240 head
= &bp
->ntp_fltr_hash_tbl
[i
];
3241 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
3242 hlist_del(&fltr
->hash
);
3247 kfree(bp
->ntp_fltr_bmap
);
3248 bp
->ntp_fltr_bmap
= NULL
;
3250 bp
->ntp_fltr_count
= 0;
3254 static int bnxt_alloc_ntp_fltrs(struct bnxt
*bp
)
3256 #ifdef CONFIG_RFS_ACCEL
3259 if (!(bp
->flags
& BNXT_FLAG_RFS
))
3262 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++)
3263 INIT_HLIST_HEAD(&bp
->ntp_fltr_hash_tbl
[i
]);
3265 bp
->ntp_fltr_count
= 0;
3266 bp
->ntp_fltr_bmap
= kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR
),
3270 if (!bp
->ntp_fltr_bmap
)
3279 static void bnxt_free_mem(struct bnxt
*bp
, bool irq_re_init
)
3281 bnxt_free_vnic_attributes(bp
);
3282 bnxt_free_tx_rings(bp
);
3283 bnxt_free_rx_rings(bp
);
3284 bnxt_free_cp_rings(bp
);
3285 bnxt_free_ntp_fltrs(bp
, irq_re_init
);
3287 bnxt_free_stats(bp
);
3288 bnxt_free_ring_grps(bp
);
3289 bnxt_free_vnics(bp
);
3290 kfree(bp
->tx_ring_map
);
3291 bp
->tx_ring_map
= NULL
;
3299 bnxt_clear_ring_indices(bp
);
3303 static int bnxt_alloc_mem(struct bnxt
*bp
, bool irq_re_init
)
3305 int i
, j
, rc
, size
, arr_size
;
3309 /* Allocate bnapi mem pointer array and mem block for
3312 arr_size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
*) *
3314 size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
));
3315 bnapi
= kzalloc(arr_size
+ size
* bp
->cp_nr_rings
, GFP_KERNEL
);
3321 for (i
= 0; i
< bp
->cp_nr_rings
; i
++, bnapi
+= size
) {
3322 bp
->bnapi
[i
] = bnapi
;
3323 bp
->bnapi
[i
]->index
= i
;
3324 bp
->bnapi
[i
]->bp
= bp
;
3327 bp
->rx_ring
= kcalloc(bp
->rx_nr_rings
,
3328 sizeof(struct bnxt_rx_ring_info
),
3333 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3334 bp
->rx_ring
[i
].bnapi
= bp
->bnapi
[i
];
3335 bp
->bnapi
[i
]->rx_ring
= &bp
->rx_ring
[i
];
3338 bp
->tx_ring
= kcalloc(bp
->tx_nr_rings
,
3339 sizeof(struct bnxt_tx_ring_info
),
3344 bp
->tx_ring_map
= kcalloc(bp
->tx_nr_rings
, sizeof(u16
),
3347 if (!bp
->tx_ring_map
)
3350 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
3353 j
= bp
->rx_nr_rings
;
3355 for (i
= 0; i
< bp
->tx_nr_rings
; i
++, j
++) {
3356 bp
->tx_ring
[i
].bnapi
= bp
->bnapi
[j
];
3357 bp
->bnapi
[j
]->tx_ring
= &bp
->tx_ring
[i
];
3358 bp
->tx_ring_map
[i
] = bp
->tx_nr_rings_xdp
+ i
;
3359 if (i
>= bp
->tx_nr_rings_xdp
) {
3360 bp
->tx_ring
[i
].txq_index
= i
-
3361 bp
->tx_nr_rings_xdp
;
3362 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int
;
3364 bp
->bnapi
[j
]->flags
|= BNXT_NAPI_FLAG_XDP
;
3365 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int_xdp
;
3369 rc
= bnxt_alloc_stats(bp
);
3373 rc
= bnxt_alloc_ntp_fltrs(bp
);
3377 rc
= bnxt_alloc_vnics(bp
);
3382 bnxt_init_ring_struct(bp
);
3384 rc
= bnxt_alloc_rx_rings(bp
);
3388 rc
= bnxt_alloc_tx_rings(bp
);
3392 rc
= bnxt_alloc_cp_rings(bp
);
3396 bp
->vnic_info
[0].flags
|= BNXT_VNIC_RSS_FLAG
| BNXT_VNIC_MCAST_FLAG
|
3397 BNXT_VNIC_UCAST_FLAG
;
3398 rc
= bnxt_alloc_vnic_attributes(bp
);
3404 bnxt_free_mem(bp
, true);
3408 static void bnxt_disable_int(struct bnxt
*bp
)
3415 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3416 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3417 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3418 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3420 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
)
3421 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
3425 static int bnxt_cp_num_to_irq_num(struct bnxt
*bp
, int n
)
3427 struct bnxt_napi
*bnapi
= bp
->bnapi
[n
];
3428 struct bnxt_cp_ring_info
*cpr
;
3430 cpr
= &bnapi
->cp_ring
;
3431 return cpr
->cp_ring_struct
.map_idx
;
3434 static void bnxt_disable_int_sync(struct bnxt
*bp
)
3438 atomic_inc(&bp
->intr_sem
);
3440 bnxt_disable_int(bp
);
3441 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3442 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
3444 synchronize_irq(bp
->irq_tbl
[map_idx
].vector
);
3448 static void bnxt_enable_int(struct bnxt
*bp
)
3452 atomic_set(&bp
->intr_sem
, 0);
3453 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3454 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3455 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3457 BNXT_CP_DB_REARM(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
3461 void bnxt_hwrm_cmd_hdr_init(struct bnxt
*bp
, void *request
, u16 req_type
,
3462 u16 cmpl_ring
, u16 target_id
)
3464 struct input
*req
= request
;
3466 req
->req_type
= cpu_to_le16(req_type
);
3467 req
->cmpl_ring
= cpu_to_le16(cmpl_ring
);
3468 req
->target_id
= cpu_to_le16(target_id
);
3469 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_resp_dma_addr
);
3472 static int bnxt_hwrm_do_send_msg(struct bnxt
*bp
, void *msg
, u32 msg_len
,
3473 int timeout
, bool silent
)
3475 int i
, intr_process
, rc
, tmo_count
;
3476 struct input
*req
= msg
;
3480 u16 cp_ring_id
, len
= 0;
3481 struct hwrm_err_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3482 u16 max_req_len
= BNXT_HWRM_MAX_REQ_LEN
;
3483 struct hwrm_short_input short_input
= {0};
3485 req
->seq_id
= cpu_to_le16(bp
->hwrm_cmd_seq
++);
3486 memset(resp
, 0, PAGE_SIZE
);
3487 cp_ring_id
= le16_to_cpu(req
->cmpl_ring
);
3488 intr_process
= (cp_ring_id
== INVALID_HW_RING_ID
) ? 0 : 1;
3490 if (msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
3491 if (msg_len
> bp
->hwrm_max_ext_req_len
||
3492 !bp
->hwrm_short_cmd_req_addr
)
3496 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
3497 msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
3498 void *short_cmd_req
= bp
->hwrm_short_cmd_req_addr
;
3501 /* Set boundary for maximum extended request length for short
3502 * cmd format. If passed up from device use the max supported
3503 * internal req length.
3505 max_msg_len
= bp
->hwrm_max_ext_req_len
;
3507 memcpy(short_cmd_req
, req
, msg_len
);
3508 if (msg_len
< max_msg_len
)
3509 memset(short_cmd_req
+ msg_len
, 0,
3510 max_msg_len
- msg_len
);
3512 short_input
.req_type
= req
->req_type
;
3513 short_input
.signature
=
3514 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD
);
3515 short_input
.size
= cpu_to_le16(msg_len
);
3516 short_input
.req_addr
=
3517 cpu_to_le64(bp
->hwrm_short_cmd_req_dma_addr
);
3519 data
= (u32
*)&short_input
;
3520 msg_len
= sizeof(short_input
);
3522 /* Sync memory write before updating doorbell */
3525 max_req_len
= BNXT_HWRM_SHORT_REQ_LEN
;
3528 /* Write request msg to hwrm channel */
3529 __iowrite32_copy(bp
->bar0
, data
, msg_len
/ 4);
3531 for (i
= msg_len
; i
< max_req_len
; i
+= 4)
3532 writel(0, bp
->bar0
+ i
);
3534 /* currently supports only one outstanding message */
3536 bp
->hwrm_intr_seq_id
= le16_to_cpu(req
->seq_id
);
3538 /* Ring channel doorbell */
3539 writel(1, bp
->bar0
+ 0x100);
3542 timeout
= DFLT_HWRM_CMD_TIMEOUT
;
3543 /* convert timeout to usec */
3547 /* Short timeout for the first few iterations:
3548 * number of loops = number of loops for short timeout +
3549 * number of loops for standard timeout.
3551 tmo_count
= HWRM_SHORT_TIMEOUT_COUNTER
;
3552 timeout
= timeout
- HWRM_SHORT_MIN_TIMEOUT
* HWRM_SHORT_TIMEOUT_COUNTER
;
3553 tmo_count
+= DIV_ROUND_UP(timeout
, HWRM_MIN_TIMEOUT
);
3554 resp_len
= bp
->hwrm_cmd_resp_addr
+ HWRM_RESP_LEN_OFFSET
;
3556 /* Wait until hwrm response cmpl interrupt is processed */
3557 while (bp
->hwrm_intr_seq_id
!= HWRM_SEQ_ID_INVALID
&&
3559 /* on first few passes, just barely sleep */
3560 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
)
3561 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
3562 HWRM_SHORT_MAX_TIMEOUT
);
3564 usleep_range(HWRM_MIN_TIMEOUT
,
3568 if (bp
->hwrm_intr_seq_id
!= HWRM_SEQ_ID_INVALID
) {
3569 netdev_err(bp
->dev
, "Resp cmpl intr err msg: 0x%x\n",
3570 le16_to_cpu(req
->req_type
));
3573 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
3575 valid
= bp
->hwrm_cmd_resp_addr
+ len
- 1;
3579 /* Check if response len is updated */
3580 for (i
= 0; i
< tmo_count
; i
++) {
3581 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
3585 /* on first few passes, just barely sleep */
3586 if (i
< DFLT_HWRM_CMD_TIMEOUT
)
3587 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
3588 HWRM_SHORT_MAX_TIMEOUT
);
3590 usleep_range(HWRM_MIN_TIMEOUT
,
3594 if (i
>= tmo_count
) {
3595 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
3596 HWRM_TOTAL_TIMEOUT(i
),
3597 le16_to_cpu(req
->req_type
),
3598 le16_to_cpu(req
->seq_id
), len
);
3602 /* Last byte of resp contains valid bit */
3603 valid
= bp
->hwrm_cmd_resp_addr
+ len
- 1;
3604 for (j
= 0; j
< HWRM_VALID_BIT_DELAY_USEC
; j
++) {
3605 /* make sure we read from updated DMA memory */
3612 if (j
>= HWRM_VALID_BIT_DELAY_USEC
) {
3613 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
3614 HWRM_TOTAL_TIMEOUT(i
),
3615 le16_to_cpu(req
->req_type
),
3616 le16_to_cpu(req
->seq_id
), len
, *valid
);
3621 /* Zero valid bit for compatibility. Valid bit in an older spec
3622 * may become a new field in a newer spec. We must make sure that
3623 * a new field not implemented by old spec will read zero.
3626 rc
= le16_to_cpu(resp
->error_code
);
3628 netdev_err(bp
->dev
, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3629 le16_to_cpu(resp
->req_type
),
3630 le16_to_cpu(resp
->seq_id
), rc
);
3634 int _hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
3636 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, false);
3639 int _hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
3642 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
3645 int hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
3649 mutex_lock(&bp
->hwrm_cmd_lock
);
3650 rc
= _hwrm_send_message(bp
, msg
, msg_len
, timeout
);
3651 mutex_unlock(&bp
->hwrm_cmd_lock
);
3655 int hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
3660 mutex_lock(&bp
->hwrm_cmd_lock
);
3661 rc
= bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
3662 mutex_unlock(&bp
->hwrm_cmd_lock
);
3666 int bnxt_hwrm_func_rgtr_async_events(struct bnxt
*bp
, unsigned long *bmap
,
3669 struct hwrm_func_drv_rgtr_input req
= {0};
3670 DECLARE_BITMAP(async_events_bmap
, 256);
3671 u32
*events
= (u32
*)async_events_bmap
;
3674 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
3677 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
3679 memset(async_events_bmap
, 0, sizeof(async_events_bmap
));
3680 for (i
= 0; i
< ARRAY_SIZE(bnxt_async_events_arr
); i
++)
3681 __set_bit(bnxt_async_events_arr
[i
], async_events_bmap
);
3683 if (bmap
&& bmap_size
) {
3684 for (i
= 0; i
< bmap_size
; i
++) {
3685 if (test_bit(i
, bmap
))
3686 __set_bit(i
, async_events_bmap
);
3690 for (i
= 0; i
< 8; i
++)
3691 req
.async_event_fwd
[i
] |= cpu_to_le32(events
[i
]);
3693 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3696 static int bnxt_hwrm_func_drv_rgtr(struct bnxt
*bp
)
3698 struct hwrm_func_drv_rgtr_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3699 struct hwrm_func_drv_rgtr_input req
= {0};
3702 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
3705 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE
|
3706 FUNC_DRV_RGTR_REQ_ENABLES_VER
);
3708 req
.os_type
= cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX
);
3709 req
.flags
= cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE
);
3710 req
.ver_maj_8b
= DRV_VER_MAJ
;
3711 req
.ver_min_8b
= DRV_VER_MIN
;
3712 req
.ver_upd_8b
= DRV_VER_UPD
;
3713 req
.ver_maj
= cpu_to_le16(DRV_VER_MAJ
);
3714 req
.ver_min
= cpu_to_le16(DRV_VER_MIN
);
3715 req
.ver_upd
= cpu_to_le16(DRV_VER_UPD
);
3721 memset(data
, 0, sizeof(data
));
3722 for (i
= 0; i
< ARRAY_SIZE(bnxt_vf_req_snif
); i
++) {
3723 u16 cmd
= bnxt_vf_req_snif
[i
];
3724 unsigned int bit
, idx
;
3728 data
[idx
] |= 1 << bit
;
3731 for (i
= 0; i
< 8; i
++)
3732 req
.vf_req_fwd
[i
] = cpu_to_le32(data
[i
]);
3735 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD
);
3738 mutex_lock(&bp
->hwrm_cmd_lock
);
3739 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3742 else if (resp
->flags
&
3743 cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED
))
3744 bp
->fw_cap
|= BNXT_FW_CAP_IF_CHANGE
;
3745 mutex_unlock(&bp
->hwrm_cmd_lock
);
3749 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt
*bp
)
3751 struct hwrm_func_drv_unrgtr_input req
= {0};
3753 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_UNRGTR
, -1, -1);
3754 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3757 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt
*bp
, u8 tunnel_type
)
3760 struct hwrm_tunnel_dst_port_free_input req
= {0};
3762 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_FREE
, -1, -1);
3763 req
.tunnel_type
= tunnel_type
;
3765 switch (tunnel_type
) {
3766 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
:
3767 req
.tunnel_dst_port_id
= bp
->vxlan_fw_dst_port_id
;
3769 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
:
3770 req
.tunnel_dst_port_id
= bp
->nge_fw_dst_port_id
;
3776 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3778 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3783 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt
*bp
, __be16 port
,
3787 struct hwrm_tunnel_dst_port_alloc_input req
= {0};
3788 struct hwrm_tunnel_dst_port_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3790 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_ALLOC
, -1, -1);
3792 req
.tunnel_type
= tunnel_type
;
3793 req
.tunnel_dst_port_val
= port
;
3795 mutex_lock(&bp
->hwrm_cmd_lock
);
3796 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3798 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3803 switch (tunnel_type
) {
3804 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN
:
3805 bp
->vxlan_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
3807 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE
:
3808 bp
->nge_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
3815 mutex_unlock(&bp
->hwrm_cmd_lock
);
3819 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt
*bp
, u16 vnic_id
)
3821 struct hwrm_cfa_l2_set_rx_mask_input req
= {0};
3822 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3824 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_SET_RX_MASK
, -1, -1);
3825 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
3827 req
.num_mc_entries
= cpu_to_le32(vnic
->mc_list_count
);
3828 req
.mc_tbl_addr
= cpu_to_le64(vnic
->mc_list_mapping
);
3829 req
.mask
= cpu_to_le32(vnic
->rx_mask
);
3830 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3833 #ifdef CONFIG_RFS_ACCEL
3834 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt
*bp
,
3835 struct bnxt_ntuple_filter
*fltr
)
3837 struct hwrm_cfa_ntuple_filter_free_input req
= {0};
3839 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_FREE
, -1, -1);
3840 req
.ntuple_filter_id
= fltr
->filter_id
;
3841 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3844 #define BNXT_NTP_FLTR_FLAGS \
3845 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3846 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3847 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3848 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3849 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3850 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3851 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3852 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3853 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3854 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3855 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3856 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3857 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
3858 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
3860 #define BNXT_NTP_TUNNEL_FLTR_FLAG \
3861 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3863 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt
*bp
,
3864 struct bnxt_ntuple_filter
*fltr
)
3867 struct hwrm_cfa_ntuple_filter_alloc_input req
= {0};
3868 struct hwrm_cfa_ntuple_filter_alloc_output
*resp
=
3869 bp
->hwrm_cmd_resp_addr
;
3870 struct flow_keys
*keys
= &fltr
->fkeys
;
3871 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[fltr
->rxq
+ 1];
3873 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_ALLOC
, -1, -1);
3874 req
.l2_filter_id
= bp
->vnic_info
[0].fw_l2_filter_id
[fltr
->l2_fltr_idx
];
3876 req
.enables
= cpu_to_le32(BNXT_NTP_FLTR_FLAGS
);
3878 req
.ethertype
= htons(ETH_P_IP
);
3879 memcpy(req
.src_macaddr
, fltr
->src_mac_addr
, ETH_ALEN
);
3880 req
.ip_addr_type
= CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4
;
3881 req
.ip_protocol
= keys
->basic
.ip_proto
;
3883 if (keys
->basic
.n_proto
== htons(ETH_P_IPV6
)) {
3886 req
.ethertype
= htons(ETH_P_IPV6
);
3888 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6
;
3889 *(struct in6_addr
*)&req
.src_ipaddr
[0] =
3890 keys
->addrs
.v6addrs
.src
;
3891 *(struct in6_addr
*)&req
.dst_ipaddr
[0] =
3892 keys
->addrs
.v6addrs
.dst
;
3893 for (i
= 0; i
< 4; i
++) {
3894 req
.src_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
3895 req
.dst_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
3898 req
.src_ipaddr
[0] = keys
->addrs
.v4addrs
.src
;
3899 req
.src_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
3900 req
.dst_ipaddr
[0] = keys
->addrs
.v4addrs
.dst
;
3901 req
.dst_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
3903 if (keys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) {
3904 req
.enables
|= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG
);
3906 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL
;
3909 req
.src_port
= keys
->ports
.src
;
3910 req
.src_port_mask
= cpu_to_be16(0xffff);
3911 req
.dst_port
= keys
->ports
.dst
;
3912 req
.dst_port_mask
= cpu_to_be16(0xffff);
3914 req
.dst_id
= cpu_to_le16(vnic
->fw_vnic_id
);
3915 mutex_lock(&bp
->hwrm_cmd_lock
);
3916 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3918 fltr
->filter_id
= resp
->ntuple_filter_id
;
3919 mutex_unlock(&bp
->hwrm_cmd_lock
);
3924 static int bnxt_hwrm_set_vnic_filter(struct bnxt
*bp
, u16 vnic_id
, u16 idx
,
3928 struct hwrm_cfa_l2_filter_alloc_input req
= {0};
3929 struct hwrm_cfa_l2_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3931 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_ALLOC
, -1, -1);
3932 req
.flags
= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX
);
3933 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
3935 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST
);
3936 req
.dst_id
= cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
3938 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR
|
3939 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID
|
3940 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK
);
3941 memcpy(req
.l2_addr
, mac_addr
, ETH_ALEN
);
3942 req
.l2_addr_mask
[0] = 0xff;
3943 req
.l2_addr_mask
[1] = 0xff;
3944 req
.l2_addr_mask
[2] = 0xff;
3945 req
.l2_addr_mask
[3] = 0xff;
3946 req
.l2_addr_mask
[4] = 0xff;
3947 req
.l2_addr_mask
[5] = 0xff;
3949 mutex_lock(&bp
->hwrm_cmd_lock
);
3950 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
3952 bp
->vnic_info
[vnic_id
].fw_l2_filter_id
[idx
] =
3954 mutex_unlock(&bp
->hwrm_cmd_lock
);
3958 static int bnxt_hwrm_clear_vnic_filter(struct bnxt
*bp
)
3960 u16 i
, j
, num_of_vnics
= 1; /* only vnic 0 supported */
3963 /* Any associated ntuple filters will also be cleared by firmware. */
3964 mutex_lock(&bp
->hwrm_cmd_lock
);
3965 for (i
= 0; i
< num_of_vnics
; i
++) {
3966 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
3968 for (j
= 0; j
< vnic
->uc_filter_count
; j
++) {
3969 struct hwrm_cfa_l2_filter_free_input req
= {0};
3971 bnxt_hwrm_cmd_hdr_init(bp
, &req
,
3972 HWRM_CFA_L2_FILTER_FREE
, -1, -1);
3974 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[j
];
3976 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
3979 vnic
->uc_filter_count
= 0;
3981 mutex_unlock(&bp
->hwrm_cmd_lock
);
3986 static int bnxt_hwrm_vnic_set_tpa(struct bnxt
*bp
, u16 vnic_id
, u32 tpa_flags
)
3988 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
3989 struct hwrm_vnic_tpa_cfg_input req
= {0};
3991 if (vnic
->fw_vnic_id
== INVALID_HW_RING_ID
)
3994 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_TPA_CFG
, -1, -1);
3997 u16 mss
= bp
->dev
->mtu
- 40;
3998 u32 nsegs
, n
, segs
= 0, flags
;
4000 flags
= VNIC_TPA_CFG_REQ_FLAGS_TPA
|
4001 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA
|
4002 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE
|
4003 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN
|
4004 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ
;
4005 if (tpa_flags
& BNXT_FLAG_GRO
)
4006 flags
|= VNIC_TPA_CFG_REQ_FLAGS_GRO
;
4008 req
.flags
= cpu_to_le32(flags
);
4011 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS
|
4012 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS
|
4013 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN
);
4015 /* Number of segs are log2 units, and first packet is not
4016 * included as part of this units.
4018 if (mss
<= BNXT_RX_PAGE_SIZE
) {
4019 n
= BNXT_RX_PAGE_SIZE
/ mss
;
4020 nsegs
= (MAX_SKB_FRAGS
- 1) * n
;
4022 n
= mss
/ BNXT_RX_PAGE_SIZE
;
4023 if (mss
& (BNXT_RX_PAGE_SIZE
- 1))
4025 nsegs
= (MAX_SKB_FRAGS
- n
) / n
;
4028 segs
= ilog2(nsegs
);
4029 req
.max_agg_segs
= cpu_to_le16(segs
);
4030 req
.max_aggs
= cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX
);
4032 req
.min_agg_len
= cpu_to_le32(512);
4034 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4036 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4039 static int bnxt_hwrm_vnic_set_rss(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
4041 u32 i
, j
, max_rings
;
4042 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4043 struct hwrm_vnic_rss_cfg_input req
= {0};
4045 if (vnic
->fw_rss_cos_lb_ctx
[0] == INVALID_HW_RING_ID
)
4048 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
4050 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
4051 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
4052 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
) {
4053 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
4054 max_rings
= bp
->rx_nr_rings
- 1;
4056 max_rings
= bp
->rx_nr_rings
;
4061 /* Fill the RSS indirection table with ring group ids */
4062 for (i
= 0, j
= 0; i
< HW_HASH_INDEX_SIZE
; i
++, j
++) {
4065 vnic
->rss_table
[i
] = cpu_to_le16(vnic
->fw_grp_ids
[j
]);
4068 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
4069 req
.hash_key_tbl_addr
=
4070 cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
4072 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
4073 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4076 static int bnxt_hwrm_vnic_set_hds(struct bnxt
*bp
, u16 vnic_id
)
4078 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4079 struct hwrm_vnic_plcmodes_cfg_input req
= {0};
4081 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_PLCMODES_CFG
, -1, -1);
4082 req
.flags
= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT
|
4083 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4
|
4084 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6
);
4086 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID
|
4087 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID
);
4088 /* thresholds not implemented in firmware yet */
4089 req
.jumbo_thresh
= cpu_to_le16(bp
->rx_copy_thresh
);
4090 req
.hds_threshold
= cpu_to_le16(bp
->rx_copy_thresh
);
4091 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4092 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4095 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt
*bp
, u16 vnic_id
,
4098 struct hwrm_vnic_rss_cos_lb_ctx_free_input req
= {0};
4100 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_FREE
, -1, -1);
4101 req
.rss_cos_lb_ctx_id
=
4102 cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
]);
4104 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4105 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] = INVALID_HW_RING_ID
;
4108 static void bnxt_hwrm_vnic_ctx_free(struct bnxt
*bp
)
4112 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
4113 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
4115 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++) {
4116 if (vnic
->fw_rss_cos_lb_ctx
[j
] != INVALID_HW_RING_ID
)
4117 bnxt_hwrm_vnic_ctx_free_one(bp
, i
, j
);
4120 bp
->rsscos_nr_ctxs
= 0;
4123 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt
*bp
, u16 vnic_id
, u16 ctx_idx
)
4126 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req
= {0};
4127 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output
*resp
=
4128 bp
->hwrm_cmd_resp_addr
;
4130 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC
, -1,
4133 mutex_lock(&bp
->hwrm_cmd_lock
);
4134 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4136 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] =
4137 le16_to_cpu(resp
->rss_cos_lb_ctx_id
);
4138 mutex_unlock(&bp
->hwrm_cmd_lock
);
4143 static u32
bnxt_get_roce_vnic_mode(struct bnxt
*bp
)
4145 if (bp
->flags
& BNXT_FLAG_ROCE_MIRROR_CAP
)
4146 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE
;
4147 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE
;
4150 int bnxt_hwrm_vnic_cfg(struct bnxt
*bp
, u16 vnic_id
)
4152 unsigned int ring
= 0, grp_idx
;
4153 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4154 struct hwrm_vnic_cfg_input req
= {0};
4157 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_CFG
, -1, -1);
4159 req
.enables
= cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP
);
4160 /* Only RSS support for now TBD: COS & LB */
4161 if (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
) {
4162 req
.rss_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
4163 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
4164 VNIC_CFG_REQ_ENABLES_MRU
);
4165 } else if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
) {
4167 cpu_to_le16(bp
->vnic_info
[0].fw_rss_cos_lb_ctx
[0]);
4168 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
4169 VNIC_CFG_REQ_ENABLES_MRU
);
4170 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE
);
4172 req
.rss_rule
= cpu_to_le16(0xffff);
4175 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) &&
4176 (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
)) {
4177 req
.cos_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[1]);
4178 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE
);
4180 req
.cos_rule
= cpu_to_le16(0xffff);
4183 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
4185 else if (vnic
->flags
& BNXT_VNIC_RFS_FLAG
)
4187 else if ((vnic_id
== 1) && BNXT_CHIP_TYPE_NITRO_A0(bp
))
4188 ring
= bp
->rx_nr_rings
- 1;
4190 grp_idx
= bp
->rx_ring
[ring
].bnapi
->index
;
4191 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4192 req
.dflt_ring_grp
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_grp_id
);
4194 req
.lb_rule
= cpu_to_le16(0xffff);
4195 req
.mru
= cpu_to_le16(bp
->dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+
4198 #ifdef CONFIG_BNXT_SRIOV
4200 def_vlan
= bp
->vf
.vlan
;
4202 if ((bp
->flags
& BNXT_FLAG_STRIP_VLAN
) || def_vlan
)
4203 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE
);
4204 if (!vnic_id
&& bnxt_ulp_registered(bp
->edev
, BNXT_ROCE_ULP
))
4205 req
.flags
|= cpu_to_le32(bnxt_get_roce_vnic_mode(bp
));
4207 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4210 static int bnxt_hwrm_vnic_free_one(struct bnxt
*bp
, u16 vnic_id
)
4214 if (bp
->vnic_info
[vnic_id
].fw_vnic_id
!= INVALID_HW_RING_ID
) {
4215 struct hwrm_vnic_free_input req
= {0};
4217 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_FREE
, -1, -1);
4219 cpu_to_le32(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
4221 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4224 bp
->vnic_info
[vnic_id
].fw_vnic_id
= INVALID_HW_RING_ID
;
4229 static void bnxt_hwrm_vnic_free(struct bnxt
*bp
)
4233 for (i
= 0; i
< bp
->nr_vnics
; i
++)
4234 bnxt_hwrm_vnic_free_one(bp
, i
);
4237 static int bnxt_hwrm_vnic_alloc(struct bnxt
*bp
, u16 vnic_id
,
4238 unsigned int start_rx_ring_idx
,
4239 unsigned int nr_rings
)
4242 unsigned int i
, j
, grp_idx
, end_idx
= start_rx_ring_idx
+ nr_rings
;
4243 struct hwrm_vnic_alloc_input req
= {0};
4244 struct hwrm_vnic_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4246 /* map ring groups to this vnic */
4247 for (i
= start_rx_ring_idx
, j
= 0; i
< end_idx
; i
++, j
++) {
4248 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
4249 if (bp
->grp_info
[grp_idx
].fw_grp_id
== INVALID_HW_RING_ID
) {
4250 netdev_err(bp
->dev
, "Not enough ring groups avail:%x req:%x\n",
4254 bp
->vnic_info
[vnic_id
].fw_grp_ids
[j
] =
4255 bp
->grp_info
[grp_idx
].fw_grp_id
;
4258 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[0] = INVALID_HW_RING_ID
;
4259 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[1] = INVALID_HW_RING_ID
;
4261 req
.flags
= cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT
);
4263 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_ALLOC
, -1, -1);
4265 mutex_lock(&bp
->hwrm_cmd_lock
);
4266 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4268 bp
->vnic_info
[vnic_id
].fw_vnic_id
= le32_to_cpu(resp
->vnic_id
);
4269 mutex_unlock(&bp
->hwrm_cmd_lock
);
4273 static int bnxt_hwrm_vnic_qcaps(struct bnxt
*bp
)
4275 struct hwrm_vnic_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4276 struct hwrm_vnic_qcaps_input req
= {0};
4279 if (bp
->hwrm_spec_code
< 0x10600)
4282 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_QCAPS
, -1, -1);
4283 mutex_lock(&bp
->hwrm_cmd_lock
);
4284 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4286 u32 flags
= le32_to_cpu(resp
->flags
);
4288 if (flags
& VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP
)
4289 bp
->flags
|= BNXT_FLAG_NEW_RSS_CAP
;
4291 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP
)
4292 bp
->flags
|= BNXT_FLAG_ROCE_MIRROR_CAP
;
4294 mutex_unlock(&bp
->hwrm_cmd_lock
);
4298 static int bnxt_hwrm_ring_grp_alloc(struct bnxt
*bp
)
4303 mutex_lock(&bp
->hwrm_cmd_lock
);
4304 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4305 struct hwrm_ring_grp_alloc_input req
= {0};
4306 struct hwrm_ring_grp_alloc_output
*resp
=
4307 bp
->hwrm_cmd_resp_addr
;
4308 unsigned int grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
4310 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_ALLOC
, -1, -1);
4312 req
.cr
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
4313 req
.rr
= cpu_to_le16(bp
->grp_info
[grp_idx
].rx_fw_ring_id
);
4314 req
.ar
= cpu_to_le16(bp
->grp_info
[grp_idx
].agg_fw_ring_id
);
4315 req
.sc
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_stats_ctx
);
4317 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4322 bp
->grp_info
[grp_idx
].fw_grp_id
=
4323 le32_to_cpu(resp
->ring_group_id
);
4325 mutex_unlock(&bp
->hwrm_cmd_lock
);
4329 static int bnxt_hwrm_ring_grp_free(struct bnxt
*bp
)
4333 struct hwrm_ring_grp_free_input req
= {0};
4338 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_FREE
, -1, -1);
4340 mutex_lock(&bp
->hwrm_cmd_lock
);
4341 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4342 if (bp
->grp_info
[i
].fw_grp_id
== INVALID_HW_RING_ID
)
4345 cpu_to_le32(bp
->grp_info
[i
].fw_grp_id
);
4347 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4351 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
4353 mutex_unlock(&bp
->hwrm_cmd_lock
);
4357 static int hwrm_ring_alloc_send_msg(struct bnxt
*bp
,
4358 struct bnxt_ring_struct
*ring
,
4359 u32 ring_type
, u32 map_index
)
4361 int rc
= 0, err
= 0;
4362 struct hwrm_ring_alloc_input req
= {0};
4363 struct hwrm_ring_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4364 struct bnxt_ring_mem_info
*rmem
= &ring
->ring_mem
;
4365 struct bnxt_ring_grp_info
*grp_info
;
4368 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_ALLOC
, -1, -1);
4371 if (rmem
->nr_pages
> 1) {
4372 req
.page_tbl_addr
= cpu_to_le64(rmem
->pg_tbl_map
);
4373 /* Page size is in log2 units */
4374 req
.page_size
= BNXT_PAGE_SHIFT
;
4375 req
.page_tbl_depth
= 1;
4377 req
.page_tbl_addr
= cpu_to_le64(rmem
->dma_arr
[0]);
4380 /* Association of ring index with doorbell index and MSIX number */
4381 req
.logical_id
= cpu_to_le16(map_index
);
4383 switch (ring_type
) {
4384 case HWRM_RING_ALLOC_TX
:
4385 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_TX
;
4386 /* Association of transmit ring with completion ring */
4387 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4388 req
.cmpl_ring_id
= cpu_to_le16(grp_info
->cp_fw_ring_id
);
4389 req
.length
= cpu_to_le32(bp
->tx_ring_mask
+ 1);
4390 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
4391 req
.queue_id
= cpu_to_le16(ring
->queue_id
);
4393 case HWRM_RING_ALLOC_RX
:
4394 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
4395 req
.length
= cpu_to_le32(bp
->rx_ring_mask
+ 1);
4397 case HWRM_RING_ALLOC_AGG
:
4398 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
4399 req
.length
= cpu_to_le32(bp
->rx_agg_ring_mask
+ 1);
4401 case HWRM_RING_ALLOC_CMPL
:
4402 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_L2_CMPL
;
4403 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
4404 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
4405 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
4408 netdev_err(bp
->dev
, "hwrm alloc invalid ring type %d\n",
4413 mutex_lock(&bp
->hwrm_cmd_lock
);
4414 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4415 err
= le16_to_cpu(resp
->error_code
);
4416 ring_id
= le16_to_cpu(resp
->ring_id
);
4417 mutex_unlock(&bp
->hwrm_cmd_lock
);
4420 netdev_err(bp
->dev
, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
4421 ring_type
, rc
, err
);
4424 ring
->fw_ring_id
= ring_id
;
4428 static int bnxt_hwrm_set_async_event_cr(struct bnxt
*bp
, int idx
)
4433 struct hwrm_func_cfg_input req
= {0};
4435 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
4436 req
.fid
= cpu_to_le16(0xffff);
4437 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
4438 req
.async_event_cr
= cpu_to_le16(idx
);
4439 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4441 struct hwrm_func_vf_cfg_input req
= {0};
4443 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_VF_CFG
, -1, -1);
4445 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
4446 req
.async_event_cr
= cpu_to_le16(idx
);
4447 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4452 static int bnxt_hwrm_ring_alloc(struct bnxt
*bp
)
4456 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4457 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4458 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4459 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
4460 u32 map_idx
= ring
->map_idx
;
4462 cpr
->cp_doorbell
= bp
->bar1
+ map_idx
* 0x80;
4463 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_CMPL
,
4467 BNXT_CP_DB(cpr
->cp_doorbell
, cpr
->cp_raw_cons
);
4468 bp
->grp_info
[i
].cp_fw_ring_id
= ring
->fw_ring_id
;
4471 rc
= bnxt_hwrm_set_async_event_cr(bp
, ring
->fw_ring_id
);
4473 netdev_warn(bp
->dev
, "Failed to set async event completion ring.\n");
4477 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
4478 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
4479 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
4482 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_TX
,
4486 txr
->tx_doorbell
= bp
->bar1
+ map_idx
* 0x80;
4489 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4490 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
4491 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
4492 u32 map_idx
= rxr
->bnapi
->index
;
4494 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, HWRM_RING_ALLOC_RX
,
4498 rxr
->rx_doorbell
= bp
->bar1
+ map_idx
* 0x80;
4499 writel(DB_KEY_RX
| rxr
->rx_prod
, rxr
->rx_doorbell
);
4500 bp
->grp_info
[map_idx
].rx_fw_ring_id
= ring
->fw_ring_id
;
4503 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
4504 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4505 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
4506 struct bnxt_ring_struct
*ring
=
4507 &rxr
->rx_agg_ring_struct
;
4508 u32 grp_idx
= ring
->grp_idx
;
4509 u32 map_idx
= grp_idx
+ bp
->rx_nr_rings
;
4511 rc
= hwrm_ring_alloc_send_msg(bp
, ring
,
4512 HWRM_RING_ALLOC_AGG
,
4517 rxr
->rx_agg_doorbell
= bp
->bar1
+ map_idx
* 0x80;
4518 writel(DB_KEY_RX
| rxr
->rx_agg_prod
,
4519 rxr
->rx_agg_doorbell
);
4520 bp
->grp_info
[grp_idx
].agg_fw_ring_id
= ring
->fw_ring_id
;
4527 static int hwrm_ring_free_send_msg(struct bnxt
*bp
,
4528 struct bnxt_ring_struct
*ring
,
4529 u32 ring_type
, int cmpl_ring_id
)
4532 struct hwrm_ring_free_input req
= {0};
4533 struct hwrm_ring_free_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4536 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_FREE
, cmpl_ring_id
, -1);
4537 req
.ring_type
= ring_type
;
4538 req
.ring_id
= cpu_to_le16(ring
->fw_ring_id
);
4540 mutex_lock(&bp
->hwrm_cmd_lock
);
4541 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4542 error_code
= le16_to_cpu(resp
->error_code
);
4543 mutex_unlock(&bp
->hwrm_cmd_lock
);
4545 if (rc
|| error_code
) {
4546 netdev_err(bp
->dev
, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
4547 ring_type
, rc
, error_code
);
4553 static void bnxt_hwrm_ring_free(struct bnxt
*bp
, bool close_path
)
4560 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
4561 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
4562 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
4563 u32 grp_idx
= txr
->bnapi
->index
;
4564 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
4566 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
4567 hwrm_ring_free_send_msg(bp
, ring
,
4568 RING_FREE_REQ_RING_TYPE_TX
,
4569 close_path
? cmpl_ring_id
:
4570 INVALID_HW_RING_ID
);
4571 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
4575 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4576 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
4577 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
4578 u32 grp_idx
= rxr
->bnapi
->index
;
4579 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
4581 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
4582 hwrm_ring_free_send_msg(bp
, ring
,
4583 RING_FREE_REQ_RING_TYPE_RX
,
4584 close_path
? cmpl_ring_id
:
4585 INVALID_HW_RING_ID
);
4586 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
4587 bp
->grp_info
[grp_idx
].rx_fw_ring_id
=
4592 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4593 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
4594 struct bnxt_ring_struct
*ring
= &rxr
->rx_agg_ring_struct
;
4595 u32 grp_idx
= rxr
->bnapi
->index
;
4596 u32 cmpl_ring_id
= bp
->grp_info
[grp_idx
].cp_fw_ring_id
;
4598 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
4599 hwrm_ring_free_send_msg(bp
, ring
,
4600 RING_FREE_REQ_RING_TYPE_RX
,
4601 close_path
? cmpl_ring_id
:
4602 INVALID_HW_RING_ID
);
4603 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
4604 bp
->grp_info
[grp_idx
].agg_fw_ring_id
=
4609 /* The completion rings are about to be freed. After that the
4610 * IRQ doorbell will not work anymore. So we need to disable
4613 bnxt_disable_int_sync(bp
);
4615 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4616 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4617 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4618 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
4620 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
4621 hwrm_ring_free_send_msg(bp
, ring
,
4622 RING_FREE_REQ_RING_TYPE_L2_CMPL
,
4623 INVALID_HW_RING_ID
);
4624 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
4625 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
4630 static int bnxt_hwrm_get_rings(struct bnxt
*bp
)
4632 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4633 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
4634 struct hwrm_func_qcfg_input req
= {0};
4637 if (bp
->hwrm_spec_code
< 0x10601)
4640 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
4641 req
.fid
= cpu_to_le16(0xffff);
4642 mutex_lock(&bp
->hwrm_cmd_lock
);
4643 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4645 mutex_unlock(&bp
->hwrm_cmd_lock
);
4649 hw_resc
->resv_tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
4650 if (BNXT_NEW_RM(bp
)) {
4653 hw_resc
->resv_rx_rings
= le16_to_cpu(resp
->alloc_rx_rings
);
4654 hw_resc
->resv_hw_ring_grps
=
4655 le32_to_cpu(resp
->alloc_hw_ring_grps
);
4656 hw_resc
->resv_vnics
= le16_to_cpu(resp
->alloc_vnics
);
4657 cp
= le16_to_cpu(resp
->alloc_cmpl_rings
);
4658 stats
= le16_to_cpu(resp
->alloc_stat_ctx
);
4659 cp
= min_t(u16
, cp
, stats
);
4660 hw_resc
->resv_cp_rings
= cp
;
4662 mutex_unlock(&bp
->hwrm_cmd_lock
);
4666 /* Caller must hold bp->hwrm_cmd_lock */
4667 int __bnxt_hwrm_get_tx_rings(struct bnxt
*bp
, u16 fid
, int *tx_rings
)
4669 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4670 struct hwrm_func_qcfg_input req
= {0};
4673 if (bp
->hwrm_spec_code
< 0x10601)
4676 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
4677 req
.fid
= cpu_to_le16(fid
);
4678 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4680 *tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
4686 __bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, struct hwrm_func_cfg_input
*req
,
4687 int tx_rings
, int rx_rings
, int ring_grps
,
4688 int cp_rings
, int vnics
)
4692 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_CFG
, -1, -1);
4693 req
->fid
= cpu_to_le16(0xffff);
4694 enables
|= tx_rings
? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
4695 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
4696 if (BNXT_NEW_RM(bp
)) {
4697 enables
|= rx_rings
? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS
: 0;
4698 enables
|= cp_rings
? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
4699 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
4700 enables
|= ring_grps
?
4701 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
: 0;
4702 enables
|= vnics
? FUNC_CFG_REQ_ENABLES_NUM_VNICS
: 0;
4704 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
4705 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
4706 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
4707 req
->num_stat_ctxs
= req
->num_cmpl_rings
;
4708 req
->num_vnics
= cpu_to_le16(vnics
);
4710 req
->enables
= cpu_to_le32(enables
);
4714 __bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
,
4715 struct hwrm_func_vf_cfg_input
*req
, int tx_rings
,
4716 int rx_rings
, int ring_grps
, int cp_rings
,
4721 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_VF_CFG
, -1, -1);
4722 enables
|= tx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
4723 enables
|= rx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS
: 0;
4724 enables
|= cp_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
4725 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
4726 enables
|= ring_grps
? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
: 0;
4727 enables
|= vnics
? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS
: 0;
4729 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
4730 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
4731 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
4732 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
4733 req
->num_stat_ctxs
= req
->num_cmpl_rings
;
4734 req
->num_vnics
= cpu_to_le16(vnics
);
4736 req
->enables
= cpu_to_le32(enables
);
4740 bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
4741 int ring_grps
, int cp_rings
, int vnics
)
4743 struct hwrm_func_cfg_input req
= {0};
4746 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
4751 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4755 if (bp
->hwrm_spec_code
< 0x10601)
4756 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
4758 rc
= bnxt_hwrm_get_rings(bp
);
4763 bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
4764 int ring_grps
, int cp_rings
, int vnics
)
4766 struct hwrm_func_vf_cfg_input req
= {0};
4769 if (!BNXT_NEW_RM(bp
)) {
4770 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
4774 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
4776 req
.enables
|= cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
|
4777 FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS
);
4778 req
.num_rsscos_ctxs
= cpu_to_le16(BNXT_VF_MAX_RSS_CTX
);
4779 req
.num_l2_ctxs
= cpu_to_le16(BNXT_VF_MAX_L2_CTX
);
4780 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4784 rc
= bnxt_hwrm_get_rings(bp
);
4788 static int bnxt_hwrm_reserve_rings(struct bnxt
*bp
, int tx
, int rx
, int grp
,
4792 return bnxt_hwrm_reserve_pf_rings(bp
, tx
, rx
, grp
, cp
, vnic
);
4794 return bnxt_hwrm_reserve_vf_rings(bp
, tx
, rx
, grp
, cp
, vnic
);
4797 static int bnxt_cp_rings_in_use(struct bnxt
*bp
)
4799 int cp
= bp
->cp_nr_rings
;
4800 int ulp_msix
, ulp_base
;
4802 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
4804 ulp_base
= bnxt_get_ulp_msix_base(bp
);
4806 if ((ulp_base
+ ulp_msix
) > cp
)
4807 cp
= ulp_base
+ ulp_msix
;
4812 static bool bnxt_need_reserve_rings(struct bnxt
*bp
)
4814 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
4815 int cp
= bnxt_cp_rings_in_use(bp
);
4816 int rx
= bp
->rx_nr_rings
;
4817 int vnic
= 1, grp
= rx
;
4819 if (bp
->hwrm_spec_code
< 0x10601)
4822 if (hw_resc
->resv_tx_rings
!= bp
->tx_nr_rings
)
4825 if (bp
->flags
& BNXT_FLAG_RFS
)
4827 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
4829 if (BNXT_NEW_RM(bp
) &&
4830 (hw_resc
->resv_rx_rings
!= rx
|| hw_resc
->resv_cp_rings
!= cp
||
4831 hw_resc
->resv_hw_ring_grps
!= grp
|| hw_resc
->resv_vnics
!= vnic
))
4836 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
4839 static int __bnxt_reserve_rings(struct bnxt
*bp
)
4841 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
4842 int cp
= bnxt_cp_rings_in_use(bp
);
4843 int tx
= bp
->tx_nr_rings
;
4844 int rx
= bp
->rx_nr_rings
;
4845 int grp
, rx_rings
, rc
;
4849 if (!bnxt_need_reserve_rings(bp
))
4852 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
4854 if (bp
->flags
& BNXT_FLAG_RFS
)
4856 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
4858 grp
= bp
->rx_nr_rings
;
4860 rc
= bnxt_hwrm_reserve_rings(bp
, tx
, rx
, grp
, cp
, vnic
);
4864 tx
= hw_resc
->resv_tx_rings
;
4865 if (BNXT_NEW_RM(bp
)) {
4866 rx
= hw_resc
->resv_rx_rings
;
4867 cp
= hw_resc
->resv_cp_rings
;
4868 grp
= hw_resc
->resv_hw_ring_grps
;
4869 vnic
= hw_resc
->resv_vnics
;
4873 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
4877 if (netif_running(bp
->dev
))
4880 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
4881 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
4882 bp
->dev
->hw_features
&= ~NETIF_F_LRO
;
4883 bp
->dev
->features
&= ~NETIF_F_LRO
;
4884 bnxt_set_ring_params(bp
);
4887 rx_rings
= min_t(int, rx_rings
, grp
);
4888 rc
= bnxt_trim_rings(bp
, &rx_rings
, &tx
, cp
, sh
);
4889 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
4891 cp
= sh
? max_t(int, tx
, rx_rings
) : tx
+ rx_rings
;
4892 bp
->tx_nr_rings
= tx
;
4893 bp
->rx_nr_rings
= rx_rings
;
4894 bp
->cp_nr_rings
= cp
;
4896 if (!tx
|| !rx
|| !cp
|| !grp
|| !vnic
)
4902 static int bnxt_hwrm_check_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
4903 int ring_grps
, int cp_rings
, int vnics
)
4905 struct hwrm_func_vf_cfg_input req
= {0};
4909 if (!BNXT_NEW_RM(bp
))
4912 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
4914 flags
= FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST
|
4915 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
4916 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
4917 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
|
4918 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
4919 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
;
4921 req
.flags
= cpu_to_le32(flags
);
4922 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4928 static int bnxt_hwrm_check_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
4929 int ring_grps
, int cp_rings
, int vnics
)
4931 struct hwrm_func_cfg_input req
= {0};
4935 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
4937 flags
= FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST
;
4938 if (BNXT_NEW_RM(bp
))
4939 flags
|= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
4940 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
4941 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
|
4942 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
4943 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
;
4945 req
.flags
= cpu_to_le32(flags
);
4946 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4952 static int bnxt_hwrm_check_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
4953 int ring_grps
, int cp_rings
, int vnics
)
4955 if (bp
->hwrm_spec_code
< 0x10801)
4959 return bnxt_hwrm_check_pf_rings(bp
, tx_rings
, rx_rings
,
4960 ring_grps
, cp_rings
, vnics
);
4962 return bnxt_hwrm_check_vf_rings(bp
, tx_rings
, rx_rings
, ring_grps
,
4966 static void bnxt_hwrm_coal_params_qcaps(struct bnxt
*bp
)
4968 struct hwrm_ring_aggint_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4969 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
4970 struct hwrm_ring_aggint_qcaps_input req
= {0};
4973 coal_cap
->cmpl_params
= BNXT_LEGACY_COAL_CMPL_PARAMS
;
4974 coal_cap
->num_cmpl_dma_aggr_max
= 63;
4975 coal_cap
->num_cmpl_dma_aggr_during_int_max
= 63;
4976 coal_cap
->cmpl_aggr_dma_tmr_max
= 65535;
4977 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
= 65535;
4978 coal_cap
->int_lat_tmr_min_max
= 65535;
4979 coal_cap
->int_lat_tmr_max_max
= 65535;
4980 coal_cap
->num_cmpl_aggr_int_max
= 65535;
4981 coal_cap
->timer_units
= 80;
4983 if (bp
->hwrm_spec_code
< 0x10902)
4986 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_AGGINT_QCAPS
, -1, -1);
4987 mutex_lock(&bp
->hwrm_cmd_lock
);
4988 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4990 coal_cap
->cmpl_params
= le32_to_cpu(resp
->cmpl_params
);
4991 coal_cap
->num_cmpl_dma_aggr_max
=
4992 le16_to_cpu(resp
->num_cmpl_dma_aggr_max
);
4993 coal_cap
->num_cmpl_dma_aggr_during_int_max
=
4994 le16_to_cpu(resp
->num_cmpl_dma_aggr_during_int_max
);
4995 coal_cap
->cmpl_aggr_dma_tmr_max
=
4996 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_max
);
4997 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
=
4998 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_during_int_max
);
4999 coal_cap
->int_lat_tmr_min_max
=
5000 le16_to_cpu(resp
->int_lat_tmr_min_max
);
5001 coal_cap
->int_lat_tmr_max_max
=
5002 le16_to_cpu(resp
->int_lat_tmr_max_max
);
5003 coal_cap
->num_cmpl_aggr_int_max
=
5004 le16_to_cpu(resp
->num_cmpl_aggr_int_max
);
5005 coal_cap
->timer_units
= le16_to_cpu(resp
->timer_units
);
5007 mutex_unlock(&bp
->hwrm_cmd_lock
);
5010 static u16
bnxt_usec_to_coal_tmr(struct bnxt
*bp
, u16 usec
)
5012 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5014 return usec
* 1000 / coal_cap
->timer_units
;
5017 static void bnxt_hwrm_set_coal_params(struct bnxt
*bp
,
5018 struct bnxt_coal
*hw_coal
,
5019 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input
*req
)
5021 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5022 u32 cmpl_params
= coal_cap
->cmpl_params
;
5023 u16 val
, tmr
, max
, flags
= 0;
5025 max
= hw_coal
->bufs_per_record
* 128;
5026 if (hw_coal
->budget
)
5027 max
= hw_coal
->bufs_per_record
* hw_coal
->budget
;
5028 max
= min_t(u16
, max
, coal_cap
->num_cmpl_aggr_int_max
);
5030 val
= clamp_t(u16
, hw_coal
->coal_bufs
, 1, max
);
5031 req
->num_cmpl_aggr_int
= cpu_to_le16(val
);
5033 val
= min_t(u16
, val
, coal_cap
->num_cmpl_dma_aggr_max
);
5034 req
->num_cmpl_dma_aggr
= cpu_to_le16(val
);
5036 val
= clamp_t(u16
, hw_coal
->coal_bufs_irq
, 1,
5037 coal_cap
->num_cmpl_dma_aggr_during_int_max
);
5038 req
->num_cmpl_dma_aggr_during_int
= cpu_to_le16(val
);
5040 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
);
5041 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_max_max
);
5042 req
->int_lat_tmr_max
= cpu_to_le16(tmr
);
5044 /* min timer set to 1/2 of interrupt timer */
5045 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN
) {
5047 val
= clamp_t(u16
, val
, 1, coal_cap
->int_lat_tmr_min_max
);
5048 req
->int_lat_tmr_min
= cpu_to_le16(val
);
5049 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
5052 /* buf timer set to 1/4 of interrupt timer */
5053 val
= clamp_t(u16
, tmr
/ 4, 1, coal_cap
->cmpl_aggr_dma_tmr_max
);
5054 req
->cmpl_aggr_dma_tmr
= cpu_to_le16(val
);
5057 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT
) {
5058 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks_irq
);
5059 val
= clamp_t(u16
, tmr
, 1,
5060 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
);
5061 req
->cmpl_aggr_dma_tmr_during_int
= cpu_to_le16(tmr
);
5063 cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE
);
5066 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET
)
5067 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
5068 if ((cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE
) &&
5069 hw_coal
->idle_thresh
&& hw_coal
->coal_ticks
< hw_coal
->idle_thresh
)
5070 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE
;
5071 req
->flags
= cpu_to_le16(flags
);
5072 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_ENABLES
);
5075 int bnxt_hwrm_set_ring_coal(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
5077 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0};
5078 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5079 struct bnxt_coal coal
;
5080 unsigned int grp_idx
;
5082 /* Tick values in micro seconds.
5083 * 1 coal_buf x bufs_per_record = 1 completion record.
5085 memcpy(&coal
, &bp
->rx_coal
, sizeof(struct bnxt_coal
));
5087 coal
.coal_ticks
= cpr
->rx_ring_coal
.coal_ticks
;
5088 coal
.coal_bufs
= cpr
->rx_ring_coal
.coal_bufs
;
5090 if (!bnapi
->rx_ring
)
5093 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
5094 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5096 bnxt_hwrm_set_coal_params(bp
, &coal
, &req_rx
);
5098 grp_idx
= bnapi
->index
;
5099 req_rx
.ring_id
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
5101 return hwrm_send_message(bp
, &req_rx
, sizeof(req_rx
),
5105 int bnxt_hwrm_set_coal(struct bnxt
*bp
)
5108 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0},
5111 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
5112 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5113 bnxt_hwrm_cmd_hdr_init(bp
, &req_tx
,
5114 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5116 bnxt_hwrm_set_coal_params(bp
, &bp
->rx_coal
, &req_rx
);
5117 bnxt_hwrm_set_coal_params(bp
, &bp
->tx_coal
, &req_tx
);
5119 mutex_lock(&bp
->hwrm_cmd_lock
);
5120 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5121 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5124 if (!bnapi
->rx_ring
)
5126 req
->ring_id
= cpu_to_le16(bp
->grp_info
[i
].cp_fw_ring_id
);
5128 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
5133 mutex_unlock(&bp
->hwrm_cmd_lock
);
5137 static int bnxt_hwrm_stat_ctx_free(struct bnxt
*bp
)
5140 struct hwrm_stat_ctx_free_input req
= {0};
5145 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5148 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_FREE
, -1, -1);
5150 mutex_lock(&bp
->hwrm_cmd_lock
);
5151 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5152 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5153 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5155 if (cpr
->hw_stats_ctx_id
!= INVALID_STATS_CTX_ID
) {
5156 req
.stat_ctx_id
= cpu_to_le32(cpr
->hw_stats_ctx_id
);
5158 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5163 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
5166 mutex_unlock(&bp
->hwrm_cmd_lock
);
5170 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt
*bp
)
5173 struct hwrm_stat_ctx_alloc_input req
= {0};
5174 struct hwrm_stat_ctx_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5176 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5179 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_ALLOC
, -1, -1);
5181 req
.update_period_ms
= cpu_to_le32(bp
->stats_coal_ticks
/ 1000);
5183 mutex_lock(&bp
->hwrm_cmd_lock
);
5184 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5185 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5186 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5188 req
.stats_dma_addr
= cpu_to_le64(cpr
->hw_stats_map
);
5190 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5195 cpr
->hw_stats_ctx_id
= le32_to_cpu(resp
->stat_ctx_id
);
5197 bp
->grp_info
[i
].fw_stats_ctx
= cpr
->hw_stats_ctx_id
;
5199 mutex_unlock(&bp
->hwrm_cmd_lock
);
5203 static int bnxt_hwrm_func_qcfg(struct bnxt
*bp
)
5205 struct hwrm_func_qcfg_input req
= {0};
5206 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5210 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5211 req
.fid
= cpu_to_le16(0xffff);
5212 mutex_lock(&bp
->hwrm_cmd_lock
);
5213 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5215 goto func_qcfg_exit
;
5217 #ifdef CONFIG_BNXT_SRIOV
5219 struct bnxt_vf_info
*vf
= &bp
->vf
;
5221 vf
->vlan
= le16_to_cpu(resp
->vlan
) & VLAN_VID_MASK
;
5224 flags
= le16_to_cpu(resp
->flags
);
5225 if (flags
& (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
|
5226 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED
)) {
5227 bp
->fw_cap
|= BNXT_FW_CAP_LLDP_AGENT
;
5228 if (flags
& FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
)
5229 bp
->fw_cap
|= BNXT_FW_CAP_DCBX_AGENT
;
5231 if (BNXT_PF(bp
) && (flags
& FUNC_QCFG_RESP_FLAGS_MULTI_HOST
))
5232 bp
->flags
|= BNXT_FLAG_MULTI_HOST
;
5234 switch (resp
->port_partition_type
) {
5235 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0
:
5236 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5
:
5237 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0
:
5238 bp
->port_partition_type
= resp
->port_partition_type
;
5241 if (bp
->hwrm_spec_code
< 0x10707 ||
5242 resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEB
)
5243 bp
->br_mode
= BRIDGE_MODE_VEB
;
5244 else if (resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEPA
)
5245 bp
->br_mode
= BRIDGE_MODE_VEPA
;
5247 bp
->br_mode
= BRIDGE_MODE_UNDEF
;
5249 bp
->max_mtu
= le16_to_cpu(resp
->max_mtu_configured
);
5251 bp
->max_mtu
= BNXT_MAX_MTU
;
5254 mutex_unlock(&bp
->hwrm_cmd_lock
);
5258 static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt
*bp
)
5260 struct hwrm_func_backing_store_qcaps_input req
= {0};
5261 struct hwrm_func_backing_store_qcaps_output
*resp
=
5262 bp
->hwrm_cmd_resp_addr
;
5265 if (bp
->hwrm_spec_code
< 0x10902 || BNXT_VF(bp
) || bp
->ctx
)
5268 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_QCAPS
, -1, -1);
5269 mutex_lock(&bp
->hwrm_cmd_lock
);
5270 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5272 struct bnxt_ctx_pg_info
*ctx_pg
;
5273 struct bnxt_ctx_mem_info
*ctx
;
5276 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
5281 ctx_pg
= kzalloc(sizeof(*ctx_pg
) * (bp
->max_q
+ 1), GFP_KERNEL
);
5287 for (i
= 0; i
< bp
->max_q
+ 1; i
++, ctx_pg
++)
5288 ctx
->tqm_mem
[i
] = ctx_pg
;
5291 ctx
->qp_max_entries
= le32_to_cpu(resp
->qp_max_entries
);
5292 ctx
->qp_min_qp1_entries
= le16_to_cpu(resp
->qp_min_qp1_entries
);
5293 ctx
->qp_max_l2_entries
= le16_to_cpu(resp
->qp_max_l2_entries
);
5294 ctx
->qp_entry_size
= le16_to_cpu(resp
->qp_entry_size
);
5295 ctx
->srq_max_l2_entries
= le16_to_cpu(resp
->srq_max_l2_entries
);
5296 ctx
->srq_max_entries
= le32_to_cpu(resp
->srq_max_entries
);
5297 ctx
->srq_entry_size
= le16_to_cpu(resp
->srq_entry_size
);
5298 ctx
->cq_max_l2_entries
= le16_to_cpu(resp
->cq_max_l2_entries
);
5299 ctx
->cq_max_entries
= le32_to_cpu(resp
->cq_max_entries
);
5300 ctx
->cq_entry_size
= le16_to_cpu(resp
->cq_entry_size
);
5301 ctx
->vnic_max_vnic_entries
=
5302 le16_to_cpu(resp
->vnic_max_vnic_entries
);
5303 ctx
->vnic_max_ring_table_entries
=
5304 le16_to_cpu(resp
->vnic_max_ring_table_entries
);
5305 ctx
->vnic_entry_size
= le16_to_cpu(resp
->vnic_entry_size
);
5306 ctx
->stat_max_entries
= le32_to_cpu(resp
->stat_max_entries
);
5307 ctx
->stat_entry_size
= le16_to_cpu(resp
->stat_entry_size
);
5308 ctx
->tqm_entry_size
= le16_to_cpu(resp
->tqm_entry_size
);
5309 ctx
->tqm_min_entries_per_ring
=
5310 le32_to_cpu(resp
->tqm_min_entries_per_ring
);
5311 ctx
->tqm_max_entries_per_ring
=
5312 le32_to_cpu(resp
->tqm_max_entries_per_ring
);
5313 ctx
->tqm_entries_multiple
= resp
->tqm_entries_multiple
;
5314 if (!ctx
->tqm_entries_multiple
)
5315 ctx
->tqm_entries_multiple
= 1;
5316 ctx
->mrav_max_entries
= le32_to_cpu(resp
->mrav_max_entries
);
5317 ctx
->mrav_entry_size
= le16_to_cpu(resp
->mrav_entry_size
);
5318 ctx
->tim_entry_size
= le16_to_cpu(resp
->tim_entry_size
);
5319 ctx
->tim_max_entries
= le32_to_cpu(resp
->tim_max_entries
);
5324 mutex_unlock(&bp
->hwrm_cmd_lock
);
5328 static int bnxt_alloc_ctx_mem_blk(struct bnxt
*bp
,
5329 struct bnxt_ctx_pg_info
*ctx_pg
, u32 mem_size
)
5331 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
5336 rmem
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
5337 if (rmem
->nr_pages
> MAX_CTX_PAGES
) {
5341 rmem
->page_size
= BNXT_PAGE_SIZE
;
5342 rmem
->pg_arr
= ctx_pg
->ctx_pg_arr
;
5343 rmem
->dma_arr
= ctx_pg
->ctx_dma_arr
;
5344 return bnxt_alloc_ring(bp
, rmem
);
5347 static void bnxt_free_ctx_mem(struct bnxt
*bp
)
5349 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
5355 if (ctx
->tqm_mem
[0]) {
5356 for (i
= 0; i
< bp
->max_q
+ 1; i
++)
5357 bnxt_free_ring(bp
, &ctx
->tqm_mem
[i
]->ring_mem
);
5358 kfree(ctx
->tqm_mem
[0]);
5359 ctx
->tqm_mem
[0] = NULL
;
5362 bnxt_free_ring(bp
, &ctx
->stat_mem
.ring_mem
);
5363 bnxt_free_ring(bp
, &ctx
->vnic_mem
.ring_mem
);
5364 bnxt_free_ring(bp
, &ctx
->cq_mem
.ring_mem
);
5365 bnxt_free_ring(bp
, &ctx
->srq_mem
.ring_mem
);
5366 bnxt_free_ring(bp
, &ctx
->qp_mem
.ring_mem
);
5367 ctx
->flags
&= ~BNXT_CTX_FLAG_INITED
;
5370 static int bnxt_alloc_ctx_mem(struct bnxt
*bp
)
5372 struct bnxt_ctx_pg_info
*ctx_pg
;
5373 struct bnxt_ctx_mem_info
*ctx
;
5374 u32 mem_size
, entries
;
5377 rc
= bnxt_hwrm_func_backing_store_qcaps(bp
);
5379 netdev_err(bp
->dev
, "Failed querying context mem capability, rc = %d.\n",
5384 if (!ctx
|| (ctx
->flags
& BNXT_CTX_FLAG_INITED
))
5387 ctx_pg
= &ctx
->qp_mem
;
5388 ctx_pg
->entries
= ctx
->qp_min_qp1_entries
+ ctx
->qp_max_l2_entries
;
5389 mem_size
= ctx
->qp_entry_size
* ctx_pg
->entries
;
5390 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5394 ctx_pg
= &ctx
->srq_mem
;
5395 ctx_pg
->entries
= ctx
->srq_max_l2_entries
;
5396 mem_size
= ctx
->srq_entry_size
* ctx_pg
->entries
;
5397 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5401 ctx_pg
= &ctx
->cq_mem
;
5402 ctx_pg
->entries
= ctx
->cq_max_l2_entries
;
5403 mem_size
= ctx
->cq_entry_size
* ctx_pg
->entries
;
5404 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5408 ctx_pg
= &ctx
->vnic_mem
;
5409 ctx_pg
->entries
= ctx
->vnic_max_vnic_entries
+
5410 ctx
->vnic_max_ring_table_entries
;
5411 mem_size
= ctx
->vnic_entry_size
* ctx_pg
->entries
;
5412 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5416 ctx_pg
= &ctx
->stat_mem
;
5417 ctx_pg
->entries
= ctx
->stat_max_entries
;
5418 mem_size
= ctx
->stat_entry_size
* ctx_pg
->entries
;
5419 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5423 entries
= ctx
->qp_max_l2_entries
;
5424 entries
= roundup(entries
, ctx
->tqm_entries_multiple
);
5425 entries
= clamp_t(u32
, entries
, ctx
->tqm_min_entries_per_ring
,
5426 ctx
->tqm_max_entries_per_ring
);
5427 for (i
= 0; i
< bp
->max_q
+ 1; i
++) {
5428 ctx_pg
= ctx
->tqm_mem
[i
];
5429 ctx_pg
->entries
= entries
;
5430 mem_size
= ctx
->tqm_entry_size
* entries
;
5431 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
, mem_size
);
5435 ctx
->flags
|= BNXT_CTX_FLAG_INITED
;
5439 int bnxt_hwrm_func_resc_qcaps(struct bnxt
*bp
, bool all
)
5441 struct hwrm_func_resource_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5442 struct hwrm_func_resource_qcaps_input req
= {0};
5443 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5446 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESOURCE_QCAPS
, -1, -1);
5447 req
.fid
= cpu_to_le16(0xffff);
5449 mutex_lock(&bp
->hwrm_cmd_lock
);
5450 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5453 goto hwrm_func_resc_qcaps_exit
;
5456 hw_resc
->max_tx_sch_inputs
= le16_to_cpu(resp
->max_tx_scheduler_inputs
);
5458 goto hwrm_func_resc_qcaps_exit
;
5460 hw_resc
->min_rsscos_ctxs
= le16_to_cpu(resp
->min_rsscos_ctx
);
5461 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
5462 hw_resc
->min_cp_rings
= le16_to_cpu(resp
->min_cmpl_rings
);
5463 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
5464 hw_resc
->min_tx_rings
= le16_to_cpu(resp
->min_tx_rings
);
5465 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
5466 hw_resc
->min_rx_rings
= le16_to_cpu(resp
->min_rx_rings
);
5467 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
5468 hw_resc
->min_hw_ring_grps
= le16_to_cpu(resp
->min_hw_ring_grps
);
5469 hw_resc
->max_hw_ring_grps
= le16_to_cpu(resp
->max_hw_ring_grps
);
5470 hw_resc
->min_l2_ctxs
= le16_to_cpu(resp
->min_l2_ctxs
);
5471 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
5472 hw_resc
->min_vnics
= le16_to_cpu(resp
->min_vnics
);
5473 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
5474 hw_resc
->min_stat_ctxs
= le16_to_cpu(resp
->min_stat_ctx
);
5475 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
5478 struct bnxt_pf_info
*pf
= &bp
->pf
;
5480 pf
->vf_resv_strategy
=
5481 le16_to_cpu(resp
->vf_reservation_strategy
);
5482 if (pf
->vf_resv_strategy
> BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC
)
5483 pf
->vf_resv_strategy
= BNXT_VF_RESV_STRATEGY_MAXIMAL
;
5485 hwrm_func_resc_qcaps_exit
:
5486 mutex_unlock(&bp
->hwrm_cmd_lock
);
5490 static int __bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
5493 struct hwrm_func_qcaps_input req
= {0};
5494 struct hwrm_func_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5495 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5498 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCAPS
, -1, -1);
5499 req
.fid
= cpu_to_le16(0xffff);
5501 mutex_lock(&bp
->hwrm_cmd_lock
);
5502 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5504 goto hwrm_func_qcaps_exit
;
5506 flags
= le32_to_cpu(resp
->flags
);
5507 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED
)
5508 bp
->flags
|= BNXT_FLAG_ROCEV1_CAP
;
5509 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED
)
5510 bp
->flags
|= BNXT_FLAG_ROCEV2_CAP
;
5512 bp
->tx_push_thresh
= 0;
5513 if (flags
& FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED
)
5514 bp
->tx_push_thresh
= BNXT_TX_PUSH_THRESH
;
5516 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
5517 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
5518 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
5519 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
5520 hw_resc
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
5521 if (!hw_resc
->max_hw_ring_grps
)
5522 hw_resc
->max_hw_ring_grps
= hw_resc
->max_tx_rings
;
5523 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
5524 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
5525 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
5528 struct bnxt_pf_info
*pf
= &bp
->pf
;
5530 pf
->fw_fid
= le16_to_cpu(resp
->fid
);
5531 pf
->port_id
= le16_to_cpu(resp
->port_id
);
5532 bp
->dev
->dev_port
= pf
->port_id
;
5533 memcpy(pf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
5534 pf
->first_vf_id
= le16_to_cpu(resp
->first_vf_id
);
5535 pf
->max_vfs
= le16_to_cpu(resp
->max_vfs
);
5536 pf
->max_encap_records
= le32_to_cpu(resp
->max_encap_records
);
5537 pf
->max_decap_records
= le32_to_cpu(resp
->max_decap_records
);
5538 pf
->max_tx_em_flows
= le32_to_cpu(resp
->max_tx_em_flows
);
5539 pf
->max_tx_wm_flows
= le32_to_cpu(resp
->max_tx_wm_flows
);
5540 pf
->max_rx_em_flows
= le32_to_cpu(resp
->max_rx_em_flows
);
5541 pf
->max_rx_wm_flows
= le32_to_cpu(resp
->max_rx_wm_flows
);
5542 if (flags
& FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED
)
5543 bp
->flags
|= BNXT_FLAG_WOL_CAP
;
5545 #ifdef CONFIG_BNXT_SRIOV
5546 struct bnxt_vf_info
*vf
= &bp
->vf
;
5548 vf
->fw_fid
= le16_to_cpu(resp
->fid
);
5549 memcpy(vf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
5553 hwrm_func_qcaps_exit
:
5554 mutex_unlock(&bp
->hwrm_cmd_lock
);
5558 static int bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
5562 rc
= __bnxt_hwrm_func_qcaps(bp
);
5565 if (bp
->hwrm_spec_code
>= 0x10803) {
5566 rc
= bnxt_alloc_ctx_mem(bp
);
5569 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
5571 bp
->fw_cap
|= BNXT_FW_CAP_NEW_RM
;
5576 static int bnxt_hwrm_func_reset(struct bnxt
*bp
)
5578 struct hwrm_func_reset_input req
= {0};
5580 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESET
, -1, -1);
5583 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_RESET_TIMEOUT
);
5586 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
)
5589 struct hwrm_queue_qportcfg_input req
= {0};
5590 struct hwrm_queue_qportcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5594 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_QUEUE_QPORTCFG
, -1, -1);
5596 mutex_lock(&bp
->hwrm_cmd_lock
);
5597 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5601 if (!resp
->max_configurable_queues
) {
5605 bp
->max_tc
= resp
->max_configurable_queues
;
5606 bp
->max_lltc
= resp
->max_configurable_lossless_queues
;
5607 if (bp
->max_tc
> BNXT_MAX_QUEUE
)
5608 bp
->max_tc
= BNXT_MAX_QUEUE
;
5610 no_rdma
= !(bp
->flags
& BNXT_FLAG_ROCE_CAP
);
5611 qptr
= &resp
->queue_id0
;
5612 for (i
= 0, j
= 0; i
< bp
->max_tc
; i
++) {
5613 bp
->q_info
[j
].queue_id
= *qptr
;
5614 bp
->q_ids
[i
] = *qptr
++;
5615 bp
->q_info
[j
].queue_profile
= *qptr
++;
5616 bp
->tc_to_qidx
[j
] = j
;
5617 if (!BNXT_CNPQ(bp
->q_info
[j
].queue_profile
) ||
5618 (no_rdma
&& BNXT_PF(bp
)))
5621 bp
->max_q
= bp
->max_tc
;
5622 bp
->max_tc
= max_t(u8
, j
, 1);
5624 if (resp
->queue_cfg_info
& QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG
)
5627 if (bp
->max_lltc
> bp
->max_tc
)
5628 bp
->max_lltc
= bp
->max_tc
;
5631 mutex_unlock(&bp
->hwrm_cmd_lock
);
5635 static int bnxt_hwrm_ver_get(struct bnxt
*bp
)
5638 struct hwrm_ver_get_input req
= {0};
5639 struct hwrm_ver_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5642 bp
->hwrm_max_req_len
= HWRM_MAX_REQ_LEN
;
5643 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VER_GET
, -1, -1);
5644 req
.hwrm_intf_maj
= HWRM_VERSION_MAJOR
;
5645 req
.hwrm_intf_min
= HWRM_VERSION_MINOR
;
5646 req
.hwrm_intf_upd
= HWRM_VERSION_UPDATE
;
5647 mutex_lock(&bp
->hwrm_cmd_lock
);
5648 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5650 goto hwrm_ver_get_exit
;
5652 memcpy(&bp
->ver_resp
, resp
, sizeof(struct hwrm_ver_get_output
));
5654 bp
->hwrm_spec_code
= resp
->hwrm_intf_maj_8b
<< 16 |
5655 resp
->hwrm_intf_min_8b
<< 8 |
5656 resp
->hwrm_intf_upd_8b
;
5657 if (resp
->hwrm_intf_maj_8b
< 1) {
5658 netdev_warn(bp
->dev
, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
5659 resp
->hwrm_intf_maj_8b
, resp
->hwrm_intf_min_8b
,
5660 resp
->hwrm_intf_upd_8b
);
5661 netdev_warn(bp
->dev
, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
5663 snprintf(bp
->fw_ver_str
, BC_HWRM_STR_LEN
, "%d.%d.%d.%d",
5664 resp
->hwrm_fw_maj_8b
, resp
->hwrm_fw_min_8b
,
5665 resp
->hwrm_fw_bld_8b
, resp
->hwrm_fw_rsvd_8b
);
5667 bp
->hwrm_cmd_timeout
= le16_to_cpu(resp
->def_req_timeout
);
5668 if (!bp
->hwrm_cmd_timeout
)
5669 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
5671 if (resp
->hwrm_intf_maj_8b
>= 1) {
5672 bp
->hwrm_max_req_len
= le16_to_cpu(resp
->max_req_win_len
);
5673 bp
->hwrm_max_ext_req_len
= le16_to_cpu(resp
->max_ext_req_len
);
5675 if (bp
->hwrm_max_ext_req_len
< HWRM_MAX_REQ_LEN
)
5676 bp
->hwrm_max_ext_req_len
= HWRM_MAX_REQ_LEN
;
5678 bp
->chip_num
= le16_to_cpu(resp
->chip_num
);
5679 if (bp
->chip_num
== CHIP_NUM_58700
&& !resp
->chip_rev
&&
5681 bp
->flags
|= BNXT_FLAG_CHIP_NITRO_A0
;
5683 dev_caps_cfg
= le32_to_cpu(resp
->dev_caps_cfg
);
5684 if ((dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED
) &&
5685 (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED
))
5686 bp
->fw_cap
|= BNXT_FW_CAP_SHORT_CMD
;
5689 mutex_unlock(&bp
->hwrm_cmd_lock
);
5693 int bnxt_hwrm_fw_set_time(struct bnxt
*bp
)
5695 struct hwrm_fw_set_time_input req
= {0};
5697 time64_t now
= ktime_get_real_seconds();
5699 if ((BNXT_VF(bp
) && bp
->hwrm_spec_code
< 0x10901) ||
5700 bp
->hwrm_spec_code
< 0x10400)
5703 time64_to_tm(now
, 0, &tm
);
5704 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_SET_TIME
, -1, -1);
5705 req
.year
= cpu_to_le16(1900 + tm
.tm_year
);
5706 req
.month
= 1 + tm
.tm_mon
;
5707 req
.day
= tm
.tm_mday
;
5708 req
.hour
= tm
.tm_hour
;
5709 req
.minute
= tm
.tm_min
;
5710 req
.second
= tm
.tm_sec
;
5711 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5714 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
)
5717 struct bnxt_pf_info
*pf
= &bp
->pf
;
5718 struct hwrm_port_qstats_input req
= {0};
5720 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS
))
5723 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS
, -1, -1);
5724 req
.port_id
= cpu_to_le16(pf
->port_id
);
5725 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_map
);
5726 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_map
);
5727 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5731 static int bnxt_hwrm_port_qstats_ext(struct bnxt
*bp
)
5733 struct hwrm_port_qstats_ext_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5734 struct hwrm_port_qstats_ext_input req
= {0};
5735 struct bnxt_pf_info
*pf
= &bp
->pf
;
5738 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
))
5741 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS_EXT
, -1, -1);
5742 req
.port_id
= cpu_to_le16(pf
->port_id
);
5743 req
.rx_stat_size
= cpu_to_le16(sizeof(struct rx_port_stats_ext
));
5744 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_ext_map
);
5745 req
.tx_stat_size
= cpu_to_le16(sizeof(struct tx_port_stats_ext
));
5746 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_ext_map
);
5747 mutex_lock(&bp
->hwrm_cmd_lock
);
5748 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5750 bp
->fw_rx_stats_ext_size
= le16_to_cpu(resp
->rx_stat_size
) / 8;
5751 bp
->fw_tx_stats_ext_size
= le16_to_cpu(resp
->tx_stat_size
) / 8;
5753 bp
->fw_rx_stats_ext_size
= 0;
5754 bp
->fw_tx_stats_ext_size
= 0;
5756 mutex_unlock(&bp
->hwrm_cmd_lock
);
5760 static void bnxt_hwrm_free_tunnel_ports(struct bnxt
*bp
)
5762 if (bp
->vxlan_port_cnt
) {
5763 bnxt_hwrm_tunnel_dst_port_free(
5764 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
5766 bp
->vxlan_port_cnt
= 0;
5767 if (bp
->nge_port_cnt
) {
5768 bnxt_hwrm_tunnel_dst_port_free(
5769 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
5771 bp
->nge_port_cnt
= 0;
5774 static int bnxt_set_tpa(struct bnxt
*bp
, bool set_tpa
)
5780 tpa_flags
= bp
->flags
& BNXT_FLAG_TPA
;
5781 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
5782 rc
= bnxt_hwrm_vnic_set_tpa(bp
, i
, tpa_flags
);
5784 netdev_err(bp
->dev
, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
5792 static void bnxt_hwrm_clear_vnic_rss(struct bnxt
*bp
)
5796 for (i
= 0; i
< bp
->nr_vnics
; i
++)
5797 bnxt_hwrm_vnic_set_rss(bp
, i
, false);
5800 static void bnxt_hwrm_resource_free(struct bnxt
*bp
, bool close_path
,
5803 if (bp
->vnic_info
) {
5804 bnxt_hwrm_clear_vnic_filter(bp
);
5805 /* clear all RSS setting before free vnic ctx */
5806 bnxt_hwrm_clear_vnic_rss(bp
);
5807 bnxt_hwrm_vnic_ctx_free(bp
);
5808 /* before free the vnic, undo the vnic tpa settings */
5809 if (bp
->flags
& BNXT_FLAG_TPA
)
5810 bnxt_set_tpa(bp
, false);
5811 bnxt_hwrm_vnic_free(bp
);
5813 bnxt_hwrm_ring_free(bp
, close_path
);
5814 bnxt_hwrm_ring_grp_free(bp
);
5816 bnxt_hwrm_stat_ctx_free(bp
);
5817 bnxt_hwrm_free_tunnel_ports(bp
);
5821 static int bnxt_hwrm_set_br_mode(struct bnxt
*bp
, u16 br_mode
)
5823 struct hwrm_func_cfg_input req
= {0};
5826 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
5827 req
.fid
= cpu_to_le16(0xffff);
5828 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE
);
5829 if (br_mode
== BRIDGE_MODE_VEB
)
5830 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEB
;
5831 else if (br_mode
== BRIDGE_MODE_VEPA
)
5832 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEPA
;
5835 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5841 static int bnxt_hwrm_set_cache_line_size(struct bnxt
*bp
, int size
)
5843 struct hwrm_func_cfg_input req
= {0};
5846 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10803)
5849 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
5850 req
.fid
= cpu_to_le16(0xffff);
5851 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE
);
5852 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64
;
5854 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128
;
5856 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5862 static int bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
5864 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5867 if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
)
5870 /* allocate context for vnic */
5871 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 0);
5873 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
5875 goto vnic_setup_err
;
5877 bp
->rsscos_nr_ctxs
++;
5879 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
5880 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 1);
5882 netdev_err(bp
->dev
, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
5884 goto vnic_setup_err
;
5886 bp
->rsscos_nr_ctxs
++;
5890 /* configure default vnic, ring grp */
5891 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
5893 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
5895 goto vnic_setup_err
;
5898 /* Enable RSS hashing on vnic */
5899 rc
= bnxt_hwrm_vnic_set_rss(bp
, vnic_id
, true);
5901 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %x\n",
5903 goto vnic_setup_err
;
5906 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
5907 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
5909 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
5918 static int bnxt_alloc_rfs_vnics(struct bnxt
*bp
)
5920 #ifdef CONFIG_RFS_ACCEL
5923 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5924 struct bnxt_vnic_info
*vnic
;
5925 u16 vnic_id
= i
+ 1;
5928 if (vnic_id
>= bp
->nr_vnics
)
5931 vnic
= &bp
->vnic_info
[vnic_id
];
5932 vnic
->flags
|= BNXT_VNIC_RFS_FLAG
;
5933 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
5934 vnic
->flags
|= BNXT_VNIC_RFS_NEW_RSS_FLAG
;
5935 rc
= bnxt_hwrm_vnic_alloc(bp
, vnic_id
, ring_id
, 1);
5937 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
5941 rc
= bnxt_setup_vnic(bp
, vnic_id
);
5951 /* Allow PF and VF with default VLAN to be in promiscuous mode */
5952 static bool bnxt_promisc_ok(struct bnxt
*bp
)
5954 #ifdef CONFIG_BNXT_SRIOV
5955 if (BNXT_VF(bp
) && !bp
->vf
.vlan
)
5961 static int bnxt_setup_nitroa0_vnic(struct bnxt
*bp
)
5963 unsigned int rc
= 0;
5965 rc
= bnxt_hwrm_vnic_alloc(bp
, 1, bp
->rx_nr_rings
- 1, 1);
5967 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
5972 rc
= bnxt_hwrm_vnic_cfg(bp
, 1);
5974 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
5981 static int bnxt_cfg_rx_mode(struct bnxt
*);
5982 static bool bnxt_mc_list_updated(struct bnxt
*, u32
*);
5984 static int bnxt_init_chip(struct bnxt
*bp
, bool irq_re_init
)
5986 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
5988 unsigned int rx_nr_rings
= bp
->rx_nr_rings
;
5991 rc
= bnxt_hwrm_stat_ctx_alloc(bp
);
5993 netdev_err(bp
->dev
, "hwrm stat ctx alloc failure rc: %x\n",
5999 rc
= bnxt_hwrm_ring_alloc(bp
);
6001 netdev_err(bp
->dev
, "hwrm ring alloc failure rc: %x\n", rc
);
6005 rc
= bnxt_hwrm_ring_grp_alloc(bp
);
6007 netdev_err(bp
->dev
, "hwrm_ring_grp alloc failure: %x\n", rc
);
6011 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6014 /* default vnic 0 */
6015 rc
= bnxt_hwrm_vnic_alloc(bp
, 0, 0, rx_nr_rings
);
6017 netdev_err(bp
->dev
, "hwrm vnic alloc failure rc: %x\n", rc
);
6021 rc
= bnxt_setup_vnic(bp
, 0);
6025 if (bp
->flags
& BNXT_FLAG_RFS
) {
6026 rc
= bnxt_alloc_rfs_vnics(bp
);
6031 if (bp
->flags
& BNXT_FLAG_TPA
) {
6032 rc
= bnxt_set_tpa(bp
, true);
6038 bnxt_update_vf_mac(bp
);
6040 /* Filter for default vnic 0 */
6041 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, 0, bp
->dev
->dev_addr
);
6043 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n", rc
);
6046 vnic
->uc_filter_count
= 1;
6049 if (bp
->dev
->flags
& IFF_BROADCAST
)
6050 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
6052 if ((bp
->dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
6053 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
6055 if (bp
->dev
->flags
& IFF_ALLMULTI
) {
6056 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
6057 vnic
->mc_list_count
= 0;
6061 bnxt_mc_list_updated(bp
, &mask
);
6062 vnic
->rx_mask
|= mask
;
6065 rc
= bnxt_cfg_rx_mode(bp
);
6069 rc
= bnxt_hwrm_set_coal(bp
);
6071 netdev_warn(bp
->dev
, "HWRM set coalescing failure rc: %x\n",
6074 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
6075 rc
= bnxt_setup_nitroa0_vnic(bp
);
6077 netdev_err(bp
->dev
, "Special vnic setup failure for NS2 A0 rc: %x\n",
6082 bnxt_hwrm_func_qcfg(bp
);
6083 netdev_update_features(bp
->dev
);
6089 bnxt_hwrm_resource_free(bp
, 0, true);
6094 static int bnxt_shutdown_nic(struct bnxt
*bp
, bool irq_re_init
)
6096 bnxt_hwrm_resource_free(bp
, 1, irq_re_init
);
6100 static int bnxt_init_nic(struct bnxt
*bp
, bool irq_re_init
)
6102 bnxt_init_cp_rings(bp
);
6103 bnxt_init_rx_rings(bp
);
6104 bnxt_init_tx_rings(bp
);
6105 bnxt_init_ring_grps(bp
, irq_re_init
);
6106 bnxt_init_vnics(bp
);
6108 return bnxt_init_chip(bp
, irq_re_init
);
6111 static int bnxt_set_real_num_queues(struct bnxt
*bp
)
6114 struct net_device
*dev
= bp
->dev
;
6116 rc
= netif_set_real_num_tx_queues(dev
, bp
->tx_nr_rings
-
6117 bp
->tx_nr_rings_xdp
);
6121 rc
= netif_set_real_num_rx_queues(dev
, bp
->rx_nr_rings
);
6125 #ifdef CONFIG_RFS_ACCEL
6126 if (bp
->flags
& BNXT_FLAG_RFS
)
6127 dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(bp
->rx_nr_rings
);
6133 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
6136 int _rx
= *rx
, _tx
= *tx
;
6139 *rx
= min_t(int, _rx
, max
);
6140 *tx
= min_t(int, _tx
, max
);
6145 while (_rx
+ _tx
> max
) {
6146 if (_rx
> _tx
&& _rx
> 1)
6157 static void bnxt_setup_msix(struct bnxt
*bp
)
6159 const int len
= sizeof(bp
->irq_tbl
[0].name
);
6160 struct net_device
*dev
= bp
->dev
;
6163 tcs
= netdev_get_num_tc(dev
);
6167 for (i
= 0; i
< tcs
; i
++) {
6168 count
= bp
->tx_nr_rings_per_tc
;
6170 netdev_set_tc_queue(dev
, i
, count
, off
);
6174 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6175 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
6178 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
6180 else if (i
< bp
->rx_nr_rings
)
6185 snprintf(bp
->irq_tbl
[map_idx
].name
, len
, "%s-%s-%d", dev
->name
,
6187 bp
->irq_tbl
[map_idx
].handler
= bnxt_msix
;
6191 static void bnxt_setup_inta(struct bnxt
*bp
)
6193 const int len
= sizeof(bp
->irq_tbl
[0].name
);
6195 if (netdev_get_num_tc(bp
->dev
))
6196 netdev_reset_tc(bp
->dev
);
6198 snprintf(bp
->irq_tbl
[0].name
, len
, "%s-%s-%d", bp
->dev
->name
, "TxRx",
6200 bp
->irq_tbl
[0].handler
= bnxt_inta
;
6203 static int bnxt_setup_int_mode(struct bnxt
*bp
)
6207 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
6208 bnxt_setup_msix(bp
);
6210 bnxt_setup_inta(bp
);
6212 rc
= bnxt_set_real_num_queues(bp
);
6216 #ifdef CONFIG_RFS_ACCEL
6217 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt
*bp
)
6219 return bp
->hw_resc
.max_rsscos_ctxs
;
6222 static unsigned int bnxt_get_max_func_vnics(struct bnxt
*bp
)
6224 return bp
->hw_resc
.max_vnics
;
6228 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt
*bp
)
6230 return bp
->hw_resc
.max_stat_ctxs
;
6233 void bnxt_set_max_func_stat_ctxs(struct bnxt
*bp
, unsigned int max
)
6235 bp
->hw_resc
.max_stat_ctxs
= max
;
6238 unsigned int bnxt_get_max_func_cp_rings(struct bnxt
*bp
)
6240 return bp
->hw_resc
.max_cp_rings
;
6243 unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt
*bp
)
6245 return bp
->hw_resc
.max_cp_rings
- bnxt_get_ulp_msix_num(bp
);
6248 static unsigned int bnxt_get_max_func_irqs(struct bnxt
*bp
)
6250 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6252 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_cp_rings
);
6255 static void bnxt_set_max_func_irqs(struct bnxt
*bp
, unsigned int max_irqs
)
6257 bp
->hw_resc
.max_irqs
= max_irqs
;
6260 int bnxt_get_avail_msix(struct bnxt
*bp
, int num
)
6262 int max_cp
= bnxt_get_max_func_cp_rings(bp
);
6263 int max_irq
= bnxt_get_max_func_irqs(bp
);
6264 int total_req
= bp
->cp_nr_rings
+ num
;
6265 int max_idx
, avail_msix
;
6267 max_idx
= min_t(int, bp
->total_irqs
, max_cp
);
6268 avail_msix
= max_idx
- bp
->cp_nr_rings
;
6269 if (!BNXT_NEW_RM(bp
) || avail_msix
>= num
)
6272 if (max_irq
< total_req
) {
6273 num
= max_irq
- bp
->cp_nr_rings
;
6280 static int bnxt_get_num_msix(struct bnxt
*bp
)
6282 if (!BNXT_NEW_RM(bp
))
6283 return bnxt_get_max_func_irqs(bp
);
6285 return bnxt_cp_rings_in_use(bp
);
6288 static int bnxt_init_msix(struct bnxt
*bp
)
6290 int i
, total_vecs
, max
, rc
= 0, min
= 1, ulp_msix
;
6291 struct msix_entry
*msix_ent
;
6293 total_vecs
= bnxt_get_num_msix(bp
);
6294 max
= bnxt_get_max_func_irqs(bp
);
6295 if (total_vecs
> max
)
6301 msix_ent
= kcalloc(total_vecs
, sizeof(struct msix_entry
), GFP_KERNEL
);
6305 for (i
= 0; i
< total_vecs
; i
++) {
6306 msix_ent
[i
].entry
= i
;
6307 msix_ent
[i
].vector
= 0;
6310 if (!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
))
6313 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
, min
, total_vecs
);
6314 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
6315 if (total_vecs
< 0 || total_vecs
< ulp_msix
) {
6317 goto msix_setup_exit
;
6320 bp
->irq_tbl
= kcalloc(total_vecs
, sizeof(struct bnxt_irq
), GFP_KERNEL
);
6322 for (i
= 0; i
< total_vecs
; i
++)
6323 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
6325 bp
->total_irqs
= total_vecs
;
6326 /* Trim rings based upon num of vectors allocated */
6327 rc
= bnxt_trim_rings(bp
, &bp
->rx_nr_rings
, &bp
->tx_nr_rings
,
6328 total_vecs
- ulp_msix
, min
== 1);
6330 goto msix_setup_exit
;
6332 bp
->cp_nr_rings
= (min
== 1) ?
6333 max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
6334 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
6338 goto msix_setup_exit
;
6340 bp
->flags
|= BNXT_FLAG_USING_MSIX
;
6345 netdev_err(bp
->dev
, "bnxt_init_msix err: %x\n", rc
);
6348 pci_disable_msix(bp
->pdev
);
6353 static int bnxt_init_inta(struct bnxt
*bp
)
6355 bp
->irq_tbl
= kcalloc(1, sizeof(struct bnxt_irq
), GFP_KERNEL
);
6360 bp
->rx_nr_rings
= 1;
6361 bp
->tx_nr_rings
= 1;
6362 bp
->cp_nr_rings
= 1;
6363 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
6364 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
6368 static int bnxt_init_int_mode(struct bnxt
*bp
)
6372 if (bp
->flags
& BNXT_FLAG_MSIX_CAP
)
6373 rc
= bnxt_init_msix(bp
);
6375 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
) && BNXT_PF(bp
)) {
6376 /* fallback to INTA */
6377 rc
= bnxt_init_inta(bp
);
6382 static void bnxt_clear_int_mode(struct bnxt
*bp
)
6384 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
6385 pci_disable_msix(bp
->pdev
);
6389 bp
->flags
&= ~BNXT_FLAG_USING_MSIX
;
6392 int bnxt_reserve_rings(struct bnxt
*bp
)
6394 int tcs
= netdev_get_num_tc(bp
->dev
);
6397 if (!bnxt_need_reserve_rings(bp
))
6400 rc
= __bnxt_reserve_rings(bp
);
6402 netdev_err(bp
->dev
, "ring reservation failure rc: %d\n", rc
);
6405 if (BNXT_NEW_RM(bp
) && (bnxt_get_num_msix(bp
) != bp
->total_irqs
)) {
6406 bnxt_ulp_irq_stop(bp
);
6407 bnxt_clear_int_mode(bp
);
6408 rc
= bnxt_init_int_mode(bp
);
6409 bnxt_ulp_irq_restart(bp
, rc
);
6413 if (tcs
&& (bp
->tx_nr_rings_per_tc
* tcs
!= bp
->tx_nr_rings
)) {
6414 netdev_err(bp
->dev
, "tx ring reservation failure\n");
6415 netdev_reset_tc(bp
->dev
);
6416 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
6419 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
6423 static void bnxt_free_irq(struct bnxt
*bp
)
6425 struct bnxt_irq
*irq
;
6428 #ifdef CONFIG_RFS_ACCEL
6429 free_irq_cpu_rmap(bp
->dev
->rx_cpu_rmap
);
6430 bp
->dev
->rx_cpu_rmap
= NULL
;
6432 if (!bp
->irq_tbl
|| !bp
->bnapi
)
6435 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6436 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
6438 irq
= &bp
->irq_tbl
[map_idx
];
6439 if (irq
->requested
) {
6440 if (irq
->have_cpumask
) {
6441 irq_set_affinity_hint(irq
->vector
, NULL
);
6442 free_cpumask_var(irq
->cpu_mask
);
6443 irq
->have_cpumask
= 0;
6445 free_irq(irq
->vector
, bp
->bnapi
[i
]);
6452 static int bnxt_request_irq(struct bnxt
*bp
)
6455 unsigned long flags
= 0;
6456 #ifdef CONFIG_RFS_ACCEL
6457 struct cpu_rmap
*rmap
;
6460 rc
= bnxt_setup_int_mode(bp
);
6462 netdev_err(bp
->dev
, "bnxt_setup_int_mode err: %x\n",
6466 #ifdef CONFIG_RFS_ACCEL
6467 rmap
= bp
->dev
->rx_cpu_rmap
;
6469 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
))
6470 flags
= IRQF_SHARED
;
6472 for (i
= 0, j
= 0; i
< bp
->cp_nr_rings
; i
++) {
6473 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
6474 struct bnxt_irq
*irq
= &bp
->irq_tbl
[map_idx
];
6476 #ifdef CONFIG_RFS_ACCEL
6477 if (rmap
&& bp
->bnapi
[i
]->rx_ring
) {
6478 rc
= irq_cpu_rmap_add(rmap
, irq
->vector
);
6480 netdev_warn(bp
->dev
, "failed adding irq rmap for ring %d\n",
6485 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
6492 if (zalloc_cpumask_var(&irq
->cpu_mask
, GFP_KERNEL
)) {
6493 int numa_node
= dev_to_node(&bp
->pdev
->dev
);
6495 irq
->have_cpumask
= 1;
6496 cpumask_set_cpu(cpumask_local_spread(i
, numa_node
),
6498 rc
= irq_set_affinity_hint(irq
->vector
, irq
->cpu_mask
);
6500 netdev_warn(bp
->dev
,
6501 "Set affinity failed, IRQ = %d\n",
6510 static void bnxt_del_napi(struct bnxt
*bp
)
6517 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6518 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6520 napi_hash_del(&bnapi
->napi
);
6521 netif_napi_del(&bnapi
->napi
);
6523 /* We called napi_hash_del() before netif_napi_del(), we need
6524 * to respect an RCU grace period before freeing napi structures.
6529 static void bnxt_init_napi(struct bnxt
*bp
)
6532 unsigned int cp_nr_rings
= bp
->cp_nr_rings
;
6533 struct bnxt_napi
*bnapi
;
6535 if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
6536 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6538 for (i
= 0; i
< cp_nr_rings
; i
++) {
6539 bnapi
= bp
->bnapi
[i
];
6540 netif_napi_add(bp
->dev
, &bnapi
->napi
,
6543 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
6544 bnapi
= bp
->bnapi
[cp_nr_rings
];
6545 netif_napi_add(bp
->dev
, &bnapi
->napi
,
6546 bnxt_poll_nitroa0
, 64);
6549 bnapi
= bp
->bnapi
[0];
6550 netif_napi_add(bp
->dev
, &bnapi
->napi
, bnxt_poll
, 64);
6554 static void bnxt_disable_napi(struct bnxt
*bp
)
6561 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6562 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
6564 if (bp
->bnapi
[i
]->rx_ring
)
6565 cancel_work_sync(&cpr
->dim
.work
);
6567 napi_disable(&bp
->bnapi
[i
]->napi
);
6571 static void bnxt_enable_napi(struct bnxt
*bp
)
6575 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6576 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
6577 bp
->bnapi
[i
]->in_reset
= false;
6579 if (bp
->bnapi
[i
]->rx_ring
) {
6580 INIT_WORK(&cpr
->dim
.work
, bnxt_dim_work
);
6581 cpr
->dim
.mode
= NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE
;
6583 napi_enable(&bp
->bnapi
[i
]->napi
);
6587 void bnxt_tx_disable(struct bnxt
*bp
)
6590 struct bnxt_tx_ring_info
*txr
;
6593 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
6594 txr
= &bp
->tx_ring
[i
];
6595 txr
->dev_state
= BNXT_DEV_STATE_CLOSING
;
6598 /* Stop all TX queues */
6599 netif_tx_disable(bp
->dev
);
6600 netif_carrier_off(bp
->dev
);
6603 void bnxt_tx_enable(struct bnxt
*bp
)
6606 struct bnxt_tx_ring_info
*txr
;
6608 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
6609 txr
= &bp
->tx_ring
[i
];
6612 netif_tx_wake_all_queues(bp
->dev
);
6613 if (bp
->link_info
.link_up
)
6614 netif_carrier_on(bp
->dev
);
6617 static void bnxt_report_link(struct bnxt
*bp
)
6619 if (bp
->link_info
.link_up
) {
6621 const char *flow_ctrl
;
6625 netif_carrier_on(bp
->dev
);
6626 if (bp
->link_info
.duplex
== BNXT_LINK_DUPLEX_FULL
)
6630 if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_BOTH
)
6631 flow_ctrl
= "ON - receive & transmit";
6632 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_TX
)
6633 flow_ctrl
= "ON - transmit";
6634 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_RX
)
6635 flow_ctrl
= "ON - receive";
6638 speed
= bnxt_fw_to_ethtool_speed(bp
->link_info
.link_speed
);
6639 netdev_info(bp
->dev
, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
6640 speed
, duplex
, flow_ctrl
);
6641 if (bp
->flags
& BNXT_FLAG_EEE_CAP
)
6642 netdev_info(bp
->dev
, "EEE is %s\n",
6643 bp
->eee
.eee_active
? "active" :
6645 fec
= bp
->link_info
.fec_cfg
;
6646 if (!(fec
& PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
))
6647 netdev_info(bp
->dev
, "FEC autoneg %s encodings: %s\n",
6648 (fec
& BNXT_FEC_AUTONEG
) ? "on" : "off",
6649 (fec
& BNXT_FEC_ENC_BASE_R
) ? "BaseR" :
6650 (fec
& BNXT_FEC_ENC_RS
) ? "RS" : "None");
6652 netif_carrier_off(bp
->dev
);
6653 netdev_err(bp
->dev
, "NIC Link is Down\n");
6657 static int bnxt_hwrm_phy_qcaps(struct bnxt
*bp
)
6660 struct hwrm_port_phy_qcaps_input req
= {0};
6661 struct hwrm_port_phy_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6662 struct bnxt_link_info
*link_info
= &bp
->link_info
;
6664 if (bp
->hwrm_spec_code
< 0x10201)
6667 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCAPS
, -1, -1);
6669 mutex_lock(&bp
->hwrm_cmd_lock
);
6670 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6672 goto hwrm_phy_qcaps_exit
;
6674 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED
) {
6675 struct ethtool_eee
*eee
= &bp
->eee
;
6676 u16 fw_speeds
= le16_to_cpu(resp
->supported_speeds_eee_mode
);
6678 bp
->flags
|= BNXT_FLAG_EEE_CAP
;
6679 eee
->supported
= _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
6680 bp
->lpi_tmr_lo
= le32_to_cpu(resp
->tx_lpi_timer_low
) &
6681 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK
;
6682 bp
->lpi_tmr_hi
= le32_to_cpu(resp
->valid_tx_lpi_timer_high
) &
6683 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK
;
6685 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EXTERNAL_LPBK_SUPPORTED
) {
6687 bp
->test_info
->flags
|= BNXT_TEST_FL_EXT_LPBK
;
6689 if (resp
->supported_speeds_auto_mode
)
6690 link_info
->support_auto_speeds
=
6691 le16_to_cpu(resp
->supported_speeds_auto_mode
);
6693 bp
->port_count
= resp
->port_cnt
;
6695 hwrm_phy_qcaps_exit
:
6696 mutex_unlock(&bp
->hwrm_cmd_lock
);
6700 static int bnxt_update_link(struct bnxt
*bp
, bool chng_link_state
)
6703 struct bnxt_link_info
*link_info
= &bp
->link_info
;
6704 struct hwrm_port_phy_qcfg_input req
= {0};
6705 struct hwrm_port_phy_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6706 u8 link_up
= link_info
->link_up
;
6709 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCFG
, -1, -1);
6711 mutex_lock(&bp
->hwrm_cmd_lock
);
6712 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6714 mutex_unlock(&bp
->hwrm_cmd_lock
);
6718 memcpy(&link_info
->phy_qcfg_resp
, resp
, sizeof(*resp
));
6719 link_info
->phy_link_status
= resp
->link
;
6720 link_info
->duplex
= resp
->duplex_cfg
;
6721 if (bp
->hwrm_spec_code
>= 0x10800)
6722 link_info
->duplex
= resp
->duplex_state
;
6723 link_info
->pause
= resp
->pause
;
6724 link_info
->auto_mode
= resp
->auto_mode
;
6725 link_info
->auto_pause_setting
= resp
->auto_pause
;
6726 link_info
->lp_pause
= resp
->link_partner_adv_pause
;
6727 link_info
->force_pause_setting
= resp
->force_pause
;
6728 link_info
->duplex_setting
= resp
->duplex_cfg
;
6729 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
6730 link_info
->link_speed
= le16_to_cpu(resp
->link_speed
);
6732 link_info
->link_speed
= 0;
6733 link_info
->force_link_speed
= le16_to_cpu(resp
->force_link_speed
);
6734 link_info
->support_speeds
= le16_to_cpu(resp
->support_speeds
);
6735 link_info
->auto_link_speeds
= le16_to_cpu(resp
->auto_link_speed_mask
);
6736 link_info
->lp_auto_link_speeds
=
6737 le16_to_cpu(resp
->link_partner_adv_speeds
);
6738 link_info
->preemphasis
= le32_to_cpu(resp
->preemphasis
);
6739 link_info
->phy_ver
[0] = resp
->phy_maj
;
6740 link_info
->phy_ver
[1] = resp
->phy_min
;
6741 link_info
->phy_ver
[2] = resp
->phy_bld
;
6742 link_info
->media_type
= resp
->media_type
;
6743 link_info
->phy_type
= resp
->phy_type
;
6744 link_info
->transceiver
= resp
->xcvr_pkg_type
;
6745 link_info
->phy_addr
= resp
->eee_config_phy_addr
&
6746 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK
;
6747 link_info
->module_status
= resp
->module_status
;
6749 if (bp
->flags
& BNXT_FLAG_EEE_CAP
) {
6750 struct ethtool_eee
*eee
= &bp
->eee
;
6753 eee
->eee_active
= 0;
6754 if (resp
->eee_config_phy_addr
&
6755 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE
) {
6756 eee
->eee_active
= 1;
6757 fw_speeds
= le16_to_cpu(
6758 resp
->link_partner_adv_eee_link_speed_mask
);
6759 eee
->lp_advertised
=
6760 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
6763 /* Pull initial EEE config */
6764 if (!chng_link_state
) {
6765 if (resp
->eee_config_phy_addr
&
6766 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED
)
6767 eee
->eee_enabled
= 1;
6769 fw_speeds
= le16_to_cpu(resp
->adv_eee_link_speed_mask
);
6771 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
6773 if (resp
->eee_config_phy_addr
&
6774 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI
) {
6777 eee
->tx_lpi_enabled
= 1;
6778 tmr
= resp
->xcvr_identifier_type_tx_lpi_timer
;
6779 eee
->tx_lpi_timer
= le32_to_cpu(tmr
) &
6780 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK
;
6785 link_info
->fec_cfg
= PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
;
6786 if (bp
->hwrm_spec_code
>= 0x10504)
6787 link_info
->fec_cfg
= le16_to_cpu(resp
->fec_cfg
);
6789 /* TODO: need to add more logic to report VF link */
6790 if (chng_link_state
) {
6791 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
6792 link_info
->link_up
= 1;
6794 link_info
->link_up
= 0;
6795 if (link_up
!= link_info
->link_up
)
6796 bnxt_report_link(bp
);
6798 /* alwasy link down if not require to update link state */
6799 link_info
->link_up
= 0;
6801 mutex_unlock(&bp
->hwrm_cmd_lock
);
6803 if (!BNXT_SINGLE_PF(bp
))
6806 diff
= link_info
->support_auto_speeds
^ link_info
->advertising
;
6807 if ((link_info
->support_auto_speeds
| diff
) !=
6808 link_info
->support_auto_speeds
) {
6809 /* An advertised speed is no longer supported, so we need to
6810 * update the advertisement settings. Caller holds RTNL
6811 * so we can modify link settings.
6813 link_info
->advertising
= link_info
->support_auto_speeds
;
6814 if (link_info
->autoneg
& BNXT_AUTONEG_SPEED
)
6815 bnxt_hwrm_set_link_setting(bp
, true, false);
6820 static void bnxt_get_port_module_status(struct bnxt
*bp
)
6822 struct bnxt_link_info
*link_info
= &bp
->link_info
;
6823 struct hwrm_port_phy_qcfg_output
*resp
= &link_info
->phy_qcfg_resp
;
6826 if (bnxt_update_link(bp
, true))
6829 module_status
= link_info
->module_status
;
6830 switch (module_status
) {
6831 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
:
6832 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
:
6833 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
:
6834 netdev_warn(bp
->dev
, "Unqualified SFP+ module detected on port %d\n",
6836 if (bp
->hwrm_spec_code
>= 0x10201) {
6837 netdev_warn(bp
->dev
, "Module part number %s\n",
6838 resp
->phy_vendor_partnumber
);
6840 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
)
6841 netdev_warn(bp
->dev
, "TX is disabled\n");
6842 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
)
6843 netdev_warn(bp
->dev
, "SFP+ module is shutdown\n");
6848 bnxt_hwrm_set_pause_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
6850 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) {
6851 if (bp
->hwrm_spec_code
>= 0x10201)
6853 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
6854 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
6855 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX
;
6856 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
6857 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX
;
6859 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
6861 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
6862 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX
;
6863 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
6864 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX
;
6866 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE
);
6867 if (bp
->hwrm_spec_code
>= 0x10201) {
6868 req
->auto_pause
= req
->force_pause
;
6869 req
->enables
|= cpu_to_le32(
6870 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
6875 static void bnxt_hwrm_set_link_common(struct bnxt
*bp
,
6876 struct hwrm_port_phy_cfg_input
*req
)
6878 u8 autoneg
= bp
->link_info
.autoneg
;
6879 u16 fw_link_speed
= bp
->link_info
.req_link_speed
;
6880 u16 advertising
= bp
->link_info
.advertising
;
6882 if (autoneg
& BNXT_AUTONEG_SPEED
) {
6884 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK
;
6886 req
->enables
|= cpu_to_le32(
6887 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK
);
6888 req
->auto_link_speed_mask
= cpu_to_le16(advertising
);
6890 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE
);
6892 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG
);
6894 req
->force_link_speed
= cpu_to_le16(fw_link_speed
);
6895 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE
);
6898 /* tell chimp that the setting takes effect immediately */
6899 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY
);
6902 int bnxt_hwrm_set_pause(struct bnxt
*bp
)
6904 struct hwrm_port_phy_cfg_input req
= {0};
6907 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
6908 bnxt_hwrm_set_pause_common(bp
, &req
);
6910 if ((bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) ||
6911 bp
->link_info
.force_link_chng
)
6912 bnxt_hwrm_set_link_common(bp
, &req
);
6914 mutex_lock(&bp
->hwrm_cmd_lock
);
6915 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6916 if (!rc
&& !(bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
)) {
6917 /* since changing of pause setting doesn't trigger any link
6918 * change event, the driver needs to update the current pause
6919 * result upon successfully return of the phy_cfg command
6921 bp
->link_info
.pause
=
6922 bp
->link_info
.force_pause_setting
= bp
->link_info
.req_flow_ctrl
;
6923 bp
->link_info
.auto_pause_setting
= 0;
6924 if (!bp
->link_info
.force_link_chng
)
6925 bnxt_report_link(bp
);
6927 bp
->link_info
.force_link_chng
= false;
6928 mutex_unlock(&bp
->hwrm_cmd_lock
);
6932 static void bnxt_hwrm_set_eee(struct bnxt
*bp
,
6933 struct hwrm_port_phy_cfg_input
*req
)
6935 struct ethtool_eee
*eee
= &bp
->eee
;
6937 if (eee
->eee_enabled
) {
6939 u32 flags
= PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE
;
6941 if (eee
->tx_lpi_enabled
)
6942 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE
;
6944 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE
;
6946 req
->flags
|= cpu_to_le32(flags
);
6947 eee_speeds
= bnxt_get_fw_auto_link_speeds(eee
->advertised
);
6948 req
->eee_link_speed_mask
= cpu_to_le16(eee_speeds
);
6949 req
->tx_lpi_timer
= cpu_to_le32(eee
->tx_lpi_timer
);
6951 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE
);
6955 int bnxt_hwrm_set_link_setting(struct bnxt
*bp
, bool set_pause
, bool set_eee
)
6957 struct hwrm_port_phy_cfg_input req
= {0};
6959 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
6961 bnxt_hwrm_set_pause_common(bp
, &req
);
6963 bnxt_hwrm_set_link_common(bp
, &req
);
6966 bnxt_hwrm_set_eee(bp
, &req
);
6967 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6970 static int bnxt_hwrm_shutdown_link(struct bnxt
*bp
)
6972 struct hwrm_port_phy_cfg_input req
= {0};
6974 if (!BNXT_SINGLE_PF(bp
))
6977 if (pci_num_vf(bp
->pdev
))
6980 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
6981 req
.flags
= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN
);
6982 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6985 static int bnxt_hwrm_if_change(struct bnxt
*bp
, bool up
)
6987 struct hwrm_func_drv_if_change_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6988 struct hwrm_func_drv_if_change_input req
= {0};
6989 bool resc_reinit
= false;
6992 if (!(bp
->fw_cap
& BNXT_FW_CAP_IF_CHANGE
))
6995 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_IF_CHANGE
, -1, -1);
6997 req
.flags
= cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP
);
6998 mutex_lock(&bp
->hwrm_cmd_lock
);
6999 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7000 if (!rc
&& (resp
->flags
&
7001 cpu_to_le32(FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE
)))
7003 mutex_unlock(&bp
->hwrm_cmd_lock
);
7005 if (up
&& resc_reinit
&& BNXT_NEW_RM(bp
)) {
7006 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7008 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
7009 hw_resc
->resv_cp_rings
= 0;
7010 hw_resc
->resv_tx_rings
= 0;
7011 hw_resc
->resv_rx_rings
= 0;
7012 hw_resc
->resv_hw_ring_grps
= 0;
7013 hw_resc
->resv_vnics
= 0;
7014 bp
->tx_nr_rings
= 0;
7015 bp
->rx_nr_rings
= 0;
7020 static int bnxt_hwrm_port_led_qcaps(struct bnxt
*bp
)
7022 struct hwrm_port_led_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7023 struct hwrm_port_led_qcaps_input req
= {0};
7024 struct bnxt_pf_info
*pf
= &bp
->pf
;
7027 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10601)
7030 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_LED_QCAPS
, -1, -1);
7031 req
.port_id
= cpu_to_le16(pf
->port_id
);
7032 mutex_lock(&bp
->hwrm_cmd_lock
);
7033 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7035 mutex_unlock(&bp
->hwrm_cmd_lock
);
7038 if (resp
->num_leds
> 0 && resp
->num_leds
< BNXT_MAX_LED
) {
7041 bp
->num_leds
= resp
->num_leds
;
7042 memcpy(bp
->leds
, &resp
->led0_id
, sizeof(bp
->leds
[0]) *
7044 for (i
= 0; i
< bp
->num_leds
; i
++) {
7045 struct bnxt_led_info
*led
= &bp
->leds
[i
];
7046 __le16 caps
= led
->led_state_caps
;
7048 if (!led
->led_group_id
||
7049 !BNXT_LED_ALT_BLINK_CAP(caps
)) {
7055 mutex_unlock(&bp
->hwrm_cmd_lock
);
7059 int bnxt_hwrm_alloc_wol_fltr(struct bnxt
*bp
)
7061 struct hwrm_wol_filter_alloc_input req
= {0};
7062 struct hwrm_wol_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7065 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_ALLOC
, -1, -1);
7066 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
7067 req
.wol_type
= WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
;
7068 req
.enables
= cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS
);
7069 memcpy(req
.mac_address
, bp
->dev
->dev_addr
, ETH_ALEN
);
7070 mutex_lock(&bp
->hwrm_cmd_lock
);
7071 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7073 bp
->wol_filter_id
= resp
->wol_filter_id
;
7074 mutex_unlock(&bp
->hwrm_cmd_lock
);
7078 int bnxt_hwrm_free_wol_fltr(struct bnxt
*bp
)
7080 struct hwrm_wol_filter_free_input req
= {0};
7083 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_FREE
, -1, -1);
7084 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
7085 req
.enables
= cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID
);
7086 req
.wol_filter_id
= bp
->wol_filter_id
;
7087 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7091 static u16
bnxt_hwrm_get_wol_fltrs(struct bnxt
*bp
, u16 handle
)
7093 struct hwrm_wol_filter_qcfg_input req
= {0};
7094 struct hwrm_wol_filter_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7095 u16 next_handle
= 0;
7098 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_QCFG
, -1, -1);
7099 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
7100 req
.handle
= cpu_to_le16(handle
);
7101 mutex_lock(&bp
->hwrm_cmd_lock
);
7102 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7104 next_handle
= le16_to_cpu(resp
->next_handle
);
7105 if (next_handle
!= 0) {
7106 if (resp
->wol_type
==
7107 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
) {
7109 bp
->wol_filter_id
= resp
->wol_filter_id
;
7113 mutex_unlock(&bp
->hwrm_cmd_lock
);
7117 static void bnxt_get_wol_settings(struct bnxt
*bp
)
7121 if (!BNXT_PF(bp
) || !(bp
->flags
& BNXT_FLAG_WOL_CAP
))
7125 handle
= bnxt_hwrm_get_wol_fltrs(bp
, handle
);
7126 } while (handle
&& handle
!= 0xffff);
7129 #ifdef CONFIG_BNXT_HWMON
7130 static ssize_t
bnxt_show_temp(struct device
*dev
,
7131 struct device_attribute
*devattr
, char *buf
)
7133 struct hwrm_temp_monitor_query_input req
= {0};
7134 struct hwrm_temp_monitor_query_output
*resp
;
7135 struct bnxt
*bp
= dev_get_drvdata(dev
);
7138 resp
= bp
->hwrm_cmd_resp_addr
;
7139 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TEMP_MONITOR_QUERY
, -1, -1);
7140 mutex_lock(&bp
->hwrm_cmd_lock
);
7141 if (!_hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
))
7142 temp
= resp
->temp
* 1000; /* display millidegree */
7143 mutex_unlock(&bp
->hwrm_cmd_lock
);
7145 return sprintf(buf
, "%u\n", temp
);
7147 static SENSOR_DEVICE_ATTR(temp1_input
, 0444, bnxt_show_temp
, NULL
, 0);
7149 static struct attribute
*bnxt_attrs
[] = {
7150 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
7153 ATTRIBUTE_GROUPS(bnxt
);
7155 static void bnxt_hwmon_close(struct bnxt
*bp
)
7157 if (bp
->hwmon_dev
) {
7158 hwmon_device_unregister(bp
->hwmon_dev
);
7159 bp
->hwmon_dev
= NULL
;
7163 static void bnxt_hwmon_open(struct bnxt
*bp
)
7165 struct pci_dev
*pdev
= bp
->pdev
;
7167 bp
->hwmon_dev
= hwmon_device_register_with_groups(&pdev
->dev
,
7168 DRV_MODULE_NAME
, bp
,
7170 if (IS_ERR(bp
->hwmon_dev
)) {
7171 bp
->hwmon_dev
= NULL
;
7172 dev_warn(&pdev
->dev
, "Cannot register hwmon device\n");
7176 static void bnxt_hwmon_close(struct bnxt
*bp
)
7180 static void bnxt_hwmon_open(struct bnxt
*bp
)
7185 static bool bnxt_eee_config_ok(struct bnxt
*bp
)
7187 struct ethtool_eee
*eee
= &bp
->eee
;
7188 struct bnxt_link_info
*link_info
= &bp
->link_info
;
7190 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
7193 if (eee
->eee_enabled
) {
7195 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
7197 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
7198 eee
->eee_enabled
= 0;
7201 if (eee
->advertised
& ~advertising
) {
7202 eee
->advertised
= advertising
& eee
->supported
;
7209 static int bnxt_update_phy_setting(struct bnxt
*bp
)
7212 bool update_link
= false;
7213 bool update_pause
= false;
7214 bool update_eee
= false;
7215 struct bnxt_link_info
*link_info
= &bp
->link_info
;
7217 rc
= bnxt_update_link(bp
, true);
7219 netdev_err(bp
->dev
, "failed to update link (rc: %x)\n",
7223 if (!BNXT_SINGLE_PF(bp
))
7226 if ((link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
7227 (link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
) !=
7228 link_info
->req_flow_ctrl
)
7229 update_pause
= true;
7230 if (!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
7231 link_info
->force_pause_setting
!= link_info
->req_flow_ctrl
)
7232 update_pause
= true;
7233 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
7234 if (BNXT_AUTO_MODE(link_info
->auto_mode
))
7236 if (link_info
->req_link_speed
!= link_info
->force_link_speed
)
7238 if (link_info
->req_duplex
!= link_info
->duplex_setting
)
7241 if (link_info
->auto_mode
== BNXT_LINK_AUTO_NONE
)
7243 if (link_info
->advertising
!= link_info
->auto_link_speeds
)
7247 /* The last close may have shutdown the link, so need to call
7248 * PHY_CFG to bring it back up.
7250 if (!netif_carrier_ok(bp
->dev
))
7253 if (!bnxt_eee_config_ok(bp
))
7257 rc
= bnxt_hwrm_set_link_setting(bp
, update_pause
, update_eee
);
7258 else if (update_pause
)
7259 rc
= bnxt_hwrm_set_pause(bp
);
7261 netdev_err(bp
->dev
, "failed to update phy setting (rc: %x)\n",
7269 /* Common routine to pre-map certain register block to different GRC window.
7270 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
7271 * in PF and 3 windows in VF that can be customized to map in different
7274 static void bnxt_preset_reg_win(struct bnxt
*bp
)
7277 /* CAG registers map to GRC window #4 */
7278 writel(BNXT_CAG_REG_BASE
,
7279 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 12);
7283 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
);
7285 static int __bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
7289 bnxt_preset_reg_win(bp
);
7290 netif_carrier_off(bp
->dev
);
7292 /* Reserve rings now if none were reserved at driver probe. */
7293 rc
= bnxt_init_dflt_ring_mode(bp
);
7295 netdev_err(bp
->dev
, "Failed to reserve default rings at open\n");
7298 rc
= bnxt_reserve_rings(bp
);
7302 if ((bp
->flags
& BNXT_FLAG_RFS
) &&
7303 !(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
7304 /* disable RFS if falling back to INTA */
7305 bp
->dev
->hw_features
&= ~NETIF_F_NTUPLE
;
7306 bp
->flags
&= ~BNXT_FLAG_RFS
;
7309 rc
= bnxt_alloc_mem(bp
, irq_re_init
);
7311 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
7312 goto open_err_free_mem
;
7317 rc
= bnxt_request_irq(bp
);
7319 netdev_err(bp
->dev
, "bnxt_request_irq err: %x\n", rc
);
7324 bnxt_enable_napi(bp
);
7325 bnxt_debug_dev_init(bp
);
7327 rc
= bnxt_init_nic(bp
, irq_re_init
);
7329 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
7334 mutex_lock(&bp
->link_lock
);
7335 rc
= bnxt_update_phy_setting(bp
);
7336 mutex_unlock(&bp
->link_lock
);
7338 netdev_warn(bp
->dev
, "failed to update phy settings\n");
7339 if (BNXT_SINGLE_PF(bp
)) {
7340 bp
->link_info
.phy_retry
= true;
7341 bp
->link_info
.phy_retry_expires
=
7348 udp_tunnel_get_rx_info(bp
->dev
);
7350 set_bit(BNXT_STATE_OPEN
, &bp
->state
);
7351 bnxt_enable_int(bp
);
7352 /* Enable TX queues */
7354 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
7355 /* Poll link status and check for SFP+ module status */
7356 bnxt_get_port_module_status(bp
);
7358 /* VF-reps may need to be re-opened after the PF is re-opened */
7360 bnxt_vf_reps_open(bp
);
7364 bnxt_debug_dev_exit(bp
);
7365 bnxt_disable_napi(bp
);
7373 bnxt_free_mem(bp
, true);
7377 /* rtnl_lock held */
7378 int bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
7382 rc
= __bnxt_open_nic(bp
, irq_re_init
, link_re_init
);
7384 netdev_err(bp
->dev
, "nic open fail (rc: %x)\n", rc
);
7390 /* rtnl_lock held, open the NIC half way by allocating all resources, but
7391 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
7394 int bnxt_half_open_nic(struct bnxt
*bp
)
7398 rc
= bnxt_alloc_mem(bp
, false);
7400 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
7403 rc
= bnxt_init_nic(bp
, false);
7405 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
7412 bnxt_free_mem(bp
, false);
7417 /* rtnl_lock held, this call can only be made after a previous successful
7418 * call to bnxt_half_open_nic().
7420 void bnxt_half_close_nic(struct bnxt
*bp
)
7422 bnxt_hwrm_resource_free(bp
, false, false);
7424 bnxt_free_mem(bp
, false);
7427 static int bnxt_open(struct net_device
*dev
)
7429 struct bnxt
*bp
= netdev_priv(dev
);
7432 bnxt_hwrm_if_change(bp
, true);
7433 rc
= __bnxt_open_nic(bp
, true, true);
7435 bnxt_hwrm_if_change(bp
, false);
7437 bnxt_hwmon_open(bp
);
7442 static bool bnxt_drv_busy(struct bnxt
*bp
)
7444 return (test_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
) ||
7445 test_bit(BNXT_STATE_READ_STATS
, &bp
->state
));
7448 static void __bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
,
7451 /* Close the VF-reps before closing PF */
7453 bnxt_vf_reps_close(bp
);
7455 /* Change device state to avoid TX queue wake up's */
7456 bnxt_tx_disable(bp
);
7458 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
7459 smp_mb__after_atomic();
7460 while (bnxt_drv_busy(bp
))
7463 /* Flush rings and and disable interrupts */
7464 bnxt_shutdown_nic(bp
, irq_re_init
);
7466 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
7468 bnxt_debug_dev_exit(bp
);
7469 bnxt_disable_napi(bp
);
7470 del_timer_sync(&bp
->timer
);
7477 bnxt_free_mem(bp
, irq_re_init
);
7480 int bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
7484 #ifdef CONFIG_BNXT_SRIOV
7485 if (bp
->sriov_cfg
) {
7486 rc
= wait_event_interruptible_timeout(bp
->sriov_cfg_wait
,
7488 BNXT_SRIOV_CFG_WAIT_TMO
);
7490 netdev_warn(bp
->dev
, "timeout waiting for SRIOV config operation to complete!\n");
7493 __bnxt_close_nic(bp
, irq_re_init
, link_re_init
);
7497 static int bnxt_close(struct net_device
*dev
)
7499 struct bnxt
*bp
= netdev_priv(dev
);
7501 bnxt_hwmon_close(bp
);
7502 bnxt_close_nic(bp
, true, true);
7503 bnxt_hwrm_shutdown_link(bp
);
7504 bnxt_hwrm_if_change(bp
, false);
7508 /* rtnl_lock held */
7509 static int bnxt_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
7515 if (!netif_running(dev
))
7522 if (!netif_running(dev
))
7535 bnxt_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
7538 struct bnxt
*bp
= netdev_priv(dev
);
7540 set_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
7541 /* Make sure bnxt_close_nic() sees that we are reading stats before
7542 * we check the BNXT_STATE_OPEN flag.
7544 smp_mb__after_atomic();
7545 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
7546 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
7550 /* TODO check if we need to synchronize with bnxt_close path */
7551 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7552 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
7553 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
7554 struct ctx_hw_stats
*hw_stats
= cpr
->hw_stats
;
7556 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_ucast_pkts
);
7557 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
7558 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_bcast_pkts
);
7560 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_ucast_pkts
);
7561 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_mcast_pkts
);
7562 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_bcast_pkts
);
7564 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_ucast_bytes
);
7565 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_mcast_bytes
);
7566 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_bcast_bytes
);
7568 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_ucast_bytes
);
7569 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_mcast_bytes
);
7570 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_bcast_bytes
);
7572 stats
->rx_missed_errors
+=
7573 le64_to_cpu(hw_stats
->rx_discard_pkts
);
7575 stats
->multicast
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
7577 stats
->tx_dropped
+= le64_to_cpu(hw_stats
->tx_drop_pkts
);
7580 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
7581 struct rx_port_stats
*rx
= bp
->hw_rx_port_stats
;
7582 struct tx_port_stats
*tx
= bp
->hw_tx_port_stats
;
7584 stats
->rx_crc_errors
= le64_to_cpu(rx
->rx_fcs_err_frames
);
7585 stats
->rx_frame_errors
= le64_to_cpu(rx
->rx_align_err_frames
);
7586 stats
->rx_length_errors
= le64_to_cpu(rx
->rx_undrsz_frames
) +
7587 le64_to_cpu(rx
->rx_ovrsz_frames
) +
7588 le64_to_cpu(rx
->rx_runt_frames
);
7589 stats
->rx_errors
= le64_to_cpu(rx
->rx_false_carrier_frames
) +
7590 le64_to_cpu(rx
->rx_jbr_frames
);
7591 stats
->collisions
= le64_to_cpu(tx
->tx_total_collisions
);
7592 stats
->tx_fifo_errors
= le64_to_cpu(tx
->tx_fifo_underruns
);
7593 stats
->tx_errors
= le64_to_cpu(tx
->tx_err
);
7595 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
7598 static bool bnxt_mc_list_updated(struct bnxt
*bp
, u32
*rx_mask
)
7600 struct net_device
*dev
= bp
->dev
;
7601 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7602 struct netdev_hw_addr
*ha
;
7605 bool update
= false;
7608 netdev_for_each_mc_addr(ha
, dev
) {
7609 if (mc_count
>= BNXT_MAX_MC_ADDRS
) {
7610 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
7611 vnic
->mc_list_count
= 0;
7615 if (!ether_addr_equal(haddr
, vnic
->mc_list
+ off
)) {
7616 memcpy(vnic
->mc_list
+ off
, haddr
, ETH_ALEN
);
7623 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
;
7625 if (mc_count
!= vnic
->mc_list_count
) {
7626 vnic
->mc_list_count
= mc_count
;
7632 static bool bnxt_uc_list_updated(struct bnxt
*bp
)
7634 struct net_device
*dev
= bp
->dev
;
7635 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7636 struct netdev_hw_addr
*ha
;
7639 if (netdev_uc_count(dev
) != (vnic
->uc_filter_count
- 1))
7642 netdev_for_each_uc_addr(ha
, dev
) {
7643 if (!ether_addr_equal(ha
->addr
, vnic
->uc_list
+ off
))
7651 static void bnxt_set_rx_mode(struct net_device
*dev
)
7653 struct bnxt
*bp
= netdev_priv(dev
);
7654 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7655 u32 mask
= vnic
->rx_mask
;
7656 bool mc_update
= false;
7659 if (!netif_running(dev
))
7662 mask
&= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
|
7663 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
|
7664 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
|
7665 CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
);
7667 if ((dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
7668 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
7670 uc_update
= bnxt_uc_list_updated(bp
);
7672 if (dev
->flags
& IFF_BROADCAST
)
7673 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
7674 if (dev
->flags
& IFF_ALLMULTI
) {
7675 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
7676 vnic
->mc_list_count
= 0;
7678 mc_update
= bnxt_mc_list_updated(bp
, &mask
);
7681 if (mask
!= vnic
->rx_mask
|| uc_update
|| mc_update
) {
7682 vnic
->rx_mask
= mask
;
7684 set_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
);
7685 bnxt_queue_sp_work(bp
);
7689 static int bnxt_cfg_rx_mode(struct bnxt
*bp
)
7691 struct net_device
*dev
= bp
->dev
;
7692 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7693 struct netdev_hw_addr
*ha
;
7697 netif_addr_lock_bh(dev
);
7698 uc_update
= bnxt_uc_list_updated(bp
);
7699 netif_addr_unlock_bh(dev
);
7704 mutex_lock(&bp
->hwrm_cmd_lock
);
7705 for (i
= 1; i
< vnic
->uc_filter_count
; i
++) {
7706 struct hwrm_cfa_l2_filter_free_input req
= {0};
7708 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_FREE
, -1,
7711 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[i
];
7713 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
7716 mutex_unlock(&bp
->hwrm_cmd_lock
);
7718 vnic
->uc_filter_count
= 1;
7720 netif_addr_lock_bh(dev
);
7721 if (netdev_uc_count(dev
) > (BNXT_MAX_UC_ADDRS
- 1)) {
7722 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
7724 netdev_for_each_uc_addr(ha
, dev
) {
7725 memcpy(vnic
->uc_list
+ off
, ha
->addr
, ETH_ALEN
);
7727 vnic
->uc_filter_count
++;
7730 netif_addr_unlock_bh(dev
);
7732 for (i
= 1, off
= 0; i
< vnic
->uc_filter_count
; i
++, off
+= ETH_ALEN
) {
7733 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, i
, vnic
->uc_list
+ off
);
7735 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n",
7737 vnic
->uc_filter_count
= i
;
7743 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
7745 netdev_err(bp
->dev
, "HWRM cfa l2 rx mask failure rc: %x\n",
7751 static bool bnxt_can_reserve_rings(struct bnxt
*bp
)
7753 #ifdef CONFIG_BNXT_SRIOV
7754 if (BNXT_NEW_RM(bp
) && BNXT_VF(bp
)) {
7755 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7757 /* No minimum rings were provisioned by the PF. Don't
7758 * reserve rings by default when device is down.
7760 if (hw_resc
->min_tx_rings
|| hw_resc
->resv_tx_rings
)
7763 if (!netif_running(bp
->dev
))
7770 /* If the chip and firmware supports RFS */
7771 static bool bnxt_rfs_supported(struct bnxt
*bp
)
7773 if (BNXT_PF(bp
) && !BNXT_CHIP_TYPE_NITRO_A0(bp
))
7775 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
7780 /* If runtime conditions support RFS */
7781 static bool bnxt_rfs_capable(struct bnxt
*bp
)
7783 #ifdef CONFIG_RFS_ACCEL
7784 int vnics
, max_vnics
, max_rss_ctxs
;
7786 if (!(bp
->flags
& BNXT_FLAG_MSIX_CAP
) || !bnxt_can_reserve_rings(bp
))
7789 vnics
= 1 + bp
->rx_nr_rings
;
7790 max_vnics
= bnxt_get_max_func_vnics(bp
);
7791 max_rss_ctxs
= bnxt_get_max_func_rss_ctxs(bp
);
7793 /* RSS contexts not a limiting factor */
7794 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
7795 max_rss_ctxs
= max_vnics
;
7796 if (vnics
> max_vnics
|| vnics
> max_rss_ctxs
) {
7797 if (bp
->rx_nr_rings
> 1)
7798 netdev_warn(bp
->dev
,
7799 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
7800 min(max_rss_ctxs
- 1, max_vnics
- 1));
7804 if (!BNXT_NEW_RM(bp
))
7807 if (vnics
== bp
->hw_resc
.resv_vnics
)
7810 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, vnics
);
7811 if (vnics
<= bp
->hw_resc
.resv_vnics
)
7814 netdev_warn(bp
->dev
, "Unable to reserve resources to support NTUPLE filters.\n");
7815 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 1);
7822 static netdev_features_t
bnxt_fix_features(struct net_device
*dev
,
7823 netdev_features_t features
)
7825 struct bnxt
*bp
= netdev_priv(dev
);
7827 if ((features
& NETIF_F_NTUPLE
) && !bnxt_rfs_capable(bp
))
7828 features
&= ~NETIF_F_NTUPLE
;
7830 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
7831 features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
7833 if (!(features
& NETIF_F_GRO
))
7834 features
&= ~NETIF_F_GRO_HW
;
7836 if (features
& NETIF_F_GRO_HW
)
7837 features
&= ~NETIF_F_LRO
;
7839 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
7840 * turned on or off together.
7842 if ((features
& (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) !=
7843 (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) {
7844 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
7845 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
7846 NETIF_F_HW_VLAN_STAG_RX
);
7848 features
|= NETIF_F_HW_VLAN_CTAG_RX
|
7849 NETIF_F_HW_VLAN_STAG_RX
;
7851 #ifdef CONFIG_BNXT_SRIOV
7854 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
7855 NETIF_F_HW_VLAN_STAG_RX
);
7862 static int bnxt_set_features(struct net_device
*dev
, netdev_features_t features
)
7864 struct bnxt
*bp
= netdev_priv(dev
);
7865 u32 flags
= bp
->flags
;
7868 bool re_init
= false;
7869 bool update_tpa
= false;
7871 flags
&= ~BNXT_FLAG_ALL_CONFIG_FEATS
;
7872 if (features
& NETIF_F_GRO_HW
)
7873 flags
|= BNXT_FLAG_GRO
;
7874 else if (features
& NETIF_F_LRO
)
7875 flags
|= BNXT_FLAG_LRO
;
7877 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
7878 flags
&= ~BNXT_FLAG_TPA
;
7880 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
7881 flags
|= BNXT_FLAG_STRIP_VLAN
;
7883 if (features
& NETIF_F_NTUPLE
)
7884 flags
|= BNXT_FLAG_RFS
;
7886 changes
= flags
^ bp
->flags
;
7887 if (changes
& BNXT_FLAG_TPA
) {
7889 if ((bp
->flags
& BNXT_FLAG_TPA
) == 0 ||
7890 (flags
& BNXT_FLAG_TPA
) == 0)
7894 if (changes
& ~BNXT_FLAG_TPA
)
7897 if (flags
!= bp
->flags
) {
7898 u32 old_flags
= bp
->flags
;
7902 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
7904 bnxt_set_ring_params(bp
);
7909 bnxt_close_nic(bp
, false, false);
7911 bnxt_set_ring_params(bp
);
7913 return bnxt_open_nic(bp
, false, false);
7916 rc
= bnxt_set_tpa(bp
,
7917 (flags
& BNXT_FLAG_TPA
) ?
7920 bp
->flags
= old_flags
;
7926 static void bnxt_dump_tx_sw_state(struct bnxt_napi
*bnapi
)
7928 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
7929 int i
= bnapi
->index
;
7934 netdev_info(bnapi
->bp
->dev
, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
7935 i
, txr
->tx_ring_struct
.fw_ring_id
, txr
->tx_prod
,
7939 static void bnxt_dump_rx_sw_state(struct bnxt_napi
*bnapi
)
7941 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
7942 int i
= bnapi
->index
;
7947 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",
7948 i
, rxr
->rx_ring_struct
.fw_ring_id
, rxr
->rx_prod
,
7949 rxr
->rx_agg_ring_struct
.fw_ring_id
, rxr
->rx_agg_prod
,
7950 rxr
->rx_sw_agg_prod
);
7953 static void bnxt_dump_cp_sw_state(struct bnxt_napi
*bnapi
)
7955 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
7956 int i
= bnapi
->index
;
7958 netdev_info(bnapi
->bp
->dev
, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
7959 i
, cpr
->cp_ring_struct
.fw_ring_id
, cpr
->cp_raw_cons
);
7962 static void bnxt_dbg_dump_states(struct bnxt
*bp
)
7965 struct bnxt_napi
*bnapi
;
7967 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7968 bnapi
= bp
->bnapi
[i
];
7969 if (netif_msg_drv(bp
)) {
7970 bnxt_dump_tx_sw_state(bnapi
);
7971 bnxt_dump_rx_sw_state(bnapi
);
7972 bnxt_dump_cp_sw_state(bnapi
);
7977 static void bnxt_reset_task(struct bnxt
*bp
, bool silent
)
7980 bnxt_dbg_dump_states(bp
);
7981 if (netif_running(bp
->dev
)) {
7986 bnxt_close_nic(bp
, false, false);
7987 rc
= bnxt_open_nic(bp
, false, false);
7993 static void bnxt_tx_timeout(struct net_device
*dev
)
7995 struct bnxt
*bp
= netdev_priv(dev
);
7997 netdev_err(bp
->dev
, "TX timeout detected, starting reset task!\n");
7998 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
7999 bnxt_queue_sp_work(bp
);
8002 static void bnxt_timer(struct timer_list
*t
)
8004 struct bnxt
*bp
= from_timer(bp
, t
, timer
);
8005 struct net_device
*dev
= bp
->dev
;
8007 if (!netif_running(dev
))
8010 if (atomic_read(&bp
->intr_sem
) != 0)
8011 goto bnxt_restart_timer
;
8013 if (bp
->link_info
.link_up
&& (bp
->flags
& BNXT_FLAG_PORT_STATS
) &&
8014 bp
->stats_coal_ticks
) {
8015 set_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
);
8016 bnxt_queue_sp_work(bp
);
8019 if (bnxt_tc_flower_enabled(bp
)) {
8020 set_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
);
8021 bnxt_queue_sp_work(bp
);
8024 if (bp
->link_info
.phy_retry
) {
8025 if (time_after(jiffies
, bp
->link_info
.phy_retry_expires
)) {
8026 bp
->link_info
.phy_retry
= 0;
8027 netdev_warn(bp
->dev
, "failed to update phy settings after maximum retries.\n");
8029 set_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
);
8030 bnxt_queue_sp_work(bp
);
8034 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
8037 static void bnxt_rtnl_lock_sp(struct bnxt
*bp
)
8039 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
8040 * set. If the device is being closed, bnxt_close() may be holding
8041 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
8042 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
8044 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
8048 static void bnxt_rtnl_unlock_sp(struct bnxt
*bp
)
8050 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
8054 /* Only called from bnxt_sp_task() */
8055 static void bnxt_reset(struct bnxt
*bp
, bool silent
)
8057 bnxt_rtnl_lock_sp(bp
);
8058 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
))
8059 bnxt_reset_task(bp
, silent
);
8060 bnxt_rtnl_unlock_sp(bp
);
8063 static void bnxt_cfg_ntp_filters(struct bnxt
*);
8065 static void bnxt_sp_task(struct work_struct
*work
)
8067 struct bnxt
*bp
= container_of(work
, struct bnxt
, sp_task
);
8069 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
8070 smp_mb__after_atomic();
8071 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
8072 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
8076 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
))
8077 bnxt_cfg_rx_mode(bp
);
8079 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
))
8080 bnxt_cfg_ntp_filters(bp
);
8081 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
))
8082 bnxt_hwrm_exec_fwd_req(bp
);
8083 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
8084 bnxt_hwrm_tunnel_dst_port_alloc(
8086 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
8088 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
8089 bnxt_hwrm_tunnel_dst_port_free(
8090 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
8092 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
8093 bnxt_hwrm_tunnel_dst_port_alloc(
8095 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
8097 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
8098 bnxt_hwrm_tunnel_dst_port_free(
8099 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
8101 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
)) {
8102 bnxt_hwrm_port_qstats(bp
);
8103 bnxt_hwrm_port_qstats_ext(bp
);
8106 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
)) {
8109 mutex_lock(&bp
->link_lock
);
8110 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
,
8112 bnxt_hwrm_phy_qcaps(bp
);
8114 rc
= bnxt_update_link(bp
, true);
8115 mutex_unlock(&bp
->link_lock
);
8117 netdev_err(bp
->dev
, "SP task can't update link (rc: %x)\n",
8120 if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
)) {
8123 mutex_lock(&bp
->link_lock
);
8124 rc
= bnxt_update_phy_setting(bp
);
8125 mutex_unlock(&bp
->link_lock
);
8127 netdev_warn(bp
->dev
, "update phy settings retry failed\n");
8129 bp
->link_info
.phy_retry
= false;
8130 netdev_info(bp
->dev
, "update phy settings retry succeeded\n");
8133 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
)) {
8134 mutex_lock(&bp
->link_lock
);
8135 bnxt_get_port_module_status(bp
);
8136 mutex_unlock(&bp
->link_lock
);
8139 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
))
8140 bnxt_tc_flow_stats_work(bp
);
8142 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
8143 * must be the last functions to be called before exiting.
8145 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
))
8146 bnxt_reset(bp
, false);
8148 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
))
8149 bnxt_reset(bp
, true);
8151 smp_mb__before_atomic();
8152 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
8155 /* Under rtnl_lock */
8156 int bnxt_check_rings(struct bnxt
*bp
, int tx
, int rx
, bool sh
, int tcs
,
8159 int max_rx
, max_tx
, tx_sets
= 1;
8160 int tx_rings_needed
;
8167 rc
= bnxt_get_max_rings(bp
, &max_rx
, &max_tx
, sh
);
8174 tx_rings_needed
= tx
* tx_sets
+ tx_xdp
;
8175 if (max_tx
< tx_rings_needed
)
8179 if (bp
->flags
& BNXT_FLAG_RFS
)
8182 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
8184 cp
= sh
? max_t(int, tx_rings_needed
, rx
) : tx_rings_needed
+ rx
;
8185 if (BNXT_NEW_RM(bp
))
8186 cp
+= bnxt_get_ulp_msix_num(bp
);
8187 return bnxt_hwrm_check_rings(bp
, tx_rings_needed
, rx_rings
, rx
, cp
,
8191 static void bnxt_unmap_bars(struct bnxt
*bp
, struct pci_dev
*pdev
)
8194 pci_iounmap(pdev
, bp
->bar2
);
8199 pci_iounmap(pdev
, bp
->bar1
);
8204 pci_iounmap(pdev
, bp
->bar0
);
8209 static void bnxt_cleanup_pci(struct bnxt
*bp
)
8211 bnxt_unmap_bars(bp
, bp
->pdev
);
8212 pci_release_regions(bp
->pdev
);
8213 pci_disable_device(bp
->pdev
);
8216 static void bnxt_init_dflt_coal(struct bnxt
*bp
)
8218 struct bnxt_coal
*coal
;
8220 /* Tick values in micro seconds.
8221 * 1 coal_buf x bufs_per_record = 1 completion record.
8223 coal
= &bp
->rx_coal
;
8224 coal
->coal_ticks
= 14;
8225 coal
->coal_bufs
= 30;
8226 coal
->coal_ticks_irq
= 1;
8227 coal
->coal_bufs_irq
= 2;
8228 coal
->idle_thresh
= 50;
8229 coal
->bufs_per_record
= 2;
8230 coal
->budget
= 64; /* NAPI budget */
8232 coal
= &bp
->tx_coal
;
8233 coal
->coal_ticks
= 28;
8234 coal
->coal_bufs
= 30;
8235 coal
->coal_ticks_irq
= 2;
8236 coal
->coal_bufs_irq
= 2;
8237 coal
->bufs_per_record
= 1;
8239 bp
->stats_coal_ticks
= BNXT_DEF_STATS_COAL_TICKS
;
8242 static int bnxt_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
8245 struct bnxt
*bp
= netdev_priv(dev
);
8247 SET_NETDEV_DEV(dev
, &pdev
->dev
);
8249 /* enable device (incl. PCI PM wakeup), and bus-mastering */
8250 rc
= pci_enable_device(pdev
);
8252 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
8256 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
8258 "Cannot find PCI device base address, aborting\n");
8260 goto init_err_disable
;
8263 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
8265 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
8266 goto init_err_disable
;
8269 if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64)) != 0 &&
8270 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)) != 0) {
8271 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
8272 goto init_err_disable
;
8275 pci_set_master(pdev
);
8280 bp
->bar0
= pci_ioremap_bar(pdev
, 0);
8282 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
8284 goto init_err_release
;
8287 bp
->bar1
= pci_ioremap_bar(pdev
, 2);
8289 dev_err(&pdev
->dev
, "Cannot map doorbell registers, aborting\n");
8291 goto init_err_release
;
8294 bp
->bar2
= pci_ioremap_bar(pdev
, 4);
8296 dev_err(&pdev
->dev
, "Cannot map bar4 registers, aborting\n");
8298 goto init_err_release
;
8301 pci_enable_pcie_error_reporting(pdev
);
8303 INIT_WORK(&bp
->sp_task
, bnxt_sp_task
);
8305 spin_lock_init(&bp
->ntp_fltr_lock
);
8307 bp
->rx_ring_size
= BNXT_DEFAULT_RX_RING_SIZE
;
8308 bp
->tx_ring_size
= BNXT_DEFAULT_TX_RING_SIZE
;
8310 bnxt_init_dflt_coal(bp
);
8312 timer_setup(&bp
->timer
, bnxt_timer
, 0);
8313 bp
->current_interval
= BNXT_TIMER_INTERVAL
;
8315 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
8319 bnxt_unmap_bars(bp
, pdev
);
8320 pci_release_regions(pdev
);
8323 pci_disable_device(pdev
);
8329 /* rtnl_lock held */
8330 static int bnxt_change_mac_addr(struct net_device
*dev
, void *p
)
8332 struct sockaddr
*addr
= p
;
8333 struct bnxt
*bp
= netdev_priv(dev
);
8336 if (!is_valid_ether_addr(addr
->sa_data
))
8337 return -EADDRNOTAVAIL
;
8339 if (ether_addr_equal(addr
->sa_data
, dev
->dev_addr
))
8342 rc
= bnxt_approve_mac(bp
, addr
->sa_data
, true);
8346 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
8347 if (netif_running(dev
)) {
8348 bnxt_close_nic(bp
, false, false);
8349 rc
= bnxt_open_nic(bp
, false, false);
8355 /* rtnl_lock held */
8356 static int bnxt_change_mtu(struct net_device
*dev
, int new_mtu
)
8358 struct bnxt
*bp
= netdev_priv(dev
);
8360 if (netif_running(dev
))
8361 bnxt_close_nic(bp
, false, false);
8364 bnxt_set_ring_params(bp
);
8366 if (netif_running(dev
))
8367 return bnxt_open_nic(bp
, false, false);
8372 int bnxt_setup_mq_tc(struct net_device
*dev
, u8 tc
)
8374 struct bnxt
*bp
= netdev_priv(dev
);
8378 if (tc
> bp
->max_tc
) {
8379 netdev_err(dev
, "Too many traffic classes requested: %d. Max supported is %d.\n",
8384 if (netdev_get_num_tc(dev
) == tc
)
8387 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
8390 rc
= bnxt_check_rings(bp
, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
,
8391 sh
, tc
, bp
->tx_nr_rings_xdp
);
8395 /* Needs to close the device and do hw resource re-allocations */
8396 if (netif_running(bp
->dev
))
8397 bnxt_close_nic(bp
, true, false);
8400 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tc
;
8401 netdev_set_num_tc(dev
, tc
);
8403 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
8404 netdev_reset_tc(dev
);
8406 bp
->tx_nr_rings
+= bp
->tx_nr_rings_xdp
;
8407 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
8408 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
8409 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
8411 if (netif_running(bp
->dev
))
8412 return bnxt_open_nic(bp
, true, false);
8417 static int bnxt_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
8420 struct bnxt
*bp
= cb_priv
;
8422 if (!bnxt_tc_flower_enabled(bp
) ||
8423 !tc_cls_can_offload_and_chain0(bp
->dev
, type_data
))
8427 case TC_SETUP_CLSFLOWER
:
8428 return bnxt_tc_setup_flower(bp
, bp
->pf
.fw_fid
, type_data
);
8434 static int bnxt_setup_tc_block(struct net_device
*dev
,
8435 struct tc_block_offload
*f
)
8437 struct bnxt
*bp
= netdev_priv(dev
);
8439 if (f
->binder_type
!= TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS
)
8442 switch (f
->command
) {
8444 return tcf_block_cb_register(f
->block
, bnxt_setup_tc_block_cb
,
8446 case TC_BLOCK_UNBIND
:
8447 tcf_block_cb_unregister(f
->block
, bnxt_setup_tc_block_cb
, bp
);
8454 static int bnxt_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
8458 case TC_SETUP_BLOCK
:
8459 return bnxt_setup_tc_block(dev
, type_data
);
8460 case TC_SETUP_QDISC_MQPRIO
: {
8461 struct tc_mqprio_qopt
*mqprio
= type_data
;
8463 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
8465 return bnxt_setup_mq_tc(dev
, mqprio
->num_tc
);
8472 #ifdef CONFIG_RFS_ACCEL
8473 static bool bnxt_fltr_match(struct bnxt_ntuple_filter
*f1
,
8474 struct bnxt_ntuple_filter
*f2
)
8476 struct flow_keys
*keys1
= &f1
->fkeys
;
8477 struct flow_keys
*keys2
= &f2
->fkeys
;
8479 if (keys1
->addrs
.v4addrs
.src
== keys2
->addrs
.v4addrs
.src
&&
8480 keys1
->addrs
.v4addrs
.dst
== keys2
->addrs
.v4addrs
.dst
&&
8481 keys1
->ports
.ports
== keys2
->ports
.ports
&&
8482 keys1
->basic
.ip_proto
== keys2
->basic
.ip_proto
&&
8483 keys1
->basic
.n_proto
== keys2
->basic
.n_proto
&&
8484 keys1
->control
.flags
== keys2
->control
.flags
&&
8485 ether_addr_equal(f1
->src_mac_addr
, f2
->src_mac_addr
) &&
8486 ether_addr_equal(f1
->dst_mac_addr
, f2
->dst_mac_addr
))
8492 static int bnxt_rx_flow_steer(struct net_device
*dev
, const struct sk_buff
*skb
,
8493 u16 rxq_index
, u32 flow_id
)
8495 struct bnxt
*bp
= netdev_priv(dev
);
8496 struct bnxt_ntuple_filter
*fltr
, *new_fltr
;
8497 struct flow_keys
*fkeys
;
8498 struct ethhdr
*eth
= (struct ethhdr
*)skb_mac_header(skb
);
8499 int rc
= 0, idx
, bit_id
, l2_idx
= 0;
8500 struct hlist_head
*head
;
8502 if (!ether_addr_equal(dev
->dev_addr
, eth
->h_dest
)) {
8503 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8506 netif_addr_lock_bh(dev
);
8507 for (j
= 0; j
< vnic
->uc_filter_count
; j
++, off
+= ETH_ALEN
) {
8508 if (ether_addr_equal(eth
->h_dest
,
8509 vnic
->uc_list
+ off
)) {
8514 netif_addr_unlock_bh(dev
);
8518 new_fltr
= kzalloc(sizeof(*new_fltr
), GFP_ATOMIC
);
8522 fkeys
= &new_fltr
->fkeys
;
8523 if (!skb_flow_dissect_flow_keys(skb
, fkeys
, 0)) {
8524 rc
= -EPROTONOSUPPORT
;
8528 if ((fkeys
->basic
.n_proto
!= htons(ETH_P_IP
) &&
8529 fkeys
->basic
.n_proto
!= htons(ETH_P_IPV6
)) ||
8530 ((fkeys
->basic
.ip_proto
!= IPPROTO_TCP
) &&
8531 (fkeys
->basic
.ip_proto
!= IPPROTO_UDP
))) {
8532 rc
= -EPROTONOSUPPORT
;
8535 if (fkeys
->basic
.n_proto
== htons(ETH_P_IPV6
) &&
8536 bp
->hwrm_spec_code
< 0x10601) {
8537 rc
= -EPROTONOSUPPORT
;
8540 if ((fkeys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) &&
8541 bp
->hwrm_spec_code
< 0x10601) {
8542 rc
= -EPROTONOSUPPORT
;
8546 memcpy(new_fltr
->dst_mac_addr
, eth
->h_dest
, ETH_ALEN
);
8547 memcpy(new_fltr
->src_mac_addr
, eth
->h_source
, ETH_ALEN
);
8549 idx
= skb_get_hash_raw(skb
) & BNXT_NTP_FLTR_HASH_MASK
;
8550 head
= &bp
->ntp_fltr_hash_tbl
[idx
];
8552 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
8553 if (bnxt_fltr_match(fltr
, new_fltr
)) {
8561 spin_lock_bh(&bp
->ntp_fltr_lock
);
8562 bit_id
= bitmap_find_free_region(bp
->ntp_fltr_bmap
,
8563 BNXT_NTP_FLTR_MAX_FLTR
, 0);
8565 spin_unlock_bh(&bp
->ntp_fltr_lock
);
8570 new_fltr
->sw_id
= (u16
)bit_id
;
8571 new_fltr
->flow_id
= flow_id
;
8572 new_fltr
->l2_fltr_idx
= l2_idx
;
8573 new_fltr
->rxq
= rxq_index
;
8574 hlist_add_head_rcu(&new_fltr
->hash
, head
);
8575 bp
->ntp_fltr_count
++;
8576 spin_unlock_bh(&bp
->ntp_fltr_lock
);
8578 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
8579 bnxt_queue_sp_work(bp
);
8581 return new_fltr
->sw_id
;
8588 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
8592 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
8593 struct hlist_head
*head
;
8594 struct hlist_node
*tmp
;
8595 struct bnxt_ntuple_filter
*fltr
;
8598 head
= &bp
->ntp_fltr_hash_tbl
[i
];
8599 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
8602 if (test_bit(BNXT_FLTR_VALID
, &fltr
->state
)) {
8603 if (rps_may_expire_flow(bp
->dev
, fltr
->rxq
,
8606 bnxt_hwrm_cfa_ntuple_filter_free(bp
,
8611 rc
= bnxt_hwrm_cfa_ntuple_filter_alloc(bp
,
8616 set_bit(BNXT_FLTR_VALID
, &fltr
->state
);
8620 spin_lock_bh(&bp
->ntp_fltr_lock
);
8621 hlist_del_rcu(&fltr
->hash
);
8622 bp
->ntp_fltr_count
--;
8623 spin_unlock_bh(&bp
->ntp_fltr_lock
);
8625 clear_bit(fltr
->sw_id
, bp
->ntp_fltr_bmap
);
8630 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
))
8631 netdev_info(bp
->dev
, "Receive PF driver unload event!");
8636 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
8640 #endif /* CONFIG_RFS_ACCEL */
8642 static void bnxt_udp_tunnel_add(struct net_device
*dev
,
8643 struct udp_tunnel_info
*ti
)
8645 struct bnxt
*bp
= netdev_priv(dev
);
8647 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
8650 if (!netif_running(dev
))
8654 case UDP_TUNNEL_TYPE_VXLAN
:
8655 if (bp
->vxlan_port_cnt
&& bp
->vxlan_port
!= ti
->port
)
8658 bp
->vxlan_port_cnt
++;
8659 if (bp
->vxlan_port_cnt
== 1) {
8660 bp
->vxlan_port
= ti
->port
;
8661 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
8662 bnxt_queue_sp_work(bp
);
8665 case UDP_TUNNEL_TYPE_GENEVE
:
8666 if (bp
->nge_port_cnt
&& bp
->nge_port
!= ti
->port
)
8670 if (bp
->nge_port_cnt
== 1) {
8671 bp
->nge_port
= ti
->port
;
8672 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
8679 bnxt_queue_sp_work(bp
);
8682 static void bnxt_udp_tunnel_del(struct net_device
*dev
,
8683 struct udp_tunnel_info
*ti
)
8685 struct bnxt
*bp
= netdev_priv(dev
);
8687 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
8690 if (!netif_running(dev
))
8694 case UDP_TUNNEL_TYPE_VXLAN
:
8695 if (!bp
->vxlan_port_cnt
|| bp
->vxlan_port
!= ti
->port
)
8697 bp
->vxlan_port_cnt
--;
8699 if (bp
->vxlan_port_cnt
!= 0)
8702 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
8704 case UDP_TUNNEL_TYPE_GENEVE
:
8705 if (!bp
->nge_port_cnt
|| bp
->nge_port
!= ti
->port
)
8709 if (bp
->nge_port_cnt
!= 0)
8712 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
8718 bnxt_queue_sp_work(bp
);
8721 static int bnxt_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8722 struct net_device
*dev
, u32 filter_mask
,
8725 struct bnxt
*bp
= netdev_priv(dev
);
8727 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, bp
->br_mode
, 0, 0,
8728 nlflags
, filter_mask
, NULL
);
8731 static int bnxt_bridge_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
,
8734 struct bnxt
*bp
= netdev_priv(dev
);
8735 struct nlattr
*attr
, *br_spec
;
8738 if (bp
->hwrm_spec_code
< 0x10708 || !BNXT_SINGLE_PF(bp
))
8741 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8745 nla_for_each_nested(attr
, br_spec
, rem
) {
8748 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8751 if (nla_len(attr
) < sizeof(mode
))
8754 mode
= nla_get_u16(attr
);
8755 if (mode
== bp
->br_mode
)
8758 rc
= bnxt_hwrm_set_br_mode(bp
, mode
);
8766 static int bnxt_get_phys_port_name(struct net_device
*dev
, char *buf
,
8769 struct bnxt
*bp
= netdev_priv(dev
);
8772 /* The PF and it's VF-reps only support the switchdev framework */
8776 rc
= snprintf(buf
, len
, "p%d", bp
->pf
.port_id
);
8783 int bnxt_port_attr_get(struct bnxt
*bp
, struct switchdev_attr
*attr
)
8785 if (bp
->eswitch_mode
!= DEVLINK_ESWITCH_MODE_SWITCHDEV
)
8788 /* The PF and it's VF-reps only support the switchdev framework */
8793 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID
:
8794 attr
->u
.ppid
.id_len
= sizeof(bp
->switch_id
);
8795 memcpy(attr
->u
.ppid
.id
, bp
->switch_id
, attr
->u
.ppid
.id_len
);
8803 static int bnxt_swdev_port_attr_get(struct net_device
*dev
,
8804 struct switchdev_attr
*attr
)
8806 return bnxt_port_attr_get(netdev_priv(dev
), attr
);
8809 static const struct switchdev_ops bnxt_switchdev_ops
= {
8810 .switchdev_port_attr_get
= bnxt_swdev_port_attr_get
8813 static const struct net_device_ops bnxt_netdev_ops
= {
8814 .ndo_open
= bnxt_open
,
8815 .ndo_start_xmit
= bnxt_start_xmit
,
8816 .ndo_stop
= bnxt_close
,
8817 .ndo_get_stats64
= bnxt_get_stats64
,
8818 .ndo_set_rx_mode
= bnxt_set_rx_mode
,
8819 .ndo_do_ioctl
= bnxt_ioctl
,
8820 .ndo_validate_addr
= eth_validate_addr
,
8821 .ndo_set_mac_address
= bnxt_change_mac_addr
,
8822 .ndo_change_mtu
= bnxt_change_mtu
,
8823 .ndo_fix_features
= bnxt_fix_features
,
8824 .ndo_set_features
= bnxt_set_features
,
8825 .ndo_tx_timeout
= bnxt_tx_timeout
,
8826 #ifdef CONFIG_BNXT_SRIOV
8827 .ndo_get_vf_config
= bnxt_get_vf_config
,
8828 .ndo_set_vf_mac
= bnxt_set_vf_mac
,
8829 .ndo_set_vf_vlan
= bnxt_set_vf_vlan
,
8830 .ndo_set_vf_rate
= bnxt_set_vf_bw
,
8831 .ndo_set_vf_link_state
= bnxt_set_vf_link_state
,
8832 .ndo_set_vf_spoofchk
= bnxt_set_vf_spoofchk
,
8833 .ndo_set_vf_trust
= bnxt_set_vf_trust
,
8835 .ndo_setup_tc
= bnxt_setup_tc
,
8836 #ifdef CONFIG_RFS_ACCEL
8837 .ndo_rx_flow_steer
= bnxt_rx_flow_steer
,
8839 .ndo_udp_tunnel_add
= bnxt_udp_tunnel_add
,
8840 .ndo_udp_tunnel_del
= bnxt_udp_tunnel_del
,
8841 .ndo_bpf
= bnxt_xdp
,
8842 .ndo_bridge_getlink
= bnxt_bridge_getlink
,
8843 .ndo_bridge_setlink
= bnxt_bridge_setlink
,
8844 .ndo_get_phys_port_name
= bnxt_get_phys_port_name
8847 static void bnxt_remove_one(struct pci_dev
*pdev
)
8849 struct net_device
*dev
= pci_get_drvdata(pdev
);
8850 struct bnxt
*bp
= netdev_priv(dev
);
8853 bnxt_sriov_disable(bp
);
8854 bnxt_dl_unregister(bp
);
8857 pci_disable_pcie_error_reporting(pdev
);
8858 unregister_netdev(dev
);
8859 bnxt_shutdown_tc(bp
);
8860 bnxt_cancel_sp_work(bp
);
8863 bnxt_clear_int_mode(bp
);
8864 bnxt_hwrm_func_drv_unrgtr(bp
);
8865 bnxt_free_hwrm_resources(bp
);
8866 bnxt_free_hwrm_short_cmd_req(bp
);
8867 bnxt_ethtool_free(bp
);
8871 bnxt_free_ctx_mem(bp
);
8874 bnxt_cleanup_pci(bp
);
8878 static int bnxt_probe_phy(struct bnxt
*bp
)
8881 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8883 rc
= bnxt_hwrm_phy_qcaps(bp
);
8885 netdev_err(bp
->dev
, "Probe phy can't get phy capabilities (rc: %x)\n",
8889 mutex_init(&bp
->link_lock
);
8891 rc
= bnxt_update_link(bp
, false);
8893 netdev_err(bp
->dev
, "Probe phy can't update link (rc: %x)\n",
8898 /* Older firmware does not have supported_auto_speeds, so assume
8899 * that all supported speeds can be autonegotiated.
8901 if (link_info
->auto_link_speeds
&& !link_info
->support_auto_speeds
)
8902 link_info
->support_auto_speeds
= link_info
->support_speeds
;
8904 /*initialize the ethool setting copy with NVM settings */
8905 if (BNXT_AUTO_MODE(link_info
->auto_mode
)) {
8906 link_info
->autoneg
= BNXT_AUTONEG_SPEED
;
8907 if (bp
->hwrm_spec_code
>= 0x10201) {
8908 if (link_info
->auto_pause_setting
&
8909 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
)
8910 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
8912 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
8914 link_info
->advertising
= link_info
->auto_link_speeds
;
8916 link_info
->req_link_speed
= link_info
->force_link_speed
;
8917 link_info
->req_duplex
= link_info
->duplex_setting
;
8919 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
8920 link_info
->req_flow_ctrl
=
8921 link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
;
8923 link_info
->req_flow_ctrl
= link_info
->force_pause_setting
;
8927 static int bnxt_get_max_irq(struct pci_dev
*pdev
)
8931 if (!pdev
->msix_cap
)
8934 pci_read_config_word(pdev
, pdev
->msix_cap
+ PCI_MSIX_FLAGS
, &ctrl
);
8935 return (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
8938 static void _bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
8941 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
8942 int max_ring_grps
= 0;
8944 *max_tx
= hw_resc
->max_tx_rings
;
8945 *max_rx
= hw_resc
->max_rx_rings
;
8946 *max_cp
= min_t(int, bnxt_get_max_func_cp_rings_for_en(bp
),
8947 hw_resc
->max_irqs
- bnxt_get_ulp_msix_num(bp
));
8948 *max_cp
= min_t(int, *max_cp
, hw_resc
->max_stat_ctxs
);
8949 max_ring_grps
= hw_resc
->max_hw_ring_grps
;
8950 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) && BNXT_PF(bp
)) {
8954 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
8956 *max_rx
= min_t(int, *max_rx
, max_ring_grps
);
8959 int bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
, bool shared
)
8963 _bnxt_get_max_rings(bp
, &rx
, &tx
, &cp
);
8966 if (!rx
|| !tx
|| !cp
)
8969 return bnxt_trim_rings(bp
, max_rx
, max_tx
, cp
, shared
);
8972 static int bnxt_get_dflt_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
8977 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
8978 if (rc
&& (bp
->flags
& BNXT_FLAG_AGG_RINGS
)) {
8979 /* Not enough rings, try disabling agg rings. */
8980 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
8981 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
8983 /* set BNXT_FLAG_AGG_RINGS back for consistency */
8984 bp
->flags
|= BNXT_FLAG_AGG_RINGS
;
8987 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
8988 bp
->dev
->hw_features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
8989 bp
->dev
->features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
8990 bnxt_set_ring_params(bp
);
8993 if (bp
->flags
& BNXT_FLAG_ROCE_CAP
) {
8994 int max_cp
, max_stat
, max_irq
;
8996 /* Reserve minimum resources for RoCE */
8997 max_cp
= bnxt_get_max_func_cp_rings(bp
);
8998 max_stat
= bnxt_get_max_func_stat_ctxs(bp
);
8999 max_irq
= bnxt_get_max_func_irqs(bp
);
9000 if (max_cp
<= BNXT_MIN_ROCE_CP_RINGS
||
9001 max_irq
<= BNXT_MIN_ROCE_CP_RINGS
||
9002 max_stat
<= BNXT_MIN_ROCE_STAT_CTXS
)
9005 max_cp
-= BNXT_MIN_ROCE_CP_RINGS
;
9006 max_irq
-= BNXT_MIN_ROCE_CP_RINGS
;
9007 max_stat
-= BNXT_MIN_ROCE_STAT_CTXS
;
9008 max_cp
= min_t(int, max_cp
, max_irq
);
9009 max_cp
= min_t(int, max_cp
, max_stat
);
9010 rc
= bnxt_trim_rings(bp
, max_rx
, max_tx
, max_cp
, shared
);
9017 /* In initial default shared ring setting, each shared ring must have a
9020 static void bnxt_trim_dflt_sh_rings(struct bnxt
*bp
)
9022 bp
->cp_nr_rings
= min_t(int, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
);
9023 bp
->rx_nr_rings
= bp
->cp_nr_rings
;
9024 bp
->tx_nr_rings_per_tc
= bp
->cp_nr_rings
;
9025 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
9028 static int bnxt_set_dflt_rings(struct bnxt
*bp
, bool sh
)
9030 int dflt_rings
, max_rx_rings
, max_tx_rings
, rc
;
9032 if (!bnxt_can_reserve_rings(bp
))
9036 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
9037 dflt_rings
= netif_get_num_default_rss_queues();
9038 /* Reduce default rings on multi-port cards so that total default
9039 * rings do not exceed CPU count.
9041 if (bp
->port_count
> 1) {
9043 max_t(int, num_online_cpus() / bp
->port_count
, 1);
9045 dflt_rings
= min_t(int, dflt_rings
, max_rings
);
9047 rc
= bnxt_get_dflt_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
9050 bp
->rx_nr_rings
= min_t(int, dflt_rings
, max_rx_rings
);
9051 bp
->tx_nr_rings_per_tc
= min_t(int, dflt_rings
, max_tx_rings
);
9053 bnxt_trim_dflt_sh_rings(bp
);
9055 bp
->cp_nr_rings
= bp
->tx_nr_rings_per_tc
+ bp
->rx_nr_rings
;
9056 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
9058 rc
= __bnxt_reserve_rings(bp
);
9060 netdev_warn(bp
->dev
, "Unable to reserve tx rings\n");
9061 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
9063 bnxt_trim_dflt_sh_rings(bp
);
9065 /* Rings may have been trimmed, re-reserve the trimmed rings. */
9066 if (bnxt_need_reserve_rings(bp
)) {
9067 rc
= __bnxt_reserve_rings(bp
);
9069 netdev_warn(bp
->dev
, "2nd rings reservation failed.\n");
9070 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
9072 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
9073 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
9080 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
)
9084 if (bp
->tx_nr_rings
)
9087 bnxt_ulp_irq_stop(bp
);
9088 bnxt_clear_int_mode(bp
);
9089 rc
= bnxt_set_dflt_rings(bp
, true);
9091 netdev_err(bp
->dev
, "Not enough rings available.\n");
9092 goto init_dflt_ring_err
;
9094 rc
= bnxt_init_int_mode(bp
);
9096 goto init_dflt_ring_err
;
9098 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
9099 if (bnxt_rfs_supported(bp
) && bnxt_rfs_capable(bp
)) {
9100 bp
->flags
|= BNXT_FLAG_RFS
;
9101 bp
->dev
->features
|= NETIF_F_NTUPLE
;
9104 bnxt_ulp_irq_restart(bp
, rc
);
9108 int bnxt_restore_pf_fw_resources(struct bnxt
*bp
)
9113 bnxt_hwrm_func_qcaps(bp
);
9115 if (netif_running(bp
->dev
))
9116 __bnxt_close_nic(bp
, true, false);
9118 bnxt_ulp_irq_stop(bp
);
9119 bnxt_clear_int_mode(bp
);
9120 rc
= bnxt_init_int_mode(bp
);
9121 bnxt_ulp_irq_restart(bp
, rc
);
9123 if (netif_running(bp
->dev
)) {
9127 rc
= bnxt_open_nic(bp
, true, false);
9133 static int bnxt_init_mac_addr(struct bnxt
*bp
)
9138 memcpy(bp
->dev
->dev_addr
, bp
->pf
.mac_addr
, ETH_ALEN
);
9140 #ifdef CONFIG_BNXT_SRIOV
9141 struct bnxt_vf_info
*vf
= &bp
->vf
;
9142 bool strict_approval
= true;
9144 if (is_valid_ether_addr(vf
->mac_addr
)) {
9145 /* overwrite netdev dev_addr with admin VF MAC */
9146 memcpy(bp
->dev
->dev_addr
, vf
->mac_addr
, ETH_ALEN
);
9147 /* Older PF driver or firmware may not approve this
9150 strict_approval
= false;
9152 eth_hw_addr_random(bp
->dev
);
9154 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, strict_approval
);
9160 static int bnxt_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9162 static int version_printed
;
9163 struct net_device
*dev
;
9167 if (pci_is_bridge(pdev
))
9170 if (version_printed
++ == 0)
9171 pr_info("%s", version
);
9173 max_irqs
= bnxt_get_max_irq(pdev
);
9174 dev
= alloc_etherdev_mq(sizeof(*bp
), max_irqs
);
9178 bp
= netdev_priv(dev
);
9180 if (bnxt_vf_pciid(ent
->driver_data
))
9181 bp
->flags
|= BNXT_FLAG_VF
;
9184 bp
->flags
|= BNXT_FLAG_MSIX_CAP
;
9186 rc
= bnxt_init_board(pdev
, dev
);
9190 dev
->netdev_ops
= &bnxt_netdev_ops
;
9191 dev
->watchdog_timeo
= BNXT_TX_TIMEOUT
;
9192 dev
->ethtool_ops
= &bnxt_ethtool_ops
;
9193 SWITCHDEV_SET_OPS(dev
, &bnxt_switchdev_ops
);
9194 pci_set_drvdata(pdev
, dev
);
9196 rc
= bnxt_alloc_hwrm_resources(bp
);
9198 goto init_err_pci_clean
;
9200 mutex_init(&bp
->hwrm_cmd_lock
);
9201 rc
= bnxt_hwrm_ver_get(bp
);
9203 goto init_err_pci_clean
;
9205 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
9206 bp
->hwrm_max_ext_req_len
> BNXT_HWRM_MAX_REQ_LEN
) {
9207 rc
= bnxt_alloc_hwrm_short_cmd_req(bp
);
9209 goto init_err_pci_clean
;
9212 rc
= bnxt_hwrm_func_reset(bp
);
9214 goto init_err_pci_clean
;
9216 bnxt_hwrm_fw_set_time(bp
);
9218 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
9219 NETIF_F_TSO
| NETIF_F_TSO6
|
9220 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
9221 NETIF_F_GSO_IPXIP4
|
9222 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
9223 NETIF_F_GSO_PARTIAL
| NETIF_F_RXHASH
|
9224 NETIF_F_RXCSUM
| NETIF_F_GRO
;
9226 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
9227 dev
->hw_features
|= NETIF_F_LRO
;
9229 dev
->hw_enc_features
=
9230 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
9231 NETIF_F_TSO
| NETIF_F_TSO6
|
9232 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
9233 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
9234 NETIF_F_GSO_IPXIP4
| NETIF_F_GSO_PARTIAL
;
9235 dev
->gso_partial_features
= NETIF_F_GSO_UDP_TUNNEL_CSUM
|
9236 NETIF_F_GSO_GRE_CSUM
;
9237 dev
->vlan_features
= dev
->hw_features
| NETIF_F_HIGHDMA
;
9238 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_CTAG_TX
|
9239 NETIF_F_HW_VLAN_STAG_RX
| NETIF_F_HW_VLAN_STAG_TX
;
9240 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
9241 dev
->hw_features
|= NETIF_F_GRO_HW
;
9242 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
9243 if (dev
->features
& NETIF_F_GRO_HW
)
9244 dev
->features
&= ~NETIF_F_LRO
;
9245 dev
->priv_flags
|= IFF_UNICAST_FLT
;
9247 #ifdef CONFIG_BNXT_SRIOV
9248 init_waitqueue_head(&bp
->sriov_cfg_wait
);
9249 mutex_init(&bp
->sriov_lock
);
9251 bp
->gro_func
= bnxt_gro_func_5730x
;
9252 if (BNXT_CHIP_P4_PLUS(bp
))
9253 bp
->gro_func
= bnxt_gro_func_5731x
;
9255 bp
->flags
|= BNXT_FLAG_DOUBLE_DB
;
9257 rc
= bnxt_hwrm_func_drv_rgtr(bp
);
9259 goto init_err_pci_clean
;
9261 rc
= bnxt_hwrm_func_rgtr_async_events(bp
, NULL
, 0);
9263 goto init_err_pci_clean
;
9265 bp
->ulp_probe
= bnxt_ulp_probe
;
9267 rc
= bnxt_hwrm_queue_qportcfg(bp
);
9269 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %x\n",
9272 goto init_err_pci_clean
;
9274 /* Get the MAX capabilities for this function */
9275 rc
= bnxt_hwrm_func_qcaps(bp
);
9277 netdev_err(bp
->dev
, "hwrm query capability failure rc: %x\n",
9280 goto init_err_pci_clean
;
9282 rc
= bnxt_init_mac_addr(bp
);
9284 dev_err(&pdev
->dev
, "Unable to initialize mac address.\n");
9285 rc
= -EADDRNOTAVAIL
;
9286 goto init_err_pci_clean
;
9289 bnxt_hwrm_func_qcfg(bp
);
9290 bnxt_hwrm_port_led_qcaps(bp
);
9291 bnxt_ethtool_init(bp
);
9294 /* MTU range: 60 - FW defined max */
9295 dev
->min_mtu
= ETH_ZLEN
;
9296 dev
->max_mtu
= bp
->max_mtu
;
9298 rc
= bnxt_probe_phy(bp
);
9300 goto init_err_pci_clean
;
9302 bnxt_set_rx_skb_mode(bp
, false);
9303 bnxt_set_tpa_flags(bp
);
9304 bnxt_set_ring_params(bp
);
9305 bnxt_set_max_func_irqs(bp
, max_irqs
);
9306 rc
= bnxt_set_dflt_rings(bp
, true);
9308 netdev_err(bp
->dev
, "Not enough rings available.\n");
9310 goto init_err_pci_clean
;
9313 /* Default RSS hash cfg. */
9314 bp
->rss_hash_cfg
= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
|
9315 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
|
9316 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
|
9317 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
9318 if (BNXT_CHIP_P4_PLUS(bp
) && bp
->hwrm_spec_code
>= 0x10501) {
9319 bp
->flags
|= BNXT_FLAG_UDP_RSS_CAP
;
9320 bp
->rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
|
9321 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
9324 bnxt_hwrm_vnic_qcaps(bp
);
9325 if (bnxt_rfs_supported(bp
)) {
9326 dev
->hw_features
|= NETIF_F_NTUPLE
;
9327 if (bnxt_rfs_capable(bp
)) {
9328 bp
->flags
|= BNXT_FLAG_RFS
;
9329 dev
->features
|= NETIF_F_NTUPLE
;
9333 if (dev
->hw_features
& NETIF_F_HW_VLAN_CTAG_RX
)
9334 bp
->flags
|= BNXT_FLAG_STRIP_VLAN
;
9336 rc
= bnxt_init_int_mode(bp
);
9338 goto init_err_pci_clean
;
9340 /* No TC has been set yet and rings may have been trimmed due to
9341 * limited MSIX, so we re-initialize the TX rings per TC.
9343 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
9345 bnxt_get_wol_settings(bp
);
9346 if (bp
->flags
& BNXT_FLAG_WOL_CAP
)
9347 device_set_wakeup_enable(&pdev
->dev
, bp
->wol
);
9349 device_set_wakeup_capable(&pdev
->dev
, false);
9351 bnxt_hwrm_set_cache_line_size(bp
, cache_line_size());
9353 bnxt_hwrm_coal_params_qcaps(bp
);
9358 create_singlethread_workqueue("bnxt_pf_wq");
9360 dev_err(&pdev
->dev
, "Unable to create workqueue.\n");
9361 goto init_err_pci_clean
;
9367 rc
= register_netdev(dev
);
9369 goto init_err_cleanup_tc
;
9372 bnxt_dl_register(bp
);
9374 netdev_info(dev
, "%s found at mem %lx, node addr %pM\n",
9375 board_info
[ent
->driver_data
].name
,
9376 (long)pci_resource_start(pdev
, 0), dev
->dev_addr
);
9377 pcie_print_link_status(pdev
);
9381 init_err_cleanup_tc
:
9382 bnxt_shutdown_tc(bp
);
9383 bnxt_clear_int_mode(bp
);
9386 bnxt_free_hwrm_resources(bp
);
9387 bnxt_free_ctx_mem(bp
);
9390 bnxt_cleanup_pci(bp
);
9397 static void bnxt_shutdown(struct pci_dev
*pdev
)
9399 struct net_device
*dev
= pci_get_drvdata(pdev
);
9406 bp
= netdev_priv(dev
);
9410 if (netif_running(dev
))
9413 bnxt_ulp_shutdown(bp
);
9415 if (system_state
== SYSTEM_POWER_OFF
) {
9416 bnxt_clear_int_mode(bp
);
9417 pci_wake_from_d3(pdev
, bp
->wol
);
9418 pci_set_power_state(pdev
, PCI_D3hot
);
9425 #ifdef CONFIG_PM_SLEEP
9426 static int bnxt_suspend(struct device
*device
)
9428 struct pci_dev
*pdev
= to_pci_dev(device
);
9429 struct net_device
*dev
= pci_get_drvdata(pdev
);
9430 struct bnxt
*bp
= netdev_priv(dev
);
9434 if (netif_running(dev
)) {
9435 netif_device_detach(dev
);
9436 rc
= bnxt_close(dev
);
9438 bnxt_hwrm_func_drv_unrgtr(bp
);
9443 static int bnxt_resume(struct device
*device
)
9445 struct pci_dev
*pdev
= to_pci_dev(device
);
9446 struct net_device
*dev
= pci_get_drvdata(pdev
);
9447 struct bnxt
*bp
= netdev_priv(dev
);
9451 if (bnxt_hwrm_ver_get(bp
) || bnxt_hwrm_func_drv_rgtr(bp
)) {
9455 rc
= bnxt_hwrm_func_reset(bp
);
9460 bnxt_get_wol_settings(bp
);
9461 if (netif_running(dev
)) {
9462 rc
= bnxt_open(dev
);
9464 netif_device_attach(dev
);
9472 static SIMPLE_DEV_PM_OPS(bnxt_pm_ops
, bnxt_suspend
, bnxt_resume
);
9473 #define BNXT_PM_OPS (&bnxt_pm_ops)
9477 #define BNXT_PM_OPS NULL
9479 #endif /* CONFIG_PM_SLEEP */
9482 * bnxt_io_error_detected - called when PCI error is detected
9483 * @pdev: Pointer to PCI device
9484 * @state: The current pci connection state
9486 * This function is called after a PCI bus error affecting
9487 * this device has been detected.
9489 static pci_ers_result_t
bnxt_io_error_detected(struct pci_dev
*pdev
,
9490 pci_channel_state_t state
)
9492 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9493 struct bnxt
*bp
= netdev_priv(netdev
);
9495 netdev_info(netdev
, "PCI I/O error detected\n");
9498 netif_device_detach(netdev
);
9502 if (state
== pci_channel_io_perm_failure
) {
9504 return PCI_ERS_RESULT_DISCONNECT
;
9507 if (netif_running(netdev
))
9510 pci_disable_device(pdev
);
9513 /* Request a slot slot reset. */
9514 return PCI_ERS_RESULT_NEED_RESET
;
9518 * bnxt_io_slot_reset - called after the pci bus has been reset.
9519 * @pdev: Pointer to PCI device
9521 * Restart the card from scratch, as if from a cold-boot.
9522 * At this point, the card has exprienced a hard reset,
9523 * followed by fixups by BIOS, and has its config space
9524 * set up identically to what it was at cold boot.
9526 static pci_ers_result_t
bnxt_io_slot_reset(struct pci_dev
*pdev
)
9528 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9529 struct bnxt
*bp
= netdev_priv(netdev
);
9531 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
9533 netdev_info(bp
->dev
, "PCI Slot Reset\n");
9537 if (pci_enable_device(pdev
)) {
9539 "Cannot re-enable PCI device after reset.\n");
9541 pci_set_master(pdev
);
9543 err
= bnxt_hwrm_func_reset(bp
);
9544 if (!err
&& netif_running(netdev
))
9545 err
= bnxt_open(netdev
);
9548 result
= PCI_ERS_RESULT_RECOVERED
;
9553 if (result
!= PCI_ERS_RESULT_RECOVERED
&& netif_running(netdev
))
9558 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
9561 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9562 err
); /* non-fatal, continue */
9565 return PCI_ERS_RESULT_RECOVERED
;
9569 * bnxt_io_resume - called when traffic can start flowing again.
9570 * @pdev: Pointer to PCI device
9572 * This callback is called when the error recovery driver tells
9573 * us that its OK to resume normal operation.
9575 static void bnxt_io_resume(struct pci_dev
*pdev
)
9577 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9581 netif_device_attach(netdev
);
9586 static const struct pci_error_handlers bnxt_err_handler
= {
9587 .error_detected
= bnxt_io_error_detected
,
9588 .slot_reset
= bnxt_io_slot_reset
,
9589 .resume
= bnxt_io_resume
9592 static struct pci_driver bnxt_pci_driver
= {
9593 .name
= DRV_MODULE_NAME
,
9594 .id_table
= bnxt_pci_tbl
,
9595 .probe
= bnxt_init_one
,
9596 .remove
= bnxt_remove_one
,
9597 .shutdown
= bnxt_shutdown
,
9598 .driver
.pm
= BNXT_PM_OPS
,
9599 .err_handler
= &bnxt_err_handler
,
9600 #if defined(CONFIG_BNXT_SRIOV)
9601 .sriov_configure
= bnxt_sriov_configure
,
9605 static int __init
bnxt_init(void)
9608 return pci_register_driver(&bnxt_pci_driver
);
9611 static void __exit
bnxt_exit(void)
9613 pci_unregister_driver(&bnxt_pci_driver
);
9615 destroy_workqueue(bnxt_pf_wq
);
9619 module_init(bnxt_init
);
9620 module_exit(bnxt_exit
);