blob: a69f702a2fcc36d11f6d815afc511af790bcfc7d [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)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#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>
Peter Oberparleiterd7d12ef2009-12-07 12:51:32 +010014#include <linux/completion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/ccwdev.h>
17#include <asm/idals.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020018#include <asm/chpid.h>
Peter Oberparleiter83262d62008-07-14 09:58:51 +020019#include <asm/fcx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "cio.h"
22#include "cio_debug.h"
23#include "css.h"
24#include "chsc.h"
25#include "device.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020026#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020028/**
29 * ccw_device_set_options_mask() - set some options and unset the rest
30 * @cdev: device for which the options are to be set
31 * @flags: options to be set
32 *
33 * All flags specified in @flags are set, all flags not specified in @flags
34 * are cleared.
35 * Returns:
36 * %0 on success, -%EINVAL on an invalid flag combination.
37 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010038int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 /*
41 * The flag usage is mutal exclusive ...
42 */
43 if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
44 (flags & CCWDEV_REPORT_ALL))
45 return -EINVAL;
46 cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
47 cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0;
48 cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0;
49 cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010050 cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return 0;
52}
53
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020054/**
55 * ccw_device_set_options() - set some options
56 * @cdev: device for which the options are to be set
57 * @flags: options to be set
58 *
59 * All flags specified in @flags are set, the remainder is left untouched.
60 * Returns:
61 * %0 on success, -%EINVAL if an invalid flag combination would ensue.
62 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010063int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
64{
65 /*
66 * The flag usage is mutal exclusive ...
67 */
68 if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
69 (flags & CCWDEV_REPORT_ALL)) ||
70 ((flags & CCWDEV_EARLY_NOTIFICATION) &&
71 cdev->private->options.repall) ||
72 ((flags & CCWDEV_REPORT_ALL) &&
73 cdev->private->options.fast))
74 return -EINVAL;
75 cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
76 cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
77 cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
78 cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010079 cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010080 return 0;
81}
82
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020083/**
84 * ccw_device_clear_options() - clear some options
85 * @cdev: device for which the options are to be cleared
86 * @flags: options to be cleared
87 *
88 * All flags specified in @flags are cleared, the remainder is left untouched.
89 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010090void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
91{
92 cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
93 cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
94 cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
95 cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010096 cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010097}
98
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020099/**
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100100 * ccw_device_is_pathgroup - determine if paths to this device are grouped
101 * @cdev: ccw device
102 *
103 * Return non-zero if there is a path group, zero otherwise.
104 */
105int ccw_device_is_pathgroup(struct ccw_device *cdev)
106{
107 return cdev->private->flags.pgroup;
108}
109EXPORT_SYMBOL(ccw_device_is_pathgroup);
110
111/**
112 * ccw_device_is_multipath - determine if device is operating in multipath mode
113 * @cdev: ccw device
114 *
115 * Return non-zero if device is operating in multipath mode, zero otherwise.
116 */
117int ccw_device_is_multipath(struct ccw_device *cdev)
118{
119 return cdev->private->flags.mpath;
120}
121EXPORT_SYMBOL(ccw_device_is_multipath);
122
123/**
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200124 * ccw_device_clear() - terminate I/O request processing
125 * @cdev: target ccw device
126 * @intparm: interruption parameter; value is only used if no I/O is
127 * outstanding, otherwise the intparm associated with the I/O request
128 * is returned
129 *
130 * ccw_device_clear() calls csch on @cdev's subchannel.
131 * Returns:
132 * %0 on success,
133 * -%ENODEV on device not operational,
134 * -%EINVAL on invalid device state.
135 * Context:
136 * Interrupts disabled, ccw device lock held
137 */
138int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
140 struct subchannel *sch;
141 int ret;
142
Sebastian Otte45efa92009-06-12 10:26:27 +0200143 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200145 sch = to_subchannel(cdev->dev.parent);
146 if (!sch->schib.pmcw.ena)
147 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (cdev->private->state == DEV_STATE_NOT_OPER)
149 return -ENODEV;
150 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 cdev->private->state != DEV_STATE_W4SENSE)
152 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 ret = cio_clear(sch);
155 if (ret == 0)
156 cdev->private->intparm = intparm;
157 return ret;
158}
159
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200160/**
161 * ccw_device_start_key() - start a s390 channel program with key
162 * @cdev: target ccw device
163 * @cpa: logical start address of channel program
164 * @intparm: user specific interruption parameter; will be presented back to
165 * @cdev's interrupt handler. Allows a device driver to associate
166 * the interrupt with a particular I/O request.
167 * @lpm: defines the channel path to be used for a specific I/O request. A
168 * value of 0 will make cio use the opm.
169 * @key: storage key to be used for the I/O
170 * @flags: additional flags; defines the action to be performed for I/O
171 * processing.
172 *
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 * Returns:
177 * %0, if the operation was successful;
178 * -%EBUSY, if the device is busy, or status pending;
179 * -%EACCES, if no path specified in @lpm is operational;
180 * -%ENODEV, if the device is not operational.
181 * Context:
182 * Interrupts disabled, ccw device lock held
183 */
184int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
185 unsigned long intparm, __u8 lpm, __u8 key,
186 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 struct subchannel *sch;
189 int ret;
190
Sebastian Otte45efa92009-06-12 10:26:27 +0200191 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return -ENODEV;
193 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200194 if (!sch->schib.pmcw.ena)
195 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (cdev->private->state == DEV_STATE_NOT_OPER)
197 return -ENODEV;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +0100198 if (cdev->private->state == DEV_STATE_VERIFY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 /* Remember to fake irb when finished. */
200 if (!cdev->private->flags.fake_irb) {
Sebastian Ott50c8e312011-12-01 13:32:21 +0100201 cdev->private->flags.fake_irb = FAKE_CMD_IRB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 cdev->private->intparm = intparm;
203 return 0;
204 } else
205 /* There's already a fake I/O around. */
206 return -EBUSY;
207 }
208 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200209 ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
210 !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 cdev->private->flags.doverify)
212 return -EBUSY;
213 ret = cio_set_options (sch, flags);
214 if (ret)
215 return ret;
Sebastian Ott659213b2011-12-01 13:32:20 +0100216 /* Adjust requested path mask to exclude unusable paths. */
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200217 if (lpm) {
Sebastian Ott659213b2011-12-01 13:32:20 +0100218 lpm &= sch->lpm;
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200219 if (lpm == 0)
220 return -EACCES;
221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 ret = cio_start_key (sch, cpa, lpm, key);
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200223 switch (ret) {
224 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 cdev->private->intparm = intparm;
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200226 break;
227 case -EACCES:
228 case -ENODEV:
229 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
230 break;
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return ret;
233}
234
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200235/**
236 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
237 * @cdev: target ccw device
238 * @cpa: logical start address of channel program
239 * @intparm: user specific interruption parameter; will be presented back to
240 * @cdev's interrupt handler. Allows a device driver to associate
241 * the interrupt with a particular I/O request.
242 * @lpm: defines the channel path to be used for a specific I/O request. A
243 * value of 0 will make cio use the opm.
244 * @key: storage key to be used for the I/O
245 * @flags: additional flags; defines the action to be performed for I/O
246 * processing.
247 * @expires: timeout value in jiffies
248 *
249 * Start a S/390 channel program. When the interrupt arrives, the
250 * IRQ handler is called, either immediately, delayed (dev-end missing,
251 * or sense required) or never (no IRQ handler registered).
252 * This function notifies the device driver if the channel program has not
253 * completed during the time specified by @expires. If a timeout occurs, the
254 * channel program is terminated via xsch, hsch or csch, and the device's
255 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
256 * Returns:
257 * %0, if the operation was successful;
258 * -%EBUSY, if the device is busy, or status pending;
259 * -%EACCES, if no path specified in @lpm is operational;
260 * -%ENODEV, if the device is not operational.
261 * Context:
262 * Interrupts disabled, ccw device lock held
263 */
264int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
265 unsigned long intparm, __u8 lpm, __u8 key,
266 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 int ret;
269
270 if (!cdev)
271 return -ENODEV;
272 ccw_device_set_timeout(cdev, expires);
273 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
274 if (ret != 0)
275 ccw_device_set_timeout(cdev, 0);
276 return ret;
277}
278
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200279/**
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
289 * processing.
290 *
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 * Returns:
295 * %0, if the operation was successful;
296 * -%EBUSY, if the device is busy, or status pending;
297 * -%EACCES, if no path specified in @lpm is operational;
298 * -%ENODEV, if the device is not operational.
299 * Context:
300 * Interrupts disabled, ccw device lock held
301 */
302int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
303 unsigned long intparm, __u8 lpm, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
305 return ccw_device_start_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700306 PAGE_DEFAULT_KEY, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200309/**
310 * ccw_device_start_timeout() - start a s390 channel program with timeout
311 * @cdev: target ccw device
312 * @cpa: logical start address of channel program
313 * @intparm: user specific interruption parameter; will be presented back to
314 * @cdev's interrupt handler. Allows a device driver to associate
315 * the interrupt with a particular I/O request.
316 * @lpm: defines the channel path to be used for a specific I/O request. A
317 * value of 0 will make cio use the opm.
318 * @flags: additional flags; defines the action to be performed for I/O
319 * processing.
320 * @expires: timeout value in jiffies
321 *
322 * Start a S/390 channel program. When the interrupt arrives, the
323 * IRQ handler is called, either immediately, delayed (dev-end missing,
324 * or sense required) or never (no IRQ handler registered).
325 * This function notifies the device driver if the channel program has not
326 * completed during the time specified by @expires. If a timeout occurs, the
327 * channel program is terminated via xsch, hsch or csch, and the device's
328 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
329 * Returns:
330 * %0, if the operation was successful;
331 * -%EBUSY, if the device is busy, or status pending;
332 * -%EACCES, if no path specified in @lpm is operational;
333 * -%ENODEV, if the device is not operational.
334 * Context:
335 * Interrupts disabled, ccw device lock held
336 */
337int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
338 unsigned long intparm, __u8 lpm,
339 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700342 PAGE_DEFAULT_KEY, flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 expires);
344}
345
346
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200347/**
348 * ccw_device_halt() - halt I/O request processing
349 * @cdev: target ccw device
350 * @intparm: interruption parameter; value is only used if no I/O is
351 * outstanding, otherwise the intparm associated with the I/O request
352 * is returned
353 *
354 * ccw_device_halt() calls hsch on @cdev's subchannel.
355 * Returns:
356 * %0 on success,
357 * -%ENODEV on device not operational,
358 * -%EINVAL on invalid device state,
359 * -%EBUSY on device busy or interrupt pending.
360 * Context:
361 * Interrupts disabled, ccw device lock held
362 */
363int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 struct subchannel *sch;
366 int ret;
367
Sebastian Otte45efa92009-06-12 10:26:27 +0200368 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200370 sch = to_subchannel(cdev->dev.parent);
371 if (!sch->schib.pmcw.ena)
372 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (cdev->private->state == DEV_STATE_NOT_OPER)
374 return -ENODEV;
375 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 cdev->private->state != DEV_STATE_W4SENSE)
377 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ret = cio_halt(sch);
380 if (ret == 0)
381 cdev->private->intparm = intparm;
382 return ret;
383}
384
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200385/**
386 * ccw_device_resume() - resume channel program execution
387 * @cdev: target ccw device
388 *
389 * ccw_device_resume() calls rsch on @cdev's subchannel.
390 * Returns:
391 * %0 on success,
392 * -%ENODEV on device not operational,
393 * -%EINVAL on invalid device state,
394 * -%EBUSY on device busy or interrupt pending.
395 * Context:
396 * Interrupts disabled, ccw device lock held
397 */
398int ccw_device_resume(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 struct subchannel *sch;
401
Sebastian Otte45efa92009-06-12 10:26:27 +0200402 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return -ENODEV;
404 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200405 if (!sch->schib.pmcw.ena)
406 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 if (cdev->private->state == DEV_STATE_NOT_OPER)
408 return -ENODEV;
409 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200410 !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 return -EINVAL;
412 return cio_resume(sch);
413}
414
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200415/**
416 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
417 * @cdev: ccw device to inspect
418 * @ct: command type to look for
419 *
420 * During SenseID, command information words (CIWs) describing special
421 * commands available to the device may have been stored in the extended
422 * sense data. This function searches for CIWs of a specified command
423 * type in the extended sense data.
424 * Returns:
425 * %NULL if no extended sense data has been stored or if no CIW of the
426 * specified command type could be found,
427 * else a pointer to the CIW of the specified command type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200429struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 int ciw_cnt;
432
433 if (cdev->private->flags.esid == 0)
434 return NULL;
435 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
436 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
437 return cdev->private->senseid.ciw + ciw_cnt;
438 return NULL;
439}
440
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200441/**
442 * ccw_device_get_path_mask() - get currently available paths
443 * @cdev: ccw device to be queried
444 * Returns:
445 * %0 if no subchannel for the device is available,
446 * else the mask of currently available paths for the ccw device's subchannel.
447 */
448__u8 ccw_device_get_path_mask(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 struct subchannel *sch;
451
Sebastian Otte45efa92009-06-12 10:26:27 +0200452 if (!cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return 0;
Sebastian Otte45efa92009-06-12 10:26:27 +0200454
455 sch = to_subchannel(cdev->dev.parent);
456 return sch->lpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
Sebastian Ott2bf29df2014-05-07 13:27:21 +0200459/**
460 * chp_get_chp_desc - return newly allocated channel-path descriptor
461 * @cdev: device to obtain the descriptor for
462 * @chp_idx: index of the channel path
463 *
464 * On success return a newly allocated copy of the channel-path description
465 * data associated with the given channel path. Return %NULL on error.
466 */
467struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *cdev,
468 int chp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 struct subchannel *sch;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200471 struct chp_id chpid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200474 chp_id_init(&chpid);
Sebastian Ott2bf29df2014-05-07 13:27:21 +0200475 chpid.id = sch->schib.pmcw.chpid[chp_idx];
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200476 return chp_get_chp_desc(chpid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200479/**
480 * ccw_device_get_id - obtain a ccw device id
481 * @cdev: device to obtain the id for
482 * @dev_id: where to fill in the values
483 */
484void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
485{
486 *dev_id = cdev->private->dev_id;
487}
488EXPORT_SYMBOL(ccw_device_get_id);
489
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200490/**
491 * ccw_device_tm_start_key - perform start function
492 * @cdev: ccw device on which to perform the start function
493 * @tcw: transport-command word to be started
494 * @intparm: user defined parameter to be passed to the interrupt handler
495 * @lpm: mask of paths to use
496 * @key: storage key to use for storage access
497 *
498 * Start the tcw on the given ccw device. Return zero on success, non-zero
499 * otherwise.
500 */
501int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
502 unsigned long intparm, u8 lpm, u8 key)
503{
504 struct subchannel *sch;
505 int rc;
506
507 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200508 if (!sch->schib.pmcw.ena)
509 return -EINVAL;
Sebastian Ott50c8e312011-12-01 13:32:21 +0100510 if (cdev->private->state == DEV_STATE_VERIFY) {
511 /* Remember to fake irb when finished. */
512 if (!cdev->private->flags.fake_irb) {
513 cdev->private->flags.fake_irb = FAKE_TM_IRB;
514 cdev->private->intparm = intparm;
515 return 0;
516 } else
517 /* There's already a fake I/O around. */
518 return -EBUSY;
519 }
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200520 if (cdev->private->state != DEV_STATE_ONLINE)
521 return -EIO;
Sebastian Ott659213b2011-12-01 13:32:20 +0100522 /* Adjust requested path mask to exclude unusable paths. */
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200523 if (lpm) {
Sebastian Ott659213b2011-12-01 13:32:20 +0100524 lpm &= sch->lpm;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200525 if (lpm == 0)
526 return -EACCES;
527 }
528 rc = cio_tm_start_key(sch, tcw, lpm, key);
529 if (rc == 0)
530 cdev->private->intparm = intparm;
531 return rc;
532}
533EXPORT_SYMBOL(ccw_device_tm_start_key);
534
535/**
536 * ccw_device_tm_start_timeout_key - perform start function
537 * @cdev: ccw device on which to perform the start function
538 * @tcw: transport-command word to be started
539 * @intparm: user defined parameter to be passed to the interrupt handler
540 * @lpm: mask of paths to use
541 * @key: storage key to use for storage access
542 * @expires: time span in jiffies after which to abort request
543 *
544 * Start the tcw on the given ccw device. Return zero on success, non-zero
545 * otherwise.
546 */
547int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
548 unsigned long intparm, u8 lpm, u8 key,
549 int expires)
550{
551 int ret;
552
553 ccw_device_set_timeout(cdev, expires);
554 ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
555 if (ret != 0)
556 ccw_device_set_timeout(cdev, 0);
557 return ret;
558}
559EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
560
561/**
562 * ccw_device_tm_start - perform start function
563 * @cdev: ccw device on which to perform the start function
564 * @tcw: transport-command word to be started
565 * @intparm: user defined parameter to be passed to the interrupt handler
566 * @lpm: mask of paths to use
567 *
568 * Start the tcw on the given ccw device. Return zero on success, non-zero
569 * otherwise.
570 */
571int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
572 unsigned long intparm, u8 lpm)
573{
574 return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
575 PAGE_DEFAULT_KEY);
576}
577EXPORT_SYMBOL(ccw_device_tm_start);
578
579/**
580 * ccw_device_tm_start_timeout - perform start function
581 * @cdev: ccw device on which to perform the start function
582 * @tcw: transport-command word to be started
583 * @intparm: user defined parameter to be passed to the interrupt handler
584 * @lpm: mask of paths to use
585 * @expires: time span in jiffies after which to abort request
586 *
587 * Start the tcw on the given ccw device. Return zero on success, non-zero
588 * otherwise.
589 */
590int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
591 unsigned long intparm, u8 lpm, int expires)
592{
593 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
594 PAGE_DEFAULT_KEY, expires);
595}
596EXPORT_SYMBOL(ccw_device_tm_start_timeout);
597
598/**
Sebastian Ottce322cc2011-01-05 12:47:56 +0100599 * ccw_device_get_mdc - accumulate max data count
600 * @cdev: ccw device for which the max data count is accumulated
601 * @mask: mask of paths to use
602 *
603 * Return the number of 64K-bytes blocks all paths at least support
604 * for a transport command. Return values <= 0 indicate failures.
605 */
606int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
607{
608 struct subchannel *sch = to_subchannel(cdev->dev.parent);
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100609 struct channel_path *chp;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100610 struct chp_id chpid;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100611 int mdc = 0, i;
Sebastian Ottce322cc2011-01-05 12:47:56 +0100612
613 /* Adjust requested path mask to excluded varied off paths. */
614 if (mask)
615 mask &= sch->lpm;
616 else
617 mask = sch->lpm;
618
619 chp_id_init(&chpid);
620 for (i = 0; i < 8; i++) {
621 if (!(mask & (0x80 >> i)))
622 continue;
623 chpid.id = sch->schib.pmcw.chpid[i];
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100624 chp = chpid_to_chp(chpid);
625 if (!chp)
626 continue;
627
628 mutex_lock(&chp->lock);
629 if (!chp->desc_fmt1.f) {
630 mutex_unlock(&chp->lock);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100631 return 0;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100632 }
633 if (!chp->desc_fmt1.r)
Sebastian Ottce322cc2011-01-05 12:47:56 +0100634 mdc = 1;
Peter Oberparleiter040495d2013-03-11 13:01:08 +0100635 mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
636 chp->desc_fmt1.mdc;
637 mutex_unlock(&chp->lock);
Sebastian Ottce322cc2011-01-05 12:47:56 +0100638 }
639
640 return mdc;
641}
642EXPORT_SYMBOL(ccw_device_get_mdc);
643
644/**
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200645 * ccw_device_tm_intrg - perform interrogate function
646 * @cdev: ccw device on which to perform the interrogate function
647 *
648 * Perform an interrogate function on the given ccw device. Return zero on
649 * success, non-zero otherwise.
650 */
651int ccw_device_tm_intrg(struct ccw_device *cdev)
652{
653 struct subchannel *sch = to_subchannel(cdev->dev.parent);
654
Sebastian Ott823d4942009-06-16 10:30:20 +0200655 if (!sch->schib.pmcw.ena)
656 return -EINVAL;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200657 if (cdev->private->state != DEV_STATE_ONLINE)
658 return -EIO;
659 if (!scsw_is_tm(&sch->schib.scsw) ||
Peter Oberparleiter7a968f02009-03-26 15:24:18 +0100660 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200661 return -EINVAL;
662 return cio_tm_intrg(sch);
663}
664EXPORT_SYMBOL(ccw_device_tm_intrg);
665
Cornelia Huck9368dac2012-05-30 16:03:22 +0200666/**
667 * ccw_device_get_schid - obtain a subchannel id
668 * @cdev: device to obtain the id for
669 * @schid: where to fill in the values
670 */
671void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
672{
673 struct subchannel *sch = to_subchannel(cdev->dev.parent);
674
675 *schid = sch->schid;
676}
677EXPORT_SYMBOL_GPL(ccw_device_get_schid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679MODULE_LICENSE("GPL");
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100680EXPORT_SYMBOL(ccw_device_set_options_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681EXPORT_SYMBOL(ccw_device_set_options);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100682EXPORT_SYMBOL(ccw_device_clear_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683EXPORT_SYMBOL(ccw_device_clear);
684EXPORT_SYMBOL(ccw_device_halt);
685EXPORT_SYMBOL(ccw_device_resume);
686EXPORT_SYMBOL(ccw_device_start_timeout);
687EXPORT_SYMBOL(ccw_device_start);
688EXPORT_SYMBOL(ccw_device_start_timeout_key);
689EXPORT_SYMBOL(ccw_device_start_key);
690EXPORT_SYMBOL(ccw_device_get_ciw);
691EXPORT_SYMBOL(ccw_device_get_path_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);