dasd_alias.c 29 KB

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