Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * drivers/s390/cio/device_id.c | |
3 | * | |
4 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, | |
5 | * IBM Corporation | |
4ce3b30c | 6 | * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) |
1da177e4 LT |
7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
8 | * | |
9 | * Sense ID functions. | |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
1da177e4 | 13 | #include <linux/init.h> |
045236ab | 14 | #include <linux/kernel.h> |
1da177e4 LT |
15 | |
16 | #include <asm/ccwdev.h> | |
17 | #include <asm/delay.h> | |
18 | #include <asm/cio.h> | |
19 | #include <asm/lowcore.h> | |
0a87c5cf | 20 | #include <asm/diag.h> |
1da177e4 LT |
21 | |
22 | #include "cio.h" | |
23 | #include "cio_debug.h" | |
24 | #include "css.h" | |
25 | #include "device.h" | |
26 | #include "ioasm.h" | |
cd6b4f27 | 27 | #include "io_sch.h" |
1da177e4 | 28 | |
6f52ac29 PO |
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 | |
34 | * | |
35 | * Returns control unit type if a match was made or %0xffff otherwise. | |
1da177e4 | 36 | */ |
6f52ac29 | 37 | static int vm_vdev_to_cu_type(int class, int type) |
1da177e4 LT |
38 | { |
39 | static struct { | |
6f52ac29 | 40 | int class, type, cu_type; |
1da177e4 LT |
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 }, | |
71 | }; | |
6f52ac29 PO |
72 | int i; |
73 | ||
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; | |
77 | ||
78 | return 0xffff; | |
79 | } | |
80 | ||
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 | |
85 | * | |
86 | * Returns zero on success, non-zero otherwise. | |
87 | */ | |
88 | static int diag_get_dev_info(u16 devno, struct senseid *ps) | |
89 | { | |
1da177e4 | 90 | struct diag210 diag_data; |
6f52ac29 | 91 | int ccode; |
1da177e4 LT |
92 | |
93 | CIO_TRACE_EVENT (4, "VMvdinf"); | |
94 | ||
95 | diag_data = (struct diag210) { | |
96 | .vrdcdvno = devno, | |
97 | .vrdclen = sizeof (diag_data), | |
98 | }; | |
99 | ||
100 | ccode = diag210 (&diag_data); | |
6f52ac29 PO |
101 | if ((ccode == 0) || (ccode == 2)) { |
102 | ps->reserved = 0xff; | |
1da177e4 | 103 | |
6f52ac29 PO |
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; | |
1da177e4 | 109 | } |
6f52ac29 PO |
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; | |
114 | } | |
115 | ||
1da177e4 LT |
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); | |
6f52ac29 PO |
124 | |
125 | return -ENODEV; | |
1da177e4 LT |
126 | } |
127 | ||
128 | /* | |
129 | * Start Sense ID helper function. | |
130 | * Try to obtain the 'control unit'/'device type' information | |
131 | * associated with the subchannel. | |
132 | */ | |
133 | static int | |
134 | __ccw_device_sense_id_start(struct ccw_device *cdev) | |
135 | { | |
136 | struct subchannel *sch; | |
137 | struct ccw1 *ccw; | |
c94dec99 | 138 | int ret; |
1da177e4 LT |
139 | |
140 | sch = to_subchannel(cdev->dev.parent); | |
141 | /* Setup sense channel program. */ | |
142 | ccw = cdev->private->iccws; | |
1da177e4 LT |
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; | |
147 | ||
148 | /* Reset device status. */ | |
149 | memset(&cdev->private->irb, 0, sizeof(struct irb)); | |
150 | ||
c94dec99 CH |
151 | /* Try on every path. */ |
152 | ret = -ENODEV; | |
153 | while (cdev->private->imask != 0) { | |
6f52ac29 | 154 | cdev->private->senseid.cu_type = 0xFFFF; |
c94dec99 CH |
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; | |
165 | } | |
166 | cdev->private->imask >>= 1; | |
167 | cdev->private->iretry = 5; | |
168 | } | |
169 | return ret; | |
1da177e4 LT |
170 | } |
171 | ||
172 | void | |
173 | ccw_device_sense_id_start(struct ccw_device *cdev) | |
174 | { | |
175 | int ret; | |
176 | ||
177 | memset (&cdev->private->senseid, 0, sizeof (struct senseid)); | |
c94dec99 CH |
178 | cdev->private->imask = 0x80; |
179 | cdev->private->iretry = 5; | |
1da177e4 LT |
180 | ret = __ccw_device_sense_id_start(cdev); |
181 | if (ret && ret != -EBUSY) | |
182 | ccw_device_sense_id_done(cdev, ret); | |
183 | } | |
184 | ||
185 | /* | |
186 | * Called from interrupt context to check if a valid answer | |
187 | * to Sense ID was received. | |
188 | */ | |
189 | static int | |
190 | ccw_device_check_sense_id(struct ccw_device *cdev) | |
191 | { | |
192 | struct subchannel *sch; | |
193 | struct irb *irb; | |
194 | ||
195 | sch = to_subchannel(cdev->dev.parent); | |
196 | irb = &cdev->private->irb; | |
6f52ac29 | 197 | |
1da177e4 | 198 | /* Check the error cases. */ |
23d805b6 | 199 | if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
d23861ff CH |
200 | /* Retry Sense ID if requested. */ |
201 | if (cdev->private->flags.intretry) { | |
202 | cdev->private->flags.intretry = 0; | |
203 | return -EAGAIN; | |
204 | } | |
1da177e4 | 205 | return -ETIME; |
d23861ff | 206 | } |
1da177e4 LT |
207 | if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) { |
208 | /* | |
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... | |
216 | */ | |
139b83dd | 217 | CIO_MSG_EVENT(0, "SenseID : device %04x on Subchannel " |
fb6958a5 | 218 | "0.%x.%04x reports cmd reject\n", |
78964268 | 219 | cdev->private->dev_id.devno, sch->schid.ssid, |
fb6958a5 | 220 | sch->schid.sch_no); |
1da177e4 LT |
221 | return -EOPNOTSUPP; |
222 | } | |
223 | if (irb->esw.esw0.erw.cons) { | |
fb6958a5 | 224 | CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, " |
1da177e4 LT |
225 | "lpum %02X, cnt %02d, sns :" |
226 | " %02X%02X%02X%02X %02X%02X%02X%02X ...\n", | |
78964268 CH |
227 | cdev->private->dev_id.ssid, |
228 | cdev->private->dev_id.devno, | |
1da177e4 LT |
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; | |
236 | } | |
23d805b6 | 237 | if (irb->scsw.cmd.cc == 3) { |
cd6b4f27 CH |
238 | u8 lpm; |
239 | ||
83262d63 | 240 | lpm = to_io_private(sch)->orb.cmd.lpm; |
cd6b4f27 | 241 | if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0) |
139b83dd | 242 | CIO_MSG_EVENT(4, "SenseID : path %02X for device %04x " |
fb6958a5 | 243 | "on subchannel 0.%x.%04x is " |
cd6b4f27 | 244 | "'not operational'\n", lpm, |
78964268 CH |
245 | cdev->private->dev_id.devno, |
246 | sch->schid.ssid, sch->schid.sch_no); | |
1da177e4 LT |
247 | return -EACCES; |
248 | } | |
6f52ac29 PO |
249 | |
250 | /* Did we get a proper answer ? */ | |
23d805b6 | 251 | if (irb->scsw.cmd.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF && |
6f52ac29 | 252 | cdev->private->senseid.reserved == 0xFF) { |
23d805b6 | 253 | if (irb->scsw.cmd.count < sizeof(struct senseid) - 8) |
6f52ac29 PO |
254 | cdev->private->flags.esid = 1; |
255 | return 0; /* Success */ | |
256 | } | |
257 | ||
1da177e4 LT |
258 | /* Hmm, whatever happened, try again. */ |
259 | CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on " | |
fb6958a5 | 260 | "subchannel 0.%x.%04x returns status %02X%02X\n", |
78964268 CH |
261 | cdev->private->dev_id.devno, sch->schid.ssid, |
262 | sch->schid.sch_no, | |
23d805b6 | 263 | irb->scsw.cmd.dstat, irb->scsw.cmd.cstat); |
1da177e4 LT |
264 | return -EAGAIN; |
265 | } | |
266 | ||
267 | /* | |
268 | * Got interrupt for Sense ID. | |
269 | */ | |
270 | void | |
271 | ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event) | |
272 | { | |
273 | struct subchannel *sch; | |
274 | struct irb *irb; | |
275 | int ret; | |
276 | ||
277 | sch = to_subchannel(cdev->dev.parent); | |
278 | irb = (struct irb *) __LC_IRB; | |
279 | /* Retry sense id, if needed. */ | |
23d805b6 | 280 | if (irb->scsw.cmd.stctl == |
1da177e4 | 281 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
23d805b6 | 282 | if ((irb->scsw.cmd.cc == 1) || !irb->scsw.cmd.actl) { |
1da177e4 LT |
283 | ret = __ccw_device_sense_id_start(cdev); |
284 | if (ret && ret != -EBUSY) | |
285 | ccw_device_sense_id_done(cdev, ret); | |
286 | } | |
287 | return; | |
288 | } | |
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. */ | |
c94dec99 CH |
300 | sch->lpm &= ~cdev->private->imask; |
301 | cdev->private->imask >>= 1; | |
302 | cdev->private->iretry = 5; | |
303 | /* fall through. */ | |
1da177e4 | 304 | case -EAGAIN: /* try again. */ |
c94dec99 CH |
305 | ret = __ccw_device_sense_id_start(cdev); |
306 | if (ret == 0 || ret == -EBUSY) | |
307 | break; | |
1da177e4 LT |
308 | /* fall through. */ |
309 | default: /* Sense ID failed. Try asking VM. */ | |
6f52ac29 PO |
310 | if (MACHINE_IS_VM) |
311 | ret = diag_get_dev_info(cdev->private->dev_id.devno, | |
1da177e4 | 312 | &cdev->private->senseid); |
6f52ac29 PO |
313 | else |
314 | /* | |
315 | * If we can't couldn't identify the device type we | |
316 | * consider the device "not operational". | |
317 | */ | |
318 | ret = -ENODEV; | |
319 | ||
320 | ccw_device_sense_id_done(cdev, ret); | |
1da177e4 LT |
321 | break; |
322 | } | |
323 | } |