]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/s390/cio/device_ops.c
d4be16acebe483edb33b6b020882394107e3ba9a
[net-next-2.6.git] / drivers / s390 / cio / device_ops.c
1 /*
2  * Copyright IBM Corp. 2002, 2009
3  *
4  * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
5  *            Cornelia Huck (cornelia.huck@de.ibm.com)
6  */
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/errno.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/device.h>
13 #include <linux/delay.h>
14
15 #include <asm/ccwdev.h>
16 #include <asm/idals.h>
17 #include <asm/chpid.h>
18 #include <asm/fcx.h>
19
20 #include "cio.h"
21 #include "cio_debug.h"
22 #include "css.h"
23 #include "chsc.h"
24 #include "device.h"
25 #include "chp.h"
26
27 /**
28  * ccw_device_set_options_mask() - set some options and unset the rest
29  * @cdev: device for which the options are to be set
30  * @flags: options to be set
31  *
32  * All flags specified in @flags are set, all flags not specified in @flags
33  * are cleared.
34  * Returns:
35  *   %0 on success, -%EINVAL on an invalid flag combination.
36  */
37 int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
38 {
39        /*
40         * The flag usage is mutal exclusive ...
41         */
42         if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
43             (flags & CCWDEV_REPORT_ALL))
44                 return -EINVAL;
45         cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
46         cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0;
47         cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0;
48         cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0;
49         cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
50         return 0;
51 }
52
53 /**
54  * ccw_device_set_options() - set some options
55  * @cdev: device for which the options are to be set
56  * @flags: options to be set
57  *
58  * All flags specified in @flags are set, the remainder is left untouched.
59  * Returns:
60  *   %0 on success, -%EINVAL if an invalid flag combination would ensue.
61  */
62 int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
63 {
64        /*
65         * The flag usage is mutal exclusive ...
66         */
67         if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
68             (flags & CCWDEV_REPORT_ALL)) ||
69             ((flags & CCWDEV_EARLY_NOTIFICATION) &&
70              cdev->private->options.repall) ||
71             ((flags & CCWDEV_REPORT_ALL) &&
72              cdev->private->options.fast))
73                 return -EINVAL;
74         cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
75         cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
76         cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
77         cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
78         cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
79         return 0;
80 }
81
82 /**
83  * ccw_device_clear_options() - clear some options
84  * @cdev: device for which the options are to be cleared
85  * @flags: options to be cleared
86  *
87  * All flags specified in @flags are cleared, the remainder is left untouched.
88  */
89 void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
90 {
91         cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
92         cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
93         cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
94         cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
95         cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
96 }
97
98 /**
99  * ccw_device_is_pathgroup - determine if paths to this device are grouped
100  * @cdev: ccw device
101  *
102  * Return non-zero if there is a path group, zero otherwise.
103  */
104 int ccw_device_is_pathgroup(struct ccw_device *cdev)
105 {
106         return cdev->private->flags.pgroup;
107 }
108 EXPORT_SYMBOL(ccw_device_is_pathgroup);
109
110 /**
111  * ccw_device_is_multipath - determine if device is operating in multipath mode
112  * @cdev: ccw device
113  *
114  * Return non-zero if device is operating in multipath mode, zero otherwise.
115  */
116 int ccw_device_is_multipath(struct ccw_device *cdev)
117 {
118         return cdev->private->flags.mpath;
119 }
120 EXPORT_SYMBOL(ccw_device_is_multipath);
121
122 /**
123  * ccw_device_clear() - terminate I/O request processing
124  * @cdev: target ccw device
125  * @intparm: interruption parameter; value is only used if no I/O is
126  *           outstanding, otherwise the intparm associated with the I/O request
127  *           is returned
128  *
129  * ccw_device_clear() calls csch on @cdev's subchannel.
130  * Returns:
131  *  %0 on success,
132  *  -%ENODEV on device not operational,
133  *  -%EINVAL on invalid device state.
134  * Context:
135  *  Interrupts disabled, ccw device lock held
136  */
137 int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
138 {
139         struct subchannel *sch;
140         int ret;
141
142         if (!cdev || !cdev->dev.parent)
143                 return -ENODEV;
144         sch = to_subchannel(cdev->dev.parent);
145         if (!sch->schib.pmcw.ena)
146                 return -EINVAL;
147         if (cdev->private->state == DEV_STATE_NOT_OPER)
148                 return -ENODEV;
149         if (cdev->private->state != DEV_STATE_ONLINE &&
150             cdev->private->state != DEV_STATE_W4SENSE)
151                 return -EINVAL;
152
153         ret = cio_clear(sch);
154         if (ret == 0)
155                 cdev->private->intparm = intparm;
156         return ret;
157 }
158
159 /**
160  * ccw_device_start_key() - start a s390 channel program with key
161  * @cdev: target ccw device
162  * @cpa: logical start address of channel program
163  * @intparm: user specific interruption parameter; will be presented back to
164  *           @cdev's interrupt handler. Allows a device driver to associate
165  *           the interrupt with a particular I/O request.
166  * @lpm: defines the channel path to be used for a specific I/O request. A
167  *       value of 0 will make cio use the opm.
168  * @key: storage key to be used for the I/O
169  * @flags: additional flags; defines the action to be performed for I/O
170  *         processing.
171  *
172  * Start a S/390 channel program. When the interrupt arrives, the
173  * IRQ handler is called, either immediately, delayed (dev-end missing,
174  * or sense required) or never (no IRQ handler registered).
175  * Returns:
176  *  %0, if the operation was successful;
177  *  -%EBUSY, if the device is busy, or status pending;
178  *  -%EACCES, if no path specified in @lpm is operational;
179  *  -%ENODEV, if the device is not operational.
180  * Context:
181  *  Interrupts disabled, ccw device lock held
182  */
183 int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
184                          unsigned long intparm, __u8 lpm, __u8 key,
185                          unsigned long flags)
186 {
187         struct subchannel *sch;
188         int ret;
189
190         if (!cdev || !cdev->dev.parent)
191                 return -ENODEV;
192         sch = to_subchannel(cdev->dev.parent);
193         if (!sch->schib.pmcw.ena)
194                 return -EINVAL;
195         if (cdev->private->state == DEV_STATE_NOT_OPER)
196                 return -ENODEV;
197         if (cdev->private->state == DEV_STATE_VERIFY) {
198                 /* Remember to fake irb when finished. */
199                 if (!cdev->private->flags.fake_irb) {
200                         cdev->private->flags.fake_irb = 1;
201                         cdev->private->intparm = intparm;
202                         return 0;
203                 } else
204                         /* There's already a fake I/O around. */
205                         return -EBUSY;
206         }
207         if (cdev->private->state != DEV_STATE_ONLINE ||
208             ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
209              !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
210             cdev->private->flags.doverify)
211                 return -EBUSY;
212         ret = cio_set_options (sch, flags);
213         if (ret)
214                 return ret;
215         /* Adjust requested path mask to excluded varied off paths. */
216         if (lpm) {
217                 lpm &= sch->opm;
218                 if (lpm == 0)
219                         return -EACCES;
220         }
221         ret = cio_start_key (sch, cpa, lpm, key);
222         switch (ret) {
223         case 0:
224                 cdev->private->intparm = intparm;
225                 break;
226         case -EACCES:
227         case -ENODEV:
228                 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
229                 break;
230         }
231         return ret;
232 }
233
234 /**
235  * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
236  * @cdev: target ccw device
237  * @cpa: logical start address of channel program
238  * @intparm: user specific interruption parameter; will be presented back to
239  *           @cdev's interrupt handler. Allows a device driver to associate
240  *           the interrupt with a particular I/O request.
241  * @lpm: defines the channel path to be used for a specific I/O request. A
242  *       value of 0 will make cio use the opm.
243  * @key: storage key to be used for the I/O
244  * @flags: additional flags; defines the action to be performed for I/O
245  *         processing.
246  * @expires: timeout value in jiffies
247  *
248  * Start a S/390 channel program. When the interrupt arrives, the
249  * IRQ handler is called, either immediately, delayed (dev-end missing,
250  * or sense required) or never (no IRQ handler registered).
251  * This function notifies the device driver if the channel program has not
252  * completed during the time specified by @expires. If a timeout occurs, the
253  * channel program is terminated via xsch, hsch or csch, and the device's
254  * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
255  * Returns:
256  *  %0, if the operation was successful;
257  *  -%EBUSY, if the device is busy, or status pending;
258  *  -%EACCES, if no path specified in @lpm is operational;
259  *  -%ENODEV, if the device is not operational.
260  * Context:
261  *  Interrupts disabled, ccw device lock held
262  */
263 int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
264                                  unsigned long intparm, __u8 lpm, __u8 key,
265                                  unsigned long flags, int expires)
266 {
267         int ret;
268
269         if (!cdev)
270                 return -ENODEV;
271         ccw_device_set_timeout(cdev, expires);
272         ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
273         if (ret != 0)
274                 ccw_device_set_timeout(cdev, 0);
275         return ret;
276 }
277
278 /**
279  * ccw_device_start() - start a s390 channel program
280  * @cdev: target ccw device
281  * @cpa: logical start address of channel program
282  * @intparm: user specific interruption parameter; will be presented back to
283  *           @cdev's interrupt handler. Allows a device driver to associate
284  *           the interrupt with a particular I/O request.
285  * @lpm: defines the channel path to be used for a specific I/O request. A
286  *       value of 0 will make cio use the opm.
287  * @flags: additional flags; defines the action to be performed for I/O
288  *         processing.
289  *
290  * Start a S/390 channel program. When the interrupt arrives, the
291  * IRQ handler is called, either immediately, delayed (dev-end missing,
292  * or sense required) or never (no IRQ handler registered).
293  * Returns:
294  *  %0, if the operation was successful;
295  *  -%EBUSY, if the device is busy, or status pending;
296  *  -%EACCES, if no path specified in @lpm is operational;
297  *  -%ENODEV, if the device is not operational.
298  * Context:
299  *  Interrupts disabled, ccw device lock held
300  */
301 int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
302                      unsigned long intparm, __u8 lpm, unsigned long flags)
303 {
304         return ccw_device_start_key(cdev, cpa, intparm, lpm,
305                                     PAGE_DEFAULT_KEY, flags);
306 }
307
308 /**
309  * ccw_device_start_timeout() - start a s390 channel program with timeout
310  * @cdev: target ccw device
311  * @cpa: logical start address of channel program
312  * @intparm: user specific interruption parameter; will be presented back to
313  *           @cdev's interrupt handler. Allows a device driver to associate
314  *           the interrupt with a particular I/O request.
315  * @lpm: defines the channel path to be used for a specific I/O request. A
316  *       value of 0 will make cio use the opm.
317  * @flags: additional flags; defines the action to be performed for I/O
318  *         processing.
319  * @expires: timeout value in jiffies
320  *
321  * Start a S/390 channel program. When the interrupt arrives, the
322  * IRQ handler is called, either immediately, delayed (dev-end missing,
323  * or sense required) or never (no IRQ handler registered).
324  * This function notifies the device driver if the channel program has not
325  * completed during the time specified by @expires. If a timeout occurs, the
326  * channel program is terminated via xsch, hsch or csch, and the device's
327  * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
328  * Returns:
329  *  %0, if the operation was successful;
330  *  -%EBUSY, if the device is busy, or status pending;
331  *  -%EACCES, if no path specified in @lpm is operational;
332  *  -%ENODEV, if the device is not operational.
333  * Context:
334  *  Interrupts disabled, ccw device lock held
335  */
336 int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
337                              unsigned long intparm, __u8 lpm,
338                              unsigned long flags, int expires)
339 {
340         return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
341                                             PAGE_DEFAULT_KEY, flags,
342                                             expires);
343 }
344
345
346 /**
347  * ccw_device_halt() - halt I/O request processing
348  * @cdev: target ccw device
349  * @intparm: interruption parameter; value is only used if no I/O is
350  *           outstanding, otherwise the intparm associated with the I/O request
351  *           is returned
352  *
353  * ccw_device_halt() calls hsch on @cdev's subchannel.
354  * Returns:
355  *  %0 on success,
356  *  -%ENODEV on device not operational,
357  *  -%EINVAL on invalid device state,
358  *  -%EBUSY on device busy or interrupt pending.
359  * Context:
360  *  Interrupts disabled, ccw device lock held
361  */
362 int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
363 {
364         struct subchannel *sch;
365         int ret;
366
367         if (!cdev || !cdev->dev.parent)
368                 return -ENODEV;
369         sch = to_subchannel(cdev->dev.parent);
370         if (!sch->schib.pmcw.ena)
371                 return -EINVAL;
372         if (cdev->private->state == DEV_STATE_NOT_OPER)
373                 return -ENODEV;
374         if (cdev->private->state != DEV_STATE_ONLINE &&
375             cdev->private->state != DEV_STATE_W4SENSE)
376                 return -EINVAL;
377
378         ret = cio_halt(sch);
379         if (ret == 0)
380                 cdev->private->intparm = intparm;
381         return ret;
382 }
383
384 /**
385  * ccw_device_resume() - resume channel program execution
386  * @cdev: target ccw device
387  *
388  * ccw_device_resume() calls rsch on @cdev's subchannel.
389  * Returns:
390  *  %0 on success,
391  *  -%ENODEV on device not operational,
392  *  -%EINVAL on invalid device state,
393  *  -%EBUSY on device busy or interrupt pending.
394  * Context:
395  *  Interrupts disabled, ccw device lock held
396  */
397 int ccw_device_resume(struct ccw_device *cdev)
398 {
399         struct subchannel *sch;
400
401         if (!cdev || !cdev->dev.parent)
402                 return -ENODEV;
403         sch = to_subchannel(cdev->dev.parent);
404         if (!sch->schib.pmcw.ena)
405                 return -EINVAL;
406         if (cdev->private->state == DEV_STATE_NOT_OPER)
407                 return -ENODEV;
408         if (cdev->private->state != DEV_STATE_ONLINE ||
409             !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
410                 return -EINVAL;
411         return cio_resume(sch);
412 }
413
414 /*
415  * Pass interrupt to device driver.
416  */
417 int
418 ccw_device_call_handler(struct ccw_device *cdev)
419 {
420         struct subchannel *sch;
421         unsigned int stctl;
422         int ending_status;
423
424         sch = to_subchannel(cdev->dev.parent);
425
426         /*
427          * we allow for the device action handler if .
428          *  - we received ending status
429          *  - the action handler requested to see all interrupts
430          *  - we received an intermediate status
431          *  - fast notification was requested (primary status)
432          *  - unsolicited interrupts
433          */
434         stctl = scsw_stctl(&cdev->private->irb.scsw);
435         ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
436                 (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
437                 (stctl == SCSW_STCTL_STATUS_PEND);
438         if (!ending_status &&
439             !cdev->private->options.repall &&
440             !(stctl & SCSW_STCTL_INTER_STATUS) &&
441             !(cdev->private->options.fast &&
442               (stctl & SCSW_STCTL_PRIM_STATUS)))
443                 return 0;
444
445         /* Clear pending timers for device driver initiated I/O. */
446         if (ending_status)
447                 ccw_device_set_timeout(cdev, 0);
448         /*
449          * Now we are ready to call the device driver interrupt handler.
450          */
451         if (cdev->handler)
452                 cdev->handler(cdev, cdev->private->intparm,
453                               &cdev->private->irb);
454
455         /*
456          * Clear the old and now useless interrupt response block.
457          */
458         memset(&cdev->private->irb, 0, sizeof(struct irb));
459
460         return 1;
461 }
462
463 /**
464  * ccw_device_get_ciw() - Search for CIW command in extended sense data.
465  * @cdev: ccw device to inspect
466  * @ct: command type to look for
467  *
468  * During SenseID, command information words (CIWs) describing special
469  * commands available to the device may have been stored in the extended
470  * sense data. This function searches for CIWs of a specified command
471  * type in the extended sense data.
472  * Returns:
473  *  %NULL if no extended sense data has been stored or if no CIW of the
474  *  specified command type could be found,
475  *  else a pointer to the CIW of the specified command type.
476  */
477 struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
478 {
479         int ciw_cnt;
480
481         if (cdev->private->flags.esid == 0)
482                 return NULL;
483         for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
484                 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
485                         return cdev->private->senseid.ciw + ciw_cnt;
486         return NULL;
487 }
488
489 /**
490  * ccw_device_get_path_mask() - get currently available paths
491  * @cdev: ccw device to be queried
492  * Returns:
493  *  %0 if no subchannel for the device is available,
494  *  else the mask of currently available paths for the ccw device's subchannel.
495  */
496 __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
497 {
498         struct subchannel *sch;
499
500         if (!cdev->dev.parent)
501                 return 0;
502
503         sch = to_subchannel(cdev->dev.parent);
504         return sch->lpm;
505 }
506
507 /*
508  * Try to break the lock on a boxed device.
509  */
510 int
511 ccw_device_stlck(struct ccw_device *cdev)
512 {
513         void *buf, *buf2;
514         unsigned long flags;
515         struct subchannel *sch;
516         int ret;
517
518         if (!cdev)
519                 return -ENODEV;
520
521         if (cdev->drv && !cdev->private->options.force)
522                 return -EINVAL;
523
524         sch = to_subchannel(cdev->dev.parent);
525         
526         CIO_TRACE_EVENT(2, "stl lock");
527         CIO_TRACE_EVENT(2, dev_name(&cdev->dev));
528
529         buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
530         if (!buf)
531                 return -ENOMEM;
532         buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
533         if (!buf2) {
534                 kfree(buf);
535                 return -ENOMEM;
536         }
537         spin_lock_irqsave(sch->lock, flags);
538         ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
539         if (ret)
540                 goto out_unlock;
541         /*
542          * Setup ccw. We chain an unconditional reserve and a release so we
543          * only break the lock.
544          */
545         cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
546         cdev->private->iccws[0].cda = (__u32) __pa(buf);
547         cdev->private->iccws[0].count = 32;
548         cdev->private->iccws[0].flags = CCW_FLAG_CC;
549         cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
550         cdev->private->iccws[1].cda = (__u32) __pa(buf2);
551         cdev->private->iccws[1].count = 32;
552         cdev->private->iccws[1].flags = 0;
553         ret = cio_start(sch, cdev->private->iccws, 0);
554         if (ret) {
555                 cio_disable_subchannel(sch); //FIXME: return code?
556                 goto out_unlock;
557         }
558         cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
559         spin_unlock_irqrestore(sch->lock, flags);
560         wait_event(cdev->private->wait_q,
561                    cdev->private->irb.scsw.cmd.actl == 0);
562         spin_lock_irqsave(sch->lock, flags);
563         cio_disable_subchannel(sch); //FIXME: return code?
564         if ((cdev->private->irb.scsw.cmd.dstat !=
565              (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
566             (cdev->private->irb.scsw.cmd.cstat != 0))
567                 ret = -EIO;
568         /* Clear irb. */
569         memset(&cdev->private->irb, 0, sizeof(struct irb));
570 out_unlock:
571         kfree(buf);
572         kfree(buf2);
573         spin_unlock_irqrestore(sch->lock, flags);
574         return ret;
575 }
576
577 void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
578 {
579         struct subchannel *sch;
580         struct chp_id chpid;
581
582         sch = to_subchannel(cdev->dev.parent);
583         chp_id_init(&chpid);
584         chpid.id = sch->schib.pmcw.chpid[chp_no];
585         return chp_get_chp_desc(chpid);
586 }
587
588 /**
589  * ccw_device_get_id - obtain a ccw device id
590  * @cdev: device to obtain the id for
591  * @dev_id: where to fill in the values
592  */
593 void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
594 {
595         *dev_id = cdev->private->dev_id;
596 }
597 EXPORT_SYMBOL(ccw_device_get_id);
598
599 /**
600  * ccw_device_tm_start_key - perform start function
601  * @cdev: ccw device on which to perform the start function
602  * @tcw: transport-command word to be started
603  * @intparm: user defined parameter to be passed to the interrupt handler
604  * @lpm: mask of paths to use
605  * @key: storage key to use for storage access
606  *
607  * Start the tcw on the given ccw device. Return zero on success, non-zero
608  * otherwise.
609  */
610 int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
611                             unsigned long intparm, u8 lpm, u8 key)
612 {
613         struct subchannel *sch;
614         int rc;
615
616         sch = to_subchannel(cdev->dev.parent);
617         if (!sch->schib.pmcw.ena)
618                 return -EINVAL;
619         if (cdev->private->state != DEV_STATE_ONLINE)
620                 return -EIO;
621         /* Adjust requested path mask to excluded varied off paths. */
622         if (lpm) {
623                 lpm &= sch->opm;
624                 if (lpm == 0)
625                         return -EACCES;
626         }
627         rc = cio_tm_start_key(sch, tcw, lpm, key);
628         if (rc == 0)
629                 cdev->private->intparm = intparm;
630         return rc;
631 }
632 EXPORT_SYMBOL(ccw_device_tm_start_key);
633
634 /**
635  * ccw_device_tm_start_timeout_key - perform start function
636  * @cdev: ccw device on which to perform the start function
637  * @tcw: transport-command word to be started
638  * @intparm: user defined parameter to be passed to the interrupt handler
639  * @lpm: mask of paths to use
640  * @key: storage key to use for storage access
641  * @expires: time span in jiffies after which to abort request
642  *
643  * Start the tcw on the given ccw device. Return zero on success, non-zero
644  * otherwise.
645  */
646 int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
647                                     unsigned long intparm, u8 lpm, u8 key,
648                                     int expires)
649 {
650         int ret;
651
652         ccw_device_set_timeout(cdev, expires);
653         ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
654         if (ret != 0)
655                 ccw_device_set_timeout(cdev, 0);
656         return ret;
657 }
658 EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
659
660 /**
661  * ccw_device_tm_start - perform start function
662  * @cdev: ccw device on which to perform the start function
663  * @tcw: transport-command word to be started
664  * @intparm: user defined parameter to be passed to the interrupt handler
665  * @lpm: mask of paths to use
666  *
667  * Start the tcw on the given ccw device. Return zero on success, non-zero
668  * otherwise.
669  */
670 int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
671                         unsigned long intparm, u8 lpm)
672 {
673         return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
674                                        PAGE_DEFAULT_KEY);
675 }
676 EXPORT_SYMBOL(ccw_device_tm_start);
677
678 /**
679  * ccw_device_tm_start_timeout - perform start function
680  * @cdev: ccw device on which to perform the start function
681  * @tcw: transport-command word to be started
682  * @intparm: user defined parameter to be passed to the interrupt handler
683  * @lpm: mask of paths to use
684  * @expires: time span in jiffies after which to abort request
685  *
686  * Start the tcw on the given ccw device. Return zero on success, non-zero
687  * otherwise.
688  */
689 int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
690                                unsigned long intparm, u8 lpm, int expires)
691 {
692         return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
693                                                PAGE_DEFAULT_KEY, expires);
694 }
695 EXPORT_SYMBOL(ccw_device_tm_start_timeout);
696
697 /**
698  * ccw_device_tm_intrg - perform interrogate function
699  * @cdev: ccw device on which to perform the interrogate function
700  *
701  * Perform an interrogate function on the given ccw device. Return zero on
702  * success, non-zero otherwise.
703  */
704 int ccw_device_tm_intrg(struct ccw_device *cdev)
705 {
706         struct subchannel *sch = to_subchannel(cdev->dev.parent);
707
708         if (!sch->schib.pmcw.ena)
709                 return -EINVAL;
710         if (cdev->private->state != DEV_STATE_ONLINE)
711                 return -EIO;
712         if (!scsw_is_tm(&sch->schib.scsw) ||
713             !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
714                 return -EINVAL;
715         return cio_tm_intrg(sch);
716 }
717 EXPORT_SYMBOL(ccw_device_tm_intrg);
718
719 // FIXME: these have to go:
720
721 int
722 _ccw_device_get_subchannel_number(struct ccw_device *cdev)
723 {
724         return cdev->private->schid.sch_no;
725 }
726
727
728 MODULE_LICENSE("GPL");
729 EXPORT_SYMBOL(ccw_device_set_options_mask);
730 EXPORT_SYMBOL(ccw_device_set_options);
731 EXPORT_SYMBOL(ccw_device_clear_options);
732 EXPORT_SYMBOL(ccw_device_clear);
733 EXPORT_SYMBOL(ccw_device_halt);
734 EXPORT_SYMBOL(ccw_device_resume);
735 EXPORT_SYMBOL(ccw_device_start_timeout);
736 EXPORT_SYMBOL(ccw_device_start);
737 EXPORT_SYMBOL(ccw_device_start_timeout_key);
738 EXPORT_SYMBOL(ccw_device_start_key);
739 EXPORT_SYMBOL(ccw_device_get_ciw);
740 EXPORT_SYMBOL(ccw_device_get_path_mask);
741 EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
742 EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);