On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / s390 / cio / device_id.c
blob1bdaa614e34fef0dbebe6d6f5f03aa7de7ed25a9
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>
14 #include <linux/kernel.h>
16 #include <asm/ccwdev.h>
17 #include <asm/delay.h>
18 #include <asm/cio.h>
19 #include <asm/lowcore.h>
20 #include <asm/diag.h>
22 #include "cio.h"
23 #include "cio_debug.h"
24 #include "css.h"
25 #include "device.h"
26 #include "ioasm.h"
27 #include "io_sch.h"
29 /**
30 * vm_vdev_to_cu_type - Convert vm virtual device into control unit type
31 * for certain devices.
32 * @class: virtual device class
33 * @type: virtual device type
35 * Returns control unit type if a match was made or %0xffff otherwise.
37 static int vm_vdev_to_cu_type(int class, int type)
39 static struct {
40 int class, type, cu_type;
41 } vm_devices[] = {
42 { 0x08, 0x01, 0x3480 },
43 { 0x08, 0x02, 0x3430 },
44 { 0x08, 0x10, 0x3420 },
45 { 0x08, 0x42, 0x3424 },
46 { 0x08, 0x44, 0x9348 },
47 { 0x08, 0x81, 0x3490 },
48 { 0x08, 0x82, 0x3422 },
49 { 0x10, 0x41, 0x1403 },
50 { 0x10, 0x42, 0x3211 },
51 { 0x10, 0x43, 0x3203 },
52 { 0x10, 0x45, 0x3800 },
53 { 0x10, 0x47, 0x3262 },
54 { 0x10, 0x48, 0x3820 },
55 { 0x10, 0x49, 0x3800 },
56 { 0x10, 0x4a, 0x4245 },
57 { 0x10, 0x4b, 0x4248 },
58 { 0x10, 0x4d, 0x3800 },
59 { 0x10, 0x4e, 0x3820 },
60 { 0x10, 0x4f, 0x3820 },
61 { 0x10, 0x82, 0x2540 },
62 { 0x10, 0x84, 0x3525 },
63 { 0x20, 0x81, 0x2501 },
64 { 0x20, 0x82, 0x2540 },
65 { 0x20, 0x84, 0x3505 },
66 { 0x40, 0x01, 0x3278 },
67 { 0x40, 0x04, 0x3277 },
68 { 0x40, 0x80, 0x2250 },
69 { 0x40, 0xc0, 0x5080 },
70 { 0x80, 0x00, 0x3215 },
72 int i;
74 for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
75 if (class == vm_devices[i].class && type == vm_devices[i].type)
76 return vm_devices[i].cu_type;
78 return 0xffff;
81 /**
82 * diag_get_dev_info - retrieve device information via DIAG X'210'
83 * @devno: device number
84 * @ps: pointer to sense ID data area
86 * Returns zero on success, non-zero otherwise.
88 static int diag_get_dev_info(u16 devno, struct senseid *ps)
90 struct diag210 diag_data;
91 int ccode;
93 CIO_TRACE_EVENT (4, "VMvdinf");
95 diag_data = (struct diag210) {
96 .vrdcdvno = devno,
97 .vrdclen = sizeof (diag_data),
100 ccode = diag210 (&diag_data);
101 if ((ccode == 0) || (ccode == 2)) {
102 ps->reserved = 0xff;
104 /* Special case for osa devices. */
105 if (diag_data.vrdcvcla == 0x02 && diag_data.vrdcvtyp == 0x20) {
106 ps->cu_type = 0x3088;
107 ps->cu_model = 0x60;
108 return 0;
110 ps->cu_type = vm_vdev_to_cu_type(diag_data.vrdcvcla,
111 diag_data.vrdcvtyp);
112 if (ps->cu_type != 0xffff)
113 return 0;
116 CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
117 "vdev class : %02X, vdev type : %04X \n ... "
118 "rdev class : %02X, rdev type : %04X, "
119 "rdev model: %02X\n",
120 devno, ccode,
121 diag_data.vrdcvcla, diag_data.vrdcvtyp,
122 diag_data.vrdcrccl, diag_data.vrdccrty,
123 diag_data.vrdccrmd);
125 return -ENODEV;
129 * Start Sense ID helper function.
130 * Try to obtain the 'control unit'/'device type' information
131 * associated with the subchannel.
133 static int
134 __ccw_device_sense_id_start(struct ccw_device *cdev)
136 struct subchannel *sch;
137 struct ccw1 *ccw;
138 int ret;
140 sch = to_subchannel(cdev->dev.parent);
141 /* Setup sense channel program. */
142 ccw = cdev->private->iccws;
143 ccw->cmd_code = CCW_CMD_SENSE_ID;
144 ccw->cda = (__u32) __pa (&cdev->private->senseid);
145 ccw->count = sizeof (struct senseid);
146 ccw->flags = CCW_FLAG_SLI;
148 /* Reset device status. */
149 memset(&cdev->private->irb, 0, sizeof(struct irb));
151 /* Try on every path. */
152 ret = -ENODEV;
153 while (cdev->private->imask != 0) {
154 cdev->private->senseid.cu_type = 0xFFFF;
155 if ((sch->opm & cdev->private->imask) != 0 &&
156 cdev->private->iretry > 0) {
157 cdev->private->iretry--;
158 /* Reset internal retry indication. */
159 cdev->private->flags.intretry = 0;
160 ret = cio_start (sch, cdev->private->iccws,
161 cdev->private->imask);
162 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
163 if (ret != -EACCES)
164 return ret;
166 cdev->private->imask >>= 1;
167 cdev->private->iretry = 5;
169 return ret;
172 void
173 ccw_device_sense_id_start(struct ccw_device *cdev)
175 int ret;
177 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
178 cdev->private->imask = 0x80;
179 cdev->private->iretry = 5;
180 ret = __ccw_device_sense_id_start(cdev);
181 if (ret && ret != -EBUSY)
182 ccw_device_sense_id_done(cdev, ret);
186 * Called from interrupt context to check if a valid answer
187 * to Sense ID was received.
189 static int
190 ccw_device_check_sense_id(struct ccw_device *cdev)
192 struct subchannel *sch;
193 struct irb *irb;
195 sch = to_subchannel(cdev->dev.parent);
196 irb = &cdev->private->irb;
198 /* Check the error cases. */
199 if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
200 /* Retry Sense ID if requested. */
201 if (cdev->private->flags.intretry) {
202 cdev->private->flags.intretry = 0;
203 return -EAGAIN;
205 return -ETIME;
207 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
209 * if the device doesn't support the SenseID
210 * command further retries wouldn't help ...
211 * NB: We don't check here for intervention required like we
212 * did before, because tape devices with no tape inserted
213 * may present this status *in conjunction with* the
214 * sense id information. So, for intervention required,
215 * we use the "whack it until it talks" strategy...
217 CIO_MSG_EVENT(0, "SenseID : device %04x on Subchannel "
218 "0.%x.%04x reports cmd reject\n",
219 cdev->private->dev_id.devno, sch->schid.ssid,
220 sch->schid.sch_no);
221 return -EOPNOTSUPP;
223 if (irb->esw.esw0.erw.cons) {
224 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
225 "lpum %02X, cnt %02d, sns :"
226 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
227 cdev->private->dev_id.ssid,
228 cdev->private->dev_id.devno,
229 irb->esw.esw0.sublog.lpum,
230 irb->esw.esw0.erw.scnt,
231 irb->ecw[0], irb->ecw[1],
232 irb->ecw[2], irb->ecw[3],
233 irb->ecw[4], irb->ecw[5],
234 irb->ecw[6], irb->ecw[7]);
235 return -EAGAIN;
237 if (irb->scsw.cmd.cc == 3) {
238 u8 lpm;
240 lpm = to_io_private(sch)->orb.cmd.lpm;
241 if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
242 CIO_MSG_EVENT(4, "SenseID : path %02X for device %04x "
243 "on subchannel 0.%x.%04x is "
244 "'not operational'\n", lpm,
245 cdev->private->dev_id.devno,
246 sch->schid.ssid, sch->schid.sch_no);
247 return -EACCES;
250 /* Did we get a proper answer ? */
251 if (irb->scsw.cmd.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF &&
252 cdev->private->senseid.reserved == 0xFF) {
253 if (irb->scsw.cmd.count < sizeof(struct senseid) - 8)
254 cdev->private->flags.esid = 1;
255 return 0; /* Success */
258 /* Hmm, whatever happened, try again. */
259 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
260 "subchannel 0.%x.%04x returns status %02X%02X\n",
261 cdev->private->dev_id.devno, sch->schid.ssid,
262 sch->schid.sch_no,
263 irb->scsw.cmd.dstat, irb->scsw.cmd.cstat);
264 return -EAGAIN;
268 * Got interrupt for Sense ID.
270 void
271 ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
273 struct subchannel *sch;
274 struct irb *irb;
275 int ret;
277 sch = to_subchannel(cdev->dev.parent);
278 irb = (struct irb *) __LC_IRB;
279 /* Retry sense id, if needed. */
280 if (irb->scsw.cmd.stctl ==
281 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
282 if ((irb->scsw.cmd.cc == 1) || !irb->scsw.cmd.actl) {
283 ret = __ccw_device_sense_id_start(cdev);
284 if (ret && ret != -EBUSY)
285 ccw_device_sense_id_done(cdev, ret);
287 return;
289 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
290 return;
291 ret = ccw_device_check_sense_id(cdev);
292 memset(&cdev->private->irb, 0, sizeof(struct irb));
293 switch (ret) {
294 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
295 case 0: /* Sense id succeeded. */
296 case -ETIME: /* Sense id stopped by timeout. */
297 ccw_device_sense_id_done(cdev, ret);
298 break;
299 case -EACCES: /* channel is not operational. */
300 sch->lpm &= ~cdev->private->imask;
301 cdev->private->imask >>= 1;
302 cdev->private->iretry = 5;
303 /* fall through. */
304 case -EAGAIN: /* try again. */
305 ret = __ccw_device_sense_id_start(cdev);
306 if (ret == 0 || ret == -EBUSY)
307 break;
308 /* fall through. */
309 default: /* Sense ID failed. Try asking VM. */
310 if (MACHINE_IS_VM)
311 ret = diag_get_dev_info(cdev->private->dev_id.devno,
312 &cdev->private->senseid);
313 else
315 * If we can't couldn't identify the device type we
316 * consider the device "not operational".
318 ret = -ENODEV;
320 ccw_device_sense_id_done(cdev, ret);
321 break;