xref: /linux/include/rdma/ib_sa.h (revision 1fb7f8973f51ca1a7ffe61a2c779ed15f57f3d82)
16bf9d8f6SLeon Romanovsky /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2a4d61e84SRoland Dreier /*
3a4d61e84SRoland Dreier  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
4a4d61e84SRoland Dreier  * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
5c1a0b23bSMichael S. Tsirkin  * Copyright (c) 2006 Intel Corporation.  All rights reserved.
6a4d61e84SRoland Dreier  */
7a4d61e84SRoland Dreier 
8a4d61e84SRoland Dreier #ifndef IB_SA_H
9a4d61e84SRoland Dreier #define IB_SA_H
10a4d61e84SRoland Dreier 
11c1a0b23bSMichael S. Tsirkin #include <linux/completion.h>
12a4d61e84SRoland Dreier #include <linux/compiler.h>
13a4d61e84SRoland Dreier 
1460063497SArun Sharma #include <linux/atomic.h>
15ba36e37fSMatan Barak #include <linux/netdevice.h>
16c1a0b23bSMichael S. Tsirkin 
17a4d61e84SRoland Dreier #include <rdma/ib_verbs.h>
18a4d61e84SRoland Dreier #include <rdma/ib_mad.h>
199fdca4daSDasaratharaman Chandramouli #include <rdma/ib_addr.h>
2057520751SDasaratharaman Chandramouli #include <rdma/opa_addr.h>
21a4d61e84SRoland Dreier 
22a4d61e84SRoland Dreier enum {
23a4d61e84SRoland Dreier 	IB_SA_CLASS_VERSION		= 2,	/* IB spec version 1.1/1.2 */
24a4d61e84SRoland Dreier 
25a4d61e84SRoland Dreier 	IB_SA_METHOD_GET_TABLE		= 0x12,
26a4d61e84SRoland Dreier 	IB_SA_METHOD_GET_TABLE_RESP	= 0x92,
271325cc79SHal Rosenstock 	IB_SA_METHOD_DELETE		= 0x15,
281325cc79SHal Rosenstock 	IB_SA_METHOD_DELETE_RESP	= 0x95,
291325cc79SHal Rosenstock 	IB_SA_METHOD_GET_MULTI		= 0x14,
301325cc79SHal Rosenstock 	IB_SA_METHOD_GET_MULTI_RESP	= 0x94,
311325cc79SHal Rosenstock 	IB_SA_METHOD_GET_TRACE_TBL	= 0x13
32a4d61e84SRoland Dreier };
33a4d61e84SRoland Dreier 
342196f271SDasaratharaman Chandramouli #define OPA_SA_CLASS_VERSION	0x80
35fbed8eeeSHal Rosenstock enum {
36fbed8eeeSHal Rosenstock 	IB_SA_ATTR_CLASS_PORTINFO    = 0x01,
37fbed8eeeSHal Rosenstock 	IB_SA_ATTR_NOTICE	     = 0x02,
38fbed8eeeSHal Rosenstock 	IB_SA_ATTR_INFORM_INFO	     = 0x03,
39fbed8eeeSHal Rosenstock 	IB_SA_ATTR_NODE_REC	     = 0x11,
40fbed8eeeSHal Rosenstock 	IB_SA_ATTR_PORT_INFO_REC     = 0x12,
41fbed8eeeSHal Rosenstock 	IB_SA_ATTR_SL2VL_REC	     = 0x13,
42fbed8eeeSHal Rosenstock 	IB_SA_ATTR_SWITCH_REC	     = 0x14,
43fbed8eeeSHal Rosenstock 	IB_SA_ATTR_LINEAR_FDB_REC    = 0x15,
44fbed8eeeSHal Rosenstock 	IB_SA_ATTR_RANDOM_FDB_REC    = 0x16,
45fbed8eeeSHal Rosenstock 	IB_SA_ATTR_MCAST_FDB_REC     = 0x17,
46fbed8eeeSHal Rosenstock 	IB_SA_ATTR_SM_INFO_REC	     = 0x18,
47fbed8eeeSHal Rosenstock 	IB_SA_ATTR_LINK_REC	     = 0x20,
48fbed8eeeSHal Rosenstock 	IB_SA_ATTR_GUID_INFO_REC     = 0x30,
49fbed8eeeSHal Rosenstock 	IB_SA_ATTR_SERVICE_REC	     = 0x31,
50fbed8eeeSHal Rosenstock 	IB_SA_ATTR_PARTITION_REC     = 0x33,
51fbed8eeeSHal Rosenstock 	IB_SA_ATTR_PATH_REC	     = 0x35,
52fbed8eeeSHal Rosenstock 	IB_SA_ATTR_VL_ARB_REC	     = 0x36,
53fbed8eeeSHal Rosenstock 	IB_SA_ATTR_MC_MEMBER_REC     = 0x38,
54fbed8eeeSHal Rosenstock 	IB_SA_ATTR_TRACE_REC	     = 0x39,
55fbed8eeeSHal Rosenstock 	IB_SA_ATTR_MULTI_PATH_REC    = 0x3a,
56fbed8eeeSHal Rosenstock 	IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b,
57fbed8eeeSHal Rosenstock 	IB_SA_ATTR_INFORM_INFO_REC   = 0xf3
58fbed8eeeSHal Rosenstock };
59fbed8eeeSHal Rosenstock 
60a4d61e84SRoland Dreier enum ib_sa_selector {
61aec79fccSMichael S. Tsirkin 	IB_SA_GT   = 0,
62aec79fccSMichael S. Tsirkin 	IB_SA_LT   = 1,
63a4d61e84SRoland Dreier 	IB_SA_EQ   = 2,
64a4d61e84SRoland Dreier 	/*
65a4d61e84SRoland Dreier 	 * The meaning of "best" depends on the attribute: for
66a4d61e84SRoland Dreier 	 * example, for MTU best will return the largest available
67a4d61e84SRoland Dreier 	 * MTU, while for packet life time, best will return the
68a4d61e84SRoland Dreier 	 * smallest available life time.
69a4d61e84SRoland Dreier 	 */
70a4d61e84SRoland Dreier 	IB_SA_BEST = 3
71a4d61e84SRoland Dreier };
72a4d61e84SRoland Dreier 
73ab15c95aSAlex Vesker /*
74ab15c95aSAlex Vesker  * There are 4 types of join states:
75ab15c95aSAlex Vesker  * FullMember, NonMember, SendOnlyNonMember, SendOnlyFullMember.
76ab15c95aSAlex Vesker  * The order corresponds to JoinState bits in MCMemberRecord.
77ab15c95aSAlex Vesker  */
78ab15c95aSAlex Vesker enum ib_sa_mc_join_states {
79ab15c95aSAlex Vesker 	FULLMEMBER_JOIN,
80ab15c95aSAlex Vesker 	NONMEMBER_JOIN,
81ab15c95aSAlex Vesker 	SENDONLY_NONMEBER_JOIN,
82ab15c95aSAlex Vesker 	SENDONLY_FULLMEMBER_JOIN,
83ab15c95aSAlex Vesker 	NUM_JOIN_MEMBERSHIP_TYPES,
84ab15c95aSAlex Vesker };
85ab15c95aSAlex Vesker 
86628e6f75SErez Shitrit #define IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT	BIT(12)
87628e6f75SErez Shitrit 
88a4d61e84SRoland Dreier /*
89a4d61e84SRoland Dreier  * Structures for SA records are named "struct ib_sa_xxx_rec."  No
90a4d61e84SRoland Dreier  * attempt is made to pack structures to match the physical layout of
91a4d61e84SRoland Dreier  * SA records in SA MADs; all packing and unpacking is handled by the
92a4d61e84SRoland Dreier  * SA query code.
93a4d61e84SRoland Dreier  *
94a4d61e84SRoland Dreier  * For a record with structure ib_sa_xxx_rec, the naming convention
95a4d61e84SRoland Dreier  * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we
96a4d61e84SRoland Dreier  * never use different abbreviations or otherwise change the spelling
97a4d61e84SRoland Dreier  * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY).
98a4d61e84SRoland Dreier  *
99a4d61e84SRoland Dreier  * Reserved rows are indicated with comments to help maintainability.
100a4d61e84SRoland Dreier  */
101a4d61e84SRoland Dreier 
102733d65feSSean Hefty #define IB_SA_PATH_REC_SERVICE_ID		       (IB_SA_COMP_MASK( 0) |\
103733d65feSSean Hefty 							IB_SA_COMP_MASK( 1))
104a4d61e84SRoland Dreier #define IB_SA_PATH_REC_DGID				IB_SA_COMP_MASK( 2)
105a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SGID				IB_SA_COMP_MASK( 3)
106a4d61e84SRoland Dreier #define IB_SA_PATH_REC_DLID				IB_SA_COMP_MASK( 4)
107a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SLID				IB_SA_COMP_MASK( 5)
108a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RAW_TRAFFIC			IB_SA_COMP_MASK( 6)
109a4d61e84SRoland Dreier /* reserved:								 7 */
110a4d61e84SRoland Dreier #define IB_SA_PATH_REC_FLOW_LABEL       		IB_SA_COMP_MASK( 8)
111a4d61e84SRoland Dreier #define IB_SA_PATH_REC_HOP_LIMIT			IB_SA_COMP_MASK( 9)
112a4d61e84SRoland Dreier #define IB_SA_PATH_REC_TRAFFIC_CLASS			IB_SA_COMP_MASK(10)
113a4d61e84SRoland Dreier #define IB_SA_PATH_REC_REVERSIBLE			IB_SA_COMP_MASK(11)
114a4d61e84SRoland Dreier #define IB_SA_PATH_REC_NUMB_PATH			IB_SA_COMP_MASK(12)
115a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PKEY				IB_SA_COMP_MASK(13)
116733d65feSSean Hefty #define IB_SA_PATH_REC_QOS_CLASS			IB_SA_COMP_MASK(14)
117a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SL				IB_SA_COMP_MASK(15)
118a4d61e84SRoland Dreier #define IB_SA_PATH_REC_MTU_SELECTOR			IB_SA_COMP_MASK(16)
119a4d61e84SRoland Dreier #define IB_SA_PATH_REC_MTU				IB_SA_COMP_MASK(17)
120a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RATE_SELECTOR			IB_SA_COMP_MASK(18)
121a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RATE				IB_SA_COMP_MASK(19)
122a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(20)
123a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PACKET_LIFE_TIME			IB_SA_COMP_MASK(21)
124a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PREFERENCE			IB_SA_COMP_MASK(22)
1259fdca4daSDasaratharaman Chandramouli 
126dfa834e1SDasaratharaman Chandramouli enum sa_path_rec_type {
127dfa834e1SDasaratharaman Chandramouli 	SA_PATH_REC_TYPE_IB,
128dfa834e1SDasaratharaman Chandramouli 	SA_PATH_REC_TYPE_ROCE_V1,
12957520751SDasaratharaman Chandramouli 	SA_PATH_REC_TYPE_ROCE_V2,
13057520751SDasaratharaman Chandramouli 	SA_PATH_REC_TYPE_OPA
131dfa834e1SDasaratharaman Chandramouli };
132a4d61e84SRoland Dreier 
1339fdca4daSDasaratharaman Chandramouli struct sa_path_rec_ib {
134a4d61e84SRoland Dreier 	__be16       dlid;
135a4d61e84SRoland Dreier 	__be16       slid;
13655efcfcdSJason Gunthorpe 	u8           raw_traffic;
1379fdca4daSDasaratharaman Chandramouli };
1389fdca4daSDasaratharaman Chandramouli 
139114cc9c4SParav Pandit /**
140114cc9c4SParav Pandit  * struct sa_path_rec_roce - RoCE specific portion of the path record entry
141114cc9c4SParav Pandit  * @route_resolved:	When set, it indicates that this route is already
142114cc9c4SParav Pandit  *			resolved for this path record entry.
143114cc9c4SParav Pandit  * @dmac:		Destination mac address for the given DGID entry
144114cc9c4SParav Pandit  *			of the path record entry.
145114cc9c4SParav Pandit  */
1469fdca4daSDasaratharaman Chandramouli struct sa_path_rec_roce {
147114cc9c4SParav Pandit 	bool	route_resolved;
1489fdca4daSDasaratharaman Chandramouli 	u8	dmac[ETH_ALEN];
1499fdca4daSDasaratharaman Chandramouli };
1509fdca4daSDasaratharaman Chandramouli 
15157520751SDasaratharaman Chandramouli struct sa_path_rec_opa {
15257520751SDasaratharaman Chandramouli 	__be32       dlid;
15357520751SDasaratharaman Chandramouli 	__be32       slid;
15457520751SDasaratharaman Chandramouli 	u8           raw_traffic;
15557520751SDasaratharaman Chandramouli 	u8	     l2_8B;
15657520751SDasaratharaman Chandramouli 	u8	     l2_10B;
15757520751SDasaratharaman Chandramouli 	u8	     l2_9B;
15857520751SDasaratharaman Chandramouli 	u8	     l2_16B;
15957520751SDasaratharaman Chandramouli 	u8	     qos_type;
16057520751SDasaratharaman Chandramouli 	u8	     qos_priority;
16157520751SDasaratharaman Chandramouli };
16257520751SDasaratharaman Chandramouli 
1639fdca4daSDasaratharaman Chandramouli struct sa_path_rec {
1649fdca4daSDasaratharaman Chandramouli 	union ib_gid dgid;
1659fdca4daSDasaratharaman Chandramouli 	union ib_gid sgid;
166d3957b86SMajd Dibbiny 	__be64       service_id;
167a4d61e84SRoland Dreier 	/* reserved */
168a4d61e84SRoland Dreier 	__be32       flow_label;
169a4d61e84SRoland Dreier 	u8           hop_limit;
170a4d61e84SRoland Dreier 	u8           traffic_class;
17155efcfcdSJason Gunthorpe 	u8           reversible;
172a4d61e84SRoland Dreier 	u8           numb_path;
173a4d61e84SRoland Dreier 	__be16       pkey;
174733d65feSSean Hefty 	__be16       qos_class;
175a4d61e84SRoland Dreier 	u8           sl;
176a4d61e84SRoland Dreier 	u8           mtu_selector;
177a4d61e84SRoland Dreier 	u8           mtu;
178a4d61e84SRoland Dreier 	u8           rate_selector;
179a4d61e84SRoland Dreier 	u8           rate;
180a4d61e84SRoland Dreier 	u8           packet_life_time_selector;
181a4d61e84SRoland Dreier 	u8           packet_life_time;
182a4d61e84SRoland Dreier 	u8           preference;
1839fdca4daSDasaratharaman Chandramouli 	union {
1849fdca4daSDasaratharaman Chandramouli 		struct sa_path_rec_ib ib;
1859fdca4daSDasaratharaman Chandramouli 		struct sa_path_rec_roce roce;
18657520751SDasaratharaman Chandramouli 		struct sa_path_rec_opa opa;
1879fdca4daSDasaratharaman Chandramouli 	};
188dfa834e1SDasaratharaman Chandramouli 	enum sa_path_rec_type rec_type;
189a4d61e84SRoland Dreier };
190a4d61e84SRoland Dreier 
191dfa834e1SDasaratharaman Chandramouli static inline enum ib_gid_type
192dfa834e1SDasaratharaman Chandramouli 		sa_conv_pathrec_to_gid_type(struct sa_path_rec *rec)
193dfa834e1SDasaratharaman Chandramouli {
194dfa834e1SDasaratharaman Chandramouli 	switch (rec->rec_type) {
195dfa834e1SDasaratharaman Chandramouli 	case SA_PATH_REC_TYPE_ROCE_V1:
196dfa834e1SDasaratharaman Chandramouli 		return IB_GID_TYPE_ROCE;
197dfa834e1SDasaratharaman Chandramouli 	case SA_PATH_REC_TYPE_ROCE_V2:
198dfa834e1SDasaratharaman Chandramouli 		return IB_GID_TYPE_ROCE_UDP_ENCAP;
199dfa834e1SDasaratharaman Chandramouli 	default:
200dfa834e1SDasaratharaman Chandramouli 		return IB_GID_TYPE_IB;
201dfa834e1SDasaratharaman Chandramouli 	}
202dfa834e1SDasaratharaman Chandramouli }
203dfa834e1SDasaratharaman Chandramouli 
204dfa834e1SDasaratharaman Chandramouli static inline enum sa_path_rec_type
205dfa834e1SDasaratharaman Chandramouli 		sa_conv_gid_to_pathrec_type(enum ib_gid_type type)
206dfa834e1SDasaratharaman Chandramouli {
207dfa834e1SDasaratharaman Chandramouli 	switch (type) {
208dfa834e1SDasaratharaman Chandramouli 	case IB_GID_TYPE_ROCE:
209dfa834e1SDasaratharaman Chandramouli 		return SA_PATH_REC_TYPE_ROCE_V1;
210dfa834e1SDasaratharaman Chandramouli 	case IB_GID_TYPE_ROCE_UDP_ENCAP:
211dfa834e1SDasaratharaman Chandramouli 		return SA_PATH_REC_TYPE_ROCE_V2;
212dfa834e1SDasaratharaman Chandramouli 	default:
213dfa834e1SDasaratharaman Chandramouli 		return SA_PATH_REC_TYPE_IB;
214dfa834e1SDasaratharaman Chandramouli 	}
215dfa834e1SDasaratharaman Chandramouli }
216dfa834e1SDasaratharaman Chandramouli 
21757520751SDasaratharaman Chandramouli static inline void path_conv_opa_to_ib(struct sa_path_rec *ib,
21857520751SDasaratharaman Chandramouli 				       struct sa_path_rec *opa)
21957520751SDasaratharaman Chandramouli {
22057520751SDasaratharaman Chandramouli 	if ((be32_to_cpu(opa->opa.dlid) >=
22157520751SDasaratharaman Chandramouli 	     be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
22257520751SDasaratharaman Chandramouli 	    (be32_to_cpu(opa->opa.slid) >=
22357520751SDasaratharaman Chandramouli 	     be16_to_cpu(IB_MULTICAST_LID_BASE))) {
22457520751SDasaratharaman Chandramouli 		/* Create OPA GID and zero out the LID */
22557520751SDasaratharaman Chandramouli 		ib->dgid.global.interface_id
22657520751SDasaratharaman Chandramouli 				= OPA_MAKE_ID(be32_to_cpu(opa->opa.dlid));
22757520751SDasaratharaman Chandramouli 		ib->dgid.global.subnet_prefix
22857520751SDasaratharaman Chandramouli 				= opa->dgid.global.subnet_prefix;
22957520751SDasaratharaman Chandramouli 		ib->sgid.global.interface_id
23057520751SDasaratharaman Chandramouli 				= OPA_MAKE_ID(be32_to_cpu(opa->opa.slid));
23157520751SDasaratharaman Chandramouli 		ib->dgid.global.subnet_prefix
23257520751SDasaratharaman Chandramouli 				= opa->dgid.global.subnet_prefix;
23357520751SDasaratharaman Chandramouli 		ib->ib.dlid	= 0;
23457520751SDasaratharaman Chandramouli 
23557520751SDasaratharaman Chandramouli 		ib->ib.slid	= 0;
23657520751SDasaratharaman Chandramouli 	} else {
23757520751SDasaratharaman Chandramouli 		ib->ib.dlid	= htons(ntohl(opa->opa.dlid));
23857520751SDasaratharaman Chandramouli 		ib->ib.slid	= htons(ntohl(opa->opa.slid));
23957520751SDasaratharaman Chandramouli 	}
240d3957b86SMajd Dibbiny 	ib->service_id		= opa->service_id;
24157520751SDasaratharaman Chandramouli 	ib->ib.raw_traffic	= opa->opa.raw_traffic;
24257520751SDasaratharaman Chandramouli }
24357520751SDasaratharaman Chandramouli 
24457520751SDasaratharaman Chandramouli static inline void path_conv_ib_to_opa(struct sa_path_rec *opa,
24557520751SDasaratharaman Chandramouli 				       struct sa_path_rec *ib)
24657520751SDasaratharaman Chandramouli {
24757520751SDasaratharaman Chandramouli 	__be32 slid, dlid;
24857520751SDasaratharaman Chandramouli 
24957520751SDasaratharaman Chandramouli 	if ((ib_is_opa_gid(&ib->sgid)) ||
25057520751SDasaratharaman Chandramouli 	    (ib_is_opa_gid(&ib->dgid))) {
25157520751SDasaratharaman Chandramouli 		slid = htonl(opa_get_lid_from_gid(&ib->sgid));
25257520751SDasaratharaman Chandramouli 		dlid = htonl(opa_get_lid_from_gid(&ib->dgid));
25357520751SDasaratharaman Chandramouli 	} else {
25457520751SDasaratharaman Chandramouli 		slid = htonl(ntohs(ib->ib.slid));
25557520751SDasaratharaman Chandramouli 		dlid = htonl(ntohs(ib->ib.dlid));
25657520751SDasaratharaman Chandramouli 	}
25757520751SDasaratharaman Chandramouli 	opa->opa.slid		= slid;
25857520751SDasaratharaman Chandramouli 	opa->opa.dlid		= dlid;
259d3957b86SMajd Dibbiny 	opa->service_id		= ib->service_id;
26057520751SDasaratharaman Chandramouli 	opa->opa.raw_traffic	= ib->ib.raw_traffic;
26157520751SDasaratharaman Chandramouli }
26257520751SDasaratharaman Chandramouli 
26357520751SDasaratharaman Chandramouli /* Convert from OPA to IB path record */
26457520751SDasaratharaman Chandramouli static inline void sa_convert_path_opa_to_ib(struct sa_path_rec *dest,
26557520751SDasaratharaman Chandramouli 					     struct sa_path_rec *src)
26657520751SDasaratharaman Chandramouli {
26757520751SDasaratharaman Chandramouli 	if (src->rec_type != SA_PATH_REC_TYPE_OPA)
26857520751SDasaratharaman Chandramouli 		return;
26957520751SDasaratharaman Chandramouli 
27057520751SDasaratharaman Chandramouli 	*dest = *src;
27157520751SDasaratharaman Chandramouli 	dest->rec_type = SA_PATH_REC_TYPE_IB;
27257520751SDasaratharaman Chandramouli 	path_conv_opa_to_ib(dest, src);
27357520751SDasaratharaman Chandramouli }
27457520751SDasaratharaman Chandramouli 
27557520751SDasaratharaman Chandramouli /* Convert from IB to OPA path record */
27657520751SDasaratharaman Chandramouli static inline void sa_convert_path_ib_to_opa(struct sa_path_rec *dest,
27757520751SDasaratharaman Chandramouli 					     struct sa_path_rec *src)
27857520751SDasaratharaman Chandramouli {
27957520751SDasaratharaman Chandramouli 	if (src->rec_type != SA_PATH_REC_TYPE_IB)
28057520751SDasaratharaman Chandramouli 		return;
28157520751SDasaratharaman Chandramouli 
28257520751SDasaratharaman Chandramouli 	/* Do a structure copy and overwrite the relevant fields */
28357520751SDasaratharaman Chandramouli 	*dest = *src;
28457520751SDasaratharaman Chandramouli 	dest->rec_type = SA_PATH_REC_TYPE_OPA;
28557520751SDasaratharaman Chandramouli 	path_conv_ib_to_opa(dest, src);
28657520751SDasaratharaman Chandramouli }
28757520751SDasaratharaman Chandramouli 
288a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MGID				IB_SA_COMP_MASK( 0)
289a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PORT_GID			IB_SA_COMP_MASK( 1)
290a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_QKEY				IB_SA_COMP_MASK( 2)
291a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MLID				IB_SA_COMP_MASK( 3)
292a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU_SELECTOR			IB_SA_COMP_MASK( 4)
293a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU				IB_SA_COMP_MASK( 5)
294a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS		IB_SA_COMP_MASK( 6)
295a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PKEY				IB_SA_COMP_MASK( 7)
296a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE_SELECTOR		IB_SA_COMP_MASK( 8)
297a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE				IB_SA_COMP_MASK( 9)
298a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(10)
299a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME		IB_SA_COMP_MASK(11)
300a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SL				IB_SA_COMP_MASK(12)
301a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_FLOW_LABEL			IB_SA_COMP_MASK(13)
302a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_HOP_LIMIT			IB_SA_COMP_MASK(14)
303a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SCOPE			IB_SA_COMP_MASK(15)
304a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_JOIN_STATE			IB_SA_COMP_MASK(16)
305a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PROXY_JOIN			IB_SA_COMP_MASK(17)
306a4d61e84SRoland Dreier 
307a4d61e84SRoland Dreier struct ib_sa_mcmember_rec {
308a4d61e84SRoland Dreier 	union ib_gid mgid;
309a4d61e84SRoland Dreier 	union ib_gid port_gid;
310a4d61e84SRoland Dreier 	__be32       qkey;
311a4d61e84SRoland Dreier 	__be16       mlid;
312a4d61e84SRoland Dreier 	u8           mtu_selector;
313a4d61e84SRoland Dreier 	u8           mtu;
314a4d61e84SRoland Dreier 	u8           traffic_class;
315a4d61e84SRoland Dreier 	__be16       pkey;
316a4d61e84SRoland Dreier 	u8 	     rate_selector;
317a4d61e84SRoland Dreier 	u8 	     rate;
318a4d61e84SRoland Dreier 	u8 	     packet_life_time_selector;
319a4d61e84SRoland Dreier 	u8 	     packet_life_time;
320a4d61e84SRoland Dreier 	u8           sl;
321a4d61e84SRoland Dreier 	__be32       flow_label;
322a4d61e84SRoland Dreier 	u8           hop_limit;
323a4d61e84SRoland Dreier 	u8           scope;
324a4d61e84SRoland Dreier 	u8           join_state;
32555efcfcdSJason Gunthorpe 	u8           proxy_join;
326a4d61e84SRoland Dreier };
327a4d61e84SRoland Dreier 
328a4d61e84SRoland Dreier /* Service Record Component Mask Sec 15.2.5.14 Ver 1.1	*/
329a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_ID			IB_SA_COMP_MASK( 0)
330a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_GID			IB_SA_COMP_MASK( 1)
331a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_PKEY			IB_SA_COMP_MASK( 2)
332a4d61e84SRoland Dreier /* reserved:								 3 */
333a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_LEASE			IB_SA_COMP_MASK( 4)
334a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_KEY			IB_SA_COMP_MASK( 5)
335a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_NAME			IB_SA_COMP_MASK( 6)
336a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_0		IB_SA_COMP_MASK( 7)
337a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_1		IB_SA_COMP_MASK( 8)
338a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_2		IB_SA_COMP_MASK( 9)
339a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_3		IB_SA_COMP_MASK(10)
340a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_4		IB_SA_COMP_MASK(11)
341a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_5		IB_SA_COMP_MASK(12)
342a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_6		IB_SA_COMP_MASK(13)
343a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_7		IB_SA_COMP_MASK(14)
344a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_8		IB_SA_COMP_MASK(15)
345a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_9		IB_SA_COMP_MASK(16)
346a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_10		IB_SA_COMP_MASK(17)
347a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_11		IB_SA_COMP_MASK(18)
348a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_12		IB_SA_COMP_MASK(19)
349a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_13		IB_SA_COMP_MASK(20)
350a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_14		IB_SA_COMP_MASK(21)
351a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_15		IB_SA_COMP_MASK(22)
352a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_0		IB_SA_COMP_MASK(23)
353a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_1		IB_SA_COMP_MASK(24)
354a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_2		IB_SA_COMP_MASK(25)
355a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_3		IB_SA_COMP_MASK(26)
356a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_4		IB_SA_COMP_MASK(27)
357a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_5		IB_SA_COMP_MASK(28)
358a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_6		IB_SA_COMP_MASK(29)
359a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_7		IB_SA_COMP_MASK(30)
360a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_0		IB_SA_COMP_MASK(31)
361a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_1		IB_SA_COMP_MASK(32)
362a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_2		IB_SA_COMP_MASK(33)
363a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_3		IB_SA_COMP_MASK(34)
364a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_0		IB_SA_COMP_MASK(35)
365a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_1		IB_SA_COMP_MASK(36)
366a4d61e84SRoland Dreier 
367a4d61e84SRoland Dreier #define IB_DEFAULT_SERVICE_LEASE 	0xFFFFFFFF
368a4d61e84SRoland Dreier 
369a4d61e84SRoland Dreier struct ib_sa_service_rec {
370a4d61e84SRoland Dreier 	u64		id;
371a4d61e84SRoland Dreier 	union ib_gid	gid;
372a4d61e84SRoland Dreier 	__be16 		pkey;
373a4d61e84SRoland Dreier 	/* reserved */
374a4d61e84SRoland Dreier 	u32		lease;
375a4d61e84SRoland Dreier 	u8		key[16];
376a4d61e84SRoland Dreier 	u8		name[64];
377a4d61e84SRoland Dreier 	u8		data8[16];
378a4d61e84SRoland Dreier 	u16		data16[8];
379a4d61e84SRoland Dreier 	u32		data32[4];
380a4d61e84SRoland Dreier 	u64		data64[2];
381a4d61e84SRoland Dreier };
382a4d61e84SRoland Dreier 
383aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_LID		IB_SA_COMP_MASK(0)
384aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_BLOCK_NUM	IB_SA_COMP_MASK(1)
385aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES1		IB_SA_COMP_MASK(2)
386aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES2		IB_SA_COMP_MASK(3)
387aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID0		IB_SA_COMP_MASK(4)
388aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID1		IB_SA_COMP_MASK(5)
389aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID2		IB_SA_COMP_MASK(6)
390aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID3		IB_SA_COMP_MASK(7)
391aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID4		IB_SA_COMP_MASK(8)
392aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID5		IB_SA_COMP_MASK(9)
393aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID6		IB_SA_COMP_MASK(10)
394aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID7		IB_SA_COMP_MASK(11)
395aeab97edSErez Shitrit 
396aeab97edSErez Shitrit struct ib_sa_guidinfo_rec {
397aeab97edSErez Shitrit 	__be16	lid;
398aeab97edSErez Shitrit 	u8	block_num;
399aeab97edSErez Shitrit 	/* reserved */
400aeab97edSErez Shitrit 	u8	res1;
401aeab97edSErez Shitrit 	__be32	res2;
402aeab97edSErez Shitrit 	u8	guid_info_list[64];
403aeab97edSErez Shitrit };
404aeab97edSErez Shitrit 
405c1a0b23bSMichael S. Tsirkin struct ib_sa_client {
406c1a0b23bSMichael S. Tsirkin 	atomic_t users;
407c1a0b23bSMichael S. Tsirkin 	struct completion comp;
408c1a0b23bSMichael S. Tsirkin };
409c1a0b23bSMichael S. Tsirkin 
410c1a0b23bSMichael S. Tsirkin /**
411c1a0b23bSMichael S. Tsirkin  * ib_sa_register_client - Register an SA client.
412c1a0b23bSMichael S. Tsirkin  */
413c1a0b23bSMichael S. Tsirkin void ib_sa_register_client(struct ib_sa_client *client);
414c1a0b23bSMichael S. Tsirkin 
415c1a0b23bSMichael S. Tsirkin /**
416c1a0b23bSMichael S. Tsirkin  * ib_sa_unregister_client - Deregister an SA client.
417c1a0b23bSMichael S. Tsirkin  * @client: Client object to deregister.
418c1a0b23bSMichael S. Tsirkin  */
419c1a0b23bSMichael S. Tsirkin void ib_sa_unregister_client(struct ib_sa_client *client);
420c1a0b23bSMichael S. Tsirkin 
421a4d61e84SRoland Dreier struct ib_sa_query;
422a4d61e84SRoland Dreier 
423a4d61e84SRoland Dreier void ib_sa_cancel_query(int id, struct ib_sa_query *query);
424a4d61e84SRoland Dreier 
4259549c2bdSLeon Romanovsky int ib_sa_path_rec_get(struct ib_sa_client *client, struct ib_device *device,
426*1fb7f897SMark Bloch 		       u32 port_num, struct sa_path_rec *rec,
427dbace111SLeon Romanovsky 		       ib_sa_comp_mask comp_mask, unsigned long timeout_ms,
4289549c2bdSLeon Romanovsky 		       gfp_t gfp_mask,
4299549c2bdSLeon Romanovsky 		       void (*callback)(int status, struct sa_path_rec *resp,
430a4d61e84SRoland Dreier 					void *context),
4319549c2bdSLeon Romanovsky 		       void *context, struct ib_sa_query **query);
432a4d61e84SRoland Dreier 
433c1a0b23bSMichael S. Tsirkin int ib_sa_service_rec_query(struct ib_sa_client *client,
434*1fb7f897SMark Bloch 			    struct ib_device *device, u32 port_num, u8 method,
435a4d61e84SRoland Dreier 			    struct ib_sa_service_rec *rec,
436dbace111SLeon Romanovsky 			    ib_sa_comp_mask comp_mask, unsigned long timeout_ms,
4379549c2bdSLeon Romanovsky 			    gfp_t gfp_mask,
438a4d61e84SRoland Dreier 			    void (*callback)(int status,
439a4d61e84SRoland Dreier 					     struct ib_sa_service_rec *resp,
440a4d61e84SRoland Dreier 					     void *context),
4419549c2bdSLeon Romanovsky 			    void *context, struct ib_sa_query **sa_query);
442a4d61e84SRoland Dreier 
443faec2f7bSSean Hefty struct ib_sa_multicast {
444faec2f7bSSean Hefty 	struct ib_sa_mcmember_rec rec;
445faec2f7bSSean Hefty 	ib_sa_comp_mask		comp_mask;
446faec2f7bSSean Hefty 	int			(*callback)(int status,
447faec2f7bSSean Hefty 					    struct ib_sa_multicast *multicast);
448faec2f7bSSean Hefty 	void			*context;
449faec2f7bSSean Hefty };
450a4d61e84SRoland Dreier 
451a4d61e84SRoland Dreier /**
452faec2f7bSSean Hefty  * ib_sa_join_multicast - Initiates a join request to the specified multicast
453faec2f7bSSean Hefty  *   group.
454c1a0b23bSMichael S. Tsirkin  * @client: SA client
455faec2f7bSSean Hefty  * @device: Device associated with the multicast group.
456faec2f7bSSean Hefty  * @port_num: Port on the specified device to associate with the multicast
457faec2f7bSSean Hefty  *   group.
458faec2f7bSSean Hefty  * @rec: SA multicast member record specifying group attributes.
459faec2f7bSSean Hefty  * @comp_mask: Component mask indicating which group attributes of %rec are
460faec2f7bSSean Hefty  *   valid.
461faec2f7bSSean Hefty  * @gfp_mask: GFP mask for memory allocations.
462faec2f7bSSean Hefty  * @callback: User callback invoked once the join operation completes.
463faec2f7bSSean Hefty  * @context: User specified context stored with the ib_sa_multicast structure.
464a4d61e84SRoland Dreier  *
465faec2f7bSSean Hefty  * This call initiates a multicast join request with the SA for the specified
466faec2f7bSSean Hefty  * multicast group.  If the join operation is started successfully, it returns
467faec2f7bSSean Hefty  * an ib_sa_multicast structure that is used to track the multicast operation.
468faec2f7bSSean Hefty  * Users must free this structure by calling ib_free_multicast, even if the
469faec2f7bSSean Hefty  * join operation later fails.  (The callback status is non-zero.)
470a4d61e84SRoland Dreier  *
471faec2f7bSSean Hefty  * If the join operation fails; status will be non-zero, with the following
472faec2f7bSSean Hefty  * failures possible:
473faec2f7bSSean Hefty  * -ETIMEDOUT: The request timed out.
474faec2f7bSSean Hefty  * -EIO: An error occurred sending the query.
475faec2f7bSSean Hefty  * -EINVAL: The MCMemberRecord values differed from the existing group's.
476faec2f7bSSean Hefty  * -ENETRESET: Indicates that an fatal error has occurred on the multicast
477faec2f7bSSean Hefty  *   group, and the user must rejoin the group to continue using it.
478a4d61e84SRoland Dreier  */
479faec2f7bSSean Hefty struct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client,
480*1fb7f897SMark Bloch 					     struct ib_device *device,
481*1fb7f897SMark Bloch 					     u32 port_num,
482a4d61e84SRoland Dreier 					     struct ib_sa_mcmember_rec *rec,
483faec2f7bSSean Hefty 					     ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
484faec2f7bSSean Hefty 					     int (*callback)(int status,
485faec2f7bSSean Hefty 							     struct ib_sa_multicast
486faec2f7bSSean Hefty 								    *multicast),
487faec2f7bSSean Hefty 					     void *context);
488faec2f7bSSean Hefty 
489faec2f7bSSean Hefty /**
490faec2f7bSSean Hefty  * ib_free_multicast - Frees the multicast tracking structure, and releases
491faec2f7bSSean Hefty  *    any reference on the multicast group.
492faec2f7bSSean Hefty  * @multicast: Multicast tracking structure allocated by ib_join_multicast.
493faec2f7bSSean Hefty  *
494faec2f7bSSean Hefty  * This call blocks until the multicast identifier is destroyed.  It may
495faec2f7bSSean Hefty  * not be called from within the multicast callback; however, returning a non-
496faec2f7bSSean Hefty  * zero value from the callback will result in destroying the multicast
497faec2f7bSSean Hefty  * tracking structure.
498faec2f7bSSean Hefty  */
499faec2f7bSSean Hefty void ib_sa_free_multicast(struct ib_sa_multicast *multicast);
500faec2f7bSSean Hefty 
501faec2f7bSSean Hefty /**
502faec2f7bSSean Hefty  * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and
503faec2f7bSSean Hefty  *   returns it if found.
504faec2f7bSSean Hefty  * @device: Device associated with the multicast group.
505faec2f7bSSean Hefty  * @port_num: Port on the specified device to associate with the multicast
506faec2f7bSSean Hefty  *   group.
507faec2f7bSSean Hefty  * @mgid: MGID of multicast group.
508faec2f7bSSean Hefty  * @rec: Location to copy SA multicast member record.
509faec2f7bSSean Hefty  */
510*1fb7f897SMark Bloch int ib_sa_get_mcmember_rec(struct ib_device *device, u32 port_num,
511faec2f7bSSean Hefty 			   union ib_gid *mgid, struct ib_sa_mcmember_rec *rec);
512faec2f7bSSean Hefty 
513faec2f7bSSean Hefty /**
514faec2f7bSSean Hefty  * ib_init_ah_from_mcmember - Initialize address handle attributes based on
515faec2f7bSSean Hefty  * an SA multicast member record.
516faec2f7bSSean Hefty  */
517*1fb7f897SMark Bloch int ib_init_ah_from_mcmember(struct ib_device *device, u32 port_num,
518faec2f7bSSean Hefty 			     struct ib_sa_mcmember_rec *rec,
519bee3c3c9SMoni Shoua 			     struct net_device *ndev,
520bee3c3c9SMoni Shoua 			     enum ib_gid_type gid_type,
52190898850SDasaratharaman Chandramouli 			     struct rdma_ah_attr *ah_attr);
522a4d61e84SRoland Dreier 
523*1fb7f897SMark Bloch int ib_init_ah_attr_from_path(struct ib_device *device, u32 port_num,
524c2f8fc4eSDasaratharaman Chandramouli 			      struct sa_path_rec *rec,
52539839107SParav Pandit 			      struct rdma_ah_attr *ah_attr,
52639839107SParav Pandit 			      const struct ib_gid_attr *sgid_attr);
527a4d61e84SRoland Dreier 
528a7ca1f00SSean Hefty /**
5292e08b587SSean Hefty  * ib_sa_pack_path - Conert a path record from struct ib_sa_path_rec
5302e08b587SSean Hefty  * to IB MAD wire format.
5312e08b587SSean Hefty  */
532c2f8fc4eSDasaratharaman Chandramouli void ib_sa_pack_path(struct sa_path_rec *rec, void *attribute);
5332e08b587SSean Hefty 
5342e08b587SSean Hefty /**
535a7ca1f00SSean Hefty  * ib_sa_unpack_path - Convert a path record from MAD format to struct
536a7ca1f00SSean Hefty  * ib_sa_path_rec.
537a7ca1f00SSean Hefty  */
538c2f8fc4eSDasaratharaman Chandramouli void ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec);
539a7ca1f00SSean Hefty 
540aeab97edSErez Shitrit /* Support GuidInfoRecord */
541aeab97edSErez Shitrit int ib_sa_guid_info_rec_query(struct ib_sa_client *client,
542*1fb7f897SMark Bloch 			      struct ib_device *device, u32 port_num,
543aeab97edSErez Shitrit 			      struct ib_sa_guidinfo_rec *rec,
544aeab97edSErez Shitrit 			      ib_sa_comp_mask comp_mask, u8 method,
545dbace111SLeon Romanovsky 			      unsigned long timeout_ms, gfp_t gfp_mask,
546aeab97edSErez Shitrit 			      void (*callback)(int status,
547aeab97edSErez Shitrit 					       struct ib_sa_guidinfo_rec *resp,
548aeab97edSErez Shitrit 					       void *context),
5499549c2bdSLeon Romanovsky 			      void *context, struct ib_sa_query **sa_query);
5502e08b587SSean Hefty 
5519fdca4daSDasaratharaman Chandramouli static inline bool sa_path_is_roce(struct sa_path_rec *rec)
5529fdca4daSDasaratharaman Chandramouli {
5539fdca4daSDasaratharaman Chandramouli 	return ((rec->rec_type == SA_PATH_REC_TYPE_ROCE_V1) ||
5549fdca4daSDasaratharaman Chandramouli 		(rec->rec_type == SA_PATH_REC_TYPE_ROCE_V2));
5559fdca4daSDasaratharaman Chandramouli }
5569fdca4daSDasaratharaman Chandramouli 
5570a514159SParav Pandit static inline bool sa_path_is_opa(struct sa_path_rec *rec)
5580a514159SParav Pandit {
5590a514159SParav Pandit 	return (rec->rec_type == SA_PATH_REC_TYPE_OPA);
5600a514159SParav Pandit }
5610a514159SParav Pandit 
5629d187177SBart Van Assche static inline void sa_path_set_slid(struct sa_path_rec *rec, u32 slid)
5639fdca4daSDasaratharaman Chandramouli {
5649fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5659d187177SBart Van Assche 		rec->ib.slid = cpu_to_be16(slid);
56657520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5679d187177SBart Van Assche 		rec->opa.slid = cpu_to_be32(slid);
5689fdca4daSDasaratharaman Chandramouli }
5699fdca4daSDasaratharaman Chandramouli 
5709d187177SBart Van Assche static inline void sa_path_set_dlid(struct sa_path_rec *rec, u32 dlid)
5719fdca4daSDasaratharaman Chandramouli {
5729fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5739d187177SBart Van Assche 		rec->ib.dlid = cpu_to_be16(dlid);
57457520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
5759d187177SBart Van Assche 		rec->opa.dlid = cpu_to_be32(dlid);
5769fdca4daSDasaratharaman Chandramouli }
5779fdca4daSDasaratharaman Chandramouli 
5789fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_raw_traffic(struct sa_path_rec *rec,
5799fdca4daSDasaratharaman Chandramouli 					   u8 raw_traffic)
5809fdca4daSDasaratharaman Chandramouli {
5819fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
5829fdca4daSDasaratharaman Chandramouli 		rec->ib.raw_traffic = raw_traffic;
58357520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
58457520751SDasaratharaman Chandramouli 		rec->opa.raw_traffic = raw_traffic;
5859fdca4daSDasaratharaman Chandramouli }
5869fdca4daSDasaratharaman Chandramouli 
58757520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_slid(struct sa_path_rec *rec)
5889fdca4daSDasaratharaman Chandramouli {
5899fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
59057520751SDasaratharaman Chandramouli 		return htonl(ntohs(rec->ib.slid));
59157520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
59257520751SDasaratharaman Chandramouli 		return rec->opa.slid;
5939fdca4daSDasaratharaman Chandramouli 	return 0;
5949fdca4daSDasaratharaman Chandramouli }
5959fdca4daSDasaratharaman Chandramouli 
59657520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_dlid(struct sa_path_rec *rec)
5979fdca4daSDasaratharaman Chandramouli {
5989fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
59957520751SDasaratharaman Chandramouli 		return htonl(ntohs(rec->ib.dlid));
60057520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
60157520751SDasaratharaman Chandramouli 		return rec->opa.dlid;
6029fdca4daSDasaratharaman Chandramouli 	return 0;
6039fdca4daSDasaratharaman Chandramouli }
6049fdca4daSDasaratharaman Chandramouli 
6059fdca4daSDasaratharaman Chandramouli static inline u8 sa_path_get_raw_traffic(struct sa_path_rec *rec)
6069fdca4daSDasaratharaman Chandramouli {
6079fdca4daSDasaratharaman Chandramouli 	if (rec->rec_type == SA_PATH_REC_TYPE_IB)
6089fdca4daSDasaratharaman Chandramouli 		return rec->ib.raw_traffic;
60957520751SDasaratharaman Chandramouli 	else if (rec->rec_type == SA_PATH_REC_TYPE_OPA)
61057520751SDasaratharaman Chandramouli 		return rec->opa.raw_traffic;
6119fdca4daSDasaratharaman Chandramouli 	return 0;
6129fdca4daSDasaratharaman Chandramouli }
6139fdca4daSDasaratharaman Chandramouli 
6149fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac(struct sa_path_rec *rec, u8 *dmac)
6159fdca4daSDasaratharaman Chandramouli {
6169fdca4daSDasaratharaman Chandramouli 	if (sa_path_is_roce(rec))
6179fdca4daSDasaratharaman Chandramouli 		memcpy(rec->roce.dmac, dmac, ETH_ALEN);
6189fdca4daSDasaratharaman Chandramouli }
6199fdca4daSDasaratharaman Chandramouli 
6209fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac_zero(struct sa_path_rec *rec)
6219fdca4daSDasaratharaman Chandramouli {
6229fdca4daSDasaratharaman Chandramouli 	if (sa_path_is_roce(rec))
6239fdca4daSDasaratharaman Chandramouli 		eth_zero_addr(rec->roce.dmac);
6249fdca4daSDasaratharaman Chandramouli }
6259fdca4daSDasaratharaman Chandramouli 
6269fdca4daSDasaratharaman Chandramouli static inline u8 *sa_path_get_dmac(struct sa_path_rec *rec)
6279fdca4daSDasaratharaman Chandramouli {
6289fdca4daSDasaratharaman Chandramouli 	if (sa_path_is_roce(rec))
6299fdca4daSDasaratharaman Chandramouli 		return rec->roce.dmac;
6309fdca4daSDasaratharaman Chandramouli 	return NULL;
6319fdca4daSDasaratharaman Chandramouli }
632a4d61e84SRoland Dreier #endif /* IB_SA_H */
633