1 // SPDX-License-Identifier: GPL-2.0
3 * Linux for s390 qdio support, buffer handling, qdio API and module support.
5 * Copyright IBM Corp. 2000, 2008
6 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
7 * Jan Glauber <jang@linux.vnet.ibm.com>
8 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/timer.h>
14 #include <linux/delay.h>
15 #include <linux/gfp.h>
17 #include <linux/atomic.h>
18 #include <asm/debug.h>
26 #include "qdio_debug.h"
28 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
29 "Jan Glauber <jang@linux.vnet.ibm.com>");
30 MODULE_DESCRIPTION("QDIO base support");
31 MODULE_LICENSE("GPL");
33 static inline int do_siga_sync(unsigned long schid
,
34 unsigned int out_mask
, unsigned int in_mask
,
37 register unsigned long __fc
asm ("0") = fc
;
38 register unsigned long __schid
asm ("1") = schid
;
39 register unsigned long out
asm ("2") = out_mask
;
40 register unsigned long in
asm ("3") = in_mask
;
48 : "d" (__fc
), "d" (__schid
), "d" (out
), "d" (in
) : "cc");
52 static inline int do_siga_input(unsigned long schid
, unsigned int mask
,
55 register unsigned long __fc
asm ("0") = fc
;
56 register unsigned long __schid
asm ("1") = schid
;
57 register unsigned long __mask
asm ("2") = mask
;
65 : "d" (__fc
), "d" (__schid
), "d" (__mask
) : "cc");
70 * do_siga_output - perform SIGA-w/wt function
71 * @schid: subchannel id or in case of QEBSM the subchannel token
72 * @mask: which output queues to process
73 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
74 * @fc: function code to perform
75 * @aob: asynchronous operation block
77 * Returns condition code.
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
;
94 : "=d" (cc
), "+d" (__fc
), "+d" (__aob
)
95 : "d" (__schid
), "d" (__mask
)
102 * qdio_do_eqbs - extract buffer states for QEBSM
103 * @q: queue to manipulate
104 * @state: state of the extracted buffers
105 * @start: buffer number to start at
106 * @count: count of buffers to examine
107 * @auto_ack: automatically acknowledge buffers
109 * Returns the number of successfully extracted equal buffer states.
110 * Stops processing if a state is different from the last buffers state.
112 static int qdio_do_eqbs(struct qdio_q
*q
, unsigned char *state
,
113 int start
, int count
, int auto_ack
)
115 int tmp_count
= count
, tmp_start
= start
, nr
= q
->nr
;
116 unsigned int ccq
= 0;
121 nr
+= q
->irq_ptr
->nr_input_qs
;
123 ccq
= do_eqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
,
129 /* all done, or next buffer state different */
130 return count
- tmp_count
;
132 /* not all buffers processed */
133 qperf_inc(q
, eqbs_partial
);
134 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "EQBS part:%02x",
136 return count
- tmp_count
;
138 /* no buffer processed */
139 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "EQBS again:%2d", ccq
);
142 DBF_ERROR("%4x ccq:%3d", SCH_NO(q
), ccq
);
143 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q
));
144 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
145 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_GET_BUF_STATE
, q
->nr
,
146 q
->first_to_kick
, count
, q
->irq_ptr
->int_parm
);
152 * qdio_do_sqbs - set buffer states for QEBSM
153 * @q: queue to manipulate
154 * @state: new state of the buffers
155 * @start: first buffer number to change
156 * @count: how many buffers to change
158 * Returns the number of successfully changed buffers.
159 * Does retrying until the specified count of buffer states is set or an
162 static int qdio_do_sqbs(struct qdio_q
*q
, unsigned char state
, int start
,
165 unsigned int ccq
= 0;
166 int tmp_count
= count
, tmp_start
= start
;
174 nr
+= q
->irq_ptr
->nr_input_qs
;
176 ccq
= do_sqbs(q
->irq_ptr
->sch_token
, state
, nr
, &tmp_start
, &tmp_count
);
181 /* all done, or active buffer adapter-owned */
182 WARN_ON_ONCE(tmp_count
);
183 return count
- tmp_count
;
185 /* not all buffers processed */
186 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "SQBS again:%2d", ccq
);
187 qperf_inc(q
, sqbs_partial
);
190 DBF_ERROR("%4x ccq:%3d", SCH_NO(q
), ccq
);
191 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q
));
192 DBF_ERROR("%3d%3d%2d", count
, tmp_count
, nr
);
193 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_SET_BUF_STATE
, q
->nr
,
194 q
->first_to_kick
, count
, q
->irq_ptr
->int_parm
);
200 * Returns number of examined buffers and their common state in *state.
201 * Requested number of buffers-to-examine must be > 0.
203 static inline int get_buf_states(struct qdio_q
*q
, unsigned int bufnr
,
204 unsigned char *state
, unsigned int count
,
205 int auto_ack
, int merge_pending
)
207 unsigned char __state
= 0;
211 return qdio_do_eqbs(q
, state
, bufnr
, count
, auto_ack
);
213 /* get initial state: */
214 __state
= q
->slsb
.val
[bufnr
];
215 if (merge_pending
&& __state
== SLSB_P_OUTPUT_PENDING
)
216 __state
= SLSB_P_OUTPUT_EMPTY
;
218 for (i
= 1; i
< count
; i
++) {
219 bufnr
= next_buf(bufnr
);
221 /* merge PENDING into EMPTY: */
223 q
->slsb
.val
[bufnr
] == SLSB_P_OUTPUT_PENDING
&&
224 __state
== SLSB_P_OUTPUT_EMPTY
)
227 /* stop if next state differs from initial state: */
228 if (q
->slsb
.val
[bufnr
] != __state
)
235 static inline int get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
236 unsigned char *state
, int auto_ack
)
238 return get_buf_states(q
, bufnr
, state
, 1, auto_ack
, 0);
241 /* wrap-around safe setting of slsb states, returns number of changed buffers */
242 static inline int set_buf_states(struct qdio_q
*q
, int bufnr
,
243 unsigned char state
, int count
)
248 return qdio_do_sqbs(q
, state
, bufnr
, count
);
250 for (i
= 0; i
< count
; i
++) {
251 xchg(&q
->slsb
.val
[bufnr
], state
);
252 bufnr
= next_buf(bufnr
);
257 static inline int set_buf_state(struct qdio_q
*q
, int bufnr
,
260 return set_buf_states(q
, bufnr
, state
, 1);
263 /* set slsb states to initial state */
264 static void qdio_init_buf_states(struct qdio_irq
*irq_ptr
)
269 for_each_input_queue(irq_ptr
, q
, i
)
270 set_buf_states(q
, 0, SLSB_P_INPUT_NOT_INIT
,
271 QDIO_MAX_BUFFERS_PER_Q
);
272 for_each_output_queue(irq_ptr
, q
, i
)
273 set_buf_states(q
, 0, SLSB_P_OUTPUT_NOT_INIT
,
274 QDIO_MAX_BUFFERS_PER_Q
);
277 static inline int qdio_siga_sync(struct qdio_q
*q
, unsigned int output
,
280 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
281 unsigned int fc
= QDIO_SIGA_SYNC
;
284 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-s:%1d", q
->nr
);
285 qperf_inc(q
, siga_sync
);
288 schid
= q
->irq_ptr
->sch_token
;
289 fc
|= QDIO_SIGA_QEBSM_FLAG
;
292 cc
= do_siga_sync(schid
, output
, input
, fc
);
294 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q
), cc
);
295 return (cc
) ? -EIO
: 0;
298 static inline int qdio_siga_sync_q(struct qdio_q
*q
)
301 return qdio_siga_sync(q
, 0, q
->mask
);
303 return qdio_siga_sync(q
, q
->mask
, 0);
306 static int qdio_siga_output(struct qdio_q
*q
, unsigned int *busy_bit
,
309 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
310 unsigned int fc
= QDIO_SIGA_WRITE
;
313 unsigned long laob
= 0;
315 WARN_ON_ONCE(aob
&& ((queue_type(q
) != QDIO_IQDIO_QFMT
) ||
317 if (q
->u
.out
.use_cq
&& aob
!= 0) {
318 fc
= QDIO_SIGA_WRITEQ
;
323 schid
= q
->irq_ptr
->sch_token
;
324 fc
|= QDIO_SIGA_QEBSM_FLAG
;
327 cc
= do_siga_output(schid
, q
->mask
, busy_bit
, fc
, laob
);
329 /* hipersocket busy condition */
330 if (unlikely(*busy_bit
)) {
334 start_time
= get_tod_clock_fast();
337 if (get_tod_clock_fast() - start_time
< QDIO_BUSY_BIT_PATIENCE
)
341 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
,
342 "%4x cc2 BB1:%1d", SCH_NO(q
), q
->nr
);
343 DBF_DEV_EVENT(DBF_WARN
, q
->irq_ptr
, "count:%u", retries
);
348 static inline int qdio_siga_input(struct qdio_q
*q
)
350 unsigned long schid
= *((u32
*) &q
->irq_ptr
->schid
);
351 unsigned int fc
= QDIO_SIGA_READ
;
354 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-r:%1d", q
->nr
);
355 qperf_inc(q
, siga_read
);
358 schid
= q
->irq_ptr
->sch_token
;
359 fc
|= QDIO_SIGA_QEBSM_FLAG
;
362 cc
= do_siga_input(schid
, q
->mask
, fc
);
364 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q
), cc
);
365 return (cc
) ? -EIO
: 0;
368 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
369 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
371 static inline void qdio_sync_queues(struct qdio_q
*q
)
373 /* PCI capable outbound queues will also be scanned so sync them too */
374 if (pci_out_supported(q
))
375 qdio_siga_sync_all(q
);
380 int debug_get_buf_state(struct qdio_q
*q
, unsigned int bufnr
,
381 unsigned char *state
)
383 if (need_siga_sync(q
))
385 return get_buf_states(q
, bufnr
, state
, 1, 0, 0);
388 static inline void qdio_stop_polling(struct qdio_q
*q
)
390 if (!q
->u
.in
.polling
)
394 qperf_inc(q
, stop_polling
);
396 /* show the card that we are not polling anymore */
398 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
400 q
->u
.in
.ack_count
= 0;
402 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
405 static inline void account_sbals(struct qdio_q
*q
, unsigned int count
)
409 q
->q_stats
.nr_sbal_total
+= count
;
410 if (count
== QDIO_MAX_BUFFERS_MASK
) {
411 q
->q_stats
.nr_sbals
[7]++;
415 q
->q_stats
.nr_sbals
[pos
]++;
418 static void process_buffer_error(struct qdio_q
*q
, int count
)
420 unsigned char state
= (q
->is_input_q
) ? SLSB_P_INPUT_NOT_INIT
:
421 SLSB_P_OUTPUT_NOT_INIT
;
423 q
->qdio_error
= QDIO_ERROR_SLSB_STATE
;
425 /* special handling for no target buffer empty */
426 if (queue_type(q
) == QDIO_IQDIO_QFMT
&& !q
->is_input_q
&&
427 q
->sbal
[q
->first_to_check
]->element
[15].sflags
== 0x10) {
428 qperf_inc(q
, target_full
);
429 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "OUTFULL FTC:%02x",
434 DBF_ERROR("%4x BUF ERROR", SCH_NO(q
));
435 DBF_ERROR((q
->is_input_q
) ? "IN:%2d" : "OUT:%2d", q
->nr
);
436 DBF_ERROR("FTC:%3d C:%3d", q
->first_to_check
, count
);
437 DBF_ERROR("F14:%2x F15:%2x",
438 q
->sbal
[q
->first_to_check
]->element
[14].sflags
,
439 q
->sbal
[q
->first_to_check
]->element
[15].sflags
);
443 * Interrupts may be avoided as long as the error is present
444 * so change the buffer state immediately to avoid starvation.
446 set_buf_states(q
, q
->first_to_check
, state
, count
);
449 static inline void inbound_primed(struct qdio_q
*q
, int count
)
453 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in prim:%1d %02x", q
->nr
, count
);
455 /* for QEBSM the ACK was already set by EQBS */
457 if (!q
->u
.in
.polling
) {
459 q
->u
.in
.ack_count
= count
;
460 q
->u
.in
.ack_start
= q
->first_to_check
;
464 /* delete the previous ACK's */
465 set_buf_states(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
,
467 q
->u
.in
.ack_count
= count
;
468 q
->u
.in
.ack_start
= q
->first_to_check
;
473 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
474 * or by the next inbound run.
476 new = add_buf(q
->first_to_check
, count
- 1);
477 if (q
->u
.in
.polling
) {
478 /* reset the previous ACK but first set the new one */
479 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
480 set_buf_state(q
, q
->u
.in
.ack_start
, SLSB_P_INPUT_NOT_INIT
);
483 set_buf_state(q
, new, SLSB_P_INPUT_ACK
);
486 q
->u
.in
.ack_start
= new;
490 /* need to change ALL buffers to get more interrupts */
491 set_buf_states(q
, q
->first_to_check
, SLSB_P_INPUT_NOT_INIT
, count
);
494 static int get_inbound_buffer_frontier(struct qdio_q
*q
)
496 unsigned char state
= 0;
499 q
->timestamp
= get_tod_clock_fast();
502 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
505 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
510 * No siga sync here, as a PCI or we after a thin interrupt
511 * already sync'ed the queues.
513 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 1, 0);
518 case SLSB_P_INPUT_PRIMED
:
519 inbound_primed(q
, count
);
520 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
521 if (atomic_sub_return(count
, &q
->nr_buf_used
) == 0)
522 qperf_inc(q
, inbound_queue_full
);
523 if (q
->irq_ptr
->perf_stat_enabled
)
524 account_sbals(q
, count
);
526 case SLSB_P_INPUT_ERROR
:
527 process_buffer_error(q
, count
);
528 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
529 if (atomic_sub_return(count
, &q
->nr_buf_used
) == 0)
530 qperf_inc(q
, inbound_queue_full
);
531 if (q
->irq_ptr
->perf_stat_enabled
)
532 account_sbals_error(q
, count
);
534 case SLSB_CU_INPUT_EMPTY
:
535 case SLSB_P_INPUT_NOT_INIT
:
536 case SLSB_P_INPUT_ACK
:
537 if (q
->irq_ptr
->perf_stat_enabled
)
538 q
->q_stats
.nr_sbal_nop
++;
539 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in nop:%1d %#02x",
540 q
->nr
, q
->first_to_check
);
546 return q
->first_to_check
;
549 static int qdio_inbound_q_moved(struct qdio_q
*q
)
553 bufnr
= get_inbound_buffer_frontier(q
);
555 if (bufnr
!= q
->last_move
) {
556 q
->last_move
= bufnr
;
557 if (!is_thinint_irq(q
->irq_ptr
) && MACHINE_IS_LPAR
)
558 q
->u
.in
.timestamp
= get_tod_clock();
564 static inline int qdio_inbound_q_done(struct qdio_q
*q
)
566 unsigned char state
= 0;
568 if (!atomic_read(&q
->nr_buf_used
))
571 if (need_siga_sync(q
))
573 get_buf_state(q
, q
->first_to_check
, &state
, 0);
575 if (state
== SLSB_P_INPUT_PRIMED
|| state
== SLSB_P_INPUT_ERROR
)
576 /* more work coming */
579 if (is_thinint_irq(q
->irq_ptr
))
582 /* don't poll under z/VM */
587 * At this point we know, that inbound first_to_check
588 * has (probably) not moved (see qdio_inbound_processing).
590 if (get_tod_clock_fast() > q
->u
.in
.timestamp
+ QDIO_INPUT_THRESHOLD
) {
591 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "in done:%02x",
598 static inline int contains_aobs(struct qdio_q
*q
)
600 return !q
->is_input_q
&& q
->u
.out
.use_cq
;
603 static inline void qdio_handle_aobs(struct qdio_q
*q
, int start
, int count
)
605 unsigned char state
= 0;
608 if (!contains_aobs(q
))
611 for (j
= 0; j
< count
; ++j
) {
612 get_buf_state(q
, b
, &state
, 0);
613 if (state
== SLSB_P_OUTPUT_PENDING
) {
614 struct qaob
*aob
= q
->u
.out
.aobs
[b
];
618 q
->u
.out
.sbal_state
[b
].flags
|=
619 QDIO_OUTBUF_STATE_FLAG_PENDING
;
620 q
->u
.out
.aobs
[b
] = NULL
;
621 } else if (state
== SLSB_P_OUTPUT_EMPTY
) {
622 q
->u
.out
.sbal_state
[b
].aob
= NULL
;
628 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q
*q
,
631 unsigned long phys_aob
= 0;
636 if (!q
->aobs
[bufnr
]) {
637 struct qaob
*aob
= qdio_allocate_aob();
638 q
->aobs
[bufnr
] = aob
;
640 if (q
->aobs
[bufnr
]) {
641 q
->sbal_state
[bufnr
].aob
= q
->aobs
[bufnr
];
642 q
->aobs
[bufnr
]->user1
= (u64
) q
->sbal_state
[bufnr
].user
;
643 phys_aob
= virt_to_phys(q
->aobs
[bufnr
]);
644 WARN_ON_ONCE(phys_aob
& 0xFF);
647 q
->sbal_state
[bufnr
].flags
= 0;
651 static void qdio_kick_handler(struct qdio_q
*q
)
653 int start
= q
->first_to_kick
;
654 int end
= q
->first_to_check
;
657 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
660 count
= sub_buf(end
, start
);
663 qperf_inc(q
, inbound_handler
);
664 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "kih s:%02x c:%02x", start
, count
);
666 qperf_inc(q
, outbound_handler
);
667 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "koh: s:%02x c:%02x",
671 qdio_handle_aobs(q
, start
, count
);
673 q
->handler(q
->irq_ptr
->cdev
, q
->qdio_error
, q
->nr
, start
, count
,
674 q
->irq_ptr
->int_parm
);
676 /* for the next time */
677 q
->first_to_kick
= end
;
681 static inline int qdio_tasklet_schedule(struct qdio_q
*q
)
683 if (likely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_ACTIVE
)) {
684 tasklet_schedule(&q
->tasklet
);
690 static void __qdio_inbound_processing(struct qdio_q
*q
)
692 qperf_inc(q
, tasklet_inbound
);
694 if (!qdio_inbound_q_moved(q
))
697 qdio_kick_handler(q
);
699 if (!qdio_inbound_q_done(q
)) {
700 /* means poll time is not yet over */
701 qperf_inc(q
, tasklet_inbound_resched
);
702 if (!qdio_tasklet_schedule(q
))
706 qdio_stop_polling(q
);
708 * We need to check again to not lose initiative after
709 * resetting the ACK state.
711 if (!qdio_inbound_q_done(q
)) {
712 qperf_inc(q
, tasklet_inbound_resched2
);
713 qdio_tasklet_schedule(q
);
717 void qdio_inbound_processing(unsigned long data
)
719 struct qdio_q
*q
= (struct qdio_q
*)data
;
720 __qdio_inbound_processing(q
);
723 static int get_outbound_buffer_frontier(struct qdio_q
*q
)
725 unsigned char state
= 0;
728 q
->timestamp
= get_tod_clock_fast();
730 if (need_siga_sync(q
))
731 if (((queue_type(q
) != QDIO_IQDIO_QFMT
) &&
732 !pci_out_supported(q
)) ||
733 (queue_type(q
) == QDIO_IQDIO_QFMT
&&
734 multicast_outbound(q
)))
738 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
741 count
= min(atomic_read(&q
->nr_buf_used
), QDIO_MAX_BUFFERS_MASK
);
745 count
= get_buf_states(q
, q
->first_to_check
, &state
, count
, 0,
751 case SLSB_P_OUTPUT_EMPTY
:
752 case SLSB_P_OUTPUT_PENDING
:
753 /* the adapter got it */
754 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
,
755 "out empty:%1d %02x", q
->nr
, count
);
757 atomic_sub(count
, &q
->nr_buf_used
);
758 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
759 if (q
->irq_ptr
->perf_stat_enabled
)
760 account_sbals(q
, count
);
763 case SLSB_P_OUTPUT_ERROR
:
764 process_buffer_error(q
, count
);
765 q
->first_to_check
= add_buf(q
->first_to_check
, count
);
766 atomic_sub(count
, &q
->nr_buf_used
);
767 if (q
->irq_ptr
->perf_stat_enabled
)
768 account_sbals_error(q
, count
);
770 case SLSB_CU_OUTPUT_PRIMED
:
771 /* the adapter has not fetched the output yet */
772 if (q
->irq_ptr
->perf_stat_enabled
)
773 q
->q_stats
.nr_sbal_nop
++;
774 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out primed:%1d",
777 case SLSB_P_OUTPUT_NOT_INIT
:
778 case SLSB_P_OUTPUT_HALTED
:
785 return q
->first_to_check
;
788 /* all buffers processed? */
789 static inline int qdio_outbound_q_done(struct qdio_q
*q
)
791 return atomic_read(&q
->nr_buf_used
) == 0;
794 static inline int qdio_outbound_q_moved(struct qdio_q
*q
)
798 bufnr
= get_outbound_buffer_frontier(q
);
800 if (bufnr
!= q
->last_move
) {
801 q
->last_move
= bufnr
;
802 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "out moved:%1d", q
->nr
);
808 static int qdio_kick_outbound_q(struct qdio_q
*q
, unsigned long aob
)
811 unsigned int busy_bit
;
813 if (!need_siga_out(q
))
816 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w:%1d", q
->nr
);
818 qperf_inc(q
, siga_write
);
820 cc
= qdio_siga_output(q
, &busy_bit
, aob
);
826 while (++retries
< QDIO_BUSY_BIT_RETRIES
) {
827 mdelay(QDIO_BUSY_BIT_RETRY_DELAY
);
830 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q
), q
->nr
);
833 DBF_DEV_EVENT(DBF_INFO
, q
->irq_ptr
, "siga-w cc2:%1d", q
->nr
);
839 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q
), cc
);
844 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q
), q
->nr
);
845 DBF_ERROR("count:%u", retries
);
850 static void __qdio_outbound_processing(struct qdio_q
*q
)
852 qperf_inc(q
, tasklet_outbound
);
853 WARN_ON_ONCE(atomic_read(&q
->nr_buf_used
) < 0);
855 if (qdio_outbound_q_moved(q
))
856 qdio_kick_handler(q
);
858 if (queue_type(q
) == QDIO_ZFCP_QFMT
)
859 if (!pci_out_supported(q
) && !qdio_outbound_q_done(q
))
862 if (q
->u
.out
.pci_out_enabled
)
866 * Now we know that queue type is either qeth without pci enabled
867 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
868 * is noticed and outbound_handler is called after some time.
870 if (qdio_outbound_q_done(q
))
871 del_timer_sync(&q
->u
.out
.timer
);
873 if (!timer_pending(&q
->u
.out
.timer
) &&
874 likely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_ACTIVE
))
875 mod_timer(&q
->u
.out
.timer
, jiffies
+ 10 * HZ
);
879 qdio_tasklet_schedule(q
);
882 /* outbound tasklet */
883 void qdio_outbound_processing(unsigned long data
)
885 struct qdio_q
*q
= (struct qdio_q
*)data
;
886 __qdio_outbound_processing(q
);
889 void qdio_outbound_timer(struct timer_list
*t
)
891 struct qdio_q
*q
= from_timer(q
, t
, u
.out
.timer
);
893 qdio_tasklet_schedule(q
);
896 static inline void qdio_check_outbound_after_thinint(struct qdio_q
*q
)
901 if (!pci_out_supported(q
))
904 for_each_output_queue(q
->irq_ptr
, out
, i
)
905 if (!qdio_outbound_q_done(out
))
906 qdio_tasklet_schedule(out
);
909 static void __tiqdio_inbound_processing(struct qdio_q
*q
)
911 qperf_inc(q
, tasklet_inbound
);
912 if (need_siga_sync(q
) && need_siga_sync_after_ai(q
))
916 * The interrupt could be caused by a PCI request. Check the
917 * PCI capable outbound queues.
919 qdio_check_outbound_after_thinint(q
);
921 if (!qdio_inbound_q_moved(q
))
924 qdio_kick_handler(q
);
926 if (!qdio_inbound_q_done(q
)) {
927 qperf_inc(q
, tasklet_inbound_resched
);
928 if (!qdio_tasklet_schedule(q
))
932 qdio_stop_polling(q
);
934 * We need to check again to not lose initiative after
935 * resetting the ACK state.
937 if (!qdio_inbound_q_done(q
)) {
938 qperf_inc(q
, tasklet_inbound_resched2
);
939 qdio_tasklet_schedule(q
);
943 void tiqdio_inbound_processing(unsigned long data
)
945 struct qdio_q
*q
= (struct qdio_q
*)data
;
946 __tiqdio_inbound_processing(q
);
949 static inline void qdio_set_state(struct qdio_irq
*irq_ptr
,
950 enum qdio_irq_states state
)
952 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "newstate: %1d", state
);
954 irq_ptr
->state
= state
;
958 static void qdio_irq_check_sense(struct qdio_irq
*irq_ptr
, struct irb
*irb
)
960 if (irb
->esw
.esw0
.erw
.cons
) {
961 DBF_ERROR("%4x sense:", irq_ptr
->schid
.sch_no
);
962 DBF_ERROR_HEX(irb
, 64);
963 DBF_ERROR_HEX(irb
->ecw
, 64);
967 /* PCI interrupt handler */
968 static void qdio_int_handler_pci(struct qdio_irq
*irq_ptr
)
973 if (unlikely(irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
976 for_each_input_queue(irq_ptr
, q
, i
) {
977 if (q
->u
.in
.queue_start_poll
) {
978 /* skip if polling is enabled or already in work */
979 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
980 &q
->u
.in
.queue_irq_state
)) {
981 qperf_inc(q
, int_discarded
);
984 q
->u
.in
.queue_start_poll(q
->irq_ptr
->cdev
, q
->nr
,
985 q
->irq_ptr
->int_parm
);
987 tasklet_schedule(&q
->tasklet
);
991 if (!(irq_ptr
->qib
.ac
& QIB_AC_OUTBOUND_PCI_SUPPORTED
))
994 for_each_output_queue(irq_ptr
, q
, i
) {
995 if (qdio_outbound_q_done(q
))
997 if (need_siga_sync(q
) && need_siga_sync_out_after_pci(q
))
999 qdio_tasklet_schedule(q
);
1003 static void qdio_handle_activate_check(struct ccw_device
*cdev
,
1004 unsigned long intparm
, int cstat
, int dstat
)
1006 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1010 DBF_ERROR("%4x ACT CHECK", irq_ptr
->schid
.sch_no
);
1011 DBF_ERROR("intp :%lx", intparm
);
1012 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1014 if (irq_ptr
->nr_input_qs
) {
1015 q
= irq_ptr
->input_qs
[0];
1016 } else if (irq_ptr
->nr_output_qs
) {
1017 q
= irq_ptr
->output_qs
[0];
1023 count
= sub_buf(q
->first_to_check
, q
->first_to_kick
);
1024 q
->handler(q
->irq_ptr
->cdev
, QDIO_ERROR_ACTIVATE
,
1025 q
->nr
, q
->first_to_kick
, count
, irq_ptr
->int_parm
);
1027 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1029 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1030 * Therefore we call the LGR detection function here.
1035 static void qdio_establish_handle_irq(struct ccw_device
*cdev
, int cstat
,
1038 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1040 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
, "qest irq");
1044 if (dstat
& ~(DEV_STAT_DEV_END
| DEV_STAT_CHN_END
))
1046 if (!(dstat
& DEV_STAT_DEV_END
))
1048 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ESTABLISHED
);
1052 DBF_ERROR("%4x EQ:error", irq_ptr
->schid
.sch_no
);
1053 DBF_ERROR("ds: %2x cs:%2x", dstat
, cstat
);
1054 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1057 /* qdio interrupt handler */
1058 void qdio_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1061 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1062 struct subchannel_id schid
;
1065 if (!intparm
|| !irq_ptr
) {
1066 ccw_device_get_schid(cdev
, &schid
);
1067 DBF_ERROR("qint:%4x", schid
.sch_no
);
1071 if (irq_ptr
->perf_stat_enabled
)
1072 irq_ptr
->perf_stat
.qdio_int
++;
1075 DBF_ERROR("%4x IO error", irq_ptr
->schid
.sch_no
);
1076 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ERR
);
1077 wake_up(&cdev
->private->wait_q
);
1080 qdio_irq_check_sense(irq_ptr
, irb
);
1081 cstat
= irb
->scsw
.cmd
.cstat
;
1082 dstat
= irb
->scsw
.cmd
.dstat
;
1084 switch (irq_ptr
->state
) {
1085 case QDIO_IRQ_STATE_INACTIVE
:
1086 qdio_establish_handle_irq(cdev
, cstat
, dstat
);
1088 case QDIO_IRQ_STATE_CLEANUP
:
1089 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1091 case QDIO_IRQ_STATE_ESTABLISHED
:
1092 case QDIO_IRQ_STATE_ACTIVE
:
1093 if (cstat
& SCHN_STAT_PCI
) {
1094 qdio_int_handler_pci(irq_ptr
);
1098 qdio_handle_activate_check(cdev
, intparm
, cstat
,
1101 case QDIO_IRQ_STATE_STOPPED
:
1106 wake_up(&cdev
->private->wait_q
);
1110 * qdio_get_ssqd_desc - get qdio subchannel description
1111 * @cdev: ccw device to get description for
1112 * @data: where to store the ssqd
1114 * Returns 0 or an error code. The results of the chsc are stored in the
1115 * specified structure.
1117 int qdio_get_ssqd_desc(struct ccw_device
*cdev
,
1118 struct qdio_ssqd_desc
*data
)
1120 struct subchannel_id schid
;
1122 if (!cdev
|| !cdev
->private)
1125 ccw_device_get_schid(cdev
, &schid
);
1126 DBF_EVENT("get ssqd:%4x", schid
.sch_no
);
1127 return qdio_setup_get_ssqd(NULL
, &schid
, data
);
1129 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc
);
1131 static void qdio_shutdown_queues(struct ccw_device
*cdev
)
1133 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1137 for_each_input_queue(irq_ptr
, q
, i
)
1138 tasklet_kill(&q
->tasklet
);
1140 for_each_output_queue(irq_ptr
, q
, i
) {
1141 del_timer_sync(&q
->u
.out
.timer
);
1142 tasklet_kill(&q
->tasklet
);
1147 * qdio_shutdown - shut down a qdio subchannel
1148 * @cdev: associated ccw device
1149 * @how: use halt or clear to shutdown
1151 int qdio_shutdown(struct ccw_device
*cdev
, int how
)
1153 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1154 struct subchannel_id schid
;
1160 WARN_ON_ONCE(irqs_disabled());
1161 ccw_device_get_schid(cdev
, &schid
);
1162 DBF_EVENT("qshutdown:%4x", schid
.sch_no
);
1164 mutex_lock(&irq_ptr
->setup_mutex
);
1166 * Subchannel was already shot down. We cannot prevent being called
1167 * twice since cio may trigger a shutdown asynchronously.
1169 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1170 mutex_unlock(&irq_ptr
->setup_mutex
);
1175 * Indicate that the device is going down. Scheduling the queue
1176 * tasklets is forbidden from here on.
1178 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_STOPPED
);
1180 tiqdio_remove_input_queues(irq_ptr
);
1181 qdio_shutdown_queues(cdev
);
1182 qdio_shutdown_debug_entries(irq_ptr
);
1184 /* cleanup subchannel */
1185 spin_lock_irq(get_ccwdev_lock(cdev
));
1187 if (how
& QDIO_FLAG_CLEANUP_USING_CLEAR
)
1188 rc
= ccw_device_clear(cdev
, QDIO_DOING_CLEANUP
);
1190 /* default behaviour is halt */
1191 rc
= ccw_device_halt(cdev
, QDIO_DOING_CLEANUP
);
1193 DBF_ERROR("%4x SHUTD ERR", irq_ptr
->schid
.sch_no
);
1194 DBF_ERROR("rc:%4d", rc
);
1198 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_CLEANUP
);
1199 spin_unlock_irq(get_ccwdev_lock(cdev
));
1200 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1201 irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
||
1202 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
,
1204 spin_lock_irq(get_ccwdev_lock(cdev
));
1207 qdio_shutdown_thinint(irq_ptr
);
1209 /* restore interrupt handler */
1210 if ((void *)cdev
->handler
== (void *)qdio_int_handler
) {
1211 cdev
->handler
= irq_ptr
->orig_handler
;
1212 cdev
->private->intparm
= 0;
1214 spin_unlock_irq(get_ccwdev_lock(cdev
));
1216 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1217 mutex_unlock(&irq_ptr
->setup_mutex
);
1222 EXPORT_SYMBOL_GPL(qdio_shutdown
);
1225 * qdio_free - free data structures for a qdio subchannel
1226 * @cdev: associated ccw device
1228 int qdio_free(struct ccw_device
*cdev
)
1230 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1231 struct subchannel_id schid
;
1236 ccw_device_get_schid(cdev
, &schid
);
1237 DBF_EVENT("qfree:%4x", schid
.sch_no
);
1238 DBF_DEV_EVENT(DBF_ERR
, irq_ptr
, "dbf abandoned");
1239 mutex_lock(&irq_ptr
->setup_mutex
);
1241 irq_ptr
->debug_area
= NULL
;
1242 cdev
->private->qdio_data
= NULL
;
1243 mutex_unlock(&irq_ptr
->setup_mutex
);
1245 qdio_release_memory(irq_ptr
);
1248 EXPORT_SYMBOL_GPL(qdio_free
);
1251 * qdio_allocate - allocate qdio queues and associated data
1252 * @init_data: initialization data
1254 int qdio_allocate(struct qdio_initialize
*init_data
)
1256 struct subchannel_id schid
;
1257 struct qdio_irq
*irq_ptr
;
1259 ccw_device_get_schid(init_data
->cdev
, &schid
);
1260 DBF_EVENT("qallocate:%4x", schid
.sch_no
);
1262 if ((init_data
->no_input_qs
&& !init_data
->input_handler
) ||
1263 (init_data
->no_output_qs
&& !init_data
->output_handler
))
1266 if ((init_data
->no_input_qs
> QDIO_MAX_QUEUES_PER_IRQ
) ||
1267 (init_data
->no_output_qs
> QDIO_MAX_QUEUES_PER_IRQ
))
1270 if ((!init_data
->input_sbal_addr_array
) ||
1271 (!init_data
->output_sbal_addr_array
))
1274 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1275 irq_ptr
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1279 mutex_init(&irq_ptr
->setup_mutex
);
1280 if (qdio_allocate_dbf(init_data
, irq_ptr
))
1284 * Allocate a page for the chsc calls in qdio_establish.
1285 * Must be pre-allocated since a zfcp recovery will call
1286 * qdio_establish. In case of low memory and swap on a zfcp disk
1287 * we may not be able to allocate memory otherwise.
1289 irq_ptr
->chsc_page
= get_zeroed_page(GFP_KERNEL
);
1290 if (!irq_ptr
->chsc_page
)
1293 /* qdr is used in ccw1.cda which is u32 */
1294 irq_ptr
->qdr
= (struct qdr
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1298 if (qdio_allocate_qs(irq_ptr
, init_data
->no_input_qs
,
1299 init_data
->no_output_qs
))
1302 init_data
->cdev
->private->qdio_data
= irq_ptr
;
1303 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_INACTIVE
);
1306 qdio_release_memory(irq_ptr
);
1310 EXPORT_SYMBOL_GPL(qdio_allocate
);
1312 static void qdio_detect_hsicq(struct qdio_irq
*irq_ptr
)
1314 struct qdio_q
*q
= irq_ptr
->input_qs
[0];
1317 if (irq_ptr
->nr_input_qs
> 1 && queue_type(q
) == QDIO_IQDIO_QFMT
)
1320 for_each_output_queue(irq_ptr
, q
, i
) {
1322 if (qdio_enable_async_operation(&q
->u
.out
) < 0) {
1327 qdio_disable_async_operation(&q
->u
.out
);
1329 DBF_EVENT("use_cq:%d", use_cq
);
1333 * qdio_establish - establish queues on a qdio subchannel
1334 * @init_data: initialization data
1336 int qdio_establish(struct qdio_initialize
*init_data
)
1338 struct ccw_device
*cdev
= init_data
->cdev
;
1339 struct subchannel_id schid
;
1340 struct qdio_irq
*irq_ptr
;
1343 ccw_device_get_schid(cdev
, &schid
);
1344 DBF_EVENT("qestablish:%4x", schid
.sch_no
);
1346 irq_ptr
= cdev
->private->qdio_data
;
1350 mutex_lock(&irq_ptr
->setup_mutex
);
1351 qdio_setup_irq(init_data
);
1353 rc
= qdio_establish_thinint(irq_ptr
);
1355 mutex_unlock(&irq_ptr
->setup_mutex
);
1356 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1361 irq_ptr
->ccw
.cmd_code
= irq_ptr
->equeue
.cmd
;
1362 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1363 irq_ptr
->ccw
.count
= irq_ptr
->equeue
.count
;
1364 irq_ptr
->ccw
.cda
= (u32
)((addr_t
)irq_ptr
->qdr
);
1366 spin_lock_irq(get_ccwdev_lock(cdev
));
1367 ccw_device_set_options_mask(cdev
, 0);
1369 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ESTABLISH
, 0, 0);
1370 spin_unlock_irq(get_ccwdev_lock(cdev
));
1372 DBF_ERROR("%4x est IO ERR", irq_ptr
->schid
.sch_no
);
1373 DBF_ERROR("rc:%4x", rc
);
1374 mutex_unlock(&irq_ptr
->setup_mutex
);
1375 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1379 wait_event_interruptible_timeout(cdev
->private->wait_q
,
1380 irq_ptr
->state
== QDIO_IRQ_STATE_ESTABLISHED
||
1381 irq_ptr
->state
== QDIO_IRQ_STATE_ERR
, HZ
);
1383 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ESTABLISHED
) {
1384 mutex_unlock(&irq_ptr
->setup_mutex
);
1385 qdio_shutdown(cdev
, QDIO_FLAG_CLEANUP_USING_CLEAR
);
1389 qdio_setup_ssqd_info(irq_ptr
);
1391 qdio_detect_hsicq(irq_ptr
);
1393 /* qebsm is now setup if available, initialize buffer states */
1394 qdio_init_buf_states(irq_ptr
);
1396 mutex_unlock(&irq_ptr
->setup_mutex
);
1397 qdio_print_subchannel_info(irq_ptr
, cdev
);
1398 qdio_setup_debug_entries(irq_ptr
, cdev
);
1401 EXPORT_SYMBOL_GPL(qdio_establish
);
1404 * qdio_activate - activate queues on a qdio subchannel
1405 * @cdev: associated cdev
1407 int qdio_activate(struct ccw_device
*cdev
)
1409 struct subchannel_id schid
;
1410 struct qdio_irq
*irq_ptr
;
1413 ccw_device_get_schid(cdev
, &schid
);
1414 DBF_EVENT("qactivate:%4x", schid
.sch_no
);
1416 irq_ptr
= cdev
->private->qdio_data
;
1420 mutex_lock(&irq_ptr
->setup_mutex
);
1421 if (irq_ptr
->state
== QDIO_IRQ_STATE_INACTIVE
) {
1426 irq_ptr
->ccw
.cmd_code
= irq_ptr
->aqueue
.cmd
;
1427 irq_ptr
->ccw
.flags
= CCW_FLAG_SLI
;
1428 irq_ptr
->ccw
.count
= irq_ptr
->aqueue
.count
;
1429 irq_ptr
->ccw
.cda
= 0;
1431 spin_lock_irq(get_ccwdev_lock(cdev
));
1432 ccw_device_set_options(cdev
, CCWDEV_REPORT_ALL
);
1434 rc
= ccw_device_start(cdev
, &irq_ptr
->ccw
, QDIO_DOING_ACTIVATE
,
1435 0, DOIO_DENY_PREFETCH
);
1436 spin_unlock_irq(get_ccwdev_lock(cdev
));
1438 DBF_ERROR("%4x act IO ERR", irq_ptr
->schid
.sch_no
);
1439 DBF_ERROR("rc:%4x", rc
);
1443 if (is_thinint_irq(irq_ptr
))
1444 tiqdio_add_input_queues(irq_ptr
);
1446 /* wait for subchannel to become active */
1449 switch (irq_ptr
->state
) {
1450 case QDIO_IRQ_STATE_STOPPED
:
1451 case QDIO_IRQ_STATE_ERR
:
1455 qdio_set_state(irq_ptr
, QDIO_IRQ_STATE_ACTIVE
);
1459 mutex_unlock(&irq_ptr
->setup_mutex
);
1462 EXPORT_SYMBOL_GPL(qdio_activate
);
1464 static inline int buf_in_between(int bufnr
, int start
, int count
)
1466 int end
= add_buf(start
, count
);
1469 if (bufnr
>= start
&& bufnr
< end
)
1475 /* wrap-around case */
1476 if ((bufnr
>= start
&& bufnr
<= QDIO_MAX_BUFFERS_PER_Q
) ||
1484 * handle_inbound - reset processed input buffers
1485 * @q: queue containing the buffers
1487 * @bufnr: first buffer to process
1488 * @count: how many buffers are emptied
1490 static int handle_inbound(struct qdio_q
*q
, unsigned int callflags
,
1491 int bufnr
, int count
)
1495 qperf_inc(q
, inbound_call
);
1497 if (!q
->u
.in
.polling
)
1500 /* protect against stop polling setting an ACK for an emptied slsb */
1501 if (count
== QDIO_MAX_BUFFERS_PER_Q
) {
1502 /* overwriting everything, just delete polling status */
1503 q
->u
.in
.polling
= 0;
1504 q
->u
.in
.ack_count
= 0;
1506 } else if (buf_in_between(q
->u
.in
.ack_start
, bufnr
, count
)) {
1508 /* partial overwrite, just update ack_start */
1509 diff
= add_buf(bufnr
, count
);
1510 diff
= sub_buf(diff
, q
->u
.in
.ack_start
);
1511 q
->u
.in
.ack_count
-= diff
;
1512 if (q
->u
.in
.ack_count
<= 0) {
1513 q
->u
.in
.polling
= 0;
1514 q
->u
.in
.ack_count
= 0;
1517 q
->u
.in
.ack_start
= add_buf(q
->u
.in
.ack_start
, diff
);
1520 /* the only ACK will be deleted, so stop polling */
1521 q
->u
.in
.polling
= 0;
1525 count
= set_buf_states(q
, bufnr
, SLSB_CU_INPUT_EMPTY
, count
);
1526 atomic_add(count
, &q
->nr_buf_used
);
1528 if (need_siga_in(q
))
1529 return qdio_siga_input(q
);
1535 * handle_outbound - process filled outbound buffers
1536 * @q: queue containing the buffers
1538 * @bufnr: first buffer to process
1539 * @count: how many buffers are filled
1541 static int handle_outbound(struct qdio_q
*q
, unsigned int callflags
,
1542 int bufnr
, int count
)
1544 unsigned char state
= 0;
1547 qperf_inc(q
, outbound_call
);
1549 count
= set_buf_states(q
, bufnr
, SLSB_CU_OUTPUT_PRIMED
, count
);
1550 used
= atomic_add_return(count
, &q
->nr_buf_used
);
1552 if (used
== QDIO_MAX_BUFFERS_PER_Q
)
1553 qperf_inc(q
, outbound_queue_full
);
1555 if (callflags
& QDIO_FLAG_PCI_OUT
) {
1556 q
->u
.out
.pci_out_enabled
= 1;
1557 qperf_inc(q
, pci_request_int
);
1559 q
->u
.out
.pci_out_enabled
= 0;
1561 if (queue_type(q
) == QDIO_IQDIO_QFMT
) {
1562 unsigned long phys_aob
= 0;
1564 /* One SIGA-W per buffer required for unicast HSI */
1565 WARN_ON_ONCE(count
> 1 && !multicast_outbound(q
));
1567 phys_aob
= qdio_aob_for_buffer(&q
->u
.out
, bufnr
);
1569 rc
= qdio_kick_outbound_q(q
, phys_aob
);
1570 } else if (need_siga_sync(q
)) {
1571 rc
= qdio_siga_sync_q(q
);
1572 } else if (count
< QDIO_MAX_BUFFERS_PER_Q
&&
1573 get_buf_state(q
, prev_buf(bufnr
), &state
, 0) > 0 &&
1574 state
== SLSB_CU_OUTPUT_PRIMED
) {
1575 /* The previous buffer is not processed yet, tack on. */
1576 qperf_inc(q
, fast_requeue
);
1578 rc
= qdio_kick_outbound_q(q
, 0);
1581 /* in case of SIGA errors we must process the error immediately */
1582 if (used
>= q
->u
.out
.scan_threshold
|| rc
)
1583 qdio_tasklet_schedule(q
);
1585 /* free the SBALs in case of no further traffic */
1586 if (!timer_pending(&q
->u
.out
.timer
) &&
1587 likely(q
->irq_ptr
->state
== QDIO_IRQ_STATE_ACTIVE
))
1588 mod_timer(&q
->u
.out
.timer
, jiffies
+ HZ
);
1593 * do_QDIO - process input or output buffers
1594 * @cdev: associated ccw_device for the qdio subchannel
1595 * @callflags: input or output and special flags from the program
1596 * @q_nr: queue number
1597 * @bufnr: buffer number
1598 * @count: how many buffers to process
1600 int do_QDIO(struct ccw_device
*cdev
, unsigned int callflags
,
1601 int q_nr
, unsigned int bufnr
, unsigned int count
)
1603 struct qdio_irq
*irq_ptr
;
1605 if (bufnr
>= QDIO_MAX_BUFFERS_PER_Q
|| count
> QDIO_MAX_BUFFERS_PER_Q
)
1608 irq_ptr
= cdev
->private->qdio_data
;
1612 DBF_DEV_EVENT(DBF_INFO
, irq_ptr
,
1613 "do%02x b:%02x c:%02x", callflags
, bufnr
, count
);
1615 if (irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
)
1619 if (callflags
& QDIO_FLAG_SYNC_INPUT
)
1620 return handle_inbound(irq_ptr
->input_qs
[q_nr
],
1621 callflags
, bufnr
, count
);
1622 else if (callflags
& QDIO_FLAG_SYNC_OUTPUT
)
1623 return handle_outbound(irq_ptr
->output_qs
[q_nr
],
1624 callflags
, bufnr
, count
);
1627 EXPORT_SYMBOL_GPL(do_QDIO
);
1630 * qdio_start_irq - process input buffers
1631 * @cdev: associated ccw_device for the qdio subchannel
1632 * @nr: input queue number
1636 * 1 - irqs not started since new data is available
1638 int qdio_start_irq(struct ccw_device
*cdev
, int nr
)
1641 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1645 q
= irq_ptr
->input_qs
[nr
];
1647 clear_nonshared_ind(irq_ptr
);
1648 qdio_stop_polling(q
);
1649 clear_bit(QDIO_QUEUE_IRQS_DISABLED
, &q
->u
.in
.queue_irq_state
);
1652 * We need to check again to not lose initiative after
1653 * resetting the ACK state.
1655 if (test_nonshared_ind(irq_ptr
))
1657 if (!qdio_inbound_q_done(q
))
1662 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1663 &q
->u
.in
.queue_irq_state
))
1669 EXPORT_SYMBOL(qdio_start_irq
);
1672 * qdio_get_next_buffers - process input buffers
1673 * @cdev: associated ccw_device for the qdio subchannel
1674 * @nr: input queue number
1675 * @bufnr: first filled buffer number
1676 * @error: buffers are in error state
1680 * = 0 - no new buffers found
1681 * > 0 - number of processed buffers
1683 int qdio_get_next_buffers(struct ccw_device
*cdev
, int nr
, int *bufnr
,
1688 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1692 q
= irq_ptr
->input_qs
[nr
];
1695 * Cannot rely on automatic sync after interrupt since queues may
1696 * also be examined without interrupt.
1698 if (need_siga_sync(q
))
1699 qdio_sync_queues(q
);
1701 /* check the PCI capable outbound queues. */
1702 qdio_check_outbound_after_thinint(q
);
1704 if (!qdio_inbound_q_moved(q
))
1707 /* Note: upper-layer MUST stop processing immediately here ... */
1708 if (unlikely(q
->irq_ptr
->state
!= QDIO_IRQ_STATE_ACTIVE
))
1711 start
= q
->first_to_kick
;
1712 end
= q
->first_to_check
;
1714 *error
= q
->qdio_error
;
1716 /* for the next time */
1717 q
->first_to_kick
= end
;
1719 return sub_buf(end
, start
);
1721 EXPORT_SYMBOL(qdio_get_next_buffers
);
1724 * qdio_stop_irq - disable interrupt processing for the device
1725 * @cdev: associated ccw_device for the qdio subchannel
1726 * @nr: input queue number
1729 * 0 - interrupts were already disabled
1730 * 1 - interrupts successfully disabled
1732 int qdio_stop_irq(struct ccw_device
*cdev
, int nr
)
1735 struct qdio_irq
*irq_ptr
= cdev
->private->qdio_data
;
1739 q
= irq_ptr
->input_qs
[nr
];
1741 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED
,
1742 &q
->u
.in
.queue_irq_state
))
1747 EXPORT_SYMBOL(qdio_stop_irq
);
1750 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1751 * @schid: Subchannel ID.
1752 * @cnc: Boolean Change-Notification Control
1753 * @response: Response code will be stored at this address
1754 * @cb: Callback function will be executed for each element
1755 * of the address list
1756 * @priv: Pointer to pass to the callback function.
1758 * Performs "Store-network-bridging-information list" operation and calls
1759 * the callback function for every entry in the list. If "change-
1760 * notification-control" is set, further changes in the address list
1761 * will be reported via the IPA command.
1763 int qdio_pnso_brinfo(struct subchannel_id schid
,
1764 int cnc
, u16
*response
,
1765 void (*cb
)(void *priv
, enum qdio_brinfo_entry_type type
,
1769 struct chsc_pnso_area
*rr
;
1771 u32 prev_instance
= 0;
1772 int isfirstblock
= 1;
1775 rr
= (struct chsc_pnso_area
*)get_zeroed_page(GFP_KERNEL
);
1779 /* on the first iteration, naihdr.resume_token will be zero */
1780 rc
= chsc_pnso_brinfo(schid
, rr
, rr
->naihdr
.resume_token
, cnc
);
1781 if (rc
!= 0 && rc
!= -EBUSY
)
1783 if (rr
->response
.code
!= 1) {
1792 size
= rr
->naihdr
.naids
;
1793 elems
= (rr
->response
.length
-
1794 sizeof(struct chsc_header
) -
1795 sizeof(struct chsc_brinfo_naihdr
)) /
1798 if (!isfirstblock
&& (rr
->naihdr
.instance
!= prev_instance
)) {
1799 /* Inform the caller that they need to scrap */
1800 /* the data that was already reported via cb */
1805 prev_instance
= rr
->naihdr
.instance
;
1806 for (i
= 0; i
< elems
; i
++)
1808 case sizeof(struct qdio_brinfo_entry_l3_ipv6
):
1809 (*cb
)(priv
, l3_ipv6_addr
,
1810 &rr
->entries
.l3_ipv6
[i
]);
1812 case sizeof(struct qdio_brinfo_entry_l3_ipv4
):
1813 (*cb
)(priv
, l3_ipv4_addr
,
1814 &rr
->entries
.l3_ipv4
[i
]);
1816 case sizeof(struct qdio_brinfo_entry_l2
):
1817 (*cb
)(priv
, l2_addr_lnid
,
1818 &rr
->entries
.l2
[i
]);
1825 } while (rr
->response
.code
== 0x0107 || /* channel busy */
1826 (rr
->response
.code
== 1 && /* list stored */
1827 /* resume token is non-zero => list incomplete */
1828 (rr
->naihdr
.resume_token
.t1
|| rr
->naihdr
.resume_token
.t2
)));
1829 (*response
) = rr
->response
.code
;
1832 free_page((unsigned long)rr
);
1835 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo
);
1837 static int __init
init_QDIO(void)
1841 rc
= qdio_debug_init();
1844 rc
= qdio_setup_init();
1847 rc
= tiqdio_allocate_memory();
1850 rc
= tiqdio_register_thinints();
1856 tiqdio_free_memory();
1864 static void __exit
exit_QDIO(void)
1866 tiqdio_unregister_thinints();
1867 tiqdio_free_memory();
1872 module_init(init_QDIO
);
1873 module_exit(exit_QDIO
);