device_ops.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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_timeout_key() - start a s390 channel program with timeout and 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. * @expires: timeout value in jiffies
  162. *
  163. * Start a S/390 channel program. When the interrupt arrives, the
  164. * IRQ handler is called, either immediately, delayed (dev-end missing,
  165. * or sense required) or never (no IRQ handler registered).
  166. * This function notifies the device driver if the channel program has not
  167. * completed during the time specified by @expires. If a timeout occurs, the
  168. * channel program is terminated via xsch, hsch or csch, and the device's
  169. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  170. * Returns:
  171. * %0, if the operation was successful;
  172. * -%EBUSY, if the device is busy, or status pending;
  173. * -%EACCES, if no path specified in @lpm is operational;
  174. * -%ENODEV, if the device is not operational.
  175. * Context:
  176. * Interrupts disabled, ccw device lock held
  177. */
  178. int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
  179. unsigned long intparm, __u8 lpm, __u8 key,
  180. unsigned long flags, int expires)
  181. {
  182. struct subchannel *sch;
  183. int ret;
  184. if (!cdev || !cdev->dev.parent)
  185. return -ENODEV;
  186. sch = to_subchannel(cdev->dev.parent);
  187. if (!sch->schib.pmcw.ena)
  188. return -EINVAL;
  189. if (cdev->private->state == DEV_STATE_NOT_OPER)
  190. return -ENODEV;
  191. if (cdev->private->state == DEV_STATE_VERIFY) {
  192. /* Remember to fake irb when finished. */
  193. if (!cdev->private->flags.fake_irb) {
  194. cdev->private->flags.fake_irb = FAKE_CMD_IRB;
  195. cdev->private->intparm = intparm;
  196. return 0;
  197. } else
  198. /* There's already a fake I/O around. */
  199. return -EBUSY;
  200. }
  201. if (cdev->private->state != DEV_STATE_ONLINE ||
  202. ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
  203. !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
  204. cdev->private->flags.doverify)
  205. return -EBUSY;
  206. ret = cio_set_options (sch, flags);
  207. if (ret)
  208. return ret;
  209. /* Adjust requested path mask to exclude unusable paths. */
  210. if (lpm) {
  211. lpm &= sch->lpm;
  212. if (lpm == 0)
  213. return -EACCES;
  214. }
  215. ret = cio_start_key (sch, cpa, lpm, key);
  216. switch (ret) {
  217. case 0:
  218. cdev->private->intparm = intparm;
  219. if (expires)
  220. ccw_device_set_timeout(cdev, expires);
  221. break;
  222. case -EACCES:
  223. case -ENODEV:
  224. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  225. break;
  226. }
  227. return ret;
  228. }
  229. /**
  230. * ccw_device_start_key() - start a s390 channel program with key
  231. * @cdev: target ccw device
  232. * @cpa: logical start address of channel program
  233. * @intparm: user specific interruption parameter; will be presented back to
  234. * @cdev's interrupt handler. Allows a device driver to associate
  235. * the interrupt with a particular I/O request.
  236. * @lpm: defines the channel path to be used for a specific I/O request. A
  237. * value of 0 will make cio use the opm.
  238. * @key: storage key to be used for the I/O
  239. * @flags: additional flags; defines the action to be performed for I/O
  240. * processing.
  241. *
  242. * Start a S/390 channel program. When the interrupt arrives, the
  243. * IRQ handler is called, either immediately, delayed (dev-end missing,
  244. * or sense required) or never (no IRQ handler registered).
  245. * Returns:
  246. * %0, if the operation was successful;
  247. * -%EBUSY, if the device is busy, or status pending;
  248. * -%EACCES, if no path specified in @lpm is operational;
  249. * -%ENODEV, if the device is not operational.
  250. * Context:
  251. * Interrupts disabled, ccw device lock held
  252. */
  253. int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
  254. unsigned long intparm, __u8 lpm, __u8 key,
  255. unsigned long flags)
  256. {
  257. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, key,
  258. flags, 0);
  259. }
  260. /**
  261. * ccw_device_start() - start a s390 channel program
  262. * @cdev: target ccw device
  263. * @cpa: logical start address of channel program
  264. * @intparm: user specific interruption parameter; will be presented back to
  265. * @cdev's interrupt handler. Allows a device driver to associate
  266. * the interrupt with a particular I/O request.
  267. * @lpm: defines the channel path to be used for a specific I/O request. A
  268. * value of 0 will make cio use the opm.
  269. * @flags: additional flags; defines the action to be performed for I/O
  270. * processing.
  271. *
  272. * Start a S/390 channel program. When the interrupt arrives, the
  273. * IRQ handler is called, either immediately, delayed (dev-end missing,
  274. * or sense required) or never (no IRQ handler registered).
  275. * Returns:
  276. * %0, if the operation was successful;
  277. * -%EBUSY, if the device is busy, or status pending;
  278. * -%EACCES, if no path specified in @lpm is operational;
  279. * -%ENODEV, if the device is not operational.
  280. * Context:
  281. * Interrupts disabled, ccw device lock held
  282. */
  283. int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
  284. unsigned long intparm, __u8 lpm, unsigned long flags)
  285. {
  286. return ccw_device_start_key(cdev, cpa, intparm, lpm,
  287. PAGE_DEFAULT_KEY, flags);
  288. }
  289. /**
  290. * ccw_device_start_timeout() - start a s390 channel program with timeout
  291. * @cdev: target ccw device
  292. * @cpa: logical start address of channel program
  293. * @intparm: user specific interruption parameter; will be presented back to
  294. * @cdev's interrupt handler. Allows a device driver to associate
  295. * the interrupt with a particular I/O request.
  296. * @lpm: defines the channel path to be used for a specific I/O request. A
  297. * value of 0 will make cio use the opm.
  298. * @flags: additional flags; defines the action to be performed for I/O
  299. * processing.
  300. * @expires: timeout value in jiffies
  301. *
  302. * Start a S/390 channel program. When the interrupt arrives, the
  303. * IRQ handler is called, either immediately, delayed (dev-end missing,
  304. * or sense required) or never (no IRQ handler registered).
  305. * This function notifies the device driver if the channel program has not
  306. * completed during the time specified by @expires. If a timeout occurs, the
  307. * channel program is terminated via xsch, hsch or csch, and the device's
  308. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  309. * Returns:
  310. * %0, if the operation was successful;
  311. * -%EBUSY, if the device is busy, or status pending;
  312. * -%EACCES, if no path specified in @lpm is operational;
  313. * -%ENODEV, if the device is not operational.
  314. * Context:
  315. * Interrupts disabled, ccw device lock held
  316. */
  317. int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
  318. unsigned long intparm, __u8 lpm,
  319. unsigned long flags, int expires)
  320. {
  321. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
  322. PAGE_DEFAULT_KEY, flags,
  323. expires);
  324. }
  325. /**
  326. * ccw_device_halt() - halt I/O request processing
  327. * @cdev: target ccw device
  328. * @intparm: interruption parameter; value is only used if no I/O is
  329. * outstanding, otherwise the intparm associated with the I/O request
  330. * is returned
  331. *
  332. * ccw_device_halt() calls hsch on @cdev's subchannel.
  333. * Returns:
  334. * %0 on success,
  335. * -%ENODEV on device not operational,
  336. * -%EINVAL on invalid device state,
  337. * -%EBUSY on device busy or interrupt pending.
  338. * Context:
  339. * Interrupts disabled, ccw device lock held
  340. */
  341. int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
  342. {
  343. struct subchannel *sch;
  344. int ret;
  345. if (!cdev || !cdev->dev.parent)
  346. return -ENODEV;
  347. sch = to_subchannel(cdev->dev.parent);
  348. if (!sch->schib.pmcw.ena)
  349. return -EINVAL;
  350. if (cdev->private->state == DEV_STATE_NOT_OPER)
  351. return -ENODEV;
  352. if (cdev->private->state != DEV_STATE_ONLINE &&
  353. cdev->private->state != DEV_STATE_W4SENSE)
  354. return -EINVAL;
  355. ret = cio_halt(sch);
  356. if (ret == 0)
  357. cdev->private->intparm = intparm;
  358. return ret;
  359. }
  360. /**
  361. * ccw_device_resume() - resume channel program execution
  362. * @cdev: target ccw device
  363. *
  364. * ccw_device_resume() calls rsch on @cdev's subchannel.
  365. * Returns:
  366. * %0 on success,
  367. * -%ENODEV on device not operational,
  368. * -%EINVAL on invalid device state,
  369. * -%EBUSY on device busy or interrupt pending.
  370. * Context:
  371. * Interrupts disabled, ccw device lock held
  372. */
  373. int ccw_device_resume(struct ccw_device *cdev)
  374. {
  375. struct subchannel *sch;
  376. if (!cdev || !cdev->dev.parent)
  377. return -ENODEV;
  378. sch = to_subchannel(cdev->dev.parent);
  379. if (!sch->schib.pmcw.ena)
  380. return -EINVAL;
  381. if (cdev->private->state == DEV_STATE_NOT_OPER)
  382. return -ENODEV;
  383. if (cdev->private->state != DEV_STATE_ONLINE ||
  384. !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
  385. return -EINVAL;
  386. return cio_resume(sch);
  387. }
  388. /**
  389. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  390. * @cdev: ccw device to inspect
  391. * @ct: command type to look for
  392. *
  393. * During SenseID, command information words (CIWs) describing special
  394. * commands available to the device may have been stored in the extended
  395. * sense data. This function searches for CIWs of a specified command
  396. * type in the extended sense data.
  397. * Returns:
  398. * %NULL if no extended sense data has been stored or if no CIW of the
  399. * specified command type could be found,
  400. * else a pointer to the CIW of the specified command type.
  401. */
  402. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  403. {
  404. int ciw_cnt;
  405. if (cdev->private->flags.esid == 0)
  406. return NULL;
  407. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  408. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  409. return cdev->private->senseid.ciw + ciw_cnt;
  410. return NULL;
  411. }
  412. /**
  413. * ccw_device_get_path_mask() - get currently available paths
  414. * @cdev: ccw device to be queried
  415. * Returns:
  416. * %0 if no subchannel for the device is available,
  417. * else the mask of currently available paths for the ccw device's subchannel.
  418. */
  419. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  420. {
  421. struct subchannel *sch;
  422. if (!cdev->dev.parent)
  423. return 0;
  424. sch = to_subchannel(cdev->dev.parent);
  425. return sch->lpm;
  426. }
  427. /**
  428. * ccw_device_get_chp_desc() - return newly allocated channel-path descriptor
  429. * @cdev: device to obtain the descriptor for
  430. * @chp_idx: index of the channel path
  431. *
  432. * On success return a newly allocated copy of the channel-path description
  433. * data associated with the given channel path. Return %NULL on error.
  434. */
  435. struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *cdev,
  436. int chp_idx)
  437. {
  438. struct subchannel *sch;
  439. struct chp_id chpid;
  440. sch = to_subchannel(cdev->dev.parent);
  441. chp_id_init(&chpid);
  442. chpid.id = sch->schib.pmcw.chpid[chp_idx];
  443. return chp_get_chp_desc(chpid);
  444. }
  445. /**
  446. * ccw_device_get_id() - obtain a ccw device id
  447. * @cdev: device to obtain the id for
  448. * @dev_id: where to fill in the values
  449. */
  450. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  451. {
  452. *dev_id = cdev->private->dev_id;
  453. }
  454. EXPORT_SYMBOL(ccw_device_get_id);
  455. /**
  456. * ccw_device_tm_start_timeout_key() - perform start function
  457. * @cdev: ccw device on which to perform the start function
  458. * @tcw: transport-command word to be started
  459. * @intparm: user defined parameter to be passed to the interrupt handler
  460. * @lpm: mask of paths to use
  461. * @key: storage key to use for storage access
  462. * @expires: time span in jiffies after which to abort request
  463. *
  464. * Start the tcw on the given ccw device. Return zero on success, non-zero
  465. * otherwise.
  466. */
  467. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  468. unsigned long intparm, u8 lpm, u8 key,
  469. int expires)
  470. {
  471. struct subchannel *sch;
  472. int rc;
  473. sch = to_subchannel(cdev->dev.parent);
  474. if (!sch->schib.pmcw.ena)
  475. return -EINVAL;
  476. if (cdev->private->state == DEV_STATE_VERIFY) {
  477. /* Remember to fake irb when finished. */
  478. if (!cdev->private->flags.fake_irb) {
  479. cdev->private->flags.fake_irb = FAKE_TM_IRB;
  480. cdev->private->intparm = intparm;
  481. return 0;
  482. } else
  483. /* There's already a fake I/O around. */
  484. return -EBUSY;
  485. }
  486. if (cdev->private->state != DEV_STATE_ONLINE)
  487. return -EIO;
  488. /* Adjust requested path mask to exclude unusable paths. */
  489. if (lpm) {
  490. lpm &= sch->lpm;
  491. if (lpm == 0)
  492. return -EACCES;
  493. }
  494. rc = cio_tm_start_key(sch, tcw, lpm, key);
  495. if (rc == 0) {
  496. cdev->private->intparm = intparm;
  497. if (expires)
  498. ccw_device_set_timeout(cdev, expires);
  499. }
  500. return rc;
  501. }
  502. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  503. /**
  504. * ccw_device_tm_start_key() - perform start function
  505. * @cdev: ccw device on which to perform the start function
  506. * @tcw: transport-command word to be started
  507. * @intparm: user defined parameter to be passed to the interrupt handler
  508. * @lpm: mask of paths to use
  509. * @key: storage key to use for storage access
  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_key(struct ccw_device *cdev, struct tcw *tcw,
  515. unsigned long intparm, u8 lpm, u8 key)
  516. {
  517. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, key, 0);
  518. }
  519. EXPORT_SYMBOL(ccw_device_tm_start_key);
  520. /**
  521. * ccw_device_tm_start() - perform start function
  522. * @cdev: ccw device on which to perform the start function
  523. * @tcw: transport-command word to be started
  524. * @intparm: user defined parameter to be passed to the interrupt handler
  525. * @lpm: mask of paths to use
  526. *
  527. * Start the tcw on the given ccw device. Return zero on success, non-zero
  528. * otherwise.
  529. */
  530. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  531. unsigned long intparm, u8 lpm)
  532. {
  533. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  534. PAGE_DEFAULT_KEY);
  535. }
  536. EXPORT_SYMBOL(ccw_device_tm_start);
  537. /**
  538. * ccw_device_tm_start_timeout() - perform start function
  539. * @cdev: ccw device on which to perform the start function
  540. * @tcw: transport-command word to be started
  541. * @intparm: user defined parameter to be passed to the interrupt handler
  542. * @lpm: mask of paths to use
  543. * @expires: time span in jiffies after which to abort request
  544. *
  545. * Start the tcw on the given ccw device. Return zero on success, non-zero
  546. * otherwise.
  547. */
  548. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  549. unsigned long intparm, u8 lpm, int expires)
  550. {
  551. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  552. PAGE_DEFAULT_KEY, expires);
  553. }
  554. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  555. /**
  556. * ccw_device_get_mdc() - accumulate max data count
  557. * @cdev: ccw device for which the max data count is accumulated
  558. * @mask: mask of paths to use
  559. *
  560. * Return the number of 64K-bytes blocks all paths at least support
  561. * for a transport command. Return values <= 0 indicate failures.
  562. */
  563. int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
  564. {
  565. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  566. struct channel_path *chp;
  567. struct chp_id chpid;
  568. int mdc = 0, i;
  569. /* Adjust requested path mask to excluded varied off paths. */
  570. if (mask)
  571. mask &= sch->lpm;
  572. else
  573. mask = sch->lpm;
  574. chp_id_init(&chpid);
  575. for (i = 0; i < 8; i++) {
  576. if (!(mask & (0x80 >> i)))
  577. continue;
  578. chpid.id = sch->schib.pmcw.chpid[i];
  579. chp = chpid_to_chp(chpid);
  580. if (!chp)
  581. continue;
  582. mutex_lock(&chp->lock);
  583. if (!chp->desc_fmt1.f) {
  584. mutex_unlock(&chp->lock);
  585. return 0;
  586. }
  587. if (!chp->desc_fmt1.r)
  588. mdc = 1;
  589. mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
  590. chp->desc_fmt1.mdc;
  591. mutex_unlock(&chp->lock);
  592. }
  593. return mdc;
  594. }
  595. EXPORT_SYMBOL(ccw_device_get_mdc);
  596. /**
  597. * ccw_device_tm_intrg() - perform interrogate function
  598. * @cdev: ccw device on which to perform the interrogate function
  599. *
  600. * Perform an interrogate function on the given ccw device. Return zero on
  601. * success, non-zero otherwise.
  602. */
  603. int ccw_device_tm_intrg(struct ccw_device *cdev)
  604. {
  605. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  606. if (!sch->schib.pmcw.ena)
  607. return -EINVAL;
  608. if (cdev->private->state != DEV_STATE_ONLINE)
  609. return -EIO;
  610. if (!scsw_is_tm(&sch->schib.scsw) ||
  611. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  612. return -EINVAL;
  613. return cio_tm_intrg(sch);
  614. }
  615. EXPORT_SYMBOL(ccw_device_tm_intrg);
  616. /**
  617. * ccw_device_get_schid() - obtain a subchannel id
  618. * @cdev: device to obtain the id for
  619. * @schid: where to fill in the values
  620. */
  621. void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
  622. {
  623. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  624. *schid = sch->schid;
  625. }
  626. EXPORT_SYMBOL_GPL(ccw_device_get_schid);
  627. MODULE_LICENSE("GPL");
  628. EXPORT_SYMBOL(ccw_device_set_options_mask);
  629. EXPORT_SYMBOL(ccw_device_set_options);
  630. EXPORT_SYMBOL(ccw_device_clear_options);
  631. EXPORT_SYMBOL(ccw_device_clear);
  632. EXPORT_SYMBOL(ccw_device_halt);
  633. EXPORT_SYMBOL(ccw_device_resume);
  634. EXPORT_SYMBOL(ccw_device_start_timeout);
  635. EXPORT_SYMBOL(ccw_device_start);
  636. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  637. EXPORT_SYMBOL(ccw_device_start_key);
  638. EXPORT_SYMBOL(ccw_device_get_ciw);
  639. EXPORT_SYMBOL(ccw_device_get_path_mask);
  640. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);