Linux 4.16.11
[linux/fpc-iii.git] / drivers / s390 / block / dasd_eckd.c
blob29397a9dba68a37e85b587618249270fa4ba188e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
9 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
13 #define KMSG_COMPONENT "dasd-eckd"
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/hdreg.h> /* HDIO_GETGEO */
19 #include <linux/bio.h>
20 #include <linux/module.h>
21 #include <linux/compat.h>
22 #include <linux/init.h>
23 #include <linux/seq_file.h>
25 #include <asm/css_chars.h>
26 #include <asm/debug.h>
27 #include <asm/idals.h>
28 #include <asm/ebcdic.h>
29 #include <asm/io.h>
30 #include <linux/uaccess.h>
31 #include <asm/cio.h>
32 #include <asm/ccwdev.h>
33 #include <asm/itcw.h>
34 #include <asm/schid.h>
35 #include <asm/chpid.h>
37 #include "dasd_int.h"
38 #include "dasd_eckd.h"
40 #ifdef PRINTK_HEADER
41 #undef PRINTK_HEADER
42 #endif /* PRINTK_HEADER */
43 #define PRINTK_HEADER "dasd(eckd):"
45 #define ECKD_C0(i) (i->home_bytes)
46 #define ECKD_F(i) (i->formula)
47 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
48 (i->factors.f_0x02.f1))
49 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
50 (i->factors.f_0x02.f2))
51 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
52 (i->factors.f_0x02.f3))
53 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
54 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
55 #define ECKD_F6(i) (i->factor6)
56 #define ECKD_F7(i) (i->factor7)
57 #define ECKD_F8(i) (i->factor8)
60 * raw track access always map to 64k in memory
61 * so it maps to 16 blocks of 4k per track
63 #define DASD_RAW_BLOCK_PER_TRACK 16
64 #define DASD_RAW_BLOCKSIZE 4096
65 /* 64k are 128 x 512 byte sectors */
66 #define DASD_RAW_SECTORS_PER_TRACK 128
68 MODULE_LICENSE("GPL");
70 static struct dasd_discipline dasd_eckd_discipline;
72 /* The ccw bus type uses this table to find devices that it sends to
73 * dasd_eckd_probe */
74 static struct ccw_device_id dasd_eckd_ids[] = {
75 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
76 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
77 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
78 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
79 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
80 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
81 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
82 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
83 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
84 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
85 { /* end of list */ },
88 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
90 static struct ccw_driver dasd_eckd_driver; /* see below */
92 static void *rawpadpage;
94 #define INIT_CQR_OK 0
95 #define INIT_CQR_UNFORMATTED 1
96 #define INIT_CQR_ERROR 2
98 /* emergency request for reserve/release */
99 static struct {
100 struct dasd_ccw_req cqr;
101 struct ccw1 ccw;
102 char data[32];
103 } *dasd_reserve_req;
104 static DEFINE_MUTEX(dasd_reserve_mutex);
106 /* definitions for the path verification worker */
107 struct path_verification_work_data {
108 struct work_struct worker;
109 struct dasd_device *device;
110 struct dasd_ccw_req cqr;
111 struct ccw1 ccw;
112 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
113 int isglobal;
114 __u8 tbvpm;
116 static struct path_verification_work_data *path_verification_worker;
117 static DEFINE_MUTEX(dasd_path_verification_mutex);
119 struct check_attention_work_data {
120 struct work_struct worker;
121 struct dasd_device *device;
122 __u8 lpum;
125 static int prepare_itcw(struct itcw *, unsigned int, unsigned int, int,
126 struct dasd_device *, struct dasd_device *,
127 unsigned int, int, unsigned int, unsigned int,
128 unsigned int, unsigned int);
130 /* initial attempt at a probe function. this can be simplified once
131 * the other detection code is gone */
132 static int
133 dasd_eckd_probe (struct ccw_device *cdev)
135 int ret;
137 /* set ECKD specific ccw-device options */
138 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
139 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
140 if (ret) {
141 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
142 "dasd_eckd_probe: could not set "
143 "ccw-device options");
144 return ret;
146 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
147 return ret;
150 static int
151 dasd_eckd_set_online(struct ccw_device *cdev)
153 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
156 static const int sizes_trk0[] = { 28, 148, 84 };
157 #define LABEL_SIZE 140
159 /* head and record addresses of count_area read in analysis ccw */
160 static const int count_area_head[] = { 0, 0, 0, 0, 2 };
161 static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
163 static inline unsigned int
164 round_up_multiple(unsigned int no, unsigned int mult)
166 int rem = no % mult;
167 return (rem ? no - rem + mult : no);
170 static inline unsigned int
171 ceil_quot(unsigned int d1, unsigned int d2)
173 return (d1 + (d2 - 1)) / d2;
176 static unsigned int
177 recs_per_track(struct dasd_eckd_characteristics * rdc,
178 unsigned int kl, unsigned int dl)
180 int dn, kn;
182 switch (rdc->dev_type) {
183 case 0x3380:
184 if (kl)
185 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
186 ceil_quot(dl + 12, 32));
187 else
188 return 1499 / (15 + ceil_quot(dl + 12, 32));
189 case 0x3390:
190 dn = ceil_quot(dl + 6, 232) + 1;
191 if (kl) {
192 kn = ceil_quot(kl + 6, 232) + 1;
193 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
194 9 + ceil_quot(dl + 6 * dn, 34));
195 } else
196 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
197 case 0x9345:
198 dn = ceil_quot(dl + 6, 232) + 1;
199 if (kl) {
200 kn = ceil_quot(kl + 6, 232) + 1;
201 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
202 ceil_quot(dl + 6 * dn, 34));
203 } else
204 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
206 return 0;
209 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
211 geo->cyl = (__u16) cyl;
212 geo->head = cyl >> 16;
213 geo->head <<= 4;
214 geo->head |= head;
217 static int check_XRC(struct ccw1 *ccw, struct DE_eckd_data *data,
218 struct dasd_device *device)
220 struct dasd_eckd_private *private = device->private;
221 int rc;
223 if (!private->rdc_data.facilities.XRC_supported)
224 return 0;
226 /* switch on System Time Stamp - needed for XRC Support */
227 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
228 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
230 rc = get_phys_clock(&data->ep_sys_time);
231 /* Ignore return code if sync clock is switched off. */
232 if (rc == -EOPNOTSUPP || rc == -EACCES)
233 rc = 0;
235 if (ccw) {
236 ccw->count = sizeof(struct DE_eckd_data);
237 ccw->flags |= CCW_FLAG_SLI;
240 return rc;
243 static int
244 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
245 unsigned int totrk, int cmd, struct dasd_device *device,
246 int blksize)
248 struct dasd_eckd_private *private = device->private;
249 u16 heads, beghead, endhead;
250 u32 begcyl, endcyl;
251 int rc = 0;
253 if (ccw) {
254 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
255 ccw->flags = 0;
256 ccw->count = 16;
257 ccw->cda = (__u32)__pa(data);
260 memset(data, 0, sizeof(struct DE_eckd_data));
261 switch (cmd) {
262 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
263 case DASD_ECKD_CCW_READ_RECORD_ZERO:
264 case DASD_ECKD_CCW_READ:
265 case DASD_ECKD_CCW_READ_MT:
266 case DASD_ECKD_CCW_READ_CKD:
267 case DASD_ECKD_CCW_READ_CKD_MT:
268 case DASD_ECKD_CCW_READ_KD:
269 case DASD_ECKD_CCW_READ_KD_MT:
270 data->mask.perm = 0x1;
271 data->attributes.operation = private->attrib.operation;
272 break;
273 case DASD_ECKD_CCW_READ_COUNT:
274 data->mask.perm = 0x1;
275 data->attributes.operation = DASD_BYPASS_CACHE;
276 break;
277 case DASD_ECKD_CCW_READ_TRACK:
278 case DASD_ECKD_CCW_READ_TRACK_DATA:
279 data->mask.perm = 0x1;
280 data->attributes.operation = private->attrib.operation;
281 data->blk_size = 0;
282 break;
283 case DASD_ECKD_CCW_WRITE:
284 case DASD_ECKD_CCW_WRITE_MT:
285 case DASD_ECKD_CCW_WRITE_KD:
286 case DASD_ECKD_CCW_WRITE_KD_MT:
287 data->mask.perm = 0x02;
288 data->attributes.operation = private->attrib.operation;
289 rc = check_XRC(ccw, data, device);
290 break;
291 case DASD_ECKD_CCW_WRITE_CKD:
292 case DASD_ECKD_CCW_WRITE_CKD_MT:
293 data->attributes.operation = DASD_BYPASS_CACHE;
294 rc = check_XRC(ccw, data, device);
295 break;
296 case DASD_ECKD_CCW_ERASE:
297 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
298 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
299 data->mask.perm = 0x3;
300 data->mask.auth = 0x1;
301 data->attributes.operation = DASD_BYPASS_CACHE;
302 rc = check_XRC(ccw, data, device);
303 break;
304 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
305 data->mask.perm = 0x03;
306 data->attributes.operation = private->attrib.operation;
307 data->blk_size = 0;
308 break;
309 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
310 data->mask.perm = 0x02;
311 data->attributes.operation = private->attrib.operation;
312 data->blk_size = blksize;
313 rc = check_XRC(ccw, data, device);
314 break;
315 default:
316 dev_err(&device->cdev->dev,
317 "0x%x is not a known command\n", cmd);
318 break;
321 data->attributes.mode = 0x3; /* ECKD */
323 if ((private->rdc_data.cu_type == 0x2105 ||
324 private->rdc_data.cu_type == 0x2107 ||
325 private->rdc_data.cu_type == 0x1750)
326 && !(private->uses_cdl && trk < 2))
327 data->ga_extended |= 0x40; /* Regular Data Format Mode */
329 heads = private->rdc_data.trk_per_cyl;
330 begcyl = trk / heads;
331 beghead = trk % heads;
332 endcyl = totrk / heads;
333 endhead = totrk % heads;
335 /* check for sequential prestage - enhance cylinder range */
336 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
337 data->attributes.operation == DASD_SEQ_ACCESS) {
339 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
340 endcyl += private->attrib.nr_cyl;
341 else
342 endcyl = (private->real_cyl - 1);
345 set_ch_t(&data->beg_ext, begcyl, beghead);
346 set_ch_t(&data->end_ext, endcyl, endhead);
347 return rc;
351 static void locate_record_ext(struct ccw1 *ccw, struct LRE_eckd_data *data,
352 unsigned int trk, unsigned int rec_on_trk,
353 int count, int cmd, struct dasd_device *device,
354 unsigned int reclen, unsigned int tlf)
356 struct dasd_eckd_private *private = device->private;
357 int sector;
358 int dn, d;
360 if (ccw) {
361 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD_EXT;
362 ccw->flags = 0;
363 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK)
364 ccw->count = 22;
365 else
366 ccw->count = 20;
367 ccw->cda = (__u32)__pa(data);
370 memset(data, 0, sizeof(*data));
371 sector = 0;
372 if (rec_on_trk) {
373 switch (private->rdc_data.dev_type) {
374 case 0x3390:
375 dn = ceil_quot(reclen + 6, 232);
376 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
377 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
378 break;
379 case 0x3380:
380 d = 7 + ceil_quot(reclen + 12, 32);
381 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
382 break;
385 data->sector = sector;
386 /* note: meaning of count depends on the operation
387 * for record based I/O it's the number of records, but for
388 * track based I/O it's the number of tracks
390 data->count = count;
391 switch (cmd) {
392 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
393 data->operation.orientation = 0x3;
394 data->operation.operation = 0x03;
395 break;
396 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
397 data->operation.orientation = 0x3;
398 data->operation.operation = 0x16;
399 break;
400 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
401 data->operation.orientation = 0x1;
402 data->operation.operation = 0x03;
403 data->count++;
404 break;
405 case DASD_ECKD_CCW_READ_RECORD_ZERO:
406 data->operation.orientation = 0x3;
407 data->operation.operation = 0x16;
408 data->count++;
409 break;
410 case DASD_ECKD_CCW_WRITE:
411 case DASD_ECKD_CCW_WRITE_MT:
412 case DASD_ECKD_CCW_WRITE_KD:
413 case DASD_ECKD_CCW_WRITE_KD_MT:
414 data->auxiliary.length_valid = 0x1;
415 data->length = reclen;
416 data->operation.operation = 0x01;
417 break;
418 case DASD_ECKD_CCW_WRITE_CKD:
419 case DASD_ECKD_CCW_WRITE_CKD_MT:
420 data->auxiliary.length_valid = 0x1;
421 data->length = reclen;
422 data->operation.operation = 0x03;
423 break;
424 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
425 data->operation.orientation = 0x0;
426 data->operation.operation = 0x3F;
427 data->extended_operation = 0x11;
428 data->length = 0;
429 data->extended_parameter_length = 0x02;
430 if (data->count > 8) {
431 data->extended_parameter[0] = 0xFF;
432 data->extended_parameter[1] = 0xFF;
433 data->extended_parameter[1] <<= (16 - count);
434 } else {
435 data->extended_parameter[0] = 0xFF;
436 data->extended_parameter[0] <<= (8 - count);
437 data->extended_parameter[1] = 0x00;
439 data->sector = 0xFF;
440 break;
441 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
442 data->auxiliary.length_valid = 0x1;
443 data->length = reclen; /* not tlf, as one might think */
444 data->operation.operation = 0x3F;
445 data->extended_operation = 0x23;
446 break;
447 case DASD_ECKD_CCW_READ:
448 case DASD_ECKD_CCW_READ_MT:
449 case DASD_ECKD_CCW_READ_KD:
450 case DASD_ECKD_CCW_READ_KD_MT:
451 data->auxiliary.length_valid = 0x1;
452 data->length = reclen;
453 data->operation.operation = 0x06;
454 break;
455 case DASD_ECKD_CCW_READ_CKD:
456 case DASD_ECKD_CCW_READ_CKD_MT:
457 data->auxiliary.length_valid = 0x1;
458 data->length = reclen;
459 data->operation.operation = 0x16;
460 break;
461 case DASD_ECKD_CCW_READ_COUNT:
462 data->operation.operation = 0x06;
463 break;
464 case DASD_ECKD_CCW_READ_TRACK:
465 data->operation.orientation = 0x1;
466 data->operation.operation = 0x0C;
467 data->extended_parameter_length = 0;
468 data->sector = 0xFF;
469 break;
470 case DASD_ECKD_CCW_READ_TRACK_DATA:
471 data->auxiliary.length_valid = 0x1;
472 data->length = tlf;
473 data->operation.operation = 0x0C;
474 break;
475 case DASD_ECKD_CCW_ERASE:
476 data->length = reclen;
477 data->auxiliary.length_valid = 0x1;
478 data->operation.operation = 0x0b;
479 break;
480 default:
481 DBF_DEV_EVENT(DBF_ERR, device,
482 "fill LRE unknown opcode 0x%x", cmd);
483 BUG();
485 set_ch_t(&data->seek_addr,
486 trk / private->rdc_data.trk_per_cyl,
487 trk % private->rdc_data.trk_per_cyl);
488 data->search_arg.cyl = data->seek_addr.cyl;
489 data->search_arg.head = data->seek_addr.head;
490 data->search_arg.record = rec_on_trk;
493 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
494 unsigned int trk, unsigned int totrk, int cmd,
495 struct dasd_device *basedev, struct dasd_device *startdev,
496 unsigned int format, unsigned int rec_on_trk, int count,
497 unsigned int blksize, unsigned int tlf)
499 struct dasd_eckd_private *basepriv, *startpriv;
500 struct LRE_eckd_data *lredata;
501 struct DE_eckd_data *dedata;
502 int rc = 0;
504 basepriv = basedev->private;
505 startpriv = startdev->private;
506 dedata = &pfxdata->define_extent;
507 lredata = &pfxdata->locate_record;
509 ccw->cmd_code = DASD_ECKD_CCW_PFX;
510 ccw->flags = 0;
511 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
512 ccw->count = sizeof(*pfxdata) + 2;
513 ccw->cda = (__u32) __pa(pfxdata);
514 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
515 } else {
516 ccw->count = sizeof(*pfxdata);
517 ccw->cda = (__u32) __pa(pfxdata);
518 memset(pfxdata, 0, sizeof(*pfxdata));
521 /* prefix data */
522 if (format > 1) {
523 DBF_DEV_EVENT(DBF_ERR, basedev,
524 "PFX LRE unknown format 0x%x", format);
525 BUG();
526 return -EINVAL;
528 pfxdata->format = format;
529 pfxdata->base_address = basepriv->ned->unit_addr;
530 pfxdata->base_lss = basepriv->ned->ID;
531 pfxdata->validity.define_extent = 1;
533 /* private uid is kept up to date, conf_data may be outdated */
534 if (startpriv->uid.type == UA_BASE_PAV_ALIAS)
535 pfxdata->validity.verify_base = 1;
537 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) {
538 pfxdata->validity.verify_base = 1;
539 pfxdata->validity.hyper_pav = 1;
542 rc = define_extent(NULL, dedata, trk, totrk, cmd, basedev, blksize);
545 * For some commands the System Time Stamp is set in the define extent
546 * data when XRC is supported. The validity of the time stamp must be
547 * reflected in the prefix data as well.
549 if (dedata->ga_extended & 0x08 && dedata->ga_extended & 0x02)
550 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
552 if (format == 1) {
553 locate_record_ext(NULL, lredata, trk, rec_on_trk, count, cmd,
554 basedev, blksize, tlf);
557 return rc;
560 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
561 unsigned int trk, unsigned int totrk, int cmd,
562 struct dasd_device *basedev, struct dasd_device *startdev)
564 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
565 0, 0, 0, 0, 0);
568 static void
569 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
570 unsigned int rec_on_trk, int no_rec, int cmd,
571 struct dasd_device * device, int reclen)
573 struct dasd_eckd_private *private = device->private;
574 int sector;
575 int dn, d;
577 DBF_DEV_EVENT(DBF_INFO, device,
578 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
579 trk, rec_on_trk, no_rec, cmd, reclen);
581 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
582 ccw->flags = 0;
583 ccw->count = 16;
584 ccw->cda = (__u32) __pa(data);
586 memset(data, 0, sizeof(struct LO_eckd_data));
587 sector = 0;
588 if (rec_on_trk) {
589 switch (private->rdc_data.dev_type) {
590 case 0x3390:
591 dn = ceil_quot(reclen + 6, 232);
592 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
593 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
594 break;
595 case 0x3380:
596 d = 7 + ceil_quot(reclen + 12, 32);
597 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
598 break;
601 data->sector = sector;
602 data->count = no_rec;
603 switch (cmd) {
604 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
605 data->operation.orientation = 0x3;
606 data->operation.operation = 0x03;
607 break;
608 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
609 data->operation.orientation = 0x3;
610 data->operation.operation = 0x16;
611 break;
612 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
613 data->operation.orientation = 0x1;
614 data->operation.operation = 0x03;
615 data->count++;
616 break;
617 case DASD_ECKD_CCW_READ_RECORD_ZERO:
618 data->operation.orientation = 0x3;
619 data->operation.operation = 0x16;
620 data->count++;
621 break;
622 case DASD_ECKD_CCW_WRITE:
623 case DASD_ECKD_CCW_WRITE_MT:
624 case DASD_ECKD_CCW_WRITE_KD:
625 case DASD_ECKD_CCW_WRITE_KD_MT:
626 data->auxiliary.last_bytes_used = 0x1;
627 data->length = reclen;
628 data->operation.operation = 0x01;
629 break;
630 case DASD_ECKD_CCW_WRITE_CKD:
631 case DASD_ECKD_CCW_WRITE_CKD_MT:
632 data->auxiliary.last_bytes_used = 0x1;
633 data->length = reclen;
634 data->operation.operation = 0x03;
635 break;
636 case DASD_ECKD_CCW_READ:
637 case DASD_ECKD_CCW_READ_MT:
638 case DASD_ECKD_CCW_READ_KD:
639 case DASD_ECKD_CCW_READ_KD_MT:
640 data->auxiliary.last_bytes_used = 0x1;
641 data->length = reclen;
642 data->operation.operation = 0x06;
643 break;
644 case DASD_ECKD_CCW_READ_CKD:
645 case DASD_ECKD_CCW_READ_CKD_MT:
646 data->auxiliary.last_bytes_used = 0x1;
647 data->length = reclen;
648 data->operation.operation = 0x16;
649 break;
650 case DASD_ECKD_CCW_READ_COUNT:
651 data->operation.operation = 0x06;
652 break;
653 case DASD_ECKD_CCW_ERASE:
654 data->length = reclen;
655 data->auxiliary.last_bytes_used = 0x1;
656 data->operation.operation = 0x0b;
657 break;
658 default:
659 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
660 "opcode 0x%x", cmd);
662 set_ch_t(&data->seek_addr,
663 trk / private->rdc_data.trk_per_cyl,
664 trk % private->rdc_data.trk_per_cyl);
665 data->search_arg.cyl = data->seek_addr.cyl;
666 data->search_arg.head = data->seek_addr.head;
667 data->search_arg.record = rec_on_trk;
671 * Returns 1 if the block is one of the special blocks that needs
672 * to get read/written with the KD variant of the command.
673 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
674 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
675 * Luckily the KD variants differ only by one bit (0x08) from the
676 * normal variant. So don't wonder about code like:
677 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
678 * ccw->cmd_code |= 0x8;
680 static inline int
681 dasd_eckd_cdl_special(int blk_per_trk, int recid)
683 if (recid < 3)
684 return 1;
685 if (recid < blk_per_trk)
686 return 0;
687 if (recid < 2 * blk_per_trk)
688 return 1;
689 return 0;
693 * Returns the record size for the special blocks of the cdl format.
694 * Only returns something useful if dasd_eckd_cdl_special is true
695 * for the recid.
697 static inline int
698 dasd_eckd_cdl_reclen(int recid)
700 if (recid < 3)
701 return sizes_trk0[recid];
702 return LABEL_SIZE;
704 /* create unique id from private structure. */
705 static void create_uid(struct dasd_eckd_private *private)
707 int count;
708 struct dasd_uid *uid;
710 uid = &private->uid;
711 memset(uid, 0, sizeof(struct dasd_uid));
712 memcpy(uid->vendor, private->ned->HDA_manufacturer,
713 sizeof(uid->vendor) - 1);
714 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
715 memcpy(uid->serial, private->ned->HDA_location,
716 sizeof(uid->serial) - 1);
717 EBCASC(uid->serial, sizeof(uid->serial) - 1);
718 uid->ssid = private->gneq->subsystemID;
719 uid->real_unit_addr = private->ned->unit_addr;
720 if (private->sneq) {
721 uid->type = private->sneq->sua_flags;
722 if (uid->type == UA_BASE_PAV_ALIAS)
723 uid->base_unit_addr = private->sneq->base_unit_addr;
724 } else {
725 uid->type = UA_BASE_DEVICE;
727 if (private->vdsneq) {
728 for (count = 0; count < 16; count++) {
729 sprintf(uid->vduit+2*count, "%02x",
730 private->vdsneq->uit[count]);
736 * Generate device unique id that specifies the physical device.
738 static int dasd_eckd_generate_uid(struct dasd_device *device)
740 struct dasd_eckd_private *private = device->private;
741 unsigned long flags;
743 if (!private)
744 return -ENODEV;
745 if (!private->ned || !private->gneq)
746 return -ENODEV;
747 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
748 create_uid(private);
749 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
750 return 0;
753 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
755 struct dasd_eckd_private *private = device->private;
756 unsigned long flags;
758 if (private) {
759 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
760 *uid = private->uid;
761 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
762 return 0;
764 return -EINVAL;
768 * compare device UID with data of a given dasd_eckd_private structure
769 * return 0 for match
771 static int dasd_eckd_compare_path_uid(struct dasd_device *device,
772 struct dasd_eckd_private *private)
774 struct dasd_uid device_uid;
776 create_uid(private);
777 dasd_eckd_get_uid(device, &device_uid);
779 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
782 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
783 struct dasd_ccw_req *cqr,
784 __u8 *rcd_buffer,
785 __u8 lpm)
787 struct ccw1 *ccw;
789 * buffer has to start with EBCDIC "V1.0" to show
790 * support for virtual device SNEQ
792 rcd_buffer[0] = 0xE5;
793 rcd_buffer[1] = 0xF1;
794 rcd_buffer[2] = 0x4B;
795 rcd_buffer[3] = 0xF0;
797 ccw = cqr->cpaddr;
798 ccw->cmd_code = DASD_ECKD_CCW_RCD;
799 ccw->flags = 0;
800 ccw->cda = (__u32)(addr_t)rcd_buffer;
801 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
802 cqr->magic = DASD_ECKD_MAGIC;
804 cqr->startdev = device;
805 cqr->memdev = device;
806 cqr->block = NULL;
807 cqr->expires = 10*HZ;
808 cqr->lpm = lpm;
809 cqr->retries = 256;
810 cqr->buildclk = get_tod_clock();
811 cqr->status = DASD_CQR_FILLED;
812 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
816 * Wakeup helper for read_conf
817 * if the cqr is not done and needs some error recovery
818 * the buffer has to be re-initialized with the EBCDIC "V1.0"
819 * to show support for virtual device SNEQ
821 static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
823 struct ccw1 *ccw;
824 __u8 *rcd_buffer;
826 if (cqr->status != DASD_CQR_DONE) {
827 ccw = cqr->cpaddr;
828 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
829 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
831 rcd_buffer[0] = 0xE5;
832 rcd_buffer[1] = 0xF1;
833 rcd_buffer[2] = 0x4B;
834 rcd_buffer[3] = 0xF0;
836 dasd_wakeup_cb(cqr, data);
839 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
840 struct dasd_ccw_req *cqr,
841 __u8 *rcd_buffer,
842 __u8 lpm)
844 struct ciw *ciw;
845 int rc;
847 * sanity check: scan for RCD command in extended SenseID data
848 * some devices do not support RCD
850 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
851 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
852 return -EOPNOTSUPP;
854 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
855 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
856 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
857 cqr->retries = 5;
858 cqr->callback = read_conf_cb;
859 rc = dasd_sleep_on_immediatly(cqr);
860 return rc;
863 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
864 void **rcd_buffer,
865 int *rcd_buffer_size, __u8 lpm)
867 struct ciw *ciw;
868 char *rcd_buf = NULL;
869 int ret;
870 struct dasd_ccw_req *cqr;
873 * sanity check: scan for RCD command in extended SenseID data
874 * some devices do not support RCD
876 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
877 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
878 ret = -EOPNOTSUPP;
879 goto out_error;
881 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
882 if (!rcd_buf) {
883 ret = -ENOMEM;
884 goto out_error;
886 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
887 0, /* use rcd_buf as data ara */
888 device);
889 if (IS_ERR(cqr)) {
890 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
891 "Could not allocate RCD request");
892 ret = -ENOMEM;
893 goto out_error;
895 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
896 cqr->callback = read_conf_cb;
897 ret = dasd_sleep_on(cqr);
899 * on success we update the user input parms
901 dasd_sfree_request(cqr, cqr->memdev);
902 if (ret)
903 goto out_error;
905 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
906 *rcd_buffer = rcd_buf;
907 return 0;
908 out_error:
909 kfree(rcd_buf);
910 *rcd_buffer = NULL;
911 *rcd_buffer_size = 0;
912 return ret;
915 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
918 struct dasd_sneq *sneq;
919 int i, count;
921 private->ned = NULL;
922 private->sneq = NULL;
923 private->vdsneq = NULL;
924 private->gneq = NULL;
925 count = private->conf_len / sizeof(struct dasd_sneq);
926 sneq = (struct dasd_sneq *)private->conf_data;
927 for (i = 0; i < count; ++i) {
928 if (sneq->flags.identifier == 1 && sneq->format == 1)
929 private->sneq = sneq;
930 else if (sneq->flags.identifier == 1 && sneq->format == 4)
931 private->vdsneq = (struct vd_sneq *)sneq;
932 else if (sneq->flags.identifier == 2)
933 private->gneq = (struct dasd_gneq *)sneq;
934 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
935 private->ned = (struct dasd_ned *)sneq;
936 sneq++;
938 if (!private->ned || !private->gneq) {
939 private->ned = NULL;
940 private->sneq = NULL;
941 private->vdsneq = NULL;
942 private->gneq = NULL;
943 return -EINVAL;
945 return 0;
949 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
951 struct dasd_gneq *gneq;
952 int i, count, found;
954 count = conf_len / sizeof(*gneq);
955 gneq = (struct dasd_gneq *)conf_data;
956 found = 0;
957 for (i = 0; i < count; ++i) {
958 if (gneq->flags.identifier == 2) {
959 found = 1;
960 break;
962 gneq++;
964 if (found)
965 return ((char *)gneq)[18] & 0x07;
966 else
967 return 0;
970 static void dasd_eckd_clear_conf_data(struct dasd_device *device)
972 struct dasd_eckd_private *private = device->private;
973 int i;
975 private->conf_data = NULL;
976 private->conf_len = 0;
977 for (i = 0; i < 8; i++) {
978 kfree(device->path[i].conf_data);
979 device->path[i].conf_data = NULL;
980 device->path[i].cssid = 0;
981 device->path[i].ssid = 0;
982 device->path[i].chpid = 0;
987 static int dasd_eckd_read_conf(struct dasd_device *device)
989 void *conf_data;
990 int conf_len, conf_data_saved;
991 int rc, path_err, pos;
992 __u8 lpm, opm;
993 struct dasd_eckd_private *private, path_private;
994 struct dasd_uid *uid;
995 char print_path_uid[60], print_device_uid[60];
996 struct channel_path_desc *chp_desc;
997 struct subchannel_id sch_id;
999 private = device->private;
1000 opm = ccw_device_get_path_mask(device->cdev);
1001 ccw_device_get_schid(device->cdev, &sch_id);
1002 conf_data_saved = 0;
1003 path_err = 0;
1004 /* get configuration data per operational path */
1005 for (lpm = 0x80; lpm; lpm>>= 1) {
1006 if (!(lpm & opm))
1007 continue;
1008 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1009 &conf_len, lpm);
1010 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1011 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1012 "Read configuration data returned "
1013 "error %d", rc);
1014 return rc;
1016 if (conf_data == NULL) {
1017 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1018 "No configuration data "
1019 "retrieved");
1020 /* no further analysis possible */
1021 dasd_path_add_opm(device, opm);
1022 continue; /* no error */
1024 /* save first valid configuration data */
1025 if (!conf_data_saved) {
1026 /* initially clear previously stored conf_data */
1027 dasd_eckd_clear_conf_data(device);
1028 private->conf_data = conf_data;
1029 private->conf_len = conf_len;
1030 if (dasd_eckd_identify_conf_parts(private)) {
1031 private->conf_data = NULL;
1032 private->conf_len = 0;
1033 kfree(conf_data);
1034 continue;
1036 pos = pathmask_to_pos(lpm);
1037 /* store per path conf_data */
1038 device->path[pos].conf_data = conf_data;
1039 device->path[pos].cssid = sch_id.cssid;
1040 device->path[pos].ssid = sch_id.ssid;
1041 chp_desc = ccw_device_get_chp_desc(device->cdev, pos);
1042 if (chp_desc)
1043 device->path[pos].chpid = chp_desc->chpid;
1044 kfree(chp_desc);
1046 * build device UID that other path data
1047 * can be compared to it
1049 dasd_eckd_generate_uid(device);
1050 conf_data_saved++;
1051 } else {
1052 path_private.conf_data = conf_data;
1053 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1054 if (dasd_eckd_identify_conf_parts(
1055 &path_private)) {
1056 path_private.conf_data = NULL;
1057 path_private.conf_len = 0;
1058 kfree(conf_data);
1059 continue;
1061 if (dasd_eckd_compare_path_uid(
1062 device, &path_private)) {
1063 uid = &path_private.uid;
1064 if (strlen(uid->vduit) > 0)
1065 snprintf(print_path_uid,
1066 sizeof(print_path_uid),
1067 "%s.%s.%04x.%02x.%s",
1068 uid->vendor, uid->serial,
1069 uid->ssid, uid->real_unit_addr,
1070 uid->vduit);
1071 else
1072 snprintf(print_path_uid,
1073 sizeof(print_path_uid),
1074 "%s.%s.%04x.%02x",
1075 uid->vendor, uid->serial,
1076 uid->ssid,
1077 uid->real_unit_addr);
1078 uid = &private->uid;
1079 if (strlen(uid->vduit) > 0)
1080 snprintf(print_device_uid,
1081 sizeof(print_device_uid),
1082 "%s.%s.%04x.%02x.%s",
1083 uid->vendor, uid->serial,
1084 uid->ssid, uid->real_unit_addr,
1085 uid->vduit);
1086 else
1087 snprintf(print_device_uid,
1088 sizeof(print_device_uid),
1089 "%s.%s.%04x.%02x",
1090 uid->vendor, uid->serial,
1091 uid->ssid,
1092 uid->real_unit_addr);
1093 dev_err(&device->cdev->dev,
1094 "Not all channel paths lead to "
1095 "the same device, path %02X leads to "
1096 "device %s instead of %s\n", lpm,
1097 print_path_uid, print_device_uid);
1098 path_err = -EINVAL;
1099 dasd_path_add_cablepm(device, lpm);
1100 continue;
1102 pos = pathmask_to_pos(lpm);
1103 /* store per path conf_data */
1104 device->path[pos].conf_data = conf_data;
1105 device->path[pos].cssid = sch_id.cssid;
1106 device->path[pos].ssid = sch_id.ssid;
1107 chp_desc = ccw_device_get_chp_desc(device->cdev, pos);
1108 if (chp_desc)
1109 device->path[pos].chpid = chp_desc->chpid;
1110 kfree(chp_desc);
1111 path_private.conf_data = NULL;
1112 path_private.conf_len = 0;
1114 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1115 case 0x02:
1116 dasd_path_add_nppm(device, lpm);
1117 break;
1118 case 0x03:
1119 dasd_path_add_ppm(device, lpm);
1120 break;
1122 if (!dasd_path_get_opm(device)) {
1123 dasd_path_set_opm(device, lpm);
1124 dasd_generic_path_operational(device);
1125 } else {
1126 dasd_path_add_opm(device, lpm);
1130 return path_err;
1133 static u32 get_fcx_max_data(struct dasd_device *device)
1135 struct dasd_eckd_private *private = device->private;
1136 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1137 int tpm, mdc;
1139 if (dasd_nofcx)
1140 return 0;
1141 /* is transport mode supported? */
1142 fcx_in_css = css_general_characteristics.fcx;
1143 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1144 fcx_in_features = private->features.feature[40] & 0x80;
1145 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1147 if (!tpm)
1148 return 0;
1150 mdc = ccw_device_get_mdc(device->cdev, 0);
1151 if (mdc < 0) {
1152 dev_warn(&device->cdev->dev, "Detecting the maximum supported data size for zHPF requests failed\n");
1153 return 0;
1154 } else {
1155 return (u32)mdc * FCX_MAX_DATA_FACTOR;
1159 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1161 struct dasd_eckd_private *private = device->private;
1162 int mdc;
1163 u32 fcx_max_data;
1165 if (private->fcx_max_data) {
1166 mdc = ccw_device_get_mdc(device->cdev, lpm);
1167 if ((mdc < 0)) {
1168 dev_warn(&device->cdev->dev,
1169 "Detecting the maximum data size for zHPF "
1170 "requests failed (rc=%d) for a new path %x\n",
1171 mdc, lpm);
1172 return mdc;
1174 fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR;
1175 if (fcx_max_data < private->fcx_max_data) {
1176 dev_warn(&device->cdev->dev,
1177 "The maximum data size for zHPF requests %u "
1178 "on a new path %x is below the active maximum "
1179 "%u\n", fcx_max_data, lpm,
1180 private->fcx_max_data);
1181 return -EACCES;
1184 return 0;
1187 static int rebuild_device_uid(struct dasd_device *device,
1188 struct path_verification_work_data *data)
1190 struct dasd_eckd_private *private = device->private;
1191 __u8 lpm, opm = dasd_path_get_opm(device);
1192 int rc = -ENODEV;
1194 for (lpm = 0x80; lpm; lpm >>= 1) {
1195 if (!(lpm & opm))
1196 continue;
1197 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1198 memset(&data->cqr, 0, sizeof(data->cqr));
1199 data->cqr.cpaddr = &data->ccw;
1200 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1201 data->rcd_buffer,
1202 lpm);
1204 if (rc) {
1205 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1206 continue;
1207 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1208 "Read configuration data "
1209 "returned error %d", rc);
1210 break;
1212 memcpy(private->conf_data, data->rcd_buffer,
1213 DASD_ECKD_RCD_DATA_SIZE);
1214 if (dasd_eckd_identify_conf_parts(private)) {
1215 rc = -ENODEV;
1216 } else /* first valid path is enough */
1217 break;
1220 if (!rc)
1221 rc = dasd_eckd_generate_uid(device);
1223 return rc;
1226 static void do_path_verification_work(struct work_struct *work)
1228 struct path_verification_work_data *data;
1229 struct dasd_device *device;
1230 struct dasd_eckd_private path_private;
1231 struct dasd_uid *uid;
1232 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
1233 __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
1234 unsigned long flags;
1235 char print_uid[60];
1236 int rc;
1238 data = container_of(work, struct path_verification_work_data, worker);
1239 device = data->device;
1241 /* delay path verification until device was resumed */
1242 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1243 schedule_work(work);
1244 return;
1246 /* check if path verification already running and delay if so */
1247 if (test_and_set_bit(DASD_FLAG_PATH_VERIFY, &device->flags)) {
1248 schedule_work(work);
1249 return;
1251 opm = 0;
1252 npm = 0;
1253 ppm = 0;
1254 epm = 0;
1255 hpfpm = 0;
1256 cablepm = 0;
1258 for (lpm = 0x80; lpm; lpm >>= 1) {
1259 if (!(lpm & data->tbvpm))
1260 continue;
1261 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1262 memset(&data->cqr, 0, sizeof(data->cqr));
1263 data->cqr.cpaddr = &data->ccw;
1264 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1265 data->rcd_buffer,
1266 lpm);
1267 if (!rc) {
1268 switch (dasd_eckd_path_access(data->rcd_buffer,
1269 DASD_ECKD_RCD_DATA_SIZE)
1271 case 0x02:
1272 npm |= lpm;
1273 break;
1274 case 0x03:
1275 ppm |= lpm;
1276 break;
1278 opm |= lpm;
1279 } else if (rc == -EOPNOTSUPP) {
1280 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1281 "path verification: No configuration "
1282 "data retrieved");
1283 opm |= lpm;
1284 } else if (rc == -EAGAIN) {
1285 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1286 "path verification: device is stopped,"
1287 " try again later");
1288 epm |= lpm;
1289 } else {
1290 dev_warn(&device->cdev->dev,
1291 "Reading device feature codes failed "
1292 "(rc=%d) for new path %x\n", rc, lpm);
1293 continue;
1295 if (verify_fcx_max_data(device, lpm)) {
1296 opm &= ~lpm;
1297 npm &= ~lpm;
1298 ppm &= ~lpm;
1299 hpfpm |= lpm;
1300 continue;
1304 * save conf_data for comparison after
1305 * rebuild_device_uid may have changed
1306 * the original data
1308 memcpy(&path_rcd_buf, data->rcd_buffer,
1309 DASD_ECKD_RCD_DATA_SIZE);
1310 path_private.conf_data = (void *) &path_rcd_buf;
1311 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1312 if (dasd_eckd_identify_conf_parts(&path_private)) {
1313 path_private.conf_data = NULL;
1314 path_private.conf_len = 0;
1315 continue;
1319 * compare path UID with device UID only if at least
1320 * one valid path is left
1321 * in other case the device UID may have changed and
1322 * the first working path UID will be used as device UID
1324 if (dasd_path_get_opm(device) &&
1325 dasd_eckd_compare_path_uid(device, &path_private)) {
1327 * the comparison was not successful
1328 * rebuild the device UID with at least one
1329 * known path in case a z/VM hyperswap command
1330 * has changed the device
1332 * after this compare again
1334 * if either the rebuild or the recompare fails
1335 * the path can not be used
1337 if (rebuild_device_uid(device, data) ||
1338 dasd_eckd_compare_path_uid(
1339 device, &path_private)) {
1340 uid = &path_private.uid;
1341 if (strlen(uid->vduit) > 0)
1342 snprintf(print_uid, sizeof(print_uid),
1343 "%s.%s.%04x.%02x.%s",
1344 uid->vendor, uid->serial,
1345 uid->ssid, uid->real_unit_addr,
1346 uid->vduit);
1347 else
1348 snprintf(print_uid, sizeof(print_uid),
1349 "%s.%s.%04x.%02x",
1350 uid->vendor, uid->serial,
1351 uid->ssid,
1352 uid->real_unit_addr);
1353 dev_err(&device->cdev->dev,
1354 "The newly added channel path %02X "
1355 "will not be used because it leads "
1356 "to a different device %s\n",
1357 lpm, print_uid);
1358 opm &= ~lpm;
1359 npm &= ~lpm;
1360 ppm &= ~lpm;
1361 cablepm |= lpm;
1362 continue;
1367 * There is a small chance that a path is lost again between
1368 * above path verification and the following modification of
1369 * the device opm mask. We could avoid that race here by using
1370 * yet another path mask, but we rather deal with this unlikely
1371 * situation in dasd_start_IO.
1373 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1374 if (!dasd_path_get_opm(device) && opm) {
1375 dasd_path_set_opm(device, opm);
1376 dasd_generic_path_operational(device);
1377 } else {
1378 dasd_path_add_opm(device, opm);
1380 dasd_path_add_nppm(device, npm);
1381 dasd_path_add_ppm(device, ppm);
1382 dasd_path_add_tbvpm(device, epm);
1383 dasd_path_add_cablepm(device, cablepm);
1384 dasd_path_add_nohpfpm(device, hpfpm);
1385 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1387 clear_bit(DASD_FLAG_PATH_VERIFY, &device->flags);
1388 dasd_put_device(device);
1389 if (data->isglobal)
1390 mutex_unlock(&dasd_path_verification_mutex);
1391 else
1392 kfree(data);
1395 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1397 struct path_verification_work_data *data;
1399 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1400 if (!data) {
1401 if (mutex_trylock(&dasd_path_verification_mutex)) {
1402 data = path_verification_worker;
1403 data->isglobal = 1;
1404 } else
1405 return -ENOMEM;
1406 } else {
1407 memset(data, 0, sizeof(*data));
1408 data->isglobal = 0;
1410 INIT_WORK(&data->worker, do_path_verification_work);
1411 dasd_get_device(device);
1412 data->device = device;
1413 data->tbvpm = lpm;
1414 schedule_work(&data->worker);
1415 return 0;
1418 static void dasd_eckd_reset_path(struct dasd_device *device, __u8 pm)
1420 struct dasd_eckd_private *private = device->private;
1421 unsigned long flags;
1423 if (!private->fcx_max_data)
1424 private->fcx_max_data = get_fcx_max_data(device);
1425 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1426 dasd_path_set_tbvpm(device, pm ? : dasd_path_get_notoperpm(device));
1427 dasd_schedule_device_bh(device);
1428 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1431 static int dasd_eckd_read_features(struct dasd_device *device)
1433 struct dasd_eckd_private *private = device->private;
1434 struct dasd_psf_prssd_data *prssdp;
1435 struct dasd_rssd_features *features;
1436 struct dasd_ccw_req *cqr;
1437 struct ccw1 *ccw;
1438 int rc;
1440 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1441 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1442 (sizeof(struct dasd_psf_prssd_data) +
1443 sizeof(struct dasd_rssd_features)),
1444 device);
1445 if (IS_ERR(cqr)) {
1446 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1447 "allocate initialization request");
1448 return PTR_ERR(cqr);
1450 cqr->startdev = device;
1451 cqr->memdev = device;
1452 cqr->block = NULL;
1453 cqr->retries = 256;
1454 cqr->expires = 10 * HZ;
1456 /* Prepare for Read Subsystem Data */
1457 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1458 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1459 prssdp->order = PSF_ORDER_PRSSD;
1460 prssdp->suborder = 0x41; /* Read Feature Codes */
1461 /* all other bytes of prssdp must be zero */
1463 ccw = cqr->cpaddr;
1464 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1465 ccw->count = sizeof(struct dasd_psf_prssd_data);
1466 ccw->flags |= CCW_FLAG_CC;
1467 ccw->cda = (__u32)(addr_t) prssdp;
1469 /* Read Subsystem Data - feature codes */
1470 features = (struct dasd_rssd_features *) (prssdp + 1);
1471 memset(features, 0, sizeof(struct dasd_rssd_features));
1473 ccw++;
1474 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1475 ccw->count = sizeof(struct dasd_rssd_features);
1476 ccw->cda = (__u32)(addr_t) features;
1478 cqr->buildclk = get_tod_clock();
1479 cqr->status = DASD_CQR_FILLED;
1480 rc = dasd_sleep_on(cqr);
1481 if (rc == 0) {
1482 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1483 features = (struct dasd_rssd_features *) (prssdp + 1);
1484 memcpy(&private->features, features,
1485 sizeof(struct dasd_rssd_features));
1486 } else
1487 dev_warn(&device->cdev->dev, "Reading device feature codes"
1488 " failed with rc=%d\n", rc);
1489 dasd_sfree_request(cqr, cqr->memdev);
1490 return rc;
1495 * Build CP for Perform Subsystem Function - SSC.
1497 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1498 int enable_pav)
1500 struct dasd_ccw_req *cqr;
1501 struct dasd_psf_ssc_data *psf_ssc_data;
1502 struct ccw1 *ccw;
1504 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1505 sizeof(struct dasd_psf_ssc_data),
1506 device);
1508 if (IS_ERR(cqr)) {
1509 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1510 "Could not allocate PSF-SSC request");
1511 return cqr;
1513 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1514 psf_ssc_data->order = PSF_ORDER_SSC;
1515 psf_ssc_data->suborder = 0xc0;
1516 if (enable_pav) {
1517 psf_ssc_data->suborder |= 0x08;
1518 psf_ssc_data->reserved[0] = 0x88;
1520 ccw = cqr->cpaddr;
1521 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1522 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1523 ccw->count = 66;
1525 cqr->startdev = device;
1526 cqr->memdev = device;
1527 cqr->block = NULL;
1528 cqr->retries = 256;
1529 cqr->expires = 10*HZ;
1530 cqr->buildclk = get_tod_clock();
1531 cqr->status = DASD_CQR_FILLED;
1532 return cqr;
1536 * Perform Subsystem Function.
1537 * It is necessary to trigger CIO for channel revalidation since this
1538 * call might change behaviour of DASD devices.
1540 static int
1541 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1542 unsigned long flags)
1544 struct dasd_ccw_req *cqr;
1545 int rc;
1547 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1548 if (IS_ERR(cqr))
1549 return PTR_ERR(cqr);
1552 * set flags e.g. turn on failfast, to prevent blocking
1553 * the calling function should handle failed requests
1555 cqr->flags |= flags;
1557 rc = dasd_sleep_on(cqr);
1558 if (!rc)
1559 /* trigger CIO to reprobe devices */
1560 css_schedule_reprobe();
1561 else if (cqr->intrc == -EAGAIN)
1562 rc = -EAGAIN;
1564 dasd_sfree_request(cqr, cqr->memdev);
1565 return rc;
1569 * Valide storage server of current device.
1571 static int dasd_eckd_validate_server(struct dasd_device *device,
1572 unsigned long flags)
1574 struct dasd_eckd_private *private = device->private;
1575 int enable_pav, rc;
1577 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1578 private->uid.type == UA_HYPER_PAV_ALIAS)
1579 return 0;
1580 if (dasd_nopav || MACHINE_IS_VM)
1581 enable_pav = 0;
1582 else
1583 enable_pav = 1;
1584 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
1586 /* may be requested feature is not available on server,
1587 * therefore just report error and go ahead */
1588 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1589 "returned rc=%d", private->uid.ssid, rc);
1590 return rc;
1594 * worker to do a validate server in case of a lost pathgroup
1596 static void dasd_eckd_do_validate_server(struct work_struct *work)
1598 struct dasd_device *device = container_of(work, struct dasd_device,
1599 kick_validate);
1600 unsigned long flags = 0;
1602 set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1603 if (dasd_eckd_validate_server(device, flags)
1604 == -EAGAIN) {
1605 /* schedule worker again if failed */
1606 schedule_work(&device->kick_validate);
1607 return;
1610 dasd_put_device(device);
1613 static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1615 dasd_get_device(device);
1616 /* exit if device not online or in offline processing */
1617 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1618 device->state < DASD_STATE_ONLINE) {
1619 dasd_put_device(device);
1620 return;
1622 /* queue call to do_validate_server to the kernel event daemon. */
1623 if (!schedule_work(&device->kick_validate))
1624 dasd_put_device(device);
1628 * Check device characteristics.
1629 * If the device is accessible using ECKD discipline, the device is enabled.
1631 static int
1632 dasd_eckd_check_characteristics(struct dasd_device *device)
1634 struct dasd_eckd_private *private = device->private;
1635 struct dasd_block *block;
1636 struct dasd_uid temp_uid;
1637 int rc, i;
1638 int readonly;
1639 unsigned long value;
1641 /* setup work queue for validate server*/
1642 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1643 /* setup work queue for summary unit check */
1644 INIT_WORK(&device->suc_work, dasd_alias_handle_summary_unit_check);
1646 if (!ccw_device_is_pathgroup(device->cdev)) {
1647 dev_warn(&device->cdev->dev,
1648 "A channel path group could not be established\n");
1649 return -EIO;
1651 if (!ccw_device_is_multipath(device->cdev)) {
1652 dev_info(&device->cdev->dev,
1653 "The DASD is not operating in multipath mode\n");
1655 if (!private) {
1656 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1657 if (!private) {
1658 dev_warn(&device->cdev->dev,
1659 "Allocating memory for private DASD data "
1660 "failed\n");
1661 return -ENOMEM;
1663 device->private = private;
1664 } else {
1665 memset(private, 0, sizeof(*private));
1667 /* Invalidate status of initial analysis. */
1668 private->init_cqr_status = -1;
1669 /* Set default cache operations. */
1670 private->attrib.operation = DASD_NORMAL_CACHE;
1671 private->attrib.nr_cyl = 0;
1673 /* Read Configuration Data */
1674 rc = dasd_eckd_read_conf(device);
1675 if (rc)
1676 goto out_err1;
1678 /* set some default values */
1679 device->default_expires = DASD_EXPIRES;
1680 device->default_retries = DASD_RETRIES;
1681 device->path_thrhld = DASD_ECKD_PATH_THRHLD;
1682 device->path_interval = DASD_ECKD_PATH_INTERVAL;
1684 if (private->gneq) {
1685 value = 1;
1686 for (i = 0; i < private->gneq->timeout.value; i++)
1687 value = 10 * value;
1688 value = value * private->gneq->timeout.number;
1689 /* do not accept useless values */
1690 if (value != 0 && value <= DASD_EXPIRES_MAX)
1691 device->default_expires = value;
1694 dasd_eckd_get_uid(device, &temp_uid);
1695 if (temp_uid.type == UA_BASE_DEVICE) {
1696 block = dasd_alloc_block();
1697 if (IS_ERR(block)) {
1698 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1699 "could not allocate dasd "
1700 "block structure");
1701 rc = PTR_ERR(block);
1702 goto out_err1;
1704 device->block = block;
1705 block->base = device;
1708 /* register lcu with alias handling, enable PAV */
1709 rc = dasd_alias_make_device_known_to_lcu(device);
1710 if (rc)
1711 goto out_err2;
1713 dasd_eckd_validate_server(device, 0);
1715 /* device may report different configuration data after LCU setup */
1716 rc = dasd_eckd_read_conf(device);
1717 if (rc)
1718 goto out_err3;
1720 /* Read Feature Codes */
1721 dasd_eckd_read_features(device);
1723 /* Read Device Characteristics */
1724 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1725 &private->rdc_data, 64);
1726 if (rc) {
1727 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1728 "Read device characteristic failed, rc=%d", rc);
1729 goto out_err3;
1732 if ((device->features & DASD_FEATURE_USERAW) &&
1733 !(private->rdc_data.facilities.RT_in_LR)) {
1734 dev_err(&device->cdev->dev, "The storage server does not "
1735 "support raw-track access\n");
1736 rc = -EINVAL;
1737 goto out_err3;
1740 /* find the valid cylinder size */
1741 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1742 private->rdc_data.long_no_cyl)
1743 private->real_cyl = private->rdc_data.long_no_cyl;
1744 else
1745 private->real_cyl = private->rdc_data.no_cyl;
1747 private->fcx_max_data = get_fcx_max_data(device);
1749 readonly = dasd_device_is_ro(device);
1750 if (readonly)
1751 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1753 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1754 "with %d cylinders, %d heads, %d sectors%s\n",
1755 private->rdc_data.dev_type,
1756 private->rdc_data.dev_model,
1757 private->rdc_data.cu_type,
1758 private->rdc_data.cu_model.model,
1759 private->real_cyl,
1760 private->rdc_data.trk_per_cyl,
1761 private->rdc_data.sec_per_trk,
1762 readonly ? ", read-only device" : "");
1763 return 0;
1765 out_err3:
1766 dasd_alias_disconnect_device_from_lcu(device);
1767 out_err2:
1768 dasd_free_block(device->block);
1769 device->block = NULL;
1770 out_err1:
1771 kfree(private->conf_data);
1772 kfree(device->private);
1773 device->private = NULL;
1774 return rc;
1777 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1779 struct dasd_eckd_private *private = device->private;
1780 int i;
1782 dasd_alias_disconnect_device_from_lcu(device);
1783 private->ned = NULL;
1784 private->sneq = NULL;
1785 private->vdsneq = NULL;
1786 private->gneq = NULL;
1787 private->conf_len = 0;
1788 for (i = 0; i < 8; i++) {
1789 kfree(device->path[i].conf_data);
1790 if ((__u8 *)device->path[i].conf_data ==
1791 private->conf_data) {
1792 private->conf_data = NULL;
1793 private->conf_len = 0;
1795 device->path[i].conf_data = NULL;
1796 device->path[i].cssid = 0;
1797 device->path[i].ssid = 0;
1798 device->path[i].chpid = 0;
1800 kfree(private->conf_data);
1801 private->conf_data = NULL;
1804 static struct dasd_ccw_req *
1805 dasd_eckd_analysis_ccw(struct dasd_device *device)
1807 struct dasd_eckd_private *private = device->private;
1808 struct eckd_count *count_data;
1809 struct LO_eckd_data *LO_data;
1810 struct dasd_ccw_req *cqr;
1811 struct ccw1 *ccw;
1812 int cplength, datasize;
1813 int i;
1815 cplength = 8;
1816 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1817 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1818 if (IS_ERR(cqr))
1819 return cqr;
1820 ccw = cqr->cpaddr;
1821 /* Define extent for the first 3 tracks. */
1822 define_extent(ccw++, cqr->data, 0, 2,
1823 DASD_ECKD_CCW_READ_COUNT, device, 0);
1824 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1825 /* Locate record for the first 4 records on track 0. */
1826 ccw[-1].flags |= CCW_FLAG_CC;
1827 locate_record(ccw++, LO_data++, 0, 0, 4,
1828 DASD_ECKD_CCW_READ_COUNT, device, 0);
1830 count_data = private->count_area;
1831 for (i = 0; i < 4; i++) {
1832 ccw[-1].flags |= CCW_FLAG_CC;
1833 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1834 ccw->flags = 0;
1835 ccw->count = 8;
1836 ccw->cda = (__u32)(addr_t) count_data;
1837 ccw++;
1838 count_data++;
1841 /* Locate record for the first record on track 2. */
1842 ccw[-1].flags |= CCW_FLAG_CC;
1843 locate_record(ccw++, LO_data++, 2, 0, 1,
1844 DASD_ECKD_CCW_READ_COUNT, device, 0);
1845 /* Read count ccw. */
1846 ccw[-1].flags |= CCW_FLAG_CC;
1847 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1848 ccw->flags = 0;
1849 ccw->count = 8;
1850 ccw->cda = (__u32)(addr_t) count_data;
1852 cqr->block = NULL;
1853 cqr->startdev = device;
1854 cqr->memdev = device;
1855 cqr->retries = 255;
1856 cqr->buildclk = get_tod_clock();
1857 cqr->status = DASD_CQR_FILLED;
1858 return cqr;
1861 /* differentiate between 'no record found' and any other error */
1862 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1864 char *sense;
1865 if (init_cqr->status == DASD_CQR_DONE)
1866 return INIT_CQR_OK;
1867 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1868 init_cqr->status == DASD_CQR_FAILED) {
1869 sense = dasd_get_sense(&init_cqr->irb);
1870 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1871 return INIT_CQR_UNFORMATTED;
1872 else
1873 return INIT_CQR_ERROR;
1874 } else
1875 return INIT_CQR_ERROR;
1879 * This is the callback function for the init_analysis cqr. It saves
1880 * the status of the initial analysis ccw before it frees it and kicks
1881 * the device to continue the startup sequence. This will call
1882 * dasd_eckd_do_analysis again (if the devices has not been marked
1883 * for deletion in the meantime).
1885 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1886 void *data)
1888 struct dasd_device *device = init_cqr->startdev;
1889 struct dasd_eckd_private *private = device->private;
1891 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1892 dasd_sfree_request(init_cqr, device);
1893 dasd_kick_device(device);
1896 static int dasd_eckd_start_analysis(struct dasd_block *block)
1898 struct dasd_ccw_req *init_cqr;
1900 init_cqr = dasd_eckd_analysis_ccw(block->base);
1901 if (IS_ERR(init_cqr))
1902 return PTR_ERR(init_cqr);
1903 init_cqr->callback = dasd_eckd_analysis_callback;
1904 init_cqr->callback_data = NULL;
1905 init_cqr->expires = 5*HZ;
1906 /* first try without ERP, so we can later handle unformatted
1907 * devices as special case
1909 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1910 init_cqr->retries = 0;
1911 dasd_add_request_head(init_cqr);
1912 return -EAGAIN;
1915 static int dasd_eckd_end_analysis(struct dasd_block *block)
1917 struct dasd_device *device = block->base;
1918 struct dasd_eckd_private *private = device->private;
1919 struct eckd_count *count_area;
1920 unsigned int sb, blk_per_trk;
1921 int status, i;
1922 struct dasd_ccw_req *init_cqr;
1924 status = private->init_cqr_status;
1925 private->init_cqr_status = -1;
1926 if (status == INIT_CQR_ERROR) {
1927 /* try again, this time with full ERP */
1928 init_cqr = dasd_eckd_analysis_ccw(device);
1929 dasd_sleep_on(init_cqr);
1930 status = dasd_eckd_analysis_evaluation(init_cqr);
1931 dasd_sfree_request(init_cqr, device);
1934 if (device->features & DASD_FEATURE_USERAW) {
1935 block->bp_block = DASD_RAW_BLOCKSIZE;
1936 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1937 block->s2b_shift = 3;
1938 goto raw;
1941 if (status == INIT_CQR_UNFORMATTED) {
1942 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1943 return -EMEDIUMTYPE;
1944 } else if (status == INIT_CQR_ERROR) {
1945 dev_err(&device->cdev->dev,
1946 "Detecting the DASD disk layout failed because "
1947 "of an I/O error\n");
1948 return -EIO;
1951 private->uses_cdl = 1;
1952 /* Check Track 0 for Compatible Disk Layout */
1953 count_area = NULL;
1954 for (i = 0; i < 3; i++) {
1955 if (private->count_area[i].kl != 4 ||
1956 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
1957 private->count_area[i].cyl != 0 ||
1958 private->count_area[i].head != count_area_head[i] ||
1959 private->count_area[i].record != count_area_rec[i]) {
1960 private->uses_cdl = 0;
1961 break;
1964 if (i == 3)
1965 count_area = &private->count_area[4];
1967 if (private->uses_cdl == 0) {
1968 for (i = 0; i < 5; i++) {
1969 if ((private->count_area[i].kl != 0) ||
1970 (private->count_area[i].dl !=
1971 private->count_area[0].dl) ||
1972 private->count_area[i].cyl != 0 ||
1973 private->count_area[i].head != count_area_head[i] ||
1974 private->count_area[i].record != count_area_rec[i])
1975 break;
1977 if (i == 5)
1978 count_area = &private->count_area[0];
1979 } else {
1980 if (private->count_area[3].record == 1)
1981 dev_warn(&device->cdev->dev,
1982 "Track 0 has no records following the VTOC\n");
1985 if (count_area != NULL && count_area->kl == 0) {
1986 /* we found notthing violating our disk layout */
1987 if (dasd_check_blocksize(count_area->dl) == 0)
1988 block->bp_block = count_area->dl;
1990 if (block->bp_block == 0) {
1991 dev_warn(&device->cdev->dev,
1992 "The disk layout of the DASD is not supported\n");
1993 return -EMEDIUMTYPE;
1995 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1996 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1997 block->s2b_shift++;
1999 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
2001 raw:
2002 block->blocks = (private->real_cyl *
2003 private->rdc_data.trk_per_cyl *
2004 blk_per_trk);
2006 dev_info(&device->cdev->dev,
2007 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2008 "%s\n", (block->bp_block >> 10),
2009 ((private->real_cyl *
2010 private->rdc_data.trk_per_cyl *
2011 blk_per_trk * (block->bp_block >> 9)) >> 1),
2012 ((blk_per_trk * block->bp_block) >> 10),
2013 private->uses_cdl ?
2014 "compatible disk layout" : "linux disk layout");
2016 return 0;
2019 static int dasd_eckd_do_analysis(struct dasd_block *block)
2021 struct dasd_eckd_private *private = block->base->private;
2023 if (private->init_cqr_status < 0)
2024 return dasd_eckd_start_analysis(block);
2025 else
2026 return dasd_eckd_end_analysis(block);
2029 static int dasd_eckd_basic_to_ready(struct dasd_device *device)
2031 return dasd_alias_add_device(device);
2034 static int dasd_eckd_online_to_ready(struct dasd_device *device)
2036 cancel_work_sync(&device->reload_device);
2037 cancel_work_sync(&device->kick_validate);
2038 return 0;
2041 static int dasd_eckd_basic_to_known(struct dasd_device *device)
2043 return dasd_alias_remove_device(device);
2046 static int
2047 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
2049 struct dasd_eckd_private *private = block->base->private;
2051 if (dasd_check_blocksize(block->bp_block) == 0) {
2052 geo->sectors = recs_per_track(&private->rdc_data,
2053 0, block->bp_block);
2055 geo->cylinders = private->rdc_data.no_cyl;
2056 geo->heads = private->rdc_data.trk_per_cyl;
2057 return 0;
2061 * Build the TCW request for the format check
2063 static struct dasd_ccw_req *
2064 dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata,
2065 int enable_pav, struct eckd_count *fmt_buffer,
2066 int rpt)
2068 struct dasd_eckd_private *start_priv;
2069 struct dasd_device *startdev = NULL;
2070 struct tidaw *last_tidaw = NULL;
2071 struct dasd_ccw_req *cqr;
2072 struct itcw *itcw;
2073 int itcw_size;
2074 int count;
2075 int rc;
2076 int i;
2078 if (enable_pav)
2079 startdev = dasd_alias_get_start_dev(base);
2081 if (!startdev)
2082 startdev = base;
2084 start_priv = startdev->private;
2086 count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2089 * we're adding 'count' amount of tidaw to the itcw.
2090 * calculate the corresponding itcw_size
2092 itcw_size = itcw_calc_size(0, count, 0);
2094 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2095 if (IS_ERR(cqr))
2096 return cqr;
2098 start_priv->count++;
2100 itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0);
2101 if (IS_ERR(itcw)) {
2102 rc = -EINVAL;
2103 goto out_err;
2106 cqr->cpaddr = itcw_get_tcw(itcw);
2107 rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit,
2108 DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count,
2109 sizeof(struct eckd_count),
2110 count * sizeof(struct eckd_count), 0, rpt);
2111 if (rc)
2112 goto out_err;
2114 for (i = 0; i < count; i++) {
2115 last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++,
2116 sizeof(struct eckd_count));
2117 if (IS_ERR(last_tidaw)) {
2118 rc = -EINVAL;
2119 goto out_err;
2123 last_tidaw->flags |= TIDAW_FLAGS_LAST;
2124 itcw_finalize(itcw);
2126 cqr->cpmode = 1;
2127 cqr->startdev = startdev;
2128 cqr->memdev = startdev;
2129 cqr->basedev = base;
2130 cqr->retries = startdev->default_retries;
2131 cqr->expires = startdev->default_expires * HZ;
2132 cqr->buildclk = get_tod_clock();
2133 cqr->status = DASD_CQR_FILLED;
2134 /* Set flags to suppress output for expected errors */
2135 set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
2136 set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags);
2138 return cqr;
2140 out_err:
2141 dasd_sfree_request(cqr, startdev);
2143 return ERR_PTR(rc);
2147 * Build the CCW request for the format check
2149 static struct dasd_ccw_req *
2150 dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata,
2151 int enable_pav, struct eckd_count *fmt_buffer, int rpt)
2153 struct dasd_eckd_private *start_priv;
2154 struct dasd_eckd_private *base_priv;
2155 struct dasd_device *startdev = NULL;
2156 struct dasd_ccw_req *cqr;
2157 struct ccw1 *ccw;
2158 void *data;
2159 int cplength, datasize;
2160 int use_prefix;
2161 int count;
2162 int i;
2164 if (enable_pav)
2165 startdev = dasd_alias_get_start_dev(base);
2167 if (!startdev)
2168 startdev = base;
2170 start_priv = startdev->private;
2171 base_priv = base->private;
2173 count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2175 use_prefix = base_priv->features.feature[8] & 0x01;
2177 if (use_prefix) {
2178 cplength = 1;
2179 datasize = sizeof(struct PFX_eckd_data);
2180 } else {
2181 cplength = 2;
2182 datasize = sizeof(struct DE_eckd_data) +
2183 sizeof(struct LO_eckd_data);
2185 cplength += count;
2187 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2188 startdev);
2189 if (IS_ERR(cqr))
2190 return cqr;
2192 start_priv->count++;
2193 data = cqr->data;
2194 ccw = cqr->cpaddr;
2196 if (use_prefix) {
2197 prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit,
2198 DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0,
2199 count, 0, 0);
2200 } else {
2201 define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit,
2202 DASD_ECKD_CCW_READ_COUNT, startdev, 0);
2204 data += sizeof(struct DE_eckd_data);
2205 ccw[-1].flags |= CCW_FLAG_CC;
2207 locate_record(ccw++, data, fdata->start_unit, 0, count,
2208 DASD_ECKD_CCW_READ_COUNT, base, 0);
2211 for (i = 0; i < count; i++) {
2212 ccw[-1].flags |= CCW_FLAG_CC;
2213 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
2214 ccw->flags = CCW_FLAG_SLI;
2215 ccw->count = 8;
2216 ccw->cda = (__u32)(addr_t) fmt_buffer;
2217 ccw++;
2218 fmt_buffer++;
2221 cqr->startdev = startdev;
2222 cqr->memdev = startdev;
2223 cqr->basedev = base;
2224 cqr->retries = DASD_RETRIES;
2225 cqr->expires = startdev->default_expires * HZ;
2226 cqr->buildclk = get_tod_clock();
2227 cqr->status = DASD_CQR_FILLED;
2228 /* Set flags to suppress output for expected errors */
2229 set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
2231 return cqr;
2234 static struct dasd_ccw_req *
2235 dasd_eckd_build_format(struct dasd_device *base,
2236 struct format_data_t *fdata,
2237 int enable_pav)
2239 struct dasd_eckd_private *base_priv;
2240 struct dasd_eckd_private *start_priv;
2241 struct dasd_device *startdev = NULL;
2242 struct dasd_ccw_req *fcp;
2243 struct eckd_count *ect;
2244 struct ch_t address;
2245 struct ccw1 *ccw;
2246 void *data;
2247 int rpt;
2248 int cplength, datasize;
2249 int i, j;
2250 int intensity = 0;
2251 int r0_perm;
2252 int nr_tracks;
2253 int use_prefix;
2255 if (enable_pav)
2256 startdev = dasd_alias_get_start_dev(base);
2258 if (!startdev)
2259 startdev = base;
2261 start_priv = startdev->private;
2262 base_priv = base->private;
2264 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2266 nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
2269 * fdata->intensity is a bit string that tells us what to do:
2270 * Bit 0: write record zero
2271 * Bit 1: write home address, currently not supported
2272 * Bit 2: invalidate tracks
2273 * Bit 3: use OS/390 compatible disk layout (cdl)
2274 * Bit 4: do not allow storage subsystem to modify record zero
2275 * Only some bit combinations do make sense.
2277 if (fdata->intensity & 0x10) {
2278 r0_perm = 0;
2279 intensity = fdata->intensity & ~0x10;
2280 } else {
2281 r0_perm = 1;
2282 intensity = fdata->intensity;
2285 use_prefix = base_priv->features.feature[8] & 0x01;
2287 switch (intensity) {
2288 case 0x00: /* Normal format */
2289 case 0x08: /* Normal format, use cdl. */
2290 cplength = 2 + (rpt*nr_tracks);
2291 if (use_prefix)
2292 datasize = sizeof(struct PFX_eckd_data) +
2293 sizeof(struct LO_eckd_data) +
2294 rpt * nr_tracks * sizeof(struct eckd_count);
2295 else
2296 datasize = sizeof(struct DE_eckd_data) +
2297 sizeof(struct LO_eckd_data) +
2298 rpt * nr_tracks * sizeof(struct eckd_count);
2299 break;
2300 case 0x01: /* Write record zero and format track. */
2301 case 0x09: /* Write record zero and format track, use cdl. */
2302 cplength = 2 + rpt * nr_tracks;
2303 if (use_prefix)
2304 datasize = sizeof(struct PFX_eckd_data) +
2305 sizeof(struct LO_eckd_data) +
2306 sizeof(struct eckd_count) +
2307 rpt * nr_tracks * sizeof(struct eckd_count);
2308 else
2309 datasize = sizeof(struct DE_eckd_data) +
2310 sizeof(struct LO_eckd_data) +
2311 sizeof(struct eckd_count) +
2312 rpt * nr_tracks * sizeof(struct eckd_count);
2313 break;
2314 case 0x04: /* Invalidate track. */
2315 case 0x0c: /* Invalidate track, use cdl. */
2316 cplength = 3;
2317 if (use_prefix)
2318 datasize = sizeof(struct PFX_eckd_data) +
2319 sizeof(struct LO_eckd_data) +
2320 sizeof(struct eckd_count);
2321 else
2322 datasize = sizeof(struct DE_eckd_data) +
2323 sizeof(struct LO_eckd_data) +
2324 sizeof(struct eckd_count);
2325 break;
2326 default:
2327 dev_warn(&startdev->cdev->dev,
2328 "An I/O control call used incorrect flags 0x%x\n",
2329 fdata->intensity);
2330 return ERR_PTR(-EINVAL);
2332 /* Allocate the format ccw request. */
2333 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2334 datasize, startdev);
2335 if (IS_ERR(fcp))
2336 return fcp;
2338 start_priv->count++;
2339 data = fcp->data;
2340 ccw = fcp->cpaddr;
2342 switch (intensity & ~0x08) {
2343 case 0x00: /* Normal format. */
2344 if (use_prefix) {
2345 prefix(ccw++, (struct PFX_eckd_data *) data,
2346 fdata->start_unit, fdata->stop_unit,
2347 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2348 /* grant subsystem permission to format R0 */
2349 if (r0_perm)
2350 ((struct PFX_eckd_data *)data)
2351 ->define_extent.ga_extended |= 0x04;
2352 data += sizeof(struct PFX_eckd_data);
2353 } else {
2354 define_extent(ccw++, (struct DE_eckd_data *) data,
2355 fdata->start_unit, fdata->stop_unit,
2356 DASD_ECKD_CCW_WRITE_CKD, startdev, 0);
2357 /* grant subsystem permission to format R0 */
2358 if (r0_perm)
2359 ((struct DE_eckd_data *) data)
2360 ->ga_extended |= 0x04;
2361 data += sizeof(struct DE_eckd_data);
2363 ccw[-1].flags |= CCW_FLAG_CC;
2364 locate_record(ccw++, (struct LO_eckd_data *) data,
2365 fdata->start_unit, 0, rpt*nr_tracks,
2366 DASD_ECKD_CCW_WRITE_CKD, base,
2367 fdata->blksize);
2368 data += sizeof(struct LO_eckd_data);
2369 break;
2370 case 0x01: /* Write record zero + format track. */
2371 if (use_prefix) {
2372 prefix(ccw++, (struct PFX_eckd_data *) data,
2373 fdata->start_unit, fdata->stop_unit,
2374 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2375 base, startdev);
2376 data += sizeof(struct PFX_eckd_data);
2377 } else {
2378 define_extent(ccw++, (struct DE_eckd_data *) data,
2379 fdata->start_unit, fdata->stop_unit,
2380 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev, 0);
2381 data += sizeof(struct DE_eckd_data);
2383 ccw[-1].flags |= CCW_FLAG_CC;
2384 locate_record(ccw++, (struct LO_eckd_data *) data,
2385 fdata->start_unit, 0, rpt * nr_tracks + 1,
2386 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2387 base->block->bp_block);
2388 data += sizeof(struct LO_eckd_data);
2389 break;
2390 case 0x04: /* Invalidate track. */
2391 if (use_prefix) {
2392 prefix(ccw++, (struct PFX_eckd_data *) data,
2393 fdata->start_unit, fdata->stop_unit,
2394 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2395 data += sizeof(struct PFX_eckd_data);
2396 } else {
2397 define_extent(ccw++, (struct DE_eckd_data *) data,
2398 fdata->start_unit, fdata->stop_unit,
2399 DASD_ECKD_CCW_WRITE_CKD, startdev, 0);
2400 data += sizeof(struct DE_eckd_data);
2402 ccw[-1].flags |= CCW_FLAG_CC;
2403 locate_record(ccw++, (struct LO_eckd_data *) data,
2404 fdata->start_unit, 0, 1,
2405 DASD_ECKD_CCW_WRITE_CKD, base, 8);
2406 data += sizeof(struct LO_eckd_data);
2407 break;
2410 for (j = 0; j < nr_tracks; j++) {
2411 /* calculate cylinder and head for the current track */
2412 set_ch_t(&address,
2413 (fdata->start_unit + j) /
2414 base_priv->rdc_data.trk_per_cyl,
2415 (fdata->start_unit + j) %
2416 base_priv->rdc_data.trk_per_cyl);
2417 if (intensity & 0x01) { /* write record zero */
2418 ect = (struct eckd_count *) data;
2419 data += sizeof(struct eckd_count);
2420 ect->cyl = address.cyl;
2421 ect->head = address.head;
2422 ect->record = 0;
2423 ect->kl = 0;
2424 ect->dl = 8;
2425 ccw[-1].flags |= CCW_FLAG_CC;
2426 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
2427 ccw->flags = CCW_FLAG_SLI;
2428 ccw->count = 8;
2429 ccw->cda = (__u32)(addr_t) ect;
2430 ccw++;
2432 if ((intensity & ~0x08) & 0x04) { /* erase track */
2433 ect = (struct eckd_count *) data;
2434 data += sizeof(struct eckd_count);
2435 ect->cyl = address.cyl;
2436 ect->head = address.head;
2437 ect->record = 1;
2438 ect->kl = 0;
2439 ect->dl = 0;
2440 ccw[-1].flags |= CCW_FLAG_CC;
2441 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2442 ccw->flags = CCW_FLAG_SLI;
2443 ccw->count = 8;
2444 ccw->cda = (__u32)(addr_t) ect;
2445 } else { /* write remaining records */
2446 for (i = 0; i < rpt; i++) {
2447 ect = (struct eckd_count *) data;
2448 data += sizeof(struct eckd_count);
2449 ect->cyl = address.cyl;
2450 ect->head = address.head;
2451 ect->record = i + 1;
2452 ect->kl = 0;
2453 ect->dl = fdata->blksize;
2455 * Check for special tracks 0-1
2456 * when formatting CDL
2458 if ((intensity & 0x08) &&
2459 address.cyl == 0 && address.head == 0) {
2460 if (i < 3) {
2461 ect->kl = 4;
2462 ect->dl = sizes_trk0[i] - 4;
2465 if ((intensity & 0x08) &&
2466 address.cyl == 0 && address.head == 1) {
2467 ect->kl = 44;
2468 ect->dl = LABEL_SIZE - 44;
2470 ccw[-1].flags |= CCW_FLAG_CC;
2471 if (i != 0 || j == 0)
2472 ccw->cmd_code =
2473 DASD_ECKD_CCW_WRITE_CKD;
2474 else
2475 ccw->cmd_code =
2476 DASD_ECKD_CCW_WRITE_CKD_MT;
2477 ccw->flags = CCW_FLAG_SLI;
2478 ccw->count = 8;
2479 ccw->cda = (__u32)(addr_t) ect;
2480 ccw++;
2485 fcp->startdev = startdev;
2486 fcp->memdev = startdev;
2487 fcp->basedev = base;
2488 fcp->retries = 256;
2489 fcp->expires = startdev->default_expires * HZ;
2490 fcp->buildclk = get_tod_clock();
2491 fcp->status = DASD_CQR_FILLED;
2493 return fcp;
2497 * Wrapper function to build a CCW request depending on input data
2499 static struct dasd_ccw_req *
2500 dasd_eckd_format_build_ccw_req(struct dasd_device *base,
2501 struct format_data_t *fdata, int enable_pav,
2502 int tpm, struct eckd_count *fmt_buffer, int rpt)
2504 struct dasd_ccw_req *ccw_req;
2506 if (!fmt_buffer) {
2507 ccw_req = dasd_eckd_build_format(base, fdata, enable_pav);
2508 } else {
2509 if (tpm)
2510 ccw_req = dasd_eckd_build_check_tcw(base, fdata,
2511 enable_pav,
2512 fmt_buffer, rpt);
2513 else
2514 ccw_req = dasd_eckd_build_check(base, fdata, enable_pav,
2515 fmt_buffer, rpt);
2518 return ccw_req;
2522 * Sanity checks on format_data
2524 static int dasd_eckd_format_sanity_checks(struct dasd_device *base,
2525 struct format_data_t *fdata)
2527 struct dasd_eckd_private *private = base->private;
2529 if (fdata->start_unit >=
2530 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2531 dev_warn(&base->cdev->dev,
2532 "Start track number %u used in formatting is too big\n",
2533 fdata->start_unit);
2534 return -EINVAL;
2536 if (fdata->stop_unit >=
2537 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2538 dev_warn(&base->cdev->dev,
2539 "Stop track number %u used in formatting is too big\n",
2540 fdata->stop_unit);
2541 return -EINVAL;
2543 if (fdata->start_unit > fdata->stop_unit) {
2544 dev_warn(&base->cdev->dev,
2545 "Start track %u used in formatting exceeds end track\n",
2546 fdata->start_unit);
2547 return -EINVAL;
2549 if (dasd_check_blocksize(fdata->blksize) != 0) {
2550 dev_warn(&base->cdev->dev,
2551 "The DASD cannot be formatted with block size %u\n",
2552 fdata->blksize);
2553 return -EINVAL;
2555 return 0;
2559 * This function will process format_data originally coming from an IOCTL
2561 static int dasd_eckd_format_process_data(struct dasd_device *base,
2562 struct format_data_t *fdata,
2563 int enable_pav, int tpm,
2564 struct eckd_count *fmt_buffer, int rpt,
2565 struct irb *irb)
2567 struct dasd_eckd_private *private = base->private;
2568 struct dasd_ccw_req *cqr, *n;
2569 struct list_head format_queue;
2570 struct dasd_device *device;
2571 char *sense = NULL;
2572 int old_start, old_stop, format_step;
2573 int step, retry;
2574 int rc;
2576 rc = dasd_eckd_format_sanity_checks(base, fdata);
2577 if (rc)
2578 return rc;
2580 INIT_LIST_HEAD(&format_queue);
2582 old_start = fdata->start_unit;
2583 old_stop = fdata->stop_unit;
2585 if (!tpm && fmt_buffer != NULL) {
2586 /* Command Mode / Format Check */
2587 format_step = 1;
2588 } else if (tpm && fmt_buffer != NULL) {
2589 /* Transport Mode / Format Check */
2590 format_step = DASD_CQR_MAX_CCW / rpt;
2591 } else {
2592 /* Normal Formatting */
2593 format_step = DASD_CQR_MAX_CCW /
2594 recs_per_track(&private->rdc_data, 0, fdata->blksize);
2597 do {
2598 retry = 0;
2599 while (fdata->start_unit <= old_stop) {
2600 step = fdata->stop_unit - fdata->start_unit + 1;
2601 if (step > format_step) {
2602 fdata->stop_unit =
2603 fdata->start_unit + format_step - 1;
2606 cqr = dasd_eckd_format_build_ccw_req(base, fdata,
2607 enable_pav, tpm,
2608 fmt_buffer, rpt);
2609 if (IS_ERR(cqr)) {
2610 rc = PTR_ERR(cqr);
2611 if (rc == -ENOMEM) {
2612 if (list_empty(&format_queue))
2613 goto out;
2615 * not enough memory available, start
2616 * requests retry after first requests
2617 * were finished
2619 retry = 1;
2620 break;
2622 goto out_err;
2624 list_add_tail(&cqr->blocklist, &format_queue);
2626 if (fmt_buffer) {
2627 step = fdata->stop_unit - fdata->start_unit + 1;
2628 fmt_buffer += rpt * step;
2630 fdata->start_unit = fdata->stop_unit + 1;
2631 fdata->stop_unit = old_stop;
2634 rc = dasd_sleep_on_queue(&format_queue);
2636 out_err:
2637 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2638 device = cqr->startdev;
2639 private = device->private;
2641 if (cqr->status == DASD_CQR_FAILED) {
2643 * Only get sense data if called by format
2644 * check
2646 if (fmt_buffer && irb) {
2647 sense = dasd_get_sense(&cqr->irb);
2648 memcpy(irb, &cqr->irb, sizeof(*irb));
2650 rc = -EIO;
2652 list_del_init(&cqr->blocklist);
2653 dasd_sfree_request(cqr, device);
2654 private->count--;
2657 if (rc && rc != -EIO)
2658 goto out;
2659 if (rc == -EIO) {
2661 * In case fewer than the expected records are on the
2662 * track, we will most likely get a 'No Record Found'
2663 * error (in command mode) or a 'File Protected' error
2664 * (in transport mode). Those particular cases shouldn't
2665 * pass the -EIO to the IOCTL, therefore reset the rc
2666 * and continue.
2668 if (sense &&
2669 (sense[1] & SNS1_NO_REC_FOUND ||
2670 sense[1] & SNS1_FILE_PROTECTED))
2671 retry = 1;
2672 else
2673 goto out;
2676 } while (retry);
2678 out:
2679 fdata->start_unit = old_start;
2680 fdata->stop_unit = old_stop;
2682 return rc;
2685 static int dasd_eckd_format_device(struct dasd_device *base,
2686 struct format_data_t *fdata, int enable_pav)
2688 return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL,
2689 0, NULL);
2693 * Helper function to count consecutive records of a single track.
2695 static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start,
2696 int max)
2698 int head;
2699 int i;
2701 head = fmt_buffer[start].head;
2704 * There are 3 conditions where we stop counting:
2705 * - if data reoccurs (same head and record may reoccur), which may
2706 * happen due to the way DASD_ECKD_CCW_READ_COUNT works
2707 * - when the head changes, because we're iterating over several tracks
2708 * then (DASD_ECKD_CCW_READ_COUNT_MT)
2709 * - when we've reached the end of sensible data in the buffer (the
2710 * record will be 0 then)
2712 for (i = start; i < max; i++) {
2713 if (i > start) {
2714 if ((fmt_buffer[i].head == head &&
2715 fmt_buffer[i].record == 1) ||
2716 fmt_buffer[i].head != head ||
2717 fmt_buffer[i].record == 0)
2718 break;
2722 return i - start;
2726 * Evaluate a given range of tracks. Data like number of records, blocksize,
2727 * record ids, and key length are compared with expected data.
2729 * If a mismatch occurs, the corresponding error bit is set, as well as
2730 * additional information, depending on the error.
2732 static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer,
2733 struct format_check_t *cdata,
2734 int rpt_max, int rpt_exp,
2735 int trk_per_cyl, int tpm)
2737 struct ch_t geo;
2738 int max_entries;
2739 int count = 0;
2740 int trkcount;
2741 int blksize;
2742 int pos = 0;
2743 int i, j;
2744 int kl;
2746 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2747 max_entries = trkcount * rpt_max;
2749 for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) {
2750 /* Calculate the correct next starting position in the buffer */
2751 if (tpm) {
2752 while (fmt_buffer[pos].record == 0 &&
2753 fmt_buffer[pos].dl == 0) {
2754 if (pos++ > max_entries)
2755 break;
2757 } else {
2758 if (i != cdata->expect.start_unit)
2759 pos += rpt_max - count;
2762 /* Calculate the expected geo values for the current track */
2763 set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl);
2765 /* Count and check number of records */
2766 count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max);
2768 if (count < rpt_exp) {
2769 cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS;
2770 break;
2772 if (count > rpt_exp) {
2773 cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS;
2774 break;
2777 for (j = 0; j < count; j++, pos++) {
2778 blksize = cdata->expect.blksize;
2779 kl = 0;
2782 * Set special values when checking CDL formatted
2783 * devices.
2785 if ((cdata->expect.intensity & 0x08) &&
2786 geo.cyl == 0 && geo.head == 0) {
2787 if (j < 3) {
2788 blksize = sizes_trk0[j] - 4;
2789 kl = 4;
2792 if ((cdata->expect.intensity & 0x08) &&
2793 geo.cyl == 0 && geo.head == 1) {
2794 blksize = LABEL_SIZE - 44;
2795 kl = 44;
2798 /* Check blocksize */
2799 if (fmt_buffer[pos].dl != blksize) {
2800 cdata->result = DASD_FMT_ERR_BLKSIZE;
2801 goto out;
2803 /* Check if key length is 0 */
2804 if (fmt_buffer[pos].kl != kl) {
2805 cdata->result = DASD_FMT_ERR_KEY_LENGTH;
2806 goto out;
2808 /* Check if record_id is correct */
2809 if (fmt_buffer[pos].cyl != geo.cyl ||
2810 fmt_buffer[pos].head != geo.head ||
2811 fmt_buffer[pos].record != (j + 1)) {
2812 cdata->result = DASD_FMT_ERR_RECORD_ID;
2813 goto out;
2818 out:
2820 * In case of no errors, we need to decrease by one
2821 * to get the correct positions.
2823 if (!cdata->result) {
2824 i--;
2825 pos--;
2828 cdata->unit = i;
2829 cdata->num_records = count;
2830 cdata->rec = fmt_buffer[pos].record;
2831 cdata->blksize = fmt_buffer[pos].dl;
2832 cdata->key_length = fmt_buffer[pos].kl;
2836 * Check the format of a range of tracks of a DASD.
2838 static int dasd_eckd_check_device_format(struct dasd_device *base,
2839 struct format_check_t *cdata,
2840 int enable_pav)
2842 struct dasd_eckd_private *private = base->private;
2843 struct eckd_count *fmt_buffer;
2844 struct irb irb;
2845 int rpt_max, rpt_exp;
2846 int fmt_buffer_size;
2847 int trk_per_cyl;
2848 int trkcount;
2849 int tpm = 0;
2850 int rc;
2852 trk_per_cyl = private->rdc_data.trk_per_cyl;
2854 /* Get maximum and expected amount of records per track */
2855 rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1;
2856 rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize);
2858 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2859 fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count);
2861 fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA);
2862 if (!fmt_buffer)
2863 return -ENOMEM;
2866 * A certain FICON feature subset is needed to operate in transport
2867 * mode. Additionally, the support for transport mode is implicitly
2868 * checked by comparing the buffer size with fcx_max_data. As long as
2869 * the buffer size is smaller we can operate in transport mode and
2870 * process multiple tracks. If not, only one track at once is being
2871 * processed using command mode.
2873 if ((private->features.feature[40] & 0x04) &&
2874 fmt_buffer_size <= private->fcx_max_data)
2875 tpm = 1;
2877 rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav,
2878 tpm, fmt_buffer, rpt_max, &irb);
2879 if (rc && rc != -EIO)
2880 goto out;
2881 if (rc == -EIO) {
2883 * If our first attempt with transport mode enabled comes back
2884 * with an incorrect length error, we're going to retry the
2885 * check with command mode.
2887 if (tpm && scsw_cstat(&irb.scsw) == 0x40) {
2888 tpm = 0;
2889 rc = dasd_eckd_format_process_data(base, &cdata->expect,
2890 enable_pav, tpm,
2891 fmt_buffer, rpt_max,
2892 &irb);
2893 if (rc)
2894 goto out;
2895 } else {
2896 goto out;
2900 dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp,
2901 trk_per_cyl, tpm);
2903 out:
2904 kfree(fmt_buffer);
2906 return rc;
2909 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2911 if (cqr->retries < 0) {
2912 cqr->status = DASD_CQR_FAILED;
2913 return;
2915 cqr->status = DASD_CQR_FILLED;
2916 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2917 dasd_eckd_reset_ccw_to_base_io(cqr);
2918 cqr->startdev = cqr->block->base;
2919 cqr->lpm = dasd_path_get_opm(cqr->block->base);
2923 static dasd_erp_fn_t
2924 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2926 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2927 struct ccw_device *cdev = device->cdev;
2929 switch (cdev->id.cu_type) {
2930 case 0x3990:
2931 case 0x2105:
2932 case 0x2107:
2933 case 0x1750:
2934 return dasd_3990_erp_action;
2935 case 0x9343:
2936 case 0x3880:
2937 default:
2938 return dasd_default_erp_action;
2942 static dasd_erp_fn_t
2943 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2945 return dasd_default_erp_postaction;
2948 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2949 struct dasd_ccw_req *cqr,
2950 struct irb *irb)
2952 char mask;
2953 char *sense = NULL;
2954 struct dasd_eckd_private *private = device->private;
2956 /* first of all check for state change pending interrupt */
2957 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
2958 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
2960 * for alias only, not in offline processing
2961 * and only if not suspended
2963 if (!device->block && private->lcu &&
2964 device->state == DASD_STATE_ONLINE &&
2965 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2966 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
2967 /* schedule worker to reload device */
2968 dasd_reload_device(device);
2970 dasd_generic_handle_state_change(device);
2971 return;
2974 sense = dasd_get_sense(irb);
2975 if (!sense)
2976 return;
2978 /* summary unit check */
2979 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
2980 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
2981 if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) {
2982 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2983 "eckd suc: device already notified");
2984 return;
2986 sense = dasd_get_sense(irb);
2987 if (!sense) {
2988 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2989 "eckd suc: no reason code available");
2990 clear_bit(DASD_FLAG_SUC, &device->flags);
2991 return;
2994 private->suc_reason = sense[8];
2995 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
2996 "eckd handle summary unit check: reason",
2997 private->suc_reason);
2998 dasd_get_device(device);
2999 if (!schedule_work(&device->suc_work))
3000 dasd_put_device(device);
3002 return;
3005 /* service information message SIM */
3006 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
3007 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
3008 dasd_3990_erp_handle_sim(device, sense);
3009 return;
3012 /* loss of device reservation is handled via base devices only
3013 * as alias devices may be used with several bases
3015 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
3016 (sense[7] == 0x3F) &&
3017 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
3018 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
3019 if (device->features & DASD_FEATURE_FAILONSLCK)
3020 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
3021 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3022 dev_err(&device->cdev->dev,
3023 "The device reservation was lost\n");
3027 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
3028 struct dasd_device *startdev,
3029 struct dasd_block *block,
3030 struct request *req,
3031 sector_t first_rec,
3032 sector_t last_rec,
3033 sector_t first_trk,
3034 sector_t last_trk,
3035 unsigned int first_offs,
3036 unsigned int last_offs,
3037 unsigned int blk_per_trk,
3038 unsigned int blksize)
3040 struct dasd_eckd_private *private;
3041 unsigned long *idaws;
3042 struct LO_eckd_data *LO_data;
3043 struct dasd_ccw_req *cqr;
3044 struct ccw1 *ccw;
3045 struct req_iterator iter;
3046 struct bio_vec bv;
3047 char *dst;
3048 unsigned int off;
3049 int count, cidaw, cplength, datasize;
3050 sector_t recid;
3051 unsigned char cmd, rcmd;
3052 int use_prefix;
3053 struct dasd_device *basedev;
3055 basedev = block->base;
3056 private = basedev->private;
3057 if (rq_data_dir(req) == READ)
3058 cmd = DASD_ECKD_CCW_READ_MT;
3059 else if (rq_data_dir(req) == WRITE)
3060 cmd = DASD_ECKD_CCW_WRITE_MT;
3061 else
3062 return ERR_PTR(-EINVAL);
3064 /* Check struct bio and count the number of blocks for the request. */
3065 count = 0;
3066 cidaw = 0;
3067 rq_for_each_segment(bv, req, iter) {
3068 if (bv.bv_len & (blksize - 1))
3069 /* Eckd can only do full blocks. */
3070 return ERR_PTR(-EINVAL);
3071 count += bv.bv_len >> (block->s2b_shift + 9);
3072 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
3073 cidaw += bv.bv_len >> (block->s2b_shift + 9);
3075 /* Paranoia. */
3076 if (count != last_rec - first_rec + 1)
3077 return ERR_PTR(-EINVAL);
3079 /* use the prefix command if available */
3080 use_prefix = private->features.feature[8] & 0x01;
3081 if (use_prefix) {
3082 /* 1x prefix + number of blocks */
3083 cplength = 2 + count;
3084 /* 1x prefix + cidaws*sizeof(long) */
3085 datasize = sizeof(struct PFX_eckd_data) +
3086 sizeof(struct LO_eckd_data) +
3087 cidaw * sizeof(unsigned long);
3088 } else {
3089 /* 1x define extent + 1x locate record + number of blocks */
3090 cplength = 2 + count;
3091 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
3092 datasize = sizeof(struct DE_eckd_data) +
3093 sizeof(struct LO_eckd_data) +
3094 cidaw * sizeof(unsigned long);
3096 /* Find out the number of additional locate record ccws for cdl. */
3097 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
3098 if (last_rec >= 2*blk_per_trk)
3099 count = 2*blk_per_trk - first_rec;
3100 cplength += count;
3101 datasize += count*sizeof(struct LO_eckd_data);
3103 /* Allocate the ccw request. */
3104 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3105 startdev);
3106 if (IS_ERR(cqr))
3107 return cqr;
3108 ccw = cqr->cpaddr;
3109 /* First ccw is define extent or prefix. */
3110 if (use_prefix) {
3111 if (prefix(ccw++, cqr->data, first_trk,
3112 last_trk, cmd, basedev, startdev) == -EAGAIN) {
3113 /* Clock not in sync and XRC is enabled.
3114 * Try again later.
3116 dasd_sfree_request(cqr, startdev);
3117 return ERR_PTR(-EAGAIN);
3119 idaws = (unsigned long *) (cqr->data +
3120 sizeof(struct PFX_eckd_data));
3121 } else {
3122 if (define_extent(ccw++, cqr->data, first_trk,
3123 last_trk, cmd, basedev, 0) == -EAGAIN) {
3124 /* Clock not in sync and XRC is enabled.
3125 * Try again later.
3127 dasd_sfree_request(cqr, startdev);
3128 return ERR_PTR(-EAGAIN);
3130 idaws = (unsigned long *) (cqr->data +
3131 sizeof(struct DE_eckd_data));
3133 /* Build locate_record+read/write/ccws. */
3134 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
3135 recid = first_rec;
3136 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
3137 /* Only standard blocks so there is just one locate record. */
3138 ccw[-1].flags |= CCW_FLAG_CC;
3139 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
3140 last_rec - recid + 1, cmd, basedev, blksize);
3142 rq_for_each_segment(bv, req, iter) {
3143 dst = page_address(bv.bv_page) + bv.bv_offset;
3144 if (dasd_page_cache) {
3145 char *copy = kmem_cache_alloc(dasd_page_cache,
3146 GFP_DMA | __GFP_NOWARN);
3147 if (copy && rq_data_dir(req) == WRITE)
3148 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
3149 if (copy)
3150 dst = copy + bv.bv_offset;
3152 for (off = 0; off < bv.bv_len; off += blksize) {
3153 sector_t trkid = recid;
3154 unsigned int recoffs = sector_div(trkid, blk_per_trk);
3155 rcmd = cmd;
3156 count = blksize;
3157 /* Locate record for cdl special block ? */
3158 if (private->uses_cdl && recid < 2*blk_per_trk) {
3159 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
3160 rcmd |= 0x8;
3161 count = dasd_eckd_cdl_reclen(recid);
3162 if (count < blksize &&
3163 rq_data_dir(req) == READ)
3164 memset(dst + count, 0xe5,
3165 blksize - count);
3167 ccw[-1].flags |= CCW_FLAG_CC;
3168 locate_record(ccw++, LO_data++,
3169 trkid, recoffs + 1,
3170 1, rcmd, basedev, count);
3172 /* Locate record for standard blocks ? */
3173 if (private->uses_cdl && recid == 2*blk_per_trk) {
3174 ccw[-1].flags |= CCW_FLAG_CC;
3175 locate_record(ccw++, LO_data++,
3176 trkid, recoffs + 1,
3177 last_rec - recid + 1,
3178 cmd, basedev, count);
3180 /* Read/write ccw. */
3181 ccw[-1].flags |= CCW_FLAG_CC;
3182 ccw->cmd_code = rcmd;
3183 ccw->count = count;
3184 if (idal_is_needed(dst, blksize)) {
3185 ccw->cda = (__u32)(addr_t) idaws;
3186 ccw->flags = CCW_FLAG_IDA;
3187 idaws = idal_create_words(idaws, dst, blksize);
3188 } else {
3189 ccw->cda = (__u32)(addr_t) dst;
3190 ccw->flags = 0;
3192 ccw++;
3193 dst += blksize;
3194 recid++;
3197 if (blk_noretry_request(req) ||
3198 block->base->features & DASD_FEATURE_FAILFAST)
3199 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3200 cqr->startdev = startdev;
3201 cqr->memdev = startdev;
3202 cqr->block = block;
3203 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3204 cqr->lpm = dasd_path_get_ppm(startdev);
3205 cqr->retries = startdev->default_retries;
3206 cqr->buildclk = get_tod_clock();
3207 cqr->status = DASD_CQR_FILLED;
3208 return cqr;
3211 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
3212 struct dasd_device *startdev,
3213 struct dasd_block *block,
3214 struct request *req,
3215 sector_t first_rec,
3216 sector_t last_rec,
3217 sector_t first_trk,
3218 sector_t last_trk,
3219 unsigned int first_offs,
3220 unsigned int last_offs,
3221 unsigned int blk_per_trk,
3222 unsigned int blksize)
3224 unsigned long *idaws;
3225 struct dasd_ccw_req *cqr;
3226 struct ccw1 *ccw;
3227 struct req_iterator iter;
3228 struct bio_vec bv;
3229 char *dst, *idaw_dst;
3230 unsigned int cidaw, cplength, datasize;
3231 unsigned int tlf;
3232 sector_t recid;
3233 unsigned char cmd;
3234 struct dasd_device *basedev;
3235 unsigned int trkcount, count, count_to_trk_end;
3236 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
3237 unsigned char new_track, end_idaw;
3238 sector_t trkid;
3239 unsigned int recoffs;
3241 basedev = block->base;
3242 if (rq_data_dir(req) == READ)
3243 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3244 else if (rq_data_dir(req) == WRITE)
3245 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3246 else
3247 return ERR_PTR(-EINVAL);
3249 /* Track based I/O needs IDAWs for each page, and not just for
3250 * 64 bit addresses. We need additional idals for pages
3251 * that get filled from two tracks, so we use the number
3252 * of records as upper limit.
3254 cidaw = last_rec - first_rec + 1;
3255 trkcount = last_trk - first_trk + 1;
3257 /* 1x prefix + one read/write ccw per track */
3258 cplength = 1 + trkcount;
3260 datasize = sizeof(struct PFX_eckd_data) + cidaw * sizeof(unsigned long);
3262 /* Allocate the ccw request. */
3263 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3264 startdev);
3265 if (IS_ERR(cqr))
3266 return cqr;
3267 ccw = cqr->cpaddr;
3268 /* transfer length factor: how many bytes to read from the last track */
3269 if (first_trk == last_trk)
3270 tlf = last_offs - first_offs + 1;
3271 else
3272 tlf = last_offs + 1;
3273 tlf *= blksize;
3275 if (prefix_LRE(ccw++, cqr->data, first_trk,
3276 last_trk, cmd, basedev, startdev,
3277 1 /* format */, first_offs + 1,
3278 trkcount, blksize,
3279 tlf) == -EAGAIN) {
3280 /* Clock not in sync and XRC is enabled.
3281 * Try again later.
3283 dasd_sfree_request(cqr, startdev);
3284 return ERR_PTR(-EAGAIN);
3288 * The translation of request into ccw programs must meet the
3289 * following conditions:
3290 * - all idaws but the first and the last must address full pages
3291 * (or 2K blocks on 31-bit)
3292 * - the scope of a ccw and it's idal ends with the track boundaries
3294 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
3295 recid = first_rec;
3296 new_track = 1;
3297 end_idaw = 0;
3298 len_to_track_end = 0;
3299 idaw_dst = NULL;
3300 idaw_len = 0;
3301 rq_for_each_segment(bv, req, iter) {
3302 dst = page_address(bv.bv_page) + bv.bv_offset;
3303 seg_len = bv.bv_len;
3304 while (seg_len) {
3305 if (new_track) {
3306 trkid = recid;
3307 recoffs = sector_div(trkid, blk_per_trk);
3308 count_to_trk_end = blk_per_trk - recoffs;
3309 count = min((last_rec - recid + 1),
3310 (sector_t)count_to_trk_end);
3311 len_to_track_end = count * blksize;
3312 ccw[-1].flags |= CCW_FLAG_CC;
3313 ccw->cmd_code = cmd;
3314 ccw->count = len_to_track_end;
3315 ccw->cda = (__u32)(addr_t)idaws;
3316 ccw->flags = CCW_FLAG_IDA;
3317 ccw++;
3318 recid += count;
3319 new_track = 0;
3320 /* first idaw for a ccw may start anywhere */
3321 if (!idaw_dst)
3322 idaw_dst = dst;
3324 /* If we start a new idaw, we must make sure that it
3325 * starts on an IDA_BLOCK_SIZE boundary.
3326 * If we continue an idaw, we must make sure that the
3327 * current segment begins where the so far accumulated
3328 * idaw ends
3330 if (!idaw_dst) {
3331 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
3332 dasd_sfree_request(cqr, startdev);
3333 return ERR_PTR(-ERANGE);
3334 } else
3335 idaw_dst = dst;
3337 if ((idaw_dst + idaw_len) != dst) {
3338 dasd_sfree_request(cqr, startdev);
3339 return ERR_PTR(-ERANGE);
3341 part_len = min(seg_len, len_to_track_end);
3342 seg_len -= part_len;
3343 dst += part_len;
3344 idaw_len += part_len;
3345 len_to_track_end -= part_len;
3346 /* collected memory area ends on an IDA_BLOCK border,
3347 * -> create an idaw
3348 * idal_create_words will handle cases where idaw_len
3349 * is larger then IDA_BLOCK_SIZE
3351 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
3352 end_idaw = 1;
3353 /* We also need to end the idaw at track end */
3354 if (!len_to_track_end) {
3355 new_track = 1;
3356 end_idaw = 1;
3358 if (end_idaw) {
3359 idaws = idal_create_words(idaws, idaw_dst,
3360 idaw_len);
3361 idaw_dst = NULL;
3362 idaw_len = 0;
3363 end_idaw = 0;
3368 if (blk_noretry_request(req) ||
3369 block->base->features & DASD_FEATURE_FAILFAST)
3370 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3371 cqr->startdev = startdev;
3372 cqr->memdev = startdev;
3373 cqr->block = block;
3374 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3375 cqr->lpm = dasd_path_get_ppm(startdev);
3376 cqr->retries = startdev->default_retries;
3377 cqr->buildclk = get_tod_clock();
3378 cqr->status = DASD_CQR_FILLED;
3379 return cqr;
3382 static int prepare_itcw(struct itcw *itcw,
3383 unsigned int trk, unsigned int totrk, int cmd,
3384 struct dasd_device *basedev,
3385 struct dasd_device *startdev,
3386 unsigned int rec_on_trk, int count,
3387 unsigned int blksize,
3388 unsigned int total_data_size,
3389 unsigned int tlf,
3390 unsigned int blk_per_trk)
3392 struct PFX_eckd_data pfxdata;
3393 struct dasd_eckd_private *basepriv, *startpriv;
3394 struct DE_eckd_data *dedata;
3395 struct LRE_eckd_data *lredata;
3396 struct dcw *dcw;
3398 u32 begcyl, endcyl;
3399 u16 heads, beghead, endhead;
3400 u8 pfx_cmd;
3402 int rc = 0;
3403 int sector = 0;
3404 int dn, d;
3407 /* setup prefix data */
3408 basepriv = basedev->private;
3409 startpriv = startdev->private;
3410 dedata = &pfxdata.define_extent;
3411 lredata = &pfxdata.locate_record;
3413 memset(&pfxdata, 0, sizeof(pfxdata));
3414 pfxdata.format = 1; /* PFX with LRE */
3415 pfxdata.base_address = basepriv->ned->unit_addr;
3416 pfxdata.base_lss = basepriv->ned->ID;
3417 pfxdata.validity.define_extent = 1;
3419 /* private uid is kept up to date, conf_data may be outdated */
3420 if (startpriv->uid.type == UA_BASE_PAV_ALIAS)
3421 pfxdata.validity.verify_base = 1;
3423 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) {
3424 pfxdata.validity.verify_base = 1;
3425 pfxdata.validity.hyper_pav = 1;
3428 switch (cmd) {
3429 case DASD_ECKD_CCW_READ_TRACK_DATA:
3430 dedata->mask.perm = 0x1;
3431 dedata->attributes.operation = basepriv->attrib.operation;
3432 dedata->blk_size = blksize;
3433 dedata->ga_extended |= 0x42;
3434 lredata->operation.orientation = 0x0;
3435 lredata->operation.operation = 0x0C;
3436 lredata->auxiliary.check_bytes = 0x01;
3437 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3438 break;
3439 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
3440 dedata->mask.perm = 0x02;
3441 dedata->attributes.operation = basepriv->attrib.operation;
3442 dedata->blk_size = blksize;
3443 rc = check_XRC(NULL, dedata, basedev);
3444 dedata->ga_extended |= 0x42;
3445 lredata->operation.orientation = 0x0;
3446 lredata->operation.operation = 0x3F;
3447 lredata->extended_operation = 0x23;
3448 lredata->auxiliary.check_bytes = 0x2;
3450 * If XRC is supported the System Time Stamp is set. The
3451 * validity of the time stamp must be reflected in the prefix
3452 * data as well.
3454 if (dedata->ga_extended & 0x08 && dedata->ga_extended & 0x02)
3455 pfxdata.validity.time_stamp = 1; /* 'Time Stamp Valid' */
3456 pfx_cmd = DASD_ECKD_CCW_PFX;
3457 break;
3458 case DASD_ECKD_CCW_READ_COUNT_MT:
3459 dedata->mask.perm = 0x1;
3460 dedata->attributes.operation = DASD_BYPASS_CACHE;
3461 dedata->ga_extended |= 0x42;
3462 dedata->blk_size = blksize;
3463 lredata->operation.orientation = 0x2;
3464 lredata->operation.operation = 0x16;
3465 lredata->auxiliary.check_bytes = 0x01;
3466 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3467 break;
3468 default:
3469 DBF_DEV_EVENT(DBF_ERR, basedev,
3470 "prepare itcw, unknown opcode 0x%x", cmd);
3471 BUG();
3472 break;
3474 if (rc)
3475 return rc;
3477 dedata->attributes.mode = 0x3; /* ECKD */
3479 heads = basepriv->rdc_data.trk_per_cyl;
3480 begcyl = trk / heads;
3481 beghead = trk % heads;
3482 endcyl = totrk / heads;
3483 endhead = totrk % heads;
3485 /* check for sequential prestage - enhance cylinder range */
3486 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
3487 dedata->attributes.operation == DASD_SEQ_ACCESS) {
3489 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
3490 endcyl += basepriv->attrib.nr_cyl;
3491 else
3492 endcyl = (basepriv->real_cyl - 1);
3495 set_ch_t(&dedata->beg_ext, begcyl, beghead);
3496 set_ch_t(&dedata->end_ext, endcyl, endhead);
3498 dedata->ep_format = 0x20; /* records per track is valid */
3499 dedata->ep_rec_per_track = blk_per_trk;
3501 if (rec_on_trk) {
3502 switch (basepriv->rdc_data.dev_type) {
3503 case 0x3390:
3504 dn = ceil_quot(blksize + 6, 232);
3505 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
3506 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
3507 break;
3508 case 0x3380:
3509 d = 7 + ceil_quot(blksize + 12, 32);
3510 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
3511 break;
3515 if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) {
3516 lredata->auxiliary.length_valid = 0;
3517 lredata->auxiliary.length_scope = 0;
3518 lredata->sector = 0xff;
3519 } else {
3520 lredata->auxiliary.length_valid = 1;
3521 lredata->auxiliary.length_scope = 1;
3522 lredata->sector = sector;
3524 lredata->auxiliary.imbedded_ccw_valid = 1;
3525 lredata->length = tlf;
3526 lredata->imbedded_ccw = cmd;
3527 lredata->count = count;
3528 set_ch_t(&lredata->seek_addr, begcyl, beghead);
3529 lredata->search_arg.cyl = lredata->seek_addr.cyl;
3530 lredata->search_arg.head = lredata->seek_addr.head;
3531 lredata->search_arg.record = rec_on_trk;
3533 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
3534 &pfxdata, sizeof(pfxdata), total_data_size);
3535 return PTR_RET(dcw);
3538 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
3539 struct dasd_device *startdev,
3540 struct dasd_block *block,
3541 struct request *req,
3542 sector_t first_rec,
3543 sector_t last_rec,
3544 sector_t first_trk,
3545 sector_t last_trk,
3546 unsigned int first_offs,
3547 unsigned int last_offs,
3548 unsigned int blk_per_trk,
3549 unsigned int blksize)
3551 struct dasd_ccw_req *cqr;
3552 struct req_iterator iter;
3553 struct bio_vec bv;
3554 char *dst;
3555 unsigned int trkcount, ctidaw;
3556 unsigned char cmd;
3557 struct dasd_device *basedev;
3558 unsigned int tlf;
3559 struct itcw *itcw;
3560 struct tidaw *last_tidaw = NULL;
3561 int itcw_op;
3562 size_t itcw_size;
3563 u8 tidaw_flags;
3564 unsigned int seg_len, part_len, len_to_track_end;
3565 unsigned char new_track;
3566 sector_t recid, trkid;
3567 unsigned int offs;
3568 unsigned int count, count_to_trk_end;
3569 int ret;
3571 basedev = block->base;
3572 if (rq_data_dir(req) == READ) {
3573 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3574 itcw_op = ITCW_OP_READ;
3575 } else if (rq_data_dir(req) == WRITE) {
3576 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3577 itcw_op = ITCW_OP_WRITE;
3578 } else
3579 return ERR_PTR(-EINVAL);
3581 /* trackbased I/O needs address all memory via TIDAWs,
3582 * not just for 64 bit addresses. This allows us to map
3583 * each segment directly to one tidaw.
3584 * In the case of write requests, additional tidaws may
3585 * be needed when a segment crosses a track boundary.
3587 trkcount = last_trk - first_trk + 1;
3588 ctidaw = 0;
3589 rq_for_each_segment(bv, req, iter) {
3590 ++ctidaw;
3592 if (rq_data_dir(req) == WRITE)
3593 ctidaw += (last_trk - first_trk);
3595 /* Allocate the ccw request. */
3596 itcw_size = itcw_calc_size(0, ctidaw, 0);
3597 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
3598 if (IS_ERR(cqr))
3599 return cqr;
3601 /* transfer length factor: how many bytes to read from the last track */
3602 if (first_trk == last_trk)
3603 tlf = last_offs - first_offs + 1;
3604 else
3605 tlf = last_offs + 1;
3606 tlf *= blksize;
3608 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
3609 if (IS_ERR(itcw)) {
3610 ret = -EINVAL;
3611 goto out_error;
3613 cqr->cpaddr = itcw_get_tcw(itcw);
3614 if (prepare_itcw(itcw, first_trk, last_trk,
3615 cmd, basedev, startdev,
3616 first_offs + 1,
3617 trkcount, blksize,
3618 (last_rec - first_rec + 1) * blksize,
3619 tlf, blk_per_trk) == -EAGAIN) {
3620 /* Clock not in sync and XRC is enabled.
3621 * Try again later.
3623 ret = -EAGAIN;
3624 goto out_error;
3626 len_to_track_end = 0;
3628 * A tidaw can address 4k of memory, but must not cross page boundaries
3629 * We can let the block layer handle this by setting
3630 * blk_queue_segment_boundary to page boundaries and
3631 * blk_max_segment_size to page size when setting up the request queue.
3632 * For write requests, a TIDAW must not cross track boundaries, because
3633 * we have to set the CBC flag on the last tidaw for each track.
3635 if (rq_data_dir(req) == WRITE) {
3636 new_track = 1;
3637 recid = first_rec;
3638 rq_for_each_segment(bv, req, iter) {
3639 dst = page_address(bv.bv_page) + bv.bv_offset;
3640 seg_len = bv.bv_len;
3641 while (seg_len) {
3642 if (new_track) {
3643 trkid = recid;
3644 offs = sector_div(trkid, blk_per_trk);
3645 count_to_trk_end = blk_per_trk - offs;
3646 count = min((last_rec - recid + 1),
3647 (sector_t)count_to_trk_end);
3648 len_to_track_end = count * blksize;
3649 recid += count;
3650 new_track = 0;
3652 part_len = min(seg_len, len_to_track_end);
3653 seg_len -= part_len;
3654 len_to_track_end -= part_len;
3655 /* We need to end the tidaw at track end */
3656 if (!len_to_track_end) {
3657 new_track = 1;
3658 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3659 } else
3660 tidaw_flags = 0;
3661 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3662 dst, part_len);
3663 if (IS_ERR(last_tidaw)) {
3664 ret = -EINVAL;
3665 goto out_error;
3667 dst += part_len;
3670 } else {
3671 rq_for_each_segment(bv, req, iter) {
3672 dst = page_address(bv.bv_page) + bv.bv_offset;
3673 last_tidaw = itcw_add_tidaw(itcw, 0x00,
3674 dst, bv.bv_len);
3675 if (IS_ERR(last_tidaw)) {
3676 ret = -EINVAL;
3677 goto out_error;
3681 last_tidaw->flags |= TIDAW_FLAGS_LAST;
3682 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
3683 itcw_finalize(itcw);
3685 if (blk_noretry_request(req) ||
3686 block->base->features & DASD_FEATURE_FAILFAST)
3687 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3688 cqr->cpmode = 1;
3689 cqr->startdev = startdev;
3690 cqr->memdev = startdev;
3691 cqr->block = block;
3692 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3693 cqr->lpm = dasd_path_get_ppm(startdev);
3694 cqr->retries = startdev->default_retries;
3695 cqr->buildclk = get_tod_clock();
3696 cqr->status = DASD_CQR_FILLED;
3697 return cqr;
3698 out_error:
3699 dasd_sfree_request(cqr, startdev);
3700 return ERR_PTR(ret);
3703 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3704 struct dasd_block *block,
3705 struct request *req)
3707 int cmdrtd, cmdwtd;
3708 int use_prefix;
3709 int fcx_multitrack;
3710 struct dasd_eckd_private *private;
3711 struct dasd_device *basedev;
3712 sector_t first_rec, last_rec;
3713 sector_t first_trk, last_trk;
3714 unsigned int first_offs, last_offs;
3715 unsigned int blk_per_trk, blksize;
3716 int cdlspecial;
3717 unsigned int data_size;
3718 struct dasd_ccw_req *cqr;
3720 basedev = block->base;
3721 private = basedev->private;
3723 /* Calculate number of blocks/records per track. */
3724 blksize = block->bp_block;
3725 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3726 if (blk_per_trk == 0)
3727 return ERR_PTR(-EINVAL);
3728 /* Calculate record id of first and last block. */
3729 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
3730 first_offs = sector_div(first_trk, blk_per_trk);
3731 last_rec = last_trk =
3732 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
3733 last_offs = sector_div(last_trk, blk_per_trk);
3734 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3736 fcx_multitrack = private->features.feature[40] & 0x20;
3737 data_size = blk_rq_bytes(req);
3738 if (data_size % blksize)
3739 return ERR_PTR(-EINVAL);
3740 /* tpm write request add CBC data on each track boundary */
3741 if (rq_data_dir(req) == WRITE)
3742 data_size += (last_trk - first_trk) * 4;
3744 /* is read track data and write track data in command mode supported? */
3745 cmdrtd = private->features.feature[9] & 0x20;
3746 cmdwtd = private->features.feature[12] & 0x40;
3747 use_prefix = private->features.feature[8] & 0x01;
3749 cqr = NULL;
3750 if (cdlspecial || dasd_page_cache) {
3751 /* do nothing, just fall through to the cmd mode single case */
3752 } else if ((data_size <= private->fcx_max_data)
3753 && (fcx_multitrack || (first_trk == last_trk))) {
3754 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3755 first_rec, last_rec,
3756 first_trk, last_trk,
3757 first_offs, last_offs,
3758 blk_per_trk, blksize);
3759 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3760 (PTR_ERR(cqr) != -ENOMEM))
3761 cqr = NULL;
3762 } else if (use_prefix &&
3763 (((rq_data_dir(req) == READ) && cmdrtd) ||
3764 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3765 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3766 first_rec, last_rec,
3767 first_trk, last_trk,
3768 first_offs, last_offs,
3769 blk_per_trk, blksize);
3770 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3771 (PTR_ERR(cqr) != -ENOMEM))
3772 cqr = NULL;
3774 if (!cqr)
3775 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3776 first_rec, last_rec,
3777 first_trk, last_trk,
3778 first_offs, last_offs,
3779 blk_per_trk, blksize);
3780 return cqr;
3783 static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev,
3784 struct dasd_block *block,
3785 struct request *req)
3787 sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
3788 unsigned int seg_len, len_to_track_end;
3789 unsigned int cidaw, cplength, datasize;
3790 sector_t first_trk, last_trk, sectors;
3791 struct dasd_eckd_private *base_priv;
3792 struct dasd_device *basedev;
3793 struct req_iterator iter;
3794 struct dasd_ccw_req *cqr;
3795 unsigned int first_offs;
3796 unsigned int trkcount;
3797 unsigned long *idaws;
3798 unsigned int size;
3799 unsigned char cmd;
3800 struct bio_vec bv;
3801 struct ccw1 *ccw;
3802 int use_prefix;
3803 void *data;
3804 char *dst;
3807 * raw track access needs to be mutiple of 64k and on 64k boundary
3808 * For read requests we can fix an incorrect alignment by padding
3809 * the request with dummy pages.
3811 start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
3812 end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
3813 DASD_RAW_SECTORS_PER_TRACK;
3814 end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
3815 DASD_RAW_SECTORS_PER_TRACK;
3816 basedev = block->base;
3817 if ((start_padding_sectors || end_padding_sectors) &&
3818 (rq_data_dir(req) == WRITE)) {
3819 DBF_DEV_EVENT(DBF_ERR, basedev,
3820 "raw write not track aligned (%lu,%lu) req %p",
3821 start_padding_sectors, end_padding_sectors, req);
3822 return ERR_PTR(-EINVAL);
3825 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3826 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3827 DASD_RAW_SECTORS_PER_TRACK;
3828 trkcount = last_trk - first_trk + 1;
3829 first_offs = 0;
3831 if (rq_data_dir(req) == READ)
3832 cmd = DASD_ECKD_CCW_READ_TRACK;
3833 else if (rq_data_dir(req) == WRITE)
3834 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3835 else
3836 return ERR_PTR(-EINVAL);
3839 * Raw track based I/O needs IDAWs for each page,
3840 * and not just for 64 bit addresses.
3842 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3845 * struct PFX_eckd_data and struct LRE_eckd_data can have up to 2 bytes
3846 * of extended parameter. This is needed for write full track.
3848 base_priv = basedev->private;
3849 use_prefix = base_priv->features.feature[8] & 0x01;
3850 if (use_prefix) {
3851 cplength = 1 + trkcount;
3852 size = sizeof(struct PFX_eckd_data) + 2;
3853 } else {
3854 cplength = 2 + trkcount;
3855 size = sizeof(struct DE_eckd_data) +
3856 sizeof(struct LRE_eckd_data) + 2;
3858 size = ALIGN(size, 8);
3860 datasize = size + cidaw * sizeof(unsigned long);
3862 /* Allocate the ccw request. */
3863 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3864 datasize, startdev);
3865 if (IS_ERR(cqr))
3866 return cqr;
3868 ccw = cqr->cpaddr;
3869 data = cqr->data;
3871 if (use_prefix) {
3872 prefix_LRE(ccw++, data, first_trk, last_trk, cmd, basedev,
3873 startdev, 1, first_offs + 1, trkcount, 0, 0);
3874 } else {
3875 define_extent(ccw++, data, first_trk, last_trk, cmd, basedev, 0);
3876 ccw[-1].flags |= CCW_FLAG_CC;
3878 data += sizeof(struct DE_eckd_data);
3879 locate_record_ext(ccw++, data, first_trk, first_offs + 1,
3880 trkcount, cmd, basedev, 0, 0);
3883 idaws = (unsigned long *)(cqr->data + size);
3884 len_to_track_end = 0;
3885 if (start_padding_sectors) {
3886 ccw[-1].flags |= CCW_FLAG_CC;
3887 ccw->cmd_code = cmd;
3888 /* maximum 3390 track size */
3889 ccw->count = 57326;
3890 /* 64k map to one track */
3891 len_to_track_end = 65536 - start_padding_sectors * 512;
3892 ccw->cda = (__u32)(addr_t)idaws;
3893 ccw->flags |= CCW_FLAG_IDA;
3894 ccw->flags |= CCW_FLAG_SLI;
3895 ccw++;
3896 for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
3897 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3899 rq_for_each_segment(bv, req, iter) {
3900 dst = page_address(bv.bv_page) + bv.bv_offset;
3901 seg_len = bv.bv_len;
3902 if (cmd == DASD_ECKD_CCW_READ_TRACK)
3903 memset(dst, 0, seg_len);
3904 if (!len_to_track_end) {
3905 ccw[-1].flags |= CCW_FLAG_CC;
3906 ccw->cmd_code = cmd;
3907 /* maximum 3390 track size */
3908 ccw->count = 57326;
3909 /* 64k map to one track */
3910 len_to_track_end = 65536;
3911 ccw->cda = (__u32)(addr_t)idaws;
3912 ccw->flags |= CCW_FLAG_IDA;
3913 ccw->flags |= CCW_FLAG_SLI;
3914 ccw++;
3916 len_to_track_end -= seg_len;
3917 idaws = idal_create_words(idaws, dst, seg_len);
3919 for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
3920 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3921 if (blk_noretry_request(req) ||
3922 block->base->features & DASD_FEATURE_FAILFAST)
3923 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3924 cqr->startdev = startdev;
3925 cqr->memdev = startdev;
3926 cqr->block = block;
3927 cqr->expires = startdev->default_expires * HZ;
3928 cqr->lpm = dasd_path_get_ppm(startdev);
3929 cqr->retries = startdev->default_retries;
3930 cqr->buildclk = get_tod_clock();
3931 cqr->status = DASD_CQR_FILLED;
3933 return cqr;
3937 static int
3938 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3940 struct dasd_eckd_private *private;
3941 struct ccw1 *ccw;
3942 struct req_iterator iter;
3943 struct bio_vec bv;
3944 char *dst, *cda;
3945 unsigned int blksize, blk_per_trk, off;
3946 sector_t recid;
3947 int status;
3949 if (!dasd_page_cache)
3950 goto out;
3951 private = cqr->block->base->private;
3952 blksize = cqr->block->bp_block;
3953 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3954 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
3955 ccw = cqr->cpaddr;
3956 /* Skip over define extent & locate record. */
3957 ccw++;
3958 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
3959 ccw++;
3960 rq_for_each_segment(bv, req, iter) {
3961 dst = page_address(bv.bv_page) + bv.bv_offset;
3962 for (off = 0; off < bv.bv_len; off += blksize) {
3963 /* Skip locate record. */
3964 if (private->uses_cdl && recid <= 2*blk_per_trk)
3965 ccw++;
3966 if (dst) {
3967 if (ccw->flags & CCW_FLAG_IDA)
3968 cda = *((char **)((addr_t) ccw->cda));
3969 else
3970 cda = (char *)((addr_t) ccw->cda);
3971 if (dst != cda) {
3972 if (rq_data_dir(req) == READ)
3973 memcpy(dst, cda, bv.bv_len);
3974 kmem_cache_free(dasd_page_cache,
3975 (void *)((addr_t)cda & PAGE_MASK));
3977 dst = NULL;
3979 ccw++;
3980 recid++;
3983 out:
3984 status = cqr->status == DASD_CQR_DONE;
3985 dasd_sfree_request(cqr, cqr->memdev);
3986 return status;
3990 * Modify ccw/tcw in cqr so it can be started on a base device.
3992 * Note that this is not enough to restart the cqr!
3993 * Either reset cqr->startdev as well (summary unit check handling)
3994 * or restart via separate cqr (as in ERP handling).
3996 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3998 struct ccw1 *ccw;
3999 struct PFX_eckd_data *pfxdata;
4000 struct tcw *tcw;
4001 struct tccb *tccb;
4002 struct dcw *dcw;
4004 if (cqr->cpmode == 1) {
4005 tcw = cqr->cpaddr;
4006 tccb = tcw_get_tccb(tcw);
4007 dcw = (struct dcw *)&tccb->tca[0];
4008 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
4009 pfxdata->validity.verify_base = 0;
4010 pfxdata->validity.hyper_pav = 0;
4011 } else {
4012 ccw = cqr->cpaddr;
4013 pfxdata = cqr->data;
4014 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
4015 pfxdata->validity.verify_base = 0;
4016 pfxdata->validity.hyper_pav = 0;
4021 #define DASD_ECKD_CHANQ_MAX_SIZE 4
4023 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
4024 struct dasd_block *block,
4025 struct request *req)
4027 struct dasd_eckd_private *private;
4028 struct dasd_device *startdev;
4029 unsigned long flags;
4030 struct dasd_ccw_req *cqr;
4032 startdev = dasd_alias_get_start_dev(base);
4033 if (!startdev)
4034 startdev = base;
4035 private = startdev->private;
4036 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
4037 return ERR_PTR(-EBUSY);
4039 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
4040 private->count++;
4041 if ((base->features & DASD_FEATURE_USERAW))
4042 cqr = dasd_eckd_build_cp_raw(startdev, block, req);
4043 else
4044 cqr = dasd_eckd_build_cp(startdev, block, req);
4045 if (IS_ERR(cqr))
4046 private->count--;
4047 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
4048 return cqr;
4051 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
4052 struct request *req)
4054 struct dasd_eckd_private *private;
4055 unsigned long flags;
4057 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
4058 private = cqr->memdev->private;
4059 private->count--;
4060 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
4061 return dasd_eckd_free_cp(cqr, req);
4064 static int
4065 dasd_eckd_fill_info(struct dasd_device * device,
4066 struct dasd_information2_t * info)
4068 struct dasd_eckd_private *private = device->private;
4070 info->label_block = 2;
4071 info->FBA_layout = private->uses_cdl ? 0 : 1;
4072 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
4073 info->characteristics_size = sizeof(private->rdc_data);
4074 memcpy(info->characteristics, &private->rdc_data,
4075 sizeof(private->rdc_data));
4076 info->confdata_size = min((unsigned long)private->conf_len,
4077 sizeof(info->configuration_data));
4078 memcpy(info->configuration_data, private->conf_data,
4079 info->confdata_size);
4080 return 0;
4084 * SECTION: ioctl functions for eckd devices.
4088 * Release device ioctl.
4089 * Buils a channel programm to releases a prior reserved
4090 * (see dasd_eckd_reserve) device.
4092 static int
4093 dasd_eckd_release(struct dasd_device *device)
4095 struct dasd_ccw_req *cqr;
4096 int rc;
4097 struct ccw1 *ccw;
4098 int useglobal;
4100 if (!capable(CAP_SYS_ADMIN))
4101 return -EACCES;
4103 useglobal = 0;
4104 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4105 if (IS_ERR(cqr)) {
4106 mutex_lock(&dasd_reserve_mutex);
4107 useglobal = 1;
4108 cqr = &dasd_reserve_req->cqr;
4109 memset(cqr, 0, sizeof(*cqr));
4110 memset(&dasd_reserve_req->ccw, 0,
4111 sizeof(dasd_reserve_req->ccw));
4112 cqr->cpaddr = &dasd_reserve_req->ccw;
4113 cqr->data = &dasd_reserve_req->data;
4114 cqr->magic = DASD_ECKD_MAGIC;
4116 ccw = cqr->cpaddr;
4117 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
4118 ccw->flags |= CCW_FLAG_SLI;
4119 ccw->count = 32;
4120 ccw->cda = (__u32)(addr_t) cqr->data;
4121 cqr->startdev = device;
4122 cqr->memdev = device;
4123 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4124 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4125 cqr->retries = 2; /* set retry counter to enable basic ERP */
4126 cqr->expires = 2 * HZ;
4127 cqr->buildclk = get_tod_clock();
4128 cqr->status = DASD_CQR_FILLED;
4130 rc = dasd_sleep_on_immediatly(cqr);
4131 if (!rc)
4132 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4134 if (useglobal)
4135 mutex_unlock(&dasd_reserve_mutex);
4136 else
4137 dasd_sfree_request(cqr, cqr->memdev);
4138 return rc;
4142 * Reserve device ioctl.
4143 * Options are set to 'synchronous wait for interrupt' and
4144 * 'timeout the request'. This leads to a terminate IO if
4145 * the interrupt is outstanding for a certain time.
4147 static int
4148 dasd_eckd_reserve(struct dasd_device *device)
4150 struct dasd_ccw_req *cqr;
4151 int rc;
4152 struct ccw1 *ccw;
4153 int useglobal;
4155 if (!capable(CAP_SYS_ADMIN))
4156 return -EACCES;
4158 useglobal = 0;
4159 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4160 if (IS_ERR(cqr)) {
4161 mutex_lock(&dasd_reserve_mutex);
4162 useglobal = 1;
4163 cqr = &dasd_reserve_req->cqr;
4164 memset(cqr, 0, sizeof(*cqr));
4165 memset(&dasd_reserve_req->ccw, 0,
4166 sizeof(dasd_reserve_req->ccw));
4167 cqr->cpaddr = &dasd_reserve_req->ccw;
4168 cqr->data = &dasd_reserve_req->data;
4169 cqr->magic = DASD_ECKD_MAGIC;
4171 ccw = cqr->cpaddr;
4172 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
4173 ccw->flags |= CCW_FLAG_SLI;
4174 ccw->count = 32;
4175 ccw->cda = (__u32)(addr_t) cqr->data;
4176 cqr->startdev = device;
4177 cqr->memdev = device;
4178 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4179 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4180 cqr->retries = 2; /* set retry counter to enable basic ERP */
4181 cqr->expires = 2 * HZ;
4182 cqr->buildclk = get_tod_clock();
4183 cqr->status = DASD_CQR_FILLED;
4185 rc = dasd_sleep_on_immediatly(cqr);
4186 if (!rc)
4187 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4189 if (useglobal)
4190 mutex_unlock(&dasd_reserve_mutex);
4191 else
4192 dasd_sfree_request(cqr, cqr->memdev);
4193 return rc;
4197 * Steal lock ioctl - unconditional reserve device.
4198 * Buils a channel programm to break a device's reservation.
4199 * (unconditional reserve)
4201 static int
4202 dasd_eckd_steal_lock(struct dasd_device *device)
4204 struct dasd_ccw_req *cqr;
4205 int rc;
4206 struct ccw1 *ccw;
4207 int useglobal;
4209 if (!capable(CAP_SYS_ADMIN))
4210 return -EACCES;
4212 useglobal = 0;
4213 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4214 if (IS_ERR(cqr)) {
4215 mutex_lock(&dasd_reserve_mutex);
4216 useglobal = 1;
4217 cqr = &dasd_reserve_req->cqr;
4218 memset(cqr, 0, sizeof(*cqr));
4219 memset(&dasd_reserve_req->ccw, 0,
4220 sizeof(dasd_reserve_req->ccw));
4221 cqr->cpaddr = &dasd_reserve_req->ccw;
4222 cqr->data = &dasd_reserve_req->data;
4223 cqr->magic = DASD_ECKD_MAGIC;
4225 ccw = cqr->cpaddr;
4226 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
4227 ccw->flags |= CCW_FLAG_SLI;
4228 ccw->count = 32;
4229 ccw->cda = (__u32)(addr_t) cqr->data;
4230 cqr->startdev = device;
4231 cqr->memdev = device;
4232 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4233 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4234 cqr->retries = 2; /* set retry counter to enable basic ERP */
4235 cqr->expires = 2 * HZ;
4236 cqr->buildclk = get_tod_clock();
4237 cqr->status = DASD_CQR_FILLED;
4239 rc = dasd_sleep_on_immediatly(cqr);
4240 if (!rc)
4241 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4243 if (useglobal)
4244 mutex_unlock(&dasd_reserve_mutex);
4245 else
4246 dasd_sfree_request(cqr, cqr->memdev);
4247 return rc;
4251 * SNID - Sense Path Group ID
4252 * This ioctl may be used in situations where I/O is stalled due to
4253 * a reserve, so if the normal dasd_smalloc_request fails, we use the
4254 * preallocated dasd_reserve_req.
4256 static int dasd_eckd_snid(struct dasd_device *device,
4257 void __user *argp)
4259 struct dasd_ccw_req *cqr;
4260 int rc;
4261 struct ccw1 *ccw;
4262 int useglobal;
4263 struct dasd_snid_ioctl_data usrparm;
4265 if (!capable(CAP_SYS_ADMIN))
4266 return -EACCES;
4268 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4269 return -EFAULT;
4271 useglobal = 0;
4272 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
4273 sizeof(struct dasd_snid_data), device);
4274 if (IS_ERR(cqr)) {
4275 mutex_lock(&dasd_reserve_mutex);
4276 useglobal = 1;
4277 cqr = &dasd_reserve_req->cqr;
4278 memset(cqr, 0, sizeof(*cqr));
4279 memset(&dasd_reserve_req->ccw, 0,
4280 sizeof(dasd_reserve_req->ccw));
4281 cqr->cpaddr = &dasd_reserve_req->ccw;
4282 cqr->data = &dasd_reserve_req->data;
4283 cqr->magic = DASD_ECKD_MAGIC;
4285 ccw = cqr->cpaddr;
4286 ccw->cmd_code = DASD_ECKD_CCW_SNID;
4287 ccw->flags |= CCW_FLAG_SLI;
4288 ccw->count = 12;
4289 ccw->cda = (__u32)(addr_t) cqr->data;
4290 cqr->startdev = device;
4291 cqr->memdev = device;
4292 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4293 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4294 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
4295 cqr->retries = 5;
4296 cqr->expires = 10 * HZ;
4297 cqr->buildclk = get_tod_clock();
4298 cqr->status = DASD_CQR_FILLED;
4299 cqr->lpm = usrparm.path_mask;
4301 rc = dasd_sleep_on_immediatly(cqr);
4302 /* verify that I/O processing didn't modify the path mask */
4303 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
4304 rc = -EIO;
4305 if (!rc) {
4306 usrparm.data = *((struct dasd_snid_data *)cqr->data);
4307 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
4308 rc = -EFAULT;
4311 if (useglobal)
4312 mutex_unlock(&dasd_reserve_mutex);
4313 else
4314 dasd_sfree_request(cqr, cqr->memdev);
4315 return rc;
4319 * Read performance statistics
4321 static int
4322 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
4324 struct dasd_psf_prssd_data *prssdp;
4325 struct dasd_rssd_perf_stats_t *stats;
4326 struct dasd_ccw_req *cqr;
4327 struct ccw1 *ccw;
4328 int rc;
4330 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
4331 (sizeof(struct dasd_psf_prssd_data) +
4332 sizeof(struct dasd_rssd_perf_stats_t)),
4333 device);
4334 if (IS_ERR(cqr)) {
4335 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4336 "Could not allocate initialization request");
4337 return PTR_ERR(cqr);
4339 cqr->startdev = device;
4340 cqr->memdev = device;
4341 cqr->retries = 0;
4342 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4343 cqr->expires = 10 * HZ;
4345 /* Prepare for Read Subsystem Data */
4346 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4347 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
4348 prssdp->order = PSF_ORDER_PRSSD;
4349 prssdp->suborder = 0x01; /* Performance Statistics */
4350 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
4352 ccw = cqr->cpaddr;
4353 ccw->cmd_code = DASD_ECKD_CCW_PSF;
4354 ccw->count = sizeof(struct dasd_psf_prssd_data);
4355 ccw->flags |= CCW_FLAG_CC;
4356 ccw->cda = (__u32)(addr_t) prssdp;
4358 /* Read Subsystem Data - Performance Statistics */
4359 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4360 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
4362 ccw++;
4363 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4364 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
4365 ccw->cda = (__u32)(addr_t) stats;
4367 cqr->buildclk = get_tod_clock();
4368 cqr->status = DASD_CQR_FILLED;
4369 rc = dasd_sleep_on(cqr);
4370 if (rc == 0) {
4371 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4372 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4373 if (copy_to_user(argp, stats,
4374 sizeof(struct dasd_rssd_perf_stats_t)))
4375 rc = -EFAULT;
4377 dasd_sfree_request(cqr, cqr->memdev);
4378 return rc;
4382 * Get attributes (cache operations)
4383 * Returnes the cache attributes used in Define Extend (DE).
4385 static int
4386 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
4388 struct dasd_eckd_private *private = device->private;
4389 struct attrib_data_t attrib = private->attrib;
4390 int rc;
4392 if (!capable(CAP_SYS_ADMIN))
4393 return -EACCES;
4394 if (!argp)
4395 return -EINVAL;
4397 rc = 0;
4398 if (copy_to_user(argp, (long *) &attrib,
4399 sizeof(struct attrib_data_t)))
4400 rc = -EFAULT;
4402 return rc;
4406 * Set attributes (cache operations)
4407 * Stores the attributes for cache operation to be used in Define Extend (DE).
4409 static int
4410 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
4412 struct dasd_eckd_private *private = device->private;
4413 struct attrib_data_t attrib;
4415 if (!capable(CAP_SYS_ADMIN))
4416 return -EACCES;
4417 if (!argp)
4418 return -EINVAL;
4420 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
4421 return -EFAULT;
4422 private->attrib = attrib;
4424 dev_info(&device->cdev->dev,
4425 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
4426 private->attrib.operation, private->attrib.nr_cyl);
4427 return 0;
4431 * Issue syscall I/O to EMC Symmetrix array.
4432 * CCWs are PSF and RSSD
4434 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
4436 struct dasd_symmio_parms usrparm;
4437 char *psf_data, *rssd_result;
4438 struct dasd_ccw_req *cqr;
4439 struct ccw1 *ccw;
4440 char psf0, psf1;
4441 int rc;
4443 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
4444 return -EACCES;
4445 psf0 = psf1 = 0;
4447 /* Copy parms from caller */
4448 rc = -EFAULT;
4449 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4450 goto out;
4451 if (is_compat_task()) {
4452 /* Make sure pointers are sane even on 31 bit. */
4453 rc = -EINVAL;
4454 if ((usrparm.psf_data >> 32) != 0)
4455 goto out;
4456 if ((usrparm.rssd_result >> 32) != 0)
4457 goto out;
4458 usrparm.psf_data &= 0x7fffffffULL;
4459 usrparm.rssd_result &= 0x7fffffffULL;
4461 /* alloc I/O data area */
4462 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
4463 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
4464 if (!psf_data || !rssd_result) {
4465 rc = -ENOMEM;
4466 goto out_free;
4469 /* get syscall header from user space */
4470 rc = -EFAULT;
4471 if (copy_from_user(psf_data,
4472 (void __user *)(unsigned long) usrparm.psf_data,
4473 usrparm.psf_data_len))
4474 goto out_free;
4475 psf0 = psf_data[0];
4476 psf1 = psf_data[1];
4478 /* setup CCWs for PSF + RSSD */
4479 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
4480 if (IS_ERR(cqr)) {
4481 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4482 "Could not allocate initialization request");
4483 rc = PTR_ERR(cqr);
4484 goto out_free;
4487 cqr->startdev = device;
4488 cqr->memdev = device;
4489 cqr->retries = 3;
4490 cqr->expires = 10 * HZ;
4491 cqr->buildclk = get_tod_clock();
4492 cqr->status = DASD_CQR_FILLED;
4494 /* Build the ccws */
4495 ccw = cqr->cpaddr;
4497 /* PSF ccw */
4498 ccw->cmd_code = DASD_ECKD_CCW_PSF;
4499 ccw->count = usrparm.psf_data_len;
4500 ccw->flags |= CCW_FLAG_CC;
4501 ccw->cda = (__u32)(addr_t) psf_data;
4503 ccw++;
4505 /* RSSD ccw */
4506 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4507 ccw->count = usrparm.rssd_result_len;
4508 ccw->flags = CCW_FLAG_SLI ;
4509 ccw->cda = (__u32)(addr_t) rssd_result;
4511 rc = dasd_sleep_on(cqr);
4512 if (rc)
4513 goto out_sfree;
4515 rc = -EFAULT;
4516 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
4517 rssd_result, usrparm.rssd_result_len))
4518 goto out_sfree;
4519 rc = 0;
4521 out_sfree:
4522 dasd_sfree_request(cqr, cqr->memdev);
4523 out_free:
4524 kfree(rssd_result);
4525 kfree(psf_data);
4526 out:
4527 DBF_DEV_EVENT(DBF_WARNING, device,
4528 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4529 (int) psf0, (int) psf1, rc);
4530 return rc;
4533 static int
4534 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
4536 struct dasd_device *device = block->base;
4538 switch (cmd) {
4539 case BIODASDGATTR:
4540 return dasd_eckd_get_attrib(device, argp);
4541 case BIODASDSATTR:
4542 return dasd_eckd_set_attrib(device, argp);
4543 case BIODASDPSRD:
4544 return dasd_eckd_performance(device, argp);
4545 case BIODASDRLSE:
4546 return dasd_eckd_release(device);
4547 case BIODASDRSRV:
4548 return dasd_eckd_reserve(device);
4549 case BIODASDSLCK:
4550 return dasd_eckd_steal_lock(device);
4551 case BIODASDSNID:
4552 return dasd_eckd_snid(device, argp);
4553 case BIODASDSYMMIO:
4554 return dasd_symm_io(device, argp);
4555 default:
4556 return -ENOTTY;
4561 * Dump the range of CCWs into 'page' buffer
4562 * and return number of printed chars.
4564 static int
4565 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
4567 int len, count;
4568 char *datap;
4570 len = 0;
4571 while (from <= to) {
4572 len += sprintf(page + len, PRINTK_HEADER
4573 " CCW %p: %08X %08X DAT:",
4574 from, ((int *) from)[0], ((int *) from)[1]);
4576 /* get pointer to data (consider IDALs) */
4577 if (from->flags & CCW_FLAG_IDA)
4578 datap = (char *) *((addr_t *) (addr_t) from->cda);
4579 else
4580 datap = (char *) ((addr_t) from->cda);
4582 /* dump data (max 32 bytes) */
4583 for (count = 0; count < from->count && count < 32; count++) {
4584 if (count % 8 == 0) len += sprintf(page + len, " ");
4585 if (count % 4 == 0) len += sprintf(page + len, " ");
4586 len += sprintf(page + len, "%02x", datap[count]);
4588 len += sprintf(page + len, "\n");
4589 from++;
4591 return len;
4594 static void
4595 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4596 char *reason)
4598 u64 *sense;
4599 u64 *stat;
4601 sense = (u64 *) dasd_get_sense(irb);
4602 stat = (u64 *) &irb->scsw;
4603 if (sense) {
4604 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4605 "%016llx %016llx %016llx %016llx",
4606 reason, *stat, *((u32 *) (stat + 1)),
4607 sense[0], sense[1], sense[2], sense[3]);
4608 } else {
4609 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4610 reason, *stat, *((u32 *) (stat + 1)),
4611 "NO VALID SENSE");
4616 * Print sense data and related channel program.
4617 * Parts are printed because printk buffer is only 1024 bytes.
4619 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
4620 struct dasd_ccw_req *req, struct irb *irb)
4622 char *page;
4623 struct ccw1 *first, *last, *fail, *from, *to;
4624 int len, sl, sct;
4626 page = (char *) get_zeroed_page(GFP_ATOMIC);
4627 if (page == NULL) {
4628 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4629 "No memory to dump sense data\n");
4630 return;
4632 /* dump the sense data */
4633 len = sprintf(page, PRINTK_HEADER
4634 " I/O status report for device %s:\n",
4635 dev_name(&device->cdev->dev));
4636 len += sprintf(page + len, PRINTK_HEADER
4637 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4638 "CS:%02X RC:%d\n",
4639 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4640 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4641 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4642 req ? req->intrc : 0);
4643 len += sprintf(page + len, PRINTK_HEADER
4644 " device %s: Failing CCW: %p\n",
4645 dev_name(&device->cdev->dev),
4646 (void *) (addr_t) irb->scsw.cmd.cpa);
4647 if (irb->esw.esw0.erw.cons) {
4648 for (sl = 0; sl < 4; sl++) {
4649 len += sprintf(page + len, PRINTK_HEADER
4650 " Sense(hex) %2d-%2d:",
4651 (8 * sl), ((8 * sl) + 7));
4653 for (sct = 0; sct < 8; sct++) {
4654 len += sprintf(page + len, " %02x",
4655 irb->ecw[8 * sl + sct]);
4657 len += sprintf(page + len, "\n");
4660 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4661 /* 24 Byte Sense Data */
4662 sprintf(page + len, PRINTK_HEADER
4663 " 24 Byte: %x MSG %x, "
4664 "%s MSGb to SYSOP\n",
4665 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4666 irb->ecw[1] & 0x10 ? "" : "no");
4667 } else {
4668 /* 32 Byte Sense Data */
4669 sprintf(page + len, PRINTK_HEADER
4670 " 32 Byte: Format: %x "
4671 "Exception class %x\n",
4672 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
4674 } else {
4675 sprintf(page + len, PRINTK_HEADER
4676 " SORRY - NO VALID SENSE AVAILABLE\n");
4678 printk(KERN_ERR "%s", page);
4680 if (req) {
4681 /* req == NULL for unsolicited interrupts */
4682 /* dump the Channel Program (max 140 Bytes per line) */
4683 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4684 first = req->cpaddr;
4685 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4686 to = min(first + 6, last);
4687 len = sprintf(page, PRINTK_HEADER
4688 " Related CP in req: %p\n", req);
4689 dasd_eckd_dump_ccw_range(first, to, page + len);
4690 printk(KERN_ERR "%s", page);
4692 /* print failing CCW area (maximum 4) */
4693 /* scsw->cda is either valid or zero */
4694 len = 0;
4695 from = ++to;
4696 fail = (struct ccw1 *)(addr_t)
4697 irb->scsw.cmd.cpa; /* failing CCW */
4698 if (from < fail - 2) {
4699 from = fail - 2; /* there is a gap - print header */
4700 len += sprintf(page, PRINTK_HEADER "......\n");
4702 to = min(fail + 1, last);
4703 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4705 /* print last CCWs (maximum 2) */
4706 from = max(from, ++to);
4707 if (from < last - 1) {
4708 from = last - 1; /* there is a gap - print header */
4709 len += sprintf(page + len, PRINTK_HEADER "......\n");
4711 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4712 if (len > 0)
4713 printk(KERN_ERR "%s", page);
4715 free_page((unsigned long) page);
4720 * Print sense data from a tcw.
4722 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4723 struct dasd_ccw_req *req, struct irb *irb)
4725 char *page;
4726 int len, sl, sct, residual;
4727 struct tsb *tsb;
4728 u8 *sense, *rcq;
4730 page = (char *) get_zeroed_page(GFP_ATOMIC);
4731 if (page == NULL) {
4732 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
4733 "No memory to dump sense data");
4734 return;
4736 /* dump the sense data */
4737 len = sprintf(page, PRINTK_HEADER
4738 " I/O status report for device %s:\n",
4739 dev_name(&device->cdev->dev));
4740 len += sprintf(page + len, PRINTK_HEADER
4741 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4742 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4743 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4744 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4745 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4746 irb->scsw.tm.fcxs,
4747 (irb->scsw.tm.ifob << 7) | irb->scsw.tm.sesq,
4748 req ? req->intrc : 0);
4749 len += sprintf(page + len, PRINTK_HEADER
4750 " device %s: Failing TCW: %p\n",
4751 dev_name(&device->cdev->dev),
4752 (void *) (addr_t) irb->scsw.tm.tcw);
4754 tsb = NULL;
4755 sense = NULL;
4756 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
4757 tsb = tcw_get_tsb(
4758 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4760 if (tsb) {
4761 len += sprintf(page + len, PRINTK_HEADER
4762 " tsb->length %d\n", tsb->length);
4763 len += sprintf(page + len, PRINTK_HEADER
4764 " tsb->flags %x\n", tsb->flags);
4765 len += sprintf(page + len, PRINTK_HEADER
4766 " tsb->dcw_offset %d\n", tsb->dcw_offset);
4767 len += sprintf(page + len, PRINTK_HEADER
4768 " tsb->count %d\n", tsb->count);
4769 residual = tsb->count - 28;
4770 len += sprintf(page + len, PRINTK_HEADER
4771 " residual %d\n", residual);
4773 switch (tsb->flags & 0x07) {
4774 case 1: /* tsa_iostat */
4775 len += sprintf(page + len, PRINTK_HEADER
4776 " tsb->tsa.iostat.dev_time %d\n",
4777 tsb->tsa.iostat.dev_time);
4778 len += sprintf(page + len, PRINTK_HEADER
4779 " tsb->tsa.iostat.def_time %d\n",
4780 tsb->tsa.iostat.def_time);
4781 len += sprintf(page + len, PRINTK_HEADER
4782 " tsb->tsa.iostat.queue_time %d\n",
4783 tsb->tsa.iostat.queue_time);
4784 len += sprintf(page + len, PRINTK_HEADER
4785 " tsb->tsa.iostat.dev_busy_time %d\n",
4786 tsb->tsa.iostat.dev_busy_time);
4787 len += sprintf(page + len, PRINTK_HEADER
4788 " tsb->tsa.iostat.dev_act_time %d\n",
4789 tsb->tsa.iostat.dev_act_time);
4790 sense = tsb->tsa.iostat.sense;
4791 break;
4792 case 2: /* ts_ddpc */
4793 len += sprintf(page + len, PRINTK_HEADER
4794 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
4795 for (sl = 0; sl < 2; sl++) {
4796 len += sprintf(page + len, PRINTK_HEADER
4797 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4798 (8 * sl), ((8 * sl) + 7));
4799 rcq = tsb->tsa.ddpc.rcq;
4800 for (sct = 0; sct < 8; sct++) {
4801 len += sprintf(page + len, " %02x",
4802 rcq[8 * sl + sct]);
4804 len += sprintf(page + len, "\n");
4806 sense = tsb->tsa.ddpc.sense;
4807 break;
4808 case 3: /* tsa_intrg */
4809 len += sprintf(page + len, PRINTK_HEADER
4810 " tsb->tsa.intrg.: not supported yet\n");
4811 break;
4814 if (sense) {
4815 for (sl = 0; sl < 4; sl++) {
4816 len += sprintf(page + len, PRINTK_HEADER
4817 " Sense(hex) %2d-%2d:",
4818 (8 * sl), ((8 * sl) + 7));
4819 for (sct = 0; sct < 8; sct++) {
4820 len += sprintf(page + len, " %02x",
4821 sense[8 * sl + sct]);
4823 len += sprintf(page + len, "\n");
4826 if (sense[27] & DASD_SENSE_BIT_0) {
4827 /* 24 Byte Sense Data */
4828 sprintf(page + len, PRINTK_HEADER
4829 " 24 Byte: %x MSG %x, "
4830 "%s MSGb to SYSOP\n",
4831 sense[7] >> 4, sense[7] & 0x0f,
4832 sense[1] & 0x10 ? "" : "no");
4833 } else {
4834 /* 32 Byte Sense Data */
4835 sprintf(page + len, PRINTK_HEADER
4836 " 32 Byte: Format: %x "
4837 "Exception class %x\n",
4838 sense[6] & 0x0f, sense[22] >> 4);
4840 } else {
4841 sprintf(page + len, PRINTK_HEADER
4842 " SORRY - NO VALID SENSE AVAILABLE\n");
4844 } else {
4845 sprintf(page + len, PRINTK_HEADER
4846 " SORRY - NO TSB DATA AVAILABLE\n");
4848 printk(KERN_ERR "%s", page);
4849 free_page((unsigned long) page);
4852 static void dasd_eckd_dump_sense(struct dasd_device *device,
4853 struct dasd_ccw_req *req, struct irb *irb)
4855 u8 *sense = dasd_get_sense(irb);
4857 if (scsw_is_tm(&irb->scsw)) {
4859 * In some cases the 'File Protected' or 'Incorrect Length'
4860 * error might be expected and log messages shouldn't be written
4861 * then. Check if the according suppress bit is set.
4863 if (sense && (sense[1] & SNS1_FILE_PROTECTED) &&
4864 test_bit(DASD_CQR_SUPPRESS_FP, &req->flags))
4865 return;
4866 if (scsw_cstat(&irb->scsw) == 0x40 &&
4867 test_bit(DASD_CQR_SUPPRESS_IL, &req->flags))
4868 return;
4870 dasd_eckd_dump_sense_tcw(device, req, irb);
4871 } else {
4873 * In some cases the 'Command Reject' or 'No Record Found'
4874 * error might be expected and log messages shouldn't be
4875 * written then. Check if the according suppress bit is set.
4877 if (sense && sense[0] & SNS0_CMD_REJECT &&
4878 test_bit(DASD_CQR_SUPPRESS_CR, &req->flags))
4879 return;
4881 if (sense && sense[1] & SNS1_NO_REC_FOUND &&
4882 test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags))
4883 return;
4885 dasd_eckd_dump_sense_ccw(device, req, irb);
4889 static int dasd_eckd_pm_freeze(struct dasd_device *device)
4892 * the device should be disconnected from our LCU structure
4893 * on restore we will reconnect it and reread LCU specific
4894 * information like PAV support that might have changed
4896 dasd_alias_remove_device(device);
4897 dasd_alias_disconnect_device_from_lcu(device);
4899 return 0;
4902 static int dasd_eckd_restore_device(struct dasd_device *device)
4904 struct dasd_eckd_private *private = device->private;
4905 struct dasd_eckd_characteristics temp_rdc_data;
4906 int rc;
4907 struct dasd_uid temp_uid;
4908 unsigned long flags;
4909 unsigned long cqr_flags = 0;
4911 /* Read Configuration Data */
4912 rc = dasd_eckd_read_conf(device);
4913 if (rc) {
4914 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4915 "Read configuration data failed, rc=%d", rc);
4916 goto out_err;
4919 dasd_eckd_get_uid(device, &temp_uid);
4920 /* Generate device unique id */
4921 rc = dasd_eckd_generate_uid(device);
4922 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4923 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
4924 dev_err(&device->cdev->dev, "The UID of the DASD has "
4925 "changed\n");
4926 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4927 if (rc)
4928 goto out_err;
4930 /* register lcu with alias handling, enable PAV if this is a new lcu */
4931 rc = dasd_alias_make_device_known_to_lcu(device);
4932 if (rc)
4933 goto out_err;
4935 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4936 dasd_eckd_validate_server(device, cqr_flags);
4938 /* RE-Read Configuration Data */
4939 rc = dasd_eckd_read_conf(device);
4940 if (rc) {
4941 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4942 "Read configuration data failed, rc=%d", rc);
4943 goto out_err2;
4946 /* Read Feature Codes */
4947 dasd_eckd_read_features(device);
4949 /* Read Device Characteristics */
4950 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
4951 &temp_rdc_data, 64);
4952 if (rc) {
4953 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4954 "Read device characteristic failed, rc=%d", rc);
4955 goto out_err2;
4957 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4958 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
4959 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4961 /* add device to alias management */
4962 dasd_alias_add_device(device);
4964 return 0;
4966 out_err2:
4967 dasd_alias_disconnect_device_from_lcu(device);
4968 out_err:
4969 return -1;
4972 static int dasd_eckd_reload_device(struct dasd_device *device)
4974 struct dasd_eckd_private *private = device->private;
4975 int rc, old_base;
4976 char print_uid[60];
4977 struct dasd_uid uid;
4978 unsigned long flags;
4981 * remove device from alias handling to prevent new requests
4982 * from being scheduled on the wrong alias device
4984 dasd_alias_remove_device(device);
4986 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4987 old_base = private->uid.base_unit_addr;
4988 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4990 /* Read Configuration Data */
4991 rc = dasd_eckd_read_conf(device);
4992 if (rc)
4993 goto out_err;
4995 rc = dasd_eckd_generate_uid(device);
4996 if (rc)
4997 goto out_err;
4999 * update unit address configuration and
5000 * add device to alias management
5002 dasd_alias_update_add_device(device);
5004 dasd_eckd_get_uid(device, &uid);
5006 if (old_base != uid.base_unit_addr) {
5007 if (strlen(uid.vduit) > 0)
5008 snprintf(print_uid, sizeof(print_uid),
5009 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
5010 uid.ssid, uid.base_unit_addr, uid.vduit);
5011 else
5012 snprintf(print_uid, sizeof(print_uid),
5013 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
5014 uid.ssid, uid.base_unit_addr);
5016 dev_info(&device->cdev->dev,
5017 "An Alias device was reassigned to a new base device "
5018 "with UID: %s\n", print_uid);
5020 return 0;
5022 out_err:
5023 return -1;
5026 static int dasd_eckd_read_message_buffer(struct dasd_device *device,
5027 struct dasd_rssd_messages *messages,
5028 __u8 lpum)
5030 struct dasd_rssd_messages *message_buf;
5031 struct dasd_psf_prssd_data *prssdp;
5032 struct dasd_ccw_req *cqr;
5033 struct ccw1 *ccw;
5034 int rc;
5036 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5037 (sizeof(struct dasd_psf_prssd_data) +
5038 sizeof(struct dasd_rssd_messages)),
5039 device);
5040 if (IS_ERR(cqr)) {
5041 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5042 "Could not allocate read message buffer request");
5043 return PTR_ERR(cqr);
5046 cqr->lpm = lpum;
5047 retry:
5048 cqr->startdev = device;
5049 cqr->memdev = device;
5050 cqr->block = NULL;
5051 cqr->expires = 10 * HZ;
5052 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5053 /* dasd_sleep_on_immediatly does not do complex error
5054 * recovery so clear erp flag and set retry counter to
5055 * do basic erp */
5056 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
5057 cqr->retries = 256;
5059 /* Prepare for Read Subsystem Data */
5060 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5061 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5062 prssdp->order = PSF_ORDER_PRSSD;
5063 prssdp->suborder = 0x03; /* Message Buffer */
5064 /* all other bytes of prssdp must be zero */
5066 ccw = cqr->cpaddr;
5067 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5068 ccw->count = sizeof(struct dasd_psf_prssd_data);
5069 ccw->flags |= CCW_FLAG_CC;
5070 ccw->flags |= CCW_FLAG_SLI;
5071 ccw->cda = (__u32)(addr_t) prssdp;
5073 /* Read Subsystem Data - message buffer */
5074 message_buf = (struct dasd_rssd_messages *) (prssdp + 1);
5075 memset(message_buf, 0, sizeof(struct dasd_rssd_messages));
5077 ccw++;
5078 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5079 ccw->count = sizeof(struct dasd_rssd_messages);
5080 ccw->flags |= CCW_FLAG_SLI;
5081 ccw->cda = (__u32)(addr_t) message_buf;
5083 cqr->buildclk = get_tod_clock();
5084 cqr->status = DASD_CQR_FILLED;
5085 rc = dasd_sleep_on_immediatly(cqr);
5086 if (rc == 0) {
5087 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5088 message_buf = (struct dasd_rssd_messages *)
5089 (prssdp + 1);
5090 memcpy(messages, message_buf,
5091 sizeof(struct dasd_rssd_messages));
5092 } else if (cqr->lpm) {
5094 * on z/VM we might not be able to do I/O on the requested path
5095 * but instead we get the required information on any path
5096 * so retry with open path mask
5098 cqr->lpm = 0;
5099 goto retry;
5100 } else
5101 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5102 "Reading messages failed with rc=%d\n"
5103 , rc);
5104 dasd_sfree_request(cqr, cqr->memdev);
5105 return rc;
5108 static int dasd_eckd_query_host_access(struct dasd_device *device,
5109 struct dasd_psf_query_host_access *data)
5111 struct dasd_eckd_private *private = device->private;
5112 struct dasd_psf_query_host_access *host_access;
5113 struct dasd_psf_prssd_data *prssdp;
5114 struct dasd_ccw_req *cqr;
5115 struct ccw1 *ccw;
5116 int rc;
5118 /* not available for HYPER PAV alias devices */
5119 if (!device->block && private->lcu->pav == HYPER_PAV)
5120 return -EOPNOTSUPP;
5122 /* may not be supported by the storage server */
5123 if (!(private->features.feature[14] & 0x80))
5124 return -EOPNOTSUPP;
5126 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5127 sizeof(struct dasd_psf_prssd_data) + 1,
5128 device);
5129 if (IS_ERR(cqr)) {
5130 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5131 "Could not allocate read message buffer request");
5132 return PTR_ERR(cqr);
5134 host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA);
5135 if (!host_access) {
5136 dasd_sfree_request(cqr, device);
5137 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5138 "Could not allocate host_access buffer");
5139 return -ENOMEM;
5141 cqr->startdev = device;
5142 cqr->memdev = device;
5143 cqr->block = NULL;
5144 cqr->retries = 256;
5145 cqr->expires = 10 * HZ;
5147 /* Prepare for Read Subsystem Data */
5148 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5149 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5150 prssdp->order = PSF_ORDER_PRSSD;
5151 prssdp->suborder = PSF_SUBORDER_QHA; /* query host access */
5152 /* LSS and Volume that will be queried */
5153 prssdp->lss = private->ned->ID;
5154 prssdp->volume = private->ned->unit_addr;
5155 /* all other bytes of prssdp must be zero */
5157 ccw = cqr->cpaddr;
5158 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5159 ccw->count = sizeof(struct dasd_psf_prssd_data);
5160 ccw->flags |= CCW_FLAG_CC;
5161 ccw->flags |= CCW_FLAG_SLI;
5162 ccw->cda = (__u32)(addr_t) prssdp;
5164 /* Read Subsystem Data - query host access */
5165 ccw++;
5166 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5167 ccw->count = sizeof(struct dasd_psf_query_host_access);
5168 ccw->flags |= CCW_FLAG_SLI;
5169 ccw->cda = (__u32)(addr_t) host_access;
5171 cqr->buildclk = get_tod_clock();
5172 cqr->status = DASD_CQR_FILLED;
5173 /* the command might not be supported, suppress error message */
5174 __set_bit(DASD_CQR_SUPPRESS_CR, &cqr->flags);
5175 rc = dasd_sleep_on_interruptible(cqr);
5176 if (rc == 0) {
5177 *data = *host_access;
5178 } else {
5179 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5180 "Reading host access data failed with rc=%d\n",
5181 rc);
5182 rc = -EOPNOTSUPP;
5185 dasd_sfree_request(cqr, cqr->memdev);
5186 kfree(host_access);
5187 return rc;
5190 * return number of grouped devices
5192 static int dasd_eckd_host_access_count(struct dasd_device *device)
5194 struct dasd_psf_query_host_access *access;
5195 struct dasd_ckd_path_group_entry *entry;
5196 struct dasd_ckd_host_information *info;
5197 int count = 0;
5198 int rc, i;
5200 access = kzalloc(sizeof(*access), GFP_NOIO);
5201 if (!access) {
5202 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5203 "Could not allocate access buffer");
5204 return -ENOMEM;
5206 rc = dasd_eckd_query_host_access(device, access);
5207 if (rc) {
5208 kfree(access);
5209 return rc;
5212 info = (struct dasd_ckd_host_information *)
5213 access->host_access_information;
5214 for (i = 0; i < info->entry_count; i++) {
5215 entry = (struct dasd_ckd_path_group_entry *)
5216 (info->entry + i * info->entry_size);
5217 if (entry->status_flags & DASD_ECKD_PG_GROUPED)
5218 count++;
5221 kfree(access);
5222 return count;
5226 * write host access information to a sequential file
5228 static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m)
5230 struct dasd_psf_query_host_access *access;
5231 struct dasd_ckd_path_group_entry *entry;
5232 struct dasd_ckd_host_information *info;
5233 char sysplex[9] = "";
5234 int rc, i;
5236 access = kzalloc(sizeof(*access), GFP_NOIO);
5237 if (!access) {
5238 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5239 "Could not allocate access buffer");
5240 return -ENOMEM;
5242 rc = dasd_eckd_query_host_access(device, access);
5243 if (rc) {
5244 kfree(access);
5245 return rc;
5248 info = (struct dasd_ckd_host_information *)
5249 access->host_access_information;
5250 for (i = 0; i < info->entry_count; i++) {
5251 entry = (struct dasd_ckd_path_group_entry *)
5252 (info->entry + i * info->entry_size);
5253 /* PGID */
5254 seq_printf(m, "pgid %*phN\n", 11, entry->pgid);
5255 /* FLAGS */
5256 seq_printf(m, "status_flags %02x\n", entry->status_flags);
5257 /* SYSPLEX NAME */
5258 memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1);
5259 EBCASC(sysplex, sizeof(sysplex));
5260 seq_printf(m, "sysplex_name %8s\n", sysplex);
5261 /* SUPPORTED CYLINDER */
5262 seq_printf(m, "supported_cylinder %d\n", entry->cylinder);
5263 /* TIMESTAMP */
5264 seq_printf(m, "timestamp %lu\n", (unsigned long)
5265 entry->timestamp);
5267 kfree(access);
5269 return 0;
5273 * Perform Subsystem Function - CUIR response
5275 static int
5276 dasd_eckd_psf_cuir_response(struct dasd_device *device, int response,
5277 __u32 message_id, __u8 lpum)
5279 struct dasd_psf_cuir_response *psf_cuir;
5280 int pos = pathmask_to_pos(lpum);
5281 struct dasd_ccw_req *cqr;
5282 struct ccw1 *ccw;
5283 int rc;
5285 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
5286 sizeof(struct dasd_psf_cuir_response),
5287 device);
5289 if (IS_ERR(cqr)) {
5290 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5291 "Could not allocate PSF-CUIR request");
5292 return PTR_ERR(cqr);
5295 psf_cuir = (struct dasd_psf_cuir_response *)cqr->data;
5296 psf_cuir->order = PSF_ORDER_CUIR_RESPONSE;
5297 psf_cuir->cc = response;
5298 psf_cuir->chpid = device->path[pos].chpid;
5299 psf_cuir->message_id = message_id;
5300 psf_cuir->cssid = device->path[pos].cssid;
5301 psf_cuir->ssid = device->path[pos].ssid;
5302 ccw = cqr->cpaddr;
5303 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5304 ccw->cda = (__u32)(addr_t)psf_cuir;
5305 ccw->flags = CCW_FLAG_SLI;
5306 ccw->count = sizeof(struct dasd_psf_cuir_response);
5308 cqr->startdev = device;
5309 cqr->memdev = device;
5310 cqr->block = NULL;
5311 cqr->retries = 256;
5312 cqr->expires = 10*HZ;
5313 cqr->buildclk = get_tod_clock();
5314 cqr->status = DASD_CQR_FILLED;
5315 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5317 rc = dasd_sleep_on(cqr);
5319 dasd_sfree_request(cqr, cqr->memdev);
5320 return rc;
5324 * return configuration data that is referenced by record selector
5325 * if a record selector is specified or per default return the
5326 * conf_data pointer for the path specified by lpum
5328 static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device,
5329 __u8 lpum,
5330 struct dasd_cuir_message *cuir)
5332 struct dasd_conf_data *conf_data;
5333 int path, pos;
5335 if (cuir->record_selector == 0)
5336 goto out;
5337 for (path = 0x80, pos = 0; path; path >>= 1, pos++) {
5338 conf_data = device->path[pos].conf_data;
5339 if (conf_data->gneq.record_selector ==
5340 cuir->record_selector)
5341 return conf_data;
5343 out:
5344 return device->path[pathmask_to_pos(lpum)].conf_data;
5348 * This function determines the scope of a reconfiguration request by
5349 * analysing the path and device selection data provided in the CUIR request.
5350 * Returns a path mask containing CUIR affected paths for the give device.
5352 * If the CUIR request does not contain the required information return the
5353 * path mask of the path the attention message for the CUIR request was reveived
5354 * on.
5356 static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum,
5357 struct dasd_cuir_message *cuir)
5359 struct dasd_conf_data *ref_conf_data;
5360 unsigned long bitmask = 0, mask = 0;
5361 struct dasd_conf_data *conf_data;
5362 unsigned int pos, path;
5363 char *ref_gneq, *gneq;
5364 char *ref_ned, *ned;
5365 int tbcpm = 0;
5367 /* if CUIR request does not specify the scope use the path
5368 the attention message was presented on */
5369 if (!cuir->ned_map ||
5370 !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2]))
5371 return lpum;
5373 /* get reference conf data */
5374 ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir);
5375 /* reference ned is determined by ned_map field */
5376 pos = 8 - ffs(cuir->ned_map);
5377 ref_ned = (char *)&ref_conf_data->neds[pos];
5378 ref_gneq = (char *)&ref_conf_data->gneq;
5379 /* transfer 24 bit neq_map to mask */
5380 mask = cuir->neq_map[2];
5381 mask |= cuir->neq_map[1] << 8;
5382 mask |= cuir->neq_map[0] << 16;
5384 for (path = 0; path < 8; path++) {
5385 /* initialise data per path */
5386 bitmask = mask;
5387 conf_data = device->path[path].conf_data;
5388 pos = 8 - ffs(cuir->ned_map);
5389 ned = (char *) &conf_data->neds[pos];
5390 /* compare reference ned and per path ned */
5391 if (memcmp(ref_ned, ned, sizeof(*ned)) != 0)
5392 continue;
5393 gneq = (char *)&conf_data->gneq;
5394 /* compare reference gneq and per_path gneq under
5395 24 bit mask where mask bit 0 equals byte 7 of
5396 the gneq and mask bit 24 equals byte 31 */
5397 while (bitmask) {
5398 pos = ffs(bitmask) - 1;
5399 if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1)
5400 != 0)
5401 break;
5402 clear_bit(pos, &bitmask);
5404 if (bitmask)
5405 continue;
5406 /* device and path match the reference values
5407 add path to CUIR scope */
5408 tbcpm |= 0x80 >> path;
5410 return tbcpm;
5413 static void dasd_eckd_cuir_notify_user(struct dasd_device *device,
5414 unsigned long paths, int action)
5416 int pos;
5418 while (paths) {
5419 /* get position of bit in mask */
5420 pos = 8 - ffs(paths);
5421 /* get channel path descriptor from this position */
5422 if (action == CUIR_QUIESCE)
5423 pr_warn("Service on the storage server caused path %x.%02x to go offline",
5424 device->path[pos].cssid,
5425 device->path[pos].chpid);
5426 else if (action == CUIR_RESUME)
5427 pr_info("Path %x.%02x is back online after service on the storage server",
5428 device->path[pos].cssid,
5429 device->path[pos].chpid);
5430 clear_bit(7 - pos, &paths);
5434 static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum,
5435 struct dasd_cuir_message *cuir)
5437 unsigned long tbcpm;
5439 tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir);
5440 /* nothing to do if path is not in use */
5441 if (!(dasd_path_get_opm(device) & tbcpm))
5442 return 0;
5443 if (!(dasd_path_get_opm(device) & ~tbcpm)) {
5444 /* no path would be left if the CUIR action is taken
5445 return error */
5446 return -EINVAL;
5448 /* remove device from operational path mask */
5449 dasd_path_remove_opm(device, tbcpm);
5450 dasd_path_add_cuirpm(device, tbcpm);
5451 return tbcpm;
5455 * walk through all devices and build a path mask to quiesce them
5456 * return an error if the last path to a device would be removed
5458 * if only part of the devices are quiesced and an error
5459 * occurs no onlining necessary, the storage server will
5460 * notify the already set offline devices again
5462 static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum,
5463 struct dasd_cuir_message *cuir)
5465 struct dasd_eckd_private *private = device->private;
5466 struct alias_pav_group *pavgroup, *tempgroup;
5467 struct dasd_device *dev, *n;
5468 unsigned long paths = 0;
5469 unsigned long flags;
5470 int tbcpm;
5472 /* active devices */
5473 list_for_each_entry_safe(dev, n, &private->lcu->active_devices,
5474 alias_list) {
5475 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5476 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5477 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5478 if (tbcpm < 0)
5479 goto out_err;
5480 paths |= tbcpm;
5482 /* inactive devices */
5483 list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices,
5484 alias_list) {
5485 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5486 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5487 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5488 if (tbcpm < 0)
5489 goto out_err;
5490 paths |= tbcpm;
5492 /* devices in PAV groups */
5493 list_for_each_entry_safe(pavgroup, tempgroup,
5494 &private->lcu->grouplist, group) {
5495 list_for_each_entry_safe(dev, n, &pavgroup->baselist,
5496 alias_list) {
5497 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5498 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5499 spin_unlock_irqrestore(
5500 get_ccwdev_lock(dev->cdev), flags);
5501 if (tbcpm < 0)
5502 goto out_err;
5503 paths |= tbcpm;
5505 list_for_each_entry_safe(dev, n, &pavgroup->aliaslist,
5506 alias_list) {
5507 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5508 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5509 spin_unlock_irqrestore(
5510 get_ccwdev_lock(dev->cdev), flags);
5511 if (tbcpm < 0)
5512 goto out_err;
5513 paths |= tbcpm;
5516 /* notify user about all paths affected by CUIR action */
5517 dasd_eckd_cuir_notify_user(device, paths, CUIR_QUIESCE);
5518 return 0;
5519 out_err:
5520 return tbcpm;
5523 static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum,
5524 struct dasd_cuir_message *cuir)
5526 struct dasd_eckd_private *private = device->private;
5527 struct alias_pav_group *pavgroup, *tempgroup;
5528 struct dasd_device *dev, *n;
5529 unsigned long paths = 0;
5530 int tbcpm;
5533 * the path may have been added through a generic path event before
5534 * only trigger path verification if the path is not already in use
5536 list_for_each_entry_safe(dev, n,
5537 &private->lcu->active_devices,
5538 alias_list) {
5539 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5540 paths |= tbcpm;
5541 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5542 dasd_path_add_tbvpm(dev, tbcpm);
5543 dasd_schedule_device_bh(dev);
5546 list_for_each_entry_safe(dev, n,
5547 &private->lcu->inactive_devices,
5548 alias_list) {
5549 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5550 paths |= tbcpm;
5551 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5552 dasd_path_add_tbvpm(dev, tbcpm);
5553 dasd_schedule_device_bh(dev);
5556 /* devices in PAV groups */
5557 list_for_each_entry_safe(pavgroup, tempgroup,
5558 &private->lcu->grouplist,
5559 group) {
5560 list_for_each_entry_safe(dev, n,
5561 &pavgroup->baselist,
5562 alias_list) {
5563 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5564 paths |= tbcpm;
5565 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5566 dasd_path_add_tbvpm(dev, tbcpm);
5567 dasd_schedule_device_bh(dev);
5570 list_for_each_entry_safe(dev, n,
5571 &pavgroup->aliaslist,
5572 alias_list) {
5573 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5574 paths |= tbcpm;
5575 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5576 dasd_path_add_tbvpm(dev, tbcpm);
5577 dasd_schedule_device_bh(dev);
5581 /* notify user about all paths affected by CUIR action */
5582 dasd_eckd_cuir_notify_user(device, paths, CUIR_RESUME);
5583 return 0;
5586 static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages,
5587 __u8 lpum)
5589 struct dasd_cuir_message *cuir = messages;
5590 int response;
5592 DBF_DEV_EVENT(DBF_WARNING, device,
5593 "CUIR request: %016llx %016llx %016llx %08x",
5594 ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2],
5595 ((u32 *)cuir)[3]);
5597 if (cuir->code == CUIR_QUIESCE) {
5598 /* quiesce */
5599 if (dasd_eckd_cuir_quiesce(device, lpum, cuir))
5600 response = PSF_CUIR_LAST_PATH;
5601 else
5602 response = PSF_CUIR_COMPLETED;
5603 } else if (cuir->code == CUIR_RESUME) {
5604 /* resume */
5605 dasd_eckd_cuir_resume(device, lpum, cuir);
5606 response = PSF_CUIR_COMPLETED;
5607 } else
5608 response = PSF_CUIR_NOT_SUPPORTED;
5610 dasd_eckd_psf_cuir_response(device, response,
5611 cuir->message_id, lpum);
5612 DBF_DEV_EVENT(DBF_WARNING, device,
5613 "CUIR response: %d on message ID %08x", response,
5614 cuir->message_id);
5615 /* to make sure there is no attention left schedule work again */
5616 device->discipline->check_attention(device, lpum);
5619 static void dasd_eckd_check_attention_work(struct work_struct *work)
5621 struct check_attention_work_data *data;
5622 struct dasd_rssd_messages *messages;
5623 struct dasd_device *device;
5624 int rc;
5626 data = container_of(work, struct check_attention_work_data, worker);
5627 device = data->device;
5628 messages = kzalloc(sizeof(*messages), GFP_KERNEL);
5629 if (!messages) {
5630 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5631 "Could not allocate attention message buffer");
5632 goto out;
5634 rc = dasd_eckd_read_message_buffer(device, messages, data->lpum);
5635 if (rc)
5636 goto out;
5637 if (messages->length == ATTENTION_LENGTH_CUIR &&
5638 messages->format == ATTENTION_FORMAT_CUIR)
5639 dasd_eckd_handle_cuir(device, messages, data->lpum);
5640 out:
5641 dasd_put_device(device);
5642 kfree(messages);
5643 kfree(data);
5646 static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum)
5648 struct check_attention_work_data *data;
5650 data = kzalloc(sizeof(*data), GFP_ATOMIC);
5651 if (!data)
5652 return -ENOMEM;
5653 INIT_WORK(&data->worker, dasd_eckd_check_attention_work);
5654 dasd_get_device(device);
5655 data->device = device;
5656 data->lpum = lpum;
5657 schedule_work(&data->worker);
5658 return 0;
5661 static int dasd_eckd_disable_hpf_path(struct dasd_device *device, __u8 lpum)
5663 if (~lpum & dasd_path_get_opm(device)) {
5664 dasd_path_add_nohpfpm(device, lpum);
5665 dasd_path_remove_opm(device, lpum);
5666 dev_err(&device->cdev->dev,
5667 "Channel path %02X lost HPF functionality and is disabled\n",
5668 lpum);
5669 return 1;
5671 return 0;
5674 static void dasd_eckd_disable_hpf_device(struct dasd_device *device)
5676 struct dasd_eckd_private *private = device->private;
5678 dev_err(&device->cdev->dev,
5679 "High Performance FICON disabled\n");
5680 private->fcx_max_data = 0;
5683 static int dasd_eckd_hpf_enabled(struct dasd_device *device)
5685 struct dasd_eckd_private *private = device->private;
5687 return private->fcx_max_data ? 1 : 0;
5690 static void dasd_eckd_handle_hpf_error(struct dasd_device *device,
5691 struct irb *irb)
5693 struct dasd_eckd_private *private = device->private;
5695 if (!private->fcx_max_data) {
5696 /* sanity check for no HPF, the error makes no sense */
5697 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5698 "Trying to disable HPF for a non HPF device");
5699 return;
5701 if (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX) {
5702 dasd_eckd_disable_hpf_device(device);
5703 } else if (irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX) {
5704 if (dasd_eckd_disable_hpf_path(device, irb->esw.esw1.lpum))
5705 return;
5706 dasd_eckd_disable_hpf_device(device);
5707 dasd_path_set_tbvpm(device,
5708 dasd_path_get_hpfpm(device));
5711 * prevent that any new I/O ist started on the device and schedule a
5712 * requeue of existing requests
5714 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
5715 dasd_schedule_requeue(device);
5718 static struct ccw_driver dasd_eckd_driver = {
5719 .driver = {
5720 .name = "dasd-eckd",
5721 .owner = THIS_MODULE,
5723 .ids = dasd_eckd_ids,
5724 .probe = dasd_eckd_probe,
5725 .remove = dasd_generic_remove,
5726 .set_offline = dasd_generic_set_offline,
5727 .set_online = dasd_eckd_set_online,
5728 .notify = dasd_generic_notify,
5729 .path_event = dasd_generic_path_event,
5730 .shutdown = dasd_generic_shutdown,
5731 .freeze = dasd_generic_pm_freeze,
5732 .thaw = dasd_generic_restore_device,
5733 .restore = dasd_generic_restore_device,
5734 .uc_handler = dasd_generic_uc_handler,
5735 .int_class = IRQIO_DAS,
5739 * max_blocks is dependent on the amount of storage that is available
5740 * in the static io buffer for each device. Currently each device has
5741 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5742 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5743 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5744 * addition we have one define extent ccw + 16 bytes of data and one
5745 * locate record ccw + 16 bytes of data. That makes:
5746 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5747 * We want to fit two into the available memory so that we can immediately
5748 * start the next request if one finishes off. That makes 249.5 blocks
5749 * for one request. Give a little safety and the result is 240.
5751 static struct dasd_discipline dasd_eckd_discipline = {
5752 .owner = THIS_MODULE,
5753 .name = "ECKD",
5754 .ebcname = "ECKD",
5755 .max_blocks = 190,
5756 .check_device = dasd_eckd_check_characteristics,
5757 .uncheck_device = dasd_eckd_uncheck_device,
5758 .do_analysis = dasd_eckd_do_analysis,
5759 .verify_path = dasd_eckd_verify_path,
5760 .basic_to_ready = dasd_eckd_basic_to_ready,
5761 .online_to_ready = dasd_eckd_online_to_ready,
5762 .basic_to_known = dasd_eckd_basic_to_known,
5763 .fill_geometry = dasd_eckd_fill_geometry,
5764 .start_IO = dasd_start_IO,
5765 .term_IO = dasd_term_IO,
5766 .handle_terminated_request = dasd_eckd_handle_terminated_request,
5767 .format_device = dasd_eckd_format_device,
5768 .check_device_format = dasd_eckd_check_device_format,
5769 .erp_action = dasd_eckd_erp_action,
5770 .erp_postaction = dasd_eckd_erp_postaction,
5771 .check_for_device_change = dasd_eckd_check_for_device_change,
5772 .build_cp = dasd_eckd_build_alias_cp,
5773 .free_cp = dasd_eckd_free_alias_cp,
5774 .dump_sense = dasd_eckd_dump_sense,
5775 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
5776 .fill_info = dasd_eckd_fill_info,
5777 .ioctl = dasd_eckd_ioctl,
5778 .freeze = dasd_eckd_pm_freeze,
5779 .restore = dasd_eckd_restore_device,
5780 .reload = dasd_eckd_reload_device,
5781 .get_uid = dasd_eckd_get_uid,
5782 .kick_validate = dasd_eckd_kick_validate_server,
5783 .check_attention = dasd_eckd_check_attention,
5784 .host_access_count = dasd_eckd_host_access_count,
5785 .hosts_print = dasd_hosts_print,
5786 .handle_hpf_error = dasd_eckd_handle_hpf_error,
5787 .disable_hpf = dasd_eckd_disable_hpf_device,
5788 .hpf_enabled = dasd_eckd_hpf_enabled,
5789 .reset_path = dasd_eckd_reset_path,
5792 static int __init
5793 dasd_eckd_init(void)
5795 int ret;
5797 ASCEBC(dasd_eckd_discipline.ebcname, 4);
5798 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
5799 GFP_KERNEL | GFP_DMA);
5800 if (!dasd_reserve_req)
5801 return -ENOMEM;
5802 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
5803 GFP_KERNEL | GFP_DMA);
5804 if (!path_verification_worker) {
5805 kfree(dasd_reserve_req);
5806 return -ENOMEM;
5808 rawpadpage = (void *)__get_free_page(GFP_KERNEL);
5809 if (!rawpadpage) {
5810 kfree(path_verification_worker);
5811 kfree(dasd_reserve_req);
5812 return -ENOMEM;
5814 ret = ccw_driver_register(&dasd_eckd_driver);
5815 if (!ret)
5816 wait_for_device_probe();
5817 else {
5818 kfree(path_verification_worker);
5819 kfree(dasd_reserve_req);
5820 free_page((unsigned long)rawpadpage);
5822 return ret;
5825 static void __exit
5826 dasd_eckd_cleanup(void)
5828 ccw_driver_unregister(&dasd_eckd_driver);
5829 kfree(path_verification_worker);
5830 kfree(dasd_reserve_req);
5831 free_page((unsigned long)rawpadpage);
5834 module_init(dasd_eckd_init);
5835 module_exit(dasd_eckd_cleanup);