device_ops.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Copyright IBM Corp. 2002, 2009
  3. *
  4. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  5. * Cornelia Huck (cornelia.huck@de.ibm.com)
  6. */
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/errno.h>
  10. #include <linux/slab.h>
  11. #include <linux/list.h>
  12. #include <linux/device.h>
  13. #include <linux/delay.h>
  14. #include <asm/ccwdev.h>
  15. #include <asm/idals.h>
  16. #include <asm/chpid.h>
  17. #include <asm/fcx.h>
  18. #include "cio.h"
  19. #include "cio_debug.h"
  20. #include "css.h"
  21. #include "chsc.h"
  22. #include "device.h"
  23. #include "chp.h"
  24. /**
  25. * ccw_device_set_options_mask() - set some options and unset the rest
  26. * @cdev: device for which the options are to be set
  27. * @flags: options to be set
  28. *
  29. * All flags specified in @flags are set, all flags not specified in @flags
  30. * are cleared.
  31. * Returns:
  32. * %0 on success, -%EINVAL on an invalid flag combination.
  33. */
  34. int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
  35. {
  36. /*
  37. * The flag usage is mutal exclusive ...
  38. */
  39. if ((flags & CCWDEV_EARLY_NOTIFICATION) &&
  40. (flags & CCWDEV_REPORT_ALL))
  41. return -EINVAL;
  42. cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
  43. cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0;
  44. cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0;
  45. cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0;
  46. return 0;
  47. }
  48. /**
  49. * ccw_device_set_options() - set some options
  50. * @cdev: device for which the options are to be set
  51. * @flags: options to be set
  52. *
  53. * All flags specified in @flags are set, the remainder is left untouched.
  54. * Returns:
  55. * %0 on success, -%EINVAL if an invalid flag combination would ensue.
  56. */
  57. int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
  58. {
  59. /*
  60. * The flag usage is mutal exclusive ...
  61. */
  62. if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
  63. (flags & CCWDEV_REPORT_ALL)) ||
  64. ((flags & CCWDEV_EARLY_NOTIFICATION) &&
  65. cdev->private->options.repall) ||
  66. ((flags & CCWDEV_REPORT_ALL) &&
  67. cdev->private->options.fast))
  68. return -EINVAL;
  69. cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
  70. cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
  71. cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
  72. cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
  73. return 0;
  74. }
  75. /**
  76. * ccw_device_clear_options() - clear some options
  77. * @cdev: device for which the options are to be cleared
  78. * @flags: options to be cleared
  79. *
  80. * All flags specified in @flags are cleared, the remainder is left untouched.
  81. */
  82. void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
  83. {
  84. cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
  85. cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
  86. cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
  87. cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
  88. }
  89. /**
  90. * ccw_device_clear() - terminate I/O request processing
  91. * @cdev: target ccw device
  92. * @intparm: interruption parameter; value is only used if no I/O is
  93. * outstanding, otherwise the intparm associated with the I/O request
  94. * is returned
  95. *
  96. * ccw_device_clear() calls csch on @cdev's subchannel.
  97. * Returns:
  98. * %0 on success,
  99. * -%ENODEV on device not operational,
  100. * -%EINVAL on invalid device state.
  101. * Context:
  102. * Interrupts disabled, ccw device lock held
  103. */
  104. int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
  105. {
  106. struct subchannel *sch;
  107. int ret;
  108. if (!cdev || !cdev->dev.parent)
  109. return -ENODEV;
  110. sch = to_subchannel(cdev->dev.parent);
  111. if (!sch->schib.pmcw.ena)
  112. return -EINVAL;
  113. if (cdev->private->state == DEV_STATE_NOT_OPER)
  114. return -ENODEV;
  115. if (cdev->private->state != DEV_STATE_ONLINE &&
  116. cdev->private->state != DEV_STATE_W4SENSE)
  117. return -EINVAL;
  118. ret = cio_clear(sch);
  119. if (ret == 0)
  120. cdev->private->intparm = intparm;
  121. return ret;
  122. }
  123. /**
  124. * ccw_device_start_key() - start a s390 channel program with key
  125. * @cdev: target ccw device
  126. * @cpa: logical start address of channel program
  127. * @intparm: user specific interruption parameter; will be presented back to
  128. * @cdev's interrupt handler. Allows a device driver to associate
  129. * the interrupt with a particular I/O request.
  130. * @lpm: defines the channel path to be used for a specific I/O request. A
  131. * value of 0 will make cio use the opm.
  132. * @key: storage key to be used for the I/O
  133. * @flags: additional flags; defines the action to be performed for I/O
  134. * processing.
  135. *
  136. * Start a S/390 channel program. When the interrupt arrives, the
  137. * IRQ handler is called, either immediately, delayed (dev-end missing,
  138. * or sense required) or never (no IRQ handler registered).
  139. * Returns:
  140. * %0, if the operation was successful;
  141. * -%EBUSY, if the device is busy, or status pending;
  142. * -%EACCES, if no path specified in @lpm is operational;
  143. * -%ENODEV, if the device is not operational.
  144. * Context:
  145. * Interrupts disabled, ccw device lock held
  146. */
  147. int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
  148. unsigned long intparm, __u8 lpm, __u8 key,
  149. unsigned long flags)
  150. {
  151. struct subchannel *sch;
  152. int ret;
  153. if (!cdev || !cdev->dev.parent)
  154. return -ENODEV;
  155. sch = to_subchannel(cdev->dev.parent);
  156. if (!sch->schib.pmcw.ena)
  157. return -EINVAL;
  158. if (cdev->private->state == DEV_STATE_NOT_OPER)
  159. return -ENODEV;
  160. if (cdev->private->state == DEV_STATE_VERIFY) {
  161. /* Remember to fake irb when finished. */
  162. if (!cdev->private->flags.fake_irb) {
  163. cdev->private->flags.fake_irb = 1;
  164. cdev->private->intparm = intparm;
  165. return 0;
  166. } else
  167. /* There's already a fake I/O around. */
  168. return -EBUSY;
  169. }
  170. if (cdev->private->state != DEV_STATE_ONLINE ||
  171. ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
  172. !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
  173. cdev->private->flags.doverify)
  174. return -EBUSY;
  175. ret = cio_set_options (sch, flags);
  176. if (ret)
  177. return ret;
  178. /* Adjust requested path mask to excluded varied off paths. */
  179. if (lpm) {
  180. lpm &= sch->opm;
  181. if (lpm == 0)
  182. return -EACCES;
  183. }
  184. ret = cio_start_key (sch, cpa, lpm, key);
  185. switch (ret) {
  186. case 0:
  187. cdev->private->intparm = intparm;
  188. break;
  189. case -EACCES:
  190. case -ENODEV:
  191. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  192. break;
  193. }
  194. return ret;
  195. }
  196. /**
  197. * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
  198. * @cdev: target ccw device
  199. * @cpa: logical start address of channel program
  200. * @intparm: user specific interruption parameter; will be presented back to
  201. * @cdev's interrupt handler. Allows a device driver to associate
  202. * the interrupt with a particular I/O request.
  203. * @lpm: defines the channel path to be used for a specific I/O request. A
  204. * value of 0 will make cio use the opm.
  205. * @key: storage key to be used for the I/O
  206. * @flags: additional flags; defines the action to be performed for I/O
  207. * processing.
  208. * @expires: timeout value in jiffies
  209. *
  210. * Start a S/390 channel program. When the interrupt arrives, the
  211. * IRQ handler is called, either immediately, delayed (dev-end missing,
  212. * or sense required) or never (no IRQ handler registered).
  213. * This function notifies the device driver if the channel program has not
  214. * completed during the time specified by @expires. If a timeout occurs, the
  215. * channel program is terminated via xsch, hsch or csch, and the device's
  216. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  217. * Returns:
  218. * %0, if the operation was successful;
  219. * -%EBUSY, if the device is busy, or status pending;
  220. * -%EACCES, if no path specified in @lpm is operational;
  221. * -%ENODEV, if the device is not operational.
  222. * Context:
  223. * Interrupts disabled, ccw device lock held
  224. */
  225. int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
  226. unsigned long intparm, __u8 lpm, __u8 key,
  227. unsigned long flags, int expires)
  228. {
  229. int ret;
  230. if (!cdev)
  231. return -ENODEV;
  232. ccw_device_set_timeout(cdev, expires);
  233. ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
  234. if (ret != 0)
  235. ccw_device_set_timeout(cdev, 0);
  236. return ret;
  237. }
  238. /**
  239. * ccw_device_start() - start a s390 channel program
  240. * @cdev: target ccw device
  241. * @cpa: logical start address of channel program
  242. * @intparm: user specific interruption parameter; will be presented back to
  243. * @cdev's interrupt handler. Allows a device driver to associate
  244. * the interrupt with a particular I/O request.
  245. * @lpm: defines the channel path to be used for a specific I/O request. A
  246. * value of 0 will make cio use the opm.
  247. * @flags: additional flags; defines the action to be performed for I/O
  248. * processing.
  249. *
  250. * Start a S/390 channel program. When the interrupt arrives, the
  251. * IRQ handler is called, either immediately, delayed (dev-end missing,
  252. * or sense required) or never (no IRQ handler registered).
  253. * Returns:
  254. * %0, if the operation was successful;
  255. * -%EBUSY, if the device is busy, or status pending;
  256. * -%EACCES, if no path specified in @lpm is operational;
  257. * -%ENODEV, if the device is not operational.
  258. * Context:
  259. * Interrupts disabled, ccw device lock held
  260. */
  261. int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
  262. unsigned long intparm, __u8 lpm, unsigned long flags)
  263. {
  264. return ccw_device_start_key(cdev, cpa, intparm, lpm,
  265. PAGE_DEFAULT_KEY, flags);
  266. }
  267. /**
  268. * ccw_device_start_timeout() - start a s390 channel program with timeout
  269. * @cdev: target ccw device
  270. * @cpa: logical start address of channel program
  271. * @intparm: user specific interruption parameter; will be presented back to
  272. * @cdev's interrupt handler. Allows a device driver to associate
  273. * the interrupt with a particular I/O request.
  274. * @lpm: defines the channel path to be used for a specific I/O request. A
  275. * value of 0 will make cio use the opm.
  276. * @flags: additional flags; defines the action to be performed for I/O
  277. * processing.
  278. * @expires: timeout value in jiffies
  279. *
  280. * Start a S/390 channel program. When the interrupt arrives, the
  281. * IRQ handler is called, either immediately, delayed (dev-end missing,
  282. * or sense required) or never (no IRQ handler registered).
  283. * This function notifies the device driver if the channel program has not
  284. * completed during the time specified by @expires. If a timeout occurs, the
  285. * channel program is terminated via xsch, hsch or csch, and the device's
  286. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  287. * Returns:
  288. * %0, if the operation was successful;
  289. * -%EBUSY, if the device is busy, or status pending;
  290. * -%EACCES, if no path specified in @lpm is operational;
  291. * -%ENODEV, if the device is not operational.
  292. * Context:
  293. * Interrupts disabled, ccw device lock held
  294. */
  295. int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
  296. unsigned long intparm, __u8 lpm,
  297. unsigned long flags, int expires)
  298. {
  299. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
  300. PAGE_DEFAULT_KEY, flags,
  301. expires);
  302. }
  303. /**
  304. * ccw_device_halt() - halt I/O request processing
  305. * @cdev: target ccw device
  306. * @intparm: interruption parameter; value is only used if no I/O is
  307. * outstanding, otherwise the intparm associated with the I/O request
  308. * is returned
  309. *
  310. * ccw_device_halt() calls hsch on @cdev's subchannel.
  311. * Returns:
  312. * %0 on success,
  313. * -%ENODEV on device not operational,
  314. * -%EINVAL on invalid device state,
  315. * -%EBUSY on device busy or interrupt pending.
  316. * Context:
  317. * Interrupts disabled, ccw device lock held
  318. */
  319. int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
  320. {
  321. struct subchannel *sch;
  322. int ret;
  323. if (!cdev || !cdev->dev.parent)
  324. return -ENODEV;
  325. sch = to_subchannel(cdev->dev.parent);
  326. if (!sch->schib.pmcw.ena)
  327. return -EINVAL;
  328. if (cdev->private->state == DEV_STATE_NOT_OPER)
  329. return -ENODEV;
  330. if (cdev->private->state != DEV_STATE_ONLINE &&
  331. cdev->private->state != DEV_STATE_W4SENSE)
  332. return -EINVAL;
  333. ret = cio_halt(sch);
  334. if (ret == 0)
  335. cdev->private->intparm = intparm;
  336. return ret;
  337. }
  338. /**
  339. * ccw_device_resume() - resume channel program execution
  340. * @cdev: target ccw device
  341. *
  342. * ccw_device_resume() calls rsch on @cdev's subchannel.
  343. * Returns:
  344. * %0 on success,
  345. * -%ENODEV on device not operational,
  346. * -%EINVAL on invalid device state,
  347. * -%EBUSY on device busy or interrupt pending.
  348. * Context:
  349. * Interrupts disabled, ccw device lock held
  350. */
  351. int ccw_device_resume(struct ccw_device *cdev)
  352. {
  353. struct subchannel *sch;
  354. if (!cdev || !cdev->dev.parent)
  355. return -ENODEV;
  356. sch = to_subchannel(cdev->dev.parent);
  357. if (!sch->schib.pmcw.ena)
  358. return -EINVAL;
  359. if (cdev->private->state == DEV_STATE_NOT_OPER)
  360. return -ENODEV;
  361. if (cdev->private->state != DEV_STATE_ONLINE ||
  362. !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
  363. return -EINVAL;
  364. return cio_resume(sch);
  365. }
  366. /*
  367. * Pass interrupt to device driver.
  368. */
  369. int
  370. ccw_device_call_handler(struct ccw_device *cdev)
  371. {
  372. struct subchannel *sch;
  373. unsigned int stctl;
  374. int ending_status;
  375. sch = to_subchannel(cdev->dev.parent);
  376. /*
  377. * we allow for the device action handler if .
  378. * - we received ending status
  379. * - the action handler requested to see all interrupts
  380. * - we received an intermediate status
  381. * - fast notification was requested (primary status)
  382. * - unsolicited interrupts
  383. */
  384. stctl = scsw_stctl(&cdev->private->irb.scsw);
  385. ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
  386. (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
  387. (stctl == SCSW_STCTL_STATUS_PEND);
  388. if (!ending_status &&
  389. !cdev->private->options.repall &&
  390. !(stctl & SCSW_STCTL_INTER_STATUS) &&
  391. !(cdev->private->options.fast &&
  392. (stctl & SCSW_STCTL_PRIM_STATUS)))
  393. return 0;
  394. /* Clear pending timers for device driver initiated I/O. */
  395. if (ending_status)
  396. ccw_device_set_timeout(cdev, 0);
  397. /*
  398. * Now we are ready to call the device driver interrupt handler.
  399. */
  400. if (cdev->handler)
  401. cdev->handler(cdev, cdev->private->intparm,
  402. &cdev->private->irb);
  403. /*
  404. * Clear the old and now useless interrupt response block.
  405. */
  406. memset(&cdev->private->irb, 0, sizeof(struct irb));
  407. return 1;
  408. }
  409. /**
  410. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  411. * @cdev: ccw device to inspect
  412. * @ct: command type to look for
  413. *
  414. * During SenseID, command information words (CIWs) describing special
  415. * commands available to the device may have been stored in the extended
  416. * sense data. This function searches for CIWs of a specified command
  417. * type in the extended sense data.
  418. * Returns:
  419. * %NULL if no extended sense data has been stored or if no CIW of the
  420. * specified command type could be found,
  421. * else a pointer to the CIW of the specified command type.
  422. */
  423. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  424. {
  425. int ciw_cnt;
  426. if (cdev->private->flags.esid == 0)
  427. return NULL;
  428. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  429. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  430. return cdev->private->senseid.ciw + ciw_cnt;
  431. return NULL;
  432. }
  433. /**
  434. * ccw_device_get_path_mask() - get currently available paths
  435. * @cdev: ccw device to be queried
  436. * Returns:
  437. * %0 if no subchannel for the device is available,
  438. * else the mask of currently available paths for the ccw device's subchannel.
  439. */
  440. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  441. {
  442. struct subchannel *sch;
  443. if (!cdev->dev.parent)
  444. return 0;
  445. sch = to_subchannel(cdev->dev.parent);
  446. return sch->lpm;
  447. }
  448. /*
  449. * Try to break the lock on a boxed device.
  450. */
  451. int
  452. ccw_device_stlck(struct ccw_device *cdev)
  453. {
  454. void *buf, *buf2;
  455. unsigned long flags;
  456. struct subchannel *sch;
  457. int ret;
  458. if (!cdev)
  459. return -ENODEV;
  460. if (cdev->drv && !cdev->private->options.force)
  461. return -EINVAL;
  462. sch = to_subchannel(cdev->dev.parent);
  463. CIO_TRACE_EVENT(2, "stl lock");
  464. CIO_TRACE_EVENT(2, dev_name(&cdev->dev));
  465. buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
  466. if (!buf)
  467. return -ENOMEM;
  468. buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
  469. if (!buf2) {
  470. kfree(buf);
  471. return -ENOMEM;
  472. }
  473. spin_lock_irqsave(sch->lock, flags);
  474. ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
  475. if (ret)
  476. goto out_unlock;
  477. /*
  478. * Setup ccw. We chain an unconditional reserve and a release so we
  479. * only break the lock.
  480. */
  481. cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
  482. cdev->private->iccws[0].cda = (__u32) __pa(buf);
  483. cdev->private->iccws[0].count = 32;
  484. cdev->private->iccws[0].flags = CCW_FLAG_CC;
  485. cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
  486. cdev->private->iccws[1].cda = (__u32) __pa(buf2);
  487. cdev->private->iccws[1].count = 32;
  488. cdev->private->iccws[1].flags = 0;
  489. ret = cio_start(sch, cdev->private->iccws, 0);
  490. if (ret) {
  491. cio_disable_subchannel(sch); //FIXME: return code?
  492. goto out_unlock;
  493. }
  494. cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
  495. spin_unlock_irqrestore(sch->lock, flags);
  496. wait_event(cdev->private->wait_q,
  497. cdev->private->irb.scsw.cmd.actl == 0);
  498. spin_lock_irqsave(sch->lock, flags);
  499. cio_disable_subchannel(sch); //FIXME: return code?
  500. if ((cdev->private->irb.scsw.cmd.dstat !=
  501. (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
  502. (cdev->private->irb.scsw.cmd.cstat != 0))
  503. ret = -EIO;
  504. /* Clear irb. */
  505. memset(&cdev->private->irb, 0, sizeof(struct irb));
  506. out_unlock:
  507. kfree(buf);
  508. kfree(buf2);
  509. spin_unlock_irqrestore(sch->lock, flags);
  510. return ret;
  511. }
  512. void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
  513. {
  514. struct subchannel *sch;
  515. struct chp_id chpid;
  516. sch = to_subchannel(cdev->dev.parent);
  517. chp_id_init(&chpid);
  518. chpid.id = sch->schib.pmcw.chpid[chp_no];
  519. return chp_get_chp_desc(chpid);
  520. }
  521. /**
  522. * ccw_device_get_id - obtain a ccw device id
  523. * @cdev: device to obtain the id for
  524. * @dev_id: where to fill in the values
  525. */
  526. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  527. {
  528. *dev_id = cdev->private->dev_id;
  529. }
  530. EXPORT_SYMBOL(ccw_device_get_id);
  531. /**
  532. * ccw_device_tm_start_key - perform start function
  533. * @cdev: ccw device on which to perform the start function
  534. * @tcw: transport-command word to be started
  535. * @intparm: user defined parameter to be passed to the interrupt handler
  536. * @lpm: mask of paths to use
  537. * @key: storage key to use for storage access
  538. *
  539. * Start the tcw on the given ccw device. Return zero on success, non-zero
  540. * otherwise.
  541. */
  542. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  543. unsigned long intparm, u8 lpm, u8 key)
  544. {
  545. struct subchannel *sch;
  546. int rc;
  547. sch = to_subchannel(cdev->dev.parent);
  548. if (!sch->schib.pmcw.ena)
  549. return -EINVAL;
  550. if (cdev->private->state != DEV_STATE_ONLINE)
  551. return -EIO;
  552. /* Adjust requested path mask to excluded varied off paths. */
  553. if (lpm) {
  554. lpm &= sch->opm;
  555. if (lpm == 0)
  556. return -EACCES;
  557. }
  558. rc = cio_tm_start_key(sch, tcw, lpm, key);
  559. if (rc == 0)
  560. cdev->private->intparm = intparm;
  561. return rc;
  562. }
  563. EXPORT_SYMBOL(ccw_device_tm_start_key);
  564. /**
  565. * ccw_device_tm_start_timeout_key - perform start function
  566. * @cdev: ccw device on which to perform the start function
  567. * @tcw: transport-command word to be started
  568. * @intparm: user defined parameter to be passed to the interrupt handler
  569. * @lpm: mask of paths to use
  570. * @key: storage key to use for storage access
  571. * @expires: time span in jiffies after which to abort request
  572. *
  573. * Start the tcw on the given ccw device. Return zero on success, non-zero
  574. * otherwise.
  575. */
  576. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  577. unsigned long intparm, u8 lpm, u8 key,
  578. int expires)
  579. {
  580. int ret;
  581. ccw_device_set_timeout(cdev, expires);
  582. ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
  583. if (ret != 0)
  584. ccw_device_set_timeout(cdev, 0);
  585. return ret;
  586. }
  587. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  588. /**
  589. * ccw_device_tm_start - perform start function
  590. * @cdev: ccw device on which to perform the start function
  591. * @tcw: transport-command word to be started
  592. * @intparm: user defined parameter to be passed to the interrupt handler
  593. * @lpm: mask of paths to use
  594. *
  595. * Start the tcw on the given ccw device. Return zero on success, non-zero
  596. * otherwise.
  597. */
  598. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  599. unsigned long intparm, u8 lpm)
  600. {
  601. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  602. PAGE_DEFAULT_KEY);
  603. }
  604. EXPORT_SYMBOL(ccw_device_tm_start);
  605. /**
  606. * ccw_device_tm_start_timeout - perform start function
  607. * @cdev: ccw device on which to perform the start function
  608. * @tcw: transport-command word to be started
  609. * @intparm: user defined parameter to be passed to the interrupt handler
  610. * @lpm: mask of paths to use
  611. * @expires: time span in jiffies after which to abort request
  612. *
  613. * Start the tcw on the given ccw device. Return zero on success, non-zero
  614. * otherwise.
  615. */
  616. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  617. unsigned long intparm, u8 lpm, int expires)
  618. {
  619. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  620. PAGE_DEFAULT_KEY, expires);
  621. }
  622. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  623. /**
  624. * ccw_device_tm_intrg - perform interrogate function
  625. * @cdev: ccw device on which to perform the interrogate function
  626. *
  627. * Perform an interrogate function on the given ccw device. Return zero on
  628. * success, non-zero otherwise.
  629. */
  630. int ccw_device_tm_intrg(struct ccw_device *cdev)
  631. {
  632. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  633. if (!sch->schib.pmcw.ena)
  634. return -EINVAL;
  635. if (cdev->private->state != DEV_STATE_ONLINE)
  636. return -EIO;
  637. if (!scsw_is_tm(&sch->schib.scsw) ||
  638. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  639. return -EINVAL;
  640. return cio_tm_intrg(sch);
  641. }
  642. EXPORT_SYMBOL(ccw_device_tm_intrg);
  643. // FIXME: these have to go:
  644. int
  645. _ccw_device_get_subchannel_number(struct ccw_device *cdev)
  646. {
  647. return cdev->private->schid.sch_no;
  648. }
  649. MODULE_LICENSE("GPL");
  650. EXPORT_SYMBOL(ccw_device_set_options_mask);
  651. EXPORT_SYMBOL(ccw_device_set_options);
  652. EXPORT_SYMBOL(ccw_device_clear_options);
  653. EXPORT_SYMBOL(ccw_device_clear);
  654. EXPORT_SYMBOL(ccw_device_halt);
  655. EXPORT_SYMBOL(ccw_device_resume);
  656. EXPORT_SYMBOL(ccw_device_start_timeout);
  657. EXPORT_SYMBOL(ccw_device_start);
  658. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  659. EXPORT_SYMBOL(ccw_device_start_key);
  660. EXPORT_SYMBOL(ccw_device_get_ciw);
  661. EXPORT_SYMBOL(ccw_device_get_path_mask);
  662. EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
  663. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);