net: mana: Cache MANA_QUERY_LINK_CONFIG result to avoid repeated HWC queries

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 <ernis@linux.microsoft.com>
Link: https://patch.msgid.link/20260606133301.2180073-1-ernis@linux.microsoft.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Erni Sri Satya Vennela 2026-06-06 06:32:55 -07:00 committed by Jakub Kicinski
parent ea07514700
commit 8e0ffcc926
2 changed files with 23 additions and 4 deletions

View File

@ -1473,6 +1473,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));
@ -1485,6 +1491,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);
@ -1502,12 +1509,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;
}
@ -1519,6 +1526,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;
@ -1552,6 +1561,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;
}
@ -3518,6 +3529,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);
@ -3834,6 +3846,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

View File

@ -562,6 +562,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 */