2 * drivers/s390/cio/qdio_debug.c
4 * Copyright IBM Corp. 2008
6 * Author: Jan Glauber (jang@linux.vnet.ibm.com)
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <linux/debugfs.h>
12 #include <asm/debug.h>
13 #include "qdio_debug.h"
16 debug_info_t *qdio_dbf_setup;
17 debug_info_t *qdio_dbf_error;
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
25 void qdio_allocate_dbf(struct qdio_initialize *init_data,
26 struct qdio_irq *irq_ptr)
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);
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");
54 static int qstat_show(struct seq_file *m, void *v)
57 struct qdio_q *q = m->private;
63 seq_printf(m, "device state indicator: %d\n", *(u32 *)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: %d\n", q->last_move);
67 seq_printf(m, "polling: %d\n", q->u.in.polling);
68 seq_printf(m, "ack start: %d\n", q->u.in.ack_start);
69 seq_printf(m, "ack count: %d\n", q->u.in.ack_count);
70 seq_printf(m, "slsb buffer states:\n");
71 seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
74 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
75 get_buf_state(q, i, &state, 0);
77 case SLSB_P_INPUT_NOT_INIT:
78 case SLSB_P_OUTPUT_NOT_INIT:
81 case SLSB_P_INPUT_PRIMED:
82 case SLSB_CU_OUTPUT_PRIMED:
85 case SLSB_P_INPUT_ACK:
88 case SLSB_P_INPUT_ERROR:
89 case SLSB_P_OUTPUT_ERROR:
92 case SLSB_CU_INPUT_EMPTY:
93 case SLSB_P_OUTPUT_EMPTY:
96 case SLSB_P_INPUT_HALTED:
97 case SLSB_P_OUTPUT_HALTED:
107 seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
111 static ssize_t qstat_seq_write(struct file *file, const char __user *buf,
112 size_t count, loff_t *off)
114 struct seq_file *seq = file->private_data;
115 struct qdio_q *q = seq->private;
121 xchg(q->irq_ptr->dsci, 1);
123 tasklet_schedule(&q->tasklet);
128 static int qstat_seq_open(struct inode *inode, struct file *filp)
130 return single_open(filp, qstat_show,
131 filp->f_path.dentry->d_inode->i_private);
134 static void remove_debugfs_entry(struct qdio_q *q)
138 for (i = 0; i < MAX_DEBUGFS_QUEUES; i++) {
139 if (!debugfs_queues[i])
141 if (debugfs_queues[i]->d_inode->i_private == q) {
142 debugfs_remove(debugfs_queues[i]);
143 debugfs_queues[i] = NULL;
148 static struct file_operations debugfs_fops = {
149 .owner = THIS_MODULE,
150 .open = qstat_seq_open,
152 .write = qstat_seq_write,
154 .release = single_release,
157 static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev)
160 char name[QDIO_DEBUGFS_NAME_LEN];
162 while (debugfs_queues[i] != NULL) {
164 if (i >= MAX_DEBUGFS_QUEUES)
167 snprintf(name, QDIO_DEBUGFS_NAME_LEN, "%s_%s_%d",
168 dev_name(&cdev->dev),
169 q->is_input_q ? "input" : "output",
171 debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR,
172 debugfs_root, q, &debugfs_fops);
173 if (IS_ERR(debugfs_queues[i]))
174 debugfs_queues[i] = NULL;
177 void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
182 mutex_lock(&debugfs_mutex);
183 for_each_input_queue(irq_ptr, q, i)
184 setup_debugfs_entry(q, cdev);
185 for_each_output_queue(irq_ptr, q, i)
186 setup_debugfs_entry(q, cdev);
187 mutex_unlock(&debugfs_mutex);
190 void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
195 mutex_lock(&debugfs_mutex);
196 for_each_input_queue(irq_ptr, q, i)
197 remove_debugfs_entry(q);
198 for_each_output_queue(irq_ptr, q, i)
199 remove_debugfs_entry(q);
200 mutex_unlock(&debugfs_mutex);
203 int __init qdio_debug_init(void)
205 debugfs_root = debugfs_create_dir("qdio_queues", NULL);
207 qdio_dbf_setup = debug_register("qdio_setup", 16, 1, 16);
208 debug_register_view(qdio_dbf_setup, &debug_hex_ascii_view);
209 debug_set_level(qdio_dbf_setup, DBF_INFO);
210 DBF_EVENT("dbf created\n");
212 qdio_dbf_error = debug_register("qdio_error", 4, 1, 16);
213 debug_register_view(qdio_dbf_error, &debug_hex_ascii_view);
214 debug_set_level(qdio_dbf_error, DBF_INFO);
215 DBF_ERROR("dbf created\n");
219 void qdio_debug_exit(void)
221 debugfs_remove(debugfs_root);
223 debug_unregister(qdio_dbf_setup);
225 debug_unregister(qdio_dbf_error);