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