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"
10 #include <linux/list.h>
11 #include <asm/ebcdic.h>
13 #include "dasd_eckd.h"
17 #endif /* PRINTK_HEADER */
18 #define PRINTK_HEADER "dasd(eckd):"
22 * General concept of alias management:
23 * - PAV and DASD alias management is specific to the eckd discipline.
24 * - A device is connected to an lcu as long as the device exists.
25 * dasd_alias_make_device_known_to_lcu will be called wenn the
26 * device is checked by the eckd discipline and
27 * dasd_alias_disconnect_device_from_lcu will be called
28 * before the device is deleted.
29 * - The dasd_alias_add_device / dasd_alias_remove_device
30 * functions mark the point when a device is 'ready for service'.
31 * - A summary unit check is a rare occasion, but it is mandatory to
32 * support it. It requires some complex recovery actions before the
33 * devices can be used again (see dasd_alias_handle_summary_unit_check).
34 * - dasd_alias_get_start_dev will find an alias device that can be used
35 * instead of the base device and does some (very simple) load balancing.
36 * This is the function that gets called for each I/O, so when improving
37 * something, this function should get faster or better, the rest has just
42 static void summary_unit_check_handling_work(struct work_struct
*);
43 static void lcu_update_work(struct work_struct
*);
44 static int _schedule_lcu_update(struct alias_lcu
*, struct dasd_device
*);
46 static struct alias_root aliastree
= {
47 .serverlist
= LIST_HEAD_INIT(aliastree
.serverlist
),
48 .lock
= __SPIN_LOCK_UNLOCKED(aliastree
.lock
),
51 static struct alias_server
*_find_server(struct dasd_uid
*uid
)
53 struct alias_server
*pos
;
54 list_for_each_entry(pos
, &aliastree
.serverlist
, server
) {
55 if (!strncmp(pos
->uid
.vendor
, uid
->vendor
,
57 && !strncmp(pos
->uid
.serial
, uid
->serial
,
64 static struct alias_lcu
*_find_lcu(struct alias_server
*server
,
67 struct alias_lcu
*pos
;
68 list_for_each_entry(pos
, &server
->lculist
, lcu
) {
69 if (pos
->uid
.ssid
== uid
->ssid
)
75 static struct alias_pav_group
*_find_group(struct alias_lcu
*lcu
,
78 struct alias_pav_group
*pos
;
79 __u8 search_unit_addr
;
81 /* for hyper pav there is only one group */
82 if (lcu
->pav
== HYPER_PAV
) {
83 if (list_empty(&lcu
->grouplist
))
86 return list_first_entry(&lcu
->grouplist
,
87 struct alias_pav_group
, group
);
90 /* for base pav we have to find the group that matches the base */
91 if (uid
->type
== UA_BASE_DEVICE
)
92 search_unit_addr
= uid
->real_unit_addr
;
94 search_unit_addr
= uid
->base_unit_addr
;
95 list_for_each_entry(pos
, &lcu
->grouplist
, group
) {
96 if (pos
->uid
.base_unit_addr
== search_unit_addr
&&
97 !strncmp(pos
->uid
.vduit
, uid
->vduit
, sizeof(uid
->vduit
)))
103 static struct alias_server
*_allocate_server(struct dasd_uid
*uid
)
105 struct alias_server
*server
;
107 server
= kzalloc(sizeof(*server
), GFP_KERNEL
);
109 return ERR_PTR(-ENOMEM
);
110 memcpy(server
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
111 memcpy(server
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
112 INIT_LIST_HEAD(&server
->server
);
113 INIT_LIST_HEAD(&server
->lculist
);
117 static void _free_server(struct alias_server
*server
)
122 static struct alias_lcu
*_allocate_lcu(struct dasd_uid
*uid
)
124 struct alias_lcu
*lcu
;
126 lcu
= kzalloc(sizeof(*lcu
), GFP_KERNEL
);
128 return ERR_PTR(-ENOMEM
);
129 lcu
->uac
= kzalloc(sizeof(*(lcu
->uac
)), GFP_KERNEL
| GFP_DMA
);
132 lcu
->rsu_cqr
= kzalloc(sizeof(*lcu
->rsu_cqr
), GFP_KERNEL
| GFP_DMA
);
135 lcu
->rsu_cqr
->cpaddr
= kzalloc(sizeof(struct ccw1
),
136 GFP_KERNEL
| GFP_DMA
);
137 if (!lcu
->rsu_cqr
->cpaddr
)
139 lcu
->rsu_cqr
->data
= kzalloc(16, GFP_KERNEL
| GFP_DMA
);
140 if (!lcu
->rsu_cqr
->data
)
143 memcpy(lcu
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
144 memcpy(lcu
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
145 lcu
->uid
.ssid
= uid
->ssid
;
147 lcu
->flags
= NEED_UAC_UPDATE
| UPDATE_PENDING
;
148 INIT_LIST_HEAD(&lcu
->lcu
);
149 INIT_LIST_HEAD(&lcu
->inactive_devices
);
150 INIT_LIST_HEAD(&lcu
->active_devices
);
151 INIT_LIST_HEAD(&lcu
->grouplist
);
152 INIT_WORK(&lcu
->suc_data
.worker
, summary_unit_check_handling_work
);
153 INIT_DELAYED_WORK(&lcu
->ruac_data
.dwork
, lcu_update_work
);
154 spin_lock_init(&lcu
->lock
);
158 kfree(lcu
->rsu_cqr
->cpaddr
);
165 return ERR_PTR(-ENOMEM
);
168 static void _free_lcu(struct alias_lcu
*lcu
)
170 kfree(lcu
->rsu_cqr
->data
);
171 kfree(lcu
->rsu_cqr
->cpaddr
);
178 * This is the function that will allocate all the server and lcu data,
179 * so this function must be called first for a new device.
180 * If the return value is 1, the lcu was already known before, if it
181 * is 0, this is a new lcu.
182 * Negative return code indicates that something went wrong (e.g. -ENOMEM)
184 int dasd_alias_make_device_known_to_lcu(struct dasd_device
*device
)
186 struct dasd_eckd_private
*private;
188 struct alias_server
*server
, *newserver
;
189 struct alias_lcu
*lcu
, *newlcu
;
191 struct dasd_uid
*uid
;
193 private = (struct dasd_eckd_private
*) device
->private;
195 spin_lock_irqsave(&aliastree
.lock
, flags
);
197 server
= _find_server(uid
);
199 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
200 newserver
= _allocate_server(uid
);
201 if (IS_ERR(newserver
))
202 return PTR_ERR(newserver
);
203 spin_lock_irqsave(&aliastree
.lock
, flags
);
204 server
= _find_server(uid
);
206 list_add(&newserver
->server
, &aliastree
.serverlist
);
210 /* someone was faster */
211 _free_server(newserver
);
215 lcu
= _find_lcu(server
, uid
);
217 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
218 newlcu
= _allocate_lcu(uid
);
221 spin_lock_irqsave(&aliastree
.lock
, flags
);
222 lcu
= _find_lcu(server
, uid
);
224 list_add(&newlcu
->lcu
, &server
->lculist
);
228 /* someone was faster */
233 spin_lock(&lcu
->lock
);
234 list_add(&device
->alias_list
, &lcu
->inactive_devices
);
236 spin_unlock(&lcu
->lock
);
237 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
243 * This function removes a device from the scope of alias management.
244 * The complicated part is to make sure that it is not in use by
245 * any of the workers. If necessary cancel the work.
247 void dasd_alias_disconnect_device_from_lcu(struct dasd_device
*device
)
249 struct dasd_eckd_private
*private;
251 struct alias_lcu
*lcu
;
252 struct alias_server
*server
;
255 private = (struct dasd_eckd_private
*) device
->private;
257 spin_lock_irqsave(&lcu
->lock
, flags
);
258 list_del_init(&device
->alias_list
);
259 /* make sure that the workers don't use this device */
260 if (device
== lcu
->suc_data
.device
) {
261 spin_unlock_irqrestore(&lcu
->lock
, flags
);
262 cancel_work_sync(&lcu
->suc_data
.worker
);
263 spin_lock_irqsave(&lcu
->lock
, flags
);
264 if (device
== lcu
->suc_data
.device
)
265 lcu
->suc_data
.device
= NULL
;
268 if (device
== lcu
->ruac_data
.device
) {
269 spin_unlock_irqrestore(&lcu
->lock
, flags
);
271 cancel_delayed_work_sync(&lcu
->ruac_data
.dwork
);
272 spin_lock_irqsave(&lcu
->lock
, flags
);
273 if (device
== lcu
->ruac_data
.device
)
274 lcu
->ruac_data
.device
= NULL
;
277 spin_unlock_irqrestore(&lcu
->lock
, flags
);
279 spin_lock_irqsave(&aliastree
.lock
, flags
);
280 spin_lock(&lcu
->lock
);
281 if (list_empty(&lcu
->grouplist
) &&
282 list_empty(&lcu
->active_devices
) &&
283 list_empty(&lcu
->inactive_devices
)) {
285 spin_unlock(&lcu
->lock
);
290 _schedule_lcu_update(lcu
, NULL
);
291 spin_unlock(&lcu
->lock
);
293 server
= _find_server(&private->uid
);
294 if (server
&& list_empty(&server
->lculist
)) {
295 list_del(&server
->server
);
296 _free_server(server
);
298 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
302 * This function assumes that the unit address configuration stored
303 * in the lcu is up to date and will update the device uid before
304 * adding it to a pav group.
306 static int _add_device_to_lcu(struct alias_lcu
*lcu
,
307 struct dasd_device
*device
)
310 struct dasd_eckd_private
*private;
311 struct alias_pav_group
*group
;
312 struct dasd_uid
*uid
;
314 private = (struct dasd_eckd_private
*) device
->private;
316 uid
->type
= lcu
->uac
->unit
[uid
->real_unit_addr
].ua_type
;
317 uid
->base_unit_addr
= lcu
->uac
->unit
[uid
->real_unit_addr
].base_ua
;
318 dasd_set_uid(device
->cdev
, &private->uid
);
320 /* if we have no PAV anyway, we don't need to bother with PAV groups */
321 if (lcu
->pav
== NO_PAV
) {
322 list_move(&device
->alias_list
, &lcu
->active_devices
);
326 group
= _find_group(lcu
, uid
);
328 group
= kzalloc(sizeof(*group
), GFP_ATOMIC
);
331 memcpy(group
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
332 memcpy(group
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
333 group
->uid
.ssid
= uid
->ssid
;
334 if (uid
->type
== UA_BASE_DEVICE
)
335 group
->uid
.base_unit_addr
= uid
->real_unit_addr
;
337 group
->uid
.base_unit_addr
= uid
->base_unit_addr
;
338 memcpy(group
->uid
.vduit
, uid
->vduit
, sizeof(uid
->vduit
));
339 INIT_LIST_HEAD(&group
->group
);
340 INIT_LIST_HEAD(&group
->baselist
);
341 INIT_LIST_HEAD(&group
->aliaslist
);
342 list_add(&group
->group
, &lcu
->grouplist
);
344 if (uid
->type
== UA_BASE_DEVICE
)
345 list_move(&device
->alias_list
, &group
->baselist
);
347 list_move(&device
->alias_list
, &group
->aliaslist
);
348 private->pavgroup
= group
;
352 static void _remove_device_from_lcu(struct alias_lcu
*lcu
,
353 struct dasd_device
*device
)
355 struct dasd_eckd_private
*private;
356 struct alias_pav_group
*group
;
358 private = (struct dasd_eckd_private
*) device
->private;
359 list_move(&device
->alias_list
, &lcu
->inactive_devices
);
360 group
= private->pavgroup
;
363 private->pavgroup
= NULL
;
364 if (list_empty(&group
->baselist
) && list_empty(&group
->aliaslist
)) {
365 list_del(&group
->group
);
369 if (group
->next
== device
)
373 static int read_unit_address_configuration(struct dasd_device
*device
,
374 struct alias_lcu
*lcu
)
376 struct dasd_psf_prssd_data
*prssdp
;
377 struct dasd_ccw_req
*cqr
;
382 cqr
= dasd_kmalloc_request("ECKD",
383 1 /* PSF */ + 1 /* RSSD */ ,
384 (sizeof(struct dasd_psf_prssd_data
)),
388 cqr
->startdev
= device
;
389 cqr
->memdev
= device
;
390 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
392 cqr
->expires
= 20 * HZ
;
394 /* Prepare for Read Subsystem Data */
395 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
396 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
397 prssdp
->order
= PSF_ORDER_PRSSD
;
398 prssdp
->suborder
= 0x0e; /* Read unit address configuration */
399 /* all other bytes of prssdp must be zero */
402 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
403 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
404 ccw
->flags
|= CCW_FLAG_CC
;
405 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
407 /* Read Subsystem Data - feature codes */
408 memset(lcu
->uac
, 0, sizeof(*(lcu
->uac
)));
411 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
412 ccw
->count
= sizeof(*(lcu
->uac
));
413 ccw
->cda
= (__u32
)(addr_t
) lcu
->uac
;
415 cqr
->buildclk
= get_clock();
416 cqr
->status
= DASD_CQR_FILLED
;
418 /* need to unset flag here to detect race with summary unit check */
419 spin_lock_irqsave(&lcu
->lock
, flags
);
420 lcu
->flags
&= ~NEED_UAC_UPDATE
;
421 spin_unlock_irqrestore(&lcu
->lock
, flags
);
424 rc
= dasd_sleep_on(cqr
);
425 } while (rc
&& (cqr
->retries
> 0));
427 spin_lock_irqsave(&lcu
->lock
, flags
);
428 lcu
->flags
|= NEED_UAC_UPDATE
;
429 spin_unlock_irqrestore(&lcu
->lock
, flags
);
431 dasd_kfree_request(cqr
, cqr
->memdev
);
435 static int _lcu_update(struct dasd_device
*refdev
, struct alias_lcu
*lcu
)
438 struct alias_pav_group
*pavgroup
, *tempgroup
;
439 struct dasd_device
*device
, *tempdev
;
441 struct dasd_eckd_private
*private;
443 spin_lock_irqsave(&lcu
->lock
, flags
);
444 list_for_each_entry_safe(pavgroup
, tempgroup
, &lcu
->grouplist
, group
) {
445 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->baselist
,
447 list_move(&device
->alias_list
, &lcu
->active_devices
);
448 private = (struct dasd_eckd_private
*) device
->private;
449 private->pavgroup
= NULL
;
451 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->aliaslist
,
453 list_move(&device
->alias_list
, &lcu
->active_devices
);
454 private = (struct dasd_eckd_private
*) device
->private;
455 private->pavgroup
= NULL
;
457 list_del(&pavgroup
->group
);
460 spin_unlock_irqrestore(&lcu
->lock
, flags
);
462 rc
= read_unit_address_configuration(refdev
, lcu
);
466 spin_lock_irqsave(&lcu
->lock
, flags
);
468 for (i
= 0; i
< MAX_DEVICES_PER_LCU
; ++i
) {
469 switch (lcu
->uac
->unit
[i
].ua_type
) {
470 case UA_BASE_PAV_ALIAS
:
473 case UA_HYPER_PAV_ALIAS
:
474 lcu
->pav
= HYPER_PAV
;
477 if (lcu
->pav
!= NO_PAV
)
481 list_for_each_entry_safe(device
, tempdev
, &lcu
->active_devices
,
483 _add_device_to_lcu(lcu
, device
);
485 spin_unlock_irqrestore(&lcu
->lock
, flags
);
489 static void lcu_update_work(struct work_struct
*work
)
491 struct alias_lcu
*lcu
;
492 struct read_uac_work_data
*ruac_data
;
493 struct dasd_device
*device
;
497 ruac_data
= container_of(work
, struct read_uac_work_data
, dwork
.work
);
498 lcu
= container_of(ruac_data
, struct alias_lcu
, ruac_data
);
499 device
= ruac_data
->device
;
500 rc
= _lcu_update(device
, lcu
);
502 * Need to check flags again, as there could have been another
503 * prepare_update or a new device a new device while we were still
504 * processing the data
506 spin_lock_irqsave(&lcu
->lock
, flags
);
507 if (rc
|| (lcu
->flags
& NEED_UAC_UPDATE
)) {
508 DBF_DEV_EVENT(DBF_WARNING
, device
, "could not update"
509 " alias data in lcu (rc = %d), retry later", rc
);
510 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 30*HZ
);
512 lcu
->ruac_data
.device
= NULL
;
513 lcu
->flags
&= ~UPDATE_PENDING
;
515 spin_unlock_irqrestore(&lcu
->lock
, flags
);
518 static int _schedule_lcu_update(struct alias_lcu
*lcu
,
519 struct dasd_device
*device
)
521 struct dasd_device
*usedev
= NULL
;
522 struct alias_pav_group
*group
;
524 lcu
->flags
|= NEED_UAC_UPDATE
;
525 if (lcu
->ruac_data
.device
) {
526 /* already scheduled or running */
529 if (device
&& !list_empty(&device
->alias_list
))
532 if (!usedev
&& !list_empty(&lcu
->grouplist
)) {
533 group
= list_first_entry(&lcu
->grouplist
,
534 struct alias_pav_group
, group
);
535 if (!list_empty(&group
->baselist
))
536 usedev
= list_first_entry(&group
->baselist
,
539 else if (!list_empty(&group
->aliaslist
))
540 usedev
= list_first_entry(&group
->aliaslist
,
544 if (!usedev
&& !list_empty(&lcu
->active_devices
)) {
545 usedev
= list_first_entry(&lcu
->active_devices
,
546 struct dasd_device
, alias_list
);
549 * if we haven't found a proper device yet, give up for now, the next
550 * device that will be set active will trigger an lcu update
554 lcu
->ruac_data
.device
= usedev
;
555 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 0);
559 int dasd_alias_add_device(struct dasd_device
*device
)
561 struct dasd_eckd_private
*private;
562 struct alias_lcu
*lcu
;
566 private = (struct dasd_eckd_private
*) device
->private;
569 spin_lock_irqsave(&lcu
->lock
, flags
);
570 if (!(lcu
->flags
& UPDATE_PENDING
)) {
571 rc
= _add_device_to_lcu(lcu
, device
);
573 lcu
->flags
|= UPDATE_PENDING
;
575 if (lcu
->flags
& UPDATE_PENDING
) {
576 list_move(&device
->alias_list
, &lcu
->active_devices
);
577 _schedule_lcu_update(lcu
, device
);
579 spin_unlock_irqrestore(&lcu
->lock
, flags
);
583 int dasd_alias_remove_device(struct dasd_device
*device
)
585 struct dasd_eckd_private
*private;
586 struct alias_lcu
*lcu
;
589 private = (struct dasd_eckd_private
*) device
->private;
591 spin_lock_irqsave(&lcu
->lock
, flags
);
592 _remove_device_from_lcu(lcu
, device
);
593 spin_unlock_irqrestore(&lcu
->lock
, flags
);
597 struct dasd_device
*dasd_alias_get_start_dev(struct dasd_device
*base_device
)
600 struct dasd_device
*alias_device
;
601 struct alias_pav_group
*group
;
602 struct alias_lcu
*lcu
;
603 struct dasd_eckd_private
*private, *alias_priv
;
606 private = (struct dasd_eckd_private
*) base_device
->private;
607 group
= private->pavgroup
;
611 if (lcu
->pav
== NO_PAV
||
612 lcu
->flags
& (NEED_UAC_UPDATE
| UPDATE_PENDING
))
615 spin_lock_irqsave(&lcu
->lock
, flags
);
616 alias_device
= group
->next
;
618 if (list_empty(&group
->aliaslist
)) {
619 spin_unlock_irqrestore(&lcu
->lock
, flags
);
622 alias_device
= list_first_entry(&group
->aliaslist
,
627 if (list_is_last(&alias_device
->alias_list
, &group
->aliaslist
))
628 group
->next
= list_first_entry(&group
->aliaslist
,
629 struct dasd_device
, alias_list
);
631 group
->next
= list_first_entry(&alias_device
->alias_list
,
632 struct dasd_device
, alias_list
);
633 spin_unlock_irqrestore(&lcu
->lock
, flags
);
634 alias_priv
= (struct dasd_eckd_private
*) alias_device
->private;
635 if ((alias_priv
->count
< private->count
) && !alias_device
->stopped
)
642 * Summary unit check handling depends on the way alias devices
643 * are handled so it is done here rather then in dasd_eckd.c
645 static int reset_summary_unit_check(struct alias_lcu
*lcu
,
646 struct dasd_device
*device
,
649 struct dasd_ccw_req
*cqr
;
654 strncpy((char *) &cqr
->magic
, "ECKD", 4);
655 ASCEBC((char *) &cqr
->magic
, 4);
657 ccw
->cmd_code
= DASD_ECKD_CCW_RSCK
;
660 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
661 ((char *)cqr
->data
)[0] = reason
;
663 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
664 cqr
->retries
= 255; /* set retry counter to enable basic ERP */
665 cqr
->startdev
= device
;
666 cqr
->memdev
= device
;
668 cqr
->expires
= 5 * HZ
;
669 cqr
->buildclk
= get_clock();
670 cqr
->status
= DASD_CQR_FILLED
;
672 rc
= dasd_sleep_on_immediatly(cqr
);
676 static void _restart_all_base_devices_on_lcu(struct alias_lcu
*lcu
)
678 struct alias_pav_group
*pavgroup
;
679 struct dasd_device
*device
;
680 struct dasd_eckd_private
*private;
682 /* active and inactive list can contain alias as well as base devices */
683 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
684 private = (struct dasd_eckd_private
*) device
->private;
685 if (private->uid
.type
!= UA_BASE_DEVICE
)
687 dasd_schedule_block_bh(device
->block
);
688 dasd_schedule_device_bh(device
);
690 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
691 private = (struct dasd_eckd_private
*) device
->private;
692 if (private->uid
.type
!= UA_BASE_DEVICE
)
694 dasd_schedule_block_bh(device
->block
);
695 dasd_schedule_device_bh(device
);
697 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
698 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
699 dasd_schedule_block_bh(device
->block
);
700 dasd_schedule_device_bh(device
);
705 static void flush_all_alias_devices_on_lcu(struct alias_lcu
*lcu
)
707 struct alias_pav_group
*pavgroup
;
708 struct dasd_device
*device
, *temp
;
709 struct dasd_eckd_private
*private;
715 * Problem here ist that dasd_flush_device_queue may wait
716 * for termination of a request to complete. We can't keep
717 * the lcu lock during that time, so we must assume that
718 * the lists may have changed.
719 * Idea: first gather all active alias devices in a separate list,
720 * then flush the first element of this list unlocked, and afterwards
721 * check if it is still on the list before moving it to the
722 * active_devices list.
725 spin_lock_irqsave(&lcu
->lock
, flags
);
726 list_for_each_entry_safe(device
, temp
, &lcu
->active_devices
,
728 private = (struct dasd_eckd_private
*) device
->private;
729 if (private->uid
.type
== UA_BASE_DEVICE
)
731 list_move(&device
->alias_list
, &active
);
734 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
735 list_splice_init(&pavgroup
->aliaslist
, &active
);
737 while (!list_empty(&active
)) {
738 device
= list_first_entry(&active
, struct dasd_device
,
740 spin_unlock_irqrestore(&lcu
->lock
, flags
);
741 rc
= dasd_flush_device_queue(device
);
742 spin_lock_irqsave(&lcu
->lock
, flags
);
744 * only move device around if it wasn't moved away while we
745 * were waiting for the flush
747 if (device
== list_first_entry(&active
,
748 struct dasd_device
, alias_list
))
749 list_move(&device
->alias_list
, &lcu
->active_devices
);
751 spin_unlock_irqrestore(&lcu
->lock
, flags
);
754 static void __stop_device_on_lcu(struct dasd_device
*device
,
755 struct dasd_device
*pos
)
757 /* If pos == device then device is already locked! */
759 pos
->stopped
|= DASD_STOPPED_SU
;
762 spin_lock(get_ccwdev_lock(pos
->cdev
));
763 pos
->stopped
|= DASD_STOPPED_SU
;
764 spin_unlock(get_ccwdev_lock(pos
->cdev
));
768 * This function is called in interrupt context, so the
769 * cdev lock for device is already locked!
771 static void _stop_all_devices_on_lcu(struct alias_lcu
*lcu
,
772 struct dasd_device
*device
)
774 struct alias_pav_group
*pavgroup
;
775 struct dasd_device
*pos
;
777 list_for_each_entry(pos
, &lcu
->active_devices
, alias_list
)
778 __stop_device_on_lcu(device
, pos
);
779 list_for_each_entry(pos
, &lcu
->inactive_devices
, alias_list
)
780 __stop_device_on_lcu(device
, pos
);
781 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
782 list_for_each_entry(pos
, &pavgroup
->baselist
, alias_list
)
783 __stop_device_on_lcu(device
, pos
);
784 list_for_each_entry(pos
, &pavgroup
->aliaslist
, alias_list
)
785 __stop_device_on_lcu(device
, pos
);
789 static void _unstop_all_devices_on_lcu(struct alias_lcu
*lcu
)
791 struct alias_pav_group
*pavgroup
;
792 struct dasd_device
*device
;
795 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
796 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
797 device
->stopped
&= ~DASD_STOPPED_SU
;
798 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
801 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
802 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
803 device
->stopped
&= ~DASD_STOPPED_SU
;
804 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
807 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
808 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
809 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
810 device
->stopped
&= ~DASD_STOPPED_SU
;
811 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
814 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
815 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
816 device
->stopped
&= ~DASD_STOPPED_SU
;
817 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
823 static void summary_unit_check_handling_work(struct work_struct
*work
)
825 struct alias_lcu
*lcu
;
826 struct summary_unit_check_work_data
*suc_data
;
828 struct dasd_device
*device
;
830 suc_data
= container_of(work
, struct summary_unit_check_work_data
,
832 lcu
= container_of(suc_data
, struct alias_lcu
, suc_data
);
833 device
= suc_data
->device
;
835 /* 1. flush alias devices */
836 flush_all_alias_devices_on_lcu(lcu
);
838 /* 2. reset summary unit check */
839 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
840 device
->stopped
&= ~(DASD_STOPPED_SU
| DASD_STOPPED_PENDING
);
841 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
842 reset_summary_unit_check(lcu
, device
, suc_data
->reason
);
844 spin_lock_irqsave(&lcu
->lock
, flags
);
845 _unstop_all_devices_on_lcu(lcu
);
846 _restart_all_base_devices_on_lcu(lcu
);
847 /* 3. read new alias configuration */
848 _schedule_lcu_update(lcu
, device
);
849 lcu
->suc_data
.device
= NULL
;
850 spin_unlock_irqrestore(&lcu
->lock
, flags
);
854 * note: this will be called from int handler context (cdev locked)
856 void dasd_alias_handle_summary_unit_check(struct dasd_device
*device
,
859 struct alias_lcu
*lcu
;
861 struct dasd_eckd_private
*private;
864 private = (struct dasd_eckd_private
*) device
->private;
866 sense
= dasd_get_sense(irb
);
869 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
870 "eckd handle summary unit check: reason", reason
);
872 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
873 "eckd handle summary unit check:"
874 " no reason code available");
880 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
881 "device not ready to handle summary"
882 " unit check (no lcu structure)");
885 spin_lock(&lcu
->lock
);
886 _stop_all_devices_on_lcu(lcu
, device
);
887 /* prepare for lcu_update */
888 private->lcu
->flags
|= NEED_UAC_UPDATE
| UPDATE_PENDING
;
889 /* If this device is about to be removed just return and wait for
890 * the next interrupt on a different device
892 if (list_empty(&device
->alias_list
)) {
893 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
894 "device is in offline processing,"
895 " don't do summary unit check handling");
896 spin_unlock(&lcu
->lock
);
899 if (lcu
->suc_data
.device
) {
900 /* already scheduled or running */
901 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
902 "previous instance of summary unit check worker"
904 spin_unlock(&lcu
->lock
);
907 lcu
->suc_data
.reason
= reason
;
908 lcu
->suc_data
.device
= device
;
909 spin_unlock(&lcu
->lock
);
910 schedule_work(&lcu
->suc_data
.worker
);