Skip to content

Commit 2c7c85c

Browse files
pavanchebbijgunthorpe
authored andcommitted
fwctl/bnxt_en: Refactor aux bus functions to be more generic
Up until now there was only one auxiliary device that bnxt created and that was for RoCE driver. bnxt fwctl is also going to use an aux bus device that bnxt should create. This requires some nomenclature changes and refactoring of the existing bnxt aux dev functions. Convert 'aux_priv' and 'edev' members of struct bnxt into arrays where each element contains supported auxbus device's data. Move struct bnxt_aux_priv from bnxt.h to ulp.h because that is where it belongs. Make aux bus init/uninit/add/del functions more generic which will loop through all the aux device types. Make bnxt_ulp_start/stop functions (the only other common functions applicable to any aux device) loop through the aux devices to update their config and states. Make callers of bnxt_ulp_start() call it only when there are no errors. Also, as an improvement in code, bnxt_register_dev() can skip unnecessary dereferencing of edev from bp, instead use the edev pointer from the function parameter. Future patches will reuse these functions to add an aux bus device for fwctl. Link: https://patch.msgid.link/r/20260314151605.932749-3-pavan.chebbi@broadcom.com Reviewed-by: Andy Gospodarek <gospo@broadcom.com> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 7be18a1 commit 2c7c85c

6 files changed

Lines changed: 273 additions & 167 deletions

File tree

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6896,7 +6896,8 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
68966896
#endif
68976897
if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
68986898
req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
6899-
if (vnic->vnic_id == BNXT_VNIC_DEFAULT && bnxt_ulp_registered(bp->edev))
6899+
if (vnic->vnic_id == BNXT_VNIC_DEFAULT &&
6900+
bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA]))
69006901
req->flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
69016902

69026903
return hwrm_req_send(bp, req);
@@ -8031,6 +8032,7 @@ static int bnxt_get_avail_msix(struct bnxt *bp, int num);
80318032

80328033
static int __bnxt_reserve_rings(struct bnxt *bp)
80338034
{
8035+
struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
80348036
struct bnxt_hw_rings hwr = {0};
80358037
int rx_rings, old_rx_rings, rc;
80368038
int cp = bp->cp_nr_rings;
@@ -8041,7 +8043,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
80418043
if (!bnxt_need_reserve_rings(bp))
80428044
return 0;
80438045

8044-
if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
8046+
if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
80458047
ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
80468048
if (!ulp_msix)
80478049
bnxt_set_ulp_stat_ctxs(bp, 0);
@@ -8092,8 +8094,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
80928094
}
80938095
rx_rings = min_t(int, rx_rings, hwr.grp);
80948096
hwr.cp = min_t(int, hwr.cp, bp->cp_nr_rings);
8095-
if (bnxt_ulp_registered(bp->edev) &&
8096-
hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
8097+
if (bnxt_ulp_registered(edev) && hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
80978098
hwr.stat -= bnxt_get_ulp_stat_ctxs(bp);
80988099
hwr.cp = min_t(int, hwr.cp, hwr.stat);
80998100
rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh);
@@ -8137,7 +8138,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
81378138
!netif_is_rxfh_configured(bp->dev))
81388139
bnxt_set_dflt_rss_indir_tbl(bp, NULL);
81398140

8140-
if (!bnxt_ulp_registered(bp->edev) && BNXT_NEW_RM(bp)) {
8141+
if (!bnxt_ulp_registered(edev) && BNXT_NEW_RM(bp)) {
81418142
int resv_msix, resv_ctx, ulp_ctxs;
81428143
struct bnxt_hw_resc *hw_resc;
81438144

@@ -11494,6 +11495,7 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
1149411495

1149511496
int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
1149611497
{
11498+
struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
1149711499
bool irq_cleared = false;
1149811500
bool irq_change = false;
1149911501
int tcs = bp->num_tc;
@@ -11503,7 +11505,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
1150311505
if (!bnxt_need_reserve_rings(bp))
1150411506
return 0;
1150511507

11506-
if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
11508+
if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
1150711509
int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
1150811510

1150911511
if (ulp_msix > bp->ulp_num_msix_want)
@@ -14593,7 +14595,7 @@ static void bnxt_fw_echo_reply(struct bnxt *bp)
1459314595
static void bnxt_ulp_restart(struct bnxt *bp)
1459414596
{
1459514597
bnxt_ulp_stop(bp);
14596-
bnxt_ulp_start(bp, 0);
14598+
bnxt_ulp_start(bp);
1459714599
}
1459814600

1459914601
static void bnxt_sp_task(struct work_struct *work)
@@ -14750,7 +14752,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
1475014752
hwr.cp_p5 = hwr.tx + rx;
1475114753
rc = bnxt_hwrm_check_rings(bp, &hwr);
1475214754
if (!rc && pci_msix_can_alloc_dyn(bp->pdev)) {
14753-
if (!bnxt_ulp_registered(bp->edev)) {
14755+
if (!bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
1475414756
hwr.cp += bnxt_get_ulp_msix_num(bp);
1475514757
hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp));
1475614758
}
@@ -15270,7 +15272,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)
1527015272
bnxt_dl_health_fw_status_update(bp, true);
1527115273
}
1527215274
netdev_unlock(bp->dev);
15273-
bnxt_ulp_start(bp, 0);
15275+
bnxt_ulp_start(bp);
1527415276
bnxt_reenable_sriov(bp);
1527515277
netdev_lock(bp->dev);
1527615278
bnxt_vf_reps_alloc(bp);
@@ -15292,7 +15294,8 @@ static void bnxt_fw_reset_task(struct work_struct *work)
1529215294
bnxt_fw_reset_abort(bp, rc);
1529315295
netdev_unlock(bp->dev);
1529415296
ulp_start:
15295-
bnxt_ulp_start(bp, rc);
15297+
if (!rc)
15298+
bnxt_ulp_start(bp);
1529615299
}
1529715300

1529815301
static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
@@ -16327,12 +16330,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)
1632716330
if (BNXT_PF(bp))
1632816331
__bnxt_sriov_disable(bp);
1632916332

16330-
bnxt_rdma_aux_device_del(bp);
16333+
bnxt_aux_devices_del(bp);
1633116334

1633216335
unregister_netdev(dev);
1633316336
bnxt_ptp_clear(bp);
1633416337

16335-
bnxt_rdma_aux_device_uninit(bp);
16338+
bnxt_aux_devices_uninit(bp);
16339+
bnxt_auxdev_id_free(bp, bp->auxdev_id);
1633616340

1633716341
bnxt_free_l2_filters(bp, true);
1633816342
bnxt_free_ntp_fltrs(bp, true);
@@ -16918,7 +16922,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1691816922
bnxt_set_tpa_flags(bp);
1691916923
bnxt_init_ring_params(bp);
1692016924
bnxt_set_ring_params(bp);
16921-
bnxt_rdma_aux_device_init(bp);
16925+
mutex_init(&bp->auxdev_lock);
16926+
if (!bnxt_auxdev_id_alloc(bp))
16927+
bnxt_aux_devices_init(bp);
1692216928
rc = bnxt_set_dflt_rings(bp, true);
1692316929
if (rc) {
1692416930
if (BNXT_VF(bp) && rc == -ENODEV) {
@@ -16983,15 +16989,16 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1698316989

1698416990
bnxt_dl_fw_reporters_create(bp);
1698516991

16986-
bnxt_rdma_aux_device_add(bp);
16992+
bnxt_aux_devices_add(bp);
1698716993

1698816994
bnxt_print_device_info(bp);
1698916995

1699016996
pci_save_state(pdev);
1699116997

1699216998
return 0;
1699316999
init_err_cleanup:
16994-
bnxt_rdma_aux_device_uninit(bp);
17000+
bnxt_aux_devices_uninit(bp);
17001+
bnxt_auxdev_id_free(bp, bp->auxdev_id);
1699517002
bnxt_dl_unregister(bp);
1699617003
init_err_dl:
1699717004
bnxt_shutdown_tc(bp);
@@ -17125,9 +17132,10 @@ static int bnxt_resume(struct device *device)
1712517132

1712617133
resume_exit:
1712717134
netdev_unlock(bp->dev);
17128-
bnxt_ulp_start(bp, rc);
17129-
if (!rc)
17135+
if (!rc) {
17136+
bnxt_ulp_start(bp);
1713017137
bnxt_reenable_sriov(bp);
17138+
}
1713117139
return rc;
1713217140
}
1713317141

@@ -17307,9 +17315,10 @@ static void bnxt_io_resume(struct pci_dev *pdev)
1730717315
netif_device_attach(netdev);
1730817316

1730917317
netdev_unlock(netdev);
17310-
bnxt_ulp_start(bp, err);
17311-
if (!err)
17318+
if (!err) {
17319+
bnxt_ulp_start(bp);
1731217320
bnxt_reenable_sriov(bp);
17321+
}
1731317322
}
1731417323

1731517324
static const struct pci_error_handlers bnxt_err_handler = {

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <linux/interrupt.h>
2525
#include <linux/rhashtable.h>
2626
#include <linux/crash_dump.h>
27-
#include <linux/auxiliary_bus.h>
2827
#include <net/devlink.h>
2928
#include <net/dst_metadata.h>
3029
#include <net/xdp.h>
3130
#include <linux/dim.h>
3231
#include <linux/io-64-nonatomic-lo-hi.h>
32+
#include <linux/bnxt/ulp.h>
3333
#ifdef CONFIG_TEE_BNXT_FW
3434
#include <linux/firmware/broadcom/tee_bnxt_fw.h>
3535
#endif
@@ -2085,12 +2085,6 @@ struct bnxt_fw_health {
20852085
#define BNXT_FW_IF_RETRY 10
20862086
#define BNXT_FW_SLOT_RESET_RETRY 4
20872087

2088-
struct bnxt_aux_priv {
2089-
struct auxiliary_device aux_dev;
2090-
struct bnxt_en_dev *edev;
2091-
int id;
2092-
};
2093-
20942088
enum board_idx {
20952089
BCM57301,
20962090
BCM57302,
@@ -2350,8 +2344,8 @@ struct bnxt {
23502344
#define BNXT_CHIP_P5_AND_MINUS(bp) \
23512345
(BNXT_CHIP_P3(bp) || BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp))
23522346

2353-
struct bnxt_aux_priv *aux_priv;
2354-
struct bnxt_en_dev *edev;
2347+
struct bnxt_aux_priv *aux_priv[__BNXT_AUXDEV_MAX];
2348+
struct bnxt_en_dev *edev[__BNXT_AUXDEV_MAX];
23552349

23562350
struct bnxt_napi **bnapi;
23572351

@@ -2763,6 +2757,13 @@ struct bnxt {
27632757
struct bnxt_ctx_pg_info *fw_crash_mem;
27642758
u32 fw_crash_len;
27652759
struct bnxt_bs_trace_info bs_trace[BNXT_TRACE_MAX];
2760+
int auxdev_id;
2761+
/* synchronize validity checks of available aux devices */
2762+
struct mutex auxdev_lock;
2763+
u8 auxdev_state[__BNXT_AUXDEV_MAX];
2764+
#define BNXT_ADEV_STATE_NONE 0
2765+
#define BNXT_ADEV_STATE_INIT 1
2766+
#define BNXT_ADEV_STATE_ADD 2
27662767
};
27672768

27682769
#define BNXT_NUM_RX_RING_STATS 8

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,13 @@ static int bnxt_dl_reload_down(struct devlink *dl, bool netns_change,
440440
"reload is unsupported while VFs are allocated or being configured");
441441
netdev_unlock(bp->dev);
442442
rtnl_unlock();
443-
bnxt_ulp_start(bp, 0);
443+
bnxt_ulp_start(bp);
444444
return -EOPNOTSUPP;
445445
}
446446
if (bp->dev->reg_state == NETREG_UNREGISTERED) {
447447
netdev_unlock(bp->dev);
448448
rtnl_unlock();
449-
bnxt_ulp_start(bp, 0);
449+
bnxt_ulp_start(bp);
450450
return -ENODEV;
451451
}
452452
if (netif_running(bp->dev))
@@ -578,8 +578,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
578578
}
579579
netdev_unlock(bp->dev);
580580
rtnl_unlock();
581-
if (action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
582-
bnxt_ulp_start(bp, rc);
581+
if (!rc && action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
582+
bnxt_ulp_start(bp);
583583
return rc;
584584
}
585585

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5212,7 +5212,7 @@ static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
52125212

52135213
memset(buf, 0, sizeof(u64) * bp->num_tests);
52145214
if (etest->flags & ETH_TEST_FL_OFFLINE &&
5215-
bnxt_ulp_registered(bp->edev)) {
5215+
bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
52165216
etest->flags |= ETH_TEST_FL_FAILED;
52175217
netdev_warn(dev, "Offline tests cannot be run with RoCE driver loaded\n");
52185218
return;

0 commit comments

Comments
 (0)