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