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