blob: c6bfa2640bacc2a7c61303ce556adf5b9629f5ec [file] [log] [blame]
Leon Romanovsky6bf9d8f2020-07-19 10:25:21 +03001/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
Doug Ledford87f0faa2017-05-01 16:35:59 -04002/*
3 * Copyright(c) 2017 Intel Corporation.
Doug Ledford87f0faa2017-05-01 16:35:59 -04004 */
5
6#ifndef OPA_ADDR_H
7#define OPA_ADDR_H
8
Don Hiatt13c19222017-08-04 13:53:51 -07009#include <rdma/opa_smi.h>
10
Doug Ledford87f0faa2017-05-01 16:35:59 -040011#define OPA_SPECIAL_OUI (0x00066AULL)
12#define OPA_MAKE_ID(x) (cpu_to_be64(OPA_SPECIAL_OUI << 40 | (x)))
Dasaratharaman Chandramouli582faf32017-06-08 13:37:47 -040013#define OPA_TO_IB_UCAST_LID(x) (((x) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) \
14 ? 0 : x)
Don Hiatt88733e32017-08-04 13:54:23 -070015#define OPA_GID_INDEX 0x1
Doug Ledford87f0faa2017-05-01 16:35:59 -040016/**
Don Hiatt13c19222017-08-04 13:53:51 -070017 * 0xF8 - 4 bits of multicast range and 1 bit for collective range
18 * Example: For 24 bit LID space,
19 * Multicast range: 0xF00000 to 0xF7FFFF
20 * Collective range: 0xF80000 to 0xFFFFFE
21 */
22#define OPA_MCAST_NR 0x4 /* Number of top bits set */
23#define OPA_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */
24
25/**
Doug Ledford87f0faa2017-05-01 16:35:59 -040026 * ib_is_opa_gid: Returns true if the top 24 bits of the gid
27 * contains the OPA_STL_OUI identifier. This identifies that
28 * the provided gid is a special purpose GID meant to carry
29 * extended LID information.
30 *
31 * @gid: The Global identifier
32 */
Don Hiattd98bb7f2017-08-04 13:54:16 -070033static inline bool ib_is_opa_gid(const union ib_gid *gid)
Doug Ledford87f0faa2017-05-01 16:35:59 -040034{
35 return ((be64_to_cpu(gid->global.interface_id) >> 40) ==
36 OPA_SPECIAL_OUI);
37}
38
39/**
40 * opa_get_lid_from_gid: Returns the last 32 bits of the gid.
41 * OPA devices use one of the gids in the gid table to also
42 * store the lid.
43 *
44 * @gid: The Global identifier
45 */
Don Hiattd98bb7f2017-08-04 13:54:16 -070046static inline u32 opa_get_lid_from_gid(const union ib_gid *gid)
Doug Ledford87f0faa2017-05-01 16:35:59 -040047{
48 return be64_to_cpu(gid->global.interface_id) & 0xFFFFFFFF;
49}
Hiatt, Done92aa002017-06-08 13:38:02 -040050
51/**
52 * opa_is_extended_lid: Returns true if dlid or slid are
53 * extended.
54 *
55 * @dlid: The DLID
56 * @slid: The SLID
57 */
Don Hiatta9173742017-10-02 11:04:33 -070058static inline bool opa_is_extended_lid(__be32 dlid, __be32 slid)
Hiatt, Done92aa002017-06-08 13:38:02 -040059{
60 if ((be32_to_cpu(dlid) >=
61 be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
62 (be32_to_cpu(slid) >=
63 be16_to_cpu(IB_MULTICAST_LID_BASE)))
64 return true;
Don Hiatta9173742017-10-02 11:04:33 -070065
66 return false;
Hiatt, Done92aa002017-06-08 13:38:02 -040067}
Don Hiatt13c19222017-08-04 13:53:51 -070068
69/* Get multicast lid base */
70static inline u32 opa_get_mcast_base(u32 nr_top_bits)
71{
72 return (be32_to_cpu(OPA_LID_PERMISSIVE) << (32 - nr_top_bits));
73}
74
Venkata Sandeep Dhanalakotaaf808ec2017-12-18 19:26:58 -080075/* Check for a valid unicast LID for non-SM traffic types */
76static inline bool rdma_is_valid_unicast_lid(struct rdma_ah_attr *attr)
77{
78 if (attr->type == RDMA_AH_ATTR_TYPE_IB) {
79 if (!rdma_ah_get_dlid(attr) ||
80 rdma_ah_get_dlid(attr) >=
Bart Van Assche4eefd622018-07-02 10:06:51 -070081 be16_to_cpu(IB_MULTICAST_LID_BASE))
Venkata Sandeep Dhanalakotaaf808ec2017-12-18 19:26:58 -080082 return false;
83 } else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) {
84 if (!rdma_ah_get_dlid(attr) ||
85 rdma_ah_get_dlid(attr) >=
86 opa_get_mcast_base(OPA_MCAST_NR))
87 return false;
88 }
89 return true;
90}
Doug Ledford87f0faa2017-05-01 16:35:59 -040091#endif /* OPA_ADDR_H */