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 17KB

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