2 * Linux for s390 qdio support, buffer handling, qdio API and module support.
4 * Copyright IBM Corp. 2000, 2008
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
6 * Jan Glauber <jang@linux.vnet.ibm.com>
7 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/timer.h>
13 #include <linux/delay.h>
14 #include <linux/gfp.h>
16 #include <linux/atomic.h>
17 #include <asm/debug.h>
25 #include "qdio_debug.h"
27 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
28 "Jan Glauber <jang@linux.vnet.ibm.com>");
29 MODULE_DESCRIPTION("QDIO base support");
30 MODULE_LICENSE("GPL");
32 static inline int do_siga_sync(unsigned long schid
,
33 unsigned int out_mask
, unsigned int in_mask
,
36 register unsigned long __fc
asm ("0") = fc
;
37 register unsigned long __schid
asm ("1") = schid
;
38 register unsigned long out
asm ("2") = out_mask
;
39 register unsigned long in
asm ("3") = in_mask
;
47 : "d" (__fc
), "d" (__schid
), "d" (out
), "d" (in
) : "cc");
51 static inline int do_siga_input(unsigned long schid
, unsigned int mask
,
54 register unsigned long __fc
asm ("0") = fc
;
55 register unsigned long __schid
asm ("1") = schid
;
56 register unsigned long __mask
asm ("2") = mask
;
64 : "d" (__fc
), "d" (__schid
), "d" (__mask
) : "cc");
69 * do_siga_output - perform SIGA-w/wt function
70 * @schid: subchannel id or in case of QEBSM the subchannel token
71 * @mask: which output queues to process
72 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
73 * @fc: function code to perform
75 * Returns condition code.
76 * Note: For IQDC unicast queues only the highest priority queue is processed.
78 static inline int do_siga_output(unsigned long schid
, unsigned long mask
,
79 unsigned int *bb
, unsigned int fc
,
82 register unsigned long __fc
asm("0") = fc
;
83 register unsigned long __schid
asm("1") = schid
;
84 register unsigned long __mask
asm("2") = mask
;
85 register unsigned long __aob
asm("3") = aob
;
92 : "=d" (cc
), "+d" (__fc
), "+d" (__aob
)
93 : "d" (__schid
), "d" (__mask
)
99 static inline int qdio_check_ccq(struct qdio_q
*q
, unsigned int ccq
)
101 /* all done or next buffer state different */
102 if (ccq
== 0 || ccq
== 32)
104 /* no buffer processed */
107 /* not all buffers processed */
110 /* notify devices immediately */
111 DBF_ERROR("%4x ccq:%3d", SCH_NO(q
), ccq
);
116 * qdio_do_eqbs - extract buffer states for QEBSM
117 * @q: queue to manipulate
118 * @state: state of the extracted buffers
119 * @start: buffer number to start at
120 * @count: count of buffers to examine
121 * @auto_ack: automatically acknowledge buffers
123 * Returns the number of successfully extracted equal buffer states.
124 * Stops processing if a state is different from the last buffers state.
126 static int qdio_do_eqbs(struct qdio_q
*q
, unsigned char *state
,
127 int start
, int count
, int auto_ack
)
129 int rc
, tmp_count
= count
, tmp_start
= start
, nr
= q
->nr
, retried
= 0;
130 unsigned int ccq
= 0;
135 nr
+= q
->irq_ptr
->nr_input_qs
;
137 ccq
= do_eqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
,
139 rc
= qdio_check_ccq(q
, ccq
);
141 return count
- tmp_count
;
144 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "EQBS again:%2d", ccq
);
149 qperf_inc(q
, eqbs_partial
);
150 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "EQBS part:%02x",
153 * Retry once, if that fails bail out and process the
154 * extracted buffers before trying again.
159 return count
- tmp_count
;
162 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q
));
163 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
164 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_GET_BUF_STATE
,
165 q
->nr
, q
->first_to_kick
, count
, q
->irq_ptr
->int_parm
);
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
;
193 nr
+= q
->irq_ptr
->nr_input_qs
;
195 ccq
= do_sqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
);
196 rc
= qdio_check_ccq(q
, ccq
);
198 WARN_ON_ONCE(tmp_count
);
199 return count
- tmp_count
;
202 if (rc
== 1 || rc
== 2) {
203 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "SQBS again:%2d", ccq
);
204 qperf_inc(q
, sqbs_partial
);
208 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q
));
209 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
210 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_SET_BUF_STATE
,
211 q
->nr
, q
->first_to_kick
, count
, q
->irq_ptr
->int_parm
);
215 /* returns number of examined buffers and their common state in *state */
216 static inline int get_buf_states(struct qdio_q
*q
, unsigned int bufnr
,
217 unsigned char *state
, unsigned int count
,
218 int auto_ack
, int merge_pending
)
220 unsigned char __state
= 0;
224 return qdio_do_eqbs(q
, state
, bufnr
, count
, auto_ack
);
226 for (i
= 0; i
< count
; i
++) {
228 __state
= q
->slsb
.val
[bufnr
];
229 if (merge_pending
&& __state
== SLSB_P_OUTPUT_PENDING
)
230 __state
= SLSB_P_OUTPUT_EMPTY
;
231 } else if (merge_pending
) {
232 if ((q
->slsb
.val
[bufnr
] & __state
) != __state
)
234 } else if (q
->slsb
.val
[bufnr
] != __state
)
236 bufnr
= next_buf(bufnr
);
242 static inline int get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
243 unsigned char *state
, int auto_ack
)
245 return get_buf_states(q
, bufnr
, state
, 1, auto_ack
, 0);
248 /* wrap-around safe setting of slsb states, returns number of changed buffers */
249 static inline int set_buf_states(struct qdio_q
*q
, int bufnr
,
250 unsigned char state
, int count
)
255 return qdio_do_sqbs(q
, state
, bufnr
, count
);
257 for (i
= 0; i
< count
; i
++) {
258 xchg(&q
->slsb
.val
[bufnr
], state
);
259 bufnr
= next_buf(bufnr
);
264 static inline int set_buf_state(struct qdio_q
*q
, int bufnr
,
267 return set_buf_states(q
, bufnr
, state
, 1);
270 /* set slsb states to initial state */
271 static void qdio_init_buf_states(struct qdio_irq
*irq_ptr
)
276 for_each_input_queue(irq_ptr
, q
, i
)
277 set_buf_states(q
, 0, SLSB_P_INPUT_NOT_INIT
,
278 QDIO_MAX_BUFFERS_PER_Q
);
279 for_each_output_queue(irq_ptr
, q
, i
)
280 set_buf_states(q
, 0, SLSB_P_OUTPUT_NOT_INIT
,
281 QDIO_MAX_BUFFERS_PER_Q
);
284 static inline int qdio_siga_sync(struct qdio_q
*q
, unsigned int output
,
287 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
288 unsigned int fc
= QDIO_SIGA_SYNC
;
291 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-s:%1d", q
->nr
);
292 qperf_inc(q
, siga_sync
);
295 schid
= q
->irq_ptr
->sch_token
;
296 fc
|= QDIO_SIGA_QEBSM_FLAG
;
299 cc
= do_siga_sync(schid
, output
, input
, fc
);
301 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q
), cc
);
302 return (cc
) ? -EIO
: 0;
305 static inline int qdio_siga_sync_q(struct qdio_q
*q
)
308 return qdio_siga_sync(q
, 0, q
->mask
);
310 return qdio_siga_sync(q
, q
->mask
, 0);
313 static int qdio_siga_output(struct qdio_q
*q
, unsigned int *busy_bit
,
316 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
317 unsigned int fc
= QDIO_SIGA_WRITE
;
320 unsigned long laob
= 0;
322 if (q
->u
.out
.use_cq
&& aob
!= 0) {
323 fc
= QDIO_SIGA_WRITEQ
;
328 schid
= q
->irq_ptr
->sch_token
;
329 fc
|= QDIO_SIGA_QEBSM_FLAG
;
332 WARN_ON_ONCE((aob
&& queue_type(q
) != QDIO_IQDIO_QFMT
) ||
333 (aob
&& fc
!= QDIO_SIGA_WRITEQ
));
334 cc
= do_siga_output(schid
, q
->mask
, busy_bit
, fc
, laob
);
336 /* hipersocket busy condition */
337 if (unlikely(*busy_bit
)) {
341 start_time
= get_tod_clock();
344 if ((get_tod_clock() - start_time
) < QDIO_BUSY_BIT_PATIENCE
)
348 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
,
349 "%4x cc2 BB1:%1d", SCH_NO(q
), q
->nr
);
350 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "count:%u", retries
);
355 static inline int qdio_siga_input(struct qdio_q
*q
)
357 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
358 unsigned int fc
= QDIO_SIGA_READ
;
361 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-r:%1d", q
->nr
);
362 qperf_inc(q
, siga_read
);
365 schid
= q
->irq_ptr
->sch_token
;
366 fc
|= QDIO_SIGA_QEBSM_FLAG
;
369 cc
= do_siga_input(schid
, q
->mask
, fc
);
371 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q
), cc
);
372 return (cc
) ? -EIO
: 0;
375 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
376 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
378 static inline void qdio_sync_queues(struct qdio_q
*q
)
380 /* PCI capable outbound queues will also be scanned so sync them too */
381 if (pci_out_supported(q
))
382 qdio_siga_sync_all(q
);
387 int debug_get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
388 unsigned char *state
)
390 if (need_siga_sync(q
))
392 return get_buf_states(q
, bufnr
, state
, 1, 0, 0);
395 static inline void qdio_stop_polling(struct qdio_q
*q
)
397 if (!q
->u
.in
.polling
)
401 qperf_inc(q
, stop_polling
);
403 /* show the card that we are not polling anymore */
405 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
407 q
->u
.in
.ack_count
= 0;
409 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
412 static inline void account_sbals(struct qdio_q
*q
, int count
)
416 q
->q_stats
.nr_sbal_total
+= count
;
417 if (count
== QDIO_MAX_BUFFERS_MASK
) {
418 q
->q_stats
.nr_sbals
[7]++;
423 q
->q_stats
.nr_sbals
[pos
]++;
426 static void process_buffer_error(struct qdio_q
*q
, int count
)
428 unsigned char state
= (q
->is_input_q
) ? SLSB_P_INPUT_NOT_INIT
:
429 SLSB_P_OUTPUT_NOT_INIT
;
431 q
->qdio_error
= QDIO_ERROR_SLSB_STATE
;
433 /* special handling for no target buffer empty */
434 if ((!q
->is_input_q
&&
435 (q
->sbal
[q
->first_to_check
]->element
[15].sflags
) == 0x10)) {
436 qperf_inc(q
, target_full
);
437 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "OUTFULL FTC:%02x",
442 DBF_ERROR("%4x BUF ERROR", SCH_NO(q
));
443 DBF_ERROR((q
->is_input_q
) ? "IN:%2d" : "OUT:%2d", q
->nr
);
444 DBF_ERROR("FTC:%3d C:%3d", q
->first_to_check
, count
);
445 DBF_ERROR("F14:%2x F15:%2x",
446 q
->sbal
[q
->first_to_check
]->element
[14].sflags
,
447 q
->sbal
[q
->first_to_check
]->element
[15].sflags
);
451 * Interrupts may be avoided as long as the error is present
452 * so change the buffer state immediately to avoid starvation.
454 set_buf_states(q
, q
->first_to_check
, state
, count
);
457 static inline void inbound_primed(struct qdio_q
*q
, int count
)
461 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in prim: %02x", count
);
463 /* for QEBSM the ACK was already set by EQBS */
465 if (!q
->u
.in
.polling
) {
467 q
->u
.in
.ack_count
= count
;
468 q
->u
.in
.ack_start
= q
->first_to_check
;
472 /* delete the previous ACK's */
473 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
475 q
->u
.in
.ack_count
= count
;
476 q
->u
.in
.ack_start
= q
->first_to_check
;
481 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
482 * or by the next inbound run.
484 new = add_buf(q
->first_to_check
, count
- 1);
485 if (q
->u
.in
.polling
) {
486 /* reset the previous ACK but first set the new one */
487 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
488 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
491 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
494 q
->u
.in
.ack_start
= new;
498 /* need to change ALL buffers to get more interrupts */
499 set_buf_states(q
, q
->first_to_check
, SLSB_P_INPUT_NOT_INIT
, count
);
502 static int get_inbound_buffer_frontier(struct qdio_q
*q
)
505 unsigned char state
= 0;
507 q
->timestamp
= get_tod_clock();
510 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
513 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
514 stop
= add_buf(q
->first_to_check
, count
);
516 if (q
->first_to_check
== stop
)
520 * No siga sync here, as a PCI or we after a thin interrupt
521 * already sync'ed the queues.
523 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 1, 0);
528 case SLSB_P_INPUT_PRIMED
:
529 inbound_primed(q
, count
);
530 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
531 if (atomic_sub(count
, &q
->nr_buf_used
) == 0)
532 qperf_inc(q
, inbound_queue_full
);
533 if (q
->irq_ptr
->perf_stat_enabled
)
534 account_sbals(q
, count
);
536 case SLSB_P_INPUT_ERROR
:
537 process_buffer_error(q
, count
);
538 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
539 atomic_sub(count
, &q
->nr_buf_used
);
540 if (q
->irq_ptr
->perf_stat_enabled
)
541 account_sbals_error(q
, count
);
543 case SLSB_CU_INPUT_EMPTY
:
544 case SLSB_P_INPUT_NOT_INIT
:
545 case SLSB_P_INPUT_ACK
:
546 if (q
->irq_ptr
->perf_stat_enabled
)
547 q
->q_stats
.nr_sbal_nop
++;
548 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in nop");
554 return q
->first_to_check
;
557 static int qdio_inbound_q_moved(struct qdio_q
*q
)
561 bufnr
= get_inbound_buffer_frontier(q
);
563 if (bufnr
!= q
->last_move
) {
564 q
->last_move
= bufnr
;
565 if (!is_thinint_irq(q
->irq_ptr
) && MACHINE_IS_LPAR
)
566 q
->u
.in
.timestamp
= get_tod_clock();
572 static inline int qdio_inbound_q_done(struct qdio_q
*q
)
574 unsigned char state
= 0;
576 if (!atomic_read(&q
->nr_buf_used
))
579 if (need_siga_sync(q
))
581 get_buf_state(q
, q
->first_to_check
, &state
, 0);
583 if (state
== SLSB_P_INPUT_PRIMED
|| state
== SLSB_P_INPUT_ERROR
)
584 /* more work coming */
587 if (is_thinint_irq(q
->irq_ptr
))
590 /* don't poll under z/VM */
595 * At this point we know, that inbound first_to_check
596 * has (probably) not moved (see qdio_inbound_processing).
598 if (get_tod_clock() > q
->u
.in
.timestamp
+ QDIO_INPUT_THRESHOLD
) {
599 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in done:%02x",
606 static inline int contains_aobs(struct qdio_q
*q
)
608 return !q
->is_input_q
&& q
->u
.out
.use_cq
;
611 static inline void qdio_trace_aob(struct qdio_irq
*irq
, struct qdio_q
*q
,
612 int i
, struct qaob
*aob
)
616 DBF_DEV_EVENT(DBF_INFO
, irq
, "AOB%d:%lx", i
,
617 (unsigned long) virt_to_phys(aob
));
618 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES00:%lx",
619 (unsigned long) aob
->res0
[0]);
620 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES01:%lx",
621 (unsigned long) aob
->res0
[1]);
622 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES02:%lx",
623 (unsigned long) aob
->res0
[2]);
624 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES03:%lx",
625 (unsigned long) aob
->res0
[3]);
626 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES04:%lx",
627 (unsigned long) aob
->res0
[4]);
628 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES05:%lx",
629 (unsigned long) aob
->res0
[5]);
630 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES1:%x", aob
->res1
);
631 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES2:%x", aob
->res2
);
632 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES3:%x", aob
->res3
);
633 DBF_DEV_EVENT(DBF_INFO
, irq
, "AORC:%u", aob
->aorc
);
634 DBF_DEV_EVENT(DBF_INFO
, irq
, "FLAGS:%u", aob
->flags
);
635 DBF_DEV_EVENT(DBF_INFO
, irq
, "CBTBS:%u", aob
->cbtbs
);
636 DBF_DEV_EVENT(DBF_INFO
, irq
, "SBC:%u", aob
->sb_count
);
637 for (tmp
= 0; tmp
< QDIO_MAX_ELEMENTS_PER_BUFFER
; ++tmp
) {
638 DBF_DEV_EVENT(DBF_INFO
, irq
, "SBA%d:%lx", tmp
,
639 (unsigned long) aob
->sba
[tmp
]);
640 DBF_DEV_EVENT(DBF_INFO
, irq
, "rSBA%d:%lx", tmp
,
641 (unsigned long) q
->sbal
[i
]->element
[tmp
].addr
);
642 DBF_DEV_EVENT(DBF_INFO
, irq
, "DC%d:%u", tmp
, aob
->dcount
[tmp
]);
643 DBF_DEV_EVENT(DBF_INFO
, irq
, "rDC%d:%u", tmp
,
644 q
->sbal
[i
]->element
[tmp
].length
);
646 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER0:%lx", (unsigned long) aob
->user0
);
647 for (tmp
= 0; tmp
< 2; ++tmp
) {
648 DBF_DEV_EVENT(DBF_INFO
, irq
, "RES4%d:%lx", tmp
,
649 (unsigned long) aob
->res4
[tmp
]);
651 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER1:%lx", (unsigned long) aob
->user1
);
652 DBF_DEV_EVENT(DBF_INFO
, irq
, "USER2:%lx", (unsigned long) aob
->user2
);
655 static inline void qdio_handle_aobs(struct qdio_q
*q
, int start
, int count
)
657 unsigned char state
= 0;
660 if (!contains_aobs(q
))
663 for (j
= 0; j
< count
; ++j
) {
664 get_buf_state(q
, b
, &state
, 0);
665 if (state
== SLSB_P_OUTPUT_PENDING
) {
666 struct qaob
*aob
= q
->u
.out
.aobs
[b
];
670 q
->u
.out
.sbal_state
[b
].flags
|=
671 QDIO_OUTBUF_STATE_FLAG_PENDING
;
672 q
->u
.out
.aobs
[b
] = NULL
;
673 } else if (state
== SLSB_P_OUTPUT_EMPTY
) {
674 q
->u
.out
.sbal_state
[b
].aob
= NULL
;
680 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q
*q
,
683 unsigned long phys_aob
= 0;
688 if (!q
->aobs
[bufnr
]) {
689 struct qaob
*aob
= qdio_allocate_aob();
690 q
->aobs
[bufnr
] = aob
;
692 if (q
->aobs
[bufnr
]) {
693 q
->sbal_state
[bufnr
].flags
= QDIO_OUTBUF_STATE_FLAG_NONE
;
694 q
->sbal_state
[bufnr
].aob
= q
->aobs
[bufnr
];
695 q
->aobs
[bufnr
]->user1
= (u64
) q
->sbal_state
[bufnr
].user
;
696 phys_aob
= virt_to_phys(q
->aobs
[bufnr
]);
697 WARN_ON_ONCE(phys_aob
& 0xFF);
704 static void qdio_kick_handler(struct qdio_q
*q
)
706 int start
= q
->first_to_kick
;
707 int end
= q
->first_to_check
;
710 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
713 count
= sub_buf(end
, start
);
716 qperf_inc(q
, inbound_handler
);
717 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "kih s:%02x c:%02x", start
, count
);
719 qperf_inc(q
, outbound_handler
);
720 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "koh: s:%02x c:%02x",
724 qdio_handle_aobs(q
, start
, count
);
726 q
->handler(q
->irq_ptr
->cdev
, q
->qdio_error
, q
->nr
, start
, count
,
727 q
->irq_ptr
->int_parm
);
729 /* for the next time */
730 q
->first_to_kick
= end
;
734 static void __qdio_inbound_processing(struct qdio_q
*q
)
736 qperf_inc(q
, tasklet_inbound
);
738 if (!qdio_inbound_q_moved(q
))
741 qdio_kick_handler(q
);
743 if (!qdio_inbound_q_done(q
)) {
744 /* means poll time is not yet over */
745 qperf_inc(q
, tasklet_inbound_resched
);
746 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
)) {
747 tasklet_schedule(&q
->tasklet
);
752 qdio_stop_polling(q
);
754 * We need to check again to not lose initiative after
755 * resetting the ACK state.
757 if (!qdio_inbound_q_done(q
)) {
758 qperf_inc(q
, tasklet_inbound_resched2
);
759 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
))
760 tasklet_schedule(&q
->tasklet
);
764 void qdio_inbound_processing(unsigned long data
)
766 struct qdio_q
*q
= (struct qdio_q
*)data
;
767 __qdio_inbound_processing(q
);
770 static int get_outbound_buffer_frontier(struct qdio_q
*q
)
773 unsigned char state
= 0;
775 q
->timestamp
= get_tod_clock();
777 if (need_siga_sync(q
))
778 if (((queue_type(q
) != QDIO_IQDIO_QFMT
) &&
779 !pci_out_supported(q
)) ||
780 (queue_type(q
) == QDIO_IQDIO_QFMT
&&
781 multicast_outbound(q
)))
785 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
788 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
789 stop
= add_buf(q
->first_to_check
, count
);
790 if (q
->first_to_check
== stop
)
793 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 0, 1);
798 case SLSB_P_OUTPUT_EMPTY
:
799 /* the adapter got it */
800 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
,
801 "out empty:%1d %02x", q
->nr
, count
);
803 atomic_sub(count
, &q
->nr_buf_used
);
804 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
805 if (q
->irq_ptr
->perf_stat_enabled
)
806 account_sbals(q
, count
);
809 case SLSB_P_OUTPUT_ERROR
:
810 process_buffer_error(q
, count
);
811 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
812 atomic_sub(count
, &q
->nr_buf_used
);
813 if (q
->irq_ptr
->perf_stat_enabled
)
814 account_sbals_error(q
, count
);
816 case SLSB_CU_OUTPUT_PRIMED
:
817 /* the adapter has not fetched the output yet */
818 if (q
->irq_ptr
->perf_stat_enabled
)
819 q
->q_stats
.nr_sbal_nop
++;
820 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out primed:%1d",
823 case SLSB_P_OUTPUT_NOT_INIT
:
824 case SLSB_P_OUTPUT_HALTED
:
831 return q
->first_to_check
;
834 /* all buffers processed? */
835 static inline int qdio_outbound_q_done(struct qdio_q
*q
)
837 return atomic_read(&q
->nr_buf_used
) == 0;
840 static inline int qdio_outbound_q_moved(struct qdio_q
*q
)
844 bufnr
= get_outbound_buffer_frontier(q
);
846 if (bufnr
!= q
->last_move
) {
847 q
->last_move
= bufnr
;
848 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out moved:%1d", q
->nr
);
854 static int qdio_kick_outbound_q(struct qdio_q
*q
, unsigned long aob
)
857 unsigned int busy_bit
;
859 if (!need_siga_out(q
))
862 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w:%1d", q
->nr
);
864 qperf_inc(q
, siga_write
);
866 cc
= qdio_siga_output(q
, &busy_bit
, aob
);
872 while (++retries
< QDIO_BUSY_BIT_RETRIES
) {
873 mdelay(QDIO_BUSY_BIT_RETRY_DELAY
);
876 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q
), q
->nr
);
879 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w cc2:%1d", q
->nr
);
885 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q
), cc
);
890 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q
), q
->nr
);
891 DBF_ERROR("count:%u", retries
);
896 static void __qdio_outbound_processing(struct qdio_q
*q
)
898 qperf_inc(q
, tasklet_outbound
);
899 WARN_ON_ONCE(atomic_read(&q
->nr_buf_used
) < 0);
901 if (qdio_outbound_q_moved(q
))
902 qdio_kick_handler(q
);
904 if (queue_type(q
) == QDIO_ZFCP_QFMT
)
905 if (!pci_out_supported(q
) && !qdio_outbound_q_done(q
))
908 if (q
->u
.out
.pci_out_enabled
)
912 * Now we know that queue type is either qeth without pci enabled
913 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
914 * is noticed and outbound_handler is called after some time.
916 if (qdio_outbound_q_done(q
))
917 del_timer(&q
->u
.out
.timer
);
919 if (!timer_pending(&q
->u
.out
.timer
))
920 mod_timer(&q
->u
.out
.timer
, jiffies
+ 10 * HZ
);
924 if (unlikely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
926 tasklet_schedule(&q
->tasklet
);
929 /* outbound tasklet */
930 void qdio_outbound_processing(unsigned long data
)
932 struct qdio_q
*q
= (struct qdio_q
*)data
;
933 __qdio_outbound_processing(q
);
936 void qdio_outbound_timer(unsigned long data
)
938 struct qdio_q
*q
= (struct qdio_q
*)data
;
940 if (unlikely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
942 tasklet_schedule(&q
->tasklet
);
945 static inline void qdio_check_outbound_after_thinint(struct qdio_q
*q
)
950 if (!pci_out_supported(q
))
953 for_each_output_queue(q
->irq_ptr
, out
, i
)
954 if (!qdio_outbound_q_done(out
))
955 tasklet_schedule(&out
->tasklet
);
958 static void __tiqdio_inbound_processing(struct qdio_q
*q
)
960 qperf_inc(q
, tasklet_inbound
);
961 if (need_siga_sync(q
) && need_siga_sync_after_ai(q
))
965 * The interrupt could be caused by a PCI request. Check the
966 * PCI capable outbound queues.
968 qdio_check_outbound_after_thinint(q
);
970 if (!qdio_inbound_q_moved(q
))
973 qdio_kick_handler(q
);
975 if (!qdio_inbound_q_done(q
)) {
976 qperf_inc(q
, tasklet_inbound_resched
);
977 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
)) {
978 tasklet_schedule(&q
->tasklet
);
983 qdio_stop_polling(q
);
985 * We need to check again to not lose initiative after
986 * resetting the ACK state.
988 if (!qdio_inbound_q_done(q
)) {
989 qperf_inc(q
, tasklet_inbound_resched2
);
990 if (likely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_STOPPED
))
991 tasklet_schedule(&q
->tasklet
);
995 void tiqdio_inbound_processing(unsigned long data
)
997 struct qdio_q
*q
= (struct qdio_q
*)data
;
998 __tiqdio_inbound_processing(q
);
1001 static inline void qdio_set_state(struct qdio_irq
*irq_ptr
,
1002 enum qdio_irq_states state
)
1004 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "newstate: %1d", state
);
1006 irq_ptr
->state
= state
;
1010 static void qdio_irq_check_sense(struct qdio_irq
*irq_ptr
, struct irb
*irb
)
1012 if (irb
->esw
.esw0
.erw
.cons
) {
1013 DBF_ERROR("%4x sense:", irq_ptr
->schid
.sch_no
);
1014 DBF_ERROR_HEX(irb
, 64);
1015 DBF_ERROR_HEX(irb
->ecw
, 64);
1019 /* PCI interrupt handler */
1020 static void qdio_int_handler_pci(struct qdio_irq
*irq_ptr
)
1025 if (unlikely(irq_ptr
->state
== QDIO_IRQ_STATE_STOPPED
))
1028 for_each_input_queue(irq_ptr
, q
, i
) {
1029 if (q
->u
.in
.queue_start_poll
) {
1030 /* skip if polling is enabled or already in work */
1031 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1032 &q
->u
.in
.queue_irq_state
)) {
1033 qperf_inc(q
, int_discarded
);
1036 q
->u
.in
.queue_start_poll(q
->irq_ptr
->cdev
, q
->nr
,
1037 q
->irq_ptr
->int_parm
);
1039 tasklet_schedule(&q
->tasklet
);
1043 if (!pci_out_supported(q
))
1046 for_each_output_queue(irq_ptr
, q
, i
) {
1047 if (qdio_outbound_q_done(q
))
1049 if (need_siga_sync(q
) && need_siga_sync_out_after_pci(q
))
1050 qdio_siga_sync_q(q
);
1051 tasklet_schedule(&q
->tasklet
);
1055 static void qdio_handle_activate_check(struct ccw_device
*cdev
,
1056 unsigned long intparm
, int cstat
, int dstat
)
1058 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1062 DBF_ERROR("%4x ACT CHECK", irq_ptr
->schid
.sch_no
);
1063 DBF_ERROR("intp :%lx", intparm
);
1064 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1066 if (irq_ptr
->nr_input_qs
) {
1067 q
= irq_ptr
->input_qs
[0];
1068 } else if (irq_ptr
->nr_output_qs
) {
1069 q
= irq_ptr
->output_qs
[0];
1075 count
= sub_buf(q
->first_to_check
, q
->first_to_kick
);
1076 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_ACTIVATE
,
1077 q
->nr
, q
->first_to_kick
, count
, irq_ptr
->int_parm
);
1079 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1081 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1082 * Therefore we call the LGR detection function here.
1087 static void qdio_establish_handle_irq(struct ccw_device
*cdev
, int cstat
,
1090 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1092 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "qest irq");
1096 if (dstat
& ~(DEV_STAT_DEV_END
| DEV_STAT_CHN_END
))
1098 if (!(dstat
& DEV_STAT_DEV_END
))
1100 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ESTABLISHED
);
1104 DBF_ERROR("%4x EQ:error", irq_ptr
->schid
.sch_no
);
1105 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1106 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1109 /* qdio interrupt handler */
1110 void qdio_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1113 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1116 if (!intparm
|| !irq_ptr
) {
1117 DBF_ERROR("qint:%4x", cdev
->private->schid
.sch_no
);
1121 if (irq_ptr
->perf_stat_enabled
)
1122 irq_ptr
->perf_stat
.qdio_int
++;
1125 DBF_ERROR("%4x IO error", irq_ptr
->schid
.sch_no
);
1126 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1127 wake_up(&cdev
->private->wait_q
);
1130 qdio_irq_check_sense(irq_ptr
, irb
);
1131 cstat
= irb
->scsw
.cmd
.cstat
;
1132 dstat
= irb
->scsw
.cmd
.dstat
;
1134 switch (irq_ptr
->state
) {
1135 case QDIO_IRQ_STATE_INACTIVE
:
1136 qdio_establish_handle_irq(cdev
, cstat
, dstat
);
1138 case QDIO_IRQ_STATE_CLEANUP
:
1139 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1141 case QDIO_IRQ_STATE_ESTABLISHED
:
1142 case QDIO_IRQ_STATE_ACTIVE
:
1143 if (cstat
& SCHN_STAT_PCI
) {
1144 qdio_int_handler_pci(irq_ptr
);
1148 qdio_handle_activate_check(cdev
, intparm
, cstat
,
1151 case QDIO_IRQ_STATE_STOPPED
:
1156 wake_up(&cdev
->private->wait_q
);
1160 * qdio_get_ssqd_desc - get qdio subchannel description
1161 * @cdev: ccw device to get description for
1162 * @data: where to store the ssqd
1164 * Returns 0 or an error code. The results of the chsc are stored in the
1165 * specified structure.
1167 int qdio_get_ssqd_desc(struct ccw_device
*cdev
,
1168 struct qdio_ssqd_desc
*data
)
1171 if (!cdev
|| !cdev
->private)
1174 DBF_EVENT("get ssqd:%4x", cdev
->private->schid
.sch_no
);
1175 return qdio_setup_get_ssqd(NULL
, &cdev
->private->schid
, data
);
1177 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc
);
1179 static void qdio_shutdown_queues(struct ccw_device
*cdev
)
1181 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1185 for_each_input_queue(irq_ptr
, q
, i
)
1186 tasklet_kill(&q
->tasklet
);
1188 for_each_output_queue(irq_ptr
, q
, i
) {
1189 del_timer(&q
->u
.out
.timer
);
1190 tasklet_kill(&q
->tasklet
);
1195 * qdio_shutdown - shut down a qdio subchannel
1196 * @cdev: associated ccw device
1197 * @how: use halt or clear to shutdown
1199 int qdio_shutdown(struct ccw_device
*cdev
, int how
)
1201 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1203 unsigned long flags
;
1208 WARN_ON_ONCE(irqs_disabled());
1209 DBF_EVENT("qshutdown:%4x", cdev
->private->schid
.sch_no
);
1211 mutex_lock(&irq_ptr
->setup_mutex
);
1213 * Subchannel was already shot down. We cannot prevent being called
1214 * twice since cio may trigger a shutdown asynchronously.
1216 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1217 mutex_unlock(&irq_ptr
->setup_mutex
);
1222 * Indicate that the device is going down. Scheduling the queue
1223 * tasklets is forbidden from here on.
1225 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1227 tiqdio_remove_input_queues(irq_ptr
);
1228 qdio_shutdown_queues(cdev
);
1229 qdio_shutdown_debug_entries(irq_ptr
);
1231 /* cleanup subchannel */
1232 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
1234 if (how
& QDIO_FLAG_CLEANUP_USING_CLEAR
)
1235 rc
= ccw_device_clear(cdev
, QDIO_DOING_CLEANUP
);
1237 /* default behaviour is halt */
1238 rc
= ccw_device_halt(cdev
, QDIO_DOING_CLEANUP
);
1240 DBF_ERROR("%4x SHUTD ERR", irq_ptr
->schid
.sch_no
);
1241 DBF_ERROR("rc:%4d", rc
);
1245 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_CLEANUP
);
1246 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
1247 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1248 irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
||
1249 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
,
1251 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
1254 qdio_shutdown_thinint(irq_ptr
);
1256 /* restore interrupt handler */
1257 if ((void *)cdev
->handler
== (void *)qdio_int_handler
)
1258 cdev
->handler
= irq_ptr
->orig_handler
;
1259 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
1261 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1262 mutex_unlock(&irq_ptr
->setup_mutex
);
1267 EXPORT_SYMBOL_GPL(qdio_shutdown
);
1270 * qdio_free - free data structures for a qdio subchannel
1271 * @cdev: associated ccw device
1273 int qdio_free(struct ccw_device
*cdev
)
1275 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1280 DBF_EVENT("qfree:%4x", cdev
->private->schid
.sch_no
);
1281 mutex_lock(&irq_ptr
->setup_mutex
);
1283 if (irq_ptr
->debug_area
!= NULL
) {
1284 debug_unregister(irq_ptr
->debug_area
);
1285 irq_ptr
->debug_area
= NULL
;
1287 cdev
->private->qdio_data
= NULL
;
1288 mutex_unlock(&irq_ptr
->setup_mutex
);
1290 qdio_release_memory(irq_ptr
);
1293 EXPORT_SYMBOL_GPL(qdio_free
);
1296 * qdio_allocate - allocate qdio queues and associated data
1297 * @init_data: initialization data
1299 int qdio_allocate(struct qdio_initialize
*init_data
)
1301 struct qdio_irq
*irq_ptr
;
1303 DBF_EVENT("qallocate:%4x", init_data
->cdev
->private->schid
.sch_no
);
1305 if ((init_data
->no_input_qs
&& !init_data
->input_handler
) ||
1306 (init_data
->no_output_qs
&& !init_data
->output_handler
))
1309 if ((init_data
->no_input_qs
> QDIO_MAX_QUEUES_PER_IRQ
) ||
1310 (init_data
->no_output_qs
> QDIO_MAX_QUEUES_PER_IRQ
))
1313 if ((!init_data
->input_sbal_addr_array
) ||
1314 (!init_data
->output_sbal_addr_array
))
1317 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1318 irq_ptr
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1322 mutex_init(&irq_ptr
->setup_mutex
);
1323 qdio_allocate_dbf(init_data
, irq_ptr
);
1326 * Allocate a page for the chsc calls in qdio_establish.
1327 * Must be pre-allocated since a zfcp recovery will call
1328 * qdio_establish. In case of low memory and swap on a zfcp disk
1329 * we may not be able to allocate memory otherwise.
1331 irq_ptr
->chsc_page
= get_zeroed_page(GFP_KERNEL
);
1332 if (!irq_ptr
->chsc_page
)
1335 /* qdr is used in ccw1.cda which is u32 */
1336 irq_ptr
->qdr
= (struct qdr
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1340 if (qdio_allocate_qs(irq_ptr
, init_data
->no_input_qs
,
1341 init_data
->no_output_qs
))
1344 init_data
->cdev
->private->qdio_data
= irq_ptr
;
1345 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1348 qdio_release_memory(irq_ptr
);
1352 EXPORT_SYMBOL_GPL(qdio_allocate
);
1354 static void qdio_detect_hsicq(struct qdio_irq
*irq_ptr
)
1356 struct qdio_q
*q
= irq_ptr
->input_qs
[0];
1359 if (irq_ptr
->nr_input_qs
> 1 && queue_type(q
) == QDIO_IQDIO_QFMT
)
1362 for_each_output_queue(irq_ptr
, q
, i
) {
1364 if (qdio_enable_async_operation(&q
->u
.out
) < 0) {
1369 qdio_disable_async_operation(&q
->u
.out
);
1371 DBF_EVENT("use_cq:%d", use_cq
);
1375 * qdio_establish - establish queues on a qdio subchannel
1376 * @init_data: initialization data
1378 int qdio_establish(struct qdio_initialize
*init_data
)
1380 struct qdio_irq
*irq_ptr
;
1381 struct ccw_device
*cdev
= init_data
->cdev
;
1382 unsigned long saveflags
;
1385 DBF_EVENT("qestablish:%4x", cdev
->private->schid
.sch_no
);
1387 irq_ptr
= cdev
->private->qdio_data
;
1391 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
1394 mutex_lock(&irq_ptr
->setup_mutex
);
1395 qdio_setup_irq(init_data
);
1397 rc
= qdio_establish_thinint(irq_ptr
);
1399 mutex_unlock(&irq_ptr
->setup_mutex
);
1400 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1405 irq_ptr
->ccw
.cmd_code
= irq_ptr
->equeue
.cmd
;
1406 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1407 irq_ptr
->ccw
.count
= irq_ptr
->equeue
.count
;
1408 irq_ptr
->ccw
.cda
= (u32
)((addr_t
)irq_ptr
->qdr
);
1410 spin_lock_irqsave(get_ccwdev_lock(cdev
), saveflags
);
1411 ccw_device_set_options_mask(cdev
, 0);
1413 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ESTABLISH
, 0, 0);
1415 DBF_ERROR("%4x est IO ERR", irq_ptr
->schid
.sch_no
);
1416 DBF_ERROR("rc:%4x", rc
);
1418 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), saveflags
);
1421 mutex_unlock(&irq_ptr
->setup_mutex
);
1422 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1426 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1427 irq_ptr
->state
== QDIO_IRQ_STATE_ESTABLISHED
||
1428 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
, HZ
);
1430 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ESTABLISHED
) {
1431 mutex_unlock(&irq_ptr
->setup_mutex
);
1432 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1436 qdio_setup_ssqd_info(irq_ptr
);
1438 qdio_detect_hsicq(irq_ptr
);
1440 /* qebsm is now setup if available, initialize buffer states */
1441 qdio_init_buf_states(irq_ptr
);
1443 mutex_unlock(&irq_ptr
->setup_mutex
);
1444 qdio_print_subchannel_info(irq_ptr
, cdev
);
1445 qdio_setup_debug_entries(irq_ptr
, cdev
);
1448 EXPORT_SYMBOL_GPL(qdio_establish
);
1451 * qdio_activate - activate queues on a qdio subchannel
1452 * @cdev: associated cdev
1454 int qdio_activate(struct ccw_device
*cdev
)
1456 struct qdio_irq
*irq_ptr
;
1458 unsigned long saveflags
;
1460 DBF_EVENT("qactivate:%4x", cdev
->private->schid
.sch_no
);
1462 irq_ptr
= cdev
->private->qdio_data
;
1466 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
1469 mutex_lock(&irq_ptr
->setup_mutex
);
1470 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1475 irq_ptr
->ccw
.cmd_code
= irq_ptr
->aqueue
.cmd
;
1476 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1477 irq_ptr
->ccw
.count
= irq_ptr
->aqueue
.count
;
1478 irq_ptr
->ccw
.cda
= 0;
1480 spin_lock_irqsave(get_ccwdev_lock(cdev
), saveflags
);
1481 ccw_device_set_options(cdev
, CCWDEV_REPORT_ALL
);
1483 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ACTIVATE
,
1484 0, DOIO_DENY_PREFETCH
);
1486 DBF_ERROR("%4x act IO ERR", irq_ptr
->schid
.sch_no
);
1487 DBF_ERROR("rc:%4x", rc
);
1489 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), saveflags
);
1494 if (is_thinint_irq(irq_ptr
))
1495 tiqdio_add_input_queues(irq_ptr
);
1497 /* wait for subchannel to become active */
1500 switch (irq_ptr
->state
) {
1501 case QDIO_IRQ_STATE_STOPPED
:
1502 case QDIO_IRQ_STATE_ERR
:
1506 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ACTIVE
);
1510 mutex_unlock(&irq_ptr
->setup_mutex
);
1513 EXPORT_SYMBOL_GPL(qdio_activate
);
1515 static inline int buf_in_between(int bufnr
, int start
, int count
)
1517 int end
= add_buf(start
, count
);
1520 if (bufnr
>= start
&& bufnr
< end
)
1526 /* wrap-around case */
1527 if ((bufnr
>= start
&& bufnr
<= QDIO_MAX_BUFFERS_PER_Q
) ||
1535 * handle_inbound - reset processed input buffers
1536 * @q: queue containing the buffers
1538 * @bufnr: first buffer to process
1539 * @count: how many buffers are emptied
1541 static int handle_inbound(struct qdio_q
*q
, unsigned int callflags
,
1542 int bufnr
, int count
)
1546 qperf_inc(q
, inbound_call
);
1548 if (!q
->u
.in
.polling
)
1551 /* protect against stop polling setting an ACK for an emptied slsb */
1552 if (count
== QDIO_MAX_BUFFERS_PER_Q
) {
1553 /* overwriting everything, just delete polling status */
1554 q
->u
.in
.polling
= 0;
1555 q
->u
.in
.ack_count
= 0;
1557 } else if (buf_in_between(q
->u
.in
.ack_start
, bufnr
, count
)) {
1559 /* partial overwrite, just update ack_start */
1560 diff
= add_buf(bufnr
, count
);
1561 diff
= sub_buf(diff
, q
->u
.in
.ack_start
);
1562 q
->u
.in
.ack_count
-= diff
;
1563 if (q
->u
.in
.ack_count
<= 0) {
1564 q
->u
.in
.polling
= 0;
1565 q
->u
.in
.ack_count
= 0;
1568 q
->u
.in
.ack_start
= add_buf(q
->u
.in
.ack_start
, diff
);
1571 /* the only ACK will be deleted, so stop polling */
1572 q
->u
.in
.polling
= 0;
1576 count
= set_buf_states(q
, bufnr
, SLSB_CU_INPUT_EMPTY
, count
);
1577 used
= atomic_add_return(count
, &q
->nr_buf_used
) - count
;
1579 if (need_siga_in(q
))
1580 return qdio_siga_input(q
);
1586 * handle_outbound - process filled outbound buffers
1587 * @q: queue containing the buffers
1589 * @bufnr: first buffer to process
1590 * @count: how many buffers are filled
1592 static int handle_outbound(struct qdio_q
*q
, unsigned int callflags
,
1593 int bufnr
, int count
)
1595 unsigned char state
= 0;
1598 qperf_inc(q
, outbound_call
);
1600 count
= set_buf_states(q
, bufnr
, SLSB_CU_OUTPUT_PRIMED
, count
);
1601 used
= atomic_add_return(count
, &q
->nr_buf_used
);
1603 if (used
== QDIO_MAX_BUFFERS_PER_Q
)
1604 qperf_inc(q
, outbound_queue_full
);
1606 if (callflags
& QDIO_FLAG_PCI_OUT
) {
1607 q
->u
.out
.pci_out_enabled
= 1;
1608 qperf_inc(q
, pci_request_int
);
1610 q
->u
.out
.pci_out_enabled
= 0;
1612 if (queue_type(q
) == QDIO_IQDIO_QFMT
) {
1613 unsigned long phys_aob
= 0;
1615 /* One SIGA-W per buffer required for unicast HSI */
1616 WARN_ON_ONCE(count
> 1 && !multicast_outbound(q
));
1618 phys_aob
= qdio_aob_for_buffer(&q
->u
.out
, bufnr
);
1620 rc
= qdio_kick_outbound_q(q
, phys_aob
);
1621 } else if (need_siga_sync(q
)) {
1622 rc
= qdio_siga_sync_q(q
);
1624 /* try to fast requeue buffers */
1625 get_buf_state(q
, prev_buf(bufnr
), &state
, 0);
1626 if (state
!= SLSB_CU_OUTPUT_PRIMED
)
1627 rc
= qdio_kick_outbound_q(q
, 0);
1629 qperf_inc(q
, fast_requeue
);
1632 /* in case of SIGA errors we must process the error immediately */
1633 if (used
>= q
->u
.out
.scan_threshold
|| rc
)
1634 tasklet_schedule(&q
->tasklet
);
1636 /* free the SBALs in case of no further traffic */
1637 if (!timer_pending(&q
->u
.out
.timer
))
1638 mod_timer(&q
->u
.out
.timer
, jiffies
+ HZ
);
1643 * do_QDIO - process input or output buffers
1644 * @cdev: associated ccw_device for the qdio subchannel
1645 * @callflags: input or output and special flags from the program
1646 * @q_nr: queue number
1647 * @bufnr: buffer number
1648 * @count: how many buffers to process
1650 int do_QDIO(struct ccw_device
*cdev
, unsigned int callflags
,
1651 int q_nr
, unsigned int bufnr
, unsigned int count
)
1653 struct qdio_irq
*irq_ptr
;
1655 if (bufnr
>= QDIO_MAX_BUFFERS_PER_Q
|| count
> QDIO_MAX_BUFFERS_PER_Q
)
1658 irq_ptr
= cdev
->private->qdio_data
;
1662 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
,
1663 "do%02x b:%02x c:%02x", callflags
, bufnr
, count
);
1665 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
)
1669 if (callflags
& QDIO_FLAG_SYNC_INPUT
)
1670 return handle_inbound(irq_ptr
->input_qs
[q_nr
],
1671 callflags
, bufnr
, count
);
1672 else if (callflags
& QDIO_FLAG_SYNC_OUTPUT
)
1673 return handle_outbound(irq_ptr
->output_qs
[q_nr
],
1674 callflags
, bufnr
, count
);
1677 EXPORT_SYMBOL_GPL(do_QDIO
);
1680 * qdio_start_irq - process input buffers
1681 * @cdev: associated ccw_device for the qdio subchannel
1682 * @nr: input queue number
1686 * 1 - irqs not started since new data is available
1688 int qdio_start_irq(struct ccw_device
*cdev
, int nr
)
1691 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1695 q
= irq_ptr
->input_qs
[nr
];
1697 clear_nonshared_ind(irq_ptr
);
1698 qdio_stop_polling(q
);
1699 clear_bit(QDIO_QUEUE_IRQS_DISABLED
, &q
->u
.in
.queue_irq_state
);
1702 * We need to check again to not lose initiative after
1703 * resetting the ACK state.
1705 if (test_nonshared_ind(irq_ptr
))
1707 if (!qdio_inbound_q_done(q
))
1712 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1713 &q
->u
.in
.queue_irq_state
))
1719 EXPORT_SYMBOL(qdio_start_irq
);
1722 * qdio_get_next_buffers - process input buffers
1723 * @cdev: associated ccw_device for the qdio subchannel
1724 * @nr: input queue number
1725 * @bufnr: first filled buffer number
1726 * @error: buffers are in error state
1730 * = 0 - no new buffers found
1731 * > 0 - number of processed buffers
1733 int qdio_get_next_buffers(struct ccw_device
*cdev
, int nr
, int *bufnr
,
1738 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1742 q
= irq_ptr
->input_qs
[nr
];
1745 * Cannot rely on automatic sync after interrupt since queues may
1746 * also be examined without interrupt.
1748 if (need_siga_sync(q
))
1749 qdio_sync_queues(q
);
1751 /* check the PCI capable outbound queues. */
1752 qdio_check_outbound_after_thinint(q
);
1754 if (!qdio_inbound_q_moved(q
))
1757 /* Note: upper-layer MUST stop processing immediately here ... */
1758 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
1761 start
= q
->first_to_kick
;
1762 end
= q
->first_to_check
;
1764 *error
= q
->qdio_error
;
1766 /* for the next time */
1767 q
->first_to_kick
= end
;
1769 return sub_buf(end
, start
);
1771 EXPORT_SYMBOL(qdio_get_next_buffers
);
1774 * qdio_stop_irq - disable interrupt processing for the device
1775 * @cdev: associated ccw_device for the qdio subchannel
1776 * @nr: input queue number
1779 * 0 - interrupts were already disabled
1780 * 1 - interrupts successfully disabled
1782 int qdio_stop_irq(struct ccw_device
*cdev
, int nr
)
1785 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1789 q
= irq_ptr
->input_qs
[nr
];
1791 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1792 &q
->u
.in
.queue_irq_state
))
1797 EXPORT_SYMBOL(qdio_stop_irq
);
1799 static int __init
init_QDIO(void)
1803 rc
= qdio_debug_init();
1806 rc
= qdio_setup_init();
1809 rc
= tiqdio_allocate_memory();
1812 rc
= tiqdio_register_thinints();
1818 tiqdio_free_memory();
1826 static void __exit
exit_QDIO(void)
1828 tiqdio_unregister_thinints();
1829 tiqdio_free_memory();
1834 module_init(init_QDIO
);
1835 module_exit(exit_QDIO
);