device_ops.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
  528. {
  529. struct subchannel *sch;
  530. struct chp_id chpid;
  531. sch = to_subchannel(cdev->dev.parent);
  532. chp_id_init(&chpid);
  533. chpid.id = sch->schib.pmcw.chpid[chp_no];
  534. return chp_get_chp_desc(chpid);
  535. }
  536. /**
  537. * ccw_device_get_id - obtain a ccw device id
  538. * @cdev: device to obtain the id for
  539. * @dev_id: where to fill in the values
  540. */
  541. void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
  542. {
  543. *dev_id = cdev->private->dev_id;
  544. }
  545. EXPORT_SYMBOL(ccw_device_get_id);
  546. /**
  547. * ccw_device_tm_start_key - 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. * @key: storage key to use for storage access
  553. *
  554. * Start the tcw on the given ccw device. Return zero on success, non-zero
  555. * otherwise.
  556. */
  557. int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
  558. unsigned long intparm, u8 lpm, u8 key)
  559. {
  560. struct subchannel *sch;
  561. int rc;
  562. sch = to_subchannel(cdev->dev.parent);
  563. if (!sch->schib.pmcw.ena)
  564. return -EINVAL;
  565. if (cdev->private->state == DEV_STATE_VERIFY) {
  566. /* Remember to fake irb when finished. */
  567. if (!cdev->private->flags.fake_irb) {
  568. cdev->private->flags.fake_irb = FAKE_TM_IRB;
  569. cdev->private->intparm = intparm;
  570. return 0;
  571. } else
  572. /* There's already a fake I/O around. */
  573. return -EBUSY;
  574. }
  575. if (cdev->private->state != DEV_STATE_ONLINE)
  576. return -EIO;
  577. /* Adjust requested path mask to exclude unusable paths. */
  578. if (lpm) {
  579. lpm &= sch->lpm;
  580. if (lpm == 0)
  581. return -EACCES;
  582. }
  583. rc = cio_tm_start_key(sch, tcw, lpm, key);
  584. if (rc == 0)
  585. cdev->private->intparm = intparm;
  586. return rc;
  587. }
  588. EXPORT_SYMBOL(ccw_device_tm_start_key);
  589. /**
  590. * ccw_device_tm_start_timeout_key - perform start function
  591. * @cdev: ccw device on which to perform the start function
  592. * @tcw: transport-command word to be started
  593. * @intparm: user defined parameter to be passed to the interrupt handler
  594. * @lpm: mask of paths to use
  595. * @key: storage key to use for storage access
  596. * @expires: time span in jiffies after which to abort request
  597. *
  598. * Start the tcw on the given ccw device. Return zero on success, non-zero
  599. * otherwise.
  600. */
  601. int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
  602. unsigned long intparm, u8 lpm, u8 key,
  603. int expires)
  604. {
  605. int ret;
  606. ccw_device_set_timeout(cdev, expires);
  607. ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
  608. if (ret != 0)
  609. ccw_device_set_timeout(cdev, 0);
  610. return ret;
  611. }
  612. EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
  613. /**
  614. * ccw_device_tm_start - perform start function
  615. * @cdev: ccw device on which to perform the start function
  616. * @tcw: transport-command word to be started
  617. * @intparm: user defined parameter to be passed to the interrupt handler
  618. * @lpm: mask of paths to use
  619. *
  620. * Start the tcw on the given ccw device. Return zero on success, non-zero
  621. * otherwise.
  622. */
  623. int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
  624. unsigned long intparm, u8 lpm)
  625. {
  626. return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
  627. PAGE_DEFAULT_KEY);
  628. }
  629. EXPORT_SYMBOL(ccw_device_tm_start);
  630. /**
  631. * ccw_device_tm_start_timeout - perform start function
  632. * @cdev: ccw device on which to perform the start function
  633. * @tcw: transport-command word to be started
  634. * @intparm: user defined parameter to be passed to the interrupt handler
  635. * @lpm: mask of paths to use
  636. * @expires: time span in jiffies after which to abort request
  637. *
  638. * Start the tcw on the given ccw device. Return zero on success, non-zero
  639. * otherwise.
  640. */
  641. int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
  642. unsigned long intparm, u8 lpm, int expires)
  643. {
  644. return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
  645. PAGE_DEFAULT_KEY, expires);
  646. }
  647. EXPORT_SYMBOL(ccw_device_tm_start_timeout);
  648. /**
  649. * ccw_device_get_mdc - accumulate max data count
  650. * @cdev: ccw device for which the max data count is accumulated
  651. * @mask: mask of paths to use
  652. *
  653. * Return the number of 64K-bytes blocks all paths at least support
  654. * for a transport command. Return values <= 0 indicate failures.
  655. */
  656. int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)
  657. {
  658. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  659. struct channel_path_desc_fmt1 desc;
  660. struct chp_id chpid;
  661. int mdc = 0, ret, i;
  662. /* Adjust requested path mask to excluded varied off paths. */
  663. if (mask)
  664. mask &= sch->lpm;
  665. else
  666. mask = sch->lpm;
  667. chp_id_init(&chpid);
  668. for (i = 0; i < 8; i++) {
  669. if (!(mask & (0x80 >> i)))
  670. continue;
  671. chpid.id = sch->schib.pmcw.chpid[i];
  672. ret = chsc_determine_fmt1_channel_path_desc(chpid, &desc);
  673. if (ret)
  674. return ret;
  675. if (!desc.f)
  676. return 0;
  677. if (!desc.r)
  678. mdc = 1;
  679. mdc = mdc ? min(mdc, (int)desc.mdc) : desc.mdc;
  680. }
  681. return mdc;
  682. }
  683. EXPORT_SYMBOL(ccw_device_get_mdc);
  684. /**
  685. * ccw_device_tm_intrg - perform interrogate function
  686. * @cdev: ccw device on which to perform the interrogate function
  687. *
  688. * Perform an interrogate function on the given ccw device. Return zero on
  689. * success, non-zero otherwise.
  690. */
  691. int ccw_device_tm_intrg(struct ccw_device *cdev)
  692. {
  693. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  694. if (!sch->schib.pmcw.ena)
  695. return -EINVAL;
  696. if (cdev->private->state != DEV_STATE_ONLINE)
  697. return -EIO;
  698. if (!scsw_is_tm(&sch->schib.scsw) ||
  699. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND))
  700. return -EINVAL;
  701. return cio_tm_intrg(sch);
  702. }
  703. EXPORT_SYMBOL(ccw_device_tm_intrg);
  704. // FIXME: these have to go:
  705. int
  706. _ccw_device_get_subchannel_number(struct ccw_device *cdev)
  707. {
  708. return cdev->private->schid.sch_no;
  709. }
  710. MODULE_LICENSE("GPL");
  711. EXPORT_SYMBOL(ccw_device_set_options_mask);
  712. EXPORT_SYMBOL(ccw_device_set_options);
  713. EXPORT_SYMBOL(ccw_device_clear_options);
  714. EXPORT_SYMBOL(ccw_device_clear);
  715. EXPORT_SYMBOL(ccw_device_halt);
  716. EXPORT_SYMBOL(ccw_device_resume);
  717. EXPORT_SYMBOL(ccw_device_start_timeout);
  718. EXPORT_SYMBOL(ccw_device_start);
  719. EXPORT_SYMBOL(ccw_device_start_timeout_key);
  720. EXPORT_SYMBOL(ccw_device_start_key);
  721. EXPORT_SYMBOL(ccw_device_get_ciw);
  722. EXPORT_SYMBOL(ccw_device_get_path_mask);
  723. EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
  724. EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);