summaryrefslogtreecommitdiff
path: root/drivers/s390/cio/device_status.c
blob: 929f8fb505f2066b6d4079ca5af2536b3e954fbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
 * drivers/s390/cio/device_status.c
 *
 *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
 *			 IBM Corporation
 *    Author(s): Cornelia Huck(cohuck@de.ibm.com)
 *		 Martin Schwidefsky (schwidefsky@de.ibm.com)
 *
 * Status accumulation and basic sense functions.
 */

#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/ccwdev.h>
#include <asm/cio.h>

#include "cio.h"
#include "cio_debug.h"
#include "css.h"
#include "device.h"
#include "ioasm.h"

/*
 * Check for any kind of channel or interface control check but don't
 * issue the message for the console device
 */
static inline void
ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
{
	if (!(irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
				 SCHN_STAT_CHN_CTRL_CHK |
				 SCHN_STAT_INTF_CTRL_CHK)))
		return;
		
	CIO_MSG_EVENT(0, "Channel-Check or Interface-Control-Check "
		      "received"
		      " ... device %04X on subchannel %04X, dev_stat "
		      ": %02X sch_stat : %02X\n",
		      cdev->private->devno, cdev->private->sch_no,
		      irb->scsw.dstat, irb->scsw.cstat);

	if (irb->scsw.cc != 3) {
		char dbf_text[15];

		sprintf(dbf_text, "chk%x", cdev->private->sch_no);
		CIO_TRACE_EVENT(0, dbf_text);
		CIO_HEX_EVENT(0, irb, sizeof (struct irb));
	}
}

/*
 * Some paths became not operational (pno bit in scsw is set).
 */
static void
ccw_device_path_notoper(struct ccw_device *cdev)
{
	struct subchannel *sch;

	sch = to_subchannel(cdev->dev.parent);
	stsch (sch->schid, &sch->schib);

	CIO_MSG_EVENT(0, "%s(%04x) - path(s) %02x are "
		      "not operational \n", __FUNCTION__, sch->schid.sch_no,
		      sch->schib.pmcw.pnom);

	sch->lpm &= ~sch->schib.pmcw.pnom;
	if (cdev->private->options.pgroup)
		cdev->private->flags.doverify = 1;
}

/*
 * Copy valid bits from the extended control word to device irb.
 */
static inline void
ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
{
	/*
	 * Copy extended control bit if it is valid... yes there
	 * are condition that have to be met for the extended control
	 * bit to have meaning. Sick.
	 */
	cdev->private->irb.scsw.ectl = 0;
	if ((irb->scsw.stctl & SCSW_STCTL_ALERT_STATUS) &&
	    !(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS))
		cdev->private->irb.scsw.ectl = irb->scsw.ectl;
	/* Check if extended control word is valid. */
	if (!cdev->private->irb.scsw.ectl)
		return;
	/* Copy concurrent sense / model dependent information. */
	memcpy (&cdev->private->irb.ecw, irb->ecw, sizeof (irb->ecw));
}

/*
 * Check if extended status word is valid.
 */
static inline int
ccw_device_accumulate_esw_valid(struct irb *irb)
{
	if (!irb->scsw.eswf && irb->scsw.stctl == SCSW_STCTL_STATUS_PEND)
		return 0;
	if (irb->scsw.stctl == 
	    		(SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
	    !(irb->scsw.actl & SCSW_ACTL_SUSPENDED))
		return 0;
	return 1;
}

/*
 * Copy valid bits from the extended status word to device irb.
 */
static inline void
ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
{
	struct irb *cdev_irb;
	struct sublog *cdev_sublog, *sublog;

	if (!ccw_device_accumulate_esw_valid(irb))
		return;

	cdev_irb = &cdev->private->irb;

	/* Copy last path used mask. */
	cdev_irb->esw.esw1.lpum = irb->esw.esw1.lpum;

	/* Copy subchannel logout information if esw is of format 0. */
	if (irb->scsw.eswf) {
		cdev_sublog = &cdev_irb->esw.esw0.sublog;
		sublog = &irb->esw.esw0.sublog;
		/* Copy extended status flags. */
		cdev_sublog->esf = sublog->esf;
		/*
		 * Copy fields that have a meaning for channel data check
		 * channel control check and interface control check.
		 */
		if (irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
				       SCHN_STAT_CHN_CTRL_CHK |
				       SCHN_STAT_INTF_CTRL_CHK)) {
			/* Copy ancillary report bit. */
			cdev_sublog->arep = sublog->arep;
			/* Copy field-validity-flags. */
			cdev_sublog->fvf = sublog->fvf;
			/* Copy storage access code. */
			cdev_sublog->sacc = sublog->sacc;
			/* Copy termination code. */
			cdev_sublog->termc = sublog->termc;
			/* Copy sequence code. */
			cdev_sublog->seqc = sublog->seqc;
		}
		/* Copy device status check. */
		cdev_sublog->devsc = sublog->devsc;
		/* Copy secondary error. */
		cdev_sublog->serr = sublog->serr;
		/* Copy i/o-error alert. */
		cdev_sublog->ioerr = sublog->ioerr;
		/* Copy channel path timeout bit. */
		if (irb->scsw.cstat & SCHN_STAT_INTF_CTRL_CHK)
			cdev_irb->esw.esw0.erw.cpt = irb->esw.esw0.erw.cpt;
		/* Copy failing storage address validity flag. */
		cdev_irb->esw.esw0.erw.fsavf = irb->esw.esw0.erw.fsavf;
		if (cdev_irb->esw.esw0.erw.fsavf) {
			/* ... and copy the failing storage address. */
			memcpy(cdev_irb->esw.esw0.faddr, irb->esw.esw0.faddr,
			       sizeof (irb->esw.esw0.faddr));
			/* ... and copy the failing storage address format. */
			cdev_irb->esw.esw0.erw.fsaf = irb->esw.esw0.erw.fsaf;
		}
		/* Copy secondary ccw address validity bit. */
		cdev_irb->esw.esw0.erw.scavf = irb->esw.esw0.erw.scavf;
		if (irb->esw.esw0.erw.scavf)
			/* ... and copy the secondary ccw address. */
			cdev_irb->esw.esw0.saddr = irb->esw.esw0.saddr;
		
	}
	/* FIXME: DCTI for format 2? */

	/* Copy authorization bit. */
	cdev_irb->esw.esw0.erw.auth = irb->esw.esw0.erw.auth;
	/* Copy path verification required flag. */
	cdev_irb->esw.esw0.erw.pvrf = irb->esw.esw0.erw.pvrf;
	if (irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup)
		cdev->private->flags.doverify = 1;
	/* Copy concurrent sense bit. */
	cdev_irb->esw.esw0.erw.cons = irb->esw.esw0.erw.cons;
	if (irb->esw.esw0.erw.cons)
		cdev_irb->esw.esw0.erw.scnt = irb->esw.esw0.erw.scnt;
}

/*
 * Accumulate status from irb to devstat.
 */
void
ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
{
	struct irb *cdev_irb;

	/*
	 * Check if the status pending bit is set in stctl.
	 * If not, the remaining bit have no meaning and we must ignore them.
	 * The esw is not meaningful as well...
	 */
	if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
		return;

	/* Check for channel checks and interface control checks. */
	ccw_device_msg_control_check(cdev, irb);

	/* Check for path not operational. */
	if (irb->scsw.pno && irb->scsw.fctl != 0 &&
	    (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
	     (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
		ccw_device_path_notoper(cdev);

	/*
	 * Don't accumulate unsolicited interrupts.
	 */
	if ((irb->scsw.stctl ==
	     (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
	    (!irb->scsw.cc))
		return;

	cdev_irb = &cdev->private->irb;

	/* Copy bits which are valid only for the start function. */
	if (irb->scsw.fctl & SCSW_FCTL_START_FUNC) {
		/* Copy key. */
		cdev_irb->scsw.key = irb->scsw.key;
		/* Copy suspend control bit. */
		cdev_irb->scsw.sctl = irb->scsw.sctl;
		/* Accumulate deferred condition code. */
		cdev_irb->scsw.cc |= irb->scsw.cc;
		/* Copy ccw format bit. */
		cdev_irb->scsw.fmt = irb->scsw.fmt;
		/* Copy prefetch bit. */
		cdev_irb->scsw.pfch = irb->scsw.pfch;
		/* Copy initial-status-interruption-control. */
		cdev_irb->scsw.isic = irb->scsw.isic;
		/* Copy address limit checking control. */
		cdev_irb->scsw.alcc = irb->scsw.alcc;
		/* Copy suppress suspend bit. */
		cdev_irb->scsw.ssi = irb->scsw.ssi;
	}

	/* Take care of the extended control bit and extended control word. */
	ccw_device_accumulate_ecw(cdev, irb);
	    
	/* Accumulate function control. */
	cdev_irb->scsw.fctl |= irb->scsw.fctl;
	/* Copy activity control. */
	cdev_irb->scsw.actl= irb->scsw.actl;
	/* Accumulate status control. */
	cdev_irb->scsw.stctl |= irb->scsw.stctl;
	/*
	 * Copy ccw address if it is valid. This is a bit simplified
	 * but should be close enough for all practical purposes.
	 */
	if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) ||
	    ((irb->scsw.stctl == 
	      (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND)) &&
	     (irb->scsw.actl & SCSW_ACTL_DEVACT) &&
	     (irb->scsw.actl & SCSW_ACTL_SCHACT)) ||
	    (irb->scsw.actl & SCSW_ACTL_SUSPENDED))
		cdev_irb->scsw.cpa = irb->scsw.cpa;
	/* Accumulate device status, but not the device busy flag. */
	cdev_irb->scsw.dstat &= ~DEV_STAT_BUSY;
	cdev_irb->scsw.dstat |= irb->scsw.dstat;
	/* Accumulate subchannel status. */
	cdev_irb->scsw.cstat |= irb->scsw.cstat;
	/* Copy residual count if it is valid. */
	if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
	    (irb->scsw.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN)) == 0)
		cdev_irb->scsw.count = irb->scsw.count;

	/* Take care of bits in the extended status word. */
	ccw_device_accumulate_esw(cdev, irb);

	/*
	 * Check whether we must issue a SENSE CCW ourselves if there is no
	 * concurrent sense facility installed for the subchannel.
	 * No sense is required if no delayed sense is pending
	 * and we did not get a unit check without sense information.
	 *
	 * Note: We should check for ioinfo[irq]->flags.consns but VM
	 *	 violates the ESA/390 architecture and doesn't present an
	 *	 operand exception for virtual devices without concurrent
	 *	 sense facility available/supported when enabling the
	 *	 concurrent sense facility.
	 */
	if ((cdev_irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
	    !(cdev_irb->esw.esw0.erw.cons))
		cdev->private->flags.dosense = 1;
}

/*
 * Do a basic sense.
 */
int
ccw_device_do_sense(struct ccw_device *cdev, struct irb *irb)
{
	struct subchannel *sch;

	sch = to_subchannel(cdev->dev.parent);

	/* A sense is required, can we do it now ? */
	if ((irb->scsw.actl  & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
		/*
		 * we received an Unit Check but we have no final
		 *  status yet, therefore we must delay the SENSE
		 *  processing. We must not report this intermediate
		 *  status to the device interrupt handler.
		 */
		return -EBUSY;

	/*
	 * We have ending status but no sense information. Do a basic sense.
	 */
	sch = to_subchannel(cdev->dev.parent);
	sch->sense_ccw.cmd_code = CCW_CMD_BASIC_SENSE;
	sch->sense_ccw.cda = (__u32) __pa(cdev->private->irb.ecw);
	sch->sense_ccw.count = SENSE_MAX_COUNT;
	sch->sense_ccw.flags = CCW_FLAG_SLI;

	return cio_start (sch, &sch->sense_ccw, 0xff);
}

/*
 * Add information from basic sense to devstat.
 */
void
ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
{
	/*
	 * Check if the status pending bit is set in stctl.
	 * If not, the remaining bit have no meaning and we must ignore them.
	 * The esw is not meaningful as well...
	 */
	if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
		return;

	/* Check for channel checks and interface control checks. */
	ccw_device_msg_control_check(cdev, irb);

	/* Check for path not operational. */
	if (irb->scsw.pno && irb->scsw.fctl != 0 &&
	    (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
	     (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
		ccw_device_path_notoper(cdev);

	if (!(irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
	    (irb->scsw.dstat & DEV_STAT_CHN_END)) {
		cdev->private->irb.esw.esw0.erw.cons = 1;
		cdev->private->flags.dosense = 0;
	}
	/* Check if path verification is required. */
	if (ccw_device_accumulate_esw_valid(irb) &&
	    irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup) 
		cdev->private->flags.doverify = 1;
}

/*
 * This function accumulates the status into the private devstat and
 * starts a basic sense if one is needed.
 */
int
ccw_device_accumulate_and_sense(struct ccw_device *cdev, struct irb *irb)
{
	ccw_device_accumulate_irb(cdev, irb);
	if ((irb->scsw.actl  & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
		return -EBUSY;
	/* Check for basic sense. */
	if (cdev->private->flags.dosense &&
	    !(irb->scsw.dstat & DEV_STAT_UNIT_CHECK)) {
		cdev->private->irb.esw.esw0.erw.cons = 1;
		cdev->private->flags.dosense = 0;
		return 0;
	}
	if (cdev->private->flags.dosense) {
		ccw_device_do_sense(cdev, irb);
		return -EBUSY;
	}
	return 0;
}