diff mbox series

[iwl-net,v2] iavf: validate tx_coalesce_usecs even if rx_coalesce_usecs is zero

Message ID 20231127233350.2652604-1-jacob.e.keller@intel.com
State Accepted
Delegated to: Anthony Nguyen
Headers show
Series [iwl-net,v2] iavf: validate tx_coalesce_usecs even if rx_coalesce_usecs is zero | expand

Commit Message

Jacob Keller Nov. 27, 2023, 11:33 p.m. UTC
In __iavf_set_coalesce, the driver checks both ec->rx_coalesce_usecs and
ec->tx_coalesce_usecs for validity. It does this via a chain if if/else-if
blocks. If every single branch of the series of if statements exited, this
would be fine. However, the rx_coalesce_usecs is checked against zero to
print an informative message if use_adaptive_rx_coalesce is enabled. If
this check is true, it short circuits the entire chain of statements,
preventing validation of the tx_coalesce_usecs field.

Indeed, since commit e792779e6b63 ("iavf: Prevent changing static ITR
values if adaptive moderation is on") the iavf driver actually rejects any
change to the tx_coalesce_usecs or rx_coalesce_usecs when
use_adaptive_tx_coalesce or use_adaptive_rx_coalesce is enabled, making
this checking a bit redundant.

Fix this error by removing the unnecessary and redundant checks for
use_adaptive_rx_coalesce and use_adaptive_tx_coalesce. Since zero is a
valid value, and since the tx_coalesce_usecs and rx_coalesce_usecs fields
are already unsigned, remove the minimum value check. This allows assigning
an ITR value ranging from 0-8160 as described by the printed message.

Fixes: 65e87c0398f5 ("i40evf: support queue-specific settings for interrupt moderation")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---

Changes since v1:
* Fix the new check to continue allowing zero as a valid ITR value

 drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 12 ++----------
 drivers/net/ethernet/intel/iavf/iavf_txrx.h    |  1 -
 2 files changed, 2 insertions(+), 11 deletions(-)


base-commit: 218db91044f8f2f6db95ff4788ac1a03fcaf7c4a
prerequisite-patch-id: b6de8a16db743e14af55f1b9cf67f31ef4da0900
prerequisite-patch-id: d36ab3205e29262f859cbecc76f6f52aa35dd1b5
prerequisite-patch-id: 0d1bf2d99824f1a2090539ef5bdd4ea96fbd9957

Comments

Romanowski, Rafal Nov. 30, 2023, 2:47 p.m. UTC | #1
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jacob Keller
> Sent: Tuesday, November 28, 2023 12:34 AM
> To: Intel Wired LAN <intel-wired-lan@lists.osuosl.org>
> Cc: Keller, Jacob E <jacob.e.keller@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>
> Subject: [Intel-wired-lan] [PATCH iwl-net v2] iavf: validate tx_coalesce_usecs
> even if rx_coalesce_usecs is zero
> 
> In __iavf_set_coalesce, the driver checks both ec->rx_coalesce_usecs and
> ec->tx_coalesce_usecs for validity. It does this via a chain if
> ec->if/else-if
> blocks. If every single branch of the series of if statements exited, this would
> be fine. However, the rx_coalesce_usecs is checked against zero to print an
> informative message if use_adaptive_rx_coalesce is enabled. If this check is
> true, it short circuits the entire chain of statements, preventing validation of
> the tx_coalesce_usecs field.
> 
> Indeed, since commit e792779e6b63 ("iavf: Prevent changing static ITR values
> if adaptive moderation is on") the iavf driver actually rejects any change to the
> tx_coalesce_usecs or rx_coalesce_usecs when use_adaptive_tx_coalesce or
> use_adaptive_rx_coalesce is enabled, making this checking a bit redundant.
> 
> Fix this error by removing the unnecessary and redundant checks for
> use_adaptive_rx_coalesce and use_adaptive_tx_coalesce. Since zero is a valid
> value, and since the tx_coalesce_usecs and rx_coalesce_usecs fields are already
> unsigned, remove the minimum value check. This allows assigning an ITR value
> ranging from 0-8160 as described by the printed message.
> 
> Fixes: 65e87c0398f5 ("i40evf: support queue-specific settings for interrupt
> moderation")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
> 
> Changes since v1:
> * Fix the new check to continue allowing zero as a valid ITR value
> 
>  drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 12 ++----------
>  drivers/net/ethernet/intel/iavf/iavf_txrx.h    |  1 -
>  2 files changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
> b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
> index 6f236d1a6444..19cbfe554689 100644
> --- a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
> +++ b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c


Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
index 6f236d1a6444..19cbfe554689 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
@@ -827,18 +827,10 @@  static int __iavf_set_coalesce(struct net_device *netdev,
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 	int i;
 
-	if (ec->rx_coalesce_usecs == 0) {
-		if (ec->use_adaptive_rx_coalesce)
-			netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
-	} else if ((ec->rx_coalesce_usecs < IAVF_MIN_ITR) ||
-		   (ec->rx_coalesce_usecs > IAVF_MAX_ITR)) {
+	if (ec->rx_coalesce_usecs > IAVF_MAX_ITR) {
 		netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
 		return -EINVAL;
-	} else if (ec->tx_coalesce_usecs == 0) {
-		if (ec->use_adaptive_tx_coalesce)
-			netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
-	} else if ((ec->tx_coalesce_usecs < IAVF_MIN_ITR) ||
-		   (ec->tx_coalesce_usecs > IAVF_MAX_ITR)) {
+	} else if (ec->tx_coalesce_usecs > IAVF_MAX_ITR) {
 		netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
 		return -EINVAL;
 	}
diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.h b/drivers/net/ethernet/intel/iavf/iavf_txrx.h
index 7e6ee32d19b6..10ba36602c0c 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_txrx.h
+++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.h
@@ -15,7 +15,6 @@ 
  */
 #define IAVF_ITR_DYNAMIC	0x8000	/* use top bit as a flag */
 #define IAVF_ITR_MASK		0x1FFE	/* mask for ITR register value */
-#define IAVF_MIN_ITR		     2	/* reg uses 2 usec resolution */
 #define IAVF_ITR_100K		    10	/* all values below must be even */
 #define IAVF_ITR_50K		    20
 #define IAVF_ITR_20K		    50