Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 1999, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 8 | #define KMSG_COMPONENT "dasd-fba" |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/stddef.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <asm/debug.h> |
| 13 | |
| 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> |
| 19 | |
| 20 | #include <asm/idals.h> |
| 21 | #include <asm/ebcdic.h> |
| 22 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/ccwdev.h> |
| 24 | |
| 25 | #include "dasd_int.h" |
| 26 | #include "dasd_fba.h" |
| 27 | |
| 28 | #ifdef PRINTK_HEADER |
| 29 | #undef PRINTK_HEADER |
| 30 | #endif /* PRINTK_HEADER */ |
| 31 | #define PRINTK_HEADER "dasd(fba):" |
| 32 | |
| 33 | #define DASD_FBA_CCW_WRITE 0x41 |
| 34 | #define DASD_FBA_CCW_READ 0x42 |
| 35 | #define DASD_FBA_CCW_LOCATE 0x43 |
| 36 | #define DASD_FBA_CCW_DEFINE_EXTENT 0x63 |
| 37 | |
| 38 | MODULE_LICENSE("GPL"); |
| 39 | |
| 40 | static struct dasd_discipline dasd_fba_discipline; |
| 41 | |
| 42 | struct dasd_fba_private { |
| 43 | struct dasd_fba_characteristics rdc_data; |
| 44 | }; |
| 45 | |
| 46 | static struct ccw_device_id dasd_fba_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 47 | { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1}, |
| 48 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { /* end of list */ }, |
| 50 | }; |
| 51 | |
| 52 | MODULE_DEVICE_TABLE(ccw, dasd_fba_ids); |
| 53 | |
| 54 | static struct ccw_driver dasd_fba_driver; /* see below */ |
| 55 | static int |
| 56 | dasd_fba_probe(struct ccw_device *cdev) |
| 57 | { |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 58 | return dasd_generic_probe(cdev, &dasd_fba_discipline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static int |
| 62 | dasd_fba_set_online(struct ccw_device *cdev) |
| 63 | { |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 64 | return dasd_generic_set_online(cdev, &dasd_fba_discipline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static struct ccw_driver dasd_fba_driver = { |
Sebastian Ott | 3bda058 | 2011-03-23 10:16:02 +0100 | [diff] [blame] | 68 | .driver = { |
| 69 | .name = "dasd-fba", |
| 70 | .owner = THIS_MODULE, |
| 71 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .ids = dasd_fba_ids, |
| 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, |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 78 | .path_event = dasd_generic_path_event, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 79 | .freeze = dasd_generic_pm_freeze, |
| 80 | .thaw = dasd_generic_restore_device, |
| 81 | .restore = dasd_generic_restore_device, |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 82 | .int_class = IOINT_DAS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 85 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw, |
| 87 | int blksize, int beg, int nr) |
| 88 | { |
| 89 | ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT; |
| 90 | ccw->flags = 0; |
| 91 | ccw->count = 16; |
| 92 | ccw->cda = (__u32) __pa(data); |
| 93 | memset(data, 0, sizeof (struct DE_fba_data)); |
| 94 | if (rw == WRITE) |
| 95 | (data->mask).perm = 0x0; |
| 96 | else if (rw == READ) |
| 97 | (data->mask).perm = 0x1; |
| 98 | else |
| 99 | data->mask.perm = 0x2; |
| 100 | data->blk_size = blksize; |
| 101 | data->ext_loc = beg; |
| 102 | data->ext_end = nr - 1; |
| 103 | } |
| 104 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 105 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw, |
| 107 | int block_nr, int block_ct) |
| 108 | { |
| 109 | ccw->cmd_code = DASD_FBA_CCW_LOCATE; |
| 110 | ccw->flags = 0; |
| 111 | ccw->count = 8; |
| 112 | ccw->cda = (__u32) __pa(data); |
| 113 | memset(data, 0, sizeof (struct LO_fba_data)); |
| 114 | if (rw == WRITE) |
| 115 | data->operation.cmd = 0x5; |
| 116 | else if (rw == READ) |
| 117 | data->operation.cmd = 0x6; |
| 118 | else |
| 119 | data->operation.cmd = 0x8; |
| 120 | data->blk_nr = block_nr; |
| 121 | data->blk_ct = block_ct; |
| 122 | } |
| 123 | |
| 124 | static int |
| 125 | dasd_fba_check_characteristics(struct dasd_device *device) |
| 126 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 127 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | struct dasd_fba_private *private; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 129 | struct ccw_device *cdev = device->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | int rc; |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 131 | int readonly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | private = (struct dasd_fba_private *) device->private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 134 | if (!private) { |
| 135 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); |
| 136 | if (!private) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 137 | dev_warn(&device->cdev->dev, |
| 138 | "Allocating memory for private DASD " |
| 139 | "data failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return -ENOMEM; |
| 141 | } |
| 142 | device->private = (void *) private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 143 | } else { |
| 144 | memset(private, 0, sizeof(*private)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 146 | block = dasd_alloc_block(); |
| 147 | if (IS_ERR(block)) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 148 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate " |
| 149 | "dasd block structure"); |
Cornelia Huck | 7337194 | 2008-07-17 17:16:43 +0200 | [diff] [blame] | 150 | device->private = NULL; |
| 151 | kfree(private); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 152 | return PTR_ERR(block); |
| 153 | } |
| 154 | device->block = block; |
| 155 | block->base = device; |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 158 | rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC, |
| 159 | &private->rdc_data, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (rc) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 161 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device " |
| 162 | "characteristics returned error %d", rc); |
Cornelia Huck | 7337194 | 2008-07-17 17:16:43 +0200 | [diff] [blame] | 163 | device->block = NULL; |
| 164 | dasd_free_block(block); |
| 165 | device->private = NULL; |
| 166 | kfree(private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return rc; |
| 168 | } |
| 169 | |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 170 | device->default_expires = DASD_EXPIRES; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 171 | device->path_data.opm = LPM_ANYPATH; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 172 | |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 173 | readonly = dasd_device_is_ro(device); |
| 174 | if (readonly) |
| 175 | set_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 176 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 177 | dev_info(&device->cdev->dev, |
| 178 | "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB " |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 179 | "and %d B/blk%s\n", |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 180 | cdev->id.dev_type, |
| 181 | cdev->id.dev_model, |
| 182 | cdev->id.cu_type, |
| 183 | cdev->id.cu_model, |
| 184 | ((private->rdc_data.blk_bdsa * |
| 185 | (private->rdc_data.blk_size >> 9)) >> 11), |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 186 | private->rdc_data.blk_size, |
| 187 | readonly ? ", read-only device" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 191 | static int dasd_fba_do_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | struct dasd_fba_private *private; |
| 194 | int sb, rc; |
| 195 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 196 | private = (struct dasd_fba_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | rc = dasd_check_blocksize(private->rdc_data.blk_size); |
| 198 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 199 | DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | private->rdc_data.blk_size); |
| 201 | return rc; |
| 202 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 203 | block->blocks = private->rdc_data.blk_bdsa; |
| 204 | block->bp_block = private->rdc_data.blk_size; |
| 205 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 207 | block->s2b_shift++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 211 | static int dasd_fba_fill_geometry(struct dasd_block *block, |
| 212 | struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 214 | if (dasd_check_blocksize(block->bp_block) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return -EINVAL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 216 | geo->cylinders = (block->blocks << block->s2b_shift) >> 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | geo->heads = 16; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 218 | geo->sectors = 128 >> block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | static dasd_erp_fn_t |
| 223 | dasd_fba_erp_action(struct dasd_ccw_req * cqr) |
| 224 | { |
| 225 | return dasd_default_erp_action; |
| 226 | } |
| 227 | |
| 228 | static dasd_erp_fn_t |
| 229 | dasd_fba_erp_postaction(struct dasd_ccw_req * cqr) |
| 230 | { |
| 231 | if (cqr->function == dasd_default_erp_action) |
| 232 | return dasd_default_erp_postaction; |
| 233 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 234 | DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | cqr->function); |
| 236 | return NULL; |
| 237 | } |
| 238 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 239 | static void dasd_fba_check_for_device_change(struct dasd_device *device, |
| 240 | struct dasd_ccw_req *cqr, |
| 241 | struct irb *irb) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 242 | { |
| 243 | char mask; |
| 244 | |
| 245 | /* first of all check for state change pending interrupt */ |
| 246 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 247 | if ((irb->scsw.cmd.dstat & mask) == mask) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 248 | dasd_generic_handle_state_change(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev, |
| 252 | struct dasd_block *block, |
| 253 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | struct dasd_fba_private *private; |
| 256 | unsigned long *idaws; |
| 257 | struct LO_fba_data *LO_data; |
| 258 | struct dasd_ccw_req *cqr; |
| 259 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 260 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | struct bio_vec *bv; |
| 262 | char *dst; |
| 263 | int count, cidaw, cplength, datasize; |
| 264 | sector_t recid, first_rec, last_rec; |
| 265 | unsigned int blksize, off; |
| 266 | unsigned char cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 268 | private = (struct dasd_fba_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (rq_data_dir(req) == READ) { |
| 270 | cmd = DASD_FBA_CCW_READ; |
| 271 | } else if (rq_data_dir(req) == WRITE) { |
| 272 | cmd = DASD_FBA_CCW_WRITE; |
| 273 | } else |
| 274 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 275 | blksize = block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* Calculate record id of first and last block. */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 277 | first_rec = blk_rq_pos(req) >> block->s2b_shift; |
| 278 | last_rec = |
| 279 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* Check struct bio and count the number of blocks for the request. */ |
| 281 | count = 0; |
| 282 | cidaw = 0; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 283 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 284 | if (bv->bv_len & (blksize - 1)) |
| 285 | /* Fba can only do full blocks. */ |
| 286 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 287 | count += bv->bv_len >> (block->s2b_shift + 9); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 288 | #if defined(CONFIG_64BIT) |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 289 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
| 290 | cidaw += bv->bv_len / blksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | /* Paranoia. */ |
| 294 | if (count != last_rec - first_rec + 1) |
| 295 | return ERR_PTR(-EINVAL); |
| 296 | /* 1x define extent + 1x locate record + number of blocks */ |
| 297 | cplength = 2 + count; |
| 298 | /* 1x define extent + 1x locate record */ |
| 299 | datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) + |
| 300 | cidaw * sizeof(unsigned long); |
| 301 | /* |
| 302 | * Find out number of additional locate record ccws if the device |
| 303 | * can't do data chaining. |
| 304 | */ |
| 305 | if (private->rdc_data.mode.bits.data_chain == 0) { |
| 306 | cplength += count - 1; |
| 307 | datasize += (count - 1)*sizeof(struct LO_fba_data); |
| 308 | } |
| 309 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 310 | cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (IS_ERR(cqr)) |
| 312 | return cqr; |
| 313 | ccw = cqr->cpaddr; |
| 314 | /* First ccw is define extent. */ |
| 315 | define_extent(ccw++, cqr->data, rq_data_dir(req), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 316 | block->bp_block, blk_rq_pos(req), blk_rq_sectors(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* Build locate_record + read/write ccws. */ |
| 318 | idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data)); |
| 319 | LO_data = (struct LO_fba_data *) (idaws + cidaw); |
| 320 | /* Locate record for all blocks for smart devices. */ |
| 321 | if (private->rdc_data.mode.bits.data_chain != 0) { |
| 322 | ccw[-1].flags |= CCW_FLAG_CC; |
| 323 | locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count); |
| 324 | } |
| 325 | recid = first_rec; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 326 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 328 | if (dasd_page_cache) { |
| 329 | char *copy = kmem_cache_alloc(dasd_page_cache, |
Christoph Lameter | 441e143 | 2006-12-06 20:33:19 -0800 | [diff] [blame] | 330 | GFP_DMA | __GFP_NOWARN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (copy && rq_data_dir(req) == WRITE) |
| 332 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); |
| 333 | if (copy) |
| 334 | dst = copy + bv->bv_offset; |
| 335 | } |
| 336 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 337 | /* Locate record for stupid devices. */ |
| 338 | if (private->rdc_data.mode.bits.data_chain == 0) { |
| 339 | ccw[-1].flags |= CCW_FLAG_CC; |
| 340 | locate_record(ccw, LO_data++, |
| 341 | rq_data_dir(req), |
| 342 | recid - first_rec, 1); |
| 343 | ccw->flags = CCW_FLAG_CC; |
| 344 | ccw++; |
| 345 | } else { |
| 346 | if (recid > first_rec) |
| 347 | ccw[-1].flags |= CCW_FLAG_DC; |
| 348 | else |
| 349 | ccw[-1].flags |= CCW_FLAG_CC; |
| 350 | } |
| 351 | ccw->cmd_code = cmd; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 352 | ccw->count = block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (idal_is_needed(dst, blksize)) { |
| 354 | ccw->cda = (__u32)(addr_t) idaws; |
| 355 | ccw->flags = CCW_FLAG_IDA; |
| 356 | idaws = idal_create_words(idaws, dst, blksize); |
| 357 | } else { |
| 358 | ccw->cda = (__u32)(addr_t) dst; |
| 359 | ccw->flags = 0; |
| 360 | } |
| 361 | ccw++; |
| 362 | dst += blksize; |
| 363 | recid++; |
| 364 | } |
| 365 | } |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 366 | if (blk_noretry_request(req) || |
| 367 | block->base->features & DASD_FEATURE_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 368 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 369 | cqr->startdev = memdev; |
| 370 | cqr->memdev = memdev; |
| 371 | cqr->block = block; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 372 | cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */ |
Horst Hummel | d61f6f3 | 2005-07-27 11:45:02 -0700 | [diff] [blame] | 373 | cqr->retries = 32; |
| 374 | cqr->buildclk = get_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | cqr->status = DASD_CQR_FILLED; |
| 376 | return cqr; |
| 377 | } |
| 378 | |
| 379 | static int |
| 380 | dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 381 | { |
| 382 | struct dasd_fba_private *private; |
| 383 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 384 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | struct bio_vec *bv; |
| 386 | char *dst, *cda; |
| 387 | unsigned int blksize, off; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 388 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | if (!dasd_page_cache) |
| 391 | goto out; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 392 | private = (struct dasd_fba_private *) cqr->block->base->private; |
| 393 | blksize = cqr->block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | ccw = cqr->cpaddr; |
| 395 | /* Skip over define extent & locate record. */ |
| 396 | ccw++; |
| 397 | if (private->rdc_data.mode.bits.data_chain != 0) |
| 398 | ccw++; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 399 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 401 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 402 | /* Skip locate record. */ |
| 403 | if (private->rdc_data.mode.bits.data_chain == 0) |
| 404 | ccw++; |
| 405 | if (dst) { |
| 406 | if (ccw->flags & CCW_FLAG_IDA) |
| 407 | cda = *((char **)((addr_t) ccw->cda)); |
| 408 | else |
| 409 | cda = (char *)((addr_t) ccw->cda); |
| 410 | if (dst != cda) { |
| 411 | if (rq_data_dir(req) == READ) |
| 412 | memcpy(dst, cda, bv->bv_len); |
| 413 | kmem_cache_free(dasd_page_cache, |
| 414 | (void *)((addr_t)cda & PAGE_MASK)); |
| 415 | } |
| 416 | dst = NULL; |
| 417 | } |
| 418 | ccw++; |
| 419 | } |
| 420 | } |
| 421 | out: |
| 422 | status = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 423 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | return status; |
| 425 | } |
| 426 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 427 | static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr) |
| 428 | { |
| 429 | cqr->status = DASD_CQR_FILLED; |
| 430 | }; |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | static int |
| 433 | dasd_fba_fill_info(struct dasd_device * device, |
| 434 | struct dasd_information2_t * info) |
| 435 | { |
| 436 | info->label_block = 1; |
| 437 | info->FBA_layout = 1; |
| 438 | info->format = DASD_FORMAT_LDL; |
| 439 | info->characteristics_size = sizeof(struct dasd_fba_characteristics); |
| 440 | memcpy(info->characteristics, |
| 441 | &((struct dasd_fba_private *) device->private)->rdc_data, |
| 442 | sizeof (struct dasd_fba_characteristics)); |
| 443 | info->confdata_size = 0; |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static void |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 448 | dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
| 449 | char *reason) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 450 | { |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 451 | u64 *sense; |
| 452 | |
| 453 | sense = (u64 *) dasd_get_sense(irb); |
| 454 | if (sense) { |
| 455 | DBF_DEV_EVENT(DBF_EMERG, device, |
| 456 | "%s: %s %02x%02x%02x %016llx %016llx %016llx " |
| 457 | "%016llx", reason, |
| 458 | scsw_is_tm(&irb->scsw) ? "t" : "c", |
| 459 | scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw), |
| 460 | scsw_dstat(&irb->scsw), sense[0], sense[1], |
| 461 | sense[2], sense[3]); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 462 | } else { |
| 463 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", |
| 464 | "SORRY - NO VALID SENSE AVAILABLE\n"); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | |
| 469 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req, |
| 471 | struct irb *irb) |
| 472 | { |
| 473 | char *page; |
| 474 | struct ccw1 *act, *end, *last; |
| 475 | int len, sl, sct, count; |
| 476 | |
| 477 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 478 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 479 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | "No memory to dump sense data"); |
| 481 | return; |
| 482 | } |
| 483 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 484 | " I/O status report for device %s:\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 485 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 487 | " in req: %p CS: 0x%02X DS: 0x%02X\n", req, |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 488 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 490 | " device %s: Failing CCW: %p\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 491 | dev_name(&device->cdev->dev), |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 492 | (void *) (addr_t) irb->scsw.cmd.cpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (irb->esw.esw0.erw.cons) { |
| 494 | for (sl = 0; sl < 4; sl++) { |
| 495 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 496 | " Sense(hex) %2d-%2d:", |
| 497 | (8 * sl), ((8 * sl) + 7)); |
| 498 | |
| 499 | for (sct = 0; sct < 8; sct++) { |
| 500 | len += sprintf(page + len, " %02x", |
| 501 | irb->ecw[8 * sl + sct]); |
| 502 | } |
| 503 | len += sprintf(page + len, "\n"); |
| 504 | } |
| 505 | } else { |
| 506 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 507 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
| 508 | } |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 509 | printk(KERN_ERR "%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | /* dump the Channel Program */ |
| 512 | /* print first CCWs (maximum 8) */ |
| 513 | act = req->cpaddr; |
| 514 | for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); |
| 515 | end = min(act + 8, last); |
| 516 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 517 | " Related CP in req: %p\n", req); |
| 518 | while (act <= end) { |
| 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) |
| 526 | [(count>>2)]); |
| 527 | len += sprintf(page + len, "\n"); |
| 528 | act++; |
| 529 | } |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 530 | printk(KERN_ERR "%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | |
| 533 | /* print failing CCW area */ |
| 534 | len = 0; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 535 | if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) { |
| 536 | act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); |
| 538 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 539 | end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | while (act <= end) { |
| 541 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 542 | " CCW %p: %08X %08X DAT:", |
| 543 | act, ((int *) act)[0], ((int *) act)[1]); |
| 544 | for (count = 0; count < 32 && count < act->count; |
| 545 | count += sizeof(int)) |
| 546 | len += sprintf(page + len, " %08X", |
| 547 | ((int *) (addr_t) act->cda) |
| 548 | [(count>>2)]); |
| 549 | len += sprintf(page + len, "\n"); |
| 550 | act++; |
| 551 | } |
| 552 | |
| 553 | /* print last CCWs */ |
| 554 | if (act < last - 2) { |
| 555 | act = last - 2; |
| 556 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); |
| 557 | } |
| 558 | while (act <= last) { |
| 559 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 560 | " CCW %p: %08X %08X DAT:", |
| 561 | act, ((int *) act)[0], ((int *) act)[1]); |
| 562 | for (count = 0; count < 32 && count < act->count; |
| 563 | count += sizeof(int)) |
| 564 | len += sprintf(page + len, " %08X", |
| 565 | ((int *) (addr_t) act->cda) |
| 566 | [(count>>2)]); |
| 567 | len += sprintf(page + len, "\n"); |
| 568 | act++; |
| 569 | } |
| 570 | if (len > 0) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 571 | printk(KERN_ERR "%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | free_page((unsigned long) page); |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | * max_blocks is dependent on the amount of storage that is available |
| 577 | * in the static io buffer for each device. Currently each device has |
| 578 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has |
| 579 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use |
| 580 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 581 | * addition we have one define extent ccw + 16 bytes of data and a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | * locate record ccw for each block (stupid devices!) + 16 bytes of data. |
| 583 | * That makes: |
| 584 | * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum. |
| 585 | * We want to fit two into the available memory so that we can immediately |
| 586 | * start the next request if one finishes off. That makes 100.1 blocks |
| 587 | * for one request. Give a little safety and the result is 96. |
| 588 | */ |
| 589 | static struct dasd_discipline dasd_fba_discipline = { |
| 590 | .owner = THIS_MODULE, |
| 591 | .name = "FBA ", |
| 592 | .ebcname = "FBA ", |
| 593 | .max_blocks = 96, |
| 594 | .check_device = dasd_fba_check_characteristics, |
| 595 | .do_analysis = dasd_fba_do_analysis, |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 596 | .verify_path = dasd_generic_verify_path, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | .fill_geometry = dasd_fba_fill_geometry, |
| 598 | .start_IO = dasd_start_IO, |
| 599 | .term_IO = dasd_term_IO, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 600 | .handle_terminated_request = dasd_fba_handle_terminated_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | .erp_action = dasd_fba_erp_action, |
| 602 | .erp_postaction = dasd_fba_erp_postaction, |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 603 | .check_for_device_change = dasd_fba_check_for_device_change, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | .build_cp = dasd_fba_build_cp, |
| 605 | .free_cp = dasd_fba_free_cp, |
| 606 | .dump_sense = dasd_fba_dump_sense, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 607 | .dump_sense_dbf = dasd_fba_dump_sense_dbf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | .fill_info = dasd_fba_fill_info, |
| 609 | }; |
| 610 | |
| 611 | static int __init |
| 612 | dasd_fba_init(void) |
| 613 | { |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 614 | int ret; |
| 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | ASCEBC(dasd_fba_discipline.ebcname, 4); |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 617 | ret = ccw_driver_register(&dasd_fba_driver); |
| 618 | if (!ret) |
| 619 | wait_for_device_probe(); |
| 620 | |
| 621 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static void __exit |
| 625 | dasd_fba_cleanup(void) |
| 626 | { |
| 627 | ccw_driver_unregister(&dasd_fba_driver); |
| 628 | } |
| 629 | |
| 630 | module_init(dasd_fba_init); |
| 631 | module_exit(dasd_fba_cleanup); |