mad.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #ifndef _HFI1_MAD_H
  48. #define _HFI1_MAD_H
  49. #include <rdma/ib_pma.h>
  50. #include <rdma/opa_smi.h>
  51. #include <rdma/opa_port_info.h>
  52. #include "opa_compat.h"
  53. /*
  54. * OPA Traps
  55. */
  56. #define OPA_TRAP_GID_NOW_IN_SERVICE cpu_to_be16(64)
  57. #define OPA_TRAP_GID_OUT_OF_SERVICE cpu_to_be16(65)
  58. #define OPA_TRAP_ADD_MULTICAST_GROUP cpu_to_be16(66)
  59. #define OPA_TRAL_DEL_MULTICAST_GROUP cpu_to_be16(67)
  60. #define OPA_TRAP_UNPATH cpu_to_be16(68)
  61. #define OPA_TRAP_REPATH cpu_to_be16(69)
  62. #define OPA_TRAP_PORT_CHANGE_STATE cpu_to_be16(128)
  63. #define OPA_TRAP_LINK_INTEGRITY cpu_to_be16(129)
  64. #define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN cpu_to_be16(130)
  65. #define OPA_TRAP_FLOW_WATCHDOG cpu_to_be16(131)
  66. #define OPA_TRAP_CHANGE_CAPABILITY cpu_to_be16(144)
  67. #define OPA_TRAP_CHANGE_SYSGUID cpu_to_be16(145)
  68. #define OPA_TRAP_BAD_M_KEY cpu_to_be16(256)
  69. #define OPA_TRAP_BAD_P_KEY cpu_to_be16(257)
  70. #define OPA_TRAP_BAD_Q_KEY cpu_to_be16(258)
  71. #define OPA_TRAP_SWITCH_BAD_PKEY cpu_to_be16(259)
  72. #define OPA_SMA_TRAP_DATA_LINK_WIDTH cpu_to_be16(2048)
  73. /*
  74. * Generic trap/notice other local changes flags (trap 144).
  75. */
  76. #define OPA_NOTICE_TRAP_LWDE_CHG 0x08 /* Link Width Downgrade Enable
  77. * changed
  78. */
  79. #define OPA_NOTICE_TRAP_LSE_CHG 0x04 /* Link Speed Enable changed */
  80. #define OPA_NOTICE_TRAP_LWE_CHG 0x02 /* Link Width Enable changed */
  81. #define OPA_NOTICE_TRAP_NODE_DESC_CHG 0x01
  82. struct opa_mad_notice_attr {
  83. u8 generic_type;
  84. u8 prod_type_msb;
  85. __be16 prod_type_lsb;
  86. __be16 trap_num;
  87. __be16 toggle_count;
  88. __be32 issuer_lid;
  89. __be32 reserved1;
  90. union ib_gid issuer_gid;
  91. union {
  92. struct {
  93. u8 details[64];
  94. } raw_data;
  95. struct {
  96. union ib_gid gid;
  97. } __packed ntc_64_65_66_67;
  98. struct {
  99. __be32 lid;
  100. } __packed ntc_128;
  101. struct {
  102. __be32 lid; /* where violation happened */
  103. u8 port_num; /* where violation happened */
  104. } __packed ntc_129_130_131;
  105. struct {
  106. __be32 lid; /* LID where change occurred */
  107. __be32 new_cap_mask; /* new capability mask */
  108. __be16 reserved2;
  109. __be16 cap_mask;
  110. __be16 change_flags; /* low 4 bits only */
  111. } __packed ntc_144;
  112. struct {
  113. __be64 new_sys_guid;
  114. __be32 lid; /* lid where sys guid changed */
  115. } __packed ntc_145;
  116. struct {
  117. __be32 lid;
  118. __be32 dr_slid;
  119. u8 method;
  120. u8 dr_trunc_hop;
  121. __be16 attr_id;
  122. __be32 attr_mod;
  123. __be64 mkey;
  124. u8 dr_rtn_path[30];
  125. } __packed ntc_256;
  126. struct {
  127. __be32 lid1;
  128. __be32 lid2;
  129. __be32 key;
  130. u8 sl; /* SL: high 5 bits */
  131. u8 reserved3[3];
  132. union ib_gid gid1;
  133. union ib_gid gid2;
  134. __be32 qp1; /* high 8 bits reserved */
  135. __be32 qp2; /* high 8 bits reserved */
  136. } __packed ntc_257_258;
  137. struct {
  138. __be16 flags; /* low 8 bits reserved */
  139. __be16 pkey;
  140. __be32 lid1;
  141. __be32 lid2;
  142. u8 sl; /* SL: high 5 bits */
  143. u8 reserved4[3];
  144. union ib_gid gid1;
  145. union ib_gid gid2;
  146. __be32 qp1; /* high 8 bits reserved */
  147. __be32 qp2; /* high 8 bits reserved */
  148. } __packed ntc_259;
  149. struct {
  150. __be32 lid;
  151. } __packed ntc_2048;
  152. };
  153. u8 class_data[0];
  154. };
  155. #define IB_VLARB_LOWPRI_0_31 1
  156. #define IB_VLARB_LOWPRI_32_63 2
  157. #define IB_VLARB_HIGHPRI_0_31 3
  158. #define IB_VLARB_HIGHPRI_32_63 4
  159. #define OPA_MAX_PREEMPT_CAP 32
  160. #define OPA_VLARB_LOW_ELEMENTS 0
  161. #define OPA_VLARB_HIGH_ELEMENTS 1
  162. #define OPA_VLARB_PREEMPT_ELEMENTS 2
  163. #define OPA_VLARB_PREEMPT_MATRIX 3
  164. #define IB_PMA_PORT_COUNTERS_CONG cpu_to_be16(0xFF00)
  165. struct ib_pma_portcounters_cong {
  166. u8 reserved;
  167. u8 reserved1;
  168. __be16 port_check_rate;
  169. __be16 symbol_error_counter;
  170. u8 link_error_recovery_counter;
  171. u8 link_downed_counter;
  172. __be16 port_rcv_errors;
  173. __be16 port_rcv_remphys_errors;
  174. __be16 port_rcv_switch_relay_errors;
  175. __be16 port_xmit_discards;
  176. u8 port_xmit_constraint_errors;
  177. u8 port_rcv_constraint_errors;
  178. u8 reserved2;
  179. u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
  180. __be16 reserved3;
  181. __be16 vl15_dropped;
  182. __be64 port_xmit_data;
  183. __be64 port_rcv_data;
  184. __be64 port_xmit_packets;
  185. __be64 port_rcv_packets;
  186. __be64 port_xmit_wait;
  187. __be64 port_adr_events;
  188. } __packed;
  189. #define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004)
  190. #define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
  191. #define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C)
  192. #define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C)
  193. #define OPA_MAX_PREEMPT_CAP 32
  194. #define OPA_VLARB_LOW_ELEMENTS 0
  195. #define OPA_VLARB_HIGH_ELEMENTS 1
  196. #define OPA_VLARB_PREEMPT_ELEMENTS 2
  197. #define OPA_VLARB_PREEMPT_MATRIX 3
  198. #define HFI1_XMIT_RATE_UNSUPPORTED 0x0
  199. #define HFI1_XMIT_RATE_PICO 0x7
  200. /* number of 4nsec cycles equaling 2secs */
  201. #define HFI1_CONG_TIMER_PSINTERVAL 0x1DCD64EC
  202. #define IB_CC_SVCTYPE_RC 0x0
  203. #define IB_CC_SVCTYPE_UC 0x1
  204. #define IB_CC_SVCTYPE_RD 0x2
  205. #define IB_CC_SVCTYPE_UD 0x3
  206. /*
  207. * There should be an equivalent IB #define for the following, but
  208. * I cannot find it.
  209. */
  210. #define OPA_CC_LOG_TYPE_HFI 2
  211. struct opa_hfi1_cong_log_event_internal {
  212. u32 lqpn;
  213. u32 rqpn;
  214. u8 sl;
  215. u8 svc_type;
  216. u32 rlid;
  217. s64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
  218. };
  219. struct opa_hfi1_cong_log_event {
  220. u8 local_qp_cn_entry[3];
  221. u8 remote_qp_number_cn_entry[3];
  222. u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
  223. u8 reserved;
  224. __be32 remote_lid_cn_entry;
  225. __be32 timestamp_cn_entry;
  226. } __packed;
  227. #define OPA_CONG_LOG_ELEMS 96
  228. struct opa_hfi1_cong_log {
  229. u8 log_type;
  230. u8 congestion_flags;
  231. __be16 threshold_event_counter;
  232. __be32 current_time_stamp;
  233. u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
  234. struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
  235. } __packed;
  236. #define IB_CC_TABLE_CAP_DEFAULT 31
  237. /* Port control flags */
  238. #define IB_CC_CCS_PC_SL_BASED 0x01
  239. struct opa_congestion_setting_entry {
  240. u8 ccti_increase;
  241. u8 reserved;
  242. __be16 ccti_timer;
  243. u8 trigger_threshold;
  244. u8 ccti_min; /* min CCTI for cc table */
  245. } __packed;
  246. struct opa_congestion_setting_entry_shadow {
  247. u8 ccti_increase;
  248. u8 reserved;
  249. u16 ccti_timer;
  250. u8 trigger_threshold;
  251. u8 ccti_min; /* min CCTI for cc table */
  252. } __packed;
  253. struct opa_congestion_setting_attr {
  254. __be32 control_map;
  255. __be16 port_control;
  256. struct opa_congestion_setting_entry entries[OPA_MAX_SLS];
  257. } __packed;
  258. struct opa_congestion_setting_attr_shadow {
  259. u32 control_map;
  260. u16 port_control;
  261. struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS];
  262. } __packed;
  263. #define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1
  264. #define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1
  265. /* 64 Congestion Control table entries in a single MAD */
  266. #define IB_CCT_ENTRIES 64
  267. #define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2)
  268. struct ib_cc_table_entry {
  269. __be16 entry; /* shift:2, multiplier:14 */
  270. };
  271. struct ib_cc_table_entry_shadow {
  272. u16 entry; /* shift:2, multiplier:14 */
  273. };
  274. struct ib_cc_table_attr {
  275. __be16 ccti_limit; /* max CCTI for cc table */
  276. struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES];
  277. } __packed;
  278. struct ib_cc_table_attr_shadow {
  279. u16 ccti_limit; /* max CCTI for cc table */
  280. struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
  281. } __packed;
  282. #define CC_TABLE_SHADOW_MAX \
  283. (IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES)
  284. struct cc_table_shadow {
  285. u16 ccti_limit; /* max CCTI for cc table */
  286. struct ib_cc_table_entry_shadow entries[CC_TABLE_SHADOW_MAX];
  287. } __packed;
  288. /*
  289. * struct cc_state combines the (active) per-port congestion control
  290. * table, and the (active) per-SL congestion settings. cc_state data
  291. * may need to be read in code paths that we want to be fast, so it
  292. * is an RCU protected structure.
  293. */
  294. struct cc_state {
  295. struct rcu_head rcu;
  296. struct cc_table_shadow cct;
  297. struct opa_congestion_setting_attr_shadow cong_setting;
  298. };
  299. /*
  300. * OPA BufferControl MAD
  301. */
  302. /* attribute modifier macros */
  303. #define OPA_AM_NPORT_SHIFT 24
  304. #define OPA_AM_NPORT_MASK 0xff
  305. #define OPA_AM_NPORT_SMASK (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT)
  306. #define OPA_AM_NPORT(am) (((am) >> OPA_AM_NPORT_SHIFT) & \
  307. OPA_AM_NPORT_MASK)
  308. #define OPA_AM_NBLK_SHIFT 24
  309. #define OPA_AM_NBLK_MASK 0xff
  310. #define OPA_AM_NBLK_SMASK (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT)
  311. #define OPA_AM_NBLK(am) (((am) >> OPA_AM_NBLK_SHIFT) & \
  312. OPA_AM_NBLK_MASK)
  313. #define OPA_AM_START_BLK_SHIFT 0
  314. #define OPA_AM_START_BLK_MASK 0xff
  315. #define OPA_AM_START_BLK_SMASK (OPA_AM_START_BLK_MASK << \
  316. OPA_AM_START_BLK_SHIFT)
  317. #define OPA_AM_START_BLK(am) (((am) >> OPA_AM_START_BLK_SHIFT) & \
  318. OPA_AM_START_BLK_MASK)
  319. #define OPA_AM_PORTNUM_SHIFT 0
  320. #define OPA_AM_PORTNUM_MASK 0xff
  321. #define OPA_AM_PORTNUM_SMASK (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT)
  322. #define OPA_AM_PORTNUM(am) (((am) >> OPA_AM_PORTNUM_SHIFT) & \
  323. OPA_AM_PORTNUM_MASK)
  324. #define OPA_AM_ASYNC_SHIFT 12
  325. #define OPA_AM_ASYNC_MASK 0x1
  326. #define OPA_AM_ASYNC_SMASK (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT)
  327. #define OPA_AM_ASYNC(am) (((am) >> OPA_AM_ASYNC_SHIFT) & \
  328. OPA_AM_ASYNC_MASK)
  329. #define OPA_AM_START_SM_CFG_SHIFT 9
  330. #define OPA_AM_START_SM_CFG_MASK 0x1
  331. #define OPA_AM_START_SM_CFG_SMASK (OPA_AM_START_SM_CFG_MASK << \
  332. OPA_AM_START_SM_CFG_SHIFT)
  333. #define OPA_AM_START_SM_CFG(am) (((am) >> OPA_AM_START_SM_CFG_SHIFT) \
  334. & OPA_AM_START_SM_CFG_MASK)
  335. #define OPA_AM_CI_ADDR_SHIFT 19
  336. #define OPA_AM_CI_ADDR_MASK 0xfff
  337. #define OPA_AM_CI_ADDR_SMASK (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT)
  338. #define OPA_AM_CI_ADDR(am) (((am) >> OPA_AM_CI_ADDR_SHIFT) & \
  339. OPA_AM_CI_ADDR_MASK)
  340. #define OPA_AM_CI_LEN_SHIFT 13
  341. #define OPA_AM_CI_LEN_MASK 0x3f
  342. #define OPA_AM_CI_LEN_SMASK (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT)
  343. #define OPA_AM_CI_LEN(am) (((am) >> OPA_AM_CI_LEN_SHIFT) & \
  344. OPA_AM_CI_LEN_MASK)
  345. /* error info macros */
  346. #define OPA_EI_STATUS_SMASK 0x80
  347. #define OPA_EI_CODE_SMASK 0x0f
  348. struct vl_limit {
  349. __be16 dedicated;
  350. __be16 shared;
  351. };
  352. struct buffer_control {
  353. __be16 reserved;
  354. __be16 overall_shared_limit;
  355. struct vl_limit vl[OPA_MAX_VLS];
  356. };
  357. struct sc2vlnt {
  358. u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */
  359. };
  360. /*
  361. * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
  362. * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
  363. * We support 5 counters which only count the mandatory quantities.
  364. */
  365. #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
  366. #define COUNTER_MASK0_9 \
  367. cpu_to_be32(COUNTER_MASK(1, 0) | \
  368. COUNTER_MASK(1, 1) | \
  369. COUNTER_MASK(1, 2) | \
  370. COUNTER_MASK(1, 3) | \
  371. COUNTER_MASK(1, 4))
  372. void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port);
  373. #endif /* _HFI1_MAD_H */