Skip to contentSkip to conversation

tsnep: Fixes based on napi.rst

PATCH Applied Gerhard Engleder 2 participants 5 messages Sep 15, 2023 – Sep 18, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tsnep: Fixes based on napi.rst

Based on the documentation networking/napi.rst some fixes have been done. tsnep driver should be in line with this new documentation after these fixes.

Gerhard Engleder (3):
tsnep: Fix NAPI scheduling
tsnep: Fix ethtool channels
tsnep: Fix NAPI polling with budget 0

 drivers/net/ethernet/engleder/tsnep_ethtool.c |  6 ++----
 drivers/net/ethernet/engleder/tsnep_main.c    | 18 ++++++++++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 tsnep: Fix NAPI scheduling

According to the NAPI documentation networking/napi.rst, drivers which have to mask interrupts explicitly should use the napi_schedule_prep() and __napi_schedule() calls.

No problem seen so far with current implementation. Nevertheless, let's align the implementation with documentation.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +10 -4
index f61bd89734c5..0cdf0de555ed 100644
@@ -87,8 +87,11 @@ static irqreturn_t tsnep_irq(int irq, void *arg)
 
 	/* handle TX/RX queue 0 interrupt */
 	if ((active & adapter->queue[0].irq_mask) != 0) {
-		tsnep_disable_irq(adapter, adapter->queue[0].irq_mask);
-		napi_schedule(&adapter->queue[0].napi);
+		if (napi_schedule_prep(&adapter->queue[0].napi)) {
+			tsnep_disable_irq(adapter, adapter->queue[0].irq_mask);
+			/* schedule after masking to avoid races */
+			__napi_schedule(&adapter->queue[0].napi);
+		}
 	}
 
 	return IRQ_HANDLED;
@@ -99,8 +102,11 @@ static irqreturn_t tsnep_irq_txrx(int irq, void *arg)
 	struct tsnep_queue *queue = arg;
 
 	/* handle TX/RX queue interrupt */
-	tsnep_disable_irq(queue->adapter, queue->irq_mask);
-	napi_schedule(&queue->napi);
+	if (napi_schedule_prep(&queue->napi)) {
+		tsnep_disable_irq(queue->adapter, queue->irq_mask);
+		/* schedule after masking to avoid races */
+		__napi_schedule(&queue->napi);
+	}
 
 	return IRQ_HANDLED;
 }
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/3 tsnep: Fix ethtool channels

In reply to Gerhard Engleder

According to the NAPI documentation networking/napi.rst, for the ethtool API a channel is a IRQ/NAPI which services queues of a given type.

tsnep uses a single IRQ/NAPI instance for every TX/RX queue pair. Therefore, combined channels shall be returned instead of separate tx/rx channels.

---
 drivers/net/ethernet/engleder/tsnep_ethtool.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/engleder/tsnep_ethtool.c +2 -4
index 716815dad7d2..65ec1abc9442 100644
@@ -300,10 +300,8 @@ static void tsnep_ethtool_get_channels(struct net_device *netdev,
 {
 	struct tsnep_adapter *adapter = netdev_priv(netdev);
 
-	ch->max_rx = adapter->num_rx_queues;
-	ch->max_tx = adapter->num_tx_queues;
-	ch->rx_count = adapter->num_rx_queues;
-	ch->tx_count = adapter->num_tx_queues;
+	ch->max_combined = adapter->num_queues;
+	ch->combined_count = adapter->num_queues;
 }
 
 static int tsnep_ethtool_get_ts_info(struct net_device *netdev,
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/3 tsnep: Fix NAPI polling with budget 0

In reply to Gerhard Engleder

According to the NAPI documentation networking/napi.rst, Rx specific APIs like page pool and XDP cannot be used at all when budget is 0. skb Tx processing should happen regardless of the budget.

Stop NAPI polling after Tx processing and skip Rx processing if budget is 0.

---
 drivers/net/ethernet/engleder/tsnep_main.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/engleder/tsnep_main.c +4 -0
index 0cdf0de555ed..8b992dc9bb52 100644
@@ -1734,6 +1734,10 @@ static int tsnep_poll(struct napi_struct *napi, int budget)
 	if (queue->tx)
 		complete = tsnep_tx_poll(queue->tx, budget);
 
+	/* handle case where we are called by netpoll with a budget of 0 */
+	if (unlikely(budget <= 0))
+		return budget;
+
 	if (queue->rx) {
 		done = queue->rx->xsk_pool ?
 		       tsnep_rx_poll_zc(queue->rx, napi, budget) :
Signature · 1 line
2.30.2
#4 lore raw
In reply to Gerhard Engleder
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 10 lines · On Fri, 15 Sep 2023 23:01:23 +0200 you wrote:

Based on the documentation networking/napi.rst some fixes have been done. tsnep driver should be in line with this new documentation after these fixes.

Gerhard Engleder (3):
tsnep: Fix NAPI scheduling
tsnep: Fix ethtool channels
tsnep: Fix NAPI polling with budget 0

[...]

Here is the summary with links:
- [net,1/3] tsnep: Fix NAPI scheduling

    https://git.kernel.org/netdev/net/c/ea852c17f538
  - [net,2/3] tsnep: Fix ethtool channels
    https://git.kernel.org/netdev/net/c/a7f991953d73
  - [net,3/3] tsnep: Fix NAPI polling with budget 0
    https://git.kernel.org/netdev/net/c/46589db3817b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html