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