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

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