device_ops.c 22 KB

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