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