1 // SPDX-License-Identifier: GPL-2.0
3 * PAV alias management for the DASD ECKD discipline
5 * Copyright IBM Corp. 2007
6 * Author(s): Stefan Weinhuber <wein@de.ibm.com>
9 #include <linux/list.h>
10 #include <linux/slab.h>
11 #include <asm/ebcdic.h>
13 #include "dasd_eckd.h"
16 * General concept of alias management:
17 * - PAV and DASD alias management is specific to the eckd discipline.
18 * - A device is connected to an lcu as long as the device exists.
19 * dasd_alias_make_device_known_to_lcu will be called wenn the
20 * device is checked by the eckd discipline and
21 * dasd_alias_disconnect_device_from_lcu will be called
22 * before the device is deleted.
23 * - The dasd_alias_add_device / dasd_alias_remove_device
24 * functions mark the point when a device is 'ready for service'.
25 * - A summary unit check is a rare occasion, but it is mandatory to
26 * support it. It requires some complex recovery actions before the
27 * devices can be used again (see dasd_alias_handle_summary_unit_check).
28 * - dasd_alias_get_start_dev will find an alias device that can be used
29 * instead of the base device and does some (very simple) load balancing.
30 * This is the function that gets called for each I/O, so when improving
31 * something, this function should get faster or better, the rest has just
36 static void summary_unit_check_handling_work(struct work_struct *);
37 static void lcu_update_work(struct work_struct *);
38 static int _schedule_lcu_update(struct alias_lcu *, struct dasd_device *);
40 static struct alias_root aliastree = {
41 .serverlist = LIST_HEAD_INIT(aliastree.serverlist),
42 .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock),
45 static struct alias_server *_find_server(struct dasd_uid *uid)
47 struct alias_server *pos;
48 list_for_each_entry(pos, &aliastree.serverlist, server) {
49 if (!strncmp(pos->uid.vendor, uid->vendor,
51 && !strncmp(pos->uid.serial, uid->serial,
58 static struct alias_lcu *_find_lcu(struct alias_server *server,
61 struct alias_lcu *pos;
62 list_for_each_entry(pos, &server->lculist, lcu) {
63 if (pos->uid.ssid == uid->ssid)
69 static struct alias_pav_group *_find_group(struct alias_lcu *lcu,
72 struct alias_pav_group *pos;
73 __u8 search_unit_addr;
75 /* for hyper pav there is only one group */
76 if (lcu->pav == HYPER_PAV) {
77 if (list_empty(&lcu->grouplist))
80 return list_first_entry(&lcu->grouplist,
81 struct alias_pav_group, group);
84 /* for base pav we have to find the group that matches the base */
85 if (uid->type == UA_BASE_DEVICE)
86 search_unit_addr = uid->real_unit_addr;
88 search_unit_addr = uid->base_unit_addr;
89 list_for_each_entry(pos, &lcu->grouplist, group) {
90 if (pos->uid.base_unit_addr == search_unit_addr &&
91 !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit)))
97 static struct alias_server *_allocate_server(struct dasd_uid *uid)
99 struct alias_server *server;
101 server = kzalloc(sizeof(*server), GFP_KERNEL);
103 return ERR_PTR(-ENOMEM);
104 memcpy(server->uid.vendor, uid->vendor, sizeof(uid->vendor));
105 memcpy(server->uid.serial, uid->serial, sizeof(uid->serial));
106 INIT_LIST_HEAD(&server->server);
107 INIT_LIST_HEAD(&server->lculist);
111 static void _free_server(struct alias_server *server)
116 static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid)
118 struct alias_lcu *lcu;
120 lcu = kzalloc(sizeof(*lcu), GFP_KERNEL);
122 return ERR_PTR(-ENOMEM);
123 lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA);
126 lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA);
129 lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1),
130 GFP_KERNEL | GFP_DMA);
131 if (!lcu->rsu_cqr->cpaddr)
133 lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA);
134 if (!lcu->rsu_cqr->data)
137 memcpy(lcu->uid.vendor, uid->vendor, sizeof(uid->vendor));
138 memcpy(lcu->uid.serial, uid->serial, sizeof(uid->serial));
139 lcu->uid.ssid = uid->ssid;
141 lcu->flags = NEED_UAC_UPDATE | UPDATE_PENDING;
142 INIT_LIST_HEAD(&lcu->lcu);
143 INIT_LIST_HEAD(&lcu->inactive_devices);
144 INIT_LIST_HEAD(&lcu->active_devices);
145 INIT_LIST_HEAD(&lcu->grouplist);
146 INIT_WORK(&lcu->suc_data.worker, summary_unit_check_handling_work);
147 INIT_DELAYED_WORK(&lcu->ruac_data.dwork, lcu_update_work);
148 spin_lock_init(&lcu->lock);
149 init_completion(&lcu->lcu_setup);
153 kfree(lcu->rsu_cqr->cpaddr);
160 return ERR_PTR(-ENOMEM);
163 static void _free_lcu(struct alias_lcu *lcu)
165 kfree(lcu->rsu_cqr->data);
166 kfree(lcu->rsu_cqr->cpaddr);
173 * This is the function that will allocate all the server and lcu data,
174 * so this function must be called first for a new device.
175 * If the return value is 1, the lcu was already known before, if it
176 * is 0, this is a new lcu.
177 * Negative return code indicates that something went wrong (e.g. -ENOMEM)
179 int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
181 struct dasd_eckd_private *private = device->private;
183 struct alias_server *server, *newserver;
184 struct alias_lcu *lcu, *newlcu;
187 device->discipline->get_uid(device, &uid);
188 spin_lock_irqsave(&aliastree.lock, flags);
189 server = _find_server(&uid);
191 spin_unlock_irqrestore(&aliastree.lock, flags);
192 newserver = _allocate_server(&uid);
193 if (IS_ERR(newserver))
194 return PTR_ERR(newserver);
195 spin_lock_irqsave(&aliastree.lock, flags);
196 server = _find_server(&uid);
198 list_add(&newserver->server, &aliastree.serverlist);
201 /* someone was faster */
202 _free_server(newserver);
206 lcu = _find_lcu(server, &uid);
208 spin_unlock_irqrestore(&aliastree.lock, flags);
209 newlcu = _allocate_lcu(&uid);
211 return PTR_ERR(newlcu);
212 spin_lock_irqsave(&aliastree.lock, flags);
213 lcu = _find_lcu(server, &uid);
215 list_add(&newlcu->lcu, &server->lculist);
218 /* someone was faster */
222 spin_lock(&lcu->lock);
223 list_add(&device->alias_list, &lcu->inactive_devices);
225 spin_unlock(&lcu->lock);
226 spin_unlock_irqrestore(&aliastree.lock, flags);
232 * This function removes a device from the scope of alias management.
233 * The complicated part is to make sure that it is not in use by
234 * any of the workers. If necessary cancel the work.
236 void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
238 struct dasd_eckd_private *private = device->private;
240 struct alias_lcu *lcu;
241 struct alias_server *server;
246 /* nothing to do if already disconnected */
249 device->discipline->get_uid(device, &uid);
250 spin_lock_irqsave(&lcu->lock, flags);
251 /* make sure that the workers don't use this device */
252 if (device == lcu->suc_data.device) {
253 spin_unlock_irqrestore(&lcu->lock, flags);
254 cancel_work_sync(&lcu->suc_data.worker);
255 spin_lock_irqsave(&lcu->lock, flags);
256 if (device == lcu->suc_data.device) {
257 dasd_put_device(device);
258 lcu->suc_data.device = NULL;
262 if (device == lcu->ruac_data.device) {
263 spin_unlock_irqrestore(&lcu->lock, flags);
265 cancel_delayed_work_sync(&lcu->ruac_data.dwork);
266 spin_lock_irqsave(&lcu->lock, flags);
267 if (device == lcu->ruac_data.device) {
268 dasd_put_device(device);
269 lcu->ruac_data.device = NULL;
273 spin_unlock_irqrestore(&lcu->lock, flags);
275 spin_lock_irqsave(&aliastree.lock, flags);
276 spin_lock(&lcu->lock);
277 list_del_init(&device->alias_list);
278 if (list_empty(&lcu->grouplist) &&
279 list_empty(&lcu->active_devices) &&
280 list_empty(&lcu->inactive_devices)) {
282 spin_unlock(&lcu->lock);
287 _schedule_lcu_update(lcu, NULL);
288 spin_unlock(&lcu->lock);
290 server = _find_server(&uid);
291 if (server && list_empty(&server->lculist)) {
292 list_del(&server->server);
293 _free_server(server);
295 spin_unlock_irqrestore(&aliastree.lock, flags);
299 * This function assumes that the unit address configuration stored
300 * in the lcu is up to date and will update the device uid before
301 * adding it to a pav group.
304 static int _add_device_to_lcu(struct alias_lcu *lcu,
305 struct dasd_device *device,
306 struct dasd_device *pos)
309 struct dasd_eckd_private *private = device->private;
310 struct alias_pav_group *group;
313 spin_lock(get_ccwdev_lock(device->cdev));
314 private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
315 private->uid.base_unit_addr =
316 lcu->uac->unit[private->uid.real_unit_addr].base_ua;
318 spin_unlock(get_ccwdev_lock(device->cdev));
319 /* if we have no PAV anyway, we don't need to bother with PAV groups */
320 if (lcu->pav == NO_PAV) {
321 list_move(&device->alias_list, &lcu->active_devices);
324 group = _find_group(lcu, &uid);
326 group = kzalloc(sizeof(*group), GFP_ATOMIC);
329 memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
330 memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
331 group->uid.ssid = uid.ssid;
332 if (uid.type == UA_BASE_DEVICE)
333 group->uid.base_unit_addr = uid.real_unit_addr;
335 group->uid.base_unit_addr = uid.base_unit_addr;
336 memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
337 INIT_LIST_HEAD(&group->group);
338 INIT_LIST_HEAD(&group->baselist);
339 INIT_LIST_HEAD(&group->aliaslist);
340 list_add(&group->group, &lcu->grouplist);
342 if (uid.type == UA_BASE_DEVICE)
343 list_move(&device->alias_list, &group->baselist);
345 list_move(&device->alias_list, &group->aliaslist);
346 private->pavgroup = group;
350 static void _remove_device_from_lcu(struct alias_lcu *lcu,
351 struct dasd_device *device)
353 struct dasd_eckd_private *private = device->private;
354 struct alias_pav_group *group;
356 list_move(&device->alias_list, &lcu->inactive_devices);
357 group = private->pavgroup;
360 private->pavgroup = NULL;
361 if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
362 list_del(&group->group);
366 if (group->next == device)
371 suborder_not_supported(struct dasd_ccw_req *cqr)
379 * intrc values ENODEV, ENOLINK and EPERM
380 * will be optained from sleep_on to indicate that no
381 * IO operation can be started
383 if (cqr->intrc == -ENODEV)
386 if (cqr->intrc == -ENOLINK)
389 if (cqr->intrc == -EPERM)
392 sense = dasd_get_sense(&cqr->irb);
397 msg_format = (sense[7] & 0xF0);
398 msg_no = (sense[7] & 0x0F);
400 /* command reject, Format 0 MSG 4 - invalid parameter */
401 if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04))
407 static int read_unit_address_configuration(struct dasd_device *device,
408 struct alias_lcu *lcu)
410 struct dasd_psf_prssd_data *prssdp;
411 struct dasd_ccw_req *cqr;
416 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
417 (sizeof(struct dasd_psf_prssd_data)),
421 cqr->startdev = device;
422 cqr->memdev = device;
423 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
425 cqr->expires = 20 * HZ;
427 /* Prepare for Read Subsystem Data */
428 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
429 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
430 prssdp->order = PSF_ORDER_PRSSD;
431 prssdp->suborder = 0x0e; /* Read unit address configuration */
432 /* all other bytes of prssdp must be zero */
435 ccw->cmd_code = DASD_ECKD_CCW_PSF;
436 ccw->count = sizeof(struct dasd_psf_prssd_data);
437 ccw->flags |= CCW_FLAG_CC;
438 ccw->cda = (__u32)virt_to_phys(prssdp);
440 /* Read Subsystem Data - feature codes */
441 memset(lcu->uac, 0, sizeof(*(lcu->uac)));
444 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
445 ccw->count = sizeof(*(lcu->uac));
446 ccw->cda = (__u32)virt_to_phys(lcu->uac);
448 cqr->buildclk = get_tod_clock();
449 cqr->status = DASD_CQR_FILLED;
451 /* need to unset flag here to detect race with summary unit check */
452 spin_lock_irqsave(&lcu->lock, flags);
453 lcu->flags &= ~NEED_UAC_UPDATE;
454 spin_unlock_irqrestore(&lcu->lock, flags);
456 rc = dasd_sleep_on(cqr);
460 if (suborder_not_supported(cqr)) {
461 /* suborder not supported or device unusable for IO */
464 /* IO failed but should be retried */
465 spin_lock_irqsave(&lcu->lock, flags);
466 lcu->flags |= NEED_UAC_UPDATE;
467 spin_unlock_irqrestore(&lcu->lock, flags);
470 dasd_sfree_request(cqr, cqr->memdev);
474 static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
477 struct alias_pav_group *pavgroup, *tempgroup;
478 struct dasd_device *device, *tempdev;
480 struct dasd_eckd_private *private;
482 spin_lock_irqsave(&lcu->lock, flags);
483 list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
484 list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
486 list_move(&device->alias_list, &lcu->active_devices);
487 private = device->private;
488 private->pavgroup = NULL;
490 list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
492 list_move(&device->alias_list, &lcu->active_devices);
493 private = device->private;
494 private->pavgroup = NULL;
496 list_del(&pavgroup->group);
499 spin_unlock_irqrestore(&lcu->lock, flags);
501 rc = read_unit_address_configuration(refdev, lcu);
505 spin_lock_irqsave(&lcu->lock, flags);
507 * there is another update needed skip the remaining handling
508 * the data might already be outdated
509 * but especially do not add the device to an LCU with pending
512 if (lcu->flags & NEED_UAC_UPDATE)
515 for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
516 switch (lcu->uac->unit[i].ua_type) {
517 case UA_BASE_PAV_ALIAS:
520 case UA_HYPER_PAV_ALIAS:
521 lcu->pav = HYPER_PAV;
524 if (lcu->pav != NO_PAV)
528 list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
530 _add_device_to_lcu(lcu, device, refdev);
533 spin_unlock_irqrestore(&lcu->lock, flags);
537 static void lcu_update_work(struct work_struct *work)
539 struct alias_lcu *lcu;
540 struct read_uac_work_data *ruac_data;
541 struct dasd_device *device;
545 ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
546 lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
547 device = ruac_data->device;
548 rc = _lcu_update(device, lcu);
550 * Need to check flags again, as there could have been another
551 * prepare_update or a new device a new device while we were still
552 * processing the data
554 spin_lock_irqsave(&lcu->lock, flags);
555 if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) {
556 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
557 " alias data in lcu (rc = %d), retry later", rc);
558 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ))
559 dasd_put_device(device);
561 dasd_put_device(device);
562 lcu->ruac_data.device = NULL;
563 lcu->flags &= ~UPDATE_PENDING;
565 spin_unlock_irqrestore(&lcu->lock, flags);
568 static int _schedule_lcu_update(struct alias_lcu *lcu,
569 struct dasd_device *device)
571 struct dasd_device *usedev = NULL;
572 struct alias_pav_group *group;
574 lcu->flags |= NEED_UAC_UPDATE;
575 if (lcu->ruac_data.device) {
576 /* already scheduled or running */
579 if (device && !list_empty(&device->alias_list))
582 if (!usedev && !list_empty(&lcu->grouplist)) {
583 group = list_first_entry(&lcu->grouplist,
584 struct alias_pav_group, group);
585 if (!list_empty(&group->baselist))
586 usedev = list_first_entry(&group->baselist,
589 else if (!list_empty(&group->aliaslist))
590 usedev = list_first_entry(&group->aliaslist,
594 if (!usedev && !list_empty(&lcu->active_devices)) {
595 usedev = list_first_entry(&lcu->active_devices,
596 struct dasd_device, alias_list);
599 * if we haven't found a proper device yet, give up for now, the next
600 * device that will be set active will trigger an lcu update
604 dasd_get_device(usedev);
605 lcu->ruac_data.device = usedev;
606 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0))
607 dasd_put_device(usedev);
611 int dasd_alias_add_device(struct dasd_device *device)
613 struct dasd_eckd_private *private = device->private;
614 __u8 uaddr = private->uid.real_unit_addr;
615 struct alias_lcu *lcu = private->lcu;
620 spin_lock_irqsave(&lcu->lock, flags);
622 * Check if device and lcu type differ. If so, the uac data may be
623 * outdated and needs to be updated.
625 if (private->uid.type != lcu->uac->unit[uaddr].ua_type) {
626 lcu->flags |= UPDATE_PENDING;
627 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
628 "uid type mismatch - trigger rescan");
630 if (!(lcu->flags & UPDATE_PENDING)) {
631 rc = _add_device_to_lcu(lcu, device, device);
633 lcu->flags |= UPDATE_PENDING;
635 if (lcu->flags & UPDATE_PENDING) {
636 list_move(&device->alias_list, &lcu->active_devices);
637 private->pavgroup = NULL;
638 _schedule_lcu_update(lcu, device);
640 spin_unlock_irqrestore(&lcu->lock, flags);
644 int dasd_alias_update_add_device(struct dasd_device *device)
646 struct dasd_eckd_private *private = device->private;
648 private->lcu->flags |= UPDATE_PENDING;
649 return dasd_alias_add_device(device);
652 int dasd_alias_remove_device(struct dasd_device *device)
654 struct dasd_eckd_private *private = device->private;
655 struct alias_lcu *lcu = private->lcu;
658 /* nothing to do if already removed */
661 spin_lock_irqsave(&lcu->lock, flags);
662 _remove_device_from_lcu(lcu, device);
663 spin_unlock_irqrestore(&lcu->lock, flags);
667 struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
669 struct dasd_eckd_private *alias_priv, *private = base_device->private;
670 struct alias_lcu *lcu = private->lcu;
671 struct dasd_device *alias_device;
672 struct alias_pav_group *group;
677 if (lcu->pav == NO_PAV ||
678 lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
680 if (unlikely(!(private->features.feature[8] & 0x01))) {
682 * PAV enabled but prefix not, very unlikely
683 * seems to be a lost pathgroup
684 * use base device to do IO
686 DBF_DEV_EVENT(DBF_ERR, base_device, "%s",
687 "Prefix not enabled with PAV enabled\n");
691 spin_lock_irqsave(&lcu->lock, flags);
692 group = private->pavgroup;
694 spin_unlock_irqrestore(&lcu->lock, flags);
697 alias_device = group->next;
699 if (list_empty(&group->aliaslist)) {
700 spin_unlock_irqrestore(&lcu->lock, flags);
703 alias_device = list_first_entry(&group->aliaslist,
708 if (list_is_last(&alias_device->alias_list, &group->aliaslist))
709 group->next = list_first_entry(&group->aliaslist,
710 struct dasd_device, alias_list);
712 group->next = list_first_entry(&alias_device->alias_list,
713 struct dasd_device, alias_list);
714 spin_unlock_irqrestore(&lcu->lock, flags);
715 alias_priv = alias_device->private;
716 if ((alias_priv->count < private->count) && !alias_device->stopped &&
717 !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags))
724 * Summary unit check handling depends on the way alias devices
725 * are handled so it is done here rather then in dasd_eckd.c
727 static int reset_summary_unit_check(struct alias_lcu *lcu,
728 struct dasd_device *device,
731 struct dasd_ccw_req *cqr;
736 memcpy((char *) &cqr->magic, "ECKD", 4);
737 ASCEBC((char *) &cqr->magic, 4);
739 ccw->cmd_code = DASD_ECKD_CCW_RSCK;
740 ccw->flags = CCW_FLAG_SLI;
742 ccw->cda = (__u32)virt_to_phys(cqr->data);
743 ((char *)cqr->data)[0] = reason;
745 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
746 cqr->retries = 255; /* set retry counter to enable basic ERP */
747 cqr->startdev = device;
748 cqr->memdev = device;
750 cqr->expires = 5 * HZ;
751 cqr->buildclk = get_tod_clock();
752 cqr->status = DASD_CQR_FILLED;
754 rc = dasd_sleep_on_immediatly(cqr);
758 static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
760 struct alias_pav_group *pavgroup;
761 struct dasd_device *device;
762 struct dasd_eckd_private *private;
764 /* active and inactive list can contain alias as well as base devices */
765 list_for_each_entry(device, &lcu->active_devices, alias_list) {
766 private = device->private;
767 if (private->uid.type != UA_BASE_DEVICE)
769 dasd_schedule_block_bh(device->block);
770 dasd_schedule_device_bh(device);
772 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
773 private = device->private;
774 if (private->uid.type != UA_BASE_DEVICE)
776 dasd_schedule_block_bh(device->block);
777 dasd_schedule_device_bh(device);
779 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
780 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
781 dasd_schedule_block_bh(device->block);
782 dasd_schedule_device_bh(device);
787 static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
789 struct alias_pav_group *pavgroup;
790 struct dasd_device *device, *temp;
791 struct dasd_eckd_private *private;
796 * Problem here ist that dasd_flush_device_queue may wait
797 * for termination of a request to complete. We can't keep
798 * the lcu lock during that time, so we must assume that
799 * the lists may have changed.
800 * Idea: first gather all active alias devices in a separate list,
801 * then flush the first element of this list unlocked, and afterwards
802 * check if it is still on the list before moving it to the
803 * active_devices list.
806 spin_lock_irqsave(&lcu->lock, flags);
807 list_for_each_entry_safe(device, temp, &lcu->active_devices,
809 private = device->private;
810 if (private->uid.type == UA_BASE_DEVICE)
812 list_move(&device->alias_list, &active);
815 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
816 list_splice_init(&pavgroup->aliaslist, &active);
818 while (!list_empty(&active)) {
819 device = list_first_entry(&active, struct dasd_device,
821 spin_unlock_irqrestore(&lcu->lock, flags);
822 dasd_flush_device_queue(device);
823 spin_lock_irqsave(&lcu->lock, flags);
825 * only move device around if it wasn't moved away while we
826 * were waiting for the flush
828 if (device == list_first_entry(&active,
829 struct dasd_device, alias_list)) {
830 list_move(&device->alias_list, &lcu->active_devices);
831 private = device->private;
832 private->pavgroup = NULL;
835 spin_unlock_irqrestore(&lcu->lock, flags);
838 static void _stop_all_devices_on_lcu(struct alias_lcu *lcu)
840 struct alias_pav_group *pavgroup;
841 struct dasd_device *device;
843 list_for_each_entry(device, &lcu->active_devices, alias_list) {
844 spin_lock(get_ccwdev_lock(device->cdev));
845 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
846 spin_unlock(get_ccwdev_lock(device->cdev));
848 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
849 spin_lock(get_ccwdev_lock(device->cdev));
850 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
851 spin_unlock(get_ccwdev_lock(device->cdev));
853 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
854 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
855 spin_lock(get_ccwdev_lock(device->cdev));
856 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
857 spin_unlock(get_ccwdev_lock(device->cdev));
859 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
860 spin_lock(get_ccwdev_lock(device->cdev));
861 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
862 spin_unlock(get_ccwdev_lock(device->cdev));
867 static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
869 struct alias_pav_group *pavgroup;
870 struct dasd_device *device;
872 list_for_each_entry(device, &lcu->active_devices, alias_list) {
873 spin_lock(get_ccwdev_lock(device->cdev));
874 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
875 spin_unlock(get_ccwdev_lock(device->cdev));
877 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
878 spin_lock(get_ccwdev_lock(device->cdev));
879 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
880 spin_unlock(get_ccwdev_lock(device->cdev));
882 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
883 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
884 spin_lock(get_ccwdev_lock(device->cdev));
885 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
886 spin_unlock(get_ccwdev_lock(device->cdev));
888 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
889 spin_lock(get_ccwdev_lock(device->cdev));
890 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
891 spin_unlock(get_ccwdev_lock(device->cdev));
896 static void summary_unit_check_handling_work(struct work_struct *work)
898 struct alias_lcu *lcu;
899 struct summary_unit_check_work_data *suc_data;
901 struct dasd_device *device;
903 suc_data = container_of(work, struct summary_unit_check_work_data,
905 lcu = container_of(suc_data, struct alias_lcu, suc_data);
906 device = suc_data->device;
908 /* 1. flush alias devices */
909 flush_all_alias_devices_on_lcu(lcu);
911 /* 2. reset summary unit check */
912 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
913 dasd_device_remove_stop_bits(device,
914 (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
915 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
916 reset_summary_unit_check(lcu, device, suc_data->reason);
918 spin_lock_irqsave(&lcu->lock, flags);
919 _unstop_all_devices_on_lcu(lcu);
920 _restart_all_base_devices_on_lcu(lcu);
921 /* 3. read new alias configuration */
922 _schedule_lcu_update(lcu, device);
923 lcu->suc_data.device = NULL;
924 dasd_put_device(device);
925 spin_unlock_irqrestore(&lcu->lock, flags);
928 void dasd_alias_handle_summary_unit_check(struct work_struct *work)
930 struct dasd_device *device = container_of(work, struct dasd_device,
932 struct dasd_eckd_private *private = device->private;
933 struct alias_lcu *lcu;
938 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
939 "device not ready to handle summary"
940 " unit check (no lcu structure)");
943 spin_lock_irqsave(&lcu->lock, flags);
944 /* If this device is about to be removed just return and wait for
945 * the next interrupt on a different device
947 if (list_empty(&device->alias_list)) {
948 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
949 "device is in offline processing,"
950 " don't do summary unit check handling");
953 if (lcu->suc_data.device) {
954 /* already scheduled or running */
955 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
956 "previous instance of summary unit check worker"
960 _stop_all_devices_on_lcu(lcu);
961 /* prepare for lcu_update */
962 lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
963 lcu->suc_data.reason = private->suc_reason;
964 lcu->suc_data.device = device;
965 dasd_get_device(device);
966 if (!schedule_work(&lcu->suc_data.worker))
967 dasd_put_device(device);
969 spin_unlock_irqrestore(&lcu->lock, flags);
971 clear_bit(DASD_FLAG_SUC, &device->flags);
972 dasd_put_device(device);