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