1fe267a55SPedro F. Giffuni /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0 3fe267a55SPedro F. Giffuni * 4aa0a1e58SJeff Roberson * Copyright (c) 2005 Voltaire Inc. All rights reserved. 5aa0a1e58SJeff Roberson * Copyright (c) 2005 Intel Corporation. All rights reserved. 6aa0a1e58SJeff Roberson * 7aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two 8aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU 9aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file 10aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the 11aa0a1e58SJeff Roberson * OpenIB.org BSD license below: 12aa0a1e58SJeff Roberson * 13aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or 14aa0a1e58SJeff Roberson * without modification, are permitted provided that the following 15aa0a1e58SJeff Roberson * conditions are met: 16aa0a1e58SJeff Roberson * 17aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above 18aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 19aa0a1e58SJeff Roberson * disclaimer. 20aa0a1e58SJeff Roberson * 21aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above 22aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 23aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials 24aa0a1e58SJeff Roberson * provided with the distribution. 25aa0a1e58SJeff Roberson * 26aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 30aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 31aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33aa0a1e58SJeff Roberson * SOFTWARE. 3409938b21SHans Petter Selasky * 3509938b21SHans Petter Selasky * $FreeBSD$ 36aa0a1e58SJeff Roberson */ 37aa0a1e58SJeff Roberson 38478d3005SHans Petter Selasky #if !defined(IB_ADDR_H) 39aa0a1e58SJeff Roberson #define IB_ADDR_H 40aa0a1e58SJeff Roberson 41aa0a1e58SJeff Roberson #include <linux/in.h> 42aa0a1e58SJeff Roberson #include <linux/in6.h> 43aa0a1e58SJeff Roberson #include <linux/if_arp.h> 44aa0a1e58SJeff Roberson #include <linux/netdevice.h> 45b5c1e0cbSHans Petter Selasky #include <linux/inetdevice.h> 46aa0a1e58SJeff Roberson #include <linux/socket.h> 47b5c1e0cbSHans Petter Selasky #include <linux/if_vlan.h> 48478d3005SHans Petter Selasky #include <net/ipv6.h> 49478d3005SHans Petter Selasky #include <net/if_inet6.h> 50478d3005SHans Petter Selasky #include <net/ip.h> 51aa0a1e58SJeff Roberson #include <rdma/ib_verbs.h> 52aa0a1e58SJeff Roberson #include <rdma/ib_pack.h> 53b5c1e0cbSHans Petter Selasky #include <net/ipv6.h> 54aa0a1e58SJeff Roberson 55d7c5a620SMatt Macy 56aa0a1e58SJeff Roberson struct rdma_addr_client { 57aa0a1e58SJeff Roberson atomic_t refcount; 58aa0a1e58SJeff Roberson struct completion comp; 59aa0a1e58SJeff Roberson }; 60aa0a1e58SJeff Roberson 61aa0a1e58SJeff Roberson /** 62aa0a1e58SJeff Roberson * rdma_addr_register_client - Register an address client. 63aa0a1e58SJeff Roberson */ 64aa0a1e58SJeff Roberson void rdma_addr_register_client(struct rdma_addr_client *client); 65aa0a1e58SJeff Roberson 66aa0a1e58SJeff Roberson /** 67aa0a1e58SJeff Roberson * rdma_addr_unregister_client - Deregister an address client. 68aa0a1e58SJeff Roberson * @client: Client object to deregister. 69aa0a1e58SJeff Roberson */ 70aa0a1e58SJeff Roberson void rdma_addr_unregister_client(struct rdma_addr_client *client); 71aa0a1e58SJeff Roberson 72478d3005SHans Petter Selasky /** 73478d3005SHans Petter Selasky * struct rdma_dev_addr - Contains resolved RDMA hardware addresses 74478d3005SHans Petter Selasky * @src_dev_addr: Source MAC address. 75478d3005SHans Petter Selasky * @dst_dev_addr: Destination MAC address. 76478d3005SHans Petter Selasky * @broadcast: Broadcast address of the device. 77478d3005SHans Petter Selasky * @dev_type: The interface hardware type of the device. 78478d3005SHans Petter Selasky * @bound_dev_if: An optional device interface index. 79478d3005SHans Petter Selasky * @transport: The transport type used. 80478d3005SHans Petter Selasky * @net: Network namespace containing the bound_dev_if net_dev. 81478d3005SHans Petter Selasky */ 82478d3005SHans Petter Selasky struct vnet; 83aa0a1e58SJeff Roberson struct rdma_dev_addr { 84aa0a1e58SJeff Roberson unsigned char src_dev_addr[MAX_ADDR_LEN]; 85aa0a1e58SJeff Roberson unsigned char dst_dev_addr[MAX_ADDR_LEN]; 86aa0a1e58SJeff Roberson unsigned char broadcast[MAX_ADDR_LEN]; 87aa0a1e58SJeff Roberson unsigned short dev_type; 88aa0a1e58SJeff Roberson int bound_dev_if; 89aa0a1e58SJeff Roberson enum rdma_transport_type transport; 90478d3005SHans Petter Selasky struct vnet *net; 91478d3005SHans Petter Selasky enum rdma_network_type network; 92478d3005SHans Petter Selasky int hoplimit; 93aa0a1e58SJeff Roberson }; 94aa0a1e58SJeff Roberson 95aa0a1e58SJeff Roberson /** 96aa0a1e58SJeff Roberson * rdma_translate_ip - Translate a local IP address to an RDMA hardware 97aa0a1e58SJeff Roberson * address. 98478d3005SHans Petter Selasky * 99bf8641feSHans Petter Selasky * The dev_addr->net and dev_addr->bound_dev_if fields must be initialized. 100aa0a1e58SJeff Roberson */ 101478d3005SHans Petter Selasky int rdma_translate_ip(const struct sockaddr *addr, 102bf8641feSHans Petter Selasky struct rdma_dev_addr *dev_addr); 103aa0a1e58SJeff Roberson 104aa0a1e58SJeff Roberson /** 105aa0a1e58SJeff Roberson * rdma_resolve_ip - Resolve source and destination IP addresses to 106aa0a1e58SJeff Roberson * RDMA hardware addresses. 107aa0a1e58SJeff Roberson * @client: Address client associated with request. 108aa0a1e58SJeff Roberson * @src_addr: An optional source address to use in the resolution. If a 109aa0a1e58SJeff Roberson * source address is not provided, a usable address will be returned via 110aa0a1e58SJeff Roberson * the callback. 111aa0a1e58SJeff Roberson * @dst_addr: The destination address to resolve. 112aa0a1e58SJeff Roberson * @addr: A reference to a data location that will receive the resolved 113aa0a1e58SJeff Roberson * addresses. The data location must remain valid until the callback has 114478d3005SHans Petter Selasky * been invoked. The net field of the addr struct must be valid. 115aa0a1e58SJeff Roberson * @timeout_ms: Amount of time to wait for the address resolution to complete. 116aa0a1e58SJeff Roberson * @callback: Call invoked once address resolution has completed, timed out, 117aa0a1e58SJeff Roberson * or been canceled. A status of 0 indicates success. 118aa0a1e58SJeff Roberson * @context: User-specified context associated with the call. 119aa0a1e58SJeff Roberson */ 120aa0a1e58SJeff Roberson int rdma_resolve_ip(struct rdma_addr_client *client, 121aa0a1e58SJeff Roberson struct sockaddr *src_addr, struct sockaddr *dst_addr, 122aa0a1e58SJeff Roberson struct rdma_dev_addr *addr, int timeout_ms, 123aa0a1e58SJeff Roberson void (*callback)(int status, struct sockaddr *src_addr, 124aa0a1e58SJeff Roberson struct rdma_dev_addr *addr, void *context), 125aa0a1e58SJeff Roberson void *context); 126aa0a1e58SJeff Roberson 127478d3005SHans Petter Selasky int rdma_resolve_ip_route(struct sockaddr *src_addr, 128478d3005SHans Petter Selasky const struct sockaddr *dst_addr, 129478d3005SHans Petter Selasky struct rdma_dev_addr *addr); 130478d3005SHans Petter Selasky 131aa0a1e58SJeff Roberson void rdma_addr_cancel(struct rdma_dev_addr *addr); 132aa0a1e58SJeff Roberson 133aa0a1e58SJeff Roberson int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev, 134aa0a1e58SJeff Roberson const unsigned char *dst_dev_addr); 135aa0a1e58SJeff Roberson 136478d3005SHans Petter Selasky int rdma_addr_size(struct sockaddr *addr); 137*855ad7cfSHans Petter Selasky int rdma_addr_size_in6(struct sockaddr_in6 *addr); 138*855ad7cfSHans Petter Selasky int rdma_addr_size_kss(struct sockaddr_storage *addr); 139478d3005SHans Petter Selasky 140478d3005SHans Petter Selasky int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid, 141478d3005SHans Petter Selasky const union ib_gid *dgid, 142bf8641feSHans Petter Selasky u8 *smac, struct net_device *dev, 143478d3005SHans Petter Selasky int *hoplimit); 144aa0a1e58SJeff Roberson 145aa0a1e58SJeff Roberson static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr) 146aa0a1e58SJeff Roberson { 147aa0a1e58SJeff Roberson return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9]; 148aa0a1e58SJeff Roberson } 149aa0a1e58SJeff Roberson 150aa0a1e58SJeff Roberson static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey) 151aa0a1e58SJeff Roberson { 152aa0a1e58SJeff Roberson dev_addr->broadcast[8] = pkey >> 8; 153aa0a1e58SJeff Roberson dev_addr->broadcast[9] = (unsigned char) pkey; 154aa0a1e58SJeff Roberson } 155aa0a1e58SJeff Roberson 156aa0a1e58SJeff Roberson static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr, 157aa0a1e58SJeff Roberson union ib_gid *gid) 158aa0a1e58SJeff Roberson { 159aa0a1e58SJeff Roberson memcpy(gid, dev_addr->broadcast + 4, sizeof *gid); 160aa0a1e58SJeff Roberson } 161aa0a1e58SJeff Roberson 162aa0a1e58SJeff Roberson static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr) 163aa0a1e58SJeff Roberson { 164aa0a1e58SJeff Roberson return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0; 165aa0a1e58SJeff Roberson } 166aa0a1e58SJeff Roberson 167aa0a1e58SJeff Roberson static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev) 168aa0a1e58SJeff Roberson { 169aa0a1e58SJeff Roberson uint16_t tag; 170aa0a1e58SJeff Roberson 171f4546fa3SHans Petter Selasky if (dev->if_pcp != IFNET_PCP_NONE) 172f4546fa3SHans Petter Selasky return 0x0000; /* prio-tagged traffic */ 173aa0a1e58SJeff Roberson if (VLAN_TAG(__DECONST(struct ifnet *, dev), &tag) != 0) 174aa0a1e58SJeff Roberson return 0xffff; 175aa0a1e58SJeff Roberson return tag; 176aa0a1e58SJeff Roberson } 177aa0a1e58SJeff Roberson 178478d3005SHans Petter Selasky static inline int rdma_ip2gid(const struct sockaddr *addr, union ib_gid *gid) 179b5c1e0cbSHans Petter Selasky { 180b5c1e0cbSHans Petter Selasky switch (addr->sa_family) { 181b5c1e0cbSHans Petter Selasky case AF_INET: 182478d3005SHans Petter Selasky ipv6_addr_set_v4mapped(((const struct sockaddr_in *) 183478d3005SHans Petter Selasky addr)->sin_addr.s_addr, 184b5c1e0cbSHans Petter Selasky (struct in6_addr *)gid); 185b5c1e0cbSHans Petter Selasky break; 186b5c1e0cbSHans Petter Selasky case AF_INET6: 187478d3005SHans Petter Selasky memcpy(gid->raw, &((const struct sockaddr_in6 *)addr)->sin6_addr, 16); 188aacb0377SHans Petter Selasky /* make sure scope ID gets zeroed inside GID */ 189aacb0377SHans Petter Selasky if (IN6_IS_SCOPE_LINKLOCAL((struct in6_addr *)gid->raw) || 190aacb0377SHans Petter Selasky IN6_IS_ADDR_MC_INTFACELOCAL((struct in6_addr *)gid->raw)) { 191aacb0377SHans Petter Selasky gid->raw[2] = 0; 192aacb0377SHans Petter Selasky gid->raw[3] = 0; 193aacb0377SHans Petter Selasky } 194b5c1e0cbSHans Petter Selasky break; 195b5c1e0cbSHans Petter Selasky default: 196b5c1e0cbSHans Petter Selasky return -EINVAL; 197b5c1e0cbSHans Petter Selasky } 198b5c1e0cbSHans Petter Selasky return 0; 199b5c1e0cbSHans Petter Selasky } 200b5c1e0cbSHans Petter Selasky 201b5c1e0cbSHans Petter Selasky /* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */ 202478d3005SHans Petter Selasky static inline void rdma_gid2ip(struct sockaddr *out, const union ib_gid *gid) 203b5c1e0cbSHans Petter Selasky { 204478d3005SHans Petter Selasky if (ipv6_addr_v4mapped((const struct in6_addr *)gid)) { 205b5c1e0cbSHans Petter Selasky struct sockaddr_in *out_in = (struct sockaddr_in *)out; 206b5c1e0cbSHans Petter Selasky memset(out_in, 0, sizeof(*out_in)); 207b5c1e0cbSHans Petter Selasky out_in->sin_len = sizeof(*out_in); 208b5c1e0cbSHans Petter Selasky out_in->sin_family = AF_INET; 209b5c1e0cbSHans Petter Selasky memcpy(&out_in->sin_addr.s_addr, gid->raw + 12, 4); 210b5c1e0cbSHans Petter Selasky } else { 211b5c1e0cbSHans Petter Selasky struct sockaddr_in6 *out_in = (struct sockaddr_in6 *)out; 212b5c1e0cbSHans Petter Selasky memset(out_in, 0, sizeof(*out_in)); 2130bab509bSHans Petter Selasky out_in->sin6_len = sizeof(*out_in); 214b5c1e0cbSHans Petter Selasky out_in->sin6_family = AF_INET6; 215b5c1e0cbSHans Petter Selasky memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16); 216b5c1e0cbSHans Petter Selasky } 217b5c1e0cbSHans Petter Selasky } 218b5c1e0cbSHans Petter Selasky 219aa0a1e58SJeff Roberson static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, 220aa0a1e58SJeff Roberson union ib_gid *gid) 221aa0a1e58SJeff Roberson { 222478d3005SHans Petter Selasky struct net_device *dev; 223478d3005SHans Petter Selasky struct ifaddr *ifa; 224478d3005SHans Petter Selasky 225478d3005SHans Petter Selasky dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if); 226478d3005SHans Petter Selasky if (dev) { 227d7c5a620SMatt Macy CK_STAILQ_FOREACH(ifa, &dev->if_addrhead, ifa_link) { 228478d3005SHans Petter Selasky if (ifa->ifa_addr == NULL || 229478d3005SHans Petter Selasky ifa->ifa_addr->sa_family != AF_INET) 230478d3005SHans Petter Selasky continue; 231478d3005SHans Petter Selasky ipv6_addr_set_v4mapped(((struct sockaddr_in *) 232478d3005SHans Petter Selasky ifa->ifa_addr)->sin_addr.s_addr, 233478d3005SHans Petter Selasky (struct in6_addr *)gid); 234478d3005SHans Petter Selasky break; 235478d3005SHans Petter Selasky } 236478d3005SHans Petter Selasky dev_put(dev); 237478d3005SHans Petter Selasky } 238aa0a1e58SJeff Roberson } 239aa0a1e58SJeff Roberson 240aa0a1e58SJeff Roberson static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 241aa0a1e58SJeff Roberson { 242aa0a1e58SJeff Roberson if (dev_addr->transport == RDMA_TRANSPORT_IB && 243aa0a1e58SJeff Roberson dev_addr->dev_type != ARPHRD_INFINIBAND) 244aa0a1e58SJeff Roberson iboe_addr_get_sgid(dev_addr, gid); 245aa0a1e58SJeff Roberson else 246aa0a1e58SJeff Roberson memcpy(gid, dev_addr->src_dev_addr + 247aa0a1e58SJeff Roberson rdma_addr_gid_offset(dev_addr), sizeof *gid); 248aa0a1e58SJeff Roberson } 249aa0a1e58SJeff Roberson 250aa0a1e58SJeff Roberson static inline void rdma_addr_set_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 251aa0a1e58SJeff Roberson { 252aa0a1e58SJeff Roberson memcpy(dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid); 253aa0a1e58SJeff Roberson } 254aa0a1e58SJeff Roberson 255aa0a1e58SJeff Roberson static inline void rdma_addr_get_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 256aa0a1e58SJeff Roberson { 257aa0a1e58SJeff Roberson memcpy(gid, dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid); 258aa0a1e58SJeff Roberson } 259aa0a1e58SJeff Roberson 260aa0a1e58SJeff Roberson static inline void rdma_addr_set_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 261aa0a1e58SJeff Roberson { 262aa0a1e58SJeff Roberson memcpy(dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid); 263aa0a1e58SJeff Roberson } 264aa0a1e58SJeff Roberson 265aa0a1e58SJeff Roberson static inline enum ib_mtu iboe_get_mtu(int mtu) 266aa0a1e58SJeff Roberson { 267aa0a1e58SJeff Roberson /* 268aa0a1e58SJeff Roberson * reduce IB headers from effective IBoE MTU. 28 stands for 269aa0a1e58SJeff Roberson * atomic header which is the biggest possible header after BTH 270aa0a1e58SJeff Roberson */ 271aa0a1e58SJeff Roberson mtu = mtu - IB_GRH_BYTES - IB_BTH_BYTES - 28; 272aa0a1e58SJeff Roberson 273aa0a1e58SJeff Roberson if (mtu >= ib_mtu_enum_to_int(IB_MTU_4096)) 274aa0a1e58SJeff Roberson return IB_MTU_4096; 275aa0a1e58SJeff Roberson else if (mtu >= ib_mtu_enum_to_int(IB_MTU_2048)) 276aa0a1e58SJeff Roberson return IB_MTU_2048; 277aa0a1e58SJeff Roberson else if (mtu >= ib_mtu_enum_to_int(IB_MTU_1024)) 278aa0a1e58SJeff Roberson return IB_MTU_1024; 279aa0a1e58SJeff Roberson else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512)) 280aa0a1e58SJeff Roberson return IB_MTU_512; 281aa0a1e58SJeff Roberson else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256)) 282aa0a1e58SJeff Roberson return IB_MTU_256; 283aa0a1e58SJeff Roberson else 284aa0a1e58SJeff Roberson return 0; 285aa0a1e58SJeff Roberson } 286aa0a1e58SJeff Roberson 287aa0a1e58SJeff Roberson static inline int iboe_get_rate(struct net_device *dev) 288aa0a1e58SJeff Roberson { 289478d3005SHans Petter Selasky uint64_t baudrate = dev->if_baudrate; 290478d3005SHans Petter Selasky #ifdef if_baudrate_pf 291478d3005SHans Petter Selasky int exp; 292478d3005SHans Petter Selasky for (exp = dev->if_baudrate_pf; exp > 0; exp--) 293478d3005SHans Petter Selasky baudrate *= 10; 294478d3005SHans Petter Selasky #endif 295478d3005SHans Petter Selasky if (baudrate >= IF_Gbps(40)) 296aa0a1e58SJeff Roberson return IB_RATE_40_GBPS; 297478d3005SHans Petter Selasky else if (baudrate >= IF_Gbps(30)) 298aa0a1e58SJeff Roberson return IB_RATE_30_GBPS; 299478d3005SHans Petter Selasky else if (baudrate >= IF_Gbps(20)) 300aa0a1e58SJeff Roberson return IB_RATE_20_GBPS; 301478d3005SHans Petter Selasky else if (baudrate >= IF_Gbps(10)) 302aa0a1e58SJeff Roberson return IB_RATE_10_GBPS; 303aa0a1e58SJeff Roberson else 304aa0a1e58SJeff Roberson return IB_RATE_PORT_CURRENT; 305aa0a1e58SJeff Roberson } 306aa0a1e58SJeff Roberson 307aa0a1e58SJeff Roberson static inline int rdma_link_local_addr(struct in6_addr *addr) 308aa0a1e58SJeff Roberson { 309b5c1e0cbSHans Petter Selasky if (addr->s6_addr32[0] == htonl(0xfe800000) && 310aa0a1e58SJeff Roberson addr->s6_addr32[1] == 0) 311aa0a1e58SJeff Roberson return 1; 312aa0a1e58SJeff Roberson 313aa0a1e58SJeff Roberson return 0; 314aa0a1e58SJeff Roberson } 315aa0a1e58SJeff Roberson 316aa0a1e58SJeff Roberson static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac) 317aa0a1e58SJeff Roberson { 318aa0a1e58SJeff Roberson memcpy(mac, &addr->s6_addr[8], 3); 319aa0a1e58SJeff Roberson memcpy(mac + 3, &addr->s6_addr[13], 3); 320aa0a1e58SJeff Roberson mac[0] ^= 2; 321aa0a1e58SJeff Roberson } 322aa0a1e58SJeff Roberson 323aa0a1e58SJeff Roberson static inline int rdma_is_multicast_addr(struct in6_addr *addr) 324aa0a1e58SJeff Roberson { 325b70db327SHans Petter Selasky __be32 ipv4_addr; 326b70db327SHans Petter Selasky 327b70db327SHans Petter Selasky if (addr->s6_addr[0] == 0xff) 328b70db327SHans Petter Selasky return 1; 329b70db327SHans Petter Selasky 330b70db327SHans Petter Selasky ipv4_addr = addr->s6_addr32[3]; 331b70db327SHans Petter Selasky return (ipv6_addr_v4mapped(addr) && ipv4_is_multicast(ipv4_addr)); 332aa0a1e58SJeff Roberson } 333aa0a1e58SJeff Roberson 334aa0a1e58SJeff Roberson static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac) 335aa0a1e58SJeff Roberson { 336aa0a1e58SJeff Roberson int i; 337aa0a1e58SJeff Roberson 338aa0a1e58SJeff Roberson mac[0] = 0x33; 339aa0a1e58SJeff Roberson mac[1] = 0x33; 340aa0a1e58SJeff Roberson for (i = 2; i < 6; ++i) 341aa0a1e58SJeff Roberson mac[i] = addr->s6_addr[i + 10]; 342aa0a1e58SJeff Roberson } 343aa0a1e58SJeff Roberson 344aa0a1e58SJeff Roberson static inline u16 rdma_get_vlan_id(union ib_gid *dgid) 345aa0a1e58SJeff Roberson { 346aa0a1e58SJeff Roberson u16 vid; 347aa0a1e58SJeff Roberson 348aa0a1e58SJeff Roberson vid = dgid->raw[11] << 8 | dgid->raw[12]; 349aa0a1e58SJeff Roberson return vid < 0x1000 ? vid : 0xffff; 350aa0a1e58SJeff Roberson } 351aa0a1e58SJeff Roberson 352f4546fa3SHans Petter Selasky static inline struct net_device *rdma_vlan_dev_real_dev(struct net_device *dev) 353aa0a1e58SJeff Roberson { 354f4546fa3SHans Petter Selasky if (dev->if_pcp != IFNET_PCP_NONE) 355f4546fa3SHans Petter Selasky return dev; /* prio-tagged traffic */ 356aa0a1e58SJeff Roberson return VLAN_TRUNKDEV(__DECONST(struct ifnet *, dev)); 357aa0a1e58SJeff Roberson } 358aa0a1e58SJeff Roberson 359aa0a1e58SJeff Roberson #endif /* IB_ADDR_H */ 360