blob: fc5ca1dd52b39dfd4fd3727e40598228479c7ec9 [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"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010025#include "io_sch.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
Stefan Bader7b7db1b2006-08-30 14:33:39 +020028 * Helper function called from interrupt context to decide whether an
29 * operation should be tried again.
30 */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +020031static int __ccw_device_should_retry(union scsw *scsw)
Stefan Bader7b7db1b2006-08-30 14:33:39 +020032{
33 /* CC is only valid if start function bit is set. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +020034 if ((scsw->cmd.fctl & SCSW_FCTL_START_FUNC) && scsw->cmd.cc == 1)
Stefan Bader7b7db1b2006-08-30 14:33:39 +020035 return 1;
36 /* No more activity. For sense and set PGID we stubbornly try again. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +020037 if (!scsw->cmd.actl)
Stefan Bader7b7db1b2006-08-30 14:33:39 +020038 return 1;
39 return 0;
40}
41
42/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * Start Sense Path Group ID helper function. Used in ccw_device_recog
44 * and ccw_device_sense_pgid.
45 */
46static int
47__ccw_device_sense_pgid_start(struct ccw_device *cdev)
48{
49 struct subchannel *sch;
50 struct ccw1 *ccw;
51 int ret;
Cornelia Huck7e560812006-07-12 16:40:19 +020052 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck7e560812006-07-12 16:40:19 +020055 /* Return if we already checked on all paths. */
56 if (cdev->private->imask == 0)
57 return (sch->lpm == 0) ? -ENODEV : -EACCES;
58 i = 8 - ffs(cdev->private->imask);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /* Setup sense path group id channel program. */
61 ccw = cdev->private->iccws;
62 ccw->cmd_code = CCW_CMD_SENSE_PGID;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 ccw->count = sizeof (struct pgid);
64 ccw->flags = CCW_FLAG_SLI;
65
66 /* Reset device status. */
67 memset(&cdev->private->irb, 0, sizeof(struct irb));
68 /* Try on every path. */
69 ret = -ENODEV;
70 while (cdev->private->imask != 0) {
71 /* Try every path multiple times. */
Cornelia Huck7e560812006-07-12 16:40:19 +020072 ccw->cda = (__u32) __pa (&cdev->private->pgid[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (cdev->private->iretry > 0) {
74 cdev->private->iretry--;
Cornelia Huckd23861f2006-12-04 15:41:04 +010075 /* Reset internal retry indication. */
76 cdev->private->flags.intretry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 ret = cio_start (sch, cdev->private->iccws,
78 cdev->private->imask);
79 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
80 if (ret != -EACCES)
81 return ret;
Michael Ernst139b83d2008-05-07 09:22:54 +020082 CIO_MSG_EVENT(3, "SNID - Device %04x on Subchannel "
Cornelia Huckfb6958a2006-01-06 00:19:25 -080083 "0.%x.%04x, lpm %02X, became 'not "
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 "operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +020085 cdev->private->dev_id.devno,
86 sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -080087 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 }
90 cdev->private->imask >>= 1;
91 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +020092 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
Cornelia Huck7e560812006-07-12 16:40:19 +020094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return ret;
96}
97
98void
99ccw_device_sense_pgid_start(struct ccw_device *cdev)
100{
101 int ret;
102
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200103 /* Set a timeout of 60s */
104 ccw_device_set_timeout(cdev, 60*HZ);
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 cdev->private->state = DEV_STATE_SENSE_PGID;
107 cdev->private->imask = 0x80;
108 cdev->private->iretry = 5;
Cornelia Huck7e560812006-07-12 16:40:19 +0200109 memset (&cdev->private->pgid, 0, sizeof (cdev->private->pgid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 ret = __ccw_device_sense_pgid_start(cdev);
111 if (ret && ret != -EBUSY)
112 ccw_device_sense_pgid_done(cdev, ret);
113}
114
115/*
116 * Called from interrupt context to check if a valid answer
117 * to Sense Path Group ID was received.
118 */
119static int
120__ccw_device_check_sense_pgid(struct ccw_device *cdev)
121{
122 struct subchannel *sch;
123 struct irb *irb;
Cornelia Huck7e560812006-07-12 16:40:19 +0200124 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 sch = to_subchannel(cdev->dev.parent);
127 irb = &cdev->private->irb;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200128 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
Cornelia Huckd23861f2006-12-04 15:41:04 +0100129 /* Retry Sense PGID if requested. */
130 if (cdev->private->flags.intretry) {
131 cdev->private->flags.intretry = 0;
132 return -EAGAIN;
133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return -ETIME;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (irb->esw.esw0.erw.cons &&
137 (irb->ecw[0]&(SNS0_CMD_REJECT|SNS0_INTERVENTION_REQ))) {
138 /*
139 * If the device doesn't support the Sense Path Group ID
140 * command further retries wouldn't help ...
141 */
142 return -EOPNOTSUPP;
143 }
144 if (irb->esw.esw0.erw.cons) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800145 CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 "lpum %02X, cnt %02d, sns : "
147 "%02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200148 cdev->private->dev_id.ssid,
149 cdev->private->dev_id.devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 irb->esw.esw0.sublog.lpum,
151 irb->esw.esw0.erw.scnt,
152 irb->ecw[0], irb->ecw[1],
153 irb->ecw[2], irb->ecw[3],
154 irb->ecw[4], irb->ecw[5],
155 irb->ecw[6], irb->ecw[7]);
156 return -EAGAIN;
157 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200158 if (irb->scsw.cmd.cc == 3) {
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100159 u8 lpm;
160
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200161 lpm = to_io_private(sch)->orb.cmd.lpm;
Michael Ernst139b83d2008-05-07 09:22:54 +0200162 CIO_MSG_EVENT(3, "SNID - Device %04x on Subchannel 0.%x.%04x,"
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800163 " lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200164 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckcd6b4f22008-01-26 14:10:43 +0100165 sch->schid.sch_no, lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return -EACCES;
167 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200168 i = 8 - ffs(cdev->private->imask);
169 if (cdev->private->pgid[i].inf.ps.state2 == SNID_STATE2_RESVD_ELSE) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800170 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 "is reserved by someone else\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200172 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800173 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return -EUSERS;
175 }
176 return 0;
177}
178
179/*
180 * Got interrupt for Sense Path Group ID.
181 */
182void
183ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
184{
185 struct subchannel *sch;
186 struct irb *irb;
187 int ret;
188
189 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200190
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200191 if (irb->scsw.cmd.stctl ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200193 if (__ccw_device_should_retry(&irb->scsw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 ret = __ccw_device_sense_pgid_start(cdev);
195 if (ret && ret != -EBUSY)
196 ccw_device_sense_pgid_done(cdev, ret);
197 }
198 return;
199 }
200 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
201 return;
202 sch = to_subchannel(cdev->dev.parent);
203 ret = __ccw_device_check_sense_pgid(cdev);
204 memset(&cdev->private->irb, 0, sizeof(struct irb));
205 switch (ret) {
206 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
208 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
209 break;
210 case -ETIME: /* Sense path group id stopped by timeout. */
211 ccw_device_sense_pgid_done(cdev, -ETIME);
212 break;
213 case -EACCES: /* channel is not operational. */
214 sch->lpm &= ~cdev->private->imask;
Cornelia Huck7e560812006-07-12 16:40:19 +0200215 /* Fall through. */
216 case 0: /* Sense Path Group ID successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 cdev->private->imask >>= 1;
218 cdev->private->iretry = 5;
219 /* Fall through. */
220 case -EAGAIN: /* Try again. */
221 ret = __ccw_device_sense_pgid_start(cdev);
222 if (ret != 0 && ret != -EBUSY)
Cornelia Huck7e560812006-07-12 16:40:19 +0200223 ccw_device_sense_pgid_done(cdev, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 break;
225 case -EUSERS: /* device is reserved for someone else. */
226 ccw_device_sense_pgid_done(cdev, -EUSERS);
227 break;
228 }
229}
230
231/*
232 * Path Group ID helper function.
233 */
234static int
235__ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
236{
237 struct subchannel *sch;
238 struct ccw1 *ccw;
239 int ret;
240
241 sch = to_subchannel(cdev->dev.parent);
242
243 /* Setup sense path group id channel program. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200244 cdev->private->pgid[0].inf.fc = func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 ccw = cdev->private->iccws;
Michael Ernst32aff572008-05-15 16:52:29 +0200246 if (cdev->private->flags.pgid_single)
Cornelia Huck7e560812006-07-12 16:40:19 +0200247 cdev->private->pgid[0].inf.fc |= SPID_FUNC_SINGLE_PATH;
Michael Ernst32aff572008-05-15 16:52:29 +0200248 else
249 cdev->private->pgid[0].inf.fc |= SPID_FUNC_MULTI_PATH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 ccw->cmd_code = CCW_CMD_SET_PGID;
Cornelia Huck7e560812006-07-12 16:40:19 +0200251 ccw->cda = (__u32) __pa (&cdev->private->pgid[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 ccw->count = sizeof (struct pgid);
253 ccw->flags = CCW_FLAG_SLI;
254
255 /* Reset device status. */
256 memset(&cdev->private->irb, 0, sizeof(struct irb));
257
258 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200259 ret = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (cdev->private->iretry > 0) {
261 cdev->private->iretry--;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100262 /* Reset internal retry indication. */
263 cdev->private->flags.intretry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 ret = cio_start (sch, cdev->private->iccws,
265 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200266 /* We expect an interrupt in case of success or busy
267 * indication. */
268 if ((ret == 0) || (ret == -EBUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return ret;
270 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200271 /* PGID command failed on this path. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200272 CIO_MSG_EVENT(3, "SPID - Device %04x on Subchannel "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800273 "0.%x.%04x, lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200274 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800275 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return ret;
277}
278
279/*
Cornelia Huck7e560812006-07-12 16:40:19 +0200280 * Helper function to send a nop ccw down a path.
281 */
282static int __ccw_device_do_nop(struct ccw_device *cdev)
283{
284 struct subchannel *sch;
285 struct ccw1 *ccw;
286 int ret;
287
288 sch = to_subchannel(cdev->dev.parent);
289
290 /* Setup nop channel program. */
291 ccw = cdev->private->iccws;
292 ccw->cmd_code = CCW_CMD_NOOP;
293 ccw->cda = 0;
294 ccw->count = 0;
295 ccw->flags = CCW_FLAG_SLI;
296
297 /* Reset device status. */
298 memset(&cdev->private->irb, 0, sizeof(struct irb));
299
300 /* Try multiple times. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200301 ret = -EACCES;
Cornelia Huck7e560812006-07-12 16:40:19 +0200302 if (cdev->private->iretry > 0) {
303 cdev->private->iretry--;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100304 /* Reset internal retry indication. */
305 cdev->private->flags.intretry = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200306 ret = cio_start (sch, cdev->private->iccws,
307 cdev->private->imask);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200308 /* We expect an interrupt in case of success or busy
309 * indication. */
310 if ((ret == 0) || (ret == -EBUSY))
Cornelia Huck7e560812006-07-12 16:40:19 +0200311 return ret;
312 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200313 /* nop command failed on this path. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200314 CIO_MSG_EVENT(3, "NOP - Device %04x on Subchannel "
Cornelia Huck7e560812006-07-12 16:40:19 +0200315 "0.%x.%04x, lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200316 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huck7e560812006-07-12 16:40:19 +0200317 sch->schid.sch_no, cdev->private->imask);
318 return ret;
319}
320
321
322/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 * Called from interrupt context to check if a valid answer
324 * to Set Path Group ID was received.
325 */
326static int
327__ccw_device_check_pgid(struct ccw_device *cdev)
328{
329 struct subchannel *sch;
330 struct irb *irb;
331
332 sch = to_subchannel(cdev->dev.parent);
333 irb = &cdev->private->irb;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200334 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
Cornelia Huckd23861f2006-12-04 15:41:04 +0100335 /* Retry Set PGID if requested. */
336 if (cdev->private->flags.intretry) {
337 cdev->private->flags.intretry = 0;
338 return -EAGAIN;
339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return -ETIME;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (irb->esw.esw0.erw.cons) {
343 if (irb->ecw[0] & SNS0_CMD_REJECT)
344 return -EOPNOTSUPP;
345 /* Hmm, whatever happened, try again. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800346 CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, "
347 "cnt %02d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200349 cdev->private->dev_id.ssid,
350 cdev->private->dev_id.devno,
351 irb->esw.esw0.erw.scnt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 irb->ecw[0], irb->ecw[1],
353 irb->ecw[2], irb->ecw[3],
354 irb->ecw[4], irb->ecw[5],
355 irb->ecw[6], irb->ecw[7]);
356 return -EAGAIN;
357 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200358 if (irb->scsw.cmd.cc == 3) {
Michael Ernst139b83d2008-05-07 09:22:54 +0200359 CIO_MSG_EVENT(3, "SPID - Device %04x on Subchannel 0.%x.%04x,"
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800360 " lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200361 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800362 sch->schid.sch_no, cdev->private->imask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return -EACCES;
364 }
365 return 0;
366}
367
Cornelia Huck7e560812006-07-12 16:40:19 +0200368/*
369 * Called from interrupt context to check the path status after a nop has
370 * been send.
371 */
372static int __ccw_device_check_nop(struct ccw_device *cdev)
373{
374 struct subchannel *sch;
375 struct irb *irb;
376
377 sch = to_subchannel(cdev->dev.parent);
378 irb = &cdev->private->irb;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200379 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
Cornelia Huckd23861f2006-12-04 15:41:04 +0100380 /* Retry NOP if requested. */
381 if (cdev->private->flags.intretry) {
382 cdev->private->flags.intretry = 0;
383 return -EAGAIN;
384 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200385 return -ETIME;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100386 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200387 if (irb->scsw.cmd.cc == 3) {
Michael Ernst139b83d2008-05-07 09:22:54 +0200388 CIO_MSG_EVENT(3, "NOP - Device %04x on Subchannel 0.%x.%04x,"
Cornelia Huck7e560812006-07-12 16:40:19 +0200389 " lpm %02X, became 'not operational'\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200390 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huck7e560812006-07-12 16:40:19 +0200391 sch->schid.sch_no, cdev->private->imask);
392 return -EACCES;
393 }
394 return 0;
395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397static void
398__ccw_device_verify_start(struct ccw_device *cdev)
399{
400 struct subchannel *sch;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200401 __u8 func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 int ret;
403
404 sch = to_subchannel(cdev->dev.parent);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200405 /* Repeat for all paths. */
406 for (; cdev->private->imask; cdev->private->imask >>= 1,
407 cdev->private->iretry = 5) {
408 if ((cdev->private->imask & sch->schib.pmcw.pam) == 0)
409 /* Path not available, try next. */
410 continue;
Cornelia Huck7e560812006-07-12 16:40:19 +0200411 if (cdev->private->options.pgroup) {
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200412 if (sch->opm & cdev->private->imask)
413 func = SPID_FUNC_ESTABLISH;
414 else
415 func = SPID_FUNC_RESIGN;
Cornelia Huck7e560812006-07-12 16:40:19 +0200416 ret = __ccw_device_do_pgid(cdev, func);
417 } else
418 ret = __ccw_device_do_nop(cdev);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200419 /* We expect an interrupt in case of success or busy
420 * indication. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (ret == 0 || ret == -EBUSY)
422 return;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200423 /* Permanent path failure, try next. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200425 /* Done with all paths. */
426 ccw_device_verify_done(cdev, (sch->vpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429/*
430 * Got interrupt for Set Path Group ID.
431 */
432void
433ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
434{
435 struct subchannel *sch;
436 struct irb *irb;
437 int ret;
438
439 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200440
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200441 if (irb->scsw.cmd.stctl ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200443 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 __ccw_device_verify_start(cdev);
445 return;
446 }
447 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
448 return;
449 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck7e560812006-07-12 16:40:19 +0200450 if (cdev->private->options.pgroup)
451 ret = __ccw_device_check_pgid(cdev);
452 else
453 ret = __ccw_device_check_nop(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 memset(&cdev->private->irb, 0, sizeof(struct irb));
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 switch (ret) {
457 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
458 case 0:
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200459 /* Path verification ccw finished successfully, update lpm. */
460 sch->vpm |= sch->opm & cdev->private->imask;
461 /* Go on with next path. */
462 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 case -EOPNOTSUPP:
467 /*
468 * One of those strange devices which claim to be able
469 * to do multipathing but not for Set Path Group ID.
470 */
Cornelia Huck7e560812006-07-12 16:40:19 +0200471 if (cdev->private->flags.pgid_single)
472 cdev->private->options.pgroup = 0;
473 else
474 cdev->private->flags.pgid_single = 1;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200475 /* Retry */
476 sch->vpm = 0;
477 cdev->private->imask = 0x80;
478 cdev->private->iretry = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 /* fall through. */
480 case -EAGAIN: /* Try again. */
481 __ccw_device_verify_start(cdev);
482 break;
483 case -ETIME: /* Set path group id stopped by timeout. */
484 ccw_device_verify_done(cdev, -ETIME);
485 break;
486 case -EACCES: /* channel is not operational. */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200487 cdev->private->imask >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 cdev->private->iretry = 5;
489 __ccw_device_verify_start(cdev);
490 break;
491 }
492}
493
494void
495ccw_device_verify_start(struct ccw_device *cdev)
496{
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800497 struct subchannel *sch = to_subchannel(cdev->dev.parent);
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 cdev->private->flags.pgid_single = 0;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200500 cdev->private->imask = 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 cdev->private->iretry = 5;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200502
503 /* Start with empty vpm. */
504 sch->vpm = 0;
505
506 /* Get current pam. */
Sebastian Ottcdb912a2008-12-25 13:39:12 +0100507 if (cio_update_schib(sch)) {
Cornelia Huck6810a2b2006-01-06 00:19:13 -0800508 ccw_device_verify_done(cdev, -ENODEV);
509 return;
510 }
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200511 /* After 60s path verification is considered to have failed. */
512 ccw_device_set_timeout(cdev, 60*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 __ccw_device_verify_start(cdev);
514}
515
516static void
517__ccw_device_disband_start(struct ccw_device *cdev)
518{
519 struct subchannel *sch;
520 int ret;
521
522 sch = to_subchannel(cdev->dev.parent);
523 while (cdev->private->imask != 0) {
524 if (sch->lpm & cdev->private->imask) {
525 ret = __ccw_device_do_pgid(cdev, SPID_FUNC_DISBAND);
526 if (ret == 0)
527 return;
528 }
529 cdev->private->iretry = 5;
530 cdev->private->imask >>= 1;
531 }
Cornelia Huck6d751c42006-02-17 13:52:45 -0800532 ccw_device_disband_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
535/*
536 * Got interrupt for Unset Path Group ID.
537 */
538void
539ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
540{
541 struct subchannel *sch;
542 struct irb *irb;
543 int ret;
544
545 irb = (struct irb *) __LC_IRB;
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200546
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200547 if (irb->scsw.cmd.stctl ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
Stefan Bader7b7db1b2006-08-30 14:33:39 +0200549 if (__ccw_device_should_retry(&irb->scsw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 __ccw_device_disband_start(cdev);
551 return;
552 }
553 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
554 return;
555 sch = to_subchannel(cdev->dev.parent);
556 ret = __ccw_device_check_pgid(cdev);
557 memset(&cdev->private->irb, 0, sizeof(struct irb));
558 switch (ret) {
559 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
560 case 0: /* disband successful. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 ccw_device_disband_done(cdev, ret);
562 break;
563 case -EOPNOTSUPP:
564 /*
565 * One of those strange devices which claim to be able
566 * to do multipathing but not for Unset Path Group ID.
567 */
568 cdev->private->flags.pgid_single = 1;
569 /* fall through. */
570 case -EAGAIN: /* Try again. */
571 __ccw_device_disband_start(cdev);
572 break;
573 case -ETIME: /* Set path group id stopped by timeout. */
574 ccw_device_disband_done(cdev, -ETIME);
575 break;
576 case -EACCES: /* channel is not operational. */
577 cdev->private->imask >>= 1;
578 cdev->private->iretry = 5;
579 __ccw_device_disband_start(cdev);
580 break;
581 }
582}
583
584void
585ccw_device_disband_start(struct ccw_device *cdev)
586{
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200587 /* After 60s disbanding is considered to have failed. */
588 ccw_device_set_timeout(cdev, 60*HZ);
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 cdev->private->flags.pgid_single = 0;
591 cdev->private->iretry = 5;
592 cdev->private->imask = 0x80;
593 __ccw_device_disband_start(cdev);
594}