This source file includes following definitions.
- qdio_allocate_aob
- qdio_release_aob
- qdio_free_buffers
- qdio_alloc_buffers
- qdio_reset_buffers
- qebsm_possible
- set_impl_params
- __qdio_allocate_qs
- qdio_allocate_qs
- setup_queues_misc
- setup_storage_lists
- setup_queues
- process_ac_flags
- check_and_setup_qebsm
- qdio_setup_get_ssqd
- qdio_setup_ssqd_info
- qdio_release_memory
- __qdio_allocate_fill_qdr
- setup_qdr
- setup_qib
- qdio_setup_irq
- qdio_print_subchannel_info
- qdio_enable_async_operation
- qdio_disable_async_operation
- qdio_setup_init
- qdio_setup_exit
1
2
3
4
5
6
7
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 #include <linux/export.h>
11 #include <linux/io.h>
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
22 #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
23
24 static struct kmem_cache *qdio_q_cache;
25 static struct kmem_cache *qdio_aob_cache;
26
27 struct qaob *qdio_allocate_aob(void)
28 {
29 return kmem_cache_zalloc(qdio_aob_cache, GFP_ATOMIC);
30 }
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);
37
38
39
40
41
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
54
55
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
77
78
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
89
90
91
92
93 static inline int qebsm_possible(void)
94 {
95 return css_general_characteristics.qebsm;
96 }
97
98
99
100
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
114 irq_ptr->qib.pfmt = qib_param_field_format;
115 if (qib_param_field)
116 memcpy(irq_ptr->qib.parm, qib_param_field,
117 sizeof(irq_ptr->qib.parm));
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++) {
144 q = kmem_cache_zalloc(qdio_q_cache, GFP_KERNEL);
145 if (!q)
146 return -ENOMEM;
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 }
153 irq_ptr_qs[i] = q;
154 INIT_LIST_HEAD(&q->entry);
155 }
156 return 0;
157 }
158
159 int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs)
160 {
161 int rc;
162
163 rc = __qdio_allocate_qs(irq_ptr->input_qs, nr_input_qs);
164 if (rc)
165 return rc;
166 rc = __qdio_allocate_qs(irq_ptr->output_qs, nr_output_qs);
167 return rc;
168 }
169
170 static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr,
171 qdio_handler_t *handler, int i)
172 {
173 struct slib *slib = q->slib;
174
175
176 memset(q, 0, sizeof(*q));
177 memset(slib, 0, PAGE_SIZE);
178 q->slib = slib;
179 q->irq_ptr = irq_ptr;
180 q->mask = 1 << (31 - i);
181 q->nr = i;
182 q->handler = handler;
183 INIT_LIST_HEAD(&q->entry);
184 }
185
186 static void setup_storage_lists(struct qdio_q *q, struct qdio_irq *irq_ptr,
187 struct qdio_buffer **sbals_array, int i)
188 {
189 struct qdio_q *prev;
190 int j;
191
192 DBF_HEX(&q, sizeof(void *));
193 q->sl = (struct sl *)((char *)q->slib + PAGE_SIZE / 2);
194
195
196 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
197 q->sbal[j] = *sbals_array++;
198
199
200 if (i > 0) {
201 prev = (q->is_input_q) ? irq_ptr->input_qs[i - 1]
202 : irq_ptr->output_qs[i - 1];
203 prev->slib->nsliba = (unsigned long)q->slib;
204 }
205
206 q->slib->sla = (unsigned long)q->sl;
207 q->slib->slsba = (unsigned long)&q->slsb.val[0];
208
209
210 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
211 q->sl->element[j].sbal = virt_to_phys(q->sbal[j]);
212 }
213
214 static void setup_queues(struct qdio_irq *irq_ptr,
215 struct qdio_initialize *qdio_init)
216 {
217 struct qdio_q *q;
218 struct qdio_buffer **input_sbal_array = qdio_init->input_sbal_addr_array;
219 struct qdio_buffer **output_sbal_array = qdio_init->output_sbal_addr_array;
220 struct qdio_outbuf_state *output_sbal_state_array =
221 qdio_init->output_sbal_state_array;
222 int i;
223
224 for_each_input_queue(irq_ptr, q, i) {
225 DBF_EVENT("inq:%1d", i);
226 setup_queues_misc(q, irq_ptr, qdio_init->input_handler, i);
227
228 q->is_input_q = 1;
229 q->u.in.queue_start_poll = qdio_init->queue_start_poll_array ?
230 qdio_init->queue_start_poll_array[i] : NULL;
231
232 setup_storage_lists(q, irq_ptr, input_sbal_array, i);
233 input_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
234
235 if (is_thinint_irq(irq_ptr)) {
236 tasklet_init(&q->tasklet, tiqdio_inbound_processing,
237 (unsigned long) q);
238 } else {
239 tasklet_init(&q->tasklet, qdio_inbound_processing,
240 (unsigned long) q);
241 }
242 }
243
244 for_each_output_queue(irq_ptr, q, i) {
245 DBF_EVENT("outq:%1d", i);
246 setup_queues_misc(q, irq_ptr, qdio_init->output_handler, i);
247
248 q->u.out.sbal_state = output_sbal_state_array;
249 output_sbal_state_array += QDIO_MAX_BUFFERS_PER_Q;
250
251 q->is_input_q = 0;
252 setup_storage_lists(q, irq_ptr, output_sbal_array, i);
253 output_sbal_array += QDIO_MAX_BUFFERS_PER_Q;
254
255 tasklet_init(&q->tasklet, qdio_outbound_processing,
256 (unsigned long) q);
257 timer_setup(&q->u.out.timer, qdio_outbound_timer, 0);
258 }
259 }
260
261 static void process_ac_flags(struct qdio_irq *irq_ptr, unsigned char qdioac)
262 {
263 if (qdioac & AC1_SIGA_INPUT_NEEDED)
264 irq_ptr->siga_flag.input = 1;
265 if (qdioac & AC1_SIGA_OUTPUT_NEEDED)
266 irq_ptr->siga_flag.output = 1;
267 if (qdioac & AC1_SIGA_SYNC_NEEDED)
268 irq_ptr->siga_flag.sync = 1;
269 if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_THININT))
270 irq_ptr->siga_flag.sync_after_ai = 1;
271 if (!(qdioac & AC1_AUTOMATIC_SYNC_ON_OUT_PCI))
272 irq_ptr->siga_flag.sync_out_after_pci = 1;
273 }
274
275 static void check_and_setup_qebsm(struct qdio_irq *irq_ptr,
276 unsigned char qdioac, unsigned long token)
277 {
278 if (!(irq_ptr->qib.rflags & QIB_RFLAGS_ENABLE_QEBSM))
279 goto no_qebsm;
280 if (!(qdioac & AC1_SC_QEBSM_AVAILABLE) ||
281 (!(qdioac & AC1_SC_QEBSM_ENABLED)))
282 goto no_qebsm;
283
284 irq_ptr->sch_token = token;
285
286 DBF_EVENT("V=V:1");
287 DBF_EVENT("%8lx", irq_ptr->sch_token);
288 return;
289
290 no_qebsm:
291 irq_ptr->sch_token = 0;
292 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
293 DBF_EVENT("noV=V");
294 }
295
296
297
298
299
300 int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
301 struct subchannel_id *schid,
302 struct qdio_ssqd_desc *data)
303 {
304 struct chsc_ssqd_area *ssqd;
305 int rc;
306
307 DBF_EVENT("getssqd:%4x", schid->sch_no);
308 if (!irq_ptr) {
309 ssqd = (struct chsc_ssqd_area *)__get_free_page(GFP_KERNEL);
310 if (!ssqd)
311 return -ENOMEM;
312 } else {
313 ssqd = (struct chsc_ssqd_area *)irq_ptr->chsc_page;
314 }
315
316 rc = chsc_ssqd(*schid, ssqd);
317 if (rc)
318 goto out;
319
320 if (!(ssqd->qdio_ssqd.flags & CHSC_FLAG_QDIO_CAPABILITY) ||
321 !(ssqd->qdio_ssqd.flags & CHSC_FLAG_VALIDITY) ||
322 (ssqd->qdio_ssqd.sch != schid->sch_no))
323 rc = -EINVAL;
324
325 if (!rc)
326 memcpy(data, &ssqd->qdio_ssqd, sizeof(*data));
327
328 out:
329 if (!irq_ptr)
330 free_page((unsigned long)ssqd);
331
332 return rc;
333 }
334
335 void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr)
336 {
337 unsigned char qdioac;
338 int rc;
339
340 rc = qdio_setup_get_ssqd(irq_ptr, &irq_ptr->schid, &irq_ptr->ssqd_desc);
341 if (rc) {
342 DBF_ERROR("%4x ssqd ERR", irq_ptr->schid.sch_no);
343 DBF_ERROR("rc:%x", rc);
344
345 qdioac = AC1_SIGA_INPUT_NEEDED | AC1_SIGA_OUTPUT_NEEDED |
346 AC1_SIGA_SYNC_NEEDED;
347 } else
348 qdioac = irq_ptr->ssqd_desc.qdioac1;
349
350 check_and_setup_qebsm(irq_ptr, qdioac, irq_ptr->ssqd_desc.sch_token);
351 process_ac_flags(irq_ptr, qdioac);
352 DBF_EVENT("ac 1:%2x 2:%4x", qdioac, irq_ptr->ssqd_desc.qdioac2);
353 DBF_EVENT("3:%4x qib:%4x", irq_ptr->ssqd_desc.qdioac3, irq_ptr->qib.ac);
354 }
355
356 void qdio_release_memory(struct qdio_irq *irq_ptr)
357 {
358 struct qdio_q *q;
359 int i;
360
361
362
363
364
365 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
366 q = irq_ptr->input_qs[i];
367 if (q) {
368 free_page((unsigned long) q->slib);
369 kmem_cache_free(qdio_q_cache, q);
370 }
371 }
372 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
373 q = irq_ptr->output_qs[i];
374 if (q) {
375 if (q->u.out.use_cq) {
376 int n;
377
378 for (n = 0; n < QDIO_MAX_BUFFERS_PER_Q; ++n) {
379 struct qaob *aob = q->u.out.aobs[n];
380 if (aob) {
381 qdio_release_aob(aob);
382 q->u.out.aobs[n] = NULL;
383 }
384 }
385
386 qdio_disable_async_operation(&q->u.out);
387 }
388 free_page((unsigned long) q->slib);
389 kmem_cache_free(qdio_q_cache, q);
390 }
391 }
392 free_page((unsigned long) irq_ptr->qdr);
393 free_page(irq_ptr->chsc_page);
394 free_page((unsigned long) irq_ptr);
395 }
396
397 static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr,
398 struct qdio_q **irq_ptr_qs,
399 int i, int nr)
400 {
401 irq_ptr->qdr->qdf0[i + nr].sliba =
402 (unsigned long)irq_ptr_qs[i]->slib;
403
404 irq_ptr->qdr->qdf0[i + nr].sla =
405 (unsigned long)irq_ptr_qs[i]->sl;
406
407 irq_ptr->qdr->qdf0[i + nr].slsba =
408 (unsigned long)&irq_ptr_qs[i]->slsb.val[0];
409
410 irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4;
411 irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4;
412 irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4;
413 irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4;
414 }
415
416 static void setup_qdr(struct qdio_irq *irq_ptr,
417 struct qdio_initialize *qdio_init)
418 {
419 int i;
420
421 irq_ptr->qdr->qfmt = qdio_init->q_format;
422 irq_ptr->qdr->ac = qdio_init->qdr_ac;
423 irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs;
424 irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs;
425 irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4;
426 irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4;
427 irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib;
428 irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4;
429
430 for (i = 0; i < qdio_init->no_input_qs; i++)
431 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0);
432
433 for (i = 0; i < qdio_init->no_output_qs; i++)
434 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i,
435 qdio_init->no_input_qs);
436 }
437
438 static void setup_qib(struct qdio_irq *irq_ptr,
439 struct qdio_initialize *init_data)
440 {
441 if (qebsm_possible())
442 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
443
444 irq_ptr->qib.rflags |= init_data->qib_rflags;
445
446 irq_ptr->qib.qfmt = init_data->q_format;
447 if (init_data->no_input_qs)
448 irq_ptr->qib.isliba =
449 (unsigned long)(irq_ptr->input_qs[0]->slib);
450 if (init_data->no_output_qs)
451 irq_ptr->qib.osliba =
452 (unsigned long)(irq_ptr->output_qs[0]->slib);
453 memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8);
454 }
455
456 int qdio_setup_irq(struct qdio_initialize *init_data)
457 {
458 struct ciw *ciw;
459 struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data;
460
461 memset(&irq_ptr->qib, 0, sizeof(irq_ptr->qib));
462 memset(&irq_ptr->siga_flag, 0, sizeof(irq_ptr->siga_flag));
463 memset(&irq_ptr->ccw, 0, sizeof(irq_ptr->ccw));
464 memset(&irq_ptr->ssqd_desc, 0, sizeof(irq_ptr->ssqd_desc));
465 memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat));
466
467 irq_ptr->debugfs_dev = irq_ptr->debugfs_perf = NULL;
468 irq_ptr->sch_token = irq_ptr->state = irq_ptr->perf_stat_enabled = 0;
469
470
471 memset(irq_ptr->qdr, 0, sizeof(struct qdr));
472
473 irq_ptr->int_parm = init_data->int_parm;
474 irq_ptr->nr_input_qs = init_data->no_input_qs;
475 irq_ptr->nr_output_qs = init_data->no_output_qs;
476 irq_ptr->cdev = init_data->cdev;
477 irq_ptr->scan_threshold = init_data->scan_threshold;
478 ccw_device_get_schid(irq_ptr->cdev, &irq_ptr->schid);
479 setup_queues(irq_ptr, init_data);
480
481 setup_qib(irq_ptr, init_data);
482 qdio_setup_thinint(irq_ptr);
483 set_impl_params(irq_ptr, init_data->qib_param_field_format,
484 init_data->qib_param_field,
485 init_data->input_slib_elements,
486 init_data->output_slib_elements);
487
488
489 setup_qdr(irq_ptr, init_data);
490
491
492
493
494 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
495 if (!ciw) {
496 DBF_ERROR("%4x NO EQ", irq_ptr->schid.sch_no);
497 return -EINVAL;
498 }
499 irq_ptr->equeue = *ciw;
500
501 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
502 if (!ciw) {
503 DBF_ERROR("%4x NO AQ", irq_ptr->schid.sch_no);
504 return -EINVAL;
505 }
506 irq_ptr->aqueue = *ciw;
507
508
509 spin_lock_irq(get_ccwdev_lock(irq_ptr->cdev));
510 irq_ptr->orig_handler = init_data->cdev->handler;
511 init_data->cdev->handler = qdio_int_handler;
512 spin_unlock_irq(get_ccwdev_lock(irq_ptr->cdev));
513 return 0;
514 }
515
516 void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
517 struct ccw_device *cdev)
518 {
519 char s[80];
520
521 snprintf(s, 80, "qdio: %s %s on SC %x using "
522 "AI:%d QEBSM:%d PRI:%d TDD:%d SIGA:%s%s%s%s%s\n",
523 dev_name(&cdev->dev),
524 (irq_ptr->qib.qfmt == QDIO_QETH_QFMT) ? "OSA" :
525 ((irq_ptr->qib.qfmt == QDIO_ZFCP_QFMT) ? "ZFCP" : "HS"),
526 irq_ptr->schid.sch_no,
527 is_thinint_irq(irq_ptr),
528 (irq_ptr->sch_token) ? 1 : 0,
529 pci_out_supported(irq_ptr) ? 1 : 0,
530 css_general_characteristics.aif_tdd,
531 (irq_ptr->siga_flag.input) ? "R" : " ",
532 (irq_ptr->siga_flag.output) ? "W" : " ",
533 (irq_ptr->siga_flag.sync) ? "S" : " ",
534 (irq_ptr->siga_flag.sync_after_ai) ? "A" : " ",
535 (irq_ptr->siga_flag.sync_out_after_pci) ? "P" : " ");
536 printk(KERN_INFO "%s", s);
537 }
538
539 int qdio_enable_async_operation(struct qdio_output_q *outq)
540 {
541 outq->aobs = kcalloc(QDIO_MAX_BUFFERS_PER_Q, sizeof(struct qaob *),
542 GFP_ATOMIC);
543 if (!outq->aobs) {
544 outq->use_cq = 0;
545 return -ENOMEM;
546 }
547 outq->use_cq = 1;
548 return 0;
549 }
550
551 void qdio_disable_async_operation(struct qdio_output_q *q)
552 {
553 kfree(q->aobs);
554 q->aobs = NULL;
555 q->use_cq = 0;
556 }
557
558 int __init qdio_setup_init(void)
559 {
560 int rc;
561
562 qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q),
563 256, 0, NULL);
564 if (!qdio_q_cache)
565 return -ENOMEM;
566
567 qdio_aob_cache = kmem_cache_create("qdio_aob",
568 sizeof(struct qaob),
569 sizeof(struct qaob),
570 0,
571 NULL);
572 if (!qdio_aob_cache) {
573 rc = -ENOMEM;
574 goto free_qdio_q_cache;
575 }
576
577
578 DBF_EVENT("thinint:%1d",
579 (css_general_characteristics.aif_osa) ? 1 : 0);
580
581
582 DBF_EVENT("cssQEBSM:%1d", (qebsm_possible()) ? 1 : 0);
583 rc = 0;
584 out:
585 return rc;
586 free_qdio_q_cache:
587 kmem_cache_destroy(qdio_q_cache);
588 goto out;
589 }
590
591 void qdio_setup_exit(void)
592 {
593 kmem_cache_destroy(qdio_aob_cache);
594 kmem_cache_destroy(qdio_q_cache);
595 }