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