On 12/3/26 12:30, Shradha Gupta wrote:
> XDP programs attached to a MANA netdevice currently cannot access the > receive RSS hash or its protocol type. They must either recompute the > hash or operate without metadata that the hardware has already > provided. > > Expose the hardware RSS hash and type through xdp_metadata_ops so XDP > programs can use the same receive-hash information as the skb path. > Keep the hash value packet-local for coalesced receive completions, and > decode the NDIS hash-type bitmask with protocol-specific L4 types > taking precedence over L3-only types. Return -ENODATA when no > recognized hash type is present. > > Reviewed-by: Haiyang Zhang <haiy…@microsoft.com> > Signed-off-by: Shradha Gupta <shra…@linux.microsoft.com> > --- > .../net/ethernet/microsoft/mana/mana_bpf.c | 48 +++++++++++++++++++ > drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++-- > include/net/mana/mana.h | 7 +++ > 3 files changed, 63 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c > index 494267b30..5aec18b19 100644 > --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c > +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c > @@ -10,6 +10,54 @@ > #include <net/mana/mana.h> > +static enum xdp_rss_hash_type mana_xdp_rss_type(u16 hash_type) > +{ > + if (hash_type & NDIS_HASH_TCP_IPV4) > + return XDP_RSS_TYPE_L4_IPV4_TCP; > + if (hash_type & NDIS_HASH_UDP_IPV4) > + return XDP_RSS_TYPE_L4_IPV4_UDP; > + if (hash_type & NDIS_HASH_TCP_IPV6_EX) > + return XDP_RSS_TYPE_L4_IPV6_TCP_EX; > + if (hash_type & NDIS_HASH_UDP_IPV6_EX) > + return XDP_RSS_TYPE_L4_IPV6_UDP_EX; > + if (hash_type & NDIS_HASH_TCP_IPV6) > + return XDP_RSS_TYPE_L4_IPV6_TCP; > + if (hash_type & NDIS_HASH_UDP_IPV6) > + return XDP_RSS_TYPE_L4_IPV6_UDP; > + if (hash_type & NDIS_HASH_IPV4) > + return XDP_RSS_TYPE_L3_IPV4; > + if (hash_type & NDIS_HASH_IPV6) > + return XDP_RSS_TYPE_L3_IPV6; > + if (hash_type & NDIS_HASH_IPV6_EX) > + return XDP_RSS_TYPE_L3_IPV6_EX;
Why does NDIS_HASH_IPV6 take precedence over NDIS_HASH_IPV6_EX? Especially when above NDIS_HASH_TCP_IPV6_EX takes precedence over NDIS_HASH_TCP_IPV6. Other drivers have a lookup table to avoid this kind of if-statements, but I assume you have some good reason for not doing a lookup table(?) --Jesper
> + > + return XDP_RSS_TYPE_NONE; > +} > + > +static int mana_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, > + enum xdp_rss_hash_type *rss_type) > +{ > + const struct mana_xdp_buff *mxdp = (const void *)ctx; > + enum xdp_rss_hash_type hash_type; > + > + if (!(mxdp->xdp.rxq->dev->features & NETIF_F_RXHASH) || > + !mxdp->cqe->rx_hashtype) > + return -ENODATA; > + > + hash_type = mana_xdp_rss_type(mxdp->cqe->rx_hashtype); > + if (hash_type == XDP_RSS_TYPE_NONE) > + return -ENODATA; > + > + *hash = mxdp->pkt_hash; > + *rss_type = hash_type; > + > + return 0; > +} > + > +const struct xdp_metadata_ops mana_xdp_metadata_ops = { > + .xmo_rx_hash = mana_xdp_rx_hash, > +}; > + > void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev) > { > u16 txq_idx = skb_get_queue_mapping(skb); > diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c > index 95bf153c3..6bfc3cff1 100644 > --- a/drivers/net/ethernet/microsoft/mana/mana_en.c > +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c > @@ -2145,7 +2145,11 @@ static void mana_rx_skb(void *buf_va, bool from_pool, > struct net_device *ndev = rxq->ndev; > u16 rxq_idx = rxq->rxq_idx; > struct napi_struct *napi; > - struct xdp_buff xdp = {}; > + struct mana_xdp_buff mxdp = { > + .cqe = cqe, > + .pkt_hash = pkt_hash, > + }; > + struct xdp_buff *xdp = &mxdp.xdp; > struct sk_buff *skb; > u32 act; > @@ -2157,7 +2161,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool, > return; > } > - act = mana_run_xdp(ndev, rxq, &xdp, buf_va, from_pool, pkt_len); > + act = mana_run_xdp(ndev, rxq, xdp, buf_va, from_pool, pkt_len); > if (act == XDP_REDIRECT && !rxq->xdp_rc) > return; > @@ -2165,7 +2169,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool, > if (act != XDP_PASS && act != XDP_TX) > goto drop_xdp; > - skb = mana_build_skb(rxq, buf_va, pkt_len, &xdp); > + skb = mana_build_skb(rxq, buf_va, pkt_len, xdp); > if (!skb) > goto drop; > @@ -3968,6 +3972,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, > ndev->netdev_ops = &mana_devops; > ndev->ethtool_ops = &mana_ethtool_ops; > + ndev->xdp_metadata_ops = &mana_xdp_metadata_ops; > ndev->mtu = ETH_DATA_LEN; > ndev->max_mtu = gc->adapter_mtu - ETH_HLEN; > ndev->min_mtu = ETH_MIN_MTU; > diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h > index 84afc4199..1085266e3 100644 > --- a/include/net/mana/mana.h > +++ b/include/net/mana/mana.h > @@ -297,6 +297,12 @@ struct mana_rxcomp_oob { > u32 rx_wqe_offset; > }; /* HW DATA */ > +struct mana_xdp_buff { > + struct xdp_buff xdp; > + const struct mana_rxcomp_oob *cqe; > + u32 pkt_hash; > +}; > + > struct mana_tx_comp_oob { > struct mana_cqe_header cqe_hdr; > @@ -717,6 +723,7 @@ void mana_pre_dealloc_rxbufs(struct mana_port_context *apc); > void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc); > extern const struct ethtool_ops mana_ethtool_ops; > +extern const struct xdp_metadata_ops mana_xdp_metadata_ops; > extern struct dentry *mana_debugfs_root; > /* A CQ can be created not associated with any EQ */ > > base-commit: ed3135d0881a926de56a7f490dea3d51698ba118