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