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