1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2019 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>
34 #include <linux/mdio.h>
36 #include <linux/if_vlan.h>
37 #include <linux/if_bridge.h>
38 #include <linux/rtc.h>
39 #include <linux/bpf.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <net/udp_tunnel.h>
46 #include <linux/workqueue.h>
47 #include <linux/prefetch.h>
48 #include <linux/cache.h>
49 #include <linux/log2.h>
50 #include <linux/aer.h>
51 #include <linux/bitmap.h>
52 #include <linux/cpu_rmap.h>
53 #include <linux/cpumask.h>
54 #include <net/pkt_cls.h>
55 #include <linux/hwmon.h>
56 #include <linux/hwmon-sysfs.h>
57 #include <net/page_pool.h>
62 #include "bnxt_sriov.h"
63 #include "bnxt_ethtool.h"
68 #include "bnxt_devlink.h"
69 #include "bnxt_debugfs.h"
71 #define BNXT_TX_TIMEOUT (5 * HZ)
73 static const char version
[] =
74 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME
" v" DRV_MODULE_VERSION
"\n";
76 MODULE_LICENSE("GPL");
77 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
78 MODULE_VERSION(DRV_MODULE_VERSION
);
80 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
81 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
82 #define BNXT_RX_COPY_THRESH 256
84 #define BNXT_TX_PUSH_THRESH 164
131 /* indexed by enum above */
132 static const struct {
135 [BCM57301
] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
136 [BCM57302
] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
137 [BCM57304
] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
138 [BCM57417_NPAR
] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
139 [BCM58700
] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
140 [BCM57311
] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
141 [BCM57312
] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
142 [BCM57402
] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
143 [BCM57404
] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
144 [BCM57406
] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
145 [BCM57402_NPAR
] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
146 [BCM57407
] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
147 [BCM57412
] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
148 [BCM57414
] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
149 [BCM57416
] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
150 [BCM57417
] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
151 [BCM57412_NPAR
] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
152 [BCM57314
] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
153 [BCM57417_SFP
] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
154 [BCM57416_SFP
] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
155 [BCM57404_NPAR
] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
156 [BCM57406_NPAR
] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
157 [BCM57407_SFP
] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
158 [BCM57407_NPAR
] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
159 [BCM57414_NPAR
] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
160 [BCM57416_NPAR
] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
161 [BCM57452
] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
162 [BCM57454
] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
163 [BCM5745x_NPAR
] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
164 [BCM57508
] = { "Broadcom BCM57508 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
165 [BCM57504
] = { "Broadcom BCM57504 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
166 [BCM57502
] = { "Broadcom BCM57502 NetXtreme-E 10Gb/25Gb/50Gb Ethernet" },
167 [BCM57508_NPAR
] = { "Broadcom BCM57508 NetXtreme-E Ethernet Partition" },
168 [BCM57504_NPAR
] = { "Broadcom BCM57504 NetXtreme-E Ethernet Partition" },
169 [BCM57502_NPAR
] = { "Broadcom BCM57502 NetXtreme-E Ethernet Partition" },
170 [BCM58802
] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
171 [BCM58804
] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
172 [BCM58808
] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
173 [NETXTREME_E_VF
] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
174 [NETXTREME_C_VF
] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
175 [NETXTREME_S_VF
] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
176 [NETXTREME_E_P5_VF
] = { "Broadcom BCM5750X NetXtreme-E Ethernet Virtual Function" },
179 static const struct pci_device_id bnxt_pci_tbl
[] = {
180 { PCI_VDEVICE(BROADCOM
, 0x1604), .driver_data
= BCM5745x_NPAR
},
181 { PCI_VDEVICE(BROADCOM
, 0x1605), .driver_data
= BCM5745x_NPAR
},
182 { PCI_VDEVICE(BROADCOM
, 0x1614), .driver_data
= BCM57454
},
183 { PCI_VDEVICE(BROADCOM
, 0x16c0), .driver_data
= BCM57417_NPAR
},
184 { PCI_VDEVICE(BROADCOM
, 0x16c8), .driver_data
= BCM57301
},
185 { PCI_VDEVICE(BROADCOM
, 0x16c9), .driver_data
= BCM57302
},
186 { PCI_VDEVICE(BROADCOM
, 0x16ca), .driver_data
= BCM57304
},
187 { PCI_VDEVICE(BROADCOM
, 0x16cc), .driver_data
= BCM57417_NPAR
},
188 { PCI_VDEVICE(BROADCOM
, 0x16cd), .driver_data
= BCM58700
},
189 { PCI_VDEVICE(BROADCOM
, 0x16ce), .driver_data
= BCM57311
},
190 { PCI_VDEVICE(BROADCOM
, 0x16cf), .driver_data
= BCM57312
},
191 { PCI_VDEVICE(BROADCOM
, 0x16d0), .driver_data
= BCM57402
},
192 { PCI_VDEVICE(BROADCOM
, 0x16d1), .driver_data
= BCM57404
},
193 { PCI_VDEVICE(BROADCOM
, 0x16d2), .driver_data
= BCM57406
},
194 { PCI_VDEVICE(BROADCOM
, 0x16d4), .driver_data
= BCM57402_NPAR
},
195 { PCI_VDEVICE(BROADCOM
, 0x16d5), .driver_data
= BCM57407
},
196 { PCI_VDEVICE(BROADCOM
, 0x16d6), .driver_data
= BCM57412
},
197 { PCI_VDEVICE(BROADCOM
, 0x16d7), .driver_data
= BCM57414
},
198 { PCI_VDEVICE(BROADCOM
, 0x16d8), .driver_data
= BCM57416
},
199 { PCI_VDEVICE(BROADCOM
, 0x16d9), .driver_data
= BCM57417
},
200 { PCI_VDEVICE(BROADCOM
, 0x16de), .driver_data
= BCM57412_NPAR
},
201 { PCI_VDEVICE(BROADCOM
, 0x16df), .driver_data
= BCM57314
},
202 { PCI_VDEVICE(BROADCOM
, 0x16e2), .driver_data
= BCM57417_SFP
},
203 { PCI_VDEVICE(BROADCOM
, 0x16e3), .driver_data
= BCM57416_SFP
},
204 { PCI_VDEVICE(BROADCOM
, 0x16e7), .driver_data
= BCM57404_NPAR
},
205 { PCI_VDEVICE(BROADCOM
, 0x16e8), .driver_data
= BCM57406_NPAR
},
206 { PCI_VDEVICE(BROADCOM
, 0x16e9), .driver_data
= BCM57407_SFP
},
207 { PCI_VDEVICE(BROADCOM
, 0x16ea), .driver_data
= BCM57407_NPAR
},
208 { PCI_VDEVICE(BROADCOM
, 0x16eb), .driver_data
= BCM57412_NPAR
},
209 { PCI_VDEVICE(BROADCOM
, 0x16ec), .driver_data
= BCM57414_NPAR
},
210 { PCI_VDEVICE(BROADCOM
, 0x16ed), .driver_data
= BCM57414_NPAR
},
211 { PCI_VDEVICE(BROADCOM
, 0x16ee), .driver_data
= BCM57416_NPAR
},
212 { PCI_VDEVICE(BROADCOM
, 0x16ef), .driver_data
= BCM57416_NPAR
},
213 { PCI_VDEVICE(BROADCOM
, 0x16f0), .driver_data
= BCM58808
},
214 { PCI_VDEVICE(BROADCOM
, 0x16f1), .driver_data
= BCM57452
},
215 { PCI_VDEVICE(BROADCOM
, 0x1750), .driver_data
= BCM57508
},
216 { PCI_VDEVICE(BROADCOM
, 0x1751), .driver_data
= BCM57504
},
217 { PCI_VDEVICE(BROADCOM
, 0x1752), .driver_data
= BCM57502
},
218 { PCI_VDEVICE(BROADCOM
, 0x1800), .driver_data
= BCM57508_NPAR
},
219 { PCI_VDEVICE(BROADCOM
, 0x1801), .driver_data
= BCM57504_NPAR
},
220 { PCI_VDEVICE(BROADCOM
, 0x1802), .driver_data
= BCM57502_NPAR
},
221 { PCI_VDEVICE(BROADCOM
, 0x1803), .driver_data
= BCM57508_NPAR
},
222 { PCI_VDEVICE(BROADCOM
, 0x1804), .driver_data
= BCM57504_NPAR
},
223 { PCI_VDEVICE(BROADCOM
, 0x1805), .driver_data
= BCM57502_NPAR
},
224 { PCI_VDEVICE(BROADCOM
, 0xd802), .driver_data
= BCM58802
},
225 { PCI_VDEVICE(BROADCOM
, 0xd804), .driver_data
= BCM58804
},
226 #ifdef CONFIG_BNXT_SRIOV
227 { PCI_VDEVICE(BROADCOM
, 0x1606), .driver_data
= NETXTREME_E_VF
},
228 { PCI_VDEVICE(BROADCOM
, 0x1609), .driver_data
= NETXTREME_E_VF
},
229 { PCI_VDEVICE(BROADCOM
, 0x16c1), .driver_data
= NETXTREME_E_VF
},
230 { PCI_VDEVICE(BROADCOM
, 0x16cb), .driver_data
= NETXTREME_C_VF
},
231 { PCI_VDEVICE(BROADCOM
, 0x16d3), .driver_data
= NETXTREME_E_VF
},
232 { PCI_VDEVICE(BROADCOM
, 0x16dc), .driver_data
= NETXTREME_E_VF
},
233 { PCI_VDEVICE(BROADCOM
, 0x16e1), .driver_data
= NETXTREME_C_VF
},
234 { PCI_VDEVICE(BROADCOM
, 0x16e5), .driver_data
= NETXTREME_C_VF
},
235 { PCI_VDEVICE(BROADCOM
, 0x1806), .driver_data
= NETXTREME_E_P5_VF
},
236 { PCI_VDEVICE(BROADCOM
, 0x1807), .driver_data
= NETXTREME_E_P5_VF
},
237 { PCI_VDEVICE(BROADCOM
, 0xd800), .driver_data
= NETXTREME_S_VF
},
242 MODULE_DEVICE_TABLE(pci
, bnxt_pci_tbl
);
244 static const u16 bnxt_vf_req_snif
[] = {
248 HWRM_CFA_L2_FILTER_ALLOC
,
251 static const u16 bnxt_async_events_arr
[] = {
252 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
,
253 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
,
254 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
,
255 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
,
256 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
,
257 ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY
,
258 ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
,
261 static struct workqueue_struct
*bnxt_pf_wq
;
263 static bool bnxt_vf_pciid(enum board_idx idx
)
265 return (idx
== NETXTREME_C_VF
|| idx
== NETXTREME_E_VF
||
266 idx
== NETXTREME_S_VF
|| idx
== NETXTREME_E_P5_VF
);
269 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
270 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
271 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
273 #define BNXT_CP_DB_IRQ_DIS(db) \
274 writel(DB_CP_IRQ_DIS_FLAGS, db)
276 #define BNXT_DB_CQ(db, idx) \
277 writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
279 #define BNXT_DB_NQ_P5(db, idx) \
280 writeq((db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), (db)->doorbell)
282 #define BNXT_DB_CQ_ARM(db, idx) \
283 writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
285 #define BNXT_DB_NQ_ARM_P5(db, idx) \
286 writeq((db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx), (db)->doorbell)
288 static void bnxt_db_nq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
290 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
291 BNXT_DB_NQ_P5(db
, idx
);
296 static void bnxt_db_nq_arm(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
298 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
299 BNXT_DB_NQ_ARM_P5(db
, idx
);
301 BNXT_DB_CQ_ARM(db
, idx
);
304 static void bnxt_db_cq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
306 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
307 writeq(db
->db_key64
| DBR_TYPE_CQ_ARMALL
| RING_CMP(idx
),
313 const u16 bnxt_lhint_arr
[] = {
314 TX_BD_FLAGS_LHINT_512_AND_SMALLER
,
315 TX_BD_FLAGS_LHINT_512_TO_1023
,
316 TX_BD_FLAGS_LHINT_1024_TO_2047
,
317 TX_BD_FLAGS_LHINT_1024_TO_2047
,
318 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
319 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
320 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
321 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
322 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
323 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
324 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
325 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
326 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
327 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
328 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
329 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
330 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
331 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
332 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
335 static u16
bnxt_xmit_get_cfa_action(struct sk_buff
*skb
)
337 struct metadata_dst
*md_dst
= skb_metadata_dst(skb
);
339 if (!md_dst
|| md_dst
->type
!= METADATA_HW_PORT_MUX
)
342 return md_dst
->u
.port_info
.port_id
;
345 static netdev_tx_t
bnxt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
347 struct bnxt
*bp
= netdev_priv(dev
);
349 struct tx_bd_ext
*txbd1
;
350 struct netdev_queue
*txq
;
353 unsigned int length
, pad
= 0;
354 u32 len
, free_size
, vlan_tag_flags
, cfa_action
, flags
;
356 struct pci_dev
*pdev
= bp
->pdev
;
357 struct bnxt_tx_ring_info
*txr
;
358 struct bnxt_sw_tx_bd
*tx_buf
;
360 i
= skb_get_queue_mapping(skb
);
361 if (unlikely(i
>= bp
->tx_nr_rings
)) {
362 dev_kfree_skb_any(skb
);
366 txq
= netdev_get_tx_queue(dev
, i
);
367 txr
= &bp
->tx_ring
[bp
->tx_ring_map
[i
]];
370 free_size
= bnxt_tx_avail(bp
, txr
);
371 if (unlikely(free_size
< skb_shinfo(skb
)->nr_frags
+ 2)) {
372 netif_tx_stop_queue(txq
);
373 return NETDEV_TX_BUSY
;
377 len
= skb_headlen(skb
);
378 last_frag
= skb_shinfo(skb
)->nr_frags
;
380 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
382 txbd
->tx_bd_opaque
= prod
;
384 tx_buf
= &txr
->tx_buf_ring
[prod
];
386 tx_buf
->nr_frags
= last_frag
;
389 cfa_action
= bnxt_xmit_get_cfa_action(skb
);
390 if (skb_vlan_tag_present(skb
)) {
391 vlan_tag_flags
= TX_BD_CFA_META_KEY_VLAN
|
392 skb_vlan_tag_get(skb
);
393 /* Currently supports 8021Q, 8021AD vlan offloads
394 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
396 if (skb
->vlan_proto
== htons(ETH_P_8021Q
))
397 vlan_tag_flags
|= 1 << TX_BD_CFA_META_TPID_SHIFT
;
400 if (free_size
== bp
->tx_ring_size
&& length
<= bp
->tx_push_thresh
) {
401 struct tx_push_buffer
*tx_push_buf
= txr
->tx_push
;
402 struct tx_push_bd
*tx_push
= &tx_push_buf
->push_bd
;
403 struct tx_bd_ext
*tx_push1
= &tx_push
->txbd2
;
404 void __iomem
*db
= txr
->tx_db
.doorbell
;
405 void *pdata
= tx_push_buf
->data
;
409 /* Set COAL_NOW to be ready quickly for the next push */
410 tx_push
->tx_bd_len_flags_type
=
411 cpu_to_le32((length
<< TX_BD_LEN_SHIFT
) |
412 TX_BD_TYPE_LONG_TX_BD
|
413 TX_BD_FLAGS_LHINT_512_AND_SMALLER
|
414 TX_BD_FLAGS_COAL_NOW
|
415 TX_BD_FLAGS_PACKET_END
|
416 (2 << TX_BD_FLAGS_BD_CNT_SHIFT
));
418 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
419 tx_push1
->tx_bd_hsize_lflags
=
420 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
422 tx_push1
->tx_bd_hsize_lflags
= 0;
424 tx_push1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
425 tx_push1
->tx_bd_cfa_action
=
426 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
428 end
= pdata
+ length
;
429 end
= PTR_ALIGN(end
, 8) - 1;
432 skb_copy_from_linear_data(skb
, pdata
, len
);
434 for (j
= 0; j
< last_frag
; j
++) {
435 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[j
];
438 fptr
= skb_frag_address_safe(frag
);
442 memcpy(pdata
, fptr
, skb_frag_size(frag
));
443 pdata
+= skb_frag_size(frag
);
446 txbd
->tx_bd_len_flags_type
= tx_push
->tx_bd_len_flags_type
;
447 txbd
->tx_bd_haddr
= txr
->data_mapping
;
448 prod
= NEXT_TX(prod
);
449 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
450 memcpy(txbd
, tx_push1
, sizeof(*txbd
));
451 prod
= NEXT_TX(prod
);
453 cpu_to_le32(DB_KEY_TX_PUSH
| DB_LONG_TX_PUSH
| prod
);
457 netdev_tx_sent_queue(txq
, skb
->len
);
458 wmb(); /* Sync is_push and byte queue before pushing data */
460 push_len
= (length
+ sizeof(*tx_push
) + 7) / 8;
462 __iowrite64_copy(db
, tx_push_buf
, 16);
463 __iowrite32_copy(db
+ 4, tx_push_buf
+ 1,
464 (push_len
- 16) << 1);
466 __iowrite64_copy(db
, tx_push_buf
, push_len
);
473 if (length
< BNXT_MIN_PKT_SIZE
) {
474 pad
= BNXT_MIN_PKT_SIZE
- length
;
475 if (skb_pad(skb
, pad
)) {
476 /* SKB already freed. */
480 length
= BNXT_MIN_PKT_SIZE
;
483 mapping
= dma_map_single(&pdev
->dev
, skb
->data
, len
, DMA_TO_DEVICE
);
485 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
))) {
486 dev_kfree_skb_any(skb
);
491 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
492 flags
= (len
<< TX_BD_LEN_SHIFT
) | TX_BD_TYPE_LONG_TX_BD
|
493 ((last_frag
+ 2) << TX_BD_FLAGS_BD_CNT_SHIFT
);
495 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
497 prod
= NEXT_TX(prod
);
498 txbd1
= (struct tx_bd_ext
*)
499 &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
501 txbd1
->tx_bd_hsize_lflags
= 0;
502 if (skb_is_gso(skb
)) {
505 if (skb
->encapsulation
)
506 hdr_len
= skb_inner_network_offset(skb
) +
507 skb_inner_network_header_len(skb
) +
508 inner_tcp_hdrlen(skb
);
510 hdr_len
= skb_transport_offset(skb
) +
513 txbd1
->tx_bd_hsize_lflags
= cpu_to_le32(TX_BD_FLAGS_LSO
|
515 (hdr_len
<< (TX_BD_HSIZE_SHIFT
- 1)));
516 length
= skb_shinfo(skb
)->gso_size
;
517 txbd1
->tx_bd_mss
= cpu_to_le32(length
);
519 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
520 txbd1
->tx_bd_hsize_lflags
=
521 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
522 txbd1
->tx_bd_mss
= 0;
526 if (unlikely(length
>= ARRAY_SIZE(bnxt_lhint_arr
))) {
527 dev_warn_ratelimited(&pdev
->dev
, "Dropped oversize %d bytes TX packet.\n",
532 flags
|= bnxt_lhint_arr
[length
];
533 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
535 txbd1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
536 txbd1
->tx_bd_cfa_action
=
537 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
538 for (i
= 0; i
< last_frag
; i
++) {
539 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
541 prod
= NEXT_TX(prod
);
542 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
544 len
= skb_frag_size(frag
);
545 mapping
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, len
,
548 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
)))
551 tx_buf
= &txr
->tx_buf_ring
[prod
];
552 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
554 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
556 flags
= len
<< TX_BD_LEN_SHIFT
;
557 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
561 txbd
->tx_bd_len_flags_type
=
562 cpu_to_le32(((len
+ pad
) << TX_BD_LEN_SHIFT
) | flags
|
563 TX_BD_FLAGS_PACKET_END
);
565 netdev_tx_sent_queue(txq
, skb
->len
);
567 /* Sync BD data before updating doorbell */
570 prod
= NEXT_TX(prod
);
573 if (!netdev_xmit_more() || netif_xmit_stopped(txq
))
574 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
578 if (unlikely(bnxt_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
+ 1)) {
579 if (netdev_xmit_more() && !tx_buf
->is_push
)
580 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
582 netif_tx_stop_queue(txq
);
584 /* netif_tx_stop_queue() must be done before checking
585 * tx index in bnxt_tx_avail() below, because in
586 * bnxt_tx_int(), we update tx index before checking for
587 * netif_tx_queue_stopped().
590 if (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
591 netif_tx_wake_queue(txq
);
598 /* start back at beginning and unmap skb */
600 tx_buf
= &txr
->tx_buf_ring
[prod
];
602 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
603 skb_headlen(skb
), PCI_DMA_TODEVICE
);
604 prod
= NEXT_TX(prod
);
606 /* unmap remaining mapped pages */
607 for (i
= 0; i
< last_frag
; i
++) {
608 prod
= NEXT_TX(prod
);
609 tx_buf
= &txr
->tx_buf_ring
[prod
];
610 dma_unmap_page(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
611 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
615 dev_kfree_skb_any(skb
);
619 static void bnxt_tx_int(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int nr_pkts
)
621 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
622 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, txr
->txq_index
);
623 u16 cons
= txr
->tx_cons
;
624 struct pci_dev
*pdev
= bp
->pdev
;
626 unsigned int tx_bytes
= 0;
628 for (i
= 0; i
< nr_pkts
; i
++) {
629 struct bnxt_sw_tx_bd
*tx_buf
;
633 tx_buf
= &txr
->tx_buf_ring
[cons
];
634 cons
= NEXT_TX(cons
);
638 if (tx_buf
->is_push
) {
643 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
644 skb_headlen(skb
), PCI_DMA_TODEVICE
);
645 last
= tx_buf
->nr_frags
;
647 for (j
= 0; j
< last
; j
++) {
648 cons
= NEXT_TX(cons
);
649 tx_buf
= &txr
->tx_buf_ring
[cons
];
652 dma_unmap_addr(tx_buf
, mapping
),
653 skb_frag_size(&skb_shinfo(skb
)->frags
[j
]),
658 cons
= NEXT_TX(cons
);
660 tx_bytes
+= skb
->len
;
661 dev_kfree_skb_any(skb
);
664 netdev_tx_completed_queue(txq
, nr_pkts
, tx_bytes
);
667 /* Need to make the tx_cons update visible to bnxt_start_xmit()
668 * before checking for netif_tx_queue_stopped(). Without the
669 * memory barrier, there is a small possibility that bnxt_start_xmit()
670 * will miss it and cause the queue to be stopped forever.
674 if (unlikely(netif_tx_queue_stopped(txq
)) &&
675 (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
676 __netif_tx_lock(txq
, smp_processor_id());
677 if (netif_tx_queue_stopped(txq
) &&
678 bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
&&
679 txr
->dev_state
!= BNXT_DEV_STATE_CLOSING
)
680 netif_tx_wake_queue(txq
);
681 __netif_tx_unlock(txq
);
685 static struct page
*__bnxt_alloc_rx_page(struct bnxt
*bp
, dma_addr_t
*mapping
,
686 struct bnxt_rx_ring_info
*rxr
,
689 struct device
*dev
= &bp
->pdev
->dev
;
692 page
= page_pool_dev_alloc_pages(rxr
->page_pool
);
696 *mapping
= dma_map_page_attrs(dev
, page
, 0, PAGE_SIZE
, bp
->rx_dir
,
697 DMA_ATTR_WEAK_ORDERING
);
698 if (dma_mapping_error(dev
, *mapping
)) {
699 page_pool_recycle_direct(rxr
->page_pool
, page
);
702 *mapping
+= bp
->rx_dma_offset
;
706 static inline u8
*__bnxt_alloc_rx_data(struct bnxt
*bp
, dma_addr_t
*mapping
,
710 struct pci_dev
*pdev
= bp
->pdev
;
712 data
= kmalloc(bp
->rx_buf_size
, gfp
);
716 *mapping
= dma_map_single_attrs(&pdev
->dev
, data
+ bp
->rx_dma_offset
,
717 bp
->rx_buf_use_size
, bp
->rx_dir
,
718 DMA_ATTR_WEAK_ORDERING
);
720 if (dma_mapping_error(&pdev
->dev
, *mapping
)) {
727 int bnxt_alloc_rx_data(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
730 struct rx_bd
*rxbd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
731 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[prod
];
734 if (BNXT_RX_PAGE_MODE(bp
)) {
736 __bnxt_alloc_rx_page(bp
, &mapping
, rxr
, gfp
);
742 rx_buf
->data_ptr
= page_address(page
) + bp
->rx_offset
;
744 u8
*data
= __bnxt_alloc_rx_data(bp
, &mapping
, gfp
);
750 rx_buf
->data_ptr
= data
+ bp
->rx_offset
;
752 rx_buf
->mapping
= mapping
;
754 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
758 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info
*rxr
, u16 cons
, void *data
)
760 u16 prod
= rxr
->rx_prod
;
761 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
762 struct rx_bd
*cons_bd
, *prod_bd
;
764 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
765 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
767 prod_rx_buf
->data
= data
;
768 prod_rx_buf
->data_ptr
= cons_rx_buf
->data_ptr
;
770 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
772 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
773 cons_bd
= &rxr
->rx_desc_ring
[RX_RING(cons
)][RX_IDX(cons
)];
775 prod_bd
->rx_bd_haddr
= cons_bd
->rx_bd_haddr
;
778 static inline u16
bnxt_find_next_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
780 u16 next
, max
= rxr
->rx_agg_bmap_size
;
782 next
= find_next_zero_bit(rxr
->rx_agg_bmap
, max
, idx
);
784 next
= find_first_zero_bit(rxr
->rx_agg_bmap
, max
);
788 static inline int bnxt_alloc_rx_page(struct bnxt
*bp
,
789 struct bnxt_rx_ring_info
*rxr
,
793 &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
794 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
;
795 struct pci_dev
*pdev
= bp
->pdev
;
798 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
799 unsigned int offset
= 0;
801 if (PAGE_SIZE
> BNXT_RX_PAGE_SIZE
) {
804 page
= alloc_page(gfp
);
808 rxr
->rx_page_offset
= 0;
810 offset
= rxr
->rx_page_offset
;
811 rxr
->rx_page_offset
+= BNXT_RX_PAGE_SIZE
;
812 if (rxr
->rx_page_offset
== PAGE_SIZE
)
817 page
= alloc_page(gfp
);
822 mapping
= dma_map_page_attrs(&pdev
->dev
, page
, offset
,
823 BNXT_RX_PAGE_SIZE
, PCI_DMA_FROMDEVICE
,
824 DMA_ATTR_WEAK_ORDERING
);
825 if (dma_mapping_error(&pdev
->dev
, mapping
)) {
830 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
831 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
833 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
834 rx_agg_buf
= &rxr
->rx_agg_ring
[sw_prod
];
835 rxr
->rx_sw_agg_prod
= NEXT_RX_AGG(sw_prod
);
837 rx_agg_buf
->page
= page
;
838 rx_agg_buf
->offset
= offset
;
839 rx_agg_buf
->mapping
= mapping
;
840 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
841 rxbd
->rx_bd_opaque
= sw_prod
;
845 static struct rx_agg_cmp
*bnxt_get_agg(struct bnxt
*bp
,
846 struct bnxt_cp_ring_info
*cpr
,
847 u16 cp_cons
, u16 curr
)
849 struct rx_agg_cmp
*agg
;
851 cp_cons
= RING_CMP(ADV_RAW_CMP(cp_cons
, curr
));
852 agg
= (struct rx_agg_cmp
*)
853 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
857 static struct rx_agg_cmp
*bnxt_get_tpa_agg_p5(struct bnxt
*bp
,
858 struct bnxt_rx_ring_info
*rxr
,
859 u16 agg_id
, u16 curr
)
861 struct bnxt_tpa_info
*tpa_info
= &rxr
->rx_tpa
[agg_id
];
863 return &tpa_info
->agg_arr
[curr
];
866 static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info
*cpr
, u16 idx
,
867 u16 start
, u32 agg_bufs
, bool tpa
)
869 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
870 struct bnxt
*bp
= bnapi
->bp
;
871 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
872 u16 prod
= rxr
->rx_agg_prod
;
873 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
877 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && tpa
)
880 for (i
= 0; i
< agg_bufs
; i
++) {
882 struct rx_agg_cmp
*agg
;
883 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
, *prod_rx_buf
;
884 struct rx_bd
*prod_bd
;
888 agg
= bnxt_get_tpa_agg_p5(bp
, rxr
, idx
, start
+ i
);
890 agg
= bnxt_get_agg(bp
, cpr
, idx
, start
+ i
);
891 cons
= agg
->rx_agg_cmp_opaque
;
892 __clear_bit(cons
, rxr
->rx_agg_bmap
);
894 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
895 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
897 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
898 prod_rx_buf
= &rxr
->rx_agg_ring
[sw_prod
];
899 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
901 /* It is possible for sw_prod to be equal to cons, so
902 * set cons_rx_buf->page to NULL first.
904 page
= cons_rx_buf
->page
;
905 cons_rx_buf
->page
= NULL
;
906 prod_rx_buf
->page
= page
;
907 prod_rx_buf
->offset
= cons_rx_buf
->offset
;
909 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
911 prod_bd
= &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
913 prod_bd
->rx_bd_haddr
= cpu_to_le64(cons_rx_buf
->mapping
);
914 prod_bd
->rx_bd_opaque
= sw_prod
;
916 prod
= NEXT_RX_AGG(prod
);
917 sw_prod
= NEXT_RX_AGG(sw_prod
);
919 rxr
->rx_agg_prod
= prod
;
920 rxr
->rx_sw_agg_prod
= sw_prod
;
923 static struct sk_buff
*bnxt_rx_page_skb(struct bnxt
*bp
,
924 struct bnxt_rx_ring_info
*rxr
,
925 u16 cons
, void *data
, u8
*data_ptr
,
927 unsigned int offset_and_len
)
929 unsigned int payload
= offset_and_len
>> 16;
930 unsigned int len
= offset_and_len
& 0xffff;
932 struct page
*page
= data
;
933 u16 prod
= rxr
->rx_prod
;
937 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
939 bnxt_reuse_rx_data(rxr
, cons
, data
);
942 dma_addr
-= bp
->rx_dma_offset
;
943 dma_unmap_page_attrs(&bp
->pdev
->dev
, dma_addr
, PAGE_SIZE
, bp
->rx_dir
,
944 DMA_ATTR_WEAK_ORDERING
);
946 if (unlikely(!payload
))
947 payload
= eth_get_headlen(bp
->dev
, data_ptr
, len
);
949 skb
= napi_alloc_skb(&rxr
->bnapi
->napi
, payload
);
955 off
= (void *)data_ptr
- page_address(page
);
956 skb_add_rx_frag(skb
, 0, page
, off
, len
, PAGE_SIZE
);
957 memcpy(skb
->data
- NET_IP_ALIGN
, data_ptr
- NET_IP_ALIGN
,
958 payload
+ NET_IP_ALIGN
);
960 frag
= &skb_shinfo(skb
)->frags
[0];
961 skb_frag_size_sub(frag
, payload
);
962 skb_frag_off_add(frag
, payload
);
963 skb
->data_len
-= payload
;
964 skb
->tail
+= payload
;
969 static struct sk_buff
*bnxt_rx_skb(struct bnxt
*bp
,
970 struct bnxt_rx_ring_info
*rxr
, u16 cons
,
971 void *data
, u8
*data_ptr
,
973 unsigned int offset_and_len
)
975 u16 prod
= rxr
->rx_prod
;
979 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
981 bnxt_reuse_rx_data(rxr
, cons
, data
);
985 skb
= build_skb(data
, 0);
986 dma_unmap_single_attrs(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
987 bp
->rx_dir
, DMA_ATTR_WEAK_ORDERING
);
993 skb_reserve(skb
, bp
->rx_offset
);
994 skb_put(skb
, offset_and_len
& 0xffff);
998 static struct sk_buff
*bnxt_rx_pages(struct bnxt
*bp
,
999 struct bnxt_cp_ring_info
*cpr
,
1000 struct sk_buff
*skb
, u16 idx
,
1001 u32 agg_bufs
, bool tpa
)
1003 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1004 struct pci_dev
*pdev
= bp
->pdev
;
1005 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1006 u16 prod
= rxr
->rx_agg_prod
;
1007 bool p5_tpa
= false;
1010 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && tpa
)
1013 for (i
= 0; i
< agg_bufs
; i
++) {
1015 struct rx_agg_cmp
*agg
;
1016 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
;
1021 agg
= bnxt_get_tpa_agg_p5(bp
, rxr
, idx
, i
);
1023 agg
= bnxt_get_agg(bp
, cpr
, idx
, i
);
1024 cons
= agg
->rx_agg_cmp_opaque
;
1025 frag_len
= (le32_to_cpu(agg
->rx_agg_cmp_len_flags_type
) &
1026 RX_AGG_CMP_LEN
) >> RX_AGG_CMP_LEN_SHIFT
;
1028 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
1029 skb_fill_page_desc(skb
, i
, cons_rx_buf
->page
,
1030 cons_rx_buf
->offset
, frag_len
);
1031 __clear_bit(cons
, rxr
->rx_agg_bmap
);
1033 /* It is possible for bnxt_alloc_rx_page() to allocate
1034 * a sw_prod index that equals the cons index, so we
1035 * need to clear the cons entry now.
1037 mapping
= cons_rx_buf
->mapping
;
1038 page
= cons_rx_buf
->page
;
1039 cons_rx_buf
->page
= NULL
;
1041 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_ATOMIC
) != 0) {
1042 struct skb_shared_info
*shinfo
;
1043 unsigned int nr_frags
;
1045 shinfo
= skb_shinfo(skb
);
1046 nr_frags
= --shinfo
->nr_frags
;
1047 __skb_frag_set_page(&shinfo
->frags
[nr_frags
], NULL
);
1051 cons_rx_buf
->page
= page
;
1053 /* Update prod since possibly some pages have been
1054 * allocated already.
1056 rxr
->rx_agg_prod
= prod
;
1057 bnxt_reuse_rx_agg_bufs(cpr
, idx
, i
, agg_bufs
- i
, tpa
);
1061 dma_unmap_page_attrs(&pdev
->dev
, mapping
, BNXT_RX_PAGE_SIZE
,
1063 DMA_ATTR_WEAK_ORDERING
);
1065 skb
->data_len
+= frag_len
;
1066 skb
->len
+= frag_len
;
1067 skb
->truesize
+= PAGE_SIZE
;
1069 prod
= NEXT_RX_AGG(prod
);
1071 rxr
->rx_agg_prod
= prod
;
1075 static int bnxt_agg_bufs_valid(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1076 u8 agg_bufs
, u32
*raw_cons
)
1079 struct rx_agg_cmp
*agg
;
1081 *raw_cons
= ADV_RAW_CMP(*raw_cons
, agg_bufs
);
1082 last
= RING_CMP(*raw_cons
);
1083 agg
= (struct rx_agg_cmp
*)
1084 &cpr
->cp_desc_ring
[CP_RING(last
)][CP_IDX(last
)];
1085 return RX_AGG_CMP_VALID(agg
, *raw_cons
);
1088 static inline struct sk_buff
*bnxt_copy_skb(struct bnxt_napi
*bnapi
, u8
*data
,
1092 struct bnxt
*bp
= bnapi
->bp
;
1093 struct pci_dev
*pdev
= bp
->pdev
;
1094 struct sk_buff
*skb
;
1096 skb
= napi_alloc_skb(&bnapi
->napi
, len
);
1100 dma_sync_single_for_cpu(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1103 memcpy(skb
->data
- NET_IP_ALIGN
, data
- NET_IP_ALIGN
,
1104 len
+ NET_IP_ALIGN
);
1106 dma_sync_single_for_device(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1113 static int bnxt_discard_rx(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1114 u32
*raw_cons
, void *cmp
)
1116 struct rx_cmp
*rxcmp
= cmp
;
1117 u32 tmp_raw_cons
= *raw_cons
;
1118 u8 cmp_type
, agg_bufs
= 0;
1120 cmp_type
= RX_CMP_TYPE(rxcmp
);
1122 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1123 agg_bufs
= (le32_to_cpu(rxcmp
->rx_cmp_misc_v1
) &
1125 RX_CMP_AGG_BUFS_SHIFT
;
1126 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1127 struct rx_tpa_end_cmp
*tpa_end
= cmp
;
1129 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
1132 agg_bufs
= TPA_END_AGG_BUFS(tpa_end
);
1136 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1139 *raw_cons
= tmp_raw_cons
;
1143 static void bnxt_queue_fw_reset_work(struct bnxt
*bp
, unsigned long delay
)
1146 queue_delayed_work(bnxt_pf_wq
, &bp
->fw_reset_task
, delay
);
1148 schedule_delayed_work(&bp
->fw_reset_task
, delay
);
1151 static void bnxt_queue_sp_work(struct bnxt
*bp
)
1154 queue_work(bnxt_pf_wq
, &bp
->sp_task
);
1156 schedule_work(&bp
->sp_task
);
1159 static void bnxt_cancel_sp_work(struct bnxt
*bp
)
1162 flush_workqueue(bnxt_pf_wq
);
1164 cancel_work_sync(&bp
->sp_task
);
1167 static void bnxt_sched_reset(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
1169 if (!rxr
->bnapi
->in_reset
) {
1170 rxr
->bnapi
->in_reset
= true;
1171 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
1172 bnxt_queue_sp_work(bp
);
1174 rxr
->rx_next_cons
= 0xffff;
1177 static u16
bnxt_alloc_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 agg_id
)
1179 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1180 u16 idx
= agg_id
& MAX_TPA_P5_MASK
;
1182 if (test_bit(idx
, map
->agg_idx_bmap
))
1183 idx
= find_first_zero_bit(map
->agg_idx_bmap
,
1184 BNXT_AGG_IDX_BMAP_SIZE
);
1185 __set_bit(idx
, map
->agg_idx_bmap
);
1186 map
->agg_id_tbl
[agg_id
] = idx
;
1190 static void bnxt_free_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
1192 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1194 __clear_bit(idx
, map
->agg_idx_bmap
);
1197 static u16
bnxt_lookup_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 agg_id
)
1199 struct bnxt_tpa_idx_map
*map
= rxr
->rx_tpa_idx_map
;
1201 return map
->agg_id_tbl
[agg_id
];
1204 static void bnxt_tpa_start(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1205 struct rx_tpa_start_cmp
*tpa_start
,
1206 struct rx_tpa_start_cmp_ext
*tpa_start1
)
1208 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
1209 struct bnxt_tpa_info
*tpa_info
;
1210 u16 cons
, prod
, agg_id
;
1211 struct rx_bd
*prod_bd
;
1214 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
1215 agg_id
= TPA_START_AGG_ID_P5(tpa_start
);
1216 agg_id
= bnxt_alloc_agg_idx(rxr
, agg_id
);
1218 agg_id
= TPA_START_AGG_ID(tpa_start
);
1220 cons
= tpa_start
->rx_tpa_start_cmp_opaque
;
1221 prod
= rxr
->rx_prod
;
1222 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1223 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
1224 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1226 if (unlikely(cons
!= rxr
->rx_next_cons
||
1227 TPA_START_ERROR(tpa_start
))) {
1228 netdev_warn(bp
->dev
, "TPA cons %x, expected cons %x, error code %x\n",
1229 cons
, rxr
->rx_next_cons
,
1230 TPA_START_ERROR_CODE(tpa_start1
));
1231 bnxt_sched_reset(bp
, rxr
);
1234 /* Store cfa_code in tpa_info to use in tpa_end
1235 * completion processing.
1237 tpa_info
->cfa_code
= TPA_START_CFA_CODE(tpa_start1
);
1238 prod_rx_buf
->data
= tpa_info
->data
;
1239 prod_rx_buf
->data_ptr
= tpa_info
->data_ptr
;
1241 mapping
= tpa_info
->mapping
;
1242 prod_rx_buf
->mapping
= mapping
;
1244 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
1246 prod_bd
->rx_bd_haddr
= cpu_to_le64(mapping
);
1248 tpa_info
->data
= cons_rx_buf
->data
;
1249 tpa_info
->data_ptr
= cons_rx_buf
->data_ptr
;
1250 cons_rx_buf
->data
= NULL
;
1251 tpa_info
->mapping
= cons_rx_buf
->mapping
;
1254 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_len_flags_type
) >>
1255 RX_TPA_START_CMP_LEN_SHIFT
;
1256 if (likely(TPA_START_HASH_VALID(tpa_start
))) {
1257 u32 hash_type
= TPA_START_HASH_TYPE(tpa_start
);
1259 tpa_info
->hash_type
= PKT_HASH_TYPE_L4
;
1260 tpa_info
->gso_type
= SKB_GSO_TCPV4
;
1261 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1262 if (hash_type
== 3 || TPA_START_IS_IPV6(tpa_start1
))
1263 tpa_info
->gso_type
= SKB_GSO_TCPV6
;
1264 tpa_info
->rss_hash
=
1265 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_rss_hash
);
1267 tpa_info
->hash_type
= PKT_HASH_TYPE_NONE
;
1268 tpa_info
->gso_type
= 0;
1269 if (netif_msg_rx_err(bp
))
1270 netdev_warn(bp
->dev
, "TPA packet without valid hash\n");
1272 tpa_info
->flags2
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_flags2
);
1273 tpa_info
->metadata
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_metadata
);
1274 tpa_info
->hdr_info
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_hdr_info
);
1275 tpa_info
->agg_count
= 0;
1277 rxr
->rx_prod
= NEXT_RX(prod
);
1278 cons
= NEXT_RX(cons
);
1279 rxr
->rx_next_cons
= NEXT_RX(cons
);
1280 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1282 bnxt_reuse_rx_data(rxr
, cons
, cons_rx_buf
->data
);
1283 rxr
->rx_prod
= NEXT_RX(rxr
->rx_prod
);
1284 cons_rx_buf
->data
= NULL
;
1287 static void bnxt_abort_tpa(struct bnxt_cp_ring_info
*cpr
, u16 idx
, u32 agg_bufs
)
1290 bnxt_reuse_rx_agg_bufs(cpr
, idx
, 0, agg_bufs
, true);
1294 static void bnxt_gro_tunnel(struct sk_buff
*skb
, __be16 ip_proto
)
1296 struct udphdr
*uh
= NULL
;
1298 if (ip_proto
== htons(ETH_P_IP
)) {
1299 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1301 if (iph
->protocol
== IPPROTO_UDP
)
1302 uh
= (struct udphdr
*)(iph
+ 1);
1304 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1306 if (iph
->nexthdr
== IPPROTO_UDP
)
1307 uh
= (struct udphdr
*)(iph
+ 1);
1311 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL_CSUM
;
1313 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1318 static struct sk_buff
*bnxt_gro_func_5731x(struct bnxt_tpa_info
*tpa_info
,
1319 int payload_off
, int tcp_ts
,
1320 struct sk_buff
*skb
)
1325 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1326 u32 hdr_info
= tpa_info
->hdr_info
;
1327 bool loopback
= false;
1329 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1330 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1331 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1333 /* If the packet is an internal loopback packet, the offsets will
1334 * have an extra 4 bytes.
1336 if (inner_mac_off
== 4) {
1338 } else if (inner_mac_off
> 4) {
1339 __be16 proto
= *((__be16
*)(skb
->data
+ inner_ip_off
-
1342 /* We only support inner iPv4/ipv6. If we don't see the
1343 * correct protocol ID, it must be a loopback packet where
1344 * the offsets are off by 4.
1346 if (proto
!= htons(ETH_P_IP
) && proto
!= htons(ETH_P_IPV6
))
1350 /* internal loopback packet, subtract all offsets by 4 */
1356 nw_off
= inner_ip_off
- ETH_HLEN
;
1357 skb_set_network_header(skb
, nw_off
);
1358 if (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) {
1359 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
1361 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1362 len
= skb
->len
- skb_transport_offset(skb
);
1364 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1366 struct iphdr
*iph
= ip_hdr(skb
);
1368 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1369 len
= skb
->len
- skb_transport_offset(skb
);
1371 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1374 if (inner_mac_off
) { /* tunnel */
1375 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1378 bnxt_gro_tunnel(skb
, proto
);
1384 static struct sk_buff
*bnxt_gro_func_5750x(struct bnxt_tpa_info
*tpa_info
,
1385 int payload_off
, int tcp_ts
,
1386 struct sk_buff
*skb
)
1389 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1390 u32 hdr_info
= tpa_info
->hdr_info
;
1391 int iphdr_len
, nw_off
;
1393 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1394 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1395 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1397 nw_off
= inner_ip_off
- ETH_HLEN
;
1398 skb_set_network_header(skb
, nw_off
);
1399 iphdr_len
= (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) ?
1400 sizeof(struct ipv6hdr
) : sizeof(struct iphdr
);
1401 skb_set_transport_header(skb
, nw_off
+ iphdr_len
);
1403 if (inner_mac_off
) { /* tunnel */
1404 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1407 bnxt_gro_tunnel(skb
, proto
);
1413 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1414 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1416 static struct sk_buff
*bnxt_gro_func_5730x(struct bnxt_tpa_info
*tpa_info
,
1417 int payload_off
, int tcp_ts
,
1418 struct sk_buff
*skb
)
1422 int len
, nw_off
, tcp_opt_len
= 0;
1427 if (tpa_info
->gso_type
== SKB_GSO_TCPV4
) {
1430 nw_off
= payload_off
- BNXT_IPV4_HDR_SIZE
- tcp_opt_len
-
1432 skb_set_network_header(skb
, nw_off
);
1434 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1435 len
= skb
->len
- skb_transport_offset(skb
);
1437 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1438 } else if (tpa_info
->gso_type
== SKB_GSO_TCPV6
) {
1439 struct ipv6hdr
*iph
;
1441 nw_off
= payload_off
- BNXT_IPV6_HDR_SIZE
- tcp_opt_len
-
1443 skb_set_network_header(skb
, nw_off
);
1444 iph
= ipv6_hdr(skb
);
1445 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1446 len
= skb
->len
- skb_transport_offset(skb
);
1448 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1450 dev_kfree_skb_any(skb
);
1454 if (nw_off
) /* tunnel */
1455 bnxt_gro_tunnel(skb
, skb
->protocol
);
1460 static inline struct sk_buff
*bnxt_gro_skb(struct bnxt
*bp
,
1461 struct bnxt_tpa_info
*tpa_info
,
1462 struct rx_tpa_end_cmp
*tpa_end
,
1463 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1464 struct sk_buff
*skb
)
1470 segs
= TPA_END_TPA_SEGS(tpa_end
);
1474 NAPI_GRO_CB(skb
)->count
= segs
;
1475 skb_shinfo(skb
)->gso_size
=
1476 le32_to_cpu(tpa_end1
->rx_tpa_end_cmp_seg_len
);
1477 skb_shinfo(skb
)->gso_type
= tpa_info
->gso_type
;
1478 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
1479 payload_off
= TPA_END_PAYLOAD_OFF_P5(tpa_end1
);
1481 payload_off
= TPA_END_PAYLOAD_OFF(tpa_end
);
1482 skb
= bp
->gro_func(tpa_info
, payload_off
, TPA_END_GRO_TS(tpa_end
), skb
);
1484 tcp_gro_complete(skb
);
1489 /* Given the cfa_code of a received packet determine which
1490 * netdev (vf-rep or PF) the packet is destined to.
1492 static struct net_device
*bnxt_get_pkt_dev(struct bnxt
*bp
, u16 cfa_code
)
1494 struct net_device
*dev
= bnxt_get_vf_rep(bp
, cfa_code
);
1496 /* if vf-rep dev is NULL, the must belongs to the PF */
1497 return dev
? dev
: bp
->dev
;
1500 static inline struct sk_buff
*bnxt_tpa_end(struct bnxt
*bp
,
1501 struct bnxt_cp_ring_info
*cpr
,
1503 struct rx_tpa_end_cmp
*tpa_end
,
1504 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1507 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1508 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1509 u8
*data_ptr
, agg_bufs
;
1511 struct bnxt_tpa_info
*tpa_info
;
1513 struct sk_buff
*skb
;
1514 u16 idx
= 0, agg_id
;
1518 if (unlikely(bnapi
->in_reset
)) {
1519 int rc
= bnxt_discard_rx(bp
, cpr
, raw_cons
, tpa_end
);
1522 return ERR_PTR(-EBUSY
);
1526 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
1527 agg_id
= TPA_END_AGG_ID_P5(tpa_end
);
1528 agg_id
= bnxt_lookup_agg_idx(rxr
, agg_id
);
1529 agg_bufs
= TPA_END_AGG_BUFS_P5(tpa_end1
);
1530 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1531 if (unlikely(agg_bufs
!= tpa_info
->agg_count
)) {
1532 netdev_warn(bp
->dev
, "TPA end agg_buf %d != expected agg_bufs %d\n",
1533 agg_bufs
, tpa_info
->agg_count
);
1534 agg_bufs
= tpa_info
->agg_count
;
1536 tpa_info
->agg_count
= 0;
1537 *event
|= BNXT_AGG_EVENT
;
1538 bnxt_free_agg_idx(rxr
, agg_id
);
1540 gro
= !!(bp
->flags
& BNXT_FLAG_GRO
);
1542 agg_id
= TPA_END_AGG_ID(tpa_end
);
1543 agg_bufs
= TPA_END_AGG_BUFS(tpa_end
);
1544 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1545 idx
= RING_CMP(*raw_cons
);
1547 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, raw_cons
))
1548 return ERR_PTR(-EBUSY
);
1550 *event
|= BNXT_AGG_EVENT
;
1551 idx
= NEXT_CMP(idx
);
1553 gro
= !!TPA_END_GRO(tpa_end
);
1555 data
= tpa_info
->data
;
1556 data_ptr
= tpa_info
->data_ptr
;
1558 len
= tpa_info
->len
;
1559 mapping
= tpa_info
->mapping
;
1561 if (unlikely(agg_bufs
> MAX_SKB_FRAGS
|| TPA_END_ERRORS(tpa_end1
))) {
1562 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1563 if (agg_bufs
> MAX_SKB_FRAGS
)
1564 netdev_warn(bp
->dev
, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1565 agg_bufs
, (int)MAX_SKB_FRAGS
);
1569 if (len
<= bp
->rx_copy_thresh
) {
1570 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, mapping
);
1572 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1577 dma_addr_t new_mapping
;
1579 new_data
= __bnxt_alloc_rx_data(bp
, &new_mapping
, GFP_ATOMIC
);
1581 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1585 tpa_info
->data
= new_data
;
1586 tpa_info
->data_ptr
= new_data
+ bp
->rx_offset
;
1587 tpa_info
->mapping
= new_mapping
;
1589 skb
= build_skb(data
, 0);
1590 dma_unmap_single_attrs(&bp
->pdev
->dev
, mapping
,
1591 bp
->rx_buf_use_size
, bp
->rx_dir
,
1592 DMA_ATTR_WEAK_ORDERING
);
1596 bnxt_abort_tpa(cpr
, idx
, agg_bufs
);
1599 skb_reserve(skb
, bp
->rx_offset
);
1604 skb
= bnxt_rx_pages(bp
, cpr
, skb
, idx
, agg_bufs
, true);
1606 /* Page reuse already handled by bnxt_rx_pages(). */
1612 eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, tpa_info
->cfa_code
));
1614 if (tpa_info
->hash_type
!= PKT_HASH_TYPE_NONE
)
1615 skb_set_hash(skb
, tpa_info
->rss_hash
, tpa_info
->hash_type
);
1617 if ((tpa_info
->flags2
& RX_CMP_FLAGS2_META_FORMAT_VLAN
) &&
1618 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1619 u16 vlan_proto
= tpa_info
->metadata
>>
1620 RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1621 u16 vtag
= tpa_info
->metadata
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1623 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1626 skb_checksum_none_assert(skb
);
1627 if (likely(tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_L4_CS_CALC
)) {
1628 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1630 (tpa_info
->flags2
& RX_CMP_FLAGS2_T_L4_CS_CALC
) >> 3;
1634 skb
= bnxt_gro_skb(bp
, tpa_info
, tpa_end
, tpa_end1
, skb
);
1639 static void bnxt_tpa_agg(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1640 struct rx_agg_cmp
*rx_agg
)
1642 u16 agg_id
= TPA_AGG_AGG_ID(rx_agg
);
1643 struct bnxt_tpa_info
*tpa_info
;
1645 agg_id
= bnxt_lookup_agg_idx(rxr
, agg_id
);
1646 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1647 BUG_ON(tpa_info
->agg_count
>= MAX_SKB_FRAGS
);
1648 tpa_info
->agg_arr
[tpa_info
->agg_count
++] = *rx_agg
;
1651 static void bnxt_deliver_skb(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1652 struct sk_buff
*skb
)
1654 if (skb
->dev
!= bp
->dev
) {
1655 /* this packet belongs to a vf-rep */
1656 bnxt_vf_rep_rx(bp
, skb
);
1659 skb_record_rx_queue(skb
, bnapi
->index
);
1660 napi_gro_receive(&bnapi
->napi
, skb
);
1663 /* returns the following:
1664 * 1 - 1 packet successfully received
1665 * 0 - successful TPA_START, packet not completed yet
1666 * -EBUSY - completion ring does not have all the agg buffers yet
1667 * -ENOMEM - packet aborted due to out of memory
1668 * -EIO - packet aborted due to hw error indicated in BD
1670 static int bnxt_rx_pkt(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1671 u32
*raw_cons
, u8
*event
)
1673 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1674 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1675 struct net_device
*dev
= bp
->dev
;
1676 struct rx_cmp
*rxcmp
;
1677 struct rx_cmp_ext
*rxcmp1
;
1678 u32 tmp_raw_cons
= *raw_cons
;
1679 u16 cfa_code
, cons
, prod
, cp_cons
= RING_CMP(tmp_raw_cons
);
1680 struct bnxt_sw_rx_bd
*rx_buf
;
1682 u8
*data_ptr
, agg_bufs
, cmp_type
;
1683 dma_addr_t dma_addr
;
1684 struct sk_buff
*skb
;
1689 rxcmp
= (struct rx_cmp
*)
1690 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1692 cmp_type
= RX_CMP_TYPE(rxcmp
);
1694 if (cmp_type
== CMP_TYPE_RX_TPA_AGG_CMP
) {
1695 bnxt_tpa_agg(bp
, rxr
, (struct rx_agg_cmp
*)rxcmp
);
1696 goto next_rx_no_prod_no_len
;
1699 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1700 cp_cons
= RING_CMP(tmp_raw_cons
);
1701 rxcmp1
= (struct rx_cmp_ext
*)
1702 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1704 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1707 prod
= rxr
->rx_prod
;
1709 if (cmp_type
== CMP_TYPE_RX_L2_TPA_START_CMP
) {
1710 bnxt_tpa_start(bp
, rxr
, (struct rx_tpa_start_cmp
*)rxcmp
,
1711 (struct rx_tpa_start_cmp_ext
*)rxcmp1
);
1713 *event
|= BNXT_RX_EVENT
;
1714 goto next_rx_no_prod_no_len
;
1716 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1717 skb
= bnxt_tpa_end(bp
, cpr
, &tmp_raw_cons
,
1718 (struct rx_tpa_end_cmp
*)rxcmp
,
1719 (struct rx_tpa_end_cmp_ext
*)rxcmp1
, event
);
1726 bnxt_deliver_skb(bp
, bnapi
, skb
);
1729 *event
|= BNXT_RX_EVENT
;
1730 goto next_rx_no_prod_no_len
;
1733 cons
= rxcmp
->rx_cmp_opaque
;
1734 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1735 int rc1
= bnxt_discard_rx(bp
, cpr
, raw_cons
, rxcmp
);
1737 netdev_warn(bp
->dev
, "RX cons %x != expected cons %x\n",
1738 cons
, rxr
->rx_next_cons
);
1739 bnxt_sched_reset(bp
, rxr
);
1742 rx_buf
= &rxr
->rx_buf_ring
[cons
];
1743 data
= rx_buf
->data
;
1744 data_ptr
= rx_buf
->data_ptr
;
1747 misc
= le32_to_cpu(rxcmp
->rx_cmp_misc_v1
);
1748 agg_bufs
= (misc
& RX_CMP_AGG_BUFS
) >> RX_CMP_AGG_BUFS_SHIFT
;
1751 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1754 cp_cons
= NEXT_CMP(cp_cons
);
1755 *event
|= BNXT_AGG_EVENT
;
1757 *event
|= BNXT_RX_EVENT
;
1759 rx_buf
->data
= NULL
;
1760 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L2_ERRORS
) {
1761 u32 rx_err
= le32_to_cpu(rxcmp1
->rx_cmp_cfa_code_errors_v2
);
1763 bnxt_reuse_rx_data(rxr
, cons
, data
);
1765 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, 0, agg_bufs
,
1769 if (rx_err
& RX_CMPL_ERRORS_BUFFER_ERROR_MASK
) {
1770 netdev_warn(bp
->dev
, "RX buffer error %x\n", rx_err
);
1771 bnxt_sched_reset(bp
, rxr
);
1773 goto next_rx_no_len
;
1776 len
= le32_to_cpu(rxcmp
->rx_cmp_len_flags_type
) >> RX_CMP_LEN_SHIFT
;
1777 dma_addr
= rx_buf
->mapping
;
1779 if (bnxt_rx_xdp(bp
, rxr
, cons
, data
, &data_ptr
, &len
, event
)) {
1784 if (len
<= bp
->rx_copy_thresh
) {
1785 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, dma_addr
);
1786 bnxt_reuse_rx_data(rxr
, cons
, data
);
1789 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, 0,
1797 if (rx_buf
->data_ptr
== data_ptr
)
1798 payload
= misc
& RX_CMP_PAYLOAD_OFFSET
;
1801 skb
= bp
->rx_skb_func(bp
, rxr
, cons
, data
, data_ptr
, dma_addr
,
1810 skb
= bnxt_rx_pages(bp
, cpr
, skb
, cp_cons
, agg_bufs
, false);
1817 if (RX_CMP_HASH_VALID(rxcmp
)) {
1818 u32 hash_type
= RX_CMP_HASH_TYPE(rxcmp
);
1819 enum pkt_hash_types type
= PKT_HASH_TYPE_L4
;
1821 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1822 if (hash_type
!= 1 && hash_type
!= 3)
1823 type
= PKT_HASH_TYPE_L3
;
1824 skb_set_hash(skb
, le32_to_cpu(rxcmp
->rx_cmp_rss_hash
), type
);
1827 cfa_code
= RX_CMP_CFA_CODE(rxcmp1
);
1828 skb
->protocol
= eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, cfa_code
));
1830 if ((rxcmp1
->rx_cmp_flags2
&
1831 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN
)) &&
1832 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1833 u32 meta_data
= le32_to_cpu(rxcmp1
->rx_cmp_meta_data
);
1834 u16 vtag
= meta_data
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1835 u16 vlan_proto
= meta_data
>> RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1837 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1840 skb_checksum_none_assert(skb
);
1841 if (RX_CMP_L4_CS_OK(rxcmp1
)) {
1842 if (dev
->features
& NETIF_F_RXCSUM
) {
1843 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1844 skb
->csum_level
= RX_CMP_ENCAP(rxcmp1
);
1847 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L4_CS_ERR_BITS
) {
1848 if (dev
->features
& NETIF_F_RXCSUM
)
1849 bnapi
->cp_ring
.rx_l4_csum_errors
++;
1853 bnxt_deliver_skb(bp
, bnapi
, skb
);
1857 cpr
->rx_packets
+= 1;
1858 cpr
->rx_bytes
+= len
;
1861 rxr
->rx_prod
= NEXT_RX(prod
);
1862 rxr
->rx_next_cons
= NEXT_RX(cons
);
1864 next_rx_no_prod_no_len
:
1865 *raw_cons
= tmp_raw_cons
;
1870 /* In netpoll mode, if we are using a combined completion ring, we need to
1871 * discard the rx packets and recycle the buffers.
1873 static int bnxt_force_rx_discard(struct bnxt
*bp
,
1874 struct bnxt_cp_ring_info
*cpr
,
1875 u32
*raw_cons
, u8
*event
)
1877 u32 tmp_raw_cons
= *raw_cons
;
1878 struct rx_cmp_ext
*rxcmp1
;
1879 struct rx_cmp
*rxcmp
;
1883 cp_cons
= RING_CMP(tmp_raw_cons
);
1884 rxcmp
= (struct rx_cmp
*)
1885 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1887 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1888 cp_cons
= RING_CMP(tmp_raw_cons
);
1889 rxcmp1
= (struct rx_cmp_ext
*)
1890 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1892 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1895 cmp_type
= RX_CMP_TYPE(rxcmp
);
1896 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1897 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
1898 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
1899 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1900 struct rx_tpa_end_cmp_ext
*tpa_end1
;
1902 tpa_end1
= (struct rx_tpa_end_cmp_ext
*)rxcmp1
;
1903 tpa_end1
->rx_tpa_end_cmp_errors_v2
|=
1904 cpu_to_le32(RX_TPA_END_CMP_ERRORS
);
1906 return bnxt_rx_pkt(bp
, cpr
, raw_cons
, event
);
1909 u32
bnxt_fw_health_readl(struct bnxt
*bp
, int reg_idx
)
1911 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
1912 u32 reg
= fw_health
->regs
[reg_idx
];
1913 u32 reg_type
, reg_off
, val
= 0;
1915 reg_type
= BNXT_FW_HEALTH_REG_TYPE(reg
);
1916 reg_off
= BNXT_FW_HEALTH_REG_OFF(reg
);
1918 case BNXT_FW_HEALTH_REG_TYPE_CFG
:
1919 pci_read_config_dword(bp
->pdev
, reg_off
, &val
);
1921 case BNXT_FW_HEALTH_REG_TYPE_GRC
:
1922 reg_off
= fw_health
->mapped_regs
[reg_idx
];
1924 case BNXT_FW_HEALTH_REG_TYPE_BAR0
:
1925 val
= readl(bp
->bar0
+ reg_off
);
1927 case BNXT_FW_HEALTH_REG_TYPE_BAR1
:
1928 val
= readl(bp
->bar1
+ reg_off
);
1931 if (reg_idx
== BNXT_FW_RESET_INPROG_REG
)
1932 val
&= fw_health
->fw_reset_inprog_reg_mask
;
1936 #define BNXT_GET_EVENT_PORT(data) \
1938 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
1940 static int bnxt_async_event_process(struct bnxt
*bp
,
1941 struct hwrm_async_event_cmpl
*cmpl
)
1943 u16 event_id
= le16_to_cpu(cmpl
->event_id
);
1945 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1947 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
: {
1948 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1949 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1952 goto async_event_process_exit
;
1954 /* print unsupported speed warning in forced speed mode only */
1955 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
) &&
1956 (data1
& 0x20000)) {
1957 u16 fw_speed
= link_info
->force_link_speed
;
1958 u32 speed
= bnxt_fw_to_ethtool_speed(fw_speed
);
1960 if (speed
!= SPEED_UNKNOWN
)
1961 netdev_warn(bp
->dev
, "Link speed %d no longer supported\n",
1964 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
, &bp
->sp_event
);
1967 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
:
1968 set_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
);
1970 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
:
1971 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
);
1973 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
: {
1974 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1975 u16 port_id
= BNXT_GET_EVENT_PORT(data1
);
1980 if (bp
->pf
.port_id
!= port_id
)
1983 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
);
1986 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
:
1988 goto async_event_process_exit
;
1989 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
);
1991 case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY
: {
1992 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1994 bp
->fw_reset_timestamp
= jiffies
;
1995 bp
->fw_reset_min_dsecs
= cmpl
->timestamp_lo
;
1996 if (!bp
->fw_reset_min_dsecs
)
1997 bp
->fw_reset_min_dsecs
= BNXT_DFLT_FW_RST_MIN_DSECS
;
1998 bp
->fw_reset_max_dsecs
= le16_to_cpu(cmpl
->timestamp_hi
);
1999 if (!bp
->fw_reset_max_dsecs
)
2000 bp
->fw_reset_max_dsecs
= BNXT_DFLT_FW_RST_MAX_DSECS
;
2001 if (EVENT_DATA1_RESET_NOTIFY_FATAL(data1
)) {
2002 netdev_warn(bp
->dev
, "Firmware fatal reset event received\n");
2003 set_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
2005 netdev_warn(bp
->dev
, "Firmware non-fatal reset event received, max wait time %d msec\n",
2006 bp
->fw_reset_max_dsecs
* 100);
2008 set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT
, &bp
->sp_event
);
2011 case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
: {
2012 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
2013 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
2016 goto async_event_process_exit
;
2018 fw_health
->enabled
= EVENT_DATA1_RECOVERY_ENABLED(data1
);
2019 fw_health
->master
= EVENT_DATA1_RECOVERY_MASTER_FUNC(data1
);
2020 if (!fw_health
->enabled
)
2023 if (netif_msg_drv(bp
))
2024 netdev_info(bp
->dev
, "Error recovery info: error recovery[%d], master[%d], reset count[0x%x], health status: 0x%x\n",
2025 fw_health
->enabled
, fw_health
->master
,
2026 bnxt_fw_health_readl(bp
,
2027 BNXT_FW_RESET_CNT_REG
),
2028 bnxt_fw_health_readl(bp
,
2029 BNXT_FW_HEALTH_REG
));
2030 fw_health
->tmr_multiplier
=
2031 DIV_ROUND_UP(fw_health
->polling_dsecs
* HZ
,
2032 bp
->current_interval
* 10);
2033 fw_health
->tmr_counter
= fw_health
->tmr_multiplier
;
2034 fw_health
->last_fw_heartbeat
=
2035 bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
2036 fw_health
->last_fw_reset_cnt
=
2037 bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
2038 goto async_event_process_exit
;
2041 goto async_event_process_exit
;
2043 bnxt_queue_sp_work(bp
);
2044 async_event_process_exit
:
2045 bnxt_ulp_async_events(bp
, cmpl
);
2049 static int bnxt_hwrm_handler(struct bnxt
*bp
, struct tx_cmp
*txcmp
)
2051 u16 cmpl_type
= TX_CMP_TYPE(txcmp
), vf_id
, seq_id
;
2052 struct hwrm_cmpl
*h_cmpl
= (struct hwrm_cmpl
*)txcmp
;
2053 struct hwrm_fwd_req_cmpl
*fwd_req_cmpl
=
2054 (struct hwrm_fwd_req_cmpl
*)txcmp
;
2056 switch (cmpl_type
) {
2057 case CMPL_BASE_TYPE_HWRM_DONE
:
2058 seq_id
= le16_to_cpu(h_cmpl
->sequence_id
);
2059 if (seq_id
== bp
->hwrm_intr_seq_id
)
2060 bp
->hwrm_intr_seq_id
= (u16
)~bp
->hwrm_intr_seq_id
;
2062 netdev_err(bp
->dev
, "Invalid hwrm seq id %d\n", seq_id
);
2065 case CMPL_BASE_TYPE_HWRM_FWD_REQ
:
2066 vf_id
= le16_to_cpu(fwd_req_cmpl
->source_id
);
2068 if ((vf_id
< bp
->pf
.first_vf_id
) ||
2069 (vf_id
>= bp
->pf
.first_vf_id
+ bp
->pf
.active_vfs
)) {
2070 netdev_err(bp
->dev
, "Msg contains invalid VF id %x\n",
2075 set_bit(vf_id
- bp
->pf
.first_vf_id
, bp
->pf
.vf_event_bmap
);
2076 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
);
2077 bnxt_queue_sp_work(bp
);
2080 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
:
2081 bnxt_async_event_process(bp
,
2082 (struct hwrm_async_event_cmpl
*)txcmp
);
2091 static irqreturn_t
bnxt_msix(int irq
, void *dev_instance
)
2093 struct bnxt_napi
*bnapi
= dev_instance
;
2094 struct bnxt
*bp
= bnapi
->bp
;
2095 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2096 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
2099 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
2100 napi_schedule(&bnapi
->napi
);
2104 static inline int bnxt_has_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
)
2106 u32 raw_cons
= cpr
->cp_raw_cons
;
2107 u16 cons
= RING_CMP(raw_cons
);
2108 struct tx_cmp
*txcmp
;
2110 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2112 return TX_CMP_VALID(txcmp
, raw_cons
);
2115 static irqreturn_t
bnxt_inta(int irq
, void *dev_instance
)
2117 struct bnxt_napi
*bnapi
= dev_instance
;
2118 struct bnxt
*bp
= bnapi
->bp
;
2119 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2120 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
2123 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
2125 if (!bnxt_has_work(bp
, cpr
)) {
2126 int_status
= readl(bp
->bar0
+ BNXT_CAG_REG_LEGACY_INT_STATUS
);
2127 /* return if erroneous interrupt */
2128 if (!(int_status
& (0x10000 << cpr
->cp_ring_struct
.fw_ring_id
)))
2132 /* disable ring IRQ */
2133 BNXT_CP_DB_IRQ_DIS(cpr
->cp_db
.doorbell
);
2135 /* Return here if interrupt is shared and is disabled. */
2136 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
2139 napi_schedule(&bnapi
->napi
);
2143 static int __bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
2146 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
2147 u32 raw_cons
= cpr
->cp_raw_cons
;
2152 struct tx_cmp
*txcmp
;
2154 cpr
->has_more_work
= 0;
2158 cons
= RING_CMP(raw_cons
);
2159 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2161 if (!TX_CMP_VALID(txcmp
, raw_cons
))
2164 /* The valid test of the entry must be done first before
2165 * reading any further.
2168 cpr
->had_work_done
= 1;
2169 if (TX_CMP_TYPE(txcmp
) == CMP_TYPE_TX_L2_CMP
) {
2171 /* return full budget so NAPI will complete. */
2172 if (unlikely(tx_pkts
> bp
->tx_wake_thresh
)) {
2174 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2176 cpr
->has_more_work
= 1;
2179 } else if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
2181 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
2183 rc
= bnxt_force_rx_discard(bp
, cpr
, &raw_cons
,
2185 if (likely(rc
>= 0))
2187 /* Increment rx_pkts when rc is -ENOMEM to count towards
2188 * the NAPI budget. Otherwise, we may potentially loop
2189 * here forever if we consistently cannot allocate
2192 else if (rc
== -ENOMEM
&& budget
)
2194 else if (rc
== -EBUSY
) /* partial completion */
2196 } else if (unlikely((TX_CMP_TYPE(txcmp
) ==
2197 CMPL_BASE_TYPE_HWRM_DONE
) ||
2198 (TX_CMP_TYPE(txcmp
) ==
2199 CMPL_BASE_TYPE_HWRM_FWD_REQ
) ||
2200 (TX_CMP_TYPE(txcmp
) ==
2201 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
))) {
2202 bnxt_hwrm_handler(bp
, txcmp
);
2204 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2206 if (rx_pkts
&& rx_pkts
== budget
) {
2207 cpr
->has_more_work
= 1;
2212 if (event
& BNXT_REDIRECT_EVENT
)
2215 if (event
& BNXT_TX_EVENT
) {
2216 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
2217 u16 prod
= txr
->tx_prod
;
2219 /* Sync BD data before updating doorbell */
2222 bnxt_db_write_relaxed(bp
, &txr
->tx_db
, prod
);
2225 cpr
->cp_raw_cons
= raw_cons
;
2226 bnapi
->tx_pkts
+= tx_pkts
;
2227 bnapi
->events
|= event
;
2231 static void __bnxt_poll_work_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
2233 if (bnapi
->tx_pkts
) {
2234 bnapi
->tx_int(bp
, bnapi
, bnapi
->tx_pkts
);
2238 if (bnapi
->events
& BNXT_RX_EVENT
) {
2239 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2241 if (bnapi
->events
& BNXT_AGG_EVENT
)
2242 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2243 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2248 static int bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
2251 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
2254 rx_pkts
= __bnxt_poll_work(bp
, cpr
, budget
);
2256 /* ACK completion ring before freeing tx ring and producing new
2257 * buffers in rx/agg rings to prevent overflowing the completion
2260 bnxt_db_cq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
2262 __bnxt_poll_work_done(bp
, bnapi
);
2266 static int bnxt_poll_nitroa0(struct napi_struct
*napi
, int budget
)
2268 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2269 struct bnxt
*bp
= bnapi
->bp
;
2270 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2271 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2272 struct tx_cmp
*txcmp
;
2273 struct rx_cmp_ext
*rxcmp1
;
2274 u32 cp_cons
, tmp_raw_cons
;
2275 u32 raw_cons
= cpr
->cp_raw_cons
;
2282 cp_cons
= RING_CMP(raw_cons
);
2283 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2285 if (!TX_CMP_VALID(txcmp
, raw_cons
))
2288 if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
2289 tmp_raw_cons
= NEXT_RAW_CMP(raw_cons
);
2290 cp_cons
= RING_CMP(tmp_raw_cons
);
2291 rxcmp1
= (struct rx_cmp_ext
*)
2292 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2294 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
2297 /* force an error to recycle the buffer */
2298 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
2299 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
2301 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
2302 if (likely(rc
== -EIO
) && budget
)
2304 else if (rc
== -EBUSY
) /* partial completion */
2306 } else if (unlikely(TX_CMP_TYPE(txcmp
) ==
2307 CMPL_BASE_TYPE_HWRM_DONE
)) {
2308 bnxt_hwrm_handler(bp
, txcmp
);
2311 "Invalid completion received on special ring\n");
2313 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2315 if (rx_pkts
== budget
)
2319 cpr
->cp_raw_cons
= raw_cons
;
2320 BNXT_DB_CQ(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2321 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2323 if (event
& BNXT_AGG_EVENT
)
2324 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2326 if (!bnxt_has_work(bp
, cpr
) && rx_pkts
< budget
) {
2327 napi_complete_done(napi
, rx_pkts
);
2328 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2333 static int bnxt_poll(struct napi_struct
*napi
, int budget
)
2335 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2336 struct bnxt
*bp
= bnapi
->bp
;
2337 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2341 work_done
+= bnxt_poll_work(bp
, cpr
, budget
- work_done
);
2343 if (work_done
>= budget
) {
2345 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2349 if (!bnxt_has_work(bp
, cpr
)) {
2350 if (napi_complete_done(napi
, work_done
))
2351 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2355 if (bp
->flags
& BNXT_FLAG_DIM
) {
2356 struct dim_sample dim_sample
= {};
2358 dim_update_sample(cpr
->event_ctr
,
2362 net_dim(&cpr
->dim
, dim_sample
);
2367 static int __bnxt_poll_cqs(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int budget
)
2369 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2370 int i
, work_done
= 0;
2372 for (i
= 0; i
< 2; i
++) {
2373 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2376 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2377 budget
- work_done
);
2378 cpr
->has_more_work
|= cpr2
->has_more_work
;
2384 static void __bnxt_poll_cqs_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
2385 u64 dbr_type
, bool all
)
2387 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2390 for (i
= 0; i
< 2; i
++) {
2391 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2392 struct bnxt_db_info
*db
;
2394 if (cpr2
&& (all
|| cpr2
->had_work_done
)) {
2396 writeq(db
->db_key64
| dbr_type
|
2397 RING_CMP(cpr2
->cp_raw_cons
), db
->doorbell
);
2398 cpr2
->had_work_done
= 0;
2401 __bnxt_poll_work_done(bp
, bnapi
);
2404 static int bnxt_poll_p5(struct napi_struct
*napi
, int budget
)
2406 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2407 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2408 u32 raw_cons
= cpr
->cp_raw_cons
;
2409 struct bnxt
*bp
= bnapi
->bp
;
2410 struct nqe_cn
*nqcmp
;
2414 if (cpr
->has_more_work
) {
2415 cpr
->has_more_work
= 0;
2416 work_done
= __bnxt_poll_cqs(bp
, bnapi
, budget
);
2417 if (cpr
->has_more_work
) {
2418 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ
, false);
2421 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ_ARMALL
, true);
2422 if (napi_complete_done(napi
, work_done
))
2423 BNXT_DB_NQ_ARM_P5(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2427 cons
= RING_CMP(raw_cons
);
2428 nqcmp
= &cpr
->nq_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2430 if (!NQ_CMP_VALID(nqcmp
, raw_cons
)) {
2431 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ_ARMALL
,
2433 cpr
->cp_raw_cons
= raw_cons
;
2434 if (napi_complete_done(napi
, work_done
))
2435 BNXT_DB_NQ_ARM_P5(&cpr
->cp_db
,
2440 /* The valid test of the entry must be done first before
2441 * reading any further.
2445 if (nqcmp
->type
== cpu_to_le16(NQ_CN_TYPE_CQ_NOTIFICATION
)) {
2446 u32 idx
= le32_to_cpu(nqcmp
->cq_handle_low
);
2447 struct bnxt_cp_ring_info
*cpr2
;
2449 cpr2
= cpr
->cp_ring_arr
[idx
];
2450 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2451 budget
- work_done
);
2452 cpr
->has_more_work
= cpr2
->has_more_work
;
2454 bnxt_hwrm_handler(bp
, (struct tx_cmp
*)nqcmp
);
2456 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2457 if (cpr
->has_more_work
)
2460 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ
, true);
2461 cpr
->cp_raw_cons
= raw_cons
;
2465 static void bnxt_free_tx_skbs(struct bnxt
*bp
)
2468 struct pci_dev
*pdev
= bp
->pdev
;
2473 max_idx
= bp
->tx_nr_pages
* TX_DESC_CNT
;
2474 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2475 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2478 for (j
= 0; j
< max_idx
;) {
2479 struct bnxt_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
2480 struct sk_buff
*skb
;
2483 if (i
< bp
->tx_nr_rings_xdp
&&
2484 tx_buf
->action
== XDP_REDIRECT
) {
2485 dma_unmap_single(&pdev
->dev
,
2486 dma_unmap_addr(tx_buf
, mapping
),
2487 dma_unmap_len(tx_buf
, len
),
2489 xdp_return_frame(tx_buf
->xdpf
);
2491 tx_buf
->xdpf
= NULL
;
2504 if (tx_buf
->is_push
) {
2510 dma_unmap_single(&pdev
->dev
,
2511 dma_unmap_addr(tx_buf
, mapping
),
2515 last
= tx_buf
->nr_frags
;
2517 for (k
= 0; k
< last
; k
++, j
++) {
2518 int ring_idx
= j
& bp
->tx_ring_mask
;
2519 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[k
];
2521 tx_buf
= &txr
->tx_buf_ring
[ring_idx
];
2524 dma_unmap_addr(tx_buf
, mapping
),
2525 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
2529 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
2533 static void bnxt_free_rx_skbs(struct bnxt
*bp
)
2535 int i
, max_idx
, max_agg_idx
;
2536 struct pci_dev
*pdev
= bp
->pdev
;
2541 max_idx
= bp
->rx_nr_pages
* RX_DESC_CNT
;
2542 max_agg_idx
= bp
->rx_agg_nr_pages
* RX_DESC_CNT
;
2543 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2544 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2545 struct bnxt_tpa_idx_map
*map
;
2549 for (j
= 0; j
< bp
->max_tpa
; j
++) {
2550 struct bnxt_tpa_info
*tpa_info
=
2552 u8
*data
= tpa_info
->data
;
2557 dma_unmap_single_attrs(&pdev
->dev
,
2559 bp
->rx_buf_use_size
,
2561 DMA_ATTR_WEAK_ORDERING
);
2563 tpa_info
->data
= NULL
;
2569 for (j
= 0; j
< max_idx
; j
++) {
2570 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[j
];
2571 dma_addr_t mapping
= rx_buf
->mapping
;
2572 void *data
= rx_buf
->data
;
2577 rx_buf
->data
= NULL
;
2579 if (BNXT_RX_PAGE_MODE(bp
)) {
2580 mapping
-= bp
->rx_dma_offset
;
2581 dma_unmap_page_attrs(&pdev
->dev
, mapping
,
2582 PAGE_SIZE
, bp
->rx_dir
,
2583 DMA_ATTR_WEAK_ORDERING
);
2584 page_pool_recycle_direct(rxr
->page_pool
, data
);
2586 dma_unmap_single_attrs(&pdev
->dev
, mapping
,
2587 bp
->rx_buf_use_size
,
2589 DMA_ATTR_WEAK_ORDERING
);
2594 for (j
= 0; j
< max_agg_idx
; j
++) {
2595 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
=
2596 &rxr
->rx_agg_ring
[j
];
2597 struct page
*page
= rx_agg_buf
->page
;
2602 dma_unmap_page_attrs(&pdev
->dev
, rx_agg_buf
->mapping
,
2605 DMA_ATTR_WEAK_ORDERING
);
2607 rx_agg_buf
->page
= NULL
;
2608 __clear_bit(j
, rxr
->rx_agg_bmap
);
2613 __free_page(rxr
->rx_page
);
2614 rxr
->rx_page
= NULL
;
2616 map
= rxr
->rx_tpa_idx_map
;
2618 memset(map
->agg_idx_bmap
, 0, sizeof(map
->agg_idx_bmap
));
2622 static void bnxt_free_skbs(struct bnxt
*bp
)
2624 bnxt_free_tx_skbs(bp
);
2625 bnxt_free_rx_skbs(bp
);
2628 static void bnxt_free_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2630 struct pci_dev
*pdev
= bp
->pdev
;
2633 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2634 if (!rmem
->pg_arr
[i
])
2637 dma_free_coherent(&pdev
->dev
, rmem
->page_size
,
2638 rmem
->pg_arr
[i
], rmem
->dma_arr
[i
]);
2640 rmem
->pg_arr
[i
] = NULL
;
2643 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2645 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2646 pg_tbl_size
= rmem
->page_size
;
2647 dma_free_coherent(&pdev
->dev
, pg_tbl_size
,
2648 rmem
->pg_tbl
, rmem
->pg_tbl_map
);
2649 rmem
->pg_tbl
= NULL
;
2651 if (rmem
->vmem_size
&& *rmem
->vmem
) {
2657 static int bnxt_alloc_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2659 struct pci_dev
*pdev
= bp
->pdev
;
2663 if (rmem
->flags
& (BNXT_RMEM_VALID_PTE_FLAG
| BNXT_RMEM_RING_PTE_FLAG
))
2664 valid_bit
= PTU_PTE_VALID
;
2665 if ((rmem
->nr_pages
> 1 || rmem
->depth
> 0) && !rmem
->pg_tbl
) {
2666 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2668 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2669 pg_tbl_size
= rmem
->page_size
;
2670 rmem
->pg_tbl
= dma_alloc_coherent(&pdev
->dev
, pg_tbl_size
,
2677 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2678 u64 extra_bits
= valid_bit
;
2680 rmem
->pg_arr
[i
] = dma_alloc_coherent(&pdev
->dev
,
2684 if (!rmem
->pg_arr
[i
])
2687 if (rmem
->nr_pages
> 1 || rmem
->depth
> 0) {
2688 if (i
== rmem
->nr_pages
- 2 &&
2689 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2690 extra_bits
|= PTU_PTE_NEXT_TO_LAST
;
2691 else if (i
== rmem
->nr_pages
- 1 &&
2692 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2693 extra_bits
|= PTU_PTE_LAST
;
2695 cpu_to_le64(rmem
->dma_arr
[i
] | extra_bits
);
2699 if (rmem
->vmem_size
) {
2700 *rmem
->vmem
= vzalloc(rmem
->vmem_size
);
2707 static void bnxt_free_tpa_info(struct bnxt
*bp
)
2711 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2712 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2714 kfree(rxr
->rx_tpa_idx_map
);
2715 rxr
->rx_tpa_idx_map
= NULL
;
2717 kfree(rxr
->rx_tpa
[0].agg_arr
);
2718 rxr
->rx_tpa
[0].agg_arr
= NULL
;
2725 static int bnxt_alloc_tpa_info(struct bnxt
*bp
)
2727 int i
, j
, total_aggs
= 0;
2729 bp
->max_tpa
= MAX_TPA
;
2730 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
2731 if (!bp
->max_tpa_v2
)
2733 bp
->max_tpa
= max_t(u16
, bp
->max_tpa_v2
, MAX_TPA_P5
);
2734 total_aggs
= bp
->max_tpa
* MAX_SKB_FRAGS
;
2737 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2738 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2739 struct rx_agg_cmp
*agg
;
2741 rxr
->rx_tpa
= kcalloc(bp
->max_tpa
, sizeof(struct bnxt_tpa_info
),
2746 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
2748 agg
= kcalloc(total_aggs
, sizeof(*agg
), GFP_KERNEL
);
2749 rxr
->rx_tpa
[0].agg_arr
= agg
;
2752 for (j
= 1; j
< bp
->max_tpa
; j
++)
2753 rxr
->rx_tpa
[j
].agg_arr
= agg
+ j
* MAX_SKB_FRAGS
;
2754 rxr
->rx_tpa_idx_map
= kzalloc(sizeof(*rxr
->rx_tpa_idx_map
),
2756 if (!rxr
->rx_tpa_idx_map
)
2762 static void bnxt_free_rx_rings(struct bnxt
*bp
)
2769 bnxt_free_tpa_info(bp
);
2770 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2771 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2772 struct bnxt_ring_struct
*ring
;
2775 bpf_prog_put(rxr
->xdp_prog
);
2777 if (xdp_rxq_info_is_reg(&rxr
->xdp_rxq
))
2778 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
2780 page_pool_destroy(rxr
->page_pool
);
2781 rxr
->page_pool
= NULL
;
2783 kfree(rxr
->rx_agg_bmap
);
2784 rxr
->rx_agg_bmap
= NULL
;
2786 ring
= &rxr
->rx_ring_struct
;
2787 bnxt_free_ring(bp
, &ring
->ring_mem
);
2789 ring
= &rxr
->rx_agg_ring_struct
;
2790 bnxt_free_ring(bp
, &ring
->ring_mem
);
2794 static int bnxt_alloc_rx_page_pool(struct bnxt
*bp
,
2795 struct bnxt_rx_ring_info
*rxr
)
2797 struct page_pool_params pp
= { 0 };
2799 pp
.pool_size
= bp
->rx_ring_size
;
2800 pp
.nid
= dev_to_node(&bp
->pdev
->dev
);
2801 pp
.dev
= &bp
->pdev
->dev
;
2802 pp
.dma_dir
= DMA_BIDIRECTIONAL
;
2804 rxr
->page_pool
= page_pool_create(&pp
);
2805 if (IS_ERR(rxr
->page_pool
)) {
2806 int err
= PTR_ERR(rxr
->page_pool
);
2808 rxr
->page_pool
= NULL
;
2814 static int bnxt_alloc_rx_rings(struct bnxt
*bp
)
2816 int i
, rc
= 0, agg_rings
= 0;
2821 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
2824 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2825 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2826 struct bnxt_ring_struct
*ring
;
2828 ring
= &rxr
->rx_ring_struct
;
2830 rc
= bnxt_alloc_rx_page_pool(bp
, rxr
);
2834 rc
= xdp_rxq_info_reg(&rxr
->xdp_rxq
, bp
->dev
, i
);
2838 rc
= xdp_rxq_info_reg_mem_model(&rxr
->xdp_rxq
,
2842 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
2846 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2854 ring
= &rxr
->rx_agg_ring_struct
;
2855 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2860 rxr
->rx_agg_bmap_size
= bp
->rx_agg_ring_mask
+ 1;
2861 mem_size
= rxr
->rx_agg_bmap_size
/ 8;
2862 rxr
->rx_agg_bmap
= kzalloc(mem_size
, GFP_KERNEL
);
2863 if (!rxr
->rx_agg_bmap
)
2867 if (bp
->flags
& BNXT_FLAG_TPA
)
2868 rc
= bnxt_alloc_tpa_info(bp
);
2872 static void bnxt_free_tx_rings(struct bnxt
*bp
)
2875 struct pci_dev
*pdev
= bp
->pdev
;
2880 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2881 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2882 struct bnxt_ring_struct
*ring
;
2885 dma_free_coherent(&pdev
->dev
, bp
->tx_push_size
,
2886 txr
->tx_push
, txr
->tx_push_mapping
);
2887 txr
->tx_push
= NULL
;
2890 ring
= &txr
->tx_ring_struct
;
2892 bnxt_free_ring(bp
, &ring
->ring_mem
);
2896 static int bnxt_alloc_tx_rings(struct bnxt
*bp
)
2899 struct pci_dev
*pdev
= bp
->pdev
;
2901 bp
->tx_push_size
= 0;
2902 if (bp
->tx_push_thresh
) {
2905 push_size
= L1_CACHE_ALIGN(sizeof(struct tx_push_bd
) +
2906 bp
->tx_push_thresh
);
2908 if (push_size
> 256) {
2910 bp
->tx_push_thresh
= 0;
2913 bp
->tx_push_size
= push_size
;
2916 for (i
= 0, j
= 0; i
< bp
->tx_nr_rings
; i
++) {
2917 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2918 struct bnxt_ring_struct
*ring
;
2921 ring
= &txr
->tx_ring_struct
;
2923 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2927 ring
->grp_idx
= txr
->bnapi
->index
;
2928 if (bp
->tx_push_size
) {
2931 /* One pre-allocated DMA buffer to backup
2934 txr
->tx_push
= dma_alloc_coherent(&pdev
->dev
,
2936 &txr
->tx_push_mapping
,
2942 mapping
= txr
->tx_push_mapping
+
2943 sizeof(struct tx_push_bd
);
2944 txr
->data_mapping
= cpu_to_le64(mapping
);
2946 qidx
= bp
->tc_to_qidx
[j
];
2947 ring
->queue_id
= bp
->q_info
[qidx
].queue_id
;
2948 if (i
< bp
->tx_nr_rings_xdp
)
2950 if (i
% bp
->tx_nr_rings_per_tc
== (bp
->tx_nr_rings_per_tc
- 1))
2956 static void bnxt_free_cp_rings(struct bnxt
*bp
)
2963 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2964 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2965 struct bnxt_cp_ring_info
*cpr
;
2966 struct bnxt_ring_struct
*ring
;
2972 cpr
= &bnapi
->cp_ring
;
2973 ring
= &cpr
->cp_ring_struct
;
2975 bnxt_free_ring(bp
, &ring
->ring_mem
);
2977 for (j
= 0; j
< 2; j
++) {
2978 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
2981 ring
= &cpr2
->cp_ring_struct
;
2982 bnxt_free_ring(bp
, &ring
->ring_mem
);
2984 cpr
->cp_ring_arr
[j
] = NULL
;
2990 static struct bnxt_cp_ring_info
*bnxt_alloc_cp_sub_ring(struct bnxt
*bp
)
2992 struct bnxt_ring_mem_info
*rmem
;
2993 struct bnxt_ring_struct
*ring
;
2994 struct bnxt_cp_ring_info
*cpr
;
2997 cpr
= kzalloc(sizeof(*cpr
), GFP_KERNEL
);
3001 ring
= &cpr
->cp_ring_struct
;
3002 rmem
= &ring
->ring_mem
;
3003 rmem
->nr_pages
= bp
->cp_nr_pages
;
3004 rmem
->page_size
= HW_CMPD_RING_SIZE
;
3005 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
3006 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
3007 rmem
->flags
= BNXT_RMEM_RING_PTE_FLAG
;
3008 rc
= bnxt_alloc_ring(bp
, rmem
);
3010 bnxt_free_ring(bp
, rmem
);
3017 static int bnxt_alloc_cp_rings(struct bnxt
*bp
)
3019 bool sh
= !!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
);
3020 int i
, rc
, ulp_base_vec
, ulp_msix
;
3022 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
3023 ulp_base_vec
= bnxt_get_ulp_msix_base(bp
);
3024 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3025 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3026 struct bnxt_cp_ring_info
*cpr
;
3027 struct bnxt_ring_struct
*ring
;
3032 cpr
= &bnapi
->cp_ring
;
3034 ring
= &cpr
->cp_ring_struct
;
3036 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
3040 if (ulp_msix
&& i
>= ulp_base_vec
)
3041 ring
->map_idx
= i
+ ulp_msix
;
3045 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
3048 if (i
< bp
->rx_nr_rings
) {
3049 struct bnxt_cp_ring_info
*cpr2
=
3050 bnxt_alloc_cp_sub_ring(bp
);
3052 cpr
->cp_ring_arr
[BNXT_RX_HDL
] = cpr2
;
3055 cpr2
->bnapi
= bnapi
;
3057 if ((sh
&& i
< bp
->tx_nr_rings
) ||
3058 (!sh
&& i
>= bp
->rx_nr_rings
)) {
3059 struct bnxt_cp_ring_info
*cpr2
=
3060 bnxt_alloc_cp_sub_ring(bp
);
3062 cpr
->cp_ring_arr
[BNXT_TX_HDL
] = cpr2
;
3065 cpr2
->bnapi
= bnapi
;
3071 static void bnxt_init_ring_struct(struct bnxt
*bp
)
3075 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3076 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3077 struct bnxt_ring_mem_info
*rmem
;
3078 struct bnxt_cp_ring_info
*cpr
;
3079 struct bnxt_rx_ring_info
*rxr
;
3080 struct bnxt_tx_ring_info
*txr
;
3081 struct bnxt_ring_struct
*ring
;
3086 cpr
= &bnapi
->cp_ring
;
3087 ring
= &cpr
->cp_ring_struct
;
3088 rmem
= &ring
->ring_mem
;
3089 rmem
->nr_pages
= bp
->cp_nr_pages
;
3090 rmem
->page_size
= HW_CMPD_RING_SIZE
;
3091 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
3092 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
3093 rmem
->vmem_size
= 0;
3095 rxr
= bnapi
->rx_ring
;
3099 ring
= &rxr
->rx_ring_struct
;
3100 rmem
= &ring
->ring_mem
;
3101 rmem
->nr_pages
= bp
->rx_nr_pages
;
3102 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3103 rmem
->pg_arr
= (void **)rxr
->rx_desc_ring
;
3104 rmem
->dma_arr
= rxr
->rx_desc_mapping
;
3105 rmem
->vmem_size
= SW_RXBD_RING_SIZE
* bp
->rx_nr_pages
;
3106 rmem
->vmem
= (void **)&rxr
->rx_buf_ring
;
3108 ring
= &rxr
->rx_agg_ring_struct
;
3109 rmem
= &ring
->ring_mem
;
3110 rmem
->nr_pages
= bp
->rx_agg_nr_pages
;
3111 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3112 rmem
->pg_arr
= (void **)rxr
->rx_agg_desc_ring
;
3113 rmem
->dma_arr
= rxr
->rx_agg_desc_mapping
;
3114 rmem
->vmem_size
= SW_RXBD_AGG_RING_SIZE
* bp
->rx_agg_nr_pages
;
3115 rmem
->vmem
= (void **)&rxr
->rx_agg_ring
;
3118 txr
= bnapi
->tx_ring
;
3122 ring
= &txr
->tx_ring_struct
;
3123 rmem
= &ring
->ring_mem
;
3124 rmem
->nr_pages
= bp
->tx_nr_pages
;
3125 rmem
->page_size
= HW_RXBD_RING_SIZE
;
3126 rmem
->pg_arr
= (void **)txr
->tx_desc_ring
;
3127 rmem
->dma_arr
= txr
->tx_desc_mapping
;
3128 rmem
->vmem_size
= SW_TXBD_RING_SIZE
* bp
->tx_nr_pages
;
3129 rmem
->vmem
= (void **)&txr
->tx_buf_ring
;
3133 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct
*ring
, u32 type
)
3137 struct rx_bd
**rx_buf_ring
;
3139 rx_buf_ring
= (struct rx_bd
**)ring
->ring_mem
.pg_arr
;
3140 for (i
= 0, prod
= 0; i
< ring
->ring_mem
.nr_pages
; i
++) {
3144 rxbd
= rx_buf_ring
[i
];
3148 for (j
= 0; j
< RX_DESC_CNT
; j
++, rxbd
++, prod
++) {
3149 rxbd
->rx_bd_len_flags_type
= cpu_to_le32(type
);
3150 rxbd
->rx_bd_opaque
= prod
;
3155 static int bnxt_init_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
3157 struct net_device
*dev
= bp
->dev
;
3158 struct bnxt_rx_ring_info
*rxr
;
3159 struct bnxt_ring_struct
*ring
;
3163 type
= (bp
->rx_buf_use_size
<< RX_BD_LEN_SHIFT
) |
3164 RX_BD_TYPE_RX_PACKET_BD
| RX_BD_FLAGS_EOP
;
3166 if (NET_IP_ALIGN
== 2)
3167 type
|= RX_BD_FLAGS_SOP
;
3169 rxr
= &bp
->rx_ring
[ring_nr
];
3170 ring
= &rxr
->rx_ring_struct
;
3171 bnxt_init_rxbd_pages(ring
, type
);
3173 if (BNXT_RX_PAGE_MODE(bp
) && bp
->xdp_prog
) {
3174 rxr
->xdp_prog
= bpf_prog_add(bp
->xdp_prog
, 1);
3175 if (IS_ERR(rxr
->xdp_prog
)) {
3176 int rc
= PTR_ERR(rxr
->xdp_prog
);
3178 rxr
->xdp_prog
= NULL
;
3182 prod
= rxr
->rx_prod
;
3183 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
3184 if (bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
3185 netdev_warn(dev
, "init'ed rx ring %d with %d/%d skbs only\n",
3186 ring_nr
, i
, bp
->rx_ring_size
);
3189 prod
= NEXT_RX(prod
);
3191 rxr
->rx_prod
= prod
;
3192 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3194 ring
= &rxr
->rx_agg_ring_struct
;
3195 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3197 if (!(bp
->flags
& BNXT_FLAG_AGG_RINGS
))
3200 type
= ((u32
)BNXT_RX_PAGE_SIZE
<< RX_BD_LEN_SHIFT
) |
3201 RX_BD_TYPE_RX_AGG_BD
| RX_BD_FLAGS_SOP
;
3203 bnxt_init_rxbd_pages(ring
, type
);
3205 prod
= rxr
->rx_agg_prod
;
3206 for (i
= 0; i
< bp
->rx_agg_ring_size
; i
++) {
3207 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
3208 netdev_warn(dev
, "init'ed rx ring %d with %d/%d pages only\n",
3209 ring_nr
, i
, bp
->rx_ring_size
);
3212 prod
= NEXT_RX_AGG(prod
);
3214 rxr
->rx_agg_prod
= prod
;
3216 if (bp
->flags
& BNXT_FLAG_TPA
) {
3221 for (i
= 0; i
< bp
->max_tpa
; i
++) {
3222 data
= __bnxt_alloc_rx_data(bp
, &mapping
,
3227 rxr
->rx_tpa
[i
].data
= data
;
3228 rxr
->rx_tpa
[i
].data_ptr
= data
+ bp
->rx_offset
;
3229 rxr
->rx_tpa
[i
].mapping
= mapping
;
3232 netdev_err(bp
->dev
, "No resource allocated for LRO/GRO\n");
3240 static void bnxt_init_cp_rings(struct bnxt
*bp
)
3244 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3245 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
3246 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3248 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3249 cpr
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
3250 cpr
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
3251 for (j
= 0; j
< 2; j
++) {
3252 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
3257 ring
= &cpr2
->cp_ring_struct
;
3258 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3259 cpr2
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
3260 cpr2
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
3265 static int bnxt_init_rx_rings(struct bnxt
*bp
)
3269 if (BNXT_RX_PAGE_MODE(bp
)) {
3270 bp
->rx_offset
= NET_IP_ALIGN
+ XDP_PACKET_HEADROOM
;
3271 bp
->rx_dma_offset
= XDP_PACKET_HEADROOM
;
3273 bp
->rx_offset
= BNXT_RX_OFFSET
;
3274 bp
->rx_dma_offset
= BNXT_RX_DMA_OFFSET
;
3277 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3278 rc
= bnxt_init_one_rx_ring(bp
, i
);
3286 static int bnxt_init_tx_rings(struct bnxt
*bp
)
3290 bp
->tx_wake_thresh
= max_t(int, bp
->tx_ring_size
/ 2,
3293 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
3294 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3295 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
3297 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
3303 static void bnxt_free_ring_grps(struct bnxt
*bp
)
3305 kfree(bp
->grp_info
);
3306 bp
->grp_info
= NULL
;
3309 static int bnxt_init_ring_grps(struct bnxt
*bp
, bool irq_re_init
)
3314 bp
->grp_info
= kcalloc(bp
->cp_nr_rings
,
3315 sizeof(struct bnxt_ring_grp_info
),
3320 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3322 bp
->grp_info
[i
].fw_stats_ctx
= INVALID_HW_RING_ID
;
3323 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
3324 bp
->grp_info
[i
].rx_fw_ring_id
= INVALID_HW_RING_ID
;
3325 bp
->grp_info
[i
].agg_fw_ring_id
= INVALID_HW_RING_ID
;
3326 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
3331 static void bnxt_free_vnics(struct bnxt
*bp
)
3333 kfree(bp
->vnic_info
);
3334 bp
->vnic_info
= NULL
;
3338 static int bnxt_alloc_vnics(struct bnxt
*bp
)
3342 #ifdef CONFIG_RFS_ACCEL
3343 if ((bp
->flags
& (BNXT_FLAG_RFS
| BNXT_FLAG_CHIP_P5
)) == BNXT_FLAG_RFS
)
3344 num_vnics
+= bp
->rx_nr_rings
;
3347 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
3350 bp
->vnic_info
= kcalloc(num_vnics
, sizeof(struct bnxt_vnic_info
),
3355 bp
->nr_vnics
= num_vnics
;
3359 static void bnxt_init_vnics(struct bnxt
*bp
)
3363 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3364 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
3367 vnic
->fw_vnic_id
= INVALID_HW_RING_ID
;
3368 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++)
3369 vnic
->fw_rss_cos_lb_ctx
[j
] = INVALID_HW_RING_ID
;
3371 vnic
->fw_l2_ctx_id
= INVALID_HW_RING_ID
;
3373 if (bp
->vnic_info
[i
].rss_hash_key
) {
3375 prandom_bytes(vnic
->rss_hash_key
,
3378 memcpy(vnic
->rss_hash_key
,
3379 bp
->vnic_info
[0].rss_hash_key
,
3385 static int bnxt_calc_nr_ring_pages(u32 ring_size
, int desc_per_pg
)
3389 pages
= ring_size
/ desc_per_pg
;
3396 while (pages
& (pages
- 1))
3402 void bnxt_set_tpa_flags(struct bnxt
*bp
)
3404 bp
->flags
&= ~BNXT_FLAG_TPA
;
3405 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
3407 if (bp
->dev
->features
& NETIF_F_LRO
)
3408 bp
->flags
|= BNXT_FLAG_LRO
;
3409 else if (bp
->dev
->features
& NETIF_F_GRO_HW
)
3410 bp
->flags
|= BNXT_FLAG_GRO
;
3413 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
3416 void bnxt_set_ring_params(struct bnxt
*bp
)
3418 u32 ring_size
, rx_size
, rx_space
;
3419 u32 agg_factor
= 0, agg_ring_size
= 0;
3421 /* 8 for CRC and VLAN */
3422 rx_size
= SKB_DATA_ALIGN(bp
->dev
->mtu
+ ETH_HLEN
+ NET_IP_ALIGN
+ 8);
3424 rx_space
= rx_size
+ NET_SKB_PAD
+
3425 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3427 bp
->rx_copy_thresh
= BNXT_RX_COPY_THRESH
;
3428 ring_size
= bp
->rx_ring_size
;
3429 bp
->rx_agg_ring_size
= 0;
3430 bp
->rx_agg_nr_pages
= 0;
3432 if (bp
->flags
& BNXT_FLAG_TPA
)
3433 agg_factor
= min_t(u32
, 4, 65536 / BNXT_RX_PAGE_SIZE
);
3435 bp
->flags
&= ~BNXT_FLAG_JUMBO
;
3436 if (rx_space
> PAGE_SIZE
&& !(bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)) {
3439 bp
->flags
|= BNXT_FLAG_JUMBO
;
3440 jumbo_factor
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
3441 if (jumbo_factor
> agg_factor
)
3442 agg_factor
= jumbo_factor
;
3444 agg_ring_size
= ring_size
* agg_factor
;
3446 if (agg_ring_size
) {
3447 bp
->rx_agg_nr_pages
= bnxt_calc_nr_ring_pages(agg_ring_size
,
3449 if (bp
->rx_agg_nr_pages
> MAX_RX_AGG_PAGES
) {
3450 u32 tmp
= agg_ring_size
;
3452 bp
->rx_agg_nr_pages
= MAX_RX_AGG_PAGES
;
3453 agg_ring_size
= MAX_RX_AGG_PAGES
* RX_DESC_CNT
- 1;
3454 netdev_warn(bp
->dev
, "rx agg ring size %d reduced to %d.\n",
3455 tmp
, agg_ring_size
);
3457 bp
->rx_agg_ring_size
= agg_ring_size
;
3458 bp
->rx_agg_ring_mask
= (bp
->rx_agg_nr_pages
* RX_DESC_CNT
) - 1;
3459 rx_size
= SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH
+ NET_IP_ALIGN
);
3460 rx_space
= rx_size
+ NET_SKB_PAD
+
3461 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3464 bp
->rx_buf_use_size
= rx_size
;
3465 bp
->rx_buf_size
= rx_space
;
3467 bp
->rx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, RX_DESC_CNT
);
3468 bp
->rx_ring_mask
= (bp
->rx_nr_pages
* RX_DESC_CNT
) - 1;
3470 ring_size
= bp
->tx_ring_size
;
3471 bp
->tx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, TX_DESC_CNT
);
3472 bp
->tx_ring_mask
= (bp
->tx_nr_pages
* TX_DESC_CNT
) - 1;
3474 ring_size
= bp
->rx_ring_size
* (2 + agg_factor
) + bp
->tx_ring_size
;
3475 bp
->cp_ring_size
= ring_size
;
3477 bp
->cp_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, CP_DESC_CNT
);
3478 if (bp
->cp_nr_pages
> MAX_CP_PAGES
) {
3479 bp
->cp_nr_pages
= MAX_CP_PAGES
;
3480 bp
->cp_ring_size
= MAX_CP_PAGES
* CP_DESC_CNT
- 1;
3481 netdev_warn(bp
->dev
, "completion ring size %d reduced to %d.\n",
3482 ring_size
, bp
->cp_ring_size
);
3484 bp
->cp_bit
= bp
->cp_nr_pages
* CP_DESC_CNT
;
3485 bp
->cp_ring_mask
= bp
->cp_bit
- 1;
3488 /* Changing allocation mode of RX rings.
3489 * TODO: Update when extending xdp_rxq_info to support allocation modes.
3491 int bnxt_set_rx_skb_mode(struct bnxt
*bp
, bool page_mode
)
3494 if (bp
->dev
->mtu
> BNXT_MAX_PAGE_MODE_MTU
)
3497 min_t(u16
, bp
->max_mtu
, BNXT_MAX_PAGE_MODE_MTU
);
3498 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
3499 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
| BNXT_FLAG_RX_PAGE_MODE
;
3500 bp
->rx_dir
= DMA_BIDIRECTIONAL
;
3501 bp
->rx_skb_func
= bnxt_rx_page_skb
;
3502 /* Disable LRO or GRO_HW */
3503 netdev_update_features(bp
->dev
);
3505 bp
->dev
->max_mtu
= bp
->max_mtu
;
3506 bp
->flags
&= ~BNXT_FLAG_RX_PAGE_MODE
;
3507 bp
->rx_dir
= DMA_FROM_DEVICE
;
3508 bp
->rx_skb_func
= bnxt_rx_skb
;
3513 static void bnxt_free_vnic_attributes(struct bnxt
*bp
)
3516 struct bnxt_vnic_info
*vnic
;
3517 struct pci_dev
*pdev
= bp
->pdev
;
3522 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3523 vnic
= &bp
->vnic_info
[i
];
3525 kfree(vnic
->fw_grp_ids
);
3526 vnic
->fw_grp_ids
= NULL
;
3528 kfree(vnic
->uc_list
);
3529 vnic
->uc_list
= NULL
;
3531 if (vnic
->mc_list
) {
3532 dma_free_coherent(&pdev
->dev
, vnic
->mc_list_size
,
3533 vnic
->mc_list
, vnic
->mc_list_mapping
);
3534 vnic
->mc_list
= NULL
;
3537 if (vnic
->rss_table
) {
3538 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
3540 vnic
->rss_table_dma_addr
);
3541 vnic
->rss_table
= NULL
;
3544 vnic
->rss_hash_key
= NULL
;
3549 static int bnxt_alloc_vnic_attributes(struct bnxt
*bp
)
3551 int i
, rc
= 0, size
;
3552 struct bnxt_vnic_info
*vnic
;
3553 struct pci_dev
*pdev
= bp
->pdev
;
3556 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3557 vnic
= &bp
->vnic_info
[i
];
3559 if (vnic
->flags
& BNXT_VNIC_UCAST_FLAG
) {
3560 int mem_size
= (BNXT_MAX_UC_ADDRS
- 1) * ETH_ALEN
;
3563 vnic
->uc_list
= kmalloc(mem_size
, GFP_KERNEL
);
3564 if (!vnic
->uc_list
) {
3571 if (vnic
->flags
& BNXT_VNIC_MCAST_FLAG
) {
3572 vnic
->mc_list_size
= BNXT_MAX_MC_ADDRS
* ETH_ALEN
;
3574 dma_alloc_coherent(&pdev
->dev
,
3576 &vnic
->mc_list_mapping
,
3578 if (!vnic
->mc_list
) {
3584 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
3585 goto vnic_skip_grps
;
3587 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3588 max_rings
= bp
->rx_nr_rings
;
3592 vnic
->fw_grp_ids
= kcalloc(max_rings
, sizeof(u16
), GFP_KERNEL
);
3593 if (!vnic
->fw_grp_ids
) {
3598 if ((bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
3599 !(vnic
->flags
& BNXT_VNIC_RSS_FLAG
))
3602 /* Allocate rss table and hash key */
3603 vnic
->rss_table
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3604 &vnic
->rss_table_dma_addr
,
3606 if (!vnic
->rss_table
) {
3611 size
= L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE
* sizeof(u16
));
3613 vnic
->rss_hash_key
= ((void *)vnic
->rss_table
) + size
;
3614 vnic
->rss_hash_key_dma_addr
= vnic
->rss_table_dma_addr
+ size
;
3622 static void bnxt_free_hwrm_resources(struct bnxt
*bp
)
3624 struct pci_dev
*pdev
= bp
->pdev
;
3626 if (bp
->hwrm_cmd_resp_addr
) {
3627 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
, bp
->hwrm_cmd_resp_addr
,
3628 bp
->hwrm_cmd_resp_dma_addr
);
3629 bp
->hwrm_cmd_resp_addr
= NULL
;
3632 if (bp
->hwrm_cmd_kong_resp_addr
) {
3633 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
3634 bp
->hwrm_cmd_kong_resp_addr
,
3635 bp
->hwrm_cmd_kong_resp_dma_addr
);
3636 bp
->hwrm_cmd_kong_resp_addr
= NULL
;
3640 static int bnxt_alloc_kong_hwrm_resources(struct bnxt
*bp
)
3642 struct pci_dev
*pdev
= bp
->pdev
;
3644 if (bp
->hwrm_cmd_kong_resp_addr
)
3647 bp
->hwrm_cmd_kong_resp_addr
=
3648 dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3649 &bp
->hwrm_cmd_kong_resp_dma_addr
,
3651 if (!bp
->hwrm_cmd_kong_resp_addr
)
3657 static int bnxt_alloc_hwrm_resources(struct bnxt
*bp
)
3659 struct pci_dev
*pdev
= bp
->pdev
;
3661 bp
->hwrm_cmd_resp_addr
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3662 &bp
->hwrm_cmd_resp_dma_addr
,
3664 if (!bp
->hwrm_cmd_resp_addr
)
3670 static void bnxt_free_hwrm_short_cmd_req(struct bnxt
*bp
)
3672 if (bp
->hwrm_short_cmd_req_addr
) {
3673 struct pci_dev
*pdev
= bp
->pdev
;
3675 dma_free_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3676 bp
->hwrm_short_cmd_req_addr
,
3677 bp
->hwrm_short_cmd_req_dma_addr
);
3678 bp
->hwrm_short_cmd_req_addr
= NULL
;
3682 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt
*bp
)
3684 struct pci_dev
*pdev
= bp
->pdev
;
3686 if (bp
->hwrm_short_cmd_req_addr
)
3689 bp
->hwrm_short_cmd_req_addr
=
3690 dma_alloc_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3691 &bp
->hwrm_short_cmd_req_dma_addr
,
3693 if (!bp
->hwrm_short_cmd_req_addr
)
3699 static void bnxt_free_port_stats(struct bnxt
*bp
)
3701 struct pci_dev
*pdev
= bp
->pdev
;
3703 bp
->flags
&= ~BNXT_FLAG_PORT_STATS
;
3704 bp
->flags
&= ~BNXT_FLAG_PORT_STATS_EXT
;
3706 if (bp
->hw_rx_port_stats
) {
3707 dma_free_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3708 bp
->hw_rx_port_stats
,
3709 bp
->hw_rx_port_stats_map
);
3710 bp
->hw_rx_port_stats
= NULL
;
3713 if (bp
->hw_tx_port_stats_ext
) {
3714 dma_free_coherent(&pdev
->dev
, sizeof(struct tx_port_stats_ext
),
3715 bp
->hw_tx_port_stats_ext
,
3716 bp
->hw_tx_port_stats_ext_map
);
3717 bp
->hw_tx_port_stats_ext
= NULL
;
3720 if (bp
->hw_rx_port_stats_ext
) {
3721 dma_free_coherent(&pdev
->dev
, sizeof(struct rx_port_stats_ext
),
3722 bp
->hw_rx_port_stats_ext
,
3723 bp
->hw_rx_port_stats_ext_map
);
3724 bp
->hw_rx_port_stats_ext
= NULL
;
3727 if (bp
->hw_pcie_stats
) {
3728 dma_free_coherent(&pdev
->dev
, sizeof(struct pcie_ctx_hw_stats
),
3729 bp
->hw_pcie_stats
, bp
->hw_pcie_stats_map
);
3730 bp
->hw_pcie_stats
= NULL
;
3734 static void bnxt_free_ring_stats(struct bnxt
*bp
)
3736 struct pci_dev
*pdev
= bp
->pdev
;
3742 size
= bp
->hw_ring_stats_size
;
3744 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3745 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3746 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3748 if (cpr
->hw_stats
) {
3749 dma_free_coherent(&pdev
->dev
, size
, cpr
->hw_stats
,
3751 cpr
->hw_stats
= NULL
;
3756 static int bnxt_alloc_stats(struct bnxt
*bp
)
3759 struct pci_dev
*pdev
= bp
->pdev
;
3761 size
= bp
->hw_ring_stats_size
;
3763 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3764 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3765 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3767 cpr
->hw_stats
= dma_alloc_coherent(&pdev
->dev
, size
,
3773 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
3776 if (BNXT_VF(bp
) || bp
->chip_num
== CHIP_NUM_58700
)
3779 if (bp
->hw_rx_port_stats
)
3780 goto alloc_ext_stats
;
3782 bp
->hw_port_stats_size
= sizeof(struct rx_port_stats
) +
3783 sizeof(struct tx_port_stats
) + 1024;
3785 bp
->hw_rx_port_stats
=
3786 dma_alloc_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3787 &bp
->hw_rx_port_stats_map
,
3789 if (!bp
->hw_rx_port_stats
)
3792 bp
->hw_tx_port_stats
= (void *)(bp
->hw_rx_port_stats
+ 1) + 512;
3793 bp
->hw_tx_port_stats_map
= bp
->hw_rx_port_stats_map
+
3794 sizeof(struct rx_port_stats
) + 512;
3795 bp
->flags
|= BNXT_FLAG_PORT_STATS
;
3798 /* Display extended statistics only if FW supports it */
3799 if (bp
->hwrm_spec_code
< 0x10804 || bp
->hwrm_spec_code
== 0x10900)
3800 if (!(bp
->fw_cap
& BNXT_FW_CAP_EXT_STATS_SUPPORTED
))
3803 if (bp
->hw_rx_port_stats_ext
)
3804 goto alloc_tx_ext_stats
;
3806 bp
->hw_rx_port_stats_ext
=
3807 dma_alloc_coherent(&pdev
->dev
, sizeof(struct rx_port_stats_ext
),
3808 &bp
->hw_rx_port_stats_ext_map
, GFP_KERNEL
);
3809 if (!bp
->hw_rx_port_stats_ext
)
3813 if (bp
->hw_tx_port_stats_ext
)
3814 goto alloc_pcie_stats
;
3816 if (bp
->hwrm_spec_code
>= 0x10902 ||
3817 (bp
->fw_cap
& BNXT_FW_CAP_EXT_STATS_SUPPORTED
)) {
3818 bp
->hw_tx_port_stats_ext
=
3819 dma_alloc_coherent(&pdev
->dev
,
3820 sizeof(struct tx_port_stats_ext
),
3821 &bp
->hw_tx_port_stats_ext_map
,
3824 bp
->flags
|= BNXT_FLAG_PORT_STATS_EXT
;
3827 if (bp
->hw_pcie_stats
||
3828 !(bp
->fw_cap
& BNXT_FW_CAP_PCIE_STATS_SUPPORTED
))
3832 dma_alloc_coherent(&pdev
->dev
, sizeof(struct pcie_ctx_hw_stats
),
3833 &bp
->hw_pcie_stats_map
, GFP_KERNEL
);
3834 if (!bp
->hw_pcie_stats
)
3837 bp
->flags
|= BNXT_FLAG_PCIE_STATS
;
3841 static void bnxt_clear_ring_indices(struct bnxt
*bp
)
3848 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3849 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3850 struct bnxt_cp_ring_info
*cpr
;
3851 struct bnxt_rx_ring_info
*rxr
;
3852 struct bnxt_tx_ring_info
*txr
;
3857 cpr
= &bnapi
->cp_ring
;
3858 cpr
->cp_raw_cons
= 0;
3860 txr
= bnapi
->tx_ring
;
3866 rxr
= bnapi
->rx_ring
;
3869 rxr
->rx_agg_prod
= 0;
3870 rxr
->rx_sw_agg_prod
= 0;
3871 rxr
->rx_next_cons
= 0;
3876 static void bnxt_free_ntp_fltrs(struct bnxt
*bp
, bool irq_reinit
)
3878 #ifdef CONFIG_RFS_ACCEL
3881 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3882 * safe to delete the hash table.
3884 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
3885 struct hlist_head
*head
;
3886 struct hlist_node
*tmp
;
3887 struct bnxt_ntuple_filter
*fltr
;
3889 head
= &bp
->ntp_fltr_hash_tbl
[i
];
3890 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
3891 hlist_del(&fltr
->hash
);
3896 kfree(bp
->ntp_fltr_bmap
);
3897 bp
->ntp_fltr_bmap
= NULL
;
3899 bp
->ntp_fltr_count
= 0;
3903 static int bnxt_alloc_ntp_fltrs(struct bnxt
*bp
)
3905 #ifdef CONFIG_RFS_ACCEL
3908 if (!(bp
->flags
& BNXT_FLAG_RFS
))
3911 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++)
3912 INIT_HLIST_HEAD(&bp
->ntp_fltr_hash_tbl
[i
]);
3914 bp
->ntp_fltr_count
= 0;
3915 bp
->ntp_fltr_bmap
= kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR
),
3919 if (!bp
->ntp_fltr_bmap
)
3928 static void bnxt_free_mem(struct bnxt
*bp
, bool irq_re_init
)
3930 bnxt_free_vnic_attributes(bp
);
3931 bnxt_free_tx_rings(bp
);
3932 bnxt_free_rx_rings(bp
);
3933 bnxt_free_cp_rings(bp
);
3934 bnxt_free_ntp_fltrs(bp
, irq_re_init
);
3936 bnxt_free_ring_stats(bp
);
3937 bnxt_free_ring_grps(bp
);
3938 bnxt_free_vnics(bp
);
3939 kfree(bp
->tx_ring_map
);
3940 bp
->tx_ring_map
= NULL
;
3948 bnxt_clear_ring_indices(bp
);
3952 static int bnxt_alloc_mem(struct bnxt
*bp
, bool irq_re_init
)
3954 int i
, j
, rc
, size
, arr_size
;
3958 /* Allocate bnapi mem pointer array and mem block for
3961 arr_size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
*) *
3963 size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
));
3964 bnapi
= kzalloc(arr_size
+ size
* bp
->cp_nr_rings
, GFP_KERNEL
);
3970 for (i
= 0; i
< bp
->cp_nr_rings
; i
++, bnapi
+= size
) {
3971 bp
->bnapi
[i
] = bnapi
;
3972 bp
->bnapi
[i
]->index
= i
;
3973 bp
->bnapi
[i
]->bp
= bp
;
3974 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
3975 struct bnxt_cp_ring_info
*cpr
=
3976 &bp
->bnapi
[i
]->cp_ring
;
3978 cpr
->cp_ring_struct
.ring_mem
.flags
=
3979 BNXT_RMEM_RING_PTE_FLAG
;
3983 bp
->rx_ring
= kcalloc(bp
->rx_nr_rings
,
3984 sizeof(struct bnxt_rx_ring_info
),
3989 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3990 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3992 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
3993 rxr
->rx_ring_struct
.ring_mem
.flags
=
3994 BNXT_RMEM_RING_PTE_FLAG
;
3995 rxr
->rx_agg_ring_struct
.ring_mem
.flags
=
3996 BNXT_RMEM_RING_PTE_FLAG
;
3998 rxr
->bnapi
= bp
->bnapi
[i
];
3999 bp
->bnapi
[i
]->rx_ring
= &bp
->rx_ring
[i
];
4002 bp
->tx_ring
= kcalloc(bp
->tx_nr_rings
,
4003 sizeof(struct bnxt_tx_ring_info
),
4008 bp
->tx_ring_map
= kcalloc(bp
->tx_nr_rings
, sizeof(u16
),
4011 if (!bp
->tx_ring_map
)
4014 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
4017 j
= bp
->rx_nr_rings
;
4019 for (i
= 0; i
< bp
->tx_nr_rings
; i
++, j
++) {
4020 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
4022 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4023 txr
->tx_ring_struct
.ring_mem
.flags
=
4024 BNXT_RMEM_RING_PTE_FLAG
;
4025 txr
->bnapi
= bp
->bnapi
[j
];
4026 bp
->bnapi
[j
]->tx_ring
= txr
;
4027 bp
->tx_ring_map
[i
] = bp
->tx_nr_rings_xdp
+ i
;
4028 if (i
>= bp
->tx_nr_rings_xdp
) {
4029 txr
->txq_index
= i
- bp
->tx_nr_rings_xdp
;
4030 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int
;
4032 bp
->bnapi
[j
]->flags
|= BNXT_NAPI_FLAG_XDP
;
4033 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int_xdp
;
4037 rc
= bnxt_alloc_stats(bp
);
4041 rc
= bnxt_alloc_ntp_fltrs(bp
);
4045 rc
= bnxt_alloc_vnics(bp
);
4050 bnxt_init_ring_struct(bp
);
4052 rc
= bnxt_alloc_rx_rings(bp
);
4056 rc
= bnxt_alloc_tx_rings(bp
);
4060 rc
= bnxt_alloc_cp_rings(bp
);
4064 bp
->vnic_info
[0].flags
|= BNXT_VNIC_RSS_FLAG
| BNXT_VNIC_MCAST_FLAG
|
4065 BNXT_VNIC_UCAST_FLAG
;
4066 rc
= bnxt_alloc_vnic_attributes(bp
);
4072 bnxt_free_mem(bp
, true);
4076 static void bnxt_disable_int(struct bnxt
*bp
)
4083 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4084 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4085 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4086 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
4088 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
)
4089 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
4093 static int bnxt_cp_num_to_irq_num(struct bnxt
*bp
, int n
)
4095 struct bnxt_napi
*bnapi
= bp
->bnapi
[n
];
4096 struct bnxt_cp_ring_info
*cpr
;
4098 cpr
= &bnapi
->cp_ring
;
4099 return cpr
->cp_ring_struct
.map_idx
;
4102 static void bnxt_disable_int_sync(struct bnxt
*bp
)
4106 atomic_inc(&bp
->intr_sem
);
4108 bnxt_disable_int(bp
);
4109 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4110 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
4112 synchronize_irq(bp
->irq_tbl
[map_idx
].vector
);
4116 static void bnxt_enable_int(struct bnxt
*bp
)
4120 atomic_set(&bp
->intr_sem
, 0);
4121 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4122 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4123 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4125 bnxt_db_nq_arm(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
4129 void bnxt_hwrm_cmd_hdr_init(struct bnxt
*bp
, void *request
, u16 req_type
,
4130 u16 cmpl_ring
, u16 target_id
)
4132 struct input
*req
= request
;
4134 req
->req_type
= cpu_to_le16(req_type
);
4135 req
->cmpl_ring
= cpu_to_le16(cmpl_ring
);
4136 req
->target_id
= cpu_to_le16(target_id
);
4137 if (bnxt_kong_hwrm_message(bp
, req
))
4138 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_kong_resp_dma_addr
);
4140 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_resp_dma_addr
);
4143 static int bnxt_hwrm_to_stderr(u32 hwrm_err
)
4146 case HWRM_ERR_CODE_SUCCESS
:
4148 case HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED
:
4150 case HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR
:
4152 case HWRM_ERR_CODE_INVALID_PARAMS
:
4153 case HWRM_ERR_CODE_INVALID_FLAGS
:
4154 case HWRM_ERR_CODE_INVALID_ENABLES
:
4155 case HWRM_ERR_CODE_UNSUPPORTED_TLV
:
4156 case HWRM_ERR_CODE_UNSUPPORTED_OPTION_ERR
:
4158 case HWRM_ERR_CODE_NO_BUFFER
:
4160 case HWRM_ERR_CODE_HOT_RESET_PROGRESS
:
4162 case HWRM_ERR_CODE_CMD_NOT_SUPPORTED
:
4169 static int bnxt_hwrm_do_send_msg(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4170 int timeout
, bool silent
)
4172 int i
, intr_process
, rc
, tmo_count
;
4173 struct input
*req
= msg
;
4177 u16 cp_ring_id
, len
= 0;
4178 struct hwrm_err_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4179 u16 max_req_len
= BNXT_HWRM_MAX_REQ_LEN
;
4180 struct hwrm_short_input short_input
= {0};
4181 u32 doorbell_offset
= BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER
;
4182 u8
*resp_addr
= (u8
*)bp
->hwrm_cmd_resp_addr
;
4183 u32 bar_offset
= BNXT_GRCPF_REG_CHIMP_COMM
;
4184 u16 dst
= BNXT_HWRM_CHNL_CHIMP
;
4186 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
4189 if (msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
4190 if (msg_len
> bp
->hwrm_max_ext_req_len
||
4191 !bp
->hwrm_short_cmd_req_addr
)
4195 if (bnxt_hwrm_kong_chnl(bp
, req
)) {
4196 dst
= BNXT_HWRM_CHNL_KONG
;
4197 bar_offset
= BNXT_GRCPF_REG_KONG_COMM
;
4198 doorbell_offset
= BNXT_GRCPF_REG_KONG_COMM_TRIGGER
;
4199 resp
= bp
->hwrm_cmd_kong_resp_addr
;
4200 resp_addr
= (u8
*)bp
->hwrm_cmd_kong_resp_addr
;
4203 memset(resp
, 0, PAGE_SIZE
);
4204 cp_ring_id
= le16_to_cpu(req
->cmpl_ring
);
4205 intr_process
= (cp_ring_id
== INVALID_HW_RING_ID
) ? 0 : 1;
4207 req
->seq_id
= cpu_to_le16(bnxt_get_hwrm_seq_id(bp
, dst
));
4208 /* currently supports only one outstanding message */
4210 bp
->hwrm_intr_seq_id
= le16_to_cpu(req
->seq_id
);
4212 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
4213 msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
4214 void *short_cmd_req
= bp
->hwrm_short_cmd_req_addr
;
4217 /* Set boundary for maximum extended request length for short
4218 * cmd format. If passed up from device use the max supported
4219 * internal req length.
4221 max_msg_len
= bp
->hwrm_max_ext_req_len
;
4223 memcpy(short_cmd_req
, req
, msg_len
);
4224 if (msg_len
< max_msg_len
)
4225 memset(short_cmd_req
+ msg_len
, 0,
4226 max_msg_len
- msg_len
);
4228 short_input
.req_type
= req
->req_type
;
4229 short_input
.signature
=
4230 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD
);
4231 short_input
.size
= cpu_to_le16(msg_len
);
4232 short_input
.req_addr
=
4233 cpu_to_le64(bp
->hwrm_short_cmd_req_dma_addr
);
4235 data
= (u32
*)&short_input
;
4236 msg_len
= sizeof(short_input
);
4238 /* Sync memory write before updating doorbell */
4241 max_req_len
= BNXT_HWRM_SHORT_REQ_LEN
;
4244 /* Write request msg to hwrm channel */
4245 __iowrite32_copy(bp
->bar0
+ bar_offset
, data
, msg_len
/ 4);
4247 for (i
= msg_len
; i
< max_req_len
; i
+= 4)
4248 writel(0, bp
->bar0
+ bar_offset
+ i
);
4250 /* Ring channel doorbell */
4251 writel(1, bp
->bar0
+ doorbell_offset
);
4253 if (!pci_is_enabled(bp
->pdev
))
4257 timeout
= DFLT_HWRM_CMD_TIMEOUT
;
4258 /* convert timeout to usec */
4262 /* Short timeout for the first few iterations:
4263 * number of loops = number of loops for short timeout +
4264 * number of loops for standard timeout.
4266 tmo_count
= HWRM_SHORT_TIMEOUT_COUNTER
;
4267 timeout
= timeout
- HWRM_SHORT_MIN_TIMEOUT
* HWRM_SHORT_TIMEOUT_COUNTER
;
4268 tmo_count
+= DIV_ROUND_UP(timeout
, HWRM_MIN_TIMEOUT
);
4269 resp_len
= (__le32
*)(resp_addr
+ HWRM_RESP_LEN_OFFSET
);
4272 u16 seq_id
= bp
->hwrm_intr_seq_id
;
4274 /* Wait until hwrm response cmpl interrupt is processed */
4275 while (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
&&
4277 /* on first few passes, just barely sleep */
4278 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
)
4279 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
4280 HWRM_SHORT_MAX_TIMEOUT
);
4282 usleep_range(HWRM_MIN_TIMEOUT
,
4286 if (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
) {
4288 netdev_err(bp
->dev
, "Resp cmpl intr err msg: 0x%x\n",
4289 le16_to_cpu(req
->req_type
));
4292 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
4294 valid
= resp_addr
+ len
- 1;
4298 /* Check if response len is updated */
4299 for (i
= 0; i
< tmo_count
; i
++) {
4300 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
4304 /* on first few passes, just barely sleep */
4305 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
)
4306 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
4307 HWRM_SHORT_MAX_TIMEOUT
);
4309 usleep_range(HWRM_MIN_TIMEOUT
,
4313 if (i
>= tmo_count
) {
4315 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
4316 HWRM_TOTAL_TIMEOUT(i
),
4317 le16_to_cpu(req
->req_type
),
4318 le16_to_cpu(req
->seq_id
), len
);
4322 /* Last byte of resp contains valid bit */
4323 valid
= resp_addr
+ len
- 1;
4324 for (j
= 0; j
< HWRM_VALID_BIT_DELAY_USEC
; j
++) {
4325 /* make sure we read from updated DMA memory */
4332 if (j
>= HWRM_VALID_BIT_DELAY_USEC
) {
4334 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
4335 HWRM_TOTAL_TIMEOUT(i
),
4336 le16_to_cpu(req
->req_type
),
4337 le16_to_cpu(req
->seq_id
), len
,
4343 /* Zero valid bit for compatibility. Valid bit in an older spec
4344 * may become a new field in a newer spec. We must make sure that
4345 * a new field not implemented by old spec will read zero.
4348 rc
= le16_to_cpu(resp
->error_code
);
4350 netdev_err(bp
->dev
, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
4351 le16_to_cpu(resp
->req_type
),
4352 le16_to_cpu(resp
->seq_id
), rc
);
4353 return bnxt_hwrm_to_stderr(rc
);
4356 int _hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
4358 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, false);
4361 int _hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4364 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
4367 int hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
4371 mutex_lock(&bp
->hwrm_cmd_lock
);
4372 rc
= _hwrm_send_message(bp
, msg
, msg_len
, timeout
);
4373 mutex_unlock(&bp
->hwrm_cmd_lock
);
4377 int hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4382 mutex_lock(&bp
->hwrm_cmd_lock
);
4383 rc
= bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
4384 mutex_unlock(&bp
->hwrm_cmd_lock
);
4388 int bnxt_hwrm_func_rgtr_async_events(struct bnxt
*bp
, unsigned long *bmap
,
4391 struct hwrm_func_drv_rgtr_input req
= {0};
4392 DECLARE_BITMAP(async_events_bmap
, 256);
4393 u32
*events
= (u32
*)async_events_bmap
;
4396 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
4399 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
4401 memset(async_events_bmap
, 0, sizeof(async_events_bmap
));
4402 for (i
= 0; i
< ARRAY_SIZE(bnxt_async_events_arr
); i
++) {
4403 u16 event_id
= bnxt_async_events_arr
[i
];
4405 if (event_id
== ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY
&&
4406 !(bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
))
4408 __set_bit(bnxt_async_events_arr
[i
], async_events_bmap
);
4410 if (bmap
&& bmap_size
) {
4411 for (i
= 0; i
< bmap_size
; i
++) {
4412 if (test_bit(i
, bmap
))
4413 __set_bit(i
, async_events_bmap
);
4417 for (i
= 0; i
< 8; i
++)
4418 req
.async_event_fwd
[i
] |= cpu_to_le32(events
[i
]);
4420 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4423 static int bnxt_hwrm_func_drv_rgtr(struct bnxt
*bp
)
4425 struct hwrm_func_drv_rgtr_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4426 struct hwrm_func_drv_rgtr_input req
= {0};
4430 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
4433 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE
|
4434 FUNC_DRV_RGTR_REQ_ENABLES_VER
);
4436 req
.os_type
= cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX
);
4437 flags
= FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE
|
4438 FUNC_DRV_RGTR_REQ_FLAGS_HOT_RESET_SUPPORT
;
4439 if (bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
)
4440 flags
|= FUNC_DRV_RGTR_REQ_FLAGS_ERROR_RECOVERY_SUPPORT
;
4441 req
.flags
= cpu_to_le32(flags
);
4442 req
.ver_maj_8b
= DRV_VER_MAJ
;
4443 req
.ver_min_8b
= DRV_VER_MIN
;
4444 req
.ver_upd_8b
= DRV_VER_UPD
;
4445 req
.ver_maj
= cpu_to_le16(DRV_VER_MAJ
);
4446 req
.ver_min
= cpu_to_le16(DRV_VER_MIN
);
4447 req
.ver_upd
= cpu_to_le16(DRV_VER_UPD
);
4453 memset(data
, 0, sizeof(data
));
4454 for (i
= 0; i
< ARRAY_SIZE(bnxt_vf_req_snif
); i
++) {
4455 u16 cmd
= bnxt_vf_req_snif
[i
];
4456 unsigned int bit
, idx
;
4460 data
[idx
] |= 1 << bit
;
4463 for (i
= 0; i
< 8; i
++)
4464 req
.vf_req_fwd
[i
] = cpu_to_le32(data
[i
]);
4467 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD
);
4470 if (bp
->fw_cap
& BNXT_FW_CAP_OVS_64BIT_HANDLE
)
4471 req
.flags
|= cpu_to_le32(
4472 FUNC_DRV_RGTR_REQ_FLAGS_FLOW_HANDLE_64BIT_MODE
);
4474 mutex_lock(&bp
->hwrm_cmd_lock
);
4475 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4476 if (!rc
&& (resp
->flags
&
4477 cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED
)))
4478 bp
->fw_cap
|= BNXT_FW_CAP_IF_CHANGE
;
4479 mutex_unlock(&bp
->hwrm_cmd_lock
);
4483 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt
*bp
)
4485 struct hwrm_func_drv_unrgtr_input req
= {0};
4487 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_UNRGTR
, -1, -1);
4488 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4491 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt
*bp
, u8 tunnel_type
)
4494 struct hwrm_tunnel_dst_port_free_input req
= {0};
4496 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_FREE
, -1, -1);
4497 req
.tunnel_type
= tunnel_type
;
4499 switch (tunnel_type
) {
4500 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
:
4501 req
.tunnel_dst_port_id
= bp
->vxlan_fw_dst_port_id
;
4503 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
:
4504 req
.tunnel_dst_port_id
= bp
->nge_fw_dst_port_id
;
4510 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4512 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
4517 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt
*bp
, __be16 port
,
4521 struct hwrm_tunnel_dst_port_alloc_input req
= {0};
4522 struct hwrm_tunnel_dst_port_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4524 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_ALLOC
, -1, -1);
4526 req
.tunnel_type
= tunnel_type
;
4527 req
.tunnel_dst_port_val
= port
;
4529 mutex_lock(&bp
->hwrm_cmd_lock
);
4530 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4532 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
4537 switch (tunnel_type
) {
4538 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN
:
4539 bp
->vxlan_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
4541 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE
:
4542 bp
->nge_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
4549 mutex_unlock(&bp
->hwrm_cmd_lock
);
4553 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt
*bp
, u16 vnic_id
)
4555 struct hwrm_cfa_l2_set_rx_mask_input req
= {0};
4556 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4558 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_SET_RX_MASK
, -1, -1);
4559 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4561 req
.num_mc_entries
= cpu_to_le32(vnic
->mc_list_count
);
4562 req
.mc_tbl_addr
= cpu_to_le64(vnic
->mc_list_mapping
);
4563 req
.mask
= cpu_to_le32(vnic
->rx_mask
);
4564 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4567 #ifdef CONFIG_RFS_ACCEL
4568 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt
*bp
,
4569 struct bnxt_ntuple_filter
*fltr
)
4571 struct hwrm_cfa_ntuple_filter_free_input req
= {0};
4573 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_FREE
, -1, -1);
4574 req
.ntuple_filter_id
= fltr
->filter_id
;
4575 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4578 #define BNXT_NTP_FLTR_FLAGS \
4579 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
4580 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
4581 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
4582 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
4583 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
4584 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
4585 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
4586 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
4587 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
4588 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
4589 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
4590 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
4591 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
4592 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
4594 #define BNXT_NTP_TUNNEL_FLTR_FLAG \
4595 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
4597 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt
*bp
,
4598 struct bnxt_ntuple_filter
*fltr
)
4600 struct hwrm_cfa_ntuple_filter_alloc_input req
= {0};
4601 struct hwrm_cfa_ntuple_filter_alloc_output
*resp
;
4602 struct flow_keys
*keys
= &fltr
->fkeys
;
4603 struct bnxt_vnic_info
*vnic
;
4607 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_ALLOC
, -1, -1);
4608 req
.l2_filter_id
= bp
->vnic_info
[0].fw_l2_filter_id
[fltr
->l2_fltr_idx
];
4610 if (bp
->fw_cap
& BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX
) {
4611 dst_ena
= CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_RFS_RING_TBL_IDX
;
4612 req
.rfs_ring_tbl_idx
= cpu_to_le16(fltr
->rxq
);
4613 vnic
= &bp
->vnic_info
[0];
4615 vnic
= &bp
->vnic_info
[fltr
->rxq
+ 1];
4617 req
.dst_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4618 req
.enables
= cpu_to_le32(BNXT_NTP_FLTR_FLAGS
| dst_ena
);
4620 req
.ethertype
= htons(ETH_P_IP
);
4621 memcpy(req
.src_macaddr
, fltr
->src_mac_addr
, ETH_ALEN
);
4622 req
.ip_addr_type
= CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4
;
4623 req
.ip_protocol
= keys
->basic
.ip_proto
;
4625 if (keys
->basic
.n_proto
== htons(ETH_P_IPV6
)) {
4628 req
.ethertype
= htons(ETH_P_IPV6
);
4630 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6
;
4631 *(struct in6_addr
*)&req
.src_ipaddr
[0] =
4632 keys
->addrs
.v6addrs
.src
;
4633 *(struct in6_addr
*)&req
.dst_ipaddr
[0] =
4634 keys
->addrs
.v6addrs
.dst
;
4635 for (i
= 0; i
< 4; i
++) {
4636 req
.src_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4637 req
.dst_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4640 req
.src_ipaddr
[0] = keys
->addrs
.v4addrs
.src
;
4641 req
.src_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4642 req
.dst_ipaddr
[0] = keys
->addrs
.v4addrs
.dst
;
4643 req
.dst_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4645 if (keys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) {
4646 req
.enables
|= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG
);
4648 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL
;
4651 req
.src_port
= keys
->ports
.src
;
4652 req
.src_port_mask
= cpu_to_be16(0xffff);
4653 req
.dst_port
= keys
->ports
.dst
;
4654 req
.dst_port_mask
= cpu_to_be16(0xffff);
4656 mutex_lock(&bp
->hwrm_cmd_lock
);
4657 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4659 resp
= bnxt_get_hwrm_resp_addr(bp
, &req
);
4660 fltr
->filter_id
= resp
->ntuple_filter_id
;
4662 mutex_unlock(&bp
->hwrm_cmd_lock
);
4667 static int bnxt_hwrm_set_vnic_filter(struct bnxt
*bp
, u16 vnic_id
, u16 idx
,
4671 struct hwrm_cfa_l2_filter_alloc_input req
= {0};
4672 struct hwrm_cfa_l2_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4674 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_ALLOC
, -1, -1);
4675 req
.flags
= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX
);
4676 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
4678 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST
);
4679 req
.dst_id
= cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
4681 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR
|
4682 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID
|
4683 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK
);
4684 memcpy(req
.l2_addr
, mac_addr
, ETH_ALEN
);
4685 req
.l2_addr_mask
[0] = 0xff;
4686 req
.l2_addr_mask
[1] = 0xff;
4687 req
.l2_addr_mask
[2] = 0xff;
4688 req
.l2_addr_mask
[3] = 0xff;
4689 req
.l2_addr_mask
[4] = 0xff;
4690 req
.l2_addr_mask
[5] = 0xff;
4692 mutex_lock(&bp
->hwrm_cmd_lock
);
4693 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4695 bp
->vnic_info
[vnic_id
].fw_l2_filter_id
[idx
] =
4697 mutex_unlock(&bp
->hwrm_cmd_lock
);
4701 static int bnxt_hwrm_clear_vnic_filter(struct bnxt
*bp
)
4703 u16 i
, j
, num_of_vnics
= 1; /* only vnic 0 supported */
4706 /* Any associated ntuple filters will also be cleared by firmware. */
4707 mutex_lock(&bp
->hwrm_cmd_lock
);
4708 for (i
= 0; i
< num_of_vnics
; i
++) {
4709 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
4711 for (j
= 0; j
< vnic
->uc_filter_count
; j
++) {
4712 struct hwrm_cfa_l2_filter_free_input req
= {0};
4714 bnxt_hwrm_cmd_hdr_init(bp
, &req
,
4715 HWRM_CFA_L2_FILTER_FREE
, -1, -1);
4717 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[j
];
4719 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4722 vnic
->uc_filter_count
= 0;
4724 mutex_unlock(&bp
->hwrm_cmd_lock
);
4729 static int bnxt_hwrm_vnic_set_tpa(struct bnxt
*bp
, u16 vnic_id
, u32 tpa_flags
)
4731 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4732 u16 max_aggs
= VNIC_TPA_CFG_REQ_MAX_AGGS_MAX
;
4733 struct hwrm_vnic_tpa_cfg_input req
= {0};
4735 if (vnic
->fw_vnic_id
== INVALID_HW_RING_ID
)
4738 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_TPA_CFG
, -1, -1);
4741 u16 mss
= bp
->dev
->mtu
- 40;
4742 u32 nsegs
, n
, segs
= 0, flags
;
4744 flags
= VNIC_TPA_CFG_REQ_FLAGS_TPA
|
4745 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA
|
4746 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE
|
4747 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN
|
4748 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ
;
4749 if (tpa_flags
& BNXT_FLAG_GRO
)
4750 flags
|= VNIC_TPA_CFG_REQ_FLAGS_GRO
;
4752 req
.flags
= cpu_to_le32(flags
);
4755 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS
|
4756 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS
|
4757 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN
);
4759 /* Number of segs are log2 units, and first packet is not
4760 * included as part of this units.
4762 if (mss
<= BNXT_RX_PAGE_SIZE
) {
4763 n
= BNXT_RX_PAGE_SIZE
/ mss
;
4764 nsegs
= (MAX_SKB_FRAGS
- 1) * n
;
4766 n
= mss
/ BNXT_RX_PAGE_SIZE
;
4767 if (mss
& (BNXT_RX_PAGE_SIZE
- 1))
4769 nsegs
= (MAX_SKB_FRAGS
- n
) / n
;
4772 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4773 segs
= MAX_TPA_SEGS_P5
;
4774 max_aggs
= bp
->max_tpa
;
4776 segs
= ilog2(nsegs
);
4778 req
.max_agg_segs
= cpu_to_le16(segs
);
4779 req
.max_aggs
= cpu_to_le16(max_aggs
);
4781 req
.min_agg_len
= cpu_to_le32(512);
4783 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4785 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4788 static u16
bnxt_cp_ring_from_grp(struct bnxt
*bp
, struct bnxt_ring_struct
*ring
)
4790 struct bnxt_ring_grp_info
*grp_info
;
4792 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4793 return grp_info
->cp_fw_ring_id
;
4796 static u16
bnxt_cp_ring_for_rx(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
4798 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4799 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
4800 struct bnxt_cp_ring_info
*cpr
;
4802 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_RX_HDL
];
4803 return cpr
->cp_ring_struct
.fw_ring_id
;
4805 return bnxt_cp_ring_from_grp(bp
, &rxr
->rx_ring_struct
);
4809 static u16
bnxt_cp_ring_for_tx(struct bnxt
*bp
, struct bnxt_tx_ring_info
*txr
)
4811 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4812 struct bnxt_napi
*bnapi
= txr
->bnapi
;
4813 struct bnxt_cp_ring_info
*cpr
;
4815 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_TX_HDL
];
4816 return cpr
->cp_ring_struct
.fw_ring_id
;
4818 return bnxt_cp_ring_from_grp(bp
, &txr
->tx_ring_struct
);
4822 static int bnxt_hwrm_vnic_set_rss(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
4824 u32 i
, j
, max_rings
;
4825 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4826 struct hwrm_vnic_rss_cfg_input req
= {0};
4828 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) ||
4829 vnic
->fw_rss_cos_lb_ctx
[0] == INVALID_HW_RING_ID
)
4832 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
4834 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
4835 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
4836 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
) {
4837 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
4838 max_rings
= bp
->rx_nr_rings
- 1;
4840 max_rings
= bp
->rx_nr_rings
;
4845 /* Fill the RSS indirection table with ring group ids */
4846 for (i
= 0, j
= 0; i
< HW_HASH_INDEX_SIZE
; i
++, j
++) {
4849 vnic
->rss_table
[i
] = cpu_to_le16(vnic
->fw_grp_ids
[j
]);
4852 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
4853 req
.hash_key_tbl_addr
=
4854 cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
4856 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
4857 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4860 static int bnxt_hwrm_vnic_set_rss_p5(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
4862 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4863 u32 i
, j
, k
, nr_ctxs
, max_rings
= bp
->rx_nr_rings
;
4864 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[0];
4865 struct hwrm_vnic_rss_cfg_input req
= {0};
4867 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
4868 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4870 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4873 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
4874 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
4875 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
4876 req
.hash_key_tbl_addr
= cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
4877 nr_ctxs
= DIV_ROUND_UP(bp
->rx_nr_rings
, 64);
4878 for (i
= 0, k
= 0; i
< nr_ctxs
; i
++) {
4879 __le16
*ring_tbl
= vnic
->rss_table
;
4882 req
.ring_table_pair_index
= i
;
4883 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[i
]);
4884 for (j
= 0; j
< 64; j
++) {
4887 ring_id
= rxr
->rx_ring_struct
.fw_ring_id
;
4888 *ring_tbl
++ = cpu_to_le16(ring_id
);
4889 ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
4890 *ring_tbl
++ = cpu_to_le16(ring_id
);
4893 if (k
== max_rings
) {
4895 rxr
= &bp
->rx_ring
[0];
4898 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4905 static int bnxt_hwrm_vnic_set_hds(struct bnxt
*bp
, u16 vnic_id
)
4907 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4908 struct hwrm_vnic_plcmodes_cfg_input req
= {0};
4910 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_PLCMODES_CFG
, -1, -1);
4911 req
.flags
= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT
|
4912 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4
|
4913 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6
);
4915 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID
|
4916 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID
);
4917 /* thresholds not implemented in firmware yet */
4918 req
.jumbo_thresh
= cpu_to_le16(bp
->rx_copy_thresh
);
4919 req
.hds_threshold
= cpu_to_le16(bp
->rx_copy_thresh
);
4920 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4921 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4924 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt
*bp
, u16 vnic_id
,
4927 struct hwrm_vnic_rss_cos_lb_ctx_free_input req
= {0};
4929 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_FREE
, -1, -1);
4930 req
.rss_cos_lb_ctx_id
=
4931 cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
]);
4933 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4934 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] = INVALID_HW_RING_ID
;
4937 static void bnxt_hwrm_vnic_ctx_free(struct bnxt
*bp
)
4941 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
4942 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
4944 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++) {
4945 if (vnic
->fw_rss_cos_lb_ctx
[j
] != INVALID_HW_RING_ID
)
4946 bnxt_hwrm_vnic_ctx_free_one(bp
, i
, j
);
4949 bp
->rsscos_nr_ctxs
= 0;
4952 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt
*bp
, u16 vnic_id
, u16 ctx_idx
)
4955 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req
= {0};
4956 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output
*resp
=
4957 bp
->hwrm_cmd_resp_addr
;
4959 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC
, -1,
4962 mutex_lock(&bp
->hwrm_cmd_lock
);
4963 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4965 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] =
4966 le16_to_cpu(resp
->rss_cos_lb_ctx_id
);
4967 mutex_unlock(&bp
->hwrm_cmd_lock
);
4972 static u32
bnxt_get_roce_vnic_mode(struct bnxt
*bp
)
4974 if (bp
->flags
& BNXT_FLAG_ROCE_MIRROR_CAP
)
4975 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE
;
4976 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE
;
4979 int bnxt_hwrm_vnic_cfg(struct bnxt
*bp
, u16 vnic_id
)
4981 unsigned int ring
= 0, grp_idx
;
4982 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4983 struct hwrm_vnic_cfg_input req
= {0};
4986 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_CFG
, -1, -1);
4988 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4989 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[0];
4991 req
.default_rx_ring_id
=
4992 cpu_to_le16(rxr
->rx_ring_struct
.fw_ring_id
);
4993 req
.default_cmpl_ring_id
=
4994 cpu_to_le16(bnxt_cp_ring_for_rx(bp
, rxr
));
4996 cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID
|
4997 VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID
);
5000 req
.enables
= cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP
);
5001 /* Only RSS support for now TBD: COS & LB */
5002 if (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
) {
5003 req
.rss_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
5004 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
5005 VNIC_CFG_REQ_ENABLES_MRU
);
5006 } else if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
) {
5008 cpu_to_le16(bp
->vnic_info
[0].fw_rss_cos_lb_ctx
[0]);
5009 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
5010 VNIC_CFG_REQ_ENABLES_MRU
);
5011 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE
);
5013 req
.rss_rule
= cpu_to_le16(0xffff);
5016 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) &&
5017 (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
)) {
5018 req
.cos_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[1]);
5019 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE
);
5021 req
.cos_rule
= cpu_to_le16(0xffff);
5024 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
5026 else if (vnic
->flags
& BNXT_VNIC_RFS_FLAG
)
5028 else if ((vnic_id
== 1) && BNXT_CHIP_TYPE_NITRO_A0(bp
))
5029 ring
= bp
->rx_nr_rings
- 1;
5031 grp_idx
= bp
->rx_ring
[ring
].bnapi
->index
;
5032 req
.dflt_ring_grp
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_grp_id
);
5033 req
.lb_rule
= cpu_to_le16(0xffff);
5035 req
.mru
= cpu_to_le16(bp
->dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+
5038 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
5039 #ifdef CONFIG_BNXT_SRIOV
5041 def_vlan
= bp
->vf
.vlan
;
5043 if ((bp
->flags
& BNXT_FLAG_STRIP_VLAN
) || def_vlan
)
5044 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE
);
5045 if (!vnic_id
&& bnxt_ulp_registered(bp
->edev
, BNXT_ROCE_ULP
))
5046 req
.flags
|= cpu_to_le32(bnxt_get_roce_vnic_mode(bp
));
5048 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5051 static int bnxt_hwrm_vnic_free_one(struct bnxt
*bp
, u16 vnic_id
)
5055 if (bp
->vnic_info
[vnic_id
].fw_vnic_id
!= INVALID_HW_RING_ID
) {
5056 struct hwrm_vnic_free_input req
= {0};
5058 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_FREE
, -1, -1);
5060 cpu_to_le32(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
5062 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5063 bp
->vnic_info
[vnic_id
].fw_vnic_id
= INVALID_HW_RING_ID
;
5068 static void bnxt_hwrm_vnic_free(struct bnxt
*bp
)
5072 for (i
= 0; i
< bp
->nr_vnics
; i
++)
5073 bnxt_hwrm_vnic_free_one(bp
, i
);
5076 static int bnxt_hwrm_vnic_alloc(struct bnxt
*bp
, u16 vnic_id
,
5077 unsigned int start_rx_ring_idx
,
5078 unsigned int nr_rings
)
5081 unsigned int i
, j
, grp_idx
, end_idx
= start_rx_ring_idx
+ nr_rings
;
5082 struct hwrm_vnic_alloc_input req
= {0};
5083 struct hwrm_vnic_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5084 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
5086 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5087 goto vnic_no_ring_grps
;
5089 /* map ring groups to this vnic */
5090 for (i
= start_rx_ring_idx
, j
= 0; i
< end_idx
; i
++, j
++) {
5091 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
5092 if (bp
->grp_info
[grp_idx
].fw_grp_id
== INVALID_HW_RING_ID
) {
5093 netdev_err(bp
->dev
, "Not enough ring groups avail:%x req:%x\n",
5097 vnic
->fw_grp_ids
[j
] = bp
->grp_info
[grp_idx
].fw_grp_id
;
5101 for (i
= 0; i
< BNXT_MAX_CTX_PER_VNIC
; i
++)
5102 vnic
->fw_rss_cos_lb_ctx
[i
] = INVALID_HW_RING_ID
;
5104 req
.flags
= cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT
);
5106 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_ALLOC
, -1, -1);
5108 mutex_lock(&bp
->hwrm_cmd_lock
);
5109 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5111 vnic
->fw_vnic_id
= le32_to_cpu(resp
->vnic_id
);
5112 mutex_unlock(&bp
->hwrm_cmd_lock
);
5116 static int bnxt_hwrm_vnic_qcaps(struct bnxt
*bp
)
5118 struct hwrm_vnic_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5119 struct hwrm_vnic_qcaps_input req
= {0};
5122 bp
->hw_ring_stats_size
= sizeof(struct ctx_hw_stats
);
5123 bp
->flags
&= ~(BNXT_FLAG_NEW_RSS_CAP
| BNXT_FLAG_ROCE_MIRROR_CAP
);
5124 if (bp
->hwrm_spec_code
< 0x10600)
5127 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_QCAPS
, -1, -1);
5128 mutex_lock(&bp
->hwrm_cmd_lock
);
5129 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5131 u32 flags
= le32_to_cpu(resp
->flags
);
5133 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
) &&
5134 (flags
& VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP
))
5135 bp
->flags
|= BNXT_FLAG_NEW_RSS_CAP
;
5137 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP
)
5138 bp
->flags
|= BNXT_FLAG_ROCE_MIRROR_CAP
;
5139 bp
->max_tpa_v2
= le16_to_cpu(resp
->max_aggs_supported
);
5141 bp
->hw_ring_stats_size
=
5142 sizeof(struct ctx_hw_stats_ext
);
5144 mutex_unlock(&bp
->hwrm_cmd_lock
);
5148 static int bnxt_hwrm_ring_grp_alloc(struct bnxt
*bp
)
5153 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5156 mutex_lock(&bp
->hwrm_cmd_lock
);
5157 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5158 struct hwrm_ring_grp_alloc_input req
= {0};
5159 struct hwrm_ring_grp_alloc_output
*resp
=
5160 bp
->hwrm_cmd_resp_addr
;
5161 unsigned int grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
5163 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_ALLOC
, -1, -1);
5165 req
.cr
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
5166 req
.rr
= cpu_to_le16(bp
->grp_info
[grp_idx
].rx_fw_ring_id
);
5167 req
.ar
= cpu_to_le16(bp
->grp_info
[grp_idx
].agg_fw_ring_id
);
5168 req
.sc
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_stats_ctx
);
5170 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5175 bp
->grp_info
[grp_idx
].fw_grp_id
=
5176 le32_to_cpu(resp
->ring_group_id
);
5178 mutex_unlock(&bp
->hwrm_cmd_lock
);
5182 static int bnxt_hwrm_ring_grp_free(struct bnxt
*bp
)
5186 struct hwrm_ring_grp_free_input req
= {0};
5188 if (!bp
->grp_info
|| (bp
->flags
& BNXT_FLAG_CHIP_P5
))
5191 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_FREE
, -1, -1);
5193 mutex_lock(&bp
->hwrm_cmd_lock
);
5194 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5195 if (bp
->grp_info
[i
].fw_grp_id
== INVALID_HW_RING_ID
)
5198 cpu_to_le32(bp
->grp_info
[i
].fw_grp_id
);
5200 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5202 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
5204 mutex_unlock(&bp
->hwrm_cmd_lock
);
5208 static int hwrm_ring_alloc_send_msg(struct bnxt
*bp
,
5209 struct bnxt_ring_struct
*ring
,
5210 u32 ring_type
, u32 map_index
)
5212 int rc
= 0, err
= 0;
5213 struct hwrm_ring_alloc_input req
= {0};
5214 struct hwrm_ring_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5215 struct bnxt_ring_mem_info
*rmem
= &ring
->ring_mem
;
5216 struct bnxt_ring_grp_info
*grp_info
;
5219 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_ALLOC
, -1, -1);
5222 if (rmem
->nr_pages
> 1) {
5223 req
.page_tbl_addr
= cpu_to_le64(rmem
->pg_tbl_map
);
5224 /* Page size is in log2 units */
5225 req
.page_size
= BNXT_PAGE_SHIFT
;
5226 req
.page_tbl_depth
= 1;
5228 req
.page_tbl_addr
= cpu_to_le64(rmem
->dma_arr
[0]);
5231 /* Association of ring index with doorbell index and MSIX number */
5232 req
.logical_id
= cpu_to_le16(map_index
);
5234 switch (ring_type
) {
5235 case HWRM_RING_ALLOC_TX
: {
5236 struct bnxt_tx_ring_info
*txr
;
5238 txr
= container_of(ring
, struct bnxt_tx_ring_info
,
5240 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_TX
;
5241 /* Association of transmit ring with completion ring */
5242 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5243 req
.cmpl_ring_id
= cpu_to_le16(bnxt_cp_ring_for_tx(bp
, txr
));
5244 req
.length
= cpu_to_le32(bp
->tx_ring_mask
+ 1);
5245 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5246 req
.queue_id
= cpu_to_le16(ring
->queue_id
);
5249 case HWRM_RING_ALLOC_RX
:
5250 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
5251 req
.length
= cpu_to_le32(bp
->rx_ring_mask
+ 1);
5252 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5255 /* Association of rx ring with stats context */
5256 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5257 req
.rx_buf_size
= cpu_to_le16(bp
->rx_buf_use_size
);
5258 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5259 req
.enables
|= cpu_to_le32(
5260 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
5261 if (NET_IP_ALIGN
== 2)
5262 flags
= RING_ALLOC_REQ_FLAGS_RX_SOP_PAD
;
5263 req
.flags
= cpu_to_le16(flags
);
5266 case HWRM_RING_ALLOC_AGG
:
5267 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5268 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX_AGG
;
5269 /* Association of agg ring with rx ring */
5270 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
5271 req
.rx_ring_id
= cpu_to_le16(grp_info
->rx_fw_ring_id
);
5272 req
.rx_buf_size
= cpu_to_le16(BNXT_RX_PAGE_SIZE
);
5273 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
5274 req
.enables
|= cpu_to_le32(
5275 RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID
|
5276 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
5278 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
5280 req
.length
= cpu_to_le32(bp
->rx_agg_ring_mask
+ 1);
5282 case HWRM_RING_ALLOC_CMPL
:
5283 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_L2_CMPL
;
5284 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
5285 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5286 /* Association of cp ring with nq */
5287 grp_info
= &bp
->grp_info
[map_index
];
5288 req
.nq_ring_id
= cpu_to_le16(grp_info
->cp_fw_ring_id
);
5289 req
.cq_handle
= cpu_to_le64(ring
->handle
);
5290 req
.enables
|= cpu_to_le32(
5291 RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID
);
5292 } else if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
5293 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
5296 case HWRM_RING_ALLOC_NQ
:
5297 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_NQ
;
5298 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
5299 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
5300 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
5303 netdev_err(bp
->dev
, "hwrm alloc invalid ring type %d\n",
5308 mutex_lock(&bp
->hwrm_cmd_lock
);
5309 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5310 err
= le16_to_cpu(resp
->error_code
);
5311 ring_id
= le16_to_cpu(resp
->ring_id
);
5312 mutex_unlock(&bp
->hwrm_cmd_lock
);
5315 netdev_err(bp
->dev
, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
5316 ring_type
, rc
, err
);
5319 ring
->fw_ring_id
= ring_id
;
5323 static int bnxt_hwrm_set_async_event_cr(struct bnxt
*bp
, int idx
)
5328 struct hwrm_func_cfg_input req
= {0};
5330 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
5331 req
.fid
= cpu_to_le16(0xffff);
5332 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
5333 req
.async_event_cr
= cpu_to_le16(idx
);
5334 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5336 struct hwrm_func_vf_cfg_input req
= {0};
5338 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_VF_CFG
, -1, -1);
5340 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
5341 req
.async_event_cr
= cpu_to_le16(idx
);
5342 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5347 static void bnxt_set_db(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 ring_type
,
5348 u32 map_idx
, u32 xid
)
5350 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5352 db
->doorbell
= bp
->bar1
+ 0x10000;
5354 db
->doorbell
= bp
->bar1
+ 0x4000;
5355 switch (ring_type
) {
5356 case HWRM_RING_ALLOC_TX
:
5357 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SQ
;
5359 case HWRM_RING_ALLOC_RX
:
5360 case HWRM_RING_ALLOC_AGG
:
5361 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SRQ
;
5363 case HWRM_RING_ALLOC_CMPL
:
5364 db
->db_key64
= DBR_PATH_L2
;
5366 case HWRM_RING_ALLOC_NQ
:
5367 db
->db_key64
= DBR_PATH_L2
;
5370 db
->db_key64
|= (u64
)xid
<< DBR_XID_SFT
;
5372 db
->doorbell
= bp
->bar1
+ map_idx
* 0x80;
5373 switch (ring_type
) {
5374 case HWRM_RING_ALLOC_TX
:
5375 db
->db_key32
= DB_KEY_TX
;
5377 case HWRM_RING_ALLOC_RX
:
5378 case HWRM_RING_ALLOC_AGG
:
5379 db
->db_key32
= DB_KEY_RX
;
5381 case HWRM_RING_ALLOC_CMPL
:
5382 db
->db_key32
= DB_KEY_CP
;
5388 static int bnxt_hwrm_ring_alloc(struct bnxt
*bp
)
5390 bool agg_rings
= !!(bp
->flags
& BNXT_FLAG_AGG_RINGS
);
5394 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5395 type
= HWRM_RING_ALLOC_NQ
;
5397 type
= HWRM_RING_ALLOC_CMPL
;
5398 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5399 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5400 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5401 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
5402 u32 map_idx
= ring
->map_idx
;
5403 unsigned int vector
;
5405 vector
= bp
->irq_tbl
[map_idx
].vector
;
5406 disable_irq_nosync(vector
);
5407 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5412 bnxt_set_db(bp
, &cpr
->cp_db
, type
, map_idx
, ring
->fw_ring_id
);
5413 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
5415 bp
->grp_info
[i
].cp_fw_ring_id
= ring
->fw_ring_id
;
5418 rc
= bnxt_hwrm_set_async_event_cr(bp
, ring
->fw_ring_id
);
5420 netdev_warn(bp
->dev
, "Failed to set async event completion ring.\n");
5424 type
= HWRM_RING_ALLOC_TX
;
5425 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5426 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5427 struct bnxt_ring_struct
*ring
;
5430 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5431 struct bnxt_napi
*bnapi
= txr
->bnapi
;
5432 struct bnxt_cp_ring_info
*cpr
, *cpr2
;
5433 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5435 cpr
= &bnapi
->cp_ring
;
5436 cpr2
= cpr
->cp_ring_arr
[BNXT_TX_HDL
];
5437 ring
= &cpr2
->cp_ring_struct
;
5438 ring
->handle
= BNXT_TX_HDL
;
5439 map_idx
= bnapi
->index
;
5440 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5443 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5445 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5447 ring
= &txr
->tx_ring_struct
;
5449 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5452 bnxt_set_db(bp
, &txr
->tx_db
, type
, map_idx
, ring
->fw_ring_id
);
5455 type
= HWRM_RING_ALLOC_RX
;
5456 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5457 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5458 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5459 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
5460 u32 map_idx
= bnapi
->index
;
5462 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5465 bnxt_set_db(bp
, &rxr
->rx_db
, type
, map_idx
, ring
->fw_ring_id
);
5466 /* If we have agg rings, post agg buffers first. */
5468 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
5469 bp
->grp_info
[map_idx
].rx_fw_ring_id
= ring
->fw_ring_id
;
5470 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5471 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5472 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5473 struct bnxt_cp_ring_info
*cpr2
;
5475 cpr2
= cpr
->cp_ring_arr
[BNXT_RX_HDL
];
5476 ring
= &cpr2
->cp_ring_struct
;
5477 ring
->handle
= BNXT_RX_HDL
;
5478 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5481 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5483 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5488 type
= HWRM_RING_ALLOC_AGG
;
5489 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5490 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5491 struct bnxt_ring_struct
*ring
=
5492 &rxr
->rx_agg_ring_struct
;
5493 u32 grp_idx
= ring
->grp_idx
;
5494 u32 map_idx
= grp_idx
+ bp
->rx_nr_rings
;
5496 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5500 bnxt_set_db(bp
, &rxr
->rx_agg_db
, type
, map_idx
,
5502 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
5503 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
5504 bp
->grp_info
[grp_idx
].agg_fw_ring_id
= ring
->fw_ring_id
;
5511 static int hwrm_ring_free_send_msg(struct bnxt
*bp
,
5512 struct bnxt_ring_struct
*ring
,
5513 u32 ring_type
, int cmpl_ring_id
)
5516 struct hwrm_ring_free_input req
= {0};
5517 struct hwrm_ring_free_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5520 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
5523 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_FREE
, cmpl_ring_id
, -1);
5524 req
.ring_type
= ring_type
;
5525 req
.ring_id
= cpu_to_le16(ring
->fw_ring_id
);
5527 mutex_lock(&bp
->hwrm_cmd_lock
);
5528 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5529 error_code
= le16_to_cpu(resp
->error_code
);
5530 mutex_unlock(&bp
->hwrm_cmd_lock
);
5532 if (rc
|| error_code
) {
5533 netdev_err(bp
->dev
, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
5534 ring_type
, rc
, error_code
);
5540 static void bnxt_hwrm_ring_free(struct bnxt
*bp
, bool close_path
)
5548 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5549 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5550 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
5552 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5553 u32 cmpl_ring_id
= bnxt_cp_ring_for_tx(bp
, txr
);
5555 hwrm_ring_free_send_msg(bp
, ring
,
5556 RING_FREE_REQ_RING_TYPE_TX
,
5557 close_path
? cmpl_ring_id
:
5558 INVALID_HW_RING_ID
);
5559 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5563 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5564 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5565 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5566 u32 grp_idx
= rxr
->bnapi
->index
;
5568 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5569 u32 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5571 hwrm_ring_free_send_msg(bp
, ring
,
5572 RING_FREE_REQ_RING_TYPE_RX
,
5573 close_path
? cmpl_ring_id
:
5574 INVALID_HW_RING_ID
);
5575 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5576 bp
->grp_info
[grp_idx
].rx_fw_ring_id
=
5581 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5582 type
= RING_FREE_REQ_RING_TYPE_RX_AGG
;
5584 type
= RING_FREE_REQ_RING_TYPE_RX
;
5585 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5586 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5587 struct bnxt_ring_struct
*ring
= &rxr
->rx_agg_ring_struct
;
5588 u32 grp_idx
= rxr
->bnapi
->index
;
5590 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5591 u32 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5593 hwrm_ring_free_send_msg(bp
, ring
, type
,
5594 close_path
? cmpl_ring_id
:
5595 INVALID_HW_RING_ID
);
5596 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5597 bp
->grp_info
[grp_idx
].agg_fw_ring_id
=
5602 /* The completion rings are about to be freed. After that the
5603 * IRQ doorbell will not work anymore. So we need to disable
5606 bnxt_disable_int_sync(bp
);
5608 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5609 type
= RING_FREE_REQ_RING_TYPE_NQ
;
5611 type
= RING_FREE_REQ_RING_TYPE_L2_CMPL
;
5612 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5613 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5614 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5615 struct bnxt_ring_struct
*ring
;
5618 for (j
= 0; j
< 2; j
++) {
5619 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
5622 ring
= &cpr2
->cp_ring_struct
;
5623 if (ring
->fw_ring_id
== INVALID_HW_RING_ID
)
5625 hwrm_ring_free_send_msg(bp
, ring
,
5626 RING_FREE_REQ_RING_TYPE_L2_CMPL
,
5627 INVALID_HW_RING_ID
);
5628 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5631 ring
= &cpr
->cp_ring_struct
;
5632 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5633 hwrm_ring_free_send_msg(bp
, ring
, type
,
5634 INVALID_HW_RING_ID
);
5635 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5636 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
5641 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
5644 static int bnxt_hwrm_get_rings(struct bnxt
*bp
)
5646 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5647 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5648 struct hwrm_func_qcfg_input req
= {0};
5651 if (bp
->hwrm_spec_code
< 0x10601)
5654 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5655 req
.fid
= cpu_to_le16(0xffff);
5656 mutex_lock(&bp
->hwrm_cmd_lock
);
5657 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5659 mutex_unlock(&bp
->hwrm_cmd_lock
);
5663 hw_resc
->resv_tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
5664 if (BNXT_NEW_RM(bp
)) {
5667 hw_resc
->resv_rx_rings
= le16_to_cpu(resp
->alloc_rx_rings
);
5668 hw_resc
->resv_hw_ring_grps
=
5669 le32_to_cpu(resp
->alloc_hw_ring_grps
);
5670 hw_resc
->resv_vnics
= le16_to_cpu(resp
->alloc_vnics
);
5671 cp
= le16_to_cpu(resp
->alloc_cmpl_rings
);
5672 stats
= le16_to_cpu(resp
->alloc_stat_ctx
);
5673 hw_resc
->resv_irqs
= cp
;
5674 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5675 int rx
= hw_resc
->resv_rx_rings
;
5676 int tx
= hw_resc
->resv_tx_rings
;
5678 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5680 if (cp
< (rx
+ tx
)) {
5681 bnxt_trim_rings(bp
, &rx
, &tx
, cp
, false);
5682 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5684 hw_resc
->resv_rx_rings
= rx
;
5685 hw_resc
->resv_tx_rings
= tx
;
5687 hw_resc
->resv_irqs
= le16_to_cpu(resp
->alloc_msix
);
5688 hw_resc
->resv_hw_ring_grps
= rx
;
5690 hw_resc
->resv_cp_rings
= cp
;
5691 hw_resc
->resv_stat_ctxs
= stats
;
5693 mutex_unlock(&bp
->hwrm_cmd_lock
);
5697 /* Caller must hold bp->hwrm_cmd_lock */
5698 int __bnxt_hwrm_get_tx_rings(struct bnxt
*bp
, u16 fid
, int *tx_rings
)
5700 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5701 struct hwrm_func_qcfg_input req
= {0};
5704 if (bp
->hwrm_spec_code
< 0x10601)
5707 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5708 req
.fid
= cpu_to_le16(fid
);
5709 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5711 *tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
5716 static bool bnxt_rfs_supported(struct bnxt
*bp
);
5719 __bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, struct hwrm_func_cfg_input
*req
,
5720 int tx_rings
, int rx_rings
, int ring_grps
,
5721 int cp_rings
, int stats
, int vnics
)
5725 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_CFG
, -1, -1);
5726 req
->fid
= cpu_to_le16(0xffff);
5727 enables
|= tx_rings
? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
5728 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
5729 if (BNXT_NEW_RM(bp
)) {
5730 enables
|= rx_rings
? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS
: 0;
5731 enables
|= stats
? FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5732 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5733 enables
|= cp_rings
? FUNC_CFG_REQ_ENABLES_NUM_MSIX
: 0;
5734 enables
|= tx_rings
+ ring_grps
?
5735 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
5736 enables
|= rx_rings
?
5737 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5739 enables
|= cp_rings
?
5740 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
5741 enables
|= ring_grps
?
5742 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
|
5743 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5745 enables
|= vnics
? FUNC_CFG_REQ_ENABLES_NUM_VNICS
: 0;
5747 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
5748 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5749 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
5750 req
->num_msix
= cpu_to_le16(cp_rings
);
5751 req
->num_rsscos_ctxs
=
5752 cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
5754 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
5755 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
5756 req
->num_rsscos_ctxs
= cpu_to_le16(1);
5757 if (!(bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
5758 bnxt_rfs_supported(bp
))
5759 req
->num_rsscos_ctxs
=
5760 cpu_to_le16(ring_grps
+ 1);
5762 req
->num_stat_ctxs
= cpu_to_le16(stats
);
5763 req
->num_vnics
= cpu_to_le16(vnics
);
5765 req
->enables
= cpu_to_le32(enables
);
5769 __bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
,
5770 struct hwrm_func_vf_cfg_input
*req
, int tx_rings
,
5771 int rx_rings
, int ring_grps
, int cp_rings
,
5772 int stats
, int vnics
)
5776 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_VF_CFG
, -1, -1);
5777 enables
|= tx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
5778 enables
|= rx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS
|
5779 FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5780 enables
|= stats
? FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5781 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5782 enables
|= tx_rings
+ ring_grps
?
5783 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
5785 enables
|= cp_rings
?
5786 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
: 0;
5787 enables
|= ring_grps
?
5788 FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
: 0;
5790 enables
|= vnics
? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS
: 0;
5791 enables
|= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS
;
5793 req
->num_l2_ctxs
= cpu_to_le16(BNXT_VF_MAX_L2_CTX
);
5794 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
5795 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
5796 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5797 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
5798 req
->num_rsscos_ctxs
= cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
5800 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
5801 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
5802 req
->num_rsscos_ctxs
= cpu_to_le16(BNXT_VF_MAX_RSS_CTX
);
5804 req
->num_stat_ctxs
= cpu_to_le16(stats
);
5805 req
->num_vnics
= cpu_to_le16(vnics
);
5807 req
->enables
= cpu_to_le32(enables
);
5811 bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5812 int ring_grps
, int cp_rings
, int stats
, int vnics
)
5814 struct hwrm_func_cfg_input req
= {0};
5817 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5818 cp_rings
, stats
, vnics
);
5822 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5826 if (bp
->hwrm_spec_code
< 0x10601)
5827 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
5829 rc
= bnxt_hwrm_get_rings(bp
);
5834 bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5835 int ring_grps
, int cp_rings
, int stats
, int vnics
)
5837 struct hwrm_func_vf_cfg_input req
= {0};
5840 if (!BNXT_NEW_RM(bp
)) {
5841 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
5845 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5846 cp_rings
, stats
, vnics
);
5847 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5851 rc
= bnxt_hwrm_get_rings(bp
);
5855 static int bnxt_hwrm_reserve_rings(struct bnxt
*bp
, int tx
, int rx
, int grp
,
5856 int cp
, int stat
, int vnic
)
5859 return bnxt_hwrm_reserve_pf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
5862 return bnxt_hwrm_reserve_vf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
5866 int bnxt_nq_rings_in_use(struct bnxt
*bp
)
5868 int cp
= bp
->cp_nr_rings
;
5869 int ulp_msix
, ulp_base
;
5871 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
5873 ulp_base
= bnxt_get_ulp_msix_base(bp
);
5875 if ((ulp_base
+ ulp_msix
) > cp
)
5876 cp
= ulp_base
+ ulp_msix
;
5881 static int bnxt_cp_rings_in_use(struct bnxt
*bp
)
5885 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5886 return bnxt_nq_rings_in_use(bp
);
5888 cp
= bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
5892 static int bnxt_get_func_stat_ctxs(struct bnxt
*bp
)
5894 int ulp_stat
= bnxt_get_ulp_stat_ctxs(bp
);
5895 int cp
= bp
->cp_nr_rings
;
5900 if (bnxt_nq_rings_in_use(bp
) > cp
+ bnxt_get_ulp_msix_num(bp
))
5901 return bnxt_get_ulp_msix_base(bp
) + ulp_stat
;
5903 return cp
+ ulp_stat
;
5906 static bool bnxt_need_reserve_rings(struct bnxt
*bp
)
5908 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5909 int cp
= bnxt_cp_rings_in_use(bp
);
5910 int nq
= bnxt_nq_rings_in_use(bp
);
5911 int rx
= bp
->rx_nr_rings
, stat
;
5912 int vnic
= 1, grp
= rx
;
5914 if (bp
->hwrm_spec_code
< 0x10601)
5917 if (hw_resc
->resv_tx_rings
!= bp
->tx_nr_rings
)
5920 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5922 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5924 stat
= bnxt_get_func_stat_ctxs(bp
);
5925 if (BNXT_NEW_RM(bp
) &&
5926 (hw_resc
->resv_rx_rings
!= rx
|| hw_resc
->resv_cp_rings
!= cp
||
5927 hw_resc
->resv_vnics
!= vnic
|| hw_resc
->resv_stat_ctxs
!= stat
||
5928 (hw_resc
->resv_hw_ring_grps
!= grp
&&
5929 !(bp
->flags
& BNXT_FLAG_CHIP_P5
))))
5931 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && BNXT_PF(bp
) &&
5932 hw_resc
->resv_irqs
!= nq
)
5937 static int __bnxt_reserve_rings(struct bnxt
*bp
)
5939 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5940 int cp
= bnxt_nq_rings_in_use(bp
);
5941 int tx
= bp
->tx_nr_rings
;
5942 int rx
= bp
->rx_nr_rings
;
5943 int grp
, rx_rings
, rc
;
5947 if (!bnxt_need_reserve_rings(bp
))
5950 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
5952 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5954 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5956 grp
= bp
->rx_nr_rings
;
5957 stat
= bnxt_get_func_stat_ctxs(bp
);
5959 rc
= bnxt_hwrm_reserve_rings(bp
, tx
, rx
, grp
, cp
, stat
, vnic
);
5963 tx
= hw_resc
->resv_tx_rings
;
5964 if (BNXT_NEW_RM(bp
)) {
5965 rx
= hw_resc
->resv_rx_rings
;
5966 cp
= hw_resc
->resv_irqs
;
5967 grp
= hw_resc
->resv_hw_ring_grps
;
5968 vnic
= hw_resc
->resv_vnics
;
5969 stat
= hw_resc
->resv_stat_ctxs
;
5973 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
5977 if (netif_running(bp
->dev
))
5980 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
5981 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
5982 bp
->dev
->hw_features
&= ~NETIF_F_LRO
;
5983 bp
->dev
->features
&= ~NETIF_F_LRO
;
5984 bnxt_set_ring_params(bp
);
5987 rx_rings
= min_t(int, rx_rings
, grp
);
5988 cp
= min_t(int, cp
, bp
->cp_nr_rings
);
5989 if (stat
> bnxt_get_ulp_stat_ctxs(bp
))
5990 stat
-= bnxt_get_ulp_stat_ctxs(bp
);
5991 cp
= min_t(int, cp
, stat
);
5992 rc
= bnxt_trim_rings(bp
, &rx_rings
, &tx
, cp
, sh
);
5993 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5995 cp
= sh
? max_t(int, tx
, rx_rings
) : tx
+ rx_rings
;
5996 bp
->tx_nr_rings
= tx
;
5997 bp
->rx_nr_rings
= rx_rings
;
5998 bp
->cp_nr_rings
= cp
;
6000 if (!tx
|| !rx
|| !cp
|| !grp
|| !vnic
|| !stat
)
6006 static int bnxt_hwrm_check_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6007 int ring_grps
, int cp_rings
, int stats
,
6010 struct hwrm_func_vf_cfg_input req
= {0};
6014 if (!BNXT_NEW_RM(bp
))
6017 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6018 cp_rings
, stats
, vnics
);
6019 flags
= FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST
|
6020 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
6021 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
6022 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
6023 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
|
6024 FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
;
6025 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6026 flags
|= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
6028 req
.flags
= cpu_to_le32(flags
);
6029 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6033 static int bnxt_hwrm_check_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6034 int ring_grps
, int cp_rings
, int stats
,
6037 struct hwrm_func_cfg_input req
= {0};
6041 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
6042 cp_rings
, stats
, vnics
);
6043 flags
= FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST
;
6044 if (BNXT_NEW_RM(bp
)) {
6045 flags
|= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
6046 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
6047 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
6048 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
;
6049 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
6050 flags
|= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
|
6051 FUNC_CFG_REQ_FLAGS_NQ_ASSETS_TEST
;
6053 flags
|= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
6056 req
.flags
= cpu_to_le32(flags
);
6057 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6061 static int bnxt_hwrm_check_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
6062 int ring_grps
, int cp_rings
, int stats
,
6065 if (bp
->hwrm_spec_code
< 0x10801)
6069 return bnxt_hwrm_check_pf_rings(bp
, tx_rings
, rx_rings
,
6070 ring_grps
, cp_rings
, stats
,
6073 return bnxt_hwrm_check_vf_rings(bp
, tx_rings
, rx_rings
, ring_grps
,
6074 cp_rings
, stats
, vnics
);
6077 static void bnxt_hwrm_coal_params_qcaps(struct bnxt
*bp
)
6079 struct hwrm_ring_aggint_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6080 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6081 struct hwrm_ring_aggint_qcaps_input req
= {0};
6084 coal_cap
->cmpl_params
= BNXT_LEGACY_COAL_CMPL_PARAMS
;
6085 coal_cap
->num_cmpl_dma_aggr_max
= 63;
6086 coal_cap
->num_cmpl_dma_aggr_during_int_max
= 63;
6087 coal_cap
->cmpl_aggr_dma_tmr_max
= 65535;
6088 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
= 65535;
6089 coal_cap
->int_lat_tmr_min_max
= 65535;
6090 coal_cap
->int_lat_tmr_max_max
= 65535;
6091 coal_cap
->num_cmpl_aggr_int_max
= 65535;
6092 coal_cap
->timer_units
= 80;
6094 if (bp
->hwrm_spec_code
< 0x10902)
6097 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_AGGINT_QCAPS
, -1, -1);
6098 mutex_lock(&bp
->hwrm_cmd_lock
);
6099 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6101 coal_cap
->cmpl_params
= le32_to_cpu(resp
->cmpl_params
);
6102 coal_cap
->nq_params
= le32_to_cpu(resp
->nq_params
);
6103 coal_cap
->num_cmpl_dma_aggr_max
=
6104 le16_to_cpu(resp
->num_cmpl_dma_aggr_max
);
6105 coal_cap
->num_cmpl_dma_aggr_during_int_max
=
6106 le16_to_cpu(resp
->num_cmpl_dma_aggr_during_int_max
);
6107 coal_cap
->cmpl_aggr_dma_tmr_max
=
6108 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_max
);
6109 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
=
6110 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_during_int_max
);
6111 coal_cap
->int_lat_tmr_min_max
=
6112 le16_to_cpu(resp
->int_lat_tmr_min_max
);
6113 coal_cap
->int_lat_tmr_max_max
=
6114 le16_to_cpu(resp
->int_lat_tmr_max_max
);
6115 coal_cap
->num_cmpl_aggr_int_max
=
6116 le16_to_cpu(resp
->num_cmpl_aggr_int_max
);
6117 coal_cap
->timer_units
= le16_to_cpu(resp
->timer_units
);
6119 mutex_unlock(&bp
->hwrm_cmd_lock
);
6122 static u16
bnxt_usec_to_coal_tmr(struct bnxt
*bp
, u16 usec
)
6124 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6126 return usec
* 1000 / coal_cap
->timer_units
;
6129 static void bnxt_hwrm_set_coal_params(struct bnxt
*bp
,
6130 struct bnxt_coal
*hw_coal
,
6131 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input
*req
)
6133 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6134 u32 cmpl_params
= coal_cap
->cmpl_params
;
6135 u16 val
, tmr
, max
, flags
= 0;
6137 max
= hw_coal
->bufs_per_record
* 128;
6138 if (hw_coal
->budget
)
6139 max
= hw_coal
->bufs_per_record
* hw_coal
->budget
;
6140 max
= min_t(u16
, max
, coal_cap
->num_cmpl_aggr_int_max
);
6142 val
= clamp_t(u16
, hw_coal
->coal_bufs
, 1, max
);
6143 req
->num_cmpl_aggr_int
= cpu_to_le16(val
);
6145 val
= min_t(u16
, val
, coal_cap
->num_cmpl_dma_aggr_max
);
6146 req
->num_cmpl_dma_aggr
= cpu_to_le16(val
);
6148 val
= clamp_t(u16
, hw_coal
->coal_bufs_irq
, 1,
6149 coal_cap
->num_cmpl_dma_aggr_during_int_max
);
6150 req
->num_cmpl_dma_aggr_during_int
= cpu_to_le16(val
);
6152 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
);
6153 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_max_max
);
6154 req
->int_lat_tmr_max
= cpu_to_le16(tmr
);
6156 /* min timer set to 1/2 of interrupt timer */
6157 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN
) {
6159 val
= clamp_t(u16
, val
, 1, coal_cap
->int_lat_tmr_min_max
);
6160 req
->int_lat_tmr_min
= cpu_to_le16(val
);
6161 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
6164 /* buf timer set to 1/4 of interrupt timer */
6165 val
= clamp_t(u16
, tmr
/ 4, 1, coal_cap
->cmpl_aggr_dma_tmr_max
);
6166 req
->cmpl_aggr_dma_tmr
= cpu_to_le16(val
);
6169 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT
) {
6170 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks_irq
);
6171 val
= clamp_t(u16
, tmr
, 1,
6172 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
);
6173 req
->cmpl_aggr_dma_tmr_during_int
= cpu_to_le16(tmr
);
6175 cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE
);
6178 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET
)
6179 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
6180 if ((cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE
) &&
6181 hw_coal
->idle_thresh
&& hw_coal
->coal_ticks
< hw_coal
->idle_thresh
)
6182 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE
;
6183 req
->flags
= cpu_to_le16(flags
);
6184 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_ENABLES
);
6187 /* Caller holds bp->hwrm_cmd_lock */
6188 static int __bnxt_hwrm_set_coal_nq(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
6189 struct bnxt_coal
*hw_coal
)
6191 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req
= {0};
6192 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6193 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
6194 u32 nq_params
= coal_cap
->nq_params
;
6197 if (!(nq_params
& RING_AGGINT_QCAPS_RESP_NQ_PARAMS_INT_LAT_TMR_MIN
))
6200 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
,
6202 req
.ring_id
= cpu_to_le16(cpr
->cp_ring_struct
.fw_ring_id
);
6204 cpu_to_le16(RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_IS_NQ
);
6206 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
) / 2;
6207 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_min_max
);
6208 req
.int_lat_tmr_min
= cpu_to_le16(tmr
);
6209 req
.enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
6210 return _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6213 int bnxt_hwrm_set_ring_coal(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
6215 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0};
6216 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6217 struct bnxt_coal coal
;
6219 /* Tick values in micro seconds.
6220 * 1 coal_buf x bufs_per_record = 1 completion record.
6222 memcpy(&coal
, &bp
->rx_coal
, sizeof(struct bnxt_coal
));
6224 coal
.coal_ticks
= cpr
->rx_ring_coal
.coal_ticks
;
6225 coal
.coal_bufs
= cpr
->rx_ring_coal
.coal_bufs
;
6227 if (!bnapi
->rx_ring
)
6230 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
6231 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6233 bnxt_hwrm_set_coal_params(bp
, &coal
, &req_rx
);
6235 req_rx
.ring_id
= cpu_to_le16(bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
));
6237 return hwrm_send_message(bp
, &req_rx
, sizeof(req_rx
),
6241 int bnxt_hwrm_set_coal(struct bnxt
*bp
)
6244 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0},
6247 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
6248 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6249 bnxt_hwrm_cmd_hdr_init(bp
, &req_tx
,
6250 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
6252 bnxt_hwrm_set_coal_params(bp
, &bp
->rx_coal
, &req_rx
);
6253 bnxt_hwrm_set_coal_params(bp
, &bp
->tx_coal
, &req_tx
);
6255 mutex_lock(&bp
->hwrm_cmd_lock
);
6256 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6257 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6258 struct bnxt_coal
*hw_coal
;
6262 if (!bnapi
->rx_ring
) {
6263 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
6266 ring_id
= bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
);
6268 req
->ring_id
= cpu_to_le16(ring_id
);
6270 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
6275 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
6278 if (bnapi
->rx_ring
&& bnapi
->tx_ring
) {
6280 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
6281 req
->ring_id
= cpu_to_le16(ring_id
);
6282 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
6288 hw_coal
= &bp
->rx_coal
;
6290 hw_coal
= &bp
->tx_coal
;
6291 __bnxt_hwrm_set_coal_nq(bp
, bnapi
, hw_coal
);
6293 mutex_unlock(&bp
->hwrm_cmd_lock
);
6297 static int bnxt_hwrm_stat_ctx_free(struct bnxt
*bp
)
6300 struct hwrm_stat_ctx_free_input req
= {0};
6305 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6308 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_FREE
, -1, -1);
6310 mutex_lock(&bp
->hwrm_cmd_lock
);
6311 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6312 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6313 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6315 if (cpr
->hw_stats_ctx_id
!= INVALID_STATS_CTX_ID
) {
6316 req
.stat_ctx_id
= cpu_to_le32(cpr
->hw_stats_ctx_id
);
6318 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
6321 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
6324 mutex_unlock(&bp
->hwrm_cmd_lock
);
6328 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt
*bp
)
6331 struct hwrm_stat_ctx_alloc_input req
= {0};
6332 struct hwrm_stat_ctx_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6334 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
6337 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_ALLOC
, -1, -1);
6339 req
.stats_dma_length
= cpu_to_le16(bp
->hw_ring_stats_size
);
6340 req
.update_period_ms
= cpu_to_le32(bp
->stats_coal_ticks
/ 1000);
6342 mutex_lock(&bp
->hwrm_cmd_lock
);
6343 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
6344 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
6345 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
6347 req
.stats_dma_addr
= cpu_to_le64(cpr
->hw_stats_map
);
6349 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
6354 cpr
->hw_stats_ctx_id
= le32_to_cpu(resp
->stat_ctx_id
);
6356 bp
->grp_info
[i
].fw_stats_ctx
= cpr
->hw_stats_ctx_id
;
6358 mutex_unlock(&bp
->hwrm_cmd_lock
);
6362 static int bnxt_hwrm_func_qcfg(struct bnxt
*bp
)
6364 struct hwrm_func_qcfg_input req
= {0};
6365 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6369 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
6370 req
.fid
= cpu_to_le16(0xffff);
6371 mutex_lock(&bp
->hwrm_cmd_lock
);
6372 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6374 goto func_qcfg_exit
;
6376 #ifdef CONFIG_BNXT_SRIOV
6378 struct bnxt_vf_info
*vf
= &bp
->vf
;
6380 vf
->vlan
= le16_to_cpu(resp
->vlan
) & VLAN_VID_MASK
;
6382 bp
->pf
.registered_vfs
= le16_to_cpu(resp
->registered_vfs
);
6385 flags
= le16_to_cpu(resp
->flags
);
6386 if (flags
& (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
|
6387 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED
)) {
6388 bp
->fw_cap
|= BNXT_FW_CAP_LLDP_AGENT
;
6389 if (flags
& FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
)
6390 bp
->fw_cap
|= BNXT_FW_CAP_DCBX_AGENT
;
6392 if (BNXT_PF(bp
) && (flags
& FUNC_QCFG_RESP_FLAGS_MULTI_HOST
))
6393 bp
->flags
|= BNXT_FLAG_MULTI_HOST
;
6395 switch (resp
->port_partition_type
) {
6396 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0
:
6397 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5
:
6398 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0
:
6399 bp
->port_partition_type
= resp
->port_partition_type
;
6402 if (bp
->hwrm_spec_code
< 0x10707 ||
6403 resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEB
)
6404 bp
->br_mode
= BRIDGE_MODE_VEB
;
6405 else if (resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEPA
)
6406 bp
->br_mode
= BRIDGE_MODE_VEPA
;
6408 bp
->br_mode
= BRIDGE_MODE_UNDEF
;
6410 bp
->max_mtu
= le16_to_cpu(resp
->max_mtu_configured
);
6412 bp
->max_mtu
= BNXT_MAX_MTU
;
6415 mutex_unlock(&bp
->hwrm_cmd_lock
);
6419 static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt
*bp
)
6421 struct hwrm_func_backing_store_qcaps_input req
= {0};
6422 struct hwrm_func_backing_store_qcaps_output
*resp
=
6423 bp
->hwrm_cmd_resp_addr
;
6426 if (bp
->hwrm_spec_code
< 0x10902 || BNXT_VF(bp
) || bp
->ctx
)
6429 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_QCAPS
, -1, -1);
6430 mutex_lock(&bp
->hwrm_cmd_lock
);
6431 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6433 struct bnxt_ctx_pg_info
*ctx_pg
;
6434 struct bnxt_ctx_mem_info
*ctx
;
6437 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
6442 ctx_pg
= kzalloc(sizeof(*ctx_pg
) * (bp
->max_q
+ 1), GFP_KERNEL
);
6448 for (i
= 0; i
< bp
->max_q
+ 1; i
++, ctx_pg
++)
6449 ctx
->tqm_mem
[i
] = ctx_pg
;
6452 ctx
->qp_max_entries
= le32_to_cpu(resp
->qp_max_entries
);
6453 ctx
->qp_min_qp1_entries
= le16_to_cpu(resp
->qp_min_qp1_entries
);
6454 ctx
->qp_max_l2_entries
= le16_to_cpu(resp
->qp_max_l2_entries
);
6455 ctx
->qp_entry_size
= le16_to_cpu(resp
->qp_entry_size
);
6456 ctx
->srq_max_l2_entries
= le16_to_cpu(resp
->srq_max_l2_entries
);
6457 ctx
->srq_max_entries
= le32_to_cpu(resp
->srq_max_entries
);
6458 ctx
->srq_entry_size
= le16_to_cpu(resp
->srq_entry_size
);
6459 ctx
->cq_max_l2_entries
= le16_to_cpu(resp
->cq_max_l2_entries
);
6460 ctx
->cq_max_entries
= le32_to_cpu(resp
->cq_max_entries
);
6461 ctx
->cq_entry_size
= le16_to_cpu(resp
->cq_entry_size
);
6462 ctx
->vnic_max_vnic_entries
=
6463 le16_to_cpu(resp
->vnic_max_vnic_entries
);
6464 ctx
->vnic_max_ring_table_entries
=
6465 le16_to_cpu(resp
->vnic_max_ring_table_entries
);
6466 ctx
->vnic_entry_size
= le16_to_cpu(resp
->vnic_entry_size
);
6467 ctx
->stat_max_entries
= le32_to_cpu(resp
->stat_max_entries
);
6468 ctx
->stat_entry_size
= le16_to_cpu(resp
->stat_entry_size
);
6469 ctx
->tqm_entry_size
= le16_to_cpu(resp
->tqm_entry_size
);
6470 ctx
->tqm_min_entries_per_ring
=
6471 le32_to_cpu(resp
->tqm_min_entries_per_ring
);
6472 ctx
->tqm_max_entries_per_ring
=
6473 le32_to_cpu(resp
->tqm_max_entries_per_ring
);
6474 ctx
->tqm_entries_multiple
= resp
->tqm_entries_multiple
;
6475 if (!ctx
->tqm_entries_multiple
)
6476 ctx
->tqm_entries_multiple
= 1;
6477 ctx
->mrav_max_entries
= le32_to_cpu(resp
->mrav_max_entries
);
6478 ctx
->mrav_entry_size
= le16_to_cpu(resp
->mrav_entry_size
);
6479 ctx
->mrav_num_entries_units
=
6480 le16_to_cpu(resp
->mrav_num_entries_units
);
6481 ctx
->tim_entry_size
= le16_to_cpu(resp
->tim_entry_size
);
6482 ctx
->tim_max_entries
= le32_to_cpu(resp
->tim_max_entries
);
6487 mutex_unlock(&bp
->hwrm_cmd_lock
);
6491 static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info
*rmem
, u8
*pg_attr
,
6496 if (BNXT_PAGE_SHIFT
== 13)
6498 else if (BNXT_PAGE_SIZE
== 16)
6502 if (rmem
->depth
>= 1) {
6503 if (rmem
->depth
== 2)
6507 *pg_dir
= cpu_to_le64(rmem
->pg_tbl_map
);
6509 *pg_dir
= cpu_to_le64(rmem
->dma_arr
[0]);
6513 #define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \
6514 (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \
6515 FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \
6516 FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \
6517 FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \
6518 FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT)
6520 static int bnxt_hwrm_func_backing_store_cfg(struct bnxt
*bp
, u32 enables
)
6522 struct hwrm_func_backing_store_cfg_input req
= {0};
6523 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
6524 struct bnxt_ctx_pg_info
*ctx_pg
;
6525 __le32
*num_entries
;
6535 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_CFG
, -1, -1);
6536 req
.enables
= cpu_to_le32(enables
);
6538 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP
) {
6539 ctx_pg
= &ctx
->qp_mem
;
6540 req
.qp_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6541 req
.qp_num_qp1_entries
= cpu_to_le16(ctx
->qp_min_qp1_entries
);
6542 req
.qp_num_l2_entries
= cpu_to_le16(ctx
->qp_max_l2_entries
);
6543 req
.qp_entry_size
= cpu_to_le16(ctx
->qp_entry_size
);
6544 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6545 &req
.qpc_pg_size_qpc_lvl
,
6548 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ
) {
6549 ctx_pg
= &ctx
->srq_mem
;
6550 req
.srq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6551 req
.srq_num_l2_entries
= cpu_to_le16(ctx
->srq_max_l2_entries
);
6552 req
.srq_entry_size
= cpu_to_le16(ctx
->srq_entry_size
);
6553 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6554 &req
.srq_pg_size_srq_lvl
,
6557 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ
) {
6558 ctx_pg
= &ctx
->cq_mem
;
6559 req
.cq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6560 req
.cq_num_l2_entries
= cpu_to_le16(ctx
->cq_max_l2_entries
);
6561 req
.cq_entry_size
= cpu_to_le16(ctx
->cq_entry_size
);
6562 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, &req
.cq_pg_size_cq_lvl
,
6565 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC
) {
6566 ctx_pg
= &ctx
->vnic_mem
;
6567 req
.vnic_num_vnic_entries
=
6568 cpu_to_le16(ctx
->vnic_max_vnic_entries
);
6569 req
.vnic_num_ring_table_entries
=
6570 cpu_to_le16(ctx
->vnic_max_ring_table_entries
);
6571 req
.vnic_entry_size
= cpu_to_le16(ctx
->vnic_entry_size
);
6572 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6573 &req
.vnic_pg_size_vnic_lvl
,
6574 &req
.vnic_page_dir
);
6576 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT
) {
6577 ctx_pg
= &ctx
->stat_mem
;
6578 req
.stat_num_entries
= cpu_to_le32(ctx
->stat_max_entries
);
6579 req
.stat_entry_size
= cpu_to_le16(ctx
->stat_entry_size
);
6580 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6581 &req
.stat_pg_size_stat_lvl
,
6582 &req
.stat_page_dir
);
6584 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
) {
6585 ctx_pg
= &ctx
->mrav_mem
;
6586 req
.mrav_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6587 if (ctx
->mrav_num_entries_units
)
6589 FUNC_BACKING_STORE_CFG_REQ_FLAGS_MRAV_RESERVATION_SPLIT
;
6590 req
.mrav_entry_size
= cpu_to_le16(ctx
->mrav_entry_size
);
6591 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6592 &req
.mrav_pg_size_mrav_lvl
,
6593 &req
.mrav_page_dir
);
6595 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
) {
6596 ctx_pg
= &ctx
->tim_mem
;
6597 req
.tim_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6598 req
.tim_entry_size
= cpu_to_le16(ctx
->tim_entry_size
);
6599 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6600 &req
.tim_pg_size_tim_lvl
,
6603 for (i
= 0, num_entries
= &req
.tqm_sp_num_entries
,
6604 pg_attr
= &req
.tqm_sp_pg_size_tqm_sp_lvl
,
6605 pg_dir
= &req
.tqm_sp_page_dir
,
6606 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
;
6607 i
< 9; i
++, num_entries
++, pg_attr
++, pg_dir
++, ena
<<= 1) {
6608 if (!(enables
& ena
))
6611 req
.tqm_entry_size
= cpu_to_le16(ctx
->tqm_entry_size
);
6612 ctx_pg
= ctx
->tqm_mem
[i
];
6613 *num_entries
= cpu_to_le32(ctx_pg
->entries
);
6614 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, pg_attr
, pg_dir
);
6616 req
.flags
= cpu_to_le32(flags
);
6617 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6621 static int bnxt_alloc_ctx_mem_blk(struct bnxt
*bp
,
6622 struct bnxt_ctx_pg_info
*ctx_pg
)
6624 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6626 rmem
->page_size
= BNXT_PAGE_SIZE
;
6627 rmem
->pg_arr
= ctx_pg
->ctx_pg_arr
;
6628 rmem
->dma_arr
= ctx_pg
->ctx_dma_arr
;
6629 rmem
->flags
= BNXT_RMEM_VALID_PTE_FLAG
;
6630 if (rmem
->depth
>= 1)
6631 rmem
->flags
|= BNXT_RMEM_USE_FULL_PAGE_FLAG
;
6632 return bnxt_alloc_ring(bp
, rmem
);
6635 static int bnxt_alloc_ctx_pg_tbls(struct bnxt
*bp
,
6636 struct bnxt_ctx_pg_info
*ctx_pg
, u32 mem_size
,
6639 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6645 ctx_pg
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
6646 if (ctx_pg
->nr_pages
> MAX_CTX_TOTAL_PAGES
) {
6647 ctx_pg
->nr_pages
= 0;
6650 if (ctx_pg
->nr_pages
> MAX_CTX_PAGES
|| depth
> 1) {
6654 ctx_pg
->ctx_pg_tbl
= kcalloc(MAX_CTX_PAGES
, sizeof(ctx_pg
),
6656 if (!ctx_pg
->ctx_pg_tbl
)
6658 nr_tbls
= DIV_ROUND_UP(ctx_pg
->nr_pages
, MAX_CTX_PAGES
);
6659 rmem
->nr_pages
= nr_tbls
;
6660 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
6663 for (i
= 0; i
< nr_tbls
; i
++) {
6664 struct bnxt_ctx_pg_info
*pg_tbl
;
6666 pg_tbl
= kzalloc(sizeof(*pg_tbl
), GFP_KERNEL
);
6669 ctx_pg
->ctx_pg_tbl
[i
] = pg_tbl
;
6670 rmem
= &pg_tbl
->ring_mem
;
6671 rmem
->pg_tbl
= ctx_pg
->ctx_pg_arr
[i
];
6672 rmem
->pg_tbl_map
= ctx_pg
->ctx_dma_arr
[i
];
6674 rmem
->nr_pages
= MAX_CTX_PAGES
;
6675 if (i
== (nr_tbls
- 1)) {
6676 int rem
= ctx_pg
->nr_pages
% MAX_CTX_PAGES
;
6679 rmem
->nr_pages
= rem
;
6681 rc
= bnxt_alloc_ctx_mem_blk(bp
, pg_tbl
);
6686 rmem
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
6687 if (rmem
->nr_pages
> 1 || depth
)
6689 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
6694 static void bnxt_free_ctx_pg_tbls(struct bnxt
*bp
,
6695 struct bnxt_ctx_pg_info
*ctx_pg
)
6697 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6699 if (rmem
->depth
> 1 || ctx_pg
->nr_pages
> MAX_CTX_PAGES
||
6700 ctx_pg
->ctx_pg_tbl
) {
6701 int i
, nr_tbls
= rmem
->nr_pages
;
6703 for (i
= 0; i
< nr_tbls
; i
++) {
6704 struct bnxt_ctx_pg_info
*pg_tbl
;
6705 struct bnxt_ring_mem_info
*rmem2
;
6707 pg_tbl
= ctx_pg
->ctx_pg_tbl
[i
];
6710 rmem2
= &pg_tbl
->ring_mem
;
6711 bnxt_free_ring(bp
, rmem2
);
6712 ctx_pg
->ctx_pg_arr
[i
] = NULL
;
6714 ctx_pg
->ctx_pg_tbl
[i
] = NULL
;
6716 kfree(ctx_pg
->ctx_pg_tbl
);
6717 ctx_pg
->ctx_pg_tbl
= NULL
;
6719 bnxt_free_ring(bp
, rmem
);
6720 ctx_pg
->nr_pages
= 0;
6723 static void bnxt_free_ctx_mem(struct bnxt
*bp
)
6725 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
6731 if (ctx
->tqm_mem
[0]) {
6732 for (i
= 0; i
< bp
->max_q
+ 1; i
++)
6733 bnxt_free_ctx_pg_tbls(bp
, ctx
->tqm_mem
[i
]);
6734 kfree(ctx
->tqm_mem
[0]);
6735 ctx
->tqm_mem
[0] = NULL
;
6738 bnxt_free_ctx_pg_tbls(bp
, &ctx
->tim_mem
);
6739 bnxt_free_ctx_pg_tbls(bp
, &ctx
->mrav_mem
);
6740 bnxt_free_ctx_pg_tbls(bp
, &ctx
->stat_mem
);
6741 bnxt_free_ctx_pg_tbls(bp
, &ctx
->vnic_mem
);
6742 bnxt_free_ctx_pg_tbls(bp
, &ctx
->cq_mem
);
6743 bnxt_free_ctx_pg_tbls(bp
, &ctx
->srq_mem
);
6744 bnxt_free_ctx_pg_tbls(bp
, &ctx
->qp_mem
);
6745 ctx
->flags
&= ~BNXT_CTX_FLAG_INITED
;
6748 static int bnxt_alloc_ctx_mem(struct bnxt
*bp
)
6750 struct bnxt_ctx_pg_info
*ctx_pg
;
6751 struct bnxt_ctx_mem_info
*ctx
;
6752 u32 mem_size
, ena
, entries
;
6759 rc
= bnxt_hwrm_func_backing_store_qcaps(bp
);
6761 netdev_err(bp
->dev
, "Failed querying context mem capability, rc = %d.\n",
6766 if (!ctx
|| (ctx
->flags
& BNXT_CTX_FLAG_INITED
))
6769 if ((bp
->flags
& BNXT_FLAG_ROCE_CAP
) && !is_kdump_kernel()) {
6775 ctx_pg
= &ctx
->qp_mem
;
6776 ctx_pg
->entries
= ctx
->qp_min_qp1_entries
+ ctx
->qp_max_l2_entries
+
6778 mem_size
= ctx
->qp_entry_size
* ctx_pg
->entries
;
6779 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6783 ctx_pg
= &ctx
->srq_mem
;
6784 ctx_pg
->entries
= ctx
->srq_max_l2_entries
+ extra_srqs
;
6785 mem_size
= ctx
->srq_entry_size
* ctx_pg
->entries
;
6786 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6790 ctx_pg
= &ctx
->cq_mem
;
6791 ctx_pg
->entries
= ctx
->cq_max_l2_entries
+ extra_qps
* 2;
6792 mem_size
= ctx
->cq_entry_size
* ctx_pg
->entries
;
6793 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6797 ctx_pg
= &ctx
->vnic_mem
;
6798 ctx_pg
->entries
= ctx
->vnic_max_vnic_entries
+
6799 ctx
->vnic_max_ring_table_entries
;
6800 mem_size
= ctx
->vnic_entry_size
* ctx_pg
->entries
;
6801 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6805 ctx_pg
= &ctx
->stat_mem
;
6806 ctx_pg
->entries
= ctx
->stat_max_entries
;
6807 mem_size
= ctx
->stat_entry_size
* ctx_pg
->entries
;
6808 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6813 if (!(bp
->flags
& BNXT_FLAG_ROCE_CAP
))
6816 ctx_pg
= &ctx
->mrav_mem
;
6817 /* 128K extra is needed to accommodate static AH context
6818 * allocation by f/w.
6820 num_mr
= 1024 * 256;
6821 num_ah
= 1024 * 128;
6822 ctx_pg
->entries
= num_mr
+ num_ah
;
6823 mem_size
= ctx
->mrav_entry_size
* ctx_pg
->entries
;
6824 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 2);
6827 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
;
6828 if (ctx
->mrav_num_entries_units
)
6830 ((num_mr
/ ctx
->mrav_num_entries_units
) << 16) |
6831 (num_ah
/ ctx
->mrav_num_entries_units
);
6833 ctx_pg
= &ctx
->tim_mem
;
6834 ctx_pg
->entries
= ctx
->qp_mem
.entries
;
6835 mem_size
= ctx
->tim_entry_size
* ctx_pg
->entries
;
6836 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6839 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
;
6842 entries
= ctx
->qp_max_l2_entries
+ extra_qps
;
6843 entries
= roundup(entries
, ctx
->tqm_entries_multiple
);
6844 entries
= clamp_t(u32
, entries
, ctx
->tqm_min_entries_per_ring
,
6845 ctx
->tqm_max_entries_per_ring
);
6846 for (i
= 0; i
< bp
->max_q
+ 1; i
++) {
6847 ctx_pg
= ctx
->tqm_mem
[i
];
6848 ctx_pg
->entries
= entries
;
6849 mem_size
= ctx
->tqm_entry_size
* entries
;
6850 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6853 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
<< i
;
6855 ena
|= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES
;
6856 rc
= bnxt_hwrm_func_backing_store_cfg(bp
, ena
);
6858 netdev_err(bp
->dev
, "Failed configuring context mem, rc = %d.\n",
6861 ctx
->flags
|= BNXT_CTX_FLAG_INITED
;
6866 int bnxt_hwrm_func_resc_qcaps(struct bnxt
*bp
, bool all
)
6868 struct hwrm_func_resource_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6869 struct hwrm_func_resource_qcaps_input req
= {0};
6870 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6873 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESOURCE_QCAPS
, -1, -1);
6874 req
.fid
= cpu_to_le16(0xffff);
6876 mutex_lock(&bp
->hwrm_cmd_lock
);
6877 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
),
6880 goto hwrm_func_resc_qcaps_exit
;
6882 hw_resc
->max_tx_sch_inputs
= le16_to_cpu(resp
->max_tx_scheduler_inputs
);
6884 goto hwrm_func_resc_qcaps_exit
;
6886 hw_resc
->min_rsscos_ctxs
= le16_to_cpu(resp
->min_rsscos_ctx
);
6887 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
6888 hw_resc
->min_cp_rings
= le16_to_cpu(resp
->min_cmpl_rings
);
6889 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
6890 hw_resc
->min_tx_rings
= le16_to_cpu(resp
->min_tx_rings
);
6891 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
6892 hw_resc
->min_rx_rings
= le16_to_cpu(resp
->min_rx_rings
);
6893 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
6894 hw_resc
->min_hw_ring_grps
= le16_to_cpu(resp
->min_hw_ring_grps
);
6895 hw_resc
->max_hw_ring_grps
= le16_to_cpu(resp
->max_hw_ring_grps
);
6896 hw_resc
->min_l2_ctxs
= le16_to_cpu(resp
->min_l2_ctxs
);
6897 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
6898 hw_resc
->min_vnics
= le16_to_cpu(resp
->min_vnics
);
6899 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
6900 hw_resc
->min_stat_ctxs
= le16_to_cpu(resp
->min_stat_ctx
);
6901 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
6903 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6904 u16 max_msix
= le16_to_cpu(resp
->max_msix
);
6906 hw_resc
->max_nqs
= max_msix
;
6907 hw_resc
->max_hw_ring_grps
= hw_resc
->max_rx_rings
;
6911 struct bnxt_pf_info
*pf
= &bp
->pf
;
6913 pf
->vf_resv_strategy
=
6914 le16_to_cpu(resp
->vf_reservation_strategy
);
6915 if (pf
->vf_resv_strategy
> BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC
)
6916 pf
->vf_resv_strategy
= BNXT_VF_RESV_STRATEGY_MAXIMAL
;
6918 hwrm_func_resc_qcaps_exit
:
6919 mutex_unlock(&bp
->hwrm_cmd_lock
);
6923 static int __bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
6926 struct hwrm_func_qcaps_input req
= {0};
6927 struct hwrm_func_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6928 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6931 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCAPS
, -1, -1);
6932 req
.fid
= cpu_to_le16(0xffff);
6934 mutex_lock(&bp
->hwrm_cmd_lock
);
6935 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6937 goto hwrm_func_qcaps_exit
;
6939 flags
= le32_to_cpu(resp
->flags
);
6940 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED
)
6941 bp
->flags
|= BNXT_FLAG_ROCEV1_CAP
;
6942 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED
)
6943 bp
->flags
|= BNXT_FLAG_ROCEV2_CAP
;
6944 if (flags
& FUNC_QCAPS_RESP_FLAGS_PCIE_STATS_SUPPORTED
)
6945 bp
->fw_cap
|= BNXT_FW_CAP_PCIE_STATS_SUPPORTED
;
6946 if (flags
& FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED
)
6947 bp
->fw_cap
|= BNXT_FW_CAP_EXT_STATS_SUPPORTED
;
6948 if (flags
& FUNC_QCAPS_RESP_FLAGS_ERROR_RECOVERY_CAPABLE
)
6949 bp
->fw_cap
|= BNXT_FW_CAP_ERROR_RECOVERY
;
6950 if (flags
& FUNC_QCAPS_RESP_FLAGS_ERR_RECOVER_RELOAD
)
6951 bp
->fw_cap
|= BNXT_FW_CAP_ERR_RECOVER_RELOAD
;
6953 bp
->tx_push_thresh
= 0;
6954 if (flags
& FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED
)
6955 bp
->tx_push_thresh
= BNXT_TX_PUSH_THRESH
;
6957 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
6958 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
6959 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
6960 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
6961 hw_resc
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
6962 if (!hw_resc
->max_hw_ring_grps
)
6963 hw_resc
->max_hw_ring_grps
= hw_resc
->max_tx_rings
;
6964 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
6965 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
6966 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
6969 struct bnxt_pf_info
*pf
= &bp
->pf
;
6971 pf
->fw_fid
= le16_to_cpu(resp
->fid
);
6972 pf
->port_id
= le16_to_cpu(resp
->port_id
);
6973 bp
->dev
->dev_port
= pf
->port_id
;
6974 memcpy(pf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
6975 pf
->first_vf_id
= le16_to_cpu(resp
->first_vf_id
);
6976 pf
->max_vfs
= le16_to_cpu(resp
->max_vfs
);
6977 pf
->max_encap_records
= le32_to_cpu(resp
->max_encap_records
);
6978 pf
->max_decap_records
= le32_to_cpu(resp
->max_decap_records
);
6979 pf
->max_tx_em_flows
= le32_to_cpu(resp
->max_tx_em_flows
);
6980 pf
->max_tx_wm_flows
= le32_to_cpu(resp
->max_tx_wm_flows
);
6981 pf
->max_rx_em_flows
= le32_to_cpu(resp
->max_rx_em_flows
);
6982 pf
->max_rx_wm_flows
= le32_to_cpu(resp
->max_rx_wm_flows
);
6983 bp
->flags
&= ~BNXT_FLAG_WOL_CAP
;
6984 if (flags
& FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED
)
6985 bp
->flags
|= BNXT_FLAG_WOL_CAP
;
6987 #ifdef CONFIG_BNXT_SRIOV
6988 struct bnxt_vf_info
*vf
= &bp
->vf
;
6990 vf
->fw_fid
= le16_to_cpu(resp
->fid
);
6991 memcpy(vf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
6995 hwrm_func_qcaps_exit
:
6996 mutex_unlock(&bp
->hwrm_cmd_lock
);
7000 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
);
7002 static int bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
7006 rc
= __bnxt_hwrm_func_qcaps(bp
);
7009 rc
= bnxt_hwrm_queue_qportcfg(bp
);
7011 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %d\n", rc
);
7014 if (bp
->hwrm_spec_code
>= 0x10803) {
7015 rc
= bnxt_alloc_ctx_mem(bp
);
7018 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
7020 bp
->fw_cap
|= BNXT_FW_CAP_NEW_RM
;
7025 static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt
*bp
)
7027 struct hwrm_cfa_adv_flow_mgnt_qcaps_input req
= {0};
7028 struct hwrm_cfa_adv_flow_mgnt_qcaps_output
*resp
;
7032 if (!(bp
->fw_cap
& BNXT_FW_CAP_CFA_ADV_FLOW
))
7035 resp
= bp
->hwrm_cmd_resp_addr
;
7036 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_ADV_FLOW_MGNT_QCAPS
, -1, -1);
7038 mutex_lock(&bp
->hwrm_cmd_lock
);
7039 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7041 goto hwrm_cfa_adv_qcaps_exit
;
7043 flags
= le32_to_cpu(resp
->flags
);
7045 CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_SUPPORTED
)
7046 bp
->fw_cap
|= BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX
;
7048 hwrm_cfa_adv_qcaps_exit
:
7049 mutex_unlock(&bp
->hwrm_cmd_lock
);
7053 static int bnxt_map_fw_health_regs(struct bnxt
*bp
)
7055 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
7056 u32 reg_base
= 0xffffffff;
7059 /* Only pre-map the monitoring GRC registers using window 3 */
7060 for (i
= 0; i
< 4; i
++) {
7061 u32 reg
= fw_health
->regs
[i
];
7063 if (BNXT_FW_HEALTH_REG_TYPE(reg
) != BNXT_FW_HEALTH_REG_TYPE_GRC
)
7065 if (reg_base
== 0xffffffff)
7066 reg_base
= reg
& BNXT_GRC_BASE_MASK
;
7067 if ((reg
& BNXT_GRC_BASE_MASK
) != reg_base
)
7069 fw_health
->mapped_regs
[i
] = BNXT_FW_HEALTH_WIN_BASE
+
7070 (reg
& BNXT_GRC_OFFSET_MASK
);
7072 if (reg_base
== 0xffffffff)
7075 writel(reg_base
, bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+
7076 BNXT_FW_HEALTH_WIN_MAP_OFF
);
7080 static int bnxt_hwrm_error_recovery_qcfg(struct bnxt
*bp
)
7082 struct hwrm_error_recovery_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7083 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
7084 struct hwrm_error_recovery_qcfg_input req
= {0};
7087 if (!(bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
))
7090 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_ERROR_RECOVERY_QCFG
, -1, -1);
7091 mutex_lock(&bp
->hwrm_cmd_lock
);
7092 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7094 goto err_recovery_out
;
7096 fw_health
= kzalloc(sizeof(*fw_health
), GFP_KERNEL
);
7097 bp
->fw_health
= fw_health
;
7100 goto err_recovery_out
;
7103 fw_health
->flags
= le32_to_cpu(resp
->flags
);
7104 if ((fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
) &&
7105 !(bp
->fw_cap
& BNXT_FW_CAP_KONG_MB_CHNL
)) {
7107 goto err_recovery_out
;
7109 fw_health
->polling_dsecs
= le32_to_cpu(resp
->driver_polling_freq
);
7110 fw_health
->master_func_wait_dsecs
=
7111 le32_to_cpu(resp
->master_func_wait_period
);
7112 fw_health
->normal_func_wait_dsecs
=
7113 le32_to_cpu(resp
->normal_func_wait_period
);
7114 fw_health
->post_reset_wait_dsecs
=
7115 le32_to_cpu(resp
->master_func_wait_period_after_reset
);
7116 fw_health
->post_reset_max_wait_dsecs
=
7117 le32_to_cpu(resp
->max_bailout_time_after_reset
);
7118 fw_health
->regs
[BNXT_FW_HEALTH_REG
] =
7119 le32_to_cpu(resp
->fw_health_status_reg
);
7120 fw_health
->regs
[BNXT_FW_HEARTBEAT_REG
] =
7121 le32_to_cpu(resp
->fw_heartbeat_reg
);
7122 fw_health
->regs
[BNXT_FW_RESET_CNT_REG
] =
7123 le32_to_cpu(resp
->fw_reset_cnt_reg
);
7124 fw_health
->regs
[BNXT_FW_RESET_INPROG_REG
] =
7125 le32_to_cpu(resp
->reset_inprogress_reg
);
7126 fw_health
->fw_reset_inprog_reg_mask
=
7127 le32_to_cpu(resp
->reset_inprogress_reg_mask
);
7128 fw_health
->fw_reset_seq_cnt
= resp
->reg_array_cnt
;
7129 if (fw_health
->fw_reset_seq_cnt
>= 16) {
7131 goto err_recovery_out
;
7133 for (i
= 0; i
< fw_health
->fw_reset_seq_cnt
; i
++) {
7134 fw_health
->fw_reset_seq_regs
[i
] =
7135 le32_to_cpu(resp
->reset_reg
[i
]);
7136 fw_health
->fw_reset_seq_vals
[i
] =
7137 le32_to_cpu(resp
->reset_reg_val
[i
]);
7138 fw_health
->fw_reset_seq_delay_msec
[i
] =
7139 resp
->delay_after_reset
[i
];
7142 mutex_unlock(&bp
->hwrm_cmd_lock
);
7144 rc
= bnxt_map_fw_health_regs(bp
);
7146 bp
->fw_cap
&= ~BNXT_FW_CAP_ERROR_RECOVERY
;
7150 static int bnxt_hwrm_func_reset(struct bnxt
*bp
)
7152 struct hwrm_func_reset_input req
= {0};
7154 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESET
, -1, -1);
7157 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_RESET_TIMEOUT
);
7160 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
)
7163 struct hwrm_queue_qportcfg_input req
= {0};
7164 struct hwrm_queue_qportcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7168 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_QUEUE_QPORTCFG
, -1, -1);
7170 mutex_lock(&bp
->hwrm_cmd_lock
);
7171 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7175 if (!resp
->max_configurable_queues
) {
7179 bp
->max_tc
= resp
->max_configurable_queues
;
7180 bp
->max_lltc
= resp
->max_configurable_lossless_queues
;
7181 if (bp
->max_tc
> BNXT_MAX_QUEUE
)
7182 bp
->max_tc
= BNXT_MAX_QUEUE
;
7184 no_rdma
= !(bp
->flags
& BNXT_FLAG_ROCE_CAP
);
7185 qptr
= &resp
->queue_id0
;
7186 for (i
= 0, j
= 0; i
< bp
->max_tc
; i
++) {
7187 bp
->q_info
[j
].queue_id
= *qptr
;
7188 bp
->q_ids
[i
] = *qptr
++;
7189 bp
->q_info
[j
].queue_profile
= *qptr
++;
7190 bp
->tc_to_qidx
[j
] = j
;
7191 if (!BNXT_CNPQ(bp
->q_info
[j
].queue_profile
) ||
7192 (no_rdma
&& BNXT_PF(bp
)))
7195 bp
->max_q
= bp
->max_tc
;
7196 bp
->max_tc
= max_t(u8
, j
, 1);
7198 if (resp
->queue_cfg_info
& QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG
)
7201 if (bp
->max_lltc
> bp
->max_tc
)
7202 bp
->max_lltc
= bp
->max_tc
;
7205 mutex_unlock(&bp
->hwrm_cmd_lock
);
7209 static int __bnxt_hwrm_ver_get(struct bnxt
*bp
, bool silent
)
7211 struct hwrm_ver_get_input req
= {0};
7214 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VER_GET
, -1, -1);
7215 req
.hwrm_intf_maj
= HWRM_VERSION_MAJOR
;
7216 req
.hwrm_intf_min
= HWRM_VERSION_MINOR
;
7217 req
.hwrm_intf_upd
= HWRM_VERSION_UPDATE
;
7219 rc
= bnxt_hwrm_do_send_msg(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
,
7224 static int bnxt_hwrm_ver_get(struct bnxt
*bp
)
7226 struct hwrm_ver_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7230 bp
->hwrm_max_req_len
= HWRM_MAX_REQ_LEN
;
7231 mutex_lock(&bp
->hwrm_cmd_lock
);
7232 rc
= __bnxt_hwrm_ver_get(bp
, false);
7234 goto hwrm_ver_get_exit
;
7236 memcpy(&bp
->ver_resp
, resp
, sizeof(struct hwrm_ver_get_output
));
7238 bp
->hwrm_spec_code
= resp
->hwrm_intf_maj_8b
<< 16 |
7239 resp
->hwrm_intf_min_8b
<< 8 |
7240 resp
->hwrm_intf_upd_8b
;
7241 if (resp
->hwrm_intf_maj_8b
< 1) {
7242 netdev_warn(bp
->dev
, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
7243 resp
->hwrm_intf_maj_8b
, resp
->hwrm_intf_min_8b
,
7244 resp
->hwrm_intf_upd_8b
);
7245 netdev_warn(bp
->dev
, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
7247 snprintf(bp
->fw_ver_str
, BC_HWRM_STR_LEN
, "%d.%d.%d.%d",
7248 resp
->hwrm_fw_maj_8b
, resp
->hwrm_fw_min_8b
,
7249 resp
->hwrm_fw_bld_8b
, resp
->hwrm_fw_rsvd_8b
);
7251 if (strlen(resp
->active_pkg_name
)) {
7252 int fw_ver_len
= strlen(bp
->fw_ver_str
);
7254 snprintf(bp
->fw_ver_str
+ fw_ver_len
,
7255 FW_VER_STR_LEN
- fw_ver_len
- 1, "/pkg %s",
7256 resp
->active_pkg_name
);
7257 bp
->fw_cap
|= BNXT_FW_CAP_PKG_VER
;
7260 bp
->hwrm_cmd_timeout
= le16_to_cpu(resp
->def_req_timeout
);
7261 if (!bp
->hwrm_cmd_timeout
)
7262 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
7264 if (resp
->hwrm_intf_maj_8b
>= 1) {
7265 bp
->hwrm_max_req_len
= le16_to_cpu(resp
->max_req_win_len
);
7266 bp
->hwrm_max_ext_req_len
= le16_to_cpu(resp
->max_ext_req_len
);
7268 if (bp
->hwrm_max_ext_req_len
< HWRM_MAX_REQ_LEN
)
7269 bp
->hwrm_max_ext_req_len
= HWRM_MAX_REQ_LEN
;
7271 bp
->chip_num
= le16_to_cpu(resp
->chip_num
);
7272 if (bp
->chip_num
== CHIP_NUM_58700
&& !resp
->chip_rev
&&
7274 bp
->flags
|= BNXT_FLAG_CHIP_NITRO_A0
;
7276 dev_caps_cfg
= le32_to_cpu(resp
->dev_caps_cfg
);
7277 if ((dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED
) &&
7278 (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED
))
7279 bp
->fw_cap
|= BNXT_FW_CAP_SHORT_CMD
;
7281 if (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED
)
7282 bp
->fw_cap
|= BNXT_FW_CAP_KONG_MB_CHNL
;
7285 VER_GET_RESP_DEV_CAPS_CFG_FLOW_HANDLE_64BIT_SUPPORTED
)
7286 bp
->fw_cap
|= BNXT_FW_CAP_OVS_64BIT_HANDLE
;
7289 VER_GET_RESP_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED
)
7290 bp
->fw_cap
|= BNXT_FW_CAP_TRUSTED_VF
;
7293 VER_GET_RESP_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED
)
7294 bp
->fw_cap
|= BNXT_FW_CAP_CFA_ADV_FLOW
;
7297 mutex_unlock(&bp
->hwrm_cmd_lock
);
7301 int bnxt_hwrm_fw_set_time(struct bnxt
*bp
)
7303 struct hwrm_fw_set_time_input req
= {0};
7305 time64_t now
= ktime_get_real_seconds();
7307 if ((BNXT_VF(bp
) && bp
->hwrm_spec_code
< 0x10901) ||
7308 bp
->hwrm_spec_code
< 0x10400)
7311 time64_to_tm(now
, 0, &tm
);
7312 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_SET_TIME
, -1, -1);
7313 req
.year
= cpu_to_le16(1900 + tm
.tm_year
);
7314 req
.month
= 1 + tm
.tm_mon
;
7315 req
.day
= tm
.tm_mday
;
7316 req
.hour
= tm
.tm_hour
;
7317 req
.minute
= tm
.tm_min
;
7318 req
.second
= tm
.tm_sec
;
7319 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7322 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
)
7325 struct bnxt_pf_info
*pf
= &bp
->pf
;
7326 struct hwrm_port_qstats_input req
= {0};
7328 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS
))
7331 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS
, -1, -1);
7332 req
.port_id
= cpu_to_le16(pf
->port_id
);
7333 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_map
);
7334 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_map
);
7335 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7339 static int bnxt_hwrm_port_qstats_ext(struct bnxt
*bp
)
7341 struct hwrm_port_qstats_ext_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7342 struct hwrm_queue_pri2cos_qcfg_input req2
= {0};
7343 struct hwrm_port_qstats_ext_input req
= {0};
7344 struct bnxt_pf_info
*pf
= &bp
->pf
;
7348 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
))
7351 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS_EXT
, -1, -1);
7352 req
.port_id
= cpu_to_le16(pf
->port_id
);
7353 req
.rx_stat_size
= cpu_to_le16(sizeof(struct rx_port_stats_ext
));
7354 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_ext_map
);
7355 tx_stat_size
= bp
->hw_tx_port_stats_ext
?
7356 sizeof(*bp
->hw_tx_port_stats_ext
) : 0;
7357 req
.tx_stat_size
= cpu_to_le16(tx_stat_size
);
7358 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_ext_map
);
7359 mutex_lock(&bp
->hwrm_cmd_lock
);
7360 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7362 bp
->fw_rx_stats_ext_size
= le16_to_cpu(resp
->rx_stat_size
) / 8;
7363 bp
->fw_tx_stats_ext_size
= tx_stat_size
?
7364 le16_to_cpu(resp
->tx_stat_size
) / 8 : 0;
7366 bp
->fw_rx_stats_ext_size
= 0;
7367 bp
->fw_tx_stats_ext_size
= 0;
7369 if (bp
->fw_tx_stats_ext_size
<=
7370 offsetof(struct tx_port_stats_ext
, pfc_pri0_tx_duration_us
) / 8) {
7371 mutex_unlock(&bp
->hwrm_cmd_lock
);
7372 bp
->pri2cos_valid
= 0;
7376 bnxt_hwrm_cmd_hdr_init(bp
, &req2
, HWRM_QUEUE_PRI2COS_QCFG
, -1, -1);
7377 req2
.flags
= cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN
);
7379 rc
= _hwrm_send_message(bp
, &req2
, sizeof(req2
), HWRM_CMD_TIMEOUT
);
7381 struct hwrm_queue_pri2cos_qcfg_output
*resp2
;
7385 resp2
= bp
->hwrm_cmd_resp_addr
;
7386 pri2cos
= &resp2
->pri0_cos_queue_id
;
7387 for (i
= 0; i
< 8; i
++) {
7388 u8 queue_id
= pri2cos
[i
];
7390 for (j
= 0; j
< bp
->max_q
; j
++) {
7391 if (bp
->q_ids
[j
] == queue_id
)
7395 bp
->pri2cos_valid
= 1;
7397 mutex_unlock(&bp
->hwrm_cmd_lock
);
7401 static int bnxt_hwrm_pcie_qstats(struct bnxt
*bp
)
7403 struct hwrm_pcie_qstats_input req
= {0};
7405 if (!(bp
->flags
& BNXT_FLAG_PCIE_STATS
))
7408 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PCIE_QSTATS
, -1, -1);
7409 req
.pcie_stat_size
= cpu_to_le16(sizeof(struct pcie_ctx_hw_stats
));
7410 req
.pcie_stat_host_addr
= cpu_to_le64(bp
->hw_pcie_stats_map
);
7411 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7414 static void bnxt_hwrm_free_tunnel_ports(struct bnxt
*bp
)
7416 if (bp
->vxlan_port_cnt
) {
7417 bnxt_hwrm_tunnel_dst_port_free(
7418 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
7420 bp
->vxlan_port_cnt
= 0;
7421 if (bp
->nge_port_cnt
) {
7422 bnxt_hwrm_tunnel_dst_port_free(
7423 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
7425 bp
->nge_port_cnt
= 0;
7428 static int bnxt_set_tpa(struct bnxt
*bp
, bool set_tpa
)
7434 tpa_flags
= bp
->flags
& BNXT_FLAG_TPA
;
7435 else if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
7437 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
7438 rc
= bnxt_hwrm_vnic_set_tpa(bp
, i
, tpa_flags
);
7440 netdev_err(bp
->dev
, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
7448 static void bnxt_hwrm_clear_vnic_rss(struct bnxt
*bp
)
7452 for (i
= 0; i
< bp
->nr_vnics
; i
++)
7453 bnxt_hwrm_vnic_set_rss(bp
, i
, false);
7456 static void bnxt_clear_vnic(struct bnxt
*bp
)
7461 bnxt_hwrm_clear_vnic_filter(bp
);
7462 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
)) {
7463 /* clear all RSS setting before free vnic ctx */
7464 bnxt_hwrm_clear_vnic_rss(bp
);
7465 bnxt_hwrm_vnic_ctx_free(bp
);
7467 /* before free the vnic, undo the vnic tpa settings */
7468 if (bp
->flags
& BNXT_FLAG_TPA
)
7469 bnxt_set_tpa(bp
, false);
7470 bnxt_hwrm_vnic_free(bp
);
7471 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7472 bnxt_hwrm_vnic_ctx_free(bp
);
7475 static void bnxt_hwrm_resource_free(struct bnxt
*bp
, bool close_path
,
7478 bnxt_clear_vnic(bp
);
7479 bnxt_hwrm_ring_free(bp
, close_path
);
7480 bnxt_hwrm_ring_grp_free(bp
);
7482 bnxt_hwrm_stat_ctx_free(bp
);
7483 bnxt_hwrm_free_tunnel_ports(bp
);
7487 static int bnxt_hwrm_set_br_mode(struct bnxt
*bp
, u16 br_mode
)
7489 struct hwrm_func_cfg_input req
= {0};
7492 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
7493 req
.fid
= cpu_to_le16(0xffff);
7494 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE
);
7495 if (br_mode
== BRIDGE_MODE_VEB
)
7496 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEB
;
7497 else if (br_mode
== BRIDGE_MODE_VEPA
)
7498 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEPA
;
7501 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7505 static int bnxt_hwrm_set_cache_line_size(struct bnxt
*bp
, int size
)
7507 struct hwrm_func_cfg_input req
= {0};
7510 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10803)
7513 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
7514 req
.fid
= cpu_to_le16(0xffff);
7515 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE
);
7516 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64
;
7518 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128
;
7520 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7524 static int __bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
7526 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
7529 if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
)
7532 /* allocate context for vnic */
7533 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 0);
7535 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
7537 goto vnic_setup_err
;
7539 bp
->rsscos_nr_ctxs
++;
7541 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
7542 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 1);
7544 netdev_err(bp
->dev
, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
7546 goto vnic_setup_err
;
7548 bp
->rsscos_nr_ctxs
++;
7552 /* configure default vnic, ring grp */
7553 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
7555 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
7557 goto vnic_setup_err
;
7560 /* Enable RSS hashing on vnic */
7561 rc
= bnxt_hwrm_vnic_set_rss(bp
, vnic_id
, true);
7563 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %x\n",
7565 goto vnic_setup_err
;
7568 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
7569 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
7571 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
7580 static int __bnxt_setup_vnic_p5(struct bnxt
*bp
, u16 vnic_id
)
7584 nr_ctxs
= DIV_ROUND_UP(bp
->rx_nr_rings
, 64);
7585 for (i
= 0; i
< nr_ctxs
; i
++) {
7586 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, i
);
7588 netdev_err(bp
->dev
, "hwrm vnic %d ctx %d alloc failure rc: %x\n",
7592 bp
->rsscos_nr_ctxs
++;
7597 rc
= bnxt_hwrm_vnic_set_rss_p5(bp
, vnic_id
, true);
7599 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %d\n",
7603 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
7605 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
7609 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
7610 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
7612 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
7619 static int bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
7621 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7622 return __bnxt_setup_vnic_p5(bp
, vnic_id
);
7624 return __bnxt_setup_vnic(bp
, vnic_id
);
7627 static int bnxt_alloc_rfs_vnics(struct bnxt
*bp
)
7629 #ifdef CONFIG_RFS_ACCEL
7632 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7635 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
7636 struct bnxt_vnic_info
*vnic
;
7637 u16 vnic_id
= i
+ 1;
7640 if (vnic_id
>= bp
->nr_vnics
)
7643 vnic
= &bp
->vnic_info
[vnic_id
];
7644 vnic
->flags
|= BNXT_VNIC_RFS_FLAG
;
7645 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
7646 vnic
->flags
|= BNXT_VNIC_RFS_NEW_RSS_FLAG
;
7647 rc
= bnxt_hwrm_vnic_alloc(bp
, vnic_id
, ring_id
, 1);
7649 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
7653 rc
= bnxt_setup_vnic(bp
, vnic_id
);
7663 /* Allow PF and VF with default VLAN to be in promiscuous mode */
7664 static bool bnxt_promisc_ok(struct bnxt
*bp
)
7666 #ifdef CONFIG_BNXT_SRIOV
7667 if (BNXT_VF(bp
) && !bp
->vf
.vlan
)
7673 static int bnxt_setup_nitroa0_vnic(struct bnxt
*bp
)
7675 unsigned int rc
= 0;
7677 rc
= bnxt_hwrm_vnic_alloc(bp
, 1, bp
->rx_nr_rings
- 1, 1);
7679 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
7684 rc
= bnxt_hwrm_vnic_cfg(bp
, 1);
7686 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
7693 static int bnxt_cfg_rx_mode(struct bnxt
*);
7694 static bool bnxt_mc_list_updated(struct bnxt
*, u32
*);
7696 static int bnxt_init_chip(struct bnxt
*bp
, bool irq_re_init
)
7698 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7700 unsigned int rx_nr_rings
= bp
->rx_nr_rings
;
7703 rc
= bnxt_hwrm_stat_ctx_alloc(bp
);
7705 netdev_err(bp
->dev
, "hwrm stat ctx alloc failure rc: %x\n",
7711 rc
= bnxt_hwrm_ring_alloc(bp
);
7713 netdev_err(bp
->dev
, "hwrm ring alloc failure rc: %x\n", rc
);
7717 rc
= bnxt_hwrm_ring_grp_alloc(bp
);
7719 netdev_err(bp
->dev
, "hwrm_ring_grp alloc failure: %x\n", rc
);
7723 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
7726 /* default vnic 0 */
7727 rc
= bnxt_hwrm_vnic_alloc(bp
, 0, 0, rx_nr_rings
);
7729 netdev_err(bp
->dev
, "hwrm vnic alloc failure rc: %x\n", rc
);
7733 rc
= bnxt_setup_vnic(bp
, 0);
7737 if (bp
->flags
& BNXT_FLAG_RFS
) {
7738 rc
= bnxt_alloc_rfs_vnics(bp
);
7743 if (bp
->flags
& BNXT_FLAG_TPA
) {
7744 rc
= bnxt_set_tpa(bp
, true);
7750 bnxt_update_vf_mac(bp
);
7752 /* Filter for default vnic 0 */
7753 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, 0, bp
->dev
->dev_addr
);
7755 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n", rc
);
7758 vnic
->uc_filter_count
= 1;
7761 if (bp
->dev
->flags
& IFF_BROADCAST
)
7762 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
7764 if ((bp
->dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
7765 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
7767 if (bp
->dev
->flags
& IFF_ALLMULTI
) {
7768 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
7769 vnic
->mc_list_count
= 0;
7773 bnxt_mc_list_updated(bp
, &mask
);
7774 vnic
->rx_mask
|= mask
;
7777 rc
= bnxt_cfg_rx_mode(bp
);
7781 rc
= bnxt_hwrm_set_coal(bp
);
7783 netdev_warn(bp
->dev
, "HWRM set coalescing failure rc: %x\n",
7786 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
7787 rc
= bnxt_setup_nitroa0_vnic(bp
);
7789 netdev_err(bp
->dev
, "Special vnic setup failure for NS2 A0 rc: %x\n",
7794 bnxt_hwrm_func_qcfg(bp
);
7795 netdev_update_features(bp
->dev
);
7801 bnxt_hwrm_resource_free(bp
, 0, true);
7806 static int bnxt_shutdown_nic(struct bnxt
*bp
, bool irq_re_init
)
7808 bnxt_hwrm_resource_free(bp
, 1, irq_re_init
);
7812 static int bnxt_init_nic(struct bnxt
*bp
, bool irq_re_init
)
7814 bnxt_init_cp_rings(bp
);
7815 bnxt_init_rx_rings(bp
);
7816 bnxt_init_tx_rings(bp
);
7817 bnxt_init_ring_grps(bp
, irq_re_init
);
7818 bnxt_init_vnics(bp
);
7820 return bnxt_init_chip(bp
, irq_re_init
);
7823 static int bnxt_set_real_num_queues(struct bnxt
*bp
)
7826 struct net_device
*dev
= bp
->dev
;
7828 rc
= netif_set_real_num_tx_queues(dev
, bp
->tx_nr_rings
-
7829 bp
->tx_nr_rings_xdp
);
7833 rc
= netif_set_real_num_rx_queues(dev
, bp
->rx_nr_rings
);
7837 #ifdef CONFIG_RFS_ACCEL
7838 if (bp
->flags
& BNXT_FLAG_RFS
)
7839 dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(bp
->rx_nr_rings
);
7845 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
7848 int _rx
= *rx
, _tx
= *tx
;
7851 *rx
= min_t(int, _rx
, max
);
7852 *tx
= min_t(int, _tx
, max
);
7857 while (_rx
+ _tx
> max
) {
7858 if (_rx
> _tx
&& _rx
> 1)
7869 static void bnxt_setup_msix(struct bnxt
*bp
)
7871 const int len
= sizeof(bp
->irq_tbl
[0].name
);
7872 struct net_device
*dev
= bp
->dev
;
7875 tcs
= netdev_get_num_tc(dev
);
7879 for (i
= 0; i
< tcs
; i
++) {
7880 count
= bp
->tx_nr_rings_per_tc
;
7882 netdev_set_tc_queue(dev
, i
, count
, off
);
7886 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7887 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
7890 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
7892 else if (i
< bp
->rx_nr_rings
)
7897 snprintf(bp
->irq_tbl
[map_idx
].name
, len
, "%s-%s-%d", dev
->name
,
7899 bp
->irq_tbl
[map_idx
].handler
= bnxt_msix
;
7903 static void bnxt_setup_inta(struct bnxt
*bp
)
7905 const int len
= sizeof(bp
->irq_tbl
[0].name
);
7907 if (netdev_get_num_tc(bp
->dev
))
7908 netdev_reset_tc(bp
->dev
);
7910 snprintf(bp
->irq_tbl
[0].name
, len
, "%s-%s-%d", bp
->dev
->name
, "TxRx",
7912 bp
->irq_tbl
[0].handler
= bnxt_inta
;
7915 static int bnxt_setup_int_mode(struct bnxt
*bp
)
7919 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
7920 bnxt_setup_msix(bp
);
7922 bnxt_setup_inta(bp
);
7924 rc
= bnxt_set_real_num_queues(bp
);
7928 #ifdef CONFIG_RFS_ACCEL
7929 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt
*bp
)
7931 return bp
->hw_resc
.max_rsscos_ctxs
;
7934 static unsigned int bnxt_get_max_func_vnics(struct bnxt
*bp
)
7936 return bp
->hw_resc
.max_vnics
;
7940 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt
*bp
)
7942 return bp
->hw_resc
.max_stat_ctxs
;
7945 unsigned int bnxt_get_max_func_cp_rings(struct bnxt
*bp
)
7947 return bp
->hw_resc
.max_cp_rings
;
7950 static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt
*bp
)
7952 unsigned int cp
= bp
->hw_resc
.max_cp_rings
;
7954 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
7955 cp
-= bnxt_get_ulp_msix_num(bp
);
7960 static unsigned int bnxt_get_max_func_irqs(struct bnxt
*bp
)
7962 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7964 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7965 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_nqs
);
7967 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_cp_rings
);
7970 static void bnxt_set_max_func_irqs(struct bnxt
*bp
, unsigned int max_irqs
)
7972 bp
->hw_resc
.max_irqs
= max_irqs
;
7975 unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt
*bp
)
7979 cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
7980 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7981 return cp
- bp
->rx_nr_rings
- bp
->tx_nr_rings
;
7983 return cp
- bp
->cp_nr_rings
;
7986 unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt
*bp
)
7988 return bnxt_get_max_func_stat_ctxs(bp
) - bnxt_get_func_stat_ctxs(bp
);
7991 int bnxt_get_avail_msix(struct bnxt
*bp
, int num
)
7993 int max_cp
= bnxt_get_max_func_cp_rings(bp
);
7994 int max_irq
= bnxt_get_max_func_irqs(bp
);
7995 int total_req
= bp
->cp_nr_rings
+ num
;
7996 int max_idx
, avail_msix
;
7998 max_idx
= bp
->total_irqs
;
7999 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
8000 max_idx
= min_t(int, bp
->total_irqs
, max_cp
);
8001 avail_msix
= max_idx
- bp
->cp_nr_rings
;
8002 if (!BNXT_NEW_RM(bp
) || avail_msix
>= num
)
8005 if (max_irq
< total_req
) {
8006 num
= max_irq
- bp
->cp_nr_rings
;
8013 static int bnxt_get_num_msix(struct bnxt
*bp
)
8015 if (!BNXT_NEW_RM(bp
))
8016 return bnxt_get_max_func_irqs(bp
);
8018 return bnxt_nq_rings_in_use(bp
);
8021 static int bnxt_init_msix(struct bnxt
*bp
)
8023 int i
, total_vecs
, max
, rc
= 0, min
= 1, ulp_msix
;
8024 struct msix_entry
*msix_ent
;
8026 total_vecs
= bnxt_get_num_msix(bp
);
8027 max
= bnxt_get_max_func_irqs(bp
);
8028 if (total_vecs
> max
)
8034 msix_ent
= kcalloc(total_vecs
, sizeof(struct msix_entry
), GFP_KERNEL
);
8038 for (i
= 0; i
< total_vecs
; i
++) {
8039 msix_ent
[i
].entry
= i
;
8040 msix_ent
[i
].vector
= 0;
8043 if (!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
))
8046 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
, min
, total_vecs
);
8047 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
8048 if (total_vecs
< 0 || total_vecs
< ulp_msix
) {
8050 goto msix_setup_exit
;
8053 bp
->irq_tbl
= kcalloc(total_vecs
, sizeof(struct bnxt_irq
), GFP_KERNEL
);
8055 for (i
= 0; i
< total_vecs
; i
++)
8056 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
8058 bp
->total_irqs
= total_vecs
;
8059 /* Trim rings based upon num of vectors allocated */
8060 rc
= bnxt_trim_rings(bp
, &bp
->rx_nr_rings
, &bp
->tx_nr_rings
,
8061 total_vecs
- ulp_msix
, min
== 1);
8063 goto msix_setup_exit
;
8065 bp
->cp_nr_rings
= (min
== 1) ?
8066 max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
8067 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
8071 goto msix_setup_exit
;
8073 bp
->flags
|= BNXT_FLAG_USING_MSIX
;
8078 netdev_err(bp
->dev
, "bnxt_init_msix err: %x\n", rc
);
8081 pci_disable_msix(bp
->pdev
);
8086 static int bnxt_init_inta(struct bnxt
*bp
)
8088 bp
->irq_tbl
= kcalloc(1, sizeof(struct bnxt_irq
), GFP_KERNEL
);
8093 bp
->rx_nr_rings
= 1;
8094 bp
->tx_nr_rings
= 1;
8095 bp
->cp_nr_rings
= 1;
8096 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
8097 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
8101 static int bnxt_init_int_mode(struct bnxt
*bp
)
8105 if (bp
->flags
& BNXT_FLAG_MSIX_CAP
)
8106 rc
= bnxt_init_msix(bp
);
8108 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
) && BNXT_PF(bp
)) {
8109 /* fallback to INTA */
8110 rc
= bnxt_init_inta(bp
);
8115 static void bnxt_clear_int_mode(struct bnxt
*bp
)
8117 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
8118 pci_disable_msix(bp
->pdev
);
8122 bp
->flags
&= ~BNXT_FLAG_USING_MSIX
;
8125 int bnxt_reserve_rings(struct bnxt
*bp
, bool irq_re_init
)
8127 int tcs
= netdev_get_num_tc(bp
->dev
);
8128 bool irq_cleared
= false;
8131 if (!bnxt_need_reserve_rings(bp
))
8134 if (irq_re_init
&& BNXT_NEW_RM(bp
) &&
8135 bnxt_get_num_msix(bp
) != bp
->total_irqs
) {
8136 bnxt_ulp_irq_stop(bp
);
8137 bnxt_clear_int_mode(bp
);
8140 rc
= __bnxt_reserve_rings(bp
);
8143 rc
= bnxt_init_int_mode(bp
);
8144 bnxt_ulp_irq_restart(bp
, rc
);
8147 netdev_err(bp
->dev
, "ring reservation/IRQ init failure rc: %d\n", rc
);
8150 if (tcs
&& (bp
->tx_nr_rings_per_tc
* tcs
!= bp
->tx_nr_rings
)) {
8151 netdev_err(bp
->dev
, "tx ring reservation failure\n");
8152 netdev_reset_tc(bp
->dev
);
8153 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
8159 static void bnxt_free_irq(struct bnxt
*bp
)
8161 struct bnxt_irq
*irq
;
8164 #ifdef CONFIG_RFS_ACCEL
8165 free_irq_cpu_rmap(bp
->dev
->rx_cpu_rmap
);
8166 bp
->dev
->rx_cpu_rmap
= NULL
;
8168 if (!bp
->irq_tbl
|| !bp
->bnapi
)
8171 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8172 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
8174 irq
= &bp
->irq_tbl
[map_idx
];
8175 if (irq
->requested
) {
8176 if (irq
->have_cpumask
) {
8177 irq_set_affinity_hint(irq
->vector
, NULL
);
8178 free_cpumask_var(irq
->cpu_mask
);
8179 irq
->have_cpumask
= 0;
8181 free_irq(irq
->vector
, bp
->bnapi
[i
]);
8188 static int bnxt_request_irq(struct bnxt
*bp
)
8191 unsigned long flags
= 0;
8192 #ifdef CONFIG_RFS_ACCEL
8193 struct cpu_rmap
*rmap
;
8196 rc
= bnxt_setup_int_mode(bp
);
8198 netdev_err(bp
->dev
, "bnxt_setup_int_mode err: %x\n",
8202 #ifdef CONFIG_RFS_ACCEL
8203 rmap
= bp
->dev
->rx_cpu_rmap
;
8205 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
))
8206 flags
= IRQF_SHARED
;
8208 for (i
= 0, j
= 0; i
< bp
->cp_nr_rings
; i
++) {
8209 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
8210 struct bnxt_irq
*irq
= &bp
->irq_tbl
[map_idx
];
8212 #ifdef CONFIG_RFS_ACCEL
8213 if (rmap
&& bp
->bnapi
[i
]->rx_ring
) {
8214 rc
= irq_cpu_rmap_add(rmap
, irq
->vector
);
8216 netdev_warn(bp
->dev
, "failed adding irq rmap for ring %d\n",
8221 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
8228 if (zalloc_cpumask_var(&irq
->cpu_mask
, GFP_KERNEL
)) {
8229 int numa_node
= dev_to_node(&bp
->pdev
->dev
);
8231 irq
->have_cpumask
= 1;
8232 cpumask_set_cpu(cpumask_local_spread(i
, numa_node
),
8234 rc
= irq_set_affinity_hint(irq
->vector
, irq
->cpu_mask
);
8236 netdev_warn(bp
->dev
,
8237 "Set affinity failed, IRQ = %d\n",
8246 static void bnxt_del_napi(struct bnxt
*bp
)
8253 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8254 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
8256 napi_hash_del(&bnapi
->napi
);
8257 netif_napi_del(&bnapi
->napi
);
8259 /* We called napi_hash_del() before netif_napi_del(), we need
8260 * to respect an RCU grace period before freeing napi structures.
8265 static void bnxt_init_napi(struct bnxt
*bp
)
8268 unsigned int cp_nr_rings
= bp
->cp_nr_rings
;
8269 struct bnxt_napi
*bnapi
;
8271 if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
8272 int (*poll_fn
)(struct napi_struct
*, int) = bnxt_poll
;
8274 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
8275 poll_fn
= bnxt_poll_p5
;
8276 else if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
8278 for (i
= 0; i
< cp_nr_rings
; i
++) {
8279 bnapi
= bp
->bnapi
[i
];
8280 netif_napi_add(bp
->dev
, &bnapi
->napi
, poll_fn
, 64);
8282 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
8283 bnapi
= bp
->bnapi
[cp_nr_rings
];
8284 netif_napi_add(bp
->dev
, &bnapi
->napi
,
8285 bnxt_poll_nitroa0
, 64);
8288 bnapi
= bp
->bnapi
[0];
8289 netif_napi_add(bp
->dev
, &bnapi
->napi
, bnxt_poll
, 64);
8293 static void bnxt_disable_napi(struct bnxt
*bp
)
8300 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8301 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
8303 if (bp
->bnapi
[i
]->rx_ring
)
8304 cancel_work_sync(&cpr
->dim
.work
);
8306 napi_disable(&bp
->bnapi
[i
]->napi
);
8310 static void bnxt_enable_napi(struct bnxt
*bp
)
8314 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8315 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
8316 bp
->bnapi
[i
]->in_reset
= false;
8318 if (bp
->bnapi
[i
]->rx_ring
) {
8319 INIT_WORK(&cpr
->dim
.work
, bnxt_dim_work
);
8320 cpr
->dim
.mode
= DIM_CQ_PERIOD_MODE_START_FROM_EQE
;
8322 napi_enable(&bp
->bnapi
[i
]->napi
);
8326 void bnxt_tx_disable(struct bnxt
*bp
)
8329 struct bnxt_tx_ring_info
*txr
;
8332 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
8333 txr
= &bp
->tx_ring
[i
];
8334 txr
->dev_state
= BNXT_DEV_STATE_CLOSING
;
8337 /* Stop all TX queues */
8338 netif_tx_disable(bp
->dev
);
8339 netif_carrier_off(bp
->dev
);
8342 void bnxt_tx_enable(struct bnxt
*bp
)
8345 struct bnxt_tx_ring_info
*txr
;
8347 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
8348 txr
= &bp
->tx_ring
[i
];
8351 netif_tx_wake_all_queues(bp
->dev
);
8352 if (bp
->link_info
.link_up
)
8353 netif_carrier_on(bp
->dev
);
8356 static void bnxt_report_link(struct bnxt
*bp
)
8358 if (bp
->link_info
.link_up
) {
8360 const char *flow_ctrl
;
8364 netif_carrier_on(bp
->dev
);
8365 if (bp
->link_info
.duplex
== BNXT_LINK_DUPLEX_FULL
)
8369 if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_BOTH
)
8370 flow_ctrl
= "ON - receive & transmit";
8371 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_TX
)
8372 flow_ctrl
= "ON - transmit";
8373 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_RX
)
8374 flow_ctrl
= "ON - receive";
8377 speed
= bnxt_fw_to_ethtool_speed(bp
->link_info
.link_speed
);
8378 netdev_info(bp
->dev
, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
8379 speed
, duplex
, flow_ctrl
);
8380 if (bp
->flags
& BNXT_FLAG_EEE_CAP
)
8381 netdev_info(bp
->dev
, "EEE is %s\n",
8382 bp
->eee
.eee_active
? "active" :
8384 fec
= bp
->link_info
.fec_cfg
;
8385 if (!(fec
& PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
))
8386 netdev_info(bp
->dev
, "FEC autoneg %s encodings: %s\n",
8387 (fec
& BNXT_FEC_AUTONEG
) ? "on" : "off",
8388 (fec
& BNXT_FEC_ENC_BASE_R
) ? "BaseR" :
8389 (fec
& BNXT_FEC_ENC_RS
) ? "RS" : "None");
8391 netif_carrier_off(bp
->dev
);
8392 netdev_err(bp
->dev
, "NIC Link is Down\n");
8396 static int bnxt_hwrm_phy_qcaps(struct bnxt
*bp
)
8399 struct hwrm_port_phy_qcaps_input req
= {0};
8400 struct hwrm_port_phy_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8401 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8403 bp
->flags
&= ~BNXT_FLAG_EEE_CAP
;
8405 bp
->test_info
->flags
&= ~BNXT_TEST_FL_EXT_LPBK
;
8406 if (bp
->hwrm_spec_code
< 0x10201)
8409 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCAPS
, -1, -1);
8411 mutex_lock(&bp
->hwrm_cmd_lock
);
8412 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8414 goto hwrm_phy_qcaps_exit
;
8416 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED
) {
8417 struct ethtool_eee
*eee
= &bp
->eee
;
8418 u16 fw_speeds
= le16_to_cpu(resp
->supported_speeds_eee_mode
);
8420 bp
->flags
|= BNXT_FLAG_EEE_CAP
;
8421 eee
->supported
= _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
8422 bp
->lpi_tmr_lo
= le32_to_cpu(resp
->tx_lpi_timer_low
) &
8423 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK
;
8424 bp
->lpi_tmr_hi
= le32_to_cpu(resp
->valid_tx_lpi_timer_high
) &
8425 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK
;
8427 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EXTERNAL_LPBK_SUPPORTED
) {
8429 bp
->test_info
->flags
|= BNXT_TEST_FL_EXT_LPBK
;
8431 if (resp
->supported_speeds_auto_mode
)
8432 link_info
->support_auto_speeds
=
8433 le16_to_cpu(resp
->supported_speeds_auto_mode
);
8435 bp
->port_count
= resp
->port_cnt
;
8437 hwrm_phy_qcaps_exit
:
8438 mutex_unlock(&bp
->hwrm_cmd_lock
);
8442 static int bnxt_update_link(struct bnxt
*bp
, bool chng_link_state
)
8445 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8446 struct hwrm_port_phy_qcfg_input req
= {0};
8447 struct hwrm_port_phy_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8448 u8 link_up
= link_info
->link_up
;
8451 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCFG
, -1, -1);
8453 mutex_lock(&bp
->hwrm_cmd_lock
);
8454 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8456 mutex_unlock(&bp
->hwrm_cmd_lock
);
8460 memcpy(&link_info
->phy_qcfg_resp
, resp
, sizeof(*resp
));
8461 link_info
->phy_link_status
= resp
->link
;
8462 link_info
->duplex
= resp
->duplex_cfg
;
8463 if (bp
->hwrm_spec_code
>= 0x10800)
8464 link_info
->duplex
= resp
->duplex_state
;
8465 link_info
->pause
= resp
->pause
;
8466 link_info
->auto_mode
= resp
->auto_mode
;
8467 link_info
->auto_pause_setting
= resp
->auto_pause
;
8468 link_info
->lp_pause
= resp
->link_partner_adv_pause
;
8469 link_info
->force_pause_setting
= resp
->force_pause
;
8470 link_info
->duplex_setting
= resp
->duplex_cfg
;
8471 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
8472 link_info
->link_speed
= le16_to_cpu(resp
->link_speed
);
8474 link_info
->link_speed
= 0;
8475 link_info
->force_link_speed
= le16_to_cpu(resp
->force_link_speed
);
8476 link_info
->support_speeds
= le16_to_cpu(resp
->support_speeds
);
8477 link_info
->auto_link_speeds
= le16_to_cpu(resp
->auto_link_speed_mask
);
8478 link_info
->lp_auto_link_speeds
=
8479 le16_to_cpu(resp
->link_partner_adv_speeds
);
8480 link_info
->preemphasis
= le32_to_cpu(resp
->preemphasis
);
8481 link_info
->phy_ver
[0] = resp
->phy_maj
;
8482 link_info
->phy_ver
[1] = resp
->phy_min
;
8483 link_info
->phy_ver
[2] = resp
->phy_bld
;
8484 link_info
->media_type
= resp
->media_type
;
8485 link_info
->phy_type
= resp
->phy_type
;
8486 link_info
->transceiver
= resp
->xcvr_pkg_type
;
8487 link_info
->phy_addr
= resp
->eee_config_phy_addr
&
8488 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK
;
8489 link_info
->module_status
= resp
->module_status
;
8491 if (bp
->flags
& BNXT_FLAG_EEE_CAP
) {
8492 struct ethtool_eee
*eee
= &bp
->eee
;
8495 eee
->eee_active
= 0;
8496 if (resp
->eee_config_phy_addr
&
8497 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE
) {
8498 eee
->eee_active
= 1;
8499 fw_speeds
= le16_to_cpu(
8500 resp
->link_partner_adv_eee_link_speed_mask
);
8501 eee
->lp_advertised
=
8502 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
8505 /* Pull initial EEE config */
8506 if (!chng_link_state
) {
8507 if (resp
->eee_config_phy_addr
&
8508 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED
)
8509 eee
->eee_enabled
= 1;
8511 fw_speeds
= le16_to_cpu(resp
->adv_eee_link_speed_mask
);
8513 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
8515 if (resp
->eee_config_phy_addr
&
8516 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI
) {
8519 eee
->tx_lpi_enabled
= 1;
8520 tmr
= resp
->xcvr_identifier_type_tx_lpi_timer
;
8521 eee
->tx_lpi_timer
= le32_to_cpu(tmr
) &
8522 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK
;
8527 link_info
->fec_cfg
= PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
;
8528 if (bp
->hwrm_spec_code
>= 0x10504)
8529 link_info
->fec_cfg
= le16_to_cpu(resp
->fec_cfg
);
8531 /* TODO: need to add more logic to report VF link */
8532 if (chng_link_state
) {
8533 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
8534 link_info
->link_up
= 1;
8536 link_info
->link_up
= 0;
8537 if (link_up
!= link_info
->link_up
)
8538 bnxt_report_link(bp
);
8540 /* alwasy link down if not require to update link state */
8541 link_info
->link_up
= 0;
8543 mutex_unlock(&bp
->hwrm_cmd_lock
);
8545 if (!BNXT_SINGLE_PF(bp
))
8548 diff
= link_info
->support_auto_speeds
^ link_info
->advertising
;
8549 if ((link_info
->support_auto_speeds
| diff
) !=
8550 link_info
->support_auto_speeds
) {
8551 /* An advertised speed is no longer supported, so we need to
8552 * update the advertisement settings. Caller holds RTNL
8553 * so we can modify link settings.
8555 link_info
->advertising
= link_info
->support_auto_speeds
;
8556 if (link_info
->autoneg
& BNXT_AUTONEG_SPEED
)
8557 bnxt_hwrm_set_link_setting(bp
, true, false);
8562 static void bnxt_get_port_module_status(struct bnxt
*bp
)
8564 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8565 struct hwrm_port_phy_qcfg_output
*resp
= &link_info
->phy_qcfg_resp
;
8568 if (bnxt_update_link(bp
, true))
8571 module_status
= link_info
->module_status
;
8572 switch (module_status
) {
8573 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
:
8574 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
:
8575 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
:
8576 netdev_warn(bp
->dev
, "Unqualified SFP+ module detected on port %d\n",
8578 if (bp
->hwrm_spec_code
>= 0x10201) {
8579 netdev_warn(bp
->dev
, "Module part number %s\n",
8580 resp
->phy_vendor_partnumber
);
8582 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
)
8583 netdev_warn(bp
->dev
, "TX is disabled\n");
8584 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
)
8585 netdev_warn(bp
->dev
, "SFP+ module is shutdown\n");
8590 bnxt_hwrm_set_pause_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
8592 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) {
8593 if (bp
->hwrm_spec_code
>= 0x10201)
8595 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
8596 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
8597 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX
;
8598 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
8599 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX
;
8601 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
8603 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
8604 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX
;
8605 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
8606 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX
;
8608 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE
);
8609 if (bp
->hwrm_spec_code
>= 0x10201) {
8610 req
->auto_pause
= req
->force_pause
;
8611 req
->enables
|= cpu_to_le32(
8612 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
8617 static void bnxt_hwrm_set_link_common(struct bnxt
*bp
,
8618 struct hwrm_port_phy_cfg_input
*req
)
8620 u8 autoneg
= bp
->link_info
.autoneg
;
8621 u16 fw_link_speed
= bp
->link_info
.req_link_speed
;
8622 u16 advertising
= bp
->link_info
.advertising
;
8624 if (autoneg
& BNXT_AUTONEG_SPEED
) {
8626 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK
;
8628 req
->enables
|= cpu_to_le32(
8629 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK
);
8630 req
->auto_link_speed_mask
= cpu_to_le16(advertising
);
8632 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE
);
8634 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG
);
8636 req
->force_link_speed
= cpu_to_le16(fw_link_speed
);
8637 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE
);
8640 /* tell chimp that the setting takes effect immediately */
8641 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY
);
8644 int bnxt_hwrm_set_pause(struct bnxt
*bp
)
8646 struct hwrm_port_phy_cfg_input req
= {0};
8649 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8650 bnxt_hwrm_set_pause_common(bp
, &req
);
8652 if ((bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) ||
8653 bp
->link_info
.force_link_chng
)
8654 bnxt_hwrm_set_link_common(bp
, &req
);
8656 mutex_lock(&bp
->hwrm_cmd_lock
);
8657 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8658 if (!rc
&& !(bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
)) {
8659 /* since changing of pause setting doesn't trigger any link
8660 * change event, the driver needs to update the current pause
8661 * result upon successfully return of the phy_cfg command
8663 bp
->link_info
.pause
=
8664 bp
->link_info
.force_pause_setting
= bp
->link_info
.req_flow_ctrl
;
8665 bp
->link_info
.auto_pause_setting
= 0;
8666 if (!bp
->link_info
.force_link_chng
)
8667 bnxt_report_link(bp
);
8669 bp
->link_info
.force_link_chng
= false;
8670 mutex_unlock(&bp
->hwrm_cmd_lock
);
8674 static void bnxt_hwrm_set_eee(struct bnxt
*bp
,
8675 struct hwrm_port_phy_cfg_input
*req
)
8677 struct ethtool_eee
*eee
= &bp
->eee
;
8679 if (eee
->eee_enabled
) {
8681 u32 flags
= PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE
;
8683 if (eee
->tx_lpi_enabled
)
8684 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE
;
8686 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE
;
8688 req
->flags
|= cpu_to_le32(flags
);
8689 eee_speeds
= bnxt_get_fw_auto_link_speeds(eee
->advertised
);
8690 req
->eee_link_speed_mask
= cpu_to_le16(eee_speeds
);
8691 req
->tx_lpi_timer
= cpu_to_le32(eee
->tx_lpi_timer
);
8693 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE
);
8697 int bnxt_hwrm_set_link_setting(struct bnxt
*bp
, bool set_pause
, bool set_eee
)
8699 struct hwrm_port_phy_cfg_input req
= {0};
8701 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8703 bnxt_hwrm_set_pause_common(bp
, &req
);
8705 bnxt_hwrm_set_link_common(bp
, &req
);
8708 bnxt_hwrm_set_eee(bp
, &req
);
8709 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8712 static int bnxt_hwrm_shutdown_link(struct bnxt
*bp
)
8714 struct hwrm_port_phy_cfg_input req
= {0};
8716 if (!BNXT_SINGLE_PF(bp
))
8719 if (pci_num_vf(bp
->pdev
))
8722 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8723 req
.flags
= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN
);
8724 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8727 static int bnxt_fw_init_one(struct bnxt
*bp
);
8729 static int bnxt_hwrm_if_change(struct bnxt
*bp
, bool up
)
8731 struct hwrm_func_drv_if_change_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8732 struct hwrm_func_drv_if_change_input req
= {0};
8733 bool resc_reinit
= false, fw_reset
= false;
8737 if (!(bp
->fw_cap
& BNXT_FW_CAP_IF_CHANGE
))
8740 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_IF_CHANGE
, -1, -1);
8742 req
.flags
= cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP
);
8743 mutex_lock(&bp
->hwrm_cmd_lock
);
8744 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8746 flags
= le32_to_cpu(resp
->flags
);
8747 mutex_unlock(&bp
->hwrm_cmd_lock
);
8754 if (flags
& FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE
)
8756 if (flags
& FUNC_DRV_IF_CHANGE_RESP_FLAGS_HOT_FW_RESET_DONE
)
8759 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
) && !fw_reset
) {
8760 netdev_err(bp
->dev
, "RESET_DONE not set during FW reset.\n");
8763 if (resc_reinit
|| fw_reset
) {
8765 rc
= bnxt_fw_init_one(bp
);
8767 set_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
8770 bnxt_clear_int_mode(bp
);
8771 rc
= bnxt_init_int_mode(bp
);
8773 netdev_err(bp
->dev
, "init int mode failed\n");
8776 set_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
);
8778 if (BNXT_NEW_RM(bp
)) {
8779 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
8781 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
8782 hw_resc
->resv_cp_rings
= 0;
8783 hw_resc
->resv_stat_ctxs
= 0;
8784 hw_resc
->resv_irqs
= 0;
8785 hw_resc
->resv_tx_rings
= 0;
8786 hw_resc
->resv_rx_rings
= 0;
8787 hw_resc
->resv_hw_ring_grps
= 0;
8788 hw_resc
->resv_vnics
= 0;
8790 bp
->tx_nr_rings
= 0;
8791 bp
->rx_nr_rings
= 0;
8798 static int bnxt_hwrm_port_led_qcaps(struct bnxt
*bp
)
8800 struct hwrm_port_led_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8801 struct hwrm_port_led_qcaps_input req
= {0};
8802 struct bnxt_pf_info
*pf
= &bp
->pf
;
8806 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10601)
8809 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_LED_QCAPS
, -1, -1);
8810 req
.port_id
= cpu_to_le16(pf
->port_id
);
8811 mutex_lock(&bp
->hwrm_cmd_lock
);
8812 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8814 mutex_unlock(&bp
->hwrm_cmd_lock
);
8817 if (resp
->num_leds
> 0 && resp
->num_leds
< BNXT_MAX_LED
) {
8820 bp
->num_leds
= resp
->num_leds
;
8821 memcpy(bp
->leds
, &resp
->led0_id
, sizeof(bp
->leds
[0]) *
8823 for (i
= 0; i
< bp
->num_leds
; i
++) {
8824 struct bnxt_led_info
*led
= &bp
->leds
[i
];
8825 __le16 caps
= led
->led_state_caps
;
8827 if (!led
->led_group_id
||
8828 !BNXT_LED_ALT_BLINK_CAP(caps
)) {
8834 mutex_unlock(&bp
->hwrm_cmd_lock
);
8838 int bnxt_hwrm_alloc_wol_fltr(struct bnxt
*bp
)
8840 struct hwrm_wol_filter_alloc_input req
= {0};
8841 struct hwrm_wol_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8844 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_ALLOC
, -1, -1);
8845 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8846 req
.wol_type
= WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
;
8847 req
.enables
= cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS
);
8848 memcpy(req
.mac_address
, bp
->dev
->dev_addr
, ETH_ALEN
);
8849 mutex_lock(&bp
->hwrm_cmd_lock
);
8850 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8852 bp
->wol_filter_id
= resp
->wol_filter_id
;
8853 mutex_unlock(&bp
->hwrm_cmd_lock
);
8857 int bnxt_hwrm_free_wol_fltr(struct bnxt
*bp
)
8859 struct hwrm_wol_filter_free_input req
= {0};
8862 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_FREE
, -1, -1);
8863 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8864 req
.enables
= cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID
);
8865 req
.wol_filter_id
= bp
->wol_filter_id
;
8866 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8870 static u16
bnxt_hwrm_get_wol_fltrs(struct bnxt
*bp
, u16 handle
)
8872 struct hwrm_wol_filter_qcfg_input req
= {0};
8873 struct hwrm_wol_filter_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8874 u16 next_handle
= 0;
8877 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_QCFG
, -1, -1);
8878 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8879 req
.handle
= cpu_to_le16(handle
);
8880 mutex_lock(&bp
->hwrm_cmd_lock
);
8881 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8883 next_handle
= le16_to_cpu(resp
->next_handle
);
8884 if (next_handle
!= 0) {
8885 if (resp
->wol_type
==
8886 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
) {
8888 bp
->wol_filter_id
= resp
->wol_filter_id
;
8892 mutex_unlock(&bp
->hwrm_cmd_lock
);
8896 static void bnxt_get_wol_settings(struct bnxt
*bp
)
8901 if (!BNXT_PF(bp
) || !(bp
->flags
& BNXT_FLAG_WOL_CAP
))
8905 handle
= bnxt_hwrm_get_wol_fltrs(bp
, handle
);
8906 } while (handle
&& handle
!= 0xffff);
8909 #ifdef CONFIG_BNXT_HWMON
8910 static ssize_t
bnxt_show_temp(struct device
*dev
,
8911 struct device_attribute
*devattr
, char *buf
)
8913 struct hwrm_temp_monitor_query_input req
= {0};
8914 struct hwrm_temp_monitor_query_output
*resp
;
8915 struct bnxt
*bp
= dev_get_drvdata(dev
);
8918 resp
= bp
->hwrm_cmd_resp_addr
;
8919 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TEMP_MONITOR_QUERY
, -1, -1);
8920 mutex_lock(&bp
->hwrm_cmd_lock
);
8921 if (!_hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
))
8922 temp
= resp
->temp
* 1000; /* display millidegree */
8923 mutex_unlock(&bp
->hwrm_cmd_lock
);
8925 return sprintf(buf
, "%u\n", temp
);
8927 static SENSOR_DEVICE_ATTR(temp1_input
, 0444, bnxt_show_temp
, NULL
, 0);
8929 static struct attribute
*bnxt_attrs
[] = {
8930 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
8933 ATTRIBUTE_GROUPS(bnxt
);
8935 static void bnxt_hwmon_close(struct bnxt
*bp
)
8937 if (bp
->hwmon_dev
) {
8938 hwmon_device_unregister(bp
->hwmon_dev
);
8939 bp
->hwmon_dev
= NULL
;
8943 static void bnxt_hwmon_open(struct bnxt
*bp
)
8945 struct pci_dev
*pdev
= bp
->pdev
;
8950 bp
->hwmon_dev
= hwmon_device_register_with_groups(&pdev
->dev
,
8951 DRV_MODULE_NAME
, bp
,
8953 if (IS_ERR(bp
->hwmon_dev
)) {
8954 bp
->hwmon_dev
= NULL
;
8955 dev_warn(&pdev
->dev
, "Cannot register hwmon device\n");
8959 static void bnxt_hwmon_close(struct bnxt
*bp
)
8963 static void bnxt_hwmon_open(struct bnxt
*bp
)
8968 static bool bnxt_eee_config_ok(struct bnxt
*bp
)
8970 struct ethtool_eee
*eee
= &bp
->eee
;
8971 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8973 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
8976 if (eee
->eee_enabled
) {
8978 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
8980 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
8981 eee
->eee_enabled
= 0;
8984 if (eee
->advertised
& ~advertising
) {
8985 eee
->advertised
= advertising
& eee
->supported
;
8992 static int bnxt_update_phy_setting(struct bnxt
*bp
)
8995 bool update_link
= false;
8996 bool update_pause
= false;
8997 bool update_eee
= false;
8998 struct bnxt_link_info
*link_info
= &bp
->link_info
;
9000 rc
= bnxt_update_link(bp
, true);
9002 netdev_err(bp
->dev
, "failed to update link (rc: %x)\n",
9006 if (!BNXT_SINGLE_PF(bp
))
9009 if ((link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
9010 (link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
) !=
9011 link_info
->req_flow_ctrl
)
9012 update_pause
= true;
9013 if (!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
9014 link_info
->force_pause_setting
!= link_info
->req_flow_ctrl
)
9015 update_pause
= true;
9016 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
9017 if (BNXT_AUTO_MODE(link_info
->auto_mode
))
9019 if (link_info
->req_link_speed
!= link_info
->force_link_speed
)
9021 if (link_info
->req_duplex
!= link_info
->duplex_setting
)
9024 if (link_info
->auto_mode
== BNXT_LINK_AUTO_NONE
)
9026 if (link_info
->advertising
!= link_info
->auto_link_speeds
)
9030 /* The last close may have shutdown the link, so need to call
9031 * PHY_CFG to bring it back up.
9033 if (!netif_carrier_ok(bp
->dev
))
9036 if (!bnxt_eee_config_ok(bp
))
9040 rc
= bnxt_hwrm_set_link_setting(bp
, update_pause
, update_eee
);
9041 else if (update_pause
)
9042 rc
= bnxt_hwrm_set_pause(bp
);
9044 netdev_err(bp
->dev
, "failed to update phy setting (rc: %x)\n",
9052 /* Common routine to pre-map certain register block to different GRC window.
9053 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
9054 * in PF and 3 windows in VF that can be customized to map in different
9057 static void bnxt_preset_reg_win(struct bnxt
*bp
)
9060 /* CAG registers map to GRC window #4 */
9061 writel(BNXT_CAG_REG_BASE
,
9062 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 12);
9066 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
);
9068 static int __bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
9072 bnxt_preset_reg_win(bp
);
9073 netif_carrier_off(bp
->dev
);
9075 /* Reserve rings now if none were reserved at driver probe. */
9076 rc
= bnxt_init_dflt_ring_mode(bp
);
9078 netdev_err(bp
->dev
, "Failed to reserve default rings at open\n");
9082 rc
= bnxt_reserve_rings(bp
, irq_re_init
);
9085 if ((bp
->flags
& BNXT_FLAG_RFS
) &&
9086 !(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
9087 /* disable RFS if falling back to INTA */
9088 bp
->dev
->hw_features
&= ~NETIF_F_NTUPLE
;
9089 bp
->flags
&= ~BNXT_FLAG_RFS
;
9092 rc
= bnxt_alloc_mem(bp
, irq_re_init
);
9094 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
9095 goto open_err_free_mem
;
9100 rc
= bnxt_request_irq(bp
);
9102 netdev_err(bp
->dev
, "bnxt_request_irq err: %x\n", rc
);
9107 bnxt_enable_napi(bp
);
9108 bnxt_debug_dev_init(bp
);
9110 rc
= bnxt_init_nic(bp
, irq_re_init
);
9112 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
9117 mutex_lock(&bp
->link_lock
);
9118 rc
= bnxt_update_phy_setting(bp
);
9119 mutex_unlock(&bp
->link_lock
);
9121 netdev_warn(bp
->dev
, "failed to update phy settings\n");
9122 if (BNXT_SINGLE_PF(bp
)) {
9123 bp
->link_info
.phy_retry
= true;
9124 bp
->link_info
.phy_retry_expires
=
9131 udp_tunnel_get_rx_info(bp
->dev
);
9133 set_bit(BNXT_STATE_OPEN
, &bp
->state
);
9134 bnxt_enable_int(bp
);
9135 /* Enable TX queues */
9137 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
9138 /* Poll link status and check for SFP+ module status */
9139 bnxt_get_port_module_status(bp
);
9141 /* VF-reps may need to be re-opened after the PF is re-opened */
9143 bnxt_vf_reps_open(bp
);
9147 bnxt_debug_dev_exit(bp
);
9148 bnxt_disable_napi(bp
);
9156 bnxt_free_mem(bp
, true);
9160 /* rtnl_lock held */
9161 int bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
9165 rc
= __bnxt_open_nic(bp
, irq_re_init
, link_re_init
);
9167 netdev_err(bp
->dev
, "nic open fail (rc: %x)\n", rc
);
9173 /* rtnl_lock held, open the NIC half way by allocating all resources, but
9174 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
9177 int bnxt_half_open_nic(struct bnxt
*bp
)
9181 rc
= bnxt_alloc_mem(bp
, false);
9183 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
9186 rc
= bnxt_init_nic(bp
, false);
9188 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
9195 bnxt_free_mem(bp
, false);
9200 /* rtnl_lock held, this call can only be made after a previous successful
9201 * call to bnxt_half_open_nic().
9203 void bnxt_half_close_nic(struct bnxt
*bp
)
9205 bnxt_hwrm_resource_free(bp
, false, false);
9207 bnxt_free_mem(bp
, false);
9210 static int bnxt_open(struct net_device
*dev
)
9212 struct bnxt
*bp
= netdev_priv(dev
);
9215 if (test_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
)) {
9216 netdev_err(bp
->dev
, "A previous firmware reset did not complete, aborting\n");
9220 rc
= bnxt_hwrm_if_change(bp
, true);
9223 rc
= __bnxt_open_nic(bp
, true, true);
9225 bnxt_hwrm_if_change(bp
, false);
9227 if (test_and_clear_bit(BNXT_STATE_FW_RESET_DET
, &bp
->state
) &&
9229 struct bnxt_pf_info
*pf
= &bp
->pf
;
9230 int n
= pf
->active_vfs
;
9233 bnxt_cfg_hw_sriov(bp
, &n
, true);
9235 bnxt_hwmon_open(bp
);
9241 static bool bnxt_drv_busy(struct bnxt
*bp
)
9243 return (test_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
) ||
9244 test_bit(BNXT_STATE_READ_STATS
, &bp
->state
));
9247 static void bnxt_get_ring_stats(struct bnxt
*bp
,
9248 struct rtnl_link_stats64
*stats
);
9250 static void __bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
,
9253 /* Close the VF-reps before closing PF */
9255 bnxt_vf_reps_close(bp
);
9257 /* Change device state to avoid TX queue wake up's */
9258 bnxt_tx_disable(bp
);
9260 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
9261 smp_mb__after_atomic();
9262 while (bnxt_drv_busy(bp
))
9265 /* Flush rings and and disable interrupts */
9266 bnxt_shutdown_nic(bp
, irq_re_init
);
9268 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
9270 bnxt_debug_dev_exit(bp
);
9271 bnxt_disable_napi(bp
);
9272 del_timer_sync(&bp
->timer
);
9273 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
) &&
9274 pci_is_enabled(bp
->pdev
))
9275 pci_disable_device(bp
->pdev
);
9279 /* Save ring stats before shutdown */
9281 bnxt_get_ring_stats(bp
, &bp
->net_stats_prev
);
9286 bnxt_free_mem(bp
, irq_re_init
);
9289 int bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
9293 if (test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
9294 /* If we get here, it means firmware reset is in progress
9295 * while we are trying to close. We can safely proceed with
9296 * the close because we are holding rtnl_lock(). Some firmware
9297 * messages may fail as we proceed to close. We set the
9298 * ABORT_ERR flag here so that the FW reset thread will later
9299 * abort when it gets the rtnl_lock() and sees the flag.
9301 netdev_warn(bp
->dev
, "FW reset in progress during close, FW reset will be aborted\n");
9302 set_bit(BNXT_STATE_ABORT_ERR
, &bp
->state
);
9305 #ifdef CONFIG_BNXT_SRIOV
9306 if (bp
->sriov_cfg
) {
9307 rc
= wait_event_interruptible_timeout(bp
->sriov_cfg_wait
,
9309 BNXT_SRIOV_CFG_WAIT_TMO
);
9311 netdev_warn(bp
->dev
, "timeout waiting for SRIOV config operation to complete!\n");
9314 __bnxt_close_nic(bp
, irq_re_init
, link_re_init
);
9318 static int bnxt_close(struct net_device
*dev
)
9320 struct bnxt
*bp
= netdev_priv(dev
);
9322 bnxt_hwmon_close(bp
);
9323 bnxt_close_nic(bp
, true, true);
9324 bnxt_hwrm_shutdown_link(bp
);
9325 bnxt_hwrm_if_change(bp
, false);
9329 static int bnxt_hwrm_port_phy_read(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
9332 struct hwrm_port_phy_mdio_read_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9333 struct hwrm_port_phy_mdio_read_input req
= {0};
9336 if (bp
->hwrm_spec_code
< 0x10a00)
9339 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_READ
, -1, -1);
9340 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
9341 req
.phy_addr
= phy_addr
;
9342 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
9343 if (mdio_phy_id_is_c45(phy_addr
)) {
9345 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
9346 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
9347 req
.reg_addr
= cpu_to_le16(reg
);
9350 mutex_lock(&bp
->hwrm_cmd_lock
);
9351 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9353 *val
= le16_to_cpu(resp
->reg_data
);
9354 mutex_unlock(&bp
->hwrm_cmd_lock
);
9358 static int bnxt_hwrm_port_phy_write(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
9361 struct hwrm_port_phy_mdio_write_input req
= {0};
9363 if (bp
->hwrm_spec_code
< 0x10a00)
9366 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_WRITE
, -1, -1);
9367 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
9368 req
.phy_addr
= phy_addr
;
9369 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
9370 if (mdio_phy_id_is_c45(phy_addr
)) {
9372 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
9373 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
9374 req
.reg_addr
= cpu_to_le16(reg
);
9376 req
.reg_data
= cpu_to_le16(val
);
9378 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9381 /* rtnl_lock held */
9382 static int bnxt_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
9384 struct mii_ioctl_data
*mdio
= if_mii(ifr
);
9385 struct bnxt
*bp
= netdev_priv(dev
);
9390 mdio
->phy_id
= bp
->link_info
.phy_addr
;
9396 if (!netif_running(dev
))
9399 rc
= bnxt_hwrm_port_phy_read(bp
, mdio
->phy_id
, mdio
->reg_num
,
9401 mdio
->val_out
= mii_regval
;
9406 if (!netif_running(dev
))
9409 return bnxt_hwrm_port_phy_write(bp
, mdio
->phy_id
, mdio
->reg_num
,
9419 static void bnxt_get_ring_stats(struct bnxt
*bp
,
9420 struct rtnl_link_stats64
*stats
)
9425 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9426 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
9427 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
9428 struct ctx_hw_stats
*hw_stats
= cpr
->hw_stats
;
9430 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_ucast_pkts
);
9431 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
9432 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_bcast_pkts
);
9434 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_ucast_pkts
);
9435 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_mcast_pkts
);
9436 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_bcast_pkts
);
9438 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_ucast_bytes
);
9439 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_mcast_bytes
);
9440 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_bcast_bytes
);
9442 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_ucast_bytes
);
9443 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_mcast_bytes
);
9444 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_bcast_bytes
);
9446 stats
->rx_missed_errors
+=
9447 le64_to_cpu(hw_stats
->rx_discard_pkts
);
9449 stats
->multicast
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
9451 stats
->tx_dropped
+= le64_to_cpu(hw_stats
->tx_drop_pkts
);
9455 static void bnxt_add_prev_stats(struct bnxt
*bp
,
9456 struct rtnl_link_stats64
*stats
)
9458 struct rtnl_link_stats64
*prev_stats
= &bp
->net_stats_prev
;
9460 stats
->rx_packets
+= prev_stats
->rx_packets
;
9461 stats
->tx_packets
+= prev_stats
->tx_packets
;
9462 stats
->rx_bytes
+= prev_stats
->rx_bytes
;
9463 stats
->tx_bytes
+= prev_stats
->tx_bytes
;
9464 stats
->rx_missed_errors
+= prev_stats
->rx_missed_errors
;
9465 stats
->multicast
+= prev_stats
->multicast
;
9466 stats
->tx_dropped
+= prev_stats
->tx_dropped
;
9470 bnxt_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
9472 struct bnxt
*bp
= netdev_priv(dev
);
9474 set_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
9475 /* Make sure bnxt_close_nic() sees that we are reading stats before
9476 * we check the BNXT_STATE_OPEN flag.
9478 smp_mb__after_atomic();
9479 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
9480 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
9481 *stats
= bp
->net_stats_prev
;
9485 bnxt_get_ring_stats(bp
, stats
);
9486 bnxt_add_prev_stats(bp
, stats
);
9488 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
9489 struct rx_port_stats
*rx
= bp
->hw_rx_port_stats
;
9490 struct tx_port_stats
*tx
= bp
->hw_tx_port_stats
;
9492 stats
->rx_crc_errors
= le64_to_cpu(rx
->rx_fcs_err_frames
);
9493 stats
->rx_frame_errors
= le64_to_cpu(rx
->rx_align_err_frames
);
9494 stats
->rx_length_errors
= le64_to_cpu(rx
->rx_undrsz_frames
) +
9495 le64_to_cpu(rx
->rx_ovrsz_frames
) +
9496 le64_to_cpu(rx
->rx_runt_frames
);
9497 stats
->rx_errors
= le64_to_cpu(rx
->rx_false_carrier_frames
) +
9498 le64_to_cpu(rx
->rx_jbr_frames
);
9499 stats
->collisions
= le64_to_cpu(tx
->tx_total_collisions
);
9500 stats
->tx_fifo_errors
= le64_to_cpu(tx
->tx_fifo_underruns
);
9501 stats
->tx_errors
= le64_to_cpu(tx
->tx_err
);
9503 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
9506 static bool bnxt_mc_list_updated(struct bnxt
*bp
, u32
*rx_mask
)
9508 struct net_device
*dev
= bp
->dev
;
9509 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
9510 struct netdev_hw_addr
*ha
;
9513 bool update
= false;
9516 netdev_for_each_mc_addr(ha
, dev
) {
9517 if (mc_count
>= BNXT_MAX_MC_ADDRS
) {
9518 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
9519 vnic
->mc_list_count
= 0;
9523 if (!ether_addr_equal(haddr
, vnic
->mc_list
+ off
)) {
9524 memcpy(vnic
->mc_list
+ off
, haddr
, ETH_ALEN
);
9531 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
;
9533 if (mc_count
!= vnic
->mc_list_count
) {
9534 vnic
->mc_list_count
= mc_count
;
9540 static bool bnxt_uc_list_updated(struct bnxt
*bp
)
9542 struct net_device
*dev
= bp
->dev
;
9543 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
9544 struct netdev_hw_addr
*ha
;
9547 if (netdev_uc_count(dev
) != (vnic
->uc_filter_count
- 1))
9550 netdev_for_each_uc_addr(ha
, dev
) {
9551 if (!ether_addr_equal(ha
->addr
, vnic
->uc_list
+ off
))
9559 static void bnxt_set_rx_mode(struct net_device
*dev
)
9561 struct bnxt
*bp
= netdev_priv(dev
);
9562 struct bnxt_vnic_info
*vnic
;
9563 bool mc_update
= false;
9567 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
))
9570 vnic
= &bp
->vnic_info
[0];
9571 mask
= vnic
->rx_mask
;
9572 mask
&= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
|
9573 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
|
9574 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
|
9575 CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
);
9577 if ((dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
9578 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
9580 uc_update
= bnxt_uc_list_updated(bp
);
9582 if (dev
->flags
& IFF_BROADCAST
)
9583 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
9584 if (dev
->flags
& IFF_ALLMULTI
) {
9585 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
9586 vnic
->mc_list_count
= 0;
9588 mc_update
= bnxt_mc_list_updated(bp
, &mask
);
9591 if (mask
!= vnic
->rx_mask
|| uc_update
|| mc_update
) {
9592 vnic
->rx_mask
= mask
;
9594 set_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
);
9595 bnxt_queue_sp_work(bp
);
9599 static int bnxt_cfg_rx_mode(struct bnxt
*bp
)
9601 struct net_device
*dev
= bp
->dev
;
9602 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
9603 struct netdev_hw_addr
*ha
;
9607 netif_addr_lock_bh(dev
);
9608 uc_update
= bnxt_uc_list_updated(bp
);
9609 netif_addr_unlock_bh(dev
);
9614 mutex_lock(&bp
->hwrm_cmd_lock
);
9615 for (i
= 1; i
< vnic
->uc_filter_count
; i
++) {
9616 struct hwrm_cfa_l2_filter_free_input req
= {0};
9618 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_FREE
, -1,
9621 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[i
];
9623 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
9626 mutex_unlock(&bp
->hwrm_cmd_lock
);
9628 vnic
->uc_filter_count
= 1;
9630 netif_addr_lock_bh(dev
);
9631 if (netdev_uc_count(dev
) > (BNXT_MAX_UC_ADDRS
- 1)) {
9632 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
9634 netdev_for_each_uc_addr(ha
, dev
) {
9635 memcpy(vnic
->uc_list
+ off
, ha
->addr
, ETH_ALEN
);
9637 vnic
->uc_filter_count
++;
9640 netif_addr_unlock_bh(dev
);
9642 for (i
= 1, off
= 0; i
< vnic
->uc_filter_count
; i
++, off
+= ETH_ALEN
) {
9643 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, i
, vnic
->uc_list
+ off
);
9645 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n",
9647 vnic
->uc_filter_count
= i
;
9653 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
9654 if (rc
&& vnic
->mc_list_count
) {
9655 netdev_info(bp
->dev
, "Failed setting MC filters rc: %d, turning on ALL_MCAST mode\n",
9657 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
9658 vnic
->mc_list_count
= 0;
9659 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
9662 netdev_err(bp
->dev
, "HWRM cfa l2 rx mask failure rc: %d\n",
9668 static bool bnxt_can_reserve_rings(struct bnxt
*bp
)
9670 #ifdef CONFIG_BNXT_SRIOV
9671 if (BNXT_NEW_RM(bp
) && BNXT_VF(bp
)) {
9672 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
9674 /* No minimum rings were provisioned by the PF. Don't
9675 * reserve rings by default when device is down.
9677 if (hw_resc
->min_tx_rings
|| hw_resc
->resv_tx_rings
)
9680 if (!netif_running(bp
->dev
))
9687 /* If the chip and firmware supports RFS */
9688 static bool bnxt_rfs_supported(struct bnxt
*bp
)
9690 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
9691 if (bp
->fw_cap
& BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX
)
9695 if (BNXT_PF(bp
) && !BNXT_CHIP_TYPE_NITRO_A0(bp
))
9697 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
9702 /* If runtime conditions support RFS */
9703 static bool bnxt_rfs_capable(struct bnxt
*bp
)
9705 #ifdef CONFIG_RFS_ACCEL
9706 int vnics
, max_vnics
, max_rss_ctxs
;
9708 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
9709 return bnxt_rfs_supported(bp
);
9710 if (!(bp
->flags
& BNXT_FLAG_MSIX_CAP
) || !bnxt_can_reserve_rings(bp
))
9713 vnics
= 1 + bp
->rx_nr_rings
;
9714 max_vnics
= bnxt_get_max_func_vnics(bp
);
9715 max_rss_ctxs
= bnxt_get_max_func_rss_ctxs(bp
);
9717 /* RSS contexts not a limiting factor */
9718 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
9719 max_rss_ctxs
= max_vnics
;
9720 if (vnics
> max_vnics
|| vnics
> max_rss_ctxs
) {
9721 if (bp
->rx_nr_rings
> 1)
9722 netdev_warn(bp
->dev
,
9723 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
9724 min(max_rss_ctxs
- 1, max_vnics
- 1));
9728 if (!BNXT_NEW_RM(bp
))
9731 if (vnics
== bp
->hw_resc
.resv_vnics
)
9734 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, vnics
);
9735 if (vnics
<= bp
->hw_resc
.resv_vnics
)
9738 netdev_warn(bp
->dev
, "Unable to reserve resources to support NTUPLE filters.\n");
9739 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, 1);
9746 static netdev_features_t
bnxt_fix_features(struct net_device
*dev
,
9747 netdev_features_t features
)
9749 struct bnxt
*bp
= netdev_priv(dev
);
9751 if ((features
& NETIF_F_NTUPLE
) && !bnxt_rfs_capable(bp
))
9752 features
&= ~NETIF_F_NTUPLE
;
9754 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
9755 features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
9757 if (!(features
& NETIF_F_GRO
))
9758 features
&= ~NETIF_F_GRO_HW
;
9760 if (features
& NETIF_F_GRO_HW
)
9761 features
&= ~NETIF_F_LRO
;
9763 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
9764 * turned on or off together.
9766 if ((features
& (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) !=
9767 (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) {
9768 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
9769 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
9770 NETIF_F_HW_VLAN_STAG_RX
);
9772 features
|= NETIF_F_HW_VLAN_CTAG_RX
|
9773 NETIF_F_HW_VLAN_STAG_RX
;
9775 #ifdef CONFIG_BNXT_SRIOV
9778 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
9779 NETIF_F_HW_VLAN_STAG_RX
);
9786 static int bnxt_set_features(struct net_device
*dev
, netdev_features_t features
)
9788 struct bnxt
*bp
= netdev_priv(dev
);
9789 u32 flags
= bp
->flags
;
9792 bool re_init
= false;
9793 bool update_tpa
= false;
9795 flags
&= ~BNXT_FLAG_ALL_CONFIG_FEATS
;
9796 if (features
& NETIF_F_GRO_HW
)
9797 flags
|= BNXT_FLAG_GRO
;
9798 else if (features
& NETIF_F_LRO
)
9799 flags
|= BNXT_FLAG_LRO
;
9801 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
9802 flags
&= ~BNXT_FLAG_TPA
;
9804 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
9805 flags
|= BNXT_FLAG_STRIP_VLAN
;
9807 if (features
& NETIF_F_NTUPLE
)
9808 flags
|= BNXT_FLAG_RFS
;
9810 changes
= flags
^ bp
->flags
;
9811 if (changes
& BNXT_FLAG_TPA
) {
9813 if ((bp
->flags
& BNXT_FLAG_TPA
) == 0 ||
9814 (flags
& BNXT_FLAG_TPA
) == 0 ||
9815 (bp
->flags
& BNXT_FLAG_CHIP_P5
))
9819 if (changes
& ~BNXT_FLAG_TPA
)
9822 if (flags
!= bp
->flags
) {
9823 u32 old_flags
= bp
->flags
;
9825 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
9828 bnxt_set_ring_params(bp
);
9833 bnxt_close_nic(bp
, false, false);
9836 bnxt_set_ring_params(bp
);
9838 return bnxt_open_nic(bp
, false, false);
9842 rc
= bnxt_set_tpa(bp
,
9843 (flags
& BNXT_FLAG_TPA
) ?
9846 bp
->flags
= old_flags
;
9852 static int bnxt_dbg_hwrm_ring_info_get(struct bnxt
*bp
, u8 ring_type
,
9853 u32 ring_id
, u32
*prod
, u32
*cons
)
9855 struct hwrm_dbg_ring_info_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9856 struct hwrm_dbg_ring_info_get_input req
= {0};
9859 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_DBG_RING_INFO_GET
, -1, -1);
9860 req
.ring_type
= ring_type
;
9861 req
.fw_ring_id
= cpu_to_le32(ring_id
);
9862 mutex_lock(&bp
->hwrm_cmd_lock
);
9863 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9865 *prod
= le32_to_cpu(resp
->producer_index
);
9866 *cons
= le32_to_cpu(resp
->consumer_index
);
9868 mutex_unlock(&bp
->hwrm_cmd_lock
);
9872 static void bnxt_dump_tx_sw_state(struct bnxt_napi
*bnapi
)
9874 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
9875 int i
= bnapi
->index
;
9880 netdev_info(bnapi
->bp
->dev
, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
9881 i
, txr
->tx_ring_struct
.fw_ring_id
, txr
->tx_prod
,
9885 static void bnxt_dump_rx_sw_state(struct bnxt_napi
*bnapi
)
9887 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
9888 int i
= bnapi
->index
;
9893 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",
9894 i
, rxr
->rx_ring_struct
.fw_ring_id
, rxr
->rx_prod
,
9895 rxr
->rx_agg_ring_struct
.fw_ring_id
, rxr
->rx_agg_prod
,
9896 rxr
->rx_sw_agg_prod
);
9899 static void bnxt_dump_cp_sw_state(struct bnxt_napi
*bnapi
)
9901 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
9902 int i
= bnapi
->index
;
9904 netdev_info(bnapi
->bp
->dev
, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
9905 i
, cpr
->cp_ring_struct
.fw_ring_id
, cpr
->cp_raw_cons
);
9908 static void bnxt_dbg_dump_states(struct bnxt
*bp
)
9911 struct bnxt_napi
*bnapi
;
9913 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9914 bnapi
= bp
->bnapi
[i
];
9915 if (netif_msg_drv(bp
)) {
9916 bnxt_dump_tx_sw_state(bnapi
);
9917 bnxt_dump_rx_sw_state(bnapi
);
9918 bnxt_dump_cp_sw_state(bnapi
);
9923 static void bnxt_reset_task(struct bnxt
*bp
, bool silent
)
9926 bnxt_dbg_dump_states(bp
);
9927 if (netif_running(bp
->dev
)) {
9932 bnxt_close_nic(bp
, false, false);
9933 rc
= bnxt_open_nic(bp
, false, false);
9939 static void bnxt_tx_timeout(struct net_device
*dev
)
9941 struct bnxt
*bp
= netdev_priv(dev
);
9943 netdev_err(bp
->dev
, "TX timeout detected, starting reset task!\n");
9944 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
9945 bnxt_queue_sp_work(bp
);
9948 static void bnxt_fw_health_check(struct bnxt
*bp
)
9950 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
9953 if (!fw_health
|| !fw_health
->enabled
||
9954 test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
9957 if (fw_health
->tmr_counter
) {
9958 fw_health
->tmr_counter
--;
9962 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
9963 if (val
== fw_health
->last_fw_heartbeat
)
9966 fw_health
->last_fw_heartbeat
= val
;
9968 val
= bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
9969 if (val
!= fw_health
->last_fw_reset_cnt
)
9972 fw_health
->tmr_counter
= fw_health
->tmr_multiplier
;
9976 set_bit(BNXT_FW_EXCEPTION_SP_EVENT
, &bp
->sp_event
);
9977 bnxt_queue_sp_work(bp
);
9980 static void bnxt_timer(struct timer_list
*t
)
9982 struct bnxt
*bp
= from_timer(bp
, t
, timer
);
9983 struct net_device
*dev
= bp
->dev
;
9985 if (!netif_running(dev
))
9988 if (atomic_read(&bp
->intr_sem
) != 0)
9989 goto bnxt_restart_timer
;
9991 if (bp
->fw_cap
& BNXT_FW_CAP_ERROR_RECOVERY
)
9992 bnxt_fw_health_check(bp
);
9994 if (bp
->link_info
.link_up
&& (bp
->flags
& BNXT_FLAG_PORT_STATS
) &&
9995 bp
->stats_coal_ticks
) {
9996 set_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
);
9997 bnxt_queue_sp_work(bp
);
10000 if (bnxt_tc_flower_enabled(bp
)) {
10001 set_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
);
10002 bnxt_queue_sp_work(bp
);
10005 if (bp
->link_info
.phy_retry
) {
10006 if (time_after(jiffies
, bp
->link_info
.phy_retry_expires
)) {
10007 bp
->link_info
.phy_retry
= false;
10008 netdev_warn(bp
->dev
, "failed to update phy settings after maximum retries.\n");
10010 set_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
);
10011 bnxt_queue_sp_work(bp
);
10015 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && netif_carrier_ok(dev
)) {
10016 set_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
);
10017 bnxt_queue_sp_work(bp
);
10019 bnxt_restart_timer
:
10020 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
10023 static void bnxt_rtnl_lock_sp(struct bnxt
*bp
)
10025 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
10026 * set. If the device is being closed, bnxt_close() may be holding
10027 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
10028 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
10030 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
10034 static void bnxt_rtnl_unlock_sp(struct bnxt
*bp
)
10036 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
10040 /* Only called from bnxt_sp_task() */
10041 static void bnxt_reset(struct bnxt
*bp
, bool silent
)
10043 bnxt_rtnl_lock_sp(bp
);
10044 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
))
10045 bnxt_reset_task(bp
, silent
);
10046 bnxt_rtnl_unlock_sp(bp
);
10049 static void bnxt_fw_reset_close(struct bnxt
*bp
)
10051 __bnxt_close_nic(bp
, true, false);
10052 bnxt_ulp_irq_stop(bp
);
10053 bnxt_clear_int_mode(bp
);
10054 bnxt_hwrm_func_drv_unrgtr(bp
);
10055 bnxt_free_ctx_mem(bp
);
10060 static bool is_bnxt_fw_ok(struct bnxt
*bp
)
10062 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
10063 bool no_heartbeat
= false, has_reset
= false;
10066 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEARTBEAT_REG
);
10067 if (val
== fw_health
->last_fw_heartbeat
)
10068 no_heartbeat
= true;
10070 val
= bnxt_fw_health_readl(bp
, BNXT_FW_RESET_CNT_REG
);
10071 if (val
!= fw_health
->last_fw_reset_cnt
)
10074 if (!no_heartbeat
&& has_reset
)
10080 /* rtnl_lock is acquired before calling this function */
10081 static void bnxt_force_fw_reset(struct bnxt
*bp
)
10083 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
10086 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
) ||
10087 test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
))
10090 set_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10091 bnxt_fw_reset_close(bp
);
10092 wait_dsecs
= fw_health
->master_func_wait_dsecs
;
10093 if (fw_health
->master
) {
10094 if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
)
10096 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_RESET_FW
;
10098 bp
->fw_reset_timestamp
= jiffies
+ wait_dsecs
* HZ
/ 10;
10099 wait_dsecs
= fw_health
->normal_func_wait_dsecs
;
10100 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
10103 bp
->fw_reset_min_dsecs
= fw_health
->post_reset_wait_dsecs
;
10104 bp
->fw_reset_max_dsecs
= fw_health
->post_reset_max_wait_dsecs
;
10105 bnxt_queue_fw_reset_work(bp
, wait_dsecs
* HZ
/ 10);
10108 void bnxt_fw_exception(struct bnxt
*bp
)
10110 set_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
10111 bnxt_rtnl_lock_sp(bp
);
10112 bnxt_force_fw_reset(bp
);
10113 bnxt_rtnl_unlock_sp(bp
);
10116 /* Returns the number of registered VFs, or 1 if VF configuration is pending, or
10119 static int bnxt_get_registered_vfs(struct bnxt
*bp
)
10121 #ifdef CONFIG_BNXT_SRIOV
10127 rc
= bnxt_hwrm_func_qcfg(bp
);
10129 netdev_err(bp
->dev
, "func_qcfg cmd failed, rc = %d\n", rc
);
10132 if (bp
->pf
.registered_vfs
)
10133 return bp
->pf
.registered_vfs
;
10140 void bnxt_fw_reset(struct bnxt
*bp
)
10142 bnxt_rtnl_lock_sp(bp
);
10143 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
) &&
10144 !test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
10147 set_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10148 if (bp
->pf
.active_vfs
&&
10149 !test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
))
10150 n
= bnxt_get_registered_vfs(bp
);
10152 netdev_err(bp
->dev
, "Firmware reset aborted, rc = %d\n",
10154 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10155 dev_close(bp
->dev
);
10156 goto fw_reset_exit
;
10157 } else if (n
> 0) {
10158 u16 vf_tmo_dsecs
= n
* 10;
10160 if (bp
->fw_reset_max_dsecs
< vf_tmo_dsecs
)
10161 bp
->fw_reset_max_dsecs
= vf_tmo_dsecs
;
10162 bp
->fw_reset_state
=
10163 BNXT_FW_RESET_STATE_POLL_VF
;
10164 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
10165 goto fw_reset_exit
;
10167 bnxt_fw_reset_close(bp
);
10168 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
10169 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW_DOWN
;
10172 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
10173 tmo
= bp
->fw_reset_min_dsecs
* HZ
/ 10;
10175 bnxt_queue_fw_reset_work(bp
, tmo
);
10178 bnxt_rtnl_unlock_sp(bp
);
10181 static void bnxt_chk_missed_irq(struct bnxt
*bp
)
10185 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
10188 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
10189 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
10190 struct bnxt_cp_ring_info
*cpr
;
10197 cpr
= &bnapi
->cp_ring
;
10198 for (j
= 0; j
< 2; j
++) {
10199 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
10202 if (!cpr2
|| cpr2
->has_more_work
||
10203 !bnxt_has_work(bp
, cpr2
))
10206 if (cpr2
->cp_raw_cons
!= cpr2
->last_cp_raw_cons
) {
10207 cpr2
->last_cp_raw_cons
= cpr2
->cp_raw_cons
;
10210 fw_ring_id
= cpr2
->cp_ring_struct
.fw_ring_id
;
10211 bnxt_dbg_hwrm_ring_info_get(bp
,
10212 DBG_RING_INFO_GET_REQ_RING_TYPE_L2_CMPL
,
10213 fw_ring_id
, &val
[0], &val
[1]);
10214 cpr
->missed_irqs
++;
10219 static void bnxt_cfg_ntp_filters(struct bnxt
*);
10221 static void bnxt_sp_task(struct work_struct
*work
)
10223 struct bnxt
*bp
= container_of(work
, struct bnxt
, sp_task
);
10225 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
10226 smp_mb__after_atomic();
10227 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
10228 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
10232 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
))
10233 bnxt_cfg_rx_mode(bp
);
10235 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
))
10236 bnxt_cfg_ntp_filters(bp
);
10237 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
))
10238 bnxt_hwrm_exec_fwd_req(bp
);
10239 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
10240 bnxt_hwrm_tunnel_dst_port_alloc(
10241 bp
, bp
->vxlan_port
,
10242 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
10244 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
10245 bnxt_hwrm_tunnel_dst_port_free(
10246 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
10248 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
10249 bnxt_hwrm_tunnel_dst_port_alloc(
10251 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
10253 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
10254 bnxt_hwrm_tunnel_dst_port_free(
10255 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
10257 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
)) {
10258 bnxt_hwrm_port_qstats(bp
);
10259 bnxt_hwrm_port_qstats_ext(bp
);
10260 bnxt_hwrm_pcie_qstats(bp
);
10263 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
)) {
10266 mutex_lock(&bp
->link_lock
);
10267 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
,
10269 bnxt_hwrm_phy_qcaps(bp
);
10271 rc
= bnxt_update_link(bp
, true);
10272 mutex_unlock(&bp
->link_lock
);
10274 netdev_err(bp
->dev
, "SP task can't update link (rc: %x)\n",
10277 if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
)) {
10280 mutex_lock(&bp
->link_lock
);
10281 rc
= bnxt_update_phy_setting(bp
);
10282 mutex_unlock(&bp
->link_lock
);
10284 netdev_warn(bp
->dev
, "update phy settings retry failed\n");
10286 bp
->link_info
.phy_retry
= false;
10287 netdev_info(bp
->dev
, "update phy settings retry succeeded\n");
10290 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
)) {
10291 mutex_lock(&bp
->link_lock
);
10292 bnxt_get_port_module_status(bp
);
10293 mutex_unlock(&bp
->link_lock
);
10296 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
))
10297 bnxt_tc_flow_stats_work(bp
);
10299 if (test_and_clear_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
))
10300 bnxt_chk_missed_irq(bp
);
10302 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
10303 * must be the last functions to be called before exiting.
10305 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
))
10306 bnxt_reset(bp
, false);
10308 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
))
10309 bnxt_reset(bp
, true);
10311 if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT
, &bp
->sp_event
))
10312 bnxt_devlink_health_report(bp
, BNXT_FW_RESET_NOTIFY_SP_EVENT
);
10314 if (test_and_clear_bit(BNXT_FW_EXCEPTION_SP_EVENT
, &bp
->sp_event
)) {
10315 if (!is_bnxt_fw_ok(bp
))
10316 bnxt_devlink_health_report(bp
,
10317 BNXT_FW_EXCEPTION_SP_EVENT
);
10320 smp_mb__before_atomic();
10321 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
10324 /* Under rtnl_lock */
10325 int bnxt_check_rings(struct bnxt
*bp
, int tx
, int rx
, bool sh
, int tcs
,
10328 int max_rx
, max_tx
, tx_sets
= 1;
10329 int tx_rings_needed
, stats
;
10336 rc
= bnxt_get_max_rings(bp
, &max_rx
, &max_tx
, sh
);
10343 tx_rings_needed
= tx
* tx_sets
+ tx_xdp
;
10344 if (max_tx
< tx_rings_needed
)
10348 if ((bp
->flags
& (BNXT_FLAG_RFS
| BNXT_FLAG_CHIP_P5
)) == BNXT_FLAG_RFS
)
10351 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
10353 cp
= sh
? max_t(int, tx_rings_needed
, rx
) : tx_rings_needed
+ rx
;
10355 if (BNXT_NEW_RM(bp
)) {
10356 cp
+= bnxt_get_ulp_msix_num(bp
);
10357 stats
+= bnxt_get_ulp_stat_ctxs(bp
);
10359 return bnxt_hwrm_check_rings(bp
, tx_rings_needed
, rx_rings
, rx
, cp
,
10363 static void bnxt_unmap_bars(struct bnxt
*bp
, struct pci_dev
*pdev
)
10366 pci_iounmap(pdev
, bp
->bar2
);
10371 pci_iounmap(pdev
, bp
->bar1
);
10376 pci_iounmap(pdev
, bp
->bar0
);
10381 static void bnxt_cleanup_pci(struct bnxt
*bp
)
10383 bnxt_unmap_bars(bp
, bp
->pdev
);
10384 pci_release_regions(bp
->pdev
);
10385 pci_disable_device(bp
->pdev
);
10388 static void bnxt_init_dflt_coal(struct bnxt
*bp
)
10390 struct bnxt_coal
*coal
;
10392 /* Tick values in micro seconds.
10393 * 1 coal_buf x bufs_per_record = 1 completion record.
10395 coal
= &bp
->rx_coal
;
10396 coal
->coal_ticks
= 10;
10397 coal
->coal_bufs
= 30;
10398 coal
->coal_ticks_irq
= 1;
10399 coal
->coal_bufs_irq
= 2;
10400 coal
->idle_thresh
= 50;
10401 coal
->bufs_per_record
= 2;
10402 coal
->budget
= 64; /* NAPI budget */
10404 coal
= &bp
->tx_coal
;
10405 coal
->coal_ticks
= 28;
10406 coal
->coal_bufs
= 30;
10407 coal
->coal_ticks_irq
= 2;
10408 coal
->coal_bufs_irq
= 2;
10409 coal
->bufs_per_record
= 1;
10411 bp
->stats_coal_ticks
= BNXT_DEF_STATS_COAL_TICKS
;
10414 static int bnxt_fw_init_one_p1(struct bnxt
*bp
)
10419 rc
= bnxt_hwrm_ver_get(bp
);
10423 if (bp
->fw_cap
& BNXT_FW_CAP_KONG_MB_CHNL
) {
10424 rc
= bnxt_alloc_kong_hwrm_resources(bp
);
10426 bp
->fw_cap
&= ~BNXT_FW_CAP_KONG_MB_CHNL
;
10429 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
10430 bp
->hwrm_max_ext_req_len
> BNXT_HWRM_MAX_REQ_LEN
) {
10431 rc
= bnxt_alloc_hwrm_short_cmd_req(bp
);
10435 rc
= bnxt_hwrm_func_reset(bp
);
10439 bnxt_hwrm_fw_set_time(bp
);
10443 static int bnxt_fw_init_one_p2(struct bnxt
*bp
)
10447 /* Get the MAX capabilities for this function */
10448 rc
= bnxt_hwrm_func_qcaps(bp
);
10450 netdev_err(bp
->dev
, "hwrm query capability failure rc: %x\n",
10455 rc
= bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(bp
);
10457 netdev_warn(bp
->dev
, "hwrm query adv flow mgnt failure rc: %d\n",
10460 rc
= bnxt_hwrm_error_recovery_qcfg(bp
);
10462 netdev_warn(bp
->dev
, "hwrm query error recovery failure rc: %d\n",
10465 rc
= bnxt_hwrm_func_drv_rgtr(bp
);
10469 rc
= bnxt_hwrm_func_rgtr_async_events(bp
, NULL
, 0);
10473 bnxt_hwrm_func_qcfg(bp
);
10474 bnxt_hwrm_vnic_qcaps(bp
);
10475 bnxt_hwrm_port_led_qcaps(bp
);
10476 bnxt_ethtool_init(bp
);
10481 static void bnxt_set_dflt_rss_hash_type(struct bnxt
*bp
)
10483 bp
->flags
&= ~BNXT_FLAG_UDP_RSS_CAP
;
10484 bp
->rss_hash_cfg
= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
|
10485 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
|
10486 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
|
10487 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
10488 if (BNXT_CHIP_P4(bp
) && bp
->hwrm_spec_code
>= 0x10501) {
10489 bp
->flags
|= BNXT_FLAG_UDP_RSS_CAP
;
10490 bp
->rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
|
10491 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
10495 static void bnxt_set_dflt_rfs(struct bnxt
*bp
)
10497 struct net_device
*dev
= bp
->dev
;
10499 dev
->hw_features
&= ~NETIF_F_NTUPLE
;
10500 dev
->features
&= ~NETIF_F_NTUPLE
;
10501 bp
->flags
&= ~BNXT_FLAG_RFS
;
10502 if (bnxt_rfs_supported(bp
)) {
10503 dev
->hw_features
|= NETIF_F_NTUPLE
;
10504 if (bnxt_rfs_capable(bp
)) {
10505 bp
->flags
|= BNXT_FLAG_RFS
;
10506 dev
->features
|= NETIF_F_NTUPLE
;
10511 static void bnxt_fw_init_one_p3(struct bnxt
*bp
)
10513 struct pci_dev
*pdev
= bp
->pdev
;
10515 bnxt_set_dflt_rss_hash_type(bp
);
10516 bnxt_set_dflt_rfs(bp
);
10518 bnxt_get_wol_settings(bp
);
10519 if (bp
->flags
& BNXT_FLAG_WOL_CAP
)
10520 device_set_wakeup_enable(&pdev
->dev
, bp
->wol
);
10522 device_set_wakeup_capable(&pdev
->dev
, false);
10524 bnxt_hwrm_set_cache_line_size(bp
, cache_line_size());
10525 bnxt_hwrm_coal_params_qcaps(bp
);
10528 static int bnxt_fw_init_one(struct bnxt
*bp
)
10532 rc
= bnxt_fw_init_one_p1(bp
);
10534 netdev_err(bp
->dev
, "Firmware init phase 1 failed\n");
10537 rc
= bnxt_fw_init_one_p2(bp
);
10539 netdev_err(bp
->dev
, "Firmware init phase 2 failed\n");
10542 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, false);
10545 bnxt_fw_init_one_p3(bp
);
10549 static void bnxt_fw_reset_writel(struct bnxt
*bp
, int reg_idx
)
10551 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
10552 u32 reg
= fw_health
->fw_reset_seq_regs
[reg_idx
];
10553 u32 val
= fw_health
->fw_reset_seq_vals
[reg_idx
];
10554 u32 reg_type
, reg_off
, delay_msecs
;
10556 delay_msecs
= fw_health
->fw_reset_seq_delay_msec
[reg_idx
];
10557 reg_type
= BNXT_FW_HEALTH_REG_TYPE(reg
);
10558 reg_off
= BNXT_FW_HEALTH_REG_OFF(reg
);
10559 switch (reg_type
) {
10560 case BNXT_FW_HEALTH_REG_TYPE_CFG
:
10561 pci_write_config_dword(bp
->pdev
, reg_off
, val
);
10563 case BNXT_FW_HEALTH_REG_TYPE_GRC
:
10564 writel(reg_off
& BNXT_GRC_BASE_MASK
,
10565 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 4);
10566 reg_off
= (reg_off
& BNXT_GRC_OFFSET_MASK
) + 0x2000;
10568 case BNXT_FW_HEALTH_REG_TYPE_BAR0
:
10569 writel(val
, bp
->bar0
+ reg_off
);
10571 case BNXT_FW_HEALTH_REG_TYPE_BAR1
:
10572 writel(val
, bp
->bar1
+ reg_off
);
10576 pci_read_config_dword(bp
->pdev
, 0, &val
);
10577 msleep(delay_msecs
);
10581 static void bnxt_reset_all(struct bnxt
*bp
)
10583 struct bnxt_fw_health
*fw_health
= bp
->fw_health
;
10586 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
10587 #ifdef CONFIG_TEE_BNXT_FW
10588 rc
= tee_bnxt_fw_load();
10590 netdev_err(bp
->dev
, "Unable to reset FW rc=%d\n", rc
);
10591 bp
->fw_reset_timestamp
= jiffies
;
10596 if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_HOST
) {
10597 for (i
= 0; i
< fw_health
->fw_reset_seq_cnt
; i
++)
10598 bnxt_fw_reset_writel(bp
, i
);
10599 } else if (fw_health
->flags
& ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU
) {
10600 struct hwrm_fw_reset_input req
= {0};
10602 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_RESET
, -1, -1);
10603 req
.resp_addr
= cpu_to_le64(bp
->hwrm_cmd_kong_resp_dma_addr
);
10604 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP
;
10605 req
.selfrst_status
= FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP
;
10606 req
.flags
= FW_RESET_REQ_FLAGS_RESET_GRACEFUL
;
10607 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
10609 netdev_warn(bp
->dev
, "Unable to reset FW rc=%d\n", rc
);
10611 bp
->fw_reset_timestamp
= jiffies
;
10614 static void bnxt_fw_reset_task(struct work_struct
*work
)
10616 struct bnxt
*bp
= container_of(work
, struct bnxt
, fw_reset_task
.work
);
10619 if (!test_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
)) {
10620 netdev_err(bp
->dev
, "bnxt_fw_reset_task() called when not in fw reset mode!\n");
10624 switch (bp
->fw_reset_state
) {
10625 case BNXT_FW_RESET_STATE_POLL_VF
: {
10626 int n
= bnxt_get_registered_vfs(bp
);
10630 netdev_err(bp
->dev
, "Firmware reset aborted, subsequent func_qcfg cmd failed, rc = %d, %d msecs since reset timestamp\n",
10631 n
, jiffies_to_msecs(jiffies
-
10632 bp
->fw_reset_timestamp
));
10633 goto fw_reset_abort
;
10634 } else if (n
> 0) {
10635 if (time_after(jiffies
, bp
->fw_reset_timestamp
+
10636 (bp
->fw_reset_max_dsecs
* HZ
/ 10))) {
10637 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10638 bp
->fw_reset_state
= 0;
10639 netdev_err(bp
->dev
, "Firmware reset aborted, bnxt_get_registered_vfs() returns %d\n",
10643 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
10646 bp
->fw_reset_timestamp
= jiffies
;
10648 bnxt_fw_reset_close(bp
);
10649 if (bp
->fw_cap
& BNXT_FW_CAP_ERR_RECOVER_RELOAD
) {
10650 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW_DOWN
;
10653 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
10654 tmo
= bp
->fw_reset_min_dsecs
* HZ
/ 10;
10657 bnxt_queue_fw_reset_work(bp
, tmo
);
10660 case BNXT_FW_RESET_STATE_POLL_FW_DOWN
: {
10663 val
= bnxt_fw_health_readl(bp
, BNXT_FW_HEALTH_REG
);
10664 if (!(val
& BNXT_FW_STATUS_SHUTDOWN
) &&
10665 !time_after(jiffies
, bp
->fw_reset_timestamp
+
10666 (bp
->fw_reset_max_dsecs
* HZ
/ 10))) {
10667 bnxt_queue_fw_reset_work(bp
, HZ
/ 5);
10671 if (!bp
->fw_health
->master
) {
10672 u32 wait_dsecs
= bp
->fw_health
->normal_func_wait_dsecs
;
10674 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
10675 bnxt_queue_fw_reset_work(bp
, wait_dsecs
* HZ
/ 10);
10678 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_RESET_FW
;
10681 case BNXT_FW_RESET_STATE_RESET_FW
: {
10682 u32 wait_dsecs
= bp
->fw_health
->post_reset_wait_dsecs
;
10684 bnxt_reset_all(bp
);
10685 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_ENABLE_DEV
;
10686 bnxt_queue_fw_reset_work(bp
, wait_dsecs
* HZ
/ 10);
10689 case BNXT_FW_RESET_STATE_ENABLE_DEV
:
10690 if (test_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
) &&
10694 val
= bnxt_fw_health_readl(bp
,
10695 BNXT_FW_RESET_INPROG_REG
);
10697 netdev_warn(bp
->dev
, "FW reset inprog %x after min wait time.\n",
10700 clear_bit(BNXT_STATE_FW_FATAL_COND
, &bp
->state
);
10701 if (pci_enable_device(bp
->pdev
)) {
10702 netdev_err(bp
->dev
, "Cannot re-enable PCI device\n");
10703 goto fw_reset_abort
;
10705 pci_set_master(bp
->pdev
);
10706 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_POLL_FW
;
10708 case BNXT_FW_RESET_STATE_POLL_FW
:
10709 bp
->hwrm_cmd_timeout
= SHORT_HWRM_CMD_TIMEOUT
;
10710 rc
= __bnxt_hwrm_ver_get(bp
, true);
10712 if (time_after(jiffies
, bp
->fw_reset_timestamp
+
10713 (bp
->fw_reset_max_dsecs
* HZ
/ 10))) {
10714 netdev_err(bp
->dev
, "Firmware reset aborted\n");
10715 goto fw_reset_abort
;
10717 bnxt_queue_fw_reset_work(bp
, HZ
/ 5);
10720 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
10721 bp
->fw_reset_state
= BNXT_FW_RESET_STATE_OPENING
;
10723 case BNXT_FW_RESET_STATE_OPENING
:
10724 while (!rtnl_trylock()) {
10725 bnxt_queue_fw_reset_work(bp
, HZ
/ 10);
10728 rc
= bnxt_open(bp
->dev
);
10730 netdev_err(bp
->dev
, "bnxt_open_nic() failed\n");
10731 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10732 dev_close(bp
->dev
);
10734 bnxt_ulp_irq_restart(bp
, rc
);
10737 bp
->fw_reset_state
= 0;
10738 /* Make sure fw_reset_state is 0 before clearing the flag */
10739 smp_mb__before_atomic();
10740 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10746 clear_bit(BNXT_STATE_IN_FW_RESET
, &bp
->state
);
10747 bp
->fw_reset_state
= 0;
10749 dev_close(bp
->dev
);
10753 static int bnxt_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
10756 struct bnxt
*bp
= netdev_priv(dev
);
10758 SET_NETDEV_DEV(dev
, &pdev
->dev
);
10760 /* enable device (incl. PCI PM wakeup), and bus-mastering */
10761 rc
= pci_enable_device(pdev
);
10763 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
10767 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
10768 dev_err(&pdev
->dev
,
10769 "Cannot find PCI device base address, aborting\n");
10771 goto init_err_disable
;
10774 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
10776 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
10777 goto init_err_disable
;
10780 if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64)) != 0 &&
10781 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)) != 0) {
10782 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
10783 goto init_err_disable
;
10786 pci_set_master(pdev
);
10791 bp
->bar0
= pci_ioremap_bar(pdev
, 0);
10793 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
10795 goto init_err_release
;
10798 bp
->bar1
= pci_ioremap_bar(pdev
, 2);
10800 dev_err(&pdev
->dev
, "Cannot map doorbell registers, aborting\n");
10802 goto init_err_release
;
10805 bp
->bar2
= pci_ioremap_bar(pdev
, 4);
10807 dev_err(&pdev
->dev
, "Cannot map bar4 registers, aborting\n");
10809 goto init_err_release
;
10812 pci_enable_pcie_error_reporting(pdev
);
10814 INIT_WORK(&bp
->sp_task
, bnxt_sp_task
);
10815 INIT_DELAYED_WORK(&bp
->fw_reset_task
, bnxt_fw_reset_task
);
10817 spin_lock_init(&bp
->ntp_fltr_lock
);
10818 #if BITS_PER_LONG == 32
10819 spin_lock_init(&bp
->db_lock
);
10822 bp
->rx_ring_size
= BNXT_DEFAULT_RX_RING_SIZE
;
10823 bp
->tx_ring_size
= BNXT_DEFAULT_TX_RING_SIZE
;
10825 bnxt_init_dflt_coal(bp
);
10827 timer_setup(&bp
->timer
, bnxt_timer
, 0);
10828 bp
->current_interval
= BNXT_TIMER_INTERVAL
;
10830 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
10834 bnxt_unmap_bars(bp
, pdev
);
10835 pci_release_regions(pdev
);
10838 pci_disable_device(pdev
);
10844 /* rtnl_lock held */
10845 static int bnxt_change_mac_addr(struct net_device
*dev
, void *p
)
10847 struct sockaddr
*addr
= p
;
10848 struct bnxt
*bp
= netdev_priv(dev
);
10851 if (!is_valid_ether_addr(addr
->sa_data
))
10852 return -EADDRNOTAVAIL
;
10854 if (ether_addr_equal(addr
->sa_data
, dev
->dev_addr
))
10857 rc
= bnxt_approve_mac(bp
, addr
->sa_data
, true);
10861 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
10862 if (netif_running(dev
)) {
10863 bnxt_close_nic(bp
, false, false);
10864 rc
= bnxt_open_nic(bp
, false, false);
10870 /* rtnl_lock held */
10871 static int bnxt_change_mtu(struct net_device
*dev
, int new_mtu
)
10873 struct bnxt
*bp
= netdev_priv(dev
);
10875 if (netif_running(dev
))
10876 bnxt_close_nic(bp
, false, false);
10878 dev
->mtu
= new_mtu
;
10879 bnxt_set_ring_params(bp
);
10881 if (netif_running(dev
))
10882 return bnxt_open_nic(bp
, false, false);
10887 int bnxt_setup_mq_tc(struct net_device
*dev
, u8 tc
)
10889 struct bnxt
*bp
= netdev_priv(dev
);
10893 if (tc
> bp
->max_tc
) {
10894 netdev_err(dev
, "Too many traffic classes requested: %d. Max supported is %d.\n",
10899 if (netdev_get_num_tc(dev
) == tc
)
10902 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
10905 rc
= bnxt_check_rings(bp
, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
,
10906 sh
, tc
, bp
->tx_nr_rings_xdp
);
10910 /* Needs to close the device and do hw resource re-allocations */
10911 if (netif_running(bp
->dev
))
10912 bnxt_close_nic(bp
, true, false);
10915 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tc
;
10916 netdev_set_num_tc(dev
, tc
);
10918 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
10919 netdev_reset_tc(dev
);
10921 bp
->tx_nr_rings
+= bp
->tx_nr_rings_xdp
;
10922 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
10923 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
10925 if (netif_running(bp
->dev
))
10926 return bnxt_open_nic(bp
, true, false);
10931 static int bnxt_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
10934 struct bnxt
*bp
= cb_priv
;
10936 if (!bnxt_tc_flower_enabled(bp
) ||
10937 !tc_cls_can_offload_and_chain0(bp
->dev
, type_data
))
10938 return -EOPNOTSUPP
;
10941 case TC_SETUP_CLSFLOWER
:
10942 return bnxt_tc_setup_flower(bp
, bp
->pf
.fw_fid
, type_data
);
10944 return -EOPNOTSUPP
;
10948 static LIST_HEAD(bnxt_block_cb_list
);
10950 static int bnxt_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
10953 struct bnxt
*bp
= netdev_priv(dev
);
10956 case TC_SETUP_BLOCK
:
10957 return flow_block_cb_setup_simple(type_data
,
10958 &bnxt_block_cb_list
,
10959 bnxt_setup_tc_block_cb
,
10961 case TC_SETUP_QDISC_MQPRIO
: {
10962 struct tc_mqprio_qopt
*mqprio
= type_data
;
10964 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
10966 return bnxt_setup_mq_tc(dev
, mqprio
->num_tc
);
10969 return -EOPNOTSUPP
;
10973 #ifdef CONFIG_RFS_ACCEL
10974 static bool bnxt_fltr_match(struct bnxt_ntuple_filter
*f1
,
10975 struct bnxt_ntuple_filter
*f2
)
10977 struct flow_keys
*keys1
= &f1
->fkeys
;
10978 struct flow_keys
*keys2
= &f2
->fkeys
;
10980 if (keys1
->addrs
.v4addrs
.src
== keys2
->addrs
.v4addrs
.src
&&
10981 keys1
->addrs
.v4addrs
.dst
== keys2
->addrs
.v4addrs
.dst
&&
10982 keys1
->ports
.ports
== keys2
->ports
.ports
&&
10983 keys1
->basic
.ip_proto
== keys2
->basic
.ip_proto
&&
10984 keys1
->basic
.n_proto
== keys2
->basic
.n_proto
&&
10985 keys1
->control
.flags
== keys2
->control
.flags
&&
10986 ether_addr_equal(f1
->src_mac_addr
, f2
->src_mac_addr
) &&
10987 ether_addr_equal(f1
->dst_mac_addr
, f2
->dst_mac_addr
))
10993 static int bnxt_rx_flow_steer(struct net_device
*dev
, const struct sk_buff
*skb
,
10994 u16 rxq_index
, u32 flow_id
)
10996 struct bnxt
*bp
= netdev_priv(dev
);
10997 struct bnxt_ntuple_filter
*fltr
, *new_fltr
;
10998 struct flow_keys
*fkeys
;
10999 struct ethhdr
*eth
= (struct ethhdr
*)skb_mac_header(skb
);
11000 int rc
= 0, idx
, bit_id
, l2_idx
= 0;
11001 struct hlist_head
*head
;
11003 if (!ether_addr_equal(dev
->dev_addr
, eth
->h_dest
)) {
11004 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
11007 netif_addr_lock_bh(dev
);
11008 for (j
= 0; j
< vnic
->uc_filter_count
; j
++, off
+= ETH_ALEN
) {
11009 if (ether_addr_equal(eth
->h_dest
,
11010 vnic
->uc_list
+ off
)) {
11015 netif_addr_unlock_bh(dev
);
11019 new_fltr
= kzalloc(sizeof(*new_fltr
), GFP_ATOMIC
);
11023 fkeys
= &new_fltr
->fkeys
;
11024 if (!skb_flow_dissect_flow_keys(skb
, fkeys
, 0)) {
11025 rc
= -EPROTONOSUPPORT
;
11029 if ((fkeys
->basic
.n_proto
!= htons(ETH_P_IP
) &&
11030 fkeys
->basic
.n_proto
!= htons(ETH_P_IPV6
)) ||
11031 ((fkeys
->basic
.ip_proto
!= IPPROTO_TCP
) &&
11032 (fkeys
->basic
.ip_proto
!= IPPROTO_UDP
))) {
11033 rc
= -EPROTONOSUPPORT
;
11036 if (fkeys
->basic
.n_proto
== htons(ETH_P_IPV6
) &&
11037 bp
->hwrm_spec_code
< 0x10601) {
11038 rc
= -EPROTONOSUPPORT
;
11041 if ((fkeys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) &&
11042 bp
->hwrm_spec_code
< 0x10601) {
11043 rc
= -EPROTONOSUPPORT
;
11047 memcpy(new_fltr
->dst_mac_addr
, eth
->h_dest
, ETH_ALEN
);
11048 memcpy(new_fltr
->src_mac_addr
, eth
->h_source
, ETH_ALEN
);
11050 idx
= skb_get_hash_raw(skb
) & BNXT_NTP_FLTR_HASH_MASK
;
11051 head
= &bp
->ntp_fltr_hash_tbl
[idx
];
11053 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
11054 if (bnxt_fltr_match(fltr
, new_fltr
)) {
11062 spin_lock_bh(&bp
->ntp_fltr_lock
);
11063 bit_id
= bitmap_find_free_region(bp
->ntp_fltr_bmap
,
11064 BNXT_NTP_FLTR_MAX_FLTR
, 0);
11066 spin_unlock_bh(&bp
->ntp_fltr_lock
);
11071 new_fltr
->sw_id
= (u16
)bit_id
;
11072 new_fltr
->flow_id
= flow_id
;
11073 new_fltr
->l2_fltr_idx
= l2_idx
;
11074 new_fltr
->rxq
= rxq_index
;
11075 hlist_add_head_rcu(&new_fltr
->hash
, head
);
11076 bp
->ntp_fltr_count
++;
11077 spin_unlock_bh(&bp
->ntp_fltr_lock
);
11079 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
11080 bnxt_queue_sp_work(bp
);
11082 return new_fltr
->sw_id
;
11089 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
11093 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
11094 struct hlist_head
*head
;
11095 struct hlist_node
*tmp
;
11096 struct bnxt_ntuple_filter
*fltr
;
11099 head
= &bp
->ntp_fltr_hash_tbl
[i
];
11100 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
11103 if (test_bit(BNXT_FLTR_VALID
, &fltr
->state
)) {
11104 if (rps_may_expire_flow(bp
->dev
, fltr
->rxq
,
11107 bnxt_hwrm_cfa_ntuple_filter_free(bp
,
11112 rc
= bnxt_hwrm_cfa_ntuple_filter_alloc(bp
,
11117 set_bit(BNXT_FLTR_VALID
, &fltr
->state
);
11121 spin_lock_bh(&bp
->ntp_fltr_lock
);
11122 hlist_del_rcu(&fltr
->hash
);
11123 bp
->ntp_fltr_count
--;
11124 spin_unlock_bh(&bp
->ntp_fltr_lock
);
11126 clear_bit(fltr
->sw_id
, bp
->ntp_fltr_bmap
);
11131 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
))
11132 netdev_info(bp
->dev
, "Receive PF driver unload event!");
11137 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
11141 #endif /* CONFIG_RFS_ACCEL */
11143 static void bnxt_udp_tunnel_add(struct net_device
*dev
,
11144 struct udp_tunnel_info
*ti
)
11146 struct bnxt
*bp
= netdev_priv(dev
);
11148 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
11151 if (!netif_running(dev
))
11154 switch (ti
->type
) {
11155 case UDP_TUNNEL_TYPE_VXLAN
:
11156 if (bp
->vxlan_port_cnt
&& bp
->vxlan_port
!= ti
->port
)
11159 bp
->vxlan_port_cnt
++;
11160 if (bp
->vxlan_port_cnt
== 1) {
11161 bp
->vxlan_port
= ti
->port
;
11162 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
11163 bnxt_queue_sp_work(bp
);
11166 case UDP_TUNNEL_TYPE_GENEVE
:
11167 if (bp
->nge_port_cnt
&& bp
->nge_port
!= ti
->port
)
11170 bp
->nge_port_cnt
++;
11171 if (bp
->nge_port_cnt
== 1) {
11172 bp
->nge_port
= ti
->port
;
11173 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
11180 bnxt_queue_sp_work(bp
);
11183 static void bnxt_udp_tunnel_del(struct net_device
*dev
,
11184 struct udp_tunnel_info
*ti
)
11186 struct bnxt
*bp
= netdev_priv(dev
);
11188 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
11191 if (!netif_running(dev
))
11194 switch (ti
->type
) {
11195 case UDP_TUNNEL_TYPE_VXLAN
:
11196 if (!bp
->vxlan_port_cnt
|| bp
->vxlan_port
!= ti
->port
)
11198 bp
->vxlan_port_cnt
--;
11200 if (bp
->vxlan_port_cnt
!= 0)
11203 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
11205 case UDP_TUNNEL_TYPE_GENEVE
:
11206 if (!bp
->nge_port_cnt
|| bp
->nge_port
!= ti
->port
)
11208 bp
->nge_port_cnt
--;
11210 if (bp
->nge_port_cnt
!= 0)
11213 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
11219 bnxt_queue_sp_work(bp
);
11222 static int bnxt_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
11223 struct net_device
*dev
, u32 filter_mask
,
11226 struct bnxt
*bp
= netdev_priv(dev
);
11228 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, bp
->br_mode
, 0, 0,
11229 nlflags
, filter_mask
, NULL
);
11232 static int bnxt_bridge_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
,
11233 u16 flags
, struct netlink_ext_ack
*extack
)
11235 struct bnxt
*bp
= netdev_priv(dev
);
11236 struct nlattr
*attr
, *br_spec
;
11239 if (bp
->hwrm_spec_code
< 0x10708 || !BNXT_SINGLE_PF(bp
))
11240 return -EOPNOTSUPP
;
11242 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
11246 nla_for_each_nested(attr
, br_spec
, rem
) {
11249 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
11252 if (nla_len(attr
) < sizeof(mode
))
11255 mode
= nla_get_u16(attr
);
11256 if (mode
== bp
->br_mode
)
11259 rc
= bnxt_hwrm_set_br_mode(bp
, mode
);
11261 bp
->br_mode
= mode
;
11267 int bnxt_get_port_parent_id(struct net_device
*dev
,
11268 struct netdev_phys_item_id
*ppid
)
11270 struct bnxt
*bp
= netdev_priv(dev
);
11272 if (bp
->eswitch_mode
!= DEVLINK_ESWITCH_MODE_SWITCHDEV
)
11273 return -EOPNOTSUPP
;
11275 /* The PF and it's VF-reps only support the switchdev framework */
11277 return -EOPNOTSUPP
;
11279 ppid
->id_len
= sizeof(bp
->switch_id
);
11280 memcpy(ppid
->id
, bp
->switch_id
, ppid
->id_len
);
11285 static struct devlink_port
*bnxt_get_devlink_port(struct net_device
*dev
)
11287 struct bnxt
*bp
= netdev_priv(dev
);
11289 return &bp
->dl_port
;
11292 static const struct net_device_ops bnxt_netdev_ops
= {
11293 .ndo_open
= bnxt_open
,
11294 .ndo_start_xmit
= bnxt_start_xmit
,
11295 .ndo_stop
= bnxt_close
,
11296 .ndo_get_stats64
= bnxt_get_stats64
,
11297 .ndo_set_rx_mode
= bnxt_set_rx_mode
,
11298 .ndo_do_ioctl
= bnxt_ioctl
,
11299 .ndo_validate_addr
= eth_validate_addr
,
11300 .ndo_set_mac_address
= bnxt_change_mac_addr
,
11301 .ndo_change_mtu
= bnxt_change_mtu
,
11302 .ndo_fix_features
= bnxt_fix_features
,
11303 .ndo_set_features
= bnxt_set_features
,
11304 .ndo_tx_timeout
= bnxt_tx_timeout
,
11305 #ifdef CONFIG_BNXT_SRIOV
11306 .ndo_get_vf_config
= bnxt_get_vf_config
,
11307 .ndo_set_vf_mac
= bnxt_set_vf_mac
,
11308 .ndo_set_vf_vlan
= bnxt_set_vf_vlan
,
11309 .ndo_set_vf_rate
= bnxt_set_vf_bw
,
11310 .ndo_set_vf_link_state
= bnxt_set_vf_link_state
,
11311 .ndo_set_vf_spoofchk
= bnxt_set_vf_spoofchk
,
11312 .ndo_set_vf_trust
= bnxt_set_vf_trust
,
11314 .ndo_setup_tc
= bnxt_setup_tc
,
11315 #ifdef CONFIG_RFS_ACCEL
11316 .ndo_rx_flow_steer
= bnxt_rx_flow_steer
,
11318 .ndo_udp_tunnel_add
= bnxt_udp_tunnel_add
,
11319 .ndo_udp_tunnel_del
= bnxt_udp_tunnel_del
,
11320 .ndo_bpf
= bnxt_xdp
,
11321 .ndo_xdp_xmit
= bnxt_xdp_xmit
,
11322 .ndo_bridge_getlink
= bnxt_bridge_getlink
,
11323 .ndo_bridge_setlink
= bnxt_bridge_setlink
,
11324 .ndo_get_devlink_port
= bnxt_get_devlink_port
,
11327 static void bnxt_remove_one(struct pci_dev
*pdev
)
11329 struct net_device
*dev
= pci_get_drvdata(pdev
);
11330 struct bnxt
*bp
= netdev_priv(dev
);
11333 bnxt_sriov_disable(bp
);
11334 bnxt_dl_unregister(bp
);
11337 pci_disable_pcie_error_reporting(pdev
);
11338 unregister_netdev(dev
);
11339 bnxt_shutdown_tc(bp
);
11340 bnxt_cancel_sp_work(bp
);
11343 bnxt_clear_int_mode(bp
);
11344 bnxt_hwrm_func_drv_unrgtr(bp
);
11345 bnxt_free_hwrm_resources(bp
);
11346 bnxt_free_hwrm_short_cmd_req(bp
);
11347 bnxt_ethtool_free(bp
);
11351 bnxt_cleanup_pci(bp
);
11352 bnxt_free_ctx_mem(bp
);
11355 bnxt_free_port_stats(bp
);
11359 static int bnxt_probe_phy(struct bnxt
*bp
, bool fw_dflt
)
11362 struct bnxt_link_info
*link_info
= &bp
->link_info
;
11364 rc
= bnxt_hwrm_phy_qcaps(bp
);
11366 netdev_err(bp
->dev
, "Probe phy can't get phy capabilities (rc: %x)\n",
11370 rc
= bnxt_update_link(bp
, false);
11372 netdev_err(bp
->dev
, "Probe phy can't update link (rc: %x)\n",
11377 /* Older firmware does not have supported_auto_speeds, so assume
11378 * that all supported speeds can be autonegotiated.
11380 if (link_info
->auto_link_speeds
&& !link_info
->support_auto_speeds
)
11381 link_info
->support_auto_speeds
= link_info
->support_speeds
;
11386 /*initialize the ethool setting copy with NVM settings */
11387 if (BNXT_AUTO_MODE(link_info
->auto_mode
)) {
11388 link_info
->autoneg
= BNXT_AUTONEG_SPEED
;
11389 if (bp
->hwrm_spec_code
>= 0x10201) {
11390 if (link_info
->auto_pause_setting
&
11391 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
)
11392 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
11394 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
11396 link_info
->advertising
= link_info
->auto_link_speeds
;
11398 link_info
->req_link_speed
= link_info
->force_link_speed
;
11399 link_info
->req_duplex
= link_info
->duplex_setting
;
11401 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
11402 link_info
->req_flow_ctrl
=
11403 link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
;
11405 link_info
->req_flow_ctrl
= link_info
->force_pause_setting
;
11409 static int bnxt_get_max_irq(struct pci_dev
*pdev
)
11413 if (!pdev
->msix_cap
)
11416 pci_read_config_word(pdev
, pdev
->msix_cap
+ PCI_MSIX_FLAGS
, &ctrl
);
11417 return (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
11420 static void _bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
11423 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
11424 int max_ring_grps
= 0, max_irq
;
11426 *max_tx
= hw_resc
->max_tx_rings
;
11427 *max_rx
= hw_resc
->max_rx_rings
;
11428 *max_cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
11429 max_irq
= min_t(int, bnxt_get_max_func_irqs(bp
) -
11430 bnxt_get_ulp_msix_num(bp
),
11431 hw_resc
->max_stat_ctxs
- bnxt_get_ulp_stat_ctxs(bp
));
11432 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
11433 *max_cp
= min_t(int, *max_cp
, max_irq
);
11434 max_ring_grps
= hw_resc
->max_hw_ring_grps
;
11435 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) && BNXT_PF(bp
)) {
11439 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
11441 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
11442 bnxt_trim_rings(bp
, max_rx
, max_tx
, *max_cp
, false);
11443 /* On P5 chips, max_cp output param should be available NQs */
11446 *max_rx
= min_t(int, *max_rx
, max_ring_grps
);
11449 int bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
, bool shared
)
11453 _bnxt_get_max_rings(bp
, &rx
, &tx
, &cp
);
11456 if (!rx
|| !tx
|| !cp
)
11459 return bnxt_trim_rings(bp
, max_rx
, max_tx
, cp
, shared
);
11462 static int bnxt_get_dflt_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
11467 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
11468 if (rc
&& (bp
->flags
& BNXT_FLAG_AGG_RINGS
)) {
11469 /* Not enough rings, try disabling agg rings. */
11470 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
11471 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
11473 /* set BNXT_FLAG_AGG_RINGS back for consistency */
11474 bp
->flags
|= BNXT_FLAG_AGG_RINGS
;
11477 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
11478 bp
->dev
->hw_features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
11479 bp
->dev
->features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
11480 bnxt_set_ring_params(bp
);
11483 if (bp
->flags
& BNXT_FLAG_ROCE_CAP
) {
11484 int max_cp
, max_stat
, max_irq
;
11486 /* Reserve minimum resources for RoCE */
11487 max_cp
= bnxt_get_max_func_cp_rings(bp
);
11488 max_stat
= bnxt_get_max_func_stat_ctxs(bp
);
11489 max_irq
= bnxt_get_max_func_irqs(bp
);
11490 if (max_cp
<= BNXT_MIN_ROCE_CP_RINGS
||
11491 max_irq
<= BNXT_MIN_ROCE_CP_RINGS
||
11492 max_stat
<= BNXT_MIN_ROCE_STAT_CTXS
)
11495 max_cp
-= BNXT_MIN_ROCE_CP_RINGS
;
11496 max_irq
-= BNXT_MIN_ROCE_CP_RINGS
;
11497 max_stat
-= BNXT_MIN_ROCE_STAT_CTXS
;
11498 max_cp
= min_t(int, max_cp
, max_irq
);
11499 max_cp
= min_t(int, max_cp
, max_stat
);
11500 rc
= bnxt_trim_rings(bp
, max_rx
, max_tx
, max_cp
, shared
);
11507 /* In initial default shared ring setting, each shared ring must have a
11510 static void bnxt_trim_dflt_sh_rings(struct bnxt
*bp
)
11512 bp
->cp_nr_rings
= min_t(int, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
);
11513 bp
->rx_nr_rings
= bp
->cp_nr_rings
;
11514 bp
->tx_nr_rings_per_tc
= bp
->cp_nr_rings
;
11515 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
11518 static int bnxt_set_dflt_rings(struct bnxt
*bp
, bool sh
)
11520 int dflt_rings
, max_rx_rings
, max_tx_rings
, rc
;
11522 if (!bnxt_can_reserve_rings(bp
))
11526 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
11527 dflt_rings
= is_kdump_kernel() ? 1 : netif_get_num_default_rss_queues();
11528 /* Reduce default rings on multi-port cards so that total default
11529 * rings do not exceed CPU count.
11531 if (bp
->port_count
> 1) {
11533 max_t(int, num_online_cpus() / bp
->port_count
, 1);
11535 dflt_rings
= min_t(int, dflt_rings
, max_rings
);
11537 rc
= bnxt_get_dflt_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
11540 bp
->rx_nr_rings
= min_t(int, dflt_rings
, max_rx_rings
);
11541 bp
->tx_nr_rings_per_tc
= min_t(int, dflt_rings
, max_tx_rings
);
11543 bnxt_trim_dflt_sh_rings(bp
);
11545 bp
->cp_nr_rings
= bp
->tx_nr_rings_per_tc
+ bp
->rx_nr_rings
;
11546 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
11548 rc
= __bnxt_reserve_rings(bp
);
11550 netdev_warn(bp
->dev
, "Unable to reserve tx rings\n");
11551 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
11553 bnxt_trim_dflt_sh_rings(bp
);
11555 /* Rings may have been trimmed, re-reserve the trimmed rings. */
11556 if (bnxt_need_reserve_rings(bp
)) {
11557 rc
= __bnxt_reserve_rings(bp
);
11559 netdev_warn(bp
->dev
, "2nd rings reservation failed.\n");
11560 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
11562 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
11569 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
)
11573 if (bp
->tx_nr_rings
)
11576 bnxt_ulp_irq_stop(bp
);
11577 bnxt_clear_int_mode(bp
);
11578 rc
= bnxt_set_dflt_rings(bp
, true);
11580 netdev_err(bp
->dev
, "Not enough rings available.\n");
11581 goto init_dflt_ring_err
;
11583 rc
= bnxt_init_int_mode(bp
);
11585 goto init_dflt_ring_err
;
11587 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
11588 if (bnxt_rfs_supported(bp
) && bnxt_rfs_capable(bp
)) {
11589 bp
->flags
|= BNXT_FLAG_RFS
;
11590 bp
->dev
->features
|= NETIF_F_NTUPLE
;
11592 init_dflt_ring_err
:
11593 bnxt_ulp_irq_restart(bp
, rc
);
11597 int bnxt_restore_pf_fw_resources(struct bnxt
*bp
)
11602 bnxt_hwrm_func_qcaps(bp
);
11604 if (netif_running(bp
->dev
))
11605 __bnxt_close_nic(bp
, true, false);
11607 bnxt_ulp_irq_stop(bp
);
11608 bnxt_clear_int_mode(bp
);
11609 rc
= bnxt_init_int_mode(bp
);
11610 bnxt_ulp_irq_restart(bp
, rc
);
11612 if (netif_running(bp
->dev
)) {
11614 dev_close(bp
->dev
);
11616 rc
= bnxt_open_nic(bp
, true, false);
11622 static int bnxt_init_mac_addr(struct bnxt
*bp
)
11627 memcpy(bp
->dev
->dev_addr
, bp
->pf
.mac_addr
, ETH_ALEN
);
11629 #ifdef CONFIG_BNXT_SRIOV
11630 struct bnxt_vf_info
*vf
= &bp
->vf
;
11631 bool strict_approval
= true;
11633 if (is_valid_ether_addr(vf
->mac_addr
)) {
11634 /* overwrite netdev dev_addr with admin VF MAC */
11635 memcpy(bp
->dev
->dev_addr
, vf
->mac_addr
, ETH_ALEN
);
11636 /* Older PF driver or firmware may not approve this
11639 strict_approval
= false;
11641 eth_hw_addr_random(bp
->dev
);
11643 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, strict_approval
);
11649 static int bnxt_pcie_dsn_get(struct bnxt
*bp
, u8 dsn
[])
11651 struct pci_dev
*pdev
= bp
->pdev
;
11652 int pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_DSN
);
11656 netdev_info(bp
->dev
, "Unable do read adapter's DSN");
11657 return -EOPNOTSUPP
;
11660 /* DSN (two dw) is at an offset of 4 from the cap pos */
11662 pci_read_config_dword(pdev
, pos
, &dw
);
11663 put_unaligned_le32(dw
, &dsn
[0]);
11664 pci_read_config_dword(pdev
, pos
+ 4, &dw
);
11665 put_unaligned_le32(dw
, &dsn
[4]);
11669 static int bnxt_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
11671 static int version_printed
;
11672 struct net_device
*dev
;
11676 if (pci_is_bridge(pdev
))
11679 if (version_printed
++ == 0)
11680 pr_info("%s", version
);
11682 max_irqs
= bnxt_get_max_irq(pdev
);
11683 dev
= alloc_etherdev_mq(sizeof(*bp
), max_irqs
);
11687 bp
= netdev_priv(dev
);
11688 bnxt_set_max_func_irqs(bp
, max_irqs
);
11690 if (bnxt_vf_pciid(ent
->driver_data
))
11691 bp
->flags
|= BNXT_FLAG_VF
;
11693 if (pdev
->msix_cap
)
11694 bp
->flags
|= BNXT_FLAG_MSIX_CAP
;
11696 rc
= bnxt_init_board(pdev
, dev
);
11698 goto init_err_free
;
11700 dev
->netdev_ops
= &bnxt_netdev_ops
;
11701 dev
->watchdog_timeo
= BNXT_TX_TIMEOUT
;
11702 dev
->ethtool_ops
= &bnxt_ethtool_ops
;
11703 pci_set_drvdata(pdev
, dev
);
11705 rc
= bnxt_alloc_hwrm_resources(bp
);
11707 goto init_err_pci_clean
;
11709 mutex_init(&bp
->hwrm_cmd_lock
);
11710 mutex_init(&bp
->link_lock
);
11712 rc
= bnxt_fw_init_one_p1(bp
);
11714 goto init_err_pci_clean
;
11716 if (BNXT_CHIP_P5(bp
))
11717 bp
->flags
|= BNXT_FLAG_CHIP_P5
;
11719 rc
= bnxt_fw_init_one_p2(bp
);
11721 goto init_err_pci_clean
;
11723 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
11724 NETIF_F_TSO
| NETIF_F_TSO6
|
11725 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
11726 NETIF_F_GSO_IPXIP4
|
11727 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
11728 NETIF_F_GSO_PARTIAL
| NETIF_F_RXHASH
|
11729 NETIF_F_RXCSUM
| NETIF_F_GRO
;
11731 if (BNXT_SUPPORTS_TPA(bp
))
11732 dev
->hw_features
|= NETIF_F_LRO
;
11734 dev
->hw_enc_features
=
11735 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
11736 NETIF_F_TSO
| NETIF_F_TSO6
|
11737 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
11738 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
11739 NETIF_F_GSO_IPXIP4
| NETIF_F_GSO_PARTIAL
;
11740 dev
->gso_partial_features
= NETIF_F_GSO_UDP_TUNNEL_CSUM
|
11741 NETIF_F_GSO_GRE_CSUM
;
11742 dev
->vlan_features
= dev
->hw_features
| NETIF_F_HIGHDMA
;
11743 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_CTAG_TX
|
11744 NETIF_F_HW_VLAN_STAG_RX
| NETIF_F_HW_VLAN_STAG_TX
;
11745 if (BNXT_SUPPORTS_TPA(bp
))
11746 dev
->hw_features
|= NETIF_F_GRO_HW
;
11747 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
11748 if (dev
->features
& NETIF_F_GRO_HW
)
11749 dev
->features
&= ~NETIF_F_LRO
;
11750 dev
->priv_flags
|= IFF_UNICAST_FLT
;
11752 #ifdef CONFIG_BNXT_SRIOV
11753 init_waitqueue_head(&bp
->sriov_cfg_wait
);
11754 mutex_init(&bp
->sriov_lock
);
11756 if (BNXT_SUPPORTS_TPA(bp
)) {
11757 bp
->gro_func
= bnxt_gro_func_5730x
;
11758 if (BNXT_CHIP_P4(bp
))
11759 bp
->gro_func
= bnxt_gro_func_5731x
;
11760 else if (BNXT_CHIP_P5(bp
))
11761 bp
->gro_func
= bnxt_gro_func_5750x
;
11763 if (!BNXT_CHIP_P4_PLUS(bp
))
11764 bp
->flags
|= BNXT_FLAG_DOUBLE_DB
;
11766 bp
->ulp_probe
= bnxt_ulp_probe
;
11768 rc
= bnxt_init_mac_addr(bp
);
11770 dev_err(&pdev
->dev
, "Unable to initialize mac address.\n");
11771 rc
= -EADDRNOTAVAIL
;
11772 goto init_err_pci_clean
;
11776 /* Read the adapter's DSN to use as the eswitch switch_id */
11777 rc
= bnxt_pcie_dsn_get(bp
, bp
->switch_id
);
11779 goto init_err_pci_clean
;
11782 /* MTU range: 60 - FW defined max */
11783 dev
->min_mtu
= ETH_ZLEN
;
11784 dev
->max_mtu
= bp
->max_mtu
;
11786 rc
= bnxt_probe_phy(bp
, true);
11788 goto init_err_pci_clean
;
11790 bnxt_set_rx_skb_mode(bp
, false);
11791 bnxt_set_tpa_flags(bp
);
11792 bnxt_set_ring_params(bp
);
11793 rc
= bnxt_set_dflt_rings(bp
, true);
11795 netdev_err(bp
->dev
, "Not enough rings available.\n");
11797 goto init_err_pci_clean
;
11800 bnxt_fw_init_one_p3(bp
);
11802 if (dev
->hw_features
& NETIF_F_HW_VLAN_CTAG_RX
)
11803 bp
->flags
|= BNXT_FLAG_STRIP_VLAN
;
11805 rc
= bnxt_init_int_mode(bp
);
11807 goto init_err_pci_clean
;
11809 /* No TC has been set yet and rings may have been trimmed due to
11810 * limited MSIX, so we re-initialize the TX rings per TC.
11812 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
11817 create_singlethread_workqueue("bnxt_pf_wq");
11819 dev_err(&pdev
->dev
, "Unable to create workqueue.\n");
11820 goto init_err_pci_clean
;
11826 rc
= register_netdev(dev
);
11828 goto init_err_cleanup_tc
;
11831 bnxt_dl_register(bp
);
11833 netdev_info(dev
, "%s found at mem %lx, node addr %pM\n",
11834 board_info
[ent
->driver_data
].name
,
11835 (long)pci_resource_start(pdev
, 0), dev
->dev_addr
);
11836 pcie_print_link_status(pdev
);
11840 init_err_cleanup_tc
:
11841 bnxt_shutdown_tc(bp
);
11842 bnxt_clear_int_mode(bp
);
11844 init_err_pci_clean
:
11845 bnxt_free_hwrm_short_cmd_req(bp
);
11846 bnxt_free_hwrm_resources(bp
);
11847 bnxt_free_ctx_mem(bp
);
11850 kfree(bp
->fw_health
);
11851 bp
->fw_health
= NULL
;
11852 bnxt_cleanup_pci(bp
);
11859 static void bnxt_shutdown(struct pci_dev
*pdev
)
11861 struct net_device
*dev
= pci_get_drvdata(pdev
);
11868 bp
= netdev_priv(dev
);
11870 goto shutdown_exit
;
11872 if (netif_running(dev
))
11875 bnxt_ulp_shutdown(bp
);
11877 if (system_state
== SYSTEM_POWER_OFF
) {
11878 bnxt_clear_int_mode(bp
);
11879 pci_disable_device(pdev
);
11880 pci_wake_from_d3(pdev
, bp
->wol
);
11881 pci_set_power_state(pdev
, PCI_D3hot
);
11888 #ifdef CONFIG_PM_SLEEP
11889 static int bnxt_suspend(struct device
*device
)
11891 struct net_device
*dev
= dev_get_drvdata(device
);
11892 struct bnxt
*bp
= netdev_priv(dev
);
11896 if (netif_running(dev
)) {
11897 netif_device_detach(dev
);
11898 rc
= bnxt_close(dev
);
11900 bnxt_hwrm_func_drv_unrgtr(bp
);
11905 static int bnxt_resume(struct device
*device
)
11907 struct net_device
*dev
= dev_get_drvdata(device
);
11908 struct bnxt
*bp
= netdev_priv(dev
);
11912 if (bnxt_hwrm_ver_get(bp
) || bnxt_hwrm_func_drv_rgtr(bp
)) {
11916 rc
= bnxt_hwrm_func_reset(bp
);
11921 bnxt_get_wol_settings(bp
);
11922 if (netif_running(dev
)) {
11923 rc
= bnxt_open(dev
);
11925 netif_device_attach(dev
);
11933 static SIMPLE_DEV_PM_OPS(bnxt_pm_ops
, bnxt_suspend
, bnxt_resume
);
11934 #define BNXT_PM_OPS (&bnxt_pm_ops)
11938 #define BNXT_PM_OPS NULL
11940 #endif /* CONFIG_PM_SLEEP */
11943 * bnxt_io_error_detected - called when PCI error is detected
11944 * @pdev: Pointer to PCI device
11945 * @state: The current pci connection state
11947 * This function is called after a PCI bus error affecting
11948 * this device has been detected.
11950 static pci_ers_result_t
bnxt_io_error_detected(struct pci_dev
*pdev
,
11951 pci_channel_state_t state
)
11953 struct net_device
*netdev
= pci_get_drvdata(pdev
);
11954 struct bnxt
*bp
= netdev_priv(netdev
);
11956 netdev_info(netdev
, "PCI I/O error detected\n");
11959 netif_device_detach(netdev
);
11963 if (state
== pci_channel_io_perm_failure
) {
11965 return PCI_ERS_RESULT_DISCONNECT
;
11968 if (netif_running(netdev
))
11969 bnxt_close(netdev
);
11971 pci_disable_device(pdev
);
11974 /* Request a slot slot reset. */
11975 return PCI_ERS_RESULT_NEED_RESET
;
11979 * bnxt_io_slot_reset - called after the pci bus has been reset.
11980 * @pdev: Pointer to PCI device
11982 * Restart the card from scratch, as if from a cold-boot.
11983 * At this point, the card has exprienced a hard reset,
11984 * followed by fixups by BIOS, and has its config space
11985 * set up identically to what it was at cold boot.
11987 static pci_ers_result_t
bnxt_io_slot_reset(struct pci_dev
*pdev
)
11989 struct net_device
*netdev
= pci_get_drvdata(pdev
);
11990 struct bnxt
*bp
= netdev_priv(netdev
);
11992 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
11994 netdev_info(bp
->dev
, "PCI Slot Reset\n");
11998 if (pci_enable_device(pdev
)) {
11999 dev_err(&pdev
->dev
,
12000 "Cannot re-enable PCI device after reset.\n");
12002 pci_set_master(pdev
);
12004 err
= bnxt_hwrm_func_reset(bp
);
12005 if (!err
&& netif_running(netdev
))
12006 err
= bnxt_open(netdev
);
12009 result
= PCI_ERS_RESULT_RECOVERED
;
12010 bnxt_ulp_start(bp
);
12014 if (result
!= PCI_ERS_RESULT_RECOVERED
&& netif_running(netdev
))
12019 return PCI_ERS_RESULT_RECOVERED
;
12023 * bnxt_io_resume - called when traffic can start flowing again.
12024 * @pdev: Pointer to PCI device
12026 * This callback is called when the error recovery driver tells
12027 * us that its OK to resume normal operation.
12029 static void bnxt_io_resume(struct pci_dev
*pdev
)
12031 struct net_device
*netdev
= pci_get_drvdata(pdev
);
12035 netif_device_attach(netdev
);
12040 static const struct pci_error_handlers bnxt_err_handler
= {
12041 .error_detected
= bnxt_io_error_detected
,
12042 .slot_reset
= bnxt_io_slot_reset
,
12043 .resume
= bnxt_io_resume
12046 static struct pci_driver bnxt_pci_driver
= {
12047 .name
= DRV_MODULE_NAME
,
12048 .id_table
= bnxt_pci_tbl
,
12049 .probe
= bnxt_init_one
,
12050 .remove
= bnxt_remove_one
,
12051 .shutdown
= bnxt_shutdown
,
12052 .driver
.pm
= BNXT_PM_OPS
,
12053 .err_handler
= &bnxt_err_handler
,
12054 #if defined(CONFIG_BNXT_SRIOV)
12055 .sriov_configure
= bnxt_sriov_configure
,
12059 static int __init
bnxt_init(void)
12062 return pci_register_driver(&bnxt_pci_driver
);
12065 static void __exit
bnxt_exit(void)
12067 pci_unregister_driver(&bnxt_pci_driver
);
12069 destroy_workqueue(bnxt_pf_wq
);
12073 module_init(bnxt_init
);
12074 module_exit(bnxt_exit
);