1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2008, 2009
5 * Author: Jan Glauber (jang@linux.vnet.ibm.com)
7 #include <linux/seq_file.h>
8 #include <linux/debugfs.h>
9 #include <linux/uaccess.h>
10 #include <linux/export.h>
11 #include <linux/slab.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 QDIO_DEBUGFS_NAME_LEN 10
21 #define QDIO_DBF_NAME_LEN 20
23 struct qdio_dbf_entry
{
24 char dbf_name
[QDIO_DBF_NAME_LEN
];
25 debug_info_t
*dbf_info
;
26 struct list_head dbf_list
;
29 static LIST_HEAD(qdio_dbf_list
);
30 static DEFINE_MUTEX(qdio_dbf_list_mutex
);
32 static debug_info_t
*qdio_get_dbf_entry(char *name
)
34 struct qdio_dbf_entry
*entry
;
35 debug_info_t
*rc
= NULL
;
37 mutex_lock(&qdio_dbf_list_mutex
);
38 list_for_each_entry(entry
, &qdio_dbf_list
, dbf_list
) {
39 if (strcmp(entry
->dbf_name
, name
) == 0) {
44 mutex_unlock(&qdio_dbf_list_mutex
);
48 static void qdio_clear_dbf_list(void)
50 struct qdio_dbf_entry
*entry
, *tmp
;
52 mutex_lock(&qdio_dbf_list_mutex
);
53 list_for_each_entry_safe(entry
, tmp
, &qdio_dbf_list
, dbf_list
) {
54 list_del(&entry
->dbf_list
);
55 debug_unregister(entry
->dbf_info
);
58 mutex_unlock(&qdio_dbf_list_mutex
);
61 int qdio_allocate_dbf(struct qdio_irq
*irq_ptr
)
63 char text
[QDIO_DBF_NAME_LEN
];
64 struct qdio_dbf_entry
*new_entry
;
66 DBF_EVENT("irq:%8lx", (unsigned long)irq_ptr
);
68 /* allocate trace view for the interface */
69 snprintf(text
, QDIO_DBF_NAME_LEN
, "qdio_%s",
70 dev_name(&irq_ptr
->cdev
->dev
));
71 irq_ptr
->debug_area
= qdio_get_dbf_entry(text
);
72 if (irq_ptr
->debug_area
)
73 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf reused");
75 irq_ptr
->debug_area
= debug_register(text
, 2, 1, 16);
76 if (!irq_ptr
->debug_area
)
78 if (debug_register_view(irq_ptr
->debug_area
,
79 &debug_hex_ascii_view
)) {
80 debug_unregister(irq_ptr
->debug_area
);
83 debug_set_level(irq_ptr
->debug_area
, DBF_WARN
);
84 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf created");
85 new_entry
= kzalloc(sizeof(struct qdio_dbf_entry
), GFP_KERNEL
);
87 debug_unregister(irq_ptr
->debug_area
);
90 strlcpy(new_entry
->dbf_name
, text
, QDIO_DBF_NAME_LEN
);
91 new_entry
->dbf_info
= irq_ptr
->debug_area
;
92 mutex_lock(&qdio_dbf_list_mutex
);
93 list_add(&new_entry
->dbf_list
, &qdio_dbf_list
);
94 mutex_unlock(&qdio_dbf_list_mutex
);
99 static int qstat_show(struct seq_file
*m
, void *v
)
102 struct qdio_q
*q
= m
->private;
108 seq_printf(m
, "Timestamp: %Lx Last AI: %Lx\n",
109 q
->timestamp
, last_ai_time
);
110 seq_printf(m
, "nr_used: %d ftc: %d\n",
111 atomic_read(&q
->nr_buf_used
), q
->first_to_check
);
113 seq_printf(m
, "batch start: %u batch count: %u\n",
114 q
->u
.in
.batch_start
, q
->u
.in
.batch_count
);
115 seq_printf(m
, "DSCI: %x IRQs disabled: %u\n",
116 *(u8
*)q
->irq_ptr
->dsci
,
117 test_bit(QDIO_IRQ_DISABLED
,
118 &q
->irq_ptr
->poll_state
));
120 seq_printf(m
, "SBAL states:\n");
121 seq_printf(m
, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
123 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; i
++) {
124 debug_get_buf_state(q
, i
, &state
);
126 case SLSB_P_INPUT_NOT_INIT
:
127 case SLSB_P_OUTPUT_NOT_INIT
:
130 case SLSB_P_OUTPUT_PENDING
:
133 case SLSB_P_INPUT_PRIMED
:
134 case SLSB_CU_OUTPUT_PRIMED
:
137 case SLSB_P_INPUT_ACK
:
140 case SLSB_P_INPUT_ERROR
:
141 case SLSB_P_OUTPUT_ERROR
:
144 case SLSB_CU_INPUT_EMPTY
:
145 case SLSB_P_OUTPUT_EMPTY
:
148 case SLSB_P_INPUT_HALTED
:
149 case SLSB_P_OUTPUT_HALTED
:
159 seq_printf(m
, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
161 seq_printf(m
, "\nSBAL statistics:");
162 if (!q
->irq_ptr
->perf_stat_enabled
) {
163 seq_printf(m
, " disabled\n");
167 seq_printf(m
, "\n1 2.. 4.. 8.. "
168 "16.. 32.. 64.. 128\n");
169 for (i
= 0; i
< ARRAY_SIZE(q
->q_stats
.nr_sbals
); i
++)
170 seq_printf(m
, "%-10u ", q
->q_stats
.nr_sbals
[i
]);
171 seq_printf(m
, "\nError NOP Total\n%-10u %-10u %-10u\n\n",
172 q
->q_stats
.nr_sbal_error
, q
->q_stats
.nr_sbal_nop
,
173 q
->q_stats
.nr_sbal_total
);
177 DEFINE_SHOW_ATTRIBUTE(qstat
);
179 static int ssqd_show(struct seq_file
*m
, void *v
)
181 struct ccw_device
*cdev
= m
->private;
182 struct qdio_ssqd_desc ssqd
;
185 rc
= qdio_get_ssqd_desc(cdev
, &ssqd
);
189 seq_hex_dump(m
, "", DUMP_PREFIX_NONE
, 16, 4, &ssqd
, sizeof(ssqd
),
194 DEFINE_SHOW_ATTRIBUTE(ssqd
);
196 static char *qperf_names
[] = {
197 "Assumed adapter interrupts",
200 "Inbound tasklet runs",
201 "Inbound tasklet resched",
202 "Inbound tasklet resched2",
203 "Outbound tasklet runs",
209 "Inbound stop_polling",
210 "Inbound queue full",
213 "Outbound queue full",
214 "Outbound fast_requeue",
215 "Outbound target_full",
217 "QEBSM eqbs partial",
219 "QEBSM sqbs partial",
220 "Discarded interrupts"
223 static int qperf_show(struct seq_file
*m
, void *v
)
225 struct qdio_irq
*irq_ptr
= m
->private;
231 if (!irq_ptr
->perf_stat_enabled
) {
232 seq_printf(m
, "disabled\n");
235 stat
= (unsigned int *)&irq_ptr
->perf_stat
;
237 for (i
= 0; i
< ARRAY_SIZE(qperf_names
); i
++)
238 seq_printf(m
, "%26s:\t%u\n",
239 qperf_names
[i
], *(stat
+ i
));
243 static ssize_t
qperf_seq_write(struct file
*file
, const char __user
*ubuf
,
244 size_t count
, loff_t
*off
)
246 struct seq_file
*seq
= file
->private_data
;
247 struct qdio_irq
*irq_ptr
= seq
->private;
255 ret
= kstrtoul_from_user(ubuf
, count
, 10, &val
);
261 irq_ptr
->perf_stat_enabled
= 0;
262 memset(&irq_ptr
->perf_stat
, 0, sizeof(irq_ptr
->perf_stat
));
263 for_each_input_queue(irq_ptr
, q
, i
)
264 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
265 for_each_output_queue(irq_ptr
, q
, i
)
266 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
269 irq_ptr
->perf_stat_enabled
= 1;
275 static int qperf_seq_open(struct inode
*inode
, struct file
*filp
)
277 return single_open(filp
, qperf_show
,
278 file_inode(filp
)->i_private
);
281 static const struct file_operations debugfs_perf_fops
= {
282 .owner
= THIS_MODULE
,
283 .open
= qperf_seq_open
,
285 .write
= qperf_seq_write
,
287 .release
= single_release
,
290 static void setup_debugfs_entry(struct dentry
*parent
, struct qdio_q
*q
)
292 char name
[QDIO_DEBUGFS_NAME_LEN
];
294 snprintf(name
, QDIO_DEBUGFS_NAME_LEN
, "%s_%d",
295 q
->is_input_q
? "input" : "output",
297 debugfs_create_file(name
, 0444, parent
, q
, &qstat_fops
);
300 void qdio_setup_debug_entries(struct qdio_irq
*irq_ptr
)
305 irq_ptr
->debugfs_dev
= debugfs_create_dir(dev_name(&irq_ptr
->cdev
->dev
),
307 debugfs_create_file("statistics", S_IFREG
| S_IRUGO
| S_IWUSR
,
308 irq_ptr
->debugfs_dev
, irq_ptr
, &debugfs_perf_fops
);
309 debugfs_create_file("ssqd", 0444, irq_ptr
->debugfs_dev
, irq_ptr
->cdev
,
312 for_each_input_queue(irq_ptr
, q
, i
)
313 setup_debugfs_entry(irq_ptr
->debugfs_dev
, q
);
314 for_each_output_queue(irq_ptr
, q
, i
)
315 setup_debugfs_entry(irq_ptr
->debugfs_dev
, q
);
318 void qdio_shutdown_debug_entries(struct qdio_irq
*irq_ptr
)
320 debugfs_remove_recursive(irq_ptr
->debugfs_dev
);
323 int __init
qdio_debug_init(void)
325 debugfs_root
= debugfs_create_dir("qdio", NULL
);
327 qdio_dbf_setup
= debug_register("qdio_setup", 16, 1, 16);
328 debug_register_view(qdio_dbf_setup
, &debug_hex_ascii_view
);
329 debug_set_level(qdio_dbf_setup
, DBF_INFO
);
330 DBF_EVENT("dbf created\n");
332 qdio_dbf_error
= debug_register("qdio_error", 4, 1, 16);
333 debug_register_view(qdio_dbf_error
, &debug_hex_ascii_view
);
334 debug_set_level(qdio_dbf_error
, DBF_INFO
);
335 DBF_ERROR("dbf created\n");
339 void qdio_debug_exit(void)
341 qdio_clear_dbf_list();
342 debugfs_remove_recursive(debugfs_root
);
343 debug_unregister(qdio_dbf_setup
);
344 debug_unregister(qdio_dbf_error
);