vfio_ccw_private.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Private stuff for vfio_ccw driver
  4. *
  5. * Copyright IBM Corp. 2017
  6. * Copyright Red Hat, Inc. 2019
  7. *
  8. * Author(s): Dong Jia Shi <[email protected]>
  9. * Xiao Feng Ren <[email protected]>
  10. * Cornelia Huck <[email protected]>
  11. */
  12. #ifndef _VFIO_CCW_PRIVATE_H_
  13. #define _VFIO_CCW_PRIVATE_H_
  14. #include <linux/completion.h>
  15. #include <linux/eventfd.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/vfio_ccw.h>
  18. #include <linux/vfio.h>
  19. #include <linux/mdev.h>
  20. #include <asm/crw.h>
  21. #include <asm/debug.h>
  22. #include "css.h"
  23. #include "vfio_ccw_cp.h"
  24. #define VFIO_CCW_OFFSET_SHIFT 10
  25. #define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT)
  26. #define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT)
  27. #define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1)
  28. /* capability chain handling similar to vfio-pci */
  29. struct vfio_ccw_private;
  30. struct vfio_ccw_region;
  31. struct vfio_ccw_regops {
  32. ssize_t (*read)(struct vfio_ccw_private *private, char __user *buf,
  33. size_t count, loff_t *ppos);
  34. ssize_t (*write)(struct vfio_ccw_private *private,
  35. const char __user *buf, size_t count, loff_t *ppos);
  36. void (*release)(struct vfio_ccw_private *private,
  37. struct vfio_ccw_region *region);
  38. };
  39. struct vfio_ccw_region {
  40. u32 type;
  41. u32 subtype;
  42. const struct vfio_ccw_regops *ops;
  43. void *data;
  44. size_t size;
  45. u32 flags;
  46. };
  47. int vfio_ccw_register_dev_region(struct vfio_ccw_private *private,
  48. unsigned int subtype,
  49. const struct vfio_ccw_regops *ops,
  50. size_t size, u32 flags, void *data);
  51. void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private);
  52. int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private);
  53. int vfio_ccw_register_schib_dev_regions(struct vfio_ccw_private *private);
  54. int vfio_ccw_register_crw_dev_regions(struct vfio_ccw_private *private);
  55. struct vfio_ccw_crw {
  56. struct list_head next;
  57. struct crw crw;
  58. };
  59. /**
  60. * struct vfio_ccw_private
  61. * @vdev: Embedded VFIO device
  62. * @sch: pointer to the subchannel
  63. * @state: internal state of the device
  64. * @completion: synchronization helper of the I/O completion
  65. * @io_region: MMIO region to input/output I/O arguments/results
  66. * @io_mutex: protect against concurrent update of I/O regions
  67. * @region: additional regions for other subchannel operations
  68. * @cmd_region: MMIO region for asynchronous I/O commands other than START
  69. * @schib_region: MMIO region for SCHIB information
  70. * @crw_region: MMIO region for getting channel report words
  71. * @num_regions: number of additional regions
  72. * @cp: channel program for the current I/O operation
  73. * @irb: irb info received from interrupt
  74. * @scsw: scsw info
  75. * @io_trigger: eventfd ctx for signaling userspace I/O results
  76. * @crw_trigger: eventfd ctx for signaling userspace CRW information
  77. * @req_trigger: eventfd ctx for signaling userspace to return device
  78. * @io_work: work for deferral process of I/O handling
  79. * @crw_work: work for deferral process of CRW handling
  80. * @release_comp: synchronization helper for vfio device release
  81. * @parent: parent data structures for mdevs created
  82. */
  83. struct vfio_ccw_private {
  84. struct vfio_device vdev;
  85. struct subchannel *sch;
  86. int state;
  87. struct completion *completion;
  88. struct ccw_io_region *io_region;
  89. struct mutex io_mutex;
  90. struct vfio_ccw_region *region;
  91. struct ccw_cmd_region *cmd_region;
  92. struct ccw_schib_region *schib_region;
  93. struct ccw_crw_region *crw_region;
  94. int num_regions;
  95. struct channel_program cp;
  96. struct irb irb;
  97. union scsw scsw;
  98. struct list_head crw;
  99. struct eventfd_ctx *io_trigger;
  100. struct eventfd_ctx *crw_trigger;
  101. struct eventfd_ctx *req_trigger;
  102. struct work_struct io_work;
  103. struct work_struct crw_work;
  104. struct completion release_comp;
  105. struct mdev_parent parent;
  106. struct mdev_type mdev_type;
  107. struct mdev_type *mdev_types[1];
  108. } __aligned(8);
  109. int vfio_ccw_sch_quiesce(struct subchannel *sch);
  110. extern struct mdev_driver vfio_ccw_mdev_driver;
  111. /*
  112. * States of the device statemachine.
  113. */
  114. enum vfio_ccw_state {
  115. VFIO_CCW_STATE_NOT_OPER,
  116. VFIO_CCW_STATE_STANDBY,
  117. VFIO_CCW_STATE_IDLE,
  118. VFIO_CCW_STATE_CP_PROCESSING,
  119. VFIO_CCW_STATE_CP_PENDING,
  120. /* last element! */
  121. NR_VFIO_CCW_STATES
  122. };
  123. /*
  124. * Asynchronous events of the device statemachine.
  125. */
  126. enum vfio_ccw_event {
  127. VFIO_CCW_EVENT_NOT_OPER,
  128. VFIO_CCW_EVENT_IO_REQ,
  129. VFIO_CCW_EVENT_INTERRUPT,
  130. VFIO_CCW_EVENT_ASYNC_REQ,
  131. VFIO_CCW_EVENT_OPEN,
  132. VFIO_CCW_EVENT_CLOSE,
  133. /* last element! */
  134. NR_VFIO_CCW_EVENTS
  135. };
  136. /*
  137. * Action called through jumptable.
  138. */
  139. typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event);
  140. extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS];
  141. static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
  142. enum vfio_ccw_event event)
  143. {
  144. trace_vfio_ccw_fsm_event(private->sch->schid, private->state, event);
  145. vfio_ccw_jumptable[private->state][event](private, event);
  146. }
  147. extern struct workqueue_struct *vfio_ccw_work_q;
  148. /* s390 debug feature, similar to base cio */
  149. extern debug_info_t *vfio_ccw_debug_msg_id;
  150. extern debug_info_t *vfio_ccw_debug_trace_id;
  151. #define VFIO_CCW_TRACE_EVENT(imp, txt) \
  152. debug_text_event(vfio_ccw_debug_trace_id, imp, txt)
  153. #define VFIO_CCW_MSG_EVENT(imp, args...) \
  154. debug_sprintf_event(vfio_ccw_debug_msg_id, imp, ##args)
  155. static inline void VFIO_CCW_HEX_EVENT(int level, void *data, int length)
  156. {
  157. debug_event(vfio_ccw_debug_trace_id, level, data, length);
  158. }
  159. #endif