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>
15 #include <asm/ccwdev.h>
16 #include <asm/delay.h>
18 #include <asm/lowcore.h>
21 #include "cio_debug.h"
27 * diag210 is used under VM to get information about a virtual device
31 diag210(struct diag210 * addr)
34 * diag 210 needs its data below the 2GB border, so we
35 * use a static data area to be sure
37 static struct diag210 diag210_tmp;
38 static DEFINE_SPINLOCK(diag210_lock);
42 spin_lock_irqsave(&diag210_lock, flags);
52 ".section __ex_table,\"a\"\n"
56 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
59 spin_unlock_irqrestore(&diag210_lock, flags);
65 diag210(struct diag210 * addr)
75 ".section __ex_table,\"a\"\n"
79 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
87 * devno - device number
88 * ps - pointer to sense ID data area
92 VM_virtual_device_info (__u16 devno, struct senseid *ps)
95 int vrdcvcla, vrdcvtyp, cu_type;
97 { 0x08, 0x01, 0x3480 },
98 { 0x08, 0x02, 0x3430 },
99 { 0x08, 0x10, 0x3420 },
100 { 0x08, 0x42, 0x3424 },
101 { 0x08, 0x44, 0x9348 },
102 { 0x08, 0x81, 0x3490 },
103 { 0x08, 0x82, 0x3422 },
104 { 0x10, 0x41, 0x1403 },
105 { 0x10, 0x42, 0x3211 },
106 { 0x10, 0x43, 0x3203 },
107 { 0x10, 0x45, 0x3800 },
108 { 0x10, 0x47, 0x3262 },
109 { 0x10, 0x48, 0x3820 },
110 { 0x10, 0x49, 0x3800 },
111 { 0x10, 0x4a, 0x4245 },
112 { 0x10, 0x4b, 0x4248 },
113 { 0x10, 0x4d, 0x3800 },
114 { 0x10, 0x4e, 0x3820 },
115 { 0x10, 0x4f, 0x3820 },
116 { 0x10, 0x82, 0x2540 },
117 { 0x10, 0x84, 0x3525 },
118 { 0x20, 0x81, 0x2501 },
119 { 0x20, 0x82, 0x2540 },
120 { 0x20, 0x84, 0x3505 },
121 { 0x40, 0x01, 0x3278 },
122 { 0x40, 0x04, 0x3277 },
123 { 0x40, 0x80, 0x2250 },
124 { 0x40, 0xc0, 0x5080 },
125 { 0x80, 0x00, 0x3215 },
127 struct diag210 diag_data;
130 CIO_TRACE_EVENT (4, "VMvdinf");
132 diag_data = (struct diag210) {
134 .vrdclen = sizeof (diag_data),
137 ccode = diag210 (&diag_data);
140 /* Special case for bloody osa devices. */
141 if (diag_data.vrdcvcla == 0x02 &&
142 diag_data.vrdcvtyp == 0x20) {
143 ps->cu_type = 0x3088;
147 for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
148 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
149 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
150 ps->cu_type = vm_devices[i].cu_type;
153 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
154 "vdev class : %02X, vdev type : %04X \n ... "
155 "rdev class : %02X, rdev type : %04X, "
156 "rdev model: %02X\n",
158 diag_data.vrdcvcla, diag_data.vrdcvtyp,
159 diag_data.vrdcrccl, diag_data.vrdccrty,
164 * Start Sense ID helper function.
165 * Try to obtain the 'control unit'/'device type' information
166 * associated with the subchannel.
169 __ccw_device_sense_id_start(struct ccw_device *cdev)
171 struct subchannel *sch;
175 sch = to_subchannel(cdev->dev.parent);
176 /* Setup sense channel program. */
177 ccw = cdev->private->iccws;
178 if (sch->schib.pmcw.pim != 0x80) {
179 /* more than one path installed. */
180 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
183 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
186 ccw->cmd_code = CCW_CMD_SENSE_ID;
187 ccw->cda = (__u32) __pa (&cdev->private->senseid);
188 ccw->count = sizeof (struct senseid);
189 ccw->flags = CCW_FLAG_SLI;
191 /* Reset device status. */
192 memset(&cdev->private->irb, 0, sizeof(struct irb));
194 /* Try on every path. */
196 while (cdev->private->imask != 0) {
197 if ((sch->opm & cdev->private->imask) != 0 &&
198 cdev->private->iretry > 0) {
199 cdev->private->iretry--;
200 ret = cio_start (sch, cdev->private->iccws,
201 cdev->private->imask);
202 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
206 cdev->private->imask >>= 1;
207 cdev->private->iretry = 5;
213 ccw_device_sense_id_start(struct ccw_device *cdev)
217 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
218 cdev->private->senseid.cu_type = 0xFFFF;
219 cdev->private->imask = 0x80;
220 cdev->private->iretry = 5;
221 ret = __ccw_device_sense_id_start(cdev);
222 if (ret && ret != -EBUSY)
223 ccw_device_sense_id_done(cdev, ret);
227 * Called from interrupt context to check if a valid answer
228 * to Sense ID was received.
231 ccw_device_check_sense_id(struct ccw_device *cdev)
233 struct subchannel *sch;
236 sch = to_subchannel(cdev->dev.parent);
237 irb = &cdev->private->irb;
238 /* Did we get a proper answer ? */
239 if (cdev->private->senseid.cu_type != 0xFFFF &&
240 cdev->private->senseid.reserved == 0xFF) {
241 if (irb->scsw.count < sizeof (struct senseid) - 8)
242 cdev->private->flags.esid = 1;
243 return 0; /* Success */
245 /* Check the error cases. */
246 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
248 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
250 * if the device doesn't support the SenseID
251 * command further retries wouldn't help ...
252 * NB: We don't check here for intervention required like we
253 * did before, because tape devices with no tape inserted
254 * may present this status *in conjunction with* the
255 * sense id information. So, for intervention required,
256 * we use the "whack it until it talks" strategy...
258 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
259 "0.%x.%04x reports cmd reject\n",
260 cdev->private->devno, sch->schid.ssid,
264 if (irb->esw.esw0.erw.cons) {
265 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
266 "lpum %02X, cnt %02d, sns :"
267 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
268 cdev->private->ssid, cdev->private->devno,
269 irb->esw.esw0.sublog.lpum,
270 irb->esw.esw0.erw.scnt,
271 irb->ecw[0], irb->ecw[1],
272 irb->ecw[2], irb->ecw[3],
273 irb->ecw[4], irb->ecw[5],
274 irb->ecw[6], irb->ecw[7]);
277 if (irb->scsw.cc == 3) {
279 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
280 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
281 "on subchannel 0.%x.%04x is "
282 "'not operational'\n", sch->orb.lpm,
283 cdev->private->devno, sch->schid.ssid,
287 /* Hmm, whatever happened, try again. */
288 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
289 "subchannel 0.%x.%04x returns status %02X%02X\n",
290 cdev->private->devno, sch->schid.ssid, sch->schid.sch_no,
291 irb->scsw.dstat, irb->scsw.cstat);
296 * Got interrupt for Sense ID.
299 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
301 struct subchannel *sch;
305 sch = to_subchannel(cdev->dev.parent);
306 irb = (struct irb *) __LC_IRB;
307 /* Retry sense id, if needed. */
308 if (irb->scsw.stctl ==
309 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
310 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
311 ret = __ccw_device_sense_id_start(cdev);
312 if (ret && ret != -EBUSY)
313 ccw_device_sense_id_done(cdev, ret);
317 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
319 ret = ccw_device_check_sense_id(cdev);
320 memset(&cdev->private->irb, 0, sizeof(struct irb));
322 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
323 case 0: /* Sense id succeeded. */
324 case -ETIME: /* Sense id stopped by timeout. */
325 ccw_device_sense_id_done(cdev, ret);
327 case -EACCES: /* channel is not operational. */
328 sch->lpm &= ~cdev->private->imask;
329 cdev->private->imask >>= 1;
330 cdev->private->iretry = 5;
332 case -EAGAIN: /* try again. */
333 ret = __ccw_device_sense_id_start(cdev);
334 if (ret == 0 || ret == -EBUSY)
337 default: /* Sense ID failed. Try asking VM. */
339 VM_virtual_device_info (cdev->private->devno,
340 &cdev->private->senseid);
341 if (cdev->private->senseid.cu_type != 0xFFFF) {
342 /* Got the device information from VM. */
343 ccw_device_sense_id_done(cdev, 0);
348 * If we can't couldn't identify the device type we
349 * consider the device "not operational".
351 ccw_device_sense_id_done(cdev, -ENODEV);
356 EXPORT_SYMBOL(diag210);