Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/device_id.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 | * Sense ID functions. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
Ahmed S. Darwish | 045236a | 2007-02-12 15:49:51 +0100 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <asm/ccwdev.h> |
| 17 | #include <asm/delay.h> |
| 18 | #include <asm/cio.h> |
| 19 | #include <asm/lowcore.h> |
Michael Holzheu | 0a87c5c | 2007-08-22 13:51:40 +0200 | [diff] [blame] | 20 | #include <asm/diag.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include "cio.h" |
| 23 | #include "cio_debug.h" |
| 24 | #include "css.h" |
| 25 | #include "device.h" |
| 26 | #include "ioasm.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame^] | 27 | #include "io_sch.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Input : |
| 31 | * devno - device number |
| 32 | * ps - pointer to sense ID data area |
| 33 | * Output : none |
| 34 | */ |
| 35 | static void |
| 36 | VM_virtual_device_info (__u16 devno, struct senseid *ps) |
| 37 | { |
| 38 | static struct { |
| 39 | int vrdcvcla, vrdcvtyp, cu_type; |
| 40 | } vm_devices[] = { |
| 41 | { 0x08, 0x01, 0x3480 }, |
| 42 | { 0x08, 0x02, 0x3430 }, |
| 43 | { 0x08, 0x10, 0x3420 }, |
| 44 | { 0x08, 0x42, 0x3424 }, |
| 45 | { 0x08, 0x44, 0x9348 }, |
| 46 | { 0x08, 0x81, 0x3490 }, |
| 47 | { 0x08, 0x82, 0x3422 }, |
| 48 | { 0x10, 0x41, 0x1403 }, |
| 49 | { 0x10, 0x42, 0x3211 }, |
| 50 | { 0x10, 0x43, 0x3203 }, |
| 51 | { 0x10, 0x45, 0x3800 }, |
| 52 | { 0x10, 0x47, 0x3262 }, |
| 53 | { 0x10, 0x48, 0x3820 }, |
| 54 | { 0x10, 0x49, 0x3800 }, |
| 55 | { 0x10, 0x4a, 0x4245 }, |
| 56 | { 0x10, 0x4b, 0x4248 }, |
| 57 | { 0x10, 0x4d, 0x3800 }, |
| 58 | { 0x10, 0x4e, 0x3820 }, |
| 59 | { 0x10, 0x4f, 0x3820 }, |
| 60 | { 0x10, 0x82, 0x2540 }, |
| 61 | { 0x10, 0x84, 0x3525 }, |
| 62 | { 0x20, 0x81, 0x2501 }, |
| 63 | { 0x20, 0x82, 0x2540 }, |
| 64 | { 0x20, 0x84, 0x3505 }, |
| 65 | { 0x40, 0x01, 0x3278 }, |
| 66 | { 0x40, 0x04, 0x3277 }, |
| 67 | { 0x40, 0x80, 0x2250 }, |
| 68 | { 0x40, 0xc0, 0x5080 }, |
| 69 | { 0x80, 0x00, 0x3215 }, |
| 70 | }; |
| 71 | struct diag210 diag_data; |
| 72 | int ccode, i; |
| 73 | |
| 74 | CIO_TRACE_EVENT (4, "VMvdinf"); |
| 75 | |
| 76 | diag_data = (struct diag210) { |
| 77 | .vrdcdvno = devno, |
| 78 | .vrdclen = sizeof (diag_data), |
| 79 | }; |
| 80 | |
| 81 | ccode = diag210 (&diag_data); |
| 82 | ps->reserved = 0xff; |
| 83 | |
| 84 | /* Special case for bloody osa devices. */ |
| 85 | if (diag_data.vrdcvcla == 0x02 && |
| 86 | diag_data.vrdcvtyp == 0x20) { |
| 87 | ps->cu_type = 0x3088; |
| 88 | ps->cu_model = 0x60; |
| 89 | return; |
| 90 | } |
Ahmed S. Darwish | 045236a | 2007-02-12 15:49:51 +0100 | [diff] [blame] | 91 | for (i = 0; i < ARRAY_SIZE(vm_devices); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla && |
| 93 | diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) { |
| 94 | ps->cu_type = vm_devices[i].cu_type; |
| 95 | return; |
| 96 | } |
| 97 | CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):" |
| 98 | "vdev class : %02X, vdev type : %04X \n ... " |
| 99 | "rdev class : %02X, rdev type : %04X, " |
| 100 | "rdev model: %02X\n", |
| 101 | devno, ccode, |
| 102 | diag_data.vrdcvcla, diag_data.vrdcvtyp, |
| 103 | diag_data.vrdcrccl, diag_data.vrdccrty, |
| 104 | diag_data.vrdccrmd); |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Start Sense ID helper function. |
| 109 | * Try to obtain the 'control unit'/'device type' information |
| 110 | * associated with the subchannel. |
| 111 | */ |
| 112 | static int |
| 113 | __ccw_device_sense_id_start(struct ccw_device *cdev) |
| 114 | { |
| 115 | struct subchannel *sch; |
| 116 | struct ccw1 *ccw; |
Cornelia Huck | c94dec9 | 2007-12-04 16:09:01 +0100 | [diff] [blame] | 117 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | sch = to_subchannel(cdev->dev.parent); |
| 120 | /* Setup sense channel program. */ |
| 121 | ccw = cdev->private->iccws; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | ccw->cmd_code = CCW_CMD_SENSE_ID; |
| 123 | ccw->cda = (__u32) __pa (&cdev->private->senseid); |
| 124 | ccw->count = sizeof (struct senseid); |
| 125 | ccw->flags = CCW_FLAG_SLI; |
| 126 | |
| 127 | /* Reset device status. */ |
| 128 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 129 | |
Cornelia Huck | c94dec9 | 2007-12-04 16:09:01 +0100 | [diff] [blame] | 130 | /* Try on every path. */ |
| 131 | ret = -ENODEV; |
| 132 | while (cdev->private->imask != 0) { |
| 133 | if ((sch->opm & cdev->private->imask) != 0 && |
| 134 | cdev->private->iretry > 0) { |
| 135 | cdev->private->iretry--; |
| 136 | /* Reset internal retry indication. */ |
| 137 | cdev->private->flags.intretry = 0; |
| 138 | ret = cio_start (sch, cdev->private->iccws, |
| 139 | cdev->private->imask); |
| 140 | /* ret is 0, -EBUSY, -EACCES or -ENODEV */ |
| 141 | if (ret != -EACCES) |
| 142 | return ret; |
| 143 | } |
| 144 | cdev->private->imask >>= 1; |
| 145 | cdev->private->iretry = 5; |
| 146 | } |
| 147 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void |
| 151 | ccw_device_sense_id_start(struct ccw_device *cdev) |
| 152 | { |
| 153 | int ret; |
| 154 | |
| 155 | memset (&cdev->private->senseid, 0, sizeof (struct senseid)); |
| 156 | cdev->private->senseid.cu_type = 0xFFFF; |
Cornelia Huck | c94dec9 | 2007-12-04 16:09:01 +0100 | [diff] [blame] | 157 | cdev->private->imask = 0x80; |
| 158 | cdev->private->iretry = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | ret = __ccw_device_sense_id_start(cdev); |
| 160 | if (ret && ret != -EBUSY) |
| 161 | ccw_device_sense_id_done(cdev, ret); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Called from interrupt context to check if a valid answer |
| 166 | * to Sense ID was received. |
| 167 | */ |
| 168 | static int |
| 169 | ccw_device_check_sense_id(struct ccw_device *cdev) |
| 170 | { |
| 171 | struct subchannel *sch; |
| 172 | struct irb *irb; |
| 173 | |
| 174 | sch = to_subchannel(cdev->dev.parent); |
| 175 | irb = &cdev->private->irb; |
| 176 | /* Did we get a proper answer ? */ |
| 177 | if (cdev->private->senseid.cu_type != 0xFFFF && |
| 178 | cdev->private->senseid.reserved == 0xFF) { |
| 179 | if (irb->scsw.count < sizeof (struct senseid) - 8) |
| 180 | cdev->private->flags.esid = 1; |
| 181 | return 0; /* Success */ |
| 182 | } |
| 183 | /* Check the error cases. */ |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 184 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
| 185 | /* Retry Sense ID if requested. */ |
| 186 | if (cdev->private->flags.intretry) { |
| 187 | cdev->private->flags.intretry = 0; |
| 188 | return -EAGAIN; |
| 189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return -ETIME; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) { |
| 193 | /* |
| 194 | * if the device doesn't support the SenseID |
| 195 | * command further retries wouldn't help ... |
| 196 | * NB: We don't check here for intervention required like we |
| 197 | * did before, because tape devices with no tape inserted |
| 198 | * may present this status *in conjunction with* the |
| 199 | * sense id information. So, for intervention required, |
| 200 | * we use the "whack it until it talks" strategy... |
| 201 | */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 202 | CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel " |
| 203 | "0.%x.%04x reports cmd reject\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 204 | cdev->private->dev_id.devno, sch->schid.ssid, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 205 | sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return -EOPNOTSUPP; |
| 207 | } |
| 208 | if (irb->esw.esw0.erw.cons) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 209 | CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | "lpum %02X, cnt %02d, sns :" |
| 211 | " %02X%02X%02X%02X %02X%02X%02X%02X ...\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 212 | cdev->private->dev_id.ssid, |
| 213 | cdev->private->dev_id.devno, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | irb->esw.esw0.sublog.lpum, |
| 215 | irb->esw.esw0.erw.scnt, |
| 216 | irb->ecw[0], irb->ecw[1], |
| 217 | irb->ecw[2], irb->ecw[3], |
| 218 | irb->ecw[4], irb->ecw[5], |
| 219 | irb->ecw[6], irb->ecw[7]); |
| 220 | return -EAGAIN; |
| 221 | } |
| 222 | if (irb->scsw.cc == 3) { |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame^] | 223 | u8 lpm; |
| 224 | |
| 225 | lpm = to_io_private(sch)->orb.lpm; |
| 226 | if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0) |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 227 | CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x " |
| 228 | "on subchannel 0.%x.%04x is " |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame^] | 229 | "'not operational'\n", lpm, |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 230 | cdev->private->dev_id.devno, |
| 231 | sch->schid.ssid, sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return -EACCES; |
| 233 | } |
| 234 | /* Hmm, whatever happened, try again. */ |
| 235 | CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 236 | "subchannel 0.%x.%04x returns status %02X%02X\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 237 | cdev->private->dev_id.devno, sch->schid.ssid, |
| 238 | sch->schid.sch_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | irb->scsw.dstat, irb->scsw.cstat); |
| 240 | return -EAGAIN; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Got interrupt for Sense ID. |
| 245 | */ |
| 246 | void |
| 247 | ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 248 | { |
| 249 | struct subchannel *sch; |
| 250 | struct irb *irb; |
| 251 | int ret; |
| 252 | |
| 253 | sch = to_subchannel(cdev->dev.parent); |
| 254 | irb = (struct irb *) __LC_IRB; |
| 255 | /* Retry sense id, if needed. */ |
| 256 | if (irb->scsw.stctl == |
| 257 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
| 258 | if ((irb->scsw.cc == 1) || !irb->scsw.actl) { |
| 259 | ret = __ccw_device_sense_id_start(cdev); |
| 260 | if (ret && ret != -EBUSY) |
| 261 | ccw_device_sense_id_done(cdev, ret); |
| 262 | } |
| 263 | return; |
| 264 | } |
| 265 | if (ccw_device_accumulate_and_sense(cdev, irb) != 0) |
| 266 | return; |
| 267 | ret = ccw_device_check_sense_id(cdev); |
| 268 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 269 | switch (ret) { |
| 270 | /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */ |
| 271 | case 0: /* Sense id succeeded. */ |
| 272 | case -ETIME: /* Sense id stopped by timeout. */ |
| 273 | ccw_device_sense_id_done(cdev, ret); |
| 274 | break; |
| 275 | case -EACCES: /* channel is not operational. */ |
Cornelia Huck | c94dec9 | 2007-12-04 16:09:01 +0100 | [diff] [blame] | 276 | sch->lpm &= ~cdev->private->imask; |
| 277 | cdev->private->imask >>= 1; |
| 278 | cdev->private->iretry = 5; |
| 279 | /* fall through. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | case -EAGAIN: /* try again. */ |
Cornelia Huck | c94dec9 | 2007-12-04 16:09:01 +0100 | [diff] [blame] | 281 | ret = __ccw_device_sense_id_start(cdev); |
| 282 | if (ret == 0 || ret == -EBUSY) |
| 283 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* fall through. */ |
| 285 | default: /* Sense ID failed. Try asking VM. */ |
| 286 | if (MACHINE_IS_VM) { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 287 | VM_virtual_device_info (cdev->private->dev_id.devno, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | &cdev->private->senseid); |
| 289 | if (cdev->private->senseid.cu_type != 0xFFFF) { |
| 290 | /* Got the device information from VM. */ |
| 291 | ccw_device_sense_id_done(cdev, 0); |
| 292 | return; |
| 293 | } |
| 294 | } |
| 295 | /* |
| 296 | * If we can't couldn't identify the device type we |
| 297 | * consider the device "not operational". |
| 298 | */ |
| 299 | ccw_device_sense_id_done(cdev, -ENODEV); |
| 300 | break; |
| 301 | } |
| 302 | } |