1
2
3
4
5
6
7
8
9
10
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/slab.h>
15#include <linux/device.h>
16#include <linux/kernel_stat.h>
17#include <linux/interrupt.h>
18#include <asm/cio.h>
19#include <asm/delay.h>
20#include <asm/irq.h>
21#include <asm/irq_regs.h>
22#include <asm/setup.h>
23#include <asm/reset.h>
24#include <asm/ipl.h>
25#include <asm/chpid.h>
26#include "airq.h"
27#include "cio.h"
28#include "css.h"
29#include "chsc.h"
30#include "ioasm.h"
31#include "blacklist.h"
32#include "cio_debug.h"
33#include "chp.h"
34#include "../s390mach.h"
35
36debug_info_t *cio_debug_msg_id;
37debug_info_t *cio_debug_trace_id;
38debug_info_t *cio_debug_crw_id;
39
40int cio_show_msg;
41
42static int __init
43cio_setup (char *parm)
44{
45 if (!strcmp (parm, "yes"))
46 cio_show_msg = 1;
47 else if (!strcmp (parm, "no"))
48 cio_show_msg = 0;
49 else
50 printk(KERN_ERR "cio: cio_setup: "
51 "invalid cio_msg parameter '%s'", parm);
52 return 1;
53}
54
55__setup ("cio_msg=", cio_setup);
56
57
58
59
60
61
62
63
64
65static int __init
66cio_debug_init (void)
67{
68 cio_debug_msg_id = debug_register ("cio_msg", 16, 4, 16*sizeof (long));
69 if (!cio_debug_msg_id)
70 goto out_unregister;
71 debug_register_view (cio_debug_msg_id, &debug_sprintf_view);
72 debug_set_level (cio_debug_msg_id, 2);
73 cio_debug_trace_id = debug_register ("cio_trace", 16, 4, 16);
74 if (!cio_debug_trace_id)
75 goto out_unregister;
76 debug_register_view (cio_debug_trace_id, &debug_hex_ascii_view);
77 debug_set_level (cio_debug_trace_id, 2);
78 cio_debug_crw_id = debug_register ("cio_crw", 4, 4, 16*sizeof (long));
79 if (!cio_debug_crw_id)
80 goto out_unregister;
81 debug_register_view (cio_debug_crw_id, &debug_sprintf_view);
82 debug_set_level (cio_debug_crw_id, 2);
83 return 0;
84
85out_unregister:
86 if (cio_debug_msg_id)
87 debug_unregister (cio_debug_msg_id);
88 if (cio_debug_trace_id)
89 debug_unregister (cio_debug_trace_id);
90 if (cio_debug_crw_id)
91 debug_unregister (cio_debug_crw_id);
92 printk(KERN_WARNING"cio: could not initialize debugging\n");
93 return -1;
94}
95
96arch_initcall (cio_debug_init);
97
98int
99cio_set_options (struct subchannel *sch, int flags)
100{
101 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
102 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
103 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
104 return 0;
105}
106
107
108int
109cio_get_options (struct subchannel *sch)
110{
111 int flags;
112
113 flags = 0;
114 if (sch->options.suspend)
115 flags |= DOIO_ALLOW_SUSPEND;
116 if (sch->options.prefetch)
117 flags |= DOIO_DENY_PREFETCH;
118 if (sch->options.inter)
119 flags |= DOIO_SUPPRESS_INTER;
120 return flags;
121}
122
123
124
125
126
127static int
128cio_tpi(void)
129{
130 struct tpi_info *tpi_info;
131 struct subchannel *sch;
132 struct irb *irb;
133
134 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
135 if (tpi (NULL) != 1)
136 return 0;
137 irb = (struct irb *) __LC_IRB;
138
139 if (tsch (tpi_info->schid, irb) != 0)
140
141 return 1;
142 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
143 if (!sch)
144 return 1;
145 local_bh_disable();
146 irq_enter ();
147 spin_lock(sch->lock);
148 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
149 if (sch->driver && sch->driver->irq)
150 sch->driver->irq(&sch->dev);
151 spin_unlock(sch->lock);
152 irq_exit ();
153 _local_bh_enable();
154 return 1;
155}
156
157static int
158cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
159{
160 char dbf_text[15];
161
162 if (lpm != 0)
163 sch->lpm &= ~lpm;
164 else
165 sch->lpm = 0;
166
167 stsch (sch->schid, &sch->schib);
168
169 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
170 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
171 sch->schid.sch_no);
172 sprintf(dbf_text, "no%s", sch->dev.bus_id);
173 CIO_TRACE_EVENT(0, dbf_text);
174 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
175
176 return (sch->lpm ? -EACCES : -ENODEV);
177}
178
179int
180cio_start_key (struct subchannel *sch,
181 struct ccw1 * cpa,
182 __u8 lpm,
183 __u8 key)
184{
185 char dbf_txt[15];
186 int ccode;
187
188 CIO_TRACE_EVENT (4, "stIO");
189 CIO_TRACE_EVENT (4, sch->dev.bus_id);
190
191
192 sch->orb.intparm = (__u32)(unsigned long)sch;
193 sch->orb.fmt = 1;
194
195 sch->orb.pfch = sch->options.prefetch == 0;
196 sch->orb.spnd = sch->options.suspend;
197 sch->orb.ssic = sch->options.suspend && sch->options.inter;
198 sch->orb.lpm = (lpm != 0) ? lpm : sch->lpm;
199#ifdef CONFIG_64BIT
200
201
202
203 sch->orb.c64 = 1;
204 sch->orb.i2k = 0;
205#endif
206 sch->orb.key = key >> 4;
207
208 sch->orb.cpa = (__u32) __pa (cpa);
209 ccode = ssch (sch->schid, &sch->orb);
210
211
212 sprintf (dbf_txt, "ccode:%d", ccode);
213 CIO_TRACE_EVENT (4, dbf_txt);
214
215 switch (ccode) {
216 case 0:
217
218
219
220 sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
221 return 0;
222 case 1:
223 case 2:
224 return -EBUSY;
225 default:
226 return cio_start_handle_notoper(sch, lpm);
227 }
228}
229
230int
231cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
232{
233 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
234}
235
236
237
238
239int
240cio_resume (struct subchannel *sch)
241{
242 char dbf_txt[15];
243 int ccode;
244
245 CIO_TRACE_EVENT (4, "resIO");
246 CIO_TRACE_EVENT (4, sch->dev.bus_id);
247
248 ccode = rsch (sch->schid);
249
250 sprintf (dbf_txt, "ccode:%d", ccode);
251 CIO_TRACE_EVENT (4, dbf_txt);
252
253 switch (ccode) {
254 case 0:
255 sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
256 return 0;
257 case 1:
258 return -EBUSY;
259 case 2:
260 return -EINVAL;
261 default:
262
263
264
265
266 return -ENODEV;
267 }
268}
269
270
271
272
273int
274cio_halt(struct subchannel *sch)
275{
276 char dbf_txt[15];
277 int ccode;
278
279 if (!sch)
280 return -ENODEV;
281
282 CIO_TRACE_EVENT (2, "haltIO");
283 CIO_TRACE_EVENT (2, sch->dev.bus_id);
284
285
286
287
288 ccode = hsch (sch->schid);
289
290 sprintf (dbf_txt, "ccode:%d", ccode);
291 CIO_TRACE_EVENT (2, dbf_txt);
292
293 switch (ccode) {
294 case 0:
295 sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
296 return 0;
297 case 1:
298 case 2:
299 return -EBUSY;
300 default:
301 return -ENODEV;
302 }
303}
304
305
306
307
308int
309cio_clear(struct subchannel *sch)
310{
311 char dbf_txt[15];
312 int ccode;
313
314 if (!sch)
315 return -ENODEV;
316
317 CIO_TRACE_EVENT (2, "clearIO");
318 CIO_TRACE_EVENT (2, sch->dev.bus_id);
319
320
321
322
323 ccode = csch (sch->schid);
324
325 sprintf (dbf_txt, "ccode:%d", ccode);
326 CIO_TRACE_EVENT (2, dbf_txt);
327
328 switch (ccode) {
329 case 0:
330 sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
331 return 0;
332 default:
333 return -ENODEV;
334 }
335}
336
337
338
339
340
341
342
343
344int
345cio_cancel (struct subchannel *sch)
346{
347 char dbf_txt[15];
348 int ccode;
349
350 if (!sch)
351 return -ENODEV;
352
353 CIO_TRACE_EVENT (2, "cancelIO");
354 CIO_TRACE_EVENT (2, sch->dev.bus_id);
355
356 ccode = xsch (sch->schid);
357
358 sprintf (dbf_txt, "ccode:%d", ccode);
359 CIO_TRACE_EVENT (2, dbf_txt);
360
361 switch (ccode) {
362 case 0:
363
364 stsch (sch->schid, &sch->schib);
365 return 0;
366 case 1:
367 return -EBUSY;
368 case 2:
369 return -EINVAL;
370 default:
371 return -ENODEV;
372 }
373}
374
375
376
377
378
379int
380cio_modify (struct subchannel *sch)
381{
382 int ccode, retry, ret;
383
384 ret = 0;
385 for (retry = 0; retry < 5; retry++) {
386 ccode = msch_err (sch->schid, &sch->schib);
387 if (ccode < 0)
388 return ccode;
389 switch (ccode) {
390 case 0:
391 return 0;
392 case 1:
393 return -EBUSY;
394 case 2:
395 udelay (100);
396 ret = -EBUSY;
397 break;
398 case 3:
399 return -ENODEV;
400 }
401 }
402 return ret;
403}
404
405
406
407
408int
409cio_enable_subchannel (struct subchannel *sch, unsigned int isc)
410{
411 char dbf_txt[15];
412 int ccode;
413 int retry;
414 int ret;
415
416 CIO_TRACE_EVENT (2, "ensch");
417 CIO_TRACE_EVENT (2, sch->dev.bus_id);
418
419 if (sch_is_pseudo_sch(sch))
420 return -EINVAL;
421 ccode = stsch (sch->schid, &sch->schib);
422 if (ccode)
423 return -ENODEV;
424
425 for (retry = 5, ret = 0; retry > 0; retry--) {
426 sch->schib.pmcw.ena = 1;
427 sch->schib.pmcw.isc = isc;
428 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
429 ret = cio_modify(sch);
430 if (ret == -ENODEV)
431 break;
432 if (ret == -EIO)
433
434
435
436
437 sch->schib.pmcw.csense = 0;
438 if (ret == 0) {
439 stsch (sch->schid, &sch->schib);
440 if (sch->schib.pmcw.ena)
441 break;
442 }
443 if (ret == -EBUSY) {
444 struct irb irb;
445 if (tsch(sch->schid, &irb) != 0)
446 break;
447 }
448 }
449 sprintf (dbf_txt, "ret:%d", ret);
450 CIO_TRACE_EVENT (2, dbf_txt);
451 return ret;
452}
453
454
455
456
457int
458cio_disable_subchannel (struct subchannel *sch)
459{
460 char dbf_txt[15];
461 int ccode;
462 int retry;
463 int ret;
464
465 CIO_TRACE_EVENT (2, "dissch");
466 CIO_TRACE_EVENT (2, sch->dev.bus_id);
467
468 if (sch_is_pseudo_sch(sch))
469 return 0;
470 ccode = stsch (sch->schid, &sch->schib);
471 if (ccode == 3)
472 return -ENODEV;
473
474 if (sch->schib.scsw.actl != 0)
475
476
477
478
479 return -EBUSY;
480
481 for (retry = 5, ret = 0; retry > 0; retry--) {
482 sch->schib.pmcw.ena = 0;
483 ret = cio_modify(sch);
484 if (ret == -ENODEV)
485 break;
486 if (ret == -EBUSY)
487
488
489
490
491
492 break;
493 if (ret == 0) {
494 stsch (sch->schid, &sch->schib);
495 if (!sch->schib.pmcw.ena)
496 break;
497 }
498 }
499 sprintf (dbf_txt, "ret:%d", ret);
500 CIO_TRACE_EVENT (2, dbf_txt);
501 return ret;
502}
503
504int cio_create_sch_lock(struct subchannel *sch)
505{
506 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
507 if (!sch->lock)
508 return -ENOMEM;
509 spin_lock_init(sch->lock);
510 return 0;
511}
512
513
514
515
516
517
518
519
520
521
522
523
524
525int
526cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
527{
528 char dbf_txt[15];
529 int ccode;
530 int err;
531
532 sprintf (dbf_txt, "valsch%x", schid.sch_no);
533 CIO_TRACE_EVENT (4, dbf_txt);
534
535
536 memset(sch, 0, sizeof(struct subchannel));
537
538 sch->schid = schid;
539 if (cio_is_console(schid)) {
540 sch->lock = cio_get_console_lock();
541 } else {
542 err = cio_create_sch_lock(sch);
543 if (err)
544 goto out;
545 }
546 mutex_init(&sch->reg_mutex);
547
548 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
549 schid.sch_no);
550
551
552
553
554
555
556
557 ccode = stsch_err (schid, &sch->schib);
558 if (ccode) {
559 err = (ccode == 3) ? -ENXIO : ccode;
560 goto out;
561 }
562
563 sch->st = sch->schib.pmcw.st;
564
565
566
567
568 if (sch->st != 0) {
569 CIO_DEBUG(KERN_INFO, 0,
570 "cio: Subchannel 0.%x.%04x reports "
571 "non-I/O subchannel type %04X\n",
572 sch->schid.ssid, sch->schid.sch_no, sch->st);
573
574 err = sch->st;
575 goto out;
576 }
577
578
579 if (!sch->schib.pmcw.dnv) {
580
581 err = -ENODEV;
582 goto out;
583 }
584
585 if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
586
587
588
589
590 CIO_MSG_EVENT(4, "Blacklisted device detected "
591 "at devno %04X, subchannel set %x\n",
592 sch->schib.pmcw.dev, sch->schid.ssid);
593 err = -ENODEV;
594 goto out;
595 }
596 if (cio_is_console(sch->schid))
597 sch->opm = 0xff;
598 else
599 sch->opm = chp_get_sch_opm(sch);
600 sch->lpm = sch->schib.pmcw.pam & sch->opm;
601
602 CIO_DEBUG(KERN_INFO, 0,
603 "cio: Detected device %04x on subchannel 0.%x.%04X"
604 " - PIM = %02X, PAM = %02X, POM = %02X\n",
605 sch->schib.pmcw.dev, sch->schid.ssid,
606 sch->schid.sch_no, sch->schib.pmcw.pim,
607 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
608
609
610
611
612
613
614
615
616
617 sch->schib.pmcw.isc = 3;
618 sch->schib.pmcw.csense = 1;
619 sch->schib.pmcw.ena = 0;
620 if ((sch->lpm & (sch->lpm - 1)) != 0)
621 sch->schib.pmcw.mp = 1;
622
623 sch->schib.pmcw.mme = 0;
624 sch->schib.pmcw.mbfc = 0;
625 sch->schib.pmcw.mbi = 0;
626 sch->schib.mba = 0;
627 return 0;
628out:
629 if (!cio_is_console(schid))
630 kfree(sch->lock);
631 sch->lock = NULL;
632 return err;
633}
634
635
636
637
638
639
640
641void
642do_IRQ (struct pt_regs *regs)
643{
644 struct tpi_info *tpi_info;
645 struct subchannel *sch;
646 struct irb *irb;
647 struct pt_regs *old_regs;
648
649 old_regs = set_irq_regs(regs);
650 irq_enter();
651 asm volatile ("mc 0,0");
652 if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
653
654
655
656
657 account_ticks(S390_lowcore.int_clock);
658
659
660
661 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
662 irb = (struct irb *) __LC_IRB;
663 do {
664 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
665
666
667
668 if (tpi_info->adapter_IO == 1 &&
669 tpi_info->int_type == IO_INTERRUPT_TYPE) {
670 do_adapter_IO();
671 continue;
672 }
673 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
674 if (sch)
675 spin_lock(sch->lock);
676
677 if (tsch (tpi_info->schid, irb) == 0 && sch) {
678
679 memcpy (&sch->schib.scsw, &irb->scsw,
680 sizeof (irb->scsw));
681
682 if (sch->driver && sch->driver->irq)
683 sch->driver->irq(&sch->dev);
684 }
685 if (sch)
686 spin_unlock(sch->lock);
687
688
689
690
691
692
693
694 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
695 irq_exit();
696 set_irq_regs(old_regs);
697}
698
699#ifdef CONFIG_CCW_CONSOLE
700static struct subchannel console_subchannel;
701static int console_subchannel_in_use;
702
703
704
705
706void
707wait_cons_dev (void)
708{
709 unsigned long cr6 __attribute__ ((aligned (8)));
710 unsigned long save_cr6 __attribute__ ((aligned (8)));
711
712
713
714
715
716 if (!console_subchannel_in_use)
717 return;
718
719
720 __ctl_store (save_cr6, 6, 6);
721 cr6 = 0x01000000;
722 __ctl_load (cr6, 6, 6);
723
724 do {
725 spin_unlock(console_subchannel.lock);
726 if (!cio_tpi())
727 cpu_relax();
728 spin_lock(console_subchannel.lock);
729 } while (console_subchannel.schib.scsw.actl != 0);
730
731
732
733 __ctl_load (save_cr6, 6, 6);
734}
735
736static int
737cio_test_for_console(struct subchannel_id schid, void *data)
738{
739 if (stsch_err(schid, &console_subchannel.schib) != 0)
740 return -ENXIO;
741 if (console_subchannel.schib.pmcw.dnv &&
742 console_subchannel.schib.pmcw.dev ==
743 console_devno) {
744 console_irq = schid.sch_no;
745 return 1;
746 }
747 return 0;
748}
749
750
751static int
752cio_get_console_sch_no(void)
753{
754 struct subchannel_id schid;
755
756 init_subchannel_id(&schid);
757 if (console_irq != -1) {
758
759 schid.sch_no = console_irq;
760 if (stsch(schid, &console_subchannel.schib) != 0 ||
761 !console_subchannel.schib.pmcw.dnv)
762 return -1;
763 console_devno = console_subchannel.schib.pmcw.dev;
764 } else if (console_devno != -1) {
765
766 for_each_subchannel(cio_test_for_console, NULL);
767 if (console_irq == -1)
768 return -1;
769 } else {
770
771
772
773 printk(KERN_WARNING "cio: No ccw console found!\n");
774 return -1;
775 }
776 return console_irq;
777}
778
779struct subchannel *
780cio_probe_console(void)
781{
782 int sch_no, ret;
783 struct subchannel_id schid;
784
785 if (xchg(&console_subchannel_in_use, 1) != 0)
786 return ERR_PTR(-EBUSY);
787 sch_no = cio_get_console_sch_no();
788 if (sch_no == -1) {
789 console_subchannel_in_use = 0;
790 return ERR_PTR(-ENODEV);
791 }
792 memset(&console_subchannel, 0, sizeof(struct subchannel));
793 init_subchannel_id(&schid);
794 schid.sch_no = sch_no;
795 ret = cio_validate_subchannel(&console_subchannel, schid);
796 if (ret) {
797 console_subchannel_in_use = 0;
798 return ERR_PTR(-ENODEV);
799 }
800
801
802
803
804 ctl_set_bit(6, 24);
805 console_subchannel.schib.pmcw.isc = 7;
806 console_subchannel.schib.pmcw.intparm =
807 (__u32)(unsigned long)&console_subchannel;
808 ret = cio_modify(&console_subchannel);
809 if (ret) {
810 console_subchannel_in_use = 0;
811 return ERR_PTR(ret);
812 }
813 return &console_subchannel;
814}
815
816void
817cio_release_console(void)
818{
819 console_subchannel.schib.pmcw.intparm = 0;
820 cio_modify(&console_subchannel);
821 ctl_clear_bit(6, 24);
822 console_subchannel_in_use = 0;
823}
824
825
826int
827cio_is_console(struct subchannel_id schid)
828{
829 if (!console_subchannel_in_use)
830 return 0;
831 return schid_equal(&schid, &console_subchannel.schid);
832}
833
834struct subchannel *
835cio_get_console_subchannel(void)
836{
837 if (!console_subchannel_in_use)
838 return NULL;
839 return &console_subchannel;
840}
841
842#endif
843static int
844__disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
845{
846 int retry, cc;
847
848 cc = 0;
849 for (retry=0;retry<3;retry++) {
850 schib->pmcw.ena = 0;
851 cc = msch(schid, schib);
852 if (cc)
853 return (cc==3?-ENODEV:-EBUSY);
854 stsch(schid, schib);
855 if (!schib->pmcw.ena)
856 return 0;
857 }
858 return -EBUSY;
859}
860
861
862
863static void udelay_reset(unsigned long usecs)
864{
865 uint64_t start_cc, end_cc;
866
867 asm volatile ("STCK %0" : "=m" (start_cc));
868 do {
869 cpu_relax();
870 asm volatile ("STCK %0" : "=m" (end_cc));
871 } while (((end_cc - start_cc)/4096) < usecs);
872}
873
874static int
875__clear_subchannel_easy(struct subchannel_id schid)
876{
877 int retry;
878
879 if (csch(schid))
880 return -ENODEV;
881 for (retry=0;retry<20;retry++) {
882 struct tpi_info ti;
883
884 if (tpi(&ti)) {
885 tsch(ti.schid, (struct irb *)__LC_IRB);
886 if (schid_equal(&ti.schid, &schid))
887 return 0;
888 }
889 udelay_reset(100);
890 }
891 return -EBUSY;
892}
893
894static int pgm_check_occured;
895
896static void cio_reset_pgm_check_handler(void)
897{
898 pgm_check_occured = 1;
899}
900
901static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
902{
903 int rc;
904
905 pgm_check_occured = 0;
906 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
907 rc = stsch(schid, addr);
908 s390_base_pgm_handler_fn = NULL;
909
910
911 barrier();
912
913 if (pgm_check_occured)
914 return -EIO;
915 else
916 return rc;
917}
918
919static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
920{
921 struct schib schib;
922
923 if (stsch_reset(schid, &schib))
924 return -ENXIO;
925 if (!schib.pmcw.ena)
926 return 0;
927 switch(__disable_subchannel_easy(schid, &schib)) {
928 case 0:
929 case -ENODEV:
930 break;
931 default:
932 if (__clear_subchannel_easy(schid))
933 break;
934 stsch(schid, &schib);
935 __disable_subchannel_easy(schid, &schib);
936 }
937 return 0;
938}
939
940static atomic_t chpid_reset_count;
941
942static void s390_reset_chpids_mcck_handler(void)
943{
944 struct crw crw;
945 struct mci *mci;
946
947
948 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
949 if (!mci->cp)
950 return;
951
952 while (stcrw(&crw) == 0) {
953
954 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
955 atomic_dec(&chpid_reset_count);
956 }
957}
958
959#define RCHP_TIMEOUT (30 * USEC_PER_SEC)
960static void css_reset(void)
961{
962 int i, ret;
963 unsigned long long timeout;
964 struct chp_id chpid;
965
966
967 for_each_subchannel(__shutdown_subchannel_easy, NULL);
968
969 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
970
971 __ctl_set_bit(14, 28);
972
973 local_mcck_enable();
974 chp_id_init(&chpid);
975 for (i = 0; i <= __MAX_CHPID; i++) {
976 chpid.id = i;
977 ret = rchp(chpid);
978 if ((ret == 0) || (ret == 2))
979
980
981
982
983 atomic_inc(&chpid_reset_count);
984 }
985
986 timeout = get_clock() + (RCHP_TIMEOUT << 12);
987 while (atomic_read(&chpid_reset_count) != 0) {
988 if (get_clock() > timeout)
989 break;
990 cpu_relax();
991 }
992
993 local_mcck_disable();
994
995 __ctl_clear_bit(14, 28);
996 s390_base_mcck_handler_fn = NULL;
997}
998
999static struct reset_call css_reset_call = {
1000 .fn = css_reset,
1001};
1002
1003static int __init init_css_reset_call(void)
1004{
1005 atomic_set(&chpid_reset_count, 0);
1006 register_reset_call(&css_reset_call);
1007 return 0;
1008}
1009
1010arch_initcall(init_css_reset_call);
1011
1012struct sch_match_id {
1013 struct subchannel_id schid;
1014 struct ccw_dev_id devid;
1015 int rc;
1016};
1017
1018static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1019{
1020 struct schib schib;
1021 struct sch_match_id *match_id = data;
1022
1023 if (stsch_reset(schid, &schib))
1024 return -ENXIO;
1025 if (schib.pmcw.dnv &&
1026 (schib.pmcw.dev == match_id->devid.devno) &&
1027 (schid.ssid == match_id->devid.ssid)) {
1028 match_id->schid = schid;
1029 match_id->rc = 0;
1030 return 1;
1031 }
1032 return 0;
1033}
1034
1035static int reipl_find_schid(struct ccw_dev_id *devid,
1036 struct subchannel_id *schid)
1037{
1038 struct sch_match_id match_id;
1039
1040 match_id.devid = *devid;
1041 match_id.rc = -ENODEV;
1042 for_each_subchannel(__reipl_subchannel_match, &match_id);
1043 if (match_id.rc == 0)
1044 *schid = match_id.schid;
1045 return match_id.rc;
1046}
1047
1048extern void do_reipl_asm(__u32 schid);
1049
1050
1051void reipl_ccw_dev(struct ccw_dev_id *devid)
1052{
1053 struct subchannel_id schid;
1054
1055 s390_reset_system();
1056 if (reipl_find_schid(devid, &schid) != 0)
1057 panic("IPL Device not found\n");
1058 do_reipl_asm(*((__u32*)&schid));
1059}
1060
1061int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
1062{
1063 struct subchannel_id schid;
1064 struct schib schib;
1065
1066 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1067 if (!schid.one)
1068 return -ENODEV;
1069 if (stsch(schid, &schib))
1070 return -ENODEV;
1071 if (!schib.pmcw.dnv)
1072 return -ENODEV;
1073 iplinfo->devno = schib.pmcw.dev;
1074 iplinfo->is_qdio = schib.pmcw.qf;
1075 return 0;
1076}
1077