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