]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
idpf: convert vport state to bitmap
authorEmil Tantilov <emil.s.tantilov@intel.com>
Tue, 25 Nov 2025 22:36:24 +0000 (14:36 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Jan 2026 15:35:26 +0000 (16:35 +0100)
[ Upstream commit 8dd72ebc73f37b216410db17340f15e6fb2cdb7b ]

Convert vport state to a bitmap and remove the DOWN state which is
redundant in the existing logic. There are no functional changes aside
from the use of bitwise operations when setting and checking the states.
Removed the double underscore to be consistent with the naming of other
bitmaps in the header and renamed current_state to vport_is_up to match
the meaning of the new variable.

Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Chittim Madhu <madhu.chittim@intel.com>
Signed-off-by: Emil Tantilov <emil.s.tantilov@intel.com>
Tested-by: Samuel Salin <Samuel.salin@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Link: https://patch.msgid.link/20251125223632.1857532-6-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 2e281e1155fc ("idpf: detach and close netdevs while handling a reset")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/intel/idpf/idpf.h
drivers/net/ethernet/intel/idpf/idpf_ethtool.c
drivers/net/ethernet/intel/idpf/idpf_lib.c
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c
drivers/net/ethernet/intel/idpf/idpf_txrx.c
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
drivers/net/ethernet/intel/idpf/xdp.c

index ca4da0c8997947084e52c646417f8a1a94f875e0..64142f8163fed7d60bcf0d95efa4f452a0b22e1a 100644 (file)
@@ -131,14 +131,12 @@ enum idpf_cap_field {
 
 /**
  * enum idpf_vport_state - Current vport state
- * @__IDPF_VPORT_DOWN: Vport is down
- * @__IDPF_VPORT_UP: Vport is up
- * @__IDPF_VPORT_STATE_LAST: Must be last, number of states
+ * @IDPF_VPORT_UP: Vport is up
+ * @IDPF_VPORT_STATE_NBITS: Must be last, number of states
  */
 enum idpf_vport_state {
-       __IDPF_VPORT_DOWN,
-       __IDPF_VPORT_UP,
-       __IDPF_VPORT_STATE_LAST,
+       IDPF_VPORT_UP,
+       IDPF_VPORT_STATE_NBITS
 };
 
 /**
@@ -162,7 +160,7 @@ struct idpf_netdev_priv {
        u16 vport_idx;
        u16 max_tx_hdr_size;
        u16 tx_max_bufs;
-       enum idpf_vport_state state;
+       DECLARE_BITMAP(state, IDPF_VPORT_STATE_NBITS);
        struct rtnl_link_stats64 netstats;
        spinlock_t stats_lock;
 };
index a5a1eec9ade8bd110507ccf6c0bfe94563be51b8..eed166bc46f38ef0869608aec83b4c8cb76cc831 100644 (file)
@@ -386,7 +386,7 @@ static int idpf_get_rxfh(struct net_device *netdev,
        }
 
        rss_data = &adapter->vport_config[np->vport_idx]->user_config.rss_data;
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                goto unlock_mutex;
 
        rxfh->hfunc = ETH_RSS_HASH_TOP;
@@ -436,7 +436,7 @@ static int idpf_set_rxfh(struct net_device *netdev,
        }
 
        rss_data = &adapter->vport_config[vport->idx]->user_config.rss_data;
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                goto unlock_mutex;
 
        if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
@@ -1167,7 +1167,7 @@ static void idpf_get_ethtool_stats(struct net_device *netdev,
        idpf_vport_ctrl_lock(netdev);
        vport = idpf_netdev_to_vport(netdev);
 
-       if (np->state != __IDPF_VPORT_UP) {
+       if (!test_bit(IDPF_VPORT_UP, np->state)) {
                idpf_vport_ctrl_unlock(netdev);
 
                return;
@@ -1319,7 +1319,7 @@ static int idpf_get_q_coalesce(struct net_device *netdev,
        idpf_vport_ctrl_lock(netdev);
        vport = idpf_netdev_to_vport(netdev);
 
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                goto unlock_mutex;
 
        if (q_num >= vport->num_rxq && q_num >= vport->num_txq) {
@@ -1507,7 +1507,7 @@ static int idpf_set_coalesce(struct net_device *netdev,
        idpf_vport_ctrl_lock(netdev);
        vport = idpf_netdev_to_vport(netdev);
 
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                goto unlock_mutex;
 
        for (i = 0; i < vport->num_txq; i++) {
@@ -1710,7 +1710,7 @@ static void idpf_get_ts_stats(struct net_device *netdev,
                ts_stats->err = u64_stats_read(&vport->tstamp_stats.discarded);
        } while (u64_stats_fetch_retry(&vport->tstamp_stats.stats_sync, start));
 
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                goto exit;
 
        for (u16 i = 0; i < vport->num_txq_grp; i++) {
index 452f3107378cbbfe01198fb538da57f5883a0899..313803c088478a7a6816c8cf2854087b718f8e40 100644 (file)
@@ -519,7 +519,7 @@ static int idpf_del_mac_filter(struct idpf_vport *vport,
        }
        spin_unlock_bh(&vport_config->mac_filter_list_lock);
 
-       if (np->state == __IDPF_VPORT_UP) {
+       if (test_bit(IDPF_VPORT_UP, np->state)) {
                int err;
 
                err = idpf_add_del_mac_filters(vport, np, false, async);
@@ -590,7 +590,7 @@ static int idpf_add_mac_filter(struct idpf_vport *vport,
        if (err)
                return err;
 
-       if (np->state == __IDPF_VPORT_UP)
+       if (test_bit(IDPF_VPORT_UP, np->state))
                err = idpf_add_del_mac_filters(vport, np, true, async);
 
        return err;
@@ -894,7 +894,7 @@ static void idpf_vport_stop(struct idpf_vport *vport, bool rtnl)
 {
        struct idpf_netdev_priv *np = netdev_priv(vport->netdev);
 
-       if (np->state <= __IDPF_VPORT_DOWN)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                return;
 
        if (rtnl)
@@ -921,7 +921,7 @@ static void idpf_vport_stop(struct idpf_vport *vport, bool rtnl)
        idpf_xdp_rxq_info_deinit_all(vport);
        idpf_vport_queues_rel(vport);
        idpf_vport_intr_rel(vport);
-       np->state = __IDPF_VPORT_DOWN;
+       clear_bit(IDPF_VPORT_UP, np->state);
 
        if (rtnl)
                rtnl_unlock();
@@ -1345,7 +1345,7 @@ static int idpf_up_complete(struct idpf_vport *vport)
                netif_tx_start_all_queues(vport->netdev);
        }
 
-       np->state = __IDPF_VPORT_UP;
+       set_bit(IDPF_VPORT_UP, np->state);
 
        return 0;
 }
@@ -1391,7 +1391,7 @@ static int idpf_vport_open(struct idpf_vport *vport, bool rtnl)
        struct idpf_vport_config *vport_config;
        int err;
 
-       if (np->state != __IDPF_VPORT_DOWN)
+       if (test_bit(IDPF_VPORT_UP, np->state))
                return -EBUSY;
 
        if (rtnl)
@@ -1602,7 +1602,7 @@ void idpf_init_task(struct work_struct *work)
 
        /* Once state is put into DOWN, driver is ready for dev_open */
        np = netdev_priv(vport->netdev);
-       np->state = __IDPF_VPORT_DOWN;
+       clear_bit(IDPF_VPORT_UP, np->state);
        if (test_and_clear_bit(IDPF_VPORT_UP_REQUESTED, vport_config->flags))
                idpf_vport_open(vport, true);
 
@@ -1796,7 +1796,7 @@ static void idpf_set_vport_state(struct idpf_adapter *adapter)
                        continue;
 
                np = netdev_priv(adapter->netdevs[i]);
-               if (np->state == __IDPF_VPORT_UP)
+               if (test_bit(IDPF_VPORT_UP, np->state))
                        set_bit(IDPF_VPORT_UP_REQUESTED,
                                adapter->vport_config[i]->flags);
        }
@@ -1934,7 +1934,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
                             enum idpf_vport_reset_cause reset_cause)
 {
        struct idpf_netdev_priv *np = netdev_priv(vport->netdev);
-       enum idpf_vport_state current_state = np->state;
+       bool vport_is_up = test_bit(IDPF_VPORT_UP, np->state);
        struct idpf_adapter *adapter = vport->adapter;
        struct idpf_vport *new_vport;
        int err;
@@ -1985,7 +1985,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
                goto free_vport;
        }
 
-       if (current_state <= __IDPF_VPORT_DOWN) {
+       if (!vport_is_up) {
                idpf_send_delete_queues_msg(vport);
        } else {
                set_bit(IDPF_VPORT_DEL_QUEUES, vport->flags);
@@ -2018,7 +2018,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
        if (err)
                goto err_open;
 
-       if (current_state == __IDPF_VPORT_UP)
+       if (vport_is_up)
                err = idpf_vport_open(vport, false);
 
        goto free_vport;
@@ -2028,7 +2028,7 @@ err_reset:
                                 vport->num_rxq, vport->num_bufq);
 
 err_open:
-       if (current_state == __IDPF_VPORT_UP)
+       if (vport_is_up)
                idpf_vport_open(vport, false);
 
 free_vport:
index 61e613066140453d59b08fa11fea654042c53ec1..e3ddf18dcbf51b78383bc984d5911e5218d0aff8 100644 (file)
@@ -570,7 +570,7 @@ fetch_next_txq_desc:
        np = netdev_priv(tx_q->netdev);
        nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
 
-       dont_wake = np->state != __IDPF_VPORT_UP ||
+       dont_wake = !test_bit(IDPF_VPORT_UP, np->state) ||
                    !netif_carrier_ok(tx_q->netdev);
        __netif_txq_completed_wake(nq, ss.packets, ss.bytes,
                                   IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH,
index 828f7c444d3093cd5401a0df6c5c94e42bc20d32..1993a3b0da59bd9e1a92d023c6de9ef6c48692ff 100644 (file)
@@ -2275,7 +2275,7 @@ fetch_next_desc:
                /* Update BQL */
                nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
 
-               dont_wake = !complq_ok || np->state != __IDPF_VPORT_UP ||
+               dont_wake = !complq_ok || !test_bit(IDPF_VPORT_UP, np->state) ||
                            !netif_carrier_ok(tx_q->netdev);
                /* Check if the TXQ needs to and can be restarted */
                __netif_txq_completed_wake(nq, tx_q->cleaned_pkts, tx_q->cleaned_bytes,
index fc03d55bc9b9084325dc5ffe85f8f14b8b1b2e92..5bbe7d9294c141eb882a2acba6a6cf2b4b9d9897 100644 (file)
@@ -68,7 +68,7 @@ static void idpf_handle_event_link(struct idpf_adapter *adapter,
 
        vport->link_up = v2e->link_status;
 
-       if (np->state != __IDPF_VPORT_UP)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                return;
 
        if (vport->link_up) {
@@ -2760,7 +2760,7 @@ int idpf_send_get_stats_msg(struct idpf_vport *vport)
 
 
        /* Don't send get_stats message if the link is down */
-       if (np->state <= __IDPF_VPORT_DOWN)
+       if (!test_bit(IDPF_VPORT_UP, np->state))
                return 0;
 
        stats_msg.vport_id = cpu_to_le32(vport->vport_id);
index 21ce25b0567f6fbf675b2a6b570ba537f6e8de97..958d16f874248d862e48210bc342c86076f1e67a 100644 (file)
@@ -418,7 +418,7 @@ static int idpf_xdp_setup_prog(struct idpf_vport *vport,
        if (test_bit(IDPF_REMOVE_IN_PROG, vport->adapter->flags) ||
            !test_bit(IDPF_VPORT_REG_NETDEV, cfg->flags) ||
            !!vport->xdp_prog == !!prog) {
-               if (np->state == __IDPF_VPORT_UP)
+               if (test_bit(IDPF_VPORT_UP, np->state))
                        idpf_xdp_copy_prog_to_rqs(vport, prog);
 
                old = xchg(&vport->xdp_prog, prog);