11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * drivers/s390/cio/device_id.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, 51da177e4SLinus Torvalds * IBM Corporation 64ce3b30cSCornelia Huck * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) 71da177e4SLinus Torvalds * Martin Schwidefsky (schwidefsky@de.ibm.com) 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Sense ID functions. 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/module.h> 131da177e4SLinus Torvalds #include <linux/init.h> 14045236abSAhmed S. Darwish #include <linux/kernel.h> 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <asm/ccwdev.h> 171da177e4SLinus Torvalds #include <asm/delay.h> 181da177e4SLinus Torvalds #include <asm/cio.h> 191da177e4SLinus Torvalds #include <asm/lowcore.h> 200a87c5cfSMichael Holzheu #include <asm/diag.h> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include "cio.h" 231da177e4SLinus Torvalds #include "cio_debug.h" 241da177e4SLinus Torvalds #include "css.h" 251da177e4SLinus Torvalds #include "device.h" 261da177e4SLinus Torvalds #include "ioasm.h" 27cd6b4f27SCornelia Huck #include "io_sch.h" 281da177e4SLinus Torvalds 29*6f52ac29SPeter Oberparleiter /** 30*6f52ac29SPeter Oberparleiter * vm_vdev_to_cu_type - Convert vm virtual device into control unit type 31*6f52ac29SPeter Oberparleiter * for certain devices. 32*6f52ac29SPeter Oberparleiter * @class: virtual device class 33*6f52ac29SPeter Oberparleiter * @type: virtual device type 34*6f52ac29SPeter Oberparleiter * 35*6f52ac29SPeter Oberparleiter * Returns control unit type if a match was made or %0xffff otherwise. 361da177e4SLinus Torvalds */ 37*6f52ac29SPeter Oberparleiter static int vm_vdev_to_cu_type(int class, int type) 381da177e4SLinus Torvalds { 391da177e4SLinus Torvalds static struct { 40*6f52ac29SPeter Oberparleiter int class, type, cu_type; 411da177e4SLinus Torvalds } vm_devices[] = { 421da177e4SLinus Torvalds { 0x08, 0x01, 0x3480 }, 431da177e4SLinus Torvalds { 0x08, 0x02, 0x3430 }, 441da177e4SLinus Torvalds { 0x08, 0x10, 0x3420 }, 451da177e4SLinus Torvalds { 0x08, 0x42, 0x3424 }, 461da177e4SLinus Torvalds { 0x08, 0x44, 0x9348 }, 471da177e4SLinus Torvalds { 0x08, 0x81, 0x3490 }, 481da177e4SLinus Torvalds { 0x08, 0x82, 0x3422 }, 491da177e4SLinus Torvalds { 0x10, 0x41, 0x1403 }, 501da177e4SLinus Torvalds { 0x10, 0x42, 0x3211 }, 511da177e4SLinus Torvalds { 0x10, 0x43, 0x3203 }, 521da177e4SLinus Torvalds { 0x10, 0x45, 0x3800 }, 531da177e4SLinus Torvalds { 0x10, 0x47, 0x3262 }, 541da177e4SLinus Torvalds { 0x10, 0x48, 0x3820 }, 551da177e4SLinus Torvalds { 0x10, 0x49, 0x3800 }, 561da177e4SLinus Torvalds { 0x10, 0x4a, 0x4245 }, 571da177e4SLinus Torvalds { 0x10, 0x4b, 0x4248 }, 581da177e4SLinus Torvalds { 0x10, 0x4d, 0x3800 }, 591da177e4SLinus Torvalds { 0x10, 0x4e, 0x3820 }, 601da177e4SLinus Torvalds { 0x10, 0x4f, 0x3820 }, 611da177e4SLinus Torvalds { 0x10, 0x82, 0x2540 }, 621da177e4SLinus Torvalds { 0x10, 0x84, 0x3525 }, 631da177e4SLinus Torvalds { 0x20, 0x81, 0x2501 }, 641da177e4SLinus Torvalds { 0x20, 0x82, 0x2540 }, 651da177e4SLinus Torvalds { 0x20, 0x84, 0x3505 }, 661da177e4SLinus Torvalds { 0x40, 0x01, 0x3278 }, 671da177e4SLinus Torvalds { 0x40, 0x04, 0x3277 }, 681da177e4SLinus Torvalds { 0x40, 0x80, 0x2250 }, 691da177e4SLinus Torvalds { 0x40, 0xc0, 0x5080 }, 701da177e4SLinus Torvalds { 0x80, 0x00, 0x3215 }, 711da177e4SLinus Torvalds }; 72*6f52ac29SPeter Oberparleiter int i; 73*6f52ac29SPeter Oberparleiter 74*6f52ac29SPeter Oberparleiter for (i = 0; i < ARRAY_SIZE(vm_devices); i++) 75*6f52ac29SPeter Oberparleiter if (class == vm_devices[i].class && type == vm_devices[i].type) 76*6f52ac29SPeter Oberparleiter return vm_devices[i].cu_type; 77*6f52ac29SPeter Oberparleiter 78*6f52ac29SPeter Oberparleiter return 0xffff; 79*6f52ac29SPeter Oberparleiter } 80*6f52ac29SPeter Oberparleiter 81*6f52ac29SPeter Oberparleiter /** 82*6f52ac29SPeter Oberparleiter * diag_get_dev_info - retrieve device information via DIAG X'210' 83*6f52ac29SPeter Oberparleiter * @devno: device number 84*6f52ac29SPeter Oberparleiter * @ps: pointer to sense ID data area 85*6f52ac29SPeter Oberparleiter * 86*6f52ac29SPeter Oberparleiter * Returns zero on success, non-zero otherwise. 87*6f52ac29SPeter Oberparleiter */ 88*6f52ac29SPeter Oberparleiter static int diag_get_dev_info(u16 devno, struct senseid *ps) 89*6f52ac29SPeter Oberparleiter { 901da177e4SLinus Torvalds struct diag210 diag_data; 91*6f52ac29SPeter Oberparleiter int ccode; 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds CIO_TRACE_EVENT (4, "VMvdinf"); 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds diag_data = (struct diag210) { 961da177e4SLinus Torvalds .vrdcdvno = devno, 971da177e4SLinus Torvalds .vrdclen = sizeof (diag_data), 981da177e4SLinus Torvalds }; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds ccode = diag210 (&diag_data); 101*6f52ac29SPeter Oberparleiter if ((ccode == 0) || (ccode == 2)) { 1021da177e4SLinus Torvalds ps->reserved = 0xff; 1031da177e4SLinus Torvalds 104*6f52ac29SPeter Oberparleiter /* Special case for osa devices. */ 105*6f52ac29SPeter Oberparleiter if (diag_data.vrdcvcla == 0x02 && diag_data.vrdcvtyp == 0x20) { 1061da177e4SLinus Torvalds ps->cu_type = 0x3088; 1071da177e4SLinus Torvalds ps->cu_model = 0x60; 108*6f52ac29SPeter Oberparleiter return 0; 1091da177e4SLinus Torvalds } 110*6f52ac29SPeter Oberparleiter ps->cu_type = vm_vdev_to_cu_type(diag_data.vrdcvcla, 111*6f52ac29SPeter Oberparleiter diag_data.vrdcvtyp); 112*6f52ac29SPeter Oberparleiter if (ps->cu_type != 0xffff) 113*6f52ac29SPeter Oberparleiter return 0; 1141da177e4SLinus Torvalds } 115*6f52ac29SPeter Oberparleiter 1161da177e4SLinus Torvalds CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):" 1171da177e4SLinus Torvalds "vdev class : %02X, vdev type : %04X \n ... " 1181da177e4SLinus Torvalds "rdev class : %02X, rdev type : %04X, " 1191da177e4SLinus Torvalds "rdev model: %02X\n", 1201da177e4SLinus Torvalds devno, ccode, 1211da177e4SLinus Torvalds diag_data.vrdcvcla, diag_data.vrdcvtyp, 1221da177e4SLinus Torvalds diag_data.vrdcrccl, diag_data.vrdccrty, 1231da177e4SLinus Torvalds diag_data.vrdccrmd); 124*6f52ac29SPeter Oberparleiter 125*6f52ac29SPeter Oberparleiter return -ENODEV; 1261da177e4SLinus Torvalds } 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds /* 1291da177e4SLinus Torvalds * Start Sense ID helper function. 1301da177e4SLinus Torvalds * Try to obtain the 'control unit'/'device type' information 1311da177e4SLinus Torvalds * associated with the subchannel. 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds static int 1341da177e4SLinus Torvalds __ccw_device_sense_id_start(struct ccw_device *cdev) 1351da177e4SLinus Torvalds { 1361da177e4SLinus Torvalds struct subchannel *sch; 1371da177e4SLinus Torvalds struct ccw1 *ccw; 138c94dec99SCornelia Huck int ret; 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 1411da177e4SLinus Torvalds /* Setup sense channel program. */ 1421da177e4SLinus Torvalds ccw = cdev->private->iccws; 1431da177e4SLinus Torvalds ccw->cmd_code = CCW_CMD_SENSE_ID; 1441da177e4SLinus Torvalds ccw->cda = (__u32) __pa (&cdev->private->senseid); 1451da177e4SLinus Torvalds ccw->count = sizeof (struct senseid); 1461da177e4SLinus Torvalds ccw->flags = CCW_FLAG_SLI; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds /* Reset device status. */ 1491da177e4SLinus Torvalds memset(&cdev->private->irb, 0, sizeof(struct irb)); 1503b8c8899SPeter Oberparleiter 151c94dec99SCornelia Huck /* Try on every path. */ 152c94dec99SCornelia Huck ret = -ENODEV; 153c94dec99SCornelia Huck while (cdev->private->imask != 0) { 154*6f52ac29SPeter Oberparleiter cdev->private->senseid.cu_type = 0xFFFF; 155c94dec99SCornelia Huck if ((sch->opm & cdev->private->imask) != 0 && 156c94dec99SCornelia Huck cdev->private->iretry > 0) { 157c94dec99SCornelia Huck cdev->private->iretry--; 158c94dec99SCornelia Huck /* Reset internal retry indication. */ 159c94dec99SCornelia Huck cdev->private->flags.intretry = 0; 160c94dec99SCornelia Huck ret = cio_start (sch, cdev->private->iccws, 161c94dec99SCornelia Huck cdev->private->imask); 162c94dec99SCornelia Huck /* ret is 0, -EBUSY, -EACCES or -ENODEV */ 163c94dec99SCornelia Huck if (ret != -EACCES) 164c94dec99SCornelia Huck return ret; 165c94dec99SCornelia Huck } 166c94dec99SCornelia Huck cdev->private->imask >>= 1; 167c94dec99SCornelia Huck cdev->private->iretry = 5; 168c94dec99SCornelia Huck } 169c94dec99SCornelia Huck return ret; 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds void 1731da177e4SLinus Torvalds ccw_device_sense_id_start(struct ccw_device *cdev) 1741da177e4SLinus Torvalds { 1751da177e4SLinus Torvalds int ret; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds memset (&cdev->private->senseid, 0, sizeof (struct senseid)); 178c94dec99SCornelia Huck cdev->private->imask = 0x80; 179c94dec99SCornelia Huck cdev->private->iretry = 5; 1801da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 1811da177e4SLinus Torvalds if (ret && ret != -EBUSY) 1821da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 1831da177e4SLinus Torvalds } 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds /* 1861da177e4SLinus Torvalds * Called from interrupt context to check if a valid answer 1871da177e4SLinus Torvalds * to Sense ID was received. 1881da177e4SLinus Torvalds */ 1891da177e4SLinus Torvalds static int 1901da177e4SLinus Torvalds ccw_device_check_sense_id(struct ccw_device *cdev) 1911da177e4SLinus Torvalds { 1921da177e4SLinus Torvalds struct subchannel *sch; 1931da177e4SLinus Torvalds struct irb *irb; 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 1961da177e4SLinus Torvalds irb = &cdev->private->irb; 197*6f52ac29SPeter Oberparleiter 1981da177e4SLinus Torvalds /* Check the error cases. */ 199d23861ffSCornelia Huck if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { 200d23861ffSCornelia Huck /* Retry Sense ID if requested. */ 201d23861ffSCornelia Huck if (cdev->private->flags.intretry) { 202d23861ffSCornelia Huck cdev->private->flags.intretry = 0; 203d23861ffSCornelia Huck return -EAGAIN; 204d23861ffSCornelia Huck } 2051da177e4SLinus Torvalds return -ETIME; 206d23861ffSCornelia Huck } 2071da177e4SLinus Torvalds if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) { 2081da177e4SLinus Torvalds /* 2091da177e4SLinus Torvalds * if the device doesn't support the SenseID 2101da177e4SLinus Torvalds * command further retries wouldn't help ... 2111da177e4SLinus Torvalds * NB: We don't check here for intervention required like we 2121da177e4SLinus Torvalds * did before, because tape devices with no tape inserted 2131da177e4SLinus Torvalds * may present this status *in conjunction with* the 2141da177e4SLinus Torvalds * sense id information. So, for intervention required, 2151da177e4SLinus Torvalds * we use the "whack it until it talks" strategy... 2161da177e4SLinus Torvalds */ 217fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel " 218fb6958a5SCornelia Huck "0.%x.%04x reports cmd reject\n", 21978964268SCornelia Huck cdev->private->dev_id.devno, sch->schid.ssid, 220fb6958a5SCornelia Huck sch->schid.sch_no); 2211da177e4SLinus Torvalds return -EOPNOTSUPP; 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds if (irb->esw.esw0.erw.cons) { 224fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, " 2251da177e4SLinus Torvalds "lpum %02X, cnt %02d, sns :" 2261da177e4SLinus Torvalds " %02X%02X%02X%02X %02X%02X%02X%02X ...\n", 22778964268SCornelia Huck cdev->private->dev_id.ssid, 22878964268SCornelia Huck cdev->private->dev_id.devno, 2291da177e4SLinus Torvalds irb->esw.esw0.sublog.lpum, 2301da177e4SLinus Torvalds irb->esw.esw0.erw.scnt, 2311da177e4SLinus Torvalds irb->ecw[0], irb->ecw[1], 2321da177e4SLinus Torvalds irb->ecw[2], irb->ecw[3], 2331da177e4SLinus Torvalds irb->ecw[4], irb->ecw[5], 2341da177e4SLinus Torvalds irb->ecw[6], irb->ecw[7]); 2351da177e4SLinus Torvalds return -EAGAIN; 2361da177e4SLinus Torvalds } 2371da177e4SLinus Torvalds if (irb->scsw.cc == 3) { 238cd6b4f27SCornelia Huck u8 lpm; 239cd6b4f27SCornelia Huck 240cd6b4f27SCornelia Huck lpm = to_io_private(sch)->orb.lpm; 241cd6b4f27SCornelia Huck if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0) 242fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x " 243fb6958a5SCornelia Huck "on subchannel 0.%x.%04x is " 244cd6b4f27SCornelia Huck "'not operational'\n", lpm, 24578964268SCornelia Huck cdev->private->dev_id.devno, 24678964268SCornelia Huck sch->schid.ssid, sch->schid.sch_no); 2471da177e4SLinus Torvalds return -EACCES; 2481da177e4SLinus Torvalds } 249*6f52ac29SPeter Oberparleiter 250*6f52ac29SPeter Oberparleiter /* Did we get a proper answer ? */ 251*6f52ac29SPeter Oberparleiter if (irb->scsw.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF && 252*6f52ac29SPeter Oberparleiter cdev->private->senseid.reserved == 0xFF) { 253*6f52ac29SPeter Oberparleiter if (irb->scsw.count < sizeof(struct senseid) - 8) 254*6f52ac29SPeter Oberparleiter cdev->private->flags.esid = 1; 255*6f52ac29SPeter Oberparleiter return 0; /* Success */ 256*6f52ac29SPeter Oberparleiter } 257*6f52ac29SPeter Oberparleiter 2581da177e4SLinus Torvalds /* Hmm, whatever happened, try again. */ 2591da177e4SLinus Torvalds CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on " 260fb6958a5SCornelia Huck "subchannel 0.%x.%04x returns status %02X%02X\n", 26178964268SCornelia Huck cdev->private->dev_id.devno, sch->schid.ssid, 26278964268SCornelia Huck sch->schid.sch_no, 2631da177e4SLinus Torvalds irb->scsw.dstat, irb->scsw.cstat); 2641da177e4SLinus Torvalds return -EAGAIN; 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* 2681da177e4SLinus Torvalds * Got interrupt for Sense ID. 2691da177e4SLinus Torvalds */ 2701da177e4SLinus Torvalds void 2711da177e4SLinus Torvalds ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event) 2721da177e4SLinus Torvalds { 2731da177e4SLinus Torvalds struct subchannel *sch; 2741da177e4SLinus Torvalds struct irb *irb; 2751da177e4SLinus Torvalds int ret; 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 2781da177e4SLinus Torvalds irb = (struct irb *) __LC_IRB; 2791da177e4SLinus Torvalds /* Retry sense id, if needed. */ 2801da177e4SLinus Torvalds if (irb->scsw.stctl == 2811da177e4SLinus Torvalds (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 2821da177e4SLinus Torvalds if ((irb->scsw.cc == 1) || !irb->scsw.actl) { 2831da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 2841da177e4SLinus Torvalds if (ret && ret != -EBUSY) 2851da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds return; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds if (ccw_device_accumulate_and_sense(cdev, irb) != 0) 2901da177e4SLinus Torvalds return; 2911da177e4SLinus Torvalds ret = ccw_device_check_sense_id(cdev); 2921da177e4SLinus Torvalds memset(&cdev->private->irb, 0, sizeof(struct irb)); 2931da177e4SLinus Torvalds switch (ret) { 2941da177e4SLinus Torvalds /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */ 2951da177e4SLinus Torvalds case 0: /* Sense id succeeded. */ 2961da177e4SLinus Torvalds case -ETIME: /* Sense id stopped by timeout. */ 2971da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 2981da177e4SLinus Torvalds break; 2991da177e4SLinus Torvalds case -EACCES: /* channel is not operational. */ 300c94dec99SCornelia Huck sch->lpm &= ~cdev->private->imask; 301c94dec99SCornelia Huck cdev->private->imask >>= 1; 302c94dec99SCornelia Huck cdev->private->iretry = 5; 303c94dec99SCornelia Huck /* fall through. */ 3041da177e4SLinus Torvalds case -EAGAIN: /* try again. */ 3051da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 3061da177e4SLinus Torvalds if (ret == 0 || ret == -EBUSY) 3071da177e4SLinus Torvalds break; 3081da177e4SLinus Torvalds /* fall through. */ 3091da177e4SLinus Torvalds default: /* Sense ID failed. Try asking VM. */ 310*6f52ac29SPeter Oberparleiter if (MACHINE_IS_VM) 311*6f52ac29SPeter Oberparleiter ret = diag_get_dev_info(cdev->private->dev_id.devno, 3121da177e4SLinus Torvalds &cdev->private->senseid); 313*6f52ac29SPeter Oberparleiter else 3141da177e4SLinus Torvalds /* 3151da177e4SLinus Torvalds * If we can't couldn't identify the device type we 3161da177e4SLinus Torvalds * consider the device "not operational". 3171da177e4SLinus Torvalds */ 318*6f52ac29SPeter Oberparleiter ret = -ENODEV; 319*6f52ac29SPeter Oberparleiter 320*6f52ac29SPeter Oberparleiter ccw_device_sense_id_done(cdev, ret); 3211da177e4SLinus Torvalds break; 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds } 324