Index: sys/dev/cxgbe/adapter.h =================================================================== --- sys/dev/cxgbe/adapter.h +++ sys/dev/cxgbe/adapter.h @@ -1288,7 +1288,6 @@ /* t4_kern_tls.c */ int cxgbe_tls_tag_alloc(struct ifnet *, union if_snd_tag_alloc_params *, struct m_snd_tag **); -void cxgbe_tls_tag_free(struct m_snd_tag *); void t6_ktls_modload(void); void t6_ktls_modunload(void); int t6_ktls_try(struct ifnet *, struct socket *, struct ktls_session *); @@ -1405,9 +1404,6 @@ struct cxgbe_rate_tag *lookup_etid(struct adapter *, int); int cxgbe_rate_tag_alloc(struct ifnet *, union if_snd_tag_alloc_params *, struct m_snd_tag **); -int cxgbe_rate_tag_modify(struct m_snd_tag *, union if_snd_tag_modify_params *); -int cxgbe_rate_tag_query(struct m_snd_tag *, union if_snd_tag_query_params *); -void cxgbe_rate_tag_free(struct m_snd_tag *); void cxgbe_rate_tag_free_locked(struct cxgbe_rate_tag *); void cxgbe_ratelimit_query(struct ifnet *, struct if_ratelimit_query_results *); #endif Index: sys/dev/cxgbe/crypto/t4_kern_tls.c =================================================================== --- sys/dev/cxgbe/crypto/t4_kern_tls.c +++ sys/dev/cxgbe/crypto/t4_kern_tls.c @@ -102,9 +102,14 @@ bool open_pending; }; +static void cxgbe_tls_tag_free(struct m_snd_tag *mst); static int ktls_setup_keys(struct tlspcb *tlsp, const struct ktls_session *tls, struct sge_txq *txq); +static const struct if_snd_tag_sw cxgbe_tls_tag_sw = { + .snd_tag_free = cxgbe_tls_tag_free +}; + static inline struct tlspcb * mst_to_tls(struct m_snd_tag *t) { @@ -122,7 +127,7 @@ if (tlsp == NULL) return (NULL); - m_snd_tag_init(&tlsp->com, ifp, IF_SND_TAG_TYPE_TLS); + m_snd_tag_init(&tlsp->com, ifp, IF_SND_TAG_TYPE_TLS, &cxgbe_tls_tag_sw); tlsp->vi = vi; tlsp->sc = sc; tlsp->ctrlq = &sc->sge.ctrlq[pi->port_id]; @@ -2071,7 +2076,7 @@ return (totdesc); } -void +static void cxgbe_tls_tag_free(struct m_snd_tag *mst) { struct adapter *sc; Index: sys/dev/cxgbe/t4_main.c =================================================================== --- sys/dev/cxgbe/t4_main.c +++ sys/dev/cxgbe/t4_main.c @@ -2453,9 +2453,6 @@ ifp->if_get_counter = cxgbe_get_counter; #if defined(KERN_TLS) || defined(RATELIMIT) ifp->if_snd_tag_alloc = cxgbe_snd_tag_alloc; - ifp->if_snd_tag_modify = cxgbe_snd_tag_modify; - ifp->if_snd_tag_query = cxgbe_snd_tag_query; - ifp->if_snd_tag_free = cxgbe_snd_tag_free; #endif #ifdef RATELIMIT ifp->if_ratelimit_query = cxgbe_ratelimit_query; @@ -3109,56 +3106,6 @@ } return (error); } - -static int -cxgbe_snd_tag_modify(struct m_snd_tag *mst, - union if_snd_tag_modify_params *params) -{ - - switch (mst->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - return (cxgbe_rate_tag_modify(mst, params)); -#endif - default: - return (EOPNOTSUPP); - } -} - -static int -cxgbe_snd_tag_query(struct m_snd_tag *mst, - union if_snd_tag_query_params *params) -{ - - switch (mst->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - return (cxgbe_rate_tag_query(mst, params)); -#endif - default: - return (EOPNOTSUPP); - } -} - -static void -cxgbe_snd_tag_free(struct m_snd_tag *mst) -{ - - switch (mst->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - cxgbe_rate_tag_free(mst); - return; -#endif -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS: - cxgbe_tls_tag_free(mst); - return; -#endif - default: - panic("shouldn't get here"); - } -} #endif /* Index: sys/dev/cxgbe/t4_sched.c =================================================================== --- sys/dev/cxgbe/t4_sched.c +++ sys/dev/cxgbe/t4_sched.c @@ -44,7 +44,6 @@ #include "common/t4_regs_values.h" #include "common/t4_msg.h" - static int in_range(int val, int lo, int hi) { @@ -785,6 +784,18 @@ mtx_unlock(&t->etid_lock); } +static int cxgbe_rate_tag_modify(struct m_snd_tag *, + union if_snd_tag_modify_params *); +static int cxgbe_rate_tag_query(struct m_snd_tag *, + union if_snd_tag_query_params *); +static void cxgbe_rate_tag_free(struct m_snd_tag *); + +static const struct if_snd_tag_sw cxgbe_rate_tag_sw = { + .snd_tag_modify = cxgbe_rate_tag_modify, + .snd_tag_query = cxgbe_rate_tag_query, + .snd_tag_free = cxgbe_rate_tag_free +}; + int cxgbe_rate_tag_alloc(struct ifnet *ifp, union if_snd_tag_alloc_params *params, struct m_snd_tag **pt) @@ -819,7 +830,8 @@ mtx_init(&cst->lock, "cst_lock", NULL, MTX_DEF); mbufq_init(&cst->pending_tx, INT_MAX); mbufq_init(&cst->pending_fwack, INT_MAX); - m_snd_tag_init(&cst->com, ifp, IF_SND_TAG_TYPE_RATE_LIMIT); + m_snd_tag_init(&cst->com, ifp, IF_SND_TAG_TYPE_RATE_LIMIT, + &cxgbe_rate_tag_sw); cst->flags |= EO_FLOWC_PENDING | EO_SND_TAG_REF; cst->adapter = sc; cst->port_id = pi->port_id; @@ -843,7 +855,7 @@ /* * Change in parameters, no change in ifp. */ -int +static int cxgbe_rate_tag_modify(struct m_snd_tag *mst, union if_snd_tag_modify_params *params) { @@ -869,7 +881,7 @@ return (0); } -int +static int cxgbe_rate_tag_query(struct m_snd_tag *mst, union if_snd_tag_query_params *params) { @@ -908,7 +920,7 @@ free(cst, M_CXGBE); } -void +static void cxgbe_rate_tag_free(struct m_snd_tag *mst) { struct cxgbe_rate_tag *cst = mst_to_crt(mst); Index: sys/dev/mlx5/mlx5_en/en.h =================================================================== --- sys/dev/mlx5/mlx5_en/en.h +++ sys/dev/mlx5/mlx5_en/en.h @@ -1216,9 +1216,4 @@ int mlx5e_fec_update(struct mlx5e_priv *priv); int mlx5e_hw_temperature_update(struct mlx5e_priv *priv); -if_snd_tag_alloc_t mlx5e_ul_snd_tag_alloc; -if_snd_tag_modify_t mlx5e_ul_snd_tag_modify; -if_snd_tag_query_t mlx5e_ul_snd_tag_query; -if_snd_tag_free_t mlx5e_ul_snd_tag_free; - #endif /* _MLX5_EN_H_ */ Index: sys/dev/mlx5/mlx5_en/en_hw_tls.h =================================================================== --- sys/dev/mlx5/mlx5_en/en_hw_tls.h +++ sys/dev/mlx5/mlx5_en/en_hw_tls.h @@ -97,8 +97,5 @@ int mlx5e_sq_tls_xmit(struct mlx5e_sq *, struct mlx5e_xmit_args *, struct mbuf **); if_snd_tag_alloc_t mlx5e_tls_snd_tag_alloc; -if_snd_tag_modify_t mlx5e_tls_snd_tag_modify; -if_snd_tag_query_t mlx5e_tls_snd_tag_query; -if_snd_tag_free_t mlx5e_tls_snd_tag_free; #endif /* _MLX5_TLS_H_ */ Index: sys/dev/mlx5/mlx5_en/en_rl.h =================================================================== --- sys/dev/mlx5/mlx5_en/en_rl.h +++ sys/dev/mlx5/mlx5_en/en_rl.h @@ -168,8 +168,5 @@ void mlx5e_rl_refresh_sq_inline(struct mlx5e_rl_priv_data *rl); if_snd_tag_alloc_t mlx5e_rl_snd_tag_alloc; -if_snd_tag_modify_t mlx5e_rl_snd_tag_modify; -if_snd_tag_query_t mlx5e_rl_snd_tag_query; -if_snd_tag_free_t mlx5e_rl_snd_tag_free; #endif /* __MLX5_EN_RL_H__ */ Index: sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls.c =================================================================== --- sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls.c +++ sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls.c @@ -37,6 +37,25 @@ #ifdef KERN_TLS +#ifdef RATELIMIT +static if_snd_tag_modify_t mlx5e_tls_rl_snd_tag_modify; +#endif +static if_snd_tag_query_t mlx5e_tls_snd_tag_query; +static if_snd_tag_free_t mlx5e_tls_snd_tag_free; + +static const struct if_snd_tag_sw mlx5e_tls_snd_tag_sw = { + .snd_tag_query = mlx5e_tls_snd_tag_query, + .snd_tag_free = mlx5e_tls_snd_tag_free +}; + +#ifdef RATELIMIT +static const struct if_snd_tag_sw mlx5e_tls_rl_snd_tag_sw = { + .snd_tag_modify = mlx5e_tls_rl_snd_tag_modify, + .snd_tag_query = mlx5e_tls_snd_tag_query, + .snd_tag_free = mlx5e_tls_snd_tag_free +}; +#endif + MALLOC_DEFINE(M_MLX5E_TLS, "MLX5E_TLS", "MLX5 ethernet HW TLS"); /* software TLS context */ @@ -281,6 +300,7 @@ struct m_snd_tag **ppmt) { union if_snd_tag_alloc_params rl_params; + const struct if_snd_tag_sw *snd_tag_sw; struct mlx5e_priv *priv; struct mlx5e_tls_tag *ptag; const struct tls_session_params *en; @@ -384,10 +404,12 @@ case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: rl_params.hdr.type = IF_SND_TAG_TYPE_RATE_LIMIT; rl_params.rate_limit.max_rate = params->tls_rate_limit.max_rate; + snd_tag_sw = &mlx5e_tls_rl_snd_tag_sw; break; #endif case IF_SND_TAG_TYPE_TLS: rl_params.hdr.type = IF_SND_TAG_TYPE_UNLIMITED; + snd_tag_sw = &mlx5e_tls_snd_tag_sw; break; default: error = EOPNOTSUPP; @@ -400,7 +422,7 @@ /* store pointer to mbuf tag */ MPASS(ptag->tag.refcount == 0); - m_snd_tag_init(&ptag->tag, ifp, params->hdr.type); + m_snd_tag_init(&ptag->tag, ifp, params->hdr.type, snd_tag_sw); *ppmt = &ptag->tag; queue_work(priv->tls.wq, &ptag->work); @@ -413,53 +435,32 @@ return (error); } -int -mlx5e_tls_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_params *params) -{ #ifdef RATELIMIT +static int +mlx5e_tls_rl_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_params *params) +{ union if_snd_tag_modify_params rl_params; struct mlx5e_tls_tag *ptag = container_of(pmt, struct mlx5e_tls_tag, tag); int error; -#endif - switch (pmt->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: - memset(&rl_params, 0, sizeof(rl_params)); - rl_params.rate_limit.max_rate = params->tls_rate_limit.max_rate; - error = ptag->rl_tag->ifp->if_snd_tag_modify(ptag->rl_tag, - &rl_params); - return (error); -#endif - default: - return (EOPNOTSUPP); - } + memset(&rl_params, 0, sizeof(rl_params)); + rl_params.rate_limit.max_rate = params->tls_rate_limit.max_rate; + error = ptag->rl_tag->sw->snd_tag_modify(ptag->rl_tag, &rl_params); + return (error); } +#endif -int +static int mlx5e_tls_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) { struct mlx5e_tls_tag *ptag = container_of(pmt, struct mlx5e_tls_tag, tag); - int error; - switch (pmt->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: -#endif - case IF_SND_TAG_TYPE_TLS: - error = ptag->rl_tag->ifp->if_snd_tag_query(ptag->rl_tag, - params); - break; - default: - error = EOPNOTSUPP; - break; - } - return (error); + return (ptag->rl_tag->sw->snd_tag_query(ptag->rl_tag, params)); } -void +static void mlx5e_tls_snd_tag_free(struct m_snd_tag *pmt) { struct mlx5e_tls_tag *ptag = Index: sys/dev/mlx5/mlx5_en/mlx5_en_main.c =================================================================== --- sys/dev/mlx5/mlx5_en/mlx5_en_main.c +++ sys/dev/mlx5/mlx5_en/mlx5_en_main.c @@ -36,6 +36,8 @@ #include static int mlx5e_get_wqe_sz(struct mlx5e_priv *priv, u32 *wqe_sz, u32 *nsegs); +static if_snd_tag_query_t mlx5e_ul_snd_tag_query; +static if_snd_tag_free_t mlx5e_ul_snd_tag_free; struct mlx5e_channel_param { struct mlx5e_rq_param rq; @@ -346,6 +348,11 @@ }, }; +static const struct if_snd_tag_sw mlx5e_ul_snd_tag_sw = { + .snd_tag_query = mlx5e_ul_snd_tag_query, + .snd_tag_free = mlx5e_ul_snd_tag_free +}; + DEBUGNET_DEFINE(mlx5_en); MALLOC_DEFINE(M_MLX5EN, "MLX5EN", "MLX5 Ethernet"); @@ -2113,7 +2120,8 @@ c->ix = ix; /* setup send tag */ - m_snd_tag_init(&c->tag, c->priv->ifp, IF_SND_TAG_TYPE_UNLIMITED); + m_snd_tag_init(&c->tag, c->priv->ifp, IF_SND_TAG_TYPE_UNLIMITED, + &mlx5e_ul_snd_tag_sw); init_completion(&c->completion); @@ -4174,7 +4182,7 @@ PRIV_UNLOCK(priv); } -int +static int mlx5e_ul_snd_tag_alloc(struct ifnet *ifp, union if_snd_tag_alloc_params *params, struct m_snd_tag **ppmt) @@ -4216,7 +4224,7 @@ } } -int +static int mlx5e_ul_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) { struct mlx5e_channel *pch = @@ -4227,7 +4235,7 @@ return (0); } -void +static void mlx5e_ul_snd_tag_free(struct m_snd_tag *pmt) { struct mlx5e_channel *pch = @@ -4262,52 +4270,6 @@ } } -static int -mlx5e_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_params *params) -{ - - switch (pmt->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - return (mlx5e_rl_snd_tag_modify(pmt, params)); -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: - return (mlx5e_tls_snd_tag_modify(pmt, params)); -#endif -#endif - case IF_SND_TAG_TYPE_UNLIMITED: -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS: -#endif - default: - return (EOPNOTSUPP); - } -} - -static int -mlx5e_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) -{ - - switch (pmt->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - return (mlx5e_rl_snd_tag_query(pmt, params)); -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: - return (mlx5e_tls_snd_tag_query(pmt, params)); -#endif -#endif - case IF_SND_TAG_TYPE_UNLIMITED: - return (mlx5e_ul_snd_tag_query(pmt, params)); -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS: - return (mlx5e_tls_snd_tag_query(pmt, params)); -#endif - default: - return (EOPNOTSUPP); - } -} - #ifdef RATELIMIT #define NUM_HDWR_RATES_MLX 13 static const uint64_t adapter_rates_mlx[NUM_HDWR_RATES_MLX] = { @@ -4352,34 +4314,6 @@ } #endif -static void -mlx5e_snd_tag_free(struct m_snd_tag *pmt) -{ - - switch (pmt->type) { -#ifdef RATELIMIT - case IF_SND_TAG_TYPE_RATE_LIMIT: - mlx5e_rl_snd_tag_free(pmt); - break; -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: - mlx5e_tls_snd_tag_free(pmt); - break; -#endif -#endif - case IF_SND_TAG_TYPE_UNLIMITED: - mlx5e_ul_snd_tag_free(pmt); - break; -#ifdef KERN_TLS - case IF_SND_TAG_TYPE_TLS: - mlx5e_tls_snd_tag_free(pmt); - break; -#endif - default: - break; - } -} - static void mlx5e_ifm_add(struct mlx5e_priv *priv, int type) { @@ -4467,9 +4401,6 @@ #endif ifp->if_capabilities |= IFCAP_VXLAN_HWCSUM | IFCAP_VXLAN_HWTSO; ifp->if_snd_tag_alloc = mlx5e_snd_tag_alloc; - ifp->if_snd_tag_free = mlx5e_snd_tag_free; - ifp->if_snd_tag_modify = mlx5e_snd_tag_modify; - ifp->if_snd_tag_query = mlx5e_snd_tag_query; #ifdef RATELIMIT ifp->if_ratelimit_query = mlx5e_ratelimit_query; #endif Index: sys/dev/mlx5/mlx5_en/mlx5_en_rl.c =================================================================== --- sys/dev/mlx5/mlx5_en/mlx5_en_rl.c +++ sys/dev/mlx5/mlx5_en/mlx5_en_rl.c @@ -38,6 +38,15 @@ struct sysctl_oid *node, const char *name, const char *desc); static int mlx5e_rl_tx_limit_add(struct mlx5e_rl_priv_data *, uint64_t value); static int mlx5e_rl_tx_limit_clr(struct mlx5e_rl_priv_data *, uint64_t value); +static if_snd_tag_modify_t mlx5e_rl_snd_tag_modify; +static if_snd_tag_query_t mlx5e_rl_snd_tag_query; +static if_snd_tag_free_t mlx5e_rl_snd_tag_free; + +static const struct if_snd_tag_sw mlx5e_rl_snd_tag_sw = { + .snd_tag_modify = mlx5e_rl_snd_tag_modify, + .snd_tag_query = mlx5e_rl_snd_tag_query, + .snd_tag_free = mlx5e_rl_snd_tag_free +}; static void mlx5e_rl_build_sq_param(struct mlx5e_rl_priv_data *rl, @@ -1110,14 +1119,15 @@ /* store pointer to mbuf tag */ MPASS(channel->tag.refcount == 0); - m_snd_tag_init(&channel->tag, ifp, IF_SND_TAG_TYPE_RATE_LIMIT); + m_snd_tag_init(&channel->tag, ifp, IF_SND_TAG_TYPE_RATE_LIMIT, + &mlx5e_rl_snd_tag_sw); *ppmt = &channel->tag; done: return (error); } -int +static int mlx5e_rl_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_params *params) { struct mlx5e_rl_channel *channel = @@ -1126,7 +1136,7 @@ return (mlx5e_rl_modify(channel->worker, channel, params->rate_limit.max_rate)); } -int +static int mlx5e_rl_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) { struct mlx5e_rl_channel *channel = @@ -1135,7 +1145,7 @@ return (mlx5e_rl_query(channel->worker, channel, params)); } -void +static void mlx5e_rl_snd_tag_free(struct m_snd_tag *pmt) { struct mlx5e_rl_channel *channel = Index: sys/kern/kern_mbuf.c =================================================================== --- sys/kern/kern_mbuf.c +++ sys/kern/kern_mbuf.c @@ -1547,13 +1547,15 @@ } void -m_snd_tag_init(struct m_snd_tag *mst, struct ifnet *ifp, u_int type) +m_snd_tag_init(struct m_snd_tag *mst, struct ifnet *ifp, u_int type, + const struct if_snd_tag_sw *sw) { if_ref(ifp); mst->ifp = ifp; refcount_init(&mst->refcount, 1); mst->type = type; + mst->sw = sw; counter_u64_add(snd_tag_count, 1); } @@ -1563,7 +1565,7 @@ struct ifnet *ifp; ifp = mst->ifp; - ifp->if_snd_tag_free(mst); + mst->sw->snd_tag_free(mst); if_rele(ifp); counter_u64_add(snd_tag_count, -1); } Index: sys/kern/uipc_ktls.c =================================================================== --- sys/kern/uipc_ktls.c +++ sys/kern/uipc_ktls.c @@ -1456,7 +1456,6 @@ .rate_limit.flags = M_NOWAIT, }; struct m_snd_tag *mst; - struct ifnet *ifp; /* Can't get to the inp, but it should be locked. */ /* INP_LOCK_ASSERT(inp); */ @@ -1477,8 +1476,7 @@ MPASS(tls->snd_tag->type == IF_SND_TAG_TYPE_TLS_RATE_LIMIT); mst = tls->snd_tag; - ifp = mst->ifp; - return (ifp->if_snd_tag_modify(mst, ¶ms)); + return (mst->sw->snd_tag_modify(mst, ¶ms)); } #endif #endif Index: sys/net/if_dead.c =================================================================== --- sys/net/if_dead.c +++ sys/net/if_dead.c @@ -109,23 +109,6 @@ return (EOPNOTSUPP); } -static int -ifdead_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_params *params) -{ - return (EOPNOTSUPP); -} - -static int -ifdead_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) -{ - return (EOPNOTSUPP); -} - -static void -ifdead_snd_tag_free(struct m_snd_tag *pmt) -{ -} - static void ifdead_ratelimit_query(struct ifnet *ifp __unused, struct if_ratelimit_query_results *q) @@ -156,8 +139,5 @@ ifp->if_transmit = ifdead_transmit; ifp->if_get_counter = ifdead_get_counter; ifp->if_snd_tag_alloc = ifdead_snd_tag_alloc; - ifp->if_snd_tag_modify = ifdead_snd_tag_modify; - ifp->if_snd_tag_query = ifdead_snd_tag_query; - ifp->if_snd_tag_free = ifdead_snd_tag_free; ifp->if_ratelimit_query = ifdead_ratelimit_query; } Index: sys/net/if_lagg.c =================================================================== --- sys/net/if_lagg.c +++ sys/net/if_lagg.c @@ -583,10 +583,6 @@ ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; #if defined(KERN_TLS) || defined(RATELIMIT) ifp->if_snd_tag_alloc = lagg_snd_tag_alloc; - ifp->if_snd_tag_modify = lagg_snd_tag_modify; - ifp->if_snd_tag_query = lagg_snd_tag_query; - ifp->if_snd_tag_free = lagg_snd_tag_free; - ifp->if_next_snd_tag = lagg_next_snd_tag; ifp->if_ratelimit_query = lagg_ratelimit_query; #endif ifp->if_capenable = ifp->if_capabilities = IFCAP_HWSTATS; @@ -1739,6 +1735,13 @@ } #if defined(KERN_TLS) || defined(RATELIMIT) +static const struct if_snd_tag_sw lagg_snd_tag_sw = { + .snd_tag_modify = lagg_snd_tag_modify, + .snd_tag_query = lagg_snd_tag_query, + .snd_tag_free = lagg_snd_tag_free, + .next_snd_tag = lagg_next_snd_tag +}; + static inline struct lagg_snd_tag * mst_to_lst(struct m_snd_tag *mst) { @@ -1830,7 +1833,7 @@ return (error); } - m_snd_tag_init(&lst->com, ifp, lst->tag->type); + m_snd_tag_init(&lst->com, ifp, lst->tag->type, &lagg_snd_tag_sw); *ppmt = &lst->com; return (0); @@ -1852,7 +1855,7 @@ struct lagg_snd_tag *lst; lst = mst_to_lst(mst); - return (lst->tag->ifp->if_snd_tag_modify(lst->tag, params)); + return (lst->tag->sw->snd_tag_modify(lst->tag, params)); } static int @@ -1862,7 +1865,7 @@ struct lagg_snd_tag *lst; lst = mst_to_lst(mst); - return (lst->tag->ifp->if_snd_tag_query(lst->tag, params)); + return (lst->tag->sw->snd_tag_query(lst->tag, params)); } static void Index: sys/net/if_var.h =================================================================== --- sys/net/if_var.h +++ sys/net/if_var.h @@ -249,6 +249,20 @@ struct if_snd_tag_rate_limit_params tls_rate_limit; }; +typedef int (if_snd_tag_alloc_t)(struct ifnet *, union if_snd_tag_alloc_params *, + struct m_snd_tag **); +typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *); +typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *); +typedef void (if_snd_tag_free_t)(struct m_snd_tag *); +typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *); + +struct if_snd_tag_sw { + if_snd_tag_modify_t *snd_tag_modify; + if_snd_tag_query_t *snd_tag_query; + if_snd_tag_free_t *snd_tag_free; + if_next_send_tag_t *next_snd_tag; +}; + /* Query return flags */ #define RT_NOSUPPORT 0x00000000 /* Not supported */ #define RT_IS_INDIRECT 0x00000001 /* @@ -273,12 +287,6 @@ uint32_t min_segment_burst; /* The amount the adapter bursts at each send */ }; -typedef int (if_snd_tag_alloc_t)(struct ifnet *, union if_snd_tag_alloc_params *, - struct m_snd_tag **); -typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *); -typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *); -typedef void (if_snd_tag_free_t)(struct m_snd_tag *); -typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *); typedef void (if_ratelimit_query_t)(struct ifnet *, struct if_ratelimit_query_results *); typedef int (if_ratelimit_setup_t)(struct ifnet *, uint64_t, uint32_t); @@ -420,10 +428,8 @@ * Network adapter send tag support: */ if_snd_tag_alloc_t *if_snd_tag_alloc; - if_snd_tag_modify_t *if_snd_tag_modify; - if_snd_tag_query_t *if_snd_tag_query; - if_snd_tag_free_t *if_snd_tag_free; - if_next_send_tag_t *if_next_snd_tag; + + /* Ratelimit (packet pacing) */ if_ratelimit_query_t *if_ratelimit_query; if_ratelimit_setup_t *if_ratelimit_setup; Index: sys/net/if_vlan.c =================================================================== --- sys/net/if_vlan.c +++ sys/net/if_vlan.c @@ -332,6 +332,15 @@ #define V_vlan_cloner VNET(vlan_cloner) #endif +#if defined(KERN_TLS) || defined(RATELIMIT) +static const struct if_snd_tag_sw vlan_snd_tag_sw = { + .snd_tag_modify = vlan_snd_tag_modify, + .snd_tag_query = vlan_snd_tag_query, + .snd_tag_free = vlan_snd_tag_free, + .next_snd_tag = vlan_next_snd_tag +}; +#endif + static void vlan_mc_free(struct epoch_context *ctx) { @@ -1102,10 +1111,6 @@ ifp->if_ioctl = vlan_ioctl; #if defined(KERN_TLS) || defined(RATELIMIT) ifp->if_snd_tag_alloc = vlan_snd_tag_alloc; - ifp->if_snd_tag_modify = vlan_snd_tag_modify; - ifp->if_snd_tag_query = vlan_snd_tag_query; - ifp->if_snd_tag_free = vlan_snd_tag_free; - ifp->if_next_snd_tag = vlan_next_snd_tag; ifp->if_ratelimit_query = vlan_ratelimit_query; #endif ifp->if_flags = VLAN_IFFLAGS; @@ -2110,7 +2115,7 @@ return (error); } - m_snd_tag_init(&vst->com, ifp, vst->tag->type); + m_snd_tag_init(&vst->com, ifp, vst->tag->type, &vlan_snd_tag_sw); *ppmt = &vst->com; return (0); @@ -2132,7 +2137,7 @@ struct vlan_snd_tag *vst; vst = mst_to_vst(mst); - return (vst->tag->ifp->if_snd_tag_modify(vst->tag, params)); + return (vst->tag->sw->snd_tag_modify(vst->tag, params)); } static int @@ -2142,7 +2147,7 @@ struct vlan_snd_tag *vst; vst = mst_to_vst(mst); - return (vst->tag->ifp->if_snd_tag_query(vst->tag, params)); + return (vst->tag->sw->snd_tag_query(vst->tag, params)); } static void Index: sys/netinet/in_pcb.c =================================================================== --- sys/netinet/in_pcb.c +++ sys/netinet/in_pcb.c @@ -3293,21 +3293,16 @@ .rate_limit.flags = M_NOWAIT, }; struct m_snd_tag *mst; - struct ifnet *ifp; int error; mst = inp->inp_snd_tag; if (mst == NULL) return (EINVAL); - ifp = mst->ifp; - if (ifp == NULL) - return (EINVAL); - - if (ifp->if_snd_tag_modify == NULL) { + if (mst->sw->snd_tag_modify == NULL) { error = EOPNOTSUPP; } else { - error = ifp->if_snd_tag_modify(mst, ¶ms); + error = mst->sw->snd_tag_modify(mst, ¶ms); } return (error); } @@ -3321,22 +3316,17 @@ { union if_snd_tag_query_params params = { }; struct m_snd_tag *mst; - struct ifnet *ifp; int error; mst = inp->inp_snd_tag; if (mst == NULL) return (EINVAL); - ifp = mst->ifp; - if (ifp == NULL) - return (EINVAL); - - if (ifp->if_snd_tag_query == NULL) { + if (mst->sw->snd_tag_query == NULL) { error = EOPNOTSUPP; } else { - error = ifp->if_snd_tag_query(mst, ¶ms); - if (error == 0 && p_max_pacing_rate != NULL) + error = mst->sw->snd_tag_query(mst, ¶ms); + if (error == 0 && p_max_pacing_rate != NULL) *p_max_pacing_rate = params.rate_limit.max_rate; } return (error); @@ -3351,22 +3341,17 @@ { union if_snd_tag_query_params params = { }; struct m_snd_tag *mst; - struct ifnet *ifp; int error; mst = inp->inp_snd_tag; if (mst == NULL) return (EINVAL); - ifp = mst->ifp; - if (ifp == NULL) - return (EINVAL); - - if (ifp->if_snd_tag_query == NULL) + if (mst->sw->snd_tag_query == NULL) return (EOPNOTSUPP); - error = ifp->if_snd_tag_query(mst, ¶ms); - if (error == 0 && p_txqueue_level != NULL) + error = mst->sw->snd_tag_query(mst, ¶ms); + if (error == 0 && p_txqueue_level != NULL) *p_txqueue_level = params.rate_limit.queue_level; return (error); } Index: sys/netinet/tcp_ratelimit.c =================================================================== --- sys/netinet/tcp_ratelimit.c +++ sys/netinet/tcp_ratelimit.c @@ -1065,8 +1065,8 @@ return (NULL); } ntag = tag; - while(ntag->ifp->if_next_snd_tag != NULL) { - ntag = ntag->ifp->if_next_snd_tag(ntag); + while (ntag->sw->next_snd_tag != NULL) { + ntag = ntag->sw->next_snd_tag(ntag); } tifp = ntag->ifp; m_snd_tag_rele(tag); Index: sys/sys/mbuf.h =================================================================== --- sys/sys/mbuf.h +++ sys/sys/mbuf.h @@ -140,8 +140,11 @@ * Static network interface owned tag. * Allocated through ifp->if_snd_tag_alloc(). */ +struct if_snd_tag_sw; + struct m_snd_tag { struct ifnet *ifp; /* network interface tag belongs to */ + const struct if_snd_tag_sw *sw; volatile u_int refcount; u_int type; /* One of IF_SND_TAG_TYPE_*. */ }; @@ -848,7 +851,8 @@ struct mbuf *m_unshare(struct mbuf *, int); int m_snd_tag_alloc(struct ifnet *, union if_snd_tag_alloc_params *, struct m_snd_tag **); -void m_snd_tag_init(struct m_snd_tag *, struct ifnet *, u_int); +void m_snd_tag_init(struct m_snd_tag *, struct ifnet *, u_int, + const struct if_snd_tag_sw *); void m_snd_tag_destroy(struct m_snd_tag *); static __inline int