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, BCM57454,
131 "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet"),
132 PVID(BROADCOM_VENDOR_ID, BCM58700,
133 "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet"),
134 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF1,
135 "Broadcom NetXtreme-C Ethernet Virtual Function"),
136 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF2,
137 "Broadcom NetXtreme-C Ethernet Virtual Function"),
138 PVID(BROADCOM_VENDOR_ID, NETXTREME_C_VF3,
139 "Broadcom NetXtreme-C Ethernet Virtual Function"),
140 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF1,
141 "Broadcom NetXtreme-E Ethernet Virtual Function"),
142 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF2,
143 "Broadcom NetXtreme-E Ethernet Virtual Function"),
144 PVID(BROADCOM_VENDOR_ID, NETXTREME_E_VF3,
145 "Broadcom NetXtreme-E Ethernet Virtual Function"),
146 /* required last entry */
152 * Function prototypes
155 static void *bnxt_register(device_t dev);
157 /* Soft queue setup and teardown */
158 static int bnxt_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
159 uint64_t *paddrs, int ntxqs, int ntxqsets);
160 static int bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
161 uint64_t *paddrs, int nrxqs, int nrxqsets);
162 static void bnxt_queues_free(if_ctx_t ctx);
164 /* Device setup and teardown */
165 static int bnxt_attach_pre(if_ctx_t ctx);
166 static int bnxt_attach_post(if_ctx_t ctx);
167 static int bnxt_detach(if_ctx_t ctx);
169 /* Device configuration */
170 static void bnxt_init(if_ctx_t ctx);
171 static void bnxt_stop(if_ctx_t ctx);
172 static void bnxt_multi_set(if_ctx_t ctx);
173 static int bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu);
174 static void bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr);
175 static int bnxt_media_change(if_ctx_t ctx);
176 static int bnxt_promisc_set(if_ctx_t ctx, int flags);
177 static uint64_t bnxt_get_counter(if_ctx_t, ift_counter);
178 static void bnxt_update_admin_status(if_ctx_t ctx);
180 /* Interrupt enable / disable */
181 static void bnxt_intr_enable(if_ctx_t ctx);
182 static int bnxt_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid);
183 static int bnxt_tx_queue_intr_enable(if_ctx_t ctx, uint16_t qid);
184 static void bnxt_disable_intr(if_ctx_t ctx);
185 static int bnxt_msix_intr_assign(if_ctx_t ctx, int msix);
188 static void bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag);
189 static void bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag);
192 static int bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data);
194 static int bnxt_shutdown(if_ctx_t ctx);
195 static int bnxt_suspend(if_ctx_t ctx);
196 static int bnxt_resume(if_ctx_t ctx);
198 /* Internal support functions */
199 static int bnxt_probe_phy(struct bnxt_softc *softc);
200 static void bnxt_add_media_types(struct bnxt_softc *softc);
201 static int bnxt_pci_mapping(struct bnxt_softc *softc);
202 static void bnxt_pci_mapping_free(struct bnxt_softc *softc);
203 static int bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state);
204 static int bnxt_handle_def_cp(void *arg);
205 static int bnxt_handle_rx_cp(void *arg);
206 static void bnxt_clear_ids(struct bnxt_softc *softc);
207 static void inline bnxt_do_enable_intr(struct bnxt_cp_ring *cpr);
208 static void inline bnxt_do_disable_intr(struct bnxt_cp_ring *cpr);
209 static void bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr);
210 static void bnxt_def_cp_task(void *context);
211 static void bnxt_handle_async_event(struct bnxt_softc *softc,
212 struct cmpl_base *cmpl);
213 static uint8_t get_phy_type(struct bnxt_softc *softc);
214 static uint64_t bnxt_get_baudrate(struct bnxt_link_info *link);
215 static void bnxt_get_wol_settings(struct bnxt_softc *softc);
216 static int bnxt_wol_config(if_ctx_t ctx);
219 * Device Interface Declaration
222 static device_method_t bnxt_methods[] = {
223 /* Device interface */
224 DEVMETHOD(device_register, bnxt_register),
225 DEVMETHOD(device_probe, iflib_device_probe),
226 DEVMETHOD(device_attach, iflib_device_attach),
227 DEVMETHOD(device_detach, iflib_device_detach),
228 DEVMETHOD(device_shutdown, iflib_device_shutdown),
229 DEVMETHOD(device_suspend, iflib_device_suspend),
230 DEVMETHOD(device_resume, iflib_device_resume),
234 static driver_t bnxt_driver = {
235 "bnxt", bnxt_methods, sizeof(struct bnxt_softc),
238 devclass_t bnxt_devclass;
239 DRIVER_MODULE(bnxt, pci, bnxt_driver, bnxt_devclass, 0, 0);
241 MODULE_DEPEND(bnxt, pci, 1, 1, 1);
242 MODULE_DEPEND(bnxt, ether, 1, 1, 1);
243 MODULE_DEPEND(bnxt, iflib, 1, 1, 1);
245 static device_method_t bnxt_iflib_methods[] = {
246 DEVMETHOD(ifdi_tx_queues_alloc, bnxt_tx_queues_alloc),
247 DEVMETHOD(ifdi_rx_queues_alloc, bnxt_rx_queues_alloc),
248 DEVMETHOD(ifdi_queues_free, bnxt_queues_free),
250 DEVMETHOD(ifdi_attach_pre, bnxt_attach_pre),
251 DEVMETHOD(ifdi_attach_post, bnxt_attach_post),
252 DEVMETHOD(ifdi_detach, bnxt_detach),
254 DEVMETHOD(ifdi_init, bnxt_init),
255 DEVMETHOD(ifdi_stop, bnxt_stop),
256 DEVMETHOD(ifdi_multi_set, bnxt_multi_set),
257 DEVMETHOD(ifdi_mtu_set, bnxt_mtu_set),
258 DEVMETHOD(ifdi_media_status, bnxt_media_status),
259 DEVMETHOD(ifdi_media_change, bnxt_media_change),
260 DEVMETHOD(ifdi_promisc_set, bnxt_promisc_set),
261 DEVMETHOD(ifdi_get_counter, bnxt_get_counter),
262 DEVMETHOD(ifdi_update_admin_status, bnxt_update_admin_status),
264 DEVMETHOD(ifdi_intr_enable, bnxt_intr_enable),
265 DEVMETHOD(ifdi_tx_queue_intr_enable, bnxt_tx_queue_intr_enable),
266 DEVMETHOD(ifdi_rx_queue_intr_enable, bnxt_rx_queue_intr_enable),
267 DEVMETHOD(ifdi_intr_disable, bnxt_disable_intr),
268 DEVMETHOD(ifdi_msix_intr_assign, bnxt_msix_intr_assign),
270 DEVMETHOD(ifdi_vlan_register, bnxt_vlan_register),
271 DEVMETHOD(ifdi_vlan_unregister, bnxt_vlan_unregister),
273 DEVMETHOD(ifdi_priv_ioctl, bnxt_priv_ioctl),
275 DEVMETHOD(ifdi_suspend, bnxt_suspend),
276 DEVMETHOD(ifdi_shutdown, bnxt_shutdown),
277 DEVMETHOD(ifdi_resume, bnxt_resume),
282 static driver_t bnxt_iflib_driver = {
283 "bnxt", bnxt_iflib_methods, sizeof(struct bnxt_softc)
287 * iflib shared context
290 #define BNXT_DRIVER_VERSION "1.0.0.1"
291 char bnxt_driver_version[] = BNXT_DRIVER_VERSION;
292 extern struct if_txrx bnxt_txrx;
293 static struct if_shared_ctx bnxt_sctx_init = {
294 .isc_magic = IFLIB_MAGIC,
295 .isc_driver = &bnxt_iflib_driver,
296 .isc_nfl = 2, // Number of Free Lists
297 .isc_flags = IFLIB_HAS_RXCQ | IFLIB_HAS_TXCQ,
298 .isc_q_align = PAGE_SIZE,
299 .isc_tx_maxsize = BNXT_TSO_SIZE,
300 .isc_tx_maxsegsize = BNXT_TSO_SIZE,
301 .isc_rx_maxsize = BNXT_TSO_SIZE,
302 .isc_rx_maxsegsize = BNXT_TSO_SIZE,
304 // Only use a single segment to avoid page size constraints
305 .isc_rx_nsegments = 1,
308 .isc_nrxd_min = {16, 16, 16},
309 .isc_nrxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 8,
310 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd),
311 PAGE_SIZE / sizeof(struct rx_prod_pkt_bd)},
312 .isc_nrxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
313 .isc_ntxd_min = {16, 16, 16},
314 .isc_ntxd_default = {PAGE_SIZE / sizeof(struct cmpl_base) * 2,
315 PAGE_SIZE / sizeof(struct tx_bd_short)},
316 .isc_ntxd_max = {INT32_MAX, INT32_MAX, INT32_MAX},
318 .isc_admin_intrcnt = 1,
319 .isc_vendor_info = bnxt_vendor_info_array,
320 .isc_driver_version = bnxt_driver_version,
323 if_shared_ctx_t bnxt_sctx = &bnxt_sctx_init;
330 bnxt_register(device_t dev)
336 * Device Dependent Configuration Functions
339 /* Soft queue setup and teardown */
341 bnxt_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
342 uint64_t *paddrs, int ntxqs, int ntxqsets)
344 struct bnxt_softc *softc;
348 softc = iflib_get_softc(ctx);
350 softc->tx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * ntxqsets,
351 M_DEVBUF, M_NOWAIT | M_ZERO);
352 if (!softc->tx_cp_rings) {
353 device_printf(iflib_get_dev(ctx),
354 "unable to allocate TX completion rings\n");
358 softc->tx_rings = malloc(sizeof(struct bnxt_ring) * ntxqsets,
359 M_DEVBUF, M_NOWAIT | M_ZERO);
360 if (!softc->tx_rings) {
361 device_printf(iflib_get_dev(ctx),
362 "unable to allocate TX rings\n");
364 goto ring_alloc_fail;
366 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * ntxqsets,
367 &softc->tx_stats, 0);
370 bus_dmamap_sync(softc->tx_stats.idi_tag, softc->tx_stats.idi_map,
371 BUS_DMASYNC_PREREAD);
373 for (i = 0; i < ntxqsets; i++) {
374 /* Set up the completion ring */
375 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
376 softc->tx_cp_rings[i].ring.phys_id =
377 (uint16_t)HWRM_NA_SIGNATURE;
378 softc->tx_cp_rings[i].ring.softc = softc;
379 softc->tx_cp_rings[i].ring.id =
380 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
381 softc->tx_cp_rings[i].ring.doorbell =
382 softc->tx_cp_rings[i].ring.id * 0x80;
383 softc->tx_cp_rings[i].ring.ring_size =
384 softc->scctx->isc_ntxd[0];
385 softc->tx_cp_rings[i].ring.vaddr = vaddrs[i * ntxqs];
386 softc->tx_cp_rings[i].ring.paddr = paddrs[i * ntxqs];
388 /* Set up the TX ring */
389 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
390 softc->tx_rings[i].softc = softc;
391 softc->tx_rings[i].id =
392 (softc->scctx->isc_nrxqsets * 2) + 1 + i;
393 softc->tx_rings[i].doorbell = softc->tx_rings[i].id * 0x80;
394 softc->tx_rings[i].ring_size = softc->scctx->isc_ntxd[1];
395 softc->tx_rings[i].vaddr = vaddrs[i * ntxqs + 1];
396 softc->tx_rings[i].paddr = paddrs[i * ntxqs + 1];
398 bnxt_create_tx_sysctls(softc, i);
401 softc->ntxqsets = ntxqsets;
405 free(softc->tx_rings, M_DEVBUF);
407 free(softc->tx_cp_rings, M_DEVBUF);
413 bnxt_queues_free(if_ctx_t ctx)
415 struct bnxt_softc *softc = iflib_get_softc(ctx);
418 iflib_dma_free(&softc->tx_stats);
419 free(softc->tx_rings, M_DEVBUF);
420 softc->tx_rings = NULL;
421 free(softc->tx_cp_rings, M_DEVBUF);
422 softc->tx_cp_rings = NULL;
426 iflib_dma_free(&softc->rx_stats);
427 free(softc->grp_info, M_DEVBUF);
428 free(softc->ag_rings, M_DEVBUF);
429 free(softc->rx_rings, M_DEVBUF);
430 free(softc->rx_cp_rings, M_DEVBUF);
434 bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
435 uint64_t *paddrs, int nrxqs, int nrxqsets)
437 struct bnxt_softc *softc;
441 softc = iflib_get_softc(ctx);
443 softc->rx_cp_rings = malloc(sizeof(struct bnxt_cp_ring) * nrxqsets,
444 M_DEVBUF, M_NOWAIT | M_ZERO);
445 if (!softc->rx_cp_rings) {
446 device_printf(iflib_get_dev(ctx),
447 "unable to allocate RX completion rings\n");
451 softc->rx_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
452 M_DEVBUF, M_NOWAIT | M_ZERO);
453 if (!softc->rx_rings) {
454 device_printf(iflib_get_dev(ctx),
455 "unable to allocate RX rings\n");
457 goto ring_alloc_fail;
459 softc->ag_rings = malloc(sizeof(struct bnxt_ring) * nrxqsets,
460 M_DEVBUF, M_NOWAIT | M_ZERO);
461 if (!softc->ag_rings) {
462 device_printf(iflib_get_dev(ctx),
463 "unable to allocate aggregation rings\n");
467 softc->grp_info = malloc(sizeof(struct bnxt_grp_info) * nrxqsets,
468 M_DEVBUF, M_NOWAIT | M_ZERO);
469 if (!softc->grp_info) {
470 device_printf(iflib_get_dev(ctx),
471 "unable to allocate ring groups\n");
476 rc = iflib_dma_alloc(ctx, sizeof(struct ctx_hw_stats) * nrxqsets,
477 &softc->rx_stats, 0);
479 goto hw_stats_alloc_fail;
480 bus_dmamap_sync(softc->rx_stats.idi_tag, softc->rx_stats.idi_map,
481 BUS_DMASYNC_PREREAD);
483 for (i = 0; i < nrxqsets; i++) {
484 /* Allocation the completion ring */
485 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
486 softc->rx_cp_rings[i].ring.phys_id =
487 (uint16_t)HWRM_NA_SIGNATURE;
488 softc->rx_cp_rings[i].ring.softc = softc;
489 softc->rx_cp_rings[i].ring.id = i + 1;
490 softc->rx_cp_rings[i].ring.doorbell =
491 softc->rx_cp_rings[i].ring.id * 0x80;
493 * If this ring overflows, RX stops working.
495 softc->rx_cp_rings[i].ring.ring_size =
496 softc->scctx->isc_nrxd[0];
497 softc->rx_cp_rings[i].ring.vaddr = vaddrs[i * nrxqs];
498 softc->rx_cp_rings[i].ring.paddr = paddrs[i * nrxqs];
500 /* Allocate the RX ring */
501 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
502 softc->rx_rings[i].softc = softc;
503 softc->rx_rings[i].id = i + 1;
504 softc->rx_rings[i].doorbell = softc->rx_rings[i].id * 0x80;
505 softc->rx_rings[i].ring_size = softc->scctx->isc_nrxd[1];
506 softc->rx_rings[i].vaddr = vaddrs[i * nrxqs + 1];
507 softc->rx_rings[i].paddr = paddrs[i * nrxqs + 1];
509 /* Allocate the TPA start buffer */
510 softc->rx_rings[i].tpa_start = malloc(sizeof(struct bnxt_full_tpa_start) *
511 (RX_TPA_START_CMPL_AGG_ID_MASK >> RX_TPA_START_CMPL_AGG_ID_SFT),
512 M_DEVBUF, M_NOWAIT | M_ZERO);
513 if (softc->rx_rings[i].tpa_start == NULL) {
515 device_printf(softc->dev,
516 "Unable to allocate space for TPA\n");
520 /* Allocate the AG ring */
521 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
522 softc->ag_rings[i].softc = softc;
523 softc->ag_rings[i].id = nrxqsets + i + 1;
524 softc->ag_rings[i].doorbell = softc->ag_rings[i].id * 0x80;
525 softc->ag_rings[i].ring_size = softc->scctx->isc_nrxd[2];
526 softc->ag_rings[i].vaddr = vaddrs[i * nrxqs + 2];
527 softc->ag_rings[i].paddr = paddrs[i * nrxqs + 2];
529 /* Allocate the ring group */
530 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
531 softc->grp_info[i].stats_ctx =
532 softc->rx_cp_rings[i].stats_ctx_id;
533 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
534 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
535 softc->grp_info[i].cp_ring_id =
536 softc->rx_cp_rings[i].ring.phys_id;
538 bnxt_create_rx_sysctls(softc, i);
541 /* And finally, the VNIC */
542 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
543 softc->vnic_info.flow_id = (uint16_t)HWRM_NA_SIGNATURE;
544 softc->vnic_info.filter_id = -1;
545 softc->vnic_info.def_ring_grp = (uint16_t)HWRM_NA_SIGNATURE;
546 softc->vnic_info.cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
547 softc->vnic_info.lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
548 softc->vnic_info.rx_mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
549 softc->vnic_info.mc_list_count = 0;
550 softc->vnic_info.flags = BNXT_VNIC_FLAG_DEFAULT;
551 rc = iflib_dma_alloc(ctx, BNXT_MAX_MC_ADDRS * ETHER_ADDR_LEN,
552 &softc->vnic_info.mc_list, 0);
554 goto mc_list_alloc_fail;
556 /* The VNIC RSS Hash Key */
557 rc = iflib_dma_alloc(ctx, HW_HASH_KEY_SIZE,
558 &softc->vnic_info.rss_hash_key_tbl, 0);
560 goto rss_hash_alloc_fail;
561 bus_dmamap_sync(softc->vnic_info.rss_hash_key_tbl.idi_tag,
562 softc->vnic_info.rss_hash_key_tbl.idi_map,
563 BUS_DMASYNC_PREWRITE);
564 memcpy(softc->vnic_info.rss_hash_key_tbl.idi_vaddr,
565 softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE);
567 /* Allocate the RSS tables */
568 rc = iflib_dma_alloc(ctx, HW_HASH_INDEX_SIZE * sizeof(uint16_t),
569 &softc->vnic_info.rss_grp_tbl, 0);
571 goto rss_grp_alloc_fail;
572 bus_dmamap_sync(softc->vnic_info.rss_grp_tbl.idi_tag,
573 softc->vnic_info.rss_grp_tbl.idi_map,
574 BUS_DMASYNC_PREWRITE);
575 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
576 softc->vnic_info.rss_grp_tbl.idi_size);
578 softc->nrxqsets = nrxqsets;
582 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
584 iflib_dma_free(&softc->vnic_info.mc_list);
587 for (i = i - 1; i >= 0; i--)
588 free(softc->rx_rings[i].tpa_start, M_DEVBUF);
589 iflib_dma_free(&softc->rx_stats);
591 free(softc->grp_info, M_DEVBUF);
593 free(softc->ag_rings, M_DEVBUF);
595 free(softc->rx_rings, M_DEVBUF);
597 free(softc->rx_cp_rings, M_DEVBUF);
602 /* Device setup and teardown */
604 bnxt_attach_pre(if_ctx_t ctx)
606 struct bnxt_softc *softc = iflib_get_softc(ctx);
607 if_softc_ctx_t scctx;
611 softc->dev = iflib_get_dev(ctx);
612 softc->media = iflib_get_media(ctx);
613 softc->scctx = iflib_get_softc_ctx(ctx);
614 softc->sctx = iflib_get_sctx(ctx);
615 scctx = softc->scctx;
617 /* TODO: Better way of detecting NPAR/VF is needed */
618 switch (softc->sctx->isc_vendor_info->pvi_device_id) {
629 softc->flags |= BNXT_FLAG_NPAR;
631 case NETXTREME_C_VF1:
632 case NETXTREME_C_VF2:
633 case NETXTREME_C_VF3:
634 case NETXTREME_E_VF1:
635 case NETXTREME_E_VF2:
636 case NETXTREME_E_VF3:
637 softc->flags |= BNXT_FLAG_VF;
641 pci_enable_busmaster(softc->dev);
643 if (bnxt_pci_mapping(softc))
646 /* HWRM setup/init */
647 BNXT_HWRM_LOCK_INIT(softc, device_get_nameunit(softc->dev));
648 rc = bnxt_alloc_hwrm_dma_mem(softc);
653 /* Get firmware version and compare with driver */
654 softc->ver_info = malloc(sizeof(struct bnxt_ver_info),
655 M_DEVBUF, M_NOWAIT | M_ZERO);
656 if (softc->ver_info == NULL) {
658 device_printf(softc->dev,
659 "Unable to allocate space for version info\n");
662 /* Default minimum required HWRM version */
663 softc->ver_info->hwrm_min_major = 1;
664 softc->ver_info->hwrm_min_minor = 2;
665 softc->ver_info->hwrm_min_update = 2;
667 rc = bnxt_hwrm_ver_get(softc);
669 device_printf(softc->dev, "attach: hwrm ver get failed\n");
674 softc->nvm_info = malloc(sizeof(struct bnxt_nvram_info),
675 M_DEVBUF, M_NOWAIT | M_ZERO);
676 if (softc->nvm_info == NULL) {
678 device_printf(softc->dev,
679 "Unable to allocate space for NVRAM info\n");
682 rc = bnxt_hwrm_nvm_get_dev_info(softc, &softc->nvm_info->mfg_id,
683 &softc->nvm_info->device_id, &softc->nvm_info->sector_size,
684 &softc->nvm_info->size, &softc->nvm_info->reserved_size,
685 &softc->nvm_info->available_size);
687 /* Register the driver with the FW */
688 rc = bnxt_hwrm_func_drv_rgtr(softc);
690 device_printf(softc->dev, "attach: hwrm drv rgtr failed\n");
694 /* Get the HW capabilities */
695 rc = bnxt_hwrm_func_qcaps(softc);
699 iflib_set_mac(ctx, softc->func.mac_addr);
701 scctx->isc_txrx = &bnxt_txrx;
702 scctx->isc_tx_csum_flags = (CSUM_IP | CSUM_TCP | CSUM_UDP |
703 CSUM_TCP_IPV6 | CSUM_UDP_IPV6 | CSUM_TSO);
704 scctx->isc_capenable =
705 /* These are translated to hwassit bits */
706 IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | IFCAP_TSO4 | IFCAP_TSO6 |
707 /* These are checked by iflib */
708 IFCAP_LRO | IFCAP_VLAN_HWFILTER |
709 /* These are part of the iflib mask */
710 IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_VLAN_MTU |
711 IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO |
712 /* These likely get lost... */
713 IFCAP_VLAN_HWCSUM | IFCAP_JUMBO_MTU;
715 if (bnxt_wol_supported(softc))
716 scctx->isc_capenable |= IFCAP_WOL_MAGIC;
718 /* Get the queue config */
719 rc = bnxt_hwrm_queue_qportcfg(softc);
721 device_printf(softc->dev, "attach: hwrm qportcfg failed\n");
725 bnxt_get_wol_settings(softc);
727 /* Now perform a function reset */
728 rc = bnxt_hwrm_func_reset(softc);
729 bnxt_clear_ids(softc);
733 /* Now set up iflib sc */
734 scctx->isc_tx_nsegments = 31,
735 scctx->isc_tx_tso_segments_max = 31;
736 scctx->isc_tx_tso_size_max = BNXT_TSO_SIZE;
737 scctx->isc_tx_tso_segsize_max = BNXT_TSO_SIZE;
738 scctx->isc_vectors = softc->func.max_cp_rings;
739 scctx->isc_txrx = &bnxt_txrx;
741 if (scctx->isc_nrxd[0] <
742 ((scctx->isc_nrxd[1] * 4) + scctx->isc_nrxd[2]))
743 device_printf(softc->dev,
744 "WARNING: nrxd0 (%d) should be at least 4 * nrxd1 (%d) + nrxd2 (%d). Driver may be unstable\n",
745 scctx->isc_nrxd[0], scctx->isc_nrxd[1], scctx->isc_nrxd[2]);
746 if (scctx->isc_ntxd[0] < scctx->isc_ntxd[1] * 2)
747 device_printf(softc->dev,
748 "WARNING: ntxd0 (%d) should be at least 2 * ntxd1 (%d). Driver may be unstable\n",
749 scctx->isc_ntxd[0], scctx->isc_ntxd[1]);
750 scctx->isc_txqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_ntxd[0];
751 scctx->isc_txqsizes[1] = sizeof(struct tx_bd_short) *
753 scctx->isc_rxqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_nrxd[0];
754 scctx->isc_rxqsizes[1] = sizeof(struct rx_prod_pkt_bd) *
756 scctx->isc_rxqsizes[2] = sizeof(struct rx_prod_pkt_bd) *
758 scctx->isc_max_rxqsets = min(pci_msix_count(softc->dev)-1,
759 softc->func.max_cp_rings - 1);
760 scctx->isc_max_rxqsets = min(scctx->isc_max_rxqsets,
761 softc->func.max_rx_rings);
762 scctx->isc_max_txqsets = min(softc->func.max_rx_rings,
763 softc->func.max_cp_rings - scctx->isc_max_rxqsets - 1);
764 scctx->isc_rss_table_size = HW_HASH_INDEX_SIZE;
765 scctx->isc_rss_table_mask = scctx->isc_rss_table_size - 1;
767 /* iflib will map and release this bar */
768 scctx->isc_msix_bar = pci_msix_table_bar(softc->dev);
770 /* Allocate the default completion ring */
771 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
772 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
773 softc->def_cp_ring.ring.softc = softc;
774 softc->def_cp_ring.ring.id = 0;
775 softc->def_cp_ring.ring.doorbell = softc->def_cp_ring.ring.id * 0x80;
776 softc->def_cp_ring.ring.ring_size = PAGE_SIZE /
777 sizeof(struct cmpl_base);
778 rc = iflib_dma_alloc(ctx,
779 sizeof(struct cmpl_base) * softc->def_cp_ring.ring.ring_size,
780 &softc->def_cp_ring_mem, 0);
781 softc->def_cp_ring.ring.vaddr = softc->def_cp_ring_mem.idi_vaddr;
782 softc->def_cp_ring.ring.paddr = softc->def_cp_ring_mem.idi_paddr;
783 iflib_config_gtask_init(ctx, &softc->def_cp_task, bnxt_def_cp_task,
786 rc = bnxt_init_sysctl_ctx(softc);
788 goto init_sysctl_failed;
789 rc = bnxt_create_nvram_sysctls(softc->nvm_info);
793 arc4rand(softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE, 0);
794 softc->vnic_info.rss_hash_type =
795 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4 |
796 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4 |
797 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4 |
798 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6 |
799 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6 |
800 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
801 rc = bnxt_create_config_sysctls_pre(softc);
805 /* Initialize the vlan list */
806 SLIST_INIT(&softc->vnic_info.vlan_tags);
807 softc->vnic_info.vlan_tag_list.idi_vaddr = NULL;
812 bnxt_free_sysctl_ctx(softc);
814 bnxt_hwrm_func_drv_unrgtr(softc, false);
816 free(softc->nvm_info, M_DEVBUF);
819 free(softc->ver_info, M_DEVBUF);
821 bnxt_free_hwrm_dma_mem(softc);
823 BNXT_HWRM_LOCK_DESTROY(softc);
824 bnxt_pci_mapping_free(softc);
825 pci_disable_busmaster(softc->dev);
830 bnxt_attach_post(if_ctx_t ctx)
832 struct bnxt_softc *softc = iflib_get_softc(ctx);
833 if_t ifp = iflib_get_ifp(ctx);
836 bnxt_create_config_sysctls_post(softc);
838 /* Update link state etc... */
839 rc = bnxt_probe_phy(softc);
843 /* Needs to be done after probing the phy */
844 bnxt_create_ver_sysctls(softc);
845 bnxt_add_media_types(softc);
846 ifmedia_set(softc->media, IFM_ETHER | IFM_AUTO);
848 softc->scctx->isc_max_frame_size = ifp->if_mtu + ETHER_HDR_LEN +
856 bnxt_detach(if_ctx_t ctx)
858 struct bnxt_softc *softc = iflib_get_softc(ctx);
859 struct bnxt_vlan_tag *tag;
860 struct bnxt_vlan_tag *tmp;
863 bnxt_wol_config(ctx);
864 bnxt_do_disable_intr(&softc->def_cp_ring);
865 bnxt_free_sysctl_ctx(softc);
866 bnxt_hwrm_func_reset(softc);
867 bnxt_clear_ids(softc);
868 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
869 iflib_config_gtask_deinit(&softc->def_cp_task);
870 /* We need to free() these here... */
871 for (i = softc->nrxqsets-1; i>=0; i--) {
872 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
874 iflib_dma_free(&softc->vnic_info.mc_list);
875 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
876 iflib_dma_free(&softc->vnic_info.rss_grp_tbl);
877 if (softc->vnic_info.vlan_tag_list.idi_vaddr)
878 iflib_dma_free(&softc->vnic_info.vlan_tag_list);
879 SLIST_FOREACH_SAFE(tag, &softc->vnic_info.vlan_tags, next, tmp)
881 iflib_dma_free(&softc->def_cp_ring_mem);
882 for (i = 0; i < softc->nrxqsets; i++)
883 free(softc->rx_rings[i].tpa_start, M_DEVBUF);
884 free(softc->ver_info, M_DEVBUF);
885 free(softc->nvm_info, M_DEVBUF);
887 bnxt_hwrm_func_drv_unrgtr(softc, false);
888 bnxt_free_hwrm_dma_mem(softc);
889 BNXT_HWRM_LOCK_DESTROY(softc);
891 pci_disable_busmaster(softc->dev);
892 bnxt_pci_mapping_free(softc);
897 /* Device configuration */
899 bnxt_init(if_ctx_t ctx)
901 struct bnxt_softc *softc = iflib_get_softc(ctx);
902 struct ifmediareq ifmr;
906 rc = bnxt_hwrm_func_reset(softc);
909 bnxt_clear_ids(softc);
911 /* Allocate the default completion ring */
912 softc->def_cp_ring.cons = UINT32_MAX;
913 softc->def_cp_ring.v_bit = 1;
914 bnxt_mark_cpr_invalid(&softc->def_cp_ring);
915 rc = bnxt_hwrm_ring_alloc(softc,
916 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
917 &softc->def_cp_ring.ring,
918 (uint16_t)HWRM_NA_SIGNATURE,
919 HWRM_NA_SIGNATURE, true);
923 /* And now set the default CP ring as the async CP ring */
924 rc = bnxt_hwrm_func_cfg(softc);
928 for (i = 0; i < softc->nrxqsets; i++) {
929 /* Allocate the statistics context */
930 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->rx_cp_rings[i],
931 softc->rx_stats.idi_paddr +
932 (sizeof(struct ctx_hw_stats) * i));
936 /* Allocate the completion ring */
937 softc->rx_cp_rings[i].cons = UINT32_MAX;
938 softc->rx_cp_rings[i].v_bit = 1;
939 softc->rx_cp_rings[i].last_idx = UINT32_MAX;
940 bnxt_mark_cpr_invalid(&softc->rx_cp_rings[i]);
941 rc = bnxt_hwrm_ring_alloc(softc,
942 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
943 &softc->rx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
944 HWRM_NA_SIGNATURE, true);
948 /* Allocate the RX ring */
949 rc = bnxt_hwrm_ring_alloc(softc,
950 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
951 &softc->rx_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
952 HWRM_NA_SIGNATURE, false);
955 BNXT_RX_DB(&softc->rx_rings[i], 0);
956 /* TODO: Cumulus+ doesn't need the double doorbell */
957 BNXT_RX_DB(&softc->rx_rings[i], 0);
959 /* Allocate the AG ring */
960 rc = bnxt_hwrm_ring_alloc(softc,
961 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
962 &softc->ag_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
963 HWRM_NA_SIGNATURE, false);
966 BNXT_RX_DB(&softc->rx_rings[i], 0);
967 /* TODO: Cumulus+ doesn't need the double doorbell */
968 BNXT_RX_DB(&softc->ag_rings[i], 0);
970 /* Allocate the ring group */
971 softc->grp_info[i].stats_ctx =
972 softc->rx_cp_rings[i].stats_ctx_id;
973 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
974 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
975 softc->grp_info[i].cp_ring_id =
976 softc->rx_cp_rings[i].ring.phys_id;
977 rc = bnxt_hwrm_ring_grp_alloc(softc, &softc->grp_info[i]);
983 /* Allocate the VNIC RSS context */
984 rc = bnxt_hwrm_vnic_ctx_alloc(softc, &softc->vnic_info.rss_id);
988 /* Allocate the vnic */
989 softc->vnic_info.def_ring_grp = softc->grp_info[0].grp_id;
990 softc->vnic_info.mru = softc->scctx->isc_max_frame_size;
991 rc = bnxt_hwrm_vnic_alloc(softc, &softc->vnic_info);
994 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
997 rc = bnxt_hwrm_set_filter(softc, &softc->vnic_info);
1001 /* Enable RSS on the VNICs */
1002 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
1004 softc->vnic_info.rss_grp_tbl.idi_vaddr)[i] =
1005 htole16(softc->grp_info[j].grp_id);
1006 if (++j == softc->nrxqsets)
1010 rc = bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1011 softc->vnic_info.rss_hash_type);
1016 * Enable LRO/TPA/GRO
1018 * Enable / Disable HW_LRO based on
1019 * ifconfig lro / ifconfig -lro setting
1021 rc = bnxt_hwrm_vnic_tpa_cfg(softc, &softc->vnic_info,
1022 (if_getcapenable(iflib_get_ifp(ctx)) & IFCAP_LRO) ?
1023 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA : 0);
1027 for (i = 0; i < softc->ntxqsets; i++) {
1028 /* Allocate the statistics context */
1029 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->tx_cp_rings[i],
1030 softc->tx_stats.idi_paddr +
1031 (sizeof(struct ctx_hw_stats) * i));
1035 /* Allocate the completion ring */
1036 softc->tx_cp_rings[i].cons = UINT32_MAX;
1037 softc->tx_cp_rings[i].v_bit = 1;
1038 bnxt_mark_cpr_invalid(&softc->tx_cp_rings[i]);
1039 rc = bnxt_hwrm_ring_alloc(softc,
1040 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
1041 &softc->tx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
1042 HWRM_NA_SIGNATURE, false);
1046 /* Allocate the TX ring */
1047 rc = bnxt_hwrm_ring_alloc(softc,
1048 HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
1049 &softc->tx_rings[i], softc->tx_cp_rings[i].ring.phys_id,
1050 softc->tx_cp_rings[i].stats_ctx_id, false);
1053 BNXT_TX_DB(&softc->tx_rings[i], 0);
1054 /* TODO: Cumulus+ doesn't need the double doorbell */
1055 BNXT_TX_DB(&softc->tx_rings[i], 0);
1058 bnxt_do_enable_intr(&softc->def_cp_ring);
1059 bnxt_media_status(softc->ctx, &ifmr);
1063 bnxt_hwrm_func_reset(softc);
1064 bnxt_clear_ids(softc);
1069 bnxt_stop(if_ctx_t ctx)
1071 struct bnxt_softc *softc = iflib_get_softc(ctx);
1073 bnxt_do_disable_intr(&softc->def_cp_ring);
1074 bnxt_hwrm_func_reset(softc);
1075 bnxt_clear_ids(softc);
1080 bnxt_multi_set(if_ctx_t ctx)
1082 struct bnxt_softc *softc = iflib_get_softc(ctx);
1083 if_t ifp = iflib_get_ifp(ctx);
1087 mcnt = if_multiaddr_count(ifp, -1);
1089 if (mcnt > BNXT_MAX_MC_ADDRS) {
1090 softc->vnic_info.rx_mask |=
1091 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1092 bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1095 softc->vnic_info.rx_mask &=
1096 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1097 mta = softc->vnic_info.mc_list.idi_vaddr;
1098 bzero(mta, softc->vnic_info.mc_list.idi_size);
1099 if_multiaddr_array(ifp, mta, &cnt, mcnt);
1100 bus_dmamap_sync(softc->vnic_info.mc_list.idi_tag,
1101 softc->vnic_info.mc_list.idi_map, BUS_DMASYNC_PREWRITE);
1102 softc->vnic_info.mc_list_count = cnt;
1103 softc->vnic_info.rx_mask |=
1104 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
1105 if (bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info))
1106 device_printf(softc->dev,
1107 "set_multi: rx_mask set failed\n");
1112 bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu)
1114 struct bnxt_softc *softc = iflib_get_softc(ctx);
1116 if (mtu > BNXT_MAX_MTU)
1119 softc->scctx->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1124 bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
1126 struct bnxt_softc *softc = iflib_get_softc(ctx);
1127 struct bnxt_link_info *link_info = &softc->link_info;
1128 uint8_t phy_type = get_phy_type(softc);
1130 bnxt_update_link(softc, true);
1132 ifmr->ifm_status = IFM_AVALID;
1133 ifmr->ifm_active = IFM_ETHER;
1135 if (link_info->link_up)
1136 ifmr->ifm_status |= IFM_ACTIVE;
1138 ifmr->ifm_status &= ~IFM_ACTIVE;
1140 if (link_info->duplex == HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
1141 ifmr->ifm_active |= IFM_FDX;
1143 ifmr->ifm_active |= IFM_HDX;
1145 switch (link_info->link_speed) {
1146 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1147 ifmr->ifm_active |= IFM_100_T;
1149 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1151 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1152 ifmr->ifm_active |= IFM_1000_KX;
1154 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1155 ifmr->ifm_active |= IFM_1000_T;
1157 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
1158 ifmr->ifm_active |= IFM_1000_SGMII;
1163 * Don't return IFM_UNKNOWN until
1164 * Stratus return proper media_type
1166 ifmr->ifm_active |= IFM_1000_KX;
1170 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1172 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1173 ifmr->ifm_active |= IFM_2500_KX;
1175 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1176 ifmr->ifm_active |= IFM_2500_T;
1179 ifmr->ifm_active |= IFM_UNKNOWN;
1183 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1185 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1186 ifmr->ifm_active |= IFM_10G_CR1;
1188 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1189 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1190 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1191 ifmr->ifm_active |= IFM_10G_KR;
1193 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1194 ifmr->ifm_active |= IFM_10G_LR;
1196 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1197 ifmr->ifm_active |= IFM_10G_SR;
1199 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1200 ifmr->ifm_active |= IFM_10G_KX4;
1202 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1203 ifmr->ifm_active |= IFM_10G_T;
1208 * Don't return IFM_UNKNOWN until
1209 * Stratus return proper media_type
1211 ifmr->ifm_active |= IFM_10G_CR1;
1215 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1216 ifmr->ifm_active |= IFM_20G_KR2;
1218 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1220 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1221 ifmr->ifm_active |= IFM_25G_CR;
1223 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1224 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1225 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1226 ifmr->ifm_active |= IFM_25G_KR;
1228 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1229 ifmr->ifm_active |= IFM_25G_SR;
1234 * Don't return IFM_UNKNOWN until
1235 * Stratus return proper media_type
1237 ifmr->ifm_active |= IFM_25G_CR;
1241 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1243 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1244 ifmr->ifm_active |= IFM_40G_CR4;
1246 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1247 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1248 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1249 ifmr->ifm_active |= IFM_40G_KR4;
1251 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1252 ifmr->ifm_active |= IFM_40G_LR4;
1254 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1255 ifmr->ifm_active |= IFM_40G_SR4;
1258 ifmr->ifm_active |= IFM_UNKNOWN;
1262 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1264 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1265 ifmr->ifm_active |= IFM_50G_CR2;
1267 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1268 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1269 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1270 ifmr->ifm_active |= IFM_50G_KR2;
1275 * Don't return IFM_UNKNOWN until
1276 * Stratus return proper media_type
1278 ifmr->ifm_active |= IFM_50G_CR2;
1282 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
1284 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1285 ifmr->ifm_active |= IFM_100G_CR4;
1287 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1288 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1289 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1290 ifmr->ifm_active |= IFM_100G_KR4;
1292 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1293 ifmr->ifm_active |= IFM_100G_LR4;
1295 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1296 ifmr->ifm_active |= IFM_100G_SR4;
1301 * Don't return IFM_UNKNOWN until
1302 * Stratus return proper media_type
1304 ifmr->ifm_active |= IFM_100G_CR4;
1311 if (link_info->pause == (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1312 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1313 ifmr->ifm_active |= (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
1314 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
1315 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
1316 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
1317 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
1319 bnxt_report_link(softc);
1324 bnxt_media_change(if_ctx_t ctx)
1326 struct bnxt_softc *softc = iflib_get_softc(ctx);
1327 struct ifmedia *ifm = iflib_get_media(ctx);
1328 struct ifmediareq ifmr;
1331 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1334 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1336 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1337 softc->link_info.req_link_speed =
1338 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
1342 case IFM_1000_SGMII:
1343 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1344 softc->link_info.req_link_speed =
1345 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
1349 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1350 softc->link_info.req_link_speed =
1351 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
1358 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1359 softc->link_info.req_link_speed =
1360 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1363 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1364 softc->link_info.req_link_speed =
1365 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
1370 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1371 softc->link_info.req_link_speed =
1372 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
1378 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1379 softc->link_info.req_link_speed =
1380 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1384 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1385 softc->link_info.req_link_speed =
1386 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1392 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1393 softc->link_info.req_link_speed =
1394 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
1397 device_printf(softc->dev,
1398 "Unsupported media type! Using auto\n");
1402 softc->link_info.autoneg |= BNXT_AUTONEG_SPEED;
1405 rc = bnxt_hwrm_set_link_setting(softc, true, true);
1406 bnxt_media_status(softc->ctx, &ifmr);
1411 bnxt_promisc_set(if_ctx_t ctx, int flags)
1413 struct bnxt_softc *softc = iflib_get_softc(ctx);
1414 if_t ifp = iflib_get_ifp(ctx);
1417 if (ifp->if_flags & IFF_ALLMULTI ||
1418 if_multiaddr_count(ifp, -1) > BNXT_MAX_MC_ADDRS)
1419 softc->vnic_info.rx_mask |=
1420 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1422 softc->vnic_info.rx_mask &=
1423 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1425 if (ifp->if_flags & IFF_PROMISC)
1426 softc->vnic_info.rx_mask |=
1427 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1428 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN;
1430 softc->vnic_info.rx_mask &=
1431 ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1432 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
1434 rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1440 bnxt_get_counter(if_ctx_t ctx, ift_counter cnt)
1442 if_t ifp = iflib_get_ifp(ctx);
1444 if (cnt < IFCOUNTERS)
1445 return if_get_counter_default(ifp, cnt);
1451 bnxt_update_admin_status(if_ctx_t ctx)
1453 /* TODO: do we need to do anything here? */
1458 bnxt_do_enable_intr(struct bnxt_cp_ring *cpr)
1460 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE) {
1461 /* First time enabling, do not set index */
1462 if (cpr->cons == UINT32_MAX)
1463 BNXT_CP_ENABLE_DB(&cpr->ring);
1465 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
1470 bnxt_do_disable_intr(struct bnxt_cp_ring *cpr)
1472 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE)
1473 BNXT_CP_DISABLE_DB(&cpr->ring);
1476 /* Enable all interrupts */
1478 bnxt_intr_enable(if_ctx_t ctx)
1480 struct bnxt_softc *softc = iflib_get_softc(ctx);
1483 bnxt_do_enable_intr(&softc->def_cp_ring);
1484 for (i = 0; i < softc->nrxqsets; i++)
1485 bnxt_do_enable_intr(&softc->rx_cp_rings[i]);
1490 /* Enable interrupt for a single queue */
1492 bnxt_tx_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1494 struct bnxt_softc *softc = iflib_get_softc(ctx);
1496 bnxt_do_enable_intr(&softc->tx_cp_rings[qid]);
1501 bnxt_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1503 struct bnxt_softc *softc = iflib_get_softc(ctx);
1505 bnxt_do_enable_intr(&softc->rx_cp_rings[qid]);
1509 /* Disable all interrupts */
1511 bnxt_disable_intr(if_ctx_t ctx)
1513 struct bnxt_softc *softc = iflib_get_softc(ctx);
1517 * NOTE: These TX interrupts should never get enabled, so don't
1520 for (i = 0; i < softc->ntxqsets; i++)
1521 bnxt_do_disable_intr(&softc->tx_cp_rings[i]);
1522 for (i = 0; i < softc->nrxqsets; i++)
1523 bnxt_do_disable_intr(&softc->rx_cp_rings[i]);
1529 bnxt_msix_intr_assign(if_ctx_t ctx, int msix)
1531 struct bnxt_softc *softc = iflib_get_softc(ctx);
1536 rc = iflib_irq_alloc_generic(ctx, &softc->def_cp_ring.irq,
1537 softc->def_cp_ring.ring.id + 1, IFLIB_INTR_ADMIN,
1538 bnxt_handle_def_cp, softc, 0, "def_cp");
1540 device_printf(iflib_get_dev(ctx),
1541 "Failed to register default completion ring handler\n");
1545 for (i=0; i<softc->scctx->isc_nrxqsets; i++) {
1546 snprintf(irq_name, sizeof(irq_name), "rxq%d", i);
1547 rc = iflib_irq_alloc_generic(ctx, &softc->rx_cp_rings[i].irq,
1548 softc->rx_cp_rings[i].ring.id + 1, IFLIB_INTR_RX,
1549 bnxt_handle_rx_cp, &softc->rx_cp_rings[i], i, irq_name);
1551 device_printf(iflib_get_dev(ctx),
1552 "Failed to register RX completion ring handler\n");
1558 for (i=0; i<softc->scctx->isc_ntxqsets; i++)
1559 iflib_softirq_alloc_generic(ctx, i + 1, IFLIB_INTR_TX, NULL, i,
1566 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
1567 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
1572 * We're explicitly allowing duplicates here. They will need to be
1573 * removed as many times as they are added.
1576 bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag)
1578 struct bnxt_softc *softc = iflib_get_softc(ctx);
1579 struct bnxt_vlan_tag *new_tag;
1581 new_tag = malloc(sizeof(struct bnxt_vlan_tag), M_DEVBUF, M_NOWAIT);
1582 if (new_tag == NULL)
1584 new_tag->tag = vtag;
1585 new_tag->tpid = 8100;
1586 SLIST_INSERT_HEAD(&softc->vnic_info.vlan_tags, new_tag, next);
1590 bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag)
1592 struct bnxt_softc *softc = iflib_get_softc(ctx);
1593 struct bnxt_vlan_tag *vlan_tag;
1595 SLIST_FOREACH(vlan_tag, &softc->vnic_info.vlan_tags, next) {
1596 if (vlan_tag->tag == vtag) {
1597 SLIST_REMOVE(&softc->vnic_info.vlan_tags, vlan_tag,
1598 bnxt_vlan_tag, next);
1599 free(vlan_tag, M_DEVBUF);
1606 bnxt_wol_config(if_ctx_t ctx)
1608 struct bnxt_softc *softc = iflib_get_softc(ctx);
1609 if_t ifp = iflib_get_ifp(ctx);
1614 if (!bnxt_wol_supported(softc))
1617 if (if_getcapabilities(ifp) & IFCAP_WOL_MAGIC) {
1619 if (bnxt_hwrm_alloc_wol_fltr(softc))
1625 if (bnxt_hwrm_free_wol_fltr(softc))
1635 bnxt_shutdown(if_ctx_t ctx)
1637 bnxt_wol_config(ctx);
1642 bnxt_suspend(if_ctx_t ctx)
1644 bnxt_wol_config(ctx);
1649 bnxt_resume(if_ctx_t ctx)
1651 struct bnxt_softc *softc = iflib_get_softc(ctx);
1653 bnxt_get_wol_settings(softc);
1658 bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data)
1660 struct bnxt_softc *softc = iflib_get_softc(ctx);
1661 struct ifreq *ifr = (struct ifreq *)data;
1662 struct ifreq_buffer *ifbuf = &ifr->ifr_ifru.ifru_buffer;
1663 struct bnxt_ioctl_header *ioh =
1664 (struct bnxt_ioctl_header *)(ifbuf->buffer);
1666 struct bnxt_ioctl_data *iod = NULL;
1669 case SIOCGPRIVATE_0:
1670 if ((rc = priv_check(curthread, PRIV_DRIVER)) != 0)
1673 iod = malloc(ifbuf->length, M_DEVBUF, M_NOWAIT | M_ZERO);
1678 copyin(ioh, iod, ifbuf->length);
1680 switch (ioh->type) {
1681 case BNXT_HWRM_NVM_FIND_DIR_ENTRY:
1683 struct bnxt_ioctl_hwrm_nvm_find_dir_entry *find =
1686 rc = bnxt_hwrm_nvm_find_dir_entry(softc, find->type,
1687 &find->ordinal, find->ext, &find->index,
1688 find->use_index, find->search_opt,
1689 &find->data_length, &find->item_length,
1693 copyout(&iod->hdr.rc, &ioh->rc,
1698 copyout(iod, ioh, ifbuf->length);
1704 case BNXT_HWRM_NVM_READ:
1706 struct bnxt_ioctl_hwrm_nvm_read *rd = &iod->read;
1707 struct iflib_dma_info dma_data;
1713 * Some HWRM versions can't read more than 0x8000 bytes
1715 rc = iflib_dma_alloc(softc->ctx,
1716 min(rd->length, 0x8000), &dma_data, BUS_DMA_NOWAIT);
1719 for (remain = rd->length, offset = 0;
1720 remain && offset < rd->length; offset += 0x8000) {
1721 csize = min(remain, 0x8000);
1722 rc = bnxt_hwrm_nvm_read(softc, rd->index,
1723 rd->offset + offset, csize, &dma_data);
1726 copyout(&iod->hdr.rc, &ioh->rc,
1731 copyout(dma_data.idi_vaddr,
1732 rd->data + offset, csize);
1737 if (iod->hdr.rc == 0)
1738 copyout(iod, ioh, ifbuf->length);
1740 iflib_dma_free(&dma_data);
1744 case BNXT_HWRM_FW_RESET:
1746 struct bnxt_ioctl_hwrm_fw_reset *rst =
1749 rc = bnxt_hwrm_fw_reset(softc, rst->processor,
1753 copyout(&iod->hdr.rc, &ioh->rc,
1758 copyout(iod, ioh, ifbuf->length);
1764 case BNXT_HWRM_FW_QSTATUS:
1766 struct bnxt_ioctl_hwrm_fw_qstatus *qstat =
1769 rc = bnxt_hwrm_fw_qstatus(softc, qstat->processor,
1773 copyout(&iod->hdr.rc, &ioh->rc,
1778 copyout(iod, ioh, ifbuf->length);
1784 case BNXT_HWRM_NVM_WRITE:
1786 struct bnxt_ioctl_hwrm_nvm_write *wr =
1789 rc = bnxt_hwrm_nvm_write(softc, wr->data, true,
1790 wr->type, wr->ordinal, wr->ext, wr->attr,
1791 wr->option, wr->data_length, wr->keep,
1792 &wr->item_length, &wr->index);
1795 copyout(&iod->hdr.rc, &ioh->rc,
1800 copyout(iod, ioh, ifbuf->length);
1806 case BNXT_HWRM_NVM_ERASE_DIR_ENTRY:
1808 struct bnxt_ioctl_hwrm_nvm_erase_dir_entry *erase =
1811 rc = bnxt_hwrm_nvm_erase_dir_entry(softc, erase->index);
1814 copyout(&iod->hdr.rc, &ioh->rc,
1819 copyout(iod, ioh, ifbuf->length);
1825 case BNXT_HWRM_NVM_GET_DIR_INFO:
1827 struct bnxt_ioctl_hwrm_nvm_get_dir_info *info =
1830 rc = bnxt_hwrm_nvm_get_dir_info(softc, &info->entries,
1831 &info->entry_length);
1834 copyout(&iod->hdr.rc, &ioh->rc,
1839 copyout(iod, ioh, ifbuf->length);
1845 case BNXT_HWRM_NVM_GET_DIR_ENTRIES:
1847 struct bnxt_ioctl_hwrm_nvm_get_dir_entries *get =
1849 struct iflib_dma_info dma_data;
1851 rc = iflib_dma_alloc(softc->ctx, get->max_size,
1852 &dma_data, BUS_DMA_NOWAIT);
1855 rc = bnxt_hwrm_nvm_get_dir_entries(softc, &get->entries,
1856 &get->entry_length, &dma_data);
1859 copyout(&iod->hdr.rc, &ioh->rc,
1863 copyout(dma_data.idi_vaddr, get->data,
1864 get->entry_length * get->entries);
1866 copyout(iod, ioh, ifbuf->length);
1868 iflib_dma_free(&dma_data);
1873 case BNXT_HWRM_NVM_VERIFY_UPDATE:
1875 struct bnxt_ioctl_hwrm_nvm_verify_update *vrfy =
1878 rc = bnxt_hwrm_nvm_verify_update(softc, vrfy->type,
1879 vrfy->ordinal, vrfy->ext);
1882 copyout(&iod->hdr.rc, &ioh->rc,
1887 copyout(iod, ioh, ifbuf->length);
1893 case BNXT_HWRM_NVM_INSTALL_UPDATE:
1895 struct bnxt_ioctl_hwrm_nvm_install_update *inst =
1898 rc = bnxt_hwrm_nvm_install_update(softc,
1899 inst->install_type, &inst->installed_items,
1900 &inst->result, &inst->problem_item,
1901 &inst->reset_required);
1904 copyout(&iod->hdr.rc, &ioh->rc,
1909 copyout(iod, ioh, ifbuf->length);
1915 case BNXT_HWRM_NVM_MODIFY:
1917 struct bnxt_ioctl_hwrm_nvm_modify *mod = &iod->modify;
1919 rc = bnxt_hwrm_nvm_modify(softc, mod->index,
1920 mod->offset, mod->data, true, mod->length);
1923 copyout(&iod->hdr.rc, &ioh->rc,
1928 copyout(iod, ioh, ifbuf->length);
1934 case BNXT_HWRM_FW_GET_TIME:
1936 struct bnxt_ioctl_hwrm_fw_get_time *gtm =
1939 rc = bnxt_hwrm_fw_get_time(softc, >m->year,
1940 >m->month, >m->day, >m->hour, >m->minute,
1941 >m->second, >m->millisecond, >m->zone);
1944 copyout(&iod->hdr.rc, &ioh->rc,
1949 copyout(iod, ioh, ifbuf->length);
1955 case BNXT_HWRM_FW_SET_TIME:
1957 struct bnxt_ioctl_hwrm_fw_set_time *stm =
1960 rc = bnxt_hwrm_fw_set_time(softc, stm->year,
1961 stm->month, stm->day, stm->hour, stm->minute,
1962 stm->second, stm->millisecond, stm->zone);
1965 copyout(&iod->hdr.rc, &ioh->rc,
1970 copyout(iod, ioh, ifbuf->length);
1982 free(iod, M_DEVBUF);
1990 bnxt_probe_phy(struct bnxt_softc *softc)
1992 struct bnxt_link_info *link_info = &softc->link_info;
1995 rc = bnxt_update_link(softc, false);
1997 device_printf(softc->dev,
1998 "Probe phy can't update link (rc: %x)\n", rc);
2002 /*initialize the ethool setting copy with NVM settings */
2003 if (link_info->auto_mode != HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
2004 link_info->autoneg |= BNXT_AUTONEG_SPEED;
2006 if (link_info->auto_pause & (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2007 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
2008 if (link_info->auto_pause == (
2009 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2010 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2011 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
2012 link_info->req_flow_ctrl = link_info->auto_pause;
2013 } else if (link_info->force_pause & (
2014 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2015 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
2016 link_info->req_flow_ctrl = link_info->force_pause;
2018 link_info->req_duplex = link_info->duplex_setting;
2019 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
2020 link_info->req_link_speed = link_info->auto_link_speed;
2022 link_info->req_link_speed = link_info->force_link_speed;
2027 bnxt_add_media_types(struct bnxt_softc *softc)
2029 struct bnxt_link_info *link_info = &softc->link_info;
2031 uint8_t phy_type = get_phy_type(softc);
2033 supported = link_info->support_speeds;
2035 /* Auto is always supported */
2036 ifmedia_add(softc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2038 if (softc->flags & BNXT_FLAG_NPAR)
2042 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
2043 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2044 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0,
2046 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
2047 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0,
2049 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2050 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_CR4, 0,
2052 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2053 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0,
2055 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2056 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0,
2059 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
2060 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
2061 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
2062 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2063 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_KR4, 0,
2065 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
2066 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_KR2, 0,
2068 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2069 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_KR4, 0,
2071 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2072 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_KR, 0,
2074 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2075 ifmedia_add(softc->media, IFM_ETHER | IFM_20G_KR2, 0,
2077 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2078 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KR, 0,
2081 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
2082 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2083 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_LR4, 0,
2085 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2086 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_LR4, 0,
2088 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2089 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_LR, 0,
2092 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
2093 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2094 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_SR4, 0,
2096 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2097 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_SR4, 0,
2099 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2100 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_SR, 0,
2102 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2103 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_SR, 0,
2106 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
2107 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2108 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KX4, 0,
2110 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2111 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_KX, 0,
2113 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2114 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_KX, 0,
2117 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
2118 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE:
2119 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10MB)
2120 ifmedia_add(softc->media, IFM_ETHER | IFM_10_T, 0,
2122 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MB)
2123 ifmedia_add(softc->media, IFM_ETHER | IFM_100_T, 0,
2125 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2126 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0,
2128 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2129 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_T, 0,
2131 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2132 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_T, 0,
2135 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
2136 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2137 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_SGMII, 0,
2140 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN:
2143 * Workaround for Cumulus & Stratus
2145 * media_type is being returned as 0x0
2146 * Return support speeds as 10G, 25G, 50G & 100G
2149 * phy_type is being returned as 0x14 (PHY_TYPE_40G_BASECR4)
2150 * Return support speeds as 1G, 10G, 25G & 50G
2152 if (pci_get_device(softc->dev) == BCM57454) {
2153 /* For Stratus: 10G, 25G, 50G & 100G */
2154 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0, NULL);
2155 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0, NULL);
2156 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0, NULL);
2157 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0, NULL);
2158 } else if (pci_get_device(softc->dev) == BCM57414) {
2159 /* For Cumulus: 1G, 10G, 25G & 50G */
2160 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0, NULL);
2161 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0, NULL);
2162 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0, NULL);
2163 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0, NULL);
2172 bnxt_map_bar(struct bnxt_softc *softc, struct bnxt_bar_info *bar, int bar_num, bool shareable)
2176 if (bar->res != NULL) {
2177 device_printf(softc->dev, "Bar %d already mapped\n", bar_num);
2181 bar->rid = PCIR_BAR(bar_num);
2184 flag |= RF_SHAREABLE;
2187 bus_alloc_resource_any(softc->dev,
2191 device_printf(softc->dev,
2192 "PCI BAR%d mapping failure\n", bar_num);
2195 bar->tag = rman_get_bustag(bar->res);
2196 bar->handle = rman_get_bushandle(bar->res);
2197 bar->size = rman_get_size(bar->res);
2203 bnxt_pci_mapping(struct bnxt_softc *softc)
2207 rc = bnxt_map_bar(softc, &softc->hwrm_bar, 0, true);
2211 rc = bnxt_map_bar(softc, &softc->doorbell_bar, 2, false);
2217 bnxt_pci_mapping_free(struct bnxt_softc *softc)
2219 if (softc->hwrm_bar.res != NULL)
2220 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2221 softc->hwrm_bar.rid, softc->hwrm_bar.res);
2222 softc->hwrm_bar.res = NULL;
2224 if (softc->doorbell_bar.res != NULL)
2225 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2226 softc->doorbell_bar.rid, softc->doorbell_bar.res);
2227 softc->doorbell_bar.res = NULL;
2231 bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state)
2233 struct bnxt_link_info *link_info = &softc->link_info;
2234 uint8_t link_up = link_info->link_up;
2237 rc = bnxt_hwrm_port_phy_qcfg(softc);
2241 /* TODO: need to add more logic to report VF link */
2242 if (chng_link_state) {
2243 if (link_info->phy_link_status ==
2244 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK)
2245 link_info->link_up = 1;
2247 link_info->link_up = 0;
2248 if (link_up != link_info->link_up)
2249 bnxt_report_link(softc);
2251 /* always link down if not require to update link state */
2252 link_info->link_up = 0;
2260 bnxt_report_link(struct bnxt_softc *softc)
2262 const char *duplex = NULL, *flow_ctrl = NULL;
2264 if (softc->link_info.link_up == softc->link_info.last_link_up) {
2265 if (!softc->link_info.link_up)
2267 if (softc->link_info.pause == softc->link_info.last_pause &&
2268 softc->link_info.duplex == softc->link_info.last_duplex)
2272 if (softc->link_info.link_up) {
2273 if (softc->link_info.duplex ==
2274 HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
2275 duplex = "full duplex";
2277 duplex = "half duplex";
2278 if (softc->link_info.pause == (
2279 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2280 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2281 flow_ctrl = "FC - receive & transmit";
2282 else if (softc->link_info.pause ==
2283 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
2284 flow_ctrl = "FC - transmit";
2285 else if (softc->link_info.pause ==
2286 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
2287 flow_ctrl = "FC - receive";
2290 iflib_link_state_change(softc->ctx, LINK_STATE_UP,
2292 device_printf(softc->dev, "Link is UP %s, %s\n", duplex,
2295 iflib_link_state_change(softc->ctx, LINK_STATE_DOWN,
2296 bnxt_get_baudrate(&softc->link_info));
2297 device_printf(softc->dev, "Link is Down\n");
2300 softc->link_info.last_link_up = softc->link_info.link_up;
2301 softc->link_info.last_pause = softc->link_info.pause;
2302 softc->link_info.last_duplex = softc->link_info.duplex;
2306 bnxt_handle_rx_cp(void *arg)
2308 struct bnxt_cp_ring *cpr = arg;
2310 /* Disable further interrupts for this queue */
2311 BNXT_CP_DISABLE_DB(&cpr->ring);
2312 return FILTER_SCHEDULE_THREAD;
2316 bnxt_handle_def_cp(void *arg)
2318 struct bnxt_softc *softc = arg;
2320 BNXT_CP_DISABLE_DB(&softc->def_cp_ring.ring);
2321 GROUPTASK_ENQUEUE(&softc->def_cp_task);
2322 return FILTER_HANDLED;
2326 bnxt_clear_ids(struct bnxt_softc *softc)
2330 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
2331 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2332 for (i = 0; i < softc->ntxqsets; i++) {
2333 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2334 softc->tx_cp_rings[i].ring.phys_id =
2335 (uint16_t)HWRM_NA_SIGNATURE;
2336 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2338 for (i = 0; i < softc->nrxqsets; i++) {
2339 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2340 softc->rx_cp_rings[i].ring.phys_id =
2341 (uint16_t)HWRM_NA_SIGNATURE;
2342 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2343 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2344 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
2346 softc->vnic_info.filter_id = -1;
2347 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
2348 softc->vnic_info.rss_id = (uint16_t)HWRM_NA_SIGNATURE;
2349 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
2350 softc->vnic_info.rss_grp_tbl.idi_size);
2354 bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr)
2356 struct cmpl_base *cmp = (void *)cpr->ring.vaddr;
2359 for (i = 0; i < cpr->ring.ring_size; i++)
2360 cmp[i].info3_v = !cpr->v_bit;
2364 bnxt_handle_async_event(struct bnxt_softc *softc, struct cmpl_base *cmpl)
2366 struct hwrm_async_event_cmpl *ae = (void *)cmpl;
2367 uint16_t async_id = le16toh(ae->event_id);
2368 struct ifmediareq ifmr;
2371 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
2372 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
2373 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
2374 bnxt_media_status(softc->ctx, &ifmr);
2376 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_MTU_CHANGE:
2377 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_DCB_CONFIG_CHANGE:
2378 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
2379 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_NOT_ALLOWED:
2380 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_UNLOAD:
2381 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_LOAD:
2382 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
2383 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_LOAD:
2384 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_FLR:
2385 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_MAC_ADDR_CHANGE:
2386 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_VF_COMM_STATUS_CHANGE:
2387 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
2388 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_HWRM_ERROR:
2389 device_printf(softc->dev,
2390 "Unhandled async completion type %u\n", async_id);
2393 device_printf(softc->dev,
2394 "Unknown async completion type %u\n", async_id);
2400 bnxt_def_cp_task(void *context)
2402 if_ctx_t ctx = context;
2403 struct bnxt_softc *softc = iflib_get_softc(ctx);
2404 struct bnxt_cp_ring *cpr = &softc->def_cp_ring;
2406 /* Handle completions on the default completion ring */
2407 struct cmpl_base *cmpl;
2408 uint32_t cons = cpr->cons;
2409 bool v_bit = cpr->v_bit;
2417 NEXT_CP_CONS_V(&cpr->ring, cons, v_bit);
2418 cmpl = &((struct cmpl_base *)cpr->ring.vaddr)[cons];
2420 if (!CMP_VALID(cmpl, v_bit))
2423 type = le16toh(cmpl->type) & CMPL_BASE_TYPE_MASK;
2425 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
2426 bnxt_handle_async_event(softc, cmpl);
2428 case CMPL_BASE_TYPE_TX_L2:
2429 case CMPL_BASE_TYPE_RX_L2:
2430 case CMPL_BASE_TYPE_RX_AGG:
2431 case CMPL_BASE_TYPE_RX_TPA_START:
2432 case CMPL_BASE_TYPE_RX_TPA_END:
2433 case CMPL_BASE_TYPE_STAT_EJECT:
2434 case CMPL_BASE_TYPE_HWRM_DONE:
2435 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
2436 case CMPL_BASE_TYPE_HWRM_FWD_RESP:
2437 case CMPL_BASE_TYPE_CQ_NOTIFICATION:
2438 case CMPL_BASE_TYPE_SRQ_EVENT:
2439 case CMPL_BASE_TYPE_DBQ_EVENT:
2440 case CMPL_BASE_TYPE_QP_EVENT:
2441 case CMPL_BASE_TYPE_FUNC_EVENT:
2442 device_printf(softc->dev,
2443 "Unhandled completion type %u\n", type);
2446 device_printf(softc->dev,
2447 "Unknown completion type %u\n", type);
2452 cpr->cons = last_cons;
2453 cpr->v_bit = last_v_bit;
2454 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
2458 get_phy_type(struct bnxt_softc *softc)
2460 struct bnxt_link_info *link_info = &softc->link_info;
2461 uint8_t phy_type = link_info->phy_type;
2464 if (phy_type != HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN)
2467 /* Deduce the phy type from the media type and supported speeds */
2468 supported = link_info->support_speeds;
2470 if (link_info->media_type ==
2471 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP)
2472 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET;
2473 if (link_info->media_type ==
2474 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_DAC) {
2475 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2476 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX;
2477 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2478 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR;
2479 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR;
2481 if (link_info->media_type ==
2482 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_FIBRE)
2483 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR;
2489 bnxt_check_hwrm_version(struct bnxt_softc *softc)
2493 sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
2494 softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
2495 if (softc->ver_info->hwrm_min_major > softc->ver_info->hwrm_if_major) {
2496 device_printf(softc->dev,
2497 "WARNING: HWRM version %s is too old (older than %s)\n",
2498 softc->ver_info->hwrm_if_ver, buf);
2501 else if(softc->ver_info->hwrm_min_major ==
2502 softc->ver_info->hwrm_if_major) {
2503 if (softc->ver_info->hwrm_min_minor >
2504 softc->ver_info->hwrm_if_minor) {
2505 device_printf(softc->dev,
2506 "WARNING: HWRM version %s is too old (older than %s)\n",
2507 softc->ver_info->hwrm_if_ver, buf);
2510 else if (softc->ver_info->hwrm_min_minor ==
2511 softc->ver_info->hwrm_if_minor) {
2512 if (softc->ver_info->hwrm_min_update >
2513 softc->ver_info->hwrm_if_update) {
2514 device_printf(softc->dev,
2515 "WARNING: HWRM version %s is too old (older than %s)\n",
2516 softc->ver_info->hwrm_if_ver, buf);
2525 bnxt_get_baudrate(struct bnxt_link_info *link)
2527 switch (link->link_speed) {
2528 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2529 return IF_Mbps(100);
2530 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2532 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2534 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2535 return IF_Mbps(2500);
2536 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2538 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2540 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2542 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2544 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2546 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2547 return IF_Gbps(100);
2548 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10MB:
2551 return IF_Gbps(100);
2555 bnxt_get_wol_settings(struct bnxt_softc *softc)
2557 uint16_t wol_handle = 0;
2559 if (!bnxt_wol_supported(softc))
2563 wol_handle = bnxt_hwrm_get_wol_fltrs(softc, wol_handle);
2564 } while (wol_handle && wol_handle != BNXT_NO_MORE_WOL_FILTERS);