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