]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
enic: make enic_dev_enable/disable ref-counted
authorSatish Kharat <satishkh@cisco.com>
Wed, 1 Apr 2026 15:31:14 +0000 (08:31 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 3 Apr 2026 01:05:06 +0000 (18:05 -0700)
Both the data path (ndo_open/ndo_stop) and the upcoming admin channel
need to enable and disable the vNIC device independently. Without
reference counting, closing the admin channel while the netdev is up
would inadvertently disable the entire device.

Add an enable_count to struct enic, protected by the existing
devcmd_lock. enic_dev_enable() issues CMD_ENABLE_WAIT only on the
first caller (0 -> 1 transition), and enic_dev_disable() issues
CMD_DISABLE only when the last caller releases (1 -> 0 transition).

Also check the return value of enic_dev_enable() in enic_open() and
fail the open if the firmware enable command fails. Without this check,
a failed enable leaves enable_count at zero while the interface appears
up, which can cause a later admin channel enable/disable cycle to
incorrectly disable the hardware under the active data path.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
Link: https://patch.msgid.link/20260401-enic-sriov-v2-prep-v4-4-d5834b2ef1b9@cisco.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/cisco/enic/enic.h
drivers/net/ethernet/cisco/enic/enic_dev.c
drivers/net/ethernet/cisco/enic/enic_main.c

index 0fd9cd917132f81ebcd00c490303bfbcc8eb7bf1..67fd780b1fa1c94f7c5e42d1f2d8595724766eb5 100644 (file)
@@ -260,6 +260,7 @@ struct enic {
        u16 num_vfs;
 #endif
        enum enic_vf_type vf_type;
+       unsigned int enable_count;
        spinlock_t enic_api_lock;
        bool enic_api_busy;
        struct enic_port_profile *pp;
index 2cbae7c6cc3d68439b9977bc78f3b620f954b797..659787f73cf180e8377ff30de14a316cabb303f7 100644 (file)
@@ -131,10 +131,13 @@ int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
 
 int enic_dev_enable(struct enic *enic)
 {
-       int err;
+       int err = 0;
 
        spin_lock_bh(&enic->devcmd_lock);
-       err = vnic_dev_enable_wait(enic->vdev);
+       if (enic->enable_count == 0)
+               err = vnic_dev_enable_wait(enic->vdev);
+       if (!err)
+               enic->enable_count++;
        spin_unlock_bh(&enic->devcmd_lock);
 
        return err;
@@ -142,10 +145,16 @@ int enic_dev_enable(struct enic *enic)
 
 int enic_dev_disable(struct enic *enic)
 {
-       int err;
+       int err = 0;
 
        spin_lock_bh(&enic->devcmd_lock);
-       err = vnic_dev_disable(enic->vdev);
+       if (enic->enable_count == 0) {
+               spin_unlock_bh(&enic->devcmd_lock);
+               return 0;
+       }
+       enic->enable_count--;
+       if (enic->enable_count == 0)
+               err = vnic_dev_disable(enic->vdev);
        spin_unlock_bh(&enic->devcmd_lock);
 
        return err;
index acd05350ec1aa94505fba019e2e738674a8b9ca0..e7125b81808799c62979d5fbad62e21e39340e38 100644 (file)
@@ -1750,7 +1750,11 @@ static int enic_open(struct net_device *netdev)
        if (vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
                for (i = 0; i < enic->wq_count; i++)
                        napi_enable(&enic->napi[enic_cq_wq(enic, i)]);
-       enic_dev_enable(enic);
+       err = enic_dev_enable(enic);
+       if (err) {
+               netdev_err(netdev, "Failed to enable device: %d\n", err);
+               goto err_out_dev_enable;
+       }
 
        for (i = 0; i < enic->intr_count; i++)
                vnic_intr_unmask(&enic->intr[i]);
@@ -1760,6 +1764,17 @@ static int enic_open(struct net_device *netdev)
 
        return 0;
 
+err_out_dev_enable:
+       for (i = 0; i < enic->rq_count; i++)
+               napi_disable(&enic->napi[i]);
+       if (vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
+               for (i = 0; i < enic->wq_count; i++)
+                       napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
+       netif_tx_disable(netdev);
+       if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
+               enic_dev_del_station_addr(enic);
+       for (i = 0; i < enic->wq_count; i++)
+               vnic_wq_disable(&enic->wq[i].vwq);
 err_out_free_rq:
        for (i = 0; i < enic->rq_count; i++) {
                ret = vnic_rq_disable(&enic->rq[i].vrq);