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>
22 #include "cio_debug.h"
28 * 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);
54 : "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
63 : "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
67 spin_unlock_irqrestore(&diag210_lock, flags);
74 * devno - device number
75 * ps - pointer to sense ID data area
79 VM_virtual_device_info (__u16 devno, struct senseid *ps)
82 int vrdcvcla, vrdcvtyp, cu_type;
84 { 0x08, 0x01, 0x3480 },
85 { 0x08, 0x02, 0x3430 },
86 { 0x08, 0x10, 0x3420 },
87 { 0x08, 0x42, 0x3424 },
88 { 0x08, 0x44, 0x9348 },
89 { 0x08, 0x81, 0x3490 },
90 { 0x08, 0x82, 0x3422 },
91 { 0x10, 0x41, 0x1403 },
92 { 0x10, 0x42, 0x3211 },
93 { 0x10, 0x43, 0x3203 },
94 { 0x10, 0x45, 0x3800 },
95 { 0x10, 0x47, 0x3262 },
96 { 0x10, 0x48, 0x3820 },
97 { 0x10, 0x49, 0x3800 },
98 { 0x10, 0x4a, 0x4245 },
99 { 0x10, 0x4b, 0x4248 },
100 { 0x10, 0x4d, 0x3800 },
101 { 0x10, 0x4e, 0x3820 },
102 { 0x10, 0x4f, 0x3820 },
103 { 0x10, 0x82, 0x2540 },
104 { 0x10, 0x84, 0x3525 },
105 { 0x20, 0x81, 0x2501 },
106 { 0x20, 0x82, 0x2540 },
107 { 0x20, 0x84, 0x3505 },
108 { 0x40, 0x01, 0x3278 },
109 { 0x40, 0x04, 0x3277 },
110 { 0x40, 0x80, 0x2250 },
111 { 0x40, 0xc0, 0x5080 },
112 { 0x80, 0x00, 0x3215 },
114 struct diag210 diag_data;
117 CIO_TRACE_EVENT (4, "VMvdinf");
119 diag_data = (struct diag210) {
121 .vrdclen = sizeof (diag_data),
124 ccode = diag210 (&diag_data);
127 /* Special case for bloody osa devices. */
128 if (diag_data.vrdcvcla == 0x02 &&
129 diag_data.vrdcvtyp == 0x20) {
130 ps->cu_type = 0x3088;
134 for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
135 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
136 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
137 ps->cu_type = vm_devices[i].cu_type;
140 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
141 "vdev class : %02X, vdev type : %04X \n ... "
142 "rdev class : %02X, rdev type : %04X, "
143 "rdev model: %02X\n",
145 diag_data.vrdcvcla, diag_data.vrdcvtyp,
146 diag_data.vrdcrccl, diag_data.vrdccrty,
151 * Start Sense ID helper function.
152 * Try to obtain the 'control unit'/'device type' information
153 * associated with the subchannel.
156 __ccw_device_sense_id_start(struct ccw_device *cdev)
158 struct subchannel *sch;
162 sch = to_subchannel(cdev->dev.parent);
163 /* Setup sense channel program. */
164 ccw = cdev->private->iccws;
165 if (sch->schib.pmcw.pim != 0x80) {
166 /* more than one path installed. */
167 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
170 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
173 ccw->cmd_code = CCW_CMD_SENSE_ID;
174 ccw->cda = (__u32) __pa (&cdev->private->senseid);
175 ccw->count = sizeof (struct senseid);
176 ccw->flags = CCW_FLAG_SLI;
178 /* Reset device status. */
179 memset(&cdev->private->irb, 0, sizeof(struct irb));
181 /* Try on every path. */
183 while (cdev->private->imask != 0) {
184 if ((sch->opm & cdev->private->imask) != 0 &&
185 cdev->private->iretry > 0) {
186 cdev->private->iretry--;
187 /* Reset internal retry indication. */
188 cdev->private->flags.intretry = 0;
189 ret = cio_start (sch, cdev->private->iccws,
190 cdev->private->imask);
191 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
195 cdev->private->imask >>= 1;
196 cdev->private->iretry = 5;
202 ccw_device_sense_id_start(struct ccw_device *cdev)
206 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
207 cdev->private->senseid.cu_type = 0xFFFF;
208 cdev->private->imask = 0x80;
209 cdev->private->iretry = 5;
210 ret = __ccw_device_sense_id_start(cdev);
211 if (ret && ret != -EBUSY)
212 ccw_device_sense_id_done(cdev, ret);
216 * Called from interrupt context to check if a valid answer
217 * to Sense ID was received.
220 ccw_device_check_sense_id(struct ccw_device *cdev)
222 struct subchannel *sch;
225 sch = to_subchannel(cdev->dev.parent);
226 irb = &cdev->private->irb;
227 /* Did we get a proper answer ? */
228 if (cdev->private->senseid.cu_type != 0xFFFF &&
229 cdev->private->senseid.reserved == 0xFF) {
230 if (irb->scsw.count < sizeof (struct senseid) - 8)
231 cdev->private->flags.esid = 1;
232 return 0; /* Success */
234 /* Check the error cases. */
235 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
236 /* Retry Sense ID if requested. */
237 if (cdev->private->flags.intretry) {
238 cdev->private->flags.intretry = 0;
243 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
245 * if the device doesn't support the SenseID
246 * command further retries wouldn't help ...
247 * NB: We don't check here for intervention required like we
248 * did before, because tape devices with no tape inserted
249 * may present this status *in conjunction with* the
250 * sense id information. So, for intervention required,
251 * we use the "whack it until it talks" strategy...
253 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
254 "0.%x.%04x reports cmd reject\n",
255 cdev->private->dev_id.devno, sch->schid.ssid,
259 if (irb->esw.esw0.erw.cons) {
260 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
261 "lpum %02X, cnt %02d, sns :"
262 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
263 cdev->private->dev_id.ssid,
264 cdev->private->dev_id.devno,
265 irb->esw.esw0.sublog.lpum,
266 irb->esw.esw0.erw.scnt,
267 irb->ecw[0], irb->ecw[1],
268 irb->ecw[2], irb->ecw[3],
269 irb->ecw[4], irb->ecw[5],
270 irb->ecw[6], irb->ecw[7]);
273 if (irb->scsw.cc == 3) {
275 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
276 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
277 "on subchannel 0.%x.%04x is "
278 "'not operational'\n", sch->orb.lpm,
279 cdev->private->dev_id.devno,
280 sch->schid.ssid, sch->schid.sch_no);
283 /* Hmm, whatever happened, try again. */
284 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
285 "subchannel 0.%x.%04x returns status %02X%02X\n",
286 cdev->private->dev_id.devno, sch->schid.ssid,
288 irb->scsw.dstat, irb->scsw.cstat);
293 * Got interrupt for Sense ID.
296 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
298 struct subchannel *sch;
302 sch = to_subchannel(cdev->dev.parent);
303 irb = (struct irb *) __LC_IRB;
304 /* Retry sense id, if needed. */
305 if (irb->scsw.stctl ==
306 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
307 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
308 ret = __ccw_device_sense_id_start(cdev);
309 if (ret && ret != -EBUSY)
310 ccw_device_sense_id_done(cdev, ret);
314 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
316 ret = ccw_device_check_sense_id(cdev);
317 memset(&cdev->private->irb, 0, sizeof(struct irb));
319 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
320 case 0: /* Sense id succeeded. */
321 case -ETIME: /* Sense id stopped by timeout. */
322 ccw_device_sense_id_done(cdev, ret);
324 case -EACCES: /* channel is not operational. */
325 sch->lpm &= ~cdev->private->imask;
326 cdev->private->imask >>= 1;
327 cdev->private->iretry = 5;
329 case -EAGAIN: /* try again. */
330 ret = __ccw_device_sense_id_start(cdev);
331 if (ret == 0 || ret == -EBUSY)
334 default: /* Sense ID failed. Try asking VM. */
336 VM_virtual_device_info (cdev->private->dev_id.devno,
337 &cdev->private->senseid);
338 if (cdev->private->senseid.cu_type != 0xFFFF) {
339 /* Got the device information from VM. */
340 ccw_device_sense_id_done(cdev, 0);
345 * If we can't couldn't identify the device type we
346 * consider the device "not operational".
348 ccw_device_sense_id_done(cdev, -ENODEV);
353 EXPORT_SYMBOL(diag210);