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