mic_common.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2013 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 MIC driver.
  19. *
  20. */
  21. #ifndef __MIC_COMMON_H_
  22. #define __MIC_COMMON_H_
  23. #include <linux/virtio_ring.h>
  24. #define __mic_align(a, x) (((a) + (x) - 1) & ~((x) - 1))
  25. /**
  26. * struct mic_device_desc: Virtio device information shared between the
  27. * virtio driver and userspace backend
  28. *
  29. * @type: Device type: console/network/disk etc. Type 0/-1 terminates.
  30. * @num_vq: Number of virtqueues.
  31. * @feature_len: Number of bytes of feature bits. Multiply by 2: one for
  32. host features and one for guest acknowledgements.
  33. * @config_len: Number of bytes of the config array after virtqueues.
  34. * @status: A status byte, written by the Guest.
  35. * @config: Start of the following variable length config.
  36. */
  37. struct mic_device_desc {
  38. __s8 type;
  39. __u8 num_vq;
  40. __u8 feature_len;
  41. __u8 config_len;
  42. __u8 status;
  43. __le64 config[0];
  44. } __attribute__ ((aligned(8)));
  45. /**
  46. * struct mic_device_ctrl: Per virtio device information in the device page
  47. * used internally by the host and card side drivers.
  48. *
  49. * @vdev: Used for storing MIC vdev information by the guest.
  50. * @config_change: Set to 1 by host when a config change is requested.
  51. * @vdev_reset: Set to 1 by guest to indicate virtio device has been reset.
  52. * @guest_ack: Set to 1 by guest to ack a command.
  53. * @host_ack: Set to 1 by host to ack a command.
  54. * @used_address_updated: Set to 1 by guest when the used address should be
  55. * updated.
  56. * @c2h_vdev_db: The doorbell number to be used by guest. Set by host.
  57. * @h2c_vdev_db: The doorbell number to be used by host. Set by guest.
  58. */
  59. struct mic_device_ctrl {
  60. __le64 vdev;
  61. __u8 config_change;
  62. __u8 vdev_reset;
  63. __u8 guest_ack;
  64. __u8 host_ack;
  65. __u8 used_address_updated;
  66. __s8 c2h_vdev_db;
  67. __s8 h2c_vdev_db;
  68. } __attribute__ ((aligned(8)));
  69. /**
  70. * struct mic_bootparam: Virtio device independent information in device page
  71. *
  72. * @magic: A magic value used by the card to ensure it can see the host
  73. * @c2h_shutdown_db: Card to Host shutdown doorbell set by host
  74. * @h2c_shutdown_db: Host to Card shutdown doorbell set by card
  75. * @h2c_config_db: Host to Card Virtio config doorbell set by card
  76. * @shutdown_status: Card shutdown status set by card
  77. * @shutdown_card: Set to 1 by the host when a card shutdown is initiated
  78. */
  79. struct mic_bootparam {
  80. __le32 magic;
  81. __s8 c2h_shutdown_db;
  82. __s8 h2c_shutdown_db;
  83. __s8 h2c_config_db;
  84. __u8 shutdown_status;
  85. __u8 shutdown_card;
  86. } __attribute__ ((aligned(8)));
  87. /**
  88. * struct mic_device_page: High level representation of the device page
  89. *
  90. * @bootparam: The bootparam structure is used for sharing information and
  91. * status updates between MIC host and card drivers.
  92. * @desc: Array of MIC virtio device descriptors.
  93. */
  94. struct mic_device_page {
  95. struct mic_bootparam bootparam;
  96. struct mic_device_desc desc[0];
  97. };
  98. /**
  99. * struct mic_vqconfig: This is how we expect the device configuration field
  100. * for a virtqueue to be laid out in config space.
  101. *
  102. * @address: Guest/MIC physical address of the virtio ring
  103. * (avail and desc rings)
  104. * @used_address: Guest/MIC physical address of the used ring
  105. * @num: The number of entries in the virtio_ring
  106. */
  107. struct mic_vqconfig {
  108. __le64 address;
  109. __le64 used_address;
  110. __le16 num;
  111. } __attribute__ ((aligned(8)));
  112. /*
  113. * The alignment to use between consumer and producer parts of vring.
  114. * This is pagesize for historical reasons.
  115. */
  116. #define MIC_VIRTIO_RING_ALIGN 4096
  117. #define MIC_MAX_VRINGS 4
  118. #define MIC_VRING_ENTRIES 128
  119. /*
  120. * Max vring entries (power of 2) to ensure desc and avail rings
  121. * fit in a single page
  122. */
  123. #define MIC_MAX_VRING_ENTRIES 128
  124. /**
  125. * Max size of the desc block in bytes: includes:
  126. * - struct mic_device_desc
  127. * - struct mic_vqconfig (num_vq of these)
  128. * - host and guest features
  129. * - virtio device config space
  130. */
  131. #define MIC_MAX_DESC_BLK_SIZE 256
  132. /**
  133. * struct _mic_vring_info - Host vring info exposed to userspace backend
  134. * for the avail index and magic for the card.
  135. *
  136. * @avail_idx: host avail idx
  137. * @magic: A magic debug cookie.
  138. */
  139. struct _mic_vring_info {
  140. __u16 avail_idx;
  141. __le32 magic;
  142. };
  143. /**
  144. * struct mic_vring - Vring information.
  145. *
  146. * @vr: The virtio ring.
  147. * @info: Host vring information exposed to the userspace backend for the
  148. * avail index and magic for the card.
  149. * @va: The va for the buffer allocated for vr and info.
  150. * @len: The length of the buffer required for allocating vr and info.
  151. */
  152. struct mic_vring {
  153. struct vring vr;
  154. struct _mic_vring_info *info;
  155. void *va;
  156. int len;
  157. };
  158. #define mic_aligned_desc_size(d) __mic_align(mic_desc_size(d), 8)
  159. #ifndef INTEL_MIC_CARD
  160. static inline unsigned mic_desc_size(const struct mic_device_desc *desc)
  161. {
  162. return sizeof(*desc) + desc->num_vq * sizeof(struct mic_vqconfig)
  163. + desc->feature_len * 2 + desc->config_len;
  164. }
  165. static inline struct mic_vqconfig *
  166. mic_vq_config(const struct mic_device_desc *desc)
  167. {
  168. return (struct mic_vqconfig *)(desc + 1);
  169. }
  170. static inline __u8 *mic_vq_features(const struct mic_device_desc *desc)
  171. {
  172. return (__u8 *)(mic_vq_config(desc) + desc->num_vq);
  173. }
  174. static inline __u8 *mic_vq_configspace(const struct mic_device_desc *desc)
  175. {
  176. return mic_vq_features(desc) + desc->feature_len * 2;
  177. }
  178. static inline unsigned mic_total_desc_size(struct mic_device_desc *desc)
  179. {
  180. return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
  181. }
  182. #endif
  183. /* Device page size */
  184. #define MIC_DP_SIZE 4096
  185. #define MIC_MAGIC 0xc0ffee00
  186. /**
  187. * enum mic_states - MIC states.
  188. */
  189. enum mic_states {
  190. MIC_OFFLINE = 0,
  191. MIC_ONLINE,
  192. MIC_SHUTTING_DOWN,
  193. MIC_RESET_FAILED,
  194. MIC_SUSPENDING,
  195. MIC_SUSPENDED,
  196. MIC_LAST
  197. };
  198. /**
  199. * enum mic_status - MIC status reported by card after
  200. * a host or card initiated shutdown or a card crash.
  201. */
  202. enum mic_status {
  203. MIC_NOP = 0,
  204. MIC_CRASHED,
  205. MIC_HALTED,
  206. MIC_POWER_OFF,
  207. MIC_RESTART,
  208. MIC_STATUS_LAST
  209. };
  210. #endif