All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mingming Cao <mmc@linux.ibm.com>
To: netdev@vger.kernel.org
Cc: Mingming Cao <mmc@linux.ibm.com>,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	nnac123@linux.ibm.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, linuxppc-dev@lists.ozlabs.org,
	horms@kernel.org, davemarq@linux.ibm.com, haren@linux.ibm.com,
	ricklind@linux.ibm.com, bjking1@linux.ibm.com,
	shaik.abdulla1@ibm.com
Subject: [PATCH net-next v2 5/8] ibmveth: Refactor TX resource allocation in open/close paths
Date: Sun, 22 Nov 2026 23:51:33 -0800	[thread overview]
Message-ID: <20261123075136.3278-6-mmc@linux.ibm.com> (raw)
In-Reply-To: <20261123075136.3278-1-mmc@linux.ibm.com>

Move TX LTB allocation and free out of open() and close() into
ibmveth_alloc_tx_resources() and ibmveth_free_tx_resources(), like
the RX helpers. alloc_tx_resources() frees its own partial
allocation, so open() no longer unwinds TX with a loop index shared
with the allocation.

open() still maps the TX LTBs before any RX buffer goes to PHYP:
under CMO both draw on the same IO entitlement, and a failed RX
mapping only skips that buffer while a failed TX mapping fails
open(). It now starts TX under netif_tx_lock_bh() so a sender that
sees DRV_XOFF clear after close() also sees the new LTBs.

Signed-off-by: Mingming Cao <mmc@linux.ibm.com>
---
Changes in v2:
- map TX LTBs before RX buffers go to PHYP again; v1 moved them after
  RX bring-up (Sashiko)
- drop the netif_tx_disable() at the top of open(); close() frees TX
  last again

 drivers/net/ethernet/ibm/ibmveth.c | 68 +++++++++++++++++++++++++-----
 1 file changed, 57 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index ea0e5158040c..06741a6756b8 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1052,6 +1052,48 @@ static int ibmveth_allocate_tx_ltb(struct ibmveth_adapter *adapter, int idx)
 	return 0;
 }
 
+/**
+ * ibmveth_alloc_tx_resources - Allocate TX LTBs for real_num_tx_queues
+ * @adapter: ibmveth adapter structure
+ *
+ * Allocate a TX long-term buffer for each live TX queue. On a
+ * partial failure this helper already frees what it allocated.
+ *
+ * Return: 0 on success, -ENOMEM on failure
+ */
+static int ibmveth_alloc_tx_resources(struct ibmveth_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	int i;
+
+	for (i = 0; i < netdev->real_num_tx_queues; i++) {
+		if (ibmveth_allocate_tx_ltb(adapter, i))
+			goto err_free_ltbs;
+	}
+
+	return 0;
+
+err_free_ltbs:
+	while (--i >= 0)
+		ibmveth_free_tx_ltb(adapter, i);
+	return -ENOMEM;
+}
+
+/**
+ * ibmveth_free_tx_resources - Free TX LTBs for real_num_tx_queues
+ * @adapter: ibmveth adapter structure
+ *
+ * Free the TX long-term buffers for each live TX queue.
+ */
+static void ibmveth_free_tx_resources(struct ibmveth_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	int i;
+
+	for (i = 0; i < netdev->real_num_tx_queues; i++)
+		ibmveth_free_tx_ltb(adapter, i);
+}
+
 static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
         union ibmveth_buf_desc rxq_desc, u64 mac_address)
 {
@@ -1102,11 +1144,13 @@ static int ibmveth_open(struct net_device *netdev)
 	if (rc)
 		goto out_free_filter_list;
 
-	rc = -ENOMEM;
-	for (i = 0; i < netdev->real_num_tx_queues; i++) {
-		if (ibmveth_allocate_tx_ltb(adapter, i))
-			goto out_free_tx_ltb;
-	}
+	/* Map the TX LTBs before RX buffers go to PHYP: under CMO they
+	 * draw on the same IO entitlement, and only RX copes with a
+	 * failed mapping.
+	 */
+	rc = ibmveth_alloc_tx_resources(adapter);
+	if (rc)
+		goto out_free_queue_mem;
 
 	mac_address = ether_addr_to_u64(netdev->dev_addr);
 
@@ -1147,7 +1191,12 @@ static int ibmveth_open(struct net_device *netdev)
 	netdev_dbg(netdev, "initial replenish cycle\n");
 	ibmveth_schedule_rx_queue(adapter, 0);
 
+	/* netif_tx_lock() takes each txq lock, so a sender that then sees
+	 * DRV_XOFF clear under its txq lock also sees the LTBs set up above.
+	 */
+	netif_tx_lock_bh(netdev);
 	netif_tx_start_all_queues(netdev);
+	netif_tx_unlock_bh(netdev);
 
 	adapter->opened = true;
 	netdev_dbg(netdev, "open complete\n");
@@ -1160,8 +1209,8 @@ static int ibmveth_open(struct net_device *netdev)
 	} while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
 	ibmveth_free_buffer_pools(adapter);
 out_free_tx_ltb:
-	for (i = netdev->real_num_tx_queues - 1; i >= 0; i--)
-		ibmveth_free_tx_ltb(adapter, i);
+	ibmveth_free_tx_resources(adapter);
+out_free_queue_mem:
 	ibmveth_cleanup_rx_resources(adapter);
 out_free_filter_list:
 	ibmveth_free_filter_list(adapter);
@@ -1173,7 +1222,6 @@ static int ibmveth_close(struct net_device *netdev)
 {
 	struct ibmveth_adapter *adapter = netdev_priv(netdev);
 	long lpar_rc;
-	int i;
 
 	/* change_mtu, pool sysfs, set_csum and set_tso call close() and
 	 * open() directly. If that open() fails, IFF_UP stays set and
@@ -1201,9 +1249,7 @@ static int ibmveth_close(struct net_device *netdev)
 	ibmveth_free_buffer_pools(adapter);
 	ibmveth_cleanup_rx_resources(adapter);
 	ibmveth_free_filter_list(adapter);
-
-	for (i = 0; i < netdev->real_num_tx_queues; i++)
-		ibmveth_free_tx_ltb(adapter, i);
+	ibmveth_free_tx_resources(adapter);
 
 	netdev_dbg(netdev, "close complete\n");
 
-- 
2.50.1 (Apple Git-155)


  parent reply	other threads:[~2026-11-23  7:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  7:51 [PATCH net-next v2 0/8] ibmveth: prepare the RX path for multi-queue Mingming Cao
2026-11-23  7:51 ` [PATCH net-next v2 1/8] ibmveth: Prepare MQ RX adapter data structures Mingming Cao
2026-11-23  7:51 ` [PATCH net-next v2 2/8] ibmveth: Refactor RX resource allocation for MQ RX bring-up Mingming Cao
2026-11-23  7:51 ` [PATCH net-next v2 3/8] ibmveth: Refactor buffer pool management for per-queue MQ RX Mingming Cao
2026-11-24  8:54   ` netdev-bot+sashiko
2026-11-24 19:10     ` mingming cao
2026-11-23  7:51 ` [PATCH net-next v2 4/8] ibmveth: Refactor RX interrupt control for MQ RX queues Mingming Cao
2026-11-23  7:51 ` Mingming Cao [this message]
2026-11-24  8:54   ` [PATCH net-next v2 5/8] ibmveth: Refactor TX resource allocation in open/close paths netdev-bot+sashiko
2026-11-24 19:15     ` mingming cao
2026-11-23  7:51 ` [PATCH net-next v2 6/8] ibmveth: Add RX queue register helpers for MQ Mingming Cao
2026-11-23  7:51 ` [PATCH net-next v2 7/8] ibmveth: Pass the RX queue index through replenish and poll Mingming Cao
2026-11-23  7:51 ` [PATCH net-next v2 8/8] ibmveth: Split RX poll into per-slot helpers for MQ Mingming Cao
2026-12-01  3:00 ` [PATCH net-next v2 0/8] ibmveth: prepare the RX path for multi-queue patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123075136.3278-6-mmc@linux.ibm.com \
    --to=mmc@linux.ibm.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bjking1@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=davem@davemloft.net \
    --cc=davemarq@linux.ibm.com \
    --cc=edumazet@kernel.org \
    --cc=haren@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=nnac123@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=ricklind@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=shaik.abdulla1@ibm.com \
    --cc=sshegde@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.