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