1
0
Fork 0

RDMA/rxe: Add ib_device_get_by_name() and use it in rxe

rxe has an open coded version of this that is not as safe as the core
version. This lets us eliminate the internal device list entirely from
rxe.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
hifive-unleashed-5.1
Jason Gunthorpe 2019-02-12 21:12:55 -07:00
parent c367074b6c
commit 6cc2c8e535
6 changed files with 32 additions and 33 deletions

View File

@ -240,6 +240,34 @@ static struct ib_device *__ib_device_get_by_name(const char *name)
return NULL;
}
/**
* ib_device_get_by_name - Find an IB device by name
* @name: The name to look for
* @driver_id: The driver ID that must match (RDMA_DRIVER_UNKNOWN matches all)
*
* Find and hold an ib_device by its name. The caller must call
* ib_device_put() on the returned pointer.
*/
struct ib_device *ib_device_get_by_name(const char *name,
enum rdma_driver_id driver_id)
{
struct ib_device *device;
down_read(&devices_rwsem);
device = __ib_device_get_by_name(name);
if (device && driver_id != RDMA_DRIVER_UNKNOWN &&
device->driver_id != driver_id)
device = NULL;
if (device) {
if (!ib_device_try_get(device))
device = NULL;
}
up_read(&devices_rwsem);
return device;
}
EXPORT_SYMBOL(ib_device_get_by_name);
int ib_device_rename(struct ib_device *ibdev, const char *name)
{
int ret;

View File

@ -69,8 +69,6 @@ void rxe_dealloc(struct ib_device *ib_dev)
if (rxe->tfm)
crypto_free_shash(rxe->tfm);
list_del(&rxe->list);
}
/* initialize rxe device parameters */
@ -275,7 +273,6 @@ static int rxe_init(struct rxe_dev *rxe)
spin_lock_init(&rxe->mmap_offset_lock);
spin_lock_init(&rxe->pending_lock);
INIT_LIST_HEAD(&rxe->pending_mmaps);
INIT_LIST_HEAD(&rxe->list);
mutex_init(&rxe->usdev_lock);

View File

@ -99,8 +99,6 @@ int rxe_add(struct rxe_dev *rxe, unsigned int mtu);
void rxe_rcv(struct sk_buff *skb);
struct rxe_dev *get_rxe_by_name(const char *name);
/* The caller must do a matching ib_device_put(&dev->ib_dev) */
static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev)
{

View File

@ -45,25 +45,6 @@
#include "rxe_net.h"
#include "rxe_loc.h"
static LIST_HEAD(rxe_dev_list);
static DEFINE_SPINLOCK(dev_list_lock); /* spinlock for device list */
struct rxe_dev *get_rxe_by_name(const char *name)
{
struct rxe_dev *rxe;
struct rxe_dev *found = NULL;
spin_lock_bh(&dev_list_lock);
list_for_each_entry(rxe, &rxe_dev_list, list) {
if (!strcmp(name, dev_name(&rxe->ib_dev.dev))) {
found = rxe;
break;
}
}
spin_unlock_bh(&dev_list_lock);
return found;
}
static struct rxe_recv_sockets recv_sockets;
struct device *rxe_dma_device(struct rxe_dev *rxe)
@ -553,9 +534,6 @@ struct rxe_dev *rxe_net_add(struct net_device *ndev)
return NULL;
}
spin_lock_bh(&dev_list_lock);
list_add_tail(&rxe->list, &rxe_dev_list);
spin_unlock_bh(&dev_list_lock);
return rxe;
}

View File

@ -101,7 +101,7 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
{
int len;
char intf[32];
struct rxe_dev *rxe;
struct ib_device *ib_dev;
len = sanitize_arg(val, intf, sizeof(intf));
if (!len) {
@ -115,14 +115,13 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
return 0;
}
rxe = get_rxe_by_name(intf);
if (!rxe) {
ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE);
if (!ib_dev) {
pr_err("not configured on %s\n", intf);
return -EINVAL;
}
ib_unregister_device(&rxe->ib_dev);
ib_unregister_device_and_put(ib_dev);
return 0;
}

View File

@ -411,7 +411,6 @@ struct rxe_dev {
atomic64_t stats_counters[RXE_NUM_OF_COUNTERS];
struct rxe_port port;
struct list_head list;
struct crypto_shash *tfm;
};