mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-07 08:26:39 +07:00
6f8372b69c
The RDMA CM is intended to support the use of a loopback address when establishing a connection; however, the behavior of the CM when loopback addresses are used is confusing and does not always work, depending on whether loopback was specified by the server, the client, or both. The defined behavior of rdma_bind_addr is to associate an RDMA device with an rdma_cm_id, as long as the user specified a non- zero address. (ie they weren't just trying to reserve a port) Currently, if the loopback address is passed to rdam_bind_addr, no device is associated with the rdma_cm_id. Fix this. If a loopback address is specified by the client as the destination address for a connection, it will fail to establish a connection. This is true even if the server is listing across all addresses or on the loopback address itself. The issue is that the server tries to translate the IP address carried in the REQ message to a local net_device address, which fails. The translation is not needed in this case, since the REQ carries the actual HW address that should be used. Finally, cleanup loopback support to be more transport neutral. Replace separate calls to get/set the sgid and dgid from the device address to a single call that behaves correctly depending on the format of the device address. And support both IPv4 and IPv6 address formats. Signed-off-by: Sean Hefty <sean.hefty@intel.com> [ Fixed RDS build by s/ib_addr_get/rdma_addr_get/ - Roland ] Signed-off-by: Roland Dreier <rolandd@cisco.com>
151 lines
5.1 KiB
C
151 lines
5.1 KiB
C
/*
|
|
* 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/socket.h>
|
|
#include <rdma/ib_verbs.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 {
|
|
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;
|
|
};
|
|
|
|
/**
|
|
* rdma_translate_ip - Translate a local IP address to an RDMA hardware
|
|
* address.
|
|
*/
|
|
int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr);
|
|
|
|
/**
|
|
* 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.
|
|
* @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);
|
|
|
|
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);
|
|
|
|
static inline int ip_addr_size(struct sockaddr *addr)
|
|
{
|
|
return addr->sa_family == AF_INET6 ?
|
|
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
|
}
|
|
|
|
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];
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr)
|
|
{
|
|
return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0;
|
|
}
|
|
|
|
static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
|
|
{
|
|
memcpy(gid, dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#endif /* IB_ADDR_H */
|