2 * File...........: linux/drivers/s390/block/dasd_eckd.c
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 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/hdreg.h> /* HDIO_GETGEO */
16 #include <linux/bio.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
20 #include <asm/debug.h>
21 #include <asm/idals.h>
22 #include <asm/ebcdic.h>
24 #include <asm/todclk.h>
25 #include <asm/uaccess.h>
27 #include <asm/ccwdev.h>
30 #include "dasd_eckd.h"
34 #endif /* PRINTK_HEADER */
35 #define PRINTK_HEADER "dasd(eckd):"
37 #define ECKD_C0(i) (i->home_bytes)
38 #define ECKD_F(i) (i->formula)
39 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
40 (i->factors.f_0x02.f1))
41 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
42 (i->factors.f_0x02.f2))
43 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
44 (i->factors.f_0x02.f3))
45 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
46 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
47 #define ECKD_F6(i) (i->factor6)
48 #define ECKD_F7(i) (i->factor7)
49 #define ECKD_F8(i) (i->factor8)
51 MODULE_LICENSE("GPL");
53 static struct dasd_discipline dasd_eckd_discipline
;
55 struct dasd_eckd_private
{
56 struct dasd_eckd_characteristics rdc_data
;
57 struct dasd_eckd_confdata conf_data
;
58 struct dasd_eckd_path path_data
;
59 struct eckd_count count_area
[5];
62 struct attrib_data_t attrib
; /* e.g. cache operations */
65 /* The ccw bus type uses this table to find devices that it sends to
67 static struct ccw_device_id dasd_eckd_ids
[] = {
68 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info
= 0x1},
69 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info
= 0x2},
70 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info
= 0x3},
71 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info
= 0x4},
72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info
= 0x5},
73 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info
= 0x6},
74 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info
= 0x7},
75 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info
= 0x8},
76 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info
= 0x9},
77 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info
= 0xa},
78 { /* end of list */ },
81 MODULE_DEVICE_TABLE(ccw
, dasd_eckd_ids
);
83 static struct ccw_driver dasd_eckd_driver
; /* see below */
85 /* initial attempt at a probe function. this can be simplified once
86 * the other detection code is gone */
88 dasd_eckd_probe (struct ccw_device
*cdev
)
92 /* set ECKD specific ccw-device options */
93 ret
= ccw_device_set_options(cdev
, CCWDEV_ALLOW_FORCE
);
96 "dasd_eckd_probe: could not set ccw-device options "
97 "for %s\n", cdev
->dev
.bus_id
);
100 ret
= dasd_generic_probe(cdev
, &dasd_eckd_discipline
);
105 dasd_eckd_set_online(struct ccw_device
*cdev
)
107 return dasd_generic_set_online(cdev
, &dasd_eckd_discipline
);
110 static struct ccw_driver dasd_eckd_driver
= {
112 .owner
= THIS_MODULE
,
113 .ids
= dasd_eckd_ids
,
114 .probe
= dasd_eckd_probe
,
115 .remove
= dasd_generic_remove
,
116 .set_offline
= dasd_generic_set_offline
,
117 .set_online
= dasd_eckd_set_online
,
118 .notify
= dasd_generic_notify
,
121 static const int sizes_trk0
[] = { 28, 148, 84 };
122 #define LABEL_SIZE 140
124 static inline unsigned int
125 round_up_multiple(unsigned int no
, unsigned int mult
)
128 return (rem
? no
- rem
+ mult
: no
);
131 static inline unsigned int
132 ceil_quot(unsigned int d1
, unsigned int d2
)
134 return (d1
+ (d2
- 1)) / d2
;
138 bytes_per_record(struct dasd_eckd_characteristics
*rdc
, int kl
, int dl
)
140 unsigned int fl1
, fl2
, int1
, int2
;
143 switch (rdc
->formula
) {
145 fl1
= round_up_multiple(ECKD_F2(rdc
) + dl
, ECKD_F1(rdc
));
146 fl2
= round_up_multiple(kl
? ECKD_F2(rdc
) + kl
: 0,
151 int1
= ceil_quot(dl
+ ECKD_F6(rdc
), ECKD_F5(rdc
) << 1);
152 int2
= ceil_quot(kl
+ ECKD_F6(rdc
), ECKD_F5(rdc
) << 1);
153 fl1
= round_up_multiple(ECKD_F1(rdc
) * ECKD_F2(rdc
) + dl
+
154 ECKD_F6(rdc
) + ECKD_F4(rdc
) * int1
,
156 fl2
= round_up_multiple(ECKD_F1(rdc
) * ECKD_F3(rdc
) + kl
+
157 ECKD_F6(rdc
) + ECKD_F4(rdc
) * int2
,
168 static inline unsigned int
169 bytes_per_track(struct dasd_eckd_characteristics
*rdc
)
171 return *(unsigned int *) (rdc
->byte_per_track
) >> 8;
174 static inline unsigned int
175 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
176 unsigned int kl
, unsigned int dl
)
180 switch (rdc
->dev_type
) {
183 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
184 ceil_quot(dl
+ 12, 32));
186 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
188 dn
= ceil_quot(dl
+ 6, 232) + 1;
190 kn
= ceil_quot(kl
+ 6, 232) + 1;
191 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
192 9 + ceil_quot(dl
+ 6 * dn
, 34));
194 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
196 dn
= ceil_quot(dl
+ 6, 232) + 1;
198 kn
= ceil_quot(kl
+ 6, 232) + 1;
199 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
200 ceil_quot(dl
+ 6 * dn
, 34));
202 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
208 check_XRC (struct ccw1
*de_ccw
,
209 struct DE_eckd_data
*data
,
210 struct dasd_device
*device
)
212 struct dasd_eckd_private
*private;
214 private = (struct dasd_eckd_private
*) device
->private;
216 /* switch on System Time Stamp - needed for XRC Support */
217 if (private->rdc_data
.facilities
.XRC_supported
) {
219 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
220 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
222 data
->ep_sys_time
= get_clock ();
224 de_ccw
->count
= sizeof (struct DE_eckd_data
);
225 de_ccw
->flags
|= CCW_FLAG_SLI
;
230 } /* end check_XRC */
233 define_extent(struct ccw1
* ccw
, struct DE_eckd_data
* data
, int trk
,
234 int totrk
, int cmd
, struct dasd_device
* device
)
236 struct dasd_eckd_private
*private;
237 struct ch_t geo
, beg
, end
;
239 private = (struct dasd_eckd_private
*) device
->private;
241 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
244 ccw
->cda
= (__u32
) __pa(data
);
246 memset(data
, 0, sizeof (struct DE_eckd_data
));
248 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
249 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
250 case DASD_ECKD_CCW_READ
:
251 case DASD_ECKD_CCW_READ_MT
:
252 case DASD_ECKD_CCW_READ_CKD
:
253 case DASD_ECKD_CCW_READ_CKD_MT
:
254 case DASD_ECKD_CCW_READ_KD
:
255 case DASD_ECKD_CCW_READ_KD_MT
:
256 case DASD_ECKD_CCW_READ_COUNT
:
257 data
->mask
.perm
= 0x1;
258 data
->attributes
.operation
= private->attrib
.operation
;
260 case DASD_ECKD_CCW_WRITE
:
261 case DASD_ECKD_CCW_WRITE_MT
:
262 case DASD_ECKD_CCW_WRITE_KD
:
263 case DASD_ECKD_CCW_WRITE_KD_MT
:
264 data
->mask
.perm
= 0x02;
265 data
->attributes
.operation
= private->attrib
.operation
;
266 check_XRC (ccw
, data
, device
);
268 case DASD_ECKD_CCW_WRITE_CKD
:
269 case DASD_ECKD_CCW_WRITE_CKD_MT
:
270 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
271 check_XRC (ccw
, data
, device
);
273 case DASD_ECKD_CCW_ERASE
:
274 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
275 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
276 data
->mask
.perm
= 0x3;
277 data
->mask
.auth
= 0x1;
278 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
279 check_XRC (ccw
, data
, device
);
282 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
286 data
->attributes
.mode
= 0x3; /* ECKD */
288 if ((private->rdc_data
.cu_type
== 0x2105 ||
289 private->rdc_data
.cu_type
== 0x2107 ||
290 private->rdc_data
.cu_type
== 0x1750)
291 && !(private->uses_cdl
&& trk
< 2))
292 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
294 geo
.cyl
= private->rdc_data
.no_cyl
;
295 geo
.head
= private->rdc_data
.trk_per_cyl
;
296 beg
.cyl
= trk
/ geo
.head
;
297 beg
.head
= trk
% geo
.head
;
298 end
.cyl
= totrk
/ geo
.head
;
299 end
.head
= totrk
% geo
.head
;
301 /* check for sequential prestage - enhance cylinder range */
302 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
303 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
305 if (end
.cyl
+ private->attrib
.nr_cyl
< geo
.cyl
)
306 end
.cyl
+= private->attrib
.nr_cyl
;
308 end
.cyl
= (geo
.cyl
- 1);
311 data
->beg_ext
.cyl
= beg
.cyl
;
312 data
->beg_ext
.head
= beg
.head
;
313 data
->end_ext
.cyl
= end
.cyl
;
314 data
->end_ext
.head
= end
.head
;
318 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, int trk
,
319 int rec_on_trk
, int no_rec
, int cmd
,
320 struct dasd_device
* device
, int reclen
)
322 struct dasd_eckd_private
*private;
326 private = (struct dasd_eckd_private
*) device
->private;
328 DBF_DEV_EVENT(DBF_INFO
, device
,
329 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
330 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
332 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
335 ccw
->cda
= (__u32
) __pa(data
);
337 memset(data
, 0, sizeof (struct LO_eckd_data
));
340 switch (private->rdc_data
.dev_type
) {
342 dn
= ceil_quot(reclen
+ 6, 232);
343 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
344 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
347 d
= 7 + ceil_quot(reclen
+ 12, 32);
348 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
352 data
->sector
= sector
;
353 data
->count
= no_rec
;
355 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
356 data
->operation
.orientation
= 0x3;
357 data
->operation
.operation
= 0x03;
359 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
360 data
->operation
.orientation
= 0x3;
361 data
->operation
.operation
= 0x16;
363 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
364 data
->operation
.orientation
= 0x1;
365 data
->operation
.operation
= 0x03;
368 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
369 data
->operation
.orientation
= 0x3;
370 data
->operation
.operation
= 0x16;
373 case DASD_ECKD_CCW_WRITE
:
374 case DASD_ECKD_CCW_WRITE_MT
:
375 case DASD_ECKD_CCW_WRITE_KD
:
376 case DASD_ECKD_CCW_WRITE_KD_MT
:
377 data
->auxiliary
.last_bytes_used
= 0x1;
378 data
->length
= reclen
;
379 data
->operation
.operation
= 0x01;
381 case DASD_ECKD_CCW_WRITE_CKD
:
382 case DASD_ECKD_CCW_WRITE_CKD_MT
:
383 data
->auxiliary
.last_bytes_used
= 0x1;
384 data
->length
= reclen
;
385 data
->operation
.operation
= 0x03;
387 case DASD_ECKD_CCW_READ
:
388 case DASD_ECKD_CCW_READ_MT
:
389 case DASD_ECKD_CCW_READ_KD
:
390 case DASD_ECKD_CCW_READ_KD_MT
:
391 data
->auxiliary
.last_bytes_used
= 0x1;
392 data
->length
= reclen
;
393 data
->operation
.operation
= 0x06;
395 case DASD_ECKD_CCW_READ_CKD
:
396 case DASD_ECKD_CCW_READ_CKD_MT
:
397 data
->auxiliary
.last_bytes_used
= 0x1;
398 data
->length
= reclen
;
399 data
->operation
.operation
= 0x16;
401 case DASD_ECKD_CCW_READ_COUNT
:
402 data
->operation
.operation
= 0x06;
404 case DASD_ECKD_CCW_ERASE
:
405 data
->length
= reclen
;
406 data
->auxiliary
.last_bytes_used
= 0x1;
407 data
->operation
.operation
= 0x0b;
410 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
412 data
->seek_addr
.cyl
= data
->search_arg
.cyl
=
413 trk
/ private->rdc_data
.trk_per_cyl
;
414 data
->seek_addr
.head
= data
->search_arg
.head
=
415 trk
% private->rdc_data
.trk_per_cyl
;
416 data
->search_arg
.record
= rec_on_trk
;
420 * Returns 1 if the block is one of the special blocks that needs
421 * to get read/written with the KD variant of the command.
422 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
423 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
424 * Luckily the KD variants differ only by one bit (0x08) from the
425 * normal variant. So don't wonder about code like:
426 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
427 * ccw->cmd_code |= 0x8;
430 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
434 if (recid
< blk_per_trk
)
436 if (recid
< 2 * blk_per_trk
)
442 * Returns the record size for the special blocks of the cdl format.
443 * Only returns something useful if dasd_eckd_cdl_special is true
447 dasd_eckd_cdl_reclen(int recid
)
450 return sizes_trk0
[recid
];
455 * Generate device unique id that specifies the physical device.
458 dasd_eckd_generate_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
460 struct dasd_eckd_private
*private;
461 struct dasd_eckd_confdata
*confdata
;
463 private = (struct dasd_eckd_private
*) device
->private;
466 confdata
= &private->conf_data
;
470 memset(uid
, 0, sizeof(struct dasd_uid
));
471 memcpy(uid
->vendor
, confdata
->ned1
.HDA_manufacturer
,
472 sizeof(uid
->vendor
) - 1);
473 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
474 memcpy(uid
->serial
, confdata
->ned1
.HDA_location
,
475 sizeof(uid
->serial
) - 1);
476 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
477 uid
->ssid
= confdata
->neq
.subsystemID
;
478 if (confdata
->ned2
.sneq
.flags
== 0x40) {
480 uid
->unit_addr
= confdata
->ned2
.sneq
.base_unit_addr
;
482 uid
->unit_addr
= confdata
->ned1
.unit_addr
;
488 dasd_eckd_read_conf(struct dasd_device
*device
)
491 int conf_len
, conf_data_saved
;
494 struct dasd_eckd_private
*private;
495 struct dasd_eckd_path
*path_data
;
497 private = (struct dasd_eckd_private
*) device
->private;
498 path_data
= (struct dasd_eckd_path
*) &private->path_data
;
499 path_data
->opm
= ccw_device_get_path_mask(device
->cdev
);
503 /* get configuration data per operational path */
504 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
505 if (lpm
& path_data
->opm
){
506 rc
= read_conf_data_lpm(device
->cdev
, &conf_data
,
508 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
509 MESSAGE(KERN_WARNING
,
510 "Read configuration data returned "
514 if (conf_data
== NULL
) {
515 MESSAGE(KERN_WARNING
, "%s", "No configuration "
517 continue; /* no errror */
519 if (conf_len
!= sizeof (struct dasd_eckd_confdata
)) {
520 MESSAGE(KERN_WARNING
,
521 "sizes of configuration data mismatch"
522 "%d (read) vs %ld (expected)",
524 sizeof (struct dasd_eckd_confdata
));
526 continue; /* no errror */
528 /* save first valid configuration data */
529 if (!conf_data_saved
){
530 memcpy(&private->conf_data
, conf_data
,
531 sizeof (struct dasd_eckd_confdata
));
534 switch (((char *)conf_data
)[242] & 0x07){
536 path_data
->npm
|= lpm
;
539 path_data
->ppm
|= lpm
;
549 * Build CP for Perform Subsystem Function - SSC.
551 struct dasd_ccw_req
*
552 dasd_eckd_build_psf_ssc(struct dasd_device
*device
)
554 struct dasd_ccw_req
*cqr
;
555 struct dasd_psf_ssc_data
*psf_ssc_data
;
558 cqr
= dasd_smalloc_request("ECKD", 1 /* PSF */ ,
559 sizeof(struct dasd_psf_ssc_data
),
563 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
564 "Could not allocate PSF-SSC request");
567 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
568 psf_ssc_data
->order
= PSF_ORDER_SSC
;
569 psf_ssc_data
->suborder
= 0x08;
572 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
573 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
576 cqr
->device
= device
;
577 cqr
->expires
= 10*HZ
;
578 cqr
->buildclk
= get_clock();
579 cqr
->status
= DASD_CQR_FILLED
;
584 * Perform Subsystem Function.
585 * It is necessary to trigger CIO for channel revalidation since this
586 * call might change behaviour of DASD devices.
589 dasd_eckd_psf_ssc(struct dasd_device
*device
)
591 struct dasd_ccw_req
*cqr
;
594 cqr
= dasd_eckd_build_psf_ssc(device
);
598 rc
= dasd_sleep_on(cqr
);
600 /* trigger CIO to reprobe devices */
601 css_schedule_reprobe();
602 dasd_sfree_request(cqr
, cqr
->device
);
607 * Valide storage server of current device.
610 dasd_eckd_validate_server(struct dasd_device
*device
, struct dasd_uid
*uid
)
614 /* Currently PAV is the only reason to 'validate' server on LPAR */
615 if (dasd_nopav
|| MACHINE_IS_VM
)
618 rc
= dasd_eckd_psf_ssc(device
);
619 /* may be requested feature is not available on server,
620 * therefore just report error and go ahead */
621 DEV_MESSAGE(KERN_INFO
, device
,
622 "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
623 uid
->vendor
, uid
->serial
, uid
->ssid
, rc
);
624 /* RE-Read Configuration Data */
625 return dasd_eckd_read_conf(device
);
629 * Check device characteristics.
630 * If the device is accessible using ECKD discipline, the device is enabled.
633 dasd_eckd_check_characteristics(struct dasd_device
*device
)
635 struct dasd_eckd_private
*private;
640 private = (struct dasd_eckd_private
*) device
->private;
641 if (private == NULL
) {
642 private = kzalloc(sizeof(struct dasd_eckd_private
),
643 GFP_KERNEL
| GFP_DMA
);
644 if (private == NULL
) {
645 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
646 "memory allocation failed for private "
650 device
->private = (void *) private;
652 /* Invalidate status of initial analysis. */
653 private->init_cqr_status
= -1;
654 /* Set default cache operations. */
655 private->attrib
.operation
= DASD_NORMAL_CACHE
;
656 private->attrib
.nr_cyl
= 0;
658 /* Read Configuration Data */
659 rc
= dasd_eckd_read_conf(device
);
663 /* Generate device unique id and register in devmap */
664 rc
= dasd_eckd_generate_uid(device
, &uid
);
667 rc
= dasd_set_uid(device
->cdev
, &uid
);
668 if (rc
== 1) /* new server found */
669 rc
= dasd_eckd_validate_server(device
, &uid
);
673 /* Read Device Characteristics */
674 rdc_data
= (void *) &(private->rdc_data
);
675 memset(rdc_data
, 0, sizeof(rdc_data
));
676 rc
= read_dev_chars(device
->cdev
, &rdc_data
, 64);
678 DEV_MESSAGE(KERN_WARNING
, device
,
679 "Read device characteristics returned "
682 DEV_MESSAGE(KERN_INFO
, device
,
683 "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
684 private->rdc_data
.dev_type
,
685 private->rdc_data
.dev_model
,
686 private->rdc_data
.cu_type
,
687 private->rdc_data
.cu_model
.model
,
688 private->rdc_data
.no_cyl
,
689 private->rdc_data
.trk_per_cyl
,
690 private->rdc_data
.sec_per_trk
);
694 static struct dasd_ccw_req
*
695 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
697 struct dasd_eckd_private
*private;
698 struct eckd_count
*count_data
;
699 struct LO_eckd_data
*LO_data
;
700 struct dasd_ccw_req
*cqr
;
702 int cplength
, datasize
;
705 private = (struct dasd_eckd_private
*) device
->private;
708 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
709 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
710 cplength
, datasize
, device
);
714 /* Define extent for the first 3 tracks. */
715 define_extent(ccw
++, cqr
->data
, 0, 2,
716 DASD_ECKD_CCW_READ_COUNT
, device
);
717 LO_data
= cqr
->data
+ sizeof (struct DE_eckd_data
);
718 /* Locate record for the first 4 records on track 0. */
719 ccw
[-1].flags
|= CCW_FLAG_CC
;
720 locate_record(ccw
++, LO_data
++, 0, 0, 4,
721 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
723 count_data
= private->count_area
;
724 for (i
= 0; i
< 4; i
++) {
725 ccw
[-1].flags
|= CCW_FLAG_CC
;
726 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
729 ccw
->cda
= (__u32
)(addr_t
) count_data
;
734 /* Locate record for the first record on track 2. */
735 ccw
[-1].flags
|= CCW_FLAG_CC
;
736 locate_record(ccw
++, LO_data
++, 2, 0, 1,
737 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
738 /* Read count ccw. */
739 ccw
[-1].flags
|= CCW_FLAG_CC
;
740 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
743 ccw
->cda
= (__u32
)(addr_t
) count_data
;
745 cqr
->device
= device
;
747 cqr
->buildclk
= get_clock();
748 cqr
->status
= DASD_CQR_FILLED
;
753 * This is the callback function for the init_analysis cqr. It saves
754 * the status of the initial analysis ccw before it frees it and kicks
755 * the device to continue the startup sequence. This will call
756 * dasd_eckd_do_analysis again (if the devices has not been marked
757 * for deletion in the meantime).
760 dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
, void *data
)
762 struct dasd_eckd_private
*private;
763 struct dasd_device
*device
;
765 device
= init_cqr
->device
;
766 private = (struct dasd_eckd_private
*) device
->private;
767 private->init_cqr_status
= init_cqr
->status
;
768 dasd_sfree_request(init_cqr
, device
);
769 dasd_kick_device(device
);
773 dasd_eckd_start_analysis(struct dasd_device
*device
)
775 struct dasd_eckd_private
*private;
776 struct dasd_ccw_req
*init_cqr
;
778 private = (struct dasd_eckd_private
*) device
->private;
779 init_cqr
= dasd_eckd_analysis_ccw(device
);
780 if (IS_ERR(init_cqr
))
781 return PTR_ERR(init_cqr
);
782 init_cqr
->callback
= dasd_eckd_analysis_callback
;
783 init_cqr
->callback_data
= NULL
;
784 init_cqr
->expires
= 5*HZ
;
785 dasd_add_request_head(init_cqr
);
790 dasd_eckd_end_analysis(struct dasd_device
*device
)
792 struct dasd_eckd_private
*private;
793 struct eckd_count
*count_area
;
794 unsigned int sb
, blk_per_trk
;
797 private = (struct dasd_eckd_private
*) device
->private;
798 status
= private->init_cqr_status
;
799 private->init_cqr_status
= -1;
800 if (status
!= DASD_CQR_DONE
) {
801 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
802 "volume analysis returned unformatted disk");
806 private->uses_cdl
= 1;
807 /* Calculate number of blocks/records per track. */
808 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, device
->bp_block
);
809 /* Check Track 0 for Compatible Disk Layout */
811 for (i
= 0; i
< 3; i
++) {
812 if (private->count_area
[i
].kl
!= 4 ||
813 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4) {
814 private->uses_cdl
= 0;
819 count_area
= &private->count_area
[4];
821 if (private->uses_cdl
== 0) {
822 for (i
= 0; i
< 5; i
++) {
823 if ((private->count_area
[i
].kl
!= 0) ||
824 (private->count_area
[i
].dl
!=
825 private->count_area
[0].dl
))
829 count_area
= &private->count_area
[0];
831 if (private->count_area
[3].record
== 1)
832 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
833 "Trk 0: no records after VTOC!");
835 if (count_area
!= NULL
&& count_area
->kl
== 0) {
836 /* we found notthing violating our disk layout */
837 if (dasd_check_blocksize(count_area
->dl
) == 0)
838 device
->bp_block
= count_area
->dl
;
840 if (device
->bp_block
== 0) {
841 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
842 "Volume has incompatible disk layout");
845 device
->s2b_shift
= 0; /* bits to shift 512 to get a block */
846 for (sb
= 512; sb
< device
->bp_block
; sb
= sb
<< 1)
849 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, device
->bp_block
);
850 device
->blocks
= (private->rdc_data
.no_cyl
*
851 private->rdc_data
.trk_per_cyl
*
854 DEV_MESSAGE(KERN_INFO
, device
,
855 "(%dkB blks): %dkB at %dkB/trk %s",
856 (device
->bp_block
>> 10),
857 ((private->rdc_data
.no_cyl
*
858 private->rdc_data
.trk_per_cyl
*
859 blk_per_trk
* (device
->bp_block
>> 9)) >> 1),
860 ((blk_per_trk
* device
->bp_block
) >> 10),
862 "compatible disk layout" : "linux disk layout");
868 dasd_eckd_do_analysis(struct dasd_device
*device
)
870 struct dasd_eckd_private
*private;
872 private = (struct dasd_eckd_private
*) device
->private;
873 if (private->init_cqr_status
< 0)
874 return dasd_eckd_start_analysis(device
);
876 return dasd_eckd_end_analysis(device
);
880 dasd_eckd_fill_geometry(struct dasd_device
*device
, struct hd_geometry
*geo
)
882 struct dasd_eckd_private
*private;
884 private = (struct dasd_eckd_private
*) device
->private;
885 if (dasd_check_blocksize(device
->bp_block
) == 0) {
886 geo
->sectors
= recs_per_track(&private->rdc_data
,
887 0, device
->bp_block
);
889 geo
->cylinders
= private->rdc_data
.no_cyl
;
890 geo
->heads
= private->rdc_data
.trk_per_cyl
;
894 static struct dasd_ccw_req
*
895 dasd_eckd_format_device(struct dasd_device
* device
,
896 struct format_data_t
* fdata
)
898 struct dasd_eckd_private
*private;
899 struct dasd_ccw_req
*fcp
;
900 struct eckd_count
*ect
;
904 int cplength
, datasize
;
907 private = (struct dasd_eckd_private
*) device
->private;
908 rpt
= recs_per_track(&private->rdc_data
, 0, fdata
->blksize
);
909 cyl
= fdata
->start_unit
/ private->rdc_data
.trk_per_cyl
;
910 head
= fdata
->start_unit
% private->rdc_data
.trk_per_cyl
;
913 if (fdata
->start_unit
>=
914 (private->rdc_data
.no_cyl
* private->rdc_data
.trk_per_cyl
)) {
915 DEV_MESSAGE(KERN_INFO
, device
, "Track no %d too big!",
917 return ERR_PTR(-EINVAL
);
919 if (fdata
->start_unit
> fdata
->stop_unit
) {
920 DEV_MESSAGE(KERN_INFO
, device
, "Track %d reached! ending.",
922 return ERR_PTR(-EINVAL
);
924 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
925 DEV_MESSAGE(KERN_WARNING
, device
,
926 "Invalid blocksize %d...terminating!",
928 return ERR_PTR(-EINVAL
);
932 * fdata->intensity is a bit string that tells us what to do:
933 * Bit 0: write record zero
934 * Bit 1: write home address, currently not supported
935 * Bit 2: invalidate tracks
936 * Bit 3: use OS/390 compatible disk layout (cdl)
937 * Only some bit combinations do make sense.
939 switch (fdata
->intensity
) {
940 case 0x00: /* Normal format */
941 case 0x08: /* Normal format, use cdl. */
943 datasize
= sizeof(struct DE_eckd_data
) +
944 sizeof(struct LO_eckd_data
) +
945 rpt
* sizeof(struct eckd_count
);
947 case 0x01: /* Write record zero and format track. */
948 case 0x09: /* Write record zero and format track, use cdl. */
950 datasize
= sizeof(struct DE_eckd_data
) +
951 sizeof(struct LO_eckd_data
) +
952 sizeof(struct eckd_count
) +
953 rpt
* sizeof(struct eckd_count
);
955 case 0x04: /* Invalidate track. */
956 case 0x0c: /* Invalidate track, use cdl. */
958 datasize
= sizeof(struct DE_eckd_data
) +
959 sizeof(struct LO_eckd_data
) +
960 sizeof(struct eckd_count
);
963 DEV_MESSAGE(KERN_WARNING
, device
, "Invalid flags 0x%x.",
965 return ERR_PTR(-EINVAL
);
967 /* Allocate the format ccw request. */
968 fcp
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
969 cplength
, datasize
, device
);
976 switch (fdata
->intensity
& ~0x08) {
977 case 0x00: /* Normal format. */
978 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
979 fdata
->start_unit
, fdata
->start_unit
,
980 DASD_ECKD_CCW_WRITE_CKD
, device
);
981 data
+= sizeof(struct DE_eckd_data
);
982 ccw
[-1].flags
|= CCW_FLAG_CC
;
983 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
984 fdata
->start_unit
, 0, rpt
,
985 DASD_ECKD_CCW_WRITE_CKD
, device
,
987 data
+= sizeof(struct LO_eckd_data
);
989 case 0x01: /* Write record zero + format track. */
990 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
991 fdata
->start_unit
, fdata
->start_unit
,
992 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
994 data
+= sizeof(struct DE_eckd_data
);
995 ccw
[-1].flags
|= CCW_FLAG_CC
;
996 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
997 fdata
->start_unit
, 0, rpt
+ 1,
998 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, device
,
1000 data
+= sizeof(struct LO_eckd_data
);
1002 case 0x04: /* Invalidate track. */
1003 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
1004 fdata
->start_unit
, fdata
->start_unit
,
1005 DASD_ECKD_CCW_WRITE_CKD
, device
);
1006 data
+= sizeof(struct DE_eckd_data
);
1007 ccw
[-1].flags
|= CCW_FLAG_CC
;
1008 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
1009 fdata
->start_unit
, 0, 1,
1010 DASD_ECKD_CCW_WRITE_CKD
, device
, 8);
1011 data
+= sizeof(struct LO_eckd_data
);
1014 if (fdata
->intensity
& 0x01) { /* write record zero */
1015 ect
= (struct eckd_count
*) data
;
1016 data
+= sizeof(struct eckd_count
);
1022 ccw
[-1].flags
|= CCW_FLAG_CC
;
1023 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
1024 ccw
->flags
= CCW_FLAG_SLI
;
1026 ccw
->cda
= (__u32
)(addr_t
) ect
;
1029 if ((fdata
->intensity
& ~0x08) & 0x04) { /* erase track */
1030 ect
= (struct eckd_count
*) data
;
1031 data
+= sizeof(struct eckd_count
);
1037 ccw
[-1].flags
|= CCW_FLAG_CC
;
1038 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
1039 ccw
->flags
= CCW_FLAG_SLI
;
1041 ccw
->cda
= (__u32
)(addr_t
) ect
;
1042 } else { /* write remaining records */
1043 for (i
= 0; i
< rpt
; i
++) {
1044 ect
= (struct eckd_count
*) data
;
1045 data
+= sizeof(struct eckd_count
);
1048 ect
->record
= i
+ 1;
1050 ect
->dl
= fdata
->blksize
;
1051 /* Check for special tracks 0-1 when formatting CDL */
1052 if ((fdata
->intensity
& 0x08) &&
1053 fdata
->start_unit
== 0) {
1056 ect
->dl
= sizes_trk0
[i
] - 4;
1059 if ((fdata
->intensity
& 0x08) &&
1060 fdata
->start_unit
== 1) {
1062 ect
->dl
= LABEL_SIZE
- 44;
1064 ccw
[-1].flags
|= CCW_FLAG_CC
;
1065 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
1066 ccw
->flags
= CCW_FLAG_SLI
;
1068 ccw
->cda
= (__u32
)(addr_t
) ect
;
1072 fcp
->device
= device
;
1073 fcp
->retries
= 2; /* set retry counter to enable ERP */
1074 fcp
->buildclk
= get_clock();
1075 fcp
->status
= DASD_CQR_FILLED
;
1080 dasd_eckd_examine_error(struct dasd_ccw_req
* cqr
, struct irb
* irb
)
1082 struct dasd_device
*device
= (struct dasd_device
*) cqr
->device
;
1083 struct ccw_device
*cdev
= device
->cdev
;
1085 if (irb
->scsw
.cstat
== 0x00 &&
1086 irb
->scsw
.dstat
== (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
))
1087 return dasd_era_none
;
1089 switch (cdev
->id
.cu_type
) {
1094 return dasd_3990_erp_examine(cqr
, irb
);
1096 return dasd_9343_erp_examine(cqr
, irb
);
1099 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1100 "default (unknown CU type) - RECOVERABLE return");
1101 return dasd_era_recover
;
1105 static dasd_erp_fn_t
1106 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
1108 struct dasd_device
*device
= (struct dasd_device
*) cqr
->device
;
1109 struct ccw_device
*cdev
= device
->cdev
;
1111 switch (cdev
->id
.cu_type
) {
1116 return dasd_3990_erp_action
;
1120 return dasd_default_erp_action
;
1124 static dasd_erp_fn_t
1125 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
1127 return dasd_default_erp_postaction
;
1130 static struct dasd_ccw_req
*
1131 dasd_eckd_build_cp(struct dasd_device
* device
, struct request
*req
)
1133 struct dasd_eckd_private
*private;
1134 unsigned long *idaws
;
1135 struct LO_eckd_data
*LO_data
;
1136 struct dasd_ccw_req
*cqr
;
1141 unsigned int blksize
, blk_per_trk
, off
;
1142 int count
, cidaw
, cplength
, datasize
;
1143 sector_t recid
, first_rec
, last_rec
;
1144 sector_t first_trk
, last_trk
;
1145 unsigned int first_offs
, last_offs
;
1146 unsigned char cmd
, rcmd
;
1149 private = (struct dasd_eckd_private
*) device
->private;
1150 if (rq_data_dir(req
) == READ
)
1151 cmd
= DASD_ECKD_CCW_READ_MT
;
1152 else if (rq_data_dir(req
) == WRITE
)
1153 cmd
= DASD_ECKD_CCW_WRITE_MT
;
1155 return ERR_PTR(-EINVAL
);
1156 /* Calculate number of blocks/records per track. */
1157 blksize
= device
->bp_block
;
1158 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1159 /* Calculate record id of first and last block. */
1160 first_rec
= first_trk
= req
->sector
>> device
->s2b_shift
;
1161 first_offs
= sector_div(first_trk
, blk_per_trk
);
1162 last_rec
= last_trk
=
1163 (req
->sector
+ req
->nr_sectors
- 1) >> device
->s2b_shift
;
1164 last_offs
= sector_div(last_trk
, blk_per_trk
);
1165 /* Check struct bio and count the number of blocks for the request. */
1168 rq_for_each_bio(bio
, req
) {
1169 bio_for_each_segment(bv
, bio
, i
) {
1170 if (bv
->bv_len
& (blksize
- 1))
1171 /* Eckd can only do full blocks. */
1172 return ERR_PTR(-EINVAL
);
1173 count
+= bv
->bv_len
>> (device
->s2b_shift
+ 9);
1174 #if defined(CONFIG_64BIT)
1175 if (idal_is_needed (page_address(bv
->bv_page
),
1177 cidaw
+= bv
->bv_len
>> (device
->s2b_shift
+ 9);
1182 if (count
!= last_rec
- first_rec
+ 1)
1183 return ERR_PTR(-EINVAL
);
1184 /* 1x define extent + 1x locate record + number of blocks */
1185 cplength
= 2 + count
;
1186 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1187 datasize
= sizeof(struct DE_eckd_data
) + sizeof(struct LO_eckd_data
) +
1188 cidaw
* sizeof(unsigned long);
1189 /* Find out the number of additional locate record ccws for cdl. */
1190 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
1191 if (last_rec
>= 2*blk_per_trk
)
1192 count
= 2*blk_per_trk
- first_rec
;
1194 datasize
+= count
*sizeof(struct LO_eckd_data
);
1196 /* Allocate the ccw request. */
1197 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1198 cplength
, datasize
, device
);
1202 /* First ccw is define extent. */
1203 define_extent(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
, device
);
1204 /* Build locate_record+read/write/ccws. */
1205 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct DE_eckd_data
));
1206 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
1208 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
1209 /* Only standard blocks so there is just one locate record. */
1210 ccw
[-1].flags
|= CCW_FLAG_CC
;
1211 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
1212 last_rec
- recid
+ 1, cmd
, device
, blksize
);
1214 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
1215 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1216 if (dasd_page_cache
) {
1217 char *copy
= kmem_cache_alloc(dasd_page_cache
,
1218 SLAB_DMA
| __GFP_NOWARN
);
1219 if (copy
&& rq_data_dir(req
) == WRITE
)
1220 memcpy(copy
+ bv
->bv_offset
, dst
, bv
->bv_len
);
1222 dst
= copy
+ bv
->bv_offset
;
1224 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1225 sector_t trkid
= recid
;
1226 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
1229 /* Locate record for cdl special block ? */
1230 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
1231 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
1233 count
= dasd_eckd_cdl_reclen(recid
);
1234 if (count
< blksize
&&
1235 rq_data_dir(req
) == READ
)
1236 memset(dst
+ count
, 0xe5,
1239 ccw
[-1].flags
|= CCW_FLAG_CC
;
1240 locate_record(ccw
++, LO_data
++,
1242 1, rcmd
, device
, count
);
1244 /* Locate record for standard blocks ? */
1245 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
1246 ccw
[-1].flags
|= CCW_FLAG_CC
;
1247 locate_record(ccw
++, LO_data
++,
1249 last_rec
- recid
+ 1,
1250 cmd
, device
, count
);
1252 /* Read/write ccw. */
1253 ccw
[-1].flags
|= CCW_FLAG_CC
;
1254 ccw
->cmd_code
= rcmd
;
1256 if (idal_is_needed(dst
, blksize
)) {
1257 ccw
->cda
= (__u32
)(addr_t
) idaws
;
1258 ccw
->flags
= CCW_FLAG_IDA
;
1259 idaws
= idal_create_words(idaws
, dst
, blksize
);
1261 ccw
->cda
= (__u32
)(addr_t
) dst
;
1269 if (req
->flags
& REQ_FAILFAST
)
1270 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1271 cqr
->device
= device
;
1272 cqr
->expires
= 5 * 60 * HZ
; /* 5 minutes */
1273 cqr
->lpm
= private->path_data
.ppm
;
1275 cqr
->buildclk
= get_clock();
1276 cqr
->status
= DASD_CQR_FILLED
;
1281 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
1283 struct dasd_eckd_private
*private;
1288 unsigned int blksize
, blk_per_trk
, off
;
1292 if (!dasd_page_cache
)
1294 private = (struct dasd_eckd_private
*) cqr
->device
->private;
1295 blksize
= cqr
->device
->bp_block
;
1296 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1297 recid
= req
->sector
>> cqr
->device
->s2b_shift
;
1299 /* Skip over define extent & locate record. */
1301 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
1303 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
1304 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1305 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1306 /* Skip locate record. */
1307 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
1310 if (ccw
->flags
& CCW_FLAG_IDA
)
1311 cda
= *((char **)((addr_t
) ccw
->cda
));
1313 cda
= (char *)((addr_t
) ccw
->cda
);
1315 if (rq_data_dir(req
) == READ
)
1316 memcpy(dst
, cda
, bv
->bv_len
);
1317 kmem_cache_free(dasd_page_cache
,
1318 (void *)((addr_t
)cda
& PAGE_MASK
));
1327 status
= cqr
->status
== DASD_CQR_DONE
;
1328 dasd_sfree_request(cqr
, cqr
->device
);
1333 dasd_eckd_fill_info(struct dasd_device
* device
,
1334 struct dasd_information2_t
* info
)
1336 struct dasd_eckd_private
*private;
1338 private = (struct dasd_eckd_private
*) device
->private;
1339 info
->label_block
= 2;
1340 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
1341 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
1342 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
1343 memcpy(info
->characteristics
, &private->rdc_data
,
1344 sizeof(struct dasd_eckd_characteristics
));
1345 info
->confdata_size
= sizeof (struct dasd_eckd_confdata
);
1346 memcpy(info
->configuration_data
, &private->conf_data
,
1347 sizeof (struct dasd_eckd_confdata
));
1352 * SECTION: ioctl functions for eckd devices.
1356 * Release device ioctl.
1357 * Buils a channel programm to releases a prior reserved
1358 * (see dasd_eckd_reserve) device.
1361 dasd_eckd_release(struct dasd_device
*device
)
1363 struct dasd_ccw_req
*cqr
;
1366 if (!capable(CAP_SYS_ADMIN
))
1369 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1372 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1373 "Could not allocate initialization request");
1374 return PTR_ERR(cqr
);
1376 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
1377 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1378 cqr
->cpaddr
->count
= 32;
1379 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1380 cqr
->device
= device
;
1381 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1382 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1384 cqr
->expires
= 2 * HZ
;
1385 cqr
->buildclk
= get_clock();
1386 cqr
->status
= DASD_CQR_FILLED
;
1388 rc
= dasd_sleep_on_immediatly(cqr
);
1390 dasd_sfree_request(cqr
, cqr
->device
);
1395 * Reserve device ioctl.
1396 * Options are set to 'synchronous wait for interrupt' and
1397 * 'timeout the request'. This leads to a terminate IO if
1398 * the interrupt is outstanding for a certain time.
1401 dasd_eckd_reserve(struct dasd_device
*device
)
1403 struct dasd_ccw_req
*cqr
;
1406 if (!capable(CAP_SYS_ADMIN
))
1409 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1412 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1413 "Could not allocate initialization request");
1414 return PTR_ERR(cqr
);
1416 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
1417 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1418 cqr
->cpaddr
->count
= 32;
1419 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1420 cqr
->device
= device
;
1421 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1422 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1424 cqr
->expires
= 2 * HZ
;
1425 cqr
->buildclk
= get_clock();
1426 cqr
->status
= DASD_CQR_FILLED
;
1428 rc
= dasd_sleep_on_immediatly(cqr
);
1430 dasd_sfree_request(cqr
, cqr
->device
);
1435 * Steal lock ioctl - unconditional reserve device.
1436 * Buils a channel programm to break a device's reservation.
1437 * (unconditional reserve)
1440 dasd_eckd_steal_lock(struct dasd_device
*device
)
1442 struct dasd_ccw_req
*cqr
;
1445 if (!capable(CAP_SYS_ADMIN
))
1448 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1451 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1452 "Could not allocate initialization request");
1453 return PTR_ERR(cqr
);
1455 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_SLCK
;
1456 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1457 cqr
->cpaddr
->count
= 32;
1458 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1459 cqr
->device
= device
;
1460 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1461 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1463 cqr
->expires
= 2 * HZ
;
1464 cqr
->buildclk
= get_clock();
1465 cqr
->status
= DASD_CQR_FILLED
;
1467 rc
= dasd_sleep_on_immediatly(cqr
);
1469 dasd_sfree_request(cqr
, cqr
->device
);
1474 * Read performance statistics
1477 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
1479 struct dasd_psf_prssd_data
*prssdp
;
1480 struct dasd_rssd_perf_stats_t
*stats
;
1481 struct dasd_ccw_req
*cqr
;
1485 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1486 1 /* PSF */ + 1 /* RSSD */ ,
1487 (sizeof (struct dasd_psf_prssd_data
) +
1488 sizeof (struct dasd_rssd_perf_stats_t
)),
1491 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1492 "Could not allocate initialization request");
1493 return PTR_ERR(cqr
);
1495 cqr
->device
= device
;
1497 cqr
->expires
= 10 * HZ
;
1499 /* Prepare for Read Subsystem Data */
1500 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1501 memset(prssdp
, 0, sizeof (struct dasd_psf_prssd_data
));
1502 prssdp
->order
= PSF_ORDER_PRSSD
;
1503 prssdp
->suborder
= 0x01; /* Perfomance Statistics */
1504 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
1507 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1508 ccw
->count
= sizeof (struct dasd_psf_prssd_data
);
1509 ccw
->flags
|= CCW_FLAG_CC
;
1510 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1512 /* Read Subsystem Data - Performance Statistics */
1513 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1514 memset(stats
, 0, sizeof (struct dasd_rssd_perf_stats_t
));
1517 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1518 ccw
->count
= sizeof (struct dasd_rssd_perf_stats_t
);
1519 ccw
->cda
= (__u32
)(addr_t
) stats
;
1521 cqr
->buildclk
= get_clock();
1522 cqr
->status
= DASD_CQR_FILLED
;
1523 rc
= dasd_sleep_on(cqr
);
1525 /* Prepare for Read Subsystem Data */
1526 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1527 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1528 if (copy_to_user(argp
, stats
,
1529 sizeof(struct dasd_rssd_perf_stats_t
)))
1532 dasd_sfree_request(cqr
, cqr
->device
);
1537 * Get attributes (cache operations)
1538 * Returnes the cache attributes used in Define Extend (DE).
1541 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
1543 struct dasd_eckd_private
*private =
1544 (struct dasd_eckd_private
*)device
->private;
1545 struct attrib_data_t attrib
= private->attrib
;
1548 if (!capable(CAP_SYS_ADMIN
))
1554 if (copy_to_user(argp
, (long *) &attrib
,
1555 sizeof (struct attrib_data_t
)))
1562 * Set attributes (cache operations)
1563 * Stores the attributes for cache operation to be used in Define Extend (DE).
1566 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
1568 struct dasd_eckd_private
*private =
1569 (struct dasd_eckd_private
*)device
->private;
1570 struct attrib_data_t attrib
;
1572 if (!capable(CAP_SYS_ADMIN
))
1577 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
1579 private->attrib
= attrib
;
1581 DEV_MESSAGE(KERN_INFO
, device
,
1582 "cache operation mode set to %x (%i cylinder prestage)",
1583 private->attrib
.operation
, private->attrib
.nr_cyl
);
1588 dasd_eckd_ioctl(struct dasd_device
*device
, unsigned int cmd
, void __user
*argp
)
1592 return dasd_eckd_get_attrib(device
, argp
);
1594 return dasd_eckd_set_attrib(device
, argp
);
1596 return dasd_eckd_performance(device
, argp
);
1598 return dasd_eckd_release(device
);
1600 return dasd_eckd_reserve(device
);
1602 return dasd_eckd_steal_lock(device
);
1604 return -ENOIOCTLCMD
;
1609 * Dump the range of CCWs into 'page' buffer
1610 * and return number of printed chars.
1613 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
1619 while (from
<= to
) {
1620 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1621 " CCW %p: %08X %08X DAT:",
1622 from
, ((int *) from
)[0], ((int *) from
)[1]);
1624 /* get pointer to data (consider IDALs) */
1625 if (from
->flags
& CCW_FLAG_IDA
)
1626 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
1628 datap
= (char *) ((addr_t
) from
->cda
);
1630 /* dump data (max 32 bytes) */
1631 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
1632 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
1633 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
1634 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
1636 len
+= sprintf(page
+ len
, "\n");
1643 * Print sense data and related channel program.
1644 * Parts are printed because printk buffer is only 1024 bytes.
1647 dasd_eckd_dump_sense(struct dasd_device
*device
, struct dasd_ccw_req
* req
,
1651 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
1654 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
1656 DEV_MESSAGE(KERN_ERR
, device
, " %s",
1657 "No memory to dump sense data");
1660 /* dump the sense data */
1661 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
1662 " I/O status report for device %s:\n",
1663 device
->cdev
->dev
.bus_id
);
1664 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1665 " in req: %p CS: 0x%02X DS: 0x%02X\n", req
,
1666 irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1667 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1668 " device %s: Failing CCW: %p\n",
1669 device
->cdev
->dev
.bus_id
,
1670 (void *) (addr_t
) irb
->scsw
.cpa
);
1671 if (irb
->esw
.esw0
.erw
.cons
) {
1672 for (sl
= 0; sl
< 4; sl
++) {
1673 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1674 " Sense(hex) %2d-%2d:",
1675 (8 * sl
), ((8 * sl
) + 7));
1677 for (sct
= 0; sct
< 8; sct
++) {
1678 len
+= sprintf(page
+ len
, " %02x",
1679 irb
->ecw
[8 * sl
+ sct
]);
1681 len
+= sprintf(page
+ len
, "\n");
1684 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
1685 /* 24 Byte Sense Data */
1686 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1687 " 24 Byte: %x MSG %x, "
1688 "%s MSGb to SYSOP\n",
1689 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
1690 irb
->ecw
[1] & 0x10 ? "" : "no");
1692 /* 32 Byte Sense Data */
1693 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1694 " 32 Byte: Format: %x "
1695 "Exception class %x\n",
1696 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
1699 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1700 " SORRY - NO VALID SENSE AVAILABLE\n");
1704 /* dump the Channel Program (max 140 Bytes per line) */
1705 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
1706 first
= req
->cpaddr
;
1707 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
1708 to
= min(first
+ 6, last
);
1709 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
1710 " Related CP in req: %p\n", req
);
1711 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
1714 /* print failing CCW area (maximum 4) */
1715 /* scsw->cda is either valid or zero */
1718 fail
= (struct ccw1
*)(addr_t
) irb
->scsw
.cpa
; /* failing CCW */
1719 if (from
< fail
- 2) {
1720 from
= fail
- 2; /* there is a gap - print header */
1721 len
+= sprintf(page
, KERN_ERR PRINTK_HEADER
"......\n");
1723 to
= min(fail
+ 1, last
);
1724 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
1726 /* print last CCWs (maximum 2) */
1727 from
= max(from
, ++to
);
1728 if (from
< last
- 1) {
1729 from
= last
- 1; /* there is a gap - print header */
1730 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
1732 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
1735 free_page((unsigned long) page
);
1739 * max_blocks is dependent on the amount of storage that is available
1740 * in the static io buffer for each device. Currently each device has
1741 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
1742 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
1743 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
1744 * addition we have one define extent ccw + 16 bytes of data and one
1745 * locate record ccw + 16 bytes of data. That makes:
1746 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
1747 * We want to fit two into the available memory so that we can immediately
1748 * start the next request if one finishes off. That makes 249.5 blocks
1749 * for one request. Give a little safety and the result is 240.
1751 static struct dasd_discipline dasd_eckd_discipline
= {
1752 .owner
= THIS_MODULE
,
1756 .check_device
= dasd_eckd_check_characteristics
,
1757 .do_analysis
= dasd_eckd_do_analysis
,
1758 .fill_geometry
= dasd_eckd_fill_geometry
,
1759 .start_IO
= dasd_start_IO
,
1760 .term_IO
= dasd_term_IO
,
1761 .format_device
= dasd_eckd_format_device
,
1762 .examine_error
= dasd_eckd_examine_error
,
1763 .erp_action
= dasd_eckd_erp_action
,
1764 .erp_postaction
= dasd_eckd_erp_postaction
,
1765 .build_cp
= dasd_eckd_build_cp
,
1766 .free_cp
= dasd_eckd_free_cp
,
1767 .dump_sense
= dasd_eckd_dump_sense
,
1768 .fill_info
= dasd_eckd_fill_info
,
1769 .ioctl
= dasd_eckd_ioctl
,
1773 dasd_eckd_init(void)
1775 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
1776 return ccw_driver_register(&dasd_eckd_driver
);
1780 dasd_eckd_cleanup(void)
1782 ccw_driver_unregister(&dasd_eckd_driver
);
1785 module_init(dasd_eckd_init
);
1786 module_exit(dasd_eckd_cleanup
);