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>
61 #include "bnxt_sriov.h"
62 #include "bnxt_ethtool.h"
67 #include "bnxt_devlink.h"
68 #include "bnxt_debugfs.h"
70 #define BNXT_TX_TIMEOUT (5 * HZ)
72 static const char version
[] =
73 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME
" v" DRV_MODULE_VERSION
"\n";
75 MODULE_LICENSE("GPL");
76 MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
77 MODULE_VERSION(DRV_MODULE_VERSION
);
79 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
80 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
81 #define BNXT_RX_COPY_THRESH 256
83 #define BNXT_TX_PUSH_THRESH 164
126 /* indexed by enum above */
127 static const struct {
130 [BCM57301
] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
131 [BCM57302
] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
132 [BCM57304
] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
133 [BCM57417_NPAR
] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
134 [BCM58700
] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
135 [BCM57311
] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
136 [BCM57312
] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
137 [BCM57402
] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
138 [BCM57404
] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
139 [BCM57406
] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
140 [BCM57402_NPAR
] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
141 [BCM57407
] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
142 [BCM57412
] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
143 [BCM57414
] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
144 [BCM57416
] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
145 [BCM57417
] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
146 [BCM57412_NPAR
] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
147 [BCM57314
] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
148 [BCM57417_SFP
] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
149 [BCM57416_SFP
] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
150 [BCM57404_NPAR
] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
151 [BCM57406_NPAR
] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
152 [BCM57407_SFP
] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
153 [BCM57407_NPAR
] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
154 [BCM57414_NPAR
] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
155 [BCM57416_NPAR
] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
156 [BCM57452
] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
157 [BCM57454
] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
158 [BCM5745x_NPAR
] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
159 [BCM57508
] = { "Broadcom BCM57508 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
160 [BCM57504
] = { "Broadcom BCM57504 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
161 [BCM58802
] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
162 [BCM58804
] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
163 [BCM58808
] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
164 [NETXTREME_E_VF
] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
165 [NETXTREME_C_VF
] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
166 [NETXTREME_S_VF
] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
167 [NETXTREME_E_P5_VF
] = { "Broadcom BCM5750X NetXtreme-E Ethernet Virtual Function" },
170 static const struct pci_device_id bnxt_pci_tbl
[] = {
171 { PCI_VDEVICE(BROADCOM
, 0x1604), .driver_data
= BCM5745x_NPAR
},
172 { PCI_VDEVICE(BROADCOM
, 0x1605), .driver_data
= BCM5745x_NPAR
},
173 { PCI_VDEVICE(BROADCOM
, 0x1614), .driver_data
= BCM57454
},
174 { PCI_VDEVICE(BROADCOM
, 0x16c0), .driver_data
= BCM57417_NPAR
},
175 { PCI_VDEVICE(BROADCOM
, 0x16c8), .driver_data
= BCM57301
},
176 { PCI_VDEVICE(BROADCOM
, 0x16c9), .driver_data
= BCM57302
},
177 { PCI_VDEVICE(BROADCOM
, 0x16ca), .driver_data
= BCM57304
},
178 { PCI_VDEVICE(BROADCOM
, 0x16cc), .driver_data
= BCM57417_NPAR
},
179 { PCI_VDEVICE(BROADCOM
, 0x16cd), .driver_data
= BCM58700
},
180 { PCI_VDEVICE(BROADCOM
, 0x16ce), .driver_data
= BCM57311
},
181 { PCI_VDEVICE(BROADCOM
, 0x16cf), .driver_data
= BCM57312
},
182 { PCI_VDEVICE(BROADCOM
, 0x16d0), .driver_data
= BCM57402
},
183 { PCI_VDEVICE(BROADCOM
, 0x16d1), .driver_data
= BCM57404
},
184 { PCI_VDEVICE(BROADCOM
, 0x16d2), .driver_data
= BCM57406
},
185 { PCI_VDEVICE(BROADCOM
, 0x16d4), .driver_data
= BCM57402_NPAR
},
186 { PCI_VDEVICE(BROADCOM
, 0x16d5), .driver_data
= BCM57407
},
187 { PCI_VDEVICE(BROADCOM
, 0x16d6), .driver_data
= BCM57412
},
188 { PCI_VDEVICE(BROADCOM
, 0x16d7), .driver_data
= BCM57414
},
189 { PCI_VDEVICE(BROADCOM
, 0x16d8), .driver_data
= BCM57416
},
190 { PCI_VDEVICE(BROADCOM
, 0x16d9), .driver_data
= BCM57417
},
191 { PCI_VDEVICE(BROADCOM
, 0x16de), .driver_data
= BCM57412_NPAR
},
192 { PCI_VDEVICE(BROADCOM
, 0x16df), .driver_data
= BCM57314
},
193 { PCI_VDEVICE(BROADCOM
, 0x16e2), .driver_data
= BCM57417_SFP
},
194 { PCI_VDEVICE(BROADCOM
, 0x16e3), .driver_data
= BCM57416_SFP
},
195 { PCI_VDEVICE(BROADCOM
, 0x16e7), .driver_data
= BCM57404_NPAR
},
196 { PCI_VDEVICE(BROADCOM
, 0x16e8), .driver_data
= BCM57406_NPAR
},
197 { PCI_VDEVICE(BROADCOM
, 0x16e9), .driver_data
= BCM57407_SFP
},
198 { PCI_VDEVICE(BROADCOM
, 0x16ea), .driver_data
= BCM57407_NPAR
},
199 { PCI_VDEVICE(BROADCOM
, 0x16eb), .driver_data
= BCM57412_NPAR
},
200 { PCI_VDEVICE(BROADCOM
, 0x16ec), .driver_data
= BCM57414_NPAR
},
201 { PCI_VDEVICE(BROADCOM
, 0x16ed), .driver_data
= BCM57414_NPAR
},
202 { PCI_VDEVICE(BROADCOM
, 0x16ee), .driver_data
= BCM57416_NPAR
},
203 { PCI_VDEVICE(BROADCOM
, 0x16ef), .driver_data
= BCM57416_NPAR
},
204 { PCI_VDEVICE(BROADCOM
, 0x16f0), .driver_data
= BCM58808
},
205 { PCI_VDEVICE(BROADCOM
, 0x16f1), .driver_data
= BCM57452
},
206 { PCI_VDEVICE(BROADCOM
, 0x1750), .driver_data
= BCM57508
},
207 { PCI_VDEVICE(BROADCOM
, 0x1751), .driver_data
= BCM57504
},
208 { PCI_VDEVICE(BROADCOM
, 0xd802), .driver_data
= BCM58802
},
209 { PCI_VDEVICE(BROADCOM
, 0xd804), .driver_data
= BCM58804
},
210 #ifdef CONFIG_BNXT_SRIOV
211 { PCI_VDEVICE(BROADCOM
, 0x1606), .driver_data
= NETXTREME_E_VF
},
212 { PCI_VDEVICE(BROADCOM
, 0x1609), .driver_data
= NETXTREME_E_VF
},
213 { PCI_VDEVICE(BROADCOM
, 0x16c1), .driver_data
= NETXTREME_E_VF
},
214 { PCI_VDEVICE(BROADCOM
, 0x16cb), .driver_data
= NETXTREME_C_VF
},
215 { PCI_VDEVICE(BROADCOM
, 0x16d3), .driver_data
= NETXTREME_E_VF
},
216 { PCI_VDEVICE(BROADCOM
, 0x16dc), .driver_data
= NETXTREME_E_VF
},
217 { PCI_VDEVICE(BROADCOM
, 0x16e1), .driver_data
= NETXTREME_C_VF
},
218 { PCI_VDEVICE(BROADCOM
, 0x16e5), .driver_data
= NETXTREME_C_VF
},
219 { PCI_VDEVICE(BROADCOM
, 0x1807), .driver_data
= NETXTREME_E_P5_VF
},
220 { PCI_VDEVICE(BROADCOM
, 0xd800), .driver_data
= NETXTREME_S_VF
},
225 MODULE_DEVICE_TABLE(pci
, bnxt_pci_tbl
);
227 static const u16 bnxt_vf_req_snif
[] = {
231 HWRM_CFA_L2_FILTER_ALLOC
,
234 static const u16 bnxt_async_events_arr
[] = {
235 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
,
236 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
,
237 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
,
238 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
,
239 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
,
242 static struct workqueue_struct
*bnxt_pf_wq
;
244 static bool bnxt_vf_pciid(enum board_idx idx
)
246 return (idx
== NETXTREME_C_VF
|| idx
== NETXTREME_E_VF
||
247 idx
== NETXTREME_S_VF
|| idx
== NETXTREME_E_P5_VF
);
250 #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
251 #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
252 #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
254 #define BNXT_CP_DB_IRQ_DIS(db) \
255 writel(DB_CP_IRQ_DIS_FLAGS, db)
257 #define BNXT_DB_CQ(db, idx) \
258 writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
260 #define BNXT_DB_NQ_P5(db, idx) \
261 writeq((db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), (db)->doorbell)
263 #define BNXT_DB_CQ_ARM(db, idx) \
264 writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
266 #define BNXT_DB_NQ_ARM_P5(db, idx) \
267 writeq((db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx), (db)->doorbell)
269 static void bnxt_db_nq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
271 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
272 BNXT_DB_NQ_P5(db
, idx
);
277 static void bnxt_db_nq_arm(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
279 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
280 BNXT_DB_NQ_ARM_P5(db
, idx
);
282 BNXT_DB_CQ_ARM(db
, idx
);
285 static void bnxt_db_cq(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 idx
)
287 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
288 writeq(db
->db_key64
| DBR_TYPE_CQ_ARMALL
| RING_CMP(idx
),
294 const u16 bnxt_lhint_arr
[] = {
295 TX_BD_FLAGS_LHINT_512_AND_SMALLER
,
296 TX_BD_FLAGS_LHINT_512_TO_1023
,
297 TX_BD_FLAGS_LHINT_1024_TO_2047
,
298 TX_BD_FLAGS_LHINT_1024_TO_2047
,
299 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
300 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
301 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
302 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
303 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
304 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
305 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
306 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
307 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
308 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
309 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
310 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
311 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
312 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
313 TX_BD_FLAGS_LHINT_2048_AND_LARGER
,
316 static u16
bnxt_xmit_get_cfa_action(struct sk_buff
*skb
)
318 struct metadata_dst
*md_dst
= skb_metadata_dst(skb
);
320 if (!md_dst
|| md_dst
->type
!= METADATA_HW_PORT_MUX
)
323 return md_dst
->u
.port_info
.port_id
;
326 static netdev_tx_t
bnxt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
328 struct bnxt
*bp
= netdev_priv(dev
);
330 struct tx_bd_ext
*txbd1
;
331 struct netdev_queue
*txq
;
334 unsigned int length
, pad
= 0;
335 u32 len
, free_size
, vlan_tag_flags
, cfa_action
, flags
;
337 struct pci_dev
*pdev
= bp
->pdev
;
338 struct bnxt_tx_ring_info
*txr
;
339 struct bnxt_sw_tx_bd
*tx_buf
;
341 i
= skb_get_queue_mapping(skb
);
342 if (unlikely(i
>= bp
->tx_nr_rings
)) {
343 dev_kfree_skb_any(skb
);
347 txq
= netdev_get_tx_queue(dev
, i
);
348 txr
= &bp
->tx_ring
[bp
->tx_ring_map
[i
]];
351 free_size
= bnxt_tx_avail(bp
, txr
);
352 if (unlikely(free_size
< skb_shinfo(skb
)->nr_frags
+ 2)) {
353 netif_tx_stop_queue(txq
);
354 return NETDEV_TX_BUSY
;
358 len
= skb_headlen(skb
);
359 last_frag
= skb_shinfo(skb
)->nr_frags
;
361 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
363 txbd
->tx_bd_opaque
= prod
;
365 tx_buf
= &txr
->tx_buf_ring
[prod
];
367 tx_buf
->nr_frags
= last_frag
;
370 cfa_action
= bnxt_xmit_get_cfa_action(skb
);
371 if (skb_vlan_tag_present(skb
)) {
372 vlan_tag_flags
= TX_BD_CFA_META_KEY_VLAN
|
373 skb_vlan_tag_get(skb
);
374 /* Currently supports 8021Q, 8021AD vlan offloads
375 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
377 if (skb
->vlan_proto
== htons(ETH_P_8021Q
))
378 vlan_tag_flags
|= 1 << TX_BD_CFA_META_TPID_SHIFT
;
381 if (free_size
== bp
->tx_ring_size
&& length
<= bp
->tx_push_thresh
) {
382 struct tx_push_buffer
*tx_push_buf
= txr
->tx_push
;
383 struct tx_push_bd
*tx_push
= &tx_push_buf
->push_bd
;
384 struct tx_bd_ext
*tx_push1
= &tx_push
->txbd2
;
385 void __iomem
*db
= txr
->tx_db
.doorbell
;
386 void *pdata
= tx_push_buf
->data
;
390 /* Set COAL_NOW to be ready quickly for the next push */
391 tx_push
->tx_bd_len_flags_type
=
392 cpu_to_le32((length
<< TX_BD_LEN_SHIFT
) |
393 TX_BD_TYPE_LONG_TX_BD
|
394 TX_BD_FLAGS_LHINT_512_AND_SMALLER
|
395 TX_BD_FLAGS_COAL_NOW
|
396 TX_BD_FLAGS_PACKET_END
|
397 (2 << TX_BD_FLAGS_BD_CNT_SHIFT
));
399 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
400 tx_push1
->tx_bd_hsize_lflags
=
401 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
403 tx_push1
->tx_bd_hsize_lflags
= 0;
405 tx_push1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
406 tx_push1
->tx_bd_cfa_action
=
407 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
409 end
= pdata
+ length
;
410 end
= PTR_ALIGN(end
, 8) - 1;
413 skb_copy_from_linear_data(skb
, pdata
, len
);
415 for (j
= 0; j
< last_frag
; j
++) {
416 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[j
];
419 fptr
= skb_frag_address_safe(frag
);
423 memcpy(pdata
, fptr
, skb_frag_size(frag
));
424 pdata
+= skb_frag_size(frag
);
427 txbd
->tx_bd_len_flags_type
= tx_push
->tx_bd_len_flags_type
;
428 txbd
->tx_bd_haddr
= txr
->data_mapping
;
429 prod
= NEXT_TX(prod
);
430 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
431 memcpy(txbd
, tx_push1
, sizeof(*txbd
));
432 prod
= NEXT_TX(prod
);
434 cpu_to_le32(DB_KEY_TX_PUSH
| DB_LONG_TX_PUSH
| prod
);
438 netdev_tx_sent_queue(txq
, skb
->len
);
439 wmb(); /* Sync is_push and byte queue before pushing data */
441 push_len
= (length
+ sizeof(*tx_push
) + 7) / 8;
443 __iowrite64_copy(db
, tx_push_buf
, 16);
444 __iowrite32_copy(db
+ 4, tx_push_buf
+ 1,
445 (push_len
- 16) << 1);
447 __iowrite64_copy(db
, tx_push_buf
, push_len
);
454 if (length
< BNXT_MIN_PKT_SIZE
) {
455 pad
= BNXT_MIN_PKT_SIZE
- length
;
456 if (skb_pad(skb
, pad
)) {
457 /* SKB already freed. */
461 length
= BNXT_MIN_PKT_SIZE
;
464 mapping
= dma_map_single(&pdev
->dev
, skb
->data
, len
, DMA_TO_DEVICE
);
466 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
))) {
467 dev_kfree_skb_any(skb
);
472 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
473 flags
= (len
<< TX_BD_LEN_SHIFT
) | TX_BD_TYPE_LONG_TX_BD
|
474 ((last_frag
+ 2) << TX_BD_FLAGS_BD_CNT_SHIFT
);
476 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
478 prod
= NEXT_TX(prod
);
479 txbd1
= (struct tx_bd_ext
*)
480 &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
482 txbd1
->tx_bd_hsize_lflags
= 0;
483 if (skb_is_gso(skb
)) {
486 if (skb
->encapsulation
)
487 hdr_len
= skb_inner_network_offset(skb
) +
488 skb_inner_network_header_len(skb
) +
489 inner_tcp_hdrlen(skb
);
491 hdr_len
= skb_transport_offset(skb
) +
494 txbd1
->tx_bd_hsize_lflags
= cpu_to_le32(TX_BD_FLAGS_LSO
|
496 (hdr_len
<< (TX_BD_HSIZE_SHIFT
- 1)));
497 length
= skb_shinfo(skb
)->gso_size
;
498 txbd1
->tx_bd_mss
= cpu_to_le32(length
);
500 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
501 txbd1
->tx_bd_hsize_lflags
=
502 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM
);
503 txbd1
->tx_bd_mss
= 0;
507 if (unlikely(length
>= ARRAY_SIZE(bnxt_lhint_arr
))) {
508 dev_warn_ratelimited(&pdev
->dev
, "Dropped oversize %d bytes TX packet.\n",
513 flags
|= bnxt_lhint_arr
[length
];
514 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
516 txbd1
->tx_bd_cfa_meta
= cpu_to_le32(vlan_tag_flags
);
517 txbd1
->tx_bd_cfa_action
=
518 cpu_to_le32(cfa_action
<< TX_BD_CFA_ACTION_SHIFT
);
519 for (i
= 0; i
< last_frag
; i
++) {
520 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
522 prod
= NEXT_TX(prod
);
523 txbd
= &txr
->tx_desc_ring
[TX_RING(prod
)][TX_IDX(prod
)];
525 len
= skb_frag_size(frag
);
526 mapping
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, len
,
529 if (unlikely(dma_mapping_error(&pdev
->dev
, mapping
)))
532 tx_buf
= &txr
->tx_buf_ring
[prod
];
533 dma_unmap_addr_set(tx_buf
, mapping
, mapping
);
535 txbd
->tx_bd_haddr
= cpu_to_le64(mapping
);
537 flags
= len
<< TX_BD_LEN_SHIFT
;
538 txbd
->tx_bd_len_flags_type
= cpu_to_le32(flags
);
542 txbd
->tx_bd_len_flags_type
=
543 cpu_to_le32(((len
+ pad
) << TX_BD_LEN_SHIFT
) | flags
|
544 TX_BD_FLAGS_PACKET_END
);
546 netdev_tx_sent_queue(txq
, skb
->len
);
548 /* Sync BD data before updating doorbell */
551 prod
= NEXT_TX(prod
);
554 if (!skb
->xmit_more
|| netif_xmit_stopped(txq
))
555 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
561 if (unlikely(bnxt_tx_avail(bp
, txr
) <= MAX_SKB_FRAGS
+ 1)) {
562 if (skb
->xmit_more
&& !tx_buf
->is_push
)
563 bnxt_db_write(bp
, &txr
->tx_db
, prod
);
565 netif_tx_stop_queue(txq
);
567 /* netif_tx_stop_queue() must be done before checking
568 * tx index in bnxt_tx_avail() below, because in
569 * bnxt_tx_int(), we update tx index before checking for
570 * netif_tx_queue_stopped().
573 if (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)
574 netif_tx_wake_queue(txq
);
581 /* start back at beginning and unmap skb */
583 tx_buf
= &txr
->tx_buf_ring
[prod
];
585 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
586 skb_headlen(skb
), PCI_DMA_TODEVICE
);
587 prod
= NEXT_TX(prod
);
589 /* unmap remaining mapped pages */
590 for (i
= 0; i
< last_frag
; i
++) {
591 prod
= NEXT_TX(prod
);
592 tx_buf
= &txr
->tx_buf_ring
[prod
];
593 dma_unmap_page(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
594 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
598 dev_kfree_skb_any(skb
);
602 static void bnxt_tx_int(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int nr_pkts
)
604 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
605 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, txr
->txq_index
);
606 u16 cons
= txr
->tx_cons
;
607 struct pci_dev
*pdev
= bp
->pdev
;
609 unsigned int tx_bytes
= 0;
611 for (i
= 0; i
< nr_pkts
; i
++) {
612 struct bnxt_sw_tx_bd
*tx_buf
;
616 tx_buf
= &txr
->tx_buf_ring
[cons
];
617 cons
= NEXT_TX(cons
);
621 if (tx_buf
->is_push
) {
626 dma_unmap_single(&pdev
->dev
, dma_unmap_addr(tx_buf
, mapping
),
627 skb_headlen(skb
), PCI_DMA_TODEVICE
);
628 last
= tx_buf
->nr_frags
;
630 for (j
= 0; j
< last
; j
++) {
631 cons
= NEXT_TX(cons
);
632 tx_buf
= &txr
->tx_buf_ring
[cons
];
635 dma_unmap_addr(tx_buf
, mapping
),
636 skb_frag_size(&skb_shinfo(skb
)->frags
[j
]),
641 cons
= NEXT_TX(cons
);
643 tx_bytes
+= skb
->len
;
644 dev_kfree_skb_any(skb
);
647 netdev_tx_completed_queue(txq
, nr_pkts
, tx_bytes
);
650 /* Need to make the tx_cons update visible to bnxt_start_xmit()
651 * before checking for netif_tx_queue_stopped(). Without the
652 * memory barrier, there is a small possibility that bnxt_start_xmit()
653 * will miss it and cause the queue to be stopped forever.
657 if (unlikely(netif_tx_queue_stopped(txq
)) &&
658 (bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
)) {
659 __netif_tx_lock(txq
, smp_processor_id());
660 if (netif_tx_queue_stopped(txq
) &&
661 bnxt_tx_avail(bp
, txr
) > bp
->tx_wake_thresh
&&
662 txr
->dev_state
!= BNXT_DEV_STATE_CLOSING
)
663 netif_tx_wake_queue(txq
);
664 __netif_tx_unlock(txq
);
668 static struct page
*__bnxt_alloc_rx_page(struct bnxt
*bp
, dma_addr_t
*mapping
,
671 struct device
*dev
= &bp
->pdev
->dev
;
674 page
= alloc_page(gfp
);
678 *mapping
= dma_map_page_attrs(dev
, page
, 0, PAGE_SIZE
, bp
->rx_dir
,
679 DMA_ATTR_WEAK_ORDERING
);
680 if (dma_mapping_error(dev
, *mapping
)) {
684 *mapping
+= bp
->rx_dma_offset
;
688 static inline u8
*__bnxt_alloc_rx_data(struct bnxt
*bp
, dma_addr_t
*mapping
,
692 struct pci_dev
*pdev
= bp
->pdev
;
694 data
= kmalloc(bp
->rx_buf_size
, gfp
);
698 *mapping
= dma_map_single_attrs(&pdev
->dev
, data
+ bp
->rx_dma_offset
,
699 bp
->rx_buf_use_size
, bp
->rx_dir
,
700 DMA_ATTR_WEAK_ORDERING
);
702 if (dma_mapping_error(&pdev
->dev
, *mapping
)) {
709 int bnxt_alloc_rx_data(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
712 struct rx_bd
*rxbd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
713 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[prod
];
716 if (BNXT_RX_PAGE_MODE(bp
)) {
717 struct page
*page
= __bnxt_alloc_rx_page(bp
, &mapping
, gfp
);
723 rx_buf
->data_ptr
= page_address(page
) + bp
->rx_offset
;
725 u8
*data
= __bnxt_alloc_rx_data(bp
, &mapping
, gfp
);
731 rx_buf
->data_ptr
= data
+ bp
->rx_offset
;
733 rx_buf
->mapping
= mapping
;
735 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
739 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info
*rxr
, u16 cons
, void *data
)
741 u16 prod
= rxr
->rx_prod
;
742 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
743 struct rx_bd
*cons_bd
, *prod_bd
;
745 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
746 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
748 prod_rx_buf
->data
= data
;
749 prod_rx_buf
->data_ptr
= cons_rx_buf
->data_ptr
;
751 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
753 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
754 cons_bd
= &rxr
->rx_desc_ring
[RX_RING(cons
)][RX_IDX(cons
)];
756 prod_bd
->rx_bd_haddr
= cons_bd
->rx_bd_haddr
;
759 static inline u16
bnxt_find_next_agg_idx(struct bnxt_rx_ring_info
*rxr
, u16 idx
)
761 u16 next
, max
= rxr
->rx_agg_bmap_size
;
763 next
= find_next_zero_bit(rxr
->rx_agg_bmap
, max
, idx
);
765 next
= find_first_zero_bit(rxr
->rx_agg_bmap
, max
);
769 static inline int bnxt_alloc_rx_page(struct bnxt
*bp
,
770 struct bnxt_rx_ring_info
*rxr
,
774 &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
775 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
;
776 struct pci_dev
*pdev
= bp
->pdev
;
779 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
780 unsigned int offset
= 0;
782 if (PAGE_SIZE
> BNXT_RX_PAGE_SIZE
) {
785 page
= alloc_page(gfp
);
789 rxr
->rx_page_offset
= 0;
791 offset
= rxr
->rx_page_offset
;
792 rxr
->rx_page_offset
+= BNXT_RX_PAGE_SIZE
;
793 if (rxr
->rx_page_offset
== PAGE_SIZE
)
798 page
= alloc_page(gfp
);
803 mapping
= dma_map_page_attrs(&pdev
->dev
, page
, offset
,
804 BNXT_RX_PAGE_SIZE
, PCI_DMA_FROMDEVICE
,
805 DMA_ATTR_WEAK_ORDERING
);
806 if (dma_mapping_error(&pdev
->dev
, mapping
)) {
811 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
812 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
814 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
815 rx_agg_buf
= &rxr
->rx_agg_ring
[sw_prod
];
816 rxr
->rx_sw_agg_prod
= NEXT_RX_AGG(sw_prod
);
818 rx_agg_buf
->page
= page
;
819 rx_agg_buf
->offset
= offset
;
820 rx_agg_buf
->mapping
= mapping
;
821 rxbd
->rx_bd_haddr
= cpu_to_le64(mapping
);
822 rxbd
->rx_bd_opaque
= sw_prod
;
826 static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info
*cpr
, u16 cp_cons
,
829 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
830 struct bnxt
*bp
= bnapi
->bp
;
831 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
832 u16 prod
= rxr
->rx_agg_prod
;
833 u16 sw_prod
= rxr
->rx_sw_agg_prod
;
836 for (i
= 0; i
< agg_bufs
; i
++) {
838 struct rx_agg_cmp
*agg
;
839 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
, *prod_rx_buf
;
840 struct rx_bd
*prod_bd
;
843 agg
= (struct rx_agg_cmp
*)
844 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
845 cons
= agg
->rx_agg_cmp_opaque
;
846 __clear_bit(cons
, rxr
->rx_agg_bmap
);
848 if (unlikely(test_bit(sw_prod
, rxr
->rx_agg_bmap
)))
849 sw_prod
= bnxt_find_next_agg_idx(rxr
, sw_prod
);
851 __set_bit(sw_prod
, rxr
->rx_agg_bmap
);
852 prod_rx_buf
= &rxr
->rx_agg_ring
[sw_prod
];
853 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
855 /* It is possible for sw_prod to be equal to cons, so
856 * set cons_rx_buf->page to NULL first.
858 page
= cons_rx_buf
->page
;
859 cons_rx_buf
->page
= NULL
;
860 prod_rx_buf
->page
= page
;
861 prod_rx_buf
->offset
= cons_rx_buf
->offset
;
863 prod_rx_buf
->mapping
= cons_rx_buf
->mapping
;
865 prod_bd
= &rxr
->rx_agg_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
867 prod_bd
->rx_bd_haddr
= cpu_to_le64(cons_rx_buf
->mapping
);
868 prod_bd
->rx_bd_opaque
= sw_prod
;
870 prod
= NEXT_RX_AGG(prod
);
871 sw_prod
= NEXT_RX_AGG(sw_prod
);
872 cp_cons
= NEXT_CMP(cp_cons
);
874 rxr
->rx_agg_prod
= prod
;
875 rxr
->rx_sw_agg_prod
= sw_prod
;
878 static struct sk_buff
*bnxt_rx_page_skb(struct bnxt
*bp
,
879 struct bnxt_rx_ring_info
*rxr
,
880 u16 cons
, void *data
, u8
*data_ptr
,
882 unsigned int offset_and_len
)
884 unsigned int payload
= offset_and_len
>> 16;
885 unsigned int len
= offset_and_len
& 0xffff;
886 struct skb_frag_struct
*frag
;
887 struct page
*page
= data
;
888 u16 prod
= rxr
->rx_prod
;
892 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
894 bnxt_reuse_rx_data(rxr
, cons
, data
);
897 dma_addr
-= bp
->rx_dma_offset
;
898 dma_unmap_page_attrs(&bp
->pdev
->dev
, dma_addr
, PAGE_SIZE
, bp
->rx_dir
,
899 DMA_ATTR_WEAK_ORDERING
);
901 if (unlikely(!payload
))
902 payload
= eth_get_headlen(data_ptr
, len
);
904 skb
= napi_alloc_skb(&rxr
->bnapi
->napi
, payload
);
910 off
= (void *)data_ptr
- page_address(page
);
911 skb_add_rx_frag(skb
, 0, page
, off
, len
, PAGE_SIZE
);
912 memcpy(skb
->data
- NET_IP_ALIGN
, data_ptr
- NET_IP_ALIGN
,
913 payload
+ NET_IP_ALIGN
);
915 frag
= &skb_shinfo(skb
)->frags
[0];
916 skb_frag_size_sub(frag
, payload
);
917 frag
->page_offset
+= payload
;
918 skb
->data_len
-= payload
;
919 skb
->tail
+= payload
;
924 static struct sk_buff
*bnxt_rx_skb(struct bnxt
*bp
,
925 struct bnxt_rx_ring_info
*rxr
, u16 cons
,
926 void *data
, u8
*data_ptr
,
928 unsigned int offset_and_len
)
930 u16 prod
= rxr
->rx_prod
;
934 err
= bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_ATOMIC
);
936 bnxt_reuse_rx_data(rxr
, cons
, data
);
940 skb
= build_skb(data
, 0);
941 dma_unmap_single_attrs(&bp
->pdev
->dev
, dma_addr
, bp
->rx_buf_use_size
,
942 bp
->rx_dir
, DMA_ATTR_WEAK_ORDERING
);
948 skb_reserve(skb
, bp
->rx_offset
);
949 skb_put(skb
, offset_and_len
& 0xffff);
953 static struct sk_buff
*bnxt_rx_pages(struct bnxt
*bp
,
954 struct bnxt_cp_ring_info
*cpr
,
955 struct sk_buff
*skb
, u16 cp_cons
,
958 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
959 struct pci_dev
*pdev
= bp
->pdev
;
960 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
961 u16 prod
= rxr
->rx_agg_prod
;
964 for (i
= 0; i
< agg_bufs
; i
++) {
966 struct rx_agg_cmp
*agg
;
967 struct bnxt_sw_rx_agg_bd
*cons_rx_buf
;
971 agg
= (struct rx_agg_cmp
*)
972 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
973 cons
= agg
->rx_agg_cmp_opaque
;
974 frag_len
= (le32_to_cpu(agg
->rx_agg_cmp_len_flags_type
) &
975 RX_AGG_CMP_LEN
) >> RX_AGG_CMP_LEN_SHIFT
;
977 cons_rx_buf
= &rxr
->rx_agg_ring
[cons
];
978 skb_fill_page_desc(skb
, i
, cons_rx_buf
->page
,
979 cons_rx_buf
->offset
, frag_len
);
980 __clear_bit(cons
, rxr
->rx_agg_bmap
);
982 /* It is possible for bnxt_alloc_rx_page() to allocate
983 * a sw_prod index that equals the cons index, so we
984 * need to clear the cons entry now.
986 mapping
= cons_rx_buf
->mapping
;
987 page
= cons_rx_buf
->page
;
988 cons_rx_buf
->page
= NULL
;
990 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_ATOMIC
) != 0) {
991 struct skb_shared_info
*shinfo
;
992 unsigned int nr_frags
;
994 shinfo
= skb_shinfo(skb
);
995 nr_frags
= --shinfo
->nr_frags
;
996 __skb_frag_set_page(&shinfo
->frags
[nr_frags
], NULL
);
1000 cons_rx_buf
->page
= page
;
1002 /* Update prod since possibly some pages have been
1003 * allocated already.
1005 rxr
->rx_agg_prod
= prod
;
1006 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, agg_bufs
- i
);
1010 dma_unmap_page_attrs(&pdev
->dev
, mapping
, BNXT_RX_PAGE_SIZE
,
1012 DMA_ATTR_WEAK_ORDERING
);
1014 skb
->data_len
+= frag_len
;
1015 skb
->len
+= frag_len
;
1016 skb
->truesize
+= PAGE_SIZE
;
1018 prod
= NEXT_RX_AGG(prod
);
1019 cp_cons
= NEXT_CMP(cp_cons
);
1021 rxr
->rx_agg_prod
= prod
;
1025 static int bnxt_agg_bufs_valid(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1026 u8 agg_bufs
, u32
*raw_cons
)
1029 struct rx_agg_cmp
*agg
;
1031 *raw_cons
= ADV_RAW_CMP(*raw_cons
, agg_bufs
);
1032 last
= RING_CMP(*raw_cons
);
1033 agg
= (struct rx_agg_cmp
*)
1034 &cpr
->cp_desc_ring
[CP_RING(last
)][CP_IDX(last
)];
1035 return RX_AGG_CMP_VALID(agg
, *raw_cons
);
1038 static inline struct sk_buff
*bnxt_copy_skb(struct bnxt_napi
*bnapi
, u8
*data
,
1042 struct bnxt
*bp
= bnapi
->bp
;
1043 struct pci_dev
*pdev
= bp
->pdev
;
1044 struct sk_buff
*skb
;
1046 skb
= napi_alloc_skb(&bnapi
->napi
, len
);
1050 dma_sync_single_for_cpu(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1053 memcpy(skb
->data
- NET_IP_ALIGN
, data
- NET_IP_ALIGN
,
1054 len
+ NET_IP_ALIGN
);
1056 dma_sync_single_for_device(&pdev
->dev
, mapping
, bp
->rx_copy_thresh
,
1063 static int bnxt_discard_rx(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1064 u32
*raw_cons
, void *cmp
)
1066 struct rx_cmp
*rxcmp
= cmp
;
1067 u32 tmp_raw_cons
= *raw_cons
;
1068 u8 cmp_type
, agg_bufs
= 0;
1070 cmp_type
= RX_CMP_TYPE(rxcmp
);
1072 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1073 agg_bufs
= (le32_to_cpu(rxcmp
->rx_cmp_misc_v1
) &
1075 RX_CMP_AGG_BUFS_SHIFT
;
1076 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1077 struct rx_tpa_end_cmp
*tpa_end
= cmp
;
1079 agg_bufs
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1080 RX_TPA_END_CMP_AGG_BUFS
) >>
1081 RX_TPA_END_CMP_AGG_BUFS_SHIFT
;
1085 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1088 *raw_cons
= tmp_raw_cons
;
1092 static void bnxt_queue_sp_work(struct bnxt
*bp
)
1095 queue_work(bnxt_pf_wq
, &bp
->sp_task
);
1097 schedule_work(&bp
->sp_task
);
1100 static void bnxt_cancel_sp_work(struct bnxt
*bp
)
1103 flush_workqueue(bnxt_pf_wq
);
1105 cancel_work_sync(&bp
->sp_task
);
1108 static void bnxt_sched_reset(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
1110 if (!rxr
->bnapi
->in_reset
) {
1111 rxr
->bnapi
->in_reset
= true;
1112 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
1113 bnxt_queue_sp_work(bp
);
1115 rxr
->rx_next_cons
= 0xffff;
1118 static void bnxt_tpa_start(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
,
1119 struct rx_tpa_start_cmp
*tpa_start
,
1120 struct rx_tpa_start_cmp_ext
*tpa_start1
)
1122 u8 agg_id
= TPA_START_AGG_ID(tpa_start
);
1124 struct bnxt_tpa_info
*tpa_info
;
1125 struct bnxt_sw_rx_bd
*cons_rx_buf
, *prod_rx_buf
;
1126 struct rx_bd
*prod_bd
;
1129 cons
= tpa_start
->rx_tpa_start_cmp_opaque
;
1130 prod
= rxr
->rx_prod
;
1131 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1132 prod_rx_buf
= &rxr
->rx_buf_ring
[prod
];
1133 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1135 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1136 netdev_warn(bp
->dev
, "TPA cons %x != expected cons %x\n",
1137 cons
, rxr
->rx_next_cons
);
1138 bnxt_sched_reset(bp
, rxr
);
1141 /* Store cfa_code in tpa_info to use in tpa_end
1142 * completion processing.
1144 tpa_info
->cfa_code
= TPA_START_CFA_CODE(tpa_start1
);
1145 prod_rx_buf
->data
= tpa_info
->data
;
1146 prod_rx_buf
->data_ptr
= tpa_info
->data_ptr
;
1148 mapping
= tpa_info
->mapping
;
1149 prod_rx_buf
->mapping
= mapping
;
1151 prod_bd
= &rxr
->rx_desc_ring
[RX_RING(prod
)][RX_IDX(prod
)];
1153 prod_bd
->rx_bd_haddr
= cpu_to_le64(mapping
);
1155 tpa_info
->data
= cons_rx_buf
->data
;
1156 tpa_info
->data_ptr
= cons_rx_buf
->data_ptr
;
1157 cons_rx_buf
->data
= NULL
;
1158 tpa_info
->mapping
= cons_rx_buf
->mapping
;
1161 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_len_flags_type
) >>
1162 RX_TPA_START_CMP_LEN_SHIFT
;
1163 if (likely(TPA_START_HASH_VALID(tpa_start
))) {
1164 u32 hash_type
= TPA_START_HASH_TYPE(tpa_start
);
1166 tpa_info
->hash_type
= PKT_HASH_TYPE_L4
;
1167 tpa_info
->gso_type
= SKB_GSO_TCPV4
;
1168 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1169 if (hash_type
== 3 || TPA_START_IS_IPV6(tpa_start1
))
1170 tpa_info
->gso_type
= SKB_GSO_TCPV6
;
1171 tpa_info
->rss_hash
=
1172 le32_to_cpu(tpa_start
->rx_tpa_start_cmp_rss_hash
);
1174 tpa_info
->hash_type
= PKT_HASH_TYPE_NONE
;
1175 tpa_info
->gso_type
= 0;
1176 if (netif_msg_rx_err(bp
))
1177 netdev_warn(bp
->dev
, "TPA packet without valid hash\n");
1179 tpa_info
->flags2
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_flags2
);
1180 tpa_info
->metadata
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_metadata
);
1181 tpa_info
->hdr_info
= le32_to_cpu(tpa_start1
->rx_tpa_start_cmp_hdr_info
);
1183 rxr
->rx_prod
= NEXT_RX(prod
);
1184 cons
= NEXT_RX(cons
);
1185 rxr
->rx_next_cons
= NEXT_RX(cons
);
1186 cons_rx_buf
= &rxr
->rx_buf_ring
[cons
];
1188 bnxt_reuse_rx_data(rxr
, cons
, cons_rx_buf
->data
);
1189 rxr
->rx_prod
= NEXT_RX(rxr
->rx_prod
);
1190 cons_rx_buf
->data
= NULL
;
1193 static void bnxt_abort_tpa(struct bnxt_cp_ring_info
*cpr
, u16 cp_cons
,
1197 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, agg_bufs
);
1200 static struct sk_buff
*bnxt_gro_func_5731x(struct bnxt_tpa_info
*tpa_info
,
1201 int payload_off
, int tcp_ts
,
1202 struct sk_buff
*skb
)
1207 u16 outer_ip_off
, inner_ip_off
, inner_mac_off
;
1208 u32 hdr_info
= tpa_info
->hdr_info
;
1209 bool loopback
= false;
1211 inner_ip_off
= BNXT_TPA_INNER_L3_OFF(hdr_info
);
1212 inner_mac_off
= BNXT_TPA_INNER_L2_OFF(hdr_info
);
1213 outer_ip_off
= BNXT_TPA_OUTER_L3_OFF(hdr_info
);
1215 /* If the packet is an internal loopback packet, the offsets will
1216 * have an extra 4 bytes.
1218 if (inner_mac_off
== 4) {
1220 } else if (inner_mac_off
> 4) {
1221 __be16 proto
= *((__be16
*)(skb
->data
+ inner_ip_off
-
1224 /* We only support inner iPv4/ipv6. If we don't see the
1225 * correct protocol ID, it must be a loopback packet where
1226 * the offsets are off by 4.
1228 if (proto
!= htons(ETH_P_IP
) && proto
!= htons(ETH_P_IPV6
))
1232 /* internal loopback packet, subtract all offsets by 4 */
1238 nw_off
= inner_ip_off
- ETH_HLEN
;
1239 skb_set_network_header(skb
, nw_off
);
1240 if (tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_IP_TYPE
) {
1241 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
1243 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1244 len
= skb
->len
- skb_transport_offset(skb
);
1246 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1248 struct iphdr
*iph
= ip_hdr(skb
);
1250 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1251 len
= skb
->len
- skb_transport_offset(skb
);
1253 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1256 if (inner_mac_off
) { /* tunnel */
1257 struct udphdr
*uh
= NULL
;
1258 __be16 proto
= *((__be16
*)(skb
->data
+ outer_ip_off
-
1261 if (proto
== htons(ETH_P_IP
)) {
1262 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1264 if (iph
->protocol
== IPPROTO_UDP
)
1265 uh
= (struct udphdr
*)(iph
+ 1);
1267 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1269 if (iph
->nexthdr
== IPPROTO_UDP
)
1270 uh
= (struct udphdr
*)(iph
+ 1);
1274 skb_shinfo(skb
)->gso_type
|=
1275 SKB_GSO_UDP_TUNNEL_CSUM
;
1277 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1284 #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1285 #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1287 static struct sk_buff
*bnxt_gro_func_5730x(struct bnxt_tpa_info
*tpa_info
,
1288 int payload_off
, int tcp_ts
,
1289 struct sk_buff
*skb
)
1293 int len
, nw_off
, tcp_opt_len
= 0;
1298 if (tpa_info
->gso_type
== SKB_GSO_TCPV4
) {
1301 nw_off
= payload_off
- BNXT_IPV4_HDR_SIZE
- tcp_opt_len
-
1303 skb_set_network_header(skb
, nw_off
);
1305 skb_set_transport_header(skb
, nw_off
+ sizeof(struct iphdr
));
1306 len
= skb
->len
- skb_transport_offset(skb
);
1308 th
->check
= ~tcp_v4_check(len
, iph
->saddr
, iph
->daddr
, 0);
1309 } else if (tpa_info
->gso_type
== SKB_GSO_TCPV6
) {
1310 struct ipv6hdr
*iph
;
1312 nw_off
= payload_off
- BNXT_IPV6_HDR_SIZE
- tcp_opt_len
-
1314 skb_set_network_header(skb
, nw_off
);
1315 iph
= ipv6_hdr(skb
);
1316 skb_set_transport_header(skb
, nw_off
+ sizeof(struct ipv6hdr
));
1317 len
= skb
->len
- skb_transport_offset(skb
);
1319 th
->check
= ~tcp_v6_check(len
, &iph
->saddr
, &iph
->daddr
, 0);
1321 dev_kfree_skb_any(skb
);
1325 if (nw_off
) { /* tunnel */
1326 struct udphdr
*uh
= NULL
;
1328 if (skb
->protocol
== htons(ETH_P_IP
)) {
1329 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
1331 if (iph
->protocol
== IPPROTO_UDP
)
1332 uh
= (struct udphdr
*)(iph
+ 1);
1334 struct ipv6hdr
*iph
= (struct ipv6hdr
*)skb
->data
;
1336 if (iph
->nexthdr
== IPPROTO_UDP
)
1337 uh
= (struct udphdr
*)(iph
+ 1);
1341 skb_shinfo(skb
)->gso_type
|=
1342 SKB_GSO_UDP_TUNNEL_CSUM
;
1344 skb_shinfo(skb
)->gso_type
|= SKB_GSO_UDP_TUNNEL
;
1351 static inline struct sk_buff
*bnxt_gro_skb(struct bnxt
*bp
,
1352 struct bnxt_tpa_info
*tpa_info
,
1353 struct rx_tpa_end_cmp
*tpa_end
,
1354 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1355 struct sk_buff
*skb
)
1361 segs
= TPA_END_TPA_SEGS(tpa_end
);
1365 NAPI_GRO_CB(skb
)->count
= segs
;
1366 skb_shinfo(skb
)->gso_size
=
1367 le32_to_cpu(tpa_end1
->rx_tpa_end_cmp_seg_len
);
1368 skb_shinfo(skb
)->gso_type
= tpa_info
->gso_type
;
1369 payload_off
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1370 RX_TPA_END_CMP_PAYLOAD_OFFSET
) >>
1371 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT
;
1372 skb
= bp
->gro_func(tpa_info
, payload_off
, TPA_END_GRO_TS(tpa_end
), skb
);
1374 tcp_gro_complete(skb
);
1379 /* Given the cfa_code of a received packet determine which
1380 * netdev (vf-rep or PF) the packet is destined to.
1382 static struct net_device
*bnxt_get_pkt_dev(struct bnxt
*bp
, u16 cfa_code
)
1384 struct net_device
*dev
= bnxt_get_vf_rep(bp
, cfa_code
);
1386 /* if vf-rep dev is NULL, the must belongs to the PF */
1387 return dev
? dev
: bp
->dev
;
1390 static inline struct sk_buff
*bnxt_tpa_end(struct bnxt
*bp
,
1391 struct bnxt_cp_ring_info
*cpr
,
1393 struct rx_tpa_end_cmp
*tpa_end
,
1394 struct rx_tpa_end_cmp_ext
*tpa_end1
,
1397 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1398 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1399 u8 agg_id
= TPA_END_AGG_ID(tpa_end
);
1400 u8
*data_ptr
, agg_bufs
;
1401 u16 cp_cons
= RING_CMP(*raw_cons
);
1403 struct bnxt_tpa_info
*tpa_info
;
1405 struct sk_buff
*skb
;
1408 if (unlikely(bnapi
->in_reset
)) {
1409 int rc
= bnxt_discard_rx(bp
, cpr
, raw_cons
, tpa_end
);
1412 return ERR_PTR(-EBUSY
);
1416 tpa_info
= &rxr
->rx_tpa
[agg_id
];
1417 data
= tpa_info
->data
;
1418 data_ptr
= tpa_info
->data_ptr
;
1420 len
= tpa_info
->len
;
1421 mapping
= tpa_info
->mapping
;
1423 agg_bufs
= (le32_to_cpu(tpa_end
->rx_tpa_end_cmp_misc_v1
) &
1424 RX_TPA_END_CMP_AGG_BUFS
) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT
;
1427 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, raw_cons
))
1428 return ERR_PTR(-EBUSY
);
1430 *event
|= BNXT_AGG_EVENT
;
1431 cp_cons
= NEXT_CMP(cp_cons
);
1434 if (unlikely(agg_bufs
> MAX_SKB_FRAGS
|| TPA_END_ERRORS(tpa_end1
))) {
1435 bnxt_abort_tpa(cpr
, cp_cons
, agg_bufs
);
1436 if (agg_bufs
> MAX_SKB_FRAGS
)
1437 netdev_warn(bp
->dev
, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1438 agg_bufs
, (int)MAX_SKB_FRAGS
);
1442 if (len
<= bp
->rx_copy_thresh
) {
1443 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, mapping
);
1445 bnxt_abort_tpa(cpr
, cp_cons
, agg_bufs
);
1450 dma_addr_t new_mapping
;
1452 new_data
= __bnxt_alloc_rx_data(bp
, &new_mapping
, GFP_ATOMIC
);
1454 bnxt_abort_tpa(cpr
, cp_cons
, agg_bufs
);
1458 tpa_info
->data
= new_data
;
1459 tpa_info
->data_ptr
= new_data
+ bp
->rx_offset
;
1460 tpa_info
->mapping
= new_mapping
;
1462 skb
= build_skb(data
, 0);
1463 dma_unmap_single_attrs(&bp
->pdev
->dev
, mapping
,
1464 bp
->rx_buf_use_size
, bp
->rx_dir
,
1465 DMA_ATTR_WEAK_ORDERING
);
1469 bnxt_abort_tpa(cpr
, cp_cons
, agg_bufs
);
1472 skb_reserve(skb
, bp
->rx_offset
);
1477 skb
= bnxt_rx_pages(bp
, cpr
, skb
, cp_cons
, agg_bufs
);
1479 /* Page reuse already handled by bnxt_rx_pages(). */
1485 eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, tpa_info
->cfa_code
));
1487 if (tpa_info
->hash_type
!= PKT_HASH_TYPE_NONE
)
1488 skb_set_hash(skb
, tpa_info
->rss_hash
, tpa_info
->hash_type
);
1490 if ((tpa_info
->flags2
& RX_CMP_FLAGS2_META_FORMAT_VLAN
) &&
1491 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1492 u16 vlan_proto
= tpa_info
->metadata
>>
1493 RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1494 u16 vtag
= tpa_info
->metadata
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1496 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1499 skb_checksum_none_assert(skb
);
1500 if (likely(tpa_info
->flags2
& RX_TPA_START_CMP_FLAGS2_L4_CS_CALC
)) {
1501 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1503 (tpa_info
->flags2
& RX_CMP_FLAGS2_T_L4_CS_CALC
) >> 3;
1506 if (TPA_END_GRO(tpa_end
))
1507 skb
= bnxt_gro_skb(bp
, tpa_info
, tpa_end
, tpa_end1
, skb
);
1512 static void bnxt_deliver_skb(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
1513 struct sk_buff
*skb
)
1515 if (skb
->dev
!= bp
->dev
) {
1516 /* this packet belongs to a vf-rep */
1517 bnxt_vf_rep_rx(bp
, skb
);
1520 skb_record_rx_queue(skb
, bnapi
->index
);
1521 napi_gro_receive(&bnapi
->napi
, skb
);
1524 /* returns the following:
1525 * 1 - 1 packet successfully received
1526 * 0 - successful TPA_START, packet not completed yet
1527 * -EBUSY - completion ring does not have all the agg buffers yet
1528 * -ENOMEM - packet aborted due to out of memory
1529 * -EIO - packet aborted due to hw error indicated in BD
1531 static int bnxt_rx_pkt(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1532 u32
*raw_cons
, u8
*event
)
1534 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1535 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
1536 struct net_device
*dev
= bp
->dev
;
1537 struct rx_cmp
*rxcmp
;
1538 struct rx_cmp_ext
*rxcmp1
;
1539 u32 tmp_raw_cons
= *raw_cons
;
1540 u16 cfa_code
, cons
, prod
, cp_cons
= RING_CMP(tmp_raw_cons
);
1541 struct bnxt_sw_rx_bd
*rx_buf
;
1543 u8
*data_ptr
, agg_bufs
, cmp_type
;
1544 dma_addr_t dma_addr
;
1545 struct sk_buff
*skb
;
1550 rxcmp
= (struct rx_cmp
*)
1551 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1553 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1554 cp_cons
= RING_CMP(tmp_raw_cons
);
1555 rxcmp1
= (struct rx_cmp_ext
*)
1556 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1558 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1561 cmp_type
= RX_CMP_TYPE(rxcmp
);
1563 prod
= rxr
->rx_prod
;
1565 if (cmp_type
== CMP_TYPE_RX_L2_TPA_START_CMP
) {
1566 bnxt_tpa_start(bp
, rxr
, (struct rx_tpa_start_cmp
*)rxcmp
,
1567 (struct rx_tpa_start_cmp_ext
*)rxcmp1
);
1569 *event
|= BNXT_RX_EVENT
;
1570 goto next_rx_no_prod_no_len
;
1572 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1573 skb
= bnxt_tpa_end(bp
, cpr
, &tmp_raw_cons
,
1574 (struct rx_tpa_end_cmp
*)rxcmp
,
1575 (struct rx_tpa_end_cmp_ext
*)rxcmp1
, event
);
1582 bnxt_deliver_skb(bp
, bnapi
, skb
);
1585 *event
|= BNXT_RX_EVENT
;
1586 goto next_rx_no_prod_no_len
;
1589 cons
= rxcmp
->rx_cmp_opaque
;
1590 if (unlikely(cons
!= rxr
->rx_next_cons
)) {
1591 int rc1
= bnxt_discard_rx(bp
, cpr
, raw_cons
, rxcmp
);
1593 netdev_warn(bp
->dev
, "RX cons %x != expected cons %x\n",
1594 cons
, rxr
->rx_next_cons
);
1595 bnxt_sched_reset(bp
, rxr
);
1598 rx_buf
= &rxr
->rx_buf_ring
[cons
];
1599 data
= rx_buf
->data
;
1600 data_ptr
= rx_buf
->data_ptr
;
1603 misc
= le32_to_cpu(rxcmp
->rx_cmp_misc_v1
);
1604 agg_bufs
= (misc
& RX_CMP_AGG_BUFS
) >> RX_CMP_AGG_BUFS_SHIFT
;
1607 if (!bnxt_agg_bufs_valid(bp
, cpr
, agg_bufs
, &tmp_raw_cons
))
1610 cp_cons
= NEXT_CMP(cp_cons
);
1611 *event
|= BNXT_AGG_EVENT
;
1613 *event
|= BNXT_RX_EVENT
;
1615 rx_buf
->data
= NULL
;
1616 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L2_ERRORS
) {
1617 u32 rx_err
= le32_to_cpu(rxcmp1
->rx_cmp_cfa_code_errors_v2
);
1619 bnxt_reuse_rx_data(rxr
, cons
, data
);
1621 bnxt_reuse_rx_agg_bufs(cpr
, cp_cons
, agg_bufs
);
1624 if (rx_err
& RX_CMPL_ERRORS_BUFFER_ERROR_MASK
) {
1625 netdev_warn(bp
->dev
, "RX buffer error %x\n", rx_err
);
1626 bnxt_sched_reset(bp
, rxr
);
1631 len
= le32_to_cpu(rxcmp
->rx_cmp_len_flags_type
) >> RX_CMP_LEN_SHIFT
;
1632 dma_addr
= rx_buf
->mapping
;
1634 if (bnxt_rx_xdp(bp
, rxr
, cons
, data
, &data_ptr
, &len
, event
)) {
1639 if (len
<= bp
->rx_copy_thresh
) {
1640 skb
= bnxt_copy_skb(bnapi
, data_ptr
, len
, dma_addr
);
1641 bnxt_reuse_rx_data(rxr
, cons
, data
);
1649 if (rx_buf
->data_ptr
== data_ptr
)
1650 payload
= misc
& RX_CMP_PAYLOAD_OFFSET
;
1653 skb
= bp
->rx_skb_func(bp
, rxr
, cons
, data
, data_ptr
, dma_addr
,
1662 skb
= bnxt_rx_pages(bp
, cpr
, skb
, cp_cons
, agg_bufs
);
1669 if (RX_CMP_HASH_VALID(rxcmp
)) {
1670 u32 hash_type
= RX_CMP_HASH_TYPE(rxcmp
);
1671 enum pkt_hash_types type
= PKT_HASH_TYPE_L4
;
1673 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1674 if (hash_type
!= 1 && hash_type
!= 3)
1675 type
= PKT_HASH_TYPE_L3
;
1676 skb_set_hash(skb
, le32_to_cpu(rxcmp
->rx_cmp_rss_hash
), type
);
1679 cfa_code
= RX_CMP_CFA_CODE(rxcmp1
);
1680 skb
->protocol
= eth_type_trans(skb
, bnxt_get_pkt_dev(bp
, cfa_code
));
1682 if ((rxcmp1
->rx_cmp_flags2
&
1683 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN
)) &&
1684 (skb
->dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)) {
1685 u32 meta_data
= le32_to_cpu(rxcmp1
->rx_cmp_meta_data
);
1686 u16 vtag
= meta_data
& RX_CMP_FLAGS2_METADATA_TCI_MASK
;
1687 u16 vlan_proto
= meta_data
>> RX_CMP_FLAGS2_METADATA_TPID_SFT
;
1689 __vlan_hwaccel_put_tag(skb
, htons(vlan_proto
), vtag
);
1692 skb_checksum_none_assert(skb
);
1693 if (RX_CMP_L4_CS_OK(rxcmp1
)) {
1694 if (dev
->features
& NETIF_F_RXCSUM
) {
1695 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1696 skb
->csum_level
= RX_CMP_ENCAP(rxcmp1
);
1699 if (rxcmp1
->rx_cmp_cfa_code_errors_v2
& RX_CMP_L4_CS_ERR_BITS
) {
1700 if (dev
->features
& NETIF_F_RXCSUM
)
1701 bnapi
->cp_ring
.rx_l4_csum_errors
++;
1705 bnxt_deliver_skb(bp
, bnapi
, skb
);
1709 rxr
->rx_prod
= NEXT_RX(prod
);
1710 rxr
->rx_next_cons
= NEXT_RX(cons
);
1712 cpr
->rx_packets
+= 1;
1713 cpr
->rx_bytes
+= len
;
1715 next_rx_no_prod_no_len
:
1716 *raw_cons
= tmp_raw_cons
;
1721 /* In netpoll mode, if we are using a combined completion ring, we need to
1722 * discard the rx packets and recycle the buffers.
1724 static int bnxt_force_rx_discard(struct bnxt
*bp
,
1725 struct bnxt_cp_ring_info
*cpr
,
1726 u32
*raw_cons
, u8
*event
)
1728 u32 tmp_raw_cons
= *raw_cons
;
1729 struct rx_cmp_ext
*rxcmp1
;
1730 struct rx_cmp
*rxcmp
;
1734 cp_cons
= RING_CMP(tmp_raw_cons
);
1735 rxcmp
= (struct rx_cmp
*)
1736 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1738 tmp_raw_cons
= NEXT_RAW_CMP(tmp_raw_cons
);
1739 cp_cons
= RING_CMP(tmp_raw_cons
);
1740 rxcmp1
= (struct rx_cmp_ext
*)
1741 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
1743 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
1746 cmp_type
= RX_CMP_TYPE(rxcmp
);
1747 if (cmp_type
== CMP_TYPE_RX_L2_CMP
) {
1748 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
1749 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
1750 } else if (cmp_type
== CMP_TYPE_RX_L2_TPA_END_CMP
) {
1751 struct rx_tpa_end_cmp_ext
*tpa_end1
;
1753 tpa_end1
= (struct rx_tpa_end_cmp_ext
*)rxcmp1
;
1754 tpa_end1
->rx_tpa_end_cmp_errors_v2
|=
1755 cpu_to_le32(RX_TPA_END_CMP_ERRORS
);
1757 return bnxt_rx_pkt(bp
, cpr
, raw_cons
, event
);
1760 #define BNXT_GET_EVENT_PORT(data) \
1762 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
1764 static int bnxt_async_event_process(struct bnxt
*bp
,
1765 struct hwrm_async_event_cmpl
*cmpl
)
1767 u16 event_id
= le16_to_cpu(cmpl
->event_id
);
1769 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1771 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE
: {
1772 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1773 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1776 goto async_event_process_exit
;
1778 /* print unsupported speed warning in forced speed mode only */
1779 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
) &&
1780 (data1
& 0x20000)) {
1781 u16 fw_speed
= link_info
->force_link_speed
;
1782 u32 speed
= bnxt_fw_to_ethtool_speed(fw_speed
);
1784 if (speed
!= SPEED_UNKNOWN
)
1785 netdev_warn(bp
->dev
, "Link speed %d no longer supported\n",
1788 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
, &bp
->sp_event
);
1791 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE
:
1792 set_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
);
1794 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD
:
1795 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
);
1797 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED
: {
1798 u32 data1
= le32_to_cpu(cmpl
->event_data1
);
1799 u16 port_id
= BNXT_GET_EVENT_PORT(data1
);
1804 if (bp
->pf
.port_id
!= port_id
)
1807 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
);
1810 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE
:
1812 goto async_event_process_exit
;
1813 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
);
1816 goto async_event_process_exit
;
1818 bnxt_queue_sp_work(bp
);
1819 async_event_process_exit
:
1820 bnxt_ulp_async_events(bp
, cmpl
);
1824 static int bnxt_hwrm_handler(struct bnxt
*bp
, struct tx_cmp
*txcmp
)
1826 u16 cmpl_type
= TX_CMP_TYPE(txcmp
), vf_id
, seq_id
;
1827 struct hwrm_cmpl
*h_cmpl
= (struct hwrm_cmpl
*)txcmp
;
1828 struct hwrm_fwd_req_cmpl
*fwd_req_cmpl
=
1829 (struct hwrm_fwd_req_cmpl
*)txcmp
;
1831 switch (cmpl_type
) {
1832 case CMPL_BASE_TYPE_HWRM_DONE
:
1833 seq_id
= le16_to_cpu(h_cmpl
->sequence_id
);
1834 if (seq_id
== bp
->hwrm_intr_seq_id
)
1835 bp
->hwrm_intr_seq_id
= (u16
)~bp
->hwrm_intr_seq_id
;
1837 netdev_err(bp
->dev
, "Invalid hwrm seq id %d\n", seq_id
);
1840 case CMPL_BASE_TYPE_HWRM_FWD_REQ
:
1841 vf_id
= le16_to_cpu(fwd_req_cmpl
->source_id
);
1843 if ((vf_id
< bp
->pf
.first_vf_id
) ||
1844 (vf_id
>= bp
->pf
.first_vf_id
+ bp
->pf
.active_vfs
)) {
1845 netdev_err(bp
->dev
, "Msg contains invalid VF id %x\n",
1850 set_bit(vf_id
- bp
->pf
.first_vf_id
, bp
->pf
.vf_event_bmap
);
1851 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
);
1852 bnxt_queue_sp_work(bp
);
1855 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
:
1856 bnxt_async_event_process(bp
,
1857 (struct hwrm_async_event_cmpl
*)txcmp
);
1866 static irqreturn_t
bnxt_msix(int irq
, void *dev_instance
)
1868 struct bnxt_napi
*bnapi
= dev_instance
;
1869 struct bnxt
*bp
= bnapi
->bp
;
1870 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1871 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1874 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1875 napi_schedule(&bnapi
->napi
);
1879 static inline int bnxt_has_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
)
1881 u32 raw_cons
= cpr
->cp_raw_cons
;
1882 u16 cons
= RING_CMP(raw_cons
);
1883 struct tx_cmp
*txcmp
;
1885 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1887 return TX_CMP_VALID(txcmp
, raw_cons
);
1890 static irqreturn_t
bnxt_inta(int irq
, void *dev_instance
)
1892 struct bnxt_napi
*bnapi
= dev_instance
;
1893 struct bnxt
*bp
= bnapi
->bp
;
1894 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
1895 u32 cons
= RING_CMP(cpr
->cp_raw_cons
);
1898 prefetch(&cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)]);
1900 if (!bnxt_has_work(bp
, cpr
)) {
1901 int_status
= readl(bp
->bar0
+ BNXT_CAG_REG_LEGACY_INT_STATUS
);
1902 /* return if erroneous interrupt */
1903 if (!(int_status
& (0x10000 << cpr
->cp_ring_struct
.fw_ring_id
)))
1907 /* disable ring IRQ */
1908 BNXT_CP_DB_IRQ_DIS(cpr
->cp_db
.doorbell
);
1910 /* Return here if interrupt is shared and is disabled. */
1911 if (unlikely(atomic_read(&bp
->intr_sem
) != 0))
1914 napi_schedule(&bnapi
->napi
);
1918 static int __bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
1921 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
1922 u32 raw_cons
= cpr
->cp_raw_cons
;
1927 struct tx_cmp
*txcmp
;
1929 cpr
->has_more_work
= 0;
1933 cons
= RING_CMP(raw_cons
);
1934 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
1936 if (!TX_CMP_VALID(txcmp
, raw_cons
))
1939 /* The valid test of the entry must be done first before
1940 * reading any further.
1943 cpr
->had_work_done
= 1;
1944 if (TX_CMP_TYPE(txcmp
) == CMP_TYPE_TX_L2_CMP
) {
1946 /* return full budget so NAPI will complete. */
1947 if (unlikely(tx_pkts
> bp
->tx_wake_thresh
)) {
1949 raw_cons
= NEXT_RAW_CMP(raw_cons
);
1951 cpr
->has_more_work
= 1;
1954 } else if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
1956 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
1958 rc
= bnxt_force_rx_discard(bp
, cpr
, &raw_cons
,
1960 if (likely(rc
>= 0))
1962 /* Increment rx_pkts when rc is -ENOMEM to count towards
1963 * the NAPI budget. Otherwise, we may potentially loop
1964 * here forever if we consistently cannot allocate
1967 else if (rc
== -ENOMEM
&& budget
)
1969 else if (rc
== -EBUSY
) /* partial completion */
1971 } else if (unlikely((TX_CMP_TYPE(txcmp
) ==
1972 CMPL_BASE_TYPE_HWRM_DONE
) ||
1973 (TX_CMP_TYPE(txcmp
) ==
1974 CMPL_BASE_TYPE_HWRM_FWD_REQ
) ||
1975 (TX_CMP_TYPE(txcmp
) ==
1976 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT
))) {
1977 bnxt_hwrm_handler(bp
, txcmp
);
1979 raw_cons
= NEXT_RAW_CMP(raw_cons
);
1981 if (rx_pkts
&& rx_pkts
== budget
) {
1982 cpr
->has_more_work
= 1;
1987 if (event
& BNXT_TX_EVENT
) {
1988 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
1989 u16 prod
= txr
->tx_prod
;
1991 /* Sync BD data before updating doorbell */
1994 bnxt_db_write_relaxed(bp
, &txr
->tx_db
, prod
);
1997 cpr
->cp_raw_cons
= raw_cons
;
1998 bnapi
->tx_pkts
+= tx_pkts
;
1999 bnapi
->events
|= event
;
2003 static void __bnxt_poll_work_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
2005 if (bnapi
->tx_pkts
) {
2006 bnapi
->tx_int(bp
, bnapi
, bnapi
->tx_pkts
);
2010 if (bnapi
->events
& BNXT_RX_EVENT
) {
2011 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2013 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2014 if (bnapi
->events
& BNXT_AGG_EVENT
)
2015 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2020 static int bnxt_poll_work(struct bnxt
*bp
, struct bnxt_cp_ring_info
*cpr
,
2023 struct bnxt_napi
*bnapi
= cpr
->bnapi
;
2026 rx_pkts
= __bnxt_poll_work(bp
, cpr
, budget
);
2028 /* ACK completion ring before freeing tx ring and producing new
2029 * buffers in rx/agg rings to prevent overflowing the completion
2032 bnxt_db_cq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
2034 __bnxt_poll_work_done(bp
, bnapi
);
2038 static int bnxt_poll_nitroa0(struct napi_struct
*napi
, int budget
)
2040 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2041 struct bnxt
*bp
= bnapi
->bp
;
2042 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2043 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
2044 struct tx_cmp
*txcmp
;
2045 struct rx_cmp_ext
*rxcmp1
;
2046 u32 cp_cons
, tmp_raw_cons
;
2047 u32 raw_cons
= cpr
->cp_raw_cons
;
2054 cp_cons
= RING_CMP(raw_cons
);
2055 txcmp
= &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2057 if (!TX_CMP_VALID(txcmp
, raw_cons
))
2060 if ((TX_CMP_TYPE(txcmp
) & 0x30) == 0x10) {
2061 tmp_raw_cons
= NEXT_RAW_CMP(raw_cons
);
2062 cp_cons
= RING_CMP(tmp_raw_cons
);
2063 rxcmp1
= (struct rx_cmp_ext
*)
2064 &cpr
->cp_desc_ring
[CP_RING(cp_cons
)][CP_IDX(cp_cons
)];
2066 if (!RX_CMP_VALID(rxcmp1
, tmp_raw_cons
))
2069 /* force an error to recycle the buffer */
2070 rxcmp1
->rx_cmp_cfa_code_errors_v2
|=
2071 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR
);
2073 rc
= bnxt_rx_pkt(bp
, cpr
, &raw_cons
, &event
);
2074 if (likely(rc
== -EIO
) && budget
)
2076 else if (rc
== -EBUSY
) /* partial completion */
2078 } else if (unlikely(TX_CMP_TYPE(txcmp
) ==
2079 CMPL_BASE_TYPE_HWRM_DONE
)) {
2080 bnxt_hwrm_handler(bp
, txcmp
);
2083 "Invalid completion received on special ring\n");
2085 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2087 if (rx_pkts
== budget
)
2091 cpr
->cp_raw_cons
= raw_cons
;
2092 BNXT_DB_CQ(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2093 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
2095 if (event
& BNXT_AGG_EVENT
)
2096 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
2098 if (!bnxt_has_work(bp
, cpr
) && rx_pkts
< budget
) {
2099 napi_complete_done(napi
, rx_pkts
);
2100 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2105 static int bnxt_poll(struct napi_struct
*napi
, int budget
)
2107 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2108 struct bnxt
*bp
= bnapi
->bp
;
2109 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2113 work_done
+= bnxt_poll_work(bp
, cpr
, budget
- work_done
);
2115 if (work_done
>= budget
) {
2117 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2121 if (!bnxt_has_work(bp
, cpr
)) {
2122 if (napi_complete_done(napi
, work_done
))
2123 BNXT_DB_CQ_ARM(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2127 if (bp
->flags
& BNXT_FLAG_DIM
) {
2128 struct net_dim_sample dim_sample
;
2130 net_dim_sample(cpr
->event_ctr
,
2134 net_dim(&cpr
->dim
, dim_sample
);
2140 static int __bnxt_poll_cqs(struct bnxt
*bp
, struct bnxt_napi
*bnapi
, int budget
)
2142 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2143 int i
, work_done
= 0;
2145 for (i
= 0; i
< 2; i
++) {
2146 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2149 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2150 budget
- work_done
);
2151 cpr
->has_more_work
|= cpr2
->has_more_work
;
2157 static void __bnxt_poll_cqs_done(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
2158 u64 dbr_type
, bool all
)
2160 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2163 for (i
= 0; i
< 2; i
++) {
2164 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[i
];
2165 struct bnxt_db_info
*db
;
2167 if (cpr2
&& (all
|| cpr2
->had_work_done
)) {
2169 writeq(db
->db_key64
| dbr_type
|
2170 RING_CMP(cpr2
->cp_raw_cons
), db
->doorbell
);
2171 cpr2
->had_work_done
= 0;
2174 __bnxt_poll_work_done(bp
, bnapi
);
2177 static int bnxt_poll_p5(struct napi_struct
*napi
, int budget
)
2179 struct bnxt_napi
*bnapi
= container_of(napi
, struct bnxt_napi
, napi
);
2180 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
2181 u32 raw_cons
= cpr
->cp_raw_cons
;
2182 struct bnxt
*bp
= bnapi
->bp
;
2183 struct nqe_cn
*nqcmp
;
2187 if (cpr
->has_more_work
) {
2188 cpr
->has_more_work
= 0;
2189 work_done
= __bnxt_poll_cqs(bp
, bnapi
, budget
);
2190 if (cpr
->has_more_work
) {
2191 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ
, false);
2194 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ_ARMALL
, true);
2195 if (napi_complete_done(napi
, work_done
))
2196 BNXT_DB_NQ_ARM_P5(&cpr
->cp_db
, cpr
->cp_raw_cons
);
2200 cons
= RING_CMP(raw_cons
);
2201 nqcmp
= &cpr
->nq_desc_ring
[CP_RING(cons
)][CP_IDX(cons
)];
2203 if (!NQ_CMP_VALID(nqcmp
, raw_cons
)) {
2204 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ_ARMALL
,
2206 cpr
->cp_raw_cons
= raw_cons
;
2207 if (napi_complete_done(napi
, work_done
))
2208 BNXT_DB_NQ_ARM_P5(&cpr
->cp_db
,
2213 /* The valid test of the entry must be done first before
2214 * reading any further.
2218 if (nqcmp
->type
== cpu_to_le16(NQ_CN_TYPE_CQ_NOTIFICATION
)) {
2219 u32 idx
= le32_to_cpu(nqcmp
->cq_handle_low
);
2220 struct bnxt_cp_ring_info
*cpr2
;
2222 cpr2
= cpr
->cp_ring_arr
[idx
];
2223 work_done
+= __bnxt_poll_work(bp
, cpr2
,
2224 budget
- work_done
);
2225 cpr
->has_more_work
= cpr2
->has_more_work
;
2227 bnxt_hwrm_handler(bp
, (struct tx_cmp
*)nqcmp
);
2229 raw_cons
= NEXT_RAW_CMP(raw_cons
);
2230 if (cpr
->has_more_work
)
2233 __bnxt_poll_cqs_done(bp
, bnapi
, DBR_TYPE_CQ
, true);
2234 cpr
->cp_raw_cons
= raw_cons
;
2238 static void bnxt_free_tx_skbs(struct bnxt
*bp
)
2241 struct pci_dev
*pdev
= bp
->pdev
;
2246 max_idx
= bp
->tx_nr_pages
* TX_DESC_CNT
;
2247 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2248 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2251 for (j
= 0; j
< max_idx
;) {
2252 struct bnxt_sw_tx_bd
*tx_buf
= &txr
->tx_buf_ring
[j
];
2253 struct sk_buff
*skb
= tx_buf
->skb
;
2263 if (tx_buf
->is_push
) {
2269 dma_unmap_single(&pdev
->dev
,
2270 dma_unmap_addr(tx_buf
, mapping
),
2274 last
= tx_buf
->nr_frags
;
2276 for (k
= 0; k
< last
; k
++, j
++) {
2277 int ring_idx
= j
& bp
->tx_ring_mask
;
2278 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[k
];
2280 tx_buf
= &txr
->tx_buf_ring
[ring_idx
];
2283 dma_unmap_addr(tx_buf
, mapping
),
2284 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
2288 netdev_tx_reset_queue(netdev_get_tx_queue(bp
->dev
, i
));
2292 static void bnxt_free_rx_skbs(struct bnxt
*bp
)
2294 int i
, max_idx
, max_agg_idx
;
2295 struct pci_dev
*pdev
= bp
->pdev
;
2300 max_idx
= bp
->rx_nr_pages
* RX_DESC_CNT
;
2301 max_agg_idx
= bp
->rx_agg_nr_pages
* RX_DESC_CNT
;
2302 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2303 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2307 for (j
= 0; j
< MAX_TPA
; j
++) {
2308 struct bnxt_tpa_info
*tpa_info
=
2310 u8
*data
= tpa_info
->data
;
2315 dma_unmap_single_attrs(&pdev
->dev
,
2317 bp
->rx_buf_use_size
,
2319 DMA_ATTR_WEAK_ORDERING
);
2321 tpa_info
->data
= NULL
;
2327 for (j
= 0; j
< max_idx
; j
++) {
2328 struct bnxt_sw_rx_bd
*rx_buf
= &rxr
->rx_buf_ring
[j
];
2329 dma_addr_t mapping
= rx_buf
->mapping
;
2330 void *data
= rx_buf
->data
;
2335 rx_buf
->data
= NULL
;
2337 if (BNXT_RX_PAGE_MODE(bp
)) {
2338 mapping
-= bp
->rx_dma_offset
;
2339 dma_unmap_page_attrs(&pdev
->dev
, mapping
,
2340 PAGE_SIZE
, bp
->rx_dir
,
2341 DMA_ATTR_WEAK_ORDERING
);
2344 dma_unmap_single_attrs(&pdev
->dev
, mapping
,
2345 bp
->rx_buf_use_size
,
2347 DMA_ATTR_WEAK_ORDERING
);
2352 for (j
= 0; j
< max_agg_idx
; j
++) {
2353 struct bnxt_sw_rx_agg_bd
*rx_agg_buf
=
2354 &rxr
->rx_agg_ring
[j
];
2355 struct page
*page
= rx_agg_buf
->page
;
2360 dma_unmap_page_attrs(&pdev
->dev
, rx_agg_buf
->mapping
,
2363 DMA_ATTR_WEAK_ORDERING
);
2365 rx_agg_buf
->page
= NULL
;
2366 __clear_bit(j
, rxr
->rx_agg_bmap
);
2371 __free_page(rxr
->rx_page
);
2372 rxr
->rx_page
= NULL
;
2377 static void bnxt_free_skbs(struct bnxt
*bp
)
2379 bnxt_free_tx_skbs(bp
);
2380 bnxt_free_rx_skbs(bp
);
2383 static void bnxt_free_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2385 struct pci_dev
*pdev
= bp
->pdev
;
2388 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2389 if (!rmem
->pg_arr
[i
])
2392 dma_free_coherent(&pdev
->dev
, rmem
->page_size
,
2393 rmem
->pg_arr
[i
], rmem
->dma_arr
[i
]);
2395 rmem
->pg_arr
[i
] = NULL
;
2398 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2400 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2401 pg_tbl_size
= rmem
->page_size
;
2402 dma_free_coherent(&pdev
->dev
, pg_tbl_size
,
2403 rmem
->pg_tbl
, rmem
->pg_tbl_map
);
2404 rmem
->pg_tbl
= NULL
;
2406 if (rmem
->vmem_size
&& *rmem
->vmem
) {
2412 static int bnxt_alloc_ring(struct bnxt
*bp
, struct bnxt_ring_mem_info
*rmem
)
2414 struct pci_dev
*pdev
= bp
->pdev
;
2418 if (rmem
->flags
& (BNXT_RMEM_VALID_PTE_FLAG
| BNXT_RMEM_RING_PTE_FLAG
))
2419 valid_bit
= PTU_PTE_VALID
;
2420 if ((rmem
->nr_pages
> 1 || rmem
->depth
> 0) && !rmem
->pg_tbl
) {
2421 size_t pg_tbl_size
= rmem
->nr_pages
* 8;
2423 if (rmem
->flags
& BNXT_RMEM_USE_FULL_PAGE_FLAG
)
2424 pg_tbl_size
= rmem
->page_size
;
2425 rmem
->pg_tbl
= dma_alloc_coherent(&pdev
->dev
, pg_tbl_size
,
2432 for (i
= 0; i
< rmem
->nr_pages
; i
++) {
2433 u64 extra_bits
= valid_bit
;
2435 rmem
->pg_arr
[i
] = dma_alloc_coherent(&pdev
->dev
,
2439 if (!rmem
->pg_arr
[i
])
2442 if (rmem
->nr_pages
> 1 || rmem
->depth
> 0) {
2443 if (i
== rmem
->nr_pages
- 2 &&
2444 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2445 extra_bits
|= PTU_PTE_NEXT_TO_LAST
;
2446 else if (i
== rmem
->nr_pages
- 1 &&
2447 (rmem
->flags
& BNXT_RMEM_RING_PTE_FLAG
))
2448 extra_bits
|= PTU_PTE_LAST
;
2450 cpu_to_le64(rmem
->dma_arr
[i
] | extra_bits
);
2454 if (rmem
->vmem_size
) {
2455 *rmem
->vmem
= vzalloc(rmem
->vmem_size
);
2462 static void bnxt_free_rx_rings(struct bnxt
*bp
)
2469 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2470 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2471 struct bnxt_ring_struct
*ring
;
2474 bpf_prog_put(rxr
->xdp_prog
);
2476 if (xdp_rxq_info_is_reg(&rxr
->xdp_rxq
))
2477 xdp_rxq_info_unreg(&rxr
->xdp_rxq
);
2482 kfree(rxr
->rx_agg_bmap
);
2483 rxr
->rx_agg_bmap
= NULL
;
2485 ring
= &rxr
->rx_ring_struct
;
2486 bnxt_free_ring(bp
, &ring
->ring_mem
);
2488 ring
= &rxr
->rx_agg_ring_struct
;
2489 bnxt_free_ring(bp
, &ring
->ring_mem
);
2493 static int bnxt_alloc_rx_rings(struct bnxt
*bp
)
2495 int i
, rc
, agg_rings
= 0, tpa_rings
= 0;
2500 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
2503 if (bp
->flags
& BNXT_FLAG_TPA
)
2506 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2507 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
2508 struct bnxt_ring_struct
*ring
;
2510 ring
= &rxr
->rx_ring_struct
;
2512 rc
= xdp_rxq_info_reg(&rxr
->xdp_rxq
, bp
->dev
, i
);
2516 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2524 ring
= &rxr
->rx_agg_ring_struct
;
2525 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2530 rxr
->rx_agg_bmap_size
= bp
->rx_agg_ring_mask
+ 1;
2531 mem_size
= rxr
->rx_agg_bmap_size
/ 8;
2532 rxr
->rx_agg_bmap
= kzalloc(mem_size
, GFP_KERNEL
);
2533 if (!rxr
->rx_agg_bmap
)
2537 rxr
->rx_tpa
= kcalloc(MAX_TPA
,
2538 sizeof(struct bnxt_tpa_info
),
2548 static void bnxt_free_tx_rings(struct bnxt
*bp
)
2551 struct pci_dev
*pdev
= bp
->pdev
;
2556 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2557 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2558 struct bnxt_ring_struct
*ring
;
2561 dma_free_coherent(&pdev
->dev
, bp
->tx_push_size
,
2562 txr
->tx_push
, txr
->tx_push_mapping
);
2563 txr
->tx_push
= NULL
;
2566 ring
= &txr
->tx_ring_struct
;
2568 bnxt_free_ring(bp
, &ring
->ring_mem
);
2572 static int bnxt_alloc_tx_rings(struct bnxt
*bp
)
2575 struct pci_dev
*pdev
= bp
->pdev
;
2577 bp
->tx_push_size
= 0;
2578 if (bp
->tx_push_thresh
) {
2581 push_size
= L1_CACHE_ALIGN(sizeof(struct tx_push_bd
) +
2582 bp
->tx_push_thresh
);
2584 if (push_size
> 256) {
2586 bp
->tx_push_thresh
= 0;
2589 bp
->tx_push_size
= push_size
;
2592 for (i
= 0, j
= 0; i
< bp
->tx_nr_rings
; i
++) {
2593 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2594 struct bnxt_ring_struct
*ring
;
2597 ring
= &txr
->tx_ring_struct
;
2599 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2603 ring
->grp_idx
= txr
->bnapi
->index
;
2604 if (bp
->tx_push_size
) {
2607 /* One pre-allocated DMA buffer to backup
2610 txr
->tx_push
= dma_alloc_coherent(&pdev
->dev
,
2612 &txr
->tx_push_mapping
,
2618 mapping
= txr
->tx_push_mapping
+
2619 sizeof(struct tx_push_bd
);
2620 txr
->data_mapping
= cpu_to_le64(mapping
);
2622 memset(txr
->tx_push
, 0, sizeof(struct tx_push_bd
));
2624 qidx
= bp
->tc_to_qidx
[j
];
2625 ring
->queue_id
= bp
->q_info
[qidx
].queue_id
;
2626 if (i
< bp
->tx_nr_rings_xdp
)
2628 if (i
% bp
->tx_nr_rings_per_tc
== (bp
->tx_nr_rings_per_tc
- 1))
2634 static void bnxt_free_cp_rings(struct bnxt
*bp
)
2641 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2642 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2643 struct bnxt_cp_ring_info
*cpr
;
2644 struct bnxt_ring_struct
*ring
;
2650 cpr
= &bnapi
->cp_ring
;
2651 ring
= &cpr
->cp_ring_struct
;
2653 bnxt_free_ring(bp
, &ring
->ring_mem
);
2655 for (j
= 0; j
< 2; j
++) {
2656 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
2659 ring
= &cpr2
->cp_ring_struct
;
2660 bnxt_free_ring(bp
, &ring
->ring_mem
);
2662 cpr
->cp_ring_arr
[j
] = NULL
;
2668 static struct bnxt_cp_ring_info
*bnxt_alloc_cp_sub_ring(struct bnxt
*bp
)
2670 struct bnxt_ring_mem_info
*rmem
;
2671 struct bnxt_ring_struct
*ring
;
2672 struct bnxt_cp_ring_info
*cpr
;
2675 cpr
= kzalloc(sizeof(*cpr
), GFP_KERNEL
);
2679 ring
= &cpr
->cp_ring_struct
;
2680 rmem
= &ring
->ring_mem
;
2681 rmem
->nr_pages
= bp
->cp_nr_pages
;
2682 rmem
->page_size
= HW_CMPD_RING_SIZE
;
2683 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
2684 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
2685 rmem
->flags
= BNXT_RMEM_RING_PTE_FLAG
;
2686 rc
= bnxt_alloc_ring(bp
, rmem
);
2688 bnxt_free_ring(bp
, rmem
);
2695 static int bnxt_alloc_cp_rings(struct bnxt
*bp
)
2697 bool sh
= !!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
);
2698 int i
, rc
, ulp_base_vec
, ulp_msix
;
2700 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
2701 ulp_base_vec
= bnxt_get_ulp_msix_base(bp
);
2702 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2703 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2704 struct bnxt_cp_ring_info
*cpr
;
2705 struct bnxt_ring_struct
*ring
;
2710 cpr
= &bnapi
->cp_ring
;
2712 ring
= &cpr
->cp_ring_struct
;
2714 rc
= bnxt_alloc_ring(bp
, &ring
->ring_mem
);
2718 if (ulp_msix
&& i
>= ulp_base_vec
)
2719 ring
->map_idx
= i
+ ulp_msix
;
2723 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
2726 if (i
< bp
->rx_nr_rings
) {
2727 struct bnxt_cp_ring_info
*cpr2
=
2728 bnxt_alloc_cp_sub_ring(bp
);
2730 cpr
->cp_ring_arr
[BNXT_RX_HDL
] = cpr2
;
2733 cpr2
->bnapi
= bnapi
;
2735 if ((sh
&& i
< bp
->tx_nr_rings
) ||
2736 (!sh
&& i
>= bp
->rx_nr_rings
)) {
2737 struct bnxt_cp_ring_info
*cpr2
=
2738 bnxt_alloc_cp_sub_ring(bp
);
2740 cpr
->cp_ring_arr
[BNXT_TX_HDL
] = cpr2
;
2743 cpr2
->bnapi
= bnapi
;
2749 static void bnxt_init_ring_struct(struct bnxt
*bp
)
2753 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2754 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
2755 struct bnxt_ring_mem_info
*rmem
;
2756 struct bnxt_cp_ring_info
*cpr
;
2757 struct bnxt_rx_ring_info
*rxr
;
2758 struct bnxt_tx_ring_info
*txr
;
2759 struct bnxt_ring_struct
*ring
;
2764 cpr
= &bnapi
->cp_ring
;
2765 ring
= &cpr
->cp_ring_struct
;
2766 rmem
= &ring
->ring_mem
;
2767 rmem
->nr_pages
= bp
->cp_nr_pages
;
2768 rmem
->page_size
= HW_CMPD_RING_SIZE
;
2769 rmem
->pg_arr
= (void **)cpr
->cp_desc_ring
;
2770 rmem
->dma_arr
= cpr
->cp_desc_mapping
;
2771 rmem
->vmem_size
= 0;
2773 rxr
= bnapi
->rx_ring
;
2777 ring
= &rxr
->rx_ring_struct
;
2778 rmem
= &ring
->ring_mem
;
2779 rmem
->nr_pages
= bp
->rx_nr_pages
;
2780 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2781 rmem
->pg_arr
= (void **)rxr
->rx_desc_ring
;
2782 rmem
->dma_arr
= rxr
->rx_desc_mapping
;
2783 rmem
->vmem_size
= SW_RXBD_RING_SIZE
* bp
->rx_nr_pages
;
2784 rmem
->vmem
= (void **)&rxr
->rx_buf_ring
;
2786 ring
= &rxr
->rx_agg_ring_struct
;
2787 rmem
= &ring
->ring_mem
;
2788 rmem
->nr_pages
= bp
->rx_agg_nr_pages
;
2789 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2790 rmem
->pg_arr
= (void **)rxr
->rx_agg_desc_ring
;
2791 rmem
->dma_arr
= rxr
->rx_agg_desc_mapping
;
2792 rmem
->vmem_size
= SW_RXBD_AGG_RING_SIZE
* bp
->rx_agg_nr_pages
;
2793 rmem
->vmem
= (void **)&rxr
->rx_agg_ring
;
2796 txr
= bnapi
->tx_ring
;
2800 ring
= &txr
->tx_ring_struct
;
2801 rmem
= &ring
->ring_mem
;
2802 rmem
->nr_pages
= bp
->tx_nr_pages
;
2803 rmem
->page_size
= HW_RXBD_RING_SIZE
;
2804 rmem
->pg_arr
= (void **)txr
->tx_desc_ring
;
2805 rmem
->dma_arr
= txr
->tx_desc_mapping
;
2806 rmem
->vmem_size
= SW_TXBD_RING_SIZE
* bp
->tx_nr_pages
;
2807 rmem
->vmem
= (void **)&txr
->tx_buf_ring
;
2811 static void bnxt_init_rxbd_pages(struct bnxt_ring_struct
*ring
, u32 type
)
2815 struct rx_bd
**rx_buf_ring
;
2817 rx_buf_ring
= (struct rx_bd
**)ring
->ring_mem
.pg_arr
;
2818 for (i
= 0, prod
= 0; i
< ring
->ring_mem
.nr_pages
; i
++) {
2822 rxbd
= rx_buf_ring
[i
];
2826 for (j
= 0; j
< RX_DESC_CNT
; j
++, rxbd
++, prod
++) {
2827 rxbd
->rx_bd_len_flags_type
= cpu_to_le32(type
);
2828 rxbd
->rx_bd_opaque
= prod
;
2833 static int bnxt_init_one_rx_ring(struct bnxt
*bp
, int ring_nr
)
2835 struct net_device
*dev
= bp
->dev
;
2836 struct bnxt_rx_ring_info
*rxr
;
2837 struct bnxt_ring_struct
*ring
;
2841 type
= (bp
->rx_buf_use_size
<< RX_BD_LEN_SHIFT
) |
2842 RX_BD_TYPE_RX_PACKET_BD
| RX_BD_FLAGS_EOP
;
2844 if (NET_IP_ALIGN
== 2)
2845 type
|= RX_BD_FLAGS_SOP
;
2847 rxr
= &bp
->rx_ring
[ring_nr
];
2848 ring
= &rxr
->rx_ring_struct
;
2849 bnxt_init_rxbd_pages(ring
, type
);
2851 if (BNXT_RX_PAGE_MODE(bp
) && bp
->xdp_prog
) {
2852 rxr
->xdp_prog
= bpf_prog_add(bp
->xdp_prog
, 1);
2853 if (IS_ERR(rxr
->xdp_prog
)) {
2854 int rc
= PTR_ERR(rxr
->xdp_prog
);
2856 rxr
->xdp_prog
= NULL
;
2860 prod
= rxr
->rx_prod
;
2861 for (i
= 0; i
< bp
->rx_ring_size
; i
++) {
2862 if (bnxt_alloc_rx_data(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
2863 netdev_warn(dev
, "init'ed rx ring %d with %d/%d skbs only\n",
2864 ring_nr
, i
, bp
->rx_ring_size
);
2867 prod
= NEXT_RX(prod
);
2869 rxr
->rx_prod
= prod
;
2870 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2872 ring
= &rxr
->rx_agg_ring_struct
;
2873 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2875 if (!(bp
->flags
& BNXT_FLAG_AGG_RINGS
))
2878 type
= ((u32
)BNXT_RX_PAGE_SIZE
<< RX_BD_LEN_SHIFT
) |
2879 RX_BD_TYPE_RX_AGG_BD
| RX_BD_FLAGS_SOP
;
2881 bnxt_init_rxbd_pages(ring
, type
);
2883 prod
= rxr
->rx_agg_prod
;
2884 for (i
= 0; i
< bp
->rx_agg_ring_size
; i
++) {
2885 if (bnxt_alloc_rx_page(bp
, rxr
, prod
, GFP_KERNEL
) != 0) {
2886 netdev_warn(dev
, "init'ed rx ring %d with %d/%d pages only\n",
2887 ring_nr
, i
, bp
->rx_ring_size
);
2890 prod
= NEXT_RX_AGG(prod
);
2892 rxr
->rx_agg_prod
= prod
;
2894 if (bp
->flags
& BNXT_FLAG_TPA
) {
2899 for (i
= 0; i
< MAX_TPA
; i
++) {
2900 data
= __bnxt_alloc_rx_data(bp
, &mapping
,
2905 rxr
->rx_tpa
[i
].data
= data
;
2906 rxr
->rx_tpa
[i
].data_ptr
= data
+ bp
->rx_offset
;
2907 rxr
->rx_tpa
[i
].mapping
= mapping
;
2910 netdev_err(bp
->dev
, "No resource allocated for LRO/GRO\n");
2918 static void bnxt_init_cp_rings(struct bnxt
*bp
)
2922 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
2923 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
2924 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
2926 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2927 cpr
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
2928 cpr
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
2929 for (j
= 0; j
< 2; j
++) {
2930 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
2935 ring
= &cpr2
->cp_ring_struct
;
2936 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2937 cpr2
->rx_ring_coal
.coal_ticks
= bp
->rx_coal
.coal_ticks
;
2938 cpr2
->rx_ring_coal
.coal_bufs
= bp
->rx_coal
.coal_bufs
;
2943 static int bnxt_init_rx_rings(struct bnxt
*bp
)
2947 if (BNXT_RX_PAGE_MODE(bp
)) {
2948 bp
->rx_offset
= NET_IP_ALIGN
+ XDP_PACKET_HEADROOM
;
2949 bp
->rx_dma_offset
= XDP_PACKET_HEADROOM
;
2951 bp
->rx_offset
= BNXT_RX_OFFSET
;
2952 bp
->rx_dma_offset
= BNXT_RX_DMA_OFFSET
;
2955 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
2956 rc
= bnxt_init_one_rx_ring(bp
, i
);
2964 static int bnxt_init_tx_rings(struct bnxt
*bp
)
2968 bp
->tx_wake_thresh
= max_t(int, bp
->tx_ring_size
/ 2,
2971 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
2972 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
2973 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
2975 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
2981 static void bnxt_free_ring_grps(struct bnxt
*bp
)
2983 kfree(bp
->grp_info
);
2984 bp
->grp_info
= NULL
;
2987 static int bnxt_init_ring_grps(struct bnxt
*bp
, bool irq_re_init
)
2992 bp
->grp_info
= kcalloc(bp
->cp_nr_rings
,
2993 sizeof(struct bnxt_ring_grp_info
),
2998 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3000 bp
->grp_info
[i
].fw_stats_ctx
= INVALID_HW_RING_ID
;
3001 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
3002 bp
->grp_info
[i
].rx_fw_ring_id
= INVALID_HW_RING_ID
;
3003 bp
->grp_info
[i
].agg_fw_ring_id
= INVALID_HW_RING_ID
;
3004 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
3009 static void bnxt_free_vnics(struct bnxt
*bp
)
3011 kfree(bp
->vnic_info
);
3012 bp
->vnic_info
= NULL
;
3016 static int bnxt_alloc_vnics(struct bnxt
*bp
)
3020 #ifdef CONFIG_RFS_ACCEL
3021 if (bp
->flags
& BNXT_FLAG_RFS
)
3022 num_vnics
+= bp
->rx_nr_rings
;
3025 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
3028 bp
->vnic_info
= kcalloc(num_vnics
, sizeof(struct bnxt_vnic_info
),
3033 bp
->nr_vnics
= num_vnics
;
3037 static void bnxt_init_vnics(struct bnxt
*bp
)
3041 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3042 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
3045 vnic
->fw_vnic_id
= INVALID_HW_RING_ID
;
3046 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++)
3047 vnic
->fw_rss_cos_lb_ctx
[j
] = INVALID_HW_RING_ID
;
3049 vnic
->fw_l2_ctx_id
= INVALID_HW_RING_ID
;
3051 if (bp
->vnic_info
[i
].rss_hash_key
) {
3053 prandom_bytes(vnic
->rss_hash_key
,
3056 memcpy(vnic
->rss_hash_key
,
3057 bp
->vnic_info
[0].rss_hash_key
,
3063 static int bnxt_calc_nr_ring_pages(u32 ring_size
, int desc_per_pg
)
3067 pages
= ring_size
/ desc_per_pg
;
3074 while (pages
& (pages
- 1))
3080 void bnxt_set_tpa_flags(struct bnxt
*bp
)
3082 bp
->flags
&= ~BNXT_FLAG_TPA
;
3083 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
3085 if (bp
->dev
->features
& NETIF_F_LRO
)
3086 bp
->flags
|= BNXT_FLAG_LRO
;
3087 else if (bp
->dev
->features
& NETIF_F_GRO_HW
)
3088 bp
->flags
|= BNXT_FLAG_GRO
;
3091 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
3094 void bnxt_set_ring_params(struct bnxt
*bp
)
3096 u32 ring_size
, rx_size
, rx_space
;
3097 u32 agg_factor
= 0, agg_ring_size
= 0;
3099 /* 8 for CRC and VLAN */
3100 rx_size
= SKB_DATA_ALIGN(bp
->dev
->mtu
+ ETH_HLEN
+ NET_IP_ALIGN
+ 8);
3102 rx_space
= rx_size
+ NET_SKB_PAD
+
3103 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3105 bp
->rx_copy_thresh
= BNXT_RX_COPY_THRESH
;
3106 ring_size
= bp
->rx_ring_size
;
3107 bp
->rx_agg_ring_size
= 0;
3108 bp
->rx_agg_nr_pages
= 0;
3110 if (bp
->flags
& BNXT_FLAG_TPA
)
3111 agg_factor
= min_t(u32
, 4, 65536 / BNXT_RX_PAGE_SIZE
);
3113 bp
->flags
&= ~BNXT_FLAG_JUMBO
;
3114 if (rx_space
> PAGE_SIZE
&& !(bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)) {
3117 bp
->flags
|= BNXT_FLAG_JUMBO
;
3118 jumbo_factor
= PAGE_ALIGN(bp
->dev
->mtu
- 40) >> PAGE_SHIFT
;
3119 if (jumbo_factor
> agg_factor
)
3120 agg_factor
= jumbo_factor
;
3122 agg_ring_size
= ring_size
* agg_factor
;
3124 if (agg_ring_size
) {
3125 bp
->rx_agg_nr_pages
= bnxt_calc_nr_ring_pages(agg_ring_size
,
3127 if (bp
->rx_agg_nr_pages
> MAX_RX_AGG_PAGES
) {
3128 u32 tmp
= agg_ring_size
;
3130 bp
->rx_agg_nr_pages
= MAX_RX_AGG_PAGES
;
3131 agg_ring_size
= MAX_RX_AGG_PAGES
* RX_DESC_CNT
- 1;
3132 netdev_warn(bp
->dev
, "rx agg ring size %d reduced to %d.\n",
3133 tmp
, agg_ring_size
);
3135 bp
->rx_agg_ring_size
= agg_ring_size
;
3136 bp
->rx_agg_ring_mask
= (bp
->rx_agg_nr_pages
* RX_DESC_CNT
) - 1;
3137 rx_size
= SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH
+ NET_IP_ALIGN
);
3138 rx_space
= rx_size
+ NET_SKB_PAD
+
3139 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
3142 bp
->rx_buf_use_size
= rx_size
;
3143 bp
->rx_buf_size
= rx_space
;
3145 bp
->rx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, RX_DESC_CNT
);
3146 bp
->rx_ring_mask
= (bp
->rx_nr_pages
* RX_DESC_CNT
) - 1;
3148 ring_size
= bp
->tx_ring_size
;
3149 bp
->tx_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, TX_DESC_CNT
);
3150 bp
->tx_ring_mask
= (bp
->tx_nr_pages
* TX_DESC_CNT
) - 1;
3152 ring_size
= bp
->rx_ring_size
* (2 + agg_factor
) + bp
->tx_ring_size
;
3153 bp
->cp_ring_size
= ring_size
;
3155 bp
->cp_nr_pages
= bnxt_calc_nr_ring_pages(ring_size
, CP_DESC_CNT
);
3156 if (bp
->cp_nr_pages
> MAX_CP_PAGES
) {
3157 bp
->cp_nr_pages
= MAX_CP_PAGES
;
3158 bp
->cp_ring_size
= MAX_CP_PAGES
* CP_DESC_CNT
- 1;
3159 netdev_warn(bp
->dev
, "completion ring size %d reduced to %d.\n",
3160 ring_size
, bp
->cp_ring_size
);
3162 bp
->cp_bit
= bp
->cp_nr_pages
* CP_DESC_CNT
;
3163 bp
->cp_ring_mask
= bp
->cp_bit
- 1;
3166 /* Changing allocation mode of RX rings.
3167 * TODO: Update when extending xdp_rxq_info to support allocation modes.
3169 int bnxt_set_rx_skb_mode(struct bnxt
*bp
, bool page_mode
)
3172 if (bp
->dev
->mtu
> BNXT_MAX_PAGE_MODE_MTU
)
3175 min_t(u16
, bp
->max_mtu
, BNXT_MAX_PAGE_MODE_MTU
);
3176 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
3177 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
| BNXT_FLAG_RX_PAGE_MODE
;
3178 bp
->rx_dir
= DMA_BIDIRECTIONAL
;
3179 bp
->rx_skb_func
= bnxt_rx_page_skb
;
3180 /* Disable LRO or GRO_HW */
3181 netdev_update_features(bp
->dev
);
3183 bp
->dev
->max_mtu
= bp
->max_mtu
;
3184 bp
->flags
&= ~BNXT_FLAG_RX_PAGE_MODE
;
3185 bp
->rx_dir
= DMA_FROM_DEVICE
;
3186 bp
->rx_skb_func
= bnxt_rx_skb
;
3191 static void bnxt_free_vnic_attributes(struct bnxt
*bp
)
3194 struct bnxt_vnic_info
*vnic
;
3195 struct pci_dev
*pdev
= bp
->pdev
;
3200 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3201 vnic
= &bp
->vnic_info
[i
];
3203 kfree(vnic
->fw_grp_ids
);
3204 vnic
->fw_grp_ids
= NULL
;
3206 kfree(vnic
->uc_list
);
3207 vnic
->uc_list
= NULL
;
3209 if (vnic
->mc_list
) {
3210 dma_free_coherent(&pdev
->dev
, vnic
->mc_list_size
,
3211 vnic
->mc_list
, vnic
->mc_list_mapping
);
3212 vnic
->mc_list
= NULL
;
3215 if (vnic
->rss_table
) {
3216 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
3218 vnic
->rss_table_dma_addr
);
3219 vnic
->rss_table
= NULL
;
3222 vnic
->rss_hash_key
= NULL
;
3227 static int bnxt_alloc_vnic_attributes(struct bnxt
*bp
)
3229 int i
, rc
= 0, size
;
3230 struct bnxt_vnic_info
*vnic
;
3231 struct pci_dev
*pdev
= bp
->pdev
;
3234 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
3235 vnic
= &bp
->vnic_info
[i
];
3237 if (vnic
->flags
& BNXT_VNIC_UCAST_FLAG
) {
3238 int mem_size
= (BNXT_MAX_UC_ADDRS
- 1) * ETH_ALEN
;
3241 vnic
->uc_list
= kmalloc(mem_size
, GFP_KERNEL
);
3242 if (!vnic
->uc_list
) {
3249 if (vnic
->flags
& BNXT_VNIC_MCAST_FLAG
) {
3250 vnic
->mc_list_size
= BNXT_MAX_MC_ADDRS
* ETH_ALEN
;
3252 dma_alloc_coherent(&pdev
->dev
,
3254 &vnic
->mc_list_mapping
,
3256 if (!vnic
->mc_list
) {
3262 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
3263 goto vnic_skip_grps
;
3265 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
3266 max_rings
= bp
->rx_nr_rings
;
3270 vnic
->fw_grp_ids
= kcalloc(max_rings
, sizeof(u16
), GFP_KERNEL
);
3271 if (!vnic
->fw_grp_ids
) {
3276 if ((bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
3277 !(vnic
->flags
& BNXT_VNIC_RSS_FLAG
))
3280 /* Allocate rss table and hash key */
3281 vnic
->rss_table
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3282 &vnic
->rss_table_dma_addr
,
3284 if (!vnic
->rss_table
) {
3289 size
= L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE
* sizeof(u16
));
3291 vnic
->rss_hash_key
= ((void *)vnic
->rss_table
) + size
;
3292 vnic
->rss_hash_key_dma_addr
= vnic
->rss_table_dma_addr
+ size
;
3300 static void bnxt_free_hwrm_resources(struct bnxt
*bp
)
3302 struct pci_dev
*pdev
= bp
->pdev
;
3304 if (bp
->hwrm_cmd_resp_addr
) {
3305 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
, bp
->hwrm_cmd_resp_addr
,
3306 bp
->hwrm_cmd_resp_dma_addr
);
3307 bp
->hwrm_cmd_resp_addr
= NULL
;
3310 if (bp
->hwrm_cmd_kong_resp_addr
) {
3311 dma_free_coherent(&pdev
->dev
, PAGE_SIZE
,
3312 bp
->hwrm_cmd_kong_resp_addr
,
3313 bp
->hwrm_cmd_kong_resp_dma_addr
);
3314 bp
->hwrm_cmd_kong_resp_addr
= NULL
;
3318 static int bnxt_alloc_kong_hwrm_resources(struct bnxt
*bp
)
3320 struct pci_dev
*pdev
= bp
->pdev
;
3322 bp
->hwrm_cmd_kong_resp_addr
=
3323 dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3324 &bp
->hwrm_cmd_kong_resp_dma_addr
,
3326 if (!bp
->hwrm_cmd_kong_resp_addr
)
3332 static int bnxt_alloc_hwrm_resources(struct bnxt
*bp
)
3334 struct pci_dev
*pdev
= bp
->pdev
;
3336 bp
->hwrm_cmd_resp_addr
= dma_alloc_coherent(&pdev
->dev
, PAGE_SIZE
,
3337 &bp
->hwrm_cmd_resp_dma_addr
,
3339 if (!bp
->hwrm_cmd_resp_addr
)
3345 static void bnxt_free_hwrm_short_cmd_req(struct bnxt
*bp
)
3347 if (bp
->hwrm_short_cmd_req_addr
) {
3348 struct pci_dev
*pdev
= bp
->pdev
;
3350 dma_free_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3351 bp
->hwrm_short_cmd_req_addr
,
3352 bp
->hwrm_short_cmd_req_dma_addr
);
3353 bp
->hwrm_short_cmd_req_addr
= NULL
;
3357 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt
*bp
)
3359 struct pci_dev
*pdev
= bp
->pdev
;
3361 bp
->hwrm_short_cmd_req_addr
=
3362 dma_alloc_coherent(&pdev
->dev
, bp
->hwrm_max_ext_req_len
,
3363 &bp
->hwrm_short_cmd_req_dma_addr
,
3365 if (!bp
->hwrm_short_cmd_req_addr
)
3371 static void bnxt_free_port_stats(struct bnxt
*bp
)
3373 struct pci_dev
*pdev
= bp
->pdev
;
3375 bp
->flags
&= ~BNXT_FLAG_PORT_STATS
;
3376 bp
->flags
&= ~BNXT_FLAG_PORT_STATS_EXT
;
3378 if (bp
->hw_rx_port_stats
) {
3379 dma_free_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3380 bp
->hw_rx_port_stats
,
3381 bp
->hw_rx_port_stats_map
);
3382 bp
->hw_rx_port_stats
= NULL
;
3385 if (bp
->hw_tx_port_stats_ext
) {
3386 dma_free_coherent(&pdev
->dev
, sizeof(struct tx_port_stats_ext
),
3387 bp
->hw_tx_port_stats_ext
,
3388 bp
->hw_tx_port_stats_ext_map
);
3389 bp
->hw_tx_port_stats_ext
= NULL
;
3392 if (bp
->hw_rx_port_stats_ext
) {
3393 dma_free_coherent(&pdev
->dev
, sizeof(struct rx_port_stats_ext
),
3394 bp
->hw_rx_port_stats_ext
,
3395 bp
->hw_rx_port_stats_ext_map
);
3396 bp
->hw_rx_port_stats_ext
= NULL
;
3400 static void bnxt_free_ring_stats(struct bnxt
*bp
)
3402 struct pci_dev
*pdev
= bp
->pdev
;
3408 size
= sizeof(struct ctx_hw_stats
);
3410 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3411 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3412 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3414 if (cpr
->hw_stats
) {
3415 dma_free_coherent(&pdev
->dev
, size
, cpr
->hw_stats
,
3417 cpr
->hw_stats
= NULL
;
3422 static int bnxt_alloc_stats(struct bnxt
*bp
)
3425 struct pci_dev
*pdev
= bp
->pdev
;
3427 size
= sizeof(struct ctx_hw_stats
);
3429 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3430 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3431 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3433 cpr
->hw_stats
= dma_alloc_coherent(&pdev
->dev
, size
,
3439 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
3442 if (BNXT_PF(bp
) && bp
->chip_num
!= CHIP_NUM_58700
) {
3443 if (bp
->hw_rx_port_stats
)
3444 goto alloc_ext_stats
;
3446 bp
->hw_port_stats_size
= sizeof(struct rx_port_stats
) +
3447 sizeof(struct tx_port_stats
) + 1024;
3449 bp
->hw_rx_port_stats
=
3450 dma_alloc_coherent(&pdev
->dev
, bp
->hw_port_stats_size
,
3451 &bp
->hw_rx_port_stats_map
,
3453 if (!bp
->hw_rx_port_stats
)
3456 bp
->hw_tx_port_stats
= (void *)(bp
->hw_rx_port_stats
+ 1) +
3458 bp
->hw_tx_port_stats_map
= bp
->hw_rx_port_stats_map
+
3459 sizeof(struct rx_port_stats
) + 512;
3460 bp
->flags
|= BNXT_FLAG_PORT_STATS
;
3463 /* Display extended statistics only if FW supports it */
3464 if (bp
->hwrm_spec_code
< 0x10804 ||
3465 bp
->hwrm_spec_code
== 0x10900)
3468 if (bp
->hw_rx_port_stats_ext
)
3469 goto alloc_tx_ext_stats
;
3471 bp
->hw_rx_port_stats_ext
=
3472 dma_alloc_coherent(&pdev
->dev
,
3473 sizeof(struct rx_port_stats_ext
),
3474 &bp
->hw_rx_port_stats_ext_map
,
3476 if (!bp
->hw_rx_port_stats_ext
)
3480 if (bp
->hw_tx_port_stats_ext
)
3483 if (bp
->hwrm_spec_code
>= 0x10902) {
3484 bp
->hw_tx_port_stats_ext
=
3485 dma_alloc_coherent(&pdev
->dev
,
3486 sizeof(struct tx_port_stats_ext
),
3487 &bp
->hw_tx_port_stats_ext_map
,
3490 bp
->flags
|= BNXT_FLAG_PORT_STATS_EXT
;
3495 static void bnxt_clear_ring_indices(struct bnxt
*bp
)
3502 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3503 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3504 struct bnxt_cp_ring_info
*cpr
;
3505 struct bnxt_rx_ring_info
*rxr
;
3506 struct bnxt_tx_ring_info
*txr
;
3511 cpr
= &bnapi
->cp_ring
;
3512 cpr
->cp_raw_cons
= 0;
3514 txr
= bnapi
->tx_ring
;
3520 rxr
= bnapi
->rx_ring
;
3523 rxr
->rx_agg_prod
= 0;
3524 rxr
->rx_sw_agg_prod
= 0;
3525 rxr
->rx_next_cons
= 0;
3530 static void bnxt_free_ntp_fltrs(struct bnxt
*bp
, bool irq_reinit
)
3532 #ifdef CONFIG_RFS_ACCEL
3535 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3536 * safe to delete the hash table.
3538 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
3539 struct hlist_head
*head
;
3540 struct hlist_node
*tmp
;
3541 struct bnxt_ntuple_filter
*fltr
;
3543 head
= &bp
->ntp_fltr_hash_tbl
[i
];
3544 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
3545 hlist_del(&fltr
->hash
);
3550 kfree(bp
->ntp_fltr_bmap
);
3551 bp
->ntp_fltr_bmap
= NULL
;
3553 bp
->ntp_fltr_count
= 0;
3557 static int bnxt_alloc_ntp_fltrs(struct bnxt
*bp
)
3559 #ifdef CONFIG_RFS_ACCEL
3562 if (!(bp
->flags
& BNXT_FLAG_RFS
))
3565 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++)
3566 INIT_HLIST_HEAD(&bp
->ntp_fltr_hash_tbl
[i
]);
3568 bp
->ntp_fltr_count
= 0;
3569 bp
->ntp_fltr_bmap
= kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR
),
3573 if (!bp
->ntp_fltr_bmap
)
3582 static void bnxt_free_mem(struct bnxt
*bp
, bool irq_re_init
)
3584 bnxt_free_vnic_attributes(bp
);
3585 bnxt_free_tx_rings(bp
);
3586 bnxt_free_rx_rings(bp
);
3587 bnxt_free_cp_rings(bp
);
3588 bnxt_free_ntp_fltrs(bp
, irq_re_init
);
3590 bnxt_free_ring_stats(bp
);
3591 bnxt_free_ring_grps(bp
);
3592 bnxt_free_vnics(bp
);
3593 kfree(bp
->tx_ring_map
);
3594 bp
->tx_ring_map
= NULL
;
3602 bnxt_clear_ring_indices(bp
);
3606 static int bnxt_alloc_mem(struct bnxt
*bp
, bool irq_re_init
)
3608 int i
, j
, rc
, size
, arr_size
;
3612 /* Allocate bnapi mem pointer array and mem block for
3615 arr_size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
*) *
3617 size
= L1_CACHE_ALIGN(sizeof(struct bnxt_napi
));
3618 bnapi
= kzalloc(arr_size
+ size
* bp
->cp_nr_rings
, GFP_KERNEL
);
3624 for (i
= 0; i
< bp
->cp_nr_rings
; i
++, bnapi
+= size
) {
3625 bp
->bnapi
[i
] = bnapi
;
3626 bp
->bnapi
[i
]->index
= i
;
3627 bp
->bnapi
[i
]->bp
= bp
;
3628 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
3629 struct bnxt_cp_ring_info
*cpr
=
3630 &bp
->bnapi
[i
]->cp_ring
;
3632 cpr
->cp_ring_struct
.ring_mem
.flags
=
3633 BNXT_RMEM_RING_PTE_FLAG
;
3637 bp
->rx_ring
= kcalloc(bp
->rx_nr_rings
,
3638 sizeof(struct bnxt_rx_ring_info
),
3643 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
3644 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
3646 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
3647 rxr
->rx_ring_struct
.ring_mem
.flags
=
3648 BNXT_RMEM_RING_PTE_FLAG
;
3649 rxr
->rx_agg_ring_struct
.ring_mem
.flags
=
3650 BNXT_RMEM_RING_PTE_FLAG
;
3652 rxr
->bnapi
= bp
->bnapi
[i
];
3653 bp
->bnapi
[i
]->rx_ring
= &bp
->rx_ring
[i
];
3656 bp
->tx_ring
= kcalloc(bp
->tx_nr_rings
,
3657 sizeof(struct bnxt_tx_ring_info
),
3662 bp
->tx_ring_map
= kcalloc(bp
->tx_nr_rings
, sizeof(u16
),
3665 if (!bp
->tx_ring_map
)
3668 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
3671 j
= bp
->rx_nr_rings
;
3673 for (i
= 0; i
< bp
->tx_nr_rings
; i
++, j
++) {
3674 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
3676 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
3677 txr
->tx_ring_struct
.ring_mem
.flags
=
3678 BNXT_RMEM_RING_PTE_FLAG
;
3679 txr
->bnapi
= bp
->bnapi
[j
];
3680 bp
->bnapi
[j
]->tx_ring
= txr
;
3681 bp
->tx_ring_map
[i
] = bp
->tx_nr_rings_xdp
+ i
;
3682 if (i
>= bp
->tx_nr_rings_xdp
) {
3683 txr
->txq_index
= i
- bp
->tx_nr_rings_xdp
;
3684 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int
;
3686 bp
->bnapi
[j
]->flags
|= BNXT_NAPI_FLAG_XDP
;
3687 bp
->bnapi
[j
]->tx_int
= bnxt_tx_int_xdp
;
3691 rc
= bnxt_alloc_stats(bp
);
3695 rc
= bnxt_alloc_ntp_fltrs(bp
);
3699 rc
= bnxt_alloc_vnics(bp
);
3704 bnxt_init_ring_struct(bp
);
3706 rc
= bnxt_alloc_rx_rings(bp
);
3710 rc
= bnxt_alloc_tx_rings(bp
);
3714 rc
= bnxt_alloc_cp_rings(bp
);
3718 bp
->vnic_info
[0].flags
|= BNXT_VNIC_RSS_FLAG
| BNXT_VNIC_MCAST_FLAG
|
3719 BNXT_VNIC_UCAST_FLAG
;
3720 rc
= bnxt_alloc_vnic_attributes(bp
);
3726 bnxt_free_mem(bp
, true);
3730 static void bnxt_disable_int(struct bnxt
*bp
)
3737 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3738 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3739 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3740 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
3742 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
)
3743 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
3747 static int bnxt_cp_num_to_irq_num(struct bnxt
*bp
, int n
)
3749 struct bnxt_napi
*bnapi
= bp
->bnapi
[n
];
3750 struct bnxt_cp_ring_info
*cpr
;
3752 cpr
= &bnapi
->cp_ring
;
3753 return cpr
->cp_ring_struct
.map_idx
;
3756 static void bnxt_disable_int_sync(struct bnxt
*bp
)
3760 atomic_inc(&bp
->intr_sem
);
3762 bnxt_disable_int(bp
);
3763 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3764 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
3766 synchronize_irq(bp
->irq_tbl
[map_idx
].vector
);
3770 static void bnxt_enable_int(struct bnxt
*bp
)
3774 atomic_set(&bp
->intr_sem
, 0);
3775 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
3776 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
3777 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
3779 bnxt_db_nq_arm(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
3783 void bnxt_hwrm_cmd_hdr_init(struct bnxt
*bp
, void *request
, u16 req_type
,
3784 u16 cmpl_ring
, u16 target_id
)
3786 struct input
*req
= request
;
3788 req
->req_type
= cpu_to_le16(req_type
);
3789 req
->cmpl_ring
= cpu_to_le16(cmpl_ring
);
3790 req
->target_id
= cpu_to_le16(target_id
);
3791 if (bnxt_kong_hwrm_message(bp
, req
))
3792 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_kong_resp_dma_addr
);
3794 req
->resp_addr
= cpu_to_le64(bp
->hwrm_cmd_resp_dma_addr
);
3797 static int bnxt_hwrm_do_send_msg(struct bnxt
*bp
, void *msg
, u32 msg_len
,
3798 int timeout
, bool silent
)
3800 int i
, intr_process
, rc
, tmo_count
;
3801 struct input
*req
= msg
;
3805 u16 cp_ring_id
, len
= 0;
3806 struct hwrm_err_output
*resp
= bp
->hwrm_cmd_resp_addr
;
3807 u16 max_req_len
= BNXT_HWRM_MAX_REQ_LEN
;
3808 struct hwrm_short_input short_input
= {0};
3809 u32 doorbell_offset
= BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER
;
3810 u8
*resp_addr
= (u8
*)bp
->hwrm_cmd_resp_addr
;
3811 u32 bar_offset
= BNXT_GRCPF_REG_CHIMP_COMM
;
3812 u16 dst
= BNXT_HWRM_CHNL_CHIMP
;
3814 if (msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
3815 if (msg_len
> bp
->hwrm_max_ext_req_len
||
3816 !bp
->hwrm_short_cmd_req_addr
)
3820 if (bnxt_hwrm_kong_chnl(bp
, req
)) {
3821 dst
= BNXT_HWRM_CHNL_KONG
;
3822 bar_offset
= BNXT_GRCPF_REG_KONG_COMM
;
3823 doorbell_offset
= BNXT_GRCPF_REG_KONG_COMM_TRIGGER
;
3824 resp
= bp
->hwrm_cmd_kong_resp_addr
;
3825 resp_addr
= (u8
*)bp
->hwrm_cmd_kong_resp_addr
;
3828 memset(resp
, 0, PAGE_SIZE
);
3829 cp_ring_id
= le16_to_cpu(req
->cmpl_ring
);
3830 intr_process
= (cp_ring_id
== INVALID_HW_RING_ID
) ? 0 : 1;
3832 req
->seq_id
= cpu_to_le16(bnxt_get_hwrm_seq_id(bp
, dst
));
3833 /* currently supports only one outstanding message */
3835 bp
->hwrm_intr_seq_id
= le16_to_cpu(req
->seq_id
);
3837 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
3838 msg_len
> BNXT_HWRM_MAX_REQ_LEN
) {
3839 void *short_cmd_req
= bp
->hwrm_short_cmd_req_addr
;
3842 /* Set boundary for maximum extended request length for short
3843 * cmd format. If passed up from device use the max supported
3844 * internal req length.
3846 max_msg_len
= bp
->hwrm_max_ext_req_len
;
3848 memcpy(short_cmd_req
, req
, msg_len
);
3849 if (msg_len
< max_msg_len
)
3850 memset(short_cmd_req
+ msg_len
, 0,
3851 max_msg_len
- msg_len
);
3853 short_input
.req_type
= req
->req_type
;
3854 short_input
.signature
=
3855 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD
);
3856 short_input
.size
= cpu_to_le16(msg_len
);
3857 short_input
.req_addr
=
3858 cpu_to_le64(bp
->hwrm_short_cmd_req_dma_addr
);
3860 data
= (u32
*)&short_input
;
3861 msg_len
= sizeof(short_input
);
3863 /* Sync memory write before updating doorbell */
3866 max_req_len
= BNXT_HWRM_SHORT_REQ_LEN
;
3869 /* Write request msg to hwrm channel */
3870 __iowrite32_copy(bp
->bar0
+ bar_offset
, data
, msg_len
/ 4);
3872 for (i
= msg_len
; i
< max_req_len
; i
+= 4)
3873 writel(0, bp
->bar0
+ bar_offset
+ i
);
3875 /* Ring channel doorbell */
3876 writel(1, bp
->bar0
+ doorbell_offset
);
3879 timeout
= DFLT_HWRM_CMD_TIMEOUT
;
3880 /* convert timeout to usec */
3884 /* Short timeout for the first few iterations:
3885 * number of loops = number of loops for short timeout +
3886 * number of loops for standard timeout.
3888 tmo_count
= HWRM_SHORT_TIMEOUT_COUNTER
;
3889 timeout
= timeout
- HWRM_SHORT_MIN_TIMEOUT
* HWRM_SHORT_TIMEOUT_COUNTER
;
3890 tmo_count
+= DIV_ROUND_UP(timeout
, HWRM_MIN_TIMEOUT
);
3891 resp_len
= (__le32
*)(resp_addr
+ HWRM_RESP_LEN_OFFSET
);
3894 u16 seq_id
= bp
->hwrm_intr_seq_id
;
3896 /* Wait until hwrm response cmpl interrupt is processed */
3897 while (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
&&
3899 /* on first few passes, just barely sleep */
3900 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
)
3901 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
3902 HWRM_SHORT_MAX_TIMEOUT
);
3904 usleep_range(HWRM_MIN_TIMEOUT
,
3908 if (bp
->hwrm_intr_seq_id
!= (u16
)~seq_id
) {
3909 netdev_err(bp
->dev
, "Resp cmpl intr err msg: 0x%x\n",
3910 le16_to_cpu(req
->req_type
));
3913 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
3915 valid
= resp_addr
+ len
- 1;
3919 /* Check if response len is updated */
3920 for (i
= 0; i
< tmo_count
; i
++) {
3921 len
= (le32_to_cpu(*resp_len
) & HWRM_RESP_LEN_MASK
) >>
3925 /* on first few passes, just barely sleep */
3926 if (i
< HWRM_SHORT_TIMEOUT_COUNTER
)
3927 usleep_range(HWRM_SHORT_MIN_TIMEOUT
,
3928 HWRM_SHORT_MAX_TIMEOUT
);
3930 usleep_range(HWRM_MIN_TIMEOUT
,
3934 if (i
>= tmo_count
) {
3935 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
3936 HWRM_TOTAL_TIMEOUT(i
),
3937 le16_to_cpu(req
->req_type
),
3938 le16_to_cpu(req
->seq_id
), len
);
3942 /* Last byte of resp contains valid bit */
3943 valid
= resp_addr
+ len
- 1;
3944 for (j
= 0; j
< HWRM_VALID_BIT_DELAY_USEC
; j
++) {
3945 /* make sure we read from updated DMA memory */
3952 if (j
>= HWRM_VALID_BIT_DELAY_USEC
) {
3953 netdev_err(bp
->dev
, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
3954 HWRM_TOTAL_TIMEOUT(i
),
3955 le16_to_cpu(req
->req_type
),
3956 le16_to_cpu(req
->seq_id
), len
, *valid
);
3961 /* Zero valid bit for compatibility. Valid bit in an older spec
3962 * may become a new field in a newer spec. We must make sure that
3963 * a new field not implemented by old spec will read zero.
3966 rc
= le16_to_cpu(resp
->error_code
);
3968 netdev_err(bp
->dev
, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3969 le16_to_cpu(resp
->req_type
),
3970 le16_to_cpu(resp
->seq_id
), rc
);
3974 int _hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
3976 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, false);
3979 int _hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
3982 return bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
3985 int hwrm_send_message(struct bnxt
*bp
, void *msg
, u32 msg_len
, int timeout
)
3989 mutex_lock(&bp
->hwrm_cmd_lock
);
3990 rc
= _hwrm_send_message(bp
, msg
, msg_len
, timeout
);
3991 mutex_unlock(&bp
->hwrm_cmd_lock
);
3995 int hwrm_send_message_silent(struct bnxt
*bp
, void *msg
, u32 msg_len
,
4000 mutex_lock(&bp
->hwrm_cmd_lock
);
4001 rc
= bnxt_hwrm_do_send_msg(bp
, msg
, msg_len
, timeout
, true);
4002 mutex_unlock(&bp
->hwrm_cmd_lock
);
4006 int bnxt_hwrm_func_rgtr_async_events(struct bnxt
*bp
, unsigned long *bmap
,
4009 struct hwrm_func_drv_rgtr_input req
= {0};
4010 DECLARE_BITMAP(async_events_bmap
, 256);
4011 u32
*events
= (u32
*)async_events_bmap
;
4014 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
4017 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD
);
4019 memset(async_events_bmap
, 0, sizeof(async_events_bmap
));
4020 for (i
= 0; i
< ARRAY_SIZE(bnxt_async_events_arr
); i
++)
4021 __set_bit(bnxt_async_events_arr
[i
], async_events_bmap
);
4023 if (bmap
&& bmap_size
) {
4024 for (i
= 0; i
< bmap_size
; i
++) {
4025 if (test_bit(i
, bmap
))
4026 __set_bit(i
, async_events_bmap
);
4030 for (i
= 0; i
< 8; i
++)
4031 req
.async_event_fwd
[i
] |= cpu_to_le32(events
[i
]);
4033 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4036 static int bnxt_hwrm_func_drv_rgtr(struct bnxt
*bp
)
4038 struct hwrm_func_drv_rgtr_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4039 struct hwrm_func_drv_rgtr_input req
= {0};
4042 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_RGTR
, -1, -1);
4045 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE
|
4046 FUNC_DRV_RGTR_REQ_ENABLES_VER
);
4048 req
.os_type
= cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX
);
4049 req
.flags
= cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE
);
4050 req
.ver_maj_8b
= DRV_VER_MAJ
;
4051 req
.ver_min_8b
= DRV_VER_MIN
;
4052 req
.ver_upd_8b
= DRV_VER_UPD
;
4053 req
.ver_maj
= cpu_to_le16(DRV_VER_MAJ
);
4054 req
.ver_min
= cpu_to_le16(DRV_VER_MIN
);
4055 req
.ver_upd
= cpu_to_le16(DRV_VER_UPD
);
4061 memset(data
, 0, sizeof(data
));
4062 for (i
= 0; i
< ARRAY_SIZE(bnxt_vf_req_snif
); i
++) {
4063 u16 cmd
= bnxt_vf_req_snif
[i
];
4064 unsigned int bit
, idx
;
4068 data
[idx
] |= 1 << bit
;
4071 for (i
= 0; i
< 8; i
++)
4072 req
.vf_req_fwd
[i
] = cpu_to_le32(data
[i
]);
4075 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD
);
4078 if (bp
->fw_cap
& BNXT_FW_CAP_OVS_64BIT_HANDLE
)
4079 req
.flags
|= cpu_to_le32(
4080 FUNC_DRV_RGTR_REQ_FLAGS_FLOW_HANDLE_64BIT_MODE
);
4082 mutex_lock(&bp
->hwrm_cmd_lock
);
4083 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4086 else if (resp
->flags
&
4087 cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED
))
4088 bp
->fw_cap
|= BNXT_FW_CAP_IF_CHANGE
;
4089 mutex_unlock(&bp
->hwrm_cmd_lock
);
4093 static int bnxt_hwrm_func_drv_unrgtr(struct bnxt
*bp
)
4095 struct hwrm_func_drv_unrgtr_input req
= {0};
4097 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_UNRGTR
, -1, -1);
4098 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4101 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt
*bp
, u8 tunnel_type
)
4104 struct hwrm_tunnel_dst_port_free_input req
= {0};
4106 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_FREE
, -1, -1);
4107 req
.tunnel_type
= tunnel_type
;
4109 switch (tunnel_type
) {
4110 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
:
4111 req
.tunnel_dst_port_id
= bp
->vxlan_fw_dst_port_id
;
4113 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
:
4114 req
.tunnel_dst_port_id
= bp
->nge_fw_dst_port_id
;
4120 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4122 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
4127 static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt
*bp
, __be16 port
,
4131 struct hwrm_tunnel_dst_port_alloc_input req
= {0};
4132 struct hwrm_tunnel_dst_port_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4134 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TUNNEL_DST_PORT_ALLOC
, -1, -1);
4136 req
.tunnel_type
= tunnel_type
;
4137 req
.tunnel_dst_port_val
= port
;
4139 mutex_lock(&bp
->hwrm_cmd_lock
);
4140 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4142 netdev_err(bp
->dev
, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
4147 switch (tunnel_type
) {
4148 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN
:
4149 bp
->vxlan_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
4151 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE
:
4152 bp
->nge_fw_dst_port_id
= resp
->tunnel_dst_port_id
;
4159 mutex_unlock(&bp
->hwrm_cmd_lock
);
4163 static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt
*bp
, u16 vnic_id
)
4165 struct hwrm_cfa_l2_set_rx_mask_input req
= {0};
4166 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4168 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_SET_RX_MASK
, -1, -1);
4169 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4171 req
.num_mc_entries
= cpu_to_le32(vnic
->mc_list_count
);
4172 req
.mc_tbl_addr
= cpu_to_le64(vnic
->mc_list_mapping
);
4173 req
.mask
= cpu_to_le32(vnic
->rx_mask
);
4174 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4177 #ifdef CONFIG_RFS_ACCEL
4178 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt
*bp
,
4179 struct bnxt_ntuple_filter
*fltr
)
4181 struct hwrm_cfa_ntuple_filter_free_input req
= {0};
4183 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_FREE
, -1, -1);
4184 req
.ntuple_filter_id
= fltr
->filter_id
;
4185 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4188 #define BNXT_NTP_FLTR_FLAGS \
4189 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
4190 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
4191 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
4192 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
4193 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
4194 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
4195 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
4196 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
4197 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
4198 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
4199 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
4200 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
4201 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
4202 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
4204 #define BNXT_NTP_TUNNEL_FLTR_FLAG \
4205 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
4207 static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt
*bp
,
4208 struct bnxt_ntuple_filter
*fltr
)
4210 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[fltr
->rxq
+ 1];
4211 struct hwrm_cfa_ntuple_filter_alloc_input req
= {0};
4212 struct hwrm_cfa_ntuple_filter_alloc_output
*resp
;
4213 struct flow_keys
*keys
= &fltr
->fkeys
;
4216 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_NTUPLE_FILTER_ALLOC
, -1, -1);
4217 req
.l2_filter_id
= bp
->vnic_info
[0].fw_l2_filter_id
[fltr
->l2_fltr_idx
];
4219 req
.enables
= cpu_to_le32(BNXT_NTP_FLTR_FLAGS
);
4221 req
.ethertype
= htons(ETH_P_IP
);
4222 memcpy(req
.src_macaddr
, fltr
->src_mac_addr
, ETH_ALEN
);
4223 req
.ip_addr_type
= CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4
;
4224 req
.ip_protocol
= keys
->basic
.ip_proto
;
4226 if (keys
->basic
.n_proto
== htons(ETH_P_IPV6
)) {
4229 req
.ethertype
= htons(ETH_P_IPV6
);
4231 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6
;
4232 *(struct in6_addr
*)&req
.src_ipaddr
[0] =
4233 keys
->addrs
.v6addrs
.src
;
4234 *(struct in6_addr
*)&req
.dst_ipaddr
[0] =
4235 keys
->addrs
.v6addrs
.dst
;
4236 for (i
= 0; i
< 4; i
++) {
4237 req
.src_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4238 req
.dst_ipaddr_mask
[i
] = cpu_to_be32(0xffffffff);
4241 req
.src_ipaddr
[0] = keys
->addrs
.v4addrs
.src
;
4242 req
.src_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4243 req
.dst_ipaddr
[0] = keys
->addrs
.v4addrs
.dst
;
4244 req
.dst_ipaddr_mask
[0] = cpu_to_be32(0xffffffff);
4246 if (keys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) {
4247 req
.enables
|= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG
);
4249 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL
;
4252 req
.src_port
= keys
->ports
.src
;
4253 req
.src_port_mask
= cpu_to_be16(0xffff);
4254 req
.dst_port
= keys
->ports
.dst
;
4255 req
.dst_port_mask
= cpu_to_be16(0xffff);
4257 req
.dst_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4258 mutex_lock(&bp
->hwrm_cmd_lock
);
4259 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4261 resp
= bnxt_get_hwrm_resp_addr(bp
, &req
);
4262 fltr
->filter_id
= resp
->ntuple_filter_id
;
4264 mutex_unlock(&bp
->hwrm_cmd_lock
);
4269 static int bnxt_hwrm_set_vnic_filter(struct bnxt
*bp
, u16 vnic_id
, u16 idx
,
4273 struct hwrm_cfa_l2_filter_alloc_input req
= {0};
4274 struct hwrm_cfa_l2_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4276 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_ALLOC
, -1, -1);
4277 req
.flags
= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX
);
4278 if (!BNXT_CHIP_TYPE_NITRO_A0(bp
))
4280 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST
);
4281 req
.dst_id
= cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
4283 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR
|
4284 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID
|
4285 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK
);
4286 memcpy(req
.l2_addr
, mac_addr
, ETH_ALEN
);
4287 req
.l2_addr_mask
[0] = 0xff;
4288 req
.l2_addr_mask
[1] = 0xff;
4289 req
.l2_addr_mask
[2] = 0xff;
4290 req
.l2_addr_mask
[3] = 0xff;
4291 req
.l2_addr_mask
[4] = 0xff;
4292 req
.l2_addr_mask
[5] = 0xff;
4294 mutex_lock(&bp
->hwrm_cmd_lock
);
4295 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4297 bp
->vnic_info
[vnic_id
].fw_l2_filter_id
[idx
] =
4299 mutex_unlock(&bp
->hwrm_cmd_lock
);
4303 static int bnxt_hwrm_clear_vnic_filter(struct bnxt
*bp
)
4305 u16 i
, j
, num_of_vnics
= 1; /* only vnic 0 supported */
4308 /* Any associated ntuple filters will also be cleared by firmware. */
4309 mutex_lock(&bp
->hwrm_cmd_lock
);
4310 for (i
= 0; i
< num_of_vnics
; i
++) {
4311 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
4313 for (j
= 0; j
< vnic
->uc_filter_count
; j
++) {
4314 struct hwrm_cfa_l2_filter_free_input req
= {0};
4316 bnxt_hwrm_cmd_hdr_init(bp
, &req
,
4317 HWRM_CFA_L2_FILTER_FREE
, -1, -1);
4319 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[j
];
4321 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4324 vnic
->uc_filter_count
= 0;
4326 mutex_unlock(&bp
->hwrm_cmd_lock
);
4331 static int bnxt_hwrm_vnic_set_tpa(struct bnxt
*bp
, u16 vnic_id
, u32 tpa_flags
)
4333 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4334 struct hwrm_vnic_tpa_cfg_input req
= {0};
4336 if (vnic
->fw_vnic_id
== INVALID_HW_RING_ID
)
4339 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_TPA_CFG
, -1, -1);
4342 u16 mss
= bp
->dev
->mtu
- 40;
4343 u32 nsegs
, n
, segs
= 0, flags
;
4345 flags
= VNIC_TPA_CFG_REQ_FLAGS_TPA
|
4346 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA
|
4347 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE
|
4348 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN
|
4349 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ
;
4350 if (tpa_flags
& BNXT_FLAG_GRO
)
4351 flags
|= VNIC_TPA_CFG_REQ_FLAGS_GRO
;
4353 req
.flags
= cpu_to_le32(flags
);
4356 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS
|
4357 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS
|
4358 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN
);
4360 /* Number of segs are log2 units, and first packet is not
4361 * included as part of this units.
4363 if (mss
<= BNXT_RX_PAGE_SIZE
) {
4364 n
= BNXT_RX_PAGE_SIZE
/ mss
;
4365 nsegs
= (MAX_SKB_FRAGS
- 1) * n
;
4367 n
= mss
/ BNXT_RX_PAGE_SIZE
;
4368 if (mss
& (BNXT_RX_PAGE_SIZE
- 1))
4370 nsegs
= (MAX_SKB_FRAGS
- n
) / n
;
4373 segs
= ilog2(nsegs
);
4374 req
.max_agg_segs
= cpu_to_le16(segs
);
4375 req
.max_aggs
= cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX
);
4377 req
.min_agg_len
= cpu_to_le32(512);
4379 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4381 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4384 static u16
bnxt_cp_ring_from_grp(struct bnxt
*bp
, struct bnxt_ring_struct
*ring
)
4386 struct bnxt_ring_grp_info
*grp_info
;
4388 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4389 return grp_info
->cp_fw_ring_id
;
4392 static u16
bnxt_cp_ring_for_rx(struct bnxt
*bp
, struct bnxt_rx_ring_info
*rxr
)
4394 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4395 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
4396 struct bnxt_cp_ring_info
*cpr
;
4398 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_RX_HDL
];
4399 return cpr
->cp_ring_struct
.fw_ring_id
;
4401 return bnxt_cp_ring_from_grp(bp
, &rxr
->rx_ring_struct
);
4405 static u16
bnxt_cp_ring_for_tx(struct bnxt
*bp
, struct bnxt_tx_ring_info
*txr
)
4407 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4408 struct bnxt_napi
*bnapi
= txr
->bnapi
;
4409 struct bnxt_cp_ring_info
*cpr
;
4411 cpr
= bnapi
->cp_ring
.cp_ring_arr
[BNXT_TX_HDL
];
4412 return cpr
->cp_ring_struct
.fw_ring_id
;
4414 return bnxt_cp_ring_from_grp(bp
, &txr
->tx_ring_struct
);
4418 static int bnxt_hwrm_vnic_set_rss(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
4420 u32 i
, j
, max_rings
;
4421 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4422 struct hwrm_vnic_rss_cfg_input req
= {0};
4424 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) ||
4425 vnic
->fw_rss_cos_lb_ctx
[0] == INVALID_HW_RING_ID
)
4428 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
4430 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
4431 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
4432 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
) {
4433 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
4434 max_rings
= bp
->rx_nr_rings
- 1;
4436 max_rings
= bp
->rx_nr_rings
;
4441 /* Fill the RSS indirection table with ring group ids */
4442 for (i
= 0, j
= 0; i
< HW_HASH_INDEX_SIZE
; i
++, j
++) {
4445 vnic
->rss_table
[i
] = cpu_to_le16(vnic
->fw_grp_ids
[j
]);
4448 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
4449 req
.hash_key_tbl_addr
=
4450 cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
4452 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
4453 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4456 static int bnxt_hwrm_vnic_set_rss_p5(struct bnxt
*bp
, u16 vnic_id
, bool set_rss
)
4458 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4459 u32 i
, j
, k
, nr_ctxs
, max_rings
= bp
->rx_nr_rings
;
4460 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[0];
4461 struct hwrm_vnic_rss_cfg_input req
= {0};
4463 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_CFG
, -1, -1);
4464 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4466 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4469 req
.hash_type
= cpu_to_le32(bp
->rss_hash_cfg
);
4470 req
.hash_mode_flags
= VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT
;
4471 req
.ring_grp_tbl_addr
= cpu_to_le64(vnic
->rss_table_dma_addr
);
4472 req
.hash_key_tbl_addr
= cpu_to_le64(vnic
->rss_hash_key_dma_addr
);
4473 nr_ctxs
= DIV_ROUND_UP(bp
->rx_nr_rings
, 64);
4474 for (i
= 0, k
= 0; i
< nr_ctxs
; i
++) {
4475 __le16
*ring_tbl
= vnic
->rss_table
;
4478 req
.ring_table_pair_index
= i
;
4479 req
.rss_ctx_idx
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[i
]);
4480 for (j
= 0; j
< 64; j
++) {
4483 ring_id
= rxr
->rx_ring_struct
.fw_ring_id
;
4484 *ring_tbl
++ = cpu_to_le16(ring_id
);
4485 ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
4486 *ring_tbl
++ = cpu_to_le16(ring_id
);
4489 if (k
== max_rings
) {
4491 rxr
= &bp
->rx_ring
[0];
4494 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4501 static int bnxt_hwrm_vnic_set_hds(struct bnxt
*bp
, u16 vnic_id
)
4503 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4504 struct hwrm_vnic_plcmodes_cfg_input req
= {0};
4506 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_PLCMODES_CFG
, -1, -1);
4507 req
.flags
= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT
|
4508 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4
|
4509 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6
);
4511 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID
|
4512 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID
);
4513 /* thresholds not implemented in firmware yet */
4514 req
.jumbo_thresh
= cpu_to_le16(bp
->rx_copy_thresh
);
4515 req
.hds_threshold
= cpu_to_le16(bp
->rx_copy_thresh
);
4516 req
.vnic_id
= cpu_to_le32(vnic
->fw_vnic_id
);
4517 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4520 static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt
*bp
, u16 vnic_id
,
4523 struct hwrm_vnic_rss_cos_lb_ctx_free_input req
= {0};
4525 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_FREE
, -1, -1);
4526 req
.rss_cos_lb_ctx_id
=
4527 cpu_to_le16(bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
]);
4529 hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4530 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] = INVALID_HW_RING_ID
;
4533 static void bnxt_hwrm_vnic_ctx_free(struct bnxt
*bp
)
4537 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
4538 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[i
];
4540 for (j
= 0; j
< BNXT_MAX_CTX_PER_VNIC
; j
++) {
4541 if (vnic
->fw_rss_cos_lb_ctx
[j
] != INVALID_HW_RING_ID
)
4542 bnxt_hwrm_vnic_ctx_free_one(bp
, i
, j
);
4545 bp
->rsscos_nr_ctxs
= 0;
4548 static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt
*bp
, u16 vnic_id
, u16 ctx_idx
)
4551 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req
= {0};
4552 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output
*resp
=
4553 bp
->hwrm_cmd_resp_addr
;
4555 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC
, -1,
4558 mutex_lock(&bp
->hwrm_cmd_lock
);
4559 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4561 bp
->vnic_info
[vnic_id
].fw_rss_cos_lb_ctx
[ctx_idx
] =
4562 le16_to_cpu(resp
->rss_cos_lb_ctx_id
);
4563 mutex_unlock(&bp
->hwrm_cmd_lock
);
4568 static u32
bnxt_get_roce_vnic_mode(struct bnxt
*bp
)
4570 if (bp
->flags
& BNXT_FLAG_ROCE_MIRROR_CAP
)
4571 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE
;
4572 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE
;
4575 int bnxt_hwrm_vnic_cfg(struct bnxt
*bp
, u16 vnic_id
)
4577 unsigned int ring
= 0, grp_idx
;
4578 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4579 struct hwrm_vnic_cfg_input req
= {0};
4582 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_CFG
, -1, -1);
4584 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4585 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[0];
4587 req
.default_rx_ring_id
=
4588 cpu_to_le16(rxr
->rx_ring_struct
.fw_ring_id
);
4589 req
.default_cmpl_ring_id
=
4590 cpu_to_le16(bnxt_cp_ring_for_rx(bp
, rxr
));
4592 cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID
|
4593 VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID
);
4596 req
.enables
= cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP
);
4597 /* Only RSS support for now TBD: COS & LB */
4598 if (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
) {
4599 req
.rss_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[0]);
4600 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
4601 VNIC_CFG_REQ_ENABLES_MRU
);
4602 } else if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
) {
4604 cpu_to_le16(bp
->vnic_info
[0].fw_rss_cos_lb_ctx
[0]);
4605 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE
|
4606 VNIC_CFG_REQ_ENABLES_MRU
);
4607 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE
);
4609 req
.rss_rule
= cpu_to_le16(0xffff);
4612 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) &&
4613 (vnic
->fw_rss_cos_lb_ctx
[0] != INVALID_HW_RING_ID
)) {
4614 req
.cos_rule
= cpu_to_le16(vnic
->fw_rss_cos_lb_ctx
[1]);
4615 req
.enables
|= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE
);
4617 req
.cos_rule
= cpu_to_le16(0xffff);
4620 if (vnic
->flags
& BNXT_VNIC_RSS_FLAG
)
4622 else if (vnic
->flags
& BNXT_VNIC_RFS_FLAG
)
4624 else if ((vnic_id
== 1) && BNXT_CHIP_TYPE_NITRO_A0(bp
))
4625 ring
= bp
->rx_nr_rings
- 1;
4627 grp_idx
= bp
->rx_ring
[ring
].bnapi
->index
;
4628 req
.dflt_ring_grp
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_grp_id
);
4629 req
.lb_rule
= cpu_to_le16(0xffff);
4631 req
.mru
= cpu_to_le16(bp
->dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+
4634 req
.vnic_id
= cpu_to_le16(vnic
->fw_vnic_id
);
4635 #ifdef CONFIG_BNXT_SRIOV
4637 def_vlan
= bp
->vf
.vlan
;
4639 if ((bp
->flags
& BNXT_FLAG_STRIP_VLAN
) || def_vlan
)
4640 req
.flags
|= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE
);
4641 if (!vnic_id
&& bnxt_ulp_registered(bp
->edev
, BNXT_ROCE_ULP
))
4642 req
.flags
|= cpu_to_le32(bnxt_get_roce_vnic_mode(bp
));
4644 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4647 static int bnxt_hwrm_vnic_free_one(struct bnxt
*bp
, u16 vnic_id
)
4651 if (bp
->vnic_info
[vnic_id
].fw_vnic_id
!= INVALID_HW_RING_ID
) {
4652 struct hwrm_vnic_free_input req
= {0};
4654 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_FREE
, -1, -1);
4656 cpu_to_le32(bp
->vnic_info
[vnic_id
].fw_vnic_id
);
4658 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4661 bp
->vnic_info
[vnic_id
].fw_vnic_id
= INVALID_HW_RING_ID
;
4666 static void bnxt_hwrm_vnic_free(struct bnxt
*bp
)
4670 for (i
= 0; i
< bp
->nr_vnics
; i
++)
4671 bnxt_hwrm_vnic_free_one(bp
, i
);
4674 static int bnxt_hwrm_vnic_alloc(struct bnxt
*bp
, u16 vnic_id
,
4675 unsigned int start_rx_ring_idx
,
4676 unsigned int nr_rings
)
4679 unsigned int i
, j
, grp_idx
, end_idx
= start_rx_ring_idx
+ nr_rings
;
4680 struct hwrm_vnic_alloc_input req
= {0};
4681 struct hwrm_vnic_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4682 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
4684 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4685 goto vnic_no_ring_grps
;
4687 /* map ring groups to this vnic */
4688 for (i
= start_rx_ring_idx
, j
= 0; i
< end_idx
; i
++, j
++) {
4689 grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
4690 if (bp
->grp_info
[grp_idx
].fw_grp_id
== INVALID_HW_RING_ID
) {
4691 netdev_err(bp
->dev
, "Not enough ring groups avail:%x req:%x\n",
4695 vnic
->fw_grp_ids
[j
] = bp
->grp_info
[grp_idx
].fw_grp_id
;
4699 for (i
= 0; i
< BNXT_MAX_CTX_PER_VNIC
; i
++)
4700 vnic
->fw_rss_cos_lb_ctx
[i
] = INVALID_HW_RING_ID
;
4702 req
.flags
= cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT
);
4704 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_ALLOC
, -1, -1);
4706 mutex_lock(&bp
->hwrm_cmd_lock
);
4707 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4709 vnic
->fw_vnic_id
= le32_to_cpu(resp
->vnic_id
);
4710 mutex_unlock(&bp
->hwrm_cmd_lock
);
4714 static int bnxt_hwrm_vnic_qcaps(struct bnxt
*bp
)
4716 struct hwrm_vnic_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4717 struct hwrm_vnic_qcaps_input req
= {0};
4720 if (bp
->hwrm_spec_code
< 0x10600)
4723 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VNIC_QCAPS
, -1, -1);
4724 mutex_lock(&bp
->hwrm_cmd_lock
);
4725 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4727 u32 flags
= le32_to_cpu(resp
->flags
);
4729 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
) &&
4730 (flags
& VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP
))
4731 bp
->flags
|= BNXT_FLAG_NEW_RSS_CAP
;
4733 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP
)
4734 bp
->flags
|= BNXT_FLAG_ROCE_MIRROR_CAP
;
4736 mutex_unlock(&bp
->hwrm_cmd_lock
);
4740 static int bnxt_hwrm_ring_grp_alloc(struct bnxt
*bp
)
4745 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4748 mutex_lock(&bp
->hwrm_cmd_lock
);
4749 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
4750 struct hwrm_ring_grp_alloc_input req
= {0};
4751 struct hwrm_ring_grp_alloc_output
*resp
=
4752 bp
->hwrm_cmd_resp_addr
;
4753 unsigned int grp_idx
= bp
->rx_ring
[i
].bnapi
->index
;
4755 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_ALLOC
, -1, -1);
4757 req
.cr
= cpu_to_le16(bp
->grp_info
[grp_idx
].cp_fw_ring_id
);
4758 req
.rr
= cpu_to_le16(bp
->grp_info
[grp_idx
].rx_fw_ring_id
);
4759 req
.ar
= cpu_to_le16(bp
->grp_info
[grp_idx
].agg_fw_ring_id
);
4760 req
.sc
= cpu_to_le16(bp
->grp_info
[grp_idx
].fw_stats_ctx
);
4762 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4767 bp
->grp_info
[grp_idx
].fw_grp_id
=
4768 le32_to_cpu(resp
->ring_group_id
);
4770 mutex_unlock(&bp
->hwrm_cmd_lock
);
4774 static int bnxt_hwrm_ring_grp_free(struct bnxt
*bp
)
4778 struct hwrm_ring_grp_free_input req
= {0};
4780 if (!bp
->grp_info
|| (bp
->flags
& BNXT_FLAG_CHIP_P5
))
4783 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_GRP_FREE
, -1, -1);
4785 mutex_lock(&bp
->hwrm_cmd_lock
);
4786 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4787 if (bp
->grp_info
[i
].fw_grp_id
== INVALID_HW_RING_ID
)
4790 cpu_to_le32(bp
->grp_info
[i
].fw_grp_id
);
4792 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
4796 bp
->grp_info
[i
].fw_grp_id
= INVALID_HW_RING_ID
;
4798 mutex_unlock(&bp
->hwrm_cmd_lock
);
4802 static int hwrm_ring_alloc_send_msg(struct bnxt
*bp
,
4803 struct bnxt_ring_struct
*ring
,
4804 u32 ring_type
, u32 map_index
)
4806 int rc
= 0, err
= 0;
4807 struct hwrm_ring_alloc_input req
= {0};
4808 struct hwrm_ring_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
4809 struct bnxt_ring_mem_info
*rmem
= &ring
->ring_mem
;
4810 struct bnxt_ring_grp_info
*grp_info
;
4813 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_ALLOC
, -1, -1);
4816 if (rmem
->nr_pages
> 1) {
4817 req
.page_tbl_addr
= cpu_to_le64(rmem
->pg_tbl_map
);
4818 /* Page size is in log2 units */
4819 req
.page_size
= BNXT_PAGE_SHIFT
;
4820 req
.page_tbl_depth
= 1;
4822 req
.page_tbl_addr
= cpu_to_le64(rmem
->dma_arr
[0]);
4825 /* Association of ring index with doorbell index and MSIX number */
4826 req
.logical_id
= cpu_to_le16(map_index
);
4828 switch (ring_type
) {
4829 case HWRM_RING_ALLOC_TX
: {
4830 struct bnxt_tx_ring_info
*txr
;
4832 txr
= container_of(ring
, struct bnxt_tx_ring_info
,
4834 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_TX
;
4835 /* Association of transmit ring with completion ring */
4836 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4837 req
.cmpl_ring_id
= cpu_to_le16(bnxt_cp_ring_for_tx(bp
, txr
));
4838 req
.length
= cpu_to_le32(bp
->tx_ring_mask
+ 1);
4839 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
4840 req
.queue_id
= cpu_to_le16(ring
->queue_id
);
4843 case HWRM_RING_ALLOC_RX
:
4844 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
4845 req
.length
= cpu_to_le32(bp
->rx_ring_mask
+ 1);
4846 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4849 /* Association of rx ring with stats context */
4850 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4851 req
.rx_buf_size
= cpu_to_le16(bp
->rx_buf_use_size
);
4852 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
4853 req
.enables
|= cpu_to_le32(
4854 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
4855 if (NET_IP_ALIGN
== 2)
4856 flags
= RING_ALLOC_REQ_FLAGS_RX_SOP_PAD
;
4857 req
.flags
= cpu_to_le16(flags
);
4860 case HWRM_RING_ALLOC_AGG
:
4861 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4862 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX_AGG
;
4863 /* Association of agg ring with rx ring */
4864 grp_info
= &bp
->grp_info
[ring
->grp_idx
];
4865 req
.rx_ring_id
= cpu_to_le16(grp_info
->rx_fw_ring_id
);
4866 req
.rx_buf_size
= cpu_to_le16(BNXT_RX_PAGE_SIZE
);
4867 req
.stat_ctx_id
= cpu_to_le32(grp_info
->fw_stats_ctx
);
4868 req
.enables
|= cpu_to_le32(
4869 RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID
|
4870 RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID
);
4872 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_RX
;
4874 req
.length
= cpu_to_le32(bp
->rx_agg_ring_mask
+ 1);
4876 case HWRM_RING_ALLOC_CMPL
:
4877 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_L2_CMPL
;
4878 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
4879 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4880 /* Association of cp ring with nq */
4881 grp_info
= &bp
->grp_info
[map_index
];
4882 req
.nq_ring_id
= cpu_to_le16(grp_info
->cp_fw_ring_id
);
4883 req
.cq_handle
= cpu_to_le64(ring
->handle
);
4884 req
.enables
|= cpu_to_le32(
4885 RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID
);
4886 } else if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
4887 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
4890 case HWRM_RING_ALLOC_NQ
:
4891 req
.ring_type
= RING_ALLOC_REQ_RING_TYPE_NQ
;
4892 req
.length
= cpu_to_le32(bp
->cp_ring_mask
+ 1);
4893 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
4894 req
.int_mode
= RING_ALLOC_REQ_INT_MODE_MSIX
;
4897 netdev_err(bp
->dev
, "hwrm alloc invalid ring type %d\n",
4902 mutex_lock(&bp
->hwrm_cmd_lock
);
4903 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4904 err
= le16_to_cpu(resp
->error_code
);
4905 ring_id
= le16_to_cpu(resp
->ring_id
);
4906 mutex_unlock(&bp
->hwrm_cmd_lock
);
4909 netdev_err(bp
->dev
, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
4910 ring_type
, rc
, err
);
4913 ring
->fw_ring_id
= ring_id
;
4917 static int bnxt_hwrm_set_async_event_cr(struct bnxt
*bp
, int idx
)
4922 struct hwrm_func_cfg_input req
= {0};
4924 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
4925 req
.fid
= cpu_to_le16(0xffff);
4926 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
4927 req
.async_event_cr
= cpu_to_le16(idx
);
4928 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4930 struct hwrm_func_vf_cfg_input req
= {0};
4932 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_VF_CFG
, -1, -1);
4934 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR
);
4935 req
.async_event_cr
= cpu_to_le16(idx
);
4936 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
4941 static void bnxt_set_db(struct bnxt
*bp
, struct bnxt_db_info
*db
, u32 ring_type
,
4942 u32 map_idx
, u32 xid
)
4944 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
4946 db
->doorbell
= bp
->bar1
+ 0x10000;
4948 db
->doorbell
= bp
->bar1
+ 0x4000;
4949 switch (ring_type
) {
4950 case HWRM_RING_ALLOC_TX
:
4951 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SQ
;
4953 case HWRM_RING_ALLOC_RX
:
4954 case HWRM_RING_ALLOC_AGG
:
4955 db
->db_key64
= DBR_PATH_L2
| DBR_TYPE_SRQ
;
4957 case HWRM_RING_ALLOC_CMPL
:
4958 db
->db_key64
= DBR_PATH_L2
;
4960 case HWRM_RING_ALLOC_NQ
:
4961 db
->db_key64
= DBR_PATH_L2
;
4964 db
->db_key64
|= (u64
)xid
<< DBR_XID_SFT
;
4966 db
->doorbell
= bp
->bar1
+ map_idx
* 0x80;
4967 switch (ring_type
) {
4968 case HWRM_RING_ALLOC_TX
:
4969 db
->db_key32
= DB_KEY_TX
;
4971 case HWRM_RING_ALLOC_RX
:
4972 case HWRM_RING_ALLOC_AGG
:
4973 db
->db_key32
= DB_KEY_RX
;
4975 case HWRM_RING_ALLOC_CMPL
:
4976 db
->db_key32
= DB_KEY_CP
;
4982 static int bnxt_hwrm_ring_alloc(struct bnxt
*bp
)
4987 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
4988 type
= HWRM_RING_ALLOC_NQ
;
4990 type
= HWRM_RING_ALLOC_CMPL
;
4991 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
4992 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
4993 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
4994 struct bnxt_ring_struct
*ring
= &cpr
->cp_ring_struct
;
4995 u32 map_idx
= ring
->map_idx
;
4996 unsigned int vector
;
4998 vector
= bp
->irq_tbl
[map_idx
].vector
;
4999 disable_irq_nosync(vector
);
5000 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5005 bnxt_set_db(bp
, &cpr
->cp_db
, type
, map_idx
, ring
->fw_ring_id
);
5006 bnxt_db_nq(bp
, &cpr
->cp_db
, cpr
->cp_raw_cons
);
5008 bp
->grp_info
[i
].cp_fw_ring_id
= ring
->fw_ring_id
;
5011 rc
= bnxt_hwrm_set_async_event_cr(bp
, ring
->fw_ring_id
);
5013 netdev_warn(bp
->dev
, "Failed to set async event completion ring.\n");
5017 type
= HWRM_RING_ALLOC_TX
;
5018 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5019 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5020 struct bnxt_ring_struct
*ring
;
5023 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5024 struct bnxt_napi
*bnapi
= txr
->bnapi
;
5025 struct bnxt_cp_ring_info
*cpr
, *cpr2
;
5026 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5028 cpr
= &bnapi
->cp_ring
;
5029 cpr2
= cpr
->cp_ring_arr
[BNXT_TX_HDL
];
5030 ring
= &cpr2
->cp_ring_struct
;
5031 ring
->handle
= BNXT_TX_HDL
;
5032 map_idx
= bnapi
->index
;
5033 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5036 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5038 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5040 ring
= &txr
->tx_ring_struct
;
5042 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5045 bnxt_set_db(bp
, &txr
->tx_db
, type
, map_idx
, ring
->fw_ring_id
);
5048 type
= HWRM_RING_ALLOC_RX
;
5049 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5050 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5051 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5052 struct bnxt_napi
*bnapi
= rxr
->bnapi
;
5053 u32 map_idx
= bnapi
->index
;
5055 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5058 bnxt_set_db(bp
, &rxr
->rx_db
, type
, map_idx
, ring
->fw_ring_id
);
5059 bnxt_db_write(bp
, &rxr
->rx_db
, rxr
->rx_prod
);
5060 bp
->grp_info
[map_idx
].rx_fw_ring_id
= ring
->fw_ring_id
;
5061 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5062 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5063 u32 type2
= HWRM_RING_ALLOC_CMPL
;
5064 struct bnxt_cp_ring_info
*cpr2
;
5066 cpr2
= cpr
->cp_ring_arr
[BNXT_RX_HDL
];
5067 ring
= &cpr2
->cp_ring_struct
;
5068 ring
->handle
= BNXT_RX_HDL
;
5069 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type2
, map_idx
);
5072 bnxt_set_db(bp
, &cpr2
->cp_db
, type2
, map_idx
,
5074 bnxt_db_cq(bp
, &cpr2
->cp_db
, cpr2
->cp_raw_cons
);
5078 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
5079 type
= HWRM_RING_ALLOC_AGG
;
5080 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5081 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5082 struct bnxt_ring_struct
*ring
=
5083 &rxr
->rx_agg_ring_struct
;
5084 u32 grp_idx
= ring
->grp_idx
;
5085 u32 map_idx
= grp_idx
+ bp
->rx_nr_rings
;
5087 rc
= hwrm_ring_alloc_send_msg(bp
, ring
, type
, map_idx
);
5091 bnxt_set_db(bp
, &rxr
->rx_agg_db
, type
, map_idx
,
5093 bnxt_db_write(bp
, &rxr
->rx_agg_db
, rxr
->rx_agg_prod
);
5094 bp
->grp_info
[grp_idx
].agg_fw_ring_id
= ring
->fw_ring_id
;
5101 static int hwrm_ring_free_send_msg(struct bnxt
*bp
,
5102 struct bnxt_ring_struct
*ring
,
5103 u32 ring_type
, int cmpl_ring_id
)
5106 struct hwrm_ring_free_input req
= {0};
5107 struct hwrm_ring_free_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5110 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_FREE
, cmpl_ring_id
, -1);
5111 req
.ring_type
= ring_type
;
5112 req
.ring_id
= cpu_to_le16(ring
->fw_ring_id
);
5114 mutex_lock(&bp
->hwrm_cmd_lock
);
5115 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5116 error_code
= le16_to_cpu(resp
->error_code
);
5117 mutex_unlock(&bp
->hwrm_cmd_lock
);
5119 if (rc
|| error_code
) {
5120 netdev_err(bp
->dev
, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
5121 ring_type
, rc
, error_code
);
5127 static void bnxt_hwrm_ring_free(struct bnxt
*bp
, bool close_path
)
5135 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
5136 struct bnxt_tx_ring_info
*txr
= &bp
->tx_ring
[i
];
5137 struct bnxt_ring_struct
*ring
= &txr
->tx_ring_struct
;
5140 cmpl_ring_id
= bnxt_cp_ring_for_tx(bp
, txr
);
5141 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5142 hwrm_ring_free_send_msg(bp
, ring
,
5143 RING_FREE_REQ_RING_TYPE_TX
,
5144 close_path
? cmpl_ring_id
:
5145 INVALID_HW_RING_ID
);
5146 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5150 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5151 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5152 struct bnxt_ring_struct
*ring
= &rxr
->rx_ring_struct
;
5153 u32 grp_idx
= rxr
->bnapi
->index
;
5156 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5157 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5158 hwrm_ring_free_send_msg(bp
, ring
,
5159 RING_FREE_REQ_RING_TYPE_RX
,
5160 close_path
? cmpl_ring_id
:
5161 INVALID_HW_RING_ID
);
5162 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5163 bp
->grp_info
[grp_idx
].rx_fw_ring_id
=
5168 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5169 type
= RING_FREE_REQ_RING_TYPE_RX_AGG
;
5171 type
= RING_FREE_REQ_RING_TYPE_RX
;
5172 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
5173 struct bnxt_rx_ring_info
*rxr
= &bp
->rx_ring
[i
];
5174 struct bnxt_ring_struct
*ring
= &rxr
->rx_agg_ring_struct
;
5175 u32 grp_idx
= rxr
->bnapi
->index
;
5178 cmpl_ring_id
= bnxt_cp_ring_for_rx(bp
, rxr
);
5179 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5180 hwrm_ring_free_send_msg(bp
, ring
, type
,
5181 close_path
? cmpl_ring_id
:
5182 INVALID_HW_RING_ID
);
5183 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5184 bp
->grp_info
[grp_idx
].agg_fw_ring_id
=
5189 /* The completion rings are about to be freed. After that the
5190 * IRQ doorbell will not work anymore. So we need to disable
5193 bnxt_disable_int_sync(bp
);
5195 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5196 type
= RING_FREE_REQ_RING_TYPE_NQ
;
5198 type
= RING_FREE_REQ_RING_TYPE_L2_CMPL
;
5199 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5200 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5201 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5202 struct bnxt_ring_struct
*ring
;
5205 for (j
= 0; j
< 2; j
++) {
5206 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
5209 ring
= &cpr2
->cp_ring_struct
;
5210 if (ring
->fw_ring_id
== INVALID_HW_RING_ID
)
5212 hwrm_ring_free_send_msg(bp
, ring
,
5213 RING_FREE_REQ_RING_TYPE_L2_CMPL
,
5214 INVALID_HW_RING_ID
);
5215 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5218 ring
= &cpr
->cp_ring_struct
;
5219 if (ring
->fw_ring_id
!= INVALID_HW_RING_ID
) {
5220 hwrm_ring_free_send_msg(bp
, ring
, type
,
5221 INVALID_HW_RING_ID
);
5222 ring
->fw_ring_id
= INVALID_HW_RING_ID
;
5223 bp
->grp_info
[i
].cp_fw_ring_id
= INVALID_HW_RING_ID
;
5228 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
5231 static int bnxt_hwrm_get_rings(struct bnxt
*bp
)
5233 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5234 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5235 struct hwrm_func_qcfg_input req
= {0};
5238 if (bp
->hwrm_spec_code
< 0x10601)
5241 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5242 req
.fid
= cpu_to_le16(0xffff);
5243 mutex_lock(&bp
->hwrm_cmd_lock
);
5244 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5246 mutex_unlock(&bp
->hwrm_cmd_lock
);
5250 hw_resc
->resv_tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
5251 if (BNXT_NEW_RM(bp
)) {
5254 hw_resc
->resv_rx_rings
= le16_to_cpu(resp
->alloc_rx_rings
);
5255 hw_resc
->resv_hw_ring_grps
=
5256 le32_to_cpu(resp
->alloc_hw_ring_grps
);
5257 hw_resc
->resv_vnics
= le16_to_cpu(resp
->alloc_vnics
);
5258 cp
= le16_to_cpu(resp
->alloc_cmpl_rings
);
5259 stats
= le16_to_cpu(resp
->alloc_stat_ctx
);
5260 hw_resc
->resv_irqs
= cp
;
5261 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5262 int rx
= hw_resc
->resv_rx_rings
;
5263 int tx
= hw_resc
->resv_tx_rings
;
5265 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5267 if (cp
< (rx
+ tx
)) {
5268 bnxt_trim_rings(bp
, &rx
, &tx
, cp
, false);
5269 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5271 hw_resc
->resv_rx_rings
= rx
;
5272 hw_resc
->resv_tx_rings
= tx
;
5274 hw_resc
->resv_irqs
= le16_to_cpu(resp
->alloc_msix
);
5275 hw_resc
->resv_hw_ring_grps
= rx
;
5277 hw_resc
->resv_cp_rings
= cp
;
5278 hw_resc
->resv_stat_ctxs
= stats
;
5280 mutex_unlock(&bp
->hwrm_cmd_lock
);
5284 /* Caller must hold bp->hwrm_cmd_lock */
5285 int __bnxt_hwrm_get_tx_rings(struct bnxt
*bp
, u16 fid
, int *tx_rings
)
5287 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5288 struct hwrm_func_qcfg_input req
= {0};
5291 if (bp
->hwrm_spec_code
< 0x10601)
5294 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5295 req
.fid
= cpu_to_le16(fid
);
5296 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5298 *tx_rings
= le16_to_cpu(resp
->alloc_tx_rings
);
5303 static bool bnxt_rfs_supported(struct bnxt
*bp
);
5306 __bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, struct hwrm_func_cfg_input
*req
,
5307 int tx_rings
, int rx_rings
, int ring_grps
,
5308 int cp_rings
, int stats
, int vnics
)
5312 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_CFG
, -1, -1);
5313 req
->fid
= cpu_to_le16(0xffff);
5314 enables
|= tx_rings
? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
5315 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
5316 if (BNXT_NEW_RM(bp
)) {
5317 enables
|= rx_rings
? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS
: 0;
5318 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5319 enables
|= cp_rings
? FUNC_CFG_REQ_ENABLES_NUM_MSIX
: 0;
5320 enables
|= tx_rings
+ ring_grps
?
5321 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
5322 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5323 enables
|= rx_rings
?
5324 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5326 enables
|= cp_rings
?
5327 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
5328 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5329 enables
|= ring_grps
?
5330 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
|
5331 FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5333 enables
|= vnics
? FUNC_CFG_REQ_ENABLES_NUM_VNICS
: 0;
5335 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
5336 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5337 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
5338 req
->num_msix
= cpu_to_le16(cp_rings
);
5339 req
->num_rsscos_ctxs
=
5340 cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
5342 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
5343 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
5344 req
->num_rsscos_ctxs
= cpu_to_le16(1);
5345 if (!(bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
) &&
5346 bnxt_rfs_supported(bp
))
5347 req
->num_rsscos_ctxs
=
5348 cpu_to_le16(ring_grps
+ 1);
5350 req
->num_stat_ctxs
= cpu_to_le16(stats
);
5351 req
->num_vnics
= cpu_to_le16(vnics
);
5353 req
->enables
= cpu_to_le32(enables
);
5357 __bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
,
5358 struct hwrm_func_vf_cfg_input
*req
, int tx_rings
,
5359 int rx_rings
, int ring_grps
, int cp_rings
,
5360 int stats
, int vnics
)
5364 bnxt_hwrm_cmd_hdr_init(bp
, req
, HWRM_FUNC_VF_CFG
, -1, -1);
5365 enables
|= tx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS
: 0;
5366 enables
|= rx_rings
? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS
|
5367 FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS
: 0;
5368 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5369 enables
|= tx_rings
+ ring_grps
?
5370 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
5371 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5373 enables
|= cp_rings
?
5374 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS
|
5375 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS
: 0;
5376 enables
|= ring_grps
?
5377 FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS
: 0;
5379 enables
|= vnics
? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS
: 0;
5380 enables
|= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS
;
5382 req
->num_l2_ctxs
= cpu_to_le16(BNXT_VF_MAX_L2_CTX
);
5383 req
->num_tx_rings
= cpu_to_le16(tx_rings
);
5384 req
->num_rx_rings
= cpu_to_le16(rx_rings
);
5385 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
5386 req
->num_cmpl_rings
= cpu_to_le16(tx_rings
+ ring_grps
);
5387 req
->num_rsscos_ctxs
= cpu_to_le16(DIV_ROUND_UP(ring_grps
, 64));
5389 req
->num_cmpl_rings
= cpu_to_le16(cp_rings
);
5390 req
->num_hw_ring_grps
= cpu_to_le16(ring_grps
);
5391 req
->num_rsscos_ctxs
= cpu_to_le16(BNXT_VF_MAX_RSS_CTX
);
5393 req
->num_stat_ctxs
= cpu_to_le16(stats
);
5394 req
->num_vnics
= cpu_to_le16(vnics
);
5396 req
->enables
= cpu_to_le32(enables
);
5400 bnxt_hwrm_reserve_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5401 int ring_grps
, int cp_rings
, int stats
, int vnics
)
5403 struct hwrm_func_cfg_input req
= {0};
5406 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5407 cp_rings
, stats
, vnics
);
5411 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5415 if (bp
->hwrm_spec_code
< 0x10601)
5416 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
5418 rc
= bnxt_hwrm_get_rings(bp
);
5423 bnxt_hwrm_reserve_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5424 int ring_grps
, int cp_rings
, int stats
, int vnics
)
5426 struct hwrm_func_vf_cfg_input req
= {0};
5429 if (!BNXT_NEW_RM(bp
)) {
5430 bp
->hw_resc
.resv_tx_rings
= tx_rings
;
5434 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5435 cp_rings
, stats
, vnics
);
5436 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5440 rc
= bnxt_hwrm_get_rings(bp
);
5444 static int bnxt_hwrm_reserve_rings(struct bnxt
*bp
, int tx
, int rx
, int grp
,
5445 int cp
, int stat
, int vnic
)
5448 return bnxt_hwrm_reserve_pf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
5451 return bnxt_hwrm_reserve_vf_rings(bp
, tx
, rx
, grp
, cp
, stat
,
5455 int bnxt_nq_rings_in_use(struct bnxt
*bp
)
5457 int cp
= bp
->cp_nr_rings
;
5458 int ulp_msix
, ulp_base
;
5460 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
5462 ulp_base
= bnxt_get_ulp_msix_base(bp
);
5464 if ((ulp_base
+ ulp_msix
) > cp
)
5465 cp
= ulp_base
+ ulp_msix
;
5470 static int bnxt_cp_rings_in_use(struct bnxt
*bp
)
5474 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5475 return bnxt_nq_rings_in_use(bp
);
5477 cp
= bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
5481 static int bnxt_get_func_stat_ctxs(struct bnxt
*bp
)
5483 return bp
->cp_nr_rings
+ bnxt_get_ulp_stat_ctxs(bp
);
5486 static bool bnxt_need_reserve_rings(struct bnxt
*bp
)
5488 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5489 int cp
= bnxt_cp_rings_in_use(bp
);
5490 int nq
= bnxt_nq_rings_in_use(bp
);
5491 int rx
= bp
->rx_nr_rings
, stat
;
5492 int vnic
= 1, grp
= rx
;
5494 if (bp
->hwrm_spec_code
< 0x10601)
5497 if (hw_resc
->resv_tx_rings
!= bp
->tx_nr_rings
)
5500 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5502 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5504 stat
= bnxt_get_func_stat_ctxs(bp
);
5505 if (BNXT_NEW_RM(bp
) &&
5506 (hw_resc
->resv_rx_rings
!= rx
|| hw_resc
->resv_cp_rings
!= cp
||
5507 hw_resc
->resv_irqs
< nq
|| hw_resc
->resv_vnics
!= vnic
||
5508 hw_resc
->resv_stat_ctxs
!= stat
||
5509 (hw_resc
->resv_hw_ring_grps
!= grp
&&
5510 !(bp
->flags
& BNXT_FLAG_CHIP_P5
))))
5515 static int __bnxt_reserve_rings(struct bnxt
*bp
)
5517 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
5518 int cp
= bnxt_nq_rings_in_use(bp
);
5519 int tx
= bp
->tx_nr_rings
;
5520 int rx
= bp
->rx_nr_rings
;
5521 int grp
, rx_rings
, rc
;
5525 if (!bnxt_need_reserve_rings(bp
))
5528 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
5530 if ((bp
->flags
& BNXT_FLAG_RFS
) && !(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5532 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5534 grp
= bp
->rx_nr_rings
;
5535 stat
= bnxt_get_func_stat_ctxs(bp
);
5537 rc
= bnxt_hwrm_reserve_rings(bp
, tx
, rx
, grp
, cp
, stat
, vnic
);
5541 tx
= hw_resc
->resv_tx_rings
;
5542 if (BNXT_NEW_RM(bp
)) {
5543 rx
= hw_resc
->resv_rx_rings
;
5544 cp
= hw_resc
->resv_irqs
;
5545 grp
= hw_resc
->resv_hw_ring_grps
;
5546 vnic
= hw_resc
->resv_vnics
;
5547 stat
= hw_resc
->resv_stat_ctxs
;
5551 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
5555 if (netif_running(bp
->dev
))
5558 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
5559 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
5560 bp
->dev
->hw_features
&= ~NETIF_F_LRO
;
5561 bp
->dev
->features
&= ~NETIF_F_LRO
;
5562 bnxt_set_ring_params(bp
);
5565 rx_rings
= min_t(int, rx_rings
, grp
);
5566 cp
= min_t(int, cp
, bp
->cp_nr_rings
);
5567 if (stat
> bnxt_get_ulp_stat_ctxs(bp
))
5568 stat
-= bnxt_get_ulp_stat_ctxs(bp
);
5569 cp
= min_t(int, cp
, stat
);
5570 rc
= bnxt_trim_rings(bp
, &rx_rings
, &tx
, cp
, sh
);
5571 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
5573 cp
= sh
? max_t(int, tx
, rx_rings
) : tx
+ rx_rings
;
5574 bp
->tx_nr_rings
= tx
;
5575 bp
->rx_nr_rings
= rx_rings
;
5576 bp
->cp_nr_rings
= cp
;
5578 if (!tx
|| !rx
|| !cp
|| !grp
|| !vnic
|| !stat
)
5584 static int bnxt_hwrm_check_vf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5585 int ring_grps
, int cp_rings
, int stats
,
5588 struct hwrm_func_vf_cfg_input req
= {0};
5592 if (!BNXT_NEW_RM(bp
))
5595 __bnxt_hwrm_reserve_vf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5596 cp_rings
, stats
, vnics
);
5597 flags
= FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST
|
5598 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
5599 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
5600 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
5601 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
|
5602 FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
;
5603 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5604 flags
|= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
5606 req
.flags
= cpu_to_le32(flags
);
5607 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5613 static int bnxt_hwrm_check_pf_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5614 int ring_grps
, int cp_rings
, int stats
,
5617 struct hwrm_func_cfg_input req
= {0};
5621 __bnxt_hwrm_reserve_pf_rings(bp
, &req
, tx_rings
, rx_rings
, ring_grps
,
5622 cp_rings
, stats
, vnics
);
5623 flags
= FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST
;
5624 if (BNXT_NEW_RM(bp
)) {
5625 flags
|= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST
|
5626 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST
|
5627 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST
|
5628 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST
;
5629 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
5630 flags
|= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST
|
5631 FUNC_CFG_REQ_FLAGS_NQ_ASSETS_TEST
;
5633 flags
|= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST
;
5636 req
.flags
= cpu_to_le32(flags
);
5637 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5643 static int bnxt_hwrm_check_rings(struct bnxt
*bp
, int tx_rings
, int rx_rings
,
5644 int ring_grps
, int cp_rings
, int stats
,
5647 if (bp
->hwrm_spec_code
< 0x10801)
5651 return bnxt_hwrm_check_pf_rings(bp
, tx_rings
, rx_rings
,
5652 ring_grps
, cp_rings
, stats
,
5655 return bnxt_hwrm_check_vf_rings(bp
, tx_rings
, rx_rings
, ring_grps
,
5656 cp_rings
, stats
, vnics
);
5659 static void bnxt_hwrm_coal_params_qcaps(struct bnxt
*bp
)
5661 struct hwrm_ring_aggint_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5662 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5663 struct hwrm_ring_aggint_qcaps_input req
= {0};
5666 coal_cap
->cmpl_params
= BNXT_LEGACY_COAL_CMPL_PARAMS
;
5667 coal_cap
->num_cmpl_dma_aggr_max
= 63;
5668 coal_cap
->num_cmpl_dma_aggr_during_int_max
= 63;
5669 coal_cap
->cmpl_aggr_dma_tmr_max
= 65535;
5670 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
= 65535;
5671 coal_cap
->int_lat_tmr_min_max
= 65535;
5672 coal_cap
->int_lat_tmr_max_max
= 65535;
5673 coal_cap
->num_cmpl_aggr_int_max
= 65535;
5674 coal_cap
->timer_units
= 80;
5676 if (bp
->hwrm_spec_code
< 0x10902)
5679 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_AGGINT_QCAPS
, -1, -1);
5680 mutex_lock(&bp
->hwrm_cmd_lock
);
5681 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5683 coal_cap
->cmpl_params
= le32_to_cpu(resp
->cmpl_params
);
5684 coal_cap
->nq_params
= le32_to_cpu(resp
->nq_params
);
5685 coal_cap
->num_cmpl_dma_aggr_max
=
5686 le16_to_cpu(resp
->num_cmpl_dma_aggr_max
);
5687 coal_cap
->num_cmpl_dma_aggr_during_int_max
=
5688 le16_to_cpu(resp
->num_cmpl_dma_aggr_during_int_max
);
5689 coal_cap
->cmpl_aggr_dma_tmr_max
=
5690 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_max
);
5691 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
=
5692 le16_to_cpu(resp
->cmpl_aggr_dma_tmr_during_int_max
);
5693 coal_cap
->int_lat_tmr_min_max
=
5694 le16_to_cpu(resp
->int_lat_tmr_min_max
);
5695 coal_cap
->int_lat_tmr_max_max
=
5696 le16_to_cpu(resp
->int_lat_tmr_max_max
);
5697 coal_cap
->num_cmpl_aggr_int_max
=
5698 le16_to_cpu(resp
->num_cmpl_aggr_int_max
);
5699 coal_cap
->timer_units
= le16_to_cpu(resp
->timer_units
);
5701 mutex_unlock(&bp
->hwrm_cmd_lock
);
5704 static u16
bnxt_usec_to_coal_tmr(struct bnxt
*bp
, u16 usec
)
5706 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5708 return usec
* 1000 / coal_cap
->timer_units
;
5711 static void bnxt_hwrm_set_coal_params(struct bnxt
*bp
,
5712 struct bnxt_coal
*hw_coal
,
5713 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input
*req
)
5715 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5716 u32 cmpl_params
= coal_cap
->cmpl_params
;
5717 u16 val
, tmr
, max
, flags
= 0;
5719 max
= hw_coal
->bufs_per_record
* 128;
5720 if (hw_coal
->budget
)
5721 max
= hw_coal
->bufs_per_record
* hw_coal
->budget
;
5722 max
= min_t(u16
, max
, coal_cap
->num_cmpl_aggr_int_max
);
5724 val
= clamp_t(u16
, hw_coal
->coal_bufs
, 1, max
);
5725 req
->num_cmpl_aggr_int
= cpu_to_le16(val
);
5727 val
= min_t(u16
, val
, coal_cap
->num_cmpl_dma_aggr_max
);
5728 req
->num_cmpl_dma_aggr
= cpu_to_le16(val
);
5730 val
= clamp_t(u16
, hw_coal
->coal_bufs_irq
, 1,
5731 coal_cap
->num_cmpl_dma_aggr_during_int_max
);
5732 req
->num_cmpl_dma_aggr_during_int
= cpu_to_le16(val
);
5734 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
);
5735 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_max_max
);
5736 req
->int_lat_tmr_max
= cpu_to_le16(tmr
);
5738 /* min timer set to 1/2 of interrupt timer */
5739 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN
) {
5741 val
= clamp_t(u16
, val
, 1, coal_cap
->int_lat_tmr_min_max
);
5742 req
->int_lat_tmr_min
= cpu_to_le16(val
);
5743 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
5746 /* buf timer set to 1/4 of interrupt timer */
5747 val
= clamp_t(u16
, tmr
/ 4, 1, coal_cap
->cmpl_aggr_dma_tmr_max
);
5748 req
->cmpl_aggr_dma_tmr
= cpu_to_le16(val
);
5751 RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT
) {
5752 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks_irq
);
5753 val
= clamp_t(u16
, tmr
, 1,
5754 coal_cap
->cmpl_aggr_dma_tmr_during_int_max
);
5755 req
->cmpl_aggr_dma_tmr_during_int
= cpu_to_le16(tmr
);
5757 cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE
);
5760 if (cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET
)
5761 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET
;
5762 if ((cmpl_params
& RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE
) &&
5763 hw_coal
->idle_thresh
&& hw_coal
->coal_ticks
< hw_coal
->idle_thresh
)
5764 flags
|= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE
;
5765 req
->flags
= cpu_to_le16(flags
);
5766 req
->enables
|= cpu_to_le16(BNXT_COAL_CMPL_ENABLES
);
5769 /* Caller holds bp->hwrm_cmd_lock */
5770 static int __bnxt_hwrm_set_coal_nq(struct bnxt
*bp
, struct bnxt_napi
*bnapi
,
5771 struct bnxt_coal
*hw_coal
)
5773 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req
= {0};
5774 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5775 struct bnxt_coal_cap
*coal_cap
= &bp
->coal_cap
;
5776 u32 nq_params
= coal_cap
->nq_params
;
5779 if (!(nq_params
& RING_AGGINT_QCAPS_RESP_NQ_PARAMS_INT_LAT_TMR_MIN
))
5782 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
,
5784 req
.ring_id
= cpu_to_le16(cpr
->cp_ring_struct
.fw_ring_id
);
5786 cpu_to_le16(RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_IS_NQ
);
5788 tmr
= bnxt_usec_to_coal_tmr(bp
, hw_coal
->coal_ticks
) / 2;
5789 tmr
= clamp_t(u16
, tmr
, 1, coal_cap
->int_lat_tmr_min_max
);
5790 req
.int_lat_tmr_min
= cpu_to_le16(tmr
);
5791 req
.enables
|= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE
);
5792 return _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5795 int bnxt_hwrm_set_ring_coal(struct bnxt
*bp
, struct bnxt_napi
*bnapi
)
5797 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0};
5798 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5799 struct bnxt_coal coal
;
5801 /* Tick values in micro seconds.
5802 * 1 coal_buf x bufs_per_record = 1 completion record.
5804 memcpy(&coal
, &bp
->rx_coal
, sizeof(struct bnxt_coal
));
5806 coal
.coal_ticks
= cpr
->rx_ring_coal
.coal_ticks
;
5807 coal
.coal_bufs
= cpr
->rx_ring_coal
.coal_bufs
;
5809 if (!bnapi
->rx_ring
)
5812 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
5813 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5815 bnxt_hwrm_set_coal_params(bp
, &coal
, &req_rx
);
5817 req_rx
.ring_id
= cpu_to_le16(bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
));
5819 return hwrm_send_message(bp
, &req_rx
, sizeof(req_rx
),
5823 int bnxt_hwrm_set_coal(struct bnxt
*bp
)
5826 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx
= {0},
5829 bnxt_hwrm_cmd_hdr_init(bp
, &req_rx
,
5830 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5831 bnxt_hwrm_cmd_hdr_init(bp
, &req_tx
,
5832 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS
, -1, -1);
5834 bnxt_hwrm_set_coal_params(bp
, &bp
->rx_coal
, &req_rx
);
5835 bnxt_hwrm_set_coal_params(bp
, &bp
->tx_coal
, &req_tx
);
5837 mutex_lock(&bp
->hwrm_cmd_lock
);
5838 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5839 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5840 struct bnxt_coal
*hw_coal
;
5844 if (!bnapi
->rx_ring
) {
5845 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
5848 ring_id
= bnxt_cp_ring_for_rx(bp
, bnapi
->rx_ring
);
5850 req
->ring_id
= cpu_to_le16(ring_id
);
5852 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
5857 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
5860 if (bnapi
->rx_ring
&& bnapi
->tx_ring
) {
5862 ring_id
= bnxt_cp_ring_for_tx(bp
, bnapi
->tx_ring
);
5863 req
->ring_id
= cpu_to_le16(ring_id
);
5864 rc
= _hwrm_send_message(bp
, req
, sizeof(*req
),
5870 hw_coal
= &bp
->rx_coal
;
5872 hw_coal
= &bp
->tx_coal
;
5873 __bnxt_hwrm_set_coal_nq(bp
, bnapi
, hw_coal
);
5875 mutex_unlock(&bp
->hwrm_cmd_lock
);
5879 static int bnxt_hwrm_stat_ctx_free(struct bnxt
*bp
)
5882 struct hwrm_stat_ctx_free_input req
= {0};
5887 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5890 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_FREE
, -1, -1);
5892 mutex_lock(&bp
->hwrm_cmd_lock
);
5893 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5894 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5895 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5897 if (cpr
->hw_stats_ctx_id
!= INVALID_STATS_CTX_ID
) {
5898 req
.stat_ctx_id
= cpu_to_le32(cpr
->hw_stats_ctx_id
);
5900 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5905 cpr
->hw_stats_ctx_id
= INVALID_STATS_CTX_ID
;
5908 mutex_unlock(&bp
->hwrm_cmd_lock
);
5912 static int bnxt_hwrm_stat_ctx_alloc(struct bnxt
*bp
)
5915 struct hwrm_stat_ctx_alloc_input req
= {0};
5916 struct hwrm_stat_ctx_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5918 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
5921 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_STAT_CTX_ALLOC
, -1, -1);
5923 req
.update_period_ms
= cpu_to_le32(bp
->stats_coal_ticks
/ 1000);
5925 mutex_lock(&bp
->hwrm_cmd_lock
);
5926 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
5927 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
5928 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
5930 req
.stats_dma_addr
= cpu_to_le64(cpr
->hw_stats_map
);
5932 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
5937 cpr
->hw_stats_ctx_id
= le32_to_cpu(resp
->stat_ctx_id
);
5939 bp
->grp_info
[i
].fw_stats_ctx
= cpr
->hw_stats_ctx_id
;
5941 mutex_unlock(&bp
->hwrm_cmd_lock
);
5945 static int bnxt_hwrm_func_qcfg(struct bnxt
*bp
)
5947 struct hwrm_func_qcfg_input req
= {0};
5948 struct hwrm_func_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
5952 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCFG
, -1, -1);
5953 req
.fid
= cpu_to_le16(0xffff);
5954 mutex_lock(&bp
->hwrm_cmd_lock
);
5955 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
5957 goto func_qcfg_exit
;
5959 #ifdef CONFIG_BNXT_SRIOV
5961 struct bnxt_vf_info
*vf
= &bp
->vf
;
5963 vf
->vlan
= le16_to_cpu(resp
->vlan
) & VLAN_VID_MASK
;
5966 flags
= le16_to_cpu(resp
->flags
);
5967 if (flags
& (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
|
5968 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED
)) {
5969 bp
->fw_cap
|= BNXT_FW_CAP_LLDP_AGENT
;
5970 if (flags
& FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED
)
5971 bp
->fw_cap
|= BNXT_FW_CAP_DCBX_AGENT
;
5973 if (BNXT_PF(bp
) && (flags
& FUNC_QCFG_RESP_FLAGS_MULTI_HOST
))
5974 bp
->flags
|= BNXT_FLAG_MULTI_HOST
;
5976 switch (resp
->port_partition_type
) {
5977 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0
:
5978 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5
:
5979 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0
:
5980 bp
->port_partition_type
= resp
->port_partition_type
;
5983 if (bp
->hwrm_spec_code
< 0x10707 ||
5984 resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEB
)
5985 bp
->br_mode
= BRIDGE_MODE_VEB
;
5986 else if (resp
->evb_mode
== FUNC_QCFG_RESP_EVB_MODE_VEPA
)
5987 bp
->br_mode
= BRIDGE_MODE_VEPA
;
5989 bp
->br_mode
= BRIDGE_MODE_UNDEF
;
5991 bp
->max_mtu
= le16_to_cpu(resp
->max_mtu_configured
);
5993 bp
->max_mtu
= BNXT_MAX_MTU
;
5996 mutex_unlock(&bp
->hwrm_cmd_lock
);
6000 static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt
*bp
)
6002 struct hwrm_func_backing_store_qcaps_input req
= {0};
6003 struct hwrm_func_backing_store_qcaps_output
*resp
=
6004 bp
->hwrm_cmd_resp_addr
;
6007 if (bp
->hwrm_spec_code
< 0x10902 || BNXT_VF(bp
) || bp
->ctx
)
6010 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_QCAPS
, -1, -1);
6011 mutex_lock(&bp
->hwrm_cmd_lock
);
6012 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6014 struct bnxt_ctx_pg_info
*ctx_pg
;
6015 struct bnxt_ctx_mem_info
*ctx
;
6018 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
6023 ctx_pg
= kzalloc(sizeof(*ctx_pg
) * (bp
->max_q
+ 1), GFP_KERNEL
);
6029 for (i
= 0; i
< bp
->max_q
+ 1; i
++, ctx_pg
++)
6030 ctx
->tqm_mem
[i
] = ctx_pg
;
6033 ctx
->qp_max_entries
= le32_to_cpu(resp
->qp_max_entries
);
6034 ctx
->qp_min_qp1_entries
= le16_to_cpu(resp
->qp_min_qp1_entries
);
6035 ctx
->qp_max_l2_entries
= le16_to_cpu(resp
->qp_max_l2_entries
);
6036 ctx
->qp_entry_size
= le16_to_cpu(resp
->qp_entry_size
);
6037 ctx
->srq_max_l2_entries
= le16_to_cpu(resp
->srq_max_l2_entries
);
6038 ctx
->srq_max_entries
= le32_to_cpu(resp
->srq_max_entries
);
6039 ctx
->srq_entry_size
= le16_to_cpu(resp
->srq_entry_size
);
6040 ctx
->cq_max_l2_entries
= le16_to_cpu(resp
->cq_max_l2_entries
);
6041 ctx
->cq_max_entries
= le32_to_cpu(resp
->cq_max_entries
);
6042 ctx
->cq_entry_size
= le16_to_cpu(resp
->cq_entry_size
);
6043 ctx
->vnic_max_vnic_entries
=
6044 le16_to_cpu(resp
->vnic_max_vnic_entries
);
6045 ctx
->vnic_max_ring_table_entries
=
6046 le16_to_cpu(resp
->vnic_max_ring_table_entries
);
6047 ctx
->vnic_entry_size
= le16_to_cpu(resp
->vnic_entry_size
);
6048 ctx
->stat_max_entries
= le32_to_cpu(resp
->stat_max_entries
);
6049 ctx
->stat_entry_size
= le16_to_cpu(resp
->stat_entry_size
);
6050 ctx
->tqm_entry_size
= le16_to_cpu(resp
->tqm_entry_size
);
6051 ctx
->tqm_min_entries_per_ring
=
6052 le32_to_cpu(resp
->tqm_min_entries_per_ring
);
6053 ctx
->tqm_max_entries_per_ring
=
6054 le32_to_cpu(resp
->tqm_max_entries_per_ring
);
6055 ctx
->tqm_entries_multiple
= resp
->tqm_entries_multiple
;
6056 if (!ctx
->tqm_entries_multiple
)
6057 ctx
->tqm_entries_multiple
= 1;
6058 ctx
->mrav_max_entries
= le32_to_cpu(resp
->mrav_max_entries
);
6059 ctx
->mrav_entry_size
= le16_to_cpu(resp
->mrav_entry_size
);
6060 ctx
->tim_entry_size
= le16_to_cpu(resp
->tim_entry_size
);
6061 ctx
->tim_max_entries
= le32_to_cpu(resp
->tim_max_entries
);
6066 mutex_unlock(&bp
->hwrm_cmd_lock
);
6070 static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info
*rmem
, u8
*pg_attr
,
6075 if (BNXT_PAGE_SHIFT
== 13)
6077 else if (BNXT_PAGE_SIZE
== 16)
6081 if (rmem
->depth
>= 1) {
6082 if (rmem
->depth
== 2)
6086 *pg_dir
= cpu_to_le64(rmem
->pg_tbl_map
);
6088 *pg_dir
= cpu_to_le64(rmem
->dma_arr
[0]);
6092 #define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \
6093 (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \
6094 FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \
6095 FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \
6096 FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \
6097 FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT)
6099 static int bnxt_hwrm_func_backing_store_cfg(struct bnxt
*bp
, u32 enables
)
6101 struct hwrm_func_backing_store_cfg_input req
= {0};
6102 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
6103 struct bnxt_ctx_pg_info
*ctx_pg
;
6104 __le32
*num_entries
;
6113 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_BACKING_STORE_CFG
, -1, -1);
6114 req
.enables
= cpu_to_le32(enables
);
6116 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP
) {
6117 ctx_pg
= &ctx
->qp_mem
;
6118 req
.qp_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6119 req
.qp_num_qp1_entries
= cpu_to_le16(ctx
->qp_min_qp1_entries
);
6120 req
.qp_num_l2_entries
= cpu_to_le16(ctx
->qp_max_l2_entries
);
6121 req
.qp_entry_size
= cpu_to_le16(ctx
->qp_entry_size
);
6122 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6123 &req
.qpc_pg_size_qpc_lvl
,
6126 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ
) {
6127 ctx_pg
= &ctx
->srq_mem
;
6128 req
.srq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6129 req
.srq_num_l2_entries
= cpu_to_le16(ctx
->srq_max_l2_entries
);
6130 req
.srq_entry_size
= cpu_to_le16(ctx
->srq_entry_size
);
6131 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6132 &req
.srq_pg_size_srq_lvl
,
6135 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ
) {
6136 ctx_pg
= &ctx
->cq_mem
;
6137 req
.cq_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6138 req
.cq_num_l2_entries
= cpu_to_le16(ctx
->cq_max_l2_entries
);
6139 req
.cq_entry_size
= cpu_to_le16(ctx
->cq_entry_size
);
6140 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, &req
.cq_pg_size_cq_lvl
,
6143 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC
) {
6144 ctx_pg
= &ctx
->vnic_mem
;
6145 req
.vnic_num_vnic_entries
=
6146 cpu_to_le16(ctx
->vnic_max_vnic_entries
);
6147 req
.vnic_num_ring_table_entries
=
6148 cpu_to_le16(ctx
->vnic_max_ring_table_entries
);
6149 req
.vnic_entry_size
= cpu_to_le16(ctx
->vnic_entry_size
);
6150 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6151 &req
.vnic_pg_size_vnic_lvl
,
6152 &req
.vnic_page_dir
);
6154 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT
) {
6155 ctx_pg
= &ctx
->stat_mem
;
6156 req
.stat_num_entries
= cpu_to_le32(ctx
->stat_max_entries
);
6157 req
.stat_entry_size
= cpu_to_le16(ctx
->stat_entry_size
);
6158 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6159 &req
.stat_pg_size_stat_lvl
,
6160 &req
.stat_page_dir
);
6162 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
) {
6163 ctx_pg
= &ctx
->mrav_mem
;
6164 req
.mrav_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6165 req
.mrav_entry_size
= cpu_to_le16(ctx
->mrav_entry_size
);
6166 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6167 &req
.mrav_pg_size_mrav_lvl
,
6168 &req
.mrav_page_dir
);
6170 if (enables
& FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
) {
6171 ctx_pg
= &ctx
->tim_mem
;
6172 req
.tim_num_entries
= cpu_to_le32(ctx_pg
->entries
);
6173 req
.tim_entry_size
= cpu_to_le16(ctx
->tim_entry_size
);
6174 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
,
6175 &req
.tim_pg_size_tim_lvl
,
6178 for (i
= 0, num_entries
= &req
.tqm_sp_num_entries
,
6179 pg_attr
= &req
.tqm_sp_pg_size_tqm_sp_lvl
,
6180 pg_dir
= &req
.tqm_sp_page_dir
,
6181 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
;
6182 i
< 9; i
++, num_entries
++, pg_attr
++, pg_dir
++, ena
<<= 1) {
6183 if (!(enables
& ena
))
6186 req
.tqm_entry_size
= cpu_to_le16(ctx
->tqm_entry_size
);
6187 ctx_pg
= ctx
->tqm_mem
[i
];
6188 *num_entries
= cpu_to_le32(ctx_pg
->entries
);
6189 bnxt_hwrm_set_pg_attr(&ctx_pg
->ring_mem
, pg_attr
, pg_dir
);
6191 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6197 static int bnxt_alloc_ctx_mem_blk(struct bnxt
*bp
,
6198 struct bnxt_ctx_pg_info
*ctx_pg
)
6200 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6202 rmem
->page_size
= BNXT_PAGE_SIZE
;
6203 rmem
->pg_arr
= ctx_pg
->ctx_pg_arr
;
6204 rmem
->dma_arr
= ctx_pg
->ctx_dma_arr
;
6205 rmem
->flags
= BNXT_RMEM_VALID_PTE_FLAG
;
6206 if (rmem
->depth
>= 1)
6207 rmem
->flags
|= BNXT_RMEM_USE_FULL_PAGE_FLAG
;
6208 return bnxt_alloc_ring(bp
, rmem
);
6211 static int bnxt_alloc_ctx_pg_tbls(struct bnxt
*bp
,
6212 struct bnxt_ctx_pg_info
*ctx_pg
, u32 mem_size
,
6215 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6221 ctx_pg
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
6222 if (ctx_pg
->nr_pages
> MAX_CTX_TOTAL_PAGES
) {
6223 ctx_pg
->nr_pages
= 0;
6226 if (ctx_pg
->nr_pages
> MAX_CTX_PAGES
|| depth
> 1) {
6230 ctx_pg
->ctx_pg_tbl
= kcalloc(MAX_CTX_PAGES
, sizeof(ctx_pg
),
6232 if (!ctx_pg
->ctx_pg_tbl
)
6234 nr_tbls
= DIV_ROUND_UP(ctx_pg
->nr_pages
, MAX_CTX_PAGES
);
6235 rmem
->nr_pages
= nr_tbls
;
6236 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
6239 for (i
= 0; i
< nr_tbls
; i
++) {
6240 struct bnxt_ctx_pg_info
*pg_tbl
;
6242 pg_tbl
= kzalloc(sizeof(*pg_tbl
), GFP_KERNEL
);
6245 ctx_pg
->ctx_pg_tbl
[i
] = pg_tbl
;
6246 rmem
= &pg_tbl
->ring_mem
;
6247 rmem
->pg_tbl
= ctx_pg
->ctx_pg_arr
[i
];
6248 rmem
->pg_tbl_map
= ctx_pg
->ctx_dma_arr
[i
];
6250 rmem
->nr_pages
= MAX_CTX_PAGES
;
6251 if (i
== (nr_tbls
- 1)) {
6252 int rem
= ctx_pg
->nr_pages
% MAX_CTX_PAGES
;
6255 rmem
->nr_pages
= rem
;
6257 rc
= bnxt_alloc_ctx_mem_blk(bp
, pg_tbl
);
6262 rmem
->nr_pages
= DIV_ROUND_UP(mem_size
, BNXT_PAGE_SIZE
);
6263 if (rmem
->nr_pages
> 1 || depth
)
6265 rc
= bnxt_alloc_ctx_mem_blk(bp
, ctx_pg
);
6270 static void bnxt_free_ctx_pg_tbls(struct bnxt
*bp
,
6271 struct bnxt_ctx_pg_info
*ctx_pg
)
6273 struct bnxt_ring_mem_info
*rmem
= &ctx_pg
->ring_mem
;
6275 if (rmem
->depth
> 1 || ctx_pg
->nr_pages
> MAX_CTX_PAGES
||
6276 ctx_pg
->ctx_pg_tbl
) {
6277 int i
, nr_tbls
= rmem
->nr_pages
;
6279 for (i
= 0; i
< nr_tbls
; i
++) {
6280 struct bnxt_ctx_pg_info
*pg_tbl
;
6281 struct bnxt_ring_mem_info
*rmem2
;
6283 pg_tbl
= ctx_pg
->ctx_pg_tbl
[i
];
6286 rmem2
= &pg_tbl
->ring_mem
;
6287 bnxt_free_ring(bp
, rmem2
);
6288 ctx_pg
->ctx_pg_arr
[i
] = NULL
;
6290 ctx_pg
->ctx_pg_tbl
[i
] = NULL
;
6292 kfree(ctx_pg
->ctx_pg_tbl
);
6293 ctx_pg
->ctx_pg_tbl
= NULL
;
6295 bnxt_free_ring(bp
, rmem
);
6296 ctx_pg
->nr_pages
= 0;
6299 static void bnxt_free_ctx_mem(struct bnxt
*bp
)
6301 struct bnxt_ctx_mem_info
*ctx
= bp
->ctx
;
6307 if (ctx
->tqm_mem
[0]) {
6308 for (i
= 0; i
< bp
->max_q
+ 1; i
++)
6309 bnxt_free_ctx_pg_tbls(bp
, ctx
->tqm_mem
[i
]);
6310 kfree(ctx
->tqm_mem
[0]);
6311 ctx
->tqm_mem
[0] = NULL
;
6314 bnxt_free_ctx_pg_tbls(bp
, &ctx
->tim_mem
);
6315 bnxt_free_ctx_pg_tbls(bp
, &ctx
->mrav_mem
);
6316 bnxt_free_ctx_pg_tbls(bp
, &ctx
->stat_mem
);
6317 bnxt_free_ctx_pg_tbls(bp
, &ctx
->vnic_mem
);
6318 bnxt_free_ctx_pg_tbls(bp
, &ctx
->cq_mem
);
6319 bnxt_free_ctx_pg_tbls(bp
, &ctx
->srq_mem
);
6320 bnxt_free_ctx_pg_tbls(bp
, &ctx
->qp_mem
);
6321 ctx
->flags
&= ~BNXT_CTX_FLAG_INITED
;
6324 static int bnxt_alloc_ctx_mem(struct bnxt
*bp
)
6326 struct bnxt_ctx_pg_info
*ctx_pg
;
6327 struct bnxt_ctx_mem_info
*ctx
;
6328 u32 mem_size
, ena
, entries
;
6334 rc
= bnxt_hwrm_func_backing_store_qcaps(bp
);
6336 netdev_err(bp
->dev
, "Failed querying context mem capability, rc = %d.\n",
6341 if (!ctx
|| (ctx
->flags
& BNXT_CTX_FLAG_INITED
))
6344 if (bp
->flags
& BNXT_FLAG_ROCE_CAP
) {
6350 ctx_pg
= &ctx
->qp_mem
;
6351 ctx_pg
->entries
= ctx
->qp_min_qp1_entries
+ ctx
->qp_max_l2_entries
+
6353 mem_size
= ctx
->qp_entry_size
* ctx_pg
->entries
;
6354 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6358 ctx_pg
= &ctx
->srq_mem
;
6359 ctx_pg
->entries
= ctx
->srq_max_l2_entries
+ extra_srqs
;
6360 mem_size
= ctx
->srq_entry_size
* ctx_pg
->entries
;
6361 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6365 ctx_pg
= &ctx
->cq_mem
;
6366 ctx_pg
->entries
= ctx
->cq_max_l2_entries
+ extra_qps
* 2;
6367 mem_size
= ctx
->cq_entry_size
* ctx_pg
->entries
;
6368 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, pg_lvl
);
6372 ctx_pg
= &ctx
->vnic_mem
;
6373 ctx_pg
->entries
= ctx
->vnic_max_vnic_entries
+
6374 ctx
->vnic_max_ring_table_entries
;
6375 mem_size
= ctx
->vnic_entry_size
* ctx_pg
->entries
;
6376 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6380 ctx_pg
= &ctx
->stat_mem
;
6381 ctx_pg
->entries
= ctx
->stat_max_entries
;
6382 mem_size
= ctx
->stat_entry_size
* ctx_pg
->entries
;
6383 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6388 if (!(bp
->flags
& BNXT_FLAG_ROCE_CAP
))
6391 ctx_pg
= &ctx
->mrav_mem
;
6392 ctx_pg
->entries
= extra_qps
* 4;
6393 mem_size
= ctx
->mrav_entry_size
* ctx_pg
->entries
;
6394 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 2);
6397 ena
= FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV
;
6399 ctx_pg
= &ctx
->tim_mem
;
6400 ctx_pg
->entries
= ctx
->qp_mem
.entries
;
6401 mem_size
= ctx
->tim_entry_size
* ctx_pg
->entries
;
6402 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6405 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM
;
6408 entries
= ctx
->qp_max_l2_entries
+ extra_qps
;
6409 entries
= roundup(entries
, ctx
->tqm_entries_multiple
);
6410 entries
= clamp_t(u32
, entries
, ctx
->tqm_min_entries_per_ring
,
6411 ctx
->tqm_max_entries_per_ring
);
6412 for (i
= 0; i
< bp
->max_q
+ 1; i
++) {
6413 ctx_pg
= ctx
->tqm_mem
[i
];
6414 ctx_pg
->entries
= entries
;
6415 mem_size
= ctx
->tqm_entry_size
* entries
;
6416 rc
= bnxt_alloc_ctx_pg_tbls(bp
, ctx_pg
, mem_size
, 1);
6419 ena
|= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP
<< i
;
6421 ena
|= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES
;
6422 rc
= bnxt_hwrm_func_backing_store_cfg(bp
, ena
);
6424 netdev_err(bp
->dev
, "Failed configuring context mem, rc = %d.\n",
6427 ctx
->flags
|= BNXT_CTX_FLAG_INITED
;
6432 int bnxt_hwrm_func_resc_qcaps(struct bnxt
*bp
, bool all
)
6434 struct hwrm_func_resource_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6435 struct hwrm_func_resource_qcaps_input req
= {0};
6436 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6439 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESOURCE_QCAPS
, -1, -1);
6440 req
.fid
= cpu_to_le16(0xffff);
6442 mutex_lock(&bp
->hwrm_cmd_lock
);
6443 rc
= _hwrm_send_message_silent(bp
, &req
, sizeof(req
),
6447 goto hwrm_func_resc_qcaps_exit
;
6450 hw_resc
->max_tx_sch_inputs
= le16_to_cpu(resp
->max_tx_scheduler_inputs
);
6452 goto hwrm_func_resc_qcaps_exit
;
6454 hw_resc
->min_rsscos_ctxs
= le16_to_cpu(resp
->min_rsscos_ctx
);
6455 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
6456 hw_resc
->min_cp_rings
= le16_to_cpu(resp
->min_cmpl_rings
);
6457 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
6458 hw_resc
->min_tx_rings
= le16_to_cpu(resp
->min_tx_rings
);
6459 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
6460 hw_resc
->min_rx_rings
= le16_to_cpu(resp
->min_rx_rings
);
6461 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
6462 hw_resc
->min_hw_ring_grps
= le16_to_cpu(resp
->min_hw_ring_grps
);
6463 hw_resc
->max_hw_ring_grps
= le16_to_cpu(resp
->max_hw_ring_grps
);
6464 hw_resc
->min_l2_ctxs
= le16_to_cpu(resp
->min_l2_ctxs
);
6465 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
6466 hw_resc
->min_vnics
= le16_to_cpu(resp
->min_vnics
);
6467 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
6468 hw_resc
->min_stat_ctxs
= le16_to_cpu(resp
->min_stat_ctx
);
6469 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
6471 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
6472 u16 max_msix
= le16_to_cpu(resp
->max_msix
);
6474 hw_resc
->max_nqs
= max_msix
;
6475 hw_resc
->max_hw_ring_grps
= hw_resc
->max_rx_rings
;
6479 struct bnxt_pf_info
*pf
= &bp
->pf
;
6481 pf
->vf_resv_strategy
=
6482 le16_to_cpu(resp
->vf_reservation_strategy
);
6483 if (pf
->vf_resv_strategy
> BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC
)
6484 pf
->vf_resv_strategy
= BNXT_VF_RESV_STRATEGY_MAXIMAL
;
6486 hwrm_func_resc_qcaps_exit
:
6487 mutex_unlock(&bp
->hwrm_cmd_lock
);
6491 static int __bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
6494 struct hwrm_func_qcaps_input req
= {0};
6495 struct hwrm_func_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6496 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
6499 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_QCAPS
, -1, -1);
6500 req
.fid
= cpu_to_le16(0xffff);
6502 mutex_lock(&bp
->hwrm_cmd_lock
);
6503 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6505 goto hwrm_func_qcaps_exit
;
6507 flags
= le32_to_cpu(resp
->flags
);
6508 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED
)
6509 bp
->flags
|= BNXT_FLAG_ROCEV1_CAP
;
6510 if (flags
& FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED
)
6511 bp
->flags
|= BNXT_FLAG_ROCEV2_CAP
;
6513 bp
->tx_push_thresh
= 0;
6514 if (flags
& FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED
)
6515 bp
->tx_push_thresh
= BNXT_TX_PUSH_THRESH
;
6517 hw_resc
->max_rsscos_ctxs
= le16_to_cpu(resp
->max_rsscos_ctx
);
6518 hw_resc
->max_cp_rings
= le16_to_cpu(resp
->max_cmpl_rings
);
6519 hw_resc
->max_tx_rings
= le16_to_cpu(resp
->max_tx_rings
);
6520 hw_resc
->max_rx_rings
= le16_to_cpu(resp
->max_rx_rings
);
6521 hw_resc
->max_hw_ring_grps
= le32_to_cpu(resp
->max_hw_ring_grps
);
6522 if (!hw_resc
->max_hw_ring_grps
)
6523 hw_resc
->max_hw_ring_grps
= hw_resc
->max_tx_rings
;
6524 hw_resc
->max_l2_ctxs
= le16_to_cpu(resp
->max_l2_ctxs
);
6525 hw_resc
->max_vnics
= le16_to_cpu(resp
->max_vnics
);
6526 hw_resc
->max_stat_ctxs
= le16_to_cpu(resp
->max_stat_ctx
);
6529 struct bnxt_pf_info
*pf
= &bp
->pf
;
6531 pf
->fw_fid
= le16_to_cpu(resp
->fid
);
6532 pf
->port_id
= le16_to_cpu(resp
->port_id
);
6533 bp
->dev
->dev_port
= pf
->port_id
;
6534 memcpy(pf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
6535 pf
->first_vf_id
= le16_to_cpu(resp
->first_vf_id
);
6536 pf
->max_vfs
= le16_to_cpu(resp
->max_vfs
);
6537 pf
->max_encap_records
= le32_to_cpu(resp
->max_encap_records
);
6538 pf
->max_decap_records
= le32_to_cpu(resp
->max_decap_records
);
6539 pf
->max_tx_em_flows
= le32_to_cpu(resp
->max_tx_em_flows
);
6540 pf
->max_tx_wm_flows
= le32_to_cpu(resp
->max_tx_wm_flows
);
6541 pf
->max_rx_em_flows
= le32_to_cpu(resp
->max_rx_em_flows
);
6542 pf
->max_rx_wm_flows
= le32_to_cpu(resp
->max_rx_wm_flows
);
6543 if (flags
& FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED
)
6544 bp
->flags
|= BNXT_FLAG_WOL_CAP
;
6546 #ifdef CONFIG_BNXT_SRIOV
6547 struct bnxt_vf_info
*vf
= &bp
->vf
;
6549 vf
->fw_fid
= le16_to_cpu(resp
->fid
);
6550 memcpy(vf
->mac_addr
, resp
->mac_address
, ETH_ALEN
);
6554 hwrm_func_qcaps_exit
:
6555 mutex_unlock(&bp
->hwrm_cmd_lock
);
6559 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
);
6561 static int bnxt_hwrm_func_qcaps(struct bnxt
*bp
)
6565 rc
= __bnxt_hwrm_func_qcaps(bp
);
6568 rc
= bnxt_hwrm_queue_qportcfg(bp
);
6570 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %d\n", rc
);
6573 if (bp
->hwrm_spec_code
>= 0x10803) {
6574 rc
= bnxt_alloc_ctx_mem(bp
);
6577 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
6579 bp
->fw_cap
|= BNXT_FW_CAP_NEW_RM
;
6584 static int bnxt_hwrm_func_reset(struct bnxt
*bp
)
6586 struct hwrm_func_reset_input req
= {0};
6588 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_RESET
, -1, -1);
6591 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_RESET_TIMEOUT
);
6594 static int bnxt_hwrm_queue_qportcfg(struct bnxt
*bp
)
6597 struct hwrm_queue_qportcfg_input req
= {0};
6598 struct hwrm_queue_qportcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6602 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_QUEUE_QPORTCFG
, -1, -1);
6604 mutex_lock(&bp
->hwrm_cmd_lock
);
6605 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6609 if (!resp
->max_configurable_queues
) {
6613 bp
->max_tc
= resp
->max_configurable_queues
;
6614 bp
->max_lltc
= resp
->max_configurable_lossless_queues
;
6615 if (bp
->max_tc
> BNXT_MAX_QUEUE
)
6616 bp
->max_tc
= BNXT_MAX_QUEUE
;
6618 no_rdma
= !(bp
->flags
& BNXT_FLAG_ROCE_CAP
);
6619 qptr
= &resp
->queue_id0
;
6620 for (i
= 0, j
= 0; i
< bp
->max_tc
; i
++) {
6621 bp
->q_info
[j
].queue_id
= *qptr
;
6622 bp
->q_ids
[i
] = *qptr
++;
6623 bp
->q_info
[j
].queue_profile
= *qptr
++;
6624 bp
->tc_to_qidx
[j
] = j
;
6625 if (!BNXT_CNPQ(bp
->q_info
[j
].queue_profile
) ||
6626 (no_rdma
&& BNXT_PF(bp
)))
6629 bp
->max_q
= bp
->max_tc
;
6630 bp
->max_tc
= max_t(u8
, j
, 1);
6632 if (resp
->queue_cfg_info
& QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG
)
6635 if (bp
->max_lltc
> bp
->max_tc
)
6636 bp
->max_lltc
= bp
->max_tc
;
6639 mutex_unlock(&bp
->hwrm_cmd_lock
);
6643 static int bnxt_hwrm_ver_get(struct bnxt
*bp
)
6646 struct hwrm_ver_get_input req
= {0};
6647 struct hwrm_ver_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6650 bp
->hwrm_max_req_len
= HWRM_MAX_REQ_LEN
;
6651 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_VER_GET
, -1, -1);
6652 req
.hwrm_intf_maj
= HWRM_VERSION_MAJOR
;
6653 req
.hwrm_intf_min
= HWRM_VERSION_MINOR
;
6654 req
.hwrm_intf_upd
= HWRM_VERSION_UPDATE
;
6655 mutex_lock(&bp
->hwrm_cmd_lock
);
6656 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6658 goto hwrm_ver_get_exit
;
6660 memcpy(&bp
->ver_resp
, resp
, sizeof(struct hwrm_ver_get_output
));
6662 bp
->hwrm_spec_code
= resp
->hwrm_intf_maj_8b
<< 16 |
6663 resp
->hwrm_intf_min_8b
<< 8 |
6664 resp
->hwrm_intf_upd_8b
;
6665 if (resp
->hwrm_intf_maj_8b
< 1) {
6666 netdev_warn(bp
->dev
, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
6667 resp
->hwrm_intf_maj_8b
, resp
->hwrm_intf_min_8b
,
6668 resp
->hwrm_intf_upd_8b
);
6669 netdev_warn(bp
->dev
, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
6671 snprintf(bp
->fw_ver_str
, BC_HWRM_STR_LEN
, "%d.%d.%d.%d",
6672 resp
->hwrm_fw_maj_8b
, resp
->hwrm_fw_min_8b
,
6673 resp
->hwrm_fw_bld_8b
, resp
->hwrm_fw_rsvd_8b
);
6675 bp
->hwrm_cmd_timeout
= le16_to_cpu(resp
->def_req_timeout
);
6676 if (!bp
->hwrm_cmd_timeout
)
6677 bp
->hwrm_cmd_timeout
= DFLT_HWRM_CMD_TIMEOUT
;
6679 if (resp
->hwrm_intf_maj_8b
>= 1) {
6680 bp
->hwrm_max_req_len
= le16_to_cpu(resp
->max_req_win_len
);
6681 bp
->hwrm_max_ext_req_len
= le16_to_cpu(resp
->max_ext_req_len
);
6683 if (bp
->hwrm_max_ext_req_len
< HWRM_MAX_REQ_LEN
)
6684 bp
->hwrm_max_ext_req_len
= HWRM_MAX_REQ_LEN
;
6686 bp
->chip_num
= le16_to_cpu(resp
->chip_num
);
6687 if (bp
->chip_num
== CHIP_NUM_58700
&& !resp
->chip_rev
&&
6689 bp
->flags
|= BNXT_FLAG_CHIP_NITRO_A0
;
6691 dev_caps_cfg
= le32_to_cpu(resp
->dev_caps_cfg
);
6692 if ((dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED
) &&
6693 (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED
))
6694 bp
->fw_cap
|= BNXT_FW_CAP_SHORT_CMD
;
6696 if (dev_caps_cfg
& VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED
)
6697 bp
->fw_cap
|= BNXT_FW_CAP_KONG_MB_CHNL
;
6700 VER_GET_RESP_DEV_CAPS_CFG_FLOW_HANDLE_64BIT_SUPPORTED
)
6701 bp
->fw_cap
|= BNXT_FW_CAP_OVS_64BIT_HANDLE
;
6704 VER_GET_RESP_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED
)
6705 bp
->fw_cap
|= BNXT_FW_CAP_TRUSTED_VF
;
6708 mutex_unlock(&bp
->hwrm_cmd_lock
);
6712 int bnxt_hwrm_fw_set_time(struct bnxt
*bp
)
6714 struct hwrm_fw_set_time_input req
= {0};
6716 time64_t now
= ktime_get_real_seconds();
6718 if ((BNXT_VF(bp
) && bp
->hwrm_spec_code
< 0x10901) ||
6719 bp
->hwrm_spec_code
< 0x10400)
6722 time64_to_tm(now
, 0, &tm
);
6723 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_SET_TIME
, -1, -1);
6724 req
.year
= cpu_to_le16(1900 + tm
.tm_year
);
6725 req
.month
= 1 + tm
.tm_mon
;
6726 req
.day
= tm
.tm_mday
;
6727 req
.hour
= tm
.tm_hour
;
6728 req
.minute
= tm
.tm_min
;
6729 req
.second
= tm
.tm_sec
;
6730 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6733 static int bnxt_hwrm_port_qstats(struct bnxt
*bp
)
6736 struct bnxt_pf_info
*pf
= &bp
->pf
;
6737 struct hwrm_port_qstats_input req
= {0};
6739 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS
))
6742 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS
, -1, -1);
6743 req
.port_id
= cpu_to_le16(pf
->port_id
);
6744 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_map
);
6745 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_map
);
6746 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6750 static int bnxt_hwrm_port_qstats_ext(struct bnxt
*bp
)
6752 struct hwrm_port_qstats_ext_output
*resp
= bp
->hwrm_cmd_resp_addr
;
6753 struct hwrm_queue_pri2cos_qcfg_input req2
= {0};
6754 struct hwrm_port_qstats_ext_input req
= {0};
6755 struct bnxt_pf_info
*pf
= &bp
->pf
;
6758 if (!(bp
->flags
& BNXT_FLAG_PORT_STATS_EXT
))
6761 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_QSTATS_EXT
, -1, -1);
6762 req
.port_id
= cpu_to_le16(pf
->port_id
);
6763 req
.rx_stat_size
= cpu_to_le16(sizeof(struct rx_port_stats_ext
));
6764 req
.rx_stat_host_addr
= cpu_to_le64(bp
->hw_rx_port_stats_ext_map
);
6765 req
.tx_stat_size
= cpu_to_le16(sizeof(struct tx_port_stats_ext
));
6766 req
.tx_stat_host_addr
= cpu_to_le64(bp
->hw_tx_port_stats_ext_map
);
6767 mutex_lock(&bp
->hwrm_cmd_lock
);
6768 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6770 bp
->fw_rx_stats_ext_size
= le16_to_cpu(resp
->rx_stat_size
) / 8;
6771 bp
->fw_tx_stats_ext_size
= le16_to_cpu(resp
->tx_stat_size
) / 8;
6773 bp
->fw_rx_stats_ext_size
= 0;
6774 bp
->fw_tx_stats_ext_size
= 0;
6776 if (bp
->fw_tx_stats_ext_size
<=
6777 offsetof(struct tx_port_stats_ext
, pfc_pri0_tx_duration_us
) / 8) {
6778 mutex_unlock(&bp
->hwrm_cmd_lock
);
6779 bp
->pri2cos_valid
= 0;
6783 bnxt_hwrm_cmd_hdr_init(bp
, &req2
, HWRM_QUEUE_PRI2COS_QCFG
, -1, -1);
6784 req2
.flags
= cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN
);
6786 rc
= _hwrm_send_message(bp
, &req2
, sizeof(req2
), HWRM_CMD_TIMEOUT
);
6788 struct hwrm_queue_pri2cos_qcfg_output
*resp2
;
6792 resp2
= bp
->hwrm_cmd_resp_addr
;
6793 pri2cos
= &resp2
->pri0_cos_queue_id
;
6794 for (i
= 0; i
< 8; i
++) {
6795 u8 queue_id
= pri2cos
[i
];
6797 for (j
= 0; j
< bp
->max_q
; j
++) {
6798 if (bp
->q_ids
[j
] == queue_id
)
6802 bp
->pri2cos_valid
= 1;
6804 mutex_unlock(&bp
->hwrm_cmd_lock
);
6808 static void bnxt_hwrm_free_tunnel_ports(struct bnxt
*bp
)
6810 if (bp
->vxlan_port_cnt
) {
6811 bnxt_hwrm_tunnel_dst_port_free(
6812 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
6814 bp
->vxlan_port_cnt
= 0;
6815 if (bp
->nge_port_cnt
) {
6816 bnxt_hwrm_tunnel_dst_port_free(
6817 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
6819 bp
->nge_port_cnt
= 0;
6822 static int bnxt_set_tpa(struct bnxt
*bp
, bool set_tpa
)
6828 tpa_flags
= bp
->flags
& BNXT_FLAG_TPA
;
6829 for (i
= 0; i
< bp
->nr_vnics
; i
++) {
6830 rc
= bnxt_hwrm_vnic_set_tpa(bp
, i
, tpa_flags
);
6832 netdev_err(bp
->dev
, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
6840 static void bnxt_hwrm_clear_vnic_rss(struct bnxt
*bp
)
6844 for (i
= 0; i
< bp
->nr_vnics
; i
++)
6845 bnxt_hwrm_vnic_set_rss(bp
, i
, false);
6848 static void bnxt_hwrm_resource_free(struct bnxt
*bp
, bool close_path
,
6851 if (bp
->vnic_info
) {
6852 bnxt_hwrm_clear_vnic_filter(bp
);
6853 /* clear all RSS setting before free vnic ctx */
6854 bnxt_hwrm_clear_vnic_rss(bp
);
6855 bnxt_hwrm_vnic_ctx_free(bp
);
6856 /* before free the vnic, undo the vnic tpa settings */
6857 if (bp
->flags
& BNXT_FLAG_TPA
)
6858 bnxt_set_tpa(bp
, false);
6859 bnxt_hwrm_vnic_free(bp
);
6861 bnxt_hwrm_ring_free(bp
, close_path
);
6862 bnxt_hwrm_ring_grp_free(bp
);
6864 bnxt_hwrm_stat_ctx_free(bp
);
6865 bnxt_hwrm_free_tunnel_ports(bp
);
6869 static int bnxt_hwrm_set_br_mode(struct bnxt
*bp
, u16 br_mode
)
6871 struct hwrm_func_cfg_input req
= {0};
6874 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
6875 req
.fid
= cpu_to_le16(0xffff);
6876 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE
);
6877 if (br_mode
== BRIDGE_MODE_VEB
)
6878 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEB
;
6879 else if (br_mode
== BRIDGE_MODE_VEPA
)
6880 req
.evb_mode
= FUNC_CFG_REQ_EVB_MODE_VEPA
;
6883 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6889 static int bnxt_hwrm_set_cache_line_size(struct bnxt
*bp
, int size
)
6891 struct hwrm_func_cfg_input req
= {0};
6894 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10803)
6897 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_CFG
, -1, -1);
6898 req
.fid
= cpu_to_le16(0xffff);
6899 req
.enables
= cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE
);
6900 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64
;
6902 req
.options
= FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128
;
6904 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
6910 static int __bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
6912 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[vnic_id
];
6915 if (vnic
->flags
& BNXT_VNIC_RFS_NEW_RSS_FLAG
)
6918 /* allocate context for vnic */
6919 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 0);
6921 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
6923 goto vnic_setup_err
;
6925 bp
->rsscos_nr_ctxs
++;
6927 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
6928 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, 1);
6930 netdev_err(bp
->dev
, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
6932 goto vnic_setup_err
;
6934 bp
->rsscos_nr_ctxs
++;
6938 /* configure default vnic, ring grp */
6939 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
6941 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
6943 goto vnic_setup_err
;
6946 /* Enable RSS hashing on vnic */
6947 rc
= bnxt_hwrm_vnic_set_rss(bp
, vnic_id
, true);
6949 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %x\n",
6951 goto vnic_setup_err
;
6954 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
6955 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
6957 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
6966 static int __bnxt_setup_vnic_p5(struct bnxt
*bp
, u16 vnic_id
)
6970 nr_ctxs
= DIV_ROUND_UP(bp
->rx_nr_rings
, 64);
6971 for (i
= 0; i
< nr_ctxs
; i
++) {
6972 rc
= bnxt_hwrm_vnic_ctx_alloc(bp
, vnic_id
, i
);
6974 netdev_err(bp
->dev
, "hwrm vnic %d ctx %d alloc failure rc: %x\n",
6978 bp
->rsscos_nr_ctxs
++;
6983 rc
= bnxt_hwrm_vnic_set_rss_p5(bp
, vnic_id
, true);
6985 netdev_err(bp
->dev
, "hwrm vnic %d set rss failure rc: %d\n",
6989 rc
= bnxt_hwrm_vnic_cfg(bp
, vnic_id
);
6991 netdev_err(bp
->dev
, "hwrm vnic %d cfg failure rc: %x\n",
6995 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
) {
6996 rc
= bnxt_hwrm_vnic_set_hds(bp
, vnic_id
);
6998 netdev_err(bp
->dev
, "hwrm vnic %d set hds failure rc: %x\n",
7005 static int bnxt_setup_vnic(struct bnxt
*bp
, u16 vnic_id
)
7007 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7008 return __bnxt_setup_vnic_p5(bp
, vnic_id
);
7010 return __bnxt_setup_vnic(bp
, vnic_id
);
7013 static int bnxt_alloc_rfs_vnics(struct bnxt
*bp
)
7015 #ifdef CONFIG_RFS_ACCEL
7018 for (i
= 0; i
< bp
->rx_nr_rings
; i
++) {
7019 struct bnxt_vnic_info
*vnic
;
7020 u16 vnic_id
= i
+ 1;
7023 if (vnic_id
>= bp
->nr_vnics
)
7026 vnic
= &bp
->vnic_info
[vnic_id
];
7027 vnic
->flags
|= BNXT_VNIC_RFS_FLAG
;
7028 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
7029 vnic
->flags
|= BNXT_VNIC_RFS_NEW_RSS_FLAG
;
7030 rc
= bnxt_hwrm_vnic_alloc(bp
, vnic_id
, ring_id
, 1);
7032 netdev_err(bp
->dev
, "hwrm vnic %d alloc failure rc: %x\n",
7036 rc
= bnxt_setup_vnic(bp
, vnic_id
);
7046 /* Allow PF and VF with default VLAN to be in promiscuous mode */
7047 static bool bnxt_promisc_ok(struct bnxt
*bp
)
7049 #ifdef CONFIG_BNXT_SRIOV
7050 if (BNXT_VF(bp
) && !bp
->vf
.vlan
)
7056 static int bnxt_setup_nitroa0_vnic(struct bnxt
*bp
)
7058 unsigned int rc
= 0;
7060 rc
= bnxt_hwrm_vnic_alloc(bp
, 1, bp
->rx_nr_rings
- 1, 1);
7062 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
7067 rc
= bnxt_hwrm_vnic_cfg(bp
, 1);
7069 netdev_err(bp
->dev
, "Cannot allocate special vnic for NS2 A0: %x\n",
7076 static int bnxt_cfg_rx_mode(struct bnxt
*);
7077 static bool bnxt_mc_list_updated(struct bnxt
*, u32
*);
7079 static int bnxt_init_chip(struct bnxt
*bp
, bool irq_re_init
)
7081 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
7083 unsigned int rx_nr_rings
= bp
->rx_nr_rings
;
7086 rc
= bnxt_hwrm_stat_ctx_alloc(bp
);
7088 netdev_err(bp
->dev
, "hwrm stat ctx alloc failure rc: %x\n",
7094 rc
= bnxt_hwrm_ring_alloc(bp
);
7096 netdev_err(bp
->dev
, "hwrm ring alloc failure rc: %x\n", rc
);
7100 rc
= bnxt_hwrm_ring_grp_alloc(bp
);
7102 netdev_err(bp
->dev
, "hwrm_ring_grp alloc failure: %x\n", rc
);
7106 if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
7109 /* default vnic 0 */
7110 rc
= bnxt_hwrm_vnic_alloc(bp
, 0, 0, rx_nr_rings
);
7112 netdev_err(bp
->dev
, "hwrm vnic alloc failure rc: %x\n", rc
);
7116 rc
= bnxt_setup_vnic(bp
, 0);
7120 if (bp
->flags
& BNXT_FLAG_RFS
) {
7121 rc
= bnxt_alloc_rfs_vnics(bp
);
7126 if (bp
->flags
& BNXT_FLAG_TPA
) {
7127 rc
= bnxt_set_tpa(bp
, true);
7133 bnxt_update_vf_mac(bp
);
7135 /* Filter for default vnic 0 */
7136 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, 0, bp
->dev
->dev_addr
);
7138 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n", rc
);
7141 vnic
->uc_filter_count
= 1;
7144 if (bp
->dev
->flags
& IFF_BROADCAST
)
7145 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
7147 if ((bp
->dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
7148 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
7150 if (bp
->dev
->flags
& IFF_ALLMULTI
) {
7151 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
7152 vnic
->mc_list_count
= 0;
7156 bnxt_mc_list_updated(bp
, &mask
);
7157 vnic
->rx_mask
|= mask
;
7160 rc
= bnxt_cfg_rx_mode(bp
);
7164 rc
= bnxt_hwrm_set_coal(bp
);
7166 netdev_warn(bp
->dev
, "HWRM set coalescing failure rc: %x\n",
7169 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
7170 rc
= bnxt_setup_nitroa0_vnic(bp
);
7172 netdev_err(bp
->dev
, "Special vnic setup failure for NS2 A0 rc: %x\n",
7177 bnxt_hwrm_func_qcfg(bp
);
7178 netdev_update_features(bp
->dev
);
7184 bnxt_hwrm_resource_free(bp
, 0, true);
7189 static int bnxt_shutdown_nic(struct bnxt
*bp
, bool irq_re_init
)
7191 bnxt_hwrm_resource_free(bp
, 1, irq_re_init
);
7195 static int bnxt_init_nic(struct bnxt
*bp
, bool irq_re_init
)
7197 bnxt_init_cp_rings(bp
);
7198 bnxt_init_rx_rings(bp
);
7199 bnxt_init_tx_rings(bp
);
7200 bnxt_init_ring_grps(bp
, irq_re_init
);
7201 bnxt_init_vnics(bp
);
7203 return bnxt_init_chip(bp
, irq_re_init
);
7206 static int bnxt_set_real_num_queues(struct bnxt
*bp
)
7209 struct net_device
*dev
= bp
->dev
;
7211 rc
= netif_set_real_num_tx_queues(dev
, bp
->tx_nr_rings
-
7212 bp
->tx_nr_rings_xdp
);
7216 rc
= netif_set_real_num_rx_queues(dev
, bp
->rx_nr_rings
);
7220 #ifdef CONFIG_RFS_ACCEL
7221 if (bp
->flags
& BNXT_FLAG_RFS
)
7222 dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(bp
->rx_nr_rings
);
7228 static int bnxt_trim_rings(struct bnxt
*bp
, int *rx
, int *tx
, int max
,
7231 int _rx
= *rx
, _tx
= *tx
;
7234 *rx
= min_t(int, _rx
, max
);
7235 *tx
= min_t(int, _tx
, max
);
7240 while (_rx
+ _tx
> max
) {
7241 if (_rx
> _tx
&& _rx
> 1)
7252 static void bnxt_setup_msix(struct bnxt
*bp
)
7254 const int len
= sizeof(bp
->irq_tbl
[0].name
);
7255 struct net_device
*dev
= bp
->dev
;
7258 tcs
= netdev_get_num_tc(dev
);
7262 for (i
= 0; i
< tcs
; i
++) {
7263 count
= bp
->tx_nr_rings_per_tc
;
7265 netdev_set_tc_queue(dev
, i
, count
, off
);
7269 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7270 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
7273 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
7275 else if (i
< bp
->rx_nr_rings
)
7280 snprintf(bp
->irq_tbl
[map_idx
].name
, len
, "%s-%s-%d", dev
->name
,
7282 bp
->irq_tbl
[map_idx
].handler
= bnxt_msix
;
7286 static void bnxt_setup_inta(struct bnxt
*bp
)
7288 const int len
= sizeof(bp
->irq_tbl
[0].name
);
7290 if (netdev_get_num_tc(bp
->dev
))
7291 netdev_reset_tc(bp
->dev
);
7293 snprintf(bp
->irq_tbl
[0].name
, len
, "%s-%s-%d", bp
->dev
->name
, "TxRx",
7295 bp
->irq_tbl
[0].handler
= bnxt_inta
;
7298 static int bnxt_setup_int_mode(struct bnxt
*bp
)
7302 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
7303 bnxt_setup_msix(bp
);
7305 bnxt_setup_inta(bp
);
7307 rc
= bnxt_set_real_num_queues(bp
);
7311 #ifdef CONFIG_RFS_ACCEL
7312 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt
*bp
)
7314 return bp
->hw_resc
.max_rsscos_ctxs
;
7317 static unsigned int bnxt_get_max_func_vnics(struct bnxt
*bp
)
7319 return bp
->hw_resc
.max_vnics
;
7323 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt
*bp
)
7325 return bp
->hw_resc
.max_stat_ctxs
;
7328 unsigned int bnxt_get_max_func_cp_rings(struct bnxt
*bp
)
7330 return bp
->hw_resc
.max_cp_rings
;
7333 static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt
*bp
)
7335 unsigned int cp
= bp
->hw_resc
.max_cp_rings
;
7337 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
7338 cp
-= bnxt_get_ulp_msix_num(bp
);
7343 static unsigned int bnxt_get_max_func_irqs(struct bnxt
*bp
)
7345 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
7347 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7348 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_nqs
);
7350 return min_t(unsigned int, hw_resc
->max_irqs
, hw_resc
->max_cp_rings
);
7353 static void bnxt_set_max_func_irqs(struct bnxt
*bp
, unsigned int max_irqs
)
7355 bp
->hw_resc
.max_irqs
= max_irqs
;
7358 unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt
*bp
)
7362 cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
7363 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7364 return cp
- bp
->rx_nr_rings
- bp
->tx_nr_rings
;
7366 return cp
- bp
->cp_nr_rings
;
7369 unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt
*bp
)
7373 stat
= bnxt_get_max_func_stat_ctxs(bp
) - bnxt_get_ulp_stat_ctxs(bp
);
7374 stat
-= bp
->cp_nr_rings
;
7378 int bnxt_get_avail_msix(struct bnxt
*bp
, int num
)
7380 int max_cp
= bnxt_get_max_func_cp_rings(bp
);
7381 int max_irq
= bnxt_get_max_func_irqs(bp
);
7382 int total_req
= bp
->cp_nr_rings
+ num
;
7383 int max_idx
, avail_msix
;
7385 max_idx
= bp
->total_irqs
;
7386 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
7387 max_idx
= min_t(int, bp
->total_irqs
, max_cp
);
7388 avail_msix
= max_idx
- bp
->cp_nr_rings
;
7389 if (!BNXT_NEW_RM(bp
) || avail_msix
>= num
)
7392 if (max_irq
< total_req
) {
7393 num
= max_irq
- bp
->cp_nr_rings
;
7400 static int bnxt_get_num_msix(struct bnxt
*bp
)
7402 if (!BNXT_NEW_RM(bp
))
7403 return bnxt_get_max_func_irqs(bp
);
7405 return bnxt_nq_rings_in_use(bp
);
7408 static int bnxt_init_msix(struct bnxt
*bp
)
7410 int i
, total_vecs
, max
, rc
= 0, min
= 1, ulp_msix
;
7411 struct msix_entry
*msix_ent
;
7413 total_vecs
= bnxt_get_num_msix(bp
);
7414 max
= bnxt_get_max_func_irqs(bp
);
7415 if (total_vecs
> max
)
7421 msix_ent
= kcalloc(total_vecs
, sizeof(struct msix_entry
), GFP_KERNEL
);
7425 for (i
= 0; i
< total_vecs
; i
++) {
7426 msix_ent
[i
].entry
= i
;
7427 msix_ent
[i
].vector
= 0;
7430 if (!(bp
->flags
& BNXT_FLAG_SHARED_RINGS
))
7433 total_vecs
= pci_enable_msix_range(bp
->pdev
, msix_ent
, min
, total_vecs
);
7434 ulp_msix
= bnxt_get_ulp_msix_num(bp
);
7435 if (total_vecs
< 0 || total_vecs
< ulp_msix
) {
7437 goto msix_setup_exit
;
7440 bp
->irq_tbl
= kcalloc(total_vecs
, sizeof(struct bnxt_irq
), GFP_KERNEL
);
7442 for (i
= 0; i
< total_vecs
; i
++)
7443 bp
->irq_tbl
[i
].vector
= msix_ent
[i
].vector
;
7445 bp
->total_irqs
= total_vecs
;
7446 /* Trim rings based upon num of vectors allocated */
7447 rc
= bnxt_trim_rings(bp
, &bp
->rx_nr_rings
, &bp
->tx_nr_rings
,
7448 total_vecs
- ulp_msix
, min
== 1);
7450 goto msix_setup_exit
;
7452 bp
->cp_nr_rings
= (min
== 1) ?
7453 max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
7454 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
7458 goto msix_setup_exit
;
7460 bp
->flags
|= BNXT_FLAG_USING_MSIX
;
7465 netdev_err(bp
->dev
, "bnxt_init_msix err: %x\n", rc
);
7468 pci_disable_msix(bp
->pdev
);
7473 static int bnxt_init_inta(struct bnxt
*bp
)
7475 bp
->irq_tbl
= kcalloc(1, sizeof(struct bnxt_irq
), GFP_KERNEL
);
7480 bp
->rx_nr_rings
= 1;
7481 bp
->tx_nr_rings
= 1;
7482 bp
->cp_nr_rings
= 1;
7483 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
7484 bp
->irq_tbl
[0].vector
= bp
->pdev
->irq
;
7488 static int bnxt_init_int_mode(struct bnxt
*bp
)
7492 if (bp
->flags
& BNXT_FLAG_MSIX_CAP
)
7493 rc
= bnxt_init_msix(bp
);
7495 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
) && BNXT_PF(bp
)) {
7496 /* fallback to INTA */
7497 rc
= bnxt_init_inta(bp
);
7502 static void bnxt_clear_int_mode(struct bnxt
*bp
)
7504 if (bp
->flags
& BNXT_FLAG_USING_MSIX
)
7505 pci_disable_msix(bp
->pdev
);
7509 bp
->flags
&= ~BNXT_FLAG_USING_MSIX
;
7512 int bnxt_reserve_rings(struct bnxt
*bp
)
7514 int tcs
= netdev_get_num_tc(bp
->dev
);
7515 bool reinit_irq
= false;
7518 if (!bnxt_need_reserve_rings(bp
))
7521 if (BNXT_NEW_RM(bp
) && (bnxt_get_num_msix(bp
) != bp
->total_irqs
)) {
7522 bnxt_ulp_irq_stop(bp
);
7523 bnxt_clear_int_mode(bp
);
7526 rc
= __bnxt_reserve_rings(bp
);
7529 rc
= bnxt_init_int_mode(bp
);
7530 bnxt_ulp_irq_restart(bp
, rc
);
7533 netdev_err(bp
->dev
, "ring reservation/IRQ init failure rc: %d\n", rc
);
7536 if (tcs
&& (bp
->tx_nr_rings_per_tc
* tcs
!= bp
->tx_nr_rings
)) {
7537 netdev_err(bp
->dev
, "tx ring reservation failure\n");
7538 netdev_reset_tc(bp
->dev
);
7539 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
7545 static void bnxt_free_irq(struct bnxt
*bp
)
7547 struct bnxt_irq
*irq
;
7550 #ifdef CONFIG_RFS_ACCEL
7551 free_irq_cpu_rmap(bp
->dev
->rx_cpu_rmap
);
7552 bp
->dev
->rx_cpu_rmap
= NULL
;
7554 if (!bp
->irq_tbl
|| !bp
->bnapi
)
7557 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7558 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
7560 irq
= &bp
->irq_tbl
[map_idx
];
7561 if (irq
->requested
) {
7562 if (irq
->have_cpumask
) {
7563 irq_set_affinity_hint(irq
->vector
, NULL
);
7564 free_cpumask_var(irq
->cpu_mask
);
7565 irq
->have_cpumask
= 0;
7567 free_irq(irq
->vector
, bp
->bnapi
[i
]);
7574 static int bnxt_request_irq(struct bnxt
*bp
)
7577 unsigned long flags
= 0;
7578 #ifdef CONFIG_RFS_ACCEL
7579 struct cpu_rmap
*rmap
;
7582 rc
= bnxt_setup_int_mode(bp
);
7584 netdev_err(bp
->dev
, "bnxt_setup_int_mode err: %x\n",
7588 #ifdef CONFIG_RFS_ACCEL
7589 rmap
= bp
->dev
->rx_cpu_rmap
;
7591 if (!(bp
->flags
& BNXT_FLAG_USING_MSIX
))
7592 flags
= IRQF_SHARED
;
7594 for (i
= 0, j
= 0; i
< bp
->cp_nr_rings
; i
++) {
7595 int map_idx
= bnxt_cp_num_to_irq_num(bp
, i
);
7596 struct bnxt_irq
*irq
= &bp
->irq_tbl
[map_idx
];
7598 #ifdef CONFIG_RFS_ACCEL
7599 if (rmap
&& bp
->bnapi
[i
]->rx_ring
) {
7600 rc
= irq_cpu_rmap_add(rmap
, irq
->vector
);
7602 netdev_warn(bp
->dev
, "failed adding irq rmap for ring %d\n",
7607 rc
= request_irq(irq
->vector
, irq
->handler
, flags
, irq
->name
,
7614 if (zalloc_cpumask_var(&irq
->cpu_mask
, GFP_KERNEL
)) {
7615 int numa_node
= dev_to_node(&bp
->pdev
->dev
);
7617 irq
->have_cpumask
= 1;
7618 cpumask_set_cpu(cpumask_local_spread(i
, numa_node
),
7620 rc
= irq_set_affinity_hint(irq
->vector
, irq
->cpu_mask
);
7622 netdev_warn(bp
->dev
,
7623 "Set affinity failed, IRQ = %d\n",
7632 static void bnxt_del_napi(struct bnxt
*bp
)
7639 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7640 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
7642 napi_hash_del(&bnapi
->napi
);
7643 netif_napi_del(&bnapi
->napi
);
7645 /* We called napi_hash_del() before netif_napi_del(), we need
7646 * to respect an RCU grace period before freeing napi structures.
7651 static void bnxt_init_napi(struct bnxt
*bp
)
7654 unsigned int cp_nr_rings
= bp
->cp_nr_rings
;
7655 struct bnxt_napi
*bnapi
;
7657 if (bp
->flags
& BNXT_FLAG_USING_MSIX
) {
7658 int (*poll_fn
)(struct napi_struct
*, int) = bnxt_poll
;
7660 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
7661 poll_fn
= bnxt_poll_p5
;
7662 else if (BNXT_CHIP_TYPE_NITRO_A0(bp
))
7664 for (i
= 0; i
< cp_nr_rings
; i
++) {
7665 bnapi
= bp
->bnapi
[i
];
7666 netif_napi_add(bp
->dev
, &bnapi
->napi
, poll_fn
, 64);
7668 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
7669 bnapi
= bp
->bnapi
[cp_nr_rings
];
7670 netif_napi_add(bp
->dev
, &bnapi
->napi
,
7671 bnxt_poll_nitroa0
, 64);
7674 bnapi
= bp
->bnapi
[0];
7675 netif_napi_add(bp
->dev
, &bnapi
->napi
, bnxt_poll
, 64);
7679 static void bnxt_disable_napi(struct bnxt
*bp
)
7686 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7687 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
7689 if (bp
->bnapi
[i
]->rx_ring
)
7690 cancel_work_sync(&cpr
->dim
.work
);
7692 napi_disable(&bp
->bnapi
[i
]->napi
);
7696 static void bnxt_enable_napi(struct bnxt
*bp
)
7700 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
7701 struct bnxt_cp_ring_info
*cpr
= &bp
->bnapi
[i
]->cp_ring
;
7702 bp
->bnapi
[i
]->in_reset
= false;
7704 if (bp
->bnapi
[i
]->rx_ring
) {
7705 INIT_WORK(&cpr
->dim
.work
, bnxt_dim_work
);
7706 cpr
->dim
.mode
= NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE
;
7708 napi_enable(&bp
->bnapi
[i
]->napi
);
7712 void bnxt_tx_disable(struct bnxt
*bp
)
7715 struct bnxt_tx_ring_info
*txr
;
7718 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
7719 txr
= &bp
->tx_ring
[i
];
7720 txr
->dev_state
= BNXT_DEV_STATE_CLOSING
;
7723 /* Stop all TX queues */
7724 netif_tx_disable(bp
->dev
);
7725 netif_carrier_off(bp
->dev
);
7728 void bnxt_tx_enable(struct bnxt
*bp
)
7731 struct bnxt_tx_ring_info
*txr
;
7733 for (i
= 0; i
< bp
->tx_nr_rings
; i
++) {
7734 txr
= &bp
->tx_ring
[i
];
7737 netif_tx_wake_all_queues(bp
->dev
);
7738 if (bp
->link_info
.link_up
)
7739 netif_carrier_on(bp
->dev
);
7742 static void bnxt_report_link(struct bnxt
*bp
)
7744 if (bp
->link_info
.link_up
) {
7746 const char *flow_ctrl
;
7750 netif_carrier_on(bp
->dev
);
7751 if (bp
->link_info
.duplex
== BNXT_LINK_DUPLEX_FULL
)
7755 if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_BOTH
)
7756 flow_ctrl
= "ON - receive & transmit";
7757 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_TX
)
7758 flow_ctrl
= "ON - transmit";
7759 else if (bp
->link_info
.pause
== BNXT_LINK_PAUSE_RX
)
7760 flow_ctrl
= "ON - receive";
7763 speed
= bnxt_fw_to_ethtool_speed(bp
->link_info
.link_speed
);
7764 netdev_info(bp
->dev
, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
7765 speed
, duplex
, flow_ctrl
);
7766 if (bp
->flags
& BNXT_FLAG_EEE_CAP
)
7767 netdev_info(bp
->dev
, "EEE is %s\n",
7768 bp
->eee
.eee_active
? "active" :
7770 fec
= bp
->link_info
.fec_cfg
;
7771 if (!(fec
& PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
))
7772 netdev_info(bp
->dev
, "FEC autoneg %s encodings: %s\n",
7773 (fec
& BNXT_FEC_AUTONEG
) ? "on" : "off",
7774 (fec
& BNXT_FEC_ENC_BASE_R
) ? "BaseR" :
7775 (fec
& BNXT_FEC_ENC_RS
) ? "RS" : "None");
7777 netif_carrier_off(bp
->dev
);
7778 netdev_err(bp
->dev
, "NIC Link is Down\n");
7782 static int bnxt_hwrm_phy_qcaps(struct bnxt
*bp
)
7785 struct hwrm_port_phy_qcaps_input req
= {0};
7786 struct hwrm_port_phy_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7787 struct bnxt_link_info
*link_info
= &bp
->link_info
;
7789 if (bp
->hwrm_spec_code
< 0x10201)
7792 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCAPS
, -1, -1);
7794 mutex_lock(&bp
->hwrm_cmd_lock
);
7795 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7797 goto hwrm_phy_qcaps_exit
;
7799 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED
) {
7800 struct ethtool_eee
*eee
= &bp
->eee
;
7801 u16 fw_speeds
= le16_to_cpu(resp
->supported_speeds_eee_mode
);
7803 bp
->flags
|= BNXT_FLAG_EEE_CAP
;
7804 eee
->supported
= _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
7805 bp
->lpi_tmr_lo
= le32_to_cpu(resp
->tx_lpi_timer_low
) &
7806 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK
;
7807 bp
->lpi_tmr_hi
= le32_to_cpu(resp
->valid_tx_lpi_timer_high
) &
7808 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK
;
7810 if (resp
->flags
& PORT_PHY_QCAPS_RESP_FLAGS_EXTERNAL_LPBK_SUPPORTED
) {
7812 bp
->test_info
->flags
|= BNXT_TEST_FL_EXT_LPBK
;
7814 if (resp
->supported_speeds_auto_mode
)
7815 link_info
->support_auto_speeds
=
7816 le16_to_cpu(resp
->supported_speeds_auto_mode
);
7818 bp
->port_count
= resp
->port_cnt
;
7820 hwrm_phy_qcaps_exit
:
7821 mutex_unlock(&bp
->hwrm_cmd_lock
);
7825 static int bnxt_update_link(struct bnxt
*bp
, bool chng_link_state
)
7828 struct bnxt_link_info
*link_info
= &bp
->link_info
;
7829 struct hwrm_port_phy_qcfg_input req
= {0};
7830 struct hwrm_port_phy_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
7831 u8 link_up
= link_info
->link_up
;
7834 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_QCFG
, -1, -1);
7836 mutex_lock(&bp
->hwrm_cmd_lock
);
7837 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
7839 mutex_unlock(&bp
->hwrm_cmd_lock
);
7843 memcpy(&link_info
->phy_qcfg_resp
, resp
, sizeof(*resp
));
7844 link_info
->phy_link_status
= resp
->link
;
7845 link_info
->duplex
= resp
->duplex_cfg
;
7846 if (bp
->hwrm_spec_code
>= 0x10800)
7847 link_info
->duplex
= resp
->duplex_state
;
7848 link_info
->pause
= resp
->pause
;
7849 link_info
->auto_mode
= resp
->auto_mode
;
7850 link_info
->auto_pause_setting
= resp
->auto_pause
;
7851 link_info
->lp_pause
= resp
->link_partner_adv_pause
;
7852 link_info
->force_pause_setting
= resp
->force_pause
;
7853 link_info
->duplex_setting
= resp
->duplex_cfg
;
7854 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
7855 link_info
->link_speed
= le16_to_cpu(resp
->link_speed
);
7857 link_info
->link_speed
= 0;
7858 link_info
->force_link_speed
= le16_to_cpu(resp
->force_link_speed
);
7859 link_info
->support_speeds
= le16_to_cpu(resp
->support_speeds
);
7860 link_info
->auto_link_speeds
= le16_to_cpu(resp
->auto_link_speed_mask
);
7861 link_info
->lp_auto_link_speeds
=
7862 le16_to_cpu(resp
->link_partner_adv_speeds
);
7863 link_info
->preemphasis
= le32_to_cpu(resp
->preemphasis
);
7864 link_info
->phy_ver
[0] = resp
->phy_maj
;
7865 link_info
->phy_ver
[1] = resp
->phy_min
;
7866 link_info
->phy_ver
[2] = resp
->phy_bld
;
7867 link_info
->media_type
= resp
->media_type
;
7868 link_info
->phy_type
= resp
->phy_type
;
7869 link_info
->transceiver
= resp
->xcvr_pkg_type
;
7870 link_info
->phy_addr
= resp
->eee_config_phy_addr
&
7871 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK
;
7872 link_info
->module_status
= resp
->module_status
;
7874 if (bp
->flags
& BNXT_FLAG_EEE_CAP
) {
7875 struct ethtool_eee
*eee
= &bp
->eee
;
7878 eee
->eee_active
= 0;
7879 if (resp
->eee_config_phy_addr
&
7880 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE
) {
7881 eee
->eee_active
= 1;
7882 fw_speeds
= le16_to_cpu(
7883 resp
->link_partner_adv_eee_link_speed_mask
);
7884 eee
->lp_advertised
=
7885 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
7888 /* Pull initial EEE config */
7889 if (!chng_link_state
) {
7890 if (resp
->eee_config_phy_addr
&
7891 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED
)
7892 eee
->eee_enabled
= 1;
7894 fw_speeds
= le16_to_cpu(resp
->adv_eee_link_speed_mask
);
7896 _bnxt_fw_to_ethtool_adv_spds(fw_speeds
, 0);
7898 if (resp
->eee_config_phy_addr
&
7899 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI
) {
7902 eee
->tx_lpi_enabled
= 1;
7903 tmr
= resp
->xcvr_identifier_type_tx_lpi_timer
;
7904 eee
->tx_lpi_timer
= le32_to_cpu(tmr
) &
7905 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK
;
7910 link_info
->fec_cfg
= PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED
;
7911 if (bp
->hwrm_spec_code
>= 0x10504)
7912 link_info
->fec_cfg
= le16_to_cpu(resp
->fec_cfg
);
7914 /* TODO: need to add more logic to report VF link */
7915 if (chng_link_state
) {
7916 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
7917 link_info
->link_up
= 1;
7919 link_info
->link_up
= 0;
7920 if (link_up
!= link_info
->link_up
)
7921 bnxt_report_link(bp
);
7923 /* alwasy link down if not require to update link state */
7924 link_info
->link_up
= 0;
7926 mutex_unlock(&bp
->hwrm_cmd_lock
);
7928 if (!BNXT_SINGLE_PF(bp
))
7931 diff
= link_info
->support_auto_speeds
^ link_info
->advertising
;
7932 if ((link_info
->support_auto_speeds
| diff
) !=
7933 link_info
->support_auto_speeds
) {
7934 /* An advertised speed is no longer supported, so we need to
7935 * update the advertisement settings. Caller holds RTNL
7936 * so we can modify link settings.
7938 link_info
->advertising
= link_info
->support_auto_speeds
;
7939 if (link_info
->autoneg
& BNXT_AUTONEG_SPEED
)
7940 bnxt_hwrm_set_link_setting(bp
, true, false);
7945 static void bnxt_get_port_module_status(struct bnxt
*bp
)
7947 struct bnxt_link_info
*link_info
= &bp
->link_info
;
7948 struct hwrm_port_phy_qcfg_output
*resp
= &link_info
->phy_qcfg_resp
;
7951 if (bnxt_update_link(bp
, true))
7954 module_status
= link_info
->module_status
;
7955 switch (module_status
) {
7956 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
:
7957 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
:
7958 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
:
7959 netdev_warn(bp
->dev
, "Unqualified SFP+ module detected on port %d\n",
7961 if (bp
->hwrm_spec_code
>= 0x10201) {
7962 netdev_warn(bp
->dev
, "Module part number %s\n",
7963 resp
->phy_vendor_partnumber
);
7965 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX
)
7966 netdev_warn(bp
->dev
, "TX is disabled\n");
7967 if (module_status
== PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN
)
7968 netdev_warn(bp
->dev
, "SFP+ module is shutdown\n");
7973 bnxt_hwrm_set_pause_common(struct bnxt
*bp
, struct hwrm_port_phy_cfg_input
*req
)
7975 if (bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) {
7976 if (bp
->hwrm_spec_code
>= 0x10201)
7978 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
7979 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
7980 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX
;
7981 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
7982 req
->auto_pause
|= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX
;
7984 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
7986 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_RX
)
7987 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX
;
7988 if (bp
->link_info
.req_flow_ctrl
& BNXT_LINK_PAUSE_TX
)
7989 req
->force_pause
|= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX
;
7991 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE
);
7992 if (bp
->hwrm_spec_code
>= 0x10201) {
7993 req
->auto_pause
= req
->force_pause
;
7994 req
->enables
|= cpu_to_le32(
7995 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE
);
8000 static void bnxt_hwrm_set_link_common(struct bnxt
*bp
,
8001 struct hwrm_port_phy_cfg_input
*req
)
8003 u8 autoneg
= bp
->link_info
.autoneg
;
8004 u16 fw_link_speed
= bp
->link_info
.req_link_speed
;
8005 u16 advertising
= bp
->link_info
.advertising
;
8007 if (autoneg
& BNXT_AUTONEG_SPEED
) {
8009 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK
;
8011 req
->enables
|= cpu_to_le32(
8012 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK
);
8013 req
->auto_link_speed_mask
= cpu_to_le16(advertising
);
8015 req
->enables
|= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE
);
8017 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG
);
8019 req
->force_link_speed
= cpu_to_le16(fw_link_speed
);
8020 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE
);
8023 /* tell chimp that the setting takes effect immediately */
8024 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY
);
8027 int bnxt_hwrm_set_pause(struct bnxt
*bp
)
8029 struct hwrm_port_phy_cfg_input req
= {0};
8032 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8033 bnxt_hwrm_set_pause_common(bp
, &req
);
8035 if ((bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
) ||
8036 bp
->link_info
.force_link_chng
)
8037 bnxt_hwrm_set_link_common(bp
, &req
);
8039 mutex_lock(&bp
->hwrm_cmd_lock
);
8040 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8041 if (!rc
&& !(bp
->link_info
.autoneg
& BNXT_AUTONEG_FLOW_CTRL
)) {
8042 /* since changing of pause setting doesn't trigger any link
8043 * change event, the driver needs to update the current pause
8044 * result upon successfully return of the phy_cfg command
8046 bp
->link_info
.pause
=
8047 bp
->link_info
.force_pause_setting
= bp
->link_info
.req_flow_ctrl
;
8048 bp
->link_info
.auto_pause_setting
= 0;
8049 if (!bp
->link_info
.force_link_chng
)
8050 bnxt_report_link(bp
);
8052 bp
->link_info
.force_link_chng
= false;
8053 mutex_unlock(&bp
->hwrm_cmd_lock
);
8057 static void bnxt_hwrm_set_eee(struct bnxt
*bp
,
8058 struct hwrm_port_phy_cfg_input
*req
)
8060 struct ethtool_eee
*eee
= &bp
->eee
;
8062 if (eee
->eee_enabled
) {
8064 u32 flags
= PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE
;
8066 if (eee
->tx_lpi_enabled
)
8067 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE
;
8069 flags
|= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE
;
8071 req
->flags
|= cpu_to_le32(flags
);
8072 eee_speeds
= bnxt_get_fw_auto_link_speeds(eee
->advertised
);
8073 req
->eee_link_speed_mask
= cpu_to_le16(eee_speeds
);
8074 req
->tx_lpi_timer
= cpu_to_le32(eee
->tx_lpi_timer
);
8076 req
->flags
|= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE
);
8080 int bnxt_hwrm_set_link_setting(struct bnxt
*bp
, bool set_pause
, bool set_eee
)
8082 struct hwrm_port_phy_cfg_input req
= {0};
8084 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8086 bnxt_hwrm_set_pause_common(bp
, &req
);
8088 bnxt_hwrm_set_link_common(bp
, &req
);
8091 bnxt_hwrm_set_eee(bp
, &req
);
8092 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8095 static int bnxt_hwrm_shutdown_link(struct bnxt
*bp
)
8097 struct hwrm_port_phy_cfg_input req
= {0};
8099 if (!BNXT_SINGLE_PF(bp
))
8102 if (pci_num_vf(bp
->pdev
))
8105 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_CFG
, -1, -1);
8106 req
.flags
= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN
);
8107 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8110 static int bnxt_hwrm_if_change(struct bnxt
*bp
, bool up
)
8112 struct hwrm_func_drv_if_change_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8113 struct hwrm_func_drv_if_change_input req
= {0};
8114 bool resc_reinit
= false;
8117 if (!(bp
->fw_cap
& BNXT_FW_CAP_IF_CHANGE
))
8120 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FUNC_DRV_IF_CHANGE
, -1, -1);
8122 req
.flags
= cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP
);
8123 mutex_lock(&bp
->hwrm_cmd_lock
);
8124 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8125 if (!rc
&& (resp
->flags
&
8126 cpu_to_le32(FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE
)))
8128 mutex_unlock(&bp
->hwrm_cmd_lock
);
8130 if (up
&& resc_reinit
&& BNXT_NEW_RM(bp
)) {
8131 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
8133 rc
= bnxt_hwrm_func_resc_qcaps(bp
, true);
8134 hw_resc
->resv_cp_rings
= 0;
8135 hw_resc
->resv_stat_ctxs
= 0;
8136 hw_resc
->resv_irqs
= 0;
8137 hw_resc
->resv_tx_rings
= 0;
8138 hw_resc
->resv_rx_rings
= 0;
8139 hw_resc
->resv_hw_ring_grps
= 0;
8140 hw_resc
->resv_vnics
= 0;
8141 bp
->tx_nr_rings
= 0;
8142 bp
->rx_nr_rings
= 0;
8147 static int bnxt_hwrm_port_led_qcaps(struct bnxt
*bp
)
8149 struct hwrm_port_led_qcaps_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8150 struct hwrm_port_led_qcaps_input req
= {0};
8151 struct bnxt_pf_info
*pf
= &bp
->pf
;
8154 if (BNXT_VF(bp
) || bp
->hwrm_spec_code
< 0x10601)
8157 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_LED_QCAPS
, -1, -1);
8158 req
.port_id
= cpu_to_le16(pf
->port_id
);
8159 mutex_lock(&bp
->hwrm_cmd_lock
);
8160 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8162 mutex_unlock(&bp
->hwrm_cmd_lock
);
8165 if (resp
->num_leds
> 0 && resp
->num_leds
< BNXT_MAX_LED
) {
8168 bp
->num_leds
= resp
->num_leds
;
8169 memcpy(bp
->leds
, &resp
->led0_id
, sizeof(bp
->leds
[0]) *
8171 for (i
= 0; i
< bp
->num_leds
; i
++) {
8172 struct bnxt_led_info
*led
= &bp
->leds
[i
];
8173 __le16 caps
= led
->led_state_caps
;
8175 if (!led
->led_group_id
||
8176 !BNXT_LED_ALT_BLINK_CAP(caps
)) {
8182 mutex_unlock(&bp
->hwrm_cmd_lock
);
8186 int bnxt_hwrm_alloc_wol_fltr(struct bnxt
*bp
)
8188 struct hwrm_wol_filter_alloc_input req
= {0};
8189 struct hwrm_wol_filter_alloc_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8192 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_ALLOC
, -1, -1);
8193 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8194 req
.wol_type
= WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
;
8195 req
.enables
= cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS
);
8196 memcpy(req
.mac_address
, bp
->dev
->dev_addr
, ETH_ALEN
);
8197 mutex_lock(&bp
->hwrm_cmd_lock
);
8198 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8200 bp
->wol_filter_id
= resp
->wol_filter_id
;
8201 mutex_unlock(&bp
->hwrm_cmd_lock
);
8205 int bnxt_hwrm_free_wol_fltr(struct bnxt
*bp
)
8207 struct hwrm_wol_filter_free_input req
= {0};
8210 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_FREE
, -1, -1);
8211 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8212 req
.enables
= cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID
);
8213 req
.wol_filter_id
= bp
->wol_filter_id
;
8214 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8218 static u16
bnxt_hwrm_get_wol_fltrs(struct bnxt
*bp
, u16 handle
)
8220 struct hwrm_wol_filter_qcfg_input req
= {0};
8221 struct hwrm_wol_filter_qcfg_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8222 u16 next_handle
= 0;
8225 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_WOL_FILTER_QCFG
, -1, -1);
8226 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8227 req
.handle
= cpu_to_le16(handle
);
8228 mutex_lock(&bp
->hwrm_cmd_lock
);
8229 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8231 next_handle
= le16_to_cpu(resp
->next_handle
);
8232 if (next_handle
!= 0) {
8233 if (resp
->wol_type
==
8234 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT
) {
8236 bp
->wol_filter_id
= resp
->wol_filter_id
;
8240 mutex_unlock(&bp
->hwrm_cmd_lock
);
8244 static void bnxt_get_wol_settings(struct bnxt
*bp
)
8248 if (!BNXT_PF(bp
) || !(bp
->flags
& BNXT_FLAG_WOL_CAP
))
8252 handle
= bnxt_hwrm_get_wol_fltrs(bp
, handle
);
8253 } while (handle
&& handle
!= 0xffff);
8256 #ifdef CONFIG_BNXT_HWMON
8257 static ssize_t
bnxt_show_temp(struct device
*dev
,
8258 struct device_attribute
*devattr
, char *buf
)
8260 struct hwrm_temp_monitor_query_input req
= {0};
8261 struct hwrm_temp_monitor_query_output
*resp
;
8262 struct bnxt
*bp
= dev_get_drvdata(dev
);
8265 resp
= bp
->hwrm_cmd_resp_addr
;
8266 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_TEMP_MONITOR_QUERY
, -1, -1);
8267 mutex_lock(&bp
->hwrm_cmd_lock
);
8268 if (!_hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
))
8269 temp
= resp
->temp
* 1000; /* display millidegree */
8270 mutex_unlock(&bp
->hwrm_cmd_lock
);
8272 return sprintf(buf
, "%u\n", temp
);
8274 static SENSOR_DEVICE_ATTR(temp1_input
, 0444, bnxt_show_temp
, NULL
, 0);
8276 static struct attribute
*bnxt_attrs
[] = {
8277 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
8280 ATTRIBUTE_GROUPS(bnxt
);
8282 static void bnxt_hwmon_close(struct bnxt
*bp
)
8284 if (bp
->hwmon_dev
) {
8285 hwmon_device_unregister(bp
->hwmon_dev
);
8286 bp
->hwmon_dev
= NULL
;
8290 static void bnxt_hwmon_open(struct bnxt
*bp
)
8292 struct pci_dev
*pdev
= bp
->pdev
;
8294 bp
->hwmon_dev
= hwmon_device_register_with_groups(&pdev
->dev
,
8295 DRV_MODULE_NAME
, bp
,
8297 if (IS_ERR(bp
->hwmon_dev
)) {
8298 bp
->hwmon_dev
= NULL
;
8299 dev_warn(&pdev
->dev
, "Cannot register hwmon device\n");
8303 static void bnxt_hwmon_close(struct bnxt
*bp
)
8307 static void bnxt_hwmon_open(struct bnxt
*bp
)
8312 static bool bnxt_eee_config_ok(struct bnxt
*bp
)
8314 struct ethtool_eee
*eee
= &bp
->eee
;
8315 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8317 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
8320 if (eee
->eee_enabled
) {
8322 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
8324 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
8325 eee
->eee_enabled
= 0;
8328 if (eee
->advertised
& ~advertising
) {
8329 eee
->advertised
= advertising
& eee
->supported
;
8336 static int bnxt_update_phy_setting(struct bnxt
*bp
)
8339 bool update_link
= false;
8340 bool update_pause
= false;
8341 bool update_eee
= false;
8342 struct bnxt_link_info
*link_info
= &bp
->link_info
;
8344 rc
= bnxt_update_link(bp
, true);
8346 netdev_err(bp
->dev
, "failed to update link (rc: %x)\n",
8350 if (!BNXT_SINGLE_PF(bp
))
8353 if ((link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
8354 (link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
) !=
8355 link_info
->req_flow_ctrl
)
8356 update_pause
= true;
8357 if (!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
) &&
8358 link_info
->force_pause_setting
!= link_info
->req_flow_ctrl
)
8359 update_pause
= true;
8360 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
8361 if (BNXT_AUTO_MODE(link_info
->auto_mode
))
8363 if (link_info
->req_link_speed
!= link_info
->force_link_speed
)
8365 if (link_info
->req_duplex
!= link_info
->duplex_setting
)
8368 if (link_info
->auto_mode
== BNXT_LINK_AUTO_NONE
)
8370 if (link_info
->advertising
!= link_info
->auto_link_speeds
)
8374 /* The last close may have shutdown the link, so need to call
8375 * PHY_CFG to bring it back up.
8377 if (!netif_carrier_ok(bp
->dev
))
8380 if (!bnxt_eee_config_ok(bp
))
8384 rc
= bnxt_hwrm_set_link_setting(bp
, update_pause
, update_eee
);
8385 else if (update_pause
)
8386 rc
= bnxt_hwrm_set_pause(bp
);
8388 netdev_err(bp
->dev
, "failed to update phy setting (rc: %x)\n",
8396 /* Common routine to pre-map certain register block to different GRC window.
8397 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
8398 * in PF and 3 windows in VF that can be customized to map in different
8401 static void bnxt_preset_reg_win(struct bnxt
*bp
)
8404 /* CAG registers map to GRC window #4 */
8405 writel(BNXT_CAG_REG_BASE
,
8406 bp
->bar0
+ BNXT_GRCPF_REG_WINDOW_BASE_OUT
+ 12);
8410 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
);
8412 static int __bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
8416 bnxt_preset_reg_win(bp
);
8417 netif_carrier_off(bp
->dev
);
8419 /* Reserve rings now if none were reserved at driver probe. */
8420 rc
= bnxt_init_dflt_ring_mode(bp
);
8422 netdev_err(bp
->dev
, "Failed to reserve default rings at open\n");
8426 rc
= bnxt_reserve_rings(bp
);
8429 if ((bp
->flags
& BNXT_FLAG_RFS
) &&
8430 !(bp
->flags
& BNXT_FLAG_USING_MSIX
)) {
8431 /* disable RFS if falling back to INTA */
8432 bp
->dev
->hw_features
&= ~NETIF_F_NTUPLE
;
8433 bp
->flags
&= ~BNXT_FLAG_RFS
;
8436 rc
= bnxt_alloc_mem(bp
, irq_re_init
);
8438 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
8439 goto open_err_free_mem
;
8444 rc
= bnxt_request_irq(bp
);
8446 netdev_err(bp
->dev
, "bnxt_request_irq err: %x\n", rc
);
8451 bnxt_enable_napi(bp
);
8452 bnxt_debug_dev_init(bp
);
8454 rc
= bnxt_init_nic(bp
, irq_re_init
);
8456 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
8461 mutex_lock(&bp
->link_lock
);
8462 rc
= bnxt_update_phy_setting(bp
);
8463 mutex_unlock(&bp
->link_lock
);
8465 netdev_warn(bp
->dev
, "failed to update phy settings\n");
8466 if (BNXT_SINGLE_PF(bp
)) {
8467 bp
->link_info
.phy_retry
= true;
8468 bp
->link_info
.phy_retry_expires
=
8475 udp_tunnel_get_rx_info(bp
->dev
);
8477 set_bit(BNXT_STATE_OPEN
, &bp
->state
);
8478 bnxt_enable_int(bp
);
8479 /* Enable TX queues */
8481 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
8482 /* Poll link status and check for SFP+ module status */
8483 bnxt_get_port_module_status(bp
);
8485 /* VF-reps may need to be re-opened after the PF is re-opened */
8487 bnxt_vf_reps_open(bp
);
8491 bnxt_debug_dev_exit(bp
);
8492 bnxt_disable_napi(bp
);
8500 bnxt_free_mem(bp
, true);
8504 /* rtnl_lock held */
8505 int bnxt_open_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
8509 rc
= __bnxt_open_nic(bp
, irq_re_init
, link_re_init
);
8511 netdev_err(bp
->dev
, "nic open fail (rc: %x)\n", rc
);
8517 /* rtnl_lock held, open the NIC half way by allocating all resources, but
8518 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
8521 int bnxt_half_open_nic(struct bnxt
*bp
)
8525 rc
= bnxt_alloc_mem(bp
, false);
8527 netdev_err(bp
->dev
, "bnxt_alloc_mem err: %x\n", rc
);
8530 rc
= bnxt_init_nic(bp
, false);
8532 netdev_err(bp
->dev
, "bnxt_init_nic err: %x\n", rc
);
8539 bnxt_free_mem(bp
, false);
8544 /* rtnl_lock held, this call can only be made after a previous successful
8545 * call to bnxt_half_open_nic().
8547 void bnxt_half_close_nic(struct bnxt
*bp
)
8549 bnxt_hwrm_resource_free(bp
, false, false);
8551 bnxt_free_mem(bp
, false);
8554 static int bnxt_open(struct net_device
*dev
)
8556 struct bnxt
*bp
= netdev_priv(dev
);
8559 bnxt_hwrm_if_change(bp
, true);
8560 rc
= __bnxt_open_nic(bp
, true, true);
8562 bnxt_hwrm_if_change(bp
, false);
8564 bnxt_hwmon_open(bp
);
8569 static bool bnxt_drv_busy(struct bnxt
*bp
)
8571 return (test_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
) ||
8572 test_bit(BNXT_STATE_READ_STATS
, &bp
->state
));
8575 static void bnxt_get_ring_stats(struct bnxt
*bp
,
8576 struct rtnl_link_stats64
*stats
);
8578 static void __bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
,
8581 /* Close the VF-reps before closing PF */
8583 bnxt_vf_reps_close(bp
);
8585 /* Change device state to avoid TX queue wake up's */
8586 bnxt_tx_disable(bp
);
8588 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
8589 smp_mb__after_atomic();
8590 while (bnxt_drv_busy(bp
))
8593 /* Flush rings and and disable interrupts */
8594 bnxt_shutdown_nic(bp
, irq_re_init
);
8596 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
8598 bnxt_debug_dev_exit(bp
);
8599 bnxt_disable_napi(bp
);
8600 del_timer_sync(&bp
->timer
);
8603 /* Save ring stats before shutdown */
8605 bnxt_get_ring_stats(bp
, &bp
->net_stats_prev
);
8610 bnxt_free_mem(bp
, irq_re_init
);
8613 int bnxt_close_nic(struct bnxt
*bp
, bool irq_re_init
, bool link_re_init
)
8617 #ifdef CONFIG_BNXT_SRIOV
8618 if (bp
->sriov_cfg
) {
8619 rc
= wait_event_interruptible_timeout(bp
->sriov_cfg_wait
,
8621 BNXT_SRIOV_CFG_WAIT_TMO
);
8623 netdev_warn(bp
->dev
, "timeout waiting for SRIOV config operation to complete!\n");
8626 __bnxt_close_nic(bp
, irq_re_init
, link_re_init
);
8630 static int bnxt_close(struct net_device
*dev
)
8632 struct bnxt
*bp
= netdev_priv(dev
);
8634 bnxt_hwmon_close(bp
);
8635 bnxt_close_nic(bp
, true, true);
8636 bnxt_hwrm_shutdown_link(bp
);
8637 bnxt_hwrm_if_change(bp
, false);
8641 static int bnxt_hwrm_port_phy_read(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
8644 struct hwrm_port_phy_mdio_read_output
*resp
= bp
->hwrm_cmd_resp_addr
;
8645 struct hwrm_port_phy_mdio_read_input req
= {0};
8648 if (bp
->hwrm_spec_code
< 0x10a00)
8651 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_READ
, -1, -1);
8652 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8653 req
.phy_addr
= phy_addr
;
8654 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
8655 if (bp
->link_info
.support_speeds
& BNXT_LINK_SPEED_MSK_10GB
) {
8657 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
8658 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
8659 req
.reg_addr
= cpu_to_le16(reg
);
8662 mutex_lock(&bp
->hwrm_cmd_lock
);
8663 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8665 *val
= le16_to_cpu(resp
->reg_data
);
8666 mutex_unlock(&bp
->hwrm_cmd_lock
);
8670 static int bnxt_hwrm_port_phy_write(struct bnxt
*bp
, u16 phy_addr
, u16 reg
,
8673 struct hwrm_port_phy_mdio_write_input req
= {0};
8675 if (bp
->hwrm_spec_code
< 0x10a00)
8678 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_MDIO_WRITE
, -1, -1);
8679 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
8680 req
.phy_addr
= phy_addr
;
8681 req
.reg_addr
= cpu_to_le16(reg
& 0x1f);
8682 if (bp
->link_info
.support_speeds
& BNXT_LINK_SPEED_MSK_10GB
) {
8684 req
.phy_addr
= mdio_phy_id_prtad(phy_addr
);
8685 req
.dev_addr
= mdio_phy_id_devad(phy_addr
);
8686 req
.reg_addr
= cpu_to_le16(reg
);
8688 req
.reg_data
= cpu_to_le16(val
);
8690 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
8693 /* rtnl_lock held */
8694 static int bnxt_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
8696 struct mii_ioctl_data
*mdio
= if_mii(ifr
);
8697 struct bnxt
*bp
= netdev_priv(dev
);
8702 mdio
->phy_id
= bp
->link_info
.phy_addr
;
8708 if (!netif_running(dev
))
8711 rc
= bnxt_hwrm_port_phy_read(bp
, mdio
->phy_id
, mdio
->reg_num
,
8713 mdio
->val_out
= mii_regval
;
8718 if (!netif_running(dev
))
8721 return bnxt_hwrm_port_phy_write(bp
, mdio
->phy_id
, mdio
->reg_num
,
8731 static void bnxt_get_ring_stats(struct bnxt
*bp
,
8732 struct rtnl_link_stats64
*stats
)
8737 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
8738 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
8739 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
8740 struct ctx_hw_stats
*hw_stats
= cpr
->hw_stats
;
8742 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_ucast_pkts
);
8743 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
8744 stats
->rx_packets
+= le64_to_cpu(hw_stats
->rx_bcast_pkts
);
8746 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_ucast_pkts
);
8747 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_mcast_pkts
);
8748 stats
->tx_packets
+= le64_to_cpu(hw_stats
->tx_bcast_pkts
);
8750 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_ucast_bytes
);
8751 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_mcast_bytes
);
8752 stats
->rx_bytes
+= le64_to_cpu(hw_stats
->rx_bcast_bytes
);
8754 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_ucast_bytes
);
8755 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_mcast_bytes
);
8756 stats
->tx_bytes
+= le64_to_cpu(hw_stats
->tx_bcast_bytes
);
8758 stats
->rx_missed_errors
+=
8759 le64_to_cpu(hw_stats
->rx_discard_pkts
);
8761 stats
->multicast
+= le64_to_cpu(hw_stats
->rx_mcast_pkts
);
8763 stats
->tx_dropped
+= le64_to_cpu(hw_stats
->tx_drop_pkts
);
8767 static void bnxt_add_prev_stats(struct bnxt
*bp
,
8768 struct rtnl_link_stats64
*stats
)
8770 struct rtnl_link_stats64
*prev_stats
= &bp
->net_stats_prev
;
8772 stats
->rx_packets
+= prev_stats
->rx_packets
;
8773 stats
->tx_packets
+= prev_stats
->tx_packets
;
8774 stats
->rx_bytes
+= prev_stats
->rx_bytes
;
8775 stats
->tx_bytes
+= prev_stats
->tx_bytes
;
8776 stats
->rx_missed_errors
+= prev_stats
->rx_missed_errors
;
8777 stats
->multicast
+= prev_stats
->multicast
;
8778 stats
->tx_dropped
+= prev_stats
->tx_dropped
;
8782 bnxt_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
8784 struct bnxt
*bp
= netdev_priv(dev
);
8786 set_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
8787 /* Make sure bnxt_close_nic() sees that we are reading stats before
8788 * we check the BNXT_STATE_OPEN flag.
8790 smp_mb__after_atomic();
8791 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
8792 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
8793 *stats
= bp
->net_stats_prev
;
8797 bnxt_get_ring_stats(bp
, stats
);
8798 bnxt_add_prev_stats(bp
, stats
);
8800 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
8801 struct rx_port_stats
*rx
= bp
->hw_rx_port_stats
;
8802 struct tx_port_stats
*tx
= bp
->hw_tx_port_stats
;
8804 stats
->rx_crc_errors
= le64_to_cpu(rx
->rx_fcs_err_frames
);
8805 stats
->rx_frame_errors
= le64_to_cpu(rx
->rx_align_err_frames
);
8806 stats
->rx_length_errors
= le64_to_cpu(rx
->rx_undrsz_frames
) +
8807 le64_to_cpu(rx
->rx_ovrsz_frames
) +
8808 le64_to_cpu(rx
->rx_runt_frames
);
8809 stats
->rx_errors
= le64_to_cpu(rx
->rx_false_carrier_frames
) +
8810 le64_to_cpu(rx
->rx_jbr_frames
);
8811 stats
->collisions
= le64_to_cpu(tx
->tx_total_collisions
);
8812 stats
->tx_fifo_errors
= le64_to_cpu(tx
->tx_fifo_underruns
);
8813 stats
->tx_errors
= le64_to_cpu(tx
->tx_err
);
8815 clear_bit(BNXT_STATE_READ_STATS
, &bp
->state
);
8818 static bool bnxt_mc_list_updated(struct bnxt
*bp
, u32
*rx_mask
)
8820 struct net_device
*dev
= bp
->dev
;
8821 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8822 struct netdev_hw_addr
*ha
;
8825 bool update
= false;
8828 netdev_for_each_mc_addr(ha
, dev
) {
8829 if (mc_count
>= BNXT_MAX_MC_ADDRS
) {
8830 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
8831 vnic
->mc_list_count
= 0;
8835 if (!ether_addr_equal(haddr
, vnic
->mc_list
+ off
)) {
8836 memcpy(vnic
->mc_list
+ off
, haddr
, ETH_ALEN
);
8843 *rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
;
8845 if (mc_count
!= vnic
->mc_list_count
) {
8846 vnic
->mc_list_count
= mc_count
;
8852 static bool bnxt_uc_list_updated(struct bnxt
*bp
)
8854 struct net_device
*dev
= bp
->dev
;
8855 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8856 struct netdev_hw_addr
*ha
;
8859 if (netdev_uc_count(dev
) != (vnic
->uc_filter_count
- 1))
8862 netdev_for_each_uc_addr(ha
, dev
) {
8863 if (!ether_addr_equal(ha
->addr
, vnic
->uc_list
+ off
))
8871 static void bnxt_set_rx_mode(struct net_device
*dev
)
8873 struct bnxt
*bp
= netdev_priv(dev
);
8874 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8875 u32 mask
= vnic
->rx_mask
;
8876 bool mc_update
= false;
8879 if (!netif_running(dev
))
8882 mask
&= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
|
8883 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST
|
8884 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
|
8885 CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
);
8887 if ((dev
->flags
& IFF_PROMISC
) && bnxt_promisc_ok(bp
))
8888 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
8890 uc_update
= bnxt_uc_list_updated(bp
);
8892 if (dev
->flags
& IFF_BROADCAST
)
8893 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST
;
8894 if (dev
->flags
& IFF_ALLMULTI
) {
8895 mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
8896 vnic
->mc_list_count
= 0;
8898 mc_update
= bnxt_mc_list_updated(bp
, &mask
);
8901 if (mask
!= vnic
->rx_mask
|| uc_update
|| mc_update
) {
8902 vnic
->rx_mask
= mask
;
8904 set_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
);
8905 bnxt_queue_sp_work(bp
);
8909 static int bnxt_cfg_rx_mode(struct bnxt
*bp
)
8911 struct net_device
*dev
= bp
->dev
;
8912 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
8913 struct netdev_hw_addr
*ha
;
8917 netif_addr_lock_bh(dev
);
8918 uc_update
= bnxt_uc_list_updated(bp
);
8919 netif_addr_unlock_bh(dev
);
8924 mutex_lock(&bp
->hwrm_cmd_lock
);
8925 for (i
= 1; i
< vnic
->uc_filter_count
; i
++) {
8926 struct hwrm_cfa_l2_filter_free_input req
= {0};
8928 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_CFA_L2_FILTER_FREE
, -1,
8931 req
.l2_filter_id
= vnic
->fw_l2_filter_id
[i
];
8933 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
8936 mutex_unlock(&bp
->hwrm_cmd_lock
);
8938 vnic
->uc_filter_count
= 1;
8940 netif_addr_lock_bh(dev
);
8941 if (netdev_uc_count(dev
) > (BNXT_MAX_UC_ADDRS
- 1)) {
8942 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS
;
8944 netdev_for_each_uc_addr(ha
, dev
) {
8945 memcpy(vnic
->uc_list
+ off
, ha
->addr
, ETH_ALEN
);
8947 vnic
->uc_filter_count
++;
8950 netif_addr_unlock_bh(dev
);
8952 for (i
= 1, off
= 0; i
< vnic
->uc_filter_count
; i
++, off
+= ETH_ALEN
) {
8953 rc
= bnxt_hwrm_set_vnic_filter(bp
, 0, i
, vnic
->uc_list
+ off
);
8955 netdev_err(bp
->dev
, "HWRM vnic filter failure rc: %x\n",
8957 vnic
->uc_filter_count
= i
;
8963 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
8964 if (rc
&& vnic
->mc_list_count
) {
8965 netdev_info(bp
->dev
, "Failed setting MC filters rc: %d, turning on ALL_MCAST mode\n",
8967 vnic
->rx_mask
|= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST
;
8968 vnic
->mc_list_count
= 0;
8969 rc
= bnxt_hwrm_cfa_l2_set_rx_mask(bp
, 0);
8972 netdev_err(bp
->dev
, "HWRM cfa l2 rx mask failure rc: %d\n",
8978 static bool bnxt_can_reserve_rings(struct bnxt
*bp
)
8980 #ifdef CONFIG_BNXT_SRIOV
8981 if (BNXT_NEW_RM(bp
) && BNXT_VF(bp
)) {
8982 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
8984 /* No minimum rings were provisioned by the PF. Don't
8985 * reserve rings by default when device is down.
8987 if (hw_resc
->min_tx_rings
|| hw_resc
->resv_tx_rings
)
8990 if (!netif_running(bp
->dev
))
8997 /* If the chip and firmware supports RFS */
8998 static bool bnxt_rfs_supported(struct bnxt
*bp
)
9000 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
9002 if (BNXT_PF(bp
) && !BNXT_CHIP_TYPE_NITRO_A0(bp
))
9004 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
9009 /* If runtime conditions support RFS */
9010 static bool bnxt_rfs_capable(struct bnxt
*bp
)
9012 #ifdef CONFIG_RFS_ACCEL
9013 int vnics
, max_vnics
, max_rss_ctxs
;
9015 if (bp
->flags
& BNXT_FLAG_CHIP_P5
)
9017 if (!(bp
->flags
& BNXT_FLAG_MSIX_CAP
) || !bnxt_can_reserve_rings(bp
))
9020 vnics
= 1 + bp
->rx_nr_rings
;
9021 max_vnics
= bnxt_get_max_func_vnics(bp
);
9022 max_rss_ctxs
= bnxt_get_max_func_rss_ctxs(bp
);
9024 /* RSS contexts not a limiting factor */
9025 if (bp
->flags
& BNXT_FLAG_NEW_RSS_CAP
)
9026 max_rss_ctxs
= max_vnics
;
9027 if (vnics
> max_vnics
|| vnics
> max_rss_ctxs
) {
9028 if (bp
->rx_nr_rings
> 1)
9029 netdev_warn(bp
->dev
,
9030 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
9031 min(max_rss_ctxs
- 1, max_vnics
- 1));
9035 if (!BNXT_NEW_RM(bp
))
9038 if (vnics
== bp
->hw_resc
.resv_vnics
)
9041 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, vnics
);
9042 if (vnics
<= bp
->hw_resc
.resv_vnics
)
9045 netdev_warn(bp
->dev
, "Unable to reserve resources to support NTUPLE filters.\n");
9046 bnxt_hwrm_reserve_rings(bp
, 0, 0, 0, 0, 0, 1);
9053 static netdev_features_t
bnxt_fix_features(struct net_device
*dev
,
9054 netdev_features_t features
)
9056 struct bnxt
*bp
= netdev_priv(dev
);
9058 if ((features
& NETIF_F_NTUPLE
) && !bnxt_rfs_capable(bp
))
9059 features
&= ~NETIF_F_NTUPLE
;
9061 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
9062 features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
9064 if (!(features
& NETIF_F_GRO
))
9065 features
&= ~NETIF_F_GRO_HW
;
9067 if (features
& NETIF_F_GRO_HW
)
9068 features
&= ~NETIF_F_LRO
;
9070 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
9071 * turned on or off together.
9073 if ((features
& (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) !=
9074 (NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_STAG_RX
)) {
9075 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
9076 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
9077 NETIF_F_HW_VLAN_STAG_RX
);
9079 features
|= NETIF_F_HW_VLAN_CTAG_RX
|
9080 NETIF_F_HW_VLAN_STAG_RX
;
9082 #ifdef CONFIG_BNXT_SRIOV
9085 features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
9086 NETIF_F_HW_VLAN_STAG_RX
);
9093 static int bnxt_set_features(struct net_device
*dev
, netdev_features_t features
)
9095 struct bnxt
*bp
= netdev_priv(dev
);
9096 u32 flags
= bp
->flags
;
9099 bool re_init
= false;
9100 bool update_tpa
= false;
9102 flags
&= ~BNXT_FLAG_ALL_CONFIG_FEATS
;
9103 if (features
& NETIF_F_GRO_HW
)
9104 flags
|= BNXT_FLAG_GRO
;
9105 else if (features
& NETIF_F_LRO
)
9106 flags
|= BNXT_FLAG_LRO
;
9108 if (bp
->flags
& BNXT_FLAG_NO_AGG_RINGS
)
9109 flags
&= ~BNXT_FLAG_TPA
;
9111 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
9112 flags
|= BNXT_FLAG_STRIP_VLAN
;
9114 if (features
& NETIF_F_NTUPLE
)
9115 flags
|= BNXT_FLAG_RFS
;
9117 changes
= flags
^ bp
->flags
;
9118 if (changes
& BNXT_FLAG_TPA
) {
9120 if ((bp
->flags
& BNXT_FLAG_TPA
) == 0 ||
9121 (flags
& BNXT_FLAG_TPA
) == 0)
9125 if (changes
& ~BNXT_FLAG_TPA
)
9128 if (flags
!= bp
->flags
) {
9129 u32 old_flags
= bp
->flags
;
9133 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
9135 bnxt_set_ring_params(bp
);
9140 bnxt_close_nic(bp
, false, false);
9142 bnxt_set_ring_params(bp
);
9144 return bnxt_open_nic(bp
, false, false);
9147 rc
= bnxt_set_tpa(bp
,
9148 (flags
& BNXT_FLAG_TPA
) ?
9151 bp
->flags
= old_flags
;
9157 static int bnxt_dbg_hwrm_ring_info_get(struct bnxt
*bp
, u8 ring_type
,
9158 u32 ring_id
, u32
*prod
, u32
*cons
)
9160 struct hwrm_dbg_ring_info_get_output
*resp
= bp
->hwrm_cmd_resp_addr
;
9161 struct hwrm_dbg_ring_info_get_input req
= {0};
9164 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_DBG_RING_INFO_GET
, -1, -1);
9165 req
.ring_type
= ring_type
;
9166 req
.fw_ring_id
= cpu_to_le32(ring_id
);
9167 mutex_lock(&bp
->hwrm_cmd_lock
);
9168 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
9170 *prod
= le32_to_cpu(resp
->producer_index
);
9171 *cons
= le32_to_cpu(resp
->consumer_index
);
9173 mutex_unlock(&bp
->hwrm_cmd_lock
);
9177 static void bnxt_dump_tx_sw_state(struct bnxt_napi
*bnapi
)
9179 struct bnxt_tx_ring_info
*txr
= bnapi
->tx_ring
;
9180 int i
= bnapi
->index
;
9185 netdev_info(bnapi
->bp
->dev
, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
9186 i
, txr
->tx_ring_struct
.fw_ring_id
, txr
->tx_prod
,
9190 static void bnxt_dump_rx_sw_state(struct bnxt_napi
*bnapi
)
9192 struct bnxt_rx_ring_info
*rxr
= bnapi
->rx_ring
;
9193 int i
= bnapi
->index
;
9198 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",
9199 i
, rxr
->rx_ring_struct
.fw_ring_id
, rxr
->rx_prod
,
9200 rxr
->rx_agg_ring_struct
.fw_ring_id
, rxr
->rx_agg_prod
,
9201 rxr
->rx_sw_agg_prod
);
9204 static void bnxt_dump_cp_sw_state(struct bnxt_napi
*bnapi
)
9206 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
9207 int i
= bnapi
->index
;
9209 netdev_info(bnapi
->bp
->dev
, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
9210 i
, cpr
->cp_ring_struct
.fw_ring_id
, cpr
->cp_raw_cons
);
9213 static void bnxt_dbg_dump_states(struct bnxt
*bp
)
9216 struct bnxt_napi
*bnapi
;
9218 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9219 bnapi
= bp
->bnapi
[i
];
9220 if (netif_msg_drv(bp
)) {
9221 bnxt_dump_tx_sw_state(bnapi
);
9222 bnxt_dump_rx_sw_state(bnapi
);
9223 bnxt_dump_cp_sw_state(bnapi
);
9228 static void bnxt_reset_task(struct bnxt
*bp
, bool silent
)
9231 bnxt_dbg_dump_states(bp
);
9232 if (netif_running(bp
->dev
)) {
9237 bnxt_close_nic(bp
, false, false);
9238 rc
= bnxt_open_nic(bp
, false, false);
9244 static void bnxt_tx_timeout(struct net_device
*dev
)
9246 struct bnxt
*bp
= netdev_priv(dev
);
9248 netdev_err(bp
->dev
, "TX timeout detected, starting reset task!\n");
9249 set_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
);
9250 bnxt_queue_sp_work(bp
);
9253 static void bnxt_timer(struct timer_list
*t
)
9255 struct bnxt
*bp
= from_timer(bp
, t
, timer
);
9256 struct net_device
*dev
= bp
->dev
;
9258 if (!netif_running(dev
))
9261 if (atomic_read(&bp
->intr_sem
) != 0)
9262 goto bnxt_restart_timer
;
9264 if (bp
->link_info
.link_up
&& (bp
->flags
& BNXT_FLAG_PORT_STATS
) &&
9265 bp
->stats_coal_ticks
) {
9266 set_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
);
9267 bnxt_queue_sp_work(bp
);
9270 if (bnxt_tc_flower_enabled(bp
)) {
9271 set_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
);
9272 bnxt_queue_sp_work(bp
);
9275 if (bp
->link_info
.phy_retry
) {
9276 if (time_after(jiffies
, bp
->link_info
.phy_retry_expires
)) {
9277 bp
->link_info
.phy_retry
= 0;
9278 netdev_warn(bp
->dev
, "failed to update phy settings after maximum retries.\n");
9280 set_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
);
9281 bnxt_queue_sp_work(bp
);
9285 if ((bp
->flags
& BNXT_FLAG_CHIP_P5
) && netif_carrier_ok(dev
)) {
9286 set_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
);
9287 bnxt_queue_sp_work(bp
);
9290 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
9293 static void bnxt_rtnl_lock_sp(struct bnxt
*bp
)
9295 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
9296 * set. If the device is being closed, bnxt_close() may be holding
9297 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
9298 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
9300 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
9304 static void bnxt_rtnl_unlock_sp(struct bnxt
*bp
)
9306 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
9310 /* Only called from bnxt_sp_task() */
9311 static void bnxt_reset(struct bnxt
*bp
, bool silent
)
9313 bnxt_rtnl_lock_sp(bp
);
9314 if (test_bit(BNXT_STATE_OPEN
, &bp
->state
))
9315 bnxt_reset_task(bp
, silent
);
9316 bnxt_rtnl_unlock_sp(bp
);
9319 static void bnxt_chk_missed_irq(struct bnxt
*bp
)
9323 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
9326 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
9327 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
9328 struct bnxt_cp_ring_info
*cpr
;
9335 cpr
= &bnapi
->cp_ring
;
9336 for (j
= 0; j
< 2; j
++) {
9337 struct bnxt_cp_ring_info
*cpr2
= cpr
->cp_ring_arr
[j
];
9340 if (!cpr2
|| cpr2
->has_more_work
||
9341 !bnxt_has_work(bp
, cpr2
))
9344 if (cpr2
->cp_raw_cons
!= cpr2
->last_cp_raw_cons
) {
9345 cpr2
->last_cp_raw_cons
= cpr2
->cp_raw_cons
;
9348 fw_ring_id
= cpr2
->cp_ring_struct
.fw_ring_id
;
9349 bnxt_dbg_hwrm_ring_info_get(bp
,
9350 DBG_RING_INFO_GET_REQ_RING_TYPE_L2_CMPL
,
9351 fw_ring_id
, &val
[0], &val
[1]);
9357 static void bnxt_cfg_ntp_filters(struct bnxt
*);
9359 static void bnxt_sp_task(struct work_struct
*work
)
9361 struct bnxt
*bp
= container_of(work
, struct bnxt
, sp_task
);
9363 set_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
9364 smp_mb__after_atomic();
9365 if (!test_bit(BNXT_STATE_OPEN
, &bp
->state
)) {
9366 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
9370 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT
, &bp
->sp_event
))
9371 bnxt_cfg_rx_mode(bp
);
9373 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
))
9374 bnxt_cfg_ntp_filters(bp
);
9375 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT
, &bp
->sp_event
))
9376 bnxt_hwrm_exec_fwd_req(bp
);
9377 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
9378 bnxt_hwrm_tunnel_dst_port_alloc(
9380 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
9382 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
9383 bnxt_hwrm_tunnel_dst_port_free(
9384 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN
);
9386 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
)) {
9387 bnxt_hwrm_tunnel_dst_port_alloc(
9389 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
9391 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
)) {
9392 bnxt_hwrm_tunnel_dst_port_free(
9393 bp
, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE
);
9395 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT
, &bp
->sp_event
)) {
9396 bnxt_hwrm_port_qstats(bp
);
9397 bnxt_hwrm_port_qstats_ext(bp
);
9400 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT
, &bp
->sp_event
)) {
9403 mutex_lock(&bp
->link_lock
);
9404 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT
,
9406 bnxt_hwrm_phy_qcaps(bp
);
9408 rc
= bnxt_update_link(bp
, true);
9409 mutex_unlock(&bp
->link_lock
);
9411 netdev_err(bp
->dev
, "SP task can't update link (rc: %x)\n",
9414 if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT
, &bp
->sp_event
)) {
9417 mutex_lock(&bp
->link_lock
);
9418 rc
= bnxt_update_phy_setting(bp
);
9419 mutex_unlock(&bp
->link_lock
);
9421 netdev_warn(bp
->dev
, "update phy settings retry failed\n");
9423 bp
->link_info
.phy_retry
= false;
9424 netdev_info(bp
->dev
, "update phy settings retry succeeded\n");
9427 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT
, &bp
->sp_event
)) {
9428 mutex_lock(&bp
->link_lock
);
9429 bnxt_get_port_module_status(bp
);
9430 mutex_unlock(&bp
->link_lock
);
9433 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT
, &bp
->sp_event
))
9434 bnxt_tc_flow_stats_work(bp
);
9436 if (test_and_clear_bit(BNXT_RING_COAL_NOW_SP_EVENT
, &bp
->sp_event
))
9437 bnxt_chk_missed_irq(bp
);
9439 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
9440 * must be the last functions to be called before exiting.
9442 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT
, &bp
->sp_event
))
9443 bnxt_reset(bp
, false);
9445 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT
, &bp
->sp_event
))
9446 bnxt_reset(bp
, true);
9448 smp_mb__before_atomic();
9449 clear_bit(BNXT_STATE_IN_SP_TASK
, &bp
->state
);
9452 /* Under rtnl_lock */
9453 int bnxt_check_rings(struct bnxt
*bp
, int tx
, int rx
, bool sh
, int tcs
,
9456 int max_rx
, max_tx
, tx_sets
= 1;
9457 int tx_rings_needed
, stats
;
9464 rc
= bnxt_get_max_rings(bp
, &max_rx
, &max_tx
, sh
);
9471 tx_rings_needed
= tx
* tx_sets
+ tx_xdp
;
9472 if (max_tx
< tx_rings_needed
)
9476 if (bp
->flags
& BNXT_FLAG_RFS
)
9479 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
9481 cp
= sh
? max_t(int, tx_rings_needed
, rx
) : tx_rings_needed
+ rx
;
9483 if (BNXT_NEW_RM(bp
)) {
9484 cp
+= bnxt_get_ulp_msix_num(bp
);
9485 stats
+= bnxt_get_ulp_stat_ctxs(bp
);
9487 return bnxt_hwrm_check_rings(bp
, tx_rings_needed
, rx_rings
, rx
, cp
,
9491 static void bnxt_unmap_bars(struct bnxt
*bp
, struct pci_dev
*pdev
)
9494 pci_iounmap(pdev
, bp
->bar2
);
9499 pci_iounmap(pdev
, bp
->bar1
);
9504 pci_iounmap(pdev
, bp
->bar0
);
9509 static void bnxt_cleanup_pci(struct bnxt
*bp
)
9511 bnxt_unmap_bars(bp
, bp
->pdev
);
9512 pci_release_regions(bp
->pdev
);
9513 pci_disable_device(bp
->pdev
);
9516 static void bnxt_init_dflt_coal(struct bnxt
*bp
)
9518 struct bnxt_coal
*coal
;
9520 /* Tick values in micro seconds.
9521 * 1 coal_buf x bufs_per_record = 1 completion record.
9523 coal
= &bp
->rx_coal
;
9524 coal
->coal_ticks
= 10;
9525 coal
->coal_bufs
= 30;
9526 coal
->coal_ticks_irq
= 1;
9527 coal
->coal_bufs_irq
= 2;
9528 coal
->idle_thresh
= 50;
9529 coal
->bufs_per_record
= 2;
9530 coal
->budget
= 64; /* NAPI budget */
9532 coal
= &bp
->tx_coal
;
9533 coal
->coal_ticks
= 28;
9534 coal
->coal_bufs
= 30;
9535 coal
->coal_ticks_irq
= 2;
9536 coal
->coal_bufs_irq
= 2;
9537 coal
->bufs_per_record
= 1;
9539 bp
->stats_coal_ticks
= BNXT_DEF_STATS_COAL_TICKS
;
9542 static int bnxt_init_board(struct pci_dev
*pdev
, struct net_device
*dev
)
9545 struct bnxt
*bp
= netdev_priv(dev
);
9547 SET_NETDEV_DEV(dev
, &pdev
->dev
);
9549 /* enable device (incl. PCI PM wakeup), and bus-mastering */
9550 rc
= pci_enable_device(pdev
);
9552 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
9556 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
9558 "Cannot find PCI device base address, aborting\n");
9560 goto init_err_disable
;
9563 rc
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
9565 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
9566 goto init_err_disable
;
9569 if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64)) != 0 &&
9570 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)) != 0) {
9571 dev_err(&pdev
->dev
, "System does not support DMA, aborting\n");
9572 goto init_err_disable
;
9575 pci_set_master(pdev
);
9580 bp
->bar0
= pci_ioremap_bar(pdev
, 0);
9582 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
9584 goto init_err_release
;
9587 bp
->bar1
= pci_ioremap_bar(pdev
, 2);
9589 dev_err(&pdev
->dev
, "Cannot map doorbell registers, aborting\n");
9591 goto init_err_release
;
9594 bp
->bar2
= pci_ioremap_bar(pdev
, 4);
9596 dev_err(&pdev
->dev
, "Cannot map bar4 registers, aborting\n");
9598 goto init_err_release
;
9601 pci_enable_pcie_error_reporting(pdev
);
9603 INIT_WORK(&bp
->sp_task
, bnxt_sp_task
);
9605 spin_lock_init(&bp
->ntp_fltr_lock
);
9606 #if BITS_PER_LONG == 32
9607 spin_lock_init(&bp
->db_lock
);
9610 bp
->rx_ring_size
= BNXT_DEFAULT_RX_RING_SIZE
;
9611 bp
->tx_ring_size
= BNXT_DEFAULT_TX_RING_SIZE
;
9613 bnxt_init_dflt_coal(bp
);
9615 timer_setup(&bp
->timer
, bnxt_timer
, 0);
9616 bp
->current_interval
= BNXT_TIMER_INTERVAL
;
9618 clear_bit(BNXT_STATE_OPEN
, &bp
->state
);
9622 bnxt_unmap_bars(bp
, pdev
);
9623 pci_release_regions(pdev
);
9626 pci_disable_device(pdev
);
9632 /* rtnl_lock held */
9633 static int bnxt_change_mac_addr(struct net_device
*dev
, void *p
)
9635 struct sockaddr
*addr
= p
;
9636 struct bnxt
*bp
= netdev_priv(dev
);
9639 if (!is_valid_ether_addr(addr
->sa_data
))
9640 return -EADDRNOTAVAIL
;
9642 if (ether_addr_equal(addr
->sa_data
, dev
->dev_addr
))
9645 rc
= bnxt_approve_mac(bp
, addr
->sa_data
, true);
9649 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
9650 if (netif_running(dev
)) {
9651 bnxt_close_nic(bp
, false, false);
9652 rc
= bnxt_open_nic(bp
, false, false);
9658 /* rtnl_lock held */
9659 static int bnxt_change_mtu(struct net_device
*dev
, int new_mtu
)
9661 struct bnxt
*bp
= netdev_priv(dev
);
9663 if (netif_running(dev
))
9664 bnxt_close_nic(bp
, false, false);
9667 bnxt_set_ring_params(bp
);
9669 if (netif_running(dev
))
9670 return bnxt_open_nic(bp
, false, false);
9675 int bnxt_setup_mq_tc(struct net_device
*dev
, u8 tc
)
9677 struct bnxt
*bp
= netdev_priv(dev
);
9681 if (tc
> bp
->max_tc
) {
9682 netdev_err(dev
, "Too many traffic classes requested: %d. Max supported is %d.\n",
9687 if (netdev_get_num_tc(dev
) == tc
)
9690 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
)
9693 rc
= bnxt_check_rings(bp
, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
,
9694 sh
, tc
, bp
->tx_nr_rings_xdp
);
9698 /* Needs to close the device and do hw resource re-allocations */
9699 if (netif_running(bp
->dev
))
9700 bnxt_close_nic(bp
, true, false);
9703 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tc
;
9704 netdev_set_num_tc(dev
, tc
);
9706 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
9707 netdev_reset_tc(dev
);
9709 bp
->tx_nr_rings
+= bp
->tx_nr_rings_xdp
;
9710 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
9711 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
9713 if (netif_running(bp
->dev
))
9714 return bnxt_open_nic(bp
, true, false);
9719 static int bnxt_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
9722 struct bnxt
*bp
= cb_priv
;
9724 if (!bnxt_tc_flower_enabled(bp
) ||
9725 !tc_cls_can_offload_and_chain0(bp
->dev
, type_data
))
9729 case TC_SETUP_CLSFLOWER
:
9730 return bnxt_tc_setup_flower(bp
, bp
->pf
.fw_fid
, type_data
);
9736 static int bnxt_setup_tc_block(struct net_device
*dev
,
9737 struct tc_block_offload
*f
)
9739 struct bnxt
*bp
= netdev_priv(dev
);
9741 if (f
->binder_type
!= TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS
)
9744 switch (f
->command
) {
9746 return tcf_block_cb_register(f
->block
, bnxt_setup_tc_block_cb
,
9748 case TC_BLOCK_UNBIND
:
9749 tcf_block_cb_unregister(f
->block
, bnxt_setup_tc_block_cb
, bp
);
9756 static int bnxt_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
9760 case TC_SETUP_BLOCK
:
9761 return bnxt_setup_tc_block(dev
, type_data
);
9762 case TC_SETUP_QDISC_MQPRIO
: {
9763 struct tc_mqprio_qopt
*mqprio
= type_data
;
9765 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
9767 return bnxt_setup_mq_tc(dev
, mqprio
->num_tc
);
9774 #ifdef CONFIG_RFS_ACCEL
9775 static bool bnxt_fltr_match(struct bnxt_ntuple_filter
*f1
,
9776 struct bnxt_ntuple_filter
*f2
)
9778 struct flow_keys
*keys1
= &f1
->fkeys
;
9779 struct flow_keys
*keys2
= &f2
->fkeys
;
9781 if (keys1
->addrs
.v4addrs
.src
== keys2
->addrs
.v4addrs
.src
&&
9782 keys1
->addrs
.v4addrs
.dst
== keys2
->addrs
.v4addrs
.dst
&&
9783 keys1
->ports
.ports
== keys2
->ports
.ports
&&
9784 keys1
->basic
.ip_proto
== keys2
->basic
.ip_proto
&&
9785 keys1
->basic
.n_proto
== keys2
->basic
.n_proto
&&
9786 keys1
->control
.flags
== keys2
->control
.flags
&&
9787 ether_addr_equal(f1
->src_mac_addr
, f2
->src_mac_addr
) &&
9788 ether_addr_equal(f1
->dst_mac_addr
, f2
->dst_mac_addr
))
9794 static int bnxt_rx_flow_steer(struct net_device
*dev
, const struct sk_buff
*skb
,
9795 u16 rxq_index
, u32 flow_id
)
9797 struct bnxt
*bp
= netdev_priv(dev
);
9798 struct bnxt_ntuple_filter
*fltr
, *new_fltr
;
9799 struct flow_keys
*fkeys
;
9800 struct ethhdr
*eth
= (struct ethhdr
*)skb_mac_header(skb
);
9801 int rc
= 0, idx
, bit_id
, l2_idx
= 0;
9802 struct hlist_head
*head
;
9804 if (!ether_addr_equal(dev
->dev_addr
, eth
->h_dest
)) {
9805 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
9808 netif_addr_lock_bh(dev
);
9809 for (j
= 0; j
< vnic
->uc_filter_count
; j
++, off
+= ETH_ALEN
) {
9810 if (ether_addr_equal(eth
->h_dest
,
9811 vnic
->uc_list
+ off
)) {
9816 netif_addr_unlock_bh(dev
);
9820 new_fltr
= kzalloc(sizeof(*new_fltr
), GFP_ATOMIC
);
9824 fkeys
= &new_fltr
->fkeys
;
9825 if (!skb_flow_dissect_flow_keys(skb
, fkeys
, 0)) {
9826 rc
= -EPROTONOSUPPORT
;
9830 if ((fkeys
->basic
.n_proto
!= htons(ETH_P_IP
) &&
9831 fkeys
->basic
.n_proto
!= htons(ETH_P_IPV6
)) ||
9832 ((fkeys
->basic
.ip_proto
!= IPPROTO_TCP
) &&
9833 (fkeys
->basic
.ip_proto
!= IPPROTO_UDP
))) {
9834 rc
= -EPROTONOSUPPORT
;
9837 if (fkeys
->basic
.n_proto
== htons(ETH_P_IPV6
) &&
9838 bp
->hwrm_spec_code
< 0x10601) {
9839 rc
= -EPROTONOSUPPORT
;
9842 if ((fkeys
->control
.flags
& FLOW_DIS_ENCAPSULATION
) &&
9843 bp
->hwrm_spec_code
< 0x10601) {
9844 rc
= -EPROTONOSUPPORT
;
9848 memcpy(new_fltr
->dst_mac_addr
, eth
->h_dest
, ETH_ALEN
);
9849 memcpy(new_fltr
->src_mac_addr
, eth
->h_source
, ETH_ALEN
);
9851 idx
= skb_get_hash_raw(skb
) & BNXT_NTP_FLTR_HASH_MASK
;
9852 head
= &bp
->ntp_fltr_hash_tbl
[idx
];
9854 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
9855 if (bnxt_fltr_match(fltr
, new_fltr
)) {
9863 spin_lock_bh(&bp
->ntp_fltr_lock
);
9864 bit_id
= bitmap_find_free_region(bp
->ntp_fltr_bmap
,
9865 BNXT_NTP_FLTR_MAX_FLTR
, 0);
9867 spin_unlock_bh(&bp
->ntp_fltr_lock
);
9872 new_fltr
->sw_id
= (u16
)bit_id
;
9873 new_fltr
->flow_id
= flow_id
;
9874 new_fltr
->l2_fltr_idx
= l2_idx
;
9875 new_fltr
->rxq
= rxq_index
;
9876 hlist_add_head_rcu(&new_fltr
->hash
, head
);
9877 bp
->ntp_fltr_count
++;
9878 spin_unlock_bh(&bp
->ntp_fltr_lock
);
9880 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT
, &bp
->sp_event
);
9881 bnxt_queue_sp_work(bp
);
9883 return new_fltr
->sw_id
;
9890 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
9894 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
9895 struct hlist_head
*head
;
9896 struct hlist_node
*tmp
;
9897 struct bnxt_ntuple_filter
*fltr
;
9900 head
= &bp
->ntp_fltr_hash_tbl
[i
];
9901 hlist_for_each_entry_safe(fltr
, tmp
, head
, hash
) {
9904 if (test_bit(BNXT_FLTR_VALID
, &fltr
->state
)) {
9905 if (rps_may_expire_flow(bp
->dev
, fltr
->rxq
,
9908 bnxt_hwrm_cfa_ntuple_filter_free(bp
,
9913 rc
= bnxt_hwrm_cfa_ntuple_filter_alloc(bp
,
9918 set_bit(BNXT_FLTR_VALID
, &fltr
->state
);
9922 spin_lock_bh(&bp
->ntp_fltr_lock
);
9923 hlist_del_rcu(&fltr
->hash
);
9924 bp
->ntp_fltr_count
--;
9925 spin_unlock_bh(&bp
->ntp_fltr_lock
);
9927 clear_bit(fltr
->sw_id
, bp
->ntp_fltr_bmap
);
9932 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT
, &bp
->sp_event
))
9933 netdev_info(bp
->dev
, "Receive PF driver unload event!");
9938 static void bnxt_cfg_ntp_filters(struct bnxt
*bp
)
9942 #endif /* CONFIG_RFS_ACCEL */
9944 static void bnxt_udp_tunnel_add(struct net_device
*dev
,
9945 struct udp_tunnel_info
*ti
)
9947 struct bnxt
*bp
= netdev_priv(dev
);
9949 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
9952 if (!netif_running(dev
))
9956 case UDP_TUNNEL_TYPE_VXLAN
:
9957 if (bp
->vxlan_port_cnt
&& bp
->vxlan_port
!= ti
->port
)
9960 bp
->vxlan_port_cnt
++;
9961 if (bp
->vxlan_port_cnt
== 1) {
9962 bp
->vxlan_port
= ti
->port
;
9963 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
9964 bnxt_queue_sp_work(bp
);
9967 case UDP_TUNNEL_TYPE_GENEVE
:
9968 if (bp
->nge_port_cnt
&& bp
->nge_port
!= ti
->port
)
9972 if (bp
->nge_port_cnt
== 1) {
9973 bp
->nge_port
= ti
->port
;
9974 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT
, &bp
->sp_event
);
9981 bnxt_queue_sp_work(bp
);
9984 static void bnxt_udp_tunnel_del(struct net_device
*dev
,
9985 struct udp_tunnel_info
*ti
)
9987 struct bnxt
*bp
= netdev_priv(dev
);
9989 if (ti
->sa_family
!= AF_INET6
&& ti
->sa_family
!= AF_INET
)
9992 if (!netif_running(dev
))
9996 case UDP_TUNNEL_TYPE_VXLAN
:
9997 if (!bp
->vxlan_port_cnt
|| bp
->vxlan_port
!= ti
->port
)
9999 bp
->vxlan_port_cnt
--;
10001 if (bp
->vxlan_port_cnt
!= 0)
10004 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
10006 case UDP_TUNNEL_TYPE_GENEVE
:
10007 if (!bp
->nge_port_cnt
|| bp
->nge_port
!= ti
->port
)
10009 bp
->nge_port_cnt
--;
10011 if (bp
->nge_port_cnt
!= 0)
10014 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT
, &bp
->sp_event
);
10020 bnxt_queue_sp_work(bp
);
10023 static int bnxt_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
10024 struct net_device
*dev
, u32 filter_mask
,
10027 struct bnxt
*bp
= netdev_priv(dev
);
10029 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, bp
->br_mode
, 0, 0,
10030 nlflags
, filter_mask
, NULL
);
10033 static int bnxt_bridge_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
,
10034 u16 flags
, struct netlink_ext_ack
*extack
)
10036 struct bnxt
*bp
= netdev_priv(dev
);
10037 struct nlattr
*attr
, *br_spec
;
10040 if (bp
->hwrm_spec_code
< 0x10708 || !BNXT_SINGLE_PF(bp
))
10041 return -EOPNOTSUPP
;
10043 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
10047 nla_for_each_nested(attr
, br_spec
, rem
) {
10050 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
10053 if (nla_len(attr
) < sizeof(mode
))
10056 mode
= nla_get_u16(attr
);
10057 if (mode
== bp
->br_mode
)
10060 rc
= bnxt_hwrm_set_br_mode(bp
, mode
);
10062 bp
->br_mode
= mode
;
10068 static int bnxt_get_phys_port_name(struct net_device
*dev
, char *buf
,
10071 struct bnxt
*bp
= netdev_priv(dev
);
10074 /* The PF and it's VF-reps only support the switchdev framework */
10076 return -EOPNOTSUPP
;
10078 rc
= snprintf(buf
, len
, "p%d", bp
->pf
.port_id
);
10081 return -EOPNOTSUPP
;
10085 int bnxt_get_port_parent_id(struct net_device
*dev
,
10086 struct netdev_phys_item_id
*ppid
)
10088 struct bnxt
*bp
= netdev_priv(dev
);
10090 if (bp
->eswitch_mode
!= DEVLINK_ESWITCH_MODE_SWITCHDEV
)
10091 return -EOPNOTSUPP
;
10093 /* The PF and it's VF-reps only support the switchdev framework */
10095 return -EOPNOTSUPP
;
10097 ppid
->id_len
= sizeof(bp
->switch_id
);
10098 memcpy(ppid
->id
, bp
->switch_id
, ppid
->id_len
);
10103 static const struct net_device_ops bnxt_netdev_ops
= {
10104 .ndo_open
= bnxt_open
,
10105 .ndo_start_xmit
= bnxt_start_xmit
,
10106 .ndo_stop
= bnxt_close
,
10107 .ndo_get_stats64
= bnxt_get_stats64
,
10108 .ndo_set_rx_mode
= bnxt_set_rx_mode
,
10109 .ndo_do_ioctl
= bnxt_ioctl
,
10110 .ndo_validate_addr
= eth_validate_addr
,
10111 .ndo_set_mac_address
= bnxt_change_mac_addr
,
10112 .ndo_change_mtu
= bnxt_change_mtu
,
10113 .ndo_fix_features
= bnxt_fix_features
,
10114 .ndo_set_features
= bnxt_set_features
,
10115 .ndo_tx_timeout
= bnxt_tx_timeout
,
10116 #ifdef CONFIG_BNXT_SRIOV
10117 .ndo_get_vf_config
= bnxt_get_vf_config
,
10118 .ndo_set_vf_mac
= bnxt_set_vf_mac
,
10119 .ndo_set_vf_vlan
= bnxt_set_vf_vlan
,
10120 .ndo_set_vf_rate
= bnxt_set_vf_bw
,
10121 .ndo_set_vf_link_state
= bnxt_set_vf_link_state
,
10122 .ndo_set_vf_spoofchk
= bnxt_set_vf_spoofchk
,
10123 .ndo_set_vf_trust
= bnxt_set_vf_trust
,
10125 .ndo_setup_tc
= bnxt_setup_tc
,
10126 #ifdef CONFIG_RFS_ACCEL
10127 .ndo_rx_flow_steer
= bnxt_rx_flow_steer
,
10129 .ndo_udp_tunnel_add
= bnxt_udp_tunnel_add
,
10130 .ndo_udp_tunnel_del
= bnxt_udp_tunnel_del
,
10131 .ndo_bpf
= bnxt_xdp
,
10132 .ndo_bridge_getlink
= bnxt_bridge_getlink
,
10133 .ndo_bridge_setlink
= bnxt_bridge_setlink
,
10134 .ndo_get_port_parent_id
= bnxt_get_port_parent_id
,
10135 .ndo_get_phys_port_name
= bnxt_get_phys_port_name
10138 static void bnxt_remove_one(struct pci_dev
*pdev
)
10140 struct net_device
*dev
= pci_get_drvdata(pdev
);
10141 struct bnxt
*bp
= netdev_priv(dev
);
10144 bnxt_sriov_disable(bp
);
10145 bnxt_dl_unregister(bp
);
10148 pci_disable_pcie_error_reporting(pdev
);
10149 unregister_netdev(dev
);
10150 bnxt_shutdown_tc(bp
);
10151 bnxt_cancel_sp_work(bp
);
10154 bnxt_clear_int_mode(bp
);
10155 bnxt_hwrm_func_drv_unrgtr(bp
);
10156 bnxt_free_hwrm_resources(bp
);
10157 bnxt_free_hwrm_short_cmd_req(bp
);
10158 bnxt_ethtool_free(bp
);
10162 bnxt_free_ctx_mem(bp
);
10165 bnxt_cleanup_pci(bp
);
10166 bnxt_free_port_stats(bp
);
10170 static int bnxt_probe_phy(struct bnxt
*bp
)
10173 struct bnxt_link_info
*link_info
= &bp
->link_info
;
10175 rc
= bnxt_hwrm_phy_qcaps(bp
);
10177 netdev_err(bp
->dev
, "Probe phy can't get phy capabilities (rc: %x)\n",
10181 mutex_init(&bp
->link_lock
);
10183 rc
= bnxt_update_link(bp
, false);
10185 netdev_err(bp
->dev
, "Probe phy can't update link (rc: %x)\n",
10190 /* Older firmware does not have supported_auto_speeds, so assume
10191 * that all supported speeds can be autonegotiated.
10193 if (link_info
->auto_link_speeds
&& !link_info
->support_auto_speeds
)
10194 link_info
->support_auto_speeds
= link_info
->support_speeds
;
10196 /*initialize the ethool setting copy with NVM settings */
10197 if (BNXT_AUTO_MODE(link_info
->auto_mode
)) {
10198 link_info
->autoneg
= BNXT_AUTONEG_SPEED
;
10199 if (bp
->hwrm_spec_code
>= 0x10201) {
10200 if (link_info
->auto_pause_setting
&
10201 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
)
10202 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
10204 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
10206 link_info
->advertising
= link_info
->auto_link_speeds
;
10208 link_info
->req_link_speed
= link_info
->force_link_speed
;
10209 link_info
->req_duplex
= link_info
->duplex_setting
;
10211 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
10212 link_info
->req_flow_ctrl
=
10213 link_info
->auto_pause_setting
& BNXT_LINK_PAUSE_BOTH
;
10215 link_info
->req_flow_ctrl
= link_info
->force_pause_setting
;
10219 static int bnxt_get_max_irq(struct pci_dev
*pdev
)
10223 if (!pdev
->msix_cap
)
10226 pci_read_config_word(pdev
, pdev
->msix_cap
+ PCI_MSIX_FLAGS
, &ctrl
);
10227 return (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
10230 static void _bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
10233 struct bnxt_hw_resc
*hw_resc
= &bp
->hw_resc
;
10234 int max_ring_grps
= 0, max_irq
;
10236 *max_tx
= hw_resc
->max_tx_rings
;
10237 *max_rx
= hw_resc
->max_rx_rings
;
10238 *max_cp
= bnxt_get_max_func_cp_rings_for_en(bp
);
10239 max_irq
= min_t(int, bnxt_get_max_func_irqs(bp
) -
10240 bnxt_get_ulp_msix_num(bp
),
10241 hw_resc
->max_stat_ctxs
- bnxt_get_ulp_stat_ctxs(bp
));
10242 if (!(bp
->flags
& BNXT_FLAG_CHIP_P5
))
10243 *max_cp
= min_t(int, *max_cp
, max_irq
);
10244 max_ring_grps
= hw_resc
->max_hw_ring_grps
;
10245 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) && BNXT_PF(bp
)) {
10249 if (bp
->flags
& BNXT_FLAG_AGG_RINGS
)
10251 if (bp
->flags
& BNXT_FLAG_CHIP_P5
) {
10252 bnxt_trim_rings(bp
, max_rx
, max_tx
, *max_cp
, false);
10253 /* On P5 chips, max_cp output param should be available NQs */
10256 *max_rx
= min_t(int, *max_rx
, max_ring_grps
);
10259 int bnxt_get_max_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
, bool shared
)
10263 _bnxt_get_max_rings(bp
, &rx
, &tx
, &cp
);
10266 if (!rx
|| !tx
|| !cp
)
10269 return bnxt_trim_rings(bp
, max_rx
, max_tx
, cp
, shared
);
10272 static int bnxt_get_dflt_rings(struct bnxt
*bp
, int *max_rx
, int *max_tx
,
10277 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
10278 if (rc
&& (bp
->flags
& BNXT_FLAG_AGG_RINGS
)) {
10279 /* Not enough rings, try disabling agg rings. */
10280 bp
->flags
&= ~BNXT_FLAG_AGG_RINGS
;
10281 rc
= bnxt_get_max_rings(bp
, max_rx
, max_tx
, shared
);
10283 /* set BNXT_FLAG_AGG_RINGS back for consistency */
10284 bp
->flags
|= BNXT_FLAG_AGG_RINGS
;
10287 bp
->flags
|= BNXT_FLAG_NO_AGG_RINGS
;
10288 bp
->dev
->hw_features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
10289 bp
->dev
->features
&= ~(NETIF_F_LRO
| NETIF_F_GRO_HW
);
10290 bnxt_set_ring_params(bp
);
10293 if (bp
->flags
& BNXT_FLAG_ROCE_CAP
) {
10294 int max_cp
, max_stat
, max_irq
;
10296 /* Reserve minimum resources for RoCE */
10297 max_cp
= bnxt_get_max_func_cp_rings(bp
);
10298 max_stat
= bnxt_get_max_func_stat_ctxs(bp
);
10299 max_irq
= bnxt_get_max_func_irqs(bp
);
10300 if (max_cp
<= BNXT_MIN_ROCE_CP_RINGS
||
10301 max_irq
<= BNXT_MIN_ROCE_CP_RINGS
||
10302 max_stat
<= BNXT_MIN_ROCE_STAT_CTXS
)
10305 max_cp
-= BNXT_MIN_ROCE_CP_RINGS
;
10306 max_irq
-= BNXT_MIN_ROCE_CP_RINGS
;
10307 max_stat
-= BNXT_MIN_ROCE_STAT_CTXS
;
10308 max_cp
= min_t(int, max_cp
, max_irq
);
10309 max_cp
= min_t(int, max_cp
, max_stat
);
10310 rc
= bnxt_trim_rings(bp
, max_rx
, max_tx
, max_cp
, shared
);
10317 /* In initial default shared ring setting, each shared ring must have a
10320 static void bnxt_trim_dflt_sh_rings(struct bnxt
*bp
)
10322 bp
->cp_nr_rings
= min_t(int, bp
->tx_nr_rings_per_tc
, bp
->rx_nr_rings
);
10323 bp
->rx_nr_rings
= bp
->cp_nr_rings
;
10324 bp
->tx_nr_rings_per_tc
= bp
->cp_nr_rings
;
10325 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
10328 static int bnxt_set_dflt_rings(struct bnxt
*bp
, bool sh
)
10330 int dflt_rings
, max_rx_rings
, max_tx_rings
, rc
;
10332 if (!bnxt_can_reserve_rings(bp
))
10336 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
10337 dflt_rings
= netif_get_num_default_rss_queues();
10338 /* Reduce default rings on multi-port cards so that total default
10339 * rings do not exceed CPU count.
10341 if (bp
->port_count
> 1) {
10343 max_t(int, num_online_cpus() / bp
->port_count
, 1);
10345 dflt_rings
= min_t(int, dflt_rings
, max_rings
);
10347 rc
= bnxt_get_dflt_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
10350 bp
->rx_nr_rings
= min_t(int, dflt_rings
, max_rx_rings
);
10351 bp
->tx_nr_rings_per_tc
= min_t(int, dflt_rings
, max_tx_rings
);
10353 bnxt_trim_dflt_sh_rings(bp
);
10355 bp
->cp_nr_rings
= bp
->tx_nr_rings_per_tc
+ bp
->rx_nr_rings
;
10356 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
10358 rc
= __bnxt_reserve_rings(bp
);
10360 netdev_warn(bp
->dev
, "Unable to reserve tx rings\n");
10361 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
10363 bnxt_trim_dflt_sh_rings(bp
);
10365 /* Rings may have been trimmed, re-reserve the trimmed rings. */
10366 if (bnxt_need_reserve_rings(bp
)) {
10367 rc
= __bnxt_reserve_rings(bp
);
10369 netdev_warn(bp
->dev
, "2nd rings reservation failed.\n");
10370 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
10372 if (BNXT_CHIP_TYPE_NITRO_A0(bp
)) {
10379 static int bnxt_init_dflt_ring_mode(struct bnxt
*bp
)
10383 if (bp
->tx_nr_rings
)
10386 bnxt_ulp_irq_stop(bp
);
10387 bnxt_clear_int_mode(bp
);
10388 rc
= bnxt_set_dflt_rings(bp
, true);
10390 netdev_err(bp
->dev
, "Not enough rings available.\n");
10391 goto init_dflt_ring_err
;
10393 rc
= bnxt_init_int_mode(bp
);
10395 goto init_dflt_ring_err
;
10397 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
10398 if (bnxt_rfs_supported(bp
) && bnxt_rfs_capable(bp
)) {
10399 bp
->flags
|= BNXT_FLAG_RFS
;
10400 bp
->dev
->features
|= NETIF_F_NTUPLE
;
10402 init_dflt_ring_err
:
10403 bnxt_ulp_irq_restart(bp
, rc
);
10407 int bnxt_restore_pf_fw_resources(struct bnxt
*bp
)
10412 bnxt_hwrm_func_qcaps(bp
);
10414 if (netif_running(bp
->dev
))
10415 __bnxt_close_nic(bp
, true, false);
10417 bnxt_ulp_irq_stop(bp
);
10418 bnxt_clear_int_mode(bp
);
10419 rc
= bnxt_init_int_mode(bp
);
10420 bnxt_ulp_irq_restart(bp
, rc
);
10422 if (netif_running(bp
->dev
)) {
10424 dev_close(bp
->dev
);
10426 rc
= bnxt_open_nic(bp
, true, false);
10432 static int bnxt_init_mac_addr(struct bnxt
*bp
)
10437 memcpy(bp
->dev
->dev_addr
, bp
->pf
.mac_addr
, ETH_ALEN
);
10439 #ifdef CONFIG_BNXT_SRIOV
10440 struct bnxt_vf_info
*vf
= &bp
->vf
;
10441 bool strict_approval
= true;
10443 if (is_valid_ether_addr(vf
->mac_addr
)) {
10444 /* overwrite netdev dev_addr with admin VF MAC */
10445 memcpy(bp
->dev
->dev_addr
, vf
->mac_addr
, ETH_ALEN
);
10446 /* Older PF driver or firmware may not approve this
10449 strict_approval
= false;
10451 eth_hw_addr_random(bp
->dev
);
10453 rc
= bnxt_approve_mac(bp
, bp
->dev
->dev_addr
, strict_approval
);
10459 static int bnxt_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10461 static int version_printed
;
10462 struct net_device
*dev
;
10466 if (pci_is_bridge(pdev
))
10469 if (version_printed
++ == 0)
10470 pr_info("%s", version
);
10472 max_irqs
= bnxt_get_max_irq(pdev
);
10473 dev
= alloc_etherdev_mq(sizeof(*bp
), max_irqs
);
10477 bp
= netdev_priv(dev
);
10478 bnxt_set_max_func_irqs(bp
, max_irqs
);
10480 if (bnxt_vf_pciid(ent
->driver_data
))
10481 bp
->flags
|= BNXT_FLAG_VF
;
10483 if (pdev
->msix_cap
)
10484 bp
->flags
|= BNXT_FLAG_MSIX_CAP
;
10486 rc
= bnxt_init_board(pdev
, dev
);
10488 goto init_err_free
;
10490 dev
->netdev_ops
= &bnxt_netdev_ops
;
10491 dev
->watchdog_timeo
= BNXT_TX_TIMEOUT
;
10492 dev
->ethtool_ops
= &bnxt_ethtool_ops
;
10493 pci_set_drvdata(pdev
, dev
);
10495 rc
= bnxt_alloc_hwrm_resources(bp
);
10497 goto init_err_pci_clean
;
10499 mutex_init(&bp
->hwrm_cmd_lock
);
10500 rc
= bnxt_hwrm_ver_get(bp
);
10502 goto init_err_pci_clean
;
10504 if (bp
->fw_cap
& BNXT_FW_CAP_KONG_MB_CHNL
) {
10505 rc
= bnxt_alloc_kong_hwrm_resources(bp
);
10507 bp
->fw_cap
&= ~BNXT_FW_CAP_KONG_MB_CHNL
;
10510 if ((bp
->fw_cap
& BNXT_FW_CAP_SHORT_CMD
) ||
10511 bp
->hwrm_max_ext_req_len
> BNXT_HWRM_MAX_REQ_LEN
) {
10512 rc
= bnxt_alloc_hwrm_short_cmd_req(bp
);
10514 goto init_err_pci_clean
;
10517 if (BNXT_CHIP_P5(bp
))
10518 bp
->flags
|= BNXT_FLAG_CHIP_P5
;
10520 rc
= bnxt_hwrm_func_reset(bp
);
10522 goto init_err_pci_clean
;
10524 bnxt_hwrm_fw_set_time(bp
);
10526 dev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
10527 NETIF_F_TSO
| NETIF_F_TSO6
|
10528 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
10529 NETIF_F_GSO_IPXIP4
|
10530 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
10531 NETIF_F_GSO_PARTIAL
| NETIF_F_RXHASH
|
10532 NETIF_F_RXCSUM
| NETIF_F_GRO
;
10534 if (BNXT_SUPPORTS_TPA(bp
))
10535 dev
->hw_features
|= NETIF_F_LRO
;
10537 dev
->hw_enc_features
=
10538 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
| NETIF_F_SG
|
10539 NETIF_F_TSO
| NETIF_F_TSO6
|
10540 NETIF_F_GSO_UDP_TUNNEL
| NETIF_F_GSO_GRE
|
10541 NETIF_F_GSO_UDP_TUNNEL_CSUM
| NETIF_F_GSO_GRE_CSUM
|
10542 NETIF_F_GSO_IPXIP4
| NETIF_F_GSO_PARTIAL
;
10543 dev
->gso_partial_features
= NETIF_F_GSO_UDP_TUNNEL_CSUM
|
10544 NETIF_F_GSO_GRE_CSUM
;
10545 dev
->vlan_features
= dev
->hw_features
| NETIF_F_HIGHDMA
;
10546 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_CTAG_TX
|
10547 NETIF_F_HW_VLAN_STAG_RX
| NETIF_F_HW_VLAN_STAG_TX
;
10548 if (BNXT_SUPPORTS_TPA(bp
))
10549 dev
->hw_features
|= NETIF_F_GRO_HW
;
10550 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
10551 if (dev
->features
& NETIF_F_GRO_HW
)
10552 dev
->features
&= ~NETIF_F_LRO
;
10553 dev
->priv_flags
|= IFF_UNICAST_FLT
;
10555 #ifdef CONFIG_BNXT_SRIOV
10556 init_waitqueue_head(&bp
->sriov_cfg_wait
);
10557 mutex_init(&bp
->sriov_lock
);
10559 if (BNXT_SUPPORTS_TPA(bp
)) {
10560 bp
->gro_func
= bnxt_gro_func_5730x
;
10561 if (BNXT_CHIP_P4(bp
))
10562 bp
->gro_func
= bnxt_gro_func_5731x
;
10564 if (!BNXT_CHIP_P4_PLUS(bp
))
10565 bp
->flags
|= BNXT_FLAG_DOUBLE_DB
;
10567 rc
= bnxt_hwrm_func_drv_rgtr(bp
);
10569 goto init_err_pci_clean
;
10571 rc
= bnxt_hwrm_func_rgtr_async_events(bp
, NULL
, 0);
10573 goto init_err_pci_clean
;
10575 bp
->ulp_probe
= bnxt_ulp_probe
;
10577 rc
= bnxt_hwrm_queue_qportcfg(bp
);
10579 netdev_err(bp
->dev
, "hwrm query qportcfg failure rc: %x\n",
10582 goto init_err_pci_clean
;
10584 /* Get the MAX capabilities for this function */
10585 rc
= bnxt_hwrm_func_qcaps(bp
);
10587 netdev_err(bp
->dev
, "hwrm query capability failure rc: %x\n",
10590 goto init_err_pci_clean
;
10592 rc
= bnxt_init_mac_addr(bp
);
10594 dev_err(&pdev
->dev
, "Unable to initialize mac address.\n");
10595 rc
= -EADDRNOTAVAIL
;
10596 goto init_err_pci_clean
;
10599 bnxt_hwrm_func_qcfg(bp
);
10600 bnxt_hwrm_vnic_qcaps(bp
);
10601 bnxt_hwrm_port_led_qcaps(bp
);
10602 bnxt_ethtool_init(bp
);
10605 /* MTU range: 60 - FW defined max */
10606 dev
->min_mtu
= ETH_ZLEN
;
10607 dev
->max_mtu
= bp
->max_mtu
;
10609 rc
= bnxt_probe_phy(bp
);
10611 goto init_err_pci_clean
;
10613 bnxt_set_rx_skb_mode(bp
, false);
10614 bnxt_set_tpa_flags(bp
);
10615 bnxt_set_ring_params(bp
);
10616 rc
= bnxt_set_dflt_rings(bp
, true);
10618 netdev_err(bp
->dev
, "Not enough rings available.\n");
10620 goto init_err_pci_clean
;
10623 /* Default RSS hash cfg. */
10624 bp
->rss_hash_cfg
= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
|
10625 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
|
10626 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
|
10627 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
10628 if (BNXT_CHIP_P4(bp
) && bp
->hwrm_spec_code
>= 0x10501) {
10629 bp
->flags
|= BNXT_FLAG_UDP_RSS_CAP
;
10630 bp
->rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
|
10631 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
10634 if (bnxt_rfs_supported(bp
)) {
10635 dev
->hw_features
|= NETIF_F_NTUPLE
;
10636 if (bnxt_rfs_capable(bp
)) {
10637 bp
->flags
|= BNXT_FLAG_RFS
;
10638 dev
->features
|= NETIF_F_NTUPLE
;
10642 if (dev
->hw_features
& NETIF_F_HW_VLAN_CTAG_RX
)
10643 bp
->flags
|= BNXT_FLAG_STRIP_VLAN
;
10645 rc
= bnxt_init_int_mode(bp
);
10647 goto init_err_pci_clean
;
10649 /* No TC has been set yet and rings may have been trimmed due to
10650 * limited MSIX, so we re-initialize the TX rings per TC.
10652 bp
->tx_nr_rings_per_tc
= bp
->tx_nr_rings
;
10654 bnxt_get_wol_settings(bp
);
10655 if (bp
->flags
& BNXT_FLAG_WOL_CAP
)
10656 device_set_wakeup_enable(&pdev
->dev
, bp
->wol
);
10658 device_set_wakeup_capable(&pdev
->dev
, false);
10660 bnxt_hwrm_set_cache_line_size(bp
, cache_line_size());
10662 bnxt_hwrm_coal_params_qcaps(bp
);
10667 create_singlethread_workqueue("bnxt_pf_wq");
10669 dev_err(&pdev
->dev
, "Unable to create workqueue.\n");
10670 goto init_err_pci_clean
;
10676 rc
= register_netdev(dev
);
10678 goto init_err_cleanup_tc
;
10681 bnxt_dl_register(bp
);
10683 netdev_info(dev
, "%s found at mem %lx, node addr %pM\n",
10684 board_info
[ent
->driver_data
].name
,
10685 (long)pci_resource_start(pdev
, 0), dev
->dev_addr
);
10686 pcie_print_link_status(pdev
);
10690 init_err_cleanup_tc
:
10691 bnxt_shutdown_tc(bp
);
10692 bnxt_clear_int_mode(bp
);
10694 init_err_pci_clean
:
10695 bnxt_free_hwrm_short_cmd_req(bp
);
10696 bnxt_free_hwrm_resources(bp
);
10697 bnxt_free_ctx_mem(bp
);
10700 bnxt_cleanup_pci(bp
);
10707 static void bnxt_shutdown(struct pci_dev
*pdev
)
10709 struct net_device
*dev
= pci_get_drvdata(pdev
);
10716 bp
= netdev_priv(dev
);
10718 goto shutdown_exit
;
10720 if (netif_running(dev
))
10723 bnxt_ulp_shutdown(bp
);
10725 if (system_state
== SYSTEM_POWER_OFF
) {
10726 bnxt_clear_int_mode(bp
);
10727 pci_wake_from_d3(pdev
, bp
->wol
);
10728 pci_set_power_state(pdev
, PCI_D3hot
);
10735 #ifdef CONFIG_PM_SLEEP
10736 static int bnxt_suspend(struct device
*device
)
10738 struct pci_dev
*pdev
= to_pci_dev(device
);
10739 struct net_device
*dev
= pci_get_drvdata(pdev
);
10740 struct bnxt
*bp
= netdev_priv(dev
);
10744 if (netif_running(dev
)) {
10745 netif_device_detach(dev
);
10746 rc
= bnxt_close(dev
);
10748 bnxt_hwrm_func_drv_unrgtr(bp
);
10753 static int bnxt_resume(struct device
*device
)
10755 struct pci_dev
*pdev
= to_pci_dev(device
);
10756 struct net_device
*dev
= pci_get_drvdata(pdev
);
10757 struct bnxt
*bp
= netdev_priv(dev
);
10761 if (bnxt_hwrm_ver_get(bp
) || bnxt_hwrm_func_drv_rgtr(bp
)) {
10765 rc
= bnxt_hwrm_func_reset(bp
);
10770 bnxt_get_wol_settings(bp
);
10771 if (netif_running(dev
)) {
10772 rc
= bnxt_open(dev
);
10774 netif_device_attach(dev
);
10782 static SIMPLE_DEV_PM_OPS(bnxt_pm_ops
, bnxt_suspend
, bnxt_resume
);
10783 #define BNXT_PM_OPS (&bnxt_pm_ops)
10787 #define BNXT_PM_OPS NULL
10789 #endif /* CONFIG_PM_SLEEP */
10792 * bnxt_io_error_detected - called when PCI error is detected
10793 * @pdev: Pointer to PCI device
10794 * @state: The current pci connection state
10796 * This function is called after a PCI bus error affecting
10797 * this device has been detected.
10799 static pci_ers_result_t
bnxt_io_error_detected(struct pci_dev
*pdev
,
10800 pci_channel_state_t state
)
10802 struct net_device
*netdev
= pci_get_drvdata(pdev
);
10803 struct bnxt
*bp
= netdev_priv(netdev
);
10805 netdev_info(netdev
, "PCI I/O error detected\n");
10808 netif_device_detach(netdev
);
10812 if (state
== pci_channel_io_perm_failure
) {
10814 return PCI_ERS_RESULT_DISCONNECT
;
10817 if (netif_running(netdev
))
10818 bnxt_close(netdev
);
10820 pci_disable_device(pdev
);
10823 /* Request a slot slot reset. */
10824 return PCI_ERS_RESULT_NEED_RESET
;
10828 * bnxt_io_slot_reset - called after the pci bus has been reset.
10829 * @pdev: Pointer to PCI device
10831 * Restart the card from scratch, as if from a cold-boot.
10832 * At this point, the card has exprienced a hard reset,
10833 * followed by fixups by BIOS, and has its config space
10834 * set up identically to what it was at cold boot.
10836 static pci_ers_result_t
bnxt_io_slot_reset(struct pci_dev
*pdev
)
10838 struct net_device
*netdev
= pci_get_drvdata(pdev
);
10839 struct bnxt
*bp
= netdev_priv(netdev
);
10841 pci_ers_result_t result
= PCI_ERS_RESULT_DISCONNECT
;
10843 netdev_info(bp
->dev
, "PCI Slot Reset\n");
10847 if (pci_enable_device(pdev
)) {
10848 dev_err(&pdev
->dev
,
10849 "Cannot re-enable PCI device after reset.\n");
10851 pci_set_master(pdev
);
10853 err
= bnxt_hwrm_func_reset(bp
);
10854 if (!err
&& netif_running(netdev
))
10855 err
= bnxt_open(netdev
);
10858 result
= PCI_ERS_RESULT_RECOVERED
;
10859 bnxt_ulp_start(bp
);
10863 if (result
!= PCI_ERS_RESULT_RECOVERED
&& netif_running(netdev
))
10868 return PCI_ERS_RESULT_RECOVERED
;
10872 * bnxt_io_resume - called when traffic can start flowing again.
10873 * @pdev: Pointer to PCI device
10875 * This callback is called when the error recovery driver tells
10876 * us that its OK to resume normal operation.
10878 static void bnxt_io_resume(struct pci_dev
*pdev
)
10880 struct net_device
*netdev
= pci_get_drvdata(pdev
);
10884 netif_device_attach(netdev
);
10889 static const struct pci_error_handlers bnxt_err_handler
= {
10890 .error_detected
= bnxt_io_error_detected
,
10891 .slot_reset
= bnxt_io_slot_reset
,
10892 .resume
= bnxt_io_resume
10895 static struct pci_driver bnxt_pci_driver
= {
10896 .name
= DRV_MODULE_NAME
,
10897 .id_table
= bnxt_pci_tbl
,
10898 .probe
= bnxt_init_one
,
10899 .remove
= bnxt_remove_one
,
10900 .shutdown
= bnxt_shutdown
,
10901 .driver
.pm
= BNXT_PM_OPS
,
10902 .err_handler
= &bnxt_err_handler
,
10903 #if defined(CONFIG_BNXT_SRIOV)
10904 .sriov_configure
= bnxt_sriov_configure
,
10908 static int __init
bnxt_init(void)
10911 return pci_register_driver(&bnxt_pci_driver
);
10914 static void __exit
bnxt_exit(void)
10916 pci_unregister_driver(&bnxt_pci_driver
);
10918 destroy_workqueue(bnxt_pf_wq
);
10922 module_init(bnxt_init
);
10923 module_exit(bnxt_exit
);