blob: 2975ce888c19ca3c2dc2b7fcf32ba79442323a46 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/device_pgid.c
3 *
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
5 * IBM Corporation
Cornelia Huck4ce3b302006-01-14 13:21:04 -08006 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 *
9 * Path Group ID functions.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/init.h>
14
15#include <asm/ccwdev.h>
16#include <asm/cio.h>
17#include <asm/delay.h>
18#include <asm/lowcore.h>
19
20#include "cio.h"
21#include "cio_debug.h"
22#include "css.h"
23#include "device.h"
Cornelia Huck6810a2b2006-01-06 00:19:13 -080024#include "ioasm.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26/*
Stefan Bader7b7db1b2006-08-30 14:33:39 +020027 * Helper function called from interrupt context to decide whether an
28 * operation should be tried again.
29 */
30static int __ccw_device_should_retry(struct scsw *scsw)
31{
32 /* CC is only valid if start function bit is set. */
33 if ((scsw->fctl & SCSW_FCTL_START_FUNC) && scsw->cc == 1)
34 return 1;
35 /* No more activity. For sense and set PGID we stubbornly try again. */
36 if (!scsw->actl)
37 return 1;
38 return 0;
39}
40
41/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 * Start Sense Path Group ID helper function. Used in ccw_device_recog
43 * and ccw_device_sense_pgid.
44 */
45static int
46__ccw_device_sense_pgid_start(struct ccw_device *cdev)
47{
48 struct subchannel *sch;
49 struct ccw1 *ccw;
50 int ret;
Cornelia Huck7e560812006-07-12 16:40:19 +020051 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck7e560812006-07-12 16:40:19 +020054 /* 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);
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /* Setup sense path group id channel program. */
60 ccw = cdev->private->iccws;
61 ccw->cmd_code = CCW_CMD_SENSE_PGID;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 ccw->count = sizeof (struct pgid);
63 ccw->flags = CCW_FLAG_SLI;
64
65 /* Reset device status. */
66 memset(&cdev->private->irb, 0, sizeof(struct irb));
67 /* Try on every path. */
68 ret = -ENODEV;
69 while (cdev->private->imask != 0) {
70 /* Try every path multiple times. */
Cornelia Huck7e560812006-07-12 16:40:19 +020071 ccw->cda = (__u32) __pa (&cdev->private->pgid[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 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 */
77 if (ret != -EACCES)
78 return ret;
79 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel "
Cornelia Huckfb6958a2006-01-06 00:19:25 -080080 "0.%x.%04x, lpm %02X, became 'not "
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 "operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +020082 cdev->private->dev_id.devno,
83 sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -080084 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 }
87 cdev->private->imask >>= 1;
88 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +020089 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
Cornelia Huck7e560812006-07-12 16:40:19 +020091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return ret;
93}
94
95void
96ccw_device_sense_pgid_start(struct ccw_device *cdev)
97{
98 int ret;
99
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200100 /* Set a timeout of 60s */
101 ccw_device_set_timeout(cdev, 60*HZ);
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 cdev->private->state = DEV_STATE_SENSE_PGID;
104 cdev->private->imask = 0x80;
105 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +0200106 memset (&cdev->private->pgid, 0, sizeof (cdev->private->pgid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 ret = __ccw_device_sense_pgid_start(cdev);
108 if (ret && ret != -EBUSY)
109 ccw_device_sense_pgid_done(cdev, ret);
110}
111
112/*
113 * Called from interrupt context to check if a valid answer
114 * to Sense Path Group ID was received.
115 */
116static int
117__ccw_device_check_sense_pgid(struct ccw_device *cdev)
118{
119 struct subchannel *sch;
120 struct irb *irb;
Cornelia Huck7e560812006-07-12 16:40:19 +0200121 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
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))
126 return -ETIME;
127 if (irb->esw.esw0.erw.cons &&
128 (irb->ecw[0]&(SNS0_CMD_REJECT|SNS0_INTERVENTION_REQ))) {
129 /*
130 * If the device doesn't support the Sense Path Group ID
131 * command further retries wouldn't help ...
132 */
133 return -EOPNOTSUPP;
134 }
135 if (irb->esw.esw0.erw.cons) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800136 CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 "lpum %02X, cnt %02d, sns : "
138 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200139 cdev->private->dev_id.ssid,
140 cdev->private->dev_id.devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 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]);
147 return -EAGAIN;
148 }
149 if (irb->scsw.cc == 3) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800150 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x,"
151 " lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200152 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800153 sch->schid.sch_no, sch->orb.lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return -EACCES;
155 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200156 i = 8 - ffs(cdev->private->imask);
157 if (cdev->private->pgid[i].inf.ps.state2 == SNID_STATE2_RESVD_ELSE) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800158 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 "is reserved by someone else\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200160 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800161 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return -EUSERS;
163 }
164 return 0;
165}
166
167/*
168 * Got interrupt for Sense Path Group ID.
169 */
170void
171ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
172{
173 struct subchannel *sch;
174 struct irb *irb;
175 int ret;
176
177 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (irb->scsw.stctl ==
180 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200181 if (__ccw_device_should_retry(&irb->scsw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 ret = __ccw_device_sense_pgid_start(cdev);
183 if (ret && ret != -EBUSY)
184 ccw_device_sense_pgid_done(cdev, ret);
185 }
186 return;
187 }
188 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
189 return;
190 sch = to_subchannel(cdev->dev.parent);
191 ret = __ccw_device_check_sense_pgid(cdev);
192 memset(&cdev->private->irb, 0, sizeof(struct irb));
193 switch (ret) {
194 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
196 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
197 break;
198 case -ETIME: /* Sense path group id stopped by timeout. */
199 ccw_device_sense_pgid_done(cdev, -ETIME);
200 break;
201 case -EACCES: /* channel is not operational. */
202 sch->lpm &= ~cdev->private->imask;
Cornelia Huck7e560812006-07-12 16:40:19 +0200203 /* Fall through. */
204 case 0: /* Sense Path Group ID successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 cdev->private->imask >>= 1;
206 cdev->private->iretry = 5;
207 /* Fall through. */
208 case -EAGAIN: /* Try again. */
209 ret = __ccw_device_sense_pgid_start(cdev);
210 if (ret != 0 && ret != -EBUSY)
Cornelia Huck7e560812006-07-12 16:40:19 +0200211 ccw_device_sense_pgid_done(cdev, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 break;
213 case -EUSERS: /* device is reserved for someone else. */
214 ccw_device_sense_pgid_done(cdev, -EUSERS);
215 break;
216 }
217}
218
219/*
220 * Path Group ID helper function.
221 */
222static int
223__ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
224{
225 struct subchannel *sch;
226 struct ccw1 *ccw;
227 int ret;
228
229 sch = to_subchannel(cdev->dev.parent);
230
231 /* Setup sense path group id channel program. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200232 cdev->private->pgid[0].inf.fc = func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 ccw = cdev->private->iccws;
234 if (!cdev->private->flags.pgid_single) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200235 cdev->private->pgid[0].inf.fc |= SPID_FUNC_MULTI_PATH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
237 ccw->cda = 0;
238 ccw->count = 0;
239 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
240 ccw++;
241 } else
Cornelia Huck7e560812006-07-12 16:40:19 +0200242 cdev->private->pgid[0].inf.fc |= SPID_FUNC_SINGLE_PATH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 ccw->cmd_code = CCW_CMD_SET_PGID;
Cornelia Huck7e560812006-07-12 16:40:19 +0200245 ccw->cda = (__u32) __pa (&cdev->private->pgid[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 ccw->count = sizeof (struct pgid);
247 ccw->flags = CCW_FLAG_SLI;
248
249 /* Reset device status. */
250 memset(&cdev->private->irb, 0, sizeof(struct irb));
251
252 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200253 ret = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 if (cdev->private->iretry > 0) {
255 cdev->private->iretry--;
256 ret = cio_start (sch, cdev->private->iccws,
257 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200258 /* We expect an interrupt in case of success or busy
259 * indication. */
260 if ((ret == 0) || (ret == -EBUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return ret;
262 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200263 /* PGID command failed on this path. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800265 "0.%x.%04x, lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200266 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800267 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return ret;
269}
270
271/*
Cornelia Huck7e560812006-07-12 16:40:19 +0200272 * Helper function to send a nop ccw down a path.
273 */
274static int __ccw_device_do_nop(struct ccw_device *cdev)
275{
276 struct subchannel *sch;
277 struct ccw1 *ccw;
278 int ret;
279
280 sch = to_subchannel(cdev->dev.parent);
281
282 /* Setup nop channel program. */
283 ccw = cdev->private->iccws;
284 ccw->cmd_code = CCW_CMD_NOOP;
285 ccw->cda = 0;
286 ccw->count = 0;
287 ccw->flags = CCW_FLAG_SLI;
288
289 /* Reset device status. */
290 memset(&cdev->private->irb, 0, sizeof(struct irb));
291
292 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200293 ret = -EACCES;
Cornelia Huck7e560812006-07-12 16:40:19 +0200294 if (cdev->private->iretry > 0) {
295 cdev->private->iretry--;
296 ret = cio_start (sch, cdev->private->iccws,
297 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200298 /* We expect an interrupt in case of success or busy
299 * indication. */
300 if ((ret == 0) || (ret == -EBUSY))
Cornelia Huck7e560812006-07-12 16:40:19 +0200301 return ret;
302 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200303 /* nop command failed on this path. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200304 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel "
305 "0.%x.%04x, lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200306 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huck7e560812006-07-12 16:40:19 +0200307 sch->schid.sch_no, cdev->private->imask);
308 return ret;
309}
310
311
312/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 * Called from interrupt context to check if a valid answer
314 * to Set Path Group ID was received.
315 */
316static int
317__ccw_device_check_pgid(struct ccw_device *cdev)
318{
319 struct subchannel *sch;
320 struct irb *irb;
321
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))
325 return -ETIME;
326 if (irb->esw.esw0.erw.cons) {
327 if (irb->ecw[0] & SNS0_CMD_REJECT)
328 return -EOPNOTSUPP;
329 /* Hmm, whatever happened, try again. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800330 CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, "
331 "cnt %02d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200333 cdev->private->dev_id.ssid,
334 cdev->private->dev_id.devno,
335 irb->esw.esw0.erw.scnt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 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]);
340 return -EAGAIN;
341 }
342 if (irb->scsw.cc == 3) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800343 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel 0.%x.%04x,"
344 " lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200345 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800346 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return -EACCES;
348 }
349 return 0;
350}
351
Cornelia Huck7e560812006-07-12 16:40:19 +0200352/*
353 * Called from interrupt context to check the path status after a nop has
354 * been send.
355 */
356static int __ccw_device_check_nop(struct ccw_device *cdev)
357{
358 struct subchannel *sch;
359 struct irb *irb;
360
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))
364 return -ETIME;
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",
Cornelia Huck78964262006-10-11 15:31:38 +0200368 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huck7e560812006-07-12 16:40:19 +0200369 sch->schid.sch_no, cdev->private->imask);
370 return -EACCES;
371 }
372 return 0;
373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375static void
376__ccw_device_verify_start(struct ccw_device *cdev)
377{
378 struct subchannel *sch;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200379 __u8 func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 int ret;
381
382 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200383 /* 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. */
388 continue;
Cornelia Huck7e560812006-07-12 16:40:19 +0200389 if (cdev->private->options.pgroup) {
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200390 if (sch->opm & cdev->private->imask)
391 func = SPID_FUNC_ESTABLISH;
392 else
393 func = SPID_FUNC_RESIGN;
Cornelia Huck7e560812006-07-12 16:40:19 +0200394 ret = __ccw_device_do_pgid(cdev, func);
395 } else
396 ret = __ccw_device_do_nop(cdev);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200397 /* We expect an interrupt in case of success or busy
398 * indication. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (ret == 0 || ret == -EBUSY)
400 return;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200401 /* Permanent path failure, try next. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200403 /* Done with all paths. */
404 ccw_device_verify_done(cdev, (sch->vpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
407/*
408 * Got interrupt for Set Path Group ID.
409 */
410void
411ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
412{
413 struct subchannel *sch;
414 struct irb *irb;
415 int ret;
416
417 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (irb->scsw.stctl ==
420 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200421 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 __ccw_device_verify_start(cdev);
423 return;
424 }
425 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
426 return;
427 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck7e560812006-07-12 16:40:19 +0200428 if (cdev->private->options.pgroup)
429 ret = __ccw_device_check_pgid(cdev);
430 else
431 ret = __ccw_device_check_nop(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 memset(&cdev->private->irb, 0, sizeof(struct irb));
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 switch (ret) {
435 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
436 case 0:
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200437 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 cdev->private->iretry = 5;
442 __ccw_device_verify_start(cdev);
443 break;
444 case -EOPNOTSUPP:
445 /*
446 * One of those strange devices which claim to be able
447 * to do multipathing but not for Set Path Group ID.
448 */
Cornelia Huck7e560812006-07-12 16:40:19 +0200449 if (cdev->private->flags.pgid_single)
450 cdev->private->options.pgroup = 0;
451 else
452 cdev->private->flags.pgid_single = 1;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200453 /* Retry */
454 sch->vpm = 0;
455 cdev->private->imask = 0x80;
456 cdev->private->iretry = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /* fall through. */
458 case -EAGAIN: /* Try again. */
459 __ccw_device_verify_start(cdev);
460 break;
461 case -ETIME: /* Set path group id stopped by timeout. */
462 ccw_device_verify_done(cdev, -ETIME);
463 break;
464 case -EACCES: /* channel is not operational. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200465 cdev->private->imask >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 cdev->private->iretry = 5;
467 __ccw_device_verify_start(cdev);
468 break;
469 }
470}
471
472void
473ccw_device_verify_start(struct ccw_device *cdev)
474{
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800475 struct subchannel *sch = to_subchannel(cdev->dev.parent);
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 cdev->private->flags.pgid_single = 0;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200478 cdev->private->imask = 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 cdev->private->iretry = 5;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200480
481 /* Start with empty vpm. */
482 sch->vpm = 0;
483
484 /* Get current pam. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800485 if (stsch(sch->schid, &sch->schib)) {
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800486 ccw_device_verify_done(cdev, -ENODEV);
487 return;
488 }
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200489 /* After 60s path verification is considered to have failed. */
490 ccw_device_set_timeout(cdev, 60*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 __ccw_device_verify_start(cdev);
492}
493
494static void
495__ccw_device_disband_start(struct ccw_device *cdev)
496{
497 struct subchannel *sch;
498 int ret;
499
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);
504 if (ret == 0)
505 return;
506 }
507 cdev->private->iretry = 5;
508 cdev->private->imask >>= 1;
509 }
Cornelia Huck6d751c42006-02-17 13:52:45 -0800510 ccw_device_disband_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
513/*
514 * Got interrupt for Unset Path Group ID.
515 */
516void
517ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
518{
519 struct subchannel *sch;
520 struct irb *irb;
521 int ret;
522
523 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (irb->scsw.stctl ==
526 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200527 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 __ccw_device_disband_start(cdev);
529 return;
530 }
531 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
532 return;
533 sch = to_subchannel(cdev->dev.parent);
534 ret = __ccw_device_check_pgid(cdev);
535 memset(&cdev->private->irb, 0, sizeof(struct irb));
536 switch (ret) {
537 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
538 case 0: /* disband successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 ccw_device_disband_done(cdev, ret);
540 break;
541 case -EOPNOTSUPP:
542 /*
543 * One of those strange devices which claim to be able
544 * to do multipathing but not for Unset Path Group ID.
545 */
546 cdev->private->flags.pgid_single = 1;
547 /* fall through. */
548 case -EAGAIN: /* Try again. */
549 __ccw_device_disband_start(cdev);
550 break;
551 case -ETIME: /* Set path group id stopped by timeout. */
552 ccw_device_disband_done(cdev, -ETIME);
553 break;
554 case -EACCES: /* channel is not operational. */
555 cdev->private->imask >>= 1;
556 cdev->private->iretry = 5;
557 __ccw_device_disband_start(cdev);
558 break;
559 }
560}
561
562void
563ccw_device_disband_start(struct ccw_device *cdev)
564{
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200565 /* After 60s disbanding is considered to have failed. */
566 ccw_device_set_timeout(cdev, 60*HZ);
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 cdev->private->flags.pgid_single = 0;
569 cdev->private->iretry = 5;
570 cdev->private->imask = 0x80;
571 __ccw_device_disband_start(cdev);
572}