File: /usr/src/linux/drivers/s390/s390io.c
1 /*
2 * arch/s390/kernel/s390io.c
3 * S/390 common I/O routines
4 *
5 * S390 version
6 * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation
8 * Author(s): Ingo Adlung (adlung@de.ibm.com)
9 * ChangeLog: 01/04/2001 Holger Smolinski (smolinsk@de.ibm.com)
10 * Fixed lost interrupts and do_adapter_IO
11 * xx/xx/xxxx nnn multiple changes not reflected
12 * 03/12/2001 Ingo Adlung blacklist= - changed to cio_ignore=
13 * 03/14/2001 Ingo Adlung disable interrupts before start_IO
14 * in Path Group processing
15 * decrease retry2 on busy while
16 * disabling sync_isc; reset isc_cnt
17 * on io error during sync_isc enablement
18 * 05/09/2001 Cornelia Huck added exploitation of debug feature
19 * 05/16/2001 Cornelia Huck added /proc/deviceinfo/<devno>/
20 * 05/22/2001 Cornelia Huck added /proc/cio_ignore
21 * un-ignore blacklisted devices by piping
22 * to /proc/cio_ignore
23 */
24
25 #include <linux/module.h>
26 #include <linux/config.h>
27 #include <linux/errno.h>
28 #include <linux/kernel_stat.h>
29 #include <linux/signal.h>
30 #include <linux/sched.h>
31 #include <linux/interrupt.h>
32 #include <linux/slab.h>
33 #include <linux/string.h>
34 #include <linux/smp.h>
35 #include <linux/threads.h>
36 #include <linux/smp_lock.h>
37 #include <linux/init.h>
38 #include <linux/bootmem.h>
39 #ifdef CONFIG_PROC_FS
40 #include <linux/proc_fs.h>
41 #endif
42 #include <asm/system.h>
43 #include <asm/io.h>
44 #include <asm/irq.h>
45 #include <asm/bitops.h>
46 #include <asm/smp.h>
47 #include <asm/pgtable.h>
48 #include <asm/delay.h>
49 #include <asm/processor.h>
50 #include <asm/lowcore.h>
51 #include <asm/idals.h>
52 #include <asm/uaccess.h>
53
54 #include <asm/s390io.h>
55 #include <asm/s390dyn.h>
56 #include <asm/s390mach.h>
57 #include <asm/debug.h>
58
59 #ifndef TRUE
60 #define TRUE 1
61 #define FALSE 0
62 #endif
63
64 #undef CONFIG_DEBUG_IO
65 #define CONFIG_DEBUG_CRW
66
67 unsigned int highest_subchannel;
68 ioinfo_t *ioinfo_head = NULL;
69 ioinfo_t *ioinfo_tail = NULL;
70 ioinfo_t *ioinfo[__MAX_SUBCHANNELS] = {
71 [0 ... (__MAX_SUBCHANNELS-1)] = INVALID_STORAGE_AREA
72 };
73
74 static atomic_t sync_isc = ATOMIC_INIT(-1);
75 static int sync_isc_cnt = 0; // synchronous irq processing lock
76
77 static spinlock_t adapter_lock = SPIN_LOCK_UNLOCKED;
78 // adapter interrupt lock
79 static psw_t io_sync_wait; // wait PSW for sync IO, prot. by sync_isc
80 static int cons_dev = -1; // identify console device
81 static int init_IRQ_complete = 0;
82 static int cio_show_msg = 0;
83 static schib_t *p_init_schib = NULL;
84 static irb_t *p_init_irb = NULL;
85 static __u64 irq_IPL_TOD;
86 static adapter_int_handler_t adapter_handler = NULL;
87
88 /* for use of debug feature */
89 debug_info_t *cio_debug_msg_id = NULL;
90 debug_info_t *cio_debug_trace_id = NULL;
91 debug_info_t *cio_debug_crw_id = NULL;
92 int cio_debug_initialized = 0;
93
94 static void init_IRQ_handler( int irq, void *dev_id, struct pt_regs *regs);
95 static void s390_process_subchannels( void);
96 static void s390_device_recognition_all( void);
97 static void s390_device_recognition_irq( int irq);
98 static void s390_redo_validation(void);
99 static int s390_validate_subchannel( int irq, int enable);
100 static int s390_SenseID( int irq, senseid_t *sid, __u8 lpm);
101 static int s390_SetPGID( int irq, __u8 lpm, pgid_t *pgid);
102 static int s390_SensePGID( int irq, __u8 lpm, pgid_t *pgid);
103 static int s390_process_IRQ( unsigned int irq );
104 static int enable_subchannel( unsigned int irq);
105 static int disable_subchannel( unsigned int irq);
106
107 static int chan_proc_init( void );
108
109 static inline void do_adapter_IO( __u32 intparm );
110
111 int s390_DevicePathVerification( int irq, __u8 domask );
112 int s390_register_adapter_interrupt( adapter_int_handler_t handler );
113 int s390_unregister_adapter_interrupt( adapter_int_handler_t handler );
114
115 extern int do_none(unsigned int irq, int cpu, struct pt_regs * regs);
116 extern int enable_none(unsigned int irq);
117 extern int disable_none(unsigned int irq);
118
119 asmlinkage void do_IRQ( struct pt_regs regs );
120
121 #define MAX_CIO_PROCFS_ENTRIES 0x300
122 /* magic number; we want to have some room to spare */
123
124 int cio_procfs_device_create(int devno);
125 int cio_procfs_device_remove(int devno);
126 int cio_procfs_device_purge(void);
127
128 int cio_notoper_msg = 1;
129 int cio_proc_devinfo = 0; /* switch off the /proc/deviceinfo/ stuff by default
130 until problems are dealt with */
131
132 /*
133 * "Blacklisting" of certain devices:
134 * Device numbers given in the commandline as blacklist=... won't be known to Linux
135 * These can be single devices or ranges of devices
136 *
137 * Introduced by Cornelia Huck <cohuck@de.ibm.com>
138 * Most of it shamelessly taken from dasd.c
139 */
140
141 typedef struct dev_blacklist_range_t {
142 unsigned int from; /* beginning of range */
143 unsigned int to; /* end of range */
144 struct dev_blacklist_range_t *next; /* next range in list */
145 } dev_blacklist_range_t;
146
147 static dev_blacklist_range_t *dev_blacklist_range_head = NULL; /* Anchor for list of ranges */
148 static spinlock_t blacklist_lock = SPIN_LOCK_UNLOCKED;
149 static int nr_blacklisted_ranges = 0;
150
151 /* Handling of the blacklist ranges */
152
153 /*
154 * Function: blacklist_range_create
155 * Creates a range from the given parameters
156 */
157 static inline dev_blacklist_range_t *blacklist_range_create( int from, int to)
158 {
159 dev_blacklist_range_t *range = NULL;
160
161 if (to && (from>to)) {
162 printk("Invalid blacklist range %x to %x, skipping\n", from, to);
163 return NULL;
164 }
165 if (init_IRQ_complete) {
166 range = ( dev_blacklist_range_t *) kmalloc( sizeof( dev_blacklist_range_t ), GFP_KERNEL);
167 } else {
168 range = ( dev_blacklist_range_t *) alloc_bootmem( sizeof( dev_blacklist_range_t ) );
169 }
170 if (range == NULL)
171 return NULL;
172 memset( range, 0, sizeof( dev_blacklist_range_t ));
173 range->from = from;
174 if (to == 0) { /* only a single device is given */
175 range->to = from;
176 } else {
177 range->to = to;
178 }
179 nr_blacklisted_ranges++;
180 return range;
181 }
182
183 /*
184 * Function: blacklist_range_destroy
185 * Free the given range
186 */
187
188 static inline void blacklist_range_destroy( dev_blacklist_range_t *range )
189 {
190 nr_blacklisted_ranges--;
191 /*
192 * FIXME: the memory was allocated as bootmem,
193 * how to get it free again ?!
194 */
195 /* kfree( range ); */
196 }
197
198 /*
199 * Function: blacklist_range_append
200 * Append a range to the list of blacklisted ranges anchored at dev_blacklist_range_head
201 */
202
203 static inline void blacklist_range_append( dev_blacklist_range_t *range )
204 {
205 dev_blacklist_range_t *temp;
206 long flags;
207
208 spin_lock_irqsave( &blacklist_lock, flags );
209 if (dev_blacklist_range_head == NULL) {
210 dev_blacklist_range_head = range;
211 } else {
212 for ( temp = dev_blacklist_range_head;
213 temp && temp->next;
214 temp = temp->next );
215 temp->next = range;
216 }
217 spin_unlock_irqrestore( &blacklist_lock, flags );
218 }
219
220 /*
221 * Function: blacklist_range_dechain
222 * Remove a range from the list of blacklisted ranges
223 */
224
225 static inline void blacklist_range_dechain( dev_blacklist_range_t *range )
226 {
227 dev_blacklist_range_t *temp, *prev = NULL;
228 long flags;
229
230 spin_lock_irqsave( &blacklist_lock, flags );
231 for ( temp = dev_blacklist_range_head; temp != NULL; temp = temp->next ) {
232 if ( temp == range )
233 break;
234 prev = temp;
235 }
236 if (!temp)
237 BUG();
238 if (prev) {
239 prev->next = range->next;
240 } else {
241 dev_blacklist_range_head = range->next;
242 }
243 spin_unlock_irqrestore( &blacklist_lock, flags );
244 }
245
246 /*
247 * Function: blacklist_range_add
248 * Creates a range from the specified arguments and appends it to the list of
249 * blacklisted devices
250 */
251
252 static inline dev_blacklist_range_t *blacklist_range_add( int from, int to )
253 {
254 dev_blacklist_range_t *temp;
255
256 temp = blacklist_range_create( from, to );
257 if (!temp)
258 return NULL;
259 blacklist_range_append( temp );
260 return temp;
261 }
262
263 /*
264 * Function: blacklist_range_remove
265 * Removes a range from the blacklist chain
266 */
267
268 static inline void blacklist_range_remove( int from, int to )
269 {
270 dev_blacklist_range_t *temp;
271
272 for ( temp = dev_blacklist_range_head;
273 (temp->from != from) && (temp->to != to);
274 temp = temp->next );
275 blacklist_range_dechain( temp );
276 blacklist_range_destroy( temp );
277 }
278
279 /* Parsing the commandline for blacklist parameters */
280
281 /*
282 * Variable to hold the blacklisted devices given by the parameter line
283 * blacklist=...
284 */
285 char *blacklist[256] = {NULL, };
286
287 /*
288 * Get the blacklist=... items from the parameter line
289 */
290
291 static void blacklist_split_parm_string (char *str)
292 {
293 char *tmp = str;
294 int count = 0;
295 do {
296 char *end;
297 int len;
298 end = strchr (tmp, ',');
299 if (end == NULL) {
300 len = strlen (tmp) + 1;
301 } else {
302 len = (long) end - (long) tmp + 1;
303 *end = '\0';
304 end++;
305 }
306 blacklist[count] = alloc_bootmem (len * sizeof (char) );
307 if (blacklist == NULL) {
308 printk (KERN_WARNING "can't store blacklist= parameter no %d\n", count + 1);
309 break;
310 }
311 memset (blacklist[count], 0, len * sizeof (char));
312 memcpy (blacklist[count], tmp, len * sizeof (char));
313 count++;
314 tmp = end;
315 } while (tmp != NULL && *tmp != '\0');
316 }
317
318 /*
319 * The blacklist parameters as one concatenated string
320 */
321
322 static char blacklist_parm_string[1024] __initdata = {0,};
323
324
325 /*
326 * function: blacklist_strtoul
327 * Strip leading '0x' and interpret the values as Hex
328 */
329 static inline int blacklist_strtoul (char *str, char **stra)
330 {
331 char *temp = str;
332 int val;
333 if (*temp == '0') {
334 temp++; /* strip leading zero */
335 if (*temp == 'x')
336 temp++; /* strip leading x */
337 }
338 val = simple_strtoul (temp, &temp, 16); /* interpret anything as hex */
339 *stra = temp;
340 return val;
341 }
342
343 /*
344 * Function: blacklist_parse
345 * Parse the parameters given to blacklist=...
346 * Add the blacklisted devices to the blacklist chain
347 */
348
349 static inline void blacklist_parse( char **str )
350 {
351 char *temp;
352 int from, to;
353
354 while (*str) {
355 temp = *str;
356 from = 0;
357 to = 0;
358
359 from = blacklist_strtoul( temp, &temp );
360 if (*temp == '-') {
361 temp++;
362 to = blacklist_strtoul( temp, &temp );
363 }
364 if (!blacklist_range_add( from, to )) {
365 printk( KERN_WARNING "Blacklisting range from %X to %X failed!\n", from, to);
366 }
367 #ifdef CONFIG_DEBUG_IO
368 printk( "Blacklisted range from %X to %X\n", from, to );
369 #endif
370 str++;
371 }
372 }
373
374
375 /*
376 * Initialisation of blacklist
377 */
378
379 void __init blacklist_init( void )
380 {
381 #ifdef CONFIG_DEBUG_IO
382 printk( "Reading blacklist...\n");
383 #endif
384 if (cio_debug_initialized)
385 debug_sprintf_event(cio_debug_msg_id, 6,
386 "Reading blacklist\n");
387 blacklist_split_parm_string( blacklist_parm_string );
388 blacklist_parse( blacklist );
389 }
390
391
392 /*
393 * Get all the blacklist parameters from parameter line
394 */
395
396 void __init blacklist_setup (char *str, int *ints)
397 {
398 int len = strlen (blacklist_parm_string);
399 if (len != 0) {
400 strcat (blacklist_parm_string, ",");
401 }
402 strcat (blacklist_parm_string, str);
403 }
404
405 int __init blacklist_call_setup (char *str)
406 {
407 int dummy;
408 #ifdef CONFIG_DEBUG_IO
409 printk( "Reading blacklist parameters...\n" );
410 #endif
411 if (cio_debug_initialized)
412 debug_sprintf_event(cio_debug_msg_id, 6,
413 "Reading blacklist parameters\n");
414 blacklist_setup(str,&dummy);
415
416 blacklist_init(); /* Blacklist ranges must be ready when device recognition starts */
417
418 return 1;
419 }
420
421 __setup ("cio_ignore=", blacklist_call_setup);
422
423 /* Checking if devices are blacklisted */
424
425 /*
426 * Function: is_blacklisted
427 * Returns 1 if the given devicenumber can be found in the blacklist, otherwise 0.
428 */
429
430 static inline int is_blacklisted( int devno )
431 {
432 dev_blacklist_range_t *temp;
433
434 if (dev_blacklist_range_head == NULL) {
435 /* no blacklist */
436 return 0;
437 }
438
439 temp = dev_blacklist_range_head;
440 while (temp) {
441 if ((temp->from <= devno) && (temp->to >= devno)) {
442 return 1; /* Deviceno is blacklisted */
443 }
444 temp = temp->next;
445 }
446 return 0;
447 }
448
449 /*
450 * Function: blacklist_free_all_ranges
451 * set all blacklisted devices free...
452 */
453
454 void blacklist_free_all_ranges(void)
455 {
456 dev_blacklist_range_t *tmp = dev_blacklist_range_head;
457
458 while (tmp) {
459 blacklist_range_dechain(tmp);
460 blacklist_range_destroy(tmp);
461 tmp = dev_blacklist_range_head;
462 }
463 }
464
465 /*
466 * Function: blacklist_parse_proc_parameters
467 * parse the stuff which is piped to /proc/cio_ignore
468 */
469 void blacklist_parse_proc_parameters(char *buf)
470 {
471 char *tmp;
472 int i;
473 char *end;
474 int len = -1;
475 char *param;
476 int from = 0;
477 int to = 0;
478 int changed = 0;
479 dev_blacklist_range_t *range, *temp;
480
481 tmp = buf;
482 if (strstr(tmp, "free ")) {
483 for (i=0; i<5; i++) {
484 tmp++;
485 }
486 if (strstr(tmp, "all")) {
487 blacklist_free_all_ranges();
488 s390_redo_validation();
489 } else {
490 while (tmp != NULL) {
491 end = strchr(tmp, ',');
492 if (end == NULL) {
493 len = strlen(tmp) + 1;
494 } else {
495 len = (long)end - (long) tmp + 1;
496 *end = '\0';
497 end++;
498 }
499 param = (char*) kmalloc(len * sizeof(char) + 1, GFP_KERNEL);
500 strncpy(param, (const char *) tmp, len);
501 tmp = end;
502 from = blacklist_strtoul(param, ¶m);
503 if (*param == '-') {
504 param++;
505 to = blacklist_strtoul(param, ¶m);
506 } else {
507 to = from;
508 }
509 range = dev_blacklist_range_head;
510 while (range != NULL) {
511 temp = range->next;
512 if ((from <= range->from) && (to >= range->to)) {
513 blacklist_range_dechain(range);
514 blacklist_range_destroy(range);
515 changed = 1;
516 } else if ((from <= range->from) && (to>=range->from) && (to < range->to)) {
517 blacklist_range_add(to+1, range->to);
518 blacklist_range_dechain(range);
519 blacklist_range_destroy(range);
520 changed = 1;
521 } else if ((from > range->from) && (from<=range->to) && (to >= range->to)) {
522 blacklist_range_add(range->from, from-1);
523 blacklist_range_dechain(range);
524 blacklist_range_destroy(range);
525 changed = 1;
526 } else if ((from > range->from) && (to < range->to)) {
527 blacklist_range_add(range->from, from-1);
528 blacklist_range_add(to+1, range->to);
529 blacklist_range_dechain(range);
530 blacklist_range_destroy(range);
531 changed = 1;
532 }
533 range = temp;
534 }
535 kfree(param);
536 }
537 if (changed)
538 s390_redo_validation();
539 }
540 } else {
541 printk("cio_ignore: Parse error; try using 'free all|<devno-range>,<devno-range>,...'\n");
542 }
543 }
544
545 /* End of blacklist handling */
546
547
548 void s390_displayhex(char *str,void *ptr,s32 cnt);
549 void s390_displayhex2(char *str, void *ptr, s32 cnt, int level);
550
551 void s390_displayhex(char *str,void *ptr,s32 cnt)
552 {
553 s32 cnt1,cnt2,maxcnt2;
554 u32 *currptr=(__u32 *)ptr;
555
556 printk("\n%s\n",str);
557
558 for(cnt1=0;cnt1<cnt;cnt1+=16)
559 {
560 printk("%08lX ",(unsigned long)currptr);
561 maxcnt2=cnt-cnt1;
562 if(maxcnt2>16)
563 maxcnt2=16;
564 for(cnt2=0;cnt2<maxcnt2;cnt2+=4)
565 printk("%08X ",*currptr++);
566 printk("\n");
567 }
568 }
569
570 void s390_displayhex2(char *str, void *ptr, s32 cnt, int level)
571 {
572 s32 cnt1, cnt2, maxcnt2;
573 u32 *currptr = (__u32 *)ptr;
574
575 debug_sprintf_event(cio_debug_msg_id, level, "%s\n", str);
576
577 for (cnt1 = 0; cnt1<cnt; cnt1+=16) {
578 debug_sprintf_event(cio_debug_msg_id, level, "%08lX ", (unsigned long)currptr);
579 maxcnt2 = cnt - cnt1;
580 if (maxcnt2 > 16)
581 maxcnt2 = 16;
582 for (cnt2 = 0; cnt2 < maxcnt2; cnt2 += 4)
583 debug_sprintf_event(cio_debug_msg_id, level, "%08X ", *currptr++);
584 }
585 }
586
587 static int __init cio_setup( char *parm )
588 {
589 if ( !strcmp( parm, "yes") )
590 {
591 cio_show_msg = 1;
592 }
593 else if ( !strcmp( parm, "no") )
594 {
595 cio_show_msg = 0;
596 }
597 else
598 {
599 printk( "cio_setup : invalid cio_msg parameter '%s'", parm);
600
601 } /* endif */
602
603 return 1;
604 }
605
606 __setup("cio_msg=", cio_setup);
607
608 static int __init cio_notoper_setup(char *parm)
609 {
610 if (!strcmp(parm, "yes")) {
611 cio_notoper_msg = 1;
612 } else if (!strcmp(parm, "no")) {
613 cio_notoper_msg = 0;
614 } else {
615 printk("cio_notoper_setup: invalid cio_notoper_msg parameter '%s'", parm);
616 }
617
618 return 1;
619 }
620
621 __setup("cio_notoper_msg=", cio_notoper_setup);
622
623 static int __init cio_proc_devinfo_setup(char *parm)
624 {
625 if (!strcmp(parm, "yes")) {
626 cio_proc_devinfo = 1;
627 } else if (!strcmp(parm, "no")) {
628 cio_proc_devinfo = 0;
629 } else {
630 printk("cio_proc_devinfo_setup: invalid parameter '%s'\n",parm);
631 }
632
633 return 1;
634 }
635
636 __setup("cio_proc_devinfo=", cio_proc_devinfo_setup);
637
638 /*
639 * register for adapter interrupts
640 *
641 * With HiperSockets the zSeries architecture provides for
642 * means of adapter interrups, pseudo I/O interrupts that are
643 * not tied to an I/O subchannel, but to an adapter. However,
644 * it doesn't disclose the info how to enable/disable them, but
645 * to recognize them only. Perhaps we should consider them
646 * being shared interrupts, and thus build a linked list
647 * of adapter handlers ... to be evaluated ...
648 */
649 int s390_register_adapter_interrupt( adapter_int_handler_t handler )
650 {
651 int ret = 0;
652
653 if (cio_debug_initialized)
654 debug_text_event(cio_debug_trace_id, 4, "rgaint");
655
656 spin_lock( &adapter_lock );
657
658 if ( handler == NULL )
659 ret = -EINVAL;
660 else if ( adapter_handler )
661 ret = -EBUSY;
662 else
663 adapter_handler = handler;
664
665 spin_unlock( &adapter_lock );
666
667 return( ret);
668 }
669
670
671 int s390_unregister_adapter_interrupt( adapter_int_handler_t handler )
672 {
673 int ret = 0;
674
675 if (cio_debug_initialized)
676 debug_text_event(cio_debug_trace_id, 4, "urgaint");
677
678 spin_lock( &adapter_lock );
679
680 if ( handler == NULL )
681 ret = -EINVAL;
682 else if ( handler != adapter_handler )
683 ret = -EINVAL;
684 else
685 adapter_handler = NULL;
686
687 spin_unlock( &adapter_lock );
688
689 return( ret);
690 }
691
692 static inline void do_adapter_IO( __u32 intparm )
693 {
694 if (cio_debug_initialized)
695 debug_text_event(cio_debug_trace_id, 4, "doaio");
696
697 spin_lock( &adapter_lock );
698
699 if ( adapter_handler )
700 (*adapter_handler)( intparm );
701
702 spin_unlock( &adapter_lock );
703
704 return;
705 }
706
707 int s390_request_irq_special( int irq,
708 io_handler_func_t io_handler,
709 not_oper_handler_func_t not_oper_handler,
710 unsigned long irqflags,
711 const char *devname,
712 void *dev_id)
713 {
714 int retval = 0;
715 unsigned long flags;
716 char dbf_txt[15];
717
718 if (irq >= __MAX_SUBCHANNELS)
719 return -EINVAL;
720
721 if ( !io_handler || !dev_id )
722 return -EINVAL;
723
724 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
725 return -ENODEV;
726
727
728 if (cio_debug_initialized) {
729 debug_text_event(cio_debug_trace_id, 4, "reqsp");
730 sprintf(dbf_txt, "%x", irq);
731 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
732 }
733
734 /*
735 * The following block of code has to be executed atomically
736 */
737 s390irq_spin_lock_irqsave( irq, flags);
738
739 if ( !ioinfo[irq]->ui.flags.ready )
740 {
741 ioinfo[irq]->irq_desc.handler = io_handler;
742 ioinfo[irq]->irq_desc.name = devname;
743 ioinfo[irq]->irq_desc.dev_id = dev_id;
744 ioinfo[irq]->ui.flags.ready = 1;
745
746 enable_subchannel(irq);
747 }
748 else
749 {
750 /*
751 * interrupt already owned, and shared interrupts
752 * aren't supported on S/390.
753 */
754 retval = -EBUSY;
755
756 } /* endif */
757
758 s390irq_spin_unlock_irqrestore(irq,flags);
759
760
761
762 if ( retval == 0 )
763 {
764 s390_DevicePathVerification( irq, 0 );
765
766 ioinfo[irq]->ui.flags.newreq = 1;
767 ioinfo[irq]->nopfunc = not_oper_handler;
768 }
769
770 return retval;
771 }
772
773
774 int s390_request_irq( unsigned int irq,
775 void (*handler)(int, void *, struct pt_regs *),
776 unsigned long irqflags,
777 const char *devname,
778 void *dev_id)
779 {
780 int ret;
781
782 ret = s390_request_irq_special( irq,
783 (io_handler_func_t)handler,
784 NULL,
785 irqflags,
786 devname,
787 dev_id);
788
789 if ( ret == 0 )
790 {
791 ioinfo[irq]->ui.flags.newreq = 0;
792
793 } /* endif */
794
795 return( ret);
796 }
797
798 void s390_free_irq(unsigned int irq, void *dev_id)
799 {
800 unsigned long flags;
801 int ret;
802
803 unsigned int count = 0;
804 char dbf_txt[15];
805
806 if ( irq >= __MAX_SUBCHANNELS || ioinfo[irq] == INVALID_STORAGE_AREA )
807 {
808 return;
809
810 } /* endif */
811
812 if (cio_debug_initialized) {
813 debug_text_event(cio_debug_trace_id, 2, "free");
814 sprintf(dbf_txt, "%x", irq);
815 debug_text_event(cio_debug_trace_id, 2, dbf_txt);
816 }
817
818 s390irq_spin_lock_irqsave( irq, flags);
819
820 #ifdef CONFIG_KERNEL_DEBUG
821 if ( irq != cons_dev )
822 {
823 printk("Trying to free IRQ%d\n",irq);
824
825 } /* endif */
826 #endif
827 if (cio_debug_initialized)
828 debug_sprintf_event(cio_debug_msg_id, 2, "Trying to free IRQ %d\n", irq);
829
830 /*
831 * disable the device and reset all IRQ info if
832 * the IRQ is actually owned by the handler ...
833 */
834 if ( ioinfo[irq]->ui.flags.ready )
835 {
836 if ( dev_id == ioinfo[irq]->irq_desc.dev_id )
837 {
838 /* start deregister */
839 ioinfo[irq]->ui.flags.unready = 1;
840
841 do
842 {
843 ret = disable_subchannel( irq);
844
845 count++;
846
847 if ( ret == -EBUSY )
848 {
849 int iret;
850
851 /*
852 * kill it !
853 * ... we first try sync and eventually
854 * try terminating the current I/O by
855 * an async request, twice halt, then
856 * clear.
857 */
858 if ( count < 2 )
859 {
860 iret = halt_IO( irq,
861 0xC8C1D3E3,
862 DOIO_WAIT_FOR_INTERRUPT );
863
864 if ( iret == -EBUSY )
865 {
866 halt_IO( irq, 0xC8C1D3E3, 0);
867 s390irq_spin_unlock_irqrestore( irq, flags);
868 udelay( 200000 ); /* 200 ms */
869 s390irq_spin_lock_irqsave( irq, flags);
870
871 } /* endif */
872 }
873 else
874 {
875 iret = clear_IO( irq,
876 0x40C3D3D9,
877 DOIO_WAIT_FOR_INTERRUPT );
878
879 if ( iret == -EBUSY )
880 {
881 clear_IO( irq, 0xC8C1D3E3, 0);
882 s390irq_spin_unlock_irqrestore( irq, flags);
883 udelay( 1000000 ); /* 1000 ms */
884 s390irq_spin_lock_irqsave( irq, flags);
885
886 } /* endif */
887
888 } /* endif */
889
890 if ( count == 2 )
891 {
892 /* give it a very last try ... */
893 disable_subchannel( irq);
894
895 if ( ioinfo[irq]->ui.flags.busy )
896 {
897 printk( KERN_CRIT"free_irq(%04X) "
898 "- device %04X busy, retry "
899 "count exceeded\n",
900 irq,
901 ioinfo[irq]->devstat.devno);
902 if (cio_debug_initialized)
903 debug_sprintf_event(cio_debug_msg_id, 0,
904 "free_irq(%04X) - device %04X busy, retry count exceeded\n",
905 irq, ioinfo[irq]->devstat.devno);
906
907 } /* endif */
908
909 break; /* sigh, let's give up ... */
910
911 } /* endif */
912
913 } /* endif */
914
915 } while ( ret == -EBUSY );
916
917 ioinfo[irq]->ui.flags.ready = 0;
918 ioinfo[irq]->ui.flags.unready = 0; /* deregister ended */
919
920 ioinfo[irq]->nopfunc = NULL;
921
922 s390irq_spin_unlock_irqrestore( irq, flags);
923 }
924 else
925 {
926 s390irq_spin_unlock_irqrestore( irq, flags);
927
928 printk( "free_irq(%04X) : error, "
929 "dev_id does not match !\n", irq);
930 if (cio_debug_initialized)
931 debug_sprintf_event(cio_debug_msg_id, 0,
932 "free_irq(%04X) : error, dev_id does not match !\n", irq);
933
934 } /* endif */
935
936 }
937 else
938 {
939 s390irq_spin_unlock_irqrestore( irq, flags);
940
941 printk( "free_irq(%04X) : error, "
942 "no action block ... !\n", irq);
943 if (cio_debug_initialized)
944 debug_sprintf_event(cio_debug_msg_id, 0,
945 "free_irq(%04X) : error, no action block ... !\n", irq);
946
947 } /* endif */
948
949 }
950
951 /*
952 * Generic enable/disable code
953 */
954 int disable_irq(unsigned int irq)
955 {
956 unsigned long flags;
957 int ret;
958 char dbf_txt[15];
959
960 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
961 return( -ENODEV);
962
963 if ( !ioinfo[irq]->ui.flags.ready )
964 return -ENODEV;
965
966 if (cio_debug_initialized) {
967 debug_text_event(cio_debug_trace_id, 4, "disirq");
968 sprintf(dbf_txt, "%x", irq);
969 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
970 }
971
972 s390irq_spin_lock_irqsave(irq, flags);
973 ret = disable_subchannel(irq);
974 s390irq_spin_unlock_irqrestore(irq, flags);
975
976 synchronize_irq();
977
978 return( ret);
979 }
980
981 int enable_irq(unsigned int irq)
982 {
983 unsigned long flags;
984 int ret;
985 char dbf_txt[15];
986
987 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
988 return( -ENODEV);
989
990 if ( !ioinfo[irq]->ui.flags.ready )
991 return -ENODEV;
992
993 if (cio_debug_initialized) {
994 debug_text_event(cio_debug_trace_id, 4, "enirq");
995 sprintf(dbf_txt, "%x", irq);
996 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
997 }
998
999 s390irq_spin_lock_irqsave(irq, flags);
1000 ret = enable_subchannel(irq);
1001 s390irq_spin_unlock_irqrestore(irq, flags);
1002
1003 return(ret);
1004 }
1005
1006 /*
1007 * Enable IRQ by modifying the subchannel
1008 */
1009 static int enable_subchannel( unsigned int irq)
1010 {
1011 int ret;
1012 int ccode;
1013 int retry = 5;
1014 char dbf_txt[15];
1015
1016 if ( irq > highest_subchannel || irq < 0 )
1017 {
1018 return( -ENODEV );
1019
1020 } /* endif */
1021
1022 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
1023 return( -ENODEV);
1024
1025 if (cio_debug_initialized) {
1026 debug_text_event(cio_debug_trace_id, 2, "ensch");
1027 sprintf(dbf_txt, "%x", irq);
1028 debug_text_event(cio_debug_trace_id, 2, dbf_txt);
1029 }
1030
1031 /*
1032 * If a previous disable request is pending we reset it. However, this
1033 * status implies that the device may (still) be not-operational.
1034 */
1035 if ( ioinfo[irq]->ui.flags.d_disable )
1036 {
1037 ioinfo[irq]->ui.flags.d_disable = 0;
1038 ret = 0;
1039 }
1040 else
1041 {
1042 ccode = stsch(irq, &(ioinfo[irq]->schib) );
1043
1044 if ( ccode )
1045 {
1046 ret = -ENODEV;
1047 }
1048 else
1049 {
1050 ioinfo[irq]->schib.pmcw.ena = 1;
1051
1052 if ( irq == cons_dev )
1053 {
1054 ioinfo[irq]->schib.pmcw.isc = 7;
1055 }
1056 else
1057 {
1058 ioinfo[irq]->schib.pmcw.isc = 3;
1059
1060 } /* endif */
1061
1062 do
1063 {
1064 ccode = msch( irq, &(ioinfo[irq]->schib) );
1065
1066 switch (ccode) {
1067 case 0:
1068 ret = 0;
1069 break;
1070
1071 case 1:
1072 /*
1073 * very bad, requires interrupt alike
1074 * processing, where "rbh" is a dummy
1075 * parameter for interface compatibility
1076 * only. Bottom-half handling cannot be
1077 * required as this must be an
1078 * unsolicited interrupt (!busy).
1079 */
1080
1081 ioinfo[irq]->ui.flags.s_pend = 1;
1082 s390_process_IRQ( irq );
1083 ioinfo[irq]->ui.flags.s_pend = 0;
1084
1085 ret = -EIO; /* might be overwritten */
1086 /* ... on re-driving */
1087 /* ... the msch() */
1088 retry--;
1089 break;
1090
1091 case 2:
1092 udelay(100); /* allow for recovery */
1093 ret = -EBUSY;
1094 retry--;
1095 break;
1096
1097 case 3:
1098 ioinfo[irq]->ui.flags.oper = 0;
1099 ret = -ENODEV;
1100 break;
1101
1102 default:
1103 printk( KERN_CRIT"enable_subchannel(%04X) "
1104 " : ccode 2 on msch() for device "
1105 "%04X received !\n",
1106 irq,
1107 ioinfo[irq]->devstat.devno);
1108 if (cio_debug_initialized)
1109 debug_sprintf_event(cio_debug_msg_id, 0,
1110 "enable_subchannel(%04X) : ccode 2 on msch() for device %04X received !\n",
1111 irq, ioinfo[irq]->devstat.devno);
1112
1113 ret = -ENODEV; // never reached
1114 }
1115
1116 } while ( (ccode == 1) && retry );
1117
1118 } /* endif */
1119
1120 } /* endif */
1121
1122 return( ret );
1123 }
1124
1125
1126 /*
1127 * Disable IRQ by modifying the subchannel
1128 */
1129 static int disable_subchannel( unsigned int irq)
1130 {
1131 int cc; /* condition code */
1132 int ret; /* function return value */
1133 int retry = 5;
1134 char dbf_txt[15];
1135
1136 if ( irq > highest_subchannel )
1137 {
1138 ret = -ENODEV;
1139 }
1140 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
1141 {
1142 return( -ENODEV);
1143 }
1144 else if ( ioinfo[irq]->ui.flags.busy )
1145 {
1146 /*
1147 * the disable function must not be called while there are
1148 * requests pending for completion !
1149 */
1150 ret = -EBUSY;
1151 }
1152 else
1153 {
1154 if (cio_debug_initialized) {
1155 debug_text_event(cio_debug_trace_id, 2, "dissch");
1156 sprintf(dbf_txt, "%x", irq);
1157 debug_text_event(cio_debug_trace_id, 2, dbf_txt);
1158 }
1159
1160 /*
1161 * If device isn't operational we have to perform delayed
1162 * disabling when the next interrupt occurs - unless the
1163 * irq is re-requested prior to the interrupt to occur.
1164 */
1165 cc = stsch(irq, &(ioinfo[irq]->schib) );
1166
1167 if ( cc == 3 )
1168 {
1169 ioinfo[irq]->ui.flags.oper = 0;
1170 ioinfo[irq]->ui.flags.d_disable = 1;
1171
1172 ret = 0;
1173 }
1174 else // cc == 0
1175 {
1176 ioinfo[irq]->schib.pmcw.ena = 0;
1177
1178 do
1179 {
1180 cc = msch( irq, &(ioinfo[irq]->schib) );
1181
1182 switch (cc) {
1183 case 0 :
1184 ret = 0; /* done */
1185 break;
1186
1187 case 1 :
1188 /*
1189 * very bad, requires interrupt alike
1190 * processing, where "rbh" is a dummy
1191 * parm for interface compatibility
1192 * only. Bottom-half handling cannot
1193 * be required as this must be an
1194 * unsolicited interrupt (!busy).
1195 */
1196 ioinfo[irq]->ui.flags.s_pend = 1;
1197 s390_process_IRQ( irq );
1198 ioinfo[irq]->ui.flags.s_pend = 0;
1199
1200 ret = -EIO; /* might be overwritten */
1201 /* ... on re-driving the */
1202 /* ... msch() call */
1203 retry--;
1204 break;
1205
1206 case 2 :
1207 /*
1208 * *** must not occur ! ***
1209 * *** ***
1210 * *** indicates our internal ***
1211 * *** interrupt accounting is out ***
1212 * *** of sync ===> panic() ***
1213 */
1214 printk( KERN_CRIT"disable_subchannel(%04X) "
1215 "- unexpected busy condition for "
1216 "device %04X received !\n",
1217 irq,
1218 ioinfo[irq]->devstat.devno);
1219 if (cio_debug_initialized)
1220 debug_sprintf_event(cio_debug_msg_id, 0,
1221 "disable_subchannel(%04X) - unexpected busy condition for device %04X received !\n",
1222 irq, ioinfo[irq]->devstat.devno);
1223 ret = -EBUSY;
1224 break;
1225
1226 case 3 :
1227 /*
1228 * should hardly occur ?!
1229 */
1230 ioinfo[irq]->ui.flags.oper = 0;
1231 ioinfo[irq]->ui.flags.d_disable = 1;
1232
1233 ret = 0; /* if the device has gone we */
1234 /* ... don't need to disable */
1235 /* ... it anymore ! */
1236 break;
1237
1238 default :
1239 ret = -ENODEV; // never reached ...
1240 break;
1241
1242 } /* endswitch */
1243
1244 } while ( (cc == 1) && retry );
1245
1246 } /* endif */
1247
1248 } /* endif */
1249
1250 return( ret);
1251 }
1252
1253
1254 void s390_init_IRQ( void )
1255 {
1256 unsigned long flags; /* PSW flags */
1257 long cr6 __attribute__ ((aligned (8)));
1258
1259 asm volatile ("STCK %0" : "=m" (irq_IPL_TOD));
1260
1261 p_init_schib = alloc_bootmem_low( sizeof(schib_t));
1262 p_init_irb = alloc_bootmem_low( sizeof(irb_t));
1263
1264
1265 /*
1266 * As we don't know about the calling environment
1267 * we assure running disabled. Before leaving the
1268 * function we resestablish the old environment.
1269 *
1270 * Note : as we don't need a system wide lock, therefore
1271 * we shouldn't use cli(), but __cli() as this
1272 * affects the current CPU only.
1273 */
1274 __save_flags(flags);
1275 __cli();
1276
1277 /*
1278 * disable all interrupts
1279 */
1280 cr6 = 0;
1281 __ctl_load( cr6, 6, 6);
1282
1283 s390_process_subchannels();
1284
1285 /*
1286 * enable default I/O-interrupt sublass 3
1287 */
1288 cr6 = 0x10000000;
1289 __ctl_load( cr6, 6, 6);
1290
1291 s390_device_recognition_all();
1292
1293 init_IRQ_complete = 1;
1294
1295 __restore_flags(flags);
1296
1297 return;
1298 }
1299
1300
1301 /*
1302 * dummy handler, used during init_IRQ() processing for compatibility only
1303 */
1304 void init_IRQ_handler( int irq, void *dev_id, struct pt_regs *regs)
1305 {
1306 /* this is a dummy handler only ... */
1307 }
1308
1309
1310 int s390_start_IO( int irq, /* IRQ */
1311 ccw1_t *cpa, /* logical channel prog addr */
1312 unsigned long user_intparm, /* interruption parameter */
1313 __u8 lpm, /* logical path mask */
1314 unsigned long flag) /* flags */
1315 {
1316 int ccode;
1317 int ret = 0;
1318 char buffer[80];
1319 char dbf_txt[15];
1320
1321 /*
1322 * The flag usage is mutal exclusive ...
1323 */
1324 if ( (flag & DOIO_EARLY_NOTIFICATION)
1325 && (flag & DOIO_REPORT_ALL ) )
1326 {
1327 return( -EINVAL );
1328
1329 } /* endif */
1330
1331 if (cio_debug_initialized) {
1332 debug_text_event(cio_debug_trace_id, 4, "stIO");
1333 sprintf(dbf_txt, "%x", irq);
1334 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
1335 }
1336
1337 /*
1338 * setup ORB
1339 */
1340 ioinfo[irq]->orb.intparm = (__u32)(long)&ioinfo[irq]->u_intparm;
1341 ioinfo[irq]->orb.fmt = 1;
1342
1343 ioinfo[irq]->orb.pfch = !(flag & DOIO_DENY_PREFETCH);
1344 ioinfo[irq]->orb.spnd = (flag & DOIO_ALLOW_SUSPEND ? TRUE : FALSE);
1345 ioinfo[irq]->orb.ssic = ( (flag & DOIO_ALLOW_SUSPEND )
1346 && (flag & DOIO_SUPPRESS_INTER) );
1347
1348 if ( flag & DOIO_VALID_LPM )
1349 {
1350 ioinfo[irq]->orb.lpm = lpm;
1351 }
1352 else
1353 {
1354 ioinfo[irq]->orb.lpm = ioinfo[irq]->opm;
1355
1356 } /* endif */
1357
1358 #ifdef CONFIG_ARCH_S390X
1359 /*
1360 * for 64 bit we always support 64 bit IDAWs with 4k page size only
1361 */
1362 ioinfo[irq]->orb.c64 = 1;
1363 ioinfo[irq]->orb.i2k = 0;
1364 #endif
1365
1366 ioinfo[irq]->orb.cpa = (__u32)virt_to_phys( cpa);
1367
1368 /*
1369 * If sync processing was requested we lock the sync ISC, modify the
1370 * device to present interrupts for this ISC only and switch the
1371 * CPU to handle this ISC + the console ISC exclusively.
1372 */
1373 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
1374 {
1375 ret = enable_cpu_sync_isc( irq);
1376
1377 if ( ret )
1378 {
1379 return( ret);
1380 }
1381
1382 } /* endif */
1383
1384 if ( flag & DOIO_DONT_CALL_INTHDLR )
1385 {
1386 ioinfo[irq]->ui.flags.repnone = 1;
1387
1388 } /* endif */
1389
1390 /*
1391 * Issue "Start subchannel" and process condition code
1392 */
1393 ccode = ssch( irq, &(ioinfo[irq]->orb) );
1394
1395 switch ( ccode ) {
1396 case 0:
1397
1398 if ( !ioinfo[irq]->ui.flags.w4sense )
1399 {
1400 /*
1401 * init the device driver specific devstat irb area
1402 *
1403 * Note : don´t clear saved irb info in case of sense !
1404 */
1405 memset( &((devstat_t *)ioinfo[irq]->irq_desc.dev_id)->ii.irb,
1406 '\0', sizeof( irb_t) );
1407 } /* endif */
1408
1409 memset( &ioinfo[irq]->devstat.ii.irb,
1410 '\0',
1411 sizeof( irb_t) );
1412
1413 /*
1414 * initialize device status information
1415 */
1416 ioinfo[irq]->ui.flags.busy = 1;
1417 ioinfo[irq]->ui.flags.doio = 1;
1418
1419 ioinfo[irq]->u_intparm = user_intparm;
1420 ioinfo[irq]->devstat.cstat = 0;
1421 ioinfo[irq]->devstat.dstat = 0;
1422 ioinfo[irq]->devstat.lpum = 0;
1423 ioinfo[irq]->devstat.flag = DEVSTAT_START_FUNCTION;
1424 ioinfo[irq]->devstat.scnt = 0;
1425
1426 ioinfo[irq]->ui.flags.fast = 0;
1427 ioinfo[irq]->ui.flags.repall = 0;
1428
1429 /*
1430 * Check for either early (FAST) notification requests
1431 * or if we are to return all interrupt info.
1432 * Default is to call IRQ handler at secondary status only
1433 */
1434 if ( flag & DOIO_EARLY_NOTIFICATION )
1435 {
1436 ioinfo[irq]->ui.flags.fast = 1;
1437 }
1438 else if ( flag & DOIO_REPORT_ALL )
1439 {
1440 ioinfo[irq]->ui.flags.repall = 1;
1441
1442 } /* endif */
1443
1444 ioinfo[irq]->ulpm = ioinfo[irq]->orb.lpm;
1445
1446 /*
1447 * If synchronous I/O processing is requested, we have
1448 * to wait for the corresponding interrupt to occur by
1449 * polling the interrupt condition. However, as multiple
1450 * interrupts may be outstanding, we must not just wait
1451 * for the first interrupt, but must poll until ours
1452 * pops up.
1453 */
1454 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
1455 {
1456 psw_t io_new_psw;
1457 int ccode;
1458 uint64_t time_start;
1459 uint64_t time_curr;
1460
1461 int ready = 0;
1462 int io_sub = -1;
1463 struct _lowcore *lc = NULL;
1464 int do_retry = 1;
1465
1466 /*
1467 * We shouldn't perform a TPI loop, waiting for an
1468 * interrupt to occur, but should load a WAIT PSW
1469 * instead. Otherwise we may keep the channel subsystem
1470 * busy, not able to present the interrupt. When our
1471 * sync. interrupt arrived we reset the I/O old PSW to
1472 * its original value.
1473 */
1474 memcpy( &io_new_psw, &lc->io_new_psw, sizeof(psw_t));
1475
1476 ccode = iac();
1477
1478 switch (ccode) {
1479 case 0: // primary-space
1480 io_sync_wait.mask = _IO_PSW_MASK
1481 | _PSW_PRIM_SPACE_MODE
1482 | _PSW_IO_WAIT;
1483 break;
1484 case 1: // secondary-space
1485 io_sync_wait.mask = _IO_PSW_MASK
1486 | _PSW_SEC_SPACE_MODE
1487 | _PSW_IO_WAIT;
1488 break;
1489 case 2: // access-register
1490 io_sync_wait.mask = _IO_PSW_MASK
1491 | _PSW_ACC_REG_MODE
1492 | _PSW_IO_WAIT;
1493 break;
1494 case 3: // home-space
1495 io_sync_wait.mask = _IO_PSW_MASK
1496 | _PSW_HOME_SPACE_MODE
1497 | _PSW_IO_WAIT;
1498 break;
1499 default:
1500 panic( "start_IO() : unexpected "
1501 "address-space-control %d\n",
1502 ccode);
1503 break;
1504 } /* endswitch */
1505
1506 io_sync_wait.addr = FIX_PSW(&&io_wakeup);
1507
1508 /*
1509 * Martin didn't like modifying the new PSW, now we take
1510 * a fast exit in do_IRQ() instead
1511 */
1512 *(__u32 *)__LC_SYNC_IO_WORD = 1;
1513
1514 asm volatile ("STCK %0" : "=m" (time_start));
1515
1516 time_start = time_start >> 32;
1517
1518 do
1519 {
1520 if ( flag & DOIO_TIMEOUT )
1521 {
1522 tpi_info_t tpi_info={0,};
1523
1524 do
1525 {
1526 if ( tpi(&tpi_info) == 1 )
1527 {
1528 io_sub = tpi_info.irq;
1529 break;
1530 }
1531 else
1532 {
1533 udelay(100); /* usecs */
1534 asm volatile ("STCK %0" : "=m" (time_curr));
1535
1536 if ( ((time_curr >> 32) - time_start ) >= 3 )
1537 do_retry = 0;
1538
1539 } /* endif */
1540
1541 } while ( do_retry );
1542 }
1543 else
1544 {
1545 __load_psw( io_sync_wait );
1546
1547 io_wakeup:
1548 io_sub = (__u32)*(__u16 *)__LC_SUBCHANNEL_NR;
1549
1550 } /* endif */
1551
1552 if ( do_retry )
1553 ready = s390_process_IRQ( io_sub );
1554
1555 /*
1556 * surrender when retry count's exceeded ...
1557 */
1558 } while ( !( ( io_sub == irq )
1559 && ( ready == 1 ))
1560 && do_retry );
1561
1562 *(__u32 *)__LC_SYNC_IO_WORD = 0;
1563
1564 if ( !do_retry )
1565 ret = -ETIMEDOUT;
1566
1567 } /* endif */
1568
1569 break;
1570
1571 case 1 : /* status pending */
1572
1573 ioinfo[irq]->devstat.flag = DEVSTAT_START_FUNCTION
1574 | DEVSTAT_STATUS_PENDING;
1575
1576 /*
1577 * initialize the device driver specific devstat irb area
1578 */
1579 memset( &((devstat_t *) ioinfo[irq]->irq_desc.dev_id)->ii.irb,
1580 '\0', sizeof( irb_t) );
1581
1582 /*
1583 * Let the common interrupt handler process the pending status.
1584 * However, we must avoid calling the user action handler, as
1585 * it won't be prepared to handle a pending status during
1586 * do_IO() processing inline. This also implies that process_IRQ
1587 * must terminate synchronously - especially if device sensing
1588 * is required.
1589 */
1590 ioinfo[irq]->ui.flags.s_pend = 1;
1591 ioinfo[irq]->ui.flags.busy = 1;
1592 ioinfo[irq]->ui.flags.doio = 1;
1593
1594 s390_process_IRQ( irq );
1595
1596 ioinfo[irq]->ui.flags.s_pend = 0;
1597 ioinfo[irq]->ui.flags.busy = 0;
1598 ioinfo[irq]->ui.flags.doio = 0;
1599
1600 ioinfo[irq]->ui.flags.repall = 0;
1601 ioinfo[irq]->ui.flags.w4final = 0;
1602
1603 ioinfo[irq]->devstat.flag |= DEVSTAT_FINAL_STATUS;
1604
1605 /*
1606 * In multipath mode a condition code 3 implies the last path
1607 * has gone, except we have previously restricted the I/O to
1608 * a particular path. A condition code 1 (0 won't occur)
1609 * results in return code EIO as well as 3 with another path
1610 * than the one used (i.e. path available mask is non-zero).
1611 */
1612 if ( ioinfo[irq]->devstat.ii.irb.scsw.cc == 3 )
1613 {
1614 if ( flag & DOIO_VALID_LPM )
1615 {
1616 ioinfo[irq]->opm &= ~(ioinfo[irq]->devstat.ii.irb.esw.esw1.lpum);
1617 }
1618 else
1619 {
1620 ioinfo[irq]->opm = 0;
1621
1622 } /* endif */
1623
1624 if ( ioinfo[irq]->opm == 0 )
1625 {
1626 ret = -ENODEV;
1627 ioinfo[irq]->ui.flags.oper = 0;
1628 }
1629 else
1630 {
1631 ret = -EIO;
1632
1633 } /* endif */
1634
1635 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
1636
1637 #ifdef CONFIG_DEBUG_IO
1638 {
1639
1640 stsch(irq, &(ioinfo[irq]->schib) );
1641
1642 sprintf( buffer, "s390_start_IO(%04X) - irb for "
1643 "device %04X, after status pending\n",
1644 irq,
1645 ioinfo[irq]->devstat.devno );
1646
1647 s390_displayhex( buffer,
1648 &(ioinfo[irq]->devstat.ii.irb) ,
1649 sizeof(irb_t));
1650
1651 sprintf( buffer, "s390_start_IO(%04X) - schib for "
1652 "device %04X, after status pending\n",
1653 irq,
1654 ioinfo[irq]->devstat.devno );
1655
1656 s390_displayhex( buffer,
1657 &(ioinfo[irq]->schib) ,
1658 sizeof(schib_t));
1659
1660
1661 if (ioinfo[irq]->devstat.flag & DEVSTAT_FLAG_SENSE_AVAIL)
1662 {
1663 sprintf( buffer, "s390_start_IO(%04X) - sense "
1664 "data for "
1665 "device %04X, after status pending\n",
1666 irq,
1667 ioinfo[irq]->devstat.devno );
1668
1669 s390_displayhex( buffer,
1670 ioinfo[irq]->irq_desc.dev_id->ii.sense.data,
1671 ioinfo[irq]->irq_desc.dev_id->rescnt);
1672
1673 } /* endif */
1674 }
1675 #endif
1676 if (cio_debug_initialized) {
1677 stsch(irq, &(ioinfo[irq]->schib) );
1678
1679 sprintf( buffer, "s390_start_IO(%04X) - irb for "
1680 "device %04X, after status pending\n",
1681 irq,
1682 ioinfo[irq]->devstat.devno );
1683
1684 s390_displayhex2( buffer,
1685 &(ioinfo[irq]->devstat.ii.irb) ,
1686 sizeof(irb_t), 2);
1687
1688 sprintf( buffer, "s390_start_IO(%04X) - schib for "
1689 "device %04X, after status pending\n",
1690 irq,
1691 ioinfo[irq]->devstat.devno );
1692
1693 s390_displayhex2( buffer,
1694 &(ioinfo[irq]->schib) ,
1695 sizeof(schib_t), 2);
1696
1697
1698 if (ioinfo[irq]->devstat.flag & DEVSTAT_FLAG_SENSE_AVAIL) {
1699 sprintf( buffer, "s390_start_IO(%04X) - sense "
1700 "data for "
1701 "device %04X, after status pending\n",
1702 irq,
1703 ioinfo[irq]->devstat.devno );
1704
1705 s390_displayhex2( buffer,
1706 ioinfo[irq]->irq_desc.dev_id->ii.sense.data,
1707 ioinfo[irq]->irq_desc.dev_id->rescnt, 2);
1708
1709 } /* endif */
1710 }
1711 }
1712 else
1713 {
1714 ret = -EIO;
1715 ioinfo[irq]->devstat.flag &= ~DEVSTAT_NOT_OPER;
1716 ioinfo[irq]->ui.flags.oper = 1;
1717
1718 } /* endif */
1719
1720 break;
1721
1722 case 2 : /* busy */
1723
1724 ret = -EBUSY;
1725 break;
1726
1727 default: /* device/path not operational */
1728
1729 if ( flag & DOIO_VALID_LPM )
1730 {
1731 ioinfo[irq]->opm &= ~lpm;
1732 }
1733 else
1734 {
1735 ioinfo[irq]->opm = 0;
1736
1737 } /* endif */
1738
1739 if ( ioinfo[irq]->opm == 0 )
1740 {
1741 ioinfo[irq]->ui.flags.oper = 0;
1742 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
1743
1744 } /* endif */
1745
1746 ret = -ENODEV;
1747
1748 memcpy( ioinfo[irq]->irq_desc.dev_id,
1749 &(ioinfo[irq]->devstat),
1750 sizeof( devstat_t) );
1751
1752
1753 #ifdef CONFIG_DEBUG_IO
1754
1755 stsch(irq, &(ioinfo[irq]->schib) );
1756
1757 sprintf( buffer, "s390_start_IO(%04X) - schib for "
1758 "device %04X, after 'not oper' status\n",
1759 irq,
1760 ioinfo[irq]->devstat.devno );
1761
1762 s390_displayhex( buffer,
1763 &(ioinfo[irq]->schib),
1764 sizeof(schib_t));
1765 #endif
1766 if (cio_debug_initialized) {
1767 stsch(irq, &(ioinfo[irq]->schib) );
1768
1769 sprintf( buffer, "s390_start_IO(%04X) - schib for "
1770 "device %04X, after 'not oper' status\n",
1771 irq,
1772 ioinfo[irq]->devstat.devno );
1773
1774 s390_displayhex2( buffer,
1775 &(ioinfo[irq]->schib),
1776 sizeof(schib_t), 2);
1777 }
1778
1779 break;
1780
1781 } /* endswitch */
1782
1783 if ( flag & DOIO_WAIT_FOR_INTERRUPT)
1784 {
1785 disable_cpu_sync_isc( irq );
1786
1787 } /* endif */
1788
1789 if ( flag & DOIO_DONT_CALL_INTHDLR )
1790 {
1791 ioinfo[irq]->ui.flags.repnone = 0;
1792
1793 } /* endif */
1794
1795 return( ret);
1796 }
1797
1798 int do_IO( int irq, /* IRQ */
1799 ccw1_t *cpa, /* channel program address */
1800 unsigned long user_intparm, /* interruption parameter */
1801 __u8 lpm, /* logical path mask */
1802 unsigned long flag) /* flags : see above */
1803 {
1804 int ret = 0;
1805 char dbf_txt[15];
1806
1807 if ( irq > highest_subchannel || irq < 0 )
1808 {
1809 return( -ENODEV );
1810
1811 } /* endif */
1812
1813 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
1814 {
1815 return( -ENODEV);
1816 }
1817
1818 /* handler registered ? or free_irq() in process already ? */
1819 if ( !ioinfo[irq]->ui.flags.ready || ioinfo[irq]->ui.flags.unready )
1820 {
1821 return( -ENODEV );
1822
1823 } /* endif */
1824
1825 if (cio_debug_initialized) {
1826 debug_text_event(cio_debug_trace_id, 4, "doIO");
1827 sprintf(dbf_txt, "%x", irq);
1828 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
1829 }
1830
1831 /*
1832 * Note: We ignore the device operational status - if not operational,
1833 * the SSCH will lead to an -ENODEV condition ...
1834 */
1835 if ( !ioinfo[irq]->ui.flags.busy ) /* last I/O completed ? */
1836 {
1837 ret = s390_start_IO( irq, cpa, user_intparm, lpm, flag);
1838 }
1839 else if ( ioinfo[irq]->ui.flags.fast )
1840 {
1841 /*
1842 * If primary status was received and ending status is missing,
1843 * the device driver won't be notified on the ending status
1844 * if early (fast) interrupt notification was requested.
1845 * Therefore we have to queue the next incoming request. If
1846 * halt_IO() is issued while there is a request queued, a HSCH
1847 * needs to be issued and the queued request must be deleted
1848 * but its intparm must be returned (see halt_IO() processing)
1849 */
1850 if ( ioinfo[irq]->ui.flags.w4final
1851 && !ioinfo[irq]->ui.flags.doio_q )
1852 {
1853 ioinfo[irq]->qflag = flag;
1854 ioinfo[irq]->qcpa = cpa;
1855 ioinfo[irq]->qintparm = user_intparm;
1856 ioinfo[irq]->qlpm = lpm;
1857 }
1858 else
1859 {
1860 ret = -EBUSY;
1861
1862 } /* endif */
1863 }
1864 else
1865 {
1866 ret = -EBUSY;
1867
1868 } /* endif */
1869
1870 return( ret );
1871
1872 }
1873
1874 /*
1875 * resume suspended I/O operation
1876 */
1877 int resume_IO( int irq)
1878 {
1879 int ret = 0;
1880 char dbf_txt[15];
1881
1882 if ( irq > highest_subchannel || irq < 0 )
1883 {
1884 return( -ENODEV );
1885
1886 } /* endif */
1887
1888 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
1889 {
1890 return( -ENODEV);
1891 }
1892
1893 if (cio_debug_initialized) {
1894 debug_text_event(cio_debug_trace_id, 4, "resIO");
1895 sprintf(dbf_txt, "%x", irq);
1896 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
1897 }
1898
1899 /*
1900 * We allow for 'resume' requests only for active I/O operations
1901 */
1902 if ( ioinfo[irq]->ui.flags.busy )
1903 {
1904 int ccode;
1905
1906 ccode = rsch( irq);
1907
1908 switch (ccode) {
1909 case 0 :
1910 break;
1911
1912 case 1 :
1913 s390_process_IRQ( irq );
1914 ret = -EBUSY;
1915 break;
1916
1917 case 2 :
1918 ret = -EINVAL;
1919 break;
1920
1921 case 3 :
1922 /*
1923 * useless to wait for request completion
1924 * as device is no longer operational !
1925 */
1926 ioinfo[irq]->ui.flags.oper = 0;
1927 ioinfo[irq]->ui.flags.busy = 0;
1928 ret = -ENODEV;
1929 break;
1930
1931 } /* endswitch */
1932
1933 }
1934 else
1935 {
1936 ret = -ENOTCONN;
1937
1938 } /* endif */
1939
1940 return( ret);
1941 }
1942
1943 /*
1944 * Note: The "intparm" parameter is not used by the halt_IO() function
1945 * itself, as no ORB is built for the HSCH instruction. However,
1946 * it allows the device interrupt handler to associate the upcoming
1947 * interrupt with the halt_IO() request.
1948 */
1949 int halt_IO( int irq,
1950 unsigned long user_intparm,
1951 unsigned long flag) /* possible DOIO_WAIT_FOR_INTERRUPT */
1952 {
1953 int ret;
1954 int ccode;
1955 char dbf_txt[15];
1956
1957 if ( irq > highest_subchannel || irq < 0 )
1958 {
1959 return -ENODEV;
1960 }
1961
1962 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
1963 {
1964 return( -ENODEV);
1965 }
1966
1967 /*
1968 * we only allow for halt_IO if the device has an I/O handler associated
1969 */
1970 else if ( !ioinfo[irq]->ui.flags.ready )
1971 {
1972 ret = -ENODEV;
1973 }
1974 /*
1975 * we ignore the halt_io() request if ending_status was received but
1976 * a SENSE operation is waiting for completion.
1977 */
1978 else if ( ioinfo[irq]->ui.flags.w4sense )
1979 {
1980 ret = 0;
1981 }
1982 /*
1983 * We don't allow for halt_io with a sync do_IO() requests pending.
1984 */
1985 else if ( ioinfo[irq]->ui.flags.syncio
1986 && (flag & DOIO_WAIT_FOR_INTERRUPT))
1987 {
1988 ret = -EBUSY;
1989 }
1990 else
1991 {
1992 if (cio_debug_initialized) {
1993 debug_text_event(cio_debug_trace_id, 2, "haltIO");
1994 sprintf(dbf_txt, "%x", irq);
1995 debug_text_event(cio_debug_trace_id, 2, dbf_txt);
1996 }
1997 /*
1998 * If sync processing was requested we lock the sync ISC,
1999 * modify the device to present interrupts for this ISC only
2000 * and switch the CPU to handle this ISC + the console ISC
2001 * exclusively.
2002 */
2003 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2004 {
2005 ret = enable_cpu_sync_isc( irq);
2006
2007 if ( ret )
2008 {
2009 return( ret);
2010
2011 } /* endif */
2012
2013 } /* endif */
2014
2015 /*
2016 * Issue "Halt subchannel" and process condition code
2017 */
2018 ccode = hsch( irq );
2019
2020 switch ( ccode ) {
2021 case 0:
2022
2023 ioinfo[irq]->ui.flags.haltio = 1;
2024
2025 if ( !ioinfo[irq]->ui.flags.doio )
2026 {
2027 ioinfo[irq]->ui.flags.busy = 1;
2028 ioinfo[irq]->u_intparm = user_intparm;
2029 ioinfo[irq]->devstat.cstat = 0;
2030 ioinfo[irq]->devstat.dstat = 0;
2031 ioinfo[irq]->devstat.lpum = 0;
2032 ioinfo[irq]->devstat.flag = DEVSTAT_HALT_FUNCTION;
2033 ioinfo[irq]->devstat.scnt = 0;
2034
2035 }
2036 else
2037 {
2038 ioinfo[irq]->devstat.flag |= DEVSTAT_HALT_FUNCTION;
2039
2040 } /* endif */
2041
2042 /*
2043 * If synchronous I/O processing is requested, we have
2044 * to wait for the corresponding interrupt to occur by
2045 * polling the interrupt condition. However, as multiple
2046 * interrupts may be outstanding, we must not just wait
2047 * for the first interrupt, but must poll until ours
2048 * pops up.
2049 */
2050 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2051 {
2052 int io_sub;
2053 __u32 io_parm;
2054 psw_t io_new_psw;
2055 int ccode;
2056
2057 int ready = 0;
2058 struct _lowcore *lc = NULL;
2059
2060 /*
2061 * We shouldn't perform a TPI loop, waiting for
2062 * an interrupt to occur, but should load a
2063 * WAIT PSW instead. Otherwise we may keep the
2064 * channel subsystem busy, not able to present
2065 * the interrupt. When our sync. interrupt
2066 * arrived we reset the I/O old PSW to its
2067 * original value.
2068 */
2069 memcpy( &io_new_psw,
2070 &lc->io_new_psw,
2071 sizeof(psw_t));
2072
2073 ccode = iac();
2074
2075 switch (ccode) {
2076 case 0: // primary-space
2077 io_sync_wait.mask = _IO_PSW_MASK
2078 | _PSW_PRIM_SPACE_MODE
2079 | _PSW_IO_WAIT;
2080 break;
2081 case 1: // secondary-space
2082 io_sync_wait.mask = _IO_PSW_MASK
2083 | _PSW_SEC_SPACE_MODE
2084 | _PSW_IO_WAIT;
2085 break;
2086 case 2: // access-register
2087 io_sync_wait.mask = _IO_PSW_MASK
2088 | _PSW_ACC_REG_MODE
2089 | _PSW_IO_WAIT;
2090 break;
2091 case 3: // home-space
2092 io_sync_wait.mask = _IO_PSW_MASK
2093 | _PSW_HOME_SPACE_MODE
2094 | _PSW_IO_WAIT;
2095 break;
2096 default:
2097 panic( "halt_IO() : unexpected "
2098 "address-space-control %d\n",
2099 ccode);
2100 break;
2101 } /* endswitch */
2102
2103 io_sync_wait.addr = FIX_PSW(&&hio_wakeup);
2104
2105 /*
2106 * Martin didn't like modifying the new PSW, now we take
2107 * a fast exit in do_IRQ() instead
2108 */
2109 *(__u32 *)__LC_SYNC_IO_WORD = 1;
2110
2111 do
2112 {
2113
2114 __load_psw( io_sync_wait );
2115 hio_wakeup:
2116 io_parm = *(__u32 *)__LC_IO_INT_PARM;
2117 io_sub = (__u32)*(__u16 *)__LC_SUBCHANNEL_NR;
2118
2119 ready = s390_process_IRQ( io_sub );
2120
2121 } while ( !((io_sub == irq) && (ready == 1)) );
2122
2123 *(__u32 *)__LC_SYNC_IO_WORD = 0;
2124
2125 } /* endif */
2126
2127 ret = 0;
2128 break;
2129
2130 case 1 : /* status pending */
2131
2132 ioinfo[irq]->devstat.flag |= DEVSTAT_STATUS_PENDING;
2133
2134 /*
2135 * initialize the device driver specific devstat irb area
2136 */
2137 memset( &ioinfo[irq]->irq_desc.dev_id->ii.irb,
2138 '\0', sizeof( irb_t) );
2139
2140 /*
2141 * Let the common interrupt handler process the pending
2142 * status. However, we must avoid calling the user
2143 * action handler, as it won't be prepared to handle
2144 * a pending status during do_IO() processing inline.
2145 * This also implies that s390_process_IRQ must
2146 * terminate synchronously - especially if device
2147 * sensing is required.
2148 */
2149 ioinfo[irq]->ui.flags.s_pend = 1;
2150 ioinfo[irq]->ui.flags.busy = 1;
2151 ioinfo[irq]->ui.flags.doio = 1;
2152
2153 s390_process_IRQ( irq );
2154
2155 ioinfo[irq]->ui.flags.s_pend = 0;
2156 ioinfo[irq]->ui.flags.busy = 0;
2157 ioinfo[irq]->ui.flags.doio = 0;
2158 ioinfo[irq]->ui.flags.repall = 0;
2159 ioinfo[irq]->ui.flags.w4final = 0;
2160
2161 ioinfo[irq]->devstat.flag |= DEVSTAT_FINAL_STATUS;
2162
2163 /*
2164 * In multipath mode a condition code 3 implies the last
2165 * path has gone, except we have previously restricted
2166 * the I/O to a particular path. A condition code 1
2167 * (0 won't occur) results in return code EIO as well
2168 * as 3 with another path than the one used (i.e. path available mask is non-zero).
2169 */
2170 if ( ioinfo[irq]->devstat.ii.irb.scsw.cc == 3 )
2171 {
2172 ret = -ENODEV;
2173 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
2174 ioinfo[irq]->ui.flags.oper = 0;
2175 }
2176 else
2177 {
2178 ret = -EIO;
2179 ioinfo[irq]->devstat.flag &= ~DEVSTAT_NOT_OPER;
2180 ioinfo[irq]->ui.flags.oper = 1;
2181
2182 } /* endif */
2183
2184 break;
2185
2186 case 2 : /* busy */
2187
2188 ret = -EBUSY;
2189 break;
2190
2191 default: /* device not operational */
2192
2193 ret = -ENODEV;
2194 break;
2195
2196 } /* endswitch */
2197
2198 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2199 {
2200 disable_cpu_sync_isc( irq );
2201
2202 } /* endif */
2203
2204 } /* endif */
2205
2206 return( ret );
2207 }
2208
2209 /*
2210 * Note: The "intparm" parameter is not used by the clear_IO() function
2211 * itself, as no ORB is built for the CSCH instruction. However,
2212 * it allows the device interrupt handler to associate the upcoming
2213 * interrupt with the clear_IO() request.
2214 */
2215 int clear_IO( int irq,
2216 unsigned long user_intparm,
2217 unsigned long flag) /* possible DOIO_WAIT_FOR_INTERRUPT */
2218 {
2219 int ret;
2220 int ccode;
2221 char dbf_txt[15];
2222
2223 if ( irq > highest_subchannel || irq < 0 )
2224 {
2225 return -ENODEV;
2226 }
2227
2228 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
2229 {
2230 return( -ENODEV);
2231 }
2232
2233 /*
2234 * we only allow for halt_IO if the device has an I/O handler associated
2235 */
2236 else if ( !ioinfo[irq]->ui.flags.ready )
2237 {
2238 ret = -ENODEV;
2239 }
2240 /*
2241 * we ignore the halt_io() request if ending_status was received but
2242 * a SENSE operation is waiting for completion.
2243 */
2244 else if ( ioinfo[irq]->ui.flags.w4sense )
2245 {
2246 ret = 0;
2247 }
2248 /*
2249 * We don't allow for halt_io with a sync do_IO() requests pending.
2250 * Concurrent I/O is possible in SMP environments only, but the
2251 * sync. I/O request can be gated to one CPU at a time only.
2252 */
2253 else if ( ioinfo[irq]->ui.flags.syncio )
2254 {
2255 ret = -EBUSY;
2256 }
2257 else
2258 {
2259 if (cio_debug_initialized) {
2260 debug_text_event(cio_debug_trace_id, 2, "clearIO");
2261 sprintf(dbf_txt, "%x", irq);
2262 debug_text_event(cio_debug_trace_id, 2, dbf_txt);
2263 }
2264 /*
2265 * If sync processing was requested we lock the sync ISC,
2266 * modify the device to present interrupts for this ISC only
2267 * and switch the CPU to handle this ISC + the console ISC
2268 * exclusively.
2269 */
2270 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2271 {
2272 ret = enable_cpu_sync_isc( irq);
2273
2274 if ( ret )
2275 {
2276 return( ret);
2277
2278 } /* endif */
2279
2280 } /* endif */
2281
2282 /*
2283 * Issue "Halt subchannel" and process condition code
2284 */
2285 ccode = csch( irq );
2286
2287 switch ( ccode ) {
2288 case 0:
2289
2290 ioinfo[irq]->ui.flags.haltio = 1;
2291
2292 if ( !ioinfo[irq]->ui.flags.doio )
2293 {
2294 ioinfo[irq]->ui.flags.busy = 1;
2295 ioinfo[irq]->u_intparm = user_intparm;
2296 ioinfo[irq]->devstat.cstat = 0;
2297 ioinfo[irq]->devstat.dstat = 0;
2298 ioinfo[irq]->devstat.lpum = 0;
2299 ioinfo[irq]->devstat.flag = DEVSTAT_CLEAR_FUNCTION;
2300 ioinfo[irq]->devstat.scnt = 0;
2301
2302 }
2303 else
2304 {
2305 ioinfo[irq]->devstat.flag |= DEVSTAT_CLEAR_FUNCTION;
2306
2307 } /* endif */
2308
2309 /*
2310 * If synchronous I/O processing is requested, we have
2311 * to wait for the corresponding interrupt to occur by
2312 * polling the interrupt condition. However, as multiple
2313 * interrupts may be outstanding, we must not just wait
2314 * for the first interrupt, but must poll until ours
2315 * pops up.
2316 */
2317 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2318 {
2319 int io_sub;
2320 __u32 io_parm;
2321 psw_t io_new_psw;
2322 int ccode;
2323
2324 int ready = 0;
2325 struct _lowcore *lc = NULL;
2326
2327 /*
2328 * We shouldn't perform a TPI loop, waiting for
2329 * an interrupt to occur, but should load a
2330 * WAIT PSW instead. Otherwise we may keep the
2331 * channel subsystem busy, not able to present
2332 * the interrupt. When our sync. interrupt
2333 * arrived we reset the I/O old PSW to its
2334 * original value.
2335 */
2336 memcpy( &io_new_psw,
2337 &lc->io_new_psw,
2338 sizeof(psw_t));
2339
2340 ccode = iac();
2341
2342 switch (ccode) {
2343 case 0: // primary-space
2344 io_sync_wait.mask = _IO_PSW_MASK
2345 | _PSW_PRIM_SPACE_MODE
2346 | _PSW_IO_WAIT;
2347 break;
2348 case 1: // secondary-space
2349 io_sync_wait.mask = _IO_PSW_MASK
2350 | _PSW_SEC_SPACE_MODE
2351 | _PSW_IO_WAIT;
2352 break;
2353 case 2: // access-register
2354 io_sync_wait.mask = _IO_PSW_MASK
2355 | _PSW_ACC_REG_MODE
2356 | _PSW_IO_WAIT;
2357 break;
2358 case 3: // home-space
2359 io_sync_wait.mask = _IO_PSW_MASK
2360 | _PSW_HOME_SPACE_MODE
2361 | _PSW_IO_WAIT;
2362 break;
2363 default:
2364 panic( "halt_IO() : unexpected "
2365 "address-space-control %d\n",
2366 ccode);
2367 break;
2368 } /* endswitch */
2369
2370 io_sync_wait.addr = FIX_PSW(&&cio_wakeup);
2371
2372 /*
2373 * Martin didn't like modifying the new PSW, now we take
2374 * a fast exit in do_IRQ() instead
2375 */
2376 *(__u32 *)__LC_SYNC_IO_WORD = 1;
2377
2378 do
2379 {
2380
2381 __load_psw( io_sync_wait );
2382 cio_wakeup:
2383 io_parm = *(__u32 *)__LC_IO_INT_PARM;
2384 io_sub = (__u32)*(__u16 *)__LC_SUBCHANNEL_NR;
2385
2386 ready = s390_process_IRQ( io_sub );
2387
2388 } while ( !((io_sub == irq) && (ready == 1)) );
2389
2390 *(__u32 *)__LC_SYNC_IO_WORD = 0;
2391
2392 } /* endif */
2393
2394 ret = 0;
2395 break;
2396
2397 case 1 : /* status pending */
2398
2399 ioinfo[irq]->devstat.flag |= DEVSTAT_STATUS_PENDING;
2400
2401 /*
2402 * initialize the device driver specific devstat irb area
2403 */
2404 memset( &ioinfo[irq]->irq_desc.dev_id->ii.irb,
2405 '\0', sizeof( irb_t) );
2406
2407 /*
2408 * Let the common interrupt handler process the pending
2409 * status. However, we must avoid calling the user
2410 * action handler, as it won't be prepared to handle
2411 * a pending status during do_IO() processing inline.
2412 * This also implies that s390_process_IRQ must
2413 * terminate synchronously - especially if device
2414 * sensing is required.
2415 */
2416 ioinfo[irq]->ui.flags.s_pend = 1;
2417 ioinfo[irq]->ui.flags.busy = 1;
2418 ioinfo[irq]->ui.flags.doio = 1;
2419
2420 s390_process_IRQ( irq );
2421
2422 ioinfo[irq]->ui.flags.s_pend = 0;
2423 ioinfo[irq]->ui.flags.busy = 0;
2424 ioinfo[irq]->ui.flags.doio = 0;
2425 ioinfo[irq]->ui.flags.repall = 0;
2426 ioinfo[irq]->ui.flags.w4final = 0;
2427
2428 ioinfo[irq]->devstat.flag |= DEVSTAT_FINAL_STATUS;
2429
2430 /*
2431 * In multipath mode a condition code 3 implies the last
2432 * path has gone, except we have previously restricted
2433 * the I/O to a particular path. A condition code 1
2434 * (0 won't occur) results in return code EIO as well
2435 * as 3 with another path than the one used (i.e. path available mask is non-zero).
2436 */
2437 if ( ioinfo[irq]->devstat.ii.irb.scsw.cc == 3 )
2438 {
2439 ret = -ENODEV;
2440 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
2441 ioinfo[irq]->ui.flags.oper = 0;
2442 }
2443 else
2444 {
2445 ret = -EIO;
2446 ioinfo[irq]->devstat.flag &= ~DEVSTAT_NOT_OPER;
2447 ioinfo[irq]->ui.flags.oper = 1;
2448
2449 } /* endif */
2450
2451 break;
2452
2453 case 2 : /* busy */
2454
2455 ret = -EBUSY;
2456 break;
2457
2458 default: /* device not operational */
2459
2460 ret = -ENODEV;
2461 break;
2462
2463 } /* endswitch */
2464
2465 if ( flag & DOIO_WAIT_FOR_INTERRUPT )
2466 {
2467 disable_cpu_sync_isc( irq );
2468
2469 } /* endif */
2470
2471 } /* endif */
2472
2473 return( ret );
2474 }
2475
2476
2477 /*
2478 * do_IRQ() handles all normal I/O device IRQ's (the special
2479 * SMP cross-CPU interrupts have their own specific
2480 * handlers).
2481 *
2482 */
2483 asmlinkage void do_IRQ( struct pt_regs regs )
2484 {
2485 /*
2486 * Get interrupt info from lowcore
2487 */
2488 volatile tpi_info_t *tpi_info = (tpi_info_t*)(__LC_SUBCHANNEL_ID);
2489 int cpu = smp_processor_id();
2490
2491 /*
2492 * take fast exit if CPU is in sync. I/O state
2493 *
2494 * Note: we have to turn off the WAIT bit and re-disable
2495 * interrupts prior to return as this was the initial
2496 * entry condition to synchronous I/O.
2497 */
2498 if ( *(__u32 *)__LC_SYNC_IO_WORD )
2499 {
2500 regs.psw.mask &= ~(_PSW_WAIT_MASK_BIT | _PSW_IO_MASK_BIT);
2501 return;
2502 } /* endif */
2503
2504 #ifdef CONFIG_FAST_IRQ
2505 do {
2506 #endif /* CONFIG_FAST_IRQ */
2507
2508 /*
2509 * Non I/O-subchannel thin interrupts are processed differently
2510 */
2511 if ( tpi_info->adapter_IO == 1 &&
2512 tpi_info->int_type == IO_INTERRUPT_TYPE )
2513 {
2514 irq_enter(cpu, -1);
2515 do_adapter_IO( tpi_info->intparm );
2516 irq_exit(cpu, -1);
2517 }
2518 else
2519 {
2520 unsigned int irq = tpi_info->irq;
2521
2522 /*
2523 * fix me !!!
2524 *
2525 * instead of boxing the device, we need to schedule device
2526 * recognition, the interrupt stays pending. We need to
2527 * dynamically allocate an ioinfo structure, etc..
2528 */
2529 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
2530 {
2531 return; /* this keeps the device boxed ... */
2532 }
2533
2534 irq_enter(cpu, irq);
2535 s390irq_spin_lock( irq );
2536 s390_process_IRQ( irq );
2537 s390irq_spin_unlock( irq );
2538 irq_exit(cpu, irq);
2539 }
2540
2541 #ifdef CONFIG_FAST_IRQ
2542
2543 /*
2544 * Are more interrupts pending?
2545 * If so, the tpi instruction will update the lowcore
2546 * to hold the info for the next interrupt.
2547 */
2548 } while ( tpi( NULL ) != 0 );
2549
2550 #endif /* CONFIG_FAST_IRQ */
2551
2552 return;
2553 }
2554
2555
2556 /*
2557 * s390_process_IRQ() handles status pending situations and interrupts
2558 *
2559 * Called by : do_IRQ() - for "real" interrupts
2560 * s390_start_IO, halt_IO()
2561 * - status pending cond. after SSCH, or HSCH
2562 * disable_subchannel() - status pending conditions (after MSCH)
2563 *
2564 * Returns: 0 - no ending status received, no further action taken
2565 * 1 - interrupt handler was called with ending status
2566 */
2567 int s390_process_IRQ( unsigned int irq )
2568 {
2569 int ccode; /* cond code from tsch() operation */
2570 int irb_cc; /* cond code from irb */
2571 int sdevstat; /* struct devstat size to copy */
2572 unsigned int fctl; /* function control */
2573 unsigned int stctl; /* status control */
2574 unsigned int actl; /* activity control */
2575 struct pt_regs regs; /* for interface compatibility only */
2576
2577 int issense = 0;
2578 int ending_status = 0;
2579 int allow4handler = 1;
2580 int chnchk = 0;
2581 devstat_t *dp;
2582 devstat_t *udp;
2583
2584 char dbf_txt[15];
2585 #if 0
2586 int cpu = smp_processor_id();
2587
2588 kstat.irqs[cpu][irq]++;
2589 #endif
2590
2591 if (cio_debug_initialized) {
2592 debug_text_event(cio_debug_trace_id, 3, "procIRQ");
2593 sprintf(dbf_txt, "%x", irq);
2594 debug_text_event(cio_debug_trace_id, 3, dbf_txt);
2595 }
2596
2597 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
2598 {
2599 /* we can't properly process the interrupt ... */
2600 tsch( irq, p_init_irb );
2601 return( 1 );
2602
2603 } /* endif */
2604
2605 dp = &ioinfo[irq]->devstat;
2606 udp = ioinfo[irq]->irq_desc.dev_id;
2607
2608
2609 /*
2610 * It might be possible that a device was not-oper. at the time
2611 * of free_irq() processing. This means the handler is no longer
2612 * available when the device possibly becomes ready again. In
2613 * this case we perform delayed disable_subchannel() processing.
2614 */
2615 if ( !ioinfo[irq]->ui.flags.ready )
2616 {
2617 if ( !ioinfo[irq]->ui.flags.d_disable )
2618 {
2619 #ifdef CONFIG_DEBUG_IO
2620 printk( KERN_CRIT"s390_process_IRQ(%04X) "
2621 "- no interrupt handler registered "
2622 "for device %04X !\n",
2623 irq,
2624 ioinfo[irq]->devstat.devno);
2625 #endif /* CONFIG_DEBUG_IO */
2626 if (cio_debug_initialized)
2627 debug_sprintf_event(cio_debug_msg_id, 0,
2628 "s390_process_IRQ(%04X) - no interrupt handler registered for device %04X !\n",
2629 irq, ioinfo[irq]->devstat.devno);
2630 } /* endif */
2631
2632 } /* endif */
2633
2634 /*
2635 * retrieve the i/o interrupt information (irb),
2636 * update the device specific status information
2637 * and possibly call the interrupt handler.
2638 *
2639 * Note 1: At this time we don't process the resulting
2640 * condition code (ccode) from tsch(), although
2641 * we probably should.
2642 *
2643 * Note 2: Here we will have to check for channel
2644 * check conditions and call a channel check
2645 * handler.
2646 *
2647 * Note 3: If a start function was issued, the interruption
2648 * parameter relates to it. If a halt function was
2649 * issued for an idle device, the intparm must not
2650 * be taken from lowcore, but from the devstat area.
2651 */
2652 ccode = tsch( irq, &(dp->ii.irb) );
2653
2654 //
2655 // We must only accumulate the status if the device is busy already
2656 //
2657 if ( ioinfo[irq]->ui.flags.busy )
2658 {
2659 dp->dstat |= dp->ii.irb.scsw.dstat;
2660 dp->cstat |= dp->ii.irb.scsw.cstat;
2661 dp->intparm = ioinfo[irq]->u_intparm;
2662
2663 }
2664 else
2665 {
2666 dp->dstat = dp->ii.irb.scsw.dstat;
2667 dp->cstat = dp->ii.irb.scsw.cstat;
2668
2669 dp->flag = 0; // reset status flags
2670 dp->intparm = 0;
2671
2672 } /* endif */
2673
2674 dp->lpum = dp->ii.irb.esw.esw1.lpum;
2675
2676 /*
2677 * reset device-busy bit if no longer set in irb
2678 */
2679 if ( (dp->dstat & DEV_STAT_BUSY )
2680 && ((dp->ii.irb.scsw.dstat & DEV_STAT_BUSY) == 0))
2681 {
2682 dp->dstat &= ~DEV_STAT_BUSY;
2683
2684 } /* endif */
2685
2686 /*
2687 * Save residual count and CCW information in case primary and
2688 * secondary status are presented with different interrupts.
2689 */
2690 if ( dp->ii.irb.scsw.stctl
2691 & ( SCSW_STCTL_PRIM_STATUS | SCSW_STCTL_INTER_STATUS ) )
2692 {
2693 dp->rescnt = dp->ii.irb.scsw.count;
2694 dp->cpa = dp->ii.irb.scsw.cpa;
2695
2696 #ifdef CONFIG_DEBUG_IO
2697 if ( irq != cons_dev )
2698 printk( "s390_process_IRQ( %04X ) : "
2699 "residual count from irb after tsch() %d\n",
2700 irq, dp->rescnt );
2701 #endif
2702 if (cio_debug_initialized)
2703 debug_sprintf_event(cio_debug_msg_id, 6,
2704 "s390_process_IRQ( %04X ) : residual count from irq after tsch() %d\n",
2705 irq, dp->rescnt);
2706
2707 } /* endif */
2708
2709 irb_cc = dp->ii.irb.scsw.cc;
2710
2711 //
2712 // check for any kind of channel or interface control check but don't
2713 // issue the message for the console device
2714 //
2715 if ( (dp->ii.irb.scsw.cstat
2716 & ( SCHN_STAT_CHN_DATA_CHK
2717 | SCHN_STAT_CHN_CTRL_CHK
2718 | SCHN_STAT_INTF_CTRL_CHK )))
2719 {
2720 if (irq != cons_dev)
2721 printk( "Channel-Check or Interface-Control-Check "
2722 "received\n"
2723 " ... device %04X on subchannel %04X, dev_stat "
2724 ": %02X sch_stat : %02X\n",
2725 ioinfo[irq]->devstat.devno,
2726 irq,
2727 dp->dstat,
2728 dp->cstat);
2729 if (cio_debug_initialized) {
2730 debug_sprintf_event(cio_debug_msg_id, 0,
2731 "Channel-Check or Interface-Control-Check received\n");
2732 debug_sprintf_event(cio_debug_msg_id, 0,
2733 "... device %04X on subchannel %04X, dev_stat: %02X sch_stat: %02X\n",
2734 ioinfo[irq]->devstat.devno, irq, dp->dstat, dp->cstat);
2735 }
2736
2737 chnchk = 1;
2738
2739 } /* endif */
2740
2741 if( dp->ii.irb.scsw.ectl==0)
2742 {
2743 issense=0;
2744 }
2745 else if ( (dp->ii.irb.scsw.stctl == SCSW_STCTL_STATUS_PEND)
2746 && (dp->ii.irb.scsw.eswf == 0 ))
2747 {
2748 issense = 0;
2749 }
2750 else if ( (dp->ii.irb.scsw.stctl ==
2751 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_INTER_STATUS))
2752 && ((dp->ii.irb.scsw.actl & SCSW_ACTL_SUSPENDED) == 0))
2753 {
2754 issense = 0;
2755 }
2756 else
2757 {
2758 issense = dp->ii.irb.esw.esw0.erw.cons;
2759
2760 } /* endif */
2761
2762 if ( issense )
2763 {
2764 dp->scnt = dp->ii.irb.esw.esw0.erw.scnt;
2765 dp->flag |= DEVSTAT_FLAG_SENSE_AVAIL;
2766
2767 sdevstat = sizeof( devstat_t);
2768
2769 #ifdef CONFIG_DEBUG_IO
2770 if ( irq != cons_dev )
2771 printk( "s390_process_IRQ( %04X ) : "
2772 "concurrent sense bytes avail %d\n",
2773 irq, dp->scnt );
2774 #endif
2775 if (cio_debug_initialized)
2776 debug_sprintf_event(cio_debug_msg_id, 4,
2777 "s390_process_IRQ( %04X ): concurrent sense bytes avail %d\n",
2778 irq, dp->scnt);
2779 }
2780 else
2781 {
2782 /* don't copy the sense data area ! */
2783 sdevstat = sizeof( devstat_t) - SENSE_MAX_COUNT;
2784
2785 } /* endif */
2786
2787 switch ( irb_cc ) {
2788 case 1: /* status pending */
2789
2790 dp->flag |= DEVSTAT_STATUS_PENDING;
2791
2792 case 0: /* normal i/o interruption */
2793
2794 fctl = dp->ii.irb.scsw.fctl;
2795 stctl = dp->ii.irb.scsw.stctl;
2796 actl = dp->ii.irb.scsw.actl;
2797
2798 if ( chnchk )
2799 {
2800 char buffer[80];
2801
2802 sprintf( buffer, "s390_process_IRQ(%04X) - irb for "
2803 "device %04X after channel check\n",
2804 irq,
2805 dp->devno );
2806
2807 s390_displayhex( buffer,
2808 &(dp->ii.irb) ,
2809 sizeof(irb_t));
2810 if (cio_debug_initialized) {
2811
2812 sprintf( buffer, "s390_process_IRQ(%04X) - irb for "
2813 "device %04X after channel check\n",
2814 irq,
2815 dp->devno );
2816
2817 s390_displayhex2( buffer,
2818 &(dp->ii.irb) ,
2819 sizeof(irb_t), 0);
2820 }
2821 } /* endif */
2822
2823 ioinfo[irq]->stctl |= stctl;
2824
2825 ending_status = ( stctl & SCSW_STCTL_SEC_STATUS )
2826 || ( stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND) )
2827 || ( (fctl == SCSW_FCTL_HALT_FUNC) && (stctl == SCSW_STCTL_STATUS_PEND) )
2828 || ( (fctl == SCSW_FCTL_CLEAR_FUNC) && (stctl == SCSW_STCTL_STATUS_PEND) );
2829
2830 /*
2831 * Check for unsolicited interrupts - for debug purposes only
2832 *
2833 * We only consider an interrupt as unsolicited, if the device was not
2834 * actively in use (busy) and an interrupt other than an ALERT status
2835 * was received.
2836 *
2837 * Note: We must not issue a message to the console, if the
2838 * unsolicited interrupt applies to the console device
2839 * itself !
2840 */
2841 if ( !( stctl & SCSW_STCTL_ALERT_STATUS )
2842 && ( ioinfo[irq]->ui.flags.busy == 0 ) )
2843 {
2844 char buffer[80];
2845 #ifdef CONFIG_DEBUG_IO
2846 if (irq != cons_dev)
2847 printk( "Unsolicited interrupt received for device %04X on subchannel %04X\n"
2848 " ... device status : %02X subchannel status : %02X\n",
2849 dp->devno,
2850 irq,
2851 dp->dstat,
2852 dp->cstat);
2853
2854 sprintf( buffer, "s390_process_IRQ(%04X) - irb for "
2855 "device %04X, ending_status %d\n",
2856 irq,
2857 dp->devno,
2858 ending_status);
2859
2860 s390_displayhex( buffer,
2861 &(dp->ii.irb) ,
2862 sizeof(irb_t));
2863 #endif
2864 if (cio_debug_initialized) {
2865 debug_sprintf_event(cio_debug_msg_id, 2,
2866 "Unsolicited interrupt received for device %04X on subchannel %04X\n"
2867 " ... device status : %02X subchannel status : %02X\n",
2868 dp->devno,
2869 irq,
2870 dp->dstat,
2871 dp->cstat);
2872 sprintf( buffer, "s390_process_IRQ(%04X) - irb for "
2873 "device %04X, ending_status %d\n",
2874 irq,
2875 dp->devno,
2876 ending_status);
2877
2878 s390_displayhex2( buffer,
2879 &(dp->ii.irb) ,
2880 sizeof(irb_t), 2);
2881 }
2882 } /* endif */
2883
2884 /*
2885 * take fast exit if no handler is available
2886 */
2887 if ( !ioinfo[irq]->ui.flags.ready )
2888 return( ending_status );
2889
2890 /*
2891 * Check whether we must issue a SENSE CCW ourselves if there is no
2892 * concurrent sense facility installed for the subchannel.
2893 *
2894 * Note: We should check for ioinfo[irq]->ui.flags.consns but VM
2895 * violates the ESA/390 architecture and doesn't present an
2896 * operand exception for virtual devices without concurrent
2897 * sense facility available/supported when enabling the
2898 * concurrent sense facility.
2899 */
2900 if ( ( (dp->ii.irb.scsw.dstat & DEV_STAT_UNIT_CHECK )
2901 && (!issense ) )
2902 || (ioinfo[irq]->ui.flags.delsense && ending_status ) )
2903 {
2904 int ret_io;
2905 ccw1_t *s_ccw = &ioinfo[irq]->senseccw;
2906 unsigned long s_flag = 0;
2907
2908 if ( ending_status )
2909 {
2910 /*
2911 * We copy the current status information into the device driver
2912 * status area. Then we can use the local devstat area for device
2913 * sensing. When finally calling the IRQ handler we must not overlay
2914 * the original device status but copy the sense data only.
2915 */
2916 memcpy( udp, dp, sizeof( devstat_t) );
2917
2918 s_ccw->cmd_code = CCW_CMD_BASIC_SENSE;
2919 s_ccw->cda = (__u32)virt_to_phys( ioinfo[irq]->sense_data );
2920 s_ccw->count = SENSE_MAX_COUNT;
2921 s_ccw->flags = CCW_FLAG_SLI;
2922
2923 /*
2924 * If free_irq() or a sync do_IO/s390_start_IO() is in
2925 * process we have to sense synchronously
2926 */
2927 if ( ioinfo[irq]->ui.flags.unready || ioinfo[irq]->ui.flags.syncio )
2928 {
2929 s_flag = DOIO_WAIT_FOR_INTERRUPT;
2930
2931 } /* endif */
2932
2933 /*
2934 * Reset status info
2935 *
2936 * It does not matter whether this is a sync. or async.
2937 * SENSE request, but we have to assure we don't call
2938 * the irq handler now, but keep the irq in busy state.
2939 * In sync. mode s390_process_IRQ() is called recursively,
2940 * while in async. mode we re-enter do_IRQ() with the
2941 * next interrupt.
2942 *
2943 * Note : this may be a delayed sense request !
2944 */
2945 allow4handler = 0;
2946
2947 ioinfo[irq]->ui.flags.fast = 0;
2948 ioinfo[irq]->ui.flags.repall = 0;
2949 ioinfo[irq]->ui.flags.w4final = 0;
2950 ioinfo[irq]->ui.flags.delsense = 0;
2951
2952 dp->cstat = 0;
2953 dp->dstat = 0;
2954 dp->rescnt = SENSE_MAX_COUNT;
2955
2956 ioinfo[irq]->ui.flags.w4sense = 1;
2957
2958 ret_io = s390_start_IO( irq,
2959 s_ccw,
2960 0xE2C5D5E2, // = SENSe
2961 0, // n/a
2962 s_flag);
2963 }
2964 else
2965 {
2966 /*
2967 * we received an Unit Check but we have no final
2968 * status yet, therefore we must delay the SENSE
2969 * processing. However, we must not report this
2970 * intermediate status to the device interrupt
2971 * handler.
2972 */
2973 ioinfo[irq]->ui.flags.fast = 0;
2974 ioinfo[irq]->ui.flags.repall = 0;
2975
2976 ioinfo[irq]->ui.flags.delsense = 1;
2977 allow4handler = 0;
2978
2979 } /* endif */
2980
2981 } /* endif */
2982
2983 /*
2984 * we allow for the device action handler if .
2985 * - we received ending status
2986 * - the action handler requested to see all interrupts
2987 * - we received an intermediate status
2988 * - fast notification was requested (primary status)
2989 * - unsollicited interrupts
2990 *
2991 */
2992 if ( allow4handler )
2993 {
2994 allow4handler = ending_status
2995 || ( ioinfo[irq]->ui.flags.repall )
2996 || ( stctl & SCSW_STCTL_INTER_STATUS )
2997 || ( (ioinfo[irq]->ui.flags.fast ) && (stctl & SCSW_STCTL_PRIM_STATUS) )
2998 || ( ioinfo[irq]->ui.flags.oper == 0 );
2999
3000 } /* endif */
3001
3002 /*
3003 * We used to copy the device status information right before
3004 * calling the device action handler. However, in status
3005 * pending situations during do_IO() or halt_IO(), as well as
3006 * enable_subchannel/disable_subchannel processing we must
3007 * synchronously return the status information and must not
3008 * call the device action handler.
3009 *
3010 */
3011 if ( allow4handler )
3012 {
3013 /*
3014 * if we were waiting for sense data we copy the sense
3015 * bytes only as the original status information was
3016 * saved prior to sense already.
3017 */
3018 if ( ioinfo[irq]->ui.flags.w4sense )
3019 {
3020 int sense_count = SENSE_MAX_COUNT-ioinfo[irq]->devstat.rescnt;
3021
3022 #ifdef CONFIG_DEBUG_IO
3023 if ( irq != cons_dev )
3024 printk( "s390_process_IRQ( %04X ) : "
3025 "BASIC SENSE bytes avail %d\n",
3026 irq, sense_count );
3027 #endif
3028 if (cio_debug_initialized)
3029 debug_sprintf_event(cio_debug_msg_id, 4,
3030 "s390_process_IRQ( %04X ): BASIC SENSE bytes avail %d\n",
3031 irq, sense_count);
3032 ioinfo[irq]->ui.flags.w4sense = 0;
3033 udp->flag |= DEVSTAT_FLAG_SENSE_AVAIL;
3034 udp->scnt = sense_count;
3035
3036 if ( sense_count >= 0 )
3037 {
3038 memcpy( udp->ii.sense.data,
3039 ioinfo[irq]->sense_data,
3040 sense_count);
3041 }
3042 else
3043 {
3044 #if 1
3045 panic( "s390_process_IRQ(%04x) encountered "
3046 "negative sense count\n",
3047 irq);
3048 #else
3049 printk( KERN_CRIT"s390_process_IRQ(%04x) encountered "
3050 "negative sense count\n",
3051 irq);
3052 if (cio_debug_initialized)
3053 debug_sprintf_event(cio_debug_msg_id, 0,
3054 "s390_process_IRQ(%04x) encountered "
3055 "negative sense count\n",
3056 irq);
3057 #endif
3058 } /* endif */
3059 }
3060 else
3061 {
3062 memcpy( udp, dp, sdevstat );
3063
3064 } /* endif */
3065
3066 } /* endif */
3067
3068 /*
3069 * for status pending situations other than deferred interrupt
3070 * conditions detected by s390_process_IRQ() itself we must not
3071 * call the handler. This will synchronously be reported back
3072 * to the caller instead, e.g. when detected during do_IO().
3073 */
3074 if ( ioinfo[irq]->ui.flags.s_pend
3075 || ioinfo[irq]->ui.flags.unready
3076 || ioinfo[irq]->ui.flags.repnone )
3077 {
3078 if ( ending_status )
3079 {
3080
3081 ioinfo[irq]->ui.flags.busy = 0;
3082 ioinfo[irq]->ui.flags.doio = 0;
3083 ioinfo[irq]->ui.flags.haltio = 0;
3084 ioinfo[irq]->ui.flags.fast = 0;
3085 ioinfo[irq]->ui.flags.repall = 0;
3086 ioinfo[irq]->ui.flags.w4final = 0;
3087
3088 dp->flag |= DEVSTAT_FINAL_STATUS;
3089 udp->flag |= DEVSTAT_FINAL_STATUS;
3090
3091 } /* endif */
3092
3093 allow4handler = 0;
3094
3095 } /* endif */
3096
3097 /*
3098 * Call device action handler if applicable
3099 */
3100 if ( allow4handler )
3101 {
3102
3103 /*
3104 * We only reset the busy condition when we are sure that no further
3105 * interrupt is pending for the current I/O request (ending_status).
3106 */
3107 if ( ending_status || !ioinfo[irq]->ui.flags.oper )
3108 {
3109 ioinfo[irq]->ui.flags.oper = 1; /* dev IS oper */
3110
3111 ioinfo[irq]->ui.flags.busy = 0;
3112 ioinfo[irq]->ui.flags.doio = 0;
3113 ioinfo[irq]->ui.flags.haltio = 0;
3114 ioinfo[irq]->ui.flags.fast = 0;
3115 ioinfo[irq]->ui.flags.repall = 0;
3116 ioinfo[irq]->ui.flags.w4final = 0;
3117
3118 dp->flag |= DEVSTAT_FINAL_STATUS;
3119 udp->flag |= DEVSTAT_FINAL_STATUS;
3120
3121 ioinfo[irq]->irq_desc.handler( irq, udp, ®s );
3122
3123 //
3124 // reset intparm after final status or we will badly present unsolicited
3125 // interrupts with a intparm value possibly no longer valid.
3126 //
3127 dp->intparm = 0;
3128
3129 //
3130 // Was there anything queued ? Start the pending channel program
3131 // if there is one.
3132 //
3133 if ( ioinfo[irq]->ui.flags.doio_q )
3134 {
3135 int ret;
3136
3137 ret = s390_start_IO( irq,
3138 ioinfo[irq]->qcpa,
3139 ioinfo[irq]->qintparm,
3140 ioinfo[irq]->qlpm,
3141 ioinfo[irq]->qflag);
3142
3143 ioinfo[irq]->ui.flags.doio_q = 0;
3144
3145 /*
3146 * If s390_start_IO() failed call the device's interrupt
3147 * handler, the IRQ related devstat area was setup by
3148 * s390_start_IO() accordingly already (status pending
3149 * condition).
3150 */
3151 if ( ret )
3152 {
3153 ioinfo[irq]->irq_desc.handler( irq, udp, ®s );
3154
3155 } /* endif */
3156
3157 } /* endif */
3158
3159 }
3160 else
3161 {
3162 ioinfo[irq]->ui.flags.w4final = 1;
3163
3164 /*
3165 * Eventually reset subchannel PCI status and
3166 * set the PCI or SUSPENDED flag in the user
3167 * device status block if appropriate.
3168 */
3169 if ( dp->cstat & SCHN_STAT_PCI )
3170 {
3171 udp->flag |= DEVSTAT_PCI;
3172 dp->cstat &= ~SCHN_STAT_PCI;
3173 }
3174
3175 if ( actl & SCSW_ACTL_SUSPENDED )
3176 {
3177 udp->flag |= DEVSTAT_SUSPENDED;
3178
3179 } /* endif */
3180
3181 ioinfo[irq]->irq_desc.handler( irq, udp, ®s );
3182
3183 } /* endif */
3184
3185 } /* endif */
3186
3187 break;
3188
3189 case 3: /* device/path not operational */
3190
3191 ioinfo[irq]->ui.flags.busy = 0;
3192 ioinfo[irq]->ui.flags.doio = 0;
3193 ioinfo[irq]->ui.flags.haltio = 0;
3194
3195 dp->cstat = 0;
3196 dp->dstat = 0;
3197
3198 if ( ioinfo[irq]->ulpm != ioinfo[irq]->opm )
3199 {
3200 /*
3201 * either it was the only path or it was restricted ...
3202 */
3203 ioinfo[irq]->opm &= ~(ioinfo[irq]->devstat.ii.irb.esw.esw1.lpum);
3204 }
3205 else
3206 {
3207 ioinfo[irq]->opm = 0;
3208
3209 } /* endif */
3210
3211 if ( ioinfo[irq]->opm == 0 )
3212 {
3213 ioinfo[irq]->ui.flags.oper = 0;
3214
3215 } /* endif */
3216
3217 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
3218 ioinfo[irq]->devstat.flag |= DEVSTAT_FINAL_STATUS;
3219
3220 /*
3221 * When we find a device "not oper" we save the status
3222 * information into the device status area and call the
3223 * device specific interrupt handler.
3224 *
3225 * Note: currently we don't have any way to reenable
3226 * the device unless an unsolicited interrupt
3227 * is presented. We don't check for spurious
3228 * interrupts on "not oper" conditions.
3229 */
3230
3231 if ( ( ioinfo[irq]->ui.flags.fast )
3232 && ( ioinfo[irq]->ui.flags.w4final ) )
3233 {
3234 /*
3235 * If a new request was queued already, we have
3236 * to simulate the "not oper" status for the
3237 * queued request by switching the "intparm" value
3238 * and notify the interrupt handler.
3239 */
3240 if ( ioinfo[irq]->ui.flags.doio_q )
3241 {
3242 ioinfo[irq]->devstat.intparm = ioinfo[irq]->qintparm;
3243
3244 } /* endif */
3245
3246 } /* endif */
3247
3248 ioinfo[irq]->ui.flags.fast = 0;
3249 ioinfo[irq]->ui.flags.repall = 0;
3250 ioinfo[irq]->ui.flags.w4final = 0;
3251
3252 /*
3253 * take fast exit if no handler is available
3254 */
3255 if ( !ioinfo[irq]->ui.flags.ready )
3256 return( ending_status );
3257
3258 memcpy( udp, &(ioinfo[irq]->devstat), sdevstat );
3259
3260 ioinfo[irq]->devstat.intparm = 0;
3261
3262 if ( !ioinfo[irq]->ui.flags.s_pend )
3263 {
3264 ioinfo[irq]->irq_desc.handler( irq, udp, ®s );
3265
3266 } /* endif */
3267
3268 ending_status = 1;
3269
3270 break;
3271
3272 } /* endswitch */
3273
3274 return( ending_status );
3275 }
3276
3277 /*
3278 * Set the special i/o-interruption sublass 7 for the
3279 * device specified by parameter irq. There can only
3280 * be a single device been operated on this special
3281 * isc. This function is aimed being able to check
3282 * on special device interrupts in disabled state,
3283 * without having to delay I/O processing (by queueing)
3284 * for non-console devices.
3285 *
3286 * Setting of this isc is done by set_cons_dev(), while
3287 * reset_cons_dev() resets this isc and re-enables the
3288 * default isc3 for this device. wait_cons_dev() allows
3289 * to actively wait on an interrupt for this device in
3290 * disabed state. When the interrupt condition is
3291 * encountered, wait_cons_dev(9 calls do_IRQ() to have
3292 * the console device driver processing the interrupt.
3293 */
3294 int set_cons_dev( int irq )
3295 {
3296 int ccode;
3297 unsigned long cr6 __attribute__ ((aligned (8)));
3298 int rc = 0;
3299 char dbf_txt[15];
3300
3301 if ( cons_dev != -1 )
3302 {
3303 rc = -EBUSY;
3304 }
3305 else if ( (irq > highest_subchannel) || (irq < 0) )
3306 {
3307 rc = -ENODEV;
3308 }
3309 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
3310 {
3311 return( -ENODEV);
3312 }
3313 else
3314 {
3315 if (cio_debug_initialized) {
3316 debug_text_event(cio_debug_trace_id, 4, "scons");
3317 sprintf(dbf_txt, "%x", irq);
3318 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
3319 }
3320
3321 /*
3322 * modify the indicated console device to operate
3323 * on special console interrupt sublass 7
3324 */
3325 ccode = stsch( irq, &(ioinfo[irq]->schib) );
3326
3327 if (ccode)
3328 {
3329 rc = -ENODEV;
3330 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
3331 }
3332 else
3333 {
3334 ioinfo[irq]->schib.pmcw.isc = 7;
3335
3336 ccode = msch( irq, &(ioinfo[irq]->schib) );
3337
3338 if (ccode)
3339 {
3340 rc = -EIO;
3341 }
3342 else
3343 {
3344 cons_dev = irq;
3345
3346 /*
3347 * enable console I/O-interrupt sublass 7
3348 */
3349 __ctl_store( cr6, 6, 6);
3350 cr6 |= 0x01000000;
3351 __ctl_load( cr6, 6, 6);
3352
3353 } /* endif */
3354
3355 } /* endif */
3356
3357 } /* endif */
3358
3359 return( rc);
3360 }
3361
3362 int reset_cons_dev( int irq)
3363 {
3364 int rc = 0;
3365 int ccode;
3366 long cr6 __attribute__ ((aligned (8)));
3367 char dbf_txt[15];
3368
3369 if ( cons_dev != -1 )
3370 {
3371 rc = -EBUSY;
3372 }
3373 else if ( (irq > highest_subchannel) || (irq < 0) )
3374 {
3375 rc = -ENODEV;
3376 }
3377 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
3378 {
3379 return( -ENODEV);
3380 }
3381 else
3382 {
3383 if (cio_debug_initialized) {
3384 debug_text_event(cio_debug_trace_id, 4, "rcons");
3385 sprintf(dbf_txt, "%x", irq);
3386 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
3387 }
3388
3389 /*
3390 * reset the indicated console device to operate
3391 * on default console interrupt sublass 3
3392 */
3393 ccode = stsch( irq, &(ioinfo[irq]->schib) );
3394
3395 if (ccode)
3396 {
3397 rc = -ENODEV;
3398 ioinfo[irq]->devstat.flag |= DEVSTAT_NOT_OPER;
3399 }
3400 else
3401 {
3402
3403 ioinfo[irq]->schib.pmcw.isc = 3;
3404
3405 ccode = msch( irq, &(ioinfo[irq]->schib) );
3406
3407 if (ccode)
3408 {
3409 rc = -EIO;
3410 }
3411 else
3412 {
3413 cons_dev = -1;
3414
3415 /*
3416 * disable special console I/O-interrupt sublass 7
3417 */
3418 __ctl_store( cr6, 6, 6);
3419 cr6 &= 0xFEFFFFFF;
3420 __ctl_load( cr6, 6, 6);
3421
3422 } /* endif */
3423
3424 } /* endif */
3425
3426 } /* endif */
3427
3428 return( rc);
3429 }
3430
3431 int wait_cons_dev( int irq )
3432 {
3433 int rc = 0;
3434 long save_cr6;
3435 char dbf_txt[15];
3436
3437 if ( irq == cons_dev )
3438 {
3439
3440 if (cio_debug_initialized) {
3441 debug_text_event(cio_debug_trace_id, 4, "wcons");
3442 sprintf(dbf_txt, "%x", irq);
3443 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
3444 }
3445
3446 /*
3447 * before entering the spinlock we may already have
3448 * processed the interrupt on a different CPU ...
3449 */
3450 if ( ioinfo[irq]->ui.flags.busy == 1 )
3451 {
3452 long cr6 __attribute__ ((aligned (8)));
3453
3454 /*
3455 * disable all, but isc 7 (console device)
3456 */
3457 __ctl_store( cr6, 6, 6);
3458 save_cr6 = cr6;
3459 cr6 &= 0x01FFFFFF;
3460 __ctl_load( cr6, 6, 6);
3461
3462 do {
3463 tpi_info_t tpi_info = {0,};
3464 if (tpi(&tpi_info) == 1) {
3465 s390_process_IRQ( tpi_info.irq );
3466 } else {
3467 s390irq_spin_unlock(irq);
3468 udelay(100);
3469 s390irq_spin_lock(irq);
3470 }
3471 eieio();
3472 } while (ioinfo[irq]->ui.flags.busy == 1);
3473
3474 /*
3475 * restore previous isc value
3476 */
3477 cr6 = save_cr6;
3478 __ctl_load( cr6, 6, 6);
3479
3480 } /* endif */
3481
3482 }
3483 else
3484 {
3485 rc = EINVAL;
3486
3487 } /* endif */
3488
3489
3490 return(rc);
3491 }
3492
3493
3494 int enable_cpu_sync_isc( int irq )
3495 {
3496 int ccode;
3497 long cr6 __attribute__ ((aligned (8)));
3498
3499 int count = 0;
3500 int rc = 0;
3501 char dbf_txt[15];
3502
3503 if (cio_debug_initialized) {
3504 debug_text_event(cio_debug_trace_id, 4, "enisc");
3505 sprintf(dbf_txt, "%x", irq);
3506 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
3507 }
3508
3509 /* This one spins until it can get the sync_isc lock for irq# irq */
3510
3511 if ( irq <= highest_subchannel && ioinfo[irq] != INVALID_STORAGE_AREA )
3512 {
3513 if ( atomic_read( &sync_isc ) != irq )
3514 atomic_compare_and_swap_spin( -1, irq, &sync_isc );
3515
3516 sync_isc_cnt++;
3517
3518 if ( sync_isc_cnt > 255 ) /* fixme : magic number */
3519 {
3520 panic("Too many recursive calls to enable_sync_isc");
3521
3522 }
3523 /*
3524 * we only run the STSCH/MSCH path for the first enablement
3525 */
3526 else if ( sync_isc_cnt == 1 )
3527 {
3528 ioinfo[irq]->ui.flags.syncio = 1;
3529
3530 ccode = stsch( irq, &(ioinfo[irq]->schib) );
3531
3532 if ( !ccode )
3533 {
3534 ioinfo[irq]->schib.pmcw.isc = 5;
3535
3536 do
3537 {
3538 ccode = msch( irq,
3539 &(ioinfo[irq]->schib) );
3540
3541 if (ccode == 0 )
3542 {
3543 /*
3544 * enable special isc
3545 */
3546 __ctl_store( cr6, 6, 6);
3547 cr6 |= 0x04000000; // enable sync isc 5
3548 cr6 &= 0xEFFFFFFF; // disable standard isc 3
3549 __ctl_load( cr6, 6, 6);
3550 }
3551 else if (ccode == 3)
3552 {
3553 rc = -ENODEV; // very unlikely
3554
3555 }
3556 else if (ccode == 2)
3557 {
3558 rc = -EBUSY; // device busy ...
3559
3560 }
3561 else if (ccode == 1)
3562 {
3563 //
3564 // process pending status
3565 //
3566 ioinfo[irq]->ui.flags.s_pend = 1;
3567
3568 s390_process_IRQ( irq );
3569
3570 ioinfo[irq]->ui.flags.s_pend = 0;
3571
3572 count++;
3573
3574 } /* endif */
3575
3576 } while ( ccode == 1 && count < 3 );
3577
3578 if ( count == 3)
3579 {
3580 rc = -EIO;
3581
3582 } /* endif */
3583 }
3584 else
3585 {
3586 rc = -ENODEV; // device is not-operational
3587
3588 } /* endif */
3589
3590 } /* endif */
3591
3592
3593 if ( rc ) /* can only happen if stsch/msch fails */
3594 {
3595 sync_isc_cnt = 0;
3596 atomic_set( &sync_isc, -1);
3597 }
3598 }
3599 else
3600 {
3601 #ifdef CONFIG_SYNC_ISC_PARANOIA
3602 panic( "enable_sync_isc: called with invalid %x\n", irq );
3603 #endif
3604
3605 rc = -EINVAL;
3606
3607 } /* endif */
3608
3609 return( rc);
3610 }
3611
3612 int disable_cpu_sync_isc( int irq)
3613 {
3614 int rc = 0;
3615 int retry1 = 5;
3616 int retry2 = 5;
3617 int clear_pend = 0;
3618
3619 int ccode;
3620 long cr6 __attribute__ ((aligned (8)));
3621
3622 char dbf_txt[15];
3623
3624 if (cio_debug_initialized) {
3625 debug_text_event(cio_debug_trace_id, 4, "disisc");
3626 sprintf(dbf_txt, "%x", irq);
3627 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
3628 }
3629
3630 if ( irq <= highest_subchannel && ioinfo[irq] != INVALID_STORAGE_AREA )
3631 {
3632 /*
3633 * We disable if we're the top user only, as we may
3634 * run recursively ...
3635 * We must not decrease the count immediately; during
3636 * msch() processing we may face another pending
3637 * status we have to process recursively (sync).
3638 */
3639
3640 #ifdef CONFIG_SYNC_ISC_PARANOIA
3641 if ( atomic_read( &sync_isc ) != irq )
3642 panic( "disable_sync_isc: called for %x while %x locked\n",
3643 irq, atomic_read( &sync_isc ) );
3644 #endif
3645
3646 if ( sync_isc_cnt == 1 )
3647 {
3648 ccode = stsch( irq, &(ioinfo[irq]->schib) );
3649
3650 ioinfo[irq]->schib.pmcw.isc = 3;
3651
3652 do
3653 {
3654 do
3655 {
3656 ccode = msch( irq, &(ioinfo[irq]->schib) );
3657
3658 switch ( ccode ) {
3659 case 0:
3660 /*
3661 * disable special interrupt subclass in CPU
3662 */
3663 __ctl_store( cr6, 6, 6);
3664 cr6 &= 0xFBFFFFFF; // disable sync isc 5
3665 cr6 |= 0x10000000; // enable standard isc 3
3666 __ctl_load( cr6, 6, 6);
3667 break;
3668 case 1:
3669 ioinfo[irq]->ui.flags.s_pend = 1;
3670 s390_process_IRQ( irq );
3671 ioinfo[irq]->ui.flags.s_pend = 0;
3672 retry2--;
3673 break;
3674 case 2:
3675 retry2--;
3676 udelay( 100); // give it time
3677 break;
3678 default:
3679 retry2 = 0;
3680 break;
3681 } /* endswitch */
3682
3683 } while ( retry2 && (ccode != 0) );
3684
3685 retry1--;
3686
3687 /* try stopping it ... */
3688 if ( (ccode) && !clear_pend )
3689 {
3690 clear_IO( irq, 0x00004711, 0 );
3691 clear_pend = 1;
3692
3693 } /* endif */
3694
3695 udelay( 100);
3696
3697 } while ( retry1 && ccode );
3698
3699 ioinfo[irq]->ui.flags.syncio = 0;
3700
3701 sync_isc_cnt = 0;
3702 atomic_set( &sync_isc, -1);
3703
3704 }
3705 else
3706 {
3707 sync_isc_cnt--;
3708
3709 } /* endif */
3710 }
3711 else
3712 {
3713 #ifdef CONFIG_SYNC_ISC_PARANOIA
3714 if ( atomic_read( &sync_isc ) != -1 )
3715 panic( "disable_sync_isc: called with invalid %x while %x locked\n",
3716 irq, atomic_read( &sync_isc ) );
3717 #endif
3718
3719 rc = -EINVAL;
3720
3721 } /* endif */
3722
3723 return( rc);
3724 }
3725
3726 //
3727 // Input :
3728 // devno - device number
3729 // ps - pointer to sense ID data area
3730 //
3731 // Output : none
3732 //
3733 void VM_virtual_device_info( __u16 devno,
3734 senseid_t *ps )
3735 {
3736 diag210_t *p_diag_data;
3737 int ccode;
3738
3739 int error = 0;
3740
3741 if (cio_debug_initialized)
3742 debug_text_event(cio_debug_trace_id, 4, "VMvdinf");
3743
3744 if ( init_IRQ_complete )
3745 {
3746 p_diag_data = kmalloc( sizeof( diag210_t), GFP_DMA );
3747 }
3748 else
3749 {
3750 p_diag_data = alloc_bootmem_low( sizeof( diag210_t));
3751
3752 } /* endif */
3753
3754 p_diag_data->vrdcdvno = devno;
3755 p_diag_data->vrdclen = sizeof( diag210_t);
3756 ccode = diag210( (diag210_t *)virt_to_phys( p_diag_data ) );
3757 ps->reserved = 0xff;
3758
3759 switch (p_diag_data->vrdcvcla) {
3760 case 0x80:
3761
3762 switch (p_diag_data->vrdcvtyp) {
3763 case 00:
3764
3765 ps->cu_type = 0x3215;
3766
3767 break;
3768
3769 default:
3770
3771 error = 1;
3772
3773 break;
3774
3775 } /* endswitch */
3776
3777 break;
3778
3779 case 0x40:
3780
3781 switch (p_diag_data->vrdcvtyp) {
3782 case 0xC0:
3783
3784 ps->cu_type = 0x5080;
3785
3786 break;
3787
3788 case 0x80:
3789
3790 ps->cu_type = 0x2250;
3791
3792 break;
3793
3794 case 0x04:
3795
3796 ps->cu_type = 0x3277;
3797
3798 break;
3799
3800 case 0x01:
3801
3802 ps->cu_type = 0x3278;
3803
3804 break;
3805
3806 default:
3807
3808 error = 1;
3809
3810 break;
3811
3812 } /* endswitch */
3813
3814 break;
3815
3816 case 0x20:
3817
3818 switch (p_diag_data->vrdcvtyp) {
3819 case 0x84:
3820
3821 ps->cu_type = 0x3505;
3822
3823 break;
3824
3825 case 0x82:
3826
3827 ps->cu_type = 0x2540;
3828
3829 break;
3830
3831 case 0x81:
3832
3833 ps->cu_type = 0x2501;
3834
3835 break;
3836
3837 default:
3838
3839 error = 1;
3840
3841 break;
3842
3843 } /* endswitch */
3844
3845 break;
3846
3847 case 0x10:
3848
3849 switch (p_diag_data->vrdcvtyp) {
3850 case 0x84:
3851
3852 ps->cu_type = 0x3525;
3853
3854 break;
3855
3856 case 0x82:
3857
3858 ps->cu_type = 0x2540;
3859
3860 break;
3861
3862 case 0x4F:
3863 case 0x4E:
3864 case 0x48:
3865
3866 ps->cu_type = 0x3820;
3867
3868 break;
3869
3870 case 0x4D:
3871 case 0x49:
3872 case 0x45:
3873
3874 ps->cu_type = 0x3800;
3875
3876 break;
3877
3878 case 0x4B:
3879
3880 ps->cu_type = 0x4248;
3881
3882 break;
3883
3884 case 0x4A:
3885
3886 ps->cu_type = 0x4245;
3887
3888 break;
3889
3890 case 0x47:
3891
3892 ps->cu_type = 0x3262;
3893
3894 break;
3895
3896 case 0x43:
3897
3898 ps->cu_type = 0x3203;
3899
3900 break;
3901
3902 case 0x42:
3903
3904 ps->cu_type = 0x3211;
3905
3906 break;
3907
3908 case 0x41:
3909
3910 ps->cu_type = 0x1403;
3911
3912 break;
3913
3914 default:
3915
3916 error = 1;
3917
3918 break;
3919
3920 } /* endswitch */
3921
3922 break;
3923
3924 case 0x08:
3925
3926 switch (p_diag_data->vrdcvtyp) {
3927 case 0x82:
3928
3929 ps->cu_type = 0x3422;
3930
3931 break;
3932
3933 case 0x81:
3934
3935 ps->cu_type = 0x3490;
3936
3937 break;
3938
3939 case 0x10:
3940
3941 ps->cu_type = 0x3420;
3942
3943 break;
3944
3945 case 0x02:
3946
3947 ps->cu_type = 0x3430;
3948
3949 break;
3950
3951 case 0x01:
3952
3953 ps->cu_type = 0x3480;
3954
3955 break;
3956
3957 case 0x42:
3958
3959 ps->cu_type = 0x3424;
3960
3961 break;
3962
3963 case 0x44:
3964
3965 ps->cu_type = 0x9348;
3966
3967 break;
3968
3969 default:
3970
3971 error = 1;
3972
3973 break;
3974
3975 } /* endswitch */
3976
3977 break;
3978
3979 case 02: /* special device class ... */
3980
3981 switch (p_diag_data->vrdcvtyp) {
3982 case 0x20: /* OSA */
3983
3984 ps->cu_type = 0x3088;
3985 ps->cu_model = 0x60;
3986
3987 break;
3988
3989 default:
3990
3991 error = 1;
3992 break;
3993
3994 } /* endswitch */
3995
3996 break;
3997
3998 default:
3999
4000 error = 1;
4001
4002 break;
4003
4004 } /* endswitch */
4005
4006 if ( init_IRQ_complete )
4007 {
4008 kfree( p_diag_data );
4009 }
4010 else
4011 {
4012 free_bootmem( (unsigned long)p_diag_data, sizeof( diag210_t) );
4013
4014 } /* endif */
4015
4016 if ( error )
4017 {
4018 printk( "DIAG X'210' for "
4019 "device %04X returned "
4020 "(cc = %d): vdev class : %02X, "
4021 "vdev type : %04X \n ... rdev class : %02X, rdev type : %04X, rdev model: %02X\n",
4022 devno,
4023 ccode,
4024 p_diag_data->vrdcvcla,
4025 p_diag_data->vrdcvtyp,
4026 p_diag_data->vrdcrccl,
4027 p_diag_data->vrdccrty,
4028 p_diag_data->vrdccrmd );
4029 if (cio_debug_initialized)
4030 debug_sprintf_event( cio_debug_msg_id, 0,
4031 "DIAG X'210' for "
4032 "device %04X returned "
4033 "(cc = %d): vdev class : %02X, "
4034 "vdev type : %04X \n ... rdev class : %02X, rdev type : %04X, rdev model: %02X\n",
4035 devno,
4036 ccode,
4037 p_diag_data->vrdcvcla,
4038 p_diag_data->vrdcvtyp,
4039 p_diag_data->vrdcrccl,
4040 p_diag_data->vrdccrty,
4041 p_diag_data->vrdccrmd );
4042
4043 } /* endif */
4044
4045 }
4046
4047 /*
4048 * This routine returns the characteristics for the device
4049 * specified. Some old devices might not provide the necessary
4050 * command code information during SenseID processing. In this
4051 * case the function returns -EINVAL. Otherwise the function
4052 * allocates a decice specific data buffer and provides the
4053 * device characteristics together with the buffer size. Its
4054 * the callers responability to release the kernel memory if
4055 * not longer needed. In case of persistent I/O problems -EBUSY
4056 * is returned.
4057 *
4058 * The function may be called enabled or disabled. However, the
4059 * caller must have locked the irq it is requesting data for.
4060 *
4061 * Note : It would have been nice to collect this information
4062 * during init_IRQ() processing but this is not possible
4063 *
4064 * a) without statically pre-allocation fixed size buffers
4065 * as virtual memory management isn't available yet.
4066 *
4067 * b) without unnecessarily increase system startup by
4068 * evaluating devices eventually not used at all.
4069 */
4070 int read_dev_chars( int irq, void **buffer, int length )
4071 {
4072 unsigned int flags;
4073 ccw1_t *rdc_ccw;
4074 devstat_t devstat;
4075 char *rdc_buf;
4076 int devflag;
4077
4078 int ret = 0;
4079 int emulated = 0;
4080 int retry = 5;
4081
4082 char dbf_txt[15];
4083
4084 if ( !buffer || !length )
4085 {
4086 return( -EINVAL );
4087
4088 } /* endif */
4089
4090 if ( (irq > highest_subchannel) || (irq < 0 ) )
4091 {
4092 return( -ENODEV );
4093
4094 }
4095 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
4096 {
4097 return( -ENODEV);
4098 }
4099
4100 if ( ioinfo[irq]->ui.flags.oper == 0 )
4101 {
4102 return( -ENODEV );
4103
4104 } /* endif */
4105
4106 if (cio_debug_initialized) {
4107 debug_text_event(cio_debug_trace_id, 4, "rddevch");
4108 sprintf(dbf_txt, "%x", irq);
4109 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
4110 }
4111
4112 /*
4113 * Before playing around with irq locks we should assure
4114 * running disabled on (just) our CPU. Sync. I/O requests
4115 * also require to run disabled.
4116 *
4117 * Note : as no global lock is required, we must not use
4118 * cli(), but __cli() instead.
4119 */
4120 __save_flags(flags);
4121 __cli();
4122
4123 rdc_ccw = &ioinfo[irq]->senseccw;
4124
4125 if ( !ioinfo[irq]->ui.flags.ready )
4126 {
4127 ret = request_irq( irq,
4128 init_IRQ_handler,
4129 0, "RDC", &devstat );
4130
4131 if ( !ret )
4132 {
4133 emulated = 1;
4134
4135 } /* endif */
4136
4137 } /* endif */
4138
4139 if ( !ret )
4140 {
4141 if ( ! *buffer )
4142 {
4143 rdc_buf = kmalloc( length, GFP_KERNEL);
4144 }
4145 else
4146 {
4147 rdc_buf = *buffer;
4148
4149 } /* endif */
4150
4151 if ( !rdc_buf )
4152 {
4153 ret = -ENOMEM;
4154 }
4155 else
4156 {
4157 do
4158 {
4159 rdc_ccw->cmd_code = CCW_CMD_RDC;
4160 rdc_ccw->count = length;
4161 rdc_ccw->flags = CCW_FLAG_SLI;
4162 set_normalized_cda( rdc_ccw, (unsigned long)rdc_buf );
4163
4164 memset( ioinfo[irq]->irq_desc.dev_id,
4165 '\0',
4166 sizeof( devstat_t));
4167
4168 ret = s390_start_IO( irq,
4169 rdc_ccw,
4170 0x00524443, // RDC
4171 0, // n/a
4172 DOIO_WAIT_FOR_INTERRUPT
4173 | DOIO_DONT_CALL_INTHDLR );
4174 retry--;
4175 devflag = ioinfo[irq]->irq_desc.dev_id->flag;
4176
4177 clear_normalized_cda( rdc_ccw);
4178
4179 } while ( ( retry )
4180 && ( ret || (devflag & DEVSTAT_STATUS_PENDING) ) );
4181
4182 } /* endif */
4183
4184 if ( !retry )
4185 {
4186 ret = -EBUSY;
4187
4188 } /* endif */
4189
4190 __restore_flags(flags);
4191
4192 /*
4193 * on success we update the user input parms
4194 */
4195 if ( !ret )
4196 {
4197 *buffer = rdc_buf;
4198
4199 } /* endif */
4200
4201 if ( emulated )
4202 {
4203 free_irq( irq, &devstat);
4204
4205 } /* endif */
4206
4207 } /* endif */
4208
4209 return( ret );
4210 }
4211
4212 /*
4213 * Read Configuration data
4214 */
4215 int read_conf_data( int irq, void **buffer, int *length, __u8 lpm )
4216 {
4217 unsigned long flags;
4218 int ciw_cnt;
4219
4220 int found = 0; // RCD CIW found
4221 int ret = 0; // return code
4222
4223 char dbf_txt[15];
4224
4225 if ( (irq > highest_subchannel) || (irq < 0 ) )
4226 {
4227 return( -ENODEV );
4228 }
4229 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
4230 {
4231 return( -ENODEV);
4232 }
4233 else if ( !buffer || !length )
4234 {
4235 return( -EINVAL);
4236 }
4237 else if ( ioinfo[irq]->ui.flags.oper == 0 )
4238 {
4239 return( -ENODEV );
4240 }
4241 else if ( ioinfo[irq]->ui.flags.esid == 0 )
4242 {
4243 return( -EOPNOTSUPP );
4244
4245 } /* endif */
4246
4247 if (cio_debug_initialized) {
4248 debug_text_event(cio_debug_trace_id, 4, "rdconf");
4249 sprintf(dbf_txt, "%x", irq);
4250 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
4251 }
4252
4253 /*
4254 * scan for RCD command in extended SenseID data
4255 */
4256
4257 for ( ciw_cnt = 0; (found == 0) && (ciw_cnt < 62); ciw_cnt++ )
4258 {
4259 if ( ioinfo[irq]->senseid.ciw[ciw_cnt].ct == CIW_TYPE_RCD )
4260 {
4261 /*
4262 * paranoia check ...
4263 */
4264 if ( ioinfo[irq]->senseid.ciw[ciw_cnt].cmd != 0 )
4265 {
4266 found = 1;
4267
4268 } /* endif */
4269
4270 break;
4271
4272 } /* endif */
4273
4274 } /* endfor */
4275
4276 if ( found )
4277 {
4278 devstat_t devstat; /* inline device status area */
4279 devstat_t *pdevstat;
4280 int ioflags;
4281
4282 ccw1_t *rcd_ccw = &ioinfo[irq]->senseccw;
4283 char *rcd_buf = NULL;
4284 int emulated = 0; /* no i/O handler installed */
4285 int retry = 5; /* retry count */
4286
4287 __save_flags(flags);
4288 __cli();
4289
4290 if ( !ioinfo[irq]->ui.flags.ready )
4291 {
4292 pdevstat = &devstat;
4293 ret = request_irq( irq,
4294 init_IRQ_handler,
4295 0, "RCD", pdevstat );
4296
4297 if ( !ret )
4298 {
4299 emulated = 1;
4300
4301 } /* endif */
4302 }
4303 else
4304 {
4305 pdevstat = ioinfo[irq]->irq_desc.dev_id;
4306
4307 } /* endif */
4308
4309 if ( !ret )
4310 {
4311 if ( init_IRQ_complete )
4312 {
4313 rcd_buf = kmalloc( ioinfo[irq]->senseid.ciw[ciw_cnt].count,
4314 GFP_DMA);
4315 }
4316 else
4317 {
4318 rcd_buf = alloc_bootmem_low( ioinfo[irq]->senseid.ciw[ciw_cnt].count);
4319
4320 } /* endif */
4321
4322 if ( rcd_buf == NULL )
4323 {
4324 ret = -ENOMEM;
4325
4326 } /* endif */
4327
4328 if ( !ret )
4329 {
4330 memset( rcd_buf,
4331 '\0',
4332 ioinfo[irq]->senseid.ciw[ciw_cnt].count);
4333
4334 do
4335 {
4336 rcd_ccw->cmd_code = ioinfo[irq]->senseid.ciw[ciw_cnt].cmd;
4337 rcd_ccw->cda = (__u32)virt_to_phys( rcd_buf );
4338 rcd_ccw->count = ioinfo[irq]->senseid.ciw[ciw_cnt].count;
4339 rcd_ccw->flags = CCW_FLAG_SLI;
4340
4341 memset( pdevstat, '\0', sizeof( devstat_t));
4342
4343 if ( lpm )
4344 {
4345 ioflags = DOIO_WAIT_FOR_INTERRUPT
4346 | DOIO_VALID_LPM
4347 | DOIO_DONT_CALL_INTHDLR;
4348 }
4349 else
4350 {
4351 ioflags = DOIO_WAIT_FOR_INTERRUPT
4352 | DOIO_DONT_CALL_INTHDLR;
4353
4354 } /* endif */
4355
4356 ret = s390_start_IO( irq,
4357 rcd_ccw,
4358 0x00524344, // == RCD
4359 lpm,
4360 ioflags );
4361
4362 switch ( ret ) {
4363 case 0 :
4364 case -EIO :
4365
4366 if ( !(pdevstat->flag & ( DEVSTAT_STATUS_PENDING
4367 | DEVSTAT_NOT_OPER
4368 | DEVSTAT_FLAG_SENSE_AVAIL ) ) )
4369 {
4370 retry = 0; // we got it ...
4371 }
4372 else
4373 {
4374 retry--; // try again ...
4375
4376 } /* endif */
4377
4378 break;
4379
4380 default : // -EBUSY, -ENODEV, ???
4381 retry = 0;
4382
4383 } /* endswitch */
4384
4385 } while ( retry );
4386
4387 } /* endif */
4388
4389 __restore_flags( flags );
4390
4391 } /* endif */
4392
4393 /*
4394 * on success we update the user input parms
4395 */
4396 if ( ret == 0 )
4397 {
4398 *length = ioinfo[irq]->senseid.ciw[ciw_cnt].count;
4399 *buffer = rcd_buf;
4400 }
4401 else
4402 {
4403 if ( rcd_buf != NULL )
4404 {
4405 if ( init_IRQ_complete )
4406 {
4407 kfree( rcd_buf );
4408 }
4409 else
4410 {
4411 free_bootmem( (unsigned long)rcd_buf,
4412 ioinfo[irq]->senseid.ciw[ciw_cnt].count);
4413
4414 } /* endif */
4415
4416 } /* endif */
4417
4418 *buffer = NULL;
4419 *length = 0;
4420
4421 } /* endif */
4422
4423 if ( emulated )
4424 free_irq( irq, pdevstat);
4425 }
4426 else
4427 {
4428 ret = -EOPNOTSUPP;
4429
4430 } /* endif */
4431
4432 return( ret );
4433
4434 }
4435
4436 int get_dev_info( int irq, s390_dev_info_t * pdi)
4437 {
4438 return( get_dev_info_by_irq( irq, pdi));
4439 }
4440
4441 static int __inline__ get_next_available_irq( ioinfo_t *pi)
4442 {
4443 int ret_val;
4444
4445 while ( TRUE )
4446 {
4447 if ( pi->ui.flags.oper )
4448 {
4449 ret_val = pi->irq;
4450 break;
4451 }
4452 else
4453 {
4454 pi = pi->next;
4455
4456 //
4457 // leave at end of list unconditionally
4458 //
4459 if ( pi == NULL )
4460 {
4461 ret_val = -ENODEV;
4462 break;
4463 }
4464
4465 } /* endif */
4466
4467 } /* endwhile */
4468
4469 return ret_val;
4470 }
4471
4472
4473 int get_irq_first( void )
4474 {
4475 int ret_irq;
4476
4477 if ( ioinfo_head )
4478 {
4479 if ( ioinfo_head->ui.flags.oper )
4480 {
4481 ret_irq = ioinfo_head->irq;
4482 }
4483 else if ( ioinfo_head->next )
4484 {
4485 ret_irq = get_next_available_irq( ioinfo_head->next );
4486
4487 }
4488 else
4489 {
4490 ret_irq = -ENODEV;
4491
4492 } /* endif */
4493 }
4494 else
4495 {
4496 ret_irq = -ENODEV;
4497
4498 } /* endif */
4499
4500 return ret_irq;
4501 }
4502
4503 int get_irq_next( int irq )
4504 {
4505 int ret_irq;
4506
4507 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
4508 {
4509 if ( ioinfo[irq]->next )
4510 {
4511 if ( ioinfo[irq]->next->ui.flags.oper )
4512 {
4513 ret_irq = ioinfo[irq]->next->irq;
4514 }
4515 else
4516 {
4517 ret_irq = get_next_available_irq( ioinfo[irq]->next );
4518
4519 } /* endif */
4520 }
4521 else
4522 {
4523 ret_irq = -ENODEV;
4524
4525 } /* endif */
4526 }
4527 else
4528 {
4529 ret_irq = -EINVAL;
4530
4531 } /* endif */
4532
4533 return ret_irq;
4534 }
4535
4536 int get_dev_info_by_irq( int irq, s390_dev_info_t *pdi)
4537 {
4538
4539 if ( irq > highest_subchannel || irq < 0 )
4540 {
4541 return -ENODEV;
4542 }
4543 else if ( pdi == NULL )
4544 {
4545 return -EINVAL;
4546 }
4547 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
4548 {
4549 return( -ENODEV);
4550 }
4551 else
4552 {
4553 pdi->devno = ioinfo[irq]->schib.pmcw.dev;
4554 pdi->irq = irq;
4555
4556 if ( ioinfo[irq]->ui.flags.oper
4557 && !ioinfo[irq]->ui.flags.unknown )
4558 {
4559 pdi->status = 0;
4560 memcpy( &(pdi->sid_data),
4561 &ioinfo[irq]->senseid,
4562 sizeof( senseid_t));
4563 }
4564 else if ( ioinfo[irq]->ui.flags.unknown )
4565 {
4566 pdi->status = DEVSTAT_UNKNOWN_DEV;
4567 memset( &(pdi->sid_data),
4568 '\0',
4569 sizeof( senseid_t));
4570 pdi->sid_data.cu_type = 0xFFFF;
4571
4572 }
4573 else
4574 {
4575 pdi->status = DEVSTAT_NOT_OPER;
4576 memset( &(pdi->sid_data),
4577 '\0',
4578 sizeof( senseid_t));
4579 pdi->sid_data.cu_type = 0xFFFF;
4580
4581 } /* endif */
4582
4583 if ( ioinfo[irq]->ui.flags.ready )
4584 pdi->status |= DEVSTAT_DEVICE_OWNED;
4585
4586 } /* endif */
4587
4588 return 0;
4589 }
4590
4591
4592 int get_dev_info_by_devno( __u16 devno, s390_dev_info_t *pdi)
4593 {
4594 int i;
4595 int rc = -ENODEV;
4596
4597 if ( devno > 0x0000ffff )
4598 {
4599 return -ENODEV;
4600 }
4601 else if ( pdi == NULL )
4602 {
4603 return -EINVAL;
4604 }
4605 else
4606 {
4607
4608 for ( i=0; i <= highest_subchannel; i++ )
4609 {
4610
4611 if ( ioinfo[i] != INVALID_STORAGE_AREA
4612 && ioinfo[i]->schib.pmcw.dev == devno )
4613 {
4614
4615 pdi->irq = i;
4616 pdi->devno = devno;
4617
4618 if ( ioinfo[i]->ui.flags.oper
4619 && !ioinfo[i]->ui.flags.unknown )
4620 {
4621 pdi->status = 0;
4622
4623 memcpy( &(pdi->sid_data),
4624 &ioinfo[i]->senseid,
4625 sizeof( senseid_t));
4626 }
4627 else if ( ioinfo[i]->ui.flags.unknown )
4628 {
4629 pdi->status = DEVSTAT_UNKNOWN_DEV;
4630
4631 memset( &(pdi->sid_data),
4632 '\0',
4633 sizeof( senseid_t));
4634
4635 pdi->sid_data.cu_type = 0xFFFF;
4636 }
4637 else
4638 {
4639 pdi->status = DEVSTAT_NOT_OPER;
4640
4641 memset( &(pdi->sid_data),
4642 '\0',
4643 sizeof( senseid_t));
4644
4645 pdi->sid_data.cu_type = 0xFFFF;
4646
4647 } /* endif */
4648
4649 if ( ioinfo[i]->ui.flags.ready )
4650 pdi->status |= DEVSTAT_DEVICE_OWNED;
4651
4652 rc = 0; /* found */
4653 break;
4654
4655 } /* endif */
4656
4657 } /* endfor */
4658
4659 return( rc);
4660
4661 } /* endif */
4662
4663 }
4664
4665 int get_irq_by_devno( __u16 devno )
4666 {
4667 int i;
4668 int rc = -1;
4669
4670 if ( devno <= 0x0000ffff )
4671 {
4672 for ( i=0; i <= highest_subchannel; i++ )
4673 {
4674 if ( (ioinfo[i] != INVALID_STORAGE_AREA )
4675 && (ioinfo[i]->schib.pmcw.dev == devno)
4676 && (ioinfo[i]->schib.pmcw.dnv == 1 ) )
4677 {
4678 rc = i;
4679 break;
4680
4681 } /* endif */
4682
4683 } /* endfor */
4684
4685 } /* endif */
4686
4687 return( rc);
4688 }
4689
4690 unsigned int get_devno_by_irq( int irq )
4691 {
4692
4693 if ( ( irq > highest_subchannel )
4694 || ( irq < 0 )
4695 || ( ioinfo[irq] == INVALID_STORAGE_AREA ) )
4696 {
4697 return -1;
4698
4699 } /* endif */
4700
4701 /*
4702 * we don't need to check for the device be operational
4703 * as the initial STSCH will always present the device
4704 * number defined by the IOCDS regardless of the device
4705 * existing or not. However, there could be subchannels
4706 * defined who's device number isn't valid ...
4707 */
4708 if ( ioinfo[irq]->schib.pmcw.dnv )
4709 return( ioinfo[irq]->schib.pmcw.dev );
4710 else
4711 return -1;
4712 }
4713
4714 /*
4715 * s390_device_recognition_irq
4716 *
4717 * Used for individual device recognition. Issues the device
4718 * independant SenseID command to obtain info the device type.
4719 *
4720 */
4721 void s390_device_recognition_irq( int irq )
4722 {
4723 int ret;
4724 char dbf_txt[15];
4725
4726 if (cio_debug_initialized) {
4727 debug_text_event(cio_debug_trace_id, 4, "devrec");
4728 sprintf(dbf_txt, "%x", irq);
4729 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
4730 }
4731
4732 /*
4733 * We issue the SenseID command on I/O subchannels we think are
4734 * operational only.
4735 */
4736 if ( ( ioinfo[irq] != INVALID_STORAGE_AREA )
4737 && ( ioinfo[irq]->schib.pmcw.st == 0 )
4738 && ( ioinfo[irq]->ui.flags.oper == 1 ) )
4739 {
4740 int irq_ret;
4741 devstat_t devstat;
4742
4743 irq_ret = request_irq( irq,
4744 init_IRQ_handler,
4745 0,
4746 "INIT",
4747 &devstat);
4748
4749 if ( !irq_ret )
4750 {
4751 ret = enable_cpu_sync_isc( irq );
4752
4753 if ( !ret )
4754 {
4755 ioinfo[irq]->ui.flags.unknown = 0;
4756
4757 memset( &ioinfo[irq]->senseid, '\0', sizeof( senseid_t));
4758
4759 s390_SenseID( irq, &ioinfo[irq]->senseid, 0xff );
4760 #if 0 /* FIXME */
4761 /*
4762 * We initially check the configuration data for
4763 * those devices with more than a single path
4764 */
4765 if ( ioinfo[irq]->schib.pmcw.pim != 0x80 )
4766 {
4767 char *prcd;
4768 int lrcd;
4769
4770 ret = read_conf_data( irq, (void **)&prcd, &lrcd, 0 );
4771
4772 if ( !ret ) // on success only ...
4773 {
4774 char buffer[80];
4775 #ifdef CONFIG_DEBUG_IO
4776 sprintf( buffer,
4777 "RCD for device(%04X)/"
4778 "subchannel(%04X) returns :\n",
4779 ioinfo[irq]->schib.pmcw.dev,
4780 irq );
4781
4782 s390_displayhex( buffer, prcd, lrcd );
4783 #endif
4784 if (cio_debug_initialized) {
4785 sprintf( buffer,
4786 "RCD for device(%04X)/"
4787 "subchannel(%04X) returns :\n",
4788 ioinfo[irq]->schib.pmcw.dev,
4789 irq );
4790
4791 s390_displayhex2( buffer, prcd, lrcd, 2);
4792 }
4793 if ( init_IRQ_complete )
4794 {
4795 kfree( prcd );
4796 }
4797 else
4798 {
4799 free_bootmem( (unsigned long)prcd, lrcd );
4800
4801 } /* endif */
4802
4803 } /* endif */
4804
4805 } /* endif */
4806 #endif
4807 s390_DevicePathVerification( irq, 0 );
4808
4809 disable_cpu_sync_isc( irq );
4810
4811 } /* endif */
4812
4813 free_irq( irq, &devstat );
4814
4815 } /* endif */
4816
4817 } /* endif */
4818
4819 }
4820
4821 /*
4822 * s390_device_recognition_all
4823 *
4824 * Used for system wide device recognition.
4825 *
4826 */
4827 void s390_device_recognition_all( void)
4828 {
4829 int irq = 0; /* let's start with subchannel 0 ... */
4830
4831 do
4832 {
4833 s390_device_recognition_irq( irq );
4834
4835 irq ++;
4836
4837 } while ( irq <= highest_subchannel );
4838
4839 }
4840
4841 /*
4842 * Function: s390_redo_validation
4843 * Look for no longer blacklisted devices
4844 * FIXME: there must be a better way to do this...
4845 */
4846
4847 void s390_redo_validation(void)
4848 {
4849 int irq = 0;
4850 int ret;
4851
4852 if (cio_debug_initialized) {
4853 debug_text_event(cio_debug_trace_id, 0, "redoval");
4854 }
4855 do {
4856 if (ioinfo[irq] == INVALID_STORAGE_AREA) {
4857 ret = s390_validate_subchannel(irq, 0);
4858 if (!ret) {
4859 s390_device_recognition_irq(irq);
4860 if (ioinfo[irq]->ui.flags.oper) {
4861 devreg_t *pdevreg;
4862
4863 pdevreg = s390_search_devreg( ioinfo[irq] );
4864 if ( pdevreg != NULL ) {
4865 if ( pdevreg->oper_func != NULL )
4866 pdevreg->oper_func( irq, pdevreg );
4867
4868 }
4869 }
4870 if (cio_proc_devinfo)
4871 if (irq < MAX_CIO_PROCFS_ENTRIES) {
4872 cio_procfs_device_create(ioinfo[irq]->devno);
4873 }
4874 }
4875 }
4876 irq++;
4877 } while (irq<=highest_subchannel);
4878 }
4879
4880 /*
4881 * s390_search_devices
4882 *
4883 * Determines all subchannels available to the system.
4884 *
4885 */
4886 void s390_process_subchannels( void)
4887 {
4888 int ret;
4889 int irq = 0; /* Evaluate all subchannels starting with 0 ... */
4890
4891 do
4892 {
4893 ret = s390_validate_subchannel( irq, 0);
4894
4895 if ( ret != -ENXIO)
4896 irq++;
4897
4898 } while ( (ret != -ENXIO) && (irq < __MAX_SUBCHANNELS) );
4899
4900 highest_subchannel = (--irq);
4901
4902 printk( "Highest subchannel number detected (hex) : %04X\n",
4903 highest_subchannel);
4904 if (cio_debug_initialized)
4905 debug_sprintf_event(cio_debug_msg_id, 0,
4906 "Highest subchannel number detected (hex) : %04X\n",
4907 highest_subchannel);
4908 }
4909
4910 /*
4911 * s390_validate_subchannel()
4912 *
4913 * Process the subchannel for the requested irq. Returns 1 for valid
4914 * subchannels, otherwise 0.
4915 */
4916 int s390_validate_subchannel( int irq, int enable )
4917 {
4918
4919 int retry; /* retry count for status pending conditions */
4920 int ccode; /* condition code for stsch() only */
4921 int ccode2; /* condition code for other I/O routines */
4922 schib_t *p_schib;
4923 int ret;
4924
4925 char dbf_txt[15];
4926
4927 if (cio_debug_initialized) {
4928 debug_text_event(cio_debug_trace_id, 4, "valsch");
4929 sprintf(dbf_txt, "%x", irq);
4930 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
4931 }
4932
4933 /*
4934 * The first subchannel that is not-operational (ccode==3)
4935 * indicates that there aren't any more devices available.
4936 */
4937 if ( ( init_IRQ_complete )
4938 && ( ioinfo[irq] != INVALID_STORAGE_AREA ) )
4939 {
4940 p_schib = &ioinfo[irq]->schib;
4941 }
4942 else
4943 {
4944 p_schib = p_init_schib;
4945
4946 } /* endif */
4947
4948 /*
4949 * If we knew the device before we assume the worst case ...
4950 */
4951 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
4952 {
4953 ioinfo[irq]->ui.flags.oper = 0;
4954 ioinfo[irq]->ui.flags.dval = 0;
4955
4956 } /* endif */
4957
4958 ccode = stsch( irq, p_schib);
4959
4960 if ( !ccode )
4961 {
4962 /*
4963 * ... just being curious we check for non I/O subchannels
4964 */
4965 if ( p_schib->pmcw.st )
4966 {
4967 printk( "Subchannel %04X reports "
4968 "non-I/O subchannel type %04X\n",
4969 irq,
4970 p_schib->pmcw.st);
4971 if (cio_debug_initialized)
4972 debug_sprintf_event(cio_debug_msg_id, 0,
4973 "Subchannel %04X reports non-I/O subchannel type %04X\n",
4974 irq, p_schib->pmcw.st);
4975
4976 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
4977 ioinfo[irq]->ui.flags.oper = 0;
4978
4979 } /* endif */
4980
4981 if ( p_schib->pmcw.dnv )
4982 {
4983 if ( is_blacklisted( p_schib->pmcw.dev )) {
4984 /*
4985 * This device must not be known to Linux. So we simply say that
4986 * there is no device and return ENODEV.
4987 */
4988 #ifdef CONFIG_DEBUG_IO
4989 printk( "Blacklisted device detected at devno %04X\n", p_schib->pmcw.dev );
4990 #endif
4991 if (cio_debug_initialized)
4992 debug_sprintf_event(cio_debug_msg_id, 0,
4993 "Blacklisted device detected at devno %04X\n",
4994 p_schib->pmcw.dev);
4995 ret = -ENODEV;
4996 } else {
4997 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
4998 {
4999 if ( !init_IRQ_complete )
5000 {
5001 ioinfo[irq] =
5002 (ioinfo_t *)alloc_bootmem_low( sizeof(ioinfo_t));
5003 }
5004 else
5005 {
5006 ioinfo[irq] =
5007 (ioinfo_t *)kmalloc( sizeof(ioinfo_t),
5008 GFP_DMA );
5009
5010 } /* endif */
5011
5012 memset( ioinfo[irq], '\0', sizeof( ioinfo_t));
5013 memcpy( &ioinfo[irq]->schib,
5014 p_init_schib,
5015 sizeof( schib_t));
5016
5017 /*
5018 * We have to insert the new ioinfo element
5019 * into the linked list, either at its head,
5020 * its tail or insert it.
5021 */
5022 if ( ioinfo_head == NULL ) /* first element */
5023 {
5024 ioinfo_head = ioinfo[irq];
5025 ioinfo_tail = ioinfo[irq];
5026 }
5027 else if ( irq < ioinfo_head->irq ) /* new head */
5028 {
5029 ioinfo[irq]->next = ioinfo_head;
5030 ioinfo_head->prev = ioinfo[irq];
5031 ioinfo_head = ioinfo[irq];
5032 }
5033 else if ( irq > ioinfo_tail->irq ) /* new tail */
5034 {
5035 ioinfo_tail->next = ioinfo[irq];
5036 ioinfo[irq]->prev = ioinfo_tail;
5037 ioinfo_tail = ioinfo[irq];
5038 }
5039 else /* insert element */
5040 {
5041 ioinfo_t *pi = ioinfo_head;
5042
5043 do
5044 {
5045 if ( irq < pi->next->irq )
5046 {
5047 ioinfo[irq]->next = pi->next;
5048 ioinfo[irq]->prev = pi;
5049 pi->next->prev = ioinfo[irq];
5050 pi->next = ioinfo[irq];
5051 break;
5052
5053 } /* endif */
5054
5055 pi = pi->next;
5056
5057 } while ( 1 );
5058
5059 } /* endif */
5060
5061 } /* endif */
5062
5063 // initialize some values ...
5064 ioinfo[irq]->ui.flags.pgid_supp = 1;
5065
5066 ioinfo[irq]->opm = ioinfo[irq]->schib.pmcw.pim
5067 & ioinfo[irq]->schib.pmcw.pam
5068 & ioinfo[irq]->schib.pmcw.pom;
5069
5070 if ( cio_show_msg )
5071 {
5072 printk( KERN_INFO"Detected device %04X "
5073 "on subchannel %04X"
5074 " - PIM = %02X, PAM = %02X, POM = %02X\n",
5075 ioinfo[irq]->schib.pmcw.dev,
5076 irq,
5077 ioinfo[irq]->schib.pmcw.pim,
5078 ioinfo[irq]->schib.pmcw.pam,
5079 ioinfo[irq]->schib.pmcw.pom);
5080
5081 } /* endif */
5082 if (cio_debug_initialized)
5083 debug_sprintf_event(cio_debug_msg_id, 0,
5084 "Detected device %04X "
5085 "on subchannel %04X"
5086 " - PIM = %02X, PAM = %02X, POM = %02X\n",
5087 ioinfo[irq]->schib.pmcw.dev,
5088 irq,
5089 ioinfo[irq]->schib.pmcw.pim,
5090 ioinfo[irq]->schib.pmcw.pam,
5091 ioinfo[irq]->schib.pmcw.pom);
5092
5093 /*
5094 * initialize ioinfo structure
5095 */
5096 ioinfo[irq]->irq = irq;
5097 if(!ioinfo[irq]->ui.flags.ready)
5098 {
5099 ioinfo[irq]->nopfunc = NULL;
5100 ioinfo[irq]->ui.flags.busy = 0;
5101 ioinfo[irq]->ui.flags.dval = 1;
5102 ioinfo[irq]->devstat.intparm = 0;
5103
5104 }
5105 ioinfo[irq]->devstat.devno = ioinfo[irq]->schib.pmcw.dev;
5106 ioinfo[irq]->devno = ioinfo[irq]->schib.pmcw.dev;
5107
5108 /*
5109 * We should have at least one CHPID ...
5110 */
5111 if ( ioinfo[irq]->opm )
5112 {
5113 /*
5114 * We now have to initially ...
5115 * ... set "interruption sublass"
5116 * ... enable "concurrent sense"
5117 * ... enable "multipath mode" if more than one
5118 * CHPID is available. This is done regardless
5119 * whether multiple paths are available for us.
5120 *
5121 * Note : we don't enable the device here, this is temporarily
5122 * done during device sensing below.
5123 */
5124 ioinfo[irq]->schib.pmcw.isc = 3; /* could be smth. else */
5125 ioinfo[irq]->schib.pmcw.csense = 1; /* concurrent sense */
5126 ioinfo[irq]->schib.pmcw.ena = enable;
5127 ioinfo[irq]->schib.pmcw.intparm =
5128 ioinfo[irq]->schib.pmcw.dev;
5129
5130 if ( ( ioinfo[irq]->opm != 0x80 )
5131 && ( ioinfo[irq]->opm != 0x40 )
5132 && ( ioinfo[irq]->opm != 0x20 )
5133 && ( ioinfo[irq]->opm != 0x10 )
5134 && ( ioinfo[irq]->opm != 0x08 )
5135 && ( ioinfo[irq]->opm != 0x04 )
5136 && ( ioinfo[irq]->opm != 0x02 )
5137 && ( ioinfo[irq]->opm != 0x01 ) )
5138 {
5139 ioinfo[irq]->schib.pmcw.mp = 1; /* multipath mode */
5140
5141 } /* endif */
5142
5143 retry = 5;
5144
5145 do
5146 {
5147 ccode2 = msch_err( irq, &ioinfo[irq]->schib);
5148
5149 switch (ccode2) {
5150 case 0: // successful completion
5151 //
5152 // concurrent sense facility available ...
5153 //
5154 ioinfo[irq]->ui.flags.oper = 1;
5155 ioinfo[irq]->ui.flags.consns = 1;
5156 ret = 0;
5157 break;
5158
5159 case 1: // status pending
5160 //
5161 // How can we have a pending status as
5162 // device is disabled for interrupts ?
5163 // Anyway, process it ...
5164 //
5165 ioinfo[irq]->ui.flags.s_pend = 1;
5166 s390_process_IRQ( irq);
5167 ioinfo[irq]->ui.flags.s_pend = 0;
5168 retry--;
5169 ret = -EIO;
5170 break;
5171
5172 case 2: // busy
5173 /*
5174 * we mark it not-oper as we can't
5175 * properly operate it !
5176 */
5177 ioinfo[irq]->ui.flags.oper = 0;
5178 udelay( 100); /* allow for recovery */
5179 retry--;
5180 ret = -EBUSY;
5181 break;
5182
5183 case 3: // not operational
5184 ioinfo[irq]->ui.flags.oper = 0;
5185 retry = 0;
5186 ret = -ENODEV;
5187 break;
5188
5189 default:
5190 #define PGMCHK_OPERAND_EXC 0x15
5191
5192 if ( (ccode2 & PGMCHK_OPERAND_EXC) == PGMCHK_OPERAND_EXC )
5193 {
5194 /*
5195 * re-issue the modify subchannel without trying to
5196 * enable the concurrent sense facility
5197 */
5198 ioinfo[irq]->schib.pmcw.csense = 0;
5199
5200 ccode2 = msch_err( irq, &ioinfo[irq]->schib);
5201
5202 if ( ccode2 != 0 )
5203 {
5204 printk( " ... msch() (2) failed with CC = %X\n",
5205 ccode2 );
5206 if (cio_debug_initialized)
5207 debug_sprintf_event(cio_debug_msg_id, 0,
5208 "msch() (2) failed with CC=%X\n",
5209 ccode2);
5210 ioinfo[irq]->ui.flags.oper = 0;
5211 ret = -EIO;
5212 }
5213 else
5214 {
5215 ioinfo[irq]->ui.flags.oper = 1;
5216 ioinfo[irq]->ui.flags.consns = 0;
5217 ret = 0;
5218
5219 } /* endif */
5220 }
5221 else
5222 {
5223 printk( " ... msch() (1) failed with CC = %X\n",
5224 ccode2);
5225 if (cio_debug_initialized)
5226 debug_sprintf_event(cio_debug_msg_id, 0,
5227 "msch() (1) failed with CC = %X\n",
5228 ccode2);
5229 ioinfo[irq]->ui.flags.oper = 0;
5230 ret = -EIO;
5231
5232 } /* endif */
5233
5234 retry = 0;
5235 break;
5236
5237 } /* endswitch */
5238
5239 } while ( ccode2 && retry );
5240
5241 if ( (ccode2 != 0) && (ccode2 != 3) && (!retry) )
5242 {
5243 printk( " ... msch() retry count for "
5244 "subchannel %04X exceeded, CC = %d\n",
5245 irq,
5246 ccode2);
5247 if (cio_debug_initialized)
5248 debug_sprintf_event(cio_debug_msg_id, 0,
5249 " ... msch() retry count for "
5250 "subchannel %04X exceeded, CC = %d\n",
5251 irq, ccode2);
5252
5253 } /* endif */
5254 }
5255 else
5256 {
5257 /* no path available ... */
5258 ioinfo[irq]->ui.flags.oper = 0;
5259 ret = -ENODEV;
5260
5261 } /* endif */
5262 }
5263 }
5264 else
5265 {
5266 ret = -ENODEV;
5267
5268 } /* endif */
5269 }
5270 else
5271 {
5272 ret = -ENXIO;
5273
5274 } /* endif */
5275
5276 return( ret );
5277 }
5278
5279 /*
5280 * s390_SenseID
5281 *
5282 * Try to obtain the 'control unit'/'device type' information
5283 * associated with the subchannel.
5284 *
5285 * The function is primarily meant to be called without irq
5286 * action handler in place. However, it also allows for
5287 * use with an action handler in place. If there is already
5288 * an action handler registered assure it can handle the
5289 * s390_SenseID() related device interrupts - interruption
5290 * parameter used is 0x00E2C9C4 ( SID ).
5291 */
5292 int s390_SenseID( int irq, senseid_t *sid, __u8 lpm )
5293 {
5294 ccw1_t *sense_ccw; /* ccw area for SenseID command */
5295 senseid_t isid; /* internal sid */
5296 devstat_t devstat; /* required by request_irq() */
5297 __u8 pathmask; /* calulate path mask */
5298 __u8 domask; /* path mask to use */
5299 int inlreq; /* inline request_irq() */
5300 int irq_ret; /* return code */
5301 devstat_t *pdevstat; /* ptr to devstat in use */
5302 int retry; /* retry count */
5303 int io_retry; /* retry indicator */
5304
5305 senseid_t *psid = sid;/* start with the external buffer */
5306 int sbuffer = 0; /* switch SID data buffer */
5307
5308 char dbf_txt[15];
5309
5310 if ( (irq > highest_subchannel) || (irq < 0 ) )
5311 {
5312 return( -ENODEV );
5313
5314 }
5315 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
5316 {
5317 return( -ENODEV);
5318
5319 } /* endif */
5320
5321 if ( ioinfo[irq]->ui.flags.oper == 0 )
5322 {
5323 return( -ENODEV );
5324
5325 } /* endif */
5326
5327 if (cio_debug_initialized) {
5328 debug_text_event(cio_debug_trace_id, 4, "snsID");
5329 sprintf(dbf_txt, "%x", irq);
5330 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
5331 }
5332
5333 if ( !ioinfo[irq]->ui.flags.ready )
5334 {
5335
5336 pdevstat = &devstat;
5337
5338 /*
5339 * Perform SENSE ID command processing. We have to request device
5340 * ownership and provide a dummy I/O handler. We issue sync. I/O
5341 * requests and evaluate the devstat area on return therefore
5342 * we don't need a real I/O handler in place.
5343 */
5344 irq_ret = request_irq( irq, init_IRQ_handler, 0, "SID", &devstat);
5345
5346 if ( irq_ret == 0 )
5347 inlreq = 1;
5348 }
5349 else
5350 {
5351 inlreq = 0;
5352 irq_ret = 0;
5353 pdevstat = ioinfo[irq]->irq_desc.dev_id;
5354
5355 } /* endif */
5356
5357 if ( irq_ret == 0 )
5358 {
5359 int i;
5360
5361 s390irq_spin_lock( irq);
5362
5363 if ( init_IRQ_complete )
5364 {
5365 sense_ccw = kmalloc( 2*sizeof( ccw1_t), GFP_DMA);
5366 }
5367 else
5368 {
5369 sense_ccw = alloc_bootmem_low( 2*sizeof( ccw1_t));
5370
5371 } /* endif */
5372
5373 // more than one path installed ?
5374 if ( ioinfo[irq]->schib.pmcw.pim != 0x80 )
5375 {
5376 sense_ccw[0].cmd_code = CCW_CMD_SUSPEND_RECONN;
5377 sense_ccw[0].cda = 0;
5378 sense_ccw[0].count = 0;
5379 sense_ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
5380
5381 sense_ccw[1].cmd_code = CCW_CMD_SENSE_ID;
5382 sense_ccw[1].cda = (__u32)virt_to_phys( sid );
5383 sense_ccw[1].count = sizeof( senseid_t);
5384 sense_ccw[1].flags = CCW_FLAG_SLI;
5385 }
5386 else
5387 {
5388 sense_ccw[0].cmd_code = CCW_CMD_SENSE_ID;
5389 sense_ccw[0].cda = (__u32)virt_to_phys( sid );
5390 sense_ccw[0].count = sizeof( senseid_t);
5391 sense_ccw[0].flags = CCW_FLAG_SLI;
5392
5393 } /* endif */
5394
5395 for ( i = 0 ; (i < 8) ; i++ )
5396 {
5397 pathmask = 0x80 >> i;
5398
5399 domask = ioinfo[irq]->opm & pathmask;
5400
5401 if ( lpm )
5402 domask &= lpm;
5403
5404 if ( domask )
5405 {
5406 psid->cu_type = 0xFFFF; /* initialize fields ... */
5407 psid->cu_model = 0;
5408 psid->dev_type = 0;
5409 psid->dev_model = 0;
5410
5411 retry = 5; /* retry count */
5412 io_retry = 1; /* enable retries */
5413
5414 /*
5415 * We now issue a SenseID request. In case of BUSY,
5416 * STATUS PENDING or non-CMD_REJECT error conditions
5417 * we run simple retries.
5418 */
5419 do
5420 {
5421 memset( pdevstat, '\0', sizeof( devstat_t) );
5422
5423 irq_ret = s390_start_IO( irq,
5424 sense_ccw,
5425 0x00E2C9C4, // == SID
5426 domask,
5427 DOIO_WAIT_FOR_INTERRUPT
5428 | DOIO_TIMEOUT
5429 | DOIO_VALID_LPM
5430 | DOIO_DONT_CALL_INTHDLR );
5431
5432 //
5433 // The OSA_E FE card possibly causes -ETIMEDOUT
5434 // conditions, as the SenseID may stay start
5435 // pending. This will cause start_IO() to finally
5436 // halt the operation we should retry. If the halt
5437 // fails this may cause -EBUSY we simply retry
5438 // and eventually clean up with free_irq().
5439 //
5440
5441 if ( psid->cu_type == 0xFFFF )
5442 {
5443 if ( pdevstat->flag & DEVSTAT_STATUS_PENDING )
5444 {
5445 #ifdef CONFIG_DEBUG_IO
5446 printk( "SenseID : device %04X on "
5447 "Subchannel %04X "
5448 "reports pending status, "
5449 "retry : %d\n",
5450 ioinfo[irq]->schib.pmcw.dev,
5451 irq,
5452 retry);
5453 #endif
5454 if (cio_debug_initialized)
5455 debug_sprintf_event(cio_debug_msg_id, 2,
5456 "SenseID : device %04X on "
5457 "Subchannel %04X "
5458 "reports pending status, "
5459 "retry : %d\n",
5460 ioinfo[irq]->schib.pmcw.dev,
5461 irq,
5462 retry);
5463 } /* endif */
5464
5465 if ( pdevstat->flag & DEVSTAT_FLAG_SENSE_AVAIL )
5466 {
5467 /*
5468 * if the device doesn't support the SenseID
5469 * command further retries wouldn't help ...
5470 */
5471 if ( pdevstat->ii.sense.data[0]
5472 & (SNS0_CMD_REJECT | SNS0_INTERVENTION_REQ) )
5473 {
5474 #ifdef CONFIG_DEBUG_IO
5475 printk( "SenseID : device %04X on "
5476 "Subchannel %04X "
5477 "reports cmd reject or "
5478 "intervention required\n",
5479 ioinfo[irq]->schib.pmcw.dev,
5480 irq);
5481 #endif
5482 if (cio_debug_initialized)
5483 debug_sprintf_event(cio_debug_msg_id, 2,
5484 "SenseID : device %04X on "
5485 "Subchannel %04X "
5486 "reports cmd reject or "
5487 "intervention required\n",
5488 ioinfo[irq]->schib.pmcw.dev,
5489 irq);
5490 io_retry = 1;
5491 }
5492
5493 else
5494 {
5495 #ifdef CONFIG_DEBUG_IO
5496 printk( "SenseID : UC on "
5497 "dev %04X, "
5498 "retry %d, "
5499 "lpum %02X, "
5500 "cnt %02d, "
5501 "sns :"
5502 " %02X%02X%02X%02X "
5503 "%02X%02X%02X%02X ...\n",
5504 ioinfo[irq]->schib.pmcw.dev,
5505 retry,
5506 pdevstat->lpum,
5507 pdevstat->scnt,
5508 pdevstat->ii.sense.data[0],
5509 pdevstat->ii.sense.data[1],
5510 pdevstat->ii.sense.data[2],
5511 pdevstat->ii.sense.data[3],
5512 pdevstat->ii.sense.data[4],
5513 pdevstat->ii.sense.data[5],
5514 pdevstat->ii.sense.data[6],
5515 pdevstat->ii.sense.data[7]);
5516 #endif
5517 if (cio_debug_initialized)
5518 debug_sprintf_event(cio_debug_msg_id, 2,
5519 "SenseID : UC on "
5520 "dev %04X, "
5521 "retry %d, "
5522 "lpum %02X, "
5523 "cnt %02d, "
5524 "sns :"
5525 " %02X%02X%02X%02X "
5526 "%02X%02X%02X%02X ...\n",
5527 ioinfo[irq]->schib.pmcw.dev,
5528 retry,
5529 pdevstat->lpum,
5530 pdevstat->scnt,
5531 pdevstat->ii.sense.data[0],
5532 pdevstat->ii.sense.data[1],
5533 pdevstat->ii.sense.data[2],
5534 pdevstat->ii.sense.data[3],
5535 pdevstat->ii.sense.data[4],
5536 pdevstat->ii.sense.data[5],
5537 pdevstat->ii.sense.data[6],
5538 pdevstat->ii.sense.data[7]);
5539 } /* endif */
5540
5541 }
5542 else if ( ( pdevstat->flag & DEVSTAT_NOT_OPER )
5543 || ( irq_ret == -ENODEV ) )
5544 {
5545 #ifdef CONFIG_DEBUG_IO
5546 printk( "SenseID : path %02X for "
5547 "device %04X on "
5548 "subchannel %04X "
5549 "is 'not operational'\n",
5550 domask,
5551 ioinfo[irq]->schib.pmcw.dev,
5552 irq);
5553 #endif
5554 if (cio_debug_initialized)
5555 debug_sprintf_event(cio_debug_msg_id, 2,
5556 "SenseID : path %02X for "
5557 "device %04X on "
5558 "subchannel %04X "
5559 "is 'not operational'\n",
5560 domask,
5561 ioinfo[irq]->schib.pmcw.dev,
5562 irq);
5563
5564 io_retry = 0;
5565 ioinfo[irq]->opm &= ~domask;
5566
5567 }
5568
5569 else if ( (pdevstat->flag !=
5570 ( DEVSTAT_START_FUNCTION
5571 | DEVSTAT_FINAL_STATUS ) )
5572 && !(pdevstat->flag &
5573 DEVSTAT_STATUS_PENDING ) )
5574 {
5575 #ifdef CONFIG_DEBUG_IO
5576 printk( "SenseID : start_IO() for "
5577 "device %04X on "
5578 "subchannel %04X "
5579 "returns %d, retry %d, "
5580 "status %04X\n",
5581 ioinfo[irq]->schib.pmcw.dev,
5582 irq,
5583 irq_ret,
5584 retry,
5585 pdevstat->flag);
5586 #endif
5587 if (cio_debug_initialized)
5588 debug_sprintf_event(cio_debug_msg_id, 2,
5589 "SenseID : start_IO() for "
5590 "device %04X on "
5591 "subchannel %04X "
5592 "returns %d, retry %d, "
5593 "status %04X\n",
5594 ioinfo[irq]->schib.pmcw.dev,
5595 irq,
5596 irq_ret,
5597 retry,
5598 pdevstat->flag);
5599
5600 } /* endif */
5601
5602 }
5603 else // we got it ...
5604 {
5605 if ( !sbuffer ) // switch buffers
5606 {
5607 /*
5608 * we report back the
5609 * first hit only
5610 */
5611 psid = &isid;
5612
5613 if ( ioinfo[irq]->schib.pmcw.pim != 0x80 )
5614 {
5615 sense_ccw[1].cda = (__u32)virt_to_phys( psid );
5616 }
5617 else
5618 {
5619 sense_ccw[0].cda = (__u32)virt_to_phys( psid );
5620
5621 } /* endif */
5622
5623 /*
5624 * if just the very first
5625 * was requested to be
5626 * sensed disable further
5627 * scans.
5628 */
5629 if ( !lpm )
5630 lpm = domask;
5631
5632 sbuffer = 1;
5633
5634 } /* endif */
5635
5636 if ( pdevstat->rescnt < (sizeof( senseid_t) - 8) )
5637 {
5638 ioinfo[irq]->ui.flags.esid = 1;
5639
5640 } /* endif */
5641
5642 io_retry = 0;
5643
5644 } /* endif */
5645
5646 if ( io_retry )
5647 {
5648 retry--;
5649
5650 if ( retry == 0 )
5651 {
5652 io_retry = 0;
5653
5654 } /* endif */
5655
5656 } /* endif */
5657
5658 } while ( (io_retry) );
5659
5660 } /* endif - domask */
5661
5662 } /* endfor */
5663
5664 if ( init_IRQ_complete )
5665 {
5666 kfree( sense_ccw );
5667 }
5668 else
5669 {
5670 free_bootmem( (unsigned long)sense_ccw, 2*sizeof(ccw1_t) );
5671
5672 } /* endif */
5673
5674 s390irq_spin_unlock( irq);
5675
5676 /*
5677 * If we installed the irq action handler we have to
5678 * release it too.
5679 */
5680 if ( inlreq )
5681 free_irq( irq, pdevstat);
5682
5683 /*
5684 * if running under VM check there ... perhaps we should do
5685 * only if we suffered a command reject, but it doesn't harm
5686 */
5687 if ( ( sid->cu_type == 0xFFFF )
5688 && ( MACHINE_IS_VM ) )
5689 {
5690 VM_virtual_device_info( ioinfo[irq]->schib.pmcw.dev,
5691 sid );
5692 } /* endif */
5693
5694 if ( sid->cu_type == 0xFFFF )
5695 {
5696 /*
5697 * SenseID CU-type of 0xffff indicates that no device
5698 * information could be retrieved (pre-init value).
5699 *
5700 * If we can't couldn't identify the device type we
5701 * consider the device "not operational".
5702 */
5703 #ifdef CONFIG_DEBUG_IO
5704 printk( "SenseID : unknown device %04X on subchannel %04X\n",
5705 ioinfo[irq]->schib.pmcw.dev,
5706 irq);
5707 #endif
5708 if (cio_debug_initialized)
5709 debug_sprintf_event(cio_debug_msg_id, 2,
5710 "SenseID : unknown device %04X on subchannel %04X\n",
5711 ioinfo[irq]->schib.pmcw.dev,
5712 irq);
5713 ioinfo[irq]->ui.flags.unknown = 1;
5714
5715 } /* endif */
5716
5717
5718 /*
5719 * Issue device info message if unit was operational .
5720 */
5721 if ( !ioinfo[irq]->ui.flags.unknown ) {
5722 if ( sid->dev_type != 0 ) {
5723 if ( cio_show_msg )
5724 printk( KERN_INFO"SenseID : device %04X reports: "
5725 "CU Type/Mod = %04X/%02X,"
5726 " Dev Type/Mod = %04X/%02X\n",
5727 ioinfo[irq]->schib.pmcw.dev,
5728 sid->cu_type,
5729 sid->cu_model,
5730 sid->dev_type,
5731 sid->dev_model);
5732 if (cio_debug_initialized)
5733 debug_sprintf_event(cio_debug_msg_id, 2,
5734 "SenseID : device %04X reports: "
5735 "CU Type/Mod = %04X/%02X,"
5736 " Dev Type/Mod = %04X/%02X\n",
5737 ioinfo[irq]->schib.pmcw.dev,
5738 sid->cu_type,
5739 sid->cu_model,
5740 sid->dev_type,
5741 sid->dev_model);
5742 } else {
5743 if ( cio_show_msg )
5744 printk( KERN_INFO"SenseID : device %04X reports:"
5745 " Dev Type/Mod = %04X/%02X\n",
5746 ioinfo[irq]->schib.pmcw.dev,
5747 sid->cu_type,
5748 sid->cu_model);
5749 if (cio_debug_initialized)
5750 debug_sprintf_event(cio_debug_msg_id, 2,
5751 "SenseID : device %04X reports:"
5752 " Dev Type/Mod = %04X/%02X\n",
5753 ioinfo[irq]->schib.pmcw.dev,
5754 sid->cu_type,
5755 sid->cu_model);
5756 } /* endif */
5757
5758 } /* endif */
5759
5760 if ( !ioinfo[irq]->ui.flags.unknown )
5761 irq_ret = 0;
5762 else
5763 irq_ret = -ENODEV;
5764
5765 } /* endif */
5766
5767 return( irq_ret );
5768 }
5769
5770 static int __inline__ s390_SetMultiPath( int irq )
5771 {
5772 int cc;
5773
5774 cc = stsch( irq, &ioinfo[irq]->schib );
5775
5776 if ( !cc )
5777 {
5778 ioinfo[irq]->schib.pmcw.mp = 1; /* multipath mode */
5779
5780 cc = msch( irq, &ioinfo[irq]->schib );
5781
5782 } /* endif */
5783
5784 return( cc);
5785 }
5786
5787 /*
5788 * Device Path Verification
5789 *
5790 * Path verification is accomplished by checking which paths (CHPIDs) are
5791 * available. Further, a path group ID is set, if possible in multipath
5792 * mode, otherwise in single path mode.
5793 *
5794 */
5795 int s390_DevicePathVerification( int irq, __u8 usermask )
5796 {
5797 #if 1
5798 int ccode;
5799 __u8 pathmask;
5800 __u8 domask;
5801
5802 int ret = 0;
5803
5804 char dbf_txt[15];
5805
5806 if (cio_debug_initialized) {
5807 debug_text_event(cio_debug_trace_id, 4, "dpver");
5808 sprintf(dbf_txt, "%x", irq);
5809 debug_text_event(cio_debug_trace_id, 4, dbf_txt);
5810 }
5811
5812 if ( ioinfo[irq]->ui.flags.pgid_supp == 0 )
5813 {
5814 return( 0); // just exit ...
5815
5816 } /* endif */
5817
5818 ccode = stsch( irq, &(ioinfo[irq]->schib) );
5819
5820 if ( ccode )
5821 {
5822 ret = -ENODEV;
5823 }
5824 else if ( ioinfo[irq]->schib.pmcw.pim == 0x80 )
5825 {
5826 /*
5827 * no error, just not required for single path only devices
5828 */
5829 ioinfo[irq]->ui.flags.pgid_supp = 0;
5830 ret = 0;
5831 }
5832 else
5833 {
5834 int i;
5835 pgid_t pgid;
5836 __u8 dev_path;
5837 int first = 1;
5838
5839 ioinfo[irq]->opm = ioinfo[irq]->schib.pmcw.pim
5840 & ioinfo[irq]->schib.pmcw.pam
5841 & ioinfo[irq]->schib.pmcw.pom;
5842
5843 if ( usermask )
5844 {
5845 dev_path = usermask;
5846 }
5847 else
5848 {
5849 dev_path = ioinfo[irq]->opm;
5850
5851 } /* endif */
5852
5853 /*
5854 * let's build a path group ID if we don't have one yet
5855 */
5856 if ( ioinfo[irq]->ui.flags.pgid == 0)
5857 {
5858 ioinfo[irq]->pgid.cpu_addr = *(__u16 *)__LC_CPUADDR;
5859 ioinfo[irq]->pgid.cpu_id = ((cpuid_t *)__LC_CPUID)->ident;
5860 ioinfo[irq]->pgid.cpu_model = ((cpuid_t *)__LC_CPUID)->machine;
5861 ioinfo[irq]->pgid.tod_high = *(__u32 *)&irq_IPL_TOD;
5862
5863 ioinfo[irq]->ui.flags.pgid = 1;
5864
5865 } /* endif */
5866
5867 memcpy( &pgid, &ioinfo[irq]->pgid, sizeof(pgid_t));
5868
5869 for ( i = 0; i < 8 && !ret ; i++)
5870 {
5871 pathmask = 0x80 >> i;
5872
5873 domask = dev_path & pathmask;
5874
5875 if ( domask )
5876 {
5877 ret = s390_SetPGID( irq, domask, &pgid );
5878
5879 /*
5880 * For the *first* path we are prepared
5881 * for recovery
5882 *
5883 * - If we fail setting the PGID we assume its
5884 * using a different PGID already (VM) we
5885 * try to sense.
5886 */
5887 if ( ret == -EOPNOTSUPP && first )
5888 {
5889 *(int *)&pgid = 0;
5890
5891 ret = s390_SensePGID( irq, domask, &pgid);
5892 first = 0;
5893
5894 if ( ret == 0 )
5895 {
5896 /*
5897 * Check whether we retrieved
5898 * a reasonable PGID ...
5899 */
5900 if ( pgid.inf.ps.state1 == SNID_STATE1_GROUPED )
5901 {
5902 memcpy( &(ioinfo[irq]->pgid),
5903 &pgid,
5904 sizeof(pgid_t) );
5905 }
5906 else // ungrouped or garbage ...
5907 {
5908 ret = -EOPNOTSUPP;
5909
5910 } /* endif */
5911 }
5912 else
5913 {
5914 ioinfo[irq]->ui.flags.pgid_supp = 0;
5915
5916 #ifdef CONFIG_DEBUG_IO
5917 printk( "PathVerification(%04X) "
5918 "- Device %04X doesn't "
5919 " support path grouping\n",
5920 irq,
5921 ioinfo[irq]->schib.pmcw.dev);
5922 #endif
5923 if (cio_debug_initialized)
5924 debug_sprintf_event(cio_debug_msg_id, 2,
5925 "PathVerification(%04X) "
5926 "- Device %04X doesn't "
5927 " support path grouping\n",
5928 irq,
5929 ioinfo[irq]->schib.pmcw.dev);
5930
5931 } /* endif */
5932 }
5933 else if ( ret == -EIO )
5934 {
5935 #ifdef CONFIG_DEBUG_IO
5936 printk("PathVerification(%04X) - I/O error "
5937 "on device %04X\n", irq,
5938 ioinfo[irq]->schib.pmcw.dev);
5939 #endif
5940
5941 if (cio_debug_initialized)
5942 debug_sprintf_event(cio_debug_msg_id, 2,
5943 "PathVerification(%04X) - I/O error "
5944 "on device %04X\n", irq,
5945 ioinfo[irq]->schib.pmcw.dev);
5946
5947 ioinfo[irq]->ui.flags.pgid_supp = 0;
5948
5949 } else {
5950 #ifdef CONFIG_DEBUG_IO
5951 printk( "PathVerification(%04X) "
5952 "- Unexpected error on device %04X\n",
5953 irq,
5954 ioinfo[irq]->schib.pmcw.dev);
5955 #endif
5956 if (cio_debug_initialized)
5957 debug_sprintf_event(cio_debug_msg_id, 2,
5958 "PathVerification(%04X) - "
5959 "Unexpected error on device %04X\n",
5960 irq,
5961 ioinfo[irq]->schib.pmcw.dev);
5962
5963 ioinfo[irq]->ui.flags.pgid_supp = 0;
5964
5965 } /* endif */
5966
5967 } /* endif */
5968
5969 } /* endfor */
5970
5971 } /* endif */
5972
5973 return ret;
5974 #else
5975 return 0;
5976 #endif
5977 }
5978
5979 /*
5980 * s390_SetPGID
5981 *
5982 * Set Path Group ID
5983 *
5984 */
5985 int s390_SetPGID( int irq, __u8 lpm, pgid_t *pgid )
5986 {
5987 ccw1_t *spid_ccw; /* ccw area for SPID command */
5988 devstat_t devstat; /* required by request_irq() */
5989 devstat_t *pdevstat = &devstat;
5990 unsigned long flags;
5991
5992
5993 int irq_ret = 0; /* return code */
5994 int retry = 5; /* retry count */
5995 int inlreq = 0; /* inline request_irq() */
5996 int mpath = 1; /* try multi-path first */
5997
5998 if ( (irq > highest_subchannel) || (irq < 0 ) )
5999 {
6000 return( -ENODEV );
6001
6002 }
6003 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
6004 {
6005 return( -ENODEV);
6006
6007 } /* endif */
6008
6009 if ( ioinfo[irq]->ui.flags.oper == 0 )
6010 {
6011 return( -ENODEV );
6012
6013 } /* endif */
6014
6015 if ( !ioinfo[irq]->ui.flags.ready )
6016 {
6017 /*
6018 * Perform SENSE ID command processing. We have to request device
6019 * ownership and provide a dummy I/O handler. We issue sync. I/O
6020 * requests and evaluate the devstat area on return therefore
6021 * we don't need a real I/O handler in place.
6022 */
6023 irq_ret = request_irq( irq,
6024 init_IRQ_handler,
6025 0,
6026 "SPID",
6027 pdevstat);
6028
6029 if ( irq_ret == 0 )
6030 inlreq = 1;
6031 }
6032 else
6033 {
6034 pdevstat = ioinfo[irq]->irq_desc.dev_id;
6035
6036 } /* endif */
6037
6038 if ( irq_ret == 0 )
6039 {
6040 s390irq_spin_lock_irqsave( irq, flags);
6041
6042 if ( init_IRQ_complete )
6043 {
6044 spid_ccw = kmalloc( 2*sizeof( ccw1_t), GFP_DMA);
6045 }
6046 else
6047 {
6048 spid_ccw = alloc_bootmem_low( 2*sizeof( ccw1_t));
6049
6050 } /* endif */
6051
6052 spid_ccw[0].cmd_code = 0x5B; /* suspend multipath reconnect */
6053 spid_ccw[0].cda = 0;
6054 spid_ccw[0].count = 0;
6055 spid_ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
6056
6057 spid_ccw[1].cmd_code = CCW_CMD_SET_PGID;
6058 spid_ccw[1].cda = (__u32)virt_to_phys( pgid );
6059 spid_ccw[1].count = sizeof( pgid_t);
6060 spid_ccw[1].flags = CCW_FLAG_SLI;
6061
6062 pgid->inf.fc = SPID_FUNC_MULTI_PATH | SPID_FUNC_ESTABLISH;
6063
6064 /*
6065 * We now issue a SenseID request. In case of BUSY
6066 * or STATUS PENDING conditions we retry 5 times.
6067 */
6068 do
6069 {
6070 memset( pdevstat, '\0', sizeof( devstat_t) );
6071
6072 irq_ret = s390_start_IO( irq,
6073 spid_ccw,
6074 0xE2D7C9C4, // == SPID
6075 lpm, // n/a
6076 DOIO_WAIT_FOR_INTERRUPT
6077 | DOIO_VALID_LPM
6078 | DOIO_DONT_CALL_INTHDLR );
6079
6080 if ( !irq_ret )
6081 {
6082 if ( pdevstat->flag & DEVSTAT_STATUS_PENDING )
6083 {
6084 #ifdef CONFIG_DEBUG_IO
6085 printk( "SPID - Device %04X "
6086 "on Subchannel %04X "
6087 "reports pending status, "
6088 "retry : %d\n",
6089 ioinfo[irq]->schib.pmcw.dev,
6090 irq,
6091 retry);
6092 #endif
6093 if (cio_debug_initialized)
6094 debug_sprintf_event(cio_debug_msg_id, 2,
6095 "SPID - Device %04X "
6096 "on Subchannel %04X "
6097 "reports pending status, "
6098 "retry : %d\n",
6099 ioinfo[irq]->schib.pmcw.dev,
6100 irq,
6101 retry);
6102 } /* endif */
6103
6104 if ( pdevstat->flag == ( DEVSTAT_START_FUNCTION
6105 | DEVSTAT_FINAL_STATUS ) )
6106 {
6107 retry = 0; // successfully set ...
6108 }
6109 else if ( pdevstat->flag & DEVSTAT_FLAG_SENSE_AVAIL )
6110 {
6111 /*
6112 * If the device doesn't support the
6113 * Sense Path Group ID command
6114 * further retries wouldn't help ...
6115 */
6116 if ( pdevstat->ii.sense.data[0] & SNS0_CMD_REJECT )
6117 {
6118 if ( mpath )
6119 {
6120 pgid->inf.fc = SPID_FUNC_SINGLE_PATH
6121 | SPID_FUNC_ESTABLISH;
6122 mpath = 0;
6123 retry--;
6124 }
6125 else
6126 {
6127 irq_ret = -EOPNOTSUPP;
6128 retry = 0;
6129
6130 } /* endif */
6131 }
6132 else
6133 {
6134 #ifdef CONFIG_DEBUG_IO
6135 printk( "SPID - device %04X,"
6136 " unit check,"
6137 " retry %d, cnt %02d,"
6138 " sns :"
6139 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
6140 ioinfo[irq]->schib.pmcw.dev,
6141 retry,
6142 pdevstat->scnt,
6143 pdevstat->ii.sense.data[0],
6144 pdevstat->ii.sense.data[1],
6145 pdevstat->ii.sense.data[2],
6146 pdevstat->ii.sense.data[3],
6147 pdevstat->ii.sense.data[4],
6148 pdevstat->ii.sense.data[5],
6149 pdevstat->ii.sense.data[6],
6150 pdevstat->ii.sense.data[7]);
6151 #endif
6152
6153 if (cio_debug_initialized)
6154 debug_sprintf_event(cio_debug_msg_id, 2,
6155 "SPID - device %04X,"
6156 " unit check,"
6157 " retry %d, cnt %02d,"
6158 " sns :"
6159 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
6160 ioinfo[irq]->schib.pmcw.dev,
6161 retry,
6162 pdevstat->scnt,
6163 pdevstat->ii.sense.data[0],
6164 pdevstat->ii.sense.data[1],
6165 pdevstat->ii.sense.data[2],
6166 pdevstat->ii.sense.data[3],
6167 pdevstat->ii.sense.data[4],
6168 pdevstat->ii.sense.data[5],
6169 pdevstat->ii.sense.data[6],
6170 pdevstat->ii.sense.data[7]);
6171
6172 retry--;
6173
6174 } /* endif */
6175
6176 }
6177 else if ( pdevstat->flag & DEVSTAT_NOT_OPER )
6178 {
6179 /* don't issue warnings during startup unless requested*/
6180 if (init_IRQ_complete || cio_notoper_msg) {
6181
6182 printk( "SPID - Device %04X "
6183 "on Subchannel %04X "
6184 "became 'not operational'\n",
6185 ioinfo[irq]->schib.pmcw.dev,
6186 irq);
6187 if (cio_debug_initialized)
6188 debug_sprintf_event(cio_debug_msg_id, 2,
6189 "SPID - Device %04X "
6190 "on Subchannel %04X "
6191 "became 'not operational'\n",
6192 ioinfo[irq]->schib.pmcw.dev,
6193 irq);
6194 }
6195
6196 retry = 0;
6197 irq_ret = -EIO;
6198
6199 } /* endif */
6200 }
6201 else if ( irq_ret != -ENODEV )
6202 {
6203 retry--;
6204 }
6205 else
6206 {
6207 retry = 0;
6208
6209 } /* endif */
6210
6211 } while ( retry > 0 );
6212
6213 if ( retry == 0 )
6214 {
6215 irq_ret = -EIO;
6216
6217 } /* endif */
6218
6219 if ( init_IRQ_complete )
6220 {
6221 kfree( spid_ccw );
6222 }
6223 else
6224 {
6225 free_bootmem( (unsigned long)spid_ccw, 2*sizeof(ccw1_t) );
6226
6227 } /* endif */
6228
6229 s390irq_spin_unlock_irqrestore( irq, flags);
6230
6231 /*
6232 * If we installed the irq action handler we have to
6233 * release it too.
6234 */
6235 if ( inlreq )
6236 free_irq( irq, pdevstat);
6237
6238 } /* endif */
6239
6240 return( irq_ret );
6241 }
6242
6243
6244 /*
6245 * s390_SensePGID
6246 *
6247 * Sense Path Group ID
6248 *
6249 */
6250 int s390_SensePGID( int irq, __u8 lpm, pgid_t *pgid )
6251 {
6252 ccw1_t *snid_ccw; /* ccw area for SNID command */
6253 devstat_t devstat; /* required by request_irq() */
6254 devstat_t *pdevstat = &devstat;
6255
6256 int irq_ret = 0; /* return code */
6257 int retry = 5; /* retry count */
6258 int inlreq = 0; /* inline request_irq() */
6259
6260 if ( (irq > highest_subchannel) || (irq < 0 ) )
6261 {
6262 return( -ENODEV );
6263
6264 }
6265 else if ( ioinfo[irq] == INVALID_STORAGE_AREA )
6266 {
6267 return( -ENODEV);
6268
6269 } /* endif */
6270
6271 if ( ioinfo[irq]->ui.flags.oper == 0 )
6272 {
6273 return( -ENODEV );
6274
6275 } /* endif */
6276
6277 if ( !ioinfo[irq]->ui.flags.ready )
6278 {
6279 /*
6280 * Perform SENSE ID command processing. We have to request device
6281 * ownership and provide a dummy I/O handler. We issue sync. I/O
6282 * requests and evaluate the devstat area on return therefore
6283 * we don't need a real I/O handler in place.
6284 */
6285 irq_ret = request_irq( irq,
6286 init_IRQ_handler,
6287 0,
6288 "SNID",
6289 pdevstat);
6290
6291 if ( irq_ret == 0 )
6292 inlreq = 1;
6293
6294 }
6295 else
6296 {
6297 pdevstat = ioinfo[irq]->irq_desc.dev_id;
6298
6299 } /* endif */
6300
6301 if ( irq_ret == 0 )
6302 {
6303 s390irq_spin_lock( irq);
6304
6305 if ( init_IRQ_complete )
6306 {
6307 snid_ccw = kmalloc( sizeof( ccw1_t), GFP_DMA);
6308 }
6309 else
6310 {
6311 snid_ccw = alloc_bootmem_low( sizeof( ccw1_t));
6312
6313 } /* endif */
6314
6315 snid_ccw->cmd_code = CCW_CMD_SENSE_PGID;
6316 snid_ccw->cda = (__u32)virt_to_phys( pgid );
6317 snid_ccw->count = sizeof( pgid_t);
6318 snid_ccw->flags = CCW_FLAG_SLI;
6319
6320 /*
6321 * We now issue a SenseID request. In case of BUSY
6322 * or STATUS PENDING conditions we retry 5 times.
6323 */
6324 do
6325 {
6326 memset( pdevstat, '\0', sizeof( devstat_t) );
6327
6328 irq_ret = s390_start_IO( irq,
6329 snid_ccw,
6330 0xE2D5C9C4, // == SNID
6331 lpm, // n/a
6332 DOIO_WAIT_FOR_INTERRUPT
6333 | DOIO_VALID_LPM
6334 | DOIO_DONT_CALL_INTHDLR );
6335
6336 if ( irq_ret == 0 )
6337 {
6338 if ( pdevstat->flag & DEVSTAT_FLAG_SENSE_AVAIL )
6339 {
6340 /*
6341 * If the device doesn't support the
6342 * Sense Path Group ID command
6343 * further retries wouldn't help ...
6344 */
6345 if ( pdevstat->ii.sense.data[0] & SNS0_CMD_REJECT )
6346 {
6347 retry = 0;
6348 irq_ret = -EOPNOTSUPP;
6349 }
6350 else
6351 {
6352 #ifdef CONFIG_DEBUG_IO
6353 printk( "SNID - device %04X,"
6354 " unit check,"
6355 " flag %04X, "
6356 " retry %d, cnt %02d,"
6357 " sns :"
6358 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
6359 ioinfo[irq]->schib.pmcw.dev,
6360 pdevstat->flag,
6361 retry,
6362 pdevstat->scnt,
6363 pdevstat->ii.sense.data[0],
6364 pdevstat->ii.sense.data[1],
6365 pdevstat->ii.sense.data[2],
6366 pdevstat->ii.sense.data[3],
6367 pdevstat->ii.sense.data[4],
6368 pdevstat->ii.sense.data[5],
6369 pdevstat->ii.sense.data[6],
6370 pdevstat->ii.sense.data[7]);
6371
6372 #endif
6373 if (cio_debug_initialized)
6374 debug_sprintf_event(cio_debug_msg_id, 2,
6375 "SNID - device %04X,"
6376 " unit check,"
6377 " flag %04X, "
6378 " retry %d, cnt %02d,"
6379 " sns :"
6380 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
6381 ioinfo[irq]->schib.pmcw.dev,
6382 pdevstat->flag,
6383 retry,
6384 pdevstat->scnt,
6385 pdevstat->ii.sense.data[0],
6386 pdevstat->ii.sense.data[1],
6387 pdevstat->ii.sense.data[2],
6388 pdevstat->ii.sense.data[3],
6389 pdevstat->ii.sense.data[4],
6390 pdevstat->ii.sense.data[5],
6391 pdevstat->ii.sense.data[6],
6392 pdevstat->ii.sense.data[7]);
6393 retry--;
6394
6395 } /* endif */
6396 }
6397 else if ( pdevstat->flag & DEVSTAT_NOT_OPER )
6398 {
6399 /* don't issue warnings during startup unless requested*/
6400 if (init_IRQ_complete || cio_notoper_msg) {
6401 printk( "SNID - Device %04X "
6402 "on Subchannel %04X "
6403 "became 'not operational'\n",
6404 ioinfo[irq]->schib.pmcw.dev,
6405 irq);
6406 if (cio_debug_initialized)
6407 debug_sprintf_event(cio_debug_msg_id, 2,
6408 "SNID - Device %04X "
6409 "on Subchannel %04X "
6410 "became 'not operational'\n",
6411 ioinfo[irq]->schib.pmcw.dev,
6412 irq);
6413 }
6414
6415 retry = 0;
6416
6417 }
6418 else
6419 {
6420 retry = 0; // success ...
6421
6422 } /* endif */
6423 }
6424 else if ( irq_ret != -ENODEV ) // -EIO, or -EBUSY
6425 {
6426
6427 if ( pdevstat->flag & DEVSTAT_STATUS_PENDING )
6428 {
6429 #ifdef CONFIG_DEBUG_IO
6430 printk( "SNID - Device %04X "
6431 "on Subchannel %04X "
6432 "reports pending status, "
6433 "retry : %d\n",
6434 ioinfo[irq]->schib.pmcw.dev,
6435 irq,
6436 retry);
6437 #endif
6438 if (cio_debug_initialized)
6439 debug_sprintf_event(cio_debug_msg_id, 2,
6440 "SNID - Device %04X "
6441 "on Subchannel %04X "
6442 "reports pending status, "
6443 "retry : %d\n",
6444 ioinfo[irq]->schib.pmcw.dev,
6445 irq,
6446 retry);
6447 } /* endif */
6448
6449
6450 printk( "SNID - device %04X,"
6451 " start_io() reports rc : %d, retrying ...\n",
6452 ioinfo[irq]->schib.pmcw.dev,
6453 irq_ret);
6454 if (cio_debug_initialized)
6455 debug_sprintf_event(cio_debug_msg_id, 2,
6456 "SNID - device %04X,"
6457 " start_io() reports rc : %d, retrying ...\n",
6458 ioinfo[irq]->schib.pmcw.dev,
6459 irq_ret);
6460 retry--;
6461 }
6462 else // -ENODEV ...
6463 {
6464 retry = 0;
6465
6466 } /* endif */
6467
6468 } while ( retry > 0 );
6469
6470 if ( retry == 0 )
6471 {
6472 irq_ret = -EIO;
6473
6474 } /* endif */
6475
6476 if ( init_IRQ_complete )
6477 {
6478 kfree( snid_ccw );
6479 }
6480 else
6481 {
6482 free_bootmem( (unsigned long)snid_ccw, sizeof(ccw1_t) );
6483
6484 } /* endif */
6485
6486 s390irq_spin_unlock( irq);
6487
6488 /*
6489 * If we installed the irq action handler we have to
6490 * release it too.
6491 */
6492 if ( inlreq )
6493 free_irq( irq, pdevstat);
6494
6495 } /* endif */
6496
6497 return( irq_ret );
6498 }
6499
6500 /*
6501 * s390_do_crw_pending
6502 *
6503 * Called by the machine check handler to process CRW pending
6504 * conditions. It may be a single CRW, or CRWs may be chained.
6505 *
6506 * Note : we currently process CRWs for subchannel source only
6507 */
6508 void s390_do_crw_pending( crwe_t *pcrwe )
6509 {
6510 int irq;
6511 int chpid;
6512 int dev_oper = 0;
6513 int dev_no = -1;
6514 int lock = 0;
6515
6516 #ifdef CONFIG_DEBUG_CRW
6517 printk( "do_crw_pending : starting ...\n");
6518 #endif
6519 if (cio_debug_initialized)
6520 debug_sprintf_event(cio_debug_crw_id, 2,
6521 "do_crw_pending: starting\n");
6522 while ( pcrwe != NULL )
6523 {
6524 int is_owned = 0;
6525
6526 switch ( pcrwe->crw.rsc ) {
6527 case CRW_RSC_SCH :
6528
6529 irq = pcrwe->crw.rsid;
6530
6531 #ifdef CONFIG_DEBUG_CRW
6532 printk( KERN_INFO"do_crw_pending : source is "
6533 "subchannel %04X\n", irq);
6534 #endif
6535 if (cio_debug_initialized)
6536 debug_sprintf_event(cio_debug_crw_id, 2,
6537 "source is subchannel %04X\n", irq);
6538 /*
6539 * If the device isn't known yet
6540 * we can't lock it ...
6541 */
6542 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
6543 {
6544 s390irq_spin_lock( irq );
6545 lock = 1;
6546
6547 dev_oper = ioinfo[irq]->ui.flags.oper;
6548
6549 if ( ioinfo[irq]->ui.flags.dval )
6550 dev_no = ioinfo[irq]->devno;
6551
6552 is_owned = ioinfo[irq]->ui.flags.ready;
6553
6554 } /* endif */
6555
6556 #ifdef CONFIG_DEBUG_CRW
6557 printk( "do_crw_pending : subchannel validation - start ...\n");
6558 #endif
6559 if (cio_debug_initialized)
6560 debug_sprintf_event(cio_debug_crw_id, 4,
6561 "subchannel validation - start\n");
6562 s390_validate_subchannel( irq, is_owned );
6563
6564 if ( irq > highest_subchannel )
6565 highest_subchannel = irq;
6566
6567 #ifdef CONFIG_DEBUG_CRW
6568 printk( "do_crw_pending : subchannel validation - done\n");
6569 #endif
6570 if (cio_debug_initialized)
6571 debug_sprintf_event(cio_debug_crw_id, 4,
6572 "subchannel validation - done\n");
6573 /*
6574 * After the validate processing
6575 * the ioinfo control block
6576 * should be allocated ...
6577 */
6578 if ( lock )
6579 {
6580 s390irq_spin_unlock( irq );
6581
6582 } /* endif */
6583
6584
6585 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
6586 {
6587 #ifdef CONFIG_DEBUG_CRW
6588 printk( "do_crw_pending : ioinfo at %08X\n",
6589 (unsigned)ioinfo[irq]);
6590 #endif
6591 if (cio_debug_initialized)
6592 debug_sprintf_event(cio_debug_crw_id, 4,
6593 "ioinfo at %08X\n");
6594 } /* endif */
6595
6596
6597 if ( ioinfo[irq] != INVALID_STORAGE_AREA )
6598 {
6599 if ( ioinfo[irq]->ui.flags.oper == 0 )
6600 {
6601 not_oper_handler_func_t nopfunc=ioinfo[irq]->nopfunc;
6602
6603 /* remove procfs entry */
6604 if (cio_proc_devinfo)
6605 cio_procfs_device_remove(dev_no);
6606 /*
6607 * If the device has gone
6608 * call not oper handler
6609 */
6610 if (( dev_oper == 1 )
6611 && ( nopfunc != NULL))
6612 {
6613
6614 free_irq( irq,ioinfo[irq]->irq_desc.dev_id );
6615 nopfunc( irq,DEVSTAT_DEVICE_GONE );
6616
6617 } /* endif */
6618 }
6619 else
6620 {
6621 #ifdef CONFIG_DEBUG_CRW
6622 printk( "do_crw_pending : device "
6623 "recognition - start ...\n");
6624 #endif
6625 if (cio_debug_initialized)
6626 debug_sprintf_event(cio_debug_crw_id, 4,
6627 "device recognition - start\n");
6628 s390_device_recognition_irq( irq );
6629
6630 #ifdef CONFIG_DEBUG_CRW
6631 printk( "do_crw_pending : device "
6632 "recognition - done\n");
6633 #endif
6634 if (cio_debug_initialized)
6635 debug_sprintf_event(cio_debug_crw_id, 4,
6636 "device recognition - done\n");
6637 /*
6638 * the device became operational
6639 */
6640 if ( dev_oper == 0 )
6641 {
6642 devreg_t *pdevreg;
6643
6644 pdevreg = s390_search_devreg( ioinfo[irq] );
6645
6646 if ( pdevreg != NULL )
6647 {
6648 if ( pdevreg->oper_func != NULL )
6649 pdevreg->oper_func( irq, pdevreg );
6650
6651 } /* endif */
6652
6653 /* add new procfs entry */
6654 if (cio_proc_devinfo)
6655 if (highest_subchannel < MAX_CIO_PROCFS_ENTRIES) {
6656 cio_procfs_device_create(ioinfo[irq]->devno);
6657 }
6658 }
6659 /*
6660 * ... it is and was operational, but
6661 * the devno may have changed
6662 */
6663 else if ((ioinfo[irq]->devno != dev_no) && ( ioinfo[irq]->nopfunc != NULL ))
6664 {
6665 int devno_old = ioinfo[irq]->devno;
6666 ioinfo[irq]->nopfunc( irq,
6667 DEVSTAT_REVALIDATE );
6668
6669 /* remove old entry, add new */
6670 if (cio_proc_devinfo) {
6671 cio_procfs_device_remove(devno_old);
6672 cio_procfs_device_create(ioinfo[irq]->devno);
6673 }
6674 } /* endif */
6675
6676 } /* endif */
6677
6678 /* get rid of dead procfs entries */
6679 if (cio_proc_devinfo)
6680 cio_procfs_device_purge();
6681
6682 } /* endif */
6683
6684 break;
6685
6686 case CRW_RSC_MONITOR :
6687
6688 #ifdef CONFIG_DEBUG_CRW
6689 printk( "do_crw_pending : source is "
6690 "monitoring facility\n");
6691 #endif
6692 if (cio_debug_initialized)
6693 debug_sprintf_event(cio_debug_crw_id, 2,
6694 "source is monitoring facility\n");
6695 break;
6696
6697 case CRW_RSC_CPATH :
6698
6699 chpid = pcrwe->crw.rsid;
6700
6701 #ifdef CONFIG_DEBUG_CRW
6702 printk( "do_crw_pending : source is "
6703 "channel path %02X\n", chpid);
6704 #endif
6705 if (cio_debug_initialized)
6706 debug_sprintf_event(cio_debug_crw_id, 2,
6707 "source is channel path %02X\n");
6708 break;
6709
6710 case CRW_RSC_CONFIG :
6711
6712 #ifdef CONFIG_DEBUG_CRW
6713 printk( "do_crw_pending : source is "
6714 "configuration-alert facility\n");
6715 #endif
6716 if (cio_debug_initialized)
6717 debug_sprintf_event(cio_debug_crw_id, 2,
6718 "source is configuration-alert facility\n");
6719 break;
6720
6721 case CRW_RSC_CSS :
6722
6723 #ifdef CONFIG_DEBUG_CRW
6724 printk( "do_crw_pending : source is "
6725 "channel subsystem\n");
6726 #endif
6727 if (cio_debug_initialized)
6728 debug_sprintf_event(cio_debug_crw_id, 2,
6729 "source is channel subsystem\n");
6730 break;
6731
6732 default :
6733
6734 #ifdef CONFIG_DEBUG_CRW
6735 printk( "do_crw_pending : unknown source\n");
6736 #endif
6737 if (cio_debug_initialized)
6738 debug_sprintf_event(cio_debug_crw_id, 2,
6739 "unknown source\n");
6740 break;
6741
6742 } /* endswitch */
6743
6744 pcrwe = pcrwe->crwe_next;
6745
6746 } /* endwhile */
6747
6748 #ifdef CONFIG_DEBUG_CRW
6749 printk( "do_crw_pending : done\n");
6750 #endif
6751 if (cio_debug_initialized)
6752 debug_sprintf_event(cio_debug_crw_id, 2,
6753 "do_crw_pending: done\n");
6754 return;
6755 }
6756
6757
6758 /* added by Holger Smolinski for reipl support in reipl.S */
6759 extern void do_reipl (int);
6760 void
6761 reipl ( int sch )
6762 {
6763 int i;
6764 s390_dev_info_t dev_info;
6765
6766 for ( i = 0; i <= highest_subchannel; i ++ )
6767 {
6768 if ( get_dev_info_by_irq( i, &dev_info ) == 0
6769 && (dev_info.status & DEVSTAT_DEVICE_OWNED) )
6770 {
6771 free_irq ( i, ioinfo[i]->irq_desc.dev_id );
6772 }
6773 }
6774
6775 if (MACHINE_IS_VM)
6776 cpcmd("IPL", NULL, 0);
6777 else
6778 do_reipl( 0x10000 | sch );
6779 }
6780
6781
6782 /*
6783 * Function: cio_debug_init
6784 * Initializes three debug logs (under /proc/s390dbf) for common I/O:
6785 * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
6786 * - cio_trace logs the calling of different functions
6787 * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
6788 * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
6789 */
6790 int cio_debug_init( void )
6791 {
6792 int ret = 0;
6793
6794 cio_debug_msg_id = debug_register("cio_msg",2,4,16*sizeof(long));
6795 if (cio_debug_msg_id != NULL) {
6796 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
6797 #ifdef CONFIG_DEBUG_IO
6798 debug_set_level(cio_debug_msg_id, 6);
6799 #else /* CONFIG_DEBUG_IO */
6800 debug_set_level(cio_debug_msg_id, 2);
6801 #endif /* CONFIG_DEBUG_IO */
6802 } else {
6803 ret = -1;
6804 }
6805 cio_debug_trace_id = debug_register("cio_trace",4,4,8);
6806 if (cio_debug_trace_id != NULL) {
6807 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
6808 #ifdef CONFIG_DEBUG_IO
6809 debug_set_level(cio_debug_trace_id, 6);
6810 #else /* CONFIG_DEBUG_IO */
6811 debug_set_level(cio_debug_trace_id, 2);
6812 #endif /* CONFIG_DEBUG_IO */
6813 } else {
6814 ret = -1;
6815 }
6816 cio_debug_crw_id = debug_register("cio_crw",2,4,16*sizeof(long));
6817 if (cio_debug_crw_id != NULL) {
6818 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
6819 #ifdef CONFIG_DEBUG_CRW
6820 debug_set_level(cio_debug_crw_id, 6);
6821 #else /* CONFIG_DEBUG_CRW */
6822 debug_set_level(cio_debug_crw_id, 2);
6823 #endif /* CONFIG_DEBUG_CRW */
6824 } else {
6825 ret = -1;
6826 }
6827 if (ret)
6828 return ret;
6829 cio_debug_initialized = 1;
6830 return 0;
6831 }
6832
6833 __initcall(cio_debug_init);
6834
6835 /*
6836 * Display info on subchannels in /proc/subchannels.
6837 * Adapted from procfs stuff in dasd.c by Cornelia Huck, 02/28/01.
6838 */
6839
6840 typedef struct {
6841 char *data;
6842 int len;
6843 } tempinfo_t;
6844
6845 #define MIN(a,b) ((a)<(b)?(a):(b))
6846
6847 static struct proc_dir_entry *chan_subch_entry;
6848
6849 static int chan_subch_open( struct inode *inode, struct file *file)
6850 {
6851 int rc = 0;
6852 int size = 1;
6853 int len = 0;
6854 int i = 0;
6855 int j = 0;
6856 tempinfo_t *info;
6857
6858 info = (tempinfo_t *) vmalloc( sizeof (tempinfo_t));
6859 if (info == NULL) {
6860 printk( KERN_WARNING "No memory available for data\n");
6861 return -ENOMEM;
6862 } else {
6863 file->private_data = ( void * ) info;
6864 }
6865
6866 size += (highest_subchannel+1) * 128;
6867 info->data = (char *) vmalloc( size );
6868
6869 if (size && info->data == NULL) {
6870 printk (KERN_WARNING "No memory available for data\n");
6871 vfree (info);
6872 return -ENOMEM;
6873 }
6874
6875 len += sprintf( info->data+len,
6876 "Device sch. Dev Type/Model CU in use PIM PAM POM LPUM CHPIDs\n");
6877 len += sprintf( info->data+len,
6878 "--------------------------------------------------------------------------\n");
6879
6880 for ( i=0; i <= highest_subchannel; i++) {
6881 if ( !((ioinfo[i] == NULL) || (ioinfo[i] == INVALID_STORAGE_AREA) || !(ioinfo[i]->ui.flags.oper)) ) {
6882 len += sprintf( info->data+len,
6883 "%04X %04X ",
6884 ioinfo[i]->schib.pmcw.dev,
6885 i );
6886 if ( ioinfo[i]->senseid.dev_type != 0 ) {
6887 len += sprintf( info->data+len,
6888 "%04X/%02X %04X/%02X",
6889 ioinfo[i]->senseid.dev_type,
6890 ioinfo[i]->senseid.dev_model,
6891 ioinfo[i]->senseid.cu_type,
6892 ioinfo[i]->senseid.cu_model );
6893 } else {
6894 len += sprintf( info->data+len,
6895 "%04X/%02X ",
6896 ioinfo[i]->senseid.cu_type,
6897 ioinfo[i]->senseid.cu_model );
6898 }
6899 if (ioinfo[i]->ui.flags.ready) {
6900 len += sprintf( info->data+len, " yes " );
6901 } else {
6902 len += sprintf( info->data+len, " " );
6903 }
6904 len += sprintf( info->data+len,
6905 " %02X %02X %02X %02X ",
6906 ioinfo[i]->schib.pmcw.pim,
6907 ioinfo[i]->schib.pmcw.pam,
6908 ioinfo[i]->schib.pmcw.pom,
6909 ioinfo[i]->schib.pmcw.lpum );
6910 for ( j=0; j < 8; j++ ) {
6911 len += sprintf( info->data+len,
6912 "%02X",
6913 ioinfo[i]->schib.pmcw.chpid[j] );
6914 if (j==3) {
6915 len += sprintf( info->data+len, " " );
6916 }
6917 }
6918 len += sprintf( info->data+len, "\n" );
6919 }
6920 }
6921 info->len = len;
6922
6923 return rc;
6924 }
6925
6926 static int chan_subch_close( struct inode *inode, struct file *file)
6927 {
6928 int rc = 0;
6929 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
6930
6931 if (p_info) {
6932 if (p_info->data)
6933 vfree( p_info->data );
6934 vfree( p_info );
6935 }
6936
6937 return rc;
6938 }
6939
6940 static ssize_t chan_subch_read( struct file *file, char *user_buf, size_t user_len, loff_t * offset)
6941 {
6942 loff_t len;
6943 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
6944
6945 if ( *offset>=p_info->len) {
6946 return 0;
6947 } else {
6948 len = MIN(user_len, (p_info->len - *offset));
6949 if (copy_to_user( user_buf, &(p_info->data[*offset]), len))
6950 return -EFAULT;
6951 (* offset) += len;
6952 return len;
6953 }
6954 }
6955
6956 static struct file_operations chan_subch_file_ops =
6957 {
6958 read:chan_subch_read,
6959 open:chan_subch_open,
6960 release:chan_subch_close,
6961 };
6962
6963 static int chan_proc_init( void )
6964 {
6965 chan_subch_entry = create_proc_entry( "subchannels", S_IFREG|S_IRUGO, &proc_root);
6966 chan_subch_entry->proc_fops = &chan_subch_file_ops;
6967
6968 return 1;
6969 }
6970
6971 __initcall(chan_proc_init);
6972
6973 void chan_proc_cleanup( void )
6974 {
6975 remove_proc_entry( "subchannels", &proc_root);
6976 }
6977
6978 /*
6979 * Display device specific information under /proc/deviceinfo/<devno>
6980 */
6981
6982 static struct proc_dir_entry *cio_procfs_deviceinfo_root = NULL;
6983
6984 /*
6985 * cio_procfs_device_list holds all devno-specific procfs directories
6986 */
6987
6988 typedef struct {
6989 int devno;
6990 struct proc_dir_entry *cio_device_entry;
6991 struct proc_dir_entry *cio_sensedata_entry;
6992 struct proc_dir_entry *cio_in_use_entry;
6993 struct proc_dir_entry *cio_chpid_entry;
6994 } cio_procfs_entry_t;
6995
6996 typedef struct _cio_procfs_device{
6997 struct _cio_procfs_device *next;
6998 cio_procfs_entry_t *entry;
6999 } cio_procfs_device_t;
7000
7001 cio_procfs_device_t *cio_procfs_device_list = NULL;
7002
7003 /*
7004 * File operations
7005 */
7006
7007 static int cio_device_entry_close( struct inode *inode, struct file *file)
7008 {
7009 int rc = 0;
7010 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
7011
7012 if (p_info) {
7013 if (p_info->data)
7014 vfree( p_info->data );
7015 vfree( p_info );
7016 }
7017
7018 return rc;
7019 }
7020
7021 static ssize_t cio_device_entry_read( struct file *file, char *user_buf, size_t user_len, loff_t * offset)
7022 {
7023 loff_t len;
7024 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
7025
7026 if ( *offset>=p_info->len) {
7027 return 0;
7028 } else {
7029 len = MIN(user_len, (p_info->len - *offset));
7030 if (copy_to_user( user_buf, &(p_info->data[*offset]), len))
7031 return -EFAULT;
7032 (* offset) += len;
7033 return len;
7034 }
7035 }
7036
7037 int cio_search_devno_by_inode(struct inode *inode)
7038 {
7039 int devno = -1;
7040 struct proc_dir_entry *pde;
7041 cio_procfs_device_t *tmp;
7042
7043 pde = (struct proc_dir_entry *)inode->u.generic_ip;
7044 tmp = cio_procfs_device_list;
7045
7046 while (tmp) {
7047 if ((tmp->entry->cio_device_entry == pde) ||
7048 (tmp->entry->cio_sensedata_entry == pde) ||
7049 (tmp->entry->cio_in_use_entry == pde) ||
7050 (tmp->entry->cio_chpid_entry == pde))
7051 break;
7052 tmp = tmp->next;
7053 }
7054
7055 if (tmp)
7056 devno = tmp->entry->devno;
7057
7058 return devno;
7059 }
7060
7061
7062 static int cio_sensedata_entry_open( struct inode *inode, struct file *file)
7063 {
7064 int rc = 0;
7065 int size = 1;
7066 int len = 0;
7067 tempinfo_t *info;
7068 int irq;
7069 int devno;
7070
7071 info = (tempinfo_t *) vmalloc(sizeof(tempinfo_t));
7072 if (info == NULL) {
7073 printk( KERN_WARNING "No memory available for data\n");
7074 rc = -ENOMEM;
7075 } else {
7076 file->private_data = (void *) info;
7077 size += 2 * 32;
7078 info->data = (char *) vmalloc(size);
7079 if (size && info->data == NULL) {
7080 printk(KERN_WARNING "No memory available for data\n");
7081 vfree(info);
7082 rc = -ENOMEM;
7083 } else {
7084 devno = cio_search_devno_by_inode(inode);
7085 if (devno != 0xFFFF) {
7086 irq = get_irq_by_devno(devno);
7087 if (irq != -1) {
7088 len += sprintf(info->data+len, "Dev Type/Mod: ");
7089 if (ioinfo[irq]->senseid.dev_type == 0) {
7090 len += sprintf(info->data+len, "%04X/%02X\n",
7091 ioinfo[irq]->senseid.cu_type,
7092 ioinfo[irq]->senseid.cu_model);
7093 } else {
7094 len += sprintf(info->data+len, "%04X/%02X\n",
7095 ioinfo[irq]->senseid.dev_type,
7096 ioinfo[irq]->senseid.dev_model);
7097 len+= sprintf(info->data+len, "CU Type/Mod: %04X/%02X\n",
7098 ioinfo[irq]->senseid.cu_type,
7099 ioinfo[irq]->senseid.cu_model);
7100 }
7101 }
7102 }
7103 info->len = len;
7104 }
7105 }
7106
7107 return rc;
7108 }
7109
7110 static int cio_in_use_entry_open( struct inode *inode, struct file *file)
7111 {
7112 int rc = 0;
7113 int size = 1;
7114 int len = 0;
7115 tempinfo_t *info;
7116 int irq;
7117 int devno;
7118
7119 info = (tempinfo_t *) vmalloc(sizeof(tempinfo_t));
7120 if (info == NULL) {
7121 printk( KERN_WARNING "No memory available for data\n");
7122 rc = -ENOMEM;
7123 } else {
7124 file->private_data = (void *) info;
7125 size += 8;
7126 info->data = (char *) vmalloc(size);
7127 if (size && info->data == NULL) {
7128 printk(KERN_WARNING "No memory available for data\n");
7129 vfree(info);
7130 rc = -ENOMEM;
7131 } else {
7132 devno = cio_search_devno_by_inode(inode);
7133 if (devno != -1) {
7134 irq = get_irq_by_devno(devno);
7135 if (irq != -1) {
7136 len += sprintf(info->data+len, "%s\n", ioinfo[irq]->ui.flags.ready?"yes":"no");
7137 }
7138 }
7139 info->len = len;
7140 }
7141 }
7142
7143 return rc;
7144 }
7145
7146 static int cio_chpid_entry_open( struct inode *inode, struct file *file)
7147 {
7148 int rc = 0;
7149 int size = 1;
7150 int len = 0;
7151 tempinfo_t *info;
7152 int irq;
7153 int devno;
7154 int i;
7155
7156 info = (tempinfo_t *) vmalloc(sizeof(tempinfo_t));
7157 if (info == NULL) {
7158 printk( KERN_WARNING "No memory available for data\n");
7159 rc = -ENOMEM;
7160 } else {
7161 file->private_data = (void *) info;
7162 size += 8*16;
7163 info->data = (char *) vmalloc(size);
7164 if (size && info->data == NULL) {
7165 printk(KERN_WARNING "No memory available for data\n");
7166 vfree(info);
7167 rc = -ENOMEM;
7168 } else {
7169 devno = cio_search_devno_by_inode(inode);
7170 if (devno != -1) {
7171 irq = get_irq_by_devno(devno);
7172 if (irq != -1) {
7173 for (i=0; i<8; i++) {
7174 len += sprintf(info->data+len, "CHPID[%d]: ", i);
7175 len += sprintf(info->data+len, "%02X\n", ioinfo[irq]->schib.pmcw.chpid[i]);
7176 }
7177 }
7178 }
7179 info->len = len;
7180 }
7181 }
7182
7183 return rc;
7184 }
7185
7186 static struct file_operations cio_sensedata_entry_file_ops =
7187 {
7188 read:cio_device_entry_read,
7189 open:cio_sensedata_entry_open,
7190 release:cio_device_entry_close,
7191 };
7192
7193 static struct file_operations cio_in_use_entry_file_ops =
7194 {
7195 read:cio_device_entry_read,
7196 open:cio_in_use_entry_open,
7197 release:cio_device_entry_close,
7198 };
7199
7200 static struct file_operations cio_chpid_entry_file_ops =
7201 {
7202 read:cio_device_entry_read,
7203 open:cio_chpid_entry_open,
7204 release:cio_device_entry_close,
7205 };
7206
7207 /*
7208 * Function: cio_procfs_device_create
7209 * create procfs entry for given device number
7210 * and insert it into list
7211 */
7212 int cio_procfs_device_create(int devno)
7213 {
7214 cio_procfs_entry_t *entry;
7215 cio_procfs_device_t *tmp;
7216 cio_procfs_device_t *where;
7217 char buf[8];
7218 int i;
7219 int rc = 0;
7220
7221
7222 /* create the directory entry */
7223 entry = (cio_procfs_entry_t *)kmalloc(sizeof(cio_procfs_entry_t), GFP_KERNEL);
7224 if (entry) {
7225 entry->devno = devno;
7226 sprintf(buf, "%x", devno);
7227 entry->cio_device_entry = proc_mkdir(buf, cio_procfs_deviceinfo_root);
7228
7229 if (entry->cio_device_entry) {
7230 tmp = (cio_procfs_device_t *)kmalloc(sizeof(cio_procfs_device_t), GFP_KERNEL);
7231 if (tmp) {
7232 tmp->entry = entry;
7233
7234 if (cio_procfs_device_list == NULL) {
7235 cio_procfs_device_list = tmp;
7236 tmp->next = NULL;
7237 } else {
7238 where = cio_procfs_device_list;
7239 i = where->entry->devno;
7240 while ((devno>i) && (where->next != NULL)) {
7241 where = where->next;
7242 i = where->entry->devno;
7243 }
7244 if (where->next == NULL) {
7245 where->next = tmp;
7246 tmp->next = NULL;
7247 } else {
7248 tmp->next = where->next;
7249 where->next = tmp;
7250 }
7251 }
7252 /* create the different entries */
7253 entry->cio_sensedata_entry = create_proc_entry( "sensedata", S_IFREG|S_IRUGO, entry->cio_device_entry);
7254 entry->cio_sensedata_entry->proc_fops = &cio_sensedata_entry_file_ops;
7255 entry->cio_in_use_entry = create_proc_entry( "in_use", S_IFREG|S_IRUGO, entry->cio_device_entry);
7256 entry->cio_in_use_entry->proc_fops = &cio_in_use_entry_file_ops;
7257 entry->cio_chpid_entry = create_proc_entry( "chpids", S_IFREG|S_IRUGO, entry->cio_device_entry);
7258 entry->cio_chpid_entry->proc_fops = &cio_chpid_entry_file_ops;
7259 } else {
7260 printk("Error, could not allocate procfs structure!\n");
7261 remove_proc_entry(buf, cio_procfs_deviceinfo_root);
7262 kfree(entry);
7263 rc = -ENOMEM;
7264 }
7265 } else {
7266 printk("Error, could not allocate procfs structure!\n");
7267 kfree(entry);
7268 rc = -ENOMEM;
7269 }
7270
7271 } else {
7272 printk("Error, could not allocate procfs structure!\n");
7273 rc = -ENOMEM;
7274 }
7275 return rc;
7276 }
7277
7278 /*
7279 * Function: cio_procfs_device_remove
7280 * remove procfs entry for given device number
7281 */
7282 int cio_procfs_device_remove(int devno)
7283 {
7284 int rc = 0;
7285 cio_procfs_device_t *tmp;
7286 cio_procfs_device_t *prev = NULL;
7287
7288 tmp=cio_procfs_device_list;
7289 while (tmp) {
7290 if (tmp->entry->devno == devno)
7291 break;
7292 prev = tmp;
7293 tmp = tmp->next;
7294 }
7295
7296 if (tmp) {
7297 char buf[8];
7298
7299 remove_proc_entry("sensedata", tmp->entry->cio_device_entry);
7300 remove_proc_entry("in_use", tmp->entry->cio_device_entry);
7301 remove_proc_entry("chpid", tmp->entry->cio_device_entry);
7302 sprintf(buf, "%x", devno);
7303 remove_proc_entry(buf, cio_procfs_deviceinfo_root);
7304
7305 if (tmp == cio_procfs_device_list) {
7306 cio_procfs_device_list = tmp->next;
7307 } else {
7308 prev->next = tmp->next;
7309 }
7310 kfree(tmp->entry);
7311 kfree(tmp);
7312 } else {
7313 rc = -ENODEV;
7314 }
7315
7316 return rc;
7317 }
7318
7319 /*
7320 * Function: cio_procfs_purge
7321 * purge /proc/deviceinfo of entries for gone devices
7322 */
7323
7324 int cio_procfs_device_purge(void)
7325 {
7326 int i;
7327
7328 for (i=0; i<=highest_subchannel; i++) {
7329 if (ioinfo[i] != INVALID_STORAGE_AREA) {
7330 if (!ioinfo[i]->ui.flags.oper)
7331 cio_procfs_device_remove(ioinfo[i]->devno);
7332 }
7333 }
7334
7335 return 0;
7336 }
7337
7338 /*
7339 * Function: cio_procfs_create
7340 * create /proc/deviceinfo/ and subdirs for the devices
7341 */
7342 static int cio_procfs_create( void )
7343 {
7344 int irq;
7345
7346 if (cio_proc_devinfo) {
7347
7348 cio_procfs_deviceinfo_root = proc_mkdir( "deviceinfo", &proc_root);
7349
7350 if (highest_subchannel >= MAX_CIO_PROCFS_ENTRIES) {
7351 printk(KERN_ALERT "Warning: Not enough inodes for creating all entries under /proc/deviceinfo/. "
7352 "Not every device will get an entry.\n");
7353 }
7354
7355 for (irq=0; irq<=highest_subchannel; irq++) {
7356 if (irq >= MAX_CIO_PROCFS_ENTRIES)
7357 break;
7358 if (ioinfo[irq] != INVALID_STORAGE_AREA) {
7359 if (ioinfo[irq]->ui.flags.oper)
7360 if (cio_procfs_device_create(ioinfo[irq]->devno) == -ENOMEM) {
7361 printk(KERN_CRIT "Out of memory while creating entries in /proc/deviceinfo/, "
7362 "not all devices might show up\n");
7363 break;
7364 }
7365 }
7366 }
7367
7368 }
7369
7370 return 1;
7371 }
7372
7373 __initcall(cio_procfs_create);
7374
7375 /*
7376 * Entry /proc/cio_ignore to display blacklisted ranges of devices.
7377 * un-ignore devices by piping to /proc/cio_ignore:
7378 * free all frees all blacklisted devices, free <range>,<range>,...
7379 * frees specified ranges of devnos
7380 */
7381
7382 static struct proc_dir_entry *cio_ignore_proc_entry;
7383
7384 static int cio_ignore_proc_open(struct inode *inode, struct file *file)
7385 {
7386 int rc = 0;
7387 int size = 1;
7388 int len = 0;
7389 tempinfo_t *info;
7390 dev_blacklist_range_t *tmp;
7391
7392 info = (tempinfo_t *) vmalloc(sizeof(tempinfo_t));
7393 if (info == NULL) {
7394 printk( KERN_WARNING "No memory available for data\n");
7395 rc = -ENOMEM;
7396 } else {
7397 file->private_data = (void *) info;
7398 size += nr_blacklisted_ranges * 32;
7399 info->data = (char *) vmalloc(size);
7400 if (size && info->data == NULL) {
7401 printk( KERN_WARNING "No memory available for data\n");
7402 vfree (info);
7403 rc = -ENOMEM;
7404 } else {
7405 tmp = dev_blacklist_range_head;
7406 while (tmp) {
7407 len += sprintf(info->data+len, "%04x ", tmp->from);
7408 if (tmp->to != tmp->from)
7409 len += sprintf(info->data+len, "- %04x", tmp->to);
7410 len += sprintf(info->data+len, "\n");
7411 tmp = tmp->next;
7412 }
7413 info->len = len;
7414 }
7415 }
7416 return rc;
7417 }
7418
7419 static int cio_ignore_proc_close(struct inode *inode, struct file *file)
7420 {
7421 int rc = 0;
7422 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
7423
7424 if (p_info) {
7425 if (p_info->data)
7426 vfree( p_info->data );
7427 vfree( p_info );
7428 }
7429
7430 return rc;
7431 }
7432
7433 static ssize_t cio_ignore_proc_read( struct file *file, char *user_buf, size_t user_len, loff_t * offset)
7434 {
7435 loff_t len;
7436 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
7437
7438 if ( *offset>=p_info->len) {
7439 return 0;
7440 } else {
7441 len = MIN(user_len, (p_info->len - *offset));
7442 if (copy_to_user( user_buf, &(p_info->data[*offset]), len))
7443 return -EFAULT;
7444 (* offset) += len;
7445 return len;
7446 }
7447 }
7448
7449 static ssize_t cio_ignore_proc_write (struct file *file, const char *user_buf,
7450 size_t user_len, loff_t * offset)
7451 {
7452 char *buffer = vmalloc (user_len);
7453
7454 if (buffer == NULL)
7455 return -ENOMEM;
7456 if (copy_from_user (buffer, user_buf, user_len)) {
7457 vfree (buffer);
7458 return -EFAULT;
7459 }
7460 buffer[user_len]='\0';
7461 #ifdef CIO_DEBUG_IO
7462 printk ("/proc/cio_ignore: '%s'\n", buffer);
7463 #endif /* CIO_DEBUG_IO */
7464 if (cio_debug_initialized)
7465 debug_sprintf_event(cio_debug_msg_id, 2, "/proc/cio_ignore: '%s'\n",buffer);
7466
7467 blacklist_parse_proc_parameters(buffer);
7468
7469 return user_len;
7470 }
7471
7472 static struct file_operations cio_ignore_proc_file_ops =
7473 {
7474 read:cio_ignore_proc_read,
7475 open:cio_ignore_proc_open,
7476 write:cio_ignore_proc_write,
7477 release:cio_ignore_proc_close,
7478 };
7479
7480 static int cio_ignore_proc_init(void)
7481 {
7482 cio_ignore_proc_entry = create_proc_entry("cio_ignore", S_IFREG|S_IRUGO|S_IWUSR, &proc_root);
7483 cio_ignore_proc_entry->proc_fops = &cio_ignore_proc_file_ops;
7484
7485 return 1;
7486 }
7487
7488 __initcall(cio_ignore_proc_init);
7489
7490 /* end of procfs stuff */
7491
7492 schib_t *s390_get_schib( int irq )
7493 {
7494 if ( (irq > highest_subchannel) || (irq < 0) )
7495 return NULL;
7496 if ( ioinfo[irq] == INVALID_STORAGE_AREA )
7497 return NULL;
7498 return &ioinfo[irq]->schib;
7499
7500 }
7501
7502
7503 EXPORT_SYMBOL(halt_IO);
7504 EXPORT_SYMBOL(clear_IO);
7505 EXPORT_SYMBOL(do_IO);
7506 EXPORT_SYMBOL(resume_IO);
7507 EXPORT_SYMBOL(ioinfo);
7508 EXPORT_SYMBOL(get_dev_info_by_irq);
7509 EXPORT_SYMBOL(get_dev_info_by_devno);
7510 EXPORT_SYMBOL(get_irq_by_devno);
7511 EXPORT_SYMBOL(get_devno_by_irq);
7512 EXPORT_SYMBOL(get_irq_first);
7513 EXPORT_SYMBOL(get_irq_next);
7514 EXPORT_SYMBOL(read_conf_data);
7515 EXPORT_SYMBOL(read_dev_chars);
7516 EXPORT_SYMBOL(s390_request_irq_special);
7517 EXPORT_SYMBOL(s390_get_schib);
7518 EXPORT_SYMBOL(s390_register_adapter_interrupt);
7519 EXPORT_SYMBOL(s390_unregister_adapter_interrupt);
7520