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> |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 8 | * Copyright IBM Corp. 1999, 2009 |
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 | */ |
| 12 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 13 | #define KMSG_COMPONENT "dasd-eckd" |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/stddef.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/hdreg.h> /* HDIO_GETGEO */ |
| 19 | #include <linux/bio.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | |
| 23 | #include <asm/debug.h> |
| 24 | #include <asm/idals.h> |
| 25 | #include <asm/ebcdic.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/todclk.h> |
| 28 | #include <asm/uaccess.h> |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 29 | #include <asm/cio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/ccwdev.h> |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 31 | #include <asm/itcw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include "dasd_int.h" |
| 34 | #include "dasd_eckd.h" |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 35 | #include "../cio/chsc.h" |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #ifdef PRINTK_HEADER |
| 39 | #undef PRINTK_HEADER |
| 40 | #endif /* PRINTK_HEADER */ |
| 41 | #define PRINTK_HEADER "dasd(eckd):" |
| 42 | |
| 43 | #define ECKD_C0(i) (i->home_bytes) |
| 44 | #define ECKD_F(i) (i->formula) |
| 45 | #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\ |
| 46 | (i->factors.f_0x02.f1)) |
| 47 | #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\ |
| 48 | (i->factors.f_0x02.f2)) |
| 49 | #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\ |
| 50 | (i->factors.f_0x02.f3)) |
| 51 | #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0) |
| 52 | #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0) |
| 53 | #define ECKD_F6(i) (i->factor6) |
| 54 | #define ECKD_F7(i) (i->factor7) |
| 55 | #define ECKD_F8(i) (i->factor8) |
| 56 | |
| 57 | MODULE_LICENSE("GPL"); |
| 58 | |
| 59 | static struct dasd_discipline dasd_eckd_discipline; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* The ccw bus type uses this table to find devices that it sends to |
| 62 | * dasd_eckd_probe */ |
| 63 | static struct ccw_device_id dasd_eckd_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 64 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
| 65 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, |
| 66 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3}, |
| 67 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
| 68 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, |
| 69 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, |
| 70 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, |
| 71 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, |
| 72 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, |
| 73 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { /* end of list */ }, |
| 75 | }; |
| 76 | |
| 77 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); |
| 78 | |
| 79 | static struct ccw_driver dasd_eckd_driver; /* see below */ |
| 80 | |
| 81 | /* initial attempt at a probe function. this can be simplified once |
| 82 | * the other detection code is gone */ |
| 83 | static int |
| 84 | dasd_eckd_probe (struct ccw_device *cdev) |
| 85 | { |
| 86 | int ret; |
| 87 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 88 | /* set ECKD specific ccw-device options */ |
| 89 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE); |
| 90 | if (ret) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 91 | DBF_EVENT(DBF_WARNING, |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 92 | "dasd_eckd_probe: could not set ccw-device options " |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 93 | "for %s\n", dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return ret; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 95 | } |
| 96 | ret = dasd_generic_probe(cdev, &dasd_eckd_discipline); |
| 97 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static int |
| 101 | dasd_eckd_set_online(struct ccw_device *cdev) |
| 102 | { |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 103 | return dasd_generic_set_online(cdev, &dasd_eckd_discipline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | static const int sizes_trk0[] = { 28, 148, 84 }; |
| 107 | #define LABEL_SIZE 140 |
| 108 | |
| 109 | static inline unsigned int |
| 110 | round_up_multiple(unsigned int no, unsigned int mult) |
| 111 | { |
| 112 | int rem = no % mult; |
| 113 | return (rem ? no - rem + mult : no); |
| 114 | } |
| 115 | |
| 116 | static inline unsigned int |
| 117 | ceil_quot(unsigned int d1, unsigned int d2) |
| 118 | { |
| 119 | return (d1 + (d2 - 1)) / d2; |
| 120 | } |
| 121 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 122 | static unsigned int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | recs_per_track(struct dasd_eckd_characteristics * rdc, |
| 124 | unsigned int kl, unsigned int dl) |
| 125 | { |
| 126 | int dn, kn; |
| 127 | |
| 128 | switch (rdc->dev_type) { |
| 129 | case 0x3380: |
| 130 | if (kl) |
| 131 | return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) + |
| 132 | ceil_quot(dl + 12, 32)); |
| 133 | else |
| 134 | return 1499 / (15 + ceil_quot(dl + 12, 32)); |
| 135 | case 0x3390: |
| 136 | dn = ceil_quot(dl + 6, 232) + 1; |
| 137 | if (kl) { |
| 138 | kn = ceil_quot(kl + 6, 232) + 1; |
| 139 | return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) + |
| 140 | 9 + ceil_quot(dl + 6 * dn, 34)); |
| 141 | } else |
| 142 | return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34)); |
| 143 | case 0x9345: |
| 144 | dn = ceil_quot(dl + 6, 232) + 1; |
| 145 | if (kl) { |
| 146 | kn = ceil_quot(kl + 6, 232) + 1; |
| 147 | return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) + |
| 148 | ceil_quot(dl + 6 * dn, 34)); |
| 149 | } else |
| 150 | return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34)); |
| 151 | } |
| 152 | return 0; |
| 153 | } |
| 154 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 155 | static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head) |
| 156 | { |
| 157 | geo->cyl = (__u16) cyl; |
| 158 | geo->head = cyl >> 16; |
| 159 | geo->head <<= 4; |
| 160 | geo->head |= head; |
| 161 | } |
| 162 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 163 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | check_XRC (struct ccw1 *de_ccw, |
| 165 | struct DE_eckd_data *data, |
| 166 | struct dasd_device *device) |
| 167 | { |
| 168 | struct dasd_eckd_private *private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 169 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | private = (struct dasd_eckd_private *) device->private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 172 | if (!private->rdc_data.facilities.XRC_supported) |
| 173 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | /* switch on System Time Stamp - needed for XRC Support */ |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 176 | data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */ |
| 177 | data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */ |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 178 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 179 | rc = get_sync_clock(&data->ep_sys_time); |
| 180 | /* Ignore return code if sync clock is switched off. */ |
| 181 | if (rc == -ENOSYS || rc == -EACCES) |
| 182 | rc = 0; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 183 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 184 | de_ccw->count = sizeof(struct DE_eckd_data); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 185 | de_ccw->flags |= CCW_FLAG_SLI; |
| 186 | return rc; |
| 187 | } |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 188 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 189 | static int |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 190 | define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk, |
| 191 | unsigned int totrk, int cmd, struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | struct dasd_eckd_private *private; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 194 | u32 begcyl, endcyl; |
| 195 | u16 heads, beghead, endhead; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 196 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | private = (struct dasd_eckd_private *) device->private; |
| 199 | |
| 200 | ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT; |
| 201 | ccw->flags = 0; |
| 202 | ccw->count = 16; |
| 203 | ccw->cda = (__u32) __pa(data); |
| 204 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 205 | memset(data, 0, sizeof(struct DE_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | switch (cmd) { |
| 207 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 208 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 209 | case DASD_ECKD_CCW_READ: |
| 210 | case DASD_ECKD_CCW_READ_MT: |
| 211 | case DASD_ECKD_CCW_READ_CKD: |
| 212 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 213 | case DASD_ECKD_CCW_READ_KD: |
| 214 | case DASD_ECKD_CCW_READ_KD_MT: |
| 215 | case DASD_ECKD_CCW_READ_COUNT: |
| 216 | data->mask.perm = 0x1; |
| 217 | data->attributes.operation = private->attrib.operation; |
| 218 | break; |
| 219 | case DASD_ECKD_CCW_WRITE: |
| 220 | case DASD_ECKD_CCW_WRITE_MT: |
| 221 | case DASD_ECKD_CCW_WRITE_KD: |
| 222 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 223 | data->mask.perm = 0x02; |
| 224 | data->attributes.operation = private->attrib.operation; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 225 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | break; |
| 227 | case DASD_ECKD_CCW_WRITE_CKD: |
| 228 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 229 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 230 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | break; |
| 232 | case DASD_ECKD_CCW_ERASE: |
| 233 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 234 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 235 | data->mask.perm = 0x3; |
| 236 | data->mask.auth = 0x1; |
| 237 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 238 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | break; |
| 240 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 241 | dev_err(&device->cdev->dev, |
| 242 | "0x%x is not a known command\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | |
| 246 | data->attributes.mode = 0x3; /* ECKD */ |
| 247 | |
| 248 | if ((private->rdc_data.cu_type == 0x2105 || |
| 249 | private->rdc_data.cu_type == 0x2107 || |
| 250 | private->rdc_data.cu_type == 0x1750) |
| 251 | && !(private->uses_cdl && trk < 2)) |
| 252 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ |
| 253 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 254 | heads = private->rdc_data.trk_per_cyl; |
| 255 | begcyl = trk / heads; |
| 256 | beghead = trk % heads; |
| 257 | endcyl = totrk / heads; |
| 258 | endhead = totrk % heads; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | /* check for sequential prestage - enhance cylinder range */ |
| 261 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || |
| 262 | data->attributes.operation == DASD_SEQ_ACCESS) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 263 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 264 | if (endcyl + private->attrib.nr_cyl < private->real_cyl) |
| 265 | endcyl += private->attrib.nr_cyl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | else |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 267 | endcyl = (private->real_cyl - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 270 | set_ch_t(&data->beg_ext, begcyl, beghead); |
| 271 | set_ch_t(&data->end_ext, endcyl, endhead); |
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 */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 286 | pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */ |
| 287 | pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 288 | pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */ |
| 289 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 290 | rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 291 | /* Ignore return code if sync clock is switched off. */ |
| 292 | if (rc == -ENOSYS || rc == -EACCES) |
| 293 | rc = 0; |
| 294 | return rc; |
| 295 | } |
| 296 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 297 | static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk, |
| 298 | unsigned int rec_on_trk, int count, int cmd, |
| 299 | struct dasd_device *device, unsigned int reclen, |
| 300 | unsigned int tlf) |
| 301 | { |
| 302 | struct dasd_eckd_private *private; |
| 303 | int sector; |
| 304 | int dn, d; |
| 305 | |
| 306 | private = (struct dasd_eckd_private *) device->private; |
| 307 | |
| 308 | memset(data, 0, sizeof(*data)); |
| 309 | sector = 0; |
| 310 | if (rec_on_trk) { |
| 311 | switch (private->rdc_data.dev_type) { |
| 312 | case 0x3390: |
| 313 | dn = ceil_quot(reclen + 6, 232); |
| 314 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); |
| 315 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 316 | break; |
| 317 | case 0x3380: |
| 318 | d = 7 + ceil_quot(reclen + 12, 32); |
| 319 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 320 | break; |
| 321 | } |
| 322 | } |
| 323 | data->sector = sector; |
| 324 | /* note: meaning of count depends on the operation |
| 325 | * for record based I/O it's the number of records, but for |
| 326 | * track based I/O it's the number of tracks |
| 327 | */ |
| 328 | data->count = count; |
| 329 | switch (cmd) { |
| 330 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 331 | data->operation.orientation = 0x3; |
| 332 | data->operation.operation = 0x03; |
| 333 | break; |
| 334 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 335 | data->operation.orientation = 0x3; |
| 336 | data->operation.operation = 0x16; |
| 337 | break; |
| 338 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 339 | data->operation.orientation = 0x1; |
| 340 | data->operation.operation = 0x03; |
| 341 | data->count++; |
| 342 | break; |
| 343 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 344 | data->operation.orientation = 0x3; |
| 345 | data->operation.operation = 0x16; |
| 346 | data->count++; |
| 347 | break; |
| 348 | case DASD_ECKD_CCW_WRITE: |
| 349 | case DASD_ECKD_CCW_WRITE_MT: |
| 350 | case DASD_ECKD_CCW_WRITE_KD: |
| 351 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 352 | data->auxiliary.length_valid = 0x1; |
| 353 | data->length = reclen; |
| 354 | data->operation.operation = 0x01; |
| 355 | break; |
| 356 | case DASD_ECKD_CCW_WRITE_CKD: |
| 357 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 358 | data->auxiliary.length_valid = 0x1; |
| 359 | data->length = reclen; |
| 360 | data->operation.operation = 0x03; |
| 361 | break; |
| 362 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 363 | data->auxiliary.length_valid = 0x1; |
| 364 | data->length = reclen; /* not tlf, as one might think */ |
| 365 | data->operation.operation = 0x3F; |
| 366 | data->extended_operation = 0x23; |
| 367 | break; |
| 368 | case DASD_ECKD_CCW_READ: |
| 369 | case DASD_ECKD_CCW_READ_MT: |
| 370 | case DASD_ECKD_CCW_READ_KD: |
| 371 | case DASD_ECKD_CCW_READ_KD_MT: |
| 372 | data->auxiliary.length_valid = 0x1; |
| 373 | data->length = reclen; |
| 374 | data->operation.operation = 0x06; |
| 375 | break; |
| 376 | case DASD_ECKD_CCW_READ_CKD: |
| 377 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 378 | data->auxiliary.length_valid = 0x1; |
| 379 | data->length = reclen; |
| 380 | data->operation.operation = 0x16; |
| 381 | break; |
| 382 | case DASD_ECKD_CCW_READ_COUNT: |
| 383 | data->operation.operation = 0x06; |
| 384 | break; |
| 385 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 386 | data->auxiliary.length_valid = 0x1; |
| 387 | data->length = tlf; |
| 388 | data->operation.operation = 0x0C; |
| 389 | break; |
| 390 | case DASD_ECKD_CCW_ERASE: |
| 391 | data->length = reclen; |
| 392 | data->auxiliary.length_valid = 0x1; |
| 393 | data->operation.operation = 0x0b; |
| 394 | break; |
| 395 | default: |
| 396 | DBF_DEV_EVENT(DBF_ERR, device, |
| 397 | "fill LRE unknown opcode 0x%x", cmd); |
| 398 | BUG(); |
| 399 | } |
| 400 | set_ch_t(&data->seek_addr, |
| 401 | trk / private->rdc_data.trk_per_cyl, |
| 402 | trk % private->rdc_data.trk_per_cyl); |
| 403 | data->search_arg.cyl = data->seek_addr.cyl; |
| 404 | data->search_arg.head = data->seek_addr.head; |
| 405 | data->search_arg.record = rec_on_trk; |
| 406 | } |
| 407 | |
| 408 | static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
| 409 | unsigned int trk, unsigned int totrk, int cmd, |
| 410 | struct dasd_device *basedev, struct dasd_device *startdev, |
| 411 | unsigned char format, unsigned int rec_on_trk, int count, |
| 412 | unsigned int blksize, unsigned int tlf) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 413 | { |
| 414 | struct dasd_eckd_private *basepriv, *startpriv; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 415 | struct DE_eckd_data *dedata; |
| 416 | struct LRE_eckd_data *lredata; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 417 | u32 begcyl, endcyl; |
| 418 | u16 heads, beghead, endhead; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 419 | int rc = 0; |
| 420 | |
| 421 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 422 | startpriv = (struct dasd_eckd_private *) startdev->private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 423 | dedata = &pfxdata->define_extent; |
| 424 | lredata = &pfxdata->locate_record; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 425 | |
| 426 | ccw->cmd_code = DASD_ECKD_CCW_PFX; |
| 427 | ccw->flags = 0; |
| 428 | ccw->count = sizeof(*pfxdata); |
| 429 | ccw->cda = (__u32) __pa(pfxdata); |
| 430 | |
| 431 | memset(pfxdata, 0, sizeof(*pfxdata)); |
| 432 | /* prefix data */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 433 | if (format > 1) { |
| 434 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 435 | "PFX LRE unknown format 0x%x", format); |
| 436 | BUG(); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | pfxdata->format = format; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 440 | pfxdata->base_address = basepriv->ned->unit_addr; |
| 441 | pfxdata->base_lss = basepriv->ned->ID; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 442 | pfxdata->validity.define_extent = 1; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 443 | |
| 444 | /* private uid is kept up to date, conf_data may be outdated */ |
| 445 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 446 | pfxdata->validity.verify_base = 1; |
| 447 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 448 | pfxdata->validity.hyper_pav = 1; |
| 449 | } |
| 450 | |
| 451 | /* define extend data (mostly)*/ |
| 452 | switch (cmd) { |
| 453 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 454 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 455 | case DASD_ECKD_CCW_READ: |
| 456 | case DASD_ECKD_CCW_READ_MT: |
| 457 | case DASD_ECKD_CCW_READ_CKD: |
| 458 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 459 | case DASD_ECKD_CCW_READ_KD: |
| 460 | case DASD_ECKD_CCW_READ_KD_MT: |
| 461 | case DASD_ECKD_CCW_READ_COUNT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 462 | dedata->mask.perm = 0x1; |
| 463 | dedata->attributes.operation = basepriv->attrib.operation; |
| 464 | break; |
| 465 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 466 | dedata->mask.perm = 0x1; |
| 467 | dedata->attributes.operation = basepriv->attrib.operation; |
| 468 | dedata->blk_size = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 469 | break; |
| 470 | case DASD_ECKD_CCW_WRITE: |
| 471 | case DASD_ECKD_CCW_WRITE_MT: |
| 472 | case DASD_ECKD_CCW_WRITE_KD: |
| 473 | case DASD_ECKD_CCW_WRITE_KD_MT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 474 | dedata->mask.perm = 0x02; |
| 475 | dedata->attributes.operation = basepriv->attrib.operation; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 476 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 477 | break; |
| 478 | case DASD_ECKD_CCW_WRITE_CKD: |
| 479 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 480 | dedata->attributes.operation = DASD_BYPASS_CACHE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 481 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 482 | break; |
| 483 | case DASD_ECKD_CCW_ERASE: |
| 484 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 485 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 486 | dedata->mask.perm = 0x3; |
| 487 | dedata->mask.auth = 0x1; |
| 488 | dedata->attributes.operation = DASD_BYPASS_CACHE; |
| 489 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 490 | break; |
| 491 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 492 | dedata->mask.perm = 0x02; |
| 493 | dedata->attributes.operation = basepriv->attrib.operation; |
| 494 | dedata->blk_size = blksize; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 495 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 496 | break; |
| 497 | default: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 498 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 499 | "PFX LRE unknown opcode 0x%x", cmd); |
| 500 | BUG(); |
| 501 | return -EINVAL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 504 | dedata->attributes.mode = 0x3; /* ECKD */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 505 | |
| 506 | if ((basepriv->rdc_data.cu_type == 0x2105 || |
| 507 | basepriv->rdc_data.cu_type == 0x2107 || |
| 508 | basepriv->rdc_data.cu_type == 0x1750) |
| 509 | && !(basepriv->uses_cdl && trk < 2)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 510 | dedata->ga_extended |= 0x40; /* Regular Data Format Mode */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 511 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 512 | heads = basepriv->rdc_data.trk_per_cyl; |
| 513 | begcyl = trk / heads; |
| 514 | beghead = trk % heads; |
| 515 | endcyl = totrk / heads; |
| 516 | endhead = totrk % heads; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 517 | |
| 518 | /* check for sequential prestage - enhance cylinder range */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 519 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
| 520 | dedata->attributes.operation == DASD_SEQ_ACCESS) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 521 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 522 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
| 523 | endcyl += basepriv->attrib.nr_cyl; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 524 | else |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 525 | endcyl = (basepriv->real_cyl - 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 528 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
| 529 | set_ch_t(&dedata->end_ext, endcyl, endhead); |
| 530 | |
| 531 | if (format == 1) { |
| 532 | fill_LRE_data(lredata, trk, rec_on_trk, count, cmd, |
| 533 | basedev, blksize, tlf); |
| 534 | } |
| 535 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 536 | return rc; |
| 537 | } |
| 538 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 539 | static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
| 540 | unsigned int trk, unsigned int totrk, int cmd, |
| 541 | struct dasd_device *basedev, struct dasd_device *startdev) |
| 542 | { |
| 543 | return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev, |
| 544 | 0, 0, 0, 0, 0); |
| 545 | } |
| 546 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 547 | static void |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 548 | locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk, |
| 549 | unsigned int rec_on_trk, int no_rec, int cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | struct dasd_device * device, int reclen) |
| 551 | { |
| 552 | struct dasd_eckd_private *private; |
| 553 | int sector; |
| 554 | int dn, d; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | private = (struct dasd_eckd_private *) device->private; |
| 557 | |
| 558 | DBF_DEV_EVENT(DBF_INFO, device, |
| 559 | "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d", |
| 560 | trk, rec_on_trk, no_rec, cmd, reclen); |
| 561 | |
| 562 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD; |
| 563 | ccw->flags = 0; |
| 564 | ccw->count = 16; |
| 565 | ccw->cda = (__u32) __pa(data); |
| 566 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 567 | memset(data, 0, sizeof(struct LO_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | sector = 0; |
| 569 | if (rec_on_trk) { |
| 570 | switch (private->rdc_data.dev_type) { |
| 571 | case 0x3390: |
| 572 | dn = ceil_quot(reclen + 6, 232); |
| 573 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); |
| 574 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 575 | break; |
| 576 | case 0x3380: |
| 577 | d = 7 + ceil_quot(reclen + 12, 32); |
| 578 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | data->sector = sector; |
| 583 | data->count = no_rec; |
| 584 | switch (cmd) { |
| 585 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 586 | data->operation.orientation = 0x3; |
| 587 | data->operation.operation = 0x03; |
| 588 | break; |
| 589 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 590 | data->operation.orientation = 0x3; |
| 591 | data->operation.operation = 0x16; |
| 592 | break; |
| 593 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 594 | data->operation.orientation = 0x1; |
| 595 | data->operation.operation = 0x03; |
| 596 | data->count++; |
| 597 | break; |
| 598 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 599 | data->operation.orientation = 0x3; |
| 600 | data->operation.operation = 0x16; |
| 601 | data->count++; |
| 602 | break; |
| 603 | case DASD_ECKD_CCW_WRITE: |
| 604 | case DASD_ECKD_CCW_WRITE_MT: |
| 605 | case DASD_ECKD_CCW_WRITE_KD: |
| 606 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 607 | data->auxiliary.last_bytes_used = 0x1; |
| 608 | data->length = reclen; |
| 609 | data->operation.operation = 0x01; |
| 610 | break; |
| 611 | case DASD_ECKD_CCW_WRITE_CKD: |
| 612 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 613 | data->auxiliary.last_bytes_used = 0x1; |
| 614 | data->length = reclen; |
| 615 | data->operation.operation = 0x03; |
| 616 | break; |
| 617 | case DASD_ECKD_CCW_READ: |
| 618 | case DASD_ECKD_CCW_READ_MT: |
| 619 | case DASD_ECKD_CCW_READ_KD: |
| 620 | case DASD_ECKD_CCW_READ_KD_MT: |
| 621 | data->auxiliary.last_bytes_used = 0x1; |
| 622 | data->length = reclen; |
| 623 | data->operation.operation = 0x06; |
| 624 | break; |
| 625 | case DASD_ECKD_CCW_READ_CKD: |
| 626 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 627 | data->auxiliary.last_bytes_used = 0x1; |
| 628 | data->length = reclen; |
| 629 | data->operation.operation = 0x16; |
| 630 | break; |
| 631 | case DASD_ECKD_CCW_READ_COUNT: |
| 632 | data->operation.operation = 0x06; |
| 633 | break; |
| 634 | case DASD_ECKD_CCW_ERASE: |
| 635 | data->length = reclen; |
| 636 | data->auxiliary.last_bytes_used = 0x1; |
| 637 | data->operation.operation = 0x0b; |
| 638 | break; |
| 639 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 640 | DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record " |
| 641 | "opcode 0x%x", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 643 | set_ch_t(&data->seek_addr, |
| 644 | trk / private->rdc_data.trk_per_cyl, |
| 645 | trk % private->rdc_data.trk_per_cyl); |
| 646 | data->search_arg.cyl = data->seek_addr.cyl; |
| 647 | data->search_arg.head = data->seek_addr.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | data->search_arg.record = rec_on_trk; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * Returns 1 if the block is one of the special blocks that needs |
| 653 | * to get read/written with the KD variant of the command. |
| 654 | * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and |
| 655 | * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT. |
| 656 | * Luckily the KD variants differ only by one bit (0x08) from the |
| 657 | * normal variant. So don't wonder about code like: |
| 658 | * if (dasd_eckd_cdl_special(blk_per_trk, recid)) |
| 659 | * ccw->cmd_code |= 0x8; |
| 660 | */ |
| 661 | static inline int |
| 662 | dasd_eckd_cdl_special(int blk_per_trk, int recid) |
| 663 | { |
| 664 | if (recid < 3) |
| 665 | return 1; |
| 666 | if (recid < blk_per_trk) |
| 667 | return 0; |
| 668 | if (recid < 2 * blk_per_trk) |
| 669 | return 1; |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * Returns the record size for the special blocks of the cdl format. |
| 675 | * Only returns something useful if dasd_eckd_cdl_special is true |
| 676 | * for the recid. |
| 677 | */ |
| 678 | static inline int |
| 679 | dasd_eckd_cdl_reclen(int recid) |
| 680 | { |
| 681 | if (recid < 3) |
| 682 | return sizes_trk0[recid]; |
| 683 | return LABEL_SIZE; |
| 684 | } |
| 685 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 686 | /* |
| 687 | * Generate device unique id that specifies the physical device. |
| 688 | */ |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 689 | static int dasd_eckd_generate_uid(struct dasd_device *device, |
| 690 | struct dasd_uid *uid) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 691 | { |
| 692 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 693 | int count; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 694 | |
| 695 | private = (struct dasd_eckd_private *) device->private; |
| 696 | if (!private) |
| 697 | return -ENODEV; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 698 | if (!private->ned || !private->gneq) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 699 | return -ENODEV; |
| 700 | |
| 701 | memset(uid, 0, sizeof(struct dasd_uid)); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 702 | memcpy(uid->vendor, private->ned->HDA_manufacturer, |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 703 | sizeof(uid->vendor) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 704 | EBCASC(uid->vendor, sizeof(uid->vendor) - 1); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 705 | memcpy(uid->serial, private->ned->HDA_location, |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 706 | sizeof(uid->serial) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 707 | EBCASC(uid->serial, sizeof(uid->serial) - 1); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 708 | uid->ssid = private->gneq->subsystemID; |
| 709 | uid->real_unit_addr = private->ned->unit_addr;; |
| 710 | if (private->sneq) { |
| 711 | uid->type = private->sneq->sua_flags; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 712 | if (uid->type == UA_BASE_PAV_ALIAS) |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 713 | uid->base_unit_addr = private->sneq->base_unit_addr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 714 | } else { |
| 715 | uid->type = UA_BASE_DEVICE; |
| 716 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 717 | if (private->vdsneq) { |
| 718 | for (count = 0; count < 16; count++) { |
| 719 | sprintf(uid->vduit+2*count, "%02x", |
| 720 | private->vdsneq->uit[count]); |
| 721 | } |
| 722 | } |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 726 | static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device, |
| 727 | void *rcd_buffer, |
| 728 | struct ciw *ciw, __u8 lpm) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 729 | { |
| 730 | struct dasd_ccw_req *cqr; |
| 731 | struct ccw1 *ccw; |
| 732 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 733 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, ciw->count, |
| 734 | device); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 735 | |
| 736 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 737 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 738 | "Could not allocate RCD request"); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 739 | return cqr; |
| 740 | } |
| 741 | |
| 742 | ccw = cqr->cpaddr; |
| 743 | ccw->cmd_code = ciw->cmd; |
| 744 | ccw->cda = (__u32)(addr_t)rcd_buffer; |
| 745 | ccw->count = ciw->count; |
| 746 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 747 | cqr->startdev = device; |
| 748 | cqr->memdev = device; |
| 749 | cqr->block = NULL; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 750 | cqr->expires = 10*HZ; |
| 751 | cqr->lpm = lpm; |
| 752 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 753 | cqr->retries = 2; |
| 754 | cqr->buildclk = get_clock(); |
| 755 | cqr->status = DASD_CQR_FILLED; |
| 756 | return cqr; |
| 757 | } |
| 758 | |
| 759 | static int dasd_eckd_read_conf_lpm(struct dasd_device *device, |
| 760 | void **rcd_buffer, |
| 761 | int *rcd_buffer_size, __u8 lpm) |
| 762 | { |
| 763 | struct ciw *ciw; |
| 764 | char *rcd_buf = NULL; |
| 765 | int ret; |
| 766 | struct dasd_ccw_req *cqr; |
| 767 | |
| 768 | /* |
| 769 | * scan for RCD command in extended SenseID data |
| 770 | */ |
| 771 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); |
| 772 | if (!ciw || ciw->cmd == 0) { |
| 773 | ret = -EOPNOTSUPP; |
| 774 | goto out_error; |
| 775 | } |
| 776 | rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA); |
| 777 | if (!rcd_buf) { |
| 778 | ret = -ENOMEM; |
| 779 | goto out_error; |
| 780 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 781 | |
| 782 | /* |
| 783 | * buffer has to start with EBCDIC "V1.0" to show |
| 784 | * support for virtual device SNEQ |
| 785 | */ |
| 786 | rcd_buf[0] = 0xE5; |
| 787 | rcd_buf[1] = 0xF1; |
| 788 | rcd_buf[2] = 0x4B; |
| 789 | rcd_buf[3] = 0xF0; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 790 | cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm); |
| 791 | if (IS_ERR(cqr)) { |
| 792 | ret = PTR_ERR(cqr); |
| 793 | goto out_error; |
| 794 | } |
| 795 | ret = dasd_sleep_on(cqr); |
| 796 | /* |
| 797 | * on success we update the user input parms |
| 798 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 799 | dasd_sfree_request(cqr, cqr->memdev); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 800 | if (ret) |
| 801 | goto out_error; |
| 802 | |
| 803 | *rcd_buffer_size = ciw->count; |
| 804 | *rcd_buffer = rcd_buf; |
| 805 | return 0; |
| 806 | out_error: |
| 807 | kfree(rcd_buf); |
| 808 | *rcd_buffer = NULL; |
| 809 | *rcd_buffer_size = 0; |
| 810 | return ret; |
| 811 | } |
| 812 | |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 813 | static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private) |
| 814 | { |
| 815 | |
| 816 | struct dasd_sneq *sneq; |
| 817 | int i, count; |
| 818 | |
| 819 | private->ned = NULL; |
| 820 | private->sneq = NULL; |
| 821 | private->vdsneq = NULL; |
| 822 | private->gneq = NULL; |
| 823 | count = private->conf_len / sizeof(struct dasd_sneq); |
| 824 | sneq = (struct dasd_sneq *)private->conf_data; |
| 825 | for (i = 0; i < count; ++i) { |
| 826 | if (sneq->flags.identifier == 1 && sneq->format == 1) |
| 827 | private->sneq = sneq; |
| 828 | else if (sneq->flags.identifier == 1 && sneq->format == 4) |
| 829 | private->vdsneq = (struct vd_sneq *)sneq; |
| 830 | else if (sneq->flags.identifier == 2) |
| 831 | private->gneq = (struct dasd_gneq *)sneq; |
| 832 | else if (sneq->flags.identifier == 3 && sneq->res1 == 1) |
| 833 | private->ned = (struct dasd_ned *)sneq; |
| 834 | sneq++; |
| 835 | } |
| 836 | if (!private->ned || !private->gneq) { |
| 837 | private->ned = NULL; |
| 838 | private->sneq = NULL; |
| 839 | private->vdsneq = NULL; |
| 840 | private->gneq = NULL; |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | return 0; |
| 844 | |
| 845 | }; |
| 846 | |
| 847 | static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len) |
| 848 | { |
| 849 | struct dasd_gneq *gneq; |
| 850 | int i, count, found; |
| 851 | |
| 852 | count = conf_len / sizeof(*gneq); |
| 853 | gneq = (struct dasd_gneq *)conf_data; |
| 854 | found = 0; |
| 855 | for (i = 0; i < count; ++i) { |
| 856 | if (gneq->flags.identifier == 2) { |
| 857 | found = 1; |
| 858 | break; |
| 859 | } |
| 860 | gneq++; |
| 861 | } |
| 862 | if (found) |
| 863 | return ((char *)gneq)[18] & 0x07; |
| 864 | else |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static int dasd_eckd_read_conf(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | void *conf_data; |
| 871 | int conf_len, conf_data_saved; |
| 872 | int rc; |
| 873 | __u8 lpm; |
| 874 | struct dasd_eckd_private *private; |
| 875 | struct dasd_eckd_path *path_data; |
| 876 | |
| 877 | private = (struct dasd_eckd_private *) device->private; |
| 878 | path_data = (struct dasd_eckd_path *) &private->path_data; |
| 879 | path_data->opm = ccw_device_get_path_mask(device->cdev); |
| 880 | lpm = 0x80; |
| 881 | conf_data_saved = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | /* get configuration data per operational path */ |
| 883 | for (lpm = 0x80; lpm; lpm>>= 1) { |
| 884 | if (lpm & path_data->opm){ |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 885 | rc = dasd_eckd_read_conf_lpm(device, &conf_data, |
| 886 | &conf_len, lpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 888 | DBF_EVENT(DBF_WARNING, |
| 889 | "Read configuration data returned " |
| 890 | "error %d for device: %s", rc, |
| 891 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | return rc; |
| 893 | } |
| 894 | if (conf_data == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 895 | DBF_EVENT(DBF_WARNING, "No configuration " |
| 896 | "data retrieved for device: %s", |
| 897 | dev_name(&device->cdev->dev)); |
Gabriel Craciunescu | d133a96 | 2007-07-31 00:39:19 -0700 | [diff] [blame] | 898 | continue; /* no error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | /* save first valid configuration data */ |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 901 | if (!conf_data_saved) { |
| 902 | kfree(private->conf_data); |
| 903 | private->conf_data = conf_data; |
| 904 | private->conf_len = conf_len; |
| 905 | if (dasd_eckd_identify_conf_parts(private)) { |
| 906 | private->conf_data = NULL; |
| 907 | private->conf_len = 0; |
| 908 | kfree(conf_data); |
| 909 | continue; |
| 910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | conf_data_saved++; |
| 912 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 913 | switch (dasd_eckd_path_access(conf_data, conf_len)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | case 0x02: |
| 915 | path_data->npm |= lpm; |
| 916 | break; |
| 917 | case 0x03: |
| 918 | path_data->ppm |= lpm; |
| 919 | break; |
| 920 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 921 | if (conf_data != private->conf_data) |
| 922 | kfree(conf_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | return 0; |
| 926 | } |
| 927 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 928 | static int dasd_eckd_read_features(struct dasd_device *device) |
| 929 | { |
| 930 | struct dasd_psf_prssd_data *prssdp; |
| 931 | struct dasd_rssd_features *features; |
| 932 | struct dasd_ccw_req *cqr; |
| 933 | struct ccw1 *ccw; |
| 934 | int rc; |
| 935 | struct dasd_eckd_private *private; |
| 936 | |
| 937 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 938 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 939 | (sizeof(struct dasd_psf_prssd_data) + |
| 940 | sizeof(struct dasd_rssd_features)), |
| 941 | device); |
| 942 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 943 | DBF_EVENT(DBF_WARNING, "Could not allocate initialization " |
| 944 | "request for device: %s", |
| 945 | dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 946 | return PTR_ERR(cqr); |
| 947 | } |
| 948 | cqr->startdev = device; |
| 949 | cqr->memdev = device; |
| 950 | cqr->block = NULL; |
| 951 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 952 | cqr->retries = 5; |
| 953 | cqr->expires = 10 * HZ; |
| 954 | |
| 955 | /* Prepare for Read Subsystem Data */ |
| 956 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 957 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 958 | prssdp->order = PSF_ORDER_PRSSD; |
| 959 | prssdp->suborder = 0x41; /* Read Feature Codes */ |
| 960 | /* all other bytes of prssdp must be zero */ |
| 961 | |
| 962 | ccw = cqr->cpaddr; |
| 963 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 964 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 965 | ccw->flags |= CCW_FLAG_CC; |
| 966 | ccw->cda = (__u32)(addr_t) prssdp; |
| 967 | |
| 968 | /* Read Subsystem Data - feature codes */ |
| 969 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 970 | memset(features, 0, sizeof(struct dasd_rssd_features)); |
| 971 | |
| 972 | ccw++; |
| 973 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 974 | ccw->count = sizeof(struct dasd_rssd_features); |
| 975 | ccw->cda = (__u32)(addr_t) features; |
| 976 | |
| 977 | cqr->buildclk = get_clock(); |
| 978 | cqr->status = DASD_CQR_FILLED; |
| 979 | rc = dasd_sleep_on(cqr); |
| 980 | if (rc == 0) { |
| 981 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 982 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 983 | memcpy(&private->features, features, |
| 984 | sizeof(struct dasd_rssd_features)); |
| 985 | } |
| 986 | dasd_sfree_request(cqr, cqr->memdev); |
| 987 | return rc; |
| 988 | } |
| 989 | |
| 990 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 991 | /* |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 992 | * Build CP for Perform Subsystem Function - SSC. |
| 993 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 994 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, |
| 995 | int enable_pav) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 996 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 997 | struct dasd_ccw_req *cqr; |
| 998 | struct dasd_psf_ssc_data *psf_ssc_data; |
| 999 | struct ccw1 *ccw; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1000 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1001 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1002 | sizeof(struct dasd_psf_ssc_data), |
| 1003 | device); |
| 1004 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1005 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1006 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1007 | "Could not allocate PSF-SSC request"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1008 | return cqr; |
| 1009 | } |
| 1010 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; |
| 1011 | psf_ssc_data->order = PSF_ORDER_SSC; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1012 | psf_ssc_data->suborder = 0x40; |
| 1013 | if (enable_pav) { |
| 1014 | psf_ssc_data->suborder |= 0x88; |
| 1015 | psf_ssc_data->reserved[0] = 0x88; |
| 1016 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1017 | ccw = cqr->cpaddr; |
| 1018 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 1019 | ccw->cda = (__u32)(addr_t)psf_ssc_data; |
| 1020 | ccw->count = 66; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1021 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1022 | cqr->startdev = device; |
| 1023 | cqr->memdev = device; |
| 1024 | cqr->block = NULL; |
| 1025 | cqr->expires = 10*HZ; |
| 1026 | cqr->buildclk = get_clock(); |
| 1027 | cqr->status = DASD_CQR_FILLED; |
| 1028 | return cqr; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * Perform Subsystem Function. |
| 1033 | * It is necessary to trigger CIO for channel revalidation since this |
| 1034 | * call might change behaviour of DASD devices. |
| 1035 | */ |
| 1036 | static int |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1037 | dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1038 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1039 | struct dasd_ccw_req *cqr; |
| 1040 | int rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1041 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1042 | cqr = dasd_eckd_build_psf_ssc(device, enable_pav); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1043 | if (IS_ERR(cqr)) |
| 1044 | return PTR_ERR(cqr); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1045 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1046 | rc = dasd_sleep_on(cqr); |
| 1047 | if (!rc) |
| 1048 | /* trigger CIO to reprobe devices */ |
| 1049 | css_schedule_reprobe(); |
| 1050 | dasd_sfree_request(cqr, cqr->memdev); |
| 1051 | return rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* |
| 1055 | * Valide storage server of current device. |
| 1056 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1057 | static int dasd_eckd_validate_server(struct dasd_device *device) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1058 | { |
| 1059 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1060 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1061 | int enable_pav; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1062 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1063 | if (dasd_nopav || MACHINE_IS_VM) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1064 | enable_pav = 0; |
| 1065 | else |
| 1066 | enable_pav = 1; |
| 1067 | rc = dasd_eckd_psf_ssc(device, enable_pav); |
Horst Hummel | 8e79a44 | 2006-08-24 13:22:36 +0200 | [diff] [blame] | 1068 | /* may be requested feature is not available on server, |
| 1069 | * therefore just report error and go ahead */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1070 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1071 | DBF_EVENT(DBF_WARNING, "PSF-SSC on storage subsystem %s.%s.%04x " |
| 1072 | "returned rc=%d for device: %s", |
| 1073 | private->uid.vendor, private->uid.serial, |
| 1074 | private->uid.ssid, rc, dev_name(&device->cdev->dev)); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1075 | /* RE-Read Configuration Data */ |
| 1076 | return dasd_eckd_read_conf(device); |
| 1077 | } |
| 1078 | |
| 1079 | /* |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1080 | * Check device characteristics. |
| 1081 | * If the device is accessible using ECKD discipline, the device is enabled. |
| 1082 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | static int |
| 1084 | dasd_eckd_check_characteristics(struct dasd_device *device) |
| 1085 | { |
| 1086 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1087 | struct dasd_block *block; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1088 | int is_known, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | private = (struct dasd_eckd_private *) device->private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1091 | if (!private) { |
| 1092 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); |
| 1093 | if (!private) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1094 | dev_warn(&device->cdev->dev, |
| 1095 | "Allocating memory for private DASD data " |
| 1096 | "failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | return -ENOMEM; |
| 1098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | device->private = (void *) private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1100 | } else { |
| 1101 | memset(private, 0, sizeof(*private)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | /* Invalidate status of initial analysis. */ |
| 1104 | private->init_cqr_status = -1; |
| 1105 | /* Set default cache operations. */ |
| 1106 | private->attrib.operation = DASD_NORMAL_CACHE; |
| 1107 | private->attrib.nr_cyl = 0; |
| 1108 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1109 | /* Read Configuration Data */ |
| 1110 | rc = dasd_eckd_read_conf(device); |
| 1111 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1112 | goto out_err1; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1113 | |
| 1114 | /* Generate device unique id and register in devmap */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1115 | rc = dasd_eckd_generate_uid(device, &private->uid); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1116 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1117 | goto out_err1; |
| 1118 | dasd_set_uid(device->cdev, &private->uid); |
| 1119 | |
| 1120 | if (private->uid.type == UA_BASE_DEVICE) { |
| 1121 | block = dasd_alloc_block(); |
| 1122 | if (IS_ERR(block)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1123 | DBF_EVENT(DBF_WARNING, "could not allocate dasd " |
| 1124 | "block structure for device: %s", |
| 1125 | dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1126 | rc = PTR_ERR(block); |
| 1127 | goto out_err1; |
| 1128 | } |
| 1129 | device->block = block; |
| 1130 | block->base = device; |
| 1131 | } |
| 1132 | |
| 1133 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
| 1134 | is_known = dasd_alias_make_device_known_to_lcu(device); |
| 1135 | if (is_known < 0) { |
| 1136 | rc = is_known; |
| 1137 | goto out_err2; |
| 1138 | } |
| 1139 | if (!is_known) { |
| 1140 | /* new lcu found */ |
| 1141 | rc = dasd_eckd_validate_server(device); /* will switch pav on */ |
| 1142 | if (rc) |
| 1143 | goto out_err3; |
| 1144 | } |
| 1145 | |
| 1146 | /* Read Feature Codes */ |
| 1147 | rc = dasd_eckd_read_features(device); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1148 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1149 | goto out_err3; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1152 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
| 1153 | &private->rdc_data, 64); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1154 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1155 | DBF_EVENT(DBF_WARNING, |
| 1156 | "Read device characteristics failed, rc=%d for " |
| 1157 | "device: %s", rc, dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1158 | goto out_err3; |
| 1159 | } |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1160 | /* find the vaild cylinder size */ |
| 1161 | if (private->rdc_data.no_cyl == LV_COMPAT_CYL && |
| 1162 | private->rdc_data.long_no_cyl) |
| 1163 | private->real_cyl = private->rdc_data.long_no_cyl; |
| 1164 | else |
| 1165 | private->real_cyl = private->rdc_data.no_cyl; |
| 1166 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1167 | dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " |
| 1168 | "with %d cylinders, %d heads, %d sectors\n", |
| 1169 | private->rdc_data.dev_type, |
| 1170 | private->rdc_data.dev_model, |
| 1171 | private->rdc_data.cu_type, |
| 1172 | private->rdc_data.cu_model.model, |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1173 | private->real_cyl, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1174 | private->rdc_data.trk_per_cyl, |
| 1175 | private->rdc_data.sec_per_trk); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1176 | return 0; |
| 1177 | |
| 1178 | out_err3: |
| 1179 | dasd_alias_disconnect_device_from_lcu(device); |
| 1180 | out_err2: |
| 1181 | dasd_free_block(device->block); |
| 1182 | device->block = NULL; |
| 1183 | out_err1: |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1184 | kfree(private->conf_data); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1185 | kfree(device->private); |
| 1186 | device->private = NULL; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1187 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1190 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
| 1191 | { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1192 | struct dasd_eckd_private *private; |
| 1193 | |
| 1194 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1195 | dasd_alias_disconnect_device_from_lcu(device); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1196 | private->ned = NULL; |
| 1197 | private->sneq = NULL; |
| 1198 | private->vdsneq = NULL; |
| 1199 | private->gneq = NULL; |
| 1200 | private->conf_len = 0; |
| 1201 | kfree(private->conf_data); |
| 1202 | private->conf_data = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1203 | } |
| 1204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | static struct dasd_ccw_req * |
| 1206 | dasd_eckd_analysis_ccw(struct dasd_device *device) |
| 1207 | { |
| 1208 | struct dasd_eckd_private *private; |
| 1209 | struct eckd_count *count_data; |
| 1210 | struct LO_eckd_data *LO_data; |
| 1211 | struct dasd_ccw_req *cqr; |
| 1212 | struct ccw1 *ccw; |
| 1213 | int cplength, datasize; |
| 1214 | int i; |
| 1215 | |
| 1216 | private = (struct dasd_eckd_private *) device->private; |
| 1217 | |
| 1218 | cplength = 8; |
| 1219 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1220 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | if (IS_ERR(cqr)) |
| 1222 | return cqr; |
| 1223 | ccw = cqr->cpaddr; |
| 1224 | /* Define extent for the first 3 tracks. */ |
| 1225 | define_extent(ccw++, cqr->data, 0, 2, |
| 1226 | DASD_ECKD_CCW_READ_COUNT, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1227 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | /* Locate record for the first 4 records on track 0. */ |
| 1229 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1230 | locate_record(ccw++, LO_data++, 0, 0, 4, |
| 1231 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1232 | |
| 1233 | count_data = private->count_area; |
| 1234 | for (i = 0; i < 4; i++) { |
| 1235 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1236 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1237 | ccw->flags = 0; |
| 1238 | ccw->count = 8; |
| 1239 | ccw->cda = (__u32)(addr_t) count_data; |
| 1240 | ccw++; |
| 1241 | count_data++; |
| 1242 | } |
| 1243 | |
| 1244 | /* Locate record for the first record on track 2. */ |
| 1245 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1246 | locate_record(ccw++, LO_data++, 2, 0, 1, |
| 1247 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1248 | /* Read count ccw. */ |
| 1249 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1250 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1251 | ccw->flags = 0; |
| 1252 | ccw->count = 8; |
| 1253 | ccw->cda = (__u32)(addr_t) count_data; |
| 1254 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1255 | cqr->block = NULL; |
| 1256 | cqr->startdev = device; |
| 1257 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | cqr->retries = 0; |
| 1259 | cqr->buildclk = get_clock(); |
| 1260 | cqr->status = DASD_CQR_FILLED; |
| 1261 | return cqr; |
| 1262 | } |
| 1263 | |
| 1264 | /* |
| 1265 | * This is the callback function for the init_analysis cqr. It saves |
| 1266 | * the status of the initial analysis ccw before it frees it and kicks |
| 1267 | * the device to continue the startup sequence. This will call |
| 1268 | * dasd_eckd_do_analysis again (if the devices has not been marked |
| 1269 | * for deletion in the meantime). |
| 1270 | */ |
| 1271 | static void |
| 1272 | dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data) |
| 1273 | { |
| 1274 | struct dasd_eckd_private *private; |
| 1275 | struct dasd_device *device; |
| 1276 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1277 | device = init_cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | private = (struct dasd_eckd_private *) device->private; |
| 1279 | private->init_cqr_status = init_cqr->status; |
| 1280 | dasd_sfree_request(init_cqr, device); |
| 1281 | dasd_kick_device(device); |
| 1282 | } |
| 1283 | |
| 1284 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1285 | dasd_eckd_start_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | { |
| 1287 | struct dasd_eckd_private *private; |
| 1288 | struct dasd_ccw_req *init_cqr; |
| 1289 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1290 | private = (struct dasd_eckd_private *) block->base->private; |
| 1291 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | if (IS_ERR(init_cqr)) |
| 1293 | return PTR_ERR(init_cqr); |
| 1294 | init_cqr->callback = dasd_eckd_analysis_callback; |
| 1295 | init_cqr->callback_data = NULL; |
| 1296 | init_cqr->expires = 5*HZ; |
| 1297 | dasd_add_request_head(init_cqr); |
| 1298 | return -EAGAIN; |
| 1299 | } |
| 1300 | |
| 1301 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1302 | dasd_eckd_end_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1304 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | struct dasd_eckd_private *private; |
| 1306 | struct eckd_count *count_area; |
| 1307 | unsigned int sb, blk_per_trk; |
| 1308 | int status, i; |
| 1309 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1310 | device = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | private = (struct dasd_eckd_private *) device->private; |
| 1312 | status = private->init_cqr_status; |
| 1313 | private->init_cqr_status = -1; |
| 1314 | if (status != DASD_CQR_DONE) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1315 | dev_warn(&device->cdev->dev, |
| 1316 | "The DASD is not formatted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | return -EMEDIUMTYPE; |
| 1318 | } |
| 1319 | |
| 1320 | private->uses_cdl = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | /* Check Track 0 for Compatible Disk Layout */ |
| 1322 | count_area = NULL; |
| 1323 | for (i = 0; i < 3; i++) { |
| 1324 | if (private->count_area[i].kl != 4 || |
| 1325 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) { |
| 1326 | private->uses_cdl = 0; |
| 1327 | break; |
| 1328 | } |
| 1329 | } |
| 1330 | if (i == 3) |
| 1331 | count_area = &private->count_area[4]; |
| 1332 | |
| 1333 | if (private->uses_cdl == 0) { |
| 1334 | for (i = 0; i < 5; i++) { |
| 1335 | if ((private->count_area[i].kl != 0) || |
| 1336 | (private->count_area[i].dl != |
| 1337 | private->count_area[0].dl)) |
| 1338 | break; |
| 1339 | } |
| 1340 | if (i == 5) |
| 1341 | count_area = &private->count_area[0]; |
| 1342 | } else { |
| 1343 | if (private->count_area[3].record == 1) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1344 | dev_warn(&device->cdev->dev, |
| 1345 | "Track 0 has no records following the VTOC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | } |
| 1347 | if (count_area != NULL && count_area->kl == 0) { |
| 1348 | /* we found notthing violating our disk layout */ |
| 1349 | if (dasd_check_blocksize(count_area->dl) == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1350 | block->bp_block = count_area->dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1352 | if (block->bp_block == 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1353 | dev_warn(&device->cdev->dev, |
| 1354 | "The disk layout of the DASD is not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | return -EMEDIUMTYPE; |
| 1356 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1357 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 1358 | for (sb = 512; sb < block->bp_block; sb = sb << 1) |
| 1359 | block->s2b_shift++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1361 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1362 | block->blocks = (private->real_cyl * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | private->rdc_data.trk_per_cyl * |
| 1364 | blk_per_trk); |
| 1365 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1366 | dev_info(&device->cdev->dev, |
| 1367 | "DASD with %d KB/block, %d KB total size, %d KB/track, " |
| 1368 | "%s\n", (block->bp_block >> 10), |
| 1369 | ((private->real_cyl * |
| 1370 | private->rdc_data.trk_per_cyl * |
| 1371 | blk_per_trk * (block->bp_block >> 9)) >> 1), |
| 1372 | ((blk_per_trk * block->bp_block) >> 10), |
| 1373 | private->uses_cdl ? |
| 1374 | "compatible disk layout" : "linux disk layout"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1379 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { |
| 1381 | struct dasd_eckd_private *private; |
| 1382 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1383 | private = (struct dasd_eckd_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | if (private->init_cqr_status < 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1385 | return dasd_eckd_start_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1387 | return dasd_eckd_end_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1390 | static int dasd_eckd_ready_to_online(struct dasd_device *device) |
| 1391 | { |
| 1392 | return dasd_alias_add_device(device); |
| 1393 | }; |
| 1394 | |
| 1395 | static int dasd_eckd_online_to_ready(struct dasd_device *device) |
| 1396 | { |
| 1397 | return dasd_alias_remove_device(device); |
| 1398 | }; |
| 1399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1401 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
| 1403 | struct dasd_eckd_private *private; |
| 1404 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1405 | private = (struct dasd_eckd_private *) block->base->private; |
| 1406 | if (dasd_check_blocksize(block->bp_block) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | geo->sectors = recs_per_track(&private->rdc_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1408 | 0, block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | } |
| 1410 | geo->cylinders = private->rdc_data.no_cyl; |
| 1411 | geo->heads = private->rdc_data.trk_per_cyl; |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | static struct dasd_ccw_req * |
| 1416 | dasd_eckd_format_device(struct dasd_device * device, |
| 1417 | struct format_data_t * fdata) |
| 1418 | { |
| 1419 | struct dasd_eckd_private *private; |
| 1420 | struct dasd_ccw_req *fcp; |
| 1421 | struct eckd_count *ect; |
| 1422 | struct ccw1 *ccw; |
| 1423 | void *data; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1424 | int rpt; |
| 1425 | struct ch_t address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | int cplength, datasize; |
| 1427 | int i; |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1428 | int intensity = 0; |
| 1429 | int r0_perm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
| 1431 | private = (struct dasd_eckd_private *) device->private; |
| 1432 | rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1433 | set_ch_t(&address, |
| 1434 | fdata->start_unit / private->rdc_data.trk_per_cyl, |
| 1435 | fdata->start_unit % private->rdc_data.trk_per_cyl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
| 1437 | /* Sanity checks. */ |
| 1438 | if (fdata->start_unit >= |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1439 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1440 | dev_warn(&device->cdev->dev, "Start track number %d used in " |
| 1441 | "formatting is too big\n", fdata->start_unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | return ERR_PTR(-EINVAL); |
| 1443 | } |
| 1444 | if (fdata->start_unit > fdata->stop_unit) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1445 | dev_warn(&device->cdev->dev, "Start track %d used in " |
| 1446 | "formatting exceeds end track\n", fdata->start_unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | return ERR_PTR(-EINVAL); |
| 1448 | } |
| 1449 | if (dasd_check_blocksize(fdata->blksize) != 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1450 | dev_warn(&device->cdev->dev, |
| 1451 | "The DASD cannot be formatted with block size %d\n", |
| 1452 | fdata->blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | return ERR_PTR(-EINVAL); |
| 1454 | } |
| 1455 | |
| 1456 | /* |
| 1457 | * fdata->intensity is a bit string that tells us what to do: |
| 1458 | * Bit 0: write record zero |
| 1459 | * Bit 1: write home address, currently not supported |
| 1460 | * Bit 2: invalidate tracks |
| 1461 | * Bit 3: use OS/390 compatible disk layout (cdl) |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1462 | * Bit 4: do not allow storage subsystem to modify record zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | * Only some bit combinations do make sense. |
| 1464 | */ |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1465 | if (fdata->intensity & 0x10) { |
| 1466 | r0_perm = 0; |
| 1467 | intensity = fdata->intensity & ~0x10; |
| 1468 | } else { |
| 1469 | r0_perm = 1; |
| 1470 | intensity = fdata->intensity; |
| 1471 | } |
| 1472 | switch (intensity) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | case 0x00: /* Normal format */ |
| 1474 | case 0x08: /* Normal format, use cdl. */ |
| 1475 | cplength = 2 + rpt; |
| 1476 | datasize = sizeof(struct DE_eckd_data) + |
| 1477 | sizeof(struct LO_eckd_data) + |
| 1478 | rpt * sizeof(struct eckd_count); |
| 1479 | break; |
| 1480 | case 0x01: /* Write record zero and format track. */ |
| 1481 | case 0x09: /* Write record zero and format track, use cdl. */ |
| 1482 | cplength = 3 + rpt; |
| 1483 | datasize = sizeof(struct DE_eckd_data) + |
| 1484 | sizeof(struct LO_eckd_data) + |
| 1485 | sizeof(struct eckd_count) + |
| 1486 | rpt * sizeof(struct eckd_count); |
| 1487 | break; |
| 1488 | case 0x04: /* Invalidate track. */ |
| 1489 | case 0x0c: /* Invalidate track, use cdl. */ |
| 1490 | cplength = 3; |
| 1491 | datasize = sizeof(struct DE_eckd_data) + |
| 1492 | sizeof(struct LO_eckd_data) + |
| 1493 | sizeof(struct eckd_count); |
| 1494 | break; |
| 1495 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1496 | dev_warn(&device->cdev->dev, "An I/O control call used " |
| 1497 | "incorrect flags 0x%x\n", fdata->intensity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | return ERR_PTR(-EINVAL); |
| 1499 | } |
| 1500 | /* Allocate the format ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1501 | fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | if (IS_ERR(fcp)) |
| 1503 | return fcp; |
| 1504 | |
| 1505 | data = fcp->data; |
| 1506 | ccw = fcp->cpaddr; |
| 1507 | |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1508 | switch (intensity & ~0x08) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | case 0x00: /* Normal format. */ |
| 1510 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1511 | fdata->start_unit, fdata->start_unit, |
| 1512 | DASD_ECKD_CCW_WRITE_CKD, device); |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1513 | /* grant subsystem permission to format R0 */ |
| 1514 | if (r0_perm) |
| 1515 | ((struct DE_eckd_data *)data)->ga_extended |= 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | data += sizeof(struct DE_eckd_data); |
| 1517 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1518 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1519 | fdata->start_unit, 0, rpt, |
| 1520 | DASD_ECKD_CCW_WRITE_CKD, device, |
| 1521 | fdata->blksize); |
| 1522 | data += sizeof(struct LO_eckd_data); |
| 1523 | break; |
| 1524 | case 0x01: /* Write record zero + format track. */ |
| 1525 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1526 | fdata->start_unit, fdata->start_unit, |
| 1527 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, |
| 1528 | device); |
| 1529 | data += sizeof(struct DE_eckd_data); |
| 1530 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1531 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1532 | fdata->start_unit, 0, rpt + 1, |
| 1533 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1534 | device->block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | data += sizeof(struct LO_eckd_data); |
| 1536 | break; |
| 1537 | case 0x04: /* Invalidate track. */ |
| 1538 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1539 | fdata->start_unit, fdata->start_unit, |
| 1540 | DASD_ECKD_CCW_WRITE_CKD, device); |
| 1541 | data += sizeof(struct DE_eckd_data); |
| 1542 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1543 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1544 | fdata->start_unit, 0, 1, |
| 1545 | DASD_ECKD_CCW_WRITE_CKD, device, 8); |
| 1546 | data += sizeof(struct LO_eckd_data); |
| 1547 | break; |
| 1548 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1549 | if (intensity & 0x01) { /* write record zero */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | ect = (struct eckd_count *) data; |
| 1551 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1552 | ect->cyl = address.cyl; |
| 1553 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | ect->record = 0; |
| 1555 | ect->kl = 0; |
| 1556 | ect->dl = 8; |
| 1557 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1558 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; |
| 1559 | ccw->flags = CCW_FLAG_SLI; |
| 1560 | ccw->count = 8; |
| 1561 | ccw->cda = (__u32)(addr_t) ect; |
| 1562 | ccw++; |
| 1563 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1564 | if ((intensity & ~0x08) & 0x04) { /* erase track */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | ect = (struct eckd_count *) data; |
| 1566 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1567 | ect->cyl = address.cyl; |
| 1568 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | ect->record = 1; |
| 1570 | ect->kl = 0; |
| 1571 | ect->dl = 0; |
| 1572 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1573 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1574 | ccw->flags = CCW_FLAG_SLI; |
| 1575 | ccw->count = 8; |
| 1576 | ccw->cda = (__u32)(addr_t) ect; |
| 1577 | } else { /* write remaining records */ |
| 1578 | for (i = 0; i < rpt; i++) { |
| 1579 | ect = (struct eckd_count *) data; |
| 1580 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1581 | ect->cyl = address.cyl; |
| 1582 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | ect->record = i + 1; |
| 1584 | ect->kl = 0; |
| 1585 | ect->dl = fdata->blksize; |
| 1586 | /* Check for special tracks 0-1 when formatting CDL */ |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1587 | if ((intensity & 0x08) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | fdata->start_unit == 0) { |
| 1589 | if (i < 3) { |
| 1590 | ect->kl = 4; |
| 1591 | ect->dl = sizes_trk0[i] - 4; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1592 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1594 | if ((intensity & 0x08) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | fdata->start_unit == 1) { |
| 1596 | ect->kl = 44; |
| 1597 | ect->dl = LABEL_SIZE - 44; |
| 1598 | } |
| 1599 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1600 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1601 | ccw->flags = CCW_FLAG_SLI; |
| 1602 | ccw->count = 8; |
| 1603 | ccw->cda = (__u32)(addr_t) ect; |
| 1604 | ccw++; |
| 1605 | } |
| 1606 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1607 | fcp->startdev = device; |
| 1608 | fcp->memdev = device; |
| 1609 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags); |
| 1610 | fcp->retries = 5; /* set retry counter to enable default ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | fcp->buildclk = get_clock(); |
| 1612 | fcp->status = DASD_CQR_FILLED; |
| 1613 | return fcp; |
| 1614 | } |
| 1615 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1616 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1618 | cqr->status = DASD_CQR_FILLED; |
| 1619 | if (cqr->block && (cqr->startdev != cqr->block->base)) { |
| 1620 | dasd_eckd_reset_ccw_to_base_io(cqr); |
| 1621 | cqr->startdev = cqr->block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1623 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
| 1625 | static dasd_erp_fn_t |
| 1626 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) |
| 1627 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1628 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | struct ccw_device *cdev = device->cdev; |
| 1630 | |
| 1631 | switch (cdev->id.cu_type) { |
| 1632 | case 0x3990: |
| 1633 | case 0x2105: |
| 1634 | case 0x2107: |
| 1635 | case 0x1750: |
| 1636 | return dasd_3990_erp_action; |
| 1637 | case 0x9343: |
| 1638 | case 0x3880: |
| 1639 | default: |
| 1640 | return dasd_default_erp_action; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | static dasd_erp_fn_t |
| 1645 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) |
| 1646 | { |
| 1647 | return dasd_default_erp_postaction; |
| 1648 | } |
| 1649 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1650 | |
| 1651 | static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device, |
| 1652 | struct irb *irb) |
| 1653 | { |
| 1654 | char mask; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1655 | char *sense = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1656 | |
| 1657 | /* first of all check for state change pending interrupt */ |
| 1658 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1659 | if ((scsw_dstat(&irb->scsw) & mask) == mask) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1660 | dasd_generic_handle_state_change(device); |
| 1661 | return; |
| 1662 | } |
| 1663 | |
| 1664 | /* summary unit check */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1665 | if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1666 | (irb->ecw[7] == 0x0D)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1667 | dasd_alias_handle_summary_unit_check(device, irb); |
| 1668 | return; |
| 1669 | } |
| 1670 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1671 | sense = dasd_get_sense(irb); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1672 | /* service information message SIM */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1673 | if (sense && !(sense[27] & DASD_SENSE_BIT_0) && |
| 1674 | ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
| 1675 | dasd_3990_erp_handle_sim(device, sense); |
Stefan Haberland | 9d853ca | 2008-07-17 17:16:41 +0200 | [diff] [blame] | 1676 | dasd_schedule_device_bh(device); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1677 | return; |
| 1678 | } |
| 1679 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1680 | if ((scsw_cc(&irb->scsw) == 1) && |
| 1681 | (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) && |
| 1682 | (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) && |
| 1683 | (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) { |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1684 | /* fake irb do nothing, they are handled elsewhere */ |
| 1685 | dasd_schedule_device_bh(device); |
| 1686 | return; |
| 1687 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1688 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1689 | if (!sense) { |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1690 | /* just report other unsolicited interrupts */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1691 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1692 | "unsolicited interrupt received"); |
| 1693 | } else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1694 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1695 | "unsolicited interrupt received " |
| 1696 | "(sense available)"); |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 1697 | device->discipline->dump_sense_dbf(device, irb, "unsolicited"); |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | dasd_schedule_device_bh(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1701 | return; |
| 1702 | }; |
| 1703 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1704 | |
| 1705 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( |
| 1706 | struct dasd_device *startdev, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1707 | struct dasd_block *block, |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1708 | struct request *req, |
| 1709 | sector_t first_rec, |
| 1710 | sector_t last_rec, |
| 1711 | sector_t first_trk, |
| 1712 | sector_t last_trk, |
| 1713 | unsigned int first_offs, |
| 1714 | unsigned int last_offs, |
| 1715 | unsigned int blk_per_trk, |
| 1716 | unsigned int blksize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | { |
| 1718 | struct dasd_eckd_private *private; |
| 1719 | unsigned long *idaws; |
| 1720 | struct LO_eckd_data *LO_data; |
| 1721 | struct dasd_ccw_req *cqr; |
| 1722 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1723 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | struct bio_vec *bv; |
| 1725 | char *dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1726 | unsigned int off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | int count, cidaw, cplength, datasize; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1728 | sector_t recid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | unsigned char cmd, rcmd; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1730 | int use_prefix; |
| 1731 | struct dasd_device *basedev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1733 | basedev = block->base; |
| 1734 | private = (struct dasd_eckd_private *) basedev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | if (rq_data_dir(req) == READ) |
| 1736 | cmd = DASD_ECKD_CCW_READ_MT; |
| 1737 | else if (rq_data_dir(req) == WRITE) |
| 1738 | cmd = DASD_ECKD_CCW_WRITE_MT; |
| 1739 | else |
| 1740 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | /* Check struct bio and count the number of blocks for the request. */ |
| 1743 | count = 0; |
| 1744 | cidaw = 0; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1745 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1746 | if (bv->bv_len & (blksize - 1)) |
| 1747 | /* Eckd can only do full blocks. */ |
| 1748 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1749 | count += bv->bv_len >> (block->s2b_shift + 9); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 1750 | #if defined(CONFIG_64BIT) |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1751 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1752 | cidaw += bv->bv_len >> (block->s2b_shift + 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | /* Paranoia. */ |
| 1756 | if (count != last_rec - first_rec + 1) |
| 1757 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1758 | |
| 1759 | /* use the prefix command if available */ |
| 1760 | use_prefix = private->features.feature[8] & 0x01; |
| 1761 | if (use_prefix) { |
| 1762 | /* 1x prefix + number of blocks */ |
| 1763 | cplength = 2 + count; |
| 1764 | /* 1x prefix + cidaws*sizeof(long) */ |
| 1765 | datasize = sizeof(struct PFX_eckd_data) + |
| 1766 | sizeof(struct LO_eckd_data) + |
| 1767 | cidaw * sizeof(unsigned long); |
| 1768 | } else { |
| 1769 | /* 1x define extent + 1x locate record + number of blocks */ |
| 1770 | cplength = 2 + count; |
| 1771 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ |
| 1772 | datasize = sizeof(struct DE_eckd_data) + |
| 1773 | sizeof(struct LO_eckd_data) + |
| 1774 | cidaw * sizeof(unsigned long); |
| 1775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | /* Find out the number of additional locate record ccws for cdl. */ |
| 1777 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { |
| 1778 | if (last_rec >= 2*blk_per_trk) |
| 1779 | count = 2*blk_per_trk - first_rec; |
| 1780 | cplength += count; |
| 1781 | datasize += count*sizeof(struct LO_eckd_data); |
| 1782 | } |
| 1783 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1784 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 1785 | startdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | if (IS_ERR(cqr)) |
| 1787 | return cqr; |
| 1788 | ccw = cqr->cpaddr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1789 | /* First ccw is define extent or prefix. */ |
| 1790 | if (use_prefix) { |
| 1791 | if (prefix(ccw++, cqr->data, first_trk, |
| 1792 | last_trk, cmd, basedev, startdev) == -EAGAIN) { |
| 1793 | /* Clock not in sync and XRC is enabled. |
| 1794 | * Try again later. |
| 1795 | */ |
| 1796 | dasd_sfree_request(cqr, startdev); |
| 1797 | return ERR_PTR(-EAGAIN); |
| 1798 | } |
| 1799 | idaws = (unsigned long *) (cqr->data + |
| 1800 | sizeof(struct PFX_eckd_data)); |
| 1801 | } else { |
| 1802 | if (define_extent(ccw++, cqr->data, first_trk, |
| 1803 | last_trk, cmd, startdev) == -EAGAIN) { |
| 1804 | /* Clock not in sync and XRC is enabled. |
| 1805 | * Try again later. |
| 1806 | */ |
| 1807 | dasd_sfree_request(cqr, startdev); |
| 1808 | return ERR_PTR(-EAGAIN); |
| 1809 | } |
| 1810 | idaws = (unsigned long *) (cqr->data + |
| 1811 | sizeof(struct DE_eckd_data)); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 1812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | /* Build locate_record+read/write/ccws. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
| 1815 | recid = first_rec; |
| 1816 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { |
| 1817 | /* Only standard blocks so there is just one locate record. */ |
| 1818 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1819 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1820 | last_rec - recid + 1, cmd, basedev, blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1822 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1824 | if (dasd_page_cache) { |
| 1825 | char *copy = kmem_cache_alloc(dasd_page_cache, |
Christoph Lameter | 441e143 | 2006-12-06 20:33:19 -0800 | [diff] [blame] | 1826 | GFP_DMA | __GFP_NOWARN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | if (copy && rq_data_dir(req) == WRITE) |
| 1828 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); |
| 1829 | if (copy) |
| 1830 | dst = copy + bv->bv_offset; |
| 1831 | } |
| 1832 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 1833 | sector_t trkid = recid; |
| 1834 | unsigned int recoffs = sector_div(trkid, blk_per_trk); |
| 1835 | rcmd = cmd; |
| 1836 | count = blksize; |
| 1837 | /* Locate record for cdl special block ? */ |
| 1838 | if (private->uses_cdl && recid < 2*blk_per_trk) { |
| 1839 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ |
| 1840 | rcmd |= 0x8; |
| 1841 | count = dasd_eckd_cdl_reclen(recid); |
Horst Hummel | ec5883a | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1842 | if (count < blksize && |
| 1843 | rq_data_dir(req) == READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | memset(dst + count, 0xe5, |
| 1845 | blksize - count); |
| 1846 | } |
| 1847 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1848 | locate_record(ccw++, LO_data++, |
| 1849 | trkid, recoffs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1850 | 1, rcmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | } |
| 1852 | /* Locate record for standard blocks ? */ |
| 1853 | if (private->uses_cdl && recid == 2*blk_per_trk) { |
| 1854 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1855 | locate_record(ccw++, LO_data++, |
| 1856 | trkid, recoffs + 1, |
| 1857 | last_rec - recid + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1858 | cmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | } |
| 1860 | /* Read/write ccw. */ |
| 1861 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1862 | ccw->cmd_code = rcmd; |
| 1863 | ccw->count = count; |
| 1864 | if (idal_is_needed(dst, blksize)) { |
| 1865 | ccw->cda = (__u32)(addr_t) idaws; |
| 1866 | ccw->flags = CCW_FLAG_IDA; |
| 1867 | idaws = idal_create_words(idaws, dst, blksize); |
| 1868 | } else { |
| 1869 | ccw->cda = (__u32)(addr_t) dst; |
| 1870 | ccw->flags = 0; |
| 1871 | } |
| 1872 | ccw++; |
| 1873 | dst += blksize; |
| 1874 | recid++; |
| 1875 | } |
| 1876 | } |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 1877 | if (blk_noretry_request(req) || |
| 1878 | block->base->features & DASD_FEATURE_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1879 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1880 | cqr->startdev = startdev; |
| 1881 | cqr->memdev = startdev; |
| 1882 | cqr->block = block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 1884 | cqr->lpm = private->path_data.ppm; |
| 1885 | cqr->retries = 256; |
| 1886 | cqr->buildclk = get_clock(); |
| 1887 | cqr->status = DASD_CQR_FILLED; |
| 1888 | return cqr; |
| 1889 | } |
| 1890 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1891 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( |
| 1892 | struct dasd_device *startdev, |
| 1893 | struct dasd_block *block, |
| 1894 | struct request *req, |
| 1895 | sector_t first_rec, |
| 1896 | sector_t last_rec, |
| 1897 | sector_t first_trk, |
| 1898 | sector_t last_trk, |
| 1899 | unsigned int first_offs, |
| 1900 | unsigned int last_offs, |
| 1901 | unsigned int blk_per_trk, |
| 1902 | unsigned int blksize) |
| 1903 | { |
| 1904 | struct dasd_eckd_private *private; |
| 1905 | unsigned long *idaws; |
| 1906 | struct dasd_ccw_req *cqr; |
| 1907 | struct ccw1 *ccw; |
| 1908 | struct req_iterator iter; |
| 1909 | struct bio_vec *bv; |
| 1910 | char *dst, *idaw_dst; |
| 1911 | unsigned int cidaw, cplength, datasize; |
| 1912 | unsigned int tlf; |
| 1913 | sector_t recid; |
| 1914 | unsigned char cmd; |
| 1915 | struct dasd_device *basedev; |
| 1916 | unsigned int trkcount, count, count_to_trk_end; |
| 1917 | unsigned int idaw_len, seg_len, part_len, len_to_track_end; |
| 1918 | unsigned char new_track, end_idaw; |
| 1919 | sector_t trkid; |
| 1920 | unsigned int recoffs; |
| 1921 | |
| 1922 | basedev = block->base; |
| 1923 | private = (struct dasd_eckd_private *) basedev->private; |
| 1924 | if (rq_data_dir(req) == READ) |
| 1925 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 1926 | else if (rq_data_dir(req) == WRITE) |
| 1927 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 1928 | else |
| 1929 | return ERR_PTR(-EINVAL); |
| 1930 | |
| 1931 | /* Track based I/O needs IDAWs for each page, and not just for |
| 1932 | * 64 bit addresses. We need additional idals for pages |
| 1933 | * that get filled from two tracks, so we use the number |
| 1934 | * of records as upper limit. |
| 1935 | */ |
| 1936 | cidaw = last_rec - first_rec + 1; |
| 1937 | trkcount = last_trk - first_trk + 1; |
| 1938 | |
| 1939 | /* 1x prefix + one read/write ccw per track */ |
| 1940 | cplength = 1 + trkcount; |
| 1941 | |
| 1942 | /* on 31-bit we need space for two 32 bit addresses per page |
| 1943 | * on 64-bit one 64 bit address |
| 1944 | */ |
| 1945 | datasize = sizeof(struct PFX_eckd_data) + |
| 1946 | cidaw * sizeof(unsigned long long); |
| 1947 | |
| 1948 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1949 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 1950 | startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1951 | if (IS_ERR(cqr)) |
| 1952 | return cqr; |
| 1953 | ccw = cqr->cpaddr; |
| 1954 | /* transfer length factor: how many bytes to read from the last track */ |
| 1955 | if (first_trk == last_trk) |
| 1956 | tlf = last_offs - first_offs + 1; |
| 1957 | else |
| 1958 | tlf = last_offs + 1; |
| 1959 | tlf *= blksize; |
| 1960 | |
| 1961 | if (prefix_LRE(ccw++, cqr->data, first_trk, |
| 1962 | last_trk, cmd, basedev, startdev, |
| 1963 | 1 /* format */, first_offs + 1, |
| 1964 | trkcount, blksize, |
| 1965 | tlf) == -EAGAIN) { |
| 1966 | /* Clock not in sync and XRC is enabled. |
| 1967 | * Try again later. |
| 1968 | */ |
| 1969 | dasd_sfree_request(cqr, startdev); |
| 1970 | return ERR_PTR(-EAGAIN); |
| 1971 | } |
| 1972 | |
| 1973 | /* |
| 1974 | * The translation of request into ccw programs must meet the |
| 1975 | * following conditions: |
| 1976 | * - all idaws but the first and the last must address full pages |
| 1977 | * (or 2K blocks on 31-bit) |
| 1978 | * - the scope of a ccw and it's idal ends with the track boundaries |
| 1979 | */ |
| 1980 | idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); |
| 1981 | recid = first_rec; |
| 1982 | new_track = 1; |
| 1983 | end_idaw = 0; |
| 1984 | len_to_track_end = 0; |
| 1985 | idaw_dst = 0; |
| 1986 | idaw_len = 0; |
| 1987 | rq_for_each_segment(bv, req, iter) { |
| 1988 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1989 | seg_len = bv->bv_len; |
| 1990 | while (seg_len) { |
| 1991 | if (new_track) { |
| 1992 | trkid = recid; |
| 1993 | recoffs = sector_div(trkid, blk_per_trk); |
| 1994 | count_to_trk_end = blk_per_trk - recoffs; |
| 1995 | count = min((last_rec - recid + 1), |
| 1996 | (sector_t)count_to_trk_end); |
| 1997 | len_to_track_end = count * blksize; |
| 1998 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1999 | ccw->cmd_code = cmd; |
| 2000 | ccw->count = len_to_track_end; |
| 2001 | ccw->cda = (__u32)(addr_t)idaws; |
| 2002 | ccw->flags = CCW_FLAG_IDA; |
| 2003 | ccw++; |
| 2004 | recid += count; |
| 2005 | new_track = 0; |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2006 | /* first idaw for a ccw may start anywhere */ |
| 2007 | if (!idaw_dst) |
| 2008 | idaw_dst = dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2009 | } |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2010 | /* If we start a new idaw, we must make sure that it |
| 2011 | * starts on an IDA_BLOCK_SIZE boundary. |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2012 | * If we continue an idaw, we must make sure that the |
| 2013 | * current segment begins where the so far accumulated |
| 2014 | * idaw ends |
| 2015 | */ |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2016 | if (!idaw_dst) { |
| 2017 | if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { |
| 2018 | dasd_sfree_request(cqr, startdev); |
| 2019 | return ERR_PTR(-ERANGE); |
| 2020 | } else |
| 2021 | idaw_dst = dst; |
| 2022 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2023 | if ((idaw_dst + idaw_len) != dst) { |
| 2024 | dasd_sfree_request(cqr, startdev); |
| 2025 | return ERR_PTR(-ERANGE); |
| 2026 | } |
| 2027 | part_len = min(seg_len, len_to_track_end); |
| 2028 | seg_len -= part_len; |
| 2029 | dst += part_len; |
| 2030 | idaw_len += part_len; |
| 2031 | len_to_track_end -= part_len; |
| 2032 | /* collected memory area ends on an IDA_BLOCK border, |
| 2033 | * -> create an idaw |
| 2034 | * idal_create_words will handle cases where idaw_len |
| 2035 | * is larger then IDA_BLOCK_SIZE |
| 2036 | */ |
| 2037 | if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) |
| 2038 | end_idaw = 1; |
| 2039 | /* We also need to end the idaw at track end */ |
| 2040 | if (!len_to_track_end) { |
| 2041 | new_track = 1; |
| 2042 | end_idaw = 1; |
| 2043 | } |
| 2044 | if (end_idaw) { |
| 2045 | idaws = idal_create_words(idaws, idaw_dst, |
| 2046 | idaw_len); |
| 2047 | idaw_dst = 0; |
| 2048 | idaw_len = 0; |
| 2049 | end_idaw = 0; |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | if (blk_noretry_request(req) || |
| 2055 | block->base->features & DASD_FEATURE_FAILFAST) |
| 2056 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 2057 | cqr->startdev = startdev; |
| 2058 | cqr->memdev = startdev; |
| 2059 | cqr->block = block; |
| 2060 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 2061 | cqr->lpm = private->path_data.ppm; |
| 2062 | cqr->retries = 256; |
| 2063 | cqr->buildclk = get_clock(); |
| 2064 | cqr->status = DASD_CQR_FILLED; |
| 2065 | return cqr; |
| 2066 | } |
| 2067 | |
| 2068 | static int prepare_itcw(struct itcw *itcw, |
| 2069 | unsigned int trk, unsigned int totrk, int cmd, |
| 2070 | struct dasd_device *basedev, |
| 2071 | struct dasd_device *startdev, |
| 2072 | unsigned int rec_on_trk, int count, |
| 2073 | unsigned int blksize, |
| 2074 | unsigned int total_data_size, |
| 2075 | unsigned int tlf, |
| 2076 | unsigned int blk_per_trk) |
| 2077 | { |
| 2078 | struct PFX_eckd_data pfxdata; |
| 2079 | struct dasd_eckd_private *basepriv, *startpriv; |
| 2080 | struct DE_eckd_data *dedata; |
| 2081 | struct LRE_eckd_data *lredata; |
| 2082 | struct dcw *dcw; |
| 2083 | |
| 2084 | u32 begcyl, endcyl; |
| 2085 | u16 heads, beghead, endhead; |
| 2086 | u8 pfx_cmd; |
| 2087 | |
| 2088 | int rc = 0; |
| 2089 | int sector = 0; |
| 2090 | int dn, d; |
| 2091 | |
| 2092 | |
| 2093 | /* setup prefix data */ |
| 2094 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 2095 | startpriv = (struct dasd_eckd_private *) startdev->private; |
| 2096 | dedata = &pfxdata.define_extent; |
| 2097 | lredata = &pfxdata.locate_record; |
| 2098 | |
| 2099 | memset(&pfxdata, 0, sizeof(pfxdata)); |
| 2100 | pfxdata.format = 1; /* PFX with LRE */ |
| 2101 | pfxdata.base_address = basepriv->ned->unit_addr; |
| 2102 | pfxdata.base_lss = basepriv->ned->ID; |
| 2103 | pfxdata.validity.define_extent = 1; |
| 2104 | |
| 2105 | /* private uid is kept up to date, conf_data may be outdated */ |
| 2106 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 2107 | pfxdata.validity.verify_base = 1; |
| 2108 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 2109 | pfxdata.validity.hyper_pav = 1; |
| 2110 | } |
| 2111 | |
| 2112 | switch (cmd) { |
| 2113 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 2114 | dedata->mask.perm = 0x1; |
| 2115 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2116 | dedata->blk_size = blksize; |
| 2117 | dedata->ga_extended |= 0x42; |
| 2118 | lredata->operation.orientation = 0x0; |
| 2119 | lredata->operation.operation = 0x0C; |
| 2120 | lredata->auxiliary.check_bytes = 0x01; |
| 2121 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; |
| 2122 | break; |
| 2123 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 2124 | dedata->mask.perm = 0x02; |
| 2125 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2126 | dedata->blk_size = blksize; |
| 2127 | rc = check_XRC_on_prefix(&pfxdata, basedev); |
| 2128 | dedata->ga_extended |= 0x42; |
| 2129 | lredata->operation.orientation = 0x0; |
| 2130 | lredata->operation.operation = 0x3F; |
| 2131 | lredata->extended_operation = 0x23; |
| 2132 | lredata->auxiliary.check_bytes = 0x2; |
| 2133 | pfx_cmd = DASD_ECKD_CCW_PFX; |
| 2134 | break; |
| 2135 | default: |
| 2136 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 2137 | "prepare itcw, unknown opcode 0x%x", cmd); |
| 2138 | BUG(); |
| 2139 | break; |
| 2140 | } |
| 2141 | if (rc) |
| 2142 | return rc; |
| 2143 | |
| 2144 | dedata->attributes.mode = 0x3; /* ECKD */ |
| 2145 | |
| 2146 | heads = basepriv->rdc_data.trk_per_cyl; |
| 2147 | begcyl = trk / heads; |
| 2148 | beghead = trk % heads; |
| 2149 | endcyl = totrk / heads; |
| 2150 | endhead = totrk % heads; |
| 2151 | |
| 2152 | /* check for sequential prestage - enhance cylinder range */ |
| 2153 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
| 2154 | dedata->attributes.operation == DASD_SEQ_ACCESS) { |
| 2155 | |
| 2156 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
| 2157 | endcyl += basepriv->attrib.nr_cyl; |
| 2158 | else |
| 2159 | endcyl = (basepriv->real_cyl - 1); |
| 2160 | } |
| 2161 | |
| 2162 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
| 2163 | set_ch_t(&dedata->end_ext, endcyl, endhead); |
| 2164 | |
| 2165 | dedata->ep_format = 0x20; /* records per track is valid */ |
| 2166 | dedata->ep_rec_per_track = blk_per_trk; |
| 2167 | |
| 2168 | if (rec_on_trk) { |
| 2169 | switch (basepriv->rdc_data.dev_type) { |
| 2170 | case 0x3390: |
| 2171 | dn = ceil_quot(blksize + 6, 232); |
| 2172 | d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); |
| 2173 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 2174 | break; |
| 2175 | case 0x3380: |
| 2176 | d = 7 + ceil_quot(blksize + 12, 32); |
| 2177 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 2178 | break; |
| 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | lredata->auxiliary.length_valid = 1; |
| 2183 | lredata->auxiliary.length_scope = 1; |
| 2184 | lredata->auxiliary.imbedded_ccw_valid = 1; |
| 2185 | lredata->length = tlf; |
| 2186 | lredata->imbedded_ccw = cmd; |
| 2187 | lredata->count = count; |
| 2188 | lredata->sector = sector; |
| 2189 | set_ch_t(&lredata->seek_addr, begcyl, beghead); |
| 2190 | lredata->search_arg.cyl = lredata->seek_addr.cyl; |
| 2191 | lredata->search_arg.head = lredata->seek_addr.head; |
| 2192 | lredata->search_arg.record = rec_on_trk; |
| 2193 | |
| 2194 | dcw = itcw_add_dcw(itcw, pfx_cmd, 0, |
| 2195 | &pfxdata, sizeof(pfxdata), total_data_size); |
| 2196 | |
| 2197 | return rc; |
| 2198 | } |
| 2199 | |
| 2200 | static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( |
| 2201 | struct dasd_device *startdev, |
| 2202 | struct dasd_block *block, |
| 2203 | struct request *req, |
| 2204 | sector_t first_rec, |
| 2205 | sector_t last_rec, |
| 2206 | sector_t first_trk, |
| 2207 | sector_t last_trk, |
| 2208 | unsigned int first_offs, |
| 2209 | unsigned int last_offs, |
| 2210 | unsigned int blk_per_trk, |
| 2211 | unsigned int blksize) |
| 2212 | { |
| 2213 | struct dasd_eckd_private *private; |
| 2214 | struct dasd_ccw_req *cqr; |
| 2215 | struct req_iterator iter; |
| 2216 | struct bio_vec *bv; |
| 2217 | char *dst; |
| 2218 | unsigned int trkcount, ctidaw; |
| 2219 | unsigned char cmd; |
| 2220 | struct dasd_device *basedev; |
| 2221 | unsigned int tlf; |
| 2222 | struct itcw *itcw; |
| 2223 | struct tidaw *last_tidaw = NULL; |
| 2224 | int itcw_op; |
| 2225 | size_t itcw_size; |
| 2226 | |
| 2227 | basedev = block->base; |
| 2228 | private = (struct dasd_eckd_private *) basedev->private; |
| 2229 | if (rq_data_dir(req) == READ) { |
| 2230 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 2231 | itcw_op = ITCW_OP_READ; |
| 2232 | } else if (rq_data_dir(req) == WRITE) { |
| 2233 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 2234 | itcw_op = ITCW_OP_WRITE; |
| 2235 | } else |
| 2236 | return ERR_PTR(-EINVAL); |
| 2237 | |
| 2238 | /* trackbased I/O needs address all memory via TIDAWs, |
| 2239 | * not just for 64 bit addresses. This allows us to map |
| 2240 | * each segment directly to one tidaw. |
| 2241 | */ |
| 2242 | trkcount = last_trk - first_trk + 1; |
| 2243 | ctidaw = 0; |
| 2244 | rq_for_each_segment(bv, req, iter) { |
| 2245 | ++ctidaw; |
| 2246 | } |
| 2247 | |
| 2248 | /* Allocate the ccw request. */ |
| 2249 | itcw_size = itcw_calc_size(0, ctidaw, 0); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2250 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2251 | if (IS_ERR(cqr)) |
| 2252 | return cqr; |
| 2253 | |
| 2254 | cqr->cpmode = 1; |
| 2255 | cqr->startdev = startdev; |
| 2256 | cqr->memdev = startdev; |
| 2257 | cqr->block = block; |
| 2258 | cqr->expires = 100*HZ; |
| 2259 | cqr->buildclk = get_clock(); |
| 2260 | cqr->status = DASD_CQR_FILLED; |
| 2261 | cqr->retries = 10; |
| 2262 | |
| 2263 | /* transfer length factor: how many bytes to read from the last track */ |
| 2264 | if (first_trk == last_trk) |
| 2265 | tlf = last_offs - first_offs + 1; |
| 2266 | else |
| 2267 | tlf = last_offs + 1; |
| 2268 | tlf *= blksize; |
| 2269 | |
| 2270 | itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); |
| 2271 | cqr->cpaddr = itcw_get_tcw(itcw); |
| 2272 | |
| 2273 | if (prepare_itcw(itcw, first_trk, last_trk, |
| 2274 | cmd, basedev, startdev, |
| 2275 | first_offs + 1, |
| 2276 | trkcount, blksize, |
| 2277 | (last_rec - first_rec + 1) * blksize, |
| 2278 | tlf, blk_per_trk) == -EAGAIN) { |
| 2279 | /* Clock not in sync and XRC is enabled. |
| 2280 | * Try again later. |
| 2281 | */ |
| 2282 | dasd_sfree_request(cqr, startdev); |
| 2283 | return ERR_PTR(-EAGAIN); |
| 2284 | } |
| 2285 | |
| 2286 | /* |
| 2287 | * A tidaw can address 4k of memory, but must not cross page boundaries |
| 2288 | * We can let the block layer handle this by setting |
| 2289 | * blk_queue_segment_boundary to page boundaries and |
| 2290 | * blk_max_segment_size to page size when setting up the request queue. |
| 2291 | */ |
| 2292 | rq_for_each_segment(bv, req, iter) { |
| 2293 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2294 | last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len); |
| 2295 | if (IS_ERR(last_tidaw)) |
| 2296 | return (struct dasd_ccw_req *)last_tidaw; |
| 2297 | } |
| 2298 | |
| 2299 | last_tidaw->flags |= 0x80; |
| 2300 | itcw_finalize(itcw); |
| 2301 | |
| 2302 | if (blk_noretry_request(req) || |
| 2303 | block->base->features & DASD_FEATURE_FAILFAST) |
| 2304 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 2305 | cqr->startdev = startdev; |
| 2306 | cqr->memdev = startdev; |
| 2307 | cqr->block = block; |
| 2308 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 2309 | cqr->lpm = private->path_data.ppm; |
| 2310 | cqr->retries = 256; |
| 2311 | cqr->buildclk = get_clock(); |
| 2312 | cqr->status = DASD_CQR_FILLED; |
| 2313 | return cqr; |
| 2314 | } |
| 2315 | |
| 2316 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, |
| 2317 | struct dasd_block *block, |
| 2318 | struct request *req) |
| 2319 | { |
| 2320 | int tpm, cmdrtd, cmdwtd; |
| 2321 | int use_prefix; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2322 | #if defined(CONFIG_64BIT) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2323 | int fcx_in_css, fcx_in_gneq, fcx_in_features; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2324 | #endif |
| 2325 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2326 | struct dasd_device *basedev; |
| 2327 | sector_t first_rec, last_rec; |
| 2328 | sector_t first_trk, last_trk; |
| 2329 | unsigned int first_offs, last_offs; |
| 2330 | unsigned int blk_per_trk, blksize; |
| 2331 | int cdlspecial; |
| 2332 | struct dasd_ccw_req *cqr; |
| 2333 | |
| 2334 | basedev = block->base; |
| 2335 | private = (struct dasd_eckd_private *) basedev->private; |
| 2336 | |
| 2337 | /* Calculate number of blocks/records per track. */ |
| 2338 | blksize = block->bp_block; |
| 2339 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
| 2340 | /* Calculate record id of first and last block. */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2341 | first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2342 | first_offs = sector_div(first_trk, blk_per_trk); |
| 2343 | last_rec = last_trk = |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2344 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2345 | last_offs = sector_div(last_trk, blk_per_trk); |
| 2346 | cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); |
| 2347 | |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2348 | /* is transport mode supported? */ |
| 2349 | #if defined(CONFIG_64BIT) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2350 | fcx_in_css = css_general_characteristics.fcx; |
| 2351 | fcx_in_gneq = private->gneq->reserved2[7] & 0x04; |
| 2352 | fcx_in_features = private->features.feature[40] & 0x80; |
| 2353 | tpm = fcx_in_css && fcx_in_gneq && fcx_in_features; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2354 | #else |
| 2355 | tpm = 0; |
| 2356 | #endif |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2357 | |
| 2358 | /* is read track data and write track data in command mode supported? */ |
| 2359 | cmdrtd = private->features.feature[9] & 0x20; |
| 2360 | cmdwtd = private->features.feature[12] & 0x40; |
| 2361 | use_prefix = private->features.feature[8] & 0x01; |
| 2362 | |
| 2363 | cqr = NULL; |
| 2364 | if (cdlspecial || dasd_page_cache) { |
| 2365 | /* do nothing, just fall through to the cmd mode single case */ |
| 2366 | } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) { |
| 2367 | cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, |
| 2368 | first_rec, last_rec, |
| 2369 | first_trk, last_trk, |
| 2370 | first_offs, last_offs, |
| 2371 | blk_per_trk, blksize); |
| 2372 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) |
| 2373 | cqr = NULL; |
| 2374 | } else if (use_prefix && |
| 2375 | (((rq_data_dir(req) == READ) && cmdrtd) || |
| 2376 | ((rq_data_dir(req) == WRITE) && cmdwtd))) { |
| 2377 | cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, |
| 2378 | first_rec, last_rec, |
| 2379 | first_trk, last_trk, |
| 2380 | first_offs, last_offs, |
| 2381 | blk_per_trk, blksize); |
| 2382 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) |
| 2383 | cqr = NULL; |
| 2384 | } |
| 2385 | if (!cqr) |
| 2386 | cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, |
| 2387 | first_rec, last_rec, |
| 2388 | first_trk, last_trk, |
| 2389 | first_offs, last_offs, |
| 2390 | blk_per_trk, blksize); |
| 2391 | return cqr; |
| 2392 | } |
| 2393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | static int |
| 2395 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 2396 | { |
| 2397 | struct dasd_eckd_private *private; |
| 2398 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2399 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | struct bio_vec *bv; |
| 2401 | char *dst, *cda; |
| 2402 | unsigned int blksize, blk_per_trk, off; |
| 2403 | sector_t recid; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2404 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | |
| 2406 | if (!dasd_page_cache) |
| 2407 | goto out; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2408 | private = (struct dasd_eckd_private *) cqr->block->base->private; |
| 2409 | blksize = cqr->block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2411 | recid = blk_rq_pos(req) >> cqr->block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | ccw = cqr->cpaddr; |
| 2413 | /* Skip over define extent & locate record. */ |
| 2414 | ccw++; |
| 2415 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) |
| 2416 | ccw++; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2417 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2419 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 2420 | /* Skip locate record. */ |
| 2421 | if (private->uses_cdl && recid <= 2*blk_per_trk) |
| 2422 | ccw++; |
| 2423 | if (dst) { |
| 2424 | if (ccw->flags & CCW_FLAG_IDA) |
| 2425 | cda = *((char **)((addr_t) ccw->cda)); |
| 2426 | else |
| 2427 | cda = (char *)((addr_t) ccw->cda); |
| 2428 | if (dst != cda) { |
| 2429 | if (rq_data_dir(req) == READ) |
| 2430 | memcpy(dst, cda, bv->bv_len); |
| 2431 | kmem_cache_free(dasd_page_cache, |
| 2432 | (void *)((addr_t)cda & PAGE_MASK)); |
| 2433 | } |
| 2434 | dst = NULL; |
| 2435 | } |
| 2436 | ccw++; |
| 2437 | recid++; |
| 2438 | } |
| 2439 | } |
| 2440 | out: |
| 2441 | status = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2442 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | return status; |
| 2444 | } |
| 2445 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2446 | /* |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2447 | * Modify ccw/tcw in cqr so it can be started on a base device. |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2448 | * |
| 2449 | * Note that this is not enough to restart the cqr! |
| 2450 | * Either reset cqr->startdev as well (summary unit check handling) |
| 2451 | * or restart via separate cqr (as in ERP handling). |
| 2452 | */ |
| 2453 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) |
| 2454 | { |
| 2455 | struct ccw1 *ccw; |
| 2456 | struct PFX_eckd_data *pfxdata; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2457 | struct tcw *tcw; |
| 2458 | struct tccb *tccb; |
| 2459 | struct dcw *dcw; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2460 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2461 | if (cqr->cpmode == 1) { |
| 2462 | tcw = cqr->cpaddr; |
| 2463 | tccb = tcw_get_tccb(tcw); |
| 2464 | dcw = (struct dcw *)&tccb->tca[0]; |
| 2465 | pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2466 | pfxdata->validity.verify_base = 0; |
| 2467 | pfxdata->validity.hyper_pav = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2468 | } else { |
| 2469 | ccw = cqr->cpaddr; |
| 2470 | pfxdata = cqr->data; |
| 2471 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { |
| 2472 | pfxdata->validity.verify_base = 0; |
| 2473 | pfxdata->validity.hyper_pav = 0; |
| 2474 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 |
| 2479 | |
| 2480 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, |
| 2481 | struct dasd_block *block, |
| 2482 | struct request *req) |
| 2483 | { |
| 2484 | struct dasd_eckd_private *private; |
| 2485 | struct dasd_device *startdev; |
| 2486 | unsigned long flags; |
| 2487 | struct dasd_ccw_req *cqr; |
| 2488 | |
| 2489 | startdev = dasd_alias_get_start_dev(base); |
| 2490 | if (!startdev) |
| 2491 | startdev = base; |
| 2492 | private = (struct dasd_eckd_private *) startdev->private; |
| 2493 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) |
| 2494 | return ERR_PTR(-EBUSY); |
| 2495 | |
| 2496 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); |
| 2497 | private->count++; |
| 2498 | cqr = dasd_eckd_build_cp(startdev, block, req); |
| 2499 | if (IS_ERR(cqr)) |
| 2500 | private->count--; |
| 2501 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); |
| 2502 | return cqr; |
| 2503 | } |
| 2504 | |
| 2505 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, |
| 2506 | struct request *req) |
| 2507 | { |
| 2508 | struct dasd_eckd_private *private; |
| 2509 | unsigned long flags; |
| 2510 | |
| 2511 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 2512 | private = (struct dasd_eckd_private *) cqr->memdev->private; |
| 2513 | private->count--; |
| 2514 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 2515 | return dasd_eckd_free_cp(cqr, req); |
| 2516 | } |
| 2517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | static int |
| 2519 | dasd_eckd_fill_info(struct dasd_device * device, |
| 2520 | struct dasd_information2_t * info) |
| 2521 | { |
| 2522 | struct dasd_eckd_private *private; |
| 2523 | |
| 2524 | private = (struct dasd_eckd_private *) device->private; |
| 2525 | info->label_block = 2; |
| 2526 | info->FBA_layout = private->uses_cdl ? 0 : 1; |
| 2527 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; |
| 2528 | info->characteristics_size = sizeof(struct dasd_eckd_characteristics); |
| 2529 | memcpy(info->characteristics, &private->rdc_data, |
| 2530 | sizeof(struct dasd_eckd_characteristics)); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 2531 | info->confdata_size = min((unsigned long)private->conf_len, |
| 2532 | sizeof(info->configuration_data)); |
| 2533 | memcpy(info->configuration_data, private->conf_data, |
| 2534 | info->confdata_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | return 0; |
| 2536 | } |
| 2537 | |
| 2538 | /* |
| 2539 | * SECTION: ioctl functions for eckd devices. |
| 2540 | */ |
| 2541 | |
| 2542 | /* |
| 2543 | * Release device ioctl. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2544 | * Buils a channel programm to releases a prior reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | * (see dasd_eckd_reserve) device. |
| 2546 | */ |
| 2547 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2548 | dasd_eckd_release(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | struct dasd_ccw_req *cqr; |
| 2551 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2552 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | |
| 2554 | if (!capable(CAP_SYS_ADMIN)) |
| 2555 | return -EACCES; |
| 2556 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2557 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2559 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | "Could not allocate initialization request"); |
| 2561 | return PTR_ERR(cqr); |
| 2562 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2563 | ccw = cqr->cpaddr; |
| 2564 | ccw->cmd_code = DASD_ECKD_CCW_RELEASE; |
| 2565 | ccw->flags |= CCW_FLAG_SLI; |
| 2566 | ccw->count = 32; |
| 2567 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2568 | cqr->startdev = device; |
| 2569 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2571 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2572 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | cqr->expires = 2 * HZ; |
| 2574 | cqr->buildclk = get_clock(); |
| 2575 | cqr->status = DASD_CQR_FILLED; |
| 2576 | |
| 2577 | rc = dasd_sleep_on_immediatly(cqr); |
| 2578 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2579 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | return rc; |
| 2581 | } |
| 2582 | |
| 2583 | /* |
| 2584 | * Reserve device ioctl. |
| 2585 | * Options are set to 'synchronous wait for interrupt' and |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2586 | * 'timeout the request'. This leads to a terminate IO if |
| 2587 | * the interrupt is outstanding for a certain time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | */ |
| 2589 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2590 | dasd_eckd_reserve(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | struct dasd_ccw_req *cqr; |
| 2593 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2594 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | |
| 2596 | if (!capable(CAP_SYS_ADMIN)) |
| 2597 | return -EACCES; |
| 2598 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2599 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2601 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | "Could not allocate initialization request"); |
| 2603 | return PTR_ERR(cqr); |
| 2604 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2605 | ccw = cqr->cpaddr; |
| 2606 | ccw->cmd_code = DASD_ECKD_CCW_RESERVE; |
| 2607 | ccw->flags |= CCW_FLAG_SLI; |
| 2608 | ccw->count = 32; |
| 2609 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2610 | cqr->startdev = device; |
| 2611 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2613 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2614 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | cqr->expires = 2 * HZ; |
| 2616 | cqr->buildclk = get_clock(); |
| 2617 | cqr->status = DASD_CQR_FILLED; |
| 2618 | |
| 2619 | rc = dasd_sleep_on_immediatly(cqr); |
| 2620 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2621 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | return rc; |
| 2623 | } |
| 2624 | |
| 2625 | /* |
| 2626 | * Steal lock ioctl - unconditional reserve device. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2627 | * Buils a channel programm to break a device's reservation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | * (unconditional reserve) |
| 2629 | */ |
| 2630 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2631 | dasd_eckd_steal_lock(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | struct dasd_ccw_req *cqr; |
| 2634 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2635 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
| 2637 | if (!capable(CAP_SYS_ADMIN)) |
| 2638 | return -EACCES; |
| 2639 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2640 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2642 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | "Could not allocate initialization request"); |
| 2644 | return PTR_ERR(cqr); |
| 2645 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2646 | ccw = cqr->cpaddr; |
| 2647 | ccw->cmd_code = DASD_ECKD_CCW_SLCK; |
| 2648 | ccw->flags |= CCW_FLAG_SLI; |
| 2649 | ccw->count = 32; |
| 2650 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2651 | cqr->startdev = device; |
| 2652 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2654 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2655 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | cqr->expires = 2 * HZ; |
| 2657 | cqr->buildclk = get_clock(); |
| 2658 | cqr->status = DASD_CQR_FILLED; |
| 2659 | |
| 2660 | rc = dasd_sleep_on_immediatly(cqr); |
| 2661 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2662 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | return rc; |
| 2664 | } |
| 2665 | |
| 2666 | /* |
| 2667 | * Read performance statistics |
| 2668 | */ |
| 2669 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2670 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | struct dasd_psf_prssd_data *prssdp; |
| 2673 | struct dasd_rssd_perf_stats_t *stats; |
| 2674 | struct dasd_ccw_req *cqr; |
| 2675 | struct ccw1 *ccw; |
| 2676 | int rc; |
| 2677 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2678 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2679 | (sizeof(struct dasd_psf_prssd_data) + |
| 2680 | sizeof(struct dasd_rssd_perf_stats_t)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | device); |
| 2682 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2683 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | "Could not allocate initialization request"); |
| 2685 | return PTR_ERR(cqr); |
| 2686 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2687 | cqr->startdev = device; |
| 2688 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | cqr->retries = 0; |
| 2690 | cqr->expires = 10 * HZ; |
| 2691 | |
| 2692 | /* Prepare for Read Subsystem Data */ |
| 2693 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2694 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | prssdp->order = PSF_ORDER_PRSSD; |
Joe Perches | 5d67d16 | 2008-01-26 14:11:20 +0100 | [diff] [blame] | 2696 | prssdp->suborder = 0x01; /* Performance Statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
| 2698 | |
| 2699 | ccw = cqr->cpaddr; |
| 2700 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2701 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | ccw->flags |= CCW_FLAG_CC; |
| 2703 | ccw->cda = (__u32)(addr_t) prssdp; |
| 2704 | |
| 2705 | /* Read Subsystem Data - Performance Statistics */ |
| 2706 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2707 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | |
| 2709 | ccw++; |
| 2710 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2711 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | ccw->cda = (__u32)(addr_t) stats; |
| 2713 | |
| 2714 | cqr->buildclk = get_clock(); |
| 2715 | cqr->status = DASD_CQR_FILLED; |
| 2716 | rc = dasd_sleep_on(cqr); |
| 2717 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 2719 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2720 | if (copy_to_user(argp, stats, |
| 2721 | sizeof(struct dasd_rssd_perf_stats_t))) |
| 2722 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2724 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | return rc; |
| 2726 | } |
| 2727 | |
| 2728 | /* |
| 2729 | * Get attributes (cache operations) |
| 2730 | * Returnes the cache attributes used in Define Extend (DE). |
| 2731 | */ |
| 2732 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2733 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2735 | struct dasd_eckd_private *private = |
| 2736 | (struct dasd_eckd_private *)device->private; |
| 2737 | struct attrib_data_t attrib = private->attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | int rc; |
| 2739 | |
| 2740 | if (!capable(CAP_SYS_ADMIN)) |
| 2741 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2742 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | return -EINVAL; |
| 2744 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2745 | rc = 0; |
| 2746 | if (copy_to_user(argp, (long *) &attrib, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2747 | sizeof(struct attrib_data_t))) |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2748 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | |
| 2750 | return rc; |
| 2751 | } |
| 2752 | |
| 2753 | /* |
| 2754 | * Set attributes (cache operations) |
| 2755 | * Stores the attributes for cache operation to be used in Define Extend (DE). |
| 2756 | */ |
| 2757 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2758 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2760 | struct dasd_eckd_private *private = |
| 2761 | (struct dasd_eckd_private *)device->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | struct attrib_data_t attrib; |
| 2763 | |
| 2764 | if (!capable(CAP_SYS_ADMIN)) |
| 2765 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2766 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | return -EINVAL; |
| 2768 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2769 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | private->attrib = attrib; |
| 2772 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2773 | dev_info(&device->cdev->dev, |
| 2774 | "The DASD cache mode was set to %x (%i cylinder prestage)\n", |
| 2775 | private->attrib.operation, private->attrib.nr_cyl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | return 0; |
| 2777 | } |
| 2778 | |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2779 | /* |
| 2780 | * Issue syscall I/O to EMC Symmetrix array. |
| 2781 | * CCWs are PSF and RSSD |
| 2782 | */ |
| 2783 | static int dasd_symm_io(struct dasd_device *device, void __user *argp) |
| 2784 | { |
| 2785 | struct dasd_symmio_parms usrparm; |
| 2786 | char *psf_data, *rssd_result; |
| 2787 | struct dasd_ccw_req *cqr; |
| 2788 | struct ccw1 *ccw; |
| 2789 | int rc; |
| 2790 | |
| 2791 | /* Copy parms from caller */ |
| 2792 | rc = -EFAULT; |
| 2793 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) |
| 2794 | goto out; |
| 2795 | #ifndef CONFIG_64BIT |
| 2796 | /* Make sure pointers are sane even on 31 bit. */ |
| 2797 | if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) { |
| 2798 | rc = -EINVAL; |
| 2799 | goto out; |
| 2800 | } |
| 2801 | #endif |
| 2802 | /* alloc I/O data area */ |
| 2803 | psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); |
| 2804 | rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); |
| 2805 | if (!psf_data || !rssd_result) { |
| 2806 | rc = -ENOMEM; |
| 2807 | goto out_free; |
| 2808 | } |
| 2809 | |
| 2810 | /* get syscall header from user space */ |
| 2811 | rc = -EFAULT; |
| 2812 | if (copy_from_user(psf_data, |
| 2813 | (void __user *)(unsigned long) usrparm.psf_data, |
| 2814 | usrparm.psf_data_len)) |
| 2815 | goto out_free; |
| 2816 | |
| 2817 | /* sanity check on syscall header */ |
| 2818 | if (psf_data[0] != 0x17 && psf_data[1] != 0xce) { |
| 2819 | rc = -EINVAL; |
| 2820 | goto out_free; |
| 2821 | } |
| 2822 | |
| 2823 | /* setup CCWs for PSF + RSSD */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2824 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2825 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2826 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2827 | "Could not allocate initialization request"); |
| 2828 | rc = PTR_ERR(cqr); |
| 2829 | goto out_free; |
| 2830 | } |
| 2831 | |
| 2832 | cqr->startdev = device; |
| 2833 | cqr->memdev = device; |
| 2834 | cqr->retries = 3; |
| 2835 | cqr->expires = 10 * HZ; |
| 2836 | cqr->buildclk = get_clock(); |
| 2837 | cqr->status = DASD_CQR_FILLED; |
| 2838 | |
| 2839 | /* Build the ccws */ |
| 2840 | ccw = cqr->cpaddr; |
| 2841 | |
| 2842 | /* PSF ccw */ |
| 2843 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 2844 | ccw->count = usrparm.psf_data_len; |
| 2845 | ccw->flags |= CCW_FLAG_CC; |
| 2846 | ccw->cda = (__u32)(addr_t) psf_data; |
| 2847 | |
| 2848 | ccw++; |
| 2849 | |
| 2850 | /* RSSD ccw */ |
| 2851 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 2852 | ccw->count = usrparm.rssd_result_len; |
| 2853 | ccw->flags = CCW_FLAG_SLI ; |
| 2854 | ccw->cda = (__u32)(addr_t) rssd_result; |
| 2855 | |
| 2856 | rc = dasd_sleep_on(cqr); |
| 2857 | if (rc) |
| 2858 | goto out_sfree; |
| 2859 | |
| 2860 | rc = -EFAULT; |
| 2861 | if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, |
| 2862 | rssd_result, usrparm.rssd_result_len)) |
| 2863 | goto out_sfree; |
| 2864 | rc = 0; |
| 2865 | |
| 2866 | out_sfree: |
| 2867 | dasd_sfree_request(cqr, cqr->memdev); |
| 2868 | out_free: |
| 2869 | kfree(rssd_result); |
| 2870 | kfree(psf_data); |
| 2871 | out: |
| 2872 | DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc); |
| 2873 | return rc; |
| 2874 | } |
| 2875 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2876 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2877 | 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] | 2878 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2879 | struct dasd_device *device = block->base; |
| 2880 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2881 | switch (cmd) { |
| 2882 | case BIODASDGATTR: |
| 2883 | return dasd_eckd_get_attrib(device, argp); |
| 2884 | case BIODASDSATTR: |
| 2885 | return dasd_eckd_set_attrib(device, argp); |
| 2886 | case BIODASDPSRD: |
| 2887 | return dasd_eckd_performance(device, argp); |
| 2888 | case BIODASDRLSE: |
| 2889 | return dasd_eckd_release(device); |
| 2890 | case BIODASDRSRV: |
| 2891 | return dasd_eckd_reserve(device); |
| 2892 | case BIODASDSLCK: |
| 2893 | return dasd_eckd_steal_lock(device); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2894 | case BIODASDSYMMIO: |
| 2895 | return dasd_symm_io(device, argp); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2896 | default: |
| 2897 | return -ENOIOCTLCMD; |
| 2898 | } |
| 2899 | } |
| 2900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | /* |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2902 | * Dump the range of CCWs into 'page' buffer |
| 2903 | * and return number of printed chars. |
| 2904 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2905 | static int |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2906 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
| 2907 | { |
| 2908 | int len, count; |
| 2909 | char *datap; |
| 2910 | |
| 2911 | len = 0; |
| 2912 | while (from <= to) { |
| 2913 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2914 | " CCW %p: %08X %08X DAT:", |
| 2915 | from, ((int *) from)[0], ((int *) from)[1]); |
| 2916 | |
| 2917 | /* get pointer to data (consider IDALs) */ |
| 2918 | if (from->flags & CCW_FLAG_IDA) |
| 2919 | datap = (char *) *((addr_t *) (addr_t) from->cda); |
| 2920 | else |
| 2921 | datap = (char *) ((addr_t) from->cda); |
| 2922 | |
| 2923 | /* dump data (max 32 bytes) */ |
| 2924 | for (count = 0; count < from->count && count < 32; count++) { |
| 2925 | if (count % 8 == 0) len += sprintf(page + len, " "); |
| 2926 | if (count % 4 == 0) len += sprintf(page + len, " "); |
| 2927 | len += sprintf(page + len, "%02x", datap[count]); |
| 2928 | } |
| 2929 | len += sprintf(page + len, "\n"); |
| 2930 | from++; |
| 2931 | } |
| 2932 | return len; |
| 2933 | } |
| 2934 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2935 | static void |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2936 | dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
| 2937 | char *reason) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2938 | { |
| 2939 | u64 *sense; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2940 | |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2941 | sense = (u64 *) dasd_get_sense(irb); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2942 | if (sense) { |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2943 | DBF_DEV_EVENT(DBF_EMERG, device, |
| 2944 | "%s: %s %02x%02x%02x %016llx %016llx %016llx " |
| 2945 | "%016llx", reason, |
| 2946 | scsw_is_tm(&irb->scsw) ? "t" : "c", |
| 2947 | scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw), |
| 2948 | scsw_dstat(&irb->scsw), sense[0], sense[1], |
| 2949 | sense[2], sense[3]); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2950 | } else { |
| 2951 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", |
| 2952 | "SORRY - NO VALID SENSE AVAILABLE\n"); |
| 2953 | } |
| 2954 | } |
| 2955 | |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2956 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | * Print sense data and related channel program. |
| 2958 | * Parts are printed because printk buffer is only 1024 bytes. |
| 2959 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2960 | static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2961 | struct dasd_ccw_req *req, struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | { |
| 2963 | char *page; |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2964 | struct ccw1 *first, *last, *fail, *from, *to; |
| 2965 | int len, sl, sct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
| 2967 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 2968 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2969 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 2970 | "No memory to dump sense data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | return; |
| 2972 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2973 | /* dump the sense data */ |
| 2974 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | " I/O status report for device %s:\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2976 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 2978 | " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d\n", |
| 2979 | req, scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw), |
| 2980 | scsw_cc(&irb->scsw), req->intrc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2982 | " device %s: Failing CCW: %p\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2983 | dev_name(&device->cdev->dev), |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 2984 | (void *) (addr_t) irb->scsw.cmd.cpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | if (irb->esw.esw0.erw.cons) { |
| 2986 | for (sl = 0; sl < 4; sl++) { |
| 2987 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2988 | " Sense(hex) %2d-%2d:", |
| 2989 | (8 * sl), ((8 * sl) + 7)); |
| 2990 | |
| 2991 | for (sct = 0; sct < 8; sct++) { |
| 2992 | len += sprintf(page + len, " %02x", |
| 2993 | irb->ecw[8 * sl + sct]); |
| 2994 | } |
| 2995 | len += sprintf(page + len, "\n"); |
| 2996 | } |
| 2997 | |
| 2998 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { |
| 2999 | /* 24 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3000 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3001 | " 24 Byte: %x MSG %x, " |
| 3002 | "%s MSGb to SYSOP\n", |
| 3003 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, |
| 3004 | irb->ecw[1] & 0x10 ? "" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | } else { |
| 3006 | /* 32 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3007 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3008 | " 32 Byte: Format: %x " |
| 3009 | "Exception class %x\n", |
| 3010 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | } |
| 3012 | } else { |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3013 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3014 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3016 | printk("%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3018 | if (req) { |
| 3019 | /* req == NULL for unsolicited interrupts */ |
| 3020 | /* dump the Channel Program (max 140 Bytes per line) */ |
| 3021 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ |
| 3022 | first = req->cpaddr; |
| 3023 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); |
| 3024 | to = min(first + 6, last); |
| 3025 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 3026 | " Related CP in req: %p\n", req); |
| 3027 | dasd_eckd_dump_ccw_range(first, to, page + len); |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3028 | printk("%s", page); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3029 | |
| 3030 | /* print failing CCW area (maximum 4) */ |
| 3031 | /* scsw->cda is either valid or zero */ |
| 3032 | len = 0; |
| 3033 | from = ++to; |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 3034 | fail = (struct ccw1 *)(addr_t) |
| 3035 | irb->scsw.cmd.cpa; /* failing CCW */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3036 | if (from < fail - 2) { |
| 3037 | from = fail - 2; /* there is a gap - print header */ |
| 3038 | len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n"); |
| 3039 | } |
| 3040 | to = min(fail + 1, last); |
| 3041 | len += dasd_eckd_dump_ccw_range(from, to, page + len); |
| 3042 | |
| 3043 | /* print last CCWs (maximum 2) */ |
| 3044 | from = max(from, ++to); |
| 3045 | if (from < last - 1) { |
| 3046 | from = last - 1; /* there is a gap - print header */ |
| 3047 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); |
| 3048 | } |
| 3049 | len += dasd_eckd_dump_ccw_range(from, last, page + len); |
| 3050 | if (len > 0) |
| 3051 | printk("%s", page); |
| 3052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | free_page((unsigned long) page); |
| 3054 | } |
| 3055 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3056 | |
| 3057 | /* |
| 3058 | * Print sense data from a tcw. |
| 3059 | */ |
| 3060 | static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, |
| 3061 | struct dasd_ccw_req *req, struct irb *irb) |
| 3062 | { |
| 3063 | char *page; |
| 3064 | int len, sl, sct, residual; |
| 3065 | |
| 3066 | struct tsb *tsb; |
| 3067 | u8 *sense; |
| 3068 | |
| 3069 | |
| 3070 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 3071 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3072 | DBF_DEV_EVENT(DBF_WARNING, device, " %s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3073 | "No memory to dump sense data"); |
| 3074 | return; |
| 3075 | } |
| 3076 | /* dump the sense data */ |
| 3077 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 3078 | " I/O status report for device %s:\n", |
| 3079 | dev_name(&device->cdev->dev)); |
| 3080 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 3081 | " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d " |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3082 | "fcxs: 0x%02X schxs: 0x%02X\n", req, |
| 3083 | scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw), |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 3084 | scsw_cc(&irb->scsw), req->intrc, |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3085 | irb->scsw.tm.fcxs, irb->scsw.tm.schxs); |
| 3086 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3087 | " device %s: Failing TCW: %p\n", |
| 3088 | dev_name(&device->cdev->dev), |
| 3089 | (void *) (addr_t) irb->scsw.tm.tcw); |
| 3090 | |
| 3091 | tsb = NULL; |
| 3092 | sense = NULL; |
| 3093 | if (irb->scsw.tm.tcw) |
| 3094 | tsb = tcw_get_tsb( |
| 3095 | (struct tcw *)(unsigned long)irb->scsw.tm.tcw); |
| 3096 | |
| 3097 | if (tsb && (irb->scsw.tm.fcxs == 0x01)) { |
| 3098 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3099 | " tsb->length %d\n", tsb->length); |
| 3100 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3101 | " tsb->flags %x\n", tsb->flags); |
| 3102 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3103 | " tsb->dcw_offset %d\n", tsb->dcw_offset); |
| 3104 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3105 | " tsb->count %d\n", tsb->count); |
| 3106 | residual = tsb->count - 28; |
| 3107 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3108 | " residual %d\n", residual); |
| 3109 | |
| 3110 | switch (tsb->flags & 0x07) { |
| 3111 | case 1: /* tsa_iostat */ |
| 3112 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3113 | " tsb->tsa.iostat.dev_time %d\n", |
| 3114 | tsb->tsa.iostat.dev_time); |
| 3115 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3116 | " tsb->tsa.iostat.def_time %d\n", |
| 3117 | tsb->tsa.iostat.def_time); |
| 3118 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3119 | " tsb->tsa.iostat.queue_time %d\n", |
| 3120 | tsb->tsa.iostat.queue_time); |
| 3121 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3122 | " tsb->tsa.iostat.dev_busy_time %d\n", |
| 3123 | tsb->tsa.iostat.dev_busy_time); |
| 3124 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3125 | " tsb->tsa.iostat.dev_act_time %d\n", |
| 3126 | tsb->tsa.iostat.dev_act_time); |
| 3127 | sense = tsb->tsa.iostat.sense; |
| 3128 | break; |
| 3129 | case 2: /* ts_ddpc */ |
| 3130 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3131 | " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); |
| 3132 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3133 | " tsb->tsa.ddpc.rcq: "); |
| 3134 | for (sl = 0; sl < 16; sl++) { |
| 3135 | for (sct = 0; sct < 8; sct++) { |
| 3136 | len += sprintf(page + len, " %02x", |
| 3137 | tsb->tsa.ddpc.rcq[sl]); |
| 3138 | } |
| 3139 | len += sprintf(page + len, "\n"); |
| 3140 | } |
| 3141 | sense = tsb->tsa.ddpc.sense; |
| 3142 | break; |
| 3143 | case 3: /* tsa_intrg */ |
| 3144 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3145 | " tsb->tsa.intrg.: not supportet yet \n"); |
| 3146 | break; |
| 3147 | } |
| 3148 | |
| 3149 | if (sense) { |
| 3150 | for (sl = 0; sl < 4; sl++) { |
| 3151 | len += sprintf(page + len, |
| 3152 | KERN_ERR PRINTK_HEADER |
| 3153 | " Sense(hex) %2d-%2d:", |
| 3154 | (8 * sl), ((8 * sl) + 7)); |
| 3155 | for (sct = 0; sct < 8; sct++) { |
| 3156 | len += sprintf(page + len, " %02x", |
| 3157 | sense[8 * sl + sct]); |
| 3158 | } |
| 3159 | len += sprintf(page + len, "\n"); |
| 3160 | } |
| 3161 | |
| 3162 | if (sense[27] & DASD_SENSE_BIT_0) { |
| 3163 | /* 24 Byte Sense Data */ |
| 3164 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3165 | " 24 Byte: %x MSG %x, " |
| 3166 | "%s MSGb to SYSOP\n", |
| 3167 | sense[7] >> 4, sense[7] & 0x0f, |
| 3168 | sense[1] & 0x10 ? "" : "no"); |
| 3169 | } else { |
| 3170 | /* 32 Byte Sense Data */ |
| 3171 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3172 | " 32 Byte: Format: %x " |
| 3173 | "Exception class %x\n", |
| 3174 | sense[6] & 0x0f, sense[22] >> 4); |
| 3175 | } |
| 3176 | } else { |
| 3177 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3178 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
| 3179 | } |
| 3180 | } else { |
| 3181 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3182 | " SORRY - NO TSB DATA AVAILABLE\n"); |
| 3183 | } |
| 3184 | printk("%s", page); |
| 3185 | free_page((unsigned long) page); |
| 3186 | } |
| 3187 | |
| 3188 | static void dasd_eckd_dump_sense(struct dasd_device *device, |
| 3189 | struct dasd_ccw_req *req, struct irb *irb) |
| 3190 | { |
| 3191 | if (req && scsw_is_tm(&req->irb.scsw)) |
| 3192 | dasd_eckd_dump_sense_tcw(device, req, irb); |
| 3193 | else |
| 3194 | dasd_eckd_dump_sense_ccw(device, req, irb); |
| 3195 | } |
| 3196 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3197 | int dasd_eckd_pm_freeze(struct dasd_device *device) |
| 3198 | { |
| 3199 | /* |
| 3200 | * the device should be disconnected from our LCU structure |
| 3201 | * on restore we will reconnect it and reread LCU specific |
| 3202 | * information like PAV support that might have changed |
| 3203 | */ |
| 3204 | dasd_alias_remove_device(device); |
| 3205 | dasd_alias_disconnect_device_from_lcu(device); |
| 3206 | |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
| 3210 | int dasd_eckd_restore_device(struct dasd_device *device) |
| 3211 | { |
| 3212 | struct dasd_eckd_private *private; |
| 3213 | int is_known, rc; |
| 3214 | struct dasd_uid temp_uid; |
| 3215 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3216 | private = (struct dasd_eckd_private *) device->private; |
| 3217 | |
| 3218 | /* Read Configuration Data */ |
| 3219 | rc = dasd_eckd_read_conf(device); |
| 3220 | if (rc) |
| 3221 | goto out_err; |
| 3222 | |
| 3223 | /* Generate device unique id and register in devmap */ |
| 3224 | rc = dasd_eckd_generate_uid(device, &private->uid); |
| 3225 | dasd_get_uid(device->cdev, &temp_uid); |
| 3226 | if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) |
| 3227 | dev_err(&device->cdev->dev, "The UID of the DASD has changed\n"); |
| 3228 | if (rc) |
| 3229 | goto out_err; |
| 3230 | dasd_set_uid(device->cdev, &private->uid); |
| 3231 | |
| 3232 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
| 3233 | is_known = dasd_alias_make_device_known_to_lcu(device); |
| 3234 | if (is_known < 0) |
| 3235 | return is_known; |
| 3236 | if (!is_known) { |
| 3237 | /* new lcu found */ |
| 3238 | rc = dasd_eckd_validate_server(device); /* will switch pav on */ |
| 3239 | if (rc) |
| 3240 | goto out_err; |
| 3241 | } |
| 3242 | |
| 3243 | /* Read Feature Codes */ |
| 3244 | rc = dasd_eckd_read_features(device); |
| 3245 | if (rc) |
| 3246 | goto out_err; |
| 3247 | |
| 3248 | /* Read Device Characteristics */ |
| 3249 | memset(&private->rdc_data, 0, sizeof(private->rdc_data)); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3250 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3251 | &private->rdc_data, 64); |
| 3252 | if (rc) { |
| 3253 | DBF_EVENT(DBF_WARNING, |
| 3254 | "Read device characteristics failed, rc=%d for " |
| 3255 | "device: %s", rc, dev_name(&device->cdev->dev)); |
| 3256 | goto out_err; |
| 3257 | } |
| 3258 | |
| 3259 | /* add device to alias management */ |
| 3260 | dasd_alias_add_device(device); |
| 3261 | |
| 3262 | return 0; |
| 3263 | |
| 3264 | out_err: |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 3265 | return -1; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | static struct ccw_driver dasd_eckd_driver = { |
| 3269 | .name = "dasd-eckd", |
| 3270 | .owner = THIS_MODULE, |
| 3271 | .ids = dasd_eckd_ids, |
| 3272 | .probe = dasd_eckd_probe, |
| 3273 | .remove = dasd_generic_remove, |
| 3274 | .set_offline = dasd_generic_set_offline, |
| 3275 | .set_online = dasd_eckd_set_online, |
| 3276 | .notify = dasd_generic_notify, |
| 3277 | .freeze = dasd_generic_pm_freeze, |
| 3278 | .thaw = dasd_generic_restore_device, |
| 3279 | .restore = dasd_generic_restore_device, |
| 3280 | }; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | /* |
| 3283 | * max_blocks is dependent on the amount of storage that is available |
| 3284 | * in the static io buffer for each device. Currently each device has |
| 3285 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has |
| 3286 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use |
| 3287 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In |
| 3288 | * addition we have one define extent ccw + 16 bytes of data and one |
| 3289 | * locate record ccw + 16 bytes of data. That makes: |
| 3290 | * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. |
| 3291 | * We want to fit two into the available memory so that we can immediately |
| 3292 | * start the next request if one finishes off. That makes 249.5 blocks |
| 3293 | * for one request. Give a little safety and the result is 240. |
| 3294 | */ |
| 3295 | static struct dasd_discipline dasd_eckd_discipline = { |
| 3296 | .owner = THIS_MODULE, |
| 3297 | .name = "ECKD", |
| 3298 | .ebcname = "ECKD", |
| 3299 | .max_blocks = 240, |
| 3300 | .check_device = dasd_eckd_check_characteristics, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3301 | .uncheck_device = dasd_eckd_uncheck_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | .do_analysis = dasd_eckd_do_analysis, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3303 | .ready_to_online = dasd_eckd_ready_to_online, |
| 3304 | .online_to_ready = dasd_eckd_online_to_ready, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | .fill_geometry = dasd_eckd_fill_geometry, |
| 3306 | .start_IO = dasd_start_IO, |
| 3307 | .term_IO = dasd_term_IO, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3308 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | .format_device = dasd_eckd_format_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | .erp_action = dasd_eckd_erp_action, |
| 3311 | .erp_postaction = dasd_eckd_erp_postaction, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3312 | .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt, |
| 3313 | .build_cp = dasd_eckd_build_alias_cp, |
| 3314 | .free_cp = dasd_eckd_free_alias_cp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | .dump_sense = dasd_eckd_dump_sense, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3316 | .dump_sense_dbf = dasd_eckd_dump_sense_dbf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | .fill_info = dasd_eckd_fill_info, |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3318 | .ioctl = dasd_eckd_ioctl, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3319 | .freeze = dasd_eckd_pm_freeze, |
| 3320 | .restore = dasd_eckd_restore_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | }; |
| 3322 | |
| 3323 | static int __init |
| 3324 | dasd_eckd_init(void) |
| 3325 | { |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 3326 | int ret; |
| 3327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 3329 | ret = ccw_driver_register(&dasd_eckd_driver); |
| 3330 | if (!ret) |
| 3331 | wait_for_device_probe(); |
| 3332 | |
| 3333 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | static void __exit |
| 3337 | dasd_eckd_cleanup(void) |
| 3338 | { |
| 3339 | ccw_driver_unregister(&dasd_eckd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | module_init(dasd_eckd_init); |
| 3343 | module_exit(dasd_eckd_cleanup); |