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