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