18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright(c) 2017 Intel Corporation. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef OPA_ADDR_H 78c2ecf20Sopenharmony_ci#define OPA_ADDR_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <rdma/opa_smi.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define OPA_SPECIAL_OUI (0x00066AULL) 128c2ecf20Sopenharmony_ci#define OPA_MAKE_ID(x) (cpu_to_be64(OPA_SPECIAL_OUI << 40 | (x))) 138c2ecf20Sopenharmony_ci#define OPA_TO_IB_UCAST_LID(x) (((x) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) \ 148c2ecf20Sopenharmony_ci ? 0 : x) 158c2ecf20Sopenharmony_ci#define OPA_GID_INDEX 0x1 168c2ecf20Sopenharmony_ci/** 178c2ecf20Sopenharmony_ci * 0xF8 - 4 bits of multicast range and 1 bit for collective range 188c2ecf20Sopenharmony_ci * Example: For 24 bit LID space, 198c2ecf20Sopenharmony_ci * Multicast range: 0xF00000 to 0xF7FFFF 208c2ecf20Sopenharmony_ci * Collective range: 0xF80000 to 0xFFFFFE 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#define OPA_MCAST_NR 0x4 /* Number of top bits set */ 238c2ecf20Sopenharmony_ci#define OPA_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/** 268c2ecf20Sopenharmony_ci * ib_is_opa_gid: Returns true if the top 24 bits of the gid 278c2ecf20Sopenharmony_ci * contains the OPA_STL_OUI identifier. This identifies that 288c2ecf20Sopenharmony_ci * the provided gid is a special purpose GID meant to carry 298c2ecf20Sopenharmony_ci * extended LID information. 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * @gid: The Global identifier 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_cistatic inline bool ib_is_opa_gid(const union ib_gid *gid) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci return ((be64_to_cpu(gid->global.interface_id) >> 40) == 368c2ecf20Sopenharmony_ci OPA_SPECIAL_OUI); 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/** 408c2ecf20Sopenharmony_ci * opa_get_lid_from_gid: Returns the last 32 bits of the gid. 418c2ecf20Sopenharmony_ci * OPA devices use one of the gids in the gid table to also 428c2ecf20Sopenharmony_ci * store the lid. 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * @gid: The Global identifier 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_cistatic inline u32 opa_get_lid_from_gid(const union ib_gid *gid) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return be64_to_cpu(gid->global.interface_id) & 0xFFFFFFFF; 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/** 528c2ecf20Sopenharmony_ci * opa_is_extended_lid: Returns true if dlid or slid are 538c2ecf20Sopenharmony_ci * extended. 548c2ecf20Sopenharmony_ci * 558c2ecf20Sopenharmony_ci * @dlid: The DLID 568c2ecf20Sopenharmony_ci * @slid: The SLID 578c2ecf20Sopenharmony_ci */ 588c2ecf20Sopenharmony_cistatic inline bool opa_is_extended_lid(__be32 dlid, __be32 slid) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci if ((be32_to_cpu(dlid) >= 618c2ecf20Sopenharmony_ci be16_to_cpu(IB_MULTICAST_LID_BASE)) || 628c2ecf20Sopenharmony_ci (be32_to_cpu(slid) >= 638c2ecf20Sopenharmony_ci be16_to_cpu(IB_MULTICAST_LID_BASE))) 648c2ecf20Sopenharmony_ci return true; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci return false; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* Get multicast lid base */ 708c2ecf20Sopenharmony_cistatic inline u32 opa_get_mcast_base(u32 nr_top_bits) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci return (be32_to_cpu(OPA_LID_PERMISSIVE) << (32 - nr_top_bits)); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Check for a valid unicast LID for non-SM traffic types */ 768c2ecf20Sopenharmony_cistatic inline bool rdma_is_valid_unicast_lid(struct rdma_ah_attr *attr) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci if (attr->type == RDMA_AH_ATTR_TYPE_IB) { 798c2ecf20Sopenharmony_ci if (!rdma_ah_get_dlid(attr) || 808c2ecf20Sopenharmony_ci rdma_ah_get_dlid(attr) >= 818c2ecf20Sopenharmony_ci be16_to_cpu(IB_MULTICAST_LID_BASE)) 828c2ecf20Sopenharmony_ci return false; 838c2ecf20Sopenharmony_ci } else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) { 848c2ecf20Sopenharmony_ci if (!rdma_ah_get_dlid(attr) || 858c2ecf20Sopenharmony_ci rdma_ah_get_dlid(attr) >= 868c2ecf20Sopenharmony_ci opa_get_mcast_base(OPA_MCAST_NR)) 878c2ecf20Sopenharmony_ci return false; 888c2ecf20Sopenharmony_ci } 898c2ecf20Sopenharmony_ci return true; 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci#endif /* OPA_ADDR_H */ 92