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