2009-02-24 15:30:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Oracle. 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/inetdevice.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-05-27 13:12:25 +00:00
|
|
|
#include <linux/module.h>
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2016-06-13 16:44:26 +00:00
|
|
|
#include "rds_single_path.h"
|
2009-02-24 15:30:30 +00:00
|
|
|
#include "rds.h"
|
|
|
|
#include "ib.h"
|
2016-03-01 23:20:46 +00:00
|
|
|
#include "ib_mr.h"
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2017-02-28 06:45:40 +00:00
|
|
|
static unsigned int rds_ib_mr_1m_pool_size = RDS_MR_1M_POOL_SIZE;
|
|
|
|
static unsigned int rds_ib_mr_8k_pool_size = RDS_MR_8K_POOL_SIZE;
|
2009-07-17 13:13:22 +00:00
|
|
|
unsigned int rds_ib_retry_count = RDS_IB_DEFAULT_RETRY_COUNT;
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2016-03-01 23:20:46 +00:00
|
|
|
module_param(rds_ib_mr_1m_pool_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_mr_1m_pool_size, " Max number of 1M mr per HCA");
|
|
|
|
module_param(rds_ib_mr_8k_pool_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_mr_8k_pool_size, " Max number of 8K mr per HCA");
|
2009-07-17 13:13:22 +00:00
|
|
|
module_param(rds_ib_retry_count, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_ib_retry_count, " Number of hw retries before reporting an error");
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2010-07-15 19:34:33 +00:00
|
|
|
/*
|
|
|
|
* we have a clumsy combination of RCU and a rwsem protecting this list
|
|
|
|
* because it is used both in the get_mr fast path and while blocking in
|
|
|
|
* the FMR flushing path.
|
|
|
|
*/
|
|
|
|
DECLARE_RWSEM(rds_ib_devices_lock);
|
2009-02-24 15:30:30 +00:00
|
|
|
struct list_head rds_ib_devices;
|
|
|
|
|
2009-04-01 08:20:19 +00:00
|
|
|
/* NOTE: if also grabbing ibdev lock, grab this first */
|
2009-02-24 15:30:30 +00:00
|
|
|
DEFINE_SPINLOCK(ib_nodev_conns_lock);
|
|
|
|
LIST_HEAD(ib_nodev_conns);
|
|
|
|
|
2010-10-19 08:08:33 +00:00
|
|
|
static void rds_ib_nodev_connect(void)
|
2010-05-24 20:16:57 +00:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
|
|
|
|
spin_lock(&ib_nodev_conns_lock);
|
|
|
|
list_for_each_entry(ic, &ib_nodev_conns, ib_node)
|
|
|
|
rds_conn_connect_if_down(ic->conn);
|
|
|
|
spin_unlock(&ib_nodev_conns_lock);
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:08:33 +00:00
|
|
|
static void rds_ib_dev_shutdown(struct rds_ib_device *rds_ibdev)
|
2010-05-24 20:16:57 +00:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rds_ibdev->spinlock, flags);
|
|
|
|
list_for_each_entry(ic, &rds_ibdev->conn_list, ib_node)
|
|
|
|
rds_conn_drop(ic->conn);
|
|
|
|
spin_unlock_irqrestore(&rds_ibdev->spinlock, flags);
|
|
|
|
}
|
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
/*
|
|
|
|
* rds_ib_destroy_mr_pool() blocks on a few things and mrs drop references
|
|
|
|
* from interrupt context so we push freing off into a work struct in krdsd.
|
|
|
|
*/
|
|
|
|
static void rds_ib_dev_free(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct rds_ib_ipaddr *i_ipaddr, *i_next;
|
|
|
|
struct rds_ib_device *rds_ibdev = container_of(work,
|
|
|
|
struct rds_ib_device, free_work);
|
|
|
|
|
2015-09-11 04:20:57 +00:00
|
|
|
if (rds_ibdev->mr_8k_pool)
|
|
|
|
rds_ib_destroy_mr_pool(rds_ibdev->mr_8k_pool);
|
|
|
|
if (rds_ibdev->mr_1m_pool)
|
|
|
|
rds_ib_destroy_mr_pool(rds_ibdev->mr_1m_pool);
|
2010-05-18 22:48:51 +00:00
|
|
|
if (rds_ibdev->pd)
|
|
|
|
ib_dealloc_pd(rds_ibdev->pd);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(i_ipaddr, i_next, &rds_ibdev->ipaddr_list, list) {
|
|
|
|
list_del(&i_ipaddr->list);
|
|
|
|
kfree(i_ipaddr);
|
|
|
|
}
|
|
|
|
|
2017-02-23 12:47:01 +00:00
|
|
|
kfree(rds_ibdev->vector_load);
|
2016-07-04 23:16:36 +00:00
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
kfree(rds_ibdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_dev_put(struct rds_ib_device *rds_ibdev)
|
|
|
|
{
|
|
|
|
BUG_ON(atomic_read(&rds_ibdev->refcount) <= 0);
|
|
|
|
if (atomic_dec_and_test(&rds_ibdev->refcount))
|
|
|
|
queue_work(rds_wq, &rds_ibdev->free_work);
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:08:33 +00:00
|
|
|
static void rds_ib_add_one(struct ib_device *device)
|
2009-02-24 15:30:30 +00:00
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
|
|
|
/* Only handle IB (no iWARP) devices */
|
|
|
|
if (device->node_type != RDMA_NODE_IB_CA)
|
|
|
|
return;
|
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
rds_ibdev = kzalloc_node(sizeof(struct rds_ib_device), GFP_KERNEL,
|
|
|
|
ibdev_to_node(device));
|
2009-02-24 15:30:30 +00:00
|
|
|
if (!rds_ibdev)
|
2015-12-18 08:59:47 +00:00
|
|
|
return;
|
2009-02-24 15:30:30 +00:00
|
|
|
|
|
|
|
spin_lock_init(&rds_ibdev->spinlock);
|
2010-05-18 22:48:51 +00:00
|
|
|
atomic_set(&rds_ibdev->refcount, 1);
|
|
|
|
INIT_WORK(&rds_ibdev->free_work, rds_ib_dev_free);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2015-12-18 08:59:47 +00:00
|
|
|
rds_ibdev->max_wrs = device->attrs.max_qp_wr;
|
|
|
|
rds_ibdev->max_sge = min(device->attrs.max_sge, RDS_IB_MAX_SGE);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2016-03-01 23:20:52 +00:00
|
|
|
rds_ibdev->has_fr = (device->attrs.device_cap_flags &
|
|
|
|
IB_DEVICE_MEM_MGT_EXTENSIONS);
|
|
|
|
rds_ibdev->has_fmr = (device->alloc_fmr && device->dealloc_fmr &&
|
|
|
|
device->map_phys_fmr && device->unmap_fmr);
|
|
|
|
rds_ibdev->use_fastreg = (rds_ibdev->has_fr && !rds_ibdev->has_fmr);
|
|
|
|
|
2015-12-18 08:59:47 +00:00
|
|
|
rds_ibdev->fmr_max_remaps = device->attrs.max_map_per_fmr?: 32;
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ibdev->max_1m_mrs = device->attrs.max_mr ?
|
2015-12-18 08:59:47 +00:00
|
|
|
min_t(unsigned int, (device->attrs.max_mr / 2),
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ib_mr_1m_pool_size) : rds_ib_mr_1m_pool_size;
|
2015-09-11 04:20:57 +00:00
|
|
|
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ibdev->max_8k_mrs = device->attrs.max_mr ?
|
2015-12-18 08:59:47 +00:00
|
|
|
min_t(unsigned int, ((device->attrs.max_mr / 2) * RDS_MR_8K_SCALE),
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ib_mr_8k_pool_size) : rds_ib_mr_8k_pool_size;
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2015-12-18 08:59:47 +00:00
|
|
|
rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom;
|
|
|
|
rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom;
|
2010-01-12 18:50:48 +00:00
|
|
|
|
2016-07-04 23:16:36 +00:00
|
|
|
rds_ibdev->vector_load = kzalloc(sizeof(int) * device->num_comp_vectors,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!rds_ibdev->vector_load) {
|
|
|
|
pr_err("RDS/IB: %s failed to allocate vector memory\n",
|
|
|
|
__func__);
|
|
|
|
goto put_dev;
|
|
|
|
}
|
|
|
|
|
2009-02-24 15:30:30 +00:00
|
|
|
rds_ibdev->dev = device;
|
2016-09-05 10:56:17 +00:00
|
|
|
rds_ibdev->pd = ib_alloc_pd(device, 0);
|
2010-05-18 22:48:51 +00:00
|
|
|
if (IS_ERR(rds_ibdev->pd)) {
|
|
|
|
rds_ibdev->pd = NULL;
|
|
|
|
goto put_dev;
|
|
|
|
}
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2015-09-11 04:20:57 +00:00
|
|
|
rds_ibdev->mr_1m_pool =
|
|
|
|
rds_ib_create_mr_pool(rds_ibdev, RDS_IB_MR_1M_POOL);
|
|
|
|
if (IS_ERR(rds_ibdev->mr_1m_pool)) {
|
|
|
|
rds_ibdev->mr_1m_pool = NULL;
|
2010-05-18 22:48:51 +00:00
|
|
|
goto put_dev;
|
2009-02-24 15:30:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 04:20:57 +00:00
|
|
|
rds_ibdev->mr_8k_pool =
|
|
|
|
rds_ib_create_mr_pool(rds_ibdev, RDS_IB_MR_8K_POOL);
|
|
|
|
if (IS_ERR(rds_ibdev->mr_8k_pool)) {
|
|
|
|
rds_ibdev->mr_8k_pool = NULL;
|
|
|
|
goto put_dev;
|
|
|
|
}
|
|
|
|
|
2016-03-01 23:20:46 +00:00
|
|
|
rdsdebug("RDS/IB: max_mr = %d, max_wrs = %d, max_sge = %d, fmr_max_remaps = %d, max_1m_mrs = %d, max_8k_mrs = %d\n",
|
2015-12-18 08:59:47 +00:00
|
|
|
device->attrs.max_fmr, rds_ibdev->max_wrs, rds_ibdev->max_sge,
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ibdev->fmr_max_remaps, rds_ibdev->max_1m_mrs,
|
|
|
|
rds_ibdev->max_8k_mrs);
|
2015-09-11 04:20:57 +00:00
|
|
|
|
2016-03-01 23:20:52 +00:00
|
|
|
pr_info("RDS/IB: %s: %s supported and preferred\n",
|
|
|
|
device->name,
|
|
|
|
rds_ibdev->use_fastreg ? "FRMR" : "FMR");
|
|
|
|
|
2009-02-24 15:30:30 +00:00
|
|
|
INIT_LIST_HEAD(&rds_ibdev->ipaddr_list);
|
|
|
|
INIT_LIST_HEAD(&rds_ibdev->conn_list);
|
2010-07-15 19:34:33 +00:00
|
|
|
|
|
|
|
down_write(&rds_ib_devices_lock);
|
|
|
|
list_add_tail_rcu(&rds_ibdev->list, &rds_ib_devices);
|
|
|
|
up_write(&rds_ib_devices_lock);
|
2010-05-18 22:48:51 +00:00
|
|
|
atomic_inc(&rds_ibdev->refcount);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
|
|
|
ib_set_client_data(device, &rds_ib_client, rds_ibdev);
|
2010-05-18 22:48:51 +00:00
|
|
|
atomic_inc(&rds_ibdev->refcount);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2010-05-24 20:16:57 +00:00
|
|
|
rds_ib_nodev_connect();
|
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
put_dev:
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 15:30:30 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
/*
|
|
|
|
* New connections use this to find the device to associate with the
|
|
|
|
* connection. It's not in the fast path so we're not concerned about the
|
|
|
|
* performance of the IB call. (As of this writing, it uses an interrupt
|
|
|
|
* blocking spinlock to serialize walking a per-device list of all registered
|
|
|
|
* clients.)
|
|
|
|
*
|
|
|
|
* RCU is used to handle incoming connections racing with device teardown.
|
|
|
|
* Rather than use a lock to serialize removal from the client_data and
|
|
|
|
* getting a new reference, we use an RCU grace period. The destruction
|
|
|
|
* path removes the device from client_data and then waits for all RCU
|
|
|
|
* readers to finish.
|
|
|
|
*
|
|
|
|
* A new connection can get NULL from this if its arriving on a
|
|
|
|
* device that is in the process of being removed.
|
|
|
|
*/
|
|
|
|
struct rds_ib_device *rds_ib_get_client_data(struct ib_device *device)
|
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
rds_ibdev = ib_get_client_data(device, &rds_ib_client);
|
|
|
|
if (rds_ibdev)
|
|
|
|
atomic_inc(&rds_ibdev->refcount);
|
|
|
|
rcu_read_unlock();
|
|
|
|
return rds_ibdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IB stack is letting us know that a device is going away. This can
|
|
|
|
* happen if the underlying HCA driver is removed or if PCI hotplug is removing
|
|
|
|
* the pci function, for example.
|
|
|
|
*
|
|
|
|
* This can be called at any time and can be racing with any other RDS path.
|
|
|
|
*/
|
2015-07-30 14:50:14 +00:00
|
|
|
static void rds_ib_remove_one(struct ib_device *device, void *client_data)
|
2009-02-24 15:30:30 +00:00
|
|
|
{
|
2015-07-30 14:50:14 +00:00
|
|
|
struct rds_ib_device *rds_ibdev = client_data;
|
2009-02-24 15:30:30 +00:00
|
|
|
|
|
|
|
if (!rds_ibdev)
|
|
|
|
return;
|
|
|
|
|
2010-05-24 20:16:57 +00:00
|
|
|
rds_ib_dev_shutdown(rds_ibdev);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2010-07-15 19:34:33 +00:00
|
|
|
/* stop connection attempts from getting a reference to this device. */
|
|
|
|
ib_set_client_data(device, &rds_ib_client, NULL);
|
|
|
|
|
|
|
|
down_write(&rds_ib_devices_lock);
|
|
|
|
list_del_rcu(&rds_ibdev->list);
|
|
|
|
up_write(&rds_ib_devices_lock);
|
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
/*
|
2010-07-15 19:34:33 +00:00
|
|
|
* This synchronize rcu is waiting for readers of both the ib
|
|
|
|
* client data and the devices list to finish before we drop
|
|
|
|
* both of those references.
|
2010-05-18 22:48:51 +00:00
|
|
|
*/
|
|
|
|
synchronize_rcu();
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 15:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ib_client rds_ib_client = {
|
|
|
|
.name = "rds_ib",
|
|
|
|
.add = rds_ib_add_one,
|
|
|
|
.remove = rds_ib_remove_one
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rds_ib_conn_info_visitor(struct rds_connection *conn,
|
|
|
|
void *buffer)
|
|
|
|
{
|
|
|
|
struct rds_info_rdma_connection *iinfo = buffer;
|
|
|
|
struct rds_ib_connection *ic;
|
|
|
|
|
|
|
|
/* We will only ever look at IB transports */
|
|
|
|
if (conn->c_trans != &rds_ib_transport)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iinfo->src_addr = conn->c_laddr;
|
|
|
|
iinfo->dst_addr = conn->c_faddr;
|
|
|
|
|
|
|
|
memset(&iinfo->src_gid, 0, sizeof(iinfo->src_gid));
|
|
|
|
memset(&iinfo->dst_gid, 0, sizeof(iinfo->dst_gid));
|
|
|
|
if (rds_conn_state(conn) == RDS_CONN_UP) {
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
struct rdma_dev_addr *dev_addr;
|
|
|
|
|
|
|
|
ic = conn->c_transport_data;
|
|
|
|
dev_addr = &ic->i_cm_id->route.addr.dev_addr;
|
|
|
|
|
RDMA/cm: fix loopback address support
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>
2009-11-19 21:26:06 +00:00
|
|
|
rdma_addr_get_sgid(dev_addr, (union ib_gid *) &iinfo->src_gid);
|
|
|
|
rdma_addr_get_dgid(dev_addr, (union ib_gid *) &iinfo->dst_gid);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
2010-05-18 22:48:51 +00:00
|
|
|
rds_ibdev = ic->rds_ibdev;
|
2009-02-24 15:30:30 +00:00
|
|
|
iinfo->max_send_wr = ic->i_send_ring.w_nr;
|
|
|
|
iinfo->max_recv_wr = ic->i_recv_ring.w_nr;
|
|
|
|
iinfo->max_send_sge = rds_ibdev->max_sge;
|
|
|
|
rds_ib_get_mr_info(rds_ibdev, iinfo);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_ic_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
|
|
|
rds_for_each_conn_info(sock, len, iter, lens,
|
|
|
|
rds_ib_conn_info_visitor,
|
|
|
|
sizeof(struct rds_info_rdma_connection));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Early RDS/IB was built to only bind to an address if there is an IPoIB
|
|
|
|
* device with that address set.
|
|
|
|
*
|
|
|
|
* If it were me, I'd advocate for something more flexible. Sending and
|
|
|
|
* receiving should be device-agnostic. Transports would try and maintain
|
|
|
|
* connections between peers who have messages queued. Userspace would be
|
|
|
|
* allowed to influence which paths have priority. We could call userspace
|
|
|
|
* asserting this policy "routing".
|
|
|
|
*/
|
2015-08-05 05:43:25 +00:00
|
|
|
static int rds_ib_laddr_check(struct net *net, __be32 addr)
|
2009-02-24 15:30:30 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rdma_cm_id *cm_id;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
/* Create a CMA ID and try to bind it. This catches both
|
|
|
|
* IB and iWARP capable NICs.
|
|
|
|
*/
|
2015-10-22 12:20:10 +00:00
|
|
|
cm_id = rdma_create_id(&init_net, NULL, NULL, RDMA_PS_TCP, IB_QPT_RC);
|
2009-04-09 14:09:46 +00:00
|
|
|
if (IS_ERR(cm_id))
|
|
|
|
return PTR_ERR(cm_id);
|
2009-02-24 15:30:30 +00:00
|
|
|
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_addr.s_addr = addr;
|
|
|
|
|
|
|
|
/* rdma_bind_addr will only succeed for IB & iWARP devices */
|
|
|
|
ret = rdma_bind_addr(cm_id, (struct sockaddr *)&sin);
|
|
|
|
/* due to this, we will claim to support iWARP devices unless we
|
|
|
|
check node_type. */
|
2013-12-19 04:49:42 +00:00
|
|
|
if (ret || !cm_id->device ||
|
|
|
|
cm_id->device->node_type != RDMA_NODE_IB_CA)
|
2009-02-24 15:30:30 +00:00
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
rdsdebug("addr %pI4 ret %d node type %d\n",
|
|
|
|
&addr, ret,
|
|
|
|
cm_id->device ? cm_id->device->node_type : -1);
|
|
|
|
|
|
|
|
rdma_destroy_id(cm_id);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-06-25 21:59:49 +00:00
|
|
|
static void rds_ib_unregister_client(void)
|
|
|
|
{
|
|
|
|
ib_unregister_client(&rds_ib_client);
|
|
|
|
/* wait for rds_ib_dev_free() to complete */
|
|
|
|
flush_workqueue(rds_wq);
|
|
|
|
}
|
|
|
|
|
2009-02-24 15:30:30 +00:00
|
|
|
void rds_ib_exit(void)
|
|
|
|
{
|
|
|
|
rds_info_deregister_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
|
2010-06-25 21:59:49 +00:00
|
|
|
rds_ib_unregister_client();
|
2010-06-25 21:58:16 +00:00
|
|
|
rds_ib_destroy_nodev_conns();
|
2009-02-24 15:30:30 +00:00
|
|
|
rds_ib_sysctl_exit();
|
|
|
|
rds_ib_recv_exit();
|
|
|
|
rds_trans_unregister(&rds_ib_transport);
|
2016-03-01 23:20:46 +00:00
|
|
|
rds_ib_mr_exit();
|
2009-02-24 15:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct rds_transport rds_ib_transport = {
|
|
|
|
.laddr_check = rds_ib_laddr_check,
|
2016-06-30 23:11:10 +00:00
|
|
|
.xmit_path_complete = rds_ib_xmit_path_complete,
|
2009-02-24 15:30:30 +00:00
|
|
|
.xmit = rds_ib_xmit,
|
|
|
|
.xmit_rdma = rds_ib_xmit_rdma,
|
2010-01-12 22:33:38 +00:00
|
|
|
.xmit_atomic = rds_ib_xmit_atomic,
|
2016-06-30 23:11:15 +00:00
|
|
|
.recv_path = rds_ib_recv_path,
|
2009-02-24 15:30:30 +00:00
|
|
|
.conn_alloc = rds_ib_conn_alloc,
|
|
|
|
.conn_free = rds_ib_conn_free,
|
2016-06-30 23:11:16 +00:00
|
|
|
.conn_path_connect = rds_ib_conn_path_connect,
|
2016-06-30 23:11:10 +00:00
|
|
|
.conn_path_shutdown = rds_ib_conn_path_shutdown,
|
2009-02-24 15:30:30 +00:00
|
|
|
.inc_copy_to_user = rds_ib_inc_copy_to_user,
|
|
|
|
.inc_free = rds_ib_inc_free,
|
|
|
|
.cm_initiate_connect = rds_ib_cm_initiate_connect,
|
|
|
|
.cm_handle_connect = rds_ib_cm_handle_connect,
|
|
|
|
.cm_connect_complete = rds_ib_cm_connect_complete,
|
|
|
|
.stats_info_copy = rds_ib_stats_info_copy,
|
|
|
|
.exit = rds_ib_exit,
|
|
|
|
.get_mr = rds_ib_get_mr,
|
|
|
|
.sync_mr = rds_ib_sync_mr,
|
|
|
|
.free_mr = rds_ib_free_mr,
|
|
|
|
.flush_mrs = rds_ib_flush_mrs,
|
|
|
|
.t_owner = THIS_MODULE,
|
|
|
|
.t_name = "infiniband",
|
2009-08-21 12:28:34 +00:00
|
|
|
.t_type = RDS_TRANS_IB
|
2009-02-24 15:30:30 +00:00
|
|
|
};
|
|
|
|
|
2010-07-09 19:26:20 +00:00
|
|
|
int rds_ib_init(void)
|
2009-02-24 15:30:30 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&rds_ib_devices);
|
|
|
|
|
2016-03-01 23:20:46 +00:00
|
|
|
ret = rds_ib_mr_init();
|
2010-07-06 22:09:56 +00:00
|
|
|
if (ret)
|
2011-02-01 10:42:43 +00:00
|
|
|
goto out;
|
2010-07-06 22:09:56 +00:00
|
|
|
|
2015-08-25 19:02:01 +00:00
|
|
|
ret = ib_register_client(&rds_ib_client);
|
|
|
|
if (ret)
|
2016-03-01 23:20:46 +00:00
|
|
|
goto out_mr_exit;
|
2015-08-25 19:02:01 +00:00
|
|
|
|
2009-02-24 15:30:30 +00:00
|
|
|
ret = rds_ib_sysctl_init();
|
|
|
|
if (ret)
|
|
|
|
goto out_ibreg;
|
|
|
|
|
|
|
|
ret = rds_ib_recv_init();
|
|
|
|
if (ret)
|
|
|
|
goto out_sysctl;
|
|
|
|
|
|
|
|
ret = rds_trans_register(&rds_ib_transport);
|
|
|
|
if (ret)
|
|
|
|
goto out_recv;
|
|
|
|
|
|
|
|
rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out_recv:
|
|
|
|
rds_ib_recv_exit();
|
|
|
|
out_sysctl:
|
|
|
|
rds_ib_sysctl_exit();
|
|
|
|
out_ibreg:
|
2010-06-25 21:59:49 +00:00
|
|
|
rds_ib_unregister_client();
|
2016-03-01 23:20:46 +00:00
|
|
|
out_mr_exit:
|
|
|
|
rds_ib_mr_exit();
|
2009-02-24 15:30:30 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|