blob: 6dbe9488d3f99450f98296820da2ebe98281ea99 [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 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
42int cio_show_msg;
43
44static int __init
45cio_setup (char *parm)
46{
47 if (!strcmp (parm, "yes"))
48 cio_show_msg = 1;
49 else if (!strcmp (parm, "no"))
50 cio_show_msg = 0;
51 else
Cornelia Hucke556bbb2007-07-27 12:29:19 +020052 printk(KERN_ERR "cio: cio_setup: "
53 "invalid cio_msg parameter '%s'", parm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return 1;
55}
56
57__setup ("cio_msg=", cio_setup);
58
59/*
60 * Function: cio_debug_init
Cornelia Huckbc698bc2008-01-26 14:10:42 +010061 * Initializes three debug logs for common I/O:
62 * - cio_msg logs generic cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * - cio_trace logs the calling of different functions
Cornelia Huckbc698bc2008-01-26 14:10:42 +010064 * - cio_crw logs machine check related cio messages
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
Cornelia Huckbc698bc2008-01-26 14:10:42 +010066static int __init cio_debug_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Peter Tiedemann361f4942008-01-26 14:11:30 +010068 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (!cio_debug_msg_id)
70 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010071 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
72 debug_set_level(cio_debug_msg_id, 2);
Peter Tiedemann361f4942008-01-26 14:11:30 +010073 cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if (!cio_debug_trace_id)
75 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010076 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
77 debug_set_level(cio_debug_trace_id, 2);
Peter Tiedemann361f4942008-01-26 14:11:30 +010078 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (!cio_debug_crw_id)
80 goto out_unregister;
Cornelia Huckbc698bc2008-01-26 14:10:42 +010081 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
82 debug_set_level(cio_debug_crw_id, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return 0;
84
85out_unregister:
86 if (cio_debug_msg_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010087 debug_unregister(cio_debug_msg_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if (cio_debug_trace_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010089 debug_unregister(cio_debug_trace_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (cio_debug_crw_id)
Cornelia Huckbc698bc2008-01-26 14:10:42 +010091 debug_unregister(cio_debug_crw_id);
Cornelia Hucke556bbb2007-07-27 12:29:19 +020092 printk(KERN_WARNING"cio: could not initialize debugging\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return -1;
94}
95
96arch_initcall (cio_debug_init);
97
98int
99cio_set_options (struct subchannel *sch, int flags)
100{
101 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
102 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
103 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
104 return 0;
105}
106
107/* FIXME: who wants to use this? */
108int
109cio_get_options (struct subchannel *sch)
110{
111 int flags;
112
113 flags = 0;
114 if (sch->options.suspend)
115 flags |= DOIO_ALLOW_SUSPEND;
116 if (sch->options.prefetch)
117 flags |= DOIO_DENY_PREFETCH;
118 if (sch->options.inter)
119 flags |= DOIO_SUPPRESS_INTER;
120 return flags;
121}
122
123/*
124 * Use tpi to get a pending interrupt, call the interrupt handler and
125 * return a pointer to the subchannel structure.
126 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100127static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128cio_tpi(void)
129{
130 struct tpi_info *tpi_info;
131 struct subchannel *sch;
132 struct irb *irb;
133
134 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
135 if (tpi (NULL) != 1)
136 return 0;
137 irb = (struct irb *) __LC_IRB;
138 /* Store interrupt response block to lowcore. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800139 if (tsch (tpi_info->schid, irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* Not status pending or not operational. */
141 return 1;
142 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
143 if (!sch)
144 return 1;
145 local_bh_disable();
146 irq_enter ();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100147 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
149 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100150 sch->driver->irq(sch);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100151 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 irq_exit ();
Heiko Carstens1f194a42006-07-03 00:24:46 -0700153 _local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 1;
155}
156
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100157static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
159{
160 char dbf_text[15];
161
162 if (lpm != 0)
163 sch->lpm &= ~lpm;
164 else
165 sch->lpm = 0;
166
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800167 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800170 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
171 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 sprintf(dbf_text, "no%s", sch->dev.bus_id);
173 CIO_TRACE_EVENT(0, dbf_text);
174 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
175
176 return (sch->lpm ? -EACCES : -ENODEV);
177}
178
179int
180cio_start_key (struct subchannel *sch, /* subchannel structure */
181 struct ccw1 * cpa, /* logical channel prog addr */
182 __u8 lpm, /* logical path mask */
183 __u8 key) /* storage key */
184{
185 char dbf_txt[15];
186 int ccode;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100187 struct orb *orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100189 CIO_TRACE_EVENT(4, "stIO");
190 CIO_TRACE_EVENT(4, sch->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100192 orb = &to_io_private(sch)->orb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /* sch is always under 2G. */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100194 orb->intparm = (u32)(addr_t)sch;
195 orb->fmt = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100197 orb->pfch = sch->options.prefetch == 0;
198 orb->spnd = sch->options.suspend;
199 orb->ssic = sch->options.suspend && sch->options.inter;
200 orb->lpm = (lpm != 0) ? lpm : sch->lpm;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800201#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /*
203 * for 64 bit we always support 64 bit IDAWs with 4k page size only
204 */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100205 orb->c64 = 1;
206 orb->i2k = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#endif
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100208 orb->key = key >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 /* issue "Start Subchannel" */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100210 orb->cpa = (__u32) __pa(cpa);
211 ccode = ssch(sch->schid, orb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 /* process condition code */
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100214 sprintf(dbf_txt, "ccode:%d", ccode);
215 CIO_TRACE_EVENT(4, dbf_txt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 switch (ccode) {
218 case 0:
219 /*
220 * initialize device status information
221 */
222 sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
223 return 0;
224 case 1: /* status pending */
225 case 2: /* busy */
226 return -EBUSY;
227 default: /* device/path not operational */
228 return cio_start_handle_notoper(sch, lpm);
229 }
230}
231
232int
233cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
234{
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700235 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238/*
239 * resume suspended I/O operation
240 */
241int
242cio_resume (struct subchannel *sch)
243{
244 char dbf_txt[15];
245 int ccode;
246
247 CIO_TRACE_EVENT (4, "resIO");
248 CIO_TRACE_EVENT (4, sch->dev.bus_id);
249
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800250 ccode = rsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 sprintf (dbf_txt, "ccode:%d", ccode);
253 CIO_TRACE_EVENT (4, dbf_txt);
254
255 switch (ccode) {
256 case 0:
257 sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
258 return 0;
259 case 1:
260 return -EBUSY;
261 case 2:
262 return -EINVAL;
263 default:
264 /*
265 * useless to wait for request completion
266 * as device is no longer operational !
267 */
268 return -ENODEV;
269 }
270}
271
272/*
273 * halt I/O operation
274 */
275int
276cio_halt(struct subchannel *sch)
277{
278 char dbf_txt[15];
279 int ccode;
280
281 if (!sch)
282 return -ENODEV;
283
284 CIO_TRACE_EVENT (2, "haltIO");
285 CIO_TRACE_EVENT (2, sch->dev.bus_id);
286
287 /*
288 * Issue "Halt subchannel" and process condition code
289 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800290 ccode = hsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 sprintf (dbf_txt, "ccode:%d", ccode);
293 CIO_TRACE_EVENT (2, dbf_txt);
294
295 switch (ccode) {
296 case 0:
297 sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
298 return 0;
299 case 1: /* status pending */
300 case 2: /* busy */
301 return -EBUSY;
302 default: /* device not operational */
303 return -ENODEV;
304 }
305}
306
307/*
308 * Clear I/O operation
309 */
310int
311cio_clear(struct subchannel *sch)
312{
313 char dbf_txt[15];
314 int ccode;
315
316 if (!sch)
317 return -ENODEV;
318
319 CIO_TRACE_EVENT (2, "clearIO");
320 CIO_TRACE_EVENT (2, sch->dev.bus_id);
321
322 /*
323 * Issue "Clear subchannel" and process condition code
324 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800325 ccode = csch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 sprintf (dbf_txt, "ccode:%d", ccode);
328 CIO_TRACE_EVENT (2, dbf_txt);
329
330 switch (ccode) {
331 case 0:
332 sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
333 return 0;
334 default: /* device not operational */
335 return -ENODEV;
336 }
337}
338
339/*
340 * Function: cio_cancel
341 * Issues a "Cancel Subchannel" on the specified subchannel
342 * Note: We don't need any fancy intparms and flags here
343 * since xsch is executed synchronously.
344 * Only for common I/O internal use as for now.
345 */
346int
347cio_cancel (struct subchannel *sch)
348{
349 char dbf_txt[15];
350 int ccode;
351
352 if (!sch)
353 return -ENODEV;
354
355 CIO_TRACE_EVENT (2, "cancelIO");
356 CIO_TRACE_EVENT (2, sch->dev.bus_id);
357
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800358 ccode = xsch (sch->schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 sprintf (dbf_txt, "ccode:%d", ccode);
361 CIO_TRACE_EVENT (2, dbf_txt);
362
363 switch (ccode) {
364 case 0: /* success */
365 /* Update information in scsw. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800366 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return 0;
368 case 1: /* status pending */
369 return -EBUSY;
370 case 2: /* not applicable */
371 return -EINVAL;
372 default: /* not oper */
373 return -ENODEV;
374 }
375}
376
377/*
378 * Function: cio_modify
379 * Issues a "Modify Subchannel" on the specified subchannel
380 */
381int
382cio_modify (struct subchannel *sch)
383{
384 int ccode, retry, ret;
385
386 ret = 0;
387 for (retry = 0; retry < 5; retry++) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800388 ccode = msch_err (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (ccode < 0) /* -EIO if msch gets a program check. */
390 return ccode;
391 switch (ccode) {
392 case 0: /* successfull */
393 return 0;
394 case 1: /* status pending */
395 return -EBUSY;
396 case 2: /* busy */
397 udelay (100); /* allow for recovery */
398 ret = -EBUSY;
399 break;
400 case 3: /* not operational */
401 return -ENODEV;
402 }
403 }
404 return ret;
405}
406
407/*
408 * Enable subchannel.
409 */
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100410int cio_enable_subchannel(struct subchannel *sch, unsigned int isc,
411 u32 intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
413 char dbf_txt[15];
414 int ccode;
415 int retry;
416 int ret;
417
418 CIO_TRACE_EVENT (2, "ensch");
419 CIO_TRACE_EVENT (2, sch->dev.bus_id);
420
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100421 if (sch_is_pseudo_sch(sch))
422 return -EINVAL;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800423 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (ccode)
425 return -ENODEV;
426
427 for (retry = 5, ret = 0; retry > 0; retry--) {
428 sch->schib.pmcw.ena = 1;
429 sch->schib.pmcw.isc = isc;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100430 sch->schib.pmcw.intparm = intparm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 ret = cio_modify(sch);
432 if (ret == -ENODEV)
433 break;
434 if (ret == -EIO)
435 /*
436 * Got a program check in cio_modify. Try without
437 * the concurrent sense bit the next time.
438 */
439 sch->schib.pmcw.csense = 0;
440 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800441 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (sch->schib.pmcw.ena)
443 break;
444 }
445 if (ret == -EBUSY) {
446 struct irb irb;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800447 if (tsch(sch->schid, &irb) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 break;
449 }
450 }
451 sprintf (dbf_txt, "ret:%d", ret);
452 CIO_TRACE_EVENT (2, dbf_txt);
453 return ret;
454}
455
456/*
457 * Disable subchannel.
458 */
459int
460cio_disable_subchannel (struct subchannel *sch)
461{
462 char dbf_txt[15];
463 int ccode;
464 int retry;
465 int ret;
466
467 CIO_TRACE_EVENT (2, "dissch");
468 CIO_TRACE_EVENT (2, sch->dev.bus_id);
469
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100470 if (sch_is_pseudo_sch(sch))
471 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800472 ccode = stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 if (ccode == 3) /* Not operational. */
474 return -ENODEV;
475
476 if (sch->schib.scsw.actl != 0)
477 /*
478 * the disable function must not be called while there are
479 * requests pending for completion !
480 */
481 return -EBUSY;
482
483 for (retry = 5, ret = 0; retry > 0; retry--) {
484 sch->schib.pmcw.ena = 0;
485 ret = cio_modify(sch);
486 if (ret == -ENODEV)
487 break;
488 if (ret == -EBUSY)
489 /*
490 * The subchannel is busy or status pending.
491 * We'll disable when the next interrupt was delivered
492 * via the state machine.
493 */
494 break;
495 if (ret == 0) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800496 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (!sch->schib.pmcw.ena)
498 break;
499 }
500 }
501 sprintf (dbf_txt, "ret:%d", ret);
502 CIO_TRACE_EVENT (2, dbf_txt);
503 return ret;
504}
505
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100506int cio_create_sch_lock(struct subchannel *sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100507{
508 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
509 if (!sch->lock)
510 return -ENOMEM;
511 spin_lock_init(sch->lock);
512 return 0;
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*
516 * cio_validate_subchannel()
517 *
518 * Find out subchannel type and initialize struct subchannel.
519 * Return codes:
520 * SUBCHANNEL_TYPE_IO for a normal io subchannel
521 * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
522 * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
523 * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
524 * -ENXIO for non-defined subchannels
525 * -ENODEV for subchannels with invalid device number or blacklisted devices
526 */
527int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800528cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 char dbf_txt[15];
531 int ccode;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100532 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800534 sprintf (dbf_txt, "valsch%x", schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 CIO_TRACE_EVENT (4, dbf_txt);
536
537 /* Nuke all fields. */
538 memset(sch, 0, sizeof(struct subchannel));
539
Cornelia Huck2ec22982006-12-08 15:54:26 +0100540 sch->schid = schid;
541 if (cio_is_console(schid)) {
542 sch->lock = cio_get_console_lock();
543 } else {
544 err = cio_create_sch_lock(sch);
545 if (err)
546 goto out;
547 }
Cornelia Huck6ab48792006-07-12 16:39:50 +0200548 mutex_init(&sch->reg_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* Set a name for the subchannel */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800550 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
551 schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 /*
554 * The first subchannel that is not-operational (ccode==3)
555 * indicates that there aren't any more devices available.
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800556 * If stsch gets an exception, it means the current subchannel set
557 * is not valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800559 ccode = stsch_err (schid, &sch->schib);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100560 if (ccode) {
561 err = (ccode == 3) ? -ENXIO : ccode;
562 goto out;
563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* Copy subchannel type from path management control word. */
565 sch->st = sch->schib.pmcw.st;
566
567 /*
568 * ... just being curious we check for non I/O subchannels
569 */
570 if (sch->st != 0) {
571 CIO_DEBUG(KERN_INFO, 0,
Cornelia Huckbc698bc2008-01-26 14:10:42 +0100572 "Subchannel 0.%x.%04x reports "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 "non-I/O subchannel type %04X\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800574 sch->schid.ssid, sch->schid.sch_no, sch->st);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /* We stop here for non-io subchannels. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100576 err = sch->st;
577 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
580 /* Initialization for io subchannels. */
Michael Ernst808e4882008-01-26 14:10:51 +0100581 if (!css_sch_is_valid(&sch->schib)) {
582 err = -ENODEV;
583 goto out;
584 }
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* Devno is valid. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800587 if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /*
589 * This device must not be known to Linux. So we simply
590 * say that there is no device and return ENODEV.
591 */
Cornelia Huck347d59d2007-02-05 21:17:56 +0100592 CIO_MSG_EVENT(4, "Blacklisted device detected "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800593 "at devno %04X, subchannel set %x\n",
594 sch->schib.pmcw.dev, sch->schid.ssid);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100595 err = -ENODEV;
596 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200598 if (cio_is_console(sch->schid))
599 sch->opm = 0xff;
600 else
601 sch->opm = chp_get_sch_opm(sch);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200602 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 CIO_DEBUG(KERN_INFO, 0,
Cornelia Huckbc698bc2008-01-26 14:10:42 +0100605 "Detected device %04x on subchannel 0.%x.%04X"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 " - PIM = %02X, PAM = %02X, POM = %02X\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800607 sch->schib.pmcw.dev, sch->schid.ssid,
608 sch->schid.sch_no, sch->schib.pmcw.pim,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
610
611 /*
612 * We now have to initially ...
613 * ... set "interruption subclass"
614 * ... enable "concurrent sense"
615 * ... enable "multipath mode" if more than one
616 * CHPID is available. This is done regardless
617 * whether multiple paths are available for us.
618 */
619 sch->schib.pmcw.isc = 3; /* could be smth. else */
620 sch->schib.pmcw.csense = 1; /* concurrent sense */
621 sch->schib.pmcw.ena = 0;
622 if ((sch->lpm & (sch->lpm - 1)) != 0)
623 sch->schib.pmcw.mp = 1; /* multipath mode */
Cornelia Huck1842f2b2007-10-12 16:11:22 +0200624 /* clean up possible residual cmf stuff */
625 sch->schib.pmcw.mme = 0;
626 sch->schib.pmcw.mbfc = 0;
627 sch->schib.pmcw.mbi = 0;
628 sch->schib.mba = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return 0;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100630out:
631 if (!cio_is_console(schid))
632 kfree(sch->lock);
633 sch->lock = NULL;
634 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635}
636
637/*
638 * do_IRQ() handles all normal I/O device IRQ's (the special
639 * SMP cross-CPU interrupts have their own specific
640 * handlers).
641 *
642 */
643void
644do_IRQ (struct pt_regs *regs)
645{
646 struct tpi_info *tpi_info;
647 struct subchannel *sch;
648 struct irb *irb;
Heiko Carstens5a489b92006-10-06 16:38:35 +0200649 struct pt_regs *old_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Heiko Carstens5a489b92006-10-06 16:38:35 +0200651 old_regs = set_irq_regs(regs);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200652 irq_enter();
Heiko Carstens43ca5c32008-04-17 07:46:23 +0200653 s390_idle_check();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
655 /**
656 * Make sure that the i/o interrupt did not "overtake"
657 * the last HZ timer interrupt.
658 */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100659 account_ticks(S390_lowcore.int_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 /*
661 * Get interrupt information from lowcore
662 */
663 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
664 irb = (struct irb *) __LC_IRB;
665 do {
666 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
667 /*
668 * Non I/O-subchannel thin interrupts are processed differently
669 */
670 if (tpi_info->adapter_IO == 1 &&
671 tpi_info->int_type == IO_INTERRUPT_TYPE) {
672 do_adapter_IO();
673 continue;
674 }
675 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
676 if (sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100677 spin_lock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /* Store interrupt response block to lowcore. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800679 if (tsch (tpi_info->schid, irb) == 0 && sch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /* Keep subchannel information word up to date. */
681 memcpy (&sch->schib.scsw, &irb->scsw,
682 sizeof (irb->scsw));
683 /* Call interrupt handler if there is one. */
684 if (sch->driver && sch->driver->irq)
Cornelia Huck602b20f2008-01-26 14:10:39 +0100685 sch->driver->irq(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687 if (sch)
Cornelia Huck2ec22982006-12-08 15:54:26 +0100688 spin_unlock(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /*
690 * Are more interrupts pending?
691 * If so, the tpi instruction will update the lowcore
692 * to hold the info for the next interrupt.
693 * We don't do this for VM because a tpi drops the cpu
694 * out of the sie which costs more cycles than it saves.
695 */
696 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200697 irq_exit();
Heiko Carstens5a489b92006-10-06 16:38:35 +0200698 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
701#ifdef CONFIG_CCW_CONSOLE
702static struct subchannel console_subchannel;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100703static struct io_subchannel_private console_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704static int console_subchannel_in_use;
705
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100706void *cio_get_console_priv(void)
707{
708 return &console_priv;
709}
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711/*
712 * busy wait for the next interrupt on the console
713 */
714void
715wait_cons_dev (void)
716{
717 unsigned long cr6 __attribute__ ((aligned (8)));
718 unsigned long save_cr6 __attribute__ ((aligned (8)));
719
720 /*
721 * before entering the spinlock we may already have
722 * processed the interrupt on a different CPU...
723 */
724 if (!console_subchannel_in_use)
725 return;
726
727 /* disable all but isc 7 (console device) */
728 __ctl_store (save_cr6, 6, 6);
729 cr6 = 0x01000000;
730 __ctl_load (cr6, 6, 6);
731
732 do {
Cornelia Huck2ec22982006-12-08 15:54:26 +0100733 spin_unlock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (!cio_tpi())
735 cpu_relax();
Cornelia Huck2ec22982006-12-08 15:54:26 +0100736 spin_lock(console_subchannel.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 } while (console_subchannel.schib.scsw.actl != 0);
738 /*
739 * restore previous isc value
740 */
741 __ctl_load (save_cr6, 6, 6);
742}
743
744static int
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800745cio_test_for_console(struct subchannel_id schid, void *data)
746{
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800747 if (stsch_err(schid, &console_subchannel.schib) != 0)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800748 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100749 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
750 console_subchannel.schib.pmcw.dnv &&
751 (console_subchannel.schib.pmcw.dev == console_devno)) {
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800752 console_irq = schid.sch_no;
753 return 1; /* found */
754 }
755 return 0;
756}
757
758
759static int
760cio_get_console_sch_no(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800762 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800764 init_subchannel_id(&schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 if (console_irq != -1) {
766 /* VM provided us with the irq number of the console. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800767 schid.sch_no = console_irq;
768 if (stsch(schid, &console_subchannel.schib) != 0 ||
Cornelia Huckb279a4f2008-01-26 14:10:45 +0100769 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 !console_subchannel.schib.pmcw.dnv)
771 return -1;
772 console_devno = console_subchannel.schib.pmcw.dev;
773 } else if (console_devno != -1) {
774 /* At least the console device number is known. */
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800775 for_each_subchannel(cio_test_for_console, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (console_irq == -1)
777 return -1;
778 } else {
779 /* unlike in 2.4, we cannot autoprobe here, since
780 * the channel subsystem is not fully initialized.
781 * With some luck, the HWC console can take over */
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200782 printk(KERN_WARNING "cio: No ccw console found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return -1;
784 }
785 return console_irq;
786}
787
788struct subchannel *
789cio_probe_console(void)
790{
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800791 int sch_no, ret;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800792 struct subchannel_id schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (xchg(&console_subchannel_in_use, 1) != 0)
795 return ERR_PTR(-EBUSY);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800796 sch_no = cio_get_console_sch_no();
797 if (sch_no == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 console_subchannel_in_use = 0;
799 return ERR_PTR(-ENODEV);
800 }
801 memset(&console_subchannel, 0, sizeof(struct subchannel));
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800802 init_subchannel_id(&schid);
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800803 schid.sch_no = sch_no;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800804 ret = cio_validate_subchannel(&console_subchannel, schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (ret) {
806 console_subchannel_in_use = 0;
807 return ERR_PTR(-ENODEV);
808 }
809
810 /*
811 * enable console I/O-interrupt subclass 7
812 */
813 ctl_set_bit(6, 24);
814 console_subchannel.schib.pmcw.isc = 7;
815 console_subchannel.schib.pmcw.intparm =
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100816 (u32)(addr_t)&console_subchannel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 ret = cio_modify(&console_subchannel);
818 if (ret) {
819 console_subchannel_in_use = 0;
820 return ERR_PTR(ret);
821 }
822 return &console_subchannel;
823}
824
825void
826cio_release_console(void)
827{
828 console_subchannel.schib.pmcw.intparm = 0;
829 cio_modify(&console_subchannel);
830 ctl_clear_bit(6, 24);
831 console_subchannel_in_use = 0;
832}
833
834/* Bah... hack to catch console special sausages. */
835int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800836cio_is_console(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 if (!console_subchannel_in_use)
839 return 0;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800840 return schid_equal(&schid, &console_subchannel.schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841}
842
843struct subchannel *
844cio_get_console_subchannel(void)
845{
846 if (!console_subchannel_in_use)
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200847 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return &console_subchannel;
849}
850
851#endif
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100852static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800853__disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854{
855 int retry, cc;
856
857 cc = 0;
858 for (retry=0;retry<3;retry++) {
859 schib->pmcw.ena = 0;
860 cc = msch(schid, schib);
861 if (cc)
862 return (cc==3?-ENODEV:-EBUSY);
863 stsch(schid, schib);
864 if (!schib->pmcw.ena)
865 return 0;
866 }
867 return -EBUSY; /* uhm... */
868}
869
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100870/* we can't use the normal udelay here, since it enables external interrupts */
871
872static void udelay_reset(unsigned long usecs)
873{
874 uint64_t start_cc, end_cc;
875
876 asm volatile ("STCK %0" : "=m" (start_cc));
877 do {
878 cpu_relax();
879 asm volatile ("STCK %0" : "=m" (end_cc));
880 } while (((end_cc - start_cc)/4096) < usecs);
881}
882
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100883static int
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800884__clear_subchannel_easy(struct subchannel_id schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 int retry;
887
888 if (csch(schid))
889 return -ENODEV;
890 for (retry=0;retry<20;retry++) {
891 struct tpi_info ti;
892
893 if (tpi(&ti)) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800894 tsch(ti.schid, (struct irb *)__LC_IRB);
895 if (schid_equal(&ti.schid, &schid))
Cornelia Huck4c24da72005-09-03 15:58:01 -0700896 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100898 udelay_reset(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900 return -EBUSY;
901}
902
Michael Holzheua45e1412006-12-15 17:18:22 +0100903static int pgm_check_occured;
904
905static void cio_reset_pgm_check_handler(void)
906{
907 pgm_check_occured = 1;
908}
909
910static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
911{
912 int rc;
913
914 pgm_check_occured = 0;
Heiko Carstensab14de62007-02-05 21:18:37 +0100915 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100916 rc = stsch(schid, addr);
Heiko Carstensab14de62007-02-05 21:18:37 +0100917 s390_base_pgm_handler_fn = NULL;
Heiko Carstens6faf4442007-01-09 10:18:41 +0100918
Heiko Carstensab14de62007-02-05 21:18:37 +0100919 /* The program check handler could have changed pgm_check_occured. */
Heiko Carstens6faf4442007-01-09 10:18:41 +0100920 barrier();
921
Michael Holzheua45e1412006-12-15 17:18:22 +0100922 if (pgm_check_occured)
923 return -EIO;
924 else
925 return rc;
926}
927
Heiko Carstens15e9b582006-12-04 15:40:26 +0100928static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800929{
930 struct schib schib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Michael Holzheua45e1412006-12-15 17:18:22 +0100932 if (stsch_reset(schid, &schib))
Cornelia Huckf97a56f2006-01-06 00:19:22 -0800933 return -ENXIO;
934 if (!schib.pmcw.ena)
935 return 0;
936 switch(__disable_subchannel_easy(schid, &schib)) {
937 case 0:
938 case -ENODEV:
939 break;
940 default: /* -EBUSY */
941 if (__clear_subchannel_easy(schid))
942 break; /* give up... */
943 stsch(schid, &schib);
944 __disable_subchannel_easy(schid, &schib);
945 }
946 return 0;
947}
948
Heiko Carstens15e9b582006-12-04 15:40:26 +0100949static atomic_t chpid_reset_count;
950
951static void s390_reset_chpids_mcck_handler(void)
952{
953 struct crw crw;
954 struct mci *mci;
955
956 /* Check for pending channel report word. */
957 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
958 if (!mci->cp)
959 return;
960 /* Process channel report words. */
961 while (stcrw(&crw) == 0) {
962 /* Check for responses to RCHP. */
963 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
964 atomic_dec(&chpid_reset_count);
965 }
966}
967
968#define RCHP_TIMEOUT (30 * USEC_PER_SEC)
969static void css_reset(void)
970{
971 int i, ret;
972 unsigned long long timeout;
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200973 struct chp_id chpid;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100974
975 /* Reset subchannels. */
976 for_each_subchannel(__shutdown_subchannel_easy, NULL);
977 /* Reset channel paths. */
Heiko Carstensab14de62007-02-05 21:18:37 +0100978 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
Heiko Carstens15e9b582006-12-04 15:40:26 +0100979 /* Enable channel report machine checks. */
980 __ctl_set_bit(14, 28);
981 /* Temporarily reenable machine checks. */
982 local_mcck_enable();
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200983 chp_id_init(&chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100984 for (i = 0; i <= __MAX_CHPID; i++) {
Peter Oberparleiterf86635f2007-04-27 16:01:26 +0200985 chpid.id = i;
986 ret = rchp(chpid);
Heiko Carstens15e9b582006-12-04 15:40:26 +0100987 if ((ret == 0) || (ret == 2))
988 /*
989 * rchp either succeeded, or another rchp is already
990 * in progress. In either case, we'll get a crw.
991 */
992 atomic_inc(&chpid_reset_count);
993 }
994 /* Wait for machine check for all channel paths. */
995 timeout = get_clock() + (RCHP_TIMEOUT << 12);
996 while (atomic_read(&chpid_reset_count) != 0) {
997 if (get_clock() > timeout)
998 break;
999 cpu_relax();
1000 }
1001 /* Disable machine checks again. */
1002 local_mcck_disable();
1003 /* Disable channel report machine checks. */
1004 __ctl_clear_bit(14, 28);
Heiko Carstensab14de62007-02-05 21:18:37 +01001005 s390_base_mcck_handler_fn = NULL;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001006}
1007
1008static struct reset_call css_reset_call = {
1009 .fn = css_reset,
1010};
1011
1012static int __init init_css_reset_call(void)
1013{
1014 atomic_set(&chpid_reset_count, 0);
1015 register_reset_call(&css_reset_call);
1016 return 0;
1017}
1018
1019arch_initcall(init_css_reset_call);
1020
1021struct sch_match_id {
1022 struct subchannel_id schid;
1023 struct ccw_dev_id devid;
1024 int rc;
1025};
1026
1027static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1028{
1029 struct schib schib;
1030 struct sch_match_id *match_id = data;
1031
Michael Holzheua45e1412006-12-15 17:18:22 +01001032 if (stsch_reset(schid, &schib))
Heiko Carstens15e9b582006-12-04 15:40:26 +01001033 return -ENXIO;
Cornelia Huckb279a4f2008-01-26 14:10:45 +01001034 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
Heiko Carstens15e9b582006-12-04 15:40:26 +01001035 (schib.pmcw.dev == match_id->devid.devno) &&
1036 (schid.ssid == match_id->devid.ssid)) {
1037 match_id->schid = schid;
1038 match_id->rc = 0;
1039 return 1;
1040 }
1041 return 0;
1042}
1043
1044static int reipl_find_schid(struct ccw_dev_id *devid,
1045 struct subchannel_id *schid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001047 struct sch_match_id match_id;
1048
1049 match_id.devid = *devid;
1050 match_id.rc = -ENODEV;
Heiko Carstens15e9b582006-12-04 15:40:26 +01001051 for_each_subchannel(__reipl_subchannel_match, &match_id);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001052 if (match_id.rc == 0)
1053 *schid = match_id.schid;
1054 return match_id.rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001057extern void do_reipl_asm(__u32 schid);
1058
1059/* Make sure all subchannels are quiet before we re-ipl an lpar. */
1060void reipl_ccw_dev(struct ccw_dev_id *devid)
1061{
1062 struct subchannel_id schid;
1063
Heiko Carstens15e9b582006-12-04 15:40:26 +01001064 s390_reset_system();
1065 if (reipl_find_schid(devid, &schid) != 0)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001066 panic("IPL Device not found\n");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001067 do_reipl_asm(*((__u32*)&schid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068}
Heiko Carstense87bfe52006-09-20 15:59:15 +02001069
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001070int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
Heiko Carstense87bfe52006-09-20 15:59:15 +02001071{
1072 struct subchannel_id schid;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001073 struct schib schib;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001074
1075 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1076 if (!schid.one)
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001077 return -ENODEV;
1078 if (stsch(schid, &schib))
1079 return -ENODEV;
Cornelia Huckb279a4f2008-01-26 14:10:45 +01001080 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1081 return -ENODEV;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001082 if (!schib.pmcw.dnv)
1083 return -ENODEV;
1084 iplinfo->devno = schib.pmcw.dev;
1085 iplinfo->is_qdio = schib.pmcw.qf;
1086 return 0;
Heiko Carstense87bfe52006-09-20 15:59:15 +02001087}