[S390] Remove error checking from copy_oldmem_page()
[linux/fpc-iii.git] / drivers / s390 / cio / qdio_setup.c
blobd9a46a429bccf8213f4dd6c6fea8032c1d127070
1 /*
2 * driver/s390/cio/qdio_setup.c
4 * qdio queue initialization
6 * Copyright (C) IBM Corp. 2008
7 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
8 */
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <asm/qdio.h>
13 #include "cio.h"
14 #include "css.h"
15 #include "device.h"
16 #include "ioasm.h"
17 #include "chsc.h"
18 #include "qdio.h"
19 #include "qdio_debug.h"
21 static struct kmem_cache *qdio_q_cache;
22 static struct kmem_cache *qdio_aob_cache;
24 struct qaob *qdio_allocate_aob()
26 struct qaob *aob;
28 aob = kmem_cache_zalloc(qdio_aob_cache, GFP_ATOMIC);
29 return aob;
31 EXPORT_SYMBOL_GPL(qdio_allocate_aob);
33 void qdio_release_aob(struct qaob *aob)
35 kmem_cache_free(qdio_aob_cache, aob);
37 EXPORT_SYMBOL_GPL(qdio_release_aob);
40 * qebsm is only available under 64bit but the adapter sets the feature
41 * flag anyway, so we manually override it.
43 static inline int qebsm_possible(void)
45 #ifdef CONFIG_64BIT
46 return css_general_characteristics.qebsm;
47 #endif
48 return 0;
52 * qib_param_field: pointer to 128 bytes or NULL, if no param field
53 * nr_input_qs: pointer to nr_queues*128 words of data or NULL
55 static void set_impl_params(struct qdio_irq *irq_ptr,
56 unsigned int qib_param_field_format,
57 unsigned char *qib_param_field,
58 unsigned long *input_slib_elements,
59 unsigned long *output_slib_elements)
61 struct qdio_q *q;
62 int i, j;
64 if (!irq_ptr)
65 return;
67 irq_ptr->qib.pfmt = qib_param_field_format;
68 if (qib_param_field)
69 memcpy(irq_ptr->qib.parm, qib_param_field,
70 QDIO_MAX_BUFFERS_PER_Q);
72 if (!input_slib_elements)
73 goto output;
75 for_each_input_queue(irq_ptr, q, i) {
76 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
77 q->slib->slibe[j].parms =
78 input_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j];
80 output:
81 if (!output_slib_elements)
82 return;
84 for_each_output_queue(irq_ptr, q, i) {
85 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
86 q->slib->slibe[j].parms =
87 output_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j];
91 static int __qdio_allocate_qs(struct qdio_q **irq_ptr_qs, int nr_queues)
93 struct qdio_q *q;
94 int i;
96 for (i = 0; i < nr_queues; i++) {
97 q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL);
98 if (!q)
99 return -ENOMEM;
101 q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
102 if (!q->slib) {
103 kmem_cache_free(qdio_q_cache, q);
104 return -ENOMEM;
106 irq_ptr_qs[i] = q;
108 return 0;
111 int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs)
113 int rc;
115 rc = __qdio_allocate_qs(irq_ptr->input_qs, nr_input_qs);
116 if (rc)
117 return rc;
118 rc = __qdio_allocate_qs(irq_ptr->output_qs, nr_output_qs);
119 return rc;
122 static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr,
123 qdio_handler_t *handler, int i)
125 struct slib *slib = q->slib;
127 /* queue must be cleared for qdio_establish */
128 memset(q, 0, sizeof(*q));
129 memset(slib, 0, PAGE_SIZE);
130 q->slib = slib;
131 q->irq_ptr = irq_ptr;
132 q->mask = 1 << (31 - i);
133 q->nr = i;
134 q->handler = handler;
137 static void setup_storage_lists(struct qdio_q *q, struct qdio_irq *irq_ptr,
138 void **sbals_array, int i)
140 struct qdio_q *prev;
141 int j;
143 DBF_HEX(&q, sizeof(void *));
144 q->sl = (struct sl *)((char *)q->slib + PAGE_SIZE / 2);
146 /* fill in sbal */
147 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) {
148 q->sbal[j] = *sbals_array++;
149 BUG_ON((unsigned long)q->sbal[j] & 0xff);
152 /* fill in slib */
153 if (i > 0) {
154 prev = (q->is_input_q) ? irq_ptr->input_qs[i - 1]
155 : irq_ptr->output_qs[i - 1];
156 prev->slib->nsliba = (unsigned long)q->slib;
159 q->slib->sla = (unsigned long)q->sl;
160 q->slib->slsba = (unsigned long)&q->slsb.val[0];
162 /* fill in sl */
163 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
164 q->sl->element[j].sbal = (unsigned long)q->sbal[j];
167 static void setup_queues(struct qdio_irq *irq_ptr,
168 struct qdio_initialize *qdio_init)
170 struct qdio_q *q;
171 void **input_sbal_array = qdio_init->input_sbal_addr_array;
172 void **output_sbal_array = qdio_init->output_sbal_addr_array;
173 struct qdio_outbuf_state *output_sbal_state_array =
174 qdio_init->output_sbal_state_array;
175 int i;
177 for_each_input_queue(irq_ptr, q, i) {
178 DBF_EVENT("inq:%1d", i);
179 setup_queues_misc(q, irq_ptr, qdio_init->input_handler, i);
181 q->is_input_q = 1;
182 q->u.in.queue_start_poll = qdio_init->queue_start_poll[i];
184 setup_storage_lists(q, irq_ptr, input_sbal_array, i);
185 input_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
187 if (is_thinint_irq(irq_ptr)) {
188 tasklet_init(&q->tasklet, tiqdio_inbound_processing,
189 (unsigned long) q);
190 } else {
191 tasklet_init(&q->tasklet, qdio_inbound_processing,
192 (unsigned long) q);
196 for_each_output_queue(irq_ptr, q, i) {
197 DBF_EVENT("outq:%1d", i);
198 setup_queues_misc(q, irq_ptr, qdio_init->output_handler, i);
200 q->u.out.sbal_state = output_sbal_state_array;
201 output_sbal_state_array += QDIO_MAX_BUFFERS_PER_Q;
203 q->is_input_q = 0;
204 q->u.out.scan_threshold = qdio_init->scan_threshold;
205 setup_storage_lists(q, irq_ptr, output_sbal_array, i);
206 output_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
208 tasklet_init(&q->tasklet, qdio_outbound_processing,
209 (unsigned long) q);
210 setup_timer(&q->u.out.timer, (void(*)(unsigned long))
211 &qdio_outbound_timer, (unsigned long)q);
215 static void process_ac_flags(struct qdio_irq *irq_ptr, unsigned char qdioac)
217 if (qdioac & AC1_SIGA_INPUT_NEEDED)
218 irq_ptr->siga_flag.input = 1;
219 if (qdioac & AC1_SIGA_OUTPUT_NEEDED)
220 irq_ptr->siga_flag.output = 1;
221 if (qdioac & AC1_SIGA_SYNC_NEEDED)
222 irq_ptr->siga_flag.sync = 1;
223 if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_THININT))
224 irq_ptr->siga_flag.sync_after_ai = 1;
225 if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_OUT_PCI))
226 irq_ptr->siga_flag.sync_out_after_pci = 1;
229 static void check_and_setup_qebsm(struct qdio_irq *irq_ptr,
230 unsigned char qdioac, unsigned long token)
232 if (!(irq_ptr->qib.rflags & QIB_RFLAGS_ENABLE_QEBSM))
233 goto no_qebsm;
234 if (!(qdioac & AC1_SC_QEBSM_AVAILABLE) ||
235 (!(qdioac & AC1_SC_QEBSM_ENABLED)))
236 goto no_qebsm;
238 irq_ptr->sch_token = token;
240 DBF_EVENT("V=V:1");
241 DBF_EVENT("%8lx", irq_ptr->sch_token);
242 return;
244 no_qebsm:
245 irq_ptr->sch_token = 0;
246 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
247 DBF_EVENT("noV=V");
251 * If there is a qdio_irq we use the chsc_page and store the information
252 * in the qdio_irq, otherwise we copy it to the specified structure.
254 int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
255 struct subchannel_id *schid,
256 struct qdio_ssqd_desc *data)
258 struct chsc_ssqd_area *ssqd;
259 int rc;
261 DBF_EVENT("getssqd:%4x", schid->sch_no);
262 if (irq_ptr != NULL)
263 ssqd = (struct chsc_ssqd_area *)irq_ptr->chsc_page;
264 else
265 ssqd = (struct chsc_ssqd_area *)__get_free_page(GFP_KERNEL);
266 memset(ssqd, 0, PAGE_SIZE);
268 ssqd->request = (struct chsc_header) {
269 .length = 0x0010,
270 .code = 0x0024,
272 ssqd->first_sch = schid->sch_no;
273 ssqd->last_sch = schid->sch_no;
274 ssqd->ssid = schid->ssid;
276 if (chsc(ssqd))
277 return -EIO;
278 rc = chsc_error_from_response(ssqd->response.code);
279 if (rc)
280 return rc;
282 if (!(ssqd->qdio_ssqd.flags & CHSC_FLAG_QDIO_CAPABILITY) ||
283 !(ssqd->qdio_ssqd.flags & CHSC_FLAG_VALIDITY) ||
284 (ssqd->qdio_ssqd.sch != schid->sch_no))
285 return -EINVAL;
287 if (irq_ptr != NULL)
288 memcpy(&irq_ptr->ssqd_desc, &ssqd->qdio_ssqd,
289 sizeof(struct qdio_ssqd_desc));
290 else {
291 memcpy(data, &ssqd->qdio_ssqd,
292 sizeof(struct qdio_ssqd_desc));
293 free_page((unsigned long)ssqd);
295 return 0;
298 void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr)
300 unsigned char qdioac;
301 int rc;
303 rc = qdio_setup_get_ssqd(irq_ptr, &irq_ptr->schid, NULL);
304 if (rc) {
305 DBF_ERROR("%4x ssqd ERR", irq_ptr->schid.sch_no);
306 DBF_ERROR("rc:%x", rc);
307 /* all flags set, worst case */
308 qdioac = AC1_SIGA_INPUT_NEEDED | AC1_SIGA_OUTPUT_NEEDED |
309 AC1_SIGA_SYNC_NEEDED;
310 } else
311 qdioac = irq_ptr->ssqd_desc.qdioac1;
313 check_and_setup_qebsm(irq_ptr, qdioac, irq_ptr->ssqd_desc.sch_token);
314 process_ac_flags(irq_ptr, qdioac);
315 DBF_EVENT("qdioac:%4x", qdioac);
318 void qdio_release_memory(struct qdio_irq *irq_ptr)
320 struct qdio_q *q;
321 int i;
324 * Must check queue array manually since irq_ptr->nr_input_queues /
325 * irq_ptr->nr_input_queues may not yet be set.
327 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
328 q = irq_ptr->input_qs[i];
329 if (q) {
330 free_page((unsigned long) q->slib);
331 kmem_cache_free(qdio_q_cache, q);
334 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
335 q = irq_ptr->output_qs[i];
336 if (q) {
337 if (q->u.out.use_cq) {
338 int n;
340 for (n = 0; n < QDIO_MAX_BUFFERS_PER_Q; ++n) {
341 struct qaob *aob = q->u.out.aobs[n];
342 if (aob) {
343 qdio_release_aob(aob);
344 q->u.out.aobs[n] = NULL;
348 qdio_disable_async_operation(&q->u.out);
350 free_page((unsigned long) q->slib);
351 kmem_cache_free(qdio_q_cache, q);
354 free_page((unsigned long) irq_ptr->qdr);
355 free_page(irq_ptr->chsc_page);
356 free_page((unsigned long) irq_ptr);
359 static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr,
360 struct qdio_q **irq_ptr_qs,
361 int i, int nr)
363 irq_ptr->qdr->qdf0[i + nr].sliba =
364 (unsigned long)irq_ptr_qs[i]->slib;
366 irq_ptr->qdr->qdf0[i + nr].sla =
367 (unsigned long)irq_ptr_qs[i]->sl;
369 irq_ptr->qdr->qdf0[i + nr].slsba =
370 (unsigned long)&irq_ptr_qs[i]->slsb.val[0];
372 irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4;
373 irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4;
374 irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4;
375 irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4;
378 static void setup_qdr(struct qdio_irq *irq_ptr,
379 struct qdio_initialize *qdio_init)
381 int i;
383 irq_ptr->qdr->qfmt = qdio_init->q_format;
384 irq_ptr->qdr->ac = qdio_init->qdr_ac;
385 irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs;
386 irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs;
387 irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */
388 irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4;
389 irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib;
390 irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4;
392 for (i = 0; i < qdio_init->no_input_qs; i++)
393 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0);
395 for (i = 0; i < qdio_init->no_output_qs; i++)
396 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i,
397 qdio_init->no_input_qs);
400 static void setup_qib(struct qdio_irq *irq_ptr,
401 struct qdio_initialize *init_data)
403 if (qebsm_possible())
404 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
406 irq_ptr->qib.rflags |= init_data->qib_rflags;
408 irq_ptr->qib.qfmt = init_data->q_format;
409 if (init_data->no_input_qs)
410 irq_ptr->qib.isliba =
411 (unsigned long)(irq_ptr->input_qs[0]->slib);
412 if (init_data->no_output_qs)
413 irq_ptr->qib.osliba =
414 (unsigned long)(irq_ptr->output_qs[0]->slib);
415 memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8);
418 int qdio_setup_irq(struct qdio_initialize *init_data)
420 struct ciw *ciw;
421 struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data;
422 int rc;
424 memset(&irq_ptr->qib, 0, sizeof(irq_ptr->qib));
425 memset(&irq_ptr->siga_flag, 0, sizeof(irq_ptr->siga_flag));
426 memset(&irq_ptr->ccw, 0, sizeof(irq_ptr->ccw));
427 memset(&irq_ptr->ssqd_desc, 0, sizeof(irq_ptr->ssqd_desc));
428 memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat));
430 irq_ptr->debugfs_dev = irq_ptr->debugfs_perf = NULL;
431 irq_ptr->sch_token = irq_ptr->state = irq_ptr->perf_stat_enabled = 0;
433 /* wipes qib.ac, required by ar7063 */
434 memset(irq_ptr->qdr, 0, sizeof(struct qdr));
436 irq_ptr->int_parm = init_data->int_parm;
437 irq_ptr->nr_input_qs = init_data->no_input_qs;
438 irq_ptr->nr_output_qs = init_data->no_output_qs;
440 irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev);
441 irq_ptr->cdev = init_data->cdev;
442 setup_queues(irq_ptr, init_data);
444 setup_qib(irq_ptr, init_data);
445 qdio_setup_thinint(irq_ptr);
446 set_impl_params(irq_ptr, init_data->qib_param_field_format,
447 init_data->qib_param_field,
448 init_data->input_slib_elements,
449 init_data->output_slib_elements);
451 /* fill input and output descriptors */
452 setup_qdr(irq_ptr, init_data);
454 /* qdr, qib, sls, slsbs, slibs, sbales are filled now */
456 /* get qdio commands */
457 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
458 if (!ciw) {
459 DBF_ERROR("%4x NO EQ", irq_ptr->schid.sch_no);
460 rc = -EINVAL;
461 goto out_err;
463 irq_ptr->equeue = *ciw;
465 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
466 if (!ciw) {
467 DBF_ERROR("%4x NO AQ", irq_ptr->schid.sch_no);
468 rc = -EINVAL;
469 goto out_err;
471 irq_ptr->aqueue = *ciw;
473 /* set new interrupt handler */
474 irq_ptr->orig_handler = init_data->cdev->handler;
475 init_data->cdev->handler = qdio_int_handler;
476 return 0;
477 out_err:
478 qdio_release_memory(irq_ptr);
479 return rc;
482 void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
483 struct ccw_device *cdev)
485 char s[80];
487 snprintf(s, 80, "qdio: %s %s on SC %x using "
488 "AI:%d QEBSM:%d PCI:%d TDD:%d SIGA:%s%s%s%s%s\n",
489 dev_name(&cdev->dev),
490 (irq_ptr->qib.qfmt == QDIO_QETH_QFMT) ? "OSA" :
491 ((irq_ptr->qib.qfmt == QDIO_ZFCP_QFMT) ? "ZFCP" : "HS"),
492 irq_ptr->schid.sch_no,
493 is_thinint_irq(irq_ptr),
494 (irq_ptr->sch_token) ? 1 : 0,
495 (irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED) ? 1 : 0,
496 css_general_characteristics.aif_tdd,
497 (irq_ptr->siga_flag.input) ? "R" : " ",
498 (irq_ptr->siga_flag.output) ? "W" : " ",
499 (irq_ptr->siga_flag.sync) ? "S" : " ",
500 (irq_ptr->siga_flag.sync_after_ai) ? "A" : " ",
501 (irq_ptr->siga_flag.sync_out_after_pci) ? "P" : " ");
502 printk(KERN_INFO "%s", s);
505 int qdio_enable_async_operation(struct qdio_output_q *outq)
507 outq->aobs = kzalloc(sizeof(struct qaob *) * QDIO_MAX_BUFFERS_PER_Q,
508 GFP_ATOMIC);
509 if (!outq->aobs) {
510 outq->use_cq = 0;
511 return -ENOMEM;
513 outq->use_cq = 1;
514 return 0;
517 void qdio_disable_async_operation(struct qdio_output_q *q)
519 kfree(q->aobs);
520 q->aobs = NULL;
521 q->use_cq = 0;
524 int __init qdio_setup_init(void)
526 int rc;
528 qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q),
529 256, 0, NULL);
530 if (!qdio_q_cache)
531 return -ENOMEM;
533 qdio_aob_cache = kmem_cache_create("qdio_aob",
534 sizeof(struct qaob),
535 sizeof(struct qaob),
537 NULL);
538 if (!qdio_aob_cache) {
539 rc = -ENOMEM;
540 goto free_qdio_q_cache;
543 /* Check for OSA/FCP thin interrupts (bit 67). */
544 DBF_EVENT("thinint:%1d",
545 (css_general_characteristics.aif_osa) ? 1 : 0);
547 /* Check for QEBSM support in general (bit 58). */
548 DBF_EVENT("cssQEBSM:%1d", (qebsm_possible()) ? 1 : 0);
549 rc = 0;
550 out:
551 return rc;
552 free_qdio_q_cache:
553 kmem_cache_destroy(qdio_q_cache);
554 goto out;
557 void qdio_setup_exit(void)
559 kmem_cache_destroy(qdio_aob_cache);
560 kmem_cache_destroy(qdio_q_cache);