xref: /openbmc/linux/drivers/vdpa/mlx5/net/debug.c (revision e724e7aa)
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #include <linux/debugfs.h>
5 #include <linux/mlx5/fs.h>
6 #include "mlx5_vnet.h"
7 
8 static int tirn_show(struct seq_file *file, void *priv)
9 {
10 	struct mlx5_vdpa_net *ndev = file->private;
11 
12 	seq_printf(file, "0x%x\n", ndev->res.tirn);
13 	return 0;
14 }
15 
16 DEFINE_SHOW_ATTRIBUTE(tirn);
17 
18 void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev)
19 {
20 	if (ndev->debugfs)
21 		debugfs_remove(ndev->res.tirn_dent);
22 }
23 
24 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev)
25 {
26 	ndev->res.tirn_dent = debugfs_create_file("tirn", 0444, ndev->rx_dent,
27 						  ndev, &tirn_fops);
28 }
29 
30 static int rx_flow_table_show(struct seq_file *file, void *priv)
31 {
32 	struct mlx5_vdpa_net *ndev = file->private;
33 
34 	seq_printf(file, "0x%x\n", mlx5_flow_table_id(ndev->rxft));
35 	return 0;
36 }
37 
38 DEFINE_SHOW_ATTRIBUTE(rx_flow_table);
39 
40 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev)
41 {
42 	if (ndev->debugfs)
43 		debugfs_remove(ndev->rx_table_dent);
44 }
45 
46 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev)
47 {
48 	ndev->rx_table_dent = debugfs_create_file("table_id", 0444, ndev->rx_dent,
49 						  ndev, &rx_flow_table_fops);
50 }
51 
52 #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
53 static int packets_show(struct seq_file *file, void *priv)
54 {
55 	struct mlx5_vdpa_counter *counter = file->private;
56 	u64 packets;
57 	u64 bytes;
58 	int err;
59 
60 	err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
61 	if (err)
62 		return err;
63 
64 	seq_printf(file, "0x%llx\n", packets);
65 	return 0;
66 }
67 
68 static int bytes_show(struct seq_file *file, void *priv)
69 {
70 	struct mlx5_vdpa_counter *counter = file->private;
71 	u64 packets;
72 	u64 bytes;
73 	int err;
74 
75 	err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
76 	if (err)
77 		return err;
78 
79 	seq_printf(file, "0x%llx\n", bytes);
80 	return 0;
81 }
82 
83 DEFINE_SHOW_ATTRIBUTE(packets);
84 DEFINE_SHOW_ATTRIBUTE(bytes);
85 
86 static void add_counter_node(struct mlx5_vdpa_counter *counter,
87 			     struct dentry *parent)
88 {
89 	debugfs_create_file("packets", 0444, parent, counter,
90 			    &packets_fops);
91 	debugfs_create_file("bytes", 0444, parent, counter,
92 			    &bytes_fops);
93 }
94 
95 void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
96 			       struct macvlan_node *node)
97 {
98 	static const char *ut = "untagged";
99 	char vidstr[9];
100 	u16 vid;
101 
102 	node->ucast_counter.mdev = ndev->mvdev.mdev;
103 	node->mcast_counter.mdev = ndev->mvdev.mdev;
104 	if (node->tagged) {
105 		vid = key2vid(node->macvlan);
106 		snprintf(vidstr, sizeof(vidstr), "0x%x", vid);
107 	} else {
108 		strcpy(vidstr, ut);
109 	}
110 
111 	node->dent = debugfs_create_dir(vidstr, ndev->rx_dent);
112 	if (IS_ERR(node->dent)) {
113 		node->dent = NULL;
114 		return;
115 	}
116 
117 	node->ucast_counter.dent = debugfs_create_dir("ucast", node->dent);
118 	if (IS_ERR(node->ucast_counter.dent))
119 		return;
120 
121 	add_counter_node(&node->ucast_counter, node->ucast_counter.dent);
122 
123 	node->mcast_counter.dent = debugfs_create_dir("mcast", node->dent);
124 	if (IS_ERR(node->mcast_counter.dent))
125 		return;
126 
127 	add_counter_node(&node->mcast_counter, node->mcast_counter.dent);
128 }
129 
130 void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
131 				  struct macvlan_node *node)
132 {
133 	if (node->dent && ndev->debugfs)
134 		debugfs_remove_recursive(node->dent);
135 }
136 #endif
137 
138 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
139 {
140 	struct mlx5_core_dev *mdev;
141 
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);
147 }
148 
149 void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
150 {
151 	debugfs_remove_recursive(dbg);
152 }
153