1 // SPDX-License-Identifier: GPL-2.0
3 * CCW device SENSE ID I/O handling.
5 * Copyright IBM Corp. 2002, 2009
6 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/errno.h>
15 #include <asm/machine.h>
16 #include <asm/ccwdev.h>
17 #include <asm/setup.h>
22 #include "cio_debug.h"
26 #define SENSE_ID_RETRIES 256
27 #define SENSE_ID_TIMEOUT (10 * HZ)
28 #define SENSE_ID_MIN_LEN 4
29 #define SENSE_ID_BASIC_LEN 7
32 * diag210_to_senseid - convert diag 0x210 data to sense id information
34 * @diag: diag 0x210 data
36 * Return 0 on success, non-zero otherwise.
38 static int diag210_to_senseid(struct senseid *senseid, struct diag210 *diag)
41 int class, type, cu_type;
43 { 0x08, 0x01, 0x3480 },
44 { 0x08, 0x02, 0x3430 },
45 { 0x08, 0x10, 0x3420 },
46 { 0x08, 0x42, 0x3424 },
47 { 0x08, 0x44, 0x9348 },
48 { 0x08, 0x81, 0x3490 },
49 { 0x08, 0x82, 0x3422 },
50 { 0x10, 0x41, 0x1403 },
51 { 0x10, 0x42, 0x3211 },
52 { 0x10, 0x43, 0x3203 },
53 { 0x10, 0x45, 0x3800 },
54 { 0x10, 0x47, 0x3262 },
55 { 0x10, 0x48, 0x3820 },
56 { 0x10, 0x49, 0x3800 },
57 { 0x10, 0x4a, 0x4245 },
58 { 0x10, 0x4b, 0x4248 },
59 { 0x10, 0x4d, 0x3800 },
60 { 0x10, 0x4e, 0x3820 },
61 { 0x10, 0x4f, 0x3820 },
62 { 0x10, 0x82, 0x2540 },
63 { 0x10, 0x84, 0x3525 },
64 { 0x20, 0x81, 0x2501 },
65 { 0x20, 0x82, 0x2540 },
66 { 0x20, 0x84, 0x3505 },
67 { 0x40, 0x01, 0x3278 },
68 { 0x40, 0x04, 0x3277 },
69 { 0x40, 0x80, 0x2250 },
70 { 0x40, 0xc0, 0x5080 },
71 { 0x80, 0x00, 0x3215 },
75 /* Special case for osa devices. */
76 if (diag->vrdcvcla == 0x02 && diag->vrdcvtyp == 0x20) {
77 senseid->cu_type = 0x3088;
78 senseid->cu_model = 0x60;
79 senseid->reserved = 0xff;
82 for (i = 0; i < ARRAY_SIZE(vm_devices); i++) {
83 if (diag->vrdcvcla == vm_devices[i].class &&
84 diag->vrdcvtyp == vm_devices[i].type) {
85 senseid->cu_type = vm_devices[i].cu_type;
86 senseid->reserved = 0xff;
95 * diag210_get_dev_info - retrieve device information via diag 0x210
98 * Returns zero on success, non-zero otherwise.
100 static int diag210_get_dev_info(struct ccw_device *cdev)
102 struct ccw_dev_id *dev_id = &cdev->private->dev_id;
103 struct senseid *senseid = &cdev->private->dma_area->senseid;
104 struct diag210 diag_data;
107 if (dev_id->ssid != 0)
109 memset(&diag_data, 0, sizeof(diag_data));
110 diag_data.vrdcdvno = dev_id->devno;
111 diag_data.vrdclen = sizeof(diag_data);
112 rc = diag210(&diag_data);
113 CIO_TRACE_EVENT(4, "diag210");
114 CIO_HEX_EVENT(4, &rc, sizeof(rc));
115 CIO_HEX_EVENT(4, &diag_data, sizeof(diag_data));
116 if (rc != 0 && rc != 2)
118 if (diag210_to_senseid(senseid, &diag_data))
123 CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: unknown diag210 data\n",
124 dev_id->ssid, dev_id->devno);
127 CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: diag210 failed (rc=%d)\n",
128 dev_id->ssid, dev_id->devno, rc);
133 * Initialize SENSE ID data.
135 static void snsid_init(struct ccw_device *cdev)
137 cdev->private->flags.esid = 0;
139 memset(&cdev->private->dma_area->senseid, 0,
140 sizeof(cdev->private->dma_area->senseid));
141 cdev->private->dma_area->senseid.cu_type = 0xffff;
145 * Check for complete SENSE ID data.
147 static int snsid_check(struct ccw_device *cdev, void *data)
149 struct cmd_scsw *scsw = &cdev->private->dma_area->irb.scsw.cmd;
150 int len = sizeof(struct senseid) - scsw->count;
152 /* Check for incomplete SENSE ID data. */
153 if (len < SENSE_ID_MIN_LEN)
155 if (cdev->private->dma_area->senseid.cu_type == 0xffff)
157 /* Check for incompatible SENSE ID data. */
158 if (cdev->private->dma_area->senseid.reserved != 0xff)
160 /* Check for extended-identification information. */
161 if (len > SENSE_ID_BASIC_LEN)
162 cdev->private->flags.esid = 1;
171 * Process SENSE ID request result.
173 static void snsid_callback(struct ccw_device *cdev, void *data, int rc)
175 struct ccw_dev_id *id = &cdev->private->dev_id;
176 struct senseid *senseid = &cdev->private->dma_area->senseid;
179 if (rc && machine_is_vm()) {
180 /* Try diag 0x210 fallback on z/VM. */
182 if (diag210_get_dev_info(cdev) == 0) {
187 CIO_MSG_EVENT(2, "snsid: device 0.%x.%04x: rc=%d %04x/%02x "
188 "%04x/%02x%s\n", id->ssid, id->devno, rc,
189 senseid->cu_type, senseid->cu_model, senseid->dev_type,
190 senseid->dev_model, vm ? " (diag210)" : "");
191 ccw_device_sense_id_done(cdev, rc);
195 * ccw_device_sense_id_start - perform SENSE ID
198 * Execute a SENSE ID channel program on @cdev to update its sense id
199 * information. When finished, call ccw_device_sense_id_done with a
200 * return code specifying the result.
202 void ccw_device_sense_id_start(struct ccw_device *cdev)
204 struct subchannel *sch = to_subchannel(cdev->dev.parent);
205 struct ccw_request *req = &cdev->private->req;
206 struct ccw1 *cp = cdev->private->dma_area->iccws;
208 CIO_TRACE_EVENT(4, "snsid");
209 CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
212 /* Channel program setup. */
213 cp->cmd_code = CCW_CMD_SENSE_ID;
214 cp->cda = virt_to_dma32(&cdev->private->dma_area->senseid);
215 cp->count = sizeof(struct senseid);
216 cp->flags = CCW_FLAG_SLI;
218 memset(req, 0, sizeof(*req));
220 req->timeout = SENSE_ID_TIMEOUT;
221 req->maxretries = SENSE_ID_RETRIES;
222 req->lpm = sch->schib.pmcw.pam & sch->opm;
223 req->check = snsid_check;
224 req->callback = snsid_callback;
225 ccw_request_start(cdev);