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 #define KMSG_COMPONENT "dasd"
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)
60 return dasd_generic_probe(cdev, &dasd_fba_discipline);
64 dasd_fba_set_online(struct ccw_device *cdev)
66 return dasd_generic_set_online(cdev, &dasd_fba_discipline);
69 static struct ccw_driver dasd_fba_driver = {
73 .probe = dasd_fba_probe,
74 .remove = dasd_generic_remove,
75 .set_offline = dasd_generic_set_offline,
76 .set_online = dasd_fba_set_online,
77 .notify = dasd_generic_notify,
81 define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
82 int blksize, int beg, int nr)
84 ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
87 ccw->cda = (__u32) __pa(data);
88 memset(data, 0, sizeof (struct DE_fba_data));
90 (data->mask).perm = 0x0;
92 (data->mask).perm = 0x1;
94 data->mask.perm = 0x2;
95 data->blk_size = blksize;
97 data->ext_end = nr - 1;
101 locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
102 int block_nr, int block_ct)
104 ccw->cmd_code = DASD_FBA_CCW_LOCATE;
107 ccw->cda = (__u32) __pa(data);
108 memset(data, 0, sizeof (struct LO_fba_data));
110 data->operation.cmd = 0x5;
112 data->operation.cmd = 0x6;
114 data->operation.cmd = 0x8;
115 data->blk_nr = block_nr;
116 data->blk_ct = block_ct;
120 dasd_fba_check_characteristics(struct dasd_device *device)
122 struct dasd_block *block;
123 struct dasd_fba_private *private;
124 struct ccw_device *cdev = device->cdev;
128 private = (struct dasd_fba_private *) device->private;
129 if (private == NULL) {
130 private = kzalloc(sizeof(struct dasd_fba_private),
131 GFP_KERNEL | GFP_DMA);
132 if (private == NULL) {
133 dev_warn(&device->cdev->dev,
134 "Allocating memory for private DASD "
138 device->private = (void *) private;
140 block = dasd_alloc_block();
142 DBF_EVENT(DBF_WARNING, "could not allocate dasd block "
143 "structure for device: %s",
144 dev_name(&device->cdev->dev));
145 device->private = NULL;
147 return PTR_ERR(block);
149 device->block = block;
150 block->base = device;
152 /* Read Device Characteristics */
153 rdc_data = (void *) &(private->rdc_data);
154 rc = dasd_generic_read_dev_chars(device, "FBA ", &rdc_data, 32);
156 DBF_EVENT(DBF_WARNING, "Read device characteristics returned "
157 "error %d for device: %s",
158 rc, dev_name(&device->cdev->dev));
159 device->block = NULL;
160 dasd_free_block(block);
161 device->private = NULL;
166 dev_info(&device->cdev->dev,
167 "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB "
173 ((private->rdc_data.blk_bdsa *
174 (private->rdc_data.blk_size >> 9)) >> 11),
175 private->rdc_data.blk_size);
179 static int dasd_fba_do_analysis(struct dasd_block *block)
181 struct dasd_fba_private *private;
184 private = (struct dasd_fba_private *) block->base->private;
185 rc = dasd_check_blocksize(private->rdc_data.blk_size);
187 DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
188 private->rdc_data.blk_size);
191 block->blocks = private->rdc_data.blk_bdsa;
192 block->bp_block = private->rdc_data.blk_size;
193 block->s2b_shift = 0; /* bits to shift 512 to get a block */
194 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
199 static int dasd_fba_fill_geometry(struct dasd_block *block,
200 struct hd_geometry *geo)
202 if (dasd_check_blocksize(block->bp_block) != 0)
204 geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
206 geo->sectors = 128 >> block->s2b_shift;
211 dasd_fba_erp_action(struct dasd_ccw_req * cqr)
213 return dasd_default_erp_action;
217 dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
219 if (cqr->function == dasd_default_erp_action)
220 return dasd_default_erp_postaction;
222 DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
227 static void dasd_fba_handle_unsolicited_interrupt(struct dasd_device *device,
232 /* first of all check for state change pending interrupt */
233 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
234 if ((irb->scsw.cmd.dstat & mask) == mask) {
235 dasd_generic_handle_state_change(device);
239 /* check for unsolicited interrupts */
240 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
241 "unsolicited interrupt received");
242 device->discipline->dump_sense_dbf(device, NULL, irb, "unsolicited");
243 dasd_schedule_device_bh(device);
247 static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
248 struct dasd_block *block,
251 struct dasd_fba_private *private;
252 unsigned long *idaws;
253 struct LO_fba_data *LO_data;
254 struct dasd_ccw_req *cqr;
256 struct req_iterator iter;
259 int count, cidaw, cplength, datasize;
260 sector_t recid, first_rec, last_rec;
261 unsigned int blksize, off;
264 private = (struct dasd_fba_private *) block->base->private;
265 if (rq_data_dir(req) == READ) {
266 cmd = DASD_FBA_CCW_READ;
267 } else if (rq_data_dir(req) == WRITE) {
268 cmd = DASD_FBA_CCW_WRITE;
270 return ERR_PTR(-EINVAL);
271 blksize = block->bp_block;
272 /* Calculate record id of first and last block. */
273 first_rec = req->sector >> block->s2b_shift;
274 last_rec = (req->sector + req->nr_sectors - 1) >> block->s2b_shift;
275 /* Check struct bio and count the number of blocks for the request. */
278 rq_for_each_segment(bv, req, iter) {
279 if (bv->bv_len & (blksize - 1))
280 /* Fba can only do full blocks. */
281 return ERR_PTR(-EINVAL);
282 count += bv->bv_len >> (block->s2b_shift + 9);
283 #if defined(CONFIG_64BIT)
284 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
285 cidaw += bv->bv_len / blksize;
289 if (count != last_rec - first_rec + 1)
290 return ERR_PTR(-EINVAL);
291 /* 1x define extent + 1x locate record + number of blocks */
292 cplength = 2 + count;
293 /* 1x define extent + 1x locate record */
294 datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
295 cidaw * sizeof(unsigned long);
297 * Find out number of additional locate record ccws if the device
298 * can't do data chaining.
300 if (private->rdc_data.mode.bits.data_chain == 0) {
301 cplength += count - 1;
302 datasize += (count - 1)*sizeof(struct LO_fba_data);
304 /* Allocate the ccw request. */
305 cqr = dasd_smalloc_request(dasd_fba_discipline.name,
306 cplength, datasize, memdev);
310 /* First ccw is define extent. */
311 define_extent(ccw++, cqr->data, rq_data_dir(req),
312 block->bp_block, req->sector, req->nr_sectors);
313 /* Build locate_record + read/write ccws. */
314 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
315 LO_data = (struct LO_fba_data *) (idaws + cidaw);
316 /* Locate record for all blocks for smart devices. */
317 if (private->rdc_data.mode.bits.data_chain != 0) {
318 ccw[-1].flags |= CCW_FLAG_CC;
319 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
322 rq_for_each_segment(bv, req, iter) {
323 dst = page_address(bv->bv_page) + bv->bv_offset;
324 if (dasd_page_cache) {
325 char *copy = kmem_cache_alloc(dasd_page_cache,
326 GFP_DMA | __GFP_NOWARN);
327 if (copy && rq_data_dir(req) == WRITE)
328 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
330 dst = copy + bv->bv_offset;
332 for (off = 0; off < bv->bv_len; off += blksize) {
333 /* Locate record for stupid devices. */
334 if (private->rdc_data.mode.bits.data_chain == 0) {
335 ccw[-1].flags |= CCW_FLAG_CC;
336 locate_record(ccw, LO_data++,
338 recid - first_rec, 1);
339 ccw->flags = CCW_FLAG_CC;
342 if (recid > first_rec)
343 ccw[-1].flags |= CCW_FLAG_DC;
345 ccw[-1].flags |= CCW_FLAG_CC;
348 ccw->count = block->bp_block;
349 if (idal_is_needed(dst, blksize)) {
350 ccw->cda = (__u32)(addr_t) idaws;
351 ccw->flags = CCW_FLAG_IDA;
352 idaws = idal_create_words(idaws, dst, blksize);
354 ccw->cda = (__u32)(addr_t) dst;
362 if (blk_noretry_request(req) ||
363 block->base->features & DASD_FEATURE_FAILFAST)
364 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
365 cqr->startdev = memdev;
366 cqr->memdev = memdev;
368 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
370 cqr->buildclk = get_clock();
371 cqr->status = DASD_CQR_FILLED;
376 dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
378 struct dasd_fba_private *private;
380 struct req_iterator iter;
383 unsigned int blksize, off;
386 if (!dasd_page_cache)
388 private = (struct dasd_fba_private *) cqr->block->base->private;
389 blksize = cqr->block->bp_block;
391 /* Skip over define extent & locate record. */
393 if (private->rdc_data.mode.bits.data_chain != 0)
395 rq_for_each_segment(bv, req, iter) {
396 dst = page_address(bv->bv_page) + bv->bv_offset;
397 for (off = 0; off < bv->bv_len; off += blksize) {
398 /* Skip locate record. */
399 if (private->rdc_data.mode.bits.data_chain == 0)
402 if (ccw->flags & CCW_FLAG_IDA)
403 cda = *((char **)((addr_t) ccw->cda));
405 cda = (char *)((addr_t) ccw->cda);
407 if (rq_data_dir(req) == READ)
408 memcpy(dst, cda, bv->bv_len);
409 kmem_cache_free(dasd_page_cache,
410 (void *)((addr_t)cda & PAGE_MASK));
418 status = cqr->status == DASD_CQR_DONE;
419 dasd_sfree_request(cqr, cqr->memdev);
423 static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
425 cqr->status = DASD_CQR_FILLED;
429 dasd_fba_fill_info(struct dasd_device * device,
430 struct dasd_information2_t * info)
432 info->label_block = 1;
433 info->FBA_layout = 1;
434 info->format = DASD_FORMAT_LDL;
435 info->characteristics_size = sizeof(struct dasd_fba_characteristics);
436 memcpy(info->characteristics,
437 &((struct dasd_fba_private *) device->private)->rdc_data,
438 sizeof (struct dasd_fba_characteristics));
439 info->confdata_size = 0;
444 dasd_fba_dump_sense_dbf(struct dasd_device *device, struct dasd_ccw_req *req,
445 struct irb *irb, char *reason)
448 if (irb->esw.esw0.erw.cons) {
449 for (sl = 0; sl < 4; sl++) {
450 DBF_DEV_EVENT(DBF_EMERG, device,
451 "%s: %08x %08x %08x %08x",
452 reason, irb->ecw[8 * 0], irb->ecw[8 * 1],
453 irb->ecw[8 * 2], irb->ecw[8 * 3]);
456 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
457 "SORRY - NO VALID SENSE AVAILABLE\n");
463 dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
467 struct ccw1 *act, *end, *last;
468 int len, sl, sct, count;
470 page = (char *) get_zeroed_page(GFP_ATOMIC);
472 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
473 "No memory to dump sense data");
476 len = sprintf(page, KERN_ERR PRINTK_HEADER
477 " I/O status report for device %s:\n",
478 dev_name(&device->cdev->dev));
479 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
480 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
481 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
482 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
483 " device %s: Failing CCW: %p\n",
484 dev_name(&device->cdev->dev),
485 (void *) (addr_t) irb->scsw.cmd.cpa);
486 if (irb->esw.esw0.erw.cons) {
487 for (sl = 0; sl < 4; sl++) {
488 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
489 " Sense(hex) %2d-%2d:",
490 (8 * sl), ((8 * sl) + 7));
492 for (sct = 0; sct < 8; sct++) {
493 len += sprintf(page + len, " %02x",
494 irb->ecw[8 * sl + sct]);
496 len += sprintf(page + len, "\n");
499 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
500 " SORRY - NO VALID SENSE AVAILABLE\n");
502 printk(KERN_ERR "%s", page);
504 /* dump the Channel Program */
505 /* print first CCWs (maximum 8) */
507 for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
508 end = min(act + 8, last);
509 len = sprintf(page, KERN_ERR PRINTK_HEADER
510 " Related CP in req: %p\n", req);
512 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
513 " CCW %p: %08X %08X DAT:",
514 act, ((int *) act)[0], ((int *) act)[1]);
515 for (count = 0; count < 32 && count < act->count;
516 count += sizeof(int))
517 len += sprintf(page + len, " %08X",
518 ((int *) (addr_t) act->cda)
520 len += sprintf(page + len, "\n");
523 printk(KERN_ERR "%s", page);
526 /* print failing CCW area */
528 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
529 act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
530 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
532 end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
534 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
535 " CCW %p: %08X %08X DAT:",
536 act, ((int *) act)[0], ((int *) act)[1]);
537 for (count = 0; count < 32 && count < act->count;
538 count += sizeof(int))
539 len += sprintf(page + len, " %08X",
540 ((int *) (addr_t) act->cda)
542 len += sprintf(page + len, "\n");
546 /* print last CCWs */
547 if (act < last - 2) {
549 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
551 while (act <= last) {
552 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
553 " CCW %p: %08X %08X DAT:",
554 act, ((int *) act)[0], ((int *) act)[1]);
555 for (count = 0; count < 32 && count < act->count;
556 count += sizeof(int))
557 len += sprintf(page + len, " %08X",
558 ((int *) (addr_t) act->cda)
560 len += sprintf(page + len, "\n");
564 printk(KERN_ERR "%s", page);
565 free_page((unsigned long) page);
569 * max_blocks is dependent on the amount of storage that is available
570 * in the static io buffer for each device. Currently each device has
571 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
572 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
573 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
574 * addition we have one define extent ccw + 16 bytes of data and a
575 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
577 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
578 * We want to fit two into the available memory so that we can immediately
579 * start the next request if one finishes off. That makes 100.1 blocks
580 * for one request. Give a little safety and the result is 96.
582 static struct dasd_discipline dasd_fba_discipline = {
583 .owner = THIS_MODULE,
587 .check_device = dasd_fba_check_characteristics,
588 .do_analysis = dasd_fba_do_analysis,
589 .fill_geometry = dasd_fba_fill_geometry,
590 .start_IO = dasd_start_IO,
591 .term_IO = dasd_term_IO,
592 .handle_terminated_request = dasd_fba_handle_terminated_request,
593 .erp_action = dasd_fba_erp_action,
594 .erp_postaction = dasd_fba_erp_postaction,
595 .handle_unsolicited_interrupt = dasd_fba_handle_unsolicited_interrupt,
596 .build_cp = dasd_fba_build_cp,
597 .free_cp = dasd_fba_free_cp,
598 .dump_sense = dasd_fba_dump_sense,
599 .dump_sense_dbf = dasd_fba_dump_sense_dbf,
600 .fill_info = dasd_fba_fill_info,
606 ASCEBC(dasd_fba_discipline.ebcname, 4);
607 return ccw_driver_register(&dasd_fba_driver);
611 dasd_fba_cleanup(void)
613 ccw_driver_unregister(&dasd_fba_driver);
616 module_init(dasd_fba_init);
617 module_exit(dasd_fba_cleanup);