mad.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /*
  2. * Copyright(c) 2015 - 2017 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_mask3;
  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. #define LINK_SPEED_25G 1
  166. #define LINK_SPEED_12_5G 2
  167. #define LINK_WIDTH_DEFAULT 4
  168. #define DECIMAL_FACTORING 1000
  169. /*
  170. * The default link width is multiplied by 1000
  171. * to get accurate value after division.
  172. */
  173. #define FACTOR_LINK_WIDTH (LINK_WIDTH_DEFAULT * DECIMAL_FACTORING)
  174. struct ib_pma_portcounters_cong {
  175. u8 reserved;
  176. u8 reserved1;
  177. __be16 port_check_rate;
  178. __be16 symbol_error_counter;
  179. u8 link_error_recovery_counter;
  180. u8 link_downed_counter;
  181. __be16 port_rcv_errors;
  182. __be16 port_rcv_remphys_errors;
  183. __be16 port_rcv_switch_relay_errors;
  184. __be16 port_xmit_discards;
  185. u8 port_xmit_constraint_errors;
  186. u8 port_rcv_constraint_errors;
  187. u8 reserved2;
  188. u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
  189. __be16 reserved3;
  190. __be16 vl15_dropped;
  191. __be64 port_xmit_data;
  192. __be64 port_rcv_data;
  193. __be64 port_xmit_packets;
  194. __be64 port_rcv_packets;
  195. __be64 port_xmit_wait;
  196. __be64 port_adr_events;
  197. } __packed;
  198. #define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004)
  199. #define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
  200. #define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C)
  201. #define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C)
  202. #define OPA_MAX_PREEMPT_CAP 32
  203. #define OPA_VLARB_LOW_ELEMENTS 0
  204. #define OPA_VLARB_HIGH_ELEMENTS 1
  205. #define OPA_VLARB_PREEMPT_ELEMENTS 2
  206. #define OPA_VLARB_PREEMPT_MATRIX 3
  207. #define HFI1_XMIT_RATE_UNSUPPORTED 0x0
  208. #define HFI1_XMIT_RATE_PICO 0x7
  209. /* number of 4nsec cycles equaling 2secs */
  210. #define HFI1_CONG_TIMER_PSINTERVAL 0x1DCD64EC
  211. #define IB_CC_SVCTYPE_RC 0x0
  212. #define IB_CC_SVCTYPE_UC 0x1
  213. #define IB_CC_SVCTYPE_RD 0x2
  214. #define IB_CC_SVCTYPE_UD 0x3
  215. /*
  216. * There should be an equivalent IB #define for the following, but
  217. * I cannot find it.
  218. */
  219. #define OPA_CC_LOG_TYPE_HFI 2
  220. struct opa_hfi1_cong_log_event_internal {
  221. u32 lqpn;
  222. u32 rqpn;
  223. u8 sl;
  224. u8 svc_type;
  225. u32 rlid;
  226. u64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
  227. };
  228. struct opa_hfi1_cong_log_event {
  229. u8 local_qp_cn_entry[3];
  230. u8 remote_qp_number_cn_entry[3];
  231. u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
  232. u8 reserved;
  233. __be32 remote_lid_cn_entry;
  234. __be32 timestamp_cn_entry;
  235. } __packed;
  236. #define OPA_CONG_LOG_ELEMS 96
  237. struct opa_hfi1_cong_log {
  238. u8 log_type;
  239. u8 congestion_flags;
  240. __be16 threshold_event_counter;
  241. __be32 current_time_stamp;
  242. u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
  243. struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
  244. } __packed;
  245. #define IB_CC_TABLE_CAP_DEFAULT 31
  246. /* Port control flags */
  247. #define IB_CC_CCS_PC_SL_BASED 0x01
  248. struct opa_congestion_setting_entry {
  249. u8 ccti_increase;
  250. u8 reserved;
  251. __be16 ccti_timer;
  252. u8 trigger_threshold;
  253. u8 ccti_min; /* min CCTI for cc table */
  254. } __packed;
  255. struct opa_congestion_setting_entry_shadow {
  256. u8 ccti_increase;
  257. u8 reserved;
  258. u16 ccti_timer;
  259. u8 trigger_threshold;
  260. u8 ccti_min; /* min CCTI for cc table */
  261. } __packed;
  262. struct opa_congestion_setting_attr {
  263. __be32 control_map;
  264. __be16 port_control;
  265. struct opa_congestion_setting_entry entries[OPA_MAX_SLS];
  266. } __packed;
  267. struct opa_congestion_setting_attr_shadow {
  268. u32 control_map;
  269. u16 port_control;
  270. struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS];
  271. } __packed;
  272. #define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1
  273. #define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1
  274. /* 64 Congestion Control table entries in a single MAD */
  275. #define IB_CCT_ENTRIES 64
  276. #define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2)
  277. struct ib_cc_table_entry {
  278. __be16 entry; /* shift:2, multiplier:14 */
  279. };
  280. struct ib_cc_table_entry_shadow {
  281. u16 entry; /* shift:2, multiplier:14 */
  282. };
  283. struct ib_cc_table_attr {
  284. __be16 ccti_limit; /* max CCTI for cc table */
  285. struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES];
  286. } __packed;
  287. struct ib_cc_table_attr_shadow {
  288. u16 ccti_limit; /* max CCTI for cc table */
  289. struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
  290. } __packed;
  291. #define CC_TABLE_SHADOW_MAX \
  292. (IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES)
  293. struct cc_table_shadow {
  294. u16 ccti_limit; /* max CCTI for cc table */
  295. struct ib_cc_table_entry_shadow entries[CC_TABLE_SHADOW_MAX];
  296. } __packed;
  297. /*
  298. * struct cc_state combines the (active) per-port congestion control
  299. * table, and the (active) per-SL congestion settings. cc_state data
  300. * may need to be read in code paths that we want to be fast, so it
  301. * is an RCU protected structure.
  302. */
  303. struct cc_state {
  304. struct rcu_head rcu;
  305. struct cc_table_shadow cct;
  306. struct opa_congestion_setting_attr_shadow cong_setting;
  307. };
  308. /*
  309. * OPA BufferControl MAD
  310. */
  311. /* attribute modifier macros */
  312. #define OPA_AM_NPORT_SHIFT 24
  313. #define OPA_AM_NPORT_MASK 0xff
  314. #define OPA_AM_NPORT_SMASK (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT)
  315. #define OPA_AM_NPORT(am) (((am) >> OPA_AM_NPORT_SHIFT) & \
  316. OPA_AM_NPORT_MASK)
  317. #define OPA_AM_NBLK_SHIFT 24
  318. #define OPA_AM_NBLK_MASK 0xff
  319. #define OPA_AM_NBLK_SMASK (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT)
  320. #define OPA_AM_NBLK(am) (((am) >> OPA_AM_NBLK_SHIFT) & \
  321. OPA_AM_NBLK_MASK)
  322. #define OPA_AM_START_BLK_SHIFT 0
  323. #define OPA_AM_START_BLK_MASK 0xff
  324. #define OPA_AM_START_BLK_SMASK (OPA_AM_START_BLK_MASK << \
  325. OPA_AM_START_BLK_SHIFT)
  326. #define OPA_AM_START_BLK(am) (((am) >> OPA_AM_START_BLK_SHIFT) & \
  327. OPA_AM_START_BLK_MASK)
  328. #define OPA_AM_PORTNUM_SHIFT 0
  329. #define OPA_AM_PORTNUM_MASK 0xff
  330. #define OPA_AM_PORTNUM_SMASK (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT)
  331. #define OPA_AM_PORTNUM(am) (((am) >> OPA_AM_PORTNUM_SHIFT) & \
  332. OPA_AM_PORTNUM_MASK)
  333. #define OPA_AM_ASYNC_SHIFT 12
  334. #define OPA_AM_ASYNC_MASK 0x1
  335. #define OPA_AM_ASYNC_SMASK (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT)
  336. #define OPA_AM_ASYNC(am) (((am) >> OPA_AM_ASYNC_SHIFT) & \
  337. OPA_AM_ASYNC_MASK)
  338. #define OPA_AM_START_SM_CFG_SHIFT 9
  339. #define OPA_AM_START_SM_CFG_MASK 0x1
  340. #define OPA_AM_START_SM_CFG_SMASK (OPA_AM_START_SM_CFG_MASK << \
  341. OPA_AM_START_SM_CFG_SHIFT)
  342. #define OPA_AM_START_SM_CFG(am) (((am) >> OPA_AM_START_SM_CFG_SHIFT) \
  343. & OPA_AM_START_SM_CFG_MASK)
  344. #define OPA_AM_CI_ADDR_SHIFT 19
  345. #define OPA_AM_CI_ADDR_MASK 0xfff
  346. #define OPA_AM_CI_ADDR_SMASK (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT)
  347. #define OPA_AM_CI_ADDR(am) (((am) >> OPA_AM_CI_ADDR_SHIFT) & \
  348. OPA_AM_CI_ADDR_MASK)
  349. #define OPA_AM_CI_LEN_SHIFT 13
  350. #define OPA_AM_CI_LEN_MASK 0x3f
  351. #define OPA_AM_CI_LEN_SMASK (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT)
  352. #define OPA_AM_CI_LEN(am) (((am) >> OPA_AM_CI_LEN_SHIFT) & \
  353. OPA_AM_CI_LEN_MASK)
  354. /* error info macros */
  355. #define OPA_EI_STATUS_SMASK 0x80
  356. #define OPA_EI_CODE_SMASK 0x0f
  357. struct vl_limit {
  358. __be16 dedicated;
  359. __be16 shared;
  360. };
  361. struct buffer_control {
  362. __be16 reserved;
  363. __be16 overall_shared_limit;
  364. struct vl_limit vl[OPA_MAX_VLS];
  365. };
  366. struct sc2vlnt {
  367. u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */
  368. };
  369. /*
  370. * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
  371. * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
  372. * We support 5 counters which only count the mandatory quantities.
  373. */
  374. #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
  375. #define COUNTER_MASK0_9 \
  376. cpu_to_be32(COUNTER_MASK(1, 0) | \
  377. COUNTER_MASK(1, 1) | \
  378. COUNTER_MASK(1, 2) | \
  379. COUNTER_MASK(1, 3) | \
  380. COUNTER_MASK(1, 4))
  381. void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port);
  382. void hfi1_handle_trap_timer(struct timer_list *t);
  383. u16 tx_link_width(u16 link_width);
  384. u64 get_xmit_wait_counters(struct hfi1_pportdata *ppd, u16 link_width,
  385. u16 link_speed, int vl);
  386. /**
  387. * get_link_speed - determine whether 12.5G or 25G speed
  388. * @link_speed: the speed of active link
  389. * @return: Return 2 if link speed identified as 12.5G
  390. * or return 1 if link speed is 25G.
  391. *
  392. * The function indirectly calculate required link speed
  393. * value for convert_xmit_counter function. If the link
  394. * speed is 25G, the function return as 1 as it is required
  395. * by xmit counter conversion formula :-( 25G / link_speed).
  396. * This conversion will provide value 1 if current
  397. * link speed is 25G or 2 if 12.5G.This is done to avoid
  398. * 12.5 float number conversion.
  399. */
  400. static inline u16 get_link_speed(u16 link_speed)
  401. {
  402. return (link_speed == 1) ?
  403. LINK_SPEED_12_5G : LINK_SPEED_25G;
  404. }
  405. /**
  406. * convert_xmit_counter - calculate flit times for given xmit counter
  407. * value
  408. * @xmit_wait_val: current xmit counter value
  409. * @link_width: width of active link
  410. * @link_speed: speed of active link
  411. * @return: return xmit counter value in flit times.
  412. */
  413. static inline u64 convert_xmit_counter(u64 xmit_wait_val, u16 link_width,
  414. u16 link_speed)
  415. {
  416. return (xmit_wait_val * 2 * (FACTOR_LINK_WIDTH / link_width)
  417. * link_speed) / DECIMAL_FACTORING;
  418. }
  419. #endif /* _HFI1_MAD_H */