選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

infiniband.h 17KB

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