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 <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
);
155 init_completion(&lcu
->lcu_setup
);
159 kfree(lcu
->rsu_cqr
->cpaddr
);
166 return ERR_PTR(-ENOMEM
);
169 static void _free_lcu(struct alias_lcu
*lcu
)
171 kfree(lcu
->rsu_cqr
->data
);
172 kfree(lcu
->rsu_cqr
->cpaddr
);
179 * This is the function that will allocate all the server and lcu data,
180 * so this function must be called first for a new device.
181 * If the return value is 1, the lcu was already known before, if it
182 * is 0, this is a new lcu.
183 * Negative return code indicates that something went wrong (e.g. -ENOMEM)
185 int dasd_alias_make_device_known_to_lcu(struct dasd_device
*device
)
187 struct dasd_eckd_private
*private;
189 struct alias_server
*server
, *newserver
;
190 struct alias_lcu
*lcu
, *newlcu
;
192 struct dasd_uid
*uid
;
194 private = (struct dasd_eckd_private
*) device
->private;
196 spin_lock_irqsave(&aliastree
.lock
, flags
);
198 server
= _find_server(uid
);
200 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
201 newserver
= _allocate_server(uid
);
202 if (IS_ERR(newserver
))
203 return PTR_ERR(newserver
);
204 spin_lock_irqsave(&aliastree
.lock
, flags
);
205 server
= _find_server(uid
);
207 list_add(&newserver
->server
, &aliastree
.serverlist
);
211 /* someone was faster */
212 _free_server(newserver
);
216 lcu
= _find_lcu(server
, uid
);
218 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
219 newlcu
= _allocate_lcu(uid
);
221 return PTR_ERR(newlcu
);
222 spin_lock_irqsave(&aliastree
.lock
, flags
);
223 lcu
= _find_lcu(server
, uid
);
225 list_add(&newlcu
->lcu
, &server
->lculist
);
229 /* someone was faster */
234 spin_lock(&lcu
->lock
);
235 list_add(&device
->alias_list
, &lcu
->inactive_devices
);
237 spin_unlock(&lcu
->lock
);
238 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
244 * The first device to be registered on an LCU will have to do
245 * some additional setup steps to configure that LCU on the
246 * storage server. All further devices should wait with their
247 * initialization until the first device is done.
248 * To synchronize this work, the first device will call
249 * dasd_alias_lcu_setup_complete when it is done, and all
250 * other devices will wait for it with dasd_alias_wait_for_lcu_setup.
252 void dasd_alias_lcu_setup_complete(struct dasd_device
*device
)
254 struct dasd_eckd_private
*private;
256 struct alias_server
*server
;
257 struct alias_lcu
*lcu
;
258 struct dasd_uid
*uid
;
260 private = (struct dasd_eckd_private
*) device
->private;
263 spin_lock_irqsave(&aliastree
.lock
, flags
);
264 server
= _find_server(uid
);
266 lcu
= _find_lcu(server
, uid
);
267 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
269 DBF_EVENT_DEVID(DBF_ERR
, device
->cdev
,
270 "could not find lcu for %04x %02x",
271 uid
->ssid
, uid
->real_unit_addr
);
275 complete_all(&lcu
->lcu_setup
);
278 void dasd_alias_wait_for_lcu_setup(struct dasd_device
*device
)
280 struct dasd_eckd_private
*private;
282 struct alias_server
*server
;
283 struct alias_lcu
*lcu
;
284 struct dasd_uid
*uid
;
286 private = (struct dasd_eckd_private
*) device
->private;
289 spin_lock_irqsave(&aliastree
.lock
, flags
);
290 server
= _find_server(uid
);
292 lcu
= _find_lcu(server
, uid
);
293 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
295 DBF_EVENT_DEVID(DBF_ERR
, device
->cdev
,
296 "could not find lcu for %04x %02x",
297 uid
->ssid
, uid
->real_unit_addr
);
301 wait_for_completion(&lcu
->lcu_setup
);
305 * This function removes a device from the scope of alias management.
306 * The complicated part is to make sure that it is not in use by
307 * any of the workers. If necessary cancel the work.
309 void dasd_alias_disconnect_device_from_lcu(struct dasd_device
*device
)
311 struct dasd_eckd_private
*private;
313 struct alias_lcu
*lcu
;
314 struct alias_server
*server
;
317 private = (struct dasd_eckd_private
*) device
->private;
319 spin_lock_irqsave(&lcu
->lock
, flags
);
320 list_del_init(&device
->alias_list
);
321 /* make sure that the workers don't use this device */
322 if (device
== lcu
->suc_data
.device
) {
323 spin_unlock_irqrestore(&lcu
->lock
, flags
);
324 cancel_work_sync(&lcu
->suc_data
.worker
);
325 spin_lock_irqsave(&lcu
->lock
, flags
);
326 if (device
== lcu
->suc_data
.device
)
327 lcu
->suc_data
.device
= NULL
;
330 if (device
== lcu
->ruac_data
.device
) {
331 spin_unlock_irqrestore(&lcu
->lock
, flags
);
333 cancel_delayed_work_sync(&lcu
->ruac_data
.dwork
);
334 spin_lock_irqsave(&lcu
->lock
, flags
);
335 if (device
== lcu
->ruac_data
.device
)
336 lcu
->ruac_data
.device
= NULL
;
339 spin_unlock_irqrestore(&lcu
->lock
, flags
);
341 spin_lock_irqsave(&aliastree
.lock
, flags
);
342 spin_lock(&lcu
->lock
);
343 if (list_empty(&lcu
->grouplist
) &&
344 list_empty(&lcu
->active_devices
) &&
345 list_empty(&lcu
->inactive_devices
)) {
347 spin_unlock(&lcu
->lock
);
352 _schedule_lcu_update(lcu
, NULL
);
353 spin_unlock(&lcu
->lock
);
355 server
= _find_server(&private->uid
);
356 if (server
&& list_empty(&server
->lculist
)) {
357 list_del(&server
->server
);
358 _free_server(server
);
360 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
364 * This function assumes that the unit address configuration stored
365 * in the lcu is up to date and will update the device uid before
366 * adding it to a pav group.
368 static int _add_device_to_lcu(struct alias_lcu
*lcu
,
369 struct dasd_device
*device
)
372 struct dasd_eckd_private
*private;
373 struct alias_pav_group
*group
;
374 struct dasd_uid
*uid
;
376 private = (struct dasd_eckd_private
*) device
->private;
378 uid
->type
= lcu
->uac
->unit
[uid
->real_unit_addr
].ua_type
;
379 uid
->base_unit_addr
= lcu
->uac
->unit
[uid
->real_unit_addr
].base_ua
;
380 dasd_set_uid(device
->cdev
, &private->uid
);
382 /* if we have no PAV anyway, we don't need to bother with PAV groups */
383 if (lcu
->pav
== NO_PAV
) {
384 list_move(&device
->alias_list
, &lcu
->active_devices
);
388 group
= _find_group(lcu
, uid
);
390 group
= kzalloc(sizeof(*group
), GFP_ATOMIC
);
393 memcpy(group
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
394 memcpy(group
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
395 group
->uid
.ssid
= uid
->ssid
;
396 if (uid
->type
== UA_BASE_DEVICE
)
397 group
->uid
.base_unit_addr
= uid
->real_unit_addr
;
399 group
->uid
.base_unit_addr
= uid
->base_unit_addr
;
400 memcpy(group
->uid
.vduit
, uid
->vduit
, sizeof(uid
->vduit
));
401 INIT_LIST_HEAD(&group
->group
);
402 INIT_LIST_HEAD(&group
->baselist
);
403 INIT_LIST_HEAD(&group
->aliaslist
);
404 list_add(&group
->group
, &lcu
->grouplist
);
406 if (uid
->type
== UA_BASE_DEVICE
)
407 list_move(&device
->alias_list
, &group
->baselist
);
409 list_move(&device
->alias_list
, &group
->aliaslist
);
410 private->pavgroup
= group
;
414 static void _remove_device_from_lcu(struct alias_lcu
*lcu
,
415 struct dasd_device
*device
)
417 struct dasd_eckd_private
*private;
418 struct alias_pav_group
*group
;
420 private = (struct dasd_eckd_private
*) device
->private;
421 list_move(&device
->alias_list
, &lcu
->inactive_devices
);
422 group
= private->pavgroup
;
425 private->pavgroup
= NULL
;
426 if (list_empty(&group
->baselist
) && list_empty(&group
->aliaslist
)) {
427 list_del(&group
->group
);
431 if (group
->next
== device
)
435 static int read_unit_address_configuration(struct dasd_device
*device
,
436 struct alias_lcu
*lcu
)
438 struct dasd_psf_prssd_data
*prssdp
;
439 struct dasd_ccw_req
*cqr
;
444 cqr
= dasd_kmalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
445 (sizeof(struct dasd_psf_prssd_data
)),
449 cqr
->startdev
= device
;
450 cqr
->memdev
= device
;
451 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
453 cqr
->expires
= 20 * HZ
;
455 /* Prepare for Read Subsystem Data */
456 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
457 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
458 prssdp
->order
= PSF_ORDER_PRSSD
;
459 prssdp
->suborder
= 0x0e; /* Read unit address configuration */
460 /* all other bytes of prssdp must be zero */
463 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
464 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
465 ccw
->flags
|= CCW_FLAG_CC
;
466 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
468 /* Read Subsystem Data - feature codes */
469 memset(lcu
->uac
, 0, sizeof(*(lcu
->uac
)));
472 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
473 ccw
->count
= sizeof(*(lcu
->uac
));
474 ccw
->cda
= (__u32
)(addr_t
) lcu
->uac
;
476 cqr
->buildclk
= get_clock();
477 cqr
->status
= DASD_CQR_FILLED
;
479 /* need to unset flag here to detect race with summary unit check */
480 spin_lock_irqsave(&lcu
->lock
, flags
);
481 lcu
->flags
&= ~NEED_UAC_UPDATE
;
482 spin_unlock_irqrestore(&lcu
->lock
, flags
);
485 rc
= dasd_sleep_on(cqr
);
486 } while (rc
&& (cqr
->retries
> 0));
488 spin_lock_irqsave(&lcu
->lock
, flags
);
489 lcu
->flags
|= NEED_UAC_UPDATE
;
490 spin_unlock_irqrestore(&lcu
->lock
, flags
);
492 dasd_kfree_request(cqr
, cqr
->memdev
);
496 static int _lcu_update(struct dasd_device
*refdev
, struct alias_lcu
*lcu
)
499 struct alias_pav_group
*pavgroup
, *tempgroup
;
500 struct dasd_device
*device
, *tempdev
;
502 struct dasd_eckd_private
*private;
504 spin_lock_irqsave(&lcu
->lock
, flags
);
505 list_for_each_entry_safe(pavgroup
, tempgroup
, &lcu
->grouplist
, group
) {
506 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->baselist
,
508 list_move(&device
->alias_list
, &lcu
->active_devices
);
509 private = (struct dasd_eckd_private
*) device
->private;
510 private->pavgroup
= NULL
;
512 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->aliaslist
,
514 list_move(&device
->alias_list
, &lcu
->active_devices
);
515 private = (struct dasd_eckd_private
*) device
->private;
516 private->pavgroup
= NULL
;
518 list_del(&pavgroup
->group
);
521 spin_unlock_irqrestore(&lcu
->lock
, flags
);
523 rc
= read_unit_address_configuration(refdev
, lcu
);
527 spin_lock_irqsave(&lcu
->lock
, flags
);
529 for (i
= 0; i
< MAX_DEVICES_PER_LCU
; ++i
) {
530 switch (lcu
->uac
->unit
[i
].ua_type
) {
531 case UA_BASE_PAV_ALIAS
:
534 case UA_HYPER_PAV_ALIAS
:
535 lcu
->pav
= HYPER_PAV
;
538 if (lcu
->pav
!= NO_PAV
)
542 list_for_each_entry_safe(device
, tempdev
, &lcu
->active_devices
,
544 _add_device_to_lcu(lcu
, device
);
546 spin_unlock_irqrestore(&lcu
->lock
, flags
);
550 static void lcu_update_work(struct work_struct
*work
)
552 struct alias_lcu
*lcu
;
553 struct read_uac_work_data
*ruac_data
;
554 struct dasd_device
*device
;
558 ruac_data
= container_of(work
, struct read_uac_work_data
, dwork
.work
);
559 lcu
= container_of(ruac_data
, struct alias_lcu
, ruac_data
);
560 device
= ruac_data
->device
;
561 rc
= _lcu_update(device
, lcu
);
563 * Need to check flags again, as there could have been another
564 * prepare_update or a new device a new device while we were still
565 * processing the data
567 spin_lock_irqsave(&lcu
->lock
, flags
);
568 if (rc
|| (lcu
->flags
& NEED_UAC_UPDATE
)) {
569 DBF_DEV_EVENT(DBF_WARNING
, device
, "could not update"
570 " alias data in lcu (rc = %d), retry later", rc
);
571 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 30*HZ
);
573 lcu
->ruac_data
.device
= NULL
;
574 lcu
->flags
&= ~UPDATE_PENDING
;
576 spin_unlock_irqrestore(&lcu
->lock
, flags
);
579 static int _schedule_lcu_update(struct alias_lcu
*lcu
,
580 struct dasd_device
*device
)
582 struct dasd_device
*usedev
= NULL
;
583 struct alias_pav_group
*group
;
585 lcu
->flags
|= NEED_UAC_UPDATE
;
586 if (lcu
->ruac_data
.device
) {
587 /* already scheduled or running */
590 if (device
&& !list_empty(&device
->alias_list
))
593 if (!usedev
&& !list_empty(&lcu
->grouplist
)) {
594 group
= list_first_entry(&lcu
->grouplist
,
595 struct alias_pav_group
, group
);
596 if (!list_empty(&group
->baselist
))
597 usedev
= list_first_entry(&group
->baselist
,
600 else if (!list_empty(&group
->aliaslist
))
601 usedev
= list_first_entry(&group
->aliaslist
,
605 if (!usedev
&& !list_empty(&lcu
->active_devices
)) {
606 usedev
= list_first_entry(&lcu
->active_devices
,
607 struct dasd_device
, alias_list
);
610 * if we haven't found a proper device yet, give up for now, the next
611 * device that will be set active will trigger an lcu update
615 lcu
->ruac_data
.device
= usedev
;
616 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 0);
620 int dasd_alias_add_device(struct dasd_device
*device
)
622 struct dasd_eckd_private
*private;
623 struct alias_lcu
*lcu
;
627 private = (struct dasd_eckd_private
*) device
->private;
630 spin_lock_irqsave(&lcu
->lock
, flags
);
631 if (!(lcu
->flags
& UPDATE_PENDING
)) {
632 rc
= _add_device_to_lcu(lcu
, device
);
634 lcu
->flags
|= UPDATE_PENDING
;
636 if (lcu
->flags
& UPDATE_PENDING
) {
637 list_move(&device
->alias_list
, &lcu
->active_devices
);
638 _schedule_lcu_update(lcu
, device
);
640 spin_unlock_irqrestore(&lcu
->lock
, flags
);
644 int dasd_alias_remove_device(struct dasd_device
*device
)
646 struct dasd_eckd_private
*private;
647 struct alias_lcu
*lcu
;
650 private = (struct dasd_eckd_private
*) device
->private;
652 spin_lock_irqsave(&lcu
->lock
, flags
);
653 _remove_device_from_lcu(lcu
, device
);
654 spin_unlock_irqrestore(&lcu
->lock
, flags
);
658 struct dasd_device
*dasd_alias_get_start_dev(struct dasd_device
*base_device
)
661 struct dasd_device
*alias_device
;
662 struct alias_pav_group
*group
;
663 struct alias_lcu
*lcu
;
664 struct dasd_eckd_private
*private, *alias_priv
;
667 private = (struct dasd_eckd_private
*) base_device
->private;
668 group
= private->pavgroup
;
672 if (lcu
->pav
== NO_PAV
||
673 lcu
->flags
& (NEED_UAC_UPDATE
| UPDATE_PENDING
))
676 spin_lock_irqsave(&lcu
->lock
, flags
);
677 alias_device
= group
->next
;
679 if (list_empty(&group
->aliaslist
)) {
680 spin_unlock_irqrestore(&lcu
->lock
, flags
);
683 alias_device
= list_first_entry(&group
->aliaslist
,
688 if (list_is_last(&alias_device
->alias_list
, &group
->aliaslist
))
689 group
->next
= list_first_entry(&group
->aliaslist
,
690 struct dasd_device
, alias_list
);
692 group
->next
= list_first_entry(&alias_device
->alias_list
,
693 struct dasd_device
, alias_list
);
694 spin_unlock_irqrestore(&lcu
->lock
, flags
);
695 alias_priv
= (struct dasd_eckd_private
*) alias_device
->private;
696 if ((alias_priv
->count
< private->count
) && !alias_device
->stopped
)
703 * Summary unit check handling depends on the way alias devices
704 * are handled so it is done here rather then in dasd_eckd.c
706 static int reset_summary_unit_check(struct alias_lcu
*lcu
,
707 struct dasd_device
*device
,
710 struct dasd_ccw_req
*cqr
;
715 strncpy((char *) &cqr
->magic
, "ECKD", 4);
716 ASCEBC((char *) &cqr
->magic
, 4);
718 ccw
->cmd_code
= DASD_ECKD_CCW_RSCK
;
721 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
722 ((char *)cqr
->data
)[0] = reason
;
724 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
725 cqr
->retries
= 255; /* set retry counter to enable basic ERP */
726 cqr
->startdev
= device
;
727 cqr
->memdev
= device
;
729 cqr
->expires
= 5 * HZ
;
730 cqr
->buildclk
= get_clock();
731 cqr
->status
= DASD_CQR_FILLED
;
733 rc
= dasd_sleep_on_immediatly(cqr
);
737 static void _restart_all_base_devices_on_lcu(struct alias_lcu
*lcu
)
739 struct alias_pav_group
*pavgroup
;
740 struct dasd_device
*device
;
741 struct dasd_eckd_private
*private;
743 /* active and inactive list can contain alias as well as base devices */
744 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
745 private = (struct dasd_eckd_private
*) device
->private;
746 if (private->uid
.type
!= UA_BASE_DEVICE
)
748 dasd_schedule_block_bh(device
->block
);
749 dasd_schedule_device_bh(device
);
751 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
752 private = (struct dasd_eckd_private
*) device
->private;
753 if (private->uid
.type
!= UA_BASE_DEVICE
)
755 dasd_schedule_block_bh(device
->block
);
756 dasd_schedule_device_bh(device
);
758 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
759 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
760 dasd_schedule_block_bh(device
->block
);
761 dasd_schedule_device_bh(device
);
766 static void flush_all_alias_devices_on_lcu(struct alias_lcu
*lcu
)
768 struct alias_pav_group
*pavgroup
;
769 struct dasd_device
*device
, *temp
;
770 struct dasd_eckd_private
*private;
776 * Problem here ist that dasd_flush_device_queue may wait
777 * for termination of a request to complete. We can't keep
778 * the lcu lock during that time, so we must assume that
779 * the lists may have changed.
780 * Idea: first gather all active alias devices in a separate list,
781 * then flush the first element of this list unlocked, and afterwards
782 * check if it is still on the list before moving it to the
783 * active_devices list.
786 spin_lock_irqsave(&lcu
->lock
, flags
);
787 list_for_each_entry_safe(device
, temp
, &lcu
->active_devices
,
789 private = (struct dasd_eckd_private
*) device
->private;
790 if (private->uid
.type
== UA_BASE_DEVICE
)
792 list_move(&device
->alias_list
, &active
);
795 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
796 list_splice_init(&pavgroup
->aliaslist
, &active
);
798 while (!list_empty(&active
)) {
799 device
= list_first_entry(&active
, struct dasd_device
,
801 spin_unlock_irqrestore(&lcu
->lock
, flags
);
802 rc
= dasd_flush_device_queue(device
);
803 spin_lock_irqsave(&lcu
->lock
, flags
);
805 * only move device around if it wasn't moved away while we
806 * were waiting for the flush
808 if (device
== list_first_entry(&active
,
809 struct dasd_device
, alias_list
))
810 list_move(&device
->alias_list
, &lcu
->active_devices
);
812 spin_unlock_irqrestore(&lcu
->lock
, flags
);
815 static void __stop_device_on_lcu(struct dasd_device
*device
,
816 struct dasd_device
*pos
)
818 /* If pos == device then device is already locked! */
820 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
823 spin_lock(get_ccwdev_lock(pos
->cdev
));
824 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
825 spin_unlock(get_ccwdev_lock(pos
->cdev
));
829 * This function is called in interrupt context, so the
830 * cdev lock for device is already locked!
832 static void _stop_all_devices_on_lcu(struct alias_lcu
*lcu
,
833 struct dasd_device
*device
)
835 struct alias_pav_group
*pavgroup
;
836 struct dasd_device
*pos
;
838 list_for_each_entry(pos
, &lcu
->active_devices
, alias_list
)
839 __stop_device_on_lcu(device
, pos
);
840 list_for_each_entry(pos
, &lcu
->inactive_devices
, alias_list
)
841 __stop_device_on_lcu(device
, pos
);
842 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
843 list_for_each_entry(pos
, &pavgroup
->baselist
, alias_list
)
844 __stop_device_on_lcu(device
, pos
);
845 list_for_each_entry(pos
, &pavgroup
->aliaslist
, alias_list
)
846 __stop_device_on_lcu(device
, pos
);
850 static void _unstop_all_devices_on_lcu(struct alias_lcu
*lcu
)
852 struct alias_pav_group
*pavgroup
;
853 struct dasd_device
*device
;
856 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
857 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
858 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
859 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
862 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
863 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
864 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
865 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
868 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
869 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
870 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
871 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
872 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
875 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
876 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
877 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
878 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
884 static void summary_unit_check_handling_work(struct work_struct
*work
)
886 struct alias_lcu
*lcu
;
887 struct summary_unit_check_work_data
*suc_data
;
889 struct dasd_device
*device
;
891 suc_data
= container_of(work
, struct summary_unit_check_work_data
,
893 lcu
= container_of(suc_data
, struct alias_lcu
, suc_data
);
894 device
= suc_data
->device
;
896 /* 1. flush alias devices */
897 flush_all_alias_devices_on_lcu(lcu
);
899 /* 2. reset summary unit check */
900 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
901 dasd_device_remove_stop_bits(device
,
902 (DASD_STOPPED_SU
| DASD_STOPPED_PENDING
));
903 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
904 reset_summary_unit_check(lcu
, device
, suc_data
->reason
);
906 spin_lock_irqsave(&lcu
->lock
, flags
);
907 _unstop_all_devices_on_lcu(lcu
);
908 _restart_all_base_devices_on_lcu(lcu
);
909 /* 3. read new alias configuration */
910 _schedule_lcu_update(lcu
, device
);
911 lcu
->suc_data
.device
= NULL
;
912 spin_unlock_irqrestore(&lcu
->lock
, flags
);
916 * note: this will be called from int handler context (cdev locked)
918 void dasd_alias_handle_summary_unit_check(struct dasd_device
*device
,
921 struct alias_lcu
*lcu
;
923 struct dasd_eckd_private
*private;
926 private = (struct dasd_eckd_private
*) device
->private;
928 sense
= dasd_get_sense(irb
);
931 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
932 "eckd handle summary unit check: reason", reason
);
934 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
935 "eckd handle summary unit check:"
936 " no reason code available");
942 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
943 "device not ready to handle summary"
944 " unit check (no lcu structure)");
947 spin_lock(&lcu
->lock
);
948 _stop_all_devices_on_lcu(lcu
, device
);
949 /* prepare for lcu_update */
950 private->lcu
->flags
|= NEED_UAC_UPDATE
| UPDATE_PENDING
;
951 /* If this device is about to be removed just return and wait for
952 * the next interrupt on a different device
954 if (list_empty(&device
->alias_list
)) {
955 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
956 "device is in offline processing,"
957 " don't do summary unit check handling");
958 spin_unlock(&lcu
->lock
);
961 if (lcu
->suc_data
.device
) {
962 /* already scheduled or running */
963 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
964 "previous instance of summary unit check worker"
966 spin_unlock(&lcu
->lock
);
969 lcu
->suc_data
.reason
= reason
;
970 lcu
->suc_data
.device
= device
;
971 spin_unlock(&lcu
->lock
);
972 schedule_work(&lcu
->suc_data
.worker
);