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