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.

arbel.h 12KB

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