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
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
);
54 : "=&d" (ccode
) : "a" (__pa(&diag210_tmp
)) : "cc", "memory");
57 spin_unlock_irqrestore(&diag210_lock
, flags
);
63 diag210(struct diag210
* addr
)
74 : "=&d" (ccode
) : "a" (__pa(addr
)) : "cc", "memory");
82 * devno - device number
83 * ps - pointer to sense ID data area
87 VM_virtual_device_info (__u16 devno
, struct senseid
*ps
)
90 int vrdcvcla
, vrdcvtyp
, cu_type
;
92 { 0x08, 0x01, 0x3480 },
93 { 0x08, 0x02, 0x3430 },
94 { 0x08, 0x10, 0x3420 },
95 { 0x08, 0x42, 0x3424 },
96 { 0x08, 0x44, 0x9348 },
97 { 0x08, 0x81, 0x3490 },
98 { 0x08, 0x82, 0x3422 },
99 { 0x10, 0x41, 0x1403 },
100 { 0x10, 0x42, 0x3211 },
101 { 0x10, 0x43, 0x3203 },
102 { 0x10, 0x45, 0x3800 },
103 { 0x10, 0x47, 0x3262 },
104 { 0x10, 0x48, 0x3820 },
105 { 0x10, 0x49, 0x3800 },
106 { 0x10, 0x4a, 0x4245 },
107 { 0x10, 0x4b, 0x4248 },
108 { 0x10, 0x4d, 0x3800 },
109 { 0x10, 0x4e, 0x3820 },
110 { 0x10, 0x4f, 0x3820 },
111 { 0x10, 0x82, 0x2540 },
112 { 0x10, 0x84, 0x3525 },
113 { 0x20, 0x81, 0x2501 },
114 { 0x20, 0x82, 0x2540 },
115 { 0x20, 0x84, 0x3505 },
116 { 0x40, 0x01, 0x3278 },
117 { 0x40, 0x04, 0x3277 },
118 { 0x40, 0x80, 0x2250 },
119 { 0x40, 0xc0, 0x5080 },
120 { 0x80, 0x00, 0x3215 },
122 struct diag210 diag_data
;
125 CIO_TRACE_EVENT (4, "VMvdinf");
127 diag_data
= (struct diag210
) {
129 .vrdclen
= sizeof (diag_data
),
132 ccode
= diag210 (&diag_data
);
135 /* Special case for bloody osa devices. */
136 if (diag_data
.vrdcvcla
== 0x02 &&
137 diag_data
.vrdcvtyp
== 0x20) {
138 ps
->cu_type
= 0x3088;
142 for (i
= 0; i
< ARRAY_SIZE(vm_devices
); i
++)
143 if (diag_data
.vrdcvcla
== vm_devices
[i
].vrdcvcla
&&
144 diag_data
.vrdcvtyp
== vm_devices
[i
].vrdcvtyp
) {
145 ps
->cu_type
= vm_devices
[i
].cu_type
;
148 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
149 "vdev class : %02X, vdev type : %04X \n ... "
150 "rdev class : %02X, rdev type : %04X, "
151 "rdev model: %02X\n",
153 diag_data
.vrdcvcla
, diag_data
.vrdcvtyp
,
154 diag_data
.vrdcrccl
, diag_data
.vrdccrty
,
159 * Start Sense ID helper function.
160 * Try to obtain the 'control unit'/'device type' information
161 * associated with the subchannel.
164 __ccw_device_sense_id_start(struct ccw_device
*cdev
)
166 struct subchannel
*sch
;
170 sch
= to_subchannel(cdev
->dev
.parent
);
171 /* Setup sense channel program. */
172 ccw
= cdev
->private->iccws
;
173 if (sch
->schib
.pmcw
.pim
!= 0x80) {
174 /* more than one path installed. */
175 ccw
->cmd_code
= CCW_CMD_SUSPEND_RECONN
;
178 ccw
->flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
181 ccw
->cmd_code
= CCW_CMD_SENSE_ID
;
182 ccw
->cda
= (__u32
) __pa (&cdev
->private->senseid
);
183 ccw
->count
= sizeof (struct senseid
);
184 ccw
->flags
= CCW_FLAG_SLI
;
186 /* Reset device status. */
187 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
189 /* Try on every path. */
191 while (cdev
->private->imask
!= 0) {
192 if ((sch
->opm
& cdev
->private->imask
) != 0 &&
193 cdev
->private->iretry
> 0) {
194 cdev
->private->iretry
--;
195 /* Reset internal retry indication. */
196 cdev
->private->flags
.intretry
= 0;
197 ret
= cio_start (sch
, cdev
->private->iccws
,
198 cdev
->private->imask
);
199 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
203 cdev
->private->imask
>>= 1;
204 cdev
->private->iretry
= 5;
210 ccw_device_sense_id_start(struct ccw_device
*cdev
)
214 memset (&cdev
->private->senseid
, 0, sizeof (struct senseid
));
215 cdev
->private->senseid
.cu_type
= 0xFFFF;
216 cdev
->private->imask
= 0x80;
217 cdev
->private->iretry
= 5;
218 ret
= __ccw_device_sense_id_start(cdev
);
219 if (ret
&& ret
!= -EBUSY
)
220 ccw_device_sense_id_done(cdev
, ret
);
224 * Called from interrupt context to check if a valid answer
225 * to Sense ID was received.
228 ccw_device_check_sense_id(struct ccw_device
*cdev
)
230 struct subchannel
*sch
;
233 sch
= to_subchannel(cdev
->dev
.parent
);
234 irb
= &cdev
->private->irb
;
235 /* Did we get a proper answer ? */
236 if (cdev
->private->senseid
.cu_type
!= 0xFFFF &&
237 cdev
->private->senseid
.reserved
== 0xFF) {
238 if (irb
->scsw
.count
< sizeof (struct senseid
) - 8)
239 cdev
->private->flags
.esid
= 1;
240 return 0; /* Success */
242 /* Check the error cases. */
243 if (irb
->scsw
.fctl
& (SCSW_FCTL_HALT_FUNC
| SCSW_FCTL_CLEAR_FUNC
)) {
244 /* Retry Sense ID if requested. */
245 if (cdev
->private->flags
.intretry
) {
246 cdev
->private->flags
.intretry
= 0;
251 if (irb
->esw
.esw0
.erw
.cons
&& (irb
->ecw
[0] & SNS0_CMD_REJECT
)) {
253 * if the device doesn't support the SenseID
254 * command further retries wouldn't help ...
255 * NB: We don't check here for intervention required like we
256 * did before, because tape devices with no tape inserted
257 * may present this status *in conjunction with* the
258 * sense id information. So, for intervention required,
259 * we use the "whack it until it talks" strategy...
261 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
262 "0.%x.%04x reports cmd reject\n",
263 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
267 if (irb
->esw
.esw0
.erw
.cons
) {
268 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
269 "lpum %02X, cnt %02d, sns :"
270 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
271 cdev
->private->dev_id
.ssid
,
272 cdev
->private->dev_id
.devno
,
273 irb
->esw
.esw0
.sublog
.lpum
,
274 irb
->esw
.esw0
.erw
.scnt
,
275 irb
->ecw
[0], irb
->ecw
[1],
276 irb
->ecw
[2], irb
->ecw
[3],
277 irb
->ecw
[4], irb
->ecw
[5],
278 irb
->ecw
[6], irb
->ecw
[7]);
281 if (irb
->scsw
.cc
== 3) {
283 sch
->schib
.pmcw
.pim
& sch
->schib
.pmcw
.pam
) != 0)
284 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
285 "on subchannel 0.%x.%04x is "
286 "'not operational'\n", sch
->orb
.lpm
,
287 cdev
->private->dev_id
.devno
,
288 sch
->schid
.ssid
, sch
->schid
.sch_no
);
291 /* Hmm, whatever happened, try again. */
292 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
293 "subchannel 0.%x.%04x returns status %02X%02X\n",
294 cdev
->private->dev_id
.devno
, sch
->schid
.ssid
,
296 irb
->scsw
.dstat
, irb
->scsw
.cstat
);
301 * Got interrupt for Sense ID.
304 ccw_device_sense_id_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
306 struct subchannel
*sch
;
310 sch
= to_subchannel(cdev
->dev
.parent
);
311 irb
= (struct irb
*) __LC_IRB
;
312 /* Retry sense id, if needed. */
313 if (irb
->scsw
.stctl
==
314 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
315 if ((irb
->scsw
.cc
== 1) || !irb
->scsw
.actl
) {
316 ret
= __ccw_device_sense_id_start(cdev
);
317 if (ret
&& ret
!= -EBUSY
)
318 ccw_device_sense_id_done(cdev
, ret
);
322 if (ccw_device_accumulate_and_sense(cdev
, irb
) != 0)
324 ret
= ccw_device_check_sense_id(cdev
);
325 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
327 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
328 case 0: /* Sense id succeeded. */
329 case -ETIME
: /* Sense id stopped by timeout. */
330 ccw_device_sense_id_done(cdev
, ret
);
332 case -EACCES
: /* channel is not operational. */
333 sch
->lpm
&= ~cdev
->private->imask
;
334 cdev
->private->imask
>>= 1;
335 cdev
->private->iretry
= 5;
337 case -EAGAIN
: /* try again. */
338 ret
= __ccw_device_sense_id_start(cdev
);
339 if (ret
== 0 || ret
== -EBUSY
)
342 default: /* Sense ID failed. Try asking VM. */
344 VM_virtual_device_info (cdev
->private->dev_id
.devno
,
345 &cdev
->private->senseid
);
346 if (cdev
->private->senseid
.cu_type
!= 0xFFFF) {
347 /* Got the device information from VM. */
348 ccw_device_sense_id_done(cdev
, 0);
353 * If we can't couldn't identify the device type we
354 * consider the device "not operational".
356 ccw_device_sense_id_done(cdev
, -ENODEV
);
361 EXPORT_SYMBOL(diag210
);