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