]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/s390/cio/device_pgid.c
757b2706d5a947ab3f7a67656156e9e255fcdc31
2 * drivers/s390/cio/device_pgid.c
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * Author(s): Cornelia Huck(cohuck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Path Group ID functions.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
16 #include <asm/ccwdev.h>
18 #include <asm/delay.h>
19 #include <asm/lowcore.h>
22 #include "cio_debug.h"
28 * Start Sense Path Group ID helper function. Used in ccw_device_recog
29 * and ccw_device_sense_pgid.
32 __ccw_device_sense_pgid_start(struct ccw_device
*cdev
)
34 struct subchannel
*sch
;
38 sch
= to_subchannel(cdev
->dev
.parent
);
39 /* Setup sense path group id channel program. */
40 ccw
= cdev
->private->iccws
;
41 ccw
->cmd_code
= CCW_CMD_SENSE_PGID
;
42 ccw
->cda
= (__u32
) __pa (&cdev
->private->pgid
);
43 ccw
->count
= sizeof (struct pgid
);
44 ccw
->flags
= CCW_FLAG_SLI
;
46 /* Reset device status. */
47 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
48 /* Try on every path. */
50 while (cdev
->private->imask
!= 0) {
51 /* Try every path multiple times. */
52 if (cdev
->private->iretry
> 0) {
53 cdev
->private->iretry
--;
54 ret
= cio_start (sch
, cdev
->private->iccws
,
55 cdev
->private->imask
);
56 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
59 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel "
60 "%04x, lpm %02X, became 'not "
62 cdev
->private->devno
, sch
->irq
,
63 cdev
->private->imask
);
66 cdev
->private->imask
>>= 1;
67 cdev
->private->iretry
= 5;
73 ccw_device_sense_pgid_start(struct ccw_device
*cdev
)
77 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
78 cdev
->private->imask
= 0x80;
79 cdev
->private->iretry
= 5;
80 memset (&cdev
->private->pgid
, 0, sizeof (struct pgid
));
81 ret
= __ccw_device_sense_pgid_start(cdev
);
82 if (ret
&& ret
!= -EBUSY
)
83 ccw_device_sense_pgid_done(cdev
, ret
);
87 * Called from interrupt context to check if a valid answer
88 * to Sense Path Group ID was received.
91 __ccw_device_check_sense_pgid(struct ccw_device
*cdev
)
93 struct subchannel
*sch
;
96 sch
= to_subchannel(cdev
->dev
.parent
);
97 irb
= &cdev
->private->irb
;
98 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
))
100 if (irb
->esw
.esw0
.erw
.cons
&&
101 (irb
->ecw
[0]&(SNS0_CMD_REJECT
|SNS0_INTERVENTION_REQ
))) {
103 * If the device doesn't support the Sense Path Group ID
104 * command further retries wouldn't help ...
108 if (irb
->esw
.esw0
.erw
.cons
) {
109 CIO_MSG_EVENT(2, "SNID - device %04x, unit check, "
110 "lpum %02X, cnt %02d, sns : "
111 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
112 cdev
->private->devno
,
113 irb
->esw
.esw0
.sublog
.lpum
,
114 irb
->esw
.esw0
.erw
.scnt
,
115 irb
->ecw
[0], irb
->ecw
[1],
116 irb
->ecw
[2], irb
->ecw
[3],
117 irb
->ecw
[4], irb
->ecw
[5],
118 irb
->ecw
[6], irb
->ecw
[7]);
121 if (irb
->scsw
.cc
== 3) {
122 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel "
123 "%04x, lpm %02X, became 'not operational'\n",
124 cdev
->private->devno
, sch
->irq
, sch
->orb
.lpm
);
127 if (cdev
->private->pgid
.inf
.ps
.state2
== SNID_STATE2_RESVD_ELSE
) {
128 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel %04x "
129 "is reserved by someone else\n",
130 cdev
->private->devno
, sch
->irq
);
137 * Got interrupt for Sense Path Group ID.
140 ccw_device_sense_pgid_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
142 struct subchannel
*sch
;
146 irb
= (struct irb
*) __LC_IRB
;
147 /* Retry sense pgid for cc=1. */
148 if (irb
->scsw
.stctl
==
149 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
150 if (irb
->scsw
.cc
== 1) {
151 ret
= __ccw_device_sense_pgid_start(cdev
);
152 if (ret
&& ret
!= -EBUSY
)
153 ccw_device_sense_pgid_done(cdev
, ret
);
157 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
159 sch
= to_subchannel(cdev
->dev
.parent
);
160 ret
= __ccw_device_check_sense_pgid(cdev
);
161 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
163 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
164 case 0: /* Sense Path Group ID successful. */
165 if (cdev
->private->pgid
.inf
.ps
.state1
== SNID_STATE1_RESET
)
166 memcpy(&cdev
->private->pgid
, &global_pgid
,
167 sizeof(struct pgid
));
168 ccw_device_sense_pgid_done(cdev
, 0);
170 case -EOPNOTSUPP
: /* Sense Path Group ID not supported */
171 ccw_device_sense_pgid_done(cdev
, -EOPNOTSUPP
);
173 case -ETIME
: /* Sense path group id stopped by timeout. */
174 ccw_device_sense_pgid_done(cdev
, -ETIME
);
176 case -EACCES
: /* channel is not operational. */
177 sch
->lpm
&= ~cdev
->private->imask
;
178 cdev
->private->imask
>>= 1;
179 cdev
->private->iretry
= 5;
181 case -EAGAIN
: /* Try again. */
182 ret
= __ccw_device_sense_pgid_start(cdev
);
183 if (ret
!= 0 && ret
!= -EBUSY
)
184 ccw_device_sense_pgid_done(cdev
, -ENODEV
);
186 case -EUSERS
: /* device is reserved for someone else. */
187 ccw_device_sense_pgid_done(cdev
, -EUSERS
);
193 * Path Group ID helper function.
196 __ccw_device_do_pgid(struct ccw_device
*cdev
, __u8 func
)
198 struct subchannel
*sch
;
202 sch
= to_subchannel(cdev
->dev
.parent
);
204 /* Setup sense path group id channel program. */
205 cdev
->private->pgid
.inf
.fc
= func
;
206 ccw
= cdev
->private->iccws
;
207 if (!cdev
->private->flags
.pgid_single
) {
208 cdev
->private->pgid
.inf
.fc
|= SPID_FUNC_MULTI_PATH
;
209 ccw
->cmd_code
= CCW_CMD_SUSPEND_RECONN
;
212 ccw
->flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
215 cdev
->private->pgid
.inf
.fc
|= SPID_FUNC_SINGLE_PATH
;
217 ccw
->cmd_code
= CCW_CMD_SET_PGID
;
218 ccw
->cda
= (__u32
) __pa (&cdev
->private->pgid
);
219 ccw
->count
= sizeof (struct pgid
);
220 ccw
->flags
= CCW_FLAG_SLI
;
222 /* Reset device status. */
223 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
225 /* Try multiple times. */
227 if (cdev
->private->iretry
> 0) {
228 cdev
->private->iretry
--;
229 ret
= cio_start (sch
, cdev
->private->iccws
,
230 cdev
->private->imask
);
231 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
232 if ((ret
!= -EACCES
) && (ret
!= -ENODEV
))
235 /* PGID command failed on this path. Switch it off. */
236 sch
->lpm
&= ~cdev
->private->imask
;
237 sch
->vpm
&= ~cdev
->private->imask
;
238 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
239 "%04x, lpm %02X, became 'not operational'\n",
240 cdev
->private->devno
, sch
->irq
, cdev
->private->imask
);
245 * Called from interrupt context to check if a valid answer
246 * to Set Path Group ID was received.
249 __ccw_device_check_pgid(struct ccw_device
*cdev
)
251 struct subchannel
*sch
;
254 sch
= to_subchannel(cdev
->dev
.parent
);
255 irb
= &cdev
->private->irb
;
256 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
))
258 if (irb
->esw
.esw0
.erw
.cons
) {
259 if (irb
->ecw
[0] & SNS0_CMD_REJECT
)
261 /* Hmm, whatever happened, try again. */
262 CIO_MSG_EVENT(2, "SPID - device %04x, unit check, cnt %02d, "
263 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
264 cdev
->private->devno
, irb
->esw
.esw0
.erw
.scnt
,
265 irb
->ecw
[0], irb
->ecw
[1],
266 irb
->ecw
[2], irb
->ecw
[3],
267 irb
->ecw
[4], irb
->ecw
[5],
268 irb
->ecw
[6], irb
->ecw
[7]);
271 if (irb
->scsw
.cc
== 3) {
272 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
273 "%04x, lpm %02X, became 'not operational'\n",
274 cdev
->private->devno
, sch
->irq
,
275 cdev
->private->imask
);
282 __ccw_device_verify_start(struct ccw_device
*cdev
)
284 struct subchannel
*sch
;
288 sch
= to_subchannel(cdev
->dev
.parent
);
289 while (sch
->vpm
!= sch
->lpm
) {
290 /* Find first unequal bit in vpm vs. lpm */
291 for (imask
= 0x80; imask
!= 0; imask
>>= 1)
292 if ((sch
->vpm
& imask
) != (sch
->lpm
& imask
))
294 cdev
->private->imask
= imask
;
295 func
= (sch
->vpm
& imask
) ?
296 SPID_FUNC_RESIGN
: SPID_FUNC_ESTABLISH
;
297 ret
= __ccw_device_do_pgid(cdev
, func
);
298 if (ret
== 0 || ret
== -EBUSY
)
300 cdev
->private->iretry
= 5;
302 ccw_device_verify_done(cdev
, (sch
->lpm
!= 0) ? 0 : -ENODEV
);
306 * Got interrupt for Set Path Group ID.
309 ccw_device_verify_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
311 struct subchannel
*sch
;
315 irb
= (struct irb
*) __LC_IRB
;
316 /* Retry set pgid for cc=1. */
317 if (irb
->scsw
.stctl
==
318 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
319 if (irb
->scsw
.cc
== 1)
320 __ccw_device_verify_start(cdev
);
323 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
325 sch
= to_subchannel(cdev
->dev
.parent
);
326 ret
= __ccw_device_check_pgid(cdev
);
327 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
329 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
331 /* Establish or Resign Path Group done. Update vpm. */
332 if ((sch
->lpm
& cdev
->private->imask
) != 0)
333 sch
->vpm
|= cdev
->private->imask
;
335 sch
->vpm
&= ~cdev
->private->imask
;
336 cdev
->private->iretry
= 5;
337 __ccw_device_verify_start(cdev
);
341 * One of those strange devices which claim to be able
342 * to do multipathing but not for Set Path Group ID.
344 if (cdev
->private->flags
.pgid_single
) {
345 ccw_device_verify_done(cdev
, -EOPNOTSUPP
);
348 cdev
->private->flags
.pgid_single
= 1;
350 case -EAGAIN
: /* Try again. */
351 __ccw_device_verify_start(cdev
);
353 case -ETIME
: /* Set path group id stopped by timeout. */
354 ccw_device_verify_done(cdev
, -ETIME
);
356 case -EACCES
: /* channel is not operational. */
357 sch
->lpm
&= ~cdev
->private->imask
;
358 sch
->vpm
&= ~cdev
->private->imask
;
359 cdev
->private->iretry
= 5;
360 __ccw_device_verify_start(cdev
);
366 ccw_device_verify_start(struct ccw_device
*cdev
)
368 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
370 cdev
->private->flags
.pgid_single
= 0;
371 cdev
->private->iretry
= 5;
373 * Update sch->lpm with current values to catch paths becoming
376 if (stsch(sch
->irq
, &sch
->schib
)) {
377 ccw_device_verify_done(cdev
, -ENODEV
);
380 sch
->lpm
= sch
->schib
.pmcw
.pim
&
381 sch
->schib
.pmcw
.pam
&
382 sch
->schib
.pmcw
.pom
&
384 __ccw_device_verify_start(cdev
);
388 __ccw_device_disband_start(struct ccw_device
*cdev
)
390 struct subchannel
*sch
;
393 sch
= to_subchannel(cdev
->dev
.parent
);
394 while (cdev
->private->imask
!= 0) {
395 if (sch
->lpm
& cdev
->private->imask
) {
396 ret
= __ccw_device_do_pgid(cdev
, SPID_FUNC_DISBAND
);
400 cdev
->private->iretry
= 5;
401 cdev
->private->imask
>>= 1;
403 ccw_device_verify_done(cdev
, (sch
->lpm
!= 0) ? 0 : -ENODEV
);
407 * Got interrupt for Unset Path Group ID.
410 ccw_device_disband_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
412 struct subchannel
*sch
;
416 irb
= (struct irb
*) __LC_IRB
;
417 /* Retry set pgid for cc=1. */
418 if (irb
->scsw
.stctl
==
419 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
420 if (irb
->scsw
.cc
== 1)
421 __ccw_device_disband_start(cdev
);
424 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
426 sch
= to_subchannel(cdev
->dev
.parent
);
427 ret
= __ccw_device_check_pgid(cdev
);
428 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
430 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
431 case 0: /* disband successful. */
433 ccw_device_disband_done(cdev
, ret
);
437 * One of those strange devices which claim to be able
438 * to do multipathing but not for Unset Path Group ID.
440 cdev
->private->flags
.pgid_single
= 1;
442 case -EAGAIN
: /* Try again. */
443 __ccw_device_disband_start(cdev
);
445 case -ETIME
: /* Set path group id stopped by timeout. */
446 ccw_device_disband_done(cdev
, -ETIME
);
448 case -EACCES
: /* channel is not operational. */
449 cdev
->private->imask
>>= 1;
450 cdev
->private->iretry
= 5;
451 __ccw_device_disband_start(cdev
);
457 ccw_device_disband_start(struct ccw_device
*cdev
)
459 cdev
->private->flags
.pgid_single
= 0;
460 cdev
->private->iretry
= 5;
461 cdev
->private->imask
= 0x80;
462 __ccw_device_disband_start(cdev
);