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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/uaccess.h> |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 28 | #include <asm/cio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/ccwdev.h> |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 30 | #include <asm/itcw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include "dasd_int.h" |
| 33 | #include "dasd_eckd.h" |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 34 | #include "../cio/chsc.h" |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #ifdef PRINTK_HEADER |
| 38 | #undef PRINTK_HEADER |
| 39 | #endif /* PRINTK_HEADER */ |
| 40 | #define PRINTK_HEADER "dasd(eckd):" |
| 41 | |
| 42 | #define ECKD_C0(i) (i->home_bytes) |
| 43 | #define ECKD_F(i) (i->formula) |
| 44 | #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\ |
| 45 | (i->factors.f_0x02.f1)) |
| 46 | #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\ |
| 47 | (i->factors.f_0x02.f2)) |
| 48 | #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\ |
| 49 | (i->factors.f_0x02.f3)) |
| 50 | #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0) |
| 51 | #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0) |
| 52 | #define ECKD_F6(i) (i->factor6) |
| 53 | #define ECKD_F7(i) (i->factor7) |
| 54 | #define ECKD_F8(i) (i->factor8) |
| 55 | |
| 56 | MODULE_LICENSE("GPL"); |
| 57 | |
| 58 | static struct dasd_discipline dasd_eckd_discipline; |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* The ccw bus type uses this table to find devices that it sends to |
| 61 | * dasd_eckd_probe */ |
| 62 | static struct ccw_device_id dasd_eckd_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 63 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
| 64 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, |
| 65 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3}, |
| 66 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
| 67 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, |
| 68 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, |
| 69 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, |
| 70 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, |
| 71 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, |
| 72 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { /* end of list */ }, |
| 74 | }; |
| 75 | |
| 76 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); |
| 77 | |
| 78 | static struct ccw_driver dasd_eckd_driver; /* see below */ |
| 79 | |
| 80 | /* initial attempt at a probe function. this can be simplified once |
| 81 | * the other detection code is gone */ |
| 82 | static int |
| 83 | dasd_eckd_probe (struct ccw_device *cdev) |
| 84 | { |
| 85 | int ret; |
| 86 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 87 | /* set ECKD specific ccw-device options */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 88 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE | |
| 89 | CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 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; |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 709 | uid->real_unit_addr = private->ned->unit_addr; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 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 Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 938 | memset(&private->features, 0, sizeof(struct dasd_rssd_features)); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 939 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 940 | (sizeof(struct dasd_psf_prssd_data) + |
| 941 | sizeof(struct dasd_rssd_features)), |
| 942 | device); |
| 943 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 944 | DBF_EVENT(DBF_WARNING, "Could not allocate initialization " |
| 945 | "request for device: %s", |
| 946 | dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 947 | return PTR_ERR(cqr); |
| 948 | } |
| 949 | cqr->startdev = device; |
| 950 | cqr->memdev = device; |
| 951 | cqr->block = NULL; |
| 952 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 953 | cqr->retries = 5; |
| 954 | cqr->expires = 10 * HZ; |
| 955 | |
| 956 | /* Prepare for Read Subsystem Data */ |
| 957 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 958 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 959 | prssdp->order = PSF_ORDER_PRSSD; |
| 960 | prssdp->suborder = 0x41; /* Read Feature Codes */ |
| 961 | /* all other bytes of prssdp must be zero */ |
| 962 | |
| 963 | ccw = cqr->cpaddr; |
| 964 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 965 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 966 | ccw->flags |= CCW_FLAG_CC; |
| 967 | ccw->cda = (__u32)(addr_t) prssdp; |
| 968 | |
| 969 | /* Read Subsystem Data - feature codes */ |
| 970 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 971 | memset(features, 0, sizeof(struct dasd_rssd_features)); |
| 972 | |
| 973 | ccw++; |
| 974 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 975 | ccw->count = sizeof(struct dasd_rssd_features); |
| 976 | ccw->cda = (__u32)(addr_t) features; |
| 977 | |
| 978 | cqr->buildclk = get_clock(); |
| 979 | cqr->status = DASD_CQR_FILLED; |
| 980 | rc = dasd_sleep_on(cqr); |
| 981 | if (rc == 0) { |
| 982 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 983 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 984 | memcpy(&private->features, features, |
| 985 | sizeof(struct dasd_rssd_features)); |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 986 | } else |
| 987 | dev_warn(&device->cdev->dev, "Reading device feature codes" |
| 988 | " failed with rc=%d\n", rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 989 | dasd_sfree_request(cqr, cqr->memdev); |
| 990 | return rc; |
| 991 | } |
| 992 | |
| 993 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 994 | /* |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 995 | * Build CP for Perform Subsystem Function - SSC. |
| 996 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 997 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, |
| 998 | int enable_pav) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 999 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1000 | struct dasd_ccw_req *cqr; |
| 1001 | struct dasd_psf_ssc_data *psf_ssc_data; |
| 1002 | struct ccw1 *ccw; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1003 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1004 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1005 | sizeof(struct dasd_psf_ssc_data), |
| 1006 | device); |
| 1007 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1008 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1009 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1010 | "Could not allocate PSF-SSC request"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1011 | return cqr; |
| 1012 | } |
| 1013 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; |
| 1014 | psf_ssc_data->order = PSF_ORDER_SSC; |
Stefan Weinhuber | 626350b | 2009-12-07 12:51:50 +0100 | [diff] [blame^] | 1015 | psf_ssc_data->suborder = 0xc0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1016 | if (enable_pav) { |
Stefan Weinhuber | 626350b | 2009-12-07 12:51:50 +0100 | [diff] [blame^] | 1017 | psf_ssc_data->suborder |= 0x08; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1018 | psf_ssc_data->reserved[0] = 0x88; |
| 1019 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1020 | ccw = cqr->cpaddr; |
| 1021 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 1022 | ccw->cda = (__u32)(addr_t)psf_ssc_data; |
| 1023 | ccw->count = 66; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1024 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1025 | cqr->startdev = device; |
| 1026 | cqr->memdev = device; |
| 1027 | cqr->block = NULL; |
| 1028 | cqr->expires = 10*HZ; |
| 1029 | cqr->buildclk = get_clock(); |
| 1030 | cqr->status = DASD_CQR_FILLED; |
| 1031 | return cqr; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * Perform Subsystem Function. |
| 1036 | * It is necessary to trigger CIO for channel revalidation since this |
| 1037 | * call might change behaviour of DASD devices. |
| 1038 | */ |
| 1039 | static int |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1040 | dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1041 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1042 | struct dasd_ccw_req *cqr; |
| 1043 | int rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1044 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1045 | cqr = dasd_eckd_build_psf_ssc(device, enable_pav); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1046 | if (IS_ERR(cqr)) |
| 1047 | return PTR_ERR(cqr); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1048 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1049 | rc = dasd_sleep_on(cqr); |
| 1050 | if (!rc) |
| 1051 | /* trigger CIO to reprobe devices */ |
| 1052 | css_schedule_reprobe(); |
| 1053 | dasd_sfree_request(cqr, cqr->memdev); |
| 1054 | return rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /* |
| 1058 | * Valide storage server of current device. |
| 1059 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1060 | static int dasd_eckd_validate_server(struct dasd_device *device) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1061 | { |
| 1062 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1063 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1064 | int enable_pav; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1065 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1066 | if (dasd_nopav || MACHINE_IS_VM) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1067 | enable_pav = 0; |
| 1068 | else |
| 1069 | enable_pav = 1; |
| 1070 | rc = dasd_eckd_psf_ssc(device, enable_pav); |
Horst Hummel | 8e79a44 | 2006-08-24 13:22:36 +0200 | [diff] [blame] | 1071 | /* may be requested feature is not available on server, |
| 1072 | * therefore just report error and go ahead */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1073 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1074 | DBF_EVENT(DBF_WARNING, "PSF-SSC on storage subsystem %s.%s.%04x " |
| 1075 | "returned rc=%d for device: %s", |
| 1076 | private->uid.vendor, private->uid.serial, |
| 1077 | private->uid.ssid, rc, dev_name(&device->cdev->dev)); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1078 | /* RE-Read Configuration Data */ |
| 1079 | return dasd_eckd_read_conf(device); |
| 1080 | } |
| 1081 | |
| 1082 | /* |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1083 | * Check device characteristics. |
| 1084 | * If the device is accessible using ECKD discipline, the device is enabled. |
| 1085 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | static int |
| 1087 | dasd_eckd_check_characteristics(struct dasd_device *device) |
| 1088 | { |
| 1089 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1090 | struct dasd_block *block; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1091 | int is_known, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 1093 | if (!ccw_device_is_pathgroup(device->cdev)) { |
| 1094 | dev_warn(&device->cdev->dev, |
| 1095 | "A channel path group could not be established\n"); |
| 1096 | return -EIO; |
| 1097 | } |
| 1098 | if (!ccw_device_is_multipath(device->cdev)) { |
| 1099 | dev_info(&device->cdev->dev, |
| 1100 | "The DASD is not operating in multipath mode\n"); |
| 1101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | private = (struct dasd_eckd_private *) device->private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1103 | if (!private) { |
| 1104 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); |
| 1105 | if (!private) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1106 | dev_warn(&device->cdev->dev, |
| 1107 | "Allocating memory for private DASD data " |
| 1108 | "failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | return -ENOMEM; |
| 1110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | device->private = (void *) private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1112 | } else { |
| 1113 | memset(private, 0, sizeof(*private)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
| 1115 | /* Invalidate status of initial analysis. */ |
| 1116 | private->init_cqr_status = -1; |
| 1117 | /* Set default cache operations. */ |
| 1118 | private->attrib.operation = DASD_NORMAL_CACHE; |
| 1119 | private->attrib.nr_cyl = 0; |
| 1120 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1121 | /* Read Configuration Data */ |
| 1122 | rc = dasd_eckd_read_conf(device); |
| 1123 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1124 | goto out_err1; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1125 | |
| 1126 | /* Generate device unique id and register in devmap */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1127 | rc = dasd_eckd_generate_uid(device, &private->uid); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1128 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1129 | goto out_err1; |
| 1130 | dasd_set_uid(device->cdev, &private->uid); |
| 1131 | |
| 1132 | if (private->uid.type == UA_BASE_DEVICE) { |
| 1133 | block = dasd_alloc_block(); |
| 1134 | if (IS_ERR(block)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1135 | DBF_EVENT(DBF_WARNING, "could not allocate dasd " |
| 1136 | "block structure for device: %s", |
| 1137 | dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1138 | rc = PTR_ERR(block); |
| 1139 | goto out_err1; |
| 1140 | } |
| 1141 | device->block = block; |
| 1142 | block->base = device; |
| 1143 | } |
| 1144 | |
| 1145 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
| 1146 | is_known = dasd_alias_make_device_known_to_lcu(device); |
| 1147 | if (is_known < 0) { |
| 1148 | rc = is_known; |
| 1149 | goto out_err2; |
| 1150 | } |
| 1151 | if (!is_known) { |
| 1152 | /* new lcu found */ |
| 1153 | rc = dasd_eckd_validate_server(device); /* will switch pav on */ |
| 1154 | if (rc) |
| 1155 | goto out_err3; |
| 1156 | } |
| 1157 | |
| 1158 | /* Read Feature Codes */ |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 1159 | dasd_eckd_read_features(device); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1162 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
| 1163 | &private->rdc_data, 64); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1164 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1165 | DBF_EVENT(DBF_WARNING, |
| 1166 | "Read device characteristics failed, rc=%d for " |
| 1167 | "device: %s", rc, dev_name(&device->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1168 | goto out_err3; |
| 1169 | } |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1170 | /* find the vaild cylinder size */ |
| 1171 | if (private->rdc_data.no_cyl == LV_COMPAT_CYL && |
| 1172 | private->rdc_data.long_no_cyl) |
| 1173 | private->real_cyl = private->rdc_data.long_no_cyl; |
| 1174 | else |
| 1175 | private->real_cyl = private->rdc_data.no_cyl; |
| 1176 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1177 | dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " |
| 1178 | "with %d cylinders, %d heads, %d sectors\n", |
| 1179 | private->rdc_data.dev_type, |
| 1180 | private->rdc_data.dev_model, |
| 1181 | private->rdc_data.cu_type, |
| 1182 | private->rdc_data.cu_model.model, |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1183 | private->real_cyl, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1184 | private->rdc_data.trk_per_cyl, |
| 1185 | private->rdc_data.sec_per_trk); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1186 | return 0; |
| 1187 | |
| 1188 | out_err3: |
| 1189 | dasd_alias_disconnect_device_from_lcu(device); |
| 1190 | out_err2: |
| 1191 | dasd_free_block(device->block); |
| 1192 | device->block = NULL; |
| 1193 | out_err1: |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1194 | kfree(private->conf_data); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1195 | kfree(device->private); |
| 1196 | device->private = NULL; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1197 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1200 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
| 1201 | { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1202 | struct dasd_eckd_private *private; |
| 1203 | |
| 1204 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1205 | dasd_alias_disconnect_device_from_lcu(device); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1206 | private->ned = NULL; |
| 1207 | private->sneq = NULL; |
| 1208 | private->vdsneq = NULL; |
| 1209 | private->gneq = NULL; |
| 1210 | private->conf_len = 0; |
| 1211 | kfree(private->conf_data); |
| 1212 | private->conf_data = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1213 | } |
| 1214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | static struct dasd_ccw_req * |
| 1216 | dasd_eckd_analysis_ccw(struct dasd_device *device) |
| 1217 | { |
| 1218 | struct dasd_eckd_private *private; |
| 1219 | struct eckd_count *count_data; |
| 1220 | struct LO_eckd_data *LO_data; |
| 1221 | struct dasd_ccw_req *cqr; |
| 1222 | struct ccw1 *ccw; |
| 1223 | int cplength, datasize; |
| 1224 | int i; |
| 1225 | |
| 1226 | private = (struct dasd_eckd_private *) device->private; |
| 1227 | |
| 1228 | cplength = 8; |
| 1229 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1230 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | if (IS_ERR(cqr)) |
| 1232 | return cqr; |
| 1233 | ccw = cqr->cpaddr; |
| 1234 | /* Define extent for the first 3 tracks. */ |
| 1235 | define_extent(ccw++, cqr->data, 0, 2, |
| 1236 | DASD_ECKD_CCW_READ_COUNT, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1237 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | /* Locate record for the first 4 records on track 0. */ |
| 1239 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1240 | locate_record(ccw++, LO_data++, 0, 0, 4, |
| 1241 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1242 | |
| 1243 | count_data = private->count_area; |
| 1244 | for (i = 0; i < 4; i++) { |
| 1245 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1246 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1247 | ccw->flags = 0; |
| 1248 | ccw->count = 8; |
| 1249 | ccw->cda = (__u32)(addr_t) count_data; |
| 1250 | ccw++; |
| 1251 | count_data++; |
| 1252 | } |
| 1253 | |
| 1254 | /* Locate record for the first record on track 2. */ |
| 1255 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1256 | locate_record(ccw++, LO_data++, 2, 0, 1, |
| 1257 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1258 | /* Read count ccw. */ |
| 1259 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1260 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1261 | ccw->flags = 0; |
| 1262 | ccw->count = 8; |
| 1263 | ccw->cda = (__u32)(addr_t) count_data; |
| 1264 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1265 | cqr->block = NULL; |
| 1266 | cqr->startdev = device; |
| 1267 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | cqr->retries = 0; |
| 1269 | cqr->buildclk = get_clock(); |
| 1270 | cqr->status = DASD_CQR_FILLED; |
| 1271 | return cqr; |
| 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * This is the callback function for the init_analysis cqr. It saves |
| 1276 | * the status of the initial analysis ccw before it frees it and kicks |
| 1277 | * the device to continue the startup sequence. This will call |
| 1278 | * dasd_eckd_do_analysis again (if the devices has not been marked |
| 1279 | * for deletion in the meantime). |
| 1280 | */ |
| 1281 | static void |
| 1282 | dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data) |
| 1283 | { |
| 1284 | struct dasd_eckd_private *private; |
| 1285 | struct dasd_device *device; |
| 1286 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1287 | device = init_cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | private = (struct dasd_eckd_private *) device->private; |
| 1289 | private->init_cqr_status = init_cqr->status; |
| 1290 | dasd_sfree_request(init_cqr, device); |
| 1291 | dasd_kick_device(device); |
| 1292 | } |
| 1293 | |
| 1294 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1295 | dasd_eckd_start_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
| 1297 | struct dasd_eckd_private *private; |
| 1298 | struct dasd_ccw_req *init_cqr; |
| 1299 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1300 | private = (struct dasd_eckd_private *) block->base->private; |
| 1301 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | if (IS_ERR(init_cqr)) |
| 1303 | return PTR_ERR(init_cqr); |
| 1304 | init_cqr->callback = dasd_eckd_analysis_callback; |
| 1305 | init_cqr->callback_data = NULL; |
| 1306 | init_cqr->expires = 5*HZ; |
| 1307 | dasd_add_request_head(init_cqr); |
| 1308 | return -EAGAIN; |
| 1309 | } |
| 1310 | |
| 1311 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1312 | dasd_eckd_end_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1314 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | struct dasd_eckd_private *private; |
| 1316 | struct eckd_count *count_area; |
| 1317 | unsigned int sb, blk_per_trk; |
| 1318 | int status, i; |
| 1319 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1320 | device = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | private = (struct dasd_eckd_private *) device->private; |
| 1322 | status = private->init_cqr_status; |
| 1323 | private->init_cqr_status = -1; |
| 1324 | if (status != DASD_CQR_DONE) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1325 | dev_warn(&device->cdev->dev, |
| 1326 | "The DASD is not formatted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | return -EMEDIUMTYPE; |
| 1328 | } |
| 1329 | |
| 1330 | private->uses_cdl = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | /* Check Track 0 for Compatible Disk Layout */ |
| 1332 | count_area = NULL; |
| 1333 | for (i = 0; i < 3; i++) { |
| 1334 | if (private->count_area[i].kl != 4 || |
| 1335 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) { |
| 1336 | private->uses_cdl = 0; |
| 1337 | break; |
| 1338 | } |
| 1339 | } |
| 1340 | if (i == 3) |
| 1341 | count_area = &private->count_area[4]; |
| 1342 | |
| 1343 | if (private->uses_cdl == 0) { |
| 1344 | for (i = 0; i < 5; i++) { |
| 1345 | if ((private->count_area[i].kl != 0) || |
| 1346 | (private->count_area[i].dl != |
| 1347 | private->count_area[0].dl)) |
| 1348 | break; |
| 1349 | } |
| 1350 | if (i == 5) |
| 1351 | count_area = &private->count_area[0]; |
| 1352 | } else { |
| 1353 | if (private->count_area[3].record == 1) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1354 | dev_warn(&device->cdev->dev, |
| 1355 | "Track 0 has no records following the VTOC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | } |
| 1357 | if (count_area != NULL && count_area->kl == 0) { |
| 1358 | /* we found notthing violating our disk layout */ |
| 1359 | if (dasd_check_blocksize(count_area->dl) == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1360 | block->bp_block = count_area->dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1362 | if (block->bp_block == 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1363 | dev_warn(&device->cdev->dev, |
| 1364 | "The disk layout of the DASD is not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | return -EMEDIUMTYPE; |
| 1366 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1367 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 1368 | for (sb = 512; sb < block->bp_block; sb = sb << 1) |
| 1369 | block->s2b_shift++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1371 | 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] | 1372 | block->blocks = (private->real_cyl * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | private->rdc_data.trk_per_cyl * |
| 1374 | blk_per_trk); |
| 1375 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1376 | dev_info(&device->cdev->dev, |
| 1377 | "DASD with %d KB/block, %d KB total size, %d KB/track, " |
| 1378 | "%s\n", (block->bp_block >> 10), |
| 1379 | ((private->real_cyl * |
| 1380 | private->rdc_data.trk_per_cyl * |
| 1381 | blk_per_trk * (block->bp_block >> 9)) >> 1), |
| 1382 | ((blk_per_trk * block->bp_block) >> 10), |
| 1383 | private->uses_cdl ? |
| 1384 | "compatible disk layout" : "linux disk layout"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1389 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | { |
| 1391 | struct dasd_eckd_private *private; |
| 1392 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1393 | private = (struct dasd_eckd_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | if (private->init_cqr_status < 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1395 | return dasd_eckd_start_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1397 | return dasd_eckd_end_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1400 | static int dasd_eckd_ready_to_online(struct dasd_device *device) |
| 1401 | { |
| 1402 | return dasd_alias_add_device(device); |
| 1403 | }; |
| 1404 | |
| 1405 | static int dasd_eckd_online_to_ready(struct dasd_device *device) |
| 1406 | { |
| 1407 | return dasd_alias_remove_device(device); |
| 1408 | }; |
| 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1411 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | { |
| 1413 | struct dasd_eckd_private *private; |
| 1414 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1415 | private = (struct dasd_eckd_private *) block->base->private; |
| 1416 | if (dasd_check_blocksize(block->bp_block) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | geo->sectors = recs_per_track(&private->rdc_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1418 | 0, block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | } |
| 1420 | geo->cylinders = private->rdc_data.no_cyl; |
| 1421 | geo->heads = private->rdc_data.trk_per_cyl; |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static struct dasd_ccw_req * |
| 1426 | dasd_eckd_format_device(struct dasd_device * device, |
| 1427 | struct format_data_t * fdata) |
| 1428 | { |
| 1429 | struct dasd_eckd_private *private; |
| 1430 | struct dasd_ccw_req *fcp; |
| 1431 | struct eckd_count *ect; |
| 1432 | struct ccw1 *ccw; |
| 1433 | void *data; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1434 | int rpt; |
| 1435 | struct ch_t address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | int cplength, datasize; |
| 1437 | int i; |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1438 | int intensity = 0; |
| 1439 | int r0_perm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
| 1441 | private = (struct dasd_eckd_private *) device->private; |
| 1442 | rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1443 | set_ch_t(&address, |
| 1444 | fdata->start_unit / private->rdc_data.trk_per_cyl, |
| 1445 | fdata->start_unit % private->rdc_data.trk_per_cyl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | /* Sanity checks. */ |
| 1448 | if (fdata->start_unit >= |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1449 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1450 | dev_warn(&device->cdev->dev, "Start track number %d used in " |
| 1451 | "formatting is too big\n", fdata->start_unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | return ERR_PTR(-EINVAL); |
| 1453 | } |
| 1454 | if (fdata->start_unit > fdata->stop_unit) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1455 | dev_warn(&device->cdev->dev, "Start track %d used in " |
| 1456 | "formatting exceeds end track\n", fdata->start_unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | return ERR_PTR(-EINVAL); |
| 1458 | } |
| 1459 | if (dasd_check_blocksize(fdata->blksize) != 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1460 | dev_warn(&device->cdev->dev, |
| 1461 | "The DASD cannot be formatted with block size %d\n", |
| 1462 | fdata->blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | return ERR_PTR(-EINVAL); |
| 1464 | } |
| 1465 | |
| 1466 | /* |
| 1467 | * fdata->intensity is a bit string that tells us what to do: |
| 1468 | * Bit 0: write record zero |
| 1469 | * Bit 1: write home address, currently not supported |
| 1470 | * Bit 2: invalidate tracks |
| 1471 | * Bit 3: use OS/390 compatible disk layout (cdl) |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1472 | * Bit 4: do not allow storage subsystem to modify record zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | * Only some bit combinations do make sense. |
| 1474 | */ |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1475 | if (fdata->intensity & 0x10) { |
| 1476 | r0_perm = 0; |
| 1477 | intensity = fdata->intensity & ~0x10; |
| 1478 | } else { |
| 1479 | r0_perm = 1; |
| 1480 | intensity = fdata->intensity; |
| 1481 | } |
| 1482 | switch (intensity) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | case 0x00: /* Normal format */ |
| 1484 | case 0x08: /* Normal format, use cdl. */ |
| 1485 | cplength = 2 + rpt; |
| 1486 | datasize = sizeof(struct DE_eckd_data) + |
| 1487 | sizeof(struct LO_eckd_data) + |
| 1488 | rpt * sizeof(struct eckd_count); |
| 1489 | break; |
| 1490 | case 0x01: /* Write record zero and format track. */ |
| 1491 | case 0x09: /* Write record zero and format track, use cdl. */ |
| 1492 | cplength = 3 + rpt; |
| 1493 | datasize = sizeof(struct DE_eckd_data) + |
| 1494 | sizeof(struct LO_eckd_data) + |
| 1495 | sizeof(struct eckd_count) + |
| 1496 | rpt * sizeof(struct eckd_count); |
| 1497 | break; |
| 1498 | case 0x04: /* Invalidate track. */ |
| 1499 | case 0x0c: /* Invalidate track, use cdl. */ |
| 1500 | cplength = 3; |
| 1501 | datasize = sizeof(struct DE_eckd_data) + |
| 1502 | sizeof(struct LO_eckd_data) + |
| 1503 | sizeof(struct eckd_count); |
| 1504 | break; |
| 1505 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1506 | dev_warn(&device->cdev->dev, "An I/O control call used " |
| 1507 | "incorrect flags 0x%x\n", fdata->intensity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return ERR_PTR(-EINVAL); |
| 1509 | } |
| 1510 | /* Allocate the format ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1511 | fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | if (IS_ERR(fcp)) |
| 1513 | return fcp; |
| 1514 | |
| 1515 | data = fcp->data; |
| 1516 | ccw = fcp->cpaddr; |
| 1517 | |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1518 | switch (intensity & ~0x08) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | case 0x00: /* Normal format. */ |
| 1520 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1521 | fdata->start_unit, fdata->start_unit, |
| 1522 | DASD_ECKD_CCW_WRITE_CKD, device); |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1523 | /* grant subsystem permission to format R0 */ |
| 1524 | if (r0_perm) |
| 1525 | ((struct DE_eckd_data *)data)->ga_extended |= 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | data += sizeof(struct DE_eckd_data); |
| 1527 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1528 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1529 | fdata->start_unit, 0, rpt, |
| 1530 | DASD_ECKD_CCW_WRITE_CKD, device, |
| 1531 | fdata->blksize); |
| 1532 | data += sizeof(struct LO_eckd_data); |
| 1533 | break; |
| 1534 | case 0x01: /* Write record zero + format track. */ |
| 1535 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1536 | fdata->start_unit, fdata->start_unit, |
| 1537 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, |
| 1538 | device); |
| 1539 | data += sizeof(struct DE_eckd_data); |
| 1540 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1541 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1542 | fdata->start_unit, 0, rpt + 1, |
| 1543 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1544 | device->block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | data += sizeof(struct LO_eckd_data); |
| 1546 | break; |
| 1547 | case 0x04: /* Invalidate track. */ |
| 1548 | define_extent(ccw++, (struct DE_eckd_data *) data, |
| 1549 | fdata->start_unit, fdata->start_unit, |
| 1550 | DASD_ECKD_CCW_WRITE_CKD, device); |
| 1551 | data += sizeof(struct DE_eckd_data); |
| 1552 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1553 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 1554 | fdata->start_unit, 0, 1, |
| 1555 | DASD_ECKD_CCW_WRITE_CKD, device, 8); |
| 1556 | data += sizeof(struct LO_eckd_data); |
| 1557 | break; |
| 1558 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1559 | if (intensity & 0x01) { /* write record zero */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | ect = (struct eckd_count *) data; |
| 1561 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1562 | ect->cyl = address.cyl; |
| 1563 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | ect->record = 0; |
| 1565 | ect->kl = 0; |
| 1566 | ect->dl = 8; |
| 1567 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1568 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; |
| 1569 | ccw->flags = CCW_FLAG_SLI; |
| 1570 | ccw->count = 8; |
| 1571 | ccw->cda = (__u32)(addr_t) ect; |
| 1572 | ccw++; |
| 1573 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1574 | if ((intensity & ~0x08) & 0x04) { /* erase track */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | ect = (struct eckd_count *) data; |
| 1576 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1577 | ect->cyl = address.cyl; |
| 1578 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | ect->record = 1; |
| 1580 | ect->kl = 0; |
| 1581 | ect->dl = 0; |
| 1582 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1583 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1584 | ccw->flags = CCW_FLAG_SLI; |
| 1585 | ccw->count = 8; |
| 1586 | ccw->cda = (__u32)(addr_t) ect; |
| 1587 | } else { /* write remaining records */ |
| 1588 | for (i = 0; i < rpt; i++) { |
| 1589 | ect = (struct eckd_count *) data; |
| 1590 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1591 | ect->cyl = address.cyl; |
| 1592 | ect->head = address.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | ect->record = i + 1; |
| 1594 | ect->kl = 0; |
| 1595 | ect->dl = fdata->blksize; |
| 1596 | /* Check for special tracks 0-1 when formatting CDL */ |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1597 | if ((intensity & 0x08) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | fdata->start_unit == 0) { |
| 1599 | if (i < 3) { |
| 1600 | ect->kl = 4; |
| 1601 | ect->dl = sizes_trk0[i] - 4; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 1604 | if ((intensity & 0x08) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | fdata->start_unit == 1) { |
| 1606 | ect->kl = 44; |
| 1607 | ect->dl = LABEL_SIZE - 44; |
| 1608 | } |
| 1609 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1610 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 1611 | ccw->flags = CCW_FLAG_SLI; |
| 1612 | ccw->count = 8; |
| 1613 | ccw->cda = (__u32)(addr_t) ect; |
| 1614 | ccw++; |
| 1615 | } |
| 1616 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1617 | fcp->startdev = device; |
| 1618 | fcp->memdev = device; |
| 1619 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags); |
| 1620 | fcp->retries = 5; /* set retry counter to enable default ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | fcp->buildclk = get_clock(); |
| 1622 | fcp->status = DASD_CQR_FILLED; |
| 1623 | return fcp; |
| 1624 | } |
| 1625 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1626 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1628 | cqr->status = DASD_CQR_FILLED; |
| 1629 | if (cqr->block && (cqr->startdev != cqr->block->base)) { |
| 1630 | dasd_eckd_reset_ccw_to_base_io(cqr); |
| 1631 | cqr->startdev = cqr->block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1633 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
| 1635 | static dasd_erp_fn_t |
| 1636 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) |
| 1637 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1638 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | struct ccw_device *cdev = device->cdev; |
| 1640 | |
| 1641 | switch (cdev->id.cu_type) { |
| 1642 | case 0x3990: |
| 1643 | case 0x2105: |
| 1644 | case 0x2107: |
| 1645 | case 0x1750: |
| 1646 | return dasd_3990_erp_action; |
| 1647 | case 0x9343: |
| 1648 | case 0x3880: |
| 1649 | default: |
| 1650 | return dasd_default_erp_action; |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | static dasd_erp_fn_t |
| 1655 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) |
| 1656 | { |
| 1657 | return dasd_default_erp_postaction; |
| 1658 | } |
| 1659 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1660 | |
| 1661 | static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device, |
| 1662 | struct irb *irb) |
| 1663 | { |
| 1664 | char mask; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1665 | char *sense = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1666 | |
| 1667 | /* first of all check for state change pending interrupt */ |
| 1668 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1669 | if ((scsw_dstat(&irb->scsw) & mask) == mask) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1670 | dasd_generic_handle_state_change(device); |
| 1671 | return; |
| 1672 | } |
| 1673 | |
| 1674 | /* summary unit check */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1675 | if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1676 | (irb->ecw[7] == 0x0D)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1677 | dasd_alias_handle_summary_unit_check(device, irb); |
| 1678 | return; |
| 1679 | } |
| 1680 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1681 | sense = dasd_get_sense(irb); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1682 | /* service information message SIM */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1683 | if (sense && !(sense[27] & DASD_SENSE_BIT_0) && |
| 1684 | ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
| 1685 | dasd_3990_erp_handle_sim(device, sense); |
Stefan Haberland | 9d853ca | 2008-07-17 17:16:41 +0200 | [diff] [blame] | 1686 | dasd_schedule_device_bh(device); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 1687 | return; |
| 1688 | } |
| 1689 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1690 | if ((scsw_cc(&irb->scsw) == 1) && |
| 1691 | (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) && |
| 1692 | (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) && |
| 1693 | (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) { |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1694 | /* fake irb do nothing, they are handled elsewhere */ |
| 1695 | dasd_schedule_device_bh(device); |
| 1696 | return; |
| 1697 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1698 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1699 | if (!sense) { |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1700 | /* just report other unsolicited interrupts */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1701 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1702 | "unsolicited interrupt received"); |
| 1703 | } else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1704 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1705 | "unsolicited interrupt received " |
| 1706 | "(sense available)"); |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 1707 | device->discipline->dump_sense_dbf(device, irb, "unsolicited"); |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | dasd_schedule_device_bh(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1711 | return; |
| 1712 | }; |
| 1713 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1714 | |
| 1715 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( |
| 1716 | struct dasd_device *startdev, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1717 | struct dasd_block *block, |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1718 | struct request *req, |
| 1719 | sector_t first_rec, |
| 1720 | sector_t last_rec, |
| 1721 | sector_t first_trk, |
| 1722 | sector_t last_trk, |
| 1723 | unsigned int first_offs, |
| 1724 | unsigned int last_offs, |
| 1725 | unsigned int blk_per_trk, |
| 1726 | unsigned int blksize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | { |
| 1728 | struct dasd_eckd_private *private; |
| 1729 | unsigned long *idaws; |
| 1730 | struct LO_eckd_data *LO_data; |
| 1731 | struct dasd_ccw_req *cqr; |
| 1732 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1733 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | struct bio_vec *bv; |
| 1735 | char *dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1736 | unsigned int off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | int count, cidaw, cplength, datasize; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1738 | sector_t recid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | unsigned char cmd, rcmd; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1740 | int use_prefix; |
| 1741 | struct dasd_device *basedev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1743 | basedev = block->base; |
| 1744 | private = (struct dasd_eckd_private *) basedev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | if (rq_data_dir(req) == READ) |
| 1746 | cmd = DASD_ECKD_CCW_READ_MT; |
| 1747 | else if (rq_data_dir(req) == WRITE) |
| 1748 | cmd = DASD_ECKD_CCW_WRITE_MT; |
| 1749 | else |
| 1750 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | /* Check struct bio and count the number of blocks for the request. */ |
| 1753 | count = 0; |
| 1754 | cidaw = 0; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1755 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1756 | if (bv->bv_len & (blksize - 1)) |
| 1757 | /* Eckd can only do full blocks. */ |
| 1758 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1759 | count += bv->bv_len >> (block->s2b_shift + 9); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 1760 | #if defined(CONFIG_64BIT) |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 1761 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1762 | cidaw += bv->bv_len >> (block->s2b_shift + 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | } |
| 1765 | /* Paranoia. */ |
| 1766 | if (count != last_rec - first_rec + 1) |
| 1767 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1768 | |
| 1769 | /* use the prefix command if available */ |
| 1770 | use_prefix = private->features.feature[8] & 0x01; |
| 1771 | if (use_prefix) { |
| 1772 | /* 1x prefix + number of blocks */ |
| 1773 | cplength = 2 + count; |
| 1774 | /* 1x prefix + cidaws*sizeof(long) */ |
| 1775 | datasize = sizeof(struct PFX_eckd_data) + |
| 1776 | sizeof(struct LO_eckd_data) + |
| 1777 | cidaw * sizeof(unsigned long); |
| 1778 | } else { |
| 1779 | /* 1x define extent + 1x locate record + number of blocks */ |
| 1780 | cplength = 2 + count; |
| 1781 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ |
| 1782 | datasize = sizeof(struct DE_eckd_data) + |
| 1783 | sizeof(struct LO_eckd_data) + |
| 1784 | cidaw * sizeof(unsigned long); |
| 1785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | /* Find out the number of additional locate record ccws for cdl. */ |
| 1787 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { |
| 1788 | if (last_rec >= 2*blk_per_trk) |
| 1789 | count = 2*blk_per_trk - first_rec; |
| 1790 | cplength += count; |
| 1791 | datasize += count*sizeof(struct LO_eckd_data); |
| 1792 | } |
| 1793 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1794 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 1795 | startdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | if (IS_ERR(cqr)) |
| 1797 | return cqr; |
| 1798 | ccw = cqr->cpaddr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1799 | /* First ccw is define extent or prefix. */ |
| 1800 | if (use_prefix) { |
| 1801 | if (prefix(ccw++, cqr->data, first_trk, |
| 1802 | last_trk, cmd, basedev, startdev) == -EAGAIN) { |
| 1803 | /* Clock not in sync and XRC is enabled. |
| 1804 | * Try again later. |
| 1805 | */ |
| 1806 | dasd_sfree_request(cqr, startdev); |
| 1807 | return ERR_PTR(-EAGAIN); |
| 1808 | } |
| 1809 | idaws = (unsigned long *) (cqr->data + |
| 1810 | sizeof(struct PFX_eckd_data)); |
| 1811 | } else { |
| 1812 | if (define_extent(ccw++, cqr->data, first_trk, |
| 1813 | last_trk, cmd, startdev) == -EAGAIN) { |
| 1814 | /* Clock not in sync and XRC is enabled. |
| 1815 | * Try again later. |
| 1816 | */ |
| 1817 | dasd_sfree_request(cqr, startdev); |
| 1818 | return ERR_PTR(-EAGAIN); |
| 1819 | } |
| 1820 | idaws = (unsigned long *) (cqr->data + |
| 1821 | sizeof(struct DE_eckd_data)); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 1822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | /* Build locate_record+read/write/ccws. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
| 1825 | recid = first_rec; |
| 1826 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { |
| 1827 | /* Only standard blocks so there is just one locate record. */ |
| 1828 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1829 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1830 | last_rec - recid + 1, cmd, basedev, blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | } |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 1832 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1834 | if (dasd_page_cache) { |
| 1835 | char *copy = kmem_cache_alloc(dasd_page_cache, |
Christoph Lameter | 441e143 | 2006-12-06 20:33:19 -0800 | [diff] [blame] | 1836 | GFP_DMA | __GFP_NOWARN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | if (copy && rq_data_dir(req) == WRITE) |
| 1838 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); |
| 1839 | if (copy) |
| 1840 | dst = copy + bv->bv_offset; |
| 1841 | } |
| 1842 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 1843 | sector_t trkid = recid; |
| 1844 | unsigned int recoffs = sector_div(trkid, blk_per_trk); |
| 1845 | rcmd = cmd; |
| 1846 | count = blksize; |
| 1847 | /* Locate record for cdl special block ? */ |
| 1848 | if (private->uses_cdl && recid < 2*blk_per_trk) { |
| 1849 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ |
| 1850 | rcmd |= 0x8; |
| 1851 | count = dasd_eckd_cdl_reclen(recid); |
Horst Hummel | ec5883a | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1852 | if (count < blksize && |
| 1853 | rq_data_dir(req) == READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | memset(dst + count, 0xe5, |
| 1855 | blksize - count); |
| 1856 | } |
| 1857 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1858 | locate_record(ccw++, LO_data++, |
| 1859 | trkid, recoffs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1860 | 1, rcmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | /* Locate record for standard blocks ? */ |
| 1863 | if (private->uses_cdl && recid == 2*blk_per_trk) { |
| 1864 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1865 | locate_record(ccw++, LO_data++, |
| 1866 | trkid, recoffs + 1, |
| 1867 | last_rec - recid + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1868 | cmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | /* Read/write ccw. */ |
| 1871 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1872 | ccw->cmd_code = rcmd; |
| 1873 | ccw->count = count; |
| 1874 | if (idal_is_needed(dst, blksize)) { |
| 1875 | ccw->cda = (__u32)(addr_t) idaws; |
| 1876 | ccw->flags = CCW_FLAG_IDA; |
| 1877 | idaws = idal_create_words(idaws, dst, blksize); |
| 1878 | } else { |
| 1879 | ccw->cda = (__u32)(addr_t) dst; |
| 1880 | ccw->flags = 0; |
| 1881 | } |
| 1882 | ccw++; |
| 1883 | dst += blksize; |
| 1884 | recid++; |
| 1885 | } |
| 1886 | } |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 1887 | if (blk_noretry_request(req) || |
| 1888 | block->base->features & DASD_FEATURE_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1889 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1890 | cqr->startdev = startdev; |
| 1891 | cqr->memdev = startdev; |
| 1892 | cqr->block = block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 1894 | cqr->lpm = private->path_data.ppm; |
| 1895 | cqr->retries = 256; |
| 1896 | cqr->buildclk = get_clock(); |
| 1897 | cqr->status = DASD_CQR_FILLED; |
| 1898 | return cqr; |
| 1899 | } |
| 1900 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1901 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( |
| 1902 | struct dasd_device *startdev, |
| 1903 | struct dasd_block *block, |
| 1904 | struct request *req, |
| 1905 | sector_t first_rec, |
| 1906 | sector_t last_rec, |
| 1907 | sector_t first_trk, |
| 1908 | sector_t last_trk, |
| 1909 | unsigned int first_offs, |
| 1910 | unsigned int last_offs, |
| 1911 | unsigned int blk_per_trk, |
| 1912 | unsigned int blksize) |
| 1913 | { |
| 1914 | struct dasd_eckd_private *private; |
| 1915 | unsigned long *idaws; |
| 1916 | struct dasd_ccw_req *cqr; |
| 1917 | struct ccw1 *ccw; |
| 1918 | struct req_iterator iter; |
| 1919 | struct bio_vec *bv; |
| 1920 | char *dst, *idaw_dst; |
| 1921 | unsigned int cidaw, cplength, datasize; |
| 1922 | unsigned int tlf; |
| 1923 | sector_t recid; |
| 1924 | unsigned char cmd; |
| 1925 | struct dasd_device *basedev; |
| 1926 | unsigned int trkcount, count, count_to_trk_end; |
| 1927 | unsigned int idaw_len, seg_len, part_len, len_to_track_end; |
| 1928 | unsigned char new_track, end_idaw; |
| 1929 | sector_t trkid; |
| 1930 | unsigned int recoffs; |
| 1931 | |
| 1932 | basedev = block->base; |
| 1933 | private = (struct dasd_eckd_private *) basedev->private; |
| 1934 | if (rq_data_dir(req) == READ) |
| 1935 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 1936 | else if (rq_data_dir(req) == WRITE) |
| 1937 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 1938 | else |
| 1939 | return ERR_PTR(-EINVAL); |
| 1940 | |
| 1941 | /* Track based I/O needs IDAWs for each page, and not just for |
| 1942 | * 64 bit addresses. We need additional idals for pages |
| 1943 | * that get filled from two tracks, so we use the number |
| 1944 | * of records as upper limit. |
| 1945 | */ |
| 1946 | cidaw = last_rec - first_rec + 1; |
| 1947 | trkcount = last_trk - first_trk + 1; |
| 1948 | |
| 1949 | /* 1x prefix + one read/write ccw per track */ |
| 1950 | cplength = 1 + trkcount; |
| 1951 | |
| 1952 | /* on 31-bit we need space for two 32 bit addresses per page |
| 1953 | * on 64-bit one 64 bit address |
| 1954 | */ |
| 1955 | datasize = sizeof(struct PFX_eckd_data) + |
| 1956 | cidaw * sizeof(unsigned long long); |
| 1957 | |
| 1958 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1959 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 1960 | startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1961 | if (IS_ERR(cqr)) |
| 1962 | return cqr; |
| 1963 | ccw = cqr->cpaddr; |
| 1964 | /* transfer length factor: how many bytes to read from the last track */ |
| 1965 | if (first_trk == last_trk) |
| 1966 | tlf = last_offs - first_offs + 1; |
| 1967 | else |
| 1968 | tlf = last_offs + 1; |
| 1969 | tlf *= blksize; |
| 1970 | |
| 1971 | if (prefix_LRE(ccw++, cqr->data, first_trk, |
| 1972 | last_trk, cmd, basedev, startdev, |
| 1973 | 1 /* format */, first_offs + 1, |
| 1974 | trkcount, blksize, |
| 1975 | tlf) == -EAGAIN) { |
| 1976 | /* Clock not in sync and XRC is enabled. |
| 1977 | * Try again later. |
| 1978 | */ |
| 1979 | dasd_sfree_request(cqr, startdev); |
| 1980 | return ERR_PTR(-EAGAIN); |
| 1981 | } |
| 1982 | |
| 1983 | /* |
| 1984 | * The translation of request into ccw programs must meet the |
| 1985 | * following conditions: |
| 1986 | * - all idaws but the first and the last must address full pages |
| 1987 | * (or 2K blocks on 31-bit) |
| 1988 | * - the scope of a ccw and it's idal ends with the track boundaries |
| 1989 | */ |
| 1990 | idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); |
| 1991 | recid = first_rec; |
| 1992 | new_track = 1; |
| 1993 | end_idaw = 0; |
| 1994 | len_to_track_end = 0; |
| 1995 | idaw_dst = 0; |
| 1996 | idaw_len = 0; |
| 1997 | rq_for_each_segment(bv, req, iter) { |
| 1998 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 1999 | seg_len = bv->bv_len; |
| 2000 | while (seg_len) { |
| 2001 | if (new_track) { |
| 2002 | trkid = recid; |
| 2003 | recoffs = sector_div(trkid, blk_per_trk); |
| 2004 | count_to_trk_end = blk_per_trk - recoffs; |
| 2005 | count = min((last_rec - recid + 1), |
| 2006 | (sector_t)count_to_trk_end); |
| 2007 | len_to_track_end = count * blksize; |
| 2008 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2009 | ccw->cmd_code = cmd; |
| 2010 | ccw->count = len_to_track_end; |
| 2011 | ccw->cda = (__u32)(addr_t)idaws; |
| 2012 | ccw->flags = CCW_FLAG_IDA; |
| 2013 | ccw++; |
| 2014 | recid += count; |
| 2015 | new_track = 0; |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2016 | /* first idaw for a ccw may start anywhere */ |
| 2017 | if (!idaw_dst) |
| 2018 | idaw_dst = dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2019 | } |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2020 | /* If we start a new idaw, we must make sure that it |
| 2021 | * starts on an IDA_BLOCK_SIZE boundary. |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2022 | * If we continue an idaw, we must make sure that the |
| 2023 | * current segment begins where the so far accumulated |
| 2024 | * idaw ends |
| 2025 | */ |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2026 | if (!idaw_dst) { |
| 2027 | if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { |
| 2028 | dasd_sfree_request(cqr, startdev); |
| 2029 | return ERR_PTR(-ERANGE); |
| 2030 | } else |
| 2031 | idaw_dst = dst; |
| 2032 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2033 | if ((idaw_dst + idaw_len) != dst) { |
| 2034 | dasd_sfree_request(cqr, startdev); |
| 2035 | return ERR_PTR(-ERANGE); |
| 2036 | } |
| 2037 | part_len = min(seg_len, len_to_track_end); |
| 2038 | seg_len -= part_len; |
| 2039 | dst += part_len; |
| 2040 | idaw_len += part_len; |
| 2041 | len_to_track_end -= part_len; |
| 2042 | /* collected memory area ends on an IDA_BLOCK border, |
| 2043 | * -> create an idaw |
| 2044 | * idal_create_words will handle cases where idaw_len |
| 2045 | * is larger then IDA_BLOCK_SIZE |
| 2046 | */ |
| 2047 | if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) |
| 2048 | end_idaw = 1; |
| 2049 | /* We also need to end the idaw at track end */ |
| 2050 | if (!len_to_track_end) { |
| 2051 | new_track = 1; |
| 2052 | end_idaw = 1; |
| 2053 | } |
| 2054 | if (end_idaw) { |
| 2055 | idaws = idal_create_words(idaws, idaw_dst, |
| 2056 | idaw_len); |
| 2057 | idaw_dst = 0; |
| 2058 | idaw_len = 0; |
| 2059 | end_idaw = 0; |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | if (blk_noretry_request(req) || |
| 2065 | block->base->features & DASD_FEATURE_FAILFAST) |
| 2066 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 2067 | cqr->startdev = startdev; |
| 2068 | cqr->memdev = startdev; |
| 2069 | cqr->block = block; |
| 2070 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 2071 | cqr->lpm = private->path_data.ppm; |
| 2072 | cqr->retries = 256; |
| 2073 | cqr->buildclk = get_clock(); |
| 2074 | cqr->status = DASD_CQR_FILLED; |
| 2075 | return cqr; |
| 2076 | } |
| 2077 | |
| 2078 | static int prepare_itcw(struct itcw *itcw, |
| 2079 | unsigned int trk, unsigned int totrk, int cmd, |
| 2080 | struct dasd_device *basedev, |
| 2081 | struct dasd_device *startdev, |
| 2082 | unsigned int rec_on_trk, int count, |
| 2083 | unsigned int blksize, |
| 2084 | unsigned int total_data_size, |
| 2085 | unsigned int tlf, |
| 2086 | unsigned int blk_per_trk) |
| 2087 | { |
| 2088 | struct PFX_eckd_data pfxdata; |
| 2089 | struct dasd_eckd_private *basepriv, *startpriv; |
| 2090 | struct DE_eckd_data *dedata; |
| 2091 | struct LRE_eckd_data *lredata; |
| 2092 | struct dcw *dcw; |
| 2093 | |
| 2094 | u32 begcyl, endcyl; |
| 2095 | u16 heads, beghead, endhead; |
| 2096 | u8 pfx_cmd; |
| 2097 | |
| 2098 | int rc = 0; |
| 2099 | int sector = 0; |
| 2100 | int dn, d; |
| 2101 | |
| 2102 | |
| 2103 | /* setup prefix data */ |
| 2104 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 2105 | startpriv = (struct dasd_eckd_private *) startdev->private; |
| 2106 | dedata = &pfxdata.define_extent; |
| 2107 | lredata = &pfxdata.locate_record; |
| 2108 | |
| 2109 | memset(&pfxdata, 0, sizeof(pfxdata)); |
| 2110 | pfxdata.format = 1; /* PFX with LRE */ |
| 2111 | pfxdata.base_address = basepriv->ned->unit_addr; |
| 2112 | pfxdata.base_lss = basepriv->ned->ID; |
| 2113 | pfxdata.validity.define_extent = 1; |
| 2114 | |
| 2115 | /* private uid is kept up to date, conf_data may be outdated */ |
| 2116 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 2117 | pfxdata.validity.verify_base = 1; |
| 2118 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 2119 | pfxdata.validity.hyper_pav = 1; |
| 2120 | } |
| 2121 | |
| 2122 | switch (cmd) { |
| 2123 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 2124 | dedata->mask.perm = 0x1; |
| 2125 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2126 | dedata->blk_size = blksize; |
| 2127 | dedata->ga_extended |= 0x42; |
| 2128 | lredata->operation.orientation = 0x0; |
| 2129 | lredata->operation.operation = 0x0C; |
| 2130 | lredata->auxiliary.check_bytes = 0x01; |
| 2131 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; |
| 2132 | break; |
| 2133 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 2134 | dedata->mask.perm = 0x02; |
| 2135 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2136 | dedata->blk_size = blksize; |
| 2137 | rc = check_XRC_on_prefix(&pfxdata, basedev); |
| 2138 | dedata->ga_extended |= 0x42; |
| 2139 | lredata->operation.orientation = 0x0; |
| 2140 | lredata->operation.operation = 0x3F; |
| 2141 | lredata->extended_operation = 0x23; |
| 2142 | lredata->auxiliary.check_bytes = 0x2; |
| 2143 | pfx_cmd = DASD_ECKD_CCW_PFX; |
| 2144 | break; |
| 2145 | default: |
| 2146 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 2147 | "prepare itcw, unknown opcode 0x%x", cmd); |
| 2148 | BUG(); |
| 2149 | break; |
| 2150 | } |
| 2151 | if (rc) |
| 2152 | return rc; |
| 2153 | |
| 2154 | dedata->attributes.mode = 0x3; /* ECKD */ |
| 2155 | |
| 2156 | heads = basepriv->rdc_data.trk_per_cyl; |
| 2157 | begcyl = trk / heads; |
| 2158 | beghead = trk % heads; |
| 2159 | endcyl = totrk / heads; |
| 2160 | endhead = totrk % heads; |
| 2161 | |
| 2162 | /* check for sequential prestage - enhance cylinder range */ |
| 2163 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
| 2164 | dedata->attributes.operation == DASD_SEQ_ACCESS) { |
| 2165 | |
| 2166 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
| 2167 | endcyl += basepriv->attrib.nr_cyl; |
| 2168 | else |
| 2169 | endcyl = (basepriv->real_cyl - 1); |
| 2170 | } |
| 2171 | |
| 2172 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
| 2173 | set_ch_t(&dedata->end_ext, endcyl, endhead); |
| 2174 | |
| 2175 | dedata->ep_format = 0x20; /* records per track is valid */ |
| 2176 | dedata->ep_rec_per_track = blk_per_trk; |
| 2177 | |
| 2178 | if (rec_on_trk) { |
| 2179 | switch (basepriv->rdc_data.dev_type) { |
| 2180 | case 0x3390: |
| 2181 | dn = ceil_quot(blksize + 6, 232); |
| 2182 | d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); |
| 2183 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 2184 | break; |
| 2185 | case 0x3380: |
| 2186 | d = 7 + ceil_quot(blksize + 12, 32); |
| 2187 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 2188 | break; |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | lredata->auxiliary.length_valid = 1; |
| 2193 | lredata->auxiliary.length_scope = 1; |
| 2194 | lredata->auxiliary.imbedded_ccw_valid = 1; |
| 2195 | lredata->length = tlf; |
| 2196 | lredata->imbedded_ccw = cmd; |
| 2197 | lredata->count = count; |
| 2198 | lredata->sector = sector; |
| 2199 | set_ch_t(&lredata->seek_addr, begcyl, beghead); |
| 2200 | lredata->search_arg.cyl = lredata->seek_addr.cyl; |
| 2201 | lredata->search_arg.head = lredata->seek_addr.head; |
| 2202 | lredata->search_arg.record = rec_on_trk; |
| 2203 | |
| 2204 | dcw = itcw_add_dcw(itcw, pfx_cmd, 0, |
| 2205 | &pfxdata, sizeof(pfxdata), total_data_size); |
| 2206 | |
| 2207 | return rc; |
| 2208 | } |
| 2209 | |
| 2210 | static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( |
| 2211 | struct dasd_device *startdev, |
| 2212 | struct dasd_block *block, |
| 2213 | struct request *req, |
| 2214 | sector_t first_rec, |
| 2215 | sector_t last_rec, |
| 2216 | sector_t first_trk, |
| 2217 | sector_t last_trk, |
| 2218 | unsigned int first_offs, |
| 2219 | unsigned int last_offs, |
| 2220 | unsigned int blk_per_trk, |
| 2221 | unsigned int blksize) |
| 2222 | { |
| 2223 | struct dasd_eckd_private *private; |
| 2224 | struct dasd_ccw_req *cqr; |
| 2225 | struct req_iterator iter; |
| 2226 | struct bio_vec *bv; |
| 2227 | char *dst; |
| 2228 | unsigned int trkcount, ctidaw; |
| 2229 | unsigned char cmd; |
| 2230 | struct dasd_device *basedev; |
| 2231 | unsigned int tlf; |
| 2232 | struct itcw *itcw; |
| 2233 | struct tidaw *last_tidaw = NULL; |
| 2234 | int itcw_op; |
| 2235 | size_t itcw_size; |
| 2236 | |
| 2237 | basedev = block->base; |
| 2238 | private = (struct dasd_eckd_private *) basedev->private; |
| 2239 | if (rq_data_dir(req) == READ) { |
| 2240 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 2241 | itcw_op = ITCW_OP_READ; |
| 2242 | } else if (rq_data_dir(req) == WRITE) { |
| 2243 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 2244 | itcw_op = ITCW_OP_WRITE; |
| 2245 | } else |
| 2246 | return ERR_PTR(-EINVAL); |
| 2247 | |
| 2248 | /* trackbased I/O needs address all memory via TIDAWs, |
| 2249 | * not just for 64 bit addresses. This allows us to map |
| 2250 | * each segment directly to one tidaw. |
| 2251 | */ |
| 2252 | trkcount = last_trk - first_trk + 1; |
| 2253 | ctidaw = 0; |
| 2254 | rq_for_each_segment(bv, req, iter) { |
| 2255 | ++ctidaw; |
| 2256 | } |
| 2257 | |
| 2258 | /* Allocate the ccw request. */ |
| 2259 | itcw_size = itcw_calc_size(0, ctidaw, 0); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2260 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2261 | if (IS_ERR(cqr)) |
| 2262 | return cqr; |
| 2263 | |
| 2264 | cqr->cpmode = 1; |
| 2265 | cqr->startdev = startdev; |
| 2266 | cqr->memdev = startdev; |
| 2267 | cqr->block = block; |
| 2268 | cqr->expires = 100*HZ; |
| 2269 | cqr->buildclk = get_clock(); |
| 2270 | cqr->status = DASD_CQR_FILLED; |
| 2271 | cqr->retries = 10; |
| 2272 | |
| 2273 | /* transfer length factor: how many bytes to read from the last track */ |
| 2274 | if (first_trk == last_trk) |
| 2275 | tlf = last_offs - first_offs + 1; |
| 2276 | else |
| 2277 | tlf = last_offs + 1; |
| 2278 | tlf *= blksize; |
| 2279 | |
| 2280 | itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); |
| 2281 | cqr->cpaddr = itcw_get_tcw(itcw); |
| 2282 | |
| 2283 | if (prepare_itcw(itcw, first_trk, last_trk, |
| 2284 | cmd, basedev, startdev, |
| 2285 | first_offs + 1, |
| 2286 | trkcount, blksize, |
| 2287 | (last_rec - first_rec + 1) * blksize, |
| 2288 | tlf, blk_per_trk) == -EAGAIN) { |
| 2289 | /* Clock not in sync and XRC is enabled. |
| 2290 | * Try again later. |
| 2291 | */ |
| 2292 | dasd_sfree_request(cqr, startdev); |
| 2293 | return ERR_PTR(-EAGAIN); |
| 2294 | } |
| 2295 | |
| 2296 | /* |
| 2297 | * A tidaw can address 4k of memory, but must not cross page boundaries |
| 2298 | * We can let the block layer handle this by setting |
| 2299 | * blk_queue_segment_boundary to page boundaries and |
| 2300 | * blk_max_segment_size to page size when setting up the request queue. |
| 2301 | */ |
| 2302 | rq_for_each_segment(bv, req, iter) { |
| 2303 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2304 | last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len); |
| 2305 | if (IS_ERR(last_tidaw)) |
| 2306 | return (struct dasd_ccw_req *)last_tidaw; |
| 2307 | } |
| 2308 | |
| 2309 | last_tidaw->flags |= 0x80; |
| 2310 | itcw_finalize(itcw); |
| 2311 | |
| 2312 | if (blk_noretry_request(req) || |
| 2313 | block->base->features & DASD_FEATURE_FAILFAST) |
| 2314 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 2315 | cqr->startdev = startdev; |
| 2316 | cqr->memdev = startdev; |
| 2317 | cqr->block = block; |
| 2318 | cqr->expires = 5 * 60 * HZ; /* 5 minutes */ |
| 2319 | cqr->lpm = private->path_data.ppm; |
| 2320 | cqr->retries = 256; |
| 2321 | cqr->buildclk = get_clock(); |
| 2322 | cqr->status = DASD_CQR_FILLED; |
| 2323 | return cqr; |
| 2324 | } |
| 2325 | |
| 2326 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, |
| 2327 | struct dasd_block *block, |
| 2328 | struct request *req) |
| 2329 | { |
| 2330 | int tpm, cmdrtd, cmdwtd; |
| 2331 | int use_prefix; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2332 | #if defined(CONFIG_64BIT) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2333 | int fcx_in_css, fcx_in_gneq, fcx_in_features; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2334 | #endif |
| 2335 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2336 | struct dasd_device *basedev; |
| 2337 | sector_t first_rec, last_rec; |
| 2338 | sector_t first_trk, last_trk; |
| 2339 | unsigned int first_offs, last_offs; |
| 2340 | unsigned int blk_per_trk, blksize; |
| 2341 | int cdlspecial; |
| 2342 | struct dasd_ccw_req *cqr; |
| 2343 | |
| 2344 | basedev = block->base; |
| 2345 | private = (struct dasd_eckd_private *) basedev->private; |
| 2346 | |
| 2347 | /* Calculate number of blocks/records per track. */ |
| 2348 | blksize = block->bp_block; |
| 2349 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 2350 | if (blk_per_trk == 0) |
| 2351 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2352 | /* Calculate record id of first and last block. */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2353 | first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2354 | first_offs = sector_div(first_trk, blk_per_trk); |
| 2355 | last_rec = last_trk = |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2356 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2357 | last_offs = sector_div(last_trk, blk_per_trk); |
| 2358 | cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); |
| 2359 | |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2360 | /* is transport mode supported? */ |
| 2361 | #if defined(CONFIG_64BIT) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2362 | fcx_in_css = css_general_characteristics.fcx; |
| 2363 | fcx_in_gneq = private->gneq->reserved2[7] & 0x04; |
| 2364 | fcx_in_features = private->features.feature[40] & 0x80; |
| 2365 | tpm = fcx_in_css && fcx_in_gneq && fcx_in_features; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 2366 | #else |
| 2367 | tpm = 0; |
| 2368 | #endif |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2369 | |
| 2370 | /* is read track data and write track data in command mode supported? */ |
| 2371 | cmdrtd = private->features.feature[9] & 0x20; |
| 2372 | cmdwtd = private->features.feature[12] & 0x40; |
| 2373 | use_prefix = private->features.feature[8] & 0x01; |
| 2374 | |
| 2375 | cqr = NULL; |
| 2376 | if (cdlspecial || dasd_page_cache) { |
| 2377 | /* do nothing, just fall through to the cmd mode single case */ |
| 2378 | } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) { |
| 2379 | cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, |
| 2380 | first_rec, last_rec, |
| 2381 | first_trk, last_trk, |
| 2382 | first_offs, last_offs, |
| 2383 | blk_per_trk, blksize); |
| 2384 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) |
| 2385 | cqr = NULL; |
| 2386 | } else if (use_prefix && |
| 2387 | (((rq_data_dir(req) == READ) && cmdrtd) || |
| 2388 | ((rq_data_dir(req) == WRITE) && cmdwtd))) { |
| 2389 | cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, |
| 2390 | first_rec, last_rec, |
| 2391 | first_trk, last_trk, |
| 2392 | first_offs, last_offs, |
| 2393 | blk_per_trk, blksize); |
| 2394 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) |
| 2395 | cqr = NULL; |
| 2396 | } |
| 2397 | if (!cqr) |
| 2398 | cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, |
| 2399 | first_rec, last_rec, |
| 2400 | first_trk, last_trk, |
| 2401 | first_offs, last_offs, |
| 2402 | blk_per_trk, blksize); |
| 2403 | return cqr; |
| 2404 | } |
| 2405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | static int |
| 2407 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 2408 | { |
| 2409 | struct dasd_eckd_private *private; |
| 2410 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2411 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | struct bio_vec *bv; |
| 2413 | char *dst, *cda; |
| 2414 | unsigned int blksize, blk_per_trk, off; |
| 2415 | sector_t recid; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2416 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | |
| 2418 | if (!dasd_page_cache) |
| 2419 | goto out; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2420 | private = (struct dasd_eckd_private *) cqr->block->base->private; |
| 2421 | blksize = cqr->block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2423 | recid = blk_rq_pos(req) >> cqr->block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | ccw = cqr->cpaddr; |
| 2425 | /* Skip over define extent & locate record. */ |
| 2426 | ccw++; |
| 2427 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) |
| 2428 | ccw++; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2429 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2431 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 2432 | /* Skip locate record. */ |
| 2433 | if (private->uses_cdl && recid <= 2*blk_per_trk) |
| 2434 | ccw++; |
| 2435 | if (dst) { |
| 2436 | if (ccw->flags & CCW_FLAG_IDA) |
| 2437 | cda = *((char **)((addr_t) ccw->cda)); |
| 2438 | else |
| 2439 | cda = (char *)((addr_t) ccw->cda); |
| 2440 | if (dst != cda) { |
| 2441 | if (rq_data_dir(req) == READ) |
| 2442 | memcpy(dst, cda, bv->bv_len); |
| 2443 | kmem_cache_free(dasd_page_cache, |
| 2444 | (void *)((addr_t)cda & PAGE_MASK)); |
| 2445 | } |
| 2446 | dst = NULL; |
| 2447 | } |
| 2448 | ccw++; |
| 2449 | recid++; |
| 2450 | } |
| 2451 | } |
| 2452 | out: |
| 2453 | status = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2454 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | return status; |
| 2456 | } |
| 2457 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2458 | /* |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2459 | * 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] | 2460 | * |
| 2461 | * Note that this is not enough to restart the cqr! |
| 2462 | * Either reset cqr->startdev as well (summary unit check handling) |
| 2463 | * or restart via separate cqr (as in ERP handling). |
| 2464 | */ |
| 2465 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) |
| 2466 | { |
| 2467 | struct ccw1 *ccw; |
| 2468 | struct PFX_eckd_data *pfxdata; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2469 | struct tcw *tcw; |
| 2470 | struct tccb *tccb; |
| 2471 | struct dcw *dcw; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2472 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2473 | if (cqr->cpmode == 1) { |
| 2474 | tcw = cqr->cpaddr; |
| 2475 | tccb = tcw_get_tccb(tcw); |
| 2476 | dcw = (struct dcw *)&tccb->tca[0]; |
| 2477 | pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2478 | pfxdata->validity.verify_base = 0; |
| 2479 | pfxdata->validity.hyper_pav = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2480 | } else { |
| 2481 | ccw = cqr->cpaddr; |
| 2482 | pfxdata = cqr->data; |
| 2483 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { |
| 2484 | pfxdata->validity.verify_base = 0; |
| 2485 | pfxdata->validity.hyper_pav = 0; |
| 2486 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 |
| 2491 | |
| 2492 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, |
| 2493 | struct dasd_block *block, |
| 2494 | struct request *req) |
| 2495 | { |
| 2496 | struct dasd_eckd_private *private; |
| 2497 | struct dasd_device *startdev; |
| 2498 | unsigned long flags; |
| 2499 | struct dasd_ccw_req *cqr; |
| 2500 | |
| 2501 | startdev = dasd_alias_get_start_dev(base); |
| 2502 | if (!startdev) |
| 2503 | startdev = base; |
| 2504 | private = (struct dasd_eckd_private *) startdev->private; |
| 2505 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) |
| 2506 | return ERR_PTR(-EBUSY); |
| 2507 | |
| 2508 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); |
| 2509 | private->count++; |
| 2510 | cqr = dasd_eckd_build_cp(startdev, block, req); |
| 2511 | if (IS_ERR(cqr)) |
| 2512 | private->count--; |
| 2513 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); |
| 2514 | return cqr; |
| 2515 | } |
| 2516 | |
| 2517 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, |
| 2518 | struct request *req) |
| 2519 | { |
| 2520 | struct dasd_eckd_private *private; |
| 2521 | unsigned long flags; |
| 2522 | |
| 2523 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 2524 | private = (struct dasd_eckd_private *) cqr->memdev->private; |
| 2525 | private->count--; |
| 2526 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 2527 | return dasd_eckd_free_cp(cqr, req); |
| 2528 | } |
| 2529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | static int |
| 2531 | dasd_eckd_fill_info(struct dasd_device * device, |
| 2532 | struct dasd_information2_t * info) |
| 2533 | { |
| 2534 | struct dasd_eckd_private *private; |
| 2535 | |
| 2536 | private = (struct dasd_eckd_private *) device->private; |
| 2537 | info->label_block = 2; |
| 2538 | info->FBA_layout = private->uses_cdl ? 0 : 1; |
| 2539 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; |
| 2540 | info->characteristics_size = sizeof(struct dasd_eckd_characteristics); |
| 2541 | memcpy(info->characteristics, &private->rdc_data, |
| 2542 | sizeof(struct dasd_eckd_characteristics)); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 2543 | info->confdata_size = min((unsigned long)private->conf_len, |
| 2544 | sizeof(info->configuration_data)); |
| 2545 | memcpy(info->configuration_data, private->conf_data, |
| 2546 | info->confdata_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | return 0; |
| 2548 | } |
| 2549 | |
| 2550 | /* |
| 2551 | * SECTION: ioctl functions for eckd devices. |
| 2552 | */ |
| 2553 | |
| 2554 | /* |
| 2555 | * Release device ioctl. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2556 | * Buils a channel programm to releases a prior reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | * (see dasd_eckd_reserve) device. |
| 2558 | */ |
| 2559 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2560 | dasd_eckd_release(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | struct dasd_ccw_req *cqr; |
| 2563 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2564 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
| 2566 | if (!capable(CAP_SYS_ADMIN)) |
| 2567 | return -EACCES; |
| 2568 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2569 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2571 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | "Could not allocate initialization request"); |
| 2573 | return PTR_ERR(cqr); |
| 2574 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2575 | ccw = cqr->cpaddr; |
| 2576 | ccw->cmd_code = DASD_ECKD_CCW_RELEASE; |
| 2577 | ccw->flags |= CCW_FLAG_SLI; |
| 2578 | ccw->count = 32; |
| 2579 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2580 | cqr->startdev = device; |
| 2581 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2583 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2584 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | cqr->expires = 2 * HZ; |
| 2586 | cqr->buildclk = get_clock(); |
| 2587 | cqr->status = DASD_CQR_FILLED; |
| 2588 | |
| 2589 | rc = dasd_sleep_on_immediatly(cqr); |
| 2590 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2591 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | return rc; |
| 2593 | } |
| 2594 | |
| 2595 | /* |
| 2596 | * Reserve device ioctl. |
| 2597 | * Options are set to 'synchronous wait for interrupt' and |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2598 | * 'timeout the request'. This leads to a terminate IO if |
| 2599 | * the interrupt is outstanding for a certain time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | */ |
| 2601 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2602 | dasd_eckd_reserve(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | struct dasd_ccw_req *cqr; |
| 2605 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2606 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
| 2608 | if (!capable(CAP_SYS_ADMIN)) |
| 2609 | return -EACCES; |
| 2610 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2611 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2613 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | "Could not allocate initialization request"); |
| 2615 | return PTR_ERR(cqr); |
| 2616 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2617 | ccw = cqr->cpaddr; |
| 2618 | ccw->cmd_code = DASD_ECKD_CCW_RESERVE; |
| 2619 | ccw->flags |= CCW_FLAG_SLI; |
| 2620 | ccw->count = 32; |
| 2621 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2622 | cqr->startdev = device; |
| 2623 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2625 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2626 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | cqr->expires = 2 * HZ; |
| 2628 | cqr->buildclk = get_clock(); |
| 2629 | cqr->status = DASD_CQR_FILLED; |
| 2630 | |
| 2631 | rc = dasd_sleep_on_immediatly(cqr); |
| 2632 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2633 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | return rc; |
| 2635 | } |
| 2636 | |
| 2637 | /* |
| 2638 | * Steal lock ioctl - unconditional reserve device. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2639 | * Buils a channel programm to break a device's reservation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | * (unconditional reserve) |
| 2641 | */ |
| 2642 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2643 | dasd_eckd_steal_lock(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | struct dasd_ccw_req *cqr; |
| 2646 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2647 | struct ccw1 *ccw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
| 2649 | if (!capable(CAP_SYS_ADMIN)) |
| 2650 | return -EACCES; |
| 2651 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2652 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2654 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | "Could not allocate initialization request"); |
| 2656 | return PTR_ERR(cqr); |
| 2657 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2658 | ccw = cqr->cpaddr; |
| 2659 | ccw->cmd_code = DASD_ECKD_CCW_SLCK; |
| 2660 | ccw->flags |= CCW_FLAG_SLI; |
| 2661 | ccw->count = 32; |
| 2662 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2663 | cqr->startdev = device; |
| 2664 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2666 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 2667 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | cqr->expires = 2 * HZ; |
| 2669 | cqr->buildclk = get_clock(); |
| 2670 | cqr->status = DASD_CQR_FILLED; |
| 2671 | |
| 2672 | rc = dasd_sleep_on_immediatly(cqr); |
| 2673 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2674 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | return rc; |
| 2676 | } |
| 2677 | |
| 2678 | /* |
| 2679 | * Read performance statistics |
| 2680 | */ |
| 2681 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2682 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | struct dasd_psf_prssd_data *prssdp; |
| 2685 | struct dasd_rssd_perf_stats_t *stats; |
| 2686 | struct dasd_ccw_req *cqr; |
| 2687 | struct ccw1 *ccw; |
| 2688 | int rc; |
| 2689 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2690 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2691 | (sizeof(struct dasd_psf_prssd_data) + |
| 2692 | sizeof(struct dasd_rssd_perf_stats_t)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | device); |
| 2694 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2695 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | "Could not allocate initialization request"); |
| 2697 | return PTR_ERR(cqr); |
| 2698 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2699 | cqr->startdev = device; |
| 2700 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | cqr->retries = 0; |
| 2702 | cqr->expires = 10 * HZ; |
| 2703 | |
| 2704 | /* Prepare for Read Subsystem Data */ |
| 2705 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2706 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | prssdp->order = PSF_ORDER_PRSSD; |
Joe Perches | 5d67d16 | 2008-01-26 14:11:20 +0100 | [diff] [blame] | 2708 | prssdp->suborder = 0x01; /* Performance Statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
| 2710 | |
| 2711 | ccw = cqr->cpaddr; |
| 2712 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2713 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | ccw->flags |= CCW_FLAG_CC; |
| 2715 | ccw->cda = (__u32)(addr_t) prssdp; |
| 2716 | |
| 2717 | /* Read Subsystem Data - Performance Statistics */ |
| 2718 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2719 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | |
| 2721 | ccw++; |
| 2722 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2723 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | ccw->cda = (__u32)(addr_t) stats; |
| 2725 | |
| 2726 | cqr->buildclk = get_clock(); |
| 2727 | cqr->status = DASD_CQR_FILLED; |
| 2728 | rc = dasd_sleep_on(cqr); |
| 2729 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 2731 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2732 | if (copy_to_user(argp, stats, |
| 2733 | sizeof(struct dasd_rssd_perf_stats_t))) |
| 2734 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2736 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | return rc; |
| 2738 | } |
| 2739 | |
| 2740 | /* |
| 2741 | * Get attributes (cache operations) |
| 2742 | * Returnes the cache attributes used in Define Extend (DE). |
| 2743 | */ |
| 2744 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2745 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2747 | struct dasd_eckd_private *private = |
| 2748 | (struct dasd_eckd_private *)device->private; |
| 2749 | struct attrib_data_t attrib = private->attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | int rc; |
| 2751 | |
| 2752 | if (!capable(CAP_SYS_ADMIN)) |
| 2753 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2754 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | return -EINVAL; |
| 2756 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2757 | rc = 0; |
| 2758 | if (copy_to_user(argp, (long *) &attrib, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2759 | sizeof(struct attrib_data_t))) |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2760 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | |
| 2762 | return rc; |
| 2763 | } |
| 2764 | |
| 2765 | /* |
| 2766 | * Set attributes (cache operations) |
| 2767 | * Stores the attributes for cache operation to be used in Define Extend (DE). |
| 2768 | */ |
| 2769 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2770 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2772 | struct dasd_eckd_private *private = |
| 2773 | (struct dasd_eckd_private *)device->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | struct attrib_data_t attrib; |
| 2775 | |
| 2776 | if (!capable(CAP_SYS_ADMIN)) |
| 2777 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2778 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | return -EINVAL; |
| 2780 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2781 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | private->attrib = attrib; |
| 2784 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2785 | dev_info(&device->cdev->dev, |
| 2786 | "The DASD cache mode was set to %x (%i cylinder prestage)\n", |
| 2787 | private->attrib.operation, private->attrib.nr_cyl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | return 0; |
| 2789 | } |
| 2790 | |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2791 | /* |
| 2792 | * Issue syscall I/O to EMC Symmetrix array. |
| 2793 | * CCWs are PSF and RSSD |
| 2794 | */ |
| 2795 | static int dasd_symm_io(struct dasd_device *device, void __user *argp) |
| 2796 | { |
| 2797 | struct dasd_symmio_parms usrparm; |
| 2798 | char *psf_data, *rssd_result; |
| 2799 | struct dasd_ccw_req *cqr; |
| 2800 | struct ccw1 *ccw; |
| 2801 | int rc; |
| 2802 | |
| 2803 | /* Copy parms from caller */ |
| 2804 | rc = -EFAULT; |
| 2805 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) |
| 2806 | goto out; |
| 2807 | #ifndef CONFIG_64BIT |
| 2808 | /* Make sure pointers are sane even on 31 bit. */ |
| 2809 | if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) { |
| 2810 | rc = -EINVAL; |
| 2811 | goto out; |
| 2812 | } |
| 2813 | #endif |
| 2814 | /* alloc I/O data area */ |
| 2815 | psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); |
| 2816 | rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); |
| 2817 | if (!psf_data || !rssd_result) { |
| 2818 | rc = -ENOMEM; |
| 2819 | goto out_free; |
| 2820 | } |
| 2821 | |
| 2822 | /* get syscall header from user space */ |
| 2823 | rc = -EFAULT; |
| 2824 | if (copy_from_user(psf_data, |
| 2825 | (void __user *)(unsigned long) usrparm.psf_data, |
| 2826 | usrparm.psf_data_len)) |
| 2827 | goto out_free; |
| 2828 | |
| 2829 | /* sanity check on syscall header */ |
| 2830 | if (psf_data[0] != 0x17 && psf_data[1] != 0xce) { |
| 2831 | rc = -EINVAL; |
| 2832 | goto out_free; |
| 2833 | } |
| 2834 | |
| 2835 | /* setup CCWs for PSF + RSSD */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2836 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2837 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2838 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2839 | "Could not allocate initialization request"); |
| 2840 | rc = PTR_ERR(cqr); |
| 2841 | goto out_free; |
| 2842 | } |
| 2843 | |
| 2844 | cqr->startdev = device; |
| 2845 | cqr->memdev = device; |
| 2846 | cqr->retries = 3; |
| 2847 | cqr->expires = 10 * HZ; |
| 2848 | cqr->buildclk = get_clock(); |
| 2849 | cqr->status = DASD_CQR_FILLED; |
| 2850 | |
| 2851 | /* Build the ccws */ |
| 2852 | ccw = cqr->cpaddr; |
| 2853 | |
| 2854 | /* PSF ccw */ |
| 2855 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 2856 | ccw->count = usrparm.psf_data_len; |
| 2857 | ccw->flags |= CCW_FLAG_CC; |
| 2858 | ccw->cda = (__u32)(addr_t) psf_data; |
| 2859 | |
| 2860 | ccw++; |
| 2861 | |
| 2862 | /* RSSD ccw */ |
| 2863 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 2864 | ccw->count = usrparm.rssd_result_len; |
| 2865 | ccw->flags = CCW_FLAG_SLI ; |
| 2866 | ccw->cda = (__u32)(addr_t) rssd_result; |
| 2867 | |
| 2868 | rc = dasd_sleep_on(cqr); |
| 2869 | if (rc) |
| 2870 | goto out_sfree; |
| 2871 | |
| 2872 | rc = -EFAULT; |
| 2873 | if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, |
| 2874 | rssd_result, usrparm.rssd_result_len)) |
| 2875 | goto out_sfree; |
| 2876 | rc = 0; |
| 2877 | |
| 2878 | out_sfree: |
| 2879 | dasd_sfree_request(cqr, cqr->memdev); |
| 2880 | out_free: |
| 2881 | kfree(rssd_result); |
| 2882 | kfree(psf_data); |
| 2883 | out: |
| 2884 | DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc); |
| 2885 | return rc; |
| 2886 | } |
| 2887 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2888 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2889 | 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] | 2890 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2891 | struct dasd_device *device = block->base; |
| 2892 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2893 | switch (cmd) { |
| 2894 | case BIODASDGATTR: |
| 2895 | return dasd_eckd_get_attrib(device, argp); |
| 2896 | case BIODASDSATTR: |
| 2897 | return dasd_eckd_set_attrib(device, argp); |
| 2898 | case BIODASDPSRD: |
| 2899 | return dasd_eckd_performance(device, argp); |
| 2900 | case BIODASDRLSE: |
| 2901 | return dasd_eckd_release(device); |
| 2902 | case BIODASDRSRV: |
| 2903 | return dasd_eckd_reserve(device); |
| 2904 | case BIODASDSLCK: |
| 2905 | return dasd_eckd_steal_lock(device); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 2906 | case BIODASDSYMMIO: |
| 2907 | return dasd_symm_io(device, argp); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 2908 | default: |
| 2909 | return -ENOIOCTLCMD; |
| 2910 | } |
| 2911 | } |
| 2912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | /* |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2914 | * Dump the range of CCWs into 'page' buffer |
| 2915 | * and return number of printed chars. |
| 2916 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 2917 | static int |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2918 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
| 2919 | { |
| 2920 | int len, count; |
| 2921 | char *datap; |
| 2922 | |
| 2923 | len = 0; |
| 2924 | while (from <= to) { |
| 2925 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2926 | " CCW %p: %08X %08X DAT:", |
| 2927 | from, ((int *) from)[0], ((int *) from)[1]); |
| 2928 | |
| 2929 | /* get pointer to data (consider IDALs) */ |
| 2930 | if (from->flags & CCW_FLAG_IDA) |
| 2931 | datap = (char *) *((addr_t *) (addr_t) from->cda); |
| 2932 | else |
| 2933 | datap = (char *) ((addr_t) from->cda); |
| 2934 | |
| 2935 | /* dump data (max 32 bytes) */ |
| 2936 | for (count = 0; count < from->count && count < 32; count++) { |
| 2937 | if (count % 8 == 0) len += sprintf(page + len, " "); |
| 2938 | if (count % 4 == 0) len += sprintf(page + len, " "); |
| 2939 | len += sprintf(page + len, "%02x", datap[count]); |
| 2940 | } |
| 2941 | len += sprintf(page + len, "\n"); |
| 2942 | from++; |
| 2943 | } |
| 2944 | return len; |
| 2945 | } |
| 2946 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2947 | static void |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2948 | dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
| 2949 | char *reason) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2950 | { |
| 2951 | u64 *sense; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2952 | |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2953 | sense = (u64 *) dasd_get_sense(irb); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2954 | if (sense) { |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 2955 | DBF_DEV_EVENT(DBF_EMERG, device, |
| 2956 | "%s: %s %02x%02x%02x %016llx %016llx %016llx " |
| 2957 | "%016llx", reason, |
| 2958 | scsw_is_tm(&irb->scsw) ? "t" : "c", |
| 2959 | scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw), |
| 2960 | scsw_dstat(&irb->scsw), sense[0], sense[1], |
| 2961 | sense[2], sense[3]); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2962 | } else { |
| 2963 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", |
| 2964 | "SORRY - NO VALID SENSE AVAILABLE\n"); |
| 2965 | } |
| 2966 | } |
| 2967 | |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2968 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | * Print sense data and related channel program. |
| 2970 | * Parts are printed because printk buffer is only 1024 bytes. |
| 2971 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2972 | static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2973 | struct dasd_ccw_req *req, struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | { |
| 2975 | char *page; |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2976 | struct ccw1 *first, *last, *fail, *from, *to; |
| 2977 | int len, sl, sct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | |
| 2979 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 2980 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2981 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 2982 | "No memory to dump sense data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | return; |
| 2984 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 2985 | /* dump the sense data */ |
| 2986 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | " I/O status report for device %s:\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2988 | dev_name(&device->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 2990 | " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d\n", |
| 2991 | req, scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw), |
| 2992 | scsw_cc(&irb->scsw), req->intrc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 2994 | " device %s: Failing CCW: %p\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2995 | dev_name(&device->cdev->dev), |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 2996 | (void *) (addr_t) irb->scsw.cmd.cpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | if (irb->esw.esw0.erw.cons) { |
| 2998 | for (sl = 0; sl < 4; sl++) { |
| 2999 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3000 | " Sense(hex) %2d-%2d:", |
| 3001 | (8 * sl), ((8 * sl) + 7)); |
| 3002 | |
| 3003 | for (sct = 0; sct < 8; sct++) { |
| 3004 | len += sprintf(page + len, " %02x", |
| 3005 | irb->ecw[8 * sl + sct]); |
| 3006 | } |
| 3007 | len += sprintf(page + len, "\n"); |
| 3008 | } |
| 3009 | |
| 3010 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { |
| 3011 | /* 24 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3012 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3013 | " 24 Byte: %x MSG %x, " |
| 3014 | "%s MSGb to SYSOP\n", |
| 3015 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, |
| 3016 | irb->ecw[1] & 0x10 ? "" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | } else { |
| 3018 | /* 32 Byte Sense Data */ |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3019 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3020 | " 32 Byte: Format: %x " |
| 3021 | "Exception class %x\n", |
| 3022 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | } |
| 3024 | } else { |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3025 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3026 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3028 | printk("%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3030 | if (req) { |
| 3031 | /* req == NULL for unsolicited interrupts */ |
| 3032 | /* dump the Channel Program (max 140 Bytes per line) */ |
| 3033 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ |
| 3034 | first = req->cpaddr; |
| 3035 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); |
| 3036 | to = min(first + 6, last); |
| 3037 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 3038 | " Related CP in req: %p\n", req); |
| 3039 | dasd_eckd_dump_ccw_range(first, to, page + len); |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 3040 | printk("%s", page); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3041 | |
| 3042 | /* print failing CCW area (maximum 4) */ |
| 3043 | /* scsw->cda is either valid or zero */ |
| 3044 | len = 0; |
| 3045 | from = ++to; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 3046 | fail = (struct ccw1 *)(addr_t) |
| 3047 | irb->scsw.cmd.cpa; /* failing CCW */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3048 | if (from < fail - 2) { |
| 3049 | from = fail - 2; /* there is a gap - print header */ |
| 3050 | len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n"); |
| 3051 | } |
| 3052 | to = min(fail + 1, last); |
| 3053 | len += dasd_eckd_dump_ccw_range(from, to, page + len); |
| 3054 | |
| 3055 | /* print last CCWs (maximum 2) */ |
| 3056 | from = max(from, ++to); |
| 3057 | if (from < last - 1) { |
| 3058 | from = last - 1; /* there is a gap - print header */ |
| 3059 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); |
| 3060 | } |
| 3061 | len += dasd_eckd_dump_ccw_range(from, last, page + len); |
| 3062 | if (len > 0) |
| 3063 | printk("%s", page); |
| 3064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | free_page((unsigned long) page); |
| 3066 | } |
| 3067 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3068 | |
| 3069 | /* |
| 3070 | * Print sense data from a tcw. |
| 3071 | */ |
| 3072 | static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, |
| 3073 | struct dasd_ccw_req *req, struct irb *irb) |
| 3074 | { |
| 3075 | char *page; |
| 3076 | int len, sl, sct, residual; |
| 3077 | |
| 3078 | struct tsb *tsb; |
| 3079 | u8 *sense; |
| 3080 | |
| 3081 | |
| 3082 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 3083 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3084 | DBF_DEV_EVENT(DBF_WARNING, device, " %s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3085 | "No memory to dump sense data"); |
| 3086 | return; |
| 3087 | } |
| 3088 | /* dump the sense data */ |
| 3089 | len = sprintf(page, KERN_ERR PRINTK_HEADER |
| 3090 | " I/O status report for device %s:\n", |
| 3091 | dev_name(&device->cdev->dev)); |
| 3092 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 3093 | " 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] | 3094 | "fcxs: 0x%02X schxs: 0x%02X\n", req, |
| 3095 | scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw), |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 3096 | scsw_cc(&irb->scsw), req->intrc, |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3097 | irb->scsw.tm.fcxs, irb->scsw.tm.schxs); |
| 3098 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3099 | " device %s: Failing TCW: %p\n", |
| 3100 | dev_name(&device->cdev->dev), |
| 3101 | (void *) (addr_t) irb->scsw.tm.tcw); |
| 3102 | |
| 3103 | tsb = NULL; |
| 3104 | sense = NULL; |
| 3105 | if (irb->scsw.tm.tcw) |
| 3106 | tsb = tcw_get_tsb( |
| 3107 | (struct tcw *)(unsigned long)irb->scsw.tm.tcw); |
| 3108 | |
| 3109 | if (tsb && (irb->scsw.tm.fcxs == 0x01)) { |
| 3110 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3111 | " tsb->length %d\n", tsb->length); |
| 3112 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3113 | " tsb->flags %x\n", tsb->flags); |
| 3114 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3115 | " tsb->dcw_offset %d\n", tsb->dcw_offset); |
| 3116 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3117 | " tsb->count %d\n", tsb->count); |
| 3118 | residual = tsb->count - 28; |
| 3119 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3120 | " residual %d\n", residual); |
| 3121 | |
| 3122 | switch (tsb->flags & 0x07) { |
| 3123 | case 1: /* tsa_iostat */ |
| 3124 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3125 | " tsb->tsa.iostat.dev_time %d\n", |
| 3126 | tsb->tsa.iostat.dev_time); |
| 3127 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3128 | " tsb->tsa.iostat.def_time %d\n", |
| 3129 | tsb->tsa.iostat.def_time); |
| 3130 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3131 | " tsb->tsa.iostat.queue_time %d\n", |
| 3132 | tsb->tsa.iostat.queue_time); |
| 3133 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3134 | " tsb->tsa.iostat.dev_busy_time %d\n", |
| 3135 | tsb->tsa.iostat.dev_busy_time); |
| 3136 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3137 | " tsb->tsa.iostat.dev_act_time %d\n", |
| 3138 | tsb->tsa.iostat.dev_act_time); |
| 3139 | sense = tsb->tsa.iostat.sense; |
| 3140 | break; |
| 3141 | case 2: /* ts_ddpc */ |
| 3142 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3143 | " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); |
| 3144 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3145 | " tsb->tsa.ddpc.rcq: "); |
| 3146 | for (sl = 0; sl < 16; sl++) { |
| 3147 | for (sct = 0; sct < 8; sct++) { |
| 3148 | len += sprintf(page + len, " %02x", |
| 3149 | tsb->tsa.ddpc.rcq[sl]); |
| 3150 | } |
| 3151 | len += sprintf(page + len, "\n"); |
| 3152 | } |
| 3153 | sense = tsb->tsa.ddpc.sense; |
| 3154 | break; |
| 3155 | case 3: /* tsa_intrg */ |
| 3156 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3157 | " tsb->tsa.intrg.: not supportet yet \n"); |
| 3158 | break; |
| 3159 | } |
| 3160 | |
| 3161 | if (sense) { |
| 3162 | for (sl = 0; sl < 4; sl++) { |
| 3163 | len += sprintf(page + len, |
| 3164 | KERN_ERR PRINTK_HEADER |
| 3165 | " Sense(hex) %2d-%2d:", |
| 3166 | (8 * sl), ((8 * sl) + 7)); |
| 3167 | for (sct = 0; sct < 8; sct++) { |
| 3168 | len += sprintf(page + len, " %02x", |
| 3169 | sense[8 * sl + sct]); |
| 3170 | } |
| 3171 | len += sprintf(page + len, "\n"); |
| 3172 | } |
| 3173 | |
| 3174 | if (sense[27] & DASD_SENSE_BIT_0) { |
| 3175 | /* 24 Byte Sense Data */ |
| 3176 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3177 | " 24 Byte: %x MSG %x, " |
| 3178 | "%s MSGb to SYSOP\n", |
| 3179 | sense[7] >> 4, sense[7] & 0x0f, |
| 3180 | sense[1] & 0x10 ? "" : "no"); |
| 3181 | } else { |
| 3182 | /* 32 Byte Sense Data */ |
| 3183 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3184 | " 32 Byte: Format: %x " |
| 3185 | "Exception class %x\n", |
| 3186 | sense[6] & 0x0f, sense[22] >> 4); |
| 3187 | } |
| 3188 | } else { |
| 3189 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3190 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
| 3191 | } |
| 3192 | } else { |
| 3193 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
| 3194 | " SORRY - NO TSB DATA AVAILABLE\n"); |
| 3195 | } |
| 3196 | printk("%s", page); |
| 3197 | free_page((unsigned long) page); |
| 3198 | } |
| 3199 | |
| 3200 | static void dasd_eckd_dump_sense(struct dasd_device *device, |
| 3201 | struct dasd_ccw_req *req, struct irb *irb) |
| 3202 | { |
| 3203 | if (req && scsw_is_tm(&req->irb.scsw)) |
| 3204 | dasd_eckd_dump_sense_tcw(device, req, irb); |
| 3205 | else |
| 3206 | dasd_eckd_dump_sense_ccw(device, req, irb); |
| 3207 | } |
| 3208 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3209 | int dasd_eckd_pm_freeze(struct dasd_device *device) |
| 3210 | { |
| 3211 | /* |
| 3212 | * the device should be disconnected from our LCU structure |
| 3213 | * on restore we will reconnect it and reread LCU specific |
| 3214 | * information like PAV support that might have changed |
| 3215 | */ |
| 3216 | dasd_alias_remove_device(device); |
| 3217 | dasd_alias_disconnect_device_from_lcu(device); |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
| 3222 | int dasd_eckd_restore_device(struct dasd_device *device) |
| 3223 | { |
| 3224 | struct dasd_eckd_private *private; |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 3225 | struct dasd_eckd_characteristics temp_rdc_data; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3226 | int is_known, rc; |
| 3227 | struct dasd_uid temp_uid; |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 3228 | unsigned long flags; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3229 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3230 | private = (struct dasd_eckd_private *) device->private; |
| 3231 | |
| 3232 | /* Read Configuration Data */ |
| 3233 | rc = dasd_eckd_read_conf(device); |
| 3234 | if (rc) |
| 3235 | goto out_err; |
| 3236 | |
| 3237 | /* Generate device unique id and register in devmap */ |
| 3238 | rc = dasd_eckd_generate_uid(device, &private->uid); |
| 3239 | dasd_get_uid(device->cdev, &temp_uid); |
| 3240 | if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 3241 | dev_err(&device->cdev->dev, "The UID of the DASD has " |
| 3242 | "changed\n"); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3243 | if (rc) |
| 3244 | goto out_err; |
| 3245 | dasd_set_uid(device->cdev, &private->uid); |
| 3246 | |
| 3247 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
| 3248 | is_known = dasd_alias_make_device_known_to_lcu(device); |
| 3249 | if (is_known < 0) |
| 3250 | return is_known; |
| 3251 | if (!is_known) { |
| 3252 | /* new lcu found */ |
| 3253 | rc = dasd_eckd_validate_server(device); /* will switch pav on */ |
| 3254 | if (rc) |
| 3255 | goto out_err; |
| 3256 | } |
| 3257 | |
| 3258 | /* Read Feature Codes */ |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 3259 | dasd_eckd_read_features(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3260 | |
| 3261 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3262 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 3263 | &temp_rdc_data, 64); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3264 | if (rc) { |
| 3265 | DBF_EVENT(DBF_WARNING, |
| 3266 | "Read device characteristics failed, rc=%d for " |
| 3267 | "device: %s", rc, dev_name(&device->cdev->dev)); |
| 3268 | goto out_err; |
| 3269 | } |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 3270 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 3271 | memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data)); |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 3272 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3273 | |
| 3274 | /* add device to alias management */ |
| 3275 | dasd_alias_add_device(device); |
| 3276 | |
| 3277 | return 0; |
| 3278 | |
| 3279 | out_err: |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 3280 | return -1; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | static struct ccw_driver dasd_eckd_driver = { |
| 3284 | .name = "dasd-eckd", |
| 3285 | .owner = THIS_MODULE, |
| 3286 | .ids = dasd_eckd_ids, |
| 3287 | .probe = dasd_eckd_probe, |
| 3288 | .remove = dasd_generic_remove, |
| 3289 | .set_offline = dasd_generic_set_offline, |
| 3290 | .set_online = dasd_eckd_set_online, |
| 3291 | .notify = dasd_generic_notify, |
| 3292 | .freeze = dasd_generic_pm_freeze, |
| 3293 | .thaw = dasd_generic_restore_device, |
| 3294 | .restore = dasd_generic_restore_device, |
| 3295 | }; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | /* |
| 3298 | * max_blocks is dependent on the amount of storage that is available |
| 3299 | * in the static io buffer for each device. Currently each device has |
| 3300 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has |
| 3301 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use |
| 3302 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In |
| 3303 | * addition we have one define extent ccw + 16 bytes of data and one |
| 3304 | * locate record ccw + 16 bytes of data. That makes: |
| 3305 | * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. |
| 3306 | * We want to fit two into the available memory so that we can immediately |
| 3307 | * start the next request if one finishes off. That makes 249.5 blocks |
| 3308 | * for one request. Give a little safety and the result is 240. |
| 3309 | */ |
| 3310 | static struct dasd_discipline dasd_eckd_discipline = { |
| 3311 | .owner = THIS_MODULE, |
| 3312 | .name = "ECKD", |
| 3313 | .ebcname = "ECKD", |
| 3314 | .max_blocks = 240, |
| 3315 | .check_device = dasd_eckd_check_characteristics, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3316 | .uncheck_device = dasd_eckd_uncheck_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | .do_analysis = dasd_eckd_do_analysis, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3318 | .ready_to_online = dasd_eckd_ready_to_online, |
| 3319 | .online_to_ready = dasd_eckd_online_to_ready, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | .fill_geometry = dasd_eckd_fill_geometry, |
| 3321 | .start_IO = dasd_start_IO, |
| 3322 | .term_IO = dasd_term_IO, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3323 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | .format_device = dasd_eckd_format_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | .erp_action = dasd_eckd_erp_action, |
| 3326 | .erp_postaction = dasd_eckd_erp_postaction, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3327 | .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt, |
| 3328 | .build_cp = dasd_eckd_build_alias_cp, |
| 3329 | .free_cp = dasd_eckd_free_alias_cp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | .dump_sense = dasd_eckd_dump_sense, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3331 | .dump_sense_dbf = dasd_eckd_dump_sense_dbf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | .fill_info = dasd_eckd_fill_info, |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3333 | .ioctl = dasd_eckd_ioctl, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 3334 | .freeze = dasd_eckd_pm_freeze, |
| 3335 | .restore = dasd_eckd_restore_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | }; |
| 3337 | |
| 3338 | static int __init |
| 3339 | dasd_eckd_init(void) |
| 3340 | { |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 3341 | int ret; |
| 3342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 3344 | ret = ccw_driver_register(&dasd_eckd_driver); |
| 3345 | if (!ret) |
| 3346 | wait_for_device_probe(); |
| 3347 | |
| 3348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | static void __exit |
| 3352 | dasd_eckd_cleanup(void) |
| 3353 | { |
| 3354 | ccw_driver_unregister(&dasd_eckd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | module_init(dasd_eckd_init); |
| 3358 | module_exit(dasd_eckd_cleanup); |