選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hermon.h 16KB

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