blob: f16c15c13f6e482deb5d2a5a38f6e9f7eb868c04 [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 *
Michael Holzheuaa770152006-12-28 00:35:36 +01005 * Copyright (C) IBM Corp. 1999,2006
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 Carstens5a489b982006-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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "cio.h"
28#include "css.h"
29#include "chsc.h"
30#include "ioasm.h"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010031#include "io_sch.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "blacklist.h"
33#include "cio_debug.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020034#include "chp.h"
Heiko Carstens15e9b582006-12-04 15:40:26 +010035#include "../s390mach.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37debug_info_t *cio_debug_msg_id;
38debug_info_t *cio_debug_trace_id;
39debug_info_t *cio_debug_crw_id;
40
41int cio_show_msg;
42
43static int __init
44cio_setup (char *parm)
45{
46 if (!strcmp (parm, "yes"))
47 cio_show_msg = 1;
48 else if (!strcmp (parm, "no"))
49 cio_show_msg = 0;
50 else
Cornelia Hucke556bbb2007-07-27 12:29:19 +020051 printk(KERN_ERR "cio: cio_setup: "
52 "invalid cio_msg parameter '%s'", parm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return 1;
54}
55
56__setup ("cio_msg=", cio_setup);
57
58/*
59 * Function: cio_debug_init
Cornelia Huckbc698bc2008-01-26 14:10:42 +010060 * Initializes three debug logs for common I/O:
61 * - cio_msg logs generic cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * - cio_trace logs the calling of different functions
Cornelia Huckbc698bc2008-01-26 14:10:42 +010063 * - cio_crw logs machine check related cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
Cornelia Huckbc698bc2008-01-26 14:10:42 +010065static int __init cio_debug_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Cornelia Huckbc698bc2008-01-26 14:10:42 +010067 cio_debug_msg_id = debug_register("cio_msg", 16, 4, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 if (!cio_debug_msg_id)
69 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010070 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
71 debug_set_level(cio_debug_msg_id, 2);
72 cio_debug_trace_id = debug_register("cio_trace", 16, 4, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!cio_debug_trace_id)
74 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010075 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
76 debug_set_level(cio_debug_trace_id, 2);
77 cio_debug_crw_id = debug_register("cio_crw", 16, 4, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (!cio_debug_crw_id)
79 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010080 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
81 debug_set_level(cio_debug_crw_id, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return 0;
83
84out_unregister:
85 if (cio_debug_msg_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010086 debug_unregister(cio_debug_msg_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (cio_debug_trace_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010088 debug_unregister(cio_debug_trace_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if (cio_debug_crw_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010090 debug_unregister(cio_debug_crw_id);
Cornelia Hucke556bbb2007-07-27 12:29:19 +020091 printk(KERN_WARNING"cio: could not initialize debugging\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return -1;
93}
94
95arch_initcall (cio_debug_init);
96
97int
98cio_set_options (struct subchannel *sch, int flags)
99{
100 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
101 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
102 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
103 return 0;
104}
105
106/* FIXME: who wants to use this? */
107int
108cio_get_options (struct subchannel *sch)
109{
110 int flags;
111
112 flags = 0;
113 if (sch->options.suspend)
114 flags |= DOIO_ALLOW_SUSPEND;
115 if (sch->options.prefetch)
116 flags |= DOIO_DENY_PREFETCH;
117 if (sch->options.inter)
118 flags |= DOIO_SUPPRESS_INTER;
119 return flags;
120}
121
122/*
123 * Use tpi to get a pending interrupt, call the interrupt handler and
124 * return a pointer to the subchannel structure.
125 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100126static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127cio_tpi(void)
128{
129 struct tpi_info *tpi_info;
130 struct subchannel *sch;
131 struct irb *irb;
132
133 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
134 if (tpi (NULL) != 1)
135 return 0;
136 irb = (struct irb *) __LC_IRB;
137 /* Store interrupt response block to lowcore. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800138 if (tsch (tpi_info->schid, irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /* Not status pending or not operational. */
140 return 1;
141 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
142 if (!sch)
143 return 1;
144 local_bh_disable();
145 irq_enter ();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100146 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
148 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100149 sch->driver->irq(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100150 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 irq_exit ();
Heiko Carstens1f194a42006-07-03 00:24:46 -0700152 _local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return 1;
154}
155
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100156static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
158{
159 char dbf_text[15];
160
161 if (lpm != 0)
162 sch->lpm &= ~lpm;
163 else
164 sch->lpm = 0;
165
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800166 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800169 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
170 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 sprintf(dbf_text, "no%s", sch->dev.bus_id);
172 CIO_TRACE_EVENT(0, dbf_text);
173 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
174
175 return (sch->lpm ? -EACCES : -ENODEV);
176}
177
178int
179cio_start_key (struct subchannel *sch, /* subchannel structure */
180 struct ccw1 * cpa, /* logical channel prog addr */
181 __u8 lpm, /* logical path mask */
182 __u8 key) /* storage key */
183{
184 char dbf_txt[15];
185 int ccode;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100186 struct orb *orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100188 CIO_TRACE_EVENT(4, "stIO");
189 CIO_TRACE_EVENT(4, sch->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100191 orb = &to_io_private(sch)->orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* sch is always under 2G. */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100193 orb->intparm = (u32)(addr_t)sch;
194 orb->fmt = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100196 orb->pfch = sch->options.prefetch == 0;
197 orb->spnd = sch->options.suspend;
198 orb->ssic = sch->options.suspend && sch->options.inter;
199 orb->lpm = (lpm != 0) ? lpm : sch->lpm;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800200#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /*
202 * for 64 bit we always support 64 bit IDAWs with 4k page size only
203 */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100204 orb->c64 = 1;
205 orb->i2k = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#endif
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100207 orb->key = key >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /* issue "Start Subchannel" */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100209 orb->cpa = (__u32) __pa(cpa);
210 ccode = ssch(sch->schid, orb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 /* process condition code */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100213 sprintf(dbf_txt, "ccode:%d", ccode);
214 CIO_TRACE_EVENT(4, dbf_txt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 switch (ccode) {
217 case 0:
218 /*
219 * initialize device status information
220 */
221 sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
222 return 0;
223 case 1: /* status pending */
224 case 2: /* busy */
225 return -EBUSY;
226 default: /* device/path not operational */
227 return cio_start_handle_notoper(sch, lpm);
228 }
229}
230
231int
232cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
233{
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700234 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237/*
238 * resume suspended I/O operation
239 */
240int
241cio_resume (struct subchannel *sch)
242{
243 char dbf_txt[15];
244 int ccode;
245
246 CIO_TRACE_EVENT (4, "resIO");
247 CIO_TRACE_EVENT (4, sch->dev.bus_id);
248
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800249 ccode = rsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 sprintf (dbf_txt, "ccode:%d", ccode);
252 CIO_TRACE_EVENT (4, dbf_txt);
253
254 switch (ccode) {
255 case 0:
256 sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
257 return 0;
258 case 1:
259 return -EBUSY;
260 case 2:
261 return -EINVAL;
262 default:
263 /*
264 * useless to wait for request completion
265 * as device is no longer operational !
266 */
267 return -ENODEV;
268 }
269}
270
271/*
272 * halt I/O operation
273 */
274int
275cio_halt(struct subchannel *sch)
276{
277 char dbf_txt[15];
278 int ccode;
279
280 if (!sch)
281 return -ENODEV;
282
283 CIO_TRACE_EVENT (2, "haltIO");
284 CIO_TRACE_EVENT (2, sch->dev.bus_id);
285
286 /*
287 * Issue "Halt subchannel" and process condition code
288 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800289 ccode = hsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 sprintf (dbf_txt, "ccode:%d", ccode);
292 CIO_TRACE_EVENT (2, dbf_txt);
293
294 switch (ccode) {
295 case 0:
296 sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
297 return 0;
298 case 1: /* status pending */
299 case 2: /* busy */
300 return -EBUSY;
301 default: /* device not operational */
302 return -ENODEV;
303 }
304}
305
306/*
307 * Clear I/O operation
308 */
309int
310cio_clear(struct subchannel *sch)
311{
312 char dbf_txt[15];
313 int ccode;
314
315 if (!sch)
316 return -ENODEV;
317
318 CIO_TRACE_EVENT (2, "clearIO");
319 CIO_TRACE_EVENT (2, sch->dev.bus_id);
320
321 /*
322 * Issue "Clear subchannel" and process condition code
323 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800324 ccode = csch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 sprintf (dbf_txt, "ccode:%d", ccode);
327 CIO_TRACE_EVENT (2, dbf_txt);
328
329 switch (ccode) {
330 case 0:
331 sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
332 return 0;
333 default: /* device not operational */
334 return -ENODEV;
335 }
336}
337
338/*
339 * Function: cio_cancel
340 * Issues a "Cancel Subchannel" on the specified subchannel
341 * Note: We don't need any fancy intparms and flags here
342 * since xsch is executed synchronously.
343 * Only for common I/O internal use as for now.
344 */
345int
346cio_cancel (struct subchannel *sch)
347{
348 char dbf_txt[15];
349 int ccode;
350
351 if (!sch)
352 return -ENODEV;
353
354 CIO_TRACE_EVENT (2, "cancelIO");
355 CIO_TRACE_EVENT (2, sch->dev.bus_id);
356
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800357 ccode = xsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 sprintf (dbf_txt, "ccode:%d", ccode);
360 CIO_TRACE_EVENT (2, dbf_txt);
361
362 switch (ccode) {
363 case 0: /* success */
364 /* Update information in scsw. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800365 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return 0;
367 case 1: /* status pending */
368 return -EBUSY;
369 case 2: /* not applicable */
370 return -EINVAL;
371 default: /* not oper */
372 return -ENODEV;
373 }
374}
375
376/*
377 * Function: cio_modify
378 * Issues a "Modify Subchannel" on the specified subchannel
379 */
380int
381cio_modify (struct subchannel *sch)
382{
383 int ccode, retry, ret;
384
385 ret = 0;
386 for (retry = 0; retry < 5; retry++) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800387 ccode = msch_err (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (ccode < 0) /* -EIO if msch gets a program check. */
389 return ccode;
390 switch (ccode) {
391 case 0: /* successfull */
392 return 0;
393 case 1: /* status pending */
394 return -EBUSY;
395 case 2: /* busy */
396 udelay (100); /* allow for recovery */
397 ret = -EBUSY;
398 break;
399 case 3: /* not operational */
400 return -ENODEV;
401 }
402 }
403 return ret;
404}
405
406/*
407 * Enable subchannel.
408 */
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100409int cio_enable_subchannel(struct subchannel *sch, unsigned int isc,
410 u32 intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412 char dbf_txt[15];
413 int ccode;
414 int retry;
415 int ret;
416
417 CIO_TRACE_EVENT (2, "ensch");
418 CIO_TRACE_EVENT (2, sch->dev.bus_id);
419
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100420 if (sch_is_pseudo_sch(sch))
421 return -EINVAL;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800422 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (ccode)
424 return -ENODEV;
425
426 for (retry = 5, ret = 0; retry > 0; retry--) {
427 sch->schib.pmcw.ena = 1;
428 sch->schib.pmcw.isc = isc;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100429 sch->schib.pmcw.intparm = intparm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 ret = cio_modify(sch);
431 if (ret == -ENODEV)
432 break;
433 if (ret == -EIO)
434 /*
435 * Got a program check in cio_modify. Try without
436 * the concurrent sense bit the next time.
437 */
438 sch->schib.pmcw.csense = 0;
439 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800440 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (sch->schib.pmcw.ena)
442 break;
443 }
444 if (ret == -EBUSY) {
445 struct irb irb;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800446 if (tsch(sch->schid, &irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448 }
449 }
450 sprintf (dbf_txt, "ret:%d", ret);
451 CIO_TRACE_EVENT (2, dbf_txt);
452 return ret;
453}
454
455/*
456 * Disable subchannel.
457 */
458int
459cio_disable_subchannel (struct subchannel *sch)
460{
461 char dbf_txt[15];
462 int ccode;
463 int retry;
464 int ret;
465
466 CIO_TRACE_EVENT (2, "dissch");
467 CIO_TRACE_EVENT (2, sch->dev.bus_id);
468
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100469 if (sch_is_pseudo_sch(sch))
470 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800471 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 if (ccode == 3) /* Not operational. */
473 return -ENODEV;
474
475 if (sch->schib.scsw.actl != 0)
476 /*
477 * the disable function must not be called while there are
478 * requests pending for completion !
479 */
480 return -EBUSY;
481
482 for (retry = 5, ret = 0; retry > 0; retry--) {
483 sch->schib.pmcw.ena = 0;
484 ret = cio_modify(sch);
485 if (ret == -ENODEV)
486 break;
487 if (ret == -EBUSY)
488 /*
489 * The subchannel is busy or status pending.
490 * We'll disable when the next interrupt was delivered
491 * via the state machine.
492 */
493 break;
494 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800495 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (!sch->schib.pmcw.ena)
497 break;
498 }
499 }
500 sprintf (dbf_txt, "ret:%d", ret);
501 CIO_TRACE_EVENT (2, dbf_txt);
502 return ret;
503}
504
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100505int cio_create_sch_lock(struct subchannel *sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100506{
507 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
508 if (!sch->lock)
509 return -ENOMEM;
510 spin_lock_init(sch->lock);
511 return 0;
512}
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514/*
515 * cio_validate_subchannel()
516 *
517 * Find out subchannel type and initialize struct subchannel.
518 * Return codes:
519 * SUBCHANNEL_TYPE_IO for a normal io subchannel
520 * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
521 * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
522 * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
523 * -ENXIO for non-defined subchannels
524 * -ENODEV for subchannels with invalid device number or blacklisted devices
525 */
526int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800527cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 char dbf_txt[15];
530 int ccode;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100531 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800533 sprintf (dbf_txt, "valsch%x", schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 CIO_TRACE_EVENT (4, dbf_txt);
535
536 /* Nuke all fields. */
537 memset(sch, 0, sizeof(struct subchannel));
538
Cornelia Huck2ec22982006-12-08 15:54:26 +0100539 sch->schid = schid;
540 if (cio_is_console(schid)) {
541 sch->lock = cio_get_console_lock();
542 } else {
543 err = cio_create_sch_lock(sch);
544 if (err)
545 goto out;
546 }
Cornelia Huck6ab48792006-07-12 16:39:50 +0200547 mutex_init(&sch->reg_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 /* Set a name for the subchannel */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800549 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
550 schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 /*
553 * The first subchannel that is not-operational (ccode==3)
554 * indicates that there aren't any more devices available.
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800555 * If stsch gets an exception, it means the current subchannel set
556 * is not valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800558 ccode = stsch_err (schid, &sch->schib);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100559 if (ccode) {
560 err = (ccode == 3) ? -ENXIO : ccode;
561 goto out;
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 /* Copy subchannel type from path management control word. */
564 sch->st = sch->schib.pmcw.st;
565
566 /*
567 * ... just being curious we check for non I/O subchannels
568 */
569 if (sch->st != 0) {
570 CIO_DEBUG(KERN_INFO, 0,
Cornelia Huckbc698bc2008-01-26 14:10:42 +0100571 "Subchannel 0.%x.%04x reports "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 "non-I/O subchannel type %04X\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800573 sch->schid.ssid, sch->schid.sch_no, sch->st);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* We stop here for non-io subchannels. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100575 err = sch->st;
576 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
579 /* Initialization for io subchannels. */
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100580 if (!css_sch_is_valid(&sch->schib))
581 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* Devno is valid. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800583 if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 /*
585 * This device must not be known to Linux. So we simply
586 * say that there is no device and return ENODEV.
587 */
Cornelia Huck347d59d2007-02-05 21:17:56 +0100588 CIO_MSG_EVENT(4, "Blacklisted device detected "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800589 "at devno %04X, subchannel set %x\n",
590 sch->schib.pmcw.dev, sch->schid.ssid);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100591 err = -ENODEV;
592 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200594 if (cio_is_console(sch->schid))
595 sch->opm = 0xff;
596 else
597 sch->opm = chp_get_sch_opm(sch);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200598 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 CIO_DEBUG(KERN_INFO, 0,
Cornelia Huckbc698bc2008-01-26 14:10:42 +0100601 "Detected device %04x on subchannel 0.%x.%04X"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 " - PIM = %02X, PAM = %02X, POM = %02X\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800603 sch->schib.pmcw.dev, sch->schid.ssid,
604 sch->schid.sch_no, sch->schib.pmcw.pim,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
606
607 /*
608 * We now have to initially ...
609 * ... set "interruption subclass"
610 * ... enable "concurrent sense"
611 * ... enable "multipath mode" if more than one
612 * CHPID is available. This is done regardless
613 * whether multiple paths are available for us.
614 */
615 sch->schib.pmcw.isc = 3; /* could be smth. else */
616 sch->schib.pmcw.csense = 1; /* concurrent sense */
617 sch->schib.pmcw.ena = 0;
618 if ((sch->lpm & (sch->lpm - 1)) != 0)
619 sch->schib.pmcw.mp = 1; /* multipath mode */
Cornelia Huck1842f2b2007-10-12 16:11:22 +0200620 /* clean up possible residual cmf stuff */
621 sch->schib.pmcw.mme = 0;
622 sch->schib.pmcw.mbfc = 0;
623 sch->schib.pmcw.mbi = 0;
624 sch->schib.mba = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100626out:
627 if (!cio_is_console(schid))
628 kfree(sch->lock);
629 sch->lock = NULL;
630 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
633/*
634 * do_IRQ() handles all normal I/O device IRQ's (the special
635 * SMP cross-CPU interrupts have their own specific
636 * handlers).
637 *
638 */
639void
640do_IRQ (struct pt_regs *regs)
641{
642 struct tpi_info *tpi_info;
643 struct subchannel *sch;
644 struct irb *irb;
Heiko Carstens5a489b982006-10-06 16:38:35 +0200645 struct pt_regs *old_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Heiko Carstens5a489b982006-10-06 16:38:35 +0200647 old_regs = set_irq_regs(regs);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200648 irq_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 asm volatile ("mc 0,0");
650 if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
651 /**
652 * Make sure that the i/o interrupt did not "overtake"
653 * the last HZ timer interrupt.
654 */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100655 account_ticks(S390_lowcore.int_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /*
657 * Get interrupt information from lowcore
658 */
659 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
660 irb = (struct irb *) __LC_IRB;
661 do {
662 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
663 /*
664 * Non I/O-subchannel thin interrupts are processed differently
665 */
666 if (tpi_info->adapter_IO == 1 &&
667 tpi_info->int_type == IO_INTERRUPT_TYPE) {
668 do_adapter_IO();
669 continue;
670 }
671 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
672 if (sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100673 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* Store interrupt response block to lowcore. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800675 if (tsch (tpi_info->schid, irb) == 0 && sch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 /* Keep subchannel information word up to date. */
677 memcpy (&sch->schib.scsw, &irb->scsw,
678 sizeof (irb->scsw));
679 /* Call interrupt handler if there is one. */
680 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100681 sch->driver->irq(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683 if (sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100684 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /*
686 * Are more interrupts pending?
687 * If so, the tpi instruction will update the lowcore
688 * to hold the info for the next interrupt.
689 * We don't do this for VM because a tpi drops the cpu
690 * out of the sie which costs more cycles than it saves.
691 */
692 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200693 irq_exit();
Heiko Carstens5a489b982006-10-06 16:38:35 +0200694 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
697#ifdef CONFIG_CCW_CONSOLE
698static struct subchannel console_subchannel;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100699static struct io_subchannel_private console_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700static int console_subchannel_in_use;
701
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100702void *cio_get_console_priv(void)
703{
704 return &console_priv;
705}
706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707/*
708 * busy wait for the next interrupt on the console
709 */
710void
711wait_cons_dev (void)
712{
713 unsigned long cr6 __attribute__ ((aligned (8)));
714 unsigned long save_cr6 __attribute__ ((aligned (8)));
715
716 /*
717 * before entering the spinlock we may already have
718 * processed the interrupt on a different CPU...
719 */
720 if (!console_subchannel_in_use)
721 return;
722
723 /* disable all but isc 7 (console device) */
724 __ctl_store (save_cr6, 6, 6);
725 cr6 = 0x01000000;
726 __ctl_load (cr6, 6, 6);
727
728 do {
Cornelia Huck2ec22982006-12-08 15:54:26 +0100729 spin_unlock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if (!cio_tpi())
731 cpu_relax();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100732 spin_lock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 } while (console_subchannel.schib.scsw.actl != 0);
734 /*
735 * restore previous isc value
736 */
737 __ctl_load (save_cr6, 6, 6);
738}
739
740static int
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800741cio_test_for_console(struct subchannel_id schid, void *data)
742{
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800743 if (stsch_err(schid, &console_subchannel.schib) != 0)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800744 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100745 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
746 console_subchannel.schib.pmcw.dnv &&
747 (console_subchannel.schib.pmcw.dev == console_devno)) {
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800748 console_irq = schid.sch_no;
749 return 1; /* found */
750 }
751 return 0;
752}
753
754
755static int
756cio_get_console_sch_no(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800758 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800760 init_subchannel_id(&schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 if (console_irq != -1) {
762 /* VM provided us with the irq number of the console. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800763 schid.sch_no = console_irq;
764 if (stsch(schid, &console_subchannel.schib) != 0 ||
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100765 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 !console_subchannel.schib.pmcw.dnv)
767 return -1;
768 console_devno = console_subchannel.schib.pmcw.dev;
769 } else if (console_devno != -1) {
770 /* At least the console device number is known. */
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800771 for_each_subchannel(cio_test_for_console, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (console_irq == -1)
773 return -1;
774 } else {
775 /* unlike in 2.4, we cannot autoprobe here, since
776 * the channel subsystem is not fully initialized.
777 * With some luck, the HWC console can take over */
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200778 printk(KERN_WARNING "cio: No ccw console found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return -1;
780 }
781 return console_irq;
782}
783
784struct subchannel *
785cio_probe_console(void)
786{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800787 int sch_no, ret;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800788 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 if (xchg(&console_subchannel_in_use, 1) != 0)
791 return ERR_PTR(-EBUSY);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800792 sch_no = cio_get_console_sch_no();
793 if (sch_no == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 console_subchannel_in_use = 0;
795 return ERR_PTR(-ENODEV);
796 }
797 memset(&console_subchannel, 0, sizeof(struct subchannel));
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800798 init_subchannel_id(&schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800799 schid.sch_no = sch_no;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800800 ret = cio_validate_subchannel(&console_subchannel, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (ret) {
802 console_subchannel_in_use = 0;
803 return ERR_PTR(-ENODEV);
804 }
805
806 /*
807 * enable console I/O-interrupt subclass 7
808 */
809 ctl_set_bit(6, 24);
810 console_subchannel.schib.pmcw.isc = 7;
811 console_subchannel.schib.pmcw.intparm =
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100812 (u32)(addr_t)&console_subchannel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 ret = cio_modify(&console_subchannel);
814 if (ret) {
815 console_subchannel_in_use = 0;
816 return ERR_PTR(ret);
817 }
818 return &console_subchannel;
819}
820
821void
822cio_release_console(void)
823{
824 console_subchannel.schib.pmcw.intparm = 0;
825 cio_modify(&console_subchannel);
826 ctl_clear_bit(6, 24);
827 console_subchannel_in_use = 0;
828}
829
830/* Bah... hack to catch console special sausages. */
831int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800832cio_is_console(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834 if (!console_subchannel_in_use)
835 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800836 return schid_equal(&schid, &console_subchannel.schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
839struct subchannel *
840cio_get_console_subchannel(void)
841{
842 if (!console_subchannel_in_use)
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200843 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return &console_subchannel;
845}
846
847#endif
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100848static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800849__disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
851 int retry, cc;
852
853 cc = 0;
854 for (retry=0;retry<3;retry++) {
855 schib->pmcw.ena = 0;
856 cc = msch(schid, schib);
857 if (cc)
858 return (cc==3?-ENODEV:-EBUSY);
859 stsch(schid, schib);
860 if (!schib->pmcw.ena)
861 return 0;
862 }
863 return -EBUSY; /* uhm... */
864}
865
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100866/* we can't use the normal udelay here, since it enables external interrupts */
867
868static void udelay_reset(unsigned long usecs)
869{
870 uint64_t start_cc, end_cc;
871
872 asm volatile ("STCK %0" : "=m" (start_cc));
873 do {
874 cpu_relax();
875 asm volatile ("STCK %0" : "=m" (end_cc));
876 } while (((end_cc - start_cc)/4096) < usecs);
877}
878
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100879static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800880__clear_subchannel_easy(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
882 int retry;
883
884 if (csch(schid))
885 return -ENODEV;
886 for (retry=0;retry<20;retry++) {
887 struct tpi_info ti;
888
889 if (tpi(&ti)) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800890 tsch(ti.schid, (struct irb *)__LC_IRB);
891 if (schid_equal(&ti.schid, &schid))
Cornelia Huck4c24da72005-09-03 15:58:01 -0700892 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100894 udelay_reset(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896 return -EBUSY;
897}
898
Michael Holzheua45e1412006-12-15 17:18:22 +0100899static int pgm_check_occured;
900
901static void cio_reset_pgm_check_handler(void)
902{
903 pgm_check_occured = 1;
904}
905
906static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
907{
908 int rc;
909
910 pgm_check_occured = 0;
Heiko Carstensab14de62007-02-05 21:18:37 +0100911 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100912 rc = stsch(schid, addr);
Heiko Carstensab14de62007-02-05 21:18:37 +0100913 s390_base_pgm_handler_fn = NULL;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100914
Heiko Carstensab14de62007-02-05 21:18:37 +0100915 /* The program check handler could have changed pgm_check_occured. */
Heiko Carstens6faf4442007-01-09 10:18:41 +0100916 barrier();
917
Michael Holzheua45e1412006-12-15 17:18:22 +0100918 if (pgm_check_occured)
919 return -EIO;
920 else
921 return rc;
922}
923
Heiko Carstens15e9b582006-12-04 15:40:26 +0100924static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800925{
926 struct schib schib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Michael Holzheua45e1412006-12-15 17:18:22 +0100928 if (stsch_reset(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800929 return -ENXIO;
930 if (!schib.pmcw.ena)
931 return 0;
932 switch(__disable_subchannel_easy(schid, &schib)) {
933 case 0:
934 case -ENODEV:
935 break;
936 default: /* -EBUSY */
937 if (__clear_subchannel_easy(schid))
938 break; /* give up... */
939 stsch(schid, &schib);
940 __disable_subchannel_easy(schid, &schib);
941 }
942 return 0;
943}
944
Heiko Carstens15e9b582006-12-04 15:40:26 +0100945static atomic_t chpid_reset_count;
946
947static void s390_reset_chpids_mcck_handler(void)
948{
949 struct crw crw;
950 struct mci *mci;
951
952 /* Check for pending channel report word. */
953 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
954 if (!mci->cp)
955 return;
956 /* Process channel report words. */
957 while (stcrw(&crw) == 0) {
958 /* Check for responses to RCHP. */
959 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
960 atomic_dec(&chpid_reset_count);
961 }
962}
963
964#define RCHP_TIMEOUT (30 * USEC_PER_SEC)
965static void css_reset(void)
966{
967 int i, ret;
968 unsigned long long timeout;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200969 struct chp_id chpid;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100970
971 /* Reset subchannels. */
972 for_each_subchannel(__shutdown_subchannel_easy, NULL);
973 /* Reset channel paths. */
Heiko Carstensab14de62007-02-05 21:18:37 +0100974 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100975 /* Enable channel report machine checks. */
976 __ctl_set_bit(14, 28);
977 /* Temporarily reenable machine checks. */
978 local_mcck_enable();
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200979 chp_id_init(&chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100980 for (i = 0; i <= __MAX_CHPID; i++) {
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200981 chpid.id = i;
982 ret = rchp(chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100983 if ((ret == 0) || (ret == 2))
984 /*
985 * rchp either succeeded, or another rchp is already
986 * in progress. In either case, we'll get a crw.
987 */
988 atomic_inc(&chpid_reset_count);
989 }
990 /* Wait for machine check for all channel paths. */
991 timeout = get_clock() + (RCHP_TIMEOUT << 12);
992 while (atomic_read(&chpid_reset_count) != 0) {
993 if (get_clock() > timeout)
994 break;
995 cpu_relax();
996 }
997 /* Disable machine checks again. */
998 local_mcck_disable();
999 /* Disable channel report machine checks. */
1000 __ctl_clear_bit(14, 28);
Heiko Carstensab14de62007-02-05 21:18:37 +01001001 s390_base_mcck_handler_fn = NULL;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001002}
1003
1004static struct reset_call css_reset_call = {
1005 .fn = css_reset,
1006};
1007
1008static int __init init_css_reset_call(void)
1009{
1010 atomic_set(&chpid_reset_count, 0);
1011 register_reset_call(&css_reset_call);
1012 return 0;
1013}
1014
1015arch_initcall(init_css_reset_call);
1016
1017struct sch_match_id {
1018 struct subchannel_id schid;
1019 struct ccw_dev_id devid;
1020 int rc;
1021};
1022
1023static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1024{
1025 struct schib schib;
1026 struct sch_match_id *match_id = data;
1027
Michael Holzheua45e1412006-12-15 17:18:22 +01001028 if (stsch_reset(schid, &schib))
Heiko Carstens15e9b582006-12-04 15:40:26 +01001029 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +01001030 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
Heiko Carstens15e9b582006-12-04 15:40:26 +01001031 (schib.pmcw.dev == match_id->devid.devno) &&
1032 (schid.ssid == match_id->devid.ssid)) {
1033 match_id->schid = schid;
1034 match_id->rc = 0;
1035 return 1;
1036 }
1037 return 0;
1038}
1039
1040static int reipl_find_schid(struct ccw_dev_id *devid,
1041 struct subchannel_id *schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001043 struct sch_match_id match_id;
1044
1045 match_id.devid = *devid;
1046 match_id.rc = -ENODEV;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001047 for_each_subchannel(__reipl_subchannel_match, &match_id);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001048 if (match_id.rc == 0)
1049 *schid = match_id.schid;
1050 return match_id.rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001053extern void do_reipl_asm(__u32 schid);
1054
1055/* Make sure all subchannels are quiet before we re-ipl an lpar. */
1056void reipl_ccw_dev(struct ccw_dev_id *devid)
1057{
1058 struct subchannel_id schid;
1059
Heiko Carstens15e9b582006-12-04 15:40:26 +01001060 s390_reset_system();
1061 if (reipl_find_schid(devid, &schid) != 0)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001062 panic("IPL Device not found\n");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001063 do_reipl_asm(*((__u32*)&schid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
Heiko Carstense87bfe52006-09-20 15:59:15 +02001065
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001066int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
Heiko Carstense87bfe52006-09-20 15:59:15 +02001067{
1068 struct subchannel_id schid;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001069 struct schib schib;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001070
1071 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1072 if (!schid.one)
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001073 return -ENODEV;
1074 if (stsch(schid, &schib))
1075 return -ENODEV;
Cornelia Huckb279a4f2008-01-26 14:10:45 +01001076 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1077 return -ENODEV;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001078 if (!schib.pmcw.dnv)
1079 return -ENODEV;
1080 iplinfo->devno = schib.pmcw.dev;
1081 iplinfo->is_qdio = schib.pmcw.qf;
1082 return 0;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001083}