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