Skip to content

Commit 0e41451

Browse files
gal-pressmanSaeed Mahameed
authored andcommitted
net/mlx5e: Add hairpin debugfs files
We refer to a TC NIC rule that involves forwarding as "hairpin". Hairpin queues are mlx5 hardware specific implementation for hardware forwarding of such packets. For debug purposes, introduce debugfs files which: * Expose the number of active hairpins * Dump the hairpin table * Allow control over the number and size of the hairpin queues instead of the hard-coded values. This allows us to get visibility of the feature in order to improve it for next generation hardware. Add debugfs files: fs/tc/hairpin_num_active fs/tc/hairpin_num_queues fs/tc/hairpin_queue_size fs/tc/hairpin_table_dump Note that the new values will only take effect on the next queues creation, it does not affect existing queues. Signed-off-by: Gal Pressman <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 3a3da78 commit 0e41451

File tree

1 file changed

+117
-0
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+117
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct mlx5e_tc_table {
100100
struct mlx5_tc_ct_priv *ct;
101101
struct mapping_ctx *mapping;
102102
struct mlx5e_hairpin_params hairpin_params;
103+
struct dentry *dfs_root;
103104
};
104105

105106
struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = {
@@ -1023,6 +1024,118 @@ static int mlx5e_hairpin_get_prio(struct mlx5e_priv *priv,
10231024
return 0;
10241025
}
10251026

1027+
static int debugfs_hairpin_queues_set(void *data, u64 val)
1028+
{
1029+
struct mlx5e_hairpin_params *hp = data;
1030+
1031+
if (!val) {
1032+
mlx5_core_err(hp->mdev,
1033+
"Number of hairpin queues must be > 0\n");
1034+
return -EINVAL;
1035+
}
1036+
1037+
hp->num_queues = val;
1038+
1039+
return 0;
1040+
}
1041+
1042+
static int debugfs_hairpin_queues_get(void *data, u64 *val)
1043+
{
1044+
struct mlx5e_hairpin_params *hp = data;
1045+
1046+
*val = hp->num_queues;
1047+
1048+
return 0;
1049+
}
1050+
DEFINE_DEBUGFS_ATTRIBUTE(fops_hairpin_queues, debugfs_hairpin_queues_get,
1051+
debugfs_hairpin_queues_set, "%llu\n");
1052+
1053+
static int debugfs_hairpin_queue_size_set(void *data, u64 val)
1054+
{
1055+
struct mlx5e_hairpin_params *hp = data;
1056+
1057+
if (val > BIT(MLX5_CAP_GEN(hp->mdev, log_max_hairpin_num_packets))) {
1058+
mlx5_core_err(hp->mdev,
1059+
"Invalid hairpin queue size, must be <= %lu\n",
1060+
BIT(MLX5_CAP_GEN(hp->mdev,
1061+
log_max_hairpin_num_packets)));
1062+
return -EINVAL;
1063+
}
1064+
1065+
hp->queue_size = roundup_pow_of_two(val);
1066+
1067+
return 0;
1068+
}
1069+
1070+
static int debugfs_hairpin_queue_size_get(void *data, u64 *val)
1071+
{
1072+
struct mlx5e_hairpin_params *hp = data;
1073+
1074+
*val = hp->queue_size;
1075+
1076+
return 0;
1077+
}
1078+
DEFINE_DEBUGFS_ATTRIBUTE(fops_hairpin_queue_size,
1079+
debugfs_hairpin_queue_size_get,
1080+
debugfs_hairpin_queue_size_set, "%llu\n");
1081+
1082+
static int debugfs_hairpin_num_active_get(void *data, u64 *val)
1083+
{
1084+
struct mlx5e_tc_table *tc = data;
1085+
struct mlx5e_hairpin_entry *hpe;
1086+
u32 cnt = 0;
1087+
u32 bkt;
1088+
1089+
mutex_lock(&tc->hairpin_tbl_lock);
1090+
hash_for_each(tc->hairpin_tbl, bkt, hpe, hairpin_hlist)
1091+
cnt++;
1092+
mutex_unlock(&tc->hairpin_tbl_lock);
1093+
1094+
*val = cnt;
1095+
1096+
return 0;
1097+
}
1098+
DEFINE_DEBUGFS_ATTRIBUTE(fops_hairpin_num_active,
1099+
debugfs_hairpin_num_active_get, NULL, "%llu\n");
1100+
1101+
static int debugfs_hairpin_table_dump_show(struct seq_file *file, void *priv)
1102+
1103+
{
1104+
struct mlx5e_tc_table *tc = file->private;
1105+
struct mlx5e_hairpin_entry *hpe;
1106+
u32 bkt;
1107+
1108+
mutex_lock(&tc->hairpin_tbl_lock);
1109+
hash_for_each(tc->hairpin_tbl, bkt, hpe, hairpin_hlist)
1110+
seq_printf(file, "Hairpin peer_vhca_id %u prio %u refcnt %u\n",
1111+
hpe->peer_vhca_id, hpe->prio,
1112+
refcount_read(&hpe->refcnt));
1113+
mutex_unlock(&tc->hairpin_tbl_lock);
1114+
1115+
return 0;
1116+
}
1117+
DEFINE_SHOW_ATTRIBUTE(debugfs_hairpin_table_dump);
1118+
1119+
static void mlx5e_tc_debugfs_init(struct mlx5e_tc_table *tc,
1120+
struct dentry *dfs_root)
1121+
{
1122+
if (IS_ERR_OR_NULL(dfs_root))
1123+
return;
1124+
1125+
tc->dfs_root = debugfs_create_dir("tc", dfs_root);
1126+
if (!tc->dfs_root)
1127+
return;
1128+
1129+
debugfs_create_file("hairpin_num_queues", 0644, tc->dfs_root,
1130+
&tc->hairpin_params, &fops_hairpin_queues);
1131+
debugfs_create_file("hairpin_queue_size", 0644, tc->dfs_root,
1132+
&tc->hairpin_params, &fops_hairpin_queue_size);
1133+
debugfs_create_file("hairpin_num_active", 0444, tc->dfs_root, tc,
1134+
&fops_hairpin_num_active);
1135+
debugfs_create_file("hairpin_table_dump", 0444, tc->dfs_root, tc,
1136+
&debugfs_hairpin_table_dump_fops);
1137+
}
1138+
10261139
static void
10271140
mlx5e_hairpin_params_init(struct mlx5e_hairpin_params *hairpin_params,
10281141
struct mlx5_core_dev *mdev)
@@ -5249,6 +5362,8 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
52495362
goto err_reg;
52505363
}
52515364

5365+
mlx5e_tc_debugfs_init(tc, mlx5e_fs_get_debugfs_root(priv->fs));
5366+
52525367
return 0;
52535368

52545369
err_reg:
@@ -5277,6 +5392,8 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)
52775392
{
52785393
struct mlx5e_tc_table *tc = mlx5e_fs_get_tc(priv->fs);
52795394

5395+
debugfs_remove_recursive(tc->dfs_root);
5396+
52805397
if (tc->netdevice_nb.notifier_call)
52815398
unregister_netdevice_notifier_dev_net(priv->netdev,
52825399
&tc->netdevice_nb,

0 commit comments

Comments
 (0)