On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / s390 / cio / qdio_debug.c
blob76769978285f0cd28a15eb2004b633bce16a6418
1 /*
2 * drivers/s390/cio/qdio_debug.c
4 * Copyright IBM Corp. 2008,2009
6 * Author: Jan Glauber (jang@linux.vnet.ibm.com)
7 */
8 #include <linux/seq_file.h>
9 #include <linux/debugfs.h>
10 #include <asm/debug.h>
11 #include "qdio_debug.h"
12 #include "qdio.h"
14 debug_info_t *qdio_dbf_setup;
15 debug_info_t *qdio_dbf_error;
17 static struct dentry *debugfs_root;
18 #define QDIO_DEBUGFS_NAME_LEN 10
20 void qdio_allocate_dbf(struct qdio_initialize *init_data,
21 struct qdio_irq *irq_ptr)
23 char text[20];
25 DBF_EVENT("qfmt:%1d", init_data->q_format);
26 DBF_HEX(init_data->adapter_name, 8);
27 DBF_EVENT("qpff%4x", init_data->qib_param_field_format);
28 DBF_HEX(&init_data->qib_param_field, sizeof(void *));
29 DBF_HEX(&init_data->input_slib_elements, sizeof(void *));
30 DBF_HEX(&init_data->output_slib_elements, sizeof(void *));
31 DBF_EVENT("niq:%1d noq:%1d", init_data->no_input_qs,
32 init_data->no_output_qs);
33 DBF_HEX(&init_data->input_handler, sizeof(void *));
34 DBF_HEX(&init_data->output_handler, sizeof(void *));
35 DBF_HEX(&init_data->int_parm, sizeof(long));
36 DBF_HEX(&init_data->flags, sizeof(long));
37 DBF_HEX(&init_data->input_sbal_addr_array, sizeof(void *));
38 DBF_HEX(&init_data->output_sbal_addr_array, sizeof(void *));
39 DBF_EVENT("irq:%8lx", (unsigned long)irq_ptr);
41 /* allocate trace view for the interface */
42 snprintf(text, 20, "qdio_%s", dev_name(&init_data->cdev->dev));
43 irq_ptr->debug_area = debug_register(text, 2, 1, 16);
44 debug_register_view(irq_ptr->debug_area, &debug_hex_ascii_view);
45 debug_set_level(irq_ptr->debug_area, DBF_WARN);
46 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf created");
49 static int qstat_show(struct seq_file *m, void *v)
51 unsigned char state;
52 struct qdio_q *q = m->private;
53 int i;
55 if (!q)
56 return 0;
58 seq_printf(m, "device state indicator: %d\n", *(u32 *)q->irq_ptr->dsci);
59 seq_printf(m, "nr_used: %d\n", atomic_read(&q->nr_buf_used));
60 seq_printf(m, "ftc: %d\n", q->first_to_check);
61 seq_printf(m, "last_move: %d\n", q->last_move);
62 seq_printf(m, "polling: %d\n", q->u.in.polling);
63 seq_printf(m, "ack start: %d\n", q->u.in.ack_start);
64 seq_printf(m, "ack count: %d\n", q->u.in.ack_count);
65 seq_printf(m, "slsb buffer states:\n");
66 seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
68 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
69 debug_get_buf_state(q, i, &state);
70 switch (state) {
71 case SLSB_P_INPUT_NOT_INIT:
72 case SLSB_P_OUTPUT_NOT_INIT:
73 seq_printf(m, "N");
74 break;
75 case SLSB_P_INPUT_PRIMED:
76 case SLSB_CU_OUTPUT_PRIMED:
77 seq_printf(m, "+");
78 break;
79 case SLSB_P_INPUT_ACK:
80 seq_printf(m, "A");
81 break;
82 case SLSB_P_INPUT_ERROR:
83 case SLSB_P_OUTPUT_ERROR:
84 seq_printf(m, "x");
85 break;
86 case SLSB_CU_INPUT_EMPTY:
87 case SLSB_P_OUTPUT_EMPTY:
88 seq_printf(m, "-");
89 break;
90 case SLSB_P_INPUT_HALTED:
91 case SLSB_P_OUTPUT_HALTED:
92 seq_printf(m, ".");
93 break;
94 default:
95 seq_printf(m, "?");
97 if (i == 63)
98 seq_printf(m, "\n");
100 seq_printf(m, "\n");
101 seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
102 return 0;
105 static ssize_t qstat_seq_write(struct file *file, const char __user *buf,
106 size_t count, loff_t *off)
108 struct seq_file *seq = file->private_data;
109 struct qdio_q *q = seq->private;
111 if (!q)
112 return 0;
114 if (q->is_input_q)
115 xchg(q->irq_ptr->dsci, 1);
116 local_bh_disable();
117 tasklet_schedule(&q->tasklet);
118 local_bh_enable();
119 return count;
122 static int qstat_seq_open(struct inode *inode, struct file *filp)
124 return single_open(filp, qstat_show,
125 filp->f_path.dentry->d_inode->i_private);
128 static const struct file_operations debugfs_fops = {
129 .owner = THIS_MODULE,
130 .open = qstat_seq_open,
131 .read = seq_read,
132 .write = qstat_seq_write,
133 .llseek = seq_lseek,
134 .release = single_release,
137 static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev)
139 char name[QDIO_DEBUGFS_NAME_LEN];
141 snprintf(name, QDIO_DEBUGFS_NAME_LEN, "%s_%d",
142 q->is_input_q ? "input" : "output",
143 q->nr);
144 q->debugfs_q = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR,
145 q->irq_ptr->debugfs_dev, q, &debugfs_fops);
146 if (IS_ERR(q->debugfs_q))
147 q->debugfs_q = NULL;
150 void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
152 struct qdio_q *q;
153 int i;
155 irq_ptr->debugfs_dev = debugfs_create_dir(dev_name(&cdev->dev),
156 debugfs_root);
157 if (IS_ERR(irq_ptr->debugfs_dev))
158 irq_ptr->debugfs_dev = NULL;
159 for_each_input_queue(irq_ptr, q, i)
160 setup_debugfs_entry(q, cdev);
161 for_each_output_queue(irq_ptr, q, i)
162 setup_debugfs_entry(q, cdev);
165 void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
167 struct qdio_q *q;
168 int i;
170 for_each_input_queue(irq_ptr, q, i)
171 debugfs_remove(q->debugfs_q);
172 for_each_output_queue(irq_ptr, q, i)
173 debugfs_remove(q->debugfs_q);
174 debugfs_remove(irq_ptr->debugfs_dev);
177 int __init qdio_debug_init(void)
179 debugfs_root = debugfs_create_dir("qdio", NULL);
181 qdio_dbf_setup = debug_register("qdio_setup", 16, 1, 16);
182 debug_register_view(qdio_dbf_setup, &debug_hex_ascii_view);
183 debug_set_level(qdio_dbf_setup, DBF_INFO);
184 DBF_EVENT("dbf created\n");
186 qdio_dbf_error = debug_register("qdio_error", 4, 1, 16);
187 debug_register_view(qdio_dbf_error, &debug_hex_ascii_view);
188 debug_set_level(qdio_dbf_error, DBF_INFO);
189 DBF_ERROR("dbf created\n");
190 return 0;
193 void qdio_debug_exit(void)
195 debugfs_remove(debugfs_root);
196 if (qdio_dbf_setup)
197 debug_unregister(qdio_dbf_setup);
198 if (qdio_dbf_error)
199 debug_unregister(qdio_dbf_error);