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 13KB

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