| 4953 | } |
| 4954 | |
| 4955 | int |
| 4956 | iflib_pseudo_register(device_t dev, if_shared_ctx_t sctx, if_ctx_t *ctxp, |
| 4957 | struct iflib_cloneattach_ctx *clctx) |
| 4958 | { |
| 4959 | int num_txd, num_rxd; |
| 4960 | int err; |
| 4961 | if_ctx_t ctx; |
| 4962 | if_t ifp; |
| 4963 | if_softc_ctx_t scctx; |
| 4964 | int i; |
| 4965 | void *sc; |
| 4966 | |
| 4967 | ctx = malloc(sizeof(*ctx), M_IFLIB, M_WAITOK|M_ZERO); |
| 4968 | sc = malloc(sctx->isc_driver->size, M_IFLIB, M_WAITOK|M_ZERO); |
| 4969 | ctx->ifc_flags |= IFC_SC_ALLOCATED; |
| 4970 | if (sctx->isc_flags & (IFLIB_PSEUDO|IFLIB_VIRTUAL)) |
| 4971 | ctx->ifc_flags |= IFC_PSEUDO; |
| 4972 | |
| 4973 | ctx->ifc_sctx = sctx; |
| 4974 | ctx->ifc_softc = sc; |
| 4975 | ctx->ifc_dev = dev; |
| 4976 | |
| 4977 | if ((err = iflib_register(ctx)) != 0) { |
| 4978 | device_printf(dev, "%s: iflib_register failed %d\n", __func__, err); |
| 4979 | goto fail_ctx_free; |
| 4980 | } |
| 4981 | iflib_add_device_sysctl_pre(ctx); |
| 4982 | |
| 4983 | scctx = &ctx->ifc_softc_ctx; |
| 4984 | ifp = ctx->ifc_ifp; |
| 4985 | |
| 4986 | iflib_reset_qvalues(ctx); |
| 4987 | CTX_LOCK(ctx); |
| 4988 | if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { |
| 4989 | device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); |
| 4990 | goto fail_unlock; |
| 4991 | } |
| 4992 | if (sctx->isc_flags & IFLIB_GEN_MAC) |
| 4993 | ether_gen_addr(ifp, &ctx->ifc_mac); |
| 4994 | if ((err = IFDI_CLONEATTACH(ctx, clctx->cc_ifc, clctx->cc_name, |
| 4995 | clctx->cc_params)) != 0) { |
| 4996 | device_printf(dev, "IFDI_CLONEATTACH failed %d\n", err); |
| 4997 | goto fail_unlock; |
| 4998 | } |
| 4999 | #ifdef INVARIANTS |
| 5000 | if (scctx->isc_capabilities & IFCAP_TXCSUM) |
| 5001 | MPASS(scctx->isc_tx_csum_flags); |
| 5002 | #endif |
| 5003 | |
| 5004 | if_setcapabilities(ifp, scctx->isc_capabilities | IFCAP_HWSTATS | IFCAP_LINKSTATE); |
| 5005 | if_setcapenable(ifp, scctx->isc_capenable | IFCAP_HWSTATS | IFCAP_LINKSTATE); |
| 5006 | |
| 5007 | ifp->if_flags |= IFF_NOGROUP; |
| 5008 | if (sctx->isc_flags & IFLIB_PSEUDO) { |
| 5009 | ifmedia_add(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO, 0, NULL); |
| 5010 | ifmedia_set(ctx->ifc_mediap, IFM_ETHER | IFM_AUTO); |
| 5011 | if (sctx->isc_flags & IFLIB_PSEUDO_ETHER) { |
| 5012 | ether_ifattach(ctx->ifc_ifp, ctx->ifc_mac.octet); |
no test coverage detected