cregit-Linux how code gets into the kernel

Release 4.14 include/rdma/ib_addr.h

Directory: include/rdma
/*
 * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
 * Copyright (c) 2005 Intel Corporation.  All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#if !defined(IB_ADDR_H)

#define IB_ADDR_H

#include <linux/in.h>
#include <linux/in6.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
#include <linux/socket.h>
#include <linux/if_vlan.h>
#include <net/ipv6.h>
#include <net/if_inet6.h>
#include <net/ip.h>
#include <rdma/ib_verbs.h>
#include <rdma/ib_pack.h>
#include <net/ipv6.h>
#include <net/net_namespace.h>


struct rdma_addr_client {
	
atomic_t refcount;
	
struct completion comp;
};

/**
 * rdma_addr_register_client - Register an address client.
 */
void rdma_addr_register_client(struct rdma_addr_client *client);

/**
 * rdma_addr_unregister_client - Deregister an address client.
 * @client: Client object to deregister.
 */
void rdma_addr_unregister_client(struct rdma_addr_client *client);

/**
 * struct rdma_dev_addr - Contains resolved RDMA hardware addresses
 * @src_dev_addr:       Source MAC address.
 * @dst_dev_addr:       Destination MAC address.
 * @broadcast:          Broadcast address of the device.
 * @dev_type:           The interface hardware type of the device.
 * @bound_dev_if:       An optional device interface index.
 * @transport:          The transport type used.
 * @net:                Network namespace containing the bound_dev_if net_dev.
 */

struct rdma_dev_addr {
	
unsigned char src_dev_addr[MAX_ADDR_LEN];
	
unsigned char dst_dev_addr[MAX_ADDR_LEN];
	
unsigned char broadcast[MAX_ADDR_LEN];
	
unsigned short dev_type;
	
int bound_dev_if;
	
enum rdma_transport_type transport;
	
struct net *net;
	
enum rdma_network_type network;
	
int hoplimit;
};

/**
 * rdma_translate_ip - Translate a local IP address to an RDMA hardware
 *   address.
 *
 * The dev_addr->net field must be initialized.
 */
int rdma_translate_ip(const struct sockaddr *addr,
		      struct rdma_dev_addr *dev_addr, u16 *vlan_id);

/**
 * rdma_resolve_ip - Resolve source and destination IP addresses to
 *   RDMA hardware addresses.
 * @client: Address client associated with request.
 * @src_addr: An optional source address to use in the resolution.  If a
 *   source address is not provided, a usable address will be returned via
 *   the callback.
 * @dst_addr: The destination address to resolve.
 * @addr: A reference to a data location that will receive the resolved
 *   addresses.  The data location must remain valid until the callback has
 *   been invoked. The net field of the addr struct must be valid.
 * @timeout_ms: Amount of time to wait for the address resolution to complete.
 * @callback: Call invoked once address resolution has completed, timed out,
 *   or been canceled.  A status of 0 indicates success.
 * @context: User-specified context associated with the call.
 */
int rdma_resolve_ip(struct rdma_addr_client *client,
		    struct sockaddr *src_addr, struct sockaddr *dst_addr,
		    struct rdma_dev_addr *addr, int timeout_ms,
		    void (*callback)(int status, struct sockaddr *src_addr,
				     struct rdma_dev_addr *addr, void *context),
		    void *context);

int rdma_resolve_ip_route(struct sockaddr *src_addr,
			  const struct sockaddr *dst_addr,
			  struct rdma_dev_addr *addr);

void rdma_addr_cancel(struct rdma_dev_addr *addr);

int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev,
	      const unsigned char *dst_dev_addr);

int rdma_addr_size(struct sockaddr *addr);

int rdma_addr_find_smac_by_sgid(union ib_gid *sgid, u8 *smac, u16 *vlan_id);
int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
				 const union ib_gid *dgid,
				 u8 *smac, u16 *vlan_id, int *if_index,
				 int *hoplimit);


static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr) { return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9]; }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty37100.00%1100.00%
Total37100.00%1100.00%


static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey) { dev_addr->broadcast[8] = pkey >> 8; dev_addr->broadcast[9] = (unsigned char) pkey; }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty39100.00%1100.00%
Total39100.00%1100.00%


static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { memcpy(gid, dev_addr->broadcast + 4, sizeof *gid); }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty32100.00%1100.00%
Total32100.00%1100.00%


static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr) { return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0; }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty23100.00%2100.00%
Total23100.00%2100.00%


static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev) { return is_vlan_dev(dev) ? vlan_dev_vlan_id(dev) : 0xffff; }

Contributors

PersonTokensPropCommitsCommitProp
Moni Shoua1453.85%133.33%
Eli Cohen934.62%133.33%
Parav Pandit311.54%133.33%
Total26100.00%3100.00%


static inline int rdma_ip2gid(struct sockaddr *addr, union ib_gid *gid) { switch (addr->sa_family) { case AF_INET: ipv6_addr_set_v4mapped(((struct sockaddr_in *) addr)->sin_addr.s_addr, (struct in6_addr *)gid); break; case AF_INET6: *(struct in6_addr *)&gid->raw = ((struct sockaddr_in6 *)addr)->sin6_addr; break; default: return -EINVAL; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Matan Barak7890.70%150.00%
Arnd Bergmann89.30%150.00%
Total86100.00%2100.00%

/* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */
static inline void rdma_gid2ip(struct sockaddr *out, const union ib_gid *gid) { if (ipv6_addr_v4mapped((struct in6_addr *)gid)) { struct sockaddr_in *out_in = (struct sockaddr_in *)out; memset(out_in, 0, sizeof(*out_in)); out_in->sin_family = AF_INET; memcpy(&out_in->sin_addr.s_addr, gid->raw + 12, 4); } else { struct sockaddr_in6 *out_in = (struct sockaddr_in6 *)out; memset(out_in, 0, sizeof(*out_in)); out_in->sin6_family = AF_INET6; memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16); } }

Contributors

PersonTokensPropCommitsCommitProp
Matan Barak12998.47%133.33%
Ira Weiny10.76%133.33%
Honggang Li10.76%133.33%
Total131100.00%3100.00%


static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { struct net_device *dev; struct in_device *ip4; dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if); if (dev) { ip4 = in_dev_get(dev); if (ip4 && ip4->ifa_list && ip4->ifa_list->ifa_address) ipv6_addr_set_v4mapped(ip4->ifa_list->ifa_address, (struct in6_addr *)gid); if (ip4) in_dev_put(ip4); dev_put(dev); } }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen5052.08%240.00%
Moni Shoua3435.42%120.00%
Bart Van Assche88.33%120.00%
Michal Kalderon44.17%120.00%
Total96100.00%5100.00%


static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { if (dev_addr->transport == RDMA_TRANSPORT_IB && dev_addr->dev_type != ARPHRD_INFINIBAND) iboe_addr_get_sgid(dev_addr, gid); else memcpy(gid, dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid); }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty2849.12%250.00%
Eli Cohen2238.60%125.00%
Michael S. Tsirkin712.28%125.00%
Total57100.00%4100.00%


static inline void rdma_addr_set_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { memcpy(dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid); }

Contributors

PersonTokensPropCommitsCommitProp
Sean Hefty35100.00%2100.00%
Total35100.00%2100.00%


static inline void rdma_addr_get_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { memcpy(gid, dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid); }

Contributors

PersonTokensPropCommitsCommitProp
Tom Tucker2880.00%150.00%
Sean Hefty720.00%150.00%
Total35100.00%2100.00%


static inline void rdma_addr_set_dgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) { memcpy(dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid); }

Contributors

PersonTokensPropCommitsCommitProp
Tom Tucker2777.14%150.00%
Sean Hefty822.86%150.00%
Total35100.00%2100.00%


static inline enum ib_mtu iboe_get_mtu(int mtu) { /* * reduce IB headers from effective IBoE MTU. 28 stands for * atomic header which is the biggest possible header after BTH */ mtu = mtu - IB_GRH_BYTES - IB_BTH_BYTES - 28; if (mtu >= ib_mtu_enum_to_int(IB_MTU_4096)) return IB_MTU_4096; else if (mtu >= ib_mtu_enum_to_int(IB_MTU_2048)) return IB_MTU_2048; else if (mtu >= ib_mtu_enum_to_int(IB_MTU_1024)) return IB_MTU_1024; else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512)) return IB_MTU_512; else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256)) return IB_MTU_256; else return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen90100.00%1100.00%
Total90100.00%1100.00%


static inline int iboe_get_rate(struct net_device *dev) { struct ethtool_link_ksettings cmd; int err; rtnl_lock(); err = __ethtool_get_link_ksettings(dev, &cmd); rtnl_unlock(); if (err) return IB_RATE_PORT_CURRENT; if (cmd.base.speed >= 40000) return IB_RATE_40_GBPS; else if (cmd.base.speed >= 30000) return IB_RATE_30_GBPS; else if (cmd.base.speed >= 20000) return IB_RATE_20_GBPS; else if (cmd.base.speed >= 10000) return IB_RATE_10_GBPS; else return IB_RATE_PORT_CURRENT; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen6867.33%133.33%
David Decotigny1817.82%133.33%
Jiri Pirko1514.85%133.33%
Total101100.00%3100.00%


static inline int rdma_link_local_addr(struct in6_addr *addr) { if (addr->s6_addr32[0] == htonl(0xfe800000) && addr->s6_addr32[1] == 0) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen41100.00%1100.00%
Total41100.00%1100.00%


static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac) { memcpy(mac, &addr->s6_addr[8], 3); memcpy(mac + 3, &addr->s6_addr[13], 3); mac[0] ^= 2; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen55100.00%1100.00%
Total55100.00%1100.00%


static inline int rdma_is_multicast_addr(struct in6_addr *addr) { u32 ipv4_addr; if (addr->s6_addr[0] == 0xff) return 1; memcpy(&ipv4_addr, addr->s6_addr + 12, 4); return (ipv6_addr_v4mapped(addr) && ipv4_is_multicast(ipv4_addr)); }

Contributors

PersonTokensPropCommitsCommitProp
Noa Osherovich3562.50%150.00%
Eli Cohen2137.50%150.00%
Total56100.00%2100.00%


static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac) { int i; mac[0] = 0x33; mac[1] = 0x33; for (i = 2; i < 6; ++i) mac[i] = addr->s6_addr[i + 10]; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen60100.00%1100.00%
Total60100.00%1100.00%


static inline u16 rdma_get_vlan_id(union ib_gid *dgid) { u16 vid; vid = dgid->raw[11] << 8 | dgid->raw[12]; return vid < 0x1000 ? vid : 0xffff; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen42100.00%1100.00%
Total42100.00%1100.00%


static inline struct net_device *rdma_vlan_dev_real_dev(const struct net_device *dev) { return is_vlan_dev(dev) ? vlan_dev_real_dev(dev) : NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen2485.71%133.33%
Parav Pandit310.71%133.33%
Sean Hefty13.57%133.33%
Total28100.00%3100.00%

#endif /* IB_ADDR_H */

Overall Contributors

PersonTokensPropCommitsCommitProp
Eli Cohen49234.48%26.45%
Sean Hefty39327.54%929.03%
Matan Barak28620.04%516.13%
Tom Tucker755.26%13.23%
Moni Shoua604.20%13.23%
Noa Osherovich352.45%13.23%
David Decotigny181.26%13.23%
Jiri Pirko151.05%13.23%
Guy Shapiro110.77%13.23%
Arnd Bergmann80.56%13.23%
Bart Van Assche80.56%13.23%
Michael S. Tsirkin70.49%13.23%
Parav Pandit60.42%13.23%
Michal Kalderon40.28%13.23%
Somnath Kotur40.28%13.23%
Ira Weiny30.21%13.23%
Honggang Li10.07%13.23%
Or Gerlitz10.07%13.23%
Total1427100.00%31100.00%
Directory: include/rdma
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.