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_initialize
*init_data
,
62 struct qdio_irq
*irq_ptr
)
64 char text
[QDIO_DBF_NAME_LEN
];
65 struct qdio_dbf_entry
*new_entry
;
67 DBF_EVENT("qfmt:%1d", init_data
->q_format
);
68 DBF_HEX(init_data
->adapter_name
, 8);
69 DBF_EVENT("qpff%4x", init_data
->qib_param_field_format
);
70 DBF_HEX(&init_data
->qib_param_field
, sizeof(void *));
71 DBF_HEX(&init_data
->input_slib_elements
, sizeof(void *));
72 DBF_HEX(&init_data
->output_slib_elements
, sizeof(void *));
73 DBF_EVENT("niq:%1d noq:%1d", init_data
->no_input_qs
,
74 init_data
->no_output_qs
);
75 DBF_HEX(&init_data
->input_handler
, sizeof(void *));
76 DBF_HEX(&init_data
->output_handler
, sizeof(void *));
77 DBF_HEX(&init_data
->int_parm
, sizeof(long));
78 DBF_HEX(&init_data
->input_sbal_addr_array
, sizeof(void *));
79 DBF_HEX(&init_data
->output_sbal_addr_array
, sizeof(void *));
80 DBF_EVENT("irq:%8lx", (unsigned long)irq_ptr
);
82 /* allocate trace view for the interface */
83 snprintf(text
, QDIO_DBF_NAME_LEN
, "qdio_%s",
84 dev_name(&init_data
->cdev
->dev
));
85 irq_ptr
->debug_area
= qdio_get_dbf_entry(text
);
86 if (irq_ptr
->debug_area
)
87 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf reused");
89 irq_ptr
->debug_area
= debug_register(text
, 2, 1, 16);
90 if (!irq_ptr
->debug_area
)
92 if (debug_register_view(irq_ptr
->debug_area
,
93 &debug_hex_ascii_view
)) {
94 debug_unregister(irq_ptr
->debug_area
);
97 debug_set_level(irq_ptr
->debug_area
, DBF_WARN
);
98 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf created");
99 new_entry
= kzalloc(sizeof(struct qdio_dbf_entry
), GFP_KERNEL
);
101 debug_unregister(irq_ptr
->debug_area
);
104 strlcpy(new_entry
->dbf_name
, text
, QDIO_DBF_NAME_LEN
);
105 new_entry
->dbf_info
= irq_ptr
->debug_area
;
106 mutex_lock(&qdio_dbf_list_mutex
);
107 list_add(&new_entry
->dbf_list
, &qdio_dbf_list
);
108 mutex_unlock(&qdio_dbf_list_mutex
);
113 static int qstat_show(struct seq_file
*m
, void *v
)
116 struct qdio_q
*q
= m
->private;
122 seq_printf(m
, "Timestamp: %Lx Last AI: %Lx\n",
123 q
->timestamp
, last_ai_time
);
124 seq_printf(m
, "nr_used: %d ftc: %d last_move: %d\n",
125 atomic_read(&q
->nr_buf_used
),
126 q
->first_to_check
, q
->last_move
);
128 seq_printf(m
, "polling: %d ack start: %d ack count: %d\n",
129 q
->u
.in
.polling
, q
->u
.in
.ack_start
,
131 seq_printf(m
, "DSCI: %d IRQs disabled: %u\n",
132 *(u32
*)q
->irq_ptr
->dsci
,
133 test_bit(QDIO_QUEUE_IRQS_DISABLED
,
134 &q
->u
.in
.queue_irq_state
));
136 seq_printf(m
, "SBAL states:\n");
137 seq_printf(m
, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
139 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; i
++) {
140 debug_get_buf_state(q
, i
, &state
);
142 case SLSB_P_INPUT_NOT_INIT
:
143 case SLSB_P_OUTPUT_NOT_INIT
:
146 case SLSB_P_OUTPUT_PENDING
:
149 case SLSB_P_INPUT_PRIMED
:
150 case SLSB_CU_OUTPUT_PRIMED
:
153 case SLSB_P_INPUT_ACK
:
156 case SLSB_P_INPUT_ERROR
:
157 case SLSB_P_OUTPUT_ERROR
:
160 case SLSB_CU_INPUT_EMPTY
:
161 case SLSB_P_OUTPUT_EMPTY
:
164 case SLSB_P_INPUT_HALTED
:
165 case SLSB_P_OUTPUT_HALTED
:
175 seq_printf(m
, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
177 seq_printf(m
, "\nSBAL statistics:");
178 if (!q
->irq_ptr
->perf_stat_enabled
) {
179 seq_printf(m
, " disabled\n");
183 seq_printf(m
, "\n1 2.. 4.. 8.. "
184 "16.. 32.. 64.. 127\n");
185 for (i
= 0; i
< ARRAY_SIZE(q
->q_stats
.nr_sbals
); i
++)
186 seq_printf(m
, "%-10u ", q
->q_stats
.nr_sbals
[i
]);
187 seq_printf(m
, "\nError NOP Total\n%-10u %-10u %-10u\n\n",
188 q
->q_stats
.nr_sbal_error
, q
->q_stats
.nr_sbal_nop
,
189 q
->q_stats
.nr_sbal_total
);
193 DEFINE_SHOW_ATTRIBUTE(qstat
);
195 static char *qperf_names
[] = {
196 "Assumed adapter interrupts",
199 "Inbound tasklet runs",
200 "Inbound tasklet resched",
201 "Inbound tasklet resched2",
202 "Outbound tasklet runs",
208 "Inbound stop_polling",
209 "Inbound queue full",
212 "Outbound queue full",
213 "Outbound fast_requeue",
214 "Outbound target_full",
216 "QEBSM eqbs partial",
218 "QEBSM sqbs partial",
219 "Discarded interrupts"
222 static int qperf_show(struct seq_file
*m
, void *v
)
224 struct qdio_irq
*irq_ptr
= m
->private;
230 if (!irq_ptr
->perf_stat_enabled
) {
231 seq_printf(m
, "disabled\n");
234 stat
= (unsigned int *)&irq_ptr
->perf_stat
;
236 for (i
= 0; i
< ARRAY_SIZE(qperf_names
); i
++)
237 seq_printf(m
, "%26s:\t%u\n",
238 qperf_names
[i
], *(stat
+ i
));
242 static ssize_t
qperf_seq_write(struct file
*file
, const char __user
*ubuf
,
243 size_t count
, loff_t
*off
)
245 struct seq_file
*seq
= file
->private_data
;
246 struct qdio_irq
*irq_ptr
= seq
->private;
254 ret
= kstrtoul_from_user(ubuf
, count
, 10, &val
);
260 irq_ptr
->perf_stat_enabled
= 0;
261 memset(&irq_ptr
->perf_stat
, 0, sizeof(irq_ptr
->perf_stat
));
262 for_each_input_queue(irq_ptr
, q
, i
)
263 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
264 for_each_output_queue(irq_ptr
, q
, i
)
265 memset(&q
->q_stats
, 0, sizeof(q
->q_stats
));
268 irq_ptr
->perf_stat_enabled
= 1;
274 static int qperf_seq_open(struct inode
*inode
, struct file
*filp
)
276 return single_open(filp
, qperf_show
,
277 file_inode(filp
)->i_private
);
280 static const struct file_operations debugfs_perf_fops
= {
281 .owner
= THIS_MODULE
,
282 .open
= qperf_seq_open
,
284 .write
= qperf_seq_write
,
286 .release
= single_release
,
289 static void setup_debugfs_entry(struct qdio_q
*q
)
291 char name
[QDIO_DEBUGFS_NAME_LEN
];
293 snprintf(name
, QDIO_DEBUGFS_NAME_LEN
, "%s_%d",
294 q
->is_input_q
? "input" : "output",
296 q
->debugfs_q
= debugfs_create_file(name
, 0444,
297 q
->irq_ptr
->debugfs_dev
, q
, &qstat_fops
);
298 if (IS_ERR(q
->debugfs_q
))
302 void qdio_setup_debug_entries(struct qdio_irq
*irq_ptr
, struct ccw_device
*cdev
)
307 irq_ptr
->debugfs_dev
= debugfs_create_dir(dev_name(&cdev
->dev
),
309 if (IS_ERR(irq_ptr
->debugfs_dev
))
310 irq_ptr
->debugfs_dev
= NULL
;
312 irq_ptr
->debugfs_perf
= debugfs_create_file("statistics",
313 S_IFREG
| S_IRUGO
| S_IWUSR
,
314 irq_ptr
->debugfs_dev
, irq_ptr
,
316 if (IS_ERR(irq_ptr
->debugfs_perf
))
317 irq_ptr
->debugfs_perf
= NULL
;
319 for_each_input_queue(irq_ptr
, q
, i
)
320 setup_debugfs_entry(q
);
321 for_each_output_queue(irq_ptr
, q
, i
)
322 setup_debugfs_entry(q
);
325 void qdio_shutdown_debug_entries(struct qdio_irq
*irq_ptr
)
330 for_each_input_queue(irq_ptr
, q
, i
)
331 debugfs_remove(q
->debugfs_q
);
332 for_each_output_queue(irq_ptr
, q
, i
)
333 debugfs_remove(q
->debugfs_q
);
334 debugfs_remove(irq_ptr
->debugfs_perf
);
335 debugfs_remove(irq_ptr
->debugfs_dev
);
338 int __init
qdio_debug_init(void)
340 debugfs_root
= debugfs_create_dir("qdio", NULL
);
342 qdio_dbf_setup
= debug_register("qdio_setup", 16, 1, 16);
343 debug_register_view(qdio_dbf_setup
, &debug_hex_ascii_view
);
344 debug_set_level(qdio_dbf_setup
, DBF_INFO
);
345 DBF_EVENT("dbf created\n");
347 qdio_dbf_error
= debug_register("qdio_error", 4, 1, 16);
348 debug_register_view(qdio_dbf_error
, &debug_hex_ascii_view
);
349 debug_set_level(qdio_dbf_error
, DBF_INFO
);
350 DBF_ERROR("dbf created\n");
354 void qdio_debug_exit(void)
356 qdio_clear_dbf_list();
357 debugfs_remove(debugfs_root
);
358 debug_unregister(qdio_dbf_setup
);
359 debug_unregister(qdio_dbf_error
);