summaryrefslogtreecommitdiffstats
path: root/legacy-driver-guest/debugfs/gsp_debugfs.c
blob: f3df124362166ff7ae58e7f7f23111ea1ef4b91d (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
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * GSP vGPU-IO Driver - Debugfs Interface
 */

#include "gsp_core.h"
#include <linux/debugfs.h>
#include <linux/seq_file.h>

static int gsp_debugfs_vfs_show(struct seq_file *s, void *unused)
{
    struct gsp_device *gsp = s->private;
    struct gsp_vf *vf;
    
    seq_printf(s, "%-4s %-12s %-10s %-18s %-18s\n",
               "ID", "STATE", "REFCNT", "BAR1", "PAGE_TABLE");
    
    mutex_lock(&gsp->vf_lock);
    list_for_each_entry(vf, &gsp->vf_list, list) {
        seq_printf(s, "%-4u %-12d %-10d 0x%016llx-0x%016llx 0x%016llx-0x%016llx\n",
                   vf->id, vf->state, atomic_read(&vf->refcount),
                   vf->bar1_offset, vf->bar1_offset + vf->bar1_size,
                   vf->pt_base, vf->pt_base + vf->pt_size);
    }
    mutex_unlock(&gsp->vf_lock);
    
    return 0;
}

static int gsp_debugfs_vfs_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_vfs_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_vfs_fops = {
    .open = gsp_debugfs_vfs_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

static int gsp_debugfs_vf_show(struct seq_file *s, void *unused)
{
    struct gsp_vf *vf = s->private;
    struct gsp_wpr_region *rgn;
    
    seq_printf(s, "VF %u\n", vf->id);
    seq_printf(s, "  State:       %d\n", vf->state);
    seq_printf(s, "  Refcount:    %d\n", atomic_read(&vf->refcount));
    seq_printf(s, "  BAR1:        0x%llx - 0x%llx (size: 0x%llx)\n",
               vf->bar1_offset, vf->bar1_offset + vf->bar1_size, vf->bar1_size);
    seq_printf(s, "  Page Table:  0x%llx - 0x%llx (size: 0x%llx)\n",
               vf->pt_base, vf->pt_base + vf->pt_size, vf->pt_size);
    seq_printf(s, "  Cmd Buffer:  0x%llx - 0x%llx (size: 0x%llx)\n",
               vf->cmd_base, vf->cmd_base + vf->cmd_size, vf->cmd_size);
    seq_printf(s, "  BAR State:\n");
    seq_printf(s, "    Aperture:  0x%llx - 0x%llx\n",
               vf->bar_state.aperture_offset,
               vf->bar_state.aperture_offset + vf->bar_state.aperture_size);
    seq_printf(s, "    ForceAcc:  %s (VF: %u)\n",
               vf->bar_state.force_access ? "enabled" : "disabled",
               vf->bar_state.force_vf);
    seq_printf(s, "  WPR Regions:\n");
    
    mutex_lock(&vf->wpr_lock);
    list_for_each_entry(rgn, &vf->wpr_list, list) {
        seq_printf(s, "    [0x%llx, 0x%llx) flags=0x%x\n",
                   rgn->base, rgn->base + rgn->size, rgn->flags);
    }
    mutex_unlock(&vf->wpr_lock);
    
    if (vf->migration) {
        seq_printf(s, "  Migration:\n");
        seq_printf(s, "    State:     %d\n", vf->migration->state);
        seq_printf(s, "    Dst VF:    %llu\n", vf->migration->dst_vf);
        seq_printf(s, "    Token:     0x%llx\n", vf->migration->token);
        seq_printf(s, "    Progress:  %llu pages, %llu bytes\n",
                   vf->migration->progress.pages_transferred,
                   vf->migration->progress.bytes_transferred);
    }
    
    return 0;
}

static int gsp_debugfs_vf_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_vf_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_vf_fops = {
    .open = gsp_debugfs_vf_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

static int gsp_debugfs_rpc_show(struct seq_file *s, void *unused)
{
    struct gsp_device *gsp = s->private;
    
    seq_printf(s, "RPC Statistics:\n");
    seq_printf(s, "  Total:       %lld\n", atomic64_read(&gsp->rpc_total));
    seq_printf(s, "  Errors:      %lld\n", atomic64_read(&gsp->rpc_errors));
    seq_printf(s, "  BAR Traps:   %lld\n", atomic64_read(&gsp->bar_traps));
    seq_printf(s, "  WPR Events:  %lld\n", atomic64_read(&gsp->wpr_events));
    seq_printf(s, "  Migrations:  %lld\n", atomic64_read(&gsp->migrations));
    
    return 0;
}

static int gsp_debugfs_rpc_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_rpc_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_rpc_fops = {
    .open = gsp_debugfs_rpc_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

static int gsp_debugfs_bar_show(struct seq_file *s, void *unused)
{
    struct gsp_vf *vf = s->private;
    
    seq_printf(s, "VF %u BAR State:\n", vf->id);
    seq_printf(s, "  Aperture Offset:  0x%llx\n", vf->bar_state.aperture_offset);
    seq_printf(s, "  Aperture Size:    0x%llx\n", vf->bar_state.aperture_size);
    seq_printf(s, "  Force Access:     %s\n", vf->bar_state.force_access ? "enabled" : "disabled");
    seq_printf(s, "  Force VF:         %u\n", vf->bar_state.force_vf);
    seq_printf(s, "  Backing Store:    %p\n", vf->bar_state.backing_store);
    seq_printf(s, "  Backing Size:     0x%zx\n", vf->bar_state.backing_size);
    
    return 0;
}

static int gsp_debugfs_bar_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_bar_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_bar_fops = {
    .open = gsp_debugfs_bar_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

static int gsp_debugfs_wpr_show(struct seq_file *s, void *unused)
{
    struct gsp_vf *vf = s->private;
    struct gsp_wpr_region *rgn;
    
    seq_printf(s, "VF %u WPR Regions:\n", vf->id);
    
    mutex_lock(&vf->wpr_lock);
    list_for_each_entry(rgn, &vf->wpr_list, list) {
        seq_printf(s, "  [0x%llx, 0x%llx) size=0x%llx flags=0x%x\n",
                   rgn->base, rgn->base + rgn->size, rgn->size, rgn->flags);
    }
    mutex_unlock(&vf->wpr_lock);
    
    return 0;
}

static int gsp_debugfs_wpr_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_wpr_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_wpr_fops = {
    .open = gsp_debugfs_wpr_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

static int gsp_debugfs_migration_show(struct seq_file *s, void *unused)
{
    struct gsp_vf *vf = s->private;
    
    if (!vf->migration) {
        seq_printf(s, "No active migration\n");
        return 0;
    }
    
    seq_printf(s, "VF %u Migration:\n", vf->id);
    seq_printf(s, "  State:           %d\n", vf->migration->state);
    seq_printf(s, "  Destination VF:  %llu\n", vf->migration->dst_vf);
    seq_printf(s, "  Token:           0x%llx\n", vf->migration->token);
    seq_printf(s, "  Flags:           0x%x\n", vf->migration->flags);
    seq_printf(s, "  Pages Xfer:      %llu\n", vf->migration->progress.pages_transferred);
    seq_printf(s, "  Bytes Xfer:      %llu\n", vf->migration->progress.bytes_transferred);
    seq_printf(s, "  Dirty Pages:     %llu\n", vf->migration->progress.dirty_pages);
    seq_printf(s, "  Cancelled:       %s\n", vf->migration->cancelled ? "yes" : "no");
    
    return 0;
}

static int gsp_debugfs_migration_open(struct inode *inode, struct file *file)
{
    return single_open(file, gsp_debugfs_migration_show, inode->i_private);
}

static const struct file_operations gsp_debugfs_migration_fops = {
    .open = gsp_debugfs_migration_open,
    .read = seq_read,
    .llseek = seq_lseek,
    .release = single_release,
};

/* VF Debugfs Directory Creation */
static void gsp_debugfs_vf_create(struct gsp_vf *vf)
{
    char name[16];
    struct dentry *vf_dir;
    
    snprintf(name, sizeof(name), "vf%u", vf->id);
    vf_dir = debugfs_create_dir(name, vf->gsp->debugfs_vfs_dir);
    if (!vf_dir)
        return;
    
    debugfs_create_file("status", 0444, vf_dir, vf, &gsp_debugfs_vf_fops);
    debugfs_create_file("bar", 0444, vf_dir, vf, &gsp_debugfs_bar_fops);
    debugfs_create_file("wpr", 0444, vf_dir, vf, &gsp_debugfs_wpr_fops);
    debugfs_create_file("migration", 0444, vf_dir, vf, &gsp_debugfs_migration_fops);
}

/* Main Debugfs Init */
int gsp_debugfs_init(struct gsp_device *gsp)
{
    gsp->debugfs_root = debugfs_create_dir("gsp-vgpu", NULL);
    if (!gsp->debugfs_root)
        return -ENOMEM;
    
    debugfs_create_file("vfs", 0444, gsp->debugfs_root, gsp, &gsp_debugfs_vfs_fops);
    debugfs_create_file("rpc", 0444, gsp->debugfs_root, gsp, &gsp_debugfs_rpc_fops);
    
    gsp->debugfs_vfs_dir = debugfs_create_dir("vfs", gsp->debugfs_root);
    if (!gsp->debugfs_vfs_dir) {
        debugfs_remove_recursive(gsp->debugfs_root);
        return -ENOMEM;
    }
    
    /* Create entries for existing VFs */
    mutex_lock(&gsp->vf_lock);
    struct gsp_vf *vf;
    list_for_each_entry(vf, &gsp->vf_list, list)
        gsp_debugfs_vf_create(vf);
    mutex_unlock(&gsp->vf_lock);
    
    return 0;
}

void gsp_debugfs_fini(struct gsp_device *gsp)
{
    if (gsp->debugfs_root)
        debugfs_remove_recursive(gsp->debugfs_root);
}

/* Export for VF creation/destruction */
void gsp_debugfs_vf_add(struct gsp_vf *vf)
{
    gsp_debugfs_vf_create(vf);
}

void gsp_debugfs_vf_remove(struct gsp_vf *vf)
{
    char name[16];
    snprintf(name, sizeof(name), "vf%u", vf->id);
    debugfs_remove_recursive(debugfs_lookup(name, vf->gsp->debugfs_vfs_dir));
}