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