2 * Broadcom NetXtreme-C/E network driver.
4 * Copyright (c) 2016 Broadcom, All Rights Reserved.
5 * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/socket.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
38 #include <sys/endian.h>
39 #include <sys/sockio.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/pci/pcireg.h>
46 #include <dev/pci/pcivar.h>
49 #include <net/if_media.h>
50 #include <net/if_var.h>
51 #include <net/ethernet.h>
52 #include <net/iflib.h>
55 #include "opt_inet6.h"
61 #include "bnxt_hwrm.h"
62 #include "bnxt_ioctl.h"
63 #include "bnxt_sysctl.h"
64 #include "hsi_struct_def.h"
70 static pci_vendor_info_t bnxt_vendor_info_array[] =
72 PVID(BROADCOM_VENDOR_ID, BCM57301,
73 "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet Controller"),
74 PVID(BROADCOM_VENDOR_ID, BCM57302,
75 "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet Controller"),
76 PVID(BROADCOM_VENDOR_ID, BCM57304,
77 "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet Controller"),
78 PVID(BROADCOM_VENDOR_ID, BCM57311,
79 "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet"),
80 PVID(BROADCOM_VENDOR_ID, BCM57312,
81 "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet"),
82 PVID(BROADCOM_VENDOR_ID, BCM57314,
83 "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet"),
84 PVID(BROADCOM_VENDOR_ID, BCM57402,
85 "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet Controller"),
86 PVID(BROADCOM_VENDOR_ID, BCM57402_NPAR,
87 "Broadcom BCM57402 NetXtreme-E Partition"),
88 PVID(BROADCOM_VENDOR_ID, BCM57404,
89 "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet Controller"),
90 PVID(BROADCOM_VENDOR_ID, BCM57404_NPAR,
91 "Broadcom BCM57404 NetXtreme-E Partition"),
92 PVID(BROADCOM_VENDOR_ID, BCM57406,
93 "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet Controller"),
94 PVID(BROADCOM_VENDOR_ID, BCM57406_NPAR,
95 "Broadcom BCM57406 NetXtreme-E Partition"),
96 PVID(BROADCOM_VENDOR_ID, BCM57407,
97 "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet Controller"),
98 PVID(BROADCOM_VENDOR_ID, BCM57407_NPAR,
99 "Broadcom BCM57407 NetXtreme-E Ethernet Partition"),
100 PVID(BROADCOM_VENDOR_ID, BCM57407_SFP,
101 "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet Controller"),
102 PVID(BROADCOM_VENDOR_ID, BCM57412,
103 "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet"),
104 PVID(BROADCOM_VENDOR_ID, BCM57412_NPAR1,
105 "Broadcom BCM57412 NetXtreme-E Ethernet Partition"),
106 PVID(BROADCOM_VENDOR_ID, BCM57412_NPAR2,
107 "Broadcom BCM57412 NetXtreme-E Ethernet Partition"),
108 PVID(BROADCOM_VENDOR_ID, BCM57414,
109 "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet"),
110 PVID(BROADCOM_VENDOR_ID, BCM57414_NPAR1,
111 "Broadcom BCM57414 NetXtreme-E Ethernet Partition"),
112 PVID(BROADCOM_VENDOR_ID, BCM57414_NPAR2,
113 "Broadcom BCM57414 NetXtreme-E Ethernet Partition"),
114 PVID(BROADCOM_VENDOR_ID, BCM57416,
115 "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet"),
116 PVID(BROADCOM_VENDOR_ID, BCM57416_NPAR1,
117 "Broadcom BCM57416 NetXtreme-E Ethernet Partition"),
118 PVID(BROADCOM_VENDOR_ID, BCM57416_NPAR2,
119 "Broadcom BCM57416 NetXtreme-E Ethernet Partition"),
120 PVID(BROADCOM_VENDOR_ID, BCM57416_SFP,
121 "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet"),
122 PVID(BROADCOM_VENDOR_ID, BCM57417,
123 "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet"),
124 PVID(BROADCOM_VENDOR_ID, BCM57417_NPAR1,
125 "Broadcom BCM57417 NetXtreme-E Ethernet Partition"),
126 PVID(BROADCOM_VENDOR_ID, BCM57417_NPAR2,
127 "Broadcom BCM57417 NetXtreme-E Ethernet Partition"),
128 PVID(BROADCOM_VENDOR_ID, BCM57417_SFP,
129 "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet"),
130 PVID(BROADCOM_VENDOR_ID, BCM58700,
131 "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet"),
132 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF1,
133 "Broadcom NetXtreme-C Ethernet Virtual Function"),
134 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF2,
135 "Broadcom NetXtreme-C Ethernet Virtual Function"),
136 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF3,
137 "Broadcom NetXtreme-C Ethernet Virtual Function"),
138 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF1,
139 "Broadcom NetXtreme-E Ethernet Virtual Function"),
140 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF2,
141 "Broadcom NetXtreme-E Ethernet Virtual Function"),
142 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF3,
143 "Broadcom NetXtreme-E Ethernet Virtual Function"),
144 /* required last entry */
150 * Function prototypes
153 static void *bnxt_register(device_t dev);
155 /* Soft queue setup and teardown */
156 static int bnxt_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
157 uint64_t *paddrs, int ntxqs, int ntxqsets);
158 static int bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
159 uint64_t *paddrs, int nrxqs, int nrxqsets);
160 static void bnxt_queues_free(if_ctx_t ctx);
162 /* Device setup and teardown */
163 static int bnxt_attach_pre(if_ctx_t ctx);
164 static int bnxt_attach_post(if_ctx_t ctx);
165 static int bnxt_detach(if_ctx_t ctx);
167 /* Device configuration */
168 static void bnxt_init(if_ctx_t ctx);
169 static void bnxt_stop(if_ctx_t ctx);
170 static void bnxt_multi_set(if_ctx_t ctx);
171 static int bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu);
172 static void bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr);
173 static int bnxt_media_change(if_ctx_t ctx);
174 static int bnxt_promisc_set(if_ctx_t ctx, int flags);
175 static uint64_t bnxt_get_counter(if_ctx_t, ift_counter);
176 static void bnxt_update_admin_status(if_ctx_t ctx);
178 /* Interrupt enable / disable */
179 static void bnxt_intr_enable(if_ctx_t ctx);
180 static int bnxt_queue_intr_enable(if_ctx_t ctx, uint16_t qid);
181 static void bnxt_disable_intr(if_ctx_t ctx);
182 static int bnxt_msix_intr_assign(if_ctx_t ctx, int msix);
185 static void bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag);
186 static void bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag);
189 static int bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data);
191 /* Internal support functions */
192 static int bnxt_probe_phy(struct bnxt_softc *softc);
193 static void bnxt_add_media_types(struct bnxt_softc *softc);
194 static int bnxt_pci_mapping(struct bnxt_softc *softc);
195 static void bnxt_pci_mapping_free(struct bnxt_softc *softc);
196 static int bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state);
197 static int bnxt_handle_def_cp(void *arg);
198 static int bnxt_handle_rx_cp(void *arg);
199 static void bnxt_clear_ids(struct bnxt_softc *softc);
200 static void inline bnxt_do_enable_intr(struct bnxt_cp_ring *cpr);
201 static void inline bnxt_do_disable_intr(struct bnxt_cp_ring *cpr);
202 static void bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr);
203 static void bnxt_def_cp_task(void *context);
204 static void bnxt_handle_async_event(struct bnxt_softc *softc,
205 struct cmpl_base *cmpl);
206 static uint8_t get_phy_type(struct bnxt_softc *softc);
207 static uint64_t bnxt_get_baudrate(struct bnxt_link_info *link);
210 * Device Interface Declaration
213 static device_method_t bnxt_methods[] = {
214 /* Device interface */
215 DEVMETHOD(device_register, bnxt_register),
216 DEVMETHOD(device_probe, iflib_device_probe),
217 DEVMETHOD(device_attach, iflib_device_attach),
218 DEVMETHOD(device_detach, iflib_device_detach),
219 DEVMETHOD(device_shutdown, iflib_device_shutdown),
220 DEVMETHOD(device_suspend, iflib_device_suspend),
221 DEVMETHOD(device_resume, iflib_device_resume),
225 static driver_t bnxt_driver = {
226 "bnxt", bnxt_methods, sizeof(struct bnxt_softc),
229 devclass_t bnxt_devclass;
230 DRIVER_MODULE(bnxt, pci, bnxt_driver, bnxt_devclass, 0, 0);
232 MODULE_DEPEND(bnxt, pci, 1, 1, 1);
233 MODULE_DEPEND(bnxt, ether, 1, 1, 1);
234 MODULE_DEPEND(bnxt, iflib, 1, 1, 1);
236 static device_method_t bnxt_iflib_methods[] = {
237 DEVMETHOD(ifdi_tx_queues_alloc, bnxt_tx_queues_alloc),
238 DEVMETHOD(ifdi_rx_queues_alloc, bnxt_rx_queues_alloc),
239 DEVMETHOD(ifdi_queues_free, bnxt_queues_free),
241 DEVMETHOD(ifdi_attach_pre, bnxt_attach_pre),
242 DEVMETHOD(ifdi_attach_post, bnxt_attach_post),
243 DEVMETHOD(ifdi_detach, bnxt_detach),
245 DEVMETHOD(ifdi_init, bnxt_init),
246 DEVMETHOD(ifdi_stop, bnxt_stop),
247 DEVMETHOD(ifdi_multi_set, bnxt_multi_set),
248 DEVMETHOD(ifdi_mtu_set, bnxt_mtu_set),
249 DEVMETHOD(ifdi_media_status, bnxt_media_status),
250 DEVMETHOD(ifdi_media_change, bnxt_media_change),
251 DEVMETHOD(ifdi_promisc_set, bnxt_promisc_set),
252 DEVMETHOD(ifdi_get_counter, bnxt_get_counter),
253 DEVMETHOD(ifdi_update_admin_status, bnxt_update_admin_status),
255 DEVMETHOD(ifdi_intr_enable, bnxt_intr_enable),
256 DEVMETHOD(ifdi_queue_intr_enable, bnxt_queue_intr_enable),
257 DEVMETHOD(ifdi_intr_disable, bnxt_disable_intr),
258 DEVMETHOD(ifdi_msix_intr_assign, bnxt_msix_intr_assign),
260 DEVMETHOD(ifdi_vlan_register, bnxt_vlan_register),
261 DEVMETHOD(ifdi_vlan_unregister, bnxt_vlan_unregister),
263 DEVMETHOD(ifdi_priv_ioctl, bnxt_priv_ioctl),
268 static driver_t bnxt_iflib_driver = {
269 "bnxt", bnxt_iflib_methods, sizeof(struct bnxt_softc)
273 * iflib shared context
276 char bnxt_driver_version[] = "FreeBSD base";
277 extern struct if_txrx bnxt_txrx;
278 static struct if_shared_ctx bnxt_sctx_init = {
279 .isc_magic = IFLIB_MAGIC,
280 .isc_driver = &bnxt_iflib_driver,
281 .isc_nfl = 2, // Number of Free Lists
282 .isc_flags = IFLIB_HAS_RXCQ | IFLIB_HAS_TXCQ,
283 .isc_q_align = PAGE_SIZE,
284 .isc_tx_maxsize = BNXT_TSO_SIZE,
285 .isc_tx_maxsegsize = BNXT_TSO_SIZE,
286 .isc_rx_maxsize = BNXT_TSO_SIZE,
287 .isc_rx_maxsegsize = BNXT_TSO_SIZE,
289 // Only use a single segment to avoid page size constraints
290 .isc_rx_nsegments = 1,
293 .isc_nrxd_min = {16, 16, 16},
294 .isc_nrxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 8,
295 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd),
296 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd)},
297 .isc_nrxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
298 .isc_ntxd_min = {16, 16, 16},
299 .isc_ntxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 2,
300 PAGE_SIZE / sizeof(struct tx_bd_short)},
301 .isc_ntxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
303 .isc_admin_intrcnt = 1,
304 .isc_vendor_info = bnxt_vendor_info_array,
305 .isc_driver_version = bnxt_driver_version,
308 if_shared_ctx_t bnxt_sctx = &bnxt_sctx_init;
315 bnxt_register(device_t dev)
321 * Device Dependent Configuration Functions
324 /* Soft queue setup and teardown */
326 bnxt_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
327 uint64_t *paddrs, int ntxqs, int ntxqsets)
329 struct bnxt_softc *softc;
333 softc = iflib_get_softc(ctx);
335 softc->tx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * ntxqsets,
336 M_DEVBUF, M_NOWAIT | M_ZERO);
337 if (!softc->tx_cp_rings) {
338 device_printf(iflib_get_dev(ctx),
339 "unable to allocate TX completion rings\n");
343 softc->tx_rings = malloc(sizeof(struct bnxt_ring) * ntxqsets,
344 M_DEVBUF, M_NOWAIT | M_ZERO);
345 if (!softc->tx_rings) {
346 device_printf(iflib_get_dev(ctx),
347 "unable to allocate TX rings\n");
349 goto ring_alloc_fail;
351 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * ntxqsets,
352 &softc->tx_stats, 0);
355 bus_dmamap_sync(softc->tx_stats.idi_tag, softc->tx_stats.idi_map,
356 BUS_DMASYNC_PREREAD);
358 for (i = 0; i < ntxqsets; i++) {
359 /* Set up the completion ring */
360 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
361 softc->tx_cp_rings[i].ring.phys_id =
362 (uint16_t)HWRM_NA_SIGNATURE;
363 softc->tx_cp_rings[i].ring.softc = softc;
364 softc->tx_cp_rings[i].ring.id =
365 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
366 softc->tx_cp_rings[i].ring.doorbell =
367 softc->tx_cp_rings[i].ring.id * 0x80;
368 softc->tx_cp_rings[i].ring.ring_size =
369 softc->scctx->isc_ntxd[0];
370 softc->tx_cp_rings[i].ring.vaddr = vaddrs[i * ntxqs];
371 softc->tx_cp_rings[i].ring.paddr = paddrs[i * ntxqs];
373 /* Set up the TX ring */
374 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
375 softc->tx_rings[i].softc = softc;
376 softc->tx_rings[i].id =
377 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
378 softc->tx_rings[i].doorbell = softc->tx_rings[i].id * 0x80;
379 softc->tx_rings[i].ring_size = softc->scctx->isc_ntxd[1];
380 softc->tx_rings[i].vaddr = vaddrs[i * ntxqs + 1];
381 softc->tx_rings[i].paddr = paddrs[i * ntxqs + 1];
383 bnxt_create_tx_sysctls(softc, i);
386 softc->ntxqsets = ntxqsets;
390 free(softc->tx_rings, M_DEVBUF);
392 free(softc->tx_cp_rings, M_DEVBUF);
398 bnxt_queues_free(if_ctx_t ctx)
400 struct bnxt_softc *softc = iflib_get_softc(ctx);
403 iflib_dma_free(&softc->tx_stats);
404 free(softc->tx_rings, M_DEVBUF);
405 softc->tx_rings = NULL;
406 free(softc->tx_cp_rings, M_DEVBUF);
407 softc->tx_cp_rings = NULL;
411 iflib_dma_free(&softc->rx_stats);
412 free(softc->grp_info, M_DEVBUF);
413 free(softc->ag_rings, M_DEVBUF);
414 free(softc->rx_rings, M_DEVBUF);
415 free(softc->rx_cp_rings, M_DEVBUF);
419 bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
420 uint64_t *paddrs, int nrxqs, int nrxqsets)
422 struct bnxt_softc *softc;
426 softc = iflib_get_softc(ctx);
428 softc->rx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * nrxqsets,
429 M_DEVBUF, M_NOWAIT | M_ZERO);
430 if (!softc->rx_cp_rings) {
431 device_printf(iflib_get_dev(ctx),
432 "unable to allocate RX completion rings\n");
436 softc->rx_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
437 M_DEVBUF, M_NOWAIT | M_ZERO);
438 if (!softc->rx_rings) {
439 device_printf(iflib_get_dev(ctx),
440 "unable to allocate RX rings\n");
442 goto ring_alloc_fail;
444 softc->ag_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
445 M_DEVBUF, M_NOWAIT | M_ZERO);
446 if (!softc->ag_rings) {
447 device_printf(iflib_get_dev(ctx),
448 "unable to allocate aggregation rings\n");
452 softc->grp_info = malloc(sizeof(struct bnxt_grp_info) * nrxqsets,
453 M_DEVBUF, M_NOWAIT | M_ZERO);
454 if (!softc->grp_info) {
455 device_printf(iflib_get_dev(ctx),
456 "unable to allocate ring groups\n");
461 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * nrxqsets,
462 &softc->rx_stats, 0);
464 goto hw_stats_alloc_fail;
465 bus_dmamap_sync(softc->rx_stats.idi_tag, softc->rx_stats.idi_map,
466 BUS_DMASYNC_PREREAD);
468 for (i = 0; i < nrxqsets; i++) {
469 /* Allocation the completion ring */
470 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
471 softc->rx_cp_rings[i].ring.phys_id =
472 (uint16_t)HWRM_NA_SIGNATURE;
473 softc->rx_cp_rings[i].ring.softc = softc;
474 softc->rx_cp_rings[i].ring.id = i + 1;
475 softc->rx_cp_rings[i].ring.doorbell =
476 softc->rx_cp_rings[i].ring.id * 0x80;
478 * If this ring overflows, RX stops working.
480 softc->rx_cp_rings[i].ring.ring_size =
481 softc->scctx->isc_nrxd[0];
482 softc->rx_cp_rings[i].ring.vaddr = vaddrs[i * nrxqs];
483 softc->rx_cp_rings[i].ring.paddr = paddrs[i * nrxqs];
485 /* Allocate the RX ring */
486 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
487 softc->rx_rings[i].softc = softc;
488 softc->rx_rings[i].id = i + 1;
489 softc->rx_rings[i].doorbell = softc->rx_rings[i].id * 0x80;
490 softc->rx_rings[i].ring_size = softc->scctx->isc_nrxd[1];
491 softc->rx_rings[i].vaddr = vaddrs[i * nrxqs + 1];
492 softc->rx_rings[i].paddr = paddrs[i * nrxqs + 1];
494 /* Allocate the AG ring */
495 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
496 softc->ag_rings[i].softc = softc;
497 softc->ag_rings[i].id = nrxqsets + i + 1;
498 softc->ag_rings[i].doorbell = softc->ag_rings[i].id * 0x80;
499 softc->ag_rings[i].ring_size = softc->scctx->isc_nrxd[2];
500 softc->ag_rings[i].vaddr = vaddrs[i * nrxqs + 2];
501 softc->ag_rings[i].paddr = paddrs[i * nrxqs + 2];
503 /* Allocate the ring group */
504 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
505 softc->grp_info[i].stats_ctx =
506 softc->rx_cp_rings[i].stats_ctx_id;
507 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
508 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
509 softc->grp_info[i].cp_ring_id =
510 softc->rx_cp_rings[i].ring.phys_id;
512 bnxt_create_rx_sysctls(softc, i);
515 /* And finally, the VNIC */
516 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
517 softc->vnic_info.flow_id = (uint16_t)HWRM_NA_SIGNATURE;
518 softc->vnic_info.filter_id = -1;
519 softc->vnic_info.def_ring_grp = (uint16_t)HWRM_NA_SIGNATURE;
520 softc->vnic_info.cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
521 softc->vnic_info.lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
522 softc->vnic_info.rx_mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
523 softc->vnic_info.mc_list_count = 0;
524 softc->vnic_info.flags = BNXT_VNIC_FLAG_DEFAULT;
525 rc = iflib_dma_alloc(ctx, BNXT_MAX_MC_ADDRS * ETHER_ADDR_LEN,
526 &softc->vnic_info.mc_list, 0);
528 goto mc_list_alloc_fail;
530 /* The VNIC RSS Hash Key */
531 rc = iflib_dma_alloc(ctx, HW_HASH_KEY_SIZE,
532 &softc->vnic_info.rss_hash_key_tbl, 0);
534 goto rss_hash_alloc_fail;
535 bus_dmamap_sync(softc->vnic_info.rss_hash_key_tbl.idi_tag,
536 softc->vnic_info.rss_hash_key_tbl.idi_map,
537 BUS_DMASYNC_PREWRITE);
538 memcpy(softc->vnic_info.rss_hash_key_tbl.idi_vaddr,
539 softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE);
541 /* Allocate the RSS tables */
542 rc = iflib_dma_alloc(ctx, HW_HASH_INDEX_SIZE * sizeof(uint16_t),
543 &softc->vnic_info.rss_grp_tbl, 0);
545 goto rss_grp_alloc_fail;
546 bus_dmamap_sync(softc->vnic_info.rss_grp_tbl.idi_tag,
547 softc->vnic_info.rss_grp_tbl.idi_map,
548 BUS_DMASYNC_PREWRITE);
549 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
550 softc->vnic_info.rss_grp_tbl.idi_size);
552 softc->nrxqsets = nrxqsets;
556 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
558 iflib_dma_free(&softc->vnic_info.mc_list);
560 iflib_dma_free(&softc->rx_stats);
562 free(softc->grp_info, M_DEVBUF);
564 free(softc->ag_rings, M_DEVBUF);
566 free(softc->rx_rings, M_DEVBUF);
568 free(softc->rx_cp_rings, M_DEVBUF);
573 /* Device setup and teardown */
575 bnxt_attach_pre(if_ctx_t ctx)
577 struct bnxt_softc *softc = iflib_get_softc(ctx);
578 if_softc_ctx_t scctx;
582 softc->dev = iflib_get_dev(ctx);
583 softc->media = iflib_get_media(ctx);
584 softc->scctx = iflib_get_softc_ctx(ctx);
585 softc->sctx = iflib_get_sctx(ctx);
586 scctx = softc->scctx;
588 /* TODO: Better way of detecting NPAR/VF is needed */
589 switch (softc->sctx->isc_vendor_info->pvi_device_id) {
600 softc->flags |= BNXT_FLAG_NPAR;
602 case NETXTREME_C_VF1:
603 case NETXTREME_C_VF2:
604 case NETXTREME_C_VF3:
605 case NETXTREME_E_VF1:
606 case NETXTREME_E_VF2:
607 case NETXTREME_E_VF3:
608 softc->flags |= BNXT_FLAG_VF;
612 pci_enable_busmaster(softc->dev);
614 if (bnxt_pci_mapping(softc))
617 /* HWRM setup/init */
618 BNXT_HWRM_LOCK_INIT(softc, device_get_nameunit(softc->dev));
619 rc = bnxt_alloc_hwrm_dma_mem(softc);
623 /* Allocate the TPA start buffer */
624 softc->tpa_start = malloc(sizeof(struct bnxt_full_tpa_start) *
625 (RX_TPA_START_CMPL_AGG_ID_MASK >> RX_TPA_START_CMPL_AGG_ID_SFT),
626 M_DEVBUF, M_NOWAIT | M_ZERO);
627 if (softc->tpa_start == NULL) {
629 device_printf(softc->dev,
630 "Unable to allocate space for TPA\n");
634 /* Get firmware version and compare with driver */
635 softc->ver_info = malloc(sizeof(struct bnxt_ver_info),
636 M_DEVBUF, M_NOWAIT | M_ZERO);
637 if (softc->ver_info == NULL) {
639 device_printf(softc->dev,
640 "Unable to allocate space for version info\n");
643 /* Default minimum required HWRM version */
644 softc->ver_info->hwrm_min_major = 1;
645 softc->ver_info->hwrm_min_minor = 2;
646 softc->ver_info->hwrm_min_update = 2;
648 rc = bnxt_hwrm_ver_get(softc);
650 device_printf(softc->dev, "attach: hwrm ver get failed\n");
655 softc->nvm_info = malloc(sizeof(struct bnxt_nvram_info),
656 M_DEVBUF, M_NOWAIT | M_ZERO);
657 if (softc->nvm_info == NULL) {
659 device_printf(softc->dev,
660 "Unable to allocate space for NVRAM info\n");
663 rc = bnxt_hwrm_nvm_get_dev_info(softc, &softc->nvm_info->mfg_id,
664 &softc->nvm_info->device_id, &softc->nvm_info->sector_size,
665 &softc->nvm_info->size, &softc->nvm_info->reserved_size,
666 &softc->nvm_info->available_size);
668 /* Register the driver with the FW */
669 rc = bnxt_hwrm_func_drv_rgtr(softc);
671 device_printf(softc->dev, "attach: hwrm drv rgtr failed\n");
675 /* Get the HW capabilities */
676 rc = bnxt_hwrm_func_qcaps(softc);
679 iflib_set_mac(ctx, softc->func.mac_addr);
681 scctx->isc_txrx = &bnxt_txrx;
682 scctx->isc_tx_csum_flags = (CSUM_IP | CSUM_TCP | CSUM_UDP |
683 CSUM_TCP_IPV6 | CSUM_UDP_IPV6 | CSUM_TSO);
684 scctx->isc_capenable =
685 /* These are translated to hwassit bits */
686 IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | IFCAP_TSO4 | IFCAP_TSO6 |
687 /* These are checked by iflib */
688 IFCAP_LRO | IFCAP_VLAN_HWFILTER |
689 /* These are part of the iflib mask */
690 IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_VLAN_MTU |
691 IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO |
692 /* These likely get lost... */
693 IFCAP_VLAN_HWCSUM | IFCAP_JUMBO_MTU;
695 /* Get the queue config */
696 rc = bnxt_hwrm_queue_qportcfg(softc);
698 device_printf(softc->dev, "attach: hwrm qportcfg failed\n");
702 /* Now perform a function reset */
703 rc = bnxt_hwrm_func_reset(softc);
704 bnxt_clear_ids(softc);
708 /* Now set up iflib sc */
709 scctx->isc_tx_nsegments = 31,
710 scctx->isc_tx_tso_segments_max = 31;
711 scctx->isc_tx_tso_size_max = BNXT_TSO_SIZE;
712 scctx->isc_tx_tso_segsize_max = BNXT_TSO_SIZE;
713 scctx->isc_vectors = softc->func.max_cp_rings;
714 if (scctx->isc_nrxd[0] <
715 ((scctx->isc_nrxd[1] * 4) + scctx->isc_nrxd[2]))
716 device_printf(softc->dev,
717 "WARNING: nrxd0 (%d) should be at least 4 * nrxd1 (%d) + nrxd2 (%d). Driver may be unstable\n",
718 scctx->isc_nrxd[0], scctx->isc_nrxd[1], scctx->isc_nrxd[2]);
719 if (scctx->isc_ntxd[0] < scctx->isc_ntxd[1] * 2)
720 device_printf(softc->dev,
721 "WARNING: ntxd0 (%d) should be at least 2 * ntxd1 (%d). Driver may be unstable\n",
722 scctx->isc_ntxd[0], scctx->isc_ntxd[1]);
723 scctx->isc_txqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_ntxd[0];
724 scctx->isc_txqsizes[1] = sizeof(struct tx_bd_short) *
726 scctx->isc_rxqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_nrxd[0];
727 scctx->isc_rxqsizes[1] = sizeof(struct rx_prod_pkt_bd) *
729 scctx->isc_rxqsizes[2] = sizeof(struct rx_prod_pkt_bd) *
731 scctx->isc_max_rxqsets = min(pci_msix_count(softc->dev)-1,
732 softc->func.max_cp_rings - 1);
733 scctx->isc_max_rxqsets = min(scctx->isc_max_rxqsets,
734 softc->func.max_rx_rings);
735 scctx->isc_max_txqsets = min(softc->func.max_rx_rings,
736 softc->func.max_cp_rings - scctx->isc_max_rxqsets - 1);
737 scctx->isc_rss_table_size = HW_HASH_INDEX_SIZE;
738 scctx->isc_rss_table_mask = scctx->isc_rss_table_size - 1;
740 /* iflib will map and release this bar */
741 scctx->isc_msix_bar = pci_msix_table_bar(softc->dev);
743 /* Allocate the default completion ring */
744 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
745 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
746 softc->def_cp_ring.ring.softc = softc;
747 softc->def_cp_ring.ring.id = 0;
748 softc->def_cp_ring.ring.doorbell = softc->def_cp_ring.ring.id * 0x80;
749 softc->def_cp_ring.ring.ring_size = PAGE_SIZE /
750 sizeof(struct cmpl_base);
751 rc = iflib_dma_alloc(ctx,
752 sizeof(struct cmpl_base) * softc->def_cp_ring.ring.ring_size,
753 &softc->def_cp_ring_mem, 0);
754 softc->def_cp_ring.ring.vaddr = softc->def_cp_ring_mem.idi_vaddr;
755 softc->def_cp_ring.ring.paddr = softc->def_cp_ring_mem.idi_paddr;
756 iflib_config_gtask_init(ctx, &softc->def_cp_task, bnxt_def_cp_task,
759 rc = bnxt_init_sysctl_ctx(softc);
761 goto init_sysctl_failed;
762 rc = bnxt_create_nvram_sysctls(softc->nvm_info);
766 arc4rand(softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE, 0);
767 softc->vnic_info.rss_hash_type =
768 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4 |
769 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4 |
770 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4 |
771 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6 |
772 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6 |
773 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
774 rc = bnxt_create_config_sysctls_pre(softc);
778 /* Initialize the vlan list */
779 SLIST_INIT(&softc->vnic_info.vlan_tags);
780 softc->vnic_info.vlan_tag_list.idi_vaddr = NULL;
785 bnxt_free_sysctl_ctx(softc);
787 bnxt_hwrm_func_drv_unrgtr(softc, false);
789 free(softc->nvm_info, M_DEVBUF);
792 free(softc->ver_info, M_DEVBUF);
794 free(softc->tpa_start, M_DEVBUF);
796 bnxt_free_hwrm_dma_mem(softc);
798 BNXT_HWRM_LOCK_DESTROY(softc);
799 bnxt_pci_mapping_free(softc);
800 pci_disable_busmaster(softc->dev);
805 bnxt_attach_post(if_ctx_t ctx)
807 struct bnxt_softc *softc = iflib_get_softc(ctx);
808 if_t ifp = iflib_get_ifp(ctx);
811 bnxt_create_config_sysctls_post(softc);
813 /* Update link state etc... */
814 rc = bnxt_probe_phy(softc);
818 /* Needs to be done after probing the phy */
819 bnxt_create_ver_sysctls(softc);
820 bnxt_add_media_types(softc);
821 ifmedia_set(softc->media, IFM_ETHER | IFM_AUTO);
823 softc->scctx->isc_max_frame_size = ifp->if_mtu + ETHER_HDR_LEN +
831 bnxt_detach(if_ctx_t ctx)
833 struct bnxt_softc *softc = iflib_get_softc(ctx);
834 struct bnxt_vlan_tag *tag;
835 struct bnxt_vlan_tag *tmp;
838 bnxt_do_disable_intr(&softc->def_cp_ring);
839 bnxt_free_sysctl_ctx(softc);
840 bnxt_hwrm_func_reset(softc);
841 bnxt_clear_ids(softc);
842 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
843 iflib_config_gtask_deinit(&softc->def_cp_task);
844 /* We need to free() these here... */
845 for (i = softc->nrxqsets-1; i>=0; i--) {
846 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
848 iflib_dma_free(&softc->vnic_info.mc_list);
849 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
850 iflib_dma_free(&softc->vnic_info.rss_grp_tbl);
851 if (softc->vnic_info.vlan_tag_list.idi_vaddr)
852 iflib_dma_free(&softc->vnic_info.vlan_tag_list);
853 SLIST_FOREACH_SAFE(tag, &softc->vnic_info.vlan_tags, next, tmp)
855 iflib_dma_free(&softc->def_cp_ring_mem);
856 free(softc->tpa_start, M_DEVBUF);
857 free(softc->ver_info, M_DEVBUF);
858 free(softc->nvm_info, M_DEVBUF);
860 bnxt_hwrm_func_drv_unrgtr(softc, false);
861 bnxt_free_hwrm_dma_mem(softc);
862 BNXT_HWRM_LOCK_DESTROY(softc);
864 pci_disable_busmaster(softc->dev);
865 bnxt_pci_mapping_free(softc);
870 /* Device configuration */
872 bnxt_init(if_ctx_t ctx)
874 struct bnxt_softc *softc = iflib_get_softc(ctx);
875 struct ifmediareq ifmr;
879 rc = bnxt_hwrm_func_reset(softc);
882 bnxt_clear_ids(softc);
884 /* Allocate the default completion ring */
885 softc->def_cp_ring.cons = UINT32_MAX;
886 softc->def_cp_ring.v_bit = 1;
887 bnxt_mark_cpr_invalid(&softc->def_cp_ring);
888 rc = bnxt_hwrm_ring_alloc(softc,
889 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
890 &softc->def_cp_ring.ring,
891 (uint16_t)HWRM_NA_SIGNATURE,
892 HWRM_NA_SIGNATURE, true);
896 /* And now set the default CP ring as the async CP ring */
897 rc = bnxt_hwrm_func_cfg(softc);
901 for (i = 0; i < softc->nrxqsets; i++) {
902 /* Allocate the statistics context */
903 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->rx_cp_rings[i],
904 softc->rx_stats.idi_paddr +
905 (sizeof(struct ctx_hw_stats) * i));
909 /* Allocate the completion ring */
910 softc->rx_cp_rings[i].cons = UINT32_MAX;
911 softc->rx_cp_rings[i].v_bit = 1;
912 softc->rx_cp_rings[i].last_idx = UINT32_MAX;
913 bnxt_mark_cpr_invalid(&softc->rx_cp_rings[i]);
914 rc = bnxt_hwrm_ring_alloc(softc,
915 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
916 &softc->rx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
917 HWRM_NA_SIGNATURE, true);
921 /* Allocate the RX ring */
922 rc = bnxt_hwrm_ring_alloc(softc,
923 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
924 &softc->rx_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
925 HWRM_NA_SIGNATURE, false);
928 BNXT_RX_DB(&softc->rx_rings[i], 0);
929 /* TODO: Cumulus+ doesn't need the double doorbell */
930 BNXT_RX_DB(&softc->rx_rings[i], 0);
932 /* Allocate the AG ring */
933 rc = bnxt_hwrm_ring_alloc(softc,
934 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
935 &softc->ag_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
936 HWRM_NA_SIGNATURE, false);
939 BNXT_RX_DB(&softc->rx_rings[i], 0);
940 /* TODO: Cumulus+ doesn't need the double doorbell */
941 BNXT_RX_DB(&softc->ag_rings[i], 0);
943 /* Allocate the ring group */
944 softc->grp_info[i].stats_ctx =
945 softc->rx_cp_rings[i].stats_ctx_id;
946 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
947 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
948 softc->grp_info[i].cp_ring_id =
949 softc->rx_cp_rings[i].ring.phys_id;
950 rc = bnxt_hwrm_ring_grp_alloc(softc, &softc->grp_info[i]);
956 /* Allocate the VNIC RSS context */
957 rc = bnxt_hwrm_vnic_ctx_alloc(softc, &softc->vnic_info.rss_id);
961 /* Allocate the vnic */
962 softc->vnic_info.def_ring_grp = softc->grp_info[0].grp_id;
963 softc->vnic_info.mru = softc->scctx->isc_max_frame_size;
964 rc = bnxt_hwrm_vnic_alloc(softc, &softc->vnic_info);
967 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
970 rc = bnxt_hwrm_set_filter(softc, &softc->vnic_info);
974 /* Enable RSS on the VNICs */
975 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
977 softc->vnic_info.rss_grp_tbl.idi_vaddr)[i] =
978 htole16(softc->grp_info[j].grp_id);
979 if (++j == softc->nrxqsets)
983 rc = bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
984 softc->vnic_info.rss_hash_type);
989 /* Enable LRO/TPA/GRO */
990 rc = bnxt_hwrm_vnic_tpa_cfg(softc, &softc->vnic_info,
991 (if_getcapenable(iflib_get_ifp(ctx)) & IFCAP_LRO) ?
992 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA : 0);
997 for (i = 0; i < softc->ntxqsets; i++) {
998 /* Allocate the statistics context */
999 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->tx_cp_rings[i],
1000 softc->tx_stats.idi_paddr +
1001 (sizeof(struct ctx_hw_stats) * i));
1005 /* Allocate the completion ring */
1006 softc->tx_cp_rings[i].cons = UINT32_MAX;
1007 softc->tx_cp_rings[i].v_bit = 1;
1008 bnxt_mark_cpr_invalid(&softc->tx_cp_rings[i]);
1009 rc = bnxt_hwrm_ring_alloc(softc,
1010 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
1011 &softc->tx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
1012 HWRM_NA_SIGNATURE, false);
1016 /* Allocate the TX ring */
1017 rc = bnxt_hwrm_ring_alloc(softc,
1018 HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
1019 &softc->tx_rings[i], softc->tx_cp_rings[i].ring.phys_id,
1020 softc->tx_cp_rings[i].stats_ctx_id, false);
1023 BNXT_TX_DB(&softc->tx_rings[i], 0);
1024 /* TODO: Cumulus+ doesn't need the double doorbell */
1025 BNXT_TX_DB(&softc->tx_rings[i], 0);
1028 bnxt_do_enable_intr(&softc->def_cp_ring);
1029 bnxt_media_status(softc->ctx, &ifmr);
1033 bnxt_hwrm_func_reset(softc);
1034 bnxt_clear_ids(softc);
1039 bnxt_stop(if_ctx_t ctx)
1041 struct bnxt_softc *softc = iflib_get_softc(ctx);
1043 bnxt_do_disable_intr(&softc->def_cp_ring);
1044 bnxt_hwrm_func_reset(softc);
1045 bnxt_clear_ids(softc);
1050 bnxt_multi_set(if_ctx_t ctx)
1052 struct bnxt_softc *softc = iflib_get_softc(ctx);
1053 if_t ifp = iflib_get_ifp(ctx);
1057 mcnt = if_multiaddr_count(ifp, -1);
1059 if (mcnt > BNXT_MAX_MC_ADDRS) {
1060 softc->vnic_info.rx_mask |=
1061 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1062 bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1065 softc->vnic_info.rx_mask &=
1066 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1067 mta = softc->vnic_info.mc_list.idi_vaddr;
1068 bzero(mta, softc->vnic_info.mc_list.idi_size);
1069 if_multiaddr_array(ifp, mta, &cnt, mcnt);
1070 bus_dmamap_sync(softc->vnic_info.mc_list.idi_tag,
1071 softc->vnic_info.mc_list.idi_map, BUS_DMASYNC_PREWRITE);
1072 softc->vnic_info.mc_list_count = cnt;
1073 softc->vnic_info.rx_mask |=
1074 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
1075 if (bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info))
1076 device_printf(softc->dev,
1077 "set_multi: rx_mask set failed\n");
1082 bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu)
1084 struct bnxt_softc *softc = iflib_get_softc(ctx);
1086 if (mtu > BNXT_MAX_MTU)
1089 softc->scctx->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1094 bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
1096 struct bnxt_softc *softc = iflib_get_softc(ctx);
1097 struct bnxt_link_info *link_info = &softc->link_info;
1098 uint8_t phy_type = get_phy_type(softc);
1100 bnxt_update_link(softc, true);
1102 ifmr->ifm_status = IFM_AVALID;
1103 ifmr->ifm_active = IFM_ETHER;
1105 if (link_info->link_up)
1106 ifmr->ifm_status |= IFM_ACTIVE;
1108 ifmr->ifm_status &= ~IFM_ACTIVE;
1110 if (link_info->duplex == HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
1111 ifmr->ifm_active |= IFM_FDX;
1113 ifmr->ifm_active |= IFM_HDX;
1115 switch (link_info->link_speed) {
1116 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1117 ifmr->ifm_active |= IFM_100_T;
1119 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1121 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1122 ifmr->ifm_active |= IFM_1000_KX;
1124 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1125 ifmr->ifm_active |= IFM_1000_T;
1127 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
1128 ifmr->ifm_active |= IFM_1000_SGMII;
1131 ifmr->ifm_active |= IFM_UNKNOWN;
1135 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1137 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1138 ifmr->ifm_active |= IFM_2500_KX;
1140 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1141 ifmr->ifm_active |= IFM_2500_T;
1144 ifmr->ifm_active |= IFM_UNKNOWN;
1148 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1150 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1151 ifmr->ifm_active |= IFM_10G_CR1;
1153 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1154 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1155 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1156 ifmr->ifm_active |= IFM_10G_KR;
1158 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1159 ifmr->ifm_active |= IFM_10G_LR;
1161 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1162 ifmr->ifm_active |= IFM_10G_SR;
1164 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1165 ifmr->ifm_active |= IFM_10G_KX4;
1167 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1168 ifmr->ifm_active |= IFM_10G_T;
1171 ifmr->ifm_active |= IFM_UNKNOWN;
1175 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1176 ifmr->ifm_active |= IFM_20G_KR2;
1178 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1180 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1181 ifmr->ifm_active |= IFM_25G_CR;
1183 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1184 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1185 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1186 ifmr->ifm_active |= IFM_25G_KR;
1188 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1189 ifmr->ifm_active |= IFM_25G_SR;
1192 ifmr->ifm_active |= IFM_UNKNOWN;
1196 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1198 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1199 ifmr->ifm_active |= IFM_40G_CR4;
1201 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1202 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1203 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1204 ifmr->ifm_active |= IFM_40G_KR4;
1206 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1207 ifmr->ifm_active |= IFM_40G_LR4;
1209 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1210 ifmr->ifm_active |= IFM_40G_SR4;
1213 ifmr->ifm_active |= IFM_UNKNOWN;
1217 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1219 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1220 ifmr->ifm_active |= IFM_50G_CR2;
1222 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1223 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1224 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1225 ifmr->ifm_active |= IFM_50G_KR2;
1228 ifmr->ifm_active |= IFM_UNKNOWN;
1232 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
1234 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1235 ifmr->ifm_active |= IFM_100G_CR4;
1237 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1238 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1239 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1240 ifmr->ifm_active |= IFM_100G_KR4;
1242 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1243 ifmr->ifm_active |= IFM_100G_LR4;
1245 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1246 ifmr->ifm_active |= IFM_100G_SR4;
1249 ifmr->ifm_active |= IFM_UNKNOWN;
1256 if (link_info->pause == (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1257 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1258 ifmr->ifm_active |= (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
1259 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
1260 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
1261 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
1262 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
1264 bnxt_report_link(softc);
1269 bnxt_media_change(if_ctx_t ctx)
1271 struct bnxt_softc *softc = iflib_get_softc(ctx);
1272 struct ifmedia *ifm = iflib_get_media(ctx);
1273 struct ifmediareq ifmr;
1276 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1279 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1281 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1282 softc->link_info.req_link_speed =
1283 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
1287 case IFM_1000_SGMII:
1288 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1289 softc->link_info.req_link_speed =
1290 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
1294 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1295 softc->link_info.req_link_speed =
1296 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
1303 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1304 softc->link_info.req_link_speed =
1305 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1308 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1309 softc->link_info.req_link_speed =
1310 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
1315 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1316 softc->link_info.req_link_speed =
1317 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
1323 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1324 softc->link_info.req_link_speed =
1325 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1329 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1330 softc->link_info.req_link_speed =
1331 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1337 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1338 softc->link_info.req_link_speed =
1339 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
1342 device_printf(softc->dev,
1343 "Unsupported media type! Using auto\n");
1347 softc->link_info.autoneg |= BNXT_AUTONEG_SPEED;
1350 rc = bnxt_hwrm_set_link_setting(softc, true, true);
1351 bnxt_media_status(softc->ctx, &ifmr);
1356 bnxt_promisc_set(if_ctx_t ctx, int flags)
1358 struct bnxt_softc *softc = iflib_get_softc(ctx);
1359 if_t ifp = iflib_get_ifp(ctx);
1362 if (ifp->if_flags & IFF_ALLMULTI ||
1363 if_multiaddr_count(ifp, -1) > BNXT_MAX_MC_ADDRS)
1364 softc->vnic_info.rx_mask |=
1365 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1367 softc->vnic_info.rx_mask &=
1368 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1370 if (ifp->if_flags & IFF_PROMISC)
1371 softc->vnic_info.rx_mask |=
1372 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1373 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN;
1375 softc->vnic_info.rx_mask &=
1376 ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1377 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
1379 rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1385 bnxt_get_counter(if_ctx_t ctx, ift_counter cnt)
1387 if_t ifp = iflib_get_ifp(ctx);
1389 if (cnt < IFCOUNTERS)
1390 return if_get_counter_default(ifp, cnt);
1396 bnxt_update_admin_status(if_ctx_t ctx)
1398 /* TODO: do we need to do anything here? */
1403 bnxt_do_enable_intr(struct bnxt_cp_ring *cpr)
1405 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE) {
1406 /* First time enabling, do not set index */
1407 if (cpr->cons == UINT32_MAX)
1408 BNXT_CP_ENABLE_DB(&cpr->ring);
1410 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
1415 bnxt_do_disable_intr(struct bnxt_cp_ring *cpr)
1417 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE)
1418 BNXT_CP_DISABLE_DB(&cpr->ring);
1421 /* Enable all interrupts */
1423 bnxt_intr_enable(if_ctx_t ctx)
1425 struct bnxt_softc *softc = iflib_get_softc(ctx);
1428 bnxt_do_enable_intr(&softc->def_cp_ring);
1429 for (i = 0; i < softc->nrxqsets; i++)
1430 bnxt_do_enable_intr(&softc->rx_cp_rings[i]);
1435 /* Enable interrupt for a single queue */
1437 bnxt_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1439 struct bnxt_softc *softc = iflib_get_softc(ctx);
1441 bnxt_do_enable_intr(&softc->rx_cp_rings[qid]);
1445 /* Disable all interrupts */
1447 bnxt_disable_intr(if_ctx_t ctx)
1449 struct bnxt_softc *softc = iflib_get_softc(ctx);
1453 * NOTE: These TX interrupts should never get enabled, so don't
1456 for (i = 0; i < softc->ntxqsets; i++)
1457 bnxt_do_disable_intr(&softc->tx_cp_rings[i]);
1458 for (i = 0; i < softc->nrxqsets; i++)
1459 bnxt_do_disable_intr(&softc->rx_cp_rings[i]);
1465 bnxt_msix_intr_assign(if_ctx_t ctx, int msix)
1467 struct bnxt_softc *softc = iflib_get_softc(ctx);
1471 rc = iflib_irq_alloc_generic(ctx, &softc->def_cp_ring.irq,
1472 softc->def_cp_ring.ring.id + 1, IFLIB_INTR_ADMIN,
1473 bnxt_handle_def_cp, softc, 0, "def_cp");
1475 device_printf(iflib_get_dev(ctx),
1476 "Failed to register default completion ring handler\n");
1480 for (i=0; i<softc->scctx->isc_nrxqsets; i++) {
1481 rc = iflib_irq_alloc_generic(ctx, &softc->rx_cp_rings[i].irq,
1482 softc->rx_cp_rings[i].ring.id + 1, IFLIB_INTR_RX,
1483 bnxt_handle_rx_cp, &softc->rx_cp_rings[i], i, "rx_cp");
1485 device_printf(iflib_get_dev(ctx),
1486 "Failed to register RX completion ring handler\n");
1492 for (i=0; i<softc->scctx->isc_ntxqsets; i++)
1493 iflib_softirq_alloc_generic(ctx, i + 1, IFLIB_INTR_TX, NULL, i,
1500 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
1501 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
1506 * We're explicitly allowing duplicates here. They will need to be
1507 * removed as many times as they are added.
1510 bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag)
1512 struct bnxt_softc *softc = iflib_get_softc(ctx);
1513 struct bnxt_vlan_tag *new_tag;
1515 new_tag = malloc(sizeof(struct bnxt_vlan_tag), M_DEVBUF, M_NOWAIT);
1516 if (new_tag == NULL)
1518 new_tag->tag = vtag;
1519 new_tag->tpid = 8100;
1520 SLIST_INSERT_HEAD(&softc->vnic_info.vlan_tags, new_tag, next);
1524 bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag)
1526 struct bnxt_softc *softc = iflib_get_softc(ctx);
1527 struct bnxt_vlan_tag *vlan_tag;
1529 SLIST_FOREACH(vlan_tag, &softc->vnic_info.vlan_tags, next) {
1530 if (vlan_tag->tag == vtag) {
1531 SLIST_REMOVE(&softc->vnic_info.vlan_tags, vlan_tag,
1532 bnxt_vlan_tag, next);
1533 free(vlan_tag, M_DEVBUF);
1540 bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data)
1542 struct bnxt_softc *softc = iflib_get_softc(ctx);
1543 struct ifreq *ifr = (struct ifreq *)data;
1544 struct ifreq_buffer *ifbuf = &ifr->ifr_ifru.ifru_buffer;
1545 struct bnxt_ioctl_header *ioh =
1546 (struct bnxt_ioctl_header *)(ifbuf->buffer);
1548 struct bnxt_ioctl_data *iod = NULL;
1551 case SIOCGPRIVATE_0:
1552 if ((rc = priv_check(curthread, PRIV_DRIVER)) != 0)
1555 iod = malloc(ifbuf->length, M_DEVBUF, M_NOWAIT | M_ZERO);
1560 copyin(ioh, iod, ifbuf->length);
1562 switch (ioh->type) {
1563 case BNXT_HWRM_NVM_FIND_DIR_ENTRY:
1565 struct bnxt_ioctl_hwrm_nvm_find_dir_entry *find =
1568 rc = bnxt_hwrm_nvm_find_dir_entry(softc, find->type,
1569 &find->ordinal, find->ext, &find->index,
1570 find->use_index, find->search_opt,
1571 &find->data_length, &find->item_length,
1575 copyout(&iod->hdr.rc, &ioh->rc,
1580 copyout(iod, ioh, ifbuf->length);
1586 case BNXT_HWRM_NVM_READ:
1588 struct bnxt_ioctl_hwrm_nvm_read *rd = &iod->read;
1589 struct iflib_dma_info dma_data;
1595 * Some HWRM versions can't read more than 0x8000 bytes
1597 rc = iflib_dma_alloc(softc->ctx,
1598 min(rd->length, 0x8000), &dma_data, BUS_DMA_NOWAIT);
1601 for (remain = rd->length, offset = 0;
1602 remain && offset < rd->length; offset += 0x8000) {
1603 csize = min(remain, 0x8000);
1604 rc = bnxt_hwrm_nvm_read(softc, rd->index,
1605 rd->offset + offset, csize, &dma_data);
1608 copyout(&iod->hdr.rc, &ioh->rc,
1613 copyout(dma_data.idi_vaddr,
1614 rd->data + offset, csize);
1619 if (iod->hdr.rc == 0)
1620 copyout(iod, ioh, ifbuf->length);
1622 iflib_dma_free(&dma_data);
1626 case BNXT_HWRM_FW_RESET:
1628 struct bnxt_ioctl_hwrm_fw_reset *rst =
1631 rc = bnxt_hwrm_fw_reset(softc, rst->processor,
1635 copyout(&iod->hdr.rc, &ioh->rc,
1640 copyout(iod, ioh, ifbuf->length);
1646 case BNXT_HWRM_FW_QSTATUS:
1648 struct bnxt_ioctl_hwrm_fw_qstatus *qstat =
1651 rc = bnxt_hwrm_fw_qstatus(softc, qstat->processor,
1655 copyout(&iod->hdr.rc, &ioh->rc,
1660 copyout(iod, ioh, ifbuf->length);
1666 case BNXT_HWRM_NVM_WRITE:
1668 struct bnxt_ioctl_hwrm_nvm_write *wr =
1671 rc = bnxt_hwrm_nvm_write(softc, wr->data, true,
1672 wr->type, wr->ordinal, wr->ext, wr->attr,
1673 wr->option, wr->data_length, wr->keep,
1674 &wr->item_length, &wr->index);
1677 copyout(&iod->hdr.rc, &ioh->rc,
1682 copyout(iod, ioh, ifbuf->length);
1688 case BNXT_HWRM_NVM_ERASE_DIR_ENTRY:
1690 struct bnxt_ioctl_hwrm_nvm_erase_dir_entry *erase =
1693 rc = bnxt_hwrm_nvm_erase_dir_entry(softc, erase->index);
1696 copyout(&iod->hdr.rc, &ioh->rc,
1701 copyout(iod, ioh, ifbuf->length);
1707 case BNXT_HWRM_NVM_GET_DIR_INFO:
1709 struct bnxt_ioctl_hwrm_nvm_get_dir_info *info =
1712 rc = bnxt_hwrm_nvm_get_dir_info(softc, &info->entries,
1713 &info->entry_length);
1716 copyout(&iod->hdr.rc, &ioh->rc,
1721 copyout(iod, ioh, ifbuf->length);
1727 case BNXT_HWRM_NVM_GET_DIR_ENTRIES:
1729 struct bnxt_ioctl_hwrm_nvm_get_dir_entries *get =
1731 struct iflib_dma_info dma_data;
1733 rc = iflib_dma_alloc(softc->ctx, get->max_size,
1734 &dma_data, BUS_DMA_NOWAIT);
1737 rc = bnxt_hwrm_nvm_get_dir_entries(softc, &get->entries,
1738 &get->entry_length, &dma_data);
1741 copyout(&iod->hdr.rc, &ioh->rc,
1745 copyout(dma_data.idi_vaddr, get->data,
1746 get->entry_length * get->entries);
1748 copyout(iod, ioh, ifbuf->length);
1750 iflib_dma_free(&dma_data);
1755 case BNXT_HWRM_NVM_VERIFY_UPDATE:
1757 struct bnxt_ioctl_hwrm_nvm_verify_update *vrfy =
1760 rc = bnxt_hwrm_nvm_verify_update(softc, vrfy->type,
1761 vrfy->ordinal, vrfy->ext);
1764 copyout(&iod->hdr.rc, &ioh->rc,
1769 copyout(iod, ioh, ifbuf->length);
1775 case BNXT_HWRM_NVM_INSTALL_UPDATE:
1777 struct bnxt_ioctl_hwrm_nvm_install_update *inst =
1780 rc = bnxt_hwrm_nvm_install_update(softc,
1781 inst->install_type, &inst->installed_items,
1782 &inst->result, &inst->problem_item,
1783 &inst->reset_required);
1786 copyout(&iod->hdr.rc, &ioh->rc,
1791 copyout(iod, ioh, ifbuf->length);
1797 case BNXT_HWRM_NVM_MODIFY:
1799 struct bnxt_ioctl_hwrm_nvm_modify *mod = &iod->modify;
1801 rc = bnxt_hwrm_nvm_modify(softc, mod->index,
1802 mod->offset, mod->data, true, mod->length);
1805 copyout(&iod->hdr.rc, &ioh->rc,
1810 copyout(iod, ioh, ifbuf->length);
1816 case BNXT_HWRM_FW_GET_TIME:
1818 struct bnxt_ioctl_hwrm_fw_get_time *gtm =
1821 rc = bnxt_hwrm_fw_get_time(softc, >m->year,
1822 >m->month, >m->day, >m->hour, >m->minute,
1823 >m->second, >m->millisecond, >m->zone);
1826 copyout(&iod->hdr.rc, &ioh->rc,
1831 copyout(iod, ioh, ifbuf->length);
1837 case BNXT_HWRM_FW_SET_TIME:
1839 struct bnxt_ioctl_hwrm_fw_set_time *stm =
1842 rc = bnxt_hwrm_fw_set_time(softc, stm->year,
1843 stm->month, stm->day, stm->hour, stm->minute,
1844 stm->second, stm->millisecond, stm->zone);
1847 copyout(&iod->hdr.rc, &ioh->rc,
1852 copyout(iod, ioh, ifbuf->length);
1864 free(iod, M_DEVBUF);
1872 bnxt_probe_phy(struct bnxt_softc *softc)
1874 struct bnxt_link_info *link_info = &softc->link_info;
1877 rc = bnxt_update_link(softc, false);
1879 device_printf(softc->dev,
1880 "Probe phy can't update link (rc: %x)\n", rc);
1884 /*initialize the ethool setting copy with NVM settings */
1885 if (link_info->auto_mode != HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
1886 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1888 if (link_info->auto_pause & (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1889 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
1890 if (link_info->auto_pause == (
1891 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1892 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1893 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1894 link_info->req_flow_ctrl = link_info->auto_pause;
1895 } else if (link_info->force_pause & (
1896 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1897 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
1898 link_info->req_flow_ctrl = link_info->force_pause;
1900 link_info->req_duplex = link_info->duplex_setting;
1901 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
1902 link_info->req_link_speed = link_info->auto_link_speed;
1904 link_info->req_link_speed = link_info->force_link_speed;
1909 bnxt_add_media_types(struct bnxt_softc *softc)
1911 struct bnxt_link_info *link_info = &softc->link_info;
1913 uint8_t phy_type = get_phy_type(softc);
1915 supported = link_info->support_speeds;
1917 /* Auto is always supported */
1918 ifmedia_add(softc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1920 if (softc->flags & BNXT_FLAG_NPAR)
1924 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1925 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1926 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0,
1928 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
1929 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0,
1931 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1932 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_CR4, 0,
1934 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1935 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0,
1937 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1938 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0,
1941 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN:
1944 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1945 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1946 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1947 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1948 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_KR4, 0,
1950 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
1951 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_KR2, 0,
1953 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1954 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_KR4, 0,
1956 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1957 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_KR, 0,
1959 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
1960 ifmedia_add(softc->media, IFM_ETHER | IFM_20G_KR2, 0,
1962 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1963 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KR, 0,
1966 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1967 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1968 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_LR4, 0,
1970 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1971 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_LR4, 0,
1973 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1974 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_LR, 0,
1977 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1978 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1979 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_SR4, 0,
1981 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1982 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_SR4, 0,
1984 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1985 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_SR, 0,
1987 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1988 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_SR, 0,
1991 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1992 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1993 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KX4, 0,
1995 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
1996 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_KX, 0,
1998 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
1999 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_KX, 0,
2002 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
2003 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE:
2004 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10MB)
2005 ifmedia_add(softc->media, IFM_ETHER | IFM_10_T, 0,
2007 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MB)
2008 ifmedia_add(softc->media, IFM_ETHER | IFM_100_T, 0,
2010 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2011 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0,
2013 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2014 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_T, 0,
2016 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2017 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_T, 0,
2020 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
2021 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2022 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_SGMII, 0,
2031 bnxt_map_bar(struct bnxt_softc *softc, struct bnxt_bar_info *bar, int bar_num, bool shareable)
2035 if (bar->res != NULL) {
2036 device_printf(softc->dev, "Bar %d already mapped\n", bar_num);
2040 bar->rid = PCIR_BAR(bar_num);
2043 flag |= RF_SHAREABLE;
2046 bus_alloc_resource_any(softc->dev,
2050 device_printf(softc->dev,
2051 "PCI BAR%d mapping failure\n", bar_num);
2054 bar->tag = rman_get_bustag(bar->res);
2055 bar->handle = rman_get_bushandle(bar->res);
2056 bar->size = rman_get_size(bar->res);
2062 bnxt_pci_mapping(struct bnxt_softc *softc)
2066 rc = bnxt_map_bar(softc, &softc->hwrm_bar, 0, true);
2070 rc = bnxt_map_bar(softc, &softc->doorbell_bar, 2, false);
2076 bnxt_pci_mapping_free(struct bnxt_softc *softc)
2078 if (softc->hwrm_bar.res != NULL)
2079 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2080 softc->hwrm_bar.rid, softc->hwrm_bar.res);
2081 softc->hwrm_bar.res = NULL;
2083 if (softc->doorbell_bar.res != NULL)
2084 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2085 softc->doorbell_bar.rid, softc->doorbell_bar.res);
2086 softc->doorbell_bar.res = NULL;
2090 bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state)
2092 struct bnxt_link_info *link_info = &softc->link_info;
2093 uint8_t link_up = link_info->link_up;
2096 rc = bnxt_hwrm_port_phy_qcfg(softc);
2100 /* TODO: need to add more logic to report VF link */
2101 if (chng_link_state) {
2102 if (link_info->phy_link_status ==
2103 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK)
2104 link_info->link_up = 1;
2106 link_info->link_up = 0;
2107 if (link_up != link_info->link_up)
2108 bnxt_report_link(softc);
2110 /* always link down if not require to update link state */
2111 link_info->link_up = 0;
2119 bnxt_report_link(struct bnxt_softc *softc)
2121 const char *duplex = NULL, *flow_ctrl = NULL;
2123 if (softc->link_info.link_up == softc->link_info.last_link_up) {
2124 if (!softc->link_info.link_up)
2126 if (softc->link_info.pause == softc->link_info.last_pause &&
2127 softc->link_info.duplex == softc->link_info.last_duplex)
2131 if (softc->link_info.link_up) {
2132 if (softc->link_info.duplex ==
2133 HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
2134 duplex = "full duplex";
2136 duplex = "half duplex";
2137 if (softc->link_info.pause == (
2138 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2139 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2140 flow_ctrl = "FC - receive & transmit";
2141 else if (softc->link_info.pause ==
2142 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
2143 flow_ctrl = "FC - transmit";
2144 else if (softc->link_info.pause ==
2145 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
2146 flow_ctrl = "FC - receive";
2149 iflib_link_state_change(softc->ctx, LINK_STATE_UP,
2151 device_printf(softc->dev, "Link is UP %s, %s\n", duplex,
2154 iflib_link_state_change(softc->ctx, LINK_STATE_DOWN,
2155 bnxt_get_baudrate(&softc->link_info));
2156 device_printf(softc->dev, "Link is Down\n");
2159 softc->link_info.last_link_up = softc->link_info.link_up;
2160 softc->link_info.last_pause = softc->link_info.pause;
2161 softc->link_info.last_duplex = softc->link_info.duplex;
2165 bnxt_handle_rx_cp(void *arg)
2167 struct bnxt_cp_ring *cpr = arg;
2169 /* Disable further interrupts for this queue */
2170 BNXT_CP_DISABLE_DB(&cpr->ring);
2171 return FILTER_SCHEDULE_THREAD;
2175 bnxt_handle_def_cp(void *arg)
2177 struct bnxt_softc *softc = arg;
2179 BNXT_CP_DISABLE_DB(&softc->def_cp_ring.ring);
2180 GROUPTASK_ENQUEUE(&softc->def_cp_task);
2181 return FILTER_HANDLED;
2185 bnxt_clear_ids(struct bnxt_softc *softc)
2189 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
2190 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2191 for (i = 0; i < softc->ntxqsets; i++) {
2192 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2193 softc->tx_cp_rings[i].ring.phys_id =
2194 (uint16_t)HWRM_NA_SIGNATURE;
2195 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2197 for (i = 0; i < softc->nrxqsets; i++) {
2198 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2199 softc->rx_cp_rings[i].ring.phys_id =
2200 (uint16_t)HWRM_NA_SIGNATURE;
2201 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2202 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2203 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
2205 softc->vnic_info.filter_id = -1;
2206 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
2207 softc->vnic_info.rss_id = (uint16_t)HWRM_NA_SIGNATURE;
2208 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
2209 softc->vnic_info.rss_grp_tbl.idi_size);
2213 bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr)
2215 struct cmpl_base *cmp = (void *)cpr->ring.vaddr;
2218 for (i = 0; i < cpr->ring.ring_size; i++)
2219 cmp[i].info3_v = !cpr->v_bit;
2223 bnxt_handle_async_event(struct bnxt_softc *softc, struct cmpl_base *cmpl)
2225 struct hwrm_async_event_cmpl *ae = (void *)cmpl;
2226 uint16_t async_id = le16toh(ae->event_id);
2227 struct ifmediareq ifmr;
2230 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
2231 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
2232 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
2233 bnxt_media_status(softc->ctx, &ifmr);
2235 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_MTU_CHANGE:
2236 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_DCB_CONFIG_CHANGE:
2237 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
2238 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_NOT_ALLOWED:
2239 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_UNLOAD:
2240 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_LOAD:
2241 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
2242 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_LOAD:
2243 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_FLR:
2244 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_MAC_ADDR_CHANGE:
2245 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_VF_COMM_STATUS_CHANGE:
2246 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
2247 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_HWRM_ERROR:
2248 device_printf(softc->dev,
2249 "Unhandled async completion type %u\n", async_id);
2252 device_printf(softc->dev,
2253 "Unknown async completion type %u\n", async_id);
2259 bnxt_def_cp_task(void *context)
2261 if_ctx_t ctx = context;
2262 struct bnxt_softc *softc = iflib_get_softc(ctx);
2263 struct bnxt_cp_ring *cpr = &softc->def_cp_ring;
2265 /* Handle completions on the default completion ring */
2266 struct cmpl_base *cmpl;
2267 uint32_t cons = cpr->cons;
2268 bool v_bit = cpr->v_bit;
2276 NEXT_CP_CONS_V(&cpr->ring, cons, v_bit);
2277 cmpl = &((struct cmpl_base *)cpr->ring.vaddr)[cons];
2279 if (!CMP_VALID(cmpl, v_bit))
2282 type = le16toh(cmpl->type) & CMPL_BASE_TYPE_MASK;
2284 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
2285 bnxt_handle_async_event(softc, cmpl);
2287 case CMPL_BASE_TYPE_TX_L2:
2288 case CMPL_BASE_TYPE_RX_L2:
2289 case CMPL_BASE_TYPE_RX_AGG:
2290 case CMPL_BASE_TYPE_RX_TPA_START:
2291 case CMPL_BASE_TYPE_RX_TPA_END:
2292 case CMPL_BASE_TYPE_STAT_EJECT:
2293 case CMPL_BASE_TYPE_HWRM_DONE:
2294 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
2295 case CMPL_BASE_TYPE_HWRM_FWD_RESP:
2296 case CMPL_BASE_TYPE_CQ_NOTIFICATION:
2297 case CMPL_BASE_TYPE_SRQ_EVENT:
2298 case CMPL_BASE_TYPE_DBQ_EVENT:
2299 case CMPL_BASE_TYPE_QP_EVENT:
2300 case CMPL_BASE_TYPE_FUNC_EVENT:
2301 device_printf(softc->dev,
2302 "Unhandled completion type %u\n", type);
2305 device_printf(softc->dev,
2306 "Unknown completion type %u\n", type);
2311 cpr->cons = last_cons;
2312 cpr->v_bit = last_v_bit;
2313 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
2317 get_phy_type(struct bnxt_softc *softc)
2319 struct bnxt_link_info *link_info = &softc->link_info;
2320 uint8_t phy_type = link_info->phy_type;
2323 if (phy_type != HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN)
2326 /* Deduce the phy type from the media type and supported speeds */
2327 supported = link_info->support_speeds;
2329 if (link_info->media_type ==
2330 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP)
2331 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET;
2332 if (link_info->media_type ==
2333 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_DAC) {
2334 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2335 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX;
2336 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2337 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR;
2338 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR;
2340 if (link_info->media_type ==
2341 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_FIBRE)
2342 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR;
2348 bnxt_check_hwrm_version(struct bnxt_softc *softc)
2352 sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
2353 softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
2354 if (softc->ver_info->hwrm_min_major > softc->ver_info->hwrm_if_major) {
2355 device_printf(softc->dev,
2356 "WARNING: HWRM version %s is too old (older than %s)\n",
2357 softc->ver_info->hwrm_if_ver, buf);
2360 else if(softc->ver_info->hwrm_min_major ==
2361 softc->ver_info->hwrm_if_major) {
2362 if (softc->ver_info->hwrm_min_minor >
2363 softc->ver_info->hwrm_if_minor) {
2364 device_printf(softc->dev,
2365 "WARNING: HWRM version %s is too old (older than %s)\n",
2366 softc->ver_info->hwrm_if_ver, buf);
2369 else if (softc->ver_info->hwrm_min_minor ==
2370 softc->ver_info->hwrm_if_minor) {
2371 if (softc->ver_info->hwrm_min_update >
2372 softc->ver_info->hwrm_if_update) {
2373 device_printf(softc->dev,
2374 "WARNING: HWRM version %s is too old (older than %s)\n",
2375 softc->ver_info->hwrm_if_ver, buf);
2384 bnxt_get_baudrate(struct bnxt_link_info *link)
2386 switch (link->link_speed) {
2387 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2388 return IF_Mbps(100);
2389 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2391 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2393 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2394 return IF_Mbps(2500);
2395 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2397 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2399 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2401 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2403 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2405 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2406 return IF_Gbps(100);
2407 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10MB:
2410 return IF_Gbps(100);