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 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 3 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Carsten Otte <Cotte@de.ibm.com> |
| 5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 6 | * Bugreports.to..: <Linux390@de.ibm.com> |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 7 | * Copyright IBM Corp. 1999, 2009 |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 8 | * EMC Symmetrix ioctl Copyright EMC Corporation, 2008 |
| 9 | * Author.........: Nigel Hislop <hislop_nigel@emc.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 12 | #define KMSG_COMPONENT "dasd-eckd" |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/stddef.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/hdreg.h> /* HDIO_GETGEO */ |
| 18 | #include <linux/bio.h> |
| 19 | #include <linux/module.h> |
Heiko Carstens | 048cd4e | 2012-02-27 10:01:52 +0100 | [diff] [blame] | 20 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | |
Sebastian Ott | 382b736 | 2012-08-28 16:43:36 +0200 | [diff] [blame] | 23 | #include <asm/css_chars.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/debug.h> |
| 25 | #include <asm/idals.h> |
| 26 | #include <asm/ebcdic.h> |
| 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" |
| 35 | |
| 36 | #ifdef PRINTK_HEADER |
| 37 | #undef PRINTK_HEADER |
| 38 | #endif /* PRINTK_HEADER */ |
| 39 | #define PRINTK_HEADER "dasd(eckd):" |
| 40 | |
| 41 | #define ECKD_C0(i) (i->home_bytes) |
| 42 | #define ECKD_F(i) (i->formula) |
| 43 | #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\ |
| 44 | (i->factors.f_0x02.f1)) |
| 45 | #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\ |
| 46 | (i->factors.f_0x02.f2)) |
| 47 | #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\ |
| 48 | (i->factors.f_0x02.f3)) |
| 49 | #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0) |
| 50 | #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0) |
| 51 | #define ECKD_F6(i) (i->factor6) |
| 52 | #define ECKD_F7(i) (i->factor7) |
| 53 | #define ECKD_F8(i) (i->factor8) |
| 54 | |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 55 | /* |
| 56 | * raw track access always map to 64k in memory |
| 57 | * so it maps to 16 blocks of 4k per track |
| 58 | */ |
| 59 | #define DASD_RAW_BLOCK_PER_TRACK 16 |
| 60 | #define DASD_RAW_BLOCKSIZE 4096 |
| 61 | /* 64k are 128 x 512 byte sectors */ |
| 62 | #define DASD_RAW_SECTORS_PER_TRACK 128 |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | MODULE_LICENSE("GPL"); |
| 65 | |
| 66 | static struct dasd_discipline dasd_eckd_discipline; |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* The ccw bus type uses this table to find devices that it sends to |
| 69 | * dasd_eckd_probe */ |
| 70 | static struct ccw_device_id dasd_eckd_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 71 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
| 72 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, |
Stefan Haberland | 5da24b7 | 2011-02-17 13:13:55 +0100 | [diff] [blame] | 73 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3}, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 74 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
| 75 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, |
| 76 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, |
| 77 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, |
| 78 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, |
| 79 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, |
| 80 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { /* end of list */ }, |
| 82 | }; |
| 83 | |
| 84 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); |
| 85 | |
| 86 | static struct ccw_driver dasd_eckd_driver; /* see below */ |
| 87 | |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 88 | static void *rawpadpage; |
| 89 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 90 | #define INIT_CQR_OK 0 |
| 91 | #define INIT_CQR_UNFORMATTED 1 |
| 92 | #define INIT_CQR_ERROR 2 |
| 93 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 94 | /* emergency request for reserve/release */ |
| 95 | static struct { |
| 96 | struct dasd_ccw_req cqr; |
| 97 | struct ccw1 ccw; |
| 98 | char data[32]; |
| 99 | } *dasd_reserve_req; |
| 100 | static DEFINE_MUTEX(dasd_reserve_mutex); |
| 101 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 102 | /* definitions for the path verification worker */ |
| 103 | struct path_verification_work_data { |
| 104 | struct work_struct worker; |
| 105 | struct dasd_device *device; |
| 106 | struct dasd_ccw_req cqr; |
| 107 | struct ccw1 ccw; |
| 108 | __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE]; |
| 109 | int isglobal; |
| 110 | __u8 tbvpm; |
| 111 | }; |
| 112 | static struct path_verification_work_data *path_verification_worker; |
| 113 | static DEFINE_MUTEX(dasd_path_verification_mutex); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* initial attempt at a probe function. this can be simplified once |
| 116 | * the other detection code is gone */ |
| 117 | static int |
| 118 | dasd_eckd_probe (struct ccw_device *cdev) |
| 119 | { |
| 120 | int ret; |
| 121 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 122 | /* set ECKD specific ccw-device options */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 123 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE | |
| 124 | CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 125 | if (ret) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 126 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", |
| 127 | "dasd_eckd_probe: could not set " |
| 128 | "ccw-device options"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return ret; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 130 | } |
| 131 | ret = dasd_generic_probe(cdev, &dasd_eckd_discipline); |
| 132 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static int |
| 136 | dasd_eckd_set_online(struct ccw_device *cdev) |
| 137 | { |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 138 | return dasd_generic_set_online(cdev, &dasd_eckd_discipline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | static const int sizes_trk0[] = { 28, 148, 84 }; |
| 142 | #define LABEL_SIZE 140 |
| 143 | |
Stefan Haberland | 3bc9fef9 | 2012-09-20 18:37:36 +0200 | [diff] [blame] | 144 | /* head and record addresses of count_area read in analysis ccw */ |
| 145 | static const int count_area_head[] = { 0, 0, 0, 0, 2 }; |
| 146 | static const int count_area_rec[] = { 1, 2, 3, 4, 1 }; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | static inline unsigned int |
| 149 | round_up_multiple(unsigned int no, unsigned int mult) |
| 150 | { |
| 151 | int rem = no % mult; |
| 152 | return (rem ? no - rem + mult : no); |
| 153 | } |
| 154 | |
| 155 | static inline unsigned int |
| 156 | ceil_quot(unsigned int d1, unsigned int d2) |
| 157 | { |
| 158 | return (d1 + (d2 - 1)) / d2; |
| 159 | } |
| 160 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 161 | static unsigned int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | recs_per_track(struct dasd_eckd_characteristics * rdc, |
| 163 | unsigned int kl, unsigned int dl) |
| 164 | { |
| 165 | int dn, kn; |
| 166 | |
| 167 | switch (rdc->dev_type) { |
| 168 | case 0x3380: |
| 169 | if (kl) |
| 170 | return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) + |
| 171 | ceil_quot(dl + 12, 32)); |
| 172 | else |
| 173 | return 1499 / (15 + ceil_quot(dl + 12, 32)); |
| 174 | case 0x3390: |
| 175 | dn = ceil_quot(dl + 6, 232) + 1; |
| 176 | if (kl) { |
| 177 | kn = ceil_quot(kl + 6, 232) + 1; |
| 178 | return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) + |
| 179 | 9 + ceil_quot(dl + 6 * dn, 34)); |
| 180 | } else |
| 181 | return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34)); |
| 182 | case 0x9345: |
| 183 | dn = ceil_quot(dl + 6, 232) + 1; |
| 184 | if (kl) { |
| 185 | kn = ceil_quot(kl + 6, 232) + 1; |
| 186 | return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) + |
| 187 | ceil_quot(dl + 6 * dn, 34)); |
| 188 | } else |
| 189 | return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34)); |
| 190 | } |
| 191 | return 0; |
| 192 | } |
| 193 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 194 | static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head) |
| 195 | { |
| 196 | geo->cyl = (__u16) cyl; |
| 197 | geo->head = cyl >> 16; |
| 198 | geo->head <<= 4; |
| 199 | geo->head |= head; |
| 200 | } |
| 201 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 202 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | check_XRC (struct ccw1 *de_ccw, |
| 204 | struct DE_eckd_data *data, |
| 205 | struct dasd_device *device) |
| 206 | { |
| 207 | struct dasd_eckd_private *private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 208 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | private = (struct dasd_eckd_private *) device->private; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 211 | if (!private->rdc_data.facilities.XRC_supported) |
| 212 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* switch on System Time Stamp - needed for XRC Support */ |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 215 | data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */ |
| 216 | data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */ |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 217 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 218 | rc = get_sync_clock(&data->ep_sys_time); |
| 219 | /* Ignore return code if sync clock is switched off. */ |
Heiko Carstens | a8f6db4 | 2012-09-06 15:13:34 +0200 | [diff] [blame] | 220 | if (rc == -EOPNOTSUPP || rc == -EACCES) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 221 | rc = 0; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 222 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 223 | de_ccw->count = sizeof(struct DE_eckd_data); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 224 | de_ccw->flags |= CCW_FLAG_SLI; |
| 225 | return rc; |
| 226 | } |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 227 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 228 | static int |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 229 | define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk, |
| 230 | unsigned int totrk, int cmd, struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
| 232 | struct dasd_eckd_private *private; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 233 | u32 begcyl, endcyl; |
| 234 | u16 heads, beghead, endhead; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 235 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | private = (struct dasd_eckd_private *) device->private; |
| 238 | |
| 239 | ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT; |
| 240 | ccw->flags = 0; |
| 241 | ccw->count = 16; |
| 242 | ccw->cda = (__u32) __pa(data); |
| 243 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 244 | memset(data, 0, sizeof(struct DE_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | switch (cmd) { |
| 246 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 247 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 248 | case DASD_ECKD_CCW_READ: |
| 249 | case DASD_ECKD_CCW_READ_MT: |
| 250 | case DASD_ECKD_CCW_READ_CKD: |
| 251 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 252 | case DASD_ECKD_CCW_READ_KD: |
| 253 | case DASD_ECKD_CCW_READ_KD_MT: |
| 254 | case DASD_ECKD_CCW_READ_COUNT: |
| 255 | data->mask.perm = 0x1; |
| 256 | data->attributes.operation = private->attrib.operation; |
| 257 | break; |
| 258 | case DASD_ECKD_CCW_WRITE: |
| 259 | case DASD_ECKD_CCW_WRITE_MT: |
| 260 | case DASD_ECKD_CCW_WRITE_KD: |
| 261 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 262 | data->mask.perm = 0x02; |
| 263 | data->attributes.operation = private->attrib.operation; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 264 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | break; |
| 266 | case DASD_ECKD_CCW_WRITE_CKD: |
| 267 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 268 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 269 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
| 271 | case DASD_ECKD_CCW_ERASE: |
| 272 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 273 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 274 | data->mask.perm = 0x3; |
| 275 | data->mask.auth = 0x1; |
| 276 | data->attributes.operation = DASD_BYPASS_CACHE; |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 277 | rc = check_XRC (ccw, data, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | break; |
| 279 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 280 | dev_err(&device->cdev->dev, |
| 281 | "0x%x is not a known command\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | break; |
| 283 | } |
| 284 | |
| 285 | data->attributes.mode = 0x3; /* ECKD */ |
| 286 | |
| 287 | if ((private->rdc_data.cu_type == 0x2105 || |
| 288 | private->rdc_data.cu_type == 0x2107 || |
| 289 | private->rdc_data.cu_type == 0x1750) |
| 290 | && !(private->uses_cdl && trk < 2)) |
| 291 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ |
| 292 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 293 | heads = private->rdc_data.trk_per_cyl; |
| 294 | begcyl = trk / heads; |
| 295 | beghead = trk % heads; |
| 296 | endcyl = totrk / heads; |
| 297 | endhead = totrk % heads; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* check for sequential prestage - enhance cylinder range */ |
| 300 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || |
| 301 | data->attributes.operation == DASD_SEQ_ACCESS) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 302 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 303 | if (endcyl + private->attrib.nr_cyl < private->real_cyl) |
| 304 | endcyl += private->attrib.nr_cyl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | else |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 306 | endcyl = (private->real_cyl - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 309 | set_ch_t(&data->beg_ext, begcyl, beghead); |
| 310 | set_ch_t(&data->end_ext, endcyl, endhead); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 311 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 314 | static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata, |
| 315 | struct dasd_device *device) |
| 316 | { |
| 317 | struct dasd_eckd_private *private; |
| 318 | int rc; |
| 319 | |
| 320 | private = (struct dasd_eckd_private *) device->private; |
| 321 | if (!private->rdc_data.facilities.XRC_supported) |
| 322 | return 0; |
| 323 | |
| 324 | /* switch on System Time Stamp - needed for XRC Support */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 325 | pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */ |
| 326 | pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 327 | pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */ |
| 328 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 329 | rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 330 | /* Ignore return code if sync clock is switched off. */ |
Heiko Carstens | a8f6db4 | 2012-09-06 15:13:34 +0200 | [diff] [blame] | 331 | if (rc == -EOPNOTSUPP || rc == -EACCES) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 332 | rc = 0; |
| 333 | return rc; |
| 334 | } |
| 335 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 336 | static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk, |
| 337 | unsigned int rec_on_trk, int count, int cmd, |
| 338 | struct dasd_device *device, unsigned int reclen, |
| 339 | unsigned int tlf) |
| 340 | { |
| 341 | struct dasd_eckd_private *private; |
| 342 | int sector; |
| 343 | int dn, d; |
| 344 | |
| 345 | private = (struct dasd_eckd_private *) device->private; |
| 346 | |
| 347 | memset(data, 0, sizeof(*data)); |
| 348 | sector = 0; |
| 349 | if (rec_on_trk) { |
| 350 | switch (private->rdc_data.dev_type) { |
| 351 | case 0x3390: |
| 352 | dn = ceil_quot(reclen + 6, 232); |
| 353 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); |
| 354 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 355 | break; |
| 356 | case 0x3380: |
| 357 | d = 7 + ceil_quot(reclen + 12, 32); |
| 358 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | data->sector = sector; |
| 363 | /* note: meaning of count depends on the operation |
| 364 | * for record based I/O it's the number of records, but for |
| 365 | * track based I/O it's the number of tracks |
| 366 | */ |
| 367 | data->count = count; |
| 368 | switch (cmd) { |
| 369 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 370 | data->operation.orientation = 0x3; |
| 371 | data->operation.operation = 0x03; |
| 372 | break; |
| 373 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 374 | data->operation.orientation = 0x3; |
| 375 | data->operation.operation = 0x16; |
| 376 | break; |
| 377 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 378 | data->operation.orientation = 0x1; |
| 379 | data->operation.operation = 0x03; |
| 380 | data->count++; |
| 381 | break; |
| 382 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 383 | data->operation.orientation = 0x3; |
| 384 | data->operation.operation = 0x16; |
| 385 | data->count++; |
| 386 | break; |
| 387 | case DASD_ECKD_CCW_WRITE: |
| 388 | case DASD_ECKD_CCW_WRITE_MT: |
| 389 | case DASD_ECKD_CCW_WRITE_KD: |
| 390 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 391 | data->auxiliary.length_valid = 0x1; |
| 392 | data->length = reclen; |
| 393 | data->operation.operation = 0x01; |
| 394 | break; |
| 395 | case DASD_ECKD_CCW_WRITE_CKD: |
| 396 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 397 | data->auxiliary.length_valid = 0x1; |
| 398 | data->length = reclen; |
| 399 | data->operation.operation = 0x03; |
| 400 | break; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 401 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: |
| 402 | data->operation.orientation = 0x0; |
| 403 | data->operation.operation = 0x3F; |
| 404 | data->extended_operation = 0x11; |
| 405 | data->length = 0; |
| 406 | data->extended_parameter_length = 0x02; |
| 407 | if (data->count > 8) { |
| 408 | data->extended_parameter[0] = 0xFF; |
| 409 | data->extended_parameter[1] = 0xFF; |
| 410 | data->extended_parameter[1] <<= (16 - count); |
| 411 | } else { |
| 412 | data->extended_parameter[0] = 0xFF; |
| 413 | data->extended_parameter[0] <<= (8 - count); |
| 414 | data->extended_parameter[1] = 0x00; |
| 415 | } |
| 416 | data->sector = 0xFF; |
| 417 | break; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 418 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 419 | data->auxiliary.length_valid = 0x1; |
| 420 | data->length = reclen; /* not tlf, as one might think */ |
| 421 | data->operation.operation = 0x3F; |
| 422 | data->extended_operation = 0x23; |
| 423 | break; |
| 424 | case DASD_ECKD_CCW_READ: |
| 425 | case DASD_ECKD_CCW_READ_MT: |
| 426 | case DASD_ECKD_CCW_READ_KD: |
| 427 | case DASD_ECKD_CCW_READ_KD_MT: |
| 428 | data->auxiliary.length_valid = 0x1; |
| 429 | data->length = reclen; |
| 430 | data->operation.operation = 0x06; |
| 431 | break; |
| 432 | case DASD_ECKD_CCW_READ_CKD: |
| 433 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 434 | data->auxiliary.length_valid = 0x1; |
| 435 | data->length = reclen; |
| 436 | data->operation.operation = 0x16; |
| 437 | break; |
| 438 | case DASD_ECKD_CCW_READ_COUNT: |
| 439 | data->operation.operation = 0x06; |
| 440 | break; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 441 | case DASD_ECKD_CCW_READ_TRACK: |
| 442 | data->operation.orientation = 0x1; |
| 443 | data->operation.operation = 0x0C; |
| 444 | data->extended_parameter_length = 0; |
| 445 | data->sector = 0xFF; |
| 446 | break; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 447 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 448 | data->auxiliary.length_valid = 0x1; |
| 449 | data->length = tlf; |
| 450 | data->operation.operation = 0x0C; |
| 451 | break; |
| 452 | case DASD_ECKD_CCW_ERASE: |
| 453 | data->length = reclen; |
| 454 | data->auxiliary.length_valid = 0x1; |
| 455 | data->operation.operation = 0x0b; |
| 456 | break; |
| 457 | default: |
| 458 | DBF_DEV_EVENT(DBF_ERR, device, |
| 459 | "fill LRE unknown opcode 0x%x", cmd); |
| 460 | BUG(); |
| 461 | } |
| 462 | set_ch_t(&data->seek_addr, |
| 463 | trk / private->rdc_data.trk_per_cyl, |
| 464 | trk % private->rdc_data.trk_per_cyl); |
| 465 | data->search_arg.cyl = data->seek_addr.cyl; |
| 466 | data->search_arg.head = data->seek_addr.head; |
| 467 | data->search_arg.record = rec_on_trk; |
| 468 | } |
| 469 | |
| 470 | static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
| 471 | unsigned int trk, unsigned int totrk, int cmd, |
| 472 | struct dasd_device *basedev, struct dasd_device *startdev, |
| 473 | unsigned char format, unsigned int rec_on_trk, int count, |
| 474 | unsigned int blksize, unsigned int tlf) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 475 | { |
| 476 | struct dasd_eckd_private *basepriv, *startpriv; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 477 | struct DE_eckd_data *dedata; |
| 478 | struct LRE_eckd_data *lredata; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 479 | u32 begcyl, endcyl; |
| 480 | u16 heads, beghead, endhead; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 481 | int rc = 0; |
| 482 | |
| 483 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 484 | startpriv = (struct dasd_eckd_private *) startdev->private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 485 | dedata = &pfxdata->define_extent; |
| 486 | lredata = &pfxdata->locate_record; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 487 | |
| 488 | ccw->cmd_code = DASD_ECKD_CCW_PFX; |
| 489 | ccw->flags = 0; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 490 | if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) { |
| 491 | ccw->count = sizeof(*pfxdata) + 2; |
| 492 | ccw->cda = (__u32) __pa(pfxdata); |
| 493 | memset(pfxdata, 0, sizeof(*pfxdata) + 2); |
| 494 | } else { |
| 495 | ccw->count = sizeof(*pfxdata); |
| 496 | ccw->cda = (__u32) __pa(pfxdata); |
| 497 | memset(pfxdata, 0, sizeof(*pfxdata)); |
| 498 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 499 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 500 | /* prefix data */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 501 | if (format > 1) { |
| 502 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 503 | "PFX LRE unknown format 0x%x", format); |
| 504 | BUG(); |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | pfxdata->format = format; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 508 | pfxdata->base_address = basepriv->ned->unit_addr; |
| 509 | pfxdata->base_lss = basepriv->ned->ID; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 510 | pfxdata->validity.define_extent = 1; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 511 | |
| 512 | /* private uid is kept up to date, conf_data may be outdated */ |
| 513 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 514 | pfxdata->validity.verify_base = 1; |
| 515 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 516 | pfxdata->validity.hyper_pav = 1; |
| 517 | } |
| 518 | |
| 519 | /* define extend data (mostly)*/ |
| 520 | switch (cmd) { |
| 521 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 522 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 523 | case DASD_ECKD_CCW_READ: |
| 524 | case DASD_ECKD_CCW_READ_MT: |
| 525 | case DASD_ECKD_CCW_READ_CKD: |
| 526 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 527 | case DASD_ECKD_CCW_READ_KD: |
| 528 | case DASD_ECKD_CCW_READ_KD_MT: |
| 529 | case DASD_ECKD_CCW_READ_COUNT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 530 | dedata->mask.perm = 0x1; |
| 531 | dedata->attributes.operation = basepriv->attrib.operation; |
| 532 | break; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 533 | case DASD_ECKD_CCW_READ_TRACK: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 534 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 535 | dedata->mask.perm = 0x1; |
| 536 | dedata->attributes.operation = basepriv->attrib.operation; |
| 537 | dedata->blk_size = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 538 | break; |
| 539 | case DASD_ECKD_CCW_WRITE: |
| 540 | case DASD_ECKD_CCW_WRITE_MT: |
| 541 | case DASD_ECKD_CCW_WRITE_KD: |
| 542 | case DASD_ECKD_CCW_WRITE_KD_MT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 543 | dedata->mask.perm = 0x02; |
| 544 | dedata->attributes.operation = basepriv->attrib.operation; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 545 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 546 | break; |
| 547 | case DASD_ECKD_CCW_WRITE_CKD: |
| 548 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 549 | dedata->attributes.operation = DASD_BYPASS_CACHE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 550 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 551 | break; |
| 552 | case DASD_ECKD_CCW_ERASE: |
| 553 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 554 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 555 | dedata->mask.perm = 0x3; |
| 556 | dedata->mask.auth = 0x1; |
| 557 | dedata->attributes.operation = DASD_BYPASS_CACHE; |
| 558 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 559 | break; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 560 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: |
| 561 | dedata->mask.perm = 0x03; |
| 562 | dedata->attributes.operation = basepriv->attrib.operation; |
| 563 | dedata->blk_size = 0; |
| 564 | break; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 565 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 566 | dedata->mask.perm = 0x02; |
| 567 | dedata->attributes.operation = basepriv->attrib.operation; |
| 568 | dedata->blk_size = blksize; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 569 | rc = check_XRC_on_prefix(pfxdata, basedev); |
| 570 | break; |
| 571 | default: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 572 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 573 | "PFX LRE unknown opcode 0x%x", cmd); |
| 574 | BUG(); |
| 575 | return -EINVAL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 576 | } |
| 577 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 578 | dedata->attributes.mode = 0x3; /* ECKD */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 579 | |
| 580 | if ((basepriv->rdc_data.cu_type == 0x2105 || |
| 581 | basepriv->rdc_data.cu_type == 0x2107 || |
| 582 | basepriv->rdc_data.cu_type == 0x1750) |
| 583 | && !(basepriv->uses_cdl && trk < 2)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 584 | dedata->ga_extended |= 0x40; /* Regular Data Format Mode */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 585 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 586 | heads = basepriv->rdc_data.trk_per_cyl; |
| 587 | begcyl = trk / heads; |
| 588 | beghead = trk % heads; |
| 589 | endcyl = totrk / heads; |
| 590 | endhead = totrk % heads; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 591 | |
| 592 | /* check for sequential prestage - enhance cylinder range */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 593 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
| 594 | dedata->attributes.operation == DASD_SEQ_ACCESS) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 595 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 596 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
| 597 | endcyl += basepriv->attrib.nr_cyl; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 598 | else |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 599 | endcyl = (basepriv->real_cyl - 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 602 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
| 603 | set_ch_t(&dedata->end_ext, endcyl, endhead); |
| 604 | |
| 605 | if (format == 1) { |
| 606 | fill_LRE_data(lredata, trk, rec_on_trk, count, cmd, |
| 607 | basedev, blksize, tlf); |
| 608 | } |
| 609 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 610 | return rc; |
| 611 | } |
| 612 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 613 | static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
| 614 | unsigned int trk, unsigned int totrk, int cmd, |
| 615 | struct dasd_device *basedev, struct dasd_device *startdev) |
| 616 | { |
| 617 | return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev, |
| 618 | 0, 0, 0, 0, 0); |
| 619 | } |
| 620 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 621 | static void |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 622 | locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk, |
| 623 | unsigned int rec_on_trk, int no_rec, int cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | struct dasd_device * device, int reclen) |
| 625 | { |
| 626 | struct dasd_eckd_private *private; |
| 627 | int sector; |
| 628 | int dn, d; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | private = (struct dasd_eckd_private *) device->private; |
| 631 | |
| 632 | DBF_DEV_EVENT(DBF_INFO, device, |
| 633 | "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d", |
| 634 | trk, rec_on_trk, no_rec, cmd, reclen); |
| 635 | |
| 636 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD; |
| 637 | ccw->flags = 0; |
| 638 | ccw->count = 16; |
| 639 | ccw->cda = (__u32) __pa(data); |
| 640 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 641 | memset(data, 0, sizeof(struct LO_eckd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | sector = 0; |
| 643 | if (rec_on_trk) { |
| 644 | switch (private->rdc_data.dev_type) { |
| 645 | case 0x3390: |
| 646 | dn = ceil_quot(reclen + 6, 232); |
| 647 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); |
| 648 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 649 | break; |
| 650 | case 0x3380: |
| 651 | d = 7 + ceil_quot(reclen + 12, 32); |
| 652 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | data->sector = sector; |
| 657 | data->count = no_rec; |
| 658 | switch (cmd) { |
| 659 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: |
| 660 | data->operation.orientation = 0x3; |
| 661 | data->operation.operation = 0x03; |
| 662 | break; |
| 663 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: |
| 664 | data->operation.orientation = 0x3; |
| 665 | data->operation.operation = 0x16; |
| 666 | break; |
| 667 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: |
| 668 | data->operation.orientation = 0x1; |
| 669 | data->operation.operation = 0x03; |
| 670 | data->count++; |
| 671 | break; |
| 672 | case DASD_ECKD_CCW_READ_RECORD_ZERO: |
| 673 | data->operation.orientation = 0x3; |
| 674 | data->operation.operation = 0x16; |
| 675 | data->count++; |
| 676 | break; |
| 677 | case DASD_ECKD_CCW_WRITE: |
| 678 | case DASD_ECKD_CCW_WRITE_MT: |
| 679 | case DASD_ECKD_CCW_WRITE_KD: |
| 680 | case DASD_ECKD_CCW_WRITE_KD_MT: |
| 681 | data->auxiliary.last_bytes_used = 0x1; |
| 682 | data->length = reclen; |
| 683 | data->operation.operation = 0x01; |
| 684 | break; |
| 685 | case DASD_ECKD_CCW_WRITE_CKD: |
| 686 | case DASD_ECKD_CCW_WRITE_CKD_MT: |
| 687 | data->auxiliary.last_bytes_used = 0x1; |
| 688 | data->length = reclen; |
| 689 | data->operation.operation = 0x03; |
| 690 | break; |
| 691 | case DASD_ECKD_CCW_READ: |
| 692 | case DASD_ECKD_CCW_READ_MT: |
| 693 | case DASD_ECKD_CCW_READ_KD: |
| 694 | case DASD_ECKD_CCW_READ_KD_MT: |
| 695 | data->auxiliary.last_bytes_used = 0x1; |
| 696 | data->length = reclen; |
| 697 | data->operation.operation = 0x06; |
| 698 | break; |
| 699 | case DASD_ECKD_CCW_READ_CKD: |
| 700 | case DASD_ECKD_CCW_READ_CKD_MT: |
| 701 | data->auxiliary.last_bytes_used = 0x1; |
| 702 | data->length = reclen; |
| 703 | data->operation.operation = 0x16; |
| 704 | break; |
| 705 | case DASD_ECKD_CCW_READ_COUNT: |
| 706 | data->operation.operation = 0x06; |
| 707 | break; |
| 708 | case DASD_ECKD_CCW_ERASE: |
| 709 | data->length = reclen; |
| 710 | data->auxiliary.last_bytes_used = 0x1; |
| 711 | data->operation.operation = 0x0b; |
| 712 | break; |
| 713 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 714 | DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record " |
| 715 | "opcode 0x%x", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 717 | set_ch_t(&data->seek_addr, |
| 718 | trk / private->rdc_data.trk_per_cyl, |
| 719 | trk % private->rdc_data.trk_per_cyl); |
| 720 | data->search_arg.cyl = data->seek_addr.cyl; |
| 721 | data->search_arg.head = data->seek_addr.head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | data->search_arg.record = rec_on_trk; |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | * Returns 1 if the block is one of the special blocks that needs |
| 727 | * to get read/written with the KD variant of the command. |
| 728 | * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and |
| 729 | * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT. |
| 730 | * Luckily the KD variants differ only by one bit (0x08) from the |
| 731 | * normal variant. So don't wonder about code like: |
| 732 | * if (dasd_eckd_cdl_special(blk_per_trk, recid)) |
| 733 | * ccw->cmd_code |= 0x8; |
| 734 | */ |
| 735 | static inline int |
| 736 | dasd_eckd_cdl_special(int blk_per_trk, int recid) |
| 737 | { |
| 738 | if (recid < 3) |
| 739 | return 1; |
| 740 | if (recid < blk_per_trk) |
| 741 | return 0; |
| 742 | if (recid < 2 * blk_per_trk) |
| 743 | return 1; |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | /* |
| 748 | * Returns the record size for the special blocks of the cdl format. |
| 749 | * Only returns something useful if dasd_eckd_cdl_special is true |
| 750 | * for the recid. |
| 751 | */ |
| 752 | static inline int |
| 753 | dasd_eckd_cdl_reclen(int recid) |
| 754 | { |
| 755 | if (recid < 3) |
| 756 | return sizes_trk0[recid]; |
| 757 | return LABEL_SIZE; |
| 758 | } |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 759 | /* create unique id from private structure. */ |
| 760 | static void create_uid(struct dasd_eckd_private *private) |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 761 | { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 762 | int count; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 763 | struct dasd_uid *uid; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 764 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 765 | uid = &private->uid; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 766 | memset(uid, 0, sizeof(struct dasd_uid)); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 767 | memcpy(uid->vendor, private->ned->HDA_manufacturer, |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 768 | sizeof(uid->vendor) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 769 | EBCASC(uid->vendor, sizeof(uid->vendor) - 1); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 770 | memcpy(uid->serial, private->ned->HDA_location, |
Horst Hummel | d0710c7 | 2006-08-10 15:45:16 +0200 | [diff] [blame] | 771 | sizeof(uid->serial) - 1); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 772 | EBCASC(uid->serial, sizeof(uid->serial) - 1); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 773 | uid->ssid = private->gneq->subsystemID; |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 774 | uid->real_unit_addr = private->ned->unit_addr; |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 775 | if (private->sneq) { |
| 776 | uid->type = private->sneq->sua_flags; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 777 | if (uid->type == UA_BASE_PAV_ALIAS) |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 778 | uid->base_unit_addr = private->sneq->base_unit_addr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 779 | } else { |
| 780 | uid->type = UA_BASE_DEVICE; |
| 781 | } |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 782 | if (private->vdsneq) { |
| 783 | for (count = 0; count < 16; count++) { |
| 784 | sprintf(uid->vduit+2*count, "%02x", |
| 785 | private->vdsneq->uit[count]); |
| 786 | } |
| 787 | } |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* |
| 791 | * Generate device unique id that specifies the physical device. |
| 792 | */ |
| 793 | static int dasd_eckd_generate_uid(struct dasd_device *device) |
| 794 | { |
| 795 | struct dasd_eckd_private *private; |
| 796 | unsigned long flags; |
| 797 | |
| 798 | private = (struct dasd_eckd_private *) device->private; |
| 799 | if (!private) |
| 800 | return -ENODEV; |
| 801 | if (!private->ned || !private->gneq) |
| 802 | return -ENODEV; |
| 803 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 804 | create_uid(private); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 805 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 806 | return 0; |
| 807 | } |
| 808 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 809 | static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid) |
| 810 | { |
| 811 | struct dasd_eckd_private *private; |
| 812 | unsigned long flags; |
| 813 | |
| 814 | if (device->private) { |
| 815 | private = (struct dasd_eckd_private *)device->private; |
| 816 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 817 | *uid = private->uid; |
| 818 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 819 | return 0; |
| 820 | } |
| 821 | return -EINVAL; |
| 822 | } |
| 823 | |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 824 | /* |
| 825 | * compare device UID with data of a given dasd_eckd_private structure |
| 826 | * return 0 for match |
| 827 | */ |
| 828 | static int dasd_eckd_compare_path_uid(struct dasd_device *device, |
| 829 | struct dasd_eckd_private *private) |
| 830 | { |
| 831 | struct dasd_uid device_uid; |
| 832 | |
| 833 | create_uid(private); |
| 834 | dasd_eckd_get_uid(device, &device_uid); |
| 835 | |
| 836 | return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid)); |
| 837 | } |
| 838 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 839 | static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device, |
| 840 | struct dasd_ccw_req *cqr, |
| 841 | __u8 *rcd_buffer, |
| 842 | __u8 lpm) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 843 | { |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 844 | struct ccw1 *ccw; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 845 | /* |
| 846 | * buffer has to start with EBCDIC "V1.0" to show |
| 847 | * support for virtual device SNEQ |
| 848 | */ |
| 849 | rcd_buffer[0] = 0xE5; |
| 850 | rcd_buffer[1] = 0xF1; |
| 851 | rcd_buffer[2] = 0x4B; |
| 852 | rcd_buffer[3] = 0xF0; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 853 | |
| 854 | ccw = cqr->cpaddr; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 855 | ccw->cmd_code = DASD_ECKD_CCW_RCD; |
| 856 | ccw->flags = 0; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 857 | ccw->cda = (__u32)(addr_t)rcd_buffer; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 858 | ccw->count = DASD_ECKD_RCD_DATA_SIZE; |
| 859 | cqr->magic = DASD_ECKD_MAGIC; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 860 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 861 | cqr->startdev = device; |
| 862 | cqr->memdev = device; |
| 863 | cqr->block = NULL; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 864 | cqr->expires = 10*HZ; |
| 865 | cqr->lpm = lpm; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 866 | cqr->retries = 256; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 867 | cqr->buildclk = get_tod_clock(); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 868 | cqr->status = DASD_CQR_FILLED; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 869 | set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); |
| 870 | } |
| 871 | |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 872 | /* |
| 873 | * Wakeup helper for read_conf |
| 874 | * if the cqr is not done and needs some error recovery |
| 875 | * the buffer has to be re-initialized with the EBCDIC "V1.0" |
| 876 | * to show support for virtual device SNEQ |
| 877 | */ |
| 878 | static void read_conf_cb(struct dasd_ccw_req *cqr, void *data) |
| 879 | { |
| 880 | struct ccw1 *ccw; |
| 881 | __u8 *rcd_buffer; |
| 882 | |
| 883 | if (cqr->status != DASD_CQR_DONE) { |
| 884 | ccw = cqr->cpaddr; |
| 885 | rcd_buffer = (__u8 *)((addr_t) ccw->cda); |
| 886 | memset(rcd_buffer, 0, sizeof(*rcd_buffer)); |
| 887 | |
| 888 | rcd_buffer[0] = 0xE5; |
| 889 | rcd_buffer[1] = 0xF1; |
| 890 | rcd_buffer[2] = 0x4B; |
| 891 | rcd_buffer[3] = 0xF0; |
| 892 | } |
| 893 | dasd_wakeup_cb(cqr, data); |
| 894 | } |
| 895 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 896 | static int dasd_eckd_read_conf_immediately(struct dasd_device *device, |
| 897 | struct dasd_ccw_req *cqr, |
| 898 | __u8 *rcd_buffer, |
| 899 | __u8 lpm) |
| 900 | { |
| 901 | struct ciw *ciw; |
| 902 | int rc; |
| 903 | /* |
| 904 | * sanity check: scan for RCD command in extended SenseID data |
| 905 | * some devices do not support RCD |
| 906 | */ |
| 907 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); |
| 908 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) |
| 909 | return -EOPNOTSUPP; |
| 910 | |
| 911 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm); |
| 912 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 913 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 914 | cqr->retries = 5; |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 915 | cqr->callback = read_conf_cb; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 916 | rc = dasd_sleep_on_immediatly(cqr); |
| 917 | return rc; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static int dasd_eckd_read_conf_lpm(struct dasd_device *device, |
| 921 | void **rcd_buffer, |
| 922 | int *rcd_buffer_size, __u8 lpm) |
| 923 | { |
| 924 | struct ciw *ciw; |
| 925 | char *rcd_buf = NULL; |
| 926 | int ret; |
| 927 | struct dasd_ccw_req *cqr; |
| 928 | |
| 929 | /* |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 930 | * sanity check: scan for RCD command in extended SenseID data |
| 931 | * some devices do not support RCD |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 932 | */ |
| 933 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 934 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) { |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 935 | ret = -EOPNOTSUPP; |
| 936 | goto out_error; |
| 937 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 938 | rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 939 | if (!rcd_buf) { |
| 940 | ret = -ENOMEM; |
| 941 | goto out_error; |
| 942 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 943 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, |
| 944 | 0, /* use rcd_buf as data ara */ |
| 945 | device); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 946 | if (IS_ERR(cqr)) { |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 947 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 948 | "Could not allocate RCD request"); |
| 949 | ret = -ENOMEM; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 950 | goto out_error; |
| 951 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 952 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm); |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 953 | cqr->callback = read_conf_cb; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 954 | ret = dasd_sleep_on(cqr); |
| 955 | /* |
| 956 | * on success we update the user input parms |
| 957 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 958 | dasd_sfree_request(cqr, cqr->memdev); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 959 | if (ret) |
| 960 | goto out_error; |
| 961 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 962 | *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 963 | *rcd_buffer = rcd_buf; |
| 964 | return 0; |
| 965 | out_error: |
| 966 | kfree(rcd_buf); |
| 967 | *rcd_buffer = NULL; |
| 968 | *rcd_buffer_size = 0; |
| 969 | return ret; |
| 970 | } |
| 971 | |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 972 | static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private) |
| 973 | { |
| 974 | |
| 975 | struct dasd_sneq *sneq; |
| 976 | int i, count; |
| 977 | |
| 978 | private->ned = NULL; |
| 979 | private->sneq = NULL; |
| 980 | private->vdsneq = NULL; |
| 981 | private->gneq = NULL; |
| 982 | count = private->conf_len / sizeof(struct dasd_sneq); |
| 983 | sneq = (struct dasd_sneq *)private->conf_data; |
| 984 | for (i = 0; i < count; ++i) { |
| 985 | if (sneq->flags.identifier == 1 && sneq->format == 1) |
| 986 | private->sneq = sneq; |
| 987 | else if (sneq->flags.identifier == 1 && sneq->format == 4) |
| 988 | private->vdsneq = (struct vd_sneq *)sneq; |
| 989 | else if (sneq->flags.identifier == 2) |
| 990 | private->gneq = (struct dasd_gneq *)sneq; |
| 991 | else if (sneq->flags.identifier == 3 && sneq->res1 == 1) |
| 992 | private->ned = (struct dasd_ned *)sneq; |
| 993 | sneq++; |
| 994 | } |
| 995 | if (!private->ned || !private->gneq) { |
| 996 | private->ned = NULL; |
| 997 | private->sneq = NULL; |
| 998 | private->vdsneq = NULL; |
| 999 | private->gneq = NULL; |
| 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | return 0; |
| 1003 | |
| 1004 | }; |
| 1005 | |
| 1006 | static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len) |
| 1007 | { |
| 1008 | struct dasd_gneq *gneq; |
| 1009 | int i, count, found; |
| 1010 | |
| 1011 | count = conf_len / sizeof(*gneq); |
| 1012 | gneq = (struct dasd_gneq *)conf_data; |
| 1013 | found = 0; |
| 1014 | for (i = 0; i < count; ++i) { |
| 1015 | if (gneq->flags.identifier == 2) { |
| 1016 | found = 1; |
| 1017 | break; |
| 1018 | } |
| 1019 | gneq++; |
| 1020 | } |
| 1021 | if (found) |
| 1022 | return ((char *)gneq)[18] & 0x07; |
| 1023 | else |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | static int dasd_eckd_read_conf(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | { |
| 1029 | void *conf_data; |
| 1030 | int conf_len, conf_data_saved; |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 1031 | int rc, path_err; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1032 | __u8 lpm, opm; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1033 | struct dasd_eckd_private *private, path_private; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1034 | struct dasd_path *path_data; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1035 | struct dasd_uid *uid; |
| 1036 | char print_path_uid[60], print_device_uid[60]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1039 | path_data = &device->path_data; |
| 1040 | opm = ccw_device_get_path_mask(device->cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | conf_data_saved = 0; |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 1042 | path_err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | /* get configuration data per operational path */ |
| 1044 | for (lpm = 0x80; lpm; lpm>>= 1) { |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1045 | if (!(lpm & opm)) |
| 1046 | continue; |
| 1047 | rc = dasd_eckd_read_conf_lpm(device, &conf_data, |
| 1048 | &conf_len, lpm); |
| 1049 | if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ |
| 1050 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
| 1051 | "Read configuration data returned " |
| 1052 | "error %d", rc); |
| 1053 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | } |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1055 | if (conf_data == NULL) { |
| 1056 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
| 1057 | "No configuration data " |
| 1058 | "retrieved"); |
| 1059 | /* no further analysis possible */ |
| 1060 | path_data->opm |= lpm; |
| 1061 | continue; /* no error */ |
| 1062 | } |
| 1063 | /* save first valid configuration data */ |
| 1064 | if (!conf_data_saved) { |
| 1065 | kfree(private->conf_data); |
| 1066 | private->conf_data = conf_data; |
| 1067 | private->conf_len = conf_len; |
| 1068 | if (dasd_eckd_identify_conf_parts(private)) { |
| 1069 | private->conf_data = NULL; |
| 1070 | private->conf_len = 0; |
| 1071 | kfree(conf_data); |
| 1072 | continue; |
| 1073 | } |
| 1074 | /* |
| 1075 | * build device UID that other path data |
| 1076 | * can be compared to it |
| 1077 | */ |
| 1078 | dasd_eckd_generate_uid(device); |
| 1079 | conf_data_saved++; |
| 1080 | } else { |
| 1081 | path_private.conf_data = conf_data; |
| 1082 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; |
| 1083 | if (dasd_eckd_identify_conf_parts( |
| 1084 | &path_private)) { |
| 1085 | path_private.conf_data = NULL; |
| 1086 | path_private.conf_len = 0; |
| 1087 | kfree(conf_data); |
| 1088 | continue; |
| 1089 | } |
| 1090 | |
| 1091 | if (dasd_eckd_compare_path_uid( |
| 1092 | device, &path_private)) { |
| 1093 | uid = &path_private.uid; |
| 1094 | if (strlen(uid->vduit) > 0) |
| 1095 | snprintf(print_path_uid, |
| 1096 | sizeof(print_path_uid), |
| 1097 | "%s.%s.%04x.%02x.%s", |
| 1098 | uid->vendor, uid->serial, |
| 1099 | uid->ssid, uid->real_unit_addr, |
| 1100 | uid->vduit); |
| 1101 | else |
| 1102 | snprintf(print_path_uid, |
| 1103 | sizeof(print_path_uid), |
| 1104 | "%s.%s.%04x.%02x", |
| 1105 | uid->vendor, uid->serial, |
| 1106 | uid->ssid, |
| 1107 | uid->real_unit_addr); |
| 1108 | uid = &private->uid; |
| 1109 | if (strlen(uid->vduit) > 0) |
| 1110 | snprintf(print_device_uid, |
| 1111 | sizeof(print_device_uid), |
| 1112 | "%s.%s.%04x.%02x.%s", |
| 1113 | uid->vendor, uid->serial, |
| 1114 | uid->ssid, uid->real_unit_addr, |
| 1115 | uid->vduit); |
| 1116 | else |
| 1117 | snprintf(print_device_uid, |
| 1118 | sizeof(print_device_uid), |
| 1119 | "%s.%s.%04x.%02x", |
| 1120 | uid->vendor, uid->serial, |
| 1121 | uid->ssid, |
| 1122 | uid->real_unit_addr); |
| 1123 | dev_err(&device->cdev->dev, |
| 1124 | "Not all channel paths lead to " |
| 1125 | "the same device, path %02X leads to " |
| 1126 | "device %s instead of %s\n", lpm, |
| 1127 | print_path_uid, print_device_uid); |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 1128 | path_err = -EINVAL; |
| 1129 | continue; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | path_private.conf_data = NULL; |
| 1133 | path_private.conf_len = 0; |
| 1134 | } |
| 1135 | switch (dasd_eckd_path_access(conf_data, conf_len)) { |
| 1136 | case 0x02: |
| 1137 | path_data->npm |= lpm; |
| 1138 | break; |
| 1139 | case 0x03: |
| 1140 | path_data->ppm |= lpm; |
| 1141 | break; |
| 1142 | } |
| 1143 | path_data->opm |= lpm; |
| 1144 | |
| 1145 | if (conf_data != private->conf_data) |
| 1146 | kfree(conf_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1148 | |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 1149 | return path_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1152 | static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm) |
| 1153 | { |
| 1154 | struct dasd_eckd_private *private; |
| 1155 | int mdc; |
| 1156 | u32 fcx_max_data; |
| 1157 | |
| 1158 | private = (struct dasd_eckd_private *) device->private; |
| 1159 | if (private->fcx_max_data) { |
| 1160 | mdc = ccw_device_get_mdc(device->cdev, lpm); |
| 1161 | if ((mdc < 0)) { |
| 1162 | dev_warn(&device->cdev->dev, |
| 1163 | "Detecting the maximum data size for zHPF " |
| 1164 | "requests failed (rc=%d) for a new path %x\n", |
| 1165 | mdc, lpm); |
| 1166 | return mdc; |
| 1167 | } |
| 1168 | fcx_max_data = mdc * FCX_MAX_DATA_FACTOR; |
| 1169 | if (fcx_max_data < private->fcx_max_data) { |
| 1170 | dev_warn(&device->cdev->dev, |
| 1171 | "The maximum data size for zHPF requests %u " |
| 1172 | "on a new path %x is below the active maximum " |
| 1173 | "%u\n", fcx_max_data, lpm, |
| 1174 | private->fcx_max_data); |
| 1175 | return -EACCES; |
| 1176 | } |
| 1177 | } |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1181 | static int rebuild_device_uid(struct dasd_device *device, |
| 1182 | struct path_verification_work_data *data) |
| 1183 | { |
| 1184 | struct dasd_eckd_private *private; |
| 1185 | struct dasd_path *path_data; |
| 1186 | __u8 lpm, opm; |
| 1187 | int rc; |
| 1188 | |
| 1189 | rc = -ENODEV; |
| 1190 | private = (struct dasd_eckd_private *) device->private; |
| 1191 | path_data = &device->path_data; |
| 1192 | opm = device->path_data.opm; |
| 1193 | |
| 1194 | for (lpm = 0x80; lpm; lpm >>= 1) { |
| 1195 | if (!(lpm & opm)) |
| 1196 | continue; |
| 1197 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); |
| 1198 | memset(&data->cqr, 0, sizeof(data->cqr)); |
| 1199 | data->cqr.cpaddr = &data->ccw; |
| 1200 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, |
| 1201 | data->rcd_buffer, |
| 1202 | lpm); |
| 1203 | |
| 1204 | if (rc) { |
| 1205 | if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */ |
| 1206 | continue; |
| 1207 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
| 1208 | "Read configuration data " |
| 1209 | "returned error %d", rc); |
| 1210 | break; |
| 1211 | } |
| 1212 | memcpy(private->conf_data, data->rcd_buffer, |
| 1213 | DASD_ECKD_RCD_DATA_SIZE); |
| 1214 | if (dasd_eckd_identify_conf_parts(private)) { |
| 1215 | rc = -ENODEV; |
| 1216 | } else /* first valid path is enough */ |
| 1217 | break; |
| 1218 | } |
| 1219 | |
| 1220 | if (!rc) |
| 1221 | rc = dasd_eckd_generate_uid(device); |
| 1222 | |
| 1223 | return rc; |
| 1224 | } |
| 1225 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1226 | static void do_path_verification_work(struct work_struct *work) |
| 1227 | { |
| 1228 | struct path_verification_work_data *data; |
| 1229 | struct dasd_device *device; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1230 | struct dasd_eckd_private path_private; |
| 1231 | struct dasd_uid *uid; |
| 1232 | __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE]; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1233 | __u8 lpm, opm, npm, ppm, epm; |
| 1234 | unsigned long flags; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1235 | char print_uid[60]; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1236 | int rc; |
| 1237 | |
| 1238 | data = container_of(work, struct path_verification_work_data, worker); |
| 1239 | device = data->device; |
| 1240 | |
Stefan Haberland | c8d1c0f | 2011-10-30 15:17:09 +0100 | [diff] [blame] | 1241 | /* delay path verification until device was resumed */ |
| 1242 | if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { |
| 1243 | schedule_work(work); |
| 1244 | return; |
| 1245 | } |
| 1246 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1247 | opm = 0; |
| 1248 | npm = 0; |
| 1249 | ppm = 0; |
| 1250 | epm = 0; |
| 1251 | for (lpm = 0x80; lpm; lpm >>= 1) { |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1252 | if (!(lpm & data->tbvpm)) |
| 1253 | continue; |
| 1254 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); |
| 1255 | memset(&data->cqr, 0, sizeof(data->cqr)); |
| 1256 | data->cqr.cpaddr = &data->ccw; |
| 1257 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, |
| 1258 | data->rcd_buffer, |
| 1259 | lpm); |
| 1260 | if (!rc) { |
| 1261 | switch (dasd_eckd_path_access(data->rcd_buffer, |
| 1262 | DASD_ECKD_RCD_DATA_SIZE) |
| 1263 | ) { |
| 1264 | case 0x02: |
| 1265 | npm |= lpm; |
| 1266 | break; |
| 1267 | case 0x03: |
| 1268 | ppm |= lpm; |
| 1269 | break; |
| 1270 | } |
| 1271 | opm |= lpm; |
| 1272 | } else if (rc == -EOPNOTSUPP) { |
| 1273 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
| 1274 | "path verification: No configuration " |
| 1275 | "data retrieved"); |
| 1276 | opm |= lpm; |
| 1277 | } else if (rc == -EAGAIN) { |
| 1278 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1279 | "path verification: device is stopped," |
| 1280 | " try again later"); |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1281 | epm |= lpm; |
| 1282 | } else { |
| 1283 | dev_warn(&device->cdev->dev, |
| 1284 | "Reading device feature codes failed " |
| 1285 | "(rc=%d) for new path %x\n", rc, lpm); |
| 1286 | continue; |
| 1287 | } |
| 1288 | if (verify_fcx_max_data(device, lpm)) { |
| 1289 | opm &= ~lpm; |
| 1290 | npm &= ~lpm; |
| 1291 | ppm &= ~lpm; |
| 1292 | continue; |
| 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * save conf_data for comparison after |
| 1297 | * rebuild_device_uid may have changed |
| 1298 | * the original data |
| 1299 | */ |
| 1300 | memcpy(&path_rcd_buf, data->rcd_buffer, |
| 1301 | DASD_ECKD_RCD_DATA_SIZE); |
| 1302 | path_private.conf_data = (void *) &path_rcd_buf; |
| 1303 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; |
| 1304 | if (dasd_eckd_identify_conf_parts(&path_private)) { |
| 1305 | path_private.conf_data = NULL; |
| 1306 | path_private.conf_len = 0; |
| 1307 | continue; |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * compare path UID with device UID only if at least |
| 1312 | * one valid path is left |
| 1313 | * in other case the device UID may have changed and |
| 1314 | * the first working path UID will be used as device UID |
| 1315 | */ |
| 1316 | if (device->path_data.opm && |
| 1317 | dasd_eckd_compare_path_uid(device, &path_private)) { |
| 1318 | /* |
| 1319 | * the comparison was not successful |
| 1320 | * rebuild the device UID with at least one |
| 1321 | * known path in case a z/VM hyperswap command |
| 1322 | * has changed the device |
| 1323 | * |
| 1324 | * after this compare again |
| 1325 | * |
| 1326 | * if either the rebuild or the recompare fails |
| 1327 | * the path can not be used |
| 1328 | */ |
| 1329 | if (rebuild_device_uid(device, data) || |
| 1330 | dasd_eckd_compare_path_uid( |
| 1331 | device, &path_private)) { |
| 1332 | uid = &path_private.uid; |
| 1333 | if (strlen(uid->vduit) > 0) |
| 1334 | snprintf(print_uid, sizeof(print_uid), |
| 1335 | "%s.%s.%04x.%02x.%s", |
| 1336 | uid->vendor, uid->serial, |
| 1337 | uid->ssid, uid->real_unit_addr, |
| 1338 | uid->vduit); |
| 1339 | else |
| 1340 | snprintf(print_uid, sizeof(print_uid), |
| 1341 | "%s.%s.%04x.%02x", |
| 1342 | uid->vendor, uid->serial, |
| 1343 | uid->ssid, |
| 1344 | uid->real_unit_addr); |
| 1345 | dev_err(&device->cdev->dev, |
| 1346 | "The newly added channel path %02X " |
| 1347 | "will not be used because it leads " |
| 1348 | "to a different device %s\n", |
| 1349 | lpm, print_uid); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1350 | opm &= ~lpm; |
| 1351 | npm &= ~lpm; |
| 1352 | ppm &= ~lpm; |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1353 | continue; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1354 | } |
| 1355 | } |
Stefan Haberland | b206181 | 2011-12-27 11:27:27 +0100 | [diff] [blame] | 1356 | |
| 1357 | /* |
| 1358 | * There is a small chance that a path is lost again between |
| 1359 | * above path verification and the following modification of |
| 1360 | * the device opm mask. We could avoid that race here by using |
| 1361 | * yet another path mask, but we rather deal with this unlikely |
| 1362 | * situation in dasd_start_IO. |
| 1363 | */ |
| 1364 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1365 | if (!device->path_data.opm && opm) { |
| 1366 | device->path_data.opm = opm; |
| 1367 | dasd_generic_path_operational(device); |
| 1368 | } else |
| 1369 | device->path_data.opm |= opm; |
| 1370 | device->path_data.npm |= npm; |
| 1371 | device->path_data.ppm |= ppm; |
| 1372 | device->path_data.tbvpm |= epm; |
| 1373 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1374 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1375 | |
| 1376 | dasd_put_device(device); |
| 1377 | if (data->isglobal) |
| 1378 | mutex_unlock(&dasd_path_verification_mutex); |
| 1379 | else |
| 1380 | kfree(data); |
| 1381 | } |
| 1382 | |
| 1383 | static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm) |
| 1384 | { |
| 1385 | struct path_verification_work_data *data; |
| 1386 | |
| 1387 | data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA); |
| 1388 | if (!data) { |
| 1389 | if (mutex_trylock(&dasd_path_verification_mutex)) { |
| 1390 | data = path_verification_worker; |
| 1391 | data->isglobal = 1; |
| 1392 | } else |
| 1393 | return -ENOMEM; |
| 1394 | } else { |
| 1395 | memset(data, 0, sizeof(*data)); |
| 1396 | data->isglobal = 0; |
| 1397 | } |
| 1398 | INIT_WORK(&data->worker, do_path_verification_work); |
| 1399 | dasd_get_device(device); |
| 1400 | data->device = device; |
| 1401 | data->tbvpm = lpm; |
| 1402 | schedule_work(&data->worker); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1406 | static int dasd_eckd_read_features(struct dasd_device *device) |
| 1407 | { |
| 1408 | struct dasd_psf_prssd_data *prssdp; |
| 1409 | struct dasd_rssd_features *features; |
| 1410 | struct dasd_ccw_req *cqr; |
| 1411 | struct ccw1 *ccw; |
| 1412 | int rc; |
| 1413 | struct dasd_eckd_private *private; |
| 1414 | |
| 1415 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 1416 | memset(&private->features, 0, sizeof(struct dasd_rssd_features)); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1417 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1418 | (sizeof(struct dasd_psf_prssd_data) + |
| 1419 | sizeof(struct dasd_rssd_features)), |
| 1420 | device); |
| 1421 | if (IS_ERR(cqr)) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1422 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not " |
| 1423 | "allocate initialization request"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1424 | return PTR_ERR(cqr); |
| 1425 | } |
| 1426 | cqr->startdev = device; |
| 1427 | cqr->memdev = device; |
| 1428 | cqr->block = NULL; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1429 | cqr->retries = 256; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1430 | cqr->expires = 10 * HZ; |
| 1431 | |
| 1432 | /* Prepare for Read Subsystem Data */ |
| 1433 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 1434 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 1435 | prssdp->order = PSF_ORDER_PRSSD; |
| 1436 | prssdp->suborder = 0x41; /* Read Feature Codes */ |
| 1437 | /* all other bytes of prssdp must be zero */ |
| 1438 | |
| 1439 | ccw = cqr->cpaddr; |
| 1440 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 1441 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 1442 | ccw->flags |= CCW_FLAG_CC; |
| 1443 | ccw->cda = (__u32)(addr_t) prssdp; |
| 1444 | |
| 1445 | /* Read Subsystem Data - feature codes */ |
| 1446 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 1447 | memset(features, 0, sizeof(struct dasd_rssd_features)); |
| 1448 | |
| 1449 | ccw++; |
| 1450 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 1451 | ccw->count = sizeof(struct dasd_rssd_features); |
| 1452 | ccw->cda = (__u32)(addr_t) features; |
| 1453 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1454 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1455 | cqr->status = DASD_CQR_FILLED; |
| 1456 | rc = dasd_sleep_on(cqr); |
| 1457 | if (rc == 0) { |
| 1458 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 1459 | features = (struct dasd_rssd_features *) (prssdp + 1); |
| 1460 | memcpy(&private->features, features, |
| 1461 | sizeof(struct dasd_rssd_features)); |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 1462 | } else |
| 1463 | dev_warn(&device->cdev->dev, "Reading device feature codes" |
| 1464 | " failed with rc=%d\n", rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1465 | dasd_sfree_request(cqr, cqr->memdev); |
| 1466 | return rc; |
| 1467 | } |
| 1468 | |
| 1469 | |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1470 | /* |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1471 | * Build CP for Perform Subsystem Function - SSC. |
| 1472 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1473 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, |
| 1474 | int enable_pav) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1475 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1476 | struct dasd_ccw_req *cqr; |
| 1477 | struct dasd_psf_ssc_data *psf_ssc_data; |
| 1478 | struct ccw1 *ccw; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1479 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1480 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1481 | sizeof(struct dasd_psf_ssc_data), |
| 1482 | device); |
| 1483 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1484 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1485 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1486 | "Could not allocate PSF-SSC request"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1487 | return cqr; |
| 1488 | } |
| 1489 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; |
| 1490 | psf_ssc_data->order = PSF_ORDER_SSC; |
Stefan Weinhuber | 626350b | 2009-12-07 12:51:50 +0100 | [diff] [blame] | 1491 | psf_ssc_data->suborder = 0xc0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1492 | if (enable_pav) { |
Stefan Weinhuber | 626350b | 2009-12-07 12:51:50 +0100 | [diff] [blame] | 1493 | psf_ssc_data->suborder |= 0x08; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1494 | psf_ssc_data->reserved[0] = 0x88; |
| 1495 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1496 | ccw = cqr->cpaddr; |
| 1497 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 1498 | ccw->cda = (__u32)(addr_t)psf_ssc_data; |
| 1499 | ccw->count = 66; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1500 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1501 | cqr->startdev = device; |
| 1502 | cqr->memdev = device; |
| 1503 | cqr->block = NULL; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1504 | cqr->retries = 256; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1505 | cqr->expires = 10*HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1506 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1507 | cqr->status = DASD_CQR_FILLED; |
| 1508 | return cqr; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /* |
| 1512 | * Perform Subsystem Function. |
| 1513 | * It is necessary to trigger CIO for channel revalidation since this |
| 1514 | * call might change behaviour of DASD devices. |
| 1515 | */ |
| 1516 | static int |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1517 | dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav, |
| 1518 | unsigned long flags) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1519 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1520 | struct dasd_ccw_req *cqr; |
| 1521 | int rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1522 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1523 | cqr = dasd_eckd_build_psf_ssc(device, enable_pav); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1524 | if (IS_ERR(cqr)) |
| 1525 | return PTR_ERR(cqr); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1526 | |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1527 | /* |
| 1528 | * set flags e.g. turn on failfast, to prevent blocking |
| 1529 | * the calling function should handle failed requests |
| 1530 | */ |
| 1531 | cqr->flags |= flags; |
| 1532 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1533 | rc = dasd_sleep_on(cqr); |
| 1534 | if (!rc) |
| 1535 | /* trigger CIO to reprobe devices */ |
| 1536 | css_schedule_reprobe(); |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1537 | else if (cqr->intrc == -EAGAIN) |
| 1538 | rc = -EAGAIN; |
| 1539 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1540 | dasd_sfree_request(cqr, cqr->memdev); |
| 1541 | return rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | /* |
| 1545 | * Valide storage server of current device. |
| 1546 | */ |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1547 | static int dasd_eckd_validate_server(struct dasd_device *device, |
| 1548 | unsigned long flags) |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1549 | { |
| 1550 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1551 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1552 | int enable_pav; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1553 | |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 1554 | private = (struct dasd_eckd_private *) device->private; |
| 1555 | if (private->uid.type == UA_BASE_PAV_ALIAS || |
| 1556 | private->uid.type == UA_HYPER_PAV_ALIAS) |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1557 | return 0; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1558 | if (dasd_nopav || MACHINE_IS_VM) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1559 | enable_pav = 0; |
| 1560 | else |
| 1561 | enable_pav = 1; |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1562 | rc = dasd_eckd_psf_ssc(device, enable_pav, flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1563 | |
Horst Hummel | 8e79a44 | 2006-08-24 13:22:36 +0200 | [diff] [blame] | 1564 | /* may be requested feature is not available on server, |
| 1565 | * therefore just report error and go ahead */ |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1566 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x " |
| 1567 | "returned rc=%d", private->uid.ssid, rc); |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1568 | return rc; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 1571 | /* |
| 1572 | * worker to do a validate server in case of a lost pathgroup |
| 1573 | */ |
| 1574 | static void dasd_eckd_do_validate_server(struct work_struct *work) |
| 1575 | { |
| 1576 | struct dasd_device *device = container_of(work, struct dasd_device, |
| 1577 | kick_validate); |
Stefan Haberland | ea4da6e | 2013-02-19 09:30:05 +0100 | [diff] [blame] | 1578 | unsigned long flags = 0; |
| 1579 | |
| 1580 | set_bit(DASD_CQR_FLAGS_FAILFAST, &flags); |
| 1581 | if (dasd_eckd_validate_server(device, flags) |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1582 | == -EAGAIN) { |
| 1583 | /* schedule worker again if failed */ |
| 1584 | schedule_work(&device->kick_validate); |
| 1585 | return; |
| 1586 | } |
| 1587 | |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 1588 | dasd_put_device(device); |
| 1589 | } |
| 1590 | |
| 1591 | static void dasd_eckd_kick_validate_server(struct dasd_device *device) |
| 1592 | { |
| 1593 | dasd_get_device(device); |
Stefan Haberland | 25e2cf1 | 2012-03-11 11:59:37 -0400 | [diff] [blame] | 1594 | /* exit if device not online or in offline processing */ |
| 1595 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || |
| 1596 | device->state < DASD_STATE_ONLINE) { |
| 1597 | dasd_put_device(device); |
| 1598 | return; |
| 1599 | } |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 1600 | /* queue call to do_validate_server to the kernel event daemon. */ |
| 1601 | schedule_work(&device->kick_validate); |
| 1602 | } |
| 1603 | |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 1604 | static u32 get_fcx_max_data(struct dasd_device *device) |
| 1605 | { |
| 1606 | #if defined(CONFIG_64BIT) |
| 1607 | int tpm, mdc; |
| 1608 | int fcx_in_css, fcx_in_gneq, fcx_in_features; |
| 1609 | struct dasd_eckd_private *private; |
| 1610 | |
| 1611 | if (dasd_nofcx) |
| 1612 | return 0; |
| 1613 | /* is transport mode supported? */ |
| 1614 | private = (struct dasd_eckd_private *) device->private; |
| 1615 | fcx_in_css = css_general_characteristics.fcx; |
| 1616 | fcx_in_gneq = private->gneq->reserved2[7] & 0x04; |
| 1617 | fcx_in_features = private->features.feature[40] & 0x80; |
| 1618 | tpm = fcx_in_css && fcx_in_gneq && fcx_in_features; |
| 1619 | |
| 1620 | if (!tpm) |
| 1621 | return 0; |
| 1622 | |
| 1623 | mdc = ccw_device_get_mdc(device->cdev, 0); |
| 1624 | if (mdc < 0) { |
| 1625 | dev_warn(&device->cdev->dev, "Detecting the maximum supported" |
| 1626 | " data size for zHPF requests failed\n"); |
| 1627 | return 0; |
| 1628 | } else |
| 1629 | return mdc * FCX_MAX_DATA_FACTOR; |
| 1630 | #else |
| 1631 | return 0; |
| 1632 | #endif |
| 1633 | } |
| 1634 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1635 | /* |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1636 | * Check device characteristics. |
| 1637 | * If the device is accessible using ECKD discipline, the device is enabled. |
| 1638 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | static int |
| 1640 | dasd_eckd_check_characteristics(struct dasd_device *device) |
| 1641 | { |
| 1642 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1643 | struct dasd_block *block; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1644 | struct dasd_uid temp_uid; |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 1645 | int rc, i; |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 1646 | int readonly; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 1647 | unsigned long value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 1649 | /* setup work queue for validate server*/ |
| 1650 | INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server); |
| 1651 | |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 1652 | if (!ccw_device_is_pathgroup(device->cdev)) { |
| 1653 | dev_warn(&device->cdev->dev, |
| 1654 | "A channel path group could not be established\n"); |
| 1655 | return -EIO; |
| 1656 | } |
| 1657 | if (!ccw_device_is_multipath(device->cdev)) { |
| 1658 | dev_info(&device->cdev->dev, |
| 1659 | "The DASD is not operating in multipath mode\n"); |
| 1660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | private = (struct dasd_eckd_private *) device->private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1662 | if (!private) { |
| 1663 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); |
| 1664 | if (!private) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1665 | dev_warn(&device->cdev->dev, |
| 1666 | "Allocating memory for private DASD data " |
| 1667 | "failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | return -ENOMEM; |
| 1669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | device->private = (void *) private; |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1671 | } else { |
| 1672 | memset(private, 0, sizeof(*private)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | } |
| 1674 | /* Invalidate status of initial analysis. */ |
| 1675 | private->init_cqr_status = -1; |
| 1676 | /* Set default cache operations. */ |
| 1677 | private->attrib.operation = DASD_NORMAL_CACHE; |
| 1678 | private->attrib.nr_cyl = 0; |
| 1679 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1680 | /* Read Configuration Data */ |
| 1681 | rc = dasd_eckd_read_conf(device); |
| 1682 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1683 | goto out_err1; |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1684 | |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 1685 | /* set default timeout */ |
| 1686 | device->default_expires = DASD_EXPIRES; |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 1687 | /* set default retry count */ |
| 1688 | device->default_retries = DASD_RETRIES; |
| 1689 | |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 1690 | if (private->gneq) { |
| 1691 | value = 1; |
| 1692 | for (i = 0; i < private->gneq->timeout.value; i++) |
| 1693 | value = 10 * value; |
| 1694 | value = value * private->gneq->timeout.number; |
| 1695 | /* do not accept useless values */ |
| 1696 | if (value != 0 && value <= DASD_EXPIRES_MAX) |
| 1697 | device->default_expires = value; |
| 1698 | } |
| 1699 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 1700 | dasd_eckd_get_uid(device, &temp_uid); |
| 1701 | if (temp_uid.type == UA_BASE_DEVICE) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1702 | block = dasd_alloc_block(); |
| 1703 | if (IS_ERR(block)) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1704 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
| 1705 | "could not allocate dasd " |
| 1706 | "block structure"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1707 | rc = PTR_ERR(block); |
| 1708 | goto out_err1; |
| 1709 | } |
| 1710 | device->block = block; |
| 1711 | block->base = device; |
| 1712 | } |
| 1713 | |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 1714 | /* register lcu with alias handling, enable PAV */ |
| 1715 | rc = dasd_alias_make_device_known_to_lcu(device); |
| 1716 | if (rc) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1717 | goto out_err2; |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 1718 | |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 1719 | dasd_eckd_validate_server(device, 0); |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 1720 | |
| 1721 | /* device may report different configuration data after LCU setup */ |
| 1722 | rc = dasd_eckd_read_conf(device); |
| 1723 | if (rc) |
| 1724 | goto out_err3; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1725 | |
| 1726 | /* Read Feature Codes */ |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 1727 | dasd_eckd_read_features(device); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1730 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
| 1731 | &private->rdc_data, 64); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1732 | if (rc) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1733 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
| 1734 | "Read device characteristic failed, rc=%d", rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1735 | goto out_err3; |
| 1736 | } |
Stefan Haberland | 34cd551 | 2011-08-03 16:44:23 +0200 | [diff] [blame] | 1737 | |
| 1738 | if ((device->features & DASD_FEATURE_USERAW) && |
| 1739 | !(private->rdc_data.facilities.RT_in_LR)) { |
| 1740 | dev_err(&device->cdev->dev, "The storage server does not " |
| 1741 | "support raw-track access\n"); |
| 1742 | rc = -EINVAL; |
| 1743 | goto out_err3; |
| 1744 | } |
| 1745 | |
Nikanth Karthikesan | 817f2c8 | 2010-09-20 11:44:00 +0530 | [diff] [blame] | 1746 | /* find the valid cylinder size */ |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 1747 | if (private->rdc_data.no_cyl == LV_COMPAT_CYL && |
| 1748 | private->rdc_data.long_no_cyl) |
| 1749 | private->real_cyl = private->rdc_data.long_no_cyl; |
| 1750 | else |
| 1751 | private->real_cyl = private->rdc_data.no_cyl; |
| 1752 | |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 1753 | private->fcx_max_data = get_fcx_max_data(device); |
| 1754 | |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 1755 | readonly = dasd_device_is_ro(device); |
| 1756 | if (readonly) |
| 1757 | set_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 1758 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1759 | dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 1760 | "with %d cylinders, %d heads, %d sectors%s\n", |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1761 | private->rdc_data.dev_type, |
| 1762 | private->rdc_data.dev_model, |
| 1763 | private->rdc_data.cu_type, |
| 1764 | private->rdc_data.cu_model.model, |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 1765 | private->real_cyl, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1766 | private->rdc_data.trk_per_cyl, |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 1767 | private->rdc_data.sec_per_trk, |
| 1768 | readonly ? ", read-only device" : ""); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1769 | return 0; |
| 1770 | |
| 1771 | out_err3: |
| 1772 | dasd_alias_disconnect_device_from_lcu(device); |
| 1773 | out_err2: |
| 1774 | dasd_free_block(device->block); |
| 1775 | device->block = NULL; |
| 1776 | out_err1: |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1777 | kfree(private->conf_data); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1778 | kfree(device->private); |
| 1779 | device->private = NULL; |
Horst Hummel | 3d05259 | 2006-04-27 18:40:28 -0700 | [diff] [blame] | 1780 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1783 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
| 1784 | { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1785 | struct dasd_eckd_private *private; |
| 1786 | |
| 1787 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1788 | dasd_alias_disconnect_device_from_lcu(device); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 1789 | private->ned = NULL; |
| 1790 | private->sneq = NULL; |
| 1791 | private->vdsneq = NULL; |
| 1792 | private->gneq = NULL; |
| 1793 | private->conf_len = 0; |
| 1794 | kfree(private->conf_data); |
| 1795 | private->conf_data = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | static struct dasd_ccw_req * |
| 1799 | dasd_eckd_analysis_ccw(struct dasd_device *device) |
| 1800 | { |
| 1801 | struct dasd_eckd_private *private; |
| 1802 | struct eckd_count *count_data; |
| 1803 | struct LO_eckd_data *LO_data; |
| 1804 | struct dasd_ccw_req *cqr; |
| 1805 | struct ccw1 *ccw; |
| 1806 | int cplength, datasize; |
| 1807 | int i; |
| 1808 | |
| 1809 | private = (struct dasd_eckd_private *) device->private; |
| 1810 | |
| 1811 | cplength = 8; |
| 1812 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1813 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | if (IS_ERR(cqr)) |
| 1815 | return cqr; |
| 1816 | ccw = cqr->cpaddr; |
| 1817 | /* Define extent for the first 3 tracks. */ |
| 1818 | define_extent(ccw++, cqr->data, 0, 2, |
| 1819 | DASD_ECKD_CCW_READ_COUNT, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1820 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | /* Locate record for the first 4 records on track 0. */ |
| 1822 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1823 | locate_record(ccw++, LO_data++, 0, 0, 4, |
| 1824 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1825 | |
| 1826 | count_data = private->count_area; |
| 1827 | for (i = 0; i < 4; i++) { |
| 1828 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1829 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1830 | ccw->flags = 0; |
| 1831 | ccw->count = 8; |
| 1832 | ccw->cda = (__u32)(addr_t) count_data; |
| 1833 | ccw++; |
| 1834 | count_data++; |
| 1835 | } |
| 1836 | |
| 1837 | /* Locate record for the first record on track 2. */ |
| 1838 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1839 | locate_record(ccw++, LO_data++, 2, 0, 1, |
| 1840 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
| 1841 | /* Read count ccw. */ |
| 1842 | ccw[-1].flags |= CCW_FLAG_CC; |
| 1843 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; |
| 1844 | ccw->flags = 0; |
| 1845 | ccw->count = 8; |
| 1846 | ccw->cda = (__u32)(addr_t) count_data; |
| 1847 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1848 | cqr->block = NULL; |
| 1849 | cqr->startdev = device; |
| 1850 | cqr->memdev = device; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1851 | cqr->retries = 255; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1852 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | cqr->status = DASD_CQR_FILLED; |
| 1854 | return cqr; |
| 1855 | } |
| 1856 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1857 | /* differentiate between 'no record found' and any other error */ |
| 1858 | static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr) |
| 1859 | { |
| 1860 | char *sense; |
| 1861 | if (init_cqr->status == DASD_CQR_DONE) |
| 1862 | return INIT_CQR_OK; |
| 1863 | else if (init_cqr->status == DASD_CQR_NEED_ERP || |
| 1864 | init_cqr->status == DASD_CQR_FAILED) { |
| 1865 | sense = dasd_get_sense(&init_cqr->irb); |
| 1866 | if (sense && (sense[1] & SNS1_NO_REC_FOUND)) |
| 1867 | return INIT_CQR_UNFORMATTED; |
| 1868 | else |
| 1869 | return INIT_CQR_ERROR; |
| 1870 | } else |
| 1871 | return INIT_CQR_ERROR; |
| 1872 | } |
| 1873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | /* |
| 1875 | * This is the callback function for the init_analysis cqr. It saves |
| 1876 | * the status of the initial analysis ccw before it frees it and kicks |
| 1877 | * the device to continue the startup sequence. This will call |
| 1878 | * dasd_eckd_do_analysis again (if the devices has not been marked |
| 1879 | * for deletion in the meantime). |
| 1880 | */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1881 | static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, |
| 1882 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | { |
| 1884 | struct dasd_eckd_private *private; |
| 1885 | struct dasd_device *device; |
| 1886 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1887 | device = init_cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1889 | private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | dasd_sfree_request(init_cqr, device); |
| 1891 | dasd_kick_device(device); |
| 1892 | } |
| 1893 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1894 | static int dasd_eckd_start_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | struct dasd_ccw_req *init_cqr; |
| 1897 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1898 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | if (IS_ERR(init_cqr)) |
| 1900 | return PTR_ERR(init_cqr); |
| 1901 | init_cqr->callback = dasd_eckd_analysis_callback; |
| 1902 | init_cqr->callback_data = NULL; |
| 1903 | init_cqr->expires = 5*HZ; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1904 | /* first try without ERP, so we can later handle unformatted |
| 1905 | * devices as special case |
| 1906 | */ |
| 1907 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags); |
| 1908 | init_cqr->retries = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | dasd_add_request_head(init_cqr); |
| 1910 | return -EAGAIN; |
| 1911 | } |
| 1912 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1913 | static int dasd_eckd_end_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1915 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | struct dasd_eckd_private *private; |
| 1917 | struct eckd_count *count_area; |
| 1918 | unsigned int sb, blk_per_trk; |
| 1919 | int status, i; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1920 | struct dasd_ccw_req *init_cqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1922 | device = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | private = (struct dasd_eckd_private *) device->private; |
| 1924 | status = private->init_cqr_status; |
| 1925 | private->init_cqr_status = -1; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1926 | if (status == INIT_CQR_ERROR) { |
| 1927 | /* try again, this time with full ERP */ |
| 1928 | init_cqr = dasd_eckd_analysis_ccw(device); |
| 1929 | dasd_sleep_on(init_cqr); |
| 1930 | status = dasd_eckd_analysis_evaluation(init_cqr); |
| 1931 | dasd_sfree_request(init_cqr, device); |
| 1932 | } |
| 1933 | |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 1934 | if (device->features & DASD_FEATURE_USERAW) { |
| 1935 | block->bp_block = DASD_RAW_BLOCKSIZE; |
| 1936 | blk_per_trk = DASD_RAW_BLOCK_PER_TRACK; |
| 1937 | block->s2b_shift = 3; |
| 1938 | goto raw; |
| 1939 | } |
| 1940 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1941 | if (status == INIT_CQR_UNFORMATTED) { |
| 1942 | dev_warn(&device->cdev->dev, "The DASD is not formatted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | return -EMEDIUMTYPE; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1944 | } else if (status == INIT_CQR_ERROR) { |
| 1945 | dev_err(&device->cdev->dev, |
| 1946 | "Detecting the DASD disk layout failed because " |
| 1947 | "of an I/O error\n"); |
| 1948 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | private->uses_cdl = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | /* Check Track 0 for Compatible Disk Layout */ |
| 1953 | count_area = NULL; |
| 1954 | for (i = 0; i < 3; i++) { |
| 1955 | if (private->count_area[i].kl != 4 || |
Stefan Haberland | 3bc9fef9 | 2012-09-20 18:37:36 +0200 | [diff] [blame] | 1956 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 || |
| 1957 | private->count_area[i].cyl != 0 || |
| 1958 | private->count_area[i].head != count_area_head[i] || |
| 1959 | private->count_area[i].record != count_area_rec[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | private->uses_cdl = 0; |
| 1961 | break; |
| 1962 | } |
| 1963 | } |
| 1964 | if (i == 3) |
| 1965 | count_area = &private->count_area[4]; |
| 1966 | |
| 1967 | if (private->uses_cdl == 0) { |
| 1968 | for (i = 0; i < 5; i++) { |
| 1969 | if ((private->count_area[i].kl != 0) || |
| 1970 | (private->count_area[i].dl != |
Stefan Haberland | 3bc9fef9 | 2012-09-20 18:37:36 +0200 | [diff] [blame] | 1971 | private->count_area[0].dl) || |
| 1972 | private->count_area[i].cyl != 0 || |
| 1973 | private->count_area[i].head != count_area_head[i] || |
| 1974 | private->count_area[i].record != count_area_rec[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | break; |
| 1976 | } |
| 1977 | if (i == 5) |
| 1978 | count_area = &private->count_area[0]; |
| 1979 | } else { |
| 1980 | if (private->count_area[3].record == 1) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1981 | dev_warn(&device->cdev->dev, |
| 1982 | "Track 0 has no records following the VTOC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | } |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 1984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | if (count_area != NULL && count_area->kl == 0) { |
| 1986 | /* we found notthing violating our disk layout */ |
| 1987 | if (dasd_check_blocksize(count_area->dl) == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1988 | block->bp_block = count_area->dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1990 | if (block->bp_block == 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1991 | dev_warn(&device->cdev->dev, |
| 1992 | "The disk layout of the DASD is not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | return -EMEDIUMTYPE; |
| 1994 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1995 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 1996 | for (sb = 512; sb < block->bp_block; sb = sb << 1) |
| 1997 | block->s2b_shift++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1999 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 2000 | |
| 2001 | raw: |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 2002 | block->blocks = (private->real_cyl * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | private->rdc_data.trk_per_cyl * |
| 2004 | blk_per_trk); |
| 2005 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2006 | dev_info(&device->cdev->dev, |
| 2007 | "DASD with %d KB/block, %d KB total size, %d KB/track, " |
| 2008 | "%s\n", (block->bp_block >> 10), |
| 2009 | ((private->real_cyl * |
| 2010 | private->rdc_data.trk_per_cyl * |
| 2011 | blk_per_trk * (block->bp_block >> 9)) >> 1), |
| 2012 | ((blk_per_trk * block->bp_block) >> 10), |
| 2013 | private->uses_cdl ? |
| 2014 | "compatible disk layout" : "linux disk layout"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
| 2016 | return 0; |
| 2017 | } |
| 2018 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2019 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | { |
| 2021 | struct dasd_eckd_private *private; |
| 2022 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2023 | private = (struct dasd_eckd_private *) block->base->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | if (private->init_cqr_status < 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2025 | return dasd_eckd_start_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2027 | return dasd_eckd_end_analysis(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2030 | static int dasd_eckd_basic_to_ready(struct dasd_device *device) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2031 | { |
| 2032 | return dasd_alias_add_device(device); |
| 2033 | }; |
| 2034 | |
| 2035 | static int dasd_eckd_online_to_ready(struct dasd_device *device) |
| 2036 | { |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 2037 | cancel_work_sync(&device->reload_device); |
Stefan Haberland | 25e2cf1 | 2012-03-11 11:59:37 -0400 | [diff] [blame] | 2038 | cancel_work_sync(&device->kick_validate); |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2039 | return 0; |
| 2040 | }; |
| 2041 | |
| 2042 | static int dasd_eckd_ready_to_basic(struct dasd_device *device) |
| 2043 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2044 | return dasd_alias_remove_device(device); |
| 2045 | }; |
| 2046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2048 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | { |
| 2050 | struct dasd_eckd_private *private; |
| 2051 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2052 | private = (struct dasd_eckd_private *) block->base->private; |
| 2053 | if (dasd_check_blocksize(block->bp_block) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | geo->sectors = recs_per_track(&private->rdc_data, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2055 | 0, block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | geo->cylinders = private->rdc_data.no_cyl; |
| 2058 | geo->heads = private->rdc_data.trk_per_cyl; |
| 2059 | return 0; |
| 2060 | } |
| 2061 | |
| 2062 | static struct dasd_ccw_req * |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2063 | dasd_eckd_build_format(struct dasd_device *base, |
| 2064 | struct format_data_t *fdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | { |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2066 | struct dasd_eckd_private *base_priv; |
| 2067 | struct dasd_eckd_private *start_priv; |
| 2068 | struct dasd_device *startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | struct dasd_ccw_req *fcp; |
| 2070 | struct eckd_count *ect; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2071 | struct ch_t address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | struct ccw1 *ccw; |
| 2073 | void *data; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 2074 | int rpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | int cplength, datasize; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2076 | int i, j; |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2077 | int intensity = 0; |
| 2078 | int r0_perm; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2079 | int nr_tracks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2081 | startdev = dasd_alias_get_start_dev(base); |
| 2082 | if (!startdev) |
| 2083 | startdev = base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2085 | start_priv = (struct dasd_eckd_private *) startdev->private; |
| 2086 | base_priv = (struct dasd_eckd_private *) base->private; |
| 2087 | |
| 2088 | rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize); |
| 2089 | |
| 2090 | nr_tracks = fdata->stop_unit - fdata->start_unit + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | |
| 2092 | /* |
| 2093 | * fdata->intensity is a bit string that tells us what to do: |
| 2094 | * Bit 0: write record zero |
| 2095 | * Bit 1: write home address, currently not supported |
| 2096 | * Bit 2: invalidate tracks |
| 2097 | * Bit 3: use OS/390 compatible disk layout (cdl) |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2098 | * Bit 4: do not allow storage subsystem to modify record zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | * Only some bit combinations do make sense. |
| 2100 | */ |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2101 | if (fdata->intensity & 0x10) { |
| 2102 | r0_perm = 0; |
| 2103 | intensity = fdata->intensity & ~0x10; |
| 2104 | } else { |
| 2105 | r0_perm = 1; |
| 2106 | intensity = fdata->intensity; |
| 2107 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2108 | |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2109 | switch (intensity) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | case 0x00: /* Normal format */ |
| 2111 | case 0x08: /* Normal format, use cdl. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2112 | cplength = 2 + (rpt*nr_tracks); |
| 2113 | datasize = sizeof(struct PFX_eckd_data) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | sizeof(struct LO_eckd_data) + |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2115 | rpt * nr_tracks * sizeof(struct eckd_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | break; |
| 2117 | case 0x01: /* Write record zero and format track. */ |
| 2118 | case 0x09: /* Write record zero and format track, use cdl. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2119 | cplength = 2 + rpt * nr_tracks; |
| 2120 | datasize = sizeof(struct PFX_eckd_data) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | sizeof(struct LO_eckd_data) + |
| 2122 | sizeof(struct eckd_count) + |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2123 | rpt * nr_tracks * sizeof(struct eckd_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | break; |
| 2125 | case 0x04: /* Invalidate track. */ |
| 2126 | case 0x0c: /* Invalidate track, use cdl. */ |
| 2127 | cplength = 3; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2128 | datasize = sizeof(struct PFX_eckd_data) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | sizeof(struct LO_eckd_data) + |
| 2130 | sizeof(struct eckd_count); |
| 2131 | break; |
| 2132 | default: |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2133 | dev_warn(&startdev->cdev->dev, |
| 2134 | "An I/O control call used incorrect flags 0x%x\n", |
| 2135 | fdata->intensity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | return ERR_PTR(-EINVAL); |
| 2137 | } |
| 2138 | /* Allocate the format ccw request. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2139 | fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, |
| 2140 | datasize, startdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | if (IS_ERR(fcp)) |
| 2142 | return fcp; |
| 2143 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2144 | start_priv->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | data = fcp->data; |
| 2146 | ccw = fcp->cpaddr; |
| 2147 | |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2148 | switch (intensity & ~0x08) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | case 0x00: /* Normal format. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2150 | prefix(ccw++, (struct PFX_eckd_data *) data, |
| 2151 | fdata->start_unit, fdata->stop_unit, |
| 2152 | DASD_ECKD_CCW_WRITE_CKD, base, startdev); |
Jean-Baptiste Joret | f9a28f7 | 2009-03-26 15:23:46 +0100 | [diff] [blame] | 2153 | /* grant subsystem permission to format R0 */ |
| 2154 | if (r0_perm) |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2155 | ((struct PFX_eckd_data *)data) |
| 2156 | ->define_extent.ga_extended |= 0x04; |
| 2157 | data += sizeof(struct PFX_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2159 | locate_record(ccw++, (struct LO_eckd_data *) data, |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2160 | fdata->start_unit, 0, rpt*nr_tracks, |
| 2161 | DASD_ECKD_CCW_WRITE_CKD, base, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | fdata->blksize); |
| 2163 | data += sizeof(struct LO_eckd_data); |
| 2164 | break; |
| 2165 | case 0x01: /* Write record zero + format track. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2166 | prefix(ccw++, (struct PFX_eckd_data *) data, |
| 2167 | fdata->start_unit, fdata->stop_unit, |
| 2168 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, |
| 2169 | base, startdev); |
| 2170 | data += sizeof(struct PFX_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2172 | locate_record(ccw++, (struct LO_eckd_data *) data, |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2173 | fdata->start_unit, 0, rpt * nr_tracks + 1, |
| 2174 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, base, |
| 2175 | base->block->bp_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | data += sizeof(struct LO_eckd_data); |
| 2177 | break; |
| 2178 | case 0x04: /* Invalidate track. */ |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2179 | prefix(ccw++, (struct PFX_eckd_data *) data, |
| 2180 | fdata->start_unit, fdata->stop_unit, |
| 2181 | DASD_ECKD_CCW_WRITE_CKD, base, startdev); |
| 2182 | data += sizeof(struct PFX_eckd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2184 | locate_record(ccw++, (struct LO_eckd_data *) data, |
| 2185 | fdata->start_unit, 0, 1, |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2186 | DASD_ECKD_CCW_WRITE_CKD, base, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | data += sizeof(struct LO_eckd_data); |
| 2188 | break; |
| 2189 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2190 | |
| 2191 | for (j = 0; j < nr_tracks; j++) { |
| 2192 | /* calculate cylinder and head for the current track */ |
| 2193 | set_ch_t(&address, |
| 2194 | (fdata->start_unit + j) / |
| 2195 | base_priv->rdc_data.trk_per_cyl, |
| 2196 | (fdata->start_unit + j) % |
| 2197 | base_priv->rdc_data.trk_per_cyl); |
| 2198 | if (intensity & 0x01) { /* write record zero */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | ect = (struct eckd_count *) data; |
| 2200 | data += sizeof(struct eckd_count); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 2201 | ect->cyl = address.cyl; |
| 2202 | ect->head = address.head; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2203 | ect->record = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | ect->kl = 0; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2205 | ect->dl = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | ccw[-1].flags |= CCW_FLAG_CC; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2207 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | ccw->flags = CCW_FLAG_SLI; |
| 2209 | ccw->count = 8; |
| 2210 | ccw->cda = (__u32)(addr_t) ect; |
| 2211 | ccw++; |
| 2212 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2213 | if ((intensity & ~0x08) & 0x04) { /* erase track */ |
| 2214 | ect = (struct eckd_count *) data; |
| 2215 | data += sizeof(struct eckd_count); |
| 2216 | ect->cyl = address.cyl; |
| 2217 | ect->head = address.head; |
| 2218 | ect->record = 1; |
| 2219 | ect->kl = 0; |
| 2220 | ect->dl = 0; |
| 2221 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2222 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; |
| 2223 | ccw->flags = CCW_FLAG_SLI; |
| 2224 | ccw->count = 8; |
| 2225 | ccw->cda = (__u32)(addr_t) ect; |
| 2226 | } else { /* write remaining records */ |
| 2227 | for (i = 0; i < rpt; i++) { |
| 2228 | ect = (struct eckd_count *) data; |
| 2229 | data += sizeof(struct eckd_count); |
| 2230 | ect->cyl = address.cyl; |
| 2231 | ect->head = address.head; |
| 2232 | ect->record = i + 1; |
| 2233 | ect->kl = 0; |
| 2234 | ect->dl = fdata->blksize; |
| 2235 | /* |
| 2236 | * Check for special tracks 0-1 |
| 2237 | * when formatting CDL |
| 2238 | */ |
| 2239 | if ((intensity & 0x08) && |
| 2240 | fdata->start_unit == 0) { |
| 2241 | if (i < 3) { |
| 2242 | ect->kl = 4; |
| 2243 | ect->dl = sizes_trk0[i] - 4; |
| 2244 | } |
| 2245 | } |
| 2246 | if ((intensity & 0x08) && |
| 2247 | fdata->start_unit == 1) { |
| 2248 | ect->kl = 44; |
| 2249 | ect->dl = LABEL_SIZE - 44; |
| 2250 | } |
| 2251 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2252 | if (i != 0 || j == 0) |
| 2253 | ccw->cmd_code = |
| 2254 | DASD_ECKD_CCW_WRITE_CKD; |
| 2255 | else |
| 2256 | ccw->cmd_code = |
| 2257 | DASD_ECKD_CCW_WRITE_CKD_MT; |
| 2258 | ccw->flags = CCW_FLAG_SLI; |
| 2259 | ccw->count = 8; |
| 2260 | ccw->cda = (__u32)(addr_t) ect; |
| 2261 | ccw++; |
| 2262 | } |
| 2263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2265 | |
| 2266 | fcp->startdev = startdev; |
| 2267 | fcp->memdev = startdev; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2268 | fcp->retries = 256; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2269 | fcp->expires = startdev->default_expires * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2270 | fcp->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | fcp->status = DASD_CQR_FILLED; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | return fcp; |
| 2274 | } |
| 2275 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2276 | static int |
| 2277 | dasd_eckd_format_device(struct dasd_device *base, |
| 2278 | struct format_data_t *fdata) |
| 2279 | { |
| 2280 | struct dasd_ccw_req *cqr, *n; |
| 2281 | struct dasd_block *block; |
| 2282 | struct dasd_eckd_private *private; |
| 2283 | struct list_head format_queue; |
| 2284 | struct dasd_device *device; |
| 2285 | int old_stop, format_step; |
| 2286 | int step, rc = 0; |
| 2287 | |
| 2288 | block = base->block; |
| 2289 | private = (struct dasd_eckd_private *) base->private; |
| 2290 | |
| 2291 | /* Sanity checks. */ |
| 2292 | if (fdata->start_unit >= |
| 2293 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { |
| 2294 | dev_warn(&base->cdev->dev, |
| 2295 | "Start track number %u used in formatting is too big\n", |
| 2296 | fdata->start_unit); |
| 2297 | return -EINVAL; |
| 2298 | } |
| 2299 | if (fdata->stop_unit >= |
| 2300 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { |
| 2301 | dev_warn(&base->cdev->dev, |
| 2302 | "Stop track number %u used in formatting is too big\n", |
| 2303 | fdata->stop_unit); |
| 2304 | return -EINVAL; |
| 2305 | } |
| 2306 | if (fdata->start_unit > fdata->stop_unit) { |
| 2307 | dev_warn(&base->cdev->dev, |
| 2308 | "Start track %u used in formatting exceeds end track\n", |
| 2309 | fdata->start_unit); |
| 2310 | return -EINVAL; |
| 2311 | } |
| 2312 | if (dasd_check_blocksize(fdata->blksize) != 0) { |
| 2313 | dev_warn(&base->cdev->dev, |
| 2314 | "The DASD cannot be formatted with block size %u\n", |
| 2315 | fdata->blksize); |
| 2316 | return -EINVAL; |
| 2317 | } |
| 2318 | |
| 2319 | INIT_LIST_HEAD(&format_queue); |
| 2320 | old_stop = fdata->stop_unit; |
| 2321 | |
| 2322 | while (fdata->start_unit <= 1) { |
| 2323 | fdata->stop_unit = fdata->start_unit; |
| 2324 | cqr = dasd_eckd_build_format(base, fdata); |
| 2325 | list_add(&cqr->blocklist, &format_queue); |
| 2326 | |
| 2327 | fdata->stop_unit = old_stop; |
| 2328 | fdata->start_unit++; |
| 2329 | |
| 2330 | if (fdata->start_unit > fdata->stop_unit) |
| 2331 | goto sleep; |
| 2332 | } |
| 2333 | |
| 2334 | retry: |
| 2335 | format_step = 255 / recs_per_track(&private->rdc_data, 0, |
| 2336 | fdata->blksize); |
| 2337 | while (fdata->start_unit <= old_stop) { |
| 2338 | step = fdata->stop_unit - fdata->start_unit + 1; |
| 2339 | if (step > format_step) |
| 2340 | fdata->stop_unit = fdata->start_unit + format_step - 1; |
| 2341 | |
| 2342 | cqr = dasd_eckd_build_format(base, fdata); |
| 2343 | if (IS_ERR(cqr)) { |
| 2344 | if (PTR_ERR(cqr) == -ENOMEM) { |
| 2345 | /* |
| 2346 | * not enough memory available |
| 2347 | * go to out and start requests |
| 2348 | * retry after first requests were finished |
| 2349 | */ |
| 2350 | fdata->stop_unit = old_stop; |
| 2351 | goto sleep; |
| 2352 | } else |
| 2353 | return PTR_ERR(cqr); |
| 2354 | } |
| 2355 | list_add(&cqr->blocklist, &format_queue); |
| 2356 | |
| 2357 | fdata->start_unit = fdata->stop_unit + 1; |
| 2358 | fdata->stop_unit = old_stop; |
| 2359 | } |
| 2360 | |
| 2361 | sleep: |
| 2362 | dasd_sleep_on_queue(&format_queue); |
| 2363 | |
| 2364 | list_for_each_entry_safe(cqr, n, &format_queue, blocklist) { |
| 2365 | device = cqr->startdev; |
| 2366 | private = (struct dasd_eckd_private *) device->private; |
| 2367 | if (cqr->status == DASD_CQR_FAILED) |
| 2368 | rc = -EIO; |
| 2369 | list_del_init(&cqr->blocklist); |
| 2370 | dasd_sfree_request(cqr, device); |
| 2371 | private->count--; |
| 2372 | } |
| 2373 | |
| 2374 | /* |
| 2375 | * in case of ENOMEM we need to retry after |
| 2376 | * first requests are finished |
| 2377 | */ |
| 2378 | if (fdata->start_unit <= fdata->stop_unit) |
| 2379 | goto retry; |
| 2380 | |
| 2381 | return rc; |
| 2382 | } |
| 2383 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2384 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | { |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 2386 | if (cqr->retries < 0) { |
| 2387 | cqr->status = DASD_CQR_FAILED; |
| 2388 | return; |
| 2389 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2390 | cqr->status = DASD_CQR_FILLED; |
| 2391 | if (cqr->block && (cqr->startdev != cqr->block->base)) { |
| 2392 | dasd_eckd_reset_ccw_to_base_io(cqr); |
| 2393 | cqr->startdev = cqr->block->base; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2394 | cqr->lpm = cqr->block->base->path_data.opm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2396 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | |
| 2398 | static dasd_erp_fn_t |
| 2399 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) |
| 2400 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2401 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | struct ccw_device *cdev = device->cdev; |
| 2403 | |
| 2404 | switch (cdev->id.cu_type) { |
| 2405 | case 0x3990: |
| 2406 | case 0x2105: |
| 2407 | case 0x2107: |
| 2408 | case 0x1750: |
| 2409 | return dasd_3990_erp_action; |
| 2410 | case 0x9343: |
| 2411 | case 0x3880: |
| 2412 | default: |
| 2413 | return dasd_default_erp_action; |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | static dasd_erp_fn_t |
| 2418 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) |
| 2419 | { |
| 2420 | return dasd_default_erp_postaction; |
| 2421 | } |
| 2422 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2423 | static void dasd_eckd_check_for_device_change(struct dasd_device *device, |
| 2424 | struct dasd_ccw_req *cqr, |
| 2425 | struct irb *irb) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2426 | { |
| 2427 | char mask; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2428 | char *sense = NULL; |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 2429 | struct dasd_eckd_private *private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2430 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 2431 | private = (struct dasd_eckd_private *) device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2432 | /* first of all check for state change pending interrupt */ |
| 2433 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2434 | if ((scsw_dstat(&irb->scsw) & mask) == mask) { |
Stefan Haberland | c8d1c0f | 2011-10-30 15:17:09 +0100 | [diff] [blame] | 2435 | /* |
| 2436 | * for alias only, not in offline processing |
| 2437 | * and only if not suspended |
| 2438 | */ |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 2439 | if (!device->block && private->lcu && |
Stefan Haberland | 25e2cf1 | 2012-03-11 11:59:37 -0400 | [diff] [blame] | 2440 | device->state == DASD_STATE_ONLINE && |
Stefan Haberland | c8d1c0f | 2011-10-30 15:17:09 +0100 | [diff] [blame] | 2441 | !test_bit(DASD_FLAG_OFFLINE, &device->flags) && |
| 2442 | !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 2443 | /* |
| 2444 | * the state change could be caused by an alias |
| 2445 | * reassignment remove device from alias handling |
| 2446 | * to prevent new requests from being scheduled on |
| 2447 | * the wrong alias device |
| 2448 | */ |
| 2449 | dasd_alias_remove_device(device); |
| 2450 | |
| 2451 | /* schedule worker to reload device */ |
| 2452 | dasd_reload_device(device); |
| 2453 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2454 | dasd_generic_handle_state_change(device); |
| 2455 | return; |
| 2456 | } |
| 2457 | |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 2458 | sense = dasd_get_sense(irb); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2459 | if (!sense) |
| 2460 | return; |
| 2461 | |
| 2462 | /* summary unit check */ |
Stefan Weinhuber | c7a29e5 | 2011-04-20 10:15:35 +0200 | [diff] [blame] | 2463 | if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) && |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 2464 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2465 | dasd_alias_handle_summary_unit_check(device, irb); |
| 2466 | return; |
| 2467 | } |
| 2468 | |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 2469 | /* service information message SIM */ |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2470 | if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) && |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2471 | ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
| 2472 | dasd_3990_erp_handle_sim(device, sense); |
Stefan Haberland | f60c768 | 2008-04-17 07:46:08 +0200 | [diff] [blame] | 2473 | return; |
| 2474 | } |
| 2475 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2476 | /* loss of device reservation is handled via base devices only |
| 2477 | * as alias devices may be used with several bases |
| 2478 | */ |
Stefan Weinhuber | c7a29e5 | 2011-04-20 10:15:35 +0200 | [diff] [blame] | 2479 | if (device->block && (sense[27] & DASD_SENSE_BIT_0) && |
| 2480 | (sense[7] == 0x3F) && |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2481 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
| 2482 | test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) { |
| 2483 | if (device->features & DASD_FEATURE_FAILONSLCK) |
| 2484 | set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); |
| 2485 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); |
| 2486 | dev_err(&device->cdev->dev, |
| 2487 | "The device reservation was lost\n"); |
Stefan Haberland | ada3df9 | 2008-10-10 21:33:23 +0200 | [diff] [blame] | 2488 | } |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2489 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2490 | |
| 2491 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( |
| 2492 | struct dasd_device *startdev, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2493 | struct dasd_block *block, |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2494 | struct request *req, |
| 2495 | sector_t first_rec, |
| 2496 | sector_t last_rec, |
| 2497 | sector_t first_trk, |
| 2498 | sector_t last_trk, |
| 2499 | unsigned int first_offs, |
| 2500 | unsigned int last_offs, |
| 2501 | unsigned int blk_per_trk, |
| 2502 | unsigned int blksize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | { |
| 2504 | struct dasd_eckd_private *private; |
| 2505 | unsigned long *idaws; |
| 2506 | struct LO_eckd_data *LO_data; |
| 2507 | struct dasd_ccw_req *cqr; |
| 2508 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2509 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | struct bio_vec *bv; |
| 2511 | char *dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2512 | unsigned int off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | int count, cidaw, cplength, datasize; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2514 | sector_t recid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | unsigned char cmd, rcmd; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2516 | int use_prefix; |
| 2517 | struct dasd_device *basedev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2519 | basedev = block->base; |
| 2520 | private = (struct dasd_eckd_private *) basedev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | if (rq_data_dir(req) == READ) |
| 2522 | cmd = DASD_ECKD_CCW_READ_MT; |
| 2523 | else if (rq_data_dir(req) == WRITE) |
| 2524 | cmd = DASD_ECKD_CCW_WRITE_MT; |
| 2525 | else |
| 2526 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | /* Check struct bio and count the number of blocks for the request. */ |
| 2529 | count = 0; |
| 2530 | cidaw = 0; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2531 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 2532 | if (bv->bv_len & (blksize - 1)) |
| 2533 | /* Eckd can only do full blocks. */ |
| 2534 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2535 | count += bv->bv_len >> (block->s2b_shift + 9); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 2536 | #if defined(CONFIG_64BIT) |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 2537 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2538 | cidaw += bv->bv_len >> (block->s2b_shift + 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | } |
| 2541 | /* Paranoia. */ |
| 2542 | if (count != last_rec - first_rec + 1) |
| 2543 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2544 | |
| 2545 | /* use the prefix command if available */ |
| 2546 | use_prefix = private->features.feature[8] & 0x01; |
| 2547 | if (use_prefix) { |
| 2548 | /* 1x prefix + number of blocks */ |
| 2549 | cplength = 2 + count; |
| 2550 | /* 1x prefix + cidaws*sizeof(long) */ |
| 2551 | datasize = sizeof(struct PFX_eckd_data) + |
| 2552 | sizeof(struct LO_eckd_data) + |
| 2553 | cidaw * sizeof(unsigned long); |
| 2554 | } else { |
| 2555 | /* 1x define extent + 1x locate record + number of blocks */ |
| 2556 | cplength = 2 + count; |
| 2557 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ |
| 2558 | datasize = sizeof(struct DE_eckd_data) + |
| 2559 | sizeof(struct LO_eckd_data) + |
| 2560 | cidaw * sizeof(unsigned long); |
| 2561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | /* Find out the number of additional locate record ccws for cdl. */ |
| 2563 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { |
| 2564 | if (last_rec >= 2*blk_per_trk) |
| 2565 | count = 2*blk_per_trk - first_rec; |
| 2566 | cplength += count; |
| 2567 | datasize += count*sizeof(struct LO_eckd_data); |
| 2568 | } |
| 2569 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2570 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 2571 | startdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | if (IS_ERR(cqr)) |
| 2573 | return cqr; |
| 2574 | ccw = cqr->cpaddr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2575 | /* First ccw is define extent or prefix. */ |
| 2576 | if (use_prefix) { |
| 2577 | if (prefix(ccw++, cqr->data, first_trk, |
| 2578 | last_trk, cmd, basedev, startdev) == -EAGAIN) { |
| 2579 | /* Clock not in sync and XRC is enabled. |
| 2580 | * Try again later. |
| 2581 | */ |
| 2582 | dasd_sfree_request(cqr, startdev); |
| 2583 | return ERR_PTR(-EAGAIN); |
| 2584 | } |
| 2585 | idaws = (unsigned long *) (cqr->data + |
| 2586 | sizeof(struct PFX_eckd_data)); |
| 2587 | } else { |
| 2588 | if (define_extent(ccw++, cqr->data, first_trk, |
Stefan Haberland | b38f27e | 2011-12-27 11:27:28 +0100 | [diff] [blame] | 2589 | last_trk, cmd, basedev) == -EAGAIN) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2590 | /* Clock not in sync and XRC is enabled. |
| 2591 | * Try again later. |
| 2592 | */ |
| 2593 | dasd_sfree_request(cqr, startdev); |
| 2594 | return ERR_PTR(-EAGAIN); |
| 2595 | } |
| 2596 | idaws = (unsigned long *) (cqr->data + |
| 2597 | sizeof(struct DE_eckd_data)); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 2598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | /* Build locate_record+read/write/ccws. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
| 2601 | recid = first_rec; |
| 2602 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { |
| 2603 | /* Only standard blocks so there is just one locate record. */ |
| 2604 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2605 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2606 | last_rec - recid + 1, cmd, basedev, blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | } |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2608 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2610 | if (dasd_page_cache) { |
| 2611 | char *copy = kmem_cache_alloc(dasd_page_cache, |
Christoph Lameter | 441e143 | 2006-12-06 20:33:19 -0800 | [diff] [blame] | 2612 | GFP_DMA | __GFP_NOWARN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | if (copy && rq_data_dir(req) == WRITE) |
| 2614 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); |
| 2615 | if (copy) |
| 2616 | dst = copy + bv->bv_offset; |
| 2617 | } |
| 2618 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 2619 | sector_t trkid = recid; |
| 2620 | unsigned int recoffs = sector_div(trkid, blk_per_trk); |
| 2621 | rcmd = cmd; |
| 2622 | count = blksize; |
| 2623 | /* Locate record for cdl special block ? */ |
| 2624 | if (private->uses_cdl && recid < 2*blk_per_trk) { |
| 2625 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ |
| 2626 | rcmd |= 0x8; |
| 2627 | count = dasd_eckd_cdl_reclen(recid); |
Horst Hummel | ec5883a | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 2628 | if (count < blksize && |
| 2629 | rq_data_dir(req) == READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | memset(dst + count, 0xe5, |
| 2631 | blksize - count); |
| 2632 | } |
| 2633 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2634 | locate_record(ccw++, LO_data++, |
| 2635 | trkid, recoffs + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2636 | 1, rcmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | } |
| 2638 | /* Locate record for standard blocks ? */ |
| 2639 | if (private->uses_cdl && recid == 2*blk_per_trk) { |
| 2640 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2641 | locate_record(ccw++, LO_data++, |
| 2642 | trkid, recoffs + 1, |
| 2643 | last_rec - recid + 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2644 | cmd, basedev, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | } |
| 2646 | /* Read/write ccw. */ |
| 2647 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2648 | ccw->cmd_code = rcmd; |
| 2649 | ccw->count = count; |
| 2650 | if (idal_is_needed(dst, blksize)) { |
| 2651 | ccw->cda = (__u32)(addr_t) idaws; |
| 2652 | ccw->flags = CCW_FLAG_IDA; |
| 2653 | idaws = idal_create_words(idaws, dst, blksize); |
| 2654 | } else { |
| 2655 | ccw->cda = (__u32)(addr_t) dst; |
| 2656 | ccw->flags = 0; |
| 2657 | } |
| 2658 | ccw++; |
| 2659 | dst += blksize; |
| 2660 | recid++; |
| 2661 | } |
| 2662 | } |
Holger Smolinski | 13de227 | 2009-01-09 12:14:51 +0100 | [diff] [blame] | 2663 | if (blk_noretry_request(req) || |
| 2664 | block->base->features & DASD_FEATURE_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2665 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2666 | cqr->startdev = startdev; |
| 2667 | cqr->memdev = startdev; |
| 2668 | cqr->block = block; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 2669 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2670 | cqr->lpm = startdev->path_data.ppm; |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 2671 | cqr->retries = startdev->default_retries; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2672 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | cqr->status = DASD_CQR_FILLED; |
| 2674 | return cqr; |
| 2675 | } |
| 2676 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2677 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( |
| 2678 | struct dasd_device *startdev, |
| 2679 | struct dasd_block *block, |
| 2680 | struct request *req, |
| 2681 | sector_t first_rec, |
| 2682 | sector_t last_rec, |
| 2683 | sector_t first_trk, |
| 2684 | sector_t last_trk, |
| 2685 | unsigned int first_offs, |
| 2686 | unsigned int last_offs, |
| 2687 | unsigned int blk_per_trk, |
| 2688 | unsigned int blksize) |
| 2689 | { |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2690 | unsigned long *idaws; |
| 2691 | struct dasd_ccw_req *cqr; |
| 2692 | struct ccw1 *ccw; |
| 2693 | struct req_iterator iter; |
| 2694 | struct bio_vec *bv; |
| 2695 | char *dst, *idaw_dst; |
| 2696 | unsigned int cidaw, cplength, datasize; |
| 2697 | unsigned int tlf; |
| 2698 | sector_t recid; |
| 2699 | unsigned char cmd; |
| 2700 | struct dasd_device *basedev; |
| 2701 | unsigned int trkcount, count, count_to_trk_end; |
| 2702 | unsigned int idaw_len, seg_len, part_len, len_to_track_end; |
| 2703 | unsigned char new_track, end_idaw; |
| 2704 | sector_t trkid; |
| 2705 | unsigned int recoffs; |
| 2706 | |
| 2707 | basedev = block->base; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2708 | if (rq_data_dir(req) == READ) |
| 2709 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 2710 | else if (rq_data_dir(req) == WRITE) |
| 2711 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 2712 | else |
| 2713 | return ERR_PTR(-EINVAL); |
| 2714 | |
| 2715 | /* Track based I/O needs IDAWs for each page, and not just for |
| 2716 | * 64 bit addresses. We need additional idals for pages |
| 2717 | * that get filled from two tracks, so we use the number |
| 2718 | * of records as upper limit. |
| 2719 | */ |
| 2720 | cidaw = last_rec - first_rec + 1; |
| 2721 | trkcount = last_trk - first_trk + 1; |
| 2722 | |
| 2723 | /* 1x prefix + one read/write ccw per track */ |
| 2724 | cplength = 1 + trkcount; |
| 2725 | |
| 2726 | /* on 31-bit we need space for two 32 bit addresses per page |
| 2727 | * on 64-bit one 64 bit address |
| 2728 | */ |
| 2729 | datasize = sizeof(struct PFX_eckd_data) + |
| 2730 | cidaw * sizeof(unsigned long long); |
| 2731 | |
| 2732 | /* Allocate the ccw request. */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 2733 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
| 2734 | startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2735 | if (IS_ERR(cqr)) |
| 2736 | return cqr; |
| 2737 | ccw = cqr->cpaddr; |
| 2738 | /* transfer length factor: how many bytes to read from the last track */ |
| 2739 | if (first_trk == last_trk) |
| 2740 | tlf = last_offs - first_offs + 1; |
| 2741 | else |
| 2742 | tlf = last_offs + 1; |
| 2743 | tlf *= blksize; |
| 2744 | |
| 2745 | if (prefix_LRE(ccw++, cqr->data, first_trk, |
| 2746 | last_trk, cmd, basedev, startdev, |
| 2747 | 1 /* format */, first_offs + 1, |
| 2748 | trkcount, blksize, |
| 2749 | tlf) == -EAGAIN) { |
| 2750 | /* Clock not in sync and XRC is enabled. |
| 2751 | * Try again later. |
| 2752 | */ |
| 2753 | dasd_sfree_request(cqr, startdev); |
| 2754 | return ERR_PTR(-EAGAIN); |
| 2755 | } |
| 2756 | |
| 2757 | /* |
| 2758 | * The translation of request into ccw programs must meet the |
| 2759 | * following conditions: |
| 2760 | * - all idaws but the first and the last must address full pages |
| 2761 | * (or 2K blocks on 31-bit) |
| 2762 | * - the scope of a ccw and it's idal ends with the track boundaries |
| 2763 | */ |
| 2764 | idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); |
| 2765 | recid = first_rec; |
| 2766 | new_track = 1; |
| 2767 | end_idaw = 0; |
| 2768 | len_to_track_end = 0; |
Martin Schwidefsky | 246ccea | 2011-10-30 15:17:16 +0100 | [diff] [blame] | 2769 | idaw_dst = NULL; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2770 | idaw_len = 0; |
| 2771 | rq_for_each_segment(bv, req, iter) { |
| 2772 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 2773 | seg_len = bv->bv_len; |
| 2774 | while (seg_len) { |
| 2775 | if (new_track) { |
| 2776 | trkid = recid; |
| 2777 | recoffs = sector_div(trkid, blk_per_trk); |
| 2778 | count_to_trk_end = blk_per_trk - recoffs; |
| 2779 | count = min((last_rec - recid + 1), |
| 2780 | (sector_t)count_to_trk_end); |
| 2781 | len_to_track_end = count * blksize; |
| 2782 | ccw[-1].flags |= CCW_FLAG_CC; |
| 2783 | ccw->cmd_code = cmd; |
| 2784 | ccw->count = len_to_track_end; |
| 2785 | ccw->cda = (__u32)(addr_t)idaws; |
| 2786 | ccw->flags = CCW_FLAG_IDA; |
| 2787 | ccw++; |
| 2788 | recid += count; |
| 2789 | new_track = 0; |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2790 | /* first idaw for a ccw may start anywhere */ |
| 2791 | if (!idaw_dst) |
| 2792 | idaw_dst = dst; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2793 | } |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2794 | /* If we start a new idaw, we must make sure that it |
| 2795 | * starts on an IDA_BLOCK_SIZE boundary. |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2796 | * If we continue an idaw, we must make sure that the |
| 2797 | * current segment begins where the so far accumulated |
| 2798 | * idaw ends |
| 2799 | */ |
Stefan Weinhuber | 52db45c | 2009-04-14 15:36:24 +0200 | [diff] [blame] | 2800 | if (!idaw_dst) { |
| 2801 | if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { |
| 2802 | dasd_sfree_request(cqr, startdev); |
| 2803 | return ERR_PTR(-ERANGE); |
| 2804 | } else |
| 2805 | idaw_dst = dst; |
| 2806 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2807 | if ((idaw_dst + idaw_len) != dst) { |
| 2808 | dasd_sfree_request(cqr, startdev); |
| 2809 | return ERR_PTR(-ERANGE); |
| 2810 | } |
| 2811 | part_len = min(seg_len, len_to_track_end); |
| 2812 | seg_len -= part_len; |
| 2813 | dst += part_len; |
| 2814 | idaw_len += part_len; |
| 2815 | len_to_track_end -= part_len; |
| 2816 | /* collected memory area ends on an IDA_BLOCK border, |
| 2817 | * -> create an idaw |
| 2818 | * idal_create_words will handle cases where idaw_len |
| 2819 | * is larger then IDA_BLOCK_SIZE |
| 2820 | */ |
| 2821 | if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) |
| 2822 | end_idaw = 1; |
| 2823 | /* We also need to end the idaw at track end */ |
| 2824 | if (!len_to_track_end) { |
| 2825 | new_track = 1; |
| 2826 | end_idaw = 1; |
| 2827 | } |
| 2828 | if (end_idaw) { |
| 2829 | idaws = idal_create_words(idaws, idaw_dst, |
| 2830 | idaw_len); |
Martin Schwidefsky | 246ccea | 2011-10-30 15:17:16 +0100 | [diff] [blame] | 2831 | idaw_dst = NULL; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2832 | idaw_len = 0; |
| 2833 | end_idaw = 0; |
| 2834 | } |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | if (blk_noretry_request(req) || |
| 2839 | block->base->features & DASD_FEATURE_FAILFAST) |
| 2840 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 2841 | cqr->startdev = startdev; |
| 2842 | cqr->memdev = startdev; |
| 2843 | cqr->block = block; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 2844 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2845 | cqr->lpm = startdev->path_data.ppm; |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 2846 | cqr->retries = startdev->default_retries; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2847 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2848 | cqr->status = DASD_CQR_FILLED; |
| 2849 | return cqr; |
| 2850 | } |
| 2851 | |
| 2852 | static int prepare_itcw(struct itcw *itcw, |
| 2853 | unsigned int trk, unsigned int totrk, int cmd, |
| 2854 | struct dasd_device *basedev, |
| 2855 | struct dasd_device *startdev, |
| 2856 | unsigned int rec_on_trk, int count, |
| 2857 | unsigned int blksize, |
| 2858 | unsigned int total_data_size, |
| 2859 | unsigned int tlf, |
| 2860 | unsigned int blk_per_trk) |
| 2861 | { |
| 2862 | struct PFX_eckd_data pfxdata; |
| 2863 | struct dasd_eckd_private *basepriv, *startpriv; |
| 2864 | struct DE_eckd_data *dedata; |
| 2865 | struct LRE_eckd_data *lredata; |
| 2866 | struct dcw *dcw; |
| 2867 | |
| 2868 | u32 begcyl, endcyl; |
| 2869 | u16 heads, beghead, endhead; |
| 2870 | u8 pfx_cmd; |
| 2871 | |
| 2872 | int rc = 0; |
| 2873 | int sector = 0; |
| 2874 | int dn, d; |
| 2875 | |
| 2876 | |
| 2877 | /* setup prefix data */ |
| 2878 | basepriv = (struct dasd_eckd_private *) basedev->private; |
| 2879 | startpriv = (struct dasd_eckd_private *) startdev->private; |
| 2880 | dedata = &pfxdata.define_extent; |
| 2881 | lredata = &pfxdata.locate_record; |
| 2882 | |
| 2883 | memset(&pfxdata, 0, sizeof(pfxdata)); |
| 2884 | pfxdata.format = 1; /* PFX with LRE */ |
| 2885 | pfxdata.base_address = basepriv->ned->unit_addr; |
| 2886 | pfxdata.base_lss = basepriv->ned->ID; |
| 2887 | pfxdata.validity.define_extent = 1; |
| 2888 | |
| 2889 | /* private uid is kept up to date, conf_data may be outdated */ |
| 2890 | if (startpriv->uid.type != UA_BASE_DEVICE) { |
| 2891 | pfxdata.validity.verify_base = 1; |
| 2892 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) |
| 2893 | pfxdata.validity.hyper_pav = 1; |
| 2894 | } |
| 2895 | |
| 2896 | switch (cmd) { |
| 2897 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
| 2898 | dedata->mask.perm = 0x1; |
| 2899 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2900 | dedata->blk_size = blksize; |
| 2901 | dedata->ga_extended |= 0x42; |
| 2902 | lredata->operation.orientation = 0x0; |
| 2903 | lredata->operation.operation = 0x0C; |
| 2904 | lredata->auxiliary.check_bytes = 0x01; |
| 2905 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; |
| 2906 | break; |
| 2907 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
| 2908 | dedata->mask.perm = 0x02; |
| 2909 | dedata->attributes.operation = basepriv->attrib.operation; |
| 2910 | dedata->blk_size = blksize; |
| 2911 | rc = check_XRC_on_prefix(&pfxdata, basedev); |
| 2912 | dedata->ga_extended |= 0x42; |
| 2913 | lredata->operation.orientation = 0x0; |
| 2914 | lredata->operation.operation = 0x3F; |
| 2915 | lredata->extended_operation = 0x23; |
| 2916 | lredata->auxiliary.check_bytes = 0x2; |
| 2917 | pfx_cmd = DASD_ECKD_CCW_PFX; |
| 2918 | break; |
| 2919 | default: |
| 2920 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 2921 | "prepare itcw, unknown opcode 0x%x", cmd); |
| 2922 | BUG(); |
| 2923 | break; |
| 2924 | } |
| 2925 | if (rc) |
| 2926 | return rc; |
| 2927 | |
| 2928 | dedata->attributes.mode = 0x3; /* ECKD */ |
| 2929 | |
| 2930 | heads = basepriv->rdc_data.trk_per_cyl; |
| 2931 | begcyl = trk / heads; |
| 2932 | beghead = trk % heads; |
| 2933 | endcyl = totrk / heads; |
| 2934 | endhead = totrk % heads; |
| 2935 | |
| 2936 | /* check for sequential prestage - enhance cylinder range */ |
| 2937 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
| 2938 | dedata->attributes.operation == DASD_SEQ_ACCESS) { |
| 2939 | |
| 2940 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
| 2941 | endcyl += basepriv->attrib.nr_cyl; |
| 2942 | else |
| 2943 | endcyl = (basepriv->real_cyl - 1); |
| 2944 | } |
| 2945 | |
| 2946 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
| 2947 | set_ch_t(&dedata->end_ext, endcyl, endhead); |
| 2948 | |
| 2949 | dedata->ep_format = 0x20; /* records per track is valid */ |
| 2950 | dedata->ep_rec_per_track = blk_per_trk; |
| 2951 | |
| 2952 | if (rec_on_trk) { |
| 2953 | switch (basepriv->rdc_data.dev_type) { |
| 2954 | case 0x3390: |
| 2955 | dn = ceil_quot(blksize + 6, 232); |
| 2956 | d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); |
| 2957 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; |
| 2958 | break; |
| 2959 | case 0x3380: |
| 2960 | d = 7 + ceil_quot(blksize + 12, 32); |
| 2961 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; |
| 2962 | break; |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | lredata->auxiliary.length_valid = 1; |
| 2967 | lredata->auxiliary.length_scope = 1; |
| 2968 | lredata->auxiliary.imbedded_ccw_valid = 1; |
| 2969 | lredata->length = tlf; |
| 2970 | lredata->imbedded_ccw = cmd; |
| 2971 | lredata->count = count; |
| 2972 | lredata->sector = sector; |
| 2973 | set_ch_t(&lredata->seek_addr, begcyl, beghead); |
| 2974 | lredata->search_arg.cyl = lredata->seek_addr.cyl; |
| 2975 | lredata->search_arg.head = lredata->seek_addr.head; |
| 2976 | lredata->search_arg.record = rec_on_trk; |
| 2977 | |
| 2978 | dcw = itcw_add_dcw(itcw, pfx_cmd, 0, |
| 2979 | &pfxdata, sizeof(pfxdata), total_data_size); |
Thomas Meyer | 82a7b95 | 2013-06-01 11:52:16 +0200 | [diff] [blame] | 2980 | return PTR_RET(dcw); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( |
| 2984 | struct dasd_device *startdev, |
| 2985 | struct dasd_block *block, |
| 2986 | struct request *req, |
| 2987 | sector_t first_rec, |
| 2988 | sector_t last_rec, |
| 2989 | sector_t first_trk, |
| 2990 | sector_t last_trk, |
| 2991 | unsigned int first_offs, |
| 2992 | unsigned int last_offs, |
| 2993 | unsigned int blk_per_trk, |
| 2994 | unsigned int blksize) |
| 2995 | { |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2996 | struct dasd_ccw_req *cqr; |
| 2997 | struct req_iterator iter; |
| 2998 | struct bio_vec *bv; |
| 2999 | char *dst; |
| 3000 | unsigned int trkcount, ctidaw; |
| 3001 | unsigned char cmd; |
| 3002 | struct dasd_device *basedev; |
| 3003 | unsigned int tlf; |
| 3004 | struct itcw *itcw; |
| 3005 | struct tidaw *last_tidaw = NULL; |
| 3006 | int itcw_op; |
| 3007 | size_t itcw_size; |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3008 | u8 tidaw_flags; |
| 3009 | unsigned int seg_len, part_len, len_to_track_end; |
| 3010 | unsigned char new_track; |
| 3011 | sector_t recid, trkid; |
| 3012 | unsigned int offs; |
| 3013 | unsigned int count, count_to_trk_end; |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3014 | int ret; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3015 | |
| 3016 | basedev = block->base; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3017 | if (rq_data_dir(req) == READ) { |
| 3018 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; |
| 3019 | itcw_op = ITCW_OP_READ; |
| 3020 | } else if (rq_data_dir(req) == WRITE) { |
| 3021 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; |
| 3022 | itcw_op = ITCW_OP_WRITE; |
| 3023 | } else |
| 3024 | return ERR_PTR(-EINVAL); |
| 3025 | |
| 3026 | /* trackbased I/O needs address all memory via TIDAWs, |
| 3027 | * not just for 64 bit addresses. This allows us to map |
| 3028 | * each segment directly to one tidaw. |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3029 | * In the case of write requests, additional tidaws may |
| 3030 | * be needed when a segment crosses a track boundary. |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3031 | */ |
| 3032 | trkcount = last_trk - first_trk + 1; |
| 3033 | ctidaw = 0; |
| 3034 | rq_for_each_segment(bv, req, iter) { |
| 3035 | ++ctidaw; |
| 3036 | } |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3037 | if (rq_data_dir(req) == WRITE) |
| 3038 | ctidaw += (last_trk - first_trk); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3039 | |
| 3040 | /* Allocate the ccw request. */ |
| 3041 | itcw_size = itcw_calc_size(0, ctidaw, 0); |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3042 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3043 | if (IS_ERR(cqr)) |
| 3044 | return cqr; |
| 3045 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3046 | /* transfer length factor: how many bytes to read from the last track */ |
| 3047 | if (first_trk == last_trk) |
| 3048 | tlf = last_offs - first_offs + 1; |
| 3049 | else |
| 3050 | tlf = last_offs + 1; |
| 3051 | tlf *= blksize; |
| 3052 | |
| 3053 | itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3054 | if (IS_ERR(itcw)) { |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3055 | ret = -EINVAL; |
| 3056 | goto out_error; |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3057 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3058 | cqr->cpaddr = itcw_get_tcw(itcw); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3059 | if (prepare_itcw(itcw, first_trk, last_trk, |
| 3060 | cmd, basedev, startdev, |
| 3061 | first_offs + 1, |
| 3062 | trkcount, blksize, |
| 3063 | (last_rec - first_rec + 1) * blksize, |
| 3064 | tlf, blk_per_trk) == -EAGAIN) { |
| 3065 | /* Clock not in sync and XRC is enabled. |
| 3066 | * Try again later. |
| 3067 | */ |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3068 | ret = -EAGAIN; |
| 3069 | goto out_error; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3070 | } |
Heiko Carstens | d54cddb | 2011-03-15 17:08:21 +0100 | [diff] [blame] | 3071 | len_to_track_end = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3072 | /* |
| 3073 | * A tidaw can address 4k of memory, but must not cross page boundaries |
| 3074 | * We can let the block layer handle this by setting |
| 3075 | * blk_queue_segment_boundary to page boundaries and |
| 3076 | * blk_max_segment_size to page size when setting up the request queue. |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3077 | * For write requests, a TIDAW must not cross track boundaries, because |
| 3078 | * we have to set the CBC flag on the last tidaw for each track. |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3079 | */ |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3080 | if (rq_data_dir(req) == WRITE) { |
| 3081 | new_track = 1; |
| 3082 | recid = first_rec; |
| 3083 | rq_for_each_segment(bv, req, iter) { |
| 3084 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 3085 | seg_len = bv->bv_len; |
| 3086 | while (seg_len) { |
| 3087 | if (new_track) { |
| 3088 | trkid = recid; |
| 3089 | offs = sector_div(trkid, blk_per_trk); |
| 3090 | count_to_trk_end = blk_per_trk - offs; |
| 3091 | count = min((last_rec - recid + 1), |
| 3092 | (sector_t)count_to_trk_end); |
| 3093 | len_to_track_end = count * blksize; |
| 3094 | recid += count; |
| 3095 | new_track = 0; |
| 3096 | } |
| 3097 | part_len = min(seg_len, len_to_track_end); |
| 3098 | seg_len -= part_len; |
| 3099 | len_to_track_end -= part_len; |
| 3100 | /* We need to end the tidaw at track end */ |
| 3101 | if (!len_to_track_end) { |
| 3102 | new_track = 1; |
| 3103 | tidaw_flags = TIDAW_FLAGS_INSERT_CBC; |
| 3104 | } else |
| 3105 | tidaw_flags = 0; |
| 3106 | last_tidaw = itcw_add_tidaw(itcw, tidaw_flags, |
| 3107 | dst, part_len); |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3108 | if (IS_ERR(last_tidaw)) { |
| 3109 | ret = -EINVAL; |
| 3110 | goto out_error; |
| 3111 | } |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3112 | dst += part_len; |
| 3113 | } |
| 3114 | } |
| 3115 | } else { |
| 3116 | rq_for_each_segment(bv, req, iter) { |
| 3117 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 3118 | last_tidaw = itcw_add_tidaw(itcw, 0x00, |
| 3119 | dst, bv->bv_len); |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3120 | if (IS_ERR(last_tidaw)) { |
| 3121 | ret = -EINVAL; |
| 3122 | goto out_error; |
| 3123 | } |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3124 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3125 | } |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3126 | last_tidaw->flags |= TIDAW_FLAGS_LAST; |
| 3127 | last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3128 | itcw_finalize(itcw); |
| 3129 | |
| 3130 | if (blk_noretry_request(req) || |
| 3131 | block->base->features & DASD_FEATURE_FAILFAST) |
| 3132 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3133 | cqr->cpmode = 1; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3134 | cqr->startdev = startdev; |
| 3135 | cqr->memdev = startdev; |
| 3136 | cqr->block = block; |
Stefan Haberland | 7c8faa8 | 2010-08-09 18:13:00 +0200 | [diff] [blame] | 3137 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3138 | cqr->lpm = startdev->path_data.ppm; |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 3139 | cqr->retries = startdev->default_retries; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3140 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3141 | cqr->status = DASD_CQR_FILLED; |
| 3142 | return cqr; |
Julia Lawall | cd10502 | 2012-04-11 14:28:04 +0200 | [diff] [blame] | 3143 | out_error: |
| 3144 | dasd_sfree_request(cqr, startdev); |
| 3145 | return ERR_PTR(ret); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, |
| 3149 | struct dasd_block *block, |
| 3150 | struct request *req) |
| 3151 | { |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3152 | int cmdrtd, cmdwtd; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3153 | int use_prefix; |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3154 | int fcx_multitrack; |
Stefan Weinhuber | 45b44d7 | 2009-06-12 10:26:36 +0200 | [diff] [blame] | 3155 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3156 | struct dasd_device *basedev; |
| 3157 | sector_t first_rec, last_rec; |
| 3158 | sector_t first_trk, last_trk; |
| 3159 | unsigned int first_offs, last_offs; |
| 3160 | unsigned int blk_per_trk, blksize; |
| 3161 | int cdlspecial; |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3162 | unsigned int data_size; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3163 | struct dasd_ccw_req *cqr; |
| 3164 | |
| 3165 | basedev = block->base; |
| 3166 | private = (struct dasd_eckd_private *) basedev->private; |
| 3167 | |
| 3168 | /* Calculate number of blocks/records per track. */ |
| 3169 | blksize = block->bp_block; |
| 3170 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 3171 | if (blk_per_trk == 0) |
| 3172 | return ERR_PTR(-EINVAL); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3173 | /* Calculate record id of first and last block. */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3174 | first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3175 | first_offs = sector_div(first_trk, blk_per_trk); |
| 3176 | last_rec = last_trk = |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3177 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3178 | last_offs = sector_div(last_trk, blk_per_trk); |
| 3179 | cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); |
| 3180 | |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3181 | fcx_multitrack = private->features.feature[40] & 0x20; |
| 3182 | data_size = blk_rq_bytes(req); |
| 3183 | /* tpm write request add CBC data on each track boundary */ |
| 3184 | if (rq_data_dir(req) == WRITE) |
| 3185 | data_size += (last_trk - first_trk) * 4; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3186 | |
| 3187 | /* is read track data and write track data in command mode supported? */ |
| 3188 | cmdrtd = private->features.feature[9] & 0x20; |
| 3189 | cmdwtd = private->features.feature[12] & 0x40; |
| 3190 | use_prefix = private->features.feature[8] & 0x01; |
| 3191 | |
| 3192 | cqr = NULL; |
| 3193 | if (cdlspecial || dasd_page_cache) { |
| 3194 | /* do nothing, just fall through to the cmd mode single case */ |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3195 | } else if ((data_size <= private->fcx_max_data) |
| 3196 | && (fcx_multitrack || (first_trk == last_trk))) { |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3197 | cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, |
| 3198 | first_rec, last_rec, |
| 3199 | first_trk, last_trk, |
| 3200 | first_offs, last_offs, |
| 3201 | blk_per_trk, blksize); |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3202 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
| 3203 | (PTR_ERR(cqr) != -ENOMEM)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3204 | cqr = NULL; |
| 3205 | } else if (use_prefix && |
| 3206 | (((rq_data_dir(req) == READ) && cmdrtd) || |
| 3207 | ((rq_data_dir(req) == WRITE) && cmdwtd))) { |
| 3208 | cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, |
| 3209 | first_rec, last_rec, |
| 3210 | first_trk, last_trk, |
| 3211 | first_offs, last_offs, |
| 3212 | blk_per_trk, blksize); |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 3213 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
| 3214 | (PTR_ERR(cqr) != -ENOMEM)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3215 | cqr = NULL; |
| 3216 | } |
| 3217 | if (!cqr) |
| 3218 | cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, |
| 3219 | first_rec, last_rec, |
| 3220 | first_trk, last_trk, |
| 3221 | first_offs, last_offs, |
| 3222 | blk_per_trk, blksize); |
| 3223 | return cqr; |
| 3224 | } |
| 3225 | |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3226 | static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev, |
| 3227 | struct dasd_block *block, |
| 3228 | struct request *req) |
| 3229 | { |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3230 | unsigned long *idaws; |
| 3231 | struct dasd_device *basedev; |
| 3232 | struct dasd_ccw_req *cqr; |
| 3233 | struct ccw1 *ccw; |
| 3234 | struct req_iterator iter; |
| 3235 | struct bio_vec *bv; |
| 3236 | char *dst; |
| 3237 | unsigned char cmd; |
| 3238 | unsigned int trkcount; |
| 3239 | unsigned int seg_len, len_to_track_end; |
| 3240 | unsigned int first_offs; |
| 3241 | unsigned int cidaw, cplength, datasize; |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3242 | sector_t first_trk, last_trk, sectors; |
| 3243 | sector_t start_padding_sectors, end_sector_offset, end_padding_sectors; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3244 | unsigned int pfx_datasize; |
| 3245 | |
| 3246 | /* |
| 3247 | * raw track access needs to be mutiple of 64k and on 64k boundary |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3248 | * For read requests we can fix an incorrect alignment by padding |
| 3249 | * the request with dummy pages. |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3250 | */ |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3251 | start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK; |
| 3252 | end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) % |
| 3253 | DASD_RAW_SECTORS_PER_TRACK; |
| 3254 | end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) % |
| 3255 | DASD_RAW_SECTORS_PER_TRACK; |
| 3256 | basedev = block->base; |
| 3257 | if ((start_padding_sectors || end_padding_sectors) && |
| 3258 | (rq_data_dir(req) == WRITE)) { |
| 3259 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3260 | "raw write not track aligned (%lu,%lu) req %p", |
| 3261 | start_padding_sectors, end_padding_sectors, req); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3262 | cqr = ERR_PTR(-EINVAL); |
| 3263 | goto out; |
| 3264 | } |
| 3265 | |
| 3266 | first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK; |
| 3267 | last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) / |
| 3268 | DASD_RAW_SECTORS_PER_TRACK; |
| 3269 | trkcount = last_trk - first_trk + 1; |
| 3270 | first_offs = 0; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3271 | |
| 3272 | if (rq_data_dir(req) == READ) |
| 3273 | cmd = DASD_ECKD_CCW_READ_TRACK; |
| 3274 | else if (rq_data_dir(req) == WRITE) |
| 3275 | cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK; |
| 3276 | else { |
| 3277 | cqr = ERR_PTR(-EINVAL); |
| 3278 | goto out; |
| 3279 | } |
| 3280 | |
| 3281 | /* |
| 3282 | * Raw track based I/O needs IDAWs for each page, |
| 3283 | * and not just for 64 bit addresses. |
| 3284 | */ |
| 3285 | cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK; |
| 3286 | |
| 3287 | /* 1x prefix + one read/write ccw per track */ |
| 3288 | cplength = 1 + trkcount; |
| 3289 | |
| 3290 | /* |
| 3291 | * struct PFX_eckd_data has up to 2 byte as extended parameter |
| 3292 | * this is needed for write full track and has to be mentioned |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3293 | * separately |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3294 | * add 8 instead of 2 to keep 8 byte boundary |
| 3295 | */ |
| 3296 | pfx_datasize = sizeof(struct PFX_eckd_data) + 8; |
| 3297 | |
| 3298 | datasize = pfx_datasize + cidaw * sizeof(unsigned long long); |
| 3299 | |
| 3300 | /* Allocate the ccw request. */ |
| 3301 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, |
| 3302 | datasize, startdev); |
| 3303 | if (IS_ERR(cqr)) |
| 3304 | goto out; |
| 3305 | ccw = cqr->cpaddr; |
| 3306 | |
| 3307 | if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd, |
| 3308 | basedev, startdev, 1 /* format */, first_offs + 1, |
| 3309 | trkcount, 0, 0) == -EAGAIN) { |
| 3310 | /* Clock not in sync and XRC is enabled. |
| 3311 | * Try again later. |
| 3312 | */ |
| 3313 | dasd_sfree_request(cqr, startdev); |
| 3314 | cqr = ERR_PTR(-EAGAIN); |
| 3315 | goto out; |
| 3316 | } |
| 3317 | |
| 3318 | idaws = (unsigned long *)(cqr->data + pfx_datasize); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3319 | len_to_track_end = 0; |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3320 | if (start_padding_sectors) { |
| 3321 | ccw[-1].flags |= CCW_FLAG_CC; |
| 3322 | ccw->cmd_code = cmd; |
| 3323 | /* maximum 3390 track size */ |
| 3324 | ccw->count = 57326; |
| 3325 | /* 64k map to one track */ |
| 3326 | len_to_track_end = 65536 - start_padding_sectors * 512; |
| 3327 | ccw->cda = (__u32)(addr_t)idaws; |
| 3328 | ccw->flags |= CCW_FLAG_IDA; |
| 3329 | ccw->flags |= CCW_FLAG_SLI; |
| 3330 | ccw++; |
| 3331 | for (sectors = 0; sectors < start_padding_sectors; sectors += 8) |
| 3332 | idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); |
| 3333 | } |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3334 | rq_for_each_segment(bv, req, iter) { |
| 3335 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 3336 | seg_len = bv->bv_len; |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3337 | if (cmd == DASD_ECKD_CCW_READ_TRACK) |
| 3338 | memset(dst, 0, seg_len); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3339 | if (!len_to_track_end) { |
| 3340 | ccw[-1].flags |= CCW_FLAG_CC; |
| 3341 | ccw->cmd_code = cmd; |
| 3342 | /* maximum 3390 track size */ |
| 3343 | ccw->count = 57326; |
| 3344 | /* 64k map to one track */ |
| 3345 | len_to_track_end = 65536; |
| 3346 | ccw->cda = (__u32)(addr_t)idaws; |
| 3347 | ccw->flags |= CCW_FLAG_IDA; |
| 3348 | ccw->flags |= CCW_FLAG_SLI; |
| 3349 | ccw++; |
| 3350 | } |
| 3351 | len_to_track_end -= seg_len; |
| 3352 | idaws = idal_create_words(idaws, dst, seg_len); |
| 3353 | } |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 3354 | for (sectors = 0; sectors < end_padding_sectors; sectors += 8) |
| 3355 | idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3356 | if (blk_noretry_request(req) || |
| 3357 | block->base->features & DASD_FEATURE_FAILFAST) |
| 3358 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 3359 | cqr->startdev = startdev; |
| 3360 | cqr->memdev = startdev; |
| 3361 | cqr->block = block; |
| 3362 | cqr->expires = startdev->default_expires * HZ; |
| 3363 | cqr->lpm = startdev->path_data.ppm; |
Hannes Reinecke | 1f1ee9a | 2013-01-30 09:26:12 +0000 | [diff] [blame] | 3364 | cqr->retries = startdev->default_retries; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3365 | cqr->buildclk = get_tod_clock(); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3366 | cqr->status = DASD_CQR_FILLED; |
| 3367 | |
| 3368 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) |
| 3369 | cqr = NULL; |
| 3370 | out: |
| 3371 | return cqr; |
| 3372 | } |
| 3373 | |
| 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | static int |
| 3376 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 3377 | { |
| 3378 | struct dasd_eckd_private *private; |
| 3379 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 3380 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | struct bio_vec *bv; |
| 3382 | char *dst, *cda; |
| 3383 | unsigned int blksize, blk_per_trk, off; |
| 3384 | sector_t recid; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 3385 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | |
| 3387 | if (!dasd_page_cache) |
| 3388 | goto out; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3389 | private = (struct dasd_eckd_private *) cqr->block->base->private; |
| 3390 | blksize = cqr->block->bp_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 3392 | recid = blk_rq_pos(req) >> cqr->block->s2b_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | ccw = cqr->cpaddr; |
| 3394 | /* Skip over define extent & locate record. */ |
| 3395 | ccw++; |
| 3396 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) |
| 3397 | ccw++; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 3398 | rq_for_each_segment(bv, req, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 3400 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 3401 | /* Skip locate record. */ |
| 3402 | if (private->uses_cdl && recid <= 2*blk_per_trk) |
| 3403 | ccw++; |
| 3404 | if (dst) { |
| 3405 | if (ccw->flags & CCW_FLAG_IDA) |
| 3406 | cda = *((char **)((addr_t) ccw->cda)); |
| 3407 | else |
| 3408 | cda = (char *)((addr_t) ccw->cda); |
| 3409 | if (dst != cda) { |
| 3410 | if (rq_data_dir(req) == READ) |
| 3411 | memcpy(dst, cda, bv->bv_len); |
| 3412 | kmem_cache_free(dasd_page_cache, |
| 3413 | (void *)((addr_t)cda & PAGE_MASK)); |
| 3414 | } |
| 3415 | dst = NULL; |
| 3416 | } |
| 3417 | ccw++; |
| 3418 | recid++; |
| 3419 | } |
| 3420 | } |
| 3421 | out: |
| 3422 | status = cqr->status == DASD_CQR_DONE; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3423 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | return status; |
| 3425 | } |
| 3426 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3427 | /* |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3428 | * 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] | 3429 | * |
| 3430 | * Note that this is not enough to restart the cqr! |
| 3431 | * Either reset cqr->startdev as well (summary unit check handling) |
| 3432 | * or restart via separate cqr (as in ERP handling). |
| 3433 | */ |
| 3434 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) |
| 3435 | { |
| 3436 | struct ccw1 *ccw; |
| 3437 | struct PFX_eckd_data *pfxdata; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3438 | struct tcw *tcw; |
| 3439 | struct tccb *tccb; |
| 3440 | struct dcw *dcw; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3441 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3442 | if (cqr->cpmode == 1) { |
| 3443 | tcw = cqr->cpaddr; |
| 3444 | tccb = tcw_get_tccb(tcw); |
| 3445 | dcw = (struct dcw *)&tccb->tca[0]; |
| 3446 | pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3447 | pfxdata->validity.verify_base = 0; |
| 3448 | pfxdata->validity.hyper_pav = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3449 | } else { |
| 3450 | ccw = cqr->cpaddr; |
| 3451 | pfxdata = cqr->data; |
| 3452 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { |
| 3453 | pfxdata->validity.verify_base = 0; |
| 3454 | pfxdata->validity.hyper_pav = 0; |
| 3455 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 |
| 3460 | |
| 3461 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, |
| 3462 | struct dasd_block *block, |
| 3463 | struct request *req) |
| 3464 | { |
| 3465 | struct dasd_eckd_private *private; |
| 3466 | struct dasd_device *startdev; |
| 3467 | unsigned long flags; |
| 3468 | struct dasd_ccw_req *cqr; |
| 3469 | |
| 3470 | startdev = dasd_alias_get_start_dev(base); |
| 3471 | if (!startdev) |
| 3472 | startdev = base; |
| 3473 | private = (struct dasd_eckd_private *) startdev->private; |
| 3474 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) |
| 3475 | return ERR_PTR(-EBUSY); |
| 3476 | |
| 3477 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); |
| 3478 | private->count++; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 3479 | if ((base->features & DASD_FEATURE_USERAW)) |
| 3480 | cqr = dasd_raw_build_cp(startdev, block, req); |
| 3481 | else |
| 3482 | cqr = dasd_eckd_build_cp(startdev, block, req); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3483 | if (IS_ERR(cqr)) |
| 3484 | private->count--; |
| 3485 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); |
| 3486 | return cqr; |
| 3487 | } |
| 3488 | |
| 3489 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, |
| 3490 | struct request *req) |
| 3491 | { |
| 3492 | struct dasd_eckd_private *private; |
| 3493 | unsigned long flags; |
| 3494 | |
| 3495 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 3496 | private = (struct dasd_eckd_private *) cqr->memdev->private; |
| 3497 | private->count--; |
| 3498 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); |
| 3499 | return dasd_eckd_free_cp(cqr, req); |
| 3500 | } |
| 3501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | static int |
| 3503 | dasd_eckd_fill_info(struct dasd_device * device, |
| 3504 | struct dasd_information2_t * info) |
| 3505 | { |
| 3506 | struct dasd_eckd_private *private; |
| 3507 | |
| 3508 | private = (struct dasd_eckd_private *) device->private; |
| 3509 | info->label_block = 2; |
| 3510 | info->FBA_layout = private->uses_cdl ? 0 : 1; |
| 3511 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; |
| 3512 | info->characteristics_size = sizeof(struct dasd_eckd_characteristics); |
| 3513 | memcpy(info->characteristics, &private->rdc_data, |
| 3514 | sizeof(struct dasd_eckd_characteristics)); |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 3515 | info->confdata_size = min((unsigned long)private->conf_len, |
| 3516 | sizeof(info->configuration_data)); |
| 3517 | memcpy(info->configuration_data, private->conf_data, |
| 3518 | info->confdata_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | return 0; |
| 3520 | } |
| 3521 | |
| 3522 | /* |
| 3523 | * SECTION: ioctl functions for eckd devices. |
| 3524 | */ |
| 3525 | |
| 3526 | /* |
| 3527 | * Release device ioctl. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 3528 | * Buils a channel programm to releases a prior reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | * (see dasd_eckd_reserve) device. |
| 3530 | */ |
| 3531 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3532 | dasd_eckd_release(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | struct dasd_ccw_req *cqr; |
| 3535 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3536 | struct ccw1 *ccw; |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3537 | int useglobal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | |
| 3539 | if (!capable(CAP_SYS_ADMIN)) |
| 3540 | return -EACCES; |
| 3541 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3542 | useglobal = 0; |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3543 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | if (IS_ERR(cqr)) { |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3545 | mutex_lock(&dasd_reserve_mutex); |
| 3546 | useglobal = 1; |
| 3547 | cqr = &dasd_reserve_req->cqr; |
| 3548 | memset(cqr, 0, sizeof(*cqr)); |
| 3549 | memset(&dasd_reserve_req->ccw, 0, |
| 3550 | sizeof(dasd_reserve_req->ccw)); |
| 3551 | cqr->cpaddr = &dasd_reserve_req->ccw; |
| 3552 | cqr->data = &dasd_reserve_req->data; |
| 3553 | cqr->magic = DASD_ECKD_MAGIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3555 | ccw = cqr->cpaddr; |
| 3556 | ccw->cmd_code = DASD_ECKD_CCW_RELEASE; |
| 3557 | ccw->flags |= CCW_FLAG_SLI; |
| 3558 | ccw->count = 32; |
| 3559 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3560 | cqr->startdev = device; |
| 3561 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3563 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 3564 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | cqr->expires = 2 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3566 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | cqr->status = DASD_CQR_FILLED; |
| 3568 | |
| 3569 | rc = dasd_sleep_on_immediatly(cqr); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 3570 | if (!rc) |
| 3571 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3573 | if (useglobal) |
| 3574 | mutex_unlock(&dasd_reserve_mutex); |
| 3575 | else |
| 3576 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | return rc; |
| 3578 | } |
| 3579 | |
| 3580 | /* |
| 3581 | * Reserve device ioctl. |
| 3582 | * Options are set to 'synchronous wait for interrupt' and |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 3583 | * 'timeout the request'. This leads to a terminate IO if |
| 3584 | * the interrupt is outstanding for a certain time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | */ |
| 3586 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3587 | dasd_eckd_reserve(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | struct dasd_ccw_req *cqr; |
| 3590 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3591 | struct ccw1 *ccw; |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3592 | int useglobal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | |
| 3594 | if (!capable(CAP_SYS_ADMIN)) |
| 3595 | return -EACCES; |
| 3596 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3597 | useglobal = 0; |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3598 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | if (IS_ERR(cqr)) { |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3600 | mutex_lock(&dasd_reserve_mutex); |
| 3601 | useglobal = 1; |
| 3602 | cqr = &dasd_reserve_req->cqr; |
| 3603 | memset(cqr, 0, sizeof(*cqr)); |
| 3604 | memset(&dasd_reserve_req->ccw, 0, |
| 3605 | sizeof(dasd_reserve_req->ccw)); |
| 3606 | cqr->cpaddr = &dasd_reserve_req->ccw; |
| 3607 | cqr->data = &dasd_reserve_req->data; |
| 3608 | cqr->magic = DASD_ECKD_MAGIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3610 | ccw = cqr->cpaddr; |
| 3611 | ccw->cmd_code = DASD_ECKD_CCW_RESERVE; |
| 3612 | ccw->flags |= CCW_FLAG_SLI; |
| 3613 | ccw->count = 32; |
| 3614 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3615 | cqr->startdev = device; |
| 3616 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3618 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 3619 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | cqr->expires = 2 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3621 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | cqr->status = DASD_CQR_FILLED; |
| 3623 | |
| 3624 | rc = dasd_sleep_on_immediatly(cqr); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 3625 | if (!rc) |
| 3626 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3628 | if (useglobal) |
| 3629 | mutex_unlock(&dasd_reserve_mutex); |
| 3630 | else |
| 3631 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | return rc; |
| 3633 | } |
| 3634 | |
| 3635 | /* |
| 3636 | * Steal lock ioctl - unconditional reserve device. |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 3637 | * Buils a channel programm to break a device's reservation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | * (unconditional reserve) |
| 3639 | */ |
| 3640 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3641 | dasd_eckd_steal_lock(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | struct dasd_ccw_req *cqr; |
| 3644 | int rc; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3645 | struct ccw1 *ccw; |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3646 | int useglobal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | |
| 3648 | if (!capable(CAP_SYS_ADMIN)) |
| 3649 | return -EACCES; |
| 3650 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3651 | useglobal = 0; |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3652 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | if (IS_ERR(cqr)) { |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3654 | mutex_lock(&dasd_reserve_mutex); |
| 3655 | useglobal = 1; |
| 3656 | cqr = &dasd_reserve_req->cqr; |
| 3657 | memset(cqr, 0, sizeof(*cqr)); |
| 3658 | memset(&dasd_reserve_req->ccw, 0, |
| 3659 | sizeof(dasd_reserve_req->ccw)); |
| 3660 | cqr->cpaddr = &dasd_reserve_req->ccw; |
| 3661 | cqr->data = &dasd_reserve_req->data; |
| 3662 | cqr->magic = DASD_ECKD_MAGIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 3664 | ccw = cqr->cpaddr; |
| 3665 | ccw->cmd_code = DASD_ECKD_CCW_SLCK; |
| 3666 | ccw->flags |= CCW_FLAG_SLI; |
| 3667 | ccw->count = 32; |
| 3668 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3669 | cqr->startdev = device; |
| 3670 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3672 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Horst Hummel | 336c340 | 2007-02-05 21:17:24 +0100 | [diff] [blame] | 3673 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | cqr->expires = 2 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3675 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | cqr->status = DASD_CQR_FILLED; |
| 3677 | |
| 3678 | rc = dasd_sleep_on_immediatly(cqr); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 3679 | if (!rc) |
| 3680 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 3682 | if (useglobal) |
| 3683 | mutex_unlock(&dasd_reserve_mutex); |
| 3684 | else |
| 3685 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | return rc; |
| 3687 | } |
| 3688 | |
| 3689 | /* |
Stefan Weinhuber | 196339f | 2010-10-29 16:50:43 +0200 | [diff] [blame] | 3690 | * SNID - Sense Path Group ID |
| 3691 | * This ioctl may be used in situations where I/O is stalled due to |
| 3692 | * a reserve, so if the normal dasd_smalloc_request fails, we use the |
| 3693 | * preallocated dasd_reserve_req. |
| 3694 | */ |
| 3695 | static int dasd_eckd_snid(struct dasd_device *device, |
| 3696 | void __user *argp) |
| 3697 | { |
| 3698 | struct dasd_ccw_req *cqr; |
| 3699 | int rc; |
| 3700 | struct ccw1 *ccw; |
| 3701 | int useglobal; |
| 3702 | struct dasd_snid_ioctl_data usrparm; |
| 3703 | |
| 3704 | if (!capable(CAP_SYS_ADMIN)) |
| 3705 | return -EACCES; |
| 3706 | |
| 3707 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) |
| 3708 | return -EFAULT; |
| 3709 | |
| 3710 | useglobal = 0; |
| 3711 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, |
| 3712 | sizeof(struct dasd_snid_data), device); |
| 3713 | if (IS_ERR(cqr)) { |
| 3714 | mutex_lock(&dasd_reserve_mutex); |
| 3715 | useglobal = 1; |
| 3716 | cqr = &dasd_reserve_req->cqr; |
| 3717 | memset(cqr, 0, sizeof(*cqr)); |
| 3718 | memset(&dasd_reserve_req->ccw, 0, |
| 3719 | sizeof(dasd_reserve_req->ccw)); |
| 3720 | cqr->cpaddr = &dasd_reserve_req->ccw; |
| 3721 | cqr->data = &dasd_reserve_req->data; |
| 3722 | cqr->magic = DASD_ECKD_MAGIC; |
| 3723 | } |
| 3724 | ccw = cqr->cpaddr; |
| 3725 | ccw->cmd_code = DASD_ECKD_CCW_SNID; |
| 3726 | ccw->flags |= CCW_FLAG_SLI; |
| 3727 | ccw->count = 12; |
| 3728 | ccw->cda = (__u32)(addr_t) cqr->data; |
| 3729 | cqr->startdev = device; |
| 3730 | cqr->memdev = device; |
| 3731 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 3732 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 3733 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
Stefan Weinhuber | 196339f | 2010-10-29 16:50:43 +0200 | [diff] [blame] | 3734 | cqr->retries = 5; |
| 3735 | cqr->expires = 10 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3736 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 196339f | 2010-10-29 16:50:43 +0200 | [diff] [blame] | 3737 | cqr->status = DASD_CQR_FILLED; |
| 3738 | cqr->lpm = usrparm.path_mask; |
| 3739 | |
| 3740 | rc = dasd_sleep_on_immediatly(cqr); |
| 3741 | /* verify that I/O processing didn't modify the path mask */ |
| 3742 | if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask)) |
| 3743 | rc = -EIO; |
| 3744 | if (!rc) { |
| 3745 | usrparm.data = *((struct dasd_snid_data *)cqr->data); |
| 3746 | if (copy_to_user(argp, &usrparm, sizeof(usrparm))) |
| 3747 | rc = -EFAULT; |
| 3748 | } |
| 3749 | |
| 3750 | if (useglobal) |
| 3751 | mutex_unlock(&dasd_reserve_mutex); |
| 3752 | else |
| 3753 | dasd_sfree_request(cqr, cqr->memdev); |
| 3754 | return rc; |
| 3755 | } |
| 3756 | |
| 3757 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | * Read performance statistics |
| 3759 | */ |
| 3760 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3761 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | struct dasd_psf_prssd_data *prssdp; |
| 3764 | struct dasd_rssd_perf_stats_t *stats; |
| 3765 | struct dasd_ccw_req *cqr; |
| 3766 | struct ccw1 *ccw; |
| 3767 | int rc; |
| 3768 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3769 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3770 | (sizeof(struct dasd_psf_prssd_data) + |
| 3771 | sizeof(struct dasd_rssd_perf_stats_t)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | device); |
| 3773 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3774 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | "Could not allocate initialization request"); |
| 3776 | return PTR_ERR(cqr); |
| 3777 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3778 | cqr->startdev = device; |
| 3779 | cqr->memdev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | cqr->retries = 0; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 3781 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | cqr->expires = 10 * HZ; |
| 3783 | |
| 3784 | /* Prepare for Read Subsystem Data */ |
| 3785 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3786 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | prssdp->order = PSF_ORDER_PRSSD; |
Joe Perches | 5d67d16 | 2008-01-26 14:11:20 +0100 | [diff] [blame] | 3788 | prssdp->suborder = 0x01; /* Performance Statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
| 3790 | |
| 3791 | ccw = cqr->cpaddr; |
| 3792 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3793 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | ccw->flags |= CCW_FLAG_CC; |
| 3795 | ccw->cda = (__u32)(addr_t) prssdp; |
| 3796 | |
| 3797 | /* Read Subsystem Data - Performance Statistics */ |
| 3798 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3799 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | |
| 3801 | ccw++; |
| 3802 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3803 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | ccw->cda = (__u32)(addr_t) stats; |
| 3805 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3806 | cqr->buildclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | cqr->status = DASD_CQR_FILLED; |
| 3808 | rc = dasd_sleep_on(cqr); |
| 3809 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 3811 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3812 | if (copy_to_user(argp, stats, |
| 3813 | sizeof(struct dasd_rssd_perf_stats_t))) |
| 3814 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3816 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | return rc; |
| 3818 | } |
| 3819 | |
| 3820 | /* |
| 3821 | * Get attributes (cache operations) |
| 3822 | * Returnes the cache attributes used in Define Extend (DE). |
| 3823 | */ |
| 3824 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3825 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3827 | struct dasd_eckd_private *private = |
| 3828 | (struct dasd_eckd_private *)device->private; |
| 3829 | struct attrib_data_t attrib = private->attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | int rc; |
| 3831 | |
| 3832 | if (!capable(CAP_SYS_ADMIN)) |
| 3833 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3834 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | return -EINVAL; |
| 3836 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3837 | rc = 0; |
| 3838 | if (copy_to_user(argp, (long *) &attrib, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3839 | sizeof(struct attrib_data_t))) |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3840 | rc = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | |
| 3842 | return rc; |
| 3843 | } |
| 3844 | |
| 3845 | /* |
| 3846 | * Set attributes (cache operations) |
| 3847 | * Stores the attributes for cache operation to be used in Define Extend (DE). |
| 3848 | */ |
| 3849 | static int |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3850 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | { |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3852 | struct dasd_eckd_private *private = |
| 3853 | (struct dasd_eckd_private *)device->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 | struct attrib_data_t attrib; |
| 3855 | |
| 3856 | if (!capable(CAP_SYS_ADMIN)) |
| 3857 | return -EACCES; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3858 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | return -EINVAL; |
| 3860 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3861 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | private->attrib = attrib; |
| 3864 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3865 | dev_info(&device->cdev->dev, |
| 3866 | "The DASD cache mode was set to %x (%i cylinder prestage)\n", |
| 3867 | private->attrib.operation, private->attrib.nr_cyl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | return 0; |
| 3869 | } |
| 3870 | |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3871 | /* |
| 3872 | * Issue syscall I/O to EMC Symmetrix array. |
| 3873 | * CCWs are PSF and RSSD |
| 3874 | */ |
| 3875 | static int dasd_symm_io(struct dasd_device *device, void __user *argp) |
| 3876 | { |
| 3877 | struct dasd_symmio_parms usrparm; |
| 3878 | char *psf_data, *rssd_result; |
| 3879 | struct dasd_ccw_req *cqr; |
| 3880 | struct ccw1 *ccw; |
Nigel Hislop | 5289802 | 2010-03-08 12:25:16 +0100 | [diff] [blame] | 3881 | char psf0, psf1; |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3882 | int rc; |
| 3883 | |
Nigel Hislop | 5289802 | 2010-03-08 12:25:16 +0100 | [diff] [blame] | 3884 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) |
| 3885 | return -EACCES; |
| 3886 | psf0 = psf1 = 0; |
| 3887 | |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3888 | /* Copy parms from caller */ |
| 3889 | rc = -EFAULT; |
| 3890 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) |
| 3891 | goto out; |
Heiko Carstens | f8b06859 | 2010-01-13 20:44:40 +0100 | [diff] [blame] | 3892 | if (is_compat_task() || sizeof(long) == 4) { |
| 3893 | /* Make sure pointers are sane even on 31 bit. */ |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3894 | rc = -EINVAL; |
Heiko Carstens | f8b06859 | 2010-01-13 20:44:40 +0100 | [diff] [blame] | 3895 | if ((usrparm.psf_data >> 32) != 0) |
| 3896 | goto out; |
| 3897 | if ((usrparm.rssd_result >> 32) != 0) |
| 3898 | goto out; |
| 3899 | usrparm.psf_data &= 0x7fffffffULL; |
| 3900 | usrparm.rssd_result &= 0x7fffffffULL; |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3901 | } |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3902 | /* alloc I/O data area */ |
| 3903 | psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); |
| 3904 | rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); |
| 3905 | if (!psf_data || !rssd_result) { |
| 3906 | rc = -ENOMEM; |
| 3907 | goto out_free; |
| 3908 | } |
| 3909 | |
| 3910 | /* get syscall header from user space */ |
| 3911 | rc = -EFAULT; |
| 3912 | if (copy_from_user(psf_data, |
| 3913 | (void __user *)(unsigned long) usrparm.psf_data, |
| 3914 | usrparm.psf_data_len)) |
| 3915 | goto out_free; |
Nigel Hislop | 5289802 | 2010-03-08 12:25:16 +0100 | [diff] [blame] | 3916 | psf0 = psf_data[0]; |
| 3917 | psf1 = psf_data[1]; |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3918 | |
| 3919 | /* setup CCWs for PSF + RSSD */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 3920 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3921 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3922 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3923 | "Could not allocate initialization request"); |
| 3924 | rc = PTR_ERR(cqr); |
| 3925 | goto out_free; |
| 3926 | } |
| 3927 | |
| 3928 | cqr->startdev = device; |
| 3929 | cqr->memdev = device; |
| 3930 | cqr->retries = 3; |
| 3931 | cqr->expires = 10 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3932 | cqr->buildclk = get_tod_clock(); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3933 | cqr->status = DASD_CQR_FILLED; |
| 3934 | |
| 3935 | /* Build the ccws */ |
| 3936 | ccw = cqr->cpaddr; |
| 3937 | |
| 3938 | /* PSF ccw */ |
| 3939 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 3940 | ccw->count = usrparm.psf_data_len; |
| 3941 | ccw->flags |= CCW_FLAG_CC; |
| 3942 | ccw->cda = (__u32)(addr_t) psf_data; |
| 3943 | |
| 3944 | ccw++; |
| 3945 | |
| 3946 | /* RSSD ccw */ |
| 3947 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 3948 | ccw->count = usrparm.rssd_result_len; |
| 3949 | ccw->flags = CCW_FLAG_SLI ; |
| 3950 | ccw->cda = (__u32)(addr_t) rssd_result; |
| 3951 | |
| 3952 | rc = dasd_sleep_on(cqr); |
| 3953 | if (rc) |
| 3954 | goto out_sfree; |
| 3955 | |
| 3956 | rc = -EFAULT; |
| 3957 | if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, |
| 3958 | rssd_result, usrparm.rssd_result_len)) |
| 3959 | goto out_sfree; |
| 3960 | rc = 0; |
| 3961 | |
| 3962 | out_sfree: |
| 3963 | dasd_sfree_request(cqr, cqr->memdev); |
| 3964 | out_free: |
| 3965 | kfree(rssd_result); |
| 3966 | kfree(psf_data); |
| 3967 | out: |
Nigel Hislop | 5289802 | 2010-03-08 12:25:16 +0100 | [diff] [blame] | 3968 | DBF_DEV_EVENT(DBF_WARNING, device, |
| 3969 | "Symmetrix ioctl (0x%02x 0x%02x): rc=%d", |
| 3970 | (int) psf0, (int) psf1, rc); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3971 | return rc; |
| 3972 | } |
| 3973 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3974 | static int |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3975 | 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] | 3976 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3977 | struct dasd_device *device = block->base; |
| 3978 | |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3979 | switch (cmd) { |
| 3980 | case BIODASDGATTR: |
| 3981 | return dasd_eckd_get_attrib(device, argp); |
| 3982 | case BIODASDSATTR: |
| 3983 | return dasd_eckd_set_attrib(device, argp); |
| 3984 | case BIODASDPSRD: |
| 3985 | return dasd_eckd_performance(device, argp); |
| 3986 | case BIODASDRLSE: |
| 3987 | return dasd_eckd_release(device); |
| 3988 | case BIODASDRSRV: |
| 3989 | return dasd_eckd_reserve(device); |
| 3990 | case BIODASDSLCK: |
| 3991 | return dasd_eckd_steal_lock(device); |
Stefan Weinhuber | 196339f | 2010-10-29 16:50:43 +0200 | [diff] [blame] | 3992 | case BIODASDSNID: |
| 3993 | return dasd_eckd_snid(device, argp); |
Nigel Hislop | ab1d848 | 2008-10-10 21:33:25 +0200 | [diff] [blame] | 3994 | case BIODASDSYMMIO: |
| 3995 | return dasd_symm_io(device, argp); |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3996 | default: |
Heiko Carstens | 6b79d14 | 2012-08-27 10:59:42 +0200 | [diff] [blame] | 3997 | return -ENOTTY; |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 3998 | } |
| 3999 | } |
| 4000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | /* |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4002 | * Dump the range of CCWs into 'page' buffer |
| 4003 | * and return number of printed chars. |
| 4004 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 4005 | static int |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4006 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
| 4007 | { |
| 4008 | int len, count; |
| 4009 | char *datap; |
| 4010 | |
| 4011 | len = 0; |
| 4012 | while (from <= to) { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4013 | len += sprintf(page + len, PRINTK_HEADER |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4014 | " CCW %p: %08X %08X DAT:", |
| 4015 | from, ((int *) from)[0], ((int *) from)[1]); |
| 4016 | |
| 4017 | /* get pointer to data (consider IDALs) */ |
| 4018 | if (from->flags & CCW_FLAG_IDA) |
| 4019 | datap = (char *) *((addr_t *) (addr_t) from->cda); |
| 4020 | else |
| 4021 | datap = (char *) ((addr_t) from->cda); |
| 4022 | |
| 4023 | /* dump data (max 32 bytes) */ |
| 4024 | for (count = 0; count < from->count && count < 32; count++) { |
| 4025 | if (count % 8 == 0) len += sprintf(page + len, " "); |
| 4026 | if (count % 4 == 0) len += sprintf(page + len, " "); |
| 4027 | len += sprintf(page + len, "%02x", datap[count]); |
| 4028 | } |
| 4029 | len += sprintf(page + len, "\n"); |
| 4030 | from++; |
| 4031 | } |
| 4032 | return len; |
| 4033 | } |
| 4034 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4035 | static void |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 4036 | dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
| 4037 | char *reason) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4038 | { |
| 4039 | u64 *sense; |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4040 | u64 *stat; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4041 | |
Stefan Haberland | aeec92c | 2009-07-07 16:37:06 +0200 | [diff] [blame] | 4042 | sense = (u64 *) dasd_get_sense(irb); |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4043 | stat = (u64 *) &irb->scsw; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4044 | if (sense) { |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4045 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : " |
| 4046 | "%016llx %016llx %016llx %016llx", |
| 4047 | reason, *stat, *((u32 *) (stat + 1)), |
Stefan Haberland | ed3640b | 2010-10-25 16:10:24 +0200 | [diff] [blame] | 4048 | sense[0], sense[1], sense[2], sense[3]); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4049 | } else { |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4050 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s", |
| 4051 | reason, *stat, *((u32 *) (stat + 1)), |
| 4052 | "NO VALID SENSE"); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4053 | } |
| 4054 | } |
| 4055 | |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4056 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | * Print sense data and related channel program. |
| 4058 | * Parts are printed because printk buffer is only 1024 bytes. |
| 4059 | */ |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4060 | static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4061 | struct dasd_ccw_req *req, struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | { |
| 4063 | char *page; |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4064 | struct ccw1 *first, *last, *fail, *from, *to; |
| 4065 | int len, sl, sct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
| 4067 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 4068 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4069 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 4070 | "No memory to dump sense data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | return; |
| 4072 | } |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4073 | /* dump the sense data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4074 | len = sprintf(page, PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | " I/O status report for device %s:\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 4076 | dev_name(&device->cdev->dev)); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4077 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4078 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
| 4079 | "CS:%02X RC:%d\n", |
| 4080 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), |
| 4081 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), |
| 4082 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), |
| 4083 | req ? req->intrc : 0); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4084 | len += sprintf(page + len, PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | " device %s: Failing CCW: %p\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 4086 | dev_name(&device->cdev->dev), |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 4087 | (void *) (addr_t) irb->scsw.cmd.cpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | if (irb->esw.esw0.erw.cons) { |
| 4089 | for (sl = 0; sl < 4; sl++) { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4090 | len += sprintf(page + len, PRINTK_HEADER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | " Sense(hex) %2d-%2d:", |
| 4092 | (8 * sl), ((8 * sl) + 7)); |
| 4093 | |
| 4094 | for (sct = 0; sct < 8; sct++) { |
| 4095 | len += sprintf(page + len, " %02x", |
| 4096 | irb->ecw[8 * sl + sct]); |
| 4097 | } |
| 4098 | len += sprintf(page + len, "\n"); |
| 4099 | } |
| 4100 | |
| 4101 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { |
| 4102 | /* 24 Byte Sense Data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4103 | sprintf(page + len, PRINTK_HEADER |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4104 | " 24 Byte: %x MSG %x, " |
| 4105 | "%s MSGb to SYSOP\n", |
| 4106 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, |
| 4107 | irb->ecw[1] & 0x10 ? "" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } else { |
| 4109 | /* 32 Byte Sense Data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4110 | sprintf(page + len, PRINTK_HEADER |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4111 | " 32 Byte: Format: %x " |
| 4112 | "Exception class %x\n", |
| 4113 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | } |
| 4115 | } else { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4116 | sprintf(page + len, PRINTK_HEADER |
Horst Hummel | 445b5b4 | 2006-06-29 14:57:52 +0200 | [diff] [blame] | 4117 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | } |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4119 | printk(KERN_ERR "%s", page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4121 | if (req) { |
| 4122 | /* req == NULL for unsolicited interrupts */ |
| 4123 | /* dump the Channel Program (max 140 Bytes per line) */ |
| 4124 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ |
| 4125 | first = req->cpaddr; |
| 4126 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); |
| 4127 | to = min(first + 6, last); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4128 | len = sprintf(page, PRINTK_HEADER |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4129 | " Related CP in req: %p\n", req); |
| 4130 | dasd_eckd_dump_ccw_range(first, to, page + len); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4131 | printk(KERN_ERR "%s", page); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4132 | |
| 4133 | /* print failing CCW area (maximum 4) */ |
| 4134 | /* scsw->cda is either valid or zero */ |
| 4135 | len = 0; |
| 4136 | from = ++to; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 4137 | fail = (struct ccw1 *)(addr_t) |
| 4138 | irb->scsw.cmd.cpa; /* failing CCW */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4139 | if (from < fail - 2) { |
| 4140 | from = fail - 2; /* there is a gap - print header */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4141 | len += sprintf(page, PRINTK_HEADER "......\n"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4142 | } |
| 4143 | to = min(fail + 1, last); |
| 4144 | len += dasd_eckd_dump_ccw_range(from, to, page + len); |
| 4145 | |
| 4146 | /* print last CCWs (maximum 2) */ |
| 4147 | from = max(from, ++to); |
| 4148 | if (from < last - 1) { |
| 4149 | from = last - 1; /* there is a gap - print header */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4150 | len += sprintf(page + len, PRINTK_HEADER "......\n"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4151 | } |
| 4152 | len += dasd_eckd_dump_ccw_range(from, last, page + len); |
| 4153 | if (len > 0) |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4154 | printk(KERN_ERR "%s", page); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | free_page((unsigned long) page); |
| 4157 | } |
| 4158 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4159 | |
| 4160 | /* |
| 4161 | * Print sense data from a tcw. |
| 4162 | */ |
| 4163 | static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, |
| 4164 | struct dasd_ccw_req *req, struct irb *irb) |
| 4165 | { |
| 4166 | char *page; |
| 4167 | int len, sl, sct, residual; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4168 | struct tsb *tsb; |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 4169 | u8 *sense, *rcq; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4170 | |
| 4171 | page = (char *) get_zeroed_page(GFP_ATOMIC); |
| 4172 | if (page == NULL) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4173 | DBF_DEV_EVENT(DBF_WARNING, device, " %s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4174 | "No memory to dump sense data"); |
| 4175 | return; |
| 4176 | } |
| 4177 | /* dump the sense data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4178 | len = sprintf(page, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4179 | " I/O status report for device %s:\n", |
| 4180 | dev_name(&device->cdev->dev)); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4181 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4182 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
| 4183 | "CS:%02X fcxs:%02X schxs:%02X RC:%d\n", |
| 4184 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), |
| 4185 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), |
| 4186 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), |
| 4187 | irb->scsw.tm.fcxs, irb->scsw.tm.schxs, |
| 4188 | req ? req->intrc : 0); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4189 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4190 | " device %s: Failing TCW: %p\n", |
| 4191 | dev_name(&device->cdev->dev), |
| 4192 | (void *) (addr_t) irb->scsw.tm.tcw); |
| 4193 | |
| 4194 | tsb = NULL; |
| 4195 | sense = NULL; |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4196 | if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4197 | tsb = tcw_get_tsb( |
| 4198 | (struct tcw *)(unsigned long)irb->scsw.tm.tcw); |
| 4199 | |
Stefan Haberland | b8fde72 | 2010-03-24 11:49:54 +0100 | [diff] [blame] | 4200 | if (tsb) { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4201 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4202 | " tsb->length %d\n", tsb->length); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4203 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4204 | " tsb->flags %x\n", tsb->flags); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4205 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4206 | " tsb->dcw_offset %d\n", tsb->dcw_offset); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4207 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4208 | " tsb->count %d\n", tsb->count); |
| 4209 | residual = tsb->count - 28; |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4210 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4211 | " residual %d\n", residual); |
| 4212 | |
| 4213 | switch (tsb->flags & 0x07) { |
| 4214 | case 1: /* tsa_iostat */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4215 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4216 | " tsb->tsa.iostat.dev_time %d\n", |
| 4217 | tsb->tsa.iostat.dev_time); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4218 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4219 | " tsb->tsa.iostat.def_time %d\n", |
| 4220 | tsb->tsa.iostat.def_time); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4221 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4222 | " tsb->tsa.iostat.queue_time %d\n", |
| 4223 | tsb->tsa.iostat.queue_time); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4224 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4225 | " tsb->tsa.iostat.dev_busy_time %d\n", |
| 4226 | tsb->tsa.iostat.dev_busy_time); |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4227 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4228 | " tsb->tsa.iostat.dev_act_time %d\n", |
| 4229 | tsb->tsa.iostat.dev_act_time); |
| 4230 | sense = tsb->tsa.iostat.sense; |
| 4231 | break; |
| 4232 | case 2: /* ts_ddpc */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4233 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4234 | " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 4235 | for (sl = 0; sl < 2; sl++) { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4236 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 4237 | " tsb->tsa.ddpc.rcq %2d-%2d: ", |
| 4238 | (8 * sl), ((8 * sl) + 7)); |
| 4239 | rcq = tsb->tsa.ddpc.rcq; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4240 | for (sct = 0; sct < 8; sct++) { |
| 4241 | len += sprintf(page + len, " %02x", |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 4242 | rcq[8 * sl + sct]); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4243 | } |
| 4244 | len += sprintf(page + len, "\n"); |
| 4245 | } |
| 4246 | sense = tsb->tsa.ddpc.sense; |
| 4247 | break; |
| 4248 | case 3: /* tsa_intrg */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4249 | len += sprintf(page + len, PRINTK_HEADER |
| 4250 | " tsb->tsa.intrg.: not supportet yet\n"); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | if (sense) { |
| 4255 | for (sl = 0; sl < 4; sl++) { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4256 | len += sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4257 | " Sense(hex) %2d-%2d:", |
| 4258 | (8 * sl), ((8 * sl) + 7)); |
| 4259 | for (sct = 0; sct < 8; sct++) { |
| 4260 | len += sprintf(page + len, " %02x", |
| 4261 | sense[8 * sl + sct]); |
| 4262 | } |
| 4263 | len += sprintf(page + len, "\n"); |
| 4264 | } |
| 4265 | |
| 4266 | if (sense[27] & DASD_SENSE_BIT_0) { |
| 4267 | /* 24 Byte Sense Data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4268 | sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4269 | " 24 Byte: %x MSG %x, " |
| 4270 | "%s MSGb to SYSOP\n", |
| 4271 | sense[7] >> 4, sense[7] & 0x0f, |
| 4272 | sense[1] & 0x10 ? "" : "no"); |
| 4273 | } else { |
| 4274 | /* 32 Byte Sense Data */ |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4275 | sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4276 | " 32 Byte: Format: %x " |
| 4277 | "Exception class %x\n", |
| 4278 | sense[6] & 0x0f, sense[22] >> 4); |
| 4279 | } |
| 4280 | } else { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4281 | sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4282 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
| 4283 | } |
| 4284 | } else { |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4285 | sprintf(page + len, PRINTK_HEADER |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4286 | " SORRY - NO TSB DATA AVAILABLE\n"); |
| 4287 | } |
Sebastian Ott | 773bab4 | 2012-10-23 20:28:37 +0200 | [diff] [blame] | 4288 | printk(KERN_ERR "%s", page); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4289 | free_page((unsigned long) page); |
| 4290 | } |
| 4291 | |
| 4292 | static void dasd_eckd_dump_sense(struct dasd_device *device, |
| 4293 | struct dasd_ccw_req *req, struct irb *irb) |
| 4294 | { |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 4295 | if (scsw_is_tm(&irb->scsw)) |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4296 | dasd_eckd_dump_sense_tcw(device, req, irb); |
| 4297 | else |
| 4298 | dasd_eckd_dump_sense_ccw(device, req, irb); |
| 4299 | } |
| 4300 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4301 | static int dasd_eckd_pm_freeze(struct dasd_device *device) |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4302 | { |
| 4303 | /* |
| 4304 | * the device should be disconnected from our LCU structure |
| 4305 | * on restore we will reconnect it and reread LCU specific |
| 4306 | * information like PAV support that might have changed |
| 4307 | */ |
| 4308 | dasd_alias_remove_device(device); |
| 4309 | dasd_alias_disconnect_device_from_lcu(device); |
| 4310 | |
| 4311 | return 0; |
| 4312 | } |
| 4313 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4314 | static int dasd_eckd_restore_device(struct dasd_device *device) |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4315 | { |
| 4316 | struct dasd_eckd_private *private; |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 4317 | struct dasd_eckd_characteristics temp_rdc_data; |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 4318 | int rc; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4319 | struct dasd_uid temp_uid; |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 4320 | unsigned long flags; |
Stefan Haberland | ea4da6e | 2013-02-19 09:30:05 +0100 | [diff] [blame] | 4321 | unsigned long cqr_flags = 0; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4322 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4323 | private = (struct dasd_eckd_private *) device->private; |
| 4324 | |
| 4325 | /* Read Configuration Data */ |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 4326 | dasd_eckd_read_conf(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4327 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4328 | dasd_eckd_get_uid(device, &temp_uid); |
| 4329 | /* Generate device unique id */ |
| 4330 | rc = dasd_eckd_generate_uid(device); |
| 4331 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4332 | if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 4333 | dev_err(&device->cdev->dev, "The UID of the DASD has " |
| 4334 | "changed\n"); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4335 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4336 | if (rc) |
| 4337 | goto out_err; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4338 | |
| 4339 | /* register lcu with alias handling, enable PAV if this is a new lcu */ |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 4340 | rc = dasd_alias_make_device_known_to_lcu(device); |
| 4341 | if (rc) |
| 4342 | return rc; |
Stefan Haberland | ea4da6e | 2013-02-19 09:30:05 +0100 | [diff] [blame] | 4343 | |
| 4344 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags); |
| 4345 | dasd_eckd_validate_server(device, cqr_flags); |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 4346 | |
| 4347 | /* RE-Read Configuration Data */ |
Stefan Haberland | 55d3a85 | 2012-11-27 17:04:14 +0100 | [diff] [blame] | 4348 | dasd_eckd_read_conf(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4349 | |
| 4350 | /* Read Feature Codes */ |
Stefan Weinhuber | 68d1e5f | 2009-09-22 22:58:52 +0200 | [diff] [blame] | 4351 | dasd_eckd_read_features(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4352 | |
| 4353 | /* Read Device Characteristics */ |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 4354 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 4355 | &temp_rdc_data, 64); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4356 | if (rc) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 4357 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
| 4358 | "Read device characteristic failed, rc=%d", rc); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4359 | goto out_err; |
| 4360 | } |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 4361 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 4362 | memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data)); |
Stefan Haberland | a7602f6 | 2009-10-14 12:43:46 +0200 | [diff] [blame] | 4363 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4364 | |
| 4365 | /* add device to alias management */ |
| 4366 | dasd_alias_add_device(device); |
| 4367 | |
| 4368 | return 0; |
| 4369 | |
| 4370 | out_err: |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 4371 | return -1; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4372 | } |
| 4373 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4374 | static int dasd_eckd_reload_device(struct dasd_device *device) |
| 4375 | { |
| 4376 | struct dasd_eckd_private *private; |
| 4377 | int rc, old_base; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4378 | char print_uid[60]; |
| 4379 | struct dasd_uid uid; |
| 4380 | unsigned long flags; |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4381 | |
| 4382 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4383 | |
| 4384 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4385 | old_base = private->uid.base_unit_addr; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4386 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 4387 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4388 | /* Read Configuration Data */ |
| 4389 | rc = dasd_eckd_read_conf(device); |
| 4390 | if (rc) |
| 4391 | goto out_err; |
| 4392 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4393 | rc = dasd_eckd_generate_uid(device); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4394 | if (rc) |
| 4395 | goto out_err; |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4396 | /* |
| 4397 | * update unit address configuration and |
| 4398 | * add device to alias management |
| 4399 | */ |
| 4400 | dasd_alias_update_add_device(device); |
| 4401 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4402 | dasd_eckd_get_uid(device, &uid); |
| 4403 | |
| 4404 | if (old_base != uid.base_unit_addr) { |
| 4405 | if (strlen(uid.vduit) > 0) |
| 4406 | snprintf(print_uid, sizeof(print_uid), |
| 4407 | "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial, |
| 4408 | uid.ssid, uid.base_unit_addr, uid.vduit); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4409 | else |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4410 | snprintf(print_uid, sizeof(print_uid), |
| 4411 | "%s.%s.%04x.%02x", uid.vendor, uid.serial, |
| 4412 | uid.ssid, uid.base_unit_addr); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4413 | |
| 4414 | dev_info(&device->cdev->dev, |
| 4415 | "An Alias device was reassigned to a new base device " |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4416 | "with UID: %s\n", print_uid); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4417 | } |
| 4418 | return 0; |
| 4419 | |
| 4420 | out_err: |
| 4421 | return -1; |
| 4422 | } |
| 4423 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4424 | static struct ccw_driver dasd_eckd_driver = { |
Sebastian Ott | 3bda058 | 2011-03-23 10:16:02 +0100 | [diff] [blame] | 4425 | .driver = { |
| 4426 | .name = "dasd-eckd", |
| 4427 | .owner = THIS_MODULE, |
| 4428 | }, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4429 | .ids = dasd_eckd_ids, |
| 4430 | .probe = dasd_eckd_probe, |
| 4431 | .remove = dasd_generic_remove, |
| 4432 | .set_offline = dasd_generic_set_offline, |
| 4433 | .set_online = dasd_eckd_set_online, |
| 4434 | .notify = dasd_generic_notify, |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4435 | .path_event = dasd_generic_path_event, |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 4436 | .shutdown = dasd_generic_shutdown, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4437 | .freeze = dasd_generic_pm_freeze, |
| 4438 | .thaw = dasd_generic_restore_device, |
| 4439 | .restore = dasd_generic_restore_device, |
Stefan Haberland | a23ed00 | 2010-05-26 23:27:09 +0200 | [diff] [blame] | 4440 | .uc_handler = dasd_generic_uc_handler, |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 4441 | .int_class = IRQIO_DAS, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4442 | }; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | /* |
| 4445 | * max_blocks is dependent on the amount of storage that is available |
| 4446 | * in the static io buffer for each device. Currently each device has |
| 4447 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has |
| 4448 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use |
| 4449 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In |
| 4450 | * addition we have one define extent ccw + 16 bytes of data and one |
| 4451 | * locate record ccw + 16 bytes of data. That makes: |
| 4452 | * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. |
| 4453 | * We want to fit two into the available memory so that we can immediately |
| 4454 | * start the next request if one finishes off. That makes 249.5 blocks |
| 4455 | * for one request. Give a little safety and the result is 240. |
| 4456 | */ |
| 4457 | static struct dasd_discipline dasd_eckd_discipline = { |
| 4458 | .owner = THIS_MODULE, |
| 4459 | .name = "ECKD", |
| 4460 | .ebcname = "ECKD", |
Stefan Weinhuber | ef19298b | 2011-01-05 12:48:02 +0100 | [diff] [blame] | 4461 | .max_blocks = 190, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | .check_device = dasd_eckd_check_characteristics, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4463 | .uncheck_device = dasd_eckd_uncheck_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | .do_analysis = dasd_eckd_do_analysis, |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4465 | .verify_path = dasd_eckd_verify_path, |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 4466 | .basic_to_ready = dasd_eckd_basic_to_ready, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4467 | .online_to_ready = dasd_eckd_online_to_ready, |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 4468 | .ready_to_basic = dasd_eckd_ready_to_basic, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | .fill_geometry = dasd_eckd_fill_geometry, |
| 4470 | .start_IO = dasd_start_IO, |
| 4471 | .term_IO = dasd_term_IO, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4472 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | .format_device = dasd_eckd_format_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | .erp_action = dasd_eckd_erp_action, |
| 4475 | .erp_postaction = dasd_eckd_erp_postaction, |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 4476 | .check_for_device_change = dasd_eckd_check_for_device_change, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4477 | .build_cp = dasd_eckd_build_alias_cp, |
| 4478 | .free_cp = dasd_eckd_free_alias_cp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | .dump_sense = dasd_eckd_dump_sense, |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4480 | .dump_sense_dbf = dasd_eckd_dump_sense_dbf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | .fill_info = dasd_eckd_fill_info, |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 4482 | .ioctl = dasd_eckd_ioctl, |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4483 | .freeze = dasd_eckd_pm_freeze, |
| 4484 | .restore = dasd_eckd_restore_device, |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 4485 | .reload = dasd_eckd_reload_device, |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 4486 | .get_uid = dasd_eckd_get_uid, |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 4487 | .kick_validate = dasd_eckd_kick_validate_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | }; |
| 4489 | |
| 4490 | static int __init |
| 4491 | dasd_eckd_init(void) |
| 4492 | { |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 4493 | int ret; |
| 4494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 4496 | dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req), |
| 4497 | GFP_KERNEL | GFP_DMA); |
| 4498 | if (!dasd_reserve_req) |
| 4499 | return -ENOMEM; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4500 | path_verification_worker = kmalloc(sizeof(*path_verification_worker), |
| 4501 | GFP_KERNEL | GFP_DMA); |
| 4502 | if (!path_verification_worker) { |
| 4503 | kfree(dasd_reserve_req); |
| 4504 | return -ENOMEM; |
| 4505 | } |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 4506 | rawpadpage = (void *)__get_free_page(GFP_KERNEL); |
| 4507 | if (!rawpadpage) { |
| 4508 | kfree(path_verification_worker); |
| 4509 | kfree(dasd_reserve_req); |
| 4510 | return -ENOMEM; |
| 4511 | } |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 4512 | ret = ccw_driver_register(&dasd_eckd_driver); |
| 4513 | if (!ret) |
| 4514 | wait_for_device_probe(); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4515 | else { |
| 4516 | kfree(path_verification_worker); |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 4517 | kfree(dasd_reserve_req); |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 4518 | free_page((unsigned long)rawpadpage); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4519 | } |
Sebastian Ott | 736e6ea | 2009-06-12 10:26:38 +0200 | [diff] [blame] | 4520 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | static void __exit |
| 4524 | dasd_eckd_cleanup(void) |
| 4525 | { |
| 4526 | ccw_driver_unregister(&dasd_eckd_driver); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4527 | kfree(path_verification_worker); |
Stefan Weinhuber | f932bce | 2010-08-09 18:12:59 +0200 | [diff] [blame] | 4528 | kfree(dasd_reserve_req); |
Stefan Weinhuber | 558b9ef | 2013-08-16 15:57:32 +0200 | [diff] [blame] | 4529 | free_page((unsigned long)rawpadpage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | module_init(dasd_eckd_init); |
| 4533 | module_exit(dasd_eckd_cleanup); |