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"
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 "%04x, lpm %02X, became 'not "
61 cdev->private->devno, sch->irq,
62 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 %04x, unit check, "
109 "lpum %02X, cnt %02d, sns : "
110 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
111 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 "
122 "%04x, lpm %02X, became 'not operational'\n",
123 cdev->private->devno, sch->irq, sch->orb.lpm);
126 if (cdev->private->pgid.inf.ps.state2 == SNID_STATE2_RESVD_ELSE) {
127 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel %04x "
128 "is reserved by someone else\n",
129 cdev->private->devno, sch->irq);
136 * Got interrupt for Sense Path Group ID.
139 ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
141 struct subchannel *sch;
145 irb = (struct irb *) __LC_IRB;
146 /* Retry sense pgid for cc=1. */
147 if (irb->scsw.stctl ==
148 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
149 if (irb->scsw.cc == 1) {
150 ret = __ccw_device_sense_pgid_start(cdev);
151 if (ret && ret != -EBUSY)
152 ccw_device_sense_pgid_done(cdev, ret);
156 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
158 sch = to_subchannel(cdev->dev.parent);
159 ret = __ccw_device_check_sense_pgid(cdev);
160 memset(&cdev->private->irb, 0, sizeof(struct irb));
162 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
163 case 0: /* Sense Path Group ID successful. */
164 if (cdev->private->pgid.inf.ps.state1 == SNID_STATE1_RESET)
165 memcpy(&cdev->private->pgid, &global_pgid,
166 sizeof(struct pgid));
167 ccw_device_sense_pgid_done(cdev, 0);
169 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
170 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
172 case -ETIME: /* Sense path group id stopped by timeout. */
173 ccw_device_sense_pgid_done(cdev, -ETIME);
175 case -EACCES: /* channel is not operational. */
176 sch->lpm &= ~cdev->private->imask;
177 cdev->private->imask >>= 1;
178 cdev->private->iretry = 5;
180 case -EAGAIN: /* Try again. */
181 ret = __ccw_device_sense_pgid_start(cdev);
182 if (ret != 0 && ret != -EBUSY)
183 ccw_device_sense_pgid_done(cdev, -ENODEV);
185 case -EUSERS: /* device is reserved for someone else. */
186 ccw_device_sense_pgid_done(cdev, -EUSERS);
192 * Path Group ID helper function.
195 __ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
197 struct subchannel *sch;
201 sch = to_subchannel(cdev->dev.parent);
203 /* Setup sense path group id channel program. */
204 cdev->private->pgid.inf.fc = func;
205 ccw = cdev->private->iccws;
206 if (!cdev->private->flags.pgid_single) {
207 cdev->private->pgid.inf.fc |= SPID_FUNC_MULTI_PATH;
208 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
211 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
214 cdev->private->pgid.inf.fc |= SPID_FUNC_SINGLE_PATH;
216 ccw->cmd_code = CCW_CMD_SET_PGID;
217 ccw->cda = (__u32) __pa (&cdev->private->pgid);
218 ccw->count = sizeof (struct pgid);
219 ccw->flags = CCW_FLAG_SLI;
221 /* Reset device status. */
222 memset(&cdev->private->irb, 0, sizeof(struct irb));
224 /* Try multiple times. */
226 if (cdev->private->iretry > 0) {
227 cdev->private->iretry--;
228 ret = cio_start (sch, cdev->private->iccws,
229 cdev->private->imask);
230 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
231 if ((ret != -EACCES) && (ret != -ENODEV))
234 /* PGID command failed on this path. Switch it off. */
235 sch->lpm &= ~cdev->private->imask;
236 sch->vpm &= ~cdev->private->imask;
237 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
238 "%04x, lpm %02X, became 'not operational'\n",
239 cdev->private->devno, sch->irq, cdev->private->imask);
244 * Called from interrupt context to check if a valid answer
245 * to Set Path Group ID was received.
248 __ccw_device_check_pgid(struct ccw_device *cdev)
250 struct subchannel *sch;
253 sch = to_subchannel(cdev->dev.parent);
254 irb = &cdev->private->irb;
255 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
257 if (irb->esw.esw0.erw.cons) {
258 if (irb->ecw[0] & SNS0_CMD_REJECT)
260 /* Hmm, whatever happened, try again. */
261 CIO_MSG_EVENT(2, "SPID - device %04x, unit check, cnt %02d, "
262 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
263 cdev->private->devno, irb->esw.esw0.erw.scnt,
264 irb->ecw[0], irb->ecw[1],
265 irb->ecw[2], irb->ecw[3],
266 irb->ecw[4], irb->ecw[5],
267 irb->ecw[6], irb->ecw[7]);
270 if (irb->scsw.cc == 3) {
271 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
272 "%04x, lpm %02X, became 'not operational'\n",
273 cdev->private->devno, sch->irq,
274 cdev->private->imask);
281 __ccw_device_verify_start(struct ccw_device *cdev)
283 struct subchannel *sch;
287 sch = to_subchannel(cdev->dev.parent);
288 while (sch->vpm != sch->lpm) {
289 /* Find first unequal bit in vpm vs. lpm */
290 for (imask = 0x80; imask != 0; imask >>= 1)
291 if ((sch->vpm & imask) != (sch->lpm & imask))
293 cdev->private->imask = imask;
294 func = (sch->vpm & imask) ?
295 SPID_FUNC_RESIGN : SPID_FUNC_ESTABLISH;
296 ret = __ccw_device_do_pgid(cdev, func);
297 if (ret == 0 || ret == -EBUSY)
299 cdev->private->iretry = 5;
301 ccw_device_verify_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
305 * Got interrupt for Set Path Group ID.
308 ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
310 struct subchannel *sch;
314 irb = (struct irb *) __LC_IRB;
315 /* Retry set pgid for cc=1. */
316 if (irb->scsw.stctl ==
317 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
318 if (irb->scsw.cc == 1)
319 __ccw_device_verify_start(cdev);
322 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
324 sch = to_subchannel(cdev->dev.parent);
325 ret = __ccw_device_check_pgid(cdev);
326 memset(&cdev->private->irb, 0, sizeof(struct irb));
328 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
330 /* Establish or Resign Path Group done. Update vpm. */
331 if ((sch->lpm & cdev->private->imask) != 0)
332 sch->vpm |= cdev->private->imask;
334 sch->vpm &= ~cdev->private->imask;
335 cdev->private->iretry = 5;
336 __ccw_device_verify_start(cdev);
340 * One of those strange devices which claim to be able
341 * to do multipathing but not for Set Path Group ID.
343 if (cdev->private->flags.pgid_single) {
344 ccw_device_verify_done(cdev, -EOPNOTSUPP);
347 cdev->private->flags.pgid_single = 1;
349 case -EAGAIN: /* Try again. */
350 __ccw_device_verify_start(cdev);
352 case -ETIME: /* Set path group id stopped by timeout. */
353 ccw_device_verify_done(cdev, -ETIME);
355 case -EACCES: /* channel is not operational. */
356 sch->lpm &= ~cdev->private->imask;
357 sch->vpm &= ~cdev->private->imask;
358 cdev->private->iretry = 5;
359 __ccw_device_verify_start(cdev);
365 ccw_device_verify_start(struct ccw_device *cdev)
367 cdev->private->flags.pgid_single = 0;
368 cdev->private->iretry = 5;
369 __ccw_device_verify_start(cdev);
373 __ccw_device_disband_start(struct ccw_device *cdev)
375 struct subchannel *sch;
378 sch = to_subchannel(cdev->dev.parent);
379 while (cdev->private->imask != 0) {
380 if (sch->lpm & cdev->private->imask) {
381 ret = __ccw_device_do_pgid(cdev, SPID_FUNC_DISBAND);
385 cdev->private->iretry = 5;
386 cdev->private->imask >>= 1;
388 ccw_device_verify_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
392 * Got interrupt for Unset Path Group ID.
395 ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
397 struct subchannel *sch;
401 irb = (struct irb *) __LC_IRB;
402 /* Retry set pgid for cc=1. */
403 if (irb->scsw.stctl ==
404 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
405 if (irb->scsw.cc == 1)
406 __ccw_device_disband_start(cdev);
409 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
411 sch = to_subchannel(cdev->dev.parent);
412 ret = __ccw_device_check_pgid(cdev);
413 memset(&cdev->private->irb, 0, sizeof(struct irb));
415 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
416 case 0: /* disband successful. */
418 ccw_device_disband_done(cdev, ret);
422 * One of those strange devices which claim to be able
423 * to do multipathing but not for Unset Path Group ID.
425 cdev->private->flags.pgid_single = 1;
427 case -EAGAIN: /* Try again. */
428 __ccw_device_disband_start(cdev);
430 case -ETIME: /* Set path group id stopped by timeout. */
431 ccw_device_disband_done(cdev, -ETIME);
433 case -EACCES: /* channel is not operational. */
434 cdev->private->imask >>= 1;
435 cdev->private->iretry = 5;
436 __ccw_device_disband_start(cdev);
442 ccw_device_disband_start(struct ccw_device *cdev)
444 cdev->private->flags.pgid_single = 0;
445 cdev->private->iretry = 5;
446 cdev->private->imask = 0x80;
447 __ccw_device_disband_start(cdev);