Commit 3cae5804 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/bnxt_re: Use ib_device_try_get()

There are a couple places in this driver running from a work queue that
need the ib_device to be registered. Instead of using a broken internal
bit rely on the new core code to guarantee device registration.

Link: https://lore.kernel.org/r/1584117207-2664-2-git-send-email-selvin.xavier@broadcom.comSigned-off-by: default avatarSelvin Xavier <selvin.xavier@broadcom.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 67b3c8dc
...@@ -132,7 +132,6 @@ struct bnxt_re_dev { ...@@ -132,7 +132,6 @@ struct bnxt_re_dev {
struct list_head list; struct list_head list;
unsigned long flags; unsigned long flags;
#define BNXT_RE_FLAG_NETDEV_REGISTERED 0 #define BNXT_RE_FLAG_NETDEV_REGISTERED 0
#define BNXT_RE_FLAG_IBDEV_REGISTERED 1
#define BNXT_RE_FLAG_GOT_MSIX 2 #define BNXT_RE_FLAG_GOT_MSIX 2
#define BNXT_RE_FLAG_HAVE_L2_REF 3 #define BNXT_RE_FLAG_HAVE_L2_REF 3
#define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4 #define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4
......
...@@ -1171,12 +1171,13 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev) ...@@ -1171,12 +1171,13 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev)
u16 gid_idx, index; u16 gid_idx, index;
int rc = 0; int rc = 0;
if (!test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags)) if (!ib_device_try_get(&rdev->ibdev))
return 0; return 0;
if (!sgid_tbl) { if (!sgid_tbl) {
ibdev_err(&rdev->ibdev, "QPLIB: SGID table not allocated"); ibdev_err(&rdev->ibdev, "QPLIB: SGID table not allocated");
return -EINVAL; rc = -EINVAL;
goto out;
} }
for (index = 0; index < sgid_tbl->active; index++) { for (index = 0; index < sgid_tbl->active; index++) {
...@@ -1196,7 +1197,8 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev) ...@@ -1196,7 +1197,8 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev)
rc = bnxt_qplib_update_sgid(sgid_tbl, &gid, gid_idx, rc = bnxt_qplib_update_sgid(sgid_tbl, &gid, gid_idx,
rdev->qplib_res.netdev->dev_addr); rdev->qplib_res.netdev->dev_addr);
} }
out:
ib_device_put(&rdev->ibdev);
return rc; return rc;
} }
...@@ -1319,7 +1321,6 @@ int bnxt_re_ib_init(struct bnxt_re_dev *rdev) ...@@ -1319,7 +1321,6 @@ int bnxt_re_ib_init(struct bnxt_re_dev *rdev)
pr_err("Failed to register with IB: %#x\n", rc); pr_err("Failed to register with IB: %#x\n", rc);
return rc; return rc;
} }
set_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags);
dev_info(rdev_to_dev(rdev), "Device registered successfully"); dev_info(rdev_to_dev(rdev), "Device registered successfully");
ib_get_eth_speed(&rdev->ibdev, 1, &rdev->active_speed, ib_get_eth_speed(&rdev->ibdev, 1, &rdev->active_speed,
&rdev->active_width); &rdev->active_width);
...@@ -1612,7 +1613,6 @@ static void bnxt_re_dealloc_driver(struct ib_device *ib_dev) ...@@ -1612,7 +1613,6 @@ static void bnxt_re_dealloc_driver(struct ib_device *ib_dev)
struct bnxt_re_dev *rdev = struct bnxt_re_dev *rdev =
container_of(ib_dev, struct bnxt_re_dev, ibdev); container_of(ib_dev, struct bnxt_re_dev, ibdev);
clear_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags);
dev_info(rdev_to_dev(rdev), "Unregistering Device"); dev_info(rdev_to_dev(rdev), "Unregistering Device");
rtnl_lock(); rtnl_lock();
...@@ -1630,12 +1630,7 @@ static void bnxt_re_task(struct work_struct *work) ...@@ -1630,12 +1630,7 @@ static void bnxt_re_task(struct work_struct *work)
re_work = container_of(work, struct bnxt_re_work, work); re_work = container_of(work, struct bnxt_re_work, work);
rdev = re_work->rdev; rdev = re_work->rdev;
if (re_work->event != NETDEV_REGISTER && if (re_work->event == NETDEV_REGISTER) {
!test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags))
goto done;
switch (re_work->event) {
case NETDEV_REGISTER:
rc = bnxt_re_ib_init(rdev); rc = bnxt_re_ib_init(rdev);
if (rc) { if (rc) {
ibdev_err(&rdev->ibdev, ibdev_err(&rdev->ibdev,
...@@ -1645,7 +1640,13 @@ static void bnxt_re_task(struct work_struct *work) ...@@ -1645,7 +1640,13 @@ static void bnxt_re_task(struct work_struct *work)
rtnl_unlock(); rtnl_unlock();
goto exit; goto exit;
} }
break; goto exit;
}
if (!ib_device_try_get(&rdev->ibdev))
goto exit;
switch (re_work->event) {
case NETDEV_UP: case NETDEV_UP:
bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1,
IB_EVENT_PORT_ACTIVE); IB_EVENT_PORT_ACTIVE);
...@@ -1665,7 +1666,7 @@ static void bnxt_re_task(struct work_struct *work) ...@@ -1665,7 +1666,7 @@ static void bnxt_re_task(struct work_struct *work)
default: default:
break; break;
} }
done: ib_device_put(&rdev->ibdev);
smp_mb__before_atomic(); smp_mb__before_atomic();
atomic_dec(&rdev->sched_count); atomic_dec(&rdev->sched_count);
exit: exit:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment