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.

hermon.h 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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 <ipxe/uaccess.h>
  11. #include <ipxe/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. /* Device reset */
  26. #define HERMON_RESET_OFFSET 0x0f0010
  27. #define HERMON_RESET_MAGIC 0x01000000UL
  28. #define HERMON_RESET_WAIT_TIME_MS 1000
  29. /* Work queue entry and completion queue entry opcodes */
  30. #define HERMON_OPCODE_NOP 0x00
  31. #define HERMON_OPCODE_SEND 0x0a
  32. #define HERMON_OPCODE_RECV_ERROR 0xfe
  33. #define HERMON_OPCODE_SEND_ERROR 0xff
  34. /* HCA command register opcodes */
  35. #define HERMON_HCR_QUERY_DEV_CAP 0x0003
  36. #define HERMON_HCR_QUERY_FW 0x0004
  37. #define HERMON_HCR_INIT_HCA 0x0007
  38. #define HERMON_HCR_CLOSE_HCA 0x0008
  39. #define HERMON_HCR_INIT_PORT 0x0009
  40. #define HERMON_HCR_CLOSE_PORT 0x000a
  41. #define HERMON_HCR_SET_PORT 0x000c
  42. #define HERMON_HCR_SW2HW_MPT 0x000d
  43. #define HERMON_HCR_WRITE_MTT 0x0011
  44. #define HERMON_HCR_MAP_EQ 0x0012
  45. #define HERMON_HCR_SW2HW_EQ 0x0013
  46. #define HERMON_HCR_HW2SW_EQ 0x0014
  47. #define HERMON_HCR_QUERY_EQ 0x0015
  48. #define HERMON_HCR_SW2HW_CQ 0x0016
  49. #define HERMON_HCR_HW2SW_CQ 0x0017
  50. #define HERMON_HCR_QUERY_CQ 0x0018
  51. #define HERMON_HCR_RST2INIT_QP 0x0019
  52. #define HERMON_HCR_INIT2RTR_QP 0x001a
  53. #define HERMON_HCR_RTR2RTS_QP 0x001b
  54. #define HERMON_HCR_RTS2RTS_QP 0x001c
  55. #define HERMON_HCR_2RST_QP 0x0021
  56. #define HERMON_HCR_QUERY_QP 0x0022
  57. #define HERMON_HCR_CONF_SPECIAL_QP 0x0023
  58. #define HERMON_HCR_MAD_IFC 0x0024
  59. #define HERMON_HCR_READ_MCG 0x0025
  60. #define HERMON_HCR_WRITE_MCG 0x0026
  61. #define HERMON_HCR_MGID_HASH 0x0027
  62. #define HERMON_HCR_MOD_STAT_CFG 0x0034
  63. #define HERMON_HCR_QUERY_PORT 0x0043
  64. #define HERMON_HCR_SENSE_PORT 0x004d
  65. #define HERMON_HCR_RUN_FW 0x0ff6
  66. #define HERMON_HCR_DISABLE_LAM 0x0ff7
  67. #define HERMON_HCR_ENABLE_LAM 0x0ff8
  68. #define HERMON_HCR_UNMAP_ICM 0x0ff9
  69. #define HERMON_HCR_MAP_ICM 0x0ffa
  70. #define HERMON_HCR_UNMAP_ICM_AUX 0x0ffb
  71. #define HERMON_HCR_MAP_ICM_AUX 0x0ffc
  72. #define HERMON_HCR_SET_ICM_SIZE 0x0ffd
  73. #define HERMON_HCR_UNMAP_FA 0x0ffe
  74. #define HERMON_HCR_MAP_FA 0x0fff
  75. /* Service types */
  76. #define HERMON_ST_RC 0x00
  77. #define HERMON_ST_UD 0x03
  78. #define HERMON_ST_MLX 0x07
  79. /* Port types */
  80. #define HERMON_PORT_TYPE_UNKNOWN 0
  81. #define HERMON_PORT_TYPE_IB 1
  82. #define HERMON_PORT_TYPE_ETH 2
  83. /* MTUs */
  84. #define HERMON_MTU_2048 0x04
  85. #define HERMON_MTU_ETH 0x07
  86. #define HERMON_INVALID_LKEY 0x00000100UL
  87. #define HERMON_PAGE_SIZE ( ( size_t ) 4096 )
  88. #define HERMON_DB_POST_SND_OFFSET 0x14
  89. #define HERMON_DB_EQ_OFFSET(_eqn) \
  90. ( 0x800 + HERMON_PAGE_SIZE * ( (_eqn) / 4 ) + 0x08 * ( (_eqn) % 4 ) )
  91. #define HERMON_QP_OPT_PARAM_PM_STATE 0x00000400UL
  92. #define HERMON_QP_OPT_PARAM_QKEY 0x00000020UL
  93. #define HERMON_QP_OPT_PARAM_ALT_PATH 0x00000001UL
  94. #define HERMON_MAP_EQ ( 0UL << 31 )
  95. #define HERMON_UNMAP_EQ ( 1UL << 31 )
  96. #define HERMON_SET_PORT_GENERAL_PARAM 0x0000
  97. #define HERMON_SET_PORT_RECEIVE_QP 0x0100
  98. #define HERMON_SET_PORT_MAC_TABLE 0x0200
  99. #define HERMON_SET_PORT_VLAN_TABLE 0x0300
  100. #define HERMON_SET_PORT_PRIORITY_TABLE 0x0400
  101. #define HERMON_SET_PORT_GID_TABLE 0x0500
  102. #define HERMON_EV_PORT_STATE_CHANGE 0x09
  103. #define HERMON_SCHED_QP0 0x3f
  104. #define HERMON_SCHED_DEFAULT 0x83
  105. #define HERMON_LOG_MULTICAST_HASH_SIZE 7
  106. #define HERMON_PM_STATE_ARMED 0x00
  107. #define HERMON_PM_STATE_REARM 0x01
  108. #define HERMON_PM_STATE_MIGRATED 0x03
  109. #define HERMON_RETRY_MAX 0x07
  110. /*
  111. * Datatypes that seem to be missing from the autogenerated documentation
  112. *
  113. */
  114. struct hermonprm_mgm_hash_st {
  115. pseudo_bit_t reserved0[0x00020];
  116. /* -------------- */
  117. pseudo_bit_t hash[0x00010];
  118. pseudo_bit_t reserved1[0x00010];
  119. } __attribute__ (( packed ));
  120. struct hermonprm_mcg_entry_st {
  121. struct hermonprm_mcg_hdr_st hdr;
  122. struct hermonprm_mcg_qp_dw_st qp[8];
  123. } __attribute__ (( packed ));
  124. struct hermonprm_cq_db_record_st {
  125. pseudo_bit_t update_ci[0x00018];
  126. pseudo_bit_t reserved0[0x00008];
  127. /* -------------- */
  128. pseudo_bit_t arm_ci[0x00018];
  129. pseudo_bit_t cmd[0x00003];
  130. pseudo_bit_t reserved1[0x00001];
  131. pseudo_bit_t cmd_sn[0x00002];
  132. pseudo_bit_t reserved2[0x00002];
  133. } __attribute__ (( packed ));
  134. struct hermonprm_send_db_register_st {
  135. pseudo_bit_t reserved[0x00008];
  136. pseudo_bit_t qn[0x00018];
  137. } __attribute__ (( packed ));
  138. struct hermonprm_event_db_register_st {
  139. pseudo_bit_t ci[0x00018];
  140. pseudo_bit_t reserver[0x00007];
  141. pseudo_bit_t a[0x00001];
  142. } __attribute__ (( packed ));
  143. struct hermonprm_scalar_parameter_st {
  144. pseudo_bit_t value_hi[0x00020];
  145. /* -------------- */
  146. pseudo_bit_t value[0x00020];
  147. } __attribute__ (( packed ));
  148. struct hermonprm_event_mask_st {
  149. pseudo_bit_t reserved0[0x00020];
  150. /* -------------- */
  151. pseudo_bit_t completion[0x00001];
  152. pseudo_bit_t path_migration_succeeded[0x00001];
  153. pseudo_bit_t communication_established[0x00001];
  154. pseudo_bit_t send_queue_drained[0x00001];
  155. pseudo_bit_t cq_error[0x00001];
  156. pseudo_bit_t wq_catastrophe[0x00001];
  157. pseudo_bit_t qpc_catastrophe[0x00001];
  158. pseudo_bit_t path_migration_failed[0x00001];
  159. pseudo_bit_t internal_error[0x00001];
  160. pseudo_bit_t port_state_change[0x00001];
  161. pseudo_bit_t command_done[0x00001];
  162. pseudo_bit_t fexch_error[0x00001];
  163. pseudo_bit_t reserved1[0x00004];
  164. pseudo_bit_t wq_invalid_request[0x00001];
  165. pseudo_bit_t wq_access_violation[0x00001];
  166. pseudo_bit_t srq_catastrophe[0x00001];
  167. pseudo_bit_t srq_last_wqe[0x00001];
  168. pseudo_bit_t srq_rq_limit[0x00001];
  169. pseudo_bit_t gpio[0x00001];
  170. pseudo_bit_t clientreregister[0x00001];
  171. pseudo_bit_t reserved2[0x00009];
  172. } __attribute__ (( packed ));
  173. struct hermonprm_port_state_change_event_st {
  174. pseudo_bit_t reserved[0x00020];
  175. /* -------------- */
  176. struct hermonprm_port_state_change_st data;
  177. } __attribute__ (( packed ));
  178. struct hermonprm_sense_port_st {
  179. pseudo_bit_t reserved0[0x00020];
  180. /* -------------- */
  181. pseudo_bit_t port_type[0x00002];
  182. pseudo_bit_t reserved1[0x00018];
  183. } __attribute__ (( packed ));
  184. struct hermonprm_set_port_ib_st {
  185. pseudo_bit_t rqk[0x00001];
  186. pseudo_bit_t rcm[0x00001];
  187. pseudo_bit_t reserved0[0x00002];
  188. pseudo_bit_t vl_cap[0x00004];
  189. pseudo_bit_t reserved1[0x00004];
  190. pseudo_bit_t mtu_cap[0x00004];
  191. pseudo_bit_t g0[0x00001];
  192. pseudo_bit_t ng[0x00001];
  193. pseudo_bit_t sig[0x00001];
  194. pseudo_bit_t mg[0x00001];
  195. pseudo_bit_t mp[0x00001];
  196. pseudo_bit_t mvc[0x00001];
  197. pseudo_bit_t mmc[0x00001];
  198. pseudo_bit_t reserved2[0x00009];
  199. /* -------------- */
  200. pseudo_bit_t capability_mask[0x00020];
  201. /* -------------- */
  202. pseudo_bit_t system_image_guid_h[0x00020];
  203. /* -------------- */
  204. pseudo_bit_t system_image_guid_l[0x00020];
  205. /* -------------- */
  206. pseudo_bit_t guid0_h[0x00020];
  207. /* -------------- */
  208. pseudo_bit_t guid0_l[0x00020];
  209. /* -------------- */
  210. pseudo_bit_t node_guid_h[0x00020];
  211. /* -------------- */
  212. pseudo_bit_t node_guid_l[0x00020];
  213. /* -------------- */
  214. pseudo_bit_t egress_sniff_qpn[0x00018];
  215. pseudo_bit_t egress_sniff_mode[0x00002];
  216. pseudo_bit_t reserved3[0x00006];
  217. /* -------------- */
  218. pseudo_bit_t ingress_sniff_qpn[0x00018];
  219. pseudo_bit_t ingress_sniff_mode[0x00002];
  220. pseudo_bit_t reserved4[0x00006];
  221. /* -------------- */
  222. pseudo_bit_t max_gid[0x00010];
  223. pseudo_bit_t max_pkey[0x00010];
  224. } __attribute__ (( packed ));
  225. struct hermonprm_query_port_cap_st {
  226. pseudo_bit_t eth_mtu[0x00010];
  227. pseudo_bit_t ib_mtu[0x00004];
  228. pseudo_bit_t reserved0[0x00004];
  229. pseudo_bit_t ib[0x00001];
  230. pseudo_bit_t eth[0x00001];
  231. pseudo_bit_t reserved1[0x00005];
  232. pseudo_bit_t link_state[0x00001];
  233. /* -------------- */
  234. pseudo_bit_t log_max_pkey[0x00004];
  235. pseudo_bit_t log_max_gid[0x00004];
  236. pseudo_bit_t ib_port_width[0x00004];
  237. pseudo_bit_t reserved2[0x00004];
  238. pseudo_bit_t eth_link_speed[0x00004];
  239. pseudo_bit_t reserved3[0x00004];
  240. pseudo_bit_t ib_link_speed[0x00004];
  241. pseudo_bit_t reserved4[0x00004];
  242. /* -------------- */
  243. pseudo_bit_t max_vl_ib[0x00004];
  244. pseudo_bit_t reserved5[0x00004];
  245. pseudo_bit_t log_max_mac[0x00004];
  246. pseudo_bit_t log_max_vlan[0x00004];
  247. pseudo_bit_t reserved6[0x00010];
  248. /* -------------- */
  249. pseudo_bit_t reserved7[0x00020];
  250. /* -------------- */
  251. pseudo_bit_t mac_47_32[0x00010];
  252. pseudo_bit_t reserved8[0x00010];
  253. /* -------------- */
  254. pseudo_bit_t mac_31_0[0x00020];
  255. /* -------------- */
  256. pseudo_bit_t vendor_oui[0x00018];
  257. pseudo_bit_t transceiver_type[0x00008];
  258. /* -------------- */
  259. pseudo_bit_t reserved9[0x00010];
  260. pseudo_bit_t wavelength[0x00010];
  261. /* -------------- */
  262. pseudo_bit_t transceiver_code_hi[0x00020];
  263. /* -------------- */
  264. pseudo_bit_t transceiver_code_lo[0x00020];
  265. /* -------------- */
  266. pseudo_bit_t reserved10[0x000c0];
  267. } __attribute__ (( packed ));
  268. struct hermonprm_set_port_general_context_st {
  269. pseudo_bit_t v_mtu[0x00001];
  270. pseudo_bit_t v_pprx[0x00001];
  271. pseudo_bit_t v_pptx[0x00001];
  272. pseudo_bit_t reserved0[0x0001d];
  273. /* -------------- */
  274. pseudo_bit_t mtu[0x00010];
  275. pseudo_bit_t reserved1[0x00010];
  276. /* -------------- */
  277. pseudo_bit_t reserved2[0x00010];
  278. pseudo_bit_t pfctx[0x00008];
  279. pseudo_bit_t reserved3[0x00007];
  280. pseudo_bit_t pptx[0x00001];
  281. /* -------------- */
  282. pseudo_bit_t reserved4[0x00010];
  283. pseudo_bit_t pfcrx[0x00008];
  284. pseudo_bit_t reserved5[0x00007];
  285. pseudo_bit_t pprx[0x00001];
  286. /* -------------- */
  287. } __attribute__ (( packed ));
  288. struct hermonprm_set_port_rqp_calc_st {
  289. pseudo_bit_t base_qpn[0x00018];
  290. pseudo_bit_t reserved0[0x00008];
  291. /* -------------- */
  292. pseudo_bit_t n_p[0x00002];
  293. pseudo_bit_t reserved1[0x00006];
  294. pseudo_bit_t n_v[0x00003];
  295. pseudo_bit_t reserved2[0x00005];
  296. pseudo_bit_t n_m[0x00004];
  297. pseudo_bit_t reserved3[0x0000c];
  298. /* -------------- */
  299. pseudo_bit_t mac_miss_index[0x00008];
  300. pseudo_bit_t reserved4[0x00018];
  301. /* -------------- */
  302. pseudo_bit_t vlan_miss_index[0x00007];
  303. pseudo_bit_t reserved5[0x00008];
  304. pseudo_bit_t intra_miss[0x00001];
  305. pseudo_bit_t no_vlan_index[0x00007];
  306. pseudo_bit_t reserved6[0x00008];
  307. pseudo_bit_t intra_no_vlan[0x00001];
  308. /* -------------- */
  309. pseudo_bit_t no_vlan_prio[0x00003];
  310. pseudo_bit_t reserved7[0x0001d];
  311. /* -------------- */
  312. pseudo_bit_t promisc_qpn[0x00018];
  313. pseudo_bit_t reserved8[0x00007];
  314. pseudo_bit_t en_uc_promisc[0x00001];
  315. /* -------------- */
  316. pseudo_bit_t def_mcast_qpn[0x00018];
  317. pseudo_bit_t reserved9[0x00005];
  318. pseudo_bit_t mc_by_vlan[0x00001];
  319. pseudo_bit_t mc_promisc_mode[0x00002];
  320. /* -------------- */
  321. pseudo_bit_t reserved10[0x00020];
  322. /* -------------- */
  323. } __attribute__ (( packed ));
  324. struct hermonprm_set_port_mac_table_st {
  325. pseudo_bit_t mac_h[0x00010];
  326. pseudo_bit_t reserved0[0x0000f];
  327. pseudo_bit_t v[0x00001];
  328. /* -------------- */
  329. pseudo_bit_t mac_l[0x00020];
  330. /* -------------- */
  331. } __attribute__ (( packed ));
  332. struct hermonprm_set_port_vlan_st {
  333. pseudo_bit_t vlan_id[0x0000c];
  334. pseudo_bit_t reserved0[0x00012];
  335. pseudo_bit_t intra[0x00001];
  336. pseudo_bit_t v[0x00001];
  337. /* -------------- */
  338. } __attribute__ (( packed ));
  339. struct hermonprm_mod_stat_cfg_pf_net_boot_st {
  340. pseudo_bit_t reserved1[0x0001c];
  341. pseudo_bit_t pf_net_boot[0x00001];
  342. pseudo_bit_t reserved2[0x00002];
  343. pseudo_bit_t pf_net_boot_m[0x00001];
  344. /* -------------- */
  345. pseudo_bit_t reserved0[0x00020];
  346. } __attribute__ (( packed ));
  347. /*
  348. * Wrapper structures for hardware datatypes
  349. *
  350. */
  351. struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_context );
  352. struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_entry );
  353. struct MLX_DECLARE_STRUCT ( hermonprm_completion_with_error );
  354. struct MLX_DECLARE_STRUCT ( hermonprm_cq_db_record );
  355. struct MLX_DECLARE_STRUCT ( hermonprm_eqc );
  356. struct MLX_DECLARE_STRUCT ( hermonprm_event_db_register );
  357. struct MLX_DECLARE_STRUCT ( hermonprm_event_mask );
  358. struct MLX_DECLARE_STRUCT ( hermonprm_event_queue_entry );
  359. struct MLX_DECLARE_STRUCT ( hermonprm_hca_command_register );
  360. struct MLX_DECLARE_STRUCT ( hermonprm_init_hca );
  361. struct MLX_DECLARE_STRUCT ( hermonprm_mad_ifc );
  362. struct MLX_DECLARE_STRUCT ( hermonprm_mcg_entry );
  363. struct MLX_DECLARE_STRUCT ( hermonprm_mgm_hash );
  364. struct MLX_DECLARE_STRUCT ( hermonprm_mod_stat_cfg_pf_net_boot );
  365. struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
  366. struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
  367. struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
  368. struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
  369. struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
  370. struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
  371. struct MLX_DECLARE_STRUCT ( hermonprm_query_fw );
  372. struct MLX_DECLARE_STRUCT ( hermonprm_query_port_cap );
  373. struct MLX_DECLARE_STRUCT ( hermonprm_queue_pair_ee_context_entry );
  374. struct MLX_DECLARE_STRUCT ( hermonprm_scalar_parameter );
  375. struct MLX_DECLARE_STRUCT ( hermonprm_sense_port );
  376. struct MLX_DECLARE_STRUCT ( hermonprm_send_db_register );
  377. struct MLX_DECLARE_STRUCT ( hermonprm_set_port_ib );
  378. struct MLX_DECLARE_STRUCT ( hermonprm_set_port_general_context );
  379. struct MLX_DECLARE_STRUCT ( hermonprm_set_port_mac_table );
  380. struct MLX_DECLARE_STRUCT ( hermonprm_set_port_rqp_calc );
  381. struct MLX_DECLARE_STRUCT ( hermonprm_set_port_vlan );
  382. struct MLX_DECLARE_STRUCT ( hermonprm_ud_address_vector );
  383. struct MLX_DECLARE_STRUCT ( hermonprm_virtual_physical_mapping );
  384. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_mlx );
  385. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_send );
  386. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_data_ptr );
  387. struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ud );
  388. /*
  389. * Composite hardware datatypes
  390. *
  391. */
  392. struct hermonprm_write_mtt {
  393. struct hermonprm_scalar_parameter mtt_base_addr;
  394. struct hermonprm_scalar_parameter reserved;
  395. struct hermonprm_mtt mtt;
  396. } __attribute__ (( packed ));
  397. #define HERMON_MAX_GATHER 2
  398. struct hermonprm_ud_send_wqe {
  399. struct hermonprm_wqe_segment_ctrl_send ctrl;
  400. struct hermonprm_wqe_segment_ud ud;
  401. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
  402. } __attribute__ (( packed ));
  403. struct hermonprm_mlx_send_wqe {
  404. struct hermonprm_wqe_segment_ctrl_mlx ctrl;
  405. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
  406. uint8_t headers[IB_MAX_HEADER_SIZE];
  407. } __attribute__ (( packed ));
  408. struct hermonprm_rc_send_wqe {
  409. struct hermonprm_wqe_segment_ctrl_send ctrl;
  410. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
  411. } __attribute__ (( packed ));
  412. struct hermonprm_eth_send_wqe {
  413. struct hermonprm_wqe_segment_ctrl_send ctrl;
  414. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
  415. } __attribute__ (( packed ));
  416. #define HERMON_MAX_SCATTER 1
  417. struct hermonprm_recv_wqe {
  418. struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
  419. } __attribute__ (( packed ));
  420. union hermonprm_completion_entry {
  421. struct hermonprm_completion_queue_entry normal;
  422. struct hermonprm_completion_with_error error;
  423. } __attribute__ (( packed ));
  424. union hermonprm_event_entry {
  425. struct hermonprm_event_queue_entry generic;
  426. struct hermonprm_port_state_change_event port_state_change;
  427. } __attribute__ (( packed ));
  428. union hermonprm_doorbell_register {
  429. struct hermonprm_send_db_register send;
  430. struct hermonprm_event_db_register event;
  431. uint32_t dword[1];
  432. } __attribute__ (( packed ));
  433. union hermonprm_mad {
  434. struct hermonprm_mad_ifc ifc;
  435. union ib_mad mad;
  436. } __attribute__ (( packed ));
  437. union hermonprm_set_port {
  438. struct hermonprm_set_port_ib ib;
  439. struct hermonprm_set_port_general_context general;
  440. struct hermonprm_set_port_rqp_calc rqp_calc;
  441. struct hermonprm_set_port_mac_table mac_table[128];
  442. struct hermonprm_set_port_vlan vlan;
  443. } __attribute__ (( packed ));
  444. /*
  445. * iPXE-specific definitions
  446. *
  447. */
  448. /** Hermon device capabilitiess */
  449. struct hermon_dev_cap {
  450. /** CMPT entry size */
  451. size_t cmpt_entry_size;
  452. /** Number of reserved QPs */
  453. unsigned int reserved_qps;
  454. /** QP context entry size */
  455. size_t qpc_entry_size;
  456. /** Alternate path context entry size */
  457. size_t altc_entry_size;
  458. /** Auxiliary context entry size */
  459. size_t auxc_entry_size;
  460. /** Number of reserved SRQs */
  461. unsigned int reserved_srqs;
  462. /** SRQ context entry size */
  463. size_t srqc_entry_size;
  464. /** Number of reserved CQs */
  465. unsigned int reserved_cqs;
  466. /** CQ context entry size */
  467. size_t cqc_entry_size;
  468. /** Number of reserved EQs */
  469. unsigned int reserved_eqs;
  470. /** EQ context entry size */
  471. size_t eqc_entry_size;
  472. /** Number of reserved MTTs */
  473. unsigned int reserved_mtts;
  474. /** MTT entry size */
  475. size_t mtt_entry_size;
  476. /** Number of reserved MRWs */
  477. unsigned int reserved_mrws;
  478. /** DMPT entry size */
  479. size_t dmpt_entry_size;
  480. /** Number of reserved UARs */
  481. unsigned int reserved_uars;
  482. /** Number of ports */
  483. unsigned int num_ports;
  484. /** Dual-port different protocol */
  485. int dpdp;
  486. };
  487. /** Number of cMPT entries of each type */
  488. #define HERMON_CMPT_MAX_ENTRIES ( 1 << 24 )
  489. /** Hermon ICM memory map entry */
  490. struct hermon_icm_map {
  491. /** Offset (virtual address within ICM) */
  492. uint64_t offset;
  493. /** Length */
  494. size_t len;
  495. };
  496. /** Discontiguous regions within Hermon ICM */
  497. enum hermon_icm_map_regions {
  498. HERMON_ICM_QP_CMPT = 0,
  499. HERMON_ICM_SRQ_CMPT,
  500. HERMON_ICM_CQ_CMPT,
  501. HERMON_ICM_EQ_CMPT,
  502. HERMON_ICM_OTHER,
  503. HERMON_ICM_NUM_REGIONS
  504. };
  505. /** UAR page for doorbell accesses
  506. *
  507. * Pages 0-127 are reserved for event queue doorbells only, so we use
  508. * page 128.
  509. */
  510. #define HERMON_UAR_NON_EQ_PAGE 128
  511. /** Maximum number of allocatable MTT entries
  512. *
  513. * This is a policy decision, not a device limit.
  514. */
  515. #define HERMON_MAX_MTTS 64
  516. /** A Hermon MTT descriptor */
  517. struct hermon_mtt {
  518. /** MTT offset */
  519. unsigned int mtt_offset;
  520. /** Number of pages */
  521. unsigned int num_pages;
  522. /** MTT base address */
  523. unsigned int mtt_base_addr;
  524. /** Offset within page */
  525. unsigned int page_offset;
  526. };
  527. /** Alignment of Hermon send work queue entries */
  528. #define HERMON_SEND_WQE_ALIGN 128
  529. /** A Hermon send work queue entry */
  530. union hermon_send_wqe {
  531. struct hermonprm_wqe_segment_ctrl_send ctrl;
  532. struct hermonprm_ud_send_wqe ud;
  533. struct hermonprm_mlx_send_wqe mlx;
  534. struct hermonprm_rc_send_wqe rc;
  535. struct hermonprm_eth_send_wqe eth;
  536. uint8_t force_align[HERMON_SEND_WQE_ALIGN];
  537. } __attribute__ (( packed ));
  538. /** A Hermon send work queue */
  539. struct hermon_send_work_queue {
  540. /** Number of work queue entries, including headroom
  541. *
  542. * Hermon requires us to leave unused space within the send
  543. * WQ, so we create a send WQ with more entries than are
  544. * requested in the create_qp() call.
  545. */
  546. unsigned int num_wqes;
  547. /** Work queue entries */
  548. union hermon_send_wqe *wqe;
  549. /** Size of work queue */
  550. size_t wqe_size;
  551. /** Doorbell register */
  552. void *doorbell;
  553. };
  554. /** Alignment of Hermon receive work queue entries */
  555. #define HERMON_RECV_WQE_ALIGN 16
  556. /** A Hermon receive work queue entry */
  557. union hermon_recv_wqe {
  558. struct hermonprm_recv_wqe recv;
  559. uint8_t force_align[HERMON_RECV_WQE_ALIGN];
  560. } __attribute__ (( packed ));
  561. /** A Hermon receive work queue */
  562. struct hermon_recv_work_queue {
  563. /** Work queue entries */
  564. union hermon_recv_wqe *wqe;
  565. /** Size of work queue */
  566. size_t wqe_size;
  567. /** Doorbell record */
  568. struct hermonprm_qp_db_record *doorbell;
  569. };
  570. /** Number of special queue pairs */
  571. #define HERMON_NUM_SPECIAL_QPS 8
  572. /** Number of queue pairs reserved for the "special QP" block
  573. *
  574. * The special QPs must be within a contiguous block aligned on its
  575. * own size.
  576. */
  577. #define HERMON_RSVD_SPECIAL_QPS ( ( HERMON_NUM_SPECIAL_QPS << 1 ) - 1 )
  578. /** Maximum number of allocatable queue pairs
  579. *
  580. * This is a policy decision, not a device limit.
  581. */
  582. #define HERMON_MAX_QPS 8
  583. /** Queue pair number randomisation mask */
  584. #define HERMON_QPN_RANDOM_MASK 0xfff000
  585. /** Hermon queue pair state */
  586. enum hermon_queue_pair_state {
  587. HERMON_QP_ST_RST = 0,
  588. HERMON_QP_ST_INIT,
  589. HERMON_QP_ST_RTR,
  590. HERMON_QP_ST_RTS,
  591. };
  592. /** A Hermon queue pair */
  593. struct hermon_queue_pair {
  594. /** Work queue buffer */
  595. void *wqe;
  596. /** Size of work queue buffer */
  597. size_t wqe_size;
  598. /** MTT descriptor */
  599. struct hermon_mtt mtt;
  600. /** Send work queue */
  601. struct hermon_send_work_queue send;
  602. /** Receive work queue */
  603. struct hermon_recv_work_queue recv;
  604. /** Queue state */
  605. enum hermon_queue_pair_state state;
  606. };
  607. /** Maximum number of allocatable completion queues
  608. *
  609. * This is a policy decision, not a device limit.
  610. */
  611. #define HERMON_MAX_CQS 8
  612. /** A Hermon completion queue */
  613. struct hermon_completion_queue {
  614. /** Completion queue entries */
  615. union hermonprm_completion_entry *cqe;
  616. /** Size of completion queue */
  617. size_t cqe_size;
  618. /** MTT descriptor */
  619. struct hermon_mtt mtt;
  620. /** Doorbell record */
  621. struct hermonprm_cq_db_record *doorbell;
  622. };
  623. /** Maximum number of allocatable event queues
  624. *
  625. * This is a policy decision, not a device limit.
  626. */
  627. #define HERMON_MAX_EQS 8
  628. /** A Hermon event queue */
  629. struct hermon_event_queue {
  630. /** Event queue entries */
  631. union hermonprm_event_entry *eqe;
  632. /** Size of event queue */
  633. size_t eqe_size;
  634. /** MTT descriptor */
  635. struct hermon_mtt mtt;
  636. /** Event queue number */
  637. unsigned long eqn;
  638. /** Next event queue entry index */
  639. unsigned long next_idx;
  640. /** Doorbell register */
  641. void *doorbell;
  642. };
  643. /** Number of event queue entries
  644. *
  645. * This is a policy decision.
  646. */
  647. #define HERMON_NUM_EQES 4
  648. /** A Hermon resource bitmask */
  649. typedef uint32_t hermon_bitmask_t;
  650. /** Size of a hermon resource bitmask */
  651. #define HERMON_BITMASK_SIZE(max_entries) \
  652. ( ( (max_entries) + ( 8 * sizeof ( hermon_bitmask_t ) ) - 1 ) / \
  653. ( 8 * sizeof ( hermon_bitmask_t ) ) )
  654. struct hermon;
  655. struct hermon_port;
  656. /** A Hermon port type */
  657. struct hermon_port_type {
  658. /** Register port
  659. *
  660. * @v hermon Hermon device
  661. * @v port Hermon port
  662. * @ret rc Return status code
  663. */
  664. int ( * register_dev ) ( struct hermon *hermon,
  665. struct hermon_port *port );
  666. /** Port state changed
  667. *
  668. * @v hermon Hermon device
  669. * @v port Hermon port
  670. * @v link_up Link is up
  671. */
  672. void ( * state_change ) ( struct hermon *hermon,
  673. struct hermon_port *port,
  674. int link_up );
  675. /** Unregister port
  676. *
  677. * @v hermon Hermon device
  678. * @v port Hermon port
  679. */
  680. void ( * unregister_dev ) ( struct hermon *hermon,
  681. struct hermon_port *port );
  682. };
  683. /** A Hermon port */
  684. struct hermon_port {
  685. /** Infiniband device */
  686. struct ib_device *ibdev;
  687. /** Network device */
  688. struct net_device *netdev;
  689. /** Ethernet completion queue */
  690. struct ib_completion_queue *eth_cq;
  691. /** Ethernet queue pair */
  692. struct ib_queue_pair *eth_qp;
  693. /** Port type */
  694. struct hermon_port_type *type;
  695. };
  696. /** A Hermon device */
  697. struct hermon {
  698. /** PCI configuration registers */
  699. void *config;
  700. /** PCI user Access Region */
  701. void *uar;
  702. /** Command toggle */
  703. unsigned int toggle;
  704. /** Command input mailbox */
  705. void *mailbox_in;
  706. /** Command output mailbox */
  707. void *mailbox_out;
  708. /** Firmware area in external memory */
  709. userptr_t firmware_area;
  710. /** ICM map */
  711. struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS];
  712. /** ICM area */
  713. userptr_t icm;
  714. /** Event queue */
  715. struct hermon_event_queue eq;
  716. /** Unrestricted LKey
  717. *
  718. * Used to get unrestricted memory access.
  719. */
  720. unsigned long lkey;
  721. /** Completion queue in-use bitmask */
  722. hermon_bitmask_t cq_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_CQS ) ];
  723. /** Queue pair in-use bitmask */
  724. hermon_bitmask_t qp_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_QPS ) ];
  725. /** MTT entry in-use bitmask */
  726. hermon_bitmask_t mtt_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_MTTS ) ];
  727. /** Device capabilities */
  728. struct hermon_dev_cap cap;
  729. /** Special QPN base */
  730. unsigned long special_qpn_base;
  731. /** QPN base */
  732. unsigned long qpn_base;
  733. /** Ports */
  734. struct hermon_port port[HERMON_MAX_PORTS];
  735. };
  736. /** Global protection domain */
  737. #define HERMON_GLOBAL_PD 0x123456
  738. /** Memory key prefix */
  739. #define HERMON_MKEY_PREFIX 0x77000000UL
  740. /*
  741. * HCA commands
  742. *
  743. */
  744. #define HERMON_HCR_BASE 0x80680
  745. #define HERMON_HCR_REG(x) ( HERMON_HCR_BASE + 4 * (x) )
  746. #define HERMON_HCR_MAX_WAIT_MS 2000
  747. #define HERMON_MBOX_ALIGN 4096
  748. #define HERMON_MBOX_SIZE 1024
  749. /* HCA command is split into
  750. *
  751. * bits 11:0 Opcode
  752. * bit 12 Input uses mailbox
  753. * bit 13 Output uses mailbox
  754. * bits 22:14 Input parameter length (in dwords)
  755. * bits 31:23 Output parameter length (in dwords)
  756. *
  757. * Encoding the information in this way allows us to cut out several
  758. * parameters to the hermon_command() call.
  759. */
  760. #define HERMON_HCR_IN_MBOX 0x00001000UL
  761. #define HERMON_HCR_OUT_MBOX 0x00002000UL
  762. #define HERMON_HCR_OPCODE( _command ) ( (_command) & 0xfff )
  763. #define HERMON_HCR_IN_LEN( _command ) ( ( (_command) >> 12 ) & 0x7fc )
  764. #define HERMON_HCR_OUT_LEN( _command ) ( ( (_command) >> 21 ) & 0x7fc )
  765. /** Build HCR command from component parts */
  766. #define HERMON_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len, \
  767. _out_mbox, _out_len ) \
  768. ( (_opcode) | \
  769. ( (_in_mbox) ? HERMON_HCR_IN_MBOX : 0 ) | \
  770. ( ( (_in_len) / 4 ) << 14 ) | \
  771. ( (_out_mbox) ? HERMON_HCR_OUT_MBOX : 0 ) | \
  772. ( ( (_out_len) / 4 ) << 23 ) )
  773. #define HERMON_HCR_IN_CMD( _opcode, _in_mbox, _in_len ) \
  774. HERMON_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
  775. #define HERMON_HCR_OUT_CMD( _opcode, _out_mbox, _out_len ) \
  776. HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
  777. #define HERMON_HCR_VOID_CMD( _opcode ) \
  778. HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
  779. #endif /* _HERMON_H */