aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSean Hefty <sean.hefty@intel.com>2006-06-17 23:37:28 -0400
committerRoland Dreier <rolandd@cisco.com>2006-06-17 23:37:28 -0400
commit7025fcd36bd62af2c6ca0ea3490c00b216c4d168 (patch)
treee2fda3944176fcafb24876680d6eb8b6be394fe6 /include
parenta1e8733e557bb390e13aa00ef044a6022c8d0bb2 (diff)
IB: address translation to map IP toIB addresses (GIDs)
Add an address translation service that maps IP addresses to InfiniBand GID addresses using IPoIB. Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'include')
-rw-r--r--include/rdma/ib_addr.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/include/rdma/ib_addr.h b/include/rdma/ib_addr.h
new file mode 100644
index 000000000000..fcb5ba87dcc5
--- /dev/null
+++ b/include/rdma/ib_addr.h
@@ -0,0 +1,114 @@
1/*
2 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
4 *
5 * This Software is licensed under one of the following licenses:
6 *
7 * 1) under the terms of the "Common Public License 1.0" a copy of which is
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is
12 * available from the Open Source Initiative, see
13 * http://www.opensource.org/licenses/bsd-license.php.
14 *
15 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
16 * copy of which is available from the Open Source Initiative, see
17 * http://www.opensource.org/licenses/gpl-license.php.
18 *
19 * Licensee has the right to choose one of the above licenses.
20 *
21 * Redistributions of source code must retain the above copyright
22 * notice and one of the license notices.
23 *
24 * Redistributions in binary form must reproduce both the above copyright
25 * notice, one of the license notices in the documentation
26 * and/or other materials provided with the distribution.
27 *
28 */
29
30#if !defined(IB_ADDR_H)
31#define IB_ADDR_H
32
33#include <linux/in.h>
34#include <linux/in6.h>
35#include <linux/netdevice.h>
36#include <linux/socket.h>
37#include <rdma/ib_verbs.h>
38
39struct rdma_dev_addr {
40 unsigned char src_dev_addr[MAX_ADDR_LEN];
41 unsigned char dst_dev_addr[MAX_ADDR_LEN];
42 unsigned char broadcast[MAX_ADDR_LEN];
43 enum ib_node_type dev_type;
44};
45
46/**
47 * rdma_translate_ip - Translate a local IP address to an RDMA hardware
48 * address.
49 */
50int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr);
51
52/**
53 * rdma_resolve_ip - Resolve source and destination IP addresses to
54 * RDMA hardware addresses.
55 * @src_addr: An optional source address to use in the resolution. If a
56 * source address is not provided, a usable address will be returned via
57 * the callback.
58 * @dst_addr: The destination address to resolve.
59 * @addr: A reference to a data location that will receive the resolved
60 * addresses. The data location must remain valid until the callback has
61 * been invoked.
62 * @timeout_ms: Amount of time to wait for the address resolution to complete.
63 * @callback: Call invoked once address resolution has completed, timed out,
64 * or been canceled. A status of 0 indicates success.
65 * @context: User-specified context associated with the call.
66 */
67int rdma_resolve_ip(struct sockaddr *src_addr, struct sockaddr *dst_addr,
68 struct rdma_dev_addr *addr, int timeout_ms,
69 void (*callback)(int status, struct sockaddr *src_addr,
70 struct rdma_dev_addr *addr, void *context),
71 void *context);
72
73void rdma_addr_cancel(struct rdma_dev_addr *addr);
74
75static inline int ip_addr_size(struct sockaddr *addr)
76{
77 return addr->sa_family == AF_INET6 ?
78 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
79}
80
81static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr)
82{
83 return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9];
84}
85
86static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey)
87{
88 dev_addr->broadcast[8] = pkey >> 8;
89 dev_addr->broadcast[9] = (unsigned char) pkey;
90}
91
92static inline union ib_gid *ib_addr_get_sgid(struct rdma_dev_addr *dev_addr)
93{
94 return (union ib_gid *) (dev_addr->src_dev_addr + 4);
95}
96
97static inline void ib_addr_set_sgid(struct rdma_dev_addr *dev_addr,
98 union ib_gid *gid)
99{
100 memcpy(dev_addr->src_dev_addr + 4, gid, sizeof *gid);
101}
102
103static inline union ib_gid *ib_addr_get_dgid(struct rdma_dev_addr *dev_addr)
104{
105 return (union ib_gid *) (dev_addr->dst_dev_addr + 4);
106}
107
108static inline void ib_addr_set_dgid(struct rdma_dev_addr *dev_addr,
109 union ib_gid *gid)
110{
111 memcpy(dev_addr->dst_dev_addr + 4, gid, sizeof *gid);
112}
113
114#endif /* IB_ADDR_H */