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