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