1 // SPDX-License-Identifier: GPL-2.0
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Bugreports.to..: <Linux390@de.ibm.com>
5 * Copyright IBM Corp. 1999, 2009
8 #define KMSG_COMPONENT "dasd-fba"
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/ccwdev.h>
30 #endif /* PRINTK_HEADER */
31 #define PRINTK_HEADER "dasd(fba):"
33 #define FBA_DEFAULT_RETRIES 32
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;
43 static void *dasd_fba_zero_page;
45 struct dasd_fba_private {
46 struct dasd_fba_characteristics rdc_data;
49 static struct ccw_device_id dasd_fba_ids[] = {
50 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
51 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
52 { /* end of list */ },
55 MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
57 static struct ccw_driver dasd_fba_driver; /* see below */
59 dasd_fba_probe(struct ccw_device *cdev)
61 return dasd_generic_probe(cdev, &dasd_fba_discipline);
65 dasd_fba_set_online(struct ccw_device *cdev)
67 return dasd_generic_set_online(cdev, &dasd_fba_discipline);
70 static struct ccw_driver dasd_fba_driver = {
76 .probe = dasd_fba_probe,
77 .remove = dasd_generic_remove,
78 .set_offline = dasd_generic_set_offline,
79 .set_online = dasd_fba_set_online,
80 .notify = dasd_generic_notify,
81 .path_event = dasd_generic_path_event,
82 .freeze = dasd_generic_pm_freeze,
83 .thaw = dasd_generic_restore_device,
84 .restore = dasd_generic_restore_device,
85 .int_class = IRQIO_DAS,
89 define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
90 int blksize, int beg, int nr)
92 ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
95 ccw->cda = (__u32) __pa(data);
96 memset(data, 0, sizeof (struct DE_fba_data));
98 (data->mask).perm = 0x0;
100 (data->mask).perm = 0x1;
102 data->mask.perm = 0x2;
103 data->blk_size = blksize;
105 data->ext_end = nr - 1;
109 locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
110 int block_nr, int block_ct)
112 ccw->cmd_code = DASD_FBA_CCW_LOCATE;
115 ccw->cda = (__u32) __pa(data);
116 memset(data, 0, sizeof (struct LO_fba_data));
118 data->operation.cmd = 0x5;
120 data->operation.cmd = 0x6;
122 data->operation.cmd = 0x8;
123 data->blk_nr = block_nr;
124 data->blk_ct = block_ct;
128 dasd_fba_check_characteristics(struct dasd_device *device)
130 struct dasd_fba_private *private = device->private;
131 struct ccw_device *cdev = device->cdev;
132 struct dasd_block *block;
136 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
138 dev_warn(&device->cdev->dev,
139 "Allocating memory for private DASD "
143 device->private = private;
145 memset(private, 0, sizeof(*private));
147 block = dasd_alloc_block();
149 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate "
150 "dasd block structure");
151 device->private = NULL;
153 return PTR_ERR(block);
155 device->block = block;
156 block->base = device;
158 /* Read Device Characteristics */
159 rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC,
160 &private->rdc_data, 32);
162 DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device "
163 "characteristics returned error %d", rc);
164 device->block = NULL;
165 dasd_free_block(block);
166 device->private = NULL;
171 device->default_expires = DASD_EXPIRES;
172 device->default_retries = FBA_DEFAULT_RETRIES;
173 dasd_path_set_opm(device, LPM_ANYPATH);
175 readonly = dasd_device_is_ro(device);
177 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
179 /* FBA supports discard, set the according feature bit */
180 dasd_set_feature(cdev, DASD_FEATURE_DISCARD, 1);
182 dev_info(&device->cdev->dev,
183 "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB "
189 ((private->rdc_data.blk_bdsa *
190 (private->rdc_data.blk_size >> 9)) >> 11),
191 private->rdc_data.blk_size,
192 readonly ? ", read-only device" : "");
196 static int dasd_fba_do_analysis(struct dasd_block *block)
198 struct dasd_fba_private *private = block->base->private;
201 rc = dasd_check_blocksize(private->rdc_data.blk_size);
203 DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
204 private->rdc_data.blk_size);
207 block->blocks = private->rdc_data.blk_bdsa;
208 block->bp_block = private->rdc_data.blk_size;
209 block->s2b_shift = 0; /* bits to shift 512 to get a block */
210 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
215 static int dasd_fba_fill_geometry(struct dasd_block *block,
216 struct hd_geometry *geo)
218 if (dasd_check_blocksize(block->bp_block) != 0)
220 geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
222 geo->sectors = 128 >> block->s2b_shift;
227 dasd_fba_erp_action(struct dasd_ccw_req * cqr)
229 return dasd_default_erp_action;
233 dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
235 if (cqr->function == dasd_default_erp_action)
236 return dasd_default_erp_postaction;
238 DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
243 static void dasd_fba_check_for_device_change(struct dasd_device *device,
244 struct dasd_ccw_req *cqr,
249 /* first of all check for state change pending interrupt */
250 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
251 if ((irb->scsw.cmd.dstat & mask) == mask)
252 dasd_generic_handle_state_change(device);
257 * Builds a CCW with no data payload
259 static void ccw_write_no_data(struct ccw1 *ccw)
261 ccw->cmd_code = DASD_FBA_CCW_WRITE;
262 ccw->flags |= CCW_FLAG_SLI;
267 * Builds a CCW that writes only zeroes.
269 static void ccw_write_zero(struct ccw1 *ccw, int count)
271 ccw->cmd_code = DASD_FBA_CCW_WRITE;
272 ccw->flags |= CCW_FLAG_SLI;
274 ccw->cda = (__u32) (addr_t) dasd_fba_zero_page;
278 * Helper function to count the amount of necessary CCWs within a given range
279 * with 4k alignment and command chaining in mind.
281 static int count_ccws(sector_t first_rec, sector_t last_rec,
282 unsigned int blocks_per_page)
284 sector_t wz_stop = 0, d_stop = 0;
288 if (first_rec % blocks_per_page != 0) {
289 wz_stop = first_rec + blocks_per_page -
290 (first_rec % blocks_per_page) - 1;
291 if (wz_stop > last_rec)
293 cur_pos = wz_stop - first_rec + 1;
297 if (last_rec - (first_rec + cur_pos) + 1 >= blocks_per_page) {
298 if ((last_rec - blocks_per_page + 1) % blocks_per_page != 0)
299 d_stop = last_rec - ((last_rec - blocks_per_page + 1) %
304 cur_pos += d_stop - (first_rec + cur_pos) + 1;
308 if (cur_pos == 0 || first_rec + cur_pos - 1 < last_rec)
315 * This function builds a CCW request for block layer discard requests.
316 * Each page in the z/VM hypervisor that represents certain records of an FBA
317 * device will be padded with zeros. This is a special behaviour of the WRITE
318 * command which is triggered when no data payload is added to the CCW.
320 * Note: Due to issues in some z/VM versions, we can't fully utilise this
321 * special behaviour. We have to keep a 4k (or 8 block) alignment in mind to
322 * work around those issues and write actual zeroes to the unaligned parts in
323 * the request. This workaround might be removed in the future.
325 static struct dasd_ccw_req *dasd_fba_build_cp_discard(
326 struct dasd_device *memdev,
327 struct dasd_block *block,
330 struct LO_fba_data *LO_data;
331 struct dasd_ccw_req *cqr;
334 sector_t wz_stop = 0, d_stop = 0;
335 sector_t first_rec, last_rec;
337 unsigned int blksize = block->bp_block;
338 unsigned int blocks_per_page;
341 int cur_pos = 0; /* Current position within the extent */
347 first_rec = blk_rq_pos(req) >> block->s2b_shift;
349 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
350 count = last_rec - first_rec + 1;
352 blocks_per_page = BLOCKS_PER_PAGE(blksize);
353 nr_ccws = count_ccws(first_rec, last_rec, blocks_per_page);
355 /* define extent + nr_ccws * locate record + nr_ccws * single CCW */
356 cplength = 1 + 2 * nr_ccws;
357 datasize = sizeof(struct DE_fba_data) +
358 nr_ccws * (sizeof(struct LO_fba_data) + sizeof(struct ccw1));
360 cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev,
361 blk_mq_rq_to_pdu(req));
367 define_extent(ccw++, cqr->data, WRITE, blksize, first_rec, count);
368 LO_data = cqr->data + sizeof(struct DE_fba_data);
370 /* First part is not aligned. Calculate range to write zeroes. */
371 if (first_rec % blocks_per_page != 0) {
372 wz_stop = first_rec + blocks_per_page -
373 (first_rec % blocks_per_page) - 1;
374 if (wz_stop > last_rec)
376 wz_count = wz_stop - first_rec + 1;
378 ccw[-1].flags |= CCW_FLAG_CC;
379 locate_record(ccw++, LO_data++, WRITE, cur_pos, wz_count);
381 ccw[-1].flags |= CCW_FLAG_CC;
382 ccw_write_zero(ccw++, wz_count * blksize);
387 /* We can do proper discard when we've got at least blocks_per_page blocks. */
388 if (last_rec - (first_rec + cur_pos) + 1 >= blocks_per_page) {
389 /* is last record at page boundary? */
390 if ((last_rec - blocks_per_page + 1) % blocks_per_page != 0)
391 d_stop = last_rec - ((last_rec - blocks_per_page + 1) %
396 d_count = d_stop - (first_rec + cur_pos) + 1;
398 ccw[-1].flags |= CCW_FLAG_CC;
399 locate_record(ccw++, LO_data++, WRITE, cur_pos, d_count);
401 ccw[-1].flags |= CCW_FLAG_CC;
402 ccw_write_no_data(ccw++);
407 /* We might still have some bits left which need to be zeroed. */
408 if (cur_pos == 0 || first_rec + cur_pos - 1 < last_rec) {
410 wz_count = last_rec - d_stop;
411 else if (wz_stop != 0)
412 wz_count = last_rec - wz_stop;
416 ccw[-1].flags |= CCW_FLAG_CC;
417 locate_record(ccw++, LO_data++, WRITE, cur_pos, wz_count);
419 ccw[-1].flags |= CCW_FLAG_CC;
420 ccw_write_zero(ccw++, wz_count * blksize);
423 if (blk_noretry_request(req) ||
424 block->base->features & DASD_FEATURE_FAILFAST)
425 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
427 cqr->startdev = memdev;
428 cqr->memdev = memdev;
430 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
431 cqr->retries = memdev->default_retries;
432 cqr->buildclk = get_tod_clock();
433 cqr->status = DASD_CQR_FILLED;
438 static struct dasd_ccw_req *dasd_fba_build_cp_regular(
439 struct dasd_device *memdev,
440 struct dasd_block *block,
443 struct dasd_fba_private *private = block->base->private;
444 unsigned long *idaws;
445 struct LO_fba_data *LO_data;
446 struct dasd_ccw_req *cqr;
448 struct req_iterator iter;
451 int count, cidaw, cplength, datasize;
452 sector_t recid, first_rec, last_rec;
453 unsigned int blksize, off;
456 if (rq_data_dir(req) == READ) {
457 cmd = DASD_FBA_CCW_READ;
458 } else if (rq_data_dir(req) == WRITE) {
459 cmd = DASD_FBA_CCW_WRITE;
461 return ERR_PTR(-EINVAL);
462 blksize = block->bp_block;
463 /* Calculate record id of first and last block. */
464 first_rec = blk_rq_pos(req) >> block->s2b_shift;
466 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
467 /* Check struct bio and count the number of blocks for the request. */
470 rq_for_each_segment(bv, req, iter) {
471 if (bv.bv_len & (blksize - 1))
472 /* Fba can only do full blocks. */
473 return ERR_PTR(-EINVAL);
474 count += bv.bv_len >> (block->s2b_shift + 9);
475 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
476 cidaw += bv.bv_len / blksize;
479 if (count != last_rec - first_rec + 1)
480 return ERR_PTR(-EINVAL);
481 /* 1x define extent + 1x locate record + number of blocks */
482 cplength = 2 + count;
483 /* 1x define extent + 1x locate record */
484 datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
485 cidaw * sizeof(unsigned long);
487 * Find out number of additional locate record ccws if the device
488 * can't do data chaining.
490 if (private->rdc_data.mode.bits.data_chain == 0) {
491 cplength += count - 1;
492 datasize += (count - 1)*sizeof(struct LO_fba_data);
494 /* Allocate the ccw request. */
495 cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev,
496 blk_mq_rq_to_pdu(req));
500 /* First ccw is define extent. */
501 define_extent(ccw++, cqr->data, rq_data_dir(req),
502 block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
503 /* Build locate_record + read/write ccws. */
504 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
505 LO_data = (struct LO_fba_data *) (idaws + cidaw);
506 /* Locate record for all blocks for smart devices. */
507 if (private->rdc_data.mode.bits.data_chain != 0) {
508 ccw[-1].flags |= CCW_FLAG_CC;
509 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
512 rq_for_each_segment(bv, req, iter) {
513 dst = page_address(bv.bv_page) + bv.bv_offset;
514 if (dasd_page_cache) {
515 char *copy = kmem_cache_alloc(dasd_page_cache,
516 GFP_DMA | __GFP_NOWARN);
517 if (copy && rq_data_dir(req) == WRITE)
518 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
520 dst = copy + bv.bv_offset;
522 for (off = 0; off < bv.bv_len; off += blksize) {
523 /* Locate record for stupid devices. */
524 if (private->rdc_data.mode.bits.data_chain == 0) {
525 ccw[-1].flags |= CCW_FLAG_CC;
526 locate_record(ccw, LO_data++,
528 recid - first_rec, 1);
529 ccw->flags = CCW_FLAG_CC;
532 if (recid > first_rec)
533 ccw[-1].flags |= CCW_FLAG_DC;
535 ccw[-1].flags |= CCW_FLAG_CC;
538 ccw->count = block->bp_block;
539 if (idal_is_needed(dst, blksize)) {
540 ccw->cda = (__u32)(addr_t) idaws;
541 ccw->flags = CCW_FLAG_IDA;
542 idaws = idal_create_words(idaws, dst, blksize);
544 ccw->cda = (__u32)(addr_t) dst;
552 if (blk_noretry_request(req) ||
553 block->base->features & DASD_FEATURE_FAILFAST)
554 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
555 cqr->startdev = memdev;
556 cqr->memdev = memdev;
558 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
559 cqr->retries = memdev->default_retries;
560 cqr->buildclk = get_tod_clock();
561 cqr->status = DASD_CQR_FILLED;
565 static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device *memdev,
566 struct dasd_block *block,
569 if (req_op(req) == REQ_OP_DISCARD || req_op(req) == REQ_OP_WRITE_ZEROES)
570 return dasd_fba_build_cp_discard(memdev, block, req);
572 return dasd_fba_build_cp_regular(memdev, block, req);
576 dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
578 struct dasd_fba_private *private = cqr->block->base->private;
580 struct req_iterator iter;
583 unsigned int blksize, off;
586 if (!dasd_page_cache)
588 blksize = cqr->block->bp_block;
590 /* Skip over define extent & locate record. */
592 if (private->rdc_data.mode.bits.data_chain != 0)
594 rq_for_each_segment(bv, req, iter) {
595 dst = page_address(bv.bv_page) + bv.bv_offset;
596 for (off = 0; off < bv.bv_len; off += blksize) {
597 /* Skip locate record. */
598 if (private->rdc_data.mode.bits.data_chain == 0)
601 if (ccw->flags & CCW_FLAG_IDA)
602 cda = *((char **)((addr_t) ccw->cda));
604 cda = (char *)((addr_t) ccw->cda);
606 if (rq_data_dir(req) == READ)
607 memcpy(dst, cda, bv.bv_len);
608 kmem_cache_free(dasd_page_cache,
609 (void *)((addr_t)cda & PAGE_MASK));
617 status = cqr->status == DASD_CQR_DONE;
618 dasd_sfree_request(cqr, cqr->memdev);
622 static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
624 if (cqr->retries < 0)
625 cqr->status = DASD_CQR_FAILED;
627 cqr->status = DASD_CQR_FILLED;
631 dasd_fba_fill_info(struct dasd_device * device,
632 struct dasd_information2_t * info)
634 struct dasd_fba_private *private = device->private;
636 info->label_block = 1;
637 info->FBA_layout = 1;
638 info->format = DASD_FORMAT_LDL;
639 info->characteristics_size = sizeof(private->rdc_data);
640 memcpy(info->characteristics, &private->rdc_data,
641 sizeof(private->rdc_data));
642 info->confdata_size = 0;
647 dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
652 sense = (u64 *) dasd_get_sense(irb);
654 DBF_DEV_EVENT(DBF_EMERG, device,
655 "%s: %s %02x%02x%02x %016llx %016llx %016llx "
657 scsw_is_tm(&irb->scsw) ? "t" : "c",
658 scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
659 scsw_dstat(&irb->scsw), sense[0], sense[1],
662 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
663 "SORRY - NO VALID SENSE AVAILABLE\n");
669 dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
673 struct ccw1 *act, *end, *last;
674 int len, sl, sct, count;
676 page = (char *) get_zeroed_page(GFP_ATOMIC);
678 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
679 "No memory to dump sense data");
682 len = sprintf(page, PRINTK_HEADER
683 " I/O status report for device %s:\n",
684 dev_name(&device->cdev->dev));
685 len += sprintf(page + len, PRINTK_HEADER
686 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
687 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
688 len += sprintf(page + len, PRINTK_HEADER
689 " device %s: Failing CCW: %p\n",
690 dev_name(&device->cdev->dev),
691 (void *) (addr_t) irb->scsw.cmd.cpa);
692 if (irb->esw.esw0.erw.cons) {
693 for (sl = 0; sl < 4; sl++) {
694 len += sprintf(page + len, PRINTK_HEADER
695 " Sense(hex) %2d-%2d:",
696 (8 * sl), ((8 * sl) + 7));
698 for (sct = 0; sct < 8; sct++) {
699 len += sprintf(page + len, " %02x",
700 irb->ecw[8 * sl + sct]);
702 len += sprintf(page + len, "\n");
705 len += sprintf(page + len, PRINTK_HEADER
706 " SORRY - NO VALID SENSE AVAILABLE\n");
708 printk(KERN_ERR "%s", page);
710 /* dump the Channel Program */
711 /* print first CCWs (maximum 8) */
713 for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
714 end = min(act + 8, last);
715 len = sprintf(page, PRINTK_HEADER " Related CP in req: %p\n", req);
717 len += sprintf(page + len, PRINTK_HEADER
718 " CCW %p: %08X %08X DAT:",
719 act, ((int *) act)[0], ((int *) act)[1]);
720 for (count = 0; count < 32 && count < act->count;
721 count += sizeof(int))
722 len += sprintf(page + len, " %08X",
723 ((int *) (addr_t) act->cda)
725 len += sprintf(page + len, "\n");
728 printk(KERN_ERR "%s", page);
731 /* print failing CCW area */
733 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
734 act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
735 len += sprintf(page + len, PRINTK_HEADER "......\n");
737 end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
739 len += sprintf(page + len, PRINTK_HEADER
740 " CCW %p: %08X %08X DAT:",
741 act, ((int *) act)[0], ((int *) act)[1]);
742 for (count = 0; count < 32 && count < act->count;
743 count += sizeof(int))
744 len += sprintf(page + len, " %08X",
745 ((int *) (addr_t) act->cda)
747 len += sprintf(page + len, "\n");
751 /* print last CCWs */
752 if (act < last - 2) {
754 len += sprintf(page + len, PRINTK_HEADER "......\n");
756 while (act <= last) {
757 len += sprintf(page + len, PRINTK_HEADER
758 " CCW %p: %08X %08X DAT:",
759 act, ((int *) act)[0], ((int *) act)[1]);
760 for (count = 0; count < 32 && count < act->count;
761 count += sizeof(int))
762 len += sprintf(page + len, " %08X",
763 ((int *) (addr_t) act->cda)
765 len += sprintf(page + len, "\n");
769 printk(KERN_ERR "%s", page);
770 free_page((unsigned long) page);
774 * Initialize block layer request queue.
776 static void dasd_fba_setup_blk_queue(struct dasd_block *block)
778 unsigned int logical_block_size = block->bp_block;
779 struct request_queue *q = block->request_queue;
780 unsigned int max_bytes, max_discard_sectors;
783 max = DASD_FBA_MAX_BLOCKS << block->s2b_shift;
784 blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
785 q->limits.max_dev_sectors = max;
786 blk_queue_logical_block_size(q, logical_block_size);
787 blk_queue_max_hw_sectors(q, max);
788 blk_queue_max_segments(q, USHRT_MAX);
789 /* With page sized segments each segment can be translated into one idaw/tidaw */
790 blk_queue_max_segment_size(q, PAGE_SIZE);
791 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
793 q->limits.discard_granularity = logical_block_size;
794 q->limits.discard_alignment = PAGE_SIZE;
796 /* Calculate max_discard_sectors and make it PAGE aligned */
797 max_bytes = USHRT_MAX * logical_block_size;
798 max_bytes = ALIGN_DOWN(max_bytes, PAGE_SIZE);
799 max_discard_sectors = max_bytes / logical_block_size;
801 blk_queue_max_discard_sectors(q, max_discard_sectors);
802 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
803 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
806 static int dasd_fba_pe_handler(struct dasd_device *device, __u8 tbvpm)
808 return dasd_generic_verify_path(device, tbvpm);
811 static struct dasd_discipline dasd_fba_discipline = {
812 .owner = THIS_MODULE,
815 .check_device = dasd_fba_check_characteristics,
816 .do_analysis = dasd_fba_do_analysis,
817 .pe_handler = dasd_fba_pe_handler,
818 .setup_blk_queue = dasd_fba_setup_blk_queue,
819 .fill_geometry = dasd_fba_fill_geometry,
820 .start_IO = dasd_start_IO,
821 .term_IO = dasd_term_IO,
822 .handle_terminated_request = dasd_fba_handle_terminated_request,
823 .erp_action = dasd_fba_erp_action,
824 .erp_postaction = dasd_fba_erp_postaction,
825 .check_for_device_change = dasd_fba_check_for_device_change,
826 .build_cp = dasd_fba_build_cp,
827 .free_cp = dasd_fba_free_cp,
828 .dump_sense = dasd_fba_dump_sense,
829 .dump_sense_dbf = dasd_fba_dump_sense_dbf,
830 .fill_info = dasd_fba_fill_info,
838 ASCEBC(dasd_fba_discipline.ebcname, 4);
840 dasd_fba_zero_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
841 if (!dasd_fba_zero_page)
844 ret = ccw_driver_register(&dasd_fba_driver);
846 wait_for_device_probe();
852 dasd_fba_cleanup(void)
854 ccw_driver_unregister(&dasd_fba_driver);
855 free_page((unsigned long)dasd_fba_zero_page);
858 module_init(dasd_fba_init);
859 module_exit(dasd_fba_cleanup);