[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180627024615.17856-6-saeedm@mellanox.com>
Date: Tue, 26 Jun 2018 19:46:14 -0700
From: Saeed Mahameed <saeedm@....mellanox.co.il>
To: Jesper Dangaard Brouer <brouer@...hat.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
Daniel Borkmann <borkmann@...earbox.net>
Cc: neerav.parikh@...el.com, pjwaskiewicz@...il.com,
ttoukan.linux@...il.com, Tariq Toukan <tariqt@...lanox.com>,
alexander.h.duyck@...el.com, peter.waskiewicz.jr@...el.com,
Opher Reviv <opher@...lanox.com>,
Rony Efraim <ronye@...lanox.com>, netdev@...r.kernel.org,
Saeed Mahameed <saeedm@...lanox.com>
Subject: [RFC bpf-next 5/6] net/mlx5e: Add XDP RX meta data support
Implement XDP meta data hash and vlan support.
1. on xdp setup ndo: add support for XDP_QUERY_META_FLAGS and return the
two supported flags
2. use xdp_data_meta_set_hash and xdp_data_meta_set_vlan helpers to fill
in the meta data fileds.
Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
---
.../net/ethernet/mellanox/mlx5/core/en_main.c | 6 ++++
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 30 ++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 8debae6b9cab..3d1066a953cb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -4189,6 +4189,9 @@ static u32 mlx5e_xdp_query(struct net_device *dev)
return prog_id;
}
+#define MLX5E_SUPPORTED_XDP_META_FLAGS \
+ (XDP_FLAGS_META_HASH | XDP_FLAGS_META_VLAN)
+
static int mlx5e_xdp(struct net_device *dev, struct netdev_bpf *xdp)
{
struct mlx5e_xdp_info xdp_info;
@@ -4204,6 +4207,9 @@ static int mlx5e_xdp(struct net_device *dev, struct netdev_bpf *xdp)
xdp->prog_id = mlx5e_xdp_query(dev);
xdp->prog_attached = !!xdp->prog_id;
return 0;
+ case XDP_QUERY_META_FLAGS:
+ xdp->meta_flags = MLX5E_SUPPORTED_XDP_META_FLAGS;
+ return 0;
default:
return -EINVAL;
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index e37f9747a0e3..1f3e934d0dd8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -920,6 +920,29 @@ static inline bool mlx5e_xmit_xdp_frame(struct mlx5e_rq *rq,
return true;
}
+static void
+mlx5e_xdp_fill_data_meta(xdp_md_info_arr mdi, void *data_meta, struct mlx5_cqe64 *cqe)
+{
+ if (xdp_data_meta_present(mdi, XDP_DATA_META_HASH))
+ {
+ u8 cht = cqe->rss_hash_type;
+ int ht = (cht & CQE_RSS_HTYPE_L4) ? PKT_HASH_TYPE_L4 :
+ (cht & CQE_RSS_HTYPE_IP) ? PKT_HASH_TYPE_L3 :
+ PKT_HASH_TYPE_NONE;
+ u32 hash = be32_to_cpu(cqe->rss_hash_result);
+
+ xdp_data_meta_set_hash(mdi, data_meta, hash, ht);
+ }
+
+ if (xdp_data_meta_present(mdi, XDP_DATA_META_VLAN))
+ {
+ u16 vlan = (!!cqe_has_vlan(cqe) * VLAN_TAG_PRESENT) |
+ be16_to_cpu(cqe->vlan_info);
+
+ xdp_data_meta_set_vlan(mdi, data_meta, vlan);
+ }
+}
+
/* returns true if packet was consumed by xdp */
static inline bool mlx5e_xdp_handle(struct mlx5e_rq *rq,
struct mlx5e_dma_info *di,
@@ -935,11 +958,16 @@ static inline bool mlx5e_xdp_handle(struct mlx5e_rq *rq,
return false;
xdp.data = va + *rx_headroom;
- xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + *len;
xdp.data_hard_start = va;
xdp.rxq = &rq->xdp_rxq;
+ if (rq->xdp.flags & XDP_FLAGS_META_ALL) {
+ xdp_reset_data_meta(&xdp);
+ mlx5e_xdp_fill_data_meta(rq->xdp.md_info, xdp.data_meta, cqe);
+ } else
+ xdp_set_data_meta_invalid(&xdp);
+
act = bpf_prog_run_xdp(prog, &xdp);
switch (act) {
case XDP_PASS:
--
2.17.0
Powered by blists - more mailing lists