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