blob: 84917b39de458c66ea57225e2d60a9f590e29257 [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 Huckfb6958a2006-01-06 00:19:25 -080082 cdev->private->devno, sch->schid.ssid,
83 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 }
86 cdev->private->imask >>= 1;
87 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +020088 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
Cornelia Huck7e560812006-07-12 16:40:19 +020090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return ret;
92}
93
94void
95ccw_device_sense_pgid_start(struct ccw_device *cdev)
96{
97 int ret;
98
Cornelia Huckf1ee3282006-10-04 20:02:02 +020099 /* Set a timeout of 60s */
100 ccw_device_set_timeout(cdev, 60*HZ);
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 cdev->private->state = DEV_STATE_SENSE_PGID;
103 cdev->private->imask = 0x80;
104 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +0200105 memset (&cdev->private->pgid, 0, sizeof (cdev->private->pgid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 ret = __ccw_device_sense_pgid_start(cdev);
107 if (ret && ret != -EBUSY)
108 ccw_device_sense_pgid_done(cdev, ret);
109}
110
111/*
112 * Called from interrupt context to check if a valid answer
113 * to Sense Path Group ID was received.
114 */
115static int
116__ccw_device_check_sense_pgid(struct ccw_device *cdev)
117{
118 struct subchannel *sch;
119 struct irb *irb;
Cornelia Huck7e560812006-07-12 16:40:19 +0200120 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 sch = to_subchannel(cdev->dev.parent);
123 irb = &cdev->private->irb;
124 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
125 return -ETIME;
126 if (irb->esw.esw0.erw.cons &&
127 (irb->ecw[0]&(SNS0_CMD_REJECT|SNS0_INTERVENTION_REQ))) {
128 /*
129 * If the device doesn't support the Sense Path Group ID
130 * command further retries wouldn't help ...
131 */
132 return -EOPNOTSUPP;
133 }
134 if (irb->esw.esw0.erw.cons) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800135 CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 "lpum %02X, cnt %02d, sns : "
137 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800138 cdev->private->ssid, cdev->private->devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 irb->esw.esw0.sublog.lpum,
140 irb->esw.esw0.erw.scnt,
141 irb->ecw[0], irb->ecw[1],
142 irb->ecw[2], irb->ecw[3],
143 irb->ecw[4], irb->ecw[5],
144 irb->ecw[6], irb->ecw[7]);
145 return -EAGAIN;
146 }
147 if (irb->scsw.cc == 3) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800148 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x,"
149 " lpm %02X, became 'not operational'\n",
150 cdev->private->devno, sch->schid.ssid,
151 sch->schid.sch_no, sch->orb.lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return -EACCES;
153 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200154 i = 8 - ffs(cdev->private->imask);
155 if (cdev->private->pgid[i].inf.ps.state2 == SNID_STATE2_RESVD_ELSE) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800156 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 "is reserved by someone else\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800158 cdev->private->devno, sch->schid.ssid,
159 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return -EUSERS;
161 }
162 return 0;
163}
164
165/*
166 * Got interrupt for Sense Path Group ID.
167 */
168void
169ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
170{
171 struct subchannel *sch;
172 struct irb *irb;
173 int ret;
174
175 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (irb->scsw.stctl ==
178 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200179 if (__ccw_device_should_retry(&irb->scsw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 ret = __ccw_device_sense_pgid_start(cdev);
181 if (ret && ret != -EBUSY)
182 ccw_device_sense_pgid_done(cdev, ret);
183 }
184 return;
185 }
186 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
187 return;
188 sch = to_subchannel(cdev->dev.parent);
189 ret = __ccw_device_check_sense_pgid(cdev);
190 memset(&cdev->private->irb, 0, sizeof(struct irb));
191 switch (ret) {
192 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
194 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
195 break;
196 case -ETIME: /* Sense path group id stopped by timeout. */
197 ccw_device_sense_pgid_done(cdev, -ETIME);
198 break;
199 case -EACCES: /* channel is not operational. */
200 sch->lpm &= ~cdev->private->imask;
Cornelia Huck7e560812006-07-12 16:40:19 +0200201 /* Fall through. */
202 case 0: /* Sense Path Group ID successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 cdev->private->imask >>= 1;
204 cdev->private->iretry = 5;
205 /* Fall through. */
206 case -EAGAIN: /* Try again. */
207 ret = __ccw_device_sense_pgid_start(cdev);
208 if (ret != 0 && ret != -EBUSY)
Cornelia Huck7e560812006-07-12 16:40:19 +0200209 ccw_device_sense_pgid_done(cdev, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 case -EUSERS: /* device is reserved for someone else. */
212 ccw_device_sense_pgid_done(cdev, -EUSERS);
213 break;
214 }
215}
216
217/*
218 * Path Group ID helper function.
219 */
220static int
221__ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
222{
223 struct subchannel *sch;
224 struct ccw1 *ccw;
225 int ret;
226
227 sch = to_subchannel(cdev->dev.parent);
228
229 /* Setup sense path group id channel program. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200230 cdev->private->pgid[0].inf.fc = func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ccw = cdev->private->iccws;
232 if (!cdev->private->flags.pgid_single) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200233 cdev->private->pgid[0].inf.fc |= SPID_FUNC_MULTI_PATH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
235 ccw->cda = 0;
236 ccw->count = 0;
237 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
238 ccw++;
239 } else
Cornelia Huck7e560812006-07-12 16:40:19 +0200240 cdev->private->pgid[0].inf.fc |= SPID_FUNC_SINGLE_PATH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 ccw->cmd_code = CCW_CMD_SET_PGID;
Cornelia Huck7e560812006-07-12 16:40:19 +0200243 ccw->cda = (__u32) __pa (&cdev->private->pgid[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 ccw->count = sizeof (struct pgid);
245 ccw->flags = CCW_FLAG_SLI;
246
247 /* Reset device status. */
248 memset(&cdev->private->irb, 0, sizeof(struct irb));
249
250 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200251 ret = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (cdev->private->iretry > 0) {
253 cdev->private->iretry--;
254 ret = cio_start (sch, cdev->private->iccws,
255 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200256 /* We expect an interrupt in case of success or busy
257 * indication. */
258 if ((ret == 0) || (ret == -EBUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return ret;
260 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200261 /* PGID command failed on this path. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800263 "0.%x.%04x, lpm %02X, became 'not operational'\n",
264 cdev->private->devno, sch->schid.ssid,
265 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return ret;
267}
268
269/*
Cornelia Huck7e560812006-07-12 16:40:19 +0200270 * Helper function to send a nop ccw down a path.
271 */
272static int __ccw_device_do_nop(struct ccw_device *cdev)
273{
274 struct subchannel *sch;
275 struct ccw1 *ccw;
276 int ret;
277
278 sch = to_subchannel(cdev->dev.parent);
279
280 /* Setup nop channel program. */
281 ccw = cdev->private->iccws;
282 ccw->cmd_code = CCW_CMD_NOOP;
283 ccw->cda = 0;
284 ccw->count = 0;
285 ccw->flags = CCW_FLAG_SLI;
286
287 /* Reset device status. */
288 memset(&cdev->private->irb, 0, sizeof(struct irb));
289
290 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200291 ret = -EACCES;
Cornelia Huck7e560812006-07-12 16:40:19 +0200292 if (cdev->private->iretry > 0) {
293 cdev->private->iretry--;
294 ret = cio_start (sch, cdev->private->iccws,
295 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200296 /* We expect an interrupt in case of success or busy
297 * indication. */
298 if ((ret == 0) || (ret == -EBUSY))
Cornelia Huck7e560812006-07-12 16:40:19 +0200299 return ret;
300 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200301 /* nop command failed on this path. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200302 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel "
303 "0.%x.%04x, lpm %02X, became 'not operational'\n",
304 cdev->private->devno, sch->schid.ssid,
305 sch->schid.sch_no, cdev->private->imask);
306 return ret;
307}
308
309
310/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 * Called from interrupt context to check if a valid answer
312 * to Set Path Group ID was received.
313 */
314static int
315__ccw_device_check_pgid(struct ccw_device *cdev)
316{
317 struct subchannel *sch;
318 struct irb *irb;
319
320 sch = to_subchannel(cdev->dev.parent);
321 irb = &cdev->private->irb;
322 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
323 return -ETIME;
324 if (irb->esw.esw0.erw.cons) {
325 if (irb->ecw[0] & SNS0_CMD_REJECT)
326 return -EOPNOTSUPP;
327 /* Hmm, whatever happened, try again. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800328 CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, "
329 "cnt %02d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800331 cdev->private->ssid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 cdev->private->devno, irb->esw.esw0.erw.scnt,
333 irb->ecw[0], irb->ecw[1],
334 irb->ecw[2], irb->ecw[3],
335 irb->ecw[4], irb->ecw[5],
336 irb->ecw[6], irb->ecw[7]);
337 return -EAGAIN;
338 }
339 if (irb->scsw.cc == 3) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800340 CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel 0.%x.%04x,"
341 " lpm %02X, became 'not operational'\n",
342 cdev->private->devno, sch->schid.ssid,
343 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return -EACCES;
345 }
346 return 0;
347}
348
Cornelia Huck7e560812006-07-12 16:40:19 +0200349/*
350 * Called from interrupt context to check the path status after a nop has
351 * been send.
352 */
353static int __ccw_device_check_nop(struct ccw_device *cdev)
354{
355 struct subchannel *sch;
356 struct irb *irb;
357
358 sch = to_subchannel(cdev->dev.parent);
359 irb = &cdev->private->irb;
360 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
361 return -ETIME;
362 if (irb->scsw.cc == 3) {
363 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel 0.%x.%04x,"
364 " lpm %02X, became 'not operational'\n",
365 cdev->private->devno, sch->schid.ssid,
366 sch->schid.sch_no, cdev->private->imask);
367 return -EACCES;
368 }
369 return 0;
370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372static void
373__ccw_device_verify_start(struct ccw_device *cdev)
374{
375 struct subchannel *sch;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200376 __u8 func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 int ret;
378
379 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200380 /* Repeat for all paths. */
381 for (; cdev->private->imask; cdev->private->imask >>= 1,
382 cdev->private->iretry = 5) {
383 if ((cdev->private->imask & sch->schib.pmcw.pam) == 0)
384 /* Path not available, try next. */
385 continue;
Cornelia Huck7e560812006-07-12 16:40:19 +0200386 if (cdev->private->options.pgroup) {
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200387 if (sch->opm & cdev->private->imask)
388 func = SPID_FUNC_ESTABLISH;
389 else
390 func = SPID_FUNC_RESIGN;
Cornelia Huck7e560812006-07-12 16:40:19 +0200391 ret = __ccw_device_do_pgid(cdev, func);
392 } else
393 ret = __ccw_device_do_nop(cdev);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200394 /* We expect an interrupt in case of success or busy
395 * indication. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (ret == 0 || ret == -EBUSY)
397 return;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200398 /* Permanent path failure, try next. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200400 /* Done with all paths. */
401 ccw_device_verify_done(cdev, (sch->vpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
404/*
405 * Got interrupt for Set Path Group ID.
406 */
407void
408ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
409{
410 struct subchannel *sch;
411 struct irb *irb;
412 int ret;
413
414 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (irb->scsw.stctl ==
417 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200418 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 __ccw_device_verify_start(cdev);
420 return;
421 }
422 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
423 return;
424 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck7e560812006-07-12 16:40:19 +0200425 if (cdev->private->options.pgroup)
426 ret = __ccw_device_check_pgid(cdev);
427 else
428 ret = __ccw_device_check_nop(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 memset(&cdev->private->irb, 0, sizeof(struct irb));
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 switch (ret) {
432 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
433 case 0:
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200434 /* Path verification ccw finished successfully, update lpm. */
435 sch->vpm |= sch->opm & cdev->private->imask;
436 /* Go on with next path. */
437 cdev->private->imask >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 cdev->private->iretry = 5;
439 __ccw_device_verify_start(cdev);
440 break;
441 case -EOPNOTSUPP:
442 /*
443 * One of those strange devices which claim to be able
444 * to do multipathing but not for Set Path Group ID.
445 */
Cornelia Huck7e560812006-07-12 16:40:19 +0200446 if (cdev->private->flags.pgid_single)
447 cdev->private->options.pgroup = 0;
448 else
449 cdev->private->flags.pgid_single = 1;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200450 /* Retry */
451 sch->vpm = 0;
452 cdev->private->imask = 0x80;
453 cdev->private->iretry = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 /* fall through. */
455 case -EAGAIN: /* Try again. */
456 __ccw_device_verify_start(cdev);
457 break;
458 case -ETIME: /* Set path group id stopped by timeout. */
459 ccw_device_verify_done(cdev, -ETIME);
460 break;
461 case -EACCES: /* channel is not operational. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200462 cdev->private->imask >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 cdev->private->iretry = 5;
464 __ccw_device_verify_start(cdev);
465 break;
466 }
467}
468
469void
470ccw_device_verify_start(struct ccw_device *cdev)
471{
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800472 struct subchannel *sch = to_subchannel(cdev->dev.parent);
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 cdev->private->flags.pgid_single = 0;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200475 cdev->private->imask = 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 cdev->private->iretry = 5;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200477
478 /* Start with empty vpm. */
479 sch->vpm = 0;
480
481 /* Get current pam. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800482 if (stsch(sch->schid, &sch->schib)) {
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800483 ccw_device_verify_done(cdev, -ENODEV);
484 return;
485 }
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200486 /* After 60s path verification is considered to have failed. */
487 ccw_device_set_timeout(cdev, 60*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 __ccw_device_verify_start(cdev);
489}
490
491static void
492__ccw_device_disband_start(struct ccw_device *cdev)
493{
494 struct subchannel *sch;
495 int ret;
496
497 sch = to_subchannel(cdev->dev.parent);
498 while (cdev->private->imask != 0) {
499 if (sch->lpm & cdev->private->imask) {
500 ret = __ccw_device_do_pgid(cdev, SPID_FUNC_DISBAND);
501 if (ret == 0)
502 return;
503 }
504 cdev->private->iretry = 5;
505 cdev->private->imask >>= 1;
506 }
Cornelia Huck6d751c42006-02-17 13:52:45 -0800507 ccw_device_disband_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
510/*
511 * Got interrupt for Unset Path Group ID.
512 */
513void
514ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
515{
516 struct subchannel *sch;
517 struct irb *irb;
518 int ret;
519
520 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (irb->scsw.stctl ==
523 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200524 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 __ccw_device_disband_start(cdev);
526 return;
527 }
528 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
529 return;
530 sch = to_subchannel(cdev->dev.parent);
531 ret = __ccw_device_check_pgid(cdev);
532 memset(&cdev->private->irb, 0, sizeof(struct irb));
533 switch (ret) {
534 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
535 case 0: /* disband successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 ccw_device_disband_done(cdev, ret);
537 break;
538 case -EOPNOTSUPP:
539 /*
540 * One of those strange devices which claim to be able
541 * to do multipathing but not for Unset Path Group ID.
542 */
543 cdev->private->flags.pgid_single = 1;
544 /* fall through. */
545 case -EAGAIN: /* Try again. */
546 __ccw_device_disband_start(cdev);
547 break;
548 case -ETIME: /* Set path group id stopped by timeout. */
549 ccw_device_disband_done(cdev, -ETIME);
550 break;
551 case -EACCES: /* channel is not operational. */
552 cdev->private->imask >>= 1;
553 cdev->private->iretry = 5;
554 __ccw_device_disband_start(cdev);
555 break;
556 }
557}
558
559void
560ccw_device_disband_start(struct ccw_device *cdev)
561{
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200562 /* After 60s disbanding is considered to have failed. */
563 ccw_device_set_timeout(cdev, 60*HZ);
564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 cdev->private->flags.pgid_single = 0;
566 cdev->private->iretry = 5;
567 cdev->private->imask = 0x80;
568 __ccw_device_disband_start(cdev);
569}