xref: /freebsd/sys/ofed/include/rdma/ib_addr.h (revision d7c5a620e2b99e914f1770abde956cf0d0a970b7)
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 
55*d7c5a620SMatt 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);
137478d3005SHans Petter Selasky 
138478d3005SHans Petter Selasky int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
139478d3005SHans Petter Selasky 				 const union ib_gid *dgid,
140bf8641feSHans Petter Selasky 				 u8 *smac, struct net_device *dev,
141478d3005SHans Petter Selasky 				 int *hoplimit);
142aa0a1e58SJeff Roberson 
143aa0a1e58SJeff Roberson static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr)
144aa0a1e58SJeff Roberson {
145aa0a1e58SJeff Roberson 	return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9];
146aa0a1e58SJeff Roberson }
147aa0a1e58SJeff Roberson 
148aa0a1e58SJeff Roberson static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey)
149aa0a1e58SJeff Roberson {
150aa0a1e58SJeff Roberson 	dev_addr->broadcast[8] = pkey >> 8;
151aa0a1e58SJeff Roberson 	dev_addr->broadcast[9] = (unsigned char) pkey;
152aa0a1e58SJeff Roberson }
153aa0a1e58SJeff Roberson 
154aa0a1e58SJeff Roberson static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr,
155aa0a1e58SJeff Roberson 				    union ib_gid *gid)
156aa0a1e58SJeff Roberson {
157aa0a1e58SJeff Roberson 	memcpy(gid, dev_addr->broadcast + 4, sizeof *gid);
158aa0a1e58SJeff Roberson }
159aa0a1e58SJeff Roberson 
160aa0a1e58SJeff Roberson static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr)
161aa0a1e58SJeff Roberson {
162aa0a1e58SJeff Roberson 	return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0;
163aa0a1e58SJeff Roberson }
164aa0a1e58SJeff Roberson 
165aa0a1e58SJeff Roberson static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev)
166aa0a1e58SJeff Roberson {
167aa0a1e58SJeff Roberson 	uint16_t tag;
168aa0a1e58SJeff Roberson 
169aa0a1e58SJeff Roberson 	if (VLAN_TAG(__DECONST(struct ifnet *, dev), &tag) != 0)
170aa0a1e58SJeff Roberson 		return 0xffff;
171aa0a1e58SJeff Roberson 	return tag;
172aa0a1e58SJeff Roberson }
173aa0a1e58SJeff Roberson 
174478d3005SHans Petter Selasky static inline int rdma_ip2gid(const struct sockaddr *addr, union ib_gid *gid)
175b5c1e0cbSHans Petter Selasky {
176b5c1e0cbSHans Petter Selasky 	switch (addr->sa_family) {
177b5c1e0cbSHans Petter Selasky 	case AF_INET:
178478d3005SHans Petter Selasky 		ipv6_addr_set_v4mapped(((const struct sockaddr_in *)
179478d3005SHans Petter Selasky 					addr)->sin_addr.s_addr,
180b5c1e0cbSHans Petter Selasky 				       (struct in6_addr *)gid);
181b5c1e0cbSHans Petter Selasky 		break;
182b5c1e0cbSHans Petter Selasky 	case AF_INET6:
183478d3005SHans Petter Selasky 		memcpy(gid->raw, &((const struct sockaddr_in6 *)addr)->sin6_addr, 16);
184aacb0377SHans Petter Selasky 		/* make sure scope ID gets zeroed inside GID */
185aacb0377SHans Petter Selasky 		if (IN6_IS_SCOPE_LINKLOCAL((struct in6_addr *)gid->raw) ||
186aacb0377SHans Petter Selasky 		    IN6_IS_ADDR_MC_INTFACELOCAL((struct in6_addr *)gid->raw)) {
187aacb0377SHans Petter Selasky 			gid->raw[2] = 0;
188aacb0377SHans Petter Selasky 			gid->raw[3] = 0;
189aacb0377SHans Petter Selasky 		}
190b5c1e0cbSHans Petter Selasky 		break;
191b5c1e0cbSHans Petter Selasky 	default:
192b5c1e0cbSHans Petter Selasky 		return -EINVAL;
193b5c1e0cbSHans Petter Selasky 	}
194b5c1e0cbSHans Petter Selasky 	return 0;
195b5c1e0cbSHans Petter Selasky }
196b5c1e0cbSHans Petter Selasky 
197b5c1e0cbSHans Petter Selasky /* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */
198478d3005SHans Petter Selasky static inline void rdma_gid2ip(struct sockaddr *out, const union ib_gid *gid)
199b5c1e0cbSHans Petter Selasky {
200478d3005SHans Petter Selasky 	if (ipv6_addr_v4mapped((const struct in6_addr *)gid)) {
201b5c1e0cbSHans Petter Selasky 		struct sockaddr_in *out_in = (struct sockaddr_in *)out;
202b5c1e0cbSHans Petter Selasky 		memset(out_in, 0, sizeof(*out_in));
203b5c1e0cbSHans Petter Selasky 		out_in->sin_len = sizeof(*out_in);
204b5c1e0cbSHans Petter Selasky 		out_in->sin_family = AF_INET;
205b5c1e0cbSHans Petter Selasky 		memcpy(&out_in->sin_addr.s_addr, gid->raw + 12, 4);
206b5c1e0cbSHans Petter Selasky 	} else {
207b5c1e0cbSHans Petter Selasky 		struct sockaddr_in6 *out_in = (struct sockaddr_in6 *)out;
208b5c1e0cbSHans Petter Selasky 		memset(out_in, 0, sizeof(*out_in));
2090bab509bSHans Petter Selasky 		out_in->sin6_len = sizeof(*out_in);
210b5c1e0cbSHans Petter Selasky 		out_in->sin6_family = AF_INET6;
211b5c1e0cbSHans Petter Selasky 		memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16);
212b5c1e0cbSHans Petter Selasky 	}
213b5c1e0cbSHans Petter Selasky }
214b5c1e0cbSHans Petter Selasky 
215aa0a1e58SJeff Roberson static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr,
216aa0a1e58SJeff Roberson 				      union ib_gid *gid)
217aa0a1e58SJeff Roberson {
218478d3005SHans Petter Selasky 	struct net_device *dev;
219478d3005SHans Petter Selasky 	struct ifaddr *ifa;
220478d3005SHans Petter Selasky 
221478d3005SHans Petter Selasky 	dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
222478d3005SHans Petter Selasky 	if (dev) {
223*d7c5a620SMatt Macy 		CK_STAILQ_FOREACH(ifa, &dev->if_addrhead, ifa_link) {
224478d3005SHans Petter Selasky 			if (ifa->ifa_addr == NULL ||
225478d3005SHans Petter Selasky 			    ifa->ifa_addr->sa_family != AF_INET)
226478d3005SHans Petter Selasky 				continue;
227478d3005SHans Petter Selasky 			ipv6_addr_set_v4mapped(((struct sockaddr_in *)
228478d3005SHans Petter Selasky 					       ifa->ifa_addr)->sin_addr.s_addr,
229478d3005SHans Petter Selasky 					       (struct in6_addr *)gid);
230478d3005SHans Petter Selasky 			break;
231478d3005SHans Petter Selasky 		}
232478d3005SHans Petter Selasky 		dev_put(dev);
233478d3005SHans Petter Selasky 	}
234aa0a1e58SJeff Roberson }
235aa0a1e58SJeff Roberson 
236aa0a1e58SJeff Roberson static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
237aa0a1e58SJeff Roberson {
238aa0a1e58SJeff Roberson 	if (dev_addr->transport == RDMA_TRANSPORT_IB &&
239aa0a1e58SJeff Roberson 	    dev_addr->dev_type != ARPHRD_INFINIBAND)
240aa0a1e58SJeff Roberson 		iboe_addr_get_sgid(dev_addr, gid);
241aa0a1e58SJeff Roberson 	else
242aa0a1e58SJeff Roberson 		memcpy(gid, dev_addr->src_dev_addr +
243aa0a1e58SJeff Roberson 		       rdma_addr_gid_offset(dev_addr), sizeof *gid);
244aa0a1e58SJeff Roberson }
245aa0a1e58SJeff Roberson 
246aa0a1e58SJeff Roberson static inline void rdma_addr_set_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
247aa0a1e58SJeff Roberson {
248aa0a1e58SJeff Roberson 	memcpy(dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid);
249aa0a1e58SJeff Roberson }
250aa0a1e58SJeff Roberson 
251aa0a1e58SJeff Roberson static inline void rdma_addr_get_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
252aa0a1e58SJeff Roberson {
253aa0a1e58SJeff Roberson 	memcpy(gid, dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid);
254aa0a1e58SJeff Roberson }
255aa0a1e58SJeff Roberson 
256aa0a1e58SJeff Roberson static inline void rdma_addr_set_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
257aa0a1e58SJeff Roberson {
258aa0a1e58SJeff Roberson 	memcpy(dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid);
259aa0a1e58SJeff Roberson }
260aa0a1e58SJeff Roberson 
261aa0a1e58SJeff Roberson static inline enum ib_mtu iboe_get_mtu(int mtu)
262aa0a1e58SJeff Roberson {
263aa0a1e58SJeff Roberson 	/*
264aa0a1e58SJeff Roberson 	 * reduce IB headers from effective IBoE MTU. 28 stands for
265aa0a1e58SJeff Roberson 	 * atomic header which is the biggest possible header after BTH
266aa0a1e58SJeff Roberson 	 */
267aa0a1e58SJeff Roberson 	mtu = mtu - IB_GRH_BYTES - IB_BTH_BYTES - 28;
268aa0a1e58SJeff Roberson 
269aa0a1e58SJeff Roberson 	if (mtu >= ib_mtu_enum_to_int(IB_MTU_4096))
270aa0a1e58SJeff Roberson 		return IB_MTU_4096;
271aa0a1e58SJeff Roberson 	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_2048))
272aa0a1e58SJeff Roberson 		return IB_MTU_2048;
273aa0a1e58SJeff Roberson 	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_1024))
274aa0a1e58SJeff Roberson 		return IB_MTU_1024;
275aa0a1e58SJeff Roberson 	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512))
276aa0a1e58SJeff Roberson 		return IB_MTU_512;
277aa0a1e58SJeff Roberson 	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256))
278aa0a1e58SJeff Roberson 		return IB_MTU_256;
279aa0a1e58SJeff Roberson 	else
280aa0a1e58SJeff Roberson 		return 0;
281aa0a1e58SJeff Roberson }
282aa0a1e58SJeff Roberson 
283aa0a1e58SJeff Roberson static inline int iboe_get_rate(struct net_device *dev)
284aa0a1e58SJeff Roberson {
285478d3005SHans Petter Selasky 	uint64_t baudrate = dev->if_baudrate;
286478d3005SHans Petter Selasky #ifdef if_baudrate_pf
287478d3005SHans Petter Selasky 	int exp;
288478d3005SHans Petter Selasky 	for (exp = dev->if_baudrate_pf; exp > 0; exp--)
289478d3005SHans Petter Selasky 		baudrate *= 10;
290478d3005SHans Petter Selasky #endif
291478d3005SHans Petter Selasky 	if (baudrate >= IF_Gbps(40))
292aa0a1e58SJeff Roberson 		return IB_RATE_40_GBPS;
293478d3005SHans Petter Selasky 	else if (baudrate >= IF_Gbps(30))
294aa0a1e58SJeff Roberson 		return IB_RATE_30_GBPS;
295478d3005SHans Petter Selasky 	else if (baudrate >= IF_Gbps(20))
296aa0a1e58SJeff Roberson 		return IB_RATE_20_GBPS;
297478d3005SHans Petter Selasky 	else if (baudrate >= IF_Gbps(10))
298aa0a1e58SJeff Roberson 		return IB_RATE_10_GBPS;
299aa0a1e58SJeff Roberson 	else
300aa0a1e58SJeff Roberson 		return IB_RATE_PORT_CURRENT;
301aa0a1e58SJeff Roberson }
302aa0a1e58SJeff Roberson 
303aa0a1e58SJeff Roberson static inline int rdma_link_local_addr(struct in6_addr *addr)
304aa0a1e58SJeff Roberson {
305b5c1e0cbSHans Petter Selasky 	if (addr->s6_addr32[0] == htonl(0xfe800000) &&
306aa0a1e58SJeff Roberson 	    addr->s6_addr32[1] == 0)
307aa0a1e58SJeff Roberson 		return 1;
308aa0a1e58SJeff Roberson 
309aa0a1e58SJeff Roberson 	return 0;
310aa0a1e58SJeff Roberson }
311aa0a1e58SJeff Roberson 
312aa0a1e58SJeff Roberson static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac)
313aa0a1e58SJeff Roberson {
314aa0a1e58SJeff Roberson 	memcpy(mac, &addr->s6_addr[8], 3);
315aa0a1e58SJeff Roberson 	memcpy(mac + 3, &addr->s6_addr[13], 3);
316aa0a1e58SJeff Roberson 	mac[0] ^= 2;
317aa0a1e58SJeff Roberson }
318aa0a1e58SJeff Roberson 
319aa0a1e58SJeff Roberson static inline int rdma_is_multicast_addr(struct in6_addr *addr)
320aa0a1e58SJeff Roberson {
321aa0a1e58SJeff Roberson 	return addr->s6_addr[0] == 0xff;
322aa0a1e58SJeff Roberson }
323aa0a1e58SJeff Roberson 
324aa0a1e58SJeff Roberson static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac)
325aa0a1e58SJeff Roberson {
326aa0a1e58SJeff Roberson 	int i;
327aa0a1e58SJeff Roberson 
328aa0a1e58SJeff Roberson 	mac[0] = 0x33;
329aa0a1e58SJeff Roberson 	mac[1] = 0x33;
330aa0a1e58SJeff Roberson 	for (i = 2; i < 6; ++i)
331aa0a1e58SJeff Roberson 		mac[i] = addr->s6_addr[i + 10];
332aa0a1e58SJeff Roberson }
333aa0a1e58SJeff Roberson 
334aa0a1e58SJeff Roberson static inline u16 rdma_get_vlan_id(union ib_gid *dgid)
335aa0a1e58SJeff Roberson {
336aa0a1e58SJeff Roberson 	u16 vid;
337aa0a1e58SJeff Roberson 
338aa0a1e58SJeff Roberson 	vid = dgid->raw[11] << 8 | dgid->raw[12];
339aa0a1e58SJeff Roberson 	return vid < 0x1000 ? vid : 0xffff;
340aa0a1e58SJeff Roberson }
341aa0a1e58SJeff Roberson 
342aa0a1e58SJeff Roberson static inline struct net_device *rdma_vlan_dev_real_dev(const struct net_device *dev)
343aa0a1e58SJeff Roberson {
344aa0a1e58SJeff Roberson 	return VLAN_TRUNKDEV(__DECONST(struct ifnet *, dev));
345aa0a1e58SJeff Roberson }
346aa0a1e58SJeff Roberson 
347aa0a1e58SJeff Roberson #endif /* IB_ADDR_H */
348