device_pgid.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * CCW device PGID and path verification I/O handling.
  3. *
  4. * Copyright IBM Corp. 2002, 2009
  5. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/bitops.h>
  12. #include <linux/types.h>
  13. #include <linux/errno.h>
  14. #include <linux/slab.h>
  15. #include <asm/ccwdev.h>
  16. #include <asm/cio.h>
  17. #include "cio.h"
  18. #include "cio_debug.h"
  19. #include "device.h"
  20. #include "io_sch.h"
  21. #define PGID_RETRIES 256
  22. #define PGID_TIMEOUT (10 * HZ)
  23. static void verify_start(struct ccw_device *cdev);
  24. /*
  25. * Process path verification data and report result.
  26. */
  27. static void verify_done(struct ccw_device *cdev, int rc)
  28. {
  29. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  30. struct ccw_dev_id *id = &cdev->private->dev_id;
  31. int mpath = cdev->private->flags.mpath;
  32. int pgroup = cdev->private->flags.pgroup;
  33. if (rc)
  34. goto out;
  35. /* Ensure consistent multipathing state at device and channel. */
  36. if (sch->config.mp != mpath) {
  37. sch->config.mp = mpath;
  38. rc = cio_commit_config(sch);
  39. }
  40. out:
  41. CIO_MSG_EVENT(2, "vrfy: device 0.%x.%04x: rc=%d pgroup=%d mpath=%d "
  42. "vpm=%02x\n", id->ssid, id->devno, rc, pgroup, mpath,
  43. sch->vpm);
  44. ccw_device_verify_done(cdev, rc);
  45. }
  46. /*
  47. * Create channel program to perform a NOOP.
  48. */
  49. static void nop_build_cp(struct ccw_device *cdev)
  50. {
  51. struct ccw_request *req = &cdev->private->req;
  52. struct ccw1 *cp = cdev->private->iccws;
  53. cp->cmd_code = CCW_CMD_NOOP;
  54. cp->cda = 0;
  55. cp->count = 0;
  56. cp->flags = CCW_FLAG_SLI;
  57. req->cp = cp;
  58. }
  59. /*
  60. * Perform NOOP on a single path.
  61. */
  62. static void nop_do(struct ccw_device *cdev)
  63. {
  64. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  65. struct ccw_request *req = &cdev->private->req;
  66. req->lpm = lpm_adjust(req->lpm, sch->schib.pmcw.pam & sch->opm &
  67. ~cdev->private->path_noirq_mask);
  68. if (!req->lpm)
  69. goto out_nopath;
  70. nop_build_cp(cdev);
  71. ccw_request_start(cdev);
  72. return;
  73. out_nopath:
  74. verify_done(cdev, sch->vpm ? 0 : -EACCES);
  75. }
  76. /*
  77. * Adjust NOOP I/O status.
  78. */
  79. static enum io_status nop_filter(struct ccw_device *cdev, void *data,
  80. struct irb *irb, enum io_status status)
  81. {
  82. /* Only subchannel status might indicate a path error. */
  83. if (status == IO_STATUS_ERROR && irb->scsw.cmd.cstat == 0)
  84. return IO_DONE;
  85. return status;
  86. }
  87. /*
  88. * Process NOOP request result for a single path.
  89. */
  90. static void nop_callback(struct ccw_device *cdev, void *data, int rc)
  91. {
  92. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  93. struct ccw_request *req = &cdev->private->req;
  94. switch (rc) {
  95. case 0:
  96. sch->vpm |= req->lpm;
  97. break;
  98. case -ETIME:
  99. cdev->private->path_noirq_mask |= req->lpm;
  100. break;
  101. case -EACCES:
  102. cdev->private->path_notoper_mask |= req->lpm;
  103. break;
  104. default:
  105. goto err;
  106. }
  107. /* Continue on the next path. */
  108. req->lpm >>= 1;
  109. nop_do(cdev);
  110. return;
  111. err:
  112. verify_done(cdev, rc);
  113. }
  114. /*
  115. * Create channel program to perform SET PGID on a single path.
  116. */
  117. static void spid_build_cp(struct ccw_device *cdev, u8 fn)
  118. {
  119. struct ccw_request *req = &cdev->private->req;
  120. struct ccw1 *cp = cdev->private->iccws;
  121. int i = pathmask_to_pos(req->lpm);
  122. struct pgid *pgid = &cdev->private->pgid[i];
  123. pgid->inf.fc = fn;
  124. cp->cmd_code = CCW_CMD_SET_PGID;
  125. cp->cda = (u32) (addr_t) pgid;
  126. cp->count = sizeof(*pgid);
  127. cp->flags = CCW_FLAG_SLI;
  128. req->cp = cp;
  129. }
  130. static void pgid_wipeout_callback(struct ccw_device *cdev, void *data, int rc)
  131. {
  132. if (rc) {
  133. /* We don't know the path groups' state. Abort. */
  134. verify_done(cdev, rc);
  135. return;
  136. }
  137. /*
  138. * Path groups have been reset. Restart path verification but
  139. * leave paths in path_noirq_mask out.
  140. */
  141. cdev->private->flags.pgid_unknown = 0;
  142. verify_start(cdev);
  143. }
  144. /*
  145. * Reset pathgroups and restart path verification, leave unusable paths out.
  146. */
  147. static void pgid_wipeout_start(struct ccw_device *cdev)
  148. {
  149. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  150. struct ccw_dev_id *id = &cdev->private->dev_id;
  151. struct ccw_request *req = &cdev->private->req;
  152. u8 fn;
  153. CIO_MSG_EVENT(2, "wipe: device 0.%x.%04x: pvm=%02x nim=%02x\n",
  154. id->ssid, id->devno, cdev->private->pgid_valid_mask,
  155. cdev->private->path_noirq_mask);
  156. /* Initialize request data. */
  157. memset(req, 0, sizeof(*req));
  158. req->timeout = PGID_TIMEOUT;
  159. req->maxretries = PGID_RETRIES;
  160. req->lpm = sch->schib.pmcw.pam;
  161. req->callback = pgid_wipeout_callback;
  162. fn = SPID_FUNC_DISBAND;
  163. if (cdev->private->flags.mpath)
  164. fn |= SPID_FUNC_MULTI_PATH;
  165. spid_build_cp(cdev, fn);
  166. ccw_request_start(cdev);
  167. }
  168. /*
  169. * Perform establish/resign SET PGID on a single path.
  170. */
  171. static void spid_do(struct ccw_device *cdev)
  172. {
  173. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  174. struct ccw_request *req = &cdev->private->req;
  175. u8 fn;
  176. /* Use next available path that is not already in correct state. */
  177. req->lpm = lpm_adjust(req->lpm, cdev->private->pgid_todo_mask);
  178. if (!req->lpm)
  179. goto out_nopath;
  180. /* Channel program setup. */
  181. if (req->lpm & sch->opm)
  182. fn = SPID_FUNC_ESTABLISH;
  183. else
  184. fn = SPID_FUNC_RESIGN;
  185. if (cdev->private->flags.mpath)
  186. fn |= SPID_FUNC_MULTI_PATH;
  187. spid_build_cp(cdev, fn);
  188. ccw_request_start(cdev);
  189. return;
  190. out_nopath:
  191. if (cdev->private->flags.pgid_unknown) {
  192. /* At least one SPID could be partially done. */
  193. pgid_wipeout_start(cdev);
  194. return;
  195. }
  196. verify_done(cdev, sch->vpm ? 0 : -EACCES);
  197. }
  198. /*
  199. * Process SET PGID request result for a single path.
  200. */
  201. static void spid_callback(struct ccw_device *cdev, void *data, int rc)
  202. {
  203. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  204. struct ccw_request *req = &cdev->private->req;
  205. switch (rc) {
  206. case 0:
  207. sch->vpm |= req->lpm & sch->opm;
  208. break;
  209. case -ETIME:
  210. cdev->private->flags.pgid_unknown = 1;
  211. cdev->private->path_noirq_mask |= req->lpm;
  212. break;
  213. case -EACCES:
  214. cdev->private->path_notoper_mask |= req->lpm;
  215. break;
  216. case -EOPNOTSUPP:
  217. if (cdev->private->flags.mpath) {
  218. /* Try without multipathing. */
  219. cdev->private->flags.mpath = 0;
  220. goto out_restart;
  221. }
  222. /* Try without pathgrouping. */
  223. cdev->private->flags.pgroup = 0;
  224. goto out_restart;
  225. default:
  226. goto err;
  227. }
  228. req->lpm >>= 1;
  229. spid_do(cdev);
  230. return;
  231. out_restart:
  232. verify_start(cdev);
  233. return;
  234. err:
  235. verify_done(cdev, rc);
  236. }
  237. static void spid_start(struct ccw_device *cdev)
  238. {
  239. struct ccw_request *req = &cdev->private->req;
  240. /* Initialize request data. */
  241. memset(req, 0, sizeof(*req));
  242. req->timeout = PGID_TIMEOUT;
  243. req->maxretries = PGID_RETRIES;
  244. req->lpm = 0x80;
  245. req->singlepath = 1;
  246. req->callback = spid_callback;
  247. spid_do(cdev);
  248. }
  249. static int pgid_is_reset(struct pgid *p)
  250. {
  251. char *c;
  252. for (c = (char *)p + 1; c < (char *)(p + 1); c++) {
  253. if (*c != 0)
  254. return 0;
  255. }
  256. return 1;
  257. }
  258. static int pgid_cmp(struct pgid *p1, struct pgid *p2)
  259. {
  260. return memcmp((char *) p1 + 1, (char *) p2 + 1,
  261. sizeof(struct pgid) - 1);
  262. }
  263. /*
  264. * Determine pathgroup state from PGID data.
  265. */
  266. static void pgid_analyze(struct ccw_device *cdev, struct pgid **p,
  267. int *mismatch, u8 *reserved, u8 *reset)
  268. {
  269. struct pgid *pgid = &cdev->private->pgid[0];
  270. struct pgid *first = NULL;
  271. int lpm;
  272. int i;
  273. *mismatch = 0;
  274. *reserved = 0;
  275. *reset = 0;
  276. for (i = 0, lpm = 0x80; i < 8; i++, pgid++, lpm >>= 1) {
  277. if ((cdev->private->pgid_valid_mask & lpm) == 0)
  278. continue;
  279. if (pgid->inf.ps.state2 == SNID_STATE2_RESVD_ELSE)
  280. *reserved |= lpm;
  281. if (pgid_is_reset(pgid)) {
  282. *reset |= lpm;
  283. continue;
  284. }
  285. if (!first) {
  286. first = pgid;
  287. continue;
  288. }
  289. if (pgid_cmp(pgid, first) != 0)
  290. *mismatch = 1;
  291. }
  292. if (!first)
  293. first = &channel_subsystems[0]->global_pgid;
  294. *p = first;
  295. }
  296. static u8 pgid_to_donepm(struct ccw_device *cdev)
  297. {
  298. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  299. struct pgid *pgid;
  300. int i;
  301. int lpm;
  302. u8 donepm = 0;
  303. /* Set bits for paths which are already in the target state. */
  304. for (i = 0; i < 8; i++) {
  305. lpm = 0x80 >> i;
  306. if ((cdev->private->pgid_valid_mask & lpm) == 0)
  307. continue;
  308. pgid = &cdev->private->pgid[i];
  309. if (sch->opm & lpm) {
  310. if (pgid->inf.ps.state1 != SNID_STATE1_GROUPED)
  311. continue;
  312. } else {
  313. if (pgid->inf.ps.state1 != SNID_STATE1_UNGROUPED)
  314. continue;
  315. }
  316. if (cdev->private->flags.mpath) {
  317. if (pgid->inf.ps.state3 != SNID_STATE3_MULTI_PATH)
  318. continue;
  319. } else {
  320. if (pgid->inf.ps.state3 != SNID_STATE3_SINGLE_PATH)
  321. continue;
  322. }
  323. donepm |= lpm;
  324. }
  325. return donepm;
  326. }
  327. static void pgid_fill(struct ccw_device *cdev, struct pgid *pgid)
  328. {
  329. int i;
  330. for (i = 0; i < 8; i++)
  331. memcpy(&cdev->private->pgid[i], pgid, sizeof(struct pgid));
  332. }
  333. /*
  334. * Process SENSE PGID data and report result.
  335. */
  336. static void snid_done(struct ccw_device *cdev, int rc)
  337. {
  338. struct ccw_dev_id *id = &cdev->private->dev_id;
  339. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  340. struct pgid *pgid;
  341. int mismatch = 0;
  342. u8 reserved = 0;
  343. u8 reset = 0;
  344. u8 donepm;
  345. if (rc)
  346. goto out;
  347. pgid_analyze(cdev, &pgid, &mismatch, &reserved, &reset);
  348. if (reserved == cdev->private->pgid_valid_mask)
  349. rc = -EUSERS;
  350. else if (mismatch)
  351. rc = -EOPNOTSUPP;
  352. else {
  353. donepm = pgid_to_donepm(cdev);
  354. sch->vpm = donepm & sch->opm;
  355. cdev->private->pgid_reset_mask |= reset;
  356. cdev->private->pgid_todo_mask &=
  357. ~(donepm | cdev->private->path_noirq_mask);
  358. pgid_fill(cdev, pgid);
  359. }
  360. out:
  361. CIO_MSG_EVENT(2, "snid: device 0.%x.%04x: rc=%d pvm=%02x vpm=%02x "
  362. "todo=%02x mism=%d rsvd=%02x reset=%02x\n", id->ssid,
  363. id->devno, rc, cdev->private->pgid_valid_mask, sch->vpm,
  364. cdev->private->pgid_todo_mask, mismatch, reserved, reset);
  365. switch (rc) {
  366. case 0:
  367. if (cdev->private->flags.pgid_unknown) {
  368. pgid_wipeout_start(cdev);
  369. return;
  370. }
  371. /* Anything left to do? */
  372. if (cdev->private->pgid_todo_mask == 0) {
  373. verify_done(cdev, sch->vpm == 0 ? -EACCES : 0);
  374. return;
  375. }
  376. /* Perform path-grouping. */
  377. spid_start(cdev);
  378. break;
  379. case -EOPNOTSUPP:
  380. /* Path-grouping not supported. */
  381. cdev->private->flags.pgroup = 0;
  382. cdev->private->flags.mpath = 0;
  383. verify_start(cdev);
  384. break;
  385. default:
  386. verify_done(cdev, rc);
  387. }
  388. }
  389. /*
  390. * Create channel program to perform a SENSE PGID on a single path.
  391. */
  392. static void snid_build_cp(struct ccw_device *cdev)
  393. {
  394. struct ccw_request *req = &cdev->private->req;
  395. struct ccw1 *cp = cdev->private->iccws;
  396. int i = pathmask_to_pos(req->lpm);
  397. /* Channel program setup. */
  398. cp->cmd_code = CCW_CMD_SENSE_PGID;
  399. cp->cda = (u32) (addr_t) &cdev->private->pgid[i];
  400. cp->count = sizeof(struct pgid);
  401. cp->flags = CCW_FLAG_SLI;
  402. req->cp = cp;
  403. }
  404. /*
  405. * Perform SENSE PGID on a single path.
  406. */
  407. static void snid_do(struct ccw_device *cdev)
  408. {
  409. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  410. struct ccw_request *req = &cdev->private->req;
  411. int ret;
  412. req->lpm = lpm_adjust(req->lpm, sch->schib.pmcw.pam &
  413. ~cdev->private->path_noirq_mask);
  414. if (!req->lpm)
  415. goto out_nopath;
  416. snid_build_cp(cdev);
  417. ccw_request_start(cdev);
  418. return;
  419. out_nopath:
  420. if (cdev->private->pgid_valid_mask)
  421. ret = 0;
  422. else if (cdev->private->path_noirq_mask)
  423. ret = -ETIME;
  424. else
  425. ret = -EACCES;
  426. snid_done(cdev, ret);
  427. }
  428. /*
  429. * Process SENSE PGID request result for single path.
  430. */
  431. static void snid_callback(struct ccw_device *cdev, void *data, int rc)
  432. {
  433. struct ccw_request *req = &cdev->private->req;
  434. switch (rc) {
  435. case 0:
  436. cdev->private->pgid_valid_mask |= req->lpm;
  437. break;
  438. case -ETIME:
  439. cdev->private->flags.pgid_unknown = 1;
  440. cdev->private->path_noirq_mask |= req->lpm;
  441. break;
  442. case -EACCES:
  443. cdev->private->path_notoper_mask |= req->lpm;
  444. break;
  445. default:
  446. goto err;
  447. }
  448. /* Continue on the next path. */
  449. req->lpm >>= 1;
  450. snid_do(cdev);
  451. return;
  452. err:
  453. snid_done(cdev, rc);
  454. }
  455. /*
  456. * Perform path verification.
  457. */
  458. static void verify_start(struct ccw_device *cdev)
  459. {
  460. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  461. struct ccw_request *req = &cdev->private->req;
  462. struct ccw_dev_id *devid = &cdev->private->dev_id;
  463. sch->vpm = 0;
  464. sch->lpm = sch->schib.pmcw.pam;
  465. /* Initialize PGID data. */
  466. memset(cdev->private->pgid, 0, sizeof(cdev->private->pgid));
  467. cdev->private->pgid_valid_mask = 0;
  468. cdev->private->pgid_todo_mask = sch->schib.pmcw.pam;
  469. cdev->private->path_notoper_mask = 0;
  470. /* Initialize request data. */
  471. memset(req, 0, sizeof(*req));
  472. req->timeout = PGID_TIMEOUT;
  473. req->maxretries = PGID_RETRIES;
  474. req->lpm = 0x80;
  475. req->singlepath = 1;
  476. if (cdev->private->flags.pgroup) {
  477. CIO_TRACE_EVENT(4, "snid");
  478. CIO_HEX_EVENT(4, devid, sizeof(*devid));
  479. req->callback = snid_callback;
  480. snid_do(cdev);
  481. } else {
  482. CIO_TRACE_EVENT(4, "nop");
  483. CIO_HEX_EVENT(4, devid, sizeof(*devid));
  484. req->filter = nop_filter;
  485. req->callback = nop_callback;
  486. nop_do(cdev);
  487. }
  488. }
  489. /**
  490. * ccw_device_verify_start - perform path verification
  491. * @cdev: ccw device
  492. *
  493. * Perform an I/O on each available channel path to @cdev to determine which
  494. * paths are operational. The resulting path mask is stored in sch->vpm.
  495. * If device options specify pathgrouping, establish a pathgroup for the
  496. * operational paths. When finished, call ccw_device_verify_done with a
  497. * return code specifying the result.
  498. */
  499. void ccw_device_verify_start(struct ccw_device *cdev)
  500. {
  501. CIO_TRACE_EVENT(4, "vrfy");
  502. CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
  503. /*
  504. * Initialize pathgroup and multipath state with target values.
  505. * They may change in the course of path verification.
  506. */
  507. cdev->private->flags.pgroup = cdev->private->options.pgroup;
  508. cdev->private->flags.mpath = cdev->private->options.mpath;
  509. cdev->private->flags.doverify = 0;
  510. cdev->private->path_noirq_mask = 0;
  511. verify_start(cdev);
  512. }
  513. /*
  514. * Process disband SET PGID request result.
  515. */
  516. static void disband_callback(struct ccw_device *cdev, void *data, int rc)
  517. {
  518. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  519. struct ccw_dev_id *id = &cdev->private->dev_id;
  520. if (rc)
  521. goto out;
  522. /* Ensure consistent multipathing state at device and channel. */
  523. cdev->private->flags.mpath = 0;
  524. if (sch->config.mp) {
  525. sch->config.mp = 0;
  526. rc = cio_commit_config(sch);
  527. }
  528. out:
  529. CIO_MSG_EVENT(0, "disb: device 0.%x.%04x: rc=%d\n", id->ssid, id->devno,
  530. rc);
  531. ccw_device_disband_done(cdev, rc);
  532. }
  533. /**
  534. * ccw_device_disband_start - disband pathgroup
  535. * @cdev: ccw device
  536. *
  537. * Execute a SET PGID channel program on @cdev to disband a previously
  538. * established pathgroup. When finished, call ccw_device_disband_done with
  539. * a return code specifying the result.
  540. */
  541. void ccw_device_disband_start(struct ccw_device *cdev)
  542. {
  543. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  544. struct ccw_request *req = &cdev->private->req;
  545. u8 fn;
  546. CIO_TRACE_EVENT(4, "disb");
  547. CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
  548. /* Request setup. */
  549. memset(req, 0, sizeof(*req));
  550. req->timeout = PGID_TIMEOUT;
  551. req->maxretries = PGID_RETRIES;
  552. req->lpm = sch->schib.pmcw.pam & sch->opm;
  553. req->singlepath = 1;
  554. req->callback = disband_callback;
  555. fn = SPID_FUNC_DISBAND;
  556. if (cdev->private->flags.mpath)
  557. fn |= SPID_FUNC_MULTI_PATH;
  558. spid_build_cp(cdev, fn);
  559. ccw_request_start(cdev);
  560. }
  561. struct stlck_data {
  562. struct completion done;
  563. int rc;
  564. };
  565. static void stlck_build_cp(struct ccw_device *cdev, void *buf1, void *buf2)
  566. {
  567. struct ccw_request *req = &cdev->private->req;
  568. struct ccw1 *cp = cdev->private->iccws;
  569. cp[0].cmd_code = CCW_CMD_STLCK;
  570. cp[0].cda = (u32) (addr_t) buf1;
  571. cp[0].count = 32;
  572. cp[0].flags = CCW_FLAG_CC;
  573. cp[1].cmd_code = CCW_CMD_RELEASE;
  574. cp[1].cda = (u32) (addr_t) buf2;
  575. cp[1].count = 32;
  576. cp[1].flags = 0;
  577. req->cp = cp;
  578. }
  579. static void stlck_callback(struct ccw_device *cdev, void *data, int rc)
  580. {
  581. struct stlck_data *sdata = data;
  582. sdata->rc = rc;
  583. complete(&sdata->done);
  584. }
  585. /**
  586. * ccw_device_stlck_start - perform unconditional release
  587. * @cdev: ccw device
  588. * @data: data pointer to be passed to ccw_device_stlck_done
  589. * @buf1: data pointer used in channel program
  590. * @buf2: data pointer used in channel program
  591. *
  592. * Execute a channel program on @cdev to release an existing PGID reservation.
  593. */
  594. static void ccw_device_stlck_start(struct ccw_device *cdev, void *data,
  595. void *buf1, void *buf2)
  596. {
  597. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  598. struct ccw_request *req = &cdev->private->req;
  599. CIO_TRACE_EVENT(4, "stlck");
  600. CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
  601. /* Request setup. */
  602. memset(req, 0, sizeof(*req));
  603. req->timeout = PGID_TIMEOUT;
  604. req->maxretries = PGID_RETRIES;
  605. req->lpm = sch->schib.pmcw.pam & sch->opm;
  606. req->data = data;
  607. req->callback = stlck_callback;
  608. stlck_build_cp(cdev, buf1, buf2);
  609. ccw_request_start(cdev);
  610. }
  611. /*
  612. * Perform unconditional reserve + release.
  613. */
  614. int ccw_device_stlck(struct ccw_device *cdev)
  615. {
  616. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  617. struct stlck_data data;
  618. u8 *buffer;
  619. int rc;
  620. /* Check if steal lock operation is valid for this device. */
  621. if (cdev->drv) {
  622. if (!cdev->private->options.force)
  623. return -EINVAL;
  624. }
  625. buffer = kzalloc(64, GFP_DMA | GFP_KERNEL);
  626. if (!buffer)
  627. return -ENOMEM;
  628. init_completion(&data.done);
  629. data.rc = -EIO;
  630. spin_lock_irq(sch->lock);
  631. rc = cio_enable_subchannel(sch, (u32) (addr_t) sch);
  632. if (rc)
  633. goto out_unlock;
  634. /* Perform operation. */
  635. cdev->private->state = DEV_STATE_STEAL_LOCK;
  636. ccw_device_stlck_start(cdev, &data, &buffer[0], &buffer[32]);
  637. spin_unlock_irq(sch->lock);
  638. /* Wait for operation to finish. */
  639. if (wait_for_completion_interruptible(&data.done)) {
  640. /* Got a signal. */
  641. spin_lock_irq(sch->lock);
  642. ccw_request_cancel(cdev);
  643. spin_unlock_irq(sch->lock);
  644. wait_for_completion(&data.done);
  645. }
  646. rc = data.rc;
  647. /* Check results. */
  648. spin_lock_irq(sch->lock);
  649. cio_disable_subchannel(sch);
  650. cdev->private->state = DEV_STATE_BOXED;
  651. out_unlock:
  652. spin_unlock_irq(sch->lock);
  653. kfree(buffer);
  654. return rc;
  655. }