Commit d80d88b0 authored by Ajit Khaparde's avatar Ajit Khaparde

bnxt_en: Add auxiliary driver support

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.
Signed-off-by: default avatarAjit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: default avatarAndy Gospodarek <andrew.gospodarek@broadcom.com>
Reviewed-by: default avatarSelvin Xavier <selvin.xavier@broadcom.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
parent 9f266cca
...@@ -213,6 +213,7 @@ config BNXT ...@@ -213,6 +213,7 @@ config BNXT
select NET_DEVLINK select NET_DEVLINK
select PAGE_POOL select PAGE_POOL
select DIMLIB select DIMLIB
select AUXILIARY_BUS
help help
This driver supports Broadcom NetXtreme-C/E 10/25/40/50 gigabit This driver supports Broadcom NetXtreme-C/E 10/25/40/50 gigabit
Ethernet cards. To compile this driver as a module, choose M here: Ethernet cards. To compile this driver as a module, choose M here:
......
...@@ -13181,6 +13181,8 @@ static void bnxt_remove_one(struct pci_dev *pdev) ...@@ -13181,6 +13181,8 @@ static void bnxt_remove_one(struct pci_dev *pdev)
if (BNXT_PF(bp)) if (BNXT_PF(bp))
bnxt_sriov_disable(bp); bnxt_sriov_disable(bp);
bnxt_rdma_aux_device_uninit(bp);
bnxt_ptp_clear(bp); bnxt_ptp_clear(bp);
pci_disable_pcie_error_reporting(pdev); pci_disable_pcie_error_reporting(pdev);
unregister_netdev(dev); unregister_netdev(dev);
...@@ -13776,11 +13778,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -13776,11 +13778,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
bnxt_dl_fw_reporters_create(bp); bnxt_dl_fw_reporters_create(bp);
bnxt_rdma_aux_device_init(bp);
bnxt_print_device_info(bp); bnxt_print_device_info(bp);
pci_save_state(pdev); pci_save_state(pdev);
return 0;
return 0;
init_err_cleanup: init_err_cleanup:
bnxt_dl_unregister(bp); bnxt_dl_unregister(bp);
init_err_dl: init_err_dl:
...@@ -13824,7 +13828,6 @@ static void bnxt_shutdown(struct pci_dev *pdev) ...@@ -13824,7 +13828,6 @@ static void bnxt_shutdown(struct pci_dev *pdev)
if (netif_running(dev)) if (netif_running(dev))
dev_close(dev); dev_close(dev);
bnxt_ulp_shutdown(bp);
bnxt_clear_int_mode(bp); bnxt_clear_int_mode(bp);
pci_disable_device(pdev); pci_disable_device(pdev);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/rhashtable.h> #include <linux/rhashtable.h>
#include <linux/crash_dump.h> #include <linux/crash_dump.h>
#include <linux/auxiliary_bus.h>
#include <net/devlink.h> #include <net/devlink.h>
#include <net/dst_metadata.h> #include <net/dst_metadata.h>
#include <net/xdp.h> #include <net/xdp.h>
...@@ -1631,6 +1632,12 @@ struct bnxt_fw_health { ...@@ -1631,6 +1632,12 @@ struct bnxt_fw_health {
#define BNXT_FW_IF_RETRY 10 #define BNXT_FW_IF_RETRY 10
#define BNXT_FW_SLOT_RESET_RETRY 4 #define BNXT_FW_SLOT_RESET_RETRY 4
struct bnxt_aux_priv {
struct auxiliary_device aux_dev;
struct bnxt_en_dev *edev;
int id;
};
enum board_idx { enum board_idx {
BCM57301, BCM57301,
BCM57302, BCM57302,
...@@ -1852,6 +1859,7 @@ struct bnxt { ...@@ -1852,6 +1859,7 @@ struct bnxt {
#define BNXT_CHIP_P4_PLUS(bp) \ #define BNXT_CHIP_P4_PLUS(bp) \
(BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp)) (BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp))
struct bnxt_aux_priv *aux_priv;
struct bnxt_en_dev *edev; struct bnxt_en_dev *edev;
struct bnxt_napi **bnapi; struct bnxt_napi **bnapi;
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "bnxt_hwrm.h" #include "bnxt_hwrm.h"
#include "bnxt_ulp.h" #include "bnxt_ulp.h"
static DEFINE_IDA(bnxt_aux_dev_ids);
static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id, static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id,
struct bnxt_ulp_ops *ulp_ops, void *handle) struct bnxt_ulp_ops *ulp_ops, void *handle)
{ {
...@@ -32,7 +34,6 @@ static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id, ...@@ -32,7 +34,6 @@ static int bnxt_register_dev(struct bnxt_en_dev *edev, unsigned int ulp_id,
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
struct bnxt_ulp *ulp; struct bnxt_ulp *ulp;
ASSERT_RTNL();
if (ulp_id >= BNXT_MAX_ULP) if (ulp_id >= BNXT_MAX_ULP)
return -EINVAL; return -EINVAL;
...@@ -69,10 +70,11 @@ static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id) ...@@ -69,10 +70,11 @@ static int bnxt_unregister_dev(struct bnxt_en_dev *edev, unsigned int ulp_id)
struct bnxt_ulp *ulp; struct bnxt_ulp *ulp;
int i = 0; int i = 0;
ASSERT_RTNL();
if (ulp_id >= BNXT_MAX_ULP) if (ulp_id >= BNXT_MAX_ULP)
return -EINVAL; return -EINVAL;
edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
ulp = &edev->ulp_tbl[ulp_id]; ulp = &edev->ulp_tbl[ulp_id];
if (!rcu_access_pointer(ulp->ulp_ops)) { if (!rcu_access_pointer(ulp->ulp_ops)) {
netdev_err(bp->dev, "ulp id %d not registered\n", ulp_id); netdev_err(bp->dev, "ulp id %d not registered\n", ulp_id);
...@@ -126,7 +128,6 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id, ...@@ -126,7 +128,6 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
int total_vecs; int total_vecs;
int rc = 0; int rc = 0;
ASSERT_RTNL();
if (ulp_id != BNXT_ROCE_ULP) if (ulp_id != BNXT_ROCE_ULP)
return -EINVAL; return -EINVAL;
...@@ -153,6 +154,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id, ...@@ -153,6 +154,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
edev->ulp_tbl[ulp_id].msix_requested = avail_msix; edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
hw_resc = &bp->hw_resc; hw_resc = &bp->hw_resc;
total_vecs = idx + avail_msix; total_vecs = idx + avail_msix;
rtnl_lock();
if (bp->total_irqs < total_vecs || if (bp->total_irqs < total_vecs ||
(BNXT_NEW_RM(bp) && hw_resc->resv_irqs < total_vecs)) { (BNXT_NEW_RM(bp) && hw_resc->resv_irqs < total_vecs)) {
if (netif_running(dev)) { if (netif_running(dev)) {
...@@ -162,6 +164,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id, ...@@ -162,6 +164,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id,
rc = bnxt_reserve_rings(bp, true); rc = bnxt_reserve_rings(bp, true);
} }
} }
rtnl_unlock();
if (rc) { if (rc) {
edev->ulp_tbl[ulp_id].msix_requested = 0; edev->ulp_tbl[ulp_id].msix_requested = 0;
return -EAGAIN; return -EAGAIN;
...@@ -184,7 +187,6 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id) ...@@ -184,7 +187,6 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id)
struct net_device *dev = edev->net; struct net_device *dev = edev->net;
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
ASSERT_RTNL();
if (ulp_id != BNXT_ROCE_ULP) if (ulp_id != BNXT_ROCE_ULP)
return -EINVAL; return -EINVAL;
...@@ -193,10 +195,13 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id) ...@@ -193,10 +195,13 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, unsigned int ulp_id)
edev->ulp_tbl[ulp_id].msix_requested = 0; edev->ulp_tbl[ulp_id].msix_requested = 0;
edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED; edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED;
rtnl_lock();
if (netif_running(dev) && !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) { if (netif_running(dev) && !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
bnxt_close_nic(bp, true, false); bnxt_close_nic(bp, true, false);
bnxt_open_nic(bp, true, false); bnxt_open_nic(bp, true, false);
} }
rtnl_unlock();
return 0; return 0;
} }
...@@ -347,25 +352,6 @@ void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs) ...@@ -347,25 +352,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) void bnxt_ulp_irq_stop(struct bnxt *bp)
{ {
struct bnxt_en_dev *edev = bp->edev; struct bnxt_en_dev *edev = bp->edev;
...@@ -475,6 +461,108 @@ static const struct bnxt_en_ops bnxt_en_ops_tbl = { ...@@ -475,6 +461,108 @@ static const struct bnxt_en_ops bnxt_en_ops_tbl = {
.bnxt_register_fw_async_events = bnxt_register_async_events, .bnxt_register_fw_async_events = bnxt_register_async_events,
}; };
void bnxt_rdma_aux_device_uninit(struct bnxt *bp)
{
struct bnxt_aux_priv *aux_priv;
struct auxiliary_device *adev;
/* Skip if no auxiliary device init was done. */
if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
return;
aux_priv = bp->aux_priv;
adev = &aux_priv->aux_dev;
auxiliary_device_delete(adev);
auxiliary_device_uninit(adev);
}
static void bnxt_aux_dev_release(struct device *dev)
{
struct bnxt_aux_priv *aux_priv =
container_of(dev, struct bnxt_aux_priv, aux_dev.dev);
ida_free(&bnxt_aux_dev_ids, aux_priv->id);
kfree(aux_priv->edev);
kfree(aux_priv);
}
static 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;
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;
}
void bnxt_rdma_aux_device_init(struct bnxt *bp)
{
struct auxiliary_device *aux_dev;
struct bnxt_aux_priv *aux_priv;
struct bnxt_en_dev *edev;
int rc;
if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
return;
bp->aux_priv = kzalloc(sizeof(*bp->aux_priv), GFP_KERNEL);
if (!bp->aux_priv)
goto exit;
bp->aux_priv->id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL);
if (bp->aux_priv->id < 0) {
netdev_warn(bp->dev,
"ida alloc failed for ROCE auxiliary device\n");
kfree(bp->aux_priv);
goto exit;
}
aux_priv = bp->aux_priv;
aux_dev = &aux_priv->aux_dev;
aux_dev->id = aux_priv->id;
aux_dev->name = "rdma";
aux_dev->dev.parent = &bp->pdev->dev;
aux_dev->dev.release = bnxt_aux_dev_release;
rc = auxiliary_device_init(aux_dev);
if (rc) {
ida_free(&bnxt_aux_dev_ids, bp->aux_priv->id);
kfree(bp->aux_priv);
goto exit;
}
/* From this point, all cleanup will happen via the .release callback &
* any error unwinding will need to include a call to
* auxiliary_device_uninit.
*/
edev = kzalloc(sizeof(*edev), GFP_KERNEL);
if (!edev)
goto aux_dev_uninit;
aux_priv->edev = edev;
bp->edev = edev;
bnxt_set_edev_info(edev, bp);
rc = auxiliary_device_add(aux_dev);
if (rc) {
netdev_warn(bp->dev,
"Failed to add auxiliary device for ROCE\n");
goto aux_dev_uninit;
}
return;
aux_dev_uninit:
auxiliary_device_uninit(aux_dev);
exit:
bp->flags &= ~BNXT_FLAG_ROCE_CAP;
}
struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev) struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev)
{ {
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
......
...@@ -102,10 +102,11 @@ int bnxt_get_ulp_stat_ctxs(struct bnxt *bp); ...@@ -102,10 +102,11 @@ int bnxt_get_ulp_stat_ctxs(struct bnxt *bp);
void bnxt_ulp_stop(struct bnxt *bp); void bnxt_ulp_stop(struct bnxt *bp);
void bnxt_ulp_start(struct bnxt *bp, int err); void bnxt_ulp_start(struct bnxt *bp, int err);
void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs); 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_stop(struct bnxt *bp);
void bnxt_ulp_irq_restart(struct bnxt *bp, int err); void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl); void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
void bnxt_rdma_aux_device_uninit(struct bnxt *bp);
void bnxt_rdma_aux_device_init(struct bnxt *bp);
struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev); struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev);
#endif #endif
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