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_txrx = &bnxt_txrx,
281 .isc_driver = &bnxt_iflib_driver,
282 .isc_nfl = 2, // Number of Free Lists
283 .isc_flags = IFLIB_HAS_RXCQ | IFLIB_HAS_TXCQ,
284 .isc_q_align = PAGE_SIZE,
285 .isc_tx_maxsize = BNXT_TSO_SIZE,
286 .isc_tx_maxsegsize = BNXT_TSO_SIZE,
287 .isc_rx_maxsize = BNXT_TSO_SIZE,
288 .isc_rx_maxsegsize = BNXT_TSO_SIZE,
290 // Only use a single segment to avoid page size constraints
291 .isc_rx_nsegments = 1,
294 .isc_nrxd_min = {16, 16, 16},
295 .isc_nrxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 8,
296 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd),
297 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd)},
298 .isc_nrxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
299 .isc_ntxd_min = {16, 16, 16},
300 .isc_ntxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 2,
301 PAGE_SIZE / sizeof(struct tx_bd_short)},
302 .isc_ntxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
304 .isc_admin_intrcnt = 1,
305 .isc_vendor_info = bnxt_vendor_info_array,
306 .isc_driver_version = bnxt_driver_version,
309 if_shared_ctx_t bnxt_sctx = &bnxt_sctx_init;
316 bnxt_register(device_t dev)
322 * Device Dependent Configuration Functions
325 /* Soft queue setup and teardown */
327 bnxt_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
328 uint64_t *paddrs, int ntxqs, int ntxqsets)
330 struct bnxt_softc *softc;
334 softc = iflib_get_softc(ctx);
336 softc->tx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * ntxqsets,
337 M_DEVBUF, M_NOWAIT | M_ZERO);
338 if (!softc->tx_cp_rings) {
339 device_printf(iflib_get_dev(ctx),
340 "unable to allocate TX completion rings\n");
344 softc->tx_rings = malloc(sizeof(struct bnxt_ring) * ntxqsets,
345 M_DEVBUF, M_NOWAIT | M_ZERO);
346 if (!softc->tx_rings) {
347 device_printf(iflib_get_dev(ctx),
348 "unable to allocate TX rings\n");
350 goto ring_alloc_fail;
352 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * ntxqsets,
353 &softc->tx_stats, 0);
356 bus_dmamap_sync(softc->tx_stats.idi_tag, softc->tx_stats.idi_map,
357 BUS_DMASYNC_PREREAD);
359 for (i = 0; i < ntxqsets; i++) {
360 /* Set up the completion ring */
361 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
362 softc->tx_cp_rings[i].ring.phys_id =
363 (uint16_t)HWRM_NA_SIGNATURE;
364 softc->tx_cp_rings[i].ring.softc = softc;
365 softc->tx_cp_rings[i].ring.id =
366 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
367 softc->tx_cp_rings[i].ring.doorbell =
368 softc->tx_cp_rings[i].ring.id * 0x80;
369 softc->tx_cp_rings[i].ring.ring_size =
370 softc->scctx->isc_ntxd[0];
371 softc->tx_cp_rings[i].ring.vaddr = vaddrs[i * ntxqs];
372 softc->tx_cp_rings[i].ring.paddr = paddrs[i * ntxqs];
374 /* Set up the TX ring */
375 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
376 softc->tx_rings[i].softc = softc;
377 softc->tx_rings[i].id =
378 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
379 softc->tx_rings[i].doorbell = softc->tx_rings[i].id * 0x80;
380 softc->tx_rings[i].ring_size = softc->scctx->isc_ntxd[1];
381 softc->tx_rings[i].vaddr = vaddrs[i * ntxqs + 1];
382 softc->tx_rings[i].paddr = paddrs[i * ntxqs + 1];
384 bnxt_create_tx_sysctls(softc, i);
387 softc->ntxqsets = ntxqsets;
391 free(softc->tx_rings, M_DEVBUF);
393 free(softc->tx_cp_rings, M_DEVBUF);
399 bnxt_queues_free(if_ctx_t ctx)
401 struct bnxt_softc *softc = iflib_get_softc(ctx);
404 iflib_dma_free(&softc->tx_stats);
405 free(softc->tx_rings, M_DEVBUF);
406 softc->tx_rings = NULL;
407 free(softc->tx_cp_rings, M_DEVBUF);
408 softc->tx_cp_rings = NULL;
412 iflib_dma_free(&softc->rx_stats);
413 free(softc->grp_info, M_DEVBUF);
414 free(softc->ag_rings, M_DEVBUF);
415 free(softc->rx_rings, M_DEVBUF);
416 free(softc->rx_cp_rings, M_DEVBUF);
420 bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
421 uint64_t *paddrs, int nrxqs, int nrxqsets)
423 struct bnxt_softc *softc;
427 softc = iflib_get_softc(ctx);
429 softc->rx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * nrxqsets,
430 M_DEVBUF, M_NOWAIT | M_ZERO);
431 if (!softc->rx_cp_rings) {
432 device_printf(iflib_get_dev(ctx),
433 "unable to allocate RX completion rings\n");
437 softc->rx_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
438 M_DEVBUF, M_NOWAIT | M_ZERO);
439 if (!softc->rx_rings) {
440 device_printf(iflib_get_dev(ctx),
441 "unable to allocate RX rings\n");
443 goto ring_alloc_fail;
445 softc->ag_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
446 M_DEVBUF, M_NOWAIT | M_ZERO);
447 if (!softc->ag_rings) {
448 device_printf(iflib_get_dev(ctx),
449 "unable to allocate aggregation rings\n");
453 softc->grp_info = malloc(sizeof(struct bnxt_grp_info) * nrxqsets,
454 M_DEVBUF, M_NOWAIT | M_ZERO);
455 if (!softc->grp_info) {
456 device_printf(iflib_get_dev(ctx),
457 "unable to allocate ring groups\n");
462 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * nrxqsets,
463 &softc->rx_stats, 0);
465 goto hw_stats_alloc_fail;
466 bus_dmamap_sync(softc->rx_stats.idi_tag, softc->rx_stats.idi_map,
467 BUS_DMASYNC_PREREAD);
469 for (i = 0; i < nrxqsets; i++) {
470 /* Allocation the completion ring */
471 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
472 softc->rx_cp_rings[i].ring.phys_id =
473 (uint16_t)HWRM_NA_SIGNATURE;
474 softc->rx_cp_rings[i].ring.softc = softc;
475 softc->rx_cp_rings[i].ring.id = i + 1;
476 softc->rx_cp_rings[i].ring.doorbell =
477 softc->rx_cp_rings[i].ring.id * 0x80;
479 * If this ring overflows, RX stops working.
481 softc->rx_cp_rings[i].ring.ring_size =
482 softc->scctx->isc_nrxd[0];
483 softc->rx_cp_rings[i].ring.vaddr = vaddrs[i * nrxqs];
484 softc->rx_cp_rings[i].ring.paddr = paddrs[i * nrxqs];
486 /* Allocate the RX ring */
487 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
488 softc->rx_rings[i].softc = softc;
489 softc->rx_rings[i].id = i + 1;
490 softc->rx_rings[i].doorbell = softc->rx_rings[i].id * 0x80;
491 softc->rx_rings[i].ring_size = softc->scctx->isc_nrxd[1];
492 softc->rx_rings[i].vaddr = vaddrs[i * nrxqs + 1];
493 softc->rx_rings[i].paddr = paddrs[i * nrxqs + 1];
495 /* Allocate the AG ring */
496 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
497 softc->ag_rings[i].softc = softc;
498 softc->ag_rings[i].id = nrxqsets + i + 1;
499 softc->ag_rings[i].doorbell = softc->ag_rings[i].id * 0x80;
500 softc->ag_rings[i].ring_size = softc->scctx->isc_nrxd[2];
501 softc->ag_rings[i].vaddr = vaddrs[i * nrxqs + 2];
502 softc->ag_rings[i].paddr = paddrs[i * nrxqs + 2];
504 /* Allocate the ring group */
505 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
506 softc->grp_info[i].stats_ctx =
507 softc->rx_cp_rings[i].stats_ctx_id;
508 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
509 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
510 softc->grp_info[i].cp_ring_id =
511 softc->rx_cp_rings[i].ring.phys_id;
513 bnxt_create_rx_sysctls(softc, i);
516 /* And finally, the VNIC */
517 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
518 softc->vnic_info.flow_id = (uint16_t)HWRM_NA_SIGNATURE;
519 softc->vnic_info.filter_id = -1;
520 softc->vnic_info.def_ring_grp = (uint16_t)HWRM_NA_SIGNATURE;
521 softc->vnic_info.cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
522 softc->vnic_info.lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
523 softc->vnic_info.rx_mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
524 softc->vnic_info.mc_list_count = 0;
525 softc->vnic_info.flags = BNXT_VNIC_FLAG_DEFAULT;
526 rc = iflib_dma_alloc(ctx, BNXT_MAX_MC_ADDRS * ETHER_ADDR_LEN,
527 &softc->vnic_info.mc_list, 0);
529 goto mc_list_alloc_fail;
531 /* The VNIC RSS Hash Key */
532 rc = iflib_dma_alloc(ctx, HW_HASH_KEY_SIZE,
533 &softc->vnic_info.rss_hash_key_tbl, 0);
535 goto rss_hash_alloc_fail;
536 bus_dmamap_sync(softc->vnic_info.rss_hash_key_tbl.idi_tag,
537 softc->vnic_info.rss_hash_key_tbl.idi_map,
538 BUS_DMASYNC_PREWRITE);
539 memcpy(softc->vnic_info.rss_hash_key_tbl.idi_vaddr,
540 softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE);
542 /* Allocate the RSS tables */
543 rc = iflib_dma_alloc(ctx, HW_HASH_INDEX_SIZE * sizeof(uint16_t),
544 &softc->vnic_info.rss_grp_tbl, 0);
546 goto rss_grp_alloc_fail;
547 bus_dmamap_sync(softc->vnic_info.rss_grp_tbl.idi_tag,
548 softc->vnic_info.rss_grp_tbl.idi_map,
549 BUS_DMASYNC_PREWRITE);
550 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
551 softc->vnic_info.rss_grp_tbl.idi_size);
553 softc->nrxqsets = nrxqsets;
557 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
559 iflib_dma_free(&softc->vnic_info.mc_list);
561 iflib_dma_free(&softc->rx_stats);
563 free(softc->grp_info, M_DEVBUF);
565 free(softc->ag_rings, M_DEVBUF);
567 free(softc->rx_rings, M_DEVBUF);
569 free(softc->rx_cp_rings, M_DEVBUF);
574 /* Device setup and teardown */
576 bnxt_attach_pre(if_ctx_t ctx)
578 struct bnxt_softc *softc = iflib_get_softc(ctx);
579 if_softc_ctx_t scctx;
583 softc->dev = iflib_get_dev(ctx);
584 softc->media = iflib_get_media(ctx);
585 softc->scctx = iflib_get_softc_ctx(ctx);
586 softc->sctx = iflib_get_sctx(ctx);
587 scctx = softc->scctx;
589 /* TODO: Better way of detecting NPAR/VF is needed */
590 switch (softc->sctx->isc_vendor_info->pvi_device_id) {
601 softc->flags |= BNXT_FLAG_NPAR;
603 case NETXTREME_C_VF1:
604 case NETXTREME_C_VF2:
605 case NETXTREME_C_VF3:
606 case NETXTREME_E_VF1:
607 case NETXTREME_E_VF2:
608 case NETXTREME_E_VF3:
609 softc->flags |= BNXT_FLAG_VF;
613 pci_enable_busmaster(softc->dev);
615 if (bnxt_pci_mapping(softc))
618 /* HWRM setup/init */
619 BNXT_HWRM_LOCK_INIT(softc, device_get_nameunit(softc->dev));
620 rc = bnxt_alloc_hwrm_dma_mem(softc);
624 /* Allocate the TPA start buffer */
625 softc->tpa_start = malloc(sizeof(struct bnxt_full_tpa_start) *
626 (RX_TPA_START_CMPL_AGG_ID_MASK >> RX_TPA_START_CMPL_AGG_ID_SFT),
627 M_DEVBUF, M_NOWAIT | M_ZERO);
628 if (softc->tpa_start == NULL) {
630 device_printf(softc->dev,
631 "Unable to allocate space for TPA\n");
635 /* Get firmware version and compare with driver */
636 softc->ver_info = malloc(sizeof(struct bnxt_ver_info),
637 M_DEVBUF, M_NOWAIT | M_ZERO);
638 if (softc->ver_info == NULL) {
640 device_printf(softc->dev,
641 "Unable to allocate space for version info\n");
644 /* Default minimum required HWRM version */
645 softc->ver_info->hwrm_min_major = 1;
646 softc->ver_info->hwrm_min_minor = 2;
647 softc->ver_info->hwrm_min_update = 2;
649 rc = bnxt_hwrm_ver_get(softc);
651 device_printf(softc->dev, "attach: hwrm ver get failed\n");
656 softc->nvm_info = malloc(sizeof(struct bnxt_nvram_info),
657 M_DEVBUF, M_NOWAIT | M_ZERO);
658 if (softc->nvm_info == NULL) {
660 device_printf(softc->dev,
661 "Unable to allocate space for NVRAM info\n");
664 rc = bnxt_hwrm_nvm_get_dev_info(softc, &softc->nvm_info->mfg_id,
665 &softc->nvm_info->device_id, &softc->nvm_info->sector_size,
666 &softc->nvm_info->size, &softc->nvm_info->reserved_size,
667 &softc->nvm_info->available_size);
669 /* Register the driver with the FW */
670 rc = bnxt_hwrm_func_drv_rgtr(softc);
672 device_printf(softc->dev, "attach: hwrm drv rgtr failed\n");
676 /* Get the HW capabilities */
677 rc = bnxt_hwrm_func_qcaps(softc);
680 iflib_set_mac(ctx, softc->func.mac_addr);
682 /* Get the queue config */
683 rc = bnxt_hwrm_queue_qportcfg(softc);
685 device_printf(softc->dev, "attach: hwrm qportcfg failed\n");
689 /* Now perform a function reset */
690 rc = bnxt_hwrm_func_reset(softc);
691 bnxt_clear_ids(softc);
695 /* Now set up iflib sc */
696 scctx->isc_tx_nsegments = 31,
697 scctx->isc_tx_tso_segments_max = 31;
698 scctx->isc_tx_tso_size_max = BNXT_TSO_SIZE;
699 scctx->isc_tx_tso_segsize_max = BNXT_TSO_SIZE;
700 scctx->isc_vectors = softc->func.max_cp_rings;
701 if (scctx->isc_nrxd[0] <
702 ((scctx->isc_nrxd[1] * 4) + scctx->isc_nrxd[2]))
703 device_printf(softc->dev,
704 "WARNING: nrxd0 (%d) should be at least 4 * nrxd1 (%d) + nrxd2 (%d). Driver may be unstable\n",
705 scctx->isc_nrxd[0], scctx->isc_nrxd[1], scctx->isc_nrxd[2]);
706 if (scctx->isc_ntxd[0] < scctx->isc_ntxd[1] * 2)
707 device_printf(softc->dev,
708 "WARNING: ntxd0 (%d) should be at least 2 * ntxd1 (%d). Driver may be unstable\n",
709 scctx->isc_ntxd[0], scctx->isc_ntxd[1]);
710 scctx->isc_txqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_ntxd[0];
711 scctx->isc_txqsizes[1] = sizeof(struct tx_bd_short) *
713 scctx->isc_rxqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_nrxd[0];
714 scctx->isc_rxqsizes[1] = sizeof(struct rx_prod_pkt_bd) *
716 scctx->isc_rxqsizes[2] = sizeof(struct rx_prod_pkt_bd) *
718 scctx->isc_max_rxqsets = min(pci_msix_count(softc->dev)-1,
719 softc->func.max_cp_rings - 1);
720 scctx->isc_max_rxqsets = min(scctx->isc_max_rxqsets,
721 softc->func.max_rx_rings);
722 scctx->isc_max_txqsets = min(softc->func.max_rx_rings,
723 softc->func.max_cp_rings - scctx->isc_max_rxqsets - 1);
724 scctx->isc_rss_table_size = HW_HASH_INDEX_SIZE;
725 scctx->isc_rss_table_mask = scctx->isc_rss_table_size - 1;
727 /* iflib will map and release this bar */
728 scctx->isc_msix_bar = pci_msix_table_bar(softc->dev);
730 /* Allocate the default completion ring */
731 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
732 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
733 softc->def_cp_ring.ring.softc = softc;
734 softc->def_cp_ring.ring.id = 0;
735 softc->def_cp_ring.ring.doorbell = softc->def_cp_ring.ring.id * 0x80;
736 softc->def_cp_ring.ring.ring_size = PAGE_SIZE /
737 sizeof(struct cmpl_base);
738 rc = iflib_dma_alloc(ctx,
739 sizeof(struct cmpl_base) * softc->def_cp_ring.ring.ring_size,
740 &softc->def_cp_ring_mem, 0);
741 softc->def_cp_ring.ring.vaddr = softc->def_cp_ring_mem.idi_vaddr;
742 softc->def_cp_ring.ring.paddr = softc->def_cp_ring_mem.idi_paddr;
743 iflib_config_gtask_init(ctx, &softc->def_cp_task, bnxt_def_cp_task,
746 rc = bnxt_init_sysctl_ctx(softc);
748 goto init_sysctl_failed;
749 rc = bnxt_create_nvram_sysctls(softc->nvm_info);
753 arc4rand(softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE, 0);
754 softc->vnic_info.rss_hash_type =
755 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4 |
756 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4 |
757 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4 |
758 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6 |
759 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6 |
760 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
761 rc = bnxt_create_config_sysctls_pre(softc);
765 /* Initialize the vlan list */
766 SLIST_INIT(&softc->vnic_info.vlan_tags);
767 softc->vnic_info.vlan_tag_list.idi_vaddr = NULL;
772 bnxt_free_sysctl_ctx(softc);
774 bnxt_hwrm_func_drv_unrgtr(softc, false);
776 free(softc->nvm_info, M_DEVBUF);
779 free(softc->ver_info, M_DEVBUF);
781 free(softc->tpa_start, M_DEVBUF);
783 bnxt_free_hwrm_dma_mem(softc);
785 BNXT_HWRM_LOCK_DESTROY(softc);
786 bnxt_pci_mapping_free(softc);
787 pci_disable_busmaster(softc->dev);
792 bnxt_attach_post(if_ctx_t ctx)
794 struct bnxt_softc *softc = iflib_get_softc(ctx);
795 if_t ifp = iflib_get_ifp(ctx);
796 int capabilities, enabling;
799 bnxt_create_config_sysctls_post(softc);
801 /* Update link state etc... */
802 rc = bnxt_probe_phy(softc);
806 /* Needs to be done after probing the phy */
807 bnxt_create_ver_sysctls(softc);
808 bnxt_add_media_types(softc);
809 ifmedia_set(softc->media, IFM_ETHER | IFM_AUTO);
811 if_sethwassist(ifp, (CSUM_TCP | CSUM_UDP | CSUM_TCP_IPV6 |
812 CSUM_UDP_IPV6 | CSUM_TSO));
815 /* These are translated to hwassit bits */
816 IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | IFCAP_TSO4 | IFCAP_TSO6 |
817 /* These are checked by iflib */
818 IFCAP_LRO | IFCAP_VLAN_HWFILTER |
819 /* These are part of the iflib mask */
820 IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_VLAN_MTU |
821 IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO |
822 /* These likely get lost... */
823 IFCAP_VLAN_HWCSUM | IFCAP_JUMBO_MTU;
825 if_setcapabilities(ifp, capabilities);
827 enabling = capabilities;
829 if_setcapenable(ifp, enabling);
831 softc->scctx->isc_max_frame_size = ifp->if_mtu + ETHER_HDR_LEN +
839 bnxt_detach(if_ctx_t ctx)
841 struct bnxt_softc *softc = iflib_get_softc(ctx);
842 struct bnxt_vlan_tag *tag;
843 struct bnxt_vlan_tag *tmp;
846 bnxt_do_disable_intr(&softc->def_cp_ring);
847 bnxt_free_sysctl_ctx(softc);
848 bnxt_hwrm_func_reset(softc);
849 bnxt_clear_ids(softc);
850 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
851 iflib_config_gtask_deinit(&softc->def_cp_task);
852 /* We need to free() these here... */
853 for (i = softc->nrxqsets-1; i>=0; i--) {
854 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
856 iflib_dma_free(&softc->vnic_info.mc_list);
857 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
858 iflib_dma_free(&softc->vnic_info.rss_grp_tbl);
859 if (softc->vnic_info.vlan_tag_list.idi_vaddr)
860 iflib_dma_free(&softc->vnic_info.vlan_tag_list);
861 SLIST_FOREACH_SAFE(tag, &softc->vnic_info.vlan_tags, next, tmp)
863 iflib_dma_free(&softc->def_cp_ring_mem);
864 free(softc->tpa_start, M_DEVBUF);
865 free(softc->ver_info, M_DEVBUF);
866 free(softc->nvm_info, M_DEVBUF);
868 bnxt_hwrm_func_drv_unrgtr(softc, false);
869 bnxt_free_hwrm_dma_mem(softc);
870 BNXT_HWRM_LOCK_DESTROY(softc);
872 pci_disable_busmaster(softc->dev);
873 bnxt_pci_mapping_free(softc);
878 /* Device configuration */
880 bnxt_init(if_ctx_t ctx)
882 struct bnxt_softc *softc = iflib_get_softc(ctx);
883 struct ifmediareq ifmr;
887 rc = bnxt_hwrm_func_reset(softc);
890 bnxt_clear_ids(softc);
892 /* Allocate the default completion ring */
893 softc->def_cp_ring.cons = UINT32_MAX;
894 softc->def_cp_ring.v_bit = 1;
895 bnxt_mark_cpr_invalid(&softc->def_cp_ring);
896 rc = bnxt_hwrm_ring_alloc(softc,
897 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
898 &softc->def_cp_ring.ring,
899 (uint16_t)HWRM_NA_SIGNATURE,
900 HWRM_NA_SIGNATURE, true);
904 /* And now set the default CP ring as the async CP ring */
905 rc = bnxt_hwrm_func_cfg(softc);
909 for (i = 0; i < softc->nrxqsets; i++) {
910 /* Allocate the statistics context */
911 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->rx_cp_rings[i],
912 softc->rx_stats.idi_paddr +
913 (sizeof(struct ctx_hw_stats) * i));
917 /* Allocate the completion ring */
918 softc->rx_cp_rings[i].cons = UINT32_MAX;
919 softc->rx_cp_rings[i].v_bit = 1;
920 softc->rx_cp_rings[i].last_idx = UINT32_MAX;
921 bnxt_mark_cpr_invalid(&softc->rx_cp_rings[i]);
922 rc = bnxt_hwrm_ring_alloc(softc,
923 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
924 &softc->rx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
925 HWRM_NA_SIGNATURE, true);
929 /* Allocate the RX ring */
930 rc = bnxt_hwrm_ring_alloc(softc,
931 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
932 &softc->rx_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
933 HWRM_NA_SIGNATURE, false);
936 BNXT_RX_DB(&softc->rx_rings[i], 0);
937 /* TODO: Cumulus+ doesn't need the double doorbell */
938 BNXT_RX_DB(&softc->rx_rings[i], 0);
940 /* Allocate the AG ring */
941 rc = bnxt_hwrm_ring_alloc(softc,
942 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
943 &softc->ag_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
944 HWRM_NA_SIGNATURE, false);
947 BNXT_RX_DB(&softc->rx_rings[i], 0);
948 /* TODO: Cumulus+ doesn't need the double doorbell */
949 BNXT_RX_DB(&softc->ag_rings[i], 0);
951 /* Allocate the ring group */
952 softc->grp_info[i].stats_ctx =
953 softc->rx_cp_rings[i].stats_ctx_id;
954 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
955 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
956 softc->grp_info[i].cp_ring_id =
957 softc->rx_cp_rings[i].ring.phys_id;
958 rc = bnxt_hwrm_ring_grp_alloc(softc, &softc->grp_info[i]);
964 /* Allocate the VNIC RSS context */
965 rc = bnxt_hwrm_vnic_ctx_alloc(softc, &softc->vnic_info.rss_id);
969 /* Allocate the vnic */
970 softc->vnic_info.def_ring_grp = softc->grp_info[0].grp_id;
971 softc->vnic_info.mru = softc->scctx->isc_max_frame_size;
972 rc = bnxt_hwrm_vnic_alloc(softc, &softc->vnic_info);
975 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
978 rc = bnxt_hwrm_set_filter(softc, &softc->vnic_info);
982 /* Enable RSS on the VNICs */
983 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
985 softc->vnic_info.rss_grp_tbl.idi_vaddr)[i] =
986 htole16(softc->grp_info[j].grp_id);
987 if (++j == softc->nrxqsets)
991 rc = bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
992 softc->vnic_info.rss_hash_type);
997 /* Enable LRO/TPA/GRO */
998 rc = bnxt_hwrm_vnic_tpa_cfg(softc, &softc->vnic_info,
999 (if_getcapenable(iflib_get_ifp(ctx)) & IFCAP_LRO) ?
1000 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA : 0);
1005 for (i = 0; i < softc->ntxqsets; i++) {
1006 /* Allocate the statistics context */
1007 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->tx_cp_rings[i],
1008 softc->tx_stats.idi_paddr +
1009 (sizeof(struct ctx_hw_stats) * i));
1013 /* Allocate the completion ring */
1014 softc->tx_cp_rings[i].cons = UINT32_MAX;
1015 softc->tx_cp_rings[i].v_bit = 1;
1016 bnxt_mark_cpr_invalid(&softc->tx_cp_rings[i]);
1017 rc = bnxt_hwrm_ring_alloc(softc,
1018 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
1019 &softc->tx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
1020 HWRM_NA_SIGNATURE, false);
1024 /* Allocate the TX ring */
1025 rc = bnxt_hwrm_ring_alloc(softc,
1026 HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
1027 &softc->tx_rings[i], softc->tx_cp_rings[i].ring.phys_id,
1028 softc->tx_cp_rings[i].stats_ctx_id, false);
1031 BNXT_TX_DB(&softc->tx_rings[i], 0);
1032 /* TODO: Cumulus+ doesn't need the double doorbell */
1033 BNXT_TX_DB(&softc->tx_rings[i], 0);
1036 bnxt_do_enable_intr(&softc->def_cp_ring);
1037 bnxt_media_status(softc->ctx, &ifmr);
1041 bnxt_hwrm_func_reset(softc);
1042 bnxt_clear_ids(softc);
1047 bnxt_stop(if_ctx_t ctx)
1049 struct bnxt_softc *softc = iflib_get_softc(ctx);
1051 bnxt_do_disable_intr(&softc->def_cp_ring);
1052 bnxt_hwrm_func_reset(softc);
1053 bnxt_clear_ids(softc);
1058 bnxt_multi_set(if_ctx_t ctx)
1060 struct bnxt_softc *softc = iflib_get_softc(ctx);
1061 if_t ifp = iflib_get_ifp(ctx);
1065 mcnt = if_multiaddr_count(ifp, -1);
1067 if (mcnt > BNXT_MAX_MC_ADDRS) {
1068 softc->vnic_info.rx_mask |=
1069 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1070 bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1073 softc->vnic_info.rx_mask &=
1074 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1075 mta = softc->vnic_info.mc_list.idi_vaddr;
1076 bzero(mta, softc->vnic_info.mc_list.idi_size);
1077 if_multiaddr_array(ifp, mta, &cnt, mcnt);
1078 bus_dmamap_sync(softc->vnic_info.mc_list.idi_tag,
1079 softc->vnic_info.mc_list.idi_map, BUS_DMASYNC_PREWRITE);
1080 softc->vnic_info.mc_list_count = cnt;
1081 softc->vnic_info.rx_mask |=
1082 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
1083 if (bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info))
1084 device_printf(softc->dev,
1085 "set_multi: rx_mask set failed\n");
1090 bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu)
1092 struct bnxt_softc *softc = iflib_get_softc(ctx);
1094 if (mtu > BNXT_MAX_MTU)
1097 softc->scctx->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1102 bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
1104 struct bnxt_softc *softc = iflib_get_softc(ctx);
1105 struct bnxt_link_info *link_info = &softc->link_info;
1106 uint8_t phy_type = get_phy_type(softc);
1108 bnxt_update_link(softc, true);
1110 ifmr->ifm_status = IFM_AVALID;
1111 ifmr->ifm_active = IFM_ETHER;
1113 if (link_info->link_up)
1114 ifmr->ifm_status |= IFM_ACTIVE;
1116 ifmr->ifm_status &= ~IFM_ACTIVE;
1118 if (link_info->duplex == HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
1119 ifmr->ifm_active |= IFM_FDX;
1121 ifmr->ifm_active |= IFM_HDX;
1123 switch (link_info->link_speed) {
1124 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1125 ifmr->ifm_active |= IFM_100_T;
1127 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1129 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1130 ifmr->ifm_active |= IFM_1000_KX;
1132 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1133 ifmr->ifm_active |= IFM_1000_T;
1135 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
1136 ifmr->ifm_active |= IFM_1000_SGMII;
1139 ifmr->ifm_active |= IFM_UNKNOWN;
1143 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1145 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1146 ifmr->ifm_active |= IFM_2500_KX;
1148 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1149 ifmr->ifm_active |= IFM_2500_T;
1152 ifmr->ifm_active |= IFM_UNKNOWN;
1156 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1158 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1159 ifmr->ifm_active |= IFM_10G_CR1;
1161 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1162 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1163 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1164 ifmr->ifm_active |= IFM_10G_KR;
1166 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1167 ifmr->ifm_active |= IFM_10G_LR;
1169 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1170 ifmr->ifm_active |= IFM_10G_SR;
1172 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1173 ifmr->ifm_active |= IFM_10G_KX4;
1175 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1176 ifmr->ifm_active |= IFM_10G_T;
1179 ifmr->ifm_active |= IFM_UNKNOWN;
1183 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1184 ifmr->ifm_active |= IFM_20G_KR2;
1186 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1188 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1189 ifmr->ifm_active |= IFM_25G_CR;
1191 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1192 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1193 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1194 ifmr->ifm_active |= IFM_25G_KR;
1196 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1197 ifmr->ifm_active |= IFM_25G_SR;
1200 ifmr->ifm_active |= IFM_UNKNOWN;
1204 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1206 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1207 ifmr->ifm_active |= IFM_40G_CR4;
1209 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1210 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1211 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1212 ifmr->ifm_active |= IFM_40G_KR4;
1214 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1215 ifmr->ifm_active |= IFM_40G_LR4;
1217 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1218 ifmr->ifm_active |= IFM_40G_SR4;
1221 ifmr->ifm_active |= IFM_UNKNOWN;
1225 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1227 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1228 ifmr->ifm_active |= IFM_50G_CR2;
1230 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1231 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1232 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1233 ifmr->ifm_active |= IFM_50G_KR2;
1236 ifmr->ifm_active |= IFM_UNKNOWN;
1240 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
1242 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1243 ifmr->ifm_active |= IFM_100G_CR4;
1245 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1246 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1247 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1248 ifmr->ifm_active |= IFM_100G_KR4;
1250 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1251 ifmr->ifm_active |= IFM_100G_LR4;
1253 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1254 ifmr->ifm_active |= IFM_100G_SR4;
1257 ifmr->ifm_active |= IFM_UNKNOWN;
1264 if (link_info->pause == (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1265 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1266 ifmr->ifm_active |= (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
1267 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
1268 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
1269 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
1270 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
1272 bnxt_report_link(softc);
1277 bnxt_media_change(if_ctx_t ctx)
1279 struct bnxt_softc *softc = iflib_get_softc(ctx);
1280 struct ifmedia *ifm = iflib_get_media(ctx);
1281 struct ifmediareq ifmr;
1284 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1287 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1289 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1290 softc->link_info.req_link_speed =
1291 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
1295 case IFM_1000_SGMII:
1296 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1297 softc->link_info.req_link_speed =
1298 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
1302 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1303 softc->link_info.req_link_speed =
1304 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
1311 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1312 softc->link_info.req_link_speed =
1313 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1316 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1317 softc->link_info.req_link_speed =
1318 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
1323 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1324 softc->link_info.req_link_speed =
1325 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
1331 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1332 softc->link_info.req_link_speed =
1333 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1337 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1338 softc->link_info.req_link_speed =
1339 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1345 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1346 softc->link_info.req_link_speed =
1347 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
1350 device_printf(softc->dev,
1351 "Unsupported media type! Using auto\n");
1355 softc->link_info.autoneg |= BNXT_AUTONEG_SPEED;
1358 rc = bnxt_hwrm_set_link_setting(softc, true, true);
1359 bnxt_media_status(softc->ctx, &ifmr);
1364 bnxt_promisc_set(if_ctx_t ctx, int flags)
1366 struct bnxt_softc *softc = iflib_get_softc(ctx);
1367 if_t ifp = iflib_get_ifp(ctx);
1370 if (ifp->if_flags & IFF_ALLMULTI ||
1371 if_multiaddr_count(ifp, -1) > BNXT_MAX_MC_ADDRS)
1372 softc->vnic_info.rx_mask |=
1373 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1375 softc->vnic_info.rx_mask &=
1376 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1378 if (ifp->if_flags & IFF_PROMISC)
1379 softc->vnic_info.rx_mask |=
1380 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1381 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN;
1383 softc->vnic_info.rx_mask &=
1384 ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1385 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
1387 rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1393 bnxt_get_counter(if_ctx_t ctx, ift_counter cnt)
1395 if_t ifp = iflib_get_ifp(ctx);
1397 if (cnt < IFCOUNTERS)
1398 return if_get_counter_default(ifp, cnt);
1404 bnxt_update_admin_status(if_ctx_t ctx)
1406 /* TODO: do we need to do anything here? */
1411 bnxt_do_enable_intr(struct bnxt_cp_ring *cpr)
1413 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE) {
1414 /* First time enabling, do not set index */
1415 if (cpr->cons == UINT32_MAX)
1416 BNXT_CP_ENABLE_DB(&cpr->ring);
1418 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
1423 bnxt_do_disable_intr(struct bnxt_cp_ring *cpr)
1425 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE)
1426 BNXT_CP_DISABLE_DB(&cpr->ring);
1429 /* Enable all interrupts */
1431 bnxt_intr_enable(if_ctx_t ctx)
1433 struct bnxt_softc *softc = iflib_get_softc(ctx);
1436 bnxt_do_enable_intr(&softc->def_cp_ring);
1437 for (i = 0; i < softc->nrxqsets; i++)
1438 bnxt_do_enable_intr(&softc->rx_cp_rings[i]);
1443 /* Enable interrupt for a single queue */
1445 bnxt_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1447 struct bnxt_softc *softc = iflib_get_softc(ctx);
1449 bnxt_do_enable_intr(&softc->rx_cp_rings[qid]);
1453 /* Disable all interrupts */
1455 bnxt_disable_intr(if_ctx_t ctx)
1457 struct bnxt_softc *softc = iflib_get_softc(ctx);
1461 * NOTE: These TX interrupts should never get enabled, so don't
1464 for (i = 0; i < softc->ntxqsets; i++)
1465 bnxt_do_disable_intr(&softc->tx_cp_rings[i]);
1466 for (i = 0; i < softc->nrxqsets; i++)
1467 bnxt_do_disable_intr(&softc->rx_cp_rings[i]);
1473 bnxt_msix_intr_assign(if_ctx_t ctx, int msix)
1475 struct bnxt_softc *softc = iflib_get_softc(ctx);
1479 rc = iflib_irq_alloc_generic(ctx, &softc->def_cp_ring.irq,
1480 softc->def_cp_ring.ring.id + 1, IFLIB_INTR_ADMIN,
1481 bnxt_handle_def_cp, softc, 0, "def_cp");
1483 device_printf(iflib_get_dev(ctx),
1484 "Failed to register default completion ring handler\n");
1488 for (i=0; i<softc->scctx->isc_nrxqsets; i++) {
1489 rc = iflib_irq_alloc_generic(ctx, &softc->rx_cp_rings[i].irq,
1490 softc->rx_cp_rings[i].ring.id + 1, IFLIB_INTR_RX,
1491 bnxt_handle_rx_cp, &softc->rx_cp_rings[i], i, "rx_cp");
1493 device_printf(iflib_get_dev(ctx),
1494 "Failed to register RX completion ring handler\n");
1500 for (i=0; i<softc->scctx->isc_ntxqsets; i++)
1501 iflib_softirq_alloc_generic(ctx, i + 1, IFLIB_INTR_TX, NULL, i,
1508 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
1509 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
1514 * We're explicitly allowing duplicates here. They will need to be
1515 * removed as many times as they are added.
1518 bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag)
1520 struct bnxt_softc *softc = iflib_get_softc(ctx);
1521 struct bnxt_vlan_tag *new_tag;
1523 new_tag = malloc(sizeof(struct bnxt_vlan_tag), M_DEVBUF, M_NOWAIT);
1524 if (new_tag == NULL)
1526 new_tag->tag = vtag;
1527 new_tag->tpid = 8100;
1528 SLIST_INSERT_HEAD(&softc->vnic_info.vlan_tags, new_tag, next);
1532 bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag)
1534 struct bnxt_softc *softc = iflib_get_softc(ctx);
1535 struct bnxt_vlan_tag *vlan_tag;
1537 SLIST_FOREACH(vlan_tag, &softc->vnic_info.vlan_tags, next) {
1538 if (vlan_tag->tag == vtag) {
1539 SLIST_REMOVE(&softc->vnic_info.vlan_tags, vlan_tag,
1540 bnxt_vlan_tag, next);
1541 free(vlan_tag, M_DEVBUF);
1548 bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data)
1550 struct bnxt_softc *softc = iflib_get_softc(ctx);
1551 struct ifreq *ifr = (struct ifreq *)data;
1552 struct ifreq_buffer *ifbuf = &ifr->ifr_ifru.ifru_buffer;
1553 struct bnxt_ioctl_header *ioh =
1554 (struct bnxt_ioctl_header *)(ifbuf->buffer);
1556 struct bnxt_ioctl_data *iod = NULL;
1559 case SIOCGPRIVATE_0:
1560 if ((rc = priv_check(curthread, PRIV_DRIVER)) != 0)
1563 iod = malloc(ifbuf->length, M_DEVBUF, M_NOWAIT | M_ZERO);
1568 copyin(ioh, iod, ifbuf->length);
1570 switch (ioh->type) {
1571 case BNXT_HWRM_NVM_FIND_DIR_ENTRY:
1573 struct bnxt_ioctl_hwrm_nvm_find_dir_entry *find =
1576 rc = bnxt_hwrm_nvm_find_dir_entry(softc, find->type,
1577 &find->ordinal, find->ext, &find->index,
1578 find->use_index, find->search_opt,
1579 &find->data_length, &find->item_length,
1583 copyout(&iod->hdr.rc, &ioh->rc,
1588 copyout(iod, ioh, ifbuf->length);
1594 case BNXT_HWRM_NVM_READ:
1596 struct bnxt_ioctl_hwrm_nvm_read *rd = &iod->read;
1597 struct iflib_dma_info dma_data;
1603 * Some HWRM versions can't read more than 0x8000 bytes
1605 rc = iflib_dma_alloc(softc->ctx,
1606 min(rd->length, 0x8000), &dma_data, BUS_DMA_NOWAIT);
1609 for (remain = rd->length, offset = 0;
1610 remain && offset < rd->length; offset += 0x8000) {
1611 csize = min(remain, 0x8000);
1612 rc = bnxt_hwrm_nvm_read(softc, rd->index,
1613 rd->offset + offset, csize, &dma_data);
1616 copyout(&iod->hdr.rc, &ioh->rc,
1621 copyout(dma_data.idi_vaddr,
1622 rd->data + offset, csize);
1627 if (iod->hdr.rc == 0)
1628 copyout(iod, ioh, ifbuf->length);
1630 iflib_dma_free(&dma_data);
1634 case BNXT_HWRM_FW_RESET:
1636 struct bnxt_ioctl_hwrm_fw_reset *rst =
1639 rc = bnxt_hwrm_fw_reset(softc, rst->processor,
1643 copyout(&iod->hdr.rc, &ioh->rc,
1648 copyout(iod, ioh, ifbuf->length);
1654 case BNXT_HWRM_FW_QSTATUS:
1656 struct bnxt_ioctl_hwrm_fw_qstatus *qstat =
1659 rc = bnxt_hwrm_fw_qstatus(softc, qstat->processor,
1663 copyout(&iod->hdr.rc, &ioh->rc,
1668 copyout(iod, ioh, ifbuf->length);
1674 case BNXT_HWRM_NVM_WRITE:
1676 struct bnxt_ioctl_hwrm_nvm_write *wr =
1679 rc = bnxt_hwrm_nvm_write(softc, wr->data, true,
1680 wr->type, wr->ordinal, wr->ext, wr->attr,
1681 wr->option, wr->data_length, wr->keep,
1682 &wr->item_length, &wr->index);
1685 copyout(&iod->hdr.rc, &ioh->rc,
1690 copyout(iod, ioh, ifbuf->length);
1696 case BNXT_HWRM_NVM_ERASE_DIR_ENTRY:
1698 struct bnxt_ioctl_hwrm_nvm_erase_dir_entry *erase =
1701 rc = bnxt_hwrm_nvm_erase_dir_entry(softc, erase->index);
1704 copyout(&iod->hdr.rc, &ioh->rc,
1709 copyout(iod, ioh, ifbuf->length);
1715 case BNXT_HWRM_NVM_GET_DIR_INFO:
1717 struct bnxt_ioctl_hwrm_nvm_get_dir_info *info =
1720 rc = bnxt_hwrm_nvm_get_dir_info(softc, &info->entries,
1721 &info->entry_length);
1724 copyout(&iod->hdr.rc, &ioh->rc,
1729 copyout(iod, ioh, ifbuf->length);
1735 case BNXT_HWRM_NVM_GET_DIR_ENTRIES:
1737 struct bnxt_ioctl_hwrm_nvm_get_dir_entries *get =
1739 struct iflib_dma_info dma_data;
1741 rc = iflib_dma_alloc(softc->ctx, get->max_size,
1742 &dma_data, BUS_DMA_NOWAIT);
1745 rc = bnxt_hwrm_nvm_get_dir_entries(softc, &get->entries,
1746 &get->entry_length, &dma_data);
1749 copyout(&iod->hdr.rc, &ioh->rc,
1753 copyout(dma_data.idi_vaddr, get->data,
1754 get->entry_length * get->entries);
1756 copyout(iod, ioh, ifbuf->length);
1758 iflib_dma_free(&dma_data);
1763 case BNXT_HWRM_NVM_VERIFY_UPDATE:
1765 struct bnxt_ioctl_hwrm_nvm_verify_update *vrfy =
1768 rc = bnxt_hwrm_nvm_verify_update(softc, vrfy->type,
1769 vrfy->ordinal, vrfy->ext);
1772 copyout(&iod->hdr.rc, &ioh->rc,
1777 copyout(iod, ioh, ifbuf->length);
1783 case BNXT_HWRM_NVM_INSTALL_UPDATE:
1785 struct bnxt_ioctl_hwrm_nvm_install_update *inst =
1788 rc = bnxt_hwrm_nvm_install_update(softc,
1789 inst->install_type, &inst->installed_items,
1790 &inst->result, &inst->problem_item,
1791 &inst->reset_required);
1794 copyout(&iod->hdr.rc, &ioh->rc,
1799 copyout(iod, ioh, ifbuf->length);
1805 case BNXT_HWRM_NVM_MODIFY:
1807 struct bnxt_ioctl_hwrm_nvm_modify *mod = &iod->modify;
1809 rc = bnxt_hwrm_nvm_modify(softc, mod->index,
1810 mod->offset, mod->data, true, mod->length);
1813 copyout(&iod->hdr.rc, &ioh->rc,
1818 copyout(iod, ioh, ifbuf->length);
1824 case BNXT_HWRM_FW_GET_TIME:
1826 struct bnxt_ioctl_hwrm_fw_get_time *gtm =
1829 rc = bnxt_hwrm_fw_get_time(softc, >m->year,
1830 >m->month, >m->day, >m->hour, >m->minute,
1831 >m->second, >m->millisecond, >m->zone);
1834 copyout(&iod->hdr.rc, &ioh->rc,
1839 copyout(iod, ioh, ifbuf->length);
1845 case BNXT_HWRM_FW_SET_TIME:
1847 struct bnxt_ioctl_hwrm_fw_set_time *stm =
1850 rc = bnxt_hwrm_fw_set_time(softc, stm->year,
1851 stm->month, stm->day, stm->hour, stm->minute,
1852 stm->second, stm->millisecond, stm->zone);
1855 copyout(&iod->hdr.rc, &ioh->rc,
1860 copyout(iod, ioh, ifbuf->length);
1872 free(iod, M_DEVBUF);
1880 bnxt_probe_phy(struct bnxt_softc *softc)
1882 struct bnxt_link_info *link_info = &softc->link_info;
1885 rc = bnxt_update_link(softc, false);
1887 device_printf(softc->dev,
1888 "Probe phy can't update link (rc: %x)\n", rc);
1892 /*initialize the ethool setting copy with NVM settings */
1893 if (link_info->auto_mode != HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
1894 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1896 if (link_info->auto_pause & (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1897 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
1898 if (link_info->auto_pause == (
1899 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1900 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1901 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1902 link_info->req_flow_ctrl = link_info->auto_pause;
1903 } else if (link_info->force_pause & (
1904 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1905 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
1906 link_info->req_flow_ctrl = link_info->force_pause;
1908 link_info->req_duplex = link_info->duplex_setting;
1909 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
1910 link_info->req_link_speed = link_info->auto_link_speed;
1912 link_info->req_link_speed = link_info->force_link_speed;
1917 bnxt_add_media_types(struct bnxt_softc *softc)
1919 struct bnxt_link_info *link_info = &softc->link_info;
1921 uint8_t phy_type = get_phy_type(softc);
1923 supported = link_info->support_speeds;
1925 /* Auto is always supported */
1926 ifmedia_add(softc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1928 if (softc->flags & BNXT_FLAG_NPAR)
1932 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1933 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1934 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0,
1936 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
1937 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0,
1939 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1940 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_CR4, 0,
1942 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1943 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0,
1945 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1946 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0,
1949 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN:
1952 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1953 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1954 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1955 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1956 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_KR4, 0,
1958 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
1959 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_KR2, 0,
1961 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1962 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_KR4, 0,
1964 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1965 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_KR, 0,
1967 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
1968 ifmedia_add(softc->media, IFM_ETHER | IFM_20G_KR2, 0,
1970 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1971 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KR, 0,
1974 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1975 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1976 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_LR4, 0,
1978 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1979 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_LR4, 0,
1981 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1982 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_LR, 0,
1985 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1986 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1987 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_SR4, 0,
1989 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1990 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_SR4, 0,
1992 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1993 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_SR, 0,
1995 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1996 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_SR, 0,
1999 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
2000 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2001 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KX4, 0,
2003 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2004 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_KX, 0,
2006 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2007 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_KX, 0,
2010 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
2011 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE:
2012 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10MB)
2013 ifmedia_add(softc->media, IFM_ETHER | IFM_10_T, 0,
2015 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MB)
2016 ifmedia_add(softc->media, IFM_ETHER | IFM_100_T, 0,
2018 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2019 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0,
2021 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2022 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_T, 0,
2024 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2025 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_T, 0,
2028 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
2029 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2030 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_SGMII, 0,
2039 bnxt_map_bar(struct bnxt_softc *softc, struct bnxt_bar_info *bar, int bar_num, bool shareable)
2043 if (bar->res != NULL) {
2044 device_printf(softc->dev, "Bar %d already mapped\n", bar_num);
2048 bar->rid = PCIR_BAR(bar_num);
2051 flag |= RF_SHAREABLE;
2054 bus_alloc_resource_any(softc->dev,
2058 device_printf(softc->dev,
2059 "PCI BAR%d mapping failure\n", bar_num);
2062 bar->tag = rman_get_bustag(bar->res);
2063 bar->handle = rman_get_bushandle(bar->res);
2064 bar->size = rman_get_size(bar->res);
2070 bnxt_pci_mapping(struct bnxt_softc *softc)
2074 rc = bnxt_map_bar(softc, &softc->hwrm_bar, 0, true);
2078 rc = bnxt_map_bar(softc, &softc->doorbell_bar, 2, false);
2084 bnxt_pci_mapping_free(struct bnxt_softc *softc)
2086 if (softc->hwrm_bar.res != NULL)
2087 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2088 softc->hwrm_bar.rid, softc->hwrm_bar.res);
2089 softc->hwrm_bar.res = NULL;
2091 if (softc->doorbell_bar.res != NULL)
2092 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2093 softc->doorbell_bar.rid, softc->doorbell_bar.res);
2094 softc->doorbell_bar.res = NULL;
2098 bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state)
2100 struct bnxt_link_info *link_info = &softc->link_info;
2101 uint8_t link_up = link_info->link_up;
2104 rc = bnxt_hwrm_port_phy_qcfg(softc);
2108 /* TODO: need to add more logic to report VF link */
2109 if (chng_link_state) {
2110 if (link_info->phy_link_status ==
2111 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK)
2112 link_info->link_up = 1;
2114 link_info->link_up = 0;
2115 if (link_up != link_info->link_up)
2116 bnxt_report_link(softc);
2118 /* always link down if not require to update link state */
2119 link_info->link_up = 0;
2127 bnxt_report_link(struct bnxt_softc *softc)
2129 const char *duplex = NULL, *flow_ctrl = NULL;
2131 if (softc->link_info.link_up == softc->link_info.last_link_up) {
2132 if (!softc->link_info.link_up)
2134 if (softc->link_info.pause == softc->link_info.last_pause &&
2135 softc->link_info.duplex == softc->link_info.last_duplex)
2139 if (softc->link_info.link_up) {
2140 if (softc->link_info.duplex ==
2141 HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
2142 duplex = "full duplex";
2144 duplex = "half duplex";
2145 if (softc->link_info.pause == (
2146 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2147 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2148 flow_ctrl = "FC - receive & transmit";
2149 else if (softc->link_info.pause ==
2150 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
2151 flow_ctrl = "FC - transmit";
2152 else if (softc->link_info.pause ==
2153 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
2154 flow_ctrl = "FC - receive";
2157 iflib_link_state_change(softc->ctx, LINK_STATE_UP,
2159 device_printf(softc->dev, "Link is UP %s, %s\n", duplex,
2162 iflib_link_state_change(softc->ctx, LINK_STATE_DOWN,
2163 bnxt_get_baudrate(&softc->link_info));
2164 device_printf(softc->dev, "Link is Down\n");
2167 softc->link_info.last_link_up = softc->link_info.link_up;
2168 softc->link_info.last_pause = softc->link_info.pause;
2169 softc->link_info.last_duplex = softc->link_info.duplex;
2173 bnxt_handle_rx_cp(void *arg)
2175 struct bnxt_cp_ring *cpr = arg;
2177 /* Disable further interrupts for this queue */
2178 BNXT_CP_DISABLE_DB(&cpr->ring);
2179 return FILTER_SCHEDULE_THREAD;
2183 bnxt_handle_def_cp(void *arg)
2185 struct bnxt_softc *softc = arg;
2187 BNXT_CP_DISABLE_DB(&softc->def_cp_ring.ring);
2188 GROUPTASK_ENQUEUE(&softc->def_cp_task);
2189 return FILTER_HANDLED;
2193 bnxt_clear_ids(struct bnxt_softc *softc)
2197 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
2198 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2199 for (i = 0; i < softc->ntxqsets; i++) {
2200 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2201 softc->tx_cp_rings[i].ring.phys_id =
2202 (uint16_t)HWRM_NA_SIGNATURE;
2203 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2205 for (i = 0; i < softc->nrxqsets; i++) {
2206 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2207 softc->rx_cp_rings[i].ring.phys_id =
2208 (uint16_t)HWRM_NA_SIGNATURE;
2209 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2210 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2211 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
2213 softc->vnic_info.filter_id = -1;
2214 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
2215 softc->vnic_info.rss_id = (uint16_t)HWRM_NA_SIGNATURE;
2216 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
2217 softc->vnic_info.rss_grp_tbl.idi_size);
2221 bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr)
2223 struct cmpl_base *cmp = (void *)cpr->ring.vaddr;
2226 for (i = 0; i < cpr->ring.ring_size; i++)
2227 cmp[i].info3_v = !cpr->v_bit;
2231 bnxt_handle_async_event(struct bnxt_softc *softc, struct cmpl_base *cmpl)
2233 struct hwrm_async_event_cmpl *ae = (void *)cmpl;
2234 uint16_t async_id = le16toh(ae->event_id);
2235 struct ifmediareq ifmr;
2238 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
2239 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
2240 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
2241 bnxt_media_status(softc->ctx, &ifmr);
2243 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_MTU_CHANGE:
2244 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_DCB_CONFIG_CHANGE:
2245 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
2246 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_NOT_ALLOWED:
2247 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_UNLOAD:
2248 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_LOAD:
2249 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
2250 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_LOAD:
2251 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_FLR:
2252 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_MAC_ADDR_CHANGE:
2253 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_VF_COMM_STATUS_CHANGE:
2254 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
2255 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_HWRM_ERROR:
2256 device_printf(softc->dev,
2257 "Unhandled async completion type %u\n", async_id);
2260 device_printf(softc->dev,
2261 "Unknown async completion type %u\n", async_id);
2267 bnxt_def_cp_task(void *context)
2269 if_ctx_t ctx = context;
2270 struct bnxt_softc *softc = iflib_get_softc(ctx);
2271 struct bnxt_cp_ring *cpr = &softc->def_cp_ring;
2273 /* Handle completions on the default completion ring */
2274 struct cmpl_base *cmpl;
2275 uint32_t cons = cpr->cons;
2276 bool v_bit = cpr->v_bit;
2284 NEXT_CP_CONS_V(&cpr->ring, cons, v_bit);
2285 cmpl = &((struct cmpl_base *)cpr->ring.vaddr)[cons];
2287 if (!CMP_VALID(cmpl, v_bit))
2290 type = le16toh(cmpl->type) & CMPL_BASE_TYPE_MASK;
2292 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
2293 bnxt_handle_async_event(softc, cmpl);
2295 case CMPL_BASE_TYPE_TX_L2:
2296 case CMPL_BASE_TYPE_RX_L2:
2297 case CMPL_BASE_TYPE_RX_AGG:
2298 case CMPL_BASE_TYPE_RX_TPA_START:
2299 case CMPL_BASE_TYPE_RX_TPA_END:
2300 case CMPL_BASE_TYPE_STAT_EJECT:
2301 case CMPL_BASE_TYPE_HWRM_DONE:
2302 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
2303 case CMPL_BASE_TYPE_HWRM_FWD_RESP:
2304 case CMPL_BASE_TYPE_CQ_NOTIFICATION:
2305 case CMPL_BASE_TYPE_SRQ_EVENT:
2306 case CMPL_BASE_TYPE_DBQ_EVENT:
2307 case CMPL_BASE_TYPE_QP_EVENT:
2308 case CMPL_BASE_TYPE_FUNC_EVENT:
2309 device_printf(softc->dev,
2310 "Unhandled completion type %u\n", type);
2313 device_printf(softc->dev,
2314 "Unknown completion type %u\n", type);
2319 cpr->cons = last_cons;
2320 cpr->v_bit = last_v_bit;
2321 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
2325 get_phy_type(struct bnxt_softc *softc)
2327 struct bnxt_link_info *link_info = &softc->link_info;
2328 uint8_t phy_type = link_info->phy_type;
2331 if (phy_type != HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN)
2334 /* Deduce the phy type from the media type and supported speeds */
2335 supported = link_info->support_speeds;
2337 if (link_info->media_type ==
2338 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP)
2339 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET;
2340 if (link_info->media_type ==
2341 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_DAC) {
2342 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2343 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX;
2344 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2345 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR;
2346 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR;
2348 if (link_info->media_type ==
2349 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_FIBRE)
2350 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR;
2356 bnxt_check_hwrm_version(struct bnxt_softc *softc)
2360 sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
2361 softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
2362 if (softc->ver_info->hwrm_min_major > softc->ver_info->hwrm_if_major) {
2363 device_printf(softc->dev,
2364 "WARNING: HWRM version %s is too old (older than %s)\n",
2365 softc->ver_info->hwrm_if_ver, buf);
2368 else if(softc->ver_info->hwrm_min_major ==
2369 softc->ver_info->hwrm_if_major) {
2370 if (softc->ver_info->hwrm_min_minor >
2371 softc->ver_info->hwrm_if_minor) {
2372 device_printf(softc->dev,
2373 "WARNING: HWRM version %s is too old (older than %s)\n",
2374 softc->ver_info->hwrm_if_ver, buf);
2377 else if (softc->ver_info->hwrm_min_minor ==
2378 softc->ver_info->hwrm_if_minor) {
2379 if (softc->ver_info->hwrm_min_update >
2380 softc->ver_info->hwrm_if_update) {
2381 device_printf(softc->dev,
2382 "WARNING: HWRM version %s is too old (older than %s)\n",
2383 softc->ver_info->hwrm_if_ver, buf);
2392 bnxt_get_baudrate(struct bnxt_link_info *link)
2394 switch (link->link_speed) {
2395 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2396 return IF_Mbps(100);
2397 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2399 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2401 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2402 return IF_Mbps(2500);
2403 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2405 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2407 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2409 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2411 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2413 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2414 return IF_Gbps(100);
2415 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10MB:
2418 return IF_Gbps(100);