blob: 156f3f9786b52e6ddfaeb765c81fec7ff0f77c73 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/device_id.c
3 *
4 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
5 * IBM Corporation
Cornelia Huck4ce3b302006-01-14 13:21:04 -08006 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 *
9 * Sense ID functions.
10 */
11
12#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
Ahmed S. Darwish045236a2007-02-12 15:49:51 +010014#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/ccwdev.h>
17#include <asm/delay.h>
18#include <asm/cio.h>
19#include <asm/lowcore.h>
Michael Holzheu0a87c5c2007-08-22 13:51:40 +020020#include <asm/diag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include "cio.h"
23#include "cio_debug.h"
24#include "css.h"
25#include "device.h"
26#include "ioasm.h"
27
28/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * Input :
30 * devno - device number
31 * ps - pointer to sense ID data area
32 * Output : none
33 */
34static void
35VM_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 }
Ahmed S. Darwish045236a2007-02-12 15:49:51 +010090 for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 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 */
111static int
112__ccw_device_sense_id_start(struct ccw_device *cdev)
113{
114 struct subchannel *sch;
115 struct ccw1 *ccw;
Cornelia Huckc94dec92007-12-04 16:09:01 +0100116 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 sch = to_subchannel(cdev->dev.parent);
119 /* Setup sense channel program. */
120 ccw = cdev->private->iccws;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 ccw->cmd_code = CCW_CMD_SENSE_ID;
122 ccw->cda = (__u32) __pa (&cdev->private->senseid);
123 ccw->count = sizeof (struct senseid);
124 ccw->flags = CCW_FLAG_SLI;
125
126 /* Reset device status. */
127 memset(&cdev->private->irb, 0, sizeof(struct irb));
128
Cornelia Huckc94dec92007-12-04 16:09:01 +0100129 /* Try on every path. */
130 ret = -ENODEV;
131 while (cdev->private->imask != 0) {
132 if ((sch->opm & cdev->private->imask) != 0 &&
133 cdev->private->iretry > 0) {
134 cdev->private->iretry--;
135 /* Reset internal retry indication. */
136 cdev->private->flags.intretry = 0;
137 ret = cio_start (sch, cdev->private->iccws,
138 cdev->private->imask);
139 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
140 if (ret != -EACCES)
141 return ret;
142 }
143 cdev->private->imask >>= 1;
144 cdev->private->iretry = 5;
145 }
146 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149void
150ccw_device_sense_id_start(struct ccw_device *cdev)
151{
152 int ret;
153
154 memset (&cdev->private->senseid, 0, sizeof (struct senseid));
155 cdev->private->senseid.cu_type = 0xFFFF;
Cornelia Huckc94dec92007-12-04 16:09:01 +0100156 cdev->private->imask = 0x80;
157 cdev->private->iretry = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 ret = __ccw_device_sense_id_start(cdev);
159 if (ret && ret != -EBUSY)
160 ccw_device_sense_id_done(cdev, ret);
161}
162
163/*
164 * Called from interrupt context to check if a valid answer
165 * to Sense ID was received.
166 */
167static int
168ccw_device_check_sense_id(struct ccw_device *cdev)
169{
170 struct subchannel *sch;
171 struct irb *irb;
172
173 sch = to_subchannel(cdev->dev.parent);
174 irb = &cdev->private->irb;
175 /* Did we get a proper answer ? */
176 if (cdev->private->senseid.cu_type != 0xFFFF &&
177 cdev->private->senseid.reserved == 0xFF) {
178 if (irb->scsw.count < sizeof (struct senseid) - 8)
179 cdev->private->flags.esid = 1;
180 return 0; /* Success */
181 }
182 /* Check the error cases. */
Cornelia Huckd23861f2006-12-04 15:41:04 +0100183 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
184 /* Retry Sense ID if requested. */
185 if (cdev->private->flags.intretry) {
186 cdev->private->flags.intretry = 0;
187 return -EAGAIN;
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 return -ETIME;
Cornelia Huckd23861f2006-12-04 15:41:04 +0100190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
192 /*
193 * if the device doesn't support the SenseID
194 * command further retries wouldn't help ...
195 * NB: We don't check here for intervention required like we
196 * did before, because tape devices with no tape inserted
197 * may present this status *in conjunction with* the
198 * sense id information. So, for intervention required,
199 * we use the "whack it until it talks" strategy...
200 */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800201 CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
202 "0.%x.%04x reports cmd reject\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200203 cdev->private->dev_id.devno, sch->schid.ssid,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800204 sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return -EOPNOTSUPP;
206 }
207 if (irb->esw.esw0.erw.cons) {
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800208 CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 "lpum %02X, cnt %02d, sns :"
210 " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200211 cdev->private->dev_id.ssid,
212 cdev->private->dev_id.devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 irb->esw.esw0.sublog.lpum,
214 irb->esw.esw0.erw.scnt,
215 irb->ecw[0], irb->ecw[1],
216 irb->ecw[2], irb->ecw[3],
217 irb->ecw[4], irb->ecw[5],
218 irb->ecw[6], irb->ecw[7]);
219 return -EAGAIN;
220 }
221 if (irb->scsw.cc == 3) {
222 if ((sch->orb.lpm &
223 sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800224 CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
225 "on subchannel 0.%x.%04x is "
226 "'not operational'\n", sch->orb.lpm,
Cornelia Huck78964262006-10-11 15:31:38 +0200227 cdev->private->dev_id.devno,
228 sch->schid.ssid, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return -EACCES;
230 }
231 /* Hmm, whatever happened, try again. */
232 CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800233 "subchannel 0.%x.%04x returns status %02X%02X\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200234 cdev->private->dev_id.devno, sch->schid.ssid,
235 sch->schid.sch_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 irb->scsw.dstat, irb->scsw.cstat);
237 return -EAGAIN;
238}
239
240/*
241 * Got interrupt for Sense ID.
242 */
243void
244ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
245{
246 struct subchannel *sch;
247 struct irb *irb;
248 int ret;
249
250 sch = to_subchannel(cdev->dev.parent);
251 irb = (struct irb *) __LC_IRB;
252 /* Retry sense id, if needed. */
253 if (irb->scsw.stctl ==
254 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
255 if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
256 ret = __ccw_device_sense_id_start(cdev);
257 if (ret && ret != -EBUSY)
258 ccw_device_sense_id_done(cdev, ret);
259 }
260 return;
261 }
262 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
263 return;
264 ret = ccw_device_check_sense_id(cdev);
265 memset(&cdev->private->irb, 0, sizeof(struct irb));
266 switch (ret) {
267 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
268 case 0: /* Sense id succeeded. */
269 case -ETIME: /* Sense id stopped by timeout. */
270 ccw_device_sense_id_done(cdev, ret);
271 break;
272 case -EACCES: /* channel is not operational. */
Cornelia Huckc94dec92007-12-04 16:09:01 +0100273 sch->lpm &= ~cdev->private->imask;
274 cdev->private->imask >>= 1;
275 cdev->private->iretry = 5;
276 /* fall through. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 case -EAGAIN: /* try again. */
Cornelia Huckc94dec92007-12-04 16:09:01 +0100278 ret = __ccw_device_sense_id_start(cdev);
279 if (ret == 0 || ret == -EBUSY)
280 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* fall through. */
282 default: /* Sense ID failed. Try asking VM. */
283 if (MACHINE_IS_VM) {
Cornelia Huck78964262006-10-11 15:31:38 +0200284 VM_virtual_device_info (cdev->private->dev_id.devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 &cdev->private->senseid);
286 if (cdev->private->senseid.cu_type != 0xFFFF) {
287 /* Got the device information from VM. */
288 ccw_device_sense_id_done(cdev, 0);
289 return;
290 }
291 }
292 /*
293 * If we can't couldn't identify the device type we
294 * consider the device "not operational".
295 */
296 ccw_device_sense_id_done(cdev, -ENODEV);
297 break;
298 }
299}