Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/qdio_debug.c |
| 3 | * |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008,2009 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 5 | * |
| 6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) |
| 7 | */ |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 8 | #include <linux/seq_file.h> |
| 9 | #include <linux/debugfs.h> |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 10 | #include <asm/debug.h> |
| 11 | #include "qdio_debug.h" |
| 12 | #include "qdio.h" |
| 13 | |
| 14 | debug_info_t *qdio_dbf_setup; |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 15 | debug_info_t *qdio_dbf_error; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 16 | |
| 17 | static struct dentry *debugfs_root; |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 18 | #define QDIO_DEBUGFS_NAME_LEN 10 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 19 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 20 | void qdio_allocate_dbf(struct qdio_initialize *init_data, |
| 21 | struct qdio_irq *irq_ptr) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 22 | { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 23 | char text[20]; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 24 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 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); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 40 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 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"); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static int qstat_show(struct seq_file *m, void *v) |
| 50 | { |
| 51 | unsigned char state; |
| 52 | struct qdio_q *q = m->private; |
| 53 | int i; |
| 54 | |
| 55 | if (!q) |
| 56 | return 0; |
| 57 | |
Jan Glauber | 50f769d | 2008-12-25 13:38:47 +0100 | [diff] [blame] | 58 | seq_printf(m, "device state indicator: %d\n", *(u32 *)q->irq_ptr->dsci); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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); |
Jan Glauber | e85dea0 | 2009-03-26 15:24:29 +0100 | [diff] [blame] | 61 | seq_printf(m, "last_move: %d\n", q->last_move); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 62 | seq_printf(m, "polling: %d\n", q->u.in.polling); |
Jan Glauber | e85dea0 | 2009-03-26 15:24:29 +0100 | [diff] [blame] | 63 | seq_printf(m, "ack start: %d\n", q->u.in.ack_start); |
Jan Glauber | 50f769d | 2008-12-25 13:38:47 +0100 | [diff] [blame] | 64 | seq_printf(m, "ack count: %d\n", q->u.in.ack_count); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 65 | seq_printf(m, "slsb buffer states:\n"); |
Jan Glauber | 50f769d | 2008-12-25 13:38:47 +0100 | [diff] [blame] | 66 | seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n"); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 67 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 68 | for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) { |
Jan Glauber | 60b5df2 | 2009-06-22 12:08:10 +0200 | [diff] [blame] | 69 | debug_get_buf_state(q, i, &state); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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, "?"); |
| 96 | } |
| 97 | if (i == 63) |
| 98 | seq_printf(m, "\n"); |
| 99 | } |
| 100 | seq_printf(m, "\n"); |
Jan Glauber | 50f769d | 2008-12-25 13:38:47 +0100 | [diff] [blame] | 101 | seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n"); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static ssize_t qstat_seq_write(struct file *file, const char __user *buf, |
| 106 | size_t count, loff_t *off) |
| 107 | { |
| 108 | struct seq_file *seq = file->private_data; |
| 109 | struct qdio_q *q = seq->private; |
| 110 | |
| 111 | if (!q) |
| 112 | return 0; |
| 113 | |
| 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; |
| 120 | } |
| 121 | |
| 122 | static int qstat_seq_open(struct inode *inode, struct file *filp) |
| 123 | { |
| 124 | return single_open(filp, qstat_show, |
| 125 | filp->f_path.dentry->d_inode->i_private); |
| 126 | } |
| 127 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 128 | static const struct file_operations debugfs_fops = { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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, |
| 135 | }; |
| 136 | |
| 137 | static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev) |
| 138 | { |
Jan Glauber | 2c78091 | 2008-10-28 11:10:14 +0100 | [diff] [blame] | 139 | char name[QDIO_DEBUGFS_NAME_LEN]; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 140 | |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 141 | snprintf(name, QDIO_DEBUGFS_NAME_LEN, "%s_%d", |
Jan Glauber | 2c78091 | 2008-10-28 11:10:14 +0100 | [diff] [blame] | 142 | q->is_input_q ? "input" : "output", |
| 143 | q->nr); |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 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; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) |
| 151 | { |
| 152 | struct qdio_q *q; |
| 153 | int i; |
| 154 | |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 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; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 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); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) |
| 166 | { |
| 167 | struct qdio_q *q; |
| 168 | int i; |
| 169 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 170 | for_each_input_queue(irq_ptr, q, i) |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 171 | debugfs_remove(q->debugfs_q); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 172 | for_each_output_queue(irq_ptr, q, i) |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 173 | debugfs_remove(q->debugfs_q); |
| 174 | debugfs_remove(irq_ptr->debugfs_dev); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | int __init qdio_debug_init(void) |
| 178 | { |
Jan Glauber | 3f09bb8 | 2009-09-11 10:28:22 +0200 | [diff] [blame] | 179 | debugfs_root = debugfs_create_dir("qdio", NULL); |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 180 | |
| 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"); |
| 185 | |
| 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; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void qdio_debug_exit(void) |
| 194 | { |
| 195 | debugfs_remove(debugfs_root); |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 196 | if (qdio_dbf_setup) |
| 197 | debug_unregister(qdio_dbf_setup); |
| 198 | if (qdio_dbf_error) |
| 199 | debug_unregister(qdio_dbf_error); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 200 | } |