1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
4 #include <linux/debugfs.h>
5 #include <linux/mlx5/fs.h>
8 static int tirn_show(struct seq_file *file, void *priv)
10 struct mlx5_vdpa_net *ndev = file->private;
12 seq_printf(file, "0x%x\n", ndev->res.tirn);
16 DEFINE_SHOW_ATTRIBUTE(tirn);
18 void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev)
21 debugfs_remove(ndev->res.tirn_dent);
24 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev)
26 ndev->res.tirn_dent = debugfs_create_file("tirn", 0444, ndev->rx_dent,
30 static int rx_flow_table_show(struct seq_file *file, void *priv)
32 struct mlx5_vdpa_net *ndev = file->private;
34 seq_printf(file, "0x%x\n", mlx5_flow_table_id(ndev->rxft));
38 DEFINE_SHOW_ATTRIBUTE(rx_flow_table);
40 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev)
43 debugfs_remove(ndev->rx_table_dent);
46 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev)
48 ndev->rx_table_dent = debugfs_create_file("table_id", 0444, ndev->rx_dent,
49 ndev, &rx_flow_table_fops);
52 #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
53 static int packets_show(struct seq_file *file, void *priv)
55 struct mlx5_vdpa_counter *counter = file->private;
60 err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
64 seq_printf(file, "0x%llx\n", packets);
68 static int bytes_show(struct seq_file *file, void *priv)
70 struct mlx5_vdpa_counter *counter = file->private;
75 err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
79 seq_printf(file, "0x%llx\n", bytes);
83 DEFINE_SHOW_ATTRIBUTE(packets);
84 DEFINE_SHOW_ATTRIBUTE(bytes);
86 static void add_counter_node(struct mlx5_vdpa_counter *counter,
87 struct dentry *parent)
89 debugfs_create_file("packets", 0444, parent, counter,
91 debugfs_create_file("bytes", 0444, parent, counter,
95 void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
96 struct macvlan_node *node)
98 static const char *ut = "untagged";
102 node->ucast_counter.mdev = ndev->mvdev.mdev;
103 node->mcast_counter.mdev = ndev->mvdev.mdev;
105 vid = key2vid(node->macvlan);
106 snprintf(vidstr, sizeof(vidstr), "0x%x", vid);
111 node->dent = debugfs_create_dir(vidstr, ndev->rx_dent);
112 if (IS_ERR(node->dent)) {
117 node->ucast_counter.dent = debugfs_create_dir("ucast", node->dent);
118 if (IS_ERR(node->ucast_counter.dent))
121 add_counter_node(&node->ucast_counter, node->ucast_counter.dent);
123 node->mcast_counter.dent = debugfs_create_dir("mcast", node->dent);
124 if (IS_ERR(node->mcast_counter.dent))
127 add_counter_node(&node->mcast_counter, node->mcast_counter.dent);
130 void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
131 struct macvlan_node *node)
133 if (node->dent && ndev->debugfs)
134 debugfs_remove_recursive(node->dent);
138 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
140 struct mlx5_core_dev *mdev;
142 mdev = ndev->mvdev.mdev;
143 ndev->debugfs = debugfs_create_dir(dev_name(&ndev->mvdev.vdev.dev),
144 mlx5_debugfs_get_dev_root(mdev));
145 if (!IS_ERR(ndev->debugfs))
146 ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
149 void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev)
151 debugfs_remove_recursive(ndev->debugfs);
152 ndev->debugfs = NULL;