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