]>
Commit | Line | Data |
---|---|---|
8e09f215 SW |
1 | /* |
2 | * PAV alias management for the DASD ECKD discipline | |
3 | * | |
a53c8fab | 4 | * Copyright IBM Corp. 2007 |
8e09f215 SW |
5 | * Author(s): Stefan Weinhuber <wein@de.ibm.com> |
6 | */ | |
7 | ||
ca99dab0 | 8 | #define KMSG_COMPONENT "dasd-eckd" |
fc19f381 | 9 | |
8e09f215 | 10 | #include <linux/list.h> |
5a0e3ad6 | 11 | #include <linux/slab.h> |
8e09f215 SW |
12 | #include <asm/ebcdic.h> |
13 | #include "dasd_int.h" | |
14 | #include "dasd_eckd.h" | |
15 | ||
16 | #ifdef PRINTK_HEADER | |
17 | #undef PRINTK_HEADER | |
18 | #endif /* PRINTK_HEADER */ | |
19 | #define PRINTK_HEADER "dasd(eckd):" | |
20 | ||
21 | ||
22 | /* | |
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 | |
39 | * to be correct. | |
40 | */ | |
41 | ||
42 | ||
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 *); | |
46 | ||
47 | static struct alias_root aliastree = { | |
48 | .serverlist = LIST_HEAD_INIT(aliastree.serverlist), | |
49 | .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock), | |
50 | }; | |
51 | ||
52 | static struct alias_server *_find_server(struct dasd_uid *uid) | |
53 | { | |
54 | struct alias_server *pos; | |
55 | list_for_each_entry(pos, &aliastree.serverlist, server) { | |
56 | if (!strncmp(pos->uid.vendor, uid->vendor, | |
57 | sizeof(uid->vendor)) | |
58 | && !strncmp(pos->uid.serial, uid->serial, | |
59 | sizeof(uid->serial))) | |
60 | return pos; | |
3b974874 | 61 | } |
8e09f215 SW |
62 | return NULL; |
63 | } | |
64 | ||
65 | static struct alias_lcu *_find_lcu(struct alias_server *server, | |
66 | struct dasd_uid *uid) | |
67 | { | |
68 | struct alias_lcu *pos; | |
69 | list_for_each_entry(pos, &server->lculist, lcu) { | |
70 | if (pos->uid.ssid == uid->ssid) | |
71 | return pos; | |
3b974874 | 72 | } |
8e09f215 SW |
73 | return NULL; |
74 | } | |
75 | ||
76 | static struct alias_pav_group *_find_group(struct alias_lcu *lcu, | |
77 | struct dasd_uid *uid) | |
78 | { | |
79 | struct alias_pav_group *pos; | |
80 | __u8 search_unit_addr; | |
81 | ||
82 | /* for hyper pav there is only one group */ | |
83 | if (lcu->pav == HYPER_PAV) { | |
84 | if (list_empty(&lcu->grouplist)) | |
85 | return NULL; | |
86 | else | |
87 | return list_first_entry(&lcu->grouplist, | |
88 | struct alias_pav_group, group); | |
89 | } | |
90 | ||
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; | |
94 | else | |
95 | search_unit_addr = uid->base_unit_addr; | |
96 | list_for_each_entry(pos, &lcu->grouplist, group) { | |
4abb08c2 SW |
97 | if (pos->uid.base_unit_addr == search_unit_addr && |
98 | !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit))) | |
8e09f215 | 99 | return pos; |
3b974874 | 100 | } |
8e09f215 SW |
101 | return NULL; |
102 | } | |
103 | ||
104 | static struct alias_server *_allocate_server(struct dasd_uid *uid) | |
105 | { | |
106 | struct alias_server *server; | |
107 | ||
108 | server = kzalloc(sizeof(*server), GFP_KERNEL); | |
109 | if (!server) | |
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); | |
115 | return server; | |
116 | } | |
117 | ||
118 | static void _free_server(struct alias_server *server) | |
119 | { | |
120 | kfree(server); | |
121 | } | |
122 | ||
123 | static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid) | |
124 | { | |
125 | struct alias_lcu *lcu; | |
126 | ||
127 | lcu = kzalloc(sizeof(*lcu), GFP_KERNEL); | |
128 | if (!lcu) | |
129 | return ERR_PTR(-ENOMEM); | |
130 | lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA); | |
131 | if (!lcu->uac) | |
132 | goto out_err1; | |
133 | lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA); | |
134 | if (!lcu->rsu_cqr) | |
135 | goto out_err2; | |
136 | lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1), | |
137 | GFP_KERNEL | GFP_DMA); | |
138 | if (!lcu->rsu_cqr->cpaddr) | |
139 | goto out_err3; | |
140 | lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA); | |
141 | if (!lcu->rsu_cqr->data) | |
142 | goto out_err4; | |
143 | ||
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; | |
147 | lcu->pav = NO_PAV; | |
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); | |
f4ac1d02 | 156 | init_completion(&lcu->lcu_setup); |
8e09f215 SW |
157 | return lcu; |
158 | ||
159 | out_err4: | |
160 | kfree(lcu->rsu_cqr->cpaddr); | |
161 | out_err3: | |
162 | kfree(lcu->rsu_cqr); | |
163 | out_err2: | |
164 | kfree(lcu->uac); | |
165 | out_err1: | |
166 | kfree(lcu); | |
167 | return ERR_PTR(-ENOMEM); | |
168 | } | |
169 | ||
170 | static void _free_lcu(struct alias_lcu *lcu) | |
171 | { | |
172 | kfree(lcu->rsu_cqr->data); | |
173 | kfree(lcu->rsu_cqr->cpaddr); | |
174 | kfree(lcu->rsu_cqr); | |
175 | kfree(lcu->uac); | |
176 | kfree(lcu); | |
177 | } | |
178 | ||
179 | /* | |
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) | |
185 | */ | |
186 | int dasd_alias_make_device_known_to_lcu(struct dasd_device *device) | |
187 | { | |
543691a4 | 188 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
189 | unsigned long flags; |
190 | struct alias_server *server, *newserver; | |
191 | struct alias_lcu *lcu, *newlcu; | |
2dedf0d9 | 192 | struct dasd_uid uid; |
8e09f215 | 193 | |
2dedf0d9 | 194 | device->discipline->get_uid(device, &uid); |
8e09f215 | 195 | spin_lock_irqsave(&aliastree.lock, flags); |
2dedf0d9 | 196 | server = _find_server(&uid); |
8e09f215 SW |
197 | if (!server) { |
198 | spin_unlock_irqrestore(&aliastree.lock, flags); | |
2dedf0d9 | 199 | newserver = _allocate_server(&uid); |
8e09f215 SW |
200 | if (IS_ERR(newserver)) |
201 | return PTR_ERR(newserver); | |
202 | spin_lock_irqsave(&aliastree.lock, flags); | |
2dedf0d9 | 203 | server = _find_server(&uid); |
8e09f215 SW |
204 | if (!server) { |
205 | list_add(&newserver->server, &aliastree.serverlist); | |
206 | server = newserver; | |
8e09f215 SW |
207 | } else { |
208 | /* someone was faster */ | |
209 | _free_server(newserver); | |
210 | } | |
211 | } | |
212 | ||
2dedf0d9 | 213 | lcu = _find_lcu(server, &uid); |
8e09f215 SW |
214 | if (!lcu) { |
215 | spin_unlock_irqrestore(&aliastree.lock, flags); | |
2dedf0d9 | 216 | newlcu = _allocate_lcu(&uid); |
8e09f215 | 217 | if (IS_ERR(newlcu)) |
6d53cfe5 | 218 | return PTR_ERR(newlcu); |
8e09f215 | 219 | spin_lock_irqsave(&aliastree.lock, flags); |
2dedf0d9 | 220 | lcu = _find_lcu(server, &uid); |
8e09f215 SW |
221 | if (!lcu) { |
222 | list_add(&newlcu->lcu, &server->lculist); | |
223 | lcu = newlcu; | |
8e09f215 SW |
224 | } else { |
225 | /* someone was faster */ | |
226 | _free_lcu(newlcu); | |
227 | } | |
8e09f215 SW |
228 | } |
229 | spin_lock(&lcu->lock); | |
230 | list_add(&device->alias_list, &lcu->inactive_devices); | |
231 | private->lcu = lcu; | |
232 | spin_unlock(&lcu->lock); | |
233 | spin_unlock_irqrestore(&aliastree.lock, flags); | |
234 | ||
f9f8d02f | 235 | return 0; |
f4ac1d02 SW |
236 | } |
237 | ||
8e09f215 SW |
238 | /* |
239 | * This function removes a device from the scope of alias management. | |
240 | * The complicated part is to make sure that it is not in use by | |
241 | * any of the workers. If necessary cancel the work. | |
242 | */ | |
243 | void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device) | |
244 | { | |
543691a4 | 245 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
246 | unsigned long flags; |
247 | struct alias_lcu *lcu; | |
248 | struct alias_server *server; | |
249 | int was_pending; | |
2dedf0d9 | 250 | struct dasd_uid uid; |
8e09f215 | 251 | |
8e09f215 | 252 | lcu = private->lcu; |
f602f6d6 SH |
253 | /* nothing to do if already disconnected */ |
254 | if (!lcu) | |
255 | return; | |
2dedf0d9 | 256 | device->discipline->get_uid(device, &uid); |
8e09f215 SW |
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); | |
9d862aba SH |
264 | if (device == lcu->suc_data.device) { |
265 | dasd_put_device(device); | |
8e09f215 | 266 | lcu->suc_data.device = NULL; |
9d862aba | 267 | } |
8e09f215 SW |
268 | } |
269 | was_pending = 0; | |
270 | if (device == lcu->ruac_data.device) { | |
271 | spin_unlock_irqrestore(&lcu->lock, flags); | |
272 | was_pending = 1; | |
273 | cancel_delayed_work_sync(&lcu->ruac_data.dwork); | |
274 | spin_lock_irqsave(&lcu->lock, flags); | |
9d862aba SH |
275 | if (device == lcu->ruac_data.device) { |
276 | dasd_put_device(device); | |
8e09f215 | 277 | lcu->ruac_data.device = NULL; |
9d862aba | 278 | } |
8e09f215 SW |
279 | } |
280 | private->lcu = NULL; | |
281 | spin_unlock_irqrestore(&lcu->lock, flags); | |
282 | ||
283 | spin_lock_irqsave(&aliastree.lock, flags); | |
284 | spin_lock(&lcu->lock); | |
285 | if (list_empty(&lcu->grouplist) && | |
286 | list_empty(&lcu->active_devices) && | |
287 | list_empty(&lcu->inactive_devices)) { | |
288 | list_del(&lcu->lcu); | |
289 | spin_unlock(&lcu->lock); | |
290 | _free_lcu(lcu); | |
291 | lcu = NULL; | |
292 | } else { | |
293 | if (was_pending) | |
294 | _schedule_lcu_update(lcu, NULL); | |
295 | spin_unlock(&lcu->lock); | |
296 | } | |
2dedf0d9 | 297 | server = _find_server(&uid); |
8e09f215 SW |
298 | if (server && list_empty(&server->lculist)) { |
299 | list_del(&server->server); | |
300 | _free_server(server); | |
301 | } | |
302 | spin_unlock_irqrestore(&aliastree.lock, flags); | |
303 | } | |
304 | ||
305 | /* | |
306 | * This function assumes that the unit address configuration stored | |
307 | * in the lcu is up to date and will update the device uid before | |
308 | * adding it to a pav group. | |
309 | */ | |
2dedf0d9 | 310 | |
8e09f215 | 311 | static int _add_device_to_lcu(struct alias_lcu *lcu, |
2dedf0d9 SH |
312 | struct dasd_device *device, |
313 | struct dasd_device *pos) | |
8e09f215 SW |
314 | { |
315 | ||
543691a4 | 316 | struct dasd_eckd_private *private = device->private; |
8e09f215 | 317 | struct alias_pav_group *group; |
2dedf0d9 | 318 | struct dasd_uid uid; |
8e09f215 | 319 | |
59a9ed5f | 320 | spin_lock(get_ccwdev_lock(device->cdev)); |
2dedf0d9 SH |
321 | private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type; |
322 | private->uid.base_unit_addr = | |
323 | lcu->uac->unit[private->uid.real_unit_addr].base_ua; | |
324 | uid = private->uid; | |
59a9ed5f | 325 | spin_unlock(get_ccwdev_lock(device->cdev)); |
8e09f215 SW |
326 | /* if we have no PAV anyway, we don't need to bother with PAV groups */ |
327 | if (lcu->pav == NO_PAV) { | |
328 | list_move(&device->alias_list, &lcu->active_devices); | |
329 | return 0; | |
330 | } | |
2dedf0d9 | 331 | group = _find_group(lcu, &uid); |
8e09f215 SW |
332 | if (!group) { |
333 | group = kzalloc(sizeof(*group), GFP_ATOMIC); | |
334 | if (!group) | |
335 | return -ENOMEM; | |
2dedf0d9 SH |
336 | memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor)); |
337 | memcpy(group->uid.serial, uid.serial, sizeof(uid.serial)); | |
338 | group->uid.ssid = uid.ssid; | |
339 | if (uid.type == UA_BASE_DEVICE) | |
340 | group->uid.base_unit_addr = uid.real_unit_addr; | |
8e09f215 | 341 | else |
2dedf0d9 SH |
342 | group->uid.base_unit_addr = uid.base_unit_addr; |
343 | memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit)); | |
8e09f215 SW |
344 | INIT_LIST_HEAD(&group->group); |
345 | INIT_LIST_HEAD(&group->baselist); | |
346 | INIT_LIST_HEAD(&group->aliaslist); | |
347 | list_add(&group->group, &lcu->grouplist); | |
348 | } | |
2dedf0d9 | 349 | if (uid.type == UA_BASE_DEVICE) |
8e09f215 SW |
350 | list_move(&device->alias_list, &group->baselist); |
351 | else | |
352 | list_move(&device->alias_list, &group->aliaslist); | |
353 | private->pavgroup = group; | |
354 | return 0; | |
355 | }; | |
356 | ||
357 | static void _remove_device_from_lcu(struct alias_lcu *lcu, | |
358 | struct dasd_device *device) | |
359 | { | |
543691a4 | 360 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
361 | struct alias_pav_group *group; |
362 | ||
8e09f215 SW |
363 | list_move(&device->alias_list, &lcu->inactive_devices); |
364 | group = private->pavgroup; | |
365 | if (!group) | |
366 | return; | |
367 | private->pavgroup = NULL; | |
368 | if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) { | |
369 | list_del(&group->group); | |
370 | kfree(group); | |
371 | return; | |
372 | } | |
373 | if (group->next == device) | |
374 | group->next = NULL; | |
375 | }; | |
376 | ||
03429f34 SH |
377 | static int |
378 | suborder_not_supported(struct dasd_ccw_req *cqr) | |
379 | { | |
380 | char *sense; | |
381 | char reason; | |
382 | char msg_format; | |
383 | char msg_no; | |
384 | ||
385 | sense = dasd_get_sense(&cqr->irb); | |
386 | if (!sense) | |
387 | return 0; | |
388 | ||
389 | reason = sense[0]; | |
390 | msg_format = (sense[7] & 0xF0); | |
391 | msg_no = (sense[7] & 0x0F); | |
392 | ||
393 | /* command reject, Format 0 MSG 4 - invalid parameter */ | |
394 | if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04)) | |
395 | return 1; | |
396 | ||
397 | return 0; | |
398 | } | |
399 | ||
8e09f215 SW |
400 | static int read_unit_address_configuration(struct dasd_device *device, |
401 | struct alias_lcu *lcu) | |
402 | { | |
403 | struct dasd_psf_prssd_data *prssdp; | |
404 | struct dasd_ccw_req *cqr; | |
405 | struct ccw1 *ccw; | |
406 | int rc; | |
407 | unsigned long flags; | |
408 | ||
68b781fe | 409 | cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
8e09f215 SW |
410 | (sizeof(struct dasd_psf_prssd_data)), |
411 | device); | |
412 | if (IS_ERR(cqr)) | |
413 | return PTR_ERR(cqr); | |
414 | cqr->startdev = device; | |
415 | cqr->memdev = device; | |
416 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
417 | cqr->retries = 10; | |
418 | cqr->expires = 20 * HZ; | |
419 | ||
420 | /* Prepare for Read Subsystem Data */ | |
421 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
422 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); | |
423 | prssdp->order = PSF_ORDER_PRSSD; | |
424 | prssdp->suborder = 0x0e; /* Read unit address configuration */ | |
425 | /* all other bytes of prssdp must be zero */ | |
426 | ||
427 | ccw = cqr->cpaddr; | |
428 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
429 | ccw->count = sizeof(struct dasd_psf_prssd_data); | |
430 | ccw->flags |= CCW_FLAG_CC; | |
431 | ccw->cda = (__u32)(addr_t) prssdp; | |
432 | ||
433 | /* Read Subsystem Data - feature codes */ | |
434 | memset(lcu->uac, 0, sizeof(*(lcu->uac))); | |
435 | ||
436 | ccw++; | |
437 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
438 | ccw->count = sizeof(*(lcu->uac)); | |
439 | ccw->cda = (__u32)(addr_t) lcu->uac; | |
440 | ||
1aae0560 | 441 | cqr->buildclk = get_tod_clock(); |
8e09f215 SW |
442 | cqr->status = DASD_CQR_FILLED; |
443 | ||
444 | /* need to unset flag here to detect race with summary unit check */ | |
445 | spin_lock_irqsave(&lcu->lock, flags); | |
446 | lcu->flags &= ~NEED_UAC_UPDATE; | |
447 | spin_unlock_irqrestore(&lcu->lock, flags); | |
448 | ||
449 | do { | |
450 | rc = dasd_sleep_on(cqr); | |
03429f34 SH |
451 | if (rc && suborder_not_supported(cqr)) |
452 | return -EOPNOTSUPP; | |
8e09f215 SW |
453 | } while (rc && (cqr->retries > 0)); |
454 | if (rc) { | |
455 | spin_lock_irqsave(&lcu->lock, flags); | |
456 | lcu->flags |= NEED_UAC_UPDATE; | |
457 | spin_unlock_irqrestore(&lcu->lock, flags); | |
458 | } | |
459 | dasd_kfree_request(cqr, cqr->memdev); | |
460 | return rc; | |
461 | } | |
462 | ||
463 | static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu) | |
464 | { | |
465 | unsigned long flags; | |
466 | struct alias_pav_group *pavgroup, *tempgroup; | |
467 | struct dasd_device *device, *tempdev; | |
468 | int i, rc; | |
469 | struct dasd_eckd_private *private; | |
470 | ||
471 | spin_lock_irqsave(&lcu->lock, flags); | |
472 | list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) { | |
473 | list_for_each_entry_safe(device, tempdev, &pavgroup->baselist, | |
474 | alias_list) { | |
475 | list_move(&device->alias_list, &lcu->active_devices); | |
543691a4 | 476 | private = device->private; |
8e09f215 SW |
477 | private->pavgroup = NULL; |
478 | } | |
479 | list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist, | |
480 | alias_list) { | |
481 | list_move(&device->alias_list, &lcu->active_devices); | |
543691a4 | 482 | private = device->private; |
8e09f215 SW |
483 | private->pavgroup = NULL; |
484 | } | |
485 | list_del(&pavgroup->group); | |
486 | kfree(pavgroup); | |
487 | } | |
488 | spin_unlock_irqrestore(&lcu->lock, flags); | |
489 | ||
490 | rc = read_unit_address_configuration(refdev, lcu); | |
491 | if (rc) | |
492 | return rc; | |
493 | ||
59a9ed5f | 494 | spin_lock_irqsave(&lcu->lock, flags); |
8e09f215 SW |
495 | lcu->pav = NO_PAV; |
496 | for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) { | |
497 | switch (lcu->uac->unit[i].ua_type) { | |
498 | case UA_BASE_PAV_ALIAS: | |
499 | lcu->pav = BASE_PAV; | |
500 | break; | |
501 | case UA_HYPER_PAV_ALIAS: | |
502 | lcu->pav = HYPER_PAV; | |
503 | break; | |
504 | } | |
505 | if (lcu->pav != NO_PAV) | |
506 | break; | |
507 | } | |
508 | ||
509 | list_for_each_entry_safe(device, tempdev, &lcu->active_devices, | |
510 | alias_list) { | |
2dedf0d9 | 511 | _add_device_to_lcu(lcu, device, refdev); |
8e09f215 | 512 | } |
9bfefde7 | 513 | spin_unlock_irqrestore(&lcu->lock, flags); |
8e09f215 SW |
514 | return 0; |
515 | } | |
516 | ||
517 | static void lcu_update_work(struct work_struct *work) | |
518 | { | |
519 | struct alias_lcu *lcu; | |
520 | struct read_uac_work_data *ruac_data; | |
521 | struct dasd_device *device; | |
522 | unsigned long flags; | |
523 | int rc; | |
524 | ||
525 | ruac_data = container_of(work, struct read_uac_work_data, dwork.work); | |
526 | lcu = container_of(ruac_data, struct alias_lcu, ruac_data); | |
527 | device = ruac_data->device; | |
528 | rc = _lcu_update(device, lcu); | |
529 | /* | |
530 | * Need to check flags again, as there could have been another | |
531 | * prepare_update or a new device a new device while we were still | |
532 | * processing the data | |
533 | */ | |
534 | spin_lock_irqsave(&lcu->lock, flags); | |
03429f34 | 535 | if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) { |
fc19f381 | 536 | DBF_DEV_EVENT(DBF_WARNING, device, "could not update" |
8e09f215 | 537 | " alias data in lcu (rc = %d), retry later", rc); |
9d862aba SH |
538 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ)) |
539 | dasd_put_device(device); | |
8e09f215 | 540 | } else { |
9d862aba | 541 | dasd_put_device(device); |
8e09f215 SW |
542 | lcu->ruac_data.device = NULL; |
543 | lcu->flags &= ~UPDATE_PENDING; | |
544 | } | |
545 | spin_unlock_irqrestore(&lcu->lock, flags); | |
546 | } | |
547 | ||
548 | static int _schedule_lcu_update(struct alias_lcu *lcu, | |
549 | struct dasd_device *device) | |
550 | { | |
551 | struct dasd_device *usedev = NULL; | |
552 | struct alias_pav_group *group; | |
553 | ||
554 | lcu->flags |= NEED_UAC_UPDATE; | |
555 | if (lcu->ruac_data.device) { | |
556 | /* already scheduled or running */ | |
557 | return 0; | |
558 | } | |
559 | if (device && !list_empty(&device->alias_list)) | |
560 | usedev = device; | |
561 | ||
562 | if (!usedev && !list_empty(&lcu->grouplist)) { | |
563 | group = list_first_entry(&lcu->grouplist, | |
564 | struct alias_pav_group, group); | |
565 | if (!list_empty(&group->baselist)) | |
566 | usedev = list_first_entry(&group->baselist, | |
567 | struct dasd_device, | |
568 | alias_list); | |
569 | else if (!list_empty(&group->aliaslist)) | |
570 | usedev = list_first_entry(&group->aliaslist, | |
571 | struct dasd_device, | |
572 | alias_list); | |
573 | } | |
574 | if (!usedev && !list_empty(&lcu->active_devices)) { | |
575 | usedev = list_first_entry(&lcu->active_devices, | |
576 | struct dasd_device, alias_list); | |
577 | } | |
578 | /* | |
579 | * if we haven't found a proper device yet, give up for now, the next | |
580 | * device that will be set active will trigger an lcu update | |
581 | */ | |
582 | if (!usedev) | |
583 | return -EINVAL; | |
9d862aba | 584 | dasd_get_device(usedev); |
8e09f215 | 585 | lcu->ruac_data.device = usedev; |
9d862aba SH |
586 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0)) |
587 | dasd_put_device(usedev); | |
8e09f215 SW |
588 | return 0; |
589 | } | |
590 | ||
591 | int dasd_alias_add_device(struct dasd_device *device) | |
592 | { | |
543691a4 | 593 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
594 | struct alias_lcu *lcu; |
595 | unsigned long flags; | |
596 | int rc; | |
597 | ||
8e09f215 SW |
598 | lcu = private->lcu; |
599 | rc = 0; | |
59a9ed5f | 600 | spin_lock_irqsave(&lcu->lock, flags); |
8e09f215 | 601 | if (!(lcu->flags & UPDATE_PENDING)) { |
2dedf0d9 | 602 | rc = _add_device_to_lcu(lcu, device, device); |
8e09f215 SW |
603 | if (rc) |
604 | lcu->flags |= UPDATE_PENDING; | |
605 | } | |
606 | if (lcu->flags & UPDATE_PENDING) { | |
607 | list_move(&device->alias_list, &lcu->active_devices); | |
608 | _schedule_lcu_update(lcu, device); | |
609 | } | |
59a9ed5f | 610 | spin_unlock_irqrestore(&lcu->lock, flags); |
8e09f215 SW |
611 | return rc; |
612 | } | |
613 | ||
501183f2 SH |
614 | int dasd_alias_update_add_device(struct dasd_device *device) |
615 | { | |
543691a4 SO |
616 | struct dasd_eckd_private *private = device->private; |
617 | ||
501183f2 SH |
618 | private->lcu->flags |= UPDATE_PENDING; |
619 | return dasd_alias_add_device(device); | |
620 | } | |
621 | ||
8e09f215 SW |
622 | int dasd_alias_remove_device(struct dasd_device *device) |
623 | { | |
543691a4 SO |
624 | struct dasd_eckd_private *private = device->private; |
625 | struct alias_lcu *lcu = private->lcu; | |
8e09f215 SW |
626 | unsigned long flags; |
627 | ||
f602f6d6 SH |
628 | /* nothing to do if already removed */ |
629 | if (!lcu) | |
630 | return 0; | |
8e09f215 SW |
631 | spin_lock_irqsave(&lcu->lock, flags); |
632 | _remove_device_from_lcu(lcu, device); | |
633 | spin_unlock_irqrestore(&lcu->lock, flags); | |
634 | return 0; | |
635 | } | |
636 | ||
637 | struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device) | |
638 | { | |
543691a4 SO |
639 | struct dasd_eckd_private *alias_priv, *private = base_device->private; |
640 | struct alias_pav_group *group = private->pavgroup; | |
641 | struct alias_lcu *lcu = private->lcu; | |
8e09f215 | 642 | struct dasd_device *alias_device; |
8e09f215 SW |
643 | unsigned long flags; |
644 | ||
8e09f215 SW |
645 | if (!group || !lcu) |
646 | return NULL; | |
647 | if (lcu->pav == NO_PAV || | |
648 | lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING)) | |
649 | return NULL; | |
b38f27e8 SH |
650 | if (unlikely(!(private->features.feature[8] & 0x01))) { |
651 | /* | |
652 | * PAV enabled but prefix not, very unlikely | |
653 | * seems to be a lost pathgroup | |
654 | * use base device to do IO | |
655 | */ | |
656 | DBF_DEV_EVENT(DBF_ERR, base_device, "%s", | |
657 | "Prefix not enabled with PAV enabled\n"); | |
658 | return NULL; | |
659 | } | |
8e09f215 SW |
660 | |
661 | spin_lock_irqsave(&lcu->lock, flags); | |
662 | alias_device = group->next; | |
663 | if (!alias_device) { | |
664 | if (list_empty(&group->aliaslist)) { | |
665 | spin_unlock_irqrestore(&lcu->lock, flags); | |
666 | return NULL; | |
667 | } else { | |
668 | alias_device = list_first_entry(&group->aliaslist, | |
669 | struct dasd_device, | |
670 | alias_list); | |
671 | } | |
672 | } | |
673 | if (list_is_last(&alias_device->alias_list, &group->aliaslist)) | |
674 | group->next = list_first_entry(&group->aliaslist, | |
675 | struct dasd_device, alias_list); | |
676 | else | |
677 | group->next = list_first_entry(&alias_device->alias_list, | |
678 | struct dasd_device, alias_list); | |
679 | spin_unlock_irqrestore(&lcu->lock, flags); | |
543691a4 | 680 | alias_priv = alias_device->private; |
f81a49d1 SH |
681 | if ((alias_priv->count < private->count) && !alias_device->stopped && |
682 | !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags)) | |
8e09f215 SW |
683 | return alias_device; |
684 | else | |
685 | return NULL; | |
686 | } | |
687 | ||
688 | /* | |
689 | * Summary unit check handling depends on the way alias devices | |
690 | * are handled so it is done here rather then in dasd_eckd.c | |
691 | */ | |
692 | static int reset_summary_unit_check(struct alias_lcu *lcu, | |
693 | struct dasd_device *device, | |
694 | char reason) | |
695 | { | |
696 | struct dasd_ccw_req *cqr; | |
697 | int rc = 0; | |
f3eb5384 | 698 | struct ccw1 *ccw; |
8e09f215 SW |
699 | |
700 | cqr = lcu->rsu_cqr; | |
701 | strncpy((char *) &cqr->magic, "ECKD", 4); | |
702 | ASCEBC((char *) &cqr->magic, 4); | |
f3eb5384 SW |
703 | ccw = cqr->cpaddr; |
704 | ccw->cmd_code = DASD_ECKD_CCW_RSCK; | |
020bf042 | 705 | ccw->flags = CCW_FLAG_SLI; |
f3eb5384 SW |
706 | ccw->count = 16; |
707 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
708 | ((char *)cqr->data)[0] = reason; |
709 | ||
710 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
711 | cqr->retries = 255; /* set retry counter to enable basic ERP */ | |
712 | cqr->startdev = device; | |
713 | cqr->memdev = device; | |
714 | cqr->block = NULL; | |
715 | cqr->expires = 5 * HZ; | |
1aae0560 | 716 | cqr->buildclk = get_tod_clock(); |
8e09f215 SW |
717 | cqr->status = DASD_CQR_FILLED; |
718 | ||
719 | rc = dasd_sleep_on_immediatly(cqr); | |
720 | return rc; | |
721 | } | |
722 | ||
723 | static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu) | |
724 | { | |
725 | struct alias_pav_group *pavgroup; | |
726 | struct dasd_device *device; | |
727 | struct dasd_eckd_private *private; | |
728 | ||
729 | /* active and inactive list can contain alias as well as base devices */ | |
730 | list_for_each_entry(device, &lcu->active_devices, alias_list) { | |
543691a4 | 731 | private = device->private; |
9bfefde7 | 732 | if (private->uid.type != UA_BASE_DEVICE) |
8e09f215 SW |
733 | continue; |
734 | dasd_schedule_block_bh(device->block); | |
735 | dasd_schedule_device_bh(device); | |
736 | } | |
737 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { | |
543691a4 | 738 | private = device->private; |
9bfefde7 | 739 | if (private->uid.type != UA_BASE_DEVICE) |
8e09f215 SW |
740 | continue; |
741 | dasd_schedule_block_bh(device->block); | |
742 | dasd_schedule_device_bh(device); | |
743 | } | |
744 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { | |
745 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { | |
746 | dasd_schedule_block_bh(device->block); | |
747 | dasd_schedule_device_bh(device); | |
748 | } | |
749 | } | |
750 | } | |
751 | ||
752 | static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu) | |
753 | { | |
754 | struct alias_pav_group *pavgroup; | |
755 | struct dasd_device *device, *temp; | |
756 | struct dasd_eckd_private *private; | |
757 | int rc; | |
758 | unsigned long flags; | |
759 | LIST_HEAD(active); | |
760 | ||
761 | /* | |
762 | * Problem here ist that dasd_flush_device_queue may wait | |
763 | * for termination of a request to complete. We can't keep | |
764 | * the lcu lock during that time, so we must assume that | |
765 | * the lists may have changed. | |
766 | * Idea: first gather all active alias devices in a separate list, | |
767 | * then flush the first element of this list unlocked, and afterwards | |
768 | * check if it is still on the list before moving it to the | |
769 | * active_devices list. | |
770 | */ | |
771 | ||
772 | spin_lock_irqsave(&lcu->lock, flags); | |
773 | list_for_each_entry_safe(device, temp, &lcu->active_devices, | |
774 | alias_list) { | |
543691a4 | 775 | private = device->private; |
8e09f215 SW |
776 | if (private->uid.type == UA_BASE_DEVICE) |
777 | continue; | |
778 | list_move(&device->alias_list, &active); | |
779 | } | |
780 | ||
781 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { | |
782 | list_splice_init(&pavgroup->aliaslist, &active); | |
783 | } | |
784 | while (!list_empty(&active)) { | |
785 | device = list_first_entry(&active, struct dasd_device, | |
786 | alias_list); | |
787 | spin_unlock_irqrestore(&lcu->lock, flags); | |
788 | rc = dasd_flush_device_queue(device); | |
789 | spin_lock_irqsave(&lcu->lock, flags); | |
790 | /* | |
791 | * only move device around if it wasn't moved away while we | |
792 | * were waiting for the flush | |
793 | */ | |
794 | if (device == list_first_entry(&active, | |
6933c35a | 795 | struct dasd_device, alias_list)) { |
8e09f215 | 796 | list_move(&device->alias_list, &lcu->active_devices); |
543691a4 | 797 | private = device->private; |
6933c35a SH |
798 | private->pavgroup = NULL; |
799 | } | |
8e09f215 SW |
800 | } |
801 | spin_unlock_irqrestore(&lcu->lock, flags); | |
802 | } | |
803 | ||
9bfefde7 | 804 | static void _stop_all_devices_on_lcu(struct alias_lcu *lcu) |
8e09f215 SW |
805 | { |
806 | struct alias_pav_group *pavgroup; | |
9bfefde7 | 807 | struct dasd_device *device; |
8e09f215 | 808 | |
59a9ed5f SH |
809 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
810 | spin_lock(get_ccwdev_lock(device->cdev)); | |
9bfefde7 | 811 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
812 | spin_unlock(get_ccwdev_lock(device->cdev)); |
813 | } | |
814 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { | |
815 | spin_lock(get_ccwdev_lock(device->cdev)); | |
9bfefde7 | 816 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
817 | spin_unlock(get_ccwdev_lock(device->cdev)); |
818 | } | |
8e09f215 | 819 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
59a9ed5f SH |
820 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
821 | spin_lock(get_ccwdev_lock(device->cdev)); | |
9bfefde7 | 822 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
823 | spin_unlock(get_ccwdev_lock(device->cdev)); |
824 | } | |
825 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { | |
826 | spin_lock(get_ccwdev_lock(device->cdev)); | |
9bfefde7 | 827 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
828 | spin_unlock(get_ccwdev_lock(device->cdev)); |
829 | } | |
8e09f215 SW |
830 | } |
831 | } | |
832 | ||
833 | static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu) | |
834 | { | |
835 | struct alias_pav_group *pavgroup; | |
836 | struct dasd_device *device; | |
8e09f215 | 837 | |
59a9ed5f SH |
838 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
839 | spin_lock(get_ccwdev_lock(device->cdev)); | |
eb6e199b | 840 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
841 | spin_unlock(get_ccwdev_lock(device->cdev)); |
842 | } | |
843 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { | |
844 | spin_lock(get_ccwdev_lock(device->cdev)); | |
eb6e199b | 845 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
846 | spin_unlock(get_ccwdev_lock(device->cdev)); |
847 | } | |
8e09f215 | 848 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
59a9ed5f SH |
849 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
850 | spin_lock(get_ccwdev_lock(device->cdev)); | |
eb6e199b | 851 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
852 | spin_unlock(get_ccwdev_lock(device->cdev)); |
853 | } | |
854 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { | |
855 | spin_lock(get_ccwdev_lock(device->cdev)); | |
eb6e199b | 856 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
59a9ed5f SH |
857 | spin_unlock(get_ccwdev_lock(device->cdev)); |
858 | } | |
8e09f215 SW |
859 | } |
860 | } | |
861 | ||
862 | static void summary_unit_check_handling_work(struct work_struct *work) | |
863 | { | |
864 | struct alias_lcu *lcu; | |
865 | struct summary_unit_check_work_data *suc_data; | |
866 | unsigned long flags; | |
867 | struct dasd_device *device; | |
868 | ||
869 | suc_data = container_of(work, struct summary_unit_check_work_data, | |
870 | worker); | |
871 | lcu = container_of(suc_data, struct alias_lcu, suc_data); | |
872 | device = suc_data->device; | |
873 | ||
874 | /* 1. flush alias devices */ | |
875 | flush_all_alias_devices_on_lcu(lcu); | |
876 | ||
877 | /* 2. reset summary unit check */ | |
878 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
eb6e199b SW |
879 | dasd_device_remove_stop_bits(device, |
880 | (DASD_STOPPED_SU | DASD_STOPPED_PENDING)); | |
8e09f215 SW |
881 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
882 | reset_summary_unit_check(lcu, device, suc_data->reason); | |
883 | ||
59a9ed5f | 884 | spin_lock_irqsave(&lcu->lock, flags); |
8e09f215 SW |
885 | _unstop_all_devices_on_lcu(lcu); |
886 | _restart_all_base_devices_on_lcu(lcu); | |
887 | /* 3. read new alias configuration */ | |
888 | _schedule_lcu_update(lcu, device); | |
889 | lcu->suc_data.device = NULL; | |
9d862aba | 890 | dasd_put_device(device); |
8e09f215 SW |
891 | spin_unlock_irqrestore(&lcu->lock, flags); |
892 | } | |
893 | ||
59a9ed5f | 894 | void dasd_alias_handle_summary_unit_check(struct work_struct *work) |
8e09f215 | 895 | { |
59a9ed5f SH |
896 | struct dasd_device *device = container_of(work, struct dasd_device, |
897 | suc_work); | |
543691a4 | 898 | struct dasd_eckd_private *private = device->private; |
8e09f215 | 899 | struct alias_lcu *lcu; |
59a9ed5f | 900 | unsigned long flags; |
8e09f215 SW |
901 | |
902 | lcu = private->lcu; | |
903 | if (!lcu) { | |
fc19f381 | 904 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
8e09f215 SW |
905 | "device not ready to handle summary" |
906 | " unit check (no lcu structure)"); | |
59a9ed5f | 907 | goto out; |
8e09f215 | 908 | } |
59a9ed5f | 909 | spin_lock_irqsave(&lcu->lock, flags); |
8e09f215 SW |
910 | /* If this device is about to be removed just return and wait for |
911 | * the next interrupt on a different device | |
912 | */ | |
913 | if (list_empty(&device->alias_list)) { | |
fc19f381 | 914 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
8e09f215 SW |
915 | "device is in offline processing," |
916 | " don't do summary unit check handling"); | |
59a9ed5f | 917 | goto out_unlock; |
8e09f215 SW |
918 | } |
919 | if (lcu->suc_data.device) { | |
920 | /* already scheduled or running */ | |
fc19f381 | 921 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
8e09f215 SW |
922 | "previous instance of summary unit check worker" |
923 | " still pending"); | |
59a9ed5f | 924 | goto out_unlock; |
8e09f215 | 925 | } |
9bfefde7 SH |
926 | _stop_all_devices_on_lcu(lcu); |
927 | /* prepare for lcu_update */ | |
59a9ed5f SH |
928 | lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING; |
929 | lcu->suc_data.reason = private->suc_reason; | |
8e09f215 | 930 | lcu->suc_data.device = device; |
9d862aba | 931 | dasd_get_device(device); |
9d862aba SH |
932 | if (!schedule_work(&lcu->suc_data.worker)) |
933 | dasd_put_device(device); | |
59a9ed5f SH |
934 | out_unlock: |
935 | spin_unlock_irqrestore(&lcu->lock, flags); | |
936 | out: | |
937 | clear_bit(DASD_FLAG_SUC, &device->flags); | |
938 | dasd_put_device(device); | |
8e09f215 | 939 | }; |