Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
0002 /*
0003  * Copyright(c) 2015 - 2020 Intel Corporation.
0004  */
0005 
0006 #ifndef _COMMON_H
0007 #define _COMMON_H
0008 
0009 #include <rdma/hfi/hfi1_user.h>
0010 
0011 /*
0012  * This file contains defines, structures, etc. that are used
0013  * to communicate between kernel and user code.
0014  */
0015 
0016 /* version of protocol header (known to chip also). In the long run,
0017  * we should be able to generate and accept a range of version numbers;
0018  * for now we only accept one, and it's compiled in.
0019  */
0020 #define IPS_PROTO_VERSION 2
0021 
0022 /*
0023  * These are compile time constants that you may want to enable or disable
0024  * if you are trying to debug problems with code or performance.
0025  * HFI1_VERBOSE_TRACING define as 1 if you want additional tracing in
0026  * fast path code
0027  * HFI1_TRACE_REGWRITES define as 1 if you want register writes to be
0028  * traced in fast path code
0029  * _HFI1_TRACING define as 0 if you want to remove all tracing in a
0030  * compilation unit
0031  */
0032 
0033 /* driver/hw feature set bitmask */
0034 #define HFI1_CAP_USER_SHIFT      24
0035 #define HFI1_CAP_MASK            ((1UL << HFI1_CAP_USER_SHIFT) - 1)
0036 /* locked flag - if set, only HFI1_CAP_WRITABLE_MASK bits can be set */
0037 #define HFI1_CAP_LOCKED_SHIFT    63
0038 #define HFI1_CAP_LOCKED_MASK     0x1ULL
0039 #define HFI1_CAP_LOCKED_SMASK    (HFI1_CAP_LOCKED_MASK << HFI1_CAP_LOCKED_SHIFT)
0040 /* extra bits used between kernel and user processes */
0041 #define HFI1_CAP_MISC_SHIFT      (HFI1_CAP_USER_SHIFT * 2)
0042 #define HFI1_CAP_MISC_MASK       ((1ULL << (HFI1_CAP_LOCKED_SHIFT - \
0043                        HFI1_CAP_MISC_SHIFT)) - 1)
0044 
0045 #define HFI1_CAP_KSET(cap) ({ hfi1_cap_mask |= HFI1_CAP_##cap; hfi1_cap_mask; })
0046 #define HFI1_CAP_KCLEAR(cap)                        \
0047     ({                              \
0048         hfi1_cap_mask &= ~HFI1_CAP_##cap;           \
0049         hfi1_cap_mask;                      \
0050     })
0051 #define HFI1_CAP_USET(cap)                      \
0052     ({                              \
0053         hfi1_cap_mask |= (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
0054         hfi1_cap_mask;                      \
0055         })
0056 #define HFI1_CAP_UCLEAR(cap)                        \
0057     ({                              \
0058         hfi1_cap_mask &= ~(HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
0059         hfi1_cap_mask;                      \
0060     })
0061 #define HFI1_CAP_SET(cap)                       \
0062     ({                              \
0063         hfi1_cap_mask |= (HFI1_CAP_##cap | (HFI1_CAP_##cap <<   \
0064                           HFI1_CAP_USER_SHIFT)); \
0065         hfi1_cap_mask;                      \
0066     })
0067 #define HFI1_CAP_CLEAR(cap)                     \
0068     ({                              \
0069         hfi1_cap_mask &= ~(HFI1_CAP_##cap |         \
0070                   (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT)); \
0071         hfi1_cap_mask;                      \
0072     })
0073 #define HFI1_CAP_LOCK()                         \
0074     ({ hfi1_cap_mask |= HFI1_CAP_LOCKED_SMASK; hfi1_cap_mask; })
0075 #define HFI1_CAP_LOCKED() (!!(hfi1_cap_mask & HFI1_CAP_LOCKED_SMASK))
0076 /*
0077  * The set of capability bits that can be changed after initial load
0078  * This set is the same for kernel and user contexts. However, for
0079  * user contexts, the set can be further filtered by using the
0080  * HFI1_CAP_RESERVED_MASK bits.
0081  */
0082 #define HFI1_CAP_WRITABLE_MASK   (HFI1_CAP_SDMA_AHG |           \
0083                   HFI1_CAP_HDRSUPP |            \
0084                   HFI1_CAP_MULTI_PKT_EGR |      \
0085                   HFI1_CAP_NODROP_RHQ_FULL |        \
0086                   HFI1_CAP_NODROP_EGR_FULL |        \
0087                   HFI1_CAP_ALLOW_PERM_JKEY |        \
0088                   HFI1_CAP_STATIC_RATE_CTRL |       \
0089                   HFI1_CAP_PRINT_UNIMPL |       \
0090                   HFI1_CAP_TID_UNMAP |          \
0091                   HFI1_CAP_OPFN)
0092 /*
0093  * A set of capability bits that are "global" and are not allowed to be
0094  * set in the user bitmask.
0095  */
0096 #define HFI1_CAP_RESERVED_MASK   ((HFI1_CAP_SDMA |          \
0097                    HFI1_CAP_USE_SDMA_HEAD |     \
0098                    HFI1_CAP_EXTENDED_PSN |      \
0099                    HFI1_CAP_PRINT_UNIMPL |      \
0100                    HFI1_CAP_NO_INTEGRITY |      \
0101                    HFI1_CAP_PKEY_CHECK |        \
0102                    HFI1_CAP_TID_RDMA |          \
0103                    HFI1_CAP_OPFN |          \
0104                    HFI1_CAP_AIP) <<         \
0105                   HFI1_CAP_USER_SHIFT)
0106 /*
0107  * Set of capabilities that need to be enabled for kernel context in
0108  * order to be allowed for user contexts, as well.
0109  */
0110 #define HFI1_CAP_MUST_HAVE_KERN (HFI1_CAP_STATIC_RATE_CTRL)
0111 /* Default enabled capabilities (both kernel and user) */
0112 #define HFI1_CAP_MASK_DEFAULT    (HFI1_CAP_HDRSUPP |            \
0113                  HFI1_CAP_NODROP_RHQ_FULL |     \
0114                  HFI1_CAP_NODROP_EGR_FULL |     \
0115                  HFI1_CAP_SDMA |            \
0116                  HFI1_CAP_PRINT_UNIMPL |        \
0117                  HFI1_CAP_STATIC_RATE_CTRL |        \
0118                  HFI1_CAP_PKEY_CHECK |          \
0119                  HFI1_CAP_MULTI_PKT_EGR |       \
0120                  HFI1_CAP_EXTENDED_PSN |        \
0121                  HFI1_CAP_AIP |             \
0122                  ((HFI1_CAP_HDRSUPP |           \
0123                    HFI1_CAP_MULTI_PKT_EGR |     \
0124                    HFI1_CAP_STATIC_RATE_CTRL |      \
0125                    HFI1_CAP_PKEY_CHECK |        \
0126                    HFI1_CAP_EARLY_CREDIT_RETURN) << \
0127                   HFI1_CAP_USER_SHIFT))
0128 /*
0129  * A bitmask of kernel/global capabilities that should be communicated
0130  * to user level processes.
0131  */
0132 #define HFI1_CAP_K2U (HFI1_CAP_SDMA |           \
0133              HFI1_CAP_EXTENDED_PSN |        \
0134              HFI1_CAP_PKEY_CHECK |      \
0135              HFI1_CAP_NO_INTEGRITY)
0136 
0137 #define HFI1_USER_SWVERSION ((HFI1_USER_SWMAJOR << HFI1_SWMAJOR_SHIFT) | \
0138                  HFI1_USER_SWMINOR)
0139 
0140 /*
0141  * The next set of defines are for packet headers, and chip register
0142  * and memory bits that are visible to and/or used by user-mode software.
0143  */
0144 
0145 /*
0146  * Receive Header Flags
0147  */
0148 #define RHF_PKT_LEN_SHIFT   0
0149 #define RHF_PKT_LEN_MASK    0xfffull
0150 #define RHF_PKT_LEN_SMASK (RHF_PKT_LEN_MASK << RHF_PKT_LEN_SHIFT)
0151 
0152 #define RHF_RCV_TYPE_SHIFT  12
0153 #define RHF_RCV_TYPE_MASK   0x7ull
0154 #define RHF_RCV_TYPE_SMASK (RHF_RCV_TYPE_MASK << RHF_RCV_TYPE_SHIFT)
0155 
0156 #define RHF_USE_EGR_BFR_SHIFT   15
0157 #define RHF_USE_EGR_BFR_MASK    0x1ull
0158 #define RHF_USE_EGR_BFR_SMASK (RHF_USE_EGR_BFR_MASK << RHF_USE_EGR_BFR_SHIFT)
0159 
0160 #define RHF_EGR_INDEX_SHIFT 16
0161 #define RHF_EGR_INDEX_MASK  0x7ffull
0162 #define RHF_EGR_INDEX_SMASK (RHF_EGR_INDEX_MASK << RHF_EGR_INDEX_SHIFT)
0163 
0164 #define RHF_DC_INFO_SHIFT   27
0165 #define RHF_DC_INFO_MASK    0x1ull
0166 #define RHF_DC_INFO_SMASK (RHF_DC_INFO_MASK << RHF_DC_INFO_SHIFT)
0167 
0168 #define RHF_RCV_SEQ_SHIFT   28
0169 #define RHF_RCV_SEQ_MASK    0xfull
0170 #define RHF_RCV_SEQ_SMASK (RHF_RCV_SEQ_MASK << RHF_RCV_SEQ_SHIFT)
0171 
0172 #define RHF_EGR_OFFSET_SHIFT    32
0173 #define RHF_EGR_OFFSET_MASK 0xfffull
0174 #define RHF_EGR_OFFSET_SMASK (RHF_EGR_OFFSET_MASK << RHF_EGR_OFFSET_SHIFT)
0175 #define RHF_HDRQ_OFFSET_SHIFT   44
0176 #define RHF_HDRQ_OFFSET_MASK    0x1ffull
0177 #define RHF_HDRQ_OFFSET_SMASK (RHF_HDRQ_OFFSET_MASK << RHF_HDRQ_OFFSET_SHIFT)
0178 #define RHF_K_HDR_LEN_ERR   (0x1ull << 53)
0179 #define RHF_DC_UNC_ERR      (0x1ull << 54)
0180 #define RHF_DC_ERR      (0x1ull << 55)
0181 #define RHF_RCV_TYPE_ERR_SHIFT  56
0182 #define RHF_RCV_TYPE_ERR_MASK   0x7ul
0183 #define RHF_RCV_TYPE_ERR_SMASK (RHF_RCV_TYPE_ERR_MASK << RHF_RCV_TYPE_ERR_SHIFT)
0184 #define RHF_TID_ERR     (0x1ull << 59)
0185 #define RHF_LEN_ERR     (0x1ull << 60)
0186 #define RHF_ECC_ERR     (0x1ull << 61)
0187 #define RHF_RESERVED        (0x1ull << 62)
0188 #define RHF_ICRC_ERR        (0x1ull << 63)
0189 
0190 #define RHF_ERROR_SMASK 0xffe0000000000000ull       /* bits 63:53 */
0191 
0192 /* RHF receive types */
0193 #define RHF_RCV_TYPE_EXPECTED 0
0194 #define RHF_RCV_TYPE_EAGER    1
0195 #define RHF_RCV_TYPE_IB       2 /* normal IB, IB Raw, or IPv6 */
0196 #define RHF_RCV_TYPE_ERROR    3
0197 #define RHF_RCV_TYPE_BYPASS   4
0198 #define RHF_RCV_TYPE_INVALID5 5
0199 #define RHF_RCV_TYPE_INVALID6 6
0200 #define RHF_RCV_TYPE_INVALID7 7
0201 
0202 /* RHF receive type error - expected packet errors */
0203 #define RHF_RTE_EXPECTED_FLOW_SEQ_ERR   0x2
0204 #define RHF_RTE_EXPECTED_FLOW_GEN_ERR   0x4
0205 
0206 /* RHF receive type error - eager packet errors */
0207 #define RHF_RTE_EAGER_NO_ERR        0x0
0208 
0209 /* RHF receive type error - IB packet errors */
0210 #define RHF_RTE_IB_NO_ERR       0x0
0211 
0212 /* RHF receive type error - error packet errors */
0213 #define RHF_RTE_ERROR_NO_ERR        0x0
0214 #define RHF_RTE_ERROR_OP_CODE_ERR   0x1
0215 #define RHF_RTE_ERROR_KHDR_MIN_LEN_ERR  0x2
0216 #define RHF_RTE_ERROR_KHDR_HCRC_ERR 0x3
0217 #define RHF_RTE_ERROR_KHDR_KVER_ERR 0x4
0218 #define RHF_RTE_ERROR_CONTEXT_ERR   0x5
0219 #define RHF_RTE_ERROR_KHDR_TID_ERR  0x6
0220 
0221 /* RHF receive type error - bypass packet errors */
0222 #define RHF_RTE_BYPASS_NO_ERR       0x0
0223 
0224 /* MAX RcvSEQ */
0225 #define RHF_MAX_SEQ 13
0226 
0227 /* IB - LRH header constants */
0228 #define HFI1_LRH_GRH 0x0003      /* 1. word of IB LRH - next header: GRH */
0229 #define HFI1_LRH_BTH 0x0002      /* 1. word of IB LRH - next header: BTH */
0230 
0231 /* misc. */
0232 #define SC15_PACKET 0xF
0233 #define SIZE_OF_CRC 1
0234 #define SIZE_OF_LT 1
0235 #define MAX_16B_PADDING 12 /* CRC = 4, LT = 1, Pad = 0 to 7 bytes */
0236 
0237 #define LIM_MGMT_P_KEY       0x7FFF
0238 #define FULL_MGMT_P_KEY      0xFFFF
0239 
0240 #define DEFAULT_P_KEY LIM_MGMT_P_KEY
0241 
0242 #define HFI1_PSM_IOC_BASE_SEQ 0x0
0243 
0244 /* Number of BTH.PSN bits used for sequence number in expected rcvs */
0245 #define HFI1_KDETH_BTH_SEQ_SHIFT 11
0246 #define HFI1_KDETH_BTH_SEQ_MASK (BIT(HFI1_KDETH_BTH_SEQ_SHIFT) - 1)
0247 
0248 static inline __u64 rhf_to_cpu(const __le32 *rbuf)
0249 {
0250     return __le64_to_cpu(*((__le64 *)rbuf));
0251 }
0252 
0253 static inline u64 rhf_err_flags(u64 rhf)
0254 {
0255     return rhf & RHF_ERROR_SMASK;
0256 }
0257 
0258 static inline u32 rhf_rcv_type(u64 rhf)
0259 {
0260     return (rhf >> RHF_RCV_TYPE_SHIFT) & RHF_RCV_TYPE_MASK;
0261 }
0262 
0263 static inline u32 rhf_rcv_type_err(u64 rhf)
0264 {
0265     return (rhf >> RHF_RCV_TYPE_ERR_SHIFT) & RHF_RCV_TYPE_ERR_MASK;
0266 }
0267 
0268 /* return size is in bytes, not DWORDs */
0269 static inline u32 rhf_pkt_len(u64 rhf)
0270 {
0271     return ((rhf & RHF_PKT_LEN_SMASK) >> RHF_PKT_LEN_SHIFT) << 2;
0272 }
0273 
0274 static inline u32 rhf_egr_index(u64 rhf)
0275 {
0276     return (rhf >> RHF_EGR_INDEX_SHIFT) & RHF_EGR_INDEX_MASK;
0277 }
0278 
0279 static inline u32 rhf_rcv_seq(u64 rhf)
0280 {
0281     return (rhf >> RHF_RCV_SEQ_SHIFT) & RHF_RCV_SEQ_MASK;
0282 }
0283 
0284 /* returned offset is in DWORDS */
0285 static inline u32 rhf_hdrq_offset(u64 rhf)
0286 {
0287     return (rhf >> RHF_HDRQ_OFFSET_SHIFT) & RHF_HDRQ_OFFSET_MASK;
0288 }
0289 
0290 static inline u64 rhf_use_egr_bfr(u64 rhf)
0291 {
0292     return rhf & RHF_USE_EGR_BFR_SMASK;
0293 }
0294 
0295 static inline u64 rhf_dc_info(u64 rhf)
0296 {
0297     return rhf & RHF_DC_INFO_SMASK;
0298 }
0299 
0300 static inline u32 rhf_egr_buf_offset(u64 rhf)
0301 {
0302     return (rhf >> RHF_EGR_OFFSET_SHIFT) & RHF_EGR_OFFSET_MASK;
0303 }
0304 #endif /* _COMMON_H */