Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  CCW device SENSE ID I/O handling.
0004  *
0005  *    Copyright IBM Corp. 2002, 2009
0006  *    Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
0007  *       Martin Schwidefsky <schwidefsky@de.ibm.com>
0008  *       Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
0009  */
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/string.h>
0013 #include <linux/types.h>
0014 #include <linux/errno.h>
0015 #include <asm/ccwdev.h>
0016 #include <asm/setup.h>
0017 #include <asm/cio.h>
0018 #include <asm/diag.h>
0019 
0020 #include "cio.h"
0021 #include "cio_debug.h"
0022 #include "device.h"
0023 #include "io_sch.h"
0024 
0025 #define SENSE_ID_RETRIES    256
0026 #define SENSE_ID_TIMEOUT    (10 * HZ)
0027 #define SENSE_ID_MIN_LEN    4
0028 #define SENSE_ID_BASIC_LEN  7
0029 
0030 /**
0031  * diag210_to_senseid - convert diag 0x210 data to sense id information
0032  * @senseid: sense id
0033  * @diag: diag 0x210 data
0034  *
0035  * Return 0 on success, non-zero otherwise.
0036  */
0037 static int diag210_to_senseid(struct senseid *senseid, struct diag210 *diag)
0038 {
0039     static struct {
0040         int class, type, cu_type;
0041     } vm_devices[] = {
0042         { 0x08, 0x01, 0x3480 },
0043         { 0x08, 0x02, 0x3430 },
0044         { 0x08, 0x10, 0x3420 },
0045         { 0x08, 0x42, 0x3424 },
0046         { 0x08, 0x44, 0x9348 },
0047         { 0x08, 0x81, 0x3490 },
0048         { 0x08, 0x82, 0x3422 },
0049         { 0x10, 0x41, 0x1403 },
0050         { 0x10, 0x42, 0x3211 },
0051         { 0x10, 0x43, 0x3203 },
0052         { 0x10, 0x45, 0x3800 },
0053         { 0x10, 0x47, 0x3262 },
0054         { 0x10, 0x48, 0x3820 },
0055         { 0x10, 0x49, 0x3800 },
0056         { 0x10, 0x4a, 0x4245 },
0057         { 0x10, 0x4b, 0x4248 },
0058         { 0x10, 0x4d, 0x3800 },
0059         { 0x10, 0x4e, 0x3820 },
0060         { 0x10, 0x4f, 0x3820 },
0061         { 0x10, 0x82, 0x2540 },
0062         { 0x10, 0x84, 0x3525 },
0063         { 0x20, 0x81, 0x2501 },
0064         { 0x20, 0x82, 0x2540 },
0065         { 0x20, 0x84, 0x3505 },
0066         { 0x40, 0x01, 0x3278 },
0067         { 0x40, 0x04, 0x3277 },
0068         { 0x40, 0x80, 0x2250 },
0069         { 0x40, 0xc0, 0x5080 },
0070         { 0x80, 0x00, 0x3215 },
0071     };
0072     int i;
0073 
0074     /* Special case for osa devices. */
0075     if (diag->vrdcvcla == 0x02 && diag->vrdcvtyp == 0x20) {
0076         senseid->cu_type = 0x3088;
0077         senseid->cu_model = 0x60;
0078         senseid->reserved = 0xff;
0079         return 0;
0080     }
0081     for (i = 0; i < ARRAY_SIZE(vm_devices); i++) {
0082         if (diag->vrdcvcla == vm_devices[i].class &&
0083             diag->vrdcvtyp == vm_devices[i].type) {
0084             senseid->cu_type = vm_devices[i].cu_type;
0085             senseid->reserved = 0xff;
0086             return 0;
0087         }
0088     }
0089 
0090     return -ENODEV;
0091 }
0092 
0093 /**
0094  * diag210_get_dev_info - retrieve device information via diag 0x210
0095  * @cdev: ccw device
0096  *
0097  * Returns zero on success, non-zero otherwise.
0098  */
0099 static int diag210_get_dev_info(struct ccw_device *cdev)
0100 {
0101     struct ccw_dev_id *dev_id = &cdev->private->dev_id;
0102     struct senseid *senseid = &cdev->private->dma_area->senseid;
0103     struct diag210 diag_data;
0104     int rc;
0105 
0106     if (dev_id->ssid != 0)
0107         return -ENODEV;
0108     memset(&diag_data, 0, sizeof(diag_data));
0109     diag_data.vrdcdvno  = dev_id->devno;
0110     diag_data.vrdclen   = sizeof(diag_data);
0111     rc = diag210(&diag_data);
0112     CIO_TRACE_EVENT(4, "diag210");
0113     CIO_HEX_EVENT(4, &rc, sizeof(rc));
0114     CIO_HEX_EVENT(4, &diag_data, sizeof(diag_data));
0115     if (rc != 0 && rc != 2)
0116         goto err_failed;
0117     if (diag210_to_senseid(senseid, &diag_data))
0118         goto err_unknown;
0119     return 0;
0120 
0121 err_unknown:
0122     CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: unknown diag210 data\n",
0123               dev_id->ssid, dev_id->devno);
0124     return -ENODEV;
0125 err_failed:
0126     CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: diag210 failed (rc=%d)\n",
0127               dev_id->ssid, dev_id->devno, rc);
0128     return -ENODEV;
0129 }
0130 
0131 /*
0132  * Initialize SENSE ID data.
0133  */
0134 static void snsid_init(struct ccw_device *cdev)
0135 {
0136     cdev->private->flags.esid = 0;
0137 
0138     memset(&cdev->private->dma_area->senseid, 0,
0139            sizeof(cdev->private->dma_area->senseid));
0140     cdev->private->dma_area->senseid.cu_type = 0xffff;
0141 }
0142 
0143 /*
0144  * Check for complete SENSE ID data.
0145  */
0146 static int snsid_check(struct ccw_device *cdev, void *data)
0147 {
0148     struct cmd_scsw *scsw = &cdev->private->dma_area->irb.scsw.cmd;
0149     int len = sizeof(struct senseid) - scsw->count;
0150 
0151     /* Check for incomplete SENSE ID data. */
0152     if (len < SENSE_ID_MIN_LEN)
0153         goto out_restart;
0154     if (cdev->private->dma_area->senseid.cu_type == 0xffff)
0155         goto out_restart;
0156     /* Check for incompatible SENSE ID data. */
0157     if (cdev->private->dma_area->senseid.reserved != 0xff)
0158         return -EOPNOTSUPP;
0159     /* Check for extended-identification information. */
0160     if (len > SENSE_ID_BASIC_LEN)
0161         cdev->private->flags.esid = 1;
0162     return 0;
0163 
0164 out_restart:
0165     snsid_init(cdev);
0166     return -EAGAIN;
0167 }
0168 
0169 /*
0170  * Process SENSE ID request result.
0171  */
0172 static void snsid_callback(struct ccw_device *cdev, void *data, int rc)
0173 {
0174     struct ccw_dev_id *id = &cdev->private->dev_id;
0175     struct senseid *senseid = &cdev->private->dma_area->senseid;
0176     int vm = 0;
0177 
0178     if (rc && MACHINE_IS_VM) {
0179         /* Try diag 0x210 fallback on z/VM. */
0180         snsid_init(cdev);
0181         if (diag210_get_dev_info(cdev) == 0) {
0182             rc = 0;
0183             vm = 1;
0184         }
0185     }
0186     CIO_MSG_EVENT(2, "snsid: device 0.%x.%04x: rc=%d %04x/%02x "
0187               "%04x/%02x%s\n", id->ssid, id->devno, rc,
0188               senseid->cu_type, senseid->cu_model, senseid->dev_type,
0189               senseid->dev_model, vm ? " (diag210)" : "");
0190     ccw_device_sense_id_done(cdev, rc);
0191 }
0192 
0193 /**
0194  * ccw_device_sense_id_start - perform SENSE ID
0195  * @cdev: ccw device
0196  *
0197  * Execute a SENSE ID channel program on @cdev to update its sense id
0198  * information. When finished, call ccw_device_sense_id_done with a
0199  * return code specifying the result.
0200  */
0201 void ccw_device_sense_id_start(struct ccw_device *cdev)
0202 {
0203     struct subchannel *sch = to_subchannel(cdev->dev.parent);
0204     struct ccw_request *req = &cdev->private->req;
0205     struct ccw1 *cp = cdev->private->dma_area->iccws;
0206 
0207     CIO_TRACE_EVENT(4, "snsid");
0208     CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
0209     /* Data setup. */
0210     snsid_init(cdev);
0211     /* Channel program setup. */
0212     cp->cmd_code    = CCW_CMD_SENSE_ID;
0213     cp->cda     = (u32) (addr_t) &cdev->private->dma_area->senseid;
0214     cp->count   = sizeof(struct senseid);
0215     cp->flags   = CCW_FLAG_SLI;
0216     /* Request setup. */
0217     memset(req, 0, sizeof(*req));
0218     req->cp     = cp;
0219     req->timeout    = SENSE_ID_TIMEOUT;
0220     req->maxretries = SENSE_ID_RETRIES;
0221     req->lpm    = sch->schib.pmcw.pam & sch->opm;
0222     req->check  = snsid_check;
0223     req->callback   = snsid_callback;
0224     ccw_request_start(cdev);
0225 }