Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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. struct ib_gma;
  39. /** Infiniband transmission rates */
  40. enum ib_rate {
  41. IB_RATE_2_5 = 2,
  42. IB_RATE_10 = 3,
  43. IB_RATE_30 = 4,
  44. IB_RATE_5 = 5,
  45. IB_RATE_20 = 6,
  46. IB_RATE_40 = 7,
  47. IB_RATE_60 = 8,
  48. IB_RATE_80 = 9,
  49. IB_RATE_120 = 10,
  50. };
  51. /** An Infiniband Address Vector */
  52. struct ib_address_vector {
  53. /** Queue Pair Number */
  54. unsigned long qpn;
  55. /** Queue key
  56. *
  57. * Not specified for received packets.
  58. */
  59. unsigned long qkey;
  60. /** Local ID */
  61. unsigned int lid;
  62. /** Rate
  63. *
  64. * Not specified for received packets.
  65. */
  66. enum ib_rate rate;
  67. /** Service level */
  68. unsigned int sl;
  69. /** GID is present */
  70. unsigned int gid_present;
  71. /** GID, if present */
  72. struct ib_gid gid;
  73. };
  74. /** An Infiniband Work Queue */
  75. struct ib_work_queue {
  76. /** Containing queue pair */
  77. struct ib_queue_pair *qp;
  78. /** "Is a send queue" flag */
  79. int is_send;
  80. /** Associated completion queue */
  81. struct ib_completion_queue *cq;
  82. /** List of work queues on this completion queue */
  83. struct list_head list;
  84. /** Packet sequence number */
  85. uint32_t psn;
  86. /** Number of work queue entries */
  87. unsigned int num_wqes;
  88. /** Number of occupied work queue entries */
  89. unsigned int fill;
  90. /** Next work queue entry index
  91. *
  92. * This is the index of the next entry to be filled (i.e. the
  93. * first empty entry). This value is not bounded by num_wqes;
  94. * users must logical-AND with (num_wqes-1) to generate an
  95. * array index.
  96. */
  97. unsigned long next_idx;
  98. /** I/O buffers assigned to work queue */
  99. struct io_buffer **iobufs;
  100. /** Driver private data */
  101. void *drv_priv;
  102. };
  103. /** An Infiniband multicast GID */
  104. struct ib_multicast_gid {
  105. /** List of multicast GIDs on this QP */
  106. struct list_head list;
  107. /** Multicast GID */
  108. struct ib_gid gid;
  109. };
  110. /** An Infiniband queue pair type */
  111. enum ib_queue_pair_type {
  112. IB_QPT_SMI,
  113. IB_QPT_GSI,
  114. IB_QPT_UD,
  115. IB_QPT_RC,
  116. };
  117. /** An Infiniband Queue Pair */
  118. struct ib_queue_pair {
  119. /** Containing Infiniband device */
  120. struct ib_device *ibdev;
  121. /** List of queue pairs on this Infiniband device */
  122. struct list_head list;
  123. /** Queue pair number */
  124. unsigned long qpn;
  125. /** Externally-visible queue pair number
  126. *
  127. * This may differ from the real queue pair number (e.g. when
  128. * the HCA cannot use the management QPNs 0 and 1 as hardware
  129. * QPNs and needs to remap them).
  130. */
  131. unsigned long ext_qpn;
  132. /** Queue pair type */
  133. enum ib_queue_pair_type type;
  134. /** Queue key */
  135. unsigned long qkey;
  136. /** Send queue */
  137. struct ib_work_queue send;
  138. /** Receive queue */
  139. struct ib_work_queue recv;
  140. /** List of multicast GIDs */
  141. struct list_head mgids;
  142. /** Address vector */
  143. struct ib_address_vector av;
  144. /** Driver private data */
  145. void *drv_priv;
  146. /** Queue owner private data */
  147. void *owner_priv;
  148. };
  149. /** Infiniband completion queue operations */
  150. struct ib_completion_queue_operations {
  151. /**
  152. * Complete Send WQE
  153. *
  154. * @v ibdev Infiniband device
  155. * @v qp Queue pair
  156. * @v iobuf I/O buffer
  157. * @v rc Completion status code
  158. */
  159. void ( * complete_send ) ( struct ib_device *ibdev,
  160. struct ib_queue_pair *qp,
  161. struct io_buffer *iobuf, int rc );
  162. /**
  163. * Complete Receive WQE
  164. *
  165. * @v ibdev Infiniband device
  166. * @v qp Queue pair
  167. * @v av Address vector, or NULL
  168. * @v iobuf I/O buffer
  169. * @v rc Completion status code
  170. */
  171. void ( * complete_recv ) ( struct ib_device *ibdev,
  172. struct ib_queue_pair *qp,
  173. struct ib_address_vector *av,
  174. struct io_buffer *iobuf, int rc );
  175. };
  176. /** An Infiniband Completion Queue */
  177. struct ib_completion_queue {
  178. /** Containing Infiniband device */
  179. struct ib_device *ibdev;
  180. /** List of completion queues on this Infiniband device */
  181. struct list_head list;
  182. /** Completion queue number */
  183. unsigned long cqn;
  184. /** Number of completion queue entries */
  185. unsigned int num_cqes;
  186. /** Next completion queue entry index
  187. *
  188. * This is the index of the next entry to be filled (i.e. the
  189. * first empty entry). This value is not bounded by num_wqes;
  190. * users must logical-AND with (num_wqes-1) to generate an
  191. * array index.
  192. */
  193. unsigned long next_idx;
  194. /** List of work queues completing to this queue */
  195. struct list_head work_queues;
  196. /** Completion queue operations */
  197. struct ib_completion_queue_operations *op;
  198. /** Driver private data */
  199. void *drv_priv;
  200. };
  201. /**
  202. * Infiniband device operations
  203. *
  204. * These represent a subset of the Infiniband Verbs.
  205. */
  206. struct ib_device_operations {
  207. /** Create completion queue
  208. *
  209. * @v ibdev Infiniband device
  210. * @v cq Completion queue
  211. * @ret rc Return status code
  212. */
  213. int ( * create_cq ) ( struct ib_device *ibdev,
  214. struct ib_completion_queue *cq );
  215. /** Destroy completion queue
  216. *
  217. * @v ibdev Infiniband device
  218. * @v cq Completion queue
  219. */
  220. void ( * destroy_cq ) ( struct ib_device *ibdev,
  221. struct ib_completion_queue *cq );
  222. /** Create queue pair
  223. *
  224. * @v ibdev Infiniband device
  225. * @v qp Queue pair
  226. * @ret rc Return status code
  227. */
  228. int ( * create_qp ) ( struct ib_device *ibdev,
  229. struct ib_queue_pair *qp );
  230. /** Modify queue pair
  231. *
  232. * @v ibdev Infiniband device
  233. * @v qp Queue pair
  234. * @ret rc Return status code
  235. */
  236. int ( * modify_qp ) ( struct ib_device *ibdev,
  237. struct ib_queue_pair *qp );
  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. /** Set partition key table
  335. *
  336. * @v ibdev Infiniband device
  337. * @v mad Set partition key table MAD
  338. *
  339. * This method is required only by adapters that do not have
  340. * an embedded SMA.
  341. */
  342. int ( * set_pkey_table ) ( struct ib_device *ibdev,
  343. union ib_mad *mad );
  344. };
  345. /** An Infiniband device */
  346. struct ib_device {
  347. /** Reference counter */
  348. struct refcnt refcnt;
  349. /** List of Infiniband devices */
  350. struct list_head list;
  351. /** Underlying device */
  352. struct device *dev;
  353. /** List of completion queues */
  354. struct list_head cqs;
  355. /** List of queue pairs */
  356. struct list_head qps;
  357. /** Infiniband operations */
  358. struct ib_device_operations *op;
  359. /** Port number */
  360. unsigned int port;
  361. /** Port open request counter */
  362. unsigned int open_count;
  363. /** Port state */
  364. uint8_t port_state;
  365. /** Link width supported */
  366. uint8_t link_width_supported;
  367. /** Link width enabled */
  368. uint8_t link_width_enabled;
  369. /** Link width active */
  370. uint8_t link_width_active;
  371. /** Link speed supported */
  372. uint8_t link_speed_supported;
  373. /** Link speed enabled */
  374. uint8_t link_speed_enabled;
  375. /** Link speed active */
  376. uint8_t link_speed_active;
  377. /** Port GID */
  378. struct ib_gid gid;
  379. /** Port LID */
  380. uint16_t lid;
  381. /** Subnet manager LID */
  382. uint16_t sm_lid;
  383. /** Subnet manager SL */
  384. uint8_t sm_sl;
  385. /** Partition key */
  386. uint16_t pkey;
  387. /** RDMA key
  388. *
  389. * This is a single key allowing unrestricted access to
  390. * memory.
  391. */
  392. uint32_t rdma_key;
  393. /** Subnet management interface */
  394. struct ib_mad_interface *smi;
  395. /** General management agent */
  396. struct ib_gma *gma;
  397. /** Driver private data */
  398. void *drv_priv;
  399. /** Owner private data */
  400. void *owner_priv;
  401. };
  402. extern struct ib_completion_queue *
  403. ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
  404. struct ib_completion_queue_operations *op );
  405. extern void ib_destroy_cq ( struct ib_device *ibdev,
  406. struct ib_completion_queue *cq );
  407. extern void ib_poll_cq ( struct ib_device *ibdev,
  408. struct ib_completion_queue *cq );
  409. extern struct ib_queue_pair *
  410. ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
  411. unsigned int num_send_wqes, struct ib_completion_queue *send_cq,
  412. unsigned int num_recv_wqes,
  413. struct ib_completion_queue *recv_cq );
  414. extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp );
  415. extern void ib_destroy_qp ( struct ib_device *ibdev,
  416. struct ib_queue_pair *qp );
  417. extern struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
  418. unsigned long qpn );
  419. extern struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
  420. struct ib_gid *gid );
  421. extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
  422. unsigned long qpn, int is_send );
  423. extern int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  424. struct ib_address_vector *av,
  425. struct io_buffer *iobuf );
  426. extern int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  427. struct io_buffer *iobuf );
  428. extern void ib_complete_send ( struct ib_device *ibdev,
  429. struct ib_queue_pair *qp,
  430. struct io_buffer *iobuf, int rc );
  431. extern void ib_complete_recv ( struct ib_device *ibdev,
  432. struct ib_queue_pair *qp,
  433. struct ib_address_vector *av,
  434. struct io_buffer *iobuf, int rc );
  435. extern void ib_refill_recv ( struct ib_device *ibdev,
  436. struct ib_queue_pair *qp );
  437. extern int ib_open ( struct ib_device *ibdev );
  438. extern void ib_close ( struct ib_device *ibdev );
  439. extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  440. struct ib_gid *gid );
  441. extern void ib_mcast_detach ( struct ib_device *ibdev,
  442. struct ib_queue_pair *qp, struct ib_gid *gid );
  443. extern int ib_get_hca_info ( struct ib_device *ibdev,
  444. struct ib_gid_half *hca_guid );
  445. extern int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad );
  446. extern int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad );
  447. extern struct ib_device * alloc_ibdev ( size_t priv_size );
  448. extern int register_ibdev ( struct ib_device *ibdev );
  449. extern void unregister_ibdev ( struct ib_device *ibdev );
  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 */