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