Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / s390 / cio / qdio.c
blob96f519281d92c4452207d746269bbae2d7925adf
1 /*
3 * linux/drivers/s390/cio/qdio.c
5 * Linux for S/390 QDIO base support, Hipersocket base support
6 * version 2
8 * Copyright 2000,2002 IBM Corporation
9 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
10 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
12 * Restriction: only 63 iqdio subchannels would have its own indicator,
13 * after that, subsequent subchannels share one indicator
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
37 #include <linux/slab.h>
38 #include <linux/kernel.h>
39 #include <linux/proc_fs.h>
40 #include <linux/timer.h>
41 #include <linux/mempool.h>
43 #include <asm/ccwdev.h>
44 #include <asm/io.h>
45 #include <asm/atomic.h>
46 #include <asm/semaphore.h>
47 #include <asm/timex.h>
49 #include <asm/debug.h>
50 #include <asm/qdio.h>
52 #include "cio.h"
53 #include "css.h"
54 #include "device.h"
55 #include "airq.h"
56 #include "qdio.h"
57 #include "ioasm.h"
58 #include "chsc.h"
60 /****************** MODULE PARAMETER VARIABLES ********************/
61 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
62 MODULE_DESCRIPTION("QDIO base support version 2, " \
63 "Copyright 2000 IBM Corporation");
64 MODULE_LICENSE("GPL");
66 /******************** HERE WE GO ***********************************/
68 static const char version[] = "QDIO base support version 2";
70 #ifdef QDIO_PERFORMANCE_STATS
71 static int proc_perf_file_registration;
72 static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
73 static struct qdio_perf_stats perf_stats;
74 #endif /* QDIO_PERFORMANCE_STATS */
76 static int hydra_thinints;
77 static int is_passthrough = 0;
78 static int omit_svs;
80 static int indicator_used[INDICATORS_PER_CACHELINE];
81 static __u32 * volatile indicators;
82 static __u32 volatile spare_indicator;
83 static atomic_t spare_indicator_usecount;
84 #define QDIO_MEMPOOL_SCSSC_ELEMENTS 2
85 static mempool_t *qdio_mempool_scssc;
87 static debug_info_t *qdio_dbf_setup;
88 static debug_info_t *qdio_dbf_sbal;
89 static debug_info_t *qdio_dbf_trace;
90 static debug_info_t *qdio_dbf_sense;
91 #ifdef CONFIG_QDIO_DEBUG
92 static debug_info_t *qdio_dbf_slsb_out;
93 static debug_info_t *qdio_dbf_slsb_in;
94 #endif /* CONFIG_QDIO_DEBUG */
96 /* iQDIO stuff: */
97 static volatile struct qdio_q *tiq_list=NULL; /* volatile as it could change
98 during a while loop */
99 static DEFINE_SPINLOCK(ttiq_list_lock);
100 static int register_thinint_result;
101 static void tiqdio_tl(unsigned long);
102 static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0);
104 /* not a macro, as one of the arguments is atomic_read */
105 static inline int
106 qdio_min(int a,int b)
108 if (a<b)
109 return a;
110 else
111 return b;
114 /***************** SCRUBBER HELPER ROUTINES **********************/
116 static inline __u64
117 qdio_get_micros(void)
119 return (get_clock() >> 10); /* time>>12 is microseconds */
123 * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve
124 * the q in any case, so that we'll not be interrupted when we are in
125 * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost
126 * ever works (last famous words)
128 static inline int
129 qdio_reserve_q(struct qdio_q *q)
131 return atomic_add_return(1,&q->use_count) - 1;
134 static inline void
135 qdio_release_q(struct qdio_q *q)
137 atomic_dec(&q->use_count);
140 /*check ccq */
141 static inline int
142 qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
144 char dbf_text[15];
146 if (ccq == 0 || ccq == 32 || ccq == 96)
147 return 0;
148 if (ccq == 97)
149 return 1;
150 /*notify devices immediately*/
151 sprintf(dbf_text,"%d", ccq);
152 QDIO_DBF_TEXT2(1,trace,dbf_text);
153 return -EIO;
155 /* EQBS: extract buffer states */
156 static inline int
157 qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
158 unsigned int *start, unsigned int *cnt)
160 struct qdio_irq *irq;
161 unsigned int tmp_cnt, q_no, ccq;
162 int rc ;
163 char dbf_text[15];
165 ccq = 0;
166 tmp_cnt = *cnt;
167 irq = (struct qdio_irq*)q->irq_ptr;
168 q_no = q->q_no;
169 if(!q->is_input_q)
170 q_no += irq->no_input_qs;
171 again:
172 ccq = do_eqbs(irq->sch_token, state, q_no, start, cnt);
173 rc = qdio_check_ccq(q, ccq);
174 if (rc == 1) {
175 QDIO_DBF_TEXT5(1,trace,"eqAGAIN");
176 goto again;
178 if (rc < 0) {
179 QDIO_DBF_TEXT2(1,trace,"eqberr");
180 sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt, *cnt, ccq, q_no);
181 QDIO_DBF_TEXT2(1,trace,dbf_text);
182 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
183 QDIO_STATUS_LOOK_FOR_ERROR,
184 0, 0, 0, -1, -1, q->int_parm);
185 return 0;
187 return (tmp_cnt - *cnt);
190 /* SQBS: set buffer states */
191 static inline int
192 qdio_do_sqbs(struct qdio_q *q, unsigned char state,
193 unsigned int *start, unsigned int *cnt)
195 struct qdio_irq *irq;
196 unsigned int tmp_cnt, q_no, ccq;
197 int rc;
198 char dbf_text[15];
200 ccq = 0;
201 tmp_cnt = *cnt;
202 irq = (struct qdio_irq*)q->irq_ptr;
203 q_no = q->q_no;
204 if(!q->is_input_q)
205 q_no += irq->no_input_qs;
206 again:
207 ccq = do_sqbs(irq->sch_token, state, q_no, start, cnt);
208 rc = qdio_check_ccq(q, ccq);
209 if (rc == 1) {
210 QDIO_DBF_TEXT5(1,trace,"sqAGAIN");
211 goto again;
213 if (rc < 0) {
214 QDIO_DBF_TEXT3(1,trace,"sqberr");
215 sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt,*cnt,ccq,q_no);
216 QDIO_DBF_TEXT3(1,trace,dbf_text);
217 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
218 QDIO_STATUS_LOOK_FOR_ERROR,
219 0, 0, 0, -1, -1, q->int_parm);
220 return 0;
222 return (tmp_cnt - *cnt);
225 static inline int
226 qdio_set_slsb(struct qdio_q *q, unsigned int *bufno,
227 unsigned char state, unsigned int *count)
229 volatile char *slsb;
230 struct qdio_irq *irq;
232 irq = (struct qdio_irq*)q->irq_ptr;
233 if (!irq->is_qebsm) {
234 slsb = (char *)&q->slsb.acc.val[(*bufno)];
235 xchg(slsb, state);
236 return 1;
238 return qdio_do_sqbs(q, state, bufno, count);
241 #ifdef CONFIG_QDIO_DEBUG
242 static inline void
243 qdio_trace_slsb(struct qdio_q *q)
245 if (q->queue_type==QDIO_TRACE_QTYPE) {
246 if (q->is_input_q)
247 QDIO_DBF_HEX2(0,slsb_in,&q->slsb,
248 QDIO_MAX_BUFFERS_PER_Q);
249 else
250 QDIO_DBF_HEX2(0,slsb_out,&q->slsb,
251 QDIO_MAX_BUFFERS_PER_Q);
254 #endif
256 static inline int
257 set_slsb(struct qdio_q *q, unsigned int *bufno,
258 unsigned char state, unsigned int *count)
260 int rc;
261 #ifdef CONFIG_QDIO_DEBUG
262 qdio_trace_slsb(q);
263 #endif
264 rc = qdio_set_slsb(q, bufno, state, count);
265 #ifdef CONFIG_QDIO_DEBUG
266 qdio_trace_slsb(q);
267 #endif
268 return rc;
270 static inline int
271 qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
272 unsigned int gpr3)
274 int cc;
276 QDIO_DBF_TEXT4(0,trace,"sigasync");
277 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
279 #ifdef QDIO_PERFORMANCE_STATS
280 perf_stats.siga_syncs++;
281 #endif /* QDIO_PERFORMANCE_STATS */
283 cc = do_siga_sync(q->schid, gpr2, gpr3);
284 if (cc)
285 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
287 return cc;
290 static inline int
291 qdio_siga_sync_q(struct qdio_q *q)
293 if (q->is_input_q)
294 return qdio_siga_sync(q, 0, q->mask);
295 return qdio_siga_sync(q, q->mask, 0);
298 static int
299 __do_siga_output(struct qdio_q *q, unsigned int *busy_bit)
301 struct qdio_irq *irq;
302 unsigned int fc = 0;
303 unsigned long schid;
305 irq = (struct qdio_irq *) q->irq_ptr;
306 if (!irq->is_qebsm)
307 schid = *((u32 *)&q->schid);
308 else {
309 schid = irq->sch_token;
310 fc |= 0x80;
312 return do_siga_output(schid, q->mask, busy_bit, fc);
316 * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns
317 * an access exception
319 static inline int
320 qdio_siga_output(struct qdio_q *q)
322 int cc;
323 __u32 busy_bit;
324 __u64 start_time=0;
326 #ifdef QDIO_PERFORMANCE_STATS
327 perf_stats.siga_outs++;
328 #endif /* QDIO_PERFORMANCE_STATS */
330 QDIO_DBF_TEXT4(0,trace,"sigaout");
331 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
333 for (;;) {
334 cc = __do_siga_output(q, &busy_bit);
335 //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit);
336 if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) {
337 if (!start_time)
338 start_time=NOW;
339 if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE)
340 break;
341 } else
342 break;
345 if ((cc==2) && (busy_bit))
346 cc |= QDIO_SIGA_ERROR_B_BIT_SET;
348 if (cc)
349 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
351 return cc;
354 static inline int
355 qdio_siga_input(struct qdio_q *q)
357 int cc;
359 QDIO_DBF_TEXT4(0,trace,"sigain");
360 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
362 #ifdef QDIO_PERFORMANCE_STATS
363 perf_stats.siga_ins++;
364 #endif /* QDIO_PERFORMANCE_STATS */
366 cc = do_siga_input(q->schid, q->mask);
368 if (cc)
369 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
371 return cc;
374 /* locked by the locks in qdio_activate and qdio_cleanup */
375 static __u32 *
376 qdio_get_indicator(void)
378 int i;
380 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
381 if (!indicator_used[i]) {
382 indicator_used[i]=1;
383 return indicators+i;
385 atomic_inc(&spare_indicator_usecount);
386 return (__u32 * volatile) &spare_indicator;
389 /* locked by the locks in qdio_activate and qdio_cleanup */
390 static void
391 qdio_put_indicator(__u32 *addr)
393 int i;
395 if ( (addr) && (addr!=&spare_indicator) ) {
396 i=addr-indicators;
397 indicator_used[i]=0;
399 if (addr == &spare_indicator)
400 atomic_dec(&spare_indicator_usecount);
403 static inline void
404 tiqdio_clear_summary_bit(__u32 *location)
406 QDIO_DBF_TEXT5(0,trace,"clrsummb");
407 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
409 xchg(location,0);
412 static inline void
413 tiqdio_set_summary_bit(__u32 *location)
415 QDIO_DBF_TEXT5(0,trace,"setsummb");
416 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
418 xchg(location,-1);
421 static inline void
422 tiqdio_sched_tl(void)
424 tasklet_hi_schedule(&tiqdio_tasklet);
427 static inline void
428 qdio_mark_tiq(struct qdio_q *q)
430 unsigned long flags;
432 QDIO_DBF_TEXT4(0,trace,"mark iq");
433 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
435 spin_lock_irqsave(&ttiq_list_lock,flags);
436 if (unlikely(atomic_read(&q->is_in_shutdown)))
437 goto out_unlock;
439 if (!q->is_input_q)
440 goto out_unlock;
442 if ((q->list_prev) || (q->list_next))
443 goto out_unlock;
445 if (!tiq_list) {
446 tiq_list=q;
447 q->list_prev=q;
448 q->list_next=q;
449 } else {
450 q->list_next=tiq_list;
451 q->list_prev=tiq_list->list_prev;
452 tiq_list->list_prev->list_next=q;
453 tiq_list->list_prev=q;
455 spin_unlock_irqrestore(&ttiq_list_lock,flags);
457 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
458 tiqdio_sched_tl();
459 return;
460 out_unlock:
461 spin_unlock_irqrestore(&ttiq_list_lock,flags);
462 return;
465 static inline void
466 qdio_mark_q(struct qdio_q *q)
468 QDIO_DBF_TEXT4(0,trace,"mark q");
469 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
471 if (unlikely(atomic_read(&q->is_in_shutdown)))
472 return;
474 tasklet_schedule(&q->tasklet);
477 static inline int
478 qdio_stop_polling(struct qdio_q *q)
480 #ifdef QDIO_USE_PROCESSING_STATE
481 unsigned int tmp, gsf, count = 1;
482 unsigned char state = 0;
483 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
485 if (!atomic_swap(&q->polling,0))
486 return 1;
488 QDIO_DBF_TEXT4(0,trace,"stoppoll");
489 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
491 /* show the card that we are not polling anymore */
492 if (!q->is_input_q)
493 return 1;
495 tmp = gsf = GET_SAVED_FRONTIER(q);
496 tmp = ((tmp + QDIO_MAX_BUFFERS_PER_Q-1) & (QDIO_MAX_BUFFERS_PER_Q-1) );
497 set_slsb(q, &tmp, SLSB_P_INPUT_NOT_INIT, &count);
500 * we don't issue this SYNC_MEMORY, as we trust Rick T and
501 * moreover will not use the PROCESSING state under VM, so
502 * q->polling was 0 anyway
504 /*SYNC_MEMORY;*/
505 if (irq->is_qebsm) {
506 count = 1;
507 qdio_do_eqbs(q, &state, &gsf, &count);
508 } else
509 state = q->slsb.acc.val[gsf];
510 if (state != SLSB_P_INPUT_PRIMED)
511 return 1;
513 * set our summary bit again, as otherwise there is a
514 * small window we can miss between resetting it and
515 * checking for PRIMED state
517 if (q->is_thinint_q)
518 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
519 return 0;
521 #else /* QDIO_USE_PROCESSING_STATE */
522 return 1;
523 #endif /* QDIO_USE_PROCESSING_STATE */
527 * see the comment in do_QDIO and before qdio_reserve_q about the
528 * sophisticated locking outside of unmark_q, so that we don't need to
529 * disable the interrupts :-)
531 static inline void
532 qdio_unmark_q(struct qdio_q *q)
534 unsigned long flags;
536 QDIO_DBF_TEXT4(0,trace,"unmark q");
537 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
539 if ((!q->list_prev)||(!q->list_next))
540 return;
542 if ((q->is_thinint_q)&&(q->is_input_q)) {
543 /* iQDIO */
544 spin_lock_irqsave(&ttiq_list_lock,flags);
545 /* in case cleanup has done this already and simultanously
546 * qdio_unmark_q is called from the interrupt handler, we've
547 * got to check this in this specific case again */
548 if ((!q->list_prev)||(!q->list_next))
549 goto out;
550 if (q->list_next==q) {
551 /* q was the only interesting q */
552 tiq_list=NULL;
553 q->list_next=NULL;
554 q->list_prev=NULL;
555 } else {
556 q->list_next->list_prev=q->list_prev;
557 q->list_prev->list_next=q->list_next;
558 tiq_list=q->list_next;
559 q->list_next=NULL;
560 q->list_prev=NULL;
562 out:
563 spin_unlock_irqrestore(&ttiq_list_lock,flags);
567 static inline unsigned long
568 tiqdio_clear_global_summary(void)
570 unsigned long time;
572 QDIO_DBF_TEXT5(0,trace,"clrglobl");
574 time = do_clear_global_summary();
576 QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long));
578 return time;
582 /************************* OUTBOUND ROUTINES *******************************/
583 static int
584 qdio_qebsm_get_outbound_buffer_frontier(struct qdio_q *q)
586 struct qdio_irq *irq;
587 unsigned char state;
588 unsigned int cnt, count, ftc;
590 irq = (struct qdio_irq *) q->irq_ptr;
591 if ((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis))
592 SYNC_MEMORY;
594 ftc = q->first_to_check;
595 count = qdio_min(atomic_read(&q->number_of_buffers_used),
596 (QDIO_MAX_BUFFERS_PER_Q-1));
597 if (count == 0)
598 return q->first_to_check;
599 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
600 if (cnt == 0)
601 return q->first_to_check;
602 switch (state) {
603 case SLSB_P_OUTPUT_ERROR:
604 QDIO_DBF_TEXT3(0,trace,"outperr");
605 atomic_sub(cnt , &q->number_of_buffers_used);
606 if (q->qdio_error)
607 q->error_status_flags |=
608 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
609 q->qdio_error = SLSB_P_OUTPUT_ERROR;
610 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
611 q->first_to_check = ftc;
612 break;
613 case SLSB_P_OUTPUT_EMPTY:
614 QDIO_DBF_TEXT5(0,trace,"outpempt");
615 atomic_sub(cnt, &q->number_of_buffers_used);
616 q->first_to_check = ftc;
617 break;
618 case SLSB_CU_OUTPUT_PRIMED:
619 /* all buffers primed */
620 QDIO_DBF_TEXT5(0,trace,"outpprim");
621 break;
622 default:
623 break;
625 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
626 return q->first_to_check;
629 static int
630 qdio_qebsm_get_inbound_buffer_frontier(struct qdio_q *q)
632 struct qdio_irq *irq;
633 unsigned char state;
634 int tmp, ftc, count, cnt;
635 char dbf_text[15];
638 irq = (struct qdio_irq *) q->irq_ptr;
639 ftc = q->first_to_check;
640 count = qdio_min(atomic_read(&q->number_of_buffers_used),
641 (QDIO_MAX_BUFFERS_PER_Q-1));
642 if (count == 0)
643 return q->first_to_check;
644 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
645 if (cnt == 0)
646 return q->first_to_check;
647 switch (state) {
648 case SLSB_P_INPUT_ERROR :
649 #ifdef CONFIG_QDIO_DEBUG
650 QDIO_DBF_TEXT3(1,trace,"inperr");
651 sprintf(dbf_text,"%2x,%2x",ftc,count);
652 QDIO_DBF_TEXT3(1,trace,dbf_text);
653 #endif /* CONFIG_QDIO_DEBUG */
654 if (q->qdio_error)
655 q->error_status_flags |=
656 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
657 q->qdio_error = SLSB_P_INPUT_ERROR;
658 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
659 atomic_sub(cnt, &q->number_of_buffers_used);
660 q->first_to_check = ftc;
661 break;
662 case SLSB_P_INPUT_PRIMED :
663 QDIO_DBF_TEXT3(0,trace,"inptprim");
664 sprintf(dbf_text,"%2x,%2x",ftc,count);
665 QDIO_DBF_TEXT3(1,trace,dbf_text);
666 tmp = 0;
667 ftc = q->first_to_check;
668 #ifdef QDIO_USE_PROCESSING_STATE
669 if (cnt > 1) {
670 cnt -= 1;
671 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
672 if (!tmp)
673 break;
675 cnt = 1;
676 tmp += set_slsb(q, &ftc,
677 SLSB_P_INPUT_PROCESSING, &cnt);
678 atomic_set(&q->polling, 1);
679 #else
680 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
681 #endif
682 atomic_sub(tmp, &q->number_of_buffers_used);
683 q->first_to_check = ftc;
684 break;
685 case SLSB_CU_INPUT_EMPTY:
686 case SLSB_P_INPUT_NOT_INIT:
687 case SLSB_P_INPUT_PROCESSING:
688 QDIO_DBF_TEXT5(0,trace,"inpnipro");
689 break;
690 default:
691 break;
693 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
694 return q->first_to_check;
697 static inline int
698 qdio_get_outbound_buffer_frontier(struct qdio_q *q)
700 struct qdio_irq *irq;
701 volatile char *slsb;
702 unsigned int count = 1;
703 int first_not_to_check, f, f_mod_no;
704 char dbf_text[15];
706 QDIO_DBF_TEXT4(0,trace,"getobfro");
707 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
709 irq = (struct qdio_irq *) q->irq_ptr;
710 if (irq->is_qebsm)
711 return qdio_qebsm_get_outbound_buffer_frontier(q);
713 slsb=&q->slsb.acc.val[0];
714 f_mod_no=f=q->first_to_check;
716 * f points to already processed elements, so f+no_used is correct...
717 * ... but: we don't check 128 buffers, as otherwise
718 * qdio_has_outbound_q_moved would return 0
720 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
721 (QDIO_MAX_BUFFERS_PER_Q-1));
723 if ((!q->is_iqdio_q)&&(!q->hydra_gives_outbound_pcis))
724 SYNC_MEMORY;
726 check_next:
727 if (f==first_not_to_check)
728 goto out;
730 switch(slsb[f_mod_no]) {
732 /* the adapter has not fetched the output yet */
733 case SLSB_CU_OUTPUT_PRIMED:
734 QDIO_DBF_TEXT5(0,trace,"outpprim");
735 break;
737 /* the adapter got it */
738 case SLSB_P_OUTPUT_EMPTY:
739 atomic_dec(&q->number_of_buffers_used);
740 f++;
741 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
742 QDIO_DBF_TEXT5(0,trace,"outpempt");
743 goto check_next;
745 case SLSB_P_OUTPUT_ERROR:
746 QDIO_DBF_TEXT3(0,trace,"outperr");
747 sprintf(dbf_text,"%x-%x-%x",f_mod_no,
748 q->sbal[f_mod_no]->element[14].sbalf.value,
749 q->sbal[f_mod_no]->element[15].sbalf.value);
750 QDIO_DBF_TEXT3(1,trace,dbf_text);
751 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
753 /* kind of process the buffer */
754 set_slsb(q, &f_mod_no, SLSB_P_OUTPUT_NOT_INIT, &count);
757 * we increment the frontier, as this buffer
758 * was processed obviously
760 atomic_dec(&q->number_of_buffers_used);
761 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
763 if (q->qdio_error)
764 q->error_status_flags|=
765 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
766 q->qdio_error=SLSB_P_OUTPUT_ERROR;
767 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
769 break;
771 /* no new buffers */
772 default:
773 QDIO_DBF_TEXT5(0,trace,"outpni");
775 out:
776 return (q->first_to_check=f_mod_no);
779 /* all buffers are processed */
780 static inline int
781 qdio_is_outbound_q_done(struct qdio_q *q)
783 int no_used;
784 #ifdef CONFIG_QDIO_DEBUG
785 char dbf_text[15];
786 #endif
788 no_used=atomic_read(&q->number_of_buffers_used);
790 #ifdef CONFIG_QDIO_DEBUG
791 if (no_used) {
792 sprintf(dbf_text,"oqisnt%02x",no_used);
793 QDIO_DBF_TEXT4(0,trace,dbf_text);
794 } else {
795 QDIO_DBF_TEXT4(0,trace,"oqisdone");
797 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
798 #endif /* CONFIG_QDIO_DEBUG */
799 return (no_used==0);
802 static inline int
803 qdio_has_outbound_q_moved(struct qdio_q *q)
805 int i;
807 i=qdio_get_outbound_buffer_frontier(q);
809 if ( (i!=GET_SAVED_FRONTIER(q)) ||
810 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
811 SAVE_FRONTIER(q,i);
812 QDIO_DBF_TEXT4(0,trace,"oqhasmvd");
813 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
814 return 1;
815 } else {
816 QDIO_DBF_TEXT4(0,trace,"oqhsntmv");
817 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
818 return 0;
822 static inline void
823 qdio_kick_outbound_q(struct qdio_q *q)
825 int result;
826 #ifdef CONFIG_QDIO_DEBUG
827 char dbf_text[15];
829 QDIO_DBF_TEXT4(0,trace,"kickoutq");
830 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
831 #endif /* CONFIG_QDIO_DEBUG */
833 if (!q->siga_out)
834 return;
836 /* here's the story with cc=2 and busy bit set (thanks, Rick):
837 * VM's CP could present us cc=2 and busy bit set on SIGA-write
838 * during reconfiguration of their Guest LAN (only in HIPERS mode,
839 * QDIO mode is asynchronous -- cc=2 and busy bit there will take
840 * the queues down immediately; and not being under VM we have a
841 * problem on cc=2 and busy bit set right away).
843 * Therefore qdio_siga_output will try for a short time constantly,
844 * if such a condition occurs. If it doesn't change, it will
845 * increase the busy_siga_counter and save the timestamp, and
846 * schedule the queue for later processing (via mark_q, using the
847 * queue tasklet). __qdio_outbound_processing will check out the
848 * counter. If non-zero, it will call qdio_kick_outbound_q as often
849 * as the value of the counter. This will attempt further SIGA
850 * instructions. For each successful SIGA, the counter is
851 * decreased, for failing SIGAs the counter remains the same, after
852 * all.
853 * After some time of no movement, qdio_kick_outbound_q will
854 * finally fail and reflect corresponding error codes to call
855 * the upper layer module and have it take the queues down.
857 * Note that this is a change from the original HiperSockets design
858 * (saying cc=2 and busy bit means take the queues down), but in
859 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
860 * conditions will still take the queues down, but the threshold is
861 * higher due to the Guest LAN environment.
865 result=qdio_siga_output(q);
867 switch (result) {
868 case 0:
869 /* went smooth this time, reset timestamp */
870 #ifdef CONFIG_QDIO_DEBUG
871 QDIO_DBF_TEXT3(0,trace,"cc2reslv");
872 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
873 atomic_read(&q->busy_siga_counter));
874 QDIO_DBF_TEXT3(0,trace,dbf_text);
875 #endif /* CONFIG_QDIO_DEBUG */
876 q->timing.busy_start=0;
877 break;
878 case (2|QDIO_SIGA_ERROR_B_BIT_SET):
879 /* cc=2 and busy bit: */
880 atomic_inc(&q->busy_siga_counter);
882 /* if the last siga was successful, save
883 * timestamp here */
884 if (!q->timing.busy_start)
885 q->timing.busy_start=NOW;
887 /* if we're in time, don't touch error_status_flags
888 * and siga_error */
889 if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) {
890 qdio_mark_q(q);
891 break;
893 QDIO_DBF_TEXT2(0,trace,"cc2REPRT");
894 #ifdef CONFIG_QDIO_DEBUG
895 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
896 atomic_read(&q->busy_siga_counter));
897 QDIO_DBF_TEXT3(0,trace,dbf_text);
898 #endif /* CONFIG_QDIO_DEBUG */
899 /* else fallthrough and report error */
900 default:
901 /* for plain cc=1, 2 or 3: */
902 if (q->siga_error)
903 q->error_status_flags|=
904 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
905 q->error_status_flags|=
906 QDIO_STATUS_LOOK_FOR_ERROR;
907 q->siga_error=result;
911 static inline void
912 qdio_kick_outbound_handler(struct qdio_q *q)
914 int start, end, real_end, count;
915 #ifdef CONFIG_QDIO_DEBUG
916 char dbf_text[15];
917 #endif
919 start = q->first_element_to_kick;
920 /* last_move_ftc was just updated */
921 real_end = GET_SAVED_FRONTIER(q);
922 end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)&
923 (QDIO_MAX_BUFFERS_PER_Q-1);
924 count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)&
925 (QDIO_MAX_BUFFERS_PER_Q-1);
927 #ifdef CONFIG_QDIO_DEBUG
928 QDIO_DBF_TEXT4(0,trace,"kickouth");
929 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
931 sprintf(dbf_text,"s=%2xc=%2x",start,count);
932 QDIO_DBF_TEXT4(0,trace,dbf_text);
933 #endif /* CONFIG_QDIO_DEBUG */
935 if (q->state==QDIO_IRQ_STATE_ACTIVE)
936 q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT|
937 q->error_status_flags,
938 q->qdio_error,q->siga_error,q->q_no,start,count,
939 q->int_parm);
941 /* for the next time: */
942 q->first_element_to_kick=real_end;
943 q->qdio_error=0;
944 q->siga_error=0;
945 q->error_status_flags=0;
948 static inline void
949 __qdio_outbound_processing(struct qdio_q *q)
951 int siga_attempts;
953 QDIO_DBF_TEXT4(0,trace,"qoutproc");
954 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
956 if (unlikely(qdio_reserve_q(q))) {
957 qdio_release_q(q);
958 #ifdef QDIO_PERFORMANCE_STATS
959 o_p_c++;
960 #endif /* QDIO_PERFORMANCE_STATS */
961 /* as we're sissies, we'll check next time */
962 if (likely(!atomic_read(&q->is_in_shutdown))) {
963 qdio_mark_q(q);
964 QDIO_DBF_TEXT4(0,trace,"busy,agn");
966 return;
968 #ifdef QDIO_PERFORMANCE_STATS
969 o_p_nc++;
970 perf_stats.tl_runs++;
971 #endif /* QDIO_PERFORMANCE_STATS */
973 /* see comment in qdio_kick_outbound_q */
974 siga_attempts=atomic_read(&q->busy_siga_counter);
975 while (siga_attempts) {
976 atomic_dec(&q->busy_siga_counter);
977 qdio_kick_outbound_q(q);
978 siga_attempts--;
981 if (qdio_has_outbound_q_moved(q))
982 qdio_kick_outbound_handler(q);
984 if (q->is_iqdio_q) {
986 * for asynchronous queues, we better check, if the fill
987 * level is too high. for synchronous queues, the fill
988 * level will never be that high.
990 if (atomic_read(&q->number_of_buffers_used)>
991 IQDIO_FILL_LEVEL_TO_POLL)
992 qdio_mark_q(q);
994 } else if (!q->hydra_gives_outbound_pcis)
995 if (!qdio_is_outbound_q_done(q))
996 qdio_mark_q(q);
998 qdio_release_q(q);
1001 static void
1002 qdio_outbound_processing(struct qdio_q *q)
1004 __qdio_outbound_processing(q);
1007 /************************* INBOUND ROUTINES *******************************/
1010 static inline int
1011 qdio_get_inbound_buffer_frontier(struct qdio_q *q)
1013 struct qdio_irq *irq;
1014 int f,f_mod_no;
1015 volatile char *slsb;
1016 unsigned int count = 1;
1017 int first_not_to_check;
1018 #ifdef CONFIG_QDIO_DEBUG
1019 char dbf_text[15];
1020 #endif /* CONFIG_QDIO_DEBUG */
1021 #ifdef QDIO_USE_PROCESSING_STATE
1022 int last_position=-1;
1023 #endif /* QDIO_USE_PROCESSING_STATE */
1025 QDIO_DBF_TEXT4(0,trace,"getibfro");
1026 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1028 irq = (struct qdio_irq *) q->irq_ptr;
1029 if (irq->is_qebsm)
1030 return qdio_qebsm_get_inbound_buffer_frontier(q);
1032 slsb=&q->slsb.acc.val[0];
1033 f_mod_no=f=q->first_to_check;
1035 * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved
1036 * would return 0
1038 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
1039 (QDIO_MAX_BUFFERS_PER_Q-1));
1042 * we don't use this one, as a PCI or we after a thin interrupt
1043 * will sync the queues
1045 /* SYNC_MEMORY;*/
1047 check_next:
1048 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
1049 if (f==first_not_to_check)
1050 goto out;
1051 switch (slsb[f_mod_no]) {
1053 /* CU_EMPTY means frontier is reached */
1054 case SLSB_CU_INPUT_EMPTY:
1055 QDIO_DBF_TEXT5(0,trace,"inptempt");
1056 break;
1058 /* P_PRIMED means set slsb to P_PROCESSING and move on */
1059 case SLSB_P_INPUT_PRIMED:
1060 QDIO_DBF_TEXT5(0,trace,"inptprim");
1062 #ifdef QDIO_USE_PROCESSING_STATE
1064 * as soon as running under VM, polling the input queues will
1065 * kill VM in terms of CP overhead
1067 if (q->siga_sync) {
1068 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1069 } else {
1070 /* set the previous buffer to NOT_INIT. The current
1071 * buffer will be set to PROCESSING at the end of
1072 * this function to avoid further interrupts. */
1073 if (last_position>=0)
1074 set_slsb(q, &last_position,
1075 SLSB_P_INPUT_NOT_INIT, &count);
1076 atomic_set(&q->polling,1);
1077 last_position=f_mod_no;
1079 #else /* QDIO_USE_PROCESSING_STATE */
1080 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1081 #endif /* QDIO_USE_PROCESSING_STATE */
1083 * not needed, as the inbound queue will be synced on the next
1084 * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s
1086 /*SYNC_MEMORY;*/
1087 f++;
1088 atomic_dec(&q->number_of_buffers_used);
1089 goto check_next;
1091 case SLSB_P_INPUT_NOT_INIT:
1092 case SLSB_P_INPUT_PROCESSING:
1093 QDIO_DBF_TEXT5(0,trace,"inpnipro");
1094 break;
1096 /* P_ERROR means frontier is reached, break and report error */
1097 case SLSB_P_INPUT_ERROR:
1098 #ifdef CONFIG_QDIO_DEBUG
1099 sprintf(dbf_text,"inperr%2x",f_mod_no);
1100 QDIO_DBF_TEXT3(1,trace,dbf_text);
1101 #endif /* CONFIG_QDIO_DEBUG */
1102 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
1104 /* kind of process the buffer */
1105 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1107 if (q->qdio_error)
1108 q->error_status_flags|=
1109 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
1110 q->qdio_error=SLSB_P_INPUT_ERROR;
1111 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
1113 /* we increment the frontier, as this buffer
1114 * was processed obviously */
1115 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1116 atomic_dec(&q->number_of_buffers_used);
1118 #ifdef QDIO_USE_PROCESSING_STATE
1119 last_position=-1;
1120 #endif /* QDIO_USE_PROCESSING_STATE */
1122 break;
1124 /* everything else means frontier not changed (HALTED or so) */
1125 default:
1126 break;
1128 out:
1129 q->first_to_check=f_mod_no;
1131 #ifdef QDIO_USE_PROCESSING_STATE
1132 if (last_position>=0)
1133 set_slsb(q, &last_position, SLSB_P_INPUT_NOT_INIT, &count);
1134 #endif /* QDIO_USE_PROCESSING_STATE */
1136 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
1138 return q->first_to_check;
1141 static inline int
1142 qdio_has_inbound_q_moved(struct qdio_q *q)
1144 int i;
1146 #ifdef QDIO_PERFORMANCE_STATS
1147 static int old_pcis=0;
1148 static int old_thinints=0;
1150 if ((old_pcis==perf_stats.pcis)&&(old_thinints==perf_stats.thinints))
1151 perf_stats.start_time_inbound=NOW;
1152 else
1153 old_pcis=perf_stats.pcis;
1154 #endif /* QDIO_PERFORMANCE_STATS */
1156 i=qdio_get_inbound_buffer_frontier(q);
1157 if ( (i!=GET_SAVED_FRONTIER(q)) ||
1158 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
1159 SAVE_FRONTIER(q,i);
1160 if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis))
1161 SAVE_TIMESTAMP(q);
1163 QDIO_DBF_TEXT4(0,trace,"inhasmvd");
1164 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1165 return 1;
1166 } else {
1167 QDIO_DBF_TEXT4(0,trace,"inhsntmv");
1168 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1169 return 0;
1173 /* means, no more buffers to be filled */
1174 static inline int
1175 tiqdio_is_inbound_q_done(struct qdio_q *q)
1177 int no_used;
1178 unsigned int start_buf, count;
1179 unsigned char state = 0;
1180 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1182 #ifdef CONFIG_QDIO_DEBUG
1183 char dbf_text[15];
1184 #endif
1186 no_used=atomic_read(&q->number_of_buffers_used);
1188 /* propagate the change from 82 to 80 through VM */
1189 SYNC_MEMORY;
1191 #ifdef CONFIG_QDIO_DEBUG
1192 if (no_used) {
1193 sprintf(dbf_text,"iqisnt%02x",no_used);
1194 QDIO_DBF_TEXT4(0,trace,dbf_text);
1195 } else {
1196 QDIO_DBF_TEXT4(0,trace,"iniqisdo");
1198 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1199 #endif /* CONFIG_QDIO_DEBUG */
1201 if (!no_used)
1202 return 1;
1203 if (!q->siga_sync && !irq->is_qebsm)
1204 /* we'll check for more primed buffers in qeth_stop_polling */
1205 return 0;
1206 if (irq->is_qebsm) {
1207 count = 1;
1208 start_buf = q->first_to_check;
1209 qdio_do_eqbs(q, &state, &start_buf, &count);
1210 } else
1211 state = q->slsb.acc.val[q->first_to_check];
1212 if (state != SLSB_P_INPUT_PRIMED)
1214 * nothing more to do, if next buffer is not PRIMED.
1215 * note that we did a SYNC_MEMORY before, that there
1216 * has been a sychnronization.
1217 * we will return 0 below, as there is nothing to do
1218 * (stop_polling not necessary, as we have not been
1219 * using the PROCESSING state
1221 return 0;
1224 * ok, the next input buffer is primed. that means, that device state
1225 * change indicator and adapter local summary are set, so we will find
1226 * it next time.
1227 * we will return 0 below, as there is nothing to do, except scheduling
1228 * ourselves for the next time.
1230 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1231 tiqdio_sched_tl();
1232 return 0;
1235 static inline int
1236 qdio_is_inbound_q_done(struct qdio_q *q)
1238 int no_used;
1239 unsigned int start_buf, count;
1240 unsigned char state = 0;
1241 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1243 #ifdef CONFIG_QDIO_DEBUG
1244 char dbf_text[15];
1245 #endif
1247 no_used=atomic_read(&q->number_of_buffers_used);
1250 * we need that one for synchronization with the adapter, as it
1251 * does a kind of PCI avoidance
1253 SYNC_MEMORY;
1255 if (!no_used) {
1256 QDIO_DBF_TEXT4(0,trace,"inqisdnA");
1257 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1258 QDIO_DBF_TEXT4(0,trace,dbf_text);
1259 return 1;
1261 if (irq->is_qebsm) {
1262 count = 1;
1263 start_buf = q->first_to_check;
1264 qdio_do_eqbs(q, &state, &start_buf, &count);
1265 } else
1266 state = q->slsb.acc.val[q->first_to_check];
1267 if (state == SLSB_P_INPUT_PRIMED) {
1268 /* we got something to do */
1269 QDIO_DBF_TEXT4(0,trace,"inqisntA");
1270 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1271 return 0;
1274 /* on VM, we don't poll, so the q is always done here */
1275 if (q->siga_sync)
1276 return 1;
1277 if (q->hydra_gives_outbound_pcis)
1278 return 1;
1281 * at this point we know, that inbound first_to_check
1282 * has (probably) not moved (see qdio_inbound_processing)
1284 if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) {
1285 #ifdef CONFIG_QDIO_DEBUG
1286 QDIO_DBF_TEXT4(0,trace,"inqisdon");
1287 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1288 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1289 QDIO_DBF_TEXT4(0,trace,dbf_text);
1290 #endif /* CONFIG_QDIO_DEBUG */
1291 return 1;
1292 } else {
1293 #ifdef CONFIG_QDIO_DEBUG
1294 QDIO_DBF_TEXT4(0,trace,"inqisntd");
1295 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1296 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1297 QDIO_DBF_TEXT4(0,trace,dbf_text);
1298 #endif /* CONFIG_QDIO_DEBUG */
1299 return 0;
1303 static inline void
1304 qdio_kick_inbound_handler(struct qdio_q *q)
1306 int count, start, end, real_end, i;
1307 #ifdef CONFIG_QDIO_DEBUG
1308 char dbf_text[15];
1309 #endif
1311 QDIO_DBF_TEXT4(0,trace,"kickinh");
1312 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1314 start=q->first_element_to_kick;
1315 real_end=q->first_to_check;
1316 end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1318 i=start;
1319 count=0;
1320 while (1) {
1321 count++;
1322 if (i==end)
1323 break;
1324 i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1327 #ifdef CONFIG_QDIO_DEBUG
1328 sprintf(dbf_text,"s=%2xc=%2x",start,count);
1329 QDIO_DBF_TEXT4(0,trace,dbf_text);
1330 #endif /* CONFIG_QDIO_DEBUG */
1332 if (likely(q->state==QDIO_IRQ_STATE_ACTIVE))
1333 q->handler(q->cdev,
1334 QDIO_STATUS_INBOUND_INT|q->error_status_flags,
1335 q->qdio_error,q->siga_error,q->q_no,start,count,
1336 q->int_parm);
1338 /* for the next time: */
1339 q->first_element_to_kick=real_end;
1340 q->qdio_error=0;
1341 q->siga_error=0;
1342 q->error_status_flags=0;
1344 #ifdef QDIO_PERFORMANCE_STATS
1345 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
1346 perf_stats.inbound_cnt++;
1347 #endif /* QDIO_PERFORMANCE_STATS */
1350 static inline void
1351 __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1353 struct qdio_irq *irq_ptr;
1354 struct qdio_q *oq;
1355 int i;
1357 QDIO_DBF_TEXT4(0,trace,"iqinproc");
1358 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1361 * we first want to reserve the q, so that we know, that we don't
1362 * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might
1363 * be set
1365 if (unlikely(qdio_reserve_q(q))) {
1366 qdio_release_q(q);
1367 #ifdef QDIO_PERFORMANCE_STATS
1368 ii_p_c++;
1369 #endif /* QDIO_PERFORMANCE_STATS */
1371 * as we might just be about to stop polling, we make
1372 * sure that we check again at least once more
1374 tiqdio_sched_tl();
1375 return;
1377 #ifdef QDIO_PERFORMANCE_STATS
1378 ii_p_nc++;
1379 #endif /* QDIO_PERFORMANCE_STATS */
1380 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1381 qdio_unmark_q(q);
1382 goto out;
1386 * we reset spare_ind_was_set, when the queue does not use the
1387 * spare indicator
1389 if (spare_ind_was_set)
1390 spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator);
1392 if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set)
1393 goto out;
1395 * q->dev_st_chg_ind is the indicator, be it shared or not.
1396 * only clear it, if indicator is non-shared
1398 if (!spare_ind_was_set)
1399 tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind);
1401 if (q->hydra_gives_outbound_pcis) {
1402 if (!q->siga_sync_done_on_thinints) {
1403 SYNC_MEMORY_ALL;
1404 } else if ((!q->siga_sync_done_on_outb_tis)&&
1405 (q->hydra_gives_outbound_pcis)) {
1406 SYNC_MEMORY_ALL_OUTB;
1408 } else {
1409 SYNC_MEMORY;
1412 * maybe we have to do work on our outbound queues... at least
1413 * we have to check the outbound-int-capable thinint-capable
1414 * queues
1416 if (q->hydra_gives_outbound_pcis) {
1417 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1418 for (i=0;i<irq_ptr->no_output_qs;i++) {
1419 oq = irq_ptr->output_qs[i];
1420 #ifdef QDIO_PERFORMANCE_STATS
1421 perf_stats.tl_runs--;
1422 #endif /* QDIO_PERFORMANCE_STATS */
1423 if (!qdio_is_outbound_q_done(oq))
1424 __qdio_outbound_processing(oq);
1428 if (!qdio_has_inbound_q_moved(q))
1429 goto out;
1431 qdio_kick_inbound_handler(q);
1432 if (tiqdio_is_inbound_q_done(q))
1433 if (!qdio_stop_polling(q)) {
1435 * we set the flags to get into the stuff next time,
1436 * see also comment in qdio_stop_polling
1438 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1439 tiqdio_sched_tl();
1441 out:
1442 qdio_release_q(q);
1445 static void
1446 tiqdio_inbound_processing(struct qdio_q *q)
1448 __tiqdio_inbound_processing(q, atomic_read(&spare_indicator_usecount));
1451 static inline void
1452 __qdio_inbound_processing(struct qdio_q *q)
1454 int q_laps=0;
1456 QDIO_DBF_TEXT4(0,trace,"qinproc");
1457 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1459 if (unlikely(qdio_reserve_q(q))) {
1460 qdio_release_q(q);
1461 #ifdef QDIO_PERFORMANCE_STATS
1462 i_p_c++;
1463 #endif /* QDIO_PERFORMANCE_STATS */
1464 /* as we're sissies, we'll check next time */
1465 if (likely(!atomic_read(&q->is_in_shutdown))) {
1466 qdio_mark_q(q);
1467 QDIO_DBF_TEXT4(0,trace,"busy,agn");
1469 return;
1471 #ifdef QDIO_PERFORMANCE_STATS
1472 i_p_nc++;
1473 perf_stats.tl_runs++;
1474 #endif /* QDIO_PERFORMANCE_STATS */
1476 again:
1477 if (qdio_has_inbound_q_moved(q)) {
1478 qdio_kick_inbound_handler(q);
1479 if (!qdio_stop_polling(q)) {
1480 q_laps++;
1481 if (q_laps<QDIO_Q_LAPS)
1482 goto again;
1484 qdio_mark_q(q);
1485 } else {
1486 if (!qdio_is_inbound_q_done(q))
1487 /* means poll time is not yet over */
1488 qdio_mark_q(q);
1491 qdio_release_q(q);
1494 static void
1495 qdio_inbound_processing(struct qdio_q *q)
1497 __qdio_inbound_processing(q);
1500 /************************* MAIN ROUTINES *******************************/
1502 #ifdef QDIO_USE_PROCESSING_STATE
1503 static inline int
1504 tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1506 if (!q) {
1507 tiqdio_sched_tl();
1508 return 0;
1512 * under VM, we have not used the PROCESSING state, so no
1513 * need to stop polling
1515 if (q->siga_sync)
1516 return 2;
1518 if (unlikely(qdio_reserve_q(q))) {
1519 qdio_release_q(q);
1520 #ifdef QDIO_PERFORMANCE_STATS
1521 ii_p_c++;
1522 #endif /* QDIO_PERFORMANCE_STATS */
1524 * as we might just be about to stop polling, we make
1525 * sure that we check again at least once more
1529 * sanity -- we'd get here without setting the
1530 * dev st chg ind
1532 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1533 tiqdio_sched_tl();
1534 return 0;
1536 if (qdio_stop_polling(q)) {
1537 qdio_release_q(q);
1538 return 2;
1540 if (q_laps<QDIO_Q_LAPS-1) {
1541 qdio_release_q(q);
1542 return 3;
1545 * we set the flags to get into the stuff
1546 * next time, see also comment in qdio_stop_polling
1548 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1549 tiqdio_sched_tl();
1550 qdio_release_q(q);
1551 return 1;
1554 #endif /* QDIO_USE_PROCESSING_STATE */
1556 static inline void
1557 tiqdio_inbound_checks(void)
1559 struct qdio_q *q;
1560 int spare_ind_was_set=0;
1561 #ifdef QDIO_USE_PROCESSING_STATE
1562 int q_laps=0;
1563 #endif /* QDIO_USE_PROCESSING_STATE */
1565 QDIO_DBF_TEXT4(0,trace,"iqdinbck");
1566 QDIO_DBF_TEXT5(0,trace,"iqlocsum");
1568 #ifdef QDIO_USE_PROCESSING_STATE
1569 again:
1570 #endif /* QDIO_USE_PROCESSING_STATE */
1572 /* when the spare indicator is used and set, save that and clear it */
1573 if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) {
1574 spare_ind_was_set = 1;
1575 tiqdio_clear_summary_bit((__u32*)&spare_indicator);
1578 q=(struct qdio_q*)tiq_list;
1579 do {
1580 if (!q)
1581 break;
1582 __tiqdio_inbound_processing(q, spare_ind_was_set);
1583 q=(struct qdio_q*)q->list_next;
1584 } while (q!=(struct qdio_q*)tiq_list);
1586 #ifdef QDIO_USE_PROCESSING_STATE
1587 q=(struct qdio_q*)tiq_list;
1588 do {
1589 int ret;
1591 ret = tiqdio_reset_processing_state(q, q_laps);
1592 switch (ret) {
1593 case 0:
1594 return;
1595 case 1:
1596 q_laps++;
1597 case 2:
1598 q = (struct qdio_q*)q->list_next;
1599 break;
1600 default:
1601 q_laps++;
1602 goto again;
1604 } while (q!=(struct qdio_q*)tiq_list);
1605 #endif /* QDIO_USE_PROCESSING_STATE */
1608 static void
1609 tiqdio_tl(unsigned long data)
1611 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1613 #ifdef QDIO_PERFORMANCE_STATS
1614 perf_stats.tl_runs++;
1615 #endif /* QDIO_PERFORMANCE_STATS */
1617 tiqdio_inbound_checks();
1620 /********************* GENERAL HELPER_ROUTINES ***********************/
1622 static void
1623 qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1625 int i;
1627 for (i=0;i<QDIO_MAX_QUEUES_PER_IRQ;i++) {
1628 if (!irq_ptr->input_qs[i])
1629 goto next;
1631 kfree(irq_ptr->input_qs[i]->slib);
1632 kfree(irq_ptr->input_qs[i]);
1634 next:
1635 if (!irq_ptr->output_qs[i])
1636 continue;
1638 kfree(irq_ptr->output_qs[i]->slib);
1639 kfree(irq_ptr->output_qs[i]);
1642 kfree(irq_ptr->qdr);
1643 free_page((unsigned long) irq_ptr);
1646 static void
1647 qdio_set_impl_params(struct qdio_irq *irq_ptr,
1648 unsigned int qib_param_field_format,
1649 /* pointer to 128 bytes or NULL, if no param field */
1650 unsigned char *qib_param_field,
1651 /* pointer to no_queues*128 words of data or NULL */
1652 unsigned int no_input_qs,
1653 unsigned int no_output_qs,
1654 unsigned long *input_slib_elements,
1655 unsigned long *output_slib_elements)
1657 int i,j;
1659 if (!irq_ptr)
1660 return;
1662 irq_ptr->qib.pfmt=qib_param_field_format;
1663 if (qib_param_field)
1664 memcpy(irq_ptr->qib.parm,qib_param_field,
1665 QDIO_MAX_BUFFERS_PER_Q);
1667 if (input_slib_elements)
1668 for (i=0;i<no_input_qs;i++) {
1669 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1670 irq_ptr->input_qs[i]->slib->slibe[j].parms=
1671 input_slib_elements[
1672 i*QDIO_MAX_BUFFERS_PER_Q+j];
1674 if (output_slib_elements)
1675 for (i=0;i<no_output_qs;i++) {
1676 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1677 irq_ptr->output_qs[i]->slib->slibe[j].parms=
1678 output_slib_elements[
1679 i*QDIO_MAX_BUFFERS_PER_Q+j];
1683 static int
1684 qdio_alloc_qs(struct qdio_irq *irq_ptr,
1685 int no_input_qs, int no_output_qs)
1687 int i;
1688 struct qdio_q *q;
1689 int result=-ENOMEM;
1691 for (i=0;i<no_input_qs;i++) {
1692 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1694 if (!q) {
1695 QDIO_PRINT_ERR("kmalloc of q failed!\n");
1696 goto out;
1699 q->slib = kmalloc(PAGE_SIZE, GFP_KERNEL);
1700 if (!q->slib) {
1701 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1702 goto out;
1705 irq_ptr->input_qs[i]=q;
1708 for (i=0;i<no_output_qs;i++) {
1709 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1711 if (!q) {
1712 goto out;
1715 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1716 if (!q->slib) {
1717 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1718 goto out;
1721 irq_ptr->output_qs[i]=q;
1724 result=0;
1725 out:
1726 return result;
1729 static void
1730 qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1731 int no_input_qs, int no_output_qs,
1732 qdio_handler_t *input_handler,
1733 qdio_handler_t *output_handler,
1734 unsigned long int_parm,int q_format,
1735 unsigned long flags,
1736 void **inbound_sbals_array,
1737 void **outbound_sbals_array)
1739 struct qdio_q *q;
1740 int i,j;
1741 char dbf_text[20]; /* see qdio_initialize */
1742 void *ptr;
1743 int available;
1745 sprintf(dbf_text,"qfqs%4x",cdev->private->sch_no);
1746 QDIO_DBF_TEXT0(0,setup,dbf_text);
1747 for (i=0;i<no_input_qs;i++) {
1748 q=irq_ptr->input_qs[i];
1750 memset(q,0,((char*)&q->slib)-((char*)q));
1751 sprintf(dbf_text,"in-q%4x",i);
1752 QDIO_DBF_TEXT0(0,setup,dbf_text);
1753 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1755 memset(q->slib,0,PAGE_SIZE);
1756 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1758 available=0;
1760 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1761 q->sbal[j]=*(inbound_sbals_array++);
1763 q->queue_type=q_format;
1764 q->int_parm=int_parm;
1765 q->schid = irq_ptr->schid;
1766 q->irq_ptr = irq_ptr;
1767 q->cdev = cdev;
1768 q->mask=1<<(31-i);
1769 q->q_no=i;
1770 q->is_input_q=1;
1771 q->first_to_check=0;
1772 q->last_move_ftc=0;
1773 q->handler=input_handler;
1774 q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind;
1776 q->tasklet.data=(unsigned long)q;
1777 /* q->is_thinint_q isn't valid at this time, but
1778 * irq_ptr->is_thinint_irq is */
1779 q->tasklet.func=(void(*)(unsigned long))
1780 ((irq_ptr->is_thinint_irq)?&tiqdio_inbound_processing:
1781 &qdio_inbound_processing);
1783 /* actually this is not used for inbound queues. yet. */
1784 atomic_set(&q->busy_siga_counter,0);
1785 q->timing.busy_start=0;
1787 /* for (j=0;j<QDIO_STATS_NUMBER;j++)
1788 q->timing.last_transfer_times[j]=(qdio_get_micros()/
1789 QDIO_STATS_NUMBER)*j;
1790 q->timing.last_transfer_index=QDIO_STATS_NUMBER-1;
1793 /* fill in slib */
1794 if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba=
1795 (unsigned long)(q->slib);
1796 q->slib->sla=(unsigned long)(q->sl);
1797 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1799 /* fill in sl */
1800 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1801 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1803 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1804 ptr=(void*)q->sl;
1805 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1806 ptr=(void*)&q->slsb;
1807 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1808 ptr=(void*)q->sbal[0];
1809 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1811 /* fill in slsb */
1812 if (!irq_ptr->is_qebsm) {
1813 unsigned int count = 1;
1814 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1815 set_slsb(q, &j, SLSB_P_INPUT_NOT_INIT, &count);
1819 for (i=0;i<no_output_qs;i++) {
1820 q=irq_ptr->output_qs[i];
1821 memset(q,0,((char*)&q->slib)-((char*)q));
1823 sprintf(dbf_text,"outq%4x",i);
1824 QDIO_DBF_TEXT0(0,setup,dbf_text);
1825 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1827 memset(q->slib,0,PAGE_SIZE);
1828 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1830 available=0;
1832 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1833 q->sbal[j]=*(outbound_sbals_array++);
1835 q->queue_type=q_format;
1836 q->int_parm=int_parm;
1837 q->is_input_q=0;
1838 q->schid = irq_ptr->schid;
1839 q->cdev = cdev;
1840 q->irq_ptr = irq_ptr;
1841 q->mask=1<<(31-i);
1842 q->q_no=i;
1843 q->first_to_check=0;
1844 q->last_move_ftc=0;
1845 q->handler=output_handler;
1847 q->tasklet.data=(unsigned long)q;
1848 q->tasklet.func=(void(*)(unsigned long))
1849 &qdio_outbound_processing;
1851 atomic_set(&q->busy_siga_counter,0);
1852 q->timing.busy_start=0;
1854 /* fill in slib */
1855 if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba=
1856 (unsigned long)(q->slib);
1857 q->slib->sla=(unsigned long)(q->sl);
1858 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1860 /* fill in sl */
1861 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1862 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1864 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1865 ptr=(void*)q->sl;
1866 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1867 ptr=(void*)&q->slsb;
1868 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1869 ptr=(void*)q->sbal[0];
1870 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1872 /* fill in slsb */
1873 if (!irq_ptr->is_qebsm) {
1874 unsigned int count = 1;
1875 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1876 set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count);
1881 static void
1882 qdio_fill_thresholds(struct qdio_irq *irq_ptr,
1883 unsigned int no_input_qs,
1884 unsigned int no_output_qs,
1885 unsigned int min_input_threshold,
1886 unsigned int max_input_threshold,
1887 unsigned int min_output_threshold,
1888 unsigned int max_output_threshold)
1890 int i;
1891 struct qdio_q *q;
1893 for (i=0;i<no_input_qs;i++) {
1894 q=irq_ptr->input_qs[i];
1895 q->timing.threshold=max_input_threshold;
1896 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1897 q->threshold_classes[j].threshold=
1898 min_input_threshold+
1899 (max_input_threshold-min_input_threshold)/
1900 QDIO_STATS_CLASSES;
1902 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1904 for (i=0;i<no_output_qs;i++) {
1905 q=irq_ptr->output_qs[i];
1906 q->timing.threshold=max_output_threshold;
1907 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1908 q->threshold_classes[j].threshold=
1909 min_output_threshold+
1910 (max_output_threshold-min_output_threshold)/
1911 QDIO_STATS_CLASSES;
1913 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1917 static int
1918 tiqdio_thinint_handler(void)
1920 QDIO_DBF_TEXT4(0,trace,"thin_int");
1922 #ifdef QDIO_PERFORMANCE_STATS
1923 perf_stats.thinints++;
1924 perf_stats.start_time_inbound=NOW;
1925 #endif /* QDIO_PERFORMANCE_STATS */
1927 /* SVS only when needed:
1928 * issue SVS to benefit from iqdio interrupt avoidance
1929 * (SVS clears AISOI)*/
1930 if (!omit_svs)
1931 tiqdio_clear_global_summary();
1933 tiqdio_inbound_checks();
1934 return 0;
1937 static void
1938 qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state)
1940 int i;
1941 #ifdef CONFIG_QDIO_DEBUG
1942 char dbf_text[15];
1944 QDIO_DBF_TEXT5(0,trace,"newstate");
1945 sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state);
1946 QDIO_DBF_TEXT5(0,trace,dbf_text);
1947 #endif /* CONFIG_QDIO_DEBUG */
1949 irq_ptr->state=state;
1950 for (i=0;i<irq_ptr->no_input_qs;i++)
1951 irq_ptr->input_qs[i]->state=state;
1952 for (i=0;i<irq_ptr->no_output_qs;i++)
1953 irq_ptr->output_qs[i]->state=state;
1954 mb();
1957 static inline void
1958 qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
1960 char dbf_text[15];
1962 if (irb->esw.esw0.erw.cons) {
1963 sprintf(dbf_text,"sens%4x",schid.sch_no);
1964 QDIO_DBF_TEXT2(1,trace,dbf_text);
1965 QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN);
1967 QDIO_PRINT_WARN("sense data available on qdio channel.\n");
1968 HEXDUMP16(WARN,"irb: ",irb);
1969 HEXDUMP16(WARN,"sense data: ",irb->ecw);
1974 static inline void
1975 qdio_handle_pci(struct qdio_irq *irq_ptr)
1977 int i;
1978 struct qdio_q *q;
1980 #ifdef QDIO_PERFORMANCE_STATS
1981 perf_stats.pcis++;
1982 perf_stats.start_time_inbound=NOW;
1983 #endif /* QDIO_PERFORMANCE_STATS */
1984 for (i=0;i<irq_ptr->no_input_qs;i++) {
1985 q=irq_ptr->input_qs[i];
1986 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1987 qdio_mark_q(q);
1988 else {
1989 #ifdef QDIO_PERFORMANCE_STATS
1990 perf_stats.tl_runs--;
1991 #endif /* QDIO_PERFORMANCE_STATS */
1992 __qdio_inbound_processing(q);
1995 if (!irq_ptr->hydra_gives_outbound_pcis)
1996 return;
1997 for (i=0;i<irq_ptr->no_output_qs;i++) {
1998 q=irq_ptr->output_qs[i];
1999 #ifdef QDIO_PERFORMANCE_STATS
2000 perf_stats.tl_runs--;
2001 #endif /* QDIO_PERFORMANCE_STATS */
2002 if (qdio_is_outbound_q_done(q))
2003 continue;
2004 if (!irq_ptr->sync_done_on_outb_pcis)
2005 SYNC_MEMORY;
2006 __qdio_outbound_processing(q);
2010 static void qdio_establish_handle_irq(struct ccw_device*, int, int);
2012 static inline void
2013 qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm,
2014 int cstat, int dstat)
2016 struct qdio_irq *irq_ptr;
2017 struct qdio_q *q;
2018 char dbf_text[15];
2020 irq_ptr = cdev->private->qdio_data;
2022 QDIO_DBF_TEXT2(1, trace, "ick2");
2023 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2024 QDIO_DBF_TEXT2(1,trace,dbf_text);
2025 QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int));
2026 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2027 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2028 QDIO_PRINT_ERR("received check condition on activate " \
2029 "queues on device %s (cs=x%x, ds=x%x).\n",
2030 cdev->dev.bus_id, cstat, dstat);
2031 if (irq_ptr->no_input_qs) {
2032 q=irq_ptr->input_qs[0];
2033 } else if (irq_ptr->no_output_qs) {
2034 q=irq_ptr->output_qs[0];
2035 } else {
2036 QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n",
2037 cdev->dev.bus_id);
2038 goto omit_handler_call;
2040 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
2041 QDIO_STATUS_LOOK_FOR_ERROR,
2042 0,0,0,-1,-1,q->int_parm);
2043 omit_handler_call:
2044 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED);
2048 static void
2049 qdio_call_shutdown(void *data)
2051 struct ccw_device *cdev;
2053 cdev = (struct ccw_device *)data;
2054 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2055 put_device(&cdev->dev);
2058 static void
2059 qdio_timeout_handler(struct ccw_device *cdev)
2061 struct qdio_irq *irq_ptr;
2062 char dbf_text[15];
2064 QDIO_DBF_TEXT2(0, trace, "qtoh");
2065 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2066 QDIO_DBF_TEXT2(0, trace, dbf_text);
2068 irq_ptr = cdev->private->qdio_data;
2069 sprintf(dbf_text, "state:%d", irq_ptr->state);
2070 QDIO_DBF_TEXT2(0, trace, dbf_text);
2072 switch (irq_ptr->state) {
2073 case QDIO_IRQ_STATE_INACTIVE:
2074 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n",
2075 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2076 QDIO_DBF_TEXT2(1,setup,"eq:timeo");
2077 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2078 break;
2079 case QDIO_IRQ_STATE_CLEANUP:
2080 QDIO_PRINT_INFO("Did not get interrupt on cleanup, "
2081 "irq=0.%x.%x.\n",
2082 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2083 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2084 break;
2085 case QDIO_IRQ_STATE_ESTABLISHED:
2086 case QDIO_IRQ_STATE_ACTIVE:
2087 /* I/O has been terminated by common I/O layer. */
2088 QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n",
2089 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2090 QDIO_DBF_TEXT2(1, trace, "cio:term");
2091 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
2092 if (get_device(&cdev->dev)) {
2093 /* Can't call shutdown from interrupt context. */
2094 PREPARE_WORK(&cdev->private->kick_work,
2095 qdio_call_shutdown, (void *)cdev);
2096 queue_work(ccw_device_work, &cdev->private->kick_work);
2098 break;
2099 default:
2100 BUG();
2102 ccw_device_set_timeout(cdev, 0);
2103 wake_up(&cdev->private->wait_q);
2106 static void
2107 qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
2109 struct qdio_irq *irq_ptr;
2110 int cstat,dstat;
2111 char dbf_text[15];
2113 #ifdef CONFIG_QDIO_DEBUG
2114 QDIO_DBF_TEXT4(0, trace, "qint");
2115 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2116 QDIO_DBF_TEXT4(0, trace, dbf_text);
2117 #endif /* CONFIG_QDIO_DEBUG */
2119 if (!intparm) {
2120 QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \
2121 "handler, device %s\n", cdev->dev.bus_id);
2122 return;
2125 irq_ptr = cdev->private->qdio_data;
2126 if (!irq_ptr) {
2127 QDIO_DBF_TEXT2(1, trace, "uint");
2128 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2129 QDIO_DBF_TEXT2(1,trace,dbf_text);
2130 QDIO_PRINT_ERR("received interrupt on unused device %s!\n",
2131 cdev->dev.bus_id);
2132 return;
2135 if (IS_ERR(irb)) {
2136 /* Currently running i/o is in error. */
2137 switch (PTR_ERR(irb)) {
2138 case -EIO:
2139 QDIO_PRINT_ERR("i/o error on device %s\n",
2140 cdev->dev.bus_id);
2141 return;
2142 case -ETIMEDOUT:
2143 qdio_timeout_handler(cdev);
2144 return;
2145 default:
2146 QDIO_PRINT_ERR("unknown error state %ld on device %s\n",
2147 PTR_ERR(irb), cdev->dev.bus_id);
2148 return;
2152 qdio_irq_check_sense(irq_ptr->schid, irb);
2154 #ifdef CONFIG_QDIO_DEBUG
2155 sprintf(dbf_text, "state:%d", irq_ptr->state);
2156 QDIO_DBF_TEXT4(0, trace, dbf_text);
2157 #endif /* CONFIG_QDIO_DEBUG */
2159 cstat = irb->scsw.cstat;
2160 dstat = irb->scsw.dstat;
2162 switch (irq_ptr->state) {
2163 case QDIO_IRQ_STATE_INACTIVE:
2164 qdio_establish_handle_irq(cdev, cstat, dstat);
2165 break;
2167 case QDIO_IRQ_STATE_CLEANUP:
2168 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2169 break;
2171 case QDIO_IRQ_STATE_ESTABLISHED:
2172 case QDIO_IRQ_STATE_ACTIVE:
2173 if (cstat & SCHN_STAT_PCI) {
2174 qdio_handle_pci(irq_ptr);
2175 break;
2178 if ((cstat&~SCHN_STAT_PCI)||dstat) {
2179 qdio_handle_activate_check(cdev, intparm, cstat, dstat);
2180 break;
2182 default:
2183 QDIO_PRINT_ERR("got interrupt for queues in state %d on " \
2184 "device %s?!\n",
2185 irq_ptr->state, cdev->dev.bus_id);
2187 wake_up(&cdev->private->wait_q);
2192 qdio_synchronize(struct ccw_device *cdev, unsigned int flags,
2193 unsigned int queue_number)
2195 int cc = 0;
2196 struct qdio_q *q;
2197 struct qdio_irq *irq_ptr;
2198 void *ptr;
2199 #ifdef CONFIG_QDIO_DEBUG
2200 char dbf_text[15]="SyncXXXX";
2201 #endif
2203 irq_ptr = cdev->private->qdio_data;
2204 if (!irq_ptr)
2205 return -ENODEV;
2207 #ifdef CONFIG_QDIO_DEBUG
2208 *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no;
2209 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2210 *((int*)(&dbf_text[0]))=flags;
2211 *((int*)(&dbf_text[4]))=queue_number;
2212 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2213 #endif /* CONFIG_QDIO_DEBUG */
2215 if (flags&QDIO_FLAG_SYNC_INPUT) {
2216 q=irq_ptr->input_qs[queue_number];
2217 if (!q)
2218 return -EINVAL;
2219 if (!(irq_ptr->is_qebsm))
2220 cc = do_siga_sync(q->schid, 0, q->mask);
2221 } else if (flags&QDIO_FLAG_SYNC_OUTPUT) {
2222 q=irq_ptr->output_qs[queue_number];
2223 if (!q)
2224 return -EINVAL;
2225 if (!(irq_ptr->is_qebsm))
2226 cc = do_siga_sync(q->schid, q->mask, 0);
2227 } else
2228 return -EINVAL;
2230 ptr=&cc;
2231 if (cc)
2232 QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int));
2234 return cc;
2237 static inline void
2238 qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned char qdioac,
2239 unsigned long token)
2241 struct qdio_q *q;
2242 int i;
2243 unsigned int count, start_buf;
2244 char dbf_text[15];
2246 /*check if QEBSM is disabled */
2247 if (!(irq_ptr->is_qebsm) || !(qdioac & 0x01)) {
2248 irq_ptr->is_qebsm = 0;
2249 irq_ptr->sch_token = 0;
2250 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2251 QDIO_DBF_TEXT0(0,setup,"noV=V");
2252 return;
2254 irq_ptr->sch_token = token;
2255 /*input queue*/
2256 for (i = 0; i < irq_ptr->no_input_qs;i++) {
2257 q = irq_ptr->input_qs[i];
2258 count = QDIO_MAX_BUFFERS_PER_Q;
2259 start_buf = 0;
2260 set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count);
2262 sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm);
2263 QDIO_DBF_TEXT0(0,setup,dbf_text);
2264 sprintf(dbf_text,"%8lx",irq_ptr->sch_token);
2265 QDIO_DBF_TEXT0(0,setup,dbf_text);
2266 /*output queue*/
2267 for (i = 0; i < irq_ptr->no_output_qs; i++) {
2268 q = irq_ptr->output_qs[i];
2269 count = QDIO_MAX_BUFFERS_PER_Q;
2270 start_buf = 0;
2271 set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count);
2275 static void
2276 qdio_get_ssqd_information(struct qdio_irq *irq_ptr)
2278 int result;
2279 unsigned char qdioac;
2280 struct {
2281 struct chsc_header request;
2282 u16 reserved1:10;
2283 u16 ssid:2;
2284 u16 fmt:4;
2285 u16 first_sch;
2286 u16 reserved2;
2287 u16 last_sch;
2288 u32 reserved3;
2289 struct chsc_header response;
2290 u32 reserved4;
2291 u8 flags;
2292 u8 reserved5;
2293 u16 sch;
2294 u8 qfmt;
2295 u8 parm;
2296 u8 qdioac1;
2297 u8 sch_class;
2298 u8 reserved7;
2299 u8 icnt;
2300 u8 reserved8;
2301 u8 ocnt;
2302 u8 reserved9;
2303 u8 mbccnt;
2304 u16 qdioac2;
2305 u64 sch_token;
2306 } *ssqd_area;
2308 QDIO_DBF_TEXT0(0,setup,"getssqd");
2309 qdioac = 0;
2310 ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2311 if (!ssqd_area) {
2312 QDIO_PRINT_WARN("Could not get memory for chsc. Using all " \
2313 "SIGAs for sch x%x.\n", irq_ptr->schid.sch_no);
2314 irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2315 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2316 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2317 irq_ptr->is_qebsm = 0;
2318 irq_ptr->sch_token = 0;
2319 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2320 return;
2323 ssqd_area->request = (struct chsc_header) {
2324 .length = 0x0010,
2325 .code = 0x0024,
2327 ssqd_area->first_sch = irq_ptr->schid.sch_no;
2328 ssqd_area->last_sch = irq_ptr->schid.sch_no;
2329 ssqd_area->ssid = irq_ptr->schid.ssid;
2330 result = chsc(ssqd_area);
2332 if (result) {
2333 QDIO_PRINT_WARN("CHSC returned cc %i. Using all " \
2334 "SIGAs for sch 0.%x.%x.\n", result,
2335 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2336 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2337 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2338 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2339 irq_ptr->is_qebsm = 0;
2340 goto out;
2343 if (ssqd_area->response.code != QDIO_CHSC_RESPONSE_CODE_OK) {
2344 QDIO_PRINT_WARN("response upon checking SIGA needs " \
2345 "is 0x%x. Using all SIGAs for sch 0.%x.%x.\n",
2346 ssqd_area->response.code,
2347 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2348 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2349 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2350 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2351 irq_ptr->is_qebsm = 0;
2352 goto out;
2354 if (!(ssqd_area->flags & CHSC_FLAG_QDIO_CAPABILITY) ||
2355 !(ssqd_area->flags & CHSC_FLAG_VALIDITY) ||
2356 (ssqd_area->sch != irq_ptr->schid.sch_no)) {
2357 QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \
2358 "using all SIGAs.\n",
2359 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2360 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2361 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2362 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* worst case */
2363 irq_ptr->is_qebsm = 0;
2364 goto out;
2366 qdioac = ssqd_area->qdioac1;
2367 out:
2368 qdio_check_subchannel_qebsm(irq_ptr, qdioac,
2369 ssqd_area->sch_token);
2370 mempool_free(ssqd_area, qdio_mempool_scssc);
2371 irq_ptr->qdioac = qdioac;
2374 static unsigned int
2375 tiqdio_check_chsc_availability(void)
2377 char dbf_text[15];
2379 if (!css_characteristics_avail)
2380 return -EIO;
2382 /* Check for bit 41. */
2383 if (!css_general_characteristics.aif) {
2384 QDIO_PRINT_WARN("Adapter interruption facility not " \
2385 "installed.\n");
2386 return -ENOENT;
2389 /* Check for bits 107 and 108. */
2390 if (!css_chsc_characteristics.scssc ||
2391 !css_chsc_characteristics.scsscf) {
2392 QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \
2393 "not available.\n");
2394 return -ENOENT;
2397 /* Check for OSA/FCP thin interrupts (bit 67). */
2398 hydra_thinints = css_general_characteristics.aif_osa;
2399 sprintf(dbf_text,"hydrati%1x", hydra_thinints);
2400 QDIO_DBF_TEXT0(0,setup,dbf_text);
2402 #ifdef CONFIG_64BIT
2403 /* Check for QEBSM support in general (bit 58). */
2404 is_passthrough = css_general_characteristics.qebsm;
2405 #endif
2406 sprintf(dbf_text,"cssQBS:%1x", is_passthrough);
2407 QDIO_DBF_TEXT0(0,setup,dbf_text);
2409 /* Check for aif time delay disablement fac (bit 56). If installed,
2410 * omit svs even under lpar (good point by rick again) */
2411 omit_svs = css_general_characteristics.aif_tdd;
2412 sprintf(dbf_text,"omitsvs%1x", omit_svs);
2413 QDIO_DBF_TEXT0(0,setup,dbf_text);
2414 return 0;
2418 static unsigned int
2419 tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero)
2421 unsigned long real_addr_local_summary_bit;
2422 unsigned long real_addr_dev_st_chg_ind;
2423 void *ptr;
2424 char dbf_text[15];
2426 unsigned int resp_code;
2427 int result;
2429 struct {
2430 struct chsc_header request;
2431 u16 operation_code;
2432 u16 reserved1;
2433 u32 reserved2;
2434 u32 reserved3;
2435 u64 summary_indicator_addr;
2436 u64 subchannel_indicator_addr;
2437 u32 ks:4;
2438 u32 kc:4;
2439 u32 reserved4:21;
2440 u32 isc:3;
2441 u32 word_with_d_bit;
2442 /* set to 0x10000000 to enable
2443 * time delay disablement facility */
2444 u32 reserved5;
2445 struct subchannel_id schid;
2446 u32 reserved6[1004];
2447 struct chsc_header response;
2448 u32 reserved7;
2449 } *scssc_area;
2451 if (!irq_ptr->is_thinint_irq)
2452 return -ENODEV;
2454 if (reset_to_zero) {
2455 real_addr_local_summary_bit=0;
2456 real_addr_dev_st_chg_ind=0;
2457 } else {
2458 real_addr_local_summary_bit=
2459 virt_to_phys((volatile void *)indicators);
2460 real_addr_dev_st_chg_ind=
2461 virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind);
2464 scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2465 if (!scssc_area) {
2466 QDIO_PRINT_WARN("No memory for setting indicators on " \
2467 "subchannel 0.%x.%x.\n",
2468 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2469 return -ENOMEM;
2471 scssc_area->request = (struct chsc_header) {
2472 .length = 0x0fe0,
2473 .code = 0x0021,
2475 scssc_area->operation_code = 0;
2477 scssc_area->summary_indicator_addr = real_addr_local_summary_bit;
2478 scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind;
2479 scssc_area->ks = QDIO_STORAGE_KEY;
2480 scssc_area->kc = QDIO_STORAGE_KEY;
2481 scssc_area->isc = TIQDIO_THININT_ISC;
2482 scssc_area->schid = irq_ptr->schid;
2483 /* enables the time delay disablement facility. Don't care
2484 * whether it is really there (i.e. we haven't checked for
2485 * it) */
2486 if (css_general_characteristics.aif_tdd)
2487 scssc_area->word_with_d_bit = 0x10000000;
2488 else
2489 QDIO_PRINT_WARN("Time delay disablement facility " \
2490 "not available\n");
2492 result = chsc(scssc_area);
2493 if (result) {
2494 QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \
2495 "cc=%i.\n",
2496 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result);
2497 result = -EIO;
2498 goto out;
2501 resp_code = scssc_area->response.code;
2502 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2503 QDIO_PRINT_WARN("response upon setting indicators " \
2504 "is 0x%x.\n",resp_code);
2505 sprintf(dbf_text,"sidR%4x",resp_code);
2506 QDIO_DBF_TEXT1(0,trace,dbf_text);
2507 QDIO_DBF_TEXT1(0,setup,dbf_text);
2508 ptr=&scssc_area->response;
2509 QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN);
2510 result = -EIO;
2511 goto out;
2514 QDIO_DBF_TEXT2(0,setup,"setscind");
2515 QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit,
2516 sizeof(unsigned long));
2517 QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long));
2518 result = 0;
2519 out:
2520 mempool_free(scssc_area, qdio_mempool_scssc);
2521 return result;
2525 static unsigned int
2526 tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target)
2528 unsigned int resp_code;
2529 int result;
2530 void *ptr;
2531 char dbf_text[15];
2533 struct {
2534 struct chsc_header request;
2535 u16 operation_code;
2536 u16 reserved1;
2537 u32 reserved2;
2538 u32 reserved3;
2539 u32 reserved4[2];
2540 u32 delay_target;
2541 u32 reserved5[1009];
2542 struct chsc_header response;
2543 u32 reserved6;
2544 } *scsscf_area;
2546 if (!irq_ptr->is_thinint_irq)
2547 return -ENODEV;
2549 scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2550 if (!scsscf_area) {
2551 QDIO_PRINT_WARN("No memory for setting delay target on " \
2552 "subchannel 0.%x.%x.\n",
2553 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2554 return -ENOMEM;
2556 scsscf_area->request = (struct chsc_header) {
2557 .length = 0x0fe0,
2558 .code = 0x1027,
2561 scsscf_area->delay_target = delay_target<<16;
2563 result=chsc(scsscf_area);
2564 if (result) {
2565 QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \
2566 "cc=%i. Continuing.\n",
2567 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2568 result);
2569 result = -EIO;
2570 goto out;
2573 resp_code = scsscf_area->response.code;
2574 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2575 QDIO_PRINT_WARN("response upon setting delay target " \
2576 "is 0x%x. Continuing.\n",resp_code);
2577 sprintf(dbf_text,"sdtR%4x",resp_code);
2578 QDIO_DBF_TEXT1(0,trace,dbf_text);
2579 QDIO_DBF_TEXT1(0,setup,dbf_text);
2580 ptr=&scsscf_area->response;
2581 QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN);
2583 QDIO_DBF_TEXT2(0,trace,"delytrgt");
2584 QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long));
2585 result = 0; /* not critical */
2586 out:
2587 mempool_free(scsscf_area, qdio_mempool_scssc);
2588 return result;
2592 qdio_cleanup(struct ccw_device *cdev, int how)
2594 struct qdio_irq *irq_ptr;
2595 char dbf_text[15];
2596 int rc;
2598 irq_ptr = cdev->private->qdio_data;
2599 if (!irq_ptr)
2600 return -ENODEV;
2602 sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no);
2603 QDIO_DBF_TEXT1(0,trace,dbf_text);
2604 QDIO_DBF_TEXT0(0,setup,dbf_text);
2606 rc = qdio_shutdown(cdev, how);
2607 if ((rc == 0) || (rc == -EINPROGRESS))
2608 rc = qdio_free(cdev);
2609 return rc;
2613 qdio_shutdown(struct ccw_device *cdev, int how)
2615 struct qdio_irq *irq_ptr;
2616 int i;
2617 int result = 0;
2618 int rc;
2619 unsigned long flags;
2620 int timeout;
2621 char dbf_text[15];
2623 irq_ptr = cdev->private->qdio_data;
2624 if (!irq_ptr)
2625 return -ENODEV;
2627 down(&irq_ptr->setting_up_sema);
2629 sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no);
2630 QDIO_DBF_TEXT1(0,trace,dbf_text);
2631 QDIO_DBF_TEXT0(0,setup,dbf_text);
2633 /* mark all qs as uninteresting */
2634 for (i=0;i<irq_ptr->no_input_qs;i++)
2635 atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1);
2637 for (i=0;i<irq_ptr->no_output_qs;i++)
2638 atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1);
2640 tasklet_kill(&tiqdio_tasklet);
2642 for (i=0;i<irq_ptr->no_input_qs;i++) {
2643 qdio_unmark_q(irq_ptr->input_qs[i]);
2644 tasklet_kill(&irq_ptr->input_qs[i]->tasklet);
2645 wait_event_interruptible_timeout(cdev->private->wait_q,
2646 !atomic_read(&irq_ptr->
2647 input_qs[i]->
2648 use_count),
2649 QDIO_NO_USE_COUNT_TIMEOUT);
2650 if (atomic_read(&irq_ptr->input_qs[i]->use_count))
2651 result=-EINPROGRESS;
2654 for (i=0;i<irq_ptr->no_output_qs;i++) {
2655 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2656 wait_event_interruptible_timeout(cdev->private->wait_q,
2657 !atomic_read(&irq_ptr->
2658 output_qs[i]->
2659 use_count),
2660 QDIO_NO_USE_COUNT_TIMEOUT);
2661 if (atomic_read(&irq_ptr->output_qs[i]->use_count))
2662 result=-EINPROGRESS;
2665 /* cleanup subchannel */
2666 spin_lock_irqsave(get_ccwdev_lock(cdev),flags);
2667 if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) {
2668 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
2669 timeout=QDIO_CLEANUP_CLEAR_TIMEOUT;
2670 } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) {
2671 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2672 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2673 } else { /* default behaviour */
2674 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2675 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2677 if (rc == -ENODEV) {
2678 /* No need to wait for device no longer present. */
2679 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2680 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2681 } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) {
2683 * Whoever put another handler there, has to cope with the
2684 * interrupt theirself. Might happen if qdio_shutdown was
2685 * called on already shutdown queues, but this shouldn't have
2686 * bad side effects.
2688 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2689 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2690 } else if (rc == 0) {
2691 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
2692 ccw_device_set_timeout(cdev, timeout);
2693 spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
2695 wait_event(cdev->private->wait_q,
2696 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
2697 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2698 } else {
2699 QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
2700 "device %s\n", result, cdev->dev.bus_id);
2701 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2702 result = rc;
2703 goto out;
2705 if (irq_ptr->is_thinint_irq) {
2706 qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind);
2707 tiqdio_set_subchannel_ind(irq_ptr,1);
2708 /* reset adapter interrupt indicators */
2711 /* exchange int handlers, if necessary */
2712 if ((void*)cdev->handler == (void*)qdio_handler)
2713 cdev->handler=irq_ptr->original_int_handler;
2715 /* Ignore errors. */
2716 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2717 ccw_device_set_timeout(cdev, 0);
2718 out:
2719 up(&irq_ptr->setting_up_sema);
2720 return result;
2724 qdio_free(struct ccw_device *cdev)
2726 struct qdio_irq *irq_ptr;
2727 char dbf_text[15];
2729 irq_ptr = cdev->private->qdio_data;
2730 if (!irq_ptr)
2731 return -ENODEV;
2733 down(&irq_ptr->setting_up_sema);
2735 sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no);
2736 QDIO_DBF_TEXT1(0,trace,dbf_text);
2737 QDIO_DBF_TEXT0(0,setup,dbf_text);
2739 cdev->private->qdio_data = 0;
2741 up(&irq_ptr->setting_up_sema);
2743 qdio_release_irq_memory(irq_ptr);
2744 module_put(THIS_MODULE);
2745 return 0;
2748 static inline void
2749 qdio_allocate_do_dbf(struct qdio_initialize *init_data)
2751 char dbf_text[20]; /* if a printf printed out more than 8 chars */
2753 sprintf(dbf_text,"qfmt:%x",init_data->q_format);
2754 QDIO_DBF_TEXT0(0,setup,dbf_text);
2755 QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8);
2756 sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format);
2757 QDIO_DBF_TEXT0(0,setup,dbf_text);
2758 QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*));
2759 QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*));
2760 QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*));
2761 sprintf(dbf_text,"miit%4x",init_data->min_input_threshold);
2762 QDIO_DBF_TEXT0(0,setup,dbf_text);
2763 sprintf(dbf_text,"mait%4x",init_data->max_input_threshold);
2764 QDIO_DBF_TEXT0(0,setup,dbf_text);
2765 sprintf(dbf_text,"miot%4x",init_data->min_output_threshold);
2766 QDIO_DBF_TEXT0(0,setup,dbf_text);
2767 sprintf(dbf_text,"maot%4x",init_data->max_output_threshold);
2768 QDIO_DBF_TEXT0(0,setup,dbf_text);
2769 sprintf(dbf_text,"niq:%4x",init_data->no_input_qs);
2770 QDIO_DBF_TEXT0(0,setup,dbf_text);
2771 sprintf(dbf_text,"noq:%4x",init_data->no_output_qs);
2772 QDIO_DBF_TEXT0(0,setup,dbf_text);
2773 QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*));
2774 QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*));
2775 QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long));
2776 QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long));
2777 QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*));
2778 QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*));
2781 static inline void
2782 qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt)
2784 irq_ptr->input_qs[i]->is_iqdio_q = iqfmt;
2785 irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2787 irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib);
2789 irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl);
2791 irq_ptr->qdr->qdf0[i].slsba=
2792 (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]);
2794 irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY;
2795 irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY;
2796 irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY;
2797 irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY;
2800 static inline void
2801 qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i,
2802 int j, int iqfmt)
2804 irq_ptr->output_qs[i]->is_iqdio_q = iqfmt;
2805 irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2807 irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib);
2809 irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl);
2811 irq_ptr->qdr->qdf0[i+j].slsba=
2812 (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]);
2814 irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY;
2815 irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY;
2816 irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY;
2817 irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY;
2821 static inline void
2822 qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr)
2824 int i;
2826 for (i=0;i<irq_ptr->no_input_qs;i++) {
2827 irq_ptr->input_qs[i]->siga_sync=
2828 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2829 irq_ptr->input_qs[i]->siga_in=
2830 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2831 irq_ptr->input_qs[i]->siga_out=
2832 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2833 irq_ptr->input_qs[i]->siga_sync_done_on_thinints=
2834 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2835 irq_ptr->input_qs[i]->hydra_gives_outbound_pcis=
2836 irq_ptr->hydra_gives_outbound_pcis;
2837 irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis=
2838 ((irq_ptr->qdioac&
2839 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2840 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2841 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2842 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2847 static inline void
2848 qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr)
2850 int i;
2852 for (i=0;i<irq_ptr->no_output_qs;i++) {
2853 irq_ptr->output_qs[i]->siga_sync=
2854 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2855 irq_ptr->output_qs[i]->siga_in=
2856 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2857 irq_ptr->output_qs[i]->siga_out=
2858 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2859 irq_ptr->output_qs[i]->siga_sync_done_on_thinints=
2860 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2861 irq_ptr->output_qs[i]->hydra_gives_outbound_pcis=
2862 irq_ptr->hydra_gives_outbound_pcis;
2863 irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis=
2864 ((irq_ptr->qdioac&
2865 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2866 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2867 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2868 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2873 static inline int
2874 qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat,
2875 int dstat)
2877 char dbf_text[15];
2878 struct qdio_irq *irq_ptr;
2880 irq_ptr = cdev->private->qdio_data;
2882 if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
2883 sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no);
2884 QDIO_DBF_TEXT2(1,trace,dbf_text);
2885 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2886 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2887 QDIO_PRINT_ERR("received check condition on establish " \
2888 "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n",
2889 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2890 cstat,dstat);
2891 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR);
2894 if (!(dstat & DEV_STAT_DEV_END)) {
2895 QDIO_DBF_TEXT2(1,setup,"eq:no de");
2896 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2897 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2898 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get "
2899 "device end: dstat=%02x, cstat=%02x\n",
2900 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2901 dstat, cstat);
2902 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2903 return 1;
2906 if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) {
2907 QDIO_DBF_TEXT2(1,setup,"eq:badio");
2908 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2909 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2910 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got "
2911 "the following devstat: dstat=%02x, "
2912 "cstat=%02x\n", irq_ptr->schid.ssid,
2913 irq_ptr->schid.sch_no, dstat, cstat);
2914 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2915 return 1;
2917 return 0;
2920 static void
2921 qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
2923 struct qdio_irq *irq_ptr;
2924 char dbf_text[15];
2926 irq_ptr = cdev->private->qdio_data;
2928 sprintf(dbf_text,"qehi%4x",cdev->private->sch_no);
2929 QDIO_DBF_TEXT0(0,setup,dbf_text);
2930 QDIO_DBF_TEXT0(0,trace,dbf_text);
2932 if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
2933 ccw_device_set_timeout(cdev, 0);
2934 return;
2937 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
2938 ccw_device_set_timeout(cdev, 0);
2942 qdio_initialize(struct qdio_initialize *init_data)
2944 int rc;
2945 char dbf_text[15];
2947 sprintf(dbf_text,"qini%4x",init_data->cdev->private->sch_no);
2948 QDIO_DBF_TEXT0(0,setup,dbf_text);
2949 QDIO_DBF_TEXT0(0,trace,dbf_text);
2951 rc = qdio_allocate(init_data);
2952 if (rc == 0) {
2953 rc = qdio_establish(init_data);
2954 if (rc != 0)
2955 qdio_free(init_data->cdev);
2958 return rc;
2963 qdio_allocate(struct qdio_initialize *init_data)
2965 struct qdio_irq *irq_ptr;
2966 char dbf_text[15];
2968 sprintf(dbf_text,"qalc%4x",init_data->cdev->private->sch_no);
2969 QDIO_DBF_TEXT0(0,setup,dbf_text);
2970 QDIO_DBF_TEXT0(0,trace,dbf_text);
2971 if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2972 (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2973 ((init_data->no_input_qs) && (!init_data->input_handler)) ||
2974 ((init_data->no_output_qs) && (!init_data->output_handler)) )
2975 return -EINVAL;
2977 if (!init_data->input_sbal_addr_array)
2978 return -EINVAL;
2980 if (!init_data->output_sbal_addr_array)
2981 return -EINVAL;
2983 qdio_allocate_do_dbf(init_data);
2985 /* create irq */
2986 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
2988 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2989 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
2991 if (!irq_ptr) {
2992 QDIO_PRINT_ERR("kmalloc of irq_ptr failed!\n");
2993 return -ENOMEM;
2996 init_MUTEX(&irq_ptr->setting_up_sema);
2998 /* QDR must be in DMA area since CCW data address is only 32 bit */
2999 irq_ptr->qdr=kmalloc(sizeof(struct qdr), GFP_KERNEL | GFP_DMA);
3000 if (!(irq_ptr->qdr)) {
3001 free_page((unsigned long) irq_ptr);
3002 QDIO_PRINT_ERR("kmalloc of irq_ptr->qdr failed!\n");
3003 return -ENOMEM;
3005 QDIO_DBF_TEXT0(0,setup,"qdr:");
3006 QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*));
3008 if (qdio_alloc_qs(irq_ptr,
3009 init_data->no_input_qs,
3010 init_data->no_output_qs)) {
3011 qdio_release_irq_memory(irq_ptr);
3012 return -ENOMEM;
3015 init_data->cdev->private->qdio_data = irq_ptr;
3017 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE);
3019 return 0;
3022 int qdio_fill_irq(struct qdio_initialize *init_data)
3024 int i;
3025 char dbf_text[15];
3026 struct ciw *ciw;
3027 int is_iqdio;
3028 struct qdio_irq *irq_ptr;
3030 irq_ptr = init_data->cdev->private->qdio_data;
3032 memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr));
3034 /* wipes qib.ac, required by ar7063 */
3035 memset(irq_ptr->qdr,0,sizeof(struct qdr));
3037 irq_ptr->int_parm=init_data->int_parm;
3039 irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev);
3040 irq_ptr->no_input_qs=init_data->no_input_qs;
3041 irq_ptr->no_output_qs=init_data->no_output_qs;
3043 if (init_data->q_format==QDIO_IQDIO_QFMT) {
3044 irq_ptr->is_iqdio_irq=1;
3045 irq_ptr->is_thinint_irq=1;
3046 } else {
3047 irq_ptr->is_iqdio_irq=0;
3048 irq_ptr->is_thinint_irq=hydra_thinints;
3050 sprintf(dbf_text,"is_i_t%1x%1x",
3051 irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq);
3052 QDIO_DBF_TEXT2(0,setup,dbf_text);
3054 if (irq_ptr->is_thinint_irq) {
3055 irq_ptr->dev_st_chg_ind = qdio_get_indicator();
3056 QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*));
3057 if (!irq_ptr->dev_st_chg_ind) {
3058 QDIO_PRINT_WARN("no indicator location available " \
3059 "for irq 0.%x.%x\n",
3060 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
3061 qdio_release_irq_memory(irq_ptr);
3062 return -ENOBUFS;
3066 /* defaults */
3067 irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD;
3068 irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT;
3069 irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD;
3070 irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT;
3072 qdio_fill_qs(irq_ptr, init_data->cdev,
3073 init_data->no_input_qs,
3074 init_data->no_output_qs,
3075 init_data->input_handler,
3076 init_data->output_handler,init_data->int_parm,
3077 init_data->q_format,init_data->flags,
3078 init_data->input_sbal_addr_array,
3079 init_data->output_sbal_addr_array);
3081 if (!try_module_get(THIS_MODULE)) {
3082 QDIO_PRINT_CRIT("try_module_get() failed!\n");
3083 qdio_release_irq_memory(irq_ptr);
3084 return -EINVAL;
3087 qdio_fill_thresholds(irq_ptr,init_data->no_input_qs,
3088 init_data->no_output_qs,
3089 init_data->min_input_threshold,
3090 init_data->max_input_threshold,
3091 init_data->min_output_threshold,
3092 init_data->max_output_threshold);
3094 /* fill in qdr */
3095 irq_ptr->qdr->qfmt=init_data->q_format;
3096 irq_ptr->qdr->iqdcnt=init_data->no_input_qs;
3097 irq_ptr->qdr->oqdcnt=init_data->no_output_qs;
3098 irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */
3099 irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4;
3101 irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib;
3102 irq_ptr->qdr->qkey=QDIO_STORAGE_KEY;
3104 /* fill in qib */
3105 irq_ptr->is_qebsm = is_passthrough;
3106 if (irq_ptr->is_qebsm)
3107 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
3109 irq_ptr->qib.qfmt=init_data->q_format;
3110 if (init_data->no_input_qs)
3111 irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib);
3112 if (init_data->no_output_qs)
3113 irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib);
3114 memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8);
3116 qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format,
3117 init_data->qib_param_field,
3118 init_data->no_input_qs,
3119 init_data->no_output_qs,
3120 init_data->input_slib_elements,
3121 init_data->output_slib_elements);
3123 /* first input descriptors, then output descriptors */
3124 is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0;
3125 for (i=0;i<init_data->no_input_qs;i++)
3126 qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio);
3128 for (i=0;i<init_data->no_output_qs;i++)
3129 qdio_allocate_fill_output_desc(irq_ptr, i,
3130 init_data->no_input_qs,
3131 is_iqdio);
3133 /* qdr, qib, sls, slsbs, slibs, sbales filled. */
3135 /* get qdio commands */
3136 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
3137 if (!ciw) {
3138 QDIO_DBF_TEXT2(1,setup,"no eq");
3139 QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. "
3140 "Trying to use default.\n");
3141 } else
3142 irq_ptr->equeue = *ciw;
3143 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
3144 if (!ciw) {
3145 QDIO_DBF_TEXT2(1,setup,"no aq");
3146 QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. "
3147 "Trying to use default.\n");
3148 } else
3149 irq_ptr->aqueue = *ciw;
3151 /* Set new interrupt handler. */
3152 irq_ptr->original_int_handler = init_data->cdev->handler;
3153 init_data->cdev->handler = qdio_handler;
3155 return 0;
3159 qdio_establish(struct qdio_initialize *init_data)
3161 struct qdio_irq *irq_ptr;
3162 unsigned long saveflags;
3163 int result, result2;
3164 struct ccw_device *cdev;
3165 char dbf_text[20];
3167 cdev=init_data->cdev;
3168 irq_ptr = cdev->private->qdio_data;
3169 if (!irq_ptr)
3170 return -EINVAL;
3172 if (cdev->private->state != DEV_STATE_ONLINE)
3173 return -EINVAL;
3175 down(&irq_ptr->setting_up_sema);
3177 qdio_fill_irq(init_data);
3179 /* the thinint CHSC stuff */
3180 if (irq_ptr->is_thinint_irq) {
3182 result = tiqdio_set_subchannel_ind(irq_ptr,0);
3183 if (result) {
3184 up(&irq_ptr->setting_up_sema);
3185 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3186 return result;
3188 tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET);
3191 sprintf(dbf_text,"qest%4x",cdev->private->sch_no);
3192 QDIO_DBF_TEXT0(0,setup,dbf_text);
3193 QDIO_DBF_TEXT0(0,trace,dbf_text);
3195 /* establish q */
3196 irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd;
3197 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3198 irq_ptr->ccw.count=irq_ptr->equeue.count;
3199 irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr);
3201 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3203 ccw_device_set_options(cdev, 0);
3204 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3205 QDIO_DOING_ESTABLISH,0, 0,
3206 QDIO_ESTABLISH_TIMEOUT);
3207 if (result) {
3208 result2=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3209 QDIO_DOING_ESTABLISH,0,0,
3210 QDIO_ESTABLISH_TIMEOUT);
3211 sprintf(dbf_text,"eq:io%4x",result);
3212 QDIO_DBF_TEXT2(1,setup,dbf_text);
3213 if (result2) {
3214 sprintf(dbf_text,"eq:io%4x",result);
3215 QDIO_DBF_TEXT2(1,setup,dbf_text);
3217 QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \
3218 "returned %i, next try returned %i\n",
3219 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3220 result, result2);
3221 result=result2;
3222 if (result)
3223 ccw_device_set_timeout(cdev, 0);
3226 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3228 if (result) {
3229 up(&irq_ptr->setting_up_sema);
3230 qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR);
3231 return result;
3234 /* Timeout is cared for already by using ccw_device_start_timeout(). */
3235 wait_event_interruptible(cdev->private->wait_q,
3236 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
3237 irq_ptr->state == QDIO_IRQ_STATE_ERR);
3239 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
3240 result = 0;
3241 else {
3242 up(&irq_ptr->setting_up_sema);
3243 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3244 return -EIO;
3247 qdio_get_ssqd_information(irq_ptr);
3248 /* if this gets set once, we're running under VM and can omit SVSes */
3249 if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY)
3250 omit_svs=1;
3252 sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac);
3253 QDIO_DBF_TEXT2(0,setup,dbf_text);
3255 sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac);
3256 QDIO_DBF_TEXT2(0,setup,dbf_text);
3258 irq_ptr->hydra_gives_outbound_pcis=
3259 irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED;
3260 irq_ptr->sync_done_on_outb_pcis=
3261 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS;
3263 qdio_initialize_set_siga_flags_input(irq_ptr);
3264 qdio_initialize_set_siga_flags_output(irq_ptr);
3266 up(&irq_ptr->setting_up_sema);
3268 return result;
3273 qdio_activate(struct ccw_device *cdev, int flags)
3275 struct qdio_irq *irq_ptr;
3276 int i,result=0,result2;
3277 unsigned long saveflags;
3278 char dbf_text[20]; /* see qdio_initialize */
3280 irq_ptr = cdev->private->qdio_data;
3281 if (!irq_ptr)
3282 return -ENODEV;
3284 if (cdev->private->state != DEV_STATE_ONLINE)
3285 return -EINVAL;
3287 down(&irq_ptr->setting_up_sema);
3288 if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) {
3289 result=-EBUSY;
3290 goto out;
3293 sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no);
3294 QDIO_DBF_TEXT2(0,setup,dbf_text);
3295 QDIO_DBF_TEXT2(0,trace,dbf_text);
3297 /* activate q */
3298 irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd;
3299 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3300 irq_ptr->ccw.count=irq_ptr->aqueue.count;
3301 irq_ptr->ccw.cda=QDIO_GET_ADDR(0);
3303 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3305 ccw_device_set_timeout(cdev, 0);
3306 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
3307 result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
3308 0, DOIO_DENY_PREFETCH);
3309 if (result) {
3310 result2=ccw_device_start(cdev,&irq_ptr->ccw,
3311 QDIO_DOING_ACTIVATE,0,0);
3312 sprintf(dbf_text,"aq:io%4x",result);
3313 QDIO_DBF_TEXT2(1,setup,dbf_text);
3314 if (result2) {
3315 sprintf(dbf_text,"aq:io%4x",result);
3316 QDIO_DBF_TEXT2(1,setup,dbf_text);
3318 QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \
3319 "returned %i, next try returned %i\n",
3320 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3321 result, result2);
3322 result=result2;
3325 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3326 if (result)
3327 goto out;
3329 for (i=0;i<irq_ptr->no_input_qs;i++) {
3330 if (irq_ptr->is_thinint_irq) {
3332 * that way we know, that, if we will get interrupted
3333 * by tiqdio_inbound_processing, qdio_unmark_q will
3334 * not be called
3336 qdio_reserve_q(irq_ptr->input_qs[i]);
3337 qdio_mark_tiq(irq_ptr->input_qs[i]);
3338 qdio_release_q(irq_ptr->input_qs[i]);
3342 if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) {
3343 for (i=0;i<irq_ptr->no_input_qs;i++) {
3344 irq_ptr->input_qs[i]->is_input_q|=
3345 QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT;
3349 wait_event_interruptible_timeout(cdev->private->wait_q,
3350 ((irq_ptr->state ==
3351 QDIO_IRQ_STATE_STOPPED) ||
3352 (irq_ptr->state ==
3353 QDIO_IRQ_STATE_ERR)),
3354 QDIO_ACTIVATE_TIMEOUT);
3356 switch (irq_ptr->state) {
3357 case QDIO_IRQ_STATE_STOPPED:
3358 case QDIO_IRQ_STATE_ERR:
3359 up(&irq_ptr->setting_up_sema);
3360 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3361 down(&irq_ptr->setting_up_sema);
3362 result = -EIO;
3363 break;
3364 default:
3365 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
3366 result = 0;
3368 out:
3369 up(&irq_ptr->setting_up_sema);
3371 return result;
3374 /* buffers filled forwards again to make Rick happy */
3375 static inline void
3376 qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx,
3377 unsigned int count, struct qdio_buffer *buffers)
3379 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3380 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3381 if (irq->is_qebsm) {
3382 while (count)
3383 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3384 return;
3386 for (;;) {
3387 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3388 count--;
3389 if (!count) break;
3390 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3394 static inline void
3395 qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx,
3396 unsigned int count, struct qdio_buffer *buffers)
3398 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3400 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3401 if (irq->is_qebsm) {
3402 while (count)
3403 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3404 return;
3407 for (;;) {
3408 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3409 count--;
3410 if (!count) break;
3411 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3415 static inline void
3416 do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags,
3417 unsigned int qidx, unsigned int count,
3418 struct qdio_buffer *buffers)
3420 int used_elements;
3422 /* This is the inbound handling of queues */
3423 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3425 qdio_do_qdio_fill_input(q,qidx,count,buffers);
3427 if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&&
3428 (callflags&QDIO_FLAG_UNDER_INTERRUPT))
3429 atomic_swap(&q->polling,0);
3431 if (used_elements)
3432 return;
3433 if (callflags&QDIO_FLAG_DONT_SIGA)
3434 return;
3435 if (q->siga_in) {
3436 int result;
3438 result=qdio_siga_input(q);
3439 if (result) {
3440 if (q->siga_error)
3441 q->error_status_flags|=
3442 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
3443 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
3444 q->siga_error=result;
3448 qdio_mark_q(q);
3451 static inline void
3452 do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3453 unsigned int qidx, unsigned int count,
3454 struct qdio_buffer *buffers)
3456 int used_elements;
3457 unsigned int cnt, start_buf;
3458 unsigned char state = 0;
3459 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3461 /* This is the outbound handling of queues */
3462 #ifdef QDIO_PERFORMANCE_STATS
3463 perf_stats.start_time_outbound=NOW;
3464 #endif /* QDIO_PERFORMANCE_STATS */
3466 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3468 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3470 if (callflags&QDIO_FLAG_DONT_SIGA) {
3471 #ifdef QDIO_PERFORMANCE_STATS
3472 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3473 perf_stats.outbound_cnt++;
3474 #endif /* QDIO_PERFORMANCE_STATS */
3475 return;
3477 if (q->is_iqdio_q) {
3478 /* one siga for every sbal */
3479 while (count--)
3480 qdio_kick_outbound_q(q);
3482 __qdio_outbound_processing(q);
3483 } else {
3484 /* under VM, we do a SIGA sync unconditionally */
3485 SYNC_MEMORY;
3486 else {
3488 * w/o shadow queues (else branch of
3489 * SYNC_MEMORY :-/ ), we try to
3490 * fast-requeue buffers
3492 if (irq->is_qebsm) {
3493 cnt = 1;
3494 start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) &
3495 (QDIO_MAX_BUFFERS_PER_Q-1));
3496 qdio_do_eqbs(q, &state, &start_buf, &cnt);
3497 } else
3498 state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1)
3499 &(QDIO_MAX_BUFFERS_PER_Q-1) ];
3500 if (state != SLSB_CU_OUTPUT_PRIMED) {
3501 qdio_kick_outbound_q(q);
3502 } else {
3503 QDIO_DBF_TEXT3(0,trace, "fast-req");
3504 #ifdef QDIO_PERFORMANCE_STATS
3505 perf_stats.fast_reqs++;
3506 #endif /* QDIO_PERFORMANCE_STATS */
3510 * only marking the q could take too long,
3511 * the upper layer module could do a lot of
3512 * traffic in that time
3514 __qdio_outbound_processing(q);
3517 #ifdef QDIO_PERFORMANCE_STATS
3518 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3519 perf_stats.outbound_cnt++;
3520 #endif /* QDIO_PERFORMANCE_STATS */
3523 /* count must be 1 in iqdio */
3525 do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3526 unsigned int queue_number, unsigned int qidx,
3527 unsigned int count,struct qdio_buffer *buffers)
3529 struct qdio_irq *irq_ptr;
3530 #ifdef CONFIG_QDIO_DEBUG
3531 char dbf_text[20];
3533 sprintf(dbf_text,"doQD%04x",cdev->private->sch_no);
3534 QDIO_DBF_TEXT3(0,trace,dbf_text);
3535 #endif /* CONFIG_QDIO_DEBUG */
3537 if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) ||
3538 (count>QDIO_MAX_BUFFERS_PER_Q) ||
3539 (queue_number>QDIO_MAX_QUEUES_PER_IRQ) )
3540 return -EINVAL;
3542 if (count==0)
3543 return 0;
3545 irq_ptr = cdev->private->qdio_data;
3546 if (!irq_ptr)
3547 return -ENODEV;
3549 #ifdef CONFIG_QDIO_DEBUG
3550 if (callflags&QDIO_FLAG_SYNC_INPUT)
3551 QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number],
3552 sizeof(void*));
3553 else
3554 QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number],
3555 sizeof(void*));
3556 sprintf(dbf_text,"flag%04x",callflags);
3557 QDIO_DBF_TEXT3(0,trace,dbf_text);
3558 sprintf(dbf_text,"qi%02xct%02x",qidx,count);
3559 QDIO_DBF_TEXT3(0,trace,dbf_text);
3560 #endif /* CONFIG_QDIO_DEBUG */
3562 if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE)
3563 return -EBUSY;
3565 if (callflags&QDIO_FLAG_SYNC_INPUT)
3566 do_qdio_handle_inbound(irq_ptr->input_qs[queue_number],
3567 callflags, qidx, count, buffers);
3568 else if (callflags&QDIO_FLAG_SYNC_OUTPUT)
3569 do_qdio_handle_outbound(irq_ptr->output_qs[queue_number],
3570 callflags, qidx, count, buffers);
3571 else {
3572 QDIO_DBF_TEXT3(1,trace,"doQD:inv");
3573 return -EINVAL;
3575 return 0;
3578 #ifdef QDIO_PERFORMANCE_STATS
3579 static int
3580 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3581 int buffer_length, int *eof, void *data)
3583 int c=0;
3585 /* we are always called with buffer_length=4k, so we all
3586 deliver on the first read */
3587 if (offset>0)
3588 return 0;
3590 #define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3591 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c);
3592 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c);
3593 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c);
3594 _OUTP_IT("Number of tasklet runs (total) : %u\n",
3595 perf_stats.tl_runs);
3596 _OUTP_IT("\n");
3597 _OUTP_IT("Number of SIGA sync's issued : %u\n",
3598 perf_stats.siga_syncs);
3599 _OUTP_IT("Number of SIGA in's issued : %u\n",
3600 perf_stats.siga_ins);
3601 _OUTP_IT("Number of SIGA out's issued : %u\n",
3602 perf_stats.siga_outs);
3603 _OUTP_IT("Number of PCIs caught : %u\n",
3604 perf_stats.pcis);
3605 _OUTP_IT("Number of adapter interrupts caught : %u\n",
3606 perf_stats.thinints);
3607 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %u\n",
3608 perf_stats.fast_reqs);
3609 _OUTP_IT("\n");
3610 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %u\n",
3611 perf_stats.inbound_time);
3612 _OUTP_IT("Number of inbound transfers : %u\n",
3613 perf_stats.inbound_cnt);
3614 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %u\n",
3615 perf_stats.outbound_time);
3616 _OUTP_IT("Number of do_QDIOs outbound : %u\n",
3617 perf_stats.outbound_cnt);
3618 _OUTP_IT("\n");
3620 return c;
3623 static struct proc_dir_entry *qdio_perf_proc_file;
3624 #endif /* QDIO_PERFORMANCE_STATS */
3626 static void
3627 qdio_add_procfs_entry(void)
3629 #ifdef QDIO_PERFORMANCE_STATS
3630 proc_perf_file_registration=0;
3631 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3632 S_IFREG|0444,&proc_root);
3633 if (qdio_perf_proc_file) {
3634 qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read;
3635 } else proc_perf_file_registration=-1;
3637 if (proc_perf_file_registration)
3638 QDIO_PRINT_WARN("was not able to register perf. " \
3639 "proc-file (%i).\n",
3640 proc_perf_file_registration);
3641 #endif /* QDIO_PERFORMANCE_STATS */
3644 static void
3645 qdio_remove_procfs_entry(void)
3647 #ifdef QDIO_PERFORMANCE_STATS
3648 perf_stats.tl_runs=0;
3650 if (!proc_perf_file_registration) /* means if it went ok earlier */
3651 remove_proc_entry(QDIO_PERF,&proc_root);
3652 #endif /* QDIO_PERFORMANCE_STATS */
3655 static void
3656 tiqdio_register_thinints(void)
3658 char dbf_text[20];
3659 register_thinint_result=
3660 s390_register_adapter_interrupt(&tiqdio_thinint_handler);
3661 if (register_thinint_result) {
3662 sprintf(dbf_text,"regthn%x",(register_thinint_result&0xff));
3663 QDIO_DBF_TEXT0(0,setup,dbf_text);
3664 QDIO_PRINT_ERR("failed to register adapter handler " \
3665 "(rc=%i).\nAdapter interrupts might " \
3666 "not work. Continuing.\n",
3667 register_thinint_result);
3671 static void
3672 tiqdio_unregister_thinints(void)
3674 if (!register_thinint_result)
3675 s390_unregister_adapter_interrupt(&tiqdio_thinint_handler);
3678 static int
3679 qdio_get_qdio_memory(void)
3681 int i;
3682 indicator_used[0]=1;
3684 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3685 indicator_used[i]=0;
3686 indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3687 GFP_KERNEL);
3688 if (!indicators)
3689 return -ENOMEM;
3690 return 0;
3693 static void
3694 qdio_release_qdio_memory(void)
3696 kfree(indicators);
3699 static void
3700 qdio_unregister_dbf_views(void)
3702 if (qdio_dbf_setup)
3703 debug_unregister(qdio_dbf_setup);
3704 if (qdio_dbf_sbal)
3705 debug_unregister(qdio_dbf_sbal);
3706 if (qdio_dbf_sense)
3707 debug_unregister(qdio_dbf_sense);
3708 if (qdio_dbf_trace)
3709 debug_unregister(qdio_dbf_trace);
3710 #ifdef CONFIG_QDIO_DEBUG
3711 if (qdio_dbf_slsb_out)
3712 debug_unregister(qdio_dbf_slsb_out);
3713 if (qdio_dbf_slsb_in)
3714 debug_unregister(qdio_dbf_slsb_in);
3715 #endif /* CONFIG_QDIO_DEBUG */
3718 static int
3719 qdio_register_dbf_views(void)
3721 qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME,
3722 QDIO_DBF_SETUP_PAGES,
3723 QDIO_DBF_SETUP_NR_AREAS,
3724 QDIO_DBF_SETUP_LEN);
3725 if (!qdio_dbf_setup)
3726 goto oom;
3727 debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view);
3728 debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL);
3730 qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME,
3731 QDIO_DBF_SBAL_PAGES,
3732 QDIO_DBF_SBAL_NR_AREAS,
3733 QDIO_DBF_SBAL_LEN);
3734 if (!qdio_dbf_sbal)
3735 goto oom;
3737 debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view);
3738 debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL);
3740 qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME,
3741 QDIO_DBF_SENSE_PAGES,
3742 QDIO_DBF_SENSE_NR_AREAS,
3743 QDIO_DBF_SENSE_LEN);
3744 if (!qdio_dbf_sense)
3745 goto oom;
3747 debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view);
3748 debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL);
3750 qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME,
3751 QDIO_DBF_TRACE_PAGES,
3752 QDIO_DBF_TRACE_NR_AREAS,
3753 QDIO_DBF_TRACE_LEN);
3754 if (!qdio_dbf_trace)
3755 goto oom;
3757 debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view);
3758 debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL);
3760 #ifdef CONFIG_QDIO_DEBUG
3761 qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME,
3762 QDIO_DBF_SLSB_OUT_PAGES,
3763 QDIO_DBF_SLSB_OUT_NR_AREAS,
3764 QDIO_DBF_SLSB_OUT_LEN);
3765 if (!qdio_dbf_slsb_out)
3766 goto oom;
3767 debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view);
3768 debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL);
3770 qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME,
3771 QDIO_DBF_SLSB_IN_PAGES,
3772 QDIO_DBF_SLSB_IN_NR_AREAS,
3773 QDIO_DBF_SLSB_IN_LEN);
3774 if (!qdio_dbf_slsb_in)
3775 goto oom;
3776 debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view);
3777 debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL);
3778 #endif /* CONFIG_QDIO_DEBUG */
3779 return 0;
3780 oom:
3781 QDIO_PRINT_ERR("not enough memory for dbf.\n");
3782 qdio_unregister_dbf_views();
3783 return -ENOMEM;
3786 static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size)
3788 return (void *) get_zeroed_page(gfp_mask|GFP_DMA);
3791 static void qdio_mempool_free(void *element, void *size)
3793 free_page((unsigned long) element);
3796 static int __init
3797 init_QDIO(void)
3799 int res;
3800 #ifdef QDIO_PERFORMANCE_STATS
3801 void *ptr;
3802 #endif /* QDIO_PERFORMANCE_STATS */
3804 printk("qdio: loading %s\n",version);
3806 res=qdio_get_qdio_memory();
3807 if (res)
3808 return res;
3810 res = qdio_register_dbf_views();
3811 if (res)
3812 return res;
3814 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3816 #ifdef QDIO_PERFORMANCE_STATS
3817 memset((void*)&perf_stats,0,sizeof(perf_stats));
3818 QDIO_DBF_TEXT0(0,setup,"perfstat");
3819 ptr=&perf_stats;
3820 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3821 #endif /* QDIO_PERFORMANCE_STATS */
3823 qdio_add_procfs_entry();
3825 qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS,
3826 qdio_mempool_alloc,
3827 qdio_mempool_free, NULL);
3829 if (tiqdio_check_chsc_availability())
3830 QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
3832 tiqdio_register_thinints();
3834 return 0;
3837 static void __exit
3838 cleanup_QDIO(void)
3840 tiqdio_unregister_thinints();
3841 qdio_remove_procfs_entry();
3842 qdio_release_qdio_memory();
3843 qdio_unregister_dbf_views();
3844 mempool_destroy(qdio_mempool_scssc);
3846 printk("qdio: %s: module removed\n",version);
3849 module_init(init_QDIO);
3850 module_exit(cleanup_QDIO);
3852 EXPORT_SYMBOL(qdio_allocate);
3853 EXPORT_SYMBOL(qdio_establish);
3854 EXPORT_SYMBOL(qdio_initialize);
3855 EXPORT_SYMBOL(qdio_activate);
3856 EXPORT_SYMBOL(do_QDIO);
3857 EXPORT_SYMBOL(qdio_shutdown);
3858 EXPORT_SYMBOL(qdio_free);
3859 EXPORT_SYMBOL(qdio_cleanup);
3860 EXPORT_SYMBOL(qdio_synchronize);