public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Koichiro Den <den@valinux.co.jp>
Cc: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
	Allen Hubbe <allenbh@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	ntb@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] net: ntb_netdev: Support ethtool channels for multi-queue
Date: Wed, 4 Mar 2026 17:19:30 -0800	[thread overview]
Message-ID: <20260304171930.5c3625eb@kernel.org> (raw)
In-Reply-To: <20260228145538.3955864-5-den@valinux.co.jp>

On Sat, 28 Feb 2026 23:55:38 +0900 Koichiro Den wrote:
> +static const struct ntb_queue_handlers ntb_netdev_handlers;

can we move some code around to avoid this forward declaration?

> +static int ntb_set_channels(struct net_device *ndev,
> +			    struct ethtool_channels *channels)
> +{
> +	struct ntb_netdev *dev = netdev_priv(ndev);
> +	unsigned int new = channels->combined_count;
> +	unsigned int old = dev->num_queues;
> +	bool running = netif_running(ndev);
> +	struct ntb_netdev_queue *queue;
> +	unsigned int q, created;
> +	int rc = 0;
> +
> +	if (channels->rx_count || channels->tx_count || channels->other_count)
> +		return -EINVAL;

Pretty sure core will protect from this since your get will return 0
for corresponding max values

> +	if (!new || new > ndev->num_tx_queues)
> +		return -ERANGE;

same, core should protect against this

> +	if (new == old)
> +		return 0;
> +
> +	if (new < old) {
> +		if (running)
> +			for (q = new; q < old; q++)
> +				netif_stop_subqueue(ndev, q);
> +
> +		rc = netif_set_real_num_queues(ndev, new, new);
> +		if (rc)
> +			goto out_restore;
> +
> +		/* Publish new queue count before invalidating QP pointers */
> +		dev->num_queues = new;
> +
> +		for (q = new; q < old; q++) {
> +			queue = &dev->queues[q];
> +
> +			if (running) {
> +				ntb_transport_link_down(queue->qp);
> +				ntb_netdev_queue_rx_drain(queue);
> +				timer_delete_sync(&queue->tx_timer);
> +			}
> +
> +			ntb_transport_free_queue(queue->qp);
> +			queue->qp = NULL;
> +		}
> +
> +		goto out_restore;
> +	}
> +
> +	created = old;
> +	for (q = old; q < new; q++) {
> +		queue = &dev->queues[q];
> +
> +		queue->ntdev = dev;
> +		queue->qid = q;
> +		queue->qp = ntb_transport_create_queue(queue, dev->client_dev,
> +						       &ntb_netdev_handlers);
> +		if (!queue->qp) {
> +			rc = -ENOSPC;
> +			goto err_new;
> +		}
> +		created++;
> +
> +		if (!running)
> +			continue;
> +
> +		timer_setup(&queue->tx_timer, ntb_netdev_tx_timer, 0);
> +
> +		rc = ntb_netdev_queue_rx_fill(ndev, queue);
> +		if (rc)
> +			goto err_new;
> +
> +		/*
> +		 * Carrier may already be on due to other QPs. Keep the new
> +		 * subqueue stopped until we get a Link Up event for this QP.
> +		 */
> +		netif_stop_subqueue(ndev, q);
> +	}
> +
> +	rc = netif_set_real_num_queues(ndev, new, new);
> +	if (rc)
> +		goto err_new;
> +
> +	dev->num_queues = new;
> +
> +	if (running)
> +		for (q = old; q < new; q++)
> +			ntb_transport_link_up(dev->queues[q].qp);
> +
> +	return 0;
> +
> +err_new:
> +	if (running) {
> +		unsigned int rollback = created;
> +
> +		while (rollback-- > old) {
> +			queue = &dev->queues[rollback];
> +			ntb_transport_link_down(queue->qp);
> +			ntb_netdev_queue_rx_drain(queue);
> +			timer_delete_sync(&queue->tx_timer);
> +		}
> +	}
> +
> +	while (created-- > old) {
> +		queue = &dev->queues[created];
> +		ntb_transport_free_queue(queue->qp);
> +		queue->qp = NULL;
> +	}
> +
> +out_restore:
> +	if (running) {
> +		ntb_netdev_sync_subqueues(dev);
> +		ntb_netdev_update_carrier(dev);
> +	}
> +	return rc;
> +}

The logic LGTM, but the function is a little long.
Would it be possible to split it up?

  reply	other threads:[~2026-03-05  1:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 14:55 [PATCH v2 0/4] net: ntb_netdev: Add Multi-queue support Koichiro Den
2026-02-28 14:55 ` [PATCH v2 1/4] net: ntb_netdev: Introduce per-queue context Koichiro Den
2026-03-05  1:13   ` Jakub Kicinski
2026-03-05 13:56     ` Koichiro Den
2026-02-28 14:55 ` [PATCH v2 2/4] net: ntb_netdev: Gate subqueue stop/wake by transport link Koichiro Den
2026-02-28 14:55 ` [PATCH v2 3/4] net: ntb_netdev: Factor out multi-queue helpers Koichiro Den
2026-02-28 14:55 ` [PATCH v2 4/4] net: ntb_netdev: Support ethtool channels for multi-queue Koichiro Den
2026-03-05  1:19   ` Jakub Kicinski [this message]
2026-03-05 13:47     ` Koichiro Den

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=20260304171930.5c3625eb@kernel.org \
    --to=kuba@kernel.org \
    --cc=allenbh@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=dave.jiang@intel.com \
    --cc=davem@davemloft.net \
    --cc=den@valinux.co.jp \
    --cc=edumazet@google.com \
    --cc=jdmason@kudzu.us \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ntb@lists.linux.dev \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox