| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 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 |  | 
| Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 39 | struct rdma_addr_client { | 
 | 40 | 	atomic_t refcount; | 
 | 41 | 	struct completion comp; | 
 | 42 | }; | 
 | 43 |  | 
 | 44 | /** | 
 | 45 |  * rdma_addr_register_client - Register an address client. | 
 | 46 |  */ | 
 | 47 | void rdma_addr_register_client(struct rdma_addr_client *client); | 
 | 48 |  | 
 | 49 | /** | 
 | 50 |  * rdma_addr_unregister_client - Deregister an address client. | 
 | 51 |  * @client: Client object to deregister. | 
 | 52 |  */ | 
 | 53 | void rdma_addr_unregister_client(struct rdma_addr_client *client); | 
 | 54 |  | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 55 | struct rdma_dev_addr { | 
 | 56 | 	unsigned char src_dev_addr[MAX_ADDR_LEN]; | 
 | 57 | 	unsigned char dst_dev_addr[MAX_ADDR_LEN]; | 
 | 58 | 	unsigned char broadcast[MAX_ADDR_LEN]; | 
| Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 59 | 	enum rdma_node_type dev_type; | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 60 | }; | 
 | 61 |  | 
 | 62 | /** | 
 | 63 |  * rdma_translate_ip - Translate a local IP address to an RDMA hardware | 
 | 64 |  *   address. | 
 | 65 |  */ | 
 | 66 | int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr); | 
 | 67 |  | 
 | 68 | /** | 
 | 69 |  * rdma_resolve_ip - Resolve source and destination IP addresses to | 
 | 70 |  *   RDMA hardware addresses. | 
| Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 71 |  * @client: Address client associated with request. | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 72 |  * @src_addr: An optional source address to use in the resolution.  If a | 
 | 73 |  *   source address is not provided, a usable address will be returned via | 
 | 74 |  *   the callback. | 
 | 75 |  * @dst_addr: The destination address to resolve. | 
 | 76 |  * @addr: A reference to a data location that will receive the resolved | 
 | 77 |  *   addresses.  The data location must remain valid until the callback has | 
 | 78 |  *   been invoked. | 
 | 79 |  * @timeout_ms: Amount of time to wait for the address resolution to complete. | 
 | 80 |  * @callback: Call invoked once address resolution has completed, timed out, | 
 | 81 |  *   or been canceled.  A status of 0 indicates success. | 
 | 82 |  * @context: User-specified context associated with the call. | 
 | 83 |  */ | 
| Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 84 | int rdma_resolve_ip(struct rdma_addr_client *client, | 
 | 85 | 		    struct sockaddr *src_addr, struct sockaddr *dst_addr, | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 86 | 		    struct rdma_dev_addr *addr, int timeout_ms, | 
 | 87 | 		    void (*callback)(int status, struct sockaddr *src_addr, | 
 | 88 | 				     struct rdma_dev_addr *addr, void *context), | 
 | 89 | 		    void *context); | 
 | 90 |  | 
 | 91 | void rdma_addr_cancel(struct rdma_dev_addr *addr); | 
 | 92 |  | 
| Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 93 | int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev, | 
 | 94 | 	      const unsigned char *dst_dev_addr); | 
 | 95 |  | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 96 | static inline int ip_addr_size(struct sockaddr *addr) | 
 | 97 | { | 
 | 98 | 	return addr->sa_family == AF_INET6 ? | 
 | 99 | 	       sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); | 
 | 100 | } | 
 | 101 |  | 
 | 102 | static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr) | 
 | 103 | { | 
 | 104 | 	return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9]; | 
 | 105 | } | 
 | 106 |  | 
 | 107 | static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey) | 
 | 108 | { | 
 | 109 | 	dev_addr->broadcast[8] = pkey >> 8; | 
 | 110 | 	dev_addr->broadcast[9] = (unsigned char) pkey; | 
 | 111 | } | 
 | 112 |  | 
| Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 113 | static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr, | 
 | 114 | 				    union ib_gid *gid) | 
 | 115 | { | 
 | 116 | 	memcpy(gid, dev_addr->broadcast + 4, sizeof *gid); | 
 | 117 | } | 
 | 118 |  | 
| Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 119 | static inline void ib_addr_get_sgid(struct rdma_dev_addr *dev_addr, | 
 | 120 | 				    union ib_gid *gid) | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 121 | { | 
| Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 122 | 	memcpy(gid, dev_addr->src_dev_addr + 4, sizeof *gid); | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 123 | } | 
 | 124 |  | 
 | 125 | static inline void ib_addr_set_sgid(struct rdma_dev_addr *dev_addr, | 
 | 126 | 				    union ib_gid *gid) | 
 | 127 | { | 
 | 128 | 	memcpy(dev_addr->src_dev_addr + 4, gid, sizeof *gid); | 
 | 129 | } | 
 | 130 |  | 
| Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 131 | static inline void ib_addr_get_dgid(struct rdma_dev_addr *dev_addr, | 
 | 132 | 				    union ib_gid *gid) | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 133 | { | 
| Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 134 | 	memcpy(gid, dev_addr->dst_dev_addr + 4, sizeof *gid); | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 135 | } | 
 | 136 |  | 
 | 137 | static inline void ib_addr_set_dgid(struct rdma_dev_addr *dev_addr, | 
 | 138 | 				    union ib_gid *gid) | 
 | 139 | { | 
 | 140 | 	memcpy(dev_addr->dst_dev_addr + 4, gid, sizeof *gid); | 
 | 141 | } | 
 | 142 |  | 
| Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 143 | static inline void iw_addr_get_sgid(struct rdma_dev_addr *dev_addr, | 
 | 144 | 				    union ib_gid *gid) | 
 | 145 | { | 
 | 146 | 	memcpy(gid, dev_addr->src_dev_addr, sizeof *gid); | 
 | 147 | } | 
 | 148 |  | 
 | 149 | static inline void iw_addr_get_dgid(struct rdma_dev_addr *dev_addr, | 
 | 150 | 				    union ib_gid *gid) | 
 | 151 | { | 
 | 152 | 	memcpy(gid, dev_addr->dst_dev_addr, sizeof *gid); | 
 | 153 | } | 
 | 154 |  | 
| Sean Hefty | 7025fcd | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 155 | #endif /* IB_ADDR_H */ |