xref: /linux/drivers/vdpa/mlx5/net/debug.c (revision 0a59975088d37f69815f656193c1e1e057feb494)
129422100SEli Cohen // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
229422100SEli Cohen /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
329422100SEli Cohen 
429422100SEli Cohen #include <linux/debugfs.h>
529422100SEli Cohen #include <linux/mlx5/fs.h>
629422100SEli Cohen #include "mlx5_vnet.h"
729422100SEli Cohen 
829422100SEli Cohen static int tirn_show(struct seq_file *file, void *priv)
929422100SEli Cohen {
1029422100SEli Cohen 	struct mlx5_vdpa_net *ndev = file->private;
1129422100SEli Cohen 
1229422100SEli Cohen 	seq_printf(file, "0x%x\n", ndev->res.tirn);
1329422100SEli Cohen 	return 0;
1429422100SEli Cohen }
1529422100SEli Cohen 
1629422100SEli Cohen DEFINE_SHOW_ATTRIBUTE(tirn);
1729422100SEli Cohen 
1829422100SEli Cohen void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev)
1929422100SEli Cohen {
2029422100SEli Cohen 	if (ndev->debugfs)
2129422100SEli Cohen 		debugfs_remove(ndev->res.tirn_dent);
2229422100SEli Cohen }
2329422100SEli Cohen 
2429422100SEli Cohen void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev)
2529422100SEli Cohen {
2629422100SEli Cohen 	ndev->res.tirn_dent = debugfs_create_file("tirn", 0444, ndev->rx_dent,
2729422100SEli Cohen 						  ndev, &tirn_fops);
2829422100SEli Cohen }
2929422100SEli Cohen 
3029422100SEli Cohen static int rx_flow_table_show(struct seq_file *file, void *priv)
3129422100SEli Cohen {
3229422100SEli Cohen 	struct mlx5_vdpa_net *ndev = file->private;
3329422100SEli Cohen 
3429422100SEli Cohen 	seq_printf(file, "0x%x\n", mlx5_flow_table_id(ndev->rxft));
3529422100SEli Cohen 	return 0;
3629422100SEli Cohen }
3729422100SEli Cohen 
3829422100SEli Cohen DEFINE_SHOW_ATTRIBUTE(rx_flow_table);
3929422100SEli Cohen 
4029422100SEli Cohen void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev)
4129422100SEli Cohen {
4229422100SEli Cohen 	if (ndev->debugfs)
4329422100SEli Cohen 		debugfs_remove(ndev->rx_table_dent);
4429422100SEli Cohen }
4529422100SEli Cohen 
4629422100SEli Cohen void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev)
4729422100SEli Cohen {
4829422100SEli Cohen 	ndev->rx_table_dent = debugfs_create_file("table_id", 0444, ndev->rx_dent,
4929422100SEli Cohen 						  ndev, &rx_flow_table_fops);
5029422100SEli Cohen }
5129422100SEli Cohen 
52*0a599750SEli Cohen #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
53*0a599750SEli Cohen static int packets_show(struct seq_file *file, void *priv)
54*0a599750SEli Cohen {
55*0a599750SEli Cohen 	struct mlx5_vdpa_counter *counter = file->private;
56*0a599750SEli Cohen 	u64 packets;
57*0a599750SEli Cohen 	u64 bytes;
58*0a599750SEli Cohen 	int err;
59*0a599750SEli Cohen 
60*0a599750SEli Cohen 	err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
61*0a599750SEli Cohen 	if (err)
62*0a599750SEli Cohen 		return err;
63*0a599750SEli Cohen 
64*0a599750SEli Cohen 	seq_printf(file, "0x%llx\n", packets);
65*0a599750SEli Cohen 	return 0;
66*0a599750SEli Cohen }
67*0a599750SEli Cohen 
68*0a599750SEli Cohen static int bytes_show(struct seq_file *file, void *priv)
69*0a599750SEli Cohen {
70*0a599750SEli Cohen 	struct mlx5_vdpa_counter *counter = file->private;
71*0a599750SEli Cohen 	u64 packets;
72*0a599750SEli Cohen 	u64 bytes;
73*0a599750SEli Cohen 	int err;
74*0a599750SEli Cohen 
75*0a599750SEli Cohen 	err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
76*0a599750SEli Cohen 	if (err)
77*0a599750SEli Cohen 		return err;
78*0a599750SEli Cohen 
79*0a599750SEli Cohen 	seq_printf(file, "0x%llx\n", bytes);
80*0a599750SEli Cohen 	return 0;
81*0a599750SEli Cohen }
82*0a599750SEli Cohen 
83*0a599750SEli Cohen DEFINE_SHOW_ATTRIBUTE(packets);
84*0a599750SEli Cohen DEFINE_SHOW_ATTRIBUTE(bytes);
85*0a599750SEli Cohen 
86*0a599750SEli Cohen static void add_counter_node(struct mlx5_vdpa_counter *counter,
87*0a599750SEli Cohen 			     struct dentry *parent)
88*0a599750SEli Cohen {
89*0a599750SEli Cohen 	debugfs_create_file("packets", 0444, parent, counter,
90*0a599750SEli Cohen 			    &packets_fops);
91*0a599750SEli Cohen 	debugfs_create_file("bytes", 0444, parent, counter,
92*0a599750SEli Cohen 			    &bytes_fops);
93*0a599750SEli Cohen }
94*0a599750SEli Cohen 
95*0a599750SEli Cohen void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
96*0a599750SEli Cohen 			       struct macvlan_node *node)
97*0a599750SEli Cohen {
98*0a599750SEli Cohen 	static const char *ut = "untagged";
99*0a599750SEli Cohen 	char vidstr[9];
100*0a599750SEli Cohen 	u16 vid;
101*0a599750SEli Cohen 
102*0a599750SEli Cohen 	node->ucast_counter.mdev = ndev->mvdev.mdev;
103*0a599750SEli Cohen 	node->mcast_counter.mdev = ndev->mvdev.mdev;
104*0a599750SEli Cohen 	if (node->tagged) {
105*0a599750SEli Cohen 		vid = key2vid(node->macvlan);
106*0a599750SEli Cohen 		snprintf(vidstr, sizeof(vidstr), "0x%x", vid);
107*0a599750SEli Cohen 	} else {
108*0a599750SEli Cohen 		strcpy(vidstr, ut);
109*0a599750SEli Cohen 	}
110*0a599750SEli Cohen 
111*0a599750SEli Cohen 	node->dent = debugfs_create_dir(vidstr, ndev->rx_dent);
112*0a599750SEli Cohen 	if (IS_ERR(node->dent)) {
113*0a599750SEli Cohen 		node->dent = NULL;
114*0a599750SEli Cohen 		return;
115*0a599750SEli Cohen 	}
116*0a599750SEli Cohen 
117*0a599750SEli Cohen 	node->ucast_counter.dent = debugfs_create_dir("ucast", node->dent);
118*0a599750SEli Cohen 	if (IS_ERR(node->ucast_counter.dent))
119*0a599750SEli Cohen 		return;
120*0a599750SEli Cohen 
121*0a599750SEli Cohen 	add_counter_node(&node->ucast_counter, node->ucast_counter.dent);
122*0a599750SEli Cohen 
123*0a599750SEli Cohen 	node->mcast_counter.dent = debugfs_create_dir("mcast", node->dent);
124*0a599750SEli Cohen 	if (IS_ERR(node->mcast_counter.dent))
125*0a599750SEli Cohen 		return;
126*0a599750SEli Cohen 
127*0a599750SEli Cohen 	add_counter_node(&node->mcast_counter, node->mcast_counter.dent);
128*0a599750SEli Cohen }
129*0a599750SEli Cohen 
130*0a599750SEli Cohen void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
131*0a599750SEli Cohen 				  struct macvlan_node *node)
132*0a599750SEli Cohen {
133*0a599750SEli Cohen 	if (node->dent && ndev->debugfs)
134*0a599750SEli Cohen 		debugfs_remove_recursive(node->dent);
135*0a599750SEli Cohen }
136*0a599750SEli Cohen #endif
137*0a599750SEli Cohen 
13829422100SEli Cohen void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
13929422100SEli Cohen {
14029422100SEli Cohen 	struct mlx5_core_dev *mdev;
14129422100SEli Cohen 
14229422100SEli Cohen 	mdev = ndev->mvdev.mdev;
14329422100SEli Cohen 	ndev->debugfs = debugfs_create_dir(dev_name(&ndev->mvdev.vdev.dev),
14429422100SEli Cohen 					   mlx5_debugfs_get_dev_root(mdev));
14529422100SEli Cohen 	if (!IS_ERR(ndev->debugfs))
14629422100SEli Cohen 		ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
14729422100SEli Cohen }
14829422100SEli Cohen 
14929422100SEli Cohen void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
15029422100SEli Cohen {
15129422100SEli Cohen 	debugfs_remove_recursive(dbg);
15229422100SEli Cohen }
153