vop_main.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Intel Virtio Over PCIe (VOP) driver.
  19. *
  20. */
  21. #ifndef _VOP_MAIN_H_
  22. #define _VOP_MAIN_H_
  23. #include <linux/vringh.h>
  24. #include <linux/virtio_config.h>
  25. #include <linux/virtio.h>
  26. #include <linux/miscdevice.h>
  27. #include <linux/mic_common.h>
  28. #include "../common/mic_dev.h"
  29. #include "../bus/vop_bus.h"
  30. /*
  31. * Note on endianness.
  32. * 1. Host can be both BE or LE
  33. * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
  34. * rings and ioreadXX/iowriteXX to access used ring.
  35. * 3. Device page exposed by host to guest contains LE values. Guest
  36. * accesses these using ioreadXX/iowriteXX etc. This way in general we
  37. * obey the virtio spec according to which guest works with native
  38. * endianness and host is aware of guest endianness and does all
  39. * required endianness conversion.
  40. * 4. Data provided from user space to guest (in ADD_DEVICE and
  41. * CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
  42. * in guest endianness.
  43. */
  44. /*
  45. * vop_info - Allocated per invocation of VOP probe
  46. *
  47. * @vpdev: VOP device
  48. * @hotplug_work: Handle virtio device creation, deletion and configuration
  49. * @cookie: Cookie received upon requesting a virtio configuration interrupt
  50. * @h2c_config_db: The doorbell used by the peer to indicate a config change
  51. * @vdev_list: List of "active" virtio devices injected in the peer node
  52. * @vop_mutex: Synchronize access to the device page as well as serialize
  53. * creation/deletion of virtio devices on the peer node
  54. * @dp: Peer device page information
  55. * @dbg: Debugfs entry
  56. * @dma_ch: The DMA channel used by this transport for data transfers.
  57. * @name: Name for this transport used in misc device creation.
  58. * @miscdev: The misc device registered.
  59. */
  60. struct vop_info {
  61. struct vop_device *vpdev;
  62. struct work_struct hotplug_work;
  63. struct mic_irq *cookie;
  64. int h2c_config_db;
  65. struct list_head vdev_list;
  66. struct mutex vop_mutex;
  67. void __iomem *dp;
  68. struct dentry *dbg;
  69. struct dma_chan *dma_ch;
  70. char name[16];
  71. struct miscdevice miscdev;
  72. };
  73. /**
  74. * struct vop_vringh - Virtio ring host information.
  75. *
  76. * @vring: The VOP vring used for setting up user space mappings.
  77. * @vrh: The host VRINGH used for accessing the card vrings.
  78. * @riov: The VRINGH read kernel IOV.
  79. * @wiov: The VRINGH write kernel IOV.
  80. * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
  81. * @vr_mutex: Mutex for synchronizing access to the VRING.
  82. * @buf: Temporary kernel buffer used to copy in/out data
  83. * from/to the card via DMA.
  84. * @buf_da: dma address of buf.
  85. * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
  86. */
  87. struct vop_vringh {
  88. struct mic_vring vring;
  89. struct vringh vrh;
  90. struct vringh_kiov riov;
  91. struct vringh_kiov wiov;
  92. u16 head;
  93. struct mutex vr_mutex;
  94. void *buf;
  95. dma_addr_t buf_da;
  96. struct vop_vdev *vdev;
  97. };
  98. /**
  99. * struct vop_vdev - Host information for a card Virtio device.
  100. *
  101. * @virtio_id - Virtio device id.
  102. * @waitq - Waitqueue to allow ring3 apps to poll.
  103. * @vpdev - pointer to VOP bus device.
  104. * @poll_wake - Used for waking up threads blocked in poll.
  105. * @out_bytes - Debug stats for number of bytes copied from host to card.
  106. * @in_bytes - Debug stats for number of bytes copied from card to host.
  107. * @out_bytes_dma - Debug stats for number of bytes copied from host to card
  108. * using DMA.
  109. * @in_bytes_dma - Debug stats for number of bytes copied from card to host
  110. * using DMA.
  111. * @tx_len_unaligned - Debug stats for number of bytes copied to the card where
  112. * the transfer length did not have the required DMA alignment.
  113. * @tx_dst_unaligned - Debug stats for number of bytes copied where the
  114. * destination address on the card did not have the required DMA alignment.
  115. * @vvr - Store per VRING data structures.
  116. * @virtio_bh_work - Work struct used to schedule virtio bottom half handling.
  117. * @dd - Virtio device descriptor.
  118. * @dc - Virtio device control fields.
  119. * @list - List of Virtio devices.
  120. * @virtio_db - The doorbell used by the card to interrupt the host.
  121. * @virtio_cookie - The cookie returned while requesting interrupts.
  122. * @vi: Transport information.
  123. * @vdev_mutex: Mutex synchronizing virtio device injection,
  124. * removal and data transfers.
  125. * @destroy: Track if a virtio device is being destroyed.
  126. * @deleted: The virtio device has been deleted.
  127. */
  128. struct vop_vdev {
  129. int virtio_id;
  130. wait_queue_head_t waitq;
  131. struct vop_device *vpdev;
  132. int poll_wake;
  133. unsigned long out_bytes;
  134. unsigned long in_bytes;
  135. unsigned long out_bytes_dma;
  136. unsigned long in_bytes_dma;
  137. unsigned long tx_len_unaligned;
  138. unsigned long tx_dst_unaligned;
  139. unsigned long rx_dst_unaligned;
  140. struct vop_vringh vvr[MIC_MAX_VRINGS];
  141. struct work_struct virtio_bh_work;
  142. struct mic_device_desc *dd;
  143. struct mic_device_ctrl *dc;
  144. struct list_head list;
  145. int virtio_db;
  146. struct mic_irq *virtio_cookie;
  147. struct vop_info *vi;
  148. struct mutex vdev_mutex;
  149. struct completion destroy;
  150. bool deleted;
  151. };
  152. /* Helper API to check if a virtio device is running */
  153. static inline bool vop_vdevup(struct vop_vdev *vdev)
  154. {
  155. return !!vdev->dd->status;
  156. }
  157. void vop_init_debugfs(struct vop_info *vi);
  158. void vop_exit_debugfs(struct vop_info *vi);
  159. int vop_host_init(struct vop_info *vi);
  160. void vop_host_uninit(struct vop_info *vi);
  161. #endif