vfio_ccw_private.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Private stuff for vfio_ccw driver
  4. *
  5. * Copyright IBM Corp. 2017
  6. *
  7. * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
  8. * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
  9. */
  10. #ifndef _VFIO_CCW_PRIVATE_H_
  11. #define _VFIO_CCW_PRIVATE_H_
  12. #include <linux/completion.h>
  13. #include <linux/eventfd.h>
  14. #include <linux/workqueue.h>
  15. #include <linux/vfio_ccw.h>
  16. #include "css.h"
  17. #include "vfio_ccw_cp.h"
  18. /**
  19. * struct vfio_ccw_private
  20. * @sch: pointer to the subchannel
  21. * @state: internal state of the device
  22. * @completion: synchronization helper of the I/O completion
  23. * @avail: available for creating a mediated device
  24. * @mdev: pointer to the mediated device
  25. * @nb: notifier for vfio events
  26. * @io_region: MMIO region to input/output I/O arguments/results
  27. * @cp: channel program for the current I/O operation
  28. * @irb: irb info received from interrupt
  29. * @scsw: scsw info
  30. * @io_trigger: eventfd ctx for signaling userspace I/O results
  31. * @io_work: work for deferral process of I/O handling
  32. */
  33. struct vfio_ccw_private {
  34. struct subchannel *sch;
  35. int state;
  36. struct completion *completion;
  37. atomic_t avail;
  38. struct mdev_device *mdev;
  39. struct notifier_block nb;
  40. struct ccw_io_region *io_region;
  41. struct channel_program cp;
  42. struct irb irb;
  43. union scsw scsw;
  44. struct eventfd_ctx *io_trigger;
  45. struct work_struct io_work;
  46. } __aligned(8);
  47. extern int vfio_ccw_mdev_reg(struct subchannel *sch);
  48. extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
  49. extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
  50. /*
  51. * States of the device statemachine.
  52. */
  53. enum vfio_ccw_state {
  54. VFIO_CCW_STATE_NOT_OPER,
  55. VFIO_CCW_STATE_STANDBY,
  56. VFIO_CCW_STATE_IDLE,
  57. VFIO_CCW_STATE_BOXED,
  58. VFIO_CCW_STATE_BUSY,
  59. /* last element! */
  60. NR_VFIO_CCW_STATES
  61. };
  62. /*
  63. * Asynchronous events of the device statemachine.
  64. */
  65. enum vfio_ccw_event {
  66. VFIO_CCW_EVENT_NOT_OPER,
  67. VFIO_CCW_EVENT_IO_REQ,
  68. VFIO_CCW_EVENT_INTERRUPT,
  69. /* last element! */
  70. NR_VFIO_CCW_EVENTS
  71. };
  72. /*
  73. * Action called through jumptable.
  74. */
  75. typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event);
  76. extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS];
  77. static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
  78. int event)
  79. {
  80. vfio_ccw_jumptable[private->state][event](private, event);
  81. }
  82. extern struct workqueue_struct *vfio_ccw_work_q;
  83. #endif