1 // SPDX-License-Identifier: GPL-1.0+
3 * Copyright IBM Corp. 2002, 2009
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
6 * Cornelia Huck (cornelia.huck@de.ibm.com)
8 #include <linux/export.h>
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/slab.h>
12 #include <linux/list.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/completion.h>
17 #include <asm/ccwdev.h>
18 #include <asm/idals.h>
19 #include <asm/chpid.h>
23 #include "cio_debug.h"
30 * ccw_device_set_options_mask() - set some options and unset the rest
31 * @cdev: device for which the options are to be set
32 * @flags: options to be set
34 * All flags specified in @flags are set, all flags not specified in @flags
37 * %0 on success, -%EINVAL on an invalid flag combination.
39 int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
42 * The flag usage is mutal exclusive ...
44 if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
45 (flags & CCWDEV_REPORT_ALL))
47 cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
48 cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0;
49 cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0;
50 cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0;
51 cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
56 * ccw_device_set_options() - set some options
57 * @cdev: device for which the options are to be set
58 * @flags: options to be set
60 * All flags specified in @flags are set, the remainder is left untouched.
62 * %0 on success, -%EINVAL if an invalid flag combination would ensue.
64 int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
67 * The flag usage is mutal exclusive ...
69 if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
70 (flags & CCWDEV_REPORT_ALL)) ||
71 ((flags & CCWDEV_EARLY_NOTIFICATION) &&
72 cdev->private->options.repall) ||
73 ((flags & CCWDEV_REPORT_ALL) &&
74 cdev->private->options.fast))
76 cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
77 cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
78 cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
79 cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
80 cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
85 * ccw_device_clear_options() - clear some options
86 * @cdev: device for which the options are to be cleared
87 * @flags: options to be cleared
89 * All flags specified in @flags are cleared, the remainder is left untouched.
91 void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
93 cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
94 cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
95 cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
96 cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
97 cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
101 * ccw_device_is_pathgroup() - determine if paths to this device are grouped
104 * Return non-zero if there is a path group, zero otherwise.
106 int ccw_device_is_pathgroup(struct ccw_device *cdev)
108 return cdev->private->flags.pgroup;
110 EXPORT_SYMBOL(ccw_device_is_pathgroup);
113 * ccw_device_is_multipath() - determine if device is operating in multipath mode
116 * Return non-zero if device is operating in multipath mode, zero otherwise.
118 int ccw_device_is_multipath(struct ccw_device *cdev)
120 return cdev->private->flags.mpath;
122 EXPORT_SYMBOL(ccw_device_is_multipath);
125 * ccw_device_clear() - terminate I/O request processing
126 * @cdev: target ccw device
127 * @intparm: interruption parameter to be returned upon conclusion of csch
129 * ccw_device_clear() calls csch on @cdev's subchannel.
132 * -%ENODEV on device not operational,
133 * -%EINVAL on invalid device state.
135 * Interrupts disabled, ccw device lock held
137 int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
139 struct subchannel *sch;
142 if (!cdev || !cdev->dev.parent)
144 sch = to_subchannel(cdev->dev.parent);
145 if (!sch->schib.pmcw.ena)
147 if (cdev->private->state == DEV_STATE_NOT_OPER)
149 if (cdev->private->state != DEV_STATE_ONLINE &&
150 cdev->private->state != DEV_STATE_W4SENSE)
153 ret = cio_clear(sch);
155 cdev->private->intparm = intparm;
160 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and 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
171 * @expires: timeout value in jiffies
173 * Start a S/390 channel program. When the interrupt arrives, the
174 * IRQ handler is called, either immediately, delayed (dev-end missing,
175 * or sense required) or never (no IRQ handler registered).
176 * This function notifies the device driver if the channel program has not
177 * completed during the time specified by @expires. If a timeout occurs, the
178 * channel program is terminated via xsch, hsch or csch, and the device's
179 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
180 * The interruption handler will echo back the @intparm specified here, unless
181 * another interruption parameter is specified by a subsequent invocation of
182 * ccw_device_halt() or ccw_device_clear().
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.
189 * Interrupts disabled, ccw device lock held
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)
195 struct subchannel *sch;
198 if (!cdev || !cdev->dev.parent)
200 sch = to_subchannel(cdev->dev.parent);
201 if (!sch->schib.pmcw.ena)
203 if (cdev->private->state == DEV_STATE_NOT_OPER)
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;
212 /* There's already a fake I/O around. */
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)
220 ret = cio_set_options (sch, flags);
223 /* Adjust requested path mask to exclude unusable paths. */
229 ret = cio_start_key (sch, cpa, lpm, key);
232 cdev->private->intparm = intparm;
234 ccw_device_set_timeout(cdev, expires);
238 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
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
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 * The interruption handler will echo back the @intparm specified here, unless
261 * another interruption parameter is specified by a subsequent invocation of
262 * ccw_device_halt() or ccw_device_clear().
264 * %0, if the operation was successful;
265 * -%EBUSY, if the device is busy, or status pending;
266 * -%EACCES, if no path specified in @lpm is operational;
267 * -%ENODEV, if the device is not operational.
269 * Interrupts disabled, ccw device lock held
271 int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
272 unsigned long intparm, __u8 lpm, __u8 key,
275 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, key,
280 * ccw_device_start() - start a s390 channel program
281 * @cdev: target ccw device
282 * @cpa: logical start address of channel program
283 * @intparm: user specific interruption parameter; will be presented back to
284 * @cdev's interrupt handler. Allows a device driver to associate
285 * the interrupt with a particular I/O request.
286 * @lpm: defines the channel path to be used for a specific I/O request. A
287 * value of 0 will make cio use the opm.
288 * @flags: additional flags; defines the action to be performed for I/O
291 * Start a S/390 channel program. When the interrupt arrives, the
292 * IRQ handler is called, either immediately, delayed (dev-end missing,
293 * or sense required) or never (no IRQ handler registered).
294 * The interruption handler will echo back the @intparm specified here, unless
295 * another interruption parameter is specified by a subsequent invocation of
296 * ccw_device_halt() or ccw_device_clear().
298 * %0, if the operation was successful;
299 * -%EBUSY, if the device is busy, or status pending;
300 * -%EACCES, if no path specified in @lpm is operational;
301 * -%ENODEV, if the device is not operational.
303 * Interrupts disabled, ccw device lock held
305 int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
306 unsigned long intparm, __u8 lpm, unsigned long flags)
308 return ccw_device_start_key(cdev, cpa, intparm, lpm,
309 PAGE_DEFAULT_KEY, flags);
313 * ccw_device_start_timeout() - start a s390 channel program with timeout
314 * @cdev: target ccw device
315 * @cpa: logical start address of channel program
316 * @intparm: user specific interruption parameter; will be presented back to
317 * @cdev's interrupt handler. Allows a device driver to associate
318 * the interrupt with a particular I/O request.
319 * @lpm: defines the channel path to be used for a specific I/O request. A
320 * value of 0 will make cio use the opm.
321 * @flags: additional flags; defines the action to be performed for I/O
323 * @expires: timeout value in jiffies
325 * Start a S/390 channel program. When the interrupt arrives, the
326 * IRQ handler is called, either immediately, delayed (dev-end missing,
327 * or sense required) or never (no IRQ handler registered).
328 * This function notifies the device driver if the channel program has not
329 * completed during the time specified by @expires. If a timeout occurs, the
330 * channel program is terminated via xsch, hsch or csch, and the device's
331 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
332 * The interruption handler will echo back the @intparm specified here, unless
333 * another interruption parameter is specified by a subsequent invocation of
334 * ccw_device_halt() or ccw_device_clear().
336 * %0, if the operation was successful;
337 * -%EBUSY, if the device is busy, or status pending;
338 * -%EACCES, if no path specified in @lpm is operational;
339 * -%ENODEV, if the device is not operational.
341 * Interrupts disabled, ccw device lock held
343 int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
344 unsigned long intparm, __u8 lpm,
345 unsigned long flags, int expires)
347 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
348 PAGE_DEFAULT_KEY, flags,
354 * ccw_device_halt() - halt I/O request processing
355 * @cdev: target ccw device
356 * @intparm: interruption parameter to be returned upon conclusion of hsch
358 * ccw_device_halt() calls hsch on @cdev's subchannel.
359 * The interruption handler will echo back the @intparm specified here, unless
360 * another interruption parameter is specified by a subsequent invocation of
361 * ccw_device_clear().
364 * -%ENODEV on device not operational,
365 * -%EINVAL on invalid device state,
366 * -%EBUSY on device busy or interrupt pending.
368 * Interrupts disabled, ccw device lock held
370 int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
372 struct subchannel *sch;
375 if (!cdev || !cdev->dev.parent)
377 sch = to_subchannel(cdev->dev.parent);
378 if (!sch->schib.pmcw.ena)
380 if (cdev->private->state == DEV_STATE_NOT_OPER)
382 if (cdev->private->state != DEV_STATE_ONLINE &&
383 cdev->private->state != DEV_STATE_W4SENSE)
388 cdev->private->intparm = intparm;
393 * ccw_device_resume() - resume channel program execution
394 * @cdev: target ccw device
396 * ccw_device_resume() calls rsch on @cdev's subchannel.
399 * -%ENODEV on device not operational,
400 * -%EINVAL on invalid device state,
401 * -%EBUSY on device busy or interrupt pending.
403 * Interrupts disabled, ccw device lock held
405 int ccw_device_resume(struct ccw_device *cdev)
407 struct subchannel *sch;
409 if (!cdev || !cdev->dev.parent)
411 sch = to_subchannel(cdev->dev.parent);
412 if (!sch->schib.pmcw.ena)
414 if (cdev->private->state == DEV_STATE_NOT_OPER)
416 if (cdev->private->state != DEV_STATE_ONLINE ||
417 !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
419 return cio_resume(sch);
423 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
424 * @cdev: ccw device to inspect
425 * @ct: command type to look for
427 * During SenseID, command information words (CIWs) describing special
428 * commands available to the device may have been stored in the extended
429 * sense data. This function searches for CIWs of a specified command
430 * type in the extended sense data.
432 * %NULL if no extended sense data has been stored or if no CIW of the
433 * specified command type could be found,
434 * else a pointer to the CIW of the specified command type.
436 struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
440 if (cdev->private->flags.esid == 0)
442 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
443 if (cdev->private->dma_area->senseid.ciw[ciw_cnt].ct == ct)
444 return cdev->private->dma_area->senseid.ciw + ciw_cnt;
449 * ccw_device_get_path_mask() - get currently available paths
450 * @cdev: ccw device to be queried
452 * %0 if no subchannel for the device is available,
453 * else the mask of currently available paths for the ccw device's subchannel.
455 __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
457 struct subchannel *sch;
459 if (!cdev->dev.parent)
462 sch = to_subchannel(cdev->dev.parent);
467 * ccw_device_get_chp_desc() - return newly allocated channel-path descriptor
468 * @cdev: device to obtain the descriptor for
469 * @chp_idx: index of the channel path
471 * On success return a newly allocated copy of the channel-path description
472 * data associated with the given channel path. Return %NULL on error.
474 struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *cdev,
477 struct subchannel *sch;
480 sch = to_subchannel(cdev->dev.parent);
482 chpid.id = sch->schib.pmcw.chpid[chp_idx];
483 return chp_get_chp_desc(chpid);
487 * ccw_device_get_util_str() - return newly allocated utility strings
488 * @cdev: device to obtain the utility strings for
489 * @chp_idx: index of the channel path
491 * On success return a newly allocated copy of the utility strings
492 * associated with the given channel path. Return %NULL on error.
494 u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx)
496 struct subchannel *sch = to_subchannel(cdev->dev.parent);
497 struct channel_path *chp;
502 chpid.id = sch->schib.pmcw.chpid[chp_idx];
503 chp = chpid_to_chp(chpid);
505 util_str = kmalloc(sizeof(chp->desc_fmt3.util_str), GFP_KERNEL);
509 mutex_lock(&chp->lock);
510 memcpy(util_str, chp->desc_fmt3.util_str, sizeof(chp->desc_fmt3.util_str));
511 mutex_unlock(&chp->lock);
517 * ccw_device_get_id() - obtain a ccw device id
518 * @cdev: device to obtain the id for
519 * @dev_id: where to fill in the values
521 void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
523 *dev_id = cdev->private->dev_id;
525 EXPORT_SYMBOL(ccw_device_get_id);
528 * ccw_device_tm_start_timeout_key() - perform start function
529 * @cdev: ccw device on which to perform the start function
530 * @tcw: transport-command word to be started
531 * @intparm: user defined parameter to be passed to the interrupt handler
532 * @lpm: mask of paths to use
533 * @key: storage key to use for storage access
534 * @expires: time span in jiffies after which to abort request
536 * Start the tcw on the given ccw device. Return zero on success, non-zero
539 int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
540 unsigned long intparm, u8 lpm, u8 key,
543 struct subchannel *sch;
546 sch = to_subchannel(cdev->dev.parent);
547 if (!sch->schib.pmcw.ena)
549 if (cdev->private->state == DEV_STATE_VERIFY) {
550 /* Remember to fake irb when finished. */
551 if (!cdev->private->flags.fake_irb) {
552 cdev->private->flags.fake_irb = FAKE_TM_IRB;
553 cdev->private->intparm = intparm;
556 /* There's already a fake I/O around. */
559 if (cdev->private->state != DEV_STATE_ONLINE)
561 /* Adjust requested path mask to exclude unusable paths. */
567 rc = cio_tm_start_key(sch, tcw, lpm, key);
569 cdev->private->intparm = intparm;
571 ccw_device_set_timeout(cdev, expires);
575 EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
578 * ccw_device_tm_start_key() - perform start function
579 * @cdev: ccw device on which to perform the start function
580 * @tcw: transport-command word to be started
581 * @intparm: user defined parameter to be passed to the interrupt handler
582 * @lpm: mask of paths to use
583 * @key: storage key to use for storage access
585 * Start the tcw on the given ccw device. Return zero on success, non-zero
588 int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
589 unsigned long intparm, u8 lpm, u8 key)
591 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, key, 0);
593 EXPORT_SYMBOL(ccw_device_tm_start_key);
596 * ccw_device_tm_start() - perform start function
597 * @cdev: ccw device on which to perform the start function
598 * @tcw: transport-command word to be started
599 * @intparm: user defined parameter to be passed to the interrupt handler
600 * @lpm: mask of paths to use
602 * Start the tcw on the given ccw device. Return zero on success, non-zero
605 int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
606 unsigned long intparm, u8 lpm)
608 return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
611 EXPORT_SYMBOL(ccw_device_tm_start);
614 * ccw_device_tm_start_timeout() - perform start function
615 * @cdev: ccw device on which to perform the start function
616 * @tcw: transport-command word to be started
617 * @intparm: user defined parameter to be passed to the interrupt handler
618 * @lpm: mask of paths to use
619 * @expires: time span in jiffies after which to abort request
621 * Start the tcw on the given ccw device. Return zero on success, non-zero
624 int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
625 unsigned long intparm, u8 lpm, int expires)
627 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
628 PAGE_DEFAULT_KEY, expires);
630 EXPORT_SYMBOL(ccw_device_tm_start_timeout);
633 * ccw_device_get_mdc() - accumulate max data count
634 * @cdev: ccw device for which the max data count is accumulated
635 * @mask: mask of paths to use
637 * Return the number of 64K-bytes blocks all paths at least support
638 * for a transport command. Return value 0 indicates failure.
640 int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
642 struct subchannel *sch = to_subchannel(cdev->dev.parent);
643 struct channel_path *chp;
647 /* Adjust requested path mask to excluded varied off paths. */
654 for (i = 0; i < 8; i++) {
655 if (!(mask & (0x80 >> i)))
657 chpid.id = sch->schib.pmcw.chpid[i];
658 chp = chpid_to_chp(chpid);
662 mutex_lock(&chp->lock);
663 if (!chp->desc_fmt1.f) {
664 mutex_unlock(&chp->lock);
667 if (!chp->desc_fmt1.r)
669 mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
671 mutex_unlock(&chp->lock);
676 EXPORT_SYMBOL(ccw_device_get_mdc);
679 * ccw_device_tm_intrg() - perform interrogate function
680 * @cdev: ccw device on which to perform the interrogate function
682 * Perform an interrogate function on the given ccw device. Return zero on
683 * success, non-zero otherwise.
685 int ccw_device_tm_intrg(struct ccw_device *cdev)
687 struct subchannel *sch = to_subchannel(cdev->dev.parent);
689 if (!sch->schib.pmcw.ena)
691 if (cdev->private->state != DEV_STATE_ONLINE)
693 if (!scsw_is_tm(&sch->schib.scsw) ||
694 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
696 return cio_tm_intrg(sch);
698 EXPORT_SYMBOL(ccw_device_tm_intrg);
701 * ccw_device_get_schid() - obtain a subchannel id
702 * @cdev: device to obtain the id for
703 * @schid: where to fill in the values
705 void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
707 struct subchannel *sch = to_subchannel(cdev->dev.parent);
711 EXPORT_SYMBOL_GPL(ccw_device_get_schid);
714 * ccw_device_pnso() - Perform Network-Subchannel Operation
715 * @cdev: device on which PNSO is performed
716 * @pnso_area: request and response block for the operation
717 * @oc: Operation Code
718 * @resume_token: resume token for multiblock response
719 * @cnc: Boolean change-notification control
721 * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
723 * Returns 0 on success.
725 int ccw_device_pnso(struct ccw_device *cdev,
726 struct chsc_pnso_area *pnso_area, u8 oc,
727 struct chsc_pnso_resume_token resume_token, int cnc)
729 struct subchannel_id schid;
731 ccw_device_get_schid(cdev, &schid);
732 return chsc_pnso(schid, pnso_area, oc, resume_token, cnc);
734 EXPORT_SYMBOL_GPL(ccw_device_pnso);
737 * ccw_device_get_cssid() - obtain Channel Subsystem ID
738 * @cdev: device to obtain the CSSID for
739 * @cssid: The resulting Channel Subsystem ID
741 int ccw_device_get_cssid(struct ccw_device *cdev, u8 *cssid)
743 struct device *sch_dev = cdev->dev.parent;
744 struct channel_subsystem *css = to_css(sch_dev->parent);
748 return css->id_valid ? 0 : -ENODEV;
750 EXPORT_SYMBOL_GPL(ccw_device_get_cssid);
753 * ccw_device_get_iid() - obtain MIF-image ID
754 * @cdev: device to obtain the MIF-image ID for
755 * @iid: The resulting MIF-image ID
757 int ccw_device_get_iid(struct ccw_device *cdev, u8 *iid)
759 struct device *sch_dev = cdev->dev.parent;
760 struct channel_subsystem *css = to_css(sch_dev->parent);
764 return css->id_valid ? 0 : -ENODEV;
766 EXPORT_SYMBOL_GPL(ccw_device_get_iid);
769 * ccw_device_get_chpid() - obtain Channel Path ID
770 * @cdev: device to obtain the Channel Path ID for
771 * @chp_idx: Index of the channel path
772 * @chpid: The resulting Channel Path ID
774 int ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid)
776 struct subchannel *sch = to_subchannel(cdev->dev.parent);
779 if ((chp_idx < 0) || (chp_idx > 7))
781 mask = 0x80 >> chp_idx;
782 if (!(sch->schib.pmcw.pim & mask))
785 *chpid = sch->schib.pmcw.chpid[chp_idx];
788 EXPORT_SYMBOL_GPL(ccw_device_get_chpid);
791 * ccw_device_get_chid() - obtain Channel ID associated with specified CHPID
792 * @cdev: device to obtain the Channel ID for
793 * @chp_idx: Index of the channel path
794 * @chid: The resulting Channel ID
796 int ccw_device_get_chid(struct ccw_device *cdev, int chp_idx, u16 *chid)
798 struct chp_id cssid_chpid;
799 struct channel_path *chp;
802 chp_id_init(&cssid_chpid);
803 rc = ccw_device_get_chpid(cdev, chp_idx, &cssid_chpid.id);
806 chp = chpid_to_chp(cssid_chpid);
810 mutex_lock(&chp->lock);
811 if (chp->desc_fmt1.flags & 0x10)
812 *chid = chp->desc_fmt1.chid;
815 mutex_unlock(&chp->lock);
819 EXPORT_SYMBOL_GPL(ccw_device_get_chid);
822 * Allocate zeroed dma coherent 31 bit addressable memory using
823 * the subchannels dma pool. Maximal size of allocation supported
826 void *ccw_device_dma_zalloc(struct ccw_device *cdev, size_t size)
830 if (!get_device(&cdev->dev))
832 addr = cio_gp_dma_zalloc(cdev->private->dma_pool, &cdev->dev, size);
833 if (IS_ERR_OR_NULL(addr))
834 put_device(&cdev->dev);
837 EXPORT_SYMBOL(ccw_device_dma_zalloc);
839 void ccw_device_dma_free(struct ccw_device *cdev, void *cpu_addr, size_t size)
843 cio_gp_dma_free(cdev->private->dma_pool, cpu_addr, size);
844 put_device(&cdev->dev);
846 EXPORT_SYMBOL(ccw_device_dma_free);
848 EXPORT_SYMBOL(ccw_device_set_options_mask);
849 EXPORT_SYMBOL(ccw_device_set_options);
850 EXPORT_SYMBOL(ccw_device_clear_options);
851 EXPORT_SYMBOL(ccw_device_clear);
852 EXPORT_SYMBOL(ccw_device_halt);
853 EXPORT_SYMBOL(ccw_device_resume);
854 EXPORT_SYMBOL(ccw_device_start_timeout);
855 EXPORT_SYMBOL(ccw_device_start);
856 EXPORT_SYMBOL(ccw_device_start_timeout_key);
857 EXPORT_SYMBOL(ccw_device_start_key);
858 EXPORT_SYMBOL(ccw_device_get_ciw);
859 EXPORT_SYMBOL(ccw_device_get_path_mask);
860 EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);
861 EXPORT_SYMBOL_GPL(ccw_device_get_util_str);