arbel.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. #ifndef _ARBEL_H
  2. #define _ARBEL_H
  3. /** @file
  4. *
  5. * Mellanox Arbel Infiniband HCA driver
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/uaccess.h>
  10. #include "mlx_bitops.h"
  11. #include "MT25218_PRM.h"
  12. /*
  13. * Hardware constants
  14. *
  15. */
  16. /* PCI BARs */
  17. #define ARBEL_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
  18. #define ARBEL_PCI_CONFIG_BAR_SIZE 0x100000
  19. #define ARBEL_PCI_UAR_BAR PCI_BASE_ADDRESS_2
  20. #define ARBEL_PCI_UAR_IDX 1
  21. #define ARBEL_PCI_UAR_SIZE 0x1000
  22. /* UAR context table (UCE) resource types */
  23. #define ARBEL_UAR_RES_NONE 0x00
  24. #define ARBEL_UAR_RES_CQ_CI 0x01
  25. #define ARBEL_UAR_RES_CQ_ARM 0x02
  26. #define ARBEL_UAR_RES_SQ 0x03
  27. #define ARBEL_UAR_RES_RQ 0x04
  28. #define ARBEL_UAR_RES_GROUP_SEP 0x07
  29. /* Work queue entry and completion queue entry opcodes */
  30. #define ARBEL_OPCODE_SEND 0x0a
  31. #define ARBEL_OPCODE_RECV_ERROR 0xfe
  32. #define ARBEL_OPCODE_SEND_ERROR 0xff
  33. /* HCA command register opcodes */
  34. #define ARBEL_HCR_QUERY_DEV_LIM 0x0003
  35. #define ARBEL_HCR_QUERY_FW 0x0004
  36. #define ARBEL_HCR_INIT_HCA 0x0007
  37. #define ARBEL_HCR_CLOSE_HCA 0x0008
  38. #define ARBEL_HCR_INIT_IB 0x0009
  39. #define ARBEL_HCR_CLOSE_IB 0x000a
  40. #define ARBEL_HCR_SW2HW_MPT 0x000d
  41. #define ARBEL_HCR_MAP_EQ 0x0012
  42. #define ARBEL_HCR_SW2HW_EQ 0x0013
  43. #define ARBEL_HCR_HW2SW_EQ 0x0014
  44. #define ARBEL_HCR_SW2HW_CQ 0x0016
  45. #define ARBEL_HCR_HW2SW_CQ 0x0017
  46. #define ARBEL_HCR_RST2INIT_QPEE 0x0019
  47. #define ARBEL_HCR_INIT2RTR_QPEE 0x001a
  48. #define ARBEL_HCR_RTR2RTS_QPEE 0x001b
  49. #define ARBEL_HCR_2RST_QPEE 0x0021
  50. #define ARBEL_HCR_MAD_IFC 0x0024
  51. #define ARBEL_HCR_READ_MGM 0x0025
  52. #define ARBEL_HCR_WRITE_MGM 0x0026
  53. #define ARBEL_HCR_MGID_HASH 0x0027
  54. #define ARBEL_HCR_RUN_FW 0x0ff6
  55. #define ARBEL_HCR_DISABLE_LAM 0x0ff7
  56. #define ARBEL_HCR_ENABLE_LAM 0x0ff8
  57. #define ARBEL_HCR_UNMAP_ICM 0x0ff9
  58. #define ARBEL_HCR_MAP_ICM 0x0ffa
  59. #define ARBEL_HCR_UNMAP_ICM_AUX 0x0ffb
  60. #define ARBEL_HCR_MAP_ICM_AUX 0x0ffc
  61. #define ARBEL_HCR_SET_ICM_SIZE 0x0ffd
  62. #define ARBEL_HCR_UNMAP_FA 0x0ffe
  63. #define ARBEL_HCR_MAP_FA 0x0fff
  64. /* Service types */
  65. #define ARBEL_ST_UD 0x03
  66. /* MTUs */
  67. #define ARBEL_MTU_2048 0x04
  68. #define ARBEL_NO_EQ 64
  69. #define ARBEL_INVALID_LKEY 0x00000100UL
  70. #define ARBEL_DB_POST_SND_OFFSET 0x10
  71. /*
  72. * Datatypes that seem to be missing from the autogenerated documentation
  73. *
  74. */
  75. struct arbelprm_mgm_hash_st {
  76. pseudo_bit_t reserved0[0x00020];
  77. /* -------------- */
  78. pseudo_bit_t hash[0x00010];
  79. pseudo_bit_t reserved1[0x00010];
  80. } __attribute__ (( packed ));
  81. struct arbelprm_scalar_parameter_st {
  82. pseudo_bit_t reserved0[0x00020];
  83. /* -------------- */
  84. pseudo_bit_t value[0x00020];
  85. } __attribute__ (( packed ));
  86. /*
  87. * Wrapper structures for hardware datatypes
  88. *
  89. */
  90. struct MLX_DECLARE_STRUCT ( arbelprm_access_lam );
  91. struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_context );
  92. struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_entry );
  93. struct MLX_DECLARE_STRUCT ( arbelprm_completion_with_error );
  94. struct MLX_DECLARE_STRUCT ( arbelprm_cq_arm_db_record );
  95. struct MLX_DECLARE_STRUCT ( arbelprm_cq_ci_db_record );
  96. struct MLX_DECLARE_STRUCT ( arbelprm_eqc );
  97. struct MLX_DECLARE_STRUCT ( arbelprm_hca_command_register );
  98. struct MLX_DECLARE_STRUCT ( arbelprm_init_hca );
  99. struct MLX_DECLARE_STRUCT ( arbelprm_init_ib );
  100. struct MLX_DECLARE_STRUCT ( arbelprm_mad_ifc );
  101. struct MLX_DECLARE_STRUCT ( arbelprm_mgm_entry );
  102. struct MLX_DECLARE_STRUCT ( arbelprm_mgm_hash );
  103. struct MLX_DECLARE_STRUCT ( arbelprm_mpt );
  104. struct MLX_DECLARE_STRUCT ( arbelprm_qp_db_record );
  105. struct MLX_DECLARE_STRUCT ( arbelprm_qp_ee_state_transitions );
  106. struct MLX_DECLARE_STRUCT ( arbelprm_query_dev_lim );
  107. struct MLX_DECLARE_STRUCT ( arbelprm_query_fw );
  108. struct MLX_DECLARE_STRUCT ( arbelprm_queue_pair_ee_context_entry );
  109. struct MLX_DECLARE_STRUCT ( arbelprm_recv_wqe_segment_next );
  110. struct MLX_DECLARE_STRUCT ( arbelprm_scalar_parameter );
  111. struct MLX_DECLARE_STRUCT ( arbelprm_send_doorbell );
  112. struct MLX_DECLARE_STRUCT ( arbelprm_ud_address_vector );
  113. struct MLX_DECLARE_STRUCT ( arbelprm_virtual_physical_mapping );
  114. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_send );
  115. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_data_ptr );
  116. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_next );
  117. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ud );
  118. /*
  119. * Composite hardware datatypes
  120. *
  121. */
  122. #define ARBEL_MAX_GATHER 1
  123. struct arbelprm_ud_send_wqe {
  124. struct arbelprm_wqe_segment_next next;
  125. struct arbelprm_wqe_segment_ctrl_send ctrl;
  126. struct arbelprm_wqe_segment_ud ud;
  127. struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
  128. } __attribute__ (( packed ));
  129. #define ARBEL_MAX_SCATTER 1
  130. struct arbelprm_recv_wqe {
  131. /* The autogenerated header is inconsistent between send and
  132. * receive WQEs. The "ctrl" structure for receive WQEs is
  133. * defined to include the "next" structure. Since the "ctrl"
  134. * part of the "ctrl" structure contains only "reserved, must
  135. * be zero" bits, we ignore its definition and provide
  136. * something more usable.
  137. */
  138. struct arbelprm_recv_wqe_segment_next next;
  139. uint32_t ctrl[2]; /* All "reserved, must be zero" */
  140. struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_SCATTER];
  141. } __attribute__ (( packed ));
  142. union arbelprm_completion_entry {
  143. struct arbelprm_completion_queue_entry normal;
  144. struct arbelprm_completion_with_error error;
  145. } __attribute__ (( packed ));
  146. union arbelprm_doorbell_record {
  147. struct arbelprm_cq_arm_db_record cq_arm;
  148. struct arbelprm_cq_ci_db_record cq_ci;
  149. struct arbelprm_qp_db_record qp;
  150. } __attribute__ (( packed ));
  151. union arbelprm_doorbell_register {
  152. struct arbelprm_send_doorbell send;
  153. uint32_t dword[2];
  154. } __attribute__ (( packed ));
  155. union arbelprm_mad {
  156. struct arbelprm_mad_ifc ifc;
  157. union ib_mad mad;
  158. } __attribute__ (( packed ));
  159. /*
  160. * gPXE-specific definitions
  161. *
  162. */
  163. /** Arbel device limits */
  164. struct arbel_dev_limits {
  165. /** Number of reserved QPs */
  166. unsigned int reserved_qps;
  167. /** QP context entry size */
  168. size_t qpc_entry_size;
  169. /** Extended QP context entry size */
  170. size_t eqpc_entry_size;
  171. /** Number of reserved SRQs */
  172. unsigned int reserved_srqs;
  173. /** SRQ context entry size */
  174. size_t srqc_entry_size;
  175. /** Number of reserved EEs */
  176. unsigned int reserved_ees;
  177. /** EE context entry size */
  178. size_t eec_entry_size;
  179. /** Extended EE context entry size */
  180. size_t eeec_entry_size;
  181. /** Number of reserved CQs */
  182. unsigned int reserved_cqs;
  183. /** CQ context entry size */
  184. size_t cqc_entry_size;
  185. /** Number of reserved MTTs */
  186. unsigned int reserved_mtts;
  187. /** MTT entry size */
  188. size_t mtt_entry_size;
  189. /** Number of reserved MRWs */
  190. unsigned int reserved_mrws;
  191. /** MPT entry size */
  192. size_t mpt_entry_size;
  193. /** Number of reserved RDBs */
  194. unsigned int reserved_rdbs;
  195. /** EQ context entry size */
  196. size_t eqc_entry_size;
  197. /** Number of reserved UARs */
  198. unsigned int reserved_uars;
  199. };
  200. /** Alignment of Arbel send work queue entries */
  201. #define ARBEL_SEND_WQE_ALIGN 128
  202. /** An Arbel send work queue entry */
  203. union arbel_send_wqe {
  204. struct arbelprm_ud_send_wqe ud;
  205. uint8_t force_align[ARBEL_SEND_WQE_ALIGN];
  206. } __attribute__ (( packed ));
  207. /** An Arbel send work queue */
  208. struct arbel_send_work_queue {
  209. /** Doorbell record number */
  210. unsigned int doorbell_idx;
  211. /** Work queue entries */
  212. union arbel_send_wqe *wqe;
  213. /** Size of work queue */
  214. size_t wqe_size;
  215. };
  216. /** Alignment of Arbel receive work queue entries */
  217. #define ARBEL_RECV_WQE_ALIGN 64
  218. /** An Arbel receive work queue entry */
  219. union arbel_recv_wqe {
  220. struct arbelprm_recv_wqe recv;
  221. uint8_t force_align[ARBEL_RECV_WQE_ALIGN];
  222. } __attribute__ (( packed ));
  223. /** An Arbel receive work queue */
  224. struct arbel_recv_work_queue {
  225. /** Doorbell record number */
  226. unsigned int doorbell_idx;
  227. /** Work queue entries */
  228. union arbel_recv_wqe *wqe;
  229. /** Size of work queue */
  230. size_t wqe_size;
  231. };
  232. /** Maximum number of allocatable queue pairs
  233. *
  234. * This is a policy decision, not a device limit.
  235. */
  236. #define ARBEL_MAX_QPS 8
  237. /** Base queue pair number */
  238. #define ARBEL_QPN_BASE 0x550000
  239. /** An Arbel queue pair */
  240. struct arbel_queue_pair {
  241. /** Send work queue */
  242. struct arbel_send_work_queue send;
  243. /** Receive work queue */
  244. struct arbel_recv_work_queue recv;
  245. };
  246. /** Maximum number of allocatable completion queues
  247. *
  248. * This is a policy decision, not a device limit.
  249. */
  250. #define ARBEL_MAX_CQS 8
  251. /** An Arbel completion queue */
  252. struct arbel_completion_queue {
  253. /** Consumer counter doorbell record number */
  254. unsigned int ci_doorbell_idx;
  255. /** Arm queue doorbell record number */
  256. unsigned int arm_doorbell_idx;
  257. /** Completion queue entries */
  258. union arbelprm_completion_entry *cqe;
  259. /** Size of completion queue */
  260. size_t cqe_size;
  261. };
  262. /** An Arbel resource bitmask */
  263. typedef uint32_t arbel_bitmask_t;
  264. /** Size of an Arbel resource bitmask */
  265. #define ARBEL_BITMASK_SIZE(max_entries) \
  266. ( ( (max_entries) + ( 8 * sizeof ( arbel_bitmask_t ) ) - 1 ) / \
  267. ( 8 * sizeof ( arbel_bitmask_t ) ) )
  268. /** An Arbel device */
  269. struct arbel {
  270. /** PCI configuration registers */
  271. void *config;
  272. /** PCI user Access Region */
  273. void *uar;
  274. /** Command input mailbox */
  275. void *mailbox_in;
  276. /** Command output mailbox */
  277. void *mailbox_out;
  278. /** Firmware area in external memory */
  279. userptr_t firmware_area;
  280. /** ICM size */
  281. size_t icm_len;
  282. /** ICM AUX size */
  283. size_t icm_aux_len;
  284. /** ICM area */
  285. userptr_t icm;
  286. /** Doorbell records */
  287. union arbelprm_doorbell_record *db_rec;
  288. /** Reserved LKey
  289. *
  290. * Used to get unrestricted memory access.
  291. */
  292. unsigned long reserved_lkey;
  293. /** Completion queue in-use bitmask */
  294. arbel_bitmask_t cq_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_CQS ) ];
  295. /** Queue pair in-use bitmask */
  296. arbel_bitmask_t qp_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_QPS ) ];
  297. /** Device limits */
  298. struct arbel_dev_limits limits;
  299. };
  300. /** Global protection domain */
  301. #define ARBEL_GLOBAL_PD 0x123456
  302. /** Memory key prefix */
  303. #define ARBEL_MKEY_PREFIX 0x77000000UL
  304. /*
  305. * HCA commands
  306. *
  307. */
  308. #define ARBEL_HCR_BASE 0x80680
  309. #define ARBEL_HCR_REG(x) ( ARBEL_HCR_BASE + 4 * (x) )
  310. #define ARBEL_HCR_MAX_WAIT_MS 2000
  311. #define ARBEL_MBOX_ALIGN 4096
  312. #define ARBEL_MBOX_SIZE 512
  313. /* HCA command is split into
  314. *
  315. * bits 11:0 Opcode
  316. * bit 12 Input uses mailbox
  317. * bit 13 Output uses mailbox
  318. * bits 22:14 Input parameter length (in dwords)
  319. * bits 31:23 Output parameter length (in dwords)
  320. *
  321. * Encoding the information in this way allows us to cut out several
  322. * parameters to the arbel_command() call.
  323. */
  324. #define ARBEL_HCR_IN_MBOX 0x00001000UL
  325. #define ARBEL_HCR_OUT_MBOX 0x00002000UL
  326. #define ARBEL_HCR_OPCODE( _command ) ( (_command) & 0xfff )
  327. #define ARBEL_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
  328. #define ARBEL_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
  329. /** Build HCR command from component parts */
  330. #define ARBEL_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
  331. _out_mbox, _out_len ) \
  332. ( (_opcode) | \
  333. ( (_in_mbox) ? ARBEL_HCR_IN_MBOX : 0 ) | \
  334. ( ( (_in_len) / 4 ) << 14 ) | \
  335. ( (_out_mbox) ? ARBEL_HCR_OUT_MBOX : 0 ) | \
  336. ( ( (_out_len) / 4 ) << 23 ) )
  337. #define ARBEL_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
  338. ARBEL_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
  339. #define ARBEL_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
  340. ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
  341. #define ARBEL_HCR_VOID_CMD( _opcode ) \
  342. ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
  343. /*
  344. * Doorbell record allocation
  345. *
  346. * The doorbell record map looks like:
  347. *
  348. * ARBEL_MAX_CQS * Arm completion queue doorbell
  349. * ARBEL_MAX_QPS * Send work request doorbell
  350. * Group separator
  351. * ...(empty space)...
  352. * ARBEL_MAX_QPS * Receive work request doorbell
  353. * ARBEL_MAX_CQS * Completion queue consumer counter update doorbell
  354. */
  355. #define ARBEL_MAX_DOORBELL_RECORDS 512
  356. #define ARBEL_GROUP_SEPARATOR_DOORBELL ( ARBEL_MAX_CQS + ARBEL_MAX_QPS )
  357. /**
  358. * Get arm completion queue doorbell index
  359. *
  360. * @v cqn_offset Completion queue number offset
  361. * @ret doorbell_idx Doorbell index
  362. */
  363. static inline unsigned int
  364. arbel_cq_arm_doorbell_idx ( unsigned int cqn_offset ) {
  365. return cqn_offset;
  366. }
  367. /**
  368. * Get send work request doorbell index
  369. *
  370. * @v qpn_offset Queue pair number offset
  371. * @ret doorbell_idx Doorbell index
  372. */
  373. static inline unsigned int
  374. arbel_send_doorbell_idx ( unsigned int qpn_offset ) {
  375. return ( ARBEL_MAX_CQS + qpn_offset );
  376. }
  377. /**
  378. * Get receive work request doorbell index
  379. *
  380. * @v qpn_offset Queue pair number offset
  381. * @ret doorbell_idx Doorbell index
  382. */
  383. static inline unsigned int
  384. arbel_recv_doorbell_idx ( unsigned int qpn_offset ) {
  385. return ( ARBEL_MAX_DOORBELL_RECORDS - ARBEL_MAX_CQS - qpn_offset - 1 );
  386. }
  387. /**
  388. * Get completion queue consumer counter doorbell index
  389. *
  390. * @v cqn_offset Completion queue number offset
  391. * @ret doorbell_idx Doorbell index
  392. */
  393. static inline unsigned int
  394. arbel_cq_ci_doorbell_idx ( unsigned int cqn_offset ) {
  395. return ( ARBEL_MAX_DOORBELL_RECORDS - cqn_offset - 1 );
  396. }
  397. #endif /* _ARBEL_H */