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