2 * File...........: linux/drivers/s390/block/dasd_fba.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Bugreports.to..: <Linux390@de.ibm.com>
5 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
10 #include <linux/config.h>
11 #include <linux/stddef.h>
12 #include <linux/kernel.h>
13 #include <asm/debug.h>
15 #include <linux/slab.h>
16 #include <linux/hdreg.h> /* HDIO_GETGEO */
17 #include <linux/bio.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
21 #include <asm/idals.h>
22 #include <asm/ebcdic.h>
24 #include <asm/todclk.h>
25 #include <asm/ccwdev.h>
32 #endif /* PRINTK_HEADER */
33 #define PRINTK_HEADER "dasd(fba):"
35 #define DASD_FBA_CCW_WRITE 0x41
36 #define DASD_FBA_CCW_READ 0x42
37 #define DASD_FBA_CCW_LOCATE 0x43
38 #define DASD_FBA_CCW_DEFINE_EXTENT 0x63
40 MODULE_LICENSE("GPL");
42 static struct dasd_discipline dasd_fba_discipline
;
44 struct dasd_fba_private
{
45 struct dasd_fba_characteristics rdc_data
;
48 static struct ccw_device_id dasd_fba_ids
[] = {
49 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), driver_info
: 0x1},
50 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), driver_info
: 0x2},
51 { /* end of list */ },
54 MODULE_DEVICE_TABLE(ccw
, dasd_fba_ids
);
56 static struct ccw_driver dasd_fba_driver
; /* see below */
58 dasd_fba_probe(struct ccw_device
*cdev
)
62 ret
= dasd_generic_probe (cdev
, &dasd_fba_discipline
);
65 ccw_device_set_options(cdev
, CCWDEV_DO_PATHGROUP
);
70 dasd_fba_set_online(struct ccw_device
*cdev
)
72 return dasd_generic_set_online (cdev
, &dasd_fba_discipline
);
75 static struct ccw_driver dasd_fba_driver
= {
79 .probe
= dasd_fba_probe
,
80 .remove
= dasd_generic_remove
,
81 .set_offline
= dasd_generic_set_offline
,
82 .set_online
= dasd_fba_set_online
,
83 .notify
= dasd_generic_notify
,
87 define_extent(struct ccw1
* ccw
, struct DE_fba_data
*data
, int rw
,
88 int blksize
, int beg
, int nr
)
90 ccw
->cmd_code
= DASD_FBA_CCW_DEFINE_EXTENT
;
93 ccw
->cda
= (__u32
) __pa(data
);
94 memset(data
, 0, sizeof (struct DE_fba_data
));
96 (data
->mask
).perm
= 0x0;
98 (data
->mask
).perm
= 0x1;
100 data
->mask
.perm
= 0x2;
101 data
->blk_size
= blksize
;
103 data
->ext_end
= nr
- 1;
107 locate_record(struct ccw1
* ccw
, struct LO_fba_data
*data
, int rw
,
108 int block_nr
, int block_ct
)
110 ccw
->cmd_code
= DASD_FBA_CCW_LOCATE
;
113 ccw
->cda
= (__u32
) __pa(data
);
114 memset(data
, 0, sizeof (struct LO_fba_data
));
116 data
->operation
.cmd
= 0x5;
118 data
->operation
.cmd
= 0x6;
120 data
->operation
.cmd
= 0x8;
121 data
->blk_nr
= block_nr
;
122 data
->blk_ct
= block_ct
;
126 dasd_fba_check_characteristics(struct dasd_device
*device
)
128 struct dasd_fba_private
*private;
129 struct ccw_device
*cdev
= device
->cdev
;
133 private = (struct dasd_fba_private
*) device
->private;
134 if (private == NULL
) {
135 private = kmalloc(sizeof(struct dasd_fba_private
), GFP_KERNEL
);
136 if (private == NULL
) {
137 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
138 "memory allocation failed for private "
142 device
->private = (void *) private;
144 /* Read Device Characteristics */
145 rdc_data
= (void *) &(private->rdc_data
);
146 rc
= read_dev_chars(device
->cdev
, &rdc_data
, 32);
148 DEV_MESSAGE(KERN_WARNING
, device
,
149 "Read device characteristics returned error %d",
154 DEV_MESSAGE(KERN_INFO
, device
,
155 "%04X/%02X(CU:%04X/%02X) %dMB at(%d B/blk)",
160 ((private->rdc_data
.blk_bdsa
*
161 (private->rdc_data
.blk_size
>> 9)) >> 11),
162 private->rdc_data
.blk_size
);
167 dasd_fba_do_analysis(struct dasd_device
*device
)
169 struct dasd_fba_private
*private;
172 private = (struct dasd_fba_private
*) device
->private;
173 rc
= dasd_check_blocksize(private->rdc_data
.blk_size
);
175 DEV_MESSAGE(KERN_INFO
, device
, "unknown blocksize %d",
176 private->rdc_data
.blk_size
);
179 device
->blocks
= private->rdc_data
.blk_bdsa
;
180 device
->bp_block
= private->rdc_data
.blk_size
;
181 device
->s2b_shift
= 0; /* bits to shift 512 to get a block */
182 for (sb
= 512; sb
< private->rdc_data
.blk_size
; sb
= sb
<< 1)
188 dasd_fba_fill_geometry(struct dasd_device
*device
, struct hd_geometry
*geo
)
190 if (dasd_check_blocksize(device
->bp_block
) != 0)
192 geo
->cylinders
= (device
->blocks
<< device
->s2b_shift
) >> 10;
194 geo
->sectors
= 128 >> device
->s2b_shift
;
199 dasd_fba_examine_error(struct dasd_ccw_req
* cqr
, struct irb
* irb
)
201 struct dasd_device
*device
;
202 struct ccw_device
*cdev
;
204 device
= (struct dasd_device
*) cqr
->device
;
205 if (irb
->scsw
.cstat
== 0x00 &&
206 irb
->scsw
.dstat
== (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
))
207 return dasd_era_none
;
210 switch (cdev
->id
.dev_type
) {
212 return dasd_3370_erp_examine(cqr
, irb
);
214 return dasd_9336_erp_examine(cqr
, irb
);
216 return dasd_era_recover
;
221 dasd_fba_erp_action(struct dasd_ccw_req
* cqr
)
223 return dasd_default_erp_action
;
227 dasd_fba_erp_postaction(struct dasd_ccw_req
* cqr
)
229 if (cqr
->function
== dasd_default_erp_action
)
230 return dasd_default_erp_postaction
;
232 DEV_MESSAGE(KERN_WARNING
, cqr
->device
, "unknown ERP action %p",
237 static struct dasd_ccw_req
*
238 dasd_fba_build_cp(struct dasd_device
* device
, struct request
*req
)
240 struct dasd_fba_private
*private;
241 unsigned long *idaws
;
242 struct LO_fba_data
*LO_data
;
243 struct dasd_ccw_req
*cqr
;
248 int count
, cidaw
, cplength
, datasize
;
249 sector_t recid
, first_rec
, last_rec
;
250 unsigned int blksize
, off
;
254 private = (struct dasd_fba_private
*) device
->private;
255 if (rq_data_dir(req
) == READ
) {
256 cmd
= DASD_FBA_CCW_READ
;
257 } else if (rq_data_dir(req
) == WRITE
) {
258 cmd
= DASD_FBA_CCW_WRITE
;
260 return ERR_PTR(-EINVAL
);
261 blksize
= device
->bp_block
;
262 /* Calculate record id of first and last block. */
263 first_rec
= req
->sector
>> device
->s2b_shift
;
264 last_rec
= (req
->sector
+ req
->nr_sectors
- 1) >> device
->s2b_shift
;
265 /* Check struct bio and count the number of blocks for the request. */
268 rq_for_each_bio(bio
, req
) {
269 bio_for_each_segment(bv
, bio
, i
) {
270 if (bv
->bv_len
& (blksize
- 1))
271 /* Fba can only do full blocks. */
272 return ERR_PTR(-EINVAL
);
273 count
+= bv
->bv_len
>> (device
->s2b_shift
+ 9);
274 #if defined(CONFIG_ARCH_S390X)
275 if (idal_is_needed (page_address(bv
->bv_page
),
277 cidaw
+= bv
->bv_len
/ blksize
;
282 if (count
!= last_rec
- first_rec
+ 1)
283 return ERR_PTR(-EINVAL
);
284 /* 1x define extent + 1x locate record + number of blocks */
285 cplength
= 2 + count
;
286 /* 1x define extent + 1x locate record */
287 datasize
= sizeof(struct DE_fba_data
) + sizeof(struct LO_fba_data
) +
288 cidaw
* sizeof(unsigned long);
290 * Find out number of additional locate record ccws if the device
291 * can't do data chaining.
293 if (private->rdc_data
.mode
.bits
.data_chain
== 0) {
294 cplength
+= count
- 1;
295 datasize
+= (count
- 1)*sizeof(struct LO_fba_data
);
297 /* Allocate the ccw request. */
298 cqr
= dasd_smalloc_request(dasd_fba_discipline
.name
,
299 cplength
, datasize
, device
);
303 /* First ccw is define extent. */
304 define_extent(ccw
++, cqr
->data
, rq_data_dir(req
),
305 device
->bp_block
, req
->sector
, req
->nr_sectors
);
306 /* Build locate_record + read/write ccws. */
307 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct DE_fba_data
));
308 LO_data
= (struct LO_fba_data
*) (idaws
+ cidaw
);
309 /* Locate record for all blocks for smart devices. */
310 if (private->rdc_data
.mode
.bits
.data_chain
!= 0) {
311 ccw
[-1].flags
|= CCW_FLAG_CC
;
312 locate_record(ccw
++, LO_data
++, rq_data_dir(req
), 0, count
);
315 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
316 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
317 if (dasd_page_cache
) {
318 char *copy
= kmem_cache_alloc(dasd_page_cache
,
319 SLAB_DMA
| __GFP_NOWARN
);
320 if (copy
&& rq_data_dir(req
) == WRITE
)
321 memcpy(copy
+ bv
->bv_offset
, dst
, bv
->bv_len
);
323 dst
= copy
+ bv
->bv_offset
;
325 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
326 /* Locate record for stupid devices. */
327 if (private->rdc_data
.mode
.bits
.data_chain
== 0) {
328 ccw
[-1].flags
|= CCW_FLAG_CC
;
329 locate_record(ccw
, LO_data
++,
331 recid
- first_rec
, 1);
332 ccw
->flags
= CCW_FLAG_CC
;
335 if (recid
> first_rec
)
336 ccw
[-1].flags
|= CCW_FLAG_DC
;
338 ccw
[-1].flags
|= CCW_FLAG_CC
;
341 ccw
->count
= device
->bp_block
;
342 if (idal_is_needed(dst
, blksize
)) {
343 ccw
->cda
= (__u32
)(addr_t
) idaws
;
344 ccw
->flags
= CCW_FLAG_IDA
;
345 idaws
= idal_create_words(idaws
, dst
, blksize
);
347 ccw
->cda
= (__u32
)(addr_t
) dst
;
355 cqr
->device
= device
;
356 cqr
->expires
= 5 * 60 * HZ
; /* 5 minutes */
357 cqr
->status
= DASD_CQR_FILLED
;
362 dasd_fba_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
364 struct dasd_fba_private
*private;
369 unsigned int blksize
, off
;
372 if (!dasd_page_cache
)
374 private = (struct dasd_fba_private
*) cqr
->device
->private;
375 blksize
= cqr
->device
->bp_block
;
377 /* Skip over define extent & locate record. */
379 if (private->rdc_data
.mode
.bits
.data_chain
!= 0)
381 rq_for_each_bio(bio
, req
) bio_for_each_segment(bv
, bio
, i
) {
382 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
383 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
384 /* Skip locate record. */
385 if (private->rdc_data
.mode
.bits
.data_chain
== 0)
388 if (ccw
->flags
& CCW_FLAG_IDA
)
389 cda
= *((char **)((addr_t
) ccw
->cda
));
391 cda
= (char *)((addr_t
) ccw
->cda
);
393 if (rq_data_dir(req
) == READ
)
394 memcpy(dst
, cda
, bv
->bv_len
);
395 kmem_cache_free(dasd_page_cache
,
396 (void *)((addr_t
)cda
& PAGE_MASK
));
404 status
= cqr
->status
== DASD_CQR_DONE
;
405 dasd_sfree_request(cqr
, cqr
->device
);
410 dasd_fba_fill_info(struct dasd_device
* device
,
411 struct dasd_information2_t
* info
)
413 info
->label_block
= 1;
414 info
->FBA_layout
= 1;
415 info
->format
= DASD_FORMAT_LDL
;
416 info
->characteristics_size
= sizeof(struct dasd_fba_characteristics
);
417 memcpy(info
->characteristics
,
418 &((struct dasd_fba_private
*) device
->private)->rdc_data
,
419 sizeof (struct dasd_fba_characteristics
));
420 info
->confdata_size
= 0;
425 dasd_fba_dump_sense(struct dasd_device
*device
, struct dasd_ccw_req
* req
,
429 struct ccw1
*act
, *end
, *last
;
430 int len
, sl
, sct
, count
;
432 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
434 DEV_MESSAGE(KERN_ERR
, device
, " %s",
435 "No memory to dump sense data");
438 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
439 " I/O status report for device %s:\n",
440 device
->cdev
->dev
.bus_id
);
441 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
442 " in req: %p CS: 0x%02X DS: 0x%02X\n", req
,
443 irb
->scsw
.cstat
, irb
->scsw
.dstat
);
444 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
445 " device %s: Failing CCW: %p\n",
446 device
->cdev
->dev
.bus_id
,
447 (void *) (addr_t
) irb
->scsw
.cpa
);
448 if (irb
->esw
.esw0
.erw
.cons
) {
449 for (sl
= 0; sl
< 4; sl
++) {
450 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
451 " Sense(hex) %2d-%2d:",
452 (8 * sl
), ((8 * sl
) + 7));
454 for (sct
= 0; sct
< 8; sct
++) {
455 len
+= sprintf(page
+ len
, " %02x",
456 irb
->ecw
[8 * sl
+ sct
]);
458 len
+= sprintf(page
+ len
, "\n");
461 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
462 " SORRY - NO VALID SENSE AVAILABLE\n");
464 MESSAGE_LOG(KERN_ERR
, "%s",
465 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
467 /* dump the Channel Program */
468 /* print first CCWs (maximum 8) */
470 for (last
= act
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
471 end
= min(act
+ 8, last
);
472 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
473 " Related CP in req: %p\n", req
);
475 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
476 " CCW %p: %08X %08X DAT:",
477 act
, ((int *) act
)[0], ((int *) act
)[1]);
478 for (count
= 0; count
< 32 && count
< act
->count
;
479 count
+= sizeof(int))
480 len
+= sprintf(page
+ len
, " %08X",
481 ((int *) (addr_t
) act
->cda
)
483 len
+= sprintf(page
+ len
, "\n");
486 MESSAGE_LOG(KERN_ERR
, "%s",
487 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
490 /* print failing CCW area */
492 if (act
< ((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
) - 2) {
493 act
= ((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
) - 2;
494 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
496 end
= min((struct ccw1
*)(addr_t
) irb
->scsw
.cpa
+ 2, last
);
498 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
499 " CCW %p: %08X %08X DAT:",
500 act
, ((int *) act
)[0], ((int *) act
)[1]);
501 for (count
= 0; count
< 32 && count
< act
->count
;
502 count
+= sizeof(int))
503 len
+= sprintf(page
+ len
, " %08X",
504 ((int *) (addr_t
) act
->cda
)
506 len
+= sprintf(page
+ len
, "\n");
510 /* print last CCWs */
511 if (act
< last
- 2) {
513 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
515 while (act
<= last
) {
516 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
517 " CCW %p: %08X %08X DAT:",
518 act
, ((int *) act
)[0], ((int *) act
)[1]);
519 for (count
= 0; count
< 32 && count
< act
->count
;
520 count
+= sizeof(int))
521 len
+= sprintf(page
+ len
, " %08X",
522 ((int *) (addr_t
) act
->cda
)
524 len
+= sprintf(page
+ len
, "\n");
528 MESSAGE_LOG(KERN_ERR
, "%s",
529 page
+ sizeof(KERN_ERR PRINTK_HEADER
));
530 free_page((unsigned long) page
);
534 * max_blocks is dependent on the amount of storage that is available
535 * in the static io buffer for each device. Currently each device has
536 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
537 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
538 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
539 * addition we have one define extent ccw + 16 bytes of data and a
540 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
542 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
543 * We want to fit two into the available memory so that we can immediately
544 * start the next request if one finishes off. That makes 100.1 blocks
545 * for one request. Give a little safety and the result is 96.
547 static struct dasd_discipline dasd_fba_discipline
= {
548 .owner
= THIS_MODULE
,
552 .check_device
= dasd_fba_check_characteristics
,
553 .do_analysis
= dasd_fba_do_analysis
,
554 .fill_geometry
= dasd_fba_fill_geometry
,
555 .start_IO
= dasd_start_IO
,
556 .term_IO
= dasd_term_IO
,
557 .examine_error
= dasd_fba_examine_error
,
558 .erp_action
= dasd_fba_erp_action
,
559 .erp_postaction
= dasd_fba_erp_postaction
,
560 .build_cp
= dasd_fba_build_cp
,
561 .free_cp
= dasd_fba_free_cp
,
562 .dump_sense
= dasd_fba_dump_sense
,
563 .fill_info
= dasd_fba_fill_info
,
571 ASCEBC(dasd_fba_discipline
.ebcname
, 4);
573 ret
= ccw_driver_register(&dasd_fba_driver
);
577 dasd_generic_auto_online(&dasd_fba_driver
);
582 dasd_fba_cleanup(void)
584 ccw_driver_unregister(&dasd_fba_driver
);
587 module_init(dasd_fba_init
);
588 module_exit(dasd_fba_cleanup
);
591 * Overrides for Emacs so that we follow Linus's tabbing style.
592 * Emacs will notice this stuff at the end of the file and automatically
593 * adjust the settings for this buffer only. This must remain at the end
595 * ---------------------------------------------------------------------------
598 * c-brace-imaginary-offset: 0
600 * c-argdecl-indent: 4
602 * c-continued-statement-offset: 4
603 * c-continued-brace-offset: 0
604 * indent-tabs-mode: 1