Skip to content

Commit

Permalink
net/mlx5e: TC, Handle sampled packets
Browse files Browse the repository at this point in the history
Mark the sampled packets with a sample restore object. Send sampled
packets using the psample api.

Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Oz Shlomo <ozsh@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Chris Mi authored and Saeed Mahameed committed Apr 7, 2021
1 parent 7319a1c commit be9dc00
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "en/mapping.h"
#include "en/tc_tun.h"
#include "lib/port_tun.h"
#include "esw/sample.h"

struct mlx5e_rep_indr_block_priv {
struct net_device *netdev;
Expand Down Expand Up @@ -675,13 +676,20 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe,
}

#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);
} 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);
return false;
}
#endif /* CONFIG_NET_TC_SKB_EXT */

return true;
}
Expand Down
15 changes: 15 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
mlx5_esw_sample_init(struct mlx5e_priv *priv)
{
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#define __MLX5_EN_TC_SAMPLE_H__

#include "en.h"
#include "eswitch.h"

struct mlx5_sample_attr {
u32 group_num;
u32 rate;
u32 trunc_size;
};

void mlx5_esw_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj);

struct mlx5_esw_psample *
mlx5_esw_sample_init(struct mlx5e_priv *priv);

Expand Down
6 changes: 6 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@

enum mlx5_mapped_obj_type {
MLX5_MAPPED_OBJ_CHAIN,
MLX5_MAPPED_OBJ_SAMPLE,
};

struct mlx5_mapped_obj {
enum mlx5_mapped_obj_type type;
union {
u32 chain;
struct {
u32 group_id;
u32 rate;
u32 trunc_size;
} sample;
};
};

Expand Down

0 comments on commit be9dc00

Please sign in to comment.