Skip to content

Commit 67f245c

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
mlx5: bpf_xdp_metadata_rx_hash add xdp rss hash type
Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type via mapping table. The mlx5 hardware can also identify and RSS hash IPSEC. This indicate hash includes SPI (Security Parameters Index) as part of IPSEC hash. Extend xdp core enum xdp_rss_hash_type with IPSEC hash type. Fixes: bc8d405 ("net/mlx5e: Support RX XDP metadata") Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/168132892548.340624.11185734579430124869.stgit@firesoul Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0cd917a commit 67f245c

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <net/xdp_sock_drv.h>
3535
#include "en/xdp.h"
3636
#include "en/params.h"
37+
#include <linux/bitfield.h>
3738

3839
int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param *xsk)
3940
{
@@ -169,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
169170
return 0;
170171
}
171172

173+
/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bits*/
174+
#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */
175+
#define RSS_L4 GENMASK(1, 0)
176+
#define RSS_L3 GENMASK(3, 2) /* Same as CQE_RSS_HTYPE_IP */
177+
178+
/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numerical */
179+
enum mlx5_rss_hash_type {
180+
RSS_TYPE_NO_HASH = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE) |
181+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
182+
RSS_TYPE_L3_IPV4 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
183+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
184+
RSS_TYPE_L4_IPV4_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
185+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
186+
RSS_TYPE_L4_IPV4_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
187+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
188+
RSS_TYPE_L4_IPV4_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
189+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
190+
RSS_TYPE_L3_IPV6 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
191+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
192+
RSS_TYPE_L4_IPV6_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
193+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
194+
RSS_TYPE_L4_IPV6_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
195+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
196+
RSS_TYPE_L4_IPV6_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
197+
FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
198+
};
199+
200+
/* Invalid combinations will simply return zero, allows no boundary checks */
201+
static const enum xdp_rss_hash_type mlx5_xdp_rss_type[RSS_TYPE_MAX_TABLE] = {
202+
[RSS_TYPE_NO_HASH] = XDP_RSS_TYPE_NONE,
203+
[1] = XDP_RSS_TYPE_NONE, /* Implicit zero */
204+
[2] = XDP_RSS_TYPE_NONE, /* Implicit zero */
205+
[3] = XDP_RSS_TYPE_NONE, /* Implicit zero */
206+
[RSS_TYPE_L3_IPV4] = XDP_RSS_TYPE_L3_IPV4,
207+
[RSS_TYPE_L4_IPV4_TCP] = XDP_RSS_TYPE_L4_IPV4_TCP,
208+
[RSS_TYPE_L4_IPV4_UDP] = XDP_RSS_TYPE_L4_IPV4_UDP,
209+
[RSS_TYPE_L4_IPV4_IPSEC] = XDP_RSS_TYPE_L4_IPV4_IPSEC,
210+
[RSS_TYPE_L3_IPV6] = XDP_RSS_TYPE_L3_IPV6,
211+
[RSS_TYPE_L4_IPV6_TCP] = XDP_RSS_TYPE_L4_IPV6_TCP,
212+
[RSS_TYPE_L4_IPV6_UDP] = XDP_RSS_TYPE_L4_IPV6_UDP,
213+
[RSS_TYPE_L4_IPV6_IPSEC] = XDP_RSS_TYPE_L4_IPV6_IPSEC,
214+
[12] = XDP_RSS_TYPE_NONE, /* Implicit zero */
215+
[13] = XDP_RSS_TYPE_NONE, /* Implicit zero */
216+
[14] = XDP_RSS_TYPE_NONE, /* Implicit zero */
217+
[15] = XDP_RSS_TYPE_NONE, /* Implicit zero */
218+
};
219+
172220
static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
173221
enum xdp_rss_hash_type *rss_type)
174222
{
175223
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
224+
const struct mlx5_cqe64 *cqe = _ctx->cqe;
225+
u32 hash_type, l4_type, ip_type, lookup;
176226

177227
if (unlikely(!(_ctx->xdp.rxq->dev->features & NETIF_F_RXHASH)))
178228
return -ENODATA;
179229

180-
*hash = be32_to_cpu(_ctx->cqe->rss_hash_result);
230+
*hash = be32_to_cpu(cqe->rss_hash_result);
231+
232+
hash_type = cqe->rss_hash_type;
233+
BUILD_BUG_ON(CQE_RSS_HTYPE_IP != RSS_L3); /* same mask */
234+
ip_type = hash_type & CQE_RSS_HTYPE_IP;
235+
l4_type = FIELD_GET(CQE_RSS_HTYPE_L4, hash_type);
236+
lookup = ip_type | l4_type;
237+
*rss_type = mlx5_xdp_rss_type[lookup];
238+
181239
return 0;
182240
}
183241

include/linux/mlx5/device.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/types.h>
3737
#include <rdma/ib_verbs.h>
3838
#include <linux/mlx5/mlx5_ifc.h>
39+
#include <linux/bitfield.h>
3940

4041
#if defined(__LITTLE_ENDIAN)
4142
#define MLX5_SET_HOST_ENDIANNESS 0
@@ -980,14 +981,23 @@ enum {
980981
};
981982

982983
enum {
983-
CQE_RSS_HTYPE_IP = 0x3 << 2,
984+
CQE_RSS_HTYPE_IP = GENMASK(3, 2),
984985
/* cqe->rss_hash_type[3:2] - IP destination selected for hash
985986
* (00 = none, 01 = IPv4, 10 = IPv6, 11 = Reserved)
986987
*/
987-
CQE_RSS_HTYPE_L4 = 0x3 << 6,
988+
CQE_RSS_IP_NONE = 0x0,
989+
CQE_RSS_IPV4 = 0x1,
990+
CQE_RSS_IPV6 = 0x2,
991+
CQE_RSS_RESERVED = 0x3,
992+
993+
CQE_RSS_HTYPE_L4 = GENMASK(7, 6),
988994
/* cqe->rss_hash_type[7:6] - L4 destination selected for hash
989995
* (00 = none, 01 = TCP. 10 = UDP, 11 = IPSEC.SPI
990996
*/
997+
CQE_RSS_L4_NONE = 0x0,
998+
CQE_RSS_L4_TCP = 0x1,
999+
CQE_RSS_L4_UDP = 0x2,
1000+
CQE_RSS_L4_IPSEC = 0x3,
9911001
};
9921002

9931003
enum {

include/net/xdp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,12 @@ enum xdp_rss_hash_type {
460460
XDP_RSS_TYPE_L4_IPV4_TCP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
461461
XDP_RSS_TYPE_L4_IPV4_UDP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
462462
XDP_RSS_TYPE_L4_IPV4_SCTP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
463+
XDP_RSS_TYPE_L4_IPV4_IPSEC = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
463464

464465
XDP_RSS_TYPE_L4_IPV6_TCP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
465466
XDP_RSS_TYPE_L4_IPV6_UDP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
466467
XDP_RSS_TYPE_L4_IPV6_SCTP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
468+
XDP_RSS_TYPE_L4_IPV6_IPSEC = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
467469

468470
XDP_RSS_TYPE_L4_IPV6_TCP_EX = XDP_RSS_TYPE_L4_IPV6_TCP | XDP_RSS_L3_DYNHDR,
469471
XDP_RSS_TYPE_L4_IPV6_UDP_EX = XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_DYNHDR,

0 commit comments

Comments
 (0)