diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 510d9d80e2df..3ced6f5bad2d 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -3687,15 +3687,32 @@ static void ibmveth_get_channels(struct net_device *netdev,
struct ethtool_channels *channels)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
+ unsigned int rx_count = ibmveth_get_num_rx_queues(adapter);
- channels->max_tx = ibmveth_real_max_tx_queues();
channels->tx_count = netdev->real_num_tx_queues;
+ /*
+ * Never advertise max_tx below the live count. After CPU
+ * offline, real_max can drop below real_num_tx_queues;
+ * ethtool -L is read-modify-write and the core rejects
+ * tx_count > max_tx, which would also block an RX-only
+ * request. set_channels uses this same ceiling.
+ */
+ channels->max_tx = max_t(unsigned int, channels->tx_count,
+ ibmveth_real_max_tx_queues());
- channels->rx_count = ibmveth_get_num_rx_queues(adapter);
+ /*
+ * Always report the live RX count. ethtool -L is read-modify-
+ * write, so a TX-only request echoes rx_count back at us; an
+ * understated value would be applied as a silent RX shrink.
+ * mq_fallback instead caps max_rx at the live count, which
+ * blocks growth in the core without misreporting what is
+ * currently configured.
+ */
+ channels->rx_count = rx_count;
if (adapter->multi_queue && !READ_ONCE(adapter->mq_fallback))
channels->max_rx = IBMVETH_MAX_RX_QUEUES;
else
- channels->max_rx = channels->rx_count;
+ channels->max_rx = rx_count;
}
/**@@ -3704,9 +3721,9 @@ static void ibmveth_get_channels(struct net_device *netdev,
* @goal_rx: requested RX queue count
*
* Rejects rx > 1 without MQ firmware (-EOPNOTSUPP) and rx outside
- * 1..IBMVETH_MAX_RX_QUEUES (-EINVAL). An RX count change while the
- * device is down is rejected (-EOPNOTSUPP); publishing it without
- * allocating arrives in the next patch. When up, apply via
+ * 1..IBMVETH_MAX_RX_QUEUES (-EINVAL). While down, return 0 here;
+ * ibmveth_set_channels() publishes the desired counts without
+ * allocating. When up, apply via
* ibmveth_resize_rx_queues_incremental().
*
* Return: 0 or negative errno
@@ -3750,14 +3767,9 @@ static int ibmveth_resize_rx_channels(struct ibmveth_adapter *adapter,
return -EOPNOTSUPP;
}
- /*
- * Down / failed-open: there is nothing to resize, and publishing
- * the desired count without allocating arrives in the next
- * patch. Refuse rather than report success for a request that
- * would be discarded.
- */
+ /* Down / failed-open: do not allocate. */
if (!adapter->opened)
- return -EOPNOTSUPP;
+ return 0;
rxq_entries = adapter->rx_queue[0].num_slots;
rc = ibmveth_resize_rx_queues_incremental(adapter, goal_rx,
@@ -3771,30 +3783,84 @@ static int ibmveth_set_channels(struct net_device *netdev,
struct ethtool_channels *channels)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
- unsigned int old = netdev->real_num_tx_queues,
- goal = channels->tx_count;
unsigned int old_rx = ibmveth_get_num_rx_queues(adapter);
- unsigned int want_tx = goal;
+ unsigned int goal_rx = channels->rx_count;
+ unsigned int old_tx = netdev->real_num_tx_queues;
+ unsigned int goal_tx = channels->tx_count;
+ unsigned int want_tx = goal_tx;
+ unsigned int max_tx;
bool rx_changed = false;
int rc, i, alloc_rc = 0;
- /* Validate RX (and resize when opened) before the down-path
- * early return so MQ/range errors are reported here. Publishing
- * the desired RX count and CMO while down is the next patch.
+ /*
+ * Same ceiling get_channels reports: live count or the
+ * online-CPU cap, whichever is larger.
*/
- rc = ibmveth_resize_rx_channels(adapter, channels->rx_count);
+ max_tx = max_t(unsigned int, old_tx,
+ ibmveth_real_max_tx_queues());
+ if (goal_tx < 1 || goal_tx > max_tx) {
+ netdev_err(netdev,
+ "Invalid TX queue count %u (must be 1-%u)\n",
+ goal_tx, max_tx);
+ return -EINVAL;
+ }
+
+ /* RX range / MQ checks live in ibmveth_resize_rx_channels(). */
+ rc = ibmveth_resize_rx_channels(adapter, goal_rx);
if (rc)
return rc;
- if (channels->rx_count != old_rx)
+ /* If not opened (never opened, close+open failed while IFF_UP
+ * stayed set, or close() kept the LAN memory after a failed
+ * H_FREE_LOGICAL_LAN), publish desired queue counts without
+ * allocating.
+ */
+ if (!adapter->opened) {
+ if (goal_rx > old_rx) {
+ for (i = old_rx; i < goal_rx; i++) {
+ if (adapter->queue_registered[i]) {
+ netdev_err(netdev,
+ "RX queue %d still held by PHYP, free retried on next open\n",
+ i);
+ return -EBUSY;
+ }
+ }
+ }
+ /* Apply TX first so a failure leaves the published RX
+ * count unchanged.
+ */
+ rc = netif_set_real_num_tx_queues(netdev, goal_tx);
+ if (rc)
+ return rc;
+
+ /* Publish desired RX count for next open() and refresh CMO;
+ * do not allocate while down.
+ */
+ if (goal_rx != ibmveth_get_num_rx_queues(adapter)) {
+ ibmveth_publish_num_rx_queues(adapter, goal_rx);
+ rc = netif_set_real_num_rx_queues(netdev, goal_rx);
+ if (rc) {
+ int tx_rc;
+
+ ibmveth_publish_num_rx_queues(adapter, old_rx);
+ tx_rc = netif_set_real_num_tx_queues(netdev,
+ old_tx);
+ if (tx_rc)
+ netdev_err(netdev,
+ "Failed to restore TX queues to %u after RX failure: %d\n",
+ old_tx, tx_rc);
+ return rc;
+ }
+ ibmveth_refresh_cmo_desired(adapter);
+ }
+ return 0;
+ }
+
+ if (goal_rx != old_rx)
rx_changed = true;
- /* If the device is not open (including a failed close/open with
- * IFF_UP still set) then don't allocate, just set desired
- * netdev_queue's and return
- */
- if (!adapter->opened)
- return netif_set_real_num_tx_queues(netdev, goal);
+ if (goal_tx == old_tx)
+ return 0;
/* We have IBMVETH_MAX_QUEUES netdev_queue's allocated
* but we may need to alloc/free the ltb's.@@ -3802,7 +3868,7 @@ static int ibmveth_set_channels(struct net_device *netdev,
netif_tx_stop_all_queues(netdev);
/* Allocate any queue that we need */
- for (i = old; i < goal; i++) {
+ for (i = old_tx; i < goal_tx; i++) {
if (adapter->tx_ltb_ptr[i])
continue;
@@ -3811,24 +3877,24 @@ static int ibmveth_set_channels(struct net_device *netdev,
continue;
/* if something goes wrong, free everything we just allocated */
- netdev_err(netdev, "Failed to allocate more tx queues, returning to %d queues\n",
- old);
+ netdev_err(netdev, "Failed to allocate more tx queues, returning to %u queues\n",
+ old_tx);
alloc_rc = rc;
- goal = old;
- old = i;
+ goal_tx = old_tx;
+ old_tx = i;
break;
}
- rc = netif_set_real_num_tx_queues(netdev, goal);
+ rc = netif_set_real_num_tx_queues(netdev, goal_tx);
if (rc) {
- netdev_err(netdev, "Failed to set real tx queues, returning to %d queues\n",
- old);
- goal = old;
- old = i;
+ netdev_err(netdev, "Failed to set real tx queues, returning to %u queues\n",
+ old_tx);
+ goal_tx = old_tx;
+ old_tx = i;
} else if (alloc_rc) {
rc = alloc_rc;
}
/* Free any that are no longer needed */
- for (i = old; i > goal; i--) {
+ for (i = old_tx; i > goal_tx; i--) {
if (adapter->tx_ltb_ptr[i - 1])
ibmveth_free_tx_ltb(adapter, i - 1);
}@@ -3857,7 +3923,7 @@ static int ibmveth_set_channels(struct net_device *netdev,
return rc ? rc : -ENOMEM;
}
- return rc;
+ return 0;
}
static const struct ethtool_ops netdev_ethtool_ops = {--
2.50.1 (Apple Git-155)