Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 1 | /* |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2 | * qdio queue initialization |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008 |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 5 | * Author(s): Jan Glauber <jang@linux.vnet.ibm.com> |
| 6 | */ |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/slab.h> |
Heiko Carstens | 3a4c5d5 | 2011-07-30 09:25:15 +0200 | [diff] [blame] | 9 | #include <linux/export.h> |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 10 | #include <asm/qdio.h> |
| 11 | |
| 12 | #include "cio.h" |
| 13 | #include "css.h" |
| 14 | #include "device.h" |
| 15 | #include "ioasm.h" |
| 16 | #include "chsc.h" |
| 17 | #include "qdio.h" |
| 18 | #include "qdio_debug.h" |
| 19 | |
| 20 | static struct kmem_cache *qdio_q_cache; |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 21 | static struct kmem_cache *qdio_aob_cache; |
| 22 | |
Heiko Carstens | 400d829 | 2011-12-27 11:27:10 +0100 | [diff] [blame] | 23 | struct qaob *qdio_allocate_aob(void) |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 24 | { |
Heiko Carstens | 400d829 | 2011-12-27 11:27:10 +0100 | [diff] [blame] | 25 | return kmem_cache_zalloc(qdio_aob_cache, GFP_ATOMIC); |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 26 | } |
| 27 | EXPORT_SYMBOL_GPL(qdio_allocate_aob); |
| 28 | |
| 29 | void qdio_release_aob(struct qaob *aob) |
| 30 | { |
| 31 | kmem_cache_free(qdio_aob_cache, aob); |
| 32 | } |
| 33 | EXPORT_SYMBOL_GPL(qdio_release_aob); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * qebsm is only available under 64bit but the adapter sets the feature |
| 37 | * flag anyway, so we manually override it. |
| 38 | */ |
| 39 | static inline int qebsm_possible(void) |
| 40 | { |
| 41 | #ifdef CONFIG_64BIT |
| 42 | return css_general_characteristics.qebsm; |
| 43 | #endif |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * qib_param_field: pointer to 128 bytes or NULL, if no param field |
| 49 | * nr_input_qs: pointer to nr_queues*128 words of data or NULL |
| 50 | */ |
| 51 | static void set_impl_params(struct qdio_irq *irq_ptr, |
| 52 | unsigned int qib_param_field_format, |
| 53 | unsigned char *qib_param_field, |
| 54 | unsigned long *input_slib_elements, |
| 55 | unsigned long *output_slib_elements) |
| 56 | { |
| 57 | struct qdio_q *q; |
| 58 | int i, j; |
| 59 | |
| 60 | if (!irq_ptr) |
| 61 | return; |
| 62 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 63 | irq_ptr->qib.pfmt = qib_param_field_format; |
| 64 | if (qib_param_field) |
| 65 | memcpy(irq_ptr->qib.parm, qib_param_field, |
| 66 | QDIO_MAX_BUFFERS_PER_Q); |
| 67 | |
| 68 | if (!input_slib_elements) |
| 69 | goto output; |
| 70 | |
| 71 | for_each_input_queue(irq_ptr, q, i) { |
| 72 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
| 73 | q->slib->slibe[j].parms = |
| 74 | input_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j]; |
| 75 | } |
| 76 | output: |
| 77 | if (!output_slib_elements) |
| 78 | return; |
| 79 | |
| 80 | for_each_output_queue(irq_ptr, q, i) { |
| 81 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
| 82 | q->slib->slibe[j].parms = |
| 83 | output_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j]; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static int __qdio_allocate_qs(struct qdio_q **irq_ptr_qs, int nr_queues) |
| 88 | { |
| 89 | struct qdio_q *q; |
| 90 | int i; |
| 91 | |
| 92 | for (i = 0; i < nr_queues; i++) { |
| 93 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); |
| 94 | if (!q) |
| 95 | return -ENOMEM; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 96 | |
| 97 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); |
| 98 | if (!q->slib) { |
| 99 | kmem_cache_free(qdio_q_cache, q); |
| 100 | return -ENOMEM; |
| 101 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 102 | irq_ptr_qs[i] = q; |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs) |
| 108 | { |
| 109 | int rc; |
| 110 | |
| 111 | rc = __qdio_allocate_qs(irq_ptr->input_qs, nr_input_qs); |
| 112 | if (rc) |
| 113 | return rc; |
| 114 | rc = __qdio_allocate_qs(irq_ptr->output_qs, nr_output_qs); |
| 115 | return rc; |
| 116 | } |
| 117 | |
| 118 | static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr, |
| 119 | qdio_handler_t *handler, int i) |
| 120 | { |
Jan Glauber | 5382fe1 | 2010-05-17 10:00:16 +0200 | [diff] [blame] | 121 | struct slib *slib = q->slib; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 122 | |
Jan Glauber | 5382fe1 | 2010-05-17 10:00:16 +0200 | [diff] [blame] | 123 | /* queue must be cleared for qdio_establish */ |
| 124 | memset(q, 0, sizeof(*q)); |
| 125 | memset(slib, 0, PAGE_SIZE); |
| 126 | q->slib = slib; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 127 | q->irq_ptr = irq_ptr; |
| 128 | q->mask = 1 << (31 - i); |
| 129 | q->nr = i; |
| 130 | q->handler = handler; |
| 131 | } |
| 132 | |
| 133 | static void setup_storage_lists(struct qdio_q *q, struct qdio_irq *irq_ptr, |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 134 | void **sbals_array, int i) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 135 | { |
| 136 | struct qdio_q *prev; |
| 137 | int j; |
| 138 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 139 | DBF_HEX(&q, sizeof(void *)); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 140 | q->sl = (struct sl *)((char *)q->slib + PAGE_SIZE / 2); |
| 141 | |
| 142 | /* fill in sbal */ |
Jan Glauber | ce1d801 | 2012-10-24 12:38:35 +0200 | [diff] [blame] | 143 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 144 | q->sbal[j] = *sbals_array++; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 145 | |
| 146 | /* fill in slib */ |
| 147 | if (i > 0) { |
| 148 | prev = (q->is_input_q) ? irq_ptr->input_qs[i - 1] |
| 149 | : irq_ptr->output_qs[i - 1]; |
| 150 | prev->slib->nsliba = (unsigned long)q->slib; |
| 151 | } |
| 152 | |
| 153 | q->slib->sla = (unsigned long)q->sl; |
| 154 | q->slib->slsba = (unsigned long)&q->slsb.val[0]; |
| 155 | |
| 156 | /* fill in sl */ |
| 157 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
| 158 | q->sl->element[j].sbal = (unsigned long)q->sbal[j]; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void setup_queues(struct qdio_irq *irq_ptr, |
| 162 | struct qdio_initialize *qdio_init) |
| 163 | { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 164 | struct qdio_q *q; |
| 165 | void **input_sbal_array = qdio_init->input_sbal_addr_array; |
| 166 | void **output_sbal_array = qdio_init->output_sbal_addr_array; |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 167 | struct qdio_outbuf_state *output_sbal_state_array = |
| 168 | qdio_init->output_sbal_state_array; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 169 | int i; |
| 170 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 171 | for_each_input_queue(irq_ptr, q, i) { |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 172 | DBF_EVENT("inq:%1d", i); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 173 | setup_queues_misc(q, irq_ptr, qdio_init->input_handler, i); |
| 174 | |
| 175 | q->is_input_q = 1; |
Steffen Maier | e58b0d9 | 2011-12-27 11:27:26 +0100 | [diff] [blame] | 176 | q->u.in.queue_start_poll = qdio_init->queue_start_poll_array ? |
| 177 | qdio_init->queue_start_poll_array[i] : NULL; |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 178 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 179 | setup_storage_lists(q, irq_ptr, input_sbal_array, i); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 180 | input_sbal_array += QDIO_MAX_BUFFERS_PER_Q; |
| 181 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 182 | if (is_thinint_irq(irq_ptr)) { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 183 | tasklet_init(&q->tasklet, tiqdio_inbound_processing, |
| 184 | (unsigned long) q); |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 185 | } else { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 186 | tasklet_init(&q->tasklet, qdio_inbound_processing, |
| 187 | (unsigned long) q); |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 188 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | for_each_output_queue(irq_ptr, q, i) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 192 | DBF_EVENT("outq:%1d", i); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 193 | setup_queues_misc(q, irq_ptr, qdio_init->output_handler, i); |
| 194 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 195 | q->u.out.sbal_state = output_sbal_state_array; |
| 196 | output_sbal_state_array += QDIO_MAX_BUFFERS_PER_Q; |
| 197 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 198 | q->is_input_q = 0; |
Jan Glauber | 3d6c76f | 2011-01-05 12:47:50 +0100 | [diff] [blame] | 199 | q->u.out.scan_threshold = qdio_init->scan_threshold; |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 200 | setup_storage_lists(q, irq_ptr, output_sbal_array, i); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 201 | output_sbal_array += QDIO_MAX_BUFFERS_PER_Q; |
| 202 | |
| 203 | tasklet_init(&q->tasklet, qdio_outbound_processing, |
| 204 | (unsigned long) q); |
| 205 | setup_timer(&q->u.out.timer, (void(*)(unsigned long)) |
| 206 | &qdio_outbound_timer, (unsigned long)q); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | static void process_ac_flags(struct qdio_irq *irq_ptr, unsigned char qdioac) |
| 211 | { |
| 212 | if (qdioac & AC1_SIGA_INPUT_NEEDED) |
| 213 | irq_ptr->siga_flag.input = 1; |
| 214 | if (qdioac & AC1_SIGA_OUTPUT_NEEDED) |
| 215 | irq_ptr->siga_flag.output = 1; |
| 216 | if (qdioac & AC1_SIGA_SYNC_NEEDED) |
| 217 | irq_ptr->siga_flag.sync = 1; |
Jan Glauber | 90adac5 | 2011-01-05 12:47:54 +0100 | [diff] [blame] | 218 | if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_THININT)) |
| 219 | irq_ptr->siga_flag.sync_after_ai = 1; |
| 220 | if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_OUT_PCI)) |
| 221 | irq_ptr->siga_flag.sync_out_after_pci = 1; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void check_and_setup_qebsm(struct qdio_irq *irq_ptr, |
| 225 | unsigned char qdioac, unsigned long token) |
| 226 | { |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 227 | if (!(irq_ptr->qib.rflags & QIB_RFLAGS_ENABLE_QEBSM)) |
| 228 | goto no_qebsm; |
| 229 | if (!(qdioac & AC1_SC_QEBSM_AVAILABLE) || |
| 230 | (!(qdioac & AC1_SC_QEBSM_ENABLED))) |
| 231 | goto no_qebsm; |
| 232 | |
| 233 | irq_ptr->sch_token = token; |
| 234 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 235 | DBF_EVENT("V=V:1"); |
| 236 | DBF_EVENT("%8lx", irq_ptr->sch_token); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 237 | return; |
| 238 | |
| 239 | no_qebsm: |
| 240 | irq_ptr->sch_token = 0; |
| 241 | irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM; |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 242 | DBF_EVENT("noV=V"); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Jan Glauber | bbd50e1 | 2008-12-25 13:38:43 +0100 | [diff] [blame] | 245 | /* |
| 246 | * If there is a qdio_irq we use the chsc_page and store the information |
| 247 | * in the qdio_irq, otherwise we copy it to the specified structure. |
| 248 | */ |
| 249 | int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr, |
| 250 | struct subchannel_id *schid, |
| 251 | struct qdio_ssqd_desc *data) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 252 | { |
| 253 | struct chsc_ssqd_area *ssqd; |
| 254 | int rc; |
| 255 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 256 | DBF_EVENT("getssqd:%4x", schid->sch_no); |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 257 | if (!irq_ptr) { |
Jan Glauber | bbd50e1 | 2008-12-25 13:38:43 +0100 | [diff] [blame] | 258 | ssqd = (struct chsc_ssqd_area *)__get_free_page(GFP_KERNEL); |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 259 | if (!ssqd) |
| 260 | return -ENOMEM; |
| 261 | } else { |
| 262 | ssqd = (struct chsc_ssqd_area *)irq_ptr->chsc_page; |
| 263 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 264 | |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 265 | rc = chsc_ssqd(*schid, ssqd); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 266 | if (rc) |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 267 | goto out; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 268 | |
| 269 | if (!(ssqd->qdio_ssqd.flags & CHSC_FLAG_QDIO_CAPABILITY) || |
| 270 | !(ssqd->qdio_ssqd.flags & CHSC_FLAG_VALIDITY) || |
Jan Glauber | bbd50e1 | 2008-12-25 13:38:43 +0100 | [diff] [blame] | 271 | (ssqd->qdio_ssqd.sch != schid->sch_no)) |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 272 | rc = -EINVAL; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 273 | |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 274 | if (!rc) |
| 275 | memcpy(data, &ssqd->qdio_ssqd, sizeof(*data)); |
| 276 | |
| 277 | out: |
| 278 | if (!irq_ptr) |
Jan Glauber | bbd50e1 | 2008-12-25 13:38:43 +0100 | [diff] [blame] | 279 | free_page((unsigned long)ssqd); |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 280 | |
| 281 | return rc; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr) |
| 285 | { |
| 286 | unsigned char qdioac; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 287 | int rc; |
| 288 | |
Sebastian Ott | da5b6cb | 2013-06-05 18:58:35 +0200 | [diff] [blame] | 289 | rc = qdio_setup_get_ssqd(irq_ptr, &irq_ptr->schid, &irq_ptr->ssqd_desc); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 290 | if (rc) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 291 | DBF_ERROR("%4x ssqd ERR", irq_ptr->schid.sch_no); |
| 292 | DBF_ERROR("rc:%x", rc); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 293 | /* all flags set, worst case */ |
| 294 | qdioac = AC1_SIGA_INPUT_NEEDED | AC1_SIGA_OUTPUT_NEEDED | |
| 295 | AC1_SIGA_SYNC_NEEDED; |
| 296 | } else |
| 297 | qdioac = irq_ptr->ssqd_desc.qdioac1; |
| 298 | |
| 299 | check_and_setup_qebsm(irq_ptr, qdioac, irq_ptr->ssqd_desc.sch_token); |
| 300 | process_ac_flags(irq_ptr, qdioac); |
Jan Glauber | 61d8497 | 2012-03-23 11:13:04 +0100 | [diff] [blame] | 301 | DBF_EVENT("ac 1:%2x 2:%4x", qdioac, irq_ptr->ssqd_desc.qdioac2); |
| 302 | DBF_EVENT("3:%4x qib:%4x", irq_ptr->ssqd_desc.qdioac3, irq_ptr->qib.ac); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void qdio_release_memory(struct qdio_irq *irq_ptr) |
| 306 | { |
| 307 | struct qdio_q *q; |
| 308 | int i; |
| 309 | |
| 310 | /* |
| 311 | * Must check queue array manually since irq_ptr->nr_input_queues / |
| 312 | * irq_ptr->nr_input_queues may not yet be set. |
| 313 | */ |
| 314 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { |
| 315 | q = irq_ptr->input_qs[i]; |
| 316 | if (q) { |
| 317 | free_page((unsigned long) q->slib); |
| 318 | kmem_cache_free(qdio_q_cache, q); |
| 319 | } |
| 320 | } |
| 321 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { |
| 322 | q = irq_ptr->output_qs[i]; |
| 323 | if (q) { |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 324 | if (q->u.out.use_cq) { |
| 325 | int n; |
| 326 | |
| 327 | for (n = 0; n < QDIO_MAX_BUFFERS_PER_Q; ++n) { |
| 328 | struct qaob *aob = q->u.out.aobs[n]; |
| 329 | if (aob) { |
| 330 | qdio_release_aob(aob); |
| 331 | q->u.out.aobs[n] = NULL; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | qdio_disable_async_operation(&q->u.out); |
| 336 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 337 | free_page((unsigned long) q->slib); |
| 338 | kmem_cache_free(qdio_q_cache, q); |
| 339 | } |
| 340 | } |
Jan Glauber | 3b8e300 | 2008-08-01 16:39:17 +0200 | [diff] [blame] | 341 | free_page((unsigned long) irq_ptr->qdr); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 342 | free_page(irq_ptr->chsc_page); |
| 343 | free_page((unsigned long) irq_ptr); |
| 344 | } |
| 345 | |
| 346 | static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr, |
| 347 | struct qdio_q **irq_ptr_qs, |
| 348 | int i, int nr) |
| 349 | { |
| 350 | irq_ptr->qdr->qdf0[i + nr].sliba = |
| 351 | (unsigned long)irq_ptr_qs[i]->slib; |
| 352 | |
| 353 | irq_ptr->qdr->qdf0[i + nr].sla = |
| 354 | (unsigned long)irq_ptr_qs[i]->sl; |
| 355 | |
| 356 | irq_ptr->qdr->qdf0[i + nr].slsba = |
| 357 | (unsigned long)&irq_ptr_qs[i]->slsb.val[0]; |
| 358 | |
Heiko Carstens | d1bf859 | 2010-02-26 22:37:30 +0100 | [diff] [blame] | 359 | irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4; |
| 360 | irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4; |
| 361 | irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4; |
| 362 | irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static void setup_qdr(struct qdio_irq *irq_ptr, |
| 366 | struct qdio_initialize *qdio_init) |
| 367 | { |
| 368 | int i; |
| 369 | |
| 370 | irq_ptr->qdr->qfmt = qdio_init->q_format; |
Swen Schillig | dfe5bb5 | 2011-08-15 14:40:31 +0200 | [diff] [blame] | 371 | irq_ptr->qdr->ac = qdio_init->qdr_ac; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 372 | irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs; |
| 373 | irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs; |
| 374 | irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */ |
| 375 | irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4; |
| 376 | irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib; |
Heiko Carstens | d1bf859 | 2010-02-26 22:37:30 +0100 | [diff] [blame] | 377 | irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 378 | |
| 379 | for (i = 0; i < qdio_init->no_input_qs; i++) |
| 380 | __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0); |
| 381 | |
| 382 | for (i = 0; i < qdio_init->no_output_qs; i++) |
| 383 | __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i, |
| 384 | qdio_init->no_input_qs); |
| 385 | } |
| 386 | |
| 387 | static void setup_qib(struct qdio_irq *irq_ptr, |
| 388 | struct qdio_initialize *init_data) |
| 389 | { |
| 390 | if (qebsm_possible()) |
| 391 | irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM; |
| 392 | |
Christof Schmitt | dcc18f4 | 2010-07-16 15:37:41 +0200 | [diff] [blame] | 393 | irq_ptr->qib.rflags |= init_data->qib_rflags; |
| 394 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 395 | irq_ptr->qib.qfmt = init_data->q_format; |
| 396 | if (init_data->no_input_qs) |
| 397 | irq_ptr->qib.isliba = |
| 398 | (unsigned long)(irq_ptr->input_qs[0]->slib); |
| 399 | if (init_data->no_output_qs) |
| 400 | irq_ptr->qib.osliba = |
| 401 | (unsigned long)(irq_ptr->output_qs[0]->slib); |
| 402 | memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8); |
| 403 | } |
| 404 | |
| 405 | int qdio_setup_irq(struct qdio_initialize *init_data) |
| 406 | { |
| 407 | struct ciw *ciw; |
| 408 | struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data; |
| 409 | int rc; |
| 410 | |
Jan Glauber | 432ac5e | 2010-02-26 22:37:37 +0100 | [diff] [blame] | 411 | memset(&irq_ptr->qib, 0, sizeof(irq_ptr->qib)); |
| 412 | memset(&irq_ptr->siga_flag, 0, sizeof(irq_ptr->siga_flag)); |
| 413 | memset(&irq_ptr->ccw, 0, sizeof(irq_ptr->ccw)); |
| 414 | memset(&irq_ptr->ssqd_desc, 0, sizeof(irq_ptr->ssqd_desc)); |
| 415 | memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat)); |
| 416 | |
| 417 | irq_ptr->debugfs_dev = irq_ptr->debugfs_perf = NULL; |
| 418 | irq_ptr->sch_token = irq_ptr->state = irq_ptr->perf_stat_enabled = 0; |
| 419 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 420 | /* wipes qib.ac, required by ar7063 */ |
| 421 | memset(irq_ptr->qdr, 0, sizeof(struct qdr)); |
| 422 | |
| 423 | irq_ptr->int_parm = init_data->int_parm; |
| 424 | irq_ptr->nr_input_qs = init_data->no_input_qs; |
| 425 | irq_ptr->nr_output_qs = init_data->no_output_qs; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 426 | irq_ptr->cdev = init_data->cdev; |
Sebastian Ott | 287a093 | 2012-10-29 16:50:20 +0100 | [diff] [blame] | 427 | ccw_device_get_schid(irq_ptr->cdev, &irq_ptr->schid); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 428 | setup_queues(irq_ptr, init_data); |
| 429 | |
| 430 | setup_qib(irq_ptr, init_data); |
| 431 | qdio_setup_thinint(irq_ptr); |
| 432 | set_impl_params(irq_ptr, init_data->qib_param_field_format, |
| 433 | init_data->qib_param_field, |
| 434 | init_data->input_slib_elements, |
| 435 | init_data->output_slib_elements); |
| 436 | |
| 437 | /* fill input and output descriptors */ |
| 438 | setup_qdr(irq_ptr, init_data); |
| 439 | |
| 440 | /* qdr, qib, sls, slsbs, slibs, sbales are filled now */ |
| 441 | |
| 442 | /* get qdio commands */ |
| 443 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE); |
| 444 | if (!ciw) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 445 | DBF_ERROR("%4x NO EQ", irq_ptr->schid.sch_no); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 446 | rc = -EINVAL; |
| 447 | goto out_err; |
| 448 | } |
| 449 | irq_ptr->equeue = *ciw; |
| 450 | |
| 451 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE); |
| 452 | if (!ciw) { |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 453 | DBF_ERROR("%4x NO AQ", irq_ptr->schid.sch_no); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 454 | rc = -EINVAL; |
| 455 | goto out_err; |
| 456 | } |
| 457 | irq_ptr->aqueue = *ciw; |
| 458 | |
| 459 | /* set new interrupt handler */ |
| 460 | irq_ptr->orig_handler = init_data->cdev->handler; |
| 461 | init_data->cdev->handler = qdio_int_handler; |
| 462 | return 0; |
| 463 | out_err: |
| 464 | qdio_release_memory(irq_ptr); |
| 465 | return rc; |
| 466 | } |
| 467 | |
| 468 | void qdio_print_subchannel_info(struct qdio_irq *irq_ptr, |
| 469 | struct ccw_device *cdev) |
| 470 | { |
| 471 | char s[80]; |
| 472 | |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 473 | snprintf(s, 80, "qdio: %s %s on SC %x using " |
Jan Glauber | 6726a80 | 2012-12-06 13:30:26 +0100 | [diff] [blame] | 474 | "AI:%d QEBSM:%d PRI:%d TDD:%d SIGA:%s%s%s%s%s\n", |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 475 | dev_name(&cdev->dev), |
| 476 | (irq_ptr->qib.qfmt == QDIO_QETH_QFMT) ? "OSA" : |
| 477 | ((irq_ptr->qib.qfmt == QDIO_ZFCP_QFMT) ? "ZFCP" : "HS"), |
| 478 | irq_ptr->schid.sch_no, |
| 479 | is_thinint_irq(irq_ptr), |
| 480 | (irq_ptr->sch_token) ? 1 : 0, |
| 481 | (irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED) ? 1 : 0, |
| 482 | css_general_characteristics.aif_tdd, |
| 483 | (irq_ptr->siga_flag.input) ? "R" : " ", |
| 484 | (irq_ptr->siga_flag.output) ? "W" : " ", |
| 485 | (irq_ptr->siga_flag.sync) ? "S" : " ", |
Jan Glauber | 90adac5 | 2011-01-05 12:47:54 +0100 | [diff] [blame] | 486 | (irq_ptr->siga_flag.sync_after_ai) ? "A" : " ", |
| 487 | (irq_ptr->siga_flag.sync_out_after_pci) ? "P" : " "); |
Jan Glauber | 75f6276 | 2008-10-03 21:55:00 +0200 | [diff] [blame] | 488 | printk(KERN_INFO "%s", s); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 489 | } |
| 490 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 491 | int qdio_enable_async_operation(struct qdio_output_q *outq) |
| 492 | { |
| 493 | outq->aobs = kzalloc(sizeof(struct qaob *) * QDIO_MAX_BUFFERS_PER_Q, |
| 494 | GFP_ATOMIC); |
| 495 | if (!outq->aobs) { |
| 496 | outq->use_cq = 0; |
| 497 | return -ENOMEM; |
| 498 | } |
| 499 | outq->use_cq = 1; |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | void qdio_disable_async_operation(struct qdio_output_q *q) |
| 504 | { |
| 505 | kfree(q->aobs); |
| 506 | q->aobs = NULL; |
| 507 | q->use_cq = 0; |
| 508 | } |
| 509 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 510 | int __init qdio_setup_init(void) |
| 511 | { |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 512 | int rc; |
| 513 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 514 | qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q), |
| 515 | 256, 0, NULL); |
| 516 | if (!qdio_q_cache) |
| 517 | return -ENOMEM; |
| 518 | |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 519 | qdio_aob_cache = kmem_cache_create("qdio_aob", |
| 520 | sizeof(struct qaob), |
| 521 | sizeof(struct qaob), |
| 522 | 0, |
| 523 | NULL); |
| 524 | if (!qdio_aob_cache) { |
| 525 | rc = -ENOMEM; |
| 526 | goto free_qdio_q_cache; |
| 527 | } |
| 528 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 529 | /* Check for OSA/FCP thin interrupts (bit 67). */ |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 530 | DBF_EVENT("thinint:%1d", |
| 531 | (css_general_characteristics.aif_osa) ? 1 : 0); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 532 | |
| 533 | /* Check for QEBSM support in general (bit 58). */ |
Jan Glauber | 22f9934 | 2008-12-25 13:38:46 +0100 | [diff] [blame] | 534 | DBF_EVENT("cssQEBSM:%1d", (qebsm_possible()) ? 1 : 0); |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 535 | rc = 0; |
| 536 | out: |
| 537 | return rc; |
| 538 | free_qdio_q_cache: |
| 539 | kmem_cache_destroy(qdio_q_cache); |
| 540 | goto out; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Heiko Carstens | 3f1934b | 2008-08-01 16:39:20 +0200 | [diff] [blame] | 543 | void qdio_setup_exit(void) |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 544 | { |
frank.blaschka@de.ibm.com | 104ea55 | 2011-08-08 01:33:55 +0000 | [diff] [blame] | 545 | kmem_cache_destroy(qdio_aob_cache); |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 546 | kmem_cache_destroy(qdio_q_cache); |
| 547 | } |