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