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