blob: fdb164f361092040954392cfd199dd2c736b9040 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02005 * Copyright IBM Corp. 1999,2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s): Ingo Adlung (adlung@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08007 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Arnd Bergmann (arndb@de.ibm.com)
9 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 */
11
12#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/cio.h>
19#include <asm/delay.h>
20#include <asm/irq.h>
Heiko Carstens5a489b92006-10-06 16:38:35 +020021#include <asm/irq_regs.h>
Heiko Carstense87bfe52006-09-20 15:59:15 +020022#include <asm/setup.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010023#include <asm/reset.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010024#include <asm/ipl.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020025#include <asm/chpid.h>
Peter Oberparleiter4e8e56c2008-01-26 14:10:44 +010026#include <asm/airq.h>
Heiko Carstens43ca5c32008-04-17 07:46:23 +020027#include <asm/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "cio.h"
29#include "css.h"
30#include "chsc.h"
31#include "ioasm.h"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010032#include "io_sch.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "blacklist.h"
34#include "cio_debug.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020035#include "chp.h"
Heiko Carstens15e9b582006-12-04 15:40:26 +010036#include "../s390mach.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38debug_info_t *cio_debug_msg_id;
39debug_info_t *cio_debug_trace_id;
40debug_info_t *cio_debug_crw_id;
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/*
43 * Function: cio_debug_init
Cornelia Huckbc698bc2008-01-26 14:10:42 +010044 * Initializes three debug logs for common I/O:
45 * - cio_msg logs generic cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * - cio_trace logs the calling of different functions
Cornelia Huckbc698bc2008-01-26 14:10:42 +010047 * - cio_crw logs machine check related cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
Cornelia Huckbc698bc2008-01-26 14:10:42 +010049static int __init cio_debug_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Peter Tiedemann361f4942008-01-26 14:11:30 +010051 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if (!cio_debug_msg_id)
53 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010054 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
55 debug_set_level(cio_debug_msg_id, 2);
Peter Tiedemann361f4942008-01-26 14:11:30 +010056 cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (!cio_debug_trace_id)
58 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010059 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
60 debug_set_level(cio_debug_trace_id, 2);
Peter Tiedemann361f4942008-01-26 14:11:30 +010061 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (!cio_debug_crw_id)
63 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010064 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
65 debug_set_level(cio_debug_crw_id, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return 0;
67
68out_unregister:
69 if (cio_debug_msg_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010070 debug_unregister(cio_debug_msg_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 if (cio_debug_trace_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010072 debug_unregister(cio_debug_trace_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (cio_debug_crw_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010074 debug_unregister(cio_debug_crw_id);
Cornelia Hucke556bbb2007-07-27 12:29:19 +020075 printk(KERN_WARNING"cio: could not initialize debugging\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return -1;
77}
78
79arch_initcall (cio_debug_init);
80
81int
82cio_set_options (struct subchannel *sch, int flags)
83{
84 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
85 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
86 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
87 return 0;
88}
89
90/* FIXME: who wants to use this? */
91int
92cio_get_options (struct subchannel *sch)
93{
94 int flags;
95
96 flags = 0;
97 if (sch->options.suspend)
98 flags |= DOIO_ALLOW_SUSPEND;
99 if (sch->options.prefetch)
100 flags |= DOIO_DENY_PREFETCH;
101 if (sch->options.inter)
102 flags |= DOIO_SUPPRESS_INTER;
103 return flags;
104}
105
106/*
107 * Use tpi to get a pending interrupt, call the interrupt handler and
108 * return a pointer to the subchannel structure.
109 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100110static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111cio_tpi(void)
112{
113 struct tpi_info *tpi_info;
114 struct subchannel *sch;
115 struct irb *irb;
116
117 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
118 if (tpi (NULL) != 1)
119 return 0;
120 irb = (struct irb *) __LC_IRB;
121 /* Store interrupt response block to lowcore. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800122 if (tsch (tpi_info->schid, irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* Not status pending or not operational. */
124 return 1;
125 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
126 if (!sch)
127 return 1;
128 local_bh_disable();
129 irq_enter ();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100130 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
132 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100133 sch->driver->irq(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100134 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 irq_exit ();
Heiko Carstens1f194a42006-07-03 00:24:46 -0700136 _local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return 1;
138}
139
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100140static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
142{
143 char dbf_text[15];
144
145 if (lpm != 0)
146 sch->lpm &= ~lpm;
147 else
148 sch->lpm = 0;
149
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800150 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Michael Ernst139b83d2008-05-07 09:22:54 +0200152 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800153 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
154 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 sprintf(dbf_text, "no%s", sch->dev.bus_id);
156 CIO_TRACE_EVENT(0, dbf_text);
157 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
158
159 return (sch->lpm ? -EACCES : -ENODEV);
160}
161
162int
163cio_start_key (struct subchannel *sch, /* subchannel structure */
164 struct ccw1 * cpa, /* logical channel prog addr */
165 __u8 lpm, /* logical path mask */
166 __u8 key) /* storage key */
167{
168 char dbf_txt[15];
169 int ccode;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100170 struct orb *orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100172 CIO_TRACE_EVENT(4, "stIO");
173 CIO_TRACE_EVENT(4, sch->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100175 orb = &to_io_private(sch)->orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 /* sch is always under 2G. */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100177 orb->intparm = (u32)(addr_t)sch;
178 orb->fmt = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100180 orb->pfch = sch->options.prefetch == 0;
181 orb->spnd = sch->options.suspend;
182 orb->ssic = sch->options.suspend && sch->options.inter;
183 orb->lpm = (lpm != 0) ? lpm : sch->lpm;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800184#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 /*
186 * for 64 bit we always support 64 bit IDAWs with 4k page size only
187 */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100188 orb->c64 = 1;
189 orb->i2k = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#endif
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100191 orb->key = key >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* issue "Start Subchannel" */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100193 orb->cpa = (__u32) __pa(cpa);
194 ccode = ssch(sch->schid, orb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 /* process condition code */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100197 sprintf(dbf_txt, "ccode:%d", ccode);
198 CIO_TRACE_EVENT(4, dbf_txt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 switch (ccode) {
201 case 0:
202 /*
203 * initialize device status information
204 */
205 sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
206 return 0;
207 case 1: /* status pending */
208 case 2: /* busy */
209 return -EBUSY;
210 default: /* device/path not operational */
211 return cio_start_handle_notoper(sch, lpm);
212 }
213}
214
215int
216cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
217{
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700218 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221/*
222 * resume suspended I/O operation
223 */
224int
225cio_resume (struct subchannel *sch)
226{
227 char dbf_txt[15];
228 int ccode;
229
230 CIO_TRACE_EVENT (4, "resIO");
231 CIO_TRACE_EVENT (4, sch->dev.bus_id);
232
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800233 ccode = rsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 sprintf (dbf_txt, "ccode:%d", ccode);
236 CIO_TRACE_EVENT (4, dbf_txt);
237
238 switch (ccode) {
239 case 0:
240 sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
241 return 0;
242 case 1:
243 return -EBUSY;
244 case 2:
245 return -EINVAL;
246 default:
247 /*
248 * useless to wait for request completion
249 * as device is no longer operational !
250 */
251 return -ENODEV;
252 }
253}
254
255/*
256 * halt I/O operation
257 */
258int
259cio_halt(struct subchannel *sch)
260{
261 char dbf_txt[15];
262 int ccode;
263
264 if (!sch)
265 return -ENODEV;
266
267 CIO_TRACE_EVENT (2, "haltIO");
268 CIO_TRACE_EVENT (2, sch->dev.bus_id);
269
270 /*
271 * Issue "Halt subchannel" and process condition code
272 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800273 ccode = hsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 sprintf (dbf_txt, "ccode:%d", ccode);
276 CIO_TRACE_EVENT (2, dbf_txt);
277
278 switch (ccode) {
279 case 0:
280 sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
281 return 0;
282 case 1: /* status pending */
283 case 2: /* busy */
284 return -EBUSY;
285 default: /* device not operational */
286 return -ENODEV;
287 }
288}
289
290/*
291 * Clear I/O operation
292 */
293int
294cio_clear(struct subchannel *sch)
295{
296 char dbf_txt[15];
297 int ccode;
298
299 if (!sch)
300 return -ENODEV;
301
302 CIO_TRACE_EVENT (2, "clearIO");
303 CIO_TRACE_EVENT (2, sch->dev.bus_id);
304
305 /*
306 * Issue "Clear subchannel" and process condition code
307 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800308 ccode = csch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 sprintf (dbf_txt, "ccode:%d", ccode);
311 CIO_TRACE_EVENT (2, dbf_txt);
312
313 switch (ccode) {
314 case 0:
315 sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
316 return 0;
317 default: /* device not operational */
318 return -ENODEV;
319 }
320}
321
322/*
323 * Function: cio_cancel
324 * Issues a "Cancel Subchannel" on the specified subchannel
325 * Note: We don't need any fancy intparms and flags here
326 * since xsch is executed synchronously.
327 * Only for common I/O internal use as for now.
328 */
329int
330cio_cancel (struct subchannel *sch)
331{
332 char dbf_txt[15];
333 int ccode;
334
335 if (!sch)
336 return -ENODEV;
337
338 CIO_TRACE_EVENT (2, "cancelIO");
339 CIO_TRACE_EVENT (2, sch->dev.bus_id);
340
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800341 ccode = xsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 sprintf (dbf_txt, "ccode:%d", ccode);
344 CIO_TRACE_EVENT (2, dbf_txt);
345
346 switch (ccode) {
347 case 0: /* success */
348 /* Update information in scsw. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800349 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return 0;
351 case 1: /* status pending */
352 return -EBUSY;
353 case 2: /* not applicable */
354 return -EINVAL;
355 default: /* not oper */
356 return -ENODEV;
357 }
358}
359
360/*
361 * Function: cio_modify
362 * Issues a "Modify Subchannel" on the specified subchannel
363 */
364int
365cio_modify (struct subchannel *sch)
366{
367 int ccode, retry, ret;
368
369 ret = 0;
370 for (retry = 0; retry < 5; retry++) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800371 ccode = msch_err (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (ccode < 0) /* -EIO if msch gets a program check. */
373 return ccode;
374 switch (ccode) {
375 case 0: /* successfull */
376 return 0;
377 case 1: /* status pending */
378 return -EBUSY;
379 case 2: /* busy */
380 udelay (100); /* allow for recovery */
381 ret = -EBUSY;
382 break;
383 case 3: /* not operational */
384 return -ENODEV;
385 }
386 }
387 return ret;
388}
389
390/*
391 * Enable subchannel.
392 */
Cornelia Huckedf22092008-04-30 13:38:39 +0200393int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 char dbf_txt[15];
396 int ccode;
397 int retry;
398 int ret;
399
400 CIO_TRACE_EVENT (2, "ensch");
401 CIO_TRACE_EVENT (2, sch->dev.bus_id);
402
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100403 if (sch_is_pseudo_sch(sch))
404 return -EINVAL;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800405 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (ccode)
407 return -ENODEV;
408
409 for (retry = 5, ret = 0; retry > 0; retry--) {
410 sch->schib.pmcw.ena = 1;
Cornelia Huckedf22092008-04-30 13:38:39 +0200411 sch->schib.pmcw.isc = sch->isc;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100412 sch->schib.pmcw.intparm = intparm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 ret = cio_modify(sch);
414 if (ret == -ENODEV)
415 break;
416 if (ret == -EIO)
417 /*
418 * Got a program check in cio_modify. Try without
419 * the concurrent sense bit the next time.
420 */
421 sch->schib.pmcw.csense = 0;
422 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800423 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (sch->schib.pmcw.ena)
425 break;
426 }
427 if (ret == -EBUSY) {
428 struct irb irb;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800429 if (tsch(sch->schid, &irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431 }
432 }
433 sprintf (dbf_txt, "ret:%d", ret);
434 CIO_TRACE_EVENT (2, dbf_txt);
435 return ret;
436}
437
438/*
439 * Disable subchannel.
440 */
441int
442cio_disable_subchannel (struct subchannel *sch)
443{
444 char dbf_txt[15];
445 int ccode;
446 int retry;
447 int ret;
448
449 CIO_TRACE_EVENT (2, "dissch");
450 CIO_TRACE_EVENT (2, sch->dev.bus_id);
451
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100452 if (sch_is_pseudo_sch(sch))
453 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800454 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (ccode == 3) /* Not operational. */
456 return -ENODEV;
457
458 if (sch->schib.scsw.actl != 0)
459 /*
460 * the disable function must not be called while there are
461 * requests pending for completion !
462 */
463 return -EBUSY;
464
465 for (retry = 5, ret = 0; retry > 0; retry--) {
466 sch->schib.pmcw.ena = 0;
467 ret = cio_modify(sch);
468 if (ret == -ENODEV)
469 break;
470 if (ret == -EBUSY)
471 /*
472 * The subchannel is busy or status pending.
473 * We'll disable when the next interrupt was delivered
474 * via the state machine.
475 */
476 break;
477 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800478 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 if (!sch->schib.pmcw.ena)
480 break;
481 }
482 }
483 sprintf (dbf_txt, "ret:%d", ret);
484 CIO_TRACE_EVENT (2, dbf_txt);
485 return ret;
486}
487
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100488int cio_create_sch_lock(struct subchannel *sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100489{
490 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
491 if (!sch->lock)
492 return -ENOMEM;
493 spin_lock_init(sch->lock);
494 return 0;
495}
496
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200497static int cio_validate_io_subchannel(struct subchannel *sch)
498{
499 /* Initialization for io subchannels. */
500 if (!css_sch_is_valid(&sch->schib))
501 return -ENODEV;
502
503 /* Devno is valid. */
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
517/**
518 * cio_validate_subchannel - basic validation of subchannel
519 * @sch: subchannel structure to be filled out
520 * @schid: subchannel id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 *
522 * Find out subchannel type and initialize struct subchannel.
523 * Return codes:
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200524 * 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * -ENXIO for non-defined subchannels
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200526 * -ENODEV for invalid subchannels or blacklisted devices
527 * -EIO for subchannels in an invalid subchannel set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 */
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200529int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
531 char dbf_txt[15];
532 int ccode;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100533 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200535 sprintf(dbf_txt, "valsch%x", schid.sch_no);
536 CIO_TRACE_EVENT(4, dbf_txt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /* Nuke all fields. */
539 memset(sch, 0, sizeof(struct subchannel));
540
Cornelia Huck2ec22982006-12-08 15:54:26 +0100541 sch->schid = schid;
542 if (cio_is_console(schid)) {
543 sch->lock = cio_get_console_lock();
544 } else {
545 err = cio_create_sch_lock(sch);
546 if (err)
547 goto out;
548 }
Cornelia Huck6ab48792006-07-12 16:39:50 +0200549 mutex_init(&sch->reg_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /* Set a name for the subchannel */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800551 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
552 schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 /*
555 * The first subchannel that is not-operational (ccode==3)
556 * indicates that there aren't any more devices available.
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800557 * If stsch gets an exception, it means the current subchannel set
558 * is not valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800560 ccode = stsch_err (schid, &sch->schib);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100561 if (ccode) {
562 err = (ccode == 3) ? -ENXIO : ccode;
563 goto out;
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 /* Copy subchannel type from path management control word. */
566 sch->st = sch->schib.pmcw.st;
Cornelia Huckc820de32008-07-14 09:58:45 +0200567
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200568 switch (sch->st) {
569 case SUBCHANNEL_TYPE_IO:
570 err = cio_validate_io_subchannel(sch);
571 break;
572 default:
573 err = 0;
574 }
575 if (err)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100576 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200578 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
579 sch->schid.ssid, sch->schid.sch_no, sch->st);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return 0;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100581out:
582 if (!cio_is_console(schid))
583 kfree(sch->lock);
584 sch->lock = NULL;
585 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * do_IRQ() handles all normal I/O device IRQ's (the special
590 * SMP cross-CPU interrupts have their own specific
591 * handlers).
592 *
593 */
594void
595do_IRQ (struct pt_regs *regs)
596{
597 struct tpi_info *tpi_info;
598 struct subchannel *sch;
599 struct irb *irb;
Heiko Carstens5a489b92006-10-06 16:38:35 +0200600 struct pt_regs *old_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Heiko Carstens5a489b92006-10-06 16:38:35 +0200602 old_regs = set_irq_regs(regs);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200603 irq_enter();
Heiko Carstens43ca5c32008-04-17 07:46:23 +0200604 s390_idle_check();
Heiko Carstens5a62b192008-04-17 07:46:25 +0200605 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
606 /* Serve timer interrupts first. */
607 clock_comparator_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /*
609 * Get interrupt information from lowcore
610 */
611 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
612 irb = (struct irb *) __LC_IRB;
613 do {
614 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
615 /*
616 * Non I/O-subchannel thin interrupts are processed differently
617 */
618 if (tpi_info->adapter_IO == 1 &&
619 tpi_info->int_type == IO_INTERRUPT_TYPE) {
620 do_adapter_IO();
621 continue;
622 }
623 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
Heiko Carstensa8061702008-04-17 07:46:26 +0200624 if (!sch) {
625 /* Clear pending interrupt condition. */
626 tsch(tpi_info->schid, irb);
627 continue;
628 }
629 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* Store interrupt response block to lowcore. */
Heiko Carstensa8061702008-04-17 07:46:26 +0200631 if (tsch(tpi_info->schid, irb) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 /* Keep subchannel information word up to date. */
633 memcpy (&sch->schib.scsw, &irb->scsw,
634 sizeof (irb->scsw));
635 /* Call interrupt handler if there is one. */
636 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100637 sch->driver->irq(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
Heiko Carstensa8061702008-04-17 07:46:26 +0200639 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 /*
641 * Are more interrupts pending?
642 * If so, the tpi instruction will update the lowcore
643 * to hold the info for the next interrupt.
644 * We don't do this for VM because a tpi drops the cpu
645 * out of the sie which costs more cycles than it saves.
646 */
647 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200648 irq_exit();
Heiko Carstens5a489b92006-10-06 16:38:35 +0200649 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652#ifdef CONFIG_CCW_CONSOLE
653static struct subchannel console_subchannel;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100654static struct io_subchannel_private console_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655static int console_subchannel_in_use;
656
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100657void *cio_get_console_priv(void)
658{
659 return &console_priv;
660}
661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662/*
663 * busy wait for the next interrupt on the console
664 */
Heiko Carstensa8061702008-04-17 07:46:26 +0200665void wait_cons_dev(void)
666 __releases(console_subchannel.lock)
667 __acquires(console_subchannel.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
669 unsigned long cr6 __attribute__ ((aligned (8)));
670 unsigned long save_cr6 __attribute__ ((aligned (8)));
671
672 /*
673 * before entering the spinlock we may already have
674 * processed the interrupt on a different CPU...
675 */
676 if (!console_subchannel_in_use)
677 return;
678
Cornelia Huck85b0d7c2008-06-10 10:03:21 +0200679 /* disable all but isc 1 (console device) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 __ctl_store (save_cr6, 6, 6);
Cornelia Huck85b0d7c2008-06-10 10:03:21 +0200681 cr6 = 0x40000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 __ctl_load (cr6, 6, 6);
683
684 do {
Cornelia Huck2ec22982006-12-08 15:54:26 +0100685 spin_unlock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (!cio_tpi())
687 cpu_relax();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100688 spin_lock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 } while (console_subchannel.schib.scsw.actl != 0);
690 /*
691 * restore previous isc value
692 */
693 __ctl_load (save_cr6, 6, 6);
694}
695
696static int
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800697cio_test_for_console(struct subchannel_id schid, void *data)
698{
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800699 if (stsch_err(schid, &console_subchannel.schib) != 0)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800700 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100701 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
702 console_subchannel.schib.pmcw.dnv &&
703 (console_subchannel.schib.pmcw.dev == console_devno)) {
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800704 console_irq = schid.sch_no;
705 return 1; /* found */
706 }
707 return 0;
708}
709
710
711static int
712cio_get_console_sch_no(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800714 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800716 init_subchannel_id(&schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 if (console_irq != -1) {
718 /* VM provided us with the irq number of the console. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800719 schid.sch_no = console_irq;
720 if (stsch(schid, &console_subchannel.schib) != 0 ||
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100721 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 !console_subchannel.schib.pmcw.dnv)
723 return -1;
724 console_devno = console_subchannel.schib.pmcw.dev;
725 } else if (console_devno != -1) {
726 /* At least the console device number is known. */
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800727 for_each_subchannel(cio_test_for_console, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (console_irq == -1)
729 return -1;
730 } else {
731 /* unlike in 2.4, we cannot autoprobe here, since
732 * the channel subsystem is not fully initialized.
733 * With some luck, the HWC console can take over */
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200734 printk(KERN_WARNING "cio: No ccw console found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return -1;
736 }
737 return console_irq;
738}
739
740struct subchannel *
741cio_probe_console(void)
742{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800743 int sch_no, ret;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800744 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 if (xchg(&console_subchannel_in_use, 1) != 0)
747 return ERR_PTR(-EBUSY);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800748 sch_no = cio_get_console_sch_no();
749 if (sch_no == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 console_subchannel_in_use = 0;
751 return ERR_PTR(-ENODEV);
752 }
753 memset(&console_subchannel, 0, sizeof(struct subchannel));
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800754 init_subchannel_id(&schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800755 schid.sch_no = sch_no;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800756 ret = cio_validate_subchannel(&console_subchannel, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 if (ret) {
758 console_subchannel_in_use = 0;
759 return ERR_PTR(-ENODEV);
760 }
761
762 /*
Cornelia Huck85b0d7c2008-06-10 10:03:21 +0200763 * enable console I/O-interrupt subclass 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 */
Cornelia Huck85b0d7c2008-06-10 10:03:21 +0200765 ctl_set_bit(6, 30);
Cornelia Huck85b0d7c2008-06-10 10:03:21 +0200766 console_subchannel.schib.pmcw.isc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 console_subchannel.schib.pmcw.intparm =
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100768 (u32)(addr_t)&console_subchannel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 ret = cio_modify(&console_subchannel);
770 if (ret) {
771 console_subchannel_in_use = 0;
772 return ERR_PTR(ret);
773 }
774 return &console_subchannel;
775}
776
777void
778cio_release_console(void)
779{
780 console_subchannel.schib.pmcw.intparm = 0;
781 cio_modify(&console_subchannel);
Cornelia Huck9689b332008-07-14 09:57:23 +0200782 ctl_clear_bit(6, 30);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 console_subchannel_in_use = 0;
784}
785
786/* Bah... hack to catch console special sausages. */
787int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800788cio_is_console(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
790 if (!console_subchannel_in_use)
791 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800792 return schid_equal(&schid, &console_subchannel.schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
795struct subchannel *
796cio_get_console_subchannel(void)
797{
798 if (!console_subchannel_in_use)
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200799 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return &console_subchannel;
801}
802
803#endif
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100804static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800805__disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
807 int retry, cc;
808
809 cc = 0;
810 for (retry=0;retry<3;retry++) {
811 schib->pmcw.ena = 0;
812 cc = msch(schid, schib);
813 if (cc)
814 return (cc==3?-ENODEV:-EBUSY);
815 stsch(schid, schib);
816 if (!schib->pmcw.ena)
817 return 0;
818 }
819 return -EBUSY; /* uhm... */
820}
821
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100822/* we can't use the normal udelay here, since it enables external interrupts */
823
824static void udelay_reset(unsigned long usecs)
825{
826 uint64_t start_cc, end_cc;
827
828 asm volatile ("STCK %0" : "=m" (start_cc));
829 do {
830 cpu_relax();
831 asm volatile ("STCK %0" : "=m" (end_cc));
832 } while (((end_cc - start_cc)/4096) < usecs);
833}
834
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100835static int
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200836__clear_io_subchannel_easy(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 int retry;
839
840 if (csch(schid))
841 return -ENODEV;
842 for (retry=0;retry<20;retry++) {
843 struct tpi_info ti;
844
845 if (tpi(&ti)) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800846 tsch(ti.schid, (struct irb *)__LC_IRB);
847 if (schid_equal(&ti.schid, &schid))
Cornelia Huck4c24da72005-09-03 15:58:01 -0700848 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100850 udelay_reset(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852 return -EBUSY;
853}
854
Michael Holzheua45e1412006-12-15 17:18:22 +0100855static int pgm_check_occured;
856
857static void cio_reset_pgm_check_handler(void)
858{
859 pgm_check_occured = 1;
860}
861
862static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
863{
864 int rc;
865
866 pgm_check_occured = 0;
Heiko Carstensab14de62007-02-05 21:18:37 +0100867 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100868 rc = stsch(schid, addr);
Heiko Carstensab14de62007-02-05 21:18:37 +0100869 s390_base_pgm_handler_fn = NULL;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100870
Heiko Carstensab14de62007-02-05 21:18:37 +0100871 /* The program check handler could have changed pgm_check_occured. */
Heiko Carstens6faf4442007-01-09 10:18:41 +0100872 barrier();
873
Michael Holzheua45e1412006-12-15 17:18:22 +0100874 if (pgm_check_occured)
875 return -EIO;
876 else
877 return rc;
878}
879
Heiko Carstens15e9b582006-12-04 15:40:26 +0100880static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800881{
882 struct schib schib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Michael Holzheua45e1412006-12-15 17:18:22 +0100884 if (stsch_reset(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800885 return -ENXIO;
886 if (!schib.pmcw.ena)
887 return 0;
888 switch(__disable_subchannel_easy(schid, &schib)) {
889 case 0:
890 case -ENODEV:
891 break;
892 default: /* -EBUSY */
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200893 switch (schib.pmcw.st) {
894 case SUBCHANNEL_TYPE_IO:
895 if (__clear_io_subchannel_easy(schid))
896 goto out; /* give up... */
897 break;
898 default:
899 /* No default clear strategy */
900 break;
901 }
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800902 stsch(schid, &schib);
903 __disable_subchannel_easy(schid, &schib);
904 }
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +0200905out:
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800906 return 0;
907}
908
Heiko Carstens15e9b582006-12-04 15:40:26 +0100909static atomic_t chpid_reset_count;
910
911static void s390_reset_chpids_mcck_handler(void)
912{
913 struct crw crw;
914 struct mci *mci;
915
916 /* Check for pending channel report word. */
917 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
918 if (!mci->cp)
919 return;
920 /* Process channel report words. */
921 while (stcrw(&crw) == 0) {
922 /* Check for responses to RCHP. */
923 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
924 atomic_dec(&chpid_reset_count);
925 }
926}
927
928#define RCHP_TIMEOUT (30 * USEC_PER_SEC)
929static void css_reset(void)
930{
931 int i, ret;
932 unsigned long long timeout;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200933 struct chp_id chpid;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100934
935 /* Reset subchannels. */
936 for_each_subchannel(__shutdown_subchannel_easy, NULL);
937 /* Reset channel paths. */
Heiko Carstensab14de62007-02-05 21:18:37 +0100938 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100939 /* Enable channel report machine checks. */
940 __ctl_set_bit(14, 28);
941 /* Temporarily reenable machine checks. */
942 local_mcck_enable();
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200943 chp_id_init(&chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100944 for (i = 0; i <= __MAX_CHPID; i++) {
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200945 chpid.id = i;
946 ret = rchp(chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100947 if ((ret == 0) || (ret == 2))
948 /*
949 * rchp either succeeded, or another rchp is already
950 * in progress. In either case, we'll get a crw.
951 */
952 atomic_inc(&chpid_reset_count);
953 }
954 /* Wait for machine check for all channel paths. */
955 timeout = get_clock() + (RCHP_TIMEOUT << 12);
956 while (atomic_read(&chpid_reset_count) != 0) {
957 if (get_clock() > timeout)
958 break;
959 cpu_relax();
960 }
961 /* Disable machine checks again. */
962 local_mcck_disable();
963 /* Disable channel report machine checks. */
964 __ctl_clear_bit(14, 28);
Heiko Carstensab14de62007-02-05 21:18:37 +0100965 s390_base_mcck_handler_fn = NULL;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100966}
967
968static struct reset_call css_reset_call = {
969 .fn = css_reset,
970};
971
972static int __init init_css_reset_call(void)
973{
974 atomic_set(&chpid_reset_count, 0);
975 register_reset_call(&css_reset_call);
976 return 0;
977}
978
979arch_initcall(init_css_reset_call);
980
981struct sch_match_id {
982 struct subchannel_id schid;
983 struct ccw_dev_id devid;
984 int rc;
985};
986
987static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
988{
989 struct schib schib;
990 struct sch_match_id *match_id = data;
991
Michael Holzheua45e1412006-12-15 17:18:22 +0100992 if (stsch_reset(schid, &schib))
Heiko Carstens15e9b582006-12-04 15:40:26 +0100993 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100994 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
Heiko Carstens15e9b582006-12-04 15:40:26 +0100995 (schib.pmcw.dev == match_id->devid.devno) &&
996 (schid.ssid == match_id->devid.ssid)) {
997 match_id->schid = schid;
998 match_id->rc = 0;
999 return 1;
1000 }
1001 return 0;
1002}
1003
1004static int reipl_find_schid(struct ccw_dev_id *devid,
1005 struct subchannel_id *schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001007 struct sch_match_id match_id;
1008
1009 match_id.devid = *devid;
1010 match_id.rc = -ENODEV;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001011 for_each_subchannel(__reipl_subchannel_match, &match_id);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001012 if (match_id.rc == 0)
1013 *schid = match_id.schid;
1014 return match_id.rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001017extern void do_reipl_asm(__u32 schid);
1018
1019/* Make sure all subchannels are quiet before we re-ipl an lpar. */
1020void reipl_ccw_dev(struct ccw_dev_id *devid)
1021{
1022 struct subchannel_id schid;
1023
Heiko Carstens15e9b582006-12-04 15:40:26 +01001024 s390_reset_system();
1025 if (reipl_find_schid(devid, &schid) != 0)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001026 panic("IPL Device not found\n");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001027 do_reipl_asm(*((__u32*)&schid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
Heiko Carstense87bfe52006-09-20 15:59:15 +02001029
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001030int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
Heiko Carstense87bfe52006-09-20 15:59:15 +02001031{
1032 struct subchannel_id schid;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001033 struct schib schib;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001034
1035 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1036 if (!schid.one)
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001037 return -ENODEV;
1038 if (stsch(schid, &schib))
1039 return -ENODEV;
Cornelia Huckb279a4f2008-01-26 14:10:45 +01001040 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1041 return -ENODEV;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001042 if (!schib.pmcw.dnv)
1043 return -ENODEV;
1044 iplinfo->devno = schib.pmcw.dev;
1045 iplinfo->is_qdio = schib.pmcw.qf;
1046 return 0;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001047}