blob: 25d99bd2808959a89d5099e48d20b6d5b914c0e4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/device_status.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 * Status accumulation and basic sense functions.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/init.h>
14
15#include <asm/ccwdev.h>
16#include <asm/cio.h>
17
18#include "cio.h"
19#include "cio_debug.h"
20#include "css.h"
21#include "device.h"
22#include "ioasm.h"
23
24/*
25 * Check for any kind of channel or interface control check but don't
26 * issue the message for the console device
27 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +010028static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070029ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
30{
31 if (!(irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
32 SCHN_STAT_CHN_CTRL_CHK |
33 SCHN_STAT_INTF_CTRL_CHK)))
34 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 CIO_MSG_EVENT(0, "Channel-Check or Interface-Control-Check "
36 "received"
Cornelia Huckfb6958a2006-01-06 00:19:25 -080037 " ... device %04x on subchannel 0.%x.%04x, dev_stat "
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 ": %02X sch_stat : %02X\n",
Cornelia Huck78964262006-10-11 15:31:38 +020039 cdev->private->dev_id.devno, cdev->private->schid.ssid,
40 cdev->private->schid.sch_no,
Cornelia Huck1d3ac7a2005-07-27 11:45:00 -070041 irb->scsw.dstat, irb->scsw.cstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 if (irb->scsw.cc != 3) {
44 char dbf_text[15];
45
Cornelia Huck78964262006-10-11 15:31:38 +020046 sprintf(dbf_text, "chk%x", cdev->private->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 CIO_TRACE_EVENT(0, dbf_text);
Cornelia Huck1d3ac7a2005-07-27 11:45:00 -070048 CIO_HEX_EVENT(0, irb, sizeof (struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 }
50}
51
52/*
53 * Some paths became not operational (pno bit in scsw is set).
54 */
55static void
56ccw_device_path_notoper(struct ccw_device *cdev)
57{
58 struct subchannel *sch;
59
60 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -080061 stsch (sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Cornelia Huckfb6958a2006-01-06 00:19:25 -080063 CIO_MSG_EVENT(0, "%s(0.%x.%04x) - path(s) %02x are "
64 "not operational \n", __FUNCTION__,
65 sch->schid.ssid, sch->schid.sch_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 sch->schib.pmcw.pnom);
67
68 sch->lpm &= ~sch->schib.pmcw.pnom;
Cornelia Huck7e560812006-07-12 16:40:19 +020069 cdev->private->flags.doverify = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72/*
73 * Copy valid bits from the extended control word to device irb.
74 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +010075static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070076ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
77{
78 /*
79 * Copy extended control bit if it is valid... yes there
80 * are condition that have to be met for the extended control
81 * bit to have meaning. Sick.
82 */
83 cdev->private->irb.scsw.ectl = 0;
84 if ((irb->scsw.stctl & SCSW_STCTL_ALERT_STATUS) &&
85 !(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS))
86 cdev->private->irb.scsw.ectl = irb->scsw.ectl;
87 /* Check if extended control word is valid. */
88 if (!cdev->private->irb.scsw.ectl)
89 return;
90 /* Copy concurrent sense / model dependent information. */
91 memcpy (&cdev->private->irb.ecw, irb->ecw, sizeof (irb->ecw));
92}
93
94/*
95 * Check if extended status word is valid.
96 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +010097static int
Linus Torvalds1da177e2005-04-16 15:20:36 -070098ccw_device_accumulate_esw_valid(struct irb *irb)
99{
100 if (!irb->scsw.eswf && irb->scsw.stctl == SCSW_STCTL_STATUS_PEND)
101 return 0;
102 if (irb->scsw.stctl ==
103 (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
104 !(irb->scsw.actl & SCSW_ACTL_SUSPENDED))
105 return 0;
106 return 1;
107}
108
109/*
110 * Copy valid bits from the extended status word to device irb.
111 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100112static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
114{
115 struct irb *cdev_irb;
116 struct sublog *cdev_sublog, *sublog;
117
118 if (!ccw_device_accumulate_esw_valid(irb))
119 return;
120
121 cdev_irb = &cdev->private->irb;
122
123 /* Copy last path used mask. */
124 cdev_irb->esw.esw1.lpum = irb->esw.esw1.lpum;
125
126 /* Copy subchannel logout information if esw is of format 0. */
127 if (irb->scsw.eswf) {
128 cdev_sublog = &cdev_irb->esw.esw0.sublog;
129 sublog = &irb->esw.esw0.sublog;
130 /* Copy extended status flags. */
131 cdev_sublog->esf = sublog->esf;
132 /*
133 * Copy fields that have a meaning for channel data check
134 * channel control check and interface control check.
135 */
136 if (irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
137 SCHN_STAT_CHN_CTRL_CHK |
138 SCHN_STAT_INTF_CTRL_CHK)) {
139 /* Copy ancillary report bit. */
140 cdev_sublog->arep = sublog->arep;
141 /* Copy field-validity-flags. */
142 cdev_sublog->fvf = sublog->fvf;
143 /* Copy storage access code. */
144 cdev_sublog->sacc = sublog->sacc;
145 /* Copy termination code. */
146 cdev_sublog->termc = sublog->termc;
147 /* Copy sequence code. */
148 cdev_sublog->seqc = sublog->seqc;
149 }
150 /* Copy device status check. */
151 cdev_sublog->devsc = sublog->devsc;
152 /* Copy secondary error. */
153 cdev_sublog->serr = sublog->serr;
154 /* Copy i/o-error alert. */
155 cdev_sublog->ioerr = sublog->ioerr;
156 /* Copy channel path timeout bit. */
157 if (irb->scsw.cstat & SCHN_STAT_INTF_CTRL_CHK)
158 cdev_irb->esw.esw0.erw.cpt = irb->esw.esw0.erw.cpt;
159 /* Copy failing storage address validity flag. */
160 cdev_irb->esw.esw0.erw.fsavf = irb->esw.esw0.erw.fsavf;
161 if (cdev_irb->esw.esw0.erw.fsavf) {
162 /* ... and copy the failing storage address. */
163 memcpy(cdev_irb->esw.esw0.faddr, irb->esw.esw0.faddr,
164 sizeof (irb->esw.esw0.faddr));
165 /* ... and copy the failing storage address format. */
166 cdev_irb->esw.esw0.erw.fsaf = irb->esw.esw0.erw.fsaf;
167 }
168 /* Copy secondary ccw address validity bit. */
169 cdev_irb->esw.esw0.erw.scavf = irb->esw.esw0.erw.scavf;
170 if (irb->esw.esw0.erw.scavf)
171 /* ... and copy the secondary ccw address. */
172 cdev_irb->esw.esw0.saddr = irb->esw.esw0.saddr;
173
174 }
175 /* FIXME: DCTI for format 2? */
176
177 /* Copy authorization bit. */
178 cdev_irb->esw.esw0.erw.auth = irb->esw.esw0.erw.auth;
179 /* Copy path verification required flag. */
180 cdev_irb->esw.esw0.erw.pvrf = irb->esw.esw0.erw.pvrf;
Cornelia Huck7e560812006-07-12 16:40:19 +0200181 if (irb->esw.esw0.erw.pvrf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 cdev->private->flags.doverify = 1;
183 /* Copy concurrent sense bit. */
184 cdev_irb->esw.esw0.erw.cons = irb->esw.esw0.erw.cons;
185 if (irb->esw.esw0.erw.cons)
186 cdev_irb->esw.esw0.erw.scnt = irb->esw.esw0.erw.scnt;
187}
188
189/*
190 * Accumulate status from irb to devstat.
191 */
192void
193ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
194{
195 struct irb *cdev_irb;
196
197 /*
198 * Check if the status pending bit is set in stctl.
199 * If not, the remaining bit have no meaning and we must ignore them.
200 * The esw is not meaningful as well...
201 */
202 if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
203 return;
204
205 /* Check for channel checks and interface control checks. */
206 ccw_device_msg_control_check(cdev, irb);
207
208 /* Check for path not operational. */
209 if (irb->scsw.pno && irb->scsw.fctl != 0 &&
210 (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
211 (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
212 ccw_device_path_notoper(cdev);
213
214 /*
215 * Don't accumulate unsolicited interrupts.
216 */
217 if ((irb->scsw.stctl ==
218 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
219 (!irb->scsw.cc))
220 return;
221
222 cdev_irb = &cdev->private->irb;
223
224 /* Copy bits which are valid only for the start function. */
225 if (irb->scsw.fctl & SCSW_FCTL_START_FUNC) {
226 /* Copy key. */
227 cdev_irb->scsw.key = irb->scsw.key;
228 /* Copy suspend control bit. */
229 cdev_irb->scsw.sctl = irb->scsw.sctl;
230 /* Accumulate deferred condition code. */
231 cdev_irb->scsw.cc |= irb->scsw.cc;
232 /* Copy ccw format bit. */
233 cdev_irb->scsw.fmt = irb->scsw.fmt;
234 /* Copy prefetch bit. */
235 cdev_irb->scsw.pfch = irb->scsw.pfch;
236 /* Copy initial-status-interruption-control. */
237 cdev_irb->scsw.isic = irb->scsw.isic;
238 /* Copy address limit checking control. */
239 cdev_irb->scsw.alcc = irb->scsw.alcc;
240 /* Copy suppress suspend bit. */
241 cdev_irb->scsw.ssi = irb->scsw.ssi;
242 }
243
244 /* Take care of the extended control bit and extended control word. */
245 ccw_device_accumulate_ecw(cdev, irb);
246
247 /* Accumulate function control. */
248 cdev_irb->scsw.fctl |= irb->scsw.fctl;
249 /* Copy activity control. */
250 cdev_irb->scsw.actl= irb->scsw.actl;
251 /* Accumulate status control. */
252 cdev_irb->scsw.stctl |= irb->scsw.stctl;
253 /*
254 * Copy ccw address if it is valid. This is a bit simplified
255 * but should be close enough for all practical purposes.
256 */
257 if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) ||
258 ((irb->scsw.stctl ==
259 (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND)) &&
260 (irb->scsw.actl & SCSW_ACTL_DEVACT) &&
261 (irb->scsw.actl & SCSW_ACTL_SCHACT)) ||
262 (irb->scsw.actl & SCSW_ACTL_SUSPENDED))
263 cdev_irb->scsw.cpa = irb->scsw.cpa;
264 /* Accumulate device status, but not the device busy flag. */
265 cdev_irb->scsw.dstat &= ~DEV_STAT_BUSY;
Cornelia Huck25c61a12007-03-26 20:42:41 +0200266 /* dstat is not always valid. */
267 if (irb->scsw.stctl &
268 (SCSW_STCTL_PRIM_STATUS | SCSW_STCTL_SEC_STATUS
269 | SCSW_STCTL_INTER_STATUS | SCSW_STCTL_ALERT_STATUS))
270 cdev_irb->scsw.dstat |= irb->scsw.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* Accumulate subchannel status. */
272 cdev_irb->scsw.cstat |= irb->scsw.cstat;
273 /* Copy residual count if it is valid. */
274 if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
275 (irb->scsw.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN)) == 0)
276 cdev_irb->scsw.count = irb->scsw.count;
277
278 /* Take care of bits in the extended status word. */
279 ccw_device_accumulate_esw(cdev, irb);
280
281 /*
282 * Check whether we must issue a SENSE CCW ourselves if there is no
283 * concurrent sense facility installed for the subchannel.
284 * No sense is required if no delayed sense is pending
285 * and we did not get a unit check without sense information.
286 *
287 * Note: We should check for ioinfo[irq]->flags.consns but VM
288 * violates the ESA/390 architecture and doesn't present an
289 * operand exception for virtual devices without concurrent
290 * sense facility available/supported when enabling the
291 * concurrent sense facility.
292 */
293 if ((cdev_irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
294 !(cdev_irb->esw.esw0.erw.cons))
295 cdev->private->flags.dosense = 1;
296}
297
298/*
299 * Do a basic sense.
300 */
301int
302ccw_device_do_sense(struct ccw_device *cdev, struct irb *irb)
303{
304 struct subchannel *sch;
305
306 sch = to_subchannel(cdev->dev.parent);
307
308 /* A sense is required, can we do it now ? */
309 if ((irb->scsw.actl & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
310 /*
311 * we received an Unit Check but we have no final
312 * status yet, therefore we must delay the SENSE
313 * processing. We must not report this intermediate
314 * status to the device interrupt handler.
315 */
316 return -EBUSY;
317
318 /*
319 * We have ending status but no sense information. Do a basic sense.
320 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 sch->sense_ccw.cmd_code = CCW_CMD_BASIC_SENSE;
322 sch->sense_ccw.cda = (__u32) __pa(cdev->private->irb.ecw);
323 sch->sense_ccw.count = SENSE_MAX_COUNT;
324 sch->sense_ccw.flags = CCW_FLAG_SLI;
325
Cornelia Huckd23861f2006-12-04 15:41:04 +0100326 /* Reset internal retry indication. */
327 cdev->private->flags.intretry = 0;
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return cio_start (sch, &sch->sense_ccw, 0xff);
330}
331
332/*
333 * Add information from basic sense to devstat.
334 */
335void
336ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
337{
338 /*
339 * Check if the status pending bit is set in stctl.
340 * If not, the remaining bit have no meaning and we must ignore them.
341 * The esw is not meaningful as well...
342 */
343 if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
344 return;
345
346 /* Check for channel checks and interface control checks. */
347 ccw_device_msg_control_check(cdev, irb);
348
349 /* Check for path not operational. */
350 if (irb->scsw.pno && irb->scsw.fctl != 0 &&
351 (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
352 (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
353 ccw_device_path_notoper(cdev);
354
355 if (!(irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
356 (irb->scsw.dstat & DEV_STAT_CHN_END)) {
357 cdev->private->irb.esw.esw0.erw.cons = 1;
358 cdev->private->flags.dosense = 0;
359 }
360 /* Check if path verification is required. */
361 if (ccw_device_accumulate_esw_valid(irb) &&
Cornelia Huck7e560812006-07-12 16:40:19 +0200362 irb->esw.esw0.erw.pvrf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 cdev->private->flags.doverify = 1;
364}
365
366/*
367 * This function accumulates the status into the private devstat and
368 * starts a basic sense if one is needed.
369 */
370int
371ccw_device_accumulate_and_sense(struct ccw_device *cdev, struct irb *irb)
372{
373 ccw_device_accumulate_irb(cdev, irb);
374 if ((irb->scsw.actl & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
375 return -EBUSY;
376 /* Check for basic sense. */
377 if (cdev->private->flags.dosense &&
378 !(irb->scsw.dstat & DEV_STAT_UNIT_CHECK)) {
379 cdev->private->irb.esw.esw0.erw.cons = 1;
380 cdev->private->flags.dosense = 0;
381 return 0;
382 }
383 if (cdev->private->flags.dosense) {
384 ccw_device_do_sense(cdev, irb);
385 return -EBUSY;
386 }
387 return 0;
388}
389