Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. #ifndef _ARBEL_H
  2. #define _ARBEL_H
  3. /** @file
  4. *
  5. * Mellanox Arbel Infiniband HCA driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <ipxe/uaccess.h>
  11. #include <ipxe/ib_packet.h>
  12. #include "mlx_bitops.h"
  13. #include "MT25218_PRM.h"
  14. /*
  15. * Hardware constants
  16. *
  17. */
  18. /* Ports in existence */
  19. #define ARBEL_NUM_PORTS 2
  20. #define ARBEL_PORT_BASE 1
  21. /* PCI BARs */
  22. #define ARBEL_PCI_CONFIG_BAR PCI_BASE_ADDRESS_0
  23. #define ARBEL_PCI_CONFIG_BAR_SIZE 0x100000
  24. #define ARBEL_PCI_UAR_BAR PCI_BASE_ADDRESS_2
  25. #define ARBEL_PCI_UAR_IDX 1
  26. #define ARBEL_PCI_UAR_SIZE 0x1000
  27. /* UAR context table (UCE) resource types */
  28. #define ARBEL_UAR_RES_NONE 0x00
  29. #define ARBEL_UAR_RES_CQ_CI 0x01
  30. #define ARBEL_UAR_RES_CQ_ARM 0x02
  31. #define ARBEL_UAR_RES_SQ 0x03
  32. #define ARBEL_UAR_RES_RQ 0x04
  33. #define ARBEL_UAR_RES_GROUP_SEP 0x07
  34. /* Work queue entry and completion queue entry opcodes */
  35. #define ARBEL_OPCODE_SEND 0x0a
  36. #define ARBEL_OPCODE_RECV_ERROR 0xfe
  37. #define ARBEL_OPCODE_SEND_ERROR 0xff
  38. /* HCA command register opcodes */
  39. #define ARBEL_HCR_QUERY_DEV_LIM 0x0003
  40. #define ARBEL_HCR_QUERY_FW 0x0004
  41. #define ARBEL_HCR_INIT_HCA 0x0007
  42. #define ARBEL_HCR_CLOSE_HCA 0x0008
  43. #define ARBEL_HCR_INIT_IB 0x0009
  44. #define ARBEL_HCR_CLOSE_IB 0x000a
  45. #define ARBEL_HCR_SW2HW_MPT 0x000d
  46. #define ARBEL_HCR_MAP_EQ 0x0012
  47. #define ARBEL_HCR_SW2HW_EQ 0x0013
  48. #define ARBEL_HCR_HW2SW_EQ 0x0014
  49. #define ARBEL_HCR_SW2HW_CQ 0x0016
  50. #define ARBEL_HCR_HW2SW_CQ 0x0017
  51. #define ARBEL_HCR_QUERY_CQ 0x0018
  52. #define ARBEL_HCR_RST2INIT_QPEE 0x0019
  53. #define ARBEL_HCR_INIT2RTR_QPEE 0x001a
  54. #define ARBEL_HCR_RTR2RTS_QPEE 0x001b
  55. #define ARBEL_HCR_RTS2RTS_QPEE 0x001c
  56. #define ARBEL_HCR_2RST_QPEE 0x0021
  57. #define ARBEL_HCR_QUERY_QPEE 0x0022
  58. #define ARBEL_HCR_CONF_SPECIAL_QP 0x0023
  59. #define ARBEL_HCR_MAD_IFC 0x0024
  60. #define ARBEL_HCR_READ_MGM 0x0025
  61. #define ARBEL_HCR_WRITE_MGM 0x0026
  62. #define ARBEL_HCR_MGID_HASH 0x0027
  63. #define ARBEL_HCR_RUN_FW 0x0ff6
  64. #define ARBEL_HCR_DISABLE_LAM 0x0ff7
  65. #define ARBEL_HCR_ENABLE_LAM 0x0ff8
  66. #define ARBEL_HCR_UNMAP_ICM 0x0ff9
  67. #define ARBEL_HCR_MAP_ICM 0x0ffa
  68. #define ARBEL_HCR_UNMAP_ICM_AUX 0x0ffb
  69. #define ARBEL_HCR_MAP_ICM_AUX 0x0ffc
  70. #define ARBEL_HCR_SET_ICM_SIZE 0x0ffd
  71. #define ARBEL_HCR_UNMAP_FA 0x0ffe
  72. #define ARBEL_HCR_MAP_FA 0x0fff
  73. /* Service types */
  74. #define ARBEL_ST_UD 0x03
  75. #define ARBEL_ST_MLX 0x07
  76. /* MTUs */
  77. #define ARBEL_MTU_2048 0x04
  78. #define ARBEL_NO_EQ 64
  79. #define ARBEL_INVALID_LKEY 0x00000100UL
  80. #define ARBEL_PAGE_SIZE 4096
  81. #define ARBEL_RDB_ENTRY_SIZE 32
  82. #define ARBEL_DB_POST_SND_OFFSET 0x10
  83. #define ARBEL_DB_EQ_OFFSET(_eqn) ( 0x08 * (_eqn) )
  84. #define ARBEL_QPEE_OPT_PARAM_QKEY 0x00000020UL
  85. #define ARBEL_MAP_EQ ( 0UL << 31 )
  86. #define ARBEL_UNMAP_EQ ( 1UL << 31 )
  87. #define ARBEL_EV_PORT_STATE_CHANGE 0x09
  88. #define ARBEL_LOG_MULTICAST_HASH_SIZE 3
  89. /*
  90. * Datatypes that seem to be missing from the autogenerated documentation
  91. *
  92. */
  93. struct arbelprm_mgm_hash_st {
  94. pseudo_bit_t reserved0[0x00020];
  95. /* -------------- */
  96. pseudo_bit_t hash[0x00010];
  97. pseudo_bit_t reserved1[0x00010];
  98. } __attribute__ (( packed ));
  99. struct arbelprm_scalar_parameter_st {
  100. pseudo_bit_t reserved0[0x00020];
  101. /* -------------- */
  102. pseudo_bit_t value[0x00020];
  103. } __attribute__ (( packed ));
  104. struct arbelprm_event_mask_st {
  105. pseudo_bit_t reserved0[0x00020];
  106. /* -------------- */
  107. pseudo_bit_t completion[0x00001];
  108. pseudo_bit_t path_migration_succeeded[0x00001];
  109. pseudo_bit_t communication_established[0x00001];
  110. pseudo_bit_t send_queue_drained[0x00001];
  111. pseudo_bit_t cq_error[0x00001];
  112. pseudo_bit_t wq_catastrophe[0x00001];
  113. pseudo_bit_t qpc_catastrophe[0x00001];
  114. pseudo_bit_t path_migration_failed[0x00001];
  115. pseudo_bit_t reserved1[0x00001];
  116. pseudo_bit_t port_state_change[0x00001];
  117. pseudo_bit_t command_done[0x00001];
  118. pseudo_bit_t reserved2[0x00005];
  119. pseudo_bit_t wq_invalid_request[0x00001];
  120. pseudo_bit_t wq_access_violation[0x00001];
  121. pseudo_bit_t srq_catastrophe[0x00001];
  122. pseudo_bit_t srq_last_wqe[0x00001];
  123. pseudo_bit_t srq_rq_limit[0x00001];
  124. pseudo_bit_t gpio[0x00001];
  125. pseudo_bit_t clientreregister[0x00001];
  126. pseudo_bit_t path_migration_armed[0x00001];
  127. pseudo_bit_t reserved3[0x00008];
  128. } __attribute__ (( packed ));
  129. struct arbelprm_eq_set_ci_st {
  130. pseudo_bit_t ci[0x00020];
  131. } __attribute__ (( packed ));
  132. struct arbelprm_port_state_change_event_st {
  133. pseudo_bit_t reserved[0x00020];
  134. struct arbelprm_port_state_change_st data;
  135. } __attribute__ (( packed ));
  136. /*
  137. * Wrapper structures for hardware datatypes
  138. *
  139. */
  140. struct MLX_DECLARE_STRUCT ( arbelprm_access_lam );
  141. struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_context );
  142. struct MLX_DECLARE_STRUCT ( arbelprm_completion_queue_entry );
  143. struct MLX_DECLARE_STRUCT ( arbelprm_completion_with_error );
  144. struct MLX_DECLARE_STRUCT ( arbelprm_cq_arm_db_record );
  145. struct MLX_DECLARE_STRUCT ( arbelprm_cq_ci_db_record );
  146. struct MLX_DECLARE_STRUCT ( arbelprm_event_mask );
  147. struct MLX_DECLARE_STRUCT ( arbelprm_event_queue_entry );
  148. struct MLX_DECLARE_STRUCT ( arbelprm_eq_set_ci );
  149. struct MLX_DECLARE_STRUCT ( arbelprm_eqc );
  150. struct MLX_DECLARE_STRUCT ( arbelprm_hca_command_register );
  151. struct MLX_DECLARE_STRUCT ( arbelprm_init_hca );
  152. struct MLX_DECLARE_STRUCT ( arbelprm_init_ib );
  153. struct MLX_DECLARE_STRUCT ( arbelprm_mad_ifc );
  154. struct MLX_DECLARE_STRUCT ( arbelprm_mgm_entry );
  155. struct MLX_DECLARE_STRUCT ( arbelprm_mgm_hash );
  156. struct MLX_DECLARE_STRUCT ( arbelprm_mpt );
  157. struct MLX_DECLARE_STRUCT ( arbelprm_port_state_change_event );
  158. struct MLX_DECLARE_STRUCT ( arbelprm_qp_db_record );
  159. struct MLX_DECLARE_STRUCT ( arbelprm_qp_ee_state_transitions );
  160. struct MLX_DECLARE_STRUCT ( arbelprm_query_dev_lim );
  161. struct MLX_DECLARE_STRUCT ( arbelprm_query_fw );
  162. struct MLX_DECLARE_STRUCT ( arbelprm_queue_pair_ee_context_entry );
  163. struct MLX_DECLARE_STRUCT ( arbelprm_recv_wqe_segment_next );
  164. struct MLX_DECLARE_STRUCT ( arbelprm_scalar_parameter );
  165. struct MLX_DECLARE_STRUCT ( arbelprm_send_doorbell );
  166. struct MLX_DECLARE_STRUCT ( arbelprm_ud_address_vector );
  167. struct MLX_DECLARE_STRUCT ( arbelprm_virtual_physical_mapping );
  168. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_mlx );
  169. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ctrl_send );
  170. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_data_ptr );
  171. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_next );
  172. struct MLX_DECLARE_STRUCT ( arbelprm_wqe_segment_ud );
  173. /*
  174. * Composite hardware datatypes
  175. *
  176. */
  177. #define ARBEL_MAX_GATHER 2
  178. struct arbelprm_ud_send_wqe {
  179. struct arbelprm_wqe_segment_next next;
  180. struct arbelprm_wqe_segment_ctrl_send ctrl;
  181. struct arbelprm_wqe_segment_ud ud;
  182. struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
  183. } __attribute__ (( packed ));
  184. struct arbelprm_mlx_send_wqe {
  185. struct arbelprm_wqe_segment_next next;
  186. struct arbelprm_wqe_segment_ctrl_mlx ctrl;
  187. struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER];
  188. uint8_t headers[IB_MAX_HEADER_SIZE];
  189. } __attribute__ (( packed ));
  190. #define ARBEL_MAX_SCATTER 1
  191. struct arbelprm_recv_wqe {
  192. /* The autogenerated header is inconsistent between send and
  193. * receive WQEs. The "ctrl" structure for receive WQEs is
  194. * defined to include the "next" structure. Since the "ctrl"
  195. * part of the "ctrl" structure contains only "reserved, must
  196. * be zero" bits, we ignore its definition and provide
  197. * something more usable.
  198. */
  199. struct arbelprm_recv_wqe_segment_next next;
  200. uint32_t ctrl[2]; /* All "reserved, must be zero" */
  201. struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_SCATTER];
  202. } __attribute__ (( packed ));
  203. union arbelprm_completion_entry {
  204. struct arbelprm_completion_queue_entry normal;
  205. struct arbelprm_completion_with_error error;
  206. } __attribute__ (( packed ));
  207. union arbelprm_event_entry {
  208. struct arbelprm_event_queue_entry generic;
  209. struct arbelprm_port_state_change_event port_state_change;
  210. } __attribute__ (( packed ));
  211. union arbelprm_doorbell_record {
  212. struct arbelprm_cq_arm_db_record cq_arm;
  213. struct arbelprm_cq_ci_db_record cq_ci;
  214. struct arbelprm_qp_db_record qp;
  215. } __attribute__ (( packed ));
  216. union arbelprm_doorbell_register {
  217. struct arbelprm_send_doorbell send;
  218. uint32_t dword[2];
  219. } __attribute__ (( packed ));
  220. union arbelprm_eq_doorbell_register {
  221. struct arbelprm_eq_set_ci ci;
  222. uint32_t dword[1];
  223. } __attribute__ (( packed ));
  224. union arbelprm_mad {
  225. struct arbelprm_mad_ifc ifc;
  226. union ib_mad mad;
  227. } __attribute__ (( packed ));
  228. /*
  229. * iPXE-specific definitions
  230. *
  231. */
  232. /** Arbel device limits */
  233. struct arbel_dev_limits {
  234. /** Number of reserved QPs */
  235. unsigned int reserved_qps;
  236. /** QP context entry size */
  237. size_t qpc_entry_size;
  238. /** Extended QP context entry size */
  239. size_t eqpc_entry_size;
  240. /** Number of reserved SRQs */
  241. unsigned int reserved_srqs;
  242. /** SRQ context entry size */
  243. size_t srqc_entry_size;
  244. /** Number of reserved EEs */
  245. unsigned int reserved_ees;
  246. /** EE context entry size */
  247. size_t eec_entry_size;
  248. /** Extended EE context entry size */
  249. size_t eeec_entry_size;
  250. /** Number of reserved CQs */
  251. unsigned int reserved_cqs;
  252. /** CQ context entry size */
  253. size_t cqc_entry_size;
  254. /** Number of reserved EQs */
  255. unsigned int reserved_eqs;
  256. /** Number of reserved MTTs */
  257. unsigned int reserved_mtts;
  258. /** MTT entry size */
  259. size_t mtt_entry_size;
  260. /** Number of reserved MRWs */
  261. unsigned int reserved_mrws;
  262. /** MPT entry size */
  263. size_t mpt_entry_size;
  264. /** Number of reserved RDBs */
  265. unsigned int reserved_rdbs;
  266. /** EQ context entry size */
  267. size_t eqc_entry_size;
  268. /** Number of reserved UARs */
  269. unsigned int reserved_uars;
  270. };
  271. /** Alignment of Arbel send work queue entries */
  272. #define ARBEL_SEND_WQE_ALIGN 128
  273. /** An Arbel send work queue entry */
  274. union arbel_send_wqe {
  275. struct arbelprm_wqe_segment_next next;
  276. struct arbelprm_ud_send_wqe ud;
  277. struct arbelprm_mlx_send_wqe mlx;
  278. uint8_t force_align[ARBEL_SEND_WQE_ALIGN];
  279. } __attribute__ (( packed ));
  280. /** An Arbel send work queue */
  281. struct arbel_send_work_queue {
  282. /** Doorbell record number */
  283. unsigned int doorbell_idx;
  284. /** Work queue entries */
  285. union arbel_send_wqe *wqe;
  286. /** Size of work queue */
  287. size_t wqe_size;
  288. };
  289. /** Alignment of Arbel receive work queue entries */
  290. #define ARBEL_RECV_WQE_ALIGN 64
  291. /** An Arbel receive work queue entry */
  292. union arbel_recv_wqe {
  293. struct arbelprm_recv_wqe recv;
  294. uint8_t force_align[ARBEL_RECV_WQE_ALIGN];
  295. } __attribute__ (( packed ));
  296. /** An Arbel receive work queue */
  297. struct arbel_recv_work_queue {
  298. /** Doorbell record number */
  299. unsigned int doorbell_idx;
  300. /** Work queue entries */
  301. union arbel_recv_wqe *wqe;
  302. /** Size of work queue */
  303. size_t wqe_size;
  304. };
  305. /** Number of special queue pairs */
  306. #define ARBEL_NUM_SPECIAL_QPS 4
  307. /** Number of queue pairs reserved for the "special QP" block
  308. *
  309. * The special QPs must be in (2n,2n+1) pairs, hence we need to
  310. * reserve one extra QP to allow for alignment.
  311. */
  312. #define ARBEL_RSVD_SPECIAL_QPS ( ARBEL_NUM_SPECIAL_QPS + 1 )
  313. /** Maximum number of allocatable queue pairs
  314. *
  315. * This is a policy decision, not a device limit.
  316. */
  317. #define ARBEL_MAX_QPS 8
  318. /** Queue pair number randomisation mask */
  319. #define ARBEL_QPN_RANDOM_MASK 0xfff000
  320. /** Arbel queue pair state */
  321. enum arbel_queue_pair_state {
  322. ARBEL_QP_ST_RST = 0,
  323. ARBEL_QP_ST_INIT,
  324. ARBEL_QP_ST_RTR,
  325. ARBEL_QP_ST_RTS,
  326. };
  327. /** An Arbel queue pair */
  328. struct arbel_queue_pair {
  329. /** Send work queue */
  330. struct arbel_send_work_queue send;
  331. /** Receive work queue */
  332. struct arbel_recv_work_queue recv;
  333. /** Queue state */
  334. enum arbel_queue_pair_state state;
  335. };
  336. /** Maximum number of allocatable completion queues
  337. *
  338. * This is a policy decision, not a device limit.
  339. */
  340. #define ARBEL_MAX_CQS 8
  341. /** An Arbel completion queue */
  342. struct arbel_completion_queue {
  343. /** Consumer counter doorbell record number */
  344. unsigned int ci_doorbell_idx;
  345. /** Arm queue doorbell record number */
  346. unsigned int arm_doorbell_idx;
  347. /** Completion queue entries */
  348. union arbelprm_completion_entry *cqe;
  349. /** Size of completion queue */
  350. size_t cqe_size;
  351. };
  352. /** Maximum number of allocatable event queues
  353. *
  354. * This is a policy decision, not a device limit.
  355. */
  356. #define ARBEL_MAX_EQS 64
  357. /** A Arbel event queue */
  358. struct arbel_event_queue {
  359. /** Event queue entries */
  360. union arbelprm_event_entry *eqe;
  361. /** Size of event queue */
  362. size_t eqe_size;
  363. /** Event queue number */
  364. unsigned long eqn;
  365. /** Next event queue entry index */
  366. unsigned long next_idx;
  367. /** Doorbell register */
  368. void *doorbell;
  369. };
  370. /** Number of event queue entries
  371. *
  372. * This is a policy decision.
  373. */
  374. #define ARBEL_NUM_EQES 4
  375. /** An Arbel resource bitmask */
  376. typedef uint32_t arbel_bitmask_t;
  377. /** Size of an Arbel resource bitmask */
  378. #define ARBEL_BITMASK_SIZE(max_entries) \
  379. ( ( (max_entries) + ( 8 * sizeof ( arbel_bitmask_t ) ) - 1 ) / \
  380. ( 8 * sizeof ( arbel_bitmask_t ) ) )
  381. /** An Arbel device */
  382. struct arbel {
  383. /** PCI configuration registers */
  384. void *config;
  385. /** PCI user Access Region */
  386. void *uar;
  387. /** Event queue consumer index doorbells */
  388. void *eq_ci_doorbells;
  389. /** Command input mailbox */
  390. void *mailbox_in;
  391. /** Command output mailbox */
  392. void *mailbox_out;
  393. /** Firmware area in external memory */
  394. userptr_t firmware_area;
  395. /** ICM size */
  396. size_t icm_len;
  397. /** ICM AUX size */
  398. size_t icm_aux_len;
  399. /** ICM area */
  400. userptr_t icm;
  401. /** Event queue */
  402. struct arbel_event_queue eq;
  403. /** Doorbell records */
  404. union arbelprm_doorbell_record *db_rec;
  405. /** Reserved LKey
  406. *
  407. * Used to get unrestricted memory access.
  408. */
  409. unsigned long reserved_lkey;
  410. /** Completion queue in-use bitmask */
  411. arbel_bitmask_t cq_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_CQS ) ];
  412. /** Queue pair in-use bitmask */
  413. arbel_bitmask_t qp_inuse[ ARBEL_BITMASK_SIZE ( ARBEL_MAX_QPS ) ];
  414. /** Device limits */
  415. struct arbel_dev_limits limits;
  416. /** Special QPN base */
  417. unsigned long special_qpn_base;
  418. /** QPN base */
  419. unsigned long qpn_base;
  420. /** Infiniband devices */
  421. struct ib_device *ibdev[ARBEL_NUM_PORTS];
  422. };
  423. /** Global protection domain */
  424. #define ARBEL_GLOBAL_PD 0x123456
  425. /** Memory key prefix */
  426. #define ARBEL_MKEY_PREFIX 0x77000000UL
  427. /*
  428. * HCA commands
  429. *
  430. */
  431. #define ARBEL_HCR_BASE 0x80680
  432. #define ARBEL_HCR_REG(x) ( ARBEL_HCR_BASE + 4 * (x) )
  433. #define ARBEL_HCR_MAX_WAIT_MS 2000
  434. #define ARBEL_MBOX_ALIGN 4096
  435. #define ARBEL_MBOX_SIZE 512
  436. /* HCA command is split into
  437. *
  438. * bits 11:0 Opcode
  439. * bit 12 Input uses mailbox
  440. * bit 13 Output uses mailbox
  441. * bits 22:14 Input parameter length (in dwords)
  442. * bits 31:23 Output parameter length (in dwords)
  443. *
  444. * Encoding the information in this way allows us to cut out several
  445. * parameters to the arbel_command() call.
  446. */
  447. #define ARBEL_HCR_IN_MBOX 0x00001000UL
  448. #define ARBEL_HCR_OUT_MBOX 0x00002000UL
  449. #define ARBEL_HCR_OPCODE( _command ) ( (_command) & 0xfff )
  450. #define ARBEL_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
  451. #define ARBEL_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
  452. /** Build HCR command from component parts */
  453. #define ARBEL_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
  454. _out_mbox, _out_len ) \
  455. ( (_opcode) | \
  456. ( (_in_mbox) ? ARBEL_HCR_IN_MBOX : 0 ) | \
  457. ( ( (_in_len) / 4 ) << 14 ) | \
  458. ( (_out_mbox) ? ARBEL_HCR_OUT_MBOX : 0 ) | \
  459. ( ( (_out_len) / 4 ) << 23 ) )
  460. #define ARBEL_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
  461. ARBEL_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
  462. #define ARBEL_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
  463. ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
  464. #define ARBEL_HCR_VOID_CMD( _opcode ) \
  465. ARBEL_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
  466. /*
  467. * Doorbell record allocation
  468. *
  469. * The doorbell record map looks like:
  470. *
  471. * ARBEL_MAX_CQS * Arm completion queue doorbell
  472. * ARBEL_MAX_QPS * Send work request doorbell
  473. * Group separator
  474. * ...(empty space)...
  475. * ARBEL_MAX_QPS * Receive work request doorbell
  476. * ARBEL_MAX_CQS * Completion queue consumer counter update doorbell
  477. */
  478. #define ARBEL_MAX_DOORBELL_RECORDS 512
  479. #define ARBEL_GROUP_SEPARATOR_DOORBELL \
  480. ( ARBEL_MAX_CQS + ARBEL_RSVD_SPECIAL_QPS + ARBEL_MAX_QPS )
  481. /**
  482. * Get arm completion queue doorbell index
  483. *
  484. * @v arbel Arbel device
  485. * @v cq Completion queue
  486. * @ret doorbell_idx Doorbell index
  487. */
  488. static inline unsigned int
  489. arbel_cq_arm_doorbell_idx ( struct arbel *arbel,
  490. struct ib_completion_queue *cq ) {
  491. return ( cq->cqn - arbel->limits.reserved_cqs );
  492. }
  493. /**
  494. * Get send work request doorbell index
  495. *
  496. * @v arbel Arbel device
  497. * @v qp Queue pair
  498. * @ret doorbell_idx Doorbell index
  499. */
  500. static inline unsigned int
  501. arbel_send_doorbell_idx ( struct arbel *arbel, struct ib_queue_pair *qp ) {
  502. return ( ARBEL_MAX_CQS +
  503. ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) -
  504. arbel->special_qpn_base ) );
  505. }
  506. /**
  507. * Get receive work request doorbell index
  508. *
  509. * @v arbel Arbel device
  510. * @v qp Queue pair
  511. * @ret doorbell_idx Doorbell index
  512. */
  513. static inline unsigned int
  514. arbel_recv_doorbell_idx ( struct arbel *arbel, struct ib_queue_pair *qp ) {
  515. return ( ARBEL_MAX_DOORBELL_RECORDS - ARBEL_MAX_CQS -
  516. ( ( qp->qpn & ~ARBEL_QPN_RANDOM_MASK ) -
  517. arbel->special_qpn_base ) - 1 );
  518. }
  519. /**
  520. * Get completion queue consumer counter doorbell index
  521. *
  522. * @v arbel Arbel device
  523. * @v cq Completion queue
  524. * @ret doorbell_idx Doorbell index
  525. */
  526. static inline unsigned int
  527. arbel_cq_ci_doorbell_idx ( struct arbel *arbel,
  528. struct ib_completion_queue *cq ) {
  529. return ( ARBEL_MAX_DOORBELL_RECORDS -
  530. ( cq->cqn - arbel->limits.reserved_cqs ) - 1 );
  531. }
  532. #endif /* _ARBEL_H */