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