Commit be9dc004 authored by Chris Mi's avatar Chris Mi Committed by Saeed Mahameed

net/mlx5e: TC, Handle sampled packets

Mark the sampled packets with a sample restore object. Send sampled
packets using the psample api.
Signed-off-by: default avatarChris Mi <cmi@nvidia.com>
Reviewed-by: default avatarOz Shlomo <ozsh@nvidia.com>
Reviewed-by: default avatarMark Bloch <mbloch@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 7319a1cc
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "en/mapping.h" #include "en/mapping.h"
#include "en/tc_tun.h" #include "en/tc_tun.h"
#include "lib/port_tun.h" #include "lib/port_tun.h"
#include "esw/sample.h"
struct mlx5e_rep_indr_block_priv { struct mlx5e_rep_indr_block_priv {
struct net_device *netdev; struct net_device *netdev;
...@@ -675,13 +676,20 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, ...@@ -675,13 +676,20 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe,
} }
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
if (mapped_obj.type == MLX5_MAPPED_OBJ_CHAIN) { if (mapped_obj.type == MLX5_MAPPED_OBJ_CHAIN)
return mlx5e_restore_skb(skb, mapped_obj.chain, reg_c1, tc_priv); return mlx5e_restore_skb(skb, mapped_obj.chain, reg_c1, tc_priv);
} else { #endif /* CONFIG_NET_TC_SKB_EXT */
#if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE)
if (mapped_obj.type == MLX5_MAPPED_OBJ_SAMPLE) {
mlx5_esw_sample_skb(skb, &mapped_obj);
return false;
}
#endif /* CONFIG_MLX5_TC_SAMPLE */
if (mapped_obj.type != MLX5_MAPPED_OBJ_SAMPLE &&
mapped_obj.type != MLX5_MAPPED_OBJ_CHAIN) {
netdev_dbg(priv->netdev, "Invalid mapped object type: %d\n", mapped_obj.type); netdev_dbg(priv->netdev, "Invalid mapped object type: %d\n", mapped_obj.type);
return false; return false;
} }
#endif /* CONFIG_NET_TC_SKB_EXT */
return true; return true;
} }
......
...@@ -298,6 +298,21 @@ sample_restore_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sample_rest ...@@ -298,6 +298,21 @@ sample_restore_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sample_rest
} }
} }
void mlx5_esw_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj)
{
u32 trunc_size = mapped_obj->sample.trunc_size;
struct psample_group psample_group = {};
struct psample_metadata md = {};
md.trunc_size = trunc_size ? min(trunc_size, skb->len) : skb->len;
md.in_ifindex = skb->dev->ifindex;
psample_group.group_num = mapped_obj->sample.group_id;
psample_group.net = &init_net;
skb_push(skb, skb->mac_len);
psample_sample_packet(&psample_group, skb, mapped_obj->sample.rate, &md);
}
struct mlx5_esw_psample * struct mlx5_esw_psample *
mlx5_esw_sample_init(struct mlx5e_priv *priv) mlx5_esw_sample_init(struct mlx5e_priv *priv)
{ {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#define __MLX5_EN_TC_SAMPLE_H__ #define __MLX5_EN_TC_SAMPLE_H__
#include "en.h" #include "en.h"
#include "eswitch.h"
struct mlx5_sample_attr { struct mlx5_sample_attr {
u32 group_num; u32 group_num;
...@@ -12,6 +13,8 @@ struct mlx5_sample_attr { ...@@ -12,6 +13,8 @@ struct mlx5_sample_attr {
u32 trunc_size; u32 trunc_size;
}; };
void mlx5_esw_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj);
struct mlx5_esw_psample * struct mlx5_esw_psample *
mlx5_esw_sample_init(struct mlx5e_priv *priv); mlx5_esw_sample_init(struct mlx5e_priv *priv);
......
...@@ -50,12 +50,18 @@ ...@@ -50,12 +50,18 @@
enum mlx5_mapped_obj_type { enum mlx5_mapped_obj_type {
MLX5_MAPPED_OBJ_CHAIN, MLX5_MAPPED_OBJ_CHAIN,
MLX5_MAPPED_OBJ_SAMPLE,
}; };
struct mlx5_mapped_obj { struct mlx5_mapped_obj {
enum mlx5_mapped_obj_type type; enum mlx5_mapped_obj_type type;
union { union {
u32 chain; u32 chain;
struct {
u32 group_id;
u32 rate;
u32 trunc_size;
} sample;
}; };
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment