lkml.org 
[lkml]   [2022]   [Jul]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/2] net/bnxt: Add auxiliary driver support
Date
Add auxiliary driver support.
An auxiliary device will be created if the hardware indicates
support for RDMA.
The bnxt_ulp_probe() function has been removed and a new
bnxt_rdma_aux_device_add() function has been added.
The bnxt_free_msix_vecs() and bnxt_req_msix_vecs() will now hold
the RTNL lock when they call the bnxt_close_nic()and bnxt_open_nic()
since the device close and open need to be protected under RTNL lock.
The operations between the bnxt_en and bnxt_re will be protected
using the en_ops_lock.
This will be used by the bnxt_re driver in a follow-on patch
to create ROCE interfaces.

BUG: DCSG01157556
Change-Id: I544c83c6a19925ee49a1da4d580c0970c679e746
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 72 ++++++++-
drivers/net/ethernet/broadcom/bnxt/bnxt.h | 8 +
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 137 ++++++++++++------
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h | 5 +-
4 files changed, 172 insertions(+), 50 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index ba0f1ffac507..98d5884a8418 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -79,6 +79,8 @@
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Broadcom BCM573xx network driver");

+static DEFINE_IDA(bnxt_aux_dev_ids);
+
#define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
#define BNXT_RX_DMA_OFFSET NET_SKB_PAD
#define BNXT_RX_COPY_THRESH 256
@@ -211,6 +213,68 @@ static const struct pci_device_id bnxt_pci_tbl[] = {

MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);

+static void bnxt_aux_dev_free(struct bnxt *bp)
+{
+ kfree(bp->aux_dev);
+ bp->aux_dev = NULL;
+}
+
+static struct bnxt_aux_dev *bnxt_aux_dev_init(struct bnxt *bp)
+{
+ struct bnxt_aux_dev *bnxt_adev;
+
+ bnxt_adev = kzalloc(sizeof(*bnxt_adev), GFP_KERNEL);
+ if (!bnxt_adev)
+ return ERR_PTR(-ENOMEM);
+
+ return bnxt_adev;
+}
+
+static void bnxt_aux_device_uninit(struct bnxt_aux_dev *bnxt_adev)
+{
+ struct auxiliary_device *adev;
+
+ if (IS_ERR_OR_NULL(bnxt_adev))
+ return;
+
+ adev = &bnxt_adev->aux_dev;
+ auxiliary_device_delete(adev);
+ auxiliary_device_uninit(adev);
+ if (bnxt_adev->id >= 0)
+ ida_free(&bnxt_aux_dev_ids, bnxt_adev->id);
+}
+
+static void bnxt_rdma_aux_device_init(struct bnxt *bp)
+{
+ struct net_device *dev = bp->dev;
+ int rc;
+
+ if (bp->flags & BNXT_FLAG_ROCE_CAP) {
+ bp->aux_dev = bnxt_aux_dev_init(bp);
+ if (IS_ERR_OR_NULL(bp->aux_dev)) {
+ netdev_warn(dev, "Failed to init auxiliary device for ROCE\n");
+ goto skip_aux_init;
+ }
+
+ bp->aux_dev->id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL);
+ if (bp->aux_dev->id < 0) {
+ netdev_warn(dev, "ida alloc failed for ROCE auxiliary device\n");
+ bnxt_aux_dev_free(bp);
+ goto skip_aux_init;
+ }
+
+ /* If aux bus init fails, continue with netdev init. */
+ rc = bnxt_rdma_aux_device_add(bp);
+ if (rc) {
+ netdev_warn(dev, "Failed to add auxiliary device for ROCE\n");
+ ida_free(&bnxt_aux_dev_ids, bp->aux_dev->id);
+ bnxt_aux_dev_free(bp);
+ }
+ }
+skip_aux_init:
+ return;
+}
+
static const u16 bnxt_vf_req_snif[] = {
HWRM_FUNC_CFG,
HWRM_FUNC_VF_CFG,
@@ -13122,6 +13186,9 @@ static void bnxt_remove_one(struct pci_dev *pdev)
struct net_device *dev = pci_get_drvdata(pdev);
struct bnxt *bp = netdev_priv(dev);

+ bnxt_aux_device_uninit(bp->aux_dev);
+ bnxt_aux_dev_free(bp);
+
if (BNXT_PF(bp))
bnxt_sriov_disable(bp);

@@ -13719,11 +13786,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
devlink_port_type_eth_set(&bp->dl_port, bp->dev);
bnxt_dl_fw_reporters_create(bp);

+ bnxt_rdma_aux_device_init(bp);
+
bnxt_print_device_info(bp);

pci_save_state(pdev);
- return 0;

+ return 0;
init_err_cleanup:
bnxt_dl_unregister(bp);
init_err_dl:
@@ -13767,7 +13836,6 @@ static void bnxt_shutdown(struct pci_dev *pdev)
if (netif_running(dev))
dev_close(dev);

- bnxt_ulp_shutdown(bp);
bnxt_clear_int_mode(bp);
pci_disable_device(pdev);

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 075c6206325c..064856cf4a55 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -24,6 +24,7 @@
#include <linux/interrupt.h>
#include <linux/rhashtable.h>
#include <linux/crash_dump.h>
+#include <linux/auxiliary_bus.h>
#include <net/devlink.h>
#include <net/dst_metadata.h>
#include <net/xdp.h>
@@ -1622,6 +1623,12 @@ struct bnxt_fw_health {
#define BNXT_FW_RETRY 5
#define BNXT_FW_IF_RETRY 10

+struct bnxt_aux_dev {
+ struct auxiliary_device aux_dev;
+ struct bnxt_en_dev *edev;
+ int id;
+};
+
enum board_idx {
BCM57301,
BCM57302,
@@ -2146,6 +2153,7 @@ struct bnxt {
struct dentry *debugfs_pdev;
struct device *hwmon_dev;
enum board_idx board_idx;
+ struct bnxt_aux_dev *aux_dev;
};

#define BNXT_NUM_RX_RING_STATS 8
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
index 2e54bf4fc7a7..a21f40e1e57c 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
@@ -31,26 +31,30 @@ static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id,
struct net_device *dev = edev->net;
struct bnxt *bp = netdev_priv(dev);
struct bnxt_ulp *ulp;
+ int rc = 0;

- ASSERT_RTNL();
if (ulp_id >= BNXT_MAX_ULP)
return -EINVAL;

+ mutex_lock(&edev->en_ops_lock);
ulp = &edev->ulp_tbl[ulp_id];
if (rcu_access_pointer(ulp->ulp_ops)) {
netdev_err(bp->dev, "ulp id %d already registered\n", ulp_id);
- return -EBUSY;
+ rc = -EBUSY;
+ goto exit;
}
if (ulp_id == BNXT_ROCE_ULP) {
unsigned int max_stat_ctxs;

max_stat_ctxs = bnxt_get_max_func_stat_ctxs(bp);
if (max_stat_ctxs <= BNXT_MIN_ROCE_STAT_CTXS ||
- bp->cp_nr_rings == max_stat_ctxs)
- return -ENOMEM;
+ bp->cp_nr_rings == max_stat_ctxs) {
+ rc = -ENOMEM;
+ goto exit;
+ }
}

- atomic_set(&ulp->ref_count, 0);
+ atomic_set(&ulp->ref_count, 1);
ulp->handle = handle;
rcu_assign_pointer(ulp->ulp_ops, ulp_ops);

@@ -59,7 +63,9 @@ static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id,
bnxt_hwrm_vnic_cfg(bp, 0);
}

- return 0;
+exit:
+ mutex_unlock(&edev->en_ops_lock);
+ return rc;
}

static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id)
@@ -69,10 +75,11 @@ static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id)
struct bnxt_ulp *ulp;
int i = 0;

- ASSERT_RTNL();
if (ulp_id >= BNXT_MAX_ULP)
return -EINVAL;

+ edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
+
ulp = &edev->ulp_tbl[ulp_id];
if (!rcu_access_pointer(ulp->ulp_ops)) {
netdev_err(bp->dev, "ulp id %d not registered\n", ulp_id);
@@ -81,6 +88,7 @@ static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id)
if (ulp_id == BNXT_ROCE_ULP && ulp->msix_requested)
edev->en_ops->bnxt_free_msix(edev, ulp_id);

+ mutex_lock(&edev->en_ops_lock);
if (ulp->max_async_event_id)
bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, true);

@@ -92,6 +100,7 @@ static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id)
msleep(100);
i++;
}
+ mutex_unlock(&edev->en_ops_lock);
return 0;
}

@@ -126,7 +135,6 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
int total_vecs;
int rc = 0;

- ASSERT_RTNL();
if (ulp_id != BNXT_ROCE_ULP)
return -EINVAL;

@@ -149,6 +157,8 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
max_idx = min_t(int, bp->total_irqs, max_cp_rings);
idx = max_idx - avail_msix;
}
+
+ mutex_lock(&edev->en_ops_lock);
edev->ulp_tbl[ulp_id].msix_base = idx;
edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
hw_resc = &bp->hw_resc;
@@ -156,14 +166,17 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
if (bp->total_irqs < total_vecs ||
(BNXT_NEW_RM(bp) && hw_resc->resv_irqs < total_vecs)) {
if (netif_running(dev)) {
+ rtnl_lock();
bnxt_close_nic(bp, true, false);
rc = bnxt_open_nic(bp, true, false);
+ rtnl_unlock();
} else {
rc = bnxt_reserve_rings(bp, true);
}
}
if (rc) {
edev->ulp_tbl[ulp_id].msix_requested = 0;
+ mutex_unlock(&edev->en_ops_lock);
return -EAGAIN;
}

@@ -176,6 +189,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
}
bnxt_fill_msix_vecs(bp, ent);
edev->flags |= BNXT_EN_FLAG_MSIX_REQUESTED;
+ mutex_unlock(&edev->en_ops_lock);
return avail_msix;
}

@@ -184,19 +198,23 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id)
struct net_device *dev = edev->net;
struct bnxt *bp = netdev_priv(dev);

- ASSERT_RTNL();
if (ulp_id != BNXT_ROCE_ULP)
return -EINVAL;

if (!(edev->flags & BNXT_EN_FLAG_MSIX_REQUESTED))
return 0;

+ mutex_lock(&edev->en_ops_lock);
edev->ulp_tbl[ulp_id].msix_requested = 0;
edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED;
if (netif_running(dev) && !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
+ rtnl_lock();
bnxt_close_nic(bp, true, false);
bnxt_open_nic(bp, true, false);
+ rtnl_unlock();
}
+ mutex_unlock(&edev->en_ops_lock);
+
return 0;
}

@@ -254,6 +272,7 @@ static int bnxt_send_msg(struct bnxt_en_dev *edev, unsigned int ulp_id,
if (rc)
return rc;

+ mutex_lock(&edev->en_ops_lock);
hwrm_req_timeout(bp, req, fw_msg->timeout);
resp = hwrm_req_hold(bp, req);
rc = hwrm_req_send(bp, req);
@@ -265,6 +284,7 @@ static int bnxt_send_msg(struct bnxt_en_dev *edev, unsigned int ulp_id,
memcpy(fw_msg->resp, resp, resp_len);
}
hwrm_req_drop(bp, req);
+ mutex_unlock(&edev->en_ops_lock);
return rc;
}

@@ -347,25 +367,6 @@ void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs)
}
}

-void bnxt_ulp_shutdown(struct bnxt *bp)
-{
- struct bnxt_en_dev *edev = bp->edev;
- struct bnxt_ulp_ops *ops;
- int i;
-
- if (!edev)
- return;
-
- for (i = 0; i < BNXT_MAX_ULP; i++) {
- struct bnxt_ulp *ulp = &edev->ulp_tbl[i];
-
- ops = rtnl_dereference(ulp->ulp_ops);
- if (!ops || !ops->ulp_shutdown)
- continue;
- ops->ulp_shutdown(ulp->handle);
- }
-}
-
void bnxt_ulp_irq_stop(struct bnxt *bp)
{
struct bnxt_en_dev *edev = bp->edev;
@@ -457,12 +458,14 @@ static int bnxt_register_async_events(struct bnxt_en_dev *edev, unsigned int ulp
if (ulp_id >= BNXT_MAX_ULP)
return -EINVAL;

+ mutex_lock(&edev->en_ops_lock);
ulp = &edev->ulp_tbl[ulp_id];
ulp->async_events_bmap = events_bmap;
/* Make sure bnxt_ulp_async_events() sees this order */
smp_wmb();
ulp->max_async_event_id = max_id;
bnxt_hwrm_func_drv_rgtr(bp, events_bmap, max_id + 1, true);
+ mutex_unlock(&edev->en_ops_lock);
return 0;
}

@@ -475,28 +478,70 @@ static const struct bnxt_en_ops bnxt_en_ops_tbl = {
.bnxt_register_fw_async_events = bnxt_register_async_events,
};

-struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev)
+void bnxt_aux_dev_release(struct device *dev)
{
- struct bnxt *bp = netdev_priv(dev);
- struct bnxt_en_dev *edev;
+ struct bnxt_aux_dev *bnxt_adev =
+ container_of(dev, struct bnxt_aux_dev, aux_dev.dev);
+ struct bnxt *bp = netdev_priv(bnxt_adev->edev->net);
+
+ bnxt_adev->edev->en_ops = NULL;
+ kfree(bnxt_adev->edev);
+ bnxt_adev->edev = NULL;
+ bp->edev = NULL;
+}
+
+static inline void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
+{
+ edev->en_ops = &bnxt_en_ops_tbl;
+ edev->net = bp->dev;
+ edev->pdev = bp->pdev;
+ edev->l2_db_size = bp->db_size;
+ edev->l2_db_size_nc = bp->db_size;
+ mutex_init(&edev->en_ops_lock);

- edev = bp->edev;
- if (!edev) {
- edev = kzalloc(sizeof(*edev), GFP_KERNEL);
- if (!edev)
- return ERR_PTR(-ENOMEM);
- edev->en_ops = &bnxt_en_ops_tbl;
- edev->net = dev;
- edev->pdev = bp->pdev;
- edev->l2_db_size = bp->db_size;
- edev->l2_db_size_nc = bp->db_size;
- bp->edev = edev;
- }
- edev->flags &= ~BNXT_EN_FLAG_ROCE_CAP;
if (bp->flags & BNXT_FLAG_ROCEV1_CAP)
edev->flags |= BNXT_EN_FLAG_ROCEV1_CAP;
if (bp->flags & BNXT_FLAG_ROCEV2_CAP)
edev->flags |= BNXT_EN_FLAG_ROCEV2_CAP;
- return bp->edev;
}
-EXPORT_SYMBOL(bnxt_ulp_probe);
+
+int bnxt_rdma_aux_device_add(struct bnxt *bp)
+{
+ struct bnxt_aux_dev *bnxt_adev = bp->aux_dev;
+ struct bnxt_en_dev *edev = bnxt_adev->edev;
+ struct auxiliary_device *aux_dev;
+ int ret;
+
+ aux_dev = &bnxt_adev->aux_dev;
+ aux_dev->id = bnxt_adev->id;
+ aux_dev->name = "rdma";
+ aux_dev->dev.parent = &bp->pdev->dev;
+ aux_dev->dev.release = bnxt_aux_dev_release;
+
+ if (!edev) {
+ edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+ if (!edev)
+ return -ENOMEM;
+ }
+
+ bnxt_set_edev_info(edev, bp);
+ bnxt_adev->edev = edev;
+ bp->edev = edev;
+
+ ret = auxiliary_device_init(aux_dev);
+ if (ret) {
+ kfree(edev);
+ kfree(bnxt_adev);
+ return ret;
+ }
+
+ ret = auxiliary_device_add(aux_dev);
+ if (ret) {
+ kfree(edev);
+ kfree(bnxt_adev);
+ auxiliary_device_uninit(aux_dev);
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
index 42b50abc3e91..db0d477045fc 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
@@ -65,6 +65,7 @@ struct bnxt_en_dev {
#define BNXT_EN_FLAG_MSIX_REQUESTED 0x4
#define BNXT_EN_FLAG_ULP_STOPPED 0x8
const struct bnxt_en_ops *en_ops;
+ struct mutex en_ops_lock; /* serialize ops */
struct bnxt_ulp ulp_tbl[BNXT_MAX_ULP];
int l2_db_size; /* Doorbell BAR size in
* bytes mapped by L2
@@ -102,10 +103,10 @@ int bnxt_get_ulp_stat_ctxs(struct bnxt *bp);
void bnxt_ulp_stop(struct bnxt *bp);
void bnxt_ulp_start(struct bnxt *bp, int err);
void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
-void bnxt_ulp_shutdown(struct bnxt *bp);
void bnxt_ulp_irq_stop(struct bnxt *bp);
void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
-struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev);
+void bnxt_aux_dev_release(struct device *dev);
+int bnxt_rdma_aux_device_add(struct bnxt *bp);

#endif
--
2.32.1 (Apple Git-133)
[unhandled content-type:application/pkcs7-signature]
\
 
 \ /
  Last update: 2022-07-25 01:16    [W:0.252 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site