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.

hermon.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #ifndef _HERMON_H
  2. #define _HERMON_H
  3. /** @file
  4. *
  5. * Mellanox Hermon Infiniband HCA driver
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/uaccess.h>
  10. #include "mlx_bitops.h"
  11. #include "MT25408_PRM.h"
  12. /*
  13. * Hardware constants
  14. *
  15. */
  16. /* Ports in existence */
  17. #define HERMON_NUM_PORTS 2
  18. #define HERMON_PORT_BASE 1
  19. /* PCI BARs */
  20. #define HERMON_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
  21. #define HERMON_PCI_CONFIG_BAR_SIZE 0x100000
  22. #define HERMON_PCI_UAR_BAR PCI_BASE_ADDRESS_2
  23. /* Work queue entry and completion queue entry opcodes */
  24. #define HERMON_OPCODE_SEND 0x0a
  25. #define HERMON_OPCODE_RECV_ERROR 0xfe
  26. #define HERMON_OPCODE_SEND_ERROR 0xff
  27. /* HCA command register opcodes */
  28. #define HERMON_HCR_QUERY_DEV_CAP 0x0003
  29. #define HERMON_HCR_QUERY_FW 0x0004
  30. #define HERMON_HCR_INIT_HCA 0x0007
  31. #define HERMON_HCR_CLOSE_HCA 0x0008
  32. #define HERMON_HCR_INIT_PORT 0x0009
  33. #define HERMON_HCR_CLOSE_PORT 0x000a
  34. #define HERMON_HCR_SW2HW_MPT 0x000d
  35. #define HERMON_HCR_WRITE_MTT 0x0011
  36. #define HERMON_HCR_MAP_EQ 0x0012
  37. #define HERMON_HCR_SW2HW_EQ 0x0013
  38. #define HERMON_HCR_HW2SW_EQ 0x0014
  39. #define HERMON_HCR_QUERY_EQ 0x0015
  40. #define HERMON_HCR_SW2HW_CQ 0x0016
  41. #define HERMON_HCR_HW2SW_CQ 0x0017
  42. #define HERMON_HCR_RST2INIT_QP 0x0019
  43. #define HERMON_HCR_INIT2RTR_QP 0x001a
  44. #define HERMON_HCR_RTR2RTS_QP 0x001b
  45. #define HERMON_HCR_RTS2RTS_QP 0x001c
  46. #define HERMON_HCR_2RST_QP 0x0021
  47. #define HERMON_HCR_MAD_IFC 0x0024
  48. #define HERMON_HCR_READ_MCG 0x0025
  49. #define HERMON_HCR_WRITE_MCG 0x0026
  50. #define HERMON_HCR_MGID_HASH 0x0027
  51. #define HERMON_HCR_RUN_FW 0x0ff6
  52. #define HERMON_HCR_DISABLE_LAM 0x0ff7
  53. #define HERMON_HCR_ENABLE_LAM 0x0ff8
  54. #define HERMON_HCR_UNMAP_ICM 0x0ff9
  55. #define HERMON_HCR_MAP_ICM 0x0ffa
  56. #define HERMON_HCR_UNMAP_ICM_AUX 0x0ffb
  57. #define HERMON_HCR_MAP_ICM_AUX 0x0ffc
  58. #define HERMON_HCR_SET_ICM_SIZE 0x0ffd
  59. #define HERMON_HCR_UNMAP_FA 0x0ffe
  60. #define HERMON_HCR_MAP_FA 0x0fff
  61. /* Service types */
  62. #define HERMON_ST_UD 0x03
  63. /* MTUs */
  64. #define HERMON_MTU_2048 0x04
  65. #define HERMON_INVALID_LKEY 0x00000100UL
  66. #define HERMON_PAGE_SIZE 4096
  67. #define HERMON_DB_POST_SND_OFFSET 0x14
  68. #define HERMON_DB_EQ_OFFSET(_eqn) \
  69. ( 0x800 + HERMON_PAGE_SIZE * ( (_eqn) / 4 ) + 0x08 * ( (_eqn) % 4 ) )
  70. #define HERMON_QP_OPT_PARAM_QKEY 0x00000020UL
  71. #define HERMON_MAP_EQ ( 0UL << 31 )
  72. #define HERMON_UNMAP_EQ ( 1UL << 31 )
  73. #define HERMON_EV_PORT_STATE_CHANGE 0x09
  74. /*
  75. * Datatypes that seem to be missing from the autogenerated documentation
  76. *
  77. */
  78. struct hermonprm_mgm_hash_st {
  79. pseudo_bit_t reserved0[0x00020];
  80. /* -------------- */
  81. pseudo_bit_t hash[0x00010];
  82. pseudo_bit_t reserved1[0x00010];
  83. } __attribute__ (( packed ));
  84. struct hermonprm_mcg_entry_st {
  85. struct hermonprm_mcg_hdr_st hdr;
  86. struct hermonprm_mcg_qp_dw_st qp[8];
  87. } __attribute__ (( packed ));
  88. struct hermonprm_cq_db_record_st {
  89. pseudo_bit_t update_ci[0x00018];
  90. pseudo_bit_t reserved0[0x00008];
  91. /* -------------- */
  92. pseudo_bit_t arm_ci[0x00018];
  93. pseudo_bit_t cmd[0x00003];
  94. pseudo_bit_t reserved1[0x00001];
  95. pseudo_bit_t cmd_sn[0x00002];
  96. pseudo_bit_t reserved2[0x00002];
  97. } __attribute__ (( packed ));
  98. struct hermonprm_send_db_register_st {
  99. pseudo_bit_t reserved[0x00008];
  100. pseudo_bit_t qn[0x00018];
  101. } __attribute__ (( packed ));
  102. struct hermonprm_event_db_register_st {
  103. pseudo_bit_t ci[0x00018];
  104. pseudo_bit_t reserver[0x00007];
  105. pseudo_bit_t a[0x00001];
  106. } __attribute__ (( packed ));
  107. struct hermonprm_scalar_parameter_st {
  108. pseudo_bit_t value_hi[0x00020];
  109. /* -------------- */
  110. pseudo_bit_t value[0x00020];
  111. } __attribute__ (( packed ));
  112. struct hermonprm_event_mask_st {
  113. pseudo_bit_t reserved0[0x00020];
  114. /* -------------- */
  115. pseudo_bit_t completion[0x00001];
  116. pseudo_bit_t reserved1[0x0008];
  117. pseudo_bit_t port_state_change[0x00001];
  118. pseudo_bit_t reserved2[0x00016];
  119. } __attribute__ (( packed ));
  120. struct hermonprm_port_state_change_event_st {
  121. pseudo_bit_t reserved[0x00020];
  122. struct hermonprm_port_state_change_st data;
  123. } __attribute__ (( packed ));
  124. /*
  125. * Wrapper structures for hardware datatypes
  126. *
  127. */
  128. struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_context );
  129. struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_entry );
  130. struct MLX_DECLARE_STRUCT ( hermonprm_completion_with_error );
  131. struct MLX_DECLARE_STRUCT ( hermonprm_cq_db_record );
  132. struct MLX_DECLARE_STRUCT ( hermonprm_eqc );
  133. struct MLX_DECLARE_STRUCT ( hermonprm_event_db_register );
  134. struct MLX_DECLARE_STRUCT ( hermonprm_event_mask );
  135. struct MLX_DECLARE_STRUCT ( hermonprm_event_queue_entry );
  136. struct MLX_DECLARE_STRUCT ( hermonprm_hca_command_register );
  137. struct MLX_DECLARE_STRUCT ( hermonprm_init_hca );
  138. struct MLX_DECLARE_STRUCT ( hermonprm_init_port );
  139. struct MLX_DECLARE_STRUCT ( hermonprm_mad_ifc );
  140. struct MLX_DECLARE_STRUCT ( hermonprm_mcg_entry );
  141. struct MLX_DECLARE_STRUCT ( hermonprm_mgm_hash );
  142. struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
  143. struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
  144. struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
  145. struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
  146. struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
  147. struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
  148. struct MLX_DECLARE_STRUCT ( hermonprm_query_fw );
  149. struct MLX_DECLARE_STRUCT ( hermonprm_queue_pair_ee_context_entry );
  150. struct MLX_DECLARE_STRUCT ( hermonprm_scalar_parameter );
  151. struct MLX_DECLARE_STRUCT ( hermonprm_send_db_register );
  152. struct MLX_DECLARE_STRUCT ( hermonprm_ud_address_vector );
  153. struct MLX_DECLARE_STRUCT ( hermonprm_virtual_physical_mapping );
  154. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_send );
  155. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_data_ptr );
  156. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ud );
  157. /*
  158. * Composite hardware datatypes
  159. *
  160. */
  161. struct hermonprm_write_mtt {
  162. struct hermonprm_scalar_parameter mtt_base_addr;
  163. struct hermonprm_scalar_parameter reserved;
  164. struct hermonprm_mtt mtt;
  165. } __attribute__ (( packed ));
  166. #define HERMON_MAX_GATHER 1
  167. struct hermonprm_ud_send_wqe {
  168. struct hermonprm_wqe_segment_ctrl_send ctrl;
  169. struct hermonprm_wqe_segment_ud ud;
  170. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
  171. } __attribute__ (( packed ));
  172. #define HERMON_MAX_SCATTER 1
  173. struct hermonprm_recv_wqe {
  174. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
  175. } __attribute__ (( packed ));
  176. union hermonprm_completion_entry {
  177. struct hermonprm_completion_queue_entry normal;
  178. struct hermonprm_completion_with_error error;
  179. } __attribute__ (( packed ));
  180. union hermonprm_event_entry {
  181. struct hermonprm_event_queue_entry generic;
  182. struct hermonprm_port_state_change_event port_state_change;
  183. } __attribute__ (( packed ));
  184. union hermonprm_doorbell_register {
  185. struct hermonprm_send_db_register send;
  186. struct hermonprm_event_db_register event;
  187. uint32_t dword[1];
  188. } __attribute__ (( packed ));
  189. union hermonprm_mad {
  190. struct hermonprm_mad_ifc ifc;
  191. union ib_mad mad;
  192. } __attribute__ (( packed ));
  193. /*
  194. * gPXE-specific definitions
  195. *
  196. */
  197. /** Hermon device capabilitiess */
  198. struct hermon_dev_cap {
  199. /** CMPT entry size */
  200. size_t cmpt_entry_size;
  201. /** Number of reserved QPs */
  202. unsigned int reserved_qps;
  203. /** QP context entry size */
  204. size_t qpc_entry_size;
  205. /** Alternate path context entry size */
  206. size_t altc_entry_size;
  207. /** Auxiliary context entry size */
  208. size_t auxc_entry_size;
  209. /** Number of reserved SRQs */
  210. unsigned int reserved_srqs;
  211. /** SRQ context entry size */
  212. size_t srqc_entry_size;
  213. /** Number of reserved CQs */
  214. unsigned int reserved_cqs;
  215. /** CQ context entry size */
  216. size_t cqc_entry_size;
  217. /** Number of reserved EQs */
  218. unsigned int reserved_eqs;
  219. /** EQ context entry size */
  220. size_t eqc_entry_size;
  221. /** Number of reserved MTTs */
  222. unsigned int reserved_mtts;
  223. /** MTT entry size */
  224. size_t mtt_entry_size;
  225. /** Number of reserved MRWs */
  226. unsigned int reserved_mrws;
  227. /** DMPT entry size */
  228. size_t dmpt_entry_size;
  229. /** Number of reserved UARs */
  230. unsigned int reserved_uars;
  231. };
  232. /** Number of cMPT entries of each type */
  233. #define HERMON_CMPT_MAX_ENTRIES ( 1 << 24 )
  234. /** Hermon ICM memory map entry */
  235. struct hermon_icm_map {
  236. /** Offset (virtual address within ICM) */
  237. uint64_t offset;
  238. /** Length */
  239. size_t len;
  240. };
  241. /** Discontiguous regions within Hermon ICM */
  242. enum hermon_icm_map_regions {
  243. HERMON_ICM_QP_CMPT = 0,
  244. HERMON_ICM_SRQ_CMPT,
  245. HERMON_ICM_CQ_CMPT,
  246. HERMON_ICM_EQ_CMPT,
  247. HERMON_ICM_OTHER,
  248. HERMON_ICM_NUM_REGIONS
  249. };
  250. /** UAR page for doorbell accesses
  251. *
  252. * Pages 0-127 are reserved for event queue doorbells only, so we use
  253. * page 128.
  254. */
  255. #define HERMON_UAR_NON_EQ_PAGE 128
  256. /** Maximum number of allocatable MTT entries
  257. *
  258. * This is a policy decision, not a device limit.
  259. */
  260. #define HERMON_MAX_MTTS 64
  261. /** A Hermon MTT descriptor */
  262. struct hermon_mtt {
  263. /** MTT offset */
  264. unsigned int mtt_offset;
  265. /** Number of pages */
  266. unsigned int num_pages;
  267. /** MTT base address */
  268. unsigned int mtt_base_addr;
  269. /** Offset within page */
  270. unsigned int page_offset;
  271. };
  272. /** Alignment of Hermon send work queue entries */
  273. #define HERMON_SEND_WQE_ALIGN 128
  274. /** A Hermon send work queue entry */
  275. union hermon_send_wqe {
  276. struct hermonprm_ud_send_wqe ud;
  277. uint8_t force_align[HERMON_SEND_WQE_ALIGN];
  278. } __attribute__ (( packed ));
  279. /** A Hermon send work queue */
  280. struct hermon_send_work_queue {
  281. /** Number of work queue entries, including headroom
  282. *
  283. * Hermon requires us to leave unused space within the send
  284. * WQ, so we create a send WQ with more entries than are
  285. * requested in the create_qp() call.
  286. */
  287. unsigned int num_wqes;
  288. /** Work queue entries */
  289. union hermon_send_wqe *wqe;
  290. /** Size of work queue */
  291. size_t wqe_size;
  292. /** Doorbell register */
  293. void *doorbell;
  294. };
  295. /** Alignment of Hermon receive work queue entries */
  296. #define HERMON_RECV_WQE_ALIGN 16
  297. /** A Hermon receive work queue entry */
  298. union hermon_recv_wqe {
  299. struct hermonprm_recv_wqe recv;
  300. uint8_t force_align[HERMON_RECV_WQE_ALIGN];
  301. } __attribute__ (( packed ));
  302. /** A Hermon receive work queue */
  303. struct hermon_recv_work_queue {
  304. /** Work queue entries */
  305. union hermon_recv_wqe *wqe;
  306. /** Size of work queue */
  307. size_t wqe_size;
  308. /** Doorbell */
  309. struct hermonprm_qp_db_record doorbell __attribute__ (( aligned (4) ));
  310. };
  311. /** Maximum number of allocatable queue pairs
  312. *
  313. * This is a policy decision, not a device limit.
  314. */
  315. #define HERMON_MAX_QPS 8
  316. /** Base queue pair number */
  317. #define HERMON_QPN_BASE 0x550000
  318. /** A Hermon queue pair */
  319. struct hermon_queue_pair {
  320. /** Work queue buffer */
  321. void *wqe;
  322. /** Size of work queue buffer */
  323. size_t wqe_size;
  324. /** MTT descriptor */
  325. struct hermon_mtt mtt;
  326. /** Send work queue */
  327. struct hermon_send_work_queue send;
  328. /** Receive work queue */
  329. struct hermon_recv_work_queue recv;
  330. };
  331. /** Maximum number of allocatable completion queues
  332. *
  333. * This is a policy decision, not a device limit.
  334. */
  335. #define HERMON_MAX_CQS 8
  336. /** A Hermon completion queue */
  337. struct hermon_completion_queue {
  338. /** Completion queue entries */
  339. union hermonprm_completion_entry *cqe;
  340. /** Size of completion queue */
  341. size_t cqe_size;
  342. /** MTT descriptor */
  343. struct hermon_mtt mtt;
  344. /** Doorbell */
  345. struct hermonprm_cq_db_record doorbell __attribute__ (( aligned (8) ));
  346. };
  347. /** Maximum number of allocatable event queues
  348. *
  349. * This is a policy decision, not a device limit.
  350. */
  351. #define HERMON_MAX_EQS 8
  352. /** A Hermon event queue */
  353. struct hermon_event_queue {
  354. /** Event queue entries */
  355. union hermonprm_event_entry *eqe;
  356. /** Size of event queue */
  357. size_t eqe_size;
  358. /** MTT descriptor */
  359. struct hermon_mtt mtt;
  360. /** Event queue number */
  361. unsigned long eqn;
  362. /** Next event queue entry index */
  363. unsigned long next_idx;
  364. /** Doorbell register */
  365. void *doorbell;
  366. };
  367. /** Number of event queue entries
  368. *
  369. * This is a policy decision.
  370. */
  371. #define HERMON_NUM_EQES 4
  372. /** A Hermon resource bitmask */
  373. typedef uint32_t hermon_bitmask_t;
  374. /** Size of a hermon resource bitmask */
  375. #define HERMON_BITMASK_SIZE(max_entries) \
  376. ( ( (max_entries) + ( 8 * sizeof ( hermon_bitmask_t ) ) - 1 ) / \
  377. ( 8 * sizeof ( hermon_bitmask_t ) ) )
  378. /** A Hermon device */
  379. struct hermon {
  380. /** PCI configuration registers */
  381. void *config;
  382. /** PCI user Access Region */
  383. void *uar;
  384. /** Command toggle */
  385. unsigned int toggle;
  386. /** Command input mailbox */
  387. void *mailbox_in;
  388. /** Command output mailbox */
  389. void *mailbox_out;
  390. /** Firmware area in external memory */
  391. userptr_t firmware_area;
  392. /** ICM map */
  393. struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS];
  394. /** ICM area */
  395. userptr_t icm;
  396. /** Event queue */
  397. struct hermon_event_queue eq;
  398. /** Reserved LKey
  399. *
  400. * Used to get unrestricted memory access.
  401. */
  402. unsigned long reserved_lkey;
  403. /** Completion queue in-use bitmask */
  404. hermon_bitmask_t cq_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_CQS ) ];
  405. /** Queue pair in-use bitmask */
  406. hermon_bitmask_t qp_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_QPS ) ];
  407. /** MTT entry in-use bitmask */
  408. hermon_bitmask_t mtt_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_MTTS ) ];
  409. /** Device capabilities */
  410. struct hermon_dev_cap cap;
  411. /** Infiniband devices */
  412. struct ib_device *ibdev[HERMON_NUM_PORTS];
  413. };
  414. /** Global protection domain */
  415. #define HERMON_GLOBAL_PD 0x123456
  416. /** Memory key prefix */
  417. #define HERMON_MKEY_PREFIX 0x77000000UL
  418. /*
  419. * HCA commands
  420. *
  421. */
  422. #define HERMON_HCR_BASE 0x80680
  423. #define HERMON_HCR_REG(x) ( HERMON_HCR_BASE + 4 * (x) )
  424. #define HERMON_HCR_MAX_WAIT_MS 2000
  425. #define HERMON_MBOX_ALIGN 4096
  426. #define HERMON_MBOX_SIZE 512
  427. /* HCA command is split into
  428. *
  429. * bits 11:0 Opcode
  430. * bit 12 Input uses mailbox
  431. * bit 13 Output uses mailbox
  432. * bits 22:14 Input parameter length (in dwords)
  433. * bits 31:23 Output parameter length (in dwords)
  434. *
  435. * Encoding the information in this way allows us to cut out several
  436. * parameters to the hermon_command() call.
  437. */
  438. #define HERMON_HCR_IN_MBOX 0x00001000UL
  439. #define HERMON_HCR_OUT_MBOX 0x00002000UL
  440. #define HERMON_HCR_OPCODE( _command ) ( (_command) & 0xfff )
  441. #define HERMON_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
  442. #define HERMON_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
  443. /** Build HCR command from component parts */
  444. #define HERMON_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
  445. _out_mbox, _out_len ) \
  446. ( (_opcode) | \
  447. ( (_in_mbox) ? HERMON_HCR_IN_MBOX : 0 ) | \
  448. ( ( (_in_len) / 4 ) << 14 ) | \
  449. ( (_out_mbox) ? HERMON_HCR_OUT_MBOX : 0 ) | \
  450. ( ( (_out_len) / 4 ) << 23 ) )
  451. #define HERMON_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
  452. HERMON_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
  453. #define HERMON_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
  454. HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
  455. #define HERMON_HCR_VOID_CMD( _opcode ) \
  456. HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
  457. #endif /* _HERMON_H */