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/config.h>
14 #include <linux/init.h>
16 #include <asm/ccwdev.h>
17 #include <asm/delay.h>
19 #include <asm/lowcore.h>
22 #include "cio_debug.h"
28 * diag210 is used under VM to get information about a virtual device
32 diag210(struct diag210 * addr)
35 * diag 210 needs its data below the 2GB border, so we
36 * use a static data area to be sure
38 static struct diag210 diag210_tmp;
39 static DEFINE_SPINLOCK(diag210_lock);
43 spin_lock_irqsave(&diag210_lock, flags);
53 ".section __ex_table,\"a\"\n"
57 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
60 spin_unlock_irqrestore(&diag210_lock, flags);
66 diag210(struct diag210 * addr)
76 ".section __ex_table,\"a\"\n"
80 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
88 * devno - device number
89 * ps - pointer to sense ID data area
93 VM_virtual_device_info (__u16 devno, struct senseid *ps)
96 int vrdcvcla, vrdcvtyp, cu_type;
98 { 0x08, 0x01, 0x3480 },
99 { 0x08, 0x02, 0x3430 },
100 { 0x08, 0x10, 0x3420 },
101 { 0x08, 0x42, 0x3424 },
102 { 0x08, 0x44, 0x9348 },
103 { 0x08, 0x81, 0x3490 },
104 { 0x08, 0x82, 0x3422 },
105 { 0x10, 0x41, 0x1403 },
106 { 0x10, 0x42, 0x3211 },
107 { 0x10, 0x43, 0x3203 },
108 { 0x10, 0x45, 0x3800 },
109 { 0x10, 0x47, 0x3262 },
110 { 0x10, 0x48, 0x3820 },
111 { 0x10, 0x49, 0x3800 },
112 { 0x10, 0x4a, 0x4245 },
113 { 0x10, 0x4b, 0x4248 },
114 { 0x10, 0x4d, 0x3800 },
115 { 0x10, 0x4e, 0x3820 },
116 { 0x10, 0x4f, 0x3820 },
117 { 0x10, 0x82, 0x2540 },
118 { 0x10, 0x84, 0x3525 },
119 { 0x20, 0x81, 0x2501 },
120 { 0x20, 0x82, 0x2540 },
121 { 0x20, 0x84, 0x3505 },
122 { 0x40, 0x01, 0x3278 },
123 { 0x40, 0x04, 0x3277 },
124 { 0x40, 0x80, 0x2250 },
125 { 0x40, 0xc0, 0x5080 },
126 { 0x80, 0x00, 0x3215 },
128 struct diag210 diag_data;
131 CIO_TRACE_EVENT (4, "VMvdinf");
133 diag_data = (struct diag210) {
135 .vrdclen = sizeof (diag_data),
138 ccode = diag210 (&diag_data);
141 /* Special case for bloody osa devices. */
142 if (diag_data.vrdcvcla == 0x02 &&
143 diag_data.vrdcvtyp == 0x20) {
144 ps->cu_type = 0x3088;
148 for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
149 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
150 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
151 ps->cu_type = vm_devices[i].cu_type;
154 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
155 "vdev class : %02X, vdev type : %04X \n ... "
156 "rdev class : %02X, rdev type : %04X, "
157 "rdev model: %02X\n",
159 diag_data.vrdcvcla, diag_data.vrdcvtyp,
160 diag_data.vrdcrccl, diag_data.vrdccrty,
165 * Start Sense ID helper function.
166 * Try to obtain the 'control unit'/'device type' information
167 * associated with the subchannel.
170 __ccw_device_sense_id_start(struct ccw_device *cdev)
172 struct subchannel *sch;
176 sch = to_subchannel(cdev->dev.parent);
177 /* Setup sense channel program. */
178 ccw = cdev->private->iccws;
179 if (sch->schib.pmcw.pim != 0x80) {
180 /* more than one path installed. */
181 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
184 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
187 ccw->cmd_code = CCW_CMD_SENSE_ID;
188 ccw->cda = (__u32) __pa (&cdev->private->senseid);
189 ccw->count = sizeof (struct senseid);
190 ccw->flags = CCW_FLAG_SLI;
192 /* Reset device status. */
193 memset(&cdev->private->irb, 0, sizeof(struct irb));
195 /* Try on every path. */
197 while (cdev->private->imask != 0) {
198 if ((sch->opm & cdev->private->imask) != 0 &&
199 cdev->private->iretry > 0) {
200 cdev->private->iretry--;
201 ret = cio_start (sch, cdev->private->iccws,
202 cdev->private->imask);
203 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
207 cdev->private->imask >>= 1;
208 cdev->private->iretry = 5;
214 ccw_device_sense_id_start(struct ccw_device *cdev)
218 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
219 cdev->private->senseid.cu_type = 0xFFFF;
220 cdev->private->imask = 0x80;
221 cdev->private->iretry = 5;
222 ret = __ccw_device_sense_id_start(cdev);
223 if (ret && ret != -EBUSY)
224 ccw_device_sense_id_done(cdev, ret);
228 * Called from interrupt context to check if a valid answer
229 * to Sense ID was received.
232 ccw_device_check_sense_id(struct ccw_device *cdev)
234 struct subchannel *sch;
237 sch = to_subchannel(cdev->dev.parent);
238 irb = &cdev->private->irb;
239 /* Did we get a proper answer ? */
240 if (cdev->private->senseid.cu_type != 0xFFFF &&
241 cdev->private->senseid.reserved == 0xFF) {
242 if (irb->scsw.count < sizeof (struct senseid) - 8)
243 cdev->private->flags.esid = 1;
244 return 0; /* Success */
246 /* Check the error cases. */
247 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
249 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
251 * if the device doesn't support the SenseID
252 * command further retries wouldn't help ...
253 * NB: We don't check here for intervention required like we
254 * did before, because tape devices with no tape inserted
255 * may present this status *in conjunction with* the
256 * sense id information. So, for intervention required,
257 * we use the "whack it until it talks" strategy...
259 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
260 "0.%x.%04x reports cmd reject\n",
261 cdev->private->devno, sch->schid.ssid,
265 if (irb->esw.esw0.erw.cons) {
266 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
267 "lpum %02X, cnt %02d, sns :"
268 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
269 cdev->private->ssid, cdev->private->devno,
270 irb->esw.esw0.sublog.lpum,
271 irb->esw.esw0.erw.scnt,
272 irb->ecw[0], irb->ecw[1],
273 irb->ecw[2], irb->ecw[3],
274 irb->ecw[4], irb->ecw[5],
275 irb->ecw[6], irb->ecw[7]);
278 if (irb->scsw.cc == 3) {
280 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
281 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
282 "on subchannel 0.%x.%04x is "
283 "'not operational'\n", sch->orb.lpm,
284 cdev->private->devno, sch->schid.ssid,
288 /* Hmm, whatever happened, try again. */
289 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
290 "subchannel 0.%x.%04x returns status %02X%02X\n",
291 cdev->private->devno, sch->schid.ssid, sch->schid.sch_no,
292 irb->scsw.dstat, irb->scsw.cstat);
297 * Got interrupt for Sense ID.
300 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
302 struct subchannel *sch;
306 sch = to_subchannel(cdev->dev.parent);
307 irb = (struct irb *) __LC_IRB;
308 /* Retry sense id, if needed. */
309 if (irb->scsw.stctl ==
310 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
311 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
312 ret = __ccw_device_sense_id_start(cdev);
313 if (ret && ret != -EBUSY)
314 ccw_device_sense_id_done(cdev, ret);
318 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
320 ret = ccw_device_check_sense_id(cdev);
321 memset(&cdev->private->irb, 0, sizeof(struct irb));
323 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
324 case 0: /* Sense id succeeded. */
325 case -ETIME: /* Sense id stopped by timeout. */
326 ccw_device_sense_id_done(cdev, ret);
328 case -EACCES: /* channel is not operational. */
329 sch->lpm &= ~cdev->private->imask;
330 cdev->private->imask >>= 1;
331 cdev->private->iretry = 5;
333 case -EAGAIN: /* try again. */
334 ret = __ccw_device_sense_id_start(cdev);
335 if (ret == 0 || ret == -EBUSY)
338 default: /* Sense ID failed. Try asking VM. */
340 VM_virtual_device_info (cdev->private->devno,
341 &cdev->private->senseid);
342 if (cdev->private->senseid.cu_type != 0xFFFF) {
343 /* Got the device information from VM. */
344 ccw_device_sense_id_done(cdev, 0);
349 * If we can't couldn't identify the device type we
350 * consider the device "not operational".
352 ccw_device_sense_id_done(cdev, -ENODEV);
357 EXPORT_SYMBOL(diag210);