device_ops.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. * Pass interrupt to device driver.
  394. */
  395. int
  396. ccw_device_call_handler(struct ccw_device *cdev)
  397. {
  398. unsigned int stctl;
  399. int ending_status;
  400. /*
  401. * we allow for the device action handler if .
  402. * - we received ending status
  403. * - the action handler requested to see all interrupts
  404. * - we received an intermediate status
  405. * - fast notification was requested (primary status)
  406. * - unsolicited interrupts
  407. */
  408. stctl = scsw_stctl(&cdev->private->irb.scsw);
  409. ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
  410. (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
  411. (stctl == SCSW_STCTL_STATUS_PEND);
  412. if (!ending_status &&
  413. !cdev->private->options.repall &&
  414. !(stctl & SCSW_STCTL_INTER_STATUS) &&
  415. !(cdev->private->options.fast &&
  416. (stctl & SCSW_STCTL_PRIM_STATUS)))
  417. return 0;
  418. /* Clear pending timers for device driver initiated I/O. */
  419. if (ending_status)
  420. ccw_device_set_timeout(cdev, 0);
  421. /*
  422. * Now we are ready to call the device driver interrupt handler.
  423. */
  424. if (cdev->handler)
  425. cdev->handler(cdev, cdev->private->intparm,
  426. &cdev->private->irb);
  427. /*
  428. * Clear the old and now useless interrupt response block.
  429. */
  430. memset(&cdev->private->irb, 0, sizeof(struct irb));
  431. return 1;
  432. }
  433. /**
  434. * ccw_device_get_ciw() - Search for CIW command in extended sense data.
  435. * @cdev: ccw device to inspect
  436. * @ct: command type to look for
  437. *
  438. * During SenseID, command information words (CIWs) describing special
  439. * commands available to the device may have been stored in the extended
  440. * sense data. This function searches for CIWs of a specified command
  441. * type in the extended sense data.
  442. * Returns:
  443. * %NULL if no extended sense data has been stored or if no CIW of the
  444. * specified command type could be found,
  445. * else a pointer to the CIW of the specified command type.
  446. */
  447. struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct)
  448. {
  449. int ciw_cnt;
  450. if (cdev->private->flags.esid == 0)
  451. return NULL;
  452. for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)
  453. if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)
  454. return cdev->private->senseid.ciw + ciw_cnt;
  455. return NULL;
  456. }
  457. /**
  458. * ccw_device_get_path_mask() - get currently available paths
  459. * @cdev: ccw device to be queried
  460. * Returns:
  461. * %0 if no subchannel for the device is available,
  462. * else the mask of currently available paths for the ccw device's subchannel.
  463. */
  464. __u8 ccw_device_get_path_mask(struct ccw_device *cdev)
  465. {
  466. struct subchannel *sch;
  467. if (!cdev->dev.parent)
  468. return 0;
  469. sch = to_subchannel(cdev->dev.parent);
  470. return sch->lpm;
  471. }
  472. struct stlck_data {
  473. struct completion done;
  474. int rc;
  475. };
  476. void ccw_device_stlck_done(struct ccw_device *cdev, void *data, int rc)
  477. {
  478. struct stlck_data *sdata = data;
  479. sdata->rc = rc;
  480. complete(&sdata->done);
  481. }
  482. /*
  483. * Perform unconditional reserve + release.
  484. */
  485. int ccw_device_stlck(struct ccw_device *cdev)
  486. {
  487. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  488. struct stlck_data data;
  489. u8 *buffer;
  490. int rc;
  491. /* Check if steal lock operation is valid for this device. */
  492. if (cdev->drv) {
  493. if (!cdev->private->options.force)
  494. return -EINVAL;
  495. }
  496. buffer = kzalloc(64, GFP_DMA | GFP_KERNEL);
  497. if (!buffer)
  498. return -ENOMEM;
  499. init_completion(&data.done);
  500. data.rc = -EIO;
  501. spin_lock_irq(sch->lock);
  502. rc = cio_enable_subchannel(sch, (u32) (addr_t) sch);
  503. if (rc)
  504. goto out_unlock;
  505. /* Perform operation. */
  506. cdev->private->state = DEV_STATE_STEAL_LOCK,
  507. ccw_device_stlck_start(cdev, &data, &buffer[0], &buffer[32]);
  508. spin_unlock_irq(sch->lock);
  509. /* Wait for operation to finish. */
  510. if (wait_for_completion_interruptible(&data.done)) {
  511. /* Got a signal. */
  512. spin_lock_irq(sch->lock);
  513. ccw_request_cancel(cdev);
  514. spin_unlock_irq(sch->lock);
  515. wait_for_completion(&data.done);
  516. }
  517. rc = data.rc;
  518. /* Check results. */
  519. spin_lock_irq(sch->lock);
  520. cio_disable_subchannel(sch);
  521. cdev->private->state = DEV_STATE_BOXED;
  522. out_unlock:
  523. spin_unlock_irq(sch->lock);
  524. kfree(buffer);
  525. return rc;
  526. }
  527. /**
  528. * chp_get_chp_desc - return newly allocated channel-path descriptor
  529. * @cdev: device to obtain the descriptor for
  530. * @chp_idx: index of the channel path
  531. *
  532. * On success return a newly allocated copy of the channel-path description
  533. * data associated with the given channel path. Return %NULL on error.
  534. */
  535. struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *cdev,
  536. int chp_idx)
  537. {
  538. struct subchannel *sch;
  539. struct chp_id chpid;
  540. sch = to_subchannel(cdev->dev.parent);
  541. chp_id_init(&chpid);
  542. chpid.id = sch->schib.pmcw.chpid[chp_idx];
  543. return chp_get_chp_desc(chpid);
  544. }
  545. /**
  546. * ccw_device_get_id - obtain a ccw device id
  547. * @cdev: device to obtain the id for
  548. * @dev_id: where to fill in the values
  549. */
  550. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  551. {
  552. *dev_id = cdev->private->dev_id;
  553. }
  554. EXPORT_SYMBOL(ccw_device_get_id);
  555. /**
  556. * ccw_device_tm_start_key - perform start function
  557. * @cdev: ccw device on which to perform the start function
  558. * @tcw: transport-command word to be started
  559. * @intparm: user defined parameter to be passed to the interrupt handler
  560. * @lpm: mask of paths to use
  561. * @key: storage key to use for storage access
  562. *
  563. * Start the tcw on the given ccw device. Return zero on success, non-zero
  564. * otherwise.
  565. */
  566. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  567. unsigned long intparm, u8 lpm, u8 key)
  568. {
  569. struct subchannel *sch;
  570. int rc;
  571. sch = to_subchannel(cdev->dev.parent);
  572. if (!sch->schib.pmcw.ena)
  573. return -EINVAL;
  574. if (cdev->private->state == DEV_STATE_VERIFY) {
  575. /* Remember to fake irb when finished. */
  576. if (!cdev->private->flags.fake_irb) {
  577. cdev->private->flags.fake_irb = FAKE_TM_IRB;
  578. cdev->private->intparm = intparm;
  579. return 0;
  580. } else
  581. /* There's already a fake I/O around. */
  582. return -EBUSY;
  583. }
  584. if (cdev->private->state != DEV_STATE_ONLINE)
  585. return -EIO;
  586. /* Adjust requested path mask to exclude unusable paths. */
  587. if (lpm) {
  588. lpm &= sch->lpm;
  589. if (lpm == 0)
  590. return -EACCES;
  591. }
  592. rc = cio_tm_start_key(sch, tcw, lpm, key);
  593. if (rc == 0)
  594. cdev->private->intparm = intparm;
  595. return rc;
  596. }
  597. EXPORT_SYMBOL(ccw_device_tm_start_key);
  598. /**
  599. * ccw_device_tm_start_timeout_key - perform start function
  600. * @cdev: ccw device on which to perform the start function
  601. * @tcw: transport-command word to be started
  602. * @intparm: user defined parameter to be passed to the interrupt handler
  603. * @lpm: mask of paths to use
  604. * @key: storage key to use for storage access
  605. * @expires: time span in jiffies after which to abort request
  606. *
  607. * Start the tcw on the given ccw device. Return zero on success, non-zero
  608. * otherwise.
  609. */
  610. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  611. unsigned long intparm, u8 lpm, u8 key,
  612. int expires)
  613. {
  614. int ret;
  615. ccw_device_set_timeout(cdev, expires);
  616. ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
  617. if (ret != 0)
  618. ccw_device_set_timeout(cdev, 0);
  619. return ret;
  620. }
  621. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  622. /**
  623. * ccw_device_tm_start - 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. *
  629. * Start the tcw on the given ccw device. Return zero on success, non-zero
  630. * otherwise.
  631. */
  632. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  633. unsigned long intparm, u8 lpm)
  634. {
  635. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  636. PAGE_DEFAULT_KEY);
  637. }
  638. EXPORT_SYMBOL(ccw_device_tm_start);
  639. /**
  640. * ccw_device_tm_start_timeout - perform start function
  641. * @cdev: ccw device on which to perform the start function
  642. * @tcw: transport-command word to be started
  643. * @intparm: user defined parameter to be passed to the interrupt handler
  644. * @lpm: mask of paths to use
  645. * @expires: time span in jiffies after which to abort request
  646. *
  647. * Start the tcw on the given ccw device. Return zero on success, non-zero
  648. * otherwise.
  649. */
  650. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  651. unsigned long intparm, u8 lpm, int expires)
  652. {
  653. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  654. PAGE_DEFAULT_KEY, expires);
  655. }
  656. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  657. /**
  658. * ccw_device_get_mdc - accumulate max data count
  659. * @cdev: ccw device for which the max data count is accumulated
  660. * @mask: mask of paths to use
  661. *
  662. * Return the number of 64K-bytes blocks all paths at least support
  663. * for a transport command. Return values <= 0 indicate failures.
  664. */
  665. int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
  666. {
  667. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  668. struct channel_path *chp;
  669. struct chp_id chpid;
  670. int mdc = 0, i;
  671. /* Adjust requested path mask to excluded varied off paths. */
  672. if (mask)
  673. mask &= sch->lpm;
  674. else
  675. mask = sch->lpm;
  676. chp_id_init(&chpid);
  677. for (i = 0; i < 8; i++) {
  678. if (!(mask & (0x80 >> i)))
  679. continue;
  680. chpid.id = sch->schib.pmcw.chpid[i];
  681. chp = chpid_to_chp(chpid);
  682. if (!chp)
  683. continue;
  684. mutex_lock(&chp->lock);
  685. if (!chp->desc_fmt1.f) {
  686. mutex_unlock(&chp->lock);
  687. return 0;
  688. }
  689. if (!chp->desc_fmt1.r)
  690. mdc = 1;
  691. mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) :
  692. chp->desc_fmt1.mdc;
  693. mutex_unlock(&chp->lock);
  694. }
  695. return mdc;
  696. }
  697. EXPORT_SYMBOL(ccw_device_get_mdc);
  698. /**
  699. * ccw_device_tm_intrg - perform interrogate function
  700. * @cdev: ccw device on which to perform the interrogate function
  701. *
  702. * Perform an interrogate function on the given ccw device. Return zero on
  703. * success, non-zero otherwise.
  704. */
  705. int ccw_device_tm_intrg(struct ccw_device *cdev)
  706. {
  707. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  708. if (!sch->schib.pmcw.ena)
  709. return -EINVAL;
  710. if (cdev->private->state != DEV_STATE_ONLINE)
  711. return -EIO;
  712. if (!scsw_is_tm(&sch->schib.scsw) ||
  713. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  714. return -EINVAL;
  715. return cio_tm_intrg(sch);
  716. }
  717. EXPORT_SYMBOL(ccw_device_tm_intrg);
  718. /**
  719. * ccw_device_get_schid - obtain a subchannel id
  720. * @cdev: device to obtain the id for
  721. * @schid: where to fill in the values
  722. */
  723. void ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid)
  724. {
  725. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  726. *schid = sch->schid;
  727. }
  728. EXPORT_SYMBOL_GPL(ccw_device_get_schid);
  729. MODULE_LICENSE("GPL");
  730. EXPORT_SYMBOL(ccw_device_set_options_mask);
  731. EXPORT_SYMBOL(ccw_device_set_options);
  732. EXPORT_SYMBOL(ccw_device_clear_options);
  733. EXPORT_SYMBOL(ccw_device_clear);
  734. EXPORT_SYMBOL(ccw_device_halt);
  735. EXPORT_SYMBOL(ccw_device_resume);
  736. EXPORT_SYMBOL(ccw_device_start_timeout);
  737. EXPORT_SYMBOL(ccw_device_start);
  738. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  739. EXPORT_SYMBOL(ccw_device_start_key);
  740. EXPORT_SYMBOL(ccw_device_get_ciw);
  741. EXPORT_SYMBOL(ccw_device_get_path_mask);
  742. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);