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.

infiniband.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. #ifndef _GPXE_INFINIBAND_H
  2. #define _GPXE_INFINIBAND_H
  3. /** @file
  4. *
  5. * Infiniband protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <gpxe/refcnt.h>
  11. #include <gpxe/device.h>
  12. #include <gpxe/ib_packet.h>
  13. #include <gpxe/ib_mad.h>
  14. /** Subnet administrator QPN */
  15. #define IB_SA_QPN 1
  16. /** Broadcast QPN */
  17. #define IB_BROADCAST_QPN 0xffffffUL
  18. /** Subnet administrator queue key */
  19. #define IB_GLOBAL_QKEY 0x80010000UL
  20. /**
  21. * Maximum payload size
  22. *
  23. * This is currently hard-coded in various places (drivers, subnet
  24. * management agent, etc.) to 2048.
  25. */
  26. #define IB_MAX_PAYLOAD_SIZE 2048
  27. struct ib_device;
  28. struct ib_queue_pair;
  29. struct ib_address_vector;
  30. struct ib_completion_queue;
  31. /** An Infiniband Work Queue */
  32. struct ib_work_queue {
  33. /** Containing queue pair */
  34. struct ib_queue_pair *qp;
  35. /** "Is a send queue" flag */
  36. int is_send;
  37. /** Associated completion queue */
  38. struct ib_completion_queue *cq;
  39. /** List of work queues on this completion queue */
  40. struct list_head list;
  41. /** Number of work queue entries */
  42. unsigned int num_wqes;
  43. /** Number of occupied work queue entries */
  44. unsigned int fill;
  45. /** Next work queue entry index
  46. *
  47. * This is the index of the next entry to be filled (i.e. the
  48. * first empty entry). This value is not bounded by num_wqes;
  49. * users must logical-AND with (num_wqes-1) to generate an
  50. * array index.
  51. */
  52. unsigned long next_idx;
  53. /** I/O buffers assigned to work queue */
  54. struct io_buffer **iobufs;
  55. /** Driver private data */
  56. void *drv_priv;
  57. };
  58. /** An Infiniband multicast GID */
  59. struct ib_multicast_gid {
  60. /** List of multicast GIDs on this QP */
  61. struct list_head list;
  62. /** Multicast GID */
  63. struct ib_gid gid;
  64. };
  65. /** An Infiniband Queue Pair */
  66. struct ib_queue_pair {
  67. /** Containing Infiniband device */
  68. struct ib_device *ibdev;
  69. /** List of queue pairs on this Infiniband device */
  70. struct list_head list;
  71. /** Queue Pair Number */
  72. unsigned long qpn;
  73. /** Queue key */
  74. unsigned long qkey;
  75. /** Send queue */
  76. struct ib_work_queue send;
  77. /** Receive queue */
  78. struct ib_work_queue recv;
  79. /** List of multicast GIDs */
  80. struct list_head mgids;
  81. /** Driver private data */
  82. void *drv_priv;
  83. /** Queue owner private data */
  84. void *owner_priv;
  85. };
  86. /** Infiniband queue pair modification flags */
  87. enum ib_queue_pair_mods {
  88. IB_MODIFY_QKEY = 0x0001,
  89. };
  90. /** An Infiniband Address Vector */
  91. struct ib_address_vector {
  92. /** Queue Pair Number */
  93. unsigned long qpn;
  94. /** Queue key
  95. *
  96. * Not specified for received packets.
  97. */
  98. unsigned long qkey;
  99. /** Local ID */
  100. unsigned int lid;
  101. /** Rate
  102. *
  103. * Not specified for received packets.
  104. */
  105. unsigned int rate;
  106. /** Service level */
  107. unsigned int sl;
  108. /** GID is present */
  109. unsigned int gid_present;
  110. /** GID, if present */
  111. struct ib_gid gid;
  112. };
  113. /** Infiniband completion queue operations */
  114. struct ib_completion_queue_operations {
  115. /**
  116. * Complete Send WQE
  117. *
  118. * @v ibdev Infiniband device
  119. * @v qp Queue pair
  120. * @v iobuf I/O buffer
  121. * @v rc Completion status code
  122. */
  123. void ( * complete_send ) ( struct ib_device *ibdev,
  124. struct ib_queue_pair *qp,
  125. struct io_buffer *iobuf, int rc );
  126. /**
  127. * Complete Receive WQE
  128. *
  129. * @v ibdev Infiniband device
  130. * @v qp Queue pair
  131. * @v av Address vector, or NULL
  132. * @v iobuf I/O buffer
  133. * @v rc Completion status code
  134. */
  135. void ( * complete_recv ) ( struct ib_device *ibdev,
  136. struct ib_queue_pair *qp,
  137. struct ib_address_vector *av,
  138. struct io_buffer *iobuf, int rc );
  139. };
  140. /** An Infiniband Completion Queue */
  141. struct ib_completion_queue {
  142. /** Containing Infiniband device */
  143. struct ib_device *ibdev;
  144. /** List of completion queues on this Infiniband device */
  145. struct list_head list;
  146. /** Completion queue number */
  147. unsigned long cqn;
  148. /** Number of completion queue entries */
  149. unsigned int num_cqes;
  150. /** Next completion queue entry index
  151. *
  152. * This is the index of the next entry to be filled (i.e. the
  153. * first empty entry). This value is not bounded by num_wqes;
  154. * users must logical-AND with (num_wqes-1) to generate an
  155. * array index.
  156. */
  157. unsigned long next_idx;
  158. /** List of work queues completing to this queue */
  159. struct list_head work_queues;
  160. /** Completion queue operations */
  161. struct ib_completion_queue_operations *op;
  162. /** Driver private data */
  163. void *drv_priv;
  164. };
  165. /**
  166. * Infiniband device operations
  167. *
  168. * These represent a subset of the Infiniband Verbs.
  169. */
  170. struct ib_device_operations {
  171. /** Create completion queue
  172. *
  173. * @v ibdev Infiniband device
  174. * @v cq Completion queue
  175. * @ret rc Return status code
  176. */
  177. int ( * create_cq ) ( struct ib_device *ibdev,
  178. struct ib_completion_queue *cq );
  179. /** Destroy completion queue
  180. *
  181. * @v ibdev Infiniband device
  182. * @v cq Completion queue
  183. */
  184. void ( * destroy_cq ) ( struct ib_device *ibdev,
  185. struct ib_completion_queue *cq );
  186. /** Create queue pair
  187. *
  188. * @v ibdev Infiniband device
  189. * @v qp Queue pair
  190. * @ret rc Return status code
  191. */
  192. int ( * create_qp ) ( struct ib_device *ibdev,
  193. struct ib_queue_pair *qp );
  194. /** Modify queue pair
  195. *
  196. * @v ibdev Infiniband device
  197. * @v qp Queue pair
  198. * @v mod_list Modification list
  199. * @ret rc Return status code
  200. */
  201. int ( * modify_qp ) ( struct ib_device *ibdev,
  202. struct ib_queue_pair *qp,
  203. unsigned long mod_list );
  204. /** Destroy queue pair
  205. *
  206. * @v ibdev Infiniband device
  207. * @v qp Queue pair
  208. */
  209. void ( * destroy_qp ) ( struct ib_device *ibdev,
  210. struct ib_queue_pair *qp );
  211. /** Post send work queue entry
  212. *
  213. * @v ibdev Infiniband device
  214. * @v qp Queue pair
  215. * @v av Address vector
  216. * @v iobuf I/O buffer
  217. * @ret rc Return status code
  218. *
  219. * If this method returns success, the I/O buffer remains
  220. * owned by the queue pair. If this method returns failure,
  221. * the I/O buffer is immediately released; the failure is
  222. * interpreted as "failure to enqueue buffer".
  223. */
  224. int ( * post_send ) ( struct ib_device *ibdev,
  225. struct ib_queue_pair *qp,
  226. struct ib_address_vector *av,
  227. struct io_buffer *iobuf );
  228. /** Post receive work queue entry
  229. *
  230. * @v ibdev Infiniband device
  231. * @v qp Queue pair
  232. * @v iobuf I/O buffer
  233. * @ret rc Return status code
  234. *
  235. * If this method returns success, the I/O buffer remains
  236. * owned by the queue pair. If this method returns failure,
  237. * the I/O buffer is immediately released; the failure is
  238. * interpreted as "failure to enqueue buffer".
  239. */
  240. int ( * post_recv ) ( struct ib_device *ibdev,
  241. struct ib_queue_pair *qp,
  242. struct io_buffer *iobuf );
  243. /** Poll completion queue
  244. *
  245. * @v ibdev Infiniband device
  246. * @v cq Completion queue
  247. *
  248. * The relevant completion handler (specified at completion
  249. * queue creation time) takes ownership of the I/O buffer.
  250. */
  251. void ( * poll_cq ) ( struct ib_device *ibdev,
  252. struct ib_completion_queue *cq );
  253. /**
  254. * Poll event queue
  255. *
  256. * @v ibdev Infiniband device
  257. */
  258. void ( * poll_eq ) ( struct ib_device *ibdev );
  259. /**
  260. * Open port
  261. *
  262. * @v ibdev Infiniband device
  263. * @ret rc Return status code
  264. */
  265. int ( * open ) ( struct ib_device *ibdev );
  266. /**
  267. * Close port
  268. *
  269. * @v ibdev Infiniband device
  270. */
  271. void ( * close ) ( struct ib_device *ibdev );
  272. /** Attach to multicast group
  273. *
  274. * @v ibdev Infiniband device
  275. * @v qp Queue pair
  276. * @v gid Multicast GID
  277. * @ret rc Return status code
  278. */
  279. int ( * mcast_attach ) ( struct ib_device *ibdev,
  280. struct ib_queue_pair *qp,
  281. struct ib_gid *gid );
  282. /** Detach from multicast group
  283. *
  284. * @v ibdev Infiniband device
  285. * @v qp Queue pair
  286. * @v gid Multicast GID
  287. */
  288. void ( * mcast_detach ) ( struct ib_device *ibdev,
  289. struct ib_queue_pair *qp,
  290. struct ib_gid *gid );
  291. };
  292. /** An Infiniband device */
  293. struct ib_device {
  294. /** Reference counter */
  295. struct refcnt refcnt;
  296. /** List of Infiniband devices */
  297. struct list_head list;
  298. /** Underlying device */
  299. struct device *dev;
  300. /** List of completion queues */
  301. struct list_head cqs;
  302. /** List of queue pairs */
  303. struct list_head qps;
  304. /** Infiniband operations */
  305. struct ib_device_operations *op;
  306. /** Port number */
  307. unsigned int port;
  308. /** Port open request counter */
  309. unsigned int open_count;
  310. /** Port state */
  311. uint8_t port_state;
  312. /** Link width */
  313. uint8_t link_width;
  314. /** Link speed */
  315. uint8_t link_speed;
  316. /** Port GID */
  317. struct ib_gid gid;
  318. /** Port LID */
  319. uint16_t lid;
  320. /** Subnet manager LID */
  321. uint16_t sm_lid;
  322. /** Subnet manager SL */
  323. uint8_t sm_sl;
  324. /** Partition key */
  325. uint16_t pkey;
  326. /** Outbound packet sequence number */
  327. uint32_t psn;
  328. /** Driver private data */
  329. void *drv_priv;
  330. /** Owner private data */
  331. void *owner_priv;
  332. };
  333. extern struct ib_completion_queue *
  334. ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
  335. struct ib_completion_queue_operations *op );
  336. extern void ib_destroy_cq ( struct ib_device *ibdev,
  337. struct ib_completion_queue *cq );
  338. extern void ib_poll_cq ( struct ib_device *ibdev,
  339. struct ib_completion_queue *cq );
  340. extern struct ib_queue_pair *
  341. ib_create_qp ( struct ib_device *ibdev, unsigned int num_send_wqes,
  342. struct ib_completion_queue *send_cq, unsigned int num_recv_wqes,
  343. struct ib_completion_queue *recv_cq, unsigned long qkey );
  344. extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  345. unsigned long mod_list, unsigned long qkey );
  346. extern void ib_destroy_qp ( struct ib_device *ibdev,
  347. struct ib_queue_pair *qp );
  348. extern struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
  349. unsigned long qpn );
  350. extern struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
  351. struct ib_gid *gid );
  352. extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
  353. unsigned long qpn, int is_send );
  354. extern int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  355. struct ib_address_vector *av,
  356. struct io_buffer *iobuf );
  357. extern int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  358. struct io_buffer *iobuf );
  359. extern void ib_complete_send ( struct ib_device *ibdev,
  360. struct ib_queue_pair *qp,
  361. struct io_buffer *iobuf, int rc );
  362. extern void ib_complete_recv ( struct ib_device *ibdev,
  363. struct ib_queue_pair *qp,
  364. struct ib_address_vector *av,
  365. struct io_buffer *iobuf, int rc );
  366. extern void ib_refill_recv ( struct ib_device *ibdev,
  367. struct ib_queue_pair *qp );
  368. extern int ib_open ( struct ib_device *ibdev );
  369. extern void ib_close ( struct ib_device *ibdev );
  370. extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  371. struct ib_gid *gid );
  372. extern void ib_mcast_detach ( struct ib_device *ibdev,
  373. struct ib_queue_pair *qp, struct ib_gid *gid );
  374. extern int ib_get_hca_info ( struct ib_device *ibdev,
  375. struct ib_gid_half *hca_guid );
  376. extern struct ib_device * alloc_ibdev ( size_t priv_size );
  377. extern int register_ibdev ( struct ib_device *ibdev );
  378. extern void unregister_ibdev ( struct ib_device *ibdev );
  379. extern void ib_link_state_changed ( struct ib_device *ibdev );
  380. extern void ib_poll_eq ( struct ib_device *ibdev );
  381. extern struct list_head ib_devices;
  382. /** Iterate over all network devices */
  383. #define for_each_ibdev( ibdev ) \
  384. list_for_each_entry ( (ibdev), &ib_devices, list )
  385. /**
  386. * Check link state
  387. *
  388. * @v ibdev Infiniband device
  389. * @ret link_up Link is up
  390. */
  391. static inline __always_inline int
  392. ib_link_ok ( struct ib_device *ibdev ) {
  393. return ( ibdev->port_state == IB_PORT_STATE_ACTIVE );
  394. }
  395. /**
  396. * Get reference to Infiniband device
  397. *
  398. * @v ibdev Infiniband device
  399. * @ret ibdev Infiniband device
  400. */
  401. static inline __always_inline struct ib_device *
  402. ibdev_get ( struct ib_device *ibdev ) {
  403. ref_get ( &ibdev->refcnt );
  404. return ibdev;
  405. }
  406. /**
  407. * Drop reference to Infiniband device
  408. *
  409. * @v ibdev Infiniband device
  410. */
  411. static inline __always_inline void
  412. ibdev_put ( struct ib_device *ibdev ) {
  413. ref_put ( &ibdev->refcnt );
  414. }
  415. /**
  416. * Set Infiniband work queue driver-private data
  417. *
  418. * @v wq Work queue
  419. * @v priv Private data
  420. */
  421. static inline __always_inline void
  422. ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
  423. wq->drv_priv = priv;
  424. }
  425. /**
  426. * Get Infiniband work queue driver-private data
  427. *
  428. * @v wq Work queue
  429. * @ret priv Private data
  430. */
  431. static inline __always_inline void *
  432. ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
  433. return wq->drv_priv;
  434. }
  435. /**
  436. * Set Infiniband queue pair driver-private data
  437. *
  438. * @v qp Queue pair
  439. * @v priv Private data
  440. */
  441. static inline __always_inline void
  442. ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
  443. qp->drv_priv = priv;
  444. }
  445. /**
  446. * Get Infiniband queue pair driver-private data
  447. *
  448. * @v qp Queue pair
  449. * @ret priv Private data
  450. */
  451. static inline __always_inline void *
  452. ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
  453. return qp->drv_priv;
  454. }
  455. /**
  456. * Set Infiniband queue pair owner-private data
  457. *
  458. * @v qp Queue pair
  459. * @v priv Private data
  460. */
  461. static inline __always_inline void
  462. ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
  463. qp->owner_priv = priv;
  464. }
  465. /**
  466. * Get Infiniband queue pair owner-private data
  467. *
  468. * @v qp Queue pair
  469. * @ret priv Private data
  470. */
  471. static inline __always_inline void *
  472. ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
  473. return qp->owner_priv;
  474. }
  475. /**
  476. * Set Infiniband completion queue driver-private data
  477. *
  478. * @v cq Completion queue
  479. * @v priv Private data
  480. */
  481. static inline __always_inline void
  482. ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
  483. cq->drv_priv = priv;
  484. }
  485. /**
  486. * Get Infiniband completion queue driver-private data
  487. *
  488. * @v cq Completion queue
  489. * @ret priv Private data
  490. */
  491. static inline __always_inline void *
  492. ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
  493. return cq->drv_priv;
  494. }
  495. /**
  496. * Set Infiniband device driver-private data
  497. *
  498. * @v ibdev Infiniband device
  499. * @v priv Private data
  500. */
  501. static inline __always_inline void
  502. ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
  503. ibdev->drv_priv = priv;
  504. }
  505. /**
  506. * Get Infiniband device driver-private data
  507. *
  508. * @v ibdev Infiniband device
  509. * @ret priv Private data
  510. */
  511. static inline __always_inline void *
  512. ib_get_drvdata ( struct ib_device *ibdev ) {
  513. return ibdev->drv_priv;
  514. }
  515. /**
  516. * Set Infiniband device owner-private data
  517. *
  518. * @v ibdev Infiniband device
  519. * @v priv Private data
  520. */
  521. static inline __always_inline void
  522. ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
  523. ibdev->owner_priv = priv;
  524. }
  525. /**
  526. * Get Infiniband device owner-private data
  527. *
  528. * @v ibdev Infiniband device
  529. * @ret priv Private data
  530. */
  531. static inline __always_inline void *
  532. ib_get_ownerdata ( struct ib_device *ibdev ) {
  533. return ibdev->owner_priv;
  534. }
  535. #endif /* _GPXE_INFINIBAND_H */