ACPI: thinkpad-acpi: improve dock subdriver initialization
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / s390 / cio / device_id.c
blobf17275917fe55a6598e1120b316e8e7695d76c45
1 /*
2 * drivers/s390/cio/device_id.c
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
5 * IBM Corporation
6 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Sense ID functions.
12 #include <linux/module.h>
13 #include <linux/init.h>
15 #include <asm/ccwdev.h>
16 #include <asm/delay.h>
17 #include <asm/cio.h>
18 #include <asm/lowcore.h>
20 #include "cio.h"
21 #include "cio_debug.h"
22 #include "css.h"
23 #include "device.h"
24 #include "ioasm.h"
27 * diag210 is used under VM to get information about a virtual device
29 #ifdef CONFIG_64BIT
30 int
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);
39 unsigned long flags;
40 int ccode;
42 spin_lock_irqsave(&diag210_lock, flags);
43 diag210_tmp = *addr;
45 asm volatile(
46 " lhi %0,-1\n"
47 " sam31\n"
48 " diag %1,0,0x210\n"
49 "0: ipm %0\n"
50 " srl %0,28\n"
51 "1: sam64\n"
52 EX_TABLE(0b,1b)
53 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory");
55 *addr = diag210_tmp;
56 spin_unlock_irqrestore(&diag210_lock, flags);
58 return ccode;
60 #else
61 int
62 diag210(struct diag210 * addr)
64 int ccode;
66 asm volatile(
67 " lhi %0,-1\n"
68 " diag %1,0,0x210\n"
69 "0: ipm %0\n"
70 " srl %0,28\n"
71 "1:\n"
72 EX_TABLE(0b,1b)
73 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory");
75 return ccode;
77 #endif
80 * Input :
81 * devno - device number
82 * ps - pointer to sense ID data area
83 * Output : none
85 static void
86 VM_virtual_device_info (__u16 devno, struct senseid *ps)
88 static struct {
89 int vrdcvcla, vrdcvtyp, cu_type;
90 } vm_devices[] = {
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;
122 int ccode, i;
124 CIO_TRACE_EVENT (4, "VMvdinf");
126 diag_data = (struct diag210) {
127 .vrdcdvno = devno,
128 .vrdclen = sizeof (diag_data),
131 ccode = diag210 (&diag_data);
132 ps->reserved = 0xff;
134 /* Special case for bloody osa devices. */
135 if (diag_data.vrdcvcla == 0x02 &&
136 diag_data.vrdcvtyp == 0x20) {
137 ps->cu_type = 0x3088;
138 ps->cu_model = 0x60;
139 return;
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;
145 return;
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",
151 devno, ccode,
152 diag_data.vrdcvcla, diag_data.vrdcvtyp,
153 diag_data.vrdcrccl, diag_data.vrdccrty,
154 diag_data.vrdccrmd);
158 * Start Sense ID helper function.
159 * Try to obtain the 'control unit'/'device type' information
160 * associated with the subchannel.
162 static int
163 __ccw_device_sense_id_start(struct ccw_device *cdev)
165 struct subchannel *sch;
166 struct ccw1 *ccw;
167 int ret;
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;
175 ccw->cda = 0;
176 ccw->count = 0;
177 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
178 ccw++;
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. */
189 ret = -ENODEV;
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 */
199 if (ret != -EACCES)
200 return ret;
202 cdev->private->imask >>= 1;
203 cdev->private->iretry = 5;
205 return ret;
208 void
209 ccw_device_sense_id_start(struct ccw_device *cdev)
211 int ret;
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.
226 static int
227 ccw_device_check_sense_id(struct ccw_device *cdev)
229 struct subchannel *sch;
230 struct irb *irb;
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;
246 return -EAGAIN;
248 return -ETIME;
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,
263 sch->schid.sch_no);
264 return -EOPNOTSUPP;
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]);
278 return -EAGAIN;
280 if (irb->scsw.cc == 3) {
281 if ((sch->orb.lpm &
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);
288 return -EACCES;
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,
294 sch->schid.sch_no,
295 irb->scsw.dstat, irb->scsw.cstat);
296 return -EAGAIN;
300 * Got interrupt for Sense ID.
302 void
303 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
305 struct subchannel *sch;
306 struct irb *irb;
307 int ret;
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);
319 return;
321 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
322 return;
323 ret = ccw_device_check_sense_id(cdev);
324 memset(&cdev->private->irb, 0, sizeof(struct irb));
325 switch (ret) {
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);
330 break;
331 case -EACCES: /* channel is not operational. */
332 sch->lpm &= ~cdev->private->imask;
333 cdev->private->imask >>= 1;
334 cdev->private->iretry = 5;
335 /* fall through. */
336 case -EAGAIN: /* try again. */
337 ret = __ccw_device_sense_id_start(cdev);
338 if (ret == 0 || ret == -EBUSY)
339 break;
340 /* fall through. */
341 default: /* Sense ID failed. Try asking VM. */
342 if (MACHINE_IS_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);
348 return;
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);
356 break;
360 EXPORT_SYMBOL(diag210);