Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /*
0003  * Copyright(c) 2017 Intel Corporation.
0004  */
0005 
0006 #ifndef OPA_ADDR_H
0007 #define OPA_ADDR_H
0008 
0009 #include <rdma/opa_smi.h>
0010 
0011 #define OPA_SPECIAL_OUI     (0x00066AULL)
0012 #define OPA_MAKE_ID(x)          (cpu_to_be64(OPA_SPECIAL_OUI << 40 | (x)))
0013 #define OPA_TO_IB_UCAST_LID(x) (((x) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) \
0014                 ? 0 : x)
0015 #define OPA_GID_INDEX       0x1
0016 /**
0017  * 0xF8 - 4 bits of multicast range and 1 bit for collective range
0018  * Example: For 24 bit LID space,
0019  * Multicast range: 0xF00000 to 0xF7FFFF
0020  * Collective range: 0xF80000 to 0xFFFFFE
0021  */
0022 #define OPA_MCAST_NR 0x4 /* Number of top bits set */
0023 #define OPA_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */
0024 
0025 /**
0026  * ib_is_opa_gid: Returns true if the top 24 bits of the gid
0027  * contains the OPA_STL_OUI identifier. This identifies that
0028  * the provided gid is a special purpose GID meant to carry
0029  * extended LID information.
0030  *
0031  * @gid: The Global identifier
0032  */
0033 static inline bool ib_is_opa_gid(const union ib_gid *gid)
0034 {
0035     return ((be64_to_cpu(gid->global.interface_id) >> 40) ==
0036         OPA_SPECIAL_OUI);
0037 }
0038 
0039 /**
0040  * opa_get_lid_from_gid: Returns the last 32 bits of the gid.
0041  * OPA devices use one of the gids in the gid table to also
0042  * store the lid.
0043  *
0044  * @gid: The Global identifier
0045  */
0046 static inline u32 opa_get_lid_from_gid(const union ib_gid *gid)
0047 {
0048     return be64_to_cpu(gid->global.interface_id) & 0xFFFFFFFF;
0049 }
0050 
0051 /**
0052  * opa_is_extended_lid: Returns true if dlid or slid are
0053  * extended.
0054  *
0055  * @dlid: The DLID
0056  * @slid: The SLID
0057  */
0058 static inline bool opa_is_extended_lid(__be32 dlid, __be32 slid)
0059 {
0060     if ((be32_to_cpu(dlid) >=
0061          be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
0062         (be32_to_cpu(slid) >=
0063          be16_to_cpu(IB_MULTICAST_LID_BASE)))
0064         return true;
0065 
0066     return false;
0067 }
0068 
0069 /* Get multicast lid base */
0070 static inline u32 opa_get_mcast_base(u32 nr_top_bits)
0071 {
0072     return (be32_to_cpu(OPA_LID_PERMISSIVE) << (32 - nr_top_bits));
0073 }
0074 
0075 /* Check for a valid unicast LID for non-SM traffic types */
0076 static inline bool rdma_is_valid_unicast_lid(struct rdma_ah_attr *attr)
0077 {
0078     if (attr->type == RDMA_AH_ATTR_TYPE_IB) {
0079         if (!rdma_ah_get_dlid(attr) ||
0080             rdma_ah_get_dlid(attr) >=
0081             be16_to_cpu(IB_MULTICAST_LID_BASE))
0082             return false;
0083     } else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) {
0084         if (!rdma_ah_get_dlid(attr) ||
0085             rdma_ah_get_dlid(attr) >=
0086             opa_get_mcast_base(OPA_MCAST_NR))
0087             return false;
0088     }
0089     return true;
0090 }
0091 #endif /* OPA_ADDR_H */