Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

infiniband.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #ifndef _GPXE_INFINIBAND_H
  2. #define _GPXE_INFINIBAND_H
  3. /** @file
  4. *
  5. * Infiniband protocol
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/device.h>
  10. /** Subnet administrator QPN */
  11. #define IB_SA_QPN 1
  12. /** Broadcast QPN */
  13. #define IB_BROADCAST_QPN 0xffffffUL
  14. /** Subnet administrator queue key */
  15. #define IB_GLOBAL_QKEY 0x80010000UL
  16. /** An Infiniband Global Identifier */
  17. struct ib_gid {
  18. union {
  19. uint8_t bytes[16];
  20. uint16_t words[8];
  21. uint32_t dwords[4];
  22. } u;
  23. };
  24. /** An Infiniband Global Route Header */
  25. struct ib_global_route_header {
  26. /** IP version, traffic class, and flow label
  27. *
  28. * 4 bits : Version of the GRH
  29. * 8 bits : Traffic class
  30. * 20 bits : Flow label
  31. */
  32. uint32_t ipver_tclass_flowlabel;
  33. /** Payload length */
  34. uint16_t paylen;
  35. /** Next header */
  36. uint8_t nxthdr;
  37. /** Hop limit */
  38. uint8_t hoplmt;
  39. /** Source GID */
  40. struct ib_gid sgid;
  41. /** Destiniation GID */
  42. struct ib_gid dgid;
  43. } __attribute__ (( packed ));
  44. struct ib_device;
  45. struct ib_queue_pair;
  46. struct ib_completion_queue;
  47. /** An Infiniband Work Queue */
  48. struct ib_work_queue {
  49. /** Containing queue pair */
  50. struct ib_queue_pair *qp;
  51. /** "Is a send queue" flag */
  52. int is_send;
  53. /** Associated completion queue */
  54. struct ib_completion_queue *cq;
  55. /** List of work queues on this completion queue */
  56. struct list_head list;
  57. /** Number of work queue entries */
  58. unsigned int num_wqes;
  59. /** Next work queue entry index
  60. *
  61. * This is the index of the next entry to be filled (i.e. the
  62. * first empty entry). This value is not bounded by num_wqes;
  63. * users must logical-AND with (num_wqes-1) to generate an
  64. * array index.
  65. */
  66. unsigned long next_idx;
  67. /** I/O buffers assigned to work queue */
  68. struct io_buffer **iobufs;
  69. /** Device private data */
  70. void *dev_priv;
  71. };
  72. /** An Infiniband Queue Pair */
  73. struct ib_queue_pair {
  74. /** Queue Pair Number */
  75. unsigned long qpn;
  76. /** Queue key */
  77. unsigned long qkey;
  78. /** Send queue */
  79. struct ib_work_queue send;
  80. /** Receive queue */
  81. struct ib_work_queue recv;
  82. /** Device private data */
  83. void *dev_priv;
  84. /** Queue owner private data */
  85. void *owner_priv;
  86. };
  87. /** An Infiniband Completion Queue */
  88. struct ib_completion_queue {
  89. /** Completion queue number */
  90. unsigned long cqn;
  91. /** Number of completion queue entries */
  92. unsigned int num_cqes;
  93. /** Next completion 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. /** List of work queues completing to this queue */
  102. struct list_head work_queues;
  103. /** Device private data */
  104. void *dev_priv;
  105. };
  106. /** An Infiniband completion */
  107. struct ib_completion {
  108. /** Syndrome
  109. *
  110. * If non-zero, then the completion is in error.
  111. */
  112. unsigned int syndrome;
  113. /** Length */
  114. size_t len;
  115. };
  116. /** An Infiniband completion handler
  117. *
  118. * @v ibdev Infiniband device
  119. * @v qp Queue pair
  120. * @v completion Completion
  121. * @v iobuf I/O buffer
  122. */
  123. typedef void ( * ib_completer_t ) ( struct ib_device *ibdev,
  124. struct ib_queue_pair *qp,
  125. struct ib_completion *completion,
  126. struct io_buffer *iobuf );
  127. /** An Infiniband Address Vector */
  128. struct ib_address_vector {
  129. /** Destination Queue Pair */
  130. unsigned int dest_qp;
  131. /** Queue key */
  132. unsigned long qkey;
  133. /** Destination Local ID */
  134. unsigned int dlid;
  135. /** Rate */
  136. unsigned int rate;
  137. /** Service level */
  138. unsigned int sl;
  139. /** GID is present */
  140. unsigned int gid_present;
  141. /** GID */
  142. struct ib_gid gid;
  143. };
  144. /**
  145. * Infiniband device operations
  146. *
  147. * These represent a subset of the Infiniband Verbs.
  148. */
  149. struct ib_device_operations {
  150. /** Create completion queue
  151. *
  152. * @v ibdev Infiniband device
  153. * @v cq Completion queue
  154. * @ret rc Return status code
  155. */
  156. int ( * create_cq ) ( struct ib_device *ibdev,
  157. struct ib_completion_queue *cq );
  158. /** Destroy completion queue
  159. *
  160. * @v ibdev Infiniband device
  161. * @v cq Completion queue
  162. */
  163. void ( * destroy_cq ) ( struct ib_device *ibdev,
  164. struct ib_completion_queue *cq );
  165. /** Create queue pair
  166. *
  167. * @v ibdev Infiniband device
  168. * @v qp Queue pair
  169. * @ret rc Return status code
  170. */
  171. int ( * create_qp ) ( struct ib_device *ibdev,
  172. struct ib_queue_pair *qp );
  173. /** Destroy queue pair
  174. *
  175. * @v ibdev Infiniband device
  176. * @v qp Queue pair
  177. */
  178. void ( * destroy_qp ) ( struct ib_device *ibdev,
  179. struct ib_queue_pair *qp );
  180. /** Post send work queue entry
  181. *
  182. * @v ibdev Infiniband device
  183. * @v qp Queue pair
  184. * @v av Address vector
  185. * @v iobuf I/O buffer
  186. * @ret rc Return status code
  187. *
  188. * If this method returns success, the I/O buffer remains
  189. * owned by the queue pair. If this method returns failure,
  190. * the I/O buffer is immediately released; the failure is
  191. * interpreted as "failure to enqueue buffer".
  192. */
  193. int ( * post_send ) ( struct ib_device *ibdev,
  194. struct ib_queue_pair *qp,
  195. struct ib_address_vector *av,
  196. struct io_buffer *iobuf );
  197. /** Post receive work queue entry
  198. *
  199. * @v ibdev Infiniband device
  200. * @v qp Queue pair
  201. * @v iobuf I/O buffer
  202. * @ret rc Return status code
  203. *
  204. * If this method returns success, the I/O buffer remains
  205. * owned by the queue pair. If this method returns failure,
  206. * the I/O buffer is immediately released; the failure is
  207. * interpreted as "failure to enqueue buffer".
  208. */
  209. int ( * post_recv ) ( struct ib_device *ibdev,
  210. struct ib_queue_pair *qp,
  211. struct io_buffer *iobuf );
  212. /** Poll completion queue
  213. *
  214. * @v ibdev Infiniband device
  215. * @v cq Completion queue
  216. * @v complete_send Send completion handler
  217. * @v complete_recv Receive completion handler
  218. *
  219. * The completion handler takes ownership of the I/O buffer.
  220. */
  221. void ( * poll_cq ) ( struct ib_device *ibdev,
  222. struct ib_completion_queue *cq,
  223. ib_completer_t complete_send,
  224. ib_completer_t complete_recv );
  225. /** Attach to multicast group
  226. *
  227. * @v ibdev Infiniband device
  228. * @v qp Queue pair
  229. * @v gid Multicast GID
  230. * @ret rc Return status code
  231. */
  232. int ( * mcast_attach ) ( struct ib_device *ibdev,
  233. struct ib_queue_pair *qp,
  234. struct ib_gid *gid );
  235. /** Detach from multicast group
  236. *
  237. * @v ibdev Infiniband device
  238. * @v qp Queue pair
  239. * @v gid Multicast GID
  240. */
  241. void ( * mcast_detach ) ( struct ib_device *ibdev,
  242. struct ib_queue_pair *qp,
  243. struct ib_gid *gid );
  244. };
  245. /** An Infiniband device */
  246. struct ib_device {
  247. /** Port GID */
  248. struct ib_gid port_gid;
  249. /** Subnet manager LID */
  250. unsigned long sm_lid;
  251. /** Partition key */
  252. unsigned int pkey;
  253. /** Underlying device */
  254. struct device *dev;
  255. /** Infiniband operations */
  256. struct ib_device_operations *op;
  257. /** Device private data */
  258. void *dev_priv;
  259. /** Owner private data */
  260. void *owner_priv;
  261. };
  262. extern struct ib_completion_queue * ib_create_cq ( struct ib_device *ibdev,
  263. unsigned int num_cqes );
  264. extern void ib_destroy_cq ( struct ib_device *ibdev,
  265. struct ib_completion_queue *cq );
  266. extern struct ib_queue_pair *
  267. ib_create_qp ( struct ib_device *ibdev, unsigned int num_send_wqes,
  268. struct ib_completion_queue *send_cq, unsigned int num_recv_wqes,
  269. struct ib_completion_queue *recv_cq, unsigned long qkey );
  270. extern void ib_destroy_qp ( struct ib_device *ibdev,
  271. struct ib_queue_pair *qp );
  272. extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
  273. unsigned long qpn, int is_send );
  274. extern struct ib_device * alloc_ibdev ( size_t priv_size );
  275. extern void free_ibdev ( struct ib_device *ibdev );
  276. /**
  277. * Post send work queue entry
  278. *
  279. * @v ibdev Infiniband device
  280. * @v qp Queue pair
  281. * @v av Address vector
  282. * @v iobuf I/O buffer
  283. * @ret rc Return status code
  284. */
  285. static inline __attribute__ (( always_inline )) int
  286. ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  287. struct ib_address_vector *av, struct io_buffer *iobuf ) {
  288. return ibdev->op->post_send ( ibdev, qp, av, iobuf );
  289. }
  290. /**
  291. * Post receive work queue entry
  292. *
  293. * @v ibdev Infiniband device
  294. * @v qp Queue pair
  295. * @v iobuf I/O buffer
  296. * @ret rc Return status code
  297. */
  298. static inline __attribute__ (( always_inline )) int
  299. ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  300. struct io_buffer *iobuf ) {
  301. return ibdev->op->post_recv ( ibdev, qp, iobuf );
  302. }
  303. /**
  304. * Poll completion queue
  305. *
  306. * @v ibdev Infiniband device
  307. * @v cq Completion queue
  308. * @v complete_send Send completion handler
  309. * @v complete_recv Receive completion handler
  310. */
  311. static inline __attribute__ (( always_inline )) void
  312. ib_poll_cq ( struct ib_device *ibdev, struct ib_completion_queue *cq,
  313. ib_completer_t complete_send, ib_completer_t complete_recv ) {
  314. ibdev->op->poll_cq ( ibdev, cq, complete_send, complete_recv );
  315. }
  316. /**
  317. * Attach to multicast group
  318. *
  319. * @v ibdev Infiniband device
  320. * @v qp Queue pair
  321. * @v gid Multicast GID
  322. * @ret rc Return status code
  323. */
  324. static inline __attribute__ (( always_inline )) int
  325. ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  326. struct ib_gid *gid ) {
  327. return ibdev->op->mcast_attach ( ibdev, qp, gid );
  328. }
  329. /**
  330. * Detach from multicast group
  331. *
  332. * @v ibdev Infiniband device
  333. * @v qp Queue pair
  334. * @v gid Multicast GID
  335. */
  336. static inline __attribute__ (( always_inline )) void
  337. ib_mcast_detach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
  338. struct ib_gid *gid ) {
  339. ibdev->op->mcast_detach ( ibdev, qp, gid );
  340. }
  341. /**
  342. * Set Infiniband owner-private data
  343. *
  344. * @v pci Infiniband device
  345. * @v priv Private data
  346. */
  347. static inline void ib_set_ownerdata ( struct ib_device *ibdev,
  348. void *owner_priv ) {
  349. ibdev->owner_priv = owner_priv;
  350. }
  351. /**
  352. * Get Infiniband owner-private data
  353. *
  354. * @v pci Infiniband device
  355. * @ret priv Private data
  356. */
  357. static inline void * ib_get_ownerdata ( struct ib_device *ibdev ) {
  358. return ibdev->owner_priv;
  359. }
  360. /*****************************************************************************
  361. *
  362. * Management datagrams
  363. *
  364. * Portions Copyright (c) 2004 Mellanox Technologies Ltd. All rights
  365. * reserved.
  366. *
  367. */
  368. /* Management base version */
  369. #define IB_MGMT_BASE_VERSION 1
  370. /* Management classes */
  371. #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
  372. #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
  373. #define IB_MGMT_CLASS_SUBN_ADM 0x03
  374. #define IB_MGMT_CLASS_PERF_MGMT 0x04
  375. #define IB_MGMT_CLASS_BM 0x05
  376. #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
  377. #define IB_MGMT_CLASS_CM 0x07
  378. #define IB_MGMT_CLASS_SNMP 0x08
  379. #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
  380. #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
  381. /* Management methods */
  382. #define IB_MGMT_METHOD_GET 0x01
  383. #define IB_MGMT_METHOD_SET 0x02
  384. #define IB_MGMT_METHOD_GET_RESP 0x81
  385. #define IB_MGMT_METHOD_SEND 0x03
  386. #define IB_MGMT_METHOD_TRAP 0x05
  387. #define IB_MGMT_METHOD_REPORT 0x06
  388. #define IB_MGMT_METHOD_REPORT_RESP 0x86
  389. #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
  390. #define IB_MGMT_METHOD_DELETE 0x15
  391. #define IB_MGMT_METHOD_RESP 0x80
  392. /* Subnet management attributes */
  393. #define IB_SMP_ATTR_NOTICE 0x0002
  394. #define IB_SMP_ATTR_NODE_DESC 0x0010
  395. #define IB_SMP_ATTR_NODE_INFO 0x0011
  396. #define IB_SMP_ATTR_SWITCH_INFO 0x0012
  397. #define IB_SMP_ATTR_GUID_INFO 0x0014
  398. #define IB_SMP_ATTR_PORT_INFO 0x0015
  399. #define IB_SMP_ATTR_PKEY_TABLE 0x0016
  400. #define IB_SMP_ATTR_SL_TO_VL_TABLE 0x0017
  401. #define IB_SMP_ATTR_VL_ARB_TABLE 0x0018
  402. #define IB_SMP_ATTR_LINEAR_FORWARD_TABLE 0x0019
  403. #define IB_SMP_ATTR_RANDOM_FORWARD_TABLE 0x001A
  404. #define IB_SMP_ATTR_MCAST_FORWARD_TABLE 0x001B
  405. #define IB_SMP_ATTR_SM_INFO 0x0020
  406. #define IB_SMP_ATTR_VENDOR_DIAG 0x0030
  407. #define IB_SMP_ATTR_LED_INFO 0x0031
  408. #define IB_SMP_ATTR_VENDOR_MASK 0xFF00
  409. #define IB_SA_ATTR_MC_MEMBER_REC 0x38
  410. #define IB_SA_ATTR_PATH_REC 0x35
  411. #define IB_SA_MCMEMBER_REC_MGID (1<<0)
  412. #define IB_SA_MCMEMBER_REC_PORT_GID (1<<1)
  413. #define IB_SA_MCMEMBER_REC_QKEY (1<<2)
  414. #define IB_SA_MCMEMBER_REC_MLID (1<<3)
  415. #define IB_SA_MCMEMBER_REC_MTU_SELECTOR (1<<4)
  416. #define IB_SA_MCMEMBER_REC_MTU (1<<5)
  417. #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS (1<<6)
  418. #define IB_SA_MCMEMBER_REC_PKEY (1<<7)
  419. #define IB_SA_MCMEMBER_REC_RATE_SELECTOR (1<<8)
  420. #define IB_SA_MCMEMBER_REC_RATE (1<<9)
  421. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR (1<<10)
  422. #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME (1<<11)
  423. #define IB_SA_MCMEMBER_REC_SL (1<<12)
  424. #define IB_SA_MCMEMBER_REC_FLOW_LABEL (1<<13)
  425. #define IB_SA_MCMEMBER_REC_HOP_LIMIT (1<<14)
  426. #define IB_SA_MCMEMBER_REC_SCOPE (1<<15)
  427. #define IB_SA_MCMEMBER_REC_JOIN_STATE (1<<16)
  428. #define IB_SA_MCMEMBER_REC_PROXY_JOIN (1<<17)
  429. #define IB_SA_PATH_REC_DGID (1<<2)
  430. #define IB_SA_PATH_REC_SGID (1<<3)
  431. struct ib_mad_hdr {
  432. uint8_t base_version;
  433. uint8_t mgmt_class;
  434. uint8_t class_version;
  435. uint8_t method;
  436. uint16_t status;
  437. uint16_t class_specific;
  438. uint32_t tid[2];
  439. uint16_t attr_id;
  440. uint16_t resv;
  441. uint32_t attr_mod;
  442. } __attribute__ (( packed ));
  443. struct ib_sa_hdr {
  444. uint32_t sm_key[2];
  445. uint16_t reserved;
  446. uint16_t attrib_offset;
  447. uint32_t comp_mask[2];
  448. } __attribute__ (( packed ));
  449. struct ib_rmpp_hdr {
  450. uint32_t raw[3];
  451. } __attribute__ (( packed ));
  452. struct ib_mad_data {
  453. struct ib_mad_hdr mad_hdr;
  454. uint8_t data[232];
  455. } __attribute__ (( packed ));
  456. struct ib_mad_guid_info {
  457. struct ib_mad_hdr mad_hdr;
  458. uint32_t mkey[2];
  459. uint32_t reserved[8];
  460. uint8_t gid_local[8];
  461. } __attribute__ (( packed ));
  462. struct ib_mad_port_info {
  463. struct ib_mad_hdr mad_hdr;
  464. uint32_t mkey[2];
  465. uint32_t reserved[8];
  466. uint32_t mkey2[2];
  467. uint8_t gid_prefix[8];
  468. uint16_t lid;
  469. uint16_t mastersm_lid;
  470. uint32_t cap_mask;
  471. uint16_t diag_code;
  472. uint16_t mkey_lease_period;
  473. uint8_t local_port_num;
  474. uint8_t link_width_enabled;
  475. uint8_t link_width_supported;
  476. uint8_t link_width_active;
  477. uint8_t port_state__link_speed_supported;
  478. uint8_t link_down_def_state__port_phys_state;
  479. uint8_t lmc__r1__mkey_prot_bits;
  480. uint8_t link_speed_enabled__link_speed_active;
  481. } __attribute__ (( packed ));
  482. struct ib_mad_pkey_table {
  483. struct ib_mad_hdr mad_hdr;
  484. uint32_t mkey[2];
  485. uint32_t reserved[8];
  486. uint16_t pkey[16][2];
  487. } __attribute__ (( packed ));
  488. struct ib_mad_path_record {
  489. struct ib_mad_hdr mad_hdr;
  490. struct ib_rmpp_hdr rmpp_hdr;
  491. struct ib_sa_hdr sa_hdr;
  492. uint32_t reserved0[2];
  493. struct ib_gid dgid;
  494. struct ib_gid sgid;
  495. uint16_t dlid;
  496. uint16_t slid;
  497. uint32_t hop_limit__flow_label__raw_traffic;
  498. uint32_t pkey__numb_path__reversible__tclass;
  499. uint8_t reserved1;
  500. uint8_t reserved__sl;
  501. uint8_t mtu_selector__mtu;
  502. uint8_t rate_selector__rate;
  503. uint32_t preference__packet_lifetime__packet_lifetime_selector;
  504. uint32_t reserved2[35];
  505. } __attribute__ (( packed ));
  506. struct ib_mad_mc_member_record {
  507. struct ib_mad_hdr mad_hdr;
  508. struct ib_rmpp_hdr rmpp_hdr;
  509. struct ib_sa_hdr sa_hdr;
  510. struct ib_gid mgid;
  511. struct ib_gid port_gid;
  512. uint32_t qkey;
  513. uint16_t mlid;
  514. uint8_t mtu_selector__mtu;
  515. uint8_t tclass;
  516. uint16_t pkey;
  517. uint8_t rate_selector__rate;
  518. uint8_t packet_lifetime_selector__packet_lifetime;
  519. uint32_t sl__flow_label__hop_limit;
  520. uint8_t scope__join_state;
  521. uint8_t proxy_join__reserved;
  522. uint16_t reserved0;
  523. uint32_t reserved1[37];
  524. } __attribute__ (( packed ));
  525. union ib_mad {
  526. struct ib_mad_hdr mad_hdr;
  527. struct ib_mad_data data;
  528. struct ib_mad_guid_info guid_info;
  529. struct ib_mad_port_info port_info;
  530. struct ib_mad_pkey_table pkey_table;
  531. struct ib_mad_path_record path_record;
  532. struct ib_mad_mc_member_record mc_member_record;
  533. } __attribute__ (( packed ));
  534. #endif /* _GPXE_INFINIBAND_H */