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