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