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 rc = bnxt_hwrm_func_rgtr_async_events(softc, NULL, 0);
696 device_printf(softc->dev, "attach: hwrm rgtr async evts failed\n");
700 /* Get the HW capabilities */
701 rc = bnxt_hwrm_func_qcaps(softc);
705 iflib_set_mac(ctx, softc->func.mac_addr);
707 scctx->isc_txrx = &bnxt_txrx;
708 scctx->isc_tx_csum_flags = (CSUM_IP | CSUM_TCP | CSUM_UDP |
709 CSUM_TCP_IPV6 | CSUM_UDP_IPV6 | CSUM_TSO);
710 scctx->isc_capenable =
711 /* These are translated to hwassit bits */
712 IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | IFCAP_TSO4 | IFCAP_TSO6 |
713 /* These are checked by iflib */
714 IFCAP_LRO | IFCAP_VLAN_HWFILTER |
715 /* These are part of the iflib mask */
716 IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_VLAN_MTU |
717 IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO |
718 /* These likely get lost... */
719 IFCAP_VLAN_HWCSUM | IFCAP_JUMBO_MTU;
721 if (bnxt_wol_supported(softc))
722 scctx->isc_capenable |= IFCAP_WOL_MAGIC;
724 /* Get the queue config */
725 rc = bnxt_hwrm_queue_qportcfg(softc);
727 device_printf(softc->dev, "attach: hwrm qportcfg failed\n");
731 bnxt_get_wol_settings(softc);
733 /* Now perform a function reset */
734 rc = bnxt_hwrm_func_reset(softc);
735 bnxt_clear_ids(softc);
739 /* Now set up iflib sc */
740 scctx->isc_tx_nsegments = 31,
741 scctx->isc_tx_tso_segments_max = 31;
742 scctx->isc_tx_tso_size_max = BNXT_TSO_SIZE;
743 scctx->isc_tx_tso_segsize_max = BNXT_TSO_SIZE;
744 scctx->isc_vectors = softc->func.max_cp_rings;
745 scctx->isc_txrx = &bnxt_txrx;
747 if (scctx->isc_nrxd[0] <
748 ((scctx->isc_nrxd[1] * 4) + scctx->isc_nrxd[2]))
749 device_printf(softc->dev,
750 "WARNING: nrxd0 (%d) should be at least 4 * nrxd1 (%d) + nrxd2 (%d). Driver may be unstable\n",
751 scctx->isc_nrxd[0], scctx->isc_nrxd[1], scctx->isc_nrxd[2]);
752 if (scctx->isc_ntxd[0] < scctx->isc_ntxd[1] * 2)
753 device_printf(softc->dev,
754 "WARNING: ntxd0 (%d) should be at least 2 * ntxd1 (%d). Driver may be unstable\n",
755 scctx->isc_ntxd[0], scctx->isc_ntxd[1]);
756 scctx->isc_txqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_ntxd[0];
757 scctx->isc_txqsizes[1] = sizeof(struct tx_bd_short) *
759 scctx->isc_rxqsizes[0] = sizeof(struct cmpl_base) * scctx->isc_nrxd[0];
760 scctx->isc_rxqsizes[1] = sizeof(struct rx_prod_pkt_bd) *
762 scctx->isc_rxqsizes[2] = sizeof(struct rx_prod_pkt_bd) *
764 scctx->isc_max_rxqsets = min(pci_msix_count(softc->dev)-1,
765 softc->func.max_cp_rings - 1);
766 scctx->isc_max_rxqsets = min(scctx->isc_max_rxqsets,
767 softc->func.max_rx_rings);
768 scctx->isc_max_txqsets = min(softc->func.max_rx_rings,
769 softc->func.max_cp_rings - scctx->isc_max_rxqsets - 1);
770 scctx->isc_rss_table_size = HW_HASH_INDEX_SIZE;
771 scctx->isc_rss_table_mask = scctx->isc_rss_table_size - 1;
773 /* iflib will map and release this bar */
774 scctx->isc_msix_bar = pci_msix_table_bar(softc->dev);
776 /* Allocate the default completion ring */
777 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
778 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
779 softc->def_cp_ring.ring.softc = softc;
780 softc->def_cp_ring.ring.id = 0;
781 softc->def_cp_ring.ring.doorbell = softc->def_cp_ring.ring.id * 0x80;
782 softc->def_cp_ring.ring.ring_size = PAGE_SIZE /
783 sizeof(struct cmpl_base);
784 rc = iflib_dma_alloc(ctx,
785 sizeof(struct cmpl_base) * softc->def_cp_ring.ring.ring_size,
786 &softc->def_cp_ring_mem, 0);
787 softc->def_cp_ring.ring.vaddr = softc->def_cp_ring_mem.idi_vaddr;
788 softc->def_cp_ring.ring.paddr = softc->def_cp_ring_mem.idi_paddr;
789 iflib_config_gtask_init(ctx, &softc->def_cp_task, bnxt_def_cp_task,
792 rc = bnxt_init_sysctl_ctx(softc);
794 goto init_sysctl_failed;
795 rc = bnxt_create_nvram_sysctls(softc->nvm_info);
799 arc4rand(softc->vnic_info.rss_hash_key, HW_HASH_KEY_SIZE, 0);
800 softc->vnic_info.rss_hash_type =
801 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4 |
802 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4 |
803 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4 |
804 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6 |
805 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6 |
806 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
807 rc = bnxt_create_config_sysctls_pre(softc);
811 /* Initialize the vlan list */
812 SLIST_INIT(&softc->vnic_info.vlan_tags);
813 softc->vnic_info.vlan_tag_list.idi_vaddr = NULL;
818 bnxt_free_sysctl_ctx(softc);
820 bnxt_hwrm_func_drv_unrgtr(softc, false);
822 free(softc->nvm_info, M_DEVBUF);
825 free(softc->ver_info, M_DEVBUF);
827 bnxt_free_hwrm_dma_mem(softc);
829 BNXT_HWRM_LOCK_DESTROY(softc);
830 bnxt_pci_mapping_free(softc);
831 pci_disable_busmaster(softc->dev);
836 bnxt_attach_post(if_ctx_t ctx)
838 struct bnxt_softc *softc = iflib_get_softc(ctx);
839 if_t ifp = iflib_get_ifp(ctx);
842 bnxt_create_config_sysctls_post(softc);
844 /* Update link state etc... */
845 rc = bnxt_probe_phy(softc);
849 /* Needs to be done after probing the phy */
850 bnxt_create_ver_sysctls(softc);
851 bnxt_add_media_types(softc);
852 ifmedia_set(softc->media, IFM_ETHER | IFM_AUTO);
854 softc->scctx->isc_max_frame_size = ifp->if_mtu + ETHER_HDR_LEN +
862 bnxt_detach(if_ctx_t ctx)
864 struct bnxt_softc *softc = iflib_get_softc(ctx);
865 struct bnxt_vlan_tag *tag;
866 struct bnxt_vlan_tag *tmp;
869 bnxt_wol_config(ctx);
870 bnxt_do_disable_intr(&softc->def_cp_ring);
871 bnxt_free_sysctl_ctx(softc);
872 bnxt_hwrm_func_reset(softc);
873 bnxt_clear_ids(softc);
874 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
875 iflib_config_gtask_deinit(&softc->def_cp_task);
876 /* We need to free() these here... */
877 for (i = softc->nrxqsets-1; i>=0; i--) {
878 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
880 iflib_dma_free(&softc->vnic_info.mc_list);
881 iflib_dma_free(&softc->vnic_info.rss_hash_key_tbl);
882 iflib_dma_free(&softc->vnic_info.rss_grp_tbl);
883 if (softc->vnic_info.vlan_tag_list.idi_vaddr)
884 iflib_dma_free(&softc->vnic_info.vlan_tag_list);
885 SLIST_FOREACH_SAFE(tag, &softc->vnic_info.vlan_tags, next, tmp)
887 iflib_dma_free(&softc->def_cp_ring_mem);
888 for (i = 0; i < softc->nrxqsets; i++)
889 free(softc->rx_rings[i].tpa_start, M_DEVBUF);
890 free(softc->ver_info, M_DEVBUF);
891 free(softc->nvm_info, M_DEVBUF);
893 bnxt_hwrm_func_drv_unrgtr(softc, false);
894 bnxt_free_hwrm_dma_mem(softc);
895 BNXT_HWRM_LOCK_DESTROY(softc);
897 pci_disable_busmaster(softc->dev);
898 bnxt_pci_mapping_free(softc);
903 /* Device configuration */
905 bnxt_init(if_ctx_t ctx)
907 struct bnxt_softc *softc = iflib_get_softc(ctx);
908 struct ifmediareq ifmr;
912 rc = bnxt_hwrm_func_reset(softc);
915 bnxt_clear_ids(softc);
917 /* Allocate the default completion ring */
918 softc->def_cp_ring.cons = UINT32_MAX;
919 softc->def_cp_ring.v_bit = 1;
920 bnxt_mark_cpr_invalid(&softc->def_cp_ring);
921 rc = bnxt_hwrm_ring_alloc(softc,
922 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
923 &softc->def_cp_ring.ring,
924 (uint16_t)HWRM_NA_SIGNATURE,
925 HWRM_NA_SIGNATURE, true);
929 /* And now set the default CP ring as the async CP ring */
930 rc = bnxt_hwrm_func_cfg(softc);
934 for (i = 0; i < softc->nrxqsets; i++) {
935 /* Allocate the statistics context */
936 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->rx_cp_rings[i],
937 softc->rx_stats.idi_paddr +
938 (sizeof(struct ctx_hw_stats) * i));
942 /* Allocate the completion ring */
943 softc->rx_cp_rings[i].cons = UINT32_MAX;
944 softc->rx_cp_rings[i].v_bit = 1;
945 softc->rx_cp_rings[i].last_idx = UINT32_MAX;
946 bnxt_mark_cpr_invalid(&softc->rx_cp_rings[i]);
947 rc = bnxt_hwrm_ring_alloc(softc,
948 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
949 &softc->rx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
950 HWRM_NA_SIGNATURE, true);
954 /* Allocate the RX ring */
955 rc = bnxt_hwrm_ring_alloc(softc,
956 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
957 &softc->rx_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
958 HWRM_NA_SIGNATURE, false);
961 BNXT_RX_DB(&softc->rx_rings[i], 0);
962 /* TODO: Cumulus+ doesn't need the double doorbell */
963 BNXT_RX_DB(&softc->rx_rings[i], 0);
965 /* Allocate the AG ring */
966 rc = bnxt_hwrm_ring_alloc(softc,
967 HWRM_RING_ALLOC_INPUT_RING_TYPE_RX,
968 &softc->ag_rings[i], (uint16_t)HWRM_NA_SIGNATURE,
969 HWRM_NA_SIGNATURE, false);
972 BNXT_RX_DB(&softc->rx_rings[i], 0);
973 /* TODO: Cumulus+ doesn't need the double doorbell */
974 BNXT_RX_DB(&softc->ag_rings[i], 0);
976 /* Allocate the ring group */
977 softc->grp_info[i].stats_ctx =
978 softc->rx_cp_rings[i].stats_ctx_id;
979 softc->grp_info[i].rx_ring_id = softc->rx_rings[i].phys_id;
980 softc->grp_info[i].ag_ring_id = softc->ag_rings[i].phys_id;
981 softc->grp_info[i].cp_ring_id =
982 softc->rx_cp_rings[i].ring.phys_id;
983 rc = bnxt_hwrm_ring_grp_alloc(softc, &softc->grp_info[i]);
989 /* Allocate the VNIC RSS context */
990 rc = bnxt_hwrm_vnic_ctx_alloc(softc, &softc->vnic_info.rss_id);
994 /* Allocate the vnic */
995 softc->vnic_info.def_ring_grp = softc->grp_info[0].grp_id;
996 softc->vnic_info.mru = softc->scctx->isc_max_frame_size;
997 rc = bnxt_hwrm_vnic_alloc(softc, &softc->vnic_info);
1000 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1003 rc = bnxt_hwrm_set_filter(softc, &softc->vnic_info);
1007 /* Enable RSS on the VNICs */
1008 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
1010 softc->vnic_info.rss_grp_tbl.idi_vaddr)[i] =
1011 htole16(softc->grp_info[j].grp_id);
1012 if (++j == softc->nrxqsets)
1016 rc = bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1017 softc->vnic_info.rss_hash_type);
1022 * Enable LRO/TPA/GRO
1024 * Enable / Disable HW_LRO based on
1025 * ifconfig lro / ifconfig -lro setting
1027 rc = bnxt_hwrm_vnic_tpa_cfg(softc, &softc->vnic_info,
1028 (if_getcapenable(iflib_get_ifp(ctx)) & IFCAP_LRO) ?
1029 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA : 0);
1033 for (i = 0; i < softc->ntxqsets; i++) {
1034 /* Allocate the statistics context */
1035 rc = bnxt_hwrm_stat_ctx_alloc(softc, &softc->tx_cp_rings[i],
1036 softc->tx_stats.idi_paddr +
1037 (sizeof(struct ctx_hw_stats) * i));
1041 /* Allocate the completion ring */
1042 softc->tx_cp_rings[i].cons = UINT32_MAX;
1043 softc->tx_cp_rings[i].v_bit = 1;
1044 bnxt_mark_cpr_invalid(&softc->tx_cp_rings[i]);
1045 rc = bnxt_hwrm_ring_alloc(softc,
1046 HWRM_RING_ALLOC_INPUT_RING_TYPE_CMPL,
1047 &softc->tx_cp_rings[i].ring, (uint16_t)HWRM_NA_SIGNATURE,
1048 HWRM_NA_SIGNATURE, false);
1052 /* Allocate the TX ring */
1053 rc = bnxt_hwrm_ring_alloc(softc,
1054 HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
1055 &softc->tx_rings[i], softc->tx_cp_rings[i].ring.phys_id,
1056 softc->tx_cp_rings[i].stats_ctx_id, false);
1059 BNXT_TX_DB(&softc->tx_rings[i], 0);
1060 /* TODO: Cumulus+ doesn't need the double doorbell */
1061 BNXT_TX_DB(&softc->tx_rings[i], 0);
1064 bnxt_do_enable_intr(&softc->def_cp_ring);
1065 bnxt_media_status(softc->ctx, &ifmr);
1069 bnxt_hwrm_func_reset(softc);
1070 bnxt_clear_ids(softc);
1075 bnxt_stop(if_ctx_t ctx)
1077 struct bnxt_softc *softc = iflib_get_softc(ctx);
1079 bnxt_do_disable_intr(&softc->def_cp_ring);
1080 bnxt_hwrm_func_reset(softc);
1081 bnxt_clear_ids(softc);
1086 bnxt_multi_set(if_ctx_t ctx)
1088 struct bnxt_softc *softc = iflib_get_softc(ctx);
1089 if_t ifp = iflib_get_ifp(ctx);
1093 mcnt = if_multiaddr_count(ifp, -1);
1095 if (mcnt > BNXT_MAX_MC_ADDRS) {
1096 softc->vnic_info.rx_mask |=
1097 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1098 bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1101 softc->vnic_info.rx_mask &=
1102 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1103 mta = softc->vnic_info.mc_list.idi_vaddr;
1104 bzero(mta, softc->vnic_info.mc_list.idi_size);
1105 if_multiaddr_array(ifp, mta, &cnt, mcnt);
1106 bus_dmamap_sync(softc->vnic_info.mc_list.idi_tag,
1107 softc->vnic_info.mc_list.idi_map, BUS_DMASYNC_PREWRITE);
1108 softc->vnic_info.mc_list_count = cnt;
1109 softc->vnic_info.rx_mask |=
1110 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
1111 if (bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info))
1112 device_printf(softc->dev,
1113 "set_multi: rx_mask set failed\n");
1118 bnxt_mtu_set(if_ctx_t ctx, uint32_t mtu)
1120 struct bnxt_softc *softc = iflib_get_softc(ctx);
1122 if (mtu > BNXT_MAX_MTU)
1125 softc->scctx->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1130 bnxt_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
1132 struct bnxt_softc *softc = iflib_get_softc(ctx);
1133 struct bnxt_link_info *link_info = &softc->link_info;
1134 uint8_t phy_type = get_phy_type(softc);
1136 bnxt_update_link(softc, true);
1138 ifmr->ifm_status = IFM_AVALID;
1139 ifmr->ifm_active = IFM_ETHER;
1141 if (link_info->link_up)
1142 ifmr->ifm_status |= IFM_ACTIVE;
1144 ifmr->ifm_status &= ~IFM_ACTIVE;
1146 if (link_info->duplex == HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
1147 ifmr->ifm_active |= IFM_FDX;
1149 ifmr->ifm_active |= IFM_HDX;
1151 switch (link_info->link_speed) {
1152 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1153 ifmr->ifm_active |= IFM_100_T;
1155 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1157 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1158 ifmr->ifm_active |= IFM_1000_KX;
1160 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1161 ifmr->ifm_active |= IFM_1000_T;
1163 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
1164 ifmr->ifm_active |= IFM_1000_SGMII;
1169 * Don't return IFM_UNKNOWN until
1170 * Stratus return proper media_type
1172 ifmr->ifm_active |= IFM_1000_KX;
1176 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1178 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1179 ifmr->ifm_active |= IFM_2500_KX;
1181 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1182 ifmr->ifm_active |= IFM_2500_T;
1185 ifmr->ifm_active |= IFM_UNKNOWN;
1189 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1191 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1192 ifmr->ifm_active |= IFM_10G_CR1;
1194 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1195 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1196 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1197 ifmr->ifm_active |= IFM_10G_KR;
1199 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1200 ifmr->ifm_active |= IFM_10G_LR;
1202 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1203 ifmr->ifm_active |= IFM_10G_SR;
1205 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
1206 ifmr->ifm_active |= IFM_10G_KX4;
1208 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
1209 ifmr->ifm_active |= IFM_10G_T;
1214 * Don't return IFM_UNKNOWN until
1215 * Stratus return proper media_type
1217 ifmr->ifm_active |= IFM_10G_CR1;
1221 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1222 ifmr->ifm_active |= IFM_20G_KR2;
1224 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1226 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1227 ifmr->ifm_active |= IFM_25G_CR;
1229 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1230 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1231 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1232 ifmr->ifm_active |= IFM_25G_KR;
1234 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1235 ifmr->ifm_active |= IFM_25G_SR;
1240 * Don't return IFM_UNKNOWN until
1241 * Stratus return proper media_type
1243 ifmr->ifm_active |= IFM_25G_CR;
1247 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1249 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1250 ifmr->ifm_active |= IFM_40G_CR4;
1252 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1253 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1254 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1255 ifmr->ifm_active |= IFM_40G_KR4;
1257 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1258 ifmr->ifm_active |= IFM_40G_LR4;
1260 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1261 ifmr->ifm_active |= IFM_40G_SR4;
1264 ifmr->ifm_active |= IFM_UNKNOWN;
1268 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1270 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1271 ifmr->ifm_active |= IFM_50G_CR2;
1273 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1274 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1275 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1276 ifmr->ifm_active |= IFM_50G_KR2;
1281 * Don't return IFM_UNKNOWN until
1282 * Stratus return proper media_type
1284 ifmr->ifm_active |= IFM_50G_CR2;
1288 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
1290 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
1291 ifmr->ifm_active |= IFM_100G_CR4;
1293 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
1294 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
1295 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
1296 ifmr->ifm_active |= IFM_100G_KR4;
1298 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
1299 ifmr->ifm_active |= IFM_100G_LR4;
1301 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
1302 ifmr->ifm_active |= IFM_100G_SR4;
1307 * Don't return IFM_UNKNOWN until
1308 * Stratus return proper media_type
1310 ifmr->ifm_active |= IFM_100G_CR4;
1317 if (link_info->pause == (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1318 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
1319 ifmr->ifm_active |= (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
1320 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
1321 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
1322 else if (link_info->pause == HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
1323 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
1325 bnxt_report_link(softc);
1330 bnxt_media_change(if_ctx_t ctx)
1332 struct bnxt_softc *softc = iflib_get_softc(ctx);
1333 struct ifmedia *ifm = iflib_get_media(ctx);
1334 struct ifmediareq ifmr;
1337 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1340 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1342 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1343 softc->link_info.req_link_speed =
1344 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
1348 case IFM_1000_SGMII:
1349 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1350 softc->link_info.req_link_speed =
1351 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
1355 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1356 softc->link_info.req_link_speed =
1357 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
1364 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1365 softc->link_info.req_link_speed =
1366 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1369 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1370 softc->link_info.req_link_speed =
1371 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
1376 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1377 softc->link_info.req_link_speed =
1378 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
1384 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1385 softc->link_info.req_link_speed =
1386 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1390 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1391 softc->link_info.req_link_speed =
1392 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1398 softc->link_info.autoneg &= ~BNXT_AUTONEG_SPEED;
1399 softc->link_info.req_link_speed =
1400 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
1403 device_printf(softc->dev,
1404 "Unsupported media type! Using auto\n");
1408 softc->link_info.autoneg |= BNXT_AUTONEG_SPEED;
1411 rc = bnxt_hwrm_set_link_setting(softc, true, true);
1412 bnxt_media_status(softc->ctx, &ifmr);
1417 bnxt_promisc_set(if_ctx_t ctx, int flags)
1419 struct bnxt_softc *softc = iflib_get_softc(ctx);
1420 if_t ifp = iflib_get_ifp(ctx);
1423 if (ifp->if_flags & IFF_ALLMULTI ||
1424 if_multiaddr_count(ifp, -1) > BNXT_MAX_MC_ADDRS)
1425 softc->vnic_info.rx_mask |=
1426 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1428 softc->vnic_info.rx_mask &=
1429 ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
1431 if (ifp->if_flags & IFF_PROMISC)
1432 softc->vnic_info.rx_mask |=
1433 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1434 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN;
1436 softc->vnic_info.rx_mask &=
1437 ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS |
1438 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
1440 rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);
1446 bnxt_get_counter(if_ctx_t ctx, ift_counter cnt)
1448 if_t ifp = iflib_get_ifp(ctx);
1450 if (cnt < IFCOUNTERS)
1451 return if_get_counter_default(ifp, cnt);
1457 bnxt_update_admin_status(if_ctx_t ctx)
1459 /* TODO: do we need to do anything here? */
1464 bnxt_do_enable_intr(struct bnxt_cp_ring *cpr)
1466 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE) {
1467 /* First time enabling, do not set index */
1468 if (cpr->cons == UINT32_MAX)
1469 BNXT_CP_ENABLE_DB(&cpr->ring);
1471 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
1476 bnxt_do_disable_intr(struct bnxt_cp_ring *cpr)
1478 if (cpr->ring.phys_id != (uint16_t)HWRM_NA_SIGNATURE)
1479 BNXT_CP_DISABLE_DB(&cpr->ring);
1482 /* Enable all interrupts */
1484 bnxt_intr_enable(if_ctx_t ctx)
1486 struct bnxt_softc *softc = iflib_get_softc(ctx);
1489 bnxt_do_enable_intr(&softc->def_cp_ring);
1490 for (i = 0; i < softc->nrxqsets; i++)
1491 bnxt_do_enable_intr(&softc->rx_cp_rings[i]);
1496 /* Enable interrupt for a single queue */
1498 bnxt_tx_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1500 struct bnxt_softc *softc = iflib_get_softc(ctx);
1502 bnxt_do_enable_intr(&softc->tx_cp_rings[qid]);
1507 bnxt_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid)
1509 struct bnxt_softc *softc = iflib_get_softc(ctx);
1511 bnxt_do_enable_intr(&softc->rx_cp_rings[qid]);
1515 /* Disable all interrupts */
1517 bnxt_disable_intr(if_ctx_t ctx)
1519 struct bnxt_softc *softc = iflib_get_softc(ctx);
1523 * NOTE: These TX interrupts should never get enabled, so don't
1526 for (i = 0; i < softc->ntxqsets; i++)
1527 bnxt_do_disable_intr(&softc->tx_cp_rings[i]);
1528 for (i = 0; i < softc->nrxqsets; i++)
1529 bnxt_do_disable_intr(&softc->rx_cp_rings[i]);
1535 bnxt_msix_intr_assign(if_ctx_t ctx, int msix)
1537 struct bnxt_softc *softc = iflib_get_softc(ctx);
1542 rc = iflib_irq_alloc_generic(ctx, &softc->def_cp_ring.irq,
1543 softc->def_cp_ring.ring.id + 1, IFLIB_INTR_ADMIN,
1544 bnxt_handle_def_cp, softc, 0, "def_cp");
1546 device_printf(iflib_get_dev(ctx),
1547 "Failed to register default completion ring handler\n");
1551 for (i=0; i<softc->scctx->isc_nrxqsets; i++) {
1552 snprintf(irq_name, sizeof(irq_name), "rxq%d", i);
1553 rc = iflib_irq_alloc_generic(ctx, &softc->rx_cp_rings[i].irq,
1554 softc->rx_cp_rings[i].ring.id + 1, IFLIB_INTR_RX,
1555 bnxt_handle_rx_cp, &softc->rx_cp_rings[i], i, irq_name);
1557 device_printf(iflib_get_dev(ctx),
1558 "Failed to register RX completion ring handler\n");
1564 for (i=0; i<softc->scctx->isc_ntxqsets; i++)
1565 iflib_softirq_alloc_generic(ctx, i + 1, IFLIB_INTR_TX, NULL, i,
1572 iflib_irq_free(ctx, &softc->rx_cp_rings[i].irq);
1573 iflib_irq_free(ctx, &softc->def_cp_ring.irq);
1578 * We're explicitly allowing duplicates here. They will need to be
1579 * removed as many times as they are added.
1582 bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag)
1584 struct bnxt_softc *softc = iflib_get_softc(ctx);
1585 struct bnxt_vlan_tag *new_tag;
1587 new_tag = malloc(sizeof(struct bnxt_vlan_tag), M_DEVBUF, M_NOWAIT);
1588 if (new_tag == NULL)
1590 new_tag->tag = vtag;
1591 new_tag->tpid = 8100;
1592 SLIST_INSERT_HEAD(&softc->vnic_info.vlan_tags, new_tag, next);
1596 bnxt_vlan_unregister(if_ctx_t ctx, uint16_t vtag)
1598 struct bnxt_softc *softc = iflib_get_softc(ctx);
1599 struct bnxt_vlan_tag *vlan_tag;
1601 SLIST_FOREACH(vlan_tag, &softc->vnic_info.vlan_tags, next) {
1602 if (vlan_tag->tag == vtag) {
1603 SLIST_REMOVE(&softc->vnic_info.vlan_tags, vlan_tag,
1604 bnxt_vlan_tag, next);
1605 free(vlan_tag, M_DEVBUF);
1612 bnxt_wol_config(if_ctx_t ctx)
1614 struct bnxt_softc *softc = iflib_get_softc(ctx);
1615 if_t ifp = iflib_get_ifp(ctx);
1620 if (!bnxt_wol_supported(softc))
1623 if (if_getcapabilities(ifp) & IFCAP_WOL_MAGIC) {
1625 if (bnxt_hwrm_alloc_wol_fltr(softc))
1631 if (bnxt_hwrm_free_wol_fltr(softc))
1641 bnxt_shutdown(if_ctx_t ctx)
1643 bnxt_wol_config(ctx);
1648 bnxt_suspend(if_ctx_t ctx)
1650 bnxt_wol_config(ctx);
1655 bnxt_resume(if_ctx_t ctx)
1657 struct bnxt_softc *softc = iflib_get_softc(ctx);
1659 bnxt_get_wol_settings(softc);
1664 bnxt_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data)
1666 struct bnxt_softc *softc = iflib_get_softc(ctx);
1667 struct ifreq *ifr = (struct ifreq *)data;
1668 struct ifreq_buffer *ifbuf = &ifr->ifr_ifru.ifru_buffer;
1669 struct bnxt_ioctl_header *ioh =
1670 (struct bnxt_ioctl_header *)(ifbuf->buffer);
1672 struct bnxt_ioctl_data *iod = NULL;
1675 case SIOCGPRIVATE_0:
1676 if ((rc = priv_check(curthread, PRIV_DRIVER)) != 0)
1679 iod = malloc(ifbuf->length, M_DEVBUF, M_NOWAIT | M_ZERO);
1684 copyin(ioh, iod, ifbuf->length);
1686 switch (ioh->type) {
1687 case BNXT_HWRM_NVM_FIND_DIR_ENTRY:
1689 struct bnxt_ioctl_hwrm_nvm_find_dir_entry *find =
1692 rc = bnxt_hwrm_nvm_find_dir_entry(softc, find->type,
1693 &find->ordinal, find->ext, &find->index,
1694 find->use_index, find->search_opt,
1695 &find->data_length, &find->item_length,
1699 copyout(&iod->hdr.rc, &ioh->rc,
1704 copyout(iod, ioh, ifbuf->length);
1710 case BNXT_HWRM_NVM_READ:
1712 struct bnxt_ioctl_hwrm_nvm_read *rd = &iod->read;
1713 struct iflib_dma_info dma_data;
1719 * Some HWRM versions can't read more than 0x8000 bytes
1721 rc = iflib_dma_alloc(softc->ctx,
1722 min(rd->length, 0x8000), &dma_data, BUS_DMA_NOWAIT);
1725 for (remain = rd->length, offset = 0;
1726 remain && offset < rd->length; offset += 0x8000) {
1727 csize = min(remain, 0x8000);
1728 rc = bnxt_hwrm_nvm_read(softc, rd->index,
1729 rd->offset + offset, csize, &dma_data);
1732 copyout(&iod->hdr.rc, &ioh->rc,
1737 copyout(dma_data.idi_vaddr,
1738 rd->data + offset, csize);
1743 if (iod->hdr.rc == 0)
1744 copyout(iod, ioh, ifbuf->length);
1746 iflib_dma_free(&dma_data);
1750 case BNXT_HWRM_FW_RESET:
1752 struct bnxt_ioctl_hwrm_fw_reset *rst =
1755 rc = bnxt_hwrm_fw_reset(softc, rst->processor,
1759 copyout(&iod->hdr.rc, &ioh->rc,
1764 copyout(iod, ioh, ifbuf->length);
1770 case BNXT_HWRM_FW_QSTATUS:
1772 struct bnxt_ioctl_hwrm_fw_qstatus *qstat =
1775 rc = bnxt_hwrm_fw_qstatus(softc, qstat->processor,
1779 copyout(&iod->hdr.rc, &ioh->rc,
1784 copyout(iod, ioh, ifbuf->length);
1790 case BNXT_HWRM_NVM_WRITE:
1792 struct bnxt_ioctl_hwrm_nvm_write *wr =
1795 rc = bnxt_hwrm_nvm_write(softc, wr->data, true,
1796 wr->type, wr->ordinal, wr->ext, wr->attr,
1797 wr->option, wr->data_length, wr->keep,
1798 &wr->item_length, &wr->index);
1801 copyout(&iod->hdr.rc, &ioh->rc,
1806 copyout(iod, ioh, ifbuf->length);
1812 case BNXT_HWRM_NVM_ERASE_DIR_ENTRY:
1814 struct bnxt_ioctl_hwrm_nvm_erase_dir_entry *erase =
1817 rc = bnxt_hwrm_nvm_erase_dir_entry(softc, erase->index);
1820 copyout(&iod->hdr.rc, &ioh->rc,
1825 copyout(iod, ioh, ifbuf->length);
1831 case BNXT_HWRM_NVM_GET_DIR_INFO:
1833 struct bnxt_ioctl_hwrm_nvm_get_dir_info *info =
1836 rc = bnxt_hwrm_nvm_get_dir_info(softc, &info->entries,
1837 &info->entry_length);
1840 copyout(&iod->hdr.rc, &ioh->rc,
1845 copyout(iod, ioh, ifbuf->length);
1851 case BNXT_HWRM_NVM_GET_DIR_ENTRIES:
1853 struct bnxt_ioctl_hwrm_nvm_get_dir_entries *get =
1855 struct iflib_dma_info dma_data;
1857 rc = iflib_dma_alloc(softc->ctx, get->max_size,
1858 &dma_data, BUS_DMA_NOWAIT);
1861 rc = bnxt_hwrm_nvm_get_dir_entries(softc, &get->entries,
1862 &get->entry_length, &dma_data);
1865 copyout(&iod->hdr.rc, &ioh->rc,
1869 copyout(dma_data.idi_vaddr, get->data,
1870 get->entry_length * get->entries);
1872 copyout(iod, ioh, ifbuf->length);
1874 iflib_dma_free(&dma_data);
1879 case BNXT_HWRM_NVM_VERIFY_UPDATE:
1881 struct bnxt_ioctl_hwrm_nvm_verify_update *vrfy =
1884 rc = bnxt_hwrm_nvm_verify_update(softc, vrfy->type,
1885 vrfy->ordinal, vrfy->ext);
1888 copyout(&iod->hdr.rc, &ioh->rc,
1893 copyout(iod, ioh, ifbuf->length);
1899 case BNXT_HWRM_NVM_INSTALL_UPDATE:
1901 struct bnxt_ioctl_hwrm_nvm_install_update *inst =
1904 rc = bnxt_hwrm_nvm_install_update(softc,
1905 inst->install_type, &inst->installed_items,
1906 &inst->result, &inst->problem_item,
1907 &inst->reset_required);
1910 copyout(&iod->hdr.rc, &ioh->rc,
1915 copyout(iod, ioh, ifbuf->length);
1921 case BNXT_HWRM_NVM_MODIFY:
1923 struct bnxt_ioctl_hwrm_nvm_modify *mod = &iod->modify;
1925 rc = bnxt_hwrm_nvm_modify(softc, mod->index,
1926 mod->offset, mod->data, true, mod->length);
1929 copyout(&iod->hdr.rc, &ioh->rc,
1934 copyout(iod, ioh, ifbuf->length);
1940 case BNXT_HWRM_FW_GET_TIME:
1942 struct bnxt_ioctl_hwrm_fw_get_time *gtm =
1945 rc = bnxt_hwrm_fw_get_time(softc, >m->year,
1946 >m->month, >m->day, >m->hour, >m->minute,
1947 >m->second, >m->millisecond, >m->zone);
1950 copyout(&iod->hdr.rc, &ioh->rc,
1955 copyout(iod, ioh, ifbuf->length);
1961 case BNXT_HWRM_FW_SET_TIME:
1963 struct bnxt_ioctl_hwrm_fw_set_time *stm =
1966 rc = bnxt_hwrm_fw_set_time(softc, stm->year,
1967 stm->month, stm->day, stm->hour, stm->minute,
1968 stm->second, stm->millisecond, stm->zone);
1971 copyout(&iod->hdr.rc, &ioh->rc,
1976 copyout(iod, ioh, ifbuf->length);
1988 free(iod, M_DEVBUF);
1996 bnxt_probe_phy(struct bnxt_softc *softc)
1998 struct bnxt_link_info *link_info = &softc->link_info;
2001 rc = bnxt_update_link(softc, false);
2003 device_printf(softc->dev,
2004 "Probe phy can't update link (rc: %x)\n", rc);
2008 /*initialize the ethool setting copy with NVM settings */
2009 if (link_info->auto_mode != HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
2010 link_info->autoneg |= BNXT_AUTONEG_SPEED;
2012 if (link_info->auto_pause & (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2013 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
2014 if (link_info->auto_pause == (
2015 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2016 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2017 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
2018 link_info->req_flow_ctrl = link_info->auto_pause;
2019 } else if (link_info->force_pause & (
2020 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2021 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)) {
2022 link_info->req_flow_ctrl = link_info->force_pause;
2024 link_info->req_duplex = link_info->duplex_setting;
2025 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
2026 link_info->req_link_speed = link_info->auto_link_speed;
2028 link_info->req_link_speed = link_info->force_link_speed;
2033 bnxt_add_media_types(struct bnxt_softc *softc)
2035 struct bnxt_link_info *link_info = &softc->link_info;
2037 uint8_t phy_type = get_phy_type(softc);
2039 supported = link_info->support_speeds;
2041 /* Auto is always supported */
2042 ifmedia_add(softc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2044 if (softc->flags & BNXT_FLAG_NPAR)
2048 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR:
2049 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2050 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0,
2052 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
2053 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0,
2055 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2056 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_CR4, 0,
2058 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2059 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0,
2061 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2062 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0,
2065 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR4:
2066 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR2:
2067 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR:
2068 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2069 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_KR4, 0,
2071 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
2072 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_KR2, 0,
2074 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2075 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_KR4, 0,
2077 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2078 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_KR, 0,
2080 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2081 ifmedia_add(softc->media, IFM_ETHER | IFM_20G_KR2, 0,
2083 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2084 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KR, 0,
2087 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASELR:
2088 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2089 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_LR4, 0,
2091 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2092 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_LR4, 0,
2094 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2095 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_LR, 0,
2098 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR:
2099 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
2100 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_SR4, 0,
2102 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
2103 ifmedia_add(softc->media, IFM_ETHER | IFM_40G_SR4, 0,
2105 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
2106 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_SR, 0,
2108 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2109 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_SR, 0,
2112 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX:
2113 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2114 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_KX4, 0,
2116 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2117 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_KX, 0,
2119 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2120 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_KX, 0,
2123 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET:
2124 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE:
2125 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10MB)
2126 ifmedia_add(softc->media, IFM_ETHER | IFM_10_T, 0,
2128 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MB)
2129 ifmedia_add(softc->media, IFM_ETHER | IFM_100_T, 0,
2131 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2132 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0,
2134 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2135 ifmedia_add(softc->media, IFM_ETHER | IFM_2500_T, 0,
2137 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
2138 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_T, 0,
2141 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_SGMIIEXTPHY:
2142 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
2143 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_SGMII, 0,
2146 case HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN:
2149 * Workaround for Cumulus & Stratus
2151 * media_type is being returned as 0x0
2152 * Return support speeds as 10G, 25G, 50G & 100G
2155 * phy_type is being returned as 0x14 (PHY_TYPE_40G_BASECR4)
2156 * Return support speeds as 1G, 10G, 25G & 50G
2158 if (pci_get_device(softc->dev) == BCM57454) {
2159 /* For Stratus: 10G, 25G, 50G & 100G */
2160 ifmedia_add(softc->media, IFM_ETHER | IFM_100G_CR4, 0, NULL);
2161 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0, NULL);
2162 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0, NULL);
2163 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0, NULL);
2164 } else if (pci_get_device(softc->dev) == BCM57414) {
2165 /* For Cumulus: 1G, 10G, 25G & 50G */
2166 ifmedia_add(softc->media, IFM_ETHER | IFM_50G_CR2, 0, NULL);
2167 ifmedia_add(softc->media, IFM_ETHER | IFM_25G_CR, 0, NULL);
2168 ifmedia_add(softc->media, IFM_ETHER | IFM_10G_CR1, 0, NULL);
2169 ifmedia_add(softc->media, IFM_ETHER | IFM_1000_T, 0, NULL);
2178 bnxt_map_bar(struct bnxt_softc *softc, struct bnxt_bar_info *bar, int bar_num, bool shareable)
2182 if (bar->res != NULL) {
2183 device_printf(softc->dev, "Bar %d already mapped\n", bar_num);
2187 bar->rid = PCIR_BAR(bar_num);
2190 flag |= RF_SHAREABLE;
2193 bus_alloc_resource_any(softc->dev,
2197 device_printf(softc->dev,
2198 "PCI BAR%d mapping failure\n", bar_num);
2201 bar->tag = rman_get_bustag(bar->res);
2202 bar->handle = rman_get_bushandle(bar->res);
2203 bar->size = rman_get_size(bar->res);
2209 bnxt_pci_mapping(struct bnxt_softc *softc)
2213 rc = bnxt_map_bar(softc, &softc->hwrm_bar, 0, true);
2217 rc = bnxt_map_bar(softc, &softc->doorbell_bar, 2, false);
2223 bnxt_pci_mapping_free(struct bnxt_softc *softc)
2225 if (softc->hwrm_bar.res != NULL)
2226 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2227 softc->hwrm_bar.rid, softc->hwrm_bar.res);
2228 softc->hwrm_bar.res = NULL;
2230 if (softc->doorbell_bar.res != NULL)
2231 bus_release_resource(softc->dev, SYS_RES_MEMORY,
2232 softc->doorbell_bar.rid, softc->doorbell_bar.res);
2233 softc->doorbell_bar.res = NULL;
2237 bnxt_update_link(struct bnxt_softc *softc, bool chng_link_state)
2239 struct bnxt_link_info *link_info = &softc->link_info;
2240 uint8_t link_up = link_info->link_up;
2243 rc = bnxt_hwrm_port_phy_qcfg(softc);
2247 /* TODO: need to add more logic to report VF link */
2248 if (chng_link_state) {
2249 if (link_info->phy_link_status ==
2250 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK)
2251 link_info->link_up = 1;
2253 link_info->link_up = 0;
2254 if (link_up != link_info->link_up)
2255 bnxt_report_link(softc);
2257 /* always link down if not require to update link state */
2258 link_info->link_up = 0;
2266 bnxt_report_link(struct bnxt_softc *softc)
2268 const char *duplex = NULL, *flow_ctrl = NULL;
2270 if (softc->link_info.link_up == softc->link_info.last_link_up) {
2271 if (!softc->link_info.link_up)
2273 if (softc->link_info.pause == softc->link_info.last_pause &&
2274 softc->link_info.duplex == softc->link_info.last_duplex)
2278 if (softc->link_info.link_up) {
2279 if (softc->link_info.duplex ==
2280 HWRM_PORT_PHY_QCFG_OUTPUT_DUPLEX_FULL)
2281 duplex = "full duplex";
2283 duplex = "half duplex";
2284 if (softc->link_info.pause == (
2285 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2286 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX))
2287 flow_ctrl = "FC - receive & transmit";
2288 else if (softc->link_info.pause ==
2289 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX)
2290 flow_ctrl = "FC - transmit";
2291 else if (softc->link_info.pause ==
2292 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX)
2293 flow_ctrl = "FC - receive";
2295 flow_ctrl = "FC - none";
2296 iflib_link_state_change(softc->ctx, LINK_STATE_UP,
2298 device_printf(softc->dev, "Link is UP %s, %s - %d Mbps \n", duplex,
2299 flow_ctrl, (softc->link_info.link_speed * 100));
2301 iflib_link_state_change(softc->ctx, LINK_STATE_DOWN,
2302 bnxt_get_baudrate(&softc->link_info));
2303 device_printf(softc->dev, "Link is Down\n");
2306 softc->link_info.last_link_up = softc->link_info.link_up;
2307 softc->link_info.last_pause = softc->link_info.pause;
2308 softc->link_info.last_duplex = softc->link_info.duplex;
2312 bnxt_handle_rx_cp(void *arg)
2314 struct bnxt_cp_ring *cpr = arg;
2316 /* Disable further interrupts for this queue */
2317 BNXT_CP_DISABLE_DB(&cpr->ring);
2318 return FILTER_SCHEDULE_THREAD;
2322 bnxt_handle_def_cp(void *arg)
2324 struct bnxt_softc *softc = arg;
2326 BNXT_CP_DISABLE_DB(&softc->def_cp_ring.ring);
2327 GROUPTASK_ENQUEUE(&softc->def_cp_task);
2328 return FILTER_HANDLED;
2332 bnxt_clear_ids(struct bnxt_softc *softc)
2336 softc->def_cp_ring.stats_ctx_id = HWRM_NA_SIGNATURE;
2337 softc->def_cp_ring.ring.phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2338 for (i = 0; i < softc->ntxqsets; i++) {
2339 softc->tx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2340 softc->tx_cp_rings[i].ring.phys_id =
2341 (uint16_t)HWRM_NA_SIGNATURE;
2342 softc->tx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2344 for (i = 0; i < softc->nrxqsets; i++) {
2345 softc->rx_cp_rings[i].stats_ctx_id = HWRM_NA_SIGNATURE;
2346 softc->rx_cp_rings[i].ring.phys_id =
2347 (uint16_t)HWRM_NA_SIGNATURE;
2348 softc->rx_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2349 softc->ag_rings[i].phys_id = (uint16_t)HWRM_NA_SIGNATURE;
2350 softc->grp_info[i].grp_id = (uint16_t)HWRM_NA_SIGNATURE;
2352 softc->vnic_info.filter_id = -1;
2353 softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
2354 softc->vnic_info.rss_id = (uint16_t)HWRM_NA_SIGNATURE;
2355 memset(softc->vnic_info.rss_grp_tbl.idi_vaddr, 0xff,
2356 softc->vnic_info.rss_grp_tbl.idi_size);
2360 bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr)
2362 struct cmpl_base *cmp = (void *)cpr->ring.vaddr;
2365 for (i = 0; i < cpr->ring.ring_size; i++)
2366 cmp[i].info3_v = !cpr->v_bit;
2370 bnxt_handle_async_event(struct bnxt_softc *softc, struct cmpl_base *cmpl)
2372 struct hwrm_async_event_cmpl *ae = (void *)cmpl;
2373 uint16_t async_id = le16toh(ae->event_id);
2374 struct ifmediareq ifmr;
2377 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
2378 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
2379 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
2380 bnxt_media_status(softc->ctx, &ifmr);
2382 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_MTU_CHANGE:
2383 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_DCB_CONFIG_CHANGE:
2384 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
2385 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_NOT_ALLOWED:
2386 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_UNLOAD:
2387 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_FUNC_DRVR_LOAD:
2388 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
2389 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_LOAD:
2390 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_FLR:
2391 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_MAC_ADDR_CHANGE:
2392 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_VF_COMM_STATUS_CHANGE:
2393 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
2394 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_HWRM_ERROR:
2395 device_printf(softc->dev,
2396 "Unhandled async completion type %u\n", async_id);
2399 device_printf(softc->dev,
2400 "Unknown async completion type %u\n", async_id);
2406 bnxt_def_cp_task(void *context)
2408 if_ctx_t ctx = context;
2409 struct bnxt_softc *softc = iflib_get_softc(ctx);
2410 struct bnxt_cp_ring *cpr = &softc->def_cp_ring;
2412 /* Handle completions on the default completion ring */
2413 struct cmpl_base *cmpl;
2414 uint32_t cons = cpr->cons;
2415 bool v_bit = cpr->v_bit;
2423 NEXT_CP_CONS_V(&cpr->ring, cons, v_bit);
2424 cmpl = &((struct cmpl_base *)cpr->ring.vaddr)[cons];
2426 if (!CMP_VALID(cmpl, v_bit))
2429 type = le16toh(cmpl->type) & CMPL_BASE_TYPE_MASK;
2431 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
2432 bnxt_handle_async_event(softc, cmpl);
2434 case CMPL_BASE_TYPE_TX_L2:
2435 case CMPL_BASE_TYPE_RX_L2:
2436 case CMPL_BASE_TYPE_RX_AGG:
2437 case CMPL_BASE_TYPE_RX_TPA_START:
2438 case CMPL_BASE_TYPE_RX_TPA_END:
2439 case CMPL_BASE_TYPE_STAT_EJECT:
2440 case CMPL_BASE_TYPE_HWRM_DONE:
2441 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
2442 case CMPL_BASE_TYPE_HWRM_FWD_RESP:
2443 case CMPL_BASE_TYPE_CQ_NOTIFICATION:
2444 case CMPL_BASE_TYPE_SRQ_EVENT:
2445 case CMPL_BASE_TYPE_DBQ_EVENT:
2446 case CMPL_BASE_TYPE_QP_EVENT:
2447 case CMPL_BASE_TYPE_FUNC_EVENT:
2448 device_printf(softc->dev,
2449 "Unhandled completion type %u\n", type);
2452 device_printf(softc->dev,
2453 "Unknown completion type %u\n", type);
2458 cpr->cons = last_cons;
2459 cpr->v_bit = last_v_bit;
2460 BNXT_CP_IDX_ENABLE_DB(&cpr->ring, cpr->cons);
2464 get_phy_type(struct bnxt_softc *softc)
2466 struct bnxt_link_info *link_info = &softc->link_info;
2467 uint8_t phy_type = link_info->phy_type;
2470 if (phy_type != HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_UNKNOWN)
2473 /* Deduce the phy type from the media type and supported speeds */
2474 supported = link_info->support_speeds;
2476 if (link_info->media_type ==
2477 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP)
2478 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET;
2479 if (link_info->media_type ==
2480 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_DAC) {
2481 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
2482 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKX;
2483 if (supported & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
2484 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASEKR;
2485 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASECR;
2487 if (link_info->media_type ==
2488 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_FIBRE)
2489 return HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASESR;
2495 bnxt_check_hwrm_version(struct bnxt_softc *softc)
2499 sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
2500 softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
2501 if (softc->ver_info->hwrm_min_major > softc->ver_info->hwrm_if_major) {
2502 device_printf(softc->dev,
2503 "WARNING: HWRM version %s is too old (older than %s)\n",
2504 softc->ver_info->hwrm_if_ver, buf);
2507 else if(softc->ver_info->hwrm_min_major ==
2508 softc->ver_info->hwrm_if_major) {
2509 if (softc->ver_info->hwrm_min_minor >
2510 softc->ver_info->hwrm_if_minor) {
2511 device_printf(softc->dev,
2512 "WARNING: HWRM version %s is too old (older than %s)\n",
2513 softc->ver_info->hwrm_if_ver, buf);
2516 else if (softc->ver_info->hwrm_min_minor ==
2517 softc->ver_info->hwrm_if_minor) {
2518 if (softc->ver_info->hwrm_min_update >
2519 softc->ver_info->hwrm_if_update) {
2520 device_printf(softc->dev,
2521 "WARNING: HWRM version %s is too old (older than %s)\n",
2522 softc->ver_info->hwrm_if_ver, buf);
2531 bnxt_get_baudrate(struct bnxt_link_info *link)
2533 switch (link->link_speed) {
2534 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2535 return IF_Mbps(100);
2536 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2538 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2540 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2541 return IF_Mbps(2500);
2542 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2544 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2546 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2548 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2550 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2552 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2553 return IF_Gbps(100);
2554 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10MB:
2557 return IF_Gbps(100);
2561 bnxt_get_wol_settings(struct bnxt_softc *softc)
2563 uint16_t wol_handle = 0;
2565 if (!bnxt_wol_supported(softc))
2569 wol_handle = bnxt_hwrm_get_wol_fltrs(softc, wol_handle);
2570 } while (wol_handle && wol_handle != BNXT_NO_MORE_WOL_FILTERS);