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