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