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> 20*0a87c5cfSMichael 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" 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * Input : 301da177e4SLinus Torvalds * devno - device number 311da177e4SLinus Torvalds * ps - pointer to sense ID data area 321da177e4SLinus Torvalds * Output : none 331da177e4SLinus Torvalds */ 341da177e4SLinus Torvalds static void 351da177e4SLinus Torvalds VM_virtual_device_info (__u16 devno, struct senseid *ps) 361da177e4SLinus Torvalds { 371da177e4SLinus Torvalds static struct { 381da177e4SLinus Torvalds int vrdcvcla, vrdcvtyp, cu_type; 391da177e4SLinus Torvalds } vm_devices[] = { 401da177e4SLinus Torvalds { 0x08, 0x01, 0x3480 }, 411da177e4SLinus Torvalds { 0x08, 0x02, 0x3430 }, 421da177e4SLinus Torvalds { 0x08, 0x10, 0x3420 }, 431da177e4SLinus Torvalds { 0x08, 0x42, 0x3424 }, 441da177e4SLinus Torvalds { 0x08, 0x44, 0x9348 }, 451da177e4SLinus Torvalds { 0x08, 0x81, 0x3490 }, 461da177e4SLinus Torvalds { 0x08, 0x82, 0x3422 }, 471da177e4SLinus Torvalds { 0x10, 0x41, 0x1403 }, 481da177e4SLinus Torvalds { 0x10, 0x42, 0x3211 }, 491da177e4SLinus Torvalds { 0x10, 0x43, 0x3203 }, 501da177e4SLinus Torvalds { 0x10, 0x45, 0x3800 }, 511da177e4SLinus Torvalds { 0x10, 0x47, 0x3262 }, 521da177e4SLinus Torvalds { 0x10, 0x48, 0x3820 }, 531da177e4SLinus Torvalds { 0x10, 0x49, 0x3800 }, 541da177e4SLinus Torvalds { 0x10, 0x4a, 0x4245 }, 551da177e4SLinus Torvalds { 0x10, 0x4b, 0x4248 }, 561da177e4SLinus Torvalds { 0x10, 0x4d, 0x3800 }, 571da177e4SLinus Torvalds { 0x10, 0x4e, 0x3820 }, 581da177e4SLinus Torvalds { 0x10, 0x4f, 0x3820 }, 591da177e4SLinus Torvalds { 0x10, 0x82, 0x2540 }, 601da177e4SLinus Torvalds { 0x10, 0x84, 0x3525 }, 611da177e4SLinus Torvalds { 0x20, 0x81, 0x2501 }, 621da177e4SLinus Torvalds { 0x20, 0x82, 0x2540 }, 631da177e4SLinus Torvalds { 0x20, 0x84, 0x3505 }, 641da177e4SLinus Torvalds { 0x40, 0x01, 0x3278 }, 651da177e4SLinus Torvalds { 0x40, 0x04, 0x3277 }, 661da177e4SLinus Torvalds { 0x40, 0x80, 0x2250 }, 671da177e4SLinus Torvalds { 0x40, 0xc0, 0x5080 }, 681da177e4SLinus Torvalds { 0x80, 0x00, 0x3215 }, 691da177e4SLinus Torvalds }; 701da177e4SLinus Torvalds struct diag210 diag_data; 711da177e4SLinus Torvalds int ccode, i; 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds CIO_TRACE_EVENT (4, "VMvdinf"); 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds diag_data = (struct diag210) { 761da177e4SLinus Torvalds .vrdcdvno = devno, 771da177e4SLinus Torvalds .vrdclen = sizeof (diag_data), 781da177e4SLinus Torvalds }; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds ccode = diag210 (&diag_data); 811da177e4SLinus Torvalds ps->reserved = 0xff; 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* Special case for bloody osa devices. */ 841da177e4SLinus Torvalds if (diag_data.vrdcvcla == 0x02 && 851da177e4SLinus Torvalds diag_data.vrdcvtyp == 0x20) { 861da177e4SLinus Torvalds ps->cu_type = 0x3088; 871da177e4SLinus Torvalds ps->cu_model = 0x60; 881da177e4SLinus Torvalds return; 891da177e4SLinus Torvalds } 90045236abSAhmed S. Darwish for (i = 0; i < ARRAY_SIZE(vm_devices); i++) 911da177e4SLinus Torvalds if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla && 921da177e4SLinus Torvalds diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) { 931da177e4SLinus Torvalds ps->cu_type = vm_devices[i].cu_type; 941da177e4SLinus Torvalds return; 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):" 971da177e4SLinus Torvalds "vdev class : %02X, vdev type : %04X \n ... " 981da177e4SLinus Torvalds "rdev class : %02X, rdev type : %04X, " 991da177e4SLinus Torvalds "rdev model: %02X\n", 1001da177e4SLinus Torvalds devno, ccode, 1011da177e4SLinus Torvalds diag_data.vrdcvcla, diag_data.vrdcvtyp, 1021da177e4SLinus Torvalds diag_data.vrdcrccl, diag_data.vrdccrty, 1031da177e4SLinus Torvalds diag_data.vrdccrmd); 1041da177e4SLinus Torvalds } 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds /* 1071da177e4SLinus Torvalds * Start Sense ID helper function. 1081da177e4SLinus Torvalds * Try to obtain the 'control unit'/'device type' information 1091da177e4SLinus Torvalds * associated with the subchannel. 1101da177e4SLinus Torvalds */ 1111da177e4SLinus Torvalds static int 1121da177e4SLinus Torvalds __ccw_device_sense_id_start(struct ccw_device *cdev) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds struct subchannel *sch; 1151da177e4SLinus Torvalds struct ccw1 *ccw; 1161da177e4SLinus Torvalds int ret; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 1191da177e4SLinus Torvalds /* Setup sense channel program. */ 1201da177e4SLinus Torvalds ccw = cdev->private->iccws; 1211da177e4SLinus Torvalds if (sch->schib.pmcw.pim != 0x80) { 1221da177e4SLinus Torvalds /* more than one path installed. */ 1231da177e4SLinus Torvalds ccw->cmd_code = CCW_CMD_SUSPEND_RECONN; 1241da177e4SLinus Torvalds ccw->cda = 0; 1251da177e4SLinus Torvalds ccw->count = 0; 1261da177e4SLinus Torvalds ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC; 1271da177e4SLinus Torvalds ccw++; 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds ccw->cmd_code = CCW_CMD_SENSE_ID; 1301da177e4SLinus Torvalds ccw->cda = (__u32) __pa (&cdev->private->senseid); 1311da177e4SLinus Torvalds ccw->count = sizeof (struct senseid); 1321da177e4SLinus Torvalds ccw->flags = CCW_FLAG_SLI; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds /* Reset device status. */ 1351da177e4SLinus Torvalds memset(&cdev->private->irb, 0, sizeof(struct irb)); 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds /* Try on every path. */ 1381da177e4SLinus Torvalds ret = -ENODEV; 1391da177e4SLinus Torvalds while (cdev->private->imask != 0) { 1401da177e4SLinus Torvalds if ((sch->opm & cdev->private->imask) != 0 && 1411da177e4SLinus Torvalds cdev->private->iretry > 0) { 1421da177e4SLinus Torvalds cdev->private->iretry--; 143d23861ffSCornelia Huck /* Reset internal retry indication. */ 144d23861ffSCornelia Huck cdev->private->flags.intretry = 0; 1451da177e4SLinus Torvalds ret = cio_start (sch, cdev->private->iccws, 1461da177e4SLinus Torvalds cdev->private->imask); 1471da177e4SLinus Torvalds /* ret is 0, -EBUSY, -EACCES or -ENODEV */ 1481da177e4SLinus Torvalds if (ret != -EACCES) 1491da177e4SLinus Torvalds return ret; 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds cdev->private->imask >>= 1; 1521da177e4SLinus Torvalds cdev->private->iretry = 5; 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds return ret; 1551da177e4SLinus Torvalds } 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds void 1581da177e4SLinus Torvalds ccw_device_sense_id_start(struct ccw_device *cdev) 1591da177e4SLinus Torvalds { 1601da177e4SLinus Torvalds int ret; 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds memset (&cdev->private->senseid, 0, sizeof (struct senseid)); 1631da177e4SLinus Torvalds cdev->private->senseid.cu_type = 0xFFFF; 1641da177e4SLinus Torvalds cdev->private->imask = 0x80; 1651da177e4SLinus Torvalds cdev->private->iretry = 5; 1661da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 1671da177e4SLinus Torvalds if (ret && ret != -EBUSY) 1681da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds /* 1721da177e4SLinus Torvalds * Called from interrupt context to check if a valid answer 1731da177e4SLinus Torvalds * to Sense ID was received. 1741da177e4SLinus Torvalds */ 1751da177e4SLinus Torvalds static int 1761da177e4SLinus Torvalds ccw_device_check_sense_id(struct ccw_device *cdev) 1771da177e4SLinus Torvalds { 1781da177e4SLinus Torvalds struct subchannel *sch; 1791da177e4SLinus Torvalds struct irb *irb; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 1821da177e4SLinus Torvalds irb = &cdev->private->irb; 1831da177e4SLinus Torvalds /* Did we get a proper answer ? */ 1841da177e4SLinus Torvalds if (cdev->private->senseid.cu_type != 0xFFFF && 1851da177e4SLinus Torvalds cdev->private->senseid.reserved == 0xFF) { 1861da177e4SLinus Torvalds if (irb->scsw.count < sizeof (struct senseid) - 8) 1871da177e4SLinus Torvalds cdev->private->flags.esid = 1; 1881da177e4SLinus Torvalds return 0; /* Success */ 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds /* Check the error cases. */ 191d23861ffSCornelia Huck if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { 192d23861ffSCornelia Huck /* Retry Sense ID if requested. */ 193d23861ffSCornelia Huck if (cdev->private->flags.intretry) { 194d23861ffSCornelia Huck cdev->private->flags.intretry = 0; 195d23861ffSCornelia Huck return -EAGAIN; 196d23861ffSCornelia Huck } 1971da177e4SLinus Torvalds return -ETIME; 198d23861ffSCornelia Huck } 1991da177e4SLinus Torvalds if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) { 2001da177e4SLinus Torvalds /* 2011da177e4SLinus Torvalds * if the device doesn't support the SenseID 2021da177e4SLinus Torvalds * command further retries wouldn't help ... 2031da177e4SLinus Torvalds * NB: We don't check here for intervention required like we 2041da177e4SLinus Torvalds * did before, because tape devices with no tape inserted 2051da177e4SLinus Torvalds * may present this status *in conjunction with* the 2061da177e4SLinus Torvalds * sense id information. So, for intervention required, 2071da177e4SLinus Torvalds * we use the "whack it until it talks" strategy... 2081da177e4SLinus Torvalds */ 209fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel " 210fb6958a5SCornelia Huck "0.%x.%04x reports cmd reject\n", 21178964268SCornelia Huck cdev->private->dev_id.devno, sch->schid.ssid, 212fb6958a5SCornelia Huck sch->schid.sch_no); 2131da177e4SLinus Torvalds return -EOPNOTSUPP; 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds if (irb->esw.esw0.erw.cons) { 216fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, " 2171da177e4SLinus Torvalds "lpum %02X, cnt %02d, sns :" 2181da177e4SLinus Torvalds " %02X%02X%02X%02X %02X%02X%02X%02X ...\n", 21978964268SCornelia Huck cdev->private->dev_id.ssid, 22078964268SCornelia Huck cdev->private->dev_id.devno, 2211da177e4SLinus Torvalds irb->esw.esw0.sublog.lpum, 2221da177e4SLinus Torvalds irb->esw.esw0.erw.scnt, 2231da177e4SLinus Torvalds irb->ecw[0], irb->ecw[1], 2241da177e4SLinus Torvalds irb->ecw[2], irb->ecw[3], 2251da177e4SLinus Torvalds irb->ecw[4], irb->ecw[5], 2261da177e4SLinus Torvalds irb->ecw[6], irb->ecw[7]); 2271da177e4SLinus Torvalds return -EAGAIN; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds if (irb->scsw.cc == 3) { 2301da177e4SLinus Torvalds if ((sch->orb.lpm & 2311da177e4SLinus Torvalds sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0) 232fb6958a5SCornelia Huck CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x " 233fb6958a5SCornelia Huck "on subchannel 0.%x.%04x is " 234fb6958a5SCornelia Huck "'not operational'\n", sch->orb.lpm, 23578964268SCornelia Huck cdev->private->dev_id.devno, 23678964268SCornelia Huck sch->schid.ssid, sch->schid.sch_no); 2371da177e4SLinus Torvalds return -EACCES; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds /* Hmm, whatever happened, try again. */ 2401da177e4SLinus Torvalds CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on " 241fb6958a5SCornelia Huck "subchannel 0.%x.%04x returns status %02X%02X\n", 24278964268SCornelia Huck cdev->private->dev_id.devno, sch->schid.ssid, 24378964268SCornelia Huck sch->schid.sch_no, 2441da177e4SLinus Torvalds irb->scsw.dstat, irb->scsw.cstat); 2451da177e4SLinus Torvalds return -EAGAIN; 2461da177e4SLinus Torvalds } 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds /* 2491da177e4SLinus Torvalds * Got interrupt for Sense ID. 2501da177e4SLinus Torvalds */ 2511da177e4SLinus Torvalds void 2521da177e4SLinus Torvalds ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event) 2531da177e4SLinus Torvalds { 2541da177e4SLinus Torvalds struct subchannel *sch; 2551da177e4SLinus Torvalds struct irb *irb; 2561da177e4SLinus Torvalds int ret; 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds sch = to_subchannel(cdev->dev.parent); 2591da177e4SLinus Torvalds irb = (struct irb *) __LC_IRB; 2601da177e4SLinus Torvalds /* Retry sense id, if needed. */ 2611da177e4SLinus Torvalds if (irb->scsw.stctl == 2621da177e4SLinus Torvalds (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 2631da177e4SLinus Torvalds if ((irb->scsw.cc == 1) || !irb->scsw.actl) { 2641da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 2651da177e4SLinus Torvalds if (ret && ret != -EBUSY) 2661da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 2671da177e4SLinus Torvalds } 2681da177e4SLinus Torvalds return; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds if (ccw_device_accumulate_and_sense(cdev, irb) != 0) 2711da177e4SLinus Torvalds return; 2721da177e4SLinus Torvalds ret = ccw_device_check_sense_id(cdev); 2731da177e4SLinus Torvalds memset(&cdev->private->irb, 0, sizeof(struct irb)); 2741da177e4SLinus Torvalds switch (ret) { 2751da177e4SLinus Torvalds /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */ 2761da177e4SLinus Torvalds case 0: /* Sense id succeeded. */ 2771da177e4SLinus Torvalds case -ETIME: /* Sense id stopped by timeout. */ 2781da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, ret); 2791da177e4SLinus Torvalds break; 2801da177e4SLinus Torvalds case -EACCES: /* channel is not operational. */ 2811da177e4SLinus Torvalds sch->lpm &= ~cdev->private->imask; 2821da177e4SLinus Torvalds cdev->private->imask >>= 1; 2831da177e4SLinus Torvalds cdev->private->iretry = 5; 2841da177e4SLinus Torvalds /* fall through. */ 2851da177e4SLinus Torvalds case -EAGAIN: /* try again. */ 2861da177e4SLinus Torvalds ret = __ccw_device_sense_id_start(cdev); 2871da177e4SLinus Torvalds if (ret == 0 || ret == -EBUSY) 2881da177e4SLinus Torvalds break; 2891da177e4SLinus Torvalds /* fall through. */ 2901da177e4SLinus Torvalds default: /* Sense ID failed. Try asking VM. */ 2911da177e4SLinus Torvalds if (MACHINE_IS_VM) { 29278964268SCornelia Huck VM_virtual_device_info (cdev->private->dev_id.devno, 2931da177e4SLinus Torvalds &cdev->private->senseid); 2941da177e4SLinus Torvalds if (cdev->private->senseid.cu_type != 0xFFFF) { 2951da177e4SLinus Torvalds /* Got the device information from VM. */ 2961da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, 0); 2971da177e4SLinus Torvalds return; 2981da177e4SLinus Torvalds } 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds /* 3011da177e4SLinus Torvalds * If we can't couldn't identify the device type we 3021da177e4SLinus Torvalds * consider the device "not operational". 3031da177e4SLinus Torvalds */ 3041da177e4SLinus Torvalds ccw_device_sense_id_done(cdev, -ENODEV); 3051da177e4SLinus Torvalds break; 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds } 308