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