| 1 |
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ |
| 2 |
/* |
| 3 |
* Copyright(c) 2015 - 2017 Intel Corporation. |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef _HFI1_MAD_H |
| 7 |
#define _HFI1_MAD_H |
| 8 |
|
| 9 |
#include <rdma/ib_pma.h> |
| 10 |
#include <rdma/opa_smi.h> |
| 11 |
#include <rdma/opa_port_info.h> |
| 12 |
#include "opa_compat.h" |
| 13 |
|
| 14 |
/* |
| 15 |
* OPA Traps |
| 16 |
*/ |
| 17 |
#define OPA_TRAP_GID_NOW_IN_SERVICE cpu_to_be16(64) |
| 18 |
#define OPA_TRAP_GID_OUT_OF_SERVICE cpu_to_be16(65) |
| 19 |
#define OPA_TRAP_ADD_MULTICAST_GROUP cpu_to_be16(66) |
| 20 |
#define OPA_TRAL_DEL_MULTICAST_GROUP cpu_to_be16(67) |
| 21 |
#define OPA_TRAP_UNPATH cpu_to_be16(68) |
| 22 |
#define OPA_TRAP_REPATH cpu_to_be16(69) |
| 23 |
#define OPA_TRAP_PORT_CHANGE_STATE cpu_to_be16(128) |
| 24 |
#define OPA_TRAP_LINK_INTEGRITY cpu_to_be16(129) |
| 25 |
#define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN cpu_to_be16(130) |
| 26 |
#define OPA_TRAP_FLOW_WATCHDOG cpu_to_be16(131) |
| 27 |
#define OPA_TRAP_CHANGE_CAPABILITY cpu_to_be16(144) |
| 28 |
#define OPA_TRAP_CHANGE_SYSGUID cpu_to_be16(145) |
| 29 |
#define OPA_TRAP_BAD_M_KEY cpu_to_be16(256) |
| 30 |
#define OPA_TRAP_BAD_P_KEY cpu_to_be16(257) |
| 31 |
#define OPA_TRAP_BAD_Q_KEY cpu_to_be16(258) |
| 32 |
#define OPA_TRAP_SWITCH_BAD_PKEY cpu_to_be16(259) |
| 33 |
#define OPA_SMA_TRAP_DATA_LINK_WIDTH cpu_to_be16(2048) |
| 34 |
|
| 35 |
/* |
| 36 |
* Generic trap/notice other local changes flags (trap 144). |
| 37 |
*/ |
| 38 |
#define OPA_NOTICE_TRAP_LWDE_CHG 0x08 /* Link Width Downgrade Enable |
| 39 |
* changed |
| 40 |
*/ |
| 41 |
#define OPA_NOTICE_TRAP_LSE_CHG 0x04 /* Link Speed Enable changed */ |
| 42 |
#define OPA_NOTICE_TRAP_LWE_CHG 0x02 /* Link Width Enable changed */ |
| 43 |
#define OPA_NOTICE_TRAP_NODE_DESC_CHG 0x01 |
| 44 |
|
| 45 |
struct opa_mad_notice_attr { |
| 46 |
u8 generic_type; |
| 47 |
u8 prod_type_msb; |
| 48 |
__be16 prod_type_lsb; |
| 49 |
__be16 trap_num; |
| 50 |
__be16 toggle_count; |
| 51 |
__be32 issuer_lid; |
| 52 |
__be32 reserved1; |
| 53 |
union ib_gid issuer_gid; |
| 54 |
|
| 55 |
union { |
| 56 |
struct { |
| 57 |
u8 details[64]; |
| 58 |
} raw_data; |
| 59 |
|
| 60 |
struct { |
| 61 |
union ib_gid gid; |
| 62 |
} __packed ntc_64_65_66_67; |
| 63 |
|
| 64 |
struct { |
| 65 |
__be32 lid; |
| 66 |
} __packed ntc_128; |
| 67 |
|
| 68 |
struct { |
| 69 |
__be32 lid; /* where violation happened */ |
| 70 |
u8 port_num; /* where violation happened */ |
| 71 |
} __packed ntc_129_130_131; |
| 72 |
|
| 73 |
struct { |
| 74 |
__be32 lid; /* LID where change occurred */ |
| 75 |
__be32 new_cap_mask; /* new capability mask */ |
| 76 |
__be16 reserved2; |
| 77 |
__be16 cap_mask3; |
| 78 |
__be16 change_flags; /* low 4 bits only */ |
| 79 |
} __packed ntc_144; |
| 80 |
|
| 81 |
struct { |
| 82 |
__be64 new_sys_guid; |
| 83 |
__be32 lid; /* lid where sys guid changed */ |
| 84 |
} __packed ntc_145; |
| 85 |
|
| 86 |
struct { |
| 87 |
__be32 lid; |
| 88 |
__be32 dr_slid; |
| 89 |
u8 method; |
| 90 |
u8 dr_trunc_hop; |
| 91 |
__be16 attr_id; |
| 92 |
__be32 attr_mod; |
| 93 |
__be64 mkey; |
| 94 |
u8 dr_rtn_path[30]; |
| 95 |
} __packed ntc_256; |
| 96 |
|
| 97 |
struct { |
| 98 |
__be32 lid1; |
| 99 |
__be32 lid2; |
| 100 |
__be32 key; |
| 101 |
u8 sl; /* SL: high 5 bits */ |
| 102 |
u8 reserved3[3]; |
| 103 |
union ib_gid gid1; |
| 104 |
union ib_gid gid2; |
| 105 |
__be32 qp1; /* high 8 bits reserved */ |
| 106 |
__be32 qp2; /* high 8 bits reserved */ |
| 107 |
} __packed ntc_257_258; |
| 108 |
|
| 109 |
struct { |
| 110 |
__be16 flags; /* low 8 bits reserved */ |
| 111 |
__be16 pkey; |
| 112 |
__be32 lid1; |
| 113 |
__be32 lid2; |
| 114 |
u8 sl; /* SL: high 5 bits */ |
| 115 |
u8 reserved4[3]; |
| 116 |
union ib_gid gid1; |
| 117 |
union ib_gid gid2; |
| 118 |
__be32 qp1; /* high 8 bits reserved */ |
| 119 |
__be32 qp2; /* high 8 bits reserved */ |
| 120 |
} __packed ntc_259; |
| 121 |
|
| 122 |
struct { |
| 123 |
__be32 lid; |
| 124 |
} __packed ntc_2048; |
| 125 |
|
| 126 |
}; |
| 127 |
}; |
| 128 |
|
| 129 |
#define IB_VLARB_LOWPRI_0_31 1 |
| 130 |
#define IB_VLARB_LOWPRI_32_63 2 |
| 131 |
#define IB_VLARB_HIGHPRI_0_31 3 |
| 132 |
#define IB_VLARB_HIGHPRI_32_63 4 |
| 133 |
|
| 134 |
#define OPA_MAX_PREEMPT_CAP 32 |
| 135 |
#define OPA_VLARB_LOW_ELEMENTS 0 |
| 136 |
#define OPA_VLARB_HIGH_ELEMENTS 1 |
| 137 |
#define OPA_VLARB_PREEMPT_ELEMENTS 2 |
| 138 |
#define OPA_VLARB_PREEMPT_MATRIX 3 |
| 139 |
|
| 140 |
#define IB_PMA_PORT_COUNTERS_CONG cpu_to_be16(0xFF00) |
| 141 |
#define LINK_SPEED_25G 1 |
| 142 |
#define LINK_SPEED_12_5G 2 |
| 143 |
#define LINK_WIDTH_DEFAULT 4 |
| 144 |
#define DECIMAL_FACTORING 1000 |
| 145 |
/* |
| 146 |
* The default link width is multiplied by 1000 |
| 147 |
* to get accurate value after division. |
| 148 |
*/ |
| 149 |
#define FACTOR_LINK_WIDTH (LINK_WIDTH_DEFAULT * DECIMAL_FACTORING) |
| 150 |
|
| 151 |
struct ib_pma_portcounters_cong { |
| 152 |
u8 reserved; |
| 153 |
u8 reserved1; |
| 154 |
__be16 port_check_rate; |
| 155 |
__be16 symbol_error_counter; |
| 156 |
u8 link_error_recovery_counter; |
| 157 |
u8 link_downed_counter; |
| 158 |
__be16 port_rcv_errors; |
| 159 |
__be16 port_rcv_remphys_errors; |
| 160 |
__be16 port_rcv_switch_relay_errors; |
| 161 |
__be16 port_xmit_discards; |
| 162 |
u8 port_xmit_constraint_errors; |
| 163 |
u8 port_rcv_constraint_errors; |
| 164 |
u8 reserved2; |
| 165 |
u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */ |
| 166 |
__be16 reserved3; |
| 167 |
__be16 vl15_dropped; |
| 168 |
__be64 port_xmit_data; |
| 169 |
__be64 port_rcv_data; |
| 170 |
__be64 port_xmit_packets; |
| 171 |
__be64 port_rcv_packets; |
| 172 |
__be64 port_xmit_wait; |
| 173 |
__be64 port_adr_events; |
| 174 |
} __packed; |
| 175 |
|
| 176 |
#define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004) |
| 177 |
#define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008) |
| 178 |
#define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C) |
| 179 |
#define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C) |
| 180 |
|
| 181 |
#define OPA_MAX_PREEMPT_CAP 32 |
| 182 |
#define OPA_VLARB_LOW_ELEMENTS 0 |
| 183 |
#define OPA_VLARB_HIGH_ELEMENTS 1 |
| 184 |
#define OPA_VLARB_PREEMPT_ELEMENTS 2 |
| 185 |
#define OPA_VLARB_PREEMPT_MATRIX 3 |
| 186 |
|
| 187 |
#define HFI1_XMIT_RATE_UNSUPPORTED 0x0 |
| 188 |
#define HFI1_XMIT_RATE_PICO 0x7 |
| 189 |
/* number of 4nsec cycles equaling 2secs */ |
| 190 |
#define HFI1_CONG_TIMER_PSINTERVAL 0x1DCD64EC |
| 191 |
|
| 192 |
#define IB_CC_SVCTYPE_RC 0x0 |
| 193 |
#define IB_CC_SVCTYPE_UC 0x1 |
| 194 |
#define IB_CC_SVCTYPE_RD 0x2 |
| 195 |
#define IB_CC_SVCTYPE_UD 0x3 |
| 196 |
|
| 197 |
/* |
| 198 |
* There should be an equivalent IB #define for the following, but |
| 199 |
* I cannot find it. |
| 200 |
*/ |
| 201 |
#define OPA_CC_LOG_TYPE_HFI 2 |
| 202 |
|
| 203 |
struct opa_hfi1_cong_log_event_internal { |
| 204 |
u32 lqpn; |
| 205 |
u32 rqpn; |
| 206 |
u8 sl; |
| 207 |
u8 svc_type; |
| 208 |
u32 rlid; |
| 209 |
u64 timestamp; /* wider than 32 bits to detect 32 bit rollover */ |
| 210 |
}; |
| 211 |
|
| 212 |
struct opa_hfi1_cong_log_event { |
| 213 |
u8 local_qp_cn_entry[3]; |
| 214 |
u8 remote_qp_number_cn_entry[3]; |
| 215 |
u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */ |
| 216 |
u8 reserved; |
| 217 |
__be32 remote_lid_cn_entry; |
| 218 |
__be32 timestamp_cn_entry; |
| 219 |
} __packed; |
| 220 |
|
| 221 |
#define OPA_CONG_LOG_ELEMS 96 |
| 222 |
|
| 223 |
struct opa_hfi1_cong_log { |
| 224 |
u8 log_type; |
| 225 |
u8 congestion_flags; |
| 226 |
__be16 threshold_event_counter; |
| 227 |
__be32 current_time_stamp; |
| 228 |
u8 threshold_cong_event_map[OPA_MAX_SLS / 8]; |
| 229 |
struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS]; |
| 230 |
} __packed; |
| 231 |
|
| 232 |
#define IB_CC_TABLE_CAP_DEFAULT 31 |
| 233 |
|
| 234 |
/* Port control flags */ |
| 235 |
#define IB_CC_CCS_PC_SL_BASED 0x01 |
| 236 |
|
| 237 |
struct opa_congestion_setting_entry { |
| 238 |
u8 ccti_increase; |
| 239 |
u8 reserved; |
| 240 |
__be16 ccti_timer; |
| 241 |
u8 trigger_threshold; |
| 242 |
u8 ccti_min; /* min CCTI for cc table */ |
| 243 |
} __packed; |
| 244 |
|
| 245 |
struct opa_congestion_setting_entry_shadow { |
| 246 |
u8 ccti_increase; |
| 247 |
u8 reserved; |
| 248 |
u16 ccti_timer; |
| 249 |
u8 trigger_threshold; |
| 250 |
u8 ccti_min; /* min CCTI for cc table */ |
| 251 |
} __packed; |
| 252 |
|
| 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 |
|
| 259 |
struct opa_congestion_setting_attr_shadow { |
| 260 |
u32 control_map; |
| 261 |
u16 port_control; |
| 262 |
struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS]; |
| 263 |
} __packed; |
| 264 |
|
| 265 |
#define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1 |
| 266 |
#define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1 |
| 267 |
|
| 268 |
/* 64 Congestion Control table entries in a single MAD */ |
| 269 |
#define IB_CCT_ENTRIES 64 |
| 270 |
#define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2) |
| 271 |
|
| 272 |
struct ib_cc_table_entry { |
| 273 |
__be16 entry; /* shift:2, multiplier:14 */ |
| 274 |
}; |
| 275 |
|
| 276 |
struct ib_cc_table_entry_shadow { |
| 277 |
u16 entry; /* shift:2, multiplier:14 */ |
| 278 |
}; |
| 279 |
|
| 280 |
struct ib_cc_table_attr { |
| 281 |
__be16 ccti_limit; /* max CCTI for cc table */ |
| 282 |
struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES]; |
| 283 |
} __packed; |
| 284 |
|
| 285 |
struct ib_cc_table_attr_shadow { |
| 286 |
u16 ccti_limit; /* max CCTI for cc table */ |
| 287 |
struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES]; |
| 288 |
} __packed; |
| 289 |
|
| 290 |
#define CC_TABLE_SHADOW_MAX \ |
| 291 |
(IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES) |
| 292 |
|
| 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 |
/* |
| 299 |
* struct cc_state combines the (active) per-port congestion control |
| 300 |
* table, and the (active) per-SL congestion settings. cc_state data |
| 301 |
* may need to be read in code paths that we want to be fast, so it |
| 302 |
* is an RCU protected structure. |
| 303 |
*/ |
| 304 |
struct cc_state { |
| 305 |
struct rcu_head rcu; |
| 306 |
struct cc_table_shadow cct; |
| 307 |
struct opa_congestion_setting_attr_shadow cong_setting; |
| 308 |
}; |
| 309 |
|
| 310 |
/* |
| 311 |
* OPA BufferControl MAD |
| 312 |
*/ |
| 313 |
|
| 314 |
/* attribute modifier macros */ |
| 315 |
#define OPA_AM_NPORT_SHIFT 24 |
| 316 |
#define OPA_AM_NPORT_MASK 0xff |
| 317 |
#define OPA_AM_NPORT_SMASK (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT) |
| 318 |
#define OPA_AM_NPORT(am) (((am) >> OPA_AM_NPORT_SHIFT) & \ |
| 319 |
OPA_AM_NPORT_MASK) |
| 320 |
|
| 321 |
#define OPA_AM_NBLK_SHIFT 24 |
| 322 |
#define OPA_AM_NBLK_MASK 0xff |
| 323 |
#define OPA_AM_NBLK_SMASK (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT) |
| 324 |
#define OPA_AM_NBLK(am) (((am) >> OPA_AM_NBLK_SHIFT) & \ |
| 325 |
OPA_AM_NBLK_MASK) |
| 326 |
|
| 327 |
#define OPA_AM_START_BLK_SHIFT 0 |
| 328 |
#define OPA_AM_START_BLK_MASK 0xff |
| 329 |
#define OPA_AM_START_BLK_SMASK (OPA_AM_START_BLK_MASK << \ |
| 330 |
OPA_AM_START_BLK_SHIFT) |
| 331 |
#define OPA_AM_START_BLK(am) (((am) >> OPA_AM_START_BLK_SHIFT) & \ |
| 332 |
OPA_AM_START_BLK_MASK) |
| 333 |
|
| 334 |
#define OPA_AM_PORTNUM_SHIFT 0 |
| 335 |
#define OPA_AM_PORTNUM_MASK 0xff |
| 336 |
#define OPA_AM_PORTNUM_SMASK (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT) |
| 337 |
#define OPA_AM_PORTNUM(am) (((am) >> OPA_AM_PORTNUM_SHIFT) & \ |
| 338 |
OPA_AM_PORTNUM_MASK) |
| 339 |
|
| 340 |
#define OPA_AM_ASYNC_SHIFT 12 |
| 341 |
#define OPA_AM_ASYNC_MASK 0x1 |
| 342 |
#define OPA_AM_ASYNC_SMASK (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT) |
| 343 |
#define OPA_AM_ASYNC(am) (((am) >> OPA_AM_ASYNC_SHIFT) & \ |
| 344 |
OPA_AM_ASYNC_MASK) |
| 345 |
|
| 346 |
#define OPA_AM_START_SM_CFG_SHIFT 9 |
| 347 |
#define OPA_AM_START_SM_CFG_MASK 0x1 |
| 348 |
#define OPA_AM_START_SM_CFG_SMASK (OPA_AM_START_SM_CFG_MASK << \ |
| 349 |
OPA_AM_START_SM_CFG_SHIFT) |
| 350 |
#define OPA_AM_START_SM_CFG(am) (((am) >> OPA_AM_START_SM_CFG_SHIFT) \ |
| 351 |
& OPA_AM_START_SM_CFG_MASK) |
| 352 |
|
| 353 |
#define OPA_AM_CI_ADDR_SHIFT 19 |
| 354 |
#define OPA_AM_CI_ADDR_MASK 0xfff |
| 355 |
#define OPA_AM_CI_ADDR_SMASK (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT) |
| 356 |
#define OPA_AM_CI_ADDR(am) (((am) >> OPA_AM_CI_ADDR_SHIFT) & \ |
| 357 |
OPA_AM_CI_ADDR_MASK) |
| 358 |
|
| 359 |
#define OPA_AM_CI_LEN_SHIFT 13 |
| 360 |
#define OPA_AM_CI_LEN_MASK 0x3f |
| 361 |
#define OPA_AM_CI_LEN_SMASK (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT) |
| 362 |
#define OPA_AM_CI_LEN(am) (((am) >> OPA_AM_CI_LEN_SHIFT) & \ |
| 363 |
OPA_AM_CI_LEN_MASK) |
| 364 |
|
| 365 |
/* error info macros */ |
| 366 |
#define OPA_EI_STATUS_SMASK 0x80 |
| 367 |
#define OPA_EI_CODE_SMASK 0x0f |
| 368 |
|
| 369 |
struct vl_limit { |
| 370 |
__be16 dedicated; |
| 371 |
__be16 shared; |
| 372 |
}; |
| 373 |
|
| 374 |
struct buffer_control { |
| 375 |
__be16 reserved; |
| 376 |
__be16 overall_shared_limit; |
| 377 |
struct vl_limit vl[OPA_MAX_VLS]; |
| 378 |
}; |
| 379 |
|
| 380 |
struct sc2vlnt { |
| 381 |
u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */ |
| 382 |
}; |
| 383 |
|
| 384 |
/* |
| 385 |
* The PortSamplesControl.CounterMasks field is an array of 3 bit fields |
| 386 |
* which specify the N'th counter's capabilities. See ch. 16.1.3.2. |
| 387 |
* We support 5 counters which only count the mandatory quantities. |
| 388 |
*/ |
| 389 |
#define COUNTER_MASK(q, n) (q << ((9 - n) * 3)) |
| 390 |
#define COUNTER_MASK0_9 \ |
| 391 |
cpu_to_be32(COUNTER_MASK(1, 0) | \ |
| 392 |
COUNTER_MASK(1, 1) | \ |
| 393 |
COUNTER_MASK(1, 2) | \ |
| 394 |
COUNTER_MASK(1, 3) | \ |
| 395 |
COUNTER_MASK(1, 4)) |
| 396 |
|
| 397 |
void hfi1_event_pkey_change(struct hfi1_devdata *dd, u32 port); |
| 398 |
void hfi1_handle_trap_timer(struct timer_list *t); |
| 399 |
u16 tx_link_width(u16 link_width); |
| 400 |
u64 get_xmit_wait_counters(struct hfi1_pportdata *ppd, u16 link_width, |
| 401 |
u16 link_speed, int vl); |
| 402 |
/** |
| 403 |
* get_link_speed - determine whether 12.5G or 25G speed |
| 404 |
* @link_speed: the speed of active link |
| 405 |
* @return: Return 2 if link speed identified as 12.5G |
| 406 |
* or return 1 if link speed is 25G. |
| 407 |
* |
| 408 |
* The function indirectly calculate required link speed |
| 409 |
* value for convert_xmit_counter function. If the link |
| 410 |
* speed is 25G, the function return as 1 as it is required |
| 411 |
* by xmit counter conversion formula :-( 25G / link_speed). |
| 412 |
* This conversion will provide value 1 if current |
| 413 |
* link speed is 25G or 2 if 12.5G.This is done to avoid |
| 414 |
* 12.5 float number conversion. |
| 415 |
*/ |
| 416 |
static inline u16 get_link_speed(u16 link_speed) |
| 417 |
{ |
| 418 |
return (link_speed == 1) ? |
| 419 |
LINK_SPEED_12_5G : LINK_SPEED_25G; |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* convert_xmit_counter - calculate flit times for given xmit counter |
| 424 |
* value |
| 425 |
* @xmit_wait_val: current xmit counter value |
| 426 |
* @link_width: width of active link |
| 427 |
* @link_speed: speed of active link |
| 428 |
* @return: return xmit counter value in flit times. |
| 429 |
*/ |
| 430 |
static inline u64 convert_xmit_counter(u64 xmit_wait_val, u16 link_width, |
| 431 |
u16 link_speed) |
| 432 |
{ |
| 433 |
return (xmit_wait_val * 2 * (FACTOR_LINK_WIDTH / link_width) |
| 434 |
* link_speed) / DECIMAL_FACTORING; |
| 435 |
} |
| 436 |
#endif /* _HFI1_MAD_H */ |