RDMA/ocrdma: Incorporate the moving of GID Table mgmt to IB/Core
1.Change query_gid hook to return value from IB/Core GID management APIs. 2.Get rid of all the netdev notifier chain subscription code as well as maintenance of SGID Table in memory. 3.Implement get_netdev hook in driver. Signed-off-by: Somnath Kotur <somnath.kotur@avagotech.com> Signed-off-by: Devesh Sharma <devesh.sharma@avagotech.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
parent
5070cd2239
commit
cc36929e73
|
@ -246,7 +246,6 @@ struct ocrdma_dev {
|
|||
u16 base_eqid;
|
||||
u16 max_eq;
|
||||
|
||||
union ib_gid *sgid_tbl;
|
||||
/* provided synchronization to sgid table for
|
||||
* updating gid entries triggered by notifier.
|
||||
*/
|
||||
|
|
|
@ -67,8 +67,6 @@ static LIST_HEAD(ocrdma_dev_list);
|
|||
static DEFINE_SPINLOCK(ocrdma_devlist_lock);
|
||||
static DEFINE_IDR(ocrdma_dev_id);
|
||||
|
||||
static union ib_gid ocrdma_zero_sgid;
|
||||
|
||||
void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
|
||||
{
|
||||
u8 mac_addr[6];
|
||||
|
@ -83,135 +81,6 @@ void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
|
|||
guid[6] = mac_addr[4];
|
||||
guid[7] = mac_addr[5];
|
||||
}
|
||||
|
||||
static bool ocrdma_add_sgid(struct ocrdma_dev *dev, union ib_gid *new_sgid)
|
||||
{
|
||||
int i;
|
||||
unsigned long flags;
|
||||
|
||||
memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid));
|
||||
|
||||
|
||||
spin_lock_irqsave(&dev->sgid_lock, flags);
|
||||
for (i = 0; i < OCRDMA_MAX_SGID; i++) {
|
||||
if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid,
|
||||
sizeof(union ib_gid))) {
|
||||
/* found free entry */
|
||||
memcpy(&dev->sgid_tbl[i], new_sgid,
|
||||
sizeof(union ib_gid));
|
||||
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
||||
return true;
|
||||
} else if (!memcmp(&dev->sgid_tbl[i], new_sgid,
|
||||
sizeof(union ib_gid))) {
|
||||
/* entry already present, no addition is required. */
|
||||
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ocrdma_del_sgid(struct ocrdma_dev *dev, union ib_gid *sgid)
|
||||
{
|
||||
int found = false;
|
||||
int i;
|
||||
unsigned long flags;
|
||||
|
||||
|
||||
spin_lock_irqsave(&dev->sgid_lock, flags);
|
||||
/* first is default sgid, which cannot be deleted. */
|
||||
for (i = 1; i < OCRDMA_MAX_SGID; i++) {
|
||||
if (!memcmp(&dev->sgid_tbl[i], sgid, sizeof(union ib_gid))) {
|
||||
/* found matching entry */
|
||||
memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
||||
return found;
|
||||
}
|
||||
|
||||
static int ocrdma_addr_event(unsigned long event, struct net_device *netdev,
|
||||
union ib_gid *gid)
|
||||
{
|
||||
struct ib_event gid_event;
|
||||
struct ocrdma_dev *dev;
|
||||
bool found = false;
|
||||
bool updated = false;
|
||||
bool is_vlan = false;
|
||||
|
||||
is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN;
|
||||
if (is_vlan)
|
||||
netdev = rdma_vlan_dev_real_dev(netdev);
|
||||
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) {
|
||||
if (dev->nic_info.netdev == netdev) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
if (!found)
|
||||
return NOTIFY_DONE;
|
||||
|
||||
mutex_lock(&dev->dev_lock);
|
||||
switch (event) {
|
||||
case NETDEV_UP:
|
||||
updated = ocrdma_add_sgid(dev, gid);
|
||||
break;
|
||||
case NETDEV_DOWN:
|
||||
updated = ocrdma_del_sgid(dev, gid);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (updated) {
|
||||
/* GID table updated, notify the consumers about it */
|
||||
gid_event.device = &dev->ibdev;
|
||||
gid_event.element.port_num = 1;
|
||||
gid_event.event = IB_EVENT_GID_CHANGE;
|
||||
ib_dispatch_event(&gid_event);
|
||||
}
|
||||
mutex_unlock(&dev->dev_lock);
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static int ocrdma_inetaddr_event(struct notifier_block *notifier,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
struct in_ifaddr *ifa = ptr;
|
||||
union ib_gid gid;
|
||||
struct net_device *netdev = ifa->ifa_dev->dev;
|
||||
|
||||
ipv6_addr_set_v4mapped(ifa->ifa_address, (struct in6_addr *)&gid);
|
||||
return ocrdma_addr_event(event, netdev, &gid);
|
||||
}
|
||||
|
||||
static struct notifier_block ocrdma_inetaddr_notifier = {
|
||||
.notifier_call = ocrdma_inetaddr_event
|
||||
};
|
||||
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
|
||||
static int ocrdma_inet6addr_event(struct notifier_block *notifier,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
|
||||
union ib_gid *gid = (union ib_gid *)&ifa->addr;
|
||||
struct net_device *netdev = ifa->idev->dev;
|
||||
return ocrdma_addr_event(event, netdev, gid);
|
||||
}
|
||||
|
||||
static struct notifier_block ocrdma_inet6addr_notifier = {
|
||||
.notifier_call = ocrdma_inet6addr_event
|
||||
};
|
||||
|
||||
#endif /* IPV6 and VLAN */
|
||||
|
||||
static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device,
|
||||
u8 port_num)
|
||||
{
|
||||
|
@ -280,6 +149,9 @@ static int ocrdma_register_device(struct ocrdma_dev *dev)
|
|||
dev->ibdev.query_port = ocrdma_query_port;
|
||||
dev->ibdev.modify_port = ocrdma_modify_port;
|
||||
dev->ibdev.query_gid = ocrdma_query_gid;
|
||||
dev->ibdev.get_netdev = ocrdma_get_netdev;
|
||||
dev->ibdev.add_gid = ocrdma_add_gid;
|
||||
dev->ibdev.del_gid = ocrdma_del_gid;
|
||||
dev->ibdev.get_link_layer = ocrdma_link_layer;
|
||||
dev->ibdev.alloc_pd = ocrdma_alloc_pd;
|
||||
dev->ibdev.dealloc_pd = ocrdma_dealloc_pd;
|
||||
|
@ -342,12 +214,6 @@ static int ocrdma_register_device(struct ocrdma_dev *dev)
|
|||
static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
|
||||
{
|
||||
mutex_init(&dev->dev_lock);
|
||||
dev->sgid_tbl = kzalloc(sizeof(union ib_gid) *
|
||||
OCRDMA_MAX_SGID, GFP_KERNEL);
|
||||
if (!dev->sgid_tbl)
|
||||
goto alloc_err;
|
||||
spin_lock_init(&dev->sgid_lock);
|
||||
|
||||
dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) *
|
||||
OCRDMA_MAX_CQ, GFP_KERNEL);
|
||||
if (!dev->cq_tbl)
|
||||
|
@ -379,7 +245,6 @@ static void ocrdma_free_resources(struct ocrdma_dev *dev)
|
|||
kfree(dev->stag_arr);
|
||||
kfree(dev->qp_tbl);
|
||||
kfree(dev->cq_tbl);
|
||||
kfree(dev->sgid_tbl);
|
||||
}
|
||||
|
||||
/* OCRDMA sysfs interface */
|
||||
|
@ -425,68 +290,6 @@ static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev)
|
|||
device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]);
|
||||
}
|
||||
|
||||
static void ocrdma_add_default_sgid(struct ocrdma_dev *dev)
|
||||
{
|
||||
/* GID Index 0 - Invariant manufacturer-assigned EUI-64 */
|
||||
union ib_gid *sgid = &dev->sgid_tbl[0];
|
||||
|
||||
sgid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
|
||||
ocrdma_get_guid(dev, &sgid->raw[8]);
|
||||
}
|
||||
|
||||
static void ocrdma_init_ipv4_gids(struct ocrdma_dev *dev,
|
||||
struct net_device *net)
|
||||
{
|
||||
struct in_device *in_dev;
|
||||
union ib_gid gid;
|
||||
in_dev = in_dev_get(net);
|
||||
if (in_dev) {
|
||||
for_ifa(in_dev) {
|
||||
ipv6_addr_set_v4mapped(ifa->ifa_address,
|
||||
(struct in6_addr *)&gid);
|
||||
ocrdma_add_sgid(dev, &gid);
|
||||
}
|
||||
endfor_ifa(in_dev);
|
||||
in_dev_put(in_dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void ocrdma_init_ipv6_gids(struct ocrdma_dev *dev,
|
||||
struct net_device *net)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
struct inet6_dev *in6_dev;
|
||||
union ib_gid *pgid;
|
||||
struct inet6_ifaddr *ifp;
|
||||
in6_dev = in6_dev_get(net);
|
||||
if (in6_dev) {
|
||||
read_lock_bh(&in6_dev->lock);
|
||||
list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
|
||||
pgid = (union ib_gid *)&ifp->addr;
|
||||
ocrdma_add_sgid(dev, pgid);
|
||||
}
|
||||
read_unlock_bh(&in6_dev->lock);
|
||||
in6_dev_put(in6_dev);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ocrdma_init_gid_table(struct ocrdma_dev *dev)
|
||||
{
|
||||
struct net_device *net_dev;
|
||||
|
||||
for_each_netdev(&init_net, net_dev) {
|
||||
struct net_device *real_dev = rdma_vlan_dev_real_dev(net_dev) ?
|
||||
rdma_vlan_dev_real_dev(net_dev) : net_dev;
|
||||
|
||||
if (real_dev == dev->nic_info.netdev) {
|
||||
ocrdma_add_default_sgid(dev);
|
||||
ocrdma_init_ipv4_gids(dev, net_dev);
|
||||
ocrdma_init_ipv6_gids(dev, net_dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
|
||||
{
|
||||
int status = 0, i;
|
||||
|
@ -515,7 +318,6 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
|
|||
goto alloc_err;
|
||||
|
||||
ocrdma_init_service_level(dev);
|
||||
ocrdma_init_gid_table(dev);
|
||||
status = ocrdma_register_device(dev);
|
||||
if (status)
|
||||
goto alloc_err;
|
||||
|
@ -662,34 +464,12 @@ static struct ocrdma_driver ocrdma_drv = {
|
|||
.be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION,
|
||||
};
|
||||
|
||||
static void ocrdma_unregister_inet6addr_notifier(void)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
unregister_inet6addr_notifier(&ocrdma_inet6addr_notifier);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ocrdma_unregister_inetaddr_notifier(void)
|
||||
{
|
||||
unregister_inetaddr_notifier(&ocrdma_inetaddr_notifier);
|
||||
}
|
||||
|
||||
static int __init ocrdma_init_module(void)
|
||||
{
|
||||
int status;
|
||||
|
||||
ocrdma_init_debugfs();
|
||||
|
||||
status = register_inetaddr_notifier(&ocrdma_inetaddr_notifier);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
status = register_inet6addr_notifier(&ocrdma_inet6addr_notifier);
|
||||
if (status)
|
||||
goto err_notifier6;
|
||||
#endif
|
||||
|
||||
status = be_roce_register_driver(&ocrdma_drv);
|
||||
if (status)
|
||||
goto err_be_reg;
|
||||
|
@ -697,19 +477,13 @@ static int __init ocrdma_init_module(void)
|
|||
return 0;
|
||||
|
||||
err_be_reg:
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
ocrdma_unregister_inet6addr_notifier();
|
||||
err_notifier6:
|
||||
#endif
|
||||
ocrdma_unregister_inetaddr_notifier();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void __exit ocrdma_exit_module(void)
|
||||
{
|
||||
be_roce_unregister_driver(&ocrdma_drv);
|
||||
ocrdma_unregister_inet6addr_notifier();
|
||||
ocrdma_unregister_inetaddr_notifier();
|
||||
ocrdma_rem_debugfs();
|
||||
idr_destroy(&ocrdma_dev_id);
|
||||
}
|
||||
|
|
|
@ -140,6 +140,8 @@ enum {
|
|||
OCRDMA_DB_RQ_SHIFT = 24
|
||||
};
|
||||
|
||||
#define OCRDMA_ROUDP_FLAGS_SHIFT 0x03
|
||||
|
||||
#define OCRDMA_DB_CQ_RING_ID_MASK 0x3FF /* bits 0 - 9 */
|
||||
#define OCRDMA_DB_CQ_RING_ID_EXT_MASK 0x0C00 /* bits 10-11 of qid at 12-11 */
|
||||
/* qid #2 msbits at 12-11 */
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <rdma/iw_cm.h>
|
||||
#include <rdma/ib_umem.h>
|
||||
#include <rdma/ib_addr.h>
|
||||
#include <rdma/ib_cache.h>
|
||||
|
||||
#include "ocrdma.h"
|
||||
#include "ocrdma_hw.h"
|
||||
|
@ -64,6 +65,7 @@ int ocrdma_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
|
|||
int ocrdma_query_gid(struct ib_device *ibdev, u8 port,
|
||||
int index, union ib_gid *sgid)
|
||||
{
|
||||
int ret;
|
||||
struct ocrdma_dev *dev;
|
||||
|
||||
dev = get_ocrdma_dev(ibdev);
|
||||
|
@ -71,8 +73,28 @@ int ocrdma_query_gid(struct ib_device *ibdev, u8 port,
|
|||
if (index >= OCRDMA_MAX_SGID)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(sgid, &dev->sgid_tbl[index], sizeof(*sgid));
|
||||
ret = ib_get_cached_gid(ibdev, port, index, sgid);
|
||||
if (ret == -EAGAIN) {
|
||||
memcpy(sgid, &zgid, sizeof(*sgid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ocrdma_add_gid(struct ib_device *device,
|
||||
u8 port_num,
|
||||
unsigned int index,
|
||||
const union ib_gid *gid,
|
||||
const struct ib_gid_attr *attr,
|
||||
void **context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ocrdma_del_gid(struct ib_device *device,
|
||||
u8 port_num,
|
||||
unsigned int index,
|
||||
void **context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -125,6 +147,24 @@ int ocrdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct net_device *ocrdma_get_netdev(struct ib_device *ibdev, u8 port_num)
|
||||
{
|
||||
struct ocrdma_dev *dev;
|
||||
struct net_device *ndev = NULL;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
dev = get_ocrdma_dev(ibdev);
|
||||
if (dev)
|
||||
ndev = dev->nic_info.netdev;
|
||||
if (ndev)
|
||||
dev_hold(ndev);
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return ndev;
|
||||
}
|
||||
|
||||
static inline void get_link_speed_and_width(struct ocrdma_dev *dev,
|
||||
u8 *ib_speed, u8 *ib_width)
|
||||
{
|
||||
|
@ -194,7 +234,8 @@ int ocrdma_query_port(struct ib_device *ibdev,
|
|||
props->port_cap_flags =
|
||||
IB_PORT_CM_SUP |
|
||||
IB_PORT_REINIT_SUP |
|
||||
IB_PORT_DEVICE_MGMT_SUP | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_IP_BASED_GIDS;
|
||||
IB_PORT_DEVICE_MGMT_SUP | IB_PORT_VENDOR_CLASS_SUP |
|
||||
IB_PORT_IP_BASED_GIDS;
|
||||
props->gid_tbl_len = OCRDMA_MAX_SGID;
|
||||
props->pkey_tbl_len = 1;
|
||||
props->bad_pkey_cntr = 0;
|
||||
|
|
|
@ -63,6 +63,17 @@ ocrdma_query_protocol(struct ib_device *device, u8 port_num);
|
|||
void ocrdma_get_guid(struct ocrdma_dev *, u8 *guid);
|
||||
int ocrdma_query_gid(struct ib_device *, u8 port,
|
||||
int index, union ib_gid *gid);
|
||||
struct net_device *ocrdma_get_netdev(struct ib_device *device, u8 port_num);
|
||||
int ocrdma_add_gid(struct ib_device *device,
|
||||
u8 port_num,
|
||||
unsigned int index,
|
||||
const union ib_gid *gid,
|
||||
const struct ib_gid_attr *attr,
|
||||
void **context);
|
||||
int ocrdma_del_gid(struct ib_device *device,
|
||||
u8 port_num,
|
||||
unsigned int index,
|
||||
void **context);
|
||||
int ocrdma_query_pkey(struct ib_device *, u8 port, u16 index, u16 *pkey);
|
||||
|
||||
struct ib_ucontext *ocrdma_alloc_ucontext(struct ib_device *,
|
||||
|
|
Loading…
Reference in New Issue