Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File...........: linux/drivers/s390/block/dasd.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 8 | * Copyright IBM Corp. 1999, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 11 | #define KMSG_COMPONENT "dasd" |
| 12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kmod.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/major.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/buffer_head.h> |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 21 | #include <linux/hdreg.h> |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 22 | #include <linux/async.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <asm/ccwdev.h> |
| 25 | #include <asm/ebcdic.h> |
| 26 | #include <asm/idals.h> |
| 27 | #include <asm/todclk.h> |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 28 | #include <asm/itcw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | /* This is ugly... */ |
| 31 | #define PRINTK_HEADER "dasd:" |
| 32 | |
| 33 | #include "dasd_int.h" |
| 34 | /* |
| 35 | * SECTION: Constant definitions to be used within this file |
| 36 | */ |
| 37 | #define DASD_CHANQ_MAX_SIZE 4 |
| 38 | |
| 39 | /* |
| 40 | * SECTION: exported variables of dasd.c |
| 41 | */ |
| 42 | debug_info_t *dasd_debug_area; |
| 43 | struct dasd_discipline *dasd_diag_discipline_pointer; |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 44 | void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>"); |
| 47 | MODULE_DESCRIPTION("Linux on S/390 DASD device driver," |
| 48 | " Copyright 2000 IBM Corporation"); |
| 49 | MODULE_SUPPORTED_DEVICE("dasd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | MODULE_LICENSE("GPL"); |
| 51 | |
| 52 | /* |
| 53 | * SECTION: prototypes for static functions of dasd.c |
| 54 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 55 | static int dasd_alloc_queue(struct dasd_block *); |
| 56 | static void dasd_setup_queue(struct dasd_block *); |
| 57 | static void dasd_free_queue(struct dasd_block *); |
| 58 | static void dasd_flush_request_queue(struct dasd_block *); |
| 59 | static int dasd_flush_block_queue(struct dasd_block *); |
| 60 | static void dasd_device_tasklet(struct dasd_device *); |
| 61 | static void dasd_block_tasklet(struct dasd_block *); |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 62 | static void do_kick_device(struct work_struct *); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 63 | static void do_restore_device(struct work_struct *); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 64 | static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *); |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 65 | static void dasd_device_timeout(unsigned long); |
| 66 | static void dasd_block_timeout(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * SECTION: Operations on the device structure. |
| 70 | */ |
| 71 | static wait_queue_head_t dasd_init_waitq; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 72 | static wait_queue_head_t dasd_flush_wq; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 73 | static wait_queue_head_t generic_waitq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Allocate memory for a new device structure. |
| 77 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 78 | struct dasd_device *dasd_alloc_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | struct dasd_device *device; |
| 81 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 82 | device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC); |
| 83 | if (!device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* Get two pages for normal block device operations. */ |
| 87 | device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 88 | if (!device->ccw_mem) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | kfree(device); |
| 90 | return ERR_PTR(-ENOMEM); |
| 91 | } |
| 92 | /* Get one page for error recovery. */ |
| 93 | device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 94 | if (!device->erp_mem) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | free_pages((unsigned long) device->ccw_mem, 1); |
| 96 | kfree(device); |
| 97 | return ERR_PTR(-ENOMEM); |
| 98 | } |
| 99 | |
| 100 | dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2); |
| 101 | dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE); |
| 102 | spin_lock_init(&device->mem_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 103 | atomic_set(&device->tasklet_scheduled, 0); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 104 | tasklet_init(&device->tasklet, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 105 | (void (*)(unsigned long)) dasd_device_tasklet, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | (unsigned long) device); |
| 107 | INIT_LIST_HEAD(&device->ccw_queue); |
| 108 | init_timer(&device->timer); |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 109 | device->timer.function = dasd_device_timeout; |
| 110 | device->timer.data = (unsigned long) device; |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 111 | INIT_WORK(&device->kick_work, do_kick_device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 112 | INIT_WORK(&device->restore_device, do_restore_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | device->state = DASD_STATE_NEW; |
| 114 | device->target = DASD_STATE_NEW; |
| 115 | |
| 116 | return device; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * Free memory of a device structure. |
| 121 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 122 | void dasd_free_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 124 | kfree(device->private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | free_page((unsigned long) device->erp_mem); |
| 126 | free_pages((unsigned long) device->ccw_mem, 1); |
| 127 | kfree(device); |
| 128 | } |
| 129 | |
| 130 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 131 | * Allocate memory for a new device structure. |
| 132 | */ |
| 133 | struct dasd_block *dasd_alloc_block(void) |
| 134 | { |
| 135 | struct dasd_block *block; |
| 136 | |
| 137 | block = kzalloc(sizeof(*block), GFP_ATOMIC); |
| 138 | if (!block) |
| 139 | return ERR_PTR(-ENOMEM); |
| 140 | /* open_count = 0 means device online but not in use */ |
| 141 | atomic_set(&block->open_count, -1); |
| 142 | |
| 143 | spin_lock_init(&block->request_queue_lock); |
| 144 | atomic_set(&block->tasklet_scheduled, 0); |
| 145 | tasklet_init(&block->tasklet, |
| 146 | (void (*)(unsigned long)) dasd_block_tasklet, |
| 147 | (unsigned long) block); |
| 148 | INIT_LIST_HEAD(&block->ccw_queue); |
| 149 | spin_lock_init(&block->queue_lock); |
| 150 | init_timer(&block->timer); |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 151 | block->timer.function = dasd_block_timeout; |
| 152 | block->timer.data = (unsigned long) block; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 153 | |
| 154 | return block; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Free memory of a device structure. |
| 159 | */ |
| 160 | void dasd_free_block(struct dasd_block *block) |
| 161 | { |
| 162 | kfree(block); |
| 163 | } |
| 164 | |
| 165 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * Make a new device known to the system. |
| 167 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 168 | static int dasd_state_new_to_known(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
| 170 | int rc; |
| 171 | |
| 172 | /* |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 173 | * As long as the device is not in state DASD_STATE_NEW we want to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * keep the reference count > 0. |
| 175 | */ |
| 176 | dasd_get_device(device); |
| 177 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 178 | if (device->block) { |
| 179 | rc = dasd_alloc_queue(device->block); |
| 180 | if (rc) { |
| 181 | dasd_put_device(device); |
| 182 | return rc; |
| 183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | device->state = DASD_STATE_KNOWN; |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Let the system forget about a device. |
| 191 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 192 | static int dasd_state_known_to_new(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 194 | /* Disable extended error reporting for this device. */ |
| 195 | dasd_eer_disable(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | /* Forget the discipline information. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 197 | if (device->discipline) { |
| 198 | if (device->discipline->uncheck_device) |
| 199 | device->discipline->uncheck_device(device); |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 200 | module_put(device->discipline->owner); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | device->discipline = NULL; |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 203 | if (device->base_discipline) |
| 204 | module_put(device->base_discipline->owner); |
| 205 | device->base_discipline = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | device->state = DASD_STATE_NEW; |
| 207 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 208 | if (device->block) |
| 209 | dasd_free_queue(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* Give up reference we took in dasd_state_new_to_known. */ |
| 212 | dasd_put_device(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Request the irq line for the device. |
| 218 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 219 | static int dasd_state_known_to_basic(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | int rc; |
| 222 | |
| 223 | /* Allocate and register gendisk structure. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 224 | if (device->block) { |
| 225 | rc = dasd_gendisk_alloc(device->block); |
| 226 | if (rc) |
| 227 | return rc; |
| 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* register 'device' debug area, used for all DBF_DEV_XXX calls */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 230 | device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 231 | 8 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | debug_register_view(device->debug_area, &debug_sprintf_view); |
Horst Hummel | b0035f1 | 2006-09-20 15:59:07 +0200 | [diff] [blame] | 233 | debug_set_level(device->debug_area, DBF_WARNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created"); |
| 235 | |
| 236 | device->state = DASD_STATE_BASIC; |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Release the irq line for the device. Terminate any running i/o. |
| 242 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 243 | static int dasd_state_basic_to_known(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 245 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 246 | if (device->block) { |
| 247 | dasd_gendisk_free(device->block); |
| 248 | dasd_block_clear_timer(device->block); |
| 249 | } |
| 250 | rc = dasd_flush_device_queue(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 251 | if (rc) |
| 252 | return rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 253 | dasd_device_clear_timer(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device); |
| 256 | if (device->debug_area != NULL) { |
| 257 | debug_unregister(device->debug_area); |
| 258 | device->debug_area = NULL; |
| 259 | } |
| 260 | device->state = DASD_STATE_KNOWN; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 261 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Do the initial analysis. The do_analysis function may return |
| 266 | * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC |
| 267 | * until the discipline decides to continue the startup sequence |
| 268 | * by calling the function dasd_change_state. The eckd disciplines |
| 269 | * uses this to start a ccw that detects the format. The completion |
| 270 | * interrupt for this detection ccw uses the kernel event daemon to |
| 271 | * trigger the call to dasd_change_state. All this is done in the |
| 272 | * discipline code, see dasd_eckd.c. |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 273 | * After the analysis ccw is done (do_analysis returned 0) the block |
| 274 | * device is setup. |
| 275 | * In case the analysis returns an error, the device setup is stopped |
| 276 | * (a fake disk was already added to allow formatting). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 278 | static int dasd_state_basic_to_ready(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
| 280 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 281 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | rc = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 284 | block = device->block; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 285 | /* make disk known with correct capacity */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 286 | if (block) { |
| 287 | if (block->base->discipline->do_analysis != NULL) |
| 288 | rc = block->base->discipline->do_analysis(block); |
| 289 | if (rc) { |
| 290 | if (rc != -EAGAIN) |
| 291 | device->state = DASD_STATE_UNFMT; |
| 292 | return rc; |
| 293 | } |
| 294 | dasd_setup_queue(block); |
| 295 | set_capacity(block->gdp, |
| 296 | block->blocks << block->s2b_shift); |
| 297 | device->state = DASD_STATE_READY; |
| 298 | rc = dasd_scan_partitions(block); |
| 299 | if (rc) |
| 300 | device->state = DASD_STATE_BASIC; |
| 301 | } else { |
| 302 | device->state = DASD_STATE_READY; |
| 303 | } |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 304 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Remove device from block device layer. Destroy dirty buffers. |
| 309 | * Forget format information. Check if the target level is basic |
| 310 | * and if it is create fake disk for formatting. |
| 311 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 312 | static int dasd_state_ready_to_basic(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 314 | int rc; |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | device->state = DASD_STATE_BASIC; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 317 | if (device->block) { |
| 318 | struct dasd_block *block = device->block; |
| 319 | rc = dasd_flush_block_queue(block); |
| 320 | if (rc) { |
| 321 | device->state = DASD_STATE_READY; |
| 322 | return rc; |
| 323 | } |
| 324 | dasd_destroy_partitions(block); |
| 325 | dasd_flush_request_queue(block); |
| 326 | block->blocks = 0; |
| 327 | block->bp_block = 0; |
| 328 | block->s2b_shift = 0; |
| 329 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 330 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 334 | * Back to basic. |
| 335 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 336 | static int dasd_state_unfmt_to_basic(struct dasd_device *device) |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 337 | { |
| 338 | device->state = DASD_STATE_BASIC; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 339 | return 0; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | * Make the device online and schedule the bottom half to start |
| 344 | * the requeueing of requests from the linux request queue to the |
| 345 | * ccw queue. |
| 346 | */ |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 347 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | dasd_state_ready_to_online(struct dasd_device * device) |
| 349 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 350 | int rc; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 351 | struct gendisk *disk; |
| 352 | struct disk_part_iter piter; |
| 353 | struct hd_struct *part; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 354 | |
| 355 | if (device->discipline->ready_to_online) { |
| 356 | rc = device->discipline->ready_to_online(device); |
| 357 | if (rc) |
| 358 | return rc; |
| 359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | device->state = DASD_STATE_ONLINE; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 361 | if (device->block) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 362 | dasd_schedule_block_bh(device->block); |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 363 | disk = device->block->bdev->bd_disk; |
| 364 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); |
| 365 | while ((part = disk_part_iter_next(&piter))) |
| 366 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); |
| 367 | disk_part_iter_exit(&piter); |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Stop the requeueing of requests again. |
| 374 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 375 | static int dasd_state_online_to_ready(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 377 | int rc; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 378 | struct gendisk *disk; |
| 379 | struct disk_part_iter piter; |
| 380 | struct hd_struct *part; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 381 | |
| 382 | if (device->discipline->online_to_ready) { |
| 383 | rc = device->discipline->online_to_ready(device); |
| 384 | if (rc) |
| 385 | return rc; |
| 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | device->state = DASD_STATE_READY; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 388 | if (device->block) { |
| 389 | disk = device->block->bdev->bd_disk; |
| 390 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); |
| 391 | while ((part = disk_part_iter_next(&piter))) |
| 392 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); |
| 393 | disk_part_iter_exit(&piter); |
| 394 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 395 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Device startup state changes. |
| 400 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 401 | static int dasd_increase_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
| 403 | int rc; |
| 404 | |
| 405 | rc = 0; |
| 406 | if (device->state == DASD_STATE_NEW && |
| 407 | device->target >= DASD_STATE_KNOWN) |
| 408 | rc = dasd_state_new_to_known(device); |
| 409 | |
| 410 | if (!rc && |
| 411 | device->state == DASD_STATE_KNOWN && |
| 412 | device->target >= DASD_STATE_BASIC) |
| 413 | rc = dasd_state_known_to_basic(device); |
| 414 | |
| 415 | if (!rc && |
| 416 | device->state == DASD_STATE_BASIC && |
| 417 | device->target >= DASD_STATE_READY) |
| 418 | rc = dasd_state_basic_to_ready(device); |
| 419 | |
| 420 | if (!rc && |
Horst Hummel | 39ccf95 | 2006-04-27 18:40:10 -0700 | [diff] [blame] | 421 | device->state == DASD_STATE_UNFMT && |
| 422 | device->target > DASD_STATE_UNFMT) |
| 423 | rc = -EPERM; |
| 424 | |
| 425 | if (!rc && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | device->state == DASD_STATE_READY && |
| 427 | device->target >= DASD_STATE_ONLINE) |
| 428 | rc = dasd_state_ready_to_online(device); |
| 429 | |
| 430 | return rc; |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Device shutdown state changes. |
| 435 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 436 | static int dasd_decrease_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 438 | int rc; |
| 439 | |
| 440 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (device->state == DASD_STATE_ONLINE && |
| 442 | device->target <= DASD_STATE_READY) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 443 | rc = dasd_state_online_to_ready(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 444 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 445 | if (!rc && |
| 446 | device->state == DASD_STATE_READY && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | device->target <= DASD_STATE_BASIC) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 448 | rc = dasd_state_ready_to_basic(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 449 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 450 | if (!rc && |
| 451 | device->state == DASD_STATE_UNFMT && |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 452 | device->target <= DASD_STATE_BASIC) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 453 | rc = dasd_state_unfmt_to_basic(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 454 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 455 | if (!rc && |
| 456 | device->state == DASD_STATE_BASIC && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | device->target <= DASD_STATE_KNOWN) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 458 | rc = dasd_state_basic_to_known(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 459 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 460 | if (!rc && |
| 461 | device->state == DASD_STATE_KNOWN && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | device->target <= DASD_STATE_NEW) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 463 | rc = dasd_state_known_to_new(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 465 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* |
| 469 | * This is the main startup/shutdown routine. |
| 470 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 471 | static void dasd_change_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Sebastian Ott | 181d952 | 2009-06-22 12:08:21 +0200 | [diff] [blame^] | 473 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | if (device->state == device->target) |
| 476 | /* Already where we want to go today... */ |
| 477 | return; |
| 478 | if (device->state < device->target) |
| 479 | rc = dasd_increase_state(device); |
| 480 | else |
| 481 | rc = dasd_decrease_state(device); |
Sebastian Ott | 181d952 | 2009-06-22 12:08:21 +0200 | [diff] [blame^] | 482 | if (rc == -EAGAIN) |
| 483 | return; |
| 484 | if (rc) |
| 485 | device->target = device->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 487 | if (device->state == device->target) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | wake_up(&dasd_init_waitq); |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 489 | dasd_put_device(device); |
| 490 | } |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 491 | |
| 492 | /* let user-space know that the device status changed */ |
| 493 | kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /* |
| 497 | * Kick starter for devices that did not complete the startup/shutdown |
| 498 | * procedure or were sleeping because of a pending state. |
| 499 | * dasd_kick_device will schedule a call do do_kick_device to the kernel |
| 500 | * event daemon. |
| 501 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 502 | static void do_kick_device(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 504 | struct dasd_device *device = container_of(work, struct dasd_device, kick_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | dasd_change_state(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 506 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | dasd_put_device(device); |
| 508 | } |
| 509 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 510 | void dasd_kick_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
| 512 | dasd_get_device(device); |
| 513 | /* queue call to dasd_kick_device to the kernel event daemon. */ |
| 514 | schedule_work(&device->kick_work); |
| 515 | } |
| 516 | |
| 517 | /* |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 518 | * dasd_restore_device will schedule a call do do_restore_device to the kernel |
| 519 | * event daemon. |
| 520 | */ |
| 521 | static void do_restore_device(struct work_struct *work) |
| 522 | { |
| 523 | struct dasd_device *device = container_of(work, struct dasd_device, |
| 524 | restore_device); |
| 525 | device->cdev->drv->restore(device->cdev); |
| 526 | dasd_put_device(device); |
| 527 | } |
| 528 | |
| 529 | void dasd_restore_device(struct dasd_device *device) |
| 530 | { |
| 531 | dasd_get_device(device); |
| 532 | /* queue call to dasd_restore_device to the kernel event daemon. */ |
| 533 | schedule_work(&device->restore_device); |
| 534 | } |
| 535 | |
| 536 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | * Set the target state for a device and starts the state change. |
| 538 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 539 | void dasd_set_target_state(struct dasd_device *device, int target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 541 | dasd_get_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* If we are in probeonly mode stop at DASD_STATE_READY. */ |
| 543 | if (dasd_probeonly && target > DASD_STATE_READY) |
| 544 | target = DASD_STATE_READY; |
| 545 | if (device->target != target) { |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 546 | if (device->state == target) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | wake_up(&dasd_init_waitq); |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 548 | dasd_put_device(device); |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | device->target = target; |
| 551 | } |
| 552 | if (device->state != device->target) |
| 553 | dasd_change_state(device); |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Enable devices with device numbers in [from..to]. |
| 558 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 559 | static inline int _wait_for_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | return (device->state == device->target); |
| 562 | } |
| 563 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 564 | void dasd_enable_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
| 566 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 567 | if (device->state <= DASD_STATE_KNOWN) |
| 568 | /* No discipline for device found. */ |
| 569 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 570 | /* Now wait for the devices to come up. */ |
| 571 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * SECTION: device operation (interrupt handler, start i/o, term i/o ...) |
| 576 | */ |
| 577 | #ifdef CONFIG_DASD_PROFILE |
| 578 | |
| 579 | struct dasd_profile_info_t dasd_global_profile; |
| 580 | unsigned int dasd_profile_level = DASD_PROFILE_OFF; |
| 581 | |
| 582 | /* |
| 583 | * Increments counter in global and local profiling structures. |
| 584 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 585 | #define dasd_profile_counter(value, counter, block) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { \ |
| 587 | int index; \ |
| 588 | for (index = 0; index < 31 && value >> (2+index); index++); \ |
| 589 | dasd_global_profile.counter[index]++; \ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 590 | block->profile.counter[index]++; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* |
| 594 | * Add profiling information for cqr before execution. |
| 595 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 596 | static void dasd_profile_start(struct dasd_block *block, |
| 597 | struct dasd_ccw_req *cqr, |
| 598 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | struct list_head *l; |
| 601 | unsigned int counter; |
| 602 | |
| 603 | if (dasd_profile_level != DASD_PROFILE_ON) |
| 604 | return; |
| 605 | |
| 606 | /* count the length of the chanq for statistics */ |
| 607 | counter = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 608 | list_for_each(l, &block->ccw_queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (++counter >= 31) |
| 610 | break; |
| 611 | dasd_global_profile.dasd_io_nr_req[counter]++; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 612 | block->profile.dasd_io_nr_req[counter]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* |
| 616 | * Add profiling information for cqr after execution. |
| 617 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 618 | static void dasd_profile_end(struct dasd_block *block, |
| 619 | struct dasd_ccw_req *cqr, |
| 620 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
| 622 | long strtime, irqtime, endtime, tottime; /* in microseconds */ |
| 623 | long tottimeps, sectors; |
| 624 | |
| 625 | if (dasd_profile_level != DASD_PROFILE_ON) |
| 626 | return; |
| 627 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 628 | sectors = blk_rq_sectors(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (!cqr->buildclk || !cqr->startclk || |
| 630 | !cqr->stopclk || !cqr->endclk || |
| 631 | !sectors) |
| 632 | return; |
| 633 | |
| 634 | strtime = ((cqr->startclk - cqr->buildclk) >> 12); |
| 635 | irqtime = ((cqr->stopclk - cqr->startclk) >> 12); |
| 636 | endtime = ((cqr->endclk - cqr->stopclk) >> 12); |
| 637 | tottime = ((cqr->endclk - cqr->buildclk) >> 12); |
| 638 | tottimeps = tottime / sectors; |
| 639 | |
| 640 | if (!dasd_global_profile.dasd_io_reqs) |
| 641 | memset(&dasd_global_profile, 0, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 642 | sizeof(struct dasd_profile_info_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | dasd_global_profile.dasd_io_reqs++; |
| 644 | dasd_global_profile.dasd_io_sects += sectors; |
| 645 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 646 | if (!block->profile.dasd_io_reqs) |
| 647 | memset(&block->profile, 0, |
| 648 | sizeof(struct dasd_profile_info_t)); |
| 649 | block->profile.dasd_io_reqs++; |
| 650 | block->profile.dasd_io_sects += sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 652 | dasd_profile_counter(sectors, dasd_io_secs, block); |
| 653 | dasd_profile_counter(tottime, dasd_io_times, block); |
| 654 | dasd_profile_counter(tottimeps, dasd_io_timps, block); |
| 655 | dasd_profile_counter(strtime, dasd_io_time1, block); |
| 656 | dasd_profile_counter(irqtime, dasd_io_time2, block); |
| 657 | dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block); |
| 658 | dasd_profile_counter(endtime, dasd_io_time3, block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | #else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 661 | #define dasd_profile_start(block, cqr, req) do {} while (0) |
| 662 | #define dasd_profile_end(block, cqr, req) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | #endif /* CONFIG_DASD_PROFILE */ |
| 664 | |
| 665 | /* |
| 666 | * Allocate memory for a channel program with 'cplength' channel |
| 667 | * command words and 'datasize' additional space. There are two |
| 668 | * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed |
| 669 | * memory and 2) dasd_smalloc_request uses the static ccw memory |
| 670 | * that gets allocated for each device. |
| 671 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 672 | struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength, |
| 673 | int datasize, |
| 674 | struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
| 676 | struct dasd_ccw_req *cqr; |
| 677 | |
| 678 | /* Sanity checks */ |
Eric Sesterhenn | 7ac1e87 | 2006-03-24 18:48:13 +0100 | [diff] [blame] | 679 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 680 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 682 | cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (cqr == NULL) |
| 684 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | cqr->cpaddr = NULL; |
| 686 | if (cplength > 0) { |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 687 | cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | GFP_ATOMIC | GFP_DMA); |
| 689 | if (cqr->cpaddr == NULL) { |
| 690 | kfree(cqr); |
| 691 | return ERR_PTR(-ENOMEM); |
| 692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | cqr->data = NULL; |
| 695 | if (datasize > 0) { |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 696 | cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (cqr->data == NULL) { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 698 | kfree(cqr->cpaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | kfree(cqr); |
| 700 | return ERR_PTR(-ENOMEM); |
| 701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | strncpy((char *) &cqr->magic, magic, 4); |
| 704 | ASCEBC((char *) &cqr->magic, 4); |
| 705 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 706 | dasd_get_device(device); |
| 707 | return cqr; |
| 708 | } |
| 709 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 710 | struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength, |
| 711 | int datasize, |
| 712 | struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | { |
| 714 | unsigned long flags; |
| 715 | struct dasd_ccw_req *cqr; |
| 716 | char *data; |
| 717 | int size; |
| 718 | |
| 719 | /* Sanity checks */ |
Eric Sesterhenn | 7ac1e87 | 2006-03-24 18:48:13 +0100 | [diff] [blame] | 720 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 721 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; |
| 724 | if (cplength > 0) |
| 725 | size += cplength * sizeof(struct ccw1); |
| 726 | if (datasize > 0) |
| 727 | size += datasize; |
| 728 | spin_lock_irqsave(&device->mem_lock, flags); |
| 729 | cqr = (struct dasd_ccw_req *) |
| 730 | dasd_alloc_chunk(&device->ccw_chunks, size); |
| 731 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 732 | if (cqr == NULL) |
| 733 | return ERR_PTR(-ENOMEM); |
| 734 | memset(cqr, 0, sizeof(struct dasd_ccw_req)); |
| 735 | data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); |
| 736 | cqr->cpaddr = NULL; |
| 737 | if (cplength > 0) { |
| 738 | cqr->cpaddr = (struct ccw1 *) data; |
| 739 | data += cplength*sizeof(struct ccw1); |
| 740 | memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); |
| 741 | } |
| 742 | cqr->data = NULL; |
| 743 | if (datasize > 0) { |
| 744 | cqr->data = data; |
| 745 | memset(cqr->data, 0, datasize); |
| 746 | } |
| 747 | strncpy((char *) &cqr->magic, magic, 4); |
| 748 | ASCEBC((char *) &cqr->magic, 4); |
| 749 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 750 | dasd_get_device(device); |
| 751 | return cqr; |
| 752 | } |
| 753 | |
| 754 | /* |
| 755 | * Free memory of a channel program. This function needs to free all the |
| 756 | * idal lists that might have been created by dasd_set_cda and the |
| 757 | * struct dasd_ccw_req itself. |
| 758 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 759 | void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 761 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | struct ccw1 *ccw; |
| 763 | |
| 764 | /* Clear any idals used for the request. */ |
| 765 | ccw = cqr->cpaddr; |
| 766 | do { |
| 767 | clear_normalized_cda(ccw); |
| 768 | } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC)); |
| 769 | #endif |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 770 | kfree(cqr->cpaddr); |
| 771 | kfree(cqr->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | kfree(cqr); |
| 773 | dasd_put_device(device); |
| 774 | } |
| 775 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 776 | void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
| 778 | unsigned long flags; |
| 779 | |
| 780 | spin_lock_irqsave(&device->mem_lock, flags); |
| 781 | dasd_free_chunk(&device->ccw_chunks, cqr); |
| 782 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 783 | dasd_put_device(device); |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | * Check discipline magic in cqr. |
| 788 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 789 | static inline int dasd_check_cqr(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { |
| 791 | struct dasd_device *device; |
| 792 | |
| 793 | if (cqr == NULL) |
| 794 | return -EINVAL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 795 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 797 | DBF_DEV_EVENT(DBF_WARNING, device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | " dasd_ccw_req 0x%08x magic doesn't match" |
| 799 | " discipline 0x%08x", |
| 800 | cqr->magic, |
| 801 | *(unsigned int *) device->discipline->name); |
| 802 | return -EINVAL; |
| 803 | } |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Terminate the current i/o and set the request to clear_pending. |
| 809 | * Timer keeps device runnig. |
| 810 | * ccw_device_clear can fail if the i/o subsystem |
| 811 | * is in a bad mood. |
| 812 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 813 | int dasd_term_IO(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | struct dasd_device *device; |
| 816 | int retries, rc; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 817 | char errorstring[ERRORLENGTH]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | /* Check the cqr */ |
| 820 | rc = dasd_check_cqr(cqr); |
| 821 | if (rc) |
| 822 | return rc; |
| 823 | retries = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 824 | device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) { |
| 826 | rc = ccw_device_clear(device->cdev, (long) cqr); |
| 827 | switch (rc) { |
| 828 | case 0: /* termination successful */ |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 829 | cqr->retries--; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 830 | cqr->status = DASD_CQR_CLEAR_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | cqr->stopclk = get_clock(); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 832 | cqr->starttime = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 834 | "terminate cqr %p successful", |
| 835 | cqr); |
| 836 | break; |
| 837 | case -ENODEV: |
| 838 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 839 | "device gone, retry"); |
| 840 | break; |
| 841 | case -EIO: |
| 842 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 843 | "I/O error, retry"); |
| 844 | break; |
| 845 | case -EINVAL: |
| 846 | case -EBUSY: |
| 847 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 848 | "device busy, retry later"); |
| 849 | break; |
| 850 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 851 | /* internal error 10 - unknown rc*/ |
| 852 | snprintf(errorstring, ERRORLENGTH, "10 %d", rc); |
| 853 | dev_err(&device->cdev->dev, "An error occurred in the " |
| 854 | "DASD device driver, reason=%s\n", errorstring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | BUG(); |
| 856 | break; |
| 857 | } |
| 858 | retries++; |
| 859 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 860 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | return rc; |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * Start the i/o. This start_IO can fail if the channel is really busy. |
| 866 | * In that case set up a timer to start the request later. |
| 867 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 868 | int dasd_start_IO(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | struct dasd_device *device; |
| 871 | int rc; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 872 | char errorstring[ERRORLENGTH]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | /* Check the cqr */ |
| 875 | rc = dasd_check_cqr(cqr); |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 876 | if (rc) { |
| 877 | cqr->intrc = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | return rc; |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 879 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 880 | device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | if (cqr->retries < 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 882 | /* internal error 14 - start_IO run out of retries */ |
| 883 | sprintf(errorstring, "14 %p", cqr); |
| 884 | dev_err(&device->cdev->dev, "An error occurred in the DASD " |
| 885 | "device driver, reason=%s\n", errorstring); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 886 | cqr->status = DASD_CQR_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return -EIO; |
| 888 | } |
| 889 | cqr->startclk = get_clock(); |
| 890 | cqr->starttime = jiffies; |
| 891 | cqr->retries--; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 892 | if (cqr->cpmode == 1) { |
| 893 | rc = ccw_device_tm_start(device->cdev, cqr->cpaddr, |
| 894 | (long) cqr, cqr->lpm); |
| 895 | } else { |
| 896 | rc = ccw_device_start(device->cdev, cqr->cpaddr, |
| 897 | (long) cqr, cqr->lpm, 0); |
| 898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | switch (rc) { |
| 900 | case 0: |
| 901 | cqr->status = DASD_CQR_IN_IO; |
| 902 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 903 | "start_IO: request %p started successful", |
| 904 | cqr); |
| 905 | break; |
| 906 | case -EBUSY: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 907 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | "start_IO: device busy, retry later"); |
| 909 | break; |
| 910 | case -ETIMEDOUT: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 911 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | "start_IO: request timeout, retry later"); |
| 913 | break; |
| 914 | case -EACCES: |
| 915 | /* -EACCES indicates that the request used only a |
| 916 | * subset of the available pathes and all these |
| 917 | * pathes are gone. |
| 918 | * Do a retry with all available pathes. |
| 919 | */ |
| 920 | cqr->lpm = LPM_ANYPATH; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 921 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | "start_IO: selected pathes gone," |
| 923 | " retry on all pathes"); |
| 924 | break; |
| 925 | case -ENODEV: |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 926 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
| 927 | "start_IO: -ENODEV device gone, retry"); |
| 928 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | case -EIO: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 930 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 931 | "start_IO: -EIO device gone, retry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | break; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 933 | case -EINVAL: |
| 934 | /* most likely caused in power management context */ |
| 935 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
| 936 | "start_IO: -EINVAL device currently " |
| 937 | "not accessible"); |
| 938 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 940 | /* internal error 11 - unknown rc */ |
| 941 | snprintf(errorstring, ERRORLENGTH, "11 %d", rc); |
| 942 | dev_err(&device->cdev->dev, |
| 943 | "An error occurred in the DASD device driver, " |
| 944 | "reason=%s\n", errorstring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | BUG(); |
| 946 | break; |
| 947 | } |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 948 | cqr->intrc = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return rc; |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | * Timeout function for dasd devices. This is used for different purposes |
| 954 | * 1) missing interrupt handler for normal operation |
| 955 | * 2) delayed start of request where start_IO failed with -EBUSY |
| 956 | * 3) timeout for missing state change interrupts |
| 957 | * The head of the ccw queue will have status DASD_CQR_IN_IO for 1), |
| 958 | * DASD_CQR_QUEUED for 2) and 3). |
| 959 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 960 | static void dasd_device_timeout(unsigned long ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
| 962 | unsigned long flags; |
| 963 | struct dasd_device *device; |
| 964 | |
| 965 | device = (struct dasd_device *) ptr; |
| 966 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 967 | /* re-activate request queue */ |
| 968 | device->stopped &= ~DASD_STOPPED_PENDING; |
| 969 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 970 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* |
| 974 | * Setup timeout for a device in jiffies. |
| 975 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 976 | void dasd_device_set_timer(struct dasd_device *device, int expires) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 978 | if (expires == 0) |
| 979 | del_timer(&device->timer); |
| 980 | else |
| 981 | mod_timer(&device->timer, jiffies + expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /* |
| 985 | * Clear timeout for a device. |
| 986 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 987 | void dasd_device_clear_timer(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 989 | del_timer(&device->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 992 | static void dasd_handle_killed_request(struct ccw_device *cdev, |
| 993 | unsigned long intparm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
| 995 | struct dasd_ccw_req *cqr; |
| 996 | struct dasd_device *device; |
| 997 | |
Stefan Weinhuber | f16f584 | 2008-05-15 16:52:36 +0200 | [diff] [blame] | 998 | if (!intparm) |
| 999 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | cqr = (struct dasd_ccw_req *) intparm; |
| 1001 | if (cqr->status != DASD_CQR_IN_IO) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1002 | DBF_EVENT(DBF_DEBUG, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | "invalid status in handle_killed_request: " |
| 1004 | "bus_id %s, status %02x", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1005 | dev_name(&cdev->dev), cqr->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | return; |
| 1007 | } |
| 1008 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1009 | device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | if (device == NULL || |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 1011 | device != dasd_device_from_cdev_locked(cdev) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1013 | DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: " |
| 1014 | "bus_id %s", dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | /* Schedule request to be retried. */ |
| 1019 | cqr->status = DASD_CQR_QUEUED; |
| 1020 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1021 | dasd_device_clear_timer(device); |
| 1022 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | dasd_put_device(device); |
| 1024 | } |
| 1025 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1026 | void dasd_generic_handle_state_change(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1028 | /* First of all start sense subsystem status request. */ |
| 1029 | dasd_eer_snss(device); |
| 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | device->stopped &= ~DASD_STOPPED_PENDING; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1032 | dasd_schedule_device_bh(device); |
| 1033 | if (device->block) |
| 1034 | dasd_schedule_block_bh(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /* |
| 1038 | * Interrupt handler for "normal" ssch-io based dasd devices. |
| 1039 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1040 | void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm, |
| 1041 | struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
| 1043 | struct dasd_ccw_req *cqr, *next; |
| 1044 | struct dasd_device *device; |
| 1045 | unsigned long long now; |
| 1046 | int expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | if (IS_ERR(irb)) { |
| 1049 | switch (PTR_ERR(irb)) { |
| 1050 | case -EIO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | break; |
| 1052 | case -ETIMEDOUT: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1053 | DBF_EVENT(DBF_WARNING, "%s(%s): request timed out\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1054 | __func__, dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | break; |
| 1056 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1057 | DBF_EVENT(DBF_WARNING, "%s(%s): unknown error %ld\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1058 | __func__, dev_name(&cdev->dev), PTR_ERR(irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
Stefan Weinhuber | f16f584 | 2008-05-15 16:52:36 +0200 | [diff] [blame] | 1060 | dasd_handle_killed_request(cdev, intparm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | now = get_clock(); |
| 1065 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1066 | /* check for unsolicited interrupts */ |
| 1067 | cqr = (struct dasd_ccw_req *) intparm; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1068 | if (!cqr || ((scsw_cc(&irb->scsw) == 1) && |
| 1069 | (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) && |
| 1070 | (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1071 | if (cqr && cqr->status == DASD_CQR_IN_IO) |
| 1072 | cqr->status = DASD_CQR_QUEUED; |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 1073 | device = dasd_device_from_cdev_locked(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | if (!IS_ERR(device)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1075 | dasd_device_clear_timer(device); |
| 1076 | device->discipline->handle_unsolicited_interrupt(device, |
| 1077 | irb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | dasd_put_device(device); |
| 1079 | } |
| 1080 | return; |
| 1081 | } |
| 1082 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1083 | device = (struct dasd_device *) cqr->startdev; |
| 1084 | if (!device || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1086 | DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: " |
| 1087 | "bus_id %s", dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | /* Check for clear pending */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1092 | if (cqr->status == DASD_CQR_CLEAR_PENDING && |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1093 | scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1094 | cqr->status = DASD_CQR_CLEARED; |
| 1095 | dasd_device_clear_timer(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1096 | wake_up(&dasd_flush_wq); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1097 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | return; |
| 1099 | } |
| 1100 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1101 | /* check status - the request might have been killed by dyn detach */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | if (cqr->status != DASD_CQR_IN_IO) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1103 | DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, " |
| 1104 | "status %02x", dev_name(&cdev->dev), cqr->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return; |
| 1106 | } |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1107 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1108 | next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | expires = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1110 | if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && |
| 1111 | scsw_cstat(&irb->scsw) == 0) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1112 | /* request was completed successfully */ |
| 1113 | cqr->status = DASD_CQR_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | cqr->stopclk = now; |
| 1115 | /* Start first request on queue if possible -> fast_io. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1116 | if (cqr->devlist.next != &device->ccw_queue) { |
| 1117 | next = list_entry(cqr->devlist.next, |
| 1118 | struct dasd_ccw_req, devlist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1120 | } else { /* error */ |
| 1121 | memcpy(&cqr->irb, irb, sizeof(struct irb)); |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1122 | /* log sense for every failed I/O to s390 debugfeature */ |
| 1123 | dasd_log_sense_dbf(cqr, irb); |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 1124 | if (device->features & DASD_FEATURE_ERPLOG) { |
Horst Hummel | 9575bf2 | 2006-12-08 15:54:15 +0100 | [diff] [blame] | 1125 | dasd_log_sense(cqr, irb); |
| 1126 | } |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1127 | |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 1128 | /* |
| 1129 | * If we don't want complex ERP for this request, then just |
| 1130 | * reset this and retry it in the fastpath |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1131 | */ |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 1132 | if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) && |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1133 | cqr->retries > 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1134 | if (cqr->lpm == LPM_ANYPATH) |
| 1135 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 1136 | "default ERP in fastpath " |
| 1137 | "(%i retries left)", |
| 1138 | cqr->retries); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1139 | cqr->lpm = LPM_ANYPATH; |
| 1140 | cqr->status = DASD_CQR_QUEUED; |
| 1141 | next = cqr; |
| 1142 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | cqr->status = DASD_CQR_ERROR; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1144 | } |
| 1145 | if (next && (next->status == DASD_CQR_QUEUED) && |
| 1146 | (!device->stopped)) { |
| 1147 | if (device->discipline->start_IO(next) == 0) |
| 1148 | expires = next->expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | } |
| 1150 | if (expires != 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1151 | dasd_device_set_timer(device, expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1153 | dasd_device_clear_timer(device); |
| 1154 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1158 | * If we have an error on a dasd_block layer request then we cancel |
| 1159 | * and return all further requests from the same dasd_block as well. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1161 | static void __dasd_device_recovery(struct dasd_device *device, |
| 1162 | struct dasd_ccw_req *ref_cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | { |
| 1164 | struct list_head *l, *n; |
| 1165 | struct dasd_ccw_req *cqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
| 1167 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1168 | * only requeue request that came from the dasd_block layer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1170 | if (!ref_cqr->block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | return; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1172 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1173 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1174 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1175 | if (cqr->status == DASD_CQR_QUEUED && |
| 1176 | ref_cqr->block == cqr->block) { |
| 1177 | cqr->status = DASD_CQR_CLEARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1179 | } |
| 1180 | }; |
| 1181 | |
| 1182 | /* |
| 1183 | * Remove those ccw requests from the queue that need to be returned |
| 1184 | * to the upper layer. |
| 1185 | */ |
| 1186 | static void __dasd_device_process_ccw_queue(struct dasd_device *device, |
| 1187 | struct list_head *final_queue) |
| 1188 | { |
| 1189 | struct list_head *l, *n; |
| 1190 | struct dasd_ccw_req *cqr; |
| 1191 | |
| 1192 | /* Process request with final status. */ |
| 1193 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1194 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1195 | |
| 1196 | /* Stop list processing at the first non-final request. */ |
| 1197 | if (cqr->status == DASD_CQR_QUEUED || |
| 1198 | cqr->status == DASD_CQR_IN_IO || |
| 1199 | cqr->status == DASD_CQR_CLEAR_PENDING) |
| 1200 | break; |
| 1201 | if (cqr->status == DASD_CQR_ERROR) { |
| 1202 | __dasd_device_recovery(device, cqr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1204 | /* Rechain finished requests to final queue */ |
| 1205 | list_move_tail(&cqr->devlist, final_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1210 | * the cqrs from the final queue are returned to the upper layer |
| 1211 | * by setting a dasd_block state and calling the callback function |
| 1212 | */ |
| 1213 | static void __dasd_device_process_final_queue(struct dasd_device *device, |
| 1214 | struct list_head *final_queue) |
| 1215 | { |
| 1216 | struct list_head *l, *n; |
| 1217 | struct dasd_ccw_req *cqr; |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1218 | struct dasd_block *block; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1219 | void (*callback)(struct dasd_ccw_req *, void *data); |
| 1220 | void *callback_data; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1221 | char errorstring[ERRORLENGTH]; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1222 | |
| 1223 | list_for_each_safe(l, n, final_queue) { |
| 1224 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1225 | list_del_init(&cqr->devlist); |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1226 | block = cqr->block; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1227 | callback = cqr->callback; |
| 1228 | callback_data = cqr->callback_data; |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1229 | if (block) |
| 1230 | spin_lock_bh(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1231 | switch (cqr->status) { |
| 1232 | case DASD_CQR_SUCCESS: |
| 1233 | cqr->status = DASD_CQR_DONE; |
| 1234 | break; |
| 1235 | case DASD_CQR_ERROR: |
| 1236 | cqr->status = DASD_CQR_NEED_ERP; |
| 1237 | break; |
| 1238 | case DASD_CQR_CLEARED: |
| 1239 | cqr->status = DASD_CQR_TERMINATED; |
| 1240 | break; |
| 1241 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1242 | /* internal error 12 - wrong cqr status*/ |
| 1243 | snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status); |
| 1244 | dev_err(&device->cdev->dev, |
| 1245 | "An error occurred in the DASD device driver, " |
| 1246 | "reason=%s\n", errorstring); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1247 | BUG(); |
| 1248 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1249 | if (cqr->callback != NULL) |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1250 | (callback)(cqr, callback_data); |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1251 | if (block) |
| 1252 | spin_unlock_bh(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1256 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | * Take a look at the first request on the ccw queue and check |
| 1258 | * if it reached its expire time. If so, terminate the IO. |
| 1259 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1260 | static void __dasd_device_check_expire(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | { |
| 1262 | struct dasd_ccw_req *cqr; |
| 1263 | |
| 1264 | if (list_empty(&device->ccw_queue)) |
| 1265 | return; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1266 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Horst Hummel | 29145a6 | 2006-12-04 15:40:15 +0100 | [diff] [blame] | 1267 | if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) && |
| 1268 | (time_after_eq(jiffies, cqr->expires + cqr->starttime))) { |
| 1269 | if (device->discipline->term_IO(cqr) != 0) { |
| 1270 | /* Hmpf, try again in 5 sec */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1271 | dev_err(&device->cdev->dev, |
| 1272 | "cqr %p timed out (%is) but cannot be " |
| 1273 | "ended, retrying in 5 s\n", |
| 1274 | cqr, (cqr->expires/HZ)); |
Stefan Haberland | 7dc1da9 | 2008-01-26 14:11:26 +0100 | [diff] [blame] | 1275 | cqr->expires += 5*HZ; |
| 1276 | dasd_device_set_timer(device, 5*HZ); |
Horst Hummel | 29145a6 | 2006-12-04 15:40:15 +0100 | [diff] [blame] | 1277 | } else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1278 | dev_err(&device->cdev->dev, |
| 1279 | "cqr %p timed out (%is), %i retries " |
| 1280 | "remaining\n", cqr, (cqr->expires/HZ), |
| 1281 | cqr->retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * Take a look at the first request on the ccw queue and check |
| 1288 | * if it needs to be started. |
| 1289 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1290 | static void __dasd_device_start_head(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
| 1292 | struct dasd_ccw_req *cqr; |
| 1293 | int rc; |
| 1294 | |
| 1295 | if (list_empty(&device->ccw_queue)) |
| 1296 | return; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1297 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 1298 | if (cqr->status != DASD_CQR_QUEUED) |
| 1299 | return; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1300 | /* when device is stopped, return request to previous layer */ |
| 1301 | if (device->stopped) { |
| 1302 | cqr->status = DASD_CQR_CLEARED; |
| 1303 | dasd_schedule_device_bh(device); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 1304 | return; |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1305 | } |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 1306 | |
| 1307 | rc = device->discipline->start_IO(cqr); |
| 1308 | if (rc == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1309 | dasd_device_set_timer(device, cqr->expires); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 1310 | else if (rc == -EACCES) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1311 | dasd_schedule_device_bh(device); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 1312 | } else |
| 1313 | /* Hmpf, try again in 1/2 sec */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1314 | dasd_device_set_timer(device, 50); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1318 | * Go through all request on the dasd_device request queue, |
| 1319 | * terminate them on the cdev if necessary, and return them to the |
| 1320 | * submitting layer via callback. |
| 1321 | * Note: |
| 1322 | * Make sure that all 'submitting layers' still exist when |
| 1323 | * this function is called!. In other words, when 'device' is a base |
| 1324 | * device then all block layer requests must have been removed before |
| 1325 | * via dasd_flush_block_queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1327 | int dasd_flush_device_queue(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1329 | struct dasd_ccw_req *cqr, *n; |
| 1330 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | struct list_head flush_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
| 1333 | INIT_LIST_HEAD(&flush_queue); |
| 1334 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1335 | rc = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1336 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1337 | /* Check status and move request to flush_queue */ |
| 1338 | switch (cqr->status) { |
| 1339 | case DASD_CQR_IN_IO: |
| 1340 | rc = device->discipline->term_IO(cqr); |
| 1341 | if (rc) { |
| 1342 | /* unable to terminate requeust */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1343 | dev_err(&device->cdev->dev, |
| 1344 | "Flushing the DASD request queue " |
| 1345 | "failed for request %p\n", cqr); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1346 | /* stop flush processing */ |
| 1347 | goto finished; |
| 1348 | } |
| 1349 | break; |
| 1350 | case DASD_CQR_QUEUED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | cqr->stopclk = get_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1352 | cqr->status = DASD_CQR_CLEARED; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1353 | break; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1354 | default: /* no need to modify the others */ |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1355 | break; |
| 1356 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1357 | list_move_tail(&cqr->devlist, &flush_queue); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1358 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1359 | finished: |
| 1360 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1361 | /* |
| 1362 | * After this point all requests must be in state CLEAR_PENDING, |
| 1363 | * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become |
| 1364 | * one of the others. |
| 1365 | */ |
| 1366 | list_for_each_entry_safe(cqr, n, &flush_queue, devlist) |
| 1367 | wait_event(dasd_flush_wq, |
| 1368 | (cqr->status != DASD_CQR_CLEAR_PENDING)); |
| 1369 | /* |
| 1370 | * Now set each request back to TERMINATED, DONE or NEED_ERP |
| 1371 | * and call the callback function of flushed requests |
| 1372 | */ |
| 1373 | __dasd_device_process_final_queue(device, &flush_queue); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1374 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /* |
| 1378 | * Acquire the device lock and process queues for the device. |
| 1379 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1380 | static void dasd_device_tasklet(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | { |
| 1382 | struct list_head final_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | atomic_set (&device->tasklet_scheduled, 0); |
| 1385 | INIT_LIST_HEAD(&final_queue); |
| 1386 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1387 | /* Check expire time of first request on the ccw queue. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1388 | __dasd_device_check_expire(device); |
| 1389 | /* find final requests on ccw queue */ |
| 1390 | __dasd_device_process_ccw_queue(device, &final_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1392 | /* Now call the callback function of requests with final status */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1393 | __dasd_device_process_final_queue(device, &final_queue); |
| 1394 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | /* Now check if the head of the ccw queue needs to be started. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1396 | __dasd_device_start_head(device); |
| 1397 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | dasd_put_device(device); |
| 1399 | } |
| 1400 | |
| 1401 | /* |
| 1402 | * Schedules a call to dasd_tasklet over the device tasklet. |
| 1403 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1404 | void dasd_schedule_device_bh(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | { |
| 1406 | /* Protect against rescheduling. */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1407 | if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | return; |
| 1409 | dasd_get_device(device); |
| 1410 | tasklet_hi_schedule(&device->tasklet); |
| 1411 | } |
| 1412 | |
| 1413 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1414 | * Queue a request to the head of the device ccw_queue. |
| 1415 | * Start the I/O if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1417 | void dasd_add_request_head(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | { |
| 1419 | struct dasd_device *device; |
| 1420 | unsigned long flags; |
| 1421 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1422 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1424 | cqr->status = DASD_CQR_QUEUED; |
| 1425 | list_add(&cqr->devlist, &device->ccw_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1427 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 1429 | } |
| 1430 | |
| 1431 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1432 | * Queue a request to the tail of the device ccw_queue. |
| 1433 | * Start the I/O if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1435 | void dasd_add_request_tail(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | { |
| 1437 | struct dasd_device *device; |
| 1438 | unsigned long flags; |
| 1439 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1440 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1442 | cqr->status = DASD_CQR_QUEUED; |
| 1443 | list_add_tail(&cqr->devlist, &device->ccw_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1445 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 1447 | } |
| 1448 | |
| 1449 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1450 | * Wakeup helper for the 'sleep_on' functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1452 | static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
| 1454 | wake_up((wait_queue_head_t *) data); |
| 1455 | } |
| 1456 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1457 | static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
| 1459 | struct dasd_device *device; |
| 1460 | int rc; |
| 1461 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1462 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1464 | rc = ((cqr->status == DASD_CQR_DONE || |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1465 | cqr->status == DASD_CQR_NEED_ERP || |
| 1466 | cqr->status == DASD_CQR_TERMINATED) && |
| 1467 | list_empty(&cqr->devlist)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1469 | return rc; |
| 1470 | } |
| 1471 | |
| 1472 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1473 | * Queue a request to the tail of the device ccw_queue and wait for |
| 1474 | * it's completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1476 | int dasd_sleep_on(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | struct dasd_device *device; |
| 1479 | int rc; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1480 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1481 | device = cqr->startdev; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | cqr->callback = dasd_wakeup_cb; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1484 | cqr->callback_data = (void *) &generic_waitq; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1485 | dasd_add_request_tail(cqr); |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1486 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1487 | |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1488 | if (cqr->status == DASD_CQR_DONE) |
| 1489 | rc = 0; |
| 1490 | else if (cqr->intrc) |
| 1491 | rc = cqr->intrc; |
| 1492 | else |
| 1493 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | return rc; |
| 1495 | } |
| 1496 | |
| 1497 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1498 | * Queue a request to the tail of the device ccw_queue and wait |
| 1499 | * interruptible for it's completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1501 | int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1504 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1506 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | cqr->callback = dasd_wakeup_cb; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1508 | cqr->callback_data = (void *) &generic_waitq; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1509 | dasd_add_request_tail(cqr); |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1510 | rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1511 | if (rc == -ERESTARTSYS) { |
| 1512 | dasd_cancel_req(cqr); |
| 1513 | /* wait (non-interruptible) for final status */ |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1514 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1515 | cqr->intrc = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1517 | |
| 1518 | if (cqr->status == DASD_CQR_DONE) |
| 1519 | rc = 0; |
| 1520 | else if (cqr->intrc) |
| 1521 | rc = cqr->intrc; |
| 1522 | else |
| 1523 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | return rc; |
| 1525 | } |
| 1526 | |
| 1527 | /* |
| 1528 | * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock |
| 1529 | * for eckd devices) the currently running request has to be terminated |
| 1530 | * and be put back to status queued, before the special request is added |
| 1531 | * to the head of the queue. Then the special request is waited on normally. |
| 1532 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1533 | static inline int _dasd_term_running_cqr(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | { |
| 1535 | struct dasd_ccw_req *cqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
| 1537 | if (list_empty(&device->ccw_queue)) |
| 1538 | return 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1539 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1540 | return device->discipline->term_IO(cqr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1543 | int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | struct dasd_device *device; |
| 1546 | int rc; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1547 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1548 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1550 | rc = _dasd_term_running_cqr(device); |
| 1551 | if (rc) { |
| 1552 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1553 | return rc; |
| 1554 | } |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | cqr->callback = dasd_wakeup_cb; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1557 | cqr->callback_data = (void *) &generic_waitq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | cqr->status = DASD_CQR_QUEUED; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1559 | list_add(&cqr->devlist, &device->ccw_queue); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1562 | dasd_schedule_device_bh(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1565 | |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 1566 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 1567 | |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1568 | if (cqr->status == DASD_CQR_DONE) |
| 1569 | rc = 0; |
| 1570 | else if (cqr->intrc) |
| 1571 | rc = cqr->intrc; |
| 1572 | else |
| 1573 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | return rc; |
| 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * Cancels a request that was started with dasd_sleep_on_req. |
| 1579 | * This is useful to timeout requests. The request will be |
| 1580 | * terminated if it is currently in i/o. |
| 1581 | * Returns 1 if the request has been terminated. |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1582 | * 0 if there was no need to terminate the request (not started yet) |
| 1583 | * negative error code if termination failed |
| 1584 | * Cancellation of a request is an asynchronous operation! The calling |
| 1585 | * function has to wait until the request is properly returned via callback. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1587 | int dasd_cancel_req(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1589 | struct dasd_device *device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | unsigned long flags; |
| 1591 | int rc; |
| 1592 | |
| 1593 | rc = 0; |
| 1594 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1595 | switch (cqr->status) { |
| 1596 | case DASD_CQR_QUEUED: |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1597 | /* request was not started - just set to cleared */ |
| 1598 | cqr->status = DASD_CQR_CLEARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | break; |
| 1600 | case DASD_CQR_IN_IO: |
| 1601 | /* request in IO - terminate IO and release again */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1602 | rc = device->discipline->term_IO(cqr); |
| 1603 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1604 | dev_err(&device->cdev->dev, |
| 1605 | "Cancelling request %p failed with rc=%d\n", |
| 1606 | cqr, rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1607 | } else { |
| 1608 | cqr->stopclk = get_clock(); |
| 1609 | rc = 1; |
| 1610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | break; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1612 | default: /* already finished or clear pending - do nothing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | } |
| 1615 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1616 | dasd_schedule_device_bh(device); |
| 1617 | return rc; |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | /* |
| 1622 | * SECTION: Operations of the dasd_block layer. |
| 1623 | */ |
| 1624 | |
| 1625 | /* |
| 1626 | * Timeout function for dasd_block. This is used when the block layer |
| 1627 | * is waiting for something that may not come reliably, (e.g. a state |
| 1628 | * change interrupt) |
| 1629 | */ |
| 1630 | static void dasd_block_timeout(unsigned long ptr) |
| 1631 | { |
| 1632 | unsigned long flags; |
| 1633 | struct dasd_block *block; |
| 1634 | |
| 1635 | block = (struct dasd_block *) ptr; |
| 1636 | spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags); |
| 1637 | /* re-activate request queue */ |
| 1638 | block->base->stopped &= ~DASD_STOPPED_PENDING; |
| 1639 | spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags); |
| 1640 | dasd_schedule_block_bh(block); |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * Setup timeout for a dasd_block in jiffies. |
| 1645 | */ |
| 1646 | void dasd_block_set_timer(struct dasd_block *block, int expires) |
| 1647 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 1648 | if (expires == 0) |
| 1649 | del_timer(&block->timer); |
| 1650 | else |
| 1651 | mod_timer(&block->timer, jiffies + expires); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /* |
| 1655 | * Clear timeout for a dasd_block. |
| 1656 | */ |
| 1657 | void dasd_block_clear_timer(struct dasd_block *block) |
| 1658 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 1659 | del_timer(&block->timer); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1663 | * Process finished error recovery ccw. |
| 1664 | */ |
| 1665 | static inline void __dasd_block_process_erp(struct dasd_block *block, |
| 1666 | struct dasd_ccw_req *cqr) |
| 1667 | { |
| 1668 | dasd_erp_fn_t erp_fn; |
| 1669 | struct dasd_device *device = block->base; |
| 1670 | |
| 1671 | if (cqr->status == DASD_CQR_DONE) |
| 1672 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful"); |
| 1673 | else |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1674 | dev_err(&device->cdev->dev, "ERP failed for the DASD\n"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1675 | erp_fn = device->discipline->erp_postaction(cqr); |
| 1676 | erp_fn(cqr); |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Fetch requests from the block device queue. |
| 1681 | */ |
| 1682 | static void __dasd_process_request_queue(struct dasd_block *block) |
| 1683 | { |
| 1684 | struct request_queue *queue; |
| 1685 | struct request *req; |
| 1686 | struct dasd_ccw_req *cqr; |
| 1687 | struct dasd_device *basedev; |
| 1688 | unsigned long flags; |
| 1689 | queue = block->request_queue; |
| 1690 | basedev = block->base; |
| 1691 | /* No queue ? Then there is nothing to do. */ |
| 1692 | if (queue == NULL) |
| 1693 | return; |
| 1694 | |
| 1695 | /* |
| 1696 | * We requeue request from the block device queue to the ccw |
| 1697 | * queue only in two states. In state DASD_STATE_READY the |
| 1698 | * partition detection is done and we need to requeue requests |
| 1699 | * for that. State DASD_STATE_ONLINE is normal block device |
| 1700 | * operation. |
| 1701 | */ |
| 1702 | if (basedev->state < DASD_STATE_READY) |
| 1703 | return; |
| 1704 | /* Now we try to fetch requests from the request queue */ |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1705 | while (!blk_queue_plugged(queue) && (req = blk_peek_request(queue))) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1706 | if (basedev->features & DASD_FEATURE_READONLY && |
| 1707 | rq_data_dir(req) == WRITE) { |
| 1708 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 1709 | "Rejecting write request %p", |
| 1710 | req); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1711 | blk_start_request(req); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 1712 | __blk_end_request_all(req, -EIO); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1713 | continue; |
| 1714 | } |
| 1715 | cqr = basedev->discipline->build_cp(basedev, block, req); |
| 1716 | if (IS_ERR(cqr)) { |
| 1717 | if (PTR_ERR(cqr) == -EBUSY) |
| 1718 | break; /* normal end condition */ |
| 1719 | if (PTR_ERR(cqr) == -ENOMEM) |
| 1720 | break; /* terminate request queue loop */ |
| 1721 | if (PTR_ERR(cqr) == -EAGAIN) { |
| 1722 | /* |
| 1723 | * The current request cannot be build right |
| 1724 | * now, we have to try later. If this request |
| 1725 | * is the head-of-queue we stop the device |
| 1726 | * for 1/2 second. |
| 1727 | */ |
| 1728 | if (!list_empty(&block->ccw_queue)) |
| 1729 | break; |
| 1730 | spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags); |
| 1731 | basedev->stopped |= DASD_STOPPED_PENDING; |
| 1732 | spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags); |
| 1733 | dasd_block_set_timer(block, HZ/2); |
| 1734 | break; |
| 1735 | } |
| 1736 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 1737 | "CCW creation failed (rc=%ld) " |
| 1738 | "on request %p", |
| 1739 | PTR_ERR(cqr), req); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1740 | blk_start_request(req); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 1741 | __blk_end_request_all(req, -EIO); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1742 | continue; |
| 1743 | } |
| 1744 | /* |
| 1745 | * Note: callback is set to dasd_return_cqr_cb in |
| 1746 | * __dasd_block_start_head to cover erp requests as well |
| 1747 | */ |
| 1748 | cqr->callback_data = (void *) req; |
| 1749 | cqr->status = DASD_CQR_FILLED; |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1750 | blk_start_request(req); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1751 | list_add_tail(&cqr->blocklist, &block->ccw_queue); |
| 1752 | dasd_profile_start(block, cqr, req); |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr) |
| 1757 | { |
| 1758 | struct request *req; |
| 1759 | int status; |
Kiyoshi Ueda | 4c4e214 | 2008-01-28 10:29:42 +0100 | [diff] [blame] | 1760 | int error = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1761 | |
| 1762 | req = (struct request *) cqr->callback_data; |
| 1763 | dasd_profile_end(cqr->block, cqr, req); |
Stefan Weinhuber | fe6b8e7 | 2008-02-05 16:50:47 +0100 | [diff] [blame] | 1764 | status = cqr->block->base->discipline->free_cp(cqr, req); |
Kiyoshi Ueda | 4c4e214 | 2008-01-28 10:29:42 +0100 | [diff] [blame] | 1765 | if (status <= 0) |
| 1766 | error = status ? status : -EIO; |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 1767 | __blk_end_request_all(req, error); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | /* |
| 1771 | * Process ccw request queue. |
| 1772 | */ |
| 1773 | static void __dasd_process_block_ccw_queue(struct dasd_block *block, |
| 1774 | struct list_head *final_queue) |
| 1775 | { |
| 1776 | struct list_head *l, *n; |
| 1777 | struct dasd_ccw_req *cqr; |
| 1778 | dasd_erp_fn_t erp_fn; |
| 1779 | unsigned long flags; |
| 1780 | struct dasd_device *base = block->base; |
| 1781 | |
| 1782 | restart: |
| 1783 | /* Process request with final status. */ |
| 1784 | list_for_each_safe(l, n, &block->ccw_queue) { |
| 1785 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); |
| 1786 | if (cqr->status != DASD_CQR_DONE && |
| 1787 | cqr->status != DASD_CQR_FAILED && |
| 1788 | cqr->status != DASD_CQR_NEED_ERP && |
| 1789 | cqr->status != DASD_CQR_TERMINATED) |
| 1790 | continue; |
| 1791 | |
| 1792 | if (cqr->status == DASD_CQR_TERMINATED) { |
| 1793 | base->discipline->handle_terminated_request(cqr); |
| 1794 | goto restart; |
| 1795 | } |
| 1796 | |
| 1797 | /* Process requests that may be recovered */ |
| 1798 | if (cqr->status == DASD_CQR_NEED_ERP) { |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 1799 | erp_fn = base->discipline->erp_action(cqr); |
| 1800 | erp_fn(cqr); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1801 | goto restart; |
| 1802 | } |
| 1803 | |
Stefan Haberland | a9cffb2 | 2008-11-14 18:18:08 +0100 | [diff] [blame] | 1804 | /* log sense for fatal error */ |
| 1805 | if (cqr->status == DASD_CQR_FAILED) { |
| 1806 | dasd_log_sense(cqr, &cqr->irb); |
| 1807 | } |
| 1808 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1809 | /* First of all call extended error reporting. */ |
| 1810 | if (dasd_eer_enabled(base) && |
| 1811 | cqr->status == DASD_CQR_FAILED) { |
| 1812 | dasd_eer_write(base, cqr, DASD_EER_FATALERROR); |
| 1813 | |
| 1814 | /* restart request */ |
| 1815 | cqr->status = DASD_CQR_FILLED; |
| 1816 | cqr->retries = 255; |
| 1817 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); |
| 1818 | base->stopped |= DASD_STOPPED_QUIESCE; |
| 1819 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), |
| 1820 | flags); |
| 1821 | goto restart; |
| 1822 | } |
| 1823 | |
| 1824 | /* Process finished ERP request. */ |
| 1825 | if (cqr->refers) { |
| 1826 | __dasd_block_process_erp(block, cqr); |
| 1827 | goto restart; |
| 1828 | } |
| 1829 | |
| 1830 | /* Rechain finished requests to final queue */ |
| 1831 | cqr->endclk = get_clock(); |
| 1832 | list_move_tail(&cqr->blocklist, final_queue); |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data) |
| 1837 | { |
| 1838 | dasd_schedule_block_bh(cqr->block); |
| 1839 | } |
| 1840 | |
| 1841 | static void __dasd_block_start_head(struct dasd_block *block) |
| 1842 | { |
| 1843 | struct dasd_ccw_req *cqr; |
| 1844 | |
| 1845 | if (list_empty(&block->ccw_queue)) |
| 1846 | return; |
| 1847 | /* We allways begin with the first requests on the queue, as some |
| 1848 | * of previously started requests have to be enqueued on a |
| 1849 | * dasd_device again for error recovery. |
| 1850 | */ |
| 1851 | list_for_each_entry(cqr, &block->ccw_queue, blocklist) { |
| 1852 | if (cqr->status != DASD_CQR_FILLED) |
| 1853 | continue; |
| 1854 | /* Non-temporary stop condition will trigger fail fast */ |
| 1855 | if (block->base->stopped & ~DASD_STOPPED_PENDING && |
| 1856 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && |
| 1857 | (!dasd_eer_enabled(block->base))) { |
| 1858 | cqr->status = DASD_CQR_FAILED; |
| 1859 | dasd_schedule_block_bh(block); |
| 1860 | continue; |
| 1861 | } |
| 1862 | /* Don't try to start requests if device is stopped */ |
| 1863 | if (block->base->stopped) |
| 1864 | return; |
| 1865 | |
| 1866 | /* just a fail safe check, should not happen */ |
| 1867 | if (!cqr->startdev) |
| 1868 | cqr->startdev = block->base; |
| 1869 | |
| 1870 | /* make sure that the requests we submit find their way back */ |
| 1871 | cqr->callback = dasd_return_cqr_cb; |
| 1872 | |
| 1873 | dasd_add_request_tail(cqr); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | /* |
| 1878 | * Central dasd_block layer routine. Takes requests from the generic |
| 1879 | * block layer request queue, creates ccw requests, enqueues them on |
| 1880 | * a dasd_device and processes ccw requests that have been returned. |
| 1881 | */ |
| 1882 | static void dasd_block_tasklet(struct dasd_block *block) |
| 1883 | { |
| 1884 | struct list_head final_queue; |
| 1885 | struct list_head *l, *n; |
| 1886 | struct dasd_ccw_req *cqr; |
| 1887 | |
| 1888 | atomic_set(&block->tasklet_scheduled, 0); |
| 1889 | INIT_LIST_HEAD(&final_queue); |
| 1890 | spin_lock(&block->queue_lock); |
| 1891 | /* Finish off requests on ccw queue */ |
| 1892 | __dasd_process_block_ccw_queue(block, &final_queue); |
| 1893 | spin_unlock(&block->queue_lock); |
| 1894 | /* Now call the callback function of requests with final status */ |
| 1895 | spin_lock_irq(&block->request_queue_lock); |
| 1896 | list_for_each_safe(l, n, &final_queue) { |
| 1897 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); |
| 1898 | list_del_init(&cqr->blocklist); |
| 1899 | __dasd_cleanup_cqr(cqr); |
| 1900 | } |
| 1901 | spin_lock(&block->queue_lock); |
| 1902 | /* Get new request from the block device request queue */ |
| 1903 | __dasd_process_request_queue(block); |
| 1904 | /* Now check if the head of the ccw queue needs to be started. */ |
| 1905 | __dasd_block_start_head(block); |
| 1906 | spin_unlock(&block->queue_lock); |
| 1907 | spin_unlock_irq(&block->request_queue_lock); |
| 1908 | dasd_put_device(block->base); |
| 1909 | } |
| 1910 | |
| 1911 | static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data) |
| 1912 | { |
| 1913 | wake_up(&dasd_flush_wq); |
| 1914 | } |
| 1915 | |
| 1916 | /* |
| 1917 | * Go through all request on the dasd_block request queue, cancel them |
| 1918 | * on the respective dasd_device, and return them to the generic |
| 1919 | * block layer. |
| 1920 | */ |
| 1921 | static int dasd_flush_block_queue(struct dasd_block *block) |
| 1922 | { |
| 1923 | struct dasd_ccw_req *cqr, *n; |
| 1924 | int rc, i; |
| 1925 | struct list_head flush_queue; |
| 1926 | |
| 1927 | INIT_LIST_HEAD(&flush_queue); |
| 1928 | spin_lock_bh(&block->queue_lock); |
| 1929 | rc = 0; |
| 1930 | restart: |
| 1931 | list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) { |
| 1932 | /* if this request currently owned by a dasd_device cancel it */ |
| 1933 | if (cqr->status >= DASD_CQR_QUEUED) |
| 1934 | rc = dasd_cancel_req(cqr); |
| 1935 | if (rc < 0) |
| 1936 | break; |
| 1937 | /* Rechain request (including erp chain) so it won't be |
| 1938 | * touched by the dasd_block_tasklet anymore. |
| 1939 | * Replace the callback so we notice when the request |
| 1940 | * is returned from the dasd_device layer. |
| 1941 | */ |
| 1942 | cqr->callback = _dasd_wake_block_flush_cb; |
| 1943 | for (i = 0; cqr != NULL; cqr = cqr->refers, i++) |
| 1944 | list_move_tail(&cqr->blocklist, &flush_queue); |
| 1945 | if (i > 1) |
| 1946 | /* moved more than one request - need to restart */ |
| 1947 | goto restart; |
| 1948 | } |
| 1949 | spin_unlock_bh(&block->queue_lock); |
| 1950 | /* Now call the callback function of flushed requests */ |
| 1951 | restart_cb: |
| 1952 | list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) { |
| 1953 | wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED)); |
| 1954 | /* Process finished ERP request. */ |
| 1955 | if (cqr->refers) { |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 1956 | spin_lock_bh(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1957 | __dasd_block_process_erp(block, cqr); |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 1958 | spin_unlock_bh(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1959 | /* restart list_for_xx loop since dasd_process_erp |
| 1960 | * might remove multiple elements */ |
| 1961 | goto restart_cb; |
| 1962 | } |
| 1963 | /* call the callback function */ |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 1964 | spin_lock_irq(&block->request_queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1965 | cqr->endclk = get_clock(); |
| 1966 | list_del_init(&cqr->blocklist); |
| 1967 | __dasd_cleanup_cqr(cqr); |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 1968 | spin_unlock_irq(&block->request_queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1969 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | return rc; |
| 1971 | } |
| 1972 | |
| 1973 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1974 | * Schedules a call to dasd_tasklet over the device tasklet. |
| 1975 | */ |
| 1976 | void dasd_schedule_block_bh(struct dasd_block *block) |
| 1977 | { |
| 1978 | /* Protect against rescheduling. */ |
| 1979 | if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0) |
| 1980 | return; |
| 1981 | /* life cycle of block is bound to it's base device */ |
| 1982 | dasd_get_device(block->base); |
| 1983 | tasklet_hi_schedule(&block->tasklet); |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | /* |
| 1988 | * SECTION: external block device operations |
| 1989 | * (request queue handling, open, release, etc.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | */ |
| 1991 | |
| 1992 | /* |
| 1993 | * Dasd request queue function. Called from ll_rw_blk.c |
| 1994 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1995 | static void do_dasd_request(struct request_queue *queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1997 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1999 | block = queue->queuedata; |
| 2000 | spin_lock(&block->queue_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | /* Get new request from the block device request queue */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2002 | __dasd_process_request_queue(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | /* Now check if the head of the ccw queue needs to be started. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2004 | __dasd_block_start_head(block); |
| 2005 | spin_unlock(&block->queue_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /* |
| 2009 | * Allocate and initialize request queue and default I/O scheduler. |
| 2010 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2011 | static int dasd_alloc_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | { |
| 2013 | int rc; |
| 2014 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2015 | block->request_queue = blk_init_queue(do_dasd_request, |
| 2016 | &block->request_queue_lock); |
| 2017 | if (block->request_queue == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | return -ENOMEM; |
| 2019 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2020 | block->request_queue->queuedata = block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2022 | elevator_exit(block->request_queue->elevator); |
Josef 'Jeff' Sipek | 08a8a0c | 2008-04-17 07:45:56 +0200 | [diff] [blame] | 2023 | block->request_queue->elevator = NULL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2024 | rc = elevator_init(block->request_queue, "deadline"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | if (rc) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2026 | blk_cleanup_queue(block->request_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | return rc; |
| 2028 | } |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
| 2032 | /* |
| 2033 | * Allocate and initialize request queue. |
| 2034 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2035 | static void dasd_setup_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | { |
| 2037 | int max; |
| 2038 | |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 2039 | blk_queue_logical_block_size(block->request_queue, block->bp_block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2040 | max = block->base->discipline->max_blocks << block->s2b_shift; |
| 2041 | blk_queue_max_sectors(block->request_queue, max); |
| 2042 | blk_queue_max_phys_segments(block->request_queue, -1L); |
| 2043 | blk_queue_max_hw_segments(block->request_queue, -1L); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2044 | /* with page sized segments we can translate each segement into |
| 2045 | * one idaw/tidaw |
| 2046 | */ |
| 2047 | blk_queue_max_segment_size(block->request_queue, PAGE_SIZE); |
| 2048 | blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2049 | blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | /* |
| 2053 | * Deactivate and free request queue. |
| 2054 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2055 | static void dasd_free_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2057 | if (block->request_queue) { |
| 2058 | blk_cleanup_queue(block->request_queue); |
| 2059 | block->request_queue = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | /* |
| 2064 | * Flush request on the request queue. |
| 2065 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2066 | static void dasd_flush_request_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | { |
| 2068 | struct request *req; |
| 2069 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2070 | if (!block->request_queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | return; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2072 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2073 | spin_lock_irq(&block->request_queue_lock); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 2074 | while ((req = blk_fetch_request(block->request_queue))) |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 2075 | __blk_end_request_all(req, -EIO); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2076 | spin_unlock_irq(&block->request_queue_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 2079 | static int dasd_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 2081 | struct dasd_block *block = bdev->bd_disk->private_data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2082 | struct dasd_device *base = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | int rc; |
| 2084 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2085 | atomic_inc(&block->open_count); |
| 2086 | if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | rc = -ENODEV; |
| 2088 | goto unlock; |
| 2089 | } |
| 2090 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2091 | if (!try_module_get(base->discipline->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | rc = -EINVAL; |
| 2093 | goto unlock; |
| 2094 | } |
| 2095 | |
| 2096 | if (dasd_probeonly) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2097 | dev_info(&base->cdev->dev, |
| 2098 | "Accessing the DASD failed because it is in " |
| 2099 | "probeonly mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | rc = -EPERM; |
| 2101 | goto out; |
| 2102 | } |
| 2103 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2104 | if (base->state <= DASD_STATE_BASIC) { |
| 2105 | DBF_DEV_EVENT(DBF_ERR, base, " %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | " Cannot open unrecognized device"); |
| 2107 | rc = -ENODEV; |
| 2108 | goto out; |
| 2109 | } |
| 2110 | |
| 2111 | return 0; |
| 2112 | |
| 2113 | out: |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2114 | module_put(base->discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | unlock: |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2116 | atomic_dec(&block->open_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | return rc; |
| 2118 | } |
| 2119 | |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 2120 | static int dasd_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2122 | struct dasd_block *block = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2124 | atomic_dec(&block->open_count); |
| 2125 | module_put(block->base->discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | return 0; |
| 2127 | } |
| 2128 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2129 | /* |
| 2130 | * Return disk geometry. |
| 2131 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2132 | static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2133 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2134 | struct dasd_block *block; |
| 2135 | struct dasd_device *base; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2136 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2137 | block = bdev->bd_disk->private_data; |
| 2138 | base = block->base; |
| 2139 | if (!block) |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2140 | return -ENODEV; |
| 2141 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2142 | if (!base->discipline || |
| 2143 | !base->discipline->fill_geometry) |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2144 | return -EINVAL; |
| 2145 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2146 | base->discipline->fill_geometry(block, geo); |
| 2147 | geo->start = get_start_sect(bdev) >> block->s2b_shift; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2148 | return 0; |
| 2149 | } |
| 2150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | struct block_device_operations |
| 2152 | dasd_device_operations = { |
| 2153 | .owner = THIS_MODULE, |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 2154 | .open = dasd_open, |
| 2155 | .release = dasd_release, |
Heiko Carstens | 0000d03 | 2009-03-26 15:23:45 +0100 | [diff] [blame] | 2156 | .ioctl = dasd_ioctl, |
| 2157 | .compat_ioctl = dasd_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 2158 | .getgeo = dasd_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | }; |
| 2160 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2161 | /******************************************************************************* |
| 2162 | * end of block device operations |
| 2163 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
| 2165 | static void |
| 2166 | dasd_exit(void) |
| 2167 | { |
| 2168 | #ifdef CONFIG_PROC_FS |
| 2169 | dasd_proc_exit(); |
| 2170 | #endif |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2171 | dasd_eer_exit(); |
Horst Hummel | 6bb0e01 | 2005-07-27 11:45:03 -0700 | [diff] [blame] | 2172 | if (dasd_page_cache != NULL) { |
| 2173 | kmem_cache_destroy(dasd_page_cache); |
| 2174 | dasd_page_cache = NULL; |
| 2175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | dasd_gendisk_exit(); |
| 2177 | dasd_devmap_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | if (dasd_debug_area != NULL) { |
| 2179 | debug_unregister(dasd_debug_area); |
| 2180 | dasd_debug_area = NULL; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | /* |
| 2185 | * SECTION: common functions for ccw_driver use |
| 2186 | */ |
| 2187 | |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 2188 | static void dasd_generic_auto_online(void *data, async_cookie_t cookie) |
| 2189 | { |
| 2190 | struct ccw_device *cdev = data; |
| 2191 | int ret; |
| 2192 | |
| 2193 | ret = ccw_device_set_online(cdev); |
| 2194 | if (ret) |
| 2195 | pr_warning("%s: Setting the DASD online failed with rc=%d\n", |
| 2196 | dev_name(&cdev->dev), ret); |
| 2197 | else { |
| 2198 | struct dasd_device *device = dasd_device_from_cdev(cdev); |
| 2199 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
| 2200 | dasd_put_device(device); |
| 2201 | } |
| 2202 | } |
| 2203 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2204 | /* |
| 2205 | * Initial attempt at a probe function. this can be simplified once |
| 2206 | * the other detection code is gone. |
| 2207 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2208 | int dasd_generic_probe(struct ccw_device *cdev, |
| 2209 | struct dasd_discipline *discipline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | { |
| 2211 | int ret; |
| 2212 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2213 | ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP); |
| 2214 | if (ret) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2215 | DBF_EVENT(DBF_WARNING, |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2216 | "dasd_generic_probe: could not set ccw-device options " |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2217 | "for %s\n", dev_name(&cdev->dev)); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2218 | return ret; |
| 2219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | ret = dasd_add_sysfs_files(cdev); |
| 2221 | if (ret) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2222 | DBF_EVENT(DBF_WARNING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | "dasd_generic_probe: could not add sysfs entries " |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2224 | "for %s\n", dev_name(&cdev->dev)); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2225 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2227 | cdev->handler = &dasd_int_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2229 | /* |
| 2230 | * Automatically online either all dasd devices (dasd_autodetect) |
| 2231 | * or all devices specified with dasd= parameters during |
| 2232 | * initial probe. |
| 2233 | */ |
| 2234 | if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) || |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2235 | (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0)) |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 2236 | async_schedule(dasd_generic_auto_online, cdev); |
Stefan Haberland | de3e0da | 2008-01-26 14:11:08 +0100 | [diff] [blame] | 2237 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2240 | /* |
| 2241 | * This will one day be called from a global not_oper handler. |
| 2242 | * It is also used by driver_unregister during module unload. |
| 2243 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2244 | void dasd_generic_remove(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | { |
| 2246 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2247 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
Horst Hummel | 59afda7 | 2005-05-16 21:53:39 -0700 | [diff] [blame] | 2249 | cdev->handler = NULL; |
| 2250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | dasd_remove_sysfs_files(cdev); |
| 2252 | device = dasd_device_from_cdev(cdev); |
| 2253 | if (IS_ERR(device)) |
| 2254 | return; |
| 2255 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 2256 | /* Already doing offline processing */ |
| 2257 | dasd_put_device(device); |
| 2258 | return; |
| 2259 | } |
| 2260 | /* |
| 2261 | * This device is removed unconditionally. Set offline |
| 2262 | * flag to prevent dasd_open from opening it while it is |
| 2263 | * no quite down yet. |
| 2264 | */ |
| 2265 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 2266 | /* dasd_delete_device destroys the device reference. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2267 | block = device->block; |
| 2268 | device->block = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | dasd_delete_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2270 | /* |
| 2271 | * life cycle of block is bound to device, so delete it after |
| 2272 | * device was safely removed |
| 2273 | */ |
| 2274 | if (block) |
| 2275 | dasd_free_block(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2278 | /* |
| 2279 | * Activate a device. This is called from dasd_{eckd,fba}_probe() when either |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | * the device is detected for the first time and is supposed to be used |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2281 | * or the user has started activation through sysfs. |
| 2282 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2283 | int dasd_generic_set_online(struct ccw_device *cdev, |
| 2284 | struct dasd_discipline *base_discipline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | { |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 2286 | struct dasd_discipline *discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | struct dasd_device *device; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 2288 | int rc; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 2289 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 2290 | /* first online clears initial online feature flag */ |
| 2291 | dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | device = dasd_create_device(cdev); |
| 2293 | if (IS_ERR(device)) |
| 2294 | return PTR_ERR(device); |
| 2295 | |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 2296 | discipline = base_discipline; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 2297 | if (device->features & DASD_FEATURE_USEDIAG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | if (!dasd_diag_discipline_pointer) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2299 | pr_warning("%s Setting the DASD online failed because " |
| 2300 | "of missing DIAG discipline\n", |
| 2301 | dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | dasd_delete_device(device); |
| 2303 | return -ENODEV; |
| 2304 | } |
| 2305 | discipline = dasd_diag_discipline_pointer; |
| 2306 | } |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 2307 | if (!try_module_get(base_discipline->owner)) { |
| 2308 | dasd_delete_device(device); |
| 2309 | return -EINVAL; |
| 2310 | } |
| 2311 | if (!try_module_get(discipline->owner)) { |
| 2312 | module_put(base_discipline->owner); |
| 2313 | dasd_delete_device(device); |
| 2314 | return -EINVAL; |
| 2315 | } |
| 2316 | device->base_discipline = base_discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | device->discipline = discipline; |
| 2318 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2319 | /* check_device will allocate block device if necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | rc = discipline->check_device(device); |
| 2321 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2322 | pr_warning("%s Setting the DASD online with discipline %s " |
| 2323 | "failed with rc=%i\n", |
| 2324 | dev_name(&cdev->dev), discipline->name, rc); |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 2325 | module_put(discipline->owner); |
| 2326 | module_put(base_discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | dasd_delete_device(device); |
| 2328 | return rc; |
| 2329 | } |
| 2330 | |
| 2331 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 2332 | if (device->state <= DASD_STATE_KNOWN) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2333 | pr_warning("%s Setting the DASD online failed because of a " |
| 2334 | "missing discipline\n", dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | rc = -ENODEV; |
| 2336 | dasd_set_target_state(device, DASD_STATE_NEW); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2337 | if (device->block) |
| 2338 | dasd_free_block(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | dasd_delete_device(device); |
| 2340 | } else |
| 2341 | pr_debug("dasd_generic device %s found\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2342 | dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | return rc; |
| 2345 | } |
| 2346 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2347 | int dasd_generic_set_offline(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | { |
| 2349 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2350 | struct dasd_block *block; |
Horst Hummel | dafd87a | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2351 | int max_count, open_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
| 2353 | device = dasd_device_from_cdev(cdev); |
| 2354 | if (IS_ERR(device)) |
| 2355 | return PTR_ERR(device); |
| 2356 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 2357 | /* Already doing offline processing */ |
| 2358 | dasd_put_device(device); |
| 2359 | return 0; |
| 2360 | } |
| 2361 | /* |
| 2362 | * We must make sure that this device is currently not in use. |
| 2363 | * The open_count is increased for every opener, that includes |
| 2364 | * the blkdev_get in dasd_scan_partitions. We are only interested |
| 2365 | * in the other openers. |
| 2366 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2367 | if (device->block) { |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 2368 | max_count = device->block->bdev ? 0 : -1; |
| 2369 | open_count = atomic_read(&device->block->open_count); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2370 | if (open_count > max_count) { |
| 2371 | if (open_count > 0) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2372 | pr_warning("%s: The DASD cannot be set offline " |
| 2373 | "with open count %i\n", |
| 2374 | dev_name(&cdev->dev), open_count); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2375 | else |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2376 | pr_warning("%s: The DASD cannot be set offline " |
| 2377 | "while it is in use\n", |
| 2378 | dev_name(&cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2379 | clear_bit(DASD_FLAG_OFFLINE, &device->flags); |
| 2380 | dasd_put_device(device); |
| 2381 | return -EBUSY; |
| 2382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 2385 | /* dasd_delete_device destroys the device reference. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2386 | block = device->block; |
| 2387 | device->block = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | dasd_delete_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2389 | /* |
| 2390 | * life cycle of block is bound to device, so delete it after |
| 2391 | * device was safely removed |
| 2392 | */ |
| 2393 | if (block) |
| 2394 | dasd_free_block(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | return 0; |
| 2396 | } |
| 2397 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2398 | int dasd_generic_notify(struct ccw_device *cdev, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | { |
| 2400 | struct dasd_device *device; |
| 2401 | struct dasd_ccw_req *cqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | int ret; |
| 2403 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 2404 | device = dasd_device_from_cdev_locked(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | if (IS_ERR(device)) |
| 2406 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | ret = 0; |
| 2408 | switch (event) { |
| 2409 | case CIO_GONE: |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 2410 | case CIO_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | case CIO_NO_PATH: |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2412 | /* First of all call extended error reporting. */ |
| 2413 | dasd_eer_write(device, NULL, DASD_EER_NOPATH); |
| 2414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | if (device->state < DASD_STATE_BASIC) |
| 2416 | break; |
| 2417 | /* Device is active. We want to keep it. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2418 | list_for_each_entry(cqr, &device->ccw_queue, devlist) |
| 2419 | if (cqr->status == DASD_CQR_IN_IO) { |
| 2420 | cqr->status = DASD_CQR_QUEUED; |
| 2421 | cqr->retries++; |
| 2422 | } |
| 2423 | device->stopped |= DASD_STOPPED_DC_WAIT; |
| 2424 | dasd_device_clear_timer(device); |
| 2425 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | ret = 1; |
| 2427 | break; |
| 2428 | case CIO_OPER: |
| 2429 | /* FIXME: add a sanity check. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2430 | device->stopped &= ~DASD_STOPPED_DC_WAIT; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 2431 | if (device->stopped & DASD_UNRESUMED_PM) { |
| 2432 | device->stopped &= ~DASD_UNRESUMED_PM; |
| 2433 | dasd_restore_device(device); |
| 2434 | ret = 1; |
| 2435 | break; |
| 2436 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2437 | dasd_schedule_device_bh(device); |
| 2438 | if (device->block) |
| 2439 | dasd_schedule_block_bh(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | ret = 1; |
| 2441 | break; |
| 2442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | dasd_put_device(device); |
| 2444 | return ret; |
| 2445 | } |
| 2446 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 2447 | int dasd_generic_pm_freeze(struct ccw_device *cdev) |
| 2448 | { |
| 2449 | struct dasd_ccw_req *cqr, *n; |
| 2450 | int rc; |
| 2451 | struct list_head freeze_queue; |
| 2452 | struct dasd_device *device = dasd_device_from_cdev(cdev); |
| 2453 | |
| 2454 | if (IS_ERR(device)) |
| 2455 | return PTR_ERR(device); |
| 2456 | /* disallow new I/O */ |
| 2457 | device->stopped |= DASD_STOPPED_PM; |
| 2458 | /* clear active requests */ |
| 2459 | INIT_LIST_HEAD(&freeze_queue); |
| 2460 | spin_lock_irq(get_ccwdev_lock(cdev)); |
| 2461 | rc = 0; |
| 2462 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { |
| 2463 | /* Check status and move request to flush_queue */ |
| 2464 | if (cqr->status == DASD_CQR_IN_IO) { |
| 2465 | rc = device->discipline->term_IO(cqr); |
| 2466 | if (rc) { |
| 2467 | /* unable to terminate requeust */ |
| 2468 | dev_err(&device->cdev->dev, |
| 2469 | "Unable to terminate request %p " |
| 2470 | "on suspend\n", cqr); |
| 2471 | spin_unlock_irq(get_ccwdev_lock(cdev)); |
| 2472 | dasd_put_device(device); |
| 2473 | return rc; |
| 2474 | } |
| 2475 | } |
| 2476 | list_move_tail(&cqr->devlist, &freeze_queue); |
| 2477 | } |
| 2478 | |
| 2479 | spin_unlock_irq(get_ccwdev_lock(cdev)); |
| 2480 | |
| 2481 | list_for_each_entry_safe(cqr, n, &freeze_queue, devlist) { |
| 2482 | wait_event(dasd_flush_wq, |
| 2483 | (cqr->status != DASD_CQR_CLEAR_PENDING)); |
| 2484 | if (cqr->status == DASD_CQR_CLEARED) |
| 2485 | cqr->status = DASD_CQR_QUEUED; |
| 2486 | } |
| 2487 | /* move freeze_queue to start of the ccw_queue */ |
| 2488 | spin_lock_irq(get_ccwdev_lock(cdev)); |
| 2489 | list_splice_tail(&freeze_queue, &device->ccw_queue); |
| 2490 | spin_unlock_irq(get_ccwdev_lock(cdev)); |
| 2491 | |
| 2492 | if (device->discipline->freeze) |
| 2493 | rc = device->discipline->freeze(device); |
| 2494 | |
| 2495 | dasd_put_device(device); |
| 2496 | return rc; |
| 2497 | } |
| 2498 | EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze); |
| 2499 | |
| 2500 | int dasd_generic_restore_device(struct ccw_device *cdev) |
| 2501 | { |
| 2502 | struct dasd_device *device = dasd_device_from_cdev(cdev); |
| 2503 | int rc = 0; |
| 2504 | |
| 2505 | if (IS_ERR(device)) |
| 2506 | return PTR_ERR(device); |
| 2507 | |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 2508 | /* allow new IO again */ |
| 2509 | device->stopped &= ~DASD_STOPPED_PM; |
| 2510 | device->stopped &= ~DASD_UNRESUMED_PM; |
| 2511 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 2512 | dasd_schedule_device_bh(device); |
| 2513 | if (device->block) |
| 2514 | dasd_schedule_block_bh(device->block); |
| 2515 | |
| 2516 | if (device->discipline->restore) |
| 2517 | rc = device->discipline->restore(device); |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 2518 | if (rc) |
| 2519 | /* |
| 2520 | * if the resume failed for the DASD we put it in |
| 2521 | * an UNRESUMED stop state |
| 2522 | */ |
| 2523 | device->stopped |= DASD_UNRESUMED_PM; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 2524 | |
| 2525 | dasd_put_device(device); |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 2526 | return 0; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 2527 | } |
| 2528 | EXPORT_SYMBOL_GPL(dasd_generic_restore_device); |
| 2529 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 2530 | static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device, |
| 2531 | void *rdc_buffer, |
| 2532 | int rdc_buffer_size, |
| 2533 | char *magic) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2534 | { |
| 2535 | struct dasd_ccw_req *cqr; |
| 2536 | struct ccw1 *ccw; |
| 2537 | |
| 2538 | cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device); |
| 2539 | |
| 2540 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2541 | /* internal error 13 - Allocating the RDC request failed*/ |
| 2542 | dev_err(&device->cdev->dev, |
| 2543 | "An error occurred in the DASD device driver, " |
| 2544 | "reason=%s\n", "13"); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2545 | return cqr; |
| 2546 | } |
| 2547 | |
| 2548 | ccw = cqr->cpaddr; |
| 2549 | ccw->cmd_code = CCW_CMD_RDC; |
| 2550 | ccw->cda = (__u32)(addr_t)rdc_buffer; |
| 2551 | ccw->count = rdc_buffer_size; |
| 2552 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2553 | cqr->startdev = device; |
| 2554 | cqr->memdev = device; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2555 | cqr->expires = 10*HZ; |
| 2556 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 2557 | cqr->retries = 2; |
| 2558 | cqr->buildclk = get_clock(); |
| 2559 | cqr->status = DASD_CQR_FILLED; |
| 2560 | return cqr; |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic, |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 2565 | void *rdc_buffer, int rdc_buffer_size) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2566 | { |
| 2567 | int ret; |
| 2568 | struct dasd_ccw_req *cqr; |
| 2569 | |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 2570 | cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size, |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2571 | magic); |
| 2572 | if (IS_ERR(cqr)) |
| 2573 | return PTR_ERR(cqr); |
| 2574 | |
| 2575 | ret = dasd_sleep_on(cqr); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2576 | dasd_sfree_request(cqr, cqr->memdev); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 2577 | return ret; |
| 2578 | } |
Cornelia Huck | aaff0f6 | 2007-05-10 15:45:45 +0200 | [diff] [blame] | 2579 | EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars); |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2580 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 2581 | /* |
| 2582 | * In command mode and transport mode we need to look for sense |
| 2583 | * data in different places. The sense data itself is allways |
| 2584 | * an array of 32 bytes, so we can unify the sense data access |
| 2585 | * for both modes. |
| 2586 | */ |
| 2587 | char *dasd_get_sense(struct irb *irb) |
| 2588 | { |
| 2589 | struct tsb *tsb = NULL; |
| 2590 | char *sense = NULL; |
| 2591 | |
| 2592 | if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) { |
| 2593 | if (irb->scsw.tm.tcw) |
| 2594 | tsb = tcw_get_tsb((struct tcw *)(unsigned long) |
| 2595 | irb->scsw.tm.tcw); |
| 2596 | if (tsb && tsb->length == 64 && tsb->flags) |
| 2597 | switch (tsb->flags & 0x07) { |
| 2598 | case 1: /* tsa_iostat */ |
| 2599 | sense = tsb->tsa.iostat.sense; |
| 2600 | break; |
| 2601 | case 2: /* tsa_ddpc */ |
| 2602 | sense = tsb->tsa.ddpc.sense; |
| 2603 | break; |
| 2604 | default: |
| 2605 | /* currently we don't use interrogate data */ |
| 2606 | break; |
| 2607 | } |
| 2608 | } else if (irb->esw.esw0.erw.cons) { |
| 2609 | sense = irb->ecw; |
| 2610 | } |
| 2611 | return sense; |
| 2612 | } |
| 2613 | EXPORT_SYMBOL_GPL(dasd_get_sense); |
| 2614 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2615 | static int __init dasd_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | { |
| 2617 | int rc; |
| 2618 | |
| 2619 | init_waitqueue_head(&dasd_init_waitq); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2620 | init_waitqueue_head(&dasd_flush_wq); |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 2621 | init_waitqueue_head(&generic_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | |
| 2623 | /* register 'common' DASD debug area, used for all DBF_XXX calls */ |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 2624 | dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | if (dasd_debug_area == NULL) { |
| 2626 | rc = -ENOMEM; |
| 2627 | goto failed; |
| 2628 | } |
| 2629 | debug_register_view(dasd_debug_area, &debug_sprintf_view); |
Horst Hummel | b0035f1 | 2006-09-20 15:59:07 +0200 | [diff] [blame] | 2630 | debug_set_level(dasd_debug_area, DBF_WARNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
| 2632 | DBF_EVENT(DBF_EMERG, "%s", "debug area created"); |
| 2633 | |
| 2634 | dasd_diag_discipline_pointer = NULL; |
| 2635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | rc = dasd_devmap_init(); |
| 2637 | if (rc) |
| 2638 | goto failed; |
| 2639 | rc = dasd_gendisk_init(); |
| 2640 | if (rc) |
| 2641 | goto failed; |
| 2642 | rc = dasd_parse(); |
| 2643 | if (rc) |
| 2644 | goto failed; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2645 | rc = dasd_eer_init(); |
| 2646 | if (rc) |
| 2647 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | #ifdef CONFIG_PROC_FS |
| 2649 | rc = dasd_proc_init(); |
| 2650 | if (rc) |
| 2651 | goto failed; |
| 2652 | #endif |
| 2653 | |
| 2654 | return 0; |
| 2655 | failed: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2656 | pr_info("The DASD device driver could not be initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | dasd_exit(); |
| 2658 | return rc; |
| 2659 | } |
| 2660 | |
| 2661 | module_init(dasd_init); |
| 2662 | module_exit(dasd_exit); |
| 2663 | |
| 2664 | EXPORT_SYMBOL(dasd_debug_area); |
| 2665 | EXPORT_SYMBOL(dasd_diag_discipline_pointer); |
| 2666 | |
| 2667 | EXPORT_SYMBOL(dasd_add_request_head); |
| 2668 | EXPORT_SYMBOL(dasd_add_request_tail); |
| 2669 | EXPORT_SYMBOL(dasd_cancel_req); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2670 | EXPORT_SYMBOL(dasd_device_clear_timer); |
| 2671 | EXPORT_SYMBOL(dasd_block_clear_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | EXPORT_SYMBOL(dasd_enable_device); |
| 2673 | EXPORT_SYMBOL(dasd_int_handler); |
| 2674 | EXPORT_SYMBOL(dasd_kfree_request); |
| 2675 | EXPORT_SYMBOL(dasd_kick_device); |
| 2676 | EXPORT_SYMBOL(dasd_kmalloc_request); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2677 | EXPORT_SYMBOL(dasd_schedule_device_bh); |
| 2678 | EXPORT_SYMBOL(dasd_schedule_block_bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | EXPORT_SYMBOL(dasd_set_target_state); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2680 | EXPORT_SYMBOL(dasd_device_set_timer); |
| 2681 | EXPORT_SYMBOL(dasd_block_set_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | EXPORT_SYMBOL(dasd_sfree_request); |
| 2683 | EXPORT_SYMBOL(dasd_sleep_on); |
| 2684 | EXPORT_SYMBOL(dasd_sleep_on_immediatly); |
| 2685 | EXPORT_SYMBOL(dasd_sleep_on_interruptible); |
| 2686 | EXPORT_SYMBOL(dasd_smalloc_request); |
| 2687 | EXPORT_SYMBOL(dasd_start_IO); |
| 2688 | EXPORT_SYMBOL(dasd_term_IO); |
| 2689 | |
| 2690 | EXPORT_SYMBOL_GPL(dasd_generic_probe); |
| 2691 | EXPORT_SYMBOL_GPL(dasd_generic_remove); |
| 2692 | EXPORT_SYMBOL_GPL(dasd_generic_notify); |
| 2693 | EXPORT_SYMBOL_GPL(dasd_generic_set_online); |
| 2694 | EXPORT_SYMBOL_GPL(dasd_generic_set_offline); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2695 | EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change); |
| 2696 | EXPORT_SYMBOL_GPL(dasd_flush_device_queue); |
| 2697 | EXPORT_SYMBOL_GPL(dasd_alloc_block); |
| 2698 | EXPORT_SYMBOL_GPL(dasd_free_block); |