device_ops.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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)
  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. if (!sch)
  119. return -ENODEV;
  120. ret = cio_clear(sch);
  121. if (ret == 0)
  122. cdev->private->intparm = intparm;
  123. return ret;
  124. }
  125. /**
  126. * ccw_device_start_key() - start a s390 channel program with key
  127. * @cdev: target ccw device
  128. * @cpa: logical start address of channel program
  129. * @intparm: user specific interruption parameter; will be presented back to
  130. * @cdev's interrupt handler. Allows a device driver to associate
  131. * the interrupt with a particular I/O request.
  132. * @lpm: defines the channel path to be used for a specific I/O request. A
  133. * value of 0 will make cio use the opm.
  134. * @key: storage key to be used for the I/O
  135. * @flags: additional flags; defines the action to be performed for I/O
  136. * processing.
  137. *
  138. * Start a S/390 channel program. When the interrupt arrives, the
  139. * IRQ handler is called, either immediately, delayed (dev-end missing,
  140. * or sense required) or never (no IRQ handler registered).
  141. * Returns:
  142. * %0, if the operation was successful;
  143. * -%EBUSY, if the device is busy, or status pending;
  144. * -%EACCES, if no path specified in @lpm is operational;
  145. * -%ENODEV, if the device is not operational.
  146. * Context:
  147. * Interrupts disabled, ccw device lock held
  148. */
  149. int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
  150. unsigned long intparm, __u8 lpm, __u8 key,
  151. unsigned long flags)
  152. {
  153. struct subchannel *sch;
  154. int ret;
  155. if (!cdev)
  156. return -ENODEV;
  157. sch = to_subchannel(cdev->dev.parent);
  158. if (!sch)
  159. return -ENODEV;
  160. if (cdev->private->state == DEV_STATE_NOT_OPER)
  161. return -ENODEV;
  162. if (cdev->private->state == DEV_STATE_VERIFY ||
  163. cdev->private->state == DEV_STATE_CLEAR_VERIFY) {
  164. /* Remember to fake irb when finished. */
  165. if (!cdev->private->flags.fake_irb) {
  166. cdev->private->flags.fake_irb = 1;
  167. cdev->private->intparm = intparm;
  168. return 0;
  169. } else
  170. /* There's already a fake I/O around. */
  171. return -EBUSY;
  172. }
  173. if (cdev->private->state != DEV_STATE_ONLINE ||
  174. ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
  175. !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
  176. cdev->private->flags.doverify)
  177. return -EBUSY;
  178. ret = cio_set_options (sch, flags);
  179. if (ret)
  180. return ret;
  181. /* Adjust requested path mask to excluded varied off paths. */
  182. if (lpm) {
  183. lpm &= sch->opm;
  184. if (lpm == 0)
  185. return -EACCES;
  186. }
  187. ret = cio_start_key (sch, cpa, lpm, key);
  188. switch (ret) {
  189. case 0:
  190. cdev->private->intparm = intparm;
  191. break;
  192. case -EACCES:
  193. case -ENODEV:
  194. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  195. break;
  196. }
  197. return ret;
  198. }
  199. /**
  200. * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
  201. * @cdev: target ccw device
  202. * @cpa: logical start address of channel program
  203. * @intparm: user specific interruption parameter; will be presented back to
  204. * @cdev's interrupt handler. Allows a device driver to associate
  205. * the interrupt with a particular I/O request.
  206. * @lpm: defines the channel path to be used for a specific I/O request. A
  207. * value of 0 will make cio use the opm.
  208. * @key: storage key to be used for the I/O
  209. * @flags: additional flags; defines the action to be performed for I/O
  210. * processing.
  211. * @expires: timeout value in jiffies
  212. *
  213. * Start a S/390 channel program. When the interrupt arrives, the
  214. * IRQ handler is called, either immediately, delayed (dev-end missing,
  215. * or sense required) or never (no IRQ handler registered).
  216. * This function notifies the device driver if the channel program has not
  217. * completed during the time specified by @expires. If a timeout occurs, the
  218. * channel program is terminated via xsch, hsch or csch, and the device's
  219. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  220. * Returns:
  221. * %0, if the operation was successful;
  222. * -%EBUSY, if the device is busy, or status pending;
  223. * -%EACCES, if no path specified in @lpm is operational;
  224. * -%ENODEV, if the device is not operational.
  225. * Context:
  226. * Interrupts disabled, ccw device lock held
  227. */
  228. int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
  229. unsigned long intparm, __u8 lpm, __u8 key,
  230. unsigned long flags, int expires)
  231. {
  232. int ret;
  233. if (!cdev)
  234. return -ENODEV;
  235. ccw_device_set_timeout(cdev, expires);
  236. ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
  237. if (ret != 0)
  238. ccw_device_set_timeout(cdev, 0);
  239. return ret;
  240. }
  241. /**
  242. * ccw_device_start() - start a s390 channel program
  243. * @cdev: target ccw device
  244. * @cpa: logical start address of channel program
  245. * @intparm: user specific interruption parameter; will be presented back to
  246. * @cdev's interrupt handler. Allows a device driver to associate
  247. * the interrupt with a particular I/O request.
  248. * @lpm: defines the channel path to be used for a specific I/O request. A
  249. * value of 0 will make cio use the opm.
  250. * @flags: additional flags; defines the action to be performed for I/O
  251. * processing.
  252. *
  253. * Start a S/390 channel program. When the interrupt arrives, the
  254. * IRQ handler is called, either immediately, delayed (dev-end missing,
  255. * or sense required) or never (no IRQ handler registered).
  256. * Returns:
  257. * %0, if the operation was successful;
  258. * -%EBUSY, if the device is busy, or status pending;
  259. * -%EACCES, if no path specified in @lpm is operational;
  260. * -%ENODEV, if the device is not operational.
  261. * Context:
  262. * Interrupts disabled, ccw device lock held
  263. */
  264. int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
  265. unsigned long intparm, __u8 lpm, unsigned long flags)
  266. {
  267. return ccw_device_start_key(cdev, cpa, intparm, lpm,
  268. PAGE_DEFAULT_KEY, flags);
  269. }
  270. /**
  271. * ccw_device_start_timeout() - start a s390 channel program with timeout
  272. * @cdev: target ccw device
  273. * @cpa: logical start address of channel program
  274. * @intparm: user specific interruption parameter; will be presented back to
  275. * @cdev's interrupt handler. Allows a device driver to associate
  276. * the interrupt with a particular I/O request.
  277. * @lpm: defines the channel path to be used for a specific I/O request. A
  278. * value of 0 will make cio use the opm.
  279. * @flags: additional flags; defines the action to be performed for I/O
  280. * processing.
  281. * @expires: timeout value in jiffies
  282. *
  283. * Start a S/390 channel program. When the interrupt arrives, the
  284. * IRQ handler is called, either immediately, delayed (dev-end missing,
  285. * or sense required) or never (no IRQ handler registered).
  286. * This function notifies the device driver if the channel program has not
  287. * completed during the time specified by @expires. If a timeout occurs, the
  288. * channel program is terminated via xsch, hsch or csch, and the device's
  289. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  290. * Returns:
  291. * %0, if the operation was successful;
  292. * -%EBUSY, if the device is busy, or status pending;
  293. * -%EACCES, if no path specified in @lpm is operational;
  294. * -%ENODEV, if the device is not operational.
  295. * Context:
  296. * Interrupts disabled, ccw device lock held
  297. */
  298. int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
  299. unsigned long intparm, __u8 lpm,
  300. unsigned long flags, int expires)
  301. {
  302. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
  303. PAGE_DEFAULT_KEY, flags,
  304. expires);
  305. }
  306. /**
  307. * ccw_device_halt() - halt I/O request processing
  308. * @cdev: target ccw device
  309. * @intparm: interruption parameter; value is only used if no I/O is
  310. * outstanding, otherwise the intparm associated with the I/O request
  311. * is returned
  312. *
  313. * ccw_device_halt() calls hsch on @cdev's subchannel.
  314. * Returns:
  315. * %0 on success,
  316. * -%ENODEV on device not operational,
  317. * -%EINVAL on invalid device state,
  318. * -%EBUSY on device busy or interrupt pending.
  319. * Context:
  320. * Interrupts disabled, ccw device lock held
  321. */
  322. int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
  323. {
  324. struct subchannel *sch;
  325. int ret;
  326. if (!cdev)
  327. return -ENODEV;
  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. sch = to_subchannel(cdev->dev.parent);
  334. if (!sch)
  335. return -ENODEV;
  336. ret = cio_halt(sch);
  337. if (ret == 0)
  338. cdev->private->intparm = intparm;
  339. return ret;
  340. }
  341. /**
  342. * ccw_device_resume() - resume channel program execution
  343. * @cdev: target ccw device
  344. *
  345. * ccw_device_resume() calls rsch on @cdev's subchannel.
  346. * Returns:
  347. * %0 on success,
  348. * -%ENODEV on device not operational,
  349. * -%EINVAL on invalid device state,
  350. * -%EBUSY on device busy or interrupt pending.
  351. * Context:
  352. * Interrupts disabled, ccw device lock held
  353. */
  354. int ccw_device_resume(struct ccw_device *cdev)
  355. {
  356. struct subchannel *sch;
  357. if (!cdev)
  358. return -ENODEV;
  359. sch = to_subchannel(cdev->dev.parent);
  360. if (!sch)
  361. return -ENODEV;
  362. if (cdev->private->state == DEV_STATE_NOT_OPER)
  363. return -ENODEV;
  364. if (cdev->private->state != DEV_STATE_ONLINE ||
  365. !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
  366. return -EINVAL;
  367. return cio_resume(sch);
  368. }
  369. /*
  370. * Pass interrupt to device driver.
  371. */
  372. int
  373. ccw_device_call_handler(struct ccw_device *cdev)
  374. {
  375. struct subchannel *sch;
  376. unsigned int stctl;
  377. int ending_status;
  378. sch = to_subchannel(cdev->dev.parent);
  379. /*
  380. * we allow for the device action handler if .
  381. * - we received ending status
  382. * - the action handler requested to see all interrupts
  383. * - we received an intermediate status
  384. * - fast notification was requested (primary status)
  385. * - unsolicited interrupts
  386. */
  387. stctl = scsw_stctl(&cdev->private->irb.scsw);
  388. ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
  389. (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
  390. (stctl == SCSW_STCTL_STATUS_PEND);
  391. if (!ending_status &&
  392. !cdev->private->options.repall &&
  393. !(stctl & SCSW_STCTL_INTER_STATUS) &&
  394. !(cdev->private->options.fast &&
  395. (stctl & SCSW_STCTL_PRIM_STATUS)))
  396. return 0;
  397. /* Clear pending timers for device driver initiated I/O. */
  398. if (ending_status)
  399. ccw_device_set_timeout(cdev, 0);
  400. /*
  401. * Now we are ready to call the device driver interrupt handler.
  402. */
  403. if (cdev->handler)
  404. cdev->handler(cdev, cdev->private->intparm,
  405. &cdev->private->irb);
  406. /*
  407. * Clear the old and now useless interrupt response block.
  408. */
  409. memset(&cdev->private->irb, 0, sizeof(struct irb));
  410. return 1;
  411. }
  412. /**
  413. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  414. * @cdev: ccw device to inspect
  415. * @ct: command type to look for
  416. *
  417. * During SenseID, command information words (CIWs) describing special
  418. * commands available to the device may have been stored in the extended
  419. * sense data. This function searches for CIWs of a specified command
  420. * type in the extended sense data.
  421. * Returns:
  422. * %NULL if no extended sense data has been stored or if no CIW of the
  423. * specified command type could be found,
  424. * else a pointer to the CIW of the specified command type.
  425. */
  426. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  427. {
  428. int ciw_cnt;
  429. if (cdev->private->flags.esid == 0)
  430. return NULL;
  431. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  432. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  433. return cdev->private->senseid.ciw + ciw_cnt;
  434. return NULL;
  435. }
  436. /**
  437. * ccw_device_get_path_mask() - get currently available paths
  438. * @cdev: ccw device to be queried
  439. * Returns:
  440. * %0 if no subchannel for the device is available,
  441. * else the mask of currently available paths for the ccw device's subchannel.
  442. */
  443. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  444. {
  445. struct subchannel *sch;
  446. sch = to_subchannel(cdev->dev.parent);
  447. if (!sch)
  448. return 0;
  449. else
  450. return sch->lpm;
  451. }
  452. /*
  453. * Try to break the lock on a boxed device.
  454. */
  455. int
  456. ccw_device_stlck(struct ccw_device *cdev)
  457. {
  458. void *buf, *buf2;
  459. unsigned long flags;
  460. struct subchannel *sch;
  461. int ret;
  462. if (!cdev)
  463. return -ENODEV;
  464. if (cdev->drv && !cdev->private->options.force)
  465. return -EINVAL;
  466. sch = to_subchannel(cdev->dev.parent);
  467. CIO_TRACE_EVENT(2, "stl lock");
  468. CIO_TRACE_EVENT(2, dev_name(&cdev->dev));
  469. buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
  470. if (!buf)
  471. return -ENOMEM;
  472. buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);
  473. if (!buf2) {
  474. kfree(buf);
  475. return -ENOMEM;
  476. }
  477. spin_lock_irqsave(sch->lock, flags);
  478. ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
  479. if (ret)
  480. goto out_unlock;
  481. /*
  482. * Setup ccw. We chain an unconditional reserve and a release so we
  483. * only break the lock.
  484. */
  485. cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;
  486. cdev->private->iccws[0].cda = (__u32) __pa(buf);
  487. cdev->private->iccws[0].count = 32;
  488. cdev->private->iccws[0].flags = CCW_FLAG_CC;
  489. cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;
  490. cdev->private->iccws[1].cda = (__u32) __pa(buf2);
  491. cdev->private->iccws[1].count = 32;
  492. cdev->private->iccws[1].flags = 0;
  493. ret = cio_start(sch, cdev->private->iccws, 0);
  494. if (ret) {
  495. cio_disable_subchannel(sch); //FIXME: return code?
  496. goto out_unlock;
  497. }
  498. cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
  499. spin_unlock_irqrestore(sch->lock, flags);
  500. wait_event(cdev->private->wait_q,
  501. cdev->private->irb.scsw.cmd.actl == 0);
  502. spin_lock_irqsave(sch->lock, flags);
  503. cio_disable_subchannel(sch); //FIXME: return code?
  504. if ((cdev->private->irb.scsw.cmd.dstat !=
  505. (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
  506. (cdev->private->irb.scsw.cmd.cstat != 0))
  507. ret = -EIO;
  508. /* Clear irb. */
  509. memset(&cdev->private->irb, 0, sizeof(struct irb));
  510. out_unlock:
  511. kfree(buf);
  512. kfree(buf2);
  513. spin_unlock_irqrestore(sch->lock, flags);
  514. return ret;
  515. }
  516. void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
  517. {
  518. struct subchannel *sch;
  519. struct chp_id chpid;
  520. sch = to_subchannel(cdev->dev.parent);
  521. chp_id_init(&chpid);
  522. chpid.id = sch->schib.pmcw.chpid[chp_no];
  523. return chp_get_chp_desc(chpid);
  524. }
  525. /**
  526. * ccw_device_get_id - obtain a ccw device id
  527. * @cdev: device to obtain the id for
  528. * @dev_id: where to fill in the values
  529. */
  530. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  531. {
  532. *dev_id = cdev->private->dev_id;
  533. }
  534. EXPORT_SYMBOL(ccw_device_get_id);
  535. /**
  536. * ccw_device_tm_start_key - perform start function
  537. * @cdev: ccw device on which to perform the start function
  538. * @tcw: transport-command word to be started
  539. * @intparm: user defined parameter to be passed to the interrupt handler
  540. * @lpm: mask of paths to use
  541. * @key: storage key to use for storage access
  542. *
  543. * Start the tcw on the given ccw device. Return zero on success, non-zero
  544. * otherwise.
  545. */
  546. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  547. unsigned long intparm, u8 lpm, u8 key)
  548. {
  549. struct subchannel *sch;
  550. int rc;
  551. sch = to_subchannel(cdev->dev.parent);
  552. if (cdev->private->state != DEV_STATE_ONLINE)
  553. return -EIO;
  554. /* Adjust requested path mask to excluded varied off paths. */
  555. if (lpm) {
  556. lpm &= sch->opm;
  557. if (lpm == 0)
  558. return -EACCES;
  559. }
  560. rc = cio_tm_start_key(sch, tcw, lpm, key);
  561. if (rc == 0)
  562. cdev->private->intparm = intparm;
  563. return rc;
  564. }
  565. EXPORT_SYMBOL(ccw_device_tm_start_key);
  566. /**
  567. * ccw_device_tm_start_timeout_key - perform start function
  568. * @cdev: ccw device on which to perform the start function
  569. * @tcw: transport-command word to be started
  570. * @intparm: user defined parameter to be passed to the interrupt handler
  571. * @lpm: mask of paths to use
  572. * @key: storage key to use for storage access
  573. * @expires: time span in jiffies after which to abort request
  574. *
  575. * Start the tcw on the given ccw device. Return zero on success, non-zero
  576. * otherwise.
  577. */
  578. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  579. unsigned long intparm, u8 lpm, u8 key,
  580. int expires)
  581. {
  582. int ret;
  583. ccw_device_set_timeout(cdev, expires);
  584. ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
  585. if (ret != 0)
  586. ccw_device_set_timeout(cdev, 0);
  587. return ret;
  588. }
  589. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  590. /**
  591. * ccw_device_tm_start - perform start function
  592. * @cdev: ccw device on which to perform the start function
  593. * @tcw: transport-command word to be started
  594. * @intparm: user defined parameter to be passed to the interrupt handler
  595. * @lpm: mask of paths to use
  596. *
  597. * Start the tcw on the given ccw device. Return zero on success, non-zero
  598. * otherwise.
  599. */
  600. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  601. unsigned long intparm, u8 lpm)
  602. {
  603. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  604. PAGE_DEFAULT_KEY);
  605. }
  606. EXPORT_SYMBOL(ccw_device_tm_start);
  607. /**
  608. * ccw_device_tm_start_timeout - perform start function
  609. * @cdev: ccw device on which to perform the start function
  610. * @tcw: transport-command word to be started
  611. * @intparm: user defined parameter to be passed to the interrupt handler
  612. * @lpm: mask of paths to use
  613. * @expires: time span in jiffies after which to abort request
  614. *
  615. * Start the tcw on the given ccw device. Return zero on success, non-zero
  616. * otherwise.
  617. */
  618. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  619. unsigned long intparm, u8 lpm, int expires)
  620. {
  621. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  622. PAGE_DEFAULT_KEY, expires);
  623. }
  624. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  625. /**
  626. * ccw_device_tm_intrg - perform interrogate function
  627. * @cdev: ccw device on which to perform the interrogate function
  628. *
  629. * Perform an interrogate function on the given ccw device. Return zero on
  630. * success, non-zero otherwise.
  631. */
  632. int ccw_device_tm_intrg(struct ccw_device *cdev)
  633. {
  634. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  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);