dasd_alias.c 26 KB

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