2 * PAV alias management for the DASD ECKD discipline
4 * Copyright IBM Corporation, 2007
5 * Author(s): Stefan Weinhuber <wein@de.ibm.com>
8 #define KMSG_COMPONENT "dasd-eckd"
10 #include <linux/list.h>
11 #include <linux/slab.h>
12 #include <asm/ebcdic.h>
14 #include "dasd_eckd.h"
18 #endif /* PRINTK_HEADER */
19 #define PRINTK_HEADER "dasd(eckd):"
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
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 *);
47 static struct alias_root aliastree = {
48 .serverlist = LIST_HEAD_INIT(aliastree.serverlist),
49 .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock),
52 static struct alias_server *_find_server(struct dasd_uid *uid)
54 struct alias_server *pos;
55 list_for_each_entry(pos, &aliastree.serverlist, server) {
56 if (!strncmp(pos->uid.vendor, uid->vendor,
58 && !strncmp(pos->uid.serial, uid->serial,
65 static struct alias_lcu *_find_lcu(struct alias_server *server,
68 struct alias_lcu *pos;
69 list_for_each_entry(pos, &server->lculist, lcu) {
70 if (pos->uid.ssid == uid->ssid)
76 static struct alias_pav_group *_find_group(struct alias_lcu *lcu,
79 struct alias_pav_group *pos;
80 __u8 search_unit_addr;
82 /* for hyper pav there is only one group */
83 if (lcu->pav == HYPER_PAV) {
84 if (list_empty(&lcu->grouplist))
87 return list_first_entry(&lcu->grouplist,
88 struct alias_pav_group, group);
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;
95 search_unit_addr = uid->base_unit_addr;
96 list_for_each_entry(pos, &lcu->grouplist, group) {
97 if (pos->uid.base_unit_addr == search_unit_addr &&
98 !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit)))
104 static struct alias_server *_allocate_server(struct dasd_uid *uid)
106 struct alias_server *server;
108 server = kzalloc(sizeof(*server), GFP_KERNEL);
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);
118 static void _free_server(struct alias_server *server)
123 static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid)
125 struct alias_lcu *lcu;
127 lcu = kzalloc(sizeof(*lcu), GFP_KERNEL);
129 return ERR_PTR(-ENOMEM);
130 lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA);
133 lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA);
136 lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1),
137 GFP_KERNEL | GFP_DMA);
138 if (!lcu->rsu_cqr->cpaddr)
140 lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA);
141 if (!lcu->rsu_cqr->data)
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;
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);
156 init_completion(&lcu->lcu_setup);
160 kfree(lcu->rsu_cqr->cpaddr);
167 return ERR_PTR(-ENOMEM);
170 static void _free_lcu(struct alias_lcu *lcu)
172 kfree(lcu->rsu_cqr->data);
173 kfree(lcu->rsu_cqr->cpaddr);
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)
186 int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
188 struct dasd_eckd_private *private;
190 struct alias_server *server, *newserver;
191 struct alias_lcu *lcu, *newlcu;
193 struct dasd_uid *uid;
195 private = (struct dasd_eckd_private *) device->private;
197 spin_lock_irqsave(&aliastree.lock, flags);
199 server = _find_server(uid);
201 spin_unlock_irqrestore(&aliastree.lock, flags);
202 newserver = _allocate_server(uid);
203 if (IS_ERR(newserver))
204 return PTR_ERR(newserver);
205 spin_lock_irqsave(&aliastree.lock, flags);
206 server = _find_server(uid);
208 list_add(&newserver->server, &aliastree.serverlist);
212 /* someone was faster */
213 _free_server(newserver);
217 lcu = _find_lcu(server, uid);
219 spin_unlock_irqrestore(&aliastree.lock, flags);
220 newlcu = _allocate_lcu(uid);
222 return PTR_ERR(newlcu);
223 spin_lock_irqsave(&aliastree.lock, flags);
224 lcu = _find_lcu(server, uid);
226 list_add(&newlcu->lcu, &server->lculist);
230 /* someone was faster */
235 spin_lock(&lcu->lock);
236 list_add(&device->alias_list, &lcu->inactive_devices);
238 spin_unlock(&lcu->lock);
239 spin_unlock_irqrestore(&aliastree.lock, flags);
245 * The first device to be registered on an LCU will have to do
246 * some additional setup steps to configure that LCU on the
247 * storage server. All further devices should wait with their
248 * initialization until the first device is done.
249 * To synchronize this work, the first device will call
250 * dasd_alias_lcu_setup_complete when it is done, and all
251 * other devices will wait for it with dasd_alias_wait_for_lcu_setup.
253 void dasd_alias_lcu_setup_complete(struct dasd_device *device)
255 struct dasd_eckd_private *private;
257 struct alias_server *server;
258 struct alias_lcu *lcu;
259 struct dasd_uid *uid;
261 private = (struct dasd_eckd_private *) device->private;
264 spin_lock_irqsave(&aliastree.lock, flags);
265 server = _find_server(uid);
267 lcu = _find_lcu(server, uid);
268 spin_unlock_irqrestore(&aliastree.lock, flags);
270 DBF_EVENT_DEVID(DBF_ERR, device->cdev,
271 "could not find lcu for %04x %02x",
272 uid->ssid, uid->real_unit_addr);
276 complete_all(&lcu->lcu_setup);
279 void dasd_alias_wait_for_lcu_setup(struct dasd_device *device)
281 struct dasd_eckd_private *private;
283 struct alias_server *server;
284 struct alias_lcu *lcu;
285 struct dasd_uid *uid;
287 private = (struct dasd_eckd_private *) device->private;
290 spin_lock_irqsave(&aliastree.lock, flags);
291 server = _find_server(uid);
293 lcu = _find_lcu(server, uid);
294 spin_unlock_irqrestore(&aliastree.lock, flags);
296 DBF_EVENT_DEVID(DBF_ERR, device->cdev,
297 "could not find lcu for %04x %02x",
298 uid->ssid, uid->real_unit_addr);
302 wait_for_completion(&lcu->lcu_setup);
306 * This function removes a device from the scope of alias management.
307 * The complicated part is to make sure that it is not in use by
308 * any of the workers. If necessary cancel the work.
310 void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
312 struct dasd_eckd_private *private;
314 struct alias_lcu *lcu;
315 struct alias_server *server;
318 private = (struct dasd_eckd_private *) device->private;
320 spin_lock_irqsave(&lcu->lock, flags);
321 list_del_init(&device->alias_list);
322 /* make sure that the workers don't use this device */
323 if (device == lcu->suc_data.device) {
324 spin_unlock_irqrestore(&lcu->lock, flags);
325 cancel_work_sync(&lcu->suc_data.worker);
326 spin_lock_irqsave(&lcu->lock, flags);
327 if (device == lcu->suc_data.device)
328 lcu->suc_data.device = NULL;
331 if (device == lcu->ruac_data.device) {
332 spin_unlock_irqrestore(&lcu->lock, flags);
334 cancel_delayed_work_sync(&lcu->ruac_data.dwork);
335 spin_lock_irqsave(&lcu->lock, flags);
336 if (device == lcu->ruac_data.device)
337 lcu->ruac_data.device = NULL;
340 spin_unlock_irqrestore(&lcu->lock, flags);
342 spin_lock_irqsave(&aliastree.lock, flags);
343 spin_lock(&lcu->lock);
344 if (list_empty(&lcu->grouplist) &&
345 list_empty(&lcu->active_devices) &&
346 list_empty(&lcu->inactive_devices)) {
348 spin_unlock(&lcu->lock);
353 _schedule_lcu_update(lcu, NULL);
354 spin_unlock(&lcu->lock);
356 server = _find_server(&private->uid);
357 if (server && list_empty(&server->lculist)) {
358 list_del(&server->server);
359 _free_server(server);
361 spin_unlock_irqrestore(&aliastree.lock, flags);
365 * This function assumes that the unit address configuration stored
366 * in the lcu is up to date and will update the device uid before
367 * adding it to a pav group.
369 static int _add_device_to_lcu(struct alias_lcu *lcu,
370 struct dasd_device *device)
373 struct dasd_eckd_private *private;
374 struct alias_pav_group *group;
375 struct dasd_uid *uid;
377 private = (struct dasd_eckd_private *) device->private;
379 uid->type = lcu->uac->unit[uid->real_unit_addr].ua_type;
380 uid->base_unit_addr = lcu->uac->unit[uid->real_unit_addr].base_ua;
381 dasd_set_uid(device->cdev, &private->uid);
383 /* if we have no PAV anyway, we don't need to bother with PAV groups */
384 if (lcu->pav == NO_PAV) {
385 list_move(&device->alias_list, &lcu->active_devices);
389 group = _find_group(lcu, uid);
391 group = kzalloc(sizeof(*group), GFP_ATOMIC);
394 memcpy(group->uid.vendor, uid->vendor, sizeof(uid->vendor));
395 memcpy(group->uid.serial, uid->serial, sizeof(uid->serial));
396 group->uid.ssid = uid->ssid;
397 if (uid->type == UA_BASE_DEVICE)
398 group->uid.base_unit_addr = uid->real_unit_addr;
400 group->uid.base_unit_addr = uid->base_unit_addr;
401 memcpy(group->uid.vduit, uid->vduit, sizeof(uid->vduit));
402 INIT_LIST_HEAD(&group->group);
403 INIT_LIST_HEAD(&group->baselist);
404 INIT_LIST_HEAD(&group->aliaslist);
405 list_add(&group->group, &lcu->grouplist);
407 if (uid->type == UA_BASE_DEVICE)
408 list_move(&device->alias_list, &group->baselist);
410 list_move(&device->alias_list, &group->aliaslist);
411 private->pavgroup = group;
415 static void _remove_device_from_lcu(struct alias_lcu *lcu,
416 struct dasd_device *device)
418 struct dasd_eckd_private *private;
419 struct alias_pav_group *group;
421 private = (struct dasd_eckd_private *) device->private;
422 list_move(&device->alias_list, &lcu->inactive_devices);
423 group = private->pavgroup;
426 private->pavgroup = NULL;
427 if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
428 list_del(&group->group);
432 if (group->next == device)
436 static int read_unit_address_configuration(struct dasd_device *device,
437 struct alias_lcu *lcu)
439 struct dasd_psf_prssd_data *prssdp;
440 struct dasd_ccw_req *cqr;
445 cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
446 (sizeof(struct dasd_psf_prssd_data)),
450 cqr->startdev = device;
451 cqr->memdev = device;
452 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
454 cqr->expires = 20 * HZ;
456 /* Prepare for Read Subsystem Data */
457 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
458 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
459 prssdp->order = PSF_ORDER_PRSSD;
460 prssdp->suborder = 0x0e; /* Read unit address configuration */
461 /* all other bytes of prssdp must be zero */
464 ccw->cmd_code = DASD_ECKD_CCW_PSF;
465 ccw->count = sizeof(struct dasd_psf_prssd_data);
466 ccw->flags |= CCW_FLAG_CC;
467 ccw->cda = (__u32)(addr_t) prssdp;
469 /* Read Subsystem Data - feature codes */
470 memset(lcu->uac, 0, sizeof(*(lcu->uac)));
473 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
474 ccw->count = sizeof(*(lcu->uac));
475 ccw->cda = (__u32)(addr_t) lcu->uac;
477 cqr->buildclk = get_clock();
478 cqr->status = DASD_CQR_FILLED;
480 /* need to unset flag here to detect race with summary unit check */
481 spin_lock_irqsave(&lcu->lock, flags);
482 lcu->flags &= ~NEED_UAC_UPDATE;
483 spin_unlock_irqrestore(&lcu->lock, flags);
486 rc = dasd_sleep_on(cqr);
487 } while (rc && (cqr->retries > 0));
489 spin_lock_irqsave(&lcu->lock, flags);
490 lcu->flags |= NEED_UAC_UPDATE;
491 spin_unlock_irqrestore(&lcu->lock, flags);
493 dasd_kfree_request(cqr, cqr->memdev);
497 static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
500 struct alias_pav_group *pavgroup, *tempgroup;
501 struct dasd_device *device, *tempdev;
503 struct dasd_eckd_private *private;
505 spin_lock_irqsave(&lcu->lock, flags);
506 list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
507 list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
509 list_move(&device->alias_list, &lcu->active_devices);
510 private = (struct dasd_eckd_private *) device->private;
511 private->pavgroup = NULL;
513 list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
515 list_move(&device->alias_list, &lcu->active_devices);
516 private = (struct dasd_eckd_private *) device->private;
517 private->pavgroup = NULL;
519 list_del(&pavgroup->group);
522 spin_unlock_irqrestore(&lcu->lock, flags);
524 rc = read_unit_address_configuration(refdev, lcu);
528 spin_lock_irqsave(&lcu->lock, flags);
530 for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
531 switch (lcu->uac->unit[i].ua_type) {
532 case UA_BASE_PAV_ALIAS:
535 case UA_HYPER_PAV_ALIAS:
536 lcu->pav = HYPER_PAV;
539 if (lcu->pav != NO_PAV)
543 list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
545 _add_device_to_lcu(lcu, device);
547 spin_unlock_irqrestore(&lcu->lock, flags);
551 static void lcu_update_work(struct work_struct *work)
553 struct alias_lcu *lcu;
554 struct read_uac_work_data *ruac_data;
555 struct dasd_device *device;
559 ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
560 lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
561 device = ruac_data->device;
562 rc = _lcu_update(device, lcu);
564 * Need to check flags again, as there could have been another
565 * prepare_update or a new device a new device while we were still
566 * processing the data
568 spin_lock_irqsave(&lcu->lock, flags);
569 if (rc || (lcu->flags & NEED_UAC_UPDATE)) {
570 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
571 " alias data in lcu (rc = %d), retry later", rc);
572 schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ);
574 lcu->ruac_data.device = NULL;
575 lcu->flags &= ~UPDATE_PENDING;
577 spin_unlock_irqrestore(&lcu->lock, flags);
580 static int _schedule_lcu_update(struct alias_lcu *lcu,
581 struct dasd_device *device)
583 struct dasd_device *usedev = NULL;
584 struct alias_pav_group *group;
586 lcu->flags |= NEED_UAC_UPDATE;
587 if (lcu->ruac_data.device) {
588 /* already scheduled or running */
591 if (device && !list_empty(&device->alias_list))
594 if (!usedev && !list_empty(&lcu->grouplist)) {
595 group = list_first_entry(&lcu->grouplist,
596 struct alias_pav_group, group);
597 if (!list_empty(&group->baselist))
598 usedev = list_first_entry(&group->baselist,
601 else if (!list_empty(&group->aliaslist))
602 usedev = list_first_entry(&group->aliaslist,
606 if (!usedev && !list_empty(&lcu->active_devices)) {
607 usedev = list_first_entry(&lcu->active_devices,
608 struct dasd_device, alias_list);
611 * if we haven't found a proper device yet, give up for now, the next
612 * device that will be set active will trigger an lcu update
616 lcu->ruac_data.device = usedev;
617 schedule_delayed_work(&lcu->ruac_data.dwork, 0);
621 int dasd_alias_add_device(struct dasd_device *device)
623 struct dasd_eckd_private *private;
624 struct alias_lcu *lcu;
628 private = (struct dasd_eckd_private *) device->private;
631 spin_lock_irqsave(&lcu->lock, flags);
632 if (!(lcu->flags & UPDATE_PENDING)) {
633 rc = _add_device_to_lcu(lcu, device);
635 lcu->flags |= UPDATE_PENDING;
637 if (lcu->flags & UPDATE_PENDING) {
638 list_move(&device->alias_list, &lcu->active_devices);
639 _schedule_lcu_update(lcu, device);
641 spin_unlock_irqrestore(&lcu->lock, flags);
645 int dasd_alias_update_add_device(struct dasd_device *device)
647 struct dasd_eckd_private *private;
648 private = (struct dasd_eckd_private *) device->private;
649 private->lcu->flags |= UPDATE_PENDING;
650 return dasd_alias_add_device(device);
653 int dasd_alias_remove_device(struct dasd_device *device)
655 struct dasd_eckd_private *private;
656 struct alias_lcu *lcu;
659 private = (struct dasd_eckd_private *) device->private;
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)
670 struct dasd_device *alias_device;
671 struct alias_pav_group *group;
672 struct alias_lcu *lcu;
673 struct dasd_eckd_private *private, *alias_priv;
676 private = (struct dasd_eckd_private *) base_device->private;
677 group = private->pavgroup;
681 if (lcu->pav == NO_PAV ||
682 lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
685 spin_lock_irqsave(&lcu->lock, flags);
686 alias_device = group->next;
688 if (list_empty(&group->aliaslist)) {
689 spin_unlock_irqrestore(&lcu->lock, flags);
692 alias_device = list_first_entry(&group->aliaslist,
697 if (list_is_last(&alias_device->alias_list, &group->aliaslist))
698 group->next = list_first_entry(&group->aliaslist,
699 struct dasd_device, alias_list);
701 group->next = list_first_entry(&alias_device->alias_list,
702 struct dasd_device, alias_list);
703 spin_unlock_irqrestore(&lcu->lock, flags);
704 alias_priv = (struct dasd_eckd_private *) alias_device->private;
705 if ((alias_priv->count < private->count) && !alias_device->stopped)
712 * Summary unit check handling depends on the way alias devices
713 * are handled so it is done here rather then in dasd_eckd.c
715 static int reset_summary_unit_check(struct alias_lcu *lcu,
716 struct dasd_device *device,
719 struct dasd_ccw_req *cqr;
724 strncpy((char *) &cqr->magic, "ECKD", 4);
725 ASCEBC((char *) &cqr->magic, 4);
727 ccw->cmd_code = DASD_ECKD_CCW_RSCK;
730 ccw->cda = (__u32)(addr_t) cqr->data;
731 ((char *)cqr->data)[0] = reason;
733 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
734 cqr->retries = 255; /* set retry counter to enable basic ERP */
735 cqr->startdev = device;
736 cqr->memdev = device;
738 cqr->expires = 5 * HZ;
739 cqr->buildclk = get_clock();
740 cqr->status = DASD_CQR_FILLED;
742 rc = dasd_sleep_on_immediatly(cqr);
746 static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
748 struct alias_pav_group *pavgroup;
749 struct dasd_device *device;
750 struct dasd_eckd_private *private;
752 /* active and inactive list can contain alias as well as base devices */
753 list_for_each_entry(device, &lcu->active_devices, alias_list) {
754 private = (struct dasd_eckd_private *) device->private;
755 if (private->uid.type != UA_BASE_DEVICE)
757 dasd_schedule_block_bh(device->block);
758 dasd_schedule_device_bh(device);
760 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
761 private = (struct dasd_eckd_private *) device->private;
762 if (private->uid.type != UA_BASE_DEVICE)
764 dasd_schedule_block_bh(device->block);
765 dasd_schedule_device_bh(device);
767 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
768 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
769 dasd_schedule_block_bh(device->block);
770 dasd_schedule_device_bh(device);
775 static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
777 struct alias_pav_group *pavgroup;
778 struct dasd_device *device, *temp;
779 struct dasd_eckd_private *private;
785 * Problem here ist that dasd_flush_device_queue may wait
786 * for termination of a request to complete. We can't keep
787 * the lcu lock during that time, so we must assume that
788 * the lists may have changed.
789 * Idea: first gather all active alias devices in a separate list,
790 * then flush the first element of this list unlocked, and afterwards
791 * check if it is still on the list before moving it to the
792 * active_devices list.
795 spin_lock_irqsave(&lcu->lock, flags);
796 list_for_each_entry_safe(device, temp, &lcu->active_devices,
798 private = (struct dasd_eckd_private *) device->private;
799 if (private->uid.type == UA_BASE_DEVICE)
801 list_move(&device->alias_list, &active);
804 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
805 list_splice_init(&pavgroup->aliaslist, &active);
807 while (!list_empty(&active)) {
808 device = list_first_entry(&active, struct dasd_device,
810 spin_unlock_irqrestore(&lcu->lock, flags);
811 rc = dasd_flush_device_queue(device);
812 spin_lock_irqsave(&lcu->lock, flags);
814 * only move device around if it wasn't moved away while we
815 * were waiting for the flush
817 if (device == list_first_entry(&active,
818 struct dasd_device, alias_list))
819 list_move(&device->alias_list, &lcu->active_devices);
821 spin_unlock_irqrestore(&lcu->lock, flags);
824 static void __stop_device_on_lcu(struct dasd_device *device,
825 struct dasd_device *pos)
827 /* If pos == device then device is already locked! */
829 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
832 spin_lock(get_ccwdev_lock(pos->cdev));
833 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
834 spin_unlock(get_ccwdev_lock(pos->cdev));
838 * This function is called in interrupt context, so the
839 * cdev lock for device is already locked!
841 static void _stop_all_devices_on_lcu(struct alias_lcu *lcu,
842 struct dasd_device *device)
844 struct alias_pav_group *pavgroup;
845 struct dasd_device *pos;
847 list_for_each_entry(pos, &lcu->active_devices, alias_list)
848 __stop_device_on_lcu(device, pos);
849 list_for_each_entry(pos, &lcu->inactive_devices, alias_list)
850 __stop_device_on_lcu(device, pos);
851 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
852 list_for_each_entry(pos, &pavgroup->baselist, alias_list)
853 __stop_device_on_lcu(device, pos);
854 list_for_each_entry(pos, &pavgroup->aliaslist, alias_list)
855 __stop_device_on_lcu(device, pos);
859 static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
861 struct alias_pav_group *pavgroup;
862 struct dasd_device *device;
865 list_for_each_entry(device, &lcu->active_devices, alias_list) {
866 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
867 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
868 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
871 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
872 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
873 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
874 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
877 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
878 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
879 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
880 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
881 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
884 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
885 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
886 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
887 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
893 static void summary_unit_check_handling_work(struct work_struct *work)
895 struct alias_lcu *lcu;
896 struct summary_unit_check_work_data *suc_data;
898 struct dasd_device *device;
900 suc_data = container_of(work, struct summary_unit_check_work_data,
902 lcu = container_of(suc_data, struct alias_lcu, suc_data);
903 device = suc_data->device;
905 /* 1. flush alias devices */
906 flush_all_alias_devices_on_lcu(lcu);
908 /* 2. reset summary unit check */
909 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
910 dasd_device_remove_stop_bits(device,
911 (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
912 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
913 reset_summary_unit_check(lcu, device, suc_data->reason);
915 spin_lock_irqsave(&lcu->lock, flags);
916 _unstop_all_devices_on_lcu(lcu);
917 _restart_all_base_devices_on_lcu(lcu);
918 /* 3. read new alias configuration */
919 _schedule_lcu_update(lcu, device);
920 lcu->suc_data.device = NULL;
921 spin_unlock_irqrestore(&lcu->lock, flags);
925 * note: this will be called from int handler context (cdev locked)
927 void dasd_alias_handle_summary_unit_check(struct dasd_device *device,
930 struct alias_lcu *lcu;
932 struct dasd_eckd_private *private;
935 private = (struct dasd_eckd_private *) device->private;
937 sense = dasd_get_sense(irb);
940 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
941 "eckd handle summary unit check: reason", reason);
943 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
944 "eckd handle summary unit check:"
945 " no reason code available");
951 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
952 "device not ready to handle summary"
953 " unit check (no lcu structure)");
956 spin_lock(&lcu->lock);
957 _stop_all_devices_on_lcu(lcu, device);
958 /* prepare for lcu_update */
959 private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
960 /* If this device is about to be removed just return and wait for
961 * the next interrupt on a different device
963 if (list_empty(&device->alias_list)) {
964 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
965 "device is in offline processing,"
966 " don't do summary unit check handling");
967 spin_unlock(&lcu->lock);
970 if (lcu->suc_data.device) {
971 /* already scheduled or running */
972 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
973 "previous instance of summary unit check worker"
975 spin_unlock(&lcu->lock);
978 lcu->suc_data.reason = reason;
979 lcu->suc_data.device = device;
980 spin_unlock(&lcu->lock);
981 schedule_work(&lcu->suc_data.worker);