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

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