device_ops.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /*
  3. * Copyright IBM Corp. 2002, 2009
  4. *
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  6. * Cornelia Huck (cornelia.huck@de.ibm.com)
  7. */
  8. #include <linux/export.h>
  9. #include <linux/init.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/list.h>
  13. #include <linux/device.h>
  14. #include <linux/delay.h>
  15. #include <linux/completion.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. cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0;
  49. return 0;
  50. }
  51. /**
  52. * ccw_device_set_options() - set some options
  53. * @cdev: device for which the options are to be set
  54. * @flags: options to be set
  55. *
  56. * All flags specified in @flags are set, the remainder is left untouched.
  57. * Returns:
  58. * %0 on success, -%EINVAL if an invalid flag combination would ensue.
  59. */
  60. int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
  61. {
  62. /*
  63. * The flag usage is mutal exclusive ...
  64. */
  65. if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
  66. (flags & CCWDEV_REPORT_ALL)) ||
  67. ((flags & CCWDEV_EARLY_NOTIFICATION) &&
  68. cdev->private->options.repall) ||
  69. ((flags & CCWDEV_REPORT_ALL) &&
  70. cdev->private->options.fast))
  71. return -EINVAL;
  72. cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
  73. cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
  74. cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
  75. cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
  76. cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0;
  77. return 0;
  78. }
  79. /**
  80. * ccw_device_clear_options() - clear some options
  81. * @cdev: device for which the options are to be cleared
  82. * @flags: options to be cleared
  83. *
  84. * All flags specified in @flags are cleared, the remainder is left untouched.
  85. */
  86. void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
  87. {
  88. cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
  89. cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
  90. cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
  91. cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
  92. cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0;
  93. }
  94. /**
  95. * ccw_device_is_pathgroup() - determine if paths to this device are grouped
  96. * @cdev: ccw device
  97. *
  98. * Return non-zero if there is a path group, zero otherwise.
  99. */
  100. int ccw_device_is_pathgroup(struct ccw_device *cdev)
  101. {
  102. return cdev->private->flags.pgroup;
  103. }
  104. EXPORT_SYMBOL(ccw_device_is_pathgroup);
  105. /**
  106. * ccw_device_is_multipath() - determine if device is operating in multipath mode
  107. * @cdev: ccw device
  108. *
  109. * Return non-zero if device is operating in multipath mode, zero otherwise.
  110. */
  111. int ccw_device_is_multipath(struct ccw_device *cdev)
  112. {
  113. return cdev->private->flags.mpath;
  114. }
  115. EXPORT_SYMBOL(ccw_device_is_multipath);
  116. /**
  117. * ccw_device_clear() - terminate I/O request processing
  118. * @cdev: target ccw device
  119. * @intparm: interruption parameter; value is only used if no I/O is
  120. * outstanding, otherwise the intparm associated with the I/O request
  121. * is returned
  122. *
  123. * ccw_device_clear() calls csch on @cdev's subchannel.
  124. * Returns:
  125. * %0 on success,
  126. * -%ENODEV on device not operational,
  127. * -%EINVAL on invalid device state.
  128. * Context:
  129. * Interrupts disabled, ccw device lock held
  130. */
  131. int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
  132. {
  133. struct subchannel *sch;
  134. int ret;
  135. if (!cdev || !cdev->dev.parent)
  136. return -ENODEV;
  137. sch = to_subchannel(cdev->dev.parent);
  138. if (!sch->schib.pmcw.ena)
  139. return -EINVAL;
  140. if (cdev->private->state == DEV_STATE_NOT_OPER)
  141. return -ENODEV;
  142. if (cdev->private->state != DEV_STATE_ONLINE &&
  143. cdev->private->state != DEV_STATE_W4SENSE)
  144. return -EINVAL;
  145. ret = cio_clear(sch);
  146. if (ret == 0)
  147. cdev->private->intparm = intparm;
  148. return ret;
  149. }
  150. /**
  151. * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
  152. * @cdev: target ccw device
  153. * @cpa: logical start address of channel program
  154. * @intparm: user specific interruption parameter; will be presented back to
  155. * @cdev's interrupt handler. Allows a device driver to associate
  156. * the interrupt with a particular I/O request.
  157. * @lpm: defines the channel path to be used for a specific I/O request. A
  158. * value of 0 will make cio use the opm.
  159. * @key: storage key to be used for the I/O
  160. * @flags: additional flags; defines the action to be performed for I/O
  161. * processing.
  162. * @expires: timeout value in jiffies
  163. *
  164. * Start a S/390 channel program. When the interrupt arrives, the
  165. * IRQ handler is called, either immediately, delayed (dev-end missing,
  166. * or sense required) or never (no IRQ handler registered).
  167. * This function notifies the device driver if the channel program has not
  168. * completed during the time specified by @expires. If a timeout occurs, the
  169. * channel program is terminated via xsch, hsch or csch, and the device's
  170. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  171. * Returns:
  172. * %0, if the operation was successful;
  173. * -%EBUSY, if the device is busy, or status pending;
  174. * -%EACCES, if no path specified in @lpm is operational;
  175. * -%ENODEV, if the device is not operational.
  176. * Context:
  177. * Interrupts disabled, ccw device lock held
  178. */
  179. int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
  180. unsigned long intparm, __u8 lpm, __u8 key,
  181. unsigned long flags, int expires)
  182. {
  183. struct subchannel *sch;
  184. int ret;
  185. if (!cdev || !cdev->dev.parent)
  186. return -ENODEV;
  187. sch = to_subchannel(cdev->dev.parent);
  188. if (!sch->schib.pmcw.ena)
  189. return -EINVAL;
  190. if (cdev->private->state == DEV_STATE_NOT_OPER)
  191. return -ENODEV;
  192. if (cdev->private->state == DEV_STATE_VERIFY) {
  193. /* Remember to fake irb when finished. */
  194. if (!cdev->private->flags.fake_irb) {
  195. cdev->private->flags.fake_irb = FAKE_CMD_IRB;
  196. cdev->private->intparm = intparm;
  197. return 0;
  198. } else
  199. /* There's already a fake I/O around. */
  200. return -EBUSY;
  201. }
  202. if (cdev->private->state != DEV_STATE_ONLINE ||
  203. ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
  204. !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
  205. cdev->private->flags.doverify)
  206. return -EBUSY;
  207. ret = cio_set_options (sch, flags);
  208. if (ret)
  209. return ret;
  210. /* Adjust requested path mask to exclude unusable paths. */
  211. if (lpm) {
  212. lpm &= sch->lpm;
  213. if (lpm == 0)
  214. return -EACCES;
  215. }
  216. ret = cio_start_key (sch, cpa, lpm, key);
  217. switch (ret) {
  218. case 0:
  219. cdev->private->intparm = intparm;
  220. if (expires)
  221. ccw_device_set_timeout(cdev, expires);
  222. break;
  223. case -EACCES:
  224. case -ENODEV:
  225. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  226. break;
  227. }
  228. return ret;
  229. }
  230. /**
  231. * ccw_device_start_key() - start a s390 channel program with key
  232. * @cdev: target ccw device
  233. * @cpa: logical start address of channel program
  234. * @intparm: user specific interruption parameter; will be presented back to
  235. * @cdev's interrupt handler. Allows a device driver to associate
  236. * the interrupt with a particular I/O request.
  237. * @lpm: defines the channel path to be used for a specific I/O request. A
  238. * value of 0 will make cio use the opm.
  239. * @key: storage key to be used for the I/O
  240. * @flags: additional flags; defines the action to be performed for I/O
  241. * processing.
  242. *
  243. * Start a S/390 channel program. When the interrupt arrives, the
  244. * IRQ handler is called, either immediately, delayed (dev-end missing,
  245. * or sense required) or never (no IRQ handler registered).
  246. * Returns:
  247. * %0, if the operation was successful;
  248. * -%EBUSY, if the device is busy, or status pending;
  249. * -%EACCES, if no path specified in @lpm is operational;
  250. * -%ENODEV, if the device is not operational.
  251. * Context:
  252. * Interrupts disabled, ccw device lock held
  253. */
  254. int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
  255. unsigned long intparm, __u8 lpm, __u8 key,
  256. unsigned long flags)
  257. {
  258. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, key,
  259. flags, 0);
  260. }
  261. /**
  262. * ccw_device_start() - start a s390 channel program
  263. * @cdev: target ccw device
  264. * @cpa: logical start address of channel program
  265. * @intparm: user specific interruption parameter; will be presented back to
  266. * @cdev's interrupt handler. Allows a device driver to associate
  267. * the interrupt with a particular I/O request.
  268. * @lpm: defines the channel path to be used for a specific I/O request. A
  269. * value of 0 will make cio use the opm.
  270. * @flags: additional flags; defines the action to be performed for I/O
  271. * processing.
  272. *
  273. * Start a S/390 channel program. When the interrupt arrives, the
  274. * IRQ handler is called, either immediately, delayed (dev-end missing,
  275. * or sense required) or never (no IRQ handler registered).
  276. * Returns:
  277. * %0, if the operation was successful;
  278. * -%EBUSY, if the device is busy, or status pending;
  279. * -%EACCES, if no path specified in @lpm is operational;
  280. * -%ENODEV, if the device is not operational.
  281. * Context:
  282. * Interrupts disabled, ccw device lock held
  283. */
  284. int ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa,
  285. unsigned long intparm, __u8 lpm, unsigned long flags)
  286. {
  287. return ccw_device_start_key(cdev, cpa, intparm, lpm,
  288. PAGE_DEFAULT_KEY, flags);
  289. }
  290. /**
  291. * ccw_device_start_timeout() - start a s390 channel program with timeout
  292. * @cdev: target ccw device
  293. * @cpa: logical start address of channel program
  294. * @intparm: user specific interruption parameter; will be presented back to
  295. * @cdev's interrupt handler. Allows a device driver to associate
  296. * the interrupt with a particular I/O request.
  297. * @lpm: defines the channel path to be used for a specific I/O request. A
  298. * value of 0 will make cio use the opm.
  299. * @flags: additional flags; defines the action to be performed for I/O
  300. * processing.
  301. * @expires: timeout value in jiffies
  302. *
  303. * Start a S/390 channel program. When the interrupt arrives, the
  304. * IRQ handler is called, either immediately, delayed (dev-end missing,
  305. * or sense required) or never (no IRQ handler registered).
  306. * This function notifies the device driver if the channel program has not
  307. * completed during the time specified by @expires. If a timeout occurs, the
  308. * channel program is terminated via xsch, hsch or csch, and the device's
  309. * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
  310. * Returns:
  311. * %0, if the operation was successful;
  312. * -%EBUSY, if the device is busy, or status pending;
  313. * -%EACCES, if no path specified in @lpm is operational;
  314. * -%ENODEV, if the device is not operational.
  315. * Context:
  316. * Interrupts disabled, ccw device lock held
  317. */
  318. int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,
  319. unsigned long intparm, __u8 lpm,
  320. unsigned long flags, int expires)
  321. {
  322. return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,
  323. PAGE_DEFAULT_KEY, flags,
  324. expires);
  325. }
  326. /**
  327. * ccw_device_halt() - halt I/O request processing
  328. * @cdev: target ccw device
  329. * @intparm: interruption parameter; value is only used if no I/O is
  330. * outstanding, otherwise the intparm associated with the I/O request
  331. * is returned
  332. *
  333. * ccw_device_halt() calls hsch on @cdev's subchannel.
  334. * Returns:
  335. * %0 on success,
  336. * -%ENODEV on device not operational,
  337. * -%EINVAL on invalid device state,
  338. * -%EBUSY on device busy or interrupt pending.
  339. * Context:
  340. * Interrupts disabled, ccw device lock held
  341. */
  342. int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)
  343. {
  344. struct subchannel *sch;
  345. int ret;
  346. if (!cdev || !cdev->dev.parent)
  347. return -ENODEV;
  348. sch = to_subchannel(cdev->dev.parent);
  349. if (!sch->schib.pmcw.ena)
  350. return -EINVAL;
  351. if (cdev->private->state == DEV_STATE_NOT_OPER)
  352. return -ENODEV;
  353. if (cdev->private->state != DEV_STATE_ONLINE &&
  354. cdev->private->state != DEV_STATE_W4SENSE)
  355. return -EINVAL;
  356. ret = cio_halt(sch);
  357. if (ret == 0)
  358. cdev->private->intparm = intparm;
  359. return ret;
  360. }
  361. /**
  362. * ccw_device_resume() - resume channel program execution
  363. * @cdev: target ccw device
  364. *
  365. * ccw_device_resume() calls rsch on @cdev's subchannel.
  366. * Returns:
  367. * %0 on success,
  368. * -%ENODEV on device not operational,
  369. * -%EINVAL on invalid device state,
  370. * -%EBUSY on device busy or interrupt pending.
  371. * Context:
  372. * Interrupts disabled, ccw device lock held
  373. */
  374. int ccw_device_resume(struct ccw_device *cdev)
  375. {
  376. struct subchannel *sch;
  377. if (!cdev || !cdev->dev.parent)
  378. return -ENODEV;
  379. sch = to_subchannel(cdev->dev.parent);
  380. if (!sch->schib.pmcw.ena)
  381. return -EINVAL;
  382. if (cdev->private->state == DEV_STATE_NOT_OPER)
  383. return -ENODEV;
  384. if (cdev->private->state != DEV_STATE_ONLINE ||
  385. !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
  386. return -EINVAL;
  387. return cio_resume(sch);
  388. }
  389. /**
  390. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  391. * @cdev: ccw device to inspect
  392. * @ct: command type to look for
  393. *
  394. * During SenseID, command information words (CIWs) describing special
  395. * commands available to the device may have been stored in the extended
  396. * sense data. This function searches for CIWs of a specified command
  397. * type in the extended sense data.
  398. * Returns:
  399. * %NULL if no extended sense data has been stored or if no CIW of the
  400. * specified command type could be found,
  401. * else a pointer to the CIW of the specified command type.
  402. */
  403. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  404. {
  405. int ciw_cnt;
  406. if (cdev->private->flags.esid == 0)
  407. return NULL;
  408. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  409. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  410. return cdev->private->senseid.ciw + ciw_cnt;
  411. return NULL;
  412. }
  413. /**
  414. * ccw_device_get_path_mask() - get currently available paths
  415. * @cdev: ccw device to be queried
  416. * Returns:
  417. * %0 if no subchannel for the device is available,
  418. * else the mask of currently available paths for the ccw device's subchannel.
  419. */
  420. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  421. {
  422. struct subchannel *sch;
  423. if (!cdev->dev.parent)
  424. return 0;
  425. sch = to_subchannel(cdev->dev.parent);
  426. return sch->lpm;
  427. }
  428. /**
  429. * ccw_device_get_chp_desc() - return newly allocated channel-path descriptor
  430. * @cdev: device to obtain the descriptor for
  431. * @chp_idx: index of the channel path
  432. *
  433. * On success return a newly allocated copy of the channel-path description
  434. * data associated with the given channel path. Return %NULL on error.
  435. */
  436. struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *cdev,
  437. int chp_idx)
  438. {
  439. struct subchannel *sch;
  440. struct chp_id chpid;
  441. sch = to_subchannel(cdev->dev.parent);
  442. chp_id_init(&chpid);
  443. chpid.id = sch->schib.pmcw.chpid[chp_idx];
  444. return chp_get_chp_desc(chpid);
  445. }
  446. /**
  447. * ccw_device_get_util_str() - return newly allocated utility strings
  448. * @cdev: device to obtain the utility strings for
  449. * @chp_idx: index of the channel path
  450. *
  451. * On success return a newly allocated copy of the utility strings
  452. * associated with the given channel path. Return %NULL on error.
  453. */
  454. u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx)
  455. {
  456. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  457. struct channel_path *chp;
  458. struct chp_id chpid;
  459. u8 *util_str;
  460. chp_id_init(&chpid);
  461. chpid.id = sch->schib.pmcw.chpid[chp_idx];
  462. chp = chpid_to_chp(chpid);
  463. util_str = kmalloc(sizeof(chp->desc_fmt3.util_str), GFP_KERNEL);
  464. if (!util_str)
  465. return NULL;
  466. mutex_lock(&chp->lock);
  467. memcpy(util_str, chp->desc_fmt3.util_str, sizeof(chp->desc_fmt3.util_str));
  468. mutex_unlock(&chp->lock);
  469. return util_str;
  470. }
  471. /**
  472. * ccw_device_get_id() - obtain a ccw device id
  473. * @cdev: device to obtain the id for
  474. * @dev_id: where to fill in the values
  475. */
  476. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  477. {
  478. *dev_id = cdev->private->dev_id;
  479. }
  480. EXPORT_SYMBOL(ccw_device_get_id);
  481. /**
  482. * ccw_device_tm_start_timeout_key() - perform start function
  483. * @cdev: ccw device on which to perform the start function
  484. * @tcw: transport-command word to be started
  485. * @intparm: user defined parameter to be passed to the interrupt handler
  486. * @lpm: mask of paths to use
  487. * @key: storage key to use for storage access
  488. * @expires: time span in jiffies after which to abort request
  489. *
  490. * Start the tcw on the given ccw device. Return zero on success, non-zero
  491. * otherwise.
  492. */
  493. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  494. unsigned long intparm, u8 lpm, u8 key,
  495. int expires)
  496. {
  497. struct subchannel *sch;
  498. int rc;
  499. sch = to_subchannel(cdev->dev.parent);
  500. if (!sch->schib.pmcw.ena)
  501. return -EINVAL;
  502. if (cdev->private->state == DEV_STATE_VERIFY) {
  503. /* Remember to fake irb when finished. */
  504. if (!cdev->private->flags.fake_irb) {
  505. cdev->private->flags.fake_irb = FAKE_TM_IRB;
  506. cdev->private->intparm = intparm;
  507. return 0;
  508. } else
  509. /* There's already a fake I/O around. */
  510. return -EBUSY;
  511. }
  512. if (cdev->private->state != DEV_STATE_ONLINE)
  513. return -EIO;
  514. /* Adjust requested path mask to exclude unusable paths. */
  515. if (lpm) {
  516. lpm &= sch->lpm;
  517. if (lpm == 0)
  518. return -EACCES;
  519. }
  520. rc = cio_tm_start_key(sch, tcw, lpm, key);
  521. if (rc == 0) {
  522. cdev->private->intparm = intparm;
  523. if (expires)
  524. ccw_device_set_timeout(cdev, expires);
  525. }
  526. return rc;
  527. }
  528. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  529. /**
  530. * ccw_device_tm_start_key() - perform start function
  531. * @cdev: ccw device on which to perform the start function
  532. * @tcw: transport-command word to be started
  533. * @intparm: user defined parameter to be passed to the interrupt handler
  534. * @lpm: mask of paths to use
  535. * @key: storage key to use for storage access
  536. *
  537. * Start the tcw on the given ccw device. Return zero on success, non-zero
  538. * otherwise.
  539. */
  540. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  541. unsigned long intparm, u8 lpm, u8 key)
  542. {
  543. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, key, 0);
  544. }
  545. EXPORT_SYMBOL(ccw_device_tm_start_key);
  546. /**
  547. * ccw_device_tm_start() - perform start function
  548. * @cdev: ccw device on which to perform the start function
  549. * @tcw: transport-command word to be started
  550. * @intparm: user defined parameter to be passed to the interrupt handler
  551. * @lpm: mask of paths to use
  552. *
  553. * Start the tcw on the given ccw device. Return zero on success, non-zero
  554. * otherwise.
  555. */
  556. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  557. unsigned long intparm, u8 lpm)
  558. {
  559. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  560. PAGE_DEFAULT_KEY);
  561. }
  562. EXPORT_SYMBOL(ccw_device_tm_start);
  563. /**
  564. * ccw_device_tm_start_timeout() - perform start function
  565. * @cdev: ccw device on which to perform the start function
  566. * @tcw: transport-command word to be started
  567. * @intparm: user defined parameter to be passed to the interrupt handler
  568. * @lpm: mask of paths to use
  569. * @expires: time span in jiffies after which to abort request
  570. *
  571. * Start the tcw on the given ccw device. Return zero on success, non-zero
  572. * otherwise.
  573. */
  574. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  575. unsigned long intparm, u8 lpm, int expires)
  576. {
  577. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  578. PAGE_DEFAULT_KEY, expires);
  579. }
  580. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  581. /**
  582. * ccw_device_get_mdc() - accumulate max data count
  583. * @cdev: ccw device for which the max data count is accumulated
  584. * @mask: mask of paths to use
  585. *
  586. * Return the number of 64K-bytes blocks all paths at least support
  587. * for a transport command. Return value 0 indicates failure.
  588. */
  589. int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
  590. {
  591. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  592. struct channel_path *chp;
  593. struct chp_id chpid;
  594. int mdc = 0, i;
  595. /* Adjust requested path mask to excluded varied off paths. */
  596. if (mask)
  597. mask &= sch->lpm;
  598. else
  599. mask = sch->lpm;
  600. chp_id_init(&chpid);
  601. for (i = 0; i < 8; i++) {
  602. if (!(mask & (0x80 >> i)))
  603. continue;
  604. chpid.id = sch->schib.pmcw.chpid[i];
  605. chp = chpid_to_chp(chpid);
  606. if (!chp)
  607. continue;
  608. mutex_lock(&chp->lock);
  609. if (!chp->desc_fmt1.f) {
  610. mutex_unlock(&chp->lock);
  611. return 0;
  612. }
  613. if (!chp->desc_fmt1.r)
  614. mdc = 1;
  615. mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
  616. chp->desc_fmt1.mdc;
  617. mutex_unlock(&chp->lock);
  618. }
  619. return mdc;
  620. }
  621. EXPORT_SYMBOL(ccw_device_get_mdc);
  622. /**
  623. * ccw_device_tm_intrg() - perform interrogate function
  624. * @cdev: ccw device on which to perform the interrogate function
  625. *
  626. * Perform an interrogate function on the given ccw device. Return zero on
  627. * success, non-zero otherwise.
  628. */
  629. int ccw_device_tm_intrg(struct ccw_device *cdev)
  630. {
  631. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  632. if (!sch->schib.pmcw.ena)
  633. return -EINVAL;
  634. if (cdev->private->state != DEV_STATE_ONLINE)
  635. return -EIO;
  636. if (!scsw_is_tm(&sch->schib.scsw) ||
  637. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  638. return -EINVAL;
  639. return cio_tm_intrg(sch);
  640. }
  641. EXPORT_SYMBOL(ccw_device_tm_intrg);
  642. /**
  643. * ccw_device_get_schid() - obtain a subchannel id
  644. * @cdev: device to obtain the id for
  645. * @schid: where to fill in the values
  646. */
  647. void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
  648. {
  649. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  650. *schid = sch->schid;
  651. }
  652. EXPORT_SYMBOL_GPL(ccw_device_get_schid);
  653. EXPORT_SYMBOL(ccw_device_set_options_mask);
  654. EXPORT_SYMBOL(ccw_device_set_options);
  655. EXPORT_SYMBOL(ccw_device_clear_options);
  656. EXPORT_SYMBOL(ccw_device_clear);
  657. EXPORT_SYMBOL(ccw_device_halt);
  658. EXPORT_SYMBOL(ccw_device_resume);
  659. EXPORT_SYMBOL(ccw_device_start_timeout);
  660. EXPORT_SYMBOL(ccw_device_start);
  661. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  662. EXPORT_SYMBOL(ccw_device_start_key);
  663. EXPORT_SYMBOL(ccw_device_get_ciw);
  664. EXPORT_SYMBOL(ccw_device_get_path_mask);
  665. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);
  666. EXPORT_SYMBOL_GPL(ccw_device_get_util_str);