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_eckd.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
| 8 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/stddef.h> |
| 13 | #include <linux/kernel.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> |
| 19 | |
| 20 | #include <asm/debug.h> |
| 21 | #include <asm/idals.h> |
| 22 | #include <asm/ebcdic.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/todclk.h> |
| 25 | #include <asm/uaccess.h> |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 26 | #include <asm/cio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/ccwdev.h> |
| 28 | |
| 29 | #include "dasd_int.h" |
| 30 | #include "dasd_eckd.h" |
| 31 | |
| 32 | #ifdef PRINTK_HEADER |
| 33 | #undef PRINTK_HEADER |
| 34 | #endif /* PRINTK_HEADER */ |
| 35 | #define PRINTK_HEADER "dasd(eckd):" |
| 36 | |
| 37 | #define ECKD_C0(i) (i->home_bytes) |
| 38 | #define ECKD_F(i) (i->formula) |
| 39 | #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\ |
| 40 | (i->factors.f_0x02.f1)) |
| 41 | #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\ |
| 42 | (i->factors.f_0x02.f2)) |
| 43 | #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\ |
| 44 | (i->factors.f_0x02.f3)) |
| 45 | #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0) |
| 46 | #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0) |
| 47 | #define ECKD_F6(i) (i->factor6) |
| 48 | #define ECKD_F7(i) (i->factor7) |
| 49 | #define ECKD_F8(i) (i->factor8) |
| 50 | |
| 51 | MODULE_LICENSE("GPL"); |
| 52 | |
| 53 | static struct dasd_discipline dasd_eckd_discipline; |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* The ccw bus type uses this table to find devices that it sends to |
| 56 | * dasd_eckd_probe */ |
| 57 | static struct ccw_device_id dasd_eckd_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 58 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
| 59 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, |
| 60 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3}, |
| 61 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
| 62 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, |
| 63 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, |
| 64 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, |
| 65 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, |
| 66 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, |
| 67 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { /* end of list */ }, |
| 69 | }; |
| 70 | |
| 71 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); |
| 72 | |
| 73 | static struct ccw_driver dasd_eckd_driver; /* see below */ |
| 74 | |
| 75 | /* initial attempt at a probe function. this can be simplified once |
| 76 | * the other detection code is gone */ |
| 77 | static int |
| 78 | dasd_eckd_probe (struct ccw_device *cdev) |
| 79 | { |
| 80 | int ret; |
| 81 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 82 | /* set ECKD specific ccw-device options */ |
| 83 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE); |
| 84 | if (ret) { |
| 85 | printk(KERN_WARNING |
| 86 | "dasd_eckd_probe: could not set ccw-device options " |
| 87 | "for %s\n", cdev->dev.bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return ret; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 89 | } |
| 90 | ret = dasd_generic_probe(cdev, &dasd_eckd_discipline); |
| 91 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static int |
| 95 | dasd_eckd_set_online(struct ccw_device *cdev) |
| 96 | { |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 97 | return dasd_generic_set_online(cdev, &dasd_eckd_discipline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static struct ccw_driver dasd_eckd_driver = { |
| 101 | .name = "dasd-eckd", |
| 102 | .owner = THIS_MODULE, |
| 103 | .ids = dasd_eckd_ids, |
| 104 | .probe = dasd_eckd_probe, |
| 105 | .remove = dasd_generic_remove, |
| 106 | .set_offline = dasd_generic_set_offline, |
| 107 | .set_online = dasd_eckd_set_online, |
| 108 | .notify = dasd_generic_notify, |
| 109 | }; |
| 110 | |
| 111 | static const int sizes_trk0[] = { 28, 148, 84 }; |
| 112 | #define LABEL_SIZE 140 |
| 113 | |
| 114 | static inline unsigned int |
| 115 | round_up_multiple(unsigned int no, unsigned int mult) |
| 116 | { |
| 117 | int rem = no % mult; |
| 118 | return (rem ? no - rem + mult : no); |
| 119 | } |
| 120 | |
| 121 | static inline unsigned int |
| 122 | ceil_quot(unsigned int d1, unsigned int d2) |
| 123 | { |
| 124 | return (d1 + (d2 - 1)) / d2; |
| 125 | } |
| 126 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 127 | static unsigned int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | recs_per_track(struct dasd_eckd_characteristics * rdc, |
| 129 | unsigned int kl, unsigned int dl) |
| 130 | { |
| 131 | int dn, kn; |
| 132 | |
| 133 | switch (rdc->dev_type) { |
| 134 | case 0x3380: |
| 135 | if (kl) |
| 136 | return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) + |
| 137 | ceil_quot(dl + 12, 32)); |
| 138 | else |
| 139 | return 1499 / (15 + ceil_quot(dl + 12, 32)); |
| 140 | case 0x3390: |
| 141 | dn = ceil_quot(dl + 6, 232) + 1; |
| 142 | if (kl) { |
| 143 | kn = ceil_quot(kl + 6, 232) + 1; |
| 144 | return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) + |
| 145 | 9 + ceil_quot(dl + 6 * dn, 34)); |
| 146 | } else |
| 147 | return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34)); |
| 148 | case 0x9345: |
| 149 | dn = ceil_quot(dl + 6, 232) + 1; |
| 150 | if (kl) { |
| 151 | kn = ceil_quot(kl + 6, 232) + 1; |
| 152 | return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) + |
| 153 | ceil_quot(dl + 6 * dn, 34)); |
| 154 | } else |
| 155 | return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34)); |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 160 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | check_XRC (struct ccw1 *de_ccw, |
| 162 | struct DE_eckd_data *data, |
| 163 | struct dasd_device *device) |
| 164 | { |
| 165 | struct dasd_eckd_private *private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 166 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | private = (struct dasd_eckd_private *) device->private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 169 | if (!private->rdc_data.facilities.XRC_supported) |
| 170 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* switch on System Time Stamp - needed for XRC Support */ |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 173 | data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */ |
| 174 | data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */ |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 175 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 176 | rc = get_sync_clock(&data->ep_sys_time); |
| 177 | /* Ignore return code if sync clock is switched off. */ |
| 178 | if (rc == -ENOSYS || rc == -EACCES) |
| 179 | rc = 0; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 180 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 181 | de_ccw->count = sizeof(struct DE_eckd_data); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 182 | de_ccw->flags |= CCW_FLAG_SLI; |
| 183 | return rc; |
| 184 | } |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 185 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 186 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | define_extent(struct ccw1 * ccw, struct DE_eckd_data * data, int trk, |
| 188 | int totrk, int cmd, struct dasd_device * device) |
| 189 | { |
| 190 | struct dasd_eckd_private *private; |
| 191 | struct ch_t geo, beg, end; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 192 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | private = (struct dasd_eckd_private *) device->private; |
| 195 | |
| 196 | ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT; |
| 197 | ccw->flags = 0; |
| 198 | ccw->count = 16; |
| 199 | ccw->cda = (__u32) __pa(data); |
| 200 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 201 | memset(data, 0, sizeof(struct DE_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | switch (cmd) { |
| 203 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 204 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 205 | case DASD_ECKD_CCW_READ: |
| 206 | case DASD_ECKD_CCW_READ_MT: |
| 207 | case DASD_ECKD_CCW_READ_CKD: |
| 208 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 209 | case DASD_ECKD_CCW_READ_KD: |
| 210 | case DASD_ECKD_CCW_READ_KD_MT: |
| 211 | case DASD_ECKD_CCW_READ_COUNT: |
| 212 | data->mask.perm = 0x1; |
| 213 | data->attributes.operation = private->attrib.operation; |
| 214 | break; |
| 215 | case DASD_ECKD_CCW_WRITE: |
| 216 | case DASD_ECKD_CCW_WRITE_MT: |
| 217 | case DASD_ECKD_CCW_WRITE_KD: |
| 218 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 219 | data->mask.perm = 0x02; |
| 220 | data->attributes.operation = private->attrib.operation; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 221 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | break; |
| 223 | case DASD_ECKD_CCW_WRITE_CKD: |
| 224 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 225 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 226 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | break; |
| 228 | case DASD_ECKD_CCW_ERASE: |
| 229 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 230 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 231 | data->mask.perm = 0x3; |
| 232 | data->mask.auth = 0x1; |
| 233 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 234 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | break; |
| 236 | default: |
| 237 | DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd); |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | data->attributes.mode = 0x3; /* ECKD */ |
| 242 | |
| 243 | if ((private->rdc_data.cu_type == 0x2105 || |
| 244 | private->rdc_data.cu_type == 0x2107 || |
| 245 | private->rdc_data.cu_type == 0x1750) |
| 246 | && !(private->uses_cdl && trk < 2)) |
| 247 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ |
| 248 | |
| 249 | geo.cyl = private->rdc_data.no_cyl; |
| 250 | geo.head = private->rdc_data.trk_per_cyl; |
| 251 | beg.cyl = trk / geo.head; |
| 252 | beg.head = trk % geo.head; |
| 253 | end.cyl = totrk / geo.head; |
| 254 | end.head = totrk % geo.head; |
| 255 | |
| 256 | /* check for sequential prestage - enhance cylinder range */ |
| 257 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || |
| 258 | data->attributes.operation == DASD_SEQ_ACCESS) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 259 | |
| 260 | if (end.cyl + private->attrib.nr_cyl < geo.cyl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | end.cyl += private->attrib.nr_cyl; |
| 262 | else |
| 263 | end.cyl = (geo.cyl - 1); |
| 264 | } |
| 265 | |
| 266 | data->beg_ext.cyl = beg.cyl; |
| 267 | data->beg_ext.head = beg.head; |
| 268 | data->end_ext.cyl = end.cyl; |
| 269 | data->end_ext.head = end.head; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 270 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 273 | static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata, |
| 274 | struct dasd_device *device) |
| 275 | { |
| 276 | struct dasd_eckd_private *private; |
| 277 | int rc; |
| 278 | |
| 279 | private = (struct dasd_eckd_private *) device->private; |
| 280 | if (!private->rdc_data.facilities.XRC_supported) |
| 281 | return 0; |
| 282 | |
| 283 | /* switch on System Time Stamp - needed for XRC Support */ |
| 284 | pfxdata->define_extend.ga_extended |= 0x08; /* 'Time Stamp Valid' */ |
| 285 | pfxdata->define_extend.ga_extended |= 0x02; /* 'Extended Parameter' */ |
| 286 | pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */ |
| 287 | |
| 288 | rc = get_sync_clock(&pfxdata->define_extend.ep_sys_time); |
| 289 | /* Ignore return code if sync clock is switched off. */ |
| 290 | if (rc == -ENOSYS || rc == -EACCES) |
| 291 | rc = 0; |
| 292 | return rc; |
| 293 | } |
| 294 | |
| 295 | static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, int trk, |
| 296 | int totrk, int cmd, struct dasd_device *basedev, |
| 297 | struct dasd_device *startdev) |
| 298 | { |
| 299 | struct dasd_eckd_private *basepriv, *startpriv; |
| 300 | struct DE_eckd_data *data; |
| 301 | struct ch_t geo, beg, end; |
| 302 | int rc = 0; |
| 303 | |
| 304 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 305 | startpriv = (struct dasd_eckd_private *) startdev->private; |
| 306 | data = &pfxdata->define_extend; |
| 307 | |
| 308 | ccw->cmd_code = DASD_ECKD_CCW_PFX; |
| 309 | ccw->flags = 0; |
| 310 | ccw->count = sizeof(*pfxdata); |
| 311 | ccw->cda = (__u32) __pa(pfxdata); |
| 312 | |
| 313 | memset(pfxdata, 0, sizeof(*pfxdata)); |
| 314 | /* prefix data */ |
| 315 | pfxdata->format = 0; |
| 316 | pfxdata->base_address = basepriv->conf_data.ned1.unit_addr; |
| 317 | pfxdata->base_lss = basepriv->conf_data.ned1.ID; |
| 318 | pfxdata->validity.define_extend = 1; |
| 319 | |
| 320 | /* private uid is kept up to date, conf_data may be outdated */ |
| 321 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 322 | pfxdata->validity.verify_base = 1; |
| 323 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 324 | pfxdata->validity.hyper_pav = 1; |
| 325 | } |
| 326 | |
| 327 | /* define extend data (mostly)*/ |
| 328 | switch (cmd) { |
| 329 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 330 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 331 | case DASD_ECKD_CCW_READ: |
| 332 | case DASD_ECKD_CCW_READ_MT: |
| 333 | case DASD_ECKD_CCW_READ_CKD: |
| 334 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 335 | case DASD_ECKD_CCW_READ_KD: |
| 336 | case DASD_ECKD_CCW_READ_KD_MT: |
| 337 | case DASD_ECKD_CCW_READ_COUNT: |
| 338 | data->mask.perm = 0x1; |
| 339 | data->attributes.operation = basepriv->attrib.operation; |
| 340 | break; |
| 341 | case DASD_ECKD_CCW_WRITE: |
| 342 | case DASD_ECKD_CCW_WRITE_MT: |
| 343 | case DASD_ECKD_CCW_WRITE_KD: |
| 344 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 345 | data->mask.perm = 0x02; |
| 346 | data->attributes.operation = basepriv->attrib.operation; |
| 347 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 348 | break; |
| 349 | case DASD_ECKD_CCW_WRITE_CKD: |
| 350 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 351 | data->attributes.operation = DASD_BYPASS_CACHE; |
| 352 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 353 | break; |
| 354 | case DASD_ECKD_CCW_ERASE: |
| 355 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 356 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 357 | data->mask.perm = 0x3; |
| 358 | data->mask.auth = 0x1; |
| 359 | data->attributes.operation = DASD_BYPASS_CACHE; |
| 360 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 361 | break; |
| 362 | default: |
| 363 | DEV_MESSAGE(KERN_ERR, basedev, "unknown opcode 0x%x", cmd); |
| 364 | break; |
| 365 | } |
| 366 | |
| 367 | data->attributes.mode = 0x3; /* ECKD */ |
| 368 | |
| 369 | if ((basepriv->rdc_data.cu_type == 0x2105 || |
| 370 | basepriv->rdc_data.cu_type == 0x2107 || |
| 371 | basepriv->rdc_data.cu_type == 0x1750) |
| 372 | && !(basepriv->uses_cdl && trk < 2)) |
| 373 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ |
| 374 | |
| 375 | geo.cyl = basepriv->rdc_data.no_cyl; |
| 376 | geo.head = basepriv->rdc_data.trk_per_cyl; |
| 377 | beg.cyl = trk / geo.head; |
| 378 | beg.head = trk % geo.head; |
| 379 | end.cyl = totrk / geo.head; |
| 380 | end.head = totrk % geo.head; |
| 381 | |
| 382 | /* check for sequential prestage - enhance cylinder range */ |
| 383 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || |
| 384 | data->attributes.operation == DASD_SEQ_ACCESS) { |
| 385 | |
| 386 | if (end.cyl + basepriv->attrib.nr_cyl < geo.cyl) |
| 387 | end.cyl += basepriv->attrib.nr_cyl; |
| 388 | else |
| 389 | end.cyl = (geo.cyl - 1); |
| 390 | } |
| 391 | |
| 392 | data->beg_ext.cyl = beg.cyl; |
| 393 | data->beg_ext.head = beg.head; |
| 394 | data->end_ext.cyl = end.cyl; |
| 395 | data->end_ext.head = end.head; |
| 396 | return rc; |
| 397 | } |
| 398 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 399 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk, |
| 401 | int rec_on_trk, int no_rec, int cmd, |
| 402 | struct dasd_device * device, int reclen) |
| 403 | { |
| 404 | struct dasd_eckd_private *private; |
| 405 | int sector; |
| 406 | int dn, d; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | private = (struct dasd_eckd_private *) device->private; |
| 409 | |
| 410 | DBF_DEV_EVENT(DBF_INFO, device, |
| 411 | "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d", |
| 412 | trk, rec_on_trk, no_rec, cmd, reclen); |
| 413 | |
| 414 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD; |
| 415 | ccw->flags = 0; |
| 416 | ccw->count = 16; |
| 417 | ccw->cda = (__u32) __pa(data); |
| 418 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 419 | memset(data, 0, sizeof(struct LO_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | sector = 0; |
| 421 | if (rec_on_trk) { |
| 422 | switch (private->rdc_data.dev_type) { |
| 423 | case 0x3390: |
| 424 | dn = ceil_quot(reclen + 6, 232); |
| 425 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); |
| 426 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 427 | break; |
| 428 | case 0x3380: |
| 429 | d = 7 + ceil_quot(reclen + 12, 32); |
| 430 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 431 | break; |
| 432 | } |
| 433 | } |
| 434 | data->sector = sector; |
| 435 | data->count = no_rec; |
| 436 | switch (cmd) { |
| 437 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 438 | data->operation.orientation = 0x3; |
| 439 | data->operation.operation = 0x03; |
| 440 | break; |
| 441 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 442 | data->operation.orientation = 0x3; |
| 443 | data->operation.operation = 0x16; |
| 444 | break; |
| 445 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 446 | data->operation.orientation = 0x1; |
| 447 | data->operation.operation = 0x03; |
| 448 | data->count++; |
| 449 | break; |
| 450 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 451 | data->operation.orientation = 0x3; |
| 452 | data->operation.operation = 0x16; |
| 453 | data->count++; |
| 454 | break; |
| 455 | case DASD_ECKD_CCW_WRITE: |
| 456 | case DASD_ECKD_CCW_WRITE_MT: |
| 457 | case DASD_ECKD_CCW_WRITE_KD: |
| 458 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 459 | data->auxiliary.last_bytes_used = 0x1; |
| 460 | data->length = reclen; |
| 461 | data->operation.operation = 0x01; |
| 462 | break; |
| 463 | case DASD_ECKD_CCW_WRITE_CKD: |
| 464 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 465 | data->auxiliary.last_bytes_used = 0x1; |
| 466 | data->length = reclen; |
| 467 | data->operation.operation = 0x03; |
| 468 | break; |
| 469 | case DASD_ECKD_CCW_READ: |
| 470 | case DASD_ECKD_CCW_READ_MT: |
| 471 | case DASD_ECKD_CCW_READ_KD: |
| 472 | case DASD_ECKD_CCW_READ_KD_MT: |
| 473 | data->auxiliary.last_bytes_used = 0x1; |
| 474 | data->length = reclen; |
| 475 | data->operation.operation = 0x06; |
| 476 | break; |
| 477 | case DASD_ECKD_CCW_READ_CKD: |
| 478 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 479 | data->auxiliary.last_bytes_used = 0x1; |
| 480 | data->length = reclen; |
| 481 | data->operation.operation = 0x16; |
| 482 | break; |
| 483 | case DASD_ECKD_CCW_READ_COUNT: |
| 484 | data->operation.operation = 0x06; |
| 485 | break; |
| 486 | case DASD_ECKD_CCW_ERASE: |
| 487 | data->length = reclen; |
| 488 | data->auxiliary.last_bytes_used = 0x1; |
| 489 | data->operation.operation = 0x0b; |
| 490 | break; |
| 491 | default: |
| 492 | DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd); |
| 493 | } |
| 494 | data->seek_addr.cyl = data->search_arg.cyl = |
| 495 | trk / private->rdc_data.trk_per_cyl; |
| 496 | data->seek_addr.head = data->search_arg.head = |
| 497 | trk % private->rdc_data.trk_per_cyl; |
| 498 | data->search_arg.record = rec_on_trk; |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Returns 1 if the block is one of the special blocks that needs |
| 503 | * to get read/written with the KD variant of the command. |
| 504 | * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and |
| 505 | * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT. |
| 506 | * Luckily the KD variants differ only by one bit (0x08) from the |
| 507 | * normal variant. So don't wonder about code like: |
| 508 | * if (dasd_eckd_cdl_special(blk_per_trk, recid)) |
| 509 | * ccw->cmd_code |= 0x8; |
| 510 | */ |
| 511 | static inline int |
| 512 | dasd_eckd_cdl_special(int blk_per_trk, int recid) |
| 513 | { |
| 514 | if (recid < 3) |
| 515 | return 1; |
| 516 | if (recid < blk_per_trk) |
| 517 | return 0; |
| 518 | if (recid < 2 * blk_per_trk) |
| 519 | return 1; |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Returns the record size for the special blocks of the cdl format. |
| 525 | * Only returns something useful if dasd_eckd_cdl_special is true |
| 526 | * for the recid. |
| 527 | */ |
| 528 | static inline int |
| 529 | dasd_eckd_cdl_reclen(int recid) |
| 530 | { |
| 531 | if (recid < 3) |
| 532 | return sizes_trk0[recid]; |
| 533 | return LABEL_SIZE; |
| 534 | } |
| 535 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 536 | /* |
| 537 | * Generate device unique id that specifies the physical device. |
| 538 | */ |
| 539 | static int |
| 540 | dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid) |
| 541 | { |
| 542 | struct dasd_eckd_private *private; |
| 543 | struct dasd_eckd_confdata *confdata; |
| 544 | |
| 545 | private = (struct dasd_eckd_private *) device->private; |
| 546 | if (!private) |
| 547 | return -ENODEV; |
| 548 | confdata = &private->conf_data; |
| 549 | if (!confdata) |
| 550 | return -ENODEV; |
| 551 | |
| 552 | memset(uid, 0, sizeof(struct dasd_uid)); |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 553 | memcpy(uid->vendor, confdata->ned1.HDA_manufacturer, |
| 554 | sizeof(uid->vendor) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 555 | EBCASC(uid->vendor, sizeof(uid->vendor) - 1); |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 556 | memcpy(uid->serial, confdata->ned1.HDA_location, |
| 557 | sizeof(uid->serial) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 558 | EBCASC(uid->serial, sizeof(uid->serial) - 1); |
| 559 | uid->ssid = confdata->neq.subsystemID; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 560 | uid->real_unit_addr = confdata->ned1.unit_addr; |
| 561 | if (confdata->ned2.sneq.flags == 0x40 && |
| 562 | confdata->ned2.sneq.format == 0x0001) { |
| 563 | uid->type = confdata->ned2.sneq.sua_flags; |
| 564 | if (uid->type == UA_BASE_PAV_ALIAS) |
| 565 | uid->base_unit_addr = confdata->ned2.sneq.base_unit_addr; |
| 566 | } else { |
| 567 | uid->type = UA_BASE_DEVICE; |
| 568 | } |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 569 | return 0; |
| 570 | } |
| 571 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 572 | static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device, |
| 573 | void *rcd_buffer, |
| 574 | struct ciw *ciw, __u8 lpm) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 575 | { |
| 576 | struct dasd_ccw_req *cqr; |
| 577 | struct ccw1 *ccw; |
| 578 | |
| 579 | cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device); |
| 580 | |
| 581 | if (IS_ERR(cqr)) { |
| 582 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 583 | "Could not allocate RCD request"); |
| 584 | return cqr; |
| 585 | } |
| 586 | |
| 587 | ccw = cqr->cpaddr; |
| 588 | ccw->cmd_code = ciw->cmd; |
| 589 | ccw->cda = (__u32)(addr_t)rcd_buffer; |
| 590 | ccw->count = ciw->count; |
| 591 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 592 | cqr->startdev = device; |
| 593 | cqr->memdev = device; |
| 594 | cqr->block = NULL; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 595 | cqr->expires = 10*HZ; |
| 596 | cqr->lpm = lpm; |
| 597 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 598 | cqr->retries = 2; |
| 599 | cqr->buildclk = get_clock(); |
| 600 | cqr->status = DASD_CQR_FILLED; |
| 601 | return cqr; |
| 602 | } |
| 603 | |
| 604 | static int dasd_eckd_read_conf_lpm(struct dasd_device *device, |
| 605 | void **rcd_buffer, |
| 606 | int *rcd_buffer_size, __u8 lpm) |
| 607 | { |
| 608 | struct ciw *ciw; |
| 609 | char *rcd_buf = NULL; |
| 610 | int ret; |
| 611 | struct dasd_ccw_req *cqr; |
| 612 | |
| 613 | /* |
| 614 | * scan for RCD command in extended SenseID data |
| 615 | */ |
| 616 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); |
| 617 | if (!ciw || ciw->cmd == 0) { |
| 618 | ret = -EOPNOTSUPP; |
| 619 | goto out_error; |
| 620 | } |
| 621 | rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA); |
| 622 | if (!rcd_buf) { |
| 623 | ret = -ENOMEM; |
| 624 | goto out_error; |
| 625 | } |
| 626 | cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm); |
| 627 | if (IS_ERR(cqr)) { |
| 628 | ret = PTR_ERR(cqr); |
| 629 | goto out_error; |
| 630 | } |
| 631 | ret = dasd_sleep_on(cqr); |
| 632 | /* |
| 633 | * on success we update the user input parms |
| 634 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 635 | dasd_sfree_request(cqr, cqr->memdev); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 636 | if (ret) |
| 637 | goto out_error; |
| 638 | |
| 639 | *rcd_buffer_size = ciw->count; |
| 640 | *rcd_buffer = rcd_buf; |
| 641 | return 0; |
| 642 | out_error: |
| 643 | kfree(rcd_buf); |
| 644 | *rcd_buffer = NULL; |
| 645 | *rcd_buffer_size = 0; |
| 646 | return ret; |
| 647 | } |
| 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | static int |
| 650 | dasd_eckd_read_conf(struct dasd_device *device) |
| 651 | { |
| 652 | void *conf_data; |
| 653 | int conf_len, conf_data_saved; |
| 654 | int rc; |
| 655 | __u8 lpm; |
| 656 | struct dasd_eckd_private *private; |
| 657 | struct dasd_eckd_path *path_data; |
| 658 | |
| 659 | private = (struct dasd_eckd_private *) device->private; |
| 660 | path_data = (struct dasd_eckd_path *) &private->path_data; |
| 661 | path_data->opm = ccw_device_get_path_mask(device->cdev); |
| 662 | lpm = 0x80; |
| 663 | conf_data_saved = 0; |
| 664 | |
| 665 | /* get configuration data per operational path */ |
| 666 | for (lpm = 0x80; lpm; lpm>>= 1) { |
| 667 | if (lpm & path_data->opm){ |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 668 | rc = dasd_eckd_read_conf_lpm(device, &conf_data, |
| 669 | &conf_len, lpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ |
| 671 | MESSAGE(KERN_WARNING, |
| 672 | "Read configuration data returned " |
| 673 | "error %d", rc); |
| 674 | return rc; |
| 675 | } |
| 676 | if (conf_data == NULL) { |
| 677 | MESSAGE(KERN_WARNING, "%s", "No configuration " |
| 678 | "data retrieved"); |
Gabriel Craciunescu | d133a96 | 2007-07-31 00:39:19 -0700 | [diff] [blame] | 679 | continue; /* no error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 681 | if (conf_len != sizeof(struct dasd_eckd_confdata)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | MESSAGE(KERN_WARNING, |
| 683 | "sizes of configuration data mismatch" |
| 684 | "%d (read) vs %ld (expected)", |
| 685 | conf_len, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 686 | sizeof(struct dasd_eckd_confdata)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | kfree(conf_data); |
Gabriel Craciunescu | d133a96 | 2007-07-31 00:39:19 -0700 | [diff] [blame] | 688 | continue; /* no error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
| 690 | /* save first valid configuration data */ |
| 691 | if (!conf_data_saved){ |
| 692 | memcpy(&private->conf_data, conf_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 693 | sizeof(struct dasd_eckd_confdata)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | conf_data_saved++; |
| 695 | } |
| 696 | switch (((char *)conf_data)[242] & 0x07){ |
| 697 | case 0x02: |
| 698 | path_data->npm |= lpm; |
| 699 | break; |
| 700 | case 0x03: |
| 701 | path_data->ppm |= lpm; |
| 702 | break; |
| 703 | } |
| 704 | kfree(conf_data); |
| 705 | } |
| 706 | } |
| 707 | return 0; |
| 708 | } |
| 709 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 710 | static int dasd_eckd_read_features(struct dasd_device *device) |
| 711 | { |
| 712 | struct dasd_psf_prssd_data *prssdp; |
| 713 | struct dasd_rssd_features *features; |
| 714 | struct dasd_ccw_req *cqr; |
| 715 | struct ccw1 *ccw; |
| 716 | int rc; |
| 717 | struct dasd_eckd_private *private; |
| 718 | |
| 719 | private = (struct dasd_eckd_private *) device->private; |
| 720 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 721 | 1 /* PSF */ + 1 /* RSSD */ , |
| 722 | (sizeof(struct dasd_psf_prssd_data) + |
| 723 | sizeof(struct dasd_rssd_features)), |
| 724 | device); |
| 725 | if (IS_ERR(cqr)) { |
| 726 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 727 | "Could not allocate initialization request"); |
| 728 | return PTR_ERR(cqr); |
| 729 | } |
| 730 | cqr->startdev = device; |
| 731 | cqr->memdev = device; |
| 732 | cqr->block = NULL; |
| 733 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 734 | cqr->retries = 5; |
| 735 | cqr->expires = 10 * HZ; |
| 736 | |
| 737 | /* Prepare for Read Subsystem Data */ |
| 738 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 739 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 740 | prssdp->order = PSF_ORDER_PRSSD; |
| 741 | prssdp->suborder = 0x41; /* Read Feature Codes */ |
| 742 | /* all other bytes of prssdp must be zero */ |
| 743 | |
| 744 | ccw = cqr->cpaddr; |
| 745 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 746 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 747 | ccw->flags |= CCW_FLAG_CC; |
| 748 | ccw->cda = (__u32)(addr_t) prssdp; |
| 749 | |
| 750 | /* Read Subsystem Data - feature codes */ |
| 751 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 752 | memset(features, 0, sizeof(struct dasd_rssd_features)); |
| 753 | |
| 754 | ccw++; |
| 755 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 756 | ccw->count = sizeof(struct dasd_rssd_features); |
| 757 | ccw->cda = (__u32)(addr_t) features; |
| 758 | |
| 759 | cqr->buildclk = get_clock(); |
| 760 | cqr->status = DASD_CQR_FILLED; |
| 761 | rc = dasd_sleep_on(cqr); |
| 762 | if (rc == 0) { |
| 763 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 764 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 765 | memcpy(&private->features, features, |
| 766 | sizeof(struct dasd_rssd_features)); |
| 767 | } |
| 768 | dasd_sfree_request(cqr, cqr->memdev); |
| 769 | return rc; |
| 770 | } |
| 771 | |
| 772 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 773 | /* |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 774 | * Build CP for Perform Subsystem Function - SSC. |
| 775 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 776 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 777 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 778 | struct dasd_ccw_req *cqr; |
| 779 | struct dasd_psf_ssc_data *psf_ssc_data; |
| 780 | struct ccw1 *ccw; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 781 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 782 | cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ , |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 783 | sizeof(struct dasd_psf_ssc_data), |
| 784 | device); |
| 785 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 786 | if (IS_ERR(cqr)) { |
| 787 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 788 | "Could not allocate PSF-SSC request"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 789 | return cqr; |
| 790 | } |
| 791 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; |
| 792 | psf_ssc_data->order = PSF_ORDER_SSC; |
| 793 | psf_ssc_data->suborder = 0x88; |
| 794 | psf_ssc_data->reserved[0] = 0x88; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 795 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 796 | ccw = cqr->cpaddr; |
| 797 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 798 | ccw->cda = (__u32)(addr_t)psf_ssc_data; |
| 799 | ccw->count = 66; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 800 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 801 | cqr->startdev = device; |
| 802 | cqr->memdev = device; |
| 803 | cqr->block = NULL; |
| 804 | cqr->expires = 10*HZ; |
| 805 | cqr->buildclk = get_clock(); |
| 806 | cqr->status = DASD_CQR_FILLED; |
| 807 | return cqr; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /* |
| 811 | * Perform Subsystem Function. |
| 812 | * It is necessary to trigger CIO for channel revalidation since this |
| 813 | * call might change behaviour of DASD devices. |
| 814 | */ |
| 815 | static int |
| 816 | dasd_eckd_psf_ssc(struct dasd_device *device) |
| 817 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 818 | struct dasd_ccw_req *cqr; |
| 819 | int rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 820 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 821 | cqr = dasd_eckd_build_psf_ssc(device); |
| 822 | if (IS_ERR(cqr)) |
| 823 | return PTR_ERR(cqr); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 824 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 825 | rc = dasd_sleep_on(cqr); |
| 826 | if (!rc) |
| 827 | /* trigger CIO to reprobe devices */ |
| 828 | css_schedule_reprobe(); |
| 829 | dasd_sfree_request(cqr, cqr->memdev); |
| 830 | return rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Valide storage server of current device. |
| 835 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 836 | static int dasd_eckd_validate_server(struct dasd_device *device) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 837 | { |
| 838 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 839 | struct dasd_eckd_private *private; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 840 | |
| 841 | /* Currently PAV is the only reason to 'validate' server on LPAR */ |
| 842 | if (dasd_nopav || MACHINE_IS_VM) |
| 843 | return 0; |
| 844 | |
| 845 | rc = dasd_eckd_psf_ssc(device); |
Horst Hummel | 8e79a44 | 2006-08-24 13:22:36 +0200 | [diff] [blame] | 846 | /* may be requested feature is not available on server, |
| 847 | * therefore just report error and go ahead */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 848 | private = (struct dasd_eckd_private *) device->private; |
Horst Hummel | 8e79a44 | 2006-08-24 13:22:36 +0200 | [diff] [blame] | 849 | DEV_MESSAGE(KERN_INFO, device, |
| 850 | "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 851 | private->uid.vendor, private->uid.serial, |
| 852 | private->uid.ssid, rc); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 853 | /* RE-Read Configuration Data */ |
| 854 | return dasd_eckd_read_conf(device); |
| 855 | } |
| 856 | |
| 857 | /* |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 858 | * Check device characteristics. |
| 859 | * If the device is accessible using ECKD discipline, the device is enabled. |
| 860 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | static int |
| 862 | dasd_eckd_check_characteristics(struct dasd_device *device) |
| 863 | { |
| 864 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 865 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | void *rdc_data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 867 | int is_known, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | private = (struct dasd_eckd_private *) device->private; |
| 870 | if (private == NULL) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 871 | private = kzalloc(sizeof(struct dasd_eckd_private), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | GFP_KERNEL | GFP_DMA); |
| 873 | if (private == NULL) { |
| 874 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 875 | "memory allocation failed for private " |
| 876 | "data"); |
| 877 | return -ENOMEM; |
| 878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | device->private = (void *) private; |
| 880 | } |
| 881 | /* Invalidate status of initial analysis. */ |
| 882 | private->init_cqr_status = -1; |
| 883 | /* Set default cache operations. */ |
| 884 | private->attrib.operation = DASD_NORMAL_CACHE; |
| 885 | private->attrib.nr_cyl = 0; |
| 886 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 887 | /* Read Configuration Data */ |
| 888 | rc = dasd_eckd_read_conf(device); |
| 889 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 890 | goto out_err1; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 891 | |
| 892 | /* Generate device unique id and register in devmap */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 893 | rc = dasd_eckd_generate_uid(device, &private->uid); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 894 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 895 | goto out_err1; |
| 896 | dasd_set_uid(device->cdev, &private->uid); |
| 897 | |
| 898 | if (private->uid.type == UA_BASE_DEVICE) { |
| 899 | block = dasd_alloc_block(); |
| 900 | if (IS_ERR(block)) { |
| 901 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 902 | "could not allocate dasd block structure"); |
| 903 | rc = PTR_ERR(block); |
| 904 | goto out_err1; |
| 905 | } |
| 906 | device->block = block; |
| 907 | block->base = device; |
| 908 | } |
| 909 | |
| 910 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
| 911 | is_known = dasd_alias_make_device_known_to_lcu(device); |
| 912 | if (is_known < 0) { |
| 913 | rc = is_known; |
| 914 | goto out_err2; |
| 915 | } |
| 916 | if (!is_known) { |
| 917 | /* new lcu found */ |
| 918 | rc = dasd_eckd_validate_server(device); /* will switch pav on */ |
| 919 | if (rc) |
| 920 | goto out_err3; |
| 921 | } |
| 922 | |
| 923 | /* Read Feature Codes */ |
| 924 | rc = dasd_eckd_read_features(device); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 925 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 926 | goto out_err3; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | /* Read Device Characteristics */ |
| 929 | rdc_data = (void *) &(private->rdc_data); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 930 | memset(rdc_data, 0, sizeof(rdc_data)); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 931 | rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 932 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | DEV_MESSAGE(KERN_WARNING, device, |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 934 | "Read device characteristics returned " |
| 935 | "rc=%d", rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 936 | goto out_err3; |
| 937 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | DEV_MESSAGE(KERN_INFO, device, |
| 939 | "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d", |
| 940 | private->rdc_data.dev_type, |
| 941 | private->rdc_data.dev_model, |
| 942 | private->rdc_data.cu_type, |
| 943 | private->rdc_data.cu_model.model, |
| 944 | private->rdc_data.no_cyl, |
| 945 | private->rdc_data.trk_per_cyl, |
| 946 | private->rdc_data.sec_per_trk); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 947 | return 0; |
| 948 | |
| 949 | out_err3: |
| 950 | dasd_alias_disconnect_device_from_lcu(device); |
| 951 | out_err2: |
| 952 | dasd_free_block(device->block); |
| 953 | device->block = NULL; |
| 954 | out_err1: |
| 955 | kfree(device->private); |
| 956 | device->private = NULL; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 957 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 960 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
| 961 | { |
| 962 | dasd_alias_disconnect_device_from_lcu(device); |
| 963 | } |
| 964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | static struct dasd_ccw_req * |
| 966 | dasd_eckd_analysis_ccw(struct dasd_device *device) |
| 967 | { |
| 968 | struct dasd_eckd_private *private; |
| 969 | struct eckd_count *count_data; |
| 970 | struct LO_eckd_data *LO_data; |
| 971 | struct dasd_ccw_req *cqr; |
| 972 | struct ccw1 *ccw; |
| 973 | int cplength, datasize; |
| 974 | int i; |
| 975 | |
| 976 | private = (struct dasd_eckd_private *) device->private; |
| 977 | |
| 978 | cplength = 8; |
| 979 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); |
| 980 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 981 | cplength, datasize, device); |
| 982 | if (IS_ERR(cqr)) |
| 983 | return cqr; |
| 984 | ccw = cqr->cpaddr; |
| 985 | /* Define extent for the first 3 tracks. */ |
| 986 | define_extent(ccw++, cqr->data, 0, 2, |
| 987 | DASD_ECKD_CCW_READ_COUNT, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 988 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | /* Locate record for the first 4 records on track 0. */ |
| 990 | ccw[-1].flags |= CCW_FLAG_CC; |
| 991 | locate_record(ccw++, LO_data++, 0, 0, 4, |
| 992 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 993 | |
| 994 | count_data = private->count_area; |
| 995 | for (i = 0; i < 4; i++) { |
| 996 | ccw[-1].flags |= CCW_FLAG_CC; |
| 997 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 998 | ccw->flags = 0; |
| 999 | ccw->count = 8; |
| 1000 | ccw->cda = (__u32)(addr_t) count_data; |
| 1001 | ccw++; |
| 1002 | count_data++; |
| 1003 | } |
| 1004 | |
| 1005 | /* Locate record for the first record on track 2. */ |
| 1006 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1007 | locate_record(ccw++, LO_data++, 2, 0, 1, |
| 1008 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1009 | /* Read count ccw. */ |
| 1010 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1011 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1012 | ccw->flags = 0; |
| 1013 | ccw->count = 8; |
| 1014 | ccw->cda = (__u32)(addr_t) count_data; |
| 1015 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1016 | cqr->block = NULL; |
| 1017 | cqr->startdev = device; |
| 1018 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | cqr->retries = 0; |
| 1020 | cqr->buildclk = get_clock(); |
| 1021 | cqr->status = DASD_CQR_FILLED; |
| 1022 | return cqr; |
| 1023 | } |
| 1024 | |
| 1025 | /* |
| 1026 | * This is the callback function for the init_analysis cqr. It saves |
| 1027 | * the status of the initial analysis ccw before it frees it and kicks |
| 1028 | * the device to continue the startup sequence. This will call |
| 1029 | * dasd_eckd_do_analysis again (if the devices has not been marked |
| 1030 | * for deletion in the meantime). |
| 1031 | */ |
| 1032 | static void |
| 1033 | dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data) |
| 1034 | { |
| 1035 | struct dasd_eckd_private *private; |
| 1036 | struct dasd_device *device; |
| 1037 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1038 | device = init_cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | private = (struct dasd_eckd_private *) device->private; |
| 1040 | private->init_cqr_status = init_cqr->status; |
| 1041 | dasd_sfree_request(init_cqr, device); |
| 1042 | dasd_kick_device(device); |
| 1043 | } |
| 1044 | |
| 1045 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1046 | dasd_eckd_start_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
| 1048 | struct dasd_eckd_private *private; |
| 1049 | struct dasd_ccw_req *init_cqr; |
| 1050 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1051 | private = (struct dasd_eckd_private *) block->base->private; |
| 1052 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | if (IS_ERR(init_cqr)) |
| 1054 | return PTR_ERR(init_cqr); |
| 1055 | init_cqr->callback = dasd_eckd_analysis_callback; |
| 1056 | init_cqr->callback_data = NULL; |
| 1057 | init_cqr->expires = 5*HZ; |
| 1058 | dasd_add_request_head(init_cqr); |
| 1059 | return -EAGAIN; |
| 1060 | } |
| 1061 | |
| 1062 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1063 | dasd_eckd_end_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1065 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | struct dasd_eckd_private *private; |
| 1067 | struct eckd_count *count_area; |
| 1068 | unsigned int sb, blk_per_trk; |
| 1069 | int status, i; |
| 1070 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1071 | device = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | private = (struct dasd_eckd_private *) device->private; |
| 1073 | status = private->init_cqr_status; |
| 1074 | private->init_cqr_status = -1; |
| 1075 | if (status != DASD_CQR_DONE) { |
| 1076 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1077 | "volume analysis returned unformatted disk"); |
| 1078 | return -EMEDIUMTYPE; |
| 1079 | } |
| 1080 | |
| 1081 | private->uses_cdl = 1; |
| 1082 | /* Calculate number of blocks/records per track. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1083 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | /* Check Track 0 for Compatible Disk Layout */ |
| 1085 | count_area = NULL; |
| 1086 | for (i = 0; i < 3; i++) { |
| 1087 | if (private->count_area[i].kl != 4 || |
| 1088 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) { |
| 1089 | private->uses_cdl = 0; |
| 1090 | break; |
| 1091 | } |
| 1092 | } |
| 1093 | if (i == 3) |
| 1094 | count_area = &private->count_area[4]; |
| 1095 | |
| 1096 | if (private->uses_cdl == 0) { |
| 1097 | for (i = 0; i < 5; i++) { |
| 1098 | if ((private->count_area[i].kl != 0) || |
| 1099 | (private->count_area[i].dl != |
| 1100 | private->count_area[0].dl)) |
| 1101 | break; |
| 1102 | } |
| 1103 | if (i == 5) |
| 1104 | count_area = &private->count_area[0]; |
| 1105 | } else { |
| 1106 | if (private->count_area[3].record == 1) |
| 1107 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1108 | "Trk 0: no records after VTOC!"); |
| 1109 | } |
| 1110 | if (count_area != NULL && count_area->kl == 0) { |
| 1111 | /* we found notthing violating our disk layout */ |
| 1112 | if (dasd_check_blocksize(count_area->dl) == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1113 | block->bp_block = count_area->dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1115 | if (block->bp_block == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1117 | "Volume has incompatible disk layout"); |
| 1118 | return -EMEDIUMTYPE; |
| 1119 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1120 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 1121 | for (sb = 512; sb < block->bp_block; sb = sb << 1) |
| 1122 | block->s2b_shift++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1124 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
| 1125 | block->blocks = (private->rdc_data.no_cyl * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | private->rdc_data.trk_per_cyl * |
| 1127 | blk_per_trk); |
| 1128 | |
| 1129 | DEV_MESSAGE(KERN_INFO, device, |
| 1130 | "(%dkB blks): %dkB at %dkB/trk %s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1131 | (block->bp_block >> 10), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | ((private->rdc_data.no_cyl * |
| 1133 | private->rdc_data.trk_per_cyl * |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1134 | blk_per_trk * (block->bp_block >> 9)) >> 1), |
| 1135 | ((blk_per_trk * block->bp_block) >> 10), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | private->uses_cdl ? |
| 1137 | "compatible disk layout" : "linux disk layout"); |
| 1138 | |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1142 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | { |
| 1144 | struct dasd_eckd_private *private; |
| 1145 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1146 | private = (struct dasd_eckd_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | if (private->init_cqr_status < 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1148 | return dasd_eckd_start_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1150 | return dasd_eckd_end_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1153 | static int dasd_eckd_ready_to_online(struct dasd_device *device) |
| 1154 | { |
| 1155 | return dasd_alias_add_device(device); |
| 1156 | }; |
| 1157 | |
| 1158 | static int dasd_eckd_online_to_ready(struct dasd_device *device) |
| 1159 | { |
| 1160 | return dasd_alias_remove_device(device); |
| 1161 | }; |
| 1162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1164 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
| 1166 | struct dasd_eckd_private *private; |
| 1167 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1168 | private = (struct dasd_eckd_private *) block->base->private; |
| 1169 | if (dasd_check_blocksize(block->bp_block) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | geo->sectors = recs_per_track(&private->rdc_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1171 | 0, block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
| 1173 | geo->cylinders = private->rdc_data.no_cyl; |
| 1174 | geo->heads = private->rdc_data.trk_per_cyl; |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | static struct dasd_ccw_req * |
| 1179 | dasd_eckd_format_device(struct dasd_device * device, |
| 1180 | struct format_data_t * fdata) |
| 1181 | { |
| 1182 | struct dasd_eckd_private *private; |
| 1183 | struct dasd_ccw_req *fcp; |
| 1184 | struct eckd_count *ect; |
| 1185 | struct ccw1 *ccw; |
| 1186 | void *data; |
| 1187 | int rpt, cyl, head; |
| 1188 | int cplength, datasize; |
| 1189 | int i; |
| 1190 | |
| 1191 | private = (struct dasd_eckd_private *) device->private; |
| 1192 | rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize); |
| 1193 | cyl = fdata->start_unit / private->rdc_data.trk_per_cyl; |
| 1194 | head = fdata->start_unit % private->rdc_data.trk_per_cyl; |
| 1195 | |
| 1196 | /* Sanity checks. */ |
| 1197 | if (fdata->start_unit >= |
| 1198 | (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) { |
| 1199 | DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!", |
| 1200 | fdata->start_unit); |
| 1201 | return ERR_PTR(-EINVAL); |
| 1202 | } |
| 1203 | if (fdata->start_unit > fdata->stop_unit) { |
| 1204 | DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.", |
| 1205 | fdata->start_unit); |
| 1206 | return ERR_PTR(-EINVAL); |
| 1207 | } |
| 1208 | if (dasd_check_blocksize(fdata->blksize) != 0) { |
| 1209 | DEV_MESSAGE(KERN_WARNING, device, |
| 1210 | "Invalid blocksize %d...terminating!", |
| 1211 | fdata->blksize); |
| 1212 | return ERR_PTR(-EINVAL); |
| 1213 | } |
| 1214 | |
| 1215 | /* |
| 1216 | * fdata->intensity is a bit string that tells us what to do: |
| 1217 | * Bit 0: write record zero |
| 1218 | * Bit 1: write home address, currently not supported |
| 1219 | * Bit 2: invalidate tracks |
| 1220 | * Bit 3: use OS/390 compatible disk layout (cdl) |
| 1221 | * Only some bit combinations do make sense. |
| 1222 | */ |
| 1223 | switch (fdata->intensity) { |
| 1224 | case 0x00: /* Normal format */ |
| 1225 | case 0x08: /* Normal format, use cdl. */ |
| 1226 | cplength = 2 + rpt; |
| 1227 | datasize = sizeof(struct DE_eckd_data) + |
| 1228 | sizeof(struct LO_eckd_data) + |
| 1229 | rpt * sizeof(struct eckd_count); |
| 1230 | break; |
| 1231 | case 0x01: /* Write record zero and format track. */ |
| 1232 | case 0x09: /* Write record zero and format track, use cdl. */ |
| 1233 | cplength = 3 + rpt; |
| 1234 | datasize = sizeof(struct DE_eckd_data) + |
| 1235 | sizeof(struct LO_eckd_data) + |
| 1236 | sizeof(struct eckd_count) + |
| 1237 | rpt * sizeof(struct eckd_count); |
| 1238 | break; |
| 1239 | case 0x04: /* Invalidate track. */ |
| 1240 | case 0x0c: /* Invalidate track, use cdl. */ |
| 1241 | cplength = 3; |
| 1242 | datasize = sizeof(struct DE_eckd_data) + |
| 1243 | sizeof(struct LO_eckd_data) + |
| 1244 | sizeof(struct eckd_count); |
| 1245 | break; |
| 1246 | default: |
| 1247 | DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.", |
| 1248 | fdata->intensity); |
| 1249 | return ERR_PTR(-EINVAL); |
| 1250 | } |
| 1251 | /* Allocate the format ccw request. */ |
| 1252 | fcp = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 1253 | cplength, datasize, device); |
| 1254 | if (IS_ERR(fcp)) |
| 1255 | return fcp; |
| 1256 | |
| 1257 | data = fcp->data; |
| 1258 | ccw = fcp->cpaddr; |
| 1259 | |
| 1260 | switch (fdata->intensity & ~0x08) { |
| 1261 | case 0x00: /* Normal format. */ |
| 1262 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1263 | fdata->start_unit, fdata->start_unit, |
| 1264 | DASD_ECKD_CCW_WRITE_CKD, device); |
| 1265 | data += sizeof(struct DE_eckd_data); |
| 1266 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1267 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1268 | fdata->start_unit, 0, rpt, |
| 1269 | DASD_ECKD_CCW_WRITE_CKD, device, |
| 1270 | fdata->blksize); |
| 1271 | data += sizeof(struct LO_eckd_data); |
| 1272 | break; |
| 1273 | case 0x01: /* Write record zero + format track. */ |
| 1274 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1275 | fdata->start_unit, fdata->start_unit, |
| 1276 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, |
| 1277 | device); |
| 1278 | data += sizeof(struct DE_eckd_data); |
| 1279 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1280 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1281 | fdata->start_unit, 0, rpt + 1, |
| 1282 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1283 | device->block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | data += sizeof(struct LO_eckd_data); |
| 1285 | break; |
| 1286 | case 0x04: /* Invalidate track. */ |
| 1287 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1288 | fdata->start_unit, fdata->start_unit, |
| 1289 | DASD_ECKD_CCW_WRITE_CKD, device); |
| 1290 | data += sizeof(struct DE_eckd_data); |
| 1291 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1292 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1293 | fdata->start_unit, 0, 1, |
| 1294 | DASD_ECKD_CCW_WRITE_CKD, device, 8); |
| 1295 | data += sizeof(struct LO_eckd_data); |
| 1296 | break; |
| 1297 | } |
| 1298 | if (fdata->intensity & 0x01) { /* write record zero */ |
| 1299 | ect = (struct eckd_count *) data; |
| 1300 | data += sizeof(struct eckd_count); |
| 1301 | ect->cyl = cyl; |
| 1302 | ect->head = head; |
| 1303 | ect->record = 0; |
| 1304 | ect->kl = 0; |
| 1305 | ect->dl = 8; |
| 1306 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1307 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; |
| 1308 | ccw->flags = CCW_FLAG_SLI; |
| 1309 | ccw->count = 8; |
| 1310 | ccw->cda = (__u32)(addr_t) ect; |
| 1311 | ccw++; |
| 1312 | } |
| 1313 | if ((fdata->intensity & ~0x08) & 0x04) { /* erase track */ |
| 1314 | ect = (struct eckd_count *) data; |
| 1315 | data += sizeof(struct eckd_count); |
| 1316 | ect->cyl = cyl; |
| 1317 | ect->head = head; |
| 1318 | ect->record = 1; |
| 1319 | ect->kl = 0; |
| 1320 | ect->dl = 0; |
| 1321 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1322 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1323 | ccw->flags = CCW_FLAG_SLI; |
| 1324 | ccw->count = 8; |
| 1325 | ccw->cda = (__u32)(addr_t) ect; |
| 1326 | } else { /* write remaining records */ |
| 1327 | for (i = 0; i < rpt; i++) { |
| 1328 | ect = (struct eckd_count *) data; |
| 1329 | data += sizeof(struct eckd_count); |
| 1330 | ect->cyl = cyl; |
| 1331 | ect->head = head; |
| 1332 | ect->record = i + 1; |
| 1333 | ect->kl = 0; |
| 1334 | ect->dl = fdata->blksize; |
| 1335 | /* Check for special tracks 0-1 when formatting CDL */ |
| 1336 | if ((fdata->intensity & 0x08) && |
| 1337 | fdata->start_unit == 0) { |
| 1338 | if (i < 3) { |
| 1339 | ect->kl = 4; |
| 1340 | ect->dl = sizes_trk0[i] - 4; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
| 1343 | if ((fdata->intensity & 0x08) && |
| 1344 | fdata->start_unit == 1) { |
| 1345 | ect->kl = 44; |
| 1346 | ect->dl = LABEL_SIZE - 44; |
| 1347 | } |
| 1348 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1349 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1350 | ccw->flags = CCW_FLAG_SLI; |
| 1351 | ccw->count = 8; |
| 1352 | ccw->cda = (__u32)(addr_t) ect; |
| 1353 | ccw++; |
| 1354 | } |
| 1355 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1356 | fcp->startdev = device; |
| 1357 | fcp->memdev = device; |
| 1358 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags); |
| 1359 | fcp->retries = 5; /* set retry counter to enable default ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | fcp->buildclk = get_clock(); |
| 1361 | fcp->status = DASD_CQR_FILLED; |
| 1362 | return fcp; |
| 1363 | } |
| 1364 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1365 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1367 | cqr->status = DASD_CQR_FILLED; |
| 1368 | if (cqr->block && (cqr->startdev != cqr->block->base)) { |
| 1369 | dasd_eckd_reset_ccw_to_base_io(cqr); |
| 1370 | cqr->startdev = cqr->block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1372 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
| 1374 | static dasd_erp_fn_t |
| 1375 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) |
| 1376 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1377 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | struct ccw_device *cdev = device->cdev; |
| 1379 | |
| 1380 | switch (cdev->id.cu_type) { |
| 1381 | case 0x3990: |
| 1382 | case 0x2105: |
| 1383 | case 0x2107: |
| 1384 | case 0x1750: |
| 1385 | return dasd_3990_erp_action; |
| 1386 | case 0x9343: |
| 1387 | case 0x3880: |
| 1388 | default: |
| 1389 | return dasd_default_erp_action; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | static dasd_erp_fn_t |
| 1394 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) |
| 1395 | { |
| 1396 | return dasd_default_erp_postaction; |
| 1397 | } |
| 1398 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1399 | |
| 1400 | static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device, |
| 1401 | struct irb *irb) |
| 1402 | { |
| 1403 | char mask; |
| 1404 | |
| 1405 | /* first of all check for state change pending interrupt */ |
| 1406 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1407 | if ((irb->scsw.cmd.dstat & mask) == mask) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1408 | dasd_generic_handle_state_change(device); |
| 1409 | return; |
| 1410 | } |
| 1411 | |
| 1412 | /* summary unit check */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1413 | if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) && |
| 1414 | (irb->ecw[7] == 0x0D)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1415 | dasd_alias_handle_summary_unit_check(device, irb); |
| 1416 | return; |
| 1417 | } |
| 1418 | |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1419 | |
| 1420 | /* service information message SIM */ |
Stefan Haberland | 9d853ca | 2008-07-17 17:16:41 +0200 | [diff] [blame^] | 1421 | if (irb->esw.esw0.erw.cons && (irb->ecw[27] & DASD_SENSE_BIT_0) && |
| 1422 | ((irb->ecw[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1423 | dasd_3990_erp_handle_sim(device, irb->ecw); |
Stefan Haberland | 9d853ca | 2008-07-17 17:16:41 +0200 | [diff] [blame^] | 1424 | dasd_schedule_device_bh(device); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1425 | return; |
| 1426 | } |
| 1427 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1428 | /* just report other unsolicited interrupts */ |
| 1429 | DEV_MESSAGE(KERN_DEBUG, device, "%s", |
| 1430 | "unsolicited interrupt received"); |
| 1431 | device->discipline->dump_sense(device, NULL, irb); |
| 1432 | dasd_schedule_device_bh(device); |
| 1433 | |
| 1434 | return; |
| 1435 | }; |
| 1436 | |
| 1437 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, |
| 1438 | struct dasd_block *block, |
| 1439 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | { |
| 1441 | struct dasd_eckd_private *private; |
| 1442 | unsigned long *idaws; |
| 1443 | struct LO_eckd_data *LO_data; |
| 1444 | struct dasd_ccw_req *cqr; |
| 1445 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1446 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | struct bio_vec *bv; |
| 1448 | char *dst; |
| 1449 | unsigned int blksize, blk_per_trk, off; |
| 1450 | int count, cidaw, cplength, datasize; |
| 1451 | sector_t recid, first_rec, last_rec; |
| 1452 | sector_t first_trk, last_trk; |
| 1453 | unsigned int first_offs, last_offs; |
| 1454 | unsigned char cmd, rcmd; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1455 | int use_prefix; |
| 1456 | struct dasd_device *basedev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1458 | basedev = block->base; |
| 1459 | private = (struct dasd_eckd_private *) basedev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | if (rq_data_dir(req) == READ) |
| 1461 | cmd = DASD_ECKD_CCW_READ_MT; |
| 1462 | else if (rq_data_dir(req) == WRITE) |
| 1463 | cmd = DASD_ECKD_CCW_WRITE_MT; |
| 1464 | else |
| 1465 | return ERR_PTR(-EINVAL); |
| 1466 | /* Calculate number of blocks/records per track. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1467 | blksize = block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
| 1469 | /* Calculate record id of first and last block. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1470 | first_rec = first_trk = req->sector >> block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | first_offs = sector_div(first_trk, blk_per_trk); |
| 1472 | last_rec = last_trk = |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1473 | (req->sector + req->nr_sectors - 1) >> block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | last_offs = sector_div(last_trk, blk_per_trk); |
| 1475 | /* Check struct bio and count the number of blocks for the request. */ |
| 1476 | count = 0; |
| 1477 | cidaw = 0; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1478 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1479 | if (bv->bv_len & (blksize - 1)) |
| 1480 | /* Eckd can only do full blocks. */ |
| 1481 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1482 | count += bv->bv_len >> (block->s2b_shift + 9); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 1483 | #if defined(CONFIG_64BIT) |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1484 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1485 | cidaw += bv->bv_len >> (block->s2b_shift + 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | } |
| 1488 | /* Paranoia. */ |
| 1489 | if (count != last_rec - first_rec + 1) |
| 1490 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1491 | |
| 1492 | /* use the prefix command if available */ |
| 1493 | use_prefix = private->features.feature[8] & 0x01; |
| 1494 | if (use_prefix) { |
| 1495 | /* 1x prefix + number of blocks */ |
| 1496 | cplength = 2 + count; |
| 1497 | /* 1x prefix + cidaws*sizeof(long) */ |
| 1498 | datasize = sizeof(struct PFX_eckd_data) + |
| 1499 | sizeof(struct LO_eckd_data) + |
| 1500 | cidaw * sizeof(unsigned long); |
| 1501 | } else { |
| 1502 | /* 1x define extent + 1x locate record + number of blocks */ |
| 1503 | cplength = 2 + count; |
| 1504 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ |
| 1505 | datasize = sizeof(struct DE_eckd_data) + |
| 1506 | sizeof(struct LO_eckd_data) + |
| 1507 | cidaw * sizeof(unsigned long); |
| 1508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | /* Find out the number of additional locate record ccws for cdl. */ |
| 1510 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { |
| 1511 | if (last_rec >= 2*blk_per_trk) |
| 1512 | count = 2*blk_per_trk - first_rec; |
| 1513 | cplength += count; |
| 1514 | datasize += count*sizeof(struct LO_eckd_data); |
| 1515 | } |
| 1516 | /* Allocate the ccw request. */ |
| 1517 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1518 | cplength, datasize, startdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | if (IS_ERR(cqr)) |
| 1520 | return cqr; |
| 1521 | ccw = cqr->cpaddr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1522 | /* First ccw is define extent or prefix. */ |
| 1523 | if (use_prefix) { |
| 1524 | if (prefix(ccw++, cqr->data, first_trk, |
| 1525 | last_trk, cmd, basedev, startdev) == -EAGAIN) { |
| 1526 | /* Clock not in sync and XRC is enabled. |
| 1527 | * Try again later. |
| 1528 | */ |
| 1529 | dasd_sfree_request(cqr, startdev); |
| 1530 | return ERR_PTR(-EAGAIN); |
| 1531 | } |
| 1532 | idaws = (unsigned long *) (cqr->data + |
| 1533 | sizeof(struct PFX_eckd_data)); |
| 1534 | } else { |
| 1535 | if (define_extent(ccw++, cqr->data, first_trk, |
| 1536 | last_trk, cmd, startdev) == -EAGAIN) { |
| 1537 | /* Clock not in sync and XRC is enabled. |
| 1538 | * Try again later. |
| 1539 | */ |
| 1540 | dasd_sfree_request(cqr, startdev); |
| 1541 | return ERR_PTR(-EAGAIN); |
| 1542 | } |
| 1543 | idaws = (unsigned long *) (cqr->data + |
| 1544 | sizeof(struct DE_eckd_data)); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 1545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | /* Build locate_record+read/write/ccws. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
| 1548 | recid = first_rec; |
| 1549 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { |
| 1550 | /* Only standard blocks so there is just one locate record. */ |
| 1551 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1552 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1553 | last_rec - recid + 1, cmd, basedev, blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1555 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1557 | if (dasd_page_cache) { |
| 1558 | char *copy = kmem_cache_alloc(dasd_page_cache, |
Christoph Lameter | 441e143 | 2006-12-06 20:33:19 -0800 | [diff] [blame] | 1559 | GFP_DMA | __GFP_NOWARN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | if (copy && rq_data_dir(req) == WRITE) |
| 1561 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); |
| 1562 | if (copy) |
| 1563 | dst = copy + bv->bv_offset; |
| 1564 | } |
| 1565 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 1566 | sector_t trkid = recid; |
| 1567 | unsigned int recoffs = sector_div(trkid, blk_per_trk); |
| 1568 | rcmd = cmd; |
| 1569 | count = blksize; |
| 1570 | /* Locate record for cdl special block ? */ |
| 1571 | if (private->uses_cdl && recid < 2*blk_per_trk) { |
| 1572 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ |
| 1573 | rcmd |= 0x8; |
| 1574 | count = dasd_eckd_cdl_reclen(recid); |
Horst Hummel | ec5883a | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1575 | if (count < blksize && |
| 1576 | rq_data_dir(req) == READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | memset(dst + count, 0xe5, |
| 1578 | blksize - count); |
| 1579 | } |
| 1580 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1581 | locate_record(ccw++, LO_data++, |
| 1582 | trkid, recoffs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1583 | 1, rcmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | } |
| 1585 | /* Locate record for standard blocks ? */ |
| 1586 | if (private->uses_cdl && recid == 2*blk_per_trk) { |
| 1587 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1588 | locate_record(ccw++, LO_data++, |
| 1589 | trkid, recoffs + 1, |
| 1590 | last_rec - recid + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1591 | cmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | /* Read/write ccw. */ |
| 1594 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1595 | ccw->cmd_code = rcmd; |
| 1596 | ccw->count = count; |
| 1597 | if (idal_is_needed(dst, blksize)) { |
| 1598 | ccw->cda = (__u32)(addr_t) idaws; |
| 1599 | ccw->flags = CCW_FLAG_IDA; |
| 1600 | idaws = idal_create_words(idaws, dst, blksize); |
| 1601 | } else { |
| 1602 | ccw->cda = (__u32)(addr_t) dst; |
| 1603 | ccw->flags = 0; |
| 1604 | } |
| 1605 | ccw++; |
| 1606 | dst += blksize; |
| 1607 | recid++; |
| 1608 | } |
| 1609 | } |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1610 | if (req->cmd_flags & REQ_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1611 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1612 | cqr->startdev = startdev; |
| 1613 | cqr->memdev = startdev; |
| 1614 | cqr->block = block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 1616 | cqr->lpm = private->path_data.ppm; |
| 1617 | cqr->retries = 256; |
| 1618 | cqr->buildclk = get_clock(); |
| 1619 | cqr->status = DASD_CQR_FILLED; |
| 1620 | return cqr; |
| 1621 | } |
| 1622 | |
| 1623 | static int |
| 1624 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 1625 | { |
| 1626 | struct dasd_eckd_private *private; |
| 1627 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1628 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | struct bio_vec *bv; |
| 1630 | char *dst, *cda; |
| 1631 | unsigned int blksize, blk_per_trk, off; |
| 1632 | sector_t recid; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1633 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (!dasd_page_cache) |
| 1636 | goto out; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1637 | private = (struct dasd_eckd_private *) cqr->block->base->private; |
| 1638 | blksize = cqr->block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1640 | recid = req->sector >> cqr->block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | ccw = cqr->cpaddr; |
| 1642 | /* Skip over define extent & locate record. */ |
| 1643 | ccw++; |
| 1644 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) |
| 1645 | ccw++; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1646 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1648 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 1649 | /* Skip locate record. */ |
| 1650 | if (private->uses_cdl && recid <= 2*blk_per_trk) |
| 1651 | ccw++; |
| 1652 | if (dst) { |
| 1653 | if (ccw->flags & CCW_FLAG_IDA) |
| 1654 | cda = *((char **)((addr_t) ccw->cda)); |
| 1655 | else |
| 1656 | cda = (char *)((addr_t) ccw->cda); |
| 1657 | if (dst != cda) { |
| 1658 | if (rq_data_dir(req) == READ) |
| 1659 | memcpy(dst, cda, bv->bv_len); |
| 1660 | kmem_cache_free(dasd_page_cache, |
| 1661 | (void *)((addr_t)cda & PAGE_MASK)); |
| 1662 | } |
| 1663 | dst = NULL; |
| 1664 | } |
| 1665 | ccw++; |
| 1666 | recid++; |
| 1667 | } |
| 1668 | } |
| 1669 | out: |
| 1670 | status = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1671 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | return status; |
| 1673 | } |
| 1674 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1675 | /* |
| 1676 | * Modify ccw chain in cqr so it can be started on a base device. |
| 1677 | * |
| 1678 | * Note that this is not enough to restart the cqr! |
| 1679 | * Either reset cqr->startdev as well (summary unit check handling) |
| 1680 | * or restart via separate cqr (as in ERP handling). |
| 1681 | */ |
| 1682 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) |
| 1683 | { |
| 1684 | struct ccw1 *ccw; |
| 1685 | struct PFX_eckd_data *pfxdata; |
| 1686 | |
| 1687 | ccw = cqr->cpaddr; |
| 1688 | pfxdata = cqr->data; |
| 1689 | |
| 1690 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { |
| 1691 | pfxdata->validity.verify_base = 0; |
| 1692 | pfxdata->validity.hyper_pav = 0; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 |
| 1697 | |
| 1698 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, |
| 1699 | struct dasd_block *block, |
| 1700 | struct request *req) |
| 1701 | { |
| 1702 | struct dasd_eckd_private *private; |
| 1703 | struct dasd_device *startdev; |
| 1704 | unsigned long flags; |
| 1705 | struct dasd_ccw_req *cqr; |
| 1706 | |
| 1707 | startdev = dasd_alias_get_start_dev(base); |
| 1708 | if (!startdev) |
| 1709 | startdev = base; |
| 1710 | private = (struct dasd_eckd_private *) startdev->private; |
| 1711 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) |
| 1712 | return ERR_PTR(-EBUSY); |
| 1713 | |
| 1714 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); |
| 1715 | private->count++; |
| 1716 | cqr = dasd_eckd_build_cp(startdev, block, req); |
| 1717 | if (IS_ERR(cqr)) |
| 1718 | private->count--; |
| 1719 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); |
| 1720 | return cqr; |
| 1721 | } |
| 1722 | |
| 1723 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, |
| 1724 | struct request *req) |
| 1725 | { |
| 1726 | struct dasd_eckd_private *private; |
| 1727 | unsigned long flags; |
| 1728 | |
| 1729 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 1730 | private = (struct dasd_eckd_private *) cqr->memdev->private; |
| 1731 | private->count--; |
| 1732 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 1733 | return dasd_eckd_free_cp(cqr, req); |
| 1734 | } |
| 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | static int |
| 1737 | dasd_eckd_fill_info(struct dasd_device * device, |
| 1738 | struct dasd_information2_t * info) |
| 1739 | { |
| 1740 | struct dasd_eckd_private *private; |
| 1741 | |
| 1742 | private = (struct dasd_eckd_private *) device->private; |
| 1743 | info->label_block = 2; |
| 1744 | info->FBA_layout = private->uses_cdl ? 0 : 1; |
| 1745 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; |
| 1746 | info->characteristics_size = sizeof(struct dasd_eckd_characteristics); |
| 1747 | memcpy(info->characteristics, &private->rdc_data, |
| 1748 | sizeof(struct dasd_eckd_characteristics)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1749 | info->confdata_size = sizeof(struct dasd_eckd_confdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | memcpy(info->configuration_data, &private->conf_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1751 | sizeof(struct dasd_eckd_confdata)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * SECTION: ioctl functions for eckd devices. |
| 1757 | */ |
| 1758 | |
| 1759 | /* |
| 1760 | * Release device ioctl. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1761 | * Buils a channel programm to releases a prior reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | * (see dasd_eckd_reserve) device. |
| 1763 | */ |
| 1764 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1765 | dasd_eckd_release(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | struct dasd_ccw_req *cqr; |
| 1768 | int rc; |
| 1769 | |
| 1770 | if (!capable(CAP_SYS_ADMIN)) |
| 1771 | return -EACCES; |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 1774 | 1, 32, device); |
| 1775 | if (IS_ERR(cqr)) { |
| 1776 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1777 | "Could not allocate initialization request"); |
| 1778 | return PTR_ERR(cqr); |
| 1779 | } |
| 1780 | cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE; |
| 1781 | cqr->cpaddr->flags |= CCW_FLAG_SLI; |
| 1782 | cqr->cpaddr->count = 32; |
| 1783 | cqr->cpaddr->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1784 | cqr->startdev = device; |
| 1785 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1787 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 1788 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | cqr->expires = 2 * HZ; |
| 1790 | cqr->buildclk = get_clock(); |
| 1791 | cqr->status = DASD_CQR_FILLED; |
| 1792 | |
| 1793 | rc = dasd_sleep_on_immediatly(cqr); |
| 1794 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1795 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | return rc; |
| 1797 | } |
| 1798 | |
| 1799 | /* |
| 1800 | * Reserve device ioctl. |
| 1801 | * Options are set to 'synchronous wait for interrupt' and |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1802 | * 'timeout the request'. This leads to a terminate IO if |
| 1803 | * the interrupt is outstanding for a certain time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | */ |
| 1805 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1806 | dasd_eckd_reserve(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | struct dasd_ccw_req *cqr; |
| 1809 | int rc; |
| 1810 | |
| 1811 | if (!capable(CAP_SYS_ADMIN)) |
| 1812 | return -EACCES; |
| 1813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 1815 | 1, 32, device); |
| 1816 | if (IS_ERR(cqr)) { |
| 1817 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1818 | "Could not allocate initialization request"); |
| 1819 | return PTR_ERR(cqr); |
| 1820 | } |
| 1821 | cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE; |
| 1822 | cqr->cpaddr->flags |= CCW_FLAG_SLI; |
| 1823 | cqr->cpaddr->count = 32; |
| 1824 | cqr->cpaddr->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1825 | cqr->startdev = device; |
| 1826 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1828 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 1829 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | cqr->expires = 2 * HZ; |
| 1831 | cqr->buildclk = get_clock(); |
| 1832 | cqr->status = DASD_CQR_FILLED; |
| 1833 | |
| 1834 | rc = dasd_sleep_on_immediatly(cqr); |
| 1835 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1836 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | return rc; |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * Steal lock ioctl - unconditional reserve device. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1842 | * Buils a channel programm to break a device's reservation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | * (unconditional reserve) |
| 1844 | */ |
| 1845 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1846 | dasd_eckd_steal_lock(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | struct dasd_ccw_req *cqr; |
| 1849 | int rc; |
| 1850 | |
| 1851 | if (!capable(CAP_SYS_ADMIN)) |
| 1852 | return -EACCES; |
| 1853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 1855 | 1, 32, device); |
| 1856 | if (IS_ERR(cqr)) { |
| 1857 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1858 | "Could not allocate initialization request"); |
| 1859 | return PTR_ERR(cqr); |
| 1860 | } |
| 1861 | cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK; |
| 1862 | cqr->cpaddr->flags |= CCW_FLAG_SLI; |
| 1863 | cqr->cpaddr->count = 32; |
| 1864 | cqr->cpaddr->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1865 | cqr->startdev = device; |
| 1866 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1868 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 1869 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | cqr->expires = 2 * HZ; |
| 1871 | cqr->buildclk = get_clock(); |
| 1872 | cqr->status = DASD_CQR_FILLED; |
| 1873 | |
| 1874 | rc = dasd_sleep_on_immediatly(cqr); |
| 1875 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1876 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | return rc; |
| 1878 | } |
| 1879 | |
| 1880 | /* |
| 1881 | * Read performance statistics |
| 1882 | */ |
| 1883 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1884 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | struct dasd_psf_prssd_data *prssdp; |
| 1887 | struct dasd_rssd_perf_stats_t *stats; |
| 1888 | struct dasd_ccw_req *cqr; |
| 1889 | struct ccw1 *ccw; |
| 1890 | int rc; |
| 1891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | cqr = dasd_smalloc_request(dasd_eckd_discipline.name, |
| 1893 | 1 /* PSF */ + 1 /* RSSD */ , |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1894 | (sizeof(struct dasd_psf_prssd_data) + |
| 1895 | sizeof(struct dasd_rssd_perf_stats_t)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | device); |
| 1897 | if (IS_ERR(cqr)) { |
| 1898 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 1899 | "Could not allocate initialization request"); |
| 1900 | return PTR_ERR(cqr); |
| 1901 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1902 | cqr->startdev = device; |
| 1903 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | cqr->retries = 0; |
| 1905 | cqr->expires = 10 * HZ; |
| 1906 | |
| 1907 | /* Prepare for Read Subsystem Data */ |
| 1908 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1909 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | prssdp->order = PSF_ORDER_PRSSD; |
Joe Perches | 5d67d16 | 2008-01-26 14:11:20 +0100 | [diff] [blame] | 1911 | prssdp->suborder = 0x01; /* Performance Statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
| 1913 | |
| 1914 | ccw = cqr->cpaddr; |
| 1915 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1916 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | ccw->flags |= CCW_FLAG_CC; |
| 1918 | ccw->cda = (__u32)(addr_t) prssdp; |
| 1919 | |
| 1920 | /* Read Subsystem Data - Performance Statistics */ |
| 1921 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1922 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
| 1924 | ccw++; |
| 1925 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1926 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | ccw->cda = (__u32)(addr_t) stats; |
| 1928 | |
| 1929 | cqr->buildclk = get_clock(); |
| 1930 | cqr->status = DASD_CQR_FILLED; |
| 1931 | rc = dasd_sleep_on(cqr); |
| 1932 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 1934 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1935 | if (copy_to_user(argp, stats, |
| 1936 | sizeof(struct dasd_rssd_perf_stats_t))) |
| 1937 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1939 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | return rc; |
| 1941 | } |
| 1942 | |
| 1943 | /* |
| 1944 | * Get attributes (cache operations) |
| 1945 | * Returnes the cache attributes used in Define Extend (DE). |
| 1946 | */ |
| 1947 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1948 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1950 | struct dasd_eckd_private *private = |
| 1951 | (struct dasd_eckd_private *)device->private; |
| 1952 | struct attrib_data_t attrib = private->attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | int rc; |
| 1954 | |
| 1955 | if (!capable(CAP_SYS_ADMIN)) |
| 1956 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1957 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | return -EINVAL; |
| 1959 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1960 | rc = 0; |
| 1961 | if (copy_to_user(argp, (long *) &attrib, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1962 | sizeof(struct attrib_data_t))) |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1963 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
| 1965 | return rc; |
| 1966 | } |
| 1967 | |
| 1968 | /* |
| 1969 | * Set attributes (cache operations) |
| 1970 | * Stores the attributes for cache operation to be used in Define Extend (DE). |
| 1971 | */ |
| 1972 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1973 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1975 | struct dasd_eckd_private *private = |
| 1976 | (struct dasd_eckd_private *)device->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | struct attrib_data_t attrib; |
| 1978 | |
| 1979 | if (!capable(CAP_SYS_ADMIN)) |
| 1980 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1981 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | return -EINVAL; |
| 1983 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1984 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | private->attrib = attrib; |
| 1987 | |
| 1988 | DEV_MESSAGE(KERN_INFO, device, |
| 1989 | "cache operation mode set to %x (%i cylinder prestage)", |
| 1990 | private->attrib.operation, private->attrib.nr_cyl); |
| 1991 | return 0; |
| 1992 | } |
| 1993 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1994 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1995 | dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp) |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1996 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1997 | struct dasd_device *device = block->base; |
| 1998 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 1999 | switch (cmd) { |
| 2000 | case BIODASDGATTR: |
| 2001 | return dasd_eckd_get_attrib(device, argp); |
| 2002 | case BIODASDSATTR: |
| 2003 | return dasd_eckd_set_attrib(device, argp); |
| 2004 | case BIODASDPSRD: |
| 2005 | return dasd_eckd_performance(device, argp); |
| 2006 | case BIODASDRLSE: |
| 2007 | return dasd_eckd_release(device); |
| 2008 | case BIODASDRSRV: |
| 2009 | return dasd_eckd_reserve(device); |
| 2010 | case BIODASDSLCK: |
| 2011 | return dasd_eckd_steal_lock(device); |
| 2012 | default: |
| 2013 | return -ENOIOCTLCMD; |
| 2014 | } |
| 2015 | } |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | /* |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2018 | * Dump the range of CCWs into 'page' buffer |
| 2019 | * and return number of printed chars. |
| 2020 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2021 | static int |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2022 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
| 2023 | { |
| 2024 | int len, count; |
| 2025 | char *datap; |
| 2026 | |
| 2027 | len = 0; |
| 2028 | while (from <= to) { |
| 2029 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2030 | " CCW %p: %08X %08X DAT:", |
| 2031 | from, ((int *) from)[0], ((int *) from)[1]); |
| 2032 | |
| 2033 | /* get pointer to data (consider IDALs) */ |
| 2034 | if (from->flags & CCW_FLAG_IDA) |
| 2035 | datap = (char *) *((addr_t *) (addr_t) from->cda); |
| 2036 | else |
| 2037 | datap = (char *) ((addr_t) from->cda); |
| 2038 | |
| 2039 | /* dump data (max 32 bytes) */ |
| 2040 | for (count = 0; count < from->count && count < 32; count++) { |
| 2041 | if (count % 8 == 0) len += sprintf(page + len, " "); |
| 2042 | if (count % 4 == 0) len += sprintf(page + len, " "); |
| 2043 | len += sprintf(page + len, "%02x", datap[count]); |
| 2044 | } |
| 2045 | len += sprintf(page + len, "\n"); |
| 2046 | from++; |
| 2047 | } |
| 2048 | return len; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | * Print sense data and related channel program. |
| 2053 | * Parts are printed because printk buffer is only 1024 bytes. |
| 2054 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2055 | static void dasd_eckd_dump_sense(struct dasd_device *device, |
| 2056 | struct dasd_ccw_req *req, struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | { |
| 2058 | char *page; |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2059 | struct ccw1 *first, *last, *fail, *from, *to; |
| 2060 | int len, sl, sct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | |
| 2062 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 2063 | if (page == NULL) { |
| 2064 | DEV_MESSAGE(KERN_ERR, device, " %s", |
| 2065 | "No memory to dump sense data"); |
| 2066 | return; |
| 2067 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2068 | /* dump the sense data */ |
| 2069 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | " I/O status report for device %s:\n", |
| 2071 | device->cdev->dev.bus_id); |
| 2072 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2073 | " in req: %p CS: 0x%02X DS: 0x%02X\n", req, |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 2074 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2076 | " device %s: Failing CCW: %p\n", |
| 2077 | device->cdev->dev.bus_id, |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 2078 | (void *) (addr_t) irb->scsw.cmd.cpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | if (irb->esw.esw0.erw.cons) { |
| 2080 | for (sl = 0; sl < 4; sl++) { |
| 2081 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2082 | " Sense(hex) %2d-%2d:", |
| 2083 | (8 * sl), ((8 * sl) + 7)); |
| 2084 | |
| 2085 | for (sct = 0; sct < 8; sct++) { |
| 2086 | len += sprintf(page + len, " %02x", |
| 2087 | irb->ecw[8 * sl + sct]); |
| 2088 | } |
| 2089 | len += sprintf(page + len, "\n"); |
| 2090 | } |
| 2091 | |
| 2092 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { |
| 2093 | /* 24 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2094 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2095 | " 24 Byte: %x MSG %x, " |
| 2096 | "%s MSGb to SYSOP\n", |
| 2097 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, |
| 2098 | irb->ecw[1] & 0x10 ? "" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | } else { |
| 2100 | /* 32 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2101 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2102 | " 32 Byte: Format: %x " |
| 2103 | "Exception class %x\n", |
| 2104 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | } |
| 2106 | } else { |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2107 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2108 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2110 | printk("%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2112 | if (req) { |
| 2113 | /* req == NULL for unsolicited interrupts */ |
| 2114 | /* dump the Channel Program (max 140 Bytes per line) */ |
| 2115 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ |
| 2116 | first = req->cpaddr; |
| 2117 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); |
| 2118 | to = min(first + 6, last); |
| 2119 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 2120 | " Related CP in req: %p\n", req); |
| 2121 | dasd_eckd_dump_ccw_range(first, to, page + len); |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2122 | printk("%s", page); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2123 | |
| 2124 | /* print failing CCW area (maximum 4) */ |
| 2125 | /* scsw->cda is either valid or zero */ |
| 2126 | len = 0; |
| 2127 | from = ++to; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 2128 | fail = (struct ccw1 *)(addr_t) |
| 2129 | irb->scsw.cmd.cpa; /* failing CCW */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2130 | if (from < fail - 2) { |
| 2131 | from = fail - 2; /* there is a gap - print header */ |
| 2132 | len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n"); |
| 2133 | } |
| 2134 | to = min(fail + 1, last); |
| 2135 | len += dasd_eckd_dump_ccw_range(from, to, page + len); |
| 2136 | |
| 2137 | /* print last CCWs (maximum 2) */ |
| 2138 | from = max(from, ++to); |
| 2139 | if (from < last - 1) { |
| 2140 | from = last - 1; /* there is a gap - print header */ |
| 2141 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); |
| 2142 | } |
| 2143 | len += dasd_eckd_dump_ccw_range(from, last, page + len); |
| 2144 | if (len > 0) |
| 2145 | printk("%s", page); |
| 2146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | free_page((unsigned long) page); |
| 2148 | } |
| 2149 | |
| 2150 | /* |
| 2151 | * max_blocks is dependent on the amount of storage that is available |
| 2152 | * in the static io buffer for each device. Currently each device has |
| 2153 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has |
| 2154 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use |
| 2155 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In |
| 2156 | * addition we have one define extent ccw + 16 bytes of data and one |
| 2157 | * locate record ccw + 16 bytes of data. That makes: |
| 2158 | * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. |
| 2159 | * We want to fit two into the available memory so that we can immediately |
| 2160 | * start the next request if one finishes off. That makes 249.5 blocks |
| 2161 | * for one request. Give a little safety and the result is 240. |
| 2162 | */ |
| 2163 | static struct dasd_discipline dasd_eckd_discipline = { |
| 2164 | .owner = THIS_MODULE, |
| 2165 | .name = "ECKD", |
| 2166 | .ebcname = "ECKD", |
| 2167 | .max_blocks = 240, |
| 2168 | .check_device = dasd_eckd_check_characteristics, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2169 | .uncheck_device = dasd_eckd_uncheck_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | .do_analysis = dasd_eckd_do_analysis, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2171 | .ready_to_online = dasd_eckd_ready_to_online, |
| 2172 | .online_to_ready = dasd_eckd_online_to_ready, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | .fill_geometry = dasd_eckd_fill_geometry, |
| 2174 | .start_IO = dasd_start_IO, |
| 2175 | .term_IO = dasd_term_IO, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2176 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | .format_device = dasd_eckd_format_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | .erp_action = dasd_eckd_erp_action, |
| 2179 | .erp_postaction = dasd_eckd_erp_postaction, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2180 | .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt, |
| 2181 | .build_cp = dasd_eckd_build_alias_cp, |
| 2182 | .free_cp = dasd_eckd_free_alias_cp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | .dump_sense = dasd_eckd_dump_sense, |
| 2184 | .fill_info = dasd_eckd_fill_info, |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2185 | .ioctl = dasd_eckd_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | }; |
| 2187 | |
| 2188 | static int __init |
| 2189 | dasd_eckd_init(void) |
| 2190 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2192 | return ccw_driver_register(&dasd_eckd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | static void __exit |
| 2196 | dasd_eckd_cleanup(void) |
| 2197 | { |
| 2198 | ccw_driver_unregister(&dasd_eckd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | module_init(dasd_eckd_init); |
| 2202 | module_exit(dasd_eckd_cleanup); |