Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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