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