Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Pavan Chebbi and committed by
Jason Gunthorpe
2c7c85c8 7be18a1f

+271 -165
+28 -19
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 6896 6896 #endif 6897 6897 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan) 6898 6898 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])) 6900 6901 req->flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp)); 6901 6902 6902 6903 return hwrm_req_send(bp, req); ··· 8032 8031 8033 8032 static int __bnxt_reserve_rings(struct bnxt *bp) 8034 8033 { 8034 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 8035 8035 struct bnxt_hw_rings hwr = {0}; 8036 8036 int rx_rings, old_rx_rings, rc; 8037 8037 int cp = bp->cp_nr_rings; ··· 8043 8041 if (!bnxt_need_reserve_rings(bp)) 8044 8042 return 0; 8045 8043 8046 - if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) { 8044 + if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) { 8047 8045 ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want); 8048 8046 if (!ulp_msix) 8049 8047 bnxt_set_ulp_stat_ctxs(bp, 0); ··· 8094 8092 } 8095 8093 rx_rings = min_t(int, rx_rings, hwr.grp); 8096 8094 hwr.cp = min_t(int, hwr.cp, bp->cp_nr_rings); 8097 - if (bnxt_ulp_registered(bp->edev) && 8098 - hwr.stat > bnxt_get_ulp_stat_ctxs(bp)) 8095 + if (bnxt_ulp_registered(edev) && hwr.stat > bnxt_get_ulp_stat_ctxs(bp)) 8099 8096 hwr.stat -= bnxt_get_ulp_stat_ctxs(bp); 8100 8097 hwr.cp = min_t(int, hwr.cp, hwr.stat); 8101 8098 rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh); ··· 8138 8137 !netif_is_rxfh_configured(bp->dev)) 8139 8138 bnxt_set_dflt_rss_indir_tbl(bp, NULL); 8140 8139 8141 - if (!bnxt_ulp_registered(bp->edev) && BNXT_NEW_RM(bp)) { 8140 + if (!bnxt_ulp_registered(edev) && BNXT_NEW_RM(bp)) { 8142 8141 int resv_msix, resv_ctx, ulp_ctxs; 8143 8142 struct bnxt_hw_resc *hw_resc; 8144 8143 ··· 11495 11494 11496 11495 int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) 11497 11496 { 11497 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 11498 11498 bool irq_cleared = false; 11499 11499 bool irq_change = false; 11500 11500 int tcs = bp->num_tc; ··· 11505 11503 if (!bnxt_need_reserve_rings(bp)) 11506 11504 return 0; 11507 11505 11508 - if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) { 11506 + if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) { 11509 11507 int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want); 11510 11508 11511 11509 if (ulp_msix > bp->ulp_num_msix_want) ··· 14595 14593 static void bnxt_ulp_restart(struct bnxt *bp) 14596 14594 { 14597 14595 bnxt_ulp_stop(bp); 14598 - bnxt_ulp_start(bp, 0); 14596 + bnxt_ulp_start(bp); 14599 14597 } 14600 14598 14601 14599 static void bnxt_sp_task(struct work_struct *work) ··· 14752 14750 hwr.cp_p5 = hwr.tx + rx; 14753 14751 rc = bnxt_hwrm_check_rings(bp, &hwr); 14754 14752 if (!rc && pci_msix_can_alloc_dyn(bp->pdev)) { 14755 - if (!bnxt_ulp_registered(bp->edev)) { 14753 + if (!bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) { 14756 14754 hwr.cp += bnxt_get_ulp_msix_num(bp); 14757 14755 hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp)); 14758 14756 } ··· 15272 15270 bnxt_dl_health_fw_status_update(bp, true); 15273 15271 } 15274 15272 netdev_unlock(bp->dev); 15275 - bnxt_ulp_start(bp, 0); 15273 + bnxt_ulp_start(bp); 15276 15274 bnxt_reenable_sriov(bp); 15277 15275 netdev_lock(bp->dev); 15278 15276 bnxt_vf_reps_alloc(bp); ··· 15294 15292 bnxt_fw_reset_abort(bp, rc); 15295 15293 netdev_unlock(bp->dev); 15296 15294 ulp_start: 15297 - bnxt_ulp_start(bp, rc); 15295 + if (!rc) 15296 + bnxt_ulp_start(bp); 15298 15297 } 15299 15298 15300 15299 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) ··· 16330 16327 if (BNXT_PF(bp)) 16331 16328 __bnxt_sriov_disable(bp); 16332 16329 16333 - bnxt_rdma_aux_device_del(bp); 16330 + bnxt_aux_devices_del(bp); 16334 16331 16335 16332 unregister_netdev(dev); 16336 16333 bnxt_ptp_clear(bp); 16337 16334 16338 - bnxt_rdma_aux_device_uninit(bp); 16335 + bnxt_aux_devices_uninit(bp); 16336 + bnxt_auxdev_id_free(bp, bp->auxdev_id); 16339 16337 16340 16338 bnxt_free_l2_filters(bp, true); 16341 16339 bnxt_free_ntp_fltrs(bp, true); ··· 16922 16918 bnxt_set_tpa_flags(bp); 16923 16919 bnxt_init_ring_params(bp); 16924 16920 bnxt_set_ring_params(bp); 16925 - bnxt_rdma_aux_device_init(bp); 16921 + mutex_init(&bp->auxdev_lock); 16922 + if (!bnxt_auxdev_id_alloc(bp)) 16923 + bnxt_aux_devices_init(bp); 16926 16924 rc = bnxt_set_dflt_rings(bp, true); 16927 16925 if (rc) { 16928 16926 if (BNXT_VF(bp) && rc == -ENODEV) { ··· 16989 16983 16990 16984 bnxt_dl_fw_reporters_create(bp); 16991 16985 16992 - bnxt_rdma_aux_device_add(bp); 16986 + bnxt_aux_devices_add(bp); 16993 16987 16994 16988 bnxt_print_device_info(bp); 16995 16989 ··· 16997 16991 16998 16992 return 0; 16999 16993 init_err_cleanup: 17000 - bnxt_rdma_aux_device_uninit(bp); 16994 + bnxt_aux_devices_uninit(bp); 16995 + bnxt_auxdev_id_free(bp, bp->auxdev_id); 17001 16996 bnxt_dl_unregister(bp); 17002 16997 init_err_dl: 17003 16998 bnxt_shutdown_tc(bp); ··· 17132 17125 17133 17126 resume_exit: 17134 17127 netdev_unlock(bp->dev); 17135 - bnxt_ulp_start(bp, rc); 17136 - if (!rc) 17128 + if (!rc) { 17129 + bnxt_ulp_start(bp); 17137 17130 bnxt_reenable_sriov(bp); 17131 + } 17138 17132 return rc; 17139 17133 } 17140 17134 ··· 17315 17307 netif_device_attach(netdev); 17316 17308 17317 17309 netdev_unlock(netdev); 17318 - bnxt_ulp_start(bp, err); 17319 - if (!err) 17310 + if (!err) { 17311 + bnxt_ulp_start(bp); 17320 17312 bnxt_reenable_sriov(bp); 17313 + } 17321 17314 } 17322 17315 17323 17316 static const struct pci_error_handlers bnxt_err_handler = {
+10 -9
drivers/net/ethernet/broadcom/bnxt/bnxt.h
··· 24 24 #include <linux/interrupt.h> 25 25 #include <linux/rhashtable.h> 26 26 #include <linux/crash_dump.h> 27 - #include <linux/auxiliary_bus.h> 28 27 #include <net/devlink.h> 29 28 #include <net/dst_metadata.h> 30 29 #include <net/xdp.h> 31 30 #include <linux/dim.h> 32 31 #include <linux/io-64-nonatomic-lo-hi.h> 32 + #include <linux/bnxt/ulp.h> 33 33 #ifdef CONFIG_TEE_BNXT_FW 34 34 #include <linux/firmware/broadcom/tee_bnxt_fw.h> 35 35 #endif ··· 2085 2085 #define BNXT_FW_IF_RETRY 10 2086 2086 #define BNXT_FW_SLOT_RESET_RETRY 4 2087 2087 2088 - struct bnxt_aux_priv { 2089 - struct auxiliary_device aux_dev; 2090 - struct bnxt_en_dev *edev; 2091 - int id; 2092 - }; 2093 - 2094 2088 enum board_idx { 2095 2089 BCM57301, 2096 2090 BCM57302, ··· 2344 2350 #define BNXT_CHIP_P5_AND_MINUS(bp) \ 2345 2351 (BNXT_CHIP_P3(bp) || BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp)) 2346 2352 2347 - struct bnxt_aux_priv *aux_priv; 2348 - struct bnxt_en_dev *edev; 2353 + struct bnxt_aux_priv *aux_priv[__BNXT_AUXDEV_MAX]; 2354 + struct bnxt_en_dev *edev[__BNXT_AUXDEV_MAX]; 2349 2355 2350 2356 struct bnxt_napi **bnapi; 2351 2357 ··· 2757 2763 struct bnxt_ctx_pg_info *fw_crash_mem; 2758 2764 u32 fw_crash_len; 2759 2765 struct bnxt_bs_trace_info bs_trace[BNXT_TRACE_MAX]; 2766 + int auxdev_id; 2767 + /* synchronize validity checks of available aux devices */ 2768 + struct mutex auxdev_lock; 2769 + u8 auxdev_state[__BNXT_AUXDEV_MAX]; 2770 + #define BNXT_ADEV_STATE_NONE 0 2771 + #define BNXT_ADEV_STATE_INIT 1 2772 + #define BNXT_ADEV_STATE_ADD 2 2760 2773 }; 2761 2774 2762 2775 #define BNXT_NUM_RX_RING_STATS 8
+4 -4
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
··· 440 440 "reload is unsupported while VFs are allocated or being configured"); 441 441 netdev_unlock(bp->dev); 442 442 rtnl_unlock(); 443 - bnxt_ulp_start(bp, 0); 443 + bnxt_ulp_start(bp); 444 444 return -EOPNOTSUPP; 445 445 } 446 446 if (bp->dev->reg_state == NETREG_UNREGISTERED) { 447 447 netdev_unlock(bp->dev); 448 448 rtnl_unlock(); 449 - bnxt_ulp_start(bp, 0); 449 + bnxt_ulp_start(bp); 450 450 return -ENODEV; 451 451 } 452 452 if (netif_running(bp->dev)) ··· 578 578 } 579 579 netdev_unlock(bp->dev); 580 580 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); 583 583 return rc; 584 584 } 585 585
+1 -1
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
··· 5212 5212 5213 5213 memset(buf, 0, sizeof(u64) * bp->num_tests); 5214 5214 if (etest->flags & ETH_TEST_FL_OFFLINE && 5215 - bnxt_ulp_registered(bp->edev)) { 5215 + bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) { 5216 5216 etest->flags |= ETH_TEST_FL_FAILED; 5217 5217 netdev_warn(dev, "Offline tests cannot be run with RoCE driver loaded\n"); 5218 5218 return;
+208 -127
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
··· 29 29 30 30 static DEFINE_IDA(bnxt_aux_dev_ids); 31 31 32 + struct bnxt_aux_device { 33 + const char *name; 34 + }; 35 + 36 + static void bnxt_auxdev_set_state(struct bnxt *bp, int idx, int state) 37 + { 38 + bp->auxdev_state[idx] = state; 39 + } 40 + 41 + static bool bnxt_auxdev_is_init(struct bnxt *bp, int idx) 42 + { 43 + return (bp->auxdev_state[idx] == BNXT_ADEV_STATE_INIT); 44 + } 45 + 46 + static bool bnxt_auxdev_is_active(struct bnxt *bp, int idx) 47 + { 48 + return (bp->auxdev_state[idx] == BNXT_ADEV_STATE_ADD); 49 + } 50 + 51 + static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{ 52 + .name = "rdma", 53 + }}; 54 + 32 55 static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent) 33 56 { 34 - struct bnxt_en_dev *edev = bp->edev; 57 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 35 58 int num_msix, i; 36 59 37 60 if (!edev->ulp_tbl->msix_requested) { ··· 74 51 75 52 int bnxt_get_ulp_msix_num(struct bnxt *bp) 76 53 { 77 - if (bp->edev) 78 - return bp->edev->ulp_num_msix_vec; 54 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 55 + 56 + if (edev) 57 + return edev->ulp_num_msix_vec; 79 58 return 0; 80 59 } 81 60 82 61 void bnxt_set_ulp_msix_num(struct bnxt *bp, int num) 83 62 { 84 - if (bp->edev) 85 - bp->edev->ulp_num_msix_vec = num; 63 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 64 + 65 + if (edev) 66 + edev->ulp_num_msix_vec = num; 86 67 } 87 68 88 69 int bnxt_get_ulp_msix_num_in_use(struct bnxt *bp) 89 70 { 90 - if (bnxt_ulp_registered(bp->edev)) 91 - return bp->edev->ulp_num_msix_vec; 71 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 72 + 73 + if (bnxt_ulp_registered(edev)) 74 + return edev->ulp_num_msix_vec; 92 75 return 0; 93 76 } 94 77 95 78 int bnxt_get_ulp_stat_ctxs(struct bnxt *bp) 96 79 { 97 - if (bp->edev) 98 - return bp->edev->ulp_num_ctxs; 80 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 81 + 82 + if (edev) 83 + return edev->ulp_num_ctxs; 99 84 return 0; 100 85 } 101 86 102 87 void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ulp_ctx) 103 88 { 104 - if (bp->edev) 105 - bp->edev->ulp_num_ctxs = num_ulp_ctx; 89 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 90 + 91 + if (edev) 92 + edev->ulp_num_ctxs = num_ulp_ctx; 106 93 } 107 94 108 95 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp) 109 96 { 110 - if (bnxt_ulp_registered(bp->edev)) 111 - return bp->edev->ulp_num_ctxs; 97 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 98 + 99 + if (bnxt_ulp_registered(edev)) 100 + return edev->ulp_num_ctxs; 112 101 return 0; 113 102 } 114 103 115 104 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp) 116 105 { 117 - if (bp->edev) { 118 - bp->edev->ulp_num_ctxs = BNXT_MIN_ROCE_STAT_CTXS; 106 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 107 + 108 + if (edev) { 109 + edev->ulp_num_ctxs = BNXT_MIN_ROCE_STAT_CTXS; 119 110 /* Reserve one additional stat_ctx for PF0 (except 120 111 * on 1-port NICs) as it also creates one stat_ctx 121 112 * for PF1 in case of RoCE bonding. 122 113 */ 123 114 if (BNXT_PF(bp) && !bp->pf.port_id && 124 115 bp->port_count > 1) 125 - bp->edev->ulp_num_ctxs++; 116 + edev->ulp_num_ctxs++; 126 117 127 118 /* Reserve one additional stat_ctx when the device is capable 128 119 * of supporting port mirroring on RDMA device. 129 120 */ 130 121 if (BNXT_MIRROR_ON_ROCE_CAP(bp)) 131 - bp->edev->ulp_num_ctxs++; 122 + edev->ulp_num_ctxs++; 132 123 } 133 124 } 134 125 ··· 178 141 179 142 edev->ulp_tbl->msix_requested = bnxt_get_ulp_msix_num(bp); 180 143 181 - bnxt_fill_msix_vecs(bp, bp->edev->msix_entries); 144 + bnxt_fill_msix_vecs(bp, edev->msix_entries); 182 145 exit: 183 146 mutex_unlock(&edev->en_dev_lock); 184 147 netdev_unlock(dev); ··· 264 227 265 228 void bnxt_ulp_stop(struct bnxt *bp) 266 229 { 267 - struct bnxt_aux_priv *aux_priv = bp->aux_priv; 268 - struct bnxt_en_dev *edev = bp->edev; 230 + int i; 269 231 270 - if (!edev) 271 - return; 272 - 273 - mutex_lock(&edev->en_dev_lock); 274 - if (!bnxt_ulp_registered(edev) || 275 - (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) 276 - goto ulp_stop_exit; 277 - 278 - edev->flags |= BNXT_EN_FLAG_ULP_STOPPED; 279 - if (aux_priv) { 232 + mutex_lock(&bp->auxdev_lock); 233 + for (i = 0; i < __BNXT_AUXDEV_MAX; i++) { 234 + struct bnxt_aux_priv *aux_priv; 280 235 struct auxiliary_device *adev; 236 + struct bnxt_en_dev *edev; 237 + 238 + if (!bnxt_auxdev_is_active(bp, i)) 239 + continue; 240 + 241 + aux_priv = bp->aux_priv[i]; 242 + edev = bp->edev[i]; 243 + mutex_lock(&edev->en_dev_lock); 244 + if (!bnxt_ulp_registered(edev) || 245 + (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) { 246 + mutex_unlock(&edev->en_dev_lock); 247 + continue; 248 + } 249 + 250 + edev->flags |= BNXT_EN_FLAG_ULP_STOPPED; 281 251 282 252 adev = &aux_priv->aux_dev; 283 253 if (adev->dev.driver) { ··· 295 251 edev->en_state = bp->state; 296 252 adrv->suspend(adev, pm); 297 253 } 254 + mutex_unlock(&edev->en_dev_lock); 298 255 } 299 - ulp_stop_exit: 300 - mutex_unlock(&edev->en_dev_lock); 256 + mutex_unlock(&bp->auxdev_lock); 301 257 } 302 258 303 - void bnxt_ulp_start(struct bnxt *bp, int err) 259 + void bnxt_ulp_start(struct bnxt *bp) 304 260 { 305 - struct bnxt_aux_priv *aux_priv = bp->aux_priv; 306 - struct bnxt_en_dev *edev = bp->edev; 261 + int i; 307 262 308 - if (!edev || err) 309 - return; 310 - 311 - mutex_lock(&edev->en_dev_lock); 312 - if (!bnxt_ulp_registered(edev) || 313 - !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) 314 - goto ulp_start_exit; 315 - 316 - if (edev->ulp_tbl->msix_requested) 317 - bnxt_fill_msix_vecs(bp, edev->msix_entries); 318 - 319 - if (aux_priv) { 263 + mutex_lock(&bp->auxdev_lock); 264 + for (i = 0; i < __BNXT_AUXDEV_MAX; i++) { 265 + struct bnxt_aux_priv *aux_priv; 320 266 struct auxiliary_device *adev; 267 + struct bnxt_en_dev *edev; 268 + 269 + if (!bnxt_auxdev_is_active(bp, i)) 270 + continue; 271 + 272 + aux_priv = bp->aux_priv[i]; 273 + edev = bp->edev[i]; 274 + mutex_lock(&edev->en_dev_lock); 275 + if (!bnxt_ulp_registered(edev) || 276 + !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) { 277 + goto clear_flag_continue; 278 + } 279 + 280 + if (edev->ulp_tbl->msix_requested) 281 + bnxt_fill_msix_vecs(bp, edev->msix_entries); 282 + 321 283 322 284 adev = &aux_priv->aux_dev; 323 285 if (adev->dev.driver) { ··· 333 283 edev->en_state = bp->state; 334 284 adrv->resume(adev); 335 285 } 286 + clear_flag_continue: 287 + edev->flags &= ~BNXT_EN_FLAG_ULP_STOPPED; 288 + mutex_unlock(&edev->en_dev_lock); 336 289 } 337 - ulp_start_exit: 338 - edev->flags &= ~BNXT_EN_FLAG_ULP_STOPPED; 339 - mutex_unlock(&edev->en_dev_lock); 290 + mutex_unlock(&bp->auxdev_lock); 340 291 } 341 292 342 293 void bnxt_ulp_irq_stop(struct bnxt *bp) 343 294 { 344 - struct bnxt_en_dev *edev = bp->edev; 295 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 345 296 struct bnxt_ulp_ops *ops; 346 297 bool reset = false; 347 298 348 299 if (!edev) 349 300 return; 350 301 351 - if (bnxt_ulp_registered(bp->edev)) { 302 + if (bnxt_ulp_registered(edev)) { 352 303 struct bnxt_ulp *ulp = edev->ulp_tbl; 353 304 354 305 if (!ulp->msix_requested) ··· 366 315 367 316 void bnxt_ulp_irq_restart(struct bnxt *bp, int err) 368 317 { 369 - struct bnxt_en_dev *edev = bp->edev; 318 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 370 319 struct bnxt_ulp_ops *ops; 371 320 372 321 if (!edev) 373 322 return; 374 323 375 - if (bnxt_ulp_registered(bp->edev)) { 324 + if (bnxt_ulp_registered(edev)) { 376 325 struct bnxt_ulp *ulp = edev->ulp_tbl; 377 326 struct bnxt_msix_entry *ent = NULL; 378 327 ··· 397 346 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl) 398 347 { 399 348 u16 event_id = le16_to_cpu(cmpl->event_id); 400 - struct bnxt_en_dev *edev = bp->edev; 349 + struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA]; 401 350 struct bnxt_ulp_ops *ops; 402 351 struct bnxt_ulp *ulp; 403 352 ··· 438 387 } 439 388 EXPORT_SYMBOL(bnxt_register_async_events); 440 389 441 - void bnxt_rdma_aux_device_uninit(struct bnxt *bp) 390 + void bnxt_aux_devices_uninit(struct bnxt *bp) 442 391 { 443 392 struct bnxt_aux_priv *aux_priv; 444 393 struct auxiliary_device *adev; 394 + int idx; 445 395 446 - /* Skip if no auxiliary device init was done. */ 447 - if (!bp->aux_priv) 448 - return; 449 - 450 - aux_priv = bp->aux_priv; 451 - adev = &aux_priv->aux_dev; 452 - auxiliary_device_uninit(adev); 396 + mutex_lock(&bp->auxdev_lock); 397 + for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) { 398 + if (bnxt_auxdev_is_init(bp, idx)) { 399 + aux_priv = bp->aux_priv[idx]; 400 + adev = &aux_priv->aux_dev; 401 + auxiliary_device_uninit(adev); 402 + } 403 + } 404 + mutex_unlock(&bp->auxdev_lock); 453 405 } 454 406 455 407 static void bnxt_aux_dev_release(struct device *dev) ··· 461 407 container_of(dev, struct bnxt_aux_priv, aux_dev.dev); 462 408 struct bnxt *bp = netdev_priv(aux_priv->edev->net); 463 409 464 - ida_free(&bnxt_aux_dev_ids, aux_priv->id); 465 410 kfree(aux_priv->edev->ulp_tbl); 466 - bp->edev = NULL; 411 + bp->edev[aux_priv->id] = NULL; 467 412 kfree(aux_priv->edev); 413 + bp->aux_priv[aux_priv->id] = NULL; 468 414 kfree(aux_priv); 469 - bp->aux_priv = NULL; 470 415 } 471 416 472 - void bnxt_rdma_aux_device_del(struct bnxt *bp) 417 + void bnxt_aux_devices_del(struct bnxt *bp) 473 418 { 474 - if (!bp->edev) 475 - return; 419 + int idx; 476 420 477 - auxiliary_device_delete(&bp->aux_priv->aux_dev); 421 + mutex_lock(&bp->auxdev_lock); 422 + for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) { 423 + if (bnxt_auxdev_is_active(bp, idx)) { 424 + auxiliary_device_delete(&bp->aux_priv[idx]->aux_dev); 425 + bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT); 426 + } 427 + } 428 + mutex_unlock(&bp->auxdev_lock); 478 429 } 479 430 480 431 static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) ··· 509 450 edev->bar0 = bp->bar0; 510 451 } 511 452 512 - void bnxt_rdma_aux_device_add(struct bnxt *bp) 453 + void bnxt_aux_devices_add(struct bnxt *bp) 513 454 { 514 455 struct auxiliary_device *aux_dev; 515 - int rc; 456 + int rc, idx; 516 457 517 - if (!bp->edev) 518 - return; 519 - 520 - aux_dev = &bp->aux_priv->aux_dev; 521 - rc = auxiliary_device_add(aux_dev); 522 - if (rc) { 523 - netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n"); 524 - auxiliary_device_uninit(aux_dev); 525 - bp->flags &= ~BNXT_FLAG_ROCE_CAP; 458 + mutex_lock(&bp->auxdev_lock); 459 + for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) { 460 + if (bnxt_auxdev_is_init(bp, idx)) { 461 + aux_dev = &bp->aux_priv[idx]->aux_dev; 462 + rc = auxiliary_device_add(aux_dev); 463 + if (rc) { 464 + netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n"); 465 + auxiliary_device_uninit(aux_dev); 466 + if (idx == BNXT_AUXDEV_RDMA) 467 + bp->flags &= ~BNXT_FLAG_ROCE_CAP; 468 + continue; 469 + } 470 + bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_ADD); 471 + } 526 472 } 473 + mutex_unlock(&bp->auxdev_lock); 527 474 } 528 475 529 - void bnxt_rdma_aux_device_init(struct bnxt *bp) 476 + void bnxt_aux_devices_init(struct bnxt *bp) 530 477 { 531 478 struct auxiliary_device *aux_dev; 532 479 struct bnxt_aux_priv *aux_priv; 533 480 struct bnxt_en_dev *edev; 534 481 struct bnxt_ulp *ulp; 535 - int rc; 482 + int rc, idx; 536 483 537 - if (!(bp->flags & BNXT_FLAG_ROCE_CAP)) 538 - return; 484 + mutex_lock(&bp->auxdev_lock); 485 + for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) { 486 + bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_NONE); 539 487 540 - aux_priv = kzalloc_obj(*bp->aux_priv); 541 - if (!aux_priv) 542 - goto exit; 488 + if (idx == BNXT_AUXDEV_RDMA && 489 + !(bp->flags & BNXT_FLAG_ROCE_CAP)) 490 + continue; 543 491 544 - aux_priv->id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL); 545 - if (aux_priv->id < 0) { 546 - netdev_warn(bp->dev, 547 - "ida alloc failed for ROCE auxiliary device\n"); 548 - kfree(aux_priv); 549 - goto exit; 550 - } 492 + aux_priv = kzalloc_obj(*aux_priv); 493 + if (!aux_priv) 494 + goto next_auxdev; 551 495 552 - aux_dev = &aux_priv->aux_dev; 553 - aux_dev->id = aux_priv->id; 554 - aux_dev->name = "rdma"; 555 - aux_dev->dev.parent = &bp->pdev->dev; 556 - aux_dev->dev.release = bnxt_aux_dev_release; 496 + aux_dev = &aux_priv->aux_dev; 497 + aux_dev->id = bp->auxdev_id; 498 + aux_dev->name = bnxt_aux_devices[idx].name; 499 + aux_dev->dev.parent = &bp->pdev->dev; 500 + aux_dev->dev.release = bnxt_aux_dev_release; 557 501 558 - rc = auxiliary_device_init(aux_dev); 559 - if (rc) { 560 - ida_free(&bnxt_aux_dev_ids, aux_priv->id); 561 - kfree(aux_priv); 562 - goto exit; 563 - } 564 - bp->aux_priv = aux_priv; 502 + rc = auxiliary_device_init(aux_dev); 503 + if (rc) { 504 + kfree(aux_priv); 505 + goto next_auxdev; 506 + } 507 + bp->aux_priv[idx] = aux_priv; 565 508 566 - /* From this point, all cleanup will happen via the .release callback & 567 - * any error unwinding will need to include a call to 568 - * auxiliary_device_uninit. 569 - */ 570 - edev = kzalloc_obj(*edev); 571 - if (!edev) 572 - goto aux_dev_uninit; 509 + /* From this point, all cleanup will happen via the .release 510 + * callback & any error unwinding will need to include a call 511 + * to auxiliary_device_uninit. 512 + */ 513 + edev = kzalloc_obj(*edev); 514 + if (!edev) 515 + goto aux_dev_uninit; 573 516 574 - aux_priv->edev = edev; 517 + aux_priv->edev = edev; 518 + bnxt_set_edev_info(edev, bp); 575 519 576 - ulp = kzalloc_obj(*ulp); 577 - if (!ulp) 578 - goto aux_dev_uninit; 520 + ulp = kzalloc_obj(*ulp); 521 + if (!ulp) 522 + goto aux_dev_uninit; 579 523 580 - edev->ulp_tbl = ulp; 581 - bp->edev = edev; 582 - bnxt_set_edev_info(edev, bp); 583 - bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp); 524 + edev->ulp_tbl = ulp; 525 + bp->edev[idx] = edev; 526 + if (idx == BNXT_AUXDEV_RDMA) 527 + bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp); 528 + aux_priv->id = idx; 529 + bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT); 584 530 585 - return; 586 - 531 + continue; 587 532 aux_dev_uninit: 588 - auxiliary_device_uninit(aux_dev); 589 - exit: 590 - bp->flags &= ~BNXT_FLAG_ROCE_CAP; 533 + auxiliary_device_uninit(aux_dev); 534 + next_auxdev: 535 + if (idx == BNXT_AUXDEV_RDMA) 536 + bp->flags &= ~BNXT_FLAG_ROCE_CAP; 537 + } 538 + mutex_unlock(&bp->auxdev_lock); 539 + } 540 + 541 + int bnxt_auxdev_id_alloc(struct bnxt *bp) 542 + { 543 + bp->auxdev_id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL); 544 + if (bp->auxdev_id < 0) 545 + return bp->auxdev_id; 546 + 547 + return 0; 548 + } 549 + 550 + void bnxt_auxdev_id_free(struct bnxt *bp, int id) 551 + { 552 + if (bp->auxdev_id >= 0) 553 + ida_free(&bnxt_aux_dev_ids, id); 591 554 }
+20 -5
include/linux/bnxt/ulp.h
··· 10 10 #ifndef BNXT_ULP_H 11 11 #define BNXT_ULP_H 12 12 13 + #include <linux/auxiliary_bus.h> 14 + 13 15 #define BNXT_MIN_ROCE_CP_RINGS 2 14 16 #define BNXT_MIN_ROCE_STAT_CTXS 1 15 17 ··· 21 19 22 20 struct hwrm_async_event_cmpl; 23 21 struct bnxt; 22 + 23 + enum bnxt_auxdev_type { 24 + BNXT_AUXDEV_RDMA = 0, 25 + __BNXT_AUXDEV_MAX 26 + }; 27 + 28 + struct bnxt_aux_priv { 29 + struct auxiliary_device aux_dev; 30 + struct bnxt_en_dev *edev; 31 + int id; 32 + }; 24 33 25 34 struct bnxt_msix_entry { 26 35 u32 vector; ··· 123 110 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp); 124 111 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp); 125 112 void bnxt_ulp_stop(struct bnxt *bp); 126 - void bnxt_ulp_start(struct bnxt *bp, int err); 113 + void bnxt_ulp_start(struct bnxt *bp); 127 114 void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs); 128 115 void bnxt_ulp_irq_stop(struct bnxt *bp); 129 116 void bnxt_ulp_irq_restart(struct bnxt *bp, int err); 130 117 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl); 131 - void bnxt_rdma_aux_device_uninit(struct bnxt *bp); 132 - void bnxt_rdma_aux_device_del(struct bnxt *bp); 133 - void bnxt_rdma_aux_device_add(struct bnxt *bp); 134 - void bnxt_rdma_aux_device_init(struct bnxt *bp); 118 + void bnxt_aux_devices_uninit(struct bnxt *bp); 119 + void bnxt_aux_devices_del(struct bnxt *bp); 120 + void bnxt_aux_devices_add(struct bnxt *bp); 121 + void bnxt_aux_devices_init(struct bnxt *bp); 135 122 int bnxt_register_dev(struct bnxt_en_dev *edev, struct bnxt_ulp_ops *ulp_ops, 136 123 void *handle); 137 124 void bnxt_unregister_dev(struct bnxt_en_dev *edev); 138 125 int bnxt_send_msg(struct bnxt_en_dev *edev, struct bnxt_fw_msg *fw_msg); 139 126 void bnxt_register_async_events(struct bnxt_en_dev *edev, 140 127 unsigned long *events_bmap, u16 max_id); 128 + int bnxt_auxdev_id_alloc(struct bnxt *bp); 129 + void bnxt_auxdev_id_free(struct bnxt *bp, int id); 141 130 #endif