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 #define KMSG_COMPONENT "dasd-eckd"
11 #include <linux/list.h>
12 #include <linux/slab.h>
13 #include <asm/ebcdic.h>
15 #include "dasd_eckd.h"
19 #endif /* PRINTK_HEADER */
20 #define PRINTK_HEADER "dasd(eckd):"
24 * General concept of alias management:
25 * - PAV and DASD alias management is specific to the eckd discipline.
26 * - A device is connected to an lcu as long as the device exists.
27 * dasd_alias_make_device_known_to_lcu will be called wenn the
28 * device is checked by the eckd discipline and
29 * dasd_alias_disconnect_device_from_lcu will be called
30 * before the device is deleted.
31 * - The dasd_alias_add_device / dasd_alias_remove_device
32 * functions mark the point when a device is 'ready for service'.
33 * - A summary unit check is a rare occasion, but it is mandatory to
34 * support it. It requires some complex recovery actions before the
35 * devices can be used again (see dasd_alias_handle_summary_unit_check).
36 * - dasd_alias_get_start_dev will find an alias device that can be used
37 * instead of the base device and does some (very simple) load balancing.
38 * This is the function that gets called for each I/O, so when improving
39 * something, this function should get faster or better, the rest has just
44 static void summary_unit_check_handling_work(struct work_struct
*);
45 static void lcu_update_work(struct work_struct
*);
46 static int _schedule_lcu_update(struct alias_lcu
*, struct dasd_device
*);
48 static struct alias_root aliastree
= {
49 .serverlist
= LIST_HEAD_INIT(aliastree
.serverlist
),
50 .lock
= __SPIN_LOCK_UNLOCKED(aliastree
.lock
),
53 static struct alias_server
*_find_server(struct dasd_uid
*uid
)
55 struct alias_server
*pos
;
56 list_for_each_entry(pos
, &aliastree
.serverlist
, server
) {
57 if (!strncmp(pos
->uid
.vendor
, uid
->vendor
,
59 && !strncmp(pos
->uid
.serial
, uid
->serial
,
66 static struct alias_lcu
*_find_lcu(struct alias_server
*server
,
69 struct alias_lcu
*pos
;
70 list_for_each_entry(pos
, &server
->lculist
, lcu
) {
71 if (pos
->uid
.ssid
== uid
->ssid
)
77 static struct alias_pav_group
*_find_group(struct alias_lcu
*lcu
,
80 struct alias_pav_group
*pos
;
81 __u8 search_unit_addr
;
83 /* for hyper pav there is only one group */
84 if (lcu
->pav
== HYPER_PAV
) {
85 if (list_empty(&lcu
->grouplist
))
88 return list_first_entry(&lcu
->grouplist
,
89 struct alias_pav_group
, group
);
92 /* for base pav we have to find the group that matches the base */
93 if (uid
->type
== UA_BASE_DEVICE
)
94 search_unit_addr
= uid
->real_unit_addr
;
96 search_unit_addr
= uid
->base_unit_addr
;
97 list_for_each_entry(pos
, &lcu
->grouplist
, group
) {
98 if (pos
->uid
.base_unit_addr
== search_unit_addr
&&
99 !strncmp(pos
->uid
.vduit
, uid
->vduit
, sizeof(uid
->vduit
)))
105 static struct alias_server
*_allocate_server(struct dasd_uid
*uid
)
107 struct alias_server
*server
;
109 server
= kzalloc(sizeof(*server
), GFP_KERNEL
);
111 return ERR_PTR(-ENOMEM
);
112 memcpy(server
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
113 memcpy(server
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
114 INIT_LIST_HEAD(&server
->server
);
115 INIT_LIST_HEAD(&server
->lculist
);
119 static void _free_server(struct alias_server
*server
)
124 static struct alias_lcu
*_allocate_lcu(struct dasd_uid
*uid
)
126 struct alias_lcu
*lcu
;
128 lcu
= kzalloc(sizeof(*lcu
), GFP_KERNEL
);
130 return ERR_PTR(-ENOMEM
);
131 lcu
->uac
= kzalloc(sizeof(*(lcu
->uac
)), GFP_KERNEL
| GFP_DMA
);
134 lcu
->rsu_cqr
= kzalloc(sizeof(*lcu
->rsu_cqr
), GFP_KERNEL
| GFP_DMA
);
137 lcu
->rsu_cqr
->cpaddr
= kzalloc(sizeof(struct ccw1
),
138 GFP_KERNEL
| GFP_DMA
);
139 if (!lcu
->rsu_cqr
->cpaddr
)
141 lcu
->rsu_cqr
->data
= kzalloc(16, GFP_KERNEL
| GFP_DMA
);
142 if (!lcu
->rsu_cqr
->data
)
145 memcpy(lcu
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
146 memcpy(lcu
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
147 lcu
->uid
.ssid
= uid
->ssid
;
149 lcu
->flags
= NEED_UAC_UPDATE
| UPDATE_PENDING
;
150 INIT_LIST_HEAD(&lcu
->lcu
);
151 INIT_LIST_HEAD(&lcu
->inactive_devices
);
152 INIT_LIST_HEAD(&lcu
->active_devices
);
153 INIT_LIST_HEAD(&lcu
->grouplist
);
154 INIT_WORK(&lcu
->suc_data
.worker
, summary_unit_check_handling_work
);
155 INIT_DELAYED_WORK(&lcu
->ruac_data
.dwork
, lcu_update_work
);
156 spin_lock_init(&lcu
->lock
);
157 init_completion(&lcu
->lcu_setup
);
161 kfree(lcu
->rsu_cqr
->cpaddr
);
168 return ERR_PTR(-ENOMEM
);
171 static void _free_lcu(struct alias_lcu
*lcu
)
173 kfree(lcu
->rsu_cqr
->data
);
174 kfree(lcu
->rsu_cqr
->cpaddr
);
181 * This is the function that will allocate all the server and lcu data,
182 * so this function must be called first for a new device.
183 * If the return value is 1, the lcu was already known before, if it
184 * is 0, this is a new lcu.
185 * Negative return code indicates that something went wrong (e.g. -ENOMEM)
187 int dasd_alias_make_device_known_to_lcu(struct dasd_device
*device
)
189 struct dasd_eckd_private
*private = device
->private;
191 struct alias_server
*server
, *newserver
;
192 struct alias_lcu
*lcu
, *newlcu
;
195 device
->discipline
->get_uid(device
, &uid
);
196 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
);
209 /* someone was faster */
210 _free_server(newserver
);
214 lcu
= _find_lcu(server
, &uid
);
216 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
217 newlcu
= _allocate_lcu(&uid
);
219 return PTR_ERR(newlcu
);
220 spin_lock_irqsave(&aliastree
.lock
, flags
);
221 lcu
= _find_lcu(server
, &uid
);
223 list_add(&newlcu
->lcu
, &server
->lculist
);
226 /* someone was faster */
230 spin_lock(&lcu
->lock
);
231 list_add(&device
->alias_list
, &lcu
->inactive_devices
);
233 spin_unlock(&lcu
->lock
);
234 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
240 * This function removes a device from the scope of alias management.
241 * The complicated part is to make sure that it is not in use by
242 * any of the workers. If necessary cancel the work.
244 void dasd_alias_disconnect_device_from_lcu(struct dasd_device
*device
)
246 struct dasd_eckd_private
*private = device
->private;
248 struct alias_lcu
*lcu
;
249 struct alias_server
*server
;
254 /* nothing to do if already disconnected */
257 device
->discipline
->get_uid(device
, &uid
);
258 spin_lock_irqsave(&lcu
->lock
, flags
);
259 list_del_init(&device
->alias_list
);
260 /* make sure that the workers don't use this device */
261 if (device
== lcu
->suc_data
.device
) {
262 spin_unlock_irqrestore(&lcu
->lock
, flags
);
263 cancel_work_sync(&lcu
->suc_data
.worker
);
264 spin_lock_irqsave(&lcu
->lock
, flags
);
265 if (device
== lcu
->suc_data
.device
) {
266 dasd_put_device(device
);
267 lcu
->suc_data
.device
= NULL
;
271 if (device
== lcu
->ruac_data
.device
) {
272 spin_unlock_irqrestore(&lcu
->lock
, flags
);
274 cancel_delayed_work_sync(&lcu
->ruac_data
.dwork
);
275 spin_lock_irqsave(&lcu
->lock
, flags
);
276 if (device
== lcu
->ruac_data
.device
) {
277 dasd_put_device(device
);
278 lcu
->ruac_data
.device
= NULL
;
282 spin_unlock_irqrestore(&lcu
->lock
, flags
);
284 spin_lock_irqsave(&aliastree
.lock
, flags
);
285 spin_lock(&lcu
->lock
);
286 if (list_empty(&lcu
->grouplist
) &&
287 list_empty(&lcu
->active_devices
) &&
288 list_empty(&lcu
->inactive_devices
)) {
290 spin_unlock(&lcu
->lock
);
295 _schedule_lcu_update(lcu
, NULL
);
296 spin_unlock(&lcu
->lock
);
298 server
= _find_server(&uid
);
299 if (server
&& list_empty(&server
->lculist
)) {
300 list_del(&server
->server
);
301 _free_server(server
);
303 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
307 * This function assumes that the unit address configuration stored
308 * in the lcu is up to date and will update the device uid before
309 * adding it to a pav group.
312 static int _add_device_to_lcu(struct alias_lcu
*lcu
,
313 struct dasd_device
*device
,
314 struct dasd_device
*pos
)
317 struct dasd_eckd_private
*private = device
->private;
318 struct alias_pav_group
*group
;
321 spin_lock(get_ccwdev_lock(device
->cdev
));
322 private->uid
.type
= lcu
->uac
->unit
[private->uid
.real_unit_addr
].ua_type
;
323 private->uid
.base_unit_addr
=
324 lcu
->uac
->unit
[private->uid
.real_unit_addr
].base_ua
;
326 spin_unlock(get_ccwdev_lock(device
->cdev
));
327 /* if we have no PAV anyway, we don't need to bother with PAV groups */
328 if (lcu
->pav
== NO_PAV
) {
329 list_move(&device
->alias_list
, &lcu
->active_devices
);
332 group
= _find_group(lcu
, &uid
);
334 group
= kzalloc(sizeof(*group
), GFP_ATOMIC
);
337 memcpy(group
->uid
.vendor
, uid
.vendor
, sizeof(uid
.vendor
));
338 memcpy(group
->uid
.serial
, uid
.serial
, sizeof(uid
.serial
));
339 group
->uid
.ssid
= uid
.ssid
;
340 if (uid
.type
== UA_BASE_DEVICE
)
341 group
->uid
.base_unit_addr
= uid
.real_unit_addr
;
343 group
->uid
.base_unit_addr
= uid
.base_unit_addr
;
344 memcpy(group
->uid
.vduit
, uid
.vduit
, sizeof(uid
.vduit
));
345 INIT_LIST_HEAD(&group
->group
);
346 INIT_LIST_HEAD(&group
->baselist
);
347 INIT_LIST_HEAD(&group
->aliaslist
);
348 list_add(&group
->group
, &lcu
->grouplist
);
350 if (uid
.type
== UA_BASE_DEVICE
)
351 list_move(&device
->alias_list
, &group
->baselist
);
353 list_move(&device
->alias_list
, &group
->aliaslist
);
354 private->pavgroup
= group
;
358 static void _remove_device_from_lcu(struct alias_lcu
*lcu
,
359 struct dasd_device
*device
)
361 struct dasd_eckd_private
*private = device
->private;
362 struct alias_pav_group
*group
;
364 list_move(&device
->alias_list
, &lcu
->inactive_devices
);
365 group
= private->pavgroup
;
368 private->pavgroup
= NULL
;
369 if (list_empty(&group
->baselist
) && list_empty(&group
->aliaslist
)) {
370 list_del(&group
->group
);
374 if (group
->next
== device
)
379 suborder_not_supported(struct dasd_ccw_req
*cqr
)
387 * intrc values ENODEV, ENOLINK and EPERM
388 * will be optained from sleep_on to indicate that no
389 * IO operation can be started
391 if (cqr
->intrc
== -ENODEV
)
394 if (cqr
->intrc
== -ENOLINK
)
397 if (cqr
->intrc
== -EPERM
)
400 sense
= dasd_get_sense(&cqr
->irb
);
405 msg_format
= (sense
[7] & 0xF0);
406 msg_no
= (sense
[7] & 0x0F);
408 /* command reject, Format 0 MSG 4 - invalid parameter */
409 if ((reason
== 0x80) && (msg_format
== 0x00) && (msg_no
== 0x04))
415 static int read_unit_address_configuration(struct dasd_device
*device
,
416 struct alias_lcu
*lcu
)
418 struct dasd_psf_prssd_data
*prssdp
;
419 struct dasd_ccw_req
*cqr
;
424 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
425 (sizeof(struct dasd_psf_prssd_data
)),
429 cqr
->startdev
= device
;
430 cqr
->memdev
= device
;
431 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
433 cqr
->expires
= 20 * HZ
;
435 /* Prepare for Read Subsystem Data */
436 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
437 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
438 prssdp
->order
= PSF_ORDER_PRSSD
;
439 prssdp
->suborder
= 0x0e; /* Read unit address configuration */
440 /* all other bytes of prssdp must be zero */
443 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
444 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
445 ccw
->flags
|= CCW_FLAG_CC
;
446 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
448 /* Read Subsystem Data - feature codes */
449 memset(lcu
->uac
, 0, sizeof(*(lcu
->uac
)));
452 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
453 ccw
->count
= sizeof(*(lcu
->uac
));
454 ccw
->cda
= (__u32
)(addr_t
) lcu
->uac
;
456 cqr
->buildclk
= get_tod_clock();
457 cqr
->status
= DASD_CQR_FILLED
;
459 /* need to unset flag here to detect race with summary unit check */
460 spin_lock_irqsave(&lcu
->lock
, flags
);
461 lcu
->flags
&= ~NEED_UAC_UPDATE
;
462 spin_unlock_irqrestore(&lcu
->lock
, flags
);
464 rc
= dasd_sleep_on(cqr
);
468 if (suborder_not_supported(cqr
)) {
469 /* suborder not supported or device unusable for IO */
472 /* IO failed but should be retried */
473 spin_lock_irqsave(&lcu
->lock
, flags
);
474 lcu
->flags
|= NEED_UAC_UPDATE
;
475 spin_unlock_irqrestore(&lcu
->lock
, flags
);
478 dasd_sfree_request(cqr
, cqr
->memdev
);
482 static int _lcu_update(struct dasd_device
*refdev
, struct alias_lcu
*lcu
)
485 struct alias_pav_group
*pavgroup
, *tempgroup
;
486 struct dasd_device
*device
, *tempdev
;
488 struct dasd_eckd_private
*private;
490 spin_lock_irqsave(&lcu
->lock
, flags
);
491 list_for_each_entry_safe(pavgroup
, tempgroup
, &lcu
->grouplist
, group
) {
492 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->baselist
,
494 list_move(&device
->alias_list
, &lcu
->active_devices
);
495 private = device
->private;
496 private->pavgroup
= NULL
;
498 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->aliaslist
,
500 list_move(&device
->alias_list
, &lcu
->active_devices
);
501 private = device
->private;
502 private->pavgroup
= NULL
;
504 list_del(&pavgroup
->group
);
507 spin_unlock_irqrestore(&lcu
->lock
, flags
);
509 rc
= read_unit_address_configuration(refdev
, lcu
);
513 spin_lock_irqsave(&lcu
->lock
, flags
);
515 * there is another update needed skip the remaining handling
516 * the data might already be outdated
517 * but especially do not add the device to an LCU with pending
520 if (lcu
->flags
& NEED_UAC_UPDATE
)
523 for (i
= 0; i
< MAX_DEVICES_PER_LCU
; ++i
) {
524 switch (lcu
->uac
->unit
[i
].ua_type
) {
525 case UA_BASE_PAV_ALIAS
:
528 case UA_HYPER_PAV_ALIAS
:
529 lcu
->pav
= HYPER_PAV
;
532 if (lcu
->pav
!= NO_PAV
)
536 list_for_each_entry_safe(device
, tempdev
, &lcu
->active_devices
,
538 _add_device_to_lcu(lcu
, device
, refdev
);
541 spin_unlock_irqrestore(&lcu
->lock
, flags
);
545 static void lcu_update_work(struct work_struct
*work
)
547 struct alias_lcu
*lcu
;
548 struct read_uac_work_data
*ruac_data
;
549 struct dasd_device
*device
;
553 ruac_data
= container_of(work
, struct read_uac_work_data
, dwork
.work
);
554 lcu
= container_of(ruac_data
, struct alias_lcu
, ruac_data
);
555 device
= ruac_data
->device
;
556 rc
= _lcu_update(device
, lcu
);
558 * Need to check flags again, as there could have been another
559 * prepare_update or a new device a new device while we were still
560 * processing the data
562 spin_lock_irqsave(&lcu
->lock
, flags
);
563 if ((rc
&& (rc
!= -EOPNOTSUPP
)) || (lcu
->flags
& NEED_UAC_UPDATE
)) {
564 DBF_DEV_EVENT(DBF_WARNING
, device
, "could not update"
565 " alias data in lcu (rc = %d), retry later", rc
);
566 if (!schedule_delayed_work(&lcu
->ruac_data
.dwork
, 30*HZ
))
567 dasd_put_device(device
);
569 dasd_put_device(device
);
570 lcu
->ruac_data
.device
= NULL
;
571 lcu
->flags
&= ~UPDATE_PENDING
;
573 spin_unlock_irqrestore(&lcu
->lock
, flags
);
576 static int _schedule_lcu_update(struct alias_lcu
*lcu
,
577 struct dasd_device
*device
)
579 struct dasd_device
*usedev
= NULL
;
580 struct alias_pav_group
*group
;
582 lcu
->flags
|= NEED_UAC_UPDATE
;
583 if (lcu
->ruac_data
.device
) {
584 /* already scheduled or running */
587 if (device
&& !list_empty(&device
->alias_list
))
590 if (!usedev
&& !list_empty(&lcu
->grouplist
)) {
591 group
= list_first_entry(&lcu
->grouplist
,
592 struct alias_pav_group
, group
);
593 if (!list_empty(&group
->baselist
))
594 usedev
= list_first_entry(&group
->baselist
,
597 else if (!list_empty(&group
->aliaslist
))
598 usedev
= list_first_entry(&group
->aliaslist
,
602 if (!usedev
&& !list_empty(&lcu
->active_devices
)) {
603 usedev
= list_first_entry(&lcu
->active_devices
,
604 struct dasd_device
, alias_list
);
607 * if we haven't found a proper device yet, give up for now, the next
608 * device that will be set active will trigger an lcu update
612 dasd_get_device(usedev
);
613 lcu
->ruac_data
.device
= usedev
;
614 if (!schedule_delayed_work(&lcu
->ruac_data
.dwork
, 0))
615 dasd_put_device(usedev
);
619 int dasd_alias_add_device(struct dasd_device
*device
)
621 struct dasd_eckd_private
*private = device
->private;
622 __u8 uaddr
= private->uid
.real_unit_addr
;
623 struct alias_lcu
*lcu
= private->lcu
;
628 spin_lock_irqsave(&lcu
->lock
, flags
);
630 * Check if device and lcu type differ. If so, the uac data may be
631 * outdated and needs to be updated.
633 if (private->uid
.type
!= lcu
->uac
->unit
[uaddr
].ua_type
) {
634 lcu
->flags
|= UPDATE_PENDING
;
635 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
636 "uid type mismatch - trigger rescan");
638 if (!(lcu
->flags
& UPDATE_PENDING
)) {
639 rc
= _add_device_to_lcu(lcu
, device
, device
);
641 lcu
->flags
|= UPDATE_PENDING
;
643 if (lcu
->flags
& UPDATE_PENDING
) {
644 list_move(&device
->alias_list
, &lcu
->active_devices
);
645 _schedule_lcu_update(lcu
, device
);
647 spin_unlock_irqrestore(&lcu
->lock
, flags
);
651 int dasd_alias_update_add_device(struct dasd_device
*device
)
653 struct dasd_eckd_private
*private = device
->private;
655 private->lcu
->flags
|= UPDATE_PENDING
;
656 return dasd_alias_add_device(device
);
659 int dasd_alias_remove_device(struct dasd_device
*device
)
661 struct dasd_eckd_private
*private = device
->private;
662 struct alias_lcu
*lcu
= private->lcu
;
665 /* nothing to do if already removed */
668 spin_lock_irqsave(&lcu
->lock
, flags
);
669 _remove_device_from_lcu(lcu
, device
);
670 spin_unlock_irqrestore(&lcu
->lock
, flags
);
674 struct dasd_device
*dasd_alias_get_start_dev(struct dasd_device
*base_device
)
676 struct dasd_eckd_private
*alias_priv
, *private = base_device
->private;
677 struct alias_pav_group
*group
= private->pavgroup
;
678 struct alias_lcu
*lcu
= private->lcu
;
679 struct dasd_device
*alias_device
;
684 if (lcu
->pav
== NO_PAV
||
685 lcu
->flags
& (NEED_UAC_UPDATE
| UPDATE_PENDING
))
687 if (unlikely(!(private->features
.feature
[8] & 0x01))) {
689 * PAV enabled but prefix not, very unlikely
690 * seems to be a lost pathgroup
691 * use base device to do IO
693 DBF_DEV_EVENT(DBF_ERR
, base_device
, "%s",
694 "Prefix not enabled with PAV enabled\n");
698 spin_lock_irqsave(&lcu
->lock
, flags
);
699 alias_device
= group
->next
;
701 if (list_empty(&group
->aliaslist
)) {
702 spin_unlock_irqrestore(&lcu
->lock
, flags
);
705 alias_device
= list_first_entry(&group
->aliaslist
,
710 if (list_is_last(&alias_device
->alias_list
, &group
->aliaslist
))
711 group
->next
= list_first_entry(&group
->aliaslist
,
712 struct dasd_device
, alias_list
);
714 group
->next
= list_first_entry(&alias_device
->alias_list
,
715 struct dasd_device
, alias_list
);
716 spin_unlock_irqrestore(&lcu
->lock
, flags
);
717 alias_priv
= alias_device
->private;
718 if ((alias_priv
->count
< private->count
) && !alias_device
->stopped
&&
719 !test_bit(DASD_FLAG_OFFLINE
, &alias_device
->flags
))
726 * Summary unit check handling depends on the way alias devices
727 * are handled so it is done here rather then in dasd_eckd.c
729 static int reset_summary_unit_check(struct alias_lcu
*lcu
,
730 struct dasd_device
*device
,
733 struct dasd_ccw_req
*cqr
;
738 memcpy((char *) &cqr
->magic
, "ECKD", 4);
739 ASCEBC((char *) &cqr
->magic
, 4);
741 ccw
->cmd_code
= DASD_ECKD_CCW_RSCK
;
742 ccw
->flags
= CCW_FLAG_SLI
;
744 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
745 ((char *)cqr
->data
)[0] = reason
;
747 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
748 cqr
->retries
= 255; /* set retry counter to enable basic ERP */
749 cqr
->startdev
= device
;
750 cqr
->memdev
= device
;
752 cqr
->expires
= 5 * HZ
;
753 cqr
->buildclk
= get_tod_clock();
754 cqr
->status
= DASD_CQR_FILLED
;
756 rc
= dasd_sleep_on_immediatly(cqr
);
760 static void _restart_all_base_devices_on_lcu(struct alias_lcu
*lcu
)
762 struct alias_pav_group
*pavgroup
;
763 struct dasd_device
*device
;
764 struct dasd_eckd_private
*private;
766 /* active and inactive list can contain alias as well as base devices */
767 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
768 private = device
->private;
769 if (private->uid
.type
!= UA_BASE_DEVICE
)
771 dasd_schedule_block_bh(device
->block
);
772 dasd_schedule_device_bh(device
);
774 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
775 private = device
->private;
776 if (private->uid
.type
!= UA_BASE_DEVICE
)
778 dasd_schedule_block_bh(device
->block
);
779 dasd_schedule_device_bh(device
);
781 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
782 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
783 dasd_schedule_block_bh(device
->block
);
784 dasd_schedule_device_bh(device
);
789 static void flush_all_alias_devices_on_lcu(struct alias_lcu
*lcu
)
791 struct alias_pav_group
*pavgroup
;
792 struct dasd_device
*device
, *temp
;
793 struct dasd_eckd_private
*private;
798 * Problem here ist that dasd_flush_device_queue may wait
799 * for termination of a request to complete. We can't keep
800 * the lcu lock during that time, so we must assume that
801 * the lists may have changed.
802 * Idea: first gather all active alias devices in a separate list,
803 * then flush the first element of this list unlocked, and afterwards
804 * check if it is still on the list before moving it to the
805 * active_devices list.
808 spin_lock_irqsave(&lcu
->lock
, flags
);
809 list_for_each_entry_safe(device
, temp
, &lcu
->active_devices
,
811 private = device
->private;
812 if (private->uid
.type
== UA_BASE_DEVICE
)
814 list_move(&device
->alias_list
, &active
);
817 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
818 list_splice_init(&pavgroup
->aliaslist
, &active
);
820 while (!list_empty(&active
)) {
821 device
= list_first_entry(&active
, struct dasd_device
,
823 spin_unlock_irqrestore(&lcu
->lock
, flags
);
824 dasd_flush_device_queue(device
);
825 spin_lock_irqsave(&lcu
->lock
, flags
);
827 * only move device around if it wasn't moved away while we
828 * were waiting for the flush
830 if (device
== list_first_entry(&active
,
831 struct dasd_device
, alias_list
)) {
832 list_move(&device
->alias_list
, &lcu
->active_devices
);
833 private = device
->private;
834 private->pavgroup
= NULL
;
837 spin_unlock_irqrestore(&lcu
->lock
, flags
);
840 static void _stop_all_devices_on_lcu(struct alias_lcu
*lcu
)
842 struct alias_pav_group
*pavgroup
;
843 struct dasd_device
*device
;
845 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
846 spin_lock(get_ccwdev_lock(device
->cdev
));
847 dasd_device_set_stop_bits(device
, DASD_STOPPED_SU
);
848 spin_unlock(get_ccwdev_lock(device
->cdev
));
850 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
851 spin_lock(get_ccwdev_lock(device
->cdev
));
852 dasd_device_set_stop_bits(device
, DASD_STOPPED_SU
);
853 spin_unlock(get_ccwdev_lock(device
->cdev
));
855 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
856 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
857 spin_lock(get_ccwdev_lock(device
->cdev
));
858 dasd_device_set_stop_bits(device
, DASD_STOPPED_SU
);
859 spin_unlock(get_ccwdev_lock(device
->cdev
));
861 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
862 spin_lock(get_ccwdev_lock(device
->cdev
));
863 dasd_device_set_stop_bits(device
, DASD_STOPPED_SU
);
864 spin_unlock(get_ccwdev_lock(device
->cdev
));
869 static void _unstop_all_devices_on_lcu(struct alias_lcu
*lcu
)
871 struct alias_pav_group
*pavgroup
;
872 struct dasd_device
*device
;
874 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
875 spin_lock(get_ccwdev_lock(device
->cdev
));
876 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
877 spin_unlock(get_ccwdev_lock(device
->cdev
));
879 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
880 spin_lock(get_ccwdev_lock(device
->cdev
));
881 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
882 spin_unlock(get_ccwdev_lock(device
->cdev
));
884 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
885 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
886 spin_lock(get_ccwdev_lock(device
->cdev
));
887 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
888 spin_unlock(get_ccwdev_lock(device
->cdev
));
890 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
891 spin_lock(get_ccwdev_lock(device
->cdev
));
892 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
893 spin_unlock(get_ccwdev_lock(device
->cdev
));
898 static void summary_unit_check_handling_work(struct work_struct
*work
)
900 struct alias_lcu
*lcu
;
901 struct summary_unit_check_work_data
*suc_data
;
903 struct dasd_device
*device
;
905 suc_data
= container_of(work
, struct summary_unit_check_work_data
,
907 lcu
= container_of(suc_data
, struct alias_lcu
, suc_data
);
908 device
= suc_data
->device
;
910 /* 1. flush alias devices */
911 flush_all_alias_devices_on_lcu(lcu
);
913 /* 2. reset summary unit check */
914 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
915 dasd_device_remove_stop_bits(device
,
916 (DASD_STOPPED_SU
| DASD_STOPPED_PENDING
));
917 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
918 reset_summary_unit_check(lcu
, device
, suc_data
->reason
);
920 spin_lock_irqsave(&lcu
->lock
, flags
);
921 _unstop_all_devices_on_lcu(lcu
);
922 _restart_all_base_devices_on_lcu(lcu
);
923 /* 3. read new alias configuration */
924 _schedule_lcu_update(lcu
, device
);
925 lcu
->suc_data
.device
= NULL
;
926 dasd_put_device(device
);
927 spin_unlock_irqrestore(&lcu
->lock
, flags
);
930 void dasd_alias_handle_summary_unit_check(struct work_struct
*work
)
932 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
934 struct dasd_eckd_private
*private = device
->private;
935 struct alias_lcu
*lcu
;
940 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
941 "device not ready to handle summary"
942 " unit check (no lcu structure)");
945 spin_lock_irqsave(&lcu
->lock
, flags
);
946 /* If this device is about to be removed just return and wait for
947 * the next interrupt on a different device
949 if (list_empty(&device
->alias_list
)) {
950 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
951 "device is in offline processing,"
952 " don't do summary unit check handling");
955 if (lcu
->suc_data
.device
) {
956 /* already scheduled or running */
957 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
958 "previous instance of summary unit check worker"
962 _stop_all_devices_on_lcu(lcu
);
963 /* prepare for lcu_update */
964 lcu
->flags
|= NEED_UAC_UPDATE
| UPDATE_PENDING
;
965 lcu
->suc_data
.reason
= private->suc_reason
;
966 lcu
->suc_data
.device
= device
;
967 dasd_get_device(device
);
968 if (!schedule_work(&lcu
->suc_data
.worker
))
969 dasd_put_device(device
);
971 spin_unlock_irqrestore(&lcu
->lock
, flags
);
973 clear_bit(DASD_FLAG_SUC
, &device
->flags
);
974 dasd_put_device(device
);