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 * Start Sense Path Group ID helper function. Used in ccw_device_recog
28 * and ccw_device_sense_pgid.
31 __ccw_device_sense_pgid_start(struct ccw_device *cdev)
33 struct subchannel *sch;
37 sch = to_subchannel(cdev->dev.parent);
38 /* Setup sense path group id channel program. */
39 ccw = cdev->private->iccws;
40 ccw->cmd_code = CCW_CMD_SENSE_PGID;
41 ccw->cda = (__u32) __pa (&cdev->private->pgid);
42 ccw->count = sizeof (struct pgid);
43 ccw->flags = CCW_FLAG_SLI;
45 /* Reset device status. */
46 memset(&cdev->private->irb, 0, sizeof(struct irb));
47 /* Try on every path. */
49 while (cdev->private->imask != 0) {
50 /* Try every path multiple times. */
51 if (cdev->private->iretry > 0) {
52 cdev->private->iretry--;
53 ret = cio_start (sch, cdev->private->iccws,
54 cdev->private->imask);
55 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
58 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel "
59 "0.%x.%04x, lpm %02X, became 'not "
61 cdev->private->devno, sch->schid.ssid,
62 sch->schid.sch_no, cdev->private->imask);
65 cdev->private->imask >>= 1;
66 cdev->private->iretry = 5;
72 ccw_device_sense_pgid_start(struct ccw_device *cdev)
76 cdev->private->state = DEV_STATE_SENSE_PGID;
77 cdev->private->imask = 0x80;
78 cdev->private->iretry = 5;
79 memset (&cdev->private->pgid, 0, sizeof (struct pgid));
80 ret = __ccw_device_sense_pgid_start(cdev);
81 if (ret && ret != -EBUSY)
82 ccw_device_sense_pgid_done(cdev, ret);
86 * Called from interrupt context to check if a valid answer
87 * to Sense Path Group ID was received.
90 __ccw_device_check_sense_pgid(struct ccw_device *cdev)
92 struct subchannel *sch;
95 sch = to_subchannel(cdev->dev.parent);
96 irb = &cdev->private->irb;
97 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
99 if (irb->esw.esw0.erw.cons &&
100 (irb->ecw[0]&(SNS0_CMD_REJECT|SNS0_INTERVENTION_REQ))) {
102 * If the device doesn't support the Sense Path Group ID
103 * command further retries wouldn't help ...
107 if (irb->esw.esw0.erw.cons) {
108 CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, "
109 "lpum %02X, cnt %02d, sns : "
110 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
111 cdev->private->ssid, cdev->private->devno,
112 irb->esw.esw0.sublog.lpum,
113 irb->esw.esw0.erw.scnt,
114 irb->ecw[0], irb->ecw[1],
115 irb->ecw[2], irb->ecw[3],
116 irb->ecw[4], irb->ecw[5],
117 irb->ecw[6], irb->ecw[7]);
120 if (irb->scsw.cc == 3) {
121 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x,"
122 " lpm %02X, became 'not operational'\n",
123 cdev->private->devno, sch->schid.ssid,
124 sch->schid.sch_no, 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 0.%x.%04x "
129 "is reserved by someone else\n",
130 cdev->private->devno, sch->schid.ssid,
138 * Got interrupt for Sense Path Group ID.
141 ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
143 struct subchannel *sch;
147 irb = (struct irb *) __LC_IRB;
148 /* Retry sense pgid for cc=1. */
149 if (irb->scsw.stctl ==
150 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
151 if (irb->scsw.cc == 1) {
152 ret = __ccw_device_sense_pgid_start(cdev);
153 if (ret && ret != -EBUSY)
154 ccw_device_sense_pgid_done(cdev, ret);
158 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
160 sch = to_subchannel(cdev->dev.parent);
161 ret = __ccw_device_check_sense_pgid(cdev);
162 memset(&cdev->private->irb, 0, sizeof(struct irb));
164 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
165 case 0: /* Sense Path Group ID successful. */
166 if (cdev->private->pgid.inf.ps.state1 == SNID_STATE1_RESET)
167 memcpy(&cdev->private->pgid, &css[0]->global_pgid,
168 sizeof(struct pgid));
169 ccw_device_sense_pgid_done(cdev, 0);
171 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
172 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
174 case -ETIME: /* Sense path group id stopped by timeout. */
175 ccw_device_sense_pgid_done(cdev, -ETIME);
177 case -EACCES: /* channel is not operational. */
178 sch->lpm &= ~cdev->private->imask;
179 cdev->private->imask >>= 1;
180 cdev->private->iretry = 5;
182 case -EAGAIN: /* Try again. */
183 ret = __ccw_device_sense_pgid_start(cdev);
184 if (ret != 0 && ret != -EBUSY)
185 ccw_device_sense_pgid_done(cdev, -ENODEV);
187 case -EUSERS: /* device is reserved for someone else. */
188 ccw_device_sense_pgid_done(cdev, -EUSERS);
194 * Path Group ID helper function.
197 __ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
199 struct subchannel *sch;
203 sch = to_subchannel(cdev->dev.parent);
205 /* Setup sense path group id channel program. */
206 cdev->private->pgid.inf.fc = func;
207 ccw = cdev->private->iccws;
208 if (!cdev->private->flags.pgid_single) {
209 cdev->private->pgid.inf.fc |= SPID_FUNC_MULTI_PATH;
210 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
213 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
216 cdev->private->pgid.inf.fc |= SPID_FUNC_SINGLE_PATH;
218 ccw->cmd_code = CCW_CMD_SET_PGID;
219 ccw->cda = (__u32) __pa (&cdev->private->pgid);
220 ccw->count = sizeof (struct pgid);
221 ccw->flags = CCW_FLAG_SLI;
223 /* Reset device status. */
224 memset(&cdev->private->irb, 0, sizeof(struct irb));
226 /* Try multiple times. */
228 if (cdev->private->iretry > 0) {
229 cdev->private->iretry--;
230 ret = cio_start (sch, cdev->private->iccws,
231 cdev->private->imask);
232 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
233 if ((ret != -EACCES) && (ret != -ENODEV))
236 /* PGID command failed on this path. Switch it off. */
237 sch->lpm &= ~cdev->private->imask;
238 sch->vpm &= ~cdev->private->imask;
239 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
240 "0.%x.%04x, lpm %02X, became 'not operational'\n",
241 cdev->private->devno, sch->schid.ssid,
242 sch->schid.sch_no, cdev->private->imask);
247 * Called from interrupt context to check if a valid answer
248 * to Set Path Group ID was received.
251 __ccw_device_check_pgid(struct ccw_device *cdev)
253 struct subchannel *sch;
256 sch = to_subchannel(cdev->dev.parent);
257 irb = &cdev->private->irb;
258 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
260 if (irb->esw.esw0.erw.cons) {
261 if (irb->ecw[0] & SNS0_CMD_REJECT)
263 /* Hmm, whatever happened, try again. */
264 CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, "
266 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
268 cdev->private->devno, irb->esw.esw0.erw.scnt,
269 irb->ecw[0], irb->ecw[1],
270 irb->ecw[2], irb->ecw[3],
271 irb->ecw[4], irb->ecw[5],
272 irb->ecw[6], irb->ecw[7]);
275 if (irb->scsw.cc == 3) {
276 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel 0.%x.%04x,"
277 " lpm %02X, became 'not operational'\n",
278 cdev->private->devno, sch->schid.ssid,
279 sch->schid.sch_no, cdev->private->imask);
286 __ccw_device_verify_start(struct ccw_device *cdev)
288 struct subchannel *sch;
292 sch = to_subchannel(cdev->dev.parent);
293 while (sch->vpm != sch->lpm) {
294 /* Find first unequal bit in vpm vs. lpm */
295 for (imask = 0x80; imask != 0; imask >>= 1)
296 if ((sch->vpm & imask) != (sch->lpm & imask))
298 cdev->private->imask = imask;
299 func = (sch->vpm & imask) ?
300 SPID_FUNC_RESIGN : SPID_FUNC_ESTABLISH;
301 ret = __ccw_device_do_pgid(cdev, func);
302 if (ret == 0 || ret == -EBUSY)
304 cdev->private->iretry = 5;
306 ccw_device_verify_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
310 * Got interrupt for Set Path Group ID.
313 ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
315 struct subchannel *sch;
319 irb = (struct irb *) __LC_IRB;
320 /* Retry set pgid for cc=1. */
321 if (irb->scsw.stctl ==
322 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
323 if (irb->scsw.cc == 1)
324 __ccw_device_verify_start(cdev);
327 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
329 sch = to_subchannel(cdev->dev.parent);
330 ret = __ccw_device_check_pgid(cdev);
331 memset(&cdev->private->irb, 0, sizeof(struct irb));
333 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
335 /* Establish or Resign Path Group done. Update vpm. */
336 if ((sch->lpm & cdev->private->imask) != 0)
337 sch->vpm |= cdev->private->imask;
339 sch->vpm &= ~cdev->private->imask;
340 cdev->private->iretry = 5;
341 __ccw_device_verify_start(cdev);
345 * One of those strange devices which claim to be able
346 * to do multipathing but not for Set Path Group ID.
348 if (cdev->private->flags.pgid_single) {
349 ccw_device_verify_done(cdev, -EOPNOTSUPP);
352 cdev->private->flags.pgid_single = 1;
354 case -EAGAIN: /* Try again. */
355 __ccw_device_verify_start(cdev);
357 case -ETIME: /* Set path group id stopped by timeout. */
358 ccw_device_verify_done(cdev, -ETIME);
360 case -EACCES: /* channel is not operational. */
361 sch->lpm &= ~cdev->private->imask;
362 sch->vpm &= ~cdev->private->imask;
363 cdev->private->iretry = 5;
364 __ccw_device_verify_start(cdev);
370 ccw_device_verify_start(struct ccw_device *cdev)
372 struct subchannel *sch = to_subchannel(cdev->dev.parent);
374 cdev->private->flags.pgid_single = 0;
375 cdev->private->iretry = 5;
377 * Update sch->lpm with current values to catch paths becoming
380 if (stsch(sch->schid, &sch->schib)) {
381 ccw_device_verify_done(cdev, -ENODEV);
384 sch->lpm = sch->schib.pmcw.pim &
385 sch->schib.pmcw.pam &
386 sch->schib.pmcw.pom &
388 __ccw_device_verify_start(cdev);
392 __ccw_device_disband_start(struct ccw_device *cdev)
394 struct subchannel *sch;
397 sch = to_subchannel(cdev->dev.parent);
398 while (cdev->private->imask != 0) {
399 if (sch->lpm & cdev->private->imask) {
400 ret = __ccw_device_do_pgid(cdev, SPID_FUNC_DISBAND);
404 cdev->private->iretry = 5;
405 cdev->private->imask >>= 1;
407 ccw_device_disband_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
411 * Got interrupt for Unset Path Group ID.
414 ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
416 struct subchannel *sch;
420 irb = (struct irb *) __LC_IRB;
421 /* Retry set pgid for cc=1. */
422 if (irb->scsw.stctl ==
423 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
424 if (irb->scsw.cc == 1)
425 __ccw_device_disband_start(cdev);
428 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
430 sch = to_subchannel(cdev->dev.parent);
431 ret = __ccw_device_check_pgid(cdev);
432 memset(&cdev->private->irb, 0, sizeof(struct irb));
434 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
435 case 0: /* disband successful. */
437 ccw_device_disband_done(cdev, ret);
441 * One of those strange devices which claim to be able
442 * to do multipathing but not for Unset Path Group ID.
444 cdev->private->flags.pgid_single = 1;
446 case -EAGAIN: /* Try again. */
447 __ccw_device_disband_start(cdev);
449 case -ETIME: /* Set path group id stopped by timeout. */
450 ccw_device_disband_done(cdev, -ETIME);
452 case -EACCES: /* channel is not operational. */
453 cdev->private->imask >>= 1;
454 cdev->private->iretry = 5;
455 __ccw_device_disband_start(cdev);
461 ccw_device_disband_start(struct ccw_device *cdev)
463 cdev->private->flags.pgid_single = 0;
464 cdev->private->iretry = 5;
465 cdev->private->imask = 0x80;
466 __ccw_device_disband_start(cdev);