2 * drivers/s390/cio/device_id.c
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
16 #include <asm/ccwdev.h>
17 #include <asm/delay.h>
19 #include <asm/lowcore.h>
23 #include "cio_debug.h"
30 * devno - device number
31 * ps - pointer to sense ID data area
35 VM_virtual_device_info (__u16 devno, struct senseid *ps)
38 int vrdcvcla, vrdcvtyp, cu_type;
40 { 0x08, 0x01, 0x3480 },
41 { 0x08, 0x02, 0x3430 },
42 { 0x08, 0x10, 0x3420 },
43 { 0x08, 0x42, 0x3424 },
44 { 0x08, 0x44, 0x9348 },
45 { 0x08, 0x81, 0x3490 },
46 { 0x08, 0x82, 0x3422 },
47 { 0x10, 0x41, 0x1403 },
48 { 0x10, 0x42, 0x3211 },
49 { 0x10, 0x43, 0x3203 },
50 { 0x10, 0x45, 0x3800 },
51 { 0x10, 0x47, 0x3262 },
52 { 0x10, 0x48, 0x3820 },
53 { 0x10, 0x49, 0x3800 },
54 { 0x10, 0x4a, 0x4245 },
55 { 0x10, 0x4b, 0x4248 },
56 { 0x10, 0x4d, 0x3800 },
57 { 0x10, 0x4e, 0x3820 },
58 { 0x10, 0x4f, 0x3820 },
59 { 0x10, 0x82, 0x2540 },
60 { 0x10, 0x84, 0x3525 },
61 { 0x20, 0x81, 0x2501 },
62 { 0x20, 0x82, 0x2540 },
63 { 0x20, 0x84, 0x3505 },
64 { 0x40, 0x01, 0x3278 },
65 { 0x40, 0x04, 0x3277 },
66 { 0x40, 0x80, 0x2250 },
67 { 0x40, 0xc0, 0x5080 },
68 { 0x80, 0x00, 0x3215 },
70 struct diag210 diag_data;
73 CIO_TRACE_EVENT (4, "VMvdinf");
75 diag_data = (struct diag210) {
77 .vrdclen = sizeof (diag_data),
80 ccode = diag210 (&diag_data);
83 /* Special case for bloody osa devices. */
84 if (diag_data.vrdcvcla == 0x02 &&
85 diag_data.vrdcvtyp == 0x20) {
90 for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
91 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
92 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
93 ps->cu_type = vm_devices[i].cu_type;
96 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
97 "vdev class : %02X, vdev type : %04X \n ... "
98 "rdev class : %02X, rdev type : %04X, "
101 diag_data.vrdcvcla, diag_data.vrdcvtyp,
102 diag_data.vrdcrccl, diag_data.vrdccrty,
107 * Start Sense ID helper function.
108 * Try to obtain the 'control unit'/'device type' information
109 * associated with the subchannel.
112 __ccw_device_sense_id_start(struct ccw_device *cdev)
114 struct subchannel *sch;
117 sch = to_subchannel(cdev->dev.parent);
118 /* Setup sense channel program. */
119 ccw = cdev->private->iccws;
120 ccw->cmd_code = CCW_CMD_SENSE_ID;
121 ccw->cda = (__u32) __pa (&cdev->private->senseid);
122 ccw->count = sizeof (struct senseid);
123 ccw->flags = CCW_FLAG_SLI;
125 /* Reset device status. */
126 memset(&cdev->private->irb, 0, sizeof(struct irb));
127 cdev->private->flags.intretry = 0;
129 return cio_start(sch, ccw, LPM_ANYPATH);
133 ccw_device_sense_id_start(struct ccw_device *cdev)
137 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
138 cdev->private->senseid.cu_type = 0xFFFF;
139 cdev->private->iretry = 3;
140 ret = __ccw_device_sense_id_start(cdev);
141 if (ret && ret != -EBUSY)
142 ccw_device_sense_id_done(cdev, ret);
146 * Called from interrupt context to check if a valid answer
147 * to Sense ID was received.
150 ccw_device_check_sense_id(struct ccw_device *cdev)
152 struct subchannel *sch;
155 sch = to_subchannel(cdev->dev.parent);
156 irb = &cdev->private->irb;
157 /* Did we get a proper answer ? */
158 if (cdev->private->senseid.cu_type != 0xFFFF &&
159 cdev->private->senseid.reserved == 0xFF) {
160 if (irb->scsw.count < sizeof (struct senseid) - 8)
161 cdev->private->flags.esid = 1;
162 return 0; /* Success */
164 /* Check the error cases. */
165 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
166 /* Retry Sense ID if requested. */
167 if (cdev->private->flags.intretry) {
168 cdev->private->flags.intretry = 0;
173 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
175 * if the device doesn't support the SenseID
176 * command further retries wouldn't help ...
177 * NB: We don't check here for intervention required like we
178 * did before, because tape devices with no tape inserted
179 * may present this status *in conjunction with* the
180 * sense id information. So, for intervention required,
181 * we use the "whack it until it talks" strategy...
183 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
184 "0.%x.%04x reports cmd reject\n",
185 cdev->private->dev_id.devno, sch->schid.ssid,
189 if (irb->esw.esw0.erw.cons) {
190 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
191 "lpum %02X, cnt %02d, sns :"
192 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
193 cdev->private->dev_id.ssid,
194 cdev->private->dev_id.devno,
195 irb->esw.esw0.sublog.lpum,
196 irb->esw.esw0.erw.scnt,
197 irb->ecw[0], irb->ecw[1],
198 irb->ecw[2], irb->ecw[3],
199 irb->ecw[4], irb->ecw[5],
200 irb->ecw[6], irb->ecw[7]);
203 if (irb->scsw.cc == 3) {
205 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
206 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
207 "on subchannel 0.%x.%04x is "
208 "'not operational'\n", sch->orb.lpm,
209 cdev->private->dev_id.devno,
210 sch->schid.ssid, sch->schid.sch_no);
213 /* Hmm, whatever happened, try again. */
214 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
215 "subchannel 0.%x.%04x returns status %02X%02X\n",
216 cdev->private->dev_id.devno, sch->schid.ssid,
218 irb->scsw.dstat, irb->scsw.cstat);
223 * Got interrupt for Sense ID.
226 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
228 struct subchannel *sch;
232 sch = to_subchannel(cdev->dev.parent);
233 irb = (struct irb *) __LC_IRB;
234 /* Retry sense id, if needed. */
235 if (irb->scsw.stctl ==
236 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
237 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
238 ret = __ccw_device_sense_id_start(cdev);
239 if (ret && ret != -EBUSY)
240 ccw_device_sense_id_done(cdev, ret);
244 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
246 ret = ccw_device_check_sense_id(cdev);
247 memset(&cdev->private->irb, 0, sizeof(struct irb));
249 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
250 case 0: /* Sense id succeeded. */
251 case -ETIME: /* Sense id stopped by timeout. */
252 ccw_device_sense_id_done(cdev, ret);
254 case -EACCES: /* channel is not operational. */
255 case -EAGAIN: /* try again. */
256 cdev->private->iretry--;
257 if (cdev->private->iretry > 0) {
258 ret = __ccw_device_sense_id_start(cdev);
259 if (ret == 0 || ret == -EBUSY)
263 default: /* Sense ID failed. Try asking VM. */
265 VM_virtual_device_info (cdev->private->dev_id.devno,
266 &cdev->private->senseid);
267 if (cdev->private->senseid.cu_type != 0xFFFF) {
268 /* Got the device information from VM. */
269 ccw_device_sense_id_done(cdev, 0);
274 * If we can't couldn't identify the device type we
275 * consider the device "not operational".
277 ccw_device_sense_id_done(cdev, -ENODEV);