2 * drivers/s390/cio/device_id.c
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * Author(s): Cornelia Huck(cohuck@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
30 #ifdef CONFIG_ARCH_S390X
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 %04x "
260 "reports cmd reject\n",
261 cdev
->private->devno
, sch
->irq
);
264 if (irb
->esw
.esw0
.erw
.cons
) {
265 CIO_MSG_EVENT(2, "SenseID : UC on dev %04x, "
266 "lpum %02X, cnt %02d, sns :"
267 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
268 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 on"
281 " subchannel %04x is 'not operational'\n",
282 sch
->orb
.lpm
, cdev
->private->devno
,
286 /* Hmm, whatever happened, try again. */
287 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
288 "subchannel %04x returns status %02X%02X\n",
289 cdev
->private->devno
, sch
->irq
,
290 irb
->scsw
.dstat
, irb
->scsw
.cstat
);
295 * Got interrupt for Sense ID.
298 ccw_device_sense_id_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
300 struct subchannel
*sch
;
304 sch
= to_subchannel(cdev
->dev
.parent
);
305 irb
= (struct irb
*) __LC_IRB
;
306 /* Retry sense id, if needed. */
307 if (irb
->scsw
.stctl
==
308 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
309 if ((irb
->scsw
.cc
== 1) || !irb
->scsw
.actl
) {
310 ret
= __ccw_device_sense_id_start(cdev
);
311 if (ret
&& ret
!= -EBUSY
)
312 ccw_device_sense_id_done(cdev
, ret
);
316 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
318 ret
= ccw_device_check_sense_id(cdev
);
319 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
321 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
322 case 0: /* Sense id succeeded. */
323 case -ETIME
: /* Sense id stopped by timeout. */
324 ccw_device_sense_id_done(cdev
, ret
);
326 case -EACCES
: /* channel is not operational. */
327 sch
->lpm
&= ~cdev
->private->imask
;
328 cdev
->private->imask
>>= 1;
329 cdev
->private->iretry
= 5;
331 case -EAGAIN
: /* try again. */
332 ret
= __ccw_device_sense_id_start(cdev
);
333 if (ret
== 0 || ret
== -EBUSY
)
336 default: /* Sense ID failed. Try asking VM. */
338 VM_virtual_device_info (cdev
->private->devno
,
339 &cdev
->private->senseid
);
340 if (cdev
->private->senseid
.cu_type
!= 0xFFFF) {
341 /* Got the device information from VM. */
342 ccw_device_sense_id_done(cdev
, 0);
347 * If we can't couldn't identify the device type we
348 * consider the device "not operational".
350 ccw_device_sense_id_done(cdev
, -ENODEV
);
355 EXPORT_SYMBOL(diag210
);