]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/misc/mic/scif/scif_debugfs.c
Merge remote-tracking branch 'char-misc/char-misc-next'
[karo-tx-linux.git] / drivers / misc / mic / scif / scif_debugfs.c
1 /*
2  * Intel MIC Platform Software Stack (MPSS)
3  *
4  * Copyright(c) 2014 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 2, as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * Intel SCIF driver.
16  *
17  */
18 #include <linux/debugfs.h>
19 #include <linux/seq_file.h>
20
21 #include "../common/mic_dev.h"
22 #include "scif_main.h"
23
24 /* Debugfs parent dir */
25 static struct dentry *scif_dbg;
26
27 static int scif_dev_test(struct seq_file *s, void *unused)
28 {
29         int node;
30
31         seq_printf(s, "Total Nodes %d Self Node Id %d Maxid %d\n",
32                    scif_info.total, scif_info.nodeid,
33                    scif_info.maxid);
34
35         if (!scif_dev)
36                 return 0;
37
38         seq_printf(s, "%-16s\t%-16s\n", "node_id", "state");
39
40         for (node = 0; node <= scif_info.maxid; node++)
41                 seq_printf(s, "%-16d\t%-16s\n", scif_dev[node].node,
42                            _scifdev_alive(&scif_dev[node]) ?
43                            "Running" : "Offline");
44         return 0;
45 }
46
47 static int scif_dev_test_open(struct inode *inode, struct file *file)
48 {
49         return single_open(file, scif_dev_test, inode->i_private);
50 }
51
52 static int scif_dev_test_release(struct inode *inode, struct file *file)
53 {
54         return single_release(inode, file);
55 }
56
57 static const struct file_operations scif_dev_ops = {
58         .owner   = THIS_MODULE,
59         .open    = scif_dev_test_open,
60         .read    = seq_read,
61         .llseek  = seq_lseek,
62         .release = scif_dev_test_release
63 };
64
65 static void scif_display_window(struct scif_window *window, struct seq_file *s)
66 {
67         int j;
68         struct scatterlist *sg;
69         scif_pinned_pages_t pin = window->pinned_pages;
70
71         seq_printf(s, "window %p type %d temp %d offset 0x%llx ",
72                    window, window->type, window->temp, window->offset);
73         seq_printf(s, "nr_pages 0x%llx nr_contig_chunks 0x%x prot %d ",
74                    window->nr_pages, window->nr_contig_chunks, window->prot);
75         seq_printf(s, "ref_count %d magic 0x%llx peer_window 0x%llx ",
76                    window->ref_count, window->magic, window->peer_window);
77         seq_printf(s, "unreg_state 0x%x va_for_temp 0x%lx\n",
78                    window->unreg_state, window->va_for_temp);
79
80         for (j = 0; j < window->nr_contig_chunks; j++)
81                 seq_printf(s, "page[%d] dma_addr 0x%llx num_pages 0x%llx\n", j,
82                            window->dma_addr[j], window->num_pages[j]);
83
84         if (window->type == SCIF_WINDOW_SELF && pin)
85                 for (j = 0; j < window->nr_pages; j++)
86                         seq_printf(s, "page[%d] = pinned_pages %p address %p\n",
87                                    j, pin->pages[j],
88                                    page_address(pin->pages[j]));
89
90         if (window->st)
91                 for_each_sg(window->st->sgl, sg, window->st->nents, j)
92                         seq_printf(s, "sg[%d] dma addr 0x%llx length 0x%x\n",
93                                    j, sg_dma_address(sg), sg_dma_len(sg));
94 }
95
96 static void scif_display_all_windows(struct list_head *head, struct seq_file *s)
97 {
98         struct list_head *item;
99         struct scif_window *window;
100
101         list_for_each(item, head) {
102                 window = list_entry(item, struct scif_window, list);
103                 scif_display_window(window, s);
104         }
105 }
106
107 static int scif_rma_test(struct seq_file *s, void *unused)
108 {
109         struct scif_endpt *ep;
110         struct list_head *pos;
111
112         mutex_lock(&scif_info.connlock);
113         list_for_each(pos, &scif_info.connected) {
114                 ep = list_entry(pos, struct scif_endpt, list);
115                 seq_printf(s, "ep %p self windows\n", ep);
116                 mutex_lock(&ep->rma_info.rma_lock);
117                 scif_display_all_windows(&ep->rma_info.reg_list, s);
118                 seq_printf(s, "ep %p remote windows\n", ep);
119                 scif_display_all_windows(&ep->rma_info.remote_reg_list, s);
120                 mutex_unlock(&ep->rma_info.rma_lock);
121         }
122         mutex_unlock(&scif_info.connlock);
123         return 0;
124 }
125
126 static int scif_rma_test_open(struct inode *inode, struct file *file)
127 {
128         return single_open(file, scif_rma_test, inode->i_private);
129 }
130
131 static int scif_rma_test_release(struct inode *inode, struct file *file)
132 {
133         return single_release(inode, file);
134 }
135
136 static const struct file_operations scif_rma_ops = {
137         .owner   = THIS_MODULE,
138         .open    = scif_rma_test_open,
139         .read    = seq_read,
140         .llseek  = seq_lseek,
141         .release = scif_rma_test_release
142 };
143
144 void __init scif_init_debugfs(void)
145 {
146         scif_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
147         if (!scif_dbg) {
148                 dev_err(scif_info.mdev.this_device,
149                         "can't create debugfs dir scif\n");
150                 return;
151         }
152
153         debugfs_create_file("scif_dev", 0444, scif_dbg, NULL, &scif_dev_ops);
154         debugfs_create_file("scif_rma", 0444, scif_dbg, NULL, &scif_rma_ops);
155         debugfs_create_u8("en_msg_log", 0666, scif_dbg, &scif_info.en_msg_log);
156         debugfs_create_u8("p2p_enable", 0666, scif_dbg, &scif_info.p2p_enable);
157 }
158
159 void scif_exit_debugfs(void)
160 {
161         debugfs_remove_recursive(scif_dbg);
162 }