Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

infiniband.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. /** List of open Infiniband devices */
  351. struct list_head open_list;
  352. /** Underlying device */
  353. struct device *dev;
  354. /** List of completion queues */
  355. struct list_head cqs;
  356. /** List of queue pairs */
  357. struct list_head qps;
  358. /** Infiniband operations */
  359. struct ib_device_operations *op;
  360. /** Port number */
  361. unsigned int port;
  362. /** Port open request counter */
  363. unsigned int open_count;
  364. /** Port state */
  365. uint8_t port_state;
  366. /** Link width supported */
  367. uint8_t link_width_supported;
  368. /** Link width enabled */
  369. uint8_t link_width_enabled;
  370. /** Link width active */
  371. uint8_t link_width_active;
  372. /** Link speed supported */
  373. uint8_t link_speed_supported;
  374. /** Link speed enabled */
  375. uint8_t link_speed_enabled;
  376. /** Link speed active */
  377. uint8_t link_speed_active;
  378. /** Port GID */
  379. struct ib_gid gid;
  380. /** Port LID */
  381. uint16_t lid;
  382. /** Subnet manager LID */
  383. uint16_t sm_lid;
  384. /** Subnet manager SL */
  385. uint8_t sm_sl;
  386. /** Partition key */
  387. uint16_t pkey;
  388. /** RDMA key
  389. *
  390. * This is a single key allowing unrestricted access to
  391. * memory.
  392. */
  393. uint32_t rdma_key;
  394. /** Subnet management interface */
  395. struct ib_mad_interface *smi;
  396. /** General services interface */
  397. struct ib_mad_interface *gsi;
  398. /** Driver private data */
  399. void *drv_priv;
  400. /** Owner private data */
  401. void *owner_priv;
  402. };
  403. extern struct ib_completion_queue *
  404. ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
  405. struct ib_completion_queue_operations *op );
  406. extern void ib_destroy_cq ( struct ib_device *ibdev,
  407. struct ib_completion_queue *cq );
  408. extern void ib_poll_cq ( struct ib_device *ibdev,
  409. struct ib_completion_queue *cq );
  410. extern struct ib_queue_pair *
  411. ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
  412. unsigned int num_send_wqes, struct ib_completion_queue *send_cq,
  413. unsigned int num_recv_wqes,
  414. struct ib_completion_queue *recv_cq );
  415. extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp );
  416. extern void ib_destroy_qp ( struct ib_device *ibdev,
  417. struct ib_queue_pair *qp );
  418. extern struct ib_queue_pair * ib_find_qp_qpn ( struct ib_device *ibdev,
  419. unsigned long qpn );
  420. extern struct ib_queue_pair * ib_find_qp_mgid ( struct ib_device *ibdev,
  421. struct ib_gid *gid );
  422. extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
  423. unsigned long qpn, int is_send );
  424. extern int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  425. struct ib_address_vector *av,
  426. struct io_buffer *iobuf );
  427. extern int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  428. struct io_buffer *iobuf );
  429. extern void ib_complete_send ( struct ib_device *ibdev,
  430. struct ib_queue_pair *qp,
  431. struct io_buffer *iobuf, int rc );
  432. extern void ib_complete_recv ( struct ib_device *ibdev,
  433. struct ib_queue_pair *qp,
  434. struct ib_address_vector *av,
  435. struct io_buffer *iobuf, int rc );
  436. extern void ib_refill_recv ( struct ib_device *ibdev,
  437. struct ib_queue_pair *qp );
  438. extern int ib_open ( struct ib_device *ibdev );
  439. extern void ib_close ( struct ib_device *ibdev );
  440. extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  441. struct ib_gid *gid );
  442. extern void ib_mcast_detach ( struct ib_device *ibdev,
  443. struct ib_queue_pair *qp, struct ib_gid *gid );
  444. extern int ib_get_hca_info ( struct ib_device *ibdev,
  445. struct ib_gid_half *hca_guid );
  446. extern int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad );
  447. extern int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad );
  448. extern struct ib_device * alloc_ibdev ( size_t priv_size );
  449. extern int register_ibdev ( struct ib_device *ibdev );
  450. extern void unregister_ibdev ( struct ib_device *ibdev );
  451. extern struct ib_device * find_ibdev ( struct ib_gid *gid );
  452. extern struct ib_device * last_opened_ibdev ( void );
  453. extern void ib_link_state_changed ( struct ib_device *ibdev );
  454. extern void ib_poll_eq ( struct ib_device *ibdev );
  455. extern struct list_head ib_devices;
  456. /** Iterate over all network devices */
  457. #define for_each_ibdev( ibdev ) \
  458. list_for_each_entry ( (ibdev), &ib_devices, list )
  459. /**
  460. * Check link state
  461. *
  462. * @v ibdev Infiniband device
  463. * @ret link_up Link is up
  464. */
  465. static inline __always_inline int
  466. ib_link_ok ( struct ib_device *ibdev ) {
  467. return ( ibdev->port_state == IB_PORT_STATE_ACTIVE );
  468. }
  469. /**
  470. * Get reference to Infiniband device
  471. *
  472. * @v ibdev Infiniband device
  473. * @ret ibdev Infiniband device
  474. */
  475. static inline __always_inline struct ib_device *
  476. ibdev_get ( struct ib_device *ibdev ) {
  477. ref_get ( &ibdev->refcnt );
  478. return ibdev;
  479. }
  480. /**
  481. * Drop reference to Infiniband device
  482. *
  483. * @v ibdev Infiniband device
  484. */
  485. static inline __always_inline void
  486. ibdev_put ( struct ib_device *ibdev ) {
  487. ref_put ( &ibdev->refcnt );
  488. }
  489. /**
  490. * Set Infiniband work queue driver-private data
  491. *
  492. * @v wq Work queue
  493. * @v priv Private data
  494. */
  495. static inline __always_inline void
  496. ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
  497. wq->drv_priv = priv;
  498. }
  499. /**
  500. * Get Infiniband work queue driver-private data
  501. *
  502. * @v wq Work queue
  503. * @ret priv Private data
  504. */
  505. static inline __always_inline void *
  506. ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
  507. return wq->drv_priv;
  508. }
  509. /**
  510. * Set Infiniband queue pair driver-private data
  511. *
  512. * @v qp Queue pair
  513. * @v priv Private data
  514. */
  515. static inline __always_inline void
  516. ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
  517. qp->drv_priv = priv;
  518. }
  519. /**
  520. * Get Infiniband queue pair driver-private data
  521. *
  522. * @v qp Queue pair
  523. * @ret priv Private data
  524. */
  525. static inline __always_inline void *
  526. ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
  527. return qp->drv_priv;
  528. }
  529. /**
  530. * Set Infiniband queue pair owner-private data
  531. *
  532. * @v qp Queue pair
  533. * @v priv Private data
  534. */
  535. static inline __always_inline void
  536. ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
  537. qp->owner_priv = priv;
  538. }
  539. /**
  540. * Get Infiniband queue pair owner-private data
  541. *
  542. * @v qp Queue pair
  543. * @ret priv Private data
  544. */
  545. static inline __always_inline void *
  546. ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
  547. return qp->owner_priv;
  548. }
  549. /**
  550. * Set Infiniband completion queue driver-private data
  551. *
  552. * @v cq Completion queue
  553. * @v priv Private data
  554. */
  555. static inline __always_inline void
  556. ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
  557. cq->drv_priv = priv;
  558. }
  559. /**
  560. * Get Infiniband completion queue driver-private data
  561. *
  562. * @v cq Completion queue
  563. * @ret priv Private data
  564. */
  565. static inline __always_inline void *
  566. ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
  567. return cq->drv_priv;
  568. }
  569. /**
  570. * Set Infiniband device driver-private data
  571. *
  572. * @v ibdev Infiniband device
  573. * @v priv Private data
  574. */
  575. static inline __always_inline void
  576. ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
  577. ibdev->drv_priv = priv;
  578. }
  579. /**
  580. * Get Infiniband device driver-private data
  581. *
  582. * @v ibdev Infiniband device
  583. * @ret priv Private data
  584. */
  585. static inline __always_inline void *
  586. ib_get_drvdata ( struct ib_device *ibdev ) {
  587. return ibdev->drv_priv;
  588. }
  589. /**
  590. * Set Infiniband device owner-private data
  591. *
  592. * @v ibdev Infiniband device
  593. * @v priv Private data
  594. */
  595. static inline __always_inline void
  596. ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
  597. ibdev->owner_priv = priv;
  598. }
  599. /**
  600. * Get Infiniband device owner-private data
  601. *
  602. * @v ibdev Infiniband device
  603. * @ret priv Private data
  604. */
  605. static inline __always_inline void *
  606. ib_get_ownerdata ( struct ib_device *ibdev ) {
  607. return ibdev->owner_priv;
  608. }
  609. #endif /* _GPXE_INFINIBAND_H */