Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PAV alias management for the DASD ECKD discipline |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2007 |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 5 | * Author(s): Stefan Weinhuber <wein@de.ibm.com> |
| 6 | */ |
| 7 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 8 | #define KMSG_COMPONENT "dasd-eckd" |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 9 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 10 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 12 | #include <asm/ebcdic.h> |
| 13 | #include "dasd_int.h" |
| 14 | #include "dasd_eckd.h" |
| 15 | |
| 16 | #ifdef PRINTK_HEADER |
| 17 | #undef PRINTK_HEADER |
| 18 | #endif /* PRINTK_HEADER */ |
| 19 | #define PRINTK_HEADER "dasd(eckd):" |
| 20 | |
| 21 | |
| 22 | /* |
| 23 | * General concept of alias management: |
| 24 | * - PAV and DASD alias management is specific to the eckd discipline. |
| 25 | * - A device is connected to an lcu as long as the device exists. |
| 26 | * dasd_alias_make_device_known_to_lcu will be called wenn the |
| 27 | * device is checked by the eckd discipline and |
| 28 | * dasd_alias_disconnect_device_from_lcu will be called |
| 29 | * before the device is deleted. |
| 30 | * - The dasd_alias_add_device / dasd_alias_remove_device |
| 31 | * functions mark the point when a device is 'ready for service'. |
| 32 | * - A summary unit check is a rare occasion, but it is mandatory to |
| 33 | * support it. It requires some complex recovery actions before the |
| 34 | * devices can be used again (see dasd_alias_handle_summary_unit_check). |
| 35 | * - dasd_alias_get_start_dev will find an alias device that can be used |
| 36 | * instead of the base device and does some (very simple) load balancing. |
| 37 | * This is the function that gets called for each I/O, so when improving |
| 38 | * something, this function should get faster or better, the rest has just |
| 39 | * to be correct. |
| 40 | */ |
| 41 | |
| 42 | |
| 43 | static void summary_unit_check_handling_work(struct work_struct *); |
| 44 | static void lcu_update_work(struct work_struct *); |
| 45 | static int _schedule_lcu_update(struct alias_lcu *, struct dasd_device *); |
| 46 | |
| 47 | static struct alias_root aliastree = { |
| 48 | .serverlist = LIST_HEAD_INIT(aliastree.serverlist), |
| 49 | .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock), |
| 50 | }; |
| 51 | |
| 52 | static struct alias_server *_find_server(struct dasd_uid *uid) |
| 53 | { |
| 54 | struct alias_server *pos; |
| 55 | list_for_each_entry(pos, &aliastree.serverlist, server) { |
| 56 | if (!strncmp(pos->uid.vendor, uid->vendor, |
| 57 | sizeof(uid->vendor)) |
| 58 | && !strncmp(pos->uid.serial, uid->serial, |
| 59 | sizeof(uid->serial))) |
| 60 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 61 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | static struct alias_lcu *_find_lcu(struct alias_server *server, |
| 66 | struct dasd_uid *uid) |
| 67 | { |
| 68 | struct alias_lcu *pos; |
| 69 | list_for_each_entry(pos, &server->lculist, lcu) { |
| 70 | if (pos->uid.ssid == uid->ssid) |
| 71 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 72 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | static struct alias_pav_group *_find_group(struct alias_lcu *lcu, |
| 77 | struct dasd_uid *uid) |
| 78 | { |
| 79 | struct alias_pav_group *pos; |
| 80 | __u8 search_unit_addr; |
| 81 | |
| 82 | /* for hyper pav there is only one group */ |
| 83 | if (lcu->pav == HYPER_PAV) { |
| 84 | if (list_empty(&lcu->grouplist)) |
| 85 | return NULL; |
| 86 | else |
| 87 | return list_first_entry(&lcu->grouplist, |
| 88 | struct alias_pav_group, group); |
| 89 | } |
| 90 | |
| 91 | /* for base pav we have to find the group that matches the base */ |
| 92 | if (uid->type == UA_BASE_DEVICE) |
| 93 | search_unit_addr = uid->real_unit_addr; |
| 94 | else |
| 95 | search_unit_addr = uid->base_unit_addr; |
| 96 | list_for_each_entry(pos, &lcu->grouplist, group) { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 97 | if (pos->uid.base_unit_addr == search_unit_addr && |
| 98 | !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit))) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 99 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 100 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | static struct alias_server *_allocate_server(struct dasd_uid *uid) |
| 105 | { |
| 106 | struct alias_server *server; |
| 107 | |
| 108 | server = kzalloc(sizeof(*server), GFP_KERNEL); |
| 109 | if (!server) |
| 110 | return ERR_PTR(-ENOMEM); |
| 111 | memcpy(server->uid.vendor, uid->vendor, sizeof(uid->vendor)); |
| 112 | memcpy(server->uid.serial, uid->serial, sizeof(uid->serial)); |
| 113 | INIT_LIST_HEAD(&server->server); |
| 114 | INIT_LIST_HEAD(&server->lculist); |
| 115 | return server; |
| 116 | } |
| 117 | |
| 118 | static void _free_server(struct alias_server *server) |
| 119 | { |
| 120 | kfree(server); |
| 121 | } |
| 122 | |
| 123 | static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid) |
| 124 | { |
| 125 | struct alias_lcu *lcu; |
| 126 | |
| 127 | lcu = kzalloc(sizeof(*lcu), GFP_KERNEL); |
| 128 | if (!lcu) |
| 129 | return ERR_PTR(-ENOMEM); |
| 130 | lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA); |
| 131 | if (!lcu->uac) |
| 132 | goto out_err1; |
| 133 | lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA); |
| 134 | if (!lcu->rsu_cqr) |
| 135 | goto out_err2; |
| 136 | lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1), |
| 137 | GFP_KERNEL | GFP_DMA); |
| 138 | if (!lcu->rsu_cqr->cpaddr) |
| 139 | goto out_err3; |
| 140 | lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA); |
| 141 | if (!lcu->rsu_cqr->data) |
| 142 | goto out_err4; |
| 143 | |
| 144 | memcpy(lcu->uid.vendor, uid->vendor, sizeof(uid->vendor)); |
| 145 | memcpy(lcu->uid.serial, uid->serial, sizeof(uid->serial)); |
| 146 | lcu->uid.ssid = uid->ssid; |
| 147 | lcu->pav = NO_PAV; |
| 148 | lcu->flags = NEED_UAC_UPDATE | UPDATE_PENDING; |
| 149 | INIT_LIST_HEAD(&lcu->lcu); |
| 150 | INIT_LIST_HEAD(&lcu->inactive_devices); |
| 151 | INIT_LIST_HEAD(&lcu->active_devices); |
| 152 | INIT_LIST_HEAD(&lcu->grouplist); |
| 153 | INIT_WORK(&lcu->suc_data.worker, summary_unit_check_handling_work); |
| 154 | INIT_DELAYED_WORK(&lcu->ruac_data.dwork, lcu_update_work); |
| 155 | spin_lock_init(&lcu->lock); |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 156 | init_completion(&lcu->lcu_setup); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 157 | return lcu; |
| 158 | |
| 159 | out_err4: |
| 160 | kfree(lcu->rsu_cqr->cpaddr); |
| 161 | out_err3: |
| 162 | kfree(lcu->rsu_cqr); |
| 163 | out_err2: |
| 164 | kfree(lcu->uac); |
| 165 | out_err1: |
| 166 | kfree(lcu); |
| 167 | return ERR_PTR(-ENOMEM); |
| 168 | } |
| 169 | |
| 170 | static void _free_lcu(struct alias_lcu *lcu) |
| 171 | { |
| 172 | kfree(lcu->rsu_cqr->data); |
| 173 | kfree(lcu->rsu_cqr->cpaddr); |
| 174 | kfree(lcu->rsu_cqr); |
| 175 | kfree(lcu->uac); |
| 176 | kfree(lcu); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * This is the function that will allocate all the server and lcu data, |
| 181 | * so this function must be called first for a new device. |
| 182 | * If the return value is 1, the lcu was already known before, if it |
| 183 | * is 0, this is a new lcu. |
| 184 | * Negative return code indicates that something went wrong (e.g. -ENOMEM) |
| 185 | */ |
| 186 | int dasd_alias_make_device_known_to_lcu(struct dasd_device *device) |
| 187 | { |
| 188 | struct dasd_eckd_private *private; |
| 189 | unsigned long flags; |
| 190 | struct alias_server *server, *newserver; |
| 191 | struct alias_lcu *lcu, *newlcu; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 192 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 193 | |
| 194 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 195 | |
| 196 | device->discipline->get_uid(device, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 197 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 198 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 199 | if (!server) { |
| 200 | spin_unlock_irqrestore(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 201 | newserver = _allocate_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 202 | if (IS_ERR(newserver)) |
| 203 | return PTR_ERR(newserver); |
| 204 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 205 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 206 | if (!server) { |
| 207 | list_add(&newserver->server, &aliastree.serverlist); |
| 208 | server = newserver; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 209 | } else { |
| 210 | /* someone was faster */ |
| 211 | _free_server(newserver); |
| 212 | } |
| 213 | } |
| 214 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 215 | lcu = _find_lcu(server, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 216 | if (!lcu) { |
| 217 | spin_unlock_irqrestore(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 218 | newlcu = _allocate_lcu(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 219 | if (IS_ERR(newlcu)) |
Roel Kluin | 6d53cfe | 2009-12-18 17:43:17 +0100 | [diff] [blame] | 220 | return PTR_ERR(newlcu); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 221 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 222 | lcu = _find_lcu(server, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 223 | if (!lcu) { |
| 224 | list_add(&newlcu->lcu, &server->lculist); |
| 225 | lcu = newlcu; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 226 | } else { |
| 227 | /* someone was faster */ |
| 228 | _free_lcu(newlcu); |
| 229 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 230 | } |
| 231 | spin_lock(&lcu->lock); |
| 232 | list_add(&device->alias_list, &lcu->inactive_devices); |
| 233 | private->lcu = lcu; |
| 234 | spin_unlock(&lcu->lock); |
| 235 | spin_unlock_irqrestore(&aliastree.lock, flags); |
| 236 | |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 237 | return 0; |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 241 | * This function removes a device from the scope of alias management. |
| 242 | * The complicated part is to make sure that it is not in use by |
| 243 | * any of the workers. If necessary cancel the work. |
| 244 | */ |
| 245 | void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device) |
| 246 | { |
| 247 | struct dasd_eckd_private *private; |
| 248 | unsigned long flags; |
| 249 | struct alias_lcu *lcu; |
| 250 | struct alias_server *server; |
| 251 | int was_pending; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 252 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 253 | |
| 254 | private = (struct dasd_eckd_private *) device->private; |
| 255 | lcu = private->lcu; |
Stefan Haberland | f602f6d6 | 2011-01-31 11:30:03 +0100 | [diff] [blame] | 256 | /* nothing to do if already disconnected */ |
| 257 | if (!lcu) |
| 258 | return; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 259 | device->discipline->get_uid(device, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 260 | spin_lock_irqsave(&lcu->lock, flags); |
| 261 | list_del_init(&device->alias_list); |
| 262 | /* make sure that the workers don't use this device */ |
| 263 | if (device == lcu->suc_data.device) { |
| 264 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 265 | cancel_work_sync(&lcu->suc_data.worker); |
| 266 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 267 | if (device == lcu->suc_data.device) { |
| 268 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 269 | lcu->suc_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 270 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 271 | } |
| 272 | was_pending = 0; |
| 273 | if (device == lcu->ruac_data.device) { |
| 274 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 275 | was_pending = 1; |
| 276 | cancel_delayed_work_sync(&lcu->ruac_data.dwork); |
| 277 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 278 | if (device == lcu->ruac_data.device) { |
| 279 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 280 | lcu->ruac_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 281 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 282 | } |
| 283 | private->lcu = NULL; |
| 284 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 285 | |
| 286 | spin_lock_irqsave(&aliastree.lock, flags); |
| 287 | spin_lock(&lcu->lock); |
| 288 | if (list_empty(&lcu->grouplist) && |
| 289 | list_empty(&lcu->active_devices) && |
| 290 | list_empty(&lcu->inactive_devices)) { |
| 291 | list_del(&lcu->lcu); |
| 292 | spin_unlock(&lcu->lock); |
| 293 | _free_lcu(lcu); |
| 294 | lcu = NULL; |
| 295 | } else { |
| 296 | if (was_pending) |
| 297 | _schedule_lcu_update(lcu, NULL); |
| 298 | spin_unlock(&lcu->lock); |
| 299 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 300 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 301 | if (server && list_empty(&server->lculist)) { |
| 302 | list_del(&server->server); |
| 303 | _free_server(server); |
| 304 | } |
| 305 | spin_unlock_irqrestore(&aliastree.lock, flags); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * This function assumes that the unit address configuration stored |
| 310 | * in the lcu is up to date and will update the device uid before |
| 311 | * adding it to a pav group. |
| 312 | */ |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 313 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 314 | static int _add_device_to_lcu(struct alias_lcu *lcu, |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 315 | struct dasd_device *device, |
| 316 | struct dasd_device *pos) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 317 | { |
| 318 | |
| 319 | struct dasd_eckd_private *private; |
| 320 | struct alias_pav_group *group; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 321 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 322 | |
| 323 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 324 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 325 | private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type; |
| 326 | private->uid.base_unit_addr = |
| 327 | lcu->uac->unit[private->uid.real_unit_addr].base_ua; |
| 328 | uid = private->uid; |
| 329 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 330 | /* if we have no PAV anyway, we don't need to bother with PAV groups */ |
| 331 | if (lcu->pav == NO_PAV) { |
| 332 | list_move(&device->alias_list, &lcu->active_devices); |
| 333 | return 0; |
| 334 | } |
| 335 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 336 | group = _find_group(lcu, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 337 | if (!group) { |
| 338 | group = kzalloc(sizeof(*group), GFP_ATOMIC); |
| 339 | if (!group) |
| 340 | return -ENOMEM; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 341 | memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor)); |
| 342 | memcpy(group->uid.serial, uid.serial, sizeof(uid.serial)); |
| 343 | group->uid.ssid = uid.ssid; |
| 344 | if (uid.type == UA_BASE_DEVICE) |
| 345 | group->uid.base_unit_addr = uid.real_unit_addr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 346 | else |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 347 | group->uid.base_unit_addr = uid.base_unit_addr; |
| 348 | memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 349 | INIT_LIST_HEAD(&group->group); |
| 350 | INIT_LIST_HEAD(&group->baselist); |
| 351 | INIT_LIST_HEAD(&group->aliaslist); |
| 352 | list_add(&group->group, &lcu->grouplist); |
| 353 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 354 | if (uid.type == UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 355 | list_move(&device->alias_list, &group->baselist); |
| 356 | else |
| 357 | list_move(&device->alias_list, &group->aliaslist); |
| 358 | private->pavgroup = group; |
| 359 | return 0; |
| 360 | }; |
| 361 | |
| 362 | static void _remove_device_from_lcu(struct alias_lcu *lcu, |
| 363 | struct dasd_device *device) |
| 364 | { |
| 365 | struct dasd_eckd_private *private; |
| 366 | struct alias_pav_group *group; |
| 367 | |
| 368 | private = (struct dasd_eckd_private *) device->private; |
| 369 | list_move(&device->alias_list, &lcu->inactive_devices); |
| 370 | group = private->pavgroup; |
| 371 | if (!group) |
| 372 | return; |
| 373 | private->pavgroup = NULL; |
| 374 | if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) { |
| 375 | list_del(&group->group); |
| 376 | kfree(group); |
| 377 | return; |
| 378 | } |
| 379 | if (group->next == device) |
| 380 | group->next = NULL; |
| 381 | }; |
| 382 | |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 383 | static int |
| 384 | suborder_not_supported(struct dasd_ccw_req *cqr) |
| 385 | { |
| 386 | char *sense; |
| 387 | char reason; |
| 388 | char msg_format; |
| 389 | char msg_no; |
| 390 | |
| 391 | sense = dasd_get_sense(&cqr->irb); |
| 392 | if (!sense) |
| 393 | return 0; |
| 394 | |
| 395 | reason = sense[0]; |
| 396 | msg_format = (sense[7] & 0xF0); |
| 397 | msg_no = (sense[7] & 0x0F); |
| 398 | |
| 399 | /* command reject, Format 0 MSG 4 - invalid parameter */ |
| 400 | if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04)) |
| 401 | return 1; |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 406 | /* |
| 407 | * This function tries to lock all devices on an lcu via trylock |
| 408 | * return NULL on success otherwise return first failed device |
| 409 | */ |
| 410 | static struct dasd_device *_trylock_all_devices_on_lcu(struct alias_lcu *lcu, |
| 411 | struct dasd_device *pos) |
| 412 | |
| 413 | { |
| 414 | struct alias_pav_group *pavgroup; |
| 415 | struct dasd_device *device; |
| 416 | |
| 417 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
| 418 | if (device == pos) |
| 419 | continue; |
| 420 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 421 | return device; |
| 422 | } |
| 423 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
| 424 | if (device == pos) |
| 425 | continue; |
| 426 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 427 | return device; |
| 428 | } |
| 429 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 430 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 431 | if (device == pos) |
| 432 | continue; |
| 433 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 434 | return device; |
| 435 | } |
| 436 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { |
| 437 | if (device == pos) |
| 438 | continue; |
| 439 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 440 | return device; |
| 441 | } |
| 442 | } |
| 443 | return NULL; |
| 444 | } |
| 445 | |
| 446 | /* |
| 447 | * unlock all devices except the one that is specified as pos |
| 448 | * stop if enddev is specified and reached |
| 449 | */ |
| 450 | static void _unlock_all_devices_on_lcu(struct alias_lcu *lcu, |
| 451 | struct dasd_device *pos, |
| 452 | struct dasd_device *enddev) |
| 453 | |
| 454 | { |
| 455 | struct alias_pav_group *pavgroup; |
| 456 | struct dasd_device *device; |
| 457 | |
| 458 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
| 459 | if (device == pos) |
| 460 | continue; |
| 461 | if (device == enddev) |
| 462 | return; |
| 463 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 464 | } |
| 465 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
| 466 | if (device == pos) |
| 467 | continue; |
| 468 | if (device == enddev) |
| 469 | return; |
| 470 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 471 | } |
| 472 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 473 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 474 | if (device == pos) |
| 475 | continue; |
| 476 | if (device == enddev) |
| 477 | return; |
| 478 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 479 | } |
| 480 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { |
| 481 | if (device == pos) |
| 482 | continue; |
| 483 | if (device == enddev) |
| 484 | return; |
| 485 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /* |
| 491 | * this function is needed because the locking order |
| 492 | * device lock -> lcu lock |
| 493 | * needs to be assured when iterating over devices in an LCU |
| 494 | * |
| 495 | * if a device is specified in pos then the device lock is already hold |
| 496 | */ |
| 497 | static void _trylock_and_lock_lcu_irqsave(struct alias_lcu *lcu, |
| 498 | struct dasd_device *pos, |
| 499 | unsigned long *flags) |
| 500 | { |
| 501 | struct dasd_device *failed; |
| 502 | |
| 503 | do { |
| 504 | spin_lock_irqsave(&lcu->lock, *flags); |
| 505 | failed = _trylock_all_devices_on_lcu(lcu, pos); |
| 506 | if (failed) { |
| 507 | _unlock_all_devices_on_lcu(lcu, pos, failed); |
| 508 | spin_unlock_irqrestore(&lcu->lock, *flags); |
| 509 | cpu_relax(); |
| 510 | } |
| 511 | } while (failed); |
| 512 | } |
| 513 | |
| 514 | static void _trylock_and_lock_lcu(struct alias_lcu *lcu, |
| 515 | struct dasd_device *pos) |
| 516 | { |
| 517 | struct dasd_device *failed; |
| 518 | |
| 519 | do { |
| 520 | spin_lock(&lcu->lock); |
| 521 | failed = _trylock_all_devices_on_lcu(lcu, pos); |
| 522 | if (failed) { |
| 523 | _unlock_all_devices_on_lcu(lcu, pos, failed); |
| 524 | spin_unlock(&lcu->lock); |
| 525 | cpu_relax(); |
| 526 | } |
| 527 | } while (failed); |
| 528 | } |
| 529 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 530 | static int read_unit_address_configuration(struct dasd_device *device, |
| 531 | struct alias_lcu *lcu) |
| 532 | { |
| 533 | struct dasd_psf_prssd_data *prssdp; |
| 534 | struct dasd_ccw_req *cqr; |
| 535 | struct ccw1 *ccw; |
| 536 | int rc; |
| 537 | unsigned long flags; |
| 538 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 539 | cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 540 | (sizeof(struct dasd_psf_prssd_data)), |
| 541 | device); |
| 542 | if (IS_ERR(cqr)) |
| 543 | return PTR_ERR(cqr); |
| 544 | cqr->startdev = device; |
| 545 | cqr->memdev = device; |
| 546 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 547 | cqr->retries = 10; |
| 548 | cqr->expires = 20 * HZ; |
| 549 | |
| 550 | /* Prepare for Read Subsystem Data */ |
| 551 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 552 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 553 | prssdp->order = PSF_ORDER_PRSSD; |
| 554 | prssdp->suborder = 0x0e; /* Read unit address configuration */ |
| 555 | /* all other bytes of prssdp must be zero */ |
| 556 | |
| 557 | ccw = cqr->cpaddr; |
| 558 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 559 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 560 | ccw->flags |= CCW_FLAG_CC; |
| 561 | ccw->cda = (__u32)(addr_t) prssdp; |
| 562 | |
| 563 | /* Read Subsystem Data - feature codes */ |
| 564 | memset(lcu->uac, 0, sizeof(*(lcu->uac))); |
| 565 | |
| 566 | ccw++; |
| 567 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 568 | ccw->count = sizeof(*(lcu->uac)); |
| 569 | ccw->cda = (__u32)(addr_t) lcu->uac; |
| 570 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 571 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 572 | cqr->status = DASD_CQR_FILLED; |
| 573 | |
| 574 | /* need to unset flag here to detect race with summary unit check */ |
| 575 | spin_lock_irqsave(&lcu->lock, flags); |
| 576 | lcu->flags &= ~NEED_UAC_UPDATE; |
| 577 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 578 | |
| 579 | do { |
| 580 | rc = dasd_sleep_on(cqr); |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 581 | if (rc && suborder_not_supported(cqr)) |
| 582 | return -EOPNOTSUPP; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 583 | } while (rc && (cqr->retries > 0)); |
| 584 | if (rc) { |
| 585 | spin_lock_irqsave(&lcu->lock, flags); |
| 586 | lcu->flags |= NEED_UAC_UPDATE; |
| 587 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 588 | } |
| 589 | dasd_kfree_request(cqr, cqr->memdev); |
| 590 | return rc; |
| 591 | } |
| 592 | |
| 593 | static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu) |
| 594 | { |
| 595 | unsigned long flags; |
| 596 | struct alias_pav_group *pavgroup, *tempgroup; |
| 597 | struct dasd_device *device, *tempdev; |
| 598 | int i, rc; |
| 599 | struct dasd_eckd_private *private; |
| 600 | |
| 601 | spin_lock_irqsave(&lcu->lock, flags); |
| 602 | list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) { |
| 603 | list_for_each_entry_safe(device, tempdev, &pavgroup->baselist, |
| 604 | alias_list) { |
| 605 | list_move(&device->alias_list, &lcu->active_devices); |
| 606 | private = (struct dasd_eckd_private *) device->private; |
| 607 | private->pavgroup = NULL; |
| 608 | } |
| 609 | list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist, |
| 610 | alias_list) { |
| 611 | list_move(&device->alias_list, &lcu->active_devices); |
| 612 | private = (struct dasd_eckd_private *) device->private; |
| 613 | private->pavgroup = NULL; |
| 614 | } |
| 615 | list_del(&pavgroup->group); |
| 616 | kfree(pavgroup); |
| 617 | } |
| 618 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 619 | |
| 620 | rc = read_unit_address_configuration(refdev, lcu); |
| 621 | if (rc) |
| 622 | return rc; |
| 623 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 624 | _trylock_and_lock_lcu_irqsave(lcu, NULL, &flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 625 | lcu->pav = NO_PAV; |
| 626 | for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) { |
| 627 | switch (lcu->uac->unit[i].ua_type) { |
| 628 | case UA_BASE_PAV_ALIAS: |
| 629 | lcu->pav = BASE_PAV; |
| 630 | break; |
| 631 | case UA_HYPER_PAV_ALIAS: |
| 632 | lcu->pav = HYPER_PAV; |
| 633 | break; |
| 634 | } |
| 635 | if (lcu->pav != NO_PAV) |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | list_for_each_entry_safe(device, tempdev, &lcu->active_devices, |
| 640 | alias_list) { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 641 | _add_device_to_lcu(lcu, device, refdev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 642 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 643 | _unlock_all_devices_on_lcu(lcu, NULL, NULL); |
| 644 | spin_unlock_irqrestore(&lcu->lock, flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static void lcu_update_work(struct work_struct *work) |
| 649 | { |
| 650 | struct alias_lcu *lcu; |
| 651 | struct read_uac_work_data *ruac_data; |
| 652 | struct dasd_device *device; |
| 653 | unsigned long flags; |
| 654 | int rc; |
| 655 | |
| 656 | ruac_data = container_of(work, struct read_uac_work_data, dwork.work); |
| 657 | lcu = container_of(ruac_data, struct alias_lcu, ruac_data); |
| 658 | device = ruac_data->device; |
| 659 | rc = _lcu_update(device, lcu); |
| 660 | /* |
| 661 | * Need to check flags again, as there could have been another |
| 662 | * prepare_update or a new device a new device while we were still |
| 663 | * processing the data |
| 664 | */ |
| 665 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 666 | if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 667 | DBF_DEV_EVENT(DBF_WARNING, device, "could not update" |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 668 | " alias data in lcu (rc = %d), retry later", rc); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 669 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ)) |
| 670 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 671 | } else { |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 672 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 673 | lcu->ruac_data.device = NULL; |
| 674 | lcu->flags &= ~UPDATE_PENDING; |
| 675 | } |
| 676 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 677 | } |
| 678 | |
| 679 | static int _schedule_lcu_update(struct alias_lcu *lcu, |
| 680 | struct dasd_device *device) |
| 681 | { |
| 682 | struct dasd_device *usedev = NULL; |
| 683 | struct alias_pav_group *group; |
| 684 | |
| 685 | lcu->flags |= NEED_UAC_UPDATE; |
| 686 | if (lcu->ruac_data.device) { |
| 687 | /* already scheduled or running */ |
| 688 | return 0; |
| 689 | } |
| 690 | if (device && !list_empty(&device->alias_list)) |
| 691 | usedev = device; |
| 692 | |
| 693 | if (!usedev && !list_empty(&lcu->grouplist)) { |
| 694 | group = list_first_entry(&lcu->grouplist, |
| 695 | struct alias_pav_group, group); |
| 696 | if (!list_empty(&group->baselist)) |
| 697 | usedev = list_first_entry(&group->baselist, |
| 698 | struct dasd_device, |
| 699 | alias_list); |
| 700 | else if (!list_empty(&group->aliaslist)) |
| 701 | usedev = list_first_entry(&group->aliaslist, |
| 702 | struct dasd_device, |
| 703 | alias_list); |
| 704 | } |
| 705 | if (!usedev && !list_empty(&lcu->active_devices)) { |
| 706 | usedev = list_first_entry(&lcu->active_devices, |
| 707 | struct dasd_device, alias_list); |
| 708 | } |
| 709 | /* |
| 710 | * if we haven't found a proper device yet, give up for now, the next |
| 711 | * device that will be set active will trigger an lcu update |
| 712 | */ |
| 713 | if (!usedev) |
| 714 | return -EINVAL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 715 | dasd_get_device(usedev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 716 | lcu->ruac_data.device = usedev; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 717 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0)) |
| 718 | dasd_put_device(usedev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | int dasd_alias_add_device(struct dasd_device *device) |
| 723 | { |
| 724 | struct dasd_eckd_private *private; |
| 725 | struct alias_lcu *lcu; |
| 726 | unsigned long flags; |
| 727 | int rc; |
| 728 | |
| 729 | private = (struct dasd_eckd_private *) device->private; |
| 730 | lcu = private->lcu; |
| 731 | rc = 0; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 732 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 733 | spin_lock(&lcu->lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 734 | if (!(lcu->flags & UPDATE_PENDING)) { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 735 | rc = _add_device_to_lcu(lcu, device, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 736 | if (rc) |
| 737 | lcu->flags |= UPDATE_PENDING; |
| 738 | } |
| 739 | if (lcu->flags & UPDATE_PENDING) { |
| 740 | list_move(&device->alias_list, &lcu->active_devices); |
| 741 | _schedule_lcu_update(lcu, device); |
| 742 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 743 | spin_unlock(&lcu->lock); |
| 744 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 745 | return rc; |
| 746 | } |
| 747 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 748 | int dasd_alias_update_add_device(struct dasd_device *device) |
| 749 | { |
| 750 | struct dasd_eckd_private *private; |
| 751 | private = (struct dasd_eckd_private *) device->private; |
| 752 | private->lcu->flags |= UPDATE_PENDING; |
| 753 | return dasd_alias_add_device(device); |
| 754 | } |
| 755 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 756 | int dasd_alias_remove_device(struct dasd_device *device) |
| 757 | { |
| 758 | struct dasd_eckd_private *private; |
| 759 | struct alias_lcu *lcu; |
| 760 | unsigned long flags; |
| 761 | |
| 762 | private = (struct dasd_eckd_private *) device->private; |
| 763 | lcu = private->lcu; |
Stefan Haberland | f602f6d6 | 2011-01-31 11:30:03 +0100 | [diff] [blame] | 764 | /* nothing to do if already removed */ |
| 765 | if (!lcu) |
| 766 | return 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 767 | spin_lock_irqsave(&lcu->lock, flags); |
| 768 | _remove_device_from_lcu(lcu, device); |
| 769 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device) |
| 774 | { |
| 775 | |
| 776 | struct dasd_device *alias_device; |
| 777 | struct alias_pav_group *group; |
| 778 | struct alias_lcu *lcu; |
| 779 | struct dasd_eckd_private *private, *alias_priv; |
| 780 | unsigned long flags; |
| 781 | |
| 782 | private = (struct dasd_eckd_private *) base_device->private; |
| 783 | group = private->pavgroup; |
| 784 | lcu = private->lcu; |
| 785 | if (!group || !lcu) |
| 786 | return NULL; |
| 787 | if (lcu->pav == NO_PAV || |
| 788 | lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING)) |
| 789 | return NULL; |
Stefan Haberland | b38f27e | 2011-12-27 11:27:28 +0100 | [diff] [blame] | 790 | if (unlikely(!(private->features.feature[8] & 0x01))) { |
| 791 | /* |
| 792 | * PAV enabled but prefix not, very unlikely |
| 793 | * seems to be a lost pathgroup |
| 794 | * use base device to do IO |
| 795 | */ |
| 796 | DBF_DEV_EVENT(DBF_ERR, base_device, "%s", |
| 797 | "Prefix not enabled with PAV enabled\n"); |
| 798 | return NULL; |
| 799 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 800 | |
| 801 | spin_lock_irqsave(&lcu->lock, flags); |
| 802 | alias_device = group->next; |
| 803 | if (!alias_device) { |
| 804 | if (list_empty(&group->aliaslist)) { |
| 805 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 806 | return NULL; |
| 807 | } else { |
| 808 | alias_device = list_first_entry(&group->aliaslist, |
| 809 | struct dasd_device, |
| 810 | alias_list); |
| 811 | } |
| 812 | } |
| 813 | if (list_is_last(&alias_device->alias_list, &group->aliaslist)) |
| 814 | group->next = list_first_entry(&group->aliaslist, |
| 815 | struct dasd_device, alias_list); |
| 816 | else |
| 817 | group->next = list_first_entry(&alias_device->alias_list, |
| 818 | struct dasd_device, alias_list); |
| 819 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 820 | alias_priv = (struct dasd_eckd_private *) alias_device->private; |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 821 | if ((alias_priv->count < private->count) && !alias_device->stopped && |
| 822 | !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 823 | return alias_device; |
| 824 | else |
| 825 | return NULL; |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * Summary unit check handling depends on the way alias devices |
| 830 | * are handled so it is done here rather then in dasd_eckd.c |
| 831 | */ |
| 832 | static int reset_summary_unit_check(struct alias_lcu *lcu, |
| 833 | struct dasd_device *device, |
| 834 | char reason) |
| 835 | { |
| 836 | struct dasd_ccw_req *cqr; |
| 837 | int rc = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 838 | struct ccw1 *ccw; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 839 | |
| 840 | cqr = lcu->rsu_cqr; |
| 841 | strncpy((char *) &cqr->magic, "ECKD", 4); |
| 842 | ASCEBC((char *) &cqr->magic, 4); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 843 | ccw = cqr->cpaddr; |
| 844 | ccw->cmd_code = DASD_ECKD_CCW_RSCK; |
Stefan Haberland | 020bf04 | 2015-12-15 10:16:43 +0100 | [diff] [blame] | 845 | ccw->flags = CCW_FLAG_SLI; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 846 | ccw->count = 16; |
| 847 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 848 | ((char *)cqr->data)[0] = reason; |
| 849 | |
| 850 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 851 | cqr->retries = 255; /* set retry counter to enable basic ERP */ |
| 852 | cqr->startdev = device; |
| 853 | cqr->memdev = device; |
| 854 | cqr->block = NULL; |
| 855 | cqr->expires = 5 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 856 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 857 | cqr->status = DASD_CQR_FILLED; |
| 858 | |
| 859 | rc = dasd_sleep_on_immediatly(cqr); |
| 860 | return rc; |
| 861 | } |
| 862 | |
| 863 | static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu) |
| 864 | { |
| 865 | struct alias_pav_group *pavgroup; |
| 866 | struct dasd_device *device; |
| 867 | struct dasd_eckd_private *private; |
| 868 | |
| 869 | /* active and inactive list can contain alias as well as base devices */ |
| 870 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
| 871 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 872 | if (private->uid.type != UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 873 | continue; |
| 874 | dasd_schedule_block_bh(device->block); |
| 875 | dasd_schedule_device_bh(device); |
| 876 | } |
| 877 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
| 878 | private = (struct dasd_eckd_private *) device->private; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 879 | if (private->uid.type != UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 880 | continue; |
| 881 | dasd_schedule_block_bh(device->block); |
| 882 | dasd_schedule_device_bh(device); |
| 883 | } |
| 884 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 885 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 886 | dasd_schedule_block_bh(device->block); |
| 887 | dasd_schedule_device_bh(device); |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu) |
| 893 | { |
| 894 | struct alias_pav_group *pavgroup; |
| 895 | struct dasd_device *device, *temp; |
| 896 | struct dasd_eckd_private *private; |
| 897 | int rc; |
| 898 | unsigned long flags; |
| 899 | LIST_HEAD(active); |
| 900 | |
| 901 | /* |
| 902 | * Problem here ist that dasd_flush_device_queue may wait |
| 903 | * for termination of a request to complete. We can't keep |
| 904 | * the lcu lock during that time, so we must assume that |
| 905 | * the lists may have changed. |
| 906 | * Idea: first gather all active alias devices in a separate list, |
| 907 | * then flush the first element of this list unlocked, and afterwards |
| 908 | * check if it is still on the list before moving it to the |
| 909 | * active_devices list. |
| 910 | */ |
| 911 | |
| 912 | spin_lock_irqsave(&lcu->lock, flags); |
| 913 | list_for_each_entry_safe(device, temp, &lcu->active_devices, |
| 914 | alias_list) { |
| 915 | private = (struct dasd_eckd_private *) device->private; |
| 916 | if (private->uid.type == UA_BASE_DEVICE) |
| 917 | continue; |
| 918 | list_move(&device->alias_list, &active); |
| 919 | } |
| 920 | |
| 921 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 922 | list_splice_init(&pavgroup->aliaslist, &active); |
| 923 | } |
| 924 | while (!list_empty(&active)) { |
| 925 | device = list_first_entry(&active, struct dasd_device, |
| 926 | alias_list); |
| 927 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 928 | rc = dasd_flush_device_queue(device); |
| 929 | spin_lock_irqsave(&lcu->lock, flags); |
| 930 | /* |
| 931 | * only move device around if it wasn't moved away while we |
| 932 | * were waiting for the flush |
| 933 | */ |
| 934 | if (device == list_first_entry(&active, |
Stefan Haberland | 6933c35 | 2015-10-14 11:01:05 +0200 | [diff] [blame] | 935 | struct dasd_device, alias_list)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 936 | list_move(&device->alias_list, &lcu->active_devices); |
Stefan Haberland | 6933c35 | 2015-10-14 11:01:05 +0200 | [diff] [blame] | 937 | private = (struct dasd_eckd_private *) device->private; |
| 938 | private->pavgroup = NULL; |
| 939 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 940 | } |
| 941 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 942 | } |
| 943 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 944 | static void _stop_all_devices_on_lcu(struct alias_lcu *lcu) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 945 | { |
| 946 | struct alias_pav_group *pavgroup; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 947 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 948 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 949 | list_for_each_entry(device, &lcu->active_devices, alias_list) |
| 950 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
| 951 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) |
| 952 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 953 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 954 | list_for_each_entry(device, &pavgroup->baselist, alias_list) |
| 955 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
| 956 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) |
| 957 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu) |
| 962 | { |
| 963 | struct alias_pav_group *pavgroup; |
| 964 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 965 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 966 | list_for_each_entry(device, &lcu->active_devices, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 967 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 968 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 969 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 970 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 971 | list_for_each_entry(device, &pavgroup->baselist, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 972 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 973 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 974 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | static void summary_unit_check_handling_work(struct work_struct *work) |
| 979 | { |
| 980 | struct alias_lcu *lcu; |
| 981 | struct summary_unit_check_work_data *suc_data; |
| 982 | unsigned long flags; |
| 983 | struct dasd_device *device; |
| 984 | |
| 985 | suc_data = container_of(work, struct summary_unit_check_work_data, |
| 986 | worker); |
| 987 | lcu = container_of(suc_data, struct alias_lcu, suc_data); |
| 988 | device = suc_data->device; |
| 989 | |
| 990 | /* 1. flush alias devices */ |
| 991 | flush_all_alias_devices_on_lcu(lcu); |
| 992 | |
| 993 | /* 2. reset summary unit check */ |
| 994 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 995 | dasd_device_remove_stop_bits(device, |
| 996 | (DASD_STOPPED_SU | DASD_STOPPED_PENDING)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 997 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 998 | reset_summary_unit_check(lcu, device, suc_data->reason); |
| 999 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1000 | _trylock_and_lock_lcu_irqsave(lcu, NULL, &flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1001 | _unstop_all_devices_on_lcu(lcu); |
| 1002 | _restart_all_base_devices_on_lcu(lcu); |
| 1003 | /* 3. read new alias configuration */ |
| 1004 | _schedule_lcu_update(lcu, device); |
| 1005 | lcu->suc_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 1006 | dasd_put_device(device); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1007 | _unlock_all_devices_on_lcu(lcu, NULL, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1008 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * note: this will be called from int handler context (cdev locked) |
| 1013 | */ |
| 1014 | void dasd_alias_handle_summary_unit_check(struct dasd_device *device, |
| 1015 | struct irb *irb) |
| 1016 | { |
| 1017 | struct alias_lcu *lcu; |
| 1018 | char reason; |
| 1019 | struct dasd_eckd_private *private; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1020 | char *sense; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1021 | |
| 1022 | private = (struct dasd_eckd_private *) device->private; |
| 1023 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1024 | sense = dasd_get_sense(irb); |
| 1025 | if (sense) { |
| 1026 | reason = sense[8]; |
| 1027 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x", |
| 1028 | "eckd handle summary unit check: reason", reason); |
| 1029 | } else { |
| 1030 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 1031 | "eckd handle summary unit check:" |
| 1032 | " no reason code available"); |
| 1033 | return; |
| 1034 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1035 | |
| 1036 | lcu = private->lcu; |
| 1037 | if (!lcu) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1038 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1039 | "device not ready to handle summary" |
| 1040 | " unit check (no lcu structure)"); |
| 1041 | return; |
| 1042 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1043 | _trylock_and_lock_lcu(lcu, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1044 | /* If this device is about to be removed just return and wait for |
| 1045 | * the next interrupt on a different device |
| 1046 | */ |
| 1047 | if (list_empty(&device->alias_list)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1048 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1049 | "device is in offline processing," |
| 1050 | " don't do summary unit check handling"); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1051 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1052 | spin_unlock(&lcu->lock); |
| 1053 | return; |
| 1054 | } |
| 1055 | if (lcu->suc_data.device) { |
| 1056 | /* already scheduled or running */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1057 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1058 | "previous instance of summary unit check worker" |
| 1059 | " still pending"); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1060 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1061 | spin_unlock(&lcu->lock); |
| 1062 | return ; |
| 1063 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1064 | _stop_all_devices_on_lcu(lcu); |
| 1065 | /* prepare for lcu_update */ |
| 1066 | private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1067 | lcu->suc_data.reason = reason; |
| 1068 | lcu->suc_data.device = device; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 1069 | dasd_get_device(device); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame^] | 1070 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1071 | spin_unlock(&lcu->lock); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 1072 | if (!schedule_work(&lcu->suc_data.worker)) |
| 1073 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1074 | }; |