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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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 void ib_link_state_changed ( struct ib_device *ibdev );
  450. extern void ib_poll_eq ( struct ib_device *ibdev );
  451. extern struct list_head ib_devices;
  452. /** Iterate over all network devices */
  453. #define for_each_ibdev( ibdev ) \
  454. list_for_each_entry ( (ibdev), &ib_devices, list )
  455. /**
  456. * Check link state
  457. *
  458. * @v ibdev Infiniband device
  459. * @ret link_up Link is up
  460. */
  461. static inline __always_inline int
  462. ib_link_ok ( struct ib_device *ibdev ) {
  463. return ( ibdev->port_state == IB_PORT_STATE_ACTIVE );
  464. }
  465. /**
  466. * Get reference to Infiniband device
  467. *
  468. * @v ibdev Infiniband device
  469. * @ret ibdev Infiniband device
  470. */
  471. static inline __always_inline struct ib_device *
  472. ibdev_get ( struct ib_device *ibdev ) {
  473. ref_get ( &ibdev->refcnt );
  474. return ibdev;
  475. }
  476. /**
  477. * Drop reference to Infiniband device
  478. *
  479. * @v ibdev Infiniband device
  480. */
  481. static inline __always_inline void
  482. ibdev_put ( struct ib_device *ibdev ) {
  483. ref_put ( &ibdev->refcnt );
  484. }
  485. /**
  486. * Set Infiniband work queue driver-private data
  487. *
  488. * @v wq Work queue
  489. * @v priv Private data
  490. */
  491. static inline __always_inline void
  492. ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
  493. wq->drv_priv = priv;
  494. }
  495. /**
  496. * Get Infiniband work queue driver-private data
  497. *
  498. * @v wq Work queue
  499. * @ret priv Private data
  500. */
  501. static inline __always_inline void *
  502. ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
  503. return wq->drv_priv;
  504. }
  505. /**
  506. * Set Infiniband queue pair driver-private data
  507. *
  508. * @v qp Queue pair
  509. * @v priv Private data
  510. */
  511. static inline __always_inline void
  512. ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
  513. qp->drv_priv = priv;
  514. }
  515. /**
  516. * Get Infiniband queue pair driver-private data
  517. *
  518. * @v qp Queue pair
  519. * @ret priv Private data
  520. */
  521. static inline __always_inline void *
  522. ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
  523. return qp->drv_priv;
  524. }
  525. /**
  526. * Set Infiniband queue pair owner-private data
  527. *
  528. * @v qp Queue pair
  529. * @v priv Private data
  530. */
  531. static inline __always_inline void
  532. ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
  533. qp->owner_priv = priv;
  534. }
  535. /**
  536. * Get Infiniband queue pair owner-private data
  537. *
  538. * @v qp Queue pair
  539. * @ret priv Private data
  540. */
  541. static inline __always_inline void *
  542. ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
  543. return qp->owner_priv;
  544. }
  545. /**
  546. * Set Infiniband completion queue driver-private data
  547. *
  548. * @v cq Completion queue
  549. * @v priv Private data
  550. */
  551. static inline __always_inline void
  552. ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
  553. cq->drv_priv = priv;
  554. }
  555. /**
  556. * Get Infiniband completion queue driver-private data
  557. *
  558. * @v cq Completion queue
  559. * @ret priv Private data
  560. */
  561. static inline __always_inline void *
  562. ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
  563. return cq->drv_priv;
  564. }
  565. /**
  566. * Set Infiniband device driver-private data
  567. *
  568. * @v ibdev Infiniband device
  569. * @v priv Private data
  570. */
  571. static inline __always_inline void
  572. ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
  573. ibdev->drv_priv = priv;
  574. }
  575. /**
  576. * Get Infiniband device driver-private data
  577. *
  578. * @v ibdev Infiniband device
  579. * @ret priv Private data
  580. */
  581. static inline __always_inline void *
  582. ib_get_drvdata ( struct ib_device *ibdev ) {
  583. return ibdev->drv_priv;
  584. }
  585. /**
  586. * Set Infiniband device owner-private data
  587. *
  588. * @v ibdev Infiniband device
  589. * @v priv Private data
  590. */
  591. static inline __always_inline void
  592. ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
  593. ibdev->owner_priv = priv;
  594. }
  595. /**
  596. * Get Infiniband device owner-private data
  597. *
  598. * @v ibdev Infiniband device
  599. * @ret priv Private data
  600. */
  601. static inline __always_inline void *
  602. ib_get_ownerdata ( struct ib_device *ibdev ) {
  603. return ibdev->owner_priv;
  604. }
  605. #endif /* _GPXE_INFINIBAND_H */