You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #ifndef _GPXE_INFINIBAND_H
  2. #define _GPXE_INFINIBAND_H
  3. /** @file
  4. *
  5. * Infiniband protocol
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/netdevice.h>
  10. /** An Infiniband Global Identifier */
  11. struct ib_gid {
  12. uint8_t bytes[16];
  13. };
  14. /** An Infiniband Global Route Header */
  15. struct ib_global_route_header {
  16. /** IP version, traffic class, and flow label
  17. *
  18. * 4 bits : Version of the GRH
  19. * 8 bits : Traffic class
  20. * 20 bits : Flow label
  21. */
  22. uint32_t ipver_tclass_flowlabel;
  23. /** Payload length */
  24. uint16_t paylen;
  25. /** Next header */
  26. uint8_t nxthdr;
  27. /** Hop limit */
  28. uint8_t hoplmt;
  29. /** Source GID */
  30. struct ib_gid sgid;
  31. /** Destiniation GID */
  32. struct ib_gid dgid;
  33. } __attribute__ (( packed ));
  34. /** Infiniband MAC address length */
  35. #define IB_ALEN 20
  36. /** An Infiniband MAC address */
  37. struct ib_mac {
  38. /** Queue pair number
  39. *
  40. * MSB must be zero; QPNs are only 24-bit.
  41. */
  42. uint32_t qpn;
  43. /** Port GID */
  44. struct ib_gid gid;
  45. } __attribute__ (( packed ));
  46. /** Infiniband link-layer header length */
  47. #define IB_HLEN 4
  48. /** An Infiniband link-layer header */
  49. struct ibhdr {
  50. /** Network-layer protocol */
  51. uint16_t proto;
  52. /** Reserved, must be zero */
  53. uint16_t reserved;
  54. } __attribute__ (( packed ));
  55. struct ib_device;
  56. struct ib_queue_pair;
  57. struct ib_completion_queue;
  58. /** An Infiniband Work Queue */
  59. struct ib_work_queue {
  60. /** Containing queue pair */
  61. struct ib_queue_pair *qp;
  62. /** "Is a send queue" flag */
  63. int is_send;
  64. /** Associated completion queue */
  65. struct ib_completion_queue *cq;
  66. /** List of work queues on this completion queue */
  67. struct list_head list;
  68. /** Number of work queue entries */
  69. unsigned int num_wqes;
  70. /** Next work queue entry index
  71. *
  72. * This is the index of the next entry to be filled (i.e. the
  73. * first empty entry). This value is not bounded by num_wqes;
  74. * users must logical-AND with (num_wqes-1) to generate an
  75. * array index.
  76. */
  77. unsigned long next_idx;
  78. /** I/O buffers assigned to work queue */
  79. struct io_buffer **iobufs;
  80. };
  81. /** An Infiniband Queue Pair */
  82. struct ib_queue_pair {
  83. /** Queue Pair Number */
  84. unsigned long qpn;
  85. /** Send queue */
  86. struct ib_work_queue send;
  87. /** Receive queue */
  88. struct ib_work_queue recv;
  89. /** Queue owner private data */
  90. void *priv;
  91. };
  92. /** An Infiniband Completion Queue */
  93. struct ib_completion_queue {
  94. /** Completion queue number */
  95. unsigned long cqn;
  96. /** Number of completion queue entries */
  97. unsigned int num_cqes;
  98. /** Next completion queue entry index
  99. *
  100. * This is the index of the next entry to be filled (i.e. the
  101. * first empty entry). This value is not bounded by num_wqes;
  102. * users must logical-AND with (num_wqes-1) to generate an
  103. * array index.
  104. */
  105. unsigned long next_idx;
  106. /** List of work queues completing to this queue */
  107. struct list_head work_queues;
  108. };
  109. /** An Infiniband completion */
  110. struct ib_completion {
  111. /** Syndrome
  112. *
  113. * If non-zero, then the completion is in error.
  114. */
  115. unsigned int syndrome;
  116. /** Length */
  117. size_t len;
  118. };
  119. /** An Infiniband completion handler
  120. *
  121. * @v ibdev Infiniband device
  122. * @v qp Queue pair
  123. * @v completion Completion
  124. * @v iobuf I/O buffer
  125. */
  126. typedef void ( * ib_completer_t ) ( struct ib_device *ibdev,
  127. struct ib_queue_pair *qp,
  128. struct ib_completion *completion,
  129. struct io_buffer *iobuf );
  130. /** An Infiniband Address Vector */
  131. struct ib_address_vector {
  132. /** Destination Queue Pair */
  133. unsigned int dest_qp;
  134. /** Queue key */
  135. unsigned int qkey;
  136. /** Destination Local ID */
  137. unsigned int dlid;
  138. /** Rate */
  139. unsigned int rate;
  140. /** Service level */
  141. unsigned int sl;
  142. /** GID is present */
  143. unsigned int gid_present;
  144. /** GID */
  145. struct ib_gid gid;
  146. };
  147. /**
  148. * Infiniband device operations
  149. *
  150. * These represent a subset of the Infiniband Verbs.
  151. */
  152. struct ib_device_operations {
  153. /**
  154. * Create completion queue
  155. *
  156. * @v ibdev Infiniband device
  157. * @v log2_num_cqes Log2 of the number of completion queue entries
  158. * @ret new_cq New completion queue
  159. * @ret rc Return status code
  160. */
  161. int ( * create_cq ) ( struct ib_device *ibdev,
  162. unsigned int log2_num_cqes,
  163. struct ib_completion_queue **new_cq );
  164. /**
  165. * Destroy completion queue
  166. *
  167. * @v ibdev Infiniband device
  168. * @v cq Completion queue
  169. */
  170. void ( * destroy_cq ) ( struct ib_device *ibdev,
  171. struct ib_completion_queue *cq );
  172. /** Post send work queue entry
  173. *
  174. * @v ibdev Infiniband device
  175. * @v qp Queue pair
  176. * @v av Address vector
  177. * @v iobuf I/O buffer
  178. * @ret rc Return status code
  179. *
  180. * If this method returns success, the I/O buffer remains
  181. * owned by the queue pair. If this method returns failure,
  182. * the I/O buffer is immediately released; the failure is
  183. * interpreted as "failure to enqueue buffer".
  184. */
  185. int ( * post_send ) ( struct ib_device *ibdev,
  186. struct ib_queue_pair *qp,
  187. struct ib_address_vector *av,
  188. struct io_buffer *iobuf );
  189. /**
  190. * Post receive work queue entry
  191. *
  192. * @v ibdev Infiniband device
  193. * @v qp Queue pair
  194. * @v iobuf I/O buffer
  195. * @ret rc Return status code
  196. *
  197. * If this method returns success, the I/O buffer remains
  198. * owned by the queue pair. If this method returns failure,
  199. * the I/O buffer is immediately released; the failure is
  200. * interpreted as "failure to enqueue buffer".
  201. */
  202. int ( * post_recv ) ( struct ib_device *ibdev,
  203. struct ib_queue_pair *qp,
  204. struct io_buffer *iobuf );
  205. /** Poll completion queue
  206. *
  207. * @v ibdev Infiniband device
  208. * @v cq Completion queue
  209. * @v complete_send Send completion handler
  210. * @v complete_recv Receive completion handler
  211. *
  212. * The completion handler takes ownership of the I/O buffer.
  213. */
  214. void ( * poll_cq ) ( struct ib_device *ibdev,
  215. struct ib_completion_queue *cq,
  216. ib_completer_t complete_send,
  217. ib_completer_t complete_recv );
  218. };
  219. /** An Infiniband device */
  220. struct ib_device {
  221. /** Driver private data */
  222. void *priv;
  223. };
  224. extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
  225. unsigned long qpn, int is_send );
  226. extern struct ll_protocol infiniband_protocol;
  227. extern const char * ib_ntoa ( const void *ll_addr );
  228. /**
  229. * Allocate Infiniband device
  230. *
  231. * @v priv_size Size of driver private data
  232. * @ret netdev Network device, or NULL
  233. */
  234. static inline struct net_device * alloc_ibdev ( size_t priv_size ) {
  235. struct net_device *netdev;
  236. netdev = alloc_netdev ( priv_size );
  237. if ( netdev ) {
  238. netdev->ll_protocol = &infiniband_protocol;
  239. }
  240. return netdev;
  241. }
  242. #endif /* _GPXE_INFINIBAND_H */