summaryrefslogtreecommitdiffstats
path: root/drivers/vdpa/pds/debugfs.c
blob: c328e694f6e7f0716a9eee53d21e1d6977b64e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright(c) 2023 Advanced Micro Devices, Inc */

#include <linux/pci.h>
#include <linux/vdpa.h>

#include <linux/pds/pds_common.h>
#include <linux/pds/pds_core_if.h>
#include <linux/pds/pds_adminq.h>
#include <linux/pds/pds_auxbus.h>

#include "aux_drv.h"
#include "vdpa_dev.h"
#include "debugfs.h"

static struct dentry *dbfs_dir;

void pds_vdpa_debugfs_create(void)
{
	dbfs_dir = debugfs_create_dir(PDS_VDPA_DRV_NAME, NULL);
}

void pds_vdpa_debugfs_destroy(void)
{
	debugfs_remove_recursive(dbfs_dir);
	dbfs_dir = NULL;
}

#define PRINT_SBIT_NAME(__seq, __f, __name)                     \
	do {                                                    \
		if ((__f) & (__name))                               \
			seq_printf(__seq, " %s", &#__name[16]); \
	} while (0)

static void print_status_bits(struct seq_file *seq, u8 status)
{
	seq_puts(seq, "status:");
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_ACKNOWLEDGE);
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_DRIVER);
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_DRIVER_OK);
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_FEATURES_OK);
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_NEEDS_RESET);
	PRINT_SBIT_NAME(seq, status, VIRTIO_CONFIG_S_FAILED);
	seq_puts(seq, "\n");
}

static void print_feature_bits_all(struct seq_file *seq, u64 features)
{
	int i;

	seq_puts(seq, "features:");

	for (i = 0; i < (sizeof(u64) * 8); i++) {
		u64 mask = BIT_ULL(i);

		switch (features & mask) {
		case BIT_ULL(VIRTIO_NET_F_CSUM):
			seq_puts(seq, " VIRTIO_NET_F_CSUM");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_CSUM):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_CSUM");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_GUEST_OFFLOADS");
			break;
		case BIT_ULL(VIRTIO_NET_F_MTU):
			seq_puts(seq, " VIRTIO_NET_F_MTU");
			break;
		case BIT_ULL(VIRTIO_NET_F_MAC):
			seq_puts(seq, " VIRTIO_NET_F_MAC");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_TSO4):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_TSO4");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_TSO6):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_TSO6");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_ECN):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_ECN");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_UFO):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_UFO");
			break;
		case BIT_ULL(VIRTIO_NET_F_HOST_TSO4):
			seq_puts(seq, " VIRTIO_NET_F_HOST_TSO4");
			break;
		case BIT_ULL(VIRTIO_NET_F_HOST_TSO6):
			seq_puts(seq, " VIRTIO_NET_F_HOST_TSO6");
			break;
		case BIT_ULL(VIRTIO_NET_F_HOST_ECN):
			seq_puts(seq, " VIRTIO_NET_F_HOST_ECN");
			break;
		case BIT_ULL(VIRTIO_NET_F_HOST_UFO):
			seq_puts(seq, " VIRTIO_NET_F_HOST_UFO");
			break;
		case BIT_ULL(VIRTIO_NET_F_MRG_RXBUF):
			seq_puts(seq, " VIRTIO_NET_F_MRG_RXBUF");
			break;
		case BIT_ULL(VIRTIO_NET_F_STATUS):
			seq_puts(seq, " VIRTIO_NET_F_STATUS");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_VQ):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_VQ");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_RX):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_RX");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_VLAN):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_VLAN");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_RX_EXTRA):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_RX_EXTRA");
			break;
		case BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE):
			seq_puts(seq, " VIRTIO_NET_F_GUEST_ANNOUNCE");
			break;
		case BIT_ULL(VIRTIO_NET_F_MQ):
			seq_puts(seq, " VIRTIO_NET_F_MQ");
			break;
		case BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR):
			seq_puts(seq, " VIRTIO_NET_F_CTRL_MAC_ADDR");
			break;
		case BIT_ULL(VIRTIO_NET_F_HASH_REPORT):
			seq_puts(seq, " VIRTIO_NET_F_HASH_REPORT");
			break;
		case BIT_ULL(VIRTIO_NET_F_RSS):
			seq_puts(seq, " VIRTIO_NET_F_RSS");
			break;
		case BIT_ULL(VIRTIO_NET_F_RSC_EXT):
			seq_puts(seq, " VIRTIO_NET_F_RSC_EXT");
			break;
		case BIT_ULL(VIRTIO_NET_F_STANDBY):
			seq_puts(seq, " VIRTIO_NET_F_STANDBY");
			break;
		case BIT_ULL(VIRTIO_NET_F_SPEED_DUPLEX):
			seq_puts(seq, " VIRTIO_NET_F_SPEED_DUPLEX");
			break;
		case BIT_ULL(VIRTIO_F_NOTIFY_ON_EMPTY):
			seq_puts(seq, " VIRTIO_F_NOTIFY_ON_EMPTY");
			break;
		case BIT_ULL(VIRTIO_F_ANY_LAYOUT):
			seq_puts(seq, " VIRTIO_F_ANY_LAYOUT");
			break;
		case BIT_ULL(VIRTIO_F_VERSION_1):
			seq_puts(seq, " VIRTIO_F_VERSION_1");
			break;
		case BIT_ULL(VIRTIO_F_ACCESS_PLATFORM):
			seq_puts(seq, " VIRTIO_F_ACCESS_PLATFORM");
			break;
		case BIT_ULL(VIRTIO_F_RING_PACKED):
			seq_puts(seq, " VIRTIO_F_RING_PACKED");
			break;
		case BIT_ULL(VIRTIO_F_ORDER_PLATFORM):
			seq_puts(seq, " VIRTIO_F_ORDER_PLATFORM");
			break;
		case BIT_ULL(VIRTIO_F_SR_IOV):
			seq_puts(seq, " VIRTIO_F_SR_IOV");
			break;
		case 0:
			break;
		default:
			seq_printf(seq, " bit_%d", i);
			break;
		}
	}

	seq_puts(seq, "\n");
}

void pds_vdpa_debugfs_add_pcidev(struct pds_vdpa_aux *vdpa_aux)
{
	vdpa_aux->dentry = debugfs_create_dir(pci_name(vdpa_aux->padev->vf_pdev), dbfs_dir);
}

static int identity_show(struct seq_file *seq, void *v)
{
	struct pds_vdpa_aux *vdpa_aux = seq->private;
	struct vdpa_mgmt_dev *mgmt;
	u64 hw_features;

	seq_printf(seq, "aux_dev:            %s\n",
		   dev_name(&vdpa_aux->padev->aux_dev.dev));

	mgmt = &vdpa_aux->vdpa_mdev;
	seq_printf(seq, "max_vqs:            %d\n", mgmt->max_supported_vqs);
	seq_printf(seq, "config_attr_mask:   %#llx\n", mgmt->config_attr_mask);
	hw_features = le64_to_cpu(vdpa_aux->ident.hw_features);
	seq_printf(seq, "hw_features:        %#llx\n", hw_features);
	print_feature_bits_all(seq, hw_features);

	return 0;
}
DEFINE_SHOW_ATTRIBUTE(identity);

void pds_vdpa_debugfs_add_ident(struct pds_vdpa_aux *vdpa_aux)
{
	debugfs_create_file("identity", 0400, vdpa_aux->dentry,
			    vdpa_aux, &identity_fops);
}

static int config_show(struct seq_file *seq, void *v)
{
	struct pds_vdpa_device *pdsv = seq->private;
	struct virtio_net_config vc;
	u8 status;

	memcpy_fromio(&vc, pdsv->vdpa_aux->vd_mdev.device,
		      sizeof(struct virtio_net_config));

	seq_printf(seq, "mac:                  %pM\n", vc.mac);
	seq_printf(seq, "max_virtqueue_pairs:  %d\n",
		   __virtio16_to_cpu(true, vc.max_virtqueue_pairs));
	seq_printf(seq, "mtu:                  %d\n", __virtio16_to_cpu(true, vc.mtu));
	seq_printf(seq, "speed:                %d\n", le32_to_cpu(vc.speed));
	seq_printf(seq, "duplex:               %d\n", vc.duplex);
	seq_printf(seq, "rss_max_key_size:     %d\n", vc.rss_max_key_size);
	seq_printf(seq, "rss_max_indirection_table_length: %d\n",
		   le16_to_cpu(vc.rss_max_indirection_table_length));
	seq_printf(seq, "supported_hash_types: %#x\n",
		   le32_to_cpu(vc.supported_hash_types));
	seq_printf(seq, "vn_status:            %#x\n",
		   __virtio16_to_cpu(true, vc.status));

	status = vp_modern_get_status(&pdsv->vdpa_aux->vd_mdev);
	seq_printf(seq, "dev_status:           %#x\n", status);
	print_status_bits(seq, status);
	seq_printf(seq, "negotiated_features:  %#llx\n", pdsv->negotiated_features);
	print_feature_bits_all(seq, pdsv->negotiated_features);
	seq_printf(seq, "vdpa_index:           %d\n", pdsv->vdpa_index);
	seq_printf(seq, "num_vqs:              %d\n", pdsv->num_vqs);

	return 0;
}
DEFINE_SHOW_ATTRIBUTE(config);

static int vq_show(struct seq_file *seq, void *v)
{
	struct pds_vdpa_vq_info *vq = seq->private;

	seq_printf(seq, "ready:      %d\n", vq->ready);
	seq_printf(seq, "desc_addr:  %#llx\n", vq->desc_addr);
	seq_printf(seq, "avail_addr: %#llx\n", vq->avail_addr);
	seq_printf(seq, "used_addr:  %#llx\n", vq->used_addr);
	seq_printf(seq, "q_len:      %d\n", vq->q_len);
	seq_printf(seq, "qid:        %d\n", vq->qid);

	seq_printf(seq, "doorbell:   %#llx\n", vq->doorbell);
	seq_printf(seq, "avail_idx:  %d\n", vq->avail_idx);
	seq_printf(seq, "used_idx:   %d\n", vq->used_idx);
	seq_printf(seq, "irq:        %d\n", vq->irq);
	seq_printf(seq, "irq-name:   %s\n", vq->irq_name);

	return 0;
}
DEFINE_SHOW_ATTRIBUTE(vq);

void pds_vdpa_debugfs_add_vdpadev(struct pds_vdpa_aux *vdpa_aux)
{
	int i;

	debugfs_create_file("config", 0400, vdpa_aux->dentry, vdpa_aux->pdsv, &config_fops);

	for (i = 0; i < vdpa_aux->pdsv->num_vqs; i++) {
		char name[16];

		snprintf(name, sizeof(name), "vq%02d", i);
		debugfs_create_file(name, 0400, vdpa_aux->dentry,
				    &vdpa_aux->pdsv->vqs[i], &vq_fops);
	}
}

void pds_vdpa_debugfs_del_vdpadev(struct pds_vdpa_aux *vdpa_aux)
{
	debugfs_remove_recursive(vdpa_aux->dentry);
	vdpa_aux->dentry = NULL;
}

void pds_vdpa_debugfs_reset_vdpadev(struct pds_vdpa_aux *vdpa_aux)
{
	/* we don't keep track of the entries, so remove it all
	 * then rebuild the basics
	 */
	pds_vdpa_debugfs_del_vdpadev(vdpa_aux);
	pds_vdpa_debugfs_add_pcidev(vdpa_aux);
	pds_vdpa_debugfs_add_ident(vdpa_aux);
}