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