s390/cio: remove subchannel_id from ccw_device_private
[deliverable/linux.git] / drivers / s390 / cio / qdio_main.c
CommitLineData
779e6e1c 1/*
779e6e1c
JG
2 * Linux for s390 qdio support, buffer handling, qdio API and module support.
3 *
a53c8fab 4 * Copyright IBM Corp. 2000, 2008
779e6e1c
JG
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>
8 */
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>
5a0e3ad6 14#include <linux/gfp.h>
104ea556 15#include <linux/io.h>
60063497 16#include <linux/atomic.h>
779e6e1c
JG
17#include <asm/debug.h>
18#include <asm/qdio.h>
3ab121ab 19#include <asm/ipl.h>
779e6e1c
JG
20
21#include "cio.h"
22#include "css.h"
23#include "device.h"
24#include "qdio.h"
25#include "qdio_debug.h"
779e6e1c
JG
26
27MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
28 "Jan Glauber <jang@linux.vnet.ibm.com>");
29MODULE_DESCRIPTION("QDIO base support");
30MODULE_LICENSE("GPL");
31
958c0ba4
JG
32static inline int do_siga_sync(unsigned long schid,
33 unsigned int out_mask, unsigned int in_mask,
34 unsigned int fc)
779e6e1c 35{
958c0ba4
JG
36 register unsigned long __fc asm ("0") = fc;
37 register unsigned long __schid asm ("1") = schid;
779e6e1c
JG
38 register unsigned long out asm ("2") = out_mask;
39 register unsigned long in asm ("3") = in_mask;
40 int cc;
41
42 asm volatile(
43 " siga 0\n"
44 " ipm %0\n"
45 " srl %0,28\n"
46 : "=d" (cc)
47 : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
48 return cc;
49}
50
958c0ba4
JG
51static inline int do_siga_input(unsigned long schid, unsigned int mask,
52 unsigned int fc)
779e6e1c 53{
958c0ba4
JG
54 register unsigned long __fc asm ("0") = fc;
55 register unsigned long __schid asm ("1") = schid;
779e6e1c
JG
56 register unsigned long __mask asm ("2") = mask;
57 int cc;
58
59 asm volatile(
60 " siga 0\n"
61 " ipm %0\n"
62 " srl %0,28\n"
63 : "=d" (cc)
1549d13f 64 : "d" (__fc), "d" (__schid), "d" (__mask) : "cc");
779e6e1c
JG
65 return cc;
66}
67
68/**
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
74 *
1549d13f 75 * Returns condition code.
779e6e1c
JG
76 * Note: For IQDC unicast queues only the highest priority queue is processed.
77 */
78static inline int do_siga_output(unsigned long schid, unsigned long mask,
104ea556 79 unsigned int *bb, unsigned int fc,
80 unsigned long aob)
779e6e1c
JG
81{
82 register unsigned long __fc asm("0") = fc;
83 register unsigned long __schid asm("1") = schid;
84 register unsigned long __mask asm("2") = mask;
104ea556 85 register unsigned long __aob asm("3") = aob;
1549d13f 86 int cc;
779e6e1c
JG
87
88 asm volatile(
89 " siga 0\n"
1549d13f 90 " ipm %0\n"
779e6e1c 91 " srl %0,28\n"
1549d13f
JG
92 : "=d" (cc), "+d" (__fc), "+d" (__aob)
93 : "d" (__schid), "d" (__mask)
94 : "cc");
95 *bb = __fc >> 31;
779e6e1c
JG
96 return cc;
97}
98
99static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
100{
779e6e1c
JG
101 /* all done or next buffer state different */
102 if (ccq == 0 || ccq == 32)
103 return 0;
25f269f1
JG
104 /* no buffer processed */
105 if (ccq == 97)
779e6e1c 106 return 1;
25f269f1
JG
107 /* not all buffers processed */
108 if (ccq == 96)
109 return 2;
779e6e1c 110 /* notify devices immediately */
22f99347 111 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
779e6e1c
JG
112 return -EIO;
113}
114
115/**
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
50f769df 121 * @auto_ack: automatically acknowledge buffers
779e6e1c 122 *
73ac36ea 123 * Returns the number of successfully extracted equal buffer states.
779e6e1c
JG
124 * Stops processing if a state is different from the last buffers state.
125 */
126static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
50f769df 127 int start, int count, int auto_ack)
779e6e1c 128{
25f269f1 129 int rc, tmp_count = count, tmp_start = start, nr = q->nr, retried = 0;
779e6e1c 130 unsigned int ccq = 0;
779e6e1c 131
6486cda6 132 qperf_inc(q, eqbs);
779e6e1c
JG
133
134 if (!q->is_input_q)
135 nr += q->irq_ptr->nr_input_qs;
136again:
50f769df
JG
137 ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
138 auto_ack);
779e6e1c 139 rc = qdio_check_ccq(q, ccq);
25f269f1
JG
140 if (!rc)
141 return count - tmp_count;
22f99347 142
779e6e1c 143 if (rc == 1) {
22f99347 144 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
779e6e1c
JG
145 goto again;
146 }
147
25f269f1 148 if (rc == 2) {
25f269f1
JG
149 qperf_inc(q, eqbs_partial);
150 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
151 tmp_count);
152 /*
153 * Retry once, if that fails bail out and process the
154 * extracted buffers before trying again.
155 */
156 if (!retried++)
157 goto again;
158 else
159 return count - tmp_count;
779e6e1c 160 }
25f269f1
JG
161
162 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
163 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
1549d13f 164 q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE,
7b3cc67d 165 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
25f269f1 166 return 0;
779e6e1c
JG
167}
168
169/**
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
175 *
176 * Returns the number of successfully changed buffers.
177 * Does retrying until the specified count of buffer states is set or an
178 * error occurs.
179 */
180static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
181 int count)
182{
183 unsigned int ccq = 0;
184 int tmp_count = count, tmp_start = start;
185 int nr = q->nr;
186 int rc;
779e6e1c 187
50f769df
JG
188 if (!count)
189 return 0;
6486cda6 190 qperf_inc(q, sqbs);
779e6e1c
JG
191
192 if (!q->is_input_q)
193 nr += q->irq_ptr->nr_input_qs;
194again:
195 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
196 rc = qdio_check_ccq(q, ccq);
25f269f1 197 if (!rc) {
ce1d8014 198 WARN_ON_ONCE(tmp_count);
25f269f1
JG
199 return count - tmp_count;
200 }
201
202 if (rc == 1 || rc == 2) {
22f99347 203 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
6486cda6 204 qperf_inc(q, sqbs_partial);
779e6e1c
JG
205 goto again;
206 }
25f269f1
JG
207
208 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
209 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
1549d13f 210 q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE,
7b3cc67d 211 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
25f269f1 212 return 0;
779e6e1c
JG
213}
214
215/* returns number of examined buffers and their common state in *state */
216static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
50f769df 217 unsigned char *state, unsigned int count,
104ea556 218 int auto_ack, int merge_pending)
779e6e1c
JG
219{
220 unsigned char __state = 0;
221 int i;
222
779e6e1c 223 if (is_qebsm(q))
50f769df 224 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
779e6e1c
JG
225
226 for (i = 0; i < count; i++) {
104ea556 227 if (!__state) {
779e6e1c 228 __state = q->slsb.val[bufnr];
104ea556 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)
233 break;
234 } else if (q->slsb.val[bufnr] != __state)
779e6e1c
JG
235 break;
236 bufnr = next_buf(bufnr);
237 }
238 *state = __state;
239 return i;
240}
241
60b5df2f
JG
242static inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
243 unsigned char *state, int auto_ack)
779e6e1c 244{
104ea556 245 return get_buf_states(q, bufnr, state, 1, auto_ack, 0);
779e6e1c
JG
246}
247
248/* wrap-around safe setting of slsb states, returns number of changed buffers */
249static inline int set_buf_states(struct qdio_q *q, int bufnr,
250 unsigned char state, int count)
251{
252 int i;
253
779e6e1c
JG
254 if (is_qebsm(q))
255 return qdio_do_sqbs(q, state, bufnr, count);
256
257 for (i = 0; i < count; i++) {
258 xchg(&q->slsb.val[bufnr], state);
259 bufnr = next_buf(bufnr);
260 }
261 return count;
262}
263
264static inline int set_buf_state(struct qdio_q *q, int bufnr,
265 unsigned char state)
266{
267 return set_buf_states(q, bufnr, state, 1);
268}
269
270/* set slsb states to initial state */
c4736d96 271static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
779e6e1c
JG
272{
273 struct qdio_q *q;
274 int i;
275
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);
282}
283
60b5df2f 284static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
779e6e1c
JG
285 unsigned int input)
286{
958c0ba4
JG
287 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
288 unsigned int fc = QDIO_SIGA_SYNC;
779e6e1c
JG
289 int cc;
290
7a0b4cbc 291 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
6486cda6 292 qperf_inc(q, siga_sync);
779e6e1c 293
958c0ba4
JG
294 if (is_qebsm(q)) {
295 schid = q->irq_ptr->sch_token;
296 fc |= QDIO_SIGA_QEBSM_FLAG;
297 }
298
299 cc = do_siga_sync(schid, output, input, fc);
110da317 300 if (unlikely(cc))
22f99347 301 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
1549d13f 302 return (cc) ? -EIO : 0;
779e6e1c
JG
303}
304
60b5df2f 305static inline int qdio_siga_sync_q(struct qdio_q *q)
779e6e1c
JG
306{
307 if (q->is_input_q)
308 return qdio_siga_sync(q, 0, q->mask);
309 else
310 return qdio_siga_sync(q, q->mask, 0);
311}
312
104ea556 313static int qdio_siga_output(struct qdio_q *q, unsigned int *busy_bit,
314 unsigned long aob)
779e6e1c 315{
958c0ba4
JG
316 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
317 unsigned int fc = QDIO_SIGA_WRITE;
7a0b4cbc 318 u64 start_time = 0;
be8d97a5 319 int retries = 0, cc;
104ea556 320 unsigned long laob = 0;
321
ec6674c6
EC
322 WARN_ON_ONCE(aob && ((queue_type(q) != QDIO_IQDIO_QFMT) ||
323 !q->u.out.use_cq));
104ea556 324 if (q->u.out.use_cq && aob != 0) {
325 fc = QDIO_SIGA_WRITEQ;
326 laob = aob;
327 }
779e6e1c 328
7a0b4cbc 329 if (is_qebsm(q)) {
779e6e1c 330 schid = q->irq_ptr->sch_token;
958c0ba4 331 fc |= QDIO_SIGA_QEBSM_FLAG;
779e6e1c 332 }
779e6e1c 333again:
104ea556 334 cc = do_siga_output(schid, q->mask, busy_bit, fc, laob);
7a0b4cbc
JG
335
336 /* hipersocket busy condition */
110da317 337 if (unlikely(*busy_bit)) {
be8d97a5 338 retries++;
58eb27cd 339
7a0b4cbc 340 if (!start_time) {
8c071b0f 341 start_time = get_tod_clock_fast();
7a0b4cbc
JG
342 goto again;
343 }
8c071b0f 344 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
779e6e1c
JG
345 goto again;
346 }
be8d97a5
JG
347 if (retries) {
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);
351 }
779e6e1c
JG
352 return cc;
353}
354
355static inline int qdio_siga_input(struct qdio_q *q)
356{
958c0ba4
JG
357 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
358 unsigned int fc = QDIO_SIGA_READ;
779e6e1c
JG
359 int cc;
360
22f99347 361 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
6486cda6 362 qperf_inc(q, siga_read);
779e6e1c 363
958c0ba4
JG
364 if (is_qebsm(q)) {
365 schid = q->irq_ptr->sch_token;
366 fc |= QDIO_SIGA_QEBSM_FLAG;
367 }
368
369 cc = do_siga_input(schid, q->mask, fc);
110da317 370 if (unlikely(cc))
22f99347 371 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
1549d13f 372 return (cc) ? -EIO : 0;
779e6e1c
JG
373}
374
90adac58
JG
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)
377
378static inline void qdio_sync_queues(struct qdio_q *q)
779e6e1c 379{
90adac58
JG
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);
383 else
779e6e1c
JG
384 qdio_siga_sync_q(q);
385}
386
60b5df2f
JG
387int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
388 unsigned char *state)
389{
90adac58
JG
390 if (need_siga_sync(q))
391 qdio_siga_sync_q(q);
104ea556 392 return get_buf_states(q, bufnr, state, 1, 0, 0);
60b5df2f
JG
393}
394
395static inline void qdio_stop_polling(struct qdio_q *q)
779e6e1c 396{
50f769df 397 if (!q->u.in.polling)
779e6e1c 398 return;
50f769df 399
779e6e1c 400 q->u.in.polling = 0;
6486cda6 401 qperf_inc(q, stop_polling);
779e6e1c
JG
402
403 /* show the card that we are not polling anymore */
50f769df 404 if (is_qebsm(q)) {
e85dea0e 405 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
50f769df
JG
406 q->u.in.ack_count);
407 q->u.in.ack_count = 0;
408 } else
e85dea0e 409 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
779e6e1c
JG
410}
411
92bdae5d 412static inline void account_sbals(struct qdio_q *q, unsigned int count)
d307297f 413{
92bdae5d 414 int pos;
d307297f
JG
415
416 q->q_stats.nr_sbal_total += count;
417 if (count == QDIO_MAX_BUFFERS_MASK) {
418 q->q_stats.nr_sbals[7]++;
419 return;
420 }
92bdae5d 421 pos = ilog2(count);
d307297f
JG
422 q->q_stats.nr_sbals[pos]++;
423}
424
bffbbd2d 425static void process_buffer_error(struct qdio_q *q, int count)
779e6e1c 426{
bffbbd2d
JG
427 unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
428 SLSB_P_OUTPUT_NOT_INIT;
429
1549d13f 430 q->qdio_error = QDIO_ERROR_SLSB_STATE;
50f769df
JG
431
432 /* special handling for no target buffer empty */
433 if ((!q->is_input_q &&
3ec90878 434 (q->sbal[q->first_to_check]->element[15].sflags) == 0x10)) {
6486cda6 435 qperf_inc(q, target_full);
1d7e1500 436 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x",
50f769df 437 q->first_to_check);
2768b2de 438 goto set;
50f769df
JG
439 }
440
22f99347
JG
441 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
442 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
50f769df 443 DBF_ERROR("FTC:%3d C:%3d", q->first_to_check, count);
22f99347 444 DBF_ERROR("F14:%2x F15:%2x",
3ec90878
JG
445 q->sbal[q->first_to_check]->element[14].sflags,
446 q->sbal[q->first_to_check]->element[15].sflags);
bffbbd2d 447
2768b2de 448set:
bffbbd2d
JG
449 /*
450 * Interrupts may be avoided as long as the error is present
451 * so change the buffer state immediately to avoid starvation.
452 */
453 set_buf_states(q, q->first_to_check, state, count);
50f769df 454}
779e6e1c 455
50f769df
JG
456static inline void inbound_primed(struct qdio_q *q, int count)
457{
458 int new;
459
1d7e1500 460 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim: %02x", count);
50f769df
JG
461
462 /* for QEBSM the ACK was already set by EQBS */
463 if (is_qebsm(q)) {
464 if (!q->u.in.polling) {
465 q->u.in.polling = 1;
466 q->u.in.ack_count = count;
e85dea0e 467 q->u.in.ack_start = q->first_to_check;
50f769df
JG
468 return;
469 }
470
471 /* delete the previous ACK's */
e85dea0e 472 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
50f769df
JG
473 q->u.in.ack_count);
474 q->u.in.ack_count = count;
e85dea0e 475 q->u.in.ack_start = q->first_to_check;
50f769df
JG
476 return;
477 }
478
479 /*
480 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
481 * or by the next inbound run.
482 */
483 new = add_buf(q->first_to_check, count - 1);
484 if (q->u.in.polling) {
485 /* reset the previous ACK but first set the new one */
486 set_buf_state(q, new, SLSB_P_INPUT_ACK);
e85dea0e 487 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
3fdf1e18 488 } else {
50f769df 489 q->u.in.polling = 1;
3fdf1e18 490 set_buf_state(q, new, SLSB_P_INPUT_ACK);
50f769df
JG
491 }
492
e85dea0e 493 q->u.in.ack_start = new;
50f769df
JG
494 count--;
495 if (!count)
496 return;
6541f7b6
JG
497 /* need to change ALL buffers to get more interrupts */
498 set_buf_states(q, q->first_to_check, SLSB_P_INPUT_NOT_INIT, count);
779e6e1c
JG
499}
500
501static int get_inbound_buffer_frontier(struct qdio_q *q)
502{
503 int count, stop;
6fa1098a 504 unsigned char state = 0;
779e6e1c 505
8c071b0f 506 q->timestamp = get_tod_clock_fast();
a2b86019 507
779e6e1c
JG
508 /*
509 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
510 * would return 0.
511 */
512 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
513 stop = add_buf(q->first_to_check, count);
514
779e6e1c
JG
515 if (q->first_to_check == stop)
516 goto out;
517
36e3e721
JG
518 /*
519 * No siga sync here, as a PCI or we after a thin interrupt
520 * already sync'ed the queues.
521 */
104ea556 522 count = get_buf_states(q, q->first_to_check, &state, count, 1, 0);
779e6e1c
JG
523 if (!count)
524 goto out;
525
526 switch (state) {
527 case SLSB_P_INPUT_PRIMED:
50f769df 528 inbound_primed(q, count);
779e6e1c 529 q->first_to_check = add_buf(q->first_to_check, count);
eddf0d5b 530 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
6486cda6 531 qperf_inc(q, inbound_queue_full);
d307297f
JG
532 if (q->irq_ptr->perf_stat_enabled)
533 account_sbals(q, count);
36e3e721 534 break;
779e6e1c 535 case SLSB_P_INPUT_ERROR:
bffbbd2d 536 process_buffer_error(q, count);
779e6e1c
JG
537 q->first_to_check = add_buf(q->first_to_check, count);
538 atomic_sub(count, &q->nr_buf_used);
d307297f
JG
539 if (q->irq_ptr->perf_stat_enabled)
540 account_sbals_error(q, count);
779e6e1c
JG
541 break;
542 case SLSB_CU_INPUT_EMPTY:
543 case SLSB_P_INPUT_NOT_INIT:
544 case SLSB_P_INPUT_ACK:
d307297f
JG
545 if (q->irq_ptr->perf_stat_enabled)
546 q->q_stats.nr_sbal_nop++;
22f99347 547 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop");
779e6e1c
JG
548 break;
549 default:
ce1d8014 550 WARN_ON_ONCE(1);
779e6e1c
JG
551 }
552out:
779e6e1c
JG
553 return q->first_to_check;
554}
555
60b5df2f 556static int qdio_inbound_q_moved(struct qdio_q *q)
779e6e1c
JG
557{
558 int bufnr;
559
560 bufnr = get_inbound_buffer_frontier(q);
561
1549d13f 562 if (bufnr != q->last_move) {
e85dea0e 563 q->last_move = bufnr;
27d71602 564 if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
1aae0560 565 q->u.in.timestamp = get_tod_clock();
779e6e1c
JG
566 return 1;
567 } else
568 return 0;
569}
570
9a2c160a 571static inline int qdio_inbound_q_done(struct qdio_q *q)
779e6e1c 572{
9a1ce28a 573 unsigned char state = 0;
779e6e1c
JG
574
575 if (!atomic_read(&q->nr_buf_used))
576 return 1;
577
90adac58
JG
578 if (need_siga_sync(q))
579 qdio_siga_sync_q(q);
50f769df 580 get_buf_state(q, q->first_to_check, &state, 0);
9a2c160a 581
4c52228d 582 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
9a2c160a 583 /* more work coming */
779e6e1c
JG
584 return 0;
585
9a2c160a
JG
586 if (is_thinint_irq(q->irq_ptr))
587 return 1;
588
589 /* don't poll under z/VM */
590 if (MACHINE_IS_VM)
779e6e1c
JG
591 return 1;
592
593 /*
594 * At this point we know, that inbound first_to_check
595 * has (probably) not moved (see qdio_inbound_processing).
596 */
8c071b0f 597 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
1d7e1500 598 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
22f99347 599 q->first_to_check);
779e6e1c 600 return 1;
9a2c160a 601 } else
60b5df2f 602 return 0;
60b5df2f
JG
603}
604
104ea556 605static inline int contains_aobs(struct qdio_q *q)
606{
607 return !q->is_input_q && q->u.out.use_cq;
608}
609
104ea556 610static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
611{
612 unsigned char state = 0;
613 int j, b = start;
614
615 if (!contains_aobs(q))
616 return;
617
618 for (j = 0; j < count; ++j) {
619 get_buf_state(q, b, &state, 0);
620 if (state == SLSB_P_OUTPUT_PENDING) {
621 struct qaob *aob = q->u.out.aobs[b];
622 if (aob == NULL)
623 continue;
624
104ea556 625 q->u.out.sbal_state[b].flags |=
626 QDIO_OUTBUF_STATE_FLAG_PENDING;
627 q->u.out.aobs[b] = NULL;
628 } else if (state == SLSB_P_OUTPUT_EMPTY) {
104ea556 629 q->u.out.sbal_state[b].aob = NULL;
630 }
631 b = next_buf(b);
632 }
633}
634
635static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
636 int bufnr)
637{
638 unsigned long phys_aob = 0;
639
640 if (!q->use_cq)
641 goto out;
642
643 if (!q->aobs[bufnr]) {
644 struct qaob *aob = qdio_allocate_aob();
645 q->aobs[bufnr] = aob;
646 }
647 if (q->aobs[bufnr]) {
104ea556 648 q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
649 q->sbal_state[bufnr].aob = q->aobs[bufnr];
650 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
651 phys_aob = virt_to_phys(q->aobs[bufnr]);
ce1d8014 652 WARN_ON_ONCE(phys_aob & 0xFF);
104ea556 653 }
654
655out:
656 return phys_aob;
657}
658
60b5df2f 659static void qdio_kick_handler(struct qdio_q *q)
779e6e1c 660{
9c8a08d7
JG
661 int start = q->first_to_kick;
662 int end = q->first_to_check;
663 int count;
779e6e1c
JG
664
665 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
666 return;
667
9c8a08d7
JG
668 count = sub_buf(end, start);
669
670 if (q->is_input_q) {
6486cda6 671 qperf_inc(q, inbound_handler);
1d7e1500 672 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
bd6e8a16 673 } else {
6486cda6 674 qperf_inc(q, outbound_handler);
1d7e1500
JG
675 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
676 start, count);
bd6e8a16 677 }
9c8a08d7 678
104ea556 679 qdio_handle_aobs(q, start, count);
680
9c8a08d7
JG
681 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
682 q->irq_ptr->int_parm);
779e6e1c
JG
683
684 /* for the next time */
9c8a08d7 685 q->first_to_kick = end;
779e6e1c
JG
686 q->qdio_error = 0;
687}
688
689static void __qdio_inbound_processing(struct qdio_q *q)
690{
6486cda6 691 qperf_inc(q, tasklet_inbound);
f3eb20fa 692
779e6e1c
JG
693 if (!qdio_inbound_q_moved(q))
694 return;
695
9c8a08d7 696 qdio_kick_handler(q);
779e6e1c 697
6486cda6 698 if (!qdio_inbound_q_done(q)) {
779e6e1c 699 /* means poll time is not yet over */
6486cda6 700 qperf_inc(q, tasklet_inbound_resched);
f3eb20fa
JG
701 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) {
702 tasklet_schedule(&q->tasklet);
703 return;
704 }
6486cda6 705 }
779e6e1c
JG
706
707 qdio_stop_polling(q);
708 /*
709 * We need to check again to not lose initiative after
710 * resetting the ACK state.
711 */
6486cda6
JG
712 if (!qdio_inbound_q_done(q)) {
713 qperf_inc(q, tasklet_inbound_resched2);
f3eb20fa
JG
714 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
715 tasklet_schedule(&q->tasklet);
6486cda6 716 }
779e6e1c
JG
717}
718
779e6e1c
JG
719void qdio_inbound_processing(unsigned long data)
720{
721 struct qdio_q *q = (struct qdio_q *)data;
722 __qdio_inbound_processing(q);
723}
724
725static int get_outbound_buffer_frontier(struct qdio_q *q)
726{
727 int count, stop;
6fa1098a 728 unsigned char state = 0;
779e6e1c 729
8c071b0f 730 q->timestamp = get_tod_clock_fast();
a2b86019 731
90adac58
JG
732 if (need_siga_sync(q))
733 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
734 !pci_out_supported(q)) ||
735 (queue_type(q) == QDIO_IQDIO_QFMT &&
736 multicast_outbound(q)))
737 qdio_siga_sync_q(q);
779e6e1c
JG
738
739 /*
740 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
741 * would return 0.
742 */
743 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
744 stop = add_buf(q->first_to_check, count);
779e6e1c 745 if (q->first_to_check == stop)
104ea556 746 goto out;
779e6e1c 747
104ea556 748 count = get_buf_states(q, q->first_to_check, &state, count, 0, 1);
779e6e1c 749 if (!count)
104ea556 750 goto out;
779e6e1c
JG
751
752 switch (state) {
753 case SLSB_P_OUTPUT_EMPTY:
754 /* the adapter got it */
104ea556 755 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
756 "out empty:%1d %02x", q->nr, count);
779e6e1c
JG
757
758 atomic_sub(count, &q->nr_buf_used);
759 q->first_to_check = add_buf(q->first_to_check, count);
d307297f
JG
760 if (q->irq_ptr->perf_stat_enabled)
761 account_sbals(q, count);
104ea556 762
36e3e721 763 break;
779e6e1c 764 case SLSB_P_OUTPUT_ERROR:
bffbbd2d 765 process_buffer_error(q, count);
779e6e1c
JG
766 q->first_to_check = add_buf(q->first_to_check, count);
767 atomic_sub(count, &q->nr_buf_used);
d307297f
JG
768 if (q->irq_ptr->perf_stat_enabled)
769 account_sbals_error(q, count);
779e6e1c
JG
770 break;
771 case SLSB_CU_OUTPUT_PRIMED:
772 /* the adapter has not fetched the output yet */
d307297f
JG
773 if (q->irq_ptr->perf_stat_enabled)
774 q->q_stats.nr_sbal_nop++;
104ea556 775 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
776 q->nr);
779e6e1c
JG
777 break;
778 case SLSB_P_OUTPUT_NOT_INIT:
779 case SLSB_P_OUTPUT_HALTED:
780 break;
781 default:
ce1d8014 782 WARN_ON_ONCE(1);
779e6e1c 783 }
104ea556 784
785out:
779e6e1c
JG
786 return q->first_to_check;
787}
788
789/* all buffers processed? */
790static inline int qdio_outbound_q_done(struct qdio_q *q)
791{
792 return atomic_read(&q->nr_buf_used) == 0;
793}
794
795static inline int qdio_outbound_q_moved(struct qdio_q *q)
796{
797 int bufnr;
798
799 bufnr = get_outbound_buffer_frontier(q);
800
1549d13f 801 if (bufnr != q->last_move) {
e85dea0e 802 q->last_move = bufnr;
22f99347 803 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
779e6e1c
JG
804 return 1;
805 } else
806 return 0;
807}
808
104ea556 809static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
779e6e1c 810{
be8d97a5 811 int retries = 0, cc;
7a0b4cbc 812 unsigned int busy_bit;
779e6e1c
JG
813
814 if (!need_siga_out(q))
d303b6fd 815 return 0;
779e6e1c 816
7a0b4cbc 817 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
be8d97a5 818retry:
6486cda6 819 qperf_inc(q, siga_write);
7a0b4cbc 820
104ea556 821 cc = qdio_siga_output(q, &busy_bit, aob);
7a0b4cbc 822 switch (cc) {
779e6e1c 823 case 0:
779e6e1c 824 break;
7a0b4cbc
JG
825 case 2:
826 if (busy_bit) {
be8d97a5
JG
827 while (++retries < QDIO_BUSY_BIT_RETRIES) {
828 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
829 goto retry;
830 }
831 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
1549d13f
JG
832 cc = -EBUSY;
833 } else {
d303b6fd 834 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
1549d13f
JG
835 cc = -ENOBUFS;
836 }
7a0b4cbc
JG
837 break;
838 case 1:
839 case 3:
840 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
1549d13f 841 cc = -EIO;
7a0b4cbc 842 break;
779e6e1c 843 }
be8d97a5
JG
844 if (retries) {
845 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
846 DBF_ERROR("count:%u", retries);
847 }
d303b6fd 848 return cc;
779e6e1c
JG
849}
850
779e6e1c
JG
851static void __qdio_outbound_processing(struct qdio_q *q)
852{
6486cda6 853 qperf_inc(q, tasklet_outbound);
ce1d8014 854 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
779e6e1c
JG
855
856 if (qdio_outbound_q_moved(q))
9c8a08d7 857 qdio_kick_handler(q);
779e6e1c 858
c38f9608 859 if (queue_type(q) == QDIO_ZFCP_QFMT)
779e6e1c 860 if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
c38f9608 861 goto sched;
779e6e1c 862
779e6e1c
JG
863 if (q->u.out.pci_out_enabled)
864 return;
865
866 /*
867 * Now we know that queue type is either qeth without pci enabled
25f269f1
JG
868 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
869 * is noticed and outbound_handler is called after some time.
779e6e1c
JG
870 */
871 if (qdio_outbound_q_done(q))
872 del_timer(&q->u.out.timer);
6486cda6
JG
873 else
874 if (!timer_pending(&q->u.out.timer))
779e6e1c 875 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
c38f9608
JG
876 return;
877
878sched:
879 if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
880 return;
881 tasklet_schedule(&q->tasklet);
779e6e1c
JG
882}
883
884/* outbound tasklet */
885void qdio_outbound_processing(unsigned long data)
886{
887 struct qdio_q *q = (struct qdio_q *)data;
888 __qdio_outbound_processing(q);
889}
890
891void qdio_outbound_timer(unsigned long data)
892{
893 struct qdio_q *q = (struct qdio_q *)data;
c38f9608
JG
894
895 if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
896 return;
779e6e1c
JG
897 tasklet_schedule(&q->tasklet);
898}
899
60b5df2f 900static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
779e6e1c
JG
901{
902 struct qdio_q *out;
903 int i;
904
905 if (!pci_out_supported(q))
906 return;
907
908 for_each_output_queue(q->irq_ptr, out, i)
909 if (!qdio_outbound_q_done(out))
910 tasklet_schedule(&out->tasklet);
911}
912
60b5df2f
JG
913static void __tiqdio_inbound_processing(struct qdio_q *q)
914{
6486cda6 915 qperf_inc(q, tasklet_inbound);
90adac58
JG
916 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
917 qdio_sync_queues(q);
60b5df2f
JG
918
919 /*
920 * The interrupt could be caused by a PCI request. Check the
921 * PCI capable outbound queues.
922 */
923 qdio_check_outbound_after_thinint(q);
924
925 if (!qdio_inbound_q_moved(q))
926 return;
927
928 qdio_kick_handler(q);
929
9a2c160a 930 if (!qdio_inbound_q_done(q)) {
6486cda6 931 qperf_inc(q, tasklet_inbound_resched);
e2910bcf 932 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) {
60b5df2f 933 tasklet_schedule(&q->tasklet);
e2910bcf
JG
934 return;
935 }
60b5df2f
JG
936 }
937
938 qdio_stop_polling(q);
939 /*
940 * We need to check again to not lose initiative after
941 * resetting the ACK state.
942 */
9a2c160a 943 if (!qdio_inbound_q_done(q)) {
6486cda6 944 qperf_inc(q, tasklet_inbound_resched2);
60b5df2f
JG
945 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
946 tasklet_schedule(&q->tasklet);
947 }
948}
949
950void tiqdio_inbound_processing(unsigned long data)
951{
952 struct qdio_q *q = (struct qdio_q *)data;
953 __tiqdio_inbound_processing(q);
954}
955
779e6e1c
JG
956static inline void qdio_set_state(struct qdio_irq *irq_ptr,
957 enum qdio_irq_states state)
958{
22f99347 959 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
779e6e1c
JG
960
961 irq_ptr->state = state;
962 mb();
963}
964
22f99347 965static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
779e6e1c 966{
779e6e1c 967 if (irb->esw.esw0.erw.cons) {
22f99347
JG
968 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
969 DBF_ERROR_HEX(irb, 64);
970 DBF_ERROR_HEX(irb->ecw, 64);
779e6e1c
JG
971 }
972}
973
974/* PCI interrupt handler */
975static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
976{
977 int i;
978 struct qdio_q *q;
979
c38f9608
JG
980 if (unlikely(irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
981 return;
982
d36deae7
JG
983 for_each_input_queue(irq_ptr, q, i) {
984 if (q->u.in.queue_start_poll) {
985 /* skip if polling is enabled or already in work */
986 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
987 &q->u.in.queue_irq_state)) {
988 qperf_inc(q, int_discarded);
989 continue;
990 }
991 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
992 q->irq_ptr->int_parm);
104ea556 993 } else {
d36deae7 994 tasklet_schedule(&q->tasklet);
104ea556 995 }
d36deae7 996 }
779e6e1c 997
0f308f4f 998 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
779e6e1c
JG
999 return;
1000
1001 for_each_output_queue(irq_ptr, q, i) {
1002 if (qdio_outbound_q_done(q))
1003 continue;
90adac58 1004 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
779e6e1c 1005 qdio_siga_sync_q(q);
779e6e1c
JG
1006 tasklet_schedule(&q->tasklet);
1007 }
1008}
1009
1010static void qdio_handle_activate_check(struct ccw_device *cdev,
1011 unsigned long intparm, int cstat, int dstat)
1012{
1013 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1014 struct qdio_q *q;
dfe5bb50 1015 int count;
779e6e1c 1016
22f99347
JG
1017 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
1018 DBF_ERROR("intp :%lx", intparm);
1019 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
779e6e1c
JG
1020
1021 if (irq_ptr->nr_input_qs) {
1022 q = irq_ptr->input_qs[0];
1023 } else if (irq_ptr->nr_output_qs) {
1024 q = irq_ptr->output_qs[0];
1025 } else {
1026 dump_stack();
1027 goto no_handler;
1028 }
dfe5bb50
SS
1029
1030 count = sub_buf(q->first_to_check, q->first_to_kick);
1549d13f 1031 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
dfe5bb50 1032 q->nr, q->first_to_kick, count, irq_ptr->int_parm);
779e6e1c
JG
1033no_handler:
1034 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
3ab121ab
MH
1035 /*
1036 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1037 * Therefore we call the LGR detection function here.
1038 */
1039 lgr_info_log();
779e6e1c
JG
1040}
1041
4c575423
JG
1042static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1043 int dstat)
779e6e1c
JG
1044{
1045 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1046
4c575423 1047 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
779e6e1c 1048
4c575423 1049 if (cstat)
779e6e1c 1050 goto error;
4c575423 1051 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
779e6e1c 1052 goto error;
4c575423
JG
1053 if (!(dstat & DEV_STAT_DEV_END))
1054 goto error;
1055 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1056 return;
1057
779e6e1c 1058error:
22f99347
JG
1059 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
1060 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
779e6e1c 1061 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
779e6e1c
JG
1062}
1063
1064/* qdio interrupt handler */
1065void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1066 struct irb *irb)
1067{
1068 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
9080c924 1069 struct subchannel_id schid;
779e6e1c 1070 int cstat, dstat;
779e6e1c 1071
779e6e1c 1072 if (!intparm || !irq_ptr) {
9080c924
SO
1073 ccw_device_get_schid(cdev, &schid);
1074 DBF_ERROR("qint:%4x", schid.sch_no);
779e6e1c
JG
1075 return;
1076 }
1077
09a308f3
JG
1078 if (irq_ptr->perf_stat_enabled)
1079 irq_ptr->perf_stat.qdio_int++;
1080
779e6e1c 1081 if (IS_ERR(irb)) {
ce1d8014
JG
1082 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
1083 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1084 wake_up(&cdev->private->wait_q);
1085 return;
779e6e1c 1086 }
22f99347 1087 qdio_irq_check_sense(irq_ptr, irb);
779e6e1c
JG
1088 cstat = irb->scsw.cmd.cstat;
1089 dstat = irb->scsw.cmd.dstat;
1090
1091 switch (irq_ptr->state) {
1092 case QDIO_IRQ_STATE_INACTIVE:
1093 qdio_establish_handle_irq(cdev, cstat, dstat);
1094 break;
779e6e1c
JG
1095 case QDIO_IRQ_STATE_CLEANUP:
1096 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1097 break;
779e6e1c
JG
1098 case QDIO_IRQ_STATE_ESTABLISHED:
1099 case QDIO_IRQ_STATE_ACTIVE:
1100 if (cstat & SCHN_STAT_PCI) {
1101 qdio_int_handler_pci(irq_ptr);
779e6e1c
JG
1102 return;
1103 }
4c575423 1104 if (cstat || dstat)
779e6e1c
JG
1105 qdio_handle_activate_check(cdev, intparm, cstat,
1106 dstat);
4c575423 1107 break;
959153d3
JG
1108 case QDIO_IRQ_STATE_STOPPED:
1109 break;
779e6e1c 1110 default:
ce1d8014 1111 WARN_ON_ONCE(1);
779e6e1c
JG
1112 }
1113 wake_up(&cdev->private->wait_q);
1114}
1115
1116/**
1117 * qdio_get_ssqd_desc - get qdio subchannel description
1118 * @cdev: ccw device to get description for
bbd50e17 1119 * @data: where to store the ssqd
779e6e1c 1120 *
bbd50e17
JG
1121 * Returns 0 or an error code. The results of the chsc are stored in the
1122 * specified structure.
779e6e1c 1123 */
bbd50e17
JG
1124int qdio_get_ssqd_desc(struct ccw_device *cdev,
1125 struct qdio_ssqd_desc *data)
779e6e1c 1126{
9080c924 1127 struct subchannel_id schid;
779e6e1c 1128
bbd50e17
JG
1129 if (!cdev || !cdev->private)
1130 return -EINVAL;
1131
9080c924
SO
1132 ccw_device_get_schid(cdev, &schid);
1133 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1134 return qdio_setup_get_ssqd(NULL, &schid, data);
779e6e1c
JG
1135}
1136EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1137
779e6e1c
JG
1138static void qdio_shutdown_queues(struct ccw_device *cdev)
1139{
1140 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1141 struct qdio_q *q;
1142 int i;
1143
1144 for_each_input_queue(irq_ptr, q, i)
c38f9608 1145 tasklet_kill(&q->tasklet);
779e6e1c
JG
1146
1147 for_each_output_queue(irq_ptr, q, i) {
779e6e1c 1148 del_timer(&q->u.out.timer);
c38f9608 1149 tasklet_kill(&q->tasklet);
779e6e1c
JG
1150 }
1151}
1152
1153/**
1154 * qdio_shutdown - shut down a qdio subchannel
1155 * @cdev: associated ccw device
1156 * @how: use halt or clear to shutdown
1157 */
1158int qdio_shutdown(struct ccw_device *cdev, int how)
1159{
22f99347 1160 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
9080c924 1161 struct subchannel_id schid;
779e6e1c
JG
1162 int rc;
1163 unsigned long flags;
779e6e1c 1164
779e6e1c
JG
1165 if (!irq_ptr)
1166 return -ENODEV;
1167
ce1d8014 1168 WARN_ON_ONCE(irqs_disabled());
9080c924
SO
1169 ccw_device_get_schid(cdev, &schid);
1170 DBF_EVENT("qshutdown:%4x", schid.sch_no);
22f99347 1171
779e6e1c
JG
1172 mutex_lock(&irq_ptr->setup_mutex);
1173 /*
1174 * Subchannel was already shot down. We cannot prevent being called
1175 * twice since cio may trigger a shutdown asynchronously.
1176 */
1177 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1178 mutex_unlock(&irq_ptr->setup_mutex);
1179 return 0;
1180 }
1181
c38f9608
JG
1182 /*
1183 * Indicate that the device is going down. Scheduling the queue
1184 * tasklets is forbidden from here on.
1185 */
1186 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1187
779e6e1c
JG
1188 tiqdio_remove_input_queues(irq_ptr);
1189 qdio_shutdown_queues(cdev);
aa2383f8 1190 qdio_shutdown_debug_entries(irq_ptr);
779e6e1c
JG
1191
1192 /* cleanup subchannel */
1193 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1194
1195 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1196 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1197 else
1198 /* default behaviour is halt */
1199 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1200 if (rc) {
22f99347
JG
1201 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1202 DBF_ERROR("rc:%4d", rc);
779e6e1c
JG
1203 goto no_cleanup;
1204 }
1205
1206 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1207 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1208 wait_event_interruptible_timeout(cdev->private->wait_q,
1209 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1210 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1211 10 * HZ);
1212 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1213
1214no_cleanup:
1215 qdio_shutdown_thinint(irq_ptr);
1216
1217 /* restore interrupt handler */
1218 if ((void *)cdev->handler == (void *)qdio_int_handler)
1219 cdev->handler = irq_ptr->orig_handler;
1220 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1221
1222 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1223 mutex_unlock(&irq_ptr->setup_mutex);
779e6e1c
JG
1224 if (rc)
1225 return rc;
1226 return 0;
1227}
1228EXPORT_SYMBOL_GPL(qdio_shutdown);
1229
1230/**
1231 * qdio_free - free data structures for a qdio subchannel
1232 * @cdev: associated ccw device
1233 */
1234int qdio_free(struct ccw_device *cdev)
1235{
22f99347 1236 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
9080c924 1237 struct subchannel_id schid;
58eb27cd 1238
779e6e1c
JG
1239 if (!irq_ptr)
1240 return -ENODEV;
1241
9080c924
SO
1242 ccw_device_get_schid(cdev, &schid);
1243 DBF_EVENT("qfree:%4x", schid.sch_no);
613c4e04 1244 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
779e6e1c 1245 mutex_lock(&irq_ptr->setup_mutex);
22f99347 1246
613c4e04 1247 irq_ptr->debug_area = NULL;
779e6e1c
JG
1248 cdev->private->qdio_data = NULL;
1249 mutex_unlock(&irq_ptr->setup_mutex);
1250
1251 qdio_release_memory(irq_ptr);
1252 return 0;
1253}
1254EXPORT_SYMBOL_GPL(qdio_free);
1255
779e6e1c
JG
1256/**
1257 * qdio_allocate - allocate qdio queues and associated data
1258 * @init_data: initialization data
1259 */
1260int qdio_allocate(struct qdio_initialize *init_data)
1261{
9080c924 1262 struct subchannel_id schid;
779e6e1c 1263 struct qdio_irq *irq_ptr;
779e6e1c 1264
9080c924
SO
1265 ccw_device_get_schid(init_data->cdev, &schid);
1266 DBF_EVENT("qallocate:%4x", schid.sch_no);
779e6e1c
JG
1267
1268 if ((init_data->no_input_qs && !init_data->input_handler) ||
1269 (init_data->no_output_qs && !init_data->output_handler))
1270 return -EINVAL;
1271
1272 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1273 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1274 return -EINVAL;
1275
1276 if ((!init_data->input_sbal_addr_array) ||
1277 (!init_data->output_sbal_addr_array))
1278 return -EINVAL;
1279
779e6e1c
JG
1280 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1281 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1282 if (!irq_ptr)
1283 goto out_err;
779e6e1c
JG
1284
1285 mutex_init(&irq_ptr->setup_mutex);
613c4e04
SR
1286 if (qdio_allocate_dbf(init_data, irq_ptr))
1287 goto out_rel;
779e6e1c
JG
1288
1289 /*
1290 * Allocate a page for the chsc calls in qdio_establish.
1291 * Must be pre-allocated since a zfcp recovery will call
1292 * qdio_establish. In case of low memory and swap on a zfcp disk
1293 * we may not be able to allocate memory otherwise.
1294 */
1295 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1296 if (!irq_ptr->chsc_page)
1297 goto out_rel;
1298
1299 /* qdr is used in ccw1.cda which is u32 */
3b8e3004 1300 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
779e6e1c
JG
1301 if (!irq_ptr->qdr)
1302 goto out_rel;
779e6e1c 1303
779e6e1c
JG
1304 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1305 init_data->no_output_qs))
1306 goto out_rel;
1307
1308 init_data->cdev->private->qdio_data = irq_ptr;
1309 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1310 return 0;
1311out_rel:
1312 qdio_release_memory(irq_ptr);
1313out_err:
1314 return -ENOMEM;
1315}
1316EXPORT_SYMBOL_GPL(qdio_allocate);
1317
104ea556 1318static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1319{
1320 struct qdio_q *q = irq_ptr->input_qs[0];
1321 int i, use_cq = 0;
1322
1323 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1324 use_cq = 1;
1325
1326 for_each_output_queue(irq_ptr, q, i) {
1327 if (use_cq) {
1328 if (qdio_enable_async_operation(&q->u.out) < 0) {
1329 use_cq = 0;
1330 continue;
1331 }
1332 } else
1333 qdio_disable_async_operation(&q->u.out);
1334 }
1335 DBF_EVENT("use_cq:%d", use_cq);
1336}
1337
779e6e1c
JG
1338/**
1339 * qdio_establish - establish queues on a qdio subchannel
1340 * @init_data: initialization data
1341 */
1342int qdio_establish(struct qdio_initialize *init_data)
1343{
779e6e1c 1344 struct ccw_device *cdev = init_data->cdev;
9080c924
SO
1345 struct subchannel_id schid;
1346 struct qdio_irq *irq_ptr;
779e6e1c
JG
1347 unsigned long saveflags;
1348 int rc;
1349
9080c924
SO
1350 ccw_device_get_schid(cdev, &schid);
1351 DBF_EVENT("qestablish:%4x", schid.sch_no);
58eb27cd 1352
779e6e1c
JG
1353 irq_ptr = cdev->private->qdio_data;
1354 if (!irq_ptr)
1355 return -ENODEV;
1356
1357 if (cdev->private->state != DEV_STATE_ONLINE)
1358 return -EINVAL;
1359
779e6e1c
JG
1360 mutex_lock(&irq_ptr->setup_mutex);
1361 qdio_setup_irq(init_data);
1362
1363 rc = qdio_establish_thinint(irq_ptr);
1364 if (rc) {
1365 mutex_unlock(&irq_ptr->setup_mutex);
1366 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1367 return rc;
1368 }
1369
1370 /* establish q */
1371 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1372 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1373 irq_ptr->ccw.count = irq_ptr->equeue.count;
1374 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1375
1376 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1377 ccw_device_set_options_mask(cdev, 0);
1378
1379 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1380 if (rc) {
22f99347
JG
1381 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1382 DBF_ERROR("rc:%4x", rc);
779e6e1c
JG
1383 }
1384 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1385
1386 if (rc) {
1387 mutex_unlock(&irq_ptr->setup_mutex);
1388 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1389 return rc;
1390 }
1391
1392 wait_event_interruptible_timeout(cdev->private->wait_q,
1393 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1394 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1395
1396 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1397 mutex_unlock(&irq_ptr->setup_mutex);
1398 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1399 return -EIO;
1400 }
1401
1402 qdio_setup_ssqd_info(irq_ptr);
779e6e1c 1403
104ea556 1404 qdio_detect_hsicq(irq_ptr);
1405
779e6e1c
JG
1406 /* qebsm is now setup if available, initialize buffer states */
1407 qdio_init_buf_states(irq_ptr);
1408
1409 mutex_unlock(&irq_ptr->setup_mutex);
1410 qdio_print_subchannel_info(irq_ptr, cdev);
1411 qdio_setup_debug_entries(irq_ptr, cdev);
1412 return 0;
1413}
1414EXPORT_SYMBOL_GPL(qdio_establish);
1415
1416/**
1417 * qdio_activate - activate queues on a qdio subchannel
1418 * @cdev: associated cdev
1419 */
1420int qdio_activate(struct ccw_device *cdev)
1421{
9080c924 1422 struct subchannel_id schid;
779e6e1c
JG
1423 struct qdio_irq *irq_ptr;
1424 int rc;
1425 unsigned long saveflags;
779e6e1c 1426
9080c924
SO
1427 ccw_device_get_schid(cdev, &schid);
1428 DBF_EVENT("qactivate:%4x", schid.sch_no);
58eb27cd 1429
779e6e1c
JG
1430 irq_ptr = cdev->private->qdio_data;
1431 if (!irq_ptr)
1432 return -ENODEV;
1433
1434 if (cdev->private->state != DEV_STATE_ONLINE)
1435 return -EINVAL;
1436
1437 mutex_lock(&irq_ptr->setup_mutex);
1438 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1439 rc = -EBUSY;
1440 goto out;
1441 }
1442
779e6e1c
JG
1443 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1444 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1445 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1446 irq_ptr->ccw.cda = 0;
1447
1448 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1449 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1450
1451 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1452 0, DOIO_DENY_PREFETCH);
1453 if (rc) {
22f99347
JG
1454 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1455 DBF_ERROR("rc:%4x", rc);
779e6e1c
JG
1456 }
1457 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1458
1459 if (rc)
1460 goto out;
1461
1462 if (is_thinint_irq(irq_ptr))
1463 tiqdio_add_input_queues(irq_ptr);
1464
1465 /* wait for subchannel to become active */
1466 msleep(5);
1467
1468 switch (irq_ptr->state) {
1469 case QDIO_IRQ_STATE_STOPPED:
1470 case QDIO_IRQ_STATE_ERR:
e4c14e20
JG
1471 rc = -EIO;
1472 break;
779e6e1c
JG
1473 default:
1474 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1475 rc = 0;
1476 }
1477out:
1478 mutex_unlock(&irq_ptr->setup_mutex);
1479 return rc;
1480}
1481EXPORT_SYMBOL_GPL(qdio_activate);
1482
1483static inline int buf_in_between(int bufnr, int start, int count)
1484{
1485 int end = add_buf(start, count);
1486
1487 if (end > start) {
1488 if (bufnr >= start && bufnr < end)
1489 return 1;
1490 else
1491 return 0;
1492 }
1493
1494 /* wrap-around case */
1495 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1496 (bufnr < end))
1497 return 1;
1498 else
1499 return 0;
1500}
1501
1502/**
1503 * handle_inbound - reset processed input buffers
1504 * @q: queue containing the buffers
1505 * @callflags: flags
1506 * @bufnr: first buffer to process
1507 * @count: how many buffers are emptied
1508 */
d303b6fd
JG
1509static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1510 int bufnr, int count)
779e6e1c 1511{
dae7fd42 1512 int diff;
779e6e1c 1513
6486cda6
JG
1514 qperf_inc(q, inbound_call);
1515
50f769df
JG
1516 if (!q->u.in.polling)
1517 goto set;
1518
1519 /* protect against stop polling setting an ACK for an emptied slsb */
1520 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1521 /* overwriting everything, just delete polling status */
1522 q->u.in.polling = 0;
1523 q->u.in.ack_count = 0;
1524 goto set;
e85dea0e 1525 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
50f769df 1526 if (is_qebsm(q)) {
e85dea0e 1527 /* partial overwrite, just update ack_start */
50f769df 1528 diff = add_buf(bufnr, count);
e85dea0e 1529 diff = sub_buf(diff, q->u.in.ack_start);
50f769df
JG
1530 q->u.in.ack_count -= diff;
1531 if (q->u.in.ack_count <= 0) {
1532 q->u.in.polling = 0;
1533 q->u.in.ack_count = 0;
50f769df
JG
1534 goto set;
1535 }
e85dea0e 1536 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
50f769df
JG
1537 }
1538 else
1539 /* the only ACK will be deleted, so stop polling */
779e6e1c 1540 q->u.in.polling = 0;
50f769df 1541 }
779e6e1c 1542
50f769df 1543set:
779e6e1c 1544 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
dae7fd42 1545 atomic_add(count, &q->nr_buf_used);
779e6e1c 1546
d303b6fd
JG
1547 if (need_siga_in(q))
1548 return qdio_siga_input(q);
9cb7284f 1549
d303b6fd 1550 return 0;
779e6e1c
JG
1551}
1552
1553/**
1554 * handle_outbound - process filled outbound buffers
1555 * @q: queue containing the buffers
1556 * @callflags: flags
1557 * @bufnr: first buffer to process
1558 * @count: how many buffers are filled
1559 */
d303b6fd
JG
1560static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1561 int bufnr, int count)
779e6e1c 1562{
c26001d4 1563 unsigned char state = 0;
d303b6fd 1564 int used, rc = 0;
779e6e1c 1565
6486cda6 1566 qperf_inc(q, outbound_call);
779e6e1c
JG
1567
1568 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1569 used = atomic_add_return(count, &q->nr_buf_used);
779e6e1c 1570
0195843b
JG
1571 if (used == QDIO_MAX_BUFFERS_PER_Q)
1572 qperf_inc(q, outbound_queue_full);
1573
6486cda6 1574 if (callflags & QDIO_FLAG_PCI_OUT) {
779e6e1c 1575 q->u.out.pci_out_enabled = 1;
6486cda6 1576 qperf_inc(q, pci_request_int);
110da317 1577 } else
779e6e1c
JG
1578 q->u.out.pci_out_enabled = 0;
1579
1580 if (queue_type(q) == QDIO_IQDIO_QFMT) {
104ea556 1581 unsigned long phys_aob = 0;
1582
1583 /* One SIGA-W per buffer required for unicast HSI */
110da317
JG
1584 WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
1585
104ea556 1586 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1587
1588 rc = qdio_kick_outbound_q(q, phys_aob);
90adac58 1589 } else if (need_siga_sync(q)) {
110da317
JG
1590 rc = qdio_siga_sync_q(q);
1591 } else {
1592 /* try to fast requeue buffers */
1593 get_buf_state(q, prev_buf(bufnr), &state, 0);
1594 if (state != SLSB_CU_OUTPUT_PRIMED)
104ea556 1595 rc = qdio_kick_outbound_q(q, 0);
779e6e1c 1596 else
110da317 1597 qperf_inc(q, fast_requeue);
779e6e1c
JG
1598 }
1599
3d6c76ff
JG
1600 /* in case of SIGA errors we must process the error immediately */
1601 if (used >= q->u.out.scan_threshold || rc)
1602 tasklet_schedule(&q->tasklet);
1603 else
1604 /* free the SBALs in case of no further traffic */
1605 if (!timer_pending(&q->u.out.timer))
1606 mod_timer(&q->u.out.timer, jiffies + HZ);
d303b6fd 1607 return rc;
779e6e1c
JG
1608}
1609
1610/**
1611 * do_QDIO - process input or output buffers
1612 * @cdev: associated ccw_device for the qdio subchannel
1613 * @callflags: input or output and special flags from the program
1614 * @q_nr: queue number
1615 * @bufnr: buffer number
1616 * @count: how many buffers to process
1617 */
1618int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
6618241b 1619 int q_nr, unsigned int bufnr, unsigned int count)
779e6e1c
JG
1620{
1621 struct qdio_irq *irq_ptr;
779e6e1c 1622
6618241b 1623 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
779e6e1c
JG
1624 return -EINVAL;
1625
779e6e1c
JG
1626 irq_ptr = cdev->private->qdio_data;
1627 if (!irq_ptr)
1628 return -ENODEV;
1629
1d7e1500
JG
1630 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1631 "do%02x b:%02x c:%02x", callflags, bufnr, count);
779e6e1c
JG
1632
1633 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1549d13f 1634 return -EIO;
9a26513e
JG
1635 if (!count)
1636 return 0;
779e6e1c 1637 if (callflags & QDIO_FLAG_SYNC_INPUT)
d303b6fd
JG
1638 return handle_inbound(irq_ptr->input_qs[q_nr],
1639 callflags, bufnr, count);
779e6e1c 1640 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
d303b6fd
JG
1641 return handle_outbound(irq_ptr->output_qs[q_nr],
1642 callflags, bufnr, count);
1643 return -EINVAL;
779e6e1c
JG
1644}
1645EXPORT_SYMBOL_GPL(do_QDIO);
1646
d36deae7
JG
1647/**
1648 * qdio_start_irq - process input buffers
1649 * @cdev: associated ccw_device for the qdio subchannel
1650 * @nr: input queue number
1651 *
1652 * Return codes
1653 * 0 - success
1654 * 1 - irqs not started since new data is available
1655 */
1656int qdio_start_irq(struct ccw_device *cdev, int nr)
1657{
1658 struct qdio_q *q;
1659 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1660
1661 if (!irq_ptr)
1662 return -ENODEV;
1663 q = irq_ptr->input_qs[nr];
1664
5f4026f8 1665 clear_nonshared_ind(irq_ptr);
d36deae7
JG
1666 qdio_stop_polling(q);
1667 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1668
1669 /*
1670 * We need to check again to not lose initiative after
1671 * resetting the ACK state.
1672 */
5f4026f8 1673 if (test_nonshared_ind(irq_ptr))
d36deae7
JG
1674 goto rescan;
1675 if (!qdio_inbound_q_done(q))
1676 goto rescan;
1677 return 0;
1678
1679rescan:
1680 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1681 &q->u.in.queue_irq_state))
1682 return 0;
1683 else
1684 return 1;
1685
1686}
1687EXPORT_SYMBOL(qdio_start_irq);
1688
1689/**
1690 * qdio_get_next_buffers - process input buffers
1691 * @cdev: associated ccw_device for the qdio subchannel
1692 * @nr: input queue number
1693 * @bufnr: first filled buffer number
1694 * @error: buffers are in error state
1695 *
1696 * Return codes
1697 * < 0 - error
1698 * = 0 - no new buffers found
1699 * > 0 - number of processed buffers
1700 */
1701int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1702 int *error)
1703{
1704 struct qdio_q *q;
1705 int start, end;
1706 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1707
1708 if (!irq_ptr)
1709 return -ENODEV;
1710 q = irq_ptr->input_qs[nr];
d36deae7 1711
d36deae7 1712 /*
90adac58
JG
1713 * Cannot rely on automatic sync after interrupt since queues may
1714 * also be examined without interrupt.
d36deae7 1715 */
90adac58
JG
1716 if (need_siga_sync(q))
1717 qdio_sync_queues(q);
1718
1719 /* check the PCI capable outbound queues. */
d36deae7
JG
1720 qdio_check_outbound_after_thinint(q);
1721
1722 if (!qdio_inbound_q_moved(q))
1723 return 0;
1724
1725 /* Note: upper-layer MUST stop processing immediately here ... */
1726 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1727 return -EIO;
1728
1729 start = q->first_to_kick;
1730 end = q->first_to_check;
1731 *bufnr = start;
1732 *error = q->qdio_error;
1733
1734 /* for the next time */
1735 q->first_to_kick = end;
1736 q->qdio_error = 0;
1737 return sub_buf(end, start);
1738}
1739EXPORT_SYMBOL(qdio_get_next_buffers);
1740
1741/**
1742 * qdio_stop_irq - disable interrupt processing for the device
1743 * @cdev: associated ccw_device for the qdio subchannel
1744 * @nr: input queue number
1745 *
1746 * Return codes
1747 * 0 - interrupts were already disabled
1748 * 1 - interrupts successfully disabled
1749 */
1750int qdio_stop_irq(struct ccw_device *cdev, int nr)
1751{
1752 struct qdio_q *q;
1753 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1754
1755 if (!irq_ptr)
1756 return -ENODEV;
1757 q = irq_ptr->input_qs[nr];
1758
1759 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1760 &q->u.in.queue_irq_state))
1761 return 0;
1762 else
1763 return 1;
1764}
1765EXPORT_SYMBOL(qdio_stop_irq);
1766
1c59a861
EC
1767/**
1768 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1769 * @schid: Subchannel ID.
1770 * @cnc: Boolean Change-Notification Control
1771 * @response: Response code will be stored at this address
1772 * @cb: Callback function will be executed for each element
1773 * of the address list
1774 * @priv: Pointer passed from the caller to qdio_pnso_brinfo()
1775 * @type: Type of the address entry passed to the callback
1776 * @entry: Entry containg the address of the specified type
1777 * @priv: Pointer to pass to the callback function.
1778 *
1779 * Performs "Store-network-bridging-information list" operation and calls
1780 * the callback function for every entry in the list. If "change-
1781 * notification-control" is set, further changes in the address list
1782 * will be reported via the IPA command.
1783 */
1784int qdio_pnso_brinfo(struct subchannel_id schid,
1785 int cnc, u16 *response,
1786 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1787 void *entry),
1788 void *priv)
1789{
1790 struct chsc_pnso_area *rr;
1791 int rc;
1792 u32 prev_instance = 0;
1793 int isfirstblock = 1;
1794 int i, size, elems;
1795
1796 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1797 if (rr == NULL)
1798 return -ENOMEM;
1799 do {
1800 /* on the first iteration, naihdr.resume_token will be zero */
1801 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1802 if (rc != 0 && rc != -EBUSY)
1803 goto out;
1804 if (rr->response.code != 1) {
1805 rc = -EIO;
1806 continue;
1807 } else
1808 rc = 0;
1809
1810 if (cb == NULL)
1811 continue;
1812
1813 size = rr->naihdr.naids;
1814 elems = (rr->response.length -
1815 sizeof(struct chsc_header) -
1816 sizeof(struct chsc_brinfo_naihdr)) /
1817 size;
1818
1819 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1820 /* Inform the caller that they need to scrap */
1821 /* the data that was already reported via cb */
1822 rc = -EAGAIN;
1823 break;
1824 }
1825 isfirstblock = 0;
1826 prev_instance = rr->naihdr.instance;
1827 for (i = 0; i < elems; i++)
1828 switch (size) {
1829 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1830 (*cb)(priv, l3_ipv6_addr,
1831 &rr->entries.l3_ipv6[i]);
1832 break;
1833 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1834 (*cb)(priv, l3_ipv4_addr,
1835 &rr->entries.l3_ipv4[i]);
1836 break;
1837 case sizeof(struct qdio_brinfo_entry_l2):
1838 (*cb)(priv, l2_addr_lnid,
1839 &rr->entries.l2[i]);
1840 break;
1841 default:
1842 WARN_ON_ONCE(1);
1843 rc = -EIO;
1844 goto out;
1845 }
1846 } while (rr->response.code == 0x0107 || /* channel busy */
1847 (rr->response.code == 1 && /* list stored */
1848 /* resume token is non-zero => list incomplete */
1849 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1850 (*response) = rr->response.code;
1851
1852out:
1853 free_page((unsigned long)rr);
1854 return rc;
1855}
1856EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1857
779e6e1c
JG
1858static int __init init_QDIO(void)
1859{
1860 int rc;
1861
aa5c8df3 1862 rc = qdio_debug_init();
779e6e1c
JG
1863 if (rc)
1864 return rc;
aa5c8df3
SO
1865 rc = qdio_setup_init();
1866 if (rc)
1867 goto out_debug;
779e6e1c
JG
1868 rc = tiqdio_allocate_memory();
1869 if (rc)
1870 goto out_cache;
779e6e1c
JG
1871 rc = tiqdio_register_thinints();
1872 if (rc)
aa5c8df3 1873 goto out_ti;
779e6e1c
JG
1874 return 0;
1875
779e6e1c
JG
1876out_ti:
1877 tiqdio_free_memory();
1878out_cache:
1879 qdio_setup_exit();
aa5c8df3
SO
1880out_debug:
1881 qdio_debug_exit();
779e6e1c
JG
1882 return rc;
1883}
1884
1885static void __exit exit_QDIO(void)
1886{
1887 tiqdio_unregister_thinints();
1888 tiqdio_free_memory();
779e6e1c 1889 qdio_setup_exit();
aa5c8df3 1890 qdio_debug_exit();
779e6e1c
JG
1891}
1892
1893module_init(init_QDIO);
1894module_exit(exit_QDIO);
This page took 0.676546 seconds and 5 git commands to generate.