dasd_alias.c 26 KB

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