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