1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/seq_file.h>
3 #include <linux/debugfs.h>
4
5 #include "nitrox_csr.h"
6 #include "nitrox_dev.h"
7
firmware_show(struct seq_file * s,void * v)8 static int firmware_show(struct seq_file *s, void *v)
9 {
10 struct nitrox_device *ndev = s->private;
11
12 seq_printf(s, "Version: %s\n", ndev->hw.fw_name[0]);
13 seq_printf(s, "Version: %s\n", ndev->hw.fw_name[1]);
14 return 0;
15 }
16
17 DEFINE_SHOW_ATTRIBUTE(firmware);
18
device_show(struct seq_file * s,void * v)19 static int device_show(struct seq_file *s, void *v)
20 {
21 struct nitrox_device *ndev = s->private;
22
23 seq_printf(s, "NITROX [%d]\n", ndev->idx);
24 seq_printf(s, " Part Name: %s\n", ndev->hw.partname);
25 seq_printf(s, " Frequency: %d MHz\n", ndev->hw.freq);
26 seq_printf(s, " Device ID: 0x%0x\n", ndev->hw.device_id);
27 seq_printf(s, " Revision ID: 0x%0x\n", ndev->hw.revision_id);
28 seq_printf(s, " Cores: [AE=%u SE=%u ZIP=%u]\n",
29 ndev->hw.ae_cores, ndev->hw.se_cores, ndev->hw.zip_cores);
30
31 return 0;
32 }
33
34 DEFINE_SHOW_ATTRIBUTE(device);
35
stats_show(struct seq_file * s,void * v)36 static int stats_show(struct seq_file *s, void *v)
37 {
38 struct nitrox_device *ndev = s->private;
39
40 seq_printf(s, "NITROX [%d] Request Statistics\n", ndev->idx);
41 seq_printf(s, " Posted: %llu\n",
42 (u64)atomic64_read(&ndev->stats.posted));
43 seq_printf(s, " Completed: %llu\n",
44 (u64)atomic64_read(&ndev->stats.completed));
45 seq_printf(s, " Dropped: %llu\n",
46 (u64)atomic64_read(&ndev->stats.dropped));
47
48 return 0;
49 }
50
51 DEFINE_SHOW_ATTRIBUTE(stats);
52
nitrox_debugfs_exit(struct nitrox_device * ndev)53 void nitrox_debugfs_exit(struct nitrox_device *ndev)
54 {
55 debugfs_remove_recursive(ndev->debugfs_dir);
56 ndev->debugfs_dir = NULL;
57 }
58
nitrox_debugfs_init(struct nitrox_device * ndev)59 void nitrox_debugfs_init(struct nitrox_device *ndev)
60 {
61 struct dentry *dir;
62
63 dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
64
65 ndev->debugfs_dir = dir;
66 debugfs_create_file("firmware", 0400, dir, ndev, &firmware_fops);
67 debugfs_create_file("device", 0400, dir, ndev, &device_fops);
68 debugfs_create_file("stats", 0400, dir, ndev, &stats_fops);
69 }
70