ib_addr.h (273135) | ib_addr.h (278886) |
---|---|
1/* 2 * Copyright (c) 2005 Voltaire Inc. All rights reserved. 3 * Copyright (c) 2005 Intel Corporation. All rights reserved. 4 * 5 * This software is available to you under a choice of one of two 6 * licenses. You may choose to be licensed under the terms of the GNU 7 * General Public License (GPL) Version 2, available from the file 8 * COPYING in the main directory of this source tree, or the --- 17 unchanged lines hidden (view full) --- 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * SOFTWARE. 32 */ 33 | 1/* 2 * Copyright (c) 2005 Voltaire Inc. All rights reserved. 3 * Copyright (c) 2005 Intel Corporation. All rights reserved. 4 * 5 * This software is available to you under a choice of one of two 6 * licenses. You may choose to be licensed under the terms of the GNU 7 * General Public License (GPL) Version 2, available from the file 8 * COPYING in the main directory of this source tree, or the --- 17 unchanged lines hidden (view full) --- 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * SOFTWARE. 32 */ 33 |
34#if !defined(IB_ADDR_H) | 34#ifndef IB_ADDR_H |
35#define IB_ADDR_H 36 37#include <linux/in.h> 38#include <linux/in6.h> 39#include <linux/if_arp.h> 40#include <linux/netdevice.h> | 35#define IB_ADDR_H 36 37#include <linux/in.h> 38#include <linux/in6.h> 39#include <linux/if_arp.h> 40#include <linux/netdevice.h> |
41#include <linux/inetdevice.h> |
|
41#include <linux/socket.h> | 42#include <linux/socket.h> |
43#include <linux/if_vlan.h> |
|
42#include <rdma/ib_verbs.h> 43#include <rdma/ib_pack.h> | 44#include <rdma/ib_verbs.h> 45#include <rdma/ib_pack.h> |
44#include <linux/if_vlan.h> | 46#include <net/if_inet6.h> 47#include <net/ipv6.h> |
45 46struct rdma_addr_client { 47 atomic_t refcount; 48 struct completion comp; 49}; 50 51/** 52 * rdma_addr_register_client - Register an address client. --- 14 unchanged lines hidden (view full) --- 67 int bound_dev_if; 68 enum rdma_transport_type transport; 69}; 70 71/** 72 * rdma_translate_ip - Translate a local IP address to an RDMA hardware 73 * address. 74 */ | 48 49struct rdma_addr_client { 50 atomic_t refcount; 51 struct completion comp; 52}; 53 54/** 55 * rdma_addr_register_client - Register an address client. --- 14 unchanged lines hidden (view full) --- 70 int bound_dev_if; 71 enum rdma_transport_type transport; 72}; 73 74/** 75 * rdma_translate_ip - Translate a local IP address to an RDMA hardware 76 * address. 77 */ |
75int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr); | 78int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr, 79 u16 *vlan_id); |
76 77/** 78 * rdma_resolve_ip - Resolve source and destination IP addresses to 79 * RDMA hardware addresses. 80 * @client: Address client associated with request. 81 * @src_addr: An optional source address to use in the resolution. If a 82 * source address is not provided, a usable address will be returned via 83 * the callback. --- 12 unchanged lines hidden (view full) --- 96 void (*callback)(int status, struct sockaddr *src_addr, 97 struct rdma_dev_addr *addr, void *context), 98 void *context); 99 100void rdma_addr_cancel(struct rdma_dev_addr *addr); 101 102int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev, 103 const unsigned char *dst_dev_addr); | 80 81/** 82 * rdma_resolve_ip - Resolve source and destination IP addresses to 83 * RDMA hardware addresses. 84 * @client: Address client associated with request. 85 * @src_addr: An optional source address to use in the resolution. If a 86 * source address is not provided, a usable address will be returned via 87 * the callback. --- 12 unchanged lines hidden (view full) --- 100 void (*callback)(int status, struct sockaddr *src_addr, 101 struct rdma_dev_addr *addr, void *context), 102 void *context); 103 104void rdma_addr_cancel(struct rdma_dev_addr *addr); 105 106int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev, 107 const unsigned char *dst_dev_addr); |
108int rdma_addr_find_smac_by_sgid(union ib_gid *sgid, u8 *smac, u16 *vlan_id); 109int rdma_addr_find_dmac_by_grh(union ib_gid *sgid, union ib_gid *dgid, u8 *smac, 110 u16 *vlan_id); |
|
104 105static inline int ip_addr_size(struct sockaddr *addr) 106{ 107 return addr->sa_family == AF_INET6 ? 108 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); 109} 110 111static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr) --- 13 unchanged lines hidden (view full) --- 125 memcpy(gid, dev_addr->broadcast + 4, sizeof *gid); 126} 127 128static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr) 129{ 130 return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0; 131} 132 | 111 112static inline int ip_addr_size(struct sockaddr *addr) 113{ 114 return addr->sa_family == AF_INET6 ? 115 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); 116} 117 118static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr) --- 13 unchanged lines hidden (view full) --- 132 memcpy(gid, dev_addr->broadcast + 4, sizeof *gid); 133} 134 135static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr) 136{ 137 return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0; 138} 139 |
133static inline void iboe_mac_vlan_to_ll(union ib_gid *gid, u8 *mac, u16 vid) 134{ 135 memset(gid->raw, 0, 16); 136 *((u32 *)gid->raw) = cpu_to_be32(0xfe800000); 137 if (vid < 0x1000) { 138 gid->raw[12] = vid & 0xff; 139 gid->raw[11] = vid >> 8; 140 } else { 141 gid->raw[12] = 0xfe; 142 gid->raw[11] = 0xff; 143 } 144 145 memcpy(gid->raw + 13, mac + 3, 3); 146 memcpy(gid->raw + 8, mac, 3); 147 gid->raw[8] ^= 2; 148} 149 | |
150static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev) 151{ | 140static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev) 141{ |
152#ifdef __linux__ 153 return dev->priv_flags & IFF_802_1Q_VLAN ? 154 vlan_dev_vlan_id(dev) : 0xffff; 155#else | |
156 uint16_t tag; 157 158 if (VLAN_TAG(__DECONST(struct ifnet *, dev), &tag) != 0) 159 return 0xffff; 160 return tag; | 142 uint16_t tag; 143 144 if (VLAN_TAG(__DECONST(struct ifnet *, dev), &tag) != 0) 145 return 0xffff; 146 return tag; |
161#endif | |
162} 163 | 147} 148 |
164static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, 165 union ib_gid *gid) | 149static inline int rdma_ip2gid(struct sockaddr *addr, union ib_gid *gid) |
166{ | 150{ |
167 struct net_device *dev; 168 u16 vid = 0xffff; | 151 switch (addr->sa_family) { 152 case AF_INET: 153 ipv6_addr_set_v4mapped(((struct sockaddr_in *)addr)->sin_addr.s_addr, 154 (struct in6_addr *)gid); 155 break; 156 case AF_INET6: 157 memcpy(gid->raw, &((struct sockaddr_in6 *)addr)->sin6_addr, 158 16); 159 break; 160 default: 161 return -EINVAL; 162 } 163 return 0; 164} |
169 | 165 |
170 dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if); 171 if (dev) { 172 vid = rdma_vlan_dev_vlan_id(dev); 173 dev_put(dev); | 166/* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */ 167static inline int rdma_gid2ip(struct sockaddr *out, union ib_gid *gid) 168{ 169 if (ipv6_addr_v4mapped((struct in6_addr *)gid)) { 170 struct sockaddr_in *out_in = (struct sockaddr_in *)out; 171 memset(out_in, 0, sizeof(*out_in)); 172 out_in->sin_len = sizeof(*out_in); 173 out_in->sin_family = AF_INET; 174 memcpy(&out_in->sin_addr.s_addr, gid->raw + 12, 4); 175 } else { 176 struct sockaddr_in6 *out_in = (struct sockaddr_in6 *)out; 177 memset(out_in, 0, sizeof(*out_in)); 178 out_in->sin6_family = AF_INET6; 179 memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16); |
174 } | 180 } |
181 return 0; 182} |
|
175 | 183 |
176 iboe_mac_vlan_to_ll(gid, dev_addr->src_dev_addr, vid); | 184/* This func is called only in loopback ip address (127.0.0.1) 185 * case in which sgid is not relevant 186 */ 187static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, 188 union ib_gid *gid) 189{ |
177} 178 179static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 180{ 181 if (dev_addr->transport == RDMA_TRANSPORT_IB && 182 dev_addr->dev_type != ARPHRD_INFINIBAND) 183 iboe_addr_get_sgid(dev_addr, gid); 184 else --- 33 unchanged lines hidden (view full) --- 218 else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512)) 219 return IB_MTU_512; 220 else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256)) 221 return IB_MTU_256; 222 else 223 return 0; 224} 225 | 190} 191 192static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 193{ 194 if (dev_addr->transport == RDMA_TRANSPORT_IB && 195 dev_addr->dev_type != ARPHRD_INFINIBAND) 196 iboe_addr_get_sgid(dev_addr, gid); 197 else --- 33 unchanged lines hidden (view full) --- 231 else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512)) 232 return IB_MTU_512; 233 else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256)) 234 return IB_MTU_256; 235 else 236 return 0; 237} 238 |
226#ifdef __linux__ | |
227static inline int iboe_get_rate(struct net_device *dev) 228{ | 239static inline int iboe_get_rate(struct net_device *dev) 240{ |
229 struct ethtool_cmd cmd; 230 231 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings || 232 dev->ethtool_ops->get_settings(dev, &cmd)) 233 return IB_RATE_PORT_CURRENT; 234 235 if (cmd.speed >= 40000) 236 return IB_RATE_40_GBPS; 237 else if (cmd.speed >= 30000) 238 return IB_RATE_30_GBPS; 239 else if (cmd.speed >= 20000) 240 return IB_RATE_20_GBPS; 241 else if (cmd.speed >= 10000) 242 return IB_RATE_10_GBPS; 243 else 244 return IB_RATE_PORT_CURRENT; 245} 246#else 247static inline int iboe_get_rate(struct net_device *dev) 248{ | |
249 if (dev->if_baudrate >= IF_Gbps(40)) 250 return IB_RATE_40_GBPS; 251 else if (dev->if_baudrate >= IF_Gbps(30)) 252 return IB_RATE_30_GBPS; 253 else if (dev->if_baudrate >= IF_Gbps(20)) 254 return IB_RATE_20_GBPS; 255 else if (dev->if_baudrate >= IF_Gbps(10)) 256 return IB_RATE_10_GBPS; 257 else 258 return IB_RATE_PORT_CURRENT; 259} | 241 if (dev->if_baudrate >= IF_Gbps(40)) 242 return IB_RATE_40_GBPS; 243 else if (dev->if_baudrate >= IF_Gbps(30)) 244 return IB_RATE_30_GBPS; 245 else if (dev->if_baudrate >= IF_Gbps(20)) 246 return IB_RATE_20_GBPS; 247 else if (dev->if_baudrate >= IF_Gbps(10)) 248 return IB_RATE_10_GBPS; 249 else 250 return IB_RATE_PORT_CURRENT; 251} |
260#endif | |
261 262static inline int rdma_link_local_addr(struct in6_addr *addr) 263{ | 252 253static inline int rdma_link_local_addr(struct in6_addr *addr) 254{ |
264 if (addr->s6_addr32[0] == cpu_to_be32(0xfe800000) && | 255 if (addr->s6_addr32[0] == htonl(0xfe800000) && |
265 addr->s6_addr32[1] == 0) 266 return 1; 267 268 return 0; 269} 270 271static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac) 272{ 273 memcpy(mac, &addr->s6_addr[8], 3); 274 memcpy(mac + 3, &addr->s6_addr[13], 3); 275 mac[0] ^= 2; 276} 277 278static inline int rdma_is_multicast_addr(struct in6_addr *addr) 279{ 280 return addr->s6_addr[0] == 0xff; 281} 282 | 256 addr->s6_addr32[1] == 0) 257 return 1; 258 259 return 0; 260} 261 262static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac) 263{ 264 memcpy(mac, &addr->s6_addr[8], 3); 265 memcpy(mac + 3, &addr->s6_addr[13], 3); 266 mac[0] ^= 2; 267} 268 269static inline int rdma_is_multicast_addr(struct in6_addr *addr) 270{ 271 return addr->s6_addr[0] == 0xff; 272} 273 |
274static inline void resolve_mcast_mac(struct in6_addr *addr, u8 *mac) 275{ 276 if (addr->s6_addr[0] != 0xff) 277 return; 278 279#ifdef DUAL_MODE_MCAST_MAC 280 if (addr->s6_addr[1] == 0x0e) /* IPv4 */ 281 ip_eth_mc_map(addr->s6_addr32[3], mac); 282 else 283#endif 284 ipv6_eth_mc_map(addr, mac); 285} 286 287 |
|
283static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac) 284{ 285 int i; 286 287 mac[0] = 0x33; 288 mac[1] = 0x33; 289 for (i = 2; i < 6; ++i) 290 mac[i] = addr->s6_addr[i + 10]; --- 4 unchanged lines hidden (view full) --- 295 u16 vid; 296 297 vid = dgid->raw[11] << 8 | dgid->raw[12]; 298 return vid < 0x1000 ? vid : 0xffff; 299} 300 301static inline struct net_device *rdma_vlan_dev_real_dev(const struct net_device *dev) 302{ | 288static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac) 289{ 290 int i; 291 292 mac[0] = 0x33; 293 mac[1] = 0x33; 294 for (i = 2; i < 6; ++i) 295 mac[i] = addr->s6_addr[i + 10]; --- 4 unchanged lines hidden (view full) --- 300 u16 vid; 301 302 vid = dgid->raw[11] << 8 | dgid->raw[12]; 303 return vid < 0x1000 ? vid : 0xffff; 304} 305 306static inline struct net_device *rdma_vlan_dev_real_dev(const struct net_device *dev) 307{ |
303#ifdef __linux__ 304 return dev->priv_flags & IFF_802_1Q_VLAN ? 305 vlan_dev_real_dev(dev) : 0; 306#else | |
307 return VLAN_TRUNKDEV(__DECONST(struct ifnet *, dev)); | 308 return VLAN_TRUNKDEV(__DECONST(struct ifnet *, dev)); |
308#endif | |
309} 310 311#endif /* IB_ADDR_H */ | 309} 310 311#endif /* IB_ADDR_H */ |