From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 055553AFD19; Sat, 6 Jun 2026 13:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752803; cv=none; b=L4xi+v2sN0uExZ2SGlQWr0va8fy49+8V6j4Z0jmDSmNV1bJZX08oNc6HUwn8COzWAe2oamenzKQb/naHJ2+2jg5xqjZn40FGtcBKocwRDAEw5dBPIsnb2Lp7qHhYzhprUUKDE9qlV0MttZkpJX5Gjig722TJiwelzofJjX1DdXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752803; c=relaxed/simple; bh=DYHMfQyR2sTnIYoQ4BwT3L1UOEBgVV1FnGPDeBIplG8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cTjGZmbM06Hsc6RWo99s7aq3/ynRKny4fn9dEtdjPWvAU/Ske1YJ+Ezc/JX/SDBhXeXe+zF9ih0X85TXXgBuu+3AkxQzAaUQvD78BVLxJqixnvN0vF+6hWv8aTVrUV2aHHUjjIELq7f6jrTnD6F4PuiQrs4jtBchTJeJwaWzM2M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=C2IFoxsj; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="C2IFoxsj" Received: by linux.microsoft.com (Postfix, from userid 1173) id 0F3F520B716A; Sat, 6 Jun 2026 06:33:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0F3F520B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1780752786; bh=RJDiIch2cS/p2BsBvB6NuI4AyVbSC79DD0GQWUtLgBo=; h=From:To:Subject:Date:From; b=C2IFoxsjLhXvm5maLlS+rXeqNA37LjgJ/raoIhs1RBrZEtLm61NNVSAku/Xfan30/ GVeax45NzOLWC+7xcFluh80kt/a83y5nDaR/qor9ggucsmSAY5vTBHLnxyIfmjNwSB R3zs5mGMPRL/JTo+S4G24BMKDEKnZTY3/fnBgh+c= From: Erni Sri Satya Vennela To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kotaranov@microsoft.com, horms@kernel.org, ernis@linux.microsoft.com, dipayanroy@linux.microsoft.com, kees@kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH net-next v2] net: mana: Cache MANA_QUERY_LINK_CONFIG result to avoid repeated HWC queries Date: Sat, 6 Jun 2026 06:32:55 -0700 Message-ID: <20260606133301.2180073-1-ernis@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit mana_query_link_cfg() sends an HWC command to firmware on every call, but the link speed and QoS values it returns only change when the driver explicitly calls mana_set_bw_clamp(). This function is called not only by userspace via ethtool get_link_ksettings, but also periodically by hv_netvsc through netvsc_get_link_ksettings and by the sysfs speed_show attribute via dev_attr_show, resulting in unnecessary HWC traffic every few minutes. Add a link_cfg_error field to mana_port_context to cache the query result. The field uses three states: 1 (not yet queried, initial value set during mana_probe_port), 0 (success, speed/max_speed are valid), or a negative errno for permanent errors like -EOPNOTSUPP when the hardware does not support the command. Transient errors and qos_unconfigured responses are not cached so that subsequent calls will retry. MANA is ops-locked because it implements net_shaper_ops, so the core already takes netdev_lock() around all ethtool_ops and net_shaper_ops entry points. Reuse that lock to serialize mana_query_link_cfg() and mana_set_bw_clamp(). This prevents a concurrent mana_set_bw_clamp() from racing with an in-flight query and publishing stale pre-clamp speed/max_speed. Invalidate the cache inside mana_set_bw_clamp() on success, so all current and future callers that change the link configuration automatically trigger a fresh query on the next mana_query_link_cfg() call. Also reset link_cfg_error during resume in mana_probe() under netdev_lock(), so that any query already in flight cannot later store 0 and silently overwrite the post-resume invalidation. Signed-off-by: Erni Sri Satya Vennela --- Changes in v2: * Use netdev_lock() instead of introducing new per-port mutex. * Update commit message. --- drivers/net/ethernet/microsoft/mana/mana_en.c | 23 +++++++++++++++---- include/net/mana/mana.h | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index db14357d3732..af2517a27aad 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -1456,6 +1456,12 @@ int mana_query_link_cfg(struct mana_port_context *apc) struct mana_query_link_config_req req = {}; int err; + netdev_assert_locked(ndev); + + err = apc->link_cfg_error; + if (err <= 0) + return err; + mana_gd_init_req_hdr(&req.hdr, MANA_QUERY_LINK_CONFIG, sizeof(req), sizeof(resp)); @@ -1468,6 +1474,7 @@ int mana_query_link_cfg(struct mana_port_context *apc) if (err) { if (err == -EOPNOTSUPP) { netdev_info_once(ndev, "MANA_QUERY_LINK_CONFIG not supported\n"); + apc->link_cfg_error = err; return err; } netdev_err(ndev, "Failed to query link config: %d\n", err); @@ -1485,12 +1492,12 @@ int mana_query_link_cfg(struct mana_port_context *apc) return err; } - if (resp.qos_unconfigured) { - err = -EINVAL; - return err; - } + if (resp.qos_unconfigured) + return -EINVAL; + apc->speed = resp.link_speed_mbps; apc->max_speed = resp.qos_speed_mbps; + apc->link_cfg_error = 0; return 0; } @@ -1502,6 +1509,8 @@ int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, struct net_device *ndev = apc->ndev; int err; + netdev_assert_locked(ndev); + mana_gd_init_req_hdr(&req.hdr, MANA_SET_BW_CLAMP, sizeof(req), sizeof(resp)); req.vport = apc->port_handle; @@ -1535,6 +1544,8 @@ int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, if (resp.qos_unconfigured) netdev_info(ndev, "QoS is unconfigured\n"); + /* Invalidate the cache; next query will re-fetch from firmware. */ + apc->link_cfg_error = 1; return 0; } @@ -3448,6 +3459,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, apc->port_handle = INVALID_MANA_HANDLE; apc->pf_filter_handle = INVALID_MANA_HANDLE; apc->port_idx = port_idx; + apc->link_cfg_error = 1; apc->cqe_coalescing_enable = 0; mutex_init(&apc->vport_mutex); @@ -3768,6 +3780,9 @@ int mana_probe(struct gdma_dev *gd, bool resuming) rtnl_lock(); apc = netdev_priv(ac->ports[i]); enable_work(&apc->queue_reset_work); + netdev_lock(ac->ports[i]); + apc->link_cfg_error = 1; + netdev_unlock(ac->ports[i]); err = mana_attach(ac->ports[i]); rtnl_unlock(); /* Log the port for which the attach failed, stop diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index d9c27310fd04..2a45ff7211ef 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -555,6 +555,10 @@ struct mana_port_context { u32 speed; /* Maximum speed supported by the SKU (mbps) */ u32 max_speed; + /* 1 = not queried, 0 = cached success, negative = permanent error. + * Protected by the netdev instance lock. + */ + int link_cfg_error; bool port_is_up; bool port_st_save; /* Saved port state */ -- 2.34.1