[SERIAL] Support for Intashield 2 port PCI serial card
[linux-2.6/verdex.git] / drivers / s390 / cio / device_id.c
blob438db483035d033a85013e184fcef818a75dcfd2
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 ".section __ex_table,\"a\"\n"
53 " .align 8\n"
54 " .quad 0b,1b\n"
55 ".previous"
56 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
58 *addr = diag210_tmp;
59 spin_unlock_irqrestore(&diag210_lock, flags);
61 return ccode;
63 #else
64 int
65 diag210(struct diag210 * addr)
67 int ccode;
69 asm volatile (
70 " lhi %0,-1\n"
71 " diag %1,0,0x210\n"
72 "0: ipm %0\n"
73 " srl %0,28\n"
74 "1:\n"
75 ".section __ex_table,\"a\"\n"
76 " .align 4\n"
77 " .long 0b,1b\n"
78 ".previous"
79 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
81 return ccode;
83 #endif
86 * Input :
87 * devno - device number
88 * ps - pointer to sense ID data area
89 * Output : none
91 static void
92 VM_virtual_device_info (__u16 devno, struct senseid *ps)
94 static struct {
95 int vrdcvcla, vrdcvtyp, cu_type;
96 } vm_devices[] = {
97 { 0x08, 0x01, 0x3480 },
98 { 0x08, 0x02, 0x3430 },
99 { 0x08, 0x10, 0x3420 },
100 { 0x08, 0x42, 0x3424 },
101 { 0x08, 0x44, 0x9348 },
102 { 0x08, 0x81, 0x3490 },
103 { 0x08, 0x82, 0x3422 },
104 { 0x10, 0x41, 0x1403 },
105 { 0x10, 0x42, 0x3211 },
106 { 0x10, 0x43, 0x3203 },
107 { 0x10, 0x45, 0x3800 },
108 { 0x10, 0x47, 0x3262 },
109 { 0x10, 0x48, 0x3820 },
110 { 0x10, 0x49, 0x3800 },
111 { 0x10, 0x4a, 0x4245 },
112 { 0x10, 0x4b, 0x4248 },
113 { 0x10, 0x4d, 0x3800 },
114 { 0x10, 0x4e, 0x3820 },
115 { 0x10, 0x4f, 0x3820 },
116 { 0x10, 0x82, 0x2540 },
117 { 0x10, 0x84, 0x3525 },
118 { 0x20, 0x81, 0x2501 },
119 { 0x20, 0x82, 0x2540 },
120 { 0x20, 0x84, 0x3505 },
121 { 0x40, 0x01, 0x3278 },
122 { 0x40, 0x04, 0x3277 },
123 { 0x40, 0x80, 0x2250 },
124 { 0x40, 0xc0, 0x5080 },
125 { 0x80, 0x00, 0x3215 },
127 struct diag210 diag_data;
128 int ccode, i;
130 CIO_TRACE_EVENT (4, "VMvdinf");
132 diag_data = (struct diag210) {
133 .vrdcdvno = devno,
134 .vrdclen = sizeof (diag_data),
137 ccode = diag210 (&diag_data);
138 ps->reserved = 0xff;
140 /* Special case for bloody osa devices. */
141 if (diag_data.vrdcvcla == 0x02 &&
142 diag_data.vrdcvtyp == 0x20) {
143 ps->cu_type = 0x3088;
144 ps->cu_model = 0x60;
145 return;
147 for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
148 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
149 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
150 ps->cu_type = vm_devices[i].cu_type;
151 return;
153 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
154 "vdev class : %02X, vdev type : %04X \n ... "
155 "rdev class : %02X, rdev type : %04X, "
156 "rdev model: %02X\n",
157 devno, ccode,
158 diag_data.vrdcvcla, diag_data.vrdcvtyp,
159 diag_data.vrdcrccl, diag_data.vrdccrty,
160 diag_data.vrdccrmd);
164 * Start Sense ID helper function.
165 * Try to obtain the 'control unit'/'device type' information
166 * associated with the subchannel.
168 static int
169 __ccw_device_sense_id_start(struct ccw_device *cdev)
171 struct subchannel *sch;
172 struct ccw1 *ccw;
173 int ret;
175 sch = to_subchannel(cdev->dev.parent);
176 /* Setup sense channel program. */
177 ccw = cdev->private->iccws;
178 if (sch->schib.pmcw.pim != 0x80) {
179 /* more than one path installed. */
180 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
181 ccw->cda = 0;
182 ccw->count = 0;
183 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
184 ccw++;
186 ccw->cmd_code = CCW_CMD_SENSE_ID;
187 ccw->cda = (__u32) __pa (&cdev->private->senseid);
188 ccw->count = sizeof (struct senseid);
189 ccw->flags = CCW_FLAG_SLI;
191 /* Reset device status. */
192 memset(&cdev->private->irb, 0, sizeof(struct irb));
194 /* Try on every path. */
195 ret = -ENODEV;
196 while (cdev->private->imask != 0) {
197 if ((sch->opm & cdev->private->imask) != 0 &&
198 cdev->private->iretry > 0) {
199 cdev->private->iretry--;
200 ret = cio_start (sch, cdev->private->iccws,
201 cdev->private->imask);
202 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
203 if (ret != -EACCES)
204 return ret;
206 cdev->private->imask >>= 1;
207 cdev->private->iretry = 5;
209 return ret;
212 void
213 ccw_device_sense_id_start(struct ccw_device *cdev)
215 int ret;
217 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
218 cdev->private->senseid.cu_type = 0xFFFF;
219 cdev->private->imask = 0x80;
220 cdev->private->iretry = 5;
221 ret = __ccw_device_sense_id_start(cdev);
222 if (ret && ret != -EBUSY)
223 ccw_device_sense_id_done(cdev, ret);
227 * Called from interrupt context to check if a valid answer
228 * to Sense ID was received.
230 static int
231 ccw_device_check_sense_id(struct ccw_device *cdev)
233 struct subchannel *sch;
234 struct irb *irb;
236 sch = to_subchannel(cdev->dev.parent);
237 irb = &cdev->private->irb;
238 /* Did we get a proper answer ? */
239 if (cdev->private->senseid.cu_type != 0xFFFF &&
240 cdev->private->senseid.reserved == 0xFF) {
241 if (irb->scsw.count < sizeof (struct senseid) - 8)
242 cdev->private->flags.esid = 1;
243 return 0; /* Success */
245 /* Check the error cases. */
246 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
247 return -ETIME;
248 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
250 * if the device doesn't support the SenseID
251 * command further retries wouldn't help ...
252 * NB: We don't check here for intervention required like we
253 * did before, because tape devices with no tape inserted
254 * may present this status *in conjunction with* the
255 * sense id information. So, for intervention required,
256 * we use the "whack it until it talks" strategy...
258 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
259 "0.%x.%04x reports cmd reject\n",
260 cdev->private->devno, sch->schid.ssid,
261 sch->schid.sch_no);
262 return -EOPNOTSUPP;
264 if (irb->esw.esw0.erw.cons) {
265 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
266 "lpum %02X, cnt %02d, sns :"
267 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
268 cdev->private->ssid, 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]);
275 return -EAGAIN;
277 if (irb->scsw.cc == 3) {
278 if ((sch->orb.lpm &
279 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
280 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
281 "on subchannel 0.%x.%04x is "
282 "'not operational'\n", sch->orb.lpm,
283 cdev->private->devno, sch->schid.ssid,
284 sch->schid.sch_no);
285 return -EACCES;
287 /* Hmm, whatever happened, try again. */
288 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
289 "subchannel 0.%x.%04x returns status %02X%02X\n",
290 cdev->private->devno, sch->schid.ssid, sch->schid.sch_no,
291 irb->scsw.dstat, irb->scsw.cstat);
292 return -EAGAIN;
296 * Got interrupt for Sense ID.
298 void
299 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
301 struct subchannel *sch;
302 struct irb *irb;
303 int ret;
305 sch = to_subchannel(cdev->dev.parent);
306 irb = (struct irb *) __LC_IRB;
307 /* Retry sense id, if needed. */
308 if (irb->scsw.stctl ==
309 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
310 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
311 ret = __ccw_device_sense_id_start(cdev);
312 if (ret && ret != -EBUSY)
313 ccw_device_sense_id_done(cdev, ret);
315 return;
317 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
318 return;
319 ret = ccw_device_check_sense_id(cdev);
320 memset(&cdev->private->irb, 0, sizeof(struct irb));
321 switch (ret) {
322 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
323 case 0: /* Sense id succeeded. */
324 case -ETIME: /* Sense id stopped by timeout. */
325 ccw_device_sense_id_done(cdev, ret);
326 break;
327 case -EACCES: /* channel is not operational. */
328 sch->lpm &= ~cdev->private->imask;
329 cdev->private->imask >>= 1;
330 cdev->private->iretry = 5;
331 /* fall through. */
332 case -EAGAIN: /* try again. */
333 ret = __ccw_device_sense_id_start(cdev);
334 if (ret == 0 || ret == -EBUSY)
335 break;
336 /* fall through. */
337 default: /* Sense ID failed. Try asking VM. */
338 if (MACHINE_IS_VM) {
339 VM_virtual_device_info (cdev->private->devno,
340 &cdev->private->senseid);
341 if (cdev->private->senseid.cu_type != 0xFFFF) {
342 /* Got the device information from VM. */
343 ccw_device_sense_id_done(cdev, 0);
344 return;
348 * If we can't couldn't identify the device type we
349 * consider the device "not operational".
351 ccw_device_sense_id_done(cdev, -ENODEV);
352 break;
356 EXPORT_SYMBOL(diag210);