blob: d4be16acebe483edb33b6b020882394107e3ba9a [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>
14
15#include <asm/ccwdev.h>
16#include <asm/idals.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020017#include <asm/chpid.h>
Peter Oberparleiter83262d62008-07-14 09:58:51 +020018#include <asm/fcx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include "cio.h"
21#include "cio_debug.h"
22#include "css.h"
23#include "chsc.h"
24#include "device.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020025#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020027/**
28 * ccw_device_set_options_mask() - set some options and unset the rest
29 * @cdev: device for which the options are to be set
30 * @flags: options to be set
31 *
32 * All flags specified in @flags are set, all flags not specified in @flags
33 * are cleared.
34 * Returns:
35 * %0 on success, -%EINVAL on an invalid flag combination.
36 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010037int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 /*
40 * The flag usage is mutal exclusive ...
41 */
42 if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
43 (flags & CCWDEV_REPORT_ALL))
44 return -EINVAL;
45 cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
46 cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0;
47 cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0;
48 cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010049 cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return 0;
51}
52
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020053/**
54 * ccw_device_set_options() - set some options
55 * @cdev: device for which the options are to be set
56 * @flags: options to be set
57 *
58 * All flags specified in @flags are set, the remainder is left untouched.
59 * Returns:
60 * %0 on success, -%EINVAL if an invalid flag combination would ensue.
61 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010062int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
63{
64 /*
65 * The flag usage is mutal exclusive ...
66 */
67 if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
68 (flags & CCWDEV_REPORT_ALL)) ||
69 ((flags & CCWDEV_EARLY_NOTIFICATION) &&
70 cdev->private->options.repall) ||
71 ((flags & CCWDEV_REPORT_ALL) &&
72 cdev->private->options.fast))
73 return -EINVAL;
74 cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
75 cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
76 cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
77 cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010078 cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010079 return 0;
80}
81
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020082/**
83 * ccw_device_clear_options() - clear some options
84 * @cdev: device for which the options are to be cleared
85 * @flags: options to be cleared
86 *
87 * All flags specified in @flags are cleared, the remainder is left untouched.
88 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010089void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
90{
91 cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
92 cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
93 cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
94 cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010095 cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010096}
97
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020098/**
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010099 * ccw_device_is_pathgroup - determine if paths to this device are grouped
100 * @cdev: ccw device
101 *
102 * Return non-zero if there is a path group, zero otherwise.
103 */
104int ccw_device_is_pathgroup(struct ccw_device *cdev)
105{
106 return cdev->private->flags.pgroup;
107}
108EXPORT_SYMBOL(ccw_device_is_pathgroup);
109
110/**
111 * ccw_device_is_multipath - determine if device is operating in multipath mode
112 * @cdev: ccw device
113 *
114 * Return non-zero if device is operating in multipath mode, zero otherwise.
115 */
116int ccw_device_is_multipath(struct ccw_device *cdev)
117{
118 return cdev->private->flags.mpath;
119}
120EXPORT_SYMBOL(ccw_device_is_multipath);
121
122/**
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200123 * ccw_device_clear() - terminate I/O request processing
124 * @cdev: target ccw device
125 * @intparm: interruption parameter; value is only used if no I/O is
126 * outstanding, otherwise the intparm associated with the I/O request
127 * is returned
128 *
129 * ccw_device_clear() calls csch on @cdev's subchannel.
130 * Returns:
131 * %0 on success,
132 * -%ENODEV on device not operational,
133 * -%EINVAL on invalid device state.
134 * Context:
135 * Interrupts disabled, ccw device lock held
136 */
137int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 struct subchannel *sch;
140 int ret;
141
Sebastian Otte45efa92009-06-12 10:26:27 +0200142 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200144 sch = to_subchannel(cdev->dev.parent);
145 if (!sch->schib.pmcw.ena)
146 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 if (cdev->private->state == DEV_STATE_NOT_OPER)
148 return -ENODEV;
149 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 cdev->private->state != DEV_STATE_W4SENSE)
151 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 ret = cio_clear(sch);
154 if (ret == 0)
155 cdev->private->intparm = intparm;
156 return ret;
157}
158
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200159/**
160 * ccw_device_start_key() - start a s390 channel program with key
161 * @cdev: target ccw device
162 * @cpa: logical start address of channel program
163 * @intparm: user specific interruption parameter; will be presented back to
164 * @cdev's interrupt handler. Allows a device driver to associate
165 * the interrupt with a particular I/O request.
166 * @lpm: defines the channel path to be used for a specific I/O request. A
167 * value of 0 will make cio use the opm.
168 * @key: storage key to be used for the I/O
169 * @flags: additional flags; defines the action to be performed for I/O
170 * processing.
171 *
172 * Start a S/390 channel program. When the interrupt arrives, the
173 * IRQ handler is called, either immediately, delayed (dev-end missing,
174 * or sense required) or never (no IRQ handler registered).
175 * Returns:
176 * %0, if the operation was successful;
177 * -%EBUSY, if the device is busy, or status pending;
178 * -%EACCES, if no path specified in @lpm is operational;
179 * -%ENODEV, if the device is not operational.
180 * Context:
181 * Interrupts disabled, ccw device lock held
182 */
183int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
184 unsigned long intparm, __u8 lpm, __u8 key,
185 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 struct subchannel *sch;
188 int ret;
189
Sebastian Otte45efa92009-06-12 10:26:27 +0200190 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return -ENODEV;
192 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200193 if (!sch->schib.pmcw.ena)
194 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if (cdev->private->state == DEV_STATE_NOT_OPER)
196 return -ENODEV;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +0100197 if (cdev->private->state == DEV_STATE_VERIFY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /* Remember to fake irb when finished. */
199 if (!cdev->private->flags.fake_irb) {
200 cdev->private->flags.fake_irb = 1;
201 cdev->private->intparm = intparm;
202 return 0;
203 } else
204 /* There's already a fake I/O around. */
205 return -EBUSY;
206 }
207 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200208 ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
209 !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 cdev->private->flags.doverify)
211 return -EBUSY;
212 ret = cio_set_options (sch, flags);
213 if (ret)
214 return ret;
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200215 /* Adjust requested path mask to excluded varied off paths. */
216 if (lpm) {
217 lpm &= sch->opm;
218 if (lpm == 0)
219 return -EACCES;
220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 ret = cio_start_key (sch, cpa, lpm, key);
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200222 switch (ret) {
223 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 cdev->private->intparm = intparm;
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200225 break;
226 case -EACCES:
227 case -ENODEV:
228 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
229 break;
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 return ret;
232}
233
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200234/**
235 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
236 * @cdev: target ccw device
237 * @cpa: logical start address of channel program
238 * @intparm: user specific interruption parameter; will be presented back to
239 * @cdev's interrupt handler. Allows a device driver to associate
240 * the interrupt with a particular I/O request.
241 * @lpm: defines the channel path to be used for a specific I/O request. A
242 * value of 0 will make cio use the opm.
243 * @key: storage key to be used for the I/O
244 * @flags: additional flags; defines the action to be performed for I/O
245 * processing.
246 * @expires: timeout value in jiffies
247 *
248 * Start a S/390 channel program. When the interrupt arrives, the
249 * IRQ handler is called, either immediately, delayed (dev-end missing,
250 * or sense required) or never (no IRQ handler registered).
251 * This function notifies the device driver if the channel program has not
252 * completed during the time specified by @expires. If a timeout occurs, the
253 * channel program is terminated via xsch, hsch or csch, and the device's
254 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
255 * Returns:
256 * %0, if the operation was successful;
257 * -%EBUSY, if the device is busy, or status pending;
258 * -%EACCES, if no path specified in @lpm is operational;
259 * -%ENODEV, if the device is not operational.
260 * Context:
261 * Interrupts disabled, ccw device lock held
262 */
263int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
264 unsigned long intparm, __u8 lpm, __u8 key,
265 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 int ret;
268
269 if (!cdev)
270 return -ENODEV;
271 ccw_device_set_timeout(cdev, expires);
272 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
273 if (ret != 0)
274 ccw_device_set_timeout(cdev, 0);
275 return ret;
276}
277
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200278/**
279 * ccw_device_start() - start a s390 channel program
280 * @cdev: target ccw device
281 * @cpa: logical start address of channel program
282 * @intparm: user specific interruption parameter; will be presented back to
283 * @cdev's interrupt handler. Allows a device driver to associate
284 * the interrupt with a particular I/O request.
285 * @lpm: defines the channel path to be used for a specific I/O request. A
286 * value of 0 will make cio use the opm.
287 * @flags: additional flags; defines the action to be performed for I/O
288 * processing.
289 *
290 * Start a S/390 channel program. When the interrupt arrives, the
291 * IRQ handler is called, either immediately, delayed (dev-end missing,
292 * or sense required) or never (no IRQ handler registered).
293 * Returns:
294 * %0, if the operation was successful;
295 * -%EBUSY, if the device is busy, or status pending;
296 * -%EACCES, if no path specified in @lpm is operational;
297 * -%ENODEV, if the device is not operational.
298 * Context:
299 * Interrupts disabled, ccw device lock held
300 */
301int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
302 unsigned long intparm, __u8 lpm, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
304 return ccw_device_start_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700305 PAGE_DEFAULT_KEY, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200308/**
309 * ccw_device_start_timeout() - start a s390 channel program with timeout
310 * @cdev: target ccw device
311 * @cpa: logical start address of channel program
312 * @intparm: user specific interruption parameter; will be presented back to
313 * @cdev's interrupt handler. Allows a device driver to associate
314 * the interrupt with a particular I/O request.
315 * @lpm: defines the channel path to be used for a specific I/O request. A
316 * value of 0 will make cio use the opm.
317 * @flags: additional flags; defines the action to be performed for I/O
318 * processing.
319 * @expires: timeout value in jiffies
320 *
321 * Start a S/390 channel program. When the interrupt arrives, the
322 * IRQ handler is called, either immediately, delayed (dev-end missing,
323 * or sense required) or never (no IRQ handler registered).
324 * This function notifies the device driver if the channel program has not
325 * completed during the time specified by @expires. If a timeout occurs, the
326 * channel program is terminated via xsch, hsch or csch, and the device's
327 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
328 * Returns:
329 * %0, if the operation was successful;
330 * -%EBUSY, if the device is busy, or status pending;
331 * -%EACCES, if no path specified in @lpm is operational;
332 * -%ENODEV, if the device is not operational.
333 * Context:
334 * Interrupts disabled, ccw device lock held
335 */
336int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
337 unsigned long intparm, __u8 lpm,
338 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
340 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700341 PAGE_DEFAULT_KEY, flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 expires);
343}
344
345
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200346/**
347 * ccw_device_halt() - halt I/O request processing
348 * @cdev: target ccw device
349 * @intparm: interruption parameter; value is only used if no I/O is
350 * outstanding, otherwise the intparm associated with the I/O request
351 * is returned
352 *
353 * ccw_device_halt() calls hsch on @cdev's subchannel.
354 * Returns:
355 * %0 on success,
356 * -%ENODEV on device not operational,
357 * -%EINVAL on invalid device state,
358 * -%EBUSY on device busy or interrupt pending.
359 * Context:
360 * Interrupts disabled, ccw device lock held
361 */
362int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 struct subchannel *sch;
365 int ret;
366
Sebastian Otte45efa92009-06-12 10:26:27 +0200367 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +0200369 sch = to_subchannel(cdev->dev.parent);
370 if (!sch->schib.pmcw.ena)
371 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (cdev->private->state == DEV_STATE_NOT_OPER)
373 return -ENODEV;
374 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 cdev->private->state != DEV_STATE_W4SENSE)
376 return -EINVAL;
Sebastian Ott823d4942009-06-16 10:30:20 +0200377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 ret = cio_halt(sch);
379 if (ret == 0)
380 cdev->private->intparm = intparm;
381 return ret;
382}
383
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200384/**
385 * ccw_device_resume() - resume channel program execution
386 * @cdev: target ccw device
387 *
388 * ccw_device_resume() calls rsch on @cdev's subchannel.
389 * Returns:
390 * %0 on success,
391 * -%ENODEV on device not operational,
392 * -%EINVAL on invalid device state,
393 * -%EBUSY on device busy or interrupt pending.
394 * Context:
395 * Interrupts disabled, ccw device lock held
396 */
397int ccw_device_resume(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 struct subchannel *sch;
400
Sebastian Otte45efa92009-06-12 10:26:27 +0200401 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return -ENODEV;
403 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200404 if (!sch->schib.pmcw.ena)
405 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (cdev->private->state == DEV_STATE_NOT_OPER)
407 return -ENODEV;
408 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200409 !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return -EINVAL;
411 return cio_resume(sch);
412}
413
414/*
415 * Pass interrupt to device driver.
416 */
417int
418ccw_device_call_handler(struct ccw_device *cdev)
419{
420 struct subchannel *sch;
421 unsigned int stctl;
422 int ending_status;
423
424 sch = to_subchannel(cdev->dev.parent);
425
426 /*
427 * we allow for the device action handler if .
428 * - we received ending status
429 * - the action handler requested to see all interrupts
430 * - we received an intermediate status
431 * - fast notification was requested (primary status)
432 * - unsolicited interrupts
433 */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200434 stctl = scsw_stctl(&cdev->private->irb.scsw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
436 (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
437 (stctl == SCSW_STCTL_STATUS_PEND);
438 if (!ending_status &&
439 !cdev->private->options.repall &&
440 !(stctl & SCSW_STCTL_INTER_STATUS) &&
441 !(cdev->private->options.fast &&
442 (stctl & SCSW_STCTL_PRIM_STATUS)))
443 return 0;
444
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200445 /* Clear pending timers for device driver initiated I/O. */
446 if (ending_status)
447 ccw_device_set_timeout(cdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /*
449 * Now we are ready to call the device driver interrupt handler.
450 */
451 if (cdev->handler)
452 cdev->handler(cdev, cdev->private->intparm,
453 &cdev->private->irb);
454
455 /*
456 * Clear the old and now useless interrupt response block.
457 */
458 memset(&cdev->private->irb, 0, sizeof(struct irb));
459
460 return 1;
461}
462
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200463/**
464 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
465 * @cdev: ccw device to inspect
466 * @ct: command type to look for
467 *
468 * During SenseID, command information words (CIWs) describing special
469 * commands available to the device may have been stored in the extended
470 * sense data. This function searches for CIWs of a specified command
471 * type in the extended sense data.
472 * Returns:
473 * %NULL if no extended sense data has been stored or if no CIW of the
474 * specified command type could be found,
475 * else a pointer to the CIW of the specified command type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200477struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 int ciw_cnt;
480
481 if (cdev->private->flags.esid == 0)
482 return NULL;
483 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
484 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
485 return cdev->private->senseid.ciw + ciw_cnt;
486 return NULL;
487}
488
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200489/**
490 * ccw_device_get_path_mask() - get currently available paths
491 * @cdev: ccw device to be queried
492 * Returns:
493 * %0 if no subchannel for the device is available,
494 * else the mask of currently available paths for the ccw device's subchannel.
495 */
496__u8 ccw_device_get_path_mask(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 struct subchannel *sch;
499
Sebastian Otte45efa92009-06-12 10:26:27 +0200500 if (!cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return 0;
Sebastian Otte45efa92009-06-12 10:26:27 +0200502
503 sch = to_subchannel(cdev->dev.parent);
504 return sch->lpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507/*
508 * Try to break the lock on a boxed device.
509 */
510int
511ccw_device_stlck(struct ccw_device *cdev)
512{
513 void *buf, *buf2;
514 unsigned long flags;
515 struct subchannel *sch;
516 int ret;
517
518 if (!cdev)
519 return -ENODEV;
520
521 if (cdev->drv && !cdev->private->options.force)
522 return -EINVAL;
523
524 sch = to_subchannel(cdev->dev.parent);
525
526 CIO_TRACE_EVENT(2, "stl lock");
Kay Sievers2a0217d2008-10-10 21:33:09 +0200527 CIO_TRACE_EVENT(2, dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
530 if (!buf)
531 return -ENOMEM;
532 buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
533 if (!buf2) {
534 kfree(buf);
535 return -ENOMEM;
536 }
Cornelia Huck2ec22982006-12-08 15:54:26 +0100537 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckedf22092008-04-30 13:38:39 +0200538 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (ret)
540 goto out_unlock;
541 /*
542 * Setup ccw. We chain an unconditional reserve and a release so we
543 * only break the lock.
544 */
545 cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
546 cdev->private->iccws[0].cda = (__u32) __pa(buf);
547 cdev->private->iccws[0].count = 32;
548 cdev->private->iccws[0].flags = CCW_FLAG_CC;
549 cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
550 cdev->private->iccws[1].cda = (__u32) __pa(buf2);
551 cdev->private->iccws[1].count = 32;
552 cdev->private->iccws[1].flags = 0;
553 ret = cio_start(sch, cdev->private->iccws, 0);
554 if (ret) {
555 cio_disable_subchannel(sch); //FIXME: return code?
556 goto out_unlock;
557 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200558 cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100559 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200560 wait_event(cdev->private->wait_q,
561 cdev->private->irb.scsw.cmd.actl == 0);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100562 spin_lock_irqsave(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 cio_disable_subchannel(sch); //FIXME: return code?
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200564 if ((cdev->private->irb.scsw.cmd.dstat !=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200566 (cdev->private->irb.scsw.cmd.cstat != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 ret = -EIO;
568 /* Clear irb. */
569 memset(&cdev->private->irb, 0, sizeof(struct irb));
570out_unlock:
Jesper Juhl17fd6822005-11-07 01:01:30 -0800571 kfree(buf);
572 kfree(buf2);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100573 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return ret;
575}
576
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200577void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 struct subchannel *sch;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200580 struct chp_id chpid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200583 chp_id_init(&chpid);
584 chpid.id = sch->schib.pmcw.chpid[chp_no];
585 return chp_get_chp_desc(chpid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200588/**
589 * ccw_device_get_id - obtain a ccw device id
590 * @cdev: device to obtain the id for
591 * @dev_id: where to fill in the values
592 */
593void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
594{
595 *dev_id = cdev->private->dev_id;
596}
597EXPORT_SYMBOL(ccw_device_get_id);
598
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200599/**
600 * ccw_device_tm_start_key - perform start function
601 * @cdev: ccw device on which to perform the start function
602 * @tcw: transport-command word to be started
603 * @intparm: user defined parameter to be passed to the interrupt handler
604 * @lpm: mask of paths to use
605 * @key: storage key to use for storage access
606 *
607 * Start the tcw on the given ccw device. Return zero on success, non-zero
608 * otherwise.
609 */
610int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
611 unsigned long intparm, u8 lpm, u8 key)
612{
613 struct subchannel *sch;
614 int rc;
615
616 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +0200617 if (!sch->schib.pmcw.ena)
618 return -EINVAL;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200619 if (cdev->private->state != DEV_STATE_ONLINE)
620 return -EIO;
621 /* Adjust requested path mask to excluded varied off paths. */
622 if (lpm) {
623 lpm &= sch->opm;
624 if (lpm == 0)
625 return -EACCES;
626 }
627 rc = cio_tm_start_key(sch, tcw, lpm, key);
628 if (rc == 0)
629 cdev->private->intparm = intparm;
630 return rc;
631}
632EXPORT_SYMBOL(ccw_device_tm_start_key);
633
634/**
635 * ccw_device_tm_start_timeout_key - perform start function
636 * @cdev: ccw device on which to perform the start function
637 * @tcw: transport-command word to be started
638 * @intparm: user defined parameter to be passed to the interrupt handler
639 * @lpm: mask of paths to use
640 * @key: storage key to use for storage access
641 * @expires: time span in jiffies after which to abort request
642 *
643 * Start the tcw on the given ccw device. Return zero on success, non-zero
644 * otherwise.
645 */
646int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
647 unsigned long intparm, u8 lpm, u8 key,
648 int expires)
649{
650 int ret;
651
652 ccw_device_set_timeout(cdev, expires);
653 ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
654 if (ret != 0)
655 ccw_device_set_timeout(cdev, 0);
656 return ret;
657}
658EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
659
660/**
661 * ccw_device_tm_start - perform start function
662 * @cdev: ccw device on which to perform the start function
663 * @tcw: transport-command word to be started
664 * @intparm: user defined parameter to be passed to the interrupt handler
665 * @lpm: mask of paths to use
666 *
667 * Start the tcw on the given ccw device. Return zero on success, non-zero
668 * otherwise.
669 */
670int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
671 unsigned long intparm, u8 lpm)
672{
673 return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
674 PAGE_DEFAULT_KEY);
675}
676EXPORT_SYMBOL(ccw_device_tm_start);
677
678/**
679 * ccw_device_tm_start_timeout - perform start function
680 * @cdev: ccw device on which to perform the start function
681 * @tcw: transport-command word to be started
682 * @intparm: user defined parameter to be passed to the interrupt handler
683 * @lpm: mask of paths to use
684 * @expires: time span in jiffies after which to abort request
685 *
686 * Start the tcw on the given ccw device. Return zero on success, non-zero
687 * otherwise.
688 */
689int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
690 unsigned long intparm, u8 lpm, int expires)
691{
692 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
693 PAGE_DEFAULT_KEY, expires);
694}
695EXPORT_SYMBOL(ccw_device_tm_start_timeout);
696
697/**
698 * ccw_device_tm_intrg - perform interrogate function
699 * @cdev: ccw device on which to perform the interrogate function
700 *
701 * Perform an interrogate function on the given ccw device. Return zero on
702 * success, non-zero otherwise.
703 */
704int ccw_device_tm_intrg(struct ccw_device *cdev)
705{
706 struct subchannel *sch = to_subchannel(cdev->dev.parent);
707
Sebastian Ott823d4942009-06-16 10:30:20 +0200708 if (!sch->schib.pmcw.ena)
709 return -EINVAL;
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200710 if (cdev->private->state != DEV_STATE_ONLINE)
711 return -EIO;
712 if (!scsw_is_tm(&sch->schib.scsw) ||
Peter Oberparleiter7a968f02009-03-26 15:24:18 +0100713 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200714 return -EINVAL;
715 return cio_tm_intrg(sch);
716}
717EXPORT_SYMBOL(ccw_device_tm_intrg);
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719// FIXME: these have to go:
720
721int
722_ccw_device_get_subchannel_number(struct ccw_device *cdev)
723{
Cornelia Huck78964262006-10-11 15:31:38 +0200724 return cdev->private->schid.sch_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725}
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728MODULE_LICENSE("GPL");
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100729EXPORT_SYMBOL(ccw_device_set_options_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730EXPORT_SYMBOL(ccw_device_set_options);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100731EXPORT_SYMBOL(ccw_device_clear_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732EXPORT_SYMBOL(ccw_device_clear);
733EXPORT_SYMBOL(ccw_device_halt);
734EXPORT_SYMBOL(ccw_device_resume);
735EXPORT_SYMBOL(ccw_device_start_timeout);
736EXPORT_SYMBOL(ccw_device_start);
737EXPORT_SYMBOL(ccw_device_start_timeout_key);
738EXPORT_SYMBOL(ccw_device_start_key);
739EXPORT_SYMBOL(ccw_device_get_ciw);
740EXPORT_SYMBOL(ccw_device_get_path_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);