2 * linux/drivers/s390/cio/qdio_main.c
4 * Linux for s390 qdio support, buffer handling, qdio API and module support.
6 * Copyright 2000,2008 IBM Corp.
7 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
8 * Jan Glauber <jang@linux.vnet.ibm.com>
9 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/timer.h>
15 #include <linux/delay.h>
16 #include <linux/gfp.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/atomic.h>
20 #include <asm/debug.h>
27 #include "qdio_debug.h"
29 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
30 "Jan Glauber <jang@linux.vnet.ibm.com>");
31 MODULE_DESCRIPTION("QDIO base support");
32 MODULE_LICENSE("GPL");
34 static inline int do_siga_sync(unsigned long schid
,
35 unsigned int out_mask
, unsigned int in_mask
,
38 register unsigned long __fc
asm ("0") = fc
;
39 register unsigned long __schid
asm ("1") = schid
;
40 register unsigned long out
asm ("2") = out_mask
;
41 register unsigned long in
asm ("3") = in_mask
;
49 : "d" (__fc
), "d" (__schid
), "d" (out
), "d" (in
) : "cc");
53 static inline int do_siga_input(unsigned long schid
, unsigned int mask
,
56 register unsigned long __fc
asm ("0") = fc
;
57 register unsigned long __schid
asm ("1") = schid
;
58 register unsigned long __mask
asm ("2") = mask
;
66 : "d" (__fc
), "d" (__schid
), "d" (__mask
) : "cc", "memory");
71 * do_siga_output - perform SIGA-w/wt function
72 * @schid: subchannel id or in case of QEBSM the subchannel token
73 * @mask: which output queues to process
74 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
75 * @fc: function code to perform
77 * Returns cc or QDIO_ERROR_SIGA_ACCESS_EXCEPTION.
78 * Note: For IQDC unicast queues only the highest priority queue is processed.
80 static inline int do_siga_output(unsigned long schid
, unsigned long mask
,
81 unsigned int *bb
, unsigned int fc
,
84 register unsigned long __fc
asm("0") = fc
;
85 register unsigned long __schid
asm("1") = schid
;
86 register unsigned long __mask
asm("2") = mask
;
87 register unsigned long __aob
asm("3") = aob
;
88 int cc
= QDIO_ERROR_SIGA_ACCESS_EXCEPTION
;
96 : "+d" (cc
), "+d" (__fc
), "+d" (__schid
), "+d" (__mask
),
99 *bb
= ((unsigned int) __fc
) >> 31;
103 static inline int qdio_check_ccq(struct qdio_q
*q
, unsigned int ccq
)
105 /* all done or next buffer state different */
106 if (ccq
== 0 || ccq
== 32)
108 /* not all buffers processed */
109 if (ccq
== 96 || ccq
== 97)
111 /* notify devices immediately */
112 DBF_ERROR("%4x ccq:%3d", SCH_NO(q
), ccq
);
117 * qdio_do_eqbs - extract buffer states for QEBSM
118 * @q: queue to manipulate
119 * @state: state of the extracted buffers
120 * @start: buffer number to start at
121 * @count: count of buffers to examine
122 * @auto_ack: automatically acknowledge buffers
124 * Returns the number of successfully extracted equal buffer states.
125 * Stops processing if a state is different from the last buffers state.
127 static int qdio_do_eqbs(struct qdio_q
*q
, unsigned char *state
,
128 int start
, int count
, int auto_ack
)
130 unsigned int ccq
= 0;
131 int tmp_count
= count
, tmp_start
= start
;
135 BUG_ON(!q
->irq_ptr
->sch_token
);
139 nr
+= q
->irq_ptr
->nr_input_qs
;
141 ccq
= do_eqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
,
143 rc
= qdio_check_ccq(q
, ccq
);
145 /* At least one buffer was processed, return and extract the remaining
148 if ((ccq
== 96) && (count
!= tmp_count
)) {
149 qperf_inc(q
, eqbs_partial
);
150 return (count
- tmp_count
);
154 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "EQBS again:%2d", ccq
);
159 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q
));
160 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
161 q
->handler(q
->irq_ptr
->cdev
,
162 QDIO_ERROR_ACTIVATE_CHECK_CONDITION
,
163 0, -1, -1, q
->irq_ptr
->int_parm
);
166 return count
- tmp_count
;
170 * qdio_do_sqbs - set buffer states for QEBSM
171 * @q: queue to manipulate
172 * @state: new state of the buffers
173 * @start: first buffer number to change
174 * @count: how many buffers to change
176 * Returns the number of successfully changed buffers.
177 * Does retrying until the specified count of buffer states is set or an
180 static int qdio_do_sqbs(struct qdio_q
*q
, unsigned char state
, int start
,
183 unsigned int ccq
= 0;
184 int tmp_count
= count
, tmp_start
= start
;
191 BUG_ON(!q
->irq_ptr
->sch_token
);
195 nr
+= q
->irq_ptr
->nr_input_qs
;
197 ccq
= do_sqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
);
198 rc
= qdio_check_ccq(q
, ccq
);
200 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "SQBS again:%2d", ccq
);
201 qperf_inc(q
, sqbs_partial
);
205 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q
));
206 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
207 q
->handler(q
->irq_ptr
->cdev
,
208 QDIO_ERROR_ACTIVATE_CHECK_CONDITION
,
209 0, -1, -1, q
->irq_ptr
->int_parm
);
213 return count
- tmp_count
;
216 /* returns number of examined buffers and their common state in *state */
217 static inline int get_buf_states(struct qdio_q
*q
, unsigned int bufnr
,
218 unsigned char *state
, unsigned int count
,
219 int auto_ack
, int merge_pending
)
221 unsigned char __state
= 0;
224 BUG_ON(bufnr
> QDIO_MAX_BUFFERS_MASK
);
225 BUG_ON(count
> QDIO_MAX_BUFFERS_PER_Q
);
228 return qdio_do_eqbs(q
, state
, bufnr
, count
, auto_ack
);
230 for (i
= 0; i
< count
; i
++) {
232 __state
= q
->slsb
.val
[bufnr
];
233 if (merge_pending
&& __state
== SLSB_P_OUTPUT_PENDING
)
234 __state
= SLSB_P_OUTPUT_EMPTY
;
235 } else if (merge_pending
) {
236 if ((q
->slsb
.val
[bufnr
] & __state
) != __state
)
238 } else if (q
->slsb
.val
[bufnr
] != __state
)
240 bufnr
= next_buf(bufnr
);
246 static inline int get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
247 unsigned char *state
, int auto_ack
)
249 return get_buf_states(q
, bufnr
, state
, 1, auto_ack
, 0);
252 /* wrap-around safe setting of slsb states, returns number of changed buffers */
253 static inline int set_buf_states(struct qdio_q
*q
, int bufnr
,
254 unsigned char state
, int count
)
258 BUG_ON(bufnr
> QDIO_MAX_BUFFERS_MASK
);
259 BUG_ON(count
> QDIO_MAX_BUFFERS_PER_Q
);
262 return qdio_do_sqbs(q
, state
, bufnr
, count
);
264 for (i
= 0; i
< count
; i
++) {
265 xchg(&q
->slsb
.val
[bufnr
], state
);
266 bufnr
= next_buf(bufnr
);
271 static inline int set_buf_state(struct qdio_q
*q
, int bufnr
,
274 return set_buf_states(q
, bufnr
, state
, 1);
277 /* set slsb states to initial state */
278 void qdio_init_buf_states(struct qdio_irq
*irq_ptr
)
283 for_each_input_queue(irq_ptr
, q
, i
)
284 set_buf_states(q
, 0, SLSB_P_INPUT_NOT_INIT
,
285 QDIO_MAX_BUFFERS_PER_Q
);
286 for_each_output_queue(irq_ptr
, q
, i
)
287 set_buf_states(q
, 0, SLSB_P_OUTPUT_NOT_INIT
,
288 QDIO_MAX_BUFFERS_PER_Q
);
291 static inline int qdio_siga_sync(struct qdio_q
*q
, unsigned int output
,
294 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
295 unsigned int fc
= QDIO_SIGA_SYNC
;
298 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-s:%1d", q
->nr
);
299 qperf_inc(q
, siga_sync
);
302 schid
= q
->irq_ptr
->sch_token
;
303 fc
|= QDIO_SIGA_QEBSM_FLAG
;
306 cc
= do_siga_sync(schid
, output
, input
, fc
);
308 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q
), cc
);
312 static inline int qdio_siga_sync_q(struct qdio_q
*q
)
315 return qdio_siga_sync(q
, 0, q
->mask
);
317 return qdio_siga_sync(q
, q
->mask
, 0);
320 static int qdio_siga_output(struct qdio_q
*q
, unsigned int *busy_bit
,
323 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
324 unsigned int fc
= QDIO_SIGA_WRITE
;
327 unsigned long laob
= 0;
329 if (q
->u
.out
.use_cq
&& aob
!= 0) {
330 fc
= QDIO_SIGA_WRITEQ
;
335 schid
= q
->irq_ptr
->sch_token
;
336 fc
|= QDIO_SIGA_QEBSM_FLAG
;
339 WARN_ON_ONCE((aob
&& queue_type(q
) != QDIO_IQDIO_QFMT
) ||
340 (aob
&& fc
!= QDIO_SIGA_WRITEQ
));
341 cc
= do_siga_output(schid
, q
->mask
, busy_bit
, fc
, laob
);
343 /* hipersocket busy condition */
344 if (unlikely(*busy_bit
)) {
345 WARN_ON(queue_type(q
) != QDIO_IQDIO_QFMT
|| cc
!= 2);
349 start_time
= get_clock();
352 if ((get_clock() - start_time
) < QDIO_BUSY_BIT_PATIENCE
)
356 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
,
357 "%4x cc2 BB1:%1d", SCH_NO(q
), q
->nr
);
358 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "count:%u", retries
);
363 static inline int qdio_siga_input(struct qdio_q
*q
)
365 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
366 unsigned int fc
= QDIO_SIGA_READ
;
369 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-r:%1d", q
->nr
);
370 qperf_inc(q
, siga_read
);
373 schid
= q
->irq_ptr
->sch_token
;
374 fc
|= QDIO_SIGA_QEBSM_FLAG
;
377 cc
= do_siga_input(schid
, q
->mask
, fc
);
379 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q
), cc
);
383 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
384 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
386 static inline void qdio_sync_queues(struct qdio_q
*q
)
388 /* PCI capable outbound queues will also be scanned so sync them too */
389 if (pci_out_supported(q
))
390 qdio_siga_sync_all(q
);
395 int debug_get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
396 unsigned char *state
)
398 if (need_siga_sync(q
))
400 return get_buf_states(q
, bufnr
, state
, 1, 0, 0);
403 static inline void qdio_stop_polling(struct qdio_q
*q
)
405 if (!q
->u
.in
.polling
)
409 qperf_inc(q
, stop_polling
);
411 /* show the card that we are not polling anymore */
413 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
415 q
->u
.in
.ack_count
= 0;
417 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
420 static inline void account_sbals(struct qdio_q
*q
, int count
)
424 q
->q_stats
.nr_sbal_total
+= count
;
425 if (count
== QDIO_MAX_BUFFERS_MASK
) {
426 q
->q_stats
.nr_sbals
[7]++;
431 q
->q_stats
.nr_sbals
[pos
]++;
434 static void process_buffer_error(struct qdio_q
*q
, int count
)
436 unsigned char state
= (q
->is_input_q
) ? SLSB_P_INPUT_NOT_INIT
:
437 SLSB_P_OUTPUT_NOT_INIT
;
439 q
->qdio_error
|= QDIO_ERROR_SLSB_STATE
;
441 /* special handling for no target buffer empty */
442 if ((!q
->is_input_q
&&
443 (q
->sbal
[q
->first_to_check
]->element
[15].sflags
) == 0x10)) {
444 qperf_inc(q
, target_full
);
445 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "OUTFULL FTC:%02x",
450 DBF_ERROR("%4x BUF ERROR", SCH_NO(q
));
451 DBF_ERROR((q
->is_input_q
) ? "IN:%2d" : "OUT:%2d", q
->nr
);
452 DBF_ERROR("FTC:%3d C:%3d", q
->first_to_check
, count
);
453 DBF_ERROR("F14:%2x F15:%2x",
454 q
->sbal
[q
->first_to_check
]->element
[14].sflags
,
455 q
->sbal
[q
->first_to_check
]->element
[15].sflags
);
458 * Interrupts may be avoided as long as the error is present
459 * so change the buffer state immediately to avoid starvation.
461 set_buf_states(q
, q
->first_to_check
, state
, count
);
464 static inline void inbound_primed(struct qdio_q
*q
, int count
)
468 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in prim: %02x", count
);
470 /* for QEBSM the ACK was already set by EQBS */
472 if (!q
->u
.in
.polling
) {
474 q
->u
.in
.ack_count
= count
;
475 q
->u
.in
.ack_start
= q
->first_to_check
;
479 /* delete the previous ACK's */
480 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
482 q
->u
.in
.ack_count
= count
;
483 q
->u
.in
.ack_start
= q
->first_to_check
;
488 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
489 * or by the next inbound run.
491 new = add_buf(q
->first_to_check
, count
- 1);
492 if (q
->u
.in
.polling
) {
493 /* reset the previous ACK but first set the new one */
494 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
495 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
498 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
501 q
->u
.in
.ack_start
= new;
505 /* need to change ALL buffers to get more interrupts */
506 set_buf_states(q
, q
->first_to_check
, SLSB_P_INPUT_NOT_INIT
, count
);
509 static int get_inbound_buffer_frontier(struct qdio_q
*q
)
512 unsigned char state
= 0;
515 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
518 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
519 stop
= add_buf(q
->first_to_check
, count
);
521 if (q
->first_to_check
== stop
)
525 * No siga sync here, as a PCI or we after a thin interrupt
526 * already sync'ed the queues.
528 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 1, 0);
533 case SLSB_P_INPUT_PRIMED
:
534 inbound_primed(q
, count
);
535 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
536 if (atomic_sub(count
, &q
->nr_buf_used
) == 0)
537 qperf_inc(q
, inbound_queue_full
);
538 if (q
->irq_ptr
->perf_stat_enabled
)
539 account_sbals(q
, count
);
541 case SLSB_P_INPUT_ERROR
:
542 process_buffer_error(q
, count
);
543 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
544 atomic_sub(count
, &q
->nr_buf_used
);
545 if (q
->irq_ptr
->perf_stat_enabled
)
546 account_sbals_error(q
, count
);
548 case SLSB_CU_INPUT_EMPTY
:
549 case SLSB_P_INPUT_NOT_INIT
:
550 case SLSB_P_INPUT_ACK
:
551 if (q
->irq_ptr
->perf_stat_enabled
)
552 q
->q_stats
.nr_sbal_nop
++;
553 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in nop");
559 return q
->first_to_check
;
562 static int qdio_inbound_q_moved(struct qdio_q
*q
)
566 bufnr
= get_inbound_buffer_frontier(q
);
568 if ((bufnr
!= q
->last_move
) || q
->qdio_error
) {
569 q
->last_move
= bufnr
;
570 if (!is_thinint_irq(q
->irq_ptr
) && MACHINE_IS_LPAR
)
571 q
->u
.in
.timestamp
= get_clock();
577 static inline int qdio_inbound_q_done(struct qdio_q
*q
)
579 unsigned char state
= 0;
581 if (!atomic_read(&q
->nr_buf_used
))
584 if (need_siga_sync(q
))
586 get_buf_state(q
, q
->first_to_check
, &state
, 0);
588 if (state
== SLSB_P_INPUT_PRIMED
|| state
== SLSB_P_INPUT_ERROR
)
589 /* more work coming */
592 if (is_thinint_irq(q
->irq_ptr
))
595 /* don't poll under z/VM */
600 * At this point we know, that inbound first_to_check
601 * has (probably) not moved (see qdio_inbound_processing).
603 if (get_clock() > q
->u
.in
.timestamp
+ QDIO_INPUT_THRESHOLD
) {
604 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in done:%02x",
611 static inline int contains_aobs(struct qdio_q
*q
)
613 return !q
->is_input_q
&& q
->u
.out
.use_cq
;
616 static inline void qdio_trace_aob(struct qdio_irq
*irq
, struct qdio_q
*q
,
617 int i
, struct qaob
*aob
)
621 DBF_DEV_EVENT(DBF_INFO
, irq
, "AOB%d:%lx", i
,
622 (unsigned long) virt_to_phys(aob
));
623 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES00:%lx",
624 (unsigned long) aob
->res0
[0]);
625 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES01:%lx",
626 (unsigned long) aob
->res0
[1]);
627 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES02:%lx",
628 (unsigned long) aob
->res0
[2]);
629 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES03:%lx",
630 (unsigned long) aob
->res0
[3]);
631 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES04:%lx",
632 (unsigned long) aob
->res0
[4]);
633 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES05:%lx",
634 (unsigned long) aob
->res0
[5]);
635 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES1:%x", aob
->res1
);
636 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES2:%x", aob
->res2
);
637 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES3:%x", aob
->res3
);
638 DBF_DEV_EVENT(DBF_INFO
, irq
, "AORC:%u", aob
->aorc
);
639 DBF_DEV_EVENT(DBF_INFO
, irq
, "FLAGS:%u", aob
->flags
);
640 DBF_DEV_EVENT(DBF_INFO
, irq
, "CBTBS:%u", aob
->cbtbs
);
641 DBF_DEV_EVENT(DBF_INFO
, irq
, "SBC:%u", aob
->sb_count
);
642 for (tmp
= 0; tmp
< QDIO_MAX_ELEMENTS_PER_BUFFER
; ++tmp
) {
643 DBF_DEV_EVENT(DBF_INFO
, irq
, "SBA%d:%lx", tmp
,
644 (unsigned long) aob
->sba
[tmp
]);
645 DBF_DEV_EVENT(DBF_INFO
, irq
, "rSBA%d:%lx", tmp
,
646 (unsigned long) q
->sbal
[i
]->element
[tmp
].addr
);
647 DBF_DEV_EVENT(DBF_INFO
, irq
, "DC%d:%u", tmp
, aob
->dcount
[tmp
]);
648 DBF_DEV_EVENT(DBF_INFO
, irq
, "rDC%d:%u", tmp
,
649 q
->sbal
[i
]->element
[tmp
].length
);
651 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER0:%lx", (unsigned long) aob
->user0
);
652 for (tmp
= 0; tmp
< 2; ++tmp
) {
653 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES4%d:%lx", tmp
,
654 (unsigned long) aob
->res4
[tmp
]);
656 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER1:%lx", (unsigned long) aob
->user1
);
657 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER2:%lx", (unsigned long) aob
->user2
);
660 static inline void qdio_handle_aobs(struct qdio_q
*q
, int start
, int count
)
662 unsigned char state
= 0;
665 if (!contains_aobs(q
))
668 for (j
= 0; j
< count
; ++j
) {
669 get_buf_state(q
, b
, &state
, 0);
670 if (state
== SLSB_P_OUTPUT_PENDING
) {
671 struct qaob
*aob
= q
->u
.out
.aobs
[b
];
675 BUG_ON(q
->u
.out
.sbal_state
== NULL
);
676 q
->u
.out
.sbal_state
[b
].flags
|=
677 QDIO_OUTBUF_STATE_FLAG_PENDING
;
678 q
->u
.out
.aobs
[b
] = NULL
;
679 } else if (state
== SLSB_P_OUTPUT_EMPTY
) {
680 BUG_ON(q
->u
.out
.sbal_state
== NULL
);
681 q
->u
.out
.sbal_state
[b
].aob
= NULL
;
687 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q
*q
,
690 unsigned long phys_aob
= 0;
695 if (!q
->aobs
[bufnr
]) {
696 struct qaob
*aob
= qdio_allocate_aob();
697 q
->aobs
[bufnr
] = aob
;
699 if (q
->aobs
[bufnr
]) {
700 BUG_ON(q
->sbal_state
== NULL
);
701 q
->sbal_state
[bufnr
].flags
= QDIO_OUTBUF_STATE_FLAG_NONE
;
702 q
->sbal_state
[bufnr
].aob
= q
->aobs
[bufnr
];
703 q
->aobs
[bufnr
]->user1
= (u64
) q
->sbal_state
[bufnr
].user
;
704 phys_aob
= virt_to_phys(q
->aobs
[bufnr
]);
705 BUG_ON(phys_aob
& 0xFF);
712 static void qdio_kick_handler(struct qdio_q
*q
)
714 int start
= q
->first_to_kick
;
715 int end
= q
->first_to_check
;
718 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
721 count
= sub_buf(end
, start
);
724 qperf_inc(q
, inbound_handler
);
725 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "kih s:%02x c:%02x", start
, count
);
727 qperf_inc(q
, outbound_handler
);
728 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "koh: s:%02x c:%02x",
732 qdio_handle_aobs(q
, start
, count
);
734 q
->handler(q
->irq_ptr
->cdev
, q
->qdio_error
, q
->nr
, start
, count
,
735 q
->irq_ptr
->int_parm
);
737 /* for the next time */
738 q
->first_to_kick
= end
;
742 static void __qdio_inbound_processing(struct qdio_q
*q
)
744 qperf_inc(q
, tasklet_inbound
);
746 if (!qdio_inbound_q_moved(q
))
749 qdio_kick_handler(q
);
751 if (!qdio_inbound_q_done(q
)) {
752 /* means poll time is not yet over */
753 qperf_inc(q
, tasklet_inbound_resched
);
754 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
)) {
755 tasklet_schedule(&q
->tasklet
);
760 qdio_stop_polling(q
);
762 * We need to check again to not lose initiative after
763 * resetting the ACK state.
765 if (!qdio_inbound_q_done(q
)) {
766 qperf_inc(q
, tasklet_inbound_resched2
);
767 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
))
768 tasklet_schedule(&q
->tasklet
);
772 void qdio_inbound_processing(unsigned long data
)
774 struct qdio_q
*q
= (struct qdio_q
*)data
;
775 __qdio_inbound_processing(q
);
778 static int get_outbound_buffer_frontier(struct qdio_q
*q
)
781 unsigned char state
= 0;
783 if (need_siga_sync(q
))
784 if (((queue_type(q
) != QDIO_IQDIO_QFMT
) &&
785 !pci_out_supported(q
)) ||
786 (queue_type(q
) == QDIO_IQDIO_QFMT
&&
787 multicast_outbound(q
)))
791 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
794 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
795 stop
= add_buf(q
->first_to_check
, count
);
796 if (q
->first_to_check
== stop
)
799 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 0, 1);
804 case SLSB_P_OUTPUT_PENDING
:
806 case SLSB_P_OUTPUT_EMPTY
:
807 /* the adapter got it */
808 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
,
809 "out empty:%1d %02x", q
->nr
, count
);
811 atomic_sub(count
, &q
->nr_buf_used
);
812 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
813 if (q
->irq_ptr
->perf_stat_enabled
)
814 account_sbals(q
, count
);
817 case SLSB_P_OUTPUT_ERROR
:
818 process_buffer_error(q
, count
);
819 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
820 atomic_sub(count
, &q
->nr_buf_used
);
821 if (q
->irq_ptr
->perf_stat_enabled
)
822 account_sbals_error(q
, count
);
824 case SLSB_CU_OUTPUT_PRIMED
:
825 /* the adapter has not fetched the output yet */
826 if (q
->irq_ptr
->perf_stat_enabled
)
827 q
->q_stats
.nr_sbal_nop
++;
828 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out primed:%1d",
831 case SLSB_P_OUTPUT_NOT_INIT
:
832 case SLSB_P_OUTPUT_HALTED
:
839 return q
->first_to_check
;
842 /* all buffers processed? */
843 static inline int qdio_outbound_q_done(struct qdio_q
*q
)
845 return atomic_read(&q
->nr_buf_used
) == 0;
848 static inline int qdio_outbound_q_moved(struct qdio_q
*q
)
852 bufnr
= get_outbound_buffer_frontier(q
);
854 if ((bufnr
!= q
->last_move
) || q
->qdio_error
) {
855 q
->last_move
= bufnr
;
856 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out moved:%1d", q
->nr
);
862 static int qdio_kick_outbound_q(struct qdio_q
*q
, unsigned long aob
)
865 unsigned int busy_bit
;
867 if (!need_siga_out(q
))
870 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w:%1d", q
->nr
);
872 qperf_inc(q
, siga_write
);
874 cc
= qdio_siga_output(q
, &busy_bit
, aob
);
880 while (++retries
< QDIO_BUSY_BIT_RETRIES
) {
881 mdelay(QDIO_BUSY_BIT_RETRY_DELAY
);
884 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q
), q
->nr
);
885 cc
|= QDIO_ERROR_SIGA_BUSY
;
887 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w cc2:%1d", q
->nr
);
891 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q
), cc
);
895 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q
), q
->nr
);
896 DBF_ERROR("count:%u", retries
);
901 static void __qdio_outbound_processing(struct qdio_q
*q
)
903 qperf_inc(q
, tasklet_outbound
);
904 BUG_ON(atomic_read(&q
->nr_buf_used
) < 0);
906 if (qdio_outbound_q_moved(q
))
907 qdio_kick_handler(q
);
909 if (queue_type(q
) == QDIO_ZFCP_QFMT
)
910 if (!pci_out_supported(q
) && !qdio_outbound_q_done(q
))
913 /* bail out for HiperSockets unicast queues */
914 if (queue_type(q
) == QDIO_IQDIO_QFMT
&& !multicast_outbound(q
))
917 if ((queue_type(q
) == QDIO_IQDIO_QFMT
) &&
918 (atomic_read(&q
->nr_buf_used
)) > QDIO_IQDIO_POLL_LVL
)
921 if (q
->u
.out
.pci_out_enabled
)
925 * Now we know that queue type is either qeth without pci enabled
926 * or HiperSockets multicast. Make sure buffer switch from PRIMED to
927 * EMPTY is noticed and outbound_handler is called after some time.
929 if (qdio_outbound_q_done(q
))
930 del_timer(&q
->u
.out
.timer
);
932 if (!timer_pending(&q
->u
.out
.timer
))
933 mod_timer(&q
->u
.out
.timer
, jiffies
+ 10 * HZ
);
937 if (unlikely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
939 tasklet_schedule(&q
->tasklet
);
942 /* outbound tasklet */
943 void qdio_outbound_processing(unsigned long data
)
945 struct qdio_q
*q
= (struct qdio_q
*)data
;
946 __qdio_outbound_processing(q
);
949 void qdio_outbound_timer(unsigned long data
)
951 struct qdio_q
*q
= (struct qdio_q
*)data
;
953 if (unlikely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
955 tasklet_schedule(&q
->tasklet
);
958 static inline void qdio_check_outbound_after_thinint(struct qdio_q
*q
)
963 if (!pci_out_supported(q
))
966 for_each_output_queue(q
->irq_ptr
, out
, i
)
967 if (!qdio_outbound_q_done(out
))
968 tasklet_schedule(&out
->tasklet
);
971 static void __tiqdio_inbound_processing(struct qdio_q
*q
)
973 qperf_inc(q
, tasklet_inbound
);
974 if (need_siga_sync(q
) && need_siga_sync_after_ai(q
))
978 * The interrupt could be caused by a PCI request. Check the
979 * PCI capable outbound queues.
981 qdio_check_outbound_after_thinint(q
);
983 if (!qdio_inbound_q_moved(q
))
986 qdio_kick_handler(q
);
988 if (!qdio_inbound_q_done(q
)) {
989 qperf_inc(q
, tasklet_inbound_resched
);
990 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
)) {
991 tasklet_schedule(&q
->tasklet
);
996 qdio_stop_polling(q
);
998 * We need to check again to not lose initiative after
999 * resetting the ACK state.
1001 if (!qdio_inbound_q_done(q
)) {
1002 qperf_inc(q
, tasklet_inbound_resched2
);
1003 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
))
1004 tasklet_schedule(&q
->tasklet
);
1008 void tiqdio_inbound_processing(unsigned long data
)
1010 struct qdio_q
*q
= (struct qdio_q
*)data
;
1011 __tiqdio_inbound_processing(q
);
1014 static inline void qdio_set_state(struct qdio_irq
*irq_ptr
,
1015 enum qdio_irq_states state
)
1017 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "newstate: %1d", state
);
1019 irq_ptr
->state
= state
;
1023 static void qdio_irq_check_sense(struct qdio_irq
*irq_ptr
, struct irb
*irb
)
1025 if (irb
->esw
.esw0
.erw
.cons
) {
1026 DBF_ERROR("%4x sense:", irq_ptr
->schid
.sch_no
);
1027 DBF_ERROR_HEX(irb
, 64);
1028 DBF_ERROR_HEX(irb
->ecw
, 64);
1032 /* PCI interrupt handler */
1033 static void qdio_int_handler_pci(struct qdio_irq
*irq_ptr
)
1038 if (unlikely(irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
1041 for_each_input_queue(irq_ptr
, q
, i
) {
1042 if (q
->u
.in
.queue_start_poll
) {
1043 /* skip if polling is enabled or already in work */
1044 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1045 &q
->u
.in
.queue_irq_state
)) {
1046 qperf_inc(q
, int_discarded
);
1049 q
->u
.in
.queue_start_poll(q
->irq_ptr
->cdev
, q
->nr
,
1050 q
->irq_ptr
->int_parm
);
1052 tasklet_schedule(&q
->tasklet
);
1056 if (!pci_out_supported(q
))
1059 for_each_output_queue(irq_ptr
, q
, i
) {
1060 if (qdio_outbound_q_done(q
))
1062 if (need_siga_sync(q
) && need_siga_sync_out_after_pci(q
))
1063 qdio_siga_sync_q(q
);
1064 tasklet_schedule(&q
->tasklet
);
1068 static void qdio_handle_activate_check(struct ccw_device
*cdev
,
1069 unsigned long intparm
, int cstat
, int dstat
)
1071 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1074 DBF_ERROR("%4x ACT CHECK", irq_ptr
->schid
.sch_no
);
1075 DBF_ERROR("intp :%lx", intparm
);
1076 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1078 if (irq_ptr
->nr_input_qs
) {
1079 q
= irq_ptr
->input_qs
[0];
1080 } else if (irq_ptr
->nr_output_qs
) {
1081 q
= irq_ptr
->output_qs
[0];
1086 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_ACTIVATE_CHECK_CONDITION
,
1087 0, -1, -1, irq_ptr
->int_parm
);
1089 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1092 static void qdio_establish_handle_irq(struct ccw_device
*cdev
, int cstat
,
1095 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1097 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "qest irq");
1101 if (dstat
& ~(DEV_STAT_DEV_END
| DEV_STAT_CHN_END
))
1103 if (!(dstat
& DEV_STAT_DEV_END
))
1105 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ESTABLISHED
);
1109 DBF_ERROR("%4x EQ:error", irq_ptr
->schid
.sch_no
);
1110 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1111 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1114 /* qdio interrupt handler */
1115 void qdio_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1118 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1121 if (!intparm
|| !irq_ptr
) {
1122 DBF_ERROR("qint:%4x", cdev
->private->schid
.sch_no
);
1126 kstat_cpu(smp_processor_id()).irqs
[IOINT_QDI
]++;
1127 if (irq_ptr
->perf_stat_enabled
)
1128 irq_ptr
->perf_stat
.qdio_int
++;
1131 switch (PTR_ERR(irb
)) {
1133 DBF_ERROR("%4x IO error", irq_ptr
->schid
.sch_no
);
1134 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1135 wake_up(&cdev
->private->wait_q
);
1142 qdio_irq_check_sense(irq_ptr
, irb
);
1143 cstat
= irb
->scsw
.cmd
.cstat
;
1144 dstat
= irb
->scsw
.cmd
.dstat
;
1146 switch (irq_ptr
->state
) {
1147 case QDIO_IRQ_STATE_INACTIVE
:
1148 qdio_establish_handle_irq(cdev
, cstat
, dstat
);
1150 case QDIO_IRQ_STATE_CLEANUP
:
1151 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1153 case QDIO_IRQ_STATE_ESTABLISHED
:
1154 case QDIO_IRQ_STATE_ACTIVE
:
1155 if (cstat
& SCHN_STAT_PCI
) {
1156 qdio_int_handler_pci(irq_ptr
);
1160 qdio_handle_activate_check(cdev
, intparm
, cstat
,
1163 case QDIO_IRQ_STATE_STOPPED
:
1168 wake_up(&cdev
->private->wait_q
);
1172 * qdio_get_ssqd_desc - get qdio subchannel description
1173 * @cdev: ccw device to get description for
1174 * @data: where to store the ssqd
1176 * Returns 0 or an error code. The results of the chsc are stored in the
1177 * specified structure.
1179 int qdio_get_ssqd_desc(struct ccw_device
*cdev
,
1180 struct qdio_ssqd_desc
*data
)
1183 if (!cdev
|| !cdev
->private)
1186 DBF_EVENT("get ssqd:%4x", cdev
->private->schid
.sch_no
);
1187 return qdio_setup_get_ssqd(NULL
, &cdev
->private->schid
, data
);
1189 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc
);
1191 static void qdio_shutdown_queues(struct ccw_device
*cdev
)
1193 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1197 for_each_input_queue(irq_ptr
, q
, i
)
1198 tasklet_kill(&q
->tasklet
);
1200 for_each_output_queue(irq_ptr
, q
, i
) {
1201 del_timer(&q
->u
.out
.timer
);
1202 tasklet_kill(&q
->tasklet
);
1207 * qdio_shutdown - shut down a qdio subchannel
1208 * @cdev: associated ccw device
1209 * @how: use halt or clear to shutdown
1211 int qdio_shutdown(struct ccw_device
*cdev
, int how
)
1213 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1215 unsigned long flags
;
1220 BUG_ON(irqs_disabled());
1221 DBF_EVENT("qshutdown:%4x", cdev
->private->schid
.sch_no
);
1223 mutex_lock(&irq_ptr
->setup_mutex
);
1225 * Subchannel was already shot down. We cannot prevent being called
1226 * twice since cio may trigger a shutdown asynchronously.
1228 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1229 mutex_unlock(&irq_ptr
->setup_mutex
);
1234 * Indicate that the device is going down. Scheduling the queue
1235 * tasklets is forbidden from here on.
1237 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1239 tiqdio_remove_input_queues(irq_ptr
);
1240 qdio_shutdown_queues(cdev
);
1241 qdio_shutdown_debug_entries(irq_ptr
, cdev
);
1243 /* cleanup subchannel */
1244 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
1246 if (how
& QDIO_FLAG_CLEANUP_USING_CLEAR
)
1247 rc
= ccw_device_clear(cdev
, QDIO_DOING_CLEANUP
);
1249 /* default behaviour is halt */
1250 rc
= ccw_device_halt(cdev
, QDIO_DOING_CLEANUP
);
1252 DBF_ERROR("%4x SHUTD ERR", irq_ptr
->schid
.sch_no
);
1253 DBF_ERROR("rc:%4d", rc
);
1257 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_CLEANUP
);
1258 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
1259 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1260 irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
||
1261 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
,
1263 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
1266 qdio_shutdown_thinint(irq_ptr
);
1268 /* restore interrupt handler */
1269 if ((void *)cdev
->handler
== (void *)qdio_int_handler
)
1270 cdev
->handler
= irq_ptr
->orig_handler
;
1271 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
1273 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1274 mutex_unlock(&irq_ptr
->setup_mutex
);
1279 EXPORT_SYMBOL_GPL(qdio_shutdown
);
1282 * qdio_free - free data structures for a qdio subchannel
1283 * @cdev: associated ccw device
1285 int qdio_free(struct ccw_device
*cdev
)
1287 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1292 DBF_EVENT("qfree:%4x", cdev
->private->schid
.sch_no
);
1293 mutex_lock(&irq_ptr
->setup_mutex
);
1295 if (irq_ptr
->debug_area
!= NULL
) {
1296 debug_unregister(irq_ptr
->debug_area
);
1297 irq_ptr
->debug_area
= NULL
;
1299 cdev
->private->qdio_data
= NULL
;
1300 mutex_unlock(&irq_ptr
->setup_mutex
);
1302 qdio_release_memory(irq_ptr
);
1305 EXPORT_SYMBOL_GPL(qdio_free
);
1308 * qdio_allocate - allocate qdio queues and associated data
1309 * @init_data: initialization data
1311 int qdio_allocate(struct qdio_initialize
*init_data
)
1313 struct qdio_irq
*irq_ptr
;
1315 DBF_EVENT("qallocate:%4x", init_data
->cdev
->private->schid
.sch_no
);
1317 if ((init_data
->no_input_qs
&& !init_data
->input_handler
) ||
1318 (init_data
->no_output_qs
&& !init_data
->output_handler
))
1321 if ((init_data
->no_input_qs
> QDIO_MAX_QUEUES_PER_IRQ
) ||
1322 (init_data
->no_output_qs
> QDIO_MAX_QUEUES_PER_IRQ
))
1325 if ((!init_data
->input_sbal_addr_array
) ||
1326 (!init_data
->output_sbal_addr_array
))
1329 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1330 irq_ptr
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1334 mutex_init(&irq_ptr
->setup_mutex
);
1335 qdio_allocate_dbf(init_data
, irq_ptr
);
1338 * Allocate a page for the chsc calls in qdio_establish.
1339 * Must be pre-allocated since a zfcp recovery will call
1340 * qdio_establish. In case of low memory and swap on a zfcp disk
1341 * we may not be able to allocate memory otherwise.
1343 irq_ptr
->chsc_page
= get_zeroed_page(GFP_KERNEL
);
1344 if (!irq_ptr
->chsc_page
)
1347 /* qdr is used in ccw1.cda which is u32 */
1348 irq_ptr
->qdr
= (struct qdr
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1351 WARN_ON((unsigned long)irq_ptr
->qdr
& 0xfff);
1353 if (qdio_allocate_qs(irq_ptr
, init_data
->no_input_qs
,
1354 init_data
->no_output_qs
))
1357 init_data
->cdev
->private->qdio_data
= irq_ptr
;
1358 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1361 qdio_release_memory(irq_ptr
);
1365 EXPORT_SYMBOL_GPL(qdio_allocate
);
1367 static void qdio_detect_hsicq(struct qdio_irq
*irq_ptr
)
1369 struct qdio_q
*q
= irq_ptr
->input_qs
[0];
1372 if (irq_ptr
->nr_input_qs
> 1 && queue_type(q
) == QDIO_IQDIO_QFMT
)
1375 for_each_output_queue(irq_ptr
, q
, i
) {
1377 if (qdio_enable_async_operation(&q
->u
.out
) < 0) {
1382 qdio_disable_async_operation(&q
->u
.out
);
1384 DBF_EVENT("use_cq:%d", use_cq
);
1388 * qdio_establish - establish queues on a qdio subchannel
1389 * @init_data: initialization data
1391 int qdio_establish(struct qdio_initialize
*init_data
)
1393 struct qdio_irq
*irq_ptr
;
1394 struct ccw_device
*cdev
= init_data
->cdev
;
1395 unsigned long saveflags
;
1398 DBF_EVENT("qestablish:%4x", cdev
->private->schid
.sch_no
);
1400 irq_ptr
= cdev
->private->qdio_data
;
1404 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
1407 mutex_lock(&irq_ptr
->setup_mutex
);
1408 qdio_setup_irq(init_data
);
1410 rc
= qdio_establish_thinint(irq_ptr
);
1412 mutex_unlock(&irq_ptr
->setup_mutex
);
1413 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1418 irq_ptr
->ccw
.cmd_code
= irq_ptr
->equeue
.cmd
;
1419 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1420 irq_ptr
->ccw
.count
= irq_ptr
->equeue
.count
;
1421 irq_ptr
->ccw
.cda
= (u32
)((addr_t
)irq_ptr
->qdr
);
1423 spin_lock_irqsave(get_ccwdev_lock(cdev
), saveflags
);
1424 ccw_device_set_options_mask(cdev
, 0);
1426 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ESTABLISH
, 0, 0);
1428 DBF_ERROR("%4x est IO ERR", irq_ptr
->schid
.sch_no
);
1429 DBF_ERROR("rc:%4x", rc
);
1431 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), saveflags
);
1434 mutex_unlock(&irq_ptr
->setup_mutex
);
1435 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1439 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1440 irq_ptr
->state
== QDIO_IRQ_STATE_ESTABLISHED
||
1441 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
, HZ
);
1443 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ESTABLISHED
) {
1444 mutex_unlock(&irq_ptr
->setup_mutex
);
1445 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1449 qdio_setup_ssqd_info(irq_ptr
);
1450 DBF_EVENT("qib ac:%4x", irq_ptr
->qib
.ac
);
1452 qdio_detect_hsicq(irq_ptr
);
1454 /* qebsm is now setup if available, initialize buffer states */
1455 qdio_init_buf_states(irq_ptr
);
1457 mutex_unlock(&irq_ptr
->setup_mutex
);
1458 qdio_print_subchannel_info(irq_ptr
, cdev
);
1459 qdio_setup_debug_entries(irq_ptr
, cdev
);
1462 EXPORT_SYMBOL_GPL(qdio_establish
);
1465 * qdio_activate - activate queues on a qdio subchannel
1466 * @cdev: associated cdev
1468 int qdio_activate(struct ccw_device
*cdev
)
1470 struct qdio_irq
*irq_ptr
;
1472 unsigned long saveflags
;
1474 DBF_EVENT("qactivate:%4x", cdev
->private->schid
.sch_no
);
1476 irq_ptr
= cdev
->private->qdio_data
;
1480 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
1483 mutex_lock(&irq_ptr
->setup_mutex
);
1484 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1489 irq_ptr
->ccw
.cmd_code
= irq_ptr
->aqueue
.cmd
;
1490 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1491 irq_ptr
->ccw
.count
= irq_ptr
->aqueue
.count
;
1492 irq_ptr
->ccw
.cda
= 0;
1494 spin_lock_irqsave(get_ccwdev_lock(cdev
), saveflags
);
1495 ccw_device_set_options(cdev
, CCWDEV_REPORT_ALL
);
1497 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ACTIVATE
,
1498 0, DOIO_DENY_PREFETCH
);
1500 DBF_ERROR("%4x act IO ERR", irq_ptr
->schid
.sch_no
);
1501 DBF_ERROR("rc:%4x", rc
);
1503 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), saveflags
);
1508 if (is_thinint_irq(irq_ptr
))
1509 tiqdio_add_input_queues(irq_ptr
);
1511 /* wait for subchannel to become active */
1514 switch (irq_ptr
->state
) {
1515 case QDIO_IRQ_STATE_STOPPED
:
1516 case QDIO_IRQ_STATE_ERR
:
1520 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ACTIVE
);
1524 mutex_unlock(&irq_ptr
->setup_mutex
);
1527 EXPORT_SYMBOL_GPL(qdio_activate
);
1529 static inline int buf_in_between(int bufnr
, int start
, int count
)
1531 int end
= add_buf(start
, count
);
1534 if (bufnr
>= start
&& bufnr
< end
)
1540 /* wrap-around case */
1541 if ((bufnr
>= start
&& bufnr
<= QDIO_MAX_BUFFERS_PER_Q
) ||
1549 * handle_inbound - reset processed input buffers
1550 * @q: queue containing the buffers
1552 * @bufnr: first buffer to process
1553 * @count: how many buffers are emptied
1555 static int handle_inbound(struct qdio_q
*q
, unsigned int callflags
,
1556 int bufnr
, int count
)
1560 qperf_inc(q
, inbound_call
);
1562 if (!q
->u
.in
.polling
)
1565 /* protect against stop polling setting an ACK for an emptied slsb */
1566 if (count
== QDIO_MAX_BUFFERS_PER_Q
) {
1567 /* overwriting everything, just delete polling status */
1568 q
->u
.in
.polling
= 0;
1569 q
->u
.in
.ack_count
= 0;
1571 } else if (buf_in_between(q
->u
.in
.ack_start
, bufnr
, count
)) {
1573 /* partial overwrite, just update ack_start */
1574 diff
= add_buf(bufnr
, count
);
1575 diff
= sub_buf(diff
, q
->u
.in
.ack_start
);
1576 q
->u
.in
.ack_count
-= diff
;
1577 if (q
->u
.in
.ack_count
<= 0) {
1578 q
->u
.in
.polling
= 0;
1579 q
->u
.in
.ack_count
= 0;
1582 q
->u
.in
.ack_start
= add_buf(q
->u
.in
.ack_start
, diff
);
1585 /* the only ACK will be deleted, so stop polling */
1586 q
->u
.in
.polling
= 0;
1590 count
= set_buf_states(q
, bufnr
, SLSB_CU_INPUT_EMPTY
, count
);
1592 used
= atomic_add_return(count
, &q
->nr_buf_used
) - count
;
1593 BUG_ON(used
+ count
> QDIO_MAX_BUFFERS_PER_Q
);
1595 if (need_siga_in(q
))
1596 return qdio_siga_input(q
);
1602 * handle_outbound - process filled outbound buffers
1603 * @q: queue containing the buffers
1605 * @bufnr: first buffer to process
1606 * @count: how many buffers are filled
1608 static int handle_outbound(struct qdio_q
*q
, unsigned int callflags
,
1609 int bufnr
, int count
)
1611 unsigned char state
= 0;
1614 qperf_inc(q
, outbound_call
);
1616 count
= set_buf_states(q
, bufnr
, SLSB_CU_OUTPUT_PRIMED
, count
);
1617 used
= atomic_add_return(count
, &q
->nr_buf_used
);
1618 BUG_ON(used
> QDIO_MAX_BUFFERS_PER_Q
);
1620 if (used
== QDIO_MAX_BUFFERS_PER_Q
)
1621 qperf_inc(q
, outbound_queue_full
);
1623 if (callflags
& QDIO_FLAG_PCI_OUT
) {
1624 q
->u
.out
.pci_out_enabled
= 1;
1625 qperf_inc(q
, pci_request_int
);
1627 q
->u
.out
.pci_out_enabled
= 0;
1629 if (queue_type(q
) == QDIO_IQDIO_QFMT
) {
1630 unsigned long phys_aob
= 0;
1632 /* One SIGA-W per buffer required for unicast HSI */
1633 WARN_ON_ONCE(count
> 1 && !multicast_outbound(q
));
1635 phys_aob
= qdio_aob_for_buffer(&q
->u
.out
, bufnr
);
1637 rc
= qdio_kick_outbound_q(q
, phys_aob
);
1638 } else if (need_siga_sync(q
)) {
1639 rc
= qdio_siga_sync_q(q
);
1641 /* try to fast requeue buffers */
1642 get_buf_state(q
, prev_buf(bufnr
), &state
, 0);
1643 if (state
!= SLSB_CU_OUTPUT_PRIMED
)
1644 rc
= qdio_kick_outbound_q(q
, 0);
1646 qperf_inc(q
, fast_requeue
);
1649 /* in case of SIGA errors we must process the error immediately */
1650 if (used
>= q
->u
.out
.scan_threshold
|| rc
)
1651 tasklet_schedule(&q
->tasklet
);
1653 /* free the SBALs in case of no further traffic */
1654 if (!timer_pending(&q
->u
.out
.timer
))
1655 mod_timer(&q
->u
.out
.timer
, jiffies
+ HZ
);
1660 * do_QDIO - process input or output buffers
1661 * @cdev: associated ccw_device for the qdio subchannel
1662 * @callflags: input or output and special flags from the program
1663 * @q_nr: queue number
1664 * @bufnr: buffer number
1665 * @count: how many buffers to process
1667 int do_QDIO(struct ccw_device
*cdev
, unsigned int callflags
,
1668 int q_nr
, unsigned int bufnr
, unsigned int count
)
1670 struct qdio_irq
*irq_ptr
;
1673 if (bufnr
>= QDIO_MAX_BUFFERS_PER_Q
|| count
> QDIO_MAX_BUFFERS_PER_Q
)
1676 irq_ptr
= cdev
->private->qdio_data
;
1680 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
,
1681 "do%02x b:%02x c:%02x", callflags
, bufnr
, count
);
1683 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
)
1687 if (callflags
& QDIO_FLAG_SYNC_INPUT
)
1688 return handle_inbound(irq_ptr
->input_qs
[q_nr
],
1689 callflags
, bufnr
, count
);
1690 else if (callflags
& QDIO_FLAG_SYNC_OUTPUT
)
1691 return handle_outbound(irq_ptr
->output_qs
[q_nr
],
1692 callflags
, bufnr
, count
);
1695 EXPORT_SYMBOL_GPL(do_QDIO
);
1698 * qdio_start_irq - process input buffers
1699 * @cdev: associated ccw_device for the qdio subchannel
1700 * @nr: input queue number
1704 * 1 - irqs not started since new data is available
1706 int qdio_start_irq(struct ccw_device
*cdev
, int nr
)
1709 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1713 q
= irq_ptr
->input_qs
[nr
];
1715 WARN_ON(queue_irqs_enabled(q
));
1718 xchg(q
->irq_ptr
->dsci
, 0);
1720 qdio_stop_polling(q
);
1721 clear_bit(QDIO_QUEUE_IRQS_DISABLED
, &q
->u
.in
.queue_irq_state
);
1724 * We need to check again to not lose initiative after
1725 * resetting the ACK state.
1727 if (!shared_ind(q
) && *q
->irq_ptr
->dsci
)
1729 if (!qdio_inbound_q_done(q
))
1734 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1735 &q
->u
.in
.queue_irq_state
))
1741 EXPORT_SYMBOL(qdio_start_irq
);
1744 * qdio_get_next_buffers - process input buffers
1745 * @cdev: associated ccw_device for the qdio subchannel
1746 * @nr: input queue number
1747 * @bufnr: first filled buffer number
1748 * @error: buffers are in error state
1752 * = 0 - no new buffers found
1753 * > 0 - number of processed buffers
1755 int qdio_get_next_buffers(struct ccw_device
*cdev
, int nr
, int *bufnr
,
1760 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1764 q
= irq_ptr
->input_qs
[nr
];
1765 WARN_ON(queue_irqs_enabled(q
));
1768 * Cannot rely on automatic sync after interrupt since queues may
1769 * also be examined without interrupt.
1771 if (need_siga_sync(q
))
1772 qdio_sync_queues(q
);
1774 /* check the PCI capable outbound queues. */
1775 qdio_check_outbound_after_thinint(q
);
1777 if (!qdio_inbound_q_moved(q
))
1780 /* Note: upper-layer MUST stop processing immediately here ... */
1781 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
1784 start
= q
->first_to_kick
;
1785 end
= q
->first_to_check
;
1787 *error
= q
->qdio_error
;
1789 /* for the next time */
1790 q
->first_to_kick
= end
;
1792 return sub_buf(end
, start
);
1794 EXPORT_SYMBOL(qdio_get_next_buffers
);
1797 * qdio_stop_irq - disable interrupt processing for the device
1798 * @cdev: associated ccw_device for the qdio subchannel
1799 * @nr: input queue number
1802 * 0 - interrupts were already disabled
1803 * 1 - interrupts successfully disabled
1805 int qdio_stop_irq(struct ccw_device
*cdev
, int nr
)
1808 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1812 q
= irq_ptr
->input_qs
[nr
];
1814 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1815 &q
->u
.in
.queue_irq_state
))
1820 EXPORT_SYMBOL(qdio_stop_irq
);
1822 static int __init
init_QDIO(void)
1826 rc
= qdio_debug_init();
1829 rc
= qdio_setup_init();
1832 rc
= tiqdio_allocate_memory();
1835 rc
= tiqdio_register_thinints();
1841 tiqdio_free_memory();
1849 static void __exit
exit_QDIO(void)
1851 tiqdio_unregister_thinints();
1852 tiqdio_free_memory();
1857 module_init(init_QDIO
);
1858 module_exit(exit_QDIO
);