xref: /openbmc/linux/drivers/vdpa/pds/debugfs.c (revision f77d1a49)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2023 Advanced Micro Devices, Inc */
3 
4 #include <linux/pci.h>
5 #include <linux/vdpa.h>
6 
7 #include <linux/pds/pds_common.h>
8 #include <linux/pds/pds_core_if.h>
9 #include <linux/pds/pds_adminq.h>
10 #include <linux/pds/pds_auxbus.h>
11 
12 #include "aux_drv.h"
13 #include "vdpa_dev.h"
14 #include "debugfs.h"
15 
16 static struct dentry *dbfs_dir;
17 
18 void pds_vdpa_debugfs_create(void)
19 {
20 	dbfs_dir = debugfs_create_dir(PDS_VDPA_DRV_NAME, NULL);
21 }
22 
23 void pds_vdpa_debugfs_destroy(void)
24 {
25 	debugfs_remove_recursive(dbfs_dir);
26 	dbfs_dir = NULL;
27 }
28 
29 #define PRINT_SBIT_NAME(__seq, __f, __name)                     \
30 	do {                                                    \
31 		if ((__f) & (__name))                               \
32 			seq_printf(__seq, " %s", &#__name[16]); \
33 	} while (0)
34 
35 static void print_status_bits(struct seq_file *seq, u8 status)
36 {
37 	seq_puts(seq, "status:");
38 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_ACKNOWLEDGE);
39 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_DRIVER);
40 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_DRIVER_OK);
41 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_FEATURES_OK);
42 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_NEEDS_RESET);
43 	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_FAILED);
44 	seq_puts(seq, "\n");
45 }
46 
47 static void print_feature_bits_all(struct seq_file *seq, u64 features)
48 {
49 	int i;
50 
51 	seq_puts(seq, "features:");
52 
53 	for (i = 0; i < (sizeof(u64) * 8); i++) {
54 		u64 mask = BIT_ULL(i);
55 
56 		switch (features & mask) {
57 		case BIT_ULL(VIRTIO_NET_F_CSUM):
58 			seq_puts(seq, " VIRTIO_NET_F_CSUM");
59 			break;
60 		case BIT_ULL(VIRTIO_NET_F_GUEST_CSUM):
61 			seq_puts(seq, " VIRTIO_NET_F_GUEST_CSUM");
62 			break;
63 		case BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS):
64 			seq_puts(seq, " VIRTIO_NET_F_CTRL_GUEST_OFFLOADS");
65 			break;
66 		case BIT_ULL(VIRTIO_NET_F_MTU):
67 			seq_puts(seq, " VIRTIO_NET_F_MTU");
68 			break;
69 		case BIT_ULL(VIRTIO_NET_F_MAC):
70 			seq_puts(seq, " VIRTIO_NET_F_MAC");
71 			break;
72 		case BIT_ULL(VIRTIO_NET_F_GUEST_TSO4):
73 			seq_puts(seq, " VIRTIO_NET_F_GUEST_TSO4");
74 			break;
75 		case BIT_ULL(VIRTIO_NET_F_GUEST_TSO6):
76 			seq_puts(seq, " VIRTIO_NET_F_GUEST_TSO6");
77 			break;
78 		case BIT_ULL(VIRTIO_NET_F_GUEST_ECN):
79 			seq_puts(seq, " VIRTIO_NET_F_GUEST_ECN");
80 			break;
81 		case BIT_ULL(VIRTIO_NET_F_GUEST_UFO):
82 			seq_puts(seq, " VIRTIO_NET_F_GUEST_UFO");
83 			break;
84 		case BIT_ULL(VIRTIO_NET_F_HOST_TSO4):
85 			seq_puts(seq, " VIRTIO_NET_F_HOST_TSO4");
86 			break;
87 		case BIT_ULL(VIRTIO_NET_F_HOST_TSO6):
88 			seq_puts(seq, " VIRTIO_NET_F_HOST_TSO6");
89 			break;
90 		case BIT_ULL(VIRTIO_NET_F_HOST_ECN):
91 			seq_puts(seq, " VIRTIO_NET_F_HOST_ECN");
92 			break;
93 		case BIT_ULL(VIRTIO_NET_F_HOST_UFO):
94 			seq_puts(seq, " VIRTIO_NET_F_HOST_UFO");
95 			break;
96 		case BIT_ULL(VIRTIO_NET_F_MRG_RXBUF):
97 			seq_puts(seq, " VIRTIO_NET_F_MRG_RXBUF");
98 			break;
99 		case BIT_ULL(VIRTIO_NET_F_STATUS):
100 			seq_puts(seq, " VIRTIO_NET_F_STATUS");
101 			break;
102 		case BIT_ULL(VIRTIO_NET_F_CTRL_VQ):
103 			seq_puts(seq, " VIRTIO_NET_F_CTRL_VQ");
104 			break;
105 		case BIT_ULL(VIRTIO_NET_F_CTRL_RX):
106 			seq_puts(seq, " VIRTIO_NET_F_CTRL_RX");
107 			break;
108 		case BIT_ULL(VIRTIO_NET_F_CTRL_VLAN):
109 			seq_puts(seq, " VIRTIO_NET_F_CTRL_VLAN");
110 			break;
111 		case BIT_ULL(VIRTIO_NET_F_CTRL_RX_EXTRA):
112 			seq_puts(seq, " VIRTIO_NET_F_CTRL_RX_EXTRA");
113 			break;
114 		case BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE):
115 			seq_puts(seq, " VIRTIO_NET_F_GUEST_ANNOUNCE");
116 			break;
117 		case BIT_ULL(VIRTIO_NET_F_MQ):
118 			seq_puts(seq, " VIRTIO_NET_F_MQ");
119 			break;
120 		case BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR):
121 			seq_puts(seq, " VIRTIO_NET_F_CTRL_MAC_ADDR");
122 			break;
123 		case BIT_ULL(VIRTIO_NET_F_HASH_REPORT):
124 			seq_puts(seq, " VIRTIO_NET_F_HASH_REPORT");
125 			break;
126 		case BIT_ULL(VIRTIO_NET_F_RSS):
127 			seq_puts(seq, " VIRTIO_NET_F_RSS");
128 			break;
129 		case BIT_ULL(VIRTIO_NET_F_RSC_EXT):
130 			seq_puts(seq, " VIRTIO_NET_F_RSC_EXT");
131 			break;
132 		case BIT_ULL(VIRTIO_NET_F_STANDBY):
133 			seq_puts(seq, " VIRTIO_NET_F_STANDBY");
134 			break;
135 		case BIT_ULL(VIRTIO_NET_F_SPEED_DUPLEX):
136 			seq_puts(seq, " VIRTIO_NET_F_SPEED_DUPLEX");
137 			break;
138 		case BIT_ULL(VIRTIO_F_NOTIFY_ON_EMPTY):
139 			seq_puts(seq, " VIRTIO_F_NOTIFY_ON_EMPTY");
140 			break;
141 		case BIT_ULL(VIRTIO_F_ANY_LAYOUT):
142 			seq_puts(seq, " VIRTIO_F_ANY_LAYOUT");
143 			break;
144 		case BIT_ULL(VIRTIO_F_VERSION_1):
145 			seq_puts(seq, " VIRTIO_F_VERSION_1");
146 			break;
147 		case BIT_ULL(VIRTIO_F_ACCESS_PLATFORM):
148 			seq_puts(seq, " VIRTIO_F_ACCESS_PLATFORM");
149 			break;
150 		case BIT_ULL(VIRTIO_F_RING_PACKED):
151 			seq_puts(seq, " VIRTIO_F_RING_PACKED");
152 			break;
153 		case BIT_ULL(VIRTIO_F_ORDER_PLATFORM):
154 			seq_puts(seq, " VIRTIO_F_ORDER_PLATFORM");
155 			break;
156 		case BIT_ULL(VIRTIO_F_SR_IOV):
157 			seq_puts(seq, " VIRTIO_F_SR_IOV");
158 			break;
159 		case 0:
160 			break;
161 		default:
162 			seq_printf(seq, " bit_%d", i);
163 			break;
164 		}
165 	}
166 
167 	seq_puts(seq, "\n");
168 }
169 
170 void pds_vdpa_debugfs_add_pcidev(struct pds_vdpa_aux *vdpa_aux)
171 {
172 	vdpa_aux->dentry = debugfs_create_dir(pci_name(vdpa_aux->padev->vf_pdev), dbfs_dir);
173 }
174 
175 static int identity_show(struct seq_file *seq, void *v)
176 {
177 	struct pds_vdpa_aux *vdpa_aux = seq->private;
178 	struct vdpa_mgmt_dev *mgmt;
179 
180 	seq_printf(seq, "aux_dev:            %s\n",
181 		   dev_name(&vdpa_aux->padev->aux_dev.dev));
182 
183 	mgmt = &vdpa_aux->vdpa_mdev;
184 	seq_printf(seq, "max_vqs:            %d\n", mgmt->max_supported_vqs);
185 	seq_printf(seq, "config_attr_mask:   %#llx\n", mgmt->config_attr_mask);
186 	seq_printf(seq, "supported_features: %#llx\n", mgmt->supported_features);
187 	print_feature_bits_all(seq, mgmt->supported_features);
188 
189 	return 0;
190 }
191 DEFINE_SHOW_ATTRIBUTE(identity);
192 
193 void pds_vdpa_debugfs_add_ident(struct pds_vdpa_aux *vdpa_aux)
194 {
195 	debugfs_create_file("identity", 0400, vdpa_aux->dentry,
196 			    vdpa_aux, &identity_fops);
197 }
198 
199 static int config_show(struct seq_file *seq, void *v)
200 {
201 	struct pds_vdpa_device *pdsv = seq->private;
202 	struct virtio_net_config vc;
203 	u64 driver_features;
204 	u8 status;
205 
206 	memcpy_fromio(&vc, pdsv->vdpa_aux->vd_mdev.device,
207 		      sizeof(struct virtio_net_config));
208 
209 	seq_printf(seq, "mac:                  %pM\n", vc.mac);
210 	seq_printf(seq, "max_virtqueue_pairs:  %d\n",
211 		   __virtio16_to_cpu(true, vc.max_virtqueue_pairs));
212 	seq_printf(seq, "mtu:                  %d\n", __virtio16_to_cpu(true, vc.mtu));
213 	seq_printf(seq, "speed:                %d\n", le32_to_cpu(vc.speed));
214 	seq_printf(seq, "duplex:               %d\n", vc.duplex);
215 	seq_printf(seq, "rss_max_key_size:     %d\n", vc.rss_max_key_size);
216 	seq_printf(seq, "rss_max_indirection_table_length: %d\n",
217 		   le16_to_cpu(vc.rss_max_indirection_table_length));
218 	seq_printf(seq, "supported_hash_types: %#x\n",
219 		   le32_to_cpu(vc.supported_hash_types));
220 	seq_printf(seq, "vn_status:            %#x\n",
221 		   __virtio16_to_cpu(true, vc.status));
222 
223 	status = vp_modern_get_status(&pdsv->vdpa_aux->vd_mdev);
224 	seq_printf(seq, "dev_status:           %#x\n", status);
225 	print_status_bits(seq, status);
226 
227 	seq_printf(seq, "req_features:         %#llx\n", pdsv->req_features);
228 	print_feature_bits_all(seq, pdsv->req_features);
229 	driver_features = vp_modern_get_driver_features(&pdsv->vdpa_aux->vd_mdev);
230 	seq_printf(seq, "driver_features:      %#llx\n", driver_features);
231 	print_feature_bits_all(seq, driver_features);
232 	seq_printf(seq, "vdpa_index:           %d\n", pdsv->vdpa_index);
233 	seq_printf(seq, "num_vqs:              %d\n", pdsv->num_vqs);
234 
235 	return 0;
236 }
237 DEFINE_SHOW_ATTRIBUTE(config);
238 
239 static int vq_show(struct seq_file *seq, void *v)
240 {
241 	struct pds_vdpa_vq_info *vq = seq->private;
242 
243 	seq_printf(seq, "ready:      %d\n", vq->ready);
244 	seq_printf(seq, "desc_addr:  %#llx\n", vq->desc_addr);
245 	seq_printf(seq, "avail_addr: %#llx\n", vq->avail_addr);
246 	seq_printf(seq, "used_addr:  %#llx\n", vq->used_addr);
247 	seq_printf(seq, "q_len:      %d\n", vq->q_len);
248 	seq_printf(seq, "qid:        %d\n", vq->qid);
249 
250 	seq_printf(seq, "doorbell:   %#llx\n", vq->doorbell);
251 	seq_printf(seq, "avail_idx:  %d\n", vq->avail_idx);
252 	seq_printf(seq, "used_idx:   %d\n", vq->used_idx);
253 	seq_printf(seq, "irq:        %d\n", vq->irq);
254 	seq_printf(seq, "irq-name:   %s\n", vq->irq_name);
255 
256 	return 0;
257 }
258 DEFINE_SHOW_ATTRIBUTE(vq);
259 
260 void pds_vdpa_debugfs_add_vdpadev(struct pds_vdpa_aux *vdpa_aux)
261 {
262 	int i;
263 
264 	debugfs_create_file("config", 0400, vdpa_aux->dentry, vdpa_aux->pdsv, &config_fops);
265 
266 	for (i = 0; i < vdpa_aux->pdsv->num_vqs; i++) {
267 		char name[8];
268 
269 		snprintf(name, sizeof(name), "vq%02d", i);
270 		debugfs_create_file(name, 0400, vdpa_aux->dentry,
271 				    &vdpa_aux->pdsv->vqs[i], &vq_fops);
272 	}
273 }
274 
275 void pds_vdpa_debugfs_del_vdpadev(struct pds_vdpa_aux *vdpa_aux)
276 {
277 	debugfs_remove_recursive(vdpa_aux->dentry);
278 	vdpa_aux->dentry = NULL;
279 }
280 
281 void pds_vdpa_debugfs_reset_vdpadev(struct pds_vdpa_aux *vdpa_aux)
282 {
283 	/* we don't keep track of the entries, so remove it all
284 	 * then rebuild the basics
285 	 */
286 	pds_vdpa_debugfs_del_vdpadev(vdpa_aux);
287 	pds_vdpa_debugfs_add_pcidev(vdpa_aux);
288 	pds_vdpa_debugfs_add_ident(vdpa_aux);
289 }
290