1a4d61e84SRoland Dreier /* 2a4d61e84SRoland Dreier * Copyright (c) 2004 Topspin Communications. All rights reserved. 3a4d61e84SRoland Dreier * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 4c1a0b23bSMichael S. Tsirkin * Copyright (c) 2006 Intel Corporation. All rights reserved. 5a4d61e84SRoland Dreier * 6a4d61e84SRoland Dreier * This software is available to you under a choice of one of two 7a4d61e84SRoland Dreier * licenses. You may choose to be licensed under the terms of the GNU 8a4d61e84SRoland Dreier * General Public License (GPL) Version 2, available from the file 9a4d61e84SRoland Dreier * COPYING in the main directory of this source tree, or the 10a4d61e84SRoland Dreier * OpenIB.org BSD license below: 11a4d61e84SRoland Dreier * 12a4d61e84SRoland Dreier * Redistribution and use in source and binary forms, with or 13a4d61e84SRoland Dreier * without modification, are permitted provided that the following 14a4d61e84SRoland Dreier * conditions are met: 15a4d61e84SRoland Dreier * 16a4d61e84SRoland Dreier * - Redistributions of source code must retain the above 17a4d61e84SRoland Dreier * copyright notice, this list of conditions and the following 18a4d61e84SRoland Dreier * disclaimer. 19a4d61e84SRoland Dreier * 20a4d61e84SRoland Dreier * - Redistributions in binary form must reproduce the above 21a4d61e84SRoland Dreier * copyright notice, this list of conditions and the following 22a4d61e84SRoland Dreier * disclaimer in the documentation and/or other materials 23a4d61e84SRoland Dreier * provided with the distribution. 24a4d61e84SRoland Dreier * 25a4d61e84SRoland Dreier * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26a4d61e84SRoland Dreier * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27a4d61e84SRoland Dreier * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28a4d61e84SRoland Dreier * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29a4d61e84SRoland Dreier * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30a4d61e84SRoland Dreier * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31a4d61e84SRoland Dreier * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32a4d61e84SRoland Dreier * SOFTWARE. 33a4d61e84SRoland Dreier */ 34a4d61e84SRoland Dreier 35a4d61e84SRoland Dreier #ifndef IB_SA_H 36a4d61e84SRoland Dreier #define IB_SA_H 37a4d61e84SRoland Dreier 38c1a0b23bSMichael S. Tsirkin #include <linux/completion.h> 39a4d61e84SRoland Dreier #include <linux/compiler.h> 40a4d61e84SRoland Dreier 4160063497SArun Sharma #include <linux/atomic.h> 42ba36e37fSMatan Barak #include <linux/netdevice.h> 43c1a0b23bSMichael S. Tsirkin 44a4d61e84SRoland Dreier #include <rdma/ib_verbs.h> 45a4d61e84SRoland Dreier #include <rdma/ib_mad.h> 469fdca4daSDasaratharaman Chandramouli #include <rdma/ib_addr.h> 4757520751SDasaratharaman Chandramouli #include <rdma/opa_addr.h> 48a4d61e84SRoland Dreier 49a4d61e84SRoland Dreier enum { 50a4d61e84SRoland Dreier IB_SA_CLASS_VERSION = 2, /* IB spec version 1.1/1.2 */ 51a4d61e84SRoland Dreier 52a4d61e84SRoland Dreier IB_SA_METHOD_GET_TABLE = 0x12, 53a4d61e84SRoland Dreier IB_SA_METHOD_GET_TABLE_RESP = 0x92, 541325cc79SHal Rosenstock IB_SA_METHOD_DELETE = 0x15, 551325cc79SHal Rosenstock IB_SA_METHOD_DELETE_RESP = 0x95, 561325cc79SHal Rosenstock IB_SA_METHOD_GET_MULTI = 0x14, 571325cc79SHal Rosenstock IB_SA_METHOD_GET_MULTI_RESP = 0x94, 581325cc79SHal Rosenstock IB_SA_METHOD_GET_TRACE_TBL = 0x13 59a4d61e84SRoland Dreier }; 60a4d61e84SRoland Dreier 612196f271SDasaratharaman Chandramouli #define OPA_SA_CLASS_VERSION 0x80 62fbed8eeeSHal Rosenstock enum { 63fbed8eeeSHal Rosenstock IB_SA_ATTR_CLASS_PORTINFO = 0x01, 64fbed8eeeSHal Rosenstock IB_SA_ATTR_NOTICE = 0x02, 65fbed8eeeSHal Rosenstock IB_SA_ATTR_INFORM_INFO = 0x03, 66fbed8eeeSHal Rosenstock IB_SA_ATTR_NODE_REC = 0x11, 67fbed8eeeSHal Rosenstock IB_SA_ATTR_PORT_INFO_REC = 0x12, 68fbed8eeeSHal Rosenstock IB_SA_ATTR_SL2VL_REC = 0x13, 69fbed8eeeSHal Rosenstock IB_SA_ATTR_SWITCH_REC = 0x14, 70fbed8eeeSHal Rosenstock IB_SA_ATTR_LINEAR_FDB_REC = 0x15, 71fbed8eeeSHal Rosenstock IB_SA_ATTR_RANDOM_FDB_REC = 0x16, 72fbed8eeeSHal Rosenstock IB_SA_ATTR_MCAST_FDB_REC = 0x17, 73fbed8eeeSHal Rosenstock IB_SA_ATTR_SM_INFO_REC = 0x18, 74fbed8eeeSHal Rosenstock IB_SA_ATTR_LINK_REC = 0x20, 75fbed8eeeSHal Rosenstock IB_SA_ATTR_GUID_INFO_REC = 0x30, 76fbed8eeeSHal Rosenstock IB_SA_ATTR_SERVICE_REC = 0x31, 77fbed8eeeSHal Rosenstock IB_SA_ATTR_PARTITION_REC = 0x33, 78fbed8eeeSHal Rosenstock IB_SA_ATTR_PATH_REC = 0x35, 79fbed8eeeSHal Rosenstock IB_SA_ATTR_VL_ARB_REC = 0x36, 80fbed8eeeSHal Rosenstock IB_SA_ATTR_MC_MEMBER_REC = 0x38, 81fbed8eeeSHal Rosenstock IB_SA_ATTR_TRACE_REC = 0x39, 82fbed8eeeSHal Rosenstock IB_SA_ATTR_MULTI_PATH_REC = 0x3a, 83fbed8eeeSHal Rosenstock IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b, 84fbed8eeeSHal Rosenstock IB_SA_ATTR_INFORM_INFO_REC = 0xf3 85fbed8eeeSHal Rosenstock }; 86fbed8eeeSHal Rosenstock 87a4d61e84SRoland Dreier enum ib_sa_selector { 88aec79fccSMichael S. Tsirkin IB_SA_GT = 0, 89aec79fccSMichael S. Tsirkin IB_SA_LT = 1, 90a4d61e84SRoland Dreier IB_SA_EQ = 2, 91a4d61e84SRoland Dreier /* 92a4d61e84SRoland Dreier * The meaning of "best" depends on the attribute: for 93a4d61e84SRoland Dreier * example, for MTU best will return the largest available 94a4d61e84SRoland Dreier * MTU, while for packet life time, best will return the 95a4d61e84SRoland Dreier * smallest available life time. 96a4d61e84SRoland Dreier */ 97a4d61e84SRoland Dreier IB_SA_BEST = 3 98a4d61e84SRoland Dreier }; 99a4d61e84SRoland Dreier 100ab15c95aSAlex Vesker /* 101ab15c95aSAlex Vesker * There are 4 types of join states: 102ab15c95aSAlex Vesker * FullMember, NonMember, SendOnlyNonMember, SendOnlyFullMember. 103ab15c95aSAlex Vesker * The order corresponds to JoinState bits in MCMemberRecord. 104ab15c95aSAlex Vesker */ 105ab15c95aSAlex Vesker enum ib_sa_mc_join_states { 106ab15c95aSAlex Vesker FULLMEMBER_JOIN, 107ab15c95aSAlex Vesker NONMEMBER_JOIN, 108ab15c95aSAlex Vesker SENDONLY_NONMEBER_JOIN, 109ab15c95aSAlex Vesker SENDONLY_FULLMEMBER_JOIN, 110ab15c95aSAlex Vesker NUM_JOIN_MEMBERSHIP_TYPES, 111ab15c95aSAlex Vesker }; 112ab15c95aSAlex Vesker 113628e6f75SErez Shitrit #define IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT BIT(12) 114628e6f75SErez Shitrit 115a4d61e84SRoland Dreier /* 116a4d61e84SRoland Dreier * Structures for SA records are named "struct ib_sa_xxx_rec." No 117a4d61e84SRoland Dreier * attempt is made to pack structures to match the physical layout of 118a4d61e84SRoland Dreier * SA records in SA MADs; all packing and unpacking is handled by the 119a4d61e84SRoland Dreier * SA query code. 120a4d61e84SRoland Dreier * 121a4d61e84SRoland Dreier * For a record with structure ib_sa_xxx_rec, the naming convention 122a4d61e84SRoland Dreier * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we 123a4d61e84SRoland Dreier * never use different abbreviations or otherwise change the spelling 124a4d61e84SRoland Dreier * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY). 125a4d61e84SRoland Dreier * 126a4d61e84SRoland Dreier * Reserved rows are indicated with comments to help maintainability. 127a4d61e84SRoland Dreier */ 128a4d61e84SRoland Dreier 129733d65feSSean Hefty #define IB_SA_PATH_REC_SERVICE_ID (IB_SA_COMP_MASK( 0) |\ 130733d65feSSean Hefty IB_SA_COMP_MASK( 1)) 131a4d61e84SRoland Dreier #define IB_SA_PATH_REC_DGID IB_SA_COMP_MASK( 2) 132a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SGID IB_SA_COMP_MASK( 3) 133a4d61e84SRoland Dreier #define IB_SA_PATH_REC_DLID IB_SA_COMP_MASK( 4) 134a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SLID IB_SA_COMP_MASK( 5) 135a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RAW_TRAFFIC IB_SA_COMP_MASK( 6) 136a4d61e84SRoland Dreier /* reserved: 7 */ 137a4d61e84SRoland Dreier #define IB_SA_PATH_REC_FLOW_LABEL IB_SA_COMP_MASK( 8) 138a4d61e84SRoland Dreier #define IB_SA_PATH_REC_HOP_LIMIT IB_SA_COMP_MASK( 9) 139a4d61e84SRoland Dreier #define IB_SA_PATH_REC_TRAFFIC_CLASS IB_SA_COMP_MASK(10) 140a4d61e84SRoland Dreier #define IB_SA_PATH_REC_REVERSIBLE IB_SA_COMP_MASK(11) 141a4d61e84SRoland Dreier #define IB_SA_PATH_REC_NUMB_PATH IB_SA_COMP_MASK(12) 142a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PKEY IB_SA_COMP_MASK(13) 143733d65feSSean Hefty #define IB_SA_PATH_REC_QOS_CLASS IB_SA_COMP_MASK(14) 144a4d61e84SRoland Dreier #define IB_SA_PATH_REC_SL IB_SA_COMP_MASK(15) 145a4d61e84SRoland Dreier #define IB_SA_PATH_REC_MTU_SELECTOR IB_SA_COMP_MASK(16) 146a4d61e84SRoland Dreier #define IB_SA_PATH_REC_MTU IB_SA_COMP_MASK(17) 147a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RATE_SELECTOR IB_SA_COMP_MASK(18) 148a4d61e84SRoland Dreier #define IB_SA_PATH_REC_RATE IB_SA_COMP_MASK(19) 149a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(20) 150a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(21) 151a4d61e84SRoland Dreier #define IB_SA_PATH_REC_PREFERENCE IB_SA_COMP_MASK(22) 1529fdca4daSDasaratharaman Chandramouli 153dfa834e1SDasaratharaman Chandramouli enum sa_path_rec_type { 154dfa834e1SDasaratharaman Chandramouli SA_PATH_REC_TYPE_IB, 155dfa834e1SDasaratharaman Chandramouli SA_PATH_REC_TYPE_ROCE_V1, 15657520751SDasaratharaman Chandramouli SA_PATH_REC_TYPE_ROCE_V2, 15757520751SDasaratharaman Chandramouli SA_PATH_REC_TYPE_OPA 158dfa834e1SDasaratharaman Chandramouli }; 159a4d61e84SRoland Dreier 1609fdca4daSDasaratharaman Chandramouli struct sa_path_rec_ib { 161a4d61e84SRoland Dreier __be16 dlid; 162a4d61e84SRoland Dreier __be16 slid; 16355efcfcdSJason Gunthorpe u8 raw_traffic; 1649fdca4daSDasaratharaman Chandramouli }; 1659fdca4daSDasaratharaman Chandramouli 1669fdca4daSDasaratharaman Chandramouli struct sa_path_rec_roce { 1679fdca4daSDasaratharaman Chandramouli u8 dmac[ETH_ALEN]; 1689fdca4daSDasaratharaman Chandramouli /* ignored in IB */ 1699fdca4daSDasaratharaman Chandramouli int ifindex; 1709fdca4daSDasaratharaman Chandramouli /* ignored in IB */ 1719fdca4daSDasaratharaman Chandramouli struct net *net; 1729fdca4daSDasaratharaman Chandramouli 1739fdca4daSDasaratharaman Chandramouli }; 1749fdca4daSDasaratharaman Chandramouli 17557520751SDasaratharaman Chandramouli struct sa_path_rec_opa { 17657520751SDasaratharaman Chandramouli __be32 dlid; 17757520751SDasaratharaman Chandramouli __be32 slid; 17857520751SDasaratharaman Chandramouli u8 raw_traffic; 17957520751SDasaratharaman Chandramouli u8 l2_8B; 18057520751SDasaratharaman Chandramouli u8 l2_10B; 18157520751SDasaratharaman Chandramouli u8 l2_9B; 18257520751SDasaratharaman Chandramouli u8 l2_16B; 18357520751SDasaratharaman Chandramouli u8 qos_type; 18457520751SDasaratharaman Chandramouli u8 qos_priority; 18557520751SDasaratharaman Chandramouli }; 18657520751SDasaratharaman Chandramouli 1879fdca4daSDasaratharaman Chandramouli struct sa_path_rec { 1889fdca4daSDasaratharaman Chandramouli union ib_gid dgid; 1899fdca4daSDasaratharaman Chandramouli union ib_gid sgid; 190d3957b86SMajd Dibbiny __be64 service_id; 191a4d61e84SRoland Dreier /* reserved */ 192a4d61e84SRoland Dreier __be32 flow_label; 193a4d61e84SRoland Dreier u8 hop_limit; 194a4d61e84SRoland Dreier u8 traffic_class; 19555efcfcdSJason Gunthorpe u8 reversible; 196a4d61e84SRoland Dreier u8 numb_path; 197a4d61e84SRoland Dreier __be16 pkey; 198733d65feSSean Hefty __be16 qos_class; 199a4d61e84SRoland Dreier u8 sl; 200a4d61e84SRoland Dreier u8 mtu_selector; 201a4d61e84SRoland Dreier u8 mtu; 202a4d61e84SRoland Dreier u8 rate_selector; 203a4d61e84SRoland Dreier u8 rate; 204a4d61e84SRoland Dreier u8 packet_life_time_selector; 205a4d61e84SRoland Dreier u8 packet_life_time; 206a4d61e84SRoland Dreier u8 preference; 2079fdca4daSDasaratharaman Chandramouli union { 2089fdca4daSDasaratharaman Chandramouli struct sa_path_rec_ib ib; 2099fdca4daSDasaratharaman Chandramouli struct sa_path_rec_roce roce; 21057520751SDasaratharaman Chandramouli struct sa_path_rec_opa opa; 2119fdca4daSDasaratharaman Chandramouli }; 212dfa834e1SDasaratharaman Chandramouli enum sa_path_rec_type rec_type; 213a4d61e84SRoland Dreier }; 214a4d61e84SRoland Dreier 215dfa834e1SDasaratharaman Chandramouli static inline enum ib_gid_type 216dfa834e1SDasaratharaman Chandramouli sa_conv_pathrec_to_gid_type(struct sa_path_rec *rec) 217dfa834e1SDasaratharaman Chandramouli { 218dfa834e1SDasaratharaman Chandramouli switch (rec->rec_type) { 219dfa834e1SDasaratharaman Chandramouli case SA_PATH_REC_TYPE_ROCE_V1: 220dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_ROCE; 221dfa834e1SDasaratharaman Chandramouli case SA_PATH_REC_TYPE_ROCE_V2: 222dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_ROCE_UDP_ENCAP; 223dfa834e1SDasaratharaman Chandramouli default: 224dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_IB; 225dfa834e1SDasaratharaman Chandramouli } 226dfa834e1SDasaratharaman Chandramouli } 227dfa834e1SDasaratharaman Chandramouli 228dfa834e1SDasaratharaman Chandramouli static inline enum sa_path_rec_type 229dfa834e1SDasaratharaman Chandramouli sa_conv_gid_to_pathrec_type(enum ib_gid_type type) 230dfa834e1SDasaratharaman Chandramouli { 231dfa834e1SDasaratharaman Chandramouli switch (type) { 232dfa834e1SDasaratharaman Chandramouli case IB_GID_TYPE_ROCE: 233dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_ROCE_V1; 234dfa834e1SDasaratharaman Chandramouli case IB_GID_TYPE_ROCE_UDP_ENCAP: 235dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_ROCE_V2; 236dfa834e1SDasaratharaman Chandramouli default: 237dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_IB; 238dfa834e1SDasaratharaman Chandramouli } 239dfa834e1SDasaratharaman Chandramouli } 240dfa834e1SDasaratharaman Chandramouli 24157520751SDasaratharaman Chandramouli static inline void path_conv_opa_to_ib(struct sa_path_rec *ib, 24257520751SDasaratharaman Chandramouli struct sa_path_rec *opa) 24357520751SDasaratharaman Chandramouli { 24457520751SDasaratharaman Chandramouli if ((be32_to_cpu(opa->opa.dlid) >= 24557520751SDasaratharaman Chandramouli be16_to_cpu(IB_MULTICAST_LID_BASE)) || 24657520751SDasaratharaman Chandramouli (be32_to_cpu(opa->opa.slid) >= 24757520751SDasaratharaman Chandramouli be16_to_cpu(IB_MULTICAST_LID_BASE))) { 24857520751SDasaratharaman Chandramouli /* Create OPA GID and zero out the LID */ 24957520751SDasaratharaman Chandramouli ib->dgid.global.interface_id 25057520751SDasaratharaman Chandramouli = OPA_MAKE_ID(be32_to_cpu(opa->opa.dlid)); 25157520751SDasaratharaman Chandramouli ib->dgid.global.subnet_prefix 25257520751SDasaratharaman Chandramouli = opa->dgid.global.subnet_prefix; 25357520751SDasaratharaman Chandramouli ib->sgid.global.interface_id 25457520751SDasaratharaman Chandramouli = OPA_MAKE_ID(be32_to_cpu(opa->opa.slid)); 25557520751SDasaratharaman Chandramouli ib->dgid.global.subnet_prefix 25657520751SDasaratharaman Chandramouli = opa->dgid.global.subnet_prefix; 25757520751SDasaratharaman Chandramouli ib->ib.dlid = 0; 25857520751SDasaratharaman Chandramouli 25957520751SDasaratharaman Chandramouli ib->ib.slid = 0; 26057520751SDasaratharaman Chandramouli } else { 26157520751SDasaratharaman Chandramouli ib->ib.dlid = htons(ntohl(opa->opa.dlid)); 26257520751SDasaratharaman Chandramouli ib->ib.slid = htons(ntohl(opa->opa.slid)); 26357520751SDasaratharaman Chandramouli } 264d3957b86SMajd Dibbiny ib->service_id = opa->service_id; 26557520751SDasaratharaman Chandramouli ib->ib.raw_traffic = opa->opa.raw_traffic; 26657520751SDasaratharaman Chandramouli } 26757520751SDasaratharaman Chandramouli 26857520751SDasaratharaman Chandramouli static inline void path_conv_ib_to_opa(struct sa_path_rec *opa, 26957520751SDasaratharaman Chandramouli struct sa_path_rec *ib) 27057520751SDasaratharaman Chandramouli { 27157520751SDasaratharaman Chandramouli __be32 slid, dlid; 27257520751SDasaratharaman Chandramouli 27357520751SDasaratharaman Chandramouli if ((ib_is_opa_gid(&ib->sgid)) || 27457520751SDasaratharaman Chandramouli (ib_is_opa_gid(&ib->dgid))) { 27557520751SDasaratharaman Chandramouli slid = htonl(opa_get_lid_from_gid(&ib->sgid)); 27657520751SDasaratharaman Chandramouli dlid = htonl(opa_get_lid_from_gid(&ib->dgid)); 27757520751SDasaratharaman Chandramouli } else { 27857520751SDasaratharaman Chandramouli slid = htonl(ntohs(ib->ib.slid)); 27957520751SDasaratharaman Chandramouli dlid = htonl(ntohs(ib->ib.dlid)); 28057520751SDasaratharaman Chandramouli } 28157520751SDasaratharaman Chandramouli opa->opa.slid = slid; 28257520751SDasaratharaman Chandramouli opa->opa.dlid = dlid; 283d3957b86SMajd Dibbiny opa->service_id = ib->service_id; 28457520751SDasaratharaman Chandramouli opa->opa.raw_traffic = ib->ib.raw_traffic; 28557520751SDasaratharaman Chandramouli } 28657520751SDasaratharaman Chandramouli 28757520751SDasaratharaman Chandramouli /* Convert from OPA to IB path record */ 28857520751SDasaratharaman Chandramouli static inline void sa_convert_path_opa_to_ib(struct sa_path_rec *dest, 28957520751SDasaratharaman Chandramouli struct sa_path_rec *src) 29057520751SDasaratharaman Chandramouli { 29157520751SDasaratharaman Chandramouli if (src->rec_type != SA_PATH_REC_TYPE_OPA) 29257520751SDasaratharaman Chandramouli return; 29357520751SDasaratharaman Chandramouli 29457520751SDasaratharaman Chandramouli *dest = *src; 29557520751SDasaratharaman Chandramouli dest->rec_type = SA_PATH_REC_TYPE_IB; 29657520751SDasaratharaman Chandramouli path_conv_opa_to_ib(dest, src); 29757520751SDasaratharaman Chandramouli } 29857520751SDasaratharaman Chandramouli 29957520751SDasaratharaman Chandramouli /* Convert from IB to OPA path record */ 30057520751SDasaratharaman Chandramouli static inline void sa_convert_path_ib_to_opa(struct sa_path_rec *dest, 30157520751SDasaratharaman Chandramouli struct sa_path_rec *src) 30257520751SDasaratharaman Chandramouli { 30357520751SDasaratharaman Chandramouli if (src->rec_type != SA_PATH_REC_TYPE_IB) 30457520751SDasaratharaman Chandramouli return; 30557520751SDasaratharaman Chandramouli 30657520751SDasaratharaman Chandramouli /* Do a structure copy and overwrite the relevant fields */ 30757520751SDasaratharaman Chandramouli *dest = *src; 30857520751SDasaratharaman Chandramouli dest->rec_type = SA_PATH_REC_TYPE_OPA; 30957520751SDasaratharaman Chandramouli path_conv_ib_to_opa(dest, src); 31057520751SDasaratharaman Chandramouli } 31157520751SDasaratharaman Chandramouli 312a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MGID IB_SA_COMP_MASK( 0) 313a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PORT_GID IB_SA_COMP_MASK( 1) 314a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_QKEY IB_SA_COMP_MASK( 2) 315a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MLID IB_SA_COMP_MASK( 3) 316a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU_SELECTOR IB_SA_COMP_MASK( 4) 317a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU IB_SA_COMP_MASK( 5) 318a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS IB_SA_COMP_MASK( 6) 319a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PKEY IB_SA_COMP_MASK( 7) 320a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE_SELECTOR IB_SA_COMP_MASK( 8) 321a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE IB_SA_COMP_MASK( 9) 322a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(10) 323a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(11) 324a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SL IB_SA_COMP_MASK(12) 325a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_FLOW_LABEL IB_SA_COMP_MASK(13) 326a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_HOP_LIMIT IB_SA_COMP_MASK(14) 327a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SCOPE IB_SA_COMP_MASK(15) 328a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_JOIN_STATE IB_SA_COMP_MASK(16) 329a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PROXY_JOIN IB_SA_COMP_MASK(17) 330a4d61e84SRoland Dreier 331a4d61e84SRoland Dreier struct ib_sa_mcmember_rec { 332a4d61e84SRoland Dreier union ib_gid mgid; 333a4d61e84SRoland Dreier union ib_gid port_gid; 334a4d61e84SRoland Dreier __be32 qkey; 335a4d61e84SRoland Dreier __be16 mlid; 336a4d61e84SRoland Dreier u8 mtu_selector; 337a4d61e84SRoland Dreier u8 mtu; 338a4d61e84SRoland Dreier u8 traffic_class; 339a4d61e84SRoland Dreier __be16 pkey; 340a4d61e84SRoland Dreier u8 rate_selector; 341a4d61e84SRoland Dreier u8 rate; 342a4d61e84SRoland Dreier u8 packet_life_time_selector; 343a4d61e84SRoland Dreier u8 packet_life_time; 344a4d61e84SRoland Dreier u8 sl; 345a4d61e84SRoland Dreier __be32 flow_label; 346a4d61e84SRoland Dreier u8 hop_limit; 347a4d61e84SRoland Dreier u8 scope; 348a4d61e84SRoland Dreier u8 join_state; 34955efcfcdSJason Gunthorpe u8 proxy_join; 350a4d61e84SRoland Dreier }; 351a4d61e84SRoland Dreier 352a4d61e84SRoland Dreier /* Service Record Component Mask Sec 15.2.5.14 Ver 1.1 */ 353a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_ID IB_SA_COMP_MASK( 0) 354a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_GID IB_SA_COMP_MASK( 1) 355a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_PKEY IB_SA_COMP_MASK( 2) 356a4d61e84SRoland Dreier /* reserved: 3 */ 357a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_LEASE IB_SA_COMP_MASK( 4) 358a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_KEY IB_SA_COMP_MASK( 5) 359a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_NAME IB_SA_COMP_MASK( 6) 360a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_0 IB_SA_COMP_MASK( 7) 361a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_1 IB_SA_COMP_MASK( 8) 362a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_2 IB_SA_COMP_MASK( 9) 363a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_3 IB_SA_COMP_MASK(10) 364a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_4 IB_SA_COMP_MASK(11) 365a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_5 IB_SA_COMP_MASK(12) 366a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_6 IB_SA_COMP_MASK(13) 367a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_7 IB_SA_COMP_MASK(14) 368a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_8 IB_SA_COMP_MASK(15) 369a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_9 IB_SA_COMP_MASK(16) 370a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_10 IB_SA_COMP_MASK(17) 371a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_11 IB_SA_COMP_MASK(18) 372a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_12 IB_SA_COMP_MASK(19) 373a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_13 IB_SA_COMP_MASK(20) 374a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_14 IB_SA_COMP_MASK(21) 375a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_15 IB_SA_COMP_MASK(22) 376a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_0 IB_SA_COMP_MASK(23) 377a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_1 IB_SA_COMP_MASK(24) 378a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_2 IB_SA_COMP_MASK(25) 379a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_3 IB_SA_COMP_MASK(26) 380a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_4 IB_SA_COMP_MASK(27) 381a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_5 IB_SA_COMP_MASK(28) 382a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_6 IB_SA_COMP_MASK(29) 383a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_7 IB_SA_COMP_MASK(30) 384a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_0 IB_SA_COMP_MASK(31) 385a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_1 IB_SA_COMP_MASK(32) 386a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_2 IB_SA_COMP_MASK(33) 387a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_3 IB_SA_COMP_MASK(34) 388a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_0 IB_SA_COMP_MASK(35) 389a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_1 IB_SA_COMP_MASK(36) 390a4d61e84SRoland Dreier 391a4d61e84SRoland Dreier #define IB_DEFAULT_SERVICE_LEASE 0xFFFFFFFF 392a4d61e84SRoland Dreier 393a4d61e84SRoland Dreier struct ib_sa_service_rec { 394a4d61e84SRoland Dreier u64 id; 395a4d61e84SRoland Dreier union ib_gid gid; 396a4d61e84SRoland Dreier __be16 pkey; 397a4d61e84SRoland Dreier /* reserved */ 398a4d61e84SRoland Dreier u32 lease; 399a4d61e84SRoland Dreier u8 key[16]; 400a4d61e84SRoland Dreier u8 name[64]; 401a4d61e84SRoland Dreier u8 data8[16]; 402a4d61e84SRoland Dreier u16 data16[8]; 403a4d61e84SRoland Dreier u32 data32[4]; 404a4d61e84SRoland Dreier u64 data64[2]; 405a4d61e84SRoland Dreier }; 406a4d61e84SRoland Dreier 407aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_LID IB_SA_COMP_MASK(0) 408aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_BLOCK_NUM IB_SA_COMP_MASK(1) 409aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES1 IB_SA_COMP_MASK(2) 410aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES2 IB_SA_COMP_MASK(3) 411aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID0 IB_SA_COMP_MASK(4) 412aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID1 IB_SA_COMP_MASK(5) 413aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID2 IB_SA_COMP_MASK(6) 414aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID3 IB_SA_COMP_MASK(7) 415aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID4 IB_SA_COMP_MASK(8) 416aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID5 IB_SA_COMP_MASK(9) 417aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID6 IB_SA_COMP_MASK(10) 418aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID7 IB_SA_COMP_MASK(11) 419aeab97edSErez Shitrit 420aeab97edSErez Shitrit struct ib_sa_guidinfo_rec { 421aeab97edSErez Shitrit __be16 lid; 422aeab97edSErez Shitrit u8 block_num; 423aeab97edSErez Shitrit /* reserved */ 424aeab97edSErez Shitrit u8 res1; 425aeab97edSErez Shitrit __be32 res2; 426aeab97edSErez Shitrit u8 guid_info_list[64]; 427aeab97edSErez Shitrit }; 428aeab97edSErez Shitrit 429c1a0b23bSMichael S. Tsirkin struct ib_sa_client { 430c1a0b23bSMichael S. Tsirkin atomic_t users; 431c1a0b23bSMichael S. Tsirkin struct completion comp; 432c1a0b23bSMichael S. Tsirkin }; 433c1a0b23bSMichael S. Tsirkin 434c1a0b23bSMichael S. Tsirkin /** 435c1a0b23bSMichael S. Tsirkin * ib_sa_register_client - Register an SA client. 436c1a0b23bSMichael S. Tsirkin */ 437c1a0b23bSMichael S. Tsirkin void ib_sa_register_client(struct ib_sa_client *client); 438c1a0b23bSMichael S. Tsirkin 439c1a0b23bSMichael S. Tsirkin /** 440c1a0b23bSMichael S. Tsirkin * ib_sa_unregister_client - Deregister an SA client. 441c1a0b23bSMichael S. Tsirkin * @client: Client object to deregister. 442c1a0b23bSMichael S. Tsirkin */ 443c1a0b23bSMichael S. Tsirkin void ib_sa_unregister_client(struct ib_sa_client *client); 444c1a0b23bSMichael S. Tsirkin 445a4d61e84SRoland Dreier struct ib_sa_query; 446a4d61e84SRoland Dreier 447a4d61e84SRoland Dreier void ib_sa_cancel_query(int id, struct ib_sa_query *query); 448a4d61e84SRoland Dreier 449c1a0b23bSMichael S. Tsirkin int ib_sa_path_rec_get(struct ib_sa_client *client, 450c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 451c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *rec, 452a4d61e84SRoland Dreier ib_sa_comp_mask comp_mask, 453dd0fc66fSAl Viro int timeout_ms, gfp_t gfp_mask, 454a4d61e84SRoland Dreier void (*callback)(int status, 455c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *resp, 456a4d61e84SRoland Dreier void *context), 457a4d61e84SRoland Dreier void *context, 458a4d61e84SRoland Dreier struct ib_sa_query **query); 459a4d61e84SRoland Dreier 460c1a0b23bSMichael S. Tsirkin int ib_sa_service_rec_query(struct ib_sa_client *client, 461c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 462a4d61e84SRoland Dreier u8 method, 463a4d61e84SRoland Dreier struct ib_sa_service_rec *rec, 464a4d61e84SRoland Dreier ib_sa_comp_mask comp_mask, 465dd0fc66fSAl Viro int timeout_ms, gfp_t gfp_mask, 466a4d61e84SRoland Dreier void (*callback)(int status, 467a4d61e84SRoland Dreier struct ib_sa_service_rec *resp, 468a4d61e84SRoland Dreier void *context), 469a4d61e84SRoland Dreier void *context, 470a4d61e84SRoland Dreier struct ib_sa_query **sa_query); 471a4d61e84SRoland Dreier 472faec2f7bSSean Hefty struct ib_sa_multicast { 473faec2f7bSSean Hefty struct ib_sa_mcmember_rec rec; 474faec2f7bSSean Hefty ib_sa_comp_mask comp_mask; 475faec2f7bSSean Hefty int (*callback)(int status, 476faec2f7bSSean Hefty struct ib_sa_multicast *multicast); 477faec2f7bSSean Hefty void *context; 478faec2f7bSSean Hefty }; 479a4d61e84SRoland Dreier 480a4d61e84SRoland Dreier /** 481faec2f7bSSean Hefty * ib_sa_join_multicast - Initiates a join request to the specified multicast 482faec2f7bSSean Hefty * group. 483c1a0b23bSMichael S. Tsirkin * @client: SA client 484faec2f7bSSean Hefty * @device: Device associated with the multicast group. 485faec2f7bSSean Hefty * @port_num: Port on the specified device to associate with the multicast 486faec2f7bSSean Hefty * group. 487faec2f7bSSean Hefty * @rec: SA multicast member record specifying group attributes. 488faec2f7bSSean Hefty * @comp_mask: Component mask indicating which group attributes of %rec are 489faec2f7bSSean Hefty * valid. 490faec2f7bSSean Hefty * @gfp_mask: GFP mask for memory allocations. 491faec2f7bSSean Hefty * @callback: User callback invoked once the join operation completes. 492faec2f7bSSean Hefty * @context: User specified context stored with the ib_sa_multicast structure. 493a4d61e84SRoland Dreier * 494faec2f7bSSean Hefty * This call initiates a multicast join request with the SA for the specified 495faec2f7bSSean Hefty * multicast group. If the join operation is started successfully, it returns 496faec2f7bSSean Hefty * an ib_sa_multicast structure that is used to track the multicast operation. 497faec2f7bSSean Hefty * Users must free this structure by calling ib_free_multicast, even if the 498faec2f7bSSean Hefty * join operation later fails. (The callback status is non-zero.) 499a4d61e84SRoland Dreier * 500faec2f7bSSean Hefty * If the join operation fails; status will be non-zero, with the following 501faec2f7bSSean Hefty * failures possible: 502faec2f7bSSean Hefty * -ETIMEDOUT: The request timed out. 503faec2f7bSSean Hefty * -EIO: An error occurred sending the query. 504faec2f7bSSean Hefty * -EINVAL: The MCMemberRecord values differed from the existing group's. 505faec2f7bSSean Hefty * -ENETRESET: Indicates that an fatal error has occurred on the multicast 506faec2f7bSSean Hefty * group, and the user must rejoin the group to continue using it. 507a4d61e84SRoland Dreier */ 508faec2f7bSSean Hefty struct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client, 509c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 510a4d61e84SRoland Dreier struct ib_sa_mcmember_rec *rec, 511faec2f7bSSean Hefty ib_sa_comp_mask comp_mask, gfp_t gfp_mask, 512faec2f7bSSean Hefty int (*callback)(int status, 513faec2f7bSSean Hefty struct ib_sa_multicast 514faec2f7bSSean Hefty *multicast), 515faec2f7bSSean Hefty void *context); 516faec2f7bSSean Hefty 517faec2f7bSSean Hefty /** 518faec2f7bSSean Hefty * ib_free_multicast - Frees the multicast tracking structure, and releases 519faec2f7bSSean Hefty * any reference on the multicast group. 520faec2f7bSSean Hefty * @multicast: Multicast tracking structure allocated by ib_join_multicast. 521faec2f7bSSean Hefty * 522faec2f7bSSean Hefty * This call blocks until the multicast identifier is destroyed. It may 523faec2f7bSSean Hefty * not be called from within the multicast callback; however, returning a non- 524faec2f7bSSean Hefty * zero value from the callback will result in destroying the multicast 525faec2f7bSSean Hefty * tracking structure. 526faec2f7bSSean Hefty */ 527faec2f7bSSean Hefty void ib_sa_free_multicast(struct ib_sa_multicast *multicast); 528faec2f7bSSean Hefty 529faec2f7bSSean Hefty /** 530faec2f7bSSean Hefty * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and 531faec2f7bSSean Hefty * returns it if found. 532faec2f7bSSean Hefty * @device: Device associated with the multicast group. 533faec2f7bSSean Hefty * @port_num: Port on the specified device to associate with the multicast 534faec2f7bSSean Hefty * group. 535faec2f7bSSean Hefty * @mgid: MGID of multicast group. 536faec2f7bSSean Hefty * @rec: Location to copy SA multicast member record. 537faec2f7bSSean Hefty */ 538faec2f7bSSean Hefty int ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num, 539faec2f7bSSean Hefty union ib_gid *mgid, struct ib_sa_mcmember_rec *rec); 540faec2f7bSSean Hefty 541faec2f7bSSean Hefty /** 542faec2f7bSSean Hefty * ib_init_ah_from_mcmember - Initialize address handle attributes based on 543faec2f7bSSean Hefty * an SA multicast member record. 544faec2f7bSSean Hefty */ 545faec2f7bSSean Hefty int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num, 546faec2f7bSSean Hefty struct ib_sa_mcmember_rec *rec, 547bee3c3c9SMoni Shoua struct net_device *ndev, 548bee3c3c9SMoni Shoua enum ib_gid_type gid_type, 54990898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr); 550a4d61e84SRoland Dreier 5516d969a47SSean Hefty /** 552*4ad6a024SParav Pandit * ib_init_ah_attr_from_path - Initialize address handle attributes based on 553*4ad6a024SParav Pandit * an SA path record. 5546d969a47SSean Hefty */ 555*4ad6a024SParav Pandit int ib_init_ah_attr_from_path(struct ib_device *device, u8 port_num, 556c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *rec, 55790898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr); 558a4d61e84SRoland Dreier 559a7ca1f00SSean Hefty /** 5602e08b587SSean Hefty * ib_sa_pack_path - Conert a path record from struct ib_sa_path_rec 5612e08b587SSean Hefty * to IB MAD wire format. 5622e08b587SSean Hefty */ 563c2f8fc4eSDasaratharaman Chandramouli void ib_sa_pack_path(struct sa_path_rec *rec, void *attribute); 5642e08b587SSean Hefty 5652e08b587SSean Hefty /** 566a7ca1f00SSean Hefty * ib_sa_unpack_path - Convert a path record from MAD format to struct 567a7ca1f00SSean Hefty * ib_sa_path_rec. 568a7ca1f00SSean Hefty */ 569c2f8fc4eSDasaratharaman Chandramouli void ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec); 570a7ca1f00SSean Hefty 571aeab97edSErez Shitrit /* Support GuidInfoRecord */ 572aeab97edSErez Shitrit int ib_sa_guid_info_rec_query(struct ib_sa_client *client, 573aeab97edSErez Shitrit struct ib_device *device, u8 port_num, 574aeab97edSErez Shitrit struct ib_sa_guidinfo_rec *rec, 575aeab97edSErez Shitrit ib_sa_comp_mask comp_mask, u8 method, 576aeab97edSErez Shitrit int timeout_ms, gfp_t gfp_mask, 577aeab97edSErez Shitrit void (*callback)(int status, 578aeab97edSErez Shitrit struct ib_sa_guidinfo_rec *resp, 579aeab97edSErez Shitrit void *context), 580aeab97edSErez Shitrit void *context, 581aeab97edSErez Shitrit struct ib_sa_query **sa_query); 5822e08b587SSean Hefty 583ee1c60b1SDasaratharaman Chandramouli bool ib_sa_sendonly_fullmem_support(struct ib_sa_client *client, 584ee1c60b1SDasaratharaman Chandramouli struct ib_device *device, 585ee1c60b1SDasaratharaman Chandramouli u8 port_num); 586628e6f75SErez Shitrit 5879fdca4daSDasaratharaman Chandramouli static inline bool sa_path_is_roce(struct sa_path_rec *rec) 5889fdca4daSDasaratharaman Chandramouli { 5899fdca4daSDasaratharaman Chandramouli return ((rec->rec_type == SA_PATH_REC_TYPE_ROCE_V1) || 5909fdca4daSDasaratharaman Chandramouli (rec->rec_type == SA_PATH_REC_TYPE_ROCE_V2)); 5919fdca4daSDasaratharaman Chandramouli } 5929fdca4daSDasaratharaman Chandramouli 5939d187177SBart Van Assche static inline void sa_path_set_slid(struct sa_path_rec *rec, u32 slid) 5949fdca4daSDasaratharaman Chandramouli { 5959fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 5969d187177SBart Van Assche rec->ib.slid = cpu_to_be16(slid); 59757520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 5989d187177SBart Van Assche rec->opa.slid = cpu_to_be32(slid); 5999fdca4daSDasaratharaman Chandramouli } 6009fdca4daSDasaratharaman Chandramouli 6019d187177SBart Van Assche static inline void sa_path_set_dlid(struct sa_path_rec *rec, u32 dlid) 6029fdca4daSDasaratharaman Chandramouli { 6039fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6049d187177SBart Van Assche rec->ib.dlid = cpu_to_be16(dlid); 60557520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 6069d187177SBart Van Assche rec->opa.dlid = cpu_to_be32(dlid); 6079fdca4daSDasaratharaman Chandramouli } 6089fdca4daSDasaratharaman Chandramouli 6099fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_raw_traffic(struct sa_path_rec *rec, 6109fdca4daSDasaratharaman Chandramouli u8 raw_traffic) 6119fdca4daSDasaratharaman Chandramouli { 6129fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6139fdca4daSDasaratharaman Chandramouli rec->ib.raw_traffic = raw_traffic; 61457520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 61557520751SDasaratharaman Chandramouli rec->opa.raw_traffic = raw_traffic; 6169fdca4daSDasaratharaman Chandramouli } 6179fdca4daSDasaratharaman Chandramouli 61857520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_slid(struct sa_path_rec *rec) 6199fdca4daSDasaratharaman Chandramouli { 6209fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 62157520751SDasaratharaman Chandramouli return htonl(ntohs(rec->ib.slid)); 62257520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 62357520751SDasaratharaman Chandramouli return rec->opa.slid; 6249fdca4daSDasaratharaman Chandramouli return 0; 6259fdca4daSDasaratharaman Chandramouli } 6269fdca4daSDasaratharaman Chandramouli 62757520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_dlid(struct sa_path_rec *rec) 6289fdca4daSDasaratharaman Chandramouli { 6299fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 63057520751SDasaratharaman Chandramouli return htonl(ntohs(rec->ib.dlid)); 63157520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 63257520751SDasaratharaman Chandramouli return rec->opa.dlid; 6339fdca4daSDasaratharaman Chandramouli return 0; 6349fdca4daSDasaratharaman Chandramouli } 6359fdca4daSDasaratharaman Chandramouli 6369fdca4daSDasaratharaman Chandramouli static inline u8 sa_path_get_raw_traffic(struct sa_path_rec *rec) 6379fdca4daSDasaratharaman Chandramouli { 6389fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6399fdca4daSDasaratharaman Chandramouli return rec->ib.raw_traffic; 64057520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 64157520751SDasaratharaman Chandramouli return rec->opa.raw_traffic; 6429fdca4daSDasaratharaman Chandramouli return 0; 6439fdca4daSDasaratharaman Chandramouli } 6449fdca4daSDasaratharaman Chandramouli 6459fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac(struct sa_path_rec *rec, u8 *dmac) 6469fdca4daSDasaratharaman Chandramouli { 6479fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6489fdca4daSDasaratharaman Chandramouli memcpy(rec->roce.dmac, dmac, ETH_ALEN); 6499fdca4daSDasaratharaman Chandramouli } 6509fdca4daSDasaratharaman Chandramouli 6519fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac_zero(struct sa_path_rec *rec) 6529fdca4daSDasaratharaman Chandramouli { 6539fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6549fdca4daSDasaratharaman Chandramouli eth_zero_addr(rec->roce.dmac); 6559fdca4daSDasaratharaman Chandramouli } 6569fdca4daSDasaratharaman Chandramouli 6579fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_ifindex(struct sa_path_rec *rec, int ifindex) 6589fdca4daSDasaratharaman Chandramouli { 6599fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6609fdca4daSDasaratharaman Chandramouli rec->roce.ifindex = ifindex; 6619fdca4daSDasaratharaman Chandramouli } 6629fdca4daSDasaratharaman Chandramouli 6639fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_ndev(struct sa_path_rec *rec, struct net *net) 6649fdca4daSDasaratharaman Chandramouli { 6659fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6669fdca4daSDasaratharaman Chandramouli rec->roce.net = net; 6679fdca4daSDasaratharaman Chandramouli } 6689fdca4daSDasaratharaman Chandramouli 6699fdca4daSDasaratharaman Chandramouli static inline u8 *sa_path_get_dmac(struct sa_path_rec *rec) 6709fdca4daSDasaratharaman Chandramouli { 6719fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6729fdca4daSDasaratharaman Chandramouli return rec->roce.dmac; 6739fdca4daSDasaratharaman Chandramouli return NULL; 6749fdca4daSDasaratharaman Chandramouli } 6759fdca4daSDasaratharaman Chandramouli 6769fdca4daSDasaratharaman Chandramouli static inline int sa_path_get_ifindex(struct sa_path_rec *rec) 6779fdca4daSDasaratharaman Chandramouli { 6789fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6799fdca4daSDasaratharaman Chandramouli return rec->roce.ifindex; 6809fdca4daSDasaratharaman Chandramouli return 0; 6819fdca4daSDasaratharaman Chandramouli } 6829fdca4daSDasaratharaman Chandramouli 6839fdca4daSDasaratharaman Chandramouli static inline struct net *sa_path_get_ndev(struct sa_path_rec *rec) 6849fdca4daSDasaratharaman Chandramouli { 6859fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6869fdca4daSDasaratharaman Chandramouli return rec->roce.net; 6879fdca4daSDasaratharaman Chandramouli return NULL; 6889fdca4daSDasaratharaman Chandramouli } 6899fdca4daSDasaratharaman Chandramouli 6909fdca4daSDasaratharaman Chandramouli static inline struct net_device *ib_get_ndev_from_path(struct sa_path_rec *rec) 6919fdca4daSDasaratharaman Chandramouli { 6929fdca4daSDasaratharaman Chandramouli return sa_path_get_ndev(rec) ? 6939fdca4daSDasaratharaman Chandramouli dev_get_by_index(sa_path_get_ndev(rec), 6949fdca4daSDasaratharaman Chandramouli sa_path_get_ifindex(rec)) 6959fdca4daSDasaratharaman Chandramouli : NULL; 6969fdca4daSDasaratharaman Chandramouli } 6979fdca4daSDasaratharaman Chandramouli 698a4d61e84SRoland Dreier #endif /* IB_SA_H */ 699