aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/cio/device_id.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/s390/cio/device_id.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/s390/cio/device_id.c')
-rw-r--r--drivers/s390/cio/device_id.c355
1 files changed, 355 insertions, 0 deletions
diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
new file mode 100644
index 000000000000..0e68fb511dc9
--- /dev/null
+++ b/drivers/s390/cio/device_id.c
@@ -0,0 +1,355 @@
1/*
2 * drivers/s390/cio/device_id.c
3 *
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
5 * IBM Corporation
6 * Author(s): Cornelia Huck(cohuck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 *
9 * Sense ID functions.
10 */
11
12#include <linux/module.h>
13#include <linux/config.h>
14#include <linux/init.h>
15
16#include <asm/ccwdev.h>
17#include <asm/delay.h>
18#include <asm/cio.h>
19#include <asm/lowcore.h>
20
21#include "cio.h"
22#include "cio_debug.h"
23#include "css.h"
24#include "device.h"
25#include "ioasm.h"
26
27/*
28 * diag210 is used under VM to get information about a virtual device
29 */
30#ifdef CONFIG_ARCH_S390X
31int
32diag210(struct diag210 * addr)
33{
34 /*
35 * diag 210 needs its data below the 2GB border, so we
36 * use a static data area to be sure
37 */
38 static struct diag210 diag210_tmp;
39 static DEFINE_SPINLOCK(diag210_lock);
40 unsigned long flags;
41 int ccode;
42
43 spin_lock_irqsave(&diag210_lock, flags);
44 diag210_tmp = *addr;
45
46 asm volatile (
47 " lhi %0,-1\n"
48 " sam31\n"
49 " diag %1,0,0x210\n"
50 "0: ipm %0\n"
51 " srl %0,28\n"
52 "1: sam64\n"
53 ".section __ex_table,\"a\"\n"
54 " .align 8\n"
55 " .quad 0b,1b\n"
56 ".previous"
57 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
58
59 *addr = diag210_tmp;
60 spin_unlock_irqrestore(&diag210_lock, flags);
61
62 return ccode;
63}
64#else
65int
66diag210(struct diag210 * addr)
67{
68 int ccode;
69
70 asm volatile (
71 " lhi %0,-1\n"
72 " diag %1,0,0x210\n"
73 "0: ipm %0\n"
74 " srl %0,28\n"
75 "1:\n"
76 ".section __ex_table,\"a\"\n"
77 " .align 4\n"
78 " .long 0b,1b\n"
79 ".previous"
80 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
81
82 return ccode;
83}
84#endif
85
86/*
87 * Input :
88 * devno - device number
89 * ps - pointer to sense ID data area
90 * Output : none
91 */
92static void
93VM_virtual_device_info (__u16 devno, struct senseid *ps)
94{
95 static struct {
96 int vrdcvcla, vrdcvtyp, cu_type;
97 } vm_devices[] = {
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 },
127 };
128 struct diag210 diag_data;
129 int ccode, i;
130
131 CIO_TRACE_EVENT (4, "VMvdinf");
132
133 diag_data = (struct diag210) {
134 .vrdcdvno = devno,
135 .vrdclen = sizeof (diag_data),
136 };
137
138 ccode = diag210 (&diag_data);
139 ps->reserved = 0xff;
140
141 /* Special case for bloody osa devices. */
142 if (diag_data.vrdcvcla == 0x02 &&
143 diag_data.vrdcvtyp == 0x20) {
144 ps->cu_type = 0x3088;
145 ps->cu_model = 0x60;
146 return;
147 }
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;
152 return;
153 }
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",
158 devno, ccode,
159 diag_data.vrdcvcla, diag_data.vrdcvtyp,
160 diag_data.vrdcrccl, diag_data.vrdccrty,
161 diag_data.vrdccrmd);
162}
163
164/*
165 * Start Sense ID helper function.
166 * Try to obtain the 'control unit'/'device type' information
167 * associated with the subchannel.
168 */
169static int
170__ccw_device_sense_id_start(struct ccw_device *cdev)
171{
172 struct subchannel *sch;
173 struct ccw1 *ccw;
174 int ret;
175
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;
182 ccw->cda = 0;
183 ccw->count = 0;
184 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
185 ccw++;
186 }
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;
191
192 /* Reset device status. */
193 memset(&cdev->private->irb, 0, sizeof(struct irb));
194
195 /* Try on every path. */
196 ret = -ENODEV;
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 */
204 if (ret != -EACCES)
205 return ret;
206 }
207 cdev->private->imask >>= 1;
208 cdev->private->iretry = 5;
209 }
210 return ret;
211}
212
213void
214ccw_device_sense_id_start(struct ccw_device *cdev)
215{
216 int ret;
217
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);
225}
226
227/*
228 * Called from interrupt context to check if a valid answer
229 * to Sense ID was received.
230 */
231static int
232ccw_device_check_sense_id(struct ccw_device *cdev)
233{
234 struct subchannel *sch;
235 struct irb *irb;
236
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 */
245 }
246 /* Check the error cases. */
247 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
248 return -ETIME;
249 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
250 /*
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...
258 */
259 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel %04x "
260 "reports cmd reject\n",
261 cdev->private->devno, sch->irq);
262 return -EOPNOTSUPP;
263 }
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]);
275 return -EAGAIN;
276 }
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 on"
281 " subchannel %04x is 'not operational'\n",
282 sch->orb.lpm, cdev->private->devno,
283 sch->irq);
284 return -EACCES;
285 }
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);
291 return -EAGAIN;
292}
293
294/*
295 * Got interrupt for Sense ID.
296 */
297void
298ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
299{
300 struct subchannel *sch;
301 struct irb *irb;
302 int ret;
303
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);
313 }
314 return;
315 }
316 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
317 return;
318 ret = ccw_device_check_sense_id(cdev);
319 memset(&cdev->private->irb, 0, sizeof(struct irb));
320 switch (ret) {
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);
325 break;
326 case -EACCES: /* channel is not operational. */
327 sch->lpm &= ~cdev->private->imask;
328 cdev->private->imask >>= 1;
329 cdev->private->iretry = 5;
330 /* fall through. */
331 case -EAGAIN: /* try again. */
332 ret = __ccw_device_sense_id_start(cdev);
333 if (ret == 0 || ret == -EBUSY)
334 break;
335 /* fall through. */
336 default: /* Sense ID failed. Try asking VM. */
337 if (MACHINE_IS_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);
343 return;
344 }
345 }
346 /*
347 * If we can't couldn't identify the device type we
348 * consider the device "not operational".
349 */
350 ccw_device_sense_id_done(cdev, -ENODEV);
351 break;
352 }
353}
354
355EXPORT_SYMBOL(diag210);