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