device_ops.c 22 KB

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