Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * linux/drivers/s390/cio/qdio.c |
| 4 | * |
| 5 | * Linux for S/390 QDIO base support, Hipersocket base support |
| 6 | * version 2 |
| 7 | * |
| 8 | * Copyright 2000,2002 IBM Corporation |
| 9 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 10 | * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Restriction: only 63 iqdio subchannels would have its own indicator, |
| 13 | * after that, subsequent subchannels share one indicator |
| 14 | * |
| 15 | * |
| 16 | * |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2, or (at your option) |
| 21 | * any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
| 29 | * along with this program; if not, write to the Free Software |
| 30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 31 | */ |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/init.h> |
| 35 | |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/kernel.h> |
| 38 | #include <linux/proc_fs.h> |
| 39 | #include <linux/timer.h> |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 40 | #include <linux/mempool.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #include <asm/ccwdev.h> |
| 43 | #include <asm/io.h> |
| 44 | #include <asm/atomic.h> |
| 45 | #include <asm/semaphore.h> |
| 46 | #include <asm/timex.h> |
| 47 | |
| 48 | #include <asm/debug.h> |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 49 | #include <asm/s390_rdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <asm/qdio.h> |
| 51 | |
| 52 | #include "cio.h" |
| 53 | #include "css.h" |
| 54 | #include "device.h" |
| 55 | #include "airq.h" |
| 56 | #include "qdio.h" |
| 57 | #include "ioasm.h" |
| 58 | #include "chsc.h" |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /****************** MODULE PARAMETER VARIABLES ********************/ |
| 61 | MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>"); |
| 62 | MODULE_DESCRIPTION("QDIO base support version 2, " \ |
| 63 | "Copyright 2000 IBM Corporation"); |
| 64 | MODULE_LICENSE("GPL"); |
| 65 | |
| 66 | /******************** HERE WE GO ***********************************/ |
| 67 | |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 68 | static const char version[] = "QDIO base support version 2"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 70 | static int qdio_performance_stats = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static int proc_perf_file_registration; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static struct qdio_perf_stats perf_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | static int hydra_thinints; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 75 | static int is_passthrough = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static int omit_svs; |
| 77 | |
| 78 | static int indicator_used[INDICATORS_PER_CACHELINE]; |
| 79 | static __u32 * volatile indicators; |
| 80 | static __u32 volatile spare_indicator; |
| 81 | static atomic_t spare_indicator_usecount; |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 82 | #define QDIO_MEMPOOL_SCSSC_ELEMENTS 2 |
| 83 | static mempool_t *qdio_mempool_scssc; |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 84 | static struct kmem_cache *qdio_q_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | static debug_info_t *qdio_dbf_setup; |
| 87 | static debug_info_t *qdio_dbf_sbal; |
| 88 | static debug_info_t *qdio_dbf_trace; |
| 89 | static debug_info_t *qdio_dbf_sense; |
| 90 | #ifdef CONFIG_QDIO_DEBUG |
| 91 | static debug_info_t *qdio_dbf_slsb_out; |
| 92 | static debug_info_t *qdio_dbf_slsb_in; |
| 93 | #endif /* CONFIG_QDIO_DEBUG */ |
| 94 | |
| 95 | /* iQDIO stuff: */ |
| 96 | static volatile struct qdio_q *tiq_list=NULL; /* volatile as it could change |
| 97 | during a while loop */ |
| 98 | static DEFINE_SPINLOCK(ttiq_list_lock); |
| 99 | static int register_thinint_result; |
| 100 | static void tiqdio_tl(unsigned long); |
| 101 | static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0); |
| 102 | |
| 103 | /* not a macro, as one of the arguments is atomic_read */ |
| 104 | static inline int |
| 105 | qdio_min(int a,int b) |
| 106 | { |
| 107 | if (a<b) |
| 108 | return a; |
| 109 | else |
| 110 | return b; |
| 111 | } |
| 112 | |
| 113 | /***************** SCRUBBER HELPER ROUTINES **********************/ |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 114 | #ifdef CONFIG_64BIT |
| 115 | static inline void qdio_perf_stat_inc(atomic64_t *count) |
| 116 | { |
| 117 | if (qdio_performance_stats) |
| 118 | atomic64_inc(count); |
| 119 | } |
| 120 | |
| 121 | static inline void qdio_perf_stat_dec(atomic64_t *count) |
| 122 | { |
| 123 | if (qdio_performance_stats) |
| 124 | atomic64_dec(count); |
| 125 | } |
| 126 | #else /* CONFIG_64BIT */ |
| 127 | static inline void qdio_perf_stat_inc(atomic_t *count) |
| 128 | { |
| 129 | if (qdio_performance_stats) |
| 130 | atomic_inc(count); |
| 131 | } |
| 132 | |
| 133 | static inline void qdio_perf_stat_dec(atomic_t *count) |
| 134 | { |
| 135 | if (qdio_performance_stats) |
| 136 | atomic_dec(count); |
| 137 | } |
| 138 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Al Viro | a46206e | 2005-08-25 23:03:35 +0100 | [diff] [blame] | 140 | static inline __u64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | qdio_get_micros(void) |
| 142 | { |
Frank Pavlic | 47addc8 | 2006-09-20 15:59:03 +0200 | [diff] [blame] | 143 | return (get_clock() >> 12); /* time>>12 is microseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
| 147 | * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve |
| 148 | * the q in any case, so that we'll not be interrupted when we are in |
| 149 | * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost |
| 150 | * ever works (last famous words) |
| 151 | */ |
| 152 | static inline int |
| 153 | qdio_reserve_q(struct qdio_q *q) |
| 154 | { |
| 155 | return atomic_add_return(1,&q->use_count) - 1; |
| 156 | } |
| 157 | |
| 158 | static inline void |
| 159 | qdio_release_q(struct qdio_q *q) |
| 160 | { |
| 161 | atomic_dec(&q->use_count); |
| 162 | } |
| 163 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 164 | /*check ccq */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 165 | static int |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 166 | qdio_check_ccq(struct qdio_q *q, unsigned int ccq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 168 | char dbf_text[15]; |
| 169 | |
Frank Pavlic | 6cbed91 | 2007-07-17 13:36:04 +0200 | [diff] [blame] | 170 | if (ccq == 0 || ccq == 32) |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 171 | return 0; |
Frank Pavlic | 6cbed91 | 2007-07-17 13:36:04 +0200 | [diff] [blame] | 172 | if (ccq == 96 || ccq == 97) |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 173 | return 1; |
| 174 | /*notify devices immediately*/ |
| 175 | sprintf(dbf_text,"%d", ccq); |
| 176 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 177 | return -EIO; |
| 178 | } |
| 179 | /* EQBS: extract buffer states */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 180 | static int |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 181 | qdio_do_eqbs(struct qdio_q *q, unsigned char *state, |
| 182 | unsigned int *start, unsigned int *cnt) |
| 183 | { |
| 184 | struct qdio_irq *irq; |
| 185 | unsigned int tmp_cnt, q_no, ccq; |
| 186 | int rc ; |
| 187 | char dbf_text[15]; |
| 188 | |
| 189 | ccq = 0; |
| 190 | tmp_cnt = *cnt; |
| 191 | irq = (struct qdio_irq*)q->irq_ptr; |
| 192 | q_no = q->q_no; |
| 193 | if(!q->is_input_q) |
| 194 | q_no += irq->no_input_qs; |
Frank Pavlic | 15c7369 | 2006-02-20 18:28:12 -0800 | [diff] [blame] | 195 | again: |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 196 | ccq = do_eqbs(irq->sch_token, state, q_no, start, cnt); |
| 197 | rc = qdio_check_ccq(q, ccq); |
Klaus D. Wacker | f276730 | 2007-08-22 13:51:38 +0200 | [diff] [blame^] | 198 | if ((ccq == 96) && (tmp_cnt != *cnt)) |
| 199 | rc = 0; |
Frank Pavlic | 15c7369 | 2006-02-20 18:28:12 -0800 | [diff] [blame] | 200 | if (rc == 1) { |
| 201 | QDIO_DBF_TEXT5(1,trace,"eqAGAIN"); |
| 202 | goto again; |
| 203 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 204 | if (rc < 0) { |
| 205 | QDIO_DBF_TEXT2(1,trace,"eqberr"); |
| 206 | sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt, *cnt, ccq, q_no); |
| 207 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 208 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| |
| 209 | QDIO_STATUS_LOOK_FOR_ERROR, |
| 210 | 0, 0, 0, -1, -1, q->int_parm); |
| 211 | return 0; |
| 212 | } |
| 213 | return (tmp_cnt - *cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 216 | /* SQBS: set buffer states */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 217 | static int |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 218 | qdio_do_sqbs(struct qdio_q *q, unsigned char state, |
| 219 | unsigned int *start, unsigned int *cnt) |
| 220 | { |
| 221 | struct qdio_irq *irq; |
| 222 | unsigned int tmp_cnt, q_no, ccq; |
| 223 | int rc; |
| 224 | char dbf_text[15]; |
| 225 | |
| 226 | ccq = 0; |
| 227 | tmp_cnt = *cnt; |
| 228 | irq = (struct qdio_irq*)q->irq_ptr; |
| 229 | q_no = q->q_no; |
| 230 | if(!q->is_input_q) |
| 231 | q_no += irq->no_input_qs; |
Frank Pavlic | 15c7369 | 2006-02-20 18:28:12 -0800 | [diff] [blame] | 232 | again: |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 233 | ccq = do_sqbs(irq->sch_token, state, q_no, start, cnt); |
| 234 | rc = qdio_check_ccq(q, ccq); |
Frank Pavlic | 15c7369 | 2006-02-20 18:28:12 -0800 | [diff] [blame] | 235 | if (rc == 1) { |
| 236 | QDIO_DBF_TEXT5(1,trace,"sqAGAIN"); |
| 237 | goto again; |
| 238 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 239 | if (rc < 0) { |
Ursula Braun | dcc49d4 | 2007-03-19 13:18:12 +0100 | [diff] [blame] | 240 | QDIO_DBF_TEXT3(1,trace,"sqberr"); |
| 241 | sprintf(dbf_text,"%2x,%2x",tmp_cnt,*cnt); |
| 242 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
| 243 | sprintf(dbf_text,"%d,%d",ccq,q_no); |
| 244 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 245 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| |
| 246 | QDIO_STATUS_LOOK_FOR_ERROR, |
| 247 | 0, 0, 0, -1, -1, q->int_parm); |
| 248 | return 0; |
| 249 | } |
| 250 | return (tmp_cnt - *cnt); |
| 251 | } |
| 252 | |
| 253 | static inline int |
| 254 | qdio_set_slsb(struct qdio_q *q, unsigned int *bufno, |
| 255 | unsigned char state, unsigned int *count) |
| 256 | { |
| 257 | volatile char *slsb; |
| 258 | struct qdio_irq *irq; |
| 259 | |
| 260 | irq = (struct qdio_irq*)q->irq_ptr; |
| 261 | if (!irq->is_qebsm) { |
| 262 | slsb = (char *)&q->slsb.acc.val[(*bufno)]; |
| 263 | xchg(slsb, state); |
| 264 | return 1; |
| 265 | } |
| 266 | return qdio_do_sqbs(q, state, bufno, count); |
| 267 | } |
| 268 | |
| 269 | #ifdef CONFIG_QDIO_DEBUG |
| 270 | static inline void |
| 271 | qdio_trace_slsb(struct qdio_q *q) |
| 272 | { |
| 273 | if (q->queue_type==QDIO_TRACE_QTYPE) { |
| 274 | if (q->is_input_q) |
| 275 | QDIO_DBF_HEX2(0,slsb_in,&q->slsb, |
| 276 | QDIO_MAX_BUFFERS_PER_Q); |
| 277 | else |
| 278 | QDIO_DBF_HEX2(0,slsb_out,&q->slsb, |
| 279 | QDIO_MAX_BUFFERS_PER_Q); |
| 280 | } |
| 281 | } |
| 282 | #endif |
| 283 | |
| 284 | static inline int |
| 285 | set_slsb(struct qdio_q *q, unsigned int *bufno, |
| 286 | unsigned char state, unsigned int *count) |
| 287 | { |
| 288 | int rc; |
| 289 | #ifdef CONFIG_QDIO_DEBUG |
| 290 | qdio_trace_slsb(q); |
| 291 | #endif |
| 292 | rc = qdio_set_slsb(q, bufno, state, count); |
| 293 | #ifdef CONFIG_QDIO_DEBUG |
| 294 | qdio_trace_slsb(q); |
| 295 | #endif |
| 296 | return rc; |
| 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | static inline int |
| 299 | qdio_siga_sync(struct qdio_q *q, unsigned int gpr2, |
| 300 | unsigned int gpr3) |
| 301 | { |
| 302 | int cc; |
| 303 | |
| 304 | QDIO_DBF_TEXT4(0,trace,"sigasync"); |
| 305 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 306 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 307 | qdio_perf_stat_inc(&perf_stats.siga_syncs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 309 | cc = do_siga_sync(q->schid, gpr2, gpr3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (cc) |
| 311 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); |
| 312 | |
| 313 | return cc; |
| 314 | } |
| 315 | |
| 316 | static inline int |
| 317 | qdio_siga_sync_q(struct qdio_q *q) |
| 318 | { |
| 319 | if (q->is_input_q) |
| 320 | return qdio_siga_sync(q, 0, q->mask); |
| 321 | return qdio_siga_sync(q, q->mask, 0); |
| 322 | } |
| 323 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 324 | static int |
| 325 | __do_siga_output(struct qdio_q *q, unsigned int *busy_bit) |
| 326 | { |
| 327 | struct qdio_irq *irq; |
| 328 | unsigned int fc = 0; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 329 | unsigned long schid; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 330 | |
| 331 | irq = (struct qdio_irq *) q->irq_ptr; |
| 332 | if (!irq->is_qebsm) |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 333 | schid = *((u32 *)&q->schid); |
| 334 | else { |
| 335 | schid = irq->sch_token; |
| 336 | fc |= 0x80; |
| 337 | } |
| 338 | return do_siga_output(schid, q->mask, busy_bit, fc); |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* |
| 342 | * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns |
| 343 | * an access exception |
| 344 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 345 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | qdio_siga_output(struct qdio_q *q) |
| 347 | { |
| 348 | int cc; |
| 349 | __u32 busy_bit; |
| 350 | __u64 start_time=0; |
| 351 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 352 | qdio_perf_stat_inc(&perf_stats.siga_outs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | QDIO_DBF_TEXT4(0,trace,"sigaout"); |
| 355 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 356 | |
| 357 | for (;;) { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 358 | cc = __do_siga_output(q, &busy_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit); |
| 360 | if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) { |
| 361 | if (!start_time) |
| 362 | start_time=NOW; |
| 363 | if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE) |
| 364 | break; |
| 365 | } else |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | if ((cc==2) && (busy_bit)) |
| 370 | cc |= QDIO_SIGA_ERROR_B_BIT_SET; |
| 371 | |
| 372 | if (cc) |
| 373 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); |
| 374 | |
| 375 | return cc; |
| 376 | } |
| 377 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 378 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | qdio_siga_input(struct qdio_q *q) |
| 380 | { |
| 381 | int cc; |
| 382 | |
| 383 | QDIO_DBF_TEXT4(0,trace,"sigain"); |
| 384 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 385 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 386 | qdio_perf_stat_inc(&perf_stats.siga_ins); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 388 | cc = do_siga_input(q->schid, q->mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | if (cc) |
| 391 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); |
| 392 | |
| 393 | return cc; |
| 394 | } |
| 395 | |
| 396 | /* locked by the locks in qdio_activate and qdio_cleanup */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 397 | static __u32 * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | qdio_get_indicator(void) |
| 399 | { |
| 400 | int i; |
| 401 | |
| 402 | for (i=1;i<INDICATORS_PER_CACHELINE;i++) |
| 403 | if (!indicator_used[i]) { |
| 404 | indicator_used[i]=1; |
| 405 | return indicators+i; |
| 406 | } |
| 407 | atomic_inc(&spare_indicator_usecount); |
| 408 | return (__u32 * volatile) &spare_indicator; |
| 409 | } |
| 410 | |
| 411 | /* locked by the locks in qdio_activate and qdio_cleanup */ |
| 412 | static void |
| 413 | qdio_put_indicator(__u32 *addr) |
| 414 | { |
| 415 | int i; |
| 416 | |
| 417 | if ( (addr) && (addr!=&spare_indicator) ) { |
| 418 | i=addr-indicators; |
| 419 | indicator_used[i]=0; |
| 420 | } |
| 421 | if (addr == &spare_indicator) |
| 422 | atomic_dec(&spare_indicator_usecount); |
| 423 | } |
| 424 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 425 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | tiqdio_clear_summary_bit(__u32 *location) |
| 427 | { |
| 428 | QDIO_DBF_TEXT5(0,trace,"clrsummb"); |
| 429 | QDIO_DBF_HEX5(0,trace,&location,sizeof(void*)); |
| 430 | |
| 431 | xchg(location,0); |
| 432 | } |
| 433 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 434 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | tiqdio_set_summary_bit(__u32 *location) |
| 436 | { |
| 437 | QDIO_DBF_TEXT5(0,trace,"setsummb"); |
| 438 | QDIO_DBF_HEX5(0,trace,&location,sizeof(void*)); |
| 439 | |
| 440 | xchg(location,-1); |
| 441 | } |
| 442 | |
| 443 | static inline void |
| 444 | tiqdio_sched_tl(void) |
| 445 | { |
| 446 | tasklet_hi_schedule(&tiqdio_tasklet); |
| 447 | } |
| 448 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 449 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | qdio_mark_tiq(struct qdio_q *q) |
| 451 | { |
| 452 | unsigned long flags; |
| 453 | |
| 454 | QDIO_DBF_TEXT4(0,trace,"mark iq"); |
| 455 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 456 | |
| 457 | spin_lock_irqsave(&ttiq_list_lock,flags); |
| 458 | if (unlikely(atomic_read(&q->is_in_shutdown))) |
| 459 | goto out_unlock; |
| 460 | |
| 461 | if (!q->is_input_q) |
| 462 | goto out_unlock; |
| 463 | |
| 464 | if ((q->list_prev) || (q->list_next)) |
| 465 | goto out_unlock; |
| 466 | |
| 467 | if (!tiq_list) { |
| 468 | tiq_list=q; |
| 469 | q->list_prev=q; |
| 470 | q->list_next=q; |
| 471 | } else { |
| 472 | q->list_next=tiq_list; |
| 473 | q->list_prev=tiq_list->list_prev; |
| 474 | tiq_list->list_prev->list_next=q; |
| 475 | tiq_list->list_prev=q; |
| 476 | } |
| 477 | spin_unlock_irqrestore(&ttiq_list_lock,flags); |
| 478 | |
| 479 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 480 | tiqdio_sched_tl(); |
| 481 | return; |
| 482 | out_unlock: |
| 483 | spin_unlock_irqrestore(&ttiq_list_lock,flags); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | static inline void |
| 488 | qdio_mark_q(struct qdio_q *q) |
| 489 | { |
| 490 | QDIO_DBF_TEXT4(0,trace,"mark q"); |
| 491 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 492 | |
| 493 | if (unlikely(atomic_read(&q->is_in_shutdown))) |
| 494 | return; |
| 495 | |
| 496 | tasklet_schedule(&q->tasklet); |
| 497 | } |
| 498 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 499 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | qdio_stop_polling(struct qdio_q *q) |
| 501 | { |
| 502 | #ifdef QDIO_USE_PROCESSING_STATE |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 503 | unsigned int tmp, gsf, count = 1; |
| 504 | unsigned char state = 0; |
| 505 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 507 | if (!atomic_xchg(&q->polling,0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | return 1; |
| 509 | |
| 510 | QDIO_DBF_TEXT4(0,trace,"stoppoll"); |
| 511 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 512 | |
| 513 | /* show the card that we are not polling anymore */ |
| 514 | if (!q->is_input_q) |
| 515 | return 1; |
| 516 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 517 | tmp = gsf = GET_SAVED_FRONTIER(q); |
| 518 | tmp = ((tmp + QDIO_MAX_BUFFERS_PER_Q-1) & (QDIO_MAX_BUFFERS_PER_Q-1) ); |
| 519 | set_slsb(q, &tmp, SLSB_P_INPUT_NOT_INIT, &count); |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* |
| 522 | * we don't issue this SYNC_MEMORY, as we trust Rick T and |
| 523 | * moreover will not use the PROCESSING state under VM, so |
| 524 | * q->polling was 0 anyway |
| 525 | */ |
| 526 | /*SYNC_MEMORY;*/ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 527 | if (irq->is_qebsm) { |
| 528 | count = 1; |
| 529 | qdio_do_eqbs(q, &state, &gsf, &count); |
| 530 | } else |
| 531 | state = q->slsb.acc.val[gsf]; |
| 532 | if (state != SLSB_P_INPUT_PRIMED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return 1; |
| 534 | /* |
| 535 | * set our summary bit again, as otherwise there is a |
| 536 | * small window we can miss between resetting it and |
| 537 | * checking for PRIMED state |
| 538 | */ |
| 539 | if (q->is_thinint_q) |
| 540 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 541 | return 0; |
| 542 | |
| 543 | #else /* QDIO_USE_PROCESSING_STATE */ |
| 544 | return 1; |
| 545 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * see the comment in do_QDIO and before qdio_reserve_q about the |
| 550 | * sophisticated locking outside of unmark_q, so that we don't need to |
| 551 | * disable the interrupts :-) |
| 552 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 553 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | qdio_unmark_q(struct qdio_q *q) |
| 555 | { |
| 556 | unsigned long flags; |
| 557 | |
| 558 | QDIO_DBF_TEXT4(0,trace,"unmark q"); |
| 559 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 560 | |
| 561 | if ((!q->list_prev)||(!q->list_next)) |
| 562 | return; |
| 563 | |
| 564 | if ((q->is_thinint_q)&&(q->is_input_q)) { |
| 565 | /* iQDIO */ |
| 566 | spin_lock_irqsave(&ttiq_list_lock,flags); |
| 567 | /* in case cleanup has done this already and simultanously |
| 568 | * qdio_unmark_q is called from the interrupt handler, we've |
| 569 | * got to check this in this specific case again */ |
| 570 | if ((!q->list_prev)||(!q->list_next)) |
| 571 | goto out; |
| 572 | if (q->list_next==q) { |
| 573 | /* q was the only interesting q */ |
| 574 | tiq_list=NULL; |
| 575 | q->list_next=NULL; |
| 576 | q->list_prev=NULL; |
| 577 | } else { |
| 578 | q->list_next->list_prev=q->list_prev; |
| 579 | q->list_prev->list_next=q->list_next; |
| 580 | tiq_list=q->list_next; |
| 581 | q->list_next=NULL; |
| 582 | q->list_prev=NULL; |
| 583 | } |
| 584 | out: |
| 585 | spin_unlock_irqrestore(&ttiq_list_lock,flags); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | static inline unsigned long |
| 590 | tiqdio_clear_global_summary(void) |
| 591 | { |
| 592 | unsigned long time; |
| 593 | |
| 594 | QDIO_DBF_TEXT5(0,trace,"clrglobl"); |
| 595 | |
| 596 | time = do_clear_global_summary(); |
| 597 | |
| 598 | QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long)); |
| 599 | |
| 600 | return time; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /************************* OUTBOUND ROUTINES *******************************/ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 605 | static int |
| 606 | qdio_qebsm_get_outbound_buffer_frontier(struct qdio_q *q) |
| 607 | { |
| 608 | struct qdio_irq *irq; |
| 609 | unsigned char state; |
| 610 | unsigned int cnt, count, ftc; |
| 611 | |
| 612 | irq = (struct qdio_irq *) q->irq_ptr; |
| 613 | if ((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis)) |
| 614 | SYNC_MEMORY; |
| 615 | |
| 616 | ftc = q->first_to_check; |
| 617 | count = qdio_min(atomic_read(&q->number_of_buffers_used), |
| 618 | (QDIO_MAX_BUFFERS_PER_Q-1)); |
| 619 | if (count == 0) |
| 620 | return q->first_to_check; |
| 621 | cnt = qdio_do_eqbs(q, &state, &ftc, &count); |
| 622 | if (cnt == 0) |
| 623 | return q->first_to_check; |
| 624 | switch (state) { |
| 625 | case SLSB_P_OUTPUT_ERROR: |
| 626 | QDIO_DBF_TEXT3(0,trace,"outperr"); |
| 627 | atomic_sub(cnt , &q->number_of_buffers_used); |
| 628 | if (q->qdio_error) |
| 629 | q->error_status_flags |= |
| 630 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; |
| 631 | q->qdio_error = SLSB_P_OUTPUT_ERROR; |
| 632 | q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR; |
| 633 | q->first_to_check = ftc; |
| 634 | break; |
| 635 | case SLSB_P_OUTPUT_EMPTY: |
| 636 | QDIO_DBF_TEXT5(0,trace,"outpempt"); |
| 637 | atomic_sub(cnt, &q->number_of_buffers_used); |
| 638 | q->first_to_check = ftc; |
| 639 | break; |
| 640 | case SLSB_CU_OUTPUT_PRIMED: |
| 641 | /* all buffers primed */ |
| 642 | QDIO_DBF_TEXT5(0,trace,"outpprim"); |
| 643 | break; |
| 644 | default: |
| 645 | break; |
| 646 | } |
| 647 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); |
| 648 | return q->first_to_check; |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | qdio_qebsm_get_inbound_buffer_frontier(struct qdio_q *q) |
| 653 | { |
| 654 | struct qdio_irq *irq; |
| 655 | unsigned char state; |
| 656 | int tmp, ftc, count, cnt; |
| 657 | char dbf_text[15]; |
| 658 | |
| 659 | |
| 660 | irq = (struct qdio_irq *) q->irq_ptr; |
| 661 | ftc = q->first_to_check; |
| 662 | count = qdio_min(atomic_read(&q->number_of_buffers_used), |
| 663 | (QDIO_MAX_BUFFERS_PER_Q-1)); |
| 664 | if (count == 0) |
| 665 | return q->first_to_check; |
| 666 | cnt = qdio_do_eqbs(q, &state, &ftc, &count); |
| 667 | if (cnt == 0) |
| 668 | return q->first_to_check; |
| 669 | switch (state) { |
| 670 | case SLSB_P_INPUT_ERROR : |
| 671 | #ifdef CONFIG_QDIO_DEBUG |
| 672 | QDIO_DBF_TEXT3(1,trace,"inperr"); |
| 673 | sprintf(dbf_text,"%2x,%2x",ftc,count); |
| 674 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
| 675 | #endif /* CONFIG_QDIO_DEBUG */ |
| 676 | if (q->qdio_error) |
| 677 | q->error_status_flags |= |
| 678 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; |
| 679 | q->qdio_error = SLSB_P_INPUT_ERROR; |
| 680 | q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR; |
| 681 | atomic_sub(cnt, &q->number_of_buffers_used); |
| 682 | q->first_to_check = ftc; |
| 683 | break; |
| 684 | case SLSB_P_INPUT_PRIMED : |
| 685 | QDIO_DBF_TEXT3(0,trace,"inptprim"); |
| 686 | sprintf(dbf_text,"%2x,%2x",ftc,count); |
| 687 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
| 688 | tmp = 0; |
| 689 | ftc = q->first_to_check; |
| 690 | #ifdef QDIO_USE_PROCESSING_STATE |
| 691 | if (cnt > 1) { |
| 692 | cnt -= 1; |
| 693 | tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt); |
| 694 | if (!tmp) |
| 695 | break; |
| 696 | } |
| 697 | cnt = 1; |
| 698 | tmp += set_slsb(q, &ftc, |
| 699 | SLSB_P_INPUT_PROCESSING, &cnt); |
| 700 | atomic_set(&q->polling, 1); |
| 701 | #else |
| 702 | tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt); |
| 703 | #endif |
| 704 | atomic_sub(tmp, &q->number_of_buffers_used); |
| 705 | q->first_to_check = ftc; |
| 706 | break; |
| 707 | case SLSB_CU_INPUT_EMPTY: |
| 708 | case SLSB_P_INPUT_NOT_INIT: |
| 709 | case SLSB_P_INPUT_PROCESSING: |
| 710 | QDIO_DBF_TEXT5(0,trace,"inpnipro"); |
| 711 | break; |
| 712 | default: |
| 713 | break; |
| 714 | } |
| 715 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); |
| 716 | return q->first_to_check; |
| 717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 719 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | qdio_get_outbound_buffer_frontier(struct qdio_q *q) |
| 721 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 722 | struct qdio_irq *irq; |
| 723 | volatile char *slsb; |
| 724 | unsigned int count = 1; |
| 725 | int first_not_to_check, f, f_mod_no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | char dbf_text[15]; |
| 727 | |
| 728 | QDIO_DBF_TEXT4(0,trace,"getobfro"); |
| 729 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 730 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 731 | irq = (struct qdio_irq *) q->irq_ptr; |
| 732 | if (irq->is_qebsm) |
| 733 | return qdio_qebsm_get_outbound_buffer_frontier(q); |
| 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | slsb=&q->slsb.acc.val[0]; |
| 736 | f_mod_no=f=q->first_to_check; |
| 737 | /* |
| 738 | * f points to already processed elements, so f+no_used is correct... |
| 739 | * ... but: we don't check 128 buffers, as otherwise |
| 740 | * qdio_has_outbound_q_moved would return 0 |
| 741 | */ |
| 742 | first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used), |
| 743 | (QDIO_MAX_BUFFERS_PER_Q-1)); |
| 744 | |
| 745 | if ((!q->is_iqdio_q)&&(!q->hydra_gives_outbound_pcis)) |
| 746 | SYNC_MEMORY; |
| 747 | |
| 748 | check_next: |
| 749 | if (f==first_not_to_check) |
| 750 | goto out; |
| 751 | |
| 752 | switch(slsb[f_mod_no]) { |
| 753 | |
| 754 | /* the adapter has not fetched the output yet */ |
| 755 | case SLSB_CU_OUTPUT_PRIMED: |
| 756 | QDIO_DBF_TEXT5(0,trace,"outpprim"); |
| 757 | break; |
| 758 | |
| 759 | /* the adapter got it */ |
| 760 | case SLSB_P_OUTPUT_EMPTY: |
| 761 | atomic_dec(&q->number_of_buffers_used); |
| 762 | f++; |
| 763 | f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 764 | QDIO_DBF_TEXT5(0,trace,"outpempt"); |
| 765 | goto check_next; |
| 766 | |
| 767 | case SLSB_P_OUTPUT_ERROR: |
| 768 | QDIO_DBF_TEXT3(0,trace,"outperr"); |
| 769 | sprintf(dbf_text,"%x-%x-%x",f_mod_no, |
| 770 | q->sbal[f_mod_no]->element[14].sbalf.value, |
| 771 | q->sbal[f_mod_no]->element[15].sbalf.value); |
| 772 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
| 773 | QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256); |
| 774 | |
| 775 | /* kind of process the buffer */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 776 | set_slsb(q, &f_mod_no, SLSB_P_OUTPUT_NOT_INIT, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * we increment the frontier, as this buffer |
| 780 | * was processed obviously |
| 781 | */ |
| 782 | atomic_dec(&q->number_of_buffers_used); |
| 783 | f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 784 | |
| 785 | if (q->qdio_error) |
| 786 | q->error_status_flags|= |
| 787 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; |
| 788 | q->qdio_error=SLSB_P_OUTPUT_ERROR; |
| 789 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; |
| 790 | |
| 791 | break; |
| 792 | |
| 793 | /* no new buffers */ |
| 794 | default: |
| 795 | QDIO_DBF_TEXT5(0,trace,"outpni"); |
| 796 | } |
| 797 | out: |
| 798 | return (q->first_to_check=f_mod_no); |
| 799 | } |
| 800 | |
| 801 | /* all buffers are processed */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 802 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | qdio_is_outbound_q_done(struct qdio_q *q) |
| 804 | { |
| 805 | int no_used; |
| 806 | #ifdef CONFIG_QDIO_DEBUG |
| 807 | char dbf_text[15]; |
| 808 | #endif |
| 809 | |
| 810 | no_used=atomic_read(&q->number_of_buffers_used); |
| 811 | |
| 812 | #ifdef CONFIG_QDIO_DEBUG |
| 813 | if (no_used) { |
| 814 | sprintf(dbf_text,"oqisnt%02x",no_used); |
| 815 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 816 | } else { |
| 817 | QDIO_DBF_TEXT4(0,trace,"oqisdone"); |
| 818 | } |
| 819 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 820 | #endif /* CONFIG_QDIO_DEBUG */ |
| 821 | return (no_used==0); |
| 822 | } |
| 823 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 824 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | qdio_has_outbound_q_moved(struct qdio_q *q) |
| 826 | { |
| 827 | int i; |
| 828 | |
| 829 | i=qdio_get_outbound_buffer_frontier(q); |
| 830 | |
| 831 | if ( (i!=GET_SAVED_FRONTIER(q)) || |
| 832 | (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) { |
| 833 | SAVE_FRONTIER(q,i); |
| 834 | QDIO_DBF_TEXT4(0,trace,"oqhasmvd"); |
| 835 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 836 | return 1; |
| 837 | } else { |
| 838 | QDIO_DBF_TEXT4(0,trace,"oqhsntmv"); |
| 839 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 840 | return 0; |
| 841 | } |
| 842 | } |
| 843 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 844 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | qdio_kick_outbound_q(struct qdio_q *q) |
| 846 | { |
| 847 | int result; |
| 848 | #ifdef CONFIG_QDIO_DEBUG |
| 849 | char dbf_text[15]; |
| 850 | |
| 851 | QDIO_DBF_TEXT4(0,trace,"kickoutq"); |
| 852 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 853 | #endif /* CONFIG_QDIO_DEBUG */ |
| 854 | |
| 855 | if (!q->siga_out) |
| 856 | return; |
| 857 | |
| 858 | /* here's the story with cc=2 and busy bit set (thanks, Rick): |
| 859 | * VM's CP could present us cc=2 and busy bit set on SIGA-write |
| 860 | * during reconfiguration of their Guest LAN (only in HIPERS mode, |
| 861 | * QDIO mode is asynchronous -- cc=2 and busy bit there will take |
| 862 | * the queues down immediately; and not being under VM we have a |
| 863 | * problem on cc=2 and busy bit set right away). |
| 864 | * |
| 865 | * Therefore qdio_siga_output will try for a short time constantly, |
| 866 | * if such a condition occurs. If it doesn't change, it will |
| 867 | * increase the busy_siga_counter and save the timestamp, and |
| 868 | * schedule the queue for later processing (via mark_q, using the |
| 869 | * queue tasklet). __qdio_outbound_processing will check out the |
| 870 | * counter. If non-zero, it will call qdio_kick_outbound_q as often |
| 871 | * as the value of the counter. This will attempt further SIGA |
| 872 | * instructions. For each successful SIGA, the counter is |
| 873 | * decreased, for failing SIGAs the counter remains the same, after |
| 874 | * all. |
| 875 | * After some time of no movement, qdio_kick_outbound_q will |
| 876 | * finally fail and reflect corresponding error codes to call |
| 877 | * the upper layer module and have it take the queues down. |
| 878 | * |
| 879 | * Note that this is a change from the original HiperSockets design |
| 880 | * (saying cc=2 and busy bit means take the queues down), but in |
| 881 | * these days Guest LAN didn't exist... excessive cc=2 with busy bit |
| 882 | * conditions will still take the queues down, but the threshold is |
| 883 | * higher due to the Guest LAN environment. |
| 884 | */ |
| 885 | |
| 886 | |
| 887 | result=qdio_siga_output(q); |
| 888 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 889 | switch (result) { |
| 890 | case 0: |
| 891 | /* went smooth this time, reset timestamp */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | #ifdef CONFIG_QDIO_DEBUG |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 893 | QDIO_DBF_TEXT3(0,trace,"cc2reslv"); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 894 | sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no, |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 895 | atomic_read(&q->busy_siga_counter)); |
| 896 | QDIO_DBF_TEXT3(0,trace,dbf_text); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | #endif /* CONFIG_QDIO_DEBUG */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 898 | q->timing.busy_start=0; |
| 899 | break; |
| 900 | case (2|QDIO_SIGA_ERROR_B_BIT_SET): |
| 901 | /* cc=2 and busy bit: */ |
| 902 | atomic_inc(&q->busy_siga_counter); |
| 903 | |
| 904 | /* if the last siga was successful, save |
| 905 | * timestamp here */ |
| 906 | if (!q->timing.busy_start) |
| 907 | q->timing.busy_start=NOW; |
| 908 | |
| 909 | /* if we're in time, don't touch error_status_flags |
| 910 | * and siga_error */ |
| 911 | if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) { |
| 912 | qdio_mark_q(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 915 | QDIO_DBF_TEXT2(0,trace,"cc2REPRT"); |
| 916 | #ifdef CONFIG_QDIO_DEBUG |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 917 | sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no, |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 918 | atomic_read(&q->busy_siga_counter)); |
| 919 | QDIO_DBF_TEXT3(0,trace,dbf_text); |
| 920 | #endif /* CONFIG_QDIO_DEBUG */ |
| 921 | /* else fallthrough and report error */ |
| 922 | default: |
| 923 | /* for plain cc=1, 2 or 3: */ |
| 924 | if (q->siga_error) |
| 925 | q->error_status_flags|= |
| 926 | QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR; |
| 927 | q->error_status_flags|= |
| 928 | QDIO_STATUS_LOOK_FOR_ERROR; |
| 929 | q->siga_error=result; |
| 930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 933 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | qdio_kick_outbound_handler(struct qdio_q *q) |
| 935 | { |
| 936 | int start, end, real_end, count; |
| 937 | #ifdef CONFIG_QDIO_DEBUG |
| 938 | char dbf_text[15]; |
| 939 | #endif |
| 940 | |
| 941 | start = q->first_element_to_kick; |
| 942 | /* last_move_ftc was just updated */ |
| 943 | real_end = GET_SAVED_FRONTIER(q); |
| 944 | end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)& |
| 945 | (QDIO_MAX_BUFFERS_PER_Q-1); |
| 946 | count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)& |
| 947 | (QDIO_MAX_BUFFERS_PER_Q-1); |
| 948 | |
| 949 | #ifdef CONFIG_QDIO_DEBUG |
| 950 | QDIO_DBF_TEXT4(0,trace,"kickouth"); |
| 951 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 952 | |
| 953 | sprintf(dbf_text,"s=%2xc=%2x",start,count); |
| 954 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 955 | #endif /* CONFIG_QDIO_DEBUG */ |
| 956 | |
| 957 | if (q->state==QDIO_IRQ_STATE_ACTIVE) |
| 958 | q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT| |
| 959 | q->error_status_flags, |
| 960 | q->qdio_error,q->siga_error,q->q_no,start,count, |
| 961 | q->int_parm); |
| 962 | |
| 963 | /* for the next time: */ |
| 964 | q->first_element_to_kick=real_end; |
| 965 | q->qdio_error=0; |
| 966 | q->siga_error=0; |
| 967 | q->error_status_flags=0; |
| 968 | } |
| 969 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 970 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | __qdio_outbound_processing(struct qdio_q *q) |
| 972 | { |
| 973 | int siga_attempts; |
| 974 | |
| 975 | QDIO_DBF_TEXT4(0,trace,"qoutproc"); |
| 976 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 977 | |
| 978 | if (unlikely(qdio_reserve_q(q))) { |
| 979 | qdio_release_q(q); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 980 | qdio_perf_stat_inc(&perf_stats.outbound_tl_runs_resched); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /* as we're sissies, we'll check next time */ |
| 982 | if (likely(!atomic_read(&q->is_in_shutdown))) { |
| 983 | qdio_mark_q(q); |
| 984 | QDIO_DBF_TEXT4(0,trace,"busy,agn"); |
| 985 | } |
| 986 | return; |
| 987 | } |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 988 | qdio_perf_stat_inc(&perf_stats.outbound_tl_runs); |
| 989 | qdio_perf_stat_inc(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
| 991 | /* see comment in qdio_kick_outbound_q */ |
| 992 | siga_attempts=atomic_read(&q->busy_siga_counter); |
| 993 | while (siga_attempts) { |
| 994 | atomic_dec(&q->busy_siga_counter); |
| 995 | qdio_kick_outbound_q(q); |
| 996 | siga_attempts--; |
| 997 | } |
| 998 | |
| 999 | if (qdio_has_outbound_q_moved(q)) |
| 1000 | qdio_kick_outbound_handler(q); |
| 1001 | |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 1002 | if (q->queue_type == QDIO_ZFCP_QFMT) { |
| 1003 | if ((!q->hydra_gives_outbound_pcis) && |
| 1004 | (!qdio_is_outbound_q_done(q))) |
| 1005 | qdio_mark_q(q); |
| 1006 | } |
| 1007 | else if (((!q->is_iqdio_q) && (!q->is_pci_out)) || |
| 1008 | (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | /* |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 1010 | * make sure buffer switch from PRIMED to EMPTY is noticed |
| 1011 | * and outbound_handler is called |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | */ |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 1013 | if (qdio_is_outbound_q_done(q)) { |
| 1014 | del_timer(&q->timer); |
| 1015 | } else { |
| 1016 | if (!timer_pending(&q->timer)) |
| 1017 | mod_timer(&q->timer, jiffies + |
| 1018 | QDIO_FORCE_CHECK_TIMEOUT); |
| 1019 | } |
| 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | qdio_release_q(q); |
| 1023 | } |
| 1024 | |
| 1025 | static void |
| 1026 | qdio_outbound_processing(struct qdio_q *q) |
| 1027 | { |
| 1028 | __qdio_outbound_processing(q); |
| 1029 | } |
| 1030 | |
| 1031 | /************************* INBOUND ROUTINES *******************************/ |
| 1032 | |
| 1033 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1034 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | qdio_get_inbound_buffer_frontier(struct qdio_q *q) |
| 1036 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1037 | struct qdio_irq *irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | int f,f_mod_no; |
| 1039 | volatile char *slsb; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1040 | unsigned int count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | int first_not_to_check; |
| 1042 | #ifdef CONFIG_QDIO_DEBUG |
| 1043 | char dbf_text[15]; |
| 1044 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1045 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1046 | int last_position=-1; |
| 1047 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1048 | |
| 1049 | QDIO_DBF_TEXT4(0,trace,"getibfro"); |
| 1050 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1051 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1052 | irq = (struct qdio_irq *) q->irq_ptr; |
| 1053 | if (irq->is_qebsm) |
| 1054 | return qdio_qebsm_get_inbound_buffer_frontier(q); |
| 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | slsb=&q->slsb.acc.val[0]; |
| 1057 | f_mod_no=f=q->first_to_check; |
| 1058 | /* |
| 1059 | * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved |
| 1060 | * would return 0 |
| 1061 | */ |
| 1062 | first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used), |
| 1063 | (QDIO_MAX_BUFFERS_PER_Q-1)); |
| 1064 | |
| 1065 | /* |
| 1066 | * we don't use this one, as a PCI or we after a thin interrupt |
| 1067 | * will sync the queues |
| 1068 | */ |
| 1069 | /* SYNC_MEMORY;*/ |
| 1070 | |
| 1071 | check_next: |
| 1072 | f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 1073 | if (f==first_not_to_check) |
| 1074 | goto out; |
| 1075 | switch (slsb[f_mod_no]) { |
| 1076 | |
| 1077 | /* CU_EMPTY means frontier is reached */ |
| 1078 | case SLSB_CU_INPUT_EMPTY: |
| 1079 | QDIO_DBF_TEXT5(0,trace,"inptempt"); |
| 1080 | break; |
| 1081 | |
| 1082 | /* P_PRIMED means set slsb to P_PROCESSING and move on */ |
| 1083 | case SLSB_P_INPUT_PRIMED: |
| 1084 | QDIO_DBF_TEXT5(0,trace,"inptprim"); |
| 1085 | |
| 1086 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1087 | /* |
| 1088 | * as soon as running under VM, polling the input queues will |
| 1089 | * kill VM in terms of CP overhead |
| 1090 | */ |
| 1091 | if (q->siga_sync) { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1092 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } else { |
| 1094 | /* set the previous buffer to NOT_INIT. The current |
| 1095 | * buffer will be set to PROCESSING at the end of |
| 1096 | * this function to avoid further interrupts. */ |
| 1097 | if (last_position>=0) |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1098 | set_slsb(q, &last_position, |
| 1099 | SLSB_P_INPUT_NOT_INIT, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | atomic_set(&q->polling,1); |
| 1101 | last_position=f_mod_no; |
| 1102 | } |
| 1103 | #else /* QDIO_USE_PROCESSING_STATE */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1104 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1106 | /* |
| 1107 | * not needed, as the inbound queue will be synced on the next |
| 1108 | * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s |
| 1109 | */ |
| 1110 | /*SYNC_MEMORY;*/ |
| 1111 | f++; |
| 1112 | atomic_dec(&q->number_of_buffers_used); |
| 1113 | goto check_next; |
| 1114 | |
| 1115 | case SLSB_P_INPUT_NOT_INIT: |
| 1116 | case SLSB_P_INPUT_PROCESSING: |
| 1117 | QDIO_DBF_TEXT5(0,trace,"inpnipro"); |
| 1118 | break; |
| 1119 | |
| 1120 | /* P_ERROR means frontier is reached, break and report error */ |
| 1121 | case SLSB_P_INPUT_ERROR: |
| 1122 | #ifdef CONFIG_QDIO_DEBUG |
| 1123 | sprintf(dbf_text,"inperr%2x",f_mod_no); |
| 1124 | QDIO_DBF_TEXT3(1,trace,dbf_text); |
| 1125 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1126 | QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256); |
| 1127 | |
| 1128 | /* kind of process the buffer */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1129 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| 1131 | if (q->qdio_error) |
| 1132 | q->error_status_flags|= |
| 1133 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; |
| 1134 | q->qdio_error=SLSB_P_INPUT_ERROR; |
| 1135 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; |
| 1136 | |
| 1137 | /* we increment the frontier, as this buffer |
| 1138 | * was processed obviously */ |
| 1139 | f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 1140 | atomic_dec(&q->number_of_buffers_used); |
| 1141 | |
| 1142 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1143 | last_position=-1; |
| 1144 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1145 | |
| 1146 | break; |
| 1147 | |
| 1148 | /* everything else means frontier not changed (HALTED or so) */ |
| 1149 | default: |
| 1150 | break; |
| 1151 | } |
| 1152 | out: |
| 1153 | q->first_to_check=f_mod_no; |
| 1154 | |
| 1155 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1156 | if (last_position>=0) |
Frank Pavlic | 6981e93 | 2006-09-20 15:59:19 +0200 | [diff] [blame] | 1157 | set_slsb(q, &last_position, SLSB_P_INPUT_PROCESSING, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1159 | |
| 1160 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); |
| 1161 | |
| 1162 | return q->first_to_check; |
| 1163 | } |
| 1164 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1165 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | qdio_has_inbound_q_moved(struct qdio_q *q) |
| 1167 | { |
| 1168 | int i; |
| 1169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | i=qdio_get_inbound_buffer_frontier(q); |
| 1171 | if ( (i!=GET_SAVED_FRONTIER(q)) || |
| 1172 | (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) { |
| 1173 | SAVE_FRONTIER(q,i); |
| 1174 | if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis)) |
| 1175 | SAVE_TIMESTAMP(q); |
| 1176 | |
| 1177 | QDIO_DBF_TEXT4(0,trace,"inhasmvd"); |
| 1178 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1179 | return 1; |
| 1180 | } else { |
| 1181 | QDIO_DBF_TEXT4(0,trace,"inhsntmv"); |
| 1182 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1183 | return 0; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* means, no more buffers to be filled */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1188 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | tiqdio_is_inbound_q_done(struct qdio_q *q) |
| 1190 | { |
| 1191 | int no_used; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1192 | unsigned int start_buf, count; |
| 1193 | unsigned char state = 0; |
| 1194 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
| 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | #ifdef CONFIG_QDIO_DEBUG |
| 1197 | char dbf_text[15]; |
| 1198 | #endif |
| 1199 | |
| 1200 | no_used=atomic_read(&q->number_of_buffers_used); |
| 1201 | |
| 1202 | /* propagate the change from 82 to 80 through VM */ |
| 1203 | SYNC_MEMORY; |
| 1204 | |
| 1205 | #ifdef CONFIG_QDIO_DEBUG |
| 1206 | if (no_used) { |
| 1207 | sprintf(dbf_text,"iqisnt%02x",no_used); |
| 1208 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 1209 | } else { |
| 1210 | QDIO_DBF_TEXT4(0,trace,"iniqisdo"); |
| 1211 | } |
| 1212 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1213 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1214 | |
| 1215 | if (!no_used) |
| 1216 | return 1; |
Frank Pavlic | 15c7369 | 2006-02-20 18:28:12 -0800 | [diff] [blame] | 1217 | if (!q->siga_sync && !irq->is_qebsm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | /* we'll check for more primed buffers in qeth_stop_polling */ |
| 1219 | return 0; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1220 | if (irq->is_qebsm) { |
| 1221 | count = 1; |
| 1222 | start_buf = q->first_to_check; |
| 1223 | qdio_do_eqbs(q, &state, &start_buf, &count); |
| 1224 | } else |
| 1225 | state = q->slsb.acc.val[q->first_to_check]; |
| 1226 | if (state != SLSB_P_INPUT_PRIMED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | /* |
| 1228 | * nothing more to do, if next buffer is not PRIMED. |
| 1229 | * note that we did a SYNC_MEMORY before, that there |
| 1230 | * has been a sychnronization. |
| 1231 | * we will return 0 below, as there is nothing to do |
| 1232 | * (stop_polling not necessary, as we have not been |
| 1233 | * using the PROCESSING state |
| 1234 | */ |
| 1235 | return 0; |
| 1236 | |
| 1237 | /* |
| 1238 | * ok, the next input buffer is primed. that means, that device state |
| 1239 | * change indicator and adapter local summary are set, so we will find |
| 1240 | * it next time. |
| 1241 | * we will return 0 below, as there is nothing to do, except scheduling |
| 1242 | * ourselves for the next time. |
| 1243 | */ |
| 1244 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 1245 | tiqdio_sched_tl(); |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1249 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | qdio_is_inbound_q_done(struct qdio_q *q) |
| 1251 | { |
| 1252 | int no_used; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1253 | unsigned int start_buf, count; |
| 1254 | unsigned char state = 0; |
| 1255 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | #ifdef CONFIG_QDIO_DEBUG |
| 1258 | char dbf_text[15]; |
| 1259 | #endif |
| 1260 | |
| 1261 | no_used=atomic_read(&q->number_of_buffers_used); |
| 1262 | |
| 1263 | /* |
| 1264 | * we need that one for synchronization with the adapter, as it |
| 1265 | * does a kind of PCI avoidance |
| 1266 | */ |
| 1267 | SYNC_MEMORY; |
| 1268 | |
| 1269 | if (!no_used) { |
| 1270 | QDIO_DBF_TEXT4(0,trace,"inqisdnA"); |
| 1271 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return 1; |
| 1273 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1274 | if (irq->is_qebsm) { |
| 1275 | count = 1; |
| 1276 | start_buf = q->first_to_check; |
| 1277 | qdio_do_eqbs(q, &state, &start_buf, &count); |
| 1278 | } else |
| 1279 | state = q->slsb.acc.val[q->first_to_check]; |
| 1280 | if (state == SLSB_P_INPUT_PRIMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | /* we got something to do */ |
| 1282 | QDIO_DBF_TEXT4(0,trace,"inqisntA"); |
| 1283 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | /* on VM, we don't poll, so the q is always done here */ |
| 1288 | if (q->siga_sync) |
| 1289 | return 1; |
| 1290 | if (q->hydra_gives_outbound_pcis) |
| 1291 | return 1; |
| 1292 | |
| 1293 | /* |
| 1294 | * at this point we know, that inbound first_to_check |
| 1295 | * has (probably) not moved (see qdio_inbound_processing) |
| 1296 | */ |
| 1297 | if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) { |
| 1298 | #ifdef CONFIG_QDIO_DEBUG |
| 1299 | QDIO_DBF_TEXT4(0,trace,"inqisdon"); |
| 1300 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1301 | sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used); |
| 1302 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 1303 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1304 | return 1; |
| 1305 | } else { |
| 1306 | #ifdef CONFIG_QDIO_DEBUG |
| 1307 | QDIO_DBF_TEXT4(0,trace,"inqisntd"); |
| 1308 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1309 | sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used); |
| 1310 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 1311 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1312 | return 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1316 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | qdio_kick_inbound_handler(struct qdio_q *q) |
| 1318 | { |
| 1319 | int count, start, end, real_end, i; |
| 1320 | #ifdef CONFIG_QDIO_DEBUG |
| 1321 | char dbf_text[15]; |
| 1322 | #endif |
| 1323 | |
| 1324 | QDIO_DBF_TEXT4(0,trace,"kickinh"); |
| 1325 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1326 | |
| 1327 | start=q->first_element_to_kick; |
| 1328 | real_end=q->first_to_check; |
| 1329 | end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 1330 | |
| 1331 | i=start; |
| 1332 | count=0; |
| 1333 | while (1) { |
| 1334 | count++; |
| 1335 | if (i==end) |
| 1336 | break; |
| 1337 | i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1); |
| 1338 | } |
| 1339 | |
| 1340 | #ifdef CONFIG_QDIO_DEBUG |
| 1341 | sprintf(dbf_text,"s=%2xc=%2x",start,count); |
| 1342 | QDIO_DBF_TEXT4(0,trace,dbf_text); |
| 1343 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1344 | |
| 1345 | if (likely(q->state==QDIO_IRQ_STATE_ACTIVE)) |
| 1346 | q->handler(q->cdev, |
| 1347 | QDIO_STATUS_INBOUND_INT|q->error_status_flags, |
| 1348 | q->qdio_error,q->siga_error,q->q_no,start,count, |
| 1349 | q->int_parm); |
| 1350 | |
| 1351 | /* for the next time: */ |
| 1352 | q->first_element_to_kick=real_end; |
| 1353 | q->qdio_error=0; |
| 1354 | q->siga_error=0; |
| 1355 | q->error_status_flags=0; |
| 1356 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1357 | qdio_perf_stat_inc(&perf_stats.inbound_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1360 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set) |
| 1362 | { |
| 1363 | struct qdio_irq *irq_ptr; |
| 1364 | struct qdio_q *oq; |
| 1365 | int i; |
| 1366 | |
| 1367 | QDIO_DBF_TEXT4(0,trace,"iqinproc"); |
| 1368 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1369 | |
| 1370 | /* |
| 1371 | * we first want to reserve the q, so that we know, that we don't |
| 1372 | * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might |
| 1373 | * be set |
| 1374 | */ |
| 1375 | if (unlikely(qdio_reserve_q(q))) { |
| 1376 | qdio_release_q(q); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1377 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | /* |
| 1379 | * as we might just be about to stop polling, we make |
| 1380 | * sure that we check again at least once more |
| 1381 | */ |
| 1382 | tiqdio_sched_tl(); |
| 1383 | return; |
| 1384 | } |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1385 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | if (unlikely(atomic_read(&q->is_in_shutdown))) { |
| 1387 | qdio_unmark_q(q); |
| 1388 | goto out; |
| 1389 | } |
| 1390 | |
| 1391 | /* |
| 1392 | * we reset spare_ind_was_set, when the queue does not use the |
| 1393 | * spare indicator |
| 1394 | */ |
| 1395 | if (spare_ind_was_set) |
| 1396 | spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator); |
| 1397 | |
| 1398 | if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set) |
| 1399 | goto out; |
| 1400 | /* |
| 1401 | * q->dev_st_chg_ind is the indicator, be it shared or not. |
| 1402 | * only clear it, if indicator is non-shared |
| 1403 | */ |
| 1404 | if (!spare_ind_was_set) |
| 1405 | tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind); |
| 1406 | |
| 1407 | if (q->hydra_gives_outbound_pcis) { |
| 1408 | if (!q->siga_sync_done_on_thinints) { |
| 1409 | SYNC_MEMORY_ALL; |
| 1410 | } else if ((!q->siga_sync_done_on_outb_tis)&& |
| 1411 | (q->hydra_gives_outbound_pcis)) { |
| 1412 | SYNC_MEMORY_ALL_OUTB; |
| 1413 | } |
| 1414 | } else { |
| 1415 | SYNC_MEMORY; |
| 1416 | } |
| 1417 | /* |
| 1418 | * maybe we have to do work on our outbound queues... at least |
| 1419 | * we have to check the outbound-int-capable thinint-capable |
| 1420 | * queues |
| 1421 | */ |
| 1422 | if (q->hydra_gives_outbound_pcis) { |
| 1423 | irq_ptr = (struct qdio_irq*)q->irq_ptr; |
| 1424 | for (i=0;i<irq_ptr->no_output_qs;i++) { |
| 1425 | oq = irq_ptr->output_qs[i]; |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 1426 | if (!qdio_is_outbound_q_done(oq)) { |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1427 | qdio_perf_stat_dec(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | __qdio_outbound_processing(oq); |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 1429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | if (!qdio_has_inbound_q_moved(q)) |
| 1434 | goto out; |
| 1435 | |
| 1436 | qdio_kick_inbound_handler(q); |
| 1437 | if (tiqdio_is_inbound_q_done(q)) |
| 1438 | if (!qdio_stop_polling(q)) { |
| 1439 | /* |
| 1440 | * we set the flags to get into the stuff next time, |
| 1441 | * see also comment in qdio_stop_polling |
| 1442 | */ |
| 1443 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 1444 | tiqdio_sched_tl(); |
| 1445 | } |
| 1446 | out: |
| 1447 | qdio_release_q(q); |
| 1448 | } |
| 1449 | |
| 1450 | static void |
| 1451 | tiqdio_inbound_processing(struct qdio_q *q) |
| 1452 | { |
| 1453 | __tiqdio_inbound_processing(q, atomic_read(&spare_indicator_usecount)); |
| 1454 | } |
| 1455 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1456 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | __qdio_inbound_processing(struct qdio_q *q) |
| 1458 | { |
| 1459 | int q_laps=0; |
| 1460 | |
| 1461 | QDIO_DBF_TEXT4(0,trace,"qinproc"); |
| 1462 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); |
| 1463 | |
| 1464 | if (unlikely(qdio_reserve_q(q))) { |
| 1465 | qdio_release_q(q); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1466 | qdio_perf_stat_inc(&perf_stats.inbound_tl_runs_resched); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | /* as we're sissies, we'll check next time */ |
| 1468 | if (likely(!atomic_read(&q->is_in_shutdown))) { |
| 1469 | qdio_mark_q(q); |
| 1470 | QDIO_DBF_TEXT4(0,trace,"busy,agn"); |
| 1471 | } |
| 1472 | return; |
| 1473 | } |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1474 | qdio_perf_stat_inc(&perf_stats.inbound_tl_runs); |
| 1475 | qdio_perf_stat_inc(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
| 1477 | again: |
| 1478 | if (qdio_has_inbound_q_moved(q)) { |
| 1479 | qdio_kick_inbound_handler(q); |
| 1480 | if (!qdio_stop_polling(q)) { |
| 1481 | q_laps++; |
| 1482 | if (q_laps<QDIO_Q_LAPS) |
| 1483 | goto again; |
| 1484 | } |
| 1485 | qdio_mark_q(q); |
| 1486 | } else { |
| 1487 | if (!qdio_is_inbound_q_done(q)) |
| 1488 | /* means poll time is not yet over */ |
| 1489 | qdio_mark_q(q); |
| 1490 | } |
| 1491 | |
| 1492 | qdio_release_q(q); |
| 1493 | } |
| 1494 | |
| 1495 | static void |
| 1496 | qdio_inbound_processing(struct qdio_q *q) |
| 1497 | { |
| 1498 | __qdio_inbound_processing(q); |
| 1499 | } |
| 1500 | |
| 1501 | /************************* MAIN ROUTINES *******************************/ |
| 1502 | |
| 1503 | #ifdef QDIO_USE_PROCESSING_STATE |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1504 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | tiqdio_reset_processing_state(struct qdio_q *q, int q_laps) |
| 1506 | { |
| 1507 | if (!q) { |
| 1508 | tiqdio_sched_tl(); |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | /* |
| 1513 | * under VM, we have not used the PROCESSING state, so no |
| 1514 | * need to stop polling |
| 1515 | */ |
| 1516 | if (q->siga_sync) |
| 1517 | return 2; |
| 1518 | |
| 1519 | if (unlikely(qdio_reserve_q(q))) { |
| 1520 | qdio_release_q(q); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1521 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | /* |
| 1523 | * as we might just be about to stop polling, we make |
| 1524 | * sure that we check again at least once more |
| 1525 | */ |
| 1526 | |
| 1527 | /* |
| 1528 | * sanity -- we'd get here without setting the |
| 1529 | * dev st chg ind |
| 1530 | */ |
| 1531 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 1532 | tiqdio_sched_tl(); |
| 1533 | return 0; |
| 1534 | } |
| 1535 | if (qdio_stop_polling(q)) { |
| 1536 | qdio_release_q(q); |
| 1537 | return 2; |
| 1538 | } |
| 1539 | if (q_laps<QDIO_Q_LAPS-1) { |
| 1540 | qdio_release_q(q); |
| 1541 | return 3; |
| 1542 | } |
| 1543 | /* |
| 1544 | * we set the flags to get into the stuff |
| 1545 | * next time, see also comment in qdio_stop_polling |
| 1546 | */ |
| 1547 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); |
| 1548 | tiqdio_sched_tl(); |
| 1549 | qdio_release_q(q); |
| 1550 | return 1; |
| 1551 | |
| 1552 | } |
| 1553 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1554 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1555 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | tiqdio_inbound_checks(void) |
| 1557 | { |
| 1558 | struct qdio_q *q; |
| 1559 | int spare_ind_was_set=0; |
| 1560 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1561 | int q_laps=0; |
| 1562 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1563 | |
| 1564 | QDIO_DBF_TEXT4(0,trace,"iqdinbck"); |
| 1565 | QDIO_DBF_TEXT5(0,trace,"iqlocsum"); |
| 1566 | |
| 1567 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1568 | again: |
| 1569 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1570 | |
| 1571 | /* when the spare indicator is used and set, save that and clear it */ |
| 1572 | if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) { |
| 1573 | spare_ind_was_set = 1; |
| 1574 | tiqdio_clear_summary_bit((__u32*)&spare_indicator); |
| 1575 | } |
| 1576 | |
| 1577 | q=(struct qdio_q*)tiq_list; |
| 1578 | do { |
| 1579 | if (!q) |
| 1580 | break; |
| 1581 | __tiqdio_inbound_processing(q, spare_ind_was_set); |
| 1582 | q=(struct qdio_q*)q->list_next; |
| 1583 | } while (q!=(struct qdio_q*)tiq_list); |
| 1584 | |
| 1585 | #ifdef QDIO_USE_PROCESSING_STATE |
| 1586 | q=(struct qdio_q*)tiq_list; |
| 1587 | do { |
| 1588 | int ret; |
| 1589 | |
| 1590 | ret = tiqdio_reset_processing_state(q, q_laps); |
| 1591 | switch (ret) { |
| 1592 | case 0: |
| 1593 | return; |
| 1594 | case 1: |
| 1595 | q_laps++; |
| 1596 | case 2: |
| 1597 | q = (struct qdio_q*)q->list_next; |
| 1598 | break; |
| 1599 | default: |
| 1600 | q_laps++; |
| 1601 | goto again; |
| 1602 | } |
| 1603 | } while (q!=(struct qdio_q*)tiq_list); |
| 1604 | #endif /* QDIO_USE_PROCESSING_STATE */ |
| 1605 | } |
| 1606 | |
| 1607 | static void |
| 1608 | tiqdio_tl(unsigned long data) |
| 1609 | { |
| 1610 | QDIO_DBF_TEXT4(0,trace,"iqdio_tl"); |
| 1611 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1612 | qdio_perf_stat_inc(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | |
| 1614 | tiqdio_inbound_checks(); |
| 1615 | } |
| 1616 | |
| 1617 | /********************* GENERAL HELPER_ROUTINES ***********************/ |
| 1618 | |
| 1619 | static void |
| 1620 | qdio_release_irq_memory(struct qdio_irq *irq_ptr) |
| 1621 | { |
| 1622 | int i; |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1623 | struct qdio_q *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1625 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { |
| 1626 | q = irq_ptr->input_qs[i]; |
| 1627 | if (q) { |
| 1628 | free_page((unsigned long) q->slib); |
| 1629 | kmem_cache_free(qdio_q_cache, q); |
| 1630 | } |
| 1631 | q = irq_ptr->output_qs[i]; |
| 1632 | if (q) { |
| 1633 | free_page((unsigned long) q->slib); |
| 1634 | kmem_cache_free(qdio_q_cache, q); |
| 1635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | } |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1637 | free_page((unsigned long) irq_ptr->qdr); |
Christian Borntraeger | 40ac6b2 | 2006-04-27 18:40:11 -0700 | [diff] [blame] | 1638 | free_page((unsigned long) irq_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | static void |
| 1642 | qdio_set_impl_params(struct qdio_irq *irq_ptr, |
| 1643 | unsigned int qib_param_field_format, |
| 1644 | /* pointer to 128 bytes or NULL, if no param field */ |
| 1645 | unsigned char *qib_param_field, |
| 1646 | /* pointer to no_queues*128 words of data or NULL */ |
| 1647 | unsigned int no_input_qs, |
| 1648 | unsigned int no_output_qs, |
| 1649 | unsigned long *input_slib_elements, |
| 1650 | unsigned long *output_slib_elements) |
| 1651 | { |
| 1652 | int i,j; |
| 1653 | |
| 1654 | if (!irq_ptr) |
| 1655 | return; |
| 1656 | |
| 1657 | irq_ptr->qib.pfmt=qib_param_field_format; |
| 1658 | if (qib_param_field) |
| 1659 | memcpy(irq_ptr->qib.parm,qib_param_field, |
| 1660 | QDIO_MAX_BUFFERS_PER_Q); |
| 1661 | |
| 1662 | if (input_slib_elements) |
| 1663 | for (i=0;i<no_input_qs;i++) { |
| 1664 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1665 | irq_ptr->input_qs[i]->slib->slibe[j].parms= |
| 1666 | input_slib_elements[ |
| 1667 | i*QDIO_MAX_BUFFERS_PER_Q+j]; |
| 1668 | } |
| 1669 | if (output_slib_elements) |
| 1670 | for (i=0;i<no_output_qs;i++) { |
| 1671 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1672 | irq_ptr->output_qs[i]->slib->slibe[j].parms= |
| 1673 | output_slib_elements[ |
| 1674 | i*QDIO_MAX_BUFFERS_PER_Q+j]; |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | static int |
| 1679 | qdio_alloc_qs(struct qdio_irq *irq_ptr, |
| 1680 | int no_input_qs, int no_output_qs) |
| 1681 | { |
| 1682 | int i; |
| 1683 | struct qdio_q *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1685 | for (i = 0; i < no_input_qs; i++) { |
| 1686 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); |
| 1687 | if (!q) |
| 1688 | return -ENOMEM; |
| 1689 | memset(q, 0, sizeof(*q)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1691 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | if (!q->slib) { |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1693 | kmem_cache_free(qdio_q_cache, q); |
| 1694 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | irq_ptr->input_qs[i]=q; |
| 1697 | } |
| 1698 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1699 | for (i = 0; i < no_output_qs; i++) { |
| 1700 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); |
| 1701 | if (!q) |
| 1702 | return -ENOMEM; |
| 1703 | memset(q, 0, sizeof(*q)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1705 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | if (!q->slib) { |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1707 | kmem_cache_free(qdio_q_cache, q); |
| 1708 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | irq_ptr->output_qs[i]=q; |
| 1711 | } |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 1712 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | static void |
| 1716 | qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev, |
| 1717 | int no_input_qs, int no_output_qs, |
| 1718 | qdio_handler_t *input_handler, |
| 1719 | qdio_handler_t *output_handler, |
| 1720 | unsigned long int_parm,int q_format, |
| 1721 | unsigned long flags, |
| 1722 | void **inbound_sbals_array, |
| 1723 | void **outbound_sbals_array) |
| 1724 | { |
| 1725 | struct qdio_q *q; |
| 1726 | int i,j; |
| 1727 | char dbf_text[20]; /* see qdio_initialize */ |
| 1728 | void *ptr; |
| 1729 | int available; |
| 1730 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 1731 | sprintf(dbf_text,"qfqs%4x",cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 1733 | for (i=0;i<no_input_qs;i++) { |
| 1734 | q=irq_ptr->input_qs[i]; |
| 1735 | |
| 1736 | memset(q,0,((char*)&q->slib)-((char*)q)); |
| 1737 | sprintf(dbf_text,"in-q%4x",i); |
| 1738 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 1739 | QDIO_DBF_HEX0(0,setup,&q,sizeof(void*)); |
| 1740 | |
| 1741 | memset(q->slib,0,PAGE_SIZE); |
| 1742 | q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2); |
| 1743 | |
| 1744 | available=0; |
| 1745 | |
| 1746 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1747 | q->sbal[j]=*(inbound_sbals_array++); |
| 1748 | |
| 1749 | q->queue_type=q_format; |
| 1750 | q->int_parm=int_parm; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1751 | q->schid = irq_ptr->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | q->irq_ptr = irq_ptr; |
| 1753 | q->cdev = cdev; |
| 1754 | q->mask=1<<(31-i); |
| 1755 | q->q_no=i; |
| 1756 | q->is_input_q=1; |
| 1757 | q->first_to_check=0; |
| 1758 | q->last_move_ftc=0; |
| 1759 | q->handler=input_handler; |
| 1760 | q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind; |
| 1761 | |
| 1762 | q->tasklet.data=(unsigned long)q; |
| 1763 | /* q->is_thinint_q isn't valid at this time, but |
| 1764 | * irq_ptr->is_thinint_irq is */ |
| 1765 | q->tasklet.func=(void(*)(unsigned long)) |
| 1766 | ((irq_ptr->is_thinint_irq)?&tiqdio_inbound_processing: |
| 1767 | &qdio_inbound_processing); |
| 1768 | |
| 1769 | /* actually this is not used for inbound queues. yet. */ |
| 1770 | atomic_set(&q->busy_siga_counter,0); |
| 1771 | q->timing.busy_start=0; |
| 1772 | |
| 1773 | /* for (j=0;j<QDIO_STATS_NUMBER;j++) |
| 1774 | q->timing.last_transfer_times[j]=(qdio_get_micros()/ |
| 1775 | QDIO_STATS_NUMBER)*j; |
| 1776 | q->timing.last_transfer_index=QDIO_STATS_NUMBER-1; |
| 1777 | */ |
| 1778 | |
| 1779 | /* fill in slib */ |
| 1780 | if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba= |
| 1781 | (unsigned long)(q->slib); |
| 1782 | q->slib->sla=(unsigned long)(q->sl); |
| 1783 | q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]); |
| 1784 | |
| 1785 | /* fill in sl */ |
| 1786 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1787 | q->sl->element[j].sbal=(unsigned long)(q->sbal[j]); |
| 1788 | |
| 1789 | QDIO_DBF_TEXT2(0,setup,"sl-sb-b0"); |
| 1790 | ptr=(void*)q->sl; |
| 1791 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1792 | ptr=(void*)&q->slsb; |
| 1793 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1794 | ptr=(void*)q->sbal[0]; |
| 1795 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1796 | |
| 1797 | /* fill in slsb */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1798 | if (!irq_ptr->is_qebsm) { |
| 1799 | unsigned int count = 1; |
| 1800 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
| 1801 | set_slsb(q, &j, SLSB_P_INPUT_NOT_INIT, &count); |
| 1802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | for (i=0;i<no_output_qs;i++) { |
| 1806 | q=irq_ptr->output_qs[i]; |
| 1807 | memset(q,0,((char*)&q->slib)-((char*)q)); |
| 1808 | |
| 1809 | sprintf(dbf_text,"outq%4x",i); |
| 1810 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 1811 | QDIO_DBF_HEX0(0,setup,&q,sizeof(void*)); |
| 1812 | |
| 1813 | memset(q->slib,0,PAGE_SIZE); |
| 1814 | q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2); |
| 1815 | |
| 1816 | available=0; |
| 1817 | |
| 1818 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1819 | q->sbal[j]=*(outbound_sbals_array++); |
| 1820 | |
| 1821 | q->queue_type=q_format; |
Ursula Braun | 028cf91 | 2006-12-15 17:18:14 +0100 | [diff] [blame] | 1822 | if ((q->queue_type == QDIO_IQDIO_QFMT) && |
| 1823 | (no_output_qs > 1) && |
| 1824 | (i == no_output_qs-1)) |
| 1825 | q->queue_type = QDIO_IQDIO_QFMT_ASYNCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | q->int_parm=int_parm; |
| 1827 | q->is_input_q=0; |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 1828 | q->is_pci_out = 0; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1829 | q->schid = irq_ptr->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | q->cdev = cdev; |
| 1831 | q->irq_ptr = irq_ptr; |
| 1832 | q->mask=1<<(31-i); |
| 1833 | q->q_no=i; |
| 1834 | q->first_to_check=0; |
| 1835 | q->last_move_ftc=0; |
| 1836 | q->handler=output_handler; |
| 1837 | |
| 1838 | q->tasklet.data=(unsigned long)q; |
| 1839 | q->tasklet.func=(void(*)(unsigned long)) |
| 1840 | &qdio_outbound_processing; |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 1841 | q->timer.function=(void(*)(unsigned long)) |
| 1842 | &qdio_outbound_processing; |
| 1843 | q->timer.data = (long)q; |
| 1844 | init_timer(&q->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
| 1846 | atomic_set(&q->busy_siga_counter,0); |
| 1847 | q->timing.busy_start=0; |
| 1848 | |
| 1849 | /* fill in slib */ |
| 1850 | if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba= |
| 1851 | (unsigned long)(q->slib); |
| 1852 | q->slib->sla=(unsigned long)(q->sl); |
| 1853 | q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]); |
| 1854 | |
| 1855 | /* fill in sl */ |
| 1856 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) |
| 1857 | q->sl->element[j].sbal=(unsigned long)(q->sbal[j]); |
| 1858 | |
| 1859 | QDIO_DBF_TEXT2(0,setup,"sl-sb-b0"); |
| 1860 | ptr=(void*)q->sl; |
| 1861 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1862 | ptr=(void*)&q->slsb; |
| 1863 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1864 | ptr=(void*)q->sbal[0]; |
| 1865 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); |
| 1866 | |
| 1867 | /* fill in slsb */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 1868 | if (!irq_ptr->is_qebsm) { |
| 1869 | unsigned int count = 1; |
| 1870 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) |
| 1871 | set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count); |
| 1872 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | static void |
| 1877 | qdio_fill_thresholds(struct qdio_irq *irq_ptr, |
| 1878 | unsigned int no_input_qs, |
| 1879 | unsigned int no_output_qs, |
| 1880 | unsigned int min_input_threshold, |
| 1881 | unsigned int max_input_threshold, |
| 1882 | unsigned int min_output_threshold, |
| 1883 | unsigned int max_output_threshold) |
| 1884 | { |
| 1885 | int i; |
| 1886 | struct qdio_q *q; |
| 1887 | |
| 1888 | for (i=0;i<no_input_qs;i++) { |
| 1889 | q=irq_ptr->input_qs[i]; |
| 1890 | q->timing.threshold=max_input_threshold; |
| 1891 | /* for (j=0;j<QDIO_STATS_CLASSES;j++) { |
| 1892 | q->threshold_classes[j].threshold= |
| 1893 | min_input_threshold+ |
| 1894 | (max_input_threshold-min_input_threshold)/ |
| 1895 | QDIO_STATS_CLASSES; |
| 1896 | } |
| 1897 | qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/ |
| 1898 | } |
| 1899 | for (i=0;i<no_output_qs;i++) { |
| 1900 | q=irq_ptr->output_qs[i]; |
| 1901 | q->timing.threshold=max_output_threshold; |
| 1902 | /* for (j=0;j<QDIO_STATS_CLASSES;j++) { |
| 1903 | q->threshold_classes[j].threshold= |
| 1904 | min_output_threshold+ |
| 1905 | (max_output_threshold-min_output_threshold)/ |
| 1906 | QDIO_STATS_CLASSES; |
| 1907 | } |
| 1908 | qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/ |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | static int |
| 1913 | tiqdio_thinint_handler(void) |
| 1914 | { |
| 1915 | QDIO_DBF_TEXT4(0,trace,"thin_int"); |
| 1916 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1917 | qdio_perf_stat_inc(&perf_stats.thinints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | /* SVS only when needed: |
| 1920 | * issue SVS to benefit from iqdio interrupt avoidance |
| 1921 | * (SVS clears AISOI)*/ |
| 1922 | if (!omit_svs) |
| 1923 | tiqdio_clear_global_summary(); |
| 1924 | |
| 1925 | tiqdio_inbound_checks(); |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | static void |
| 1930 | qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state) |
| 1931 | { |
| 1932 | int i; |
| 1933 | #ifdef CONFIG_QDIO_DEBUG |
| 1934 | char dbf_text[15]; |
| 1935 | |
| 1936 | QDIO_DBF_TEXT5(0,trace,"newstate"); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1937 | sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | QDIO_DBF_TEXT5(0,trace,dbf_text); |
| 1939 | #endif /* CONFIG_QDIO_DEBUG */ |
| 1940 | |
| 1941 | irq_ptr->state=state; |
| 1942 | for (i=0;i<irq_ptr->no_input_qs;i++) |
| 1943 | irq_ptr->input_qs[i]->state=state; |
| 1944 | for (i=0;i<irq_ptr->no_output_qs;i++) |
| 1945 | irq_ptr->output_qs[i]->state=state; |
| 1946 | mb(); |
| 1947 | } |
| 1948 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1949 | static void |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1950 | qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | { |
| 1952 | char dbf_text[15]; |
| 1953 | |
| 1954 | if (irb->esw.esw0.erw.cons) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1955 | sprintf(dbf_text,"sens%4x",schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 1957 | QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN); |
| 1958 | |
| 1959 | QDIO_PRINT_WARN("sense data available on qdio channel.\n"); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1960 | QDIO_HEXDUMP16(WARN,"irb: ",irb); |
| 1961 | QDIO_HEXDUMP16(WARN,"sense data: ",irb->ecw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | } |
| 1965 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1966 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | qdio_handle_pci(struct qdio_irq *irq_ptr) |
| 1968 | { |
| 1969 | int i; |
| 1970 | struct qdio_q *q; |
| 1971 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1972 | qdio_perf_stat_inc(&perf_stats.pcis); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | for (i=0;i<irq_ptr->no_input_qs;i++) { |
| 1974 | q=irq_ptr->input_qs[i]; |
| 1975 | if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) |
| 1976 | qdio_mark_q(q); |
| 1977 | else { |
Ursula Braun | 853944c | 2007-05-10 15:45:47 +0200 | [diff] [blame] | 1978 | qdio_perf_stat_dec(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | __qdio_inbound_processing(q); |
| 1980 | } |
| 1981 | } |
| 1982 | if (!irq_ptr->hydra_gives_outbound_pcis) |
| 1983 | return; |
| 1984 | for (i=0;i<irq_ptr->no_output_qs;i++) { |
| 1985 | q=irq_ptr->output_qs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | if (qdio_is_outbound_q_done(q)) |
| 1987 | continue; |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 1988 | qdio_perf_stat_dec(&perf_stats.tl_runs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | if (!irq_ptr->sync_done_on_outb_pcis) |
| 1990 | SYNC_MEMORY; |
| 1991 | __qdio_outbound_processing(q); |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | static void qdio_establish_handle_irq(struct ccw_device*, int, int); |
| 1996 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1997 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm, |
| 1999 | int cstat, int dstat) |
| 2000 | { |
| 2001 | struct qdio_irq *irq_ptr; |
| 2002 | struct qdio_q *q; |
| 2003 | char dbf_text[15]; |
| 2004 | |
| 2005 | irq_ptr = cdev->private->qdio_data; |
| 2006 | |
| 2007 | QDIO_DBF_TEXT2(1, trace, "ick2"); |
| 2008 | sprintf(dbf_text,"%s", cdev->dev.bus_id); |
| 2009 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 2010 | QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int)); |
| 2011 | QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int)); |
| 2012 | QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int)); |
| 2013 | QDIO_PRINT_ERR("received check condition on activate " \ |
| 2014 | "queues on device %s (cs=x%x, ds=x%x).\n", |
| 2015 | cdev->dev.bus_id, cstat, dstat); |
| 2016 | if (irq_ptr->no_input_qs) { |
| 2017 | q=irq_ptr->input_qs[0]; |
| 2018 | } else if (irq_ptr->no_output_qs) { |
| 2019 | q=irq_ptr->output_qs[0]; |
| 2020 | } else { |
| 2021 | QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n", |
| 2022 | cdev->dev.bus_id); |
| 2023 | goto omit_handler_call; |
| 2024 | } |
| 2025 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| |
| 2026 | QDIO_STATUS_LOOK_FOR_ERROR, |
| 2027 | 0,0,0,-1,-1,q->int_parm); |
| 2028 | omit_handler_call: |
| 2029 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED); |
| 2030 | |
| 2031 | } |
| 2032 | |
| 2033 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 2034 | qdio_call_shutdown(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 2036 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | struct ccw_device *cdev; |
| 2038 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 2039 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 2040 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
| 2042 | put_device(&cdev->dev); |
| 2043 | } |
| 2044 | |
| 2045 | static void |
| 2046 | qdio_timeout_handler(struct ccw_device *cdev) |
| 2047 | { |
| 2048 | struct qdio_irq *irq_ptr; |
| 2049 | char dbf_text[15]; |
| 2050 | |
| 2051 | QDIO_DBF_TEXT2(0, trace, "qtoh"); |
| 2052 | sprintf(dbf_text, "%s", cdev->dev.bus_id); |
| 2053 | QDIO_DBF_TEXT2(0, trace, dbf_text); |
| 2054 | |
| 2055 | irq_ptr = cdev->private->qdio_data; |
| 2056 | sprintf(dbf_text, "state:%d", irq_ptr->state); |
| 2057 | QDIO_DBF_TEXT2(0, trace, dbf_text); |
| 2058 | |
| 2059 | switch (irq_ptr->state) { |
| 2060 | case QDIO_IRQ_STATE_INACTIVE: |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2061 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n", |
| 2062 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | QDIO_DBF_TEXT2(1,setup,"eq:timeo"); |
| 2064 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); |
| 2065 | break; |
| 2066 | case QDIO_IRQ_STATE_CLEANUP: |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2067 | QDIO_PRINT_INFO("Did not get interrupt on cleanup, " |
| 2068 | "irq=0.%x.%x.\n", |
| 2069 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); |
| 2071 | break; |
| 2072 | case QDIO_IRQ_STATE_ESTABLISHED: |
| 2073 | case QDIO_IRQ_STATE_ACTIVE: |
| 2074 | /* I/O has been terminated by common I/O layer. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2075 | QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n", |
| 2076 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | QDIO_DBF_TEXT2(1, trace, "cio:term"); |
| 2078 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED); |
| 2079 | if (get_device(&cdev->dev)) { |
| 2080 | /* Can't call shutdown from interrupt context. */ |
| 2081 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 2082 | qdio_call_shutdown); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | queue_work(ccw_device_work, &cdev->private->kick_work); |
| 2084 | } |
| 2085 | break; |
| 2086 | default: |
| 2087 | BUG(); |
| 2088 | } |
| 2089 | ccw_device_set_timeout(cdev, 0); |
| 2090 | wake_up(&cdev->private->wait_q); |
| 2091 | } |
| 2092 | |
| 2093 | static void |
| 2094 | qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) |
| 2095 | { |
| 2096 | struct qdio_irq *irq_ptr; |
| 2097 | int cstat,dstat; |
| 2098 | char dbf_text[15]; |
| 2099 | |
| 2100 | #ifdef CONFIG_QDIO_DEBUG |
| 2101 | QDIO_DBF_TEXT4(0, trace, "qint"); |
| 2102 | sprintf(dbf_text, "%s", cdev->dev.bus_id); |
| 2103 | QDIO_DBF_TEXT4(0, trace, dbf_text); |
| 2104 | #endif /* CONFIG_QDIO_DEBUG */ |
| 2105 | |
| 2106 | if (!intparm) { |
| 2107 | QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \ |
| 2108 | "handler, device %s\n", cdev->dev.bus_id); |
| 2109 | return; |
| 2110 | } |
| 2111 | |
| 2112 | irq_ptr = cdev->private->qdio_data; |
| 2113 | if (!irq_ptr) { |
| 2114 | QDIO_DBF_TEXT2(1, trace, "uint"); |
| 2115 | sprintf(dbf_text,"%s", cdev->dev.bus_id); |
| 2116 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 2117 | QDIO_PRINT_ERR("received interrupt on unused device %s!\n", |
| 2118 | cdev->dev.bus_id); |
| 2119 | return; |
| 2120 | } |
| 2121 | |
| 2122 | if (IS_ERR(irb)) { |
| 2123 | /* Currently running i/o is in error. */ |
| 2124 | switch (PTR_ERR(irb)) { |
| 2125 | case -EIO: |
| 2126 | QDIO_PRINT_ERR("i/o error on device %s\n", |
| 2127 | cdev->dev.bus_id); |
| 2128 | return; |
| 2129 | case -ETIMEDOUT: |
| 2130 | qdio_timeout_handler(cdev); |
| 2131 | return; |
| 2132 | default: |
| 2133 | QDIO_PRINT_ERR("unknown error state %ld on device %s\n", |
| 2134 | PTR_ERR(irb), cdev->dev.bus_id); |
| 2135 | return; |
| 2136 | } |
| 2137 | } |
| 2138 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2139 | qdio_irq_check_sense(irq_ptr->schid, irb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
| 2141 | #ifdef CONFIG_QDIO_DEBUG |
| 2142 | sprintf(dbf_text, "state:%d", irq_ptr->state); |
| 2143 | QDIO_DBF_TEXT4(0, trace, dbf_text); |
| 2144 | #endif /* CONFIG_QDIO_DEBUG */ |
| 2145 | |
| 2146 | cstat = irb->scsw.cstat; |
| 2147 | dstat = irb->scsw.dstat; |
| 2148 | |
| 2149 | switch (irq_ptr->state) { |
| 2150 | case QDIO_IRQ_STATE_INACTIVE: |
| 2151 | qdio_establish_handle_irq(cdev, cstat, dstat); |
| 2152 | break; |
| 2153 | |
| 2154 | case QDIO_IRQ_STATE_CLEANUP: |
| 2155 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); |
| 2156 | break; |
| 2157 | |
| 2158 | case QDIO_IRQ_STATE_ESTABLISHED: |
| 2159 | case QDIO_IRQ_STATE_ACTIVE: |
| 2160 | if (cstat & SCHN_STAT_PCI) { |
| 2161 | qdio_handle_pci(irq_ptr); |
| 2162 | break; |
| 2163 | } |
| 2164 | |
| 2165 | if ((cstat&~SCHN_STAT_PCI)||dstat) { |
| 2166 | qdio_handle_activate_check(cdev, intparm, cstat, dstat); |
| 2167 | break; |
| 2168 | } |
| 2169 | default: |
| 2170 | QDIO_PRINT_ERR("got interrupt for queues in state %d on " \ |
| 2171 | "device %s?!\n", |
| 2172 | irq_ptr->state, cdev->dev.bus_id); |
| 2173 | } |
| 2174 | wake_up(&cdev->private->wait_q); |
| 2175 | |
| 2176 | } |
| 2177 | |
| 2178 | int |
| 2179 | qdio_synchronize(struct ccw_device *cdev, unsigned int flags, |
| 2180 | unsigned int queue_number) |
| 2181 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2182 | int cc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | struct qdio_q *q; |
| 2184 | struct qdio_irq *irq_ptr; |
| 2185 | void *ptr; |
| 2186 | #ifdef CONFIG_QDIO_DEBUG |
| 2187 | char dbf_text[15]="SyncXXXX"; |
| 2188 | #endif |
| 2189 | |
| 2190 | irq_ptr = cdev->private->qdio_data; |
| 2191 | if (!irq_ptr) |
| 2192 | return -ENODEV; |
| 2193 | |
| 2194 | #ifdef CONFIG_QDIO_DEBUG |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2195 | *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN); |
| 2197 | *((int*)(&dbf_text[0]))=flags; |
| 2198 | *((int*)(&dbf_text[4]))=queue_number; |
| 2199 | QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN); |
| 2200 | #endif /* CONFIG_QDIO_DEBUG */ |
| 2201 | |
| 2202 | if (flags&QDIO_FLAG_SYNC_INPUT) { |
| 2203 | q=irq_ptr->input_qs[queue_number]; |
| 2204 | if (!q) |
| 2205 | return -EINVAL; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2206 | if (!(irq_ptr->is_qebsm)) |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2207 | cc = do_siga_sync(q->schid, 0, q->mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | } else if (flags&QDIO_FLAG_SYNC_OUTPUT) { |
| 2209 | q=irq_ptr->output_qs[queue_number]; |
| 2210 | if (!q) |
| 2211 | return -EINVAL; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2212 | if (!(irq_ptr->is_qebsm)) |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2213 | cc = do_siga_sync(q->schid, q->mask, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | } else |
| 2215 | return -EINVAL; |
| 2216 | |
| 2217 | ptr=&cc; |
| 2218 | if (cc) |
| 2219 | QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int)); |
| 2220 | |
| 2221 | return cc; |
| 2222 | } |
| 2223 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2224 | static void |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2225 | qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned char qdioac, |
| 2226 | unsigned long token) |
| 2227 | { |
| 2228 | struct qdio_q *q; |
| 2229 | int i; |
| 2230 | unsigned int count, start_buf; |
| 2231 | char dbf_text[15]; |
| 2232 | |
| 2233 | /*check if QEBSM is disabled */ |
| 2234 | if (!(irq_ptr->is_qebsm) || !(qdioac & 0x01)) { |
| 2235 | irq_ptr->is_qebsm = 0; |
| 2236 | irq_ptr->sch_token = 0; |
| 2237 | irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM; |
| 2238 | QDIO_DBF_TEXT0(0,setup,"noV=V"); |
| 2239 | return; |
| 2240 | } |
| 2241 | irq_ptr->sch_token = token; |
| 2242 | /*input queue*/ |
| 2243 | for (i = 0; i < irq_ptr->no_input_qs;i++) { |
| 2244 | q = irq_ptr->input_qs[i]; |
| 2245 | count = QDIO_MAX_BUFFERS_PER_Q; |
| 2246 | start_buf = 0; |
| 2247 | set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count); |
| 2248 | } |
| 2249 | sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm); |
| 2250 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2251 | sprintf(dbf_text,"%8lx",irq_ptr->sch_token); |
| 2252 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2253 | /*output queue*/ |
| 2254 | for (i = 0; i < irq_ptr->no_output_qs; i++) { |
| 2255 | q = irq_ptr->output_qs[i]; |
| 2256 | count = QDIO_MAX_BUFFERS_PER_Q; |
| 2257 | start_buf = 0; |
| 2258 | set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count); |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | static void |
| 2263 | qdio_get_ssqd_information(struct qdio_irq *irq_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | { |
| 2265 | int result; |
| 2266 | unsigned char qdioac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | struct { |
| 2268 | struct chsc_header request; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2269 | u16 reserved1:10; |
| 2270 | u16 ssid:2; |
| 2271 | u16 fmt:4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | u16 first_sch; |
| 2273 | u16 reserved2; |
| 2274 | u16 last_sch; |
| 2275 | u32 reserved3; |
| 2276 | struct chsc_header response; |
| 2277 | u32 reserved4; |
| 2278 | u8 flags; |
| 2279 | u8 reserved5; |
| 2280 | u16 sch; |
| 2281 | u8 qfmt; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2282 | u8 parm; |
| 2283 | u8 qdioac1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | u8 sch_class; |
| 2285 | u8 reserved7; |
| 2286 | u8 icnt; |
| 2287 | u8 reserved8; |
| 2288 | u8 ocnt; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2289 | u8 reserved9; |
| 2290 | u8 mbccnt; |
| 2291 | u16 qdioac2; |
| 2292 | u64 sch_token; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | } *ssqd_area; |
| 2294 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2295 | QDIO_DBF_TEXT0(0,setup,"getssqd"); |
| 2296 | qdioac = 0; |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2297 | ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | if (!ssqd_area) { |
| 2299 | QDIO_PRINT_WARN("Could not get memory for chsc. Using all " \ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2300 | "SIGAs for sch x%x.\n", irq_ptr->schid.sch_no); |
Jan Glauber | a07a5b3 | 2007-07-17 13:36:09 +0200 | [diff] [blame] | 2301 | irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY | |
| 2302 | CHSC_FLAG_SIGA_OUTPUT_NECESSARY | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2303 | CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */ |
| 2304 | irq_ptr->is_qebsm = 0; |
| 2305 | irq_ptr->sch_token = 0; |
| 2306 | irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM; |
| 2307 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | ssqd_area->request = (struct chsc_header) { |
| 2311 | .length = 0x0010, |
| 2312 | .code = 0x0024, |
| 2313 | }; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2314 | ssqd_area->first_sch = irq_ptr->schid.sch_no; |
| 2315 | ssqd_area->last_sch = irq_ptr->schid.sch_no; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2316 | ssqd_area->ssid = irq_ptr->schid.ssid; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2317 | result = chsc(ssqd_area); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | |
| 2319 | if (result) { |
| 2320 | QDIO_PRINT_WARN("CHSC returned cc %i. Using all " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2321 | "SIGAs for sch 0.%x.%x.\n", result, |
| 2322 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Jan Glauber | a07a5b3 | 2007-07-17 13:36:09 +0200 | [diff] [blame] | 2323 | qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY | |
| 2324 | CHSC_FLAG_SIGA_OUTPUT_NECESSARY | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2326 | irq_ptr->is_qebsm = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | goto out; |
| 2328 | } |
| 2329 | |
| 2330 | if (ssqd_area->response.code != QDIO_CHSC_RESPONSE_CODE_OK) { |
| 2331 | QDIO_PRINT_WARN("response upon checking SIGA needs " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2332 | "is 0x%x. Using all SIGAs for sch 0.%x.%x.\n", |
| 2333 | ssqd_area->response.code, |
| 2334 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Jan Glauber | a07a5b3 | 2007-07-17 13:36:09 +0200 | [diff] [blame] | 2335 | qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY | |
| 2336 | CHSC_FLAG_SIGA_OUTPUT_NECESSARY | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2338 | irq_ptr->is_qebsm = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | goto out; |
| 2340 | } |
| 2341 | if (!(ssqd_area->flags & CHSC_FLAG_QDIO_CAPABILITY) || |
| 2342 | !(ssqd_area->flags & CHSC_FLAG_VALIDITY) || |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2343 | (ssqd_area->sch != irq_ptr->schid.sch_no)) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2344 | QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \ |
| 2345 | "using all SIGAs.\n", |
| 2346 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY | |
| 2348 | CHSC_FLAG_SIGA_OUTPUT_NECESSARY | |
| 2349 | CHSC_FLAG_SIGA_SYNC_NECESSARY; /* worst case */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2350 | irq_ptr->is_qebsm = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | goto out; |
| 2352 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2353 | qdioac = ssqd_area->qdioac1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | out: |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2355 | qdio_check_subchannel_qebsm(irq_ptr, qdioac, |
| 2356 | ssqd_area->sch_token); |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2357 | mempool_free(ssqd_area, qdio_mempool_scssc); |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2358 | irq_ptr->qdioac = qdioac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | static unsigned int |
| 2362 | tiqdio_check_chsc_availability(void) |
| 2363 | { |
| 2364 | char dbf_text[15]; |
| 2365 | |
| 2366 | if (!css_characteristics_avail) |
| 2367 | return -EIO; |
| 2368 | |
| 2369 | /* Check for bit 41. */ |
| 2370 | if (!css_general_characteristics.aif) { |
| 2371 | QDIO_PRINT_WARN("Adapter interruption facility not " \ |
| 2372 | "installed.\n"); |
| 2373 | return -ENOENT; |
| 2374 | } |
| 2375 | |
| 2376 | /* Check for bits 107 and 108. */ |
| 2377 | if (!css_chsc_characteristics.scssc || |
| 2378 | !css_chsc_characteristics.scsscf) { |
| 2379 | QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \ |
| 2380 | "not available.\n"); |
| 2381 | return -ENOENT; |
| 2382 | } |
| 2383 | |
| 2384 | /* Check for OSA/FCP thin interrupts (bit 67). */ |
| 2385 | hydra_thinints = css_general_characteristics.aif_osa; |
| 2386 | sprintf(dbf_text,"hydrati%1x", hydra_thinints); |
| 2387 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2388 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 2389 | #ifdef CONFIG_64BIT |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 2390 | /* Check for QEBSM support in general (bit 58). */ |
| 2391 | is_passthrough = css_general_characteristics.qebsm; |
| 2392 | #endif |
| 2393 | sprintf(dbf_text,"cssQBS:%1x", is_passthrough); |
| 2394 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | /* Check for aif time delay disablement fac (bit 56). If installed, |
| 2397 | * omit svs even under lpar (good point by rick again) */ |
| 2398 | omit_svs = css_general_characteristics.aif_tdd; |
| 2399 | sprintf(dbf_text,"omitsvs%1x", omit_svs); |
| 2400 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2401 | return 0; |
| 2402 | } |
| 2403 | |
| 2404 | |
| 2405 | static unsigned int |
| 2406 | tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero) |
| 2407 | { |
| 2408 | unsigned long real_addr_local_summary_bit; |
| 2409 | unsigned long real_addr_dev_st_chg_ind; |
| 2410 | void *ptr; |
| 2411 | char dbf_text[15]; |
| 2412 | |
| 2413 | unsigned int resp_code; |
| 2414 | int result; |
| 2415 | |
| 2416 | struct { |
| 2417 | struct chsc_header request; |
| 2418 | u16 operation_code; |
| 2419 | u16 reserved1; |
| 2420 | u32 reserved2; |
| 2421 | u32 reserved3; |
| 2422 | u64 summary_indicator_addr; |
| 2423 | u64 subchannel_indicator_addr; |
| 2424 | u32 ks:4; |
| 2425 | u32 kc:4; |
| 2426 | u32 reserved4:21; |
| 2427 | u32 isc:3; |
| 2428 | u32 word_with_d_bit; |
| 2429 | /* set to 0x10000000 to enable |
| 2430 | * time delay disablement facility */ |
| 2431 | u32 reserved5; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2432 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | u32 reserved6[1004]; |
| 2434 | struct chsc_header response; |
| 2435 | u32 reserved7; |
| 2436 | } *scssc_area; |
| 2437 | |
| 2438 | if (!irq_ptr->is_thinint_irq) |
| 2439 | return -ENODEV; |
| 2440 | |
| 2441 | if (reset_to_zero) { |
| 2442 | real_addr_local_summary_bit=0; |
| 2443 | real_addr_dev_st_chg_ind=0; |
| 2444 | } else { |
| 2445 | real_addr_local_summary_bit= |
| 2446 | virt_to_phys((volatile void *)indicators); |
| 2447 | real_addr_dev_st_chg_ind= |
| 2448 | virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind); |
| 2449 | } |
| 2450 | |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2451 | scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | if (!scssc_area) { |
| 2453 | QDIO_PRINT_WARN("No memory for setting indicators on " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2454 | "subchannel 0.%x.%x.\n", |
| 2455 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | return -ENOMEM; |
| 2457 | } |
| 2458 | scssc_area->request = (struct chsc_header) { |
| 2459 | .length = 0x0fe0, |
| 2460 | .code = 0x0021, |
| 2461 | }; |
| 2462 | scssc_area->operation_code = 0; |
| 2463 | |
| 2464 | scssc_area->summary_indicator_addr = real_addr_local_summary_bit; |
| 2465 | scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind; |
| 2466 | scssc_area->ks = QDIO_STORAGE_KEY; |
| 2467 | scssc_area->kc = QDIO_STORAGE_KEY; |
| 2468 | scssc_area->isc = TIQDIO_THININT_ISC; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2469 | scssc_area->schid = irq_ptr->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | /* enables the time delay disablement facility. Don't care |
| 2471 | * whether it is really there (i.e. we haven't checked for |
| 2472 | * it) */ |
| 2473 | if (css_general_characteristics.aif_tdd) |
| 2474 | scssc_area->word_with_d_bit = 0x10000000; |
| 2475 | else |
| 2476 | QDIO_PRINT_WARN("Time delay disablement facility " \ |
| 2477 | "not available\n"); |
| 2478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | result = chsc(scssc_area); |
| 2480 | if (result) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2481 | QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \ |
| 2482 | "cc=%i.\n", |
| 2483 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | result = -EIO; |
| 2485 | goto out; |
| 2486 | } |
| 2487 | |
| 2488 | resp_code = scssc_area->response.code; |
| 2489 | if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) { |
| 2490 | QDIO_PRINT_WARN("response upon setting indicators " \ |
| 2491 | "is 0x%x.\n",resp_code); |
| 2492 | sprintf(dbf_text,"sidR%4x",resp_code); |
| 2493 | QDIO_DBF_TEXT1(0,trace,dbf_text); |
| 2494 | QDIO_DBF_TEXT1(0,setup,dbf_text); |
| 2495 | ptr=&scssc_area->response; |
| 2496 | QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN); |
| 2497 | result = -EIO; |
| 2498 | goto out; |
| 2499 | } |
| 2500 | |
| 2501 | QDIO_DBF_TEXT2(0,setup,"setscind"); |
| 2502 | QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit, |
| 2503 | sizeof(unsigned long)); |
| 2504 | QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long)); |
| 2505 | result = 0; |
| 2506 | out: |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2507 | mempool_free(scssc_area, qdio_mempool_scssc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | return result; |
| 2509 | |
| 2510 | } |
| 2511 | |
| 2512 | static unsigned int |
| 2513 | tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target) |
| 2514 | { |
| 2515 | unsigned int resp_code; |
| 2516 | int result; |
| 2517 | void *ptr; |
| 2518 | char dbf_text[15]; |
| 2519 | |
| 2520 | struct { |
| 2521 | struct chsc_header request; |
| 2522 | u16 operation_code; |
| 2523 | u16 reserved1; |
| 2524 | u32 reserved2; |
| 2525 | u32 reserved3; |
| 2526 | u32 reserved4[2]; |
| 2527 | u32 delay_target; |
| 2528 | u32 reserved5[1009]; |
| 2529 | struct chsc_header response; |
| 2530 | u32 reserved6; |
| 2531 | } *scsscf_area; |
| 2532 | |
| 2533 | if (!irq_ptr->is_thinint_irq) |
| 2534 | return -ENODEV; |
| 2535 | |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2536 | scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | if (!scsscf_area) { |
| 2538 | QDIO_PRINT_WARN("No memory for setting delay target on " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2539 | "subchannel 0.%x.%x.\n", |
| 2540 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | return -ENOMEM; |
| 2542 | } |
| 2543 | scsscf_area->request = (struct chsc_header) { |
| 2544 | .length = 0x0fe0, |
| 2545 | .code = 0x1027, |
| 2546 | }; |
| 2547 | |
| 2548 | scsscf_area->delay_target = delay_target<<16; |
| 2549 | |
| 2550 | result=chsc(scsscf_area); |
| 2551 | if (result) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2552 | QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \ |
| 2553 | "cc=%i. Continuing.\n", |
| 2554 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2555 | result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | result = -EIO; |
| 2557 | goto out; |
| 2558 | } |
| 2559 | |
| 2560 | resp_code = scsscf_area->response.code; |
| 2561 | if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) { |
| 2562 | QDIO_PRINT_WARN("response upon setting delay target " \ |
| 2563 | "is 0x%x. Continuing.\n",resp_code); |
| 2564 | sprintf(dbf_text,"sdtR%4x",resp_code); |
| 2565 | QDIO_DBF_TEXT1(0,trace,dbf_text); |
| 2566 | QDIO_DBF_TEXT1(0,setup,dbf_text); |
| 2567 | ptr=&scsscf_area->response; |
| 2568 | QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN); |
| 2569 | } |
| 2570 | QDIO_DBF_TEXT2(0,trace,"delytrgt"); |
| 2571 | QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long)); |
| 2572 | result = 0; /* not critical */ |
| 2573 | out: |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 2574 | mempool_free(scsscf_area, qdio_mempool_scssc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | return result; |
| 2576 | } |
| 2577 | |
| 2578 | int |
| 2579 | qdio_cleanup(struct ccw_device *cdev, int how) |
| 2580 | { |
| 2581 | struct qdio_irq *irq_ptr; |
| 2582 | char dbf_text[15]; |
| 2583 | int rc; |
| 2584 | |
| 2585 | irq_ptr = cdev->private->qdio_data; |
| 2586 | if (!irq_ptr) |
| 2587 | return -ENODEV; |
| 2588 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2589 | sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | QDIO_DBF_TEXT1(0,trace,dbf_text); |
| 2591 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2592 | |
| 2593 | rc = qdio_shutdown(cdev, how); |
| 2594 | if ((rc == 0) || (rc == -EINPROGRESS)) |
| 2595 | rc = qdio_free(cdev); |
| 2596 | return rc; |
| 2597 | } |
| 2598 | |
| 2599 | int |
| 2600 | qdio_shutdown(struct ccw_device *cdev, int how) |
| 2601 | { |
| 2602 | struct qdio_irq *irq_ptr; |
| 2603 | int i; |
| 2604 | int result = 0; |
| 2605 | int rc; |
| 2606 | unsigned long flags; |
| 2607 | int timeout; |
| 2608 | char dbf_text[15]; |
| 2609 | |
| 2610 | irq_ptr = cdev->private->qdio_data; |
| 2611 | if (!irq_ptr) |
| 2612 | return -ENODEV; |
| 2613 | |
| 2614 | down(&irq_ptr->setting_up_sema); |
| 2615 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2616 | sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | QDIO_DBF_TEXT1(0,trace,dbf_text); |
| 2618 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2619 | |
| 2620 | /* mark all qs as uninteresting */ |
| 2621 | for (i=0;i<irq_ptr->no_input_qs;i++) |
| 2622 | atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1); |
| 2623 | |
| 2624 | for (i=0;i<irq_ptr->no_output_qs;i++) |
| 2625 | atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1); |
| 2626 | |
| 2627 | tasklet_kill(&tiqdio_tasklet); |
| 2628 | |
| 2629 | for (i=0;i<irq_ptr->no_input_qs;i++) { |
| 2630 | qdio_unmark_q(irq_ptr->input_qs[i]); |
| 2631 | tasklet_kill(&irq_ptr->input_qs[i]->tasklet); |
| 2632 | wait_event_interruptible_timeout(cdev->private->wait_q, |
| 2633 | !atomic_read(&irq_ptr-> |
| 2634 | input_qs[i]-> |
| 2635 | use_count), |
| 2636 | QDIO_NO_USE_COUNT_TIMEOUT); |
| 2637 | if (atomic_read(&irq_ptr->input_qs[i]->use_count)) |
| 2638 | result=-EINPROGRESS; |
| 2639 | } |
| 2640 | |
| 2641 | for (i=0;i<irq_ptr->no_output_qs;i++) { |
| 2642 | tasklet_kill(&irq_ptr->output_qs[i]->tasklet); |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 2643 | del_timer(&irq_ptr->output_qs[i]->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | wait_event_interruptible_timeout(cdev->private->wait_q, |
| 2645 | !atomic_read(&irq_ptr-> |
| 2646 | output_qs[i]-> |
| 2647 | use_count), |
| 2648 | QDIO_NO_USE_COUNT_TIMEOUT); |
| 2649 | if (atomic_read(&irq_ptr->output_qs[i]->use_count)) |
| 2650 | result=-EINPROGRESS; |
| 2651 | } |
| 2652 | |
| 2653 | /* cleanup subchannel */ |
| 2654 | spin_lock_irqsave(get_ccwdev_lock(cdev),flags); |
| 2655 | if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) { |
| 2656 | rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); |
| 2657 | timeout=QDIO_CLEANUP_CLEAR_TIMEOUT; |
| 2658 | } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) { |
| 2659 | rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); |
| 2660 | timeout=QDIO_CLEANUP_HALT_TIMEOUT; |
| 2661 | } else { /* default behaviour */ |
| 2662 | rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); |
| 2663 | timeout=QDIO_CLEANUP_HALT_TIMEOUT; |
| 2664 | } |
| 2665 | if (rc == -ENODEV) { |
| 2666 | /* No need to wait for device no longer present. */ |
| 2667 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); |
| 2668 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 2669 | } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) { |
| 2670 | /* |
| 2671 | * Whoever put another handler there, has to cope with the |
| 2672 | * interrupt theirself. Might happen if qdio_shutdown was |
| 2673 | * called on already shutdown queues, but this shouldn't have |
| 2674 | * bad side effects. |
| 2675 | */ |
| 2676 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); |
| 2677 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 2678 | } else if (rc == 0) { |
| 2679 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP); |
| 2680 | ccw_device_set_timeout(cdev, timeout); |
| 2681 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags); |
| 2682 | |
| 2683 | wait_event(cdev->private->wait_q, |
| 2684 | irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || |
| 2685 | irq_ptr->state == QDIO_IRQ_STATE_ERR); |
| 2686 | } else { |
| 2687 | QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for " |
| 2688 | "device %s\n", result, cdev->dev.bus_id); |
| 2689 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 2690 | result = rc; |
| 2691 | goto out; |
| 2692 | } |
| 2693 | if (irq_ptr->is_thinint_irq) { |
| 2694 | qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind); |
| 2695 | tiqdio_set_subchannel_ind(irq_ptr,1); |
| 2696 | /* reset adapter interrupt indicators */ |
| 2697 | } |
| 2698 | |
| 2699 | /* exchange int handlers, if necessary */ |
| 2700 | if ((void*)cdev->handler == (void*)qdio_handler) |
| 2701 | cdev->handler=irq_ptr->original_int_handler; |
| 2702 | |
| 2703 | /* Ignore errors. */ |
| 2704 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); |
| 2705 | ccw_device_set_timeout(cdev, 0); |
| 2706 | out: |
| 2707 | up(&irq_ptr->setting_up_sema); |
| 2708 | return result; |
| 2709 | } |
| 2710 | |
| 2711 | int |
| 2712 | qdio_free(struct ccw_device *cdev) |
| 2713 | { |
| 2714 | struct qdio_irq *irq_ptr; |
| 2715 | char dbf_text[15]; |
| 2716 | |
| 2717 | irq_ptr = cdev->private->qdio_data; |
| 2718 | if (!irq_ptr) |
| 2719 | return -ENODEV; |
| 2720 | |
| 2721 | down(&irq_ptr->setting_up_sema); |
| 2722 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2723 | sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | QDIO_DBF_TEXT1(0,trace,dbf_text); |
| 2725 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2726 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 2727 | cdev->private->qdio_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | |
| 2729 | up(&irq_ptr->setting_up_sema); |
| 2730 | |
| 2731 | qdio_release_irq_memory(irq_ptr); |
| 2732 | module_put(THIS_MODULE); |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2736 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | qdio_allocate_do_dbf(struct qdio_initialize *init_data) |
| 2738 | { |
| 2739 | char dbf_text[20]; /* if a printf printed out more than 8 chars */ |
| 2740 | |
| 2741 | sprintf(dbf_text,"qfmt:%x",init_data->q_format); |
| 2742 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2743 | QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8); |
| 2744 | sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format); |
| 2745 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2746 | QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*)); |
| 2747 | QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*)); |
| 2748 | QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*)); |
| 2749 | sprintf(dbf_text,"miit%4x",init_data->min_input_threshold); |
| 2750 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2751 | sprintf(dbf_text,"mait%4x",init_data->max_input_threshold); |
| 2752 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2753 | sprintf(dbf_text,"miot%4x",init_data->min_output_threshold); |
| 2754 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2755 | sprintf(dbf_text,"maot%4x",init_data->max_output_threshold); |
| 2756 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2757 | sprintf(dbf_text,"niq:%4x",init_data->no_input_qs); |
| 2758 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2759 | sprintf(dbf_text,"noq:%4x",init_data->no_output_qs); |
| 2760 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2761 | QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*)); |
| 2762 | QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*)); |
| 2763 | QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long)); |
| 2764 | QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long)); |
| 2765 | QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*)); |
| 2766 | QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*)); |
| 2767 | } |
| 2768 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2769 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt) |
| 2771 | { |
| 2772 | irq_ptr->input_qs[i]->is_iqdio_q = iqfmt; |
| 2773 | irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq; |
| 2774 | |
| 2775 | irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib); |
| 2776 | |
| 2777 | irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl); |
| 2778 | |
| 2779 | irq_ptr->qdr->qdf0[i].slsba= |
| 2780 | (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]); |
| 2781 | |
| 2782 | irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY; |
| 2783 | irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY; |
| 2784 | irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY; |
| 2785 | irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY; |
| 2786 | } |
| 2787 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2788 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i, |
| 2790 | int j, int iqfmt) |
| 2791 | { |
| 2792 | irq_ptr->output_qs[i]->is_iqdio_q = iqfmt; |
| 2793 | irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq; |
| 2794 | |
| 2795 | irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib); |
| 2796 | |
| 2797 | irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl); |
| 2798 | |
| 2799 | irq_ptr->qdr->qdf0[i+j].slsba= |
| 2800 | (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]); |
| 2801 | |
| 2802 | irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY; |
| 2803 | irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY; |
| 2804 | irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY; |
| 2805 | irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY; |
| 2806 | } |
| 2807 | |
| 2808 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2809 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr) |
| 2811 | { |
| 2812 | int i; |
| 2813 | |
| 2814 | for (i=0;i<irq_ptr->no_input_qs;i++) { |
| 2815 | irq_ptr->input_qs[i]->siga_sync= |
| 2816 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY; |
| 2817 | irq_ptr->input_qs[i]->siga_in= |
| 2818 | irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY; |
| 2819 | irq_ptr->input_qs[i]->siga_out= |
| 2820 | irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY; |
| 2821 | irq_ptr->input_qs[i]->siga_sync_done_on_thinints= |
| 2822 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS; |
| 2823 | irq_ptr->input_qs[i]->hydra_gives_outbound_pcis= |
| 2824 | irq_ptr->hydra_gives_outbound_pcis; |
| 2825 | irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis= |
| 2826 | ((irq_ptr->qdioac& |
| 2827 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| |
| 2828 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))== |
| 2829 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| |
| 2830 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS)); |
| 2831 | |
| 2832 | } |
| 2833 | } |
| 2834 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2835 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr) |
| 2837 | { |
| 2838 | int i; |
| 2839 | |
| 2840 | for (i=0;i<irq_ptr->no_output_qs;i++) { |
| 2841 | irq_ptr->output_qs[i]->siga_sync= |
| 2842 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY; |
| 2843 | irq_ptr->output_qs[i]->siga_in= |
| 2844 | irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY; |
| 2845 | irq_ptr->output_qs[i]->siga_out= |
| 2846 | irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY; |
| 2847 | irq_ptr->output_qs[i]->siga_sync_done_on_thinints= |
| 2848 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS; |
| 2849 | irq_ptr->output_qs[i]->hydra_gives_outbound_pcis= |
| 2850 | irq_ptr->hydra_gives_outbound_pcis; |
| 2851 | irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis= |
| 2852 | ((irq_ptr->qdioac& |
| 2853 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| |
| 2854 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))== |
| 2855 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| |
| 2856 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS)); |
| 2857 | |
| 2858 | } |
| 2859 | } |
| 2860 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2861 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat, |
| 2863 | int dstat) |
| 2864 | { |
| 2865 | char dbf_text[15]; |
| 2866 | struct qdio_irq *irq_ptr; |
| 2867 | |
| 2868 | irq_ptr = cdev->private->qdio_data; |
| 2869 | |
| 2870 | if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2871 | sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | QDIO_DBF_TEXT2(1,trace,dbf_text); |
| 2873 | QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int)); |
| 2874 | QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int)); |
| 2875 | QDIO_PRINT_ERR("received check condition on establish " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2876 | "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n", |
| 2877 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, |
| 2878 | cstat,dstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR); |
| 2880 | } |
| 2881 | |
| 2882 | if (!(dstat & DEV_STAT_DEV_END)) { |
| 2883 | QDIO_DBF_TEXT2(1,setup,"eq:no de"); |
| 2884 | QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat)); |
| 2885 | QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat)); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2886 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | "device end: dstat=%02x, cstat=%02x\n", |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2888 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, |
| 2889 | dstat, cstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); |
| 2891 | return 1; |
| 2892 | } |
| 2893 | |
| 2894 | if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) { |
| 2895 | QDIO_DBF_TEXT2(1,setup,"eq:badio"); |
| 2896 | QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat)); |
| 2897 | QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat)); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2898 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | "the following devstat: dstat=%02x, " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 2900 | "cstat=%02x\n", irq_ptr->schid.ssid, |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 2901 | irq_ptr->schid.sch_no, dstat, cstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); |
| 2903 | return 1; |
| 2904 | } |
| 2905 | return 0; |
| 2906 | } |
| 2907 | |
| 2908 | static void |
| 2909 | qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat) |
| 2910 | { |
| 2911 | struct qdio_irq *irq_ptr; |
| 2912 | char dbf_text[15]; |
| 2913 | |
| 2914 | irq_ptr = cdev->private->qdio_data; |
| 2915 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 2916 | sprintf(dbf_text,"qehi%4x",cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2918 | QDIO_DBF_TEXT0(0,trace,dbf_text); |
| 2919 | |
| 2920 | if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) { |
| 2921 | ccw_device_set_timeout(cdev, 0); |
| 2922 | return; |
| 2923 | } |
| 2924 | |
| 2925 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED); |
| 2926 | ccw_device_set_timeout(cdev, 0); |
| 2927 | } |
| 2928 | |
| 2929 | int |
| 2930 | qdio_initialize(struct qdio_initialize *init_data) |
| 2931 | { |
| 2932 | int rc; |
| 2933 | char dbf_text[15]; |
| 2934 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 2935 | sprintf(dbf_text,"qini%4x",init_data->cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2937 | QDIO_DBF_TEXT0(0,trace,dbf_text); |
| 2938 | |
| 2939 | rc = qdio_allocate(init_data); |
| 2940 | if (rc == 0) { |
| 2941 | rc = qdio_establish(init_data); |
| 2942 | if (rc != 0) |
| 2943 | qdio_free(init_data->cdev); |
| 2944 | } |
| 2945 | |
| 2946 | return rc; |
| 2947 | } |
| 2948 | |
| 2949 | |
| 2950 | int |
| 2951 | qdio_allocate(struct qdio_initialize *init_data) |
| 2952 | { |
| 2953 | struct qdio_irq *irq_ptr; |
| 2954 | char dbf_text[15]; |
| 2955 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 2956 | sprintf(dbf_text,"qalc%4x",init_data->cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 2958 | QDIO_DBF_TEXT0(0,trace,dbf_text); |
| 2959 | if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) || |
| 2960 | (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) || |
| 2961 | ((init_data->no_input_qs) && (!init_data->input_handler)) || |
| 2962 | ((init_data->no_output_qs) && (!init_data->output_handler)) ) |
| 2963 | return -EINVAL; |
| 2964 | |
| 2965 | if (!init_data->input_sbal_addr_array) |
| 2966 | return -EINVAL; |
| 2967 | |
| 2968 | if (!init_data->output_sbal_addr_array) |
| 2969 | return -EINVAL; |
| 2970 | |
| 2971 | qdio_allocate_do_dbf(init_data); |
| 2972 | |
| 2973 | /* create irq */ |
Christian Borntraeger | 40ac6b2 | 2006-04-27 18:40:11 -0700 | [diff] [blame] | 2974 | irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
| 2976 | QDIO_DBF_TEXT0(0,setup,"irq_ptr:"); |
| 2977 | QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*)); |
| 2978 | |
| 2979 | if (!irq_ptr) { |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 2980 | QDIO_PRINT_ERR("allocation of irq_ptr failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | return -ENOMEM; |
| 2982 | } |
| 2983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | init_MUTEX(&irq_ptr->setting_up_sema); |
| 2985 | |
| 2986 | /* QDR must be in DMA area since CCW data address is only 32 bit */ |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 2987 | irq_ptr->qdr = (struct qdr *) __get_free_page(GFP_KERNEL | GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | if (!(irq_ptr->qdr)) { |
Christian Borntraeger | 40ac6b2 | 2006-04-27 18:40:11 -0700 | [diff] [blame] | 2989 | free_page((unsigned long) irq_ptr); |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 2990 | QDIO_PRINT_ERR("allocation of irq_ptr->qdr failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | return -ENOMEM; |
| 2992 | } |
| 2993 | QDIO_DBF_TEXT0(0,setup,"qdr:"); |
| 2994 | QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*)); |
| 2995 | |
| 2996 | if (qdio_alloc_qs(irq_ptr, |
| 2997 | init_data->no_input_qs, |
| 2998 | init_data->no_output_qs)) { |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 2999 | QDIO_PRINT_ERR("queue allocation failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | qdio_release_irq_memory(irq_ptr); |
| 3001 | return -ENOMEM; |
| 3002 | } |
| 3003 | |
| 3004 | init_data->cdev->private->qdio_data = irq_ptr; |
| 3005 | |
| 3006 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE); |
| 3007 | |
| 3008 | return 0; |
| 3009 | } |
| 3010 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 3011 | static int qdio_fill_irq(struct qdio_initialize *init_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | { |
| 3013 | int i; |
| 3014 | char dbf_text[15]; |
| 3015 | struct ciw *ciw; |
| 3016 | int is_iqdio; |
| 3017 | struct qdio_irq *irq_ptr; |
| 3018 | |
| 3019 | irq_ptr = init_data->cdev->private->qdio_data; |
| 3020 | |
| 3021 | memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr)); |
| 3022 | |
| 3023 | /* wipes qib.ac, required by ar7063 */ |
| 3024 | memset(irq_ptr->qdr,0,sizeof(struct qdr)); |
| 3025 | |
| 3026 | irq_ptr->int_parm=init_data->int_parm; |
| 3027 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 3028 | irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | irq_ptr->no_input_qs=init_data->no_input_qs; |
| 3030 | irq_ptr->no_output_qs=init_data->no_output_qs; |
| 3031 | |
| 3032 | if (init_data->q_format==QDIO_IQDIO_QFMT) { |
| 3033 | irq_ptr->is_iqdio_irq=1; |
| 3034 | irq_ptr->is_thinint_irq=1; |
| 3035 | } else { |
| 3036 | irq_ptr->is_iqdio_irq=0; |
| 3037 | irq_ptr->is_thinint_irq=hydra_thinints; |
| 3038 | } |
| 3039 | sprintf(dbf_text,"is_i_t%1x%1x", |
| 3040 | irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq); |
| 3041 | QDIO_DBF_TEXT2(0,setup,dbf_text); |
| 3042 | |
| 3043 | if (irq_ptr->is_thinint_irq) { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3044 | irq_ptr->dev_st_chg_ind = qdio_get_indicator(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*)); |
| 3046 | if (!irq_ptr->dev_st_chg_ind) { |
| 3047 | QDIO_PRINT_WARN("no indicator location available " \ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 3048 | "for irq 0.%x.%x\n", |
| 3049 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | qdio_release_irq_memory(irq_ptr); |
| 3051 | return -ENOBUFS; |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | /* defaults */ |
| 3056 | irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD; |
| 3057 | irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT; |
| 3058 | irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD; |
| 3059 | irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT; |
| 3060 | |
| 3061 | qdio_fill_qs(irq_ptr, init_data->cdev, |
| 3062 | init_data->no_input_qs, |
| 3063 | init_data->no_output_qs, |
| 3064 | init_data->input_handler, |
| 3065 | init_data->output_handler,init_data->int_parm, |
| 3066 | init_data->q_format,init_data->flags, |
| 3067 | init_data->input_sbal_addr_array, |
| 3068 | init_data->output_sbal_addr_array); |
| 3069 | |
| 3070 | if (!try_module_get(THIS_MODULE)) { |
| 3071 | QDIO_PRINT_CRIT("try_module_get() failed!\n"); |
| 3072 | qdio_release_irq_memory(irq_ptr); |
| 3073 | return -EINVAL; |
| 3074 | } |
| 3075 | |
| 3076 | qdio_fill_thresholds(irq_ptr,init_data->no_input_qs, |
| 3077 | init_data->no_output_qs, |
| 3078 | init_data->min_input_threshold, |
| 3079 | init_data->max_input_threshold, |
| 3080 | init_data->min_output_threshold, |
| 3081 | init_data->max_output_threshold); |
| 3082 | |
| 3083 | /* fill in qdr */ |
| 3084 | irq_ptr->qdr->qfmt=init_data->q_format; |
| 3085 | irq_ptr->qdr->iqdcnt=init_data->no_input_qs; |
| 3086 | irq_ptr->qdr->oqdcnt=init_data->no_output_qs; |
| 3087 | irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */ |
| 3088 | irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4; |
| 3089 | |
| 3090 | irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib; |
| 3091 | irq_ptr->qdr->qkey=QDIO_STORAGE_KEY; |
| 3092 | |
| 3093 | /* fill in qib */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3094 | irq_ptr->is_qebsm = is_passthrough; |
| 3095 | if (irq_ptr->is_qebsm) |
| 3096 | irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM; |
| 3097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | irq_ptr->qib.qfmt=init_data->q_format; |
| 3099 | if (init_data->no_input_qs) |
| 3100 | irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib); |
| 3101 | if (init_data->no_output_qs) |
| 3102 | irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib); |
| 3103 | memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8); |
| 3104 | |
| 3105 | qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format, |
| 3106 | init_data->qib_param_field, |
| 3107 | init_data->no_input_qs, |
| 3108 | init_data->no_output_qs, |
| 3109 | init_data->input_slib_elements, |
| 3110 | init_data->output_slib_elements); |
| 3111 | |
| 3112 | /* first input descriptors, then output descriptors */ |
| 3113 | is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0; |
| 3114 | for (i=0;i<init_data->no_input_qs;i++) |
| 3115 | qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio); |
| 3116 | |
| 3117 | for (i=0;i<init_data->no_output_qs;i++) |
| 3118 | qdio_allocate_fill_output_desc(irq_ptr, i, |
| 3119 | init_data->no_input_qs, |
| 3120 | is_iqdio); |
| 3121 | |
| 3122 | /* qdr, qib, sls, slsbs, slibs, sbales filled. */ |
| 3123 | |
| 3124 | /* get qdio commands */ |
| 3125 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE); |
| 3126 | if (!ciw) { |
| 3127 | QDIO_DBF_TEXT2(1,setup,"no eq"); |
| 3128 | QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. " |
| 3129 | "Trying to use default.\n"); |
| 3130 | } else |
| 3131 | irq_ptr->equeue = *ciw; |
| 3132 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE); |
| 3133 | if (!ciw) { |
| 3134 | QDIO_DBF_TEXT2(1,setup,"no aq"); |
| 3135 | QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. " |
| 3136 | "Trying to use default.\n"); |
| 3137 | } else |
| 3138 | irq_ptr->aqueue = *ciw; |
| 3139 | |
| 3140 | /* Set new interrupt handler. */ |
| 3141 | irq_ptr->original_int_handler = init_data->cdev->handler; |
| 3142 | init_data->cdev->handler = qdio_handler; |
| 3143 | |
| 3144 | return 0; |
| 3145 | } |
| 3146 | |
| 3147 | int |
| 3148 | qdio_establish(struct qdio_initialize *init_data) |
| 3149 | { |
| 3150 | struct qdio_irq *irq_ptr; |
| 3151 | unsigned long saveflags; |
| 3152 | int result, result2; |
| 3153 | struct ccw_device *cdev; |
| 3154 | char dbf_text[20]; |
| 3155 | |
| 3156 | cdev=init_data->cdev; |
| 3157 | irq_ptr = cdev->private->qdio_data; |
| 3158 | if (!irq_ptr) |
| 3159 | return -EINVAL; |
| 3160 | |
| 3161 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 3162 | return -EINVAL; |
| 3163 | |
| 3164 | down(&irq_ptr->setting_up_sema); |
| 3165 | |
| 3166 | qdio_fill_irq(init_data); |
| 3167 | |
| 3168 | /* the thinint CHSC stuff */ |
| 3169 | if (irq_ptr->is_thinint_irq) { |
| 3170 | |
| 3171 | result = tiqdio_set_subchannel_ind(irq_ptr,0); |
| 3172 | if (result) { |
| 3173 | up(&irq_ptr->setting_up_sema); |
| 3174 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
| 3175 | return result; |
| 3176 | } |
| 3177 | tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET); |
| 3178 | } |
| 3179 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 3180 | sprintf(dbf_text,"qest%4x",cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 3182 | QDIO_DBF_TEXT0(0,trace,dbf_text); |
| 3183 | |
| 3184 | /* establish q */ |
| 3185 | irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd; |
| 3186 | irq_ptr->ccw.flags=CCW_FLAG_SLI; |
| 3187 | irq_ptr->ccw.count=irq_ptr->equeue.count; |
| 3188 | irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr); |
| 3189 | |
| 3190 | spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags); |
| 3191 | |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 3192 | ccw_device_set_options_mask(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | result=ccw_device_start_timeout(cdev,&irq_ptr->ccw, |
| 3194 | QDIO_DOING_ESTABLISH,0, 0, |
| 3195 | QDIO_ESTABLISH_TIMEOUT); |
| 3196 | if (result) { |
| 3197 | result2=ccw_device_start_timeout(cdev,&irq_ptr->ccw, |
| 3198 | QDIO_DOING_ESTABLISH,0,0, |
| 3199 | QDIO_ESTABLISH_TIMEOUT); |
| 3200 | sprintf(dbf_text,"eq:io%4x",result); |
| 3201 | QDIO_DBF_TEXT2(1,setup,dbf_text); |
| 3202 | if (result2) { |
| 3203 | sprintf(dbf_text,"eq:io%4x",result); |
| 3204 | QDIO_DBF_TEXT2(1,setup,dbf_text); |
| 3205 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 3206 | QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \ |
| 3207 | "returned %i, next try returned %i\n", |
| 3208 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, |
| 3209 | result, result2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | result=result2; |
| 3211 | if (result) |
| 3212 | ccw_device_set_timeout(cdev, 0); |
| 3213 | } |
| 3214 | |
| 3215 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags); |
| 3216 | |
| 3217 | if (result) { |
| 3218 | up(&irq_ptr->setting_up_sema); |
| 3219 | qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR); |
| 3220 | return result; |
| 3221 | } |
| 3222 | |
Ursula Braun-Krahl | cdb32dc | 2005-11-07 00:59:10 -0800 | [diff] [blame] | 3223 | /* Timeout is cared for already by using ccw_device_start_timeout(). */ |
| 3224 | wait_event_interruptible(cdev->private->wait_q, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || |
Ursula Braun-Krahl | cdb32dc | 2005-11-07 00:59:10 -0800 | [diff] [blame] | 3226 | irq_ptr->state == QDIO_IRQ_STATE_ERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | |
| 3228 | if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED) |
| 3229 | result = 0; |
| 3230 | else { |
| 3231 | up(&irq_ptr->setting_up_sema); |
| 3232 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
| 3233 | return -EIO; |
| 3234 | } |
| 3235 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3236 | qdio_get_ssqd_information(irq_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | /* if this gets set once, we're running under VM and can omit SVSes */ |
| 3238 | if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY) |
| 3239 | omit_svs=1; |
| 3240 | |
| 3241 | sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac); |
| 3242 | QDIO_DBF_TEXT2(0,setup,dbf_text); |
| 3243 | |
| 3244 | sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac); |
| 3245 | QDIO_DBF_TEXT2(0,setup,dbf_text); |
| 3246 | |
| 3247 | irq_ptr->hydra_gives_outbound_pcis= |
| 3248 | irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED; |
| 3249 | irq_ptr->sync_done_on_outb_pcis= |
| 3250 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS; |
| 3251 | |
| 3252 | qdio_initialize_set_siga_flags_input(irq_ptr); |
| 3253 | qdio_initialize_set_siga_flags_output(irq_ptr); |
| 3254 | |
| 3255 | up(&irq_ptr->setting_up_sema); |
| 3256 | |
| 3257 | return result; |
| 3258 | |
| 3259 | } |
| 3260 | |
| 3261 | int |
| 3262 | qdio_activate(struct ccw_device *cdev, int flags) |
| 3263 | { |
| 3264 | struct qdio_irq *irq_ptr; |
| 3265 | int i,result=0,result2; |
| 3266 | unsigned long saveflags; |
| 3267 | char dbf_text[20]; /* see qdio_initialize */ |
| 3268 | |
| 3269 | irq_ptr = cdev->private->qdio_data; |
| 3270 | if (!irq_ptr) |
| 3271 | return -ENODEV; |
| 3272 | |
| 3273 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 3274 | return -EINVAL; |
| 3275 | |
| 3276 | down(&irq_ptr->setting_up_sema); |
| 3277 | if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) { |
| 3278 | result=-EBUSY; |
| 3279 | goto out; |
| 3280 | } |
| 3281 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 3282 | sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | QDIO_DBF_TEXT2(0,setup,dbf_text); |
| 3284 | QDIO_DBF_TEXT2(0,trace,dbf_text); |
| 3285 | |
| 3286 | /* activate q */ |
| 3287 | irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd; |
| 3288 | irq_ptr->ccw.flags=CCW_FLAG_SLI; |
| 3289 | irq_ptr->ccw.count=irq_ptr->aqueue.count; |
| 3290 | irq_ptr->ccw.cda=QDIO_GET_ADDR(0); |
| 3291 | |
| 3292 | spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags); |
| 3293 | |
| 3294 | ccw_device_set_timeout(cdev, 0); |
| 3295 | ccw_device_set_options(cdev, CCWDEV_REPORT_ALL); |
| 3296 | result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE, |
| 3297 | 0, DOIO_DENY_PREFETCH); |
| 3298 | if (result) { |
| 3299 | result2=ccw_device_start(cdev,&irq_ptr->ccw, |
| 3300 | QDIO_DOING_ACTIVATE,0,0); |
| 3301 | sprintf(dbf_text,"aq:io%4x",result); |
| 3302 | QDIO_DBF_TEXT2(1,setup,dbf_text); |
| 3303 | if (result2) { |
| 3304 | sprintf(dbf_text,"aq:io%4x",result); |
| 3305 | QDIO_DBF_TEXT2(1,setup,dbf_text); |
| 3306 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 3307 | QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \ |
| 3308 | "returned %i, next try returned %i\n", |
| 3309 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, |
| 3310 | result, result2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | result=result2; |
| 3312 | } |
| 3313 | |
| 3314 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags); |
| 3315 | if (result) |
| 3316 | goto out; |
| 3317 | |
| 3318 | for (i=0;i<irq_ptr->no_input_qs;i++) { |
| 3319 | if (irq_ptr->is_thinint_irq) { |
| 3320 | /* |
| 3321 | * that way we know, that, if we will get interrupted |
| 3322 | * by tiqdio_inbound_processing, qdio_unmark_q will |
| 3323 | * not be called |
| 3324 | */ |
| 3325 | qdio_reserve_q(irq_ptr->input_qs[i]); |
| 3326 | qdio_mark_tiq(irq_ptr->input_qs[i]); |
| 3327 | qdio_release_q(irq_ptr->input_qs[i]); |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) { |
| 3332 | for (i=0;i<irq_ptr->no_input_qs;i++) { |
| 3333 | irq_ptr->input_qs[i]->is_input_q|= |
| 3334 | QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | wait_event_interruptible_timeout(cdev->private->wait_q, |
| 3339 | ((irq_ptr->state == |
| 3340 | QDIO_IRQ_STATE_STOPPED) || |
| 3341 | (irq_ptr->state == |
| 3342 | QDIO_IRQ_STATE_ERR)), |
| 3343 | QDIO_ACTIVATE_TIMEOUT); |
| 3344 | |
| 3345 | switch (irq_ptr->state) { |
| 3346 | case QDIO_IRQ_STATE_STOPPED: |
| 3347 | case QDIO_IRQ_STATE_ERR: |
| 3348 | up(&irq_ptr->setting_up_sema); |
| 3349 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
| 3350 | down(&irq_ptr->setting_up_sema); |
| 3351 | result = -EIO; |
| 3352 | break; |
| 3353 | default: |
| 3354 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE); |
| 3355 | result = 0; |
| 3356 | } |
| 3357 | out: |
| 3358 | up(&irq_ptr->setting_up_sema); |
| 3359 | |
| 3360 | return result; |
| 3361 | } |
| 3362 | |
| 3363 | /* buffers filled forwards again to make Rick happy */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 3364 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx, |
| 3366 | unsigned int count, struct qdio_buffer *buffers) |
| 3367 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3368 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
Ursula Braun | dcc49d4 | 2007-03-19 13:18:12 +0100 | [diff] [blame] | 3369 | int tmp = 0; |
| 3370 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3371 | qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1); |
| 3372 | if (irq->is_qebsm) { |
Ursula Braun | dcc49d4 | 2007-03-19 13:18:12 +0100 | [diff] [blame] | 3373 | while (count) { |
| 3374 | tmp = set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count); |
| 3375 | if (!tmp) |
| 3376 | return; |
| 3377 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3378 | return; |
| 3379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | for (;;) { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3381 | set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | count--; |
| 3383 | if (!count) break; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3384 | qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 3388 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx, |
| 3390 | unsigned int count, struct qdio_buffer *buffers) |
| 3391 | { |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3392 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
Ursula Braun | dcc49d4 | 2007-03-19 13:18:12 +0100 | [diff] [blame] | 3393 | int tmp = 0; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3394 | |
| 3395 | qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1); |
| 3396 | if (irq->is_qebsm) { |
Ursula Braun | dcc49d4 | 2007-03-19 13:18:12 +0100 | [diff] [blame] | 3397 | while (count) { |
| 3398 | tmp = set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count); |
| 3399 | if (!tmp) |
| 3400 | return; |
| 3401 | } |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3402 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3405 | for (;;) { |
| 3406 | set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count); |
| 3407 | count--; |
| 3408 | if (!count) break; |
| 3409 | qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1); |
| 3410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | } |
| 3412 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 3413 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags, |
| 3415 | unsigned int qidx, unsigned int count, |
| 3416 | struct qdio_buffer *buffers) |
| 3417 | { |
| 3418 | int used_elements; |
| 3419 | |
| 3420 | /* This is the inbound handling of queues */ |
| 3421 | used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; |
| 3422 | |
| 3423 | qdio_do_qdio_fill_input(q,qidx,count,buffers); |
| 3424 | |
| 3425 | if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&& |
| 3426 | (callflags&QDIO_FLAG_UNDER_INTERRUPT)) |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 3427 | atomic_xchg(&q->polling,0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
| 3429 | if (used_elements) |
| 3430 | return; |
| 3431 | if (callflags&QDIO_FLAG_DONT_SIGA) |
| 3432 | return; |
| 3433 | if (q->siga_in) { |
| 3434 | int result; |
| 3435 | |
| 3436 | result=qdio_siga_input(q); |
| 3437 | if (result) { |
| 3438 | if (q->siga_error) |
| 3439 | q->error_status_flags|= |
| 3440 | QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR; |
| 3441 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; |
| 3442 | q->siga_error=result; |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | qdio_mark_q(q); |
| 3447 | } |
| 3448 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 3449 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags, |
| 3451 | unsigned int qidx, unsigned int count, |
| 3452 | struct qdio_buffer *buffers) |
| 3453 | { |
| 3454 | int used_elements; |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3455 | unsigned int cnt, start_buf; |
| 3456 | unsigned char state = 0; |
| 3457 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
| 3459 | /* This is the outbound handling of queues */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | qdio_do_qdio_fill_output(q,qidx,count,buffers); |
| 3461 | |
| 3462 | used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; |
| 3463 | |
| 3464 | if (callflags&QDIO_FLAG_DONT_SIGA) { |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3465 | qdio_perf_stat_inc(&perf_stats.outbound_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | return; |
| 3467 | } |
Ursula Braun | 1f8bdae | 2007-05-02 15:18:07 +0200 | [diff] [blame] | 3468 | if (callflags & QDIO_FLAG_PCI_OUT) |
| 3469 | q->is_pci_out = 1; |
| 3470 | else |
| 3471 | q->is_pci_out = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | if (q->is_iqdio_q) { |
| 3473 | /* one siga for every sbal */ |
| 3474 | while (count--) |
| 3475 | qdio_kick_outbound_q(q); |
| 3476 | |
| 3477 | __qdio_outbound_processing(q); |
| 3478 | } else { |
| 3479 | /* under VM, we do a SIGA sync unconditionally */ |
| 3480 | SYNC_MEMORY; |
| 3481 | else { |
| 3482 | /* |
| 3483 | * w/o shadow queues (else branch of |
| 3484 | * SYNC_MEMORY :-/ ), we try to |
| 3485 | * fast-requeue buffers |
| 3486 | */ |
Frank Pavlic | 8129ee1 | 2006-01-06 00:19:20 -0800 | [diff] [blame] | 3487 | if (irq->is_qebsm) { |
| 3488 | cnt = 1; |
| 3489 | start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) & |
| 3490 | (QDIO_MAX_BUFFERS_PER_Q-1)); |
| 3491 | qdio_do_eqbs(q, &state, &start_buf, &cnt); |
| 3492 | } else |
| 3493 | state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1) |
| 3494 | &(QDIO_MAX_BUFFERS_PER_Q-1) ]; |
| 3495 | if (state != SLSB_CU_OUTPUT_PRIMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | qdio_kick_outbound_q(q); |
| 3497 | } else { |
| 3498 | QDIO_DBF_TEXT3(0,trace, "fast-req"); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3499 | qdio_perf_stat_inc(&perf_stats.fast_reqs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | /* |
| 3503 | * only marking the q could take too long, |
| 3504 | * the upper layer module could do a lot of |
| 3505 | * traffic in that time |
| 3506 | */ |
| 3507 | __qdio_outbound_processing(q); |
| 3508 | } |
| 3509 | |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3510 | qdio_perf_stat_inc(&perf_stats.outbound_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | /* count must be 1 in iqdio */ |
| 3514 | int |
| 3515 | do_QDIO(struct ccw_device *cdev,unsigned int callflags, |
| 3516 | unsigned int queue_number, unsigned int qidx, |
| 3517 | unsigned int count,struct qdio_buffer *buffers) |
| 3518 | { |
| 3519 | struct qdio_irq *irq_ptr; |
| 3520 | #ifdef CONFIG_QDIO_DEBUG |
| 3521 | char dbf_text[20]; |
| 3522 | |
Cornelia Huck | 85a4aa6 | 2006-10-18 18:30:47 +0200 | [diff] [blame] | 3523 | sprintf(dbf_text,"doQD%04x",cdev->private->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | QDIO_DBF_TEXT3(0,trace,dbf_text); |
| 3525 | #endif /* CONFIG_QDIO_DEBUG */ |
| 3526 | |
| 3527 | if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) || |
| 3528 | (count>QDIO_MAX_BUFFERS_PER_Q) || |
| 3529 | (queue_number>QDIO_MAX_QUEUES_PER_IRQ) ) |
| 3530 | return -EINVAL; |
| 3531 | |
| 3532 | if (count==0) |
| 3533 | return 0; |
| 3534 | |
| 3535 | irq_ptr = cdev->private->qdio_data; |
| 3536 | if (!irq_ptr) |
| 3537 | return -ENODEV; |
| 3538 | |
| 3539 | #ifdef CONFIG_QDIO_DEBUG |
| 3540 | if (callflags&QDIO_FLAG_SYNC_INPUT) |
| 3541 | QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number], |
| 3542 | sizeof(void*)); |
| 3543 | else |
| 3544 | QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number], |
| 3545 | sizeof(void*)); |
| 3546 | sprintf(dbf_text,"flag%04x",callflags); |
| 3547 | QDIO_DBF_TEXT3(0,trace,dbf_text); |
| 3548 | sprintf(dbf_text,"qi%02xct%02x",qidx,count); |
| 3549 | QDIO_DBF_TEXT3(0,trace,dbf_text); |
| 3550 | #endif /* CONFIG_QDIO_DEBUG */ |
| 3551 | |
| 3552 | if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE) |
| 3553 | return -EBUSY; |
| 3554 | |
| 3555 | if (callflags&QDIO_FLAG_SYNC_INPUT) |
| 3556 | do_qdio_handle_inbound(irq_ptr->input_qs[queue_number], |
| 3557 | callflags, qidx, count, buffers); |
| 3558 | else if (callflags&QDIO_FLAG_SYNC_OUTPUT) |
| 3559 | do_qdio_handle_outbound(irq_ptr->output_qs[queue_number], |
| 3560 | callflags, qidx, count, buffers); |
| 3561 | else { |
| 3562 | QDIO_DBF_TEXT3(1,trace,"doQD:inv"); |
| 3563 | return -EINVAL; |
| 3564 | } |
| 3565 | return 0; |
| 3566 | } |
| 3567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | static int |
| 3569 | qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset, |
| 3570 | int buffer_length, int *eof, void *data) |
| 3571 | { |
| 3572 | int c=0; |
| 3573 | |
| 3574 | /* we are always called with buffer_length=4k, so we all |
| 3575 | deliver on the first read */ |
| 3576 | if (offset>0) |
| 3577 | return 0; |
| 3578 | |
| 3579 | #define _OUTP_IT(x...) c+=sprintf(buffer+c,x) |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3580 | #ifdef CONFIG_64BIT |
| 3581 | _OUTP_IT("Number of tasklet runs (total) : %li\n", |
| 3582 | (long)atomic64_read(&perf_stats.tl_runs)); |
| 3583 | _OUTP_IT("Inbound tasklet runs tried/retried : %li/%li\n", |
| 3584 | (long)atomic64_read(&perf_stats.inbound_tl_runs), |
| 3585 | (long)atomic64_read(&perf_stats.inbound_tl_runs_resched)); |
| 3586 | _OUTP_IT("Inbound-thin tasklet runs tried/retried : %li/%li\n", |
| 3587 | (long)atomic64_read(&perf_stats.inbound_thin_tl_runs), |
| 3588 | (long)atomic64_read(&perf_stats.inbound_thin_tl_runs_resched)); |
| 3589 | _OUTP_IT("Outbound tasklet runs tried/retried : %li/%li\n", |
| 3590 | (long)atomic64_read(&perf_stats.outbound_tl_runs), |
| 3591 | (long)atomic64_read(&perf_stats.outbound_tl_runs_resched)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | _OUTP_IT("\n"); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3593 | _OUTP_IT("Number of SIGA sync's issued : %li\n", |
| 3594 | (long)atomic64_read(&perf_stats.siga_syncs)); |
| 3595 | _OUTP_IT("Number of SIGA in's issued : %li\n", |
| 3596 | (long)atomic64_read(&perf_stats.siga_ins)); |
| 3597 | _OUTP_IT("Number of SIGA out's issued : %li\n", |
| 3598 | (long)atomic64_read(&perf_stats.siga_outs)); |
| 3599 | _OUTP_IT("Number of PCIs caught : %li\n", |
| 3600 | (long)atomic64_read(&perf_stats.pcis)); |
| 3601 | _OUTP_IT("Number of adapter interrupts caught : %li\n", |
| 3602 | (long)atomic64_read(&perf_stats.thinints)); |
| 3603 | _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %li\n", |
| 3604 | (long)atomic64_read(&perf_stats.fast_reqs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | _OUTP_IT("\n"); |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3606 | _OUTP_IT("Number of inbound transfers : %li\n", |
| 3607 | (long)atomic64_read(&perf_stats.inbound_cnt)); |
| 3608 | _OUTP_IT("Number of do_QDIOs outbound : %li\n", |
| 3609 | (long)atomic64_read(&perf_stats.outbound_cnt)); |
| 3610 | #else /* CONFIG_64BIT */ |
| 3611 | _OUTP_IT("Number of tasklet runs (total) : %i\n", |
| 3612 | atomic_read(&perf_stats.tl_runs)); |
| 3613 | _OUTP_IT("Inbound tasklet runs tried/retried : %i/%i\n", |
| 3614 | atomic_read(&perf_stats.inbound_tl_runs), |
| 3615 | atomic_read(&perf_stats.inbound_tl_runs_resched)); |
| 3616 | _OUTP_IT("Inbound-thin tasklet runs tried/retried : %i/%i\n", |
| 3617 | atomic_read(&perf_stats.inbound_thin_tl_runs), |
| 3618 | atomic_read(&perf_stats.inbound_thin_tl_runs_resched)); |
| 3619 | _OUTP_IT("Outbound tasklet runs tried/retried : %i/%i\n", |
| 3620 | atomic_read(&perf_stats.outbound_tl_runs), |
| 3621 | atomic_read(&perf_stats.outbound_tl_runs_resched)); |
| 3622 | _OUTP_IT("\n"); |
| 3623 | _OUTP_IT("Number of SIGA sync's issued : %i\n", |
| 3624 | atomic_read(&perf_stats.siga_syncs)); |
| 3625 | _OUTP_IT("Number of SIGA in's issued : %i\n", |
| 3626 | atomic_read(&perf_stats.siga_ins)); |
| 3627 | _OUTP_IT("Number of SIGA out's issued : %i\n", |
| 3628 | atomic_read(&perf_stats.siga_outs)); |
| 3629 | _OUTP_IT("Number of PCIs caught : %i\n", |
| 3630 | atomic_read(&perf_stats.pcis)); |
| 3631 | _OUTP_IT("Number of adapter interrupts caught : %i\n", |
| 3632 | atomic_read(&perf_stats.thinints)); |
| 3633 | _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %i\n", |
| 3634 | atomic_read(&perf_stats.fast_reqs)); |
| 3635 | _OUTP_IT("\n"); |
| 3636 | _OUTP_IT("Number of inbound transfers : %i\n", |
| 3637 | atomic_read(&perf_stats.inbound_cnt)); |
| 3638 | _OUTP_IT("Number of do_QDIOs outbound : %i\n", |
| 3639 | atomic_read(&perf_stats.outbound_cnt)); |
| 3640 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | _OUTP_IT("\n"); |
| 3642 | |
| 3643 | return c; |
| 3644 | } |
| 3645 | |
| 3646 | static struct proc_dir_entry *qdio_perf_proc_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | |
| 3648 | static void |
| 3649 | qdio_add_procfs_entry(void) |
| 3650 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | proc_perf_file_registration=0; |
| 3652 | qdio_perf_proc_file=create_proc_entry(QDIO_PERF, |
| 3653 | S_IFREG|0444,&proc_root); |
| 3654 | if (qdio_perf_proc_file) { |
| 3655 | qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read; |
| 3656 | } else proc_perf_file_registration=-1; |
| 3657 | |
| 3658 | if (proc_perf_file_registration) |
| 3659 | QDIO_PRINT_WARN("was not able to register perf. " \ |
| 3660 | "proc-file (%i).\n", |
| 3661 | proc_perf_file_registration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | static void |
| 3665 | qdio_remove_procfs_entry(void) |
| 3666 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | if (!proc_perf_file_registration) /* means if it went ok earlier */ |
| 3668 | remove_proc_entry(QDIO_PERF,&proc_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3671 | /** |
| 3672 | * attributes in sysfs |
| 3673 | *****************************************************************************/ |
| 3674 | |
| 3675 | static ssize_t |
| 3676 | qdio_performance_stats_show(struct bus_type *bus, char *buf) |
| 3677 | { |
| 3678 | return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0); |
| 3679 | } |
| 3680 | |
| 3681 | static ssize_t |
| 3682 | qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count) |
| 3683 | { |
| 3684 | char *tmp; |
| 3685 | int i; |
| 3686 | |
| 3687 | i = simple_strtoul(buf, &tmp, 16); |
| 3688 | if ((i == 0) || (i == 1)) { |
| 3689 | if (i == qdio_performance_stats) |
| 3690 | return count; |
| 3691 | qdio_performance_stats = i; |
| 3692 | if (i==0) { |
| 3693 | /* reset perf. stat. info */ |
Ursula Braun | 00c0c64 | 2007-05-04 18:47:49 +0200 | [diff] [blame] | 3694 | #ifdef CONFIG_64BIT |
| 3695 | atomic64_set(&perf_stats.tl_runs, 0); |
| 3696 | atomic64_set(&perf_stats.outbound_tl_runs, 0); |
| 3697 | atomic64_set(&perf_stats.inbound_tl_runs, 0); |
| 3698 | atomic64_set(&perf_stats.inbound_tl_runs_resched, 0); |
| 3699 | atomic64_set(&perf_stats.inbound_thin_tl_runs, 0); |
| 3700 | atomic64_set(&perf_stats.inbound_thin_tl_runs_resched, |
| 3701 | 0); |
| 3702 | atomic64_set(&perf_stats.siga_outs, 0); |
| 3703 | atomic64_set(&perf_stats.siga_ins, 0); |
| 3704 | atomic64_set(&perf_stats.siga_syncs, 0); |
| 3705 | atomic64_set(&perf_stats.pcis, 0); |
| 3706 | atomic64_set(&perf_stats.thinints, 0); |
| 3707 | atomic64_set(&perf_stats.fast_reqs, 0); |
| 3708 | atomic64_set(&perf_stats.outbound_cnt, 0); |
| 3709 | atomic64_set(&perf_stats.inbound_cnt, 0); |
| 3710 | #else /* CONFIG_64BIT */ |
| 3711 | atomic_set(&perf_stats.tl_runs, 0); |
| 3712 | atomic_set(&perf_stats.outbound_tl_runs, 0); |
| 3713 | atomic_set(&perf_stats.inbound_tl_runs, 0); |
| 3714 | atomic_set(&perf_stats.inbound_tl_runs_resched, 0); |
| 3715 | atomic_set(&perf_stats.inbound_thin_tl_runs, 0); |
| 3716 | atomic_set(&perf_stats.inbound_thin_tl_runs_resched, 0); |
| 3717 | atomic_set(&perf_stats.siga_outs, 0); |
| 3718 | atomic_set(&perf_stats.siga_ins, 0); |
| 3719 | atomic_set(&perf_stats.siga_syncs, 0); |
| 3720 | atomic_set(&perf_stats.pcis, 0); |
| 3721 | atomic_set(&perf_stats.thinints, 0); |
| 3722 | atomic_set(&perf_stats.fast_reqs, 0); |
| 3723 | atomic_set(&perf_stats.outbound_cnt, 0); |
| 3724 | atomic_set(&perf_stats.inbound_cnt, 0); |
| 3725 | #endif /* CONFIG_64BIT */ |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3726 | } |
| 3727 | } else { |
| 3728 | QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n"); |
| 3729 | return -EINVAL; |
| 3730 | } |
| 3731 | return count; |
| 3732 | } |
| 3733 | |
| 3734 | static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show, |
| 3735 | qdio_performance_stats_store); |
| 3736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | static void |
| 3738 | tiqdio_register_thinints(void) |
| 3739 | { |
| 3740 | char dbf_text[20]; |
| 3741 | register_thinint_result= |
| 3742 | s390_register_adapter_interrupt(&tiqdio_thinint_handler); |
| 3743 | if (register_thinint_result) { |
| 3744 | sprintf(dbf_text,"regthn%x",(register_thinint_result&0xff)); |
| 3745 | QDIO_DBF_TEXT0(0,setup,dbf_text); |
| 3746 | QDIO_PRINT_ERR("failed to register adapter handler " \ |
| 3747 | "(rc=%i).\nAdapter interrupts might " \ |
| 3748 | "not work. Continuing.\n", |
| 3749 | register_thinint_result); |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | static void |
| 3754 | tiqdio_unregister_thinints(void) |
| 3755 | { |
| 3756 | if (!register_thinint_result) |
| 3757 | s390_unregister_adapter_interrupt(&tiqdio_thinint_handler); |
| 3758 | } |
| 3759 | |
| 3760 | static int |
| 3761 | qdio_get_qdio_memory(void) |
| 3762 | { |
| 3763 | int i; |
| 3764 | indicator_used[0]=1; |
| 3765 | |
| 3766 | for (i=1;i<INDICATORS_PER_CACHELINE;i++) |
| 3767 | indicator_used[i]=0; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 3768 | indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | GFP_KERNEL); |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 3770 | if (!indicators) |
| 3771 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | return 0; |
| 3773 | } |
| 3774 | |
| 3775 | static void |
| 3776 | qdio_release_qdio_memory(void) |
| 3777 | { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 3778 | kfree(indicators); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | static void |
| 3783 | qdio_unregister_dbf_views(void) |
| 3784 | { |
| 3785 | if (qdio_dbf_setup) |
| 3786 | debug_unregister(qdio_dbf_setup); |
| 3787 | if (qdio_dbf_sbal) |
| 3788 | debug_unregister(qdio_dbf_sbal); |
| 3789 | if (qdio_dbf_sense) |
| 3790 | debug_unregister(qdio_dbf_sense); |
| 3791 | if (qdio_dbf_trace) |
| 3792 | debug_unregister(qdio_dbf_trace); |
| 3793 | #ifdef CONFIG_QDIO_DEBUG |
| 3794 | if (qdio_dbf_slsb_out) |
| 3795 | debug_unregister(qdio_dbf_slsb_out); |
| 3796 | if (qdio_dbf_slsb_in) |
| 3797 | debug_unregister(qdio_dbf_slsb_in); |
| 3798 | #endif /* CONFIG_QDIO_DEBUG */ |
| 3799 | } |
| 3800 | |
| 3801 | static int |
| 3802 | qdio_register_dbf_views(void) |
| 3803 | { |
| 3804 | qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3805 | QDIO_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | QDIO_DBF_SETUP_NR_AREAS, |
| 3807 | QDIO_DBF_SETUP_LEN); |
| 3808 | if (!qdio_dbf_setup) |
| 3809 | goto oom; |
| 3810 | debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view); |
| 3811 | debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL); |
| 3812 | |
| 3813 | qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3814 | QDIO_DBF_SBAL_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | QDIO_DBF_SBAL_NR_AREAS, |
| 3816 | QDIO_DBF_SBAL_LEN); |
| 3817 | if (!qdio_dbf_sbal) |
| 3818 | goto oom; |
| 3819 | |
| 3820 | debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view); |
| 3821 | debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL); |
| 3822 | |
| 3823 | qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3824 | QDIO_DBF_SENSE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | QDIO_DBF_SENSE_NR_AREAS, |
| 3826 | QDIO_DBF_SENSE_LEN); |
| 3827 | if (!qdio_dbf_sense) |
| 3828 | goto oom; |
| 3829 | |
| 3830 | debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view); |
| 3831 | debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL); |
| 3832 | |
| 3833 | qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3834 | QDIO_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | QDIO_DBF_TRACE_NR_AREAS, |
| 3836 | QDIO_DBF_TRACE_LEN); |
| 3837 | if (!qdio_dbf_trace) |
| 3838 | goto oom; |
| 3839 | |
| 3840 | debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view); |
| 3841 | debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL); |
| 3842 | |
| 3843 | #ifdef CONFIG_QDIO_DEBUG |
| 3844 | qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3845 | QDIO_DBF_SLSB_OUT_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | QDIO_DBF_SLSB_OUT_NR_AREAS, |
| 3847 | QDIO_DBF_SLSB_OUT_LEN); |
| 3848 | if (!qdio_dbf_slsb_out) |
| 3849 | goto oom; |
| 3850 | debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view); |
| 3851 | debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL); |
| 3852 | |
| 3853 | qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 3854 | QDIO_DBF_SLSB_IN_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | QDIO_DBF_SLSB_IN_NR_AREAS, |
| 3856 | QDIO_DBF_SLSB_IN_LEN); |
| 3857 | if (!qdio_dbf_slsb_in) |
| 3858 | goto oom; |
| 3859 | debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view); |
| 3860 | debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL); |
| 3861 | #endif /* CONFIG_QDIO_DEBUG */ |
| 3862 | return 0; |
| 3863 | oom: |
| 3864 | QDIO_PRINT_ERR("not enough memory for dbf.\n"); |
| 3865 | qdio_unregister_dbf_views(); |
| 3866 | return -ENOMEM; |
| 3867 | } |
| 3868 | |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 3869 | static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size) |
| 3870 | { |
| 3871 | return (void *) get_zeroed_page(gfp_mask|GFP_DMA); |
| 3872 | } |
| 3873 | |
| 3874 | static void qdio_mempool_free(void *element, void *size) |
| 3875 | { |
| 3876 | free_page((unsigned long) element); |
| 3877 | } |
| 3878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | static int __init |
| 3880 | init_QDIO(void) |
| 3881 | { |
| 3882 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | void *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
| 3885 | printk("qdio: loading %s\n",version); |
| 3886 | |
| 3887 | res=qdio_get_qdio_memory(); |
| 3888 | if (res) |
| 3889 | return res; |
| 3890 | |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 3891 | qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q), |
| 3892 | 256, 0, NULL); |
| 3893 | if (!qdio_q_cache) { |
| 3894 | qdio_release_qdio_memory(); |
| 3895 | return -ENOMEM; |
| 3896 | } |
| 3897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | res = qdio_register_dbf_views(); |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 3899 | if (res) { |
| 3900 | kmem_cache_destroy(qdio_q_cache); |
| 3901 | qdio_release_qdio_memory(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | return res; |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 3903 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | |
| 3905 | QDIO_DBF_TEXT0(0,setup,"initQDIO"); |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3906 | res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3908 | memset((void*)&perf_stats,0,sizeof(perf_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | QDIO_DBF_TEXT0(0,setup,"perfstat"); |
| 3910 | ptr=&perf_stats; |
| 3911 | QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | |
| 3913 | qdio_add_procfs_entry(); |
| 3914 | |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 3915 | qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS, |
| 3916 | qdio_mempool_alloc, |
| 3917 | qdio_mempool_free, NULL); |
| 3918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | if (tiqdio_check_chsc_availability()) |
| 3920 | QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n"); |
| 3921 | |
| 3922 | tiqdio_register_thinints(); |
| 3923 | |
| 3924 | return 0; |
| 3925 | } |
| 3926 | |
| 3927 | static void __exit |
| 3928 | cleanup_QDIO(void) |
| 3929 | { |
| 3930 | tiqdio_unregister_thinints(); |
| 3931 | qdio_remove_procfs_entry(); |
| 3932 | qdio_release_qdio_memory(); |
| 3933 | qdio_unregister_dbf_views(); |
Andreas Herrmann | a3ae39c | 2006-04-27 18:40:09 -0700 | [diff] [blame] | 3934 | mempool_destroy(qdio_mempool_scssc); |
Heiko Carstens | c6d0e80 | 2007-08-10 14:32:28 +0200 | [diff] [blame] | 3935 | kmem_cache_destroy(qdio_q_cache); |
Ursula Braun | 34249d0 | 2006-12-08 15:54:18 +0100 | [diff] [blame] | 3936 | bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | printk("qdio: %s: module removed\n",version); |
| 3938 | } |
| 3939 | |
| 3940 | module_init(init_QDIO); |
| 3941 | module_exit(cleanup_QDIO); |
| 3942 | |
| 3943 | EXPORT_SYMBOL(qdio_allocate); |
| 3944 | EXPORT_SYMBOL(qdio_establish); |
| 3945 | EXPORT_SYMBOL(qdio_initialize); |
| 3946 | EXPORT_SYMBOL(qdio_activate); |
| 3947 | EXPORT_SYMBOL(do_QDIO); |
| 3948 | EXPORT_SYMBOL(qdio_shutdown); |
| 3949 | EXPORT_SYMBOL(qdio_free); |
| 3950 | EXPORT_SYMBOL(qdio_cleanup); |
| 3951 | EXPORT_SYMBOL(qdio_synchronize); |