3 * linux/drivers/s390/cio/qdio.c
5 * Linux for S/390 QDIO base support, Hipersocket base support
8 * Copyright 2000,2002 IBM Corporation
9 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
10 * 2.6 cio integration by Cornelia Huck <cohuck@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)
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>
42 #include <asm/ccwdev.h>
44 #include <asm/atomic.h>
45 #include <asm/semaphore.h>
46 #include <asm/timex.h>
48 #include <asm/debug.h>
59 #define VERSION_QDIO_C "$Revision: 1.108 $"
61 /****************** MODULE PARAMETER VARIABLES ********************/
62 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
63 MODULE_DESCRIPTION("QDIO base support version 2, " \
64 "Copyright 2000 IBM Corporation");
65 MODULE_LICENSE("GPL");
67 /******************** HERE WE GO ***********************************/
69 static const char version[] = "QDIO base support version 2 ("
70 VERSION_QDIO_C "/" VERSION_QDIO_H "/" VERSION_CIO_QDIO_H ")";
72 #ifdef QDIO_PERFORMANCE_STATS
73 static int proc_perf_file_registration;
74 static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
75 static struct qdio_perf_stats perf_stats;
76 #endif /* QDIO_PERFORMANCE_STATS */
78 static int hydra_thinints;
81 static int indicator_used[INDICATORS_PER_CACHELINE];
82 static __u32 * volatile indicators;
83 static __u32 volatile spare_indicator;
84 static atomic_t spare_indicator_usecount;
86 static debug_info_t *qdio_dbf_setup;
87 static debug_info_t *qdio_dbf_sbal;
88 static debug_info_t *qdio_dbf_trace;
89 static debug_info_t *qdio_dbf_sense;
90 #ifdef CONFIG_QDIO_DEBUG
91 static debug_info_t *qdio_dbf_slsb_out;
92 static debug_info_t *qdio_dbf_slsb_in;
93 #endif /* CONFIG_QDIO_DEBUG */
96 static volatile struct qdio_q *tiq_list=NULL; /* volatile as it could change
97 during a while loop */
98 static DEFINE_SPINLOCK(ttiq_list_lock);
99 static int register_thinint_result;
100 static void tiqdio_tl(unsigned long);
101 static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0);
103 /* not a macro, as one of the arguments is atomic_read */
105 qdio_min(int a,int b)
113 /***************** SCRUBBER HELPER ROUTINES **********************/
116 qdio_get_micros(void)
118 return (get_clock() >> 10); /* time>>12 is microseconds */
122 * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve
123 * the q in any case, so that we'll not be interrupted when we are in
124 * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost
125 * ever works (last famous words)
128 qdio_reserve_q(struct qdio_q *q)
130 return atomic_add_return(1,&q->use_count) - 1;
134 qdio_release_q(struct qdio_q *q)
136 atomic_dec(&q->use_count);
139 static volatile inline void
140 qdio_set_slsb(volatile char *slsb, unsigned char value)
142 xchg((char*)slsb,value);
146 qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
151 QDIO_DBF_TEXT4(0,trace,"sigasync");
152 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
154 #ifdef QDIO_PERFORMANCE_STATS
155 perf_stats.siga_syncs++;
156 #endif /* QDIO_PERFORMANCE_STATS */
158 cc = do_siga_sync(q->irq, gpr2, gpr3);
160 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
166 qdio_siga_sync_q(struct qdio_q *q)
169 return qdio_siga_sync(q, 0, q->mask);
170 return qdio_siga_sync(q, q->mask, 0);
174 * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns
175 * an access exception
178 qdio_siga_output(struct qdio_q *q)
184 #ifdef QDIO_PERFORMANCE_STATS
185 perf_stats.siga_outs++;
186 #endif /* QDIO_PERFORMANCE_STATS */
188 QDIO_DBF_TEXT4(0,trace,"sigaout");
189 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
192 cc = do_siga_output(q->irq, q->mask, &busy_bit);
193 //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit);
194 if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) {
197 if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE)
203 if ((cc==2) && (busy_bit))
204 cc |= QDIO_SIGA_ERROR_B_BIT_SET;
207 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
213 qdio_siga_input(struct qdio_q *q)
217 QDIO_DBF_TEXT4(0,trace,"sigain");
218 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
220 #ifdef QDIO_PERFORMANCE_STATS
221 perf_stats.siga_ins++;
222 #endif /* QDIO_PERFORMANCE_STATS */
224 cc = do_siga_input(q->irq, q->mask);
227 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
232 /* locked by the locks in qdio_activate and qdio_cleanup */
233 static __u32 volatile *
234 qdio_get_indicator(void)
238 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
239 if (!indicator_used[i]) {
243 atomic_inc(&spare_indicator_usecount);
244 return (__u32 * volatile) &spare_indicator;
247 /* locked by the locks in qdio_activate and qdio_cleanup */
249 qdio_put_indicator(__u32 *addr)
253 if ( (addr) && (addr!=&spare_indicator) ) {
257 if (addr == &spare_indicator)
258 atomic_dec(&spare_indicator_usecount);
261 static inline volatile void
262 tiqdio_clear_summary_bit(__u32 *location)
264 QDIO_DBF_TEXT5(0,trace,"clrsummb");
265 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
270 static inline volatile void
271 tiqdio_set_summary_bit(__u32 *location)
273 QDIO_DBF_TEXT5(0,trace,"setsummb");
274 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
280 tiqdio_sched_tl(void)
282 tasklet_hi_schedule(&tiqdio_tasklet);
286 qdio_mark_tiq(struct qdio_q *q)
290 QDIO_DBF_TEXT4(0,trace,"mark iq");
291 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
293 spin_lock_irqsave(&ttiq_list_lock,flags);
294 if (unlikely(atomic_read(&q->is_in_shutdown)))
300 if ((q->list_prev) || (q->list_next))
308 q->list_next=tiq_list;
309 q->list_prev=tiq_list->list_prev;
310 tiq_list->list_prev->list_next=q;
311 tiq_list->list_prev=q;
313 spin_unlock_irqrestore(&ttiq_list_lock,flags);
315 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
319 spin_unlock_irqrestore(&ttiq_list_lock,flags);
324 qdio_mark_q(struct qdio_q *q)
326 QDIO_DBF_TEXT4(0,trace,"mark q");
327 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
329 if (unlikely(atomic_read(&q->is_in_shutdown)))
332 tasklet_schedule(&q->tasklet);
336 qdio_stop_polling(struct qdio_q *q)
338 #ifdef QDIO_USE_PROCESSING_STATE
341 if (!atomic_swap(&q->polling,0))
344 QDIO_DBF_TEXT4(0,trace,"stoppoll");
345 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
347 /* show the card that we are not polling anymore */
351 gsf=GET_SAVED_FRONTIER(q);
352 set_slsb(&q->slsb.acc.val[(gsf+QDIO_MAX_BUFFERS_PER_Q-1)&
353 (QDIO_MAX_BUFFERS_PER_Q-1)],
354 SLSB_P_INPUT_NOT_INIT);
356 * we don't issue this SYNC_MEMORY, as we trust Rick T and
357 * moreover will not use the PROCESSING state under VM, so
358 * q->polling was 0 anyway
361 if (q->slsb.acc.val[gsf]!=SLSB_P_INPUT_PRIMED)
364 * set our summary bit again, as otherwise there is a
365 * small window we can miss between resetting it and
366 * checking for PRIMED state
369 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
372 #else /* QDIO_USE_PROCESSING_STATE */
374 #endif /* QDIO_USE_PROCESSING_STATE */
378 * see the comment in do_QDIO and before qdio_reserve_q about the
379 * sophisticated locking outside of unmark_q, so that we don't need to
380 * disable the interrupts :-)
383 qdio_unmark_q(struct qdio_q *q)
387 QDIO_DBF_TEXT4(0,trace,"unmark q");
388 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
390 if ((!q->list_prev)||(!q->list_next))
393 if ((q->is_thinint_q)&&(q->is_input_q)) {
395 spin_lock_irqsave(&ttiq_list_lock,flags);
396 /* in case cleanup has done this already and simultanously
397 * qdio_unmark_q is called from the interrupt handler, we've
398 * got to check this in this specific case again */
399 if ((!q->list_prev)||(!q->list_next))
401 if (q->list_next==q) {
402 /* q was the only interesting q */
407 q->list_next->list_prev=q->list_prev;
408 q->list_prev->list_next=q->list_next;
409 tiq_list=q->list_next;
414 spin_unlock_irqrestore(&ttiq_list_lock,flags);
418 static inline unsigned long
419 tiqdio_clear_global_summary(void)
423 QDIO_DBF_TEXT5(0,trace,"clrglobl");
425 time = do_clear_global_summary();
427 QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long));
433 /************************* OUTBOUND ROUTINES *******************************/
436 qdio_get_outbound_buffer_frontier(struct qdio_q *q)
440 int first_not_to_check;
443 QDIO_DBF_TEXT4(0,trace,"getobfro");
444 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
446 slsb=&q->slsb.acc.val[0];
447 f_mod_no=f=q->first_to_check;
449 * f points to already processed elements, so f+no_used is correct...
450 * ... but: we don't check 128 buffers, as otherwise
451 * qdio_has_outbound_q_moved would return 0
453 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
454 (QDIO_MAX_BUFFERS_PER_Q-1));
456 if ((!q->is_iqdio_q)&&(!q->hydra_gives_outbound_pcis))
460 if (f==first_not_to_check)
463 switch(slsb[f_mod_no]) {
465 /* the adapter has not fetched the output yet */
466 case SLSB_CU_OUTPUT_PRIMED:
467 QDIO_DBF_TEXT5(0,trace,"outpprim");
470 /* the adapter got it */
471 case SLSB_P_OUTPUT_EMPTY:
472 atomic_dec(&q->number_of_buffers_used);
474 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
475 QDIO_DBF_TEXT5(0,trace,"outpempt");
478 case SLSB_P_OUTPUT_ERROR:
479 QDIO_DBF_TEXT3(0,trace,"outperr");
480 sprintf(dbf_text,"%x-%x-%x",f_mod_no,
481 q->sbal[f_mod_no]->element[14].sbalf.value,
482 q->sbal[f_mod_no]->element[15].sbalf.value);
483 QDIO_DBF_TEXT3(1,trace,dbf_text);
484 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
486 /* kind of process the buffer */
487 set_slsb(&q->slsb.acc.val[f_mod_no], SLSB_P_OUTPUT_NOT_INIT);
490 * we increment the frontier, as this buffer
491 * was processed obviously
493 atomic_dec(&q->number_of_buffers_used);
494 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
497 q->error_status_flags|=
498 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
499 q->qdio_error=SLSB_P_OUTPUT_ERROR;
500 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
506 QDIO_DBF_TEXT5(0,trace,"outpni");
509 return (q->first_to_check=f_mod_no);
512 /* all buffers are processed */
514 qdio_is_outbound_q_done(struct qdio_q *q)
517 #ifdef CONFIG_QDIO_DEBUG
521 no_used=atomic_read(&q->number_of_buffers_used);
523 #ifdef CONFIG_QDIO_DEBUG
525 sprintf(dbf_text,"oqisnt%02x",no_used);
526 QDIO_DBF_TEXT4(0,trace,dbf_text);
528 QDIO_DBF_TEXT4(0,trace,"oqisdone");
530 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
531 #endif /* CONFIG_QDIO_DEBUG */
536 qdio_has_outbound_q_moved(struct qdio_q *q)
540 i=qdio_get_outbound_buffer_frontier(q);
542 if ( (i!=GET_SAVED_FRONTIER(q)) ||
543 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
545 QDIO_DBF_TEXT4(0,trace,"oqhasmvd");
546 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
549 QDIO_DBF_TEXT4(0,trace,"oqhsntmv");
550 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
556 qdio_kick_outbound_q(struct qdio_q *q)
559 #ifdef CONFIG_QDIO_DEBUG
562 QDIO_DBF_TEXT4(0,trace,"kickoutq");
563 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
564 #endif /* CONFIG_QDIO_DEBUG */
569 /* here's the story with cc=2 and busy bit set (thanks, Rick):
570 * VM's CP could present us cc=2 and busy bit set on SIGA-write
571 * during reconfiguration of their Guest LAN (only in HIPERS mode,
572 * QDIO mode is asynchronous -- cc=2 and busy bit there will take
573 * the queues down immediately; and not being under VM we have a
574 * problem on cc=2 and busy bit set right away).
576 * Therefore qdio_siga_output will try for a short time constantly,
577 * if such a condition occurs. If it doesn't change, it will
578 * increase the busy_siga_counter and save the timestamp, and
579 * schedule the queue for later processing (via mark_q, using the
580 * queue tasklet). __qdio_outbound_processing will check out the
581 * counter. If non-zero, it will call qdio_kick_outbound_q as often
582 * as the value of the counter. This will attempt further SIGA
583 * instructions. For each successful SIGA, the counter is
584 * decreased, for failing SIGAs the counter remains the same, after
586 * After some time of no movement, qdio_kick_outbound_q will
587 * finally fail and reflect corresponding error codes to call
588 * the upper layer module and have it take the queues down.
590 * Note that this is a change from the original HiperSockets design
591 * (saying cc=2 and busy bit means take the queues down), but in
592 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
593 * conditions will still take the queues down, but the threshold is
594 * higher due to the Guest LAN environment.
598 result=qdio_siga_output(q);
602 /* went smooth this time, reset timestamp */
603 #ifdef CONFIG_QDIO_DEBUG
604 QDIO_DBF_TEXT3(0,trace,"cc2reslv");
605 sprintf(dbf_text,"%4x%2x%2x",q->irq,q->q_no,
606 atomic_read(&q->busy_siga_counter));
607 QDIO_DBF_TEXT3(0,trace,dbf_text);
608 #endif /* CONFIG_QDIO_DEBUG */
609 q->timing.busy_start=0;
611 case (2|QDIO_SIGA_ERROR_B_BIT_SET):
612 /* cc=2 and busy bit: */
613 atomic_inc(&q->busy_siga_counter);
615 /* if the last siga was successful, save
617 if (!q->timing.busy_start)
618 q->timing.busy_start=NOW;
620 /* if we're in time, don't touch error_status_flags
622 if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) {
626 QDIO_DBF_TEXT2(0,trace,"cc2REPRT");
627 #ifdef CONFIG_QDIO_DEBUG
628 sprintf(dbf_text,"%4x%2x%2x",q->irq,q->q_no,
629 atomic_read(&q->busy_siga_counter));
630 QDIO_DBF_TEXT3(0,trace,dbf_text);
631 #endif /* CONFIG_QDIO_DEBUG */
632 /* else fallthrough and report error */
634 /* for plain cc=1, 2 or 3: */
636 q->error_status_flags|=
637 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
638 q->error_status_flags|=
639 QDIO_STATUS_LOOK_FOR_ERROR;
640 q->siga_error=result;
645 qdio_kick_outbound_handler(struct qdio_q *q)
647 int start, end, real_end, count;
648 #ifdef CONFIG_QDIO_DEBUG
652 start = q->first_element_to_kick;
653 /* last_move_ftc was just updated */
654 real_end = GET_SAVED_FRONTIER(q);
655 end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)&
656 (QDIO_MAX_BUFFERS_PER_Q-1);
657 count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)&
658 (QDIO_MAX_BUFFERS_PER_Q-1);
660 #ifdef CONFIG_QDIO_DEBUG
661 QDIO_DBF_TEXT4(0,trace,"kickouth");
662 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
664 sprintf(dbf_text,"s=%2xc=%2x",start,count);
665 QDIO_DBF_TEXT4(0,trace,dbf_text);
666 #endif /* CONFIG_QDIO_DEBUG */
668 if (q->state==QDIO_IRQ_STATE_ACTIVE)
669 q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT|
670 q->error_status_flags,
671 q->qdio_error,q->siga_error,q->q_no,start,count,
674 /* for the next time: */
675 q->first_element_to_kick=real_end;
678 q->error_status_flags=0;
682 __qdio_outbound_processing(struct qdio_q *q)
686 QDIO_DBF_TEXT4(0,trace,"qoutproc");
687 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
689 if (unlikely(qdio_reserve_q(q))) {
691 #ifdef QDIO_PERFORMANCE_STATS
693 #endif /* QDIO_PERFORMANCE_STATS */
694 /* as we're sissies, we'll check next time */
695 if (likely(!atomic_read(&q->is_in_shutdown))) {
697 QDIO_DBF_TEXT4(0,trace,"busy,agn");
701 #ifdef QDIO_PERFORMANCE_STATS
703 perf_stats.tl_runs++;
704 #endif /* QDIO_PERFORMANCE_STATS */
706 /* see comment in qdio_kick_outbound_q */
707 siga_attempts=atomic_read(&q->busy_siga_counter);
708 while (siga_attempts) {
709 atomic_dec(&q->busy_siga_counter);
710 qdio_kick_outbound_q(q);
714 if (qdio_has_outbound_q_moved(q))
715 qdio_kick_outbound_handler(q);
719 * for asynchronous queues, we better check, if the fill
720 * level is too high. for synchronous queues, the fill
721 * level will never be that high.
723 if (atomic_read(&q->number_of_buffers_used)>
724 IQDIO_FILL_LEVEL_TO_POLL)
727 } else if (!q->hydra_gives_outbound_pcis)
728 if (!qdio_is_outbound_q_done(q))
735 qdio_outbound_processing(struct qdio_q *q)
737 __qdio_outbound_processing(q);
740 /************************* INBOUND ROUTINES *******************************/
744 qdio_get_inbound_buffer_frontier(struct qdio_q *q)
748 int first_not_to_check;
749 #ifdef CONFIG_QDIO_DEBUG
751 #endif /* CONFIG_QDIO_DEBUG */
752 #ifdef QDIO_USE_PROCESSING_STATE
753 int last_position=-1;
754 #endif /* QDIO_USE_PROCESSING_STATE */
756 QDIO_DBF_TEXT4(0,trace,"getibfro");
757 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
759 slsb=&q->slsb.acc.val[0];
760 f_mod_no=f=q->first_to_check;
762 * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved
765 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
766 (QDIO_MAX_BUFFERS_PER_Q-1));
769 * we don't use this one, as a PCI or we after a thin interrupt
770 * will sync the queues
775 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
776 if (f==first_not_to_check)
778 switch (slsb[f_mod_no]) {
780 /* CU_EMPTY means frontier is reached */
781 case SLSB_CU_INPUT_EMPTY:
782 QDIO_DBF_TEXT5(0,trace,"inptempt");
785 /* P_PRIMED means set slsb to P_PROCESSING and move on */
786 case SLSB_P_INPUT_PRIMED:
787 QDIO_DBF_TEXT5(0,trace,"inptprim");
789 #ifdef QDIO_USE_PROCESSING_STATE
791 * as soon as running under VM, polling the input queues will
792 * kill VM in terms of CP overhead
795 set_slsb(&slsb[f_mod_no],SLSB_P_INPUT_NOT_INIT);
797 /* set the previous buffer to NOT_INIT. The current
798 * buffer will be set to PROCESSING at the end of
799 * this function to avoid further interrupts. */
800 if (last_position>=0)
801 set_slsb(&slsb[last_position],
802 SLSB_P_INPUT_NOT_INIT);
803 atomic_set(&q->polling,1);
804 last_position=f_mod_no;
806 #else /* QDIO_USE_PROCESSING_STATE */
807 set_slsb(&slsb[f_mod_no],SLSB_P_INPUT_NOT_INIT);
808 #endif /* QDIO_USE_PROCESSING_STATE */
810 * not needed, as the inbound queue will be synced on the next
811 * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s
815 atomic_dec(&q->number_of_buffers_used);
818 case SLSB_P_INPUT_NOT_INIT:
819 case SLSB_P_INPUT_PROCESSING:
820 QDIO_DBF_TEXT5(0,trace,"inpnipro");
823 /* P_ERROR means frontier is reached, break and report error */
824 case SLSB_P_INPUT_ERROR:
825 #ifdef CONFIG_QDIO_DEBUG
826 sprintf(dbf_text,"inperr%2x",f_mod_no);
827 QDIO_DBF_TEXT3(1,trace,dbf_text);
828 #endif /* CONFIG_QDIO_DEBUG */
829 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
831 /* kind of process the buffer */
832 set_slsb(&slsb[f_mod_no],SLSB_P_INPUT_NOT_INIT);
835 q->error_status_flags|=
836 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
837 q->qdio_error=SLSB_P_INPUT_ERROR;
838 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
840 /* we increment the frontier, as this buffer
841 * was processed obviously */
842 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
843 atomic_dec(&q->number_of_buffers_used);
845 #ifdef QDIO_USE_PROCESSING_STATE
847 #endif /* QDIO_USE_PROCESSING_STATE */
851 /* everything else means frontier not changed (HALTED or so) */
856 q->first_to_check=f_mod_no;
858 #ifdef QDIO_USE_PROCESSING_STATE
859 if (last_position>=0)
860 set_slsb(&slsb[last_position],SLSB_P_INPUT_PROCESSING);
861 #endif /* QDIO_USE_PROCESSING_STATE */
863 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
865 return q->first_to_check;
869 qdio_has_inbound_q_moved(struct qdio_q *q)
873 #ifdef QDIO_PERFORMANCE_STATS
874 static int old_pcis=0;
875 static int old_thinints=0;
877 if ((old_pcis==perf_stats.pcis)&&(old_thinints==perf_stats.thinints))
878 perf_stats.start_time_inbound=NOW;
880 old_pcis=perf_stats.pcis;
881 #endif /* QDIO_PERFORMANCE_STATS */
883 i=qdio_get_inbound_buffer_frontier(q);
884 if ( (i!=GET_SAVED_FRONTIER(q)) ||
885 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
887 if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis))
890 QDIO_DBF_TEXT4(0,trace,"inhasmvd");
891 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
894 QDIO_DBF_TEXT4(0,trace,"inhsntmv");
895 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
900 /* means, no more buffers to be filled */
902 tiqdio_is_inbound_q_done(struct qdio_q *q)
905 #ifdef CONFIG_QDIO_DEBUG
909 no_used=atomic_read(&q->number_of_buffers_used);
911 /* propagate the change from 82 to 80 through VM */
914 #ifdef CONFIG_QDIO_DEBUG
916 sprintf(dbf_text,"iqisnt%02x",no_used);
917 QDIO_DBF_TEXT4(0,trace,dbf_text);
919 QDIO_DBF_TEXT4(0,trace,"iniqisdo");
921 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
922 #endif /* CONFIG_QDIO_DEBUG */
928 /* we'll check for more primed buffers in qeth_stop_polling */
931 if (q->slsb.acc.val[q->first_to_check]!=SLSB_P_INPUT_PRIMED)
933 * nothing more to do, if next buffer is not PRIMED.
934 * note that we did a SYNC_MEMORY before, that there
935 * has been a sychnronization.
936 * we will return 0 below, as there is nothing to do
937 * (stop_polling not necessary, as we have not been
938 * using the PROCESSING state
943 * ok, the next input buffer is primed. that means, that device state
944 * change indicator and adapter local summary are set, so we will find
946 * we will return 0 below, as there is nothing to do, except scheduling
947 * ourselves for the next time.
949 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
955 qdio_is_inbound_q_done(struct qdio_q *q)
958 #ifdef CONFIG_QDIO_DEBUG
962 no_used=atomic_read(&q->number_of_buffers_used);
965 * we need that one for synchronization with the adapter, as it
966 * does a kind of PCI avoidance
971 QDIO_DBF_TEXT4(0,trace,"inqisdnA");
972 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
973 QDIO_DBF_TEXT4(0,trace,dbf_text);
977 if (q->slsb.acc.val[q->first_to_check]==SLSB_P_INPUT_PRIMED) {
978 /* we got something to do */
979 QDIO_DBF_TEXT4(0,trace,"inqisntA");
980 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
984 /* on VM, we don't poll, so the q is always done here */
987 if (q->hydra_gives_outbound_pcis)
991 * at this point we know, that inbound first_to_check
992 * has (probably) not moved (see qdio_inbound_processing)
994 if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) {
995 #ifdef CONFIG_QDIO_DEBUG
996 QDIO_DBF_TEXT4(0,trace,"inqisdon");
997 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
998 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
999 QDIO_DBF_TEXT4(0,trace,dbf_text);
1000 #endif /* CONFIG_QDIO_DEBUG */
1003 #ifdef CONFIG_QDIO_DEBUG
1004 QDIO_DBF_TEXT4(0,trace,"inqisntd");
1005 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1006 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1007 QDIO_DBF_TEXT4(0,trace,dbf_text);
1008 #endif /* CONFIG_QDIO_DEBUG */
1014 qdio_kick_inbound_handler(struct qdio_q *q)
1016 int count, start, end, real_end, i;
1017 #ifdef CONFIG_QDIO_DEBUG
1021 QDIO_DBF_TEXT4(0,trace,"kickinh");
1022 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1024 start=q->first_element_to_kick;
1025 real_end=q->first_to_check;
1026 end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1034 i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1037 #ifdef CONFIG_QDIO_DEBUG
1038 sprintf(dbf_text,"s=%2xc=%2x",start,count);
1039 QDIO_DBF_TEXT4(0,trace,dbf_text);
1040 #endif /* CONFIG_QDIO_DEBUG */
1042 if (likely(q->state==QDIO_IRQ_STATE_ACTIVE))
1044 QDIO_STATUS_INBOUND_INT|q->error_status_flags,
1045 q->qdio_error,q->siga_error,q->q_no,start,count,
1048 /* for the next time: */
1049 q->first_element_to_kick=real_end;
1052 q->error_status_flags=0;
1054 #ifdef QDIO_PERFORMANCE_STATS
1055 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
1056 perf_stats.inbound_cnt++;
1057 #endif /* QDIO_PERFORMANCE_STATS */
1061 __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1063 struct qdio_irq *irq_ptr;
1067 QDIO_DBF_TEXT4(0,trace,"iqinproc");
1068 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1071 * we first want to reserve the q, so that we know, that we don't
1072 * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might
1075 if (unlikely(qdio_reserve_q(q))) {
1077 #ifdef QDIO_PERFORMANCE_STATS
1079 #endif /* QDIO_PERFORMANCE_STATS */
1081 * as we might just be about to stop polling, we make
1082 * sure that we check again at least once more
1087 #ifdef QDIO_PERFORMANCE_STATS
1089 #endif /* QDIO_PERFORMANCE_STATS */
1090 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1096 * we reset spare_ind_was_set, when the queue does not use the
1099 if (spare_ind_was_set)
1100 spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator);
1102 if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set)
1105 * q->dev_st_chg_ind is the indicator, be it shared or not.
1106 * only clear it, if indicator is non-shared
1108 if (!spare_ind_was_set)
1109 tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind);
1111 if (q->hydra_gives_outbound_pcis) {
1112 if (!q->siga_sync_done_on_thinints) {
1114 } else if ((!q->siga_sync_done_on_outb_tis)&&
1115 (q->hydra_gives_outbound_pcis)) {
1116 SYNC_MEMORY_ALL_OUTB;
1122 * maybe we have to do work on our outbound queues... at least
1123 * we have to check the outbound-int-capable thinint-capable
1126 if (q->hydra_gives_outbound_pcis) {
1127 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1128 for (i=0;i<irq_ptr->no_output_qs;i++) {
1129 oq = irq_ptr->output_qs[i];
1130 #ifdef QDIO_PERFORMANCE_STATS
1131 perf_stats.tl_runs--;
1132 #endif /* QDIO_PERFORMANCE_STATS */
1133 if (!qdio_is_outbound_q_done(oq))
1134 __qdio_outbound_processing(oq);
1138 if (!qdio_has_inbound_q_moved(q))
1141 qdio_kick_inbound_handler(q);
1142 if (tiqdio_is_inbound_q_done(q))
1143 if (!qdio_stop_polling(q)) {
1145 * we set the flags to get into the stuff next time,
1146 * see also comment in qdio_stop_polling
1148 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1156 tiqdio_inbound_processing(struct qdio_q *q)
1158 __tiqdio_inbound_processing(q, atomic_read(&spare_indicator_usecount));
1162 __qdio_inbound_processing(struct qdio_q *q)
1166 QDIO_DBF_TEXT4(0,trace,"qinproc");
1167 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1169 if (unlikely(qdio_reserve_q(q))) {
1171 #ifdef QDIO_PERFORMANCE_STATS
1173 #endif /* QDIO_PERFORMANCE_STATS */
1174 /* as we're sissies, we'll check next time */
1175 if (likely(!atomic_read(&q->is_in_shutdown))) {
1177 QDIO_DBF_TEXT4(0,trace,"busy,agn");
1181 #ifdef QDIO_PERFORMANCE_STATS
1183 perf_stats.tl_runs++;
1184 #endif /* QDIO_PERFORMANCE_STATS */
1187 if (qdio_has_inbound_q_moved(q)) {
1188 qdio_kick_inbound_handler(q);
1189 if (!qdio_stop_polling(q)) {
1191 if (q_laps<QDIO_Q_LAPS)
1196 if (!qdio_is_inbound_q_done(q))
1197 /* means poll time is not yet over */
1205 qdio_inbound_processing(struct qdio_q *q)
1207 __qdio_inbound_processing(q);
1210 /************************* MAIN ROUTINES *******************************/
1212 #ifdef QDIO_USE_PROCESSING_STATE
1214 tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1222 * under VM, we have not used the PROCESSING state, so no
1223 * need to stop polling
1228 if (unlikely(qdio_reserve_q(q))) {
1230 #ifdef QDIO_PERFORMANCE_STATS
1232 #endif /* QDIO_PERFORMANCE_STATS */
1234 * as we might just be about to stop polling, we make
1235 * sure that we check again at least once more
1239 * sanity -- we'd get here without setting the
1242 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1246 if (qdio_stop_polling(q)) {
1250 if (q_laps<QDIO_Q_LAPS-1) {
1255 * we set the flags to get into the stuff
1256 * next time, see also comment in qdio_stop_polling
1258 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1264 #endif /* QDIO_USE_PROCESSING_STATE */
1267 tiqdio_inbound_checks(void)
1270 int spare_ind_was_set=0;
1271 #ifdef QDIO_USE_PROCESSING_STATE
1273 #endif /* QDIO_USE_PROCESSING_STATE */
1275 QDIO_DBF_TEXT4(0,trace,"iqdinbck");
1276 QDIO_DBF_TEXT5(0,trace,"iqlocsum");
1278 #ifdef QDIO_USE_PROCESSING_STATE
1280 #endif /* QDIO_USE_PROCESSING_STATE */
1282 /* when the spare indicator is used and set, save that and clear it */
1283 if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) {
1284 spare_ind_was_set = 1;
1285 tiqdio_clear_summary_bit((__u32*)&spare_indicator);
1288 q=(struct qdio_q*)tiq_list;
1292 __tiqdio_inbound_processing(q, spare_ind_was_set);
1293 q=(struct qdio_q*)q->list_next;
1294 } while (q!=(struct qdio_q*)tiq_list);
1296 #ifdef QDIO_USE_PROCESSING_STATE
1297 q=(struct qdio_q*)tiq_list;
1301 ret = tiqdio_reset_processing_state(q, q_laps);
1308 q = (struct qdio_q*)q->list_next;
1314 } while (q!=(struct qdio_q*)tiq_list);
1315 #endif /* QDIO_USE_PROCESSING_STATE */
1319 tiqdio_tl(unsigned long data)
1321 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1323 #ifdef QDIO_PERFORMANCE_STATS
1324 perf_stats.tl_runs++;
1325 #endif /* QDIO_PERFORMANCE_STATS */
1327 tiqdio_inbound_checks();
1330 /********************* GENERAL HELPER_ROUTINES ***********************/
1333 qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1337 for (i=0;i<QDIO_MAX_QUEUES_PER_IRQ;i++) {
1338 if (!irq_ptr->input_qs[i])
1341 kfree(irq_ptr->input_qs[i]->slib);
1342 kfree(irq_ptr->input_qs[i]);
1345 if (!irq_ptr->output_qs[i])
1348 kfree(irq_ptr->output_qs[i]->slib);
1349 kfree(irq_ptr->output_qs[i]);
1352 kfree(irq_ptr->qdr);
1357 qdio_set_impl_params(struct qdio_irq *irq_ptr,
1358 unsigned int qib_param_field_format,
1359 /* pointer to 128 bytes or NULL, if no param field */
1360 unsigned char *qib_param_field,
1361 /* pointer to no_queues*128 words of data or NULL */
1362 unsigned int no_input_qs,
1363 unsigned int no_output_qs,
1364 unsigned long *input_slib_elements,
1365 unsigned long *output_slib_elements)
1372 irq_ptr->qib.pfmt=qib_param_field_format;
1373 if (qib_param_field)
1374 memcpy(irq_ptr->qib.parm,qib_param_field,
1375 QDIO_MAX_BUFFERS_PER_Q);
1377 if (input_slib_elements)
1378 for (i=0;i<no_input_qs;i++) {
1379 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1380 irq_ptr->input_qs[i]->slib->slibe[j].parms=
1381 input_slib_elements[
1382 i*QDIO_MAX_BUFFERS_PER_Q+j];
1384 if (output_slib_elements)
1385 for (i=0;i<no_output_qs;i++) {
1386 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1387 irq_ptr->output_qs[i]->slib->slibe[j].parms=
1388 output_slib_elements[
1389 i*QDIO_MAX_BUFFERS_PER_Q+j];
1394 qdio_alloc_qs(struct qdio_irq *irq_ptr,
1395 int no_input_qs, int no_output_qs)
1401 for (i=0;i<no_input_qs;i++) {
1402 q=kmalloc(sizeof(struct qdio_q),GFP_KERNEL);
1405 QDIO_PRINT_ERR("kmalloc of q failed!\n");
1409 memset(q,0,sizeof(struct qdio_q));
1411 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1413 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1417 irq_ptr->input_qs[i]=q;
1420 for (i=0;i<no_output_qs;i++) {
1421 q=kmalloc(sizeof(struct qdio_q),GFP_KERNEL);
1427 memset(q,0,sizeof(struct qdio_q));
1429 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1431 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1435 irq_ptr->output_qs[i]=q;
1444 qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1445 int no_input_qs, int no_output_qs,
1446 qdio_handler_t *input_handler,
1447 qdio_handler_t *output_handler,
1448 unsigned long int_parm,int q_format,
1449 unsigned long flags,
1450 void **inbound_sbals_array,
1451 void **outbound_sbals_array)
1455 char dbf_text[20]; /* see qdio_initialize */
1459 sprintf(dbf_text,"qfqs%4x",cdev->private->irq);
1460 QDIO_DBF_TEXT0(0,setup,dbf_text);
1461 for (i=0;i<no_input_qs;i++) {
1462 q=irq_ptr->input_qs[i];
1464 memset(q,0,((char*)&q->slib)-((char*)q));
1465 sprintf(dbf_text,"in-q%4x",i);
1466 QDIO_DBF_TEXT0(0,setup,dbf_text);
1467 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1469 memset(q->slib,0,PAGE_SIZE);
1470 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1474 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1475 q->sbal[j]=*(inbound_sbals_array++);
1477 q->queue_type=q_format;
1478 q->int_parm=int_parm;
1479 q->irq=irq_ptr->irq;
1480 q->irq_ptr = irq_ptr;
1485 q->first_to_check=0;
1487 q->handler=input_handler;
1488 q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind;
1490 q->tasklet.data=(unsigned long)q;
1491 /* q->is_thinint_q isn't valid at this time, but
1492 * irq_ptr->is_thinint_irq is */
1493 q->tasklet.func=(void(*)(unsigned long))
1494 ((irq_ptr->is_thinint_irq)?&tiqdio_inbound_processing:
1495 &qdio_inbound_processing);
1497 /* actually this is not used for inbound queues. yet. */
1498 atomic_set(&q->busy_siga_counter,0);
1499 q->timing.busy_start=0;
1501 /* for (j=0;j<QDIO_STATS_NUMBER;j++)
1502 q->timing.last_transfer_times[j]=(qdio_get_micros()/
1503 QDIO_STATS_NUMBER)*j;
1504 q->timing.last_transfer_index=QDIO_STATS_NUMBER-1;
1508 if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba=
1509 (unsigned long)(q->slib);
1510 q->slib->sla=(unsigned long)(q->sl);
1511 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1514 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1515 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1517 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1519 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1520 ptr=(void*)&q->slsb;
1521 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1522 ptr=(void*)q->sbal[0];
1523 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1526 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) {
1527 set_slsb(&q->slsb.acc.val[j],
1528 SLSB_P_INPUT_NOT_INIT);
1529 /* q->sbal[j]->element[1].sbalf.i1.key=QDIO_STORAGE_KEY;*/
1533 for (i=0;i<no_output_qs;i++) {
1534 q=irq_ptr->output_qs[i];
1535 memset(q,0,((char*)&q->slib)-((char*)q));
1537 sprintf(dbf_text,"outq%4x",i);
1538 QDIO_DBF_TEXT0(0,setup,dbf_text);
1539 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1541 memset(q->slib,0,PAGE_SIZE);
1542 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1546 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1547 q->sbal[j]=*(outbound_sbals_array++);
1549 q->queue_type=q_format;
1550 q->int_parm=int_parm;
1552 q->irq=irq_ptr->irq;
1554 q->irq_ptr = irq_ptr;
1557 q->first_to_check=0;
1559 q->handler=output_handler;
1561 q->tasklet.data=(unsigned long)q;
1562 q->tasklet.func=(void(*)(unsigned long))
1563 &qdio_outbound_processing;
1565 atomic_set(&q->busy_siga_counter,0);
1566 q->timing.busy_start=0;
1569 if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba=
1570 (unsigned long)(q->slib);
1571 q->slib->sla=(unsigned long)(q->sl);
1572 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1575 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1576 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1578 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1580 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1581 ptr=(void*)&q->slsb;
1582 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1583 ptr=(void*)q->sbal[0];
1584 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1587 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) {
1588 set_slsb(&q->slsb.acc.val[j],
1589 SLSB_P_OUTPUT_NOT_INIT);
1590 /* q->sbal[j]->element[1].sbalf.i1.key=QDIO_STORAGE_KEY;*/
1596 qdio_fill_thresholds(struct qdio_irq *irq_ptr,
1597 unsigned int no_input_qs,
1598 unsigned int no_output_qs,
1599 unsigned int min_input_threshold,
1600 unsigned int max_input_threshold,
1601 unsigned int min_output_threshold,
1602 unsigned int max_output_threshold)
1607 for (i=0;i<no_input_qs;i++) {
1608 q=irq_ptr->input_qs[i];
1609 q->timing.threshold=max_input_threshold;
1610 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1611 q->threshold_classes[j].threshold=
1612 min_input_threshold+
1613 (max_input_threshold-min_input_threshold)/
1616 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1618 for (i=0;i<no_output_qs;i++) {
1619 q=irq_ptr->output_qs[i];
1620 q->timing.threshold=max_output_threshold;
1621 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1622 q->threshold_classes[j].threshold=
1623 min_output_threshold+
1624 (max_output_threshold-min_output_threshold)/
1627 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1632 tiqdio_thinint_handler(void)
1634 QDIO_DBF_TEXT4(0,trace,"thin_int");
1636 #ifdef QDIO_PERFORMANCE_STATS
1637 perf_stats.thinints++;
1638 perf_stats.start_time_inbound=NOW;
1639 #endif /* QDIO_PERFORMANCE_STATS */
1641 /* SVS only when needed:
1642 * issue SVS to benefit from iqdio interrupt avoidance
1643 * (SVS clears AISOI)*/
1645 tiqdio_clear_global_summary();
1647 tiqdio_inbound_checks();
1652 qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state)
1655 #ifdef CONFIG_QDIO_DEBUG
1658 QDIO_DBF_TEXT5(0,trace,"newstate");
1659 sprintf(dbf_text,"%4x%4x",irq_ptr->irq,state);
1660 QDIO_DBF_TEXT5(0,trace,dbf_text);
1661 #endif /* CONFIG_QDIO_DEBUG */
1663 irq_ptr->state=state;
1664 for (i=0;i<irq_ptr->no_input_qs;i++)
1665 irq_ptr->input_qs[i]->state=state;
1666 for (i=0;i<irq_ptr->no_output_qs;i++)
1667 irq_ptr->output_qs[i]->state=state;
1672 qdio_irq_check_sense(int irq, struct irb *irb)
1676 if (irb->esw.esw0.erw.cons) {
1677 sprintf(dbf_text,"sens%4x",irq);
1678 QDIO_DBF_TEXT2(1,trace,dbf_text);
1679 QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN);
1681 QDIO_PRINT_WARN("sense data available on qdio channel.\n");
1682 HEXDUMP16(WARN,"irb: ",irb);
1683 HEXDUMP16(WARN,"sense data: ",irb->ecw);
1689 qdio_handle_pci(struct qdio_irq *irq_ptr)
1694 #ifdef QDIO_PERFORMANCE_STATS
1696 perf_stats.start_time_inbound=NOW;
1697 #endif /* QDIO_PERFORMANCE_STATS */
1698 for (i=0;i<irq_ptr->no_input_qs;i++) {
1699 q=irq_ptr->input_qs[i];
1700 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1703 #ifdef QDIO_PERFORMANCE_STATS
1704 perf_stats.tl_runs--;
1705 #endif /* QDIO_PERFORMANCE_STATS */
1706 __qdio_inbound_processing(q);
1709 if (!irq_ptr->hydra_gives_outbound_pcis)
1711 for (i=0;i<irq_ptr->no_output_qs;i++) {
1712 q=irq_ptr->output_qs[i];
1713 #ifdef QDIO_PERFORMANCE_STATS
1714 perf_stats.tl_runs--;
1715 #endif /* QDIO_PERFORMANCE_STATS */
1716 if (qdio_is_outbound_q_done(q))
1718 if (!irq_ptr->sync_done_on_outb_pcis)
1720 __qdio_outbound_processing(q);
1724 static void qdio_establish_handle_irq(struct ccw_device*, int, int);
1727 qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm,
1728 int cstat, int dstat)
1730 struct qdio_irq *irq_ptr;
1734 irq_ptr = cdev->private->qdio_data;
1736 QDIO_DBF_TEXT2(1, trace, "ick2");
1737 sprintf(dbf_text,"%s", cdev->dev.bus_id);
1738 QDIO_DBF_TEXT2(1,trace,dbf_text);
1739 QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int));
1740 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
1741 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
1742 QDIO_PRINT_ERR("received check condition on activate " \
1743 "queues on device %s (cs=x%x, ds=x%x).\n",
1744 cdev->dev.bus_id, cstat, dstat);
1745 if (irq_ptr->no_input_qs) {
1746 q=irq_ptr->input_qs[0];
1747 } else if (irq_ptr->no_output_qs) {
1748 q=irq_ptr->output_qs[0];
1750 QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n",
1752 goto omit_handler_call;
1754 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
1755 QDIO_STATUS_LOOK_FOR_ERROR,
1756 0,0,0,-1,-1,q->int_parm);
1758 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED);
1763 qdio_call_shutdown(void *data)
1765 struct ccw_device *cdev;
1767 cdev = (struct ccw_device *)data;
1768 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1769 put_device(&cdev->dev);
1773 qdio_timeout_handler(struct ccw_device *cdev)
1775 struct qdio_irq *irq_ptr;
1778 QDIO_DBF_TEXT2(0, trace, "qtoh");
1779 sprintf(dbf_text, "%s", cdev->dev.bus_id);
1780 QDIO_DBF_TEXT2(0, trace, dbf_text);
1782 irq_ptr = cdev->private->qdio_data;
1783 sprintf(dbf_text, "state:%d", irq_ptr->state);
1784 QDIO_DBF_TEXT2(0, trace, dbf_text);
1786 switch (irq_ptr->state) {
1787 case QDIO_IRQ_STATE_INACTIVE:
1788 QDIO_PRINT_ERR("establish queues on irq %04x: timed out\n",
1790 QDIO_DBF_TEXT2(1,setup,"eq:timeo");
1791 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1793 case QDIO_IRQ_STATE_CLEANUP:
1794 QDIO_PRINT_INFO("Did not get interrupt on cleanup, irq=0x%x.\n",
1796 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1798 case QDIO_IRQ_STATE_ESTABLISHED:
1799 case QDIO_IRQ_STATE_ACTIVE:
1800 /* I/O has been terminated by common I/O layer. */
1801 QDIO_PRINT_INFO("Queues on irq %04x killed by cio.\n",
1803 QDIO_DBF_TEXT2(1, trace, "cio:term");
1804 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1805 if (get_device(&cdev->dev)) {
1806 /* Can't call shutdown from interrupt context. */
1807 PREPARE_WORK(&cdev->private->kick_work,
1808 qdio_call_shutdown, (void *)cdev);
1809 queue_work(ccw_device_work, &cdev->private->kick_work);
1815 ccw_device_set_timeout(cdev, 0);
1816 wake_up(&cdev->private->wait_q);
1820 qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1822 struct qdio_irq *irq_ptr;
1826 #ifdef CONFIG_QDIO_DEBUG
1827 QDIO_DBF_TEXT4(0, trace, "qint");
1828 sprintf(dbf_text, "%s", cdev->dev.bus_id);
1829 QDIO_DBF_TEXT4(0, trace, dbf_text);
1830 #endif /* CONFIG_QDIO_DEBUG */
1833 QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \
1834 "handler, device %s\n", cdev->dev.bus_id);
1838 irq_ptr = cdev->private->qdio_data;
1840 QDIO_DBF_TEXT2(1, trace, "uint");
1841 sprintf(dbf_text,"%s", cdev->dev.bus_id);
1842 QDIO_DBF_TEXT2(1,trace,dbf_text);
1843 QDIO_PRINT_ERR("received interrupt on unused device %s!\n",
1849 /* Currently running i/o is in error. */
1850 switch (PTR_ERR(irb)) {
1852 QDIO_PRINT_ERR("i/o error on device %s\n",
1856 qdio_timeout_handler(cdev);
1859 QDIO_PRINT_ERR("unknown error state %ld on device %s\n",
1860 PTR_ERR(irb), cdev->dev.bus_id);
1865 qdio_irq_check_sense(irq_ptr->irq, irb);
1867 #ifdef CONFIG_QDIO_DEBUG
1868 sprintf(dbf_text, "state:%d", irq_ptr->state);
1869 QDIO_DBF_TEXT4(0, trace, dbf_text);
1870 #endif /* CONFIG_QDIO_DEBUG */
1872 cstat = irb->scsw.cstat;
1873 dstat = irb->scsw.dstat;
1875 switch (irq_ptr->state) {
1876 case QDIO_IRQ_STATE_INACTIVE:
1877 qdio_establish_handle_irq(cdev, cstat, dstat);
1880 case QDIO_IRQ_STATE_CLEANUP:
1881 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1884 case QDIO_IRQ_STATE_ESTABLISHED:
1885 case QDIO_IRQ_STATE_ACTIVE:
1886 if (cstat & SCHN_STAT_PCI) {
1887 qdio_handle_pci(irq_ptr);
1891 if ((cstat&~SCHN_STAT_PCI)||dstat) {
1892 qdio_handle_activate_check(cdev, intparm, cstat, dstat);
1896 QDIO_PRINT_ERR("got interrupt for queues in state %d on " \
1898 irq_ptr->state, cdev->dev.bus_id);
1900 wake_up(&cdev->private->wait_q);
1905 qdio_synchronize(struct ccw_device *cdev, unsigned int flags,
1906 unsigned int queue_number)
1910 struct qdio_irq *irq_ptr;
1912 #ifdef CONFIG_QDIO_DEBUG
1913 char dbf_text[15]="SyncXXXX";
1916 irq_ptr = cdev->private->qdio_data;
1920 #ifdef CONFIG_QDIO_DEBUG
1921 *((int*)(&dbf_text[4])) = irq_ptr->irq;
1922 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
1923 *((int*)(&dbf_text[0]))=flags;
1924 *((int*)(&dbf_text[4]))=queue_number;
1925 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
1926 #endif /* CONFIG_QDIO_DEBUG */
1928 if (flags&QDIO_FLAG_SYNC_INPUT) {
1929 q=irq_ptr->input_qs[queue_number];
1932 cc = do_siga_sync(q->irq, 0, q->mask);
1933 } else if (flags&QDIO_FLAG_SYNC_OUTPUT) {
1934 q=irq_ptr->output_qs[queue_number];
1937 cc = do_siga_sync(q->irq, q->mask, 0);
1943 QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int));
1948 static unsigned char
1949 qdio_check_siga_needs(int sch)
1952 unsigned char qdioac;
1955 struct chsc_header request;
1961 struct chsc_header response;
1976 ssqd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1978 QDIO_PRINT_WARN("Could not get memory for chsc. Using all " \
1979 "SIGAs for sch x%x.\n", sch);
1980 return CHSC_FLAG_SIGA_INPUT_NECESSARY ||
1981 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
1982 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
1984 ssqd_area->request = (struct chsc_header) {
1989 ssqd_area->first_sch = sch;
1990 ssqd_area->last_sch = sch;
1992 result=chsc(ssqd_area);
1995 QDIO_PRINT_WARN("CHSC returned cc %i. Using all " \
1996 "SIGAs for sch x%x.\n",
1998 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
1999 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2000 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2004 if (ssqd_area->response.code != QDIO_CHSC_RESPONSE_CODE_OK) {
2005 QDIO_PRINT_WARN("response upon checking SIGA needs " \
2006 "is 0x%x. Using all SIGAs for sch x%x.\n",
2007 ssqd_area->response.code, sch);
2008 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2009 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2010 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2013 if (!(ssqd_area->flags & CHSC_FLAG_QDIO_CAPABILITY) ||
2014 !(ssqd_area->flags & CHSC_FLAG_VALIDITY) ||
2015 (ssqd_area->sch != sch)) {
2016 QDIO_PRINT_WARN("huh? problems checking out sch x%x... " \
2017 "using all SIGAs.\n",sch);
2018 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2019 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2020 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* worst case */
2024 qdioac = ssqd_area->qdioac;
2026 free_page ((unsigned long) ssqd_area);
2031 tiqdio_check_chsc_availability(void)
2035 if (!css_characteristics_avail)
2038 /* Check for bit 41. */
2039 if (!css_general_characteristics.aif) {
2040 QDIO_PRINT_WARN("Adapter interruption facility not " \
2045 /* Check for bits 107 and 108. */
2046 if (!css_chsc_characteristics.scssc ||
2047 !css_chsc_characteristics.scsscf) {
2048 QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \
2049 "not available.\n");
2053 /* Check for OSA/FCP thin interrupts (bit 67). */
2054 hydra_thinints = css_general_characteristics.aif_osa;
2055 sprintf(dbf_text,"hydrati%1x", hydra_thinints);
2056 QDIO_DBF_TEXT0(0,setup,dbf_text);
2058 /* Check for aif time delay disablement fac (bit 56). If installed,
2059 * omit svs even under lpar (good point by rick again) */
2060 omit_svs = css_general_characteristics.aif_tdd;
2061 sprintf(dbf_text,"omitsvs%1x", omit_svs);
2062 QDIO_DBF_TEXT0(0,setup,dbf_text);
2068 tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero)
2070 unsigned long real_addr_local_summary_bit;
2071 unsigned long real_addr_dev_st_chg_ind;
2075 unsigned int resp_code;
2079 struct chsc_header request;
2084 u64 summary_indicator_addr;
2085 u64 subchannel_indicator_addr;
2090 u32 word_with_d_bit;
2091 /* set to 0x10000000 to enable
2092 * time delay disablement facility */
2095 u32 reserved6[1004];
2096 struct chsc_header response;
2100 if (!irq_ptr->is_thinint_irq)
2103 if (reset_to_zero) {
2104 real_addr_local_summary_bit=0;
2105 real_addr_dev_st_chg_ind=0;
2107 real_addr_local_summary_bit=
2108 virt_to_phys((volatile void *)indicators);
2109 real_addr_dev_st_chg_ind=
2110 virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind);
2113 scssc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
2115 QDIO_PRINT_WARN("No memory for setting indicators on " \
2116 "subchannel x%x.\n", irq_ptr->irq);
2119 scssc_area->request = (struct chsc_header) {
2123 scssc_area->operation_code = 0;
2125 scssc_area->summary_indicator_addr = real_addr_local_summary_bit;
2126 scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind;
2127 scssc_area->ks = QDIO_STORAGE_KEY;
2128 scssc_area->kc = QDIO_STORAGE_KEY;
2129 scssc_area->isc = TIQDIO_THININT_ISC;
2130 scssc_area->subsystem_id = (1<<16) + irq_ptr->irq;
2131 /* enables the time delay disablement facility. Don't care
2132 * whether it is really there (i.e. we haven't checked for
2134 if (css_general_characteristics.aif_tdd)
2135 scssc_area->word_with_d_bit = 0x10000000;
2137 QDIO_PRINT_WARN("Time delay disablement facility " \
2142 result = chsc(scssc_area);
2144 QDIO_PRINT_WARN("could not set indicators on irq x%x, " \
2145 "cc=%i.\n",irq_ptr->irq,result);
2150 resp_code = scssc_area->response.code;
2151 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2152 QDIO_PRINT_WARN("response upon setting indicators " \
2153 "is 0x%x.\n",resp_code);
2154 sprintf(dbf_text,"sidR%4x",resp_code);
2155 QDIO_DBF_TEXT1(0,trace,dbf_text);
2156 QDIO_DBF_TEXT1(0,setup,dbf_text);
2157 ptr=&scssc_area->response;
2158 QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN);
2163 QDIO_DBF_TEXT2(0,setup,"setscind");
2164 QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit,
2165 sizeof(unsigned long));
2166 QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long));
2169 free_page ((unsigned long) scssc_area);
2175 tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target)
2177 unsigned int resp_code;
2183 struct chsc_header request;
2190 u32 reserved5[1009];
2191 struct chsc_header response;
2195 if (!irq_ptr->is_thinint_irq)
2198 scsscf_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
2200 QDIO_PRINT_WARN("No memory for setting delay target on " \
2201 "subchannel x%x.\n", irq_ptr->irq);
2204 scsscf_area->request = (struct chsc_header) {
2209 scsscf_area->delay_target = delay_target<<16;
2211 result=chsc(scsscf_area);
2213 QDIO_PRINT_WARN("could not set delay target on irq x%x, " \
2214 "cc=%i. Continuing.\n",irq_ptr->irq,result);
2219 resp_code = scsscf_area->response.code;
2220 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2221 QDIO_PRINT_WARN("response upon setting delay target " \
2222 "is 0x%x. Continuing.\n",resp_code);
2223 sprintf(dbf_text,"sdtR%4x",resp_code);
2224 QDIO_DBF_TEXT1(0,trace,dbf_text);
2225 QDIO_DBF_TEXT1(0,setup,dbf_text);
2226 ptr=&scsscf_area->response;
2227 QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN);
2229 QDIO_DBF_TEXT2(0,trace,"delytrgt");
2230 QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long));
2231 result = 0; /* not critical */
2233 free_page ((unsigned long) scsscf_area);
2238 qdio_cleanup(struct ccw_device *cdev, int how)
2240 struct qdio_irq *irq_ptr;
2244 irq_ptr = cdev->private->qdio_data;
2248 sprintf(dbf_text,"qcln%4x",irq_ptr->irq);
2249 QDIO_DBF_TEXT1(0,trace,dbf_text);
2250 QDIO_DBF_TEXT0(0,setup,dbf_text);
2252 rc = qdio_shutdown(cdev, how);
2253 if ((rc == 0) || (rc == -EINPROGRESS))
2254 rc = qdio_free(cdev);
2259 qdio_shutdown(struct ccw_device *cdev, int how)
2261 struct qdio_irq *irq_ptr;
2265 unsigned long flags;
2269 irq_ptr = cdev->private->qdio_data;
2273 down(&irq_ptr->setting_up_sema);
2275 sprintf(dbf_text,"qsqs%4x",irq_ptr->irq);
2276 QDIO_DBF_TEXT1(0,trace,dbf_text);
2277 QDIO_DBF_TEXT0(0,setup,dbf_text);
2279 /* mark all qs as uninteresting */
2280 for (i=0;i<irq_ptr->no_input_qs;i++)
2281 atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1);
2283 for (i=0;i<irq_ptr->no_output_qs;i++)
2284 atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1);
2286 tasklet_kill(&tiqdio_tasklet);
2288 for (i=0;i<irq_ptr->no_input_qs;i++) {
2289 qdio_unmark_q(irq_ptr->input_qs[i]);
2290 tasklet_kill(&irq_ptr->input_qs[i]->tasklet);
2291 wait_event_interruptible_timeout(cdev->private->wait_q,
2292 !atomic_read(&irq_ptr->
2295 QDIO_NO_USE_COUNT_TIMEOUT);
2296 if (atomic_read(&irq_ptr->input_qs[i]->use_count))
2297 result=-EINPROGRESS;
2300 for (i=0;i<irq_ptr->no_output_qs;i++) {
2301 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2302 wait_event_interruptible_timeout(cdev->private->wait_q,
2303 !atomic_read(&irq_ptr->
2306 QDIO_NO_USE_COUNT_TIMEOUT);
2307 if (atomic_read(&irq_ptr->output_qs[i]->use_count))
2308 result=-EINPROGRESS;
2311 /* cleanup subchannel */
2312 spin_lock_irqsave(get_ccwdev_lock(cdev),flags);
2313 if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) {
2314 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
2315 timeout=QDIO_CLEANUP_CLEAR_TIMEOUT;
2316 } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) {
2317 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2318 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2319 } else { /* default behaviour */
2320 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2321 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2323 if (rc == -ENODEV) {
2324 /* No need to wait for device no longer present. */
2325 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2326 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2327 } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) {
2329 * Whoever put another handler there, has to cope with the
2330 * interrupt theirself. Might happen if qdio_shutdown was
2331 * called on already shutdown queues, but this shouldn't have
2334 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2335 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2336 } else if (rc == 0) {
2337 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
2338 ccw_device_set_timeout(cdev, timeout);
2339 spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
2341 wait_event(cdev->private->wait_q,
2342 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
2343 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2345 QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
2346 "device %s\n", result, cdev->dev.bus_id);
2347 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2351 if (irq_ptr->is_thinint_irq) {
2352 qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind);
2353 tiqdio_set_subchannel_ind(irq_ptr,1);
2354 /* reset adapter interrupt indicators */
2357 /* exchange int handlers, if necessary */
2358 if ((void*)cdev->handler == (void*)qdio_handler)
2359 cdev->handler=irq_ptr->original_int_handler;
2361 /* Ignore errors. */
2362 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2363 ccw_device_set_timeout(cdev, 0);
2365 up(&irq_ptr->setting_up_sema);
2370 qdio_free(struct ccw_device *cdev)
2372 struct qdio_irq *irq_ptr;
2375 irq_ptr = cdev->private->qdio_data;
2379 down(&irq_ptr->setting_up_sema);
2381 sprintf(dbf_text,"qfqs%4x",irq_ptr->irq);
2382 QDIO_DBF_TEXT1(0,trace,dbf_text);
2383 QDIO_DBF_TEXT0(0,setup,dbf_text);
2385 cdev->private->qdio_data = 0;
2387 up(&irq_ptr->setting_up_sema);
2389 qdio_release_irq_memory(irq_ptr);
2390 module_put(THIS_MODULE);
2395 qdio_allocate_do_dbf(struct qdio_initialize *init_data)
2397 char dbf_text[20]; /* if a printf printed out more than 8 chars */
2399 sprintf(dbf_text,"qfmt:%x",init_data->q_format);
2400 QDIO_DBF_TEXT0(0,setup,dbf_text);
2401 QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8);
2402 sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format);
2403 QDIO_DBF_TEXT0(0,setup,dbf_text);
2404 QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*));
2405 QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*));
2406 QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*));
2407 sprintf(dbf_text,"miit%4x",init_data->min_input_threshold);
2408 QDIO_DBF_TEXT0(0,setup,dbf_text);
2409 sprintf(dbf_text,"mait%4x",init_data->max_input_threshold);
2410 QDIO_DBF_TEXT0(0,setup,dbf_text);
2411 sprintf(dbf_text,"miot%4x",init_data->min_output_threshold);
2412 QDIO_DBF_TEXT0(0,setup,dbf_text);
2413 sprintf(dbf_text,"maot%4x",init_data->max_output_threshold);
2414 QDIO_DBF_TEXT0(0,setup,dbf_text);
2415 sprintf(dbf_text,"niq:%4x",init_data->no_input_qs);
2416 QDIO_DBF_TEXT0(0,setup,dbf_text);
2417 sprintf(dbf_text,"noq:%4x",init_data->no_output_qs);
2418 QDIO_DBF_TEXT0(0,setup,dbf_text);
2419 QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*));
2420 QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*));
2421 QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long));
2422 QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long));
2423 QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*));
2424 QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*));
2428 qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt)
2430 irq_ptr->input_qs[i]->is_iqdio_q = iqfmt;
2431 irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2433 irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib);
2435 irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl);
2437 irq_ptr->qdr->qdf0[i].slsba=
2438 (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]);
2440 irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY;
2441 irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY;
2442 irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY;
2443 irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY;
2447 qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i,
2450 irq_ptr->output_qs[i]->is_iqdio_q = iqfmt;
2451 irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2453 irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib);
2455 irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl);
2457 irq_ptr->qdr->qdf0[i+j].slsba=
2458 (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]);
2460 irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY;
2461 irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY;
2462 irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY;
2463 irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY;
2468 qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr)
2472 for (i=0;i<irq_ptr->no_input_qs;i++) {
2473 irq_ptr->input_qs[i]->siga_sync=
2474 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2475 irq_ptr->input_qs[i]->siga_in=
2476 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2477 irq_ptr->input_qs[i]->siga_out=
2478 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2479 irq_ptr->input_qs[i]->siga_sync_done_on_thinints=
2480 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2481 irq_ptr->input_qs[i]->hydra_gives_outbound_pcis=
2482 irq_ptr->hydra_gives_outbound_pcis;
2483 irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis=
2485 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2486 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2487 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2488 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2494 qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr)
2498 for (i=0;i<irq_ptr->no_output_qs;i++) {
2499 irq_ptr->output_qs[i]->siga_sync=
2500 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2501 irq_ptr->output_qs[i]->siga_in=
2502 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2503 irq_ptr->output_qs[i]->siga_out=
2504 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2505 irq_ptr->output_qs[i]->siga_sync_done_on_thinints=
2506 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2507 irq_ptr->output_qs[i]->hydra_gives_outbound_pcis=
2508 irq_ptr->hydra_gives_outbound_pcis;
2509 irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis=
2511 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2512 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2513 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2514 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2520 qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat,
2524 struct qdio_irq *irq_ptr;
2526 irq_ptr = cdev->private->qdio_data;
2528 if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
2529 sprintf(dbf_text,"ick1%4x",irq_ptr->irq);
2530 QDIO_DBF_TEXT2(1,trace,dbf_text);
2531 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2532 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2533 QDIO_PRINT_ERR("received check condition on establish " \
2534 "queues on irq 0x%x (cs=x%x, ds=x%x).\n",
2535 irq_ptr->irq,cstat,dstat);
2536 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR);
2539 if (!(dstat & DEV_STAT_DEV_END)) {
2540 QDIO_DBF_TEXT2(1,setup,"eq:no de");
2541 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2542 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2543 QDIO_PRINT_ERR("establish queues on irq %04x: didn't get "
2544 "device end: dstat=%02x, cstat=%02x\n",
2545 irq_ptr->irq, dstat, cstat);
2546 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2550 if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) {
2551 QDIO_DBF_TEXT2(1,setup,"eq:badio");
2552 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2553 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2554 QDIO_PRINT_ERR("establish queues on irq %04x: got "
2555 "the following devstat: dstat=%02x, "
2557 irq_ptr->irq, dstat, cstat);
2558 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2565 qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
2567 struct qdio_irq *irq_ptr;
2570 irq_ptr = cdev->private->qdio_data;
2572 sprintf(dbf_text,"qehi%4x",cdev->private->irq);
2573 QDIO_DBF_TEXT0(0,setup,dbf_text);
2574 QDIO_DBF_TEXT0(0,trace,dbf_text);
2576 if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
2577 ccw_device_set_timeout(cdev, 0);
2581 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
2582 ccw_device_set_timeout(cdev, 0);
2586 qdio_initialize(struct qdio_initialize *init_data)
2591 sprintf(dbf_text,"qini%4x",init_data->cdev->private->irq);
2592 QDIO_DBF_TEXT0(0,setup,dbf_text);
2593 QDIO_DBF_TEXT0(0,trace,dbf_text);
2595 rc = qdio_allocate(init_data);
2597 rc = qdio_establish(init_data);
2599 qdio_free(init_data->cdev);
2607 qdio_allocate(struct qdio_initialize *init_data)
2609 struct qdio_irq *irq_ptr;
2612 sprintf(dbf_text,"qalc%4x",init_data->cdev->private->irq);
2613 QDIO_DBF_TEXT0(0,setup,dbf_text);
2614 QDIO_DBF_TEXT0(0,trace,dbf_text);
2615 if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2616 (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2617 ((init_data->no_input_qs) && (!init_data->input_handler)) ||
2618 ((init_data->no_output_qs) && (!init_data->output_handler)) )
2621 if (!init_data->input_sbal_addr_array)
2624 if (!init_data->output_sbal_addr_array)
2627 qdio_allocate_do_dbf(init_data);
2630 irq_ptr=kmalloc(sizeof(struct qdio_irq), GFP_KERNEL | GFP_DMA);
2632 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2633 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
2636 QDIO_PRINT_ERR("kmalloc of irq_ptr failed!\n");
2640 memset(irq_ptr,0,sizeof(struct qdio_irq));
2642 init_MUTEX(&irq_ptr->setting_up_sema);
2644 /* QDR must be in DMA area since CCW data address is only 32 bit */
2645 irq_ptr->qdr=kmalloc(sizeof(struct qdr), GFP_KERNEL | GFP_DMA);
2646 if (!(irq_ptr->qdr)) {
2648 QDIO_PRINT_ERR("kmalloc of irq_ptr->qdr failed!\n");
2651 QDIO_DBF_TEXT0(0,setup,"qdr:");
2652 QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*));
2654 if (qdio_alloc_qs(irq_ptr,
2655 init_data->no_input_qs,
2656 init_data->no_output_qs)) {
2657 qdio_release_irq_memory(irq_ptr);
2661 init_data->cdev->private->qdio_data = irq_ptr;
2663 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE);
2668 int qdio_fill_irq(struct qdio_initialize *init_data)
2674 struct qdio_irq *irq_ptr;
2676 irq_ptr = init_data->cdev->private->qdio_data;
2678 memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr));
2680 /* wipes qib.ac, required by ar7063 */
2681 memset(irq_ptr->qdr,0,sizeof(struct qdr));
2683 irq_ptr->int_parm=init_data->int_parm;
2685 irq_ptr->irq = init_data->cdev->private->irq;
2686 irq_ptr->no_input_qs=init_data->no_input_qs;
2687 irq_ptr->no_output_qs=init_data->no_output_qs;
2689 if (init_data->q_format==QDIO_IQDIO_QFMT) {
2690 irq_ptr->is_iqdio_irq=1;
2691 irq_ptr->is_thinint_irq=1;
2693 irq_ptr->is_iqdio_irq=0;
2694 irq_ptr->is_thinint_irq=hydra_thinints;
2696 sprintf(dbf_text,"is_i_t%1x%1x",
2697 irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq);
2698 QDIO_DBF_TEXT2(0,setup,dbf_text);
2700 if (irq_ptr->is_thinint_irq) {
2701 irq_ptr->dev_st_chg_ind=qdio_get_indicator();
2702 QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*));
2703 if (!irq_ptr->dev_st_chg_ind) {
2704 QDIO_PRINT_WARN("no indicator location available " \
2705 "for irq 0x%x\n",irq_ptr->irq);
2706 qdio_release_irq_memory(irq_ptr);
2712 irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD;
2713 irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT;
2714 irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD;
2715 irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT;
2717 qdio_fill_qs(irq_ptr, init_data->cdev,
2718 init_data->no_input_qs,
2719 init_data->no_output_qs,
2720 init_data->input_handler,
2721 init_data->output_handler,init_data->int_parm,
2722 init_data->q_format,init_data->flags,
2723 init_data->input_sbal_addr_array,
2724 init_data->output_sbal_addr_array);
2726 if (!try_module_get(THIS_MODULE)) {
2727 QDIO_PRINT_CRIT("try_module_get() failed!\n");
2728 qdio_release_irq_memory(irq_ptr);
2732 qdio_fill_thresholds(irq_ptr,init_data->no_input_qs,
2733 init_data->no_output_qs,
2734 init_data->min_input_threshold,
2735 init_data->max_input_threshold,
2736 init_data->min_output_threshold,
2737 init_data->max_output_threshold);
2740 irq_ptr->qdr->qfmt=init_data->q_format;
2741 irq_ptr->qdr->iqdcnt=init_data->no_input_qs;
2742 irq_ptr->qdr->oqdcnt=init_data->no_output_qs;
2743 irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */
2744 irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4;
2746 irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib;
2747 irq_ptr->qdr->qkey=QDIO_STORAGE_KEY;
2750 irq_ptr->qib.qfmt=init_data->q_format;
2751 if (init_data->no_input_qs)
2752 irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib);
2753 if (init_data->no_output_qs)
2754 irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib);
2755 memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8);
2757 qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format,
2758 init_data->qib_param_field,
2759 init_data->no_input_qs,
2760 init_data->no_output_qs,
2761 init_data->input_slib_elements,
2762 init_data->output_slib_elements);
2764 /* first input descriptors, then output descriptors */
2765 is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0;
2766 for (i=0;i<init_data->no_input_qs;i++)
2767 qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio);
2769 for (i=0;i<init_data->no_output_qs;i++)
2770 qdio_allocate_fill_output_desc(irq_ptr, i,
2771 init_data->no_input_qs,
2774 /* qdr, qib, sls, slsbs, slibs, sbales filled. */
2776 /* get qdio commands */
2777 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
2779 QDIO_DBF_TEXT2(1,setup,"no eq");
2780 QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. "
2781 "Trying to use default.\n");
2783 irq_ptr->equeue = *ciw;
2784 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
2786 QDIO_DBF_TEXT2(1,setup,"no aq");
2787 QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. "
2788 "Trying to use default.\n");
2790 irq_ptr->aqueue = *ciw;
2792 /* Set new interrupt handler. */
2793 irq_ptr->original_int_handler = init_data->cdev->handler;
2794 init_data->cdev->handler = qdio_handler;
2800 qdio_establish(struct qdio_initialize *init_data)
2802 struct qdio_irq *irq_ptr;
2803 unsigned long saveflags;
2804 int result, result2;
2805 struct ccw_device *cdev;
2808 cdev=init_data->cdev;
2809 irq_ptr = cdev->private->qdio_data;
2813 if (cdev->private->state != DEV_STATE_ONLINE)
2816 down(&irq_ptr->setting_up_sema);
2818 qdio_fill_irq(init_data);
2820 /* the thinint CHSC stuff */
2821 if (irq_ptr->is_thinint_irq) {
2823 result = tiqdio_set_subchannel_ind(irq_ptr,0);
2825 up(&irq_ptr->setting_up_sema);
2826 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2829 tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET);
2832 sprintf(dbf_text,"qest%4x",cdev->private->irq);
2833 QDIO_DBF_TEXT0(0,setup,dbf_text);
2834 QDIO_DBF_TEXT0(0,trace,dbf_text);
2837 irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd;
2838 irq_ptr->ccw.flags=CCW_FLAG_SLI;
2839 irq_ptr->ccw.count=irq_ptr->equeue.count;
2840 irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr);
2842 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
2844 ccw_device_set_options(cdev, 0);
2845 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
2846 QDIO_DOING_ESTABLISH,0, 0,
2847 QDIO_ESTABLISH_TIMEOUT);
2849 result2=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
2850 QDIO_DOING_ESTABLISH,0,0,
2851 QDIO_ESTABLISH_TIMEOUT);
2852 sprintf(dbf_text,"eq:io%4x",result);
2853 QDIO_DBF_TEXT2(1,setup,dbf_text);
2855 sprintf(dbf_text,"eq:io%4x",result);
2856 QDIO_DBF_TEXT2(1,setup,dbf_text);
2858 QDIO_PRINT_WARN("establish queues on irq %04x: do_IO " \
2859 "returned %i, next try returned %i\n",
2860 irq_ptr->irq,result,result2);
2863 ccw_device_set_timeout(cdev, 0);
2866 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
2869 up(&irq_ptr->setting_up_sema);
2870 qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR);
2874 /* Timeout is cared for already by using ccw_device_start_timeout(). */
2875 wait_event_interruptible(cdev->private->wait_q,
2876 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
2877 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2879 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
2882 up(&irq_ptr->setting_up_sema);
2883 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2887 irq_ptr->qdioac=qdio_check_siga_needs(irq_ptr->irq);
2888 /* if this gets set once, we're running under VM and can omit SVSes */
2889 if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY)
2892 sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac);
2893 QDIO_DBF_TEXT2(0,setup,dbf_text);
2895 sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac);
2896 QDIO_DBF_TEXT2(0,setup,dbf_text);
2898 irq_ptr->hydra_gives_outbound_pcis=
2899 irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED;
2900 irq_ptr->sync_done_on_outb_pcis=
2901 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS;
2903 qdio_initialize_set_siga_flags_input(irq_ptr);
2904 qdio_initialize_set_siga_flags_output(irq_ptr);
2906 up(&irq_ptr->setting_up_sema);
2913 qdio_activate(struct ccw_device *cdev, int flags)
2915 struct qdio_irq *irq_ptr;
2916 int i,result=0,result2;
2917 unsigned long saveflags;
2918 char dbf_text[20]; /* see qdio_initialize */
2920 irq_ptr = cdev->private->qdio_data;
2924 if (cdev->private->state != DEV_STATE_ONLINE)
2927 down(&irq_ptr->setting_up_sema);
2928 if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) {
2933 sprintf(dbf_text,"qact%4x", irq_ptr->irq);
2934 QDIO_DBF_TEXT2(0,setup,dbf_text);
2935 QDIO_DBF_TEXT2(0,trace,dbf_text);
2938 irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd;
2939 irq_ptr->ccw.flags=CCW_FLAG_SLI;
2940 irq_ptr->ccw.count=irq_ptr->aqueue.count;
2941 irq_ptr->ccw.cda=QDIO_GET_ADDR(0);
2943 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
2945 ccw_device_set_timeout(cdev, 0);
2946 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
2947 result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
2948 0, DOIO_DENY_PREFETCH);
2950 result2=ccw_device_start(cdev,&irq_ptr->ccw,
2951 QDIO_DOING_ACTIVATE,0,0);
2952 sprintf(dbf_text,"aq:io%4x",result);
2953 QDIO_DBF_TEXT2(1,setup,dbf_text);
2955 sprintf(dbf_text,"aq:io%4x",result);
2956 QDIO_DBF_TEXT2(1,setup,dbf_text);
2958 QDIO_PRINT_WARN("activate queues on irq %04x: do_IO " \
2959 "returned %i, next try returned %i\n",
2960 irq_ptr->irq,result,result2);
2964 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
2968 for (i=0;i<irq_ptr->no_input_qs;i++) {
2969 if (irq_ptr->is_thinint_irq) {
2971 * that way we know, that, if we will get interrupted
2972 * by tiqdio_inbound_processing, qdio_unmark_q will
2975 qdio_reserve_q(irq_ptr->input_qs[i]);
2976 qdio_mark_tiq(irq_ptr->input_qs[i]);
2977 qdio_release_q(irq_ptr->input_qs[i]);
2981 if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) {
2982 for (i=0;i<irq_ptr->no_input_qs;i++) {
2983 irq_ptr->input_qs[i]->is_input_q|=
2984 QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT;
2988 wait_event_interruptible_timeout(cdev->private->wait_q,
2990 QDIO_IRQ_STATE_STOPPED) ||
2992 QDIO_IRQ_STATE_ERR)),
2993 QDIO_ACTIVATE_TIMEOUT);
2995 switch (irq_ptr->state) {
2996 case QDIO_IRQ_STATE_STOPPED:
2997 case QDIO_IRQ_STATE_ERR:
2998 up(&irq_ptr->setting_up_sema);
2999 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3000 down(&irq_ptr->setting_up_sema);
3004 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
3008 up(&irq_ptr->setting_up_sema);
3013 /* buffers filled forwards again to make Rick happy */
3015 qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx,
3016 unsigned int count, struct qdio_buffer *buffers)
3019 set_slsb(&q->slsb.acc.val[qidx],SLSB_CU_INPUT_EMPTY);
3022 qidx=(qidx+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
3025 /* not necessary, as the queues are synced during the SIGA read */
3030 qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx,
3031 unsigned int count, struct qdio_buffer *buffers)
3034 set_slsb(&q->slsb.acc.val[qidx],SLSB_CU_OUTPUT_PRIMED);
3037 qidx=(qidx+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
3040 /* SIGA write will sync the queues */
3045 do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags,
3046 unsigned int qidx, unsigned int count,
3047 struct qdio_buffer *buffers)
3051 /* This is the inbound handling of queues */
3052 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3054 qdio_do_qdio_fill_input(q,qidx,count,buffers);
3056 if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&&
3057 (callflags&QDIO_FLAG_UNDER_INTERRUPT))
3058 atomic_swap(&q->polling,0);
3062 if (callflags&QDIO_FLAG_DONT_SIGA)
3067 result=qdio_siga_input(q);
3070 q->error_status_flags|=
3071 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
3072 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
3073 q->siga_error=result;
3081 do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3082 unsigned int qidx, unsigned int count,
3083 struct qdio_buffer *buffers)
3087 /* This is the outbound handling of queues */
3088 #ifdef QDIO_PERFORMANCE_STATS
3089 perf_stats.start_time_outbound=NOW;
3090 #endif /* QDIO_PERFORMANCE_STATS */
3092 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3094 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3096 if (callflags&QDIO_FLAG_DONT_SIGA) {
3097 #ifdef QDIO_PERFORMANCE_STATS
3098 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3099 perf_stats.outbound_cnt++;
3100 #endif /* QDIO_PERFORMANCE_STATS */
3103 if (q->is_iqdio_q) {
3104 /* one siga for every sbal */
3106 qdio_kick_outbound_q(q);
3108 __qdio_outbound_processing(q);
3110 /* under VM, we do a SIGA sync unconditionally */
3114 * w/o shadow queues (else branch of
3115 * SYNC_MEMORY :-/ ), we try to
3116 * fast-requeue buffers
3118 if (q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1)
3119 &(QDIO_MAX_BUFFERS_PER_Q-1)]!=
3120 SLSB_CU_OUTPUT_PRIMED) {
3121 qdio_kick_outbound_q(q);
3123 QDIO_DBF_TEXT3(0,trace, "fast-req");
3124 #ifdef QDIO_PERFORMANCE_STATS
3125 perf_stats.fast_reqs++;
3126 #endif /* QDIO_PERFORMANCE_STATS */
3130 * only marking the q could take too long,
3131 * the upper layer module could do a lot of
3132 * traffic in that time
3134 __qdio_outbound_processing(q);
3137 #ifdef QDIO_PERFORMANCE_STATS
3138 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3139 perf_stats.outbound_cnt++;
3140 #endif /* QDIO_PERFORMANCE_STATS */
3143 /* count must be 1 in iqdio */
3145 do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3146 unsigned int queue_number, unsigned int qidx,
3147 unsigned int count,struct qdio_buffer *buffers)
3149 struct qdio_irq *irq_ptr;
3150 #ifdef CONFIG_QDIO_DEBUG
3153 sprintf(dbf_text,"doQD%04x",cdev->private->irq);
3154 QDIO_DBF_TEXT3(0,trace,dbf_text);
3155 #endif /* CONFIG_QDIO_DEBUG */
3157 if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) ||
3158 (count>QDIO_MAX_BUFFERS_PER_Q) ||
3159 (queue_number>QDIO_MAX_QUEUES_PER_IRQ) )
3165 irq_ptr = cdev->private->qdio_data;
3169 #ifdef CONFIG_QDIO_DEBUG
3170 if (callflags&QDIO_FLAG_SYNC_INPUT)
3171 QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number],
3174 QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number],
3176 sprintf(dbf_text,"flag%04x",callflags);
3177 QDIO_DBF_TEXT3(0,trace,dbf_text);
3178 sprintf(dbf_text,"qi%02xct%02x",qidx,count);
3179 QDIO_DBF_TEXT3(0,trace,dbf_text);
3180 #endif /* CONFIG_QDIO_DEBUG */
3182 if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE)
3185 if (callflags&QDIO_FLAG_SYNC_INPUT)
3186 do_qdio_handle_inbound(irq_ptr->input_qs[queue_number],
3187 callflags, qidx, count, buffers);
3188 else if (callflags&QDIO_FLAG_SYNC_OUTPUT)
3189 do_qdio_handle_outbound(irq_ptr->output_qs[queue_number],
3190 callflags, qidx, count, buffers);
3192 QDIO_DBF_TEXT3(1,trace,"doQD:inv");
3198 #ifdef QDIO_PERFORMANCE_STATS
3200 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3201 int buffer_length, int *eof, void *data)
3205 /* we are always called with buffer_length=4k, so we all
3206 deliver on the first read */
3210 #define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3211 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c);
3212 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c);
3213 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c);
3214 _OUTP_IT("Number of tasklet runs (total) : %u\n",
3215 perf_stats.tl_runs);
3217 _OUTP_IT("Number of SIGA sync's issued : %u\n",
3218 perf_stats.siga_syncs);
3219 _OUTP_IT("Number of SIGA in's issued : %u\n",
3220 perf_stats.siga_ins);
3221 _OUTP_IT("Number of SIGA out's issued : %u\n",
3222 perf_stats.siga_outs);
3223 _OUTP_IT("Number of PCIs caught : %u\n",
3225 _OUTP_IT("Number of adapter interrupts caught : %u\n",
3226 perf_stats.thinints);
3227 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %u\n",
3228 perf_stats.fast_reqs);
3230 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %u\n",
3231 perf_stats.inbound_time);
3232 _OUTP_IT("Number of inbound transfers : %u\n",
3233 perf_stats.inbound_cnt);
3234 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %u\n",
3235 perf_stats.outbound_time);
3236 _OUTP_IT("Number of do_QDIOs outbound : %u\n",
3237 perf_stats.outbound_cnt);
3243 static struct proc_dir_entry *qdio_perf_proc_file;
3244 #endif /* QDIO_PERFORMANCE_STATS */
3247 qdio_add_procfs_entry(void)
3249 #ifdef QDIO_PERFORMANCE_STATS
3250 proc_perf_file_registration=0;
3251 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3252 S_IFREG|0444,&proc_root);
3253 if (qdio_perf_proc_file) {
3254 qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read;
3255 } else proc_perf_file_registration=-1;
3257 if (proc_perf_file_registration)
3258 QDIO_PRINT_WARN("was not able to register perf. " \
3259 "proc-file (%i).\n",
3260 proc_perf_file_registration);
3261 #endif /* QDIO_PERFORMANCE_STATS */
3265 qdio_remove_procfs_entry(void)
3267 #ifdef QDIO_PERFORMANCE_STATS
3268 perf_stats.tl_runs=0;
3270 if (!proc_perf_file_registration) /* means if it went ok earlier */
3271 remove_proc_entry(QDIO_PERF,&proc_root);
3272 #endif /* QDIO_PERFORMANCE_STATS */
3276 tiqdio_register_thinints(void)
3279 register_thinint_result=
3280 s390_register_adapter_interrupt(&tiqdio_thinint_handler);
3281 if (register_thinint_result) {
3282 sprintf(dbf_text,"regthn%x",(register_thinint_result&0xff));
3283 QDIO_DBF_TEXT0(0,setup,dbf_text);
3284 QDIO_PRINT_ERR("failed to register adapter handler " \
3285 "(rc=%i).\nAdapter interrupts might " \
3286 "not work. Continuing.\n",
3287 register_thinint_result);
3292 tiqdio_unregister_thinints(void)
3294 if (!register_thinint_result)
3295 s390_unregister_adapter_interrupt(&tiqdio_thinint_handler);
3299 qdio_get_qdio_memory(void)
3302 indicator_used[0]=1;
3304 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3305 indicator_used[i]=0;
3306 indicators=(__u32*)kmalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3308 if (!indicators) return -ENOMEM;
3309 memset(indicators,0,sizeof(__u32)*(INDICATORS_PER_CACHELINE));
3314 qdio_release_qdio_memory(void)
3320 qdio_unregister_dbf_views(void)
3323 debug_unregister(qdio_dbf_setup);
3325 debug_unregister(qdio_dbf_sbal);
3327 debug_unregister(qdio_dbf_sense);
3329 debug_unregister(qdio_dbf_trace);
3330 #ifdef CONFIG_QDIO_DEBUG
3331 if (qdio_dbf_slsb_out)
3332 debug_unregister(qdio_dbf_slsb_out);
3333 if (qdio_dbf_slsb_in)
3334 debug_unregister(qdio_dbf_slsb_in);
3335 #endif /* CONFIG_QDIO_DEBUG */
3339 qdio_register_dbf_views(void)
3341 qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME,
3342 QDIO_DBF_SETUP_PAGES,
3343 QDIO_DBF_SETUP_NR_AREAS,
3344 QDIO_DBF_SETUP_LEN);
3345 if (!qdio_dbf_setup)
3347 debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view);
3348 debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL);
3350 qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME,
3351 QDIO_DBF_SBAL_PAGES,
3352 QDIO_DBF_SBAL_NR_AREAS,
3357 debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view);
3358 debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL);
3360 qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME,
3361 QDIO_DBF_SENSE_PAGES,
3362 QDIO_DBF_SENSE_NR_AREAS,
3363 QDIO_DBF_SENSE_LEN);
3364 if (!qdio_dbf_sense)
3367 debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view);
3368 debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL);
3370 qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME,
3371 QDIO_DBF_TRACE_PAGES,
3372 QDIO_DBF_TRACE_NR_AREAS,
3373 QDIO_DBF_TRACE_LEN);
3374 if (!qdio_dbf_trace)
3377 debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view);
3378 debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL);
3380 #ifdef CONFIG_QDIO_DEBUG
3381 qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME,
3382 QDIO_DBF_SLSB_OUT_PAGES,
3383 QDIO_DBF_SLSB_OUT_NR_AREAS,
3384 QDIO_DBF_SLSB_OUT_LEN);
3385 if (!qdio_dbf_slsb_out)
3387 debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view);
3388 debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL);
3390 qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME,
3391 QDIO_DBF_SLSB_IN_PAGES,
3392 QDIO_DBF_SLSB_IN_NR_AREAS,
3393 QDIO_DBF_SLSB_IN_LEN);
3394 if (!qdio_dbf_slsb_in)
3396 debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view);
3397 debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL);
3398 #endif /* CONFIG_QDIO_DEBUG */
3401 QDIO_PRINT_ERR("not enough memory for dbf.\n");
3402 qdio_unregister_dbf_views();
3410 #ifdef QDIO_PERFORMANCE_STATS
3412 #endif /* QDIO_PERFORMANCE_STATS */
3414 printk("qdio: loading %s\n",version);
3416 res=qdio_get_qdio_memory();
3420 res = qdio_register_dbf_views();
3424 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3426 #ifdef QDIO_PERFORMANCE_STATS
3427 memset((void*)&perf_stats,0,sizeof(perf_stats));
3428 QDIO_DBF_TEXT0(0,setup,"perfstat");
3430 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3431 #endif /* QDIO_PERFORMANCE_STATS */
3433 qdio_add_procfs_entry();
3435 if (tiqdio_check_chsc_availability())
3436 QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
3438 tiqdio_register_thinints();
3446 tiqdio_unregister_thinints();
3447 qdio_remove_procfs_entry();
3448 qdio_release_qdio_memory();
3449 qdio_unregister_dbf_views();
3451 printk("qdio: %s: module removed\n",version);
3454 module_init(init_QDIO);
3455 module_exit(cleanup_QDIO);
3457 EXPORT_SYMBOL(qdio_allocate);
3458 EXPORT_SYMBOL(qdio_establish);
3459 EXPORT_SYMBOL(qdio_initialize);
3460 EXPORT_SYMBOL(qdio_activate);
3461 EXPORT_SYMBOL(do_QDIO);
3462 EXPORT_SYMBOL(qdio_shutdown);
3463 EXPORT_SYMBOL(qdio_free);
3464 EXPORT_SYMBOL(qdio_cleanup);
3465 EXPORT_SYMBOL(qdio_synchronize);