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