2 * drivers/s390/cio/device_pgid.c
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Path Group ID functions.
12 #include <linux/module.h>
13 #include <linux/init.h>
15 #include <asm/ccwdev.h>
17 #include <asm/delay.h>
18 #include <asm/lowcore.h>
21 #include "cio_debug.h"
27 * Helper function called from interrupt context to decide whether an
28 * operation should be tried again.
30 static int __ccw_device_should_retry(struct scsw
*scsw
)
32 /* CC is only valid if start function bit is set. */
33 if ((scsw
->fctl
& SCSW_FCTL_START_FUNC
) && scsw
->cc
== 1)
35 /* No more activity. For sense and set PGID we stubbornly try again. */
42 * Start Sense Path Group ID helper function. Used in ccw_device_recog
43 * and ccw_device_sense_pgid.
46 __ccw_device_sense_pgid_start(struct ccw_device
*cdev
)
48 struct subchannel
*sch
;
53 sch
= to_subchannel(cdev
->dev
.parent
);
54 /* Return if we already checked on all paths. */
55 if (cdev
->private->imask
== 0)
56 return (sch
->lpm
== 0) ? -ENODEV
: -EACCES
;
57 i
= 8 - ffs(cdev
->private->imask
);
59 /* Setup sense path group id channel program. */
60 ccw
= cdev
->private->iccws
;
61 ccw
->cmd_code
= CCW_CMD_SENSE_PGID
;
62 ccw
->count
= sizeof (struct pgid
);
63 ccw
->flags
= CCW_FLAG_SLI
;
65 /* Reset device status. */
66 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
67 /* Try on every path. */
69 while (cdev
->private->imask
!= 0) {
70 /* Try every path multiple times. */
71 ccw
->cda
= (__u32
) __pa (&cdev
->private->pgid
[i
]);
72 if (cdev
->private->iretry
> 0) {
73 cdev
->private->iretry
--;
74 ret
= cio_start (sch
, cdev
->private->iccws
,
75 cdev
->private->imask
);
76 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
79 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel "
80 "0.%x.%04x, lpm %02X, became 'not "
82 cdev
->private->dev_id
.devno
,
84 sch
->schid
.sch_no
, cdev
->private->imask
);
87 cdev
->private->imask
>>= 1;
88 cdev
->private->iretry
= 5;
96 ccw_device_sense_pgid_start(struct ccw_device
*cdev
)
100 /* Set a timeout of 60s */
101 ccw_device_set_timeout(cdev
, 60*HZ
);
103 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
104 cdev
->private->imask
= 0x80;
105 cdev
->private->iretry
= 5;
106 memset (&cdev
->private->pgid
, 0, sizeof (cdev
->private->pgid
));
107 ret
= __ccw_device_sense_pgid_start(cdev
);
108 if (ret
&& ret
!= -EBUSY
)
109 ccw_device_sense_pgid_done(cdev
, ret
);
113 * Called from interrupt context to check if a valid answer
114 * to Sense Path Group ID was received.
117 __ccw_device_check_sense_pgid(struct ccw_device
*cdev
)
119 struct subchannel
*sch
;
123 sch
= to_subchannel(cdev
->dev
.parent
);
124 irb
= &cdev
->private->irb
;
125 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
))
127 if (irb
->esw
.esw0
.erw
.cons
&&
128 (irb
->ecw
[0]&(SNS0_CMD_REJECT
|SNS0_INTERVENTION_REQ
))) {
130 * If the device doesn't support the Sense Path Group ID
131 * command further retries wouldn't help ...
135 if (irb
->esw
.esw0
.erw
.cons
) {
136 CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, "
137 "lpum %02X, cnt %02d, sns : "
138 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
139 cdev
->private->dev_id
.ssid
,
140 cdev
->private->dev_id
.devno
,
141 irb
->esw
.esw0
.sublog
.lpum
,
142 irb
->esw
.esw0
.erw
.scnt
,
143 irb
->ecw
[0], irb
->ecw
[1],
144 irb
->ecw
[2], irb
->ecw
[3],
145 irb
->ecw
[4], irb
->ecw
[5],
146 irb
->ecw
[6], irb
->ecw
[7]);
149 if (irb
->scsw
.cc
== 3) {
150 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x,"
151 " lpm %02X, became 'not operational'\n",
152 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
153 sch
->schid
.sch_no
, sch
->orb
.lpm
);
156 i
= 8 - ffs(cdev
->private->imask
);
157 if (cdev
->private->pgid
[i
].inf
.ps
.state2
== SNID_STATE2_RESVD_ELSE
) {
158 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x "
159 "is reserved by someone else\n",
160 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
168 * Got interrupt for Sense Path Group ID.
171 ccw_device_sense_pgid_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
173 struct subchannel
*sch
;
177 irb
= (struct irb
*) __LC_IRB
;
179 if (irb
->scsw
.stctl
==
180 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
181 if (__ccw_device_should_retry(&irb
->scsw
)) {
182 ret
= __ccw_device_sense_pgid_start(cdev
);
183 if (ret
&& ret
!= -EBUSY
)
184 ccw_device_sense_pgid_done(cdev
, ret
);
188 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
190 sch
= to_subchannel(cdev
->dev
.parent
);
191 ret
= __ccw_device_check_sense_pgid(cdev
);
192 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
194 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
195 case -EOPNOTSUPP
: /* Sense Path Group ID not supported */
196 ccw_device_sense_pgid_done(cdev
, -EOPNOTSUPP
);
198 case -ETIME
: /* Sense path group id stopped by timeout. */
199 ccw_device_sense_pgid_done(cdev
, -ETIME
);
201 case -EACCES
: /* channel is not operational. */
202 sch
->lpm
&= ~cdev
->private->imask
;
204 case 0: /* Sense Path Group ID successful. */
205 cdev
->private->imask
>>= 1;
206 cdev
->private->iretry
= 5;
208 case -EAGAIN
: /* Try again. */
209 ret
= __ccw_device_sense_pgid_start(cdev
);
210 if (ret
!= 0 && ret
!= -EBUSY
)
211 ccw_device_sense_pgid_done(cdev
, ret
);
213 case -EUSERS
: /* device is reserved for someone else. */
214 ccw_device_sense_pgid_done(cdev
, -EUSERS
);
220 * Path Group ID helper function.
223 __ccw_device_do_pgid(struct ccw_device
*cdev
, __u8 func
)
225 struct subchannel
*sch
;
229 sch
= to_subchannel(cdev
->dev
.parent
);
231 /* Setup sense path group id channel program. */
232 cdev
->private->pgid
[0].inf
.fc
= func
;
233 ccw
= cdev
->private->iccws
;
234 if (!cdev
->private->flags
.pgid_single
) {
235 cdev
->private->pgid
[0].inf
.fc
|= SPID_FUNC_MULTI_PATH
;
236 ccw
->cmd_code
= CCW_CMD_SUSPEND_RECONN
;
239 ccw
->flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
242 cdev
->private->pgid
[0].inf
.fc
|= SPID_FUNC_SINGLE_PATH
;
244 ccw
->cmd_code
= CCW_CMD_SET_PGID
;
245 ccw
->cda
= (__u32
) __pa (&cdev
->private->pgid
[0]);
246 ccw
->count
= sizeof (struct pgid
);
247 ccw
->flags
= CCW_FLAG_SLI
;
249 /* Reset device status. */
250 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
252 /* Try multiple times. */
254 if (cdev
->private->iretry
> 0) {
255 cdev
->private->iretry
--;
256 ret
= cio_start (sch
, cdev
->private->iccws
,
257 cdev
->private->imask
);
258 /* We expect an interrupt in case of success or busy
260 if ((ret
== 0) || (ret
== -EBUSY
))
263 /* PGID command failed on this path. */
264 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
265 "0.%x.%04x, lpm %02X, became 'not operational'\n",
266 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
267 sch
->schid
.sch_no
, cdev
->private->imask
);
272 * Helper function to send a nop ccw down a path.
274 static int __ccw_device_do_nop(struct ccw_device
*cdev
)
276 struct subchannel
*sch
;
280 sch
= to_subchannel(cdev
->dev
.parent
);
282 /* Setup nop channel program. */
283 ccw
= cdev
->private->iccws
;
284 ccw
->cmd_code
= CCW_CMD_NOOP
;
287 ccw
->flags
= CCW_FLAG_SLI
;
289 /* Reset device status. */
290 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
292 /* Try multiple times. */
294 if (cdev
->private->iretry
> 0) {
295 cdev
->private->iretry
--;
296 ret
= cio_start (sch
, cdev
->private->iccws
,
297 cdev
->private->imask
);
298 /* We expect an interrupt in case of success or busy
300 if ((ret
== 0) || (ret
== -EBUSY
))
303 /* nop command failed on this path. */
304 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel "
305 "0.%x.%04x, lpm %02X, became 'not operational'\n",
306 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
307 sch
->schid
.sch_no
, cdev
->private->imask
);
313 * Called from interrupt context to check if a valid answer
314 * to Set Path Group ID was received.
317 __ccw_device_check_pgid(struct ccw_device
*cdev
)
319 struct subchannel
*sch
;
322 sch
= to_subchannel(cdev
->dev
.parent
);
323 irb
= &cdev
->private->irb
;
324 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
))
326 if (irb
->esw
.esw0
.erw
.cons
) {
327 if (irb
->ecw
[0] & SNS0_CMD_REJECT
)
329 /* Hmm, whatever happened, try again. */
330 CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, "
332 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
333 cdev
->private->dev_id
.ssid
,
334 cdev
->private->dev_id
.devno
,
335 irb
->esw
.esw0
.erw
.scnt
,
336 irb
->ecw
[0], irb
->ecw
[1],
337 irb
->ecw
[2], irb
->ecw
[3],
338 irb
->ecw
[4], irb
->ecw
[5],
339 irb
->ecw
[6], irb
->ecw
[7]);
342 if (irb
->scsw
.cc
== 3) {
343 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel 0.%x.%04x,"
344 " lpm %02X, became 'not operational'\n",
345 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
346 sch
->schid
.sch_no
, cdev
->private->imask
);
353 * Called from interrupt context to check the path status after a nop has
356 static int __ccw_device_check_nop(struct ccw_device
*cdev
)
358 struct subchannel
*sch
;
361 sch
= to_subchannel(cdev
->dev
.parent
);
362 irb
= &cdev
->private->irb
;
363 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
))
365 if (irb
->scsw
.cc
== 3) {
366 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel 0.%x.%04x,"
367 " lpm %02X, became 'not operational'\n",
368 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
369 sch
->schid
.sch_no
, cdev
->private->imask
);
376 __ccw_device_verify_start(struct ccw_device
*cdev
)
378 struct subchannel
*sch
;
382 sch
= to_subchannel(cdev
->dev
.parent
);
383 /* Repeat for all paths. */
384 for (; cdev
->private->imask
; cdev
->private->imask
>>= 1,
385 cdev
->private->iretry
= 5) {
386 if ((cdev
->private->imask
& sch
->schib
.pmcw
.pam
) == 0)
387 /* Path not available, try next. */
389 if (cdev
->private->options
.pgroup
) {
390 if (sch
->opm
& cdev
->private->imask
)
391 func
= SPID_FUNC_ESTABLISH
;
393 func
= SPID_FUNC_RESIGN
;
394 ret
= __ccw_device_do_pgid(cdev
, func
);
396 ret
= __ccw_device_do_nop(cdev
);
397 /* We expect an interrupt in case of success or busy
399 if (ret
== 0 || ret
== -EBUSY
)
401 /* Permanent path failure, try next. */
403 /* Done with all paths. */
404 ccw_device_verify_done(cdev
, (sch
->vpm
!= 0) ? 0 : -ENODEV
);
408 * Got interrupt for Set Path Group ID.
411 ccw_device_verify_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
413 struct subchannel
*sch
;
417 irb
= (struct irb
*) __LC_IRB
;
419 if (irb
->scsw
.stctl
==
420 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
421 if (__ccw_device_should_retry(&irb
->scsw
))
422 __ccw_device_verify_start(cdev
);
425 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
427 sch
= to_subchannel(cdev
->dev
.parent
);
428 if (cdev
->private->options
.pgroup
)
429 ret
= __ccw_device_check_pgid(cdev
);
431 ret
= __ccw_device_check_nop(cdev
);
432 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
435 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
437 /* Path verification ccw finished successfully, update lpm. */
438 sch
->vpm
|= sch
->opm
& cdev
->private->imask
;
439 /* Go on with next path. */
440 cdev
->private->imask
>>= 1;
441 cdev
->private->iretry
= 5;
442 __ccw_device_verify_start(cdev
);
446 * One of those strange devices which claim to be able
447 * to do multipathing but not for Set Path Group ID.
449 if (cdev
->private->flags
.pgid_single
)
450 cdev
->private->options
.pgroup
= 0;
452 cdev
->private->flags
.pgid_single
= 1;
455 cdev
->private->imask
= 0x80;
456 cdev
->private->iretry
= 5;
458 case -EAGAIN
: /* Try again. */
459 __ccw_device_verify_start(cdev
);
461 case -ETIME
: /* Set path group id stopped by timeout. */
462 ccw_device_verify_done(cdev
, -ETIME
);
464 case -EACCES
: /* channel is not operational. */
465 cdev
->private->imask
>>= 1;
466 cdev
->private->iretry
= 5;
467 __ccw_device_verify_start(cdev
);
473 ccw_device_verify_start(struct ccw_device
*cdev
)
475 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
477 cdev
->private->flags
.pgid_single
= 0;
478 cdev
->private->imask
= 0x80;
479 cdev
->private->iretry
= 5;
481 /* Start with empty vpm. */
484 /* Get current pam. */
485 if (stsch(sch
->schid
, &sch
->schib
)) {
486 ccw_device_verify_done(cdev
, -ENODEV
);
489 /* After 60s path verification is considered to have failed. */
490 ccw_device_set_timeout(cdev
, 60*HZ
);
491 __ccw_device_verify_start(cdev
);
495 __ccw_device_disband_start(struct ccw_device
*cdev
)
497 struct subchannel
*sch
;
500 sch
= to_subchannel(cdev
->dev
.parent
);
501 while (cdev
->private->imask
!= 0) {
502 if (sch
->lpm
& cdev
->private->imask
) {
503 ret
= __ccw_device_do_pgid(cdev
, SPID_FUNC_DISBAND
);
507 cdev
->private->iretry
= 5;
508 cdev
->private->imask
>>= 1;
510 ccw_device_disband_done(cdev
, (sch
->lpm
!= 0) ? 0 : -ENODEV
);
514 * Got interrupt for Unset Path Group ID.
517 ccw_device_disband_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
519 struct subchannel
*sch
;
523 irb
= (struct irb
*) __LC_IRB
;
525 if (irb
->scsw
.stctl
==
526 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
527 if (__ccw_device_should_retry(&irb
->scsw
))
528 __ccw_device_disband_start(cdev
);
531 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
533 sch
= to_subchannel(cdev
->dev
.parent
);
534 ret
= __ccw_device_check_pgid(cdev
);
535 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
537 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
538 case 0: /* disband successful. */
539 ccw_device_disband_done(cdev
, ret
);
543 * One of those strange devices which claim to be able
544 * to do multipathing but not for Unset Path Group ID.
546 cdev
->private->flags
.pgid_single
= 1;
548 case -EAGAIN
: /* Try again. */
549 __ccw_device_disband_start(cdev
);
551 case -ETIME
: /* Set path group id stopped by timeout. */
552 ccw_device_disband_done(cdev
, -ETIME
);
554 case -EACCES
: /* channel is not operational. */
555 cdev
->private->imask
>>= 1;
556 cdev
->private->iretry
= 5;
557 __ccw_device_disband_start(cdev
);
563 ccw_device_disband_start(struct ccw_device
*cdev
)
565 /* After 60s disbanding is considered to have failed. */
566 ccw_device_set_timeout(cdev
, 60*HZ
);
568 cdev
->private->flags
.pgid_single
= 0;
569 cdev
->private->iretry
= 5;
570 cdev
->private->imask
= 0x80;
571 __ccw_device_disband_start(cdev
);
This page took 0.044797 seconds and 5 git commands to generate.