2 * Copyright(c) 2015, 2016 Intel Corporation.
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.
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.
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.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
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
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.
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.
50 #include <rdma/ib_pma.h>
51 #include <rdma/opa_smi.h>
52 #include <rdma/opa_port_info.h>
53 #include "opa_compat.h"
58 #define OPA_TRAP_GID_NOW_IN_SERVICE cpu_to_be16(64)
59 #define OPA_TRAP_GID_OUT_OF_SERVICE cpu_to_be16(65)
60 #define OPA_TRAP_ADD_MULTICAST_GROUP cpu_to_be16(66)
61 #define OPA_TRAL_DEL_MULTICAST_GROUP cpu_to_be16(67)
62 #define OPA_TRAP_UNPATH cpu_to_be16(68)
63 #define OPA_TRAP_REPATH cpu_to_be16(69)
64 #define OPA_TRAP_PORT_CHANGE_STATE cpu_to_be16(128)
65 #define OPA_TRAP_LINK_INTEGRITY cpu_to_be16(129)
66 #define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN cpu_to_be16(130)
67 #define OPA_TRAP_FLOW_WATCHDOG cpu_to_be16(131)
68 #define OPA_TRAP_CHANGE_CAPABILITY cpu_to_be16(144)
69 #define OPA_TRAP_CHANGE_SYSGUID cpu_to_be16(145)
70 #define OPA_TRAP_BAD_M_KEY cpu_to_be16(256)
71 #define OPA_TRAP_BAD_P_KEY cpu_to_be16(257)
72 #define OPA_TRAP_BAD_Q_KEY cpu_to_be16(258)
73 #define OPA_TRAP_SWITCH_BAD_PKEY cpu_to_be16(259)
74 #define OPA_SMA_TRAP_DATA_LINK_WIDTH cpu_to_be16(2048)
77 * Generic trap/notice other local changes flags (trap 144).
79 #define OPA_NOTICE_TRAP_LWDE_CHG 0x08 /* Link Width Downgrade Enable
82 #define OPA_NOTICE_TRAP_LSE_CHG 0x04 /* Link Speed Enable changed */
83 #define OPA_NOTICE_TRAP_LWE_CHG 0x02 /* Link Width Enable changed */
84 #define OPA_NOTICE_TRAP_NODE_DESC_CHG 0x01
86 struct opa_mad_notice_attr {
94 union ib_gid issuer_gid;
103 } __packed ntc_64_65_66_67;
110 __be32 lid; /* where violation happened */
111 u8 port_num; /* where violation happened */
112 } __packed ntc_129_130_131;
115 __be32 lid; /* LID where change occurred */
116 __be32 new_cap_mask; /* new capability mask */
119 __be16 change_flags; /* low 4 bits only */
124 __be32 lid; /* lid where sys guid changed */
142 u8 sl; /* SL: high 5 bits */
146 __be32 qp1; /* high 8 bits reserved */
147 __be32 qp2; /* high 8 bits reserved */
148 } __packed ntc_257_258;
151 __be16 flags; /* low 8 bits reserved */
155 u8 sl; /* SL: high 5 bits */
159 __be32 qp1; /* high 8 bits reserved */
160 __be32 qp2; /* high 8 bits reserved */
171 #define IB_VLARB_LOWPRI_0_31 1
172 #define IB_VLARB_LOWPRI_32_63 2
173 #define IB_VLARB_HIGHPRI_0_31 3
174 #define IB_VLARB_HIGHPRI_32_63 4
176 #define OPA_MAX_PREEMPT_CAP 32
177 #define OPA_VLARB_LOW_ELEMENTS 0
178 #define OPA_VLARB_HIGH_ELEMENTS 1
179 #define OPA_VLARB_PREEMPT_ELEMENTS 2
180 #define OPA_VLARB_PREEMPT_MATRIX 3
182 #define IB_PMA_PORT_COUNTERS_CONG cpu_to_be16(0xFF00)
184 struct ib_pma_portcounters_cong {
187 __be16 port_check_rate;
188 __be16 symbol_error_counter;
189 u8 link_error_recovery_counter;
190 u8 link_downed_counter;
191 __be16 port_rcv_errors;
192 __be16 port_rcv_remphys_errors;
193 __be16 port_rcv_switch_relay_errors;
194 __be16 port_xmit_discards;
195 u8 port_xmit_constraint_errors;
196 u8 port_rcv_constraint_errors;
198 u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
201 __be64 port_xmit_data;
202 __be64 port_rcv_data;
203 __be64 port_xmit_packets;
204 __be64 port_rcv_packets;
205 __be64 port_xmit_wait;
206 __be64 port_adr_events;
209 #define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004)
210 #define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
211 #define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C)
212 #define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C)
214 #define OPA_MAX_PREEMPT_CAP 32
215 #define OPA_VLARB_LOW_ELEMENTS 0
216 #define OPA_VLARB_HIGH_ELEMENTS 1
217 #define OPA_VLARB_PREEMPT_ELEMENTS 2
218 #define OPA_VLARB_PREEMPT_MATRIX 3
220 #define HFI1_XMIT_RATE_UNSUPPORTED 0x0
221 #define HFI1_XMIT_RATE_PICO 0x7
222 /* number of 4nsec cycles equaling 2secs */
223 #define HFI1_CONG_TIMER_PSINTERVAL 0x1DCD64EC
225 #define IB_CC_SVCTYPE_RC 0x0
226 #define IB_CC_SVCTYPE_UC 0x1
227 #define IB_CC_SVCTYPE_RD 0x2
228 #define IB_CC_SVCTYPE_UD 0x3
231 * There should be an equivalent IB #define for the following, but
234 #define OPA_CC_LOG_TYPE_HFI 2
236 struct opa_hfi1_cong_log_event_internal {
242 s64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
245 struct opa_hfi1_cong_log_event {
246 u8 local_qp_cn_entry[3];
247 u8 remote_qp_number_cn_entry[3];
248 u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
250 __be32 remote_lid_cn_entry;
251 __be32 timestamp_cn_entry;
254 #define OPA_CONG_LOG_ELEMS 96
256 struct opa_hfi1_cong_log {
259 __be16 threshold_event_counter;
260 __be32 current_time_stamp;
261 u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
262 struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
265 #define IB_CC_TABLE_CAP_DEFAULT 31
267 /* Port control flags */
268 #define IB_CC_CCS_PC_SL_BASED 0x01
270 struct opa_congestion_setting_entry {
274 u8 trigger_threshold;
275 u8 ccti_min; /* min CCTI for cc table */
278 struct opa_congestion_setting_entry_shadow {
282 u8 trigger_threshold;
283 u8 ccti_min; /* min CCTI for cc table */
286 struct opa_congestion_setting_attr {
289 struct opa_congestion_setting_entry entries[OPA_MAX_SLS];
292 struct opa_congestion_setting_attr_shadow {
295 struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS];
298 #define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1
299 #define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1
301 /* 64 Congestion Control table entries in a single MAD */
302 #define IB_CCT_ENTRIES 64
303 #define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2)
305 struct ib_cc_table_entry {
306 __be16 entry; /* shift:2, multiplier:14 */
309 struct ib_cc_table_entry_shadow {
310 u16 entry; /* shift:2, multiplier:14 */
313 struct ib_cc_table_attr {
314 __be16 ccti_limit; /* max CCTI for cc table */
315 struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES];
318 struct ib_cc_table_attr_shadow {
319 u16 ccti_limit; /* max CCTI for cc table */
320 struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
323 #define CC_TABLE_SHADOW_MAX \
324 (IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES)
326 struct cc_table_shadow {
327 u16 ccti_limit; /* max CCTI for cc table */
328 struct ib_cc_table_entry_shadow entries[CC_TABLE_SHADOW_MAX];
332 * struct cc_state combines the (active) per-port congestion control
333 * table, and the (active) per-SL congestion settings. cc_state data
334 * may need to be read in code paths that we want to be fast, so it
335 * is an RCU protected structure.
339 struct cc_table_shadow cct;
340 struct opa_congestion_setting_attr_shadow cong_setting;
344 * OPA BufferControl MAD
347 /* attribute modifier macros */
348 #define OPA_AM_NPORT_SHIFT 24
349 #define OPA_AM_NPORT_MASK 0xff
350 #define OPA_AM_NPORT_SMASK (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT)
351 #define OPA_AM_NPORT(am) (((am) >> OPA_AM_NPORT_SHIFT) & \
354 #define OPA_AM_NBLK_SHIFT 24
355 #define OPA_AM_NBLK_MASK 0xff
356 #define OPA_AM_NBLK_SMASK (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT)
357 #define OPA_AM_NBLK(am) (((am) >> OPA_AM_NBLK_SHIFT) & \
360 #define OPA_AM_START_BLK_SHIFT 0
361 #define OPA_AM_START_BLK_MASK 0xff
362 #define OPA_AM_START_BLK_SMASK (OPA_AM_START_BLK_MASK << \
363 OPA_AM_START_BLK_SHIFT)
364 #define OPA_AM_START_BLK(am) (((am) >> OPA_AM_START_BLK_SHIFT) & \
365 OPA_AM_START_BLK_MASK)
367 #define OPA_AM_PORTNUM_SHIFT 0
368 #define OPA_AM_PORTNUM_MASK 0xff
369 #define OPA_AM_PORTNUM_SMASK (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT)
370 #define OPA_AM_PORTNUM(am) (((am) >> OPA_AM_PORTNUM_SHIFT) & \
373 #define OPA_AM_ASYNC_SHIFT 12
374 #define OPA_AM_ASYNC_MASK 0x1
375 #define OPA_AM_ASYNC_SMASK (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT)
376 #define OPA_AM_ASYNC(am) (((am) >> OPA_AM_ASYNC_SHIFT) & \
379 #define OPA_AM_START_SM_CFG_SHIFT 9
380 #define OPA_AM_START_SM_CFG_MASK 0x1
381 #define OPA_AM_START_SM_CFG_SMASK (OPA_AM_START_SM_CFG_MASK << \
382 OPA_AM_START_SM_CFG_SHIFT)
383 #define OPA_AM_START_SM_CFG(am) (((am) >> OPA_AM_START_SM_CFG_SHIFT) \
384 & OPA_AM_START_SM_CFG_MASK)
386 #define OPA_AM_CI_ADDR_SHIFT 19
387 #define OPA_AM_CI_ADDR_MASK 0xfff
388 #define OPA_AM_CI_ADDR_SMASK (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT)
389 #define OPA_AM_CI_ADDR(am) (((am) >> OPA_AM_CI_ADDR_SHIFT) & \
392 #define OPA_AM_CI_LEN_SHIFT 13
393 #define OPA_AM_CI_LEN_MASK 0x3f
394 #define OPA_AM_CI_LEN_SMASK (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT)
395 #define OPA_AM_CI_LEN(am) (((am) >> OPA_AM_CI_LEN_SHIFT) & \
398 /* error info macros */
399 #define OPA_EI_STATUS_SMASK 0x80
400 #define OPA_EI_CODE_SMASK 0x0f
407 struct buffer_control {
409 __be16 overall_shared_limit;
410 struct vl_limit vl[OPA_MAX_VLS];
414 u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */
418 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
419 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
420 * We support 5 counters which only count the mandatory quantities.
422 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
423 #define COUNTER_MASK0_9 \
424 cpu_to_be32(COUNTER_MASK(1, 0) | \
425 COUNTER_MASK(1, 1) | \
426 COUNTER_MASK(1, 2) | \
427 COUNTER_MASK(1, 3) | \
430 void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port);
432 #endif /* _HFI1_MAD_H */