device_ops.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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 = FAKE_CMD_IRB;
  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 exclude unusable paths. */
  205. if (lpm) {
  206. lpm &= sch->lpm;
  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. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  394. * @cdev: ccw device to inspect
  395. * @ct: command type to look for
  396. *
  397. * During SenseID, command information words (CIWs) describing special
  398. * commands available to the device may have been stored in the extended
  399. * sense data. This function searches for CIWs of a specified command
  400. * type in the extended sense data.
  401. * Returns:
  402. * %NULL if no extended sense data has been stored or if no CIW of the
  403. * specified command type could be found,
  404. * else a pointer to the CIW of the specified command type.
  405. */
  406. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  407. {
  408. int ciw_cnt;
  409. if (cdev->private->flags.esid == 0)
  410. return NULL;
  411. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  412. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  413. return cdev->private->senseid.ciw + ciw_cnt;
  414. return NULL;
  415. }
  416. /**
  417. * ccw_device_get_path_mask() - get currently available paths
  418. * @cdev: ccw device to be queried
  419. * Returns:
  420. * %0 if no subchannel for the device is available,
  421. * else the mask of currently available paths for the ccw device's subchannel.
  422. */
  423. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  424. {
  425. struct subchannel *sch;
  426. if (!cdev->dev.parent)
  427. return 0;
  428. sch = to_subchannel(cdev->dev.parent);
  429. return sch->lpm;
  430. }
  431. /**
  432. * chp_get_chp_desc - return newly allocated channel-path descriptor
  433. * @cdev: device to obtain the descriptor for
  434. * @chp_idx: index of the channel path
  435. *
  436. * On success return a newly allocated copy of the channel-path description
  437. * data associated with the given channel path. Return %NULL on error.
  438. */
  439. struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *cdev,
  440. int chp_idx)
  441. {
  442. struct subchannel *sch;
  443. struct chp_id chpid;
  444. sch = to_subchannel(cdev->dev.parent);
  445. chp_id_init(&chpid);
  446. chpid.id = sch->schib.pmcw.chpid[chp_idx];
  447. return chp_get_chp_desc(chpid);
  448. }
  449. /**
  450. * ccw_device_get_id - obtain a ccw device id
  451. * @cdev: device to obtain the id for
  452. * @dev_id: where to fill in the values
  453. */
  454. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  455. {
  456. *dev_id = cdev->private->dev_id;
  457. }
  458. EXPORT_SYMBOL(ccw_device_get_id);
  459. /**
  460. * ccw_device_tm_start_key - perform start function
  461. * @cdev: ccw device on which to perform the start function
  462. * @tcw: transport-command word to be started
  463. * @intparm: user defined parameter to be passed to the interrupt handler
  464. * @lpm: mask of paths to use
  465. * @key: storage key to use for storage access
  466. *
  467. * Start the tcw on the given ccw device. Return zero on success, non-zero
  468. * otherwise.
  469. */
  470. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  471. unsigned long intparm, u8 lpm, u8 key)
  472. {
  473. struct subchannel *sch;
  474. int rc;
  475. sch = to_subchannel(cdev->dev.parent);
  476. if (!sch->schib.pmcw.ena)
  477. return -EINVAL;
  478. if (cdev->private->state == DEV_STATE_VERIFY) {
  479. /* Remember to fake irb when finished. */
  480. if (!cdev->private->flags.fake_irb) {
  481. cdev->private->flags.fake_irb = FAKE_TM_IRB;
  482. cdev->private->intparm = intparm;
  483. return 0;
  484. } else
  485. /* There's already a fake I/O around. */
  486. return -EBUSY;
  487. }
  488. if (cdev->private->state != DEV_STATE_ONLINE)
  489. return -EIO;
  490. /* Adjust requested path mask to exclude unusable paths. */
  491. if (lpm) {
  492. lpm &= sch->lpm;
  493. if (lpm == 0)
  494. return -EACCES;
  495. }
  496. rc = cio_tm_start_key(sch, tcw, lpm, key);
  497. if (rc == 0)
  498. cdev->private->intparm = intparm;
  499. return rc;
  500. }
  501. EXPORT_SYMBOL(ccw_device_tm_start_key);
  502. /**
  503. * ccw_device_tm_start_timeout_key - perform start function
  504. * @cdev: ccw device on which to perform the start function
  505. * @tcw: transport-command word to be started
  506. * @intparm: user defined parameter to be passed to the interrupt handler
  507. * @lpm: mask of paths to use
  508. * @key: storage key to use for storage access
  509. * @expires: time span in jiffies after which to abort request
  510. *
  511. * Start the tcw on the given ccw device. Return zero on success, non-zero
  512. * otherwise.
  513. */
  514. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  515. unsigned long intparm, u8 lpm, u8 key,
  516. int expires)
  517. {
  518. int ret;
  519. ccw_device_set_timeout(cdev, expires);
  520. ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
  521. if (ret != 0)
  522. ccw_device_set_timeout(cdev, 0);
  523. return ret;
  524. }
  525. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  526. /**
  527. * ccw_device_tm_start - 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. *
  533. * Start the tcw on the given ccw device. Return zero on success, non-zero
  534. * otherwise.
  535. */
  536. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  537. unsigned long intparm, u8 lpm)
  538. {
  539. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  540. PAGE_DEFAULT_KEY);
  541. }
  542. EXPORT_SYMBOL(ccw_device_tm_start);
  543. /**
  544. * ccw_device_tm_start_timeout - perform start function
  545. * @cdev: ccw device on which to perform the start function
  546. * @tcw: transport-command word to be started
  547. * @intparm: user defined parameter to be passed to the interrupt handler
  548. * @lpm: mask of paths to use
  549. * @expires: time span in jiffies after which to abort request
  550. *
  551. * Start the tcw on the given ccw device. Return zero on success, non-zero
  552. * otherwise.
  553. */
  554. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  555. unsigned long intparm, u8 lpm, int expires)
  556. {
  557. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  558. PAGE_DEFAULT_KEY, expires);
  559. }
  560. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  561. /**
  562. * ccw_device_get_mdc - accumulate max data count
  563. * @cdev: ccw device for which the max data count is accumulated
  564. * @mask: mask of paths to use
  565. *
  566. * Return the number of 64K-bytes blocks all paths at least support
  567. * for a transport command. Return values <= 0 indicate failures.
  568. */
  569. int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
  570. {
  571. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  572. struct channel_path *chp;
  573. struct chp_id chpid;
  574. int mdc = 0, i;
  575. /* Adjust requested path mask to excluded varied off paths. */
  576. if (mask)
  577. mask &= sch->lpm;
  578. else
  579. mask = sch->lpm;
  580. chp_id_init(&chpid);
  581. for (i = 0; i < 8; i++) {
  582. if (!(mask & (0x80 >> i)))
  583. continue;
  584. chpid.id = sch->schib.pmcw.chpid[i];
  585. chp = chpid_to_chp(chpid);
  586. if (!chp)
  587. continue;
  588. mutex_lock(&chp->lock);
  589. if (!chp->desc_fmt1.f) {
  590. mutex_unlock(&chp->lock);
  591. return 0;
  592. }
  593. if (!chp->desc_fmt1.r)
  594. mdc = 1;
  595. mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
  596. chp->desc_fmt1.mdc;
  597. mutex_unlock(&chp->lock);
  598. }
  599. return mdc;
  600. }
  601. EXPORT_SYMBOL(ccw_device_get_mdc);
  602. /**
  603. * ccw_device_tm_intrg - perform interrogate function
  604. * @cdev: ccw device on which to perform the interrogate function
  605. *
  606. * Perform an interrogate function on the given ccw device. Return zero on
  607. * success, non-zero otherwise.
  608. */
  609. int ccw_device_tm_intrg(struct ccw_device *cdev)
  610. {
  611. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  612. if (!sch->schib.pmcw.ena)
  613. return -EINVAL;
  614. if (cdev->private->state != DEV_STATE_ONLINE)
  615. return -EIO;
  616. if (!scsw_is_tm(&sch->schib.scsw) ||
  617. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  618. return -EINVAL;
  619. return cio_tm_intrg(sch);
  620. }
  621. EXPORT_SYMBOL(ccw_device_tm_intrg);
  622. /**
  623. * ccw_device_get_schid - obtain a subchannel id
  624. * @cdev: device to obtain the id for
  625. * @schid: where to fill in the values
  626. */
  627. void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
  628. {
  629. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  630. *schid = sch->schid;
  631. }
  632. EXPORT_SYMBOL_GPL(ccw_device_get_schid);
  633. MODULE_LICENSE("GPL");
  634. EXPORT_SYMBOL(ccw_device_set_options_mask);
  635. EXPORT_SYMBOL(ccw_device_set_options);
  636. EXPORT_SYMBOL(ccw_device_clear_options);
  637. EXPORT_SYMBOL(ccw_device_clear);
  638. EXPORT_SYMBOL(ccw_device_halt);
  639. EXPORT_SYMBOL(ccw_device_resume);
  640. EXPORT_SYMBOL(ccw_device_start_timeout);
  641. EXPORT_SYMBOL(ccw_device_start);
  642. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  643. EXPORT_SYMBOL(ccw_device_start_key);
  644. EXPORT_SYMBOL(ccw_device_get_ciw);
  645. EXPORT_SYMBOL(ccw_device_get_path_mask);
  646. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);