]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/s390/cio/qdio_debug.c
[S390] qdio: rework debug feature logging
[linux-2.6-omap-h63xx.git] / drivers / s390 / cio / qdio_debug.c
1 /*
2  *  drivers/s390/cio/qdio_debug.c
3  *
4  *  Copyright IBM Corp. 2008
5  *
6  *  Author: Jan Glauber (jang@linux.vnet.ibm.com)
7  */
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <linux/debugfs.h>
11 #include <asm/qdio.h>
12 #include <asm/debug.h>
13 #include "qdio_debug.h"
14 #include "qdio.h"
15
16 debug_info_t *qdio_dbf_setup;
17 debug_info_t *qdio_dbf_error;
18
19 static struct dentry *debugfs_root;
20 #define MAX_DEBUGFS_QUEUES      32
21 static struct dentry *debugfs_queues[MAX_DEBUGFS_QUEUES] = { NULL };
22 static DEFINE_MUTEX(debugfs_mutex);
23 #define QDIO_DEBUGFS_NAME_LEN   40
24
25 void qdio_allocate_dbf(struct qdio_initialize *init_data,
26                        struct qdio_irq *irq_ptr)
27 {
28         char text[20];
29
30         DBF_EVENT("qfmt:%1d", init_data->q_format);
31         DBF_HEX(init_data->adapter_name, 8);
32         DBF_EVENT("qpff%4x", init_data->qib_param_field_format);
33         DBF_HEX(&init_data->qib_param_field, sizeof(void *));
34         DBF_HEX(&init_data->input_slib_elements, sizeof(void *));
35         DBF_HEX(&init_data->output_slib_elements, sizeof(void *));
36         DBF_EVENT("niq:%1d noq:%1d", init_data->no_input_qs,
37                   init_data->no_output_qs);
38         DBF_HEX(&init_data->input_handler, sizeof(void *));
39         DBF_HEX(&init_data->output_handler, sizeof(void *));
40         DBF_HEX(&init_data->int_parm, sizeof(long));
41         DBF_HEX(&init_data->flags, sizeof(long));
42         DBF_HEX(&init_data->input_sbal_addr_array, sizeof(void *));
43         DBF_HEX(&init_data->output_sbal_addr_array, sizeof(void *));
44         DBF_EVENT("irq:%8lx", (unsigned long)irq_ptr);
45
46         /* allocate trace view for the interface */
47         snprintf(text, 20, "qdio_%s", dev_name(&init_data->cdev->dev));
48         irq_ptr->debug_area = debug_register(text, 2, 1, 16);
49         debug_register_view(irq_ptr->debug_area, &debug_hex_ascii_view);
50         debug_set_level(irq_ptr->debug_area, DBF_WARN);
51         DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf created");
52 }
53
54 static int qstat_show(struct seq_file *m, void *v)
55 {
56         unsigned char state;
57         struct qdio_q *q = m->private;
58         int i;
59
60         if (!q)
61                 return 0;
62
63         seq_printf(m, "device state indicator: %d\n", *q->irq_ptr->dsci);
64         seq_printf(m, "nr_used: %d\n", atomic_read(&q->nr_buf_used));
65         seq_printf(m, "ftc: %d\n", q->first_to_check);
66         seq_printf(m, "last_move_ftc: %d\n", q->last_move_ftc);
67         seq_printf(m, "polling: %d\n", q->u.in.polling);
68         seq_printf(m, "slsb buffer states:\n");
69
70         qdio_siga_sync_q(q);
71         for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
72                 get_buf_state(q, i, &state);
73                 switch (state) {
74                 case SLSB_P_INPUT_NOT_INIT:
75                 case SLSB_P_OUTPUT_NOT_INIT:
76                         seq_printf(m, "N");
77                         break;
78                 case SLSB_P_INPUT_PRIMED:
79                 case SLSB_CU_OUTPUT_PRIMED:
80                         seq_printf(m, "+");
81                         break;
82                 case SLSB_P_INPUT_ACK:
83                         seq_printf(m, "A");
84                         break;
85                 case SLSB_P_INPUT_ERROR:
86                 case SLSB_P_OUTPUT_ERROR:
87                         seq_printf(m, "x");
88                         break;
89                 case SLSB_CU_INPUT_EMPTY:
90                 case SLSB_P_OUTPUT_EMPTY:
91                         seq_printf(m, "-");
92                         break;
93                 case SLSB_P_INPUT_HALTED:
94                 case SLSB_P_OUTPUT_HALTED:
95                         seq_printf(m, ".");
96                         break;
97                 default:
98                         seq_printf(m, "?");
99                 }
100                 if (i == 63)
101                         seq_printf(m, "\n");
102         }
103         seq_printf(m, "\n");
104         return 0;
105 }
106
107 static ssize_t qstat_seq_write(struct file *file, const char __user *buf,
108                                size_t count, loff_t *off)
109 {
110         struct seq_file *seq = file->private_data;
111         struct qdio_q *q = seq->private;
112
113         if (!q)
114                 return 0;
115
116         if (q->is_input_q)
117                 xchg(q->irq_ptr->dsci, 1);
118         local_bh_disable();
119         tasklet_schedule(&q->tasklet);
120         local_bh_enable();
121         return count;
122 }
123
124 static int qstat_seq_open(struct inode *inode, struct file *filp)
125 {
126         return single_open(filp, qstat_show,
127                            filp->f_path.dentry->d_inode->i_private);
128 }
129
130 static void remove_debugfs_entry(struct qdio_q *q)
131 {
132         int i;
133
134         for (i = 0; i < MAX_DEBUGFS_QUEUES; i++) {
135                 if (!debugfs_queues[i])
136                         continue;
137                 if (debugfs_queues[i]->d_inode->i_private == q) {
138                         debugfs_remove(debugfs_queues[i]);
139                         debugfs_queues[i] = NULL;
140                 }
141         }
142 }
143
144 static struct file_operations debugfs_fops = {
145         .owner   = THIS_MODULE,
146         .open    = qstat_seq_open,
147         .read    = seq_read,
148         .write   = qstat_seq_write,
149         .llseek  = seq_lseek,
150         .release = single_release,
151 };
152
153 static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev)
154 {
155         int i = 0;
156         char name[QDIO_DEBUGFS_NAME_LEN];
157
158         while (debugfs_queues[i] != NULL) {
159                 i++;
160                 if (i >= MAX_DEBUGFS_QUEUES)
161                         return;
162         }
163         snprintf(name, QDIO_DEBUGFS_NAME_LEN, "%s_%s_%d",
164                  dev_name(&cdev->dev),
165                  q->is_input_q ? "input" : "output",
166                  q->nr);
167         debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR,
168                                                 debugfs_root, q, &debugfs_fops);
169 }
170
171 void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
172 {
173         struct qdio_q *q;
174         int i;
175
176         mutex_lock(&debugfs_mutex);
177         for_each_input_queue(irq_ptr, q, i)
178                 setup_debugfs_entry(q, cdev);
179         for_each_output_queue(irq_ptr, q, i)
180                 setup_debugfs_entry(q, cdev);
181         mutex_unlock(&debugfs_mutex);
182 }
183
184 void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
185 {
186         struct qdio_q *q;
187         int i;
188
189         mutex_lock(&debugfs_mutex);
190         for_each_input_queue(irq_ptr, q, i)
191                 remove_debugfs_entry(q);
192         for_each_output_queue(irq_ptr, q, i)
193                 remove_debugfs_entry(q);
194         mutex_unlock(&debugfs_mutex);
195 }
196
197 int __init qdio_debug_init(void)
198 {
199         debugfs_root = debugfs_create_dir("qdio_queues", NULL);
200
201         qdio_dbf_setup = debug_register("qdio_setup", 16, 1, 16);
202         debug_register_view(qdio_dbf_setup, &debug_hex_ascii_view);
203         debug_set_level(qdio_dbf_setup, DBF_INFO);
204         DBF_EVENT("dbf created\n");
205
206         qdio_dbf_error = debug_register("qdio_error", 4, 1, 16);
207         debug_register_view(qdio_dbf_error, &debug_hex_ascii_view);
208         debug_set_level(qdio_dbf_error, DBF_INFO);
209         DBF_ERROR("dbf created\n");
210         return 0;
211 }
212
213 void qdio_debug_exit(void)
214 {
215         debugfs_remove(debugfs_root);
216         if (qdio_dbf_setup)
217                 debug_unregister(qdio_dbf_setup);
218         if (qdio_dbf_error)
219                 debug_unregister(qdio_dbf_error);
220 }