2 * CCW device PGID and path verification I/O handling.
4 * Copyright IBM Corp. 2002,2009
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/bitops.h>
15 #include <asm/ccwdev.h>
19 #include "cio_debug.h"
23 #define PGID_RETRIES 256
24 #define PGID_TIMEOUT (10 * HZ)
27 * Process path verification data and report result.
29 static void verify_done(struct ccw_device
*cdev
, int rc
)
31 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
32 struct ccw_dev_id
*id
= &cdev
->private->dev_id
;
33 int mpath
= cdev
->private->flags
.mpath
;
34 int pgroup
= cdev
->private->flags
.pgroup
;
38 /* Ensure consistent multipathing state at device and channel. */
39 if (sch
->config
.mp
!= mpath
) {
40 sch
->config
.mp
= mpath
;
41 rc
= cio_commit_config(sch
);
44 CIO_MSG_EVENT(2, "vrfy: device 0.%x.%04x: rc=%d pgroup=%d mpath=%d "
45 "vpm=%02x\n", id
->ssid
, id
->devno
, rc
, pgroup
, mpath
,
47 ccw_device_verify_done(cdev
, rc
);
51 * Create channel program to perform a NOOP.
53 static void nop_build_cp(struct ccw_device
*cdev
)
55 struct ccw_request
*req
= &cdev
->private->req
;
56 struct ccw1
*cp
= cdev
->private->iccws
;
58 cp
->cmd_code
= CCW_CMD_NOOP
;
61 cp
->flags
= CCW_FLAG_SLI
;
66 * Perform NOOP on a single path.
68 static void nop_do(struct ccw_device
*cdev
)
70 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
71 struct ccw_request
*req
= &cdev
->private->req
;
74 req
->lpm
= lpm_adjust(req
->lpm
, sch
->schib
.pmcw
.pam
& sch
->opm
);
78 ccw_request_start(cdev
);
82 verify_done(cdev
, sch
->vpm
? 0 : -EACCES
);
86 * Adjust NOOP I/O status.
88 static enum io_status
nop_filter(struct ccw_device
*cdev
, void *data
,
89 struct irb
*irb
, enum io_status status
)
91 /* Only subchannel status might indicate a path error. */
92 if (status
== IO_STATUS_ERROR
&& irb
->scsw
.cmd
.cstat
== 0)
98 * Process NOOP request result for a single path.
100 static void nop_callback(struct ccw_device
*cdev
, void *data
, int rc
)
102 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
103 struct ccw_request
*req
= &cdev
->private->req
;
106 sch
->vpm
|= req
->lpm
;
107 else if (rc
!= -EACCES
)
114 verify_done(cdev
, rc
);
118 * Create channel program to perform SET PGID on a single path.
120 static void spid_build_cp(struct ccw_device
*cdev
, u8 fn
)
122 struct ccw_request
*req
= &cdev
->private->req
;
123 struct ccw1
*cp
= cdev
->private->iccws
;
124 int i
= 8 - ffs(req
->lpm
);
125 struct pgid
*pgid
= &cdev
->private->pgid
[i
];
128 cp
->cmd_code
= CCW_CMD_SET_PGID
;
129 cp
->cda
= (u32
) (addr_t
) pgid
;
130 cp
->count
= sizeof(*pgid
);
131 cp
->flags
= CCW_FLAG_SLI
;
136 * Perform establish/resign SET PGID on a single path.
138 static void spid_do(struct ccw_device
*cdev
)
140 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
141 struct ccw_request
*req
= &cdev
->private->req
;
144 /* Use next available path that is not already in correct state. */
145 req
->lpm
= lpm_adjust(req
->lpm
, cdev
->private->pgid_todo_mask
);
148 /* Channel program setup. */
149 if (req
->lpm
& sch
->opm
)
150 fn
= SPID_FUNC_ESTABLISH
;
152 fn
= SPID_FUNC_RESIGN
;
153 if (cdev
->private->flags
.mpath
)
154 fn
|= SPID_FUNC_MULTI_PATH
;
155 spid_build_cp(cdev
, fn
);
156 ccw_request_start(cdev
);
160 verify_done(cdev
, sch
->vpm
? 0 : -EACCES
);
163 static void verify_start(struct ccw_device
*cdev
);
166 * Process SET PGID request result for a single path.
168 static void spid_callback(struct ccw_device
*cdev
, void *data
, int rc
)
170 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
171 struct ccw_request
*req
= &cdev
->private->req
;
175 sch
->vpm
|= req
->lpm
& sch
->opm
;
180 if (cdev
->private->flags
.mpath
) {
181 /* Try without multipathing. */
182 cdev
->private->flags
.mpath
= 0;
185 /* Try without pathgrouping. */
186 cdev
->private->flags
.pgroup
= 0;
199 verify_done(cdev
, rc
);
202 static void spid_start(struct ccw_device
*cdev
)
204 struct ccw_request
*req
= &cdev
->private->req
;
206 /* Initialize request data. */
207 memset(req
, 0, sizeof(*req
));
208 req
->timeout
= PGID_TIMEOUT
;
209 req
->maxretries
= PGID_RETRIES
;
211 req
->callback
= spid_callback
;
215 static int pgid_cmp(struct pgid
*p1
, struct pgid
*p2
)
217 return memcmp((char *) p1
+ 1, (char *) p2
+ 1,
218 sizeof(struct pgid
) - 1);
222 * Determine pathgroup state from PGID data.
224 static void pgid_analyze(struct ccw_device
*cdev
, struct pgid
**p
,
225 int *mismatch
, int *reserved
, int *reset
)
227 struct pgid
*pgid
= &cdev
->private->pgid
[0];
228 struct pgid
*first
= NULL
;
235 for (i
= 0, lpm
= 0x80; i
< 8; i
++, pgid
++, lpm
>>= 1) {
236 if ((cdev
->private->pgid_valid_mask
& lpm
) == 0)
238 if (pgid
->inf
.ps
.state2
== SNID_STATE2_RESVD_ELSE
)
240 if (pgid
->inf
.ps
.state1
== SNID_STATE1_RESET
) {
241 /* A PGID was reset. */
249 if (pgid_cmp(pgid
, first
) != 0)
253 first
= &channel_subsystems
[0]->global_pgid
;
257 static u8
pgid_to_donepm(struct ccw_device
*cdev
)
259 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
265 /* Set bits for paths which are already in the target state. */
266 for (i
= 0; i
< 8; i
++) {
268 if ((cdev
->private->pgid_valid_mask
& lpm
) == 0)
270 pgid
= &cdev
->private->pgid
[i
];
271 if (sch
->opm
& lpm
) {
272 if (pgid
->inf
.ps
.state1
!= SNID_STATE1_GROUPED
)
275 if (pgid
->inf
.ps
.state1
!= SNID_STATE1_UNGROUPED
)
278 if (cdev
->private->flags
.mpath
) {
279 if (pgid
->inf
.ps
.state3
!= SNID_STATE3_MULTI_PATH
)
282 if (pgid
->inf
.ps
.state3
!= SNID_STATE3_SINGLE_PATH
)
291 static void pgid_fill(struct ccw_device
*cdev
, struct pgid
*pgid
)
295 for (i
= 0; i
< 8; i
++)
296 memcpy(&cdev
->private->pgid
[i
], pgid
, sizeof(struct pgid
));
300 * Process SENSE PGID data and report result.
302 static void snid_done(struct ccw_device
*cdev
, int rc
)
304 struct ccw_dev_id
*id
= &cdev
->private->dev_id
;
305 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
314 pgid_analyze(cdev
, &pgid
, &mismatch
, &reserved
, &reset
);
320 donepm
= pgid_to_donepm(cdev
);
321 sch
->vpm
= donepm
& sch
->opm
;
322 cdev
->private->pgid_todo_mask
&= ~donepm
;
323 pgid_fill(cdev
, pgid
);
326 CIO_MSG_EVENT(2, "snid: device 0.%x.%04x: rc=%d pvm=%02x vpm=%02x "
327 "todo=%02x mism=%d rsvd=%d reset=%d\n", id
->ssid
,
328 id
->devno
, rc
, cdev
->private->pgid_valid_mask
, sch
->vpm
,
329 cdev
->private->pgid_todo_mask
, mismatch
, reserved
, reset
);
332 /* Anything left to do? */
333 if (cdev
->private->pgid_todo_mask
== 0) {
334 verify_done(cdev
, sch
->vpm
== 0 ? -EACCES
: 0);
337 /* Perform path-grouping. */
341 /* Path-grouping not supported. */
342 cdev
->private->flags
.pgroup
= 0;
343 cdev
->private->flags
.mpath
= 0;
347 verify_done(cdev
, rc
);
352 * Create channel program to perform a SENSE PGID on a single path.
354 static void snid_build_cp(struct ccw_device
*cdev
)
356 struct ccw_request
*req
= &cdev
->private->req
;
357 struct ccw1
*cp
= cdev
->private->iccws
;
358 int i
= 8 - ffs(req
->lpm
);
360 /* Channel program setup. */
361 cp
->cmd_code
= CCW_CMD_SENSE_PGID
;
362 cp
->cda
= (u32
) (addr_t
) &cdev
->private->pgid
[i
];
363 cp
->count
= sizeof(struct pgid
);
364 cp
->flags
= CCW_FLAG_SLI
;
369 * Perform SENSE PGID on a single path.
371 static void snid_do(struct ccw_device
*cdev
)
373 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
374 struct ccw_request
*req
= &cdev
->private->req
;
376 /* Adjust lpm if paths are not set in pam. */
377 req
->lpm
= lpm_adjust(req
->lpm
, sch
->schib
.pmcw
.pam
);
381 ccw_request_start(cdev
);
385 snid_done(cdev
, cdev
->private->pgid_valid_mask
? 0 : -EACCES
);
389 * Process SENSE PGID request result for single path.
391 static void snid_callback(struct ccw_device
*cdev
, void *data
, int rc
)
393 struct ccw_request
*req
= &cdev
->private->req
;
396 cdev
->private->pgid_valid_mask
|= req
->lpm
;
397 else if (rc
!= -EACCES
)
408 * Perform path verification.
410 static void verify_start(struct ccw_device
*cdev
)
412 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
413 struct ccw_request
*req
= &cdev
->private->req
;
414 struct ccw_dev_id
*devid
= &cdev
->private->dev_id
;
417 sch
->lpm
= sch
->schib
.pmcw
.pam
;
418 /* Initialize request data. */
419 memset(req
, 0, sizeof(*req
));
420 req
->timeout
= PGID_TIMEOUT
;
421 req
->maxretries
= PGID_RETRIES
;
423 if (cdev
->private->flags
.pgroup
) {
424 CIO_TRACE_EVENT(4, "snid");
425 CIO_HEX_EVENT(4, devid
, sizeof(*devid
));
426 req
->callback
= snid_callback
;
429 CIO_TRACE_EVENT(4, "nop");
430 CIO_HEX_EVENT(4, devid
, sizeof(*devid
));
431 req
->filter
= nop_filter
;
432 req
->callback
= nop_callback
;
438 * ccw_device_verify_start - perform path verification
441 * Perform an I/O on each available channel path to @cdev to determine which
442 * paths are operational. The resulting path mask is stored in sch->vpm.
443 * If device options specify pathgrouping, establish a pathgroup for the
444 * operational paths. When finished, call ccw_device_verify_done with a
445 * return code specifying the result.
447 void ccw_device_verify_start(struct ccw_device
*cdev
)
449 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
451 CIO_TRACE_EVENT(4, "vrfy");
452 CIO_HEX_EVENT(4, &cdev
->private->dev_id
, sizeof(cdev
->private->dev_id
));
453 /* Initialize PGID data. */
454 memset(cdev
->private->pgid
, 0, sizeof(cdev
->private->pgid
));
455 cdev
->private->pgid_valid_mask
= 0;
456 cdev
->private->pgid_todo_mask
= sch
->schib
.pmcw
.pam
;
458 * Initialize pathgroup and multipath state with target values.
459 * They may change in the course of path verification.
461 cdev
->private->flags
.pgroup
= cdev
->private->options
.pgroup
;
462 cdev
->private->flags
.mpath
= cdev
->private->options
.mpath
;
463 cdev
->private->flags
.doverify
= 0;
468 * Process disband SET PGID request result.
470 static void disband_callback(struct ccw_device
*cdev
, void *data
, int rc
)
472 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
473 struct ccw_dev_id
*id
= &cdev
->private->dev_id
;
477 /* Ensure consistent multipathing state at device and channel. */
478 cdev
->private->flags
.mpath
= 0;
479 if (sch
->config
.mp
) {
481 rc
= cio_commit_config(sch
);
484 CIO_MSG_EVENT(0, "disb: device 0.%x.%04x: rc=%d\n", id
->ssid
, id
->devno
,
486 ccw_device_disband_done(cdev
, rc
);
490 * ccw_device_disband_start - disband pathgroup
493 * Execute a SET PGID channel program on @cdev to disband a previously
494 * established pathgroup. When finished, call ccw_device_disband_done with
495 * a return code specifying the result.
497 void ccw_device_disband_start(struct ccw_device
*cdev
)
499 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
500 struct ccw_request
*req
= &cdev
->private->req
;
503 CIO_TRACE_EVENT(4, "disb");
504 CIO_HEX_EVENT(4, &cdev
->private->dev_id
, sizeof(cdev
->private->dev_id
));
506 memset(req
, 0, sizeof(*req
));
507 req
->timeout
= PGID_TIMEOUT
;
508 req
->maxretries
= PGID_RETRIES
;
509 req
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
510 req
->callback
= disband_callback
;
511 fn
= SPID_FUNC_DISBAND
;
512 if (cdev
->private->flags
.mpath
)
513 fn
|= SPID_FUNC_MULTI_PATH
;
514 spid_build_cp(cdev
, fn
);
515 ccw_request_start(cdev
);
518 static void stlck_build_cp(struct ccw_device
*cdev
, void *buf1
, void *buf2
)
520 struct ccw_request
*req
= &cdev
->private->req
;
521 struct ccw1
*cp
= cdev
->private->iccws
;
523 cp
[0].cmd_code
= CCW_CMD_STLCK
;
524 cp
[0].cda
= (u32
) (addr_t
) buf1
;
526 cp
[0].flags
= CCW_FLAG_CC
;
527 cp
[1].cmd_code
= CCW_CMD_RELEASE
;
528 cp
[1].cda
= (u32
) (addr_t
) buf2
;
534 static void stlck_callback(struct ccw_device
*cdev
, void *data
, int rc
)
536 ccw_device_stlck_done(cdev
, data
, rc
);
540 * ccw_device_stlck_start - perform unconditional release
542 * @data: data pointer to be passed to ccw_device_stlck_done
543 * @buf1: data pointer used in channel program
544 * @buf2: data pointer used in channel program
546 * Execute a channel program on @cdev to release an existing PGID reservation.
547 * When finished, call ccw_device_stlck_done with a return code specifying the
550 void ccw_device_stlck_start(struct ccw_device
*cdev
, void *data
, void *buf1
,
553 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
554 struct ccw_request
*req
= &cdev
->private->req
;
556 CIO_TRACE_EVENT(4, "stlck");
557 CIO_HEX_EVENT(4, &cdev
->private->dev_id
, sizeof(cdev
->private->dev_id
));
559 memset(req
, 0, sizeof(*req
));
560 req
->timeout
= PGID_TIMEOUT
;
561 req
->maxretries
= PGID_RETRIES
;
562 req
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
564 req
->callback
= stlck_callback
;
565 stlck_build_cp(cdev
, buf1
, buf2
);
566 ccw_request_start(cdev
);