[S390] Cleanup cio printk messages.
[deliverable/linux.git] / drivers / s390 / cio / cio.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls
1da177e4 4 *
0ae7a7b2 5 * Copyright IBM Corp. 1999,2008
1da177e4 6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
4ce3b30c 7 * Cornelia Huck (cornelia.huck@de.ibm.com)
1da177e4
LT
8 * Arnd Bergmann (arndb@de.ibm.com)
9 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 */
11
12#include <linux/module.h>
1da177e4
LT
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>
1da177e4
LT
18#include <asm/cio.h>
19#include <asm/delay.h>
20#include <asm/irq.h>
5a489b98 21#include <asm/irq_regs.h>
e87bfe51 22#include <asm/setup.h>
15e9b586 23#include <asm/reset.h>
46b05d26 24#include <asm/ipl.h>
e5854a58 25#include <asm/chpid.h>
4e8e56c6 26#include <asm/airq.h>
3a3fc29a 27#include <asm/isc.h>
43ca5c3a 28#include <asm/cpu.h>
83262d63 29#include <asm/fcx.h>
1da177e4
LT
30#include "cio.h"
31#include "css.h"
32#include "chsc.h"
33#include "ioasm.h"
cd6b4f27 34#include "io_sch.h"
1da177e4
LT
35#include "blacklist.h"
36#include "cio_debug.h"
e6b6e10a 37#include "chp.h"
15e9b586 38#include "../s390mach.h"
1da177e4
LT
39
40debug_info_t *cio_debug_msg_id;
41debug_info_t *cio_debug_trace_id;
42debug_info_t *cio_debug_crw_id;
43
1da177e4
LT
44/*
45 * Function: cio_debug_init
bc698bcf
CH
46 * Initializes three debug logs for common I/O:
47 * - cio_msg logs generic cio messages
1da177e4 48 * - cio_trace logs the calling of different functions
bc698bcf 49 * - cio_crw logs machine check related cio messages
1da177e4 50 */
bc698bcf 51static int __init cio_debug_init(void)
1da177e4 52{
361f494d 53 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
1da177e4
LT
54 if (!cio_debug_msg_id)
55 goto out_unregister;
bc698bcf
CH
56 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
57 debug_set_level(cio_debug_msg_id, 2);
361f494d 58 cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
1da177e4
LT
59 if (!cio_debug_trace_id)
60 goto out_unregister;
bc698bcf
CH
61 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
62 debug_set_level(cio_debug_trace_id, 2);
361f494d 63 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
1da177e4
LT
64 if (!cio_debug_crw_id)
65 goto out_unregister;
bc698bcf
CH
66 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
67 debug_set_level(cio_debug_crw_id, 4);
1da177e4
LT
68 return 0;
69
70out_unregister:
71 if (cio_debug_msg_id)
bc698bcf 72 debug_unregister(cio_debug_msg_id);
1da177e4 73 if (cio_debug_trace_id)
bc698bcf 74 debug_unregister(cio_debug_trace_id);
1da177e4 75 if (cio_debug_crw_id)
bc698bcf 76 debug_unregister(cio_debug_crw_id);
1da177e4
LT
77 return -1;
78}
79
80arch_initcall (cio_debug_init);
81
82int
83cio_set_options (struct subchannel *sch, int flags)
84{
85 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
86 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
87 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
88 return 0;
89}
90
91/* FIXME: who wants to use this? */
92int
93cio_get_options (struct subchannel *sch)
94{
95 int flags;
96
97 flags = 0;
98 if (sch->options.suspend)
99 flags |= DOIO_ALLOW_SUSPEND;
100 if (sch->options.prefetch)
101 flags |= DOIO_DENY_PREFETCH;
102 if (sch->options.inter)
103 flags |= DOIO_SUPPRESS_INTER;
104 return flags;
105}
106
107/*
108 * Use tpi to get a pending interrupt, call the interrupt handler and
109 * return a pointer to the subchannel structure.
110 */
4d284cac 111static int
1da177e4
LT
112cio_tpi(void)
113{
114 struct tpi_info *tpi_info;
115 struct subchannel *sch;
116 struct irb *irb;
117
118 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
119 if (tpi (NULL) != 1)
120 return 0;
121 irb = (struct irb *) __LC_IRB;
122 /* Store interrupt response block to lowcore. */
a8237fc4 123 if (tsch (tpi_info->schid, irb) != 0)
1da177e4
LT
124 /* Not status pending or not operational. */
125 return 1;
126 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
127 if (!sch)
128 return 1;
129 local_bh_disable();
130 irq_enter ();
2ec22984 131 spin_lock(sch->lock);
23d805b6 132 memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
1da177e4 133 if (sch->driver && sch->driver->irq)
602b20f2 134 sch->driver->irq(sch);
2ec22984 135 spin_unlock(sch->lock);
1da177e4 136 irq_exit ();
1f194a4c 137 _local_bh_enable();
1da177e4
LT
138 return 1;
139}
140
4d284cac 141static int
1da177e4
LT
142cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
143{
144 char dbf_text[15];
145
146 if (lpm != 0)
147 sch->lpm &= ~lpm;
148 else
149 sch->lpm = 0;
150
a8237fc4 151 stsch (sch->schid, &sch->schib);
1da177e4 152
139b83dd 153 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
fb6958a5
CH
154 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
155 sch->schid.sch_no);
1da177e4
LT
156 sprintf(dbf_text, "no%s", sch->dev.bus_id);
157 CIO_TRACE_EVENT(0, dbf_text);
158 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
159
160 return (sch->lpm ? -EACCES : -ENODEV);
161}
162
163int
164cio_start_key (struct subchannel *sch, /* subchannel structure */
165 struct ccw1 * cpa, /* logical channel prog addr */
166 __u8 lpm, /* logical path mask */
167 __u8 key) /* storage key */
168{
169 char dbf_txt[15];
170 int ccode;
83262d63 171 union orb *orb;
1da177e4 172
cd6b4f27
CH
173 CIO_TRACE_EVENT(4, "stIO");
174 CIO_TRACE_EVENT(4, sch->dev.bus_id);
1da177e4 175
cd6b4f27 176 orb = &to_io_private(sch)->orb;
1da177e4 177 /* sch is always under 2G. */
83262d63
PO
178 orb->cmd.intparm = (u32)(addr_t)sch;
179 orb->cmd.fmt = 1;
1da177e4 180
83262d63
PO
181 orb->cmd.pfch = sch->options.prefetch == 0;
182 orb->cmd.spnd = sch->options.suspend;
183 orb->cmd.ssic = sch->options.suspend && sch->options.inter;
184 orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
347a8dc3 185#ifdef CONFIG_64BIT
1da177e4
LT
186 /*
187 * for 64 bit we always support 64 bit IDAWs with 4k page size only
188 */
83262d63
PO
189 orb->cmd.c64 = 1;
190 orb->cmd.i2k = 0;
1da177e4 191#endif
83262d63 192 orb->cmd.key = key >> 4;
1da177e4 193 /* issue "Start Subchannel" */
83262d63 194 orb->cmd.cpa = (__u32) __pa(cpa);
cd6b4f27 195 ccode = ssch(sch->schid, orb);
1da177e4
LT
196
197 /* process condition code */
cd6b4f27
CH
198 sprintf(dbf_txt, "ccode:%d", ccode);
199 CIO_TRACE_EVENT(4, dbf_txt);
1da177e4
LT
200
201 switch (ccode) {
202 case 0:
203 /*
204 * initialize device status information
205 */
23d805b6 206 sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
1da177e4
LT
207 return 0;
208 case 1: /* status pending */
209 case 2: /* busy */
210 return -EBUSY;
211 default: /* device/path not operational */
212 return cio_start_handle_notoper(sch, lpm);
213 }
214}
215
216int
217cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
218{
0b642ede 219 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
1da177e4
LT
220}
221
222/*
223 * resume suspended I/O operation
224 */
225int
226cio_resume (struct subchannel *sch)
227{
228 char dbf_txt[15];
229 int ccode;
230
231 CIO_TRACE_EVENT (4, "resIO");
232 CIO_TRACE_EVENT (4, sch->dev.bus_id);
233
a8237fc4 234 ccode = rsch (sch->schid);
1da177e4
LT
235
236 sprintf (dbf_txt, "ccode:%d", ccode);
237 CIO_TRACE_EVENT (4, dbf_txt);
238
239 switch (ccode) {
240 case 0:
23d805b6 241 sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
1da177e4
LT
242 return 0;
243 case 1:
244 return -EBUSY;
245 case 2:
246 return -EINVAL;
247 default:
248 /*
249 * useless to wait for request completion
250 * as device is no longer operational !
251 */
252 return -ENODEV;
253 }
254}
255
256/*
257 * halt I/O operation
258 */
259int
260cio_halt(struct subchannel *sch)
261{
262 char dbf_txt[15];
263 int ccode;
264
265 if (!sch)
266 return -ENODEV;
267
268 CIO_TRACE_EVENT (2, "haltIO");
269 CIO_TRACE_EVENT (2, sch->dev.bus_id);
270
271 /*
272 * Issue "Halt subchannel" and process condition code
273 */
a8237fc4 274 ccode = hsch (sch->schid);
1da177e4
LT
275
276 sprintf (dbf_txt, "ccode:%d", ccode);
277 CIO_TRACE_EVENT (2, dbf_txt);
278
279 switch (ccode) {
280 case 0:
23d805b6 281 sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
1da177e4
LT
282 return 0;
283 case 1: /* status pending */
284 case 2: /* busy */
285 return -EBUSY;
286 default: /* device not operational */
287 return -ENODEV;
288 }
289}
290
291/*
292 * Clear I/O operation
293 */
294int
295cio_clear(struct subchannel *sch)
296{
297 char dbf_txt[15];
298 int ccode;
299
300 if (!sch)
301 return -ENODEV;
302
303 CIO_TRACE_EVENT (2, "clearIO");
304 CIO_TRACE_EVENT (2, sch->dev.bus_id);
305
306 /*
307 * Issue "Clear subchannel" and process condition code
308 */
a8237fc4 309 ccode = csch (sch->schid);
1da177e4
LT
310
311 sprintf (dbf_txt, "ccode:%d", ccode);
312 CIO_TRACE_EVENT (2, dbf_txt);
313
314 switch (ccode) {
315 case 0:
23d805b6 316 sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
1da177e4
LT
317 return 0;
318 default: /* device not operational */
319 return -ENODEV;
320 }
321}
322
323/*
324 * Function: cio_cancel
325 * Issues a "Cancel Subchannel" on the specified subchannel
326 * Note: We don't need any fancy intparms and flags here
327 * since xsch is executed synchronously.
328 * Only for common I/O internal use as for now.
329 */
330int
331cio_cancel (struct subchannel *sch)
332{
333 char dbf_txt[15];
334 int ccode;
335
336 if (!sch)
337 return -ENODEV;
338
339 CIO_TRACE_EVENT (2, "cancelIO");
340 CIO_TRACE_EVENT (2, sch->dev.bus_id);
341
a8237fc4 342 ccode = xsch (sch->schid);
1da177e4
LT
343
344 sprintf (dbf_txt, "ccode:%d", ccode);
345 CIO_TRACE_EVENT (2, dbf_txt);
346
347 switch (ccode) {
348 case 0: /* success */
349 /* Update information in scsw. */
a8237fc4 350 stsch (sch->schid, &sch->schib);
1da177e4
LT
351 return 0;
352 case 1: /* status pending */
353 return -EBUSY;
354 case 2: /* not applicable */
355 return -EINVAL;
356 default: /* not oper */
357 return -ENODEV;
358 }
359}
360
361/*
362 * Function: cio_modify
363 * Issues a "Modify Subchannel" on the specified subchannel
364 */
365int
366cio_modify (struct subchannel *sch)
367{
368 int ccode, retry, ret;
369
370 ret = 0;
371 for (retry = 0; retry < 5; retry++) {
a8237fc4 372 ccode = msch_err (sch->schid, &sch->schib);
1da177e4
LT
373 if (ccode < 0) /* -EIO if msch gets a program check. */
374 return ccode;
375 switch (ccode) {
376 case 0: /* successfull */
377 return 0;
378 case 1: /* status pending */
379 return -EBUSY;
380 case 2: /* busy */
381 udelay (100); /* allow for recovery */
382 ret = -EBUSY;
383 break;
384 case 3: /* not operational */
385 return -ENODEV;
386 }
387 }
388 return ret;
389}
390
44a1c19e
CH
391/**
392 * cio_enable_subchannel - enable a subchannel.
393 * @sch: subchannel to be enabled
394 * @intparm: interruption parameter to set
1da177e4 395 */
edf22096 396int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
1da177e4
LT
397{
398 char dbf_txt[15];
399 int ccode;
400 int retry;
401 int ret;
402
403 CIO_TRACE_EVENT (2, "ensch");
404 CIO_TRACE_EVENT (2, sch->dev.bus_id);
405
d7b5a4c9
CH
406 if (sch_is_pseudo_sch(sch))
407 return -EINVAL;
a8237fc4 408 ccode = stsch (sch->schid, &sch->schib);
1da177e4
LT
409 if (ccode)
410 return -ENODEV;
411
412 for (retry = 5, ret = 0; retry > 0; retry--) {
413 sch->schib.pmcw.ena = 1;
edf22096 414 sch->schib.pmcw.isc = sch->isc;
b279a4f5 415 sch->schib.pmcw.intparm = intparm;
1da177e4
LT
416 ret = cio_modify(sch);
417 if (ret == -ENODEV)
418 break;
419 if (ret == -EIO)
420 /*
421 * Got a program check in cio_modify. Try without
422 * the concurrent sense bit the next time.
423 */
424 sch->schib.pmcw.csense = 0;
425 if (ret == 0) {
a8237fc4 426 stsch (sch->schid, &sch->schib);
1da177e4
LT
427 if (sch->schib.pmcw.ena)
428 break;
429 }
430 if (ret == -EBUSY) {
431 struct irb irb;
a8237fc4 432 if (tsch(sch->schid, &irb) != 0)
1da177e4
LT
433 break;
434 }
435 }
436 sprintf (dbf_txt, "ret:%d", ret);
437 CIO_TRACE_EVENT (2, dbf_txt);
438 return ret;
439}
44a1c19e 440EXPORT_SYMBOL_GPL(cio_enable_subchannel);
1da177e4 441
44a1c19e
CH
442/**
443 * cio_disable_subchannel - disable a subchannel.
444 * @sch: subchannel to disable
1da177e4 445 */
44a1c19e 446int cio_disable_subchannel(struct subchannel *sch)
1da177e4
LT
447{
448 char dbf_txt[15];
449 int ccode;
450 int retry;
451 int ret;
452
453 CIO_TRACE_EVENT (2, "dissch");
454 CIO_TRACE_EVENT (2, sch->dev.bus_id);
455
d7b5a4c9
CH
456 if (sch_is_pseudo_sch(sch))
457 return 0;
a8237fc4 458 ccode = stsch (sch->schid, &sch->schib);
1da177e4
LT
459 if (ccode == 3) /* Not operational. */
460 return -ENODEV;
461
23d805b6 462 if (scsw_actl(&sch->schib.scsw) != 0)
1da177e4
LT
463 /*
464 * the disable function must not be called while there are
465 * requests pending for completion !
466 */
467 return -EBUSY;
468
469 for (retry = 5, ret = 0; retry > 0; retry--) {
470 sch->schib.pmcw.ena = 0;
471 ret = cio_modify(sch);
472 if (ret == -ENODEV)
473 break;
474 if (ret == -EBUSY)
475 /*
476 * The subchannel is busy or status pending.
477 * We'll disable when the next interrupt was delivered
478 * via the state machine.
479 */
480 break;
481 if (ret == 0) {
a8237fc4 482 stsch (sch->schid, &sch->schib);
1da177e4
LT
483 if (!sch->schib.pmcw.ena)
484 break;
485 }
486 }
487 sprintf (dbf_txt, "ret:%d", ret);
488 CIO_TRACE_EVENT (2, dbf_txt);
489 return ret;
490}
44a1c19e 491EXPORT_SYMBOL_GPL(cio_disable_subchannel);
1da177e4 492
d7b5a4c9 493int cio_create_sch_lock(struct subchannel *sch)
2ec22984
CH
494{
495 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
496 if (!sch->lock)
497 return -ENOMEM;
498 spin_lock_init(sch->lock);
499 return 0;
500}
501
b3a686f4 502static int cio_check_devno_blacklisted(struct subchannel *sch)
0ae7a7b2 503{
0ae7a7b2
CH
504 if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
505 /*
506 * This device must not be known to Linux. So we simply
507 * say that there is no device and return ENODEV.
508 */
509 CIO_MSG_EVENT(6, "Blacklisted device detected "
510 "at devno %04X, subchannel set %x\n",
511 sch->schib.pmcw.dev, sch->schid.ssid);
512 return -ENODEV;
513 }
514 return 0;
515}
516
b3a686f4
CH
517static int cio_validate_io_subchannel(struct subchannel *sch)
518{
519 /* Initialization for io subchannels. */
520 if (!css_sch_is_valid(&sch->schib))
521 return -ENODEV;
522
523 /* Devno is valid. */
524 return cio_check_devno_blacklisted(sch);
525}
526
527static int cio_validate_msg_subchannel(struct subchannel *sch)
528{
529 /* Initialization for message subchannels. */
530 if (!css_sch_is_valid(&sch->schib))
531 return -ENODEV;
532
533 /* Devno is valid. */
534 return cio_check_devno_blacklisted(sch);
535}
536
0ae7a7b2
CH
537/**
538 * cio_validate_subchannel - basic validation of subchannel
539 * @sch: subchannel structure to be filled out
540 * @schid: subchannel id
1da177e4
LT
541 *
542 * Find out subchannel type and initialize struct subchannel.
543 * Return codes:
0ae7a7b2 544 * 0 on success
1da177e4 545 * -ENXIO for non-defined subchannels
0ae7a7b2
CH
546 * -ENODEV for invalid subchannels or blacklisted devices
547 * -EIO for subchannels in an invalid subchannel set
1da177e4 548 */
0ae7a7b2 549int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
1da177e4
LT
550{
551 char dbf_txt[15];
552 int ccode;
2ec22984 553 int err;
1da177e4 554
0ae7a7b2
CH
555 sprintf(dbf_txt, "valsch%x", schid.sch_no);
556 CIO_TRACE_EVENT(4, dbf_txt);
1da177e4
LT
557
558 /* Nuke all fields. */
559 memset(sch, 0, sizeof(struct subchannel));
560
2ec22984
CH
561 sch->schid = schid;
562 if (cio_is_console(schid)) {
563 sch->lock = cio_get_console_lock();
564 } else {
565 err = cio_create_sch_lock(sch);
566 if (err)
567 goto out;
568 }
6ab4879a 569 mutex_init(&sch->reg_mutex);
1da177e4 570 /* Set a name for the subchannel */
fb6958a5
CH
571 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
572 schid.sch_no);
1da177e4
LT
573
574 /*
575 * The first subchannel that is not-operational (ccode==3)
576 * indicates that there aren't any more devices available.
fb6958a5
CH
577 * If stsch gets an exception, it means the current subchannel set
578 * is not valid.
1da177e4 579 */
fb6958a5 580 ccode = stsch_err (schid, &sch->schib);
2ec22984
CH
581 if (ccode) {
582 err = (ccode == 3) ? -ENXIO : ccode;
583 goto out;
584 }
1da177e4
LT
585 /* Copy subchannel type from path management control word. */
586 sch->st = sch->schib.pmcw.st;
c820de39 587
0ae7a7b2
CH
588 switch (sch->st) {
589 case SUBCHANNEL_TYPE_IO:
590 err = cio_validate_io_subchannel(sch);
591 break;
b3a686f4
CH
592 case SUBCHANNEL_TYPE_MSG:
593 err = cio_validate_msg_subchannel(sch);
594 break;
0ae7a7b2
CH
595 default:
596 err = 0;
1da177e4 597 }
0ae7a7b2 598 if (err)
808e4888 599 goto out;
808e4888 600
0ae7a7b2
CH
601 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
602 sch->schid.ssid, sch->schid.sch_no, sch->st);
1da177e4 603 return 0;
2ec22984
CH
604out:
605 if (!cio_is_console(schid))
606 kfree(sch->lock);
607 sch->lock = NULL;
608 return err;
1da177e4
LT
609}
610
611/*
612 * do_IRQ() handles all normal I/O device IRQ's (the special
613 * SMP cross-CPU interrupts have their own specific
614 * handlers).
615 *
616 */
617void
618do_IRQ (struct pt_regs *regs)
619{
620 struct tpi_info *tpi_info;
621 struct subchannel *sch;
622 struct irb *irb;
5a489b98 623 struct pt_regs *old_regs;
1da177e4 624
5a489b98 625 old_regs = set_irq_regs(regs);
9d0a57cb 626 irq_enter();
43ca5c3a 627 s390_idle_check();
5a62b192
HC
628 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
629 /* Serve timer interrupts first. */
630 clock_comparator_work();
1da177e4
LT
631 /*
632 * Get interrupt information from lowcore
633 */
634 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
635 irb = (struct irb *) __LC_IRB;
636 do {
637 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
638 /*
639 * Non I/O-subchannel thin interrupts are processed differently
640 */
641 if (tpi_info->adapter_IO == 1 &&
642 tpi_info->int_type == IO_INTERRUPT_TYPE) {
da7c5af8 643 do_adapter_IO(tpi_info->isc);
1da177e4
LT
644 continue;
645 }
646 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
a806170e
HC
647 if (!sch) {
648 /* Clear pending interrupt condition. */
649 tsch(tpi_info->schid, irb);
650 continue;
651 }
652 spin_lock(sch->lock);
1da177e4 653 /* Store interrupt response block to lowcore. */
a806170e 654 if (tsch(tpi_info->schid, irb) == 0) {
1da177e4
LT
655 /* Keep subchannel information word up to date. */
656 memcpy (&sch->schib.scsw, &irb->scsw,
657 sizeof (irb->scsw));
658 /* Call interrupt handler if there is one. */
659 if (sch->driver && sch->driver->irq)
602b20f2 660 sch->driver->irq(sch);
1da177e4 661 }
a806170e 662 spin_unlock(sch->lock);
1da177e4
LT
663 /*
664 * Are more interrupts pending?
665 * If so, the tpi instruction will update the lowcore
666 * to hold the info for the next interrupt.
667 * We don't do this for VM because a tpi drops the cpu
668 * out of the sie which costs more cycles than it saves.
669 */
670 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
9d0a57cb 671 irq_exit();
5a489b98 672 set_irq_regs(old_regs);
1da177e4
LT
673}
674
675#ifdef CONFIG_CCW_CONSOLE
676static struct subchannel console_subchannel;
cd6b4f27 677static struct io_subchannel_private console_priv;
1da177e4
LT
678static int console_subchannel_in_use;
679
cd6b4f27
CH
680void *cio_get_console_priv(void)
681{
682 return &console_priv;
683}
684
1da177e4
LT
685/*
686 * busy wait for the next interrupt on the console
687 */
a806170e
HC
688void wait_cons_dev(void)
689 __releases(console_subchannel.lock)
690 __acquires(console_subchannel.lock)
1da177e4
LT
691{
692 unsigned long cr6 __attribute__ ((aligned (8)));
693 unsigned long save_cr6 __attribute__ ((aligned (8)));
694
695 /*
696 * before entering the spinlock we may already have
697 * processed the interrupt on a different CPU...
698 */
699 if (!console_subchannel_in_use)
700 return;
701
3a3fc29a 702 /* disable all but the console isc */
1da177e4 703 __ctl_store (save_cr6, 6, 6);
3a3fc29a 704 cr6 = 1UL << (31 - CONSOLE_ISC);
1da177e4
LT
705 __ctl_load (cr6, 6, 6);
706
707 do {
2ec22984 708 spin_unlock(console_subchannel.lock);
1da177e4
LT
709 if (!cio_tpi())
710 cpu_relax();
2ec22984 711 spin_lock(console_subchannel.lock);
23d805b6 712 } while (console_subchannel.schib.scsw.cmd.actl != 0);
1da177e4
LT
713 /*
714 * restore previous isc value
715 */
716 __ctl_load (save_cr6, 6, 6);
717}
718
719static int
f97a56fb
CH
720cio_test_for_console(struct subchannel_id schid, void *data)
721{
fb6958a5 722 if (stsch_err(schid, &console_subchannel.schib) != 0)
f97a56fb 723 return -ENXIO;
b279a4f5
CH
724 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
725 console_subchannel.schib.pmcw.dnv &&
726 (console_subchannel.schib.pmcw.dev == console_devno)) {
f97a56fb
CH
727 console_irq = schid.sch_no;
728 return 1; /* found */
729 }
730 return 0;
731}
732
733
734static int
735cio_get_console_sch_no(void)
1da177e4 736{
a8237fc4 737 struct subchannel_id schid;
1da177e4 738
a8237fc4 739 init_subchannel_id(&schid);
1da177e4
LT
740 if (console_irq != -1) {
741 /* VM provided us with the irq number of the console. */
a8237fc4
CH
742 schid.sch_no = console_irq;
743 if (stsch(schid, &console_subchannel.schib) != 0 ||
b279a4f5 744 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
1da177e4
LT
745 !console_subchannel.schib.pmcw.dnv)
746 return -1;
747 console_devno = console_subchannel.schib.pmcw.dev;
748 } else if (console_devno != -1) {
749 /* At least the console device number is known. */
f97a56fb 750 for_each_subchannel(cio_test_for_console, NULL);
1da177e4
LT
751 if (console_irq == -1)
752 return -1;
753 } else {
754 /* unlike in 2.4, we cannot autoprobe here, since
755 * the channel subsystem is not fully initialized.
756 * With some luck, the HWC console can take over */
1da177e4
LT
757 return -1;
758 }
759 return console_irq;
760}
761
762struct subchannel *
763cio_probe_console(void)
764{
f97a56fb 765 int sch_no, ret;
a8237fc4 766 struct subchannel_id schid;
1da177e4
LT
767
768 if (xchg(&console_subchannel_in_use, 1) != 0)
769 return ERR_PTR(-EBUSY);
f97a56fb
CH
770 sch_no = cio_get_console_sch_no();
771 if (sch_no == -1) {
1da177e4 772 console_subchannel_in_use = 0;
c78aa6cb 773 printk(KERN_WARNING "cio: No ccw console found!\n");
1da177e4
LT
774 return ERR_PTR(-ENODEV);
775 }
776 memset(&console_subchannel, 0, sizeof(struct subchannel));
a8237fc4 777 init_subchannel_id(&schid);
f97a56fb 778 schid.sch_no = sch_no;
a8237fc4 779 ret = cio_validate_subchannel(&console_subchannel, schid);
1da177e4
LT
780 if (ret) {
781 console_subchannel_in_use = 0;
782 return ERR_PTR(-ENODEV);
783 }
784
785 /*
3a3fc29a 786 * enable console I/O-interrupt subclass
1da177e4 787 */
6ef556cc 788 isc_register(CONSOLE_ISC);
3a3fc29a 789 console_subchannel.schib.pmcw.isc = CONSOLE_ISC;
1da177e4 790 console_subchannel.schib.pmcw.intparm =
cd6b4f27 791 (u32)(addr_t)&console_subchannel;
1da177e4
LT
792 ret = cio_modify(&console_subchannel);
793 if (ret) {
6ef556cc 794 isc_unregister(CONSOLE_ISC);
1da177e4
LT
795 console_subchannel_in_use = 0;
796 return ERR_PTR(ret);
797 }
798 return &console_subchannel;
799}
800
801void
802cio_release_console(void)
803{
804 console_subchannel.schib.pmcw.intparm = 0;
805 cio_modify(&console_subchannel);
6ef556cc 806 isc_unregister(CONSOLE_ISC);
1da177e4
LT
807 console_subchannel_in_use = 0;
808}
809
810/* Bah... hack to catch console special sausages. */
811int
a8237fc4 812cio_is_console(struct subchannel_id schid)
1da177e4
LT
813{
814 if (!console_subchannel_in_use)
815 return 0;
a8237fc4 816 return schid_equal(&schid, &console_subchannel.schid);
1da177e4
LT
817}
818
819struct subchannel *
820cio_get_console_subchannel(void)
821{
822 if (!console_subchannel_in_use)
d2c993d8 823 return NULL;
1da177e4
LT
824 return &console_subchannel;
825}
826
827#endif
4d284cac 828static int
a8237fc4 829__disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
1da177e4
LT
830{
831 int retry, cc;
832
833 cc = 0;
834 for (retry=0;retry<3;retry++) {
835 schib->pmcw.ena = 0;
836 cc = msch(schid, schib);
837 if (cc)
838 return (cc==3?-ENODEV:-EBUSY);
839 stsch(schid, schib);
840 if (!schib->pmcw.ena)
841 return 0;
842 }
843 return -EBUSY; /* uhm... */
844}
845
d54853ef
MS
846/* we can't use the normal udelay here, since it enables external interrupts */
847
848static void udelay_reset(unsigned long usecs)
849{
850 uint64_t start_cc, end_cc;
851
852 asm volatile ("STCK %0" : "=m" (start_cc));
853 do {
854 cpu_relax();
855 asm volatile ("STCK %0" : "=m" (end_cc));
856 } while (((end_cc - start_cc)/4096) < usecs);
857}
858
4d284cac 859static int
0ae7a7b2 860__clear_io_subchannel_easy(struct subchannel_id schid)
1da177e4
LT
861{
862 int retry;
863
864 if (csch(schid))
865 return -ENODEV;
866 for (retry=0;retry<20;retry++) {
867 struct tpi_info ti;
868
869 if (tpi(&ti)) {
a8237fc4
CH
870 tsch(ti.schid, (struct irb *)__LC_IRB);
871 if (schid_equal(&ti.schid, &schid))
4c24da79 872 return 0;
1da177e4 873 }
d54853ef 874 udelay_reset(100);
1da177e4
LT
875 }
876 return -EBUSY;
877}
878
9d92a7e1
CH
879static void __clear_chsc_subchannel_easy(void)
880{
881 /* It seems we can only wait for a bit here :/ */
882 udelay_reset(100);
883}
884
a45e1414
MH
885static int pgm_check_occured;
886
887static void cio_reset_pgm_check_handler(void)
888{
889 pgm_check_occured = 1;
890}
891
892static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
893{
894 int rc;
895
896 pgm_check_occured = 0;
ab14de6c 897 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
6faf4444 898 rc = stsch(schid, addr);
ab14de6c 899 s390_base_pgm_handler_fn = NULL;
aa77015c 900
ab14de6c 901 /* The program check handler could have changed pgm_check_occured. */
6faf4444 902 barrier();
aa77015c 903
a45e1414
MH
904 if (pgm_check_occured)
905 return -EIO;
906 else
907 return rc;
908}
909
15e9b586 910static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
f97a56fb
CH
911{
912 struct schib schib;
913
a45e1414 914 if (stsch_reset(schid, &schib))
f97a56fb
CH
915 return -ENXIO;
916 if (!schib.pmcw.ena)
917 return 0;
918 switch(__disable_subchannel_easy(schid, &schib)) {
919 case 0:
920 case -ENODEV:
921 break;
922 default: /* -EBUSY */
0ae7a7b2
CH
923 switch (schib.pmcw.st) {
924 case SUBCHANNEL_TYPE_IO:
925 if (__clear_io_subchannel_easy(schid))
926 goto out; /* give up... */
927 break;
9d92a7e1
CH
928 case SUBCHANNEL_TYPE_CHSC:
929 __clear_chsc_subchannel_easy();
930 break;
0ae7a7b2
CH
931 default:
932 /* No default clear strategy */
933 break;
934 }
f97a56fb
CH
935 stsch(schid, &schib);
936 __disable_subchannel_easy(schid, &schib);
937 }
0ae7a7b2 938out:
f97a56fb
CH
939 return 0;
940}
1da177e4 941
15e9b586
HC
942static atomic_t chpid_reset_count;
943
944static void s390_reset_chpids_mcck_handler(void)
945{
946 struct crw crw;
947 struct mci *mci;
948
949 /* Check for pending channel report word. */
950 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
951 if (!mci->cp)
952 return;
953 /* Process channel report words. */
954 while (stcrw(&crw) == 0) {
955 /* Check for responses to RCHP. */
956 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
957 atomic_dec(&chpid_reset_count);
958 }
959}
960
961#define RCHP_TIMEOUT (30 * USEC_PER_SEC)
962static void css_reset(void)
963{
964 int i, ret;
965 unsigned long long timeout;
f86635fa 966 struct chp_id chpid;
15e9b586
HC
967
968 /* Reset subchannels. */
969 for_each_subchannel(__shutdown_subchannel_easy, NULL);
970 /* Reset channel paths. */
ab14de6c 971 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
15e9b586
HC
972 /* Enable channel report machine checks. */
973 __ctl_set_bit(14, 28);
974 /* Temporarily reenable machine checks. */
975 local_mcck_enable();
f86635fa 976 chp_id_init(&chpid);
15e9b586 977 for (i = 0; i <= __MAX_CHPID; i++) {
f86635fa
PO
978 chpid.id = i;
979 ret = rchp(chpid);
15e9b586
HC
980 if ((ret == 0) || (ret == 2))
981 /*
982 * rchp either succeeded, or another rchp is already
983 * in progress. In either case, we'll get a crw.
984 */
985 atomic_inc(&chpid_reset_count);
986 }
987 /* Wait for machine check for all channel paths. */
988 timeout = get_clock() + (RCHP_TIMEOUT << 12);
989 while (atomic_read(&chpid_reset_count) != 0) {
990 if (get_clock() > timeout)
991 break;
992 cpu_relax();
993 }
994 /* Disable machine checks again. */
995 local_mcck_disable();
996 /* Disable channel report machine checks. */
997 __ctl_clear_bit(14, 28);
ab14de6c 998 s390_base_mcck_handler_fn = NULL;
15e9b586
HC
999}
1000
1001static struct reset_call css_reset_call = {
1002 .fn = css_reset,
1003};
1004
1005static int __init init_css_reset_call(void)
1006{
1007 atomic_set(&chpid_reset_count, 0);
1008 register_reset_call(&css_reset_call);
1009 return 0;
1010}
1011
1012arch_initcall(init_css_reset_call);
1013
1014struct sch_match_id {
1015 struct subchannel_id schid;
1016 struct ccw_dev_id devid;
1017 int rc;
1018};
1019
1020static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1021{
1022 struct schib schib;
1023 struct sch_match_id *match_id = data;
1024
a45e1414 1025 if (stsch_reset(schid, &schib))
15e9b586 1026 return -ENXIO;
b279a4f5 1027 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
15e9b586
HC
1028 (schib.pmcw.dev == match_id->devid.devno) &&
1029 (schid.ssid == match_id->devid.ssid)) {
1030 match_id->schid = schid;
1031 match_id->rc = 0;
1032 return 1;
1033 }
1034 return 0;
1035}
1036
1037static int reipl_find_schid(struct ccw_dev_id *devid,
1038 struct subchannel_id *schid)
1da177e4 1039{
ff6b8ea6
MH
1040 struct sch_match_id match_id;
1041
1042 match_id.devid = *devid;
1043 match_id.rc = -ENODEV;
15e9b586 1044 for_each_subchannel(__reipl_subchannel_match, &match_id);
ff6b8ea6
MH
1045 if (match_id.rc == 0)
1046 *schid = match_id.schid;
1047 return match_id.rc;
1da177e4
LT
1048}
1049
ff6b8ea6
MH
1050extern void do_reipl_asm(__u32 schid);
1051
1da177e4 1052/* Make sure all subchannels are quiet before we re-ipl an lpar. */
ff6b8ea6 1053void reipl_ccw_dev(struct ccw_dev_id *devid)
1da177e4 1054{
ff6b8ea6
MH
1055 struct subchannel_id schid;
1056
15e9b586
HC
1057 s390_reset_system();
1058 if (reipl_find_schid(devid, &schid) != 0)
ff6b8ea6 1059 panic("IPL Device not found\n");
ff6b8ea6 1060 do_reipl_asm(*((__u32*)&schid));
1da177e4 1061}
e87bfe51 1062
6fc321fd 1063int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
e87bfe51
HC
1064{
1065 struct subchannel_id schid;
6fc321fd 1066 struct schib schib;
e87bfe51
HC
1067
1068 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1069 if (!schid.one)
6fc321fd
HC
1070 return -ENODEV;
1071 if (stsch(schid, &schib))
1072 return -ENODEV;
b279a4f5
CH
1073 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1074 return -ENODEV;
6fc321fd
HC
1075 if (!schib.pmcw.dnv)
1076 return -ENODEV;
1077 iplinfo->devno = schib.pmcw.dev;
1078 iplinfo->is_qdio = schib.pmcw.qf;
1079 return 0;
e87bfe51 1080}
83262d63
PO
1081
1082/**
1083 * cio_tm_start_key - perform start function
1084 * @sch: subchannel on which to perform the start function
1085 * @tcw: transport-command word to be started
1086 * @lpm: mask of paths to use
1087 * @key: storage key to use for storage access
1088 *
1089 * Start the tcw on the given subchannel. Return zero on success, non-zero
1090 * otherwise.
1091 */
1092int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
1093{
1094 int cc;
1095 union orb *orb = &to_io_private(sch)->orb;
1096
1097 memset(orb, 0, sizeof(union orb));
1098 orb->tm.intparm = (u32) (addr_t) sch;
1099 orb->tm.key = key >> 4;
1100 orb->tm.b = 1;
1101 orb->tm.lpm = lpm ? lpm : sch->lpm;
1102 orb->tm.tcw = (u32) (addr_t) tcw;
1103 cc = ssch(sch->schid, orb);
1104 switch (cc) {
1105 case 0:
1106 return 0;
1107 case 1:
1108 case 2:
1109 return -EBUSY;
1110 default:
1111 return cio_start_handle_notoper(sch, lpm);
1112 }
1113}
1114
1115/**
1116 * cio_tm_intrg - perform interrogate function
1117 * @sch - subchannel on which to perform the interrogate function
1118 *
1119 * If the specified subchannel is running in transport-mode, perform the
1120 * interrogate function. Return zero on success, non-zero otherwie.
1121 */
1122int cio_tm_intrg(struct subchannel *sch)
1123{
1124 int cc;
1125
1126 if (!to_io_private(sch)->orb.tm.b)
1127 return -EINVAL;
1128 cc = xsch(sch->schid);
1129 switch (cc) {
1130 case 0:
1131 case 2:
1132 return 0;
1133 case 1:
1134 return -EBUSY;
1135 default:
1136 return -ENODEV;
1137 }
1138}
This page took 0.422637 seconds and 5 git commands to generate.