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