vfio_ccw_private.h 2.3 KB

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