Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /*
0003  * Copyright(c) 2016 - 2018 Intel Corporation.
0004  */
0005 
0006 #ifndef IB_HDRS_H
0007 #define IB_HDRS_H
0008 
0009 #include <linux/types.h>
0010 #include <asm/unaligned.h>
0011 #include <rdma/ib_verbs.h>
0012 
0013 #define IB_SEQ_NAK  (3 << 29)
0014 
0015 /* AETH NAK opcode values */
0016 #define IB_RNR_NAK                      0x20
0017 #define IB_NAK_PSN_ERROR                0x60
0018 #define IB_NAK_INVALID_REQUEST          0x61
0019 #define IB_NAK_REMOTE_ACCESS_ERROR      0x62
0020 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
0021 #define IB_NAK_INVALID_RD_REQUEST       0x64
0022 
0023 #define IB_BTH_REQ_ACK      BIT(31)
0024 #define IB_BTH_SOLICITED    BIT(23)
0025 #define IB_BTH_MIG_REQ      BIT(22)
0026 
0027 #define IB_GRH_VERSION      6
0028 #define IB_GRH_VERSION_MASK 0xF
0029 #define IB_GRH_VERSION_SHIFT    28
0030 #define IB_GRH_TCLASS_MASK  0xFF
0031 #define IB_GRH_TCLASS_SHIFT 20
0032 #define IB_GRH_FLOW_MASK    0xFFFFF
0033 #define IB_GRH_FLOW_SHIFT   0
0034 #define IB_GRH_NEXT_HDR     0x1B
0035 #define IB_FECN_SHIFT 31
0036 #define IB_FECN_MASK 1
0037 #define IB_FECN_SMASK BIT(IB_FECN_SHIFT)
0038 #define IB_BECN_SHIFT 30
0039 #define IB_BECN_MASK 1
0040 #define IB_BECN_SMASK BIT(IB_BECN_SHIFT)
0041 
0042 #define IB_AETH_CREDIT_SHIFT    24
0043 #define IB_AETH_CREDIT_MASK 0x1F
0044 #define IB_AETH_CREDIT_INVAL    0x1F
0045 #define IB_AETH_NAK_SHIFT   29
0046 #define IB_MSN_MASK     0xFFFFFF
0047 
0048 struct ib_reth {
0049     __be64 vaddr;        /* potentially unaligned */
0050     __be32 rkey;
0051     __be32 length;
0052 } __packed;
0053 
0054 struct ib_atomic_eth {
0055     __be64 vaddr;        /* potentially unaligned */
0056     __be32 rkey;
0057     __be64 swap_data;    /* potentially unaligned */
0058     __be64 compare_data; /* potentially unaligned */
0059 } __packed;
0060 
0061 #include <rdma/tid_rdma_defs.h>
0062 
0063 union ib_ehdrs {
0064     struct {
0065         __be32 deth[2];
0066         __be32 imm_data;
0067     } ud;
0068     struct {
0069         struct ib_reth reth;
0070         __be32 imm_data;
0071     } rc;
0072     struct {
0073         __be32 aeth;
0074         __be64 atomic_ack_eth; /* potentially unaligned */
0075     } __packed at;
0076     __be32 imm_data;
0077     __be32 aeth;
0078     __be32 ieth;
0079     struct ib_atomic_eth atomic_eth;
0080     /* TID RDMA headers */
0081     union {
0082         struct tid_rdma_read_req r_req;
0083         struct tid_rdma_read_resp r_rsp;
0084         struct tid_rdma_write_req w_req;
0085         struct tid_rdma_write_resp w_rsp;
0086         struct tid_rdma_write_data w_data;
0087         struct tid_rdma_resync resync;
0088         struct tid_rdma_ack ack;
0089     } tid_rdma;
0090 }  __packed;
0091 
0092 struct ib_other_headers {
0093     __be32 bth[3];
0094     union ib_ehdrs u;
0095 } __packed;
0096 
0097 struct ib_header {
0098     __be16 lrh[4];
0099     union {
0100         struct {
0101             struct ib_grh grh;
0102             struct ib_other_headers oth;
0103         } l;
0104         struct ib_other_headers oth;
0105     } u;
0106 } __packed;
0107 
0108 /* accessors for unaligned __be64 items */
0109 
0110 static inline u64 ib_u64_get(__be64 *p)
0111 {
0112     return get_unaligned_be64(p);
0113 }
0114 
0115 static inline void ib_u64_put(u64 val, __be64 *p)
0116 {
0117     put_unaligned_be64(val, p);
0118 }
0119 
0120 static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
0121 {
0122     return ib_u64_get(&reth->vaddr);
0123 }
0124 
0125 static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
0126 {
0127     ib_u64_put(val, &reth->vaddr);
0128 }
0129 
0130 static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
0131 {
0132     return ib_u64_get(&ateth->vaddr);
0133 }
0134 
0135 static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
0136 {
0137     ib_u64_put(val, &ateth->vaddr);
0138 }
0139 
0140 static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
0141 {
0142     return ib_u64_get(&ateth->swap_data);
0143 }
0144 
0145 static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
0146 {
0147     ib_u64_put(val, &ateth->swap_data);
0148 }
0149 
0150 static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
0151 {
0152     return ib_u64_get(&ateth->compare_data);
0153 }
0154 
0155 static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
0156 {
0157     ib_u64_put(val, &ateth->compare_data);
0158 }
0159 
0160 /*
0161  * 9B/IB Packet Format
0162  */
0163 #define IB_LNH_MASK     3
0164 #define IB_SC_MASK      0xf
0165 #define IB_SC_SHIFT     12
0166 #define IB_SC5_MASK     0x10
0167 #define IB_SL_MASK      0xf
0168 #define IB_SL_SHIFT     4
0169 #define IB_SL_SHIFT     4
0170 #define IB_LVER_MASK    0xf
0171 #define IB_LVER_SHIFT   8
0172 
0173 static inline u8 ib_get_lnh(struct ib_header *hdr)
0174 {
0175     return (be16_to_cpu(hdr->lrh[0]) & IB_LNH_MASK);
0176 }
0177 
0178 static inline u8 ib_get_sc(struct ib_header *hdr)
0179 {
0180     return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
0181 }
0182 
0183 static inline bool ib_is_sc5(u16 sc5)
0184 {
0185     return !!(sc5 & IB_SC5_MASK);
0186 }
0187 
0188 static inline u8 ib_get_sl(struct ib_header *hdr)
0189 {
0190     return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
0191 }
0192 
0193 static inline u16 ib_get_dlid(struct ib_header *hdr)
0194 {
0195     return (be16_to_cpu(hdr->lrh[1]));
0196 }
0197 
0198 static inline u16 ib_get_slid(struct ib_header *hdr)
0199 {
0200     return (be16_to_cpu(hdr->lrh[3]));
0201 }
0202 
0203 static inline u8 ib_get_lver(struct ib_header *hdr)
0204 {
0205     return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
0206            IB_LVER_MASK);
0207 }
0208 
0209 static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
0210 {
0211     return be32_to_cpu(ohdr->u.ud.deth[0]);
0212 }
0213 
0214 static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
0215 {
0216     return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
0217 }
0218 
0219 /*
0220  * BTH
0221  */
0222 #define IB_BTH_OPCODE_MASK  0xff
0223 #define IB_BTH_OPCODE_SHIFT 24
0224 #define IB_BTH_PAD_MASK 3
0225 #define IB_BTH_PKEY_MASK    0xffff
0226 #define IB_BTH_PAD_SHIFT    20
0227 #define IB_BTH_A_MASK       1
0228 #define IB_BTH_A_SHIFT      31
0229 #define IB_BTH_M_MASK       1
0230 #define IB_BTH_M_SHIFT      22
0231 #define IB_BTH_SE_MASK      1
0232 #define IB_BTH_SE_SHIFT 23
0233 #define IB_BTH_TVER_MASK    0xf
0234 #define IB_BTH_TVER_SHIFT   16
0235 #define IB_BTH_OPCODE_CNP   0x81
0236 
0237 static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
0238 {
0239     return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
0240            IB_BTH_PAD_MASK);
0241 }
0242 
0243 static inline u16 ib_bth_get_pkey(struct ib_other_headers *ohdr)
0244 {
0245     return (be32_to_cpu(ohdr->bth[0]) & IB_BTH_PKEY_MASK);
0246 }
0247 
0248 static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
0249 {
0250     return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_OPCODE_SHIFT) &
0251            IB_BTH_OPCODE_MASK);
0252 }
0253 
0254 static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
0255 {
0256     return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
0257            IB_BTH_A_MASK);
0258 }
0259 
0260 static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
0261 {
0262     return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
0263             IB_BTH_M_MASK);
0264 }
0265 
0266 static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
0267 {
0268     return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
0269             IB_BTH_SE_MASK);
0270 }
0271 
0272 static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
0273 {
0274     return (u32)(be32_to_cpu(ohdr->bth[2]));
0275 }
0276 
0277 static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
0278 {
0279     return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
0280 }
0281 
0282 static inline bool ib_bth_get_becn(struct ib_other_headers *ohdr)
0283 {
0284     return (ohdr->bth[1]) & cpu_to_be32(IB_BECN_SMASK);
0285 }
0286 
0287 static inline bool ib_bth_get_fecn(struct ib_other_headers *ohdr)
0288 {
0289     return (ohdr->bth[1]) & cpu_to_be32(IB_FECN_SMASK);
0290 }
0291 
0292 static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
0293 {
0294     return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT)  &
0295             IB_BTH_TVER_MASK);
0296 }
0297 
0298 static inline bool ib_bth_is_solicited(struct ib_other_headers *ohdr)
0299 {
0300     return ohdr->bth[0] & cpu_to_be32(IB_BTH_SOLICITED);
0301 }
0302 
0303 static inline bool ib_bth_is_migration(struct ib_other_headers *ohdr)
0304 {
0305     return ohdr->bth[0] & cpu_to_be32(IB_BTH_MIG_REQ);
0306 }
0307 #endif                          /* IB_HDRS_H */