2 * Copyright IBM Corp. 2008, 2009
4 * Author: Jan Glauber (jang@linux.vnet.ibm.com)
6 #include <linux/seq_file.h>
7 #include <linux/debugfs.h>
8 #include <linux/uaccess.h>
9 #include <linux/export.h>
10 #include <linux/slab.h>
11 #include <asm/debug.h>
12 #include "qdio_debug.h"
15 debug_info_t
*qdio_dbf_setup
;
16 debug_info_t
*qdio_dbf_error
;
18 static struct dentry
*debugfs_root
;
19 #define QDIO_DEBUGFS_NAME_LEN 10
20 #define QDIO_DBF_NAME_LEN 20
22 struct qdio_dbf_entry
{
23 char dbf_name
[QDIO_DBF_NAME_LEN
];
24 debug_info_t
*dbf_info
;
25 struct list_head dbf_list
;
28 static LIST_HEAD(qdio_dbf_list
);
29 static DEFINE_MUTEX(qdio_dbf_list_mutex
);
31 static debug_info_t
*qdio_get_dbf_entry(char *name
)
33 struct qdio_dbf_entry
*entry
;
34 debug_info_t
*rc
= NULL
;
36 mutex_lock(&qdio_dbf_list_mutex
);
37 list_for_each_entry(entry
, &qdio_dbf_list
, dbf_list
) {
38 if (strcmp(entry
->dbf_name
, name
) == 0) {
43 mutex_unlock(&qdio_dbf_list_mutex
);
47 static void qdio_clear_dbf_list(void)
49 struct qdio_dbf_entry
*entry
, *tmp
;
51 mutex_lock(&qdio_dbf_list_mutex
);
52 list_for_each_entry_safe(entry
, tmp
, &qdio_dbf_list
, dbf_list
) {
53 list_del(&entry
->dbf_list
);
54 debug_unregister(entry
->dbf_info
);
57 mutex_unlock(&qdio_dbf_list_mutex
);
60 int qdio_allocate_dbf(struct qdio_initialize
*init_data
,
61 struct qdio_irq
*irq_ptr
)
63 char text
[QDIO_DBF_NAME_LEN
];
64 struct qdio_dbf_entry
*new_entry
;
66 DBF_EVENT("qfmt:%1d", init_data
->q_format
);
67 DBF_HEX(init_data
->adapter_name
, 8);
68 DBF_EVENT("qpff%4x", init_data
->qib_param_field_format
);
69 DBF_HEX(&init_data
->qib_param_field
, sizeof(void *));
70 DBF_HEX(&init_data
->input_slib_elements
, sizeof(void *));
71 DBF_HEX(&init_data
->output_slib_elements
, sizeof(void *));
72 DBF_EVENT("niq:%1d noq:%1d", init_data
->no_input_qs
,
73 init_data
->no_output_qs
);
74 DBF_HEX(&init_data
->input_handler
, sizeof(void *));
75 DBF_HEX(&init_data
->output_handler
, sizeof(void *));
76 DBF_HEX(&init_data
->int_parm
, sizeof(long));
77 DBF_HEX(&init_data
->input_sbal_addr_array
, sizeof(void *));
78 DBF_HEX(&init_data
->output_sbal_addr_array
, sizeof(void *));
79 DBF_EVENT("irq:%8lx", (unsigned long)irq_ptr
);
81 /* allocate trace view for the interface */
82 snprintf(text
, QDIO_DBF_NAME_LEN
, "qdio_%s",
83 dev_name(&init_data
->cdev
->dev
));
84 irq_ptr
->debug_area
= qdio_get_dbf_entry(text
);
85 if (irq_ptr
->debug_area
)
86 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf reused");
88 irq_ptr
->debug_area
= debug_register(text
, 2, 1, 16);
89 if (!irq_ptr
->debug_area
)
91 if (debug_register_view(irq_ptr
->debug_area
,
92 &debug_hex_ascii_view
)) {
93 debug_unregister(irq_ptr
->debug_area
);
96 debug_set_level(irq_ptr
->debug_area
, DBF_WARN
);
97 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf created");
98 new_entry
= kzalloc(sizeof(struct qdio_dbf_entry
), GFP_KERNEL
);
100 debug_unregister(irq_ptr
->debug_area
);
103 strlcpy(new_entry
->dbf_name
, text
, QDIO_DBF_NAME_LEN
);
104 new_entry
->dbf_info
= irq_ptr
->debug_area
;
105 mutex_lock(&qdio_dbf_list_mutex
);
106 list_add(&new_entry
->dbf_list
, &qdio_dbf_list
);
107 mutex_unlock(&qdio_dbf_list_mutex
);
112 static int qstat_show(struct seq_file
*m
, void *v
)
115 struct qdio_q
*q
= m
->private;
121 seq_printf(m
, "Timestamp: %Lx Last AI: %Lx\n",
122 q
->timestamp
, last_ai_time
);
123 seq_printf(m
, "nr_used: %d ftc: %d last_move: %d\n",
124 atomic_read(&q
->nr_buf_used
),
125 q
->first_to_check
, q
->last_move
);
127 seq_printf(m
, "polling: %d ack start: %d ack count: %d\n",
128 q
->u
.in
.polling
, q
->u
.in
.ack_start
,
130 seq_printf(m
, "DSCI: %d IRQs disabled: %u\n",
131 *(u32
*)q
->irq_ptr
->dsci
,
132 test_bit(QDIO_QUEUE_IRQS_DISABLED
,
133 &q
->u
.in
.queue_irq_state
));
135 seq_printf(m
, "SBAL states:\n");
136 seq_printf(m
, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
138 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; i
++) {
139 debug_get_buf_state(q
, i
, &state
);
141 case SLSB_P_INPUT_NOT_INIT
:
142 case SLSB_P_OUTPUT_NOT_INIT
:
145 case SLSB_P_OUTPUT_PENDING
:
148 case SLSB_P_INPUT_PRIMED
:
149 case SLSB_CU_OUTPUT_PRIMED
:
152 case SLSB_P_INPUT_ACK
:
155 case SLSB_P_INPUT_ERROR
:
156 case SLSB_P_OUTPUT_ERROR
:
159 case SLSB_CU_INPUT_EMPTY
:
160 case SLSB_P_OUTPUT_EMPTY
:
163 case SLSB_P_INPUT_HALTED
:
164 case SLSB_P_OUTPUT_HALTED
:
174 seq_printf(m
, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
176 seq_printf(m
, "\nSBAL statistics:");
177 if (!q
->irq_ptr
->perf_stat_enabled
) {
178 seq_printf(m
, " disabled\n");
182 seq_printf(m
, "\n1 2.. 4.. 8.. "
183 "16.. 32.. 64.. 127\n");
184 for (i
= 0; i
< ARRAY_SIZE(q
->q_stats
.nr_sbals
); i
++)
185 seq_printf(m
, "%-10u ", q
->q_stats
.nr_sbals
[i
]);
186 seq_printf(m
, "\nError NOP Total\n%-10u %-10u %-10u\n\n",
187 q
->q_stats
.nr_sbal_error
, q
->q_stats
.nr_sbal_nop
,
188 q
->q_stats
.nr_sbal_total
);
192 static int qstat_seq_open(struct inode
*inode
, struct file
*filp
)
194 return single_open(filp
, qstat_show
,
195 file_inode(filp
)->i_private
);
198 static const struct file_operations debugfs_fops
= {
199 .owner
= THIS_MODULE
,
200 .open
= qstat_seq_open
,
203 .release
= single_release
,
206 static char *qperf_names
[] = {
207 "Assumed adapter interrupts",
210 "Inbound tasklet runs",
211 "Inbound tasklet resched",
212 "Inbound tasklet resched2",
213 "Outbound tasklet runs",
219 "Inbound stop_polling",
220 "Inbound queue full",
223 "Outbound queue full",
224 "Outbound fast_requeue",
225 "Outbound target_full",
227 "QEBSM eqbs partial",
229 "QEBSM sqbs partial",
230 "Discarded interrupts"
233 static int qperf_show(struct seq_file
*m
, void *v
)
235 struct qdio_irq
*irq_ptr
= m
->private;
241 if (!irq_ptr
->perf_stat_enabled
) {
242 seq_printf(m
, "disabled\n");
245 stat
= (unsigned int *)&irq_ptr
->perf_stat
;
247 for (i
= 0; i
< ARRAY_SIZE(qperf_names
); i
++)
248 seq_printf(m
, "%26s:\t%u\n",
249 qperf_names
[i
], *(stat
+ i
));
253 static ssize_t
qperf_seq_write(struct file
*file
, const char __user
*ubuf
,
254 size_t count
, loff_t
*off
)
256 struct seq_file
*seq
= file
->private_data
;
257 struct qdio_irq
*irq_ptr
= seq
->private;
265 ret
= kstrtoul_from_user(ubuf
, count
, 10, &val
);
271 irq_ptr
->perf_stat_enabled
= 0;
272 memset(&irq_ptr
->perf_stat
, 0, sizeof(irq_ptr
->perf_stat
));
273 for_each_input_queue(irq_ptr
, q
, i
)
274 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
275 for_each_output_queue(irq_ptr
, q
, i
)
276 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
279 irq_ptr
->perf_stat_enabled
= 1;
285 static int qperf_seq_open(struct inode
*inode
, struct file
*filp
)
287 return single_open(filp
, qperf_show
,
288 file_inode(filp
)->i_private
);
291 static const struct file_operations debugfs_perf_fops
= {
292 .owner
= THIS_MODULE
,
293 .open
= qperf_seq_open
,
295 .write
= qperf_seq_write
,
297 .release
= single_release
,
300 static void setup_debugfs_entry(struct qdio_q
*q
)
302 char name
[QDIO_DEBUGFS_NAME_LEN
];
304 snprintf(name
, QDIO_DEBUGFS_NAME_LEN
, "%s_%d",
305 q
->is_input_q
? "input" : "output",
307 q
->debugfs_q
= debugfs_create_file(name
, S_IFREG
| S_IRUGO
| S_IWUSR
,
308 q
->irq_ptr
->debugfs_dev
, q
, &debugfs_fops
);
309 if (IS_ERR(q
->debugfs_q
))
313 void qdio_setup_debug_entries(struct qdio_irq
*irq_ptr
, struct ccw_device
*cdev
)
318 irq_ptr
->debugfs_dev
= debugfs_create_dir(dev_name(&cdev
->dev
),
320 if (IS_ERR(irq_ptr
->debugfs_dev
))
321 irq_ptr
->debugfs_dev
= NULL
;
323 irq_ptr
->debugfs_perf
= debugfs_create_file("statistics",
324 S_IFREG
| S_IRUGO
| S_IWUSR
,
325 irq_ptr
->debugfs_dev
, irq_ptr
,
327 if (IS_ERR(irq_ptr
->debugfs_perf
))
328 irq_ptr
->debugfs_perf
= NULL
;
330 for_each_input_queue(irq_ptr
, q
, i
)
331 setup_debugfs_entry(q
);
332 for_each_output_queue(irq_ptr
, q
, i
)
333 setup_debugfs_entry(q
);
336 void qdio_shutdown_debug_entries(struct qdio_irq
*irq_ptr
)
341 for_each_input_queue(irq_ptr
, q
, i
)
342 debugfs_remove(q
->debugfs_q
);
343 for_each_output_queue(irq_ptr
, q
, i
)
344 debugfs_remove(q
->debugfs_q
);
345 debugfs_remove(irq_ptr
->debugfs_perf
);
346 debugfs_remove(irq_ptr
->debugfs_dev
);
349 int __init
qdio_debug_init(void)
351 debugfs_root
= debugfs_create_dir("qdio", NULL
);
353 qdio_dbf_setup
= debug_register("qdio_setup", 16, 1, 16);
354 debug_register_view(qdio_dbf_setup
, &debug_hex_ascii_view
);
355 debug_set_level(qdio_dbf_setup
, DBF_INFO
);
356 DBF_EVENT("dbf created\n");
358 qdio_dbf_error
= debug_register("qdio_error", 4, 1, 16);
359 debug_register_view(qdio_dbf_error
, &debug_hex_ascii_view
);
360 debug_set_level(qdio_dbf_error
, DBF_INFO
);
361 DBF_ERROR("dbf created\n");
365 void qdio_debug_exit(void)
367 qdio_clear_dbf_list();
368 debugfs_remove(debugfs_root
);
370 debug_unregister(qdio_dbf_setup
);
372 debug_unregister(qdio_dbf_error
);