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_diag.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Based on.......: linux/drivers/s390/block/mdisk.c |
| 5 | * ...............: by Hartmunt Penner <hpenner@de.ibm.com> |
| 6 | * Bugreports.to..: <Linux390@de.ibm.com> |
| 7 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/stddef.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/slab.h> |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 14 | #include <linux/hdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/bio.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 18 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/dasd.h> |
| 21 | #include <asm/debug.h> |
| 22 | #include <asm/ebcdic.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/s390_ext.h> |
| 25 | #include <asm/todclk.h> |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 26 | #include <asm/vtoc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include "dasd_int.h" |
| 29 | #include "dasd_diag.h" |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define PRINTK_HEADER "dasd(diag):" |
| 32 | |
| 33 | MODULE_LICENSE("GPL"); |
| 34 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 35 | /* The maximum number of blocks per request (max_blocks) is dependent on the |
| 36 | * amount of storage that is available in the static I/O buffer for each |
| 37 | * device. Currently each device gets 2 pages. We want to fit two requests |
| 38 | * into the available memory so that we can immediately start the next if one |
| 39 | * finishes. */ |
| 40 | #define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \ |
| 41 | sizeof(struct dasd_diag_req)) / \ |
| 42 | sizeof(struct dasd_diag_bio)) / 2) |
| 43 | #define DIAG_MAX_RETRIES 32 |
| 44 | #define DIAG_TIMEOUT 50 * HZ |
| 45 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 46 | static struct dasd_discipline dasd_diag_discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | struct dasd_diag_private { |
| 49 | struct dasd_diag_characteristics rdc_data; |
| 50 | struct dasd_diag_rw_io iob; |
| 51 | struct dasd_diag_init_io iib; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 52 | blocknum_t pt_block; |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 53 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct dasd_diag_req { |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 57 | unsigned int block_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | struct dasd_diag_bio bio[0]; |
| 59 | }; |
| 60 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 61 | static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */ |
| 62 | |
| 63 | /* Perform DIAG250 call with block I/O parameter list iob (input and output) |
| 64 | * and function code cmd. |
| 65 | * In case of an exception return 3. Otherwise return result of bitwise OR of |
| 66 | * resulting condition code and DIAG return code. */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 67 | static inline int dia250(void *iob, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Peter Oberparleiter | 0443969 | 2007-03-26 20:42:38 +0200 | [diff] [blame] | 69 | register unsigned long reg2 asm ("2") = (unsigned long) iob; |
Peter Oberparleiter | 86b368a | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 70 | typedef union { |
| 71 | struct dasd_diag_init_io init_io; |
| 72 | struct dasd_diag_rw_io rw_io; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 73 | } addr_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | int rc; |
| 75 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 76 | rc = 3; |
| 77 | asm volatile( |
Peter Oberparleiter | 0443969 | 2007-03-26 20:42:38 +0200 | [diff] [blame] | 78 | " diag 2,%2,0x250\n" |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 79 | "0: ipm %0\n" |
| 80 | " srl %0,28\n" |
Peter Oberparleiter | 0443969 | 2007-03-26 20:42:38 +0200 | [diff] [blame] | 81 | " or %0,3\n" |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 82 | "1:\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 83 | EX_TABLE(0b,1b) |
| 84 | : "+d" (rc), "=m" (*(addr_type *) iob) |
Peter Oberparleiter | 0443969 | 2007-03-26 20:42:38 +0200 | [diff] [blame] | 85 | : "d" (cmd), "d" (reg2), "m" (*(addr_type *) iob) |
| 86 | : "3", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | return rc; |
| 88 | } |
| 89 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 90 | /* Initialize block I/O to DIAG device using the specified blocksize and |
| 91 | * block offset. On success, return zero and set end_block to contain the |
| 92 | * number of blocks on the device minus the specified offset. Return non-zero |
| 93 | * otherwise. */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 94 | static inline int |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 95 | mdsk_init_io(struct dasd_device *device, unsigned int blocksize, |
| 96 | blocknum_t offset, blocknum_t *end_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | struct dasd_diag_private *private; |
| 99 | struct dasd_diag_init_io *iib; |
| 100 | int rc; |
| 101 | |
| 102 | private = (struct dasd_diag_private *) device->private; |
| 103 | iib = &private->iib; |
| 104 | memset(iib, 0, sizeof (struct dasd_diag_init_io)); |
| 105 | |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 106 | iib->dev_nr = private->dev_id.devno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | iib->block_size = blocksize; |
| 108 | iib->offset = offset; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 109 | iib->flaga = DASD_DIAG_FLAGA_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | rc = dia250(iib, INIT_BIO); |
| 112 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 113 | if ((rc & 3) == 0 && end_block) |
| 114 | *end_block = iib->end_block; |
| 115 | |
| 116 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 119 | /* Remove block I/O environment for device. Return zero on success, non-zero |
| 120 | * otherwise. */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 121 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | mdsk_term_io(struct dasd_device * device) |
| 123 | { |
| 124 | struct dasd_diag_private *private; |
| 125 | struct dasd_diag_init_io *iib; |
| 126 | int rc; |
| 127 | |
| 128 | private = (struct dasd_diag_private *) device->private; |
| 129 | iib = &private->iib; |
| 130 | memset(iib, 0, sizeof (struct dasd_diag_init_io)); |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 131 | iib->dev_nr = private->dev_id.devno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | rc = dia250(iib, TERM_BIO); |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 133 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 136 | /* Error recovery for failed DIAG requests - try to reestablish the DIAG |
| 137 | * environment. */ |
| 138 | static void |
| 139 | dasd_diag_erp(struct dasd_device *device) |
| 140 | { |
| 141 | int rc; |
| 142 | |
| 143 | mdsk_term_io(device); |
| 144 | rc = mdsk_init_io(device, device->bp_block, 0, NULL); |
| 145 | if (rc) |
| 146 | DEV_MESSAGE(KERN_WARNING, device, "DIAG ERP unsuccessful, " |
| 147 | "rc=%d", rc); |
| 148 | } |
| 149 | |
| 150 | /* Start a given request at the device. Return zero on success, non-zero |
| 151 | * otherwise. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static int |
| 153 | dasd_start_diag(struct dasd_ccw_req * cqr) |
| 154 | { |
| 155 | struct dasd_device *device; |
| 156 | struct dasd_diag_private *private; |
| 157 | struct dasd_diag_req *dreq; |
| 158 | int rc; |
| 159 | |
| 160 | device = cqr->device; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 161 | if (cqr->retries < 0) { |
| 162 | DEV_MESSAGE(KERN_WARNING, device, "DIAG start_IO: request %p " |
| 163 | "- no retry left)", cqr); |
| 164 | cqr->status = DASD_CQR_FAILED; |
| 165 | return -EIO; |
| 166 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | private = (struct dasd_diag_private *) device->private; |
| 168 | dreq = (struct dasd_diag_req *) cqr->data; |
| 169 | |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 170 | private->iob.dev_nr = private->dev_id.devno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | private->iob.key = 0; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 172 | private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | private->iob.block_count = dreq->block_count; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 174 | private->iob.interrupt_params = (addr_t) cqr; |
Peter Oberparleiter | 86b368a | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 175 | private->iob.bio_list = dreq->bio; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 176 | private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | cqr->startclk = get_clock(); |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 179 | cqr->starttime = jiffies; |
| 180 | cqr->retries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | rc = dia250(&private->iob, RW_BIO); |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 183 | switch (rc) { |
| 184 | case 0: /* Synchronous I/O finished successfully */ |
| 185 | cqr->stopclk = get_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | cqr->status = DASD_CQR_DONE; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 187 | /* Indicate to calling function that only a dasd_schedule_bh() |
| 188 | and no timer is needed */ |
| 189 | rc = -EACCES; |
| 190 | break; |
| 191 | case 8: /* Asynchronous I/O was started */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | cqr->status = DASD_CQR_IN_IO; |
| 193 | rc = 0; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 194 | break; |
| 195 | default: /* Error condition */ |
| 196 | cqr->status = DASD_CQR_QUEUED; |
| 197 | DEV_MESSAGE(KERN_WARNING, device, "dia250 returned rc=%d", rc); |
| 198 | dasd_diag_erp(device); |
| 199 | rc = -EIO; |
| 200 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | return rc; |
| 203 | } |
| 204 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 205 | /* Terminate given request at the device. */ |
| 206 | static int |
| 207 | dasd_diag_term_IO(struct dasd_ccw_req * cqr) |
| 208 | { |
| 209 | struct dasd_device *device; |
| 210 | |
| 211 | device = cqr->device; |
| 212 | mdsk_term_io(device); |
| 213 | mdsk_init_io(device, device->bp_block, 0, NULL); |
| 214 | cqr->status = DASD_CQR_CLEAR; |
| 215 | cqr->stopclk = get_clock(); |
| 216 | dasd_schedule_bh(device); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /* Handle external interruption. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static void |
Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 222 | dasd_ext_handler(__u16 code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
| 224 | struct dasd_ccw_req *cqr, *next; |
| 225 | struct dasd_device *device; |
| 226 | unsigned long long expires; |
| 227 | unsigned long flags; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 228 | u8 int_code, status; |
| 229 | addr_t ip; |
| 230 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 232 | int_code = *((u8 *) DASD_DIAG_LC_INT_CODE); |
| 233 | status = *((u8 *) DASD_DIAG_LC_INT_STATUS); |
| 234 | switch (int_code) { |
| 235 | case DASD_DIAG_CODE_31BIT: |
| 236 | ip = (addr_t) *((u32 *) DASD_DIAG_LC_INT_PARM_31BIT); |
| 237 | break; |
| 238 | case DASD_DIAG_CODE_64BIT: |
| 239 | ip = (addr_t) *((u64 *) DASD_DIAG_LC_INT_PARM_64BIT); |
| 240 | break; |
| 241 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if (!ip) { /* no intparm: unsolicited interrupt */ |
| 245 | MESSAGE(KERN_DEBUG, "%s", "caught unsolicited interrupt"); |
| 246 | return; |
| 247 | } |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 248 | cqr = (struct dasd_ccw_req *) ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | device = (struct dasd_device *) cqr->device; |
| 250 | if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
| 251 | DEV_MESSAGE(KERN_WARNING, device, |
| 252 | " magic number of dasd_ccw_req 0x%08X doesn't" |
| 253 | " match discipline 0x%08X", |
| 254 | cqr->magic, *(int *) (&device->discipline->name)); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | /* get irq lock to modify request queue */ |
| 259 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 260 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 261 | /* Check for a pending clear operation */ |
| 262 | if (cqr->status == DASD_CQR_CLEAR) { |
| 263 | cqr->status = DASD_CQR_QUEUED; |
| 264 | dasd_clear_timer(device); |
| 265 | dasd_schedule_bh(device); |
| 266 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 267 | return; |
| 268 | } |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | cqr->stopclk = get_clock(); |
| 271 | |
| 272 | expires = 0; |
| 273 | if (status == 0) { |
| 274 | cqr->status = DASD_CQR_DONE; |
| 275 | /* Start first request on queue if possible -> fast_io. */ |
| 276 | if (!list_empty(&device->ccw_queue)) { |
| 277 | next = list_entry(device->ccw_queue.next, |
| 278 | struct dasd_ccw_req, list); |
| 279 | if (next->status == DASD_CQR_QUEUED) { |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 280 | rc = dasd_start_diag(next); |
| 281 | if (rc == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | expires = next->expires; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 283 | else if (rc != -EACCES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 285 | "Interrupt fastpath " |
| 286 | "failed!"); |
| 287 | } |
| 288 | } |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 289 | } else { |
| 290 | cqr->status = DASD_CQR_QUEUED; |
| 291 | DEV_MESSAGE(KERN_WARNING, device, "interrupt status for " |
| 292 | "request %p was %d (%d retries left)", cqr, status, |
| 293 | cqr->retries); |
| 294 | dasd_diag_erp(device); |
| 295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | if (expires != 0) |
| 298 | dasd_set_timer(device, expires); |
| 299 | else |
| 300 | dasd_clear_timer(device); |
| 301 | dasd_schedule_bh(device); |
| 302 | |
| 303 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 304 | } |
| 305 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 306 | /* Check whether device can be controlled by DIAG discipline. Return zero on |
| 307 | * success, non-zero otherwise. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | static int |
| 309 | dasd_diag_check_device(struct dasd_device *device) |
| 310 | { |
| 311 | struct dasd_diag_private *private; |
| 312 | struct dasd_diag_characteristics *rdc_data; |
| 313 | struct dasd_diag_bio bio; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 314 | struct vtoc_cms_label *label; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 315 | blocknum_t end_block; |
| 316 | unsigned int sb, bsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | int rc; |
| 318 | |
| 319 | private = (struct dasd_diag_private *) device->private; |
| 320 | if (private == NULL) { |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 321 | private = kzalloc(sizeof(struct dasd_diag_private),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (private == NULL) { |
| 323 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 324 | "memory allocation failed for private data"); |
| 325 | return -ENOMEM; |
| 326 | } |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 327 | ccw_device_get_id(device->cdev, &private->dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | device->private = (void *) private; |
| 329 | } |
| 330 | /* Read Device Characteristics */ |
| 331 | rdc_data = (void *) &(private->rdc_data); |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 332 | rdc_data->dev_nr = private->dev_id.devno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); |
| 334 | |
| 335 | rc = diag210((struct diag210 *) rdc_data); |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 336 | if (rc) { |
| 337 | DEV_MESSAGE(KERN_WARNING, device, "failed to retrieve device " |
| 338 | "information (rc=%d)", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return -ENOTSUPP; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* Figure out position of label block */ |
| 343 | switch (private->rdc_data.vdev_class) { |
| 344 | case DEV_CLASS_FBA: |
| 345 | private->pt_block = 1; |
| 346 | break; |
| 347 | case DEV_CLASS_ECKD: |
| 348 | private->pt_block = 2; |
| 349 | break; |
| 350 | default: |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 351 | DEV_MESSAGE(KERN_WARNING, device, "unsupported device class " |
| 352 | "(class=%d)", private->rdc_data.vdev_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return -ENOTSUPP; |
| 354 | } |
| 355 | |
| 356 | DBF_DEV_EVENT(DBF_INFO, device, |
| 357 | "%04X: %04X on real %04X/%02X", |
| 358 | rdc_data->dev_nr, |
| 359 | rdc_data->vdev_type, |
| 360 | rdc_data->rdev_type, rdc_data->rdev_model); |
| 361 | |
| 362 | /* terminate all outstanding operations */ |
| 363 | mdsk_term_io(device); |
| 364 | |
| 365 | /* figure out blocksize of device */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 366 | label = (struct vtoc_cms_label *) get_zeroed_page(GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if (label == NULL) { |
| 368 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 369 | "No memory to allocate initialization request"); |
| 370 | return -ENOMEM; |
| 371 | } |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 372 | rc = 0; |
| 373 | end_block = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* try all sizes - needed for ECKD devices */ |
| 375 | for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) { |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 376 | mdsk_init_io(device, bsize, 0, &end_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | memset(&bio, 0, sizeof (struct dasd_diag_bio)); |
| 378 | bio.type = MDSK_READ_REQ; |
| 379 | bio.block_number = private->pt_block + 1; |
Peter Oberparleiter | 86b368a | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 380 | bio.buffer = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io)); |
| 382 | private->iob.dev_nr = rdc_data->dev_nr; |
| 383 | private->iob.key = 0; |
| 384 | private->iob.flags = 0; /* do synchronous io */ |
| 385 | private->iob.block_count = 1; |
| 386 | private->iob.interrupt_params = 0; |
Peter Oberparleiter | 86b368a | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 387 | private->iob.bio_list = &bio; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 388 | private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
| 389 | rc = dia250(&private->iob, RW_BIO); |
Peter Oberparleiter | 1e0291b | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 390 | if (rc == 3) { |
| 391 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 392 | "DIAG call failed"); |
| 393 | rc = -EOPNOTSUPP; |
| 394 | goto out; |
| 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | mdsk_term_io(device); |
Peter Oberparleiter | 1e0291b | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 397 | if (rc == 0) |
| 398 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
Peter Oberparleiter | 1e0291b | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 400 | if (bsize > PAGE_SIZE) { |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 401 | DEV_MESSAGE(KERN_WARNING, device, "device access failed " |
| 402 | "(rc=%d)", rc); |
| 403 | rc = -EIO; |
Peter Oberparleiter | 1e0291b | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 404 | goto out; |
| 405 | } |
| 406 | /* check for label block */ |
| 407 | if (memcmp(label->label_id, DASD_DIAG_CMS1, |
| 408 | sizeof(DASD_DIAG_CMS1)) == 0) { |
| 409 | /* get formatted blocksize from label block */ |
| 410 | bsize = (unsigned int) label->block_size; |
| 411 | device->blocks = (unsigned long) label->block_count; |
| 412 | } else |
| 413 | device->blocks = end_block; |
| 414 | device->bp_block = bsize; |
| 415 | device->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 416 | for (sb = 512; sb < bsize; sb = sb << 1) |
| 417 | device->s2b_shift++; |
| 418 | rc = mdsk_init_io(device, device->bp_block, 0, NULL); |
| 419 | if (rc) { |
| 420 | DEV_MESSAGE(KERN_WARNING, device, "DIAG initialization " |
| 421 | "failed (rc=%d)", rc); |
| 422 | rc = -EIO; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 423 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | DEV_MESSAGE(KERN_INFO, device, |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 425 | "(%ld B/blk): %ldkB", |
| 426 | (unsigned long) device->bp_block, |
| 427 | (unsigned long) (device->blocks << |
| 428 | device->s2b_shift) >> 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
Peter Oberparleiter | 1e0291b | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 430 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | free_page((long) label); |
| 432 | return rc; |
| 433 | } |
| 434 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 435 | /* Fill in virtual disk geometry for device. Return zero on success, non-zero |
| 436 | * otherwise. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | static int |
| 438 | dasd_diag_fill_geometry(struct dasd_device *device, struct hd_geometry *geo) |
| 439 | { |
| 440 | if (dasd_check_blocksize(device->bp_block) != 0) |
| 441 | return -EINVAL; |
| 442 | geo->cylinders = (device->blocks << device->s2b_shift) >> 10; |
| 443 | geo->heads = 16; |
| 444 | geo->sectors = 128 >> device->s2b_shift; |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static dasd_era_t |
| 449 | dasd_diag_examine_error(struct dasd_ccw_req * cqr, struct irb * stat) |
| 450 | { |
| 451 | return dasd_era_fatal; |
| 452 | } |
| 453 | |
| 454 | static dasd_erp_fn_t |
| 455 | dasd_diag_erp_action(struct dasd_ccw_req * cqr) |
| 456 | { |
| 457 | return dasd_default_erp_action; |
| 458 | } |
| 459 | |
| 460 | static dasd_erp_fn_t |
| 461 | dasd_diag_erp_postaction(struct dasd_ccw_req * cqr) |
| 462 | { |
| 463 | return dasd_default_erp_postaction; |
| 464 | } |
| 465 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 466 | /* Create DASD request from block device request. Return pointer to new |
| 467 | * request on success, ERR_PTR otherwise. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | static struct dasd_ccw_req * |
| 469 | dasd_diag_build_cp(struct dasd_device * device, struct request *req) |
| 470 | { |
| 471 | struct dasd_ccw_req *cqr; |
| 472 | struct dasd_diag_req *dreq; |
| 473 | struct dasd_diag_bio *dbio; |
| 474 | struct bio *bio; |
| 475 | struct bio_vec *bv; |
| 476 | char *dst; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 477 | unsigned int count, datasize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | sector_t recid, first_rec, last_rec; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 479 | unsigned int blksize, off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | unsigned char rw_cmd; |
| 481 | int i; |
| 482 | |
| 483 | if (rq_data_dir(req) == READ) |
| 484 | rw_cmd = MDSK_READ_REQ; |
| 485 | else if (rq_data_dir(req) == WRITE) |
| 486 | rw_cmd = MDSK_WRITE_REQ; |
| 487 | else |
| 488 | return ERR_PTR(-EINVAL); |
| 489 | blksize = device->bp_block; |
| 490 | /* Calculate record id of first and last block. */ |
| 491 | first_rec = req->sector >> device->s2b_shift; |
| 492 | last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift; |
| 493 | /* Check struct bio and count the number of blocks for the request. */ |
| 494 | count = 0; |
| 495 | rq_for_each_bio(bio, req) { |
| 496 | bio_for_each_segment(bv, bio, i) { |
| 497 | if (bv->bv_len & (blksize - 1)) |
| 498 | /* Fba can only do full blocks. */ |
| 499 | return ERR_PTR(-EINVAL); |
| 500 | count += bv->bv_len >> (device->s2b_shift + 9); |
| 501 | } |
| 502 | } |
| 503 | /* Paranoia. */ |
| 504 | if (count != last_rec - first_rec + 1) |
| 505 | return ERR_PTR(-EINVAL); |
| 506 | /* Build the request */ |
| 507 | datasize = sizeof(struct dasd_diag_req) + |
| 508 | count*sizeof(struct dasd_diag_bio); |
| 509 | cqr = dasd_smalloc_request(dasd_diag_discipline.name, 0, |
| 510 | datasize, device); |
| 511 | if (IS_ERR(cqr)) |
| 512 | return cqr; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | dreq = (struct dasd_diag_req *) cqr->data; |
| 515 | dreq->block_count = count; |
| 516 | dbio = dreq->bio; |
| 517 | recid = first_rec; |
| 518 | rq_for_each_bio(bio, req) { |
| 519 | bio_for_each_segment(bv, bio, i) { |
| 520 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 521 | for (off = 0; off < bv->bv_len; off += blksize) { |
| 522 | memset(dbio, 0, sizeof (struct dasd_diag_bio)); |
| 523 | dbio->type = rw_cmd; |
| 524 | dbio->block_number = recid + 1; |
Peter Oberparleiter | 86b368a | 2005-11-07 00:59:08 -0800 | [diff] [blame] | 525 | dbio->buffer = dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | dbio++; |
| 527 | dst += blksize; |
| 528 | recid++; |
| 529 | } |
| 530 | } |
| 531 | } |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 532 | cqr->retries = DIAG_MAX_RETRIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | cqr->buildclk = get_clock(); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 534 | if (req->cmd_flags & REQ_FAILFAST) |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 535 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | cqr->device = device; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 537 | cqr->expires = DIAG_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | cqr->status = DASD_CQR_FILLED; |
| 539 | return cqr; |
| 540 | } |
| 541 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 542 | /* Release DASD request. Return non-zero if request was successful, zero |
| 543 | * otherwise. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | static int |
| 545 | dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 546 | { |
| 547 | int status; |
| 548 | |
| 549 | status = cqr->status == DASD_CQR_DONE; |
| 550 | dasd_sfree_request(cqr, cqr->device); |
| 551 | return status; |
| 552 | } |
| 553 | |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 554 | /* Fill in IOCTL data for device. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | static int |
| 556 | dasd_diag_fill_info(struct dasd_device * device, |
| 557 | struct dasd_information2_t * info) |
| 558 | { |
| 559 | struct dasd_diag_private *private; |
| 560 | |
| 561 | private = (struct dasd_diag_private *) device->private; |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 562 | info->label_block = (unsigned int) private->pt_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | info->FBA_layout = 1; |
| 564 | info->format = DASD_FORMAT_LDL; |
| 565 | info->characteristics_size = sizeof (struct dasd_diag_characteristics); |
| 566 | memcpy(info->characteristics, |
| 567 | &((struct dasd_diag_private *) device->private)->rdc_data, |
| 568 | sizeof (struct dasd_diag_characteristics)); |
| 569 | info->confdata_size = 0; |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static void |
| 574 | dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req, |
| 575 | struct irb *stat) |
| 576 | { |
| 577 | DEV_MESSAGE(KERN_ERR, device, "%s", |
| 578 | "dump sense not available for DIAG data"); |
| 579 | } |
| 580 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 581 | static struct dasd_discipline dasd_diag_discipline = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | .owner = THIS_MODULE, |
| 583 | .name = "DIAG", |
| 584 | .ebcname = "DIAG", |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 585 | .max_blocks = DIAG_MAX_BLOCKS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | .check_device = dasd_diag_check_device, |
| 587 | .fill_geometry = dasd_diag_fill_geometry, |
| 588 | .start_IO = dasd_start_diag, |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 589 | .term_IO = dasd_diag_term_IO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | .examine_error = dasd_diag_examine_error, |
| 591 | .erp_action = dasd_diag_erp_action, |
| 592 | .erp_postaction = dasd_diag_erp_postaction, |
| 593 | .build_cp = dasd_diag_build_cp, |
| 594 | .free_cp = dasd_diag_free_cp, |
| 595 | .dump_sense = dasd_diag_dump_sense, |
| 596 | .fill_info = dasd_diag_fill_info, |
| 597 | }; |
| 598 | |
| 599 | static int __init |
| 600 | dasd_diag_init(void) |
| 601 | { |
| 602 | if (!MACHINE_IS_VM) { |
| 603 | MESSAGE_LOG(KERN_INFO, |
| 604 | "Machine is not VM: %s " |
| 605 | "discipline not initializing", |
| 606 | dasd_diag_discipline.name); |
Horst Hummel | fd49f41 | 2005-09-03 15:58:00 -0700 | [diff] [blame] | 607 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | ASCEBC(dasd_diag_discipline.ebcname, 4); |
| 610 | |
| 611 | ctl_set_bit(0, 9); |
| 612 | register_external_interrupt(0x2603, dasd_ext_handler); |
| 613 | dasd_diag_discipline_pointer = &dasd_diag_discipline; |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static void __exit |
| 618 | dasd_diag_cleanup(void) |
| 619 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | unregister_external_interrupt(0x2603, dasd_ext_handler); |
| 621 | ctl_clear_bit(0, 9); |
| 622 | dasd_diag_discipline_pointer = NULL; |
| 623 | } |
| 624 | |
| 625 | module_init(dasd_diag_init); |
| 626 | module_exit(dasd_diag_cleanup); |