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