162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2004 Topspin Communications. All rights reserved. 462306a36Sopenharmony_ci * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 562306a36Sopenharmony_ci * Copyright (c) 2006 Intel Corporation. All rights reserved. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef IB_SA_H 962306a36Sopenharmony_ci#define IB_SA_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/completion.h> 1262306a36Sopenharmony_ci#include <linux/compiler.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/atomic.h> 1562306a36Sopenharmony_ci#include <linux/netdevice.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <rdma/ib_verbs.h> 1862306a36Sopenharmony_ci#include <rdma/ib_mad.h> 1962306a36Sopenharmony_ci#include <rdma/ib_addr.h> 2062306a36Sopenharmony_ci#include <rdma/opa_addr.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cienum { 2362306a36Sopenharmony_ci IB_SA_CLASS_VERSION = 2, /* IB spec version 1.1/1.2 */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci IB_SA_METHOD_GET_TABLE = 0x12, 2662306a36Sopenharmony_ci IB_SA_METHOD_GET_TABLE_RESP = 0x92, 2762306a36Sopenharmony_ci IB_SA_METHOD_DELETE = 0x15, 2862306a36Sopenharmony_ci IB_SA_METHOD_DELETE_RESP = 0x95, 2962306a36Sopenharmony_ci IB_SA_METHOD_GET_MULTI = 0x14, 3062306a36Sopenharmony_ci IB_SA_METHOD_GET_MULTI_RESP = 0x94, 3162306a36Sopenharmony_ci IB_SA_METHOD_GET_TRACE_TBL = 0x13 3262306a36Sopenharmony_ci}; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define OPA_SA_CLASS_VERSION 0x80 3562306a36Sopenharmony_cienum { 3662306a36Sopenharmony_ci IB_SA_ATTR_CLASS_PORTINFO = 0x01, 3762306a36Sopenharmony_ci IB_SA_ATTR_NOTICE = 0x02, 3862306a36Sopenharmony_ci IB_SA_ATTR_INFORM_INFO = 0x03, 3962306a36Sopenharmony_ci IB_SA_ATTR_NODE_REC = 0x11, 4062306a36Sopenharmony_ci IB_SA_ATTR_PORT_INFO_REC = 0x12, 4162306a36Sopenharmony_ci IB_SA_ATTR_SL2VL_REC = 0x13, 4262306a36Sopenharmony_ci IB_SA_ATTR_SWITCH_REC = 0x14, 4362306a36Sopenharmony_ci IB_SA_ATTR_LINEAR_FDB_REC = 0x15, 4462306a36Sopenharmony_ci IB_SA_ATTR_RANDOM_FDB_REC = 0x16, 4562306a36Sopenharmony_ci IB_SA_ATTR_MCAST_FDB_REC = 0x17, 4662306a36Sopenharmony_ci IB_SA_ATTR_SM_INFO_REC = 0x18, 4762306a36Sopenharmony_ci IB_SA_ATTR_LINK_REC = 0x20, 4862306a36Sopenharmony_ci IB_SA_ATTR_GUID_INFO_REC = 0x30, 4962306a36Sopenharmony_ci IB_SA_ATTR_SERVICE_REC = 0x31, 5062306a36Sopenharmony_ci IB_SA_ATTR_PARTITION_REC = 0x33, 5162306a36Sopenharmony_ci IB_SA_ATTR_PATH_REC = 0x35, 5262306a36Sopenharmony_ci IB_SA_ATTR_VL_ARB_REC = 0x36, 5362306a36Sopenharmony_ci IB_SA_ATTR_MC_MEMBER_REC = 0x38, 5462306a36Sopenharmony_ci IB_SA_ATTR_TRACE_REC = 0x39, 5562306a36Sopenharmony_ci IB_SA_ATTR_MULTI_PATH_REC = 0x3a, 5662306a36Sopenharmony_ci IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b, 5762306a36Sopenharmony_ci IB_SA_ATTR_INFORM_INFO_REC = 0xf3 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cienum ib_sa_selector { 6162306a36Sopenharmony_ci IB_SA_GT = 0, 6262306a36Sopenharmony_ci IB_SA_LT = 1, 6362306a36Sopenharmony_ci IB_SA_EQ = 2, 6462306a36Sopenharmony_ci /* 6562306a36Sopenharmony_ci * The meaning of "best" depends on the attribute: for 6662306a36Sopenharmony_ci * example, for MTU best will return the largest available 6762306a36Sopenharmony_ci * MTU, while for packet life time, best will return the 6862306a36Sopenharmony_ci * smallest available life time. 6962306a36Sopenharmony_ci */ 7062306a36Sopenharmony_ci IB_SA_BEST = 3 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* 7462306a36Sopenharmony_ci * There are 4 types of join states: 7562306a36Sopenharmony_ci * FullMember, NonMember, SendOnlyNonMember, SendOnlyFullMember. 7662306a36Sopenharmony_ci * The order corresponds to JoinState bits in MCMemberRecord. 7762306a36Sopenharmony_ci */ 7862306a36Sopenharmony_cienum ib_sa_mc_join_states { 7962306a36Sopenharmony_ci FULLMEMBER_JOIN, 8062306a36Sopenharmony_ci NONMEMBER_JOIN, 8162306a36Sopenharmony_ci SENDONLY_NONMEBER_JOIN, 8262306a36Sopenharmony_ci SENDONLY_FULLMEMBER_JOIN, 8362306a36Sopenharmony_ci NUM_JOIN_MEMBERSHIP_TYPES, 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT BIT(12) 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* 8962306a36Sopenharmony_ci * Structures for SA records are named "struct ib_sa_xxx_rec." No 9062306a36Sopenharmony_ci * attempt is made to pack structures to match the physical layout of 9162306a36Sopenharmony_ci * SA records in SA MADs; all packing and unpacking is handled by the 9262306a36Sopenharmony_ci * SA query code. 9362306a36Sopenharmony_ci * 9462306a36Sopenharmony_ci * For a record with structure ib_sa_xxx_rec, the naming convention 9562306a36Sopenharmony_ci * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we 9662306a36Sopenharmony_ci * never use different abbreviations or otherwise change the spelling 9762306a36Sopenharmony_ci * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY). 9862306a36Sopenharmony_ci * 9962306a36Sopenharmony_ci * Reserved rows are indicated with comments to help maintainability. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci#define IB_SA_PATH_REC_SERVICE_ID (IB_SA_COMP_MASK( 0) |\ 10362306a36Sopenharmony_ci IB_SA_COMP_MASK( 1)) 10462306a36Sopenharmony_ci#define IB_SA_PATH_REC_DGID IB_SA_COMP_MASK( 2) 10562306a36Sopenharmony_ci#define IB_SA_PATH_REC_SGID IB_SA_COMP_MASK( 3) 10662306a36Sopenharmony_ci#define IB_SA_PATH_REC_DLID IB_SA_COMP_MASK( 4) 10762306a36Sopenharmony_ci#define IB_SA_PATH_REC_SLID IB_SA_COMP_MASK( 5) 10862306a36Sopenharmony_ci#define IB_SA_PATH_REC_RAW_TRAFFIC IB_SA_COMP_MASK( 6) 10962306a36Sopenharmony_ci/* reserved: 7 */ 11062306a36Sopenharmony_ci#define IB_SA_PATH_REC_FLOW_LABEL IB_SA_COMP_MASK( 8) 11162306a36Sopenharmony_ci#define IB_SA_PATH_REC_HOP_LIMIT IB_SA_COMP_MASK( 9) 11262306a36Sopenharmony_ci#define IB_SA_PATH_REC_TRAFFIC_CLASS IB_SA_COMP_MASK(10) 11362306a36Sopenharmony_ci#define IB_SA_PATH_REC_REVERSIBLE IB_SA_COMP_MASK(11) 11462306a36Sopenharmony_ci#define IB_SA_PATH_REC_NUMB_PATH IB_SA_COMP_MASK(12) 11562306a36Sopenharmony_ci#define IB_SA_PATH_REC_PKEY IB_SA_COMP_MASK(13) 11662306a36Sopenharmony_ci#define IB_SA_PATH_REC_QOS_CLASS IB_SA_COMP_MASK(14) 11762306a36Sopenharmony_ci#define IB_SA_PATH_REC_SL IB_SA_COMP_MASK(15) 11862306a36Sopenharmony_ci#define IB_SA_PATH_REC_MTU_SELECTOR IB_SA_COMP_MASK(16) 11962306a36Sopenharmony_ci#define IB_SA_PATH_REC_MTU IB_SA_COMP_MASK(17) 12062306a36Sopenharmony_ci#define IB_SA_PATH_REC_RATE_SELECTOR IB_SA_COMP_MASK(18) 12162306a36Sopenharmony_ci#define IB_SA_PATH_REC_RATE IB_SA_COMP_MASK(19) 12262306a36Sopenharmony_ci#define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(20) 12362306a36Sopenharmony_ci#define IB_SA_PATH_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(21) 12462306a36Sopenharmony_ci#define IB_SA_PATH_REC_PREFERENCE IB_SA_COMP_MASK(22) 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cienum sa_path_rec_type { 12762306a36Sopenharmony_ci SA_PATH_REC_TYPE_IB, 12862306a36Sopenharmony_ci SA_PATH_REC_TYPE_ROCE_V1, 12962306a36Sopenharmony_ci SA_PATH_REC_TYPE_ROCE_V2, 13062306a36Sopenharmony_ci SA_PATH_REC_TYPE_OPA 13162306a36Sopenharmony_ci}; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_cistruct sa_path_rec_ib { 13462306a36Sopenharmony_ci __be16 dlid; 13562306a36Sopenharmony_ci __be16 slid; 13662306a36Sopenharmony_ci u8 raw_traffic; 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci/** 14062306a36Sopenharmony_ci * struct sa_path_rec_roce - RoCE specific portion of the path record entry 14162306a36Sopenharmony_ci * @route_resolved: When set, it indicates that this route is already 14262306a36Sopenharmony_ci * resolved for this path record entry. 14362306a36Sopenharmony_ci * @dmac: Destination mac address for the given DGID entry 14462306a36Sopenharmony_ci * of the path record entry. 14562306a36Sopenharmony_ci */ 14662306a36Sopenharmony_cistruct sa_path_rec_roce { 14762306a36Sopenharmony_ci bool route_resolved; 14862306a36Sopenharmony_ci u8 dmac[ETH_ALEN]; 14962306a36Sopenharmony_ci}; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistruct sa_path_rec_opa { 15262306a36Sopenharmony_ci __be32 dlid; 15362306a36Sopenharmony_ci __be32 slid; 15462306a36Sopenharmony_ci u8 raw_traffic; 15562306a36Sopenharmony_ci u8 l2_8B; 15662306a36Sopenharmony_ci u8 l2_10B; 15762306a36Sopenharmony_ci u8 l2_9B; 15862306a36Sopenharmony_ci u8 l2_16B; 15962306a36Sopenharmony_ci u8 qos_type; 16062306a36Sopenharmony_ci u8 qos_priority; 16162306a36Sopenharmony_ci}; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistruct sa_path_rec { 16462306a36Sopenharmony_ci union ib_gid dgid; 16562306a36Sopenharmony_ci union ib_gid sgid; 16662306a36Sopenharmony_ci __be64 service_id; 16762306a36Sopenharmony_ci /* reserved */ 16862306a36Sopenharmony_ci __be32 flow_label; 16962306a36Sopenharmony_ci u8 hop_limit; 17062306a36Sopenharmony_ci u8 traffic_class; 17162306a36Sopenharmony_ci u8 reversible; 17262306a36Sopenharmony_ci u8 numb_path; 17362306a36Sopenharmony_ci __be16 pkey; 17462306a36Sopenharmony_ci __be16 qos_class; 17562306a36Sopenharmony_ci u8 sl; 17662306a36Sopenharmony_ci u8 mtu_selector; 17762306a36Sopenharmony_ci u8 mtu; 17862306a36Sopenharmony_ci u8 rate_selector; 17962306a36Sopenharmony_ci u8 rate; 18062306a36Sopenharmony_ci u8 packet_life_time_selector; 18162306a36Sopenharmony_ci u8 packet_life_time; 18262306a36Sopenharmony_ci u8 preference; 18362306a36Sopenharmony_ci union { 18462306a36Sopenharmony_ci struct sa_path_rec_ib ib; 18562306a36Sopenharmony_ci struct sa_path_rec_roce roce; 18662306a36Sopenharmony_ci struct sa_path_rec_opa opa; 18762306a36Sopenharmony_ci }; 18862306a36Sopenharmony_ci enum sa_path_rec_type rec_type; 18962306a36Sopenharmony_ci u32 flags; 19062306a36Sopenharmony_ci}; 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_cistatic inline enum ib_gid_type 19362306a36Sopenharmony_ci sa_conv_pathrec_to_gid_type(struct sa_path_rec *rec) 19462306a36Sopenharmony_ci{ 19562306a36Sopenharmony_ci switch (rec->rec_type) { 19662306a36Sopenharmony_ci case SA_PATH_REC_TYPE_ROCE_V1: 19762306a36Sopenharmony_ci return IB_GID_TYPE_ROCE; 19862306a36Sopenharmony_ci case SA_PATH_REC_TYPE_ROCE_V2: 19962306a36Sopenharmony_ci return IB_GID_TYPE_ROCE_UDP_ENCAP; 20062306a36Sopenharmony_ci default: 20162306a36Sopenharmony_ci return IB_GID_TYPE_IB; 20262306a36Sopenharmony_ci } 20362306a36Sopenharmony_ci} 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_cistatic inline enum sa_path_rec_type 20662306a36Sopenharmony_ci sa_conv_gid_to_pathrec_type(enum ib_gid_type type) 20762306a36Sopenharmony_ci{ 20862306a36Sopenharmony_ci switch (type) { 20962306a36Sopenharmony_ci case IB_GID_TYPE_ROCE: 21062306a36Sopenharmony_ci return SA_PATH_REC_TYPE_ROCE_V1; 21162306a36Sopenharmony_ci case IB_GID_TYPE_ROCE_UDP_ENCAP: 21262306a36Sopenharmony_ci return SA_PATH_REC_TYPE_ROCE_V2; 21362306a36Sopenharmony_ci default: 21462306a36Sopenharmony_ci return SA_PATH_REC_TYPE_IB; 21562306a36Sopenharmony_ci } 21662306a36Sopenharmony_ci} 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_cistatic inline void path_conv_opa_to_ib(struct sa_path_rec *ib, 21962306a36Sopenharmony_ci struct sa_path_rec *opa) 22062306a36Sopenharmony_ci{ 22162306a36Sopenharmony_ci if ((be32_to_cpu(opa->opa.dlid) >= 22262306a36Sopenharmony_ci be16_to_cpu(IB_MULTICAST_LID_BASE)) || 22362306a36Sopenharmony_ci (be32_to_cpu(opa->opa.slid) >= 22462306a36Sopenharmony_ci be16_to_cpu(IB_MULTICAST_LID_BASE))) { 22562306a36Sopenharmony_ci /* Create OPA GID and zero out the LID */ 22662306a36Sopenharmony_ci ib->dgid.global.interface_id 22762306a36Sopenharmony_ci = OPA_MAKE_ID(be32_to_cpu(opa->opa.dlid)); 22862306a36Sopenharmony_ci ib->dgid.global.subnet_prefix 22962306a36Sopenharmony_ci = opa->dgid.global.subnet_prefix; 23062306a36Sopenharmony_ci ib->sgid.global.interface_id 23162306a36Sopenharmony_ci = OPA_MAKE_ID(be32_to_cpu(opa->opa.slid)); 23262306a36Sopenharmony_ci ib->dgid.global.subnet_prefix 23362306a36Sopenharmony_ci = opa->dgid.global.subnet_prefix; 23462306a36Sopenharmony_ci ib->ib.dlid = 0; 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci ib->ib.slid = 0; 23762306a36Sopenharmony_ci } else { 23862306a36Sopenharmony_ci ib->ib.dlid = htons(ntohl(opa->opa.dlid)); 23962306a36Sopenharmony_ci ib->ib.slid = htons(ntohl(opa->opa.slid)); 24062306a36Sopenharmony_ci } 24162306a36Sopenharmony_ci ib->service_id = opa->service_id; 24262306a36Sopenharmony_ci ib->ib.raw_traffic = opa->opa.raw_traffic; 24362306a36Sopenharmony_ci} 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_cistatic inline void path_conv_ib_to_opa(struct sa_path_rec *opa, 24662306a36Sopenharmony_ci struct sa_path_rec *ib) 24762306a36Sopenharmony_ci{ 24862306a36Sopenharmony_ci __be32 slid, dlid; 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci if ((ib_is_opa_gid(&ib->sgid)) || 25162306a36Sopenharmony_ci (ib_is_opa_gid(&ib->dgid))) { 25262306a36Sopenharmony_ci slid = htonl(opa_get_lid_from_gid(&ib->sgid)); 25362306a36Sopenharmony_ci dlid = htonl(opa_get_lid_from_gid(&ib->dgid)); 25462306a36Sopenharmony_ci } else { 25562306a36Sopenharmony_ci slid = htonl(ntohs(ib->ib.slid)); 25662306a36Sopenharmony_ci dlid = htonl(ntohs(ib->ib.dlid)); 25762306a36Sopenharmony_ci } 25862306a36Sopenharmony_ci opa->opa.slid = slid; 25962306a36Sopenharmony_ci opa->opa.dlid = dlid; 26062306a36Sopenharmony_ci opa->service_id = ib->service_id; 26162306a36Sopenharmony_ci opa->opa.raw_traffic = ib->ib.raw_traffic; 26262306a36Sopenharmony_ci} 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci/* Convert from OPA to IB path record */ 26562306a36Sopenharmony_cistatic inline void sa_convert_path_opa_to_ib(struct sa_path_rec *dest, 26662306a36Sopenharmony_ci struct sa_path_rec *src) 26762306a36Sopenharmony_ci{ 26862306a36Sopenharmony_ci if (src->rec_type != SA_PATH_REC_TYPE_OPA) 26962306a36Sopenharmony_ci return; 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci *dest = *src; 27262306a36Sopenharmony_ci dest->rec_type = SA_PATH_REC_TYPE_IB; 27362306a36Sopenharmony_ci path_conv_opa_to_ib(dest, src); 27462306a36Sopenharmony_ci} 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci/* Convert from IB to OPA path record */ 27762306a36Sopenharmony_cistatic inline void sa_convert_path_ib_to_opa(struct sa_path_rec *dest, 27862306a36Sopenharmony_ci struct sa_path_rec *src) 27962306a36Sopenharmony_ci{ 28062306a36Sopenharmony_ci if (src->rec_type != SA_PATH_REC_TYPE_IB) 28162306a36Sopenharmony_ci return; 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci /* Do a structure copy and overwrite the relevant fields */ 28462306a36Sopenharmony_ci *dest = *src; 28562306a36Sopenharmony_ci dest->rec_type = SA_PATH_REC_TYPE_OPA; 28662306a36Sopenharmony_ci path_conv_ib_to_opa(dest, src); 28762306a36Sopenharmony_ci} 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MGID IB_SA_COMP_MASK( 0) 29062306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PORT_GID IB_SA_COMP_MASK( 1) 29162306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_QKEY IB_SA_COMP_MASK( 2) 29262306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MLID IB_SA_COMP_MASK( 3) 29362306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MTU_SELECTOR IB_SA_COMP_MASK( 4) 29462306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MTU IB_SA_COMP_MASK( 5) 29562306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS IB_SA_COMP_MASK( 6) 29662306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PKEY IB_SA_COMP_MASK( 7) 29762306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_RATE_SELECTOR IB_SA_COMP_MASK( 8) 29862306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_RATE IB_SA_COMP_MASK( 9) 29962306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(10) 30062306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(11) 30162306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_SL IB_SA_COMP_MASK(12) 30262306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_FLOW_LABEL IB_SA_COMP_MASK(13) 30362306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_HOP_LIMIT IB_SA_COMP_MASK(14) 30462306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_SCOPE IB_SA_COMP_MASK(15) 30562306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_JOIN_STATE IB_SA_COMP_MASK(16) 30662306a36Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PROXY_JOIN IB_SA_COMP_MASK(17) 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_cistruct ib_sa_mcmember_rec { 30962306a36Sopenharmony_ci union ib_gid mgid; 31062306a36Sopenharmony_ci union ib_gid port_gid; 31162306a36Sopenharmony_ci __be32 qkey; 31262306a36Sopenharmony_ci __be16 mlid; 31362306a36Sopenharmony_ci u8 mtu_selector; 31462306a36Sopenharmony_ci u8 mtu; 31562306a36Sopenharmony_ci u8 traffic_class; 31662306a36Sopenharmony_ci __be16 pkey; 31762306a36Sopenharmony_ci u8 rate_selector; 31862306a36Sopenharmony_ci u8 rate; 31962306a36Sopenharmony_ci u8 packet_life_time_selector; 32062306a36Sopenharmony_ci u8 packet_life_time; 32162306a36Sopenharmony_ci u8 sl; 32262306a36Sopenharmony_ci __be32 flow_label; 32362306a36Sopenharmony_ci u8 hop_limit; 32462306a36Sopenharmony_ci u8 scope; 32562306a36Sopenharmony_ci u8 join_state; 32662306a36Sopenharmony_ci u8 proxy_join; 32762306a36Sopenharmony_ci}; 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci/* Service Record Component Mask Sec 15.2.5.14 Ver 1.1 */ 33062306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_ID IB_SA_COMP_MASK( 0) 33162306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_GID IB_SA_COMP_MASK( 1) 33262306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_PKEY IB_SA_COMP_MASK( 2) 33362306a36Sopenharmony_ci/* reserved: 3 */ 33462306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_LEASE IB_SA_COMP_MASK( 4) 33562306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_KEY IB_SA_COMP_MASK( 5) 33662306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_NAME IB_SA_COMP_MASK( 6) 33762306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_0 IB_SA_COMP_MASK( 7) 33862306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_1 IB_SA_COMP_MASK( 8) 33962306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_2 IB_SA_COMP_MASK( 9) 34062306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_3 IB_SA_COMP_MASK(10) 34162306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_4 IB_SA_COMP_MASK(11) 34262306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_5 IB_SA_COMP_MASK(12) 34362306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_6 IB_SA_COMP_MASK(13) 34462306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_7 IB_SA_COMP_MASK(14) 34562306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_8 IB_SA_COMP_MASK(15) 34662306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_9 IB_SA_COMP_MASK(16) 34762306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_10 IB_SA_COMP_MASK(17) 34862306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_11 IB_SA_COMP_MASK(18) 34962306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_12 IB_SA_COMP_MASK(19) 35062306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_13 IB_SA_COMP_MASK(20) 35162306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_14 IB_SA_COMP_MASK(21) 35262306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_15 IB_SA_COMP_MASK(22) 35362306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_0 IB_SA_COMP_MASK(23) 35462306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_1 IB_SA_COMP_MASK(24) 35562306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_2 IB_SA_COMP_MASK(25) 35662306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_3 IB_SA_COMP_MASK(26) 35762306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_4 IB_SA_COMP_MASK(27) 35862306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_5 IB_SA_COMP_MASK(28) 35962306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_6 IB_SA_COMP_MASK(29) 36062306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_7 IB_SA_COMP_MASK(30) 36162306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_0 IB_SA_COMP_MASK(31) 36262306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_1 IB_SA_COMP_MASK(32) 36362306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_2 IB_SA_COMP_MASK(33) 36462306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_3 IB_SA_COMP_MASK(34) 36562306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA64_0 IB_SA_COMP_MASK(35) 36662306a36Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA64_1 IB_SA_COMP_MASK(36) 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci#define IB_DEFAULT_SERVICE_LEASE 0xFFFFFFFF 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_LID IB_SA_COMP_MASK(0) 37162306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_BLOCK_NUM IB_SA_COMP_MASK(1) 37262306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_RES1 IB_SA_COMP_MASK(2) 37362306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_RES2 IB_SA_COMP_MASK(3) 37462306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID0 IB_SA_COMP_MASK(4) 37562306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID1 IB_SA_COMP_MASK(5) 37662306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID2 IB_SA_COMP_MASK(6) 37762306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID3 IB_SA_COMP_MASK(7) 37862306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID4 IB_SA_COMP_MASK(8) 37962306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID5 IB_SA_COMP_MASK(9) 38062306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID6 IB_SA_COMP_MASK(10) 38162306a36Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID7 IB_SA_COMP_MASK(11) 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_cistruct ib_sa_guidinfo_rec { 38462306a36Sopenharmony_ci __be16 lid; 38562306a36Sopenharmony_ci u8 block_num; 38662306a36Sopenharmony_ci /* reserved */ 38762306a36Sopenharmony_ci u8 res1; 38862306a36Sopenharmony_ci __be32 res2; 38962306a36Sopenharmony_ci u8 guid_info_list[64]; 39062306a36Sopenharmony_ci}; 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_cistruct ib_sa_client { 39362306a36Sopenharmony_ci atomic_t users; 39462306a36Sopenharmony_ci struct completion comp; 39562306a36Sopenharmony_ci}; 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci/** 39862306a36Sopenharmony_ci * ib_sa_register_client - Register an SA client. 39962306a36Sopenharmony_ci */ 40062306a36Sopenharmony_civoid ib_sa_register_client(struct ib_sa_client *client); 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci/** 40362306a36Sopenharmony_ci * ib_sa_unregister_client - Deregister an SA client. 40462306a36Sopenharmony_ci * @client: Client object to deregister. 40562306a36Sopenharmony_ci */ 40662306a36Sopenharmony_civoid ib_sa_unregister_client(struct ib_sa_client *client); 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_cistruct ib_sa_query; 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_civoid ib_sa_cancel_query(int id, struct ib_sa_query *query); 41162306a36Sopenharmony_ci 41262306a36Sopenharmony_ciint ib_sa_path_rec_get(struct ib_sa_client *client, struct ib_device *device, 41362306a36Sopenharmony_ci u32 port_num, struct sa_path_rec *rec, 41462306a36Sopenharmony_ci ib_sa_comp_mask comp_mask, unsigned long timeout_ms, 41562306a36Sopenharmony_ci gfp_t gfp_mask, 41662306a36Sopenharmony_ci void (*callback)(int status, struct sa_path_rec *resp, 41762306a36Sopenharmony_ci unsigned int num_prs, void *context), 41862306a36Sopenharmony_ci void *context, struct ib_sa_query **query); 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_cistruct ib_sa_multicast { 42162306a36Sopenharmony_ci struct ib_sa_mcmember_rec rec; 42262306a36Sopenharmony_ci ib_sa_comp_mask comp_mask; 42362306a36Sopenharmony_ci int (*callback)(int status, 42462306a36Sopenharmony_ci struct ib_sa_multicast *multicast); 42562306a36Sopenharmony_ci void *context; 42662306a36Sopenharmony_ci}; 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci/** 42962306a36Sopenharmony_ci * ib_sa_join_multicast - Initiates a join request to the specified multicast 43062306a36Sopenharmony_ci * group. 43162306a36Sopenharmony_ci * @client: SA client 43262306a36Sopenharmony_ci * @device: Device associated with the multicast group. 43362306a36Sopenharmony_ci * @port_num: Port on the specified device to associate with the multicast 43462306a36Sopenharmony_ci * group. 43562306a36Sopenharmony_ci * @rec: SA multicast member record specifying group attributes. 43662306a36Sopenharmony_ci * @comp_mask: Component mask indicating which group attributes of %rec are 43762306a36Sopenharmony_ci * valid. 43862306a36Sopenharmony_ci * @gfp_mask: GFP mask for memory allocations. 43962306a36Sopenharmony_ci * @callback: User callback invoked once the join operation completes. 44062306a36Sopenharmony_ci * @context: User specified context stored with the ib_sa_multicast structure. 44162306a36Sopenharmony_ci * 44262306a36Sopenharmony_ci * This call initiates a multicast join request with the SA for the specified 44362306a36Sopenharmony_ci * multicast group. If the join operation is started successfully, it returns 44462306a36Sopenharmony_ci * an ib_sa_multicast structure that is used to track the multicast operation. 44562306a36Sopenharmony_ci * Users must free this structure by calling ib_free_multicast, even if the 44662306a36Sopenharmony_ci * join operation later fails. (The callback status is non-zero.) 44762306a36Sopenharmony_ci * 44862306a36Sopenharmony_ci * If the join operation fails; status will be non-zero, with the following 44962306a36Sopenharmony_ci * failures possible: 45062306a36Sopenharmony_ci * -ETIMEDOUT: The request timed out. 45162306a36Sopenharmony_ci * -EIO: An error occurred sending the query. 45262306a36Sopenharmony_ci * -EINVAL: The MCMemberRecord values differed from the existing group's. 45362306a36Sopenharmony_ci * -ENETRESET: Indicates that an fatal error has occurred on the multicast 45462306a36Sopenharmony_ci * group, and the user must rejoin the group to continue using it. 45562306a36Sopenharmony_ci */ 45662306a36Sopenharmony_cistruct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client, 45762306a36Sopenharmony_ci struct ib_device *device, 45862306a36Sopenharmony_ci u32 port_num, 45962306a36Sopenharmony_ci struct ib_sa_mcmember_rec *rec, 46062306a36Sopenharmony_ci ib_sa_comp_mask comp_mask, gfp_t gfp_mask, 46162306a36Sopenharmony_ci int (*callback)(int status, 46262306a36Sopenharmony_ci struct ib_sa_multicast 46362306a36Sopenharmony_ci *multicast), 46462306a36Sopenharmony_ci void *context); 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci/** 46762306a36Sopenharmony_ci * ib_free_multicast - Frees the multicast tracking structure, and releases 46862306a36Sopenharmony_ci * any reference on the multicast group. 46962306a36Sopenharmony_ci * @multicast: Multicast tracking structure allocated by ib_join_multicast. 47062306a36Sopenharmony_ci * 47162306a36Sopenharmony_ci * This call blocks until the multicast identifier is destroyed. It may 47262306a36Sopenharmony_ci * not be called from within the multicast callback; however, returning a non- 47362306a36Sopenharmony_ci * zero value from the callback will result in destroying the multicast 47462306a36Sopenharmony_ci * tracking structure. 47562306a36Sopenharmony_ci */ 47662306a36Sopenharmony_civoid ib_sa_free_multicast(struct ib_sa_multicast *multicast); 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci/** 47962306a36Sopenharmony_ci * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and 48062306a36Sopenharmony_ci * returns it if found. 48162306a36Sopenharmony_ci * @device: Device associated with the multicast group. 48262306a36Sopenharmony_ci * @port_num: Port on the specified device to associate with the multicast 48362306a36Sopenharmony_ci * group. 48462306a36Sopenharmony_ci * @mgid: MGID of multicast group. 48562306a36Sopenharmony_ci * @rec: Location to copy SA multicast member record. 48662306a36Sopenharmony_ci */ 48762306a36Sopenharmony_ciint ib_sa_get_mcmember_rec(struct ib_device *device, u32 port_num, 48862306a36Sopenharmony_ci union ib_gid *mgid, struct ib_sa_mcmember_rec *rec); 48962306a36Sopenharmony_ci 49062306a36Sopenharmony_ci/** 49162306a36Sopenharmony_ci * ib_init_ah_from_mcmember - Initialize address handle attributes based on 49262306a36Sopenharmony_ci * an SA multicast member record. 49362306a36Sopenharmony_ci */ 49462306a36Sopenharmony_ciint ib_init_ah_from_mcmember(struct ib_device *device, u32 port_num, 49562306a36Sopenharmony_ci struct ib_sa_mcmember_rec *rec, 49662306a36Sopenharmony_ci struct net_device *ndev, 49762306a36Sopenharmony_ci enum ib_gid_type gid_type, 49862306a36Sopenharmony_ci struct rdma_ah_attr *ah_attr); 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ciint ib_init_ah_attr_from_path(struct ib_device *device, u32 port_num, 50162306a36Sopenharmony_ci struct sa_path_rec *rec, 50262306a36Sopenharmony_ci struct rdma_ah_attr *ah_attr, 50362306a36Sopenharmony_ci const struct ib_gid_attr *sgid_attr); 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci/** 50662306a36Sopenharmony_ci * ib_sa_pack_path - Conert a path record from struct ib_sa_path_rec 50762306a36Sopenharmony_ci * to IB MAD wire format. 50862306a36Sopenharmony_ci */ 50962306a36Sopenharmony_civoid ib_sa_pack_path(struct sa_path_rec *rec, void *attribute); 51062306a36Sopenharmony_ci 51162306a36Sopenharmony_ci/** 51262306a36Sopenharmony_ci * ib_sa_unpack_path - Convert a path record from MAD format to struct 51362306a36Sopenharmony_ci * ib_sa_path_rec. 51462306a36Sopenharmony_ci */ 51562306a36Sopenharmony_civoid ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec); 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci/* Support GuidInfoRecord */ 51862306a36Sopenharmony_ciint ib_sa_guid_info_rec_query(struct ib_sa_client *client, 51962306a36Sopenharmony_ci struct ib_device *device, u32 port_num, 52062306a36Sopenharmony_ci struct ib_sa_guidinfo_rec *rec, 52162306a36Sopenharmony_ci ib_sa_comp_mask comp_mask, u8 method, 52262306a36Sopenharmony_ci unsigned long timeout_ms, gfp_t gfp_mask, 52362306a36Sopenharmony_ci void (*callback)(int status, 52462306a36Sopenharmony_ci struct ib_sa_guidinfo_rec *resp, 52562306a36Sopenharmony_ci void *context), 52662306a36Sopenharmony_ci void *context, struct ib_sa_query **sa_query); 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_cistatic inline bool sa_path_is_roce(struct sa_path_rec *rec) 52962306a36Sopenharmony_ci{ 53062306a36Sopenharmony_ci return ((rec->rec_type == SA_PATH_REC_TYPE_ROCE_V1) || 53162306a36Sopenharmony_ci (rec->rec_type == SA_PATH_REC_TYPE_ROCE_V2)); 53262306a36Sopenharmony_ci} 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_cistatic inline bool sa_path_is_opa(struct sa_path_rec *rec) 53562306a36Sopenharmony_ci{ 53662306a36Sopenharmony_ci return (rec->rec_type == SA_PATH_REC_TYPE_OPA); 53762306a36Sopenharmony_ci} 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_cistatic inline void sa_path_set_slid(struct sa_path_rec *rec, u32 slid) 54062306a36Sopenharmony_ci{ 54162306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 54262306a36Sopenharmony_ci rec->ib.slid = cpu_to_be16(slid); 54362306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 54462306a36Sopenharmony_ci rec->opa.slid = cpu_to_be32(slid); 54562306a36Sopenharmony_ci} 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_cistatic inline void sa_path_set_dlid(struct sa_path_rec *rec, u32 dlid) 54862306a36Sopenharmony_ci{ 54962306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 55062306a36Sopenharmony_ci rec->ib.dlid = cpu_to_be16(dlid); 55162306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 55262306a36Sopenharmony_ci rec->opa.dlid = cpu_to_be32(dlid); 55362306a36Sopenharmony_ci} 55462306a36Sopenharmony_ci 55562306a36Sopenharmony_cistatic inline void sa_path_set_raw_traffic(struct sa_path_rec *rec, 55662306a36Sopenharmony_ci u8 raw_traffic) 55762306a36Sopenharmony_ci{ 55862306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 55962306a36Sopenharmony_ci rec->ib.raw_traffic = raw_traffic; 56062306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 56162306a36Sopenharmony_ci rec->opa.raw_traffic = raw_traffic; 56262306a36Sopenharmony_ci} 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_cistatic inline __be32 sa_path_get_slid(struct sa_path_rec *rec) 56562306a36Sopenharmony_ci{ 56662306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 56762306a36Sopenharmony_ci return htonl(ntohs(rec->ib.slid)); 56862306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 56962306a36Sopenharmony_ci return rec->opa.slid; 57062306a36Sopenharmony_ci return 0; 57162306a36Sopenharmony_ci} 57262306a36Sopenharmony_ci 57362306a36Sopenharmony_cistatic inline __be32 sa_path_get_dlid(struct sa_path_rec *rec) 57462306a36Sopenharmony_ci{ 57562306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 57662306a36Sopenharmony_ci return htonl(ntohs(rec->ib.dlid)); 57762306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 57862306a36Sopenharmony_ci return rec->opa.dlid; 57962306a36Sopenharmony_ci return 0; 58062306a36Sopenharmony_ci} 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_cistatic inline u8 sa_path_get_raw_traffic(struct sa_path_rec *rec) 58362306a36Sopenharmony_ci{ 58462306a36Sopenharmony_ci if (rec->rec_type == SA_PATH_REC_TYPE_IB) 58562306a36Sopenharmony_ci return rec->ib.raw_traffic; 58662306a36Sopenharmony_ci else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 58762306a36Sopenharmony_ci return rec->opa.raw_traffic; 58862306a36Sopenharmony_ci return 0; 58962306a36Sopenharmony_ci} 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_cistatic inline void sa_path_set_dmac(struct sa_path_rec *rec, u8 *dmac) 59262306a36Sopenharmony_ci{ 59362306a36Sopenharmony_ci if (sa_path_is_roce(rec)) 59462306a36Sopenharmony_ci memcpy(rec->roce.dmac, dmac, ETH_ALEN); 59562306a36Sopenharmony_ci} 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_cistatic inline void sa_path_set_dmac_zero(struct sa_path_rec *rec) 59862306a36Sopenharmony_ci{ 59962306a36Sopenharmony_ci if (sa_path_is_roce(rec)) 60062306a36Sopenharmony_ci eth_zero_addr(rec->roce.dmac); 60162306a36Sopenharmony_ci} 60262306a36Sopenharmony_ci 60362306a36Sopenharmony_cistatic inline u8 *sa_path_get_dmac(struct sa_path_rec *rec) 60462306a36Sopenharmony_ci{ 60562306a36Sopenharmony_ci if (sa_path_is_roce(rec)) 60662306a36Sopenharmony_ci return rec->roce.dmac; 60762306a36Sopenharmony_ci return NULL; 60862306a36Sopenharmony_ci} 60962306a36Sopenharmony_ci#endif /* IB_SA_H */ 610