Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
0002 /*
0003  * Copyright(c) 2015 - 2017 Intel Corporation.
0004  */
0005 
0006 #ifndef _HFI1_MAD_H
0007 #define _HFI1_MAD_H
0008 
0009 #include <rdma/ib_pma.h>
0010 #include <rdma/opa_smi.h>
0011 #include <rdma/opa_port_info.h>
0012 #include "opa_compat.h"
0013 
0014 /*
0015  * OPA Traps
0016  */
0017 #define OPA_TRAP_GID_NOW_IN_SERVICE             cpu_to_be16(64)
0018 #define OPA_TRAP_GID_OUT_OF_SERVICE             cpu_to_be16(65)
0019 #define OPA_TRAP_ADD_MULTICAST_GROUP            cpu_to_be16(66)
0020 #define OPA_TRAL_DEL_MULTICAST_GROUP            cpu_to_be16(67)
0021 #define OPA_TRAP_UNPATH                         cpu_to_be16(68)
0022 #define OPA_TRAP_REPATH                         cpu_to_be16(69)
0023 #define OPA_TRAP_PORT_CHANGE_STATE              cpu_to_be16(128)
0024 #define OPA_TRAP_LINK_INTEGRITY                 cpu_to_be16(129)
0025 #define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN       cpu_to_be16(130)
0026 #define OPA_TRAP_FLOW_WATCHDOG                  cpu_to_be16(131)
0027 #define OPA_TRAP_CHANGE_CAPABILITY              cpu_to_be16(144)
0028 #define OPA_TRAP_CHANGE_SYSGUID                 cpu_to_be16(145)
0029 #define OPA_TRAP_BAD_M_KEY                      cpu_to_be16(256)
0030 #define OPA_TRAP_BAD_P_KEY                      cpu_to_be16(257)
0031 #define OPA_TRAP_BAD_Q_KEY                      cpu_to_be16(258)
0032 #define OPA_TRAP_SWITCH_BAD_PKEY                cpu_to_be16(259)
0033 #define OPA_SMA_TRAP_DATA_LINK_WIDTH            cpu_to_be16(2048)
0034 
0035 /*
0036  * Generic trap/notice other local changes flags (trap 144).
0037  */
0038 #define OPA_NOTICE_TRAP_LWDE_CHG        0x08 /* Link Width Downgrade Enable
0039                           * changed
0040                           */
0041 #define OPA_NOTICE_TRAP_LSE_CHG         0x04 /* Link Speed Enable changed */
0042 #define OPA_NOTICE_TRAP_LWE_CHG         0x02 /* Link Width Enable changed */
0043 #define OPA_NOTICE_TRAP_NODE_DESC_CHG   0x01
0044 
0045 struct opa_mad_notice_attr {
0046     u8 generic_type;
0047     u8 prod_type_msb;
0048     __be16 prod_type_lsb;
0049     __be16 trap_num;
0050     __be16 toggle_count;
0051     __be32 issuer_lid;
0052     __be32 reserved1;
0053     union ib_gid issuer_gid;
0054 
0055     union {
0056         struct {
0057             u8  details[64];
0058         } raw_data;
0059 
0060         struct {
0061             union ib_gid    gid;
0062         } __packed ntc_64_65_66_67;
0063 
0064         struct {
0065             __be32  lid;
0066         } __packed ntc_128;
0067 
0068         struct {
0069             __be32  lid;        /* where violation happened */
0070             u8  port_num;   /* where violation happened */
0071         } __packed ntc_129_130_131;
0072 
0073         struct {
0074             __be32  lid;        /* LID where change occurred */
0075             __be32  new_cap_mask;   /* new capability mask */
0076             __be16  reserved2;
0077             __be16  cap_mask3;
0078             __be16  change_flags;   /* low 4 bits only */
0079         } __packed ntc_144;
0080 
0081         struct {
0082             __be64  new_sys_guid;
0083             __be32  lid;        /* lid where sys guid changed */
0084         } __packed ntc_145;
0085 
0086         struct {
0087             __be32  lid;
0088             __be32  dr_slid;
0089             u8  method;
0090             u8  dr_trunc_hop;
0091             __be16  attr_id;
0092             __be32  attr_mod;
0093             __be64  mkey;
0094             u8  dr_rtn_path[30];
0095         } __packed ntc_256;
0096 
0097         struct {
0098             __be32      lid1;
0099             __be32      lid2;
0100             __be32      key;
0101             u8      sl; /* SL: high 5 bits */
0102             u8      reserved3[3];
0103             union ib_gid    gid1;
0104             union ib_gid    gid2;
0105             __be32      qp1;    /* high 8 bits reserved */
0106             __be32      qp2;    /* high 8 bits reserved */
0107         } __packed ntc_257_258;
0108 
0109         struct {
0110             __be16      flags;  /* low 8 bits reserved */
0111             __be16      pkey;
0112             __be32      lid1;
0113             __be32      lid2;
0114             u8      sl; /* SL: high 5 bits */
0115             u8      reserved4[3];
0116             union ib_gid    gid1;
0117             union ib_gid    gid2;
0118             __be32      qp1;    /* high 8 bits reserved */
0119             __be32      qp2;    /* high 8 bits reserved */
0120         } __packed ntc_259;
0121 
0122         struct {
0123             __be32  lid;
0124         } __packed ntc_2048;
0125 
0126     };
0127     u8  class_data[];
0128 };
0129 
0130 #define IB_VLARB_LOWPRI_0_31    1
0131 #define IB_VLARB_LOWPRI_32_63   2
0132 #define IB_VLARB_HIGHPRI_0_31   3
0133 #define IB_VLARB_HIGHPRI_32_63  4
0134 
0135 #define OPA_MAX_PREEMPT_CAP         32
0136 #define OPA_VLARB_LOW_ELEMENTS       0
0137 #define OPA_VLARB_HIGH_ELEMENTS      1
0138 #define OPA_VLARB_PREEMPT_ELEMENTS   2
0139 #define OPA_VLARB_PREEMPT_MATRIX     3
0140 
0141 #define IB_PMA_PORT_COUNTERS_CONG       cpu_to_be16(0xFF00)
0142 #define LINK_SPEED_25G      1
0143 #define LINK_SPEED_12_5G    2
0144 #define LINK_WIDTH_DEFAULT  4
0145 #define DECIMAL_FACTORING   1000
0146 /*
0147  * The default link width is multiplied by 1000
0148  * to get accurate value after division.
0149  */
0150 #define FACTOR_LINK_WIDTH   (LINK_WIDTH_DEFAULT * DECIMAL_FACTORING)
0151 
0152 struct ib_pma_portcounters_cong {
0153     u8 reserved;
0154     u8 reserved1;
0155     __be16 port_check_rate;
0156     __be16 symbol_error_counter;
0157     u8 link_error_recovery_counter;
0158     u8 link_downed_counter;
0159     __be16 port_rcv_errors;
0160     __be16 port_rcv_remphys_errors;
0161     __be16 port_rcv_switch_relay_errors;
0162     __be16 port_xmit_discards;
0163     u8 port_xmit_constraint_errors;
0164     u8 port_rcv_constraint_errors;
0165     u8 reserved2;
0166     u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
0167     __be16 reserved3;
0168     __be16 vl15_dropped;
0169     __be64 port_xmit_data;
0170     __be64 port_rcv_data;
0171     __be64 port_xmit_packets;
0172     __be64 port_rcv_packets;
0173     __be64 port_xmit_wait;
0174     __be64 port_adr_events;
0175 } __packed;
0176 
0177 #define IB_SMP_UNSUP_VERSION    cpu_to_be16(0x0004)
0178 #define IB_SMP_UNSUP_METHOD     cpu_to_be16(0x0008)
0179 #define IB_SMP_UNSUP_METH_ATTR  cpu_to_be16(0x000C)
0180 #define IB_SMP_INVALID_FIELD    cpu_to_be16(0x001C)
0181 
0182 #define OPA_MAX_PREEMPT_CAP         32
0183 #define OPA_VLARB_LOW_ELEMENTS       0
0184 #define OPA_VLARB_HIGH_ELEMENTS      1
0185 #define OPA_VLARB_PREEMPT_ELEMENTS   2
0186 #define OPA_VLARB_PREEMPT_MATRIX     3
0187 
0188 #define HFI1_XMIT_RATE_UNSUPPORTED               0x0
0189 #define HFI1_XMIT_RATE_PICO                      0x7
0190 /* number of 4nsec cycles equaling 2secs */
0191 #define HFI1_CONG_TIMER_PSINTERVAL               0x1DCD64EC
0192 
0193 #define IB_CC_SVCTYPE_RC 0x0
0194 #define IB_CC_SVCTYPE_UC 0x1
0195 #define IB_CC_SVCTYPE_RD 0x2
0196 #define IB_CC_SVCTYPE_UD 0x3
0197 
0198 /*
0199  * There should be an equivalent IB #define for the following, but
0200  * I cannot find it.
0201  */
0202 #define OPA_CC_LOG_TYPE_HFI 2
0203 
0204 struct opa_hfi1_cong_log_event_internal {
0205     u32 lqpn;
0206     u32 rqpn;
0207     u8 sl;
0208     u8 svc_type;
0209     u32 rlid;
0210     u64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
0211 };
0212 
0213 struct opa_hfi1_cong_log_event {
0214     u8 local_qp_cn_entry[3];
0215     u8 remote_qp_number_cn_entry[3];
0216     u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
0217     u8 reserved;
0218     __be32 remote_lid_cn_entry;
0219     __be32 timestamp_cn_entry;
0220 } __packed;
0221 
0222 #define OPA_CONG_LOG_ELEMS  96
0223 
0224 struct opa_hfi1_cong_log {
0225     u8 log_type;
0226     u8 congestion_flags;
0227     __be16 threshold_event_counter;
0228     __be32 current_time_stamp;
0229     u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
0230     struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
0231 } __packed;
0232 
0233 #define IB_CC_TABLE_CAP_DEFAULT 31
0234 
0235 /* Port control flags */
0236 #define IB_CC_CCS_PC_SL_BASED 0x01
0237 
0238 struct opa_congestion_setting_entry {
0239     u8 ccti_increase;
0240     u8 reserved;
0241     __be16 ccti_timer;
0242     u8 trigger_threshold;
0243     u8 ccti_min; /* min CCTI for cc table */
0244 } __packed;
0245 
0246 struct opa_congestion_setting_entry_shadow {
0247     u8 ccti_increase;
0248     u8 reserved;
0249     u16 ccti_timer;
0250     u8 trigger_threshold;
0251     u8 ccti_min; /* min CCTI for cc table */
0252 } __packed;
0253 
0254 struct opa_congestion_setting_attr {
0255     __be32 control_map;
0256     __be16 port_control;
0257     struct opa_congestion_setting_entry entries[OPA_MAX_SLS];
0258 } __packed;
0259 
0260 struct opa_congestion_setting_attr_shadow {
0261     u32 control_map;
0262     u16 port_control;
0263     struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS];
0264 } __packed;
0265 
0266 #define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1
0267 #define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1
0268 
0269 /* 64 Congestion Control table entries in a single MAD */
0270 #define IB_CCT_ENTRIES 64
0271 #define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2)
0272 
0273 struct ib_cc_table_entry {
0274     __be16 entry; /* shift:2, multiplier:14 */
0275 };
0276 
0277 struct ib_cc_table_entry_shadow {
0278     u16 entry; /* shift:2, multiplier:14 */
0279 };
0280 
0281 struct ib_cc_table_attr {
0282     __be16 ccti_limit; /* max CCTI for cc table */
0283     struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES];
0284 } __packed;
0285 
0286 struct ib_cc_table_attr_shadow {
0287     u16 ccti_limit; /* max CCTI for cc table */
0288     struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
0289 } __packed;
0290 
0291 #define CC_TABLE_SHADOW_MAX \
0292     (IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES)
0293 
0294 struct cc_table_shadow {
0295     u16 ccti_limit; /* max CCTI for cc table */
0296     struct ib_cc_table_entry_shadow entries[CC_TABLE_SHADOW_MAX];
0297 } __packed;
0298 
0299 /*
0300  * struct cc_state combines the (active) per-port congestion control
0301  * table, and the (active) per-SL congestion settings. cc_state data
0302  * may need to be read in code paths that we want to be fast, so it
0303  * is an RCU protected structure.
0304  */
0305 struct cc_state {
0306     struct rcu_head rcu;
0307     struct cc_table_shadow cct;
0308     struct opa_congestion_setting_attr_shadow cong_setting;
0309 };
0310 
0311 /*
0312  * OPA BufferControl MAD
0313  */
0314 
0315 /* attribute modifier macros */
0316 #define OPA_AM_NPORT_SHIFT  24
0317 #define OPA_AM_NPORT_MASK   0xff
0318 #define OPA_AM_NPORT_SMASK  (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT)
0319 #define OPA_AM_NPORT(am)    (((am) >> OPA_AM_NPORT_SHIFT) & \
0320                     OPA_AM_NPORT_MASK)
0321 
0322 #define OPA_AM_NBLK_SHIFT   24
0323 #define OPA_AM_NBLK_MASK    0xff
0324 #define OPA_AM_NBLK_SMASK   (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT)
0325 #define OPA_AM_NBLK(am)     (((am) >> OPA_AM_NBLK_SHIFT) & \
0326                     OPA_AM_NBLK_MASK)
0327 
0328 #define OPA_AM_START_BLK_SHIFT  0
0329 #define OPA_AM_START_BLK_MASK   0xff
0330 #define OPA_AM_START_BLK_SMASK  (OPA_AM_START_BLK_MASK << \
0331                     OPA_AM_START_BLK_SHIFT)
0332 #define OPA_AM_START_BLK(am)    (((am) >> OPA_AM_START_BLK_SHIFT) & \
0333                     OPA_AM_START_BLK_MASK)
0334 
0335 #define OPA_AM_PORTNUM_SHIFT    0
0336 #define OPA_AM_PORTNUM_MASK 0xff
0337 #define OPA_AM_PORTNUM_SMASK    (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT)
0338 #define OPA_AM_PORTNUM(am)  (((am) >> OPA_AM_PORTNUM_SHIFT) & \
0339                     OPA_AM_PORTNUM_MASK)
0340 
0341 #define OPA_AM_ASYNC_SHIFT  12
0342 #define OPA_AM_ASYNC_MASK   0x1
0343 #define OPA_AM_ASYNC_SMASK  (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT)
0344 #define OPA_AM_ASYNC(am)    (((am) >> OPA_AM_ASYNC_SHIFT) & \
0345                     OPA_AM_ASYNC_MASK)
0346 
0347 #define OPA_AM_START_SM_CFG_SHIFT   9
0348 #define OPA_AM_START_SM_CFG_MASK    0x1
0349 #define OPA_AM_START_SM_CFG_SMASK   (OPA_AM_START_SM_CFG_MASK << \
0350                         OPA_AM_START_SM_CFG_SHIFT)
0351 #define OPA_AM_START_SM_CFG(am)     (((am) >> OPA_AM_START_SM_CFG_SHIFT) \
0352                         & OPA_AM_START_SM_CFG_MASK)
0353 
0354 #define OPA_AM_CI_ADDR_SHIFT    19
0355 #define OPA_AM_CI_ADDR_MASK 0xfff
0356 #define OPA_AM_CI_ADDR_SMASK    (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT)
0357 #define OPA_AM_CI_ADDR(am)  (((am) >> OPA_AM_CI_ADDR_SHIFT) & \
0358                     OPA_AM_CI_ADDR_MASK)
0359 
0360 #define OPA_AM_CI_LEN_SHIFT 13
0361 #define OPA_AM_CI_LEN_MASK  0x3f
0362 #define OPA_AM_CI_LEN_SMASK (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT)
0363 #define OPA_AM_CI_LEN(am)   (((am) >> OPA_AM_CI_LEN_SHIFT) & \
0364                     OPA_AM_CI_LEN_MASK)
0365 
0366 /* error info macros */
0367 #define OPA_EI_STATUS_SMASK 0x80
0368 #define OPA_EI_CODE_SMASK   0x0f
0369 
0370 struct vl_limit {
0371     __be16 dedicated;
0372     __be16 shared;
0373 };
0374 
0375 struct buffer_control {
0376     __be16 reserved;
0377     __be16 overall_shared_limit;
0378     struct vl_limit vl[OPA_MAX_VLS];
0379 };
0380 
0381 struct sc2vlnt {
0382     u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */
0383 };
0384 
0385 /*
0386  * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
0387  * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
0388  * We support 5 counters which only count the mandatory quantities.
0389  */
0390 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
0391 #define COUNTER_MASK0_9 \
0392     cpu_to_be32(COUNTER_MASK(1, 0) | \
0393             COUNTER_MASK(1, 1) | \
0394             COUNTER_MASK(1, 2) | \
0395             COUNTER_MASK(1, 3) | \
0396             COUNTER_MASK(1, 4))
0397 
0398 void hfi1_event_pkey_change(struct hfi1_devdata *dd, u32 port);
0399 void hfi1_handle_trap_timer(struct timer_list *t);
0400 u16 tx_link_width(u16 link_width);
0401 u64 get_xmit_wait_counters(struct hfi1_pportdata *ppd, u16 link_width,
0402                u16 link_speed, int vl);
0403 /**
0404  * get_link_speed - determine whether 12.5G or 25G speed
0405  * @link_speed: the speed of active link
0406  * @return: Return 2 if link speed identified as 12.5G
0407  * or return 1 if link speed is 25G.
0408  *
0409  * The function indirectly calculate required link speed
0410  * value for convert_xmit_counter function. If the link
0411  * speed is 25G, the function return as 1 as it is required
0412  * by xmit counter conversion formula :-( 25G / link_speed).
0413  * This conversion will provide value 1 if current
0414  * link speed is 25G or 2 if 12.5G.This is done to avoid
0415  * 12.5 float number conversion.
0416  */
0417 static inline u16 get_link_speed(u16 link_speed)
0418 {
0419     return (link_speed == 1) ?
0420          LINK_SPEED_12_5G : LINK_SPEED_25G;
0421 }
0422 
0423 /**
0424  * convert_xmit_counter - calculate flit times for given xmit counter
0425  * value
0426  * @xmit_wait_val: current xmit counter value
0427  * @link_width: width of active link
0428  * @link_speed: speed of active link
0429  * @return: return xmit counter value in flit times.
0430  */
0431 static inline u64 convert_xmit_counter(u64 xmit_wait_val, u16 link_width,
0432                        u16 link_speed)
0433 {
0434     return (xmit_wait_val * 2 * (FACTOR_LINK_WIDTH / link_width)
0435          * link_speed) / DECIMAL_FACTORING;
0436 }
0437 #endif              /* _HFI1_MAD_H */