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, willemb@google.com
Subject: [PATCH net-next v9 13/13] ibmveth: Allow changing the RX queue count
Date: Tue,  1 Dec 2026 11:02:16 -0800	[thread overview]
Message-ID: <20261201190216.62407-14-mmc@linux.ibm.com> (raw)
In-Reply-To: <20261201190216.62407-1-mmc@linux.ibm.com>

With MQ, ethtool -L still rejects RX count changes, so the count
cannot be raised for throughput or lowered to save memory. Accept 1
to 16 RX queues on MQ firmware; without MQ, max_rx stays at the
current count.

RX queues are registered with PHYP at open, so change the count as
change_mtu() does: if the device is up, close it, set the counts and
reopen it; if it is down, just set them, so the count can still be
lowered if PHYP refuses a queue at open. Traffic stops while the
device is closed. A TX-only change keeps the live path. Restore the
RX mode after the reopen, since close/open does not run
dev_set_rx_mode().

If the reopen fails, restore the old counts and reopen. If either
step fails, the device is left closed with IFF_UP still set and
whichever counts are in place, so schedule the reset work: it tries
one more open and leaves the device down if that fails too.

A queue count change is logged with the old and new counts.

Signed-off-by: Mingming Cao <mmc@linux.ibm.com>
---
 drivers/net/ethernet/ibm/ibmveth.c | 110 +++++++++++++++++++++++++----
 1 file changed, 98 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 20cb9202b7d3..87ce6bcda472 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -43,6 +43,7 @@
 
 static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
 static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
+static void ibmveth_set_multicast_list(struct net_device *netdev);
 
 static struct kobj_type ktype_veth_pool;
 
@@ -1729,7 +1730,8 @@ static int ibmveth_open(struct net_device *netdev)
 	netif_tx_unlock_bh(netdev);
 
 	adapter->opened = true;
-	netdev_dbg(netdev, "open complete\n");
+	netdev_dbg(netdev, "open complete: %u RX, %u TX queues\n",
+		   adapter->num_rx_queues, netdev->real_num_tx_queues);
 
 	return 0;
 
@@ -1752,9 +1754,10 @@ static int ibmveth_close(struct net_device *netdev)
 {
 	struct ibmveth_adapter *adapter = netdev_priv(netdev);
 
-	/* change_mtu, pool sysfs, set_csum and set_tso call close() and
-	 * open() directly. If that open() fails, IFF_UP stays set and
-	 * NAPI is disabled; a second close() would hang in napi_disable().
+	/* change_mtu, pool sysfs, set_csum, set_tso and set_channels call
+	 * close() and open() directly. If that open() fails, IFF_UP stays
+	 * set and NAPI is disabled; a second close() would hang in
+	 * napi_disable().
 	 */
 	if (!adapter->opened)
 		return 0;
@@ -2144,11 +2147,90 @@ static void ibmveth_get_ethtool_stats(struct net_device *dev,
 static void ibmveth_get_channels(struct net_device *netdev,
 				 struct ethtool_channels *channels)
 {
+	struct ibmveth_adapter *adapter = netdev_priv(netdev);
+
 	channels->max_tx = ibmveth_real_max_tx_queues();
 	channels->tx_count = netdev->real_num_tx_queues;
 
-	channels->max_rx = netdev->real_num_rx_queues;
 	channels->rx_count = netdev->real_num_rx_queues;
+	channels->max_rx = adapter->multi_queue ?
+			   IBMVETH_MAX_RX_QUEUES : channels->rx_count;
+}
+
+/* Called with the device closed: open() sizes the RX queues and the TX
+ * LTBs from these counts.
+ */
+static int ibmveth_set_queue_counts(struct net_device *netdev,
+				    unsigned int rx, unsigned int tx)
+{
+	struct ibmveth_adapter *adapter = netdev_priv(netdev);
+	unsigned int old_rx = adapter->num_rx_queues;
+	unsigned int old_tx = netdev->real_num_tx_queues;
+	int rc;
+
+	rc = netif_set_real_num_queues(netdev, tx, rx);
+	if (!rc) {
+		adapter->num_rx_queues = rx;
+		if (old_rx != rx || old_tx != tx) {
+			if (adapter->multi_queue)
+				netdev_info(netdev,
+					    "queues %08x: RX %u -> %u, TX %u -> %u\n",
+					    adapter->vdev->unit_address,
+					    old_rx, rx, old_tx, tx);
+			else if (old_tx != tx)
+				netdev_info(netdev,
+					    "queues %08x: TX %u -> %u (RX 1)\n",
+					    adapter->vdev->unit_address,
+					    old_tx, tx);
+		}
+	}
+	return rc;
+}
+
+static void ibmveth_restore_rx_mode(struct net_device *netdev)
+{
+	netif_addr_lock_bh(netdev);
+	ibmveth_set_multicast_list(netdev);
+	netif_addr_unlock_bh(netdev);
+}
+
+static int ibmveth_reopen_with_counts(struct net_device *netdev,
+				      unsigned int rx, unsigned int tx)
+{
+	struct ibmveth_adapter *adapter = netdev_priv(netdev);
+	unsigned int old_rx = adapter->num_rx_queues;
+	unsigned int old_tx = netdev->real_num_tx_queues;
+	int rc, rc2;
+
+	ibmveth_close(netdev);
+
+	rc = ibmveth_set_queue_counts(netdev, rx, tx);
+	if (!rc) {
+		rc = ibmveth_open(netdev);
+		if (!rc) {
+			ibmveth_restore_rx_mode(netdev);
+			return 0;
+		}
+		if (ibmveth_set_queue_counts(netdev, old_rx, old_tx)) {
+			netdev_err(netdev, "failed to restore %u RX / %u TX queues\n",
+				   old_rx, old_tx);
+			goto out_reset;
+		}
+	}
+
+	rc2 = ibmveth_open(netdev);
+	if (!rc2) {
+		ibmveth_restore_rx_mode(netdev);
+		return rc;
+	}
+	netdev_err(netdev, "reopen with the old queue counts failed: %d\n",
+		   rc2);
+out_reset:
+	/* Closed with IFF_UP set: the reset work closes and reopens once
+	 * more, and dev_open() leaves the device down if that fails.
+	 */
+	schedule_work(&adapter->work);
+	return rc;
 }
 
 static int ibmveth_set_channels(struct net_device *netdev,
@@ -2156,16 +2238,20 @@ static int ibmveth_set_channels(struct net_device *netdev,
 {
 	struct ibmveth_adapter *adapter = netdev_priv(netdev);
 	unsigned int old = netdev->real_num_tx_queues,
-		     goal = channels->tx_count;
+		     goal = channels->tx_count,
+		     rx = channels->rx_count;
 	int rc, i, alloc_rc = 0;
 
-	/*
-	 * RX channel resize is not supported; reject any request that
-	 * changes rx_count. Read-modify-write TX adjustments submit the
-	 * current rx_count and proceed.
+	/* A TX-only -L resubmits the current rx_count and takes the live
+	 * TX path below. An RX change closes and reopens a running device,
+	 * and applies the TX count in the same window; a closed device
+	 * just takes the new counts.
 	 */
-	if (channels->rx_count != adapter->num_rx_queues)
-		return -EOPNOTSUPP;
+	if (rx != adapter->num_rx_queues) {
+		if (adapter->opened)
+			return ibmveth_reopen_with_counts(netdev, rx, goal);
+		return ibmveth_set_queue_counts(netdev, rx, goal);
+	}
 
 	/* If the device is not open (including a failed close/open with
 	 * IFF_UP still set) then don't allocate, just set desired
-- 
2.50.1 (Apple Git-155)



      parent reply	other threads:[~2026-12-01 19:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:02 [PATCH net-next v9 00/13] ibmveth: Add multi-queue RX support Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 01/13] ibmveth: Keep a buffer pool enabled after its allocation fails Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 02/13] ibmveth: Keep TX statistics per queue Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 03/13] powerpc/pseries: Add hcall numbers for multi-queue virtual ethernet Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 04/13] ibmveth: Add RX queue handles Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 05/13] ibmveth: Register subordinate RX queues Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 06/13] ibmveth: Add subordinate RX queue interrupt control Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 07/13] ibmveth: Add the MQ RX buffer submit hypercall Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 08/13] ibmveth: Start every RX queue on open and resume Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 09/13] ibmveth: Keep RX statistics per queue Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 10/13] ibmveth: Keep rx_no_buffer across ifdown/up Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 11/13] ibmveth: Report per-queue statistics through netdev_stat_ops Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 12/13] ibmveth: Enable multi-queue RX Mingming Cao
2026-12-01 19:02 ` Mingming Cao [this message]

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=20261201190216.62407-14-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 \
    --cc=willemb@google.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.