]>
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 ([email protected]) |
1da177e4 LT |
7 | * Martin Schwidefsky ([email protected]) |
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" | |
27 | ||
1da177e4 LT |
28 | /* |
29 | * Input : | |
30 | * devno - device number | |
31 | * ps - pointer to sense ID data area | |
32 | * Output : none | |
33 | */ | |
34 | static void | |
35 | VM_virtual_device_info (__u16 devno, struct senseid *ps) | |
36 | { | |
37 | static struct { | |
38 | int vrdcvcla, vrdcvtyp, cu_type; | |
39 | } vm_devices[] = { | |
40 | { 0x08, 0x01, 0x3480 }, | |
41 | { 0x08, 0x02, 0x3430 }, | |
42 | { 0x08, 0x10, 0x3420 }, | |
43 | { 0x08, 0x42, 0x3424 }, | |
44 | { 0x08, 0x44, 0x9348 }, | |
45 | { 0x08, 0x81, 0x3490 }, | |
46 | { 0x08, 0x82, 0x3422 }, | |
47 | { 0x10, 0x41, 0x1403 }, | |
48 | { 0x10, 0x42, 0x3211 }, | |
49 | { 0x10, 0x43, 0x3203 }, | |
50 | { 0x10, 0x45, 0x3800 }, | |
51 | { 0x10, 0x47, 0x3262 }, | |
52 | { 0x10, 0x48, 0x3820 }, | |
53 | { 0x10, 0x49, 0x3800 }, | |
54 | { 0x10, 0x4a, 0x4245 }, | |
55 | { 0x10, 0x4b, 0x4248 }, | |
56 | { 0x10, 0x4d, 0x3800 }, | |
57 | { 0x10, 0x4e, 0x3820 }, | |
58 | { 0x10, 0x4f, 0x3820 }, | |
59 | { 0x10, 0x82, 0x2540 }, | |
60 | { 0x10, 0x84, 0x3525 }, | |
61 | { 0x20, 0x81, 0x2501 }, | |
62 | { 0x20, 0x82, 0x2540 }, | |
63 | { 0x20, 0x84, 0x3505 }, | |
64 | { 0x40, 0x01, 0x3278 }, | |
65 | { 0x40, 0x04, 0x3277 }, | |
66 | { 0x40, 0x80, 0x2250 }, | |
67 | { 0x40, 0xc0, 0x5080 }, | |
68 | { 0x80, 0x00, 0x3215 }, | |
69 | }; | |
70 | struct diag210 diag_data; | |
71 | int ccode, i; | |
72 | ||
73 | CIO_TRACE_EVENT (4, "VMvdinf"); | |
74 | ||
75 | diag_data = (struct diag210) { | |
76 | .vrdcdvno = devno, | |
77 | .vrdclen = sizeof (diag_data), | |
78 | }; | |
79 | ||
80 | ccode = diag210 (&diag_data); | |
81 | ps->reserved = 0xff; | |
82 | ||
83 | /* Special case for bloody osa devices. */ | |
84 | if (diag_data.vrdcvcla == 0x02 && | |
85 | diag_data.vrdcvtyp == 0x20) { | |
86 | ps->cu_type = 0x3088; | |
87 | ps->cu_model = 0x60; | |
88 | return; | |
89 | } | |
045236ab | 90 | for (i = 0; i < ARRAY_SIZE(vm_devices); i++) |
1da177e4 LT |
91 | if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla && |
92 | diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) { | |
93 | ps->cu_type = vm_devices[i].cu_type; | |
94 | return; | |
95 | } | |
96 | CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):" | |
97 | "vdev class : %02X, vdev type : %04X \n ... " | |
98 | "rdev class : %02X, rdev type : %04X, " | |
99 | "rdev model: %02X\n", | |
100 | devno, ccode, | |
101 | diag_data.vrdcvcla, diag_data.vrdcvtyp, | |
102 | diag_data.vrdcrccl, diag_data.vrdccrty, | |
103 | diag_data.vrdccrmd); | |
104 | } | |
105 | ||
106 | /* | |
107 | * Start Sense ID helper function. | |
108 | * Try to obtain the 'control unit'/'device type' information | |
109 | * associated with the subchannel. | |
110 | */ | |
111 | static int | |
112 | __ccw_device_sense_id_start(struct ccw_device *cdev) | |
113 | { | |
114 | struct subchannel *sch; | |
115 | struct ccw1 *ccw; | |
116 | int ret; | |
117 | ||
118 | sch = to_subchannel(cdev->dev.parent); | |
119 | /* Setup sense channel program. */ | |
120 | ccw = cdev->private->iccws; | |
121 | if (sch->schib.pmcw.pim != 0x80) { | |
122 | /* more than one path installed. */ | |
123 | ccw->cmd_code = CCW_CMD_SUSPEND_RECONN; | |
124 | ccw->cda = 0; | |
125 | ccw->count = 0; | |
126 | ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC; | |
127 | ccw++; | |
128 | } | |
129 | ccw->cmd_code = CCW_CMD_SENSE_ID; | |
130 | ccw->cda = (__u32) __pa (&cdev->private->senseid); | |
131 | ccw->count = sizeof (struct senseid); | |
132 | ccw->flags = CCW_FLAG_SLI; | |
133 | ||
134 | /* Reset device status. */ | |
135 | memset(&cdev->private->irb, 0, sizeof(struct irb)); | |
136 | ||
137 | /* Try on every path. */ | |
138 | ret = -ENODEV; | |
139 | while (cdev->private->imask != 0) { | |
140 | if ((sch->opm & cdev->private->imask) != 0 && | |
141 | cdev->private->iretry > 0) { | |
142 | cdev->private->iretry--; | |
d23861ff CH |
143 | /* Reset internal retry indication. */ |
144 | cdev->private->flags.intretry = 0; | |
1da177e4 LT |
145 | ret = cio_start (sch, cdev->private->iccws, |
146 | cdev->private->imask); | |
147 | /* ret is 0, -EBUSY, -EACCES or -ENODEV */ | |
148 | if (ret != -EACCES) | |
149 | return ret; | |
150 | } | |
151 | cdev->private->imask >>= 1; | |
152 | cdev->private->iretry = 5; | |
153 | } | |
154 | return ret; | |
155 | } | |
156 | ||
157 | void | |
158 | ccw_device_sense_id_start(struct ccw_device *cdev) | |
159 | { | |
160 | int ret; | |
161 | ||
162 | memset (&cdev->private->senseid, 0, sizeof (struct senseid)); | |
163 | cdev->private->senseid.cu_type = 0xFFFF; | |
164 | cdev->private->imask = 0x80; | |
165 | cdev->private->iretry = 5; | |
166 | ret = __ccw_device_sense_id_start(cdev); | |
167 | if (ret && ret != -EBUSY) | |
168 | ccw_device_sense_id_done(cdev, ret); | |
169 | } | |
170 | ||
171 | /* | |
172 | * Called from interrupt context to check if a valid answer | |
173 | * to Sense ID was received. | |
174 | */ | |
175 | static int | |
176 | ccw_device_check_sense_id(struct ccw_device *cdev) | |
177 | { | |
178 | struct subchannel *sch; | |
179 | struct irb *irb; | |
180 | ||
181 | sch = to_subchannel(cdev->dev.parent); | |
182 | irb = &cdev->private->irb; | |
183 | /* Did we get a proper answer ? */ | |
184 | if (cdev->private->senseid.cu_type != 0xFFFF && | |
185 | cdev->private->senseid.reserved == 0xFF) { | |
186 | if (irb->scsw.count < sizeof (struct senseid) - 8) | |
187 | cdev->private->flags.esid = 1; | |
188 | return 0; /* Success */ | |
189 | } | |
190 | /* Check the error cases. */ | |
d23861ff CH |
191 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { |
192 | /* Retry Sense ID if requested. */ | |
193 | if (cdev->private->flags.intretry) { | |
194 | cdev->private->flags.intretry = 0; | |
195 | return -EAGAIN; | |
196 | } | |
1da177e4 | 197 | return -ETIME; |
d23861ff | 198 | } |
1da177e4 LT |
199 | if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) { |
200 | /* | |
201 | * if the device doesn't support the SenseID | |
202 | * command further retries wouldn't help ... | |
203 | * NB: We don't check here for intervention required like we | |
204 | * did before, because tape devices with no tape inserted | |
205 | * may present this status *in conjunction with* the | |
206 | * sense id information. So, for intervention required, | |
207 | * we use the "whack it until it talks" strategy... | |
208 | */ | |
fb6958a5 CH |
209 | CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel " |
210 | "0.%x.%04x reports cmd reject\n", | |
78964268 | 211 | cdev->private->dev_id.devno, sch->schid.ssid, |
fb6958a5 | 212 | sch->schid.sch_no); |
1da177e4 LT |
213 | return -EOPNOTSUPP; |
214 | } | |
215 | if (irb->esw.esw0.erw.cons) { | |
fb6958a5 | 216 | CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, " |
1da177e4 LT |
217 | "lpum %02X, cnt %02d, sns :" |
218 | " %02X%02X%02X%02X %02X%02X%02X%02X ...\n", | |
78964268 CH |
219 | cdev->private->dev_id.ssid, |
220 | cdev->private->dev_id.devno, | |
1da177e4 LT |
221 | irb->esw.esw0.sublog.lpum, |
222 | irb->esw.esw0.erw.scnt, | |
223 | irb->ecw[0], irb->ecw[1], | |
224 | irb->ecw[2], irb->ecw[3], | |
225 | irb->ecw[4], irb->ecw[5], | |
226 | irb->ecw[6], irb->ecw[7]); | |
227 | return -EAGAIN; | |
228 | } | |
229 | if (irb->scsw.cc == 3) { | |
230 | if ((sch->orb.lpm & | |
231 | sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0) | |
fb6958a5 CH |
232 | CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x " |
233 | "on subchannel 0.%x.%04x is " | |
234 | "'not operational'\n", sch->orb.lpm, | |
78964268 CH |
235 | cdev->private->dev_id.devno, |
236 | sch->schid.ssid, sch->schid.sch_no); | |
1da177e4 LT |
237 | return -EACCES; |
238 | } | |
239 | /* Hmm, whatever happened, try again. */ | |
240 | CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on " | |
fb6958a5 | 241 | "subchannel 0.%x.%04x returns status %02X%02X\n", |
78964268 CH |
242 | cdev->private->dev_id.devno, sch->schid.ssid, |
243 | sch->schid.sch_no, | |
1da177e4 LT |
244 | irb->scsw.dstat, irb->scsw.cstat); |
245 | return -EAGAIN; | |
246 | } | |
247 | ||
248 | /* | |
249 | * Got interrupt for Sense ID. | |
250 | */ | |
251 | void | |
252 | ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event) | |
253 | { | |
254 | struct subchannel *sch; | |
255 | struct irb *irb; | |
256 | int ret; | |
257 | ||
258 | sch = to_subchannel(cdev->dev.parent); | |
259 | irb = (struct irb *) __LC_IRB; | |
260 | /* Retry sense id, if needed. */ | |
261 | if (irb->scsw.stctl == | |
262 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { | |
263 | if ((irb->scsw.cc == 1) || !irb->scsw.actl) { | |
264 | ret = __ccw_device_sense_id_start(cdev); | |
265 | if (ret && ret != -EBUSY) | |
266 | ccw_device_sense_id_done(cdev, ret); | |
267 | } | |
268 | return; | |
269 | } | |
270 | if (ccw_device_accumulate_and_sense(cdev, irb) != 0) | |
271 | return; | |
272 | ret = ccw_device_check_sense_id(cdev); | |
273 | memset(&cdev->private->irb, 0, sizeof(struct irb)); | |
274 | switch (ret) { | |
275 | /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */ | |
276 | case 0: /* Sense id succeeded. */ | |
277 | case -ETIME: /* Sense id stopped by timeout. */ | |
278 | ccw_device_sense_id_done(cdev, ret); | |
279 | break; | |
280 | case -EACCES: /* channel is not operational. */ | |
281 | sch->lpm &= ~cdev->private->imask; | |
282 | cdev->private->imask >>= 1; | |
283 | cdev->private->iretry = 5; | |
284 | /* fall through. */ | |
285 | case -EAGAIN: /* try again. */ | |
286 | ret = __ccw_device_sense_id_start(cdev); | |
287 | if (ret == 0 || ret == -EBUSY) | |
288 | break; | |
289 | /* fall through. */ | |
290 | default: /* Sense ID failed. Try asking VM. */ | |
291 | if (MACHINE_IS_VM) { | |
78964268 | 292 | VM_virtual_device_info (cdev->private->dev_id.devno, |
1da177e4 LT |
293 | &cdev->private->senseid); |
294 | if (cdev->private->senseid.cu_type != 0xFFFF) { | |
295 | /* Got the device information from VM. */ | |
296 | ccw_device_sense_id_done(cdev, 0); | |
297 | return; | |
298 | } | |
299 | } | |
300 | /* | |
301 | * If we can't couldn't identify the device type we | |
302 | * consider the device "not operational". | |
303 | */ | |
304 | ccw_device_sense_id_done(cdev, -ENODEV); | |
305 | break; | |
306 | } | |
307 | } |