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 166*114cc9c4SParav Pandit /** 167*114cc9c4SParav Pandit * struct sa_path_rec_roce - RoCE specific portion of the path record entry 168*114cc9c4SParav Pandit * @route_resolved: When set, it indicates that this route is already 169*114cc9c4SParav Pandit * resolved for this path record entry. 170*114cc9c4SParav Pandit * @dmac: Destination mac address for the given DGID entry 171*114cc9c4SParav Pandit * of the path record entry. 172*114cc9c4SParav Pandit */ 1739fdca4daSDasaratharaman Chandramouli struct sa_path_rec_roce { 174*114cc9c4SParav Pandit bool route_resolved; 1759fdca4daSDasaratharaman Chandramouli u8 dmac[ETH_ALEN]; 1769fdca4daSDasaratharaman Chandramouli /* ignored in IB */ 1779fdca4daSDasaratharaman Chandramouli int ifindex; 1789fdca4daSDasaratharaman Chandramouli /* ignored in IB */ 1799fdca4daSDasaratharaman Chandramouli struct net *net; 1809fdca4daSDasaratharaman Chandramouli 1819fdca4daSDasaratharaman Chandramouli }; 1829fdca4daSDasaratharaman Chandramouli 18357520751SDasaratharaman Chandramouli struct sa_path_rec_opa { 18457520751SDasaratharaman Chandramouli __be32 dlid; 18557520751SDasaratharaman Chandramouli __be32 slid; 18657520751SDasaratharaman Chandramouli u8 raw_traffic; 18757520751SDasaratharaman Chandramouli u8 l2_8B; 18857520751SDasaratharaman Chandramouli u8 l2_10B; 18957520751SDasaratharaman Chandramouli u8 l2_9B; 19057520751SDasaratharaman Chandramouli u8 l2_16B; 19157520751SDasaratharaman Chandramouli u8 qos_type; 19257520751SDasaratharaman Chandramouli u8 qos_priority; 19357520751SDasaratharaman Chandramouli }; 19457520751SDasaratharaman Chandramouli 1959fdca4daSDasaratharaman Chandramouli struct sa_path_rec { 1969fdca4daSDasaratharaman Chandramouli union ib_gid dgid; 1979fdca4daSDasaratharaman Chandramouli union ib_gid sgid; 198d3957b86SMajd Dibbiny __be64 service_id; 199a4d61e84SRoland Dreier /* reserved */ 200a4d61e84SRoland Dreier __be32 flow_label; 201a4d61e84SRoland Dreier u8 hop_limit; 202a4d61e84SRoland Dreier u8 traffic_class; 20355efcfcdSJason Gunthorpe u8 reversible; 204a4d61e84SRoland Dreier u8 numb_path; 205a4d61e84SRoland Dreier __be16 pkey; 206733d65feSSean Hefty __be16 qos_class; 207a4d61e84SRoland Dreier u8 sl; 208a4d61e84SRoland Dreier u8 mtu_selector; 209a4d61e84SRoland Dreier u8 mtu; 210a4d61e84SRoland Dreier u8 rate_selector; 211a4d61e84SRoland Dreier u8 rate; 212a4d61e84SRoland Dreier u8 packet_life_time_selector; 213a4d61e84SRoland Dreier u8 packet_life_time; 214a4d61e84SRoland Dreier u8 preference; 2159fdca4daSDasaratharaman Chandramouli union { 2169fdca4daSDasaratharaman Chandramouli struct sa_path_rec_ib ib; 2179fdca4daSDasaratharaman Chandramouli struct sa_path_rec_roce roce; 21857520751SDasaratharaman Chandramouli struct sa_path_rec_opa opa; 2199fdca4daSDasaratharaman Chandramouli }; 220dfa834e1SDasaratharaman Chandramouli enum sa_path_rec_type rec_type; 221a4d61e84SRoland Dreier }; 222a4d61e84SRoland Dreier 223dfa834e1SDasaratharaman Chandramouli static inline enum ib_gid_type 224dfa834e1SDasaratharaman Chandramouli sa_conv_pathrec_to_gid_type(struct sa_path_rec *rec) 225dfa834e1SDasaratharaman Chandramouli { 226dfa834e1SDasaratharaman Chandramouli switch (rec->rec_type) { 227dfa834e1SDasaratharaman Chandramouli case SA_PATH_REC_TYPE_ROCE_V1: 228dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_ROCE; 229dfa834e1SDasaratharaman Chandramouli case SA_PATH_REC_TYPE_ROCE_V2: 230dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_ROCE_UDP_ENCAP; 231dfa834e1SDasaratharaman Chandramouli default: 232dfa834e1SDasaratharaman Chandramouli return IB_GID_TYPE_IB; 233dfa834e1SDasaratharaman Chandramouli } 234dfa834e1SDasaratharaman Chandramouli } 235dfa834e1SDasaratharaman Chandramouli 236dfa834e1SDasaratharaman Chandramouli static inline enum sa_path_rec_type 237dfa834e1SDasaratharaman Chandramouli sa_conv_gid_to_pathrec_type(enum ib_gid_type type) 238dfa834e1SDasaratharaman Chandramouli { 239dfa834e1SDasaratharaman Chandramouli switch (type) { 240dfa834e1SDasaratharaman Chandramouli case IB_GID_TYPE_ROCE: 241dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_ROCE_V1; 242dfa834e1SDasaratharaman Chandramouli case IB_GID_TYPE_ROCE_UDP_ENCAP: 243dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_ROCE_V2; 244dfa834e1SDasaratharaman Chandramouli default: 245dfa834e1SDasaratharaman Chandramouli return SA_PATH_REC_TYPE_IB; 246dfa834e1SDasaratharaman Chandramouli } 247dfa834e1SDasaratharaman Chandramouli } 248dfa834e1SDasaratharaman Chandramouli 24957520751SDasaratharaman Chandramouli static inline void path_conv_opa_to_ib(struct sa_path_rec *ib, 25057520751SDasaratharaman Chandramouli struct sa_path_rec *opa) 25157520751SDasaratharaman Chandramouli { 25257520751SDasaratharaman Chandramouli if ((be32_to_cpu(opa->opa.dlid) >= 25357520751SDasaratharaman Chandramouli be16_to_cpu(IB_MULTICAST_LID_BASE)) || 25457520751SDasaratharaman Chandramouli (be32_to_cpu(opa->opa.slid) >= 25557520751SDasaratharaman Chandramouli be16_to_cpu(IB_MULTICAST_LID_BASE))) { 25657520751SDasaratharaman Chandramouli /* Create OPA GID and zero out the LID */ 25757520751SDasaratharaman Chandramouli ib->dgid.global.interface_id 25857520751SDasaratharaman Chandramouli = OPA_MAKE_ID(be32_to_cpu(opa->opa.dlid)); 25957520751SDasaratharaman Chandramouli ib->dgid.global.subnet_prefix 26057520751SDasaratharaman Chandramouli = opa->dgid.global.subnet_prefix; 26157520751SDasaratharaman Chandramouli ib->sgid.global.interface_id 26257520751SDasaratharaman Chandramouli = OPA_MAKE_ID(be32_to_cpu(opa->opa.slid)); 26357520751SDasaratharaman Chandramouli ib->dgid.global.subnet_prefix 26457520751SDasaratharaman Chandramouli = opa->dgid.global.subnet_prefix; 26557520751SDasaratharaman Chandramouli ib->ib.dlid = 0; 26657520751SDasaratharaman Chandramouli 26757520751SDasaratharaman Chandramouli ib->ib.slid = 0; 26857520751SDasaratharaman Chandramouli } else { 26957520751SDasaratharaman Chandramouli ib->ib.dlid = htons(ntohl(opa->opa.dlid)); 27057520751SDasaratharaman Chandramouli ib->ib.slid = htons(ntohl(opa->opa.slid)); 27157520751SDasaratharaman Chandramouli } 272d3957b86SMajd Dibbiny ib->service_id = opa->service_id; 27357520751SDasaratharaman Chandramouli ib->ib.raw_traffic = opa->opa.raw_traffic; 27457520751SDasaratharaman Chandramouli } 27557520751SDasaratharaman Chandramouli 27657520751SDasaratharaman Chandramouli static inline void path_conv_ib_to_opa(struct sa_path_rec *opa, 27757520751SDasaratharaman Chandramouli struct sa_path_rec *ib) 27857520751SDasaratharaman Chandramouli { 27957520751SDasaratharaman Chandramouli __be32 slid, dlid; 28057520751SDasaratharaman Chandramouli 28157520751SDasaratharaman Chandramouli if ((ib_is_opa_gid(&ib->sgid)) || 28257520751SDasaratharaman Chandramouli (ib_is_opa_gid(&ib->dgid))) { 28357520751SDasaratharaman Chandramouli slid = htonl(opa_get_lid_from_gid(&ib->sgid)); 28457520751SDasaratharaman Chandramouli dlid = htonl(opa_get_lid_from_gid(&ib->dgid)); 28557520751SDasaratharaman Chandramouli } else { 28657520751SDasaratharaman Chandramouli slid = htonl(ntohs(ib->ib.slid)); 28757520751SDasaratharaman Chandramouli dlid = htonl(ntohs(ib->ib.dlid)); 28857520751SDasaratharaman Chandramouli } 28957520751SDasaratharaman Chandramouli opa->opa.slid = slid; 29057520751SDasaratharaman Chandramouli opa->opa.dlid = dlid; 291d3957b86SMajd Dibbiny opa->service_id = ib->service_id; 29257520751SDasaratharaman Chandramouli opa->opa.raw_traffic = ib->ib.raw_traffic; 29357520751SDasaratharaman Chandramouli } 29457520751SDasaratharaman Chandramouli 29557520751SDasaratharaman Chandramouli /* Convert from OPA to IB path record */ 29657520751SDasaratharaman Chandramouli static inline void sa_convert_path_opa_to_ib(struct sa_path_rec *dest, 29757520751SDasaratharaman Chandramouli struct sa_path_rec *src) 29857520751SDasaratharaman Chandramouli { 29957520751SDasaratharaman Chandramouli if (src->rec_type != SA_PATH_REC_TYPE_OPA) 30057520751SDasaratharaman Chandramouli return; 30157520751SDasaratharaman Chandramouli 30257520751SDasaratharaman Chandramouli *dest = *src; 30357520751SDasaratharaman Chandramouli dest->rec_type = SA_PATH_REC_TYPE_IB; 30457520751SDasaratharaman Chandramouli path_conv_opa_to_ib(dest, src); 30557520751SDasaratharaman Chandramouli } 30657520751SDasaratharaman Chandramouli 30757520751SDasaratharaman Chandramouli /* Convert from IB to OPA path record */ 30857520751SDasaratharaman Chandramouli static inline void sa_convert_path_ib_to_opa(struct sa_path_rec *dest, 30957520751SDasaratharaman Chandramouli struct sa_path_rec *src) 31057520751SDasaratharaman Chandramouli { 31157520751SDasaratharaman Chandramouli if (src->rec_type != SA_PATH_REC_TYPE_IB) 31257520751SDasaratharaman Chandramouli return; 31357520751SDasaratharaman Chandramouli 31457520751SDasaratharaman Chandramouli /* Do a structure copy and overwrite the relevant fields */ 31557520751SDasaratharaman Chandramouli *dest = *src; 31657520751SDasaratharaman Chandramouli dest->rec_type = SA_PATH_REC_TYPE_OPA; 31757520751SDasaratharaman Chandramouli path_conv_ib_to_opa(dest, src); 31857520751SDasaratharaman Chandramouli } 31957520751SDasaratharaman Chandramouli 320a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MGID IB_SA_COMP_MASK( 0) 321a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PORT_GID IB_SA_COMP_MASK( 1) 322a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_QKEY IB_SA_COMP_MASK( 2) 323a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MLID IB_SA_COMP_MASK( 3) 324a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU_SELECTOR IB_SA_COMP_MASK( 4) 325a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_MTU IB_SA_COMP_MASK( 5) 326a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS IB_SA_COMP_MASK( 6) 327a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PKEY IB_SA_COMP_MASK( 7) 328a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE_SELECTOR IB_SA_COMP_MASK( 8) 329a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_RATE IB_SA_COMP_MASK( 9) 330a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR IB_SA_COMP_MASK(10) 331a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME IB_SA_COMP_MASK(11) 332a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SL IB_SA_COMP_MASK(12) 333a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_FLOW_LABEL IB_SA_COMP_MASK(13) 334a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_HOP_LIMIT IB_SA_COMP_MASK(14) 335a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_SCOPE IB_SA_COMP_MASK(15) 336a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_JOIN_STATE IB_SA_COMP_MASK(16) 337a4d61e84SRoland Dreier #define IB_SA_MCMEMBER_REC_PROXY_JOIN IB_SA_COMP_MASK(17) 338a4d61e84SRoland Dreier 339a4d61e84SRoland Dreier struct ib_sa_mcmember_rec { 340a4d61e84SRoland Dreier union ib_gid mgid; 341a4d61e84SRoland Dreier union ib_gid port_gid; 342a4d61e84SRoland Dreier __be32 qkey; 343a4d61e84SRoland Dreier __be16 mlid; 344a4d61e84SRoland Dreier u8 mtu_selector; 345a4d61e84SRoland Dreier u8 mtu; 346a4d61e84SRoland Dreier u8 traffic_class; 347a4d61e84SRoland Dreier __be16 pkey; 348a4d61e84SRoland Dreier u8 rate_selector; 349a4d61e84SRoland Dreier u8 rate; 350a4d61e84SRoland Dreier u8 packet_life_time_selector; 351a4d61e84SRoland Dreier u8 packet_life_time; 352a4d61e84SRoland Dreier u8 sl; 353a4d61e84SRoland Dreier __be32 flow_label; 354a4d61e84SRoland Dreier u8 hop_limit; 355a4d61e84SRoland Dreier u8 scope; 356a4d61e84SRoland Dreier u8 join_state; 35755efcfcdSJason Gunthorpe u8 proxy_join; 358a4d61e84SRoland Dreier }; 359a4d61e84SRoland Dreier 360a4d61e84SRoland Dreier /* Service Record Component Mask Sec 15.2.5.14 Ver 1.1 */ 361a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_ID IB_SA_COMP_MASK( 0) 362a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_GID IB_SA_COMP_MASK( 1) 363a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_PKEY IB_SA_COMP_MASK( 2) 364a4d61e84SRoland Dreier /* reserved: 3 */ 365a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_LEASE IB_SA_COMP_MASK( 4) 366a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_KEY IB_SA_COMP_MASK( 5) 367a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_NAME IB_SA_COMP_MASK( 6) 368a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_0 IB_SA_COMP_MASK( 7) 369a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_1 IB_SA_COMP_MASK( 8) 370a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_2 IB_SA_COMP_MASK( 9) 371a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_3 IB_SA_COMP_MASK(10) 372a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_4 IB_SA_COMP_MASK(11) 373a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_5 IB_SA_COMP_MASK(12) 374a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_6 IB_SA_COMP_MASK(13) 375a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_7 IB_SA_COMP_MASK(14) 376a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_8 IB_SA_COMP_MASK(15) 377a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_9 IB_SA_COMP_MASK(16) 378a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_10 IB_SA_COMP_MASK(17) 379a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_11 IB_SA_COMP_MASK(18) 380a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_12 IB_SA_COMP_MASK(19) 381a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_13 IB_SA_COMP_MASK(20) 382a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_14 IB_SA_COMP_MASK(21) 383a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA8_15 IB_SA_COMP_MASK(22) 384a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_0 IB_SA_COMP_MASK(23) 385a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_1 IB_SA_COMP_MASK(24) 386a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_2 IB_SA_COMP_MASK(25) 387a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_3 IB_SA_COMP_MASK(26) 388a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_4 IB_SA_COMP_MASK(27) 389a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_5 IB_SA_COMP_MASK(28) 390a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_6 IB_SA_COMP_MASK(29) 391a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA16_7 IB_SA_COMP_MASK(30) 392a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_0 IB_SA_COMP_MASK(31) 393a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_1 IB_SA_COMP_MASK(32) 394a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_2 IB_SA_COMP_MASK(33) 395a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA32_3 IB_SA_COMP_MASK(34) 396a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_0 IB_SA_COMP_MASK(35) 397a4d61e84SRoland Dreier #define IB_SA_SERVICE_REC_SERVICE_DATA64_1 IB_SA_COMP_MASK(36) 398a4d61e84SRoland Dreier 399a4d61e84SRoland Dreier #define IB_DEFAULT_SERVICE_LEASE 0xFFFFFFFF 400a4d61e84SRoland Dreier 401a4d61e84SRoland Dreier struct ib_sa_service_rec { 402a4d61e84SRoland Dreier u64 id; 403a4d61e84SRoland Dreier union ib_gid gid; 404a4d61e84SRoland Dreier __be16 pkey; 405a4d61e84SRoland Dreier /* reserved */ 406a4d61e84SRoland Dreier u32 lease; 407a4d61e84SRoland Dreier u8 key[16]; 408a4d61e84SRoland Dreier u8 name[64]; 409a4d61e84SRoland Dreier u8 data8[16]; 410a4d61e84SRoland Dreier u16 data16[8]; 411a4d61e84SRoland Dreier u32 data32[4]; 412a4d61e84SRoland Dreier u64 data64[2]; 413a4d61e84SRoland Dreier }; 414a4d61e84SRoland Dreier 415aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_LID IB_SA_COMP_MASK(0) 416aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_BLOCK_NUM IB_SA_COMP_MASK(1) 417aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES1 IB_SA_COMP_MASK(2) 418aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_RES2 IB_SA_COMP_MASK(3) 419aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID0 IB_SA_COMP_MASK(4) 420aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID1 IB_SA_COMP_MASK(5) 421aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID2 IB_SA_COMP_MASK(6) 422aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID3 IB_SA_COMP_MASK(7) 423aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID4 IB_SA_COMP_MASK(8) 424aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID5 IB_SA_COMP_MASK(9) 425aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID6 IB_SA_COMP_MASK(10) 426aeab97edSErez Shitrit #define IB_SA_GUIDINFO_REC_GID7 IB_SA_COMP_MASK(11) 427aeab97edSErez Shitrit 428aeab97edSErez Shitrit struct ib_sa_guidinfo_rec { 429aeab97edSErez Shitrit __be16 lid; 430aeab97edSErez Shitrit u8 block_num; 431aeab97edSErez Shitrit /* reserved */ 432aeab97edSErez Shitrit u8 res1; 433aeab97edSErez Shitrit __be32 res2; 434aeab97edSErez Shitrit u8 guid_info_list[64]; 435aeab97edSErez Shitrit }; 436aeab97edSErez Shitrit 437c1a0b23bSMichael S. Tsirkin struct ib_sa_client { 438c1a0b23bSMichael S. Tsirkin atomic_t users; 439c1a0b23bSMichael S. Tsirkin struct completion comp; 440c1a0b23bSMichael S. Tsirkin }; 441c1a0b23bSMichael S. Tsirkin 442c1a0b23bSMichael S. Tsirkin /** 443c1a0b23bSMichael S. Tsirkin * ib_sa_register_client - Register an SA client. 444c1a0b23bSMichael S. Tsirkin */ 445c1a0b23bSMichael S. Tsirkin void ib_sa_register_client(struct ib_sa_client *client); 446c1a0b23bSMichael S. Tsirkin 447c1a0b23bSMichael S. Tsirkin /** 448c1a0b23bSMichael S. Tsirkin * ib_sa_unregister_client - Deregister an SA client. 449c1a0b23bSMichael S. Tsirkin * @client: Client object to deregister. 450c1a0b23bSMichael S. Tsirkin */ 451c1a0b23bSMichael S. Tsirkin void ib_sa_unregister_client(struct ib_sa_client *client); 452c1a0b23bSMichael S. Tsirkin 453a4d61e84SRoland Dreier struct ib_sa_query; 454a4d61e84SRoland Dreier 455a4d61e84SRoland Dreier void ib_sa_cancel_query(int id, struct ib_sa_query *query); 456a4d61e84SRoland Dreier 457c1a0b23bSMichael S. Tsirkin int ib_sa_path_rec_get(struct ib_sa_client *client, 458c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 459c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *rec, 460a4d61e84SRoland Dreier ib_sa_comp_mask comp_mask, 461dd0fc66fSAl Viro int timeout_ms, gfp_t gfp_mask, 462a4d61e84SRoland Dreier void (*callback)(int status, 463c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *resp, 464a4d61e84SRoland Dreier void *context), 465a4d61e84SRoland Dreier void *context, 466a4d61e84SRoland Dreier struct ib_sa_query **query); 467a4d61e84SRoland Dreier 468c1a0b23bSMichael S. Tsirkin int ib_sa_service_rec_query(struct ib_sa_client *client, 469c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 470a4d61e84SRoland Dreier u8 method, 471a4d61e84SRoland Dreier struct ib_sa_service_rec *rec, 472a4d61e84SRoland Dreier ib_sa_comp_mask comp_mask, 473dd0fc66fSAl Viro int timeout_ms, gfp_t gfp_mask, 474a4d61e84SRoland Dreier void (*callback)(int status, 475a4d61e84SRoland Dreier struct ib_sa_service_rec *resp, 476a4d61e84SRoland Dreier void *context), 477a4d61e84SRoland Dreier void *context, 478a4d61e84SRoland Dreier struct ib_sa_query **sa_query); 479a4d61e84SRoland Dreier 480faec2f7bSSean Hefty struct ib_sa_multicast { 481faec2f7bSSean Hefty struct ib_sa_mcmember_rec rec; 482faec2f7bSSean Hefty ib_sa_comp_mask comp_mask; 483faec2f7bSSean Hefty int (*callback)(int status, 484faec2f7bSSean Hefty struct ib_sa_multicast *multicast); 485faec2f7bSSean Hefty void *context; 486faec2f7bSSean Hefty }; 487a4d61e84SRoland Dreier 488a4d61e84SRoland Dreier /** 489faec2f7bSSean Hefty * ib_sa_join_multicast - Initiates a join request to the specified multicast 490faec2f7bSSean Hefty * group. 491c1a0b23bSMichael S. Tsirkin * @client: SA client 492faec2f7bSSean Hefty * @device: Device associated with the multicast group. 493faec2f7bSSean Hefty * @port_num: Port on the specified device to associate with the multicast 494faec2f7bSSean Hefty * group. 495faec2f7bSSean Hefty * @rec: SA multicast member record specifying group attributes. 496faec2f7bSSean Hefty * @comp_mask: Component mask indicating which group attributes of %rec are 497faec2f7bSSean Hefty * valid. 498faec2f7bSSean Hefty * @gfp_mask: GFP mask for memory allocations. 499faec2f7bSSean Hefty * @callback: User callback invoked once the join operation completes. 500faec2f7bSSean Hefty * @context: User specified context stored with the ib_sa_multicast structure. 501a4d61e84SRoland Dreier * 502faec2f7bSSean Hefty * This call initiates a multicast join request with the SA for the specified 503faec2f7bSSean Hefty * multicast group. If the join operation is started successfully, it returns 504faec2f7bSSean Hefty * an ib_sa_multicast structure that is used to track the multicast operation. 505faec2f7bSSean Hefty * Users must free this structure by calling ib_free_multicast, even if the 506faec2f7bSSean Hefty * join operation later fails. (The callback status is non-zero.) 507a4d61e84SRoland Dreier * 508faec2f7bSSean Hefty * If the join operation fails; status will be non-zero, with the following 509faec2f7bSSean Hefty * failures possible: 510faec2f7bSSean Hefty * -ETIMEDOUT: The request timed out. 511faec2f7bSSean Hefty * -EIO: An error occurred sending the query. 512faec2f7bSSean Hefty * -EINVAL: The MCMemberRecord values differed from the existing group's. 513faec2f7bSSean Hefty * -ENETRESET: Indicates that an fatal error has occurred on the multicast 514faec2f7bSSean Hefty * group, and the user must rejoin the group to continue using it. 515a4d61e84SRoland Dreier */ 516faec2f7bSSean Hefty struct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client, 517c1a0b23bSMichael S. Tsirkin struct ib_device *device, u8 port_num, 518a4d61e84SRoland Dreier struct ib_sa_mcmember_rec *rec, 519faec2f7bSSean Hefty ib_sa_comp_mask comp_mask, gfp_t gfp_mask, 520faec2f7bSSean Hefty int (*callback)(int status, 521faec2f7bSSean Hefty struct ib_sa_multicast 522faec2f7bSSean Hefty *multicast), 523faec2f7bSSean Hefty void *context); 524faec2f7bSSean Hefty 525faec2f7bSSean Hefty /** 526faec2f7bSSean Hefty * ib_free_multicast - Frees the multicast tracking structure, and releases 527faec2f7bSSean Hefty * any reference on the multicast group. 528faec2f7bSSean Hefty * @multicast: Multicast tracking structure allocated by ib_join_multicast. 529faec2f7bSSean Hefty * 530faec2f7bSSean Hefty * This call blocks until the multicast identifier is destroyed. It may 531faec2f7bSSean Hefty * not be called from within the multicast callback; however, returning a non- 532faec2f7bSSean Hefty * zero value from the callback will result in destroying the multicast 533faec2f7bSSean Hefty * tracking structure. 534faec2f7bSSean Hefty */ 535faec2f7bSSean Hefty void ib_sa_free_multicast(struct ib_sa_multicast *multicast); 536faec2f7bSSean Hefty 537faec2f7bSSean Hefty /** 538faec2f7bSSean Hefty * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and 539faec2f7bSSean Hefty * returns it if found. 540faec2f7bSSean Hefty * @device: Device associated with the multicast group. 541faec2f7bSSean Hefty * @port_num: Port on the specified device to associate with the multicast 542faec2f7bSSean Hefty * group. 543faec2f7bSSean Hefty * @mgid: MGID of multicast group. 544faec2f7bSSean Hefty * @rec: Location to copy SA multicast member record. 545faec2f7bSSean Hefty */ 546faec2f7bSSean Hefty int ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num, 547faec2f7bSSean Hefty union ib_gid *mgid, struct ib_sa_mcmember_rec *rec); 548faec2f7bSSean Hefty 549faec2f7bSSean Hefty /** 550faec2f7bSSean Hefty * ib_init_ah_from_mcmember - Initialize address handle attributes based on 551faec2f7bSSean Hefty * an SA multicast member record. 552faec2f7bSSean Hefty */ 553faec2f7bSSean Hefty int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num, 554faec2f7bSSean Hefty struct ib_sa_mcmember_rec *rec, 555bee3c3c9SMoni Shoua struct net_device *ndev, 556bee3c3c9SMoni Shoua enum ib_gid_type gid_type, 55790898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr); 558a4d61e84SRoland Dreier 5596d969a47SSean Hefty /** 5604ad6a024SParav Pandit * ib_init_ah_attr_from_path - Initialize address handle attributes based on 5614ad6a024SParav Pandit * an SA path record. 5626d969a47SSean Hefty */ 5634ad6a024SParav Pandit int ib_init_ah_attr_from_path(struct ib_device *device, u8 port_num, 564c2f8fc4eSDasaratharaman Chandramouli struct sa_path_rec *rec, 56590898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr); 566a4d61e84SRoland Dreier 567a7ca1f00SSean Hefty /** 5682e08b587SSean Hefty * ib_sa_pack_path - Conert a path record from struct ib_sa_path_rec 5692e08b587SSean Hefty * to IB MAD wire format. 5702e08b587SSean Hefty */ 571c2f8fc4eSDasaratharaman Chandramouli void ib_sa_pack_path(struct sa_path_rec *rec, void *attribute); 5722e08b587SSean Hefty 5732e08b587SSean Hefty /** 574a7ca1f00SSean Hefty * ib_sa_unpack_path - Convert a path record from MAD format to struct 575a7ca1f00SSean Hefty * ib_sa_path_rec. 576a7ca1f00SSean Hefty */ 577c2f8fc4eSDasaratharaman Chandramouli void ib_sa_unpack_path(void *attribute, struct sa_path_rec *rec); 578a7ca1f00SSean Hefty 579aeab97edSErez Shitrit /* Support GuidInfoRecord */ 580aeab97edSErez Shitrit int ib_sa_guid_info_rec_query(struct ib_sa_client *client, 581aeab97edSErez Shitrit struct ib_device *device, u8 port_num, 582aeab97edSErez Shitrit struct ib_sa_guidinfo_rec *rec, 583aeab97edSErez Shitrit ib_sa_comp_mask comp_mask, u8 method, 584aeab97edSErez Shitrit int timeout_ms, gfp_t gfp_mask, 585aeab97edSErez Shitrit void (*callback)(int status, 586aeab97edSErez Shitrit struct ib_sa_guidinfo_rec *resp, 587aeab97edSErez Shitrit void *context), 588aeab97edSErez Shitrit void *context, 589aeab97edSErez Shitrit struct ib_sa_query **sa_query); 5902e08b587SSean Hefty 591ee1c60b1SDasaratharaman Chandramouli bool ib_sa_sendonly_fullmem_support(struct ib_sa_client *client, 592ee1c60b1SDasaratharaman Chandramouli struct ib_device *device, 593ee1c60b1SDasaratharaman Chandramouli u8 port_num); 594628e6f75SErez Shitrit 5959fdca4daSDasaratharaman Chandramouli static inline bool sa_path_is_roce(struct sa_path_rec *rec) 5969fdca4daSDasaratharaman Chandramouli { 5979fdca4daSDasaratharaman Chandramouli return ((rec->rec_type == SA_PATH_REC_TYPE_ROCE_V1) || 5989fdca4daSDasaratharaman Chandramouli (rec->rec_type == SA_PATH_REC_TYPE_ROCE_V2)); 5999fdca4daSDasaratharaman Chandramouli } 6009fdca4daSDasaratharaman Chandramouli 6010a514159SParav Pandit static inline bool sa_path_is_opa(struct sa_path_rec *rec) 6020a514159SParav Pandit { 6030a514159SParav Pandit return (rec->rec_type == SA_PATH_REC_TYPE_OPA); 6040a514159SParav Pandit } 6050a514159SParav Pandit 6069d187177SBart Van Assche static inline void sa_path_set_slid(struct sa_path_rec *rec, u32 slid) 6079fdca4daSDasaratharaman Chandramouli { 6089fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6099d187177SBart Van Assche rec->ib.slid = cpu_to_be16(slid); 61057520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 6119d187177SBart Van Assche rec->opa.slid = cpu_to_be32(slid); 6129fdca4daSDasaratharaman Chandramouli } 6139fdca4daSDasaratharaman Chandramouli 6149d187177SBart Van Assche static inline void sa_path_set_dlid(struct sa_path_rec *rec, u32 dlid) 6159fdca4daSDasaratharaman Chandramouli { 6169fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6179d187177SBart Van Assche rec->ib.dlid = cpu_to_be16(dlid); 61857520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 6199d187177SBart Van Assche rec->opa.dlid = cpu_to_be32(dlid); 6209fdca4daSDasaratharaman Chandramouli } 6219fdca4daSDasaratharaman Chandramouli 6229fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_raw_traffic(struct sa_path_rec *rec, 6239fdca4daSDasaratharaman Chandramouli u8 raw_traffic) 6249fdca4daSDasaratharaman Chandramouli { 6259fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6269fdca4daSDasaratharaman Chandramouli rec->ib.raw_traffic = raw_traffic; 62757520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 62857520751SDasaratharaman Chandramouli rec->opa.raw_traffic = raw_traffic; 6299fdca4daSDasaratharaman Chandramouli } 6309fdca4daSDasaratharaman Chandramouli 63157520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_slid(struct sa_path_rec *rec) 6329fdca4daSDasaratharaman Chandramouli { 6339fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 63457520751SDasaratharaman Chandramouli return htonl(ntohs(rec->ib.slid)); 63557520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 63657520751SDasaratharaman Chandramouli return rec->opa.slid; 6379fdca4daSDasaratharaman Chandramouli return 0; 6389fdca4daSDasaratharaman Chandramouli } 6399fdca4daSDasaratharaman Chandramouli 64057520751SDasaratharaman Chandramouli static inline __be32 sa_path_get_dlid(struct sa_path_rec *rec) 6419fdca4daSDasaratharaman Chandramouli { 6429fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 64357520751SDasaratharaman Chandramouli return htonl(ntohs(rec->ib.dlid)); 64457520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 64557520751SDasaratharaman Chandramouli return rec->opa.dlid; 6469fdca4daSDasaratharaman Chandramouli return 0; 6479fdca4daSDasaratharaman Chandramouli } 6489fdca4daSDasaratharaman Chandramouli 6499fdca4daSDasaratharaman Chandramouli static inline u8 sa_path_get_raw_traffic(struct sa_path_rec *rec) 6509fdca4daSDasaratharaman Chandramouli { 6519fdca4daSDasaratharaman Chandramouli if (rec->rec_type == SA_PATH_REC_TYPE_IB) 6529fdca4daSDasaratharaman Chandramouli return rec->ib.raw_traffic; 65357520751SDasaratharaman Chandramouli else if (rec->rec_type == SA_PATH_REC_TYPE_OPA) 65457520751SDasaratharaman Chandramouli return rec->opa.raw_traffic; 6559fdca4daSDasaratharaman Chandramouli return 0; 6569fdca4daSDasaratharaman Chandramouli } 6579fdca4daSDasaratharaman Chandramouli 6589fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac(struct sa_path_rec *rec, u8 *dmac) 6599fdca4daSDasaratharaman Chandramouli { 6609fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6619fdca4daSDasaratharaman Chandramouli memcpy(rec->roce.dmac, dmac, ETH_ALEN); 6629fdca4daSDasaratharaman Chandramouli } 6639fdca4daSDasaratharaman Chandramouli 6649fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_dmac_zero(struct sa_path_rec *rec) 6659fdca4daSDasaratharaman Chandramouli { 6669fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6679fdca4daSDasaratharaman Chandramouli eth_zero_addr(rec->roce.dmac); 6689fdca4daSDasaratharaman Chandramouli } 6699fdca4daSDasaratharaman Chandramouli 6709fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_ifindex(struct sa_path_rec *rec, int ifindex) 6719fdca4daSDasaratharaman Chandramouli { 6729fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6739fdca4daSDasaratharaman Chandramouli rec->roce.ifindex = ifindex; 6749fdca4daSDasaratharaman Chandramouli } 6759fdca4daSDasaratharaman Chandramouli 6769fdca4daSDasaratharaman Chandramouli static inline void sa_path_set_ndev(struct sa_path_rec *rec, struct net *net) 6779fdca4daSDasaratharaman Chandramouli { 6789fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6799fdca4daSDasaratharaman Chandramouli rec->roce.net = net; 6809fdca4daSDasaratharaman Chandramouli } 6819fdca4daSDasaratharaman Chandramouli 6829fdca4daSDasaratharaman Chandramouli static inline u8 *sa_path_get_dmac(struct sa_path_rec *rec) 6839fdca4daSDasaratharaman Chandramouli { 6849fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6859fdca4daSDasaratharaman Chandramouli return rec->roce.dmac; 6869fdca4daSDasaratharaman Chandramouli return NULL; 6879fdca4daSDasaratharaman Chandramouli } 6889fdca4daSDasaratharaman Chandramouli 6899fdca4daSDasaratharaman Chandramouli static inline int sa_path_get_ifindex(struct sa_path_rec *rec) 6909fdca4daSDasaratharaman Chandramouli { 6919fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6929fdca4daSDasaratharaman Chandramouli return rec->roce.ifindex; 6939fdca4daSDasaratharaman Chandramouli return 0; 6949fdca4daSDasaratharaman Chandramouli } 6959fdca4daSDasaratharaman Chandramouli 6969fdca4daSDasaratharaman Chandramouli static inline struct net *sa_path_get_ndev(struct sa_path_rec *rec) 6979fdca4daSDasaratharaman Chandramouli { 6989fdca4daSDasaratharaman Chandramouli if (sa_path_is_roce(rec)) 6999fdca4daSDasaratharaman Chandramouli return rec->roce.net; 7009fdca4daSDasaratharaman Chandramouli return NULL; 7019fdca4daSDasaratharaman Chandramouli } 7029fdca4daSDasaratharaman Chandramouli 7039fdca4daSDasaratharaman Chandramouli static inline struct net_device *ib_get_ndev_from_path(struct sa_path_rec *rec) 7049fdca4daSDasaratharaman Chandramouli { 7059fdca4daSDasaratharaman Chandramouli return sa_path_get_ndev(rec) ? 7069fdca4daSDasaratharaman Chandramouli dev_get_by_index(sa_path_get_ndev(rec), 7079fdca4daSDasaratharaman Chandramouli sa_path_get_ifindex(rec)) 7089fdca4daSDasaratharaman Chandramouli : NULL; 7099fdca4daSDasaratharaman Chandramouli } 7109fdca4daSDasaratharaman Chandramouli 711a4d61e84SRoland Dreier #endif /* IB_SA_H */ 712