blob: bf0a24af39a0542be842f5705cc49ec58da63b2f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/device_ops.c
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
5 * IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08007 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/errno.h>
12#include <linux/slab.h>
13#include <linux/list.h>
14#include <linux/device.h>
15#include <linux/delay.h>
16
17#include <asm/ccwdev.h>
18#include <asm/idals.h>
Peter Oberparleitere5854a52007-04-27 16:01:31 +020019#include <asm/chpid.h>
Peter Oberparleiter83262d62008-07-14 09:58:51 +020020#include <asm/fcx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include "cio.h"
23#include "cio_debug.h"
24#include "css.h"
25#include "chsc.h"
26#include "device.h"
Peter Oberparleitere6b6e102007-04-27 16:01:28 +020027#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020029/**
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
33 *
34 * All flags specified in @flags are set, all flags not specified in @flags
35 * are cleared.
36 * Returns:
37 * %0 on success, -%EINVAL on an invalid flag combination.
38 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010039int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 /*
42 * The flag usage is mutal exclusive ...
43 */
44 if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
45 (flags & CCWDEV_REPORT_ALL))
46 return -EINVAL;
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 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;
79 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;
95}
96
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020097/**
98 * ccw_device_clear() - terminate I/O request processing
99 * @cdev: target ccw device
100 * @intparm: interruption parameter; value is only used if no I/O is
101 * outstanding, otherwise the intparm associated with the I/O request
102 * is returned
103 *
104 * ccw_device_clear() calls csch on @cdev's subchannel.
105 * Returns:
106 * %0 on success,
107 * -%ENODEV on device not operational,
108 * -%EINVAL on invalid device state.
109 * Context:
110 * Interrupts disabled, ccw device lock held
111 */
112int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 struct subchannel *sch;
115 int ret;
116
Sebastian Otte45efa92009-06-12 10:26:27 +0200117 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -ENODEV;
119 if (cdev->private->state == DEV_STATE_NOT_OPER)
120 return -ENODEV;
121 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 cdev->private->state != DEV_STATE_W4SENSE)
123 return -EINVAL;
124 sch = to_subchannel(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 ret = cio_clear(sch);
126 if (ret == 0)
127 cdev->private->intparm = intparm;
128 return ret;
129}
130
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200131/**
132 * ccw_device_start_key() - start a s390 channel program with key
133 * @cdev: target ccw device
134 * @cpa: logical start address of channel program
135 * @intparm: user specific interruption parameter; will be presented back to
136 * @cdev's interrupt handler. Allows a device driver to associate
137 * the interrupt with a particular I/O request.
138 * @lpm: defines the channel path to be used for a specific I/O request. A
139 * value of 0 will make cio use the opm.
140 * @key: storage key to be used for the I/O
141 * @flags: additional flags; defines the action to be performed for I/O
142 * processing.
143 *
144 * Start a S/390 channel program. When the interrupt arrives, the
145 * IRQ handler is called, either immediately, delayed (dev-end missing,
146 * or sense required) or never (no IRQ handler registered).
147 * Returns:
148 * %0, if the operation was successful;
149 * -%EBUSY, if the device is busy, or status pending;
150 * -%EACCES, if no path specified in @lpm is operational;
151 * -%ENODEV, if the device is not operational.
152 * Context:
153 * Interrupts disabled, ccw device lock held
154 */
155int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
156 unsigned long intparm, __u8 lpm, __u8 key,
157 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 struct subchannel *sch;
160 int ret;
161
Sebastian Otte45efa92009-06-12 10:26:27 +0200162 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return -ENODEV;
164 sch = to_subchannel(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 if (cdev->private->state == DEV_STATE_NOT_OPER)
166 return -ENODEV;
Cornelia Huckb4f7b1e2006-06-29 15:03:35 +0200167 if (cdev->private->state == DEV_STATE_VERIFY ||
168 cdev->private->state == DEV_STATE_CLEAR_VERIFY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* Remember to fake irb when finished. */
170 if (!cdev->private->flags.fake_irb) {
171 cdev->private->flags.fake_irb = 1;
172 cdev->private->intparm = intparm;
173 return 0;
174 } else
175 /* There's already a fake I/O around. */
176 return -EBUSY;
177 }
178 if (cdev->private->state != DEV_STATE_ONLINE ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200179 ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
180 !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 cdev->private->flags.doverify)
182 return -EBUSY;
183 ret = cio_set_options (sch, flags);
184 if (ret)
185 return ret;
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200186 /* Adjust requested path mask to excluded varied off paths. */
187 if (lpm) {
188 lpm &= sch->opm;
189 if (lpm == 0)
190 return -EACCES;
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 ret = cio_start_key (sch, cpa, lpm, key);
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200193 switch (ret) {
194 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 cdev->private->intparm = intparm;
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200196 break;
197 case -EACCES:
198 case -ENODEV:
199 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
200 break;
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return ret;
203}
204
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200205/**
206 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
207 * @cdev: target ccw device
208 * @cpa: logical start address of channel program
209 * @intparm: user specific interruption parameter; will be presented back to
210 * @cdev's interrupt handler. Allows a device driver to associate
211 * the interrupt with a particular I/O request.
212 * @lpm: defines the channel path to be used for a specific I/O request. A
213 * value of 0 will make cio use the opm.
214 * @key: storage key to be used for the I/O
215 * @flags: additional flags; defines the action to be performed for I/O
216 * processing.
217 * @expires: timeout value in jiffies
218 *
219 * Start a S/390 channel program. When the interrupt arrives, the
220 * IRQ handler is called, either immediately, delayed (dev-end missing,
221 * or sense required) or never (no IRQ handler registered).
222 * This function notifies the device driver if the channel program has not
223 * completed during the time specified by @expires. If a timeout occurs, the
224 * channel program is terminated via xsch, hsch or csch, and the device's
225 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
226 * Returns:
227 * %0, if the operation was successful;
228 * -%EBUSY, if the device is busy, or status pending;
229 * -%EACCES, if no path specified in @lpm is operational;
230 * -%ENODEV, if the device is not operational.
231 * Context:
232 * Interrupts disabled, ccw device lock held
233 */
234int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
235 unsigned long intparm, __u8 lpm, __u8 key,
236 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 int ret;
239
240 if (!cdev)
241 return -ENODEV;
242 ccw_device_set_timeout(cdev, expires);
243 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
244 if (ret != 0)
245 ccw_device_set_timeout(cdev, 0);
246 return ret;
247}
248
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200249/**
250 * ccw_device_start() - start a s390 channel program
251 * @cdev: target ccw device
252 * @cpa: logical start address of channel program
253 * @intparm: user specific interruption parameter; will be presented back to
254 * @cdev's interrupt handler. Allows a device driver to associate
255 * the interrupt with a particular I/O request.
256 * @lpm: defines the channel path to be used for a specific I/O request. A
257 * value of 0 will make cio use the opm.
258 * @flags: additional flags; defines the action to be performed for I/O
259 * processing.
260 *
261 * Start a S/390 channel program. When the interrupt arrives, the
262 * IRQ handler is called, either immediately, delayed (dev-end missing,
263 * or sense required) or never (no IRQ handler registered).
264 * Returns:
265 * %0, if the operation was successful;
266 * -%EBUSY, if the device is busy, or status pending;
267 * -%EACCES, if no path specified in @lpm is operational;
268 * -%ENODEV, if the device is not operational.
269 * Context:
270 * Interrupts disabled, ccw device lock held
271 */
272int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
273 unsigned long intparm, __u8 lpm, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 return ccw_device_start_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700276 PAGE_DEFAULT_KEY, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200279/**
280 * ccw_device_start_timeout() - start a s390 channel program with timeout
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 * @expires: timeout value in jiffies
291 *
292 * Start a S/390 channel program. When the interrupt arrives, the
293 * IRQ handler is called, either immediately, delayed (dev-end missing,
294 * or sense required) or never (no IRQ handler registered).
295 * This function notifies the device driver if the channel program has not
296 * completed during the time specified by @expires. If a timeout occurs, the
297 * channel program is terminated via xsch, hsch or csch, and the device's
298 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
299 * Returns:
300 * %0, if the operation was successful;
301 * -%EBUSY, if the device is busy, or status pending;
302 * -%EACCES, if no path specified in @lpm is operational;
303 * -%ENODEV, if the device is not operational.
304 * Context:
305 * Interrupts disabled, ccw device lock held
306 */
307int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
308 unsigned long intparm, __u8 lpm,
309 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
311 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700312 PAGE_DEFAULT_KEY, flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 expires);
314}
315
316
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200317/**
318 * ccw_device_halt() - halt I/O request processing
319 * @cdev: target ccw device
320 * @intparm: interruption parameter; value is only used if no I/O is
321 * outstanding, otherwise the intparm associated with the I/O request
322 * is returned
323 *
324 * ccw_device_halt() calls hsch on @cdev's subchannel.
325 * Returns:
326 * %0 on success,
327 * -%ENODEV on device not operational,
328 * -%EINVAL on invalid device state,
329 * -%EBUSY on device busy or interrupt pending.
330 * Context:
331 * Interrupts disabled, ccw device lock held
332 */
333int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 struct subchannel *sch;
336 int ret;
337
Sebastian Otte45efa92009-06-12 10:26:27 +0200338 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 return -ENODEV;
340 if (cdev->private->state == DEV_STATE_NOT_OPER)
341 return -ENODEV;
342 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 cdev->private->state != DEV_STATE_W4SENSE)
344 return -EINVAL;
345 sch = to_subchannel(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ret = cio_halt(sch);
347 if (ret == 0)
348 cdev->private->intparm = intparm;
349 return ret;
350}
351
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200352/**
353 * ccw_device_resume() - resume channel program execution
354 * @cdev: target ccw device
355 *
356 * ccw_device_resume() calls rsch 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_resume(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 struct subchannel *sch;
368
Sebastian Otte45efa92009-06-12 10:26:27 +0200369 if (!cdev || !cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 return -ENODEV;
371 sch = to_subchannel(cdev->dev.parent);
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 ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200375 !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return -EINVAL;
377 return cio_resume(sch);
378}
379
380/*
381 * Pass interrupt to device driver.
382 */
383int
384ccw_device_call_handler(struct ccw_device *cdev)
385{
386 struct subchannel *sch;
387 unsigned int stctl;
388 int ending_status;
389
390 sch = to_subchannel(cdev->dev.parent);
391
392 /*
393 * we allow for the device action handler if .
394 * - we received ending status
395 * - the action handler requested to see all interrupts
396 * - we received an intermediate status
397 * - fast notification was requested (primary status)
398 * - unsolicited interrupts
399 */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200400 stctl = scsw_stctl(&cdev->private->irb.scsw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
402 (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
403 (stctl == SCSW_STCTL_STATUS_PEND);
404 if (!ending_status &&
405 !cdev->private->options.repall &&
406 !(stctl & SCSW_STCTL_INTER_STATUS) &&
407 !(cdev->private->options.fast &&
408 (stctl & SCSW_STCTL_PRIM_STATUS)))
409 return 0;
410
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200411 /* Clear pending timers for device driver initiated I/O. */
412 if (ending_status)
413 ccw_device_set_timeout(cdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 /*
415 * Now we are ready to call the device driver interrupt handler.
416 */
417 if (cdev->handler)
418 cdev->handler(cdev, cdev->private->intparm,
419 &cdev->private->irb);
420
421 /*
422 * Clear the old and now useless interrupt response block.
423 */
424 memset(&cdev->private->irb, 0, sizeof(struct irb));
425
426 return 1;
427}
428
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200429/**
430 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
431 * @cdev: ccw device to inspect
432 * @ct: command type to look for
433 *
434 * During SenseID, command information words (CIWs) describing special
435 * commands available to the device may have been stored in the extended
436 * sense data. This function searches for CIWs of a specified command
437 * type in the extended sense data.
438 * Returns:
439 * %NULL if no extended sense data has been stored or if no CIW of the
440 * specified command type could be found,
441 * else a pointer to the CIW of the specified command type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200443struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 int ciw_cnt;
446
447 if (cdev->private->flags.esid == 0)
448 return NULL;
449 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
450 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
451 return cdev->private->senseid.ciw + ciw_cnt;
452 return NULL;
453}
454
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200455/**
456 * ccw_device_get_path_mask() - get currently available paths
457 * @cdev: ccw device to be queried
458 * Returns:
459 * %0 if no subchannel for the device is available,
460 * else the mask of currently available paths for the ccw device's subchannel.
461 */
462__u8 ccw_device_get_path_mask(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
464 struct subchannel *sch;
465
Sebastian Otte45efa92009-06-12 10:26:27 +0200466 if (!cdev->dev.parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return 0;
Sebastian Otte45efa92009-06-12 10:26:27 +0200468
469 sch = to_subchannel(cdev->dev.parent);
470 return sch->lpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/*
474 * Try to break the lock on a boxed device.
475 */
476int
477ccw_device_stlck(struct ccw_device *cdev)
478{
479 void *buf, *buf2;
480 unsigned long flags;
481 struct subchannel *sch;
482 int ret;
483
484 if (!cdev)
485 return -ENODEV;
486
487 if (cdev->drv && !cdev->private->options.force)
488 return -EINVAL;
489
490 sch = to_subchannel(cdev->dev.parent);
491
492 CIO_TRACE_EVENT(2, "stl lock");
Kay Sievers2a0217d2008-10-10 21:33:09 +0200493 CIO_TRACE_EVENT(2, dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
496 if (!buf)
497 return -ENOMEM;
498 buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
499 if (!buf2) {
500 kfree(buf);
501 return -ENOMEM;
502 }
Cornelia Huck2ec22982006-12-08 15:54:26 +0100503 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckedf22092008-04-30 13:38:39 +0200504 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (ret)
506 goto out_unlock;
507 /*
508 * Setup ccw. We chain an unconditional reserve and a release so we
509 * only break the lock.
510 */
511 cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
512 cdev->private->iccws[0].cda = (__u32) __pa(buf);
513 cdev->private->iccws[0].count = 32;
514 cdev->private->iccws[0].flags = CCW_FLAG_CC;
515 cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
516 cdev->private->iccws[1].cda = (__u32) __pa(buf2);
517 cdev->private->iccws[1].count = 32;
518 cdev->private->iccws[1].flags = 0;
519 ret = cio_start(sch, cdev->private->iccws, 0);
520 if (ret) {
521 cio_disable_subchannel(sch); //FIXME: return code?
522 goto out_unlock;
523 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200524 cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100525 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200526 wait_event(cdev->private->wait_q,
527 cdev->private->irb.scsw.cmd.actl == 0);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100528 spin_lock_irqsave(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 cio_disable_subchannel(sch); //FIXME: return code?
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200530 if ((cdev->private->irb.scsw.cmd.dstat !=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200532 (cdev->private->irb.scsw.cmd.cstat != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 ret = -EIO;
534 /* Clear irb. */
535 memset(&cdev->private->irb, 0, sizeof(struct irb));
536out_unlock:
Jesper Juhl17fd6822005-11-07 01:01:30 -0800537 kfree(buf);
538 kfree(buf2);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100539 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 return ret;
541}
542
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200543void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 struct subchannel *sch;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200546 struct chp_id chpid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200549 chp_id_init(&chpid);
550 chpid.id = sch->schib.pmcw.chpid[chp_no];
551 return chp_get_chp_desc(chpid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200554/**
555 * ccw_device_get_id - obtain a ccw device id
556 * @cdev: device to obtain the id for
557 * @dev_id: where to fill in the values
558 */
559void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
560{
561 *dev_id = cdev->private->dev_id;
562}
563EXPORT_SYMBOL(ccw_device_get_id);
564
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200565/**
566 * ccw_device_tm_start_key - perform start function
567 * @cdev: ccw device on which to perform the start function
568 * @tcw: transport-command word to be started
569 * @intparm: user defined parameter to be passed to the interrupt handler
570 * @lpm: mask of paths to use
571 * @key: storage key to use for storage access
572 *
573 * Start the tcw on the given ccw device. Return zero on success, non-zero
574 * otherwise.
575 */
576int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
577 unsigned long intparm, u8 lpm, u8 key)
578{
579 struct subchannel *sch;
580 int rc;
581
582 sch = to_subchannel(cdev->dev.parent);
583 if (cdev->private->state != DEV_STATE_ONLINE)
584 return -EIO;
585 /* Adjust requested path mask to excluded varied off paths. */
586 if (lpm) {
587 lpm &= sch->opm;
588 if (lpm == 0)
589 return -EACCES;
590 }
591 rc = cio_tm_start_key(sch, tcw, lpm, key);
592 if (rc == 0)
593 cdev->private->intparm = intparm;
594 return rc;
595}
596EXPORT_SYMBOL(ccw_device_tm_start_key);
597
598/**
599 * ccw_device_tm_start_timeout_key - perform start function
600 * @cdev: ccw device on which to perform the start function
601 * @tcw: transport-command word to be started
602 * @intparm: user defined parameter to be passed to the interrupt handler
603 * @lpm: mask of paths to use
604 * @key: storage key to use for storage access
605 * @expires: time span in jiffies after which to abort request
606 *
607 * Start the tcw on the given ccw device. Return zero on success, non-zero
608 * otherwise.
609 */
610int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
611 unsigned long intparm, u8 lpm, u8 key,
612 int expires)
613{
614 int ret;
615
616 ccw_device_set_timeout(cdev, expires);
617 ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
618 if (ret != 0)
619 ccw_device_set_timeout(cdev, 0);
620 return ret;
621}
622EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
623
624/**
625 * ccw_device_tm_start - perform start function
626 * @cdev: ccw device on which to perform the start function
627 * @tcw: transport-command word to be started
628 * @intparm: user defined parameter to be passed to the interrupt handler
629 * @lpm: mask of paths to use
630 *
631 * Start the tcw on the given ccw device. Return zero on success, non-zero
632 * otherwise.
633 */
634int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
635 unsigned long intparm, u8 lpm)
636{
637 return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
638 PAGE_DEFAULT_KEY);
639}
640EXPORT_SYMBOL(ccw_device_tm_start);
641
642/**
643 * ccw_device_tm_start_timeout - perform start function
644 * @cdev: ccw device on which to perform the start function
645 * @tcw: transport-command word to be started
646 * @intparm: user defined parameter to be passed to the interrupt handler
647 * @lpm: mask of paths to use
648 * @expires: time span in jiffies after which to abort request
649 *
650 * Start the tcw on the given ccw device. Return zero on success, non-zero
651 * otherwise.
652 */
653int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
654 unsigned long intparm, u8 lpm, int expires)
655{
656 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
657 PAGE_DEFAULT_KEY, expires);
658}
659EXPORT_SYMBOL(ccw_device_tm_start_timeout);
660
661/**
662 * ccw_device_tm_intrg - perform interrogate function
663 * @cdev: ccw device on which to perform the interrogate function
664 *
665 * Perform an interrogate function on the given ccw device. Return zero on
666 * success, non-zero otherwise.
667 */
668int ccw_device_tm_intrg(struct ccw_device *cdev)
669{
670 struct subchannel *sch = to_subchannel(cdev->dev.parent);
671
672 if (cdev->private->state != DEV_STATE_ONLINE)
673 return -EIO;
674 if (!scsw_is_tm(&sch->schib.scsw) ||
Peter Oberparleiter7a968f02009-03-26 15:24:18 +0100675 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200676 return -EINVAL;
677 return cio_tm_intrg(sch);
678}
679EXPORT_SYMBOL(ccw_device_tm_intrg);
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681// FIXME: these have to go:
682
683int
684_ccw_device_get_subchannel_number(struct ccw_device *cdev)
685{
Cornelia Huck78964262006-10-11 15:31:38 +0200686 return cdev->private->schid.sch_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690MODULE_LICENSE("GPL");
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100691EXPORT_SYMBOL(ccw_device_set_options_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692EXPORT_SYMBOL(ccw_device_set_options);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100693EXPORT_SYMBOL(ccw_device_clear_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694EXPORT_SYMBOL(ccw_device_clear);
695EXPORT_SYMBOL(ccw_device_halt);
696EXPORT_SYMBOL(ccw_device_resume);
697EXPORT_SYMBOL(ccw_device_start_timeout);
698EXPORT_SYMBOL(ccw_device_start);
699EXPORT_SYMBOL(ccw_device_start_timeout_key);
700EXPORT_SYMBOL(ccw_device_start_key);
701EXPORT_SYMBOL(ccw_device_get_ciw);
702EXPORT_SYMBOL(ccw_device_get_path_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);