Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/device_pgid.c |
| 3 | * |
| 4 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, |
| 5 | * IBM Corporation |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 6 | * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 8 | * |
| 9 | * Path Group ID functions. |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #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 Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 24 | #include "ioasm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 27 | * Helper function called from interrupt context to decide whether an |
| 28 | * operation should be tried again. |
| 29 | */ |
| 30 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * Start Sense Path Group ID helper function. Used in ccw_device_recog |
| 43 | * and ccw_device_sense_pgid. |
| 44 | */ |
| 45 | static int |
| 46 | __ccw_device_sense_pgid_start(struct ccw_device *cdev) |
| 47 | { |
| 48 | struct subchannel *sch; |
| 49 | struct ccw1 *ccw; |
| 50 | int ret; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 51 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 54 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* Setup sense path group id channel program. */ |
| 60 | ccw = cdev->private->iccws; |
| 61 | ccw->cmd_code = CCW_CMD_SENSE_PGID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | 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 Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 71 | ccw->cda = (__u32) __pa (&cdev->private->pgid[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (cdev->private->iretry > 0) { |
| 73 | cdev->private->iretry--; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 74 | /* Reset internal retry indication. */ |
| 75 | cdev->private->flags.intretry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ret = cio_start (sch, cdev->private->iccws, |
| 77 | cdev->private->imask); |
| 78 | /* ret is 0, -EBUSY, -EACCES or -ENODEV */ |
| 79 | if (ret != -EACCES) |
| 80 | return ret; |
| 81 | CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 82 | "0.%x.%04x, lpm %02X, became 'not " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | "operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 84 | cdev->private->dev_id.devno, |
| 85 | sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 86 | sch->schid.sch_no, cdev->private->imask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | } |
| 89 | cdev->private->imask >>= 1; |
| 90 | cdev->private->iretry = 5; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 91 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | ccw_device_sense_pgid_start(struct ccw_device *cdev) |
| 99 | { |
| 100 | int ret; |
| 101 | |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 102 | /* Set a timeout of 60s */ |
| 103 | ccw_device_set_timeout(cdev, 60*HZ); |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | cdev->private->state = DEV_STATE_SENSE_PGID; |
| 106 | cdev->private->imask = 0x80; |
| 107 | cdev->private->iretry = 5; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 108 | memset (&cdev->private->pgid, 0, sizeof (cdev->private->pgid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | ret = __ccw_device_sense_pgid_start(cdev); |
| 110 | if (ret && ret != -EBUSY) |
| 111 | ccw_device_sense_pgid_done(cdev, ret); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Called from interrupt context to check if a valid answer |
| 116 | * to Sense Path Group ID was received. |
| 117 | */ |
| 118 | static int |
| 119 | __ccw_device_check_sense_pgid(struct ccw_device *cdev) |
| 120 | { |
| 121 | struct subchannel *sch; |
| 122 | struct irb *irb; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 123 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | sch = to_subchannel(cdev->dev.parent); |
| 126 | irb = &cdev->private->irb; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 127 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
| 128 | /* Retry Sense PGID if requested. */ |
| 129 | if (cdev->private->flags.intretry) { |
| 130 | cdev->private->flags.intretry = 0; |
| 131 | return -EAGAIN; |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return -ETIME; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | if (irb->esw.esw0.erw.cons && |
| 136 | (irb->ecw[0]&(SNS0_CMD_REJECT|SNS0_INTERVENTION_REQ))) { |
| 137 | /* |
| 138 | * If the device doesn't support the Sense Path Group ID |
| 139 | * command further retries wouldn't help ... |
| 140 | */ |
| 141 | return -EOPNOTSUPP; |
| 142 | } |
| 143 | if (irb->esw.esw0.erw.cons) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 144 | CIO_MSG_EVENT(2, "SNID - device 0.%x.%04x, unit check, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | "lpum %02X, cnt %02d, sns : " |
| 146 | "%02X%02X%02X%02X %02X%02X%02X%02X ...\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 147 | cdev->private->dev_id.ssid, |
| 148 | cdev->private->dev_id.devno, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | irb->esw.esw0.sublog.lpum, |
| 150 | irb->esw.esw0.erw.scnt, |
| 151 | irb->ecw[0], irb->ecw[1], |
| 152 | irb->ecw[2], irb->ecw[3], |
| 153 | irb->ecw[4], irb->ecw[5], |
| 154 | irb->ecw[6], irb->ecw[7]); |
| 155 | return -EAGAIN; |
| 156 | } |
| 157 | if (irb->scsw.cc == 3) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 158 | CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x," |
| 159 | " lpm %02X, became 'not operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 160 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 161 | sch->schid.sch_no, sch->orb.lpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -EACCES; |
| 163 | } |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 164 | i = 8 - ffs(cdev->private->imask); |
| 165 | if (cdev->private->pgid[i].inf.ps.state2 == SNID_STATE2_RESVD_ELSE) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 166 | CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | "is reserved by someone else\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 168 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 169 | sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return -EUSERS; |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Got interrupt for Sense Path Group ID. |
| 177 | */ |
| 178 | void |
| 179 | ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 180 | { |
| 181 | struct subchannel *sch; |
| 182 | struct irb *irb; |
| 183 | int ret; |
| 184 | |
| 185 | irb = (struct irb *) __LC_IRB; |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (irb->scsw.stctl == |
| 188 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 189 | if (__ccw_device_should_retry(&irb->scsw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | ret = __ccw_device_sense_pgid_start(cdev); |
| 191 | if (ret && ret != -EBUSY) |
| 192 | ccw_device_sense_pgid_done(cdev, ret); |
| 193 | } |
| 194 | return; |
| 195 | } |
| 196 | if (ccw_device_accumulate_and_sense(cdev, irb) != 0) |
| 197 | return; |
| 198 | sch = to_subchannel(cdev->dev.parent); |
| 199 | ret = __ccw_device_check_sense_pgid(cdev); |
| 200 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 201 | switch (ret) { |
| 202 | /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | case -EOPNOTSUPP: /* Sense Path Group ID not supported */ |
| 204 | ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP); |
| 205 | break; |
| 206 | case -ETIME: /* Sense path group id stopped by timeout. */ |
| 207 | ccw_device_sense_pgid_done(cdev, -ETIME); |
| 208 | break; |
| 209 | case -EACCES: /* channel is not operational. */ |
| 210 | sch->lpm &= ~cdev->private->imask; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 211 | /* Fall through. */ |
| 212 | case 0: /* Sense Path Group ID successful. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | cdev->private->imask >>= 1; |
| 214 | cdev->private->iretry = 5; |
| 215 | /* Fall through. */ |
| 216 | case -EAGAIN: /* Try again. */ |
| 217 | ret = __ccw_device_sense_pgid_start(cdev); |
| 218 | if (ret != 0 && ret != -EBUSY) |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 219 | ccw_device_sense_pgid_done(cdev, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | break; |
| 221 | case -EUSERS: /* device is reserved for someone else. */ |
| 222 | ccw_device_sense_pgid_done(cdev, -EUSERS); |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * Path Group ID helper function. |
| 229 | */ |
| 230 | static int |
| 231 | __ccw_device_do_pgid(struct ccw_device *cdev, __u8 func) |
| 232 | { |
| 233 | struct subchannel *sch; |
| 234 | struct ccw1 *ccw; |
| 235 | int ret; |
| 236 | |
| 237 | sch = to_subchannel(cdev->dev.parent); |
| 238 | |
| 239 | /* Setup sense path group id channel program. */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 240 | cdev->private->pgid[0].inf.fc = func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | ccw = cdev->private->iccws; |
| 242 | if (!cdev->private->flags.pgid_single) { |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 243 | cdev->private->pgid[0].inf.fc |= SPID_FUNC_MULTI_PATH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | ccw->cmd_code = CCW_CMD_SUSPEND_RECONN; |
| 245 | ccw->cda = 0; |
| 246 | ccw->count = 0; |
| 247 | ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 248 | ccw++; |
| 249 | } else |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 250 | cdev->private->pgid[0].inf.fc |= SPID_FUNC_SINGLE_PATH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | ccw->cmd_code = CCW_CMD_SET_PGID; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 253 | ccw->cda = (__u32) __pa (&cdev->private->pgid[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | ccw->count = sizeof (struct pgid); |
| 255 | ccw->flags = CCW_FLAG_SLI; |
| 256 | |
| 257 | /* Reset device status. */ |
| 258 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 259 | |
| 260 | /* Try multiple times. */ |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 261 | ret = -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (cdev->private->iretry > 0) { |
| 263 | cdev->private->iretry--; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 264 | /* Reset internal retry indication. */ |
| 265 | cdev->private->flags.intretry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | ret = cio_start (sch, cdev->private->iccws, |
| 267 | cdev->private->imask); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 268 | /* We expect an interrupt in case of success or busy |
| 269 | * indication. */ |
| 270 | if ((ret == 0) || (ret == -EBUSY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | return ret; |
| 272 | } |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 273 | /* PGID command failed on this path. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 275 | "0.%x.%04x, lpm %02X, became 'not operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 276 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 277 | sch->schid.sch_no, cdev->private->imask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | /* |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 282 | * Helper function to send a nop ccw down a path. |
| 283 | */ |
| 284 | static int __ccw_device_do_nop(struct ccw_device *cdev) |
| 285 | { |
| 286 | struct subchannel *sch; |
| 287 | struct ccw1 *ccw; |
| 288 | int ret; |
| 289 | |
| 290 | sch = to_subchannel(cdev->dev.parent); |
| 291 | |
| 292 | /* Setup nop channel program. */ |
| 293 | ccw = cdev->private->iccws; |
| 294 | ccw->cmd_code = CCW_CMD_NOOP; |
| 295 | ccw->cda = 0; |
| 296 | ccw->count = 0; |
| 297 | ccw->flags = CCW_FLAG_SLI; |
| 298 | |
| 299 | /* Reset device status. */ |
| 300 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 301 | |
| 302 | /* Try multiple times. */ |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 303 | ret = -EACCES; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 304 | if (cdev->private->iretry > 0) { |
| 305 | cdev->private->iretry--; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 306 | /* Reset internal retry indication. */ |
| 307 | cdev->private->flags.intretry = 0; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 308 | ret = cio_start (sch, cdev->private->iccws, |
| 309 | cdev->private->imask); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 310 | /* We expect an interrupt in case of success or busy |
| 311 | * indication. */ |
| 312 | if ((ret == 0) || (ret == -EBUSY)) |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 313 | return ret; |
| 314 | } |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 315 | /* nop command failed on this path. */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 316 | CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel " |
| 317 | "0.%x.%04x, lpm %02X, became 'not operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 318 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 319 | sch->schid.sch_no, cdev->private->imask); |
| 320 | return ret; |
| 321 | } |
| 322 | |
| 323 | |
| 324 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | * Called from interrupt context to check if a valid answer |
| 326 | * to Set Path Group ID was received. |
| 327 | */ |
| 328 | static int |
| 329 | __ccw_device_check_pgid(struct ccw_device *cdev) |
| 330 | { |
| 331 | struct subchannel *sch; |
| 332 | struct irb *irb; |
| 333 | |
| 334 | sch = to_subchannel(cdev->dev.parent); |
| 335 | irb = &cdev->private->irb; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 336 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
| 337 | /* Retry Set PGID if requested. */ |
| 338 | if (cdev->private->flags.intretry) { |
| 339 | cdev->private->flags.intretry = 0; |
| 340 | return -EAGAIN; |
| 341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | return -ETIME; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | if (irb->esw.esw0.erw.cons) { |
| 345 | if (irb->ecw[0] & SNS0_CMD_REJECT) |
| 346 | return -EOPNOTSUPP; |
| 347 | /* Hmm, whatever happened, try again. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 348 | CIO_MSG_EVENT(2, "SPID - device 0.%x.%04x, unit check, " |
| 349 | "cnt %02d, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | "sns : %02X%02X%02X%02X %02X%02X%02X%02X ...\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 351 | cdev->private->dev_id.ssid, |
| 352 | cdev->private->dev_id.devno, |
| 353 | irb->esw.esw0.erw.scnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | irb->ecw[0], irb->ecw[1], |
| 355 | irb->ecw[2], irb->ecw[3], |
| 356 | irb->ecw[4], irb->ecw[5], |
| 357 | irb->ecw[6], irb->ecw[7]); |
| 358 | return -EAGAIN; |
| 359 | } |
| 360 | if (irb->scsw.cc == 3) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 361 | CIO_MSG_EVENT(2, "SPID - Device %04x on Subchannel 0.%x.%04x," |
| 362 | " lpm %02X, became 'not operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 363 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 364 | sch->schid.sch_no, cdev->private->imask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return -EACCES; |
| 366 | } |
| 367 | return 0; |
| 368 | } |
| 369 | |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 370 | /* |
| 371 | * Called from interrupt context to check the path status after a nop has |
| 372 | * been send. |
| 373 | */ |
| 374 | static int __ccw_device_check_nop(struct ccw_device *cdev) |
| 375 | { |
| 376 | struct subchannel *sch; |
| 377 | struct irb *irb; |
| 378 | |
| 379 | sch = to_subchannel(cdev->dev.parent); |
| 380 | irb = &cdev->private->irb; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 381 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
| 382 | /* Retry NOP if requested. */ |
| 383 | if (cdev->private->flags.intretry) { |
| 384 | cdev->private->flags.intretry = 0; |
| 385 | return -EAGAIN; |
| 386 | } |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 387 | return -ETIME; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame^] | 388 | } |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 389 | if (irb->scsw.cc == 3) { |
| 390 | CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel 0.%x.%04x," |
| 391 | " lpm %02X, became 'not operational'\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 392 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 393 | sch->schid.sch_no, cdev->private->imask); |
| 394 | return -EACCES; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | static void |
| 400 | __ccw_device_verify_start(struct ccw_device *cdev) |
| 401 | { |
| 402 | struct subchannel *sch; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 403 | __u8 func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | int ret; |
| 405 | |
| 406 | sch = to_subchannel(cdev->dev.parent); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 407 | /* Repeat for all paths. */ |
| 408 | for (; cdev->private->imask; cdev->private->imask >>= 1, |
| 409 | cdev->private->iretry = 5) { |
| 410 | if ((cdev->private->imask & sch->schib.pmcw.pam) == 0) |
| 411 | /* Path not available, try next. */ |
| 412 | continue; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 413 | if (cdev->private->options.pgroup) { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 414 | if (sch->opm & cdev->private->imask) |
| 415 | func = SPID_FUNC_ESTABLISH; |
| 416 | else |
| 417 | func = SPID_FUNC_RESIGN; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 418 | ret = __ccw_device_do_pgid(cdev, func); |
| 419 | } else |
| 420 | ret = __ccw_device_do_nop(cdev); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 421 | /* We expect an interrupt in case of success or busy |
| 422 | * indication. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (ret == 0 || ret == -EBUSY) |
| 424 | return; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 425 | /* Permanent path failure, try next. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 427 | /* Done with all paths. */ |
| 428 | ccw_device_verify_done(cdev, (sch->vpm != 0) ? 0 : -ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /* |
| 432 | * Got interrupt for Set Path Group ID. |
| 433 | */ |
| 434 | void |
| 435 | ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 436 | { |
| 437 | struct subchannel *sch; |
| 438 | struct irb *irb; |
| 439 | int ret; |
| 440 | |
| 441 | irb = (struct irb *) __LC_IRB; |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | if (irb->scsw.stctl == |
| 444 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 445 | if (__ccw_device_should_retry(&irb->scsw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | __ccw_device_verify_start(cdev); |
| 447 | return; |
| 448 | } |
| 449 | if (ccw_device_accumulate_and_sense(cdev, irb) != 0) |
| 450 | return; |
| 451 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 452 | if (cdev->private->options.pgroup) |
| 453 | ret = __ccw_device_check_pgid(cdev); |
| 454 | else |
| 455 | ret = __ccw_device_check_nop(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | switch (ret) { |
| 459 | /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */ |
| 460 | case 0: |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 461 | /* Path verification ccw finished successfully, update lpm. */ |
| 462 | sch->vpm |= sch->opm & cdev->private->imask; |
| 463 | /* Go on with next path. */ |
| 464 | cdev->private->imask >>= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | cdev->private->iretry = 5; |
| 466 | __ccw_device_verify_start(cdev); |
| 467 | break; |
| 468 | case -EOPNOTSUPP: |
| 469 | /* |
| 470 | * One of those strange devices which claim to be able |
| 471 | * to do multipathing but not for Set Path Group ID. |
| 472 | */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 473 | if (cdev->private->flags.pgid_single) |
| 474 | cdev->private->options.pgroup = 0; |
| 475 | else |
| 476 | cdev->private->flags.pgid_single = 1; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 477 | /* Retry */ |
| 478 | sch->vpm = 0; |
| 479 | cdev->private->imask = 0x80; |
| 480 | cdev->private->iretry = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | /* fall through. */ |
| 482 | case -EAGAIN: /* Try again. */ |
| 483 | __ccw_device_verify_start(cdev); |
| 484 | break; |
| 485 | case -ETIME: /* Set path group id stopped by timeout. */ |
| 486 | ccw_device_verify_done(cdev, -ETIME); |
| 487 | break; |
| 488 | case -EACCES: /* channel is not operational. */ |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 489 | cdev->private->imask >>= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | cdev->private->iretry = 5; |
| 491 | __ccw_device_verify_start(cdev); |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | void |
| 497 | ccw_device_verify_start(struct ccw_device *cdev) |
| 498 | { |
Cornelia Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 499 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | cdev->private->flags.pgid_single = 0; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 502 | cdev->private->imask = 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | cdev->private->iretry = 5; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 504 | |
| 505 | /* Start with empty vpm. */ |
| 506 | sch->vpm = 0; |
| 507 | |
| 508 | /* Get current pam. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 509 | if (stsch(sch->schid, &sch->schib)) { |
Cornelia Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 510 | ccw_device_verify_done(cdev, -ENODEV); |
| 511 | return; |
| 512 | } |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 513 | /* After 60s path verification is considered to have failed. */ |
| 514 | ccw_device_set_timeout(cdev, 60*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | __ccw_device_verify_start(cdev); |
| 516 | } |
| 517 | |
| 518 | static void |
| 519 | __ccw_device_disband_start(struct ccw_device *cdev) |
| 520 | { |
| 521 | struct subchannel *sch; |
| 522 | int ret; |
| 523 | |
| 524 | sch = to_subchannel(cdev->dev.parent); |
| 525 | while (cdev->private->imask != 0) { |
| 526 | if (sch->lpm & cdev->private->imask) { |
| 527 | ret = __ccw_device_do_pgid(cdev, SPID_FUNC_DISBAND); |
| 528 | if (ret == 0) |
| 529 | return; |
| 530 | } |
| 531 | cdev->private->iretry = 5; |
| 532 | cdev->private->imask >>= 1; |
| 533 | } |
Cornelia Huck | 6d751c4 | 2006-02-17 13:52:45 -0800 | [diff] [blame] | 534 | ccw_device_disband_done(cdev, (sch->lpm != 0) ? 0 : -ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Got interrupt for Unset Path Group ID. |
| 539 | */ |
| 540 | void |
| 541 | ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 542 | { |
| 543 | struct subchannel *sch; |
| 544 | struct irb *irb; |
| 545 | int ret; |
| 546 | |
| 547 | irb = (struct irb *) __LC_IRB; |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (irb->scsw.stctl == |
| 550 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 551 | if (__ccw_device_should_retry(&irb->scsw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | __ccw_device_disband_start(cdev); |
| 553 | return; |
| 554 | } |
| 555 | if (ccw_device_accumulate_and_sense(cdev, irb) != 0) |
| 556 | return; |
| 557 | sch = to_subchannel(cdev->dev.parent); |
| 558 | ret = __ccw_device_check_pgid(cdev); |
| 559 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 560 | switch (ret) { |
| 561 | /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */ |
| 562 | case 0: /* disband successful. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | ccw_device_disband_done(cdev, ret); |
| 564 | break; |
| 565 | case -EOPNOTSUPP: |
| 566 | /* |
| 567 | * One of those strange devices which claim to be able |
| 568 | * to do multipathing but not for Unset Path Group ID. |
| 569 | */ |
| 570 | cdev->private->flags.pgid_single = 1; |
| 571 | /* fall through. */ |
| 572 | case -EAGAIN: /* Try again. */ |
| 573 | __ccw_device_disband_start(cdev); |
| 574 | break; |
| 575 | case -ETIME: /* Set path group id stopped by timeout. */ |
| 576 | ccw_device_disband_done(cdev, -ETIME); |
| 577 | break; |
| 578 | case -EACCES: /* channel is not operational. */ |
| 579 | cdev->private->imask >>= 1; |
| 580 | cdev->private->iretry = 5; |
| 581 | __ccw_device_disband_start(cdev); |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | void |
| 587 | ccw_device_disband_start(struct ccw_device *cdev) |
| 588 | { |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 589 | /* After 60s disbanding is considered to have failed. */ |
| 590 | ccw_device_set_timeout(cdev, 60*HZ); |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | cdev->private->flags.pgid_single = 0; |
| 593 | cdev->private->iretry = 5; |
| 594 | cdev->private->imask = 0x80; |
| 595 | __ccw_device_disband_start(cdev); |
| 596 | } |