Skip to content

Commit 702bd18

Browse files
committed
idpf: add XDP RSS hash hint
Add &xdp_metadata_ops with a callback to get RSS hash hint from the descriptor. Declare the splitq 32-byte descriptor as 4 u64s to parse them more efficiently when possible. Signed-off-by: Alexander Lobakin <[email protected]>
1 parent 098038a commit 702bd18

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

drivers/net/ethernet/intel/idpf/xdp.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,38 @@ int idpf_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
394394
idpf_xdp_tx_finalize);
395395
}
396396

397+
static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash,
398+
enum xdp_rss_hash_type *rss_type)
399+
{
400+
const struct libeth_xdp_buff *xdp = (typeof(xdp))ctx;
401+
const struct idpf_rx_queue *rxq;
402+
struct idpf_xdp_rx_desc desc;
403+
struct libeth_rx_pt pt;
404+
405+
rxq = libeth_xdp_buff_to_rq(xdp, typeof(*rxq), xdp_rxq);
406+
407+
idpf_xdp_get_qw0(&desc, xdp->desc);
408+
409+
pt = rxq->rx_ptype_lkup[idpf_xdp_rx_pt(&desc)];
410+
if (!libeth_rx_pt_has_hash(rxq->xdp_rxq.dev, pt))
411+
return -ENODATA;
412+
413+
idpf_xdp_get_qw2(&desc, xdp->desc);
414+
415+
return libeth_xdpmo_rx_hash(hash, rss_type, idpf_xdp_rx_hash(&desc),
416+
pt);
417+
}
418+
419+
static const struct xdp_metadata_ops idpf_xdpmo = {
420+
.xmo_rx_hash = idpf_xdpmo_rx_hash,
421+
};
422+
397423
void idpf_xdp_set_features(const struct idpf_vport *vport)
398424
{
399425
if (!idpf_is_queue_model_split(vport->rxq_model))
400426
return;
401427

402-
libeth_xdp_set_features_noredir(vport->netdev);
428+
libeth_xdp_set_features_noredir(vport->netdev, &idpf_xdpmo);
403429
}
404430

405431
/**

drivers/net/ethernet/intel/idpf/xdp.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,70 @@ static inline void idpf_xdp_tx_finalize(void *_xdpq, bool sent, bool flush)
107107
libeth_xdpsq_unlock(&xdpq->xdp_lock);
108108
}
109109

110+
struct idpf_xdp_rx_desc {
111+
aligned_u64 qw0;
112+
#define IDPF_XDP_RX_BUFQ BIT_ULL(47)
113+
#define IDPF_XDP_RX_GEN BIT_ULL(46)
114+
#define IDPF_XDP_RX_LEN GENMASK_ULL(45, 32)
115+
#define IDPF_XDP_RX_PT GENMASK_ULL(25, 16)
116+
117+
aligned_u64 qw1;
118+
#define IDPF_XDP_RX_BUF GENMASK_ULL(47, 32)
119+
#define IDPF_XDP_RX_EOP BIT_ULL(1)
120+
121+
aligned_u64 qw2;
122+
#define IDPF_XDP_RX_HASH GENMASK_ULL(31, 0)
123+
124+
aligned_u64 qw3;
125+
} __aligned(4 * sizeof(u64));
126+
static_assert(sizeof(struct idpf_xdp_rx_desc) ==
127+
sizeof(struct virtchnl2_rx_flex_desc_adv_nic_3));
128+
129+
#define idpf_xdp_rx_bufq(desc) !!((desc)->qw0 & IDPF_XDP_RX_BUFQ)
130+
#define idpf_xdp_rx_gen(desc) !!((desc)->qw0 & IDPF_XDP_RX_GEN)
131+
#define idpf_xdp_rx_len(desc) FIELD_GET(IDPF_XDP_RX_LEN, (desc)->qw0)
132+
#define idpf_xdp_rx_pt(desc) FIELD_GET(IDPF_XDP_RX_PT, (desc)->qw0)
133+
#define idpf_xdp_rx_buf(desc) FIELD_GET(IDPF_XDP_RX_BUF, (desc)->qw1)
134+
#define idpf_xdp_rx_eop(desc) !!((desc)->qw1 & IDPF_XDP_RX_EOP)
135+
#define idpf_xdp_rx_hash(desc) FIELD_GET(IDPF_XDP_RX_HASH, (desc)->qw2)
136+
137+
static inline void
138+
idpf_xdp_get_qw0(struct idpf_xdp_rx_desc *desc,
139+
const struct virtchnl2_rx_flex_desc_adv_nic_3 *rxd)
140+
{
141+
#ifdef __LIBETH_WORD_ACCESS
142+
desc->qw0 = ((const typeof(desc))rxd)->qw0;
143+
#else
144+
desc->qw0 = ((u64)le16_to_cpu(rxd->pktlen_gen_bufq_id) << 32) |
145+
((u64)le16_to_cpu(rxd->ptype_err_fflags0) << 16);
146+
#endif
147+
}
148+
149+
static inline void
150+
idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc,
151+
const struct virtchnl2_rx_flex_desc_adv_nic_3 *rxd)
152+
{
153+
#ifdef __LIBETH_WORD_ACCESS
154+
desc->qw1 = ((const typeof(desc))rxd)->qw1;
155+
#else
156+
desc->qw1 = ((u64)le16_to_cpu(rxd->buf_id) << 32) |
157+
rxd->status_err0_qw1;
158+
#endif
159+
}
160+
161+
static inline void
162+
idpf_xdp_get_qw2(struct idpf_xdp_rx_desc *desc,
163+
const struct virtchnl2_rx_flex_desc_adv_nic_3 *rxd)
164+
{
165+
#ifdef __LIBETH_WORD_ACCESS
166+
desc->qw2 = ((const typeof(desc))rxd)->qw2;
167+
#else
168+
desc->qw2 = ((u64)rxd->hash3 << 24) |
169+
((u64)rxd->ff2_mirrid_hash2.hash2 << 16) |
170+
le16_to_cpu(rxd->hash1);
171+
#endif
172+
}
173+
110174
void idpf_xdp_set_features(const struct idpf_vport *vport);
111175

112176
int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp);

0 commit comments

Comments
 (0)