Commit | Line | Data |
---|---|---|
779e6e1c JG |
1 | /* |
2 | * drivers/s390/cio/qdio_debug.c | |
3 | * | |
4 | * Copyright IBM Corp. 2008 | |
5 | * | |
6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) | |
7 | */ | |
8 | #include <linux/proc_fs.h> | |
9 | #include <linux/seq_file.h> | |
10 | #include <linux/debugfs.h> | |
11 | #include <asm/qdio.h> | |
12 | #include <asm/debug.h> | |
13 | #include "qdio_debug.h" | |
14 | #include "qdio.h" | |
15 | ||
16 | debug_info_t *qdio_dbf_setup; | |
22f99347 | 17 | debug_info_t *qdio_dbf_error; |
779e6e1c JG |
18 | |
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); | |
2c780914 | 23 | #define QDIO_DEBUGFS_NAME_LEN 40 |
779e6e1c | 24 | |
22f99347 JG |
25 | void qdio_allocate_dbf(struct qdio_initialize *init_data, |
26 | struct qdio_irq *irq_ptr) | |
779e6e1c | 27 | { |
22f99347 JG |
28 | char text[20]; |
29 | ||
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); | |
45 | ||
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"); | |
779e6e1c JG |
52 | } |
53 | ||
54 | static int qstat_show(struct seq_file *m, void *v) | |
55 | { | |
56 | unsigned char state; | |
57 | struct qdio_q *q = m->private; | |
58 | int i; | |
59 | ||
60 | if (!q) | |
61 | return 0; | |
62 | ||
50f769df | 63 | seq_printf(m, "device state indicator: %d\n", *(u32 *)q->irq_ptr->dsci); |
779e6e1c JG |
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); | |
e85dea0e | 66 | seq_printf(m, "last_move: %d\n", q->last_move); |
779e6e1c | 67 | seq_printf(m, "polling: %d\n", q->u.in.polling); |
e85dea0e | 68 | seq_printf(m, "ack start: %d\n", q->u.in.ack_start); |
50f769df | 69 | seq_printf(m, "ack count: %d\n", q->u.in.ack_count); |
779e6e1c | 70 | seq_printf(m, "slsb buffer states:\n"); |
50f769df | 71 | seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n"); |
779e6e1c JG |
72 | |
73 | qdio_siga_sync_q(q); | |
74 | for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) { | |
50f769df | 75 | get_buf_state(q, i, &state, 0); |
779e6e1c JG |
76 | switch (state) { |
77 | case SLSB_P_INPUT_NOT_INIT: | |
78 | case SLSB_P_OUTPUT_NOT_INIT: | |
79 | seq_printf(m, "N"); | |
80 | break; | |
81 | case SLSB_P_INPUT_PRIMED: | |
82 | case SLSB_CU_OUTPUT_PRIMED: | |
83 | seq_printf(m, "+"); | |
84 | break; | |
85 | case SLSB_P_INPUT_ACK: | |
86 | seq_printf(m, "A"); | |
87 | break; | |
88 | case SLSB_P_INPUT_ERROR: | |
89 | case SLSB_P_OUTPUT_ERROR: | |
90 | seq_printf(m, "x"); | |
91 | break; | |
92 | case SLSB_CU_INPUT_EMPTY: | |
93 | case SLSB_P_OUTPUT_EMPTY: | |
94 | seq_printf(m, "-"); | |
95 | break; | |
96 | case SLSB_P_INPUT_HALTED: | |
97 | case SLSB_P_OUTPUT_HALTED: | |
98 | seq_printf(m, "."); | |
99 | break; | |
100 | default: | |
101 | seq_printf(m, "?"); | |
102 | } | |
103 | if (i == 63) | |
104 | seq_printf(m, "\n"); | |
105 | } | |
106 | seq_printf(m, "\n"); | |
50f769df | 107 | seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n"); |
779e6e1c JG |
108 | return 0; |
109 | } | |
110 | ||
111 | static ssize_t qstat_seq_write(struct file *file, const char __user *buf, | |
112 | size_t count, loff_t *off) | |
113 | { | |
114 | struct seq_file *seq = file->private_data; | |
115 | struct qdio_q *q = seq->private; | |
116 | ||
117 | if (!q) | |
118 | return 0; | |
119 | ||
120 | if (q->is_input_q) | |
121 | xchg(q->irq_ptr->dsci, 1); | |
122 | local_bh_disable(); | |
123 | tasklet_schedule(&q->tasklet); | |
124 | local_bh_enable(); | |
125 | return count; | |
126 | } | |
127 | ||
128 | static int qstat_seq_open(struct inode *inode, struct file *filp) | |
129 | { | |
130 | return single_open(filp, qstat_show, | |
131 | filp->f_path.dentry->d_inode->i_private); | |
132 | } | |
133 | ||
779e6e1c JG |
134 | static void remove_debugfs_entry(struct qdio_q *q) |
135 | { | |
136 | int i; | |
137 | ||
138 | for (i = 0; i < MAX_DEBUGFS_QUEUES; i++) { | |
139 | if (!debugfs_queues[i]) | |
140 | continue; | |
141 | if (debugfs_queues[i]->d_inode->i_private == q) { | |
142 | debugfs_remove(debugfs_queues[i]); | |
143 | debugfs_queues[i] = NULL; | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | static struct file_operations debugfs_fops = { | |
149 | .owner = THIS_MODULE, | |
150 | .open = qstat_seq_open, | |
151 | .read = seq_read, | |
152 | .write = qstat_seq_write, | |
153 | .llseek = seq_lseek, | |
154 | .release = single_release, | |
155 | }; | |
156 | ||
157 | static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev) | |
158 | { | |
159 | int i = 0; | |
2c780914 | 160 | char name[QDIO_DEBUGFS_NAME_LEN]; |
779e6e1c JG |
161 | |
162 | while (debugfs_queues[i] != NULL) { | |
163 | i++; | |
164 | if (i >= MAX_DEBUGFS_QUEUES) | |
165 | return; | |
166 | } | |
2c780914 JG |
167 | snprintf(name, QDIO_DEBUGFS_NAME_LEN, "%s_%s_%d", |
168 | dev_name(&cdev->dev), | |
169 | q->is_input_q ? "input" : "output", | |
170 | q->nr); | |
779e6e1c JG |
171 | debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR, |
172 | debugfs_root, q, &debugfs_fops); | |
19cdd08b JG |
173 | if (IS_ERR(debugfs_queues[i])) |
174 | debugfs_queues[i] = NULL; | |
779e6e1c JG |
175 | } |
176 | ||
177 | void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) | |
178 | { | |
179 | struct qdio_q *q; | |
180 | int i; | |
181 | ||
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); | |
188 | } | |
189 | ||
190 | void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) | |
191 | { | |
192 | struct qdio_q *q; | |
193 | int i; | |
194 | ||
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); | |
201 | } | |
202 | ||
203 | int __init qdio_debug_init(void) | |
204 | { | |
205 | debugfs_root = debugfs_create_dir("qdio_queues", NULL); | |
22f99347 JG |
206 | |
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"); | |
211 | ||
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"); | |
216 | return 0; | |
779e6e1c JG |
217 | } |
218 | ||
219 | void qdio_debug_exit(void) | |
220 | { | |
221 | debugfs_remove(debugfs_root); | |
22f99347 JG |
222 | if (qdio_dbf_setup) |
223 | debug_unregister(qdio_dbf_setup); | |
224 | if (qdio_dbf_error) | |
225 | debug_unregister(qdio_dbf_error); | |
779e6e1c | 226 | } |