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