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

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