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