18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2004 Topspin Communications.  All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (c) 2006 Intel Corporation.  All rights reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef IB_SA_H
98c2ecf20Sopenharmony_ci#define IB_SA_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/completion.h>
128c2ecf20Sopenharmony_ci#include <linux/compiler.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/atomic.h>
158c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
188c2ecf20Sopenharmony_ci#include <rdma/ib_mad.h>
198c2ecf20Sopenharmony_ci#include <rdma/ib_addr.h>
208c2ecf20Sopenharmony_ci#include <rdma/opa_addr.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cienum {
238c2ecf20Sopenharmony_ci	IB_SA_CLASS_VERSION		= 2,	/* IB spec version 1.1/1.2 */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	IB_SA_METHOD_GET_TABLE		= 0x12,
268c2ecf20Sopenharmony_ci	IB_SA_METHOD_GET_TABLE_RESP	= 0x92,
278c2ecf20Sopenharmony_ci	IB_SA_METHOD_DELETE		= 0x15,
288c2ecf20Sopenharmony_ci	IB_SA_METHOD_DELETE_RESP	= 0x95,
298c2ecf20Sopenharmony_ci	IB_SA_METHOD_GET_MULTI		= 0x14,
308c2ecf20Sopenharmony_ci	IB_SA_METHOD_GET_MULTI_RESP	= 0x94,
318c2ecf20Sopenharmony_ci	IB_SA_METHOD_GET_TRACE_TBL	= 0x13
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define OPA_SA_CLASS_VERSION	0x80
358c2ecf20Sopenharmony_cienum {
368c2ecf20Sopenharmony_ci	IB_SA_ATTR_CLASS_PORTINFO    = 0x01,
378c2ecf20Sopenharmony_ci	IB_SA_ATTR_NOTICE	     = 0x02,
388c2ecf20Sopenharmony_ci	IB_SA_ATTR_INFORM_INFO	     = 0x03,
398c2ecf20Sopenharmony_ci	IB_SA_ATTR_NODE_REC	     = 0x11,
408c2ecf20Sopenharmony_ci	IB_SA_ATTR_PORT_INFO_REC     = 0x12,
418c2ecf20Sopenharmony_ci	IB_SA_ATTR_SL2VL_REC	     = 0x13,
428c2ecf20Sopenharmony_ci	IB_SA_ATTR_SWITCH_REC	     = 0x14,
438c2ecf20Sopenharmony_ci	IB_SA_ATTR_LINEAR_FDB_REC    = 0x15,
448c2ecf20Sopenharmony_ci	IB_SA_ATTR_RANDOM_FDB_REC    = 0x16,
458c2ecf20Sopenharmony_ci	IB_SA_ATTR_MCAST_FDB_REC     = 0x17,
468c2ecf20Sopenharmony_ci	IB_SA_ATTR_SM_INFO_REC	     = 0x18,
478c2ecf20Sopenharmony_ci	IB_SA_ATTR_LINK_REC	     = 0x20,
488c2ecf20Sopenharmony_ci	IB_SA_ATTR_GUID_INFO_REC     = 0x30,
498c2ecf20Sopenharmony_ci	IB_SA_ATTR_SERVICE_REC	     = 0x31,
508c2ecf20Sopenharmony_ci	IB_SA_ATTR_PARTITION_REC     = 0x33,
518c2ecf20Sopenharmony_ci	IB_SA_ATTR_PATH_REC	     = 0x35,
528c2ecf20Sopenharmony_ci	IB_SA_ATTR_VL_ARB_REC	     = 0x36,
538c2ecf20Sopenharmony_ci	IB_SA_ATTR_MC_MEMBER_REC     = 0x38,
548c2ecf20Sopenharmony_ci	IB_SA_ATTR_TRACE_REC	     = 0x39,
558c2ecf20Sopenharmony_ci	IB_SA_ATTR_MULTI_PATH_REC    = 0x3a,
568c2ecf20Sopenharmony_ci	IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b,
578c2ecf20Sopenharmony_ci	IB_SA_ATTR_INFORM_INFO_REC   = 0xf3
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cienum ib_sa_selector {
618c2ecf20Sopenharmony_ci	IB_SA_GT   = 0,
628c2ecf20Sopenharmony_ci	IB_SA_LT   = 1,
638c2ecf20Sopenharmony_ci	IB_SA_EQ   = 2,
648c2ecf20Sopenharmony_ci	/*
658c2ecf20Sopenharmony_ci	 * The meaning of "best" depends on the attribute: for
668c2ecf20Sopenharmony_ci	 * example, for MTU best will return the largest available
678c2ecf20Sopenharmony_ci	 * MTU, while for packet life time, best will return the
688c2ecf20Sopenharmony_ci	 * smallest available life time.
698c2ecf20Sopenharmony_ci	 */
708c2ecf20Sopenharmony_ci	IB_SA_BEST = 3
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*
748c2ecf20Sopenharmony_ci * There are 4 types of join states:
758c2ecf20Sopenharmony_ci * FullMember, NonMember, SendOnlyNonMember, SendOnlyFullMember.
768c2ecf20Sopenharmony_ci * The order corresponds to JoinState bits in MCMemberRecord.
778c2ecf20Sopenharmony_ci */
788c2ecf20Sopenharmony_cienum ib_sa_mc_join_states {
798c2ecf20Sopenharmony_ci	FULLMEMBER_JOIN,
808c2ecf20Sopenharmony_ci	NONMEMBER_JOIN,
818c2ecf20Sopenharmony_ci	SENDONLY_NONMEBER_JOIN,
828c2ecf20Sopenharmony_ci	SENDONLY_FULLMEMBER_JOIN,
838c2ecf20Sopenharmony_ci	NUM_JOIN_MEMBERSHIP_TYPES,
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT	BIT(12)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/*
898c2ecf20Sopenharmony_ci * Structures for SA records are named "struct ib_sa_xxx_rec."  No
908c2ecf20Sopenharmony_ci * attempt is made to pack structures to match the physical layout of
918c2ecf20Sopenharmony_ci * SA records in SA MADs; all packing and unpacking is handled by the
928c2ecf20Sopenharmony_ci * SA query code.
938c2ecf20Sopenharmony_ci *
948c2ecf20Sopenharmony_ci * For a record with structure ib_sa_xxx_rec, the naming convention
958c2ecf20Sopenharmony_ci * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we
968c2ecf20Sopenharmony_ci * never use different abbreviations or otherwise change the spelling
978c2ecf20Sopenharmony_ci * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY).
988c2ecf20Sopenharmony_ci *
998c2ecf20Sopenharmony_ci * Reserved rows are indicated with comments to help maintainability.
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_SERVICE_ID		       (IB_SA_COMP_MASK( 0) |\
1038c2ecf20Sopenharmony_ci							IB_SA_COMP_MASK( 1))
1048c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_DGID				IB_SA_COMP_MASK( 2)
1058c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_SGID				IB_SA_COMP_MASK( 3)
1068c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_DLID				IB_SA_COMP_MASK( 4)
1078c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_SLID				IB_SA_COMP_MASK( 5)
1088c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_RAW_TRAFFIC			IB_SA_COMP_MASK( 6)
1098c2ecf20Sopenharmony_ci/* reserved:								 7 */
1108c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_FLOW_LABEL       		IB_SA_COMP_MASK( 8)
1118c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_HOP_LIMIT			IB_SA_COMP_MASK( 9)
1128c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_TRAFFIC_CLASS			IB_SA_COMP_MASK(10)
1138c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_REVERSIBLE			IB_SA_COMP_MASK(11)
1148c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_NUMB_PATH			IB_SA_COMP_MASK(12)
1158c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_PKEY				IB_SA_COMP_MASK(13)
1168c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_QOS_CLASS			IB_SA_COMP_MASK(14)
1178c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_SL				IB_SA_COMP_MASK(15)
1188c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_MTU_SELECTOR			IB_SA_COMP_MASK(16)
1198c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_MTU				IB_SA_COMP_MASK(17)
1208c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_RATE_SELECTOR			IB_SA_COMP_MASK(18)
1218c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_RATE				IB_SA_COMP_MASK(19)
1228c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(20)
1238c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_PACKET_LIFE_TIME			IB_SA_COMP_MASK(21)
1248c2ecf20Sopenharmony_ci#define IB_SA_PATH_REC_PREFERENCE			IB_SA_COMP_MASK(22)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cienum sa_path_rec_type {
1278c2ecf20Sopenharmony_ci	SA_PATH_REC_TYPE_IB,
1288c2ecf20Sopenharmony_ci	SA_PATH_REC_TYPE_ROCE_V1,
1298c2ecf20Sopenharmony_ci	SA_PATH_REC_TYPE_ROCE_V2,
1308c2ecf20Sopenharmony_ci	SA_PATH_REC_TYPE_OPA
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistruct sa_path_rec_ib {
1348c2ecf20Sopenharmony_ci	__be16       dlid;
1358c2ecf20Sopenharmony_ci	__be16       slid;
1368c2ecf20Sopenharmony_ci	u8           raw_traffic;
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/**
1408c2ecf20Sopenharmony_ci * struct sa_path_rec_roce - RoCE specific portion of the path record entry
1418c2ecf20Sopenharmony_ci * @route_resolved:	When set, it indicates that this route is already
1428c2ecf20Sopenharmony_ci *			resolved for this path record entry.
1438c2ecf20Sopenharmony_ci * @dmac:		Destination mac address for the given DGID entry
1448c2ecf20Sopenharmony_ci *			of the path record entry.
1458c2ecf20Sopenharmony_ci */
1468c2ecf20Sopenharmony_cistruct sa_path_rec_roce {
1478c2ecf20Sopenharmony_ci	bool	route_resolved;
1488c2ecf20Sopenharmony_ci	u8	dmac[ETH_ALEN];
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistruct sa_path_rec_opa {
1528c2ecf20Sopenharmony_ci	__be32       dlid;
1538c2ecf20Sopenharmony_ci	__be32       slid;
1548c2ecf20Sopenharmony_ci	u8           raw_traffic;
1558c2ecf20Sopenharmony_ci	u8	     l2_8B;
1568c2ecf20Sopenharmony_ci	u8	     l2_10B;
1578c2ecf20Sopenharmony_ci	u8	     l2_9B;
1588c2ecf20Sopenharmony_ci	u8	     l2_16B;
1598c2ecf20Sopenharmony_ci	u8	     qos_type;
1608c2ecf20Sopenharmony_ci	u8	     qos_priority;
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistruct sa_path_rec {
1648c2ecf20Sopenharmony_ci	union ib_gid dgid;
1658c2ecf20Sopenharmony_ci	union ib_gid sgid;
1668c2ecf20Sopenharmony_ci	__be64       service_id;
1678c2ecf20Sopenharmony_ci	/* reserved */
1688c2ecf20Sopenharmony_ci	__be32       flow_label;
1698c2ecf20Sopenharmony_ci	u8           hop_limit;
1708c2ecf20Sopenharmony_ci	u8           traffic_class;
1718c2ecf20Sopenharmony_ci	u8           reversible;
1728c2ecf20Sopenharmony_ci	u8           numb_path;
1738c2ecf20Sopenharmony_ci	__be16       pkey;
1748c2ecf20Sopenharmony_ci	__be16       qos_class;
1758c2ecf20Sopenharmony_ci	u8           sl;
1768c2ecf20Sopenharmony_ci	u8           mtu_selector;
1778c2ecf20Sopenharmony_ci	u8           mtu;
1788c2ecf20Sopenharmony_ci	u8           rate_selector;
1798c2ecf20Sopenharmony_ci	u8           rate;
1808c2ecf20Sopenharmony_ci	u8           packet_life_time_selector;
1818c2ecf20Sopenharmony_ci	u8           packet_life_time;
1828c2ecf20Sopenharmony_ci	u8           preference;
1838c2ecf20Sopenharmony_ci	union {
1848c2ecf20Sopenharmony_ci		struct sa_path_rec_ib ib;
1858c2ecf20Sopenharmony_ci		struct sa_path_rec_roce roce;
1868c2ecf20Sopenharmony_ci		struct sa_path_rec_opa opa;
1878c2ecf20Sopenharmony_ci	};
1888c2ecf20Sopenharmony_ci	enum sa_path_rec_type rec_type;
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistatic inline enum ib_gid_type
1928c2ecf20Sopenharmony_ci		sa_conv_pathrec_to_gid_type(struct sa_path_rec *rec)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	switch (rec->rec_type) {
1958c2ecf20Sopenharmony_ci	case SA_PATH_REC_TYPE_ROCE_V1:
1968c2ecf20Sopenharmony_ci		return IB_GID_TYPE_ROCE;
1978c2ecf20Sopenharmony_ci	case SA_PATH_REC_TYPE_ROCE_V2:
1988c2ecf20Sopenharmony_ci		return IB_GID_TYPE_ROCE_UDP_ENCAP;
1998c2ecf20Sopenharmony_ci	default:
2008c2ecf20Sopenharmony_ci		return IB_GID_TYPE_IB;
2018c2ecf20Sopenharmony_ci	}
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic inline enum sa_path_rec_type
2058c2ecf20Sopenharmony_ci		sa_conv_gid_to_pathrec_type(enum ib_gid_type type)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	switch (type) {
2088c2ecf20Sopenharmony_ci	case IB_GID_TYPE_ROCE:
2098c2ecf20Sopenharmony_ci		return SA_PATH_REC_TYPE_ROCE_V1;
2108c2ecf20Sopenharmony_ci	case IB_GID_TYPE_ROCE_UDP_ENCAP:
2118c2ecf20Sopenharmony_ci		return SA_PATH_REC_TYPE_ROCE_V2;
2128c2ecf20Sopenharmony_ci	default:
2138c2ecf20Sopenharmony_ci		return SA_PATH_REC_TYPE_IB;
2148c2ecf20Sopenharmony_ci	}
2158c2ecf20Sopenharmony_ci}
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic inline void path_conv_opa_to_ib(struct sa_path_rec *ib,
2188c2ecf20Sopenharmony_ci				       struct sa_path_rec *opa)
2198c2ecf20Sopenharmony_ci{
2208c2ecf20Sopenharmony_ci	if ((be32_to_cpu(opa->opa.dlid) >=
2218c2ecf20Sopenharmony_ci	     be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
2228c2ecf20Sopenharmony_ci	    (be32_to_cpu(opa->opa.slid) >=
2238c2ecf20Sopenharmony_ci	     be16_to_cpu(IB_MULTICAST_LID_BASE))) {
2248c2ecf20Sopenharmony_ci		/* Create OPA GID and zero out the LID */
2258c2ecf20Sopenharmony_ci		ib->dgid.global.interface_id
2268c2ecf20Sopenharmony_ci				= OPA_MAKE_ID(be32_to_cpu(opa->opa.dlid));
2278c2ecf20Sopenharmony_ci		ib->dgid.global.subnet_prefix
2288c2ecf20Sopenharmony_ci				= opa->dgid.global.subnet_prefix;
2298c2ecf20Sopenharmony_ci		ib->sgid.global.interface_id
2308c2ecf20Sopenharmony_ci				= OPA_MAKE_ID(be32_to_cpu(opa->opa.slid));
2318c2ecf20Sopenharmony_ci		ib->dgid.global.subnet_prefix
2328c2ecf20Sopenharmony_ci				= opa->dgid.global.subnet_prefix;
2338c2ecf20Sopenharmony_ci		ib->ib.dlid	= 0;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci		ib->ib.slid	= 0;
2368c2ecf20Sopenharmony_ci	} else {
2378c2ecf20Sopenharmony_ci		ib->ib.dlid	= htons(ntohl(opa->opa.dlid));
2388c2ecf20Sopenharmony_ci		ib->ib.slid	= htons(ntohl(opa->opa.slid));
2398c2ecf20Sopenharmony_ci	}
2408c2ecf20Sopenharmony_ci	ib->service_id		= opa->service_id;
2418c2ecf20Sopenharmony_ci	ib->ib.raw_traffic	= opa->opa.raw_traffic;
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic inline void path_conv_ib_to_opa(struct sa_path_rec *opa,
2458c2ecf20Sopenharmony_ci				       struct sa_path_rec *ib)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	__be32 slid, dlid;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	if ((ib_is_opa_gid(&ib->sgid)) ||
2508c2ecf20Sopenharmony_ci	    (ib_is_opa_gid(&ib->dgid))) {
2518c2ecf20Sopenharmony_ci		slid = htonl(opa_get_lid_from_gid(&ib->sgid));
2528c2ecf20Sopenharmony_ci		dlid = htonl(opa_get_lid_from_gid(&ib->dgid));
2538c2ecf20Sopenharmony_ci	} else {
2548c2ecf20Sopenharmony_ci		slid = htonl(ntohs(ib->ib.slid));
2558c2ecf20Sopenharmony_ci		dlid = htonl(ntohs(ib->ib.dlid));
2568c2ecf20Sopenharmony_ci	}
2578c2ecf20Sopenharmony_ci	opa->opa.slid		= slid;
2588c2ecf20Sopenharmony_ci	opa->opa.dlid		= dlid;
2598c2ecf20Sopenharmony_ci	opa->service_id		= ib->service_id;
2608c2ecf20Sopenharmony_ci	opa->opa.raw_traffic	= ib->ib.raw_traffic;
2618c2ecf20Sopenharmony_ci}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci/* Convert from OPA to IB path record */
2648c2ecf20Sopenharmony_cistatic inline void sa_convert_path_opa_to_ib(struct sa_path_rec *dest,
2658c2ecf20Sopenharmony_ci					     struct sa_path_rec *src)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	if (src->rec_type != SA_PATH_REC_TYPE_OPA)
2688c2ecf20Sopenharmony_ci		return;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	*dest = *src;
2718c2ecf20Sopenharmony_ci	dest->rec_type = SA_PATH_REC_TYPE_IB;
2728c2ecf20Sopenharmony_ci	path_conv_opa_to_ib(dest, src);
2738c2ecf20Sopenharmony_ci}
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci/* Convert from IB to OPA path record */
2768c2ecf20Sopenharmony_cistatic inline void sa_convert_path_ib_to_opa(struct sa_path_rec *dest,
2778c2ecf20Sopenharmony_ci					     struct sa_path_rec *src)
2788c2ecf20Sopenharmony_ci{
2798c2ecf20Sopenharmony_ci	if (src->rec_type != SA_PATH_REC_TYPE_IB)
2808c2ecf20Sopenharmony_ci		return;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	/* Do a structure copy and overwrite the relevant fields */
2838c2ecf20Sopenharmony_ci	*dest = *src;
2848c2ecf20Sopenharmony_ci	dest->rec_type = SA_PATH_REC_TYPE_OPA;
2858c2ecf20Sopenharmony_ci	path_conv_ib_to_opa(dest, src);
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MGID				IB_SA_COMP_MASK( 0)
2898c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PORT_GID			IB_SA_COMP_MASK( 1)
2908c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_QKEY				IB_SA_COMP_MASK( 2)
2918c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MLID				IB_SA_COMP_MASK( 3)
2928c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MTU_SELECTOR			IB_SA_COMP_MASK( 4)
2938c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_MTU				IB_SA_COMP_MASK( 5)
2948c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS		IB_SA_COMP_MASK( 6)
2958c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PKEY				IB_SA_COMP_MASK( 7)
2968c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_RATE_SELECTOR		IB_SA_COMP_MASK( 8)
2978c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_RATE				IB_SA_COMP_MASK( 9)
2988c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(10)
2998c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME		IB_SA_COMP_MASK(11)
3008c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_SL				IB_SA_COMP_MASK(12)
3018c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_FLOW_LABEL			IB_SA_COMP_MASK(13)
3028c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_HOP_LIMIT			IB_SA_COMP_MASK(14)
3038c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_SCOPE			IB_SA_COMP_MASK(15)
3048c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_JOIN_STATE			IB_SA_COMP_MASK(16)
3058c2ecf20Sopenharmony_ci#define IB_SA_MCMEMBER_REC_PROXY_JOIN			IB_SA_COMP_MASK(17)
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistruct ib_sa_mcmember_rec {
3088c2ecf20Sopenharmony_ci	union ib_gid mgid;
3098c2ecf20Sopenharmony_ci	union ib_gid port_gid;
3108c2ecf20Sopenharmony_ci	__be32       qkey;
3118c2ecf20Sopenharmony_ci	__be16       mlid;
3128c2ecf20Sopenharmony_ci	u8           mtu_selector;
3138c2ecf20Sopenharmony_ci	u8           mtu;
3148c2ecf20Sopenharmony_ci	u8           traffic_class;
3158c2ecf20Sopenharmony_ci	__be16       pkey;
3168c2ecf20Sopenharmony_ci	u8 	     rate_selector;
3178c2ecf20Sopenharmony_ci	u8 	     rate;
3188c2ecf20Sopenharmony_ci	u8 	     packet_life_time_selector;
3198c2ecf20Sopenharmony_ci	u8 	     packet_life_time;
3208c2ecf20Sopenharmony_ci	u8           sl;
3218c2ecf20Sopenharmony_ci	__be32       flow_label;
3228c2ecf20Sopenharmony_ci	u8           hop_limit;
3238c2ecf20Sopenharmony_ci	u8           scope;
3248c2ecf20Sopenharmony_ci	u8           join_state;
3258c2ecf20Sopenharmony_ci	u8           proxy_join;
3268c2ecf20Sopenharmony_ci};
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* Service Record Component Mask Sec 15.2.5.14 Ver 1.1	*/
3298c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_ID			IB_SA_COMP_MASK( 0)
3308c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_GID			IB_SA_COMP_MASK( 1)
3318c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_PKEY			IB_SA_COMP_MASK( 2)
3328c2ecf20Sopenharmony_ci/* reserved:								 3 */
3338c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_LEASE			IB_SA_COMP_MASK( 4)
3348c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_KEY			IB_SA_COMP_MASK( 5)
3358c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_NAME			IB_SA_COMP_MASK( 6)
3368c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_0		IB_SA_COMP_MASK( 7)
3378c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_1		IB_SA_COMP_MASK( 8)
3388c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_2		IB_SA_COMP_MASK( 9)
3398c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_3		IB_SA_COMP_MASK(10)
3408c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_4		IB_SA_COMP_MASK(11)
3418c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_5		IB_SA_COMP_MASK(12)
3428c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_6		IB_SA_COMP_MASK(13)
3438c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_7		IB_SA_COMP_MASK(14)
3448c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_8		IB_SA_COMP_MASK(15)
3458c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_9		IB_SA_COMP_MASK(16)
3468c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_10		IB_SA_COMP_MASK(17)
3478c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_11		IB_SA_COMP_MASK(18)
3488c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_12		IB_SA_COMP_MASK(19)
3498c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_13		IB_SA_COMP_MASK(20)
3508c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_14		IB_SA_COMP_MASK(21)
3518c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA8_15		IB_SA_COMP_MASK(22)
3528c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_0		IB_SA_COMP_MASK(23)
3538c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_1		IB_SA_COMP_MASK(24)
3548c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_2		IB_SA_COMP_MASK(25)
3558c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_3		IB_SA_COMP_MASK(26)
3568c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_4		IB_SA_COMP_MASK(27)
3578c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_5		IB_SA_COMP_MASK(28)
3588c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_6		IB_SA_COMP_MASK(29)
3598c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA16_7		IB_SA_COMP_MASK(30)
3608c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_0		IB_SA_COMP_MASK(31)
3618c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_1		IB_SA_COMP_MASK(32)
3628c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_2		IB_SA_COMP_MASK(33)
3638c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA32_3		IB_SA_COMP_MASK(34)
3648c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA64_0		IB_SA_COMP_MASK(35)
3658c2ecf20Sopenharmony_ci#define IB_SA_SERVICE_REC_SERVICE_DATA64_1		IB_SA_COMP_MASK(36)
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci#define IB_DEFAULT_SERVICE_LEASE 	0xFFFFFFFF
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistruct ib_sa_service_rec {
3708c2ecf20Sopenharmony_ci	u64		id;
3718c2ecf20Sopenharmony_ci	union ib_gid	gid;
3728c2ecf20Sopenharmony_ci	__be16 		pkey;
3738c2ecf20Sopenharmony_ci	/* reserved */
3748c2ecf20Sopenharmony_ci	u32		lease;
3758c2ecf20Sopenharmony_ci	u8		key[16];
3768c2ecf20Sopenharmony_ci	u8		name[64];
3778c2ecf20Sopenharmony_ci	u8		data8[16];
3788c2ecf20Sopenharmony_ci	u16		data16[8];
3798c2ecf20Sopenharmony_ci	u32		data32[4];
3808c2ecf20Sopenharmony_ci	u64		data64[2];
3818c2ecf20Sopenharmony_ci};
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_LID		IB_SA_COMP_MASK(0)
3848c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_BLOCK_NUM	IB_SA_COMP_MASK(1)
3858c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_RES1		IB_SA_COMP_MASK(2)
3868c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_RES2		IB_SA_COMP_MASK(3)
3878c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID0		IB_SA_COMP_MASK(4)
3888c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID1		IB_SA_COMP_MASK(5)
3898c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID2		IB_SA_COMP_MASK(6)
3908c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID3		IB_SA_COMP_MASK(7)
3918c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID4		IB_SA_COMP_MASK(8)
3928c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID5		IB_SA_COMP_MASK(9)
3938c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID6		IB_SA_COMP_MASK(10)
3948c2ecf20Sopenharmony_ci#define IB_SA_GUIDINFO_REC_GID7		IB_SA_COMP_MASK(11)
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_cistruct ib_sa_guidinfo_rec {
3978c2ecf20Sopenharmony_ci	__be16	lid;
3988c2ecf20Sopenharmony_ci	u8	block_num;
3998c2ecf20Sopenharmony_ci	/* reserved */
4008c2ecf20Sopenharmony_ci	u8	res1;
4018c2ecf20Sopenharmony_ci	__be32	res2;
4028c2ecf20Sopenharmony_ci	u8	guid_info_list[64];
4038c2ecf20Sopenharmony_ci};
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_cistruct ib_sa_client {
4068c2ecf20Sopenharmony_ci	atomic_t users;
4078c2ecf20Sopenharmony_ci	struct completion comp;
4088c2ecf20Sopenharmony_ci};
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci/**
4118c2ecf20Sopenharmony_ci * ib_sa_register_client - Register an SA client.
4128c2ecf20Sopenharmony_ci */
4138c2ecf20Sopenharmony_civoid ib_sa_register_client(struct ib_sa_client *client);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci/**
4168c2ecf20Sopenharmony_ci * ib_sa_unregister_client - Deregister an SA client.
4178c2ecf20Sopenharmony_ci * @client: Client object to deregister.
4188c2ecf20Sopenharmony_ci */
4198c2ecf20Sopenharmony_civoid ib_sa_unregister_client(struct ib_sa_client *client);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_cistruct ib_sa_query;
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_civoid ib_sa_cancel_query(int id, struct ib_sa_query *query);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ciint ib_sa_path_rec_get(struct ib_sa_client *client, struct ib_device *device,
4268c2ecf20Sopenharmony_ci		       u8 port_num, struct sa_path_rec *rec,
4278c2ecf20Sopenharmony_ci		       ib_sa_comp_mask comp_mask, unsigned long timeout_ms,
4288c2ecf20Sopenharmony_ci		       gfp_t gfp_mask,
4298c2ecf20Sopenharmony_ci		       void (*callback)(int status, struct sa_path_rec *resp,
4308c2ecf20Sopenharmony_ci					void *context),
4318c2ecf20Sopenharmony_ci		       void *context, struct ib_sa_query **query);
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ciint ib_sa_service_rec_query(struct ib_sa_client *client,
4348c2ecf20Sopenharmony_ci			    struct ib_device *device, u8 port_num, u8 method,
4358c2ecf20Sopenharmony_ci			    struct ib_sa_service_rec *rec,
4368c2ecf20Sopenharmony_ci			    ib_sa_comp_mask comp_mask, unsigned long timeout_ms,
4378c2ecf20Sopenharmony_ci			    gfp_t gfp_mask,
4388c2ecf20Sopenharmony_ci			    void (*callback)(int status,
4398c2ecf20Sopenharmony_ci					     struct ib_sa_service_rec *resp,
4408c2ecf20Sopenharmony_ci					     void *context),
4418c2ecf20Sopenharmony_ci			    void *context, struct ib_sa_query **sa_query);
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistruct ib_sa_multicast {
4448c2ecf20Sopenharmony_ci	struct ib_sa_mcmember_rec rec;
4458c2ecf20Sopenharmony_ci	ib_sa_comp_mask		comp_mask;
4468c2ecf20Sopenharmony_ci	int			(*callback)(int status,
4478c2ecf20Sopenharmony_ci					    struct ib_sa_multicast *multicast);
4488c2ecf20Sopenharmony_ci	void			*context;
4498c2ecf20Sopenharmony_ci};
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci/**
4528c2ecf20Sopenharmony_ci * ib_sa_join_multicast - Initiates a join request to the specified multicast
4538c2ecf20Sopenharmony_ci *   group.
4548c2ecf20Sopenharmony_ci * @client: SA client
4558c2ecf20Sopenharmony_ci * @device: Device associated with the multicast group.
4568c2ecf20Sopenharmony_ci * @port_num: Port on the specified device to associate with the multicast
4578c2ecf20Sopenharmony_ci *   group.
4588c2ecf20Sopenharmony_ci * @rec: SA multicast member record specifying group attributes.
4598c2ecf20Sopenharmony_ci * @comp_mask: Component mask indicating which group attributes of %rec are
4608c2ecf20Sopenharmony_ci *   valid.
4618c2ecf20Sopenharmony_ci * @gfp_mask: GFP mask for memory allocations.
4628c2ecf20Sopenharmony_ci * @callback: User callback invoked once the join operation completes.
4638c2ecf20Sopenharmony_ci * @context: User specified context stored with the ib_sa_multicast structure.
4648c2ecf20Sopenharmony_ci *
4658c2ecf20Sopenharmony_ci * This call initiates a multicast join request with the SA for the specified
4668c2ecf20Sopenharmony_ci * multicast group.  If the join operation is started successfully, it returns
4678c2ecf20Sopenharmony_ci * an ib_sa_multicast structure that is used to track the multicast operation.
4688c2ecf20Sopenharmony_ci * Users must free this structure by calling ib_free_multicast, even if the
4698c2ecf20Sopenharmony_ci * join operation later fails.  (The callback status is non-zero.)
4708c2ecf20Sopenharmony_ci *
4718c2ecf20Sopenharmony_ci * If the join operation fails; status will be non-zero, with the following
4728c2ecf20Sopenharmony_ci * failures possible:
4738c2ecf20Sopenharmony_ci * -ETIMEDOUT: The request timed out.
4748c2ecf20Sopenharmony_ci * -EIO: An error occurred sending the query.
4758c2ecf20Sopenharmony_ci * -EINVAL: The MCMemberRecord values differed from the existing group's.
4768c2ecf20Sopenharmony_ci * -ENETRESET: Indicates that an fatal error has occurred on the multicast
4778c2ecf20Sopenharmony_ci *   group, and the user must rejoin the group to continue using it.
4788c2ecf20Sopenharmony_ci */
4798c2ecf20Sopenharmony_cistruct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client,
4808c2ecf20Sopenharmony_ci					     struct ib_device *device, u8 port_num,
4818c2ecf20Sopenharmony_ci					     struct ib_sa_mcmember_rec *rec,
4828c2ecf20Sopenharmony_ci					     ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
4838c2ecf20Sopenharmony_ci					     int (*callback)(int status,
4848c2ecf20Sopenharmony_ci							     struct ib_sa_multicast
4858c2ecf20Sopenharmony_ci								    *multicast),
4868c2ecf20Sopenharmony_ci					     void *context);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci/**
4898c2ecf20Sopenharmony_ci * ib_free_multicast - Frees the multicast tracking structure, and releases
4908c2ecf20Sopenharmony_ci *    any reference on the multicast group.
4918c2ecf20Sopenharmony_ci * @multicast: Multicast tracking structure allocated by ib_join_multicast.
4928c2ecf20Sopenharmony_ci *
4938c2ecf20Sopenharmony_ci * This call blocks until the multicast identifier is destroyed.  It may
4948c2ecf20Sopenharmony_ci * not be called from within the multicast callback; however, returning a non-
4958c2ecf20Sopenharmony_ci * zero value from the callback will result in destroying the multicast
4968c2ecf20Sopenharmony_ci * tracking structure.
4978c2ecf20Sopenharmony_ci */
4988c2ecf20Sopenharmony_civoid ib_sa_free_multicast(struct ib_sa_multicast *multicast);
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci/**
5018c2ecf20Sopenharmony_ci * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and
5028c2ecf20Sopenharmony_ci *   returns it if found.
5038c2ecf20Sopenharmony_ci * @device: Device associated with the multicast group.
5048c2ecf20Sopenharmony_ci * @port_num: Port on the specified device to associate with the multicast
5058c2ecf20Sopenharmony_ci *   group.
5068c2ecf20Sopenharmony_ci * @mgid: MGID of multicast group.
5078c2ecf20Sopenharmony_ci * @rec: Location to copy SA multicast member record.
5088c2ecf20Sopenharmony_ci */
5098c2ecf20Sopenharmony_ciint ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num,
5108c2ecf20Sopenharmony_ci			   union ib_gid *mgid, struct ib_sa_mcmember_rec *rec);
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci/**
5138c2ecf20Sopenharmony_ci * ib_init_ah_from_mcmember - Initialize address handle attributes based on
5148c2ecf20Sopenharmony_ci * an SA multicast member record.
5158c2ecf20Sopenharmony_ci */
5168c2ecf20Sopenharmony_ciint ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
5178c2ecf20Sopenharmony_ci			     struct ib_sa_mcmember_rec *rec,
5188c2ecf20Sopenharmony_ci			     struct net_device *ndev,
5198c2ecf20Sopenharmony_ci			     enum ib_gid_type gid_type,
5208c2ecf20Sopenharmony_ci			     struct rdma_ah_attr *ah_attr);
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ciint ib_init_ah_attr_from_path(struct ib_device *device, u8 port_num,
5238c2ecf20Sopenharmony_ci			      struct sa_path_rec *rec,
5248c2ecf20Sopenharmony_ci			      struct rdma_ah_attr *ah_attr,
5258c2ecf20Sopenharmony_ci			      const struct ib_gid_attr *sgid_attr);
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci/**
5288c2ecf20Sopenharmony_ci * ib_sa_pack_path - Conert a path record from struct ib_sa_path_rec
5298c2ecf20Sopenharmony_ci * to IB MAD wire format.
5308c2ecf20Sopenharmony_ci */
5318c2ecf20Sopenharmony_civoid ib_sa_pack_path(struct sa_path_rec *rec, void *attribute);
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci/**
5348c2ecf20Sopenharmony_ci * ib_sa_unpack_path - Convert a path record from MAD format to struct
5358c2ecf20Sopenharmony_ci * ib_sa_path_rec.
5368c2ecf20Sopenharmony_ci */
5378c2ecf20Sopenharmony_civoid ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci/* Support GuidInfoRecord */
5408c2ecf20Sopenharmony_ciint ib_sa_guid_info_rec_query(struct ib_sa_client *client,
5418c2ecf20Sopenharmony_ci			      struct ib_device *device, u8 port_num,
5428c2ecf20Sopenharmony_ci			      struct ib_sa_guidinfo_rec *rec,
5438c2ecf20Sopenharmony_ci			      ib_sa_comp_mask comp_mask, u8 method,
5448c2ecf20Sopenharmony_ci			      unsigned long timeout_ms, gfp_t gfp_mask,
5458c2ecf20Sopenharmony_ci			      void (*callback)(int status,
5468c2ecf20Sopenharmony_ci					       struct ib_sa_guidinfo_rec *resp,
5478c2ecf20Sopenharmony_ci					       void *context),
5488c2ecf20Sopenharmony_ci			      void *context, struct ib_sa_query **sa_query);
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_cibool ib_sa_sendonly_fullmem_support(struct ib_sa_client *client,
5518c2ecf20Sopenharmony_ci				    struct ib_device *device,
5528c2ecf20Sopenharmony_ci				    u8 port_num);
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_cistatic inline bool sa_path_is_roce(struct sa_path_rec *rec)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	return ((rec->rec_type == SA_PATH_REC_TYPE_ROCE_V1) ||
5578c2ecf20Sopenharmony_ci		(rec->rec_type == SA_PATH_REC_TYPE_ROCE_V2));
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistatic inline bool sa_path_is_opa(struct sa_path_rec *rec)
5618c2ecf20Sopenharmony_ci{
5628c2ecf20Sopenharmony_ci	return (rec->rec_type == SA_PATH_REC_TYPE_OPA);
5638c2ecf20Sopenharmony_ci}
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_cistatic inline void sa_path_set_slid(struct sa_path_rec *rec, u32 slid)
5668c2ecf20Sopenharmony_ci{
5678c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5688c2ecf20Sopenharmony_ci		rec->ib.slid = cpu_to_be16(slid);
5698c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5708c2ecf20Sopenharmony_ci		rec->opa.slid = cpu_to_be32(slid);
5718c2ecf20Sopenharmony_ci}
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_cistatic inline void sa_path_set_dlid(struct sa_path_rec *rec, u32 dlid)
5748c2ecf20Sopenharmony_ci{
5758c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5768c2ecf20Sopenharmony_ci		rec->ib.dlid = cpu_to_be16(dlid);
5778c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5788c2ecf20Sopenharmony_ci		rec->opa.dlid = cpu_to_be32(dlid);
5798c2ecf20Sopenharmony_ci}
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_cistatic inline void sa_path_set_raw_traffic(struct sa_path_rec *rec,
5828c2ecf20Sopenharmony_ci					   u8 raw_traffic)
5838c2ecf20Sopenharmony_ci{
5848c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5858c2ecf20Sopenharmony_ci		rec->ib.raw_traffic = raw_traffic;
5868c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5878c2ecf20Sopenharmony_ci		rec->opa.raw_traffic = raw_traffic;
5888c2ecf20Sopenharmony_ci}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_cistatic inline __be32 sa_path_get_slid(struct sa_path_rec *rec)
5918c2ecf20Sopenharmony_ci{
5928c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5938c2ecf20Sopenharmony_ci		return htonl(ntohs(rec->ib.slid));
5948c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5958c2ecf20Sopenharmony_ci		return rec->opa.slid;
5968c2ecf20Sopenharmony_ci	return 0;
5978c2ecf20Sopenharmony_ci}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_cistatic inline __be32 sa_path_get_dlid(struct sa_path_rec *rec)
6008c2ecf20Sopenharmony_ci{
6018c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
6028c2ecf20Sopenharmony_ci		return htonl(ntohs(rec->ib.dlid));
6038c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
6048c2ecf20Sopenharmony_ci		return rec->opa.dlid;
6058c2ecf20Sopenharmony_ci	return 0;
6068c2ecf20Sopenharmony_ci}
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_cistatic inline u8 sa_path_get_raw_traffic(struct sa_path_rec *rec)
6098c2ecf20Sopenharmony_ci{
6108c2ecf20Sopenharmony_ci	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
6118c2ecf20Sopenharmony_ci		return rec->ib.raw_traffic;
6128c2ecf20Sopenharmony_ci	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
6138c2ecf20Sopenharmony_ci		return rec->opa.raw_traffic;
6148c2ecf20Sopenharmony_ci	return 0;
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic inline void sa_path_set_dmac(struct sa_path_rec *rec, u8 *dmac)
6188c2ecf20Sopenharmony_ci{
6198c2ecf20Sopenharmony_ci	if (sa_path_is_roce(rec))
6208c2ecf20Sopenharmony_ci		memcpy(rec->roce.dmac, dmac, ETH_ALEN);
6218c2ecf20Sopenharmony_ci}
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_cistatic inline void sa_path_set_dmac_zero(struct sa_path_rec *rec)
6248c2ecf20Sopenharmony_ci{
6258c2ecf20Sopenharmony_ci	if (sa_path_is_roce(rec))
6268c2ecf20Sopenharmony_ci		eth_zero_addr(rec->roce.dmac);
6278c2ecf20Sopenharmony_ci}
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_cistatic inline u8 *sa_path_get_dmac(struct sa_path_rec *rec)
6308c2ecf20Sopenharmony_ci{
6318c2ecf20Sopenharmony_ci	if (sa_path_is_roce(rec))
6328c2ecf20Sopenharmony_ci		return rec->roce.dmac;
6338c2ecf20Sopenharmony_ci	return NULL;
6348c2ecf20Sopenharmony_ci}
6358c2ecf20Sopenharmony_ci#endif /* IB_SA_H */
636