blob: cf8c4ac6323a6d1c91dfe93dfdb22e2d9d0432b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Sebastian Ott823d4942009-06-16 10:30:20 +02002 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Sebastian Ott823d4942009-06-16 10:30:20 +02004 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
5 * Cornelia Huck (cornelia.huck@de.ibm.com)
Paul Gortmakera00f7612016-10-30 16:37:24 -04006 *
7 * License: GPL
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Paul Gortmakera00f7612016-10-30 16:37:24 -04009#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#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>
Peter Oberparleiterd7d12ef2009-12-07 12:51:32 +010016#include <linux/completion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/ccwdev.h>
19#include <asm/idals.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020020#include <asm/chpid.h>
Peter Oberparleiter83262d62008-07-14 09:58:51 +020021#include <asm/fcx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "cio.h"
24#include "cio_debug.h"
25#include "css.h"
26#include "chsc.h"
27#include "device.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020028#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020030/**
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 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010040int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
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;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010052 cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return 0;
54}
55
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020056/**
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 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010065int 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;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010081 cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010082 return 0;
83}
84
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020085/**
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 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010092void 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;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010098 cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010099}
100
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200101/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200102 * ccw_device_is_pathgroup() - determine if paths to this device are grouped
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100103 * @cdev: ccw device
104 *
105 * Return non-zero if there is a path group, zero otherwise.
106 */
107int ccw_device_is_pathgroup(struct ccw_device *cdev)
108{
109 return cdev->private->flags.pgroup;
110}
111EXPORT_SYMBOL(ccw_device_is_pathgroup);
112
113/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200114 * ccw_device_is_multipath() - determine if device is operating in multipath mode
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100115 * @cdev: ccw device
116 *
117 * Return non-zero if device is operating in multipath mode, zero otherwise.
118 */
119int ccw_device_is_multipath(struct ccw_device *cdev)
120{
121 return cdev->private->flags.mpath;
122}
123EXPORT_SYMBOL(ccw_device_is_multipath);
124
125/**
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200126 * 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 */
140int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 struct subchannel *sch;
143 int ret;
144
Sebastian Otte45efa92009-06-12 10:26:27 +0200145 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200147 sch = to_subchannel(cdev->dev.parent);
148 if (!sch->schib.pmcw.ena)
149 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 if (cdev->private->state == DEV_STATE_NOT_OPER)
151 return -ENODEV;
152 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 cdev->private->state != DEV_STATE_W4SENSE)
154 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 ret = cio_clear(sch);
157 if (ret == 0)
158 cdev->private->intparm = intparm;
159 return ret;
160}
161
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200162/**
163 * ccw_device_start_key() - start a s390 channel program with 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 *
175 * Start a S/390 channel program. When the interrupt arrives, the
176 * IRQ handler is called, either immediately, delayed (dev-end missing,
177 * or sense required) or never (no IRQ handler registered).
178 * Returns:
179 * %0, if the operation was successful;
180 * -%EBUSY, if the device is busy, or status pending;
181 * -%EACCES, if no path specified in @lpm is operational;
182 * -%ENODEV, if the device is not operational.
183 * Context:
184 * Interrupts disabled, ccw device lock held
185 */
186int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
187 unsigned long intparm, __u8 lpm, __u8 key,
188 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 struct subchannel *sch;
191 int ret;
192
Sebastian Otte45efa92009-06-12 10:26:27 +0200193 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return -ENODEV;
195 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200196 if (!sch->schib.pmcw.ena)
197 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (cdev->private->state == DEV_STATE_NOT_OPER)
199 return -ENODEV;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +0100200 if (cdev->private->state == DEV_STATE_VERIFY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* Remember to fake irb when finished. */
202 if (!cdev->private->flags.fake_irb) {
Sebastian Ott50c8e312011-12-01 13:32:21 +0100203 cdev->private->flags.fake_irb = FAKE_CMD_IRB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 cdev->private->intparm = intparm;
205 return 0;
206 } else
207 /* There's already a fake I/O around. */
208 return -EBUSY;
209 }
210 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b62008-07-14 09:58:50 +0200211 ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
212 !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 cdev->private->flags.doverify)
214 return -EBUSY;
215 ret = cio_set_options (sch, flags);
216 if (ret)
217 return ret;
Sebastian Ott659213b2011-12-01 13:32:20 +0100218 /* Adjust requested path mask to exclude unusable paths. */
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200219 if (lpm) {
Sebastian Ott659213b2011-12-01 13:32:20 +0100220 lpm &= sch->lpm;
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200221 if (lpm == 0)
222 return -EACCES;
223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 ret = cio_start_key (sch, cpa, lpm, key);
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200225 switch (ret) {
226 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 cdev->private->intparm = intparm;
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200228 break;
229 case -EACCES:
230 case -ENODEV:
231 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
232 break;
233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return ret;
235}
236
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200237/**
238 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
239 * @cdev: target ccw device
240 * @cpa: logical start address of channel program
241 * @intparm: user specific interruption parameter; will be presented back to
242 * @cdev's interrupt handler. Allows a device driver to associate
243 * the interrupt with a particular I/O request.
244 * @lpm: defines the channel path to be used for a specific I/O request. A
245 * value of 0 will make cio use the opm.
246 * @key: storage key to be used for the I/O
247 * @flags: additional flags; defines the action to be performed for I/O
248 * processing.
249 * @expires: timeout value in jiffies
250 *
251 * Start a S/390 channel program. When the interrupt arrives, the
252 * IRQ handler is called, either immediately, delayed (dev-end missing,
253 * or sense required) or never (no IRQ handler registered).
254 * This function notifies the device driver if the channel program has not
255 * completed during the time specified by @expires. If a timeout occurs, the
256 * channel program is terminated via xsch, hsch or csch, and the device's
257 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
258 * Returns:
259 * %0, if the operation was successful;
260 * -%EBUSY, if the device is busy, or status pending;
261 * -%EACCES, if no path specified in @lpm is operational;
262 * -%ENODEV, if the device is not operational.
263 * Context:
264 * Interrupts disabled, ccw device lock held
265 */
266int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
267 unsigned long intparm, __u8 lpm, __u8 key,
268 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
270 int ret;
271
272 if (!cdev)
273 return -ENODEV;
274 ccw_device_set_timeout(cdev, expires);
275 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
276 if (ret != 0)
277 ccw_device_set_timeout(cdev, 0);
278 return ret;
279}
280
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200281/**
282 * ccw_device_start() - start a s390 channel program
283 * @cdev: target ccw device
284 * @cpa: logical start address of channel program
285 * @intparm: user specific interruption parameter; will be presented back to
286 * @cdev's interrupt handler. Allows a device driver to associate
287 * the interrupt with a particular I/O request.
288 * @lpm: defines the channel path to be used for a specific I/O request. A
289 * value of 0 will make cio use the opm.
290 * @flags: additional flags; defines the action to be performed for I/O
291 * processing.
292 *
293 * Start a S/390 channel program. When the interrupt arrives, the
294 * IRQ handler is called, either immediately, delayed (dev-end missing,
295 * or sense required) or never (no IRQ handler registered).
296 * Returns:
297 * %0, if the operation was successful;
298 * -%EBUSY, if the device is busy, or status pending;
299 * -%EACCES, if no path specified in @lpm is operational;
300 * -%ENODEV, if the device is not operational.
301 * Context:
302 * Interrupts disabled, ccw device lock held
303 */
304int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
305 unsigned long intparm, __u8 lpm, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
307 return ccw_device_start_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700308 PAGE_DEFAULT_KEY, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200311/**
312 * ccw_device_start_timeout() - start a s390 channel program with timeout
313 * @cdev: target ccw device
314 * @cpa: logical start address of channel program
315 * @intparm: user specific interruption parameter; will be presented back to
316 * @cdev's interrupt handler. Allows a device driver to associate
317 * the interrupt with a particular I/O request.
318 * @lpm: defines the channel path to be used for a specific I/O request. A
319 * value of 0 will make cio use the opm.
320 * @flags: additional flags; defines the action to be performed for I/O
321 * processing.
322 * @expires: timeout value in jiffies
323 *
324 * Start a S/390 channel program. When the interrupt arrives, the
325 * IRQ handler is called, either immediately, delayed (dev-end missing,
326 * or sense required) or never (no IRQ handler registered).
327 * This function notifies the device driver if the channel program has not
328 * completed during the time specified by @expires. If a timeout occurs, the
329 * channel program is terminated via xsch, hsch or csch, and the device's
330 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
331 * Returns:
332 * %0, if the operation was successful;
333 * -%EBUSY, if the device is busy, or status pending;
334 * -%EACCES, if no path specified in @lpm is operational;
335 * -%ENODEV, if the device is not operational.
336 * Context:
337 * Interrupts disabled, ccw device lock held
338 */
339int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
340 unsigned long intparm, __u8 lpm,
341 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700344 PAGE_DEFAULT_KEY, flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 expires);
346}
347
348
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200349/**
350 * ccw_device_halt() - halt I/O request processing
351 * @cdev: target ccw device
352 * @intparm: interruption parameter; value is only used if no I/O is
353 * outstanding, otherwise the intparm associated with the I/O request
354 * is returned
355 *
356 * ccw_device_halt() calls hsch on @cdev's subchannel.
357 * Returns:
358 * %0 on success,
359 * -%ENODEV on device not operational,
360 * -%EINVAL on invalid device state,
361 * -%EBUSY on device busy or interrupt pending.
362 * Context:
363 * Interrupts disabled, ccw device lock held
364 */
365int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 struct subchannel *sch;
368 int ret;
369
Sebastian Otte45efa92009-06-12 10:26:27 +0200370 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200372 sch = to_subchannel(cdev->dev.parent);
373 if (!sch->schib.pmcw.ena)
374 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (cdev->private->state == DEV_STATE_NOT_OPER)
376 return -ENODEV;
377 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 cdev->private->state != DEV_STATE_W4SENSE)
379 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 ret = cio_halt(sch);
382 if (ret == 0)
383 cdev->private->intparm = intparm;
384 return ret;
385}
386
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200387/**
388 * ccw_device_resume() - resume channel program execution
389 * @cdev: target ccw device
390 *
391 * ccw_device_resume() calls rsch on @cdev's subchannel.
392 * Returns:
393 * %0 on success,
394 * -%ENODEV on device not operational,
395 * -%EINVAL on invalid device state,
396 * -%EBUSY on device busy or interrupt pending.
397 * Context:
398 * Interrupts disabled, ccw device lock held
399 */
400int ccw_device_resume(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 struct subchannel *sch;
403
Sebastian Otte45efa92009-06-12 10:26:27 +0200404 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return -ENODEV;
406 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200407 if (!sch->schib.pmcw.ena)
408 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 if (cdev->private->state == DEV_STATE_NOT_OPER)
410 return -ENODEV;
411 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b62008-07-14 09:58:50 +0200412 !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return -EINVAL;
414 return cio_resume(sch);
415}
416
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200417/**
418 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
419 * @cdev: ccw device to inspect
420 * @ct: command type to look for
421 *
422 * During SenseID, command information words (CIWs) describing special
423 * commands available to the device may have been stored in the extended
424 * sense data. This function searches for CIWs of a specified command
425 * type in the extended sense data.
426 * Returns:
427 * %NULL if no extended sense data has been stored or if no CIW of the
428 * specified command type could be found,
429 * else a pointer to the CIW of the specified command type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200431struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 int ciw_cnt;
434
435 if (cdev->private->flags.esid == 0)
436 return NULL;
437 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
438 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
439 return cdev->private->senseid.ciw + ciw_cnt;
440 return NULL;
441}
442
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200443/**
444 * ccw_device_get_path_mask() - get currently available paths
445 * @cdev: ccw device to be queried
446 * Returns:
447 * %0 if no subchannel for the device is available,
448 * else the mask of currently available paths for the ccw device's subchannel.
449 */
450__u8 ccw_device_get_path_mask(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 struct subchannel *sch;
453
Sebastian Otte45efa92009-06-12 10:26:27 +0200454 if (!cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 0;
Sebastian Otte45efa92009-06-12 10:26:27 +0200456
457 sch = to_subchannel(cdev->dev.parent);
458 return sch->lpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Sebastian Ott2bf29df2014-05-07 13:27:21 +0200461/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200462 * ccw_device_get_chp_desc() - return newly allocated channel-path descriptor
Sebastian Ott2bf29df2014-05-07 13:27:21 +0200463 * @cdev: device to obtain the descriptor for
464 * @chp_idx: index of the channel path
465 *
466 * On success return a newly allocated copy of the channel-path description
467 * data associated with the given channel path. Return %NULL on error.
468 */
469struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *cdev,
470 int chp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 struct subchannel *sch;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200473 struct chp_id chpid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200476 chp_id_init(&chpid);
Sebastian Ott2bf29df2014-05-07 13:27:21 +0200477 chpid.id = sch->schib.pmcw.chpid[chp_idx];
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200478 return chp_get_chp_desc(chpid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200481/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200482 * ccw_device_get_id() - obtain a ccw device id
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200483 * @cdev: device to obtain the id for
484 * @dev_id: where to fill in the values
485 */
486void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
487{
488 *dev_id = cdev->private->dev_id;
489}
490EXPORT_SYMBOL(ccw_device_get_id);
491
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200492/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200493 * ccw_device_tm_start_key() - perform start function
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200494 * @cdev: ccw device on which to perform the start function
495 * @tcw: transport-command word to be started
496 * @intparm: user defined parameter to be passed to the interrupt handler
497 * @lpm: mask of paths to use
498 * @key: storage key to use for storage access
499 *
500 * Start the tcw on the given ccw device. Return zero on success, non-zero
501 * otherwise.
502 */
503int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
504 unsigned long intparm, u8 lpm, u8 key)
505{
506 struct subchannel *sch;
507 int rc;
508
509 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200510 if (!sch->schib.pmcw.ena)
511 return -EINVAL;
Sebastian Ott50c8e312011-12-01 13:32:21 +0100512 if (cdev->private->state == DEV_STATE_VERIFY) {
513 /* Remember to fake irb when finished. */
514 if (!cdev->private->flags.fake_irb) {
515 cdev->private->flags.fake_irb = FAKE_TM_IRB;
516 cdev->private->intparm = intparm;
517 return 0;
518 } else
519 /* There's already a fake I/O around. */
520 return -EBUSY;
521 }
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200522 if (cdev->private->state != DEV_STATE_ONLINE)
523 return -EIO;
Sebastian Ott659213b2011-12-01 13:32:20 +0100524 /* Adjust requested path mask to exclude unusable paths. */
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200525 if (lpm) {
Sebastian Ott659213b2011-12-01 13:32:20 +0100526 lpm &= sch->lpm;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200527 if (lpm == 0)
528 return -EACCES;
529 }
530 rc = cio_tm_start_key(sch, tcw, lpm, key);
531 if (rc == 0)
532 cdev->private->intparm = intparm;
533 return rc;
534}
535EXPORT_SYMBOL(ccw_device_tm_start_key);
536
537/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200538 * ccw_device_tm_start_timeout_key() - perform start function
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200539 * @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 * @expires: time span in jiffies after which to abort request
545 *
546 * Start the tcw on the given ccw device. Return zero on success, non-zero
547 * otherwise.
548 */
549int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
550 unsigned long intparm, u8 lpm, u8 key,
551 int expires)
552{
553 int ret;
554
555 ccw_device_set_timeout(cdev, expires);
556 ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
557 if (ret != 0)
558 ccw_device_set_timeout(cdev, 0);
559 return ret;
560}
561EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
562
563/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200564 * ccw_device_tm_start() - perform start function
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200565 * @cdev: ccw device on which to perform the start function
566 * @tcw: transport-command word to be started
567 * @intparm: user defined parameter to be passed to the interrupt handler
568 * @lpm: mask of paths to use
569 *
570 * Start the tcw on the given ccw device. Return zero on success, non-zero
571 * otherwise.
572 */
573int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
574 unsigned long intparm, u8 lpm)
575{
576 return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
577 PAGE_DEFAULT_KEY);
578}
579EXPORT_SYMBOL(ccw_device_tm_start);
580
581/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200582 * ccw_device_tm_start_timeout() - perform start function
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200583 * @cdev: ccw device on which to perform the start function
584 * @tcw: transport-command word to be started
585 * @intparm: user defined parameter to be passed to the interrupt handler
586 * @lpm: mask of paths to use
587 * @expires: time span in jiffies after which to abort request
588 *
589 * Start the tcw on the given ccw device. Return zero on success, non-zero
590 * otherwise.
591 */
592int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
593 unsigned long intparm, u8 lpm, int expires)
594{
595 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
596 PAGE_DEFAULT_KEY, expires);
597}
598EXPORT_SYMBOL(ccw_device_tm_start_timeout);
599
600/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200601 * ccw_device_get_mdc() - accumulate max data count
Sebastian Ottce322cc2011-01-05 12:47:56 +0100602 * @cdev: ccw device for which the max data count is accumulated
603 * @mask: mask of paths to use
604 *
605 * Return the number of 64K-bytes blocks all paths at least support
606 * for a transport command. Return values <= 0 indicate failures.
607 */
608int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
609{
610 struct subchannel *sch = to_subchannel(cdev->dev.parent);
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100611 struct channel_path *chp;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100612 struct chp_id chpid;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100613 int mdc = 0, i;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100614
615 /* Adjust requested path mask to excluded varied off paths. */
616 if (mask)
617 mask &= sch->lpm;
618 else
619 mask = sch->lpm;
620
621 chp_id_init(&chpid);
622 for (i = 0; i < 8; i++) {
623 if (!(mask & (0x80 >> i)))
624 continue;
625 chpid.id = sch->schib.pmcw.chpid[i];
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100626 chp = chpid_to_chp(chpid);
627 if (!chp)
628 continue;
629
630 mutex_lock(&chp->lock);
631 if (!chp->desc_fmt1.f) {
632 mutex_unlock(&chp->lock);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100633 return 0;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100634 }
635 if (!chp->desc_fmt1.r)
Sebastian Ottce322cc2011-01-05 12:47:56 +0100636 mdc = 1;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100637 mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
638 chp->desc_fmt1.mdc;
639 mutex_unlock(&chp->lock);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100640 }
641
642 return mdc;
643}
644EXPORT_SYMBOL(ccw_device_get_mdc);
645
646/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200647 * ccw_device_tm_intrg() - perform interrogate function
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200648 * @cdev: ccw device on which to perform the interrogate function
649 *
650 * Perform an interrogate function on the given ccw device. Return zero on
651 * success, non-zero otherwise.
652 */
653int ccw_device_tm_intrg(struct ccw_device *cdev)
654{
655 struct subchannel *sch = to_subchannel(cdev->dev.parent);
656
Sebastian Ott823d4942009-06-16 10:30:20 +0200657 if (!sch->schib.pmcw.ena)
658 return -EINVAL;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200659 if (cdev->private->state != DEV_STATE_ONLINE)
660 return -EIO;
661 if (!scsw_is_tm(&sch->schib.scsw) ||
Peter Oberparleiter7a968f02009-03-26 15:24:18 +0100662 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200663 return -EINVAL;
664 return cio_tm_intrg(sch);
665}
666EXPORT_SYMBOL(ccw_device_tm_intrg);
667
Cornelia Huck9368dac2012-05-30 16:03:22 +0200668/**
Sebastian Ott388b74d2016-06-23 11:09:26 +0200669 * ccw_device_get_schid() - obtain a subchannel id
Cornelia Huck9368dac2012-05-30 16:03:22 +0200670 * @cdev: device to obtain the id for
671 * @schid: where to fill in the values
672 */
673void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
674{
675 struct subchannel *sch = to_subchannel(cdev->dev.parent);
676
677 *schid = sch->schid;
678}
679EXPORT_SYMBOL_GPL(ccw_device_get_schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100681EXPORT_SYMBOL(ccw_device_set_options_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682EXPORT_SYMBOL(ccw_device_set_options);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100683EXPORT_SYMBOL(ccw_device_clear_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684EXPORT_SYMBOL(ccw_device_clear);
685EXPORT_SYMBOL(ccw_device_halt);
686EXPORT_SYMBOL(ccw_device_resume);
687EXPORT_SYMBOL(ccw_device_start_timeout);
688EXPORT_SYMBOL(ccw_device_start);
689EXPORT_SYMBOL(ccw_device_start_timeout_key);
690EXPORT_SYMBOL(ccw_device_start_key);
691EXPORT_SYMBOL(ccw_device_get_ciw);
692EXPORT_SYMBOL(ccw_device_get_path_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);