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