| 4708 | } |
| 4709 | |
| 4710 | int |
| 4711 | iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ctxp) |
| 4712 | { |
| 4713 | if_ctx_t ctx; |
| 4714 | if_t ifp; |
| 4715 | if_softc_ctx_t scctx; |
| 4716 | kobjop_desc_t kobj_desc; |
| 4717 | kobj_method_t *kobj_method; |
| 4718 | int err, msix, rid; |
| 4719 | int num_txd, num_rxd; |
| 4720 | |
| 4721 | ctx = malloc(sizeof(* ctx), M_IFLIB, M_WAITOK|M_ZERO); |
| 4722 | |
| 4723 | if (sc == NULL) { |
| 4724 | sc = malloc(sctx->isc_driver->size, M_IFLIB, M_WAITOK|M_ZERO); |
| 4725 | device_set_softc(dev, ctx); |
| 4726 | ctx->ifc_flags |= IFC_SC_ALLOCATED; |
| 4727 | } |
| 4728 | |
| 4729 | ctx->ifc_sctx = sctx; |
| 4730 | ctx->ifc_dev = dev; |
| 4731 | ctx->ifc_softc = sc; |
| 4732 | |
| 4733 | if ((err = iflib_register(ctx)) != 0) { |
| 4734 | device_printf(dev, "iflib_register failed %d\n", err); |
| 4735 | goto fail_ctx_free; |
| 4736 | } |
| 4737 | iflib_add_device_sysctl_pre(ctx); |
| 4738 | |
| 4739 | scctx = &ctx->ifc_softc_ctx; |
| 4740 | ifp = ctx->ifc_ifp; |
| 4741 | |
| 4742 | iflib_reset_qvalues(ctx); |
| 4743 | CTX_LOCK(ctx); |
| 4744 | if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { |
| 4745 | device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); |
| 4746 | goto fail_unlock; |
| 4747 | } |
| 4748 | _iflib_pre_assert(scctx); |
| 4749 | ctx->ifc_txrx = *scctx->isc_txrx; |
| 4750 | |
| 4751 | if (sctx->isc_flags & IFLIB_DRIVER_MEDIA) |
| 4752 | ctx->ifc_mediap = scctx->isc_media; |
| 4753 | |
| 4754 | #ifdef INVARIANTS |
| 4755 | if (scctx->isc_capabilities & IFCAP_TXCSUM) |
| 4756 | MPASS(scctx->isc_tx_csum_flags); |
| 4757 | #endif |
| 4758 | |
| 4759 | if_setcapabilities(ifp, |
| 4760 | scctx->isc_capabilities | IFCAP_HWSTATS | IFCAP_NOMAP); |
| 4761 | if_setcapenable(ifp, |
| 4762 | scctx->isc_capenable | IFCAP_HWSTATS | IFCAP_NOMAP); |
| 4763 | |
| 4764 | if (scctx->isc_ntxqsets == 0 || (scctx->isc_ntxqsets_max && scctx->isc_ntxqsets_max < scctx->isc_ntxqsets)) |
| 4765 | scctx->isc_ntxqsets = scctx->isc_ntxqsets_max; |
| 4766 | if (scctx->isc_nrxqsets == 0 || (scctx->isc_nrxqsets_max && scctx->isc_nrxqsets_max < scctx->isc_nrxqsets)) |
| 4767 | scctx->isc_nrxqsets = scctx->isc_nrxqsets_max; |
no test coverage detected