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
9 #include <linux/config.h>
10 #include <linux/stddef.h>
11 #include <linux/kernel.h>
12 #include <asm/debug.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/idals.h>
21 #include <asm/ebcdic.h>
23 #include <asm/todclk.h>
24 #include <asm/ccwdev.h>
31 #endif /* PRINTK_HEADER */
32 #define PRINTK_HEADER "dasd(fba):"
34 #define DASD_FBA_CCW_WRITE 0x41
35 #define DASD_FBA_CCW_READ 0x42
36 #define DASD_FBA_CCW_LOCATE 0x43
37 #define DASD_FBA_CCW_DEFINE_EXTENT 0x63
39 MODULE_LICENSE("GPL");
41 static struct dasd_discipline dasd_fba_discipline;
43 struct dasd_fba_private {
44 struct dasd_fba_characteristics rdc_data;
47 static struct ccw_device_id dasd_fba_ids[] = {
48 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), driver_info: 0x1},
49 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), driver_info: 0x2},
50 { /* end of list */ },
53 MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
55 static struct ccw_driver dasd_fba_driver; /* see below */
57 dasd_fba_probe(struct ccw_device *cdev)
61 ret = dasd_generic_probe (cdev, &dasd_fba_discipline);
64 ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
69 dasd_fba_set_online(struct ccw_device *cdev)
71 return dasd_generic_set_online (cdev, &dasd_fba_discipline);
74 static struct ccw_driver dasd_fba_driver = {
78 .probe = dasd_fba_probe,
79 .remove = dasd_generic_remove,
80 .set_offline = dasd_generic_set_offline,
81 .set_online = dasd_fba_set_online,
82 .notify = dasd_generic_notify,
86 define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
87 int blksize, int beg, int nr)
89 ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
92 ccw->cda = (__u32) __pa(data);
93 memset(data, 0, sizeof (struct DE_fba_data));
95 (data->mask).perm = 0x0;
97 (data->mask).perm = 0x1;
99 data->mask.perm = 0x2;
100 data->blk_size = blksize;
102 data->ext_end = nr - 1;
106 locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
107 int block_nr, int block_ct)
109 ccw->cmd_code = DASD_FBA_CCW_LOCATE;
112 ccw->cda = (__u32) __pa(data);
113 memset(data, 0, sizeof (struct LO_fba_data));
115 data->operation.cmd = 0x5;
117 data->operation.cmd = 0x6;
119 data->operation.cmd = 0x8;
120 data->blk_nr = block_nr;
121 data->blk_ct = block_ct;
125 dasd_fba_check_characteristics(struct dasd_device *device)
127 struct dasd_fba_private *private;
128 struct ccw_device *cdev = device->cdev;
132 private = (struct dasd_fba_private *) device->private;
133 if (private == NULL) {
134 private = kmalloc(sizeof(struct dasd_fba_private), GFP_KERNEL);
135 if (private == NULL) {
136 DEV_MESSAGE(KERN_WARNING, device, "%s",
137 "memory allocation failed for private "
141 device->private = (void *) private;
143 /* Read Device Characteristics */
144 rdc_data = (void *) &(private->rdc_data);
145 rc = read_dev_chars(device->cdev, &rdc_data, 32);
147 DEV_MESSAGE(KERN_WARNING, device,
148 "Read device characteristics returned error %d",
153 DEV_MESSAGE(KERN_INFO, device,
154 "%04X/%02X(CU:%04X/%02X) %dMB at(%d B/blk)",
159 ((private->rdc_data.blk_bdsa *
160 (private->rdc_data.blk_size >> 9)) >> 11),
161 private->rdc_data.blk_size);
166 dasd_fba_do_analysis(struct dasd_device *device)
168 struct dasd_fba_private *private;
171 private = (struct dasd_fba_private *) device->private;
172 rc = dasd_check_blocksize(private->rdc_data.blk_size);
174 DEV_MESSAGE(KERN_INFO, device, "unknown blocksize %d",
175 private->rdc_data.blk_size);
178 device->blocks = private->rdc_data.blk_bdsa;
179 device->bp_block = private->rdc_data.blk_size;
180 device->s2b_shift = 0; /* bits to shift 512 to get a block */
181 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
187 dasd_fba_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
189 if (dasd_check_blocksize(device->bp_block) != 0)
191 geo->cylinders = (device->blocks << device->s2b_shift) >> 10;
193 geo->sectors = 128 >> device->s2b_shift;
198 dasd_fba_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
200 struct dasd_device *device;
201 struct ccw_device *cdev;
203 device = (struct dasd_device *) cqr->device;
204 if (irb->scsw.cstat == 0x00 &&
205 irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
206 return dasd_era_none;
209 switch (cdev->id.dev_type) {
211 return dasd_3370_erp_examine(cqr, irb);
213 return dasd_9336_erp_examine(cqr, irb);
215 return dasd_era_recover;
220 dasd_fba_erp_action(struct dasd_ccw_req * cqr)
222 return dasd_default_erp_action;
226 dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
228 if (cqr->function == dasd_default_erp_action)
229 return dasd_default_erp_postaction;
231 DEV_MESSAGE(KERN_WARNING, cqr->device, "unknown ERP action %p",
236 static struct dasd_ccw_req *
237 dasd_fba_build_cp(struct dasd_device * device, struct request *req)
239 struct dasd_fba_private *private;
240 unsigned long *idaws;
241 struct LO_fba_data *LO_data;
242 struct dasd_ccw_req *cqr;
247 int count, cidaw, cplength, datasize;
248 sector_t recid, first_rec, last_rec;
249 unsigned int blksize, off;
253 private = (struct dasd_fba_private *) device->private;
254 if (rq_data_dir(req) == READ) {
255 cmd = DASD_FBA_CCW_READ;
256 } else if (rq_data_dir(req) == WRITE) {
257 cmd = DASD_FBA_CCW_WRITE;
259 return ERR_PTR(-EINVAL);
260 blksize = device->bp_block;
261 /* Calculate record id of first and last block. */
262 first_rec = req->sector >> device->s2b_shift;
263 last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
264 /* Check struct bio and count the number of blocks for the request. */
267 rq_for_each_bio(bio, req) {
268 bio_for_each_segment(bv, bio, i) {
269 if (bv->bv_len & (blksize - 1))
270 /* Fba can only do full blocks. */
271 return ERR_PTR(-EINVAL);
272 count += bv->bv_len >> (device->s2b_shift + 9);
273 #if defined(CONFIG_64BIT)
274 if (idal_is_needed (page_address(bv->bv_page),
276 cidaw += bv->bv_len / blksize;
281 if (count != last_rec - first_rec + 1)
282 return ERR_PTR(-EINVAL);
283 /* 1x define extent + 1x locate record + number of blocks */
284 cplength = 2 + count;
285 /* 1x define extent + 1x locate record */
286 datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
287 cidaw * sizeof(unsigned long);
289 * Find out number of additional locate record ccws if the device
290 * can't do data chaining.
292 if (private->rdc_data.mode.bits.data_chain == 0) {
293 cplength += count - 1;
294 datasize += (count - 1)*sizeof(struct LO_fba_data);
296 /* Allocate the ccw request. */
297 cqr = dasd_smalloc_request(dasd_fba_discipline.name,
298 cplength, datasize, device);
302 /* First ccw is define extent. */
303 define_extent(ccw++, cqr->data, rq_data_dir(req),
304 device->bp_block, req->sector, req->nr_sectors);
305 /* Build locate_record + read/write ccws. */
306 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
307 LO_data = (struct LO_fba_data *) (idaws + cidaw);
308 /* Locate record for all blocks for smart devices. */
309 if (private->rdc_data.mode.bits.data_chain != 0) {
310 ccw[-1].flags |= CCW_FLAG_CC;
311 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
314 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
315 dst = page_address(bv->bv_page) + bv->bv_offset;
316 if (dasd_page_cache) {
317 char *copy = kmem_cache_alloc(dasd_page_cache,
318 SLAB_DMA | __GFP_NOWARN);
319 if (copy && rq_data_dir(req) == WRITE)
320 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
322 dst = copy + bv->bv_offset;
324 for (off = 0; off < bv->bv_len; off += blksize) {
325 /* Locate record for stupid devices. */
326 if (private->rdc_data.mode.bits.data_chain == 0) {
327 ccw[-1].flags |= CCW_FLAG_CC;
328 locate_record(ccw, LO_data++,
330 recid - first_rec, 1);
331 ccw->flags = CCW_FLAG_CC;
334 if (recid > first_rec)
335 ccw[-1].flags |= CCW_FLAG_DC;
337 ccw[-1].flags |= CCW_FLAG_CC;
340 ccw->count = device->bp_block;
341 if (idal_is_needed(dst, blksize)) {
342 ccw->cda = (__u32)(addr_t) idaws;
343 ccw->flags = CCW_FLAG_IDA;
344 idaws = idal_create_words(idaws, dst, blksize);
346 ccw->cda = (__u32)(addr_t) dst;
354 if (req->flags & REQ_FAILFAST)
355 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
356 cqr->device = device;
357 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
359 cqr->buildclk = get_clock();
360 cqr->status = DASD_CQR_FILLED;
365 dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
367 struct dasd_fba_private *private;
372 unsigned int blksize, off;
375 if (!dasd_page_cache)
377 private = (struct dasd_fba_private *) cqr->device->private;
378 blksize = cqr->device->bp_block;
380 /* Skip over define extent & locate record. */
382 if (private->rdc_data.mode.bits.data_chain != 0)
384 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
385 dst = page_address(bv->bv_page) + bv->bv_offset;
386 for (off = 0; off < bv->bv_len; off += blksize) {
387 /* Skip locate record. */
388 if (private->rdc_data.mode.bits.data_chain == 0)
391 if (ccw->flags & CCW_FLAG_IDA)
392 cda = *((char **)((addr_t) ccw->cda));
394 cda = (char *)((addr_t) ccw->cda);
396 if (rq_data_dir(req) == READ)
397 memcpy(dst, cda, bv->bv_len);
398 kmem_cache_free(dasd_page_cache,
399 (void *)((addr_t)cda & PAGE_MASK));
407 status = cqr->status == DASD_CQR_DONE;
408 dasd_sfree_request(cqr, cqr->device);
413 dasd_fba_fill_info(struct dasd_device * device,
414 struct dasd_information2_t * info)
416 info->label_block = 1;
417 info->FBA_layout = 1;
418 info->format = DASD_FORMAT_LDL;
419 info->characteristics_size = sizeof(struct dasd_fba_characteristics);
420 memcpy(info->characteristics,
421 &((struct dasd_fba_private *) device->private)->rdc_data,
422 sizeof (struct dasd_fba_characteristics));
423 info->confdata_size = 0;
428 dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
432 struct ccw1 *act, *end, *last;
433 int len, sl, sct, count;
435 page = (char *) get_zeroed_page(GFP_ATOMIC);
437 DEV_MESSAGE(KERN_ERR, device, " %s",
438 "No memory to dump sense data");
441 len = sprintf(page, KERN_ERR PRINTK_HEADER
442 " I/O status report for device %s:\n",
443 device->cdev->dev.bus_id);
444 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
445 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
446 irb->scsw.cstat, irb->scsw.dstat);
447 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
448 " device %s: Failing CCW: %p\n",
449 device->cdev->dev.bus_id,
450 (void *) (addr_t) irb->scsw.cpa);
451 if (irb->esw.esw0.erw.cons) {
452 for (sl = 0; sl < 4; sl++) {
453 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
454 " Sense(hex) %2d-%2d:",
455 (8 * sl), ((8 * sl) + 7));
457 for (sct = 0; sct < 8; sct++) {
458 len += sprintf(page + len, " %02x",
459 irb->ecw[8 * sl + sct]);
461 len += sprintf(page + len, "\n");
464 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
465 " SORRY - NO VALID SENSE AVAILABLE\n");
467 MESSAGE_LOG(KERN_ERR, "%s",
468 page + sizeof(KERN_ERR PRINTK_HEADER));
470 /* dump the Channel Program */
471 /* print first CCWs (maximum 8) */
473 for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
474 end = min(act + 8, last);
475 len = sprintf(page, KERN_ERR PRINTK_HEADER
476 " Related CP in req: %p\n", req);
478 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
479 " CCW %p: %08X %08X DAT:",
480 act, ((int *) act)[0], ((int *) act)[1]);
481 for (count = 0; count < 32 && count < act->count;
482 count += sizeof(int))
483 len += sprintf(page + len, " %08X",
484 ((int *) (addr_t) act->cda)
486 len += sprintf(page + len, "\n");
489 MESSAGE_LOG(KERN_ERR, "%s",
490 page + sizeof(KERN_ERR PRINTK_HEADER));
493 /* print failing CCW area */
495 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2) {
496 act = ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2;
497 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
499 end = min((struct ccw1 *)(addr_t) irb->scsw.cpa + 2, last);
501 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
502 " CCW %p: %08X %08X DAT:",
503 act, ((int *) act)[0], ((int *) act)[1]);
504 for (count = 0; count < 32 && count < act->count;
505 count += sizeof(int))
506 len += sprintf(page + len, " %08X",
507 ((int *) (addr_t) act->cda)
509 len += sprintf(page + len, "\n");
513 /* print last CCWs */
514 if (act < last - 2) {
516 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
518 while (act <= last) {
519 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
520 " CCW %p: %08X %08X DAT:",
521 act, ((int *) act)[0], ((int *) act)[1]);
522 for (count = 0; count < 32 && count < act->count;
523 count += sizeof(int))
524 len += sprintf(page + len, " %08X",
525 ((int *) (addr_t) act->cda)
527 len += sprintf(page + len, "\n");
531 MESSAGE_LOG(KERN_ERR, "%s",
532 page + sizeof(KERN_ERR PRINTK_HEADER));
533 free_page((unsigned long) page);
537 * max_blocks is dependent on the amount of storage that is available
538 * in the static io buffer for each device. Currently each device has
539 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
540 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
541 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
542 * addition we have one define extent ccw + 16 bytes of data and a
543 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
545 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
546 * We want to fit two into the available memory so that we can immediately
547 * start the next request if one finishes off. That makes 100.1 blocks
548 * for one request. Give a little safety and the result is 96.
550 static struct dasd_discipline dasd_fba_discipline = {
551 .owner = THIS_MODULE,
555 .check_device = dasd_fba_check_characteristics,
556 .do_analysis = dasd_fba_do_analysis,
557 .fill_geometry = dasd_fba_fill_geometry,
558 .start_IO = dasd_start_IO,
559 .term_IO = dasd_term_IO,
560 .examine_error = dasd_fba_examine_error,
561 .erp_action = dasd_fba_erp_action,
562 .erp_postaction = dasd_fba_erp_postaction,
563 .build_cp = dasd_fba_build_cp,
564 .free_cp = dasd_fba_free_cp,
565 .dump_sense = dasd_fba_dump_sense,
566 .fill_info = dasd_fba_fill_info,
574 ASCEBC(dasd_fba_discipline.ebcname, 4);
576 ret = ccw_driver_register(&dasd_fba_driver);
580 dasd_generic_auto_online(&dasd_fba_driver);
585 dasd_fba_cleanup(void)
587 ccw_driver_unregister(&dasd_fba_driver);
590 module_init(dasd_fba_init);
591 module_exit(dasd_fba_cleanup);
594 * Overrides for Emacs so that we follow Linus's tabbing style.
595 * Emacs will notice this stuff at the end of the file and automatically
596 * adjust the settings for this buffer only. This must remain at the end
598 * ---------------------------------------------------------------------------
601 * c-brace-imaginary-offset: 0
603 * c-argdecl-indent: 4
605 * c-continued-statement-offset: 4
606 * c-continued-brace-offset: 0
607 * indent-tabs-mode: 1