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