mic_common.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. * @h2c_config_db: Host to Card Virtio config doorbell set by card
  74. * @node_id: Unique id of the node
  75. * @h2c_scif_db - Host to card SCIF doorbell set by card
  76. * @c2h_scif_db - Card to host SCIF doorbell set by host
  77. * @scif_host_dma_addr - SCIF host queue pair DMA address
  78. * @scif_card_dma_addr - SCIF card queue pair DMA address
  79. */
  80. struct mic_bootparam {
  81. __le32 magic;
  82. __s8 h2c_config_db;
  83. __u8 node_id;
  84. __u8 h2c_scif_db;
  85. __u8 c2h_scif_db;
  86. __u64 scif_host_dma_addr;
  87. __u64 scif_card_dma_addr;
  88. } __attribute__ ((aligned(8)));
  89. /**
  90. * struct mic_device_page: High level representation of the device page
  91. *
  92. * @bootparam: The bootparam structure is used for sharing information and
  93. * status updates between MIC host and card drivers.
  94. * @desc: Array of MIC virtio device descriptors.
  95. */
  96. struct mic_device_page {
  97. struct mic_bootparam bootparam;
  98. struct mic_device_desc desc[0];
  99. };
  100. /**
  101. * struct mic_vqconfig: This is how we expect the device configuration field
  102. * for a virtqueue to be laid out in config space.
  103. *
  104. * @address: Guest/MIC physical address of the virtio ring
  105. * (avail and desc rings)
  106. * @used_address: Guest/MIC physical address of the used ring
  107. * @num: The number of entries in the virtio_ring
  108. */
  109. struct mic_vqconfig {
  110. __le64 address;
  111. __le64 used_address;
  112. __le16 num;
  113. } __attribute__ ((aligned(8)));
  114. /*
  115. * The alignment to use between consumer and producer parts of vring.
  116. * This is pagesize for historical reasons.
  117. */
  118. #define MIC_VIRTIO_RING_ALIGN 4096
  119. #define MIC_MAX_VRINGS 4
  120. #define MIC_VRING_ENTRIES 128
  121. /*
  122. * Max vring entries (power of 2) to ensure desc and avail rings
  123. * fit in a single page
  124. */
  125. #define MIC_MAX_VRING_ENTRIES 128
  126. /**
  127. * Max size of the desc block in bytes: includes:
  128. * - struct mic_device_desc
  129. * - struct mic_vqconfig (num_vq of these)
  130. * - host and guest features
  131. * - virtio device config space
  132. */
  133. #define MIC_MAX_DESC_BLK_SIZE 256
  134. /**
  135. * struct _mic_vring_info - Host vring info exposed to userspace backend
  136. * for the avail index and magic for the card.
  137. *
  138. * @avail_idx: host avail idx
  139. * @magic: A magic debug cookie.
  140. */
  141. struct _mic_vring_info {
  142. __u16 avail_idx;
  143. __le32 magic;
  144. };
  145. /**
  146. * struct mic_vring - Vring information.
  147. *
  148. * @vr: The virtio ring.
  149. * @info: Host vring information exposed to the userspace backend for the
  150. * avail index and magic for the card.
  151. * @va: The va for the buffer allocated for vr and info.
  152. * @len: The length of the buffer required for allocating vr and info.
  153. */
  154. struct mic_vring {
  155. struct vring vr;
  156. struct _mic_vring_info *info;
  157. void *va;
  158. int len;
  159. };
  160. #define mic_aligned_desc_size(d) __mic_align(mic_desc_size(d), 8)
  161. #ifndef INTEL_MIC_CARD
  162. static __inline__ unsigned mic_desc_size(const struct mic_device_desc *desc)
  163. {
  164. return sizeof(*desc) + desc->num_vq * sizeof(struct mic_vqconfig)
  165. + desc->feature_len * 2 + desc->config_len;
  166. }
  167. static __inline__ struct mic_vqconfig *
  168. mic_vq_config(const struct mic_device_desc *desc)
  169. {
  170. return (struct mic_vqconfig *)(desc + 1);
  171. }
  172. static __inline__ __u8 *mic_vq_features(const struct mic_device_desc *desc)
  173. {
  174. return (__u8 *)(mic_vq_config(desc) + desc->num_vq);
  175. }
  176. static __inline__ __u8 *mic_vq_configspace(const struct mic_device_desc *desc)
  177. {
  178. return mic_vq_features(desc) + desc->feature_len * 2;
  179. }
  180. static __inline__ unsigned mic_total_desc_size(struct mic_device_desc *desc)
  181. {
  182. return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
  183. }
  184. #endif
  185. /* Device page size */
  186. #define MIC_DP_SIZE 4096
  187. #define MIC_MAGIC 0xc0ffee00
  188. /**
  189. * enum mic_states - MIC states.
  190. */
  191. enum mic_states {
  192. MIC_READY = 0,
  193. MIC_BOOTING,
  194. MIC_ONLINE,
  195. MIC_SHUTTING_DOWN,
  196. MIC_RESETTING,
  197. MIC_RESET_FAILED,
  198. MIC_LAST
  199. };
  200. /**
  201. * enum mic_status - MIC status reported by card after
  202. * a host or card initiated shutdown or a card crash.
  203. */
  204. enum mic_status {
  205. MIC_NOP = 0,
  206. MIC_CRASHED,
  207. MIC_HALTED,
  208. MIC_POWER_OFF,
  209. MIC_RESTART,
  210. MIC_STATUS_LAST
  211. };
  212. #endif