mic_common.h 6.7 KB

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