dasd_alias.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /*
  2. * PAV alias management for the DASD ECKD discipline
  3. *
  4. * Copyright IBM Corp. 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 = device->private;
  167. unsigned long flags;
  168. struct alias_server *server, *newserver;
  169. struct alias_lcu *lcu, *newlcu;
  170. struct dasd_uid uid;
  171. device->discipline->get_uid(device, &uid);
  172. spin_lock_irqsave(&aliastree.lock, flags);
  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. } else {
  185. /* someone was faster */
  186. _free_server(newserver);
  187. }
  188. }
  189. lcu = _find_lcu(server, &uid);
  190. if (!lcu) {
  191. spin_unlock_irqrestore(&aliastree.lock, flags);
  192. newlcu = _allocate_lcu(&uid);
  193. if (IS_ERR(newlcu))
  194. return PTR_ERR(newlcu);
  195. spin_lock_irqsave(&aliastree.lock, flags);
  196. lcu = _find_lcu(server, &uid);
  197. if (!lcu) {
  198. list_add(&newlcu->lcu, &server->lculist);
  199. lcu = newlcu;
  200. } else {
  201. /* someone was faster */
  202. _free_lcu(newlcu);
  203. }
  204. }
  205. spin_lock(&lcu->lock);
  206. list_add(&device->alias_list, &lcu->inactive_devices);
  207. private->lcu = lcu;
  208. spin_unlock(&lcu->lock);
  209. spin_unlock_irqrestore(&aliastree.lock, flags);
  210. return 0;
  211. }
  212. /*
  213. * This function removes a device from the scope of alias management.
  214. * The complicated part is to make sure that it is not in use by
  215. * any of the workers. If necessary cancel the work.
  216. */
  217. void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
  218. {
  219. struct dasd_eckd_private *private = device->private;
  220. unsigned long flags;
  221. struct alias_lcu *lcu;
  222. struct alias_server *server;
  223. int was_pending;
  224. struct dasd_uid uid;
  225. lcu = private->lcu;
  226. /* nothing to do if already disconnected */
  227. if (!lcu)
  228. return;
  229. device->discipline->get_uid(device, &uid);
  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. dasd_put_device(device);
  239. lcu->suc_data.device = NULL;
  240. }
  241. }
  242. was_pending = 0;
  243. if (device == lcu->ruac_data.device) {
  244. spin_unlock_irqrestore(&lcu->lock, flags);
  245. was_pending = 1;
  246. cancel_delayed_work_sync(&lcu->ruac_data.dwork);
  247. spin_lock_irqsave(&lcu->lock, flags);
  248. if (device == lcu->ruac_data.device) {
  249. dasd_put_device(device);
  250. lcu->ruac_data.device = NULL;
  251. }
  252. }
  253. private->lcu = NULL;
  254. spin_unlock_irqrestore(&lcu->lock, flags);
  255. spin_lock_irqsave(&aliastree.lock, flags);
  256. spin_lock(&lcu->lock);
  257. if (list_empty(&lcu->grouplist) &&
  258. list_empty(&lcu->active_devices) &&
  259. list_empty(&lcu->inactive_devices)) {
  260. list_del(&lcu->lcu);
  261. spin_unlock(&lcu->lock);
  262. _free_lcu(lcu);
  263. lcu = NULL;
  264. } else {
  265. if (was_pending)
  266. _schedule_lcu_update(lcu, NULL);
  267. spin_unlock(&lcu->lock);
  268. }
  269. server = _find_server(&uid);
  270. if (server && list_empty(&server->lculist)) {
  271. list_del(&server->server);
  272. _free_server(server);
  273. }
  274. spin_unlock_irqrestore(&aliastree.lock, flags);
  275. }
  276. /*
  277. * This function assumes that the unit address configuration stored
  278. * in the lcu is up to date and will update the device uid before
  279. * adding it to a pav group.
  280. */
  281. static int _add_device_to_lcu(struct alias_lcu *lcu,
  282. struct dasd_device *device,
  283. struct dasd_device *pos)
  284. {
  285. struct dasd_eckd_private *private = device->private;
  286. struct alias_pav_group *group;
  287. struct dasd_uid uid;
  288. spin_lock(get_ccwdev_lock(device->cdev));
  289. private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
  290. private->uid.base_unit_addr =
  291. lcu->uac->unit[private->uid.real_unit_addr].base_ua;
  292. uid = private->uid;
  293. spin_unlock(get_ccwdev_lock(device->cdev));
  294. /* if we have no PAV anyway, we don't need to bother with PAV groups */
  295. if (lcu->pav == NO_PAV) {
  296. list_move(&device->alias_list, &lcu->active_devices);
  297. return 0;
  298. }
  299. group = _find_group(lcu, &uid);
  300. if (!group) {
  301. group = kzalloc(sizeof(*group), GFP_ATOMIC);
  302. if (!group)
  303. return -ENOMEM;
  304. memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
  305. memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
  306. group->uid.ssid = uid.ssid;
  307. if (uid.type == UA_BASE_DEVICE)
  308. group->uid.base_unit_addr = uid.real_unit_addr;
  309. else
  310. group->uid.base_unit_addr = uid.base_unit_addr;
  311. memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
  312. INIT_LIST_HEAD(&group->group);
  313. INIT_LIST_HEAD(&group->baselist);
  314. INIT_LIST_HEAD(&group->aliaslist);
  315. list_add(&group->group, &lcu->grouplist);
  316. }
  317. if (uid.type == UA_BASE_DEVICE)
  318. list_move(&device->alias_list, &group->baselist);
  319. else
  320. list_move(&device->alias_list, &group->aliaslist);
  321. private->pavgroup = group;
  322. return 0;
  323. };
  324. static void _remove_device_from_lcu(struct alias_lcu *lcu,
  325. struct dasd_device *device)
  326. {
  327. struct dasd_eckd_private *private = device->private;
  328. struct alias_pav_group *group;
  329. list_move(&device->alias_list, &lcu->inactive_devices);
  330. group = private->pavgroup;
  331. if (!group)
  332. return;
  333. private->pavgroup = NULL;
  334. if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
  335. list_del(&group->group);
  336. kfree(group);
  337. return;
  338. }
  339. if (group->next == device)
  340. group->next = NULL;
  341. };
  342. static int
  343. suborder_not_supported(struct dasd_ccw_req *cqr)
  344. {
  345. char *sense;
  346. char reason;
  347. char msg_format;
  348. char msg_no;
  349. sense = dasd_get_sense(&cqr->irb);
  350. if (!sense)
  351. return 0;
  352. reason = sense[0];
  353. msg_format = (sense[7] & 0xF0);
  354. msg_no = (sense[7] & 0x0F);
  355. /* command reject, Format 0 MSG 4 - invalid parameter */
  356. if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04))
  357. return 1;
  358. return 0;
  359. }
  360. static int read_unit_address_configuration(struct dasd_device *device,
  361. struct alias_lcu *lcu)
  362. {
  363. struct dasd_psf_prssd_data *prssdp;
  364. struct dasd_ccw_req *cqr;
  365. struct ccw1 *ccw;
  366. int rc;
  367. unsigned long flags;
  368. cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  369. (sizeof(struct dasd_psf_prssd_data)),
  370. device);
  371. if (IS_ERR(cqr))
  372. return PTR_ERR(cqr);
  373. cqr->startdev = device;
  374. cqr->memdev = device;
  375. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  376. cqr->retries = 10;
  377. cqr->expires = 20 * HZ;
  378. /* Prepare for Read Subsystem Data */
  379. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  380. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  381. prssdp->order = PSF_ORDER_PRSSD;
  382. prssdp->suborder = 0x0e; /* Read unit address configuration */
  383. /* all other bytes of prssdp must be zero */
  384. ccw = cqr->cpaddr;
  385. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  386. ccw->count = sizeof(struct dasd_psf_prssd_data);
  387. ccw->flags |= CCW_FLAG_CC;
  388. ccw->cda = (__u32)(addr_t) prssdp;
  389. /* Read Subsystem Data - feature codes */
  390. memset(lcu->uac, 0, sizeof(*(lcu->uac)));
  391. ccw++;
  392. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  393. ccw->count = sizeof(*(lcu->uac));
  394. ccw->cda = (__u32)(addr_t) lcu->uac;
  395. cqr->buildclk = get_tod_clock();
  396. cqr->status = DASD_CQR_FILLED;
  397. /* need to unset flag here to detect race with summary unit check */
  398. spin_lock_irqsave(&lcu->lock, flags);
  399. lcu->flags &= ~NEED_UAC_UPDATE;
  400. spin_unlock_irqrestore(&lcu->lock, flags);
  401. do {
  402. rc = dasd_sleep_on(cqr);
  403. if (rc && suborder_not_supported(cqr))
  404. return -EOPNOTSUPP;
  405. } while (rc && (cqr->retries > 0));
  406. if (rc) {
  407. spin_lock_irqsave(&lcu->lock, flags);
  408. lcu->flags |= NEED_UAC_UPDATE;
  409. spin_unlock_irqrestore(&lcu->lock, flags);
  410. }
  411. dasd_kfree_request(cqr, cqr->memdev);
  412. return rc;
  413. }
  414. static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
  415. {
  416. unsigned long flags;
  417. struct alias_pav_group *pavgroup, *tempgroup;
  418. struct dasd_device *device, *tempdev;
  419. int i, rc;
  420. struct dasd_eckd_private *private;
  421. spin_lock_irqsave(&lcu->lock, flags);
  422. list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
  423. list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
  424. alias_list) {
  425. list_move(&device->alias_list, &lcu->active_devices);
  426. private = device->private;
  427. private->pavgroup = NULL;
  428. }
  429. list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
  430. alias_list) {
  431. list_move(&device->alias_list, &lcu->active_devices);
  432. private = device->private;
  433. private->pavgroup = NULL;
  434. }
  435. list_del(&pavgroup->group);
  436. kfree(pavgroup);
  437. }
  438. spin_unlock_irqrestore(&lcu->lock, flags);
  439. rc = read_unit_address_configuration(refdev, lcu);
  440. if (rc)
  441. return rc;
  442. spin_lock_irqsave(&lcu->lock, flags);
  443. lcu->pav = NO_PAV;
  444. for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
  445. switch (lcu->uac->unit[i].ua_type) {
  446. case UA_BASE_PAV_ALIAS:
  447. lcu->pav = BASE_PAV;
  448. break;
  449. case UA_HYPER_PAV_ALIAS:
  450. lcu->pav = HYPER_PAV;
  451. break;
  452. }
  453. if (lcu->pav != NO_PAV)
  454. break;
  455. }
  456. list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
  457. alias_list) {
  458. _add_device_to_lcu(lcu, device, refdev);
  459. }
  460. spin_unlock_irqrestore(&lcu->lock, flags);
  461. return 0;
  462. }
  463. static void lcu_update_work(struct work_struct *work)
  464. {
  465. struct alias_lcu *lcu;
  466. struct read_uac_work_data *ruac_data;
  467. struct dasd_device *device;
  468. unsigned long flags;
  469. int rc;
  470. ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
  471. lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
  472. device = ruac_data->device;
  473. rc = _lcu_update(device, lcu);
  474. /*
  475. * Need to check flags again, as there could have been another
  476. * prepare_update or a new device a new device while we were still
  477. * processing the data
  478. */
  479. spin_lock_irqsave(&lcu->lock, flags);
  480. if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) {
  481. DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
  482. " alias data in lcu (rc = %d), retry later", rc);
  483. if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ))
  484. dasd_put_device(device);
  485. } else {
  486. dasd_put_device(device);
  487. lcu->ruac_data.device = NULL;
  488. lcu->flags &= ~UPDATE_PENDING;
  489. }
  490. spin_unlock_irqrestore(&lcu->lock, flags);
  491. }
  492. static int _schedule_lcu_update(struct alias_lcu *lcu,
  493. struct dasd_device *device)
  494. {
  495. struct dasd_device *usedev = NULL;
  496. struct alias_pav_group *group;
  497. lcu->flags |= NEED_UAC_UPDATE;
  498. if (lcu->ruac_data.device) {
  499. /* already scheduled or running */
  500. return 0;
  501. }
  502. if (device && !list_empty(&device->alias_list))
  503. usedev = device;
  504. if (!usedev && !list_empty(&lcu->grouplist)) {
  505. group = list_first_entry(&lcu->grouplist,
  506. struct alias_pav_group, group);
  507. if (!list_empty(&group->baselist))
  508. usedev = list_first_entry(&group->baselist,
  509. struct dasd_device,
  510. alias_list);
  511. else if (!list_empty(&group->aliaslist))
  512. usedev = list_first_entry(&group->aliaslist,
  513. struct dasd_device,
  514. alias_list);
  515. }
  516. if (!usedev && !list_empty(&lcu->active_devices)) {
  517. usedev = list_first_entry(&lcu->active_devices,
  518. struct dasd_device, alias_list);
  519. }
  520. /*
  521. * if we haven't found a proper device yet, give up for now, the next
  522. * device that will be set active will trigger an lcu update
  523. */
  524. if (!usedev)
  525. return -EINVAL;
  526. dasd_get_device(usedev);
  527. lcu->ruac_data.device = usedev;
  528. if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0))
  529. dasd_put_device(usedev);
  530. return 0;
  531. }
  532. int dasd_alias_add_device(struct dasd_device *device)
  533. {
  534. struct dasd_eckd_private *private = device->private;
  535. __u8 uaddr = private->uid.real_unit_addr;
  536. struct alias_lcu *lcu = private->lcu;
  537. unsigned long flags;
  538. int rc;
  539. rc = 0;
  540. spin_lock_irqsave(&lcu->lock, flags);
  541. /*
  542. * Check if device and lcu type differ. If so, the uac data may be
  543. * outdated and needs to be updated.
  544. */
  545. if (private->uid.type != lcu->uac->unit[uaddr].ua_type) {
  546. lcu->flags |= UPDATE_PENDING;
  547. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  548. "uid type mismatch - trigger rescan");
  549. }
  550. if (!(lcu->flags & UPDATE_PENDING)) {
  551. rc = _add_device_to_lcu(lcu, device, device);
  552. if (rc)
  553. lcu->flags |= UPDATE_PENDING;
  554. }
  555. if (lcu->flags & UPDATE_PENDING) {
  556. list_move(&device->alias_list, &lcu->active_devices);
  557. _schedule_lcu_update(lcu, device);
  558. }
  559. spin_unlock_irqrestore(&lcu->lock, flags);
  560. return rc;
  561. }
  562. int dasd_alias_update_add_device(struct dasd_device *device)
  563. {
  564. struct dasd_eckd_private *private = device->private;
  565. private->lcu->flags |= UPDATE_PENDING;
  566. return dasd_alias_add_device(device);
  567. }
  568. int dasd_alias_remove_device(struct dasd_device *device)
  569. {
  570. struct dasd_eckd_private *private = device->private;
  571. struct alias_lcu *lcu = private->lcu;
  572. unsigned long flags;
  573. /* nothing to do if already removed */
  574. if (!lcu)
  575. return 0;
  576. spin_lock_irqsave(&lcu->lock, flags);
  577. _remove_device_from_lcu(lcu, device);
  578. spin_unlock_irqrestore(&lcu->lock, flags);
  579. return 0;
  580. }
  581. struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
  582. {
  583. struct dasd_eckd_private *alias_priv, *private = base_device->private;
  584. struct alias_pav_group *group = private->pavgroup;
  585. struct alias_lcu *lcu = private->lcu;
  586. struct dasd_device *alias_device;
  587. unsigned long flags;
  588. if (!group || !lcu)
  589. return NULL;
  590. if (lcu->pav == NO_PAV ||
  591. lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
  592. return NULL;
  593. if (unlikely(!(private->features.feature[8] & 0x01))) {
  594. /*
  595. * PAV enabled but prefix not, very unlikely
  596. * seems to be a lost pathgroup
  597. * use base device to do IO
  598. */
  599. DBF_DEV_EVENT(DBF_ERR, base_device, "%s",
  600. "Prefix not enabled with PAV enabled\n");
  601. return NULL;
  602. }
  603. spin_lock_irqsave(&lcu->lock, flags);
  604. alias_device = group->next;
  605. if (!alias_device) {
  606. if (list_empty(&group->aliaslist)) {
  607. spin_unlock_irqrestore(&lcu->lock, flags);
  608. return NULL;
  609. } else {
  610. alias_device = list_first_entry(&group->aliaslist,
  611. struct dasd_device,
  612. alias_list);
  613. }
  614. }
  615. if (list_is_last(&alias_device->alias_list, &group->aliaslist))
  616. group->next = list_first_entry(&group->aliaslist,
  617. struct dasd_device, alias_list);
  618. else
  619. group->next = list_first_entry(&alias_device->alias_list,
  620. struct dasd_device, alias_list);
  621. spin_unlock_irqrestore(&lcu->lock, flags);
  622. alias_priv = alias_device->private;
  623. if ((alias_priv->count < private->count) && !alias_device->stopped &&
  624. !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags))
  625. return alias_device;
  626. else
  627. return NULL;
  628. }
  629. /*
  630. * Summary unit check handling depends on the way alias devices
  631. * are handled so it is done here rather then in dasd_eckd.c
  632. */
  633. static int reset_summary_unit_check(struct alias_lcu *lcu,
  634. struct dasd_device *device,
  635. char reason)
  636. {
  637. struct dasd_ccw_req *cqr;
  638. int rc = 0;
  639. struct ccw1 *ccw;
  640. cqr = lcu->rsu_cqr;
  641. strncpy((char *) &cqr->magic, "ECKD", 4);
  642. ASCEBC((char *) &cqr->magic, 4);
  643. ccw = cqr->cpaddr;
  644. ccw->cmd_code = DASD_ECKD_CCW_RSCK;
  645. ccw->flags = CCW_FLAG_SLI;
  646. ccw->count = 16;
  647. ccw->cda = (__u32)(addr_t) cqr->data;
  648. ((char *)cqr->data)[0] = reason;
  649. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  650. cqr->retries = 255; /* set retry counter to enable basic ERP */
  651. cqr->startdev = device;
  652. cqr->memdev = device;
  653. cqr->block = NULL;
  654. cqr->expires = 5 * HZ;
  655. cqr->buildclk = get_tod_clock();
  656. cqr->status = DASD_CQR_FILLED;
  657. rc = dasd_sleep_on_immediatly(cqr);
  658. return rc;
  659. }
  660. static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
  661. {
  662. struct alias_pav_group *pavgroup;
  663. struct dasd_device *device;
  664. struct dasd_eckd_private *private;
  665. /* active and inactive list can contain alias as well as base devices */
  666. list_for_each_entry(device, &lcu->active_devices, alias_list) {
  667. private = device->private;
  668. if (private->uid.type != UA_BASE_DEVICE)
  669. continue;
  670. dasd_schedule_block_bh(device->block);
  671. dasd_schedule_device_bh(device);
  672. }
  673. list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
  674. private = device->private;
  675. if (private->uid.type != UA_BASE_DEVICE)
  676. continue;
  677. dasd_schedule_block_bh(device->block);
  678. dasd_schedule_device_bh(device);
  679. }
  680. list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  681. list_for_each_entry(device, &pavgroup->baselist, alias_list) {
  682. dasd_schedule_block_bh(device->block);
  683. dasd_schedule_device_bh(device);
  684. }
  685. }
  686. }
  687. static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
  688. {
  689. struct alias_pav_group *pavgroup;
  690. struct dasd_device *device, *temp;
  691. struct dasd_eckd_private *private;
  692. int rc;
  693. unsigned long flags;
  694. LIST_HEAD(active);
  695. /*
  696. * Problem here ist that dasd_flush_device_queue may wait
  697. * for termination of a request to complete. We can't keep
  698. * the lcu lock during that time, so we must assume that
  699. * the lists may have changed.
  700. * Idea: first gather all active alias devices in a separate list,
  701. * then flush the first element of this list unlocked, and afterwards
  702. * check if it is still on the list before moving it to the
  703. * active_devices list.
  704. */
  705. spin_lock_irqsave(&lcu->lock, flags);
  706. list_for_each_entry_safe(device, temp, &lcu->active_devices,
  707. alias_list) {
  708. private = device->private;
  709. if (private->uid.type == UA_BASE_DEVICE)
  710. continue;
  711. list_move(&device->alias_list, &active);
  712. }
  713. list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  714. list_splice_init(&pavgroup->aliaslist, &active);
  715. }
  716. while (!list_empty(&active)) {
  717. device = list_first_entry(&active, struct dasd_device,
  718. alias_list);
  719. spin_unlock_irqrestore(&lcu->lock, flags);
  720. rc = dasd_flush_device_queue(device);
  721. spin_lock_irqsave(&lcu->lock, flags);
  722. /*
  723. * only move device around if it wasn't moved away while we
  724. * were waiting for the flush
  725. */
  726. if (device == list_first_entry(&active,
  727. struct dasd_device, alias_list)) {
  728. list_move(&device->alias_list, &lcu->active_devices);
  729. private = device->private;
  730. private->pavgroup = NULL;
  731. }
  732. }
  733. spin_unlock_irqrestore(&lcu->lock, flags);
  734. }
  735. static void _stop_all_devices_on_lcu(struct alias_lcu *lcu)
  736. {
  737. struct alias_pav_group *pavgroup;
  738. struct dasd_device *device;
  739. list_for_each_entry(device, &lcu->active_devices, alias_list) {
  740. spin_lock(get_ccwdev_lock(device->cdev));
  741. dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
  742. spin_unlock(get_ccwdev_lock(device->cdev));
  743. }
  744. list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
  745. spin_lock(get_ccwdev_lock(device->cdev));
  746. dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
  747. spin_unlock(get_ccwdev_lock(device->cdev));
  748. }
  749. list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  750. list_for_each_entry(device, &pavgroup->baselist, alias_list) {
  751. spin_lock(get_ccwdev_lock(device->cdev));
  752. dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
  753. spin_unlock(get_ccwdev_lock(device->cdev));
  754. }
  755. list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
  756. spin_lock(get_ccwdev_lock(device->cdev));
  757. dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
  758. spin_unlock(get_ccwdev_lock(device->cdev));
  759. }
  760. }
  761. }
  762. static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
  763. {
  764. struct alias_pav_group *pavgroup;
  765. struct dasd_device *device;
  766. list_for_each_entry(device, &lcu->active_devices, alias_list) {
  767. spin_lock(get_ccwdev_lock(device->cdev));
  768. dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
  769. spin_unlock(get_ccwdev_lock(device->cdev));
  770. }
  771. list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
  772. spin_lock(get_ccwdev_lock(device->cdev));
  773. dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
  774. spin_unlock(get_ccwdev_lock(device->cdev));
  775. }
  776. list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  777. list_for_each_entry(device, &pavgroup->baselist, alias_list) {
  778. spin_lock(get_ccwdev_lock(device->cdev));
  779. dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
  780. spin_unlock(get_ccwdev_lock(device->cdev));
  781. }
  782. list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
  783. spin_lock(get_ccwdev_lock(device->cdev));
  784. dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
  785. spin_unlock(get_ccwdev_lock(device->cdev));
  786. }
  787. }
  788. }
  789. static void summary_unit_check_handling_work(struct work_struct *work)
  790. {
  791. struct alias_lcu *lcu;
  792. struct summary_unit_check_work_data *suc_data;
  793. unsigned long flags;
  794. struct dasd_device *device;
  795. suc_data = container_of(work, struct summary_unit_check_work_data,
  796. worker);
  797. lcu = container_of(suc_data, struct alias_lcu, suc_data);
  798. device = suc_data->device;
  799. /* 1. flush alias devices */
  800. flush_all_alias_devices_on_lcu(lcu);
  801. /* 2. reset summary unit check */
  802. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  803. dasd_device_remove_stop_bits(device,
  804. (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
  805. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  806. reset_summary_unit_check(lcu, device, suc_data->reason);
  807. spin_lock_irqsave(&lcu->lock, flags);
  808. _unstop_all_devices_on_lcu(lcu);
  809. _restart_all_base_devices_on_lcu(lcu);
  810. /* 3. read new alias configuration */
  811. _schedule_lcu_update(lcu, device);
  812. lcu->suc_data.device = NULL;
  813. dasd_put_device(device);
  814. spin_unlock_irqrestore(&lcu->lock, flags);
  815. }
  816. void dasd_alias_handle_summary_unit_check(struct work_struct *work)
  817. {
  818. struct dasd_device *device = container_of(work, struct dasd_device,
  819. suc_work);
  820. struct dasd_eckd_private *private = device->private;
  821. struct alias_lcu *lcu;
  822. unsigned long flags;
  823. lcu = private->lcu;
  824. if (!lcu) {
  825. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  826. "device not ready to handle summary"
  827. " unit check (no lcu structure)");
  828. goto out;
  829. }
  830. spin_lock_irqsave(&lcu->lock, flags);
  831. /* If this device is about to be removed just return and wait for
  832. * the next interrupt on a different device
  833. */
  834. if (list_empty(&device->alias_list)) {
  835. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  836. "device is in offline processing,"
  837. " don't do summary unit check handling");
  838. goto out_unlock;
  839. }
  840. if (lcu->suc_data.device) {
  841. /* already scheduled or running */
  842. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  843. "previous instance of summary unit check worker"
  844. " still pending");
  845. goto out_unlock;
  846. }
  847. _stop_all_devices_on_lcu(lcu);
  848. /* prepare for lcu_update */
  849. lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
  850. lcu->suc_data.reason = private->suc_reason;
  851. lcu->suc_data.device = device;
  852. dasd_get_device(device);
  853. if (!schedule_work(&lcu->suc_data.worker))
  854. dasd_put_device(device);
  855. out_unlock:
  856. spin_unlock_irqrestore(&lcu->lock, flags);
  857. out:
  858. clear_bit(DASD_FLAG_SUC, &device->flags);
  859. dasd_put_device(device);
  860. };