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
13 #include <linux/config.h>
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/hdreg.h> /* HDIO_GETGEO */
18 #include <linux/bio.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
22 #include <asm/debug.h>
23 #include <asm/idals.h>
24 #include <asm/ebcdic.h>
26 #include <asm/todclk.h>
27 #include <asm/uaccess.h>
28 #include <asm/ccwdev.h>
31 #include "dasd_eckd.h"
35 #endif /* PRINTK_HEADER */
36 #define PRINTK_HEADER "dasd(eckd):"
38 #define ECKD_C0(i) (i->home_bytes)
39 #define ECKD_F(i) (i->formula)
40 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
41 (i->factors.f_0x02.f1))
42 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
43 (i->factors.f_0x02.f2))
44 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
45 (i->factors.f_0x02.f3))
46 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
47 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
48 #define ECKD_F6(i) (i->factor6)
49 #define ECKD_F7(i) (i->factor7)
50 #define ECKD_F8(i) (i->factor8)
52 MODULE_LICENSE("GPL");
54 static struct dasd_discipline dasd_eckd_discipline
;
56 struct dasd_eckd_private
{
57 struct dasd_eckd_characteristics rdc_data
;
58 struct dasd_eckd_confdata conf_data
;
59 struct dasd_eckd_path path_data
;
60 struct eckd_count count_area
[5];
63 struct attrib_data_t attrib
; /* e.g. cache operations */
66 /* The ccw bus type uses this table to find devices that it sends to
68 static struct ccw_device_id dasd_eckd_ids
[] = {
69 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), driver_info
: 0x1},
70 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), driver_info
: 0x2},
71 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), driver_info
: 0x3},
72 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), driver_info
: 0x4},
73 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), driver_info
: 0x5},
74 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), driver_info
: 0x6},
75 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), driver_info
: 0x7},
76 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), driver_info
: 0x8},
77 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), driver_info
: 0x9},
78 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), driver_info
: 0xa},
79 { /* end of list */ },
82 MODULE_DEVICE_TABLE(ccw
, dasd_eckd_ids
);
84 static struct ccw_driver dasd_eckd_driver
; /* see below */
86 /* initial attempt at a probe function. this can be simplified once
87 * the other detection code is gone */
89 dasd_eckd_probe (struct ccw_device
*cdev
)
93 ret
= dasd_generic_probe (cdev
, &dasd_eckd_discipline
);
96 ccw_device_set_options(cdev
, CCWDEV_DO_PATHGROUP
| CCWDEV_ALLOW_FORCE
);
101 dasd_eckd_set_online(struct ccw_device
*cdev
)
103 return dasd_generic_set_online (cdev
, &dasd_eckd_discipline
);
106 static struct ccw_driver dasd_eckd_driver
= {
108 .owner
= THIS_MODULE
,
109 .ids
= dasd_eckd_ids
,
110 .probe
= dasd_eckd_probe
,
111 .remove
= dasd_generic_remove
,
112 .set_offline
= dasd_generic_set_offline
,
113 .set_online
= dasd_eckd_set_online
,
114 .notify
= dasd_generic_notify
,
117 static const int sizes_trk0
[] = { 28, 148, 84 };
118 #define LABEL_SIZE 140
120 static inline unsigned int
121 round_up_multiple(unsigned int no
, unsigned int mult
)
124 return (rem
? no
- rem
+ mult
: no
);
127 static inline unsigned int
128 ceil_quot(unsigned int d1
, unsigned int d2
)
130 return (d1
+ (d2
- 1)) / d2
;
134 bytes_per_record(struct dasd_eckd_characteristics
*rdc
, int kl
, int dl
)
136 unsigned int fl1
, fl2
, int1
, int2
;
139 switch (rdc
->formula
) {
141 fl1
= round_up_multiple(ECKD_F2(rdc
) + dl
, ECKD_F1(rdc
));
142 fl2
= round_up_multiple(kl
? ECKD_F2(rdc
) + kl
: 0,
147 int1
= ceil_quot(dl
+ ECKD_F6(rdc
), ECKD_F5(rdc
) << 1);
148 int2
= ceil_quot(kl
+ ECKD_F6(rdc
), ECKD_F5(rdc
) << 1);
149 fl1
= round_up_multiple(ECKD_F1(rdc
) * ECKD_F2(rdc
) + dl
+
150 ECKD_F6(rdc
) + ECKD_F4(rdc
) * int1
,
152 fl2
= round_up_multiple(ECKD_F1(rdc
) * ECKD_F3(rdc
) + kl
+
153 ECKD_F6(rdc
) + ECKD_F4(rdc
) * int2
,
164 static inline unsigned int
165 bytes_per_track(struct dasd_eckd_characteristics
*rdc
)
167 return *(unsigned int *) (rdc
->byte_per_track
) >> 8;
170 static inline unsigned int
171 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
172 unsigned int kl
, unsigned int dl
)
176 switch (rdc
->dev_type
) {
179 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
180 ceil_quot(dl
+ 12, 32));
182 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
184 dn
= ceil_quot(dl
+ 6, 232) + 1;
186 kn
= ceil_quot(kl
+ 6, 232) + 1;
187 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
188 9 + ceil_quot(dl
+ 6 * dn
, 34));
190 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
192 dn
= ceil_quot(dl
+ 6, 232) + 1;
194 kn
= ceil_quot(kl
+ 6, 232) + 1;
195 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
196 ceil_quot(dl
+ 6 * dn
, 34));
198 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
204 check_XRC (struct ccw1
*de_ccw
,
205 struct DE_eckd_data
*data
,
206 struct dasd_device
*device
)
208 struct dasd_eckd_private
*private;
210 private = (struct dasd_eckd_private
*) device
->private;
212 /* switch on System Time Stamp - needed for XRC Support */
213 if (private->rdc_data
.facilities
.XRC_supported
) {
215 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
216 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
218 data
->ep_sys_time
= get_clock ();
220 de_ccw
->count
= sizeof (struct DE_eckd_data
);
221 de_ccw
->flags
|= CCW_FLAG_SLI
;
226 } /* end check_XRC */
229 define_extent(struct ccw1
* ccw
, struct DE_eckd_data
* data
, int trk
,
230 int totrk
, int cmd
, struct dasd_device
* device
)
232 struct dasd_eckd_private
*private;
233 struct ch_t geo
, beg
, end
;
235 private = (struct dasd_eckd_private
*) device
->private;
237 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
240 ccw
->cda
= (__u32
) __pa(data
);
242 memset(data
, 0, sizeof (struct DE_eckd_data
));
244 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
245 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
246 case DASD_ECKD_CCW_READ
:
247 case DASD_ECKD_CCW_READ_MT
:
248 case DASD_ECKD_CCW_READ_CKD
:
249 case DASD_ECKD_CCW_READ_CKD_MT
:
250 case DASD_ECKD_CCW_READ_KD
:
251 case DASD_ECKD_CCW_READ_KD_MT
:
252 case DASD_ECKD_CCW_READ_COUNT
:
253 data
->mask
.perm
= 0x1;
254 data
->attributes
.operation
= private->attrib
.operation
;
256 case DASD_ECKD_CCW_WRITE
:
257 case DASD_ECKD_CCW_WRITE_MT
:
258 case DASD_ECKD_CCW_WRITE_KD
:
259 case DASD_ECKD_CCW_WRITE_KD_MT
:
260 data
->mask
.perm
= 0x02;
261 data
->attributes
.operation
= private->attrib
.operation
;
262 check_XRC (ccw
, data
, device
);
264 case DASD_ECKD_CCW_WRITE_CKD
:
265 case DASD_ECKD_CCW_WRITE_CKD_MT
:
266 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
267 check_XRC (ccw
, data
, device
);
269 case DASD_ECKD_CCW_ERASE
:
270 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
271 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
272 data
->mask
.perm
= 0x3;
273 data
->mask
.auth
= 0x1;
274 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
275 check_XRC (ccw
, data
, device
);
278 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
282 data
->attributes
.mode
= 0x3; /* ECKD */
284 if ((private->rdc_data
.cu_type
== 0x2105 ||
285 private->rdc_data
.cu_type
== 0x2107 ||
286 private->rdc_data
.cu_type
== 0x1750)
287 && !(private->uses_cdl
&& trk
< 2))
288 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
290 geo
.cyl
= private->rdc_data
.no_cyl
;
291 geo
.head
= private->rdc_data
.trk_per_cyl
;
292 beg
.cyl
= trk
/ geo
.head
;
293 beg
.head
= trk
% geo
.head
;
294 end
.cyl
= totrk
/ geo
.head
;
295 end
.head
= totrk
% geo
.head
;
297 /* check for sequential prestage - enhance cylinder range */
298 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
299 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
301 if (end
.cyl
+ private->attrib
.nr_cyl
< geo
.cyl
)
302 end
.cyl
+= private->attrib
.nr_cyl
;
304 end
.cyl
= (geo
.cyl
- 1);
307 data
->beg_ext
.cyl
= beg
.cyl
;
308 data
->beg_ext
.head
= beg
.head
;
309 data
->end_ext
.cyl
= end
.cyl
;
310 data
->end_ext
.head
= end
.head
;
314 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, int trk
,
315 int rec_on_trk
, int no_rec
, int cmd
,
316 struct dasd_device
* device
, int reclen
)
318 struct dasd_eckd_private
*private;
322 private = (struct dasd_eckd_private
*) device
->private;
324 DBF_DEV_EVENT(DBF_INFO
, device
,
325 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
326 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
328 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
331 ccw
->cda
= (__u32
) __pa(data
);
333 memset(data
, 0, sizeof (struct LO_eckd_data
));
336 switch (private->rdc_data
.dev_type
) {
338 dn
= ceil_quot(reclen
+ 6, 232);
339 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
340 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
343 d
= 7 + ceil_quot(reclen
+ 12, 32);
344 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
348 data
->sector
= sector
;
349 data
->count
= no_rec
;
351 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
352 data
->operation
.orientation
= 0x3;
353 data
->operation
.operation
= 0x03;
355 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
356 data
->operation
.orientation
= 0x3;
357 data
->operation
.operation
= 0x16;
359 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
360 data
->operation
.orientation
= 0x1;
361 data
->operation
.operation
= 0x03;
364 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
365 data
->operation
.orientation
= 0x3;
366 data
->operation
.operation
= 0x16;
369 case DASD_ECKD_CCW_WRITE
:
370 case DASD_ECKD_CCW_WRITE_MT
:
371 case DASD_ECKD_CCW_WRITE_KD
:
372 case DASD_ECKD_CCW_WRITE_KD_MT
:
373 data
->auxiliary
.last_bytes_used
= 0x1;
374 data
->length
= reclen
;
375 data
->operation
.operation
= 0x01;
377 case DASD_ECKD_CCW_WRITE_CKD
:
378 case DASD_ECKD_CCW_WRITE_CKD_MT
:
379 data
->auxiliary
.last_bytes_used
= 0x1;
380 data
->length
= reclen
;
381 data
->operation
.operation
= 0x03;
383 case DASD_ECKD_CCW_READ
:
384 case DASD_ECKD_CCW_READ_MT
:
385 case DASD_ECKD_CCW_READ_KD
:
386 case DASD_ECKD_CCW_READ_KD_MT
:
387 data
->auxiliary
.last_bytes_used
= 0x1;
388 data
->length
= reclen
;
389 data
->operation
.operation
= 0x06;
391 case DASD_ECKD_CCW_READ_CKD
:
392 case DASD_ECKD_CCW_READ_CKD_MT
:
393 data
->auxiliary
.last_bytes_used
= 0x1;
394 data
->length
= reclen
;
395 data
->operation
.operation
= 0x16;
397 case DASD_ECKD_CCW_READ_COUNT
:
398 data
->operation
.operation
= 0x06;
400 case DASD_ECKD_CCW_ERASE
:
401 data
->length
= reclen
;
402 data
->auxiliary
.last_bytes_used
= 0x1;
403 data
->operation
.operation
= 0x0b;
406 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
408 data
->seek_addr
.cyl
= data
->search_arg
.cyl
=
409 trk
/ private->rdc_data
.trk_per_cyl
;
410 data
->seek_addr
.head
= data
->search_arg
.head
=
411 trk
% private->rdc_data
.trk_per_cyl
;
412 data
->search_arg
.record
= rec_on_trk
;
416 * Returns 1 if the block is one of the special blocks that needs
417 * to get read/written with the KD variant of the command.
418 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
419 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
420 * Luckily the KD variants differ only by one bit (0x08) from the
421 * normal variant. So don't wonder about code like:
422 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
423 * ccw->cmd_code |= 0x8;
426 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
430 if (recid
< blk_per_trk
)
432 if (recid
< 2 * blk_per_trk
)
438 * Returns the record size for the special blocks of the cdl format.
439 * Only returns something useful if dasd_eckd_cdl_special is true
443 dasd_eckd_cdl_reclen(int recid
)
446 return sizes_trk0
[recid
];
451 dasd_eckd_read_conf(struct dasd_device
*device
)
454 int conf_len
, conf_data_saved
;
457 struct dasd_eckd_private
*private;
458 struct dasd_eckd_path
*path_data
;
460 private = (struct dasd_eckd_private
*) device
->private;
461 path_data
= (struct dasd_eckd_path
*) &private->path_data
;
462 path_data
->opm
= ccw_device_get_path_mask(device
->cdev
);
466 /* get configuration data per operational path */
467 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
468 if (lpm
& path_data
->opm
){
469 rc
= read_conf_data_lpm(device
->cdev
, &conf_data
,
471 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
472 MESSAGE(KERN_WARNING
,
473 "Read configuration data returned "
477 if (conf_data
== NULL
) {
478 MESSAGE(KERN_WARNING
, "%s", "No configuration "
480 continue; /* no errror */
482 if (conf_len
!= sizeof (struct dasd_eckd_confdata
)) {
483 MESSAGE(KERN_WARNING
,
484 "sizes of configuration data mismatch"
485 "%d (read) vs %ld (expected)",
487 sizeof (struct dasd_eckd_confdata
));
489 continue; /* no errror */
491 /* save first valid configuration data */
492 if (!conf_data_saved
){
493 memcpy(&private->conf_data
, conf_data
,
494 sizeof (struct dasd_eckd_confdata
));
497 switch (((char *)conf_data
)[242] & 0x07){
499 path_data
->npm
|= lpm
;
502 path_data
->ppm
|= lpm
;
513 dasd_eckd_check_characteristics(struct dasd_device
*device
)
515 struct dasd_eckd_private
*private;
519 private = (struct dasd_eckd_private
*) device
->private;
520 if (private == NULL
) {
521 private = kmalloc(sizeof(struct dasd_eckd_private
),
522 GFP_KERNEL
| GFP_DMA
);
523 if (private == NULL
) {
524 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
525 "memory allocation failed for private "
529 memset(private, 0, sizeof(struct dasd_eckd_private
));
530 device
->private = (void *) private;
532 /* Invalidate status of initial analysis. */
533 private->init_cqr_status
= -1;
534 /* Set default cache operations. */
535 private->attrib
.operation
= DASD_NORMAL_CACHE
;
536 private->attrib
.nr_cyl
= 0;
538 /* Read Device Characteristics */
539 rdc_data
= (void *) &(private->rdc_data
);
540 rc
= read_dev_chars(device
->cdev
, &rdc_data
, 64);
542 DEV_MESSAGE(KERN_WARNING
, device
,
543 "Read device characteristics returned error %d",
548 DEV_MESSAGE(KERN_INFO
, device
,
549 "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
550 private->rdc_data
.dev_type
,
551 private->rdc_data
.dev_model
,
552 private->rdc_data
.cu_type
,
553 private->rdc_data
.cu_model
.model
,
554 private->rdc_data
.no_cyl
,
555 private->rdc_data
.trk_per_cyl
,
556 private->rdc_data
.sec_per_trk
);
558 /* Read Configuration Data */
559 rc
= dasd_eckd_read_conf (device
);
564 static struct dasd_ccw_req
*
565 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
567 struct dasd_eckd_private
*private;
568 struct eckd_count
*count_data
;
569 struct LO_eckd_data
*LO_data
;
570 struct dasd_ccw_req
*cqr
;
572 int cplength
, datasize
;
575 private = (struct dasd_eckd_private
*) device
->private;
578 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
579 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
580 cplength
, datasize
, device
);
584 /* Define extent for the first 3 tracks. */
585 define_extent(ccw
++, cqr
->data
, 0, 2,
586 DASD_ECKD_CCW_READ_COUNT
, device
);
587 LO_data
= cqr
->data
+ sizeof (struct DE_eckd_data
);
588 /* Locate record for the first 4 records on track 0. */
589 ccw
[-1].flags
|= CCW_FLAG_CC
;
590 locate_record(ccw
++, LO_data
++, 0, 0, 4,
591 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
593 count_data
= private->count_area
;
594 for (i
= 0; i
< 4; i
++) {
595 ccw
[-1].flags
|= CCW_FLAG_CC
;
596 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
599 ccw
->cda
= (__u32
)(addr_t
) count_data
;
604 /* Locate record for the first record on track 2. */
605 ccw
[-1].flags
|= CCW_FLAG_CC
;
606 locate_record(ccw
++, LO_data
++, 2, 0, 1,
607 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
608 /* Read count ccw. */
609 ccw
[-1].flags
|= CCW_FLAG_CC
;
610 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
613 ccw
->cda
= (__u32
)(addr_t
) count_data
;
615 cqr
->device
= device
;
617 cqr
->buildclk
= get_clock();
618 cqr
->status
= DASD_CQR_FILLED
;
623 * This is the callback function for the init_analysis cqr. It saves
624 * the status of the initial analysis ccw before it frees it and kicks
625 * the device to continue the startup sequence. This will call
626 * dasd_eckd_do_analysis again (if the devices has not been marked
627 * for deletion in the meantime).
630 dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
, void *data
)
632 struct dasd_eckd_private
*private;
633 struct dasd_device
*device
;
635 device
= init_cqr
->device
;
636 private = (struct dasd_eckd_private
*) device
->private;
637 private->init_cqr_status
= init_cqr
->status
;
638 dasd_sfree_request(init_cqr
, device
);
639 dasd_kick_device(device
);
643 dasd_eckd_start_analysis(struct dasd_device
*device
)
645 struct dasd_eckd_private
*private;
646 struct dasd_ccw_req
*init_cqr
;
648 private = (struct dasd_eckd_private
*) device
->private;
649 init_cqr
= dasd_eckd_analysis_ccw(device
);
650 if (IS_ERR(init_cqr
))
651 return PTR_ERR(init_cqr
);
652 init_cqr
->callback
= dasd_eckd_analysis_callback
;
653 init_cqr
->callback_data
= NULL
;
654 init_cqr
->expires
= 5*HZ
;
655 dasd_add_request_head(init_cqr
);
660 dasd_eckd_end_analysis(struct dasd_device
*device
)
662 struct dasd_eckd_private
*private;
663 struct eckd_count
*count_area
;
664 unsigned int sb
, blk_per_trk
;
667 private = (struct dasd_eckd_private
*) device
->private;
668 status
= private->init_cqr_status
;
669 private->init_cqr_status
= -1;
670 if (status
!= DASD_CQR_DONE
) {
671 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
672 "volume analysis returned unformatted disk");
676 private->uses_cdl
= 1;
677 /* Calculate number of blocks/records per track. */
678 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, device
->bp_block
);
679 /* Check Track 0 for Compatible Disk Layout */
681 for (i
= 0; i
< 3; i
++) {
682 if (private->count_area
[i
].kl
!= 4 ||
683 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4) {
684 private->uses_cdl
= 0;
689 count_area
= &private->count_area
[4];
691 if (private->uses_cdl
== 0) {
692 for (i
= 0; i
< 5; i
++) {
693 if ((private->count_area
[i
].kl
!= 0) ||
694 (private->count_area
[i
].dl
!=
695 private->count_area
[0].dl
))
699 count_area
= &private->count_area
[0];
701 if (private->count_area
[3].record
== 1)
702 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
703 "Trk 0: no records after VTOC!");
705 if (count_area
!= NULL
&& count_area
->kl
== 0) {
706 /* we found notthing violating our disk layout */
707 if (dasd_check_blocksize(count_area
->dl
) == 0)
708 device
->bp_block
= count_area
->dl
;
710 if (device
->bp_block
== 0) {
711 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
712 "Volume has incompatible disk layout");
715 device
->s2b_shift
= 0; /* bits to shift 512 to get a block */
716 for (sb
= 512; sb
< device
->bp_block
; sb
= sb
<< 1)
719 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, device
->bp_block
);
720 device
->blocks
= (private->rdc_data
.no_cyl
*
721 private->rdc_data
.trk_per_cyl
*
724 DEV_MESSAGE(KERN_INFO
, device
,
725 "(%dkB blks): %dkB at %dkB/trk %s",
726 (device
->bp_block
>> 10),
727 ((private->rdc_data
.no_cyl
*
728 private->rdc_data
.trk_per_cyl
*
729 blk_per_trk
* (device
->bp_block
>> 9)) >> 1),
730 ((blk_per_trk
* device
->bp_block
) >> 10),
732 "compatible disk layout" : "linux disk layout");
738 dasd_eckd_do_analysis(struct dasd_device
*device
)
740 struct dasd_eckd_private
*private;
742 private = (struct dasd_eckd_private
*) device
->private;
743 if (private->init_cqr_status
< 0)
744 return dasd_eckd_start_analysis(device
);
746 return dasd_eckd_end_analysis(device
);
750 dasd_eckd_fill_geometry(struct dasd_device
*device
, struct hd_geometry
*geo
)
752 struct dasd_eckd_private
*private;
754 private = (struct dasd_eckd_private
*) device
->private;
755 if (dasd_check_blocksize(device
->bp_block
) == 0) {
756 geo
->sectors
= recs_per_track(&private->rdc_data
,
757 0, device
->bp_block
);
759 geo
->cylinders
= private->rdc_data
.no_cyl
;
760 geo
->heads
= private->rdc_data
.trk_per_cyl
;
764 static struct dasd_ccw_req
*
765 dasd_eckd_format_device(struct dasd_device
* device
,
766 struct format_data_t
* fdata
)
768 struct dasd_eckd_private
*private;
769 struct dasd_ccw_req
*fcp
;
770 struct eckd_count
*ect
;
774 int cplength
, datasize
;
777 private = (struct dasd_eckd_private
*) device
->private;
778 rpt
= recs_per_track(&private->rdc_data
, 0, fdata
->blksize
);
779 cyl
= fdata
->start_unit
/ private->rdc_data
.trk_per_cyl
;
780 head
= fdata
->start_unit
% private->rdc_data
.trk_per_cyl
;
783 if (fdata
->start_unit
>=
784 (private->rdc_data
.no_cyl
* private->rdc_data
.trk_per_cyl
)) {
785 DEV_MESSAGE(KERN_INFO
, device
, "Track no %d too big!",
787 return ERR_PTR(-EINVAL
);
789 if (fdata
->start_unit
> fdata
->stop_unit
) {
790 DEV_MESSAGE(KERN_INFO
, device
, "Track %d reached! ending.",
792 return ERR_PTR(-EINVAL
);
794 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
795 DEV_MESSAGE(KERN_WARNING
, device
,
796 "Invalid blocksize %d...terminating!",
798 return ERR_PTR(-EINVAL
);
802 * fdata->intensity is a bit string that tells us what to do:
803 * Bit 0: write record zero
804 * Bit 1: write home address, currently not supported
805 * Bit 2: invalidate tracks
806 * Bit 3: use OS/390 compatible disk layout (cdl)
807 * Only some bit combinations do make sense.
809 switch (fdata
->intensity
) {
810 case 0x00: /* Normal format */
811 case 0x08: /* Normal format, use cdl. */
813 datasize
= sizeof(struct DE_eckd_data
) +
814 sizeof(struct LO_eckd_data
) +
815 rpt
* sizeof(struct eckd_count
);
817 case 0x01: /* Write record zero and format track. */
818 case 0x09: /* Write record zero and format track, use cdl. */
820 datasize
= sizeof(struct DE_eckd_data
) +
821 sizeof(struct LO_eckd_data
) +
822 sizeof(struct eckd_count
) +
823 rpt
* sizeof(struct eckd_count
);
825 case 0x04: /* Invalidate track. */
826 case 0x0c: /* Invalidate track, use cdl. */
828 datasize
= sizeof(struct DE_eckd_data
) +
829 sizeof(struct LO_eckd_data
) +
830 sizeof(struct eckd_count
);
833 DEV_MESSAGE(KERN_WARNING
, device
, "Invalid flags 0x%x.",
835 return ERR_PTR(-EINVAL
);
837 /* Allocate the format ccw request. */
838 fcp
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
839 cplength
, datasize
, device
);
846 switch (fdata
->intensity
& ~0x08) {
847 case 0x00: /* Normal format. */
848 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
849 fdata
->start_unit
, fdata
->start_unit
,
850 DASD_ECKD_CCW_WRITE_CKD
, device
);
851 data
+= sizeof(struct DE_eckd_data
);
852 ccw
[-1].flags
|= CCW_FLAG_CC
;
853 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
854 fdata
->start_unit
, 0, rpt
,
855 DASD_ECKD_CCW_WRITE_CKD
, device
,
857 data
+= sizeof(struct LO_eckd_data
);
859 case 0x01: /* Write record zero + format track. */
860 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
861 fdata
->start_unit
, fdata
->start_unit
,
862 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
864 data
+= sizeof(struct DE_eckd_data
);
865 ccw
[-1].flags
|= CCW_FLAG_CC
;
866 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
867 fdata
->start_unit
, 0, rpt
+ 1,
868 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, device
,
870 data
+= sizeof(struct LO_eckd_data
);
872 case 0x04: /* Invalidate track. */
873 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
874 fdata
->start_unit
, fdata
->start_unit
,
875 DASD_ECKD_CCW_WRITE_CKD
, device
);
876 data
+= sizeof(struct DE_eckd_data
);
877 ccw
[-1].flags
|= CCW_FLAG_CC
;
878 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
879 fdata
->start_unit
, 0, 1,
880 DASD_ECKD_CCW_WRITE_CKD
, device
, 8);
881 data
+= sizeof(struct LO_eckd_data
);
884 if (fdata
->intensity
& 0x01) { /* write record zero */
885 ect
= (struct eckd_count
*) data
;
886 data
+= sizeof(struct eckd_count
);
892 ccw
[-1].flags
|= CCW_FLAG_CC
;
893 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
894 ccw
->flags
= CCW_FLAG_SLI
;
896 ccw
->cda
= (__u32
)(addr_t
) ect
;
899 if ((fdata
->intensity
& ~0x08) & 0x04) { /* erase track */
900 ect
= (struct eckd_count
*) data
;
901 data
+= sizeof(struct eckd_count
);
907 ccw
[-1].flags
|= CCW_FLAG_CC
;
908 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
909 ccw
->flags
= CCW_FLAG_SLI
;
911 ccw
->cda
= (__u32
)(addr_t
) ect
;
912 } else { /* write remaining records */
913 for (i
= 0; i
< rpt
; i
++) {
914 ect
= (struct eckd_count
*) data
;
915 data
+= sizeof(struct eckd_count
);
920 ect
->dl
= fdata
->blksize
;
921 /* Check for special tracks 0-1 when formatting CDL */
922 if ((fdata
->intensity
& 0x08) &&
923 fdata
->start_unit
== 0) {
926 ect
->dl
= sizes_trk0
[i
] - 4;
929 if ((fdata
->intensity
& 0x08) &&
930 fdata
->start_unit
== 1) {
932 ect
->dl
= LABEL_SIZE
- 44;
934 ccw
[-1].flags
|= CCW_FLAG_CC
;
935 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
936 ccw
->flags
= CCW_FLAG_SLI
;
938 ccw
->cda
= (__u32
)(addr_t
) ect
;
942 fcp
->device
= device
;
943 fcp
->retries
= 2; /* set retry counter to enable ERP */
944 fcp
->buildclk
= get_clock();
945 fcp
->status
= DASD_CQR_FILLED
;
950 dasd_eckd_examine_error(struct dasd_ccw_req
* cqr
, struct irb
* irb
)
952 struct dasd_device
*device
= (struct dasd_device
*) cqr
->device
;
953 struct ccw_device
*cdev
= device
->cdev
;
955 if (irb
->scsw
.cstat
== 0x00 &&
956 irb
->scsw
.dstat
== (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
))
957 return dasd_era_none
;
959 switch (cdev
->id
.cu_type
) {
964 return dasd_3990_erp_examine(cqr
, irb
);
966 return dasd_9343_erp_examine(cqr
, irb
);
969 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
970 "default (unknown CU type) - RECOVERABLE return");
971 return dasd_era_recover
;
976 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
978 struct dasd_device
*device
= (struct dasd_device
*) cqr
->device
;
979 struct ccw_device
*cdev
= device
->cdev
;
981 switch (cdev
->id
.cu_type
) {
986 return dasd_3990_erp_action
;
990 return dasd_default_erp_action
;
995 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
997 return dasd_default_erp_postaction
;
1000 static struct dasd_ccw_req
*
1001 dasd_eckd_build_cp(struct dasd_device
* device
, struct request
*req
)
1003 struct dasd_eckd_private
*private;
1004 unsigned long *idaws
;
1005 struct LO_eckd_data
*LO_data
;
1006 struct dasd_ccw_req
*cqr
;
1011 unsigned int blksize
, blk_per_trk
, off
;
1012 int count
, cidaw
, cplength
, datasize
;
1013 sector_t recid
, first_rec
, last_rec
;
1014 sector_t first_trk
, last_trk
;
1015 unsigned int first_offs
, last_offs
;
1016 unsigned char cmd
, rcmd
;
1019 private = (struct dasd_eckd_private
*) device
->private;
1020 if (rq_data_dir(req
) == READ
)
1021 cmd
= DASD_ECKD_CCW_READ_MT
;
1022 else if (rq_data_dir(req
) == WRITE
)
1023 cmd
= DASD_ECKD_CCW_WRITE_MT
;
1025 return ERR_PTR(-EINVAL
);
1026 /* Calculate number of blocks/records per track. */
1027 blksize
= device
->bp_block
;
1028 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1029 /* Calculate record id of first and last block. */
1030 first_rec
= first_trk
= req
->sector
>> device
->s2b_shift
;
1031 first_offs
= sector_div(first_trk
, blk_per_trk
);
1032 last_rec
= last_trk
=
1033 (req
->sector
+ req
->nr_sectors
- 1) >> device
->s2b_shift
;
1034 last_offs
= sector_div(last_trk
, blk_per_trk
);
1035 /* Check struct bio and count the number of blocks for the request. */
1038 rq_for_each_bio(bio
, req
) {
1039 bio_for_each_segment(bv
, bio
, i
) {
1040 if (bv
->bv_len
& (blksize
- 1))
1041 /* Eckd can only do full blocks. */
1042 return ERR_PTR(-EINVAL
);
1043 count
+= bv
->bv_len
>> (device
->s2b_shift
+ 9);
1044 #if defined(CONFIG_ARCH_S390X)
1045 if (idal_is_needed (page_address(bv
->bv_page
),
1047 cidaw
+= bv
->bv_len
>> (device
->s2b_shift
+ 9);
1052 if (count
!= last_rec
- first_rec
+ 1)
1053 return ERR_PTR(-EINVAL
);
1054 /* 1x define extent + 1x locate record + number of blocks */
1055 cplength
= 2 + count
;
1056 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1057 datasize
= sizeof(struct DE_eckd_data
) + sizeof(struct LO_eckd_data
) +
1058 cidaw
* sizeof(unsigned long);
1059 /* Find out the number of additional locate record ccws for cdl. */
1060 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
1061 if (last_rec
>= 2*blk_per_trk
)
1062 count
= 2*blk_per_trk
- first_rec
;
1064 datasize
+= count
*sizeof(struct LO_eckd_data
);
1066 /* Allocate the ccw request. */
1067 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1068 cplength
, datasize
, device
);
1072 /* First ccw is define extent. */
1073 define_extent(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
, device
);
1074 /* Build locate_record+read/write/ccws. */
1075 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct DE_eckd_data
));
1076 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
1078 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
1079 /* Only standard blocks so there is just one locate record. */
1080 ccw
[-1].flags
|= CCW_FLAG_CC
;
1081 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
1082 last_rec
- recid
+ 1, cmd
, device
, blksize
);
1084 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
1085 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1086 if (dasd_page_cache
) {
1087 char *copy
= kmem_cache_alloc(dasd_page_cache
,
1088 SLAB_DMA
| __GFP_NOWARN
);
1089 if (copy
&& rq_data_dir(req
) == WRITE
)
1090 memcpy(copy
+ bv
->bv_offset
, dst
, bv
->bv_len
);
1092 dst
= copy
+ bv
->bv_offset
;
1094 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1095 sector_t trkid
= recid
;
1096 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
1099 /* Locate record for cdl special block ? */
1100 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
1101 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
1103 count
= dasd_eckd_cdl_reclen(recid
);
1104 if (count
< blksize
&&
1105 rq_data_dir(req
) == READ
)
1106 memset(dst
+ count
, 0xe5,
1109 ccw
[-1].flags
|= CCW_FLAG_CC
;
1110 locate_record(ccw
++, LO_data
++,
1112 1, rcmd
, device
, count
);
1114 /* Locate record for standard blocks ? */
1115 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
1116 ccw
[-1].flags
|= CCW_FLAG_CC
;
1117 locate_record(ccw
++, LO_data
++,
1119 last_rec
- recid
+ 1,
1120 cmd
, device
, count
);
1122 /* Read/write ccw. */
1123 ccw
[-1].flags
|= CCW_FLAG_CC
;
1124 ccw
->cmd_code
= rcmd
;
1126 if (idal_is_needed(dst
, blksize
)) {
1127 ccw
->cda
= (__u32
)(addr_t
) idaws
;
1128 ccw
->flags
= CCW_FLAG_IDA
;
1129 idaws
= idal_create_words(idaws
, dst
, blksize
);
1131 ccw
->cda
= (__u32
)(addr_t
) dst
;
1139 cqr
->device
= device
;
1140 cqr
->expires
= 5 * 60 * HZ
; /* 5 minutes */
1141 cqr
->lpm
= private->path_data
.ppm
;
1143 cqr
->buildclk
= get_clock();
1144 cqr
->status
= DASD_CQR_FILLED
;
1149 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
1151 struct dasd_eckd_private
*private;
1156 unsigned int blksize
, blk_per_trk
, off
;
1160 if (!dasd_page_cache
)
1162 private = (struct dasd_eckd_private
*) cqr
->device
->private;
1163 blksize
= cqr
->device
->bp_block
;
1164 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1165 recid
= req
->sector
>> cqr
->device
->s2b_shift
;
1167 /* Skip over define extent & locate record. */
1169 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
1171 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
1172 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1173 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1174 /* Skip locate record. */
1175 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
1178 if (ccw
->flags
& CCW_FLAG_IDA
)
1179 cda
= *((char **)((addr_t
) ccw
->cda
));
1181 cda
= (char *)((addr_t
) ccw
->cda
);
1183 if (rq_data_dir(req
) == READ
)
1184 memcpy(dst
, cda
, bv
->bv_len
);
1185 kmem_cache_free(dasd_page_cache
,
1186 (void *)((addr_t
)cda
& PAGE_MASK
));
1195 status
= cqr
->status
== DASD_CQR_DONE
;
1196 dasd_sfree_request(cqr
, cqr
->device
);
1201 dasd_eckd_fill_info(struct dasd_device
* device
,
1202 struct dasd_information2_t
* info
)
1204 struct dasd_eckd_private
*private;
1206 private = (struct dasd_eckd_private
*) device
->private;
1207 info
->label_block
= 2;
1208 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
1209 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
1210 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
1211 memcpy(info
->characteristics
, &private->rdc_data
,
1212 sizeof(struct dasd_eckd_characteristics
));
1213 info
->confdata_size
= sizeof (struct dasd_eckd_confdata
);
1214 memcpy(info
->configuration_data
, &private->conf_data
,
1215 sizeof (struct dasd_eckd_confdata
));
1220 * SECTION: ioctl functions for eckd devices.
1224 * Release device ioctl.
1225 * Buils a channel programm to releases a prior reserved
1226 * (see dasd_eckd_reserve) device.
1229 dasd_eckd_release(struct block_device
*bdev
, int no
, long args
)
1231 struct dasd_device
*device
;
1232 struct dasd_ccw_req
*cqr
;
1235 if (!capable(CAP_SYS_ADMIN
))
1238 device
= bdev
->bd_disk
->private_data
;
1242 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1245 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1246 "Could not allocate initialization request");
1247 return PTR_ERR(cqr
);
1249 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
1250 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1251 cqr
->cpaddr
->count
= 32;
1252 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1253 cqr
->device
= device
;
1254 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1256 cqr
->expires
= 2 * HZ
;
1257 cqr
->buildclk
= get_clock();
1258 cqr
->status
= DASD_CQR_FILLED
;
1260 rc
= dasd_sleep_on_immediatly(cqr
);
1262 dasd_sfree_request(cqr
, cqr
->device
);
1267 * Reserve device ioctl.
1268 * Options are set to 'synchronous wait for interrupt' and
1269 * 'timeout the request'. This leads to a terminate IO if
1270 * the interrupt is outstanding for a certain time.
1273 dasd_eckd_reserve(struct block_device
*bdev
, int no
, long args
)
1275 struct dasd_device
*device
;
1276 struct dasd_ccw_req
*cqr
;
1279 if (!capable(CAP_SYS_ADMIN
))
1282 device
= bdev
->bd_disk
->private_data
;
1286 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1289 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1290 "Could not allocate initialization request");
1291 return PTR_ERR(cqr
);
1293 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
1294 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1295 cqr
->cpaddr
->count
= 32;
1296 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1297 cqr
->device
= device
;
1298 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1300 cqr
->expires
= 2 * HZ
;
1301 cqr
->buildclk
= get_clock();
1302 cqr
->status
= DASD_CQR_FILLED
;
1304 rc
= dasd_sleep_on_immediatly(cqr
);
1306 dasd_sfree_request(cqr
, cqr
->device
);
1311 * Steal lock ioctl - unconditional reserve device.
1312 * Buils a channel programm to break a device's reservation.
1313 * (unconditional reserve)
1316 dasd_eckd_steal_lock(struct block_device
*bdev
, int no
, long args
)
1318 struct dasd_device
*device
;
1319 struct dasd_ccw_req
*cqr
;
1322 if (!capable(CAP_SYS_ADMIN
))
1325 device
= bdev
->bd_disk
->private_data
;
1329 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1332 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1333 "Could not allocate initialization request");
1334 return PTR_ERR(cqr
);
1336 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_SLCK
;
1337 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1338 cqr
->cpaddr
->count
= 32;
1339 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1340 cqr
->device
= device
;
1341 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1343 cqr
->expires
= 2 * HZ
;
1344 cqr
->buildclk
= get_clock();
1345 cqr
->status
= DASD_CQR_FILLED
;
1347 rc
= dasd_sleep_on_immediatly(cqr
);
1349 dasd_sfree_request(cqr
, cqr
->device
);
1354 * Read performance statistics
1357 dasd_eckd_performance(struct block_device
*bdev
, int no
, long args
)
1359 struct dasd_device
*device
;
1360 struct dasd_psf_prssd_data
*prssdp
;
1361 struct dasd_rssd_perf_stats_t
*stats
;
1362 struct dasd_ccw_req
*cqr
;
1366 device
= bdev
->bd_disk
->private_data
;
1370 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1371 1 /* PSF */ + 1 /* RSSD */ ,
1372 (sizeof (struct dasd_psf_prssd_data
) +
1373 sizeof (struct dasd_rssd_perf_stats_t
)),
1376 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1377 "Could not allocate initialization request");
1378 return PTR_ERR(cqr
);
1380 cqr
->device
= device
;
1382 cqr
->expires
= 10 * HZ
;
1384 /* Prepare for Read Subsystem Data */
1385 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1386 memset(prssdp
, 0, sizeof (struct dasd_psf_prssd_data
));
1387 prssdp
->order
= PSF_ORDER_PRSSD
;
1388 prssdp
->suborder
= 0x01; /* Perfomance Statistics */
1389 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
1392 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1393 ccw
->count
= sizeof (struct dasd_psf_prssd_data
);
1394 ccw
->flags
|= CCW_FLAG_CC
;
1395 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1397 /* Read Subsystem Data - Performance Statistics */
1398 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1399 memset(stats
, 0, sizeof (struct dasd_rssd_perf_stats_t
));
1402 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1403 ccw
->count
= sizeof (struct dasd_rssd_perf_stats_t
);
1404 ccw
->cda
= (__u32
)(addr_t
) stats
;
1406 cqr
->buildclk
= get_clock();
1407 cqr
->status
= DASD_CQR_FILLED
;
1408 rc
= dasd_sleep_on(cqr
);
1410 /* Prepare for Read Subsystem Data */
1411 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1412 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1413 rc
= copy_to_user((long __user
*) args
, (long *) stats
,
1414 sizeof(struct dasd_rssd_perf_stats_t
));
1416 dasd_sfree_request(cqr
, cqr
->device
);
1421 * Get attributes (cache operations)
1422 * Returnes the cache attributes used in Define Extend (DE).
1425 dasd_eckd_get_attrib (struct block_device
*bdev
, int no
, long args
)
1427 struct dasd_device
*device
;
1428 struct dasd_eckd_private
*private;
1429 struct attrib_data_t attrib
;
1432 if (!capable(CAP_SYS_ADMIN
))
1437 device
= bdev
->bd_disk
->private_data
;
1441 private = (struct dasd_eckd_private
*) device
->private;
1442 attrib
= private->attrib
;
1444 rc
= copy_to_user((long __user
*) args
, (long *) &attrib
,
1445 sizeof (struct attrib_data_t
));
1451 * Set attributes (cache operations)
1452 * Stores the attributes for cache operation to be used in Define Extend (DE).
1455 dasd_eckd_set_attrib(struct block_device
*bdev
, int no
, long args
)
1457 struct dasd_device
*device
;
1458 struct dasd_eckd_private
*private;
1459 struct attrib_data_t attrib
;
1461 if (!capable(CAP_SYS_ADMIN
))
1466 device
= bdev
->bd_disk
->private_data
;
1470 if (copy_from_user(&attrib
, (void __user
*) args
,
1471 sizeof (struct attrib_data_t
))) {
1474 private = (struct dasd_eckd_private
*) device
->private;
1475 private->attrib
= attrib
;
1477 DEV_MESSAGE(KERN_INFO
, device
,
1478 "cache operation mode set to %x (%i cylinder prestage)",
1479 private->attrib
.operation
, private->attrib
.nr_cyl
);
1484 * Print sense data and related channel program.
1485 * Parts are printed because printk buffer is only 1024 bytes.
1488 dasd_eckd_dump_sense(struct dasd_device
*device
, struct dasd_ccw_req
* req
,
1492 struct ccw1
*act
, *end
, *last
;
1493 int len
, sl
, sct
, count
;
1495 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
1497 DEV_MESSAGE(KERN_ERR
, device
, " %s",
1498 "No memory to dump sense data");
1501 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
1502 " I/O status report for device %s:\n",
1503 device
->cdev
->dev
.bus_id
);
1504 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1505 " in req: %p CS: 0x%02X DS: 0x%02X\n", req
,
1506 irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1507 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1508 " device %s: Failing CCW: %p\n",
1509 device
->cdev
->dev
.bus_id
,
1510 (void *) (addr_t
) irb
->scsw
.cpa
);
1511 if (irb
->esw
.esw0
.erw
.cons
) {
1512 for (sl
= 0; sl
< 4; sl
++) {
1513 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1514 " Sense(hex) %2d-%2d:",
1515 (8 * sl
), ((8 * sl
) + 7));
1517 for (sct
= 0; sct
< 8; sct
++) {
1518 len
+= sprintf(page
+ len
, " %02x",
1519 irb
->ecw
[8 * sl
+ sct
]);
1521 len
+= sprintf(page
+ len
, "\n");
1524 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
1525 /* 24 Byte Sense Data */
1526 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1527 " 24 Byte: %x MSG %x, "
1528 "%s MSGb to SYSOP\n",
1529 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
1530 irb
->ecw
[1] & 0x10 ? "" : "no");
1532 /* 32 Byte Sense Data */
1533 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1534 " 32 Byte: Format: %x "
1535 "Exception class %x\n",
1536 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
1539 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1540 " SORRY - NO VALID SENSE AVAILABLE\n");
1542 MESSAGE_LOG(KERN_ERR
, "%s",
1543 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
1545 /* dump the Channel Program */
1546 /* print first CCWs (maximum 8) */
1548 for (last
= act
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
1549 end
= min(act
+ 8, last
);
1550 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
1551 " Related CP in req: %p\n", req
);
1552 while (act
<= end
) {
1553 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1554 " CCW %p: %08X %08X DAT:",
1555 act
, ((int *) act
)[0], ((int *) act
)[1]);
1556 for (count
= 0; count
< 32 && count
< act
->count
;
1557 count
+= sizeof(int))
1558 len
+= sprintf(page
+ len
, " %08X",
1559 ((int *) (addr_t
) act
->cda
)
1561 len
+= sprintf(page
+ len
, "\n");
1564 MESSAGE_LOG(KERN_ERR
, "%s",
1565 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
1567 /* print failing CCW area */
1569 if (act
< ((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
) - 2) {
1570 act
= ((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
) - 2;
1571 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
1573 end
= min((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
+ 2, last
);
1574 while (act
<= end
) {
1575 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1576 " CCW %p: %08X %08X DAT:",
1577 act
, ((int *) act
)[0], ((int *) act
)[1]);
1578 for (count
= 0; count
< 32 && count
< act
->count
;
1579 count
+= sizeof(int))
1580 len
+= sprintf(page
+ len
, " %08X",
1581 ((int *) (addr_t
) act
->cda
)
1583 len
+= sprintf(page
+ len
, "\n");
1587 /* print last CCWs */
1588 if (act
< last
- 2) {
1590 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
1592 while (act
<= last
) {
1593 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
1594 " CCW %p: %08X %08X DAT:",
1595 act
, ((int *) act
)[0], ((int *) act
)[1]);
1596 for (count
= 0; count
< 32 && count
< act
->count
;
1597 count
+= sizeof(int))
1598 len
+= sprintf(page
+ len
, " %08X",
1599 ((int *) (addr_t
) act
->cda
)
1601 len
+= sprintf(page
+ len
, "\n");
1605 MESSAGE_LOG(KERN_ERR
, "%s",
1606 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
1607 free_page((unsigned long) page
);
1611 * max_blocks is dependent on the amount of storage that is available
1612 * in the static io buffer for each device. Currently each device has
1613 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
1614 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
1615 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
1616 * addition we have one define extent ccw + 16 bytes of data and one
1617 * locate record ccw + 16 bytes of data. That makes:
1618 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
1619 * We want to fit two into the available memory so that we can immediately
1620 * start the next request if one finishes off. That makes 249.5 blocks
1621 * for one request. Give a little safety and the result is 240.
1623 static struct dasd_discipline dasd_eckd_discipline
= {
1624 .owner
= THIS_MODULE
,
1628 .check_device
= dasd_eckd_check_characteristics
,
1629 .do_analysis
= dasd_eckd_do_analysis
,
1630 .fill_geometry
= dasd_eckd_fill_geometry
,
1631 .start_IO
= dasd_start_IO
,
1632 .term_IO
= dasd_term_IO
,
1633 .format_device
= dasd_eckd_format_device
,
1634 .examine_error
= dasd_eckd_examine_error
,
1635 .erp_action
= dasd_eckd_erp_action
,
1636 .erp_postaction
= dasd_eckd_erp_postaction
,
1637 .build_cp
= dasd_eckd_build_cp
,
1638 .free_cp
= dasd_eckd_free_cp
,
1639 .dump_sense
= dasd_eckd_dump_sense
,
1640 .fill_info
= dasd_eckd_fill_info
,
1644 dasd_eckd_init(void)
1648 dasd_ioctl_no_register(THIS_MODULE
, BIODASDGATTR
,
1649 dasd_eckd_get_attrib
);
1650 dasd_ioctl_no_register(THIS_MODULE
, BIODASDSATTR
,
1651 dasd_eckd_set_attrib
);
1652 dasd_ioctl_no_register(THIS_MODULE
, BIODASDPSRD
,
1653 dasd_eckd_performance
);
1654 dasd_ioctl_no_register(THIS_MODULE
, BIODASDRLSE
,
1656 dasd_ioctl_no_register(THIS_MODULE
, BIODASDRSRV
,
1658 dasd_ioctl_no_register(THIS_MODULE
, BIODASDSLCK
,
1659 dasd_eckd_steal_lock
);
1661 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
1663 ret
= ccw_driver_register(&dasd_eckd_driver
);
1665 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDGATTR
,
1666 dasd_eckd_get_attrib
);
1667 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDSATTR
,
1668 dasd_eckd_set_attrib
);
1669 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDPSRD
,
1670 dasd_eckd_performance
);
1671 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDRLSE
,
1673 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDRSRV
,
1675 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDSLCK
,
1676 dasd_eckd_steal_lock
);
1680 dasd_generic_auto_online(&dasd_eckd_driver
);
1685 dasd_eckd_cleanup(void)
1687 ccw_driver_unregister(&dasd_eckd_driver
);
1689 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDGATTR
,
1690 dasd_eckd_get_attrib
);
1691 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDSATTR
,
1692 dasd_eckd_set_attrib
);
1693 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDPSRD
,
1694 dasd_eckd_performance
);
1695 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDRLSE
,
1697 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDRSRV
,
1699 dasd_ioctl_no_unregister(THIS_MODULE
, BIODASDSLCK
,
1700 dasd_eckd_steal_lock
);
1703 module_init(dasd_eckd_init
);
1704 module_exit(dasd_eckd_cleanup
);
1707 * Overrides for Emacs so that we follow Linus's tabbing style.
1708 * Emacs will notice this stuff at the end of the file and automatically
1709 * adjust the settings for this buffer only. This must remain at the end
1711 * ---------------------------------------------------------------------------
1714 * c-brace-imaginary-offset: 0
1715 * c-brace-offset: -4
1716 * c-argdecl-indent: 4
1717 * c-label-offset: -4
1718 * c-continued-statement-offset: 4
1719 * c-continued-brace-offset: 0
1720 * indent-tabs-mode: 1