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