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