blob: f308ad55a6d5bed173b2fc5ee71197069bd764cc [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>
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;
50 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;
78 return 0;
79}
80
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020081/**
82 * ccw_device_clear_options() - clear some options
83 * @cdev: device for which the options are to be cleared
84 * @flags: options to be cleared
85 *
86 * All flags specified in @flags are cleared, the remainder is left untouched.
87 */
Cornelia Huck4dd3cc52007-02-12 15:47:18 +010088void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
89{
90 cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
91 cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
92 cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
93 cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
94}
95
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020096/**
97 * ccw_device_clear() - terminate I/O request processing
98 * @cdev: target ccw device
99 * @intparm: interruption parameter; value is only used if no I/O is
100 * outstanding, otherwise the intparm associated with the I/O request
101 * is returned
102 *
103 * ccw_device_clear() calls csch on @cdev's subchannel.
104 * Returns:
105 * %0 on success,
106 * -%ENODEV on device not operational,
107 * -%EINVAL on invalid device state.
108 * Context:
109 * Interrupts disabled, ccw device lock held
110 */
111int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 struct subchannel *sch;
114 int ret;
115
116 if (!cdev)
117 return -ENODEV;
118 if (cdev->private->state == DEV_STATE_NOT_OPER)
119 return -ENODEV;
120 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 cdev->private->state != DEV_STATE_W4SENSE)
122 return -EINVAL;
123 sch = to_subchannel(cdev->dev.parent);
124 if (!sch)
125 return -ENODEV;
126 ret = cio_clear(sch);
127 if (ret == 0)
128 cdev->private->intparm = intparm;
129 return ret;
130}
131
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200132/**
133 * ccw_device_start_key() - start a s390 channel program with key
134 * @cdev: target ccw device
135 * @cpa: logical start address of channel program
136 * @intparm: user specific interruption parameter; will be presented back to
137 * @cdev's interrupt handler. Allows a device driver to associate
138 * the interrupt with a particular I/O request.
139 * @lpm: defines the channel path to be used for a specific I/O request. A
140 * value of 0 will make cio use the opm.
141 * @key: storage key to be used for the I/O
142 * @flags: additional flags; defines the action to be performed for I/O
143 * processing.
144 *
145 * Start a S/390 channel program. When the interrupt arrives, the
146 * IRQ handler is called, either immediately, delayed (dev-end missing,
147 * or sense required) or never (no IRQ handler registered).
148 * Returns:
149 * %0, if the operation was successful;
150 * -%EBUSY, if the device is busy, or status pending;
151 * -%EACCES, if no path specified in @lpm is operational;
152 * -%ENODEV, if the device is not operational.
153 * Context:
154 * Interrupts disabled, ccw device lock held
155 */
156int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
157 unsigned long intparm, __u8 lpm, __u8 key,
158 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 struct subchannel *sch;
161 int ret;
162
163 if (!cdev)
164 return -ENODEV;
165 sch = to_subchannel(cdev->dev.parent);
166 if (!sch)
167 return -ENODEV;
168 if (cdev->private->state == DEV_STATE_NOT_OPER)
169 return -ENODEV;
Cornelia Huckb4f7b1e2006-06-29 15:03:35 +0200170 if (cdev->private->state == DEV_STATE_VERIFY ||
171 cdev->private->state == DEV_STATE_CLEAR_VERIFY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* Remember to fake irb when finished. */
173 if (!cdev->private->flags.fake_irb) {
174 cdev->private->flags.fake_irb = 1;
175 cdev->private->intparm = intparm;
176 return 0;
177 } else
178 /* There's already a fake I/O around. */
179 return -EBUSY;
180 }
181 if (cdev->private->state != DEV_STATE_ONLINE ||
182 ((sch->schib.scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
183 !(sch->schib.scsw.stctl & SCSW_STCTL_SEC_STATUS)) ||
184 cdev->private->flags.doverify)
185 return -EBUSY;
186 ret = cio_set_options (sch, flags);
187 if (ret)
188 return ret;
Peter Oberparleitere0e32c82006-09-20 15:59:57 +0200189 /* Adjust requested path mask to excluded varied off paths. */
190 if (lpm) {
191 lpm &= sch->opm;
192 if (lpm == 0)
193 return -EACCES;
194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ret = cio_start_key (sch, cpa, lpm, key);
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200196 switch (ret) {
197 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 cdev->private->intparm = intparm;
Cornelia Huckfe6173d2008-04-17 07:46:00 +0200199 break;
200 case -EACCES:
201 case -ENODEV:
202 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
203 break;
204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return ret;
206}
207
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200208/**
209 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
210 * @cdev: target ccw device
211 * @cpa: logical start address of channel program
212 * @intparm: user specific interruption parameter; will be presented back to
213 * @cdev's interrupt handler. Allows a device driver to associate
214 * the interrupt with a particular I/O request.
215 * @lpm: defines the channel path to be used for a specific I/O request. A
216 * value of 0 will make cio use the opm.
217 * @key: storage key to be used for the I/O
218 * @flags: additional flags; defines the action to be performed for I/O
219 * processing.
220 * @expires: timeout value in jiffies
221 *
222 * Start a S/390 channel program. When the interrupt arrives, the
223 * IRQ handler is called, either immediately, delayed (dev-end missing,
224 * or sense required) or never (no IRQ handler registered).
225 * This function notifies the device driver if the channel program has not
226 * completed during the time specified by @expires. If a timeout occurs, the
227 * channel program is terminated via xsch, hsch or csch, and the device's
228 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
229 * Returns:
230 * %0, if the operation was successful;
231 * -%EBUSY, if the device is busy, or status pending;
232 * -%EACCES, if no path specified in @lpm is operational;
233 * -%ENODEV, if the device is not operational.
234 * Context:
235 * Interrupts disabled, ccw device lock held
236 */
237int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
238 unsigned long intparm, __u8 lpm, __u8 key,
239 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 int ret;
242
243 if (!cdev)
244 return -ENODEV;
245 ccw_device_set_timeout(cdev, expires);
246 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
247 if (ret != 0)
248 ccw_device_set_timeout(cdev, 0);
249 return ret;
250}
251
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200252/**
253 * ccw_device_start() - start a s390 channel program
254 * @cdev: target ccw device
255 * @cpa: logical start address of channel program
256 * @intparm: user specific interruption parameter; will be presented back to
257 * @cdev's interrupt handler. Allows a device driver to associate
258 * the interrupt with a particular I/O request.
259 * @lpm: defines the channel path to be used for a specific I/O request. A
260 * value of 0 will make cio use the opm.
261 * @flags: additional flags; defines the action to be performed for I/O
262 * processing.
263 *
264 * Start a S/390 channel program. When the interrupt arrives, the
265 * IRQ handler is called, either immediately, delayed (dev-end missing,
266 * or sense required) or never (no IRQ handler registered).
267 * Returns:
268 * %0, if the operation was successful;
269 * -%EBUSY, if the device is busy, or status pending;
270 * -%EACCES, if no path specified in @lpm is operational;
271 * -%ENODEV, if the device is not operational.
272 * Context:
273 * Interrupts disabled, ccw device lock held
274 */
275int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
276 unsigned long intparm, __u8 lpm, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 return ccw_device_start_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700279 PAGE_DEFAULT_KEY, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200282/**
283 * ccw_device_start_timeout() - start a s390 channel program with timeout
284 * @cdev: target ccw device
285 * @cpa: logical start address of channel program
286 * @intparm: user specific interruption parameter; will be presented back to
287 * @cdev's interrupt handler. Allows a device driver to associate
288 * the interrupt with a particular I/O request.
289 * @lpm: defines the channel path to be used for a specific I/O request. A
290 * value of 0 will make cio use the opm.
291 * @flags: additional flags; defines the action to be performed for I/O
292 * processing.
293 * @expires: timeout value in jiffies
294 *
295 * Start a S/390 channel program. When the interrupt arrives, the
296 * IRQ handler is called, either immediately, delayed (dev-end missing,
297 * or sense required) or never (no IRQ handler registered).
298 * This function notifies the device driver if the channel program has not
299 * completed during the time specified by @expires. If a timeout occurs, the
300 * channel program is terminated via xsch, hsch or csch, and the device's
301 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
302 * Returns:
303 * %0, if the operation was successful;
304 * -%EBUSY, if the device is busy, or status pending;
305 * -%EACCES, if no path specified in @lpm is operational;
306 * -%ENODEV, if the device is not operational.
307 * Context:
308 * Interrupts disabled, ccw device lock held
309 */
310int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
311 unsigned long intparm, __u8 lpm,
312 unsigned long flags, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
314 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700315 PAGE_DEFAULT_KEY, flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 expires);
317}
318
319
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200320/**
321 * ccw_device_halt() - halt I/O request processing
322 * @cdev: target ccw device
323 * @intparm: interruption parameter; value is only used if no I/O is
324 * outstanding, otherwise the intparm associated with the I/O request
325 * is returned
326 *
327 * ccw_device_halt() calls hsch on @cdev's subchannel.
328 * Returns:
329 * %0 on success,
330 * -%ENODEV on device not operational,
331 * -%EINVAL on invalid device state,
332 * -%EBUSY on device busy or interrupt pending.
333 * Context:
334 * Interrupts disabled, ccw device lock held
335 */
336int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 struct subchannel *sch;
339 int ret;
340
341 if (!cdev)
342 return -ENODEV;
343 if (cdev->private->state == DEV_STATE_NOT_OPER)
344 return -ENODEV;
345 if (cdev->private->state != DEV_STATE_ONLINE &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 cdev->private->state != DEV_STATE_W4SENSE)
347 return -EINVAL;
348 sch = to_subchannel(cdev->dev.parent);
349 if (!sch)
350 return -ENODEV;
351 ret = cio_halt(sch);
352 if (ret == 0)
353 cdev->private->intparm = intparm;
354 return ret;
355}
356
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200357/**
358 * ccw_device_resume() - resume channel program execution
359 * @cdev: target ccw device
360 *
361 * ccw_device_resume() calls rsch on @cdev's subchannel.
362 * Returns:
363 * %0 on success,
364 * -%ENODEV on device not operational,
365 * -%EINVAL on invalid device state,
366 * -%EBUSY on device busy or interrupt pending.
367 * Context:
368 * Interrupts disabled, ccw device lock held
369 */
370int ccw_device_resume(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 struct subchannel *sch;
373
374 if (!cdev)
375 return -ENODEV;
376 sch = to_subchannel(cdev->dev.parent);
377 if (!sch)
378 return -ENODEV;
379 if (cdev->private->state == DEV_STATE_NOT_OPER)
380 return -ENODEV;
381 if (cdev->private->state != DEV_STATE_ONLINE ||
382 !(sch->schib.scsw.actl & SCSW_ACTL_SUSPENDED))
383 return -EINVAL;
384 return cio_resume(sch);
385}
386
387/*
388 * Pass interrupt to device driver.
389 */
390int
391ccw_device_call_handler(struct ccw_device *cdev)
392{
393 struct subchannel *sch;
394 unsigned int stctl;
395 int ending_status;
396
397 sch = to_subchannel(cdev->dev.parent);
398
399 /*
400 * we allow for the device action handler if .
401 * - we received ending status
402 * - the action handler requested to see all interrupts
403 * - we received an intermediate status
404 * - fast notification was requested (primary status)
405 * - unsolicited interrupts
406 */
407 stctl = cdev->private->irb.scsw.stctl;
408 ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
409 (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
410 (stctl == SCSW_STCTL_STATUS_PEND);
411 if (!ending_status &&
412 !cdev->private->options.repall &&
413 !(stctl & SCSW_STCTL_INTER_STATUS) &&
414 !(cdev->private->options.fast &&
415 (stctl & SCSW_STCTL_PRIM_STATUS)))
416 return 0;
417
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200418 /* Clear pending timers for device driver initiated I/O. */
419 if (ending_status)
420 ccw_device_set_timeout(cdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
422 * Now we are ready to call the device driver interrupt handler.
423 */
424 if (cdev->handler)
425 cdev->handler(cdev, cdev->private->intparm,
426 &cdev->private->irb);
427
428 /*
429 * Clear the old and now useless interrupt response block.
430 */
431 memset(&cdev->private->irb, 0, sizeof(struct irb));
432
433 return 1;
434}
435
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200436/**
437 * ccw_device_get_ciw() - Search for CIW command in extended sense data.
438 * @cdev: ccw device to inspect
439 * @ct: command type to look for
440 *
441 * During SenseID, command information words (CIWs) describing special
442 * commands available to the device may have been stored in the extended
443 * sense data. This function searches for CIWs of a specified command
444 * type in the extended sense data.
445 * Returns:
446 * %NULL if no extended sense data has been stored or if no CIW of the
447 * specified command type could be found,
448 * else a pointer to the CIW of the specified command type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200450struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 int ciw_cnt;
453
454 if (cdev->private->flags.esid == 0)
455 return NULL;
456 for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
457 if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
458 return cdev->private->senseid.ciw + ciw_cnt;
459 return NULL;
460}
461
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200462/**
463 * ccw_device_get_path_mask() - get currently available paths
464 * @cdev: ccw device to be queried
465 * Returns:
466 * %0 if no subchannel for the device is available,
467 * else the mask of currently available paths for the ccw device's subchannel.
468 */
469__u8 ccw_device_get_path_mask(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 struct subchannel *sch;
472
473 sch = to_subchannel(cdev->dev.parent);
474 if (!sch)
475 return 0;
476 else
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200477 return sch->lpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480/*
481 * Try to break the lock on a boxed device.
482 */
483int
484ccw_device_stlck(struct ccw_device *cdev)
485{
486 void *buf, *buf2;
487 unsigned long flags;
488 struct subchannel *sch;
489 int ret;
490
491 if (!cdev)
492 return -ENODEV;
493
494 if (cdev->drv && !cdev->private->options.force)
495 return -EINVAL;
496
497 sch = to_subchannel(cdev->dev.parent);
498
499 CIO_TRACE_EVENT(2, "stl lock");
500 CIO_TRACE_EVENT(2, cdev->dev.bus_id);
501
502 buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
503 if (!buf)
504 return -ENOMEM;
505 buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
506 if (!buf2) {
507 kfree(buf);
508 return -ENOMEM;
509 }
Cornelia Huck2ec22982006-12-08 15:54:26 +0100510 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckedf22092008-04-30 13:38:39 +0200511 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (ret)
513 goto out_unlock;
514 /*
515 * Setup ccw. We chain an unconditional reserve and a release so we
516 * only break the lock.
517 */
518 cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
519 cdev->private->iccws[0].cda = (__u32) __pa(buf);
520 cdev->private->iccws[0].count = 32;
521 cdev->private->iccws[0].flags = CCW_FLAG_CC;
522 cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
523 cdev->private->iccws[1].cda = (__u32) __pa(buf2);
524 cdev->private->iccws[1].count = 32;
525 cdev->private->iccws[1].flags = 0;
526 ret = cio_start(sch, cdev->private->iccws, 0);
527 if (ret) {
528 cio_disable_subchannel(sch); //FIXME: return code?
529 goto out_unlock;
530 }
531 cdev->private->irb.scsw.actl |= SCSW_ACTL_START_PEND;
Cornelia Huck2ec22982006-12-08 15:54:26 +0100532 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 wait_event(cdev->private->wait_q, cdev->private->irb.scsw.actl == 0);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100534 spin_lock_irqsave(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 cio_disable_subchannel(sch); //FIXME: return code?
536 if ((cdev->private->irb.scsw.dstat !=
537 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
538 (cdev->private->irb.scsw.cstat != 0))
539 ret = -EIO;
540 /* Clear irb. */
541 memset(&cdev->private->irb, 0, sizeof(struct irb));
542out_unlock:
Jesper Juhl17fd6822005-11-07 01:01:30 -0800543 kfree(buf);
544 kfree(buf2);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100545 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return ret;
547}
548
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200549void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
551 struct subchannel *sch;
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200552 struct chp_id chpid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleitere6b6e102007-04-27 16:01:28 +0200555 chp_id_init(&chpid);
556 chpid.id = sch->schib.pmcw.chpid[chp_no];
557 return chp_get_chp_desc(chpid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200560/**
561 * ccw_device_get_id - obtain a ccw device id
562 * @cdev: device to obtain the id for
563 * @dev_id: where to fill in the values
564 */
565void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
566{
567 *dev_id = cdev->private->dev_id;
568}
569EXPORT_SYMBOL(ccw_device_get_id);
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571// FIXME: these have to go:
572
573int
574_ccw_device_get_subchannel_number(struct ccw_device *cdev)
575{
Cornelia Huck78964262006-10-11 15:31:38 +0200576 return cdev->private->schid.sch_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580MODULE_LICENSE("GPL");
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100581EXPORT_SYMBOL(ccw_device_set_options_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582EXPORT_SYMBOL(ccw_device_set_options);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100583EXPORT_SYMBOL(ccw_device_clear_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584EXPORT_SYMBOL(ccw_device_clear);
585EXPORT_SYMBOL(ccw_device_halt);
586EXPORT_SYMBOL(ccw_device_resume);
587EXPORT_SYMBOL(ccw_device_start_timeout);
588EXPORT_SYMBOL(ccw_device_start);
589EXPORT_SYMBOL(ccw_device_start_timeout_key);
590EXPORT_SYMBOL(ccw_device_start_key);
591EXPORT_SYMBOL(ccw_device_get_ciw);
592EXPORT_SYMBOL(ccw_device_get_path_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);