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