From nobody Mon Dec 15 19:06:23 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AA202FABE6; Wed, 29 Oct 2025 10:37:54 +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=1761734276; cv=none; b=jE04ehFK+GUGP/k84GXbxaXxHEirLBCsNL7l+AIoLEZHkIaoIYn/J1P67xJdJobtYESkGTzTFSh/7v1MNZpAJAr3EdRsXGUCMYK3Ey/8cIpSoGItE6Eo+InfblbQF1XH3PFzbPfBkkjEcvrcnLPr6LmOjVzydWBkC58F/Z9Dyg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761734276; c=relaxed/simple; bh=ZhhQwUyagG2vDEa/+FRNpxvMESjC5emZEAvzV3eKn1k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References; b=X+3OZBvdjHFqNQSgyvA6apcxOYgPHzv1pYn+rE2+Ee4HD1iME3eN+xsj9dNDOcpiAVXrCIeHC1AFboC9Y5JKGtlZnV9FK3vdpP09RBVfdy5VTYu9lyYJqu0QmGGNdiMXNpghtAdDOVUFRicEyPf+fau66z1+ksTWRkySTtYpW5Q= 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=lmagk+7E; 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="lmagk+7E" Received: by linux.microsoft.com (Postfix, from userid 1173) id AA2A0200FE6A; Wed, 29 Oct 2025 03:37:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AA2A0200FE6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1761734274; bh=4y92Emie4B7uMy9DvEEp5ALZbqH46Cw5IfzVbfkqWs0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lmagk+7EDpc92psjo5KI3z0XeIGOsZA1x9Wks97jDepPrp5PGi9Lk+A2sh5un3B08 PSkCjXehzruxfJqJ4Rs6RO1snm4vl9gLmvIrMW7/RhzQE23+Lx8zv3a5ElsaU4K0Pb UMkvALEliA1zT8amL1hWPFMCzpKefBfPQHo68Jeo= From: Erni Sri Satya Vennela To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, longli@microsoft.com, kotaranov@microsoft.com, horms@kernel.org, shradhagupta@linux.microsoft.com, ssengar@linux.microsoft.com, ernis@linux.microsoft.com, dipayanroy@linux.microsoft.com, shirazsaleem@microsoft.com, rosenp@gmail.com, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH net-next v2 1/2] net: mana: Refactor GF stats to use global mana_context Date: Wed, 29 Oct 2025 03:37:51 -0700 Message-Id: <1761734272-32055-2-git-send-email-ernis@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1761734272-32055-1-git-send-email-ernis@linux.microsoft.com> References: <1761734272-32055-1-git-send-email-ernis@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Refactor mana_query_gf_stats() to use mana_context instead of per-port, enabling single query for all VFs. Isolate hardware counter stats by introducing mana_ethtool_hc_stats in mana_context and update the code to ensure all stats are properly reported via ethtool -S , maintaining consistency with previous behavior. Signed-off-by: Erni Sri Satya Vennela Reviewed-by: Haiyang Zhang Reviewed-by: Shradha Gupta Reviewed-by: Dipayaan Roy --- Changes in v2: * No change. --- drivers/net/ethernet/microsoft/mana/mana_en.c | 67 ++++++++------- .../ethernet/microsoft/mana/mana_ethtool.c | 85 ++++++++++--------- include/net/mana/mana.h | 14 +-- 3 files changed, 90 insertions(+), 76 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index 0142fd98392c..009e869ef296 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -2769,11 +2769,12 @@ int mana_config_rss(struct mana_port_context *apc, = enum TRI_STATE rx, return 0; } =20 -void mana_query_gf_stats(struct mana_port_context *apc) +void mana_query_gf_stats(struct mana_context *ac) { struct mana_query_gf_stat_resp resp =3D {}; struct mana_query_gf_stat_req req =3D {}; - struct net_device *ndev =3D apc->ndev; + struct gdma_context *gc =3D ac->gdma_dev->gdma_context; + struct device *dev =3D gc->dev; int err; =20 mana_gd_init_req_hdr(&req.hdr, MANA_QUERY_GF_STAT, @@ -2807,52 +2808,52 @@ void mana_query_gf_stats(struct mana_port_context *= apc) STATISTICS_FLAGS_HC_TX_BCAST_BYTES | STATISTICS_FLAGS_TX_ERRORS_GDMA_ERROR; =20 - err =3D mana_send_request(apc->ac, &req, sizeof(req), &resp, + err =3D mana_send_request(ac, &req, sizeof(req), &resp, sizeof(resp)); if (err) { - netdev_err(ndev, "Failed to query GF stats: %d\n", err); + dev_err(dev, "Failed to query GF stats: %d\n", err); return; } err =3D mana_verify_resp_hdr(&resp.hdr, MANA_QUERY_GF_STAT, sizeof(resp)); if (err || resp.hdr.status) { - netdev_err(ndev, "Failed to query GF stats: %d, 0x%x\n", err, - resp.hdr.status); + dev_err(dev, "Failed to query GF stats: %d, 0x%x\n", err, + resp.hdr.status); return; } =20 - apc->eth_stats.hc_rx_discards_no_wqe =3D resp.rx_discards_nowqe; - apc->eth_stats.hc_rx_err_vport_disabled =3D resp.rx_err_vport_disabled; - apc->eth_stats.hc_rx_bytes =3D resp.hc_rx_bytes; - apc->eth_stats.hc_rx_ucast_pkts =3D resp.hc_rx_ucast_pkts; - apc->eth_stats.hc_rx_ucast_bytes =3D resp.hc_rx_ucast_bytes; - apc->eth_stats.hc_rx_bcast_pkts =3D resp.hc_rx_bcast_pkts; - apc->eth_stats.hc_rx_bcast_bytes =3D resp.hc_rx_bcast_bytes; - apc->eth_stats.hc_rx_mcast_pkts =3D resp.hc_rx_mcast_pkts; - apc->eth_stats.hc_rx_mcast_bytes =3D resp.hc_rx_mcast_bytes; - apc->eth_stats.hc_tx_err_gf_disabled =3D resp.tx_err_gf_disabled; - apc->eth_stats.hc_tx_err_vport_disabled =3D resp.tx_err_vport_disabled; - apc->eth_stats.hc_tx_err_inval_vportoffset_pkt =3D + ac->hc_stats.hc_rx_discards_no_wqe =3D resp.rx_discards_nowqe; + ac->hc_stats.hc_rx_err_vport_disabled =3D resp.rx_err_vport_disabled; + ac->hc_stats.hc_rx_bytes =3D resp.hc_rx_bytes; + ac->hc_stats.hc_rx_ucast_pkts =3D resp.hc_rx_ucast_pkts; + ac->hc_stats.hc_rx_ucast_bytes =3D resp.hc_rx_ucast_bytes; + ac->hc_stats.hc_rx_bcast_pkts =3D resp.hc_rx_bcast_pkts; + ac->hc_stats.hc_rx_bcast_bytes =3D resp.hc_rx_bcast_bytes; + ac->hc_stats.hc_rx_mcast_pkts =3D resp.hc_rx_mcast_pkts; + ac->hc_stats.hc_rx_mcast_bytes =3D resp.hc_rx_mcast_bytes; + ac->hc_stats.hc_tx_err_gf_disabled =3D resp.tx_err_gf_disabled; + ac->hc_stats.hc_tx_err_vport_disabled =3D resp.tx_err_vport_disabled; + ac->hc_stats.hc_tx_err_inval_vportoffset_pkt =3D resp.tx_err_inval_vport_offset_pkt; - apc->eth_stats.hc_tx_err_vlan_enforcement =3D + ac->hc_stats.hc_tx_err_vlan_enforcement =3D resp.tx_err_vlan_enforcement; - apc->eth_stats.hc_tx_err_eth_type_enforcement =3D + ac->hc_stats.hc_tx_err_eth_type_enforcement =3D resp.tx_err_ethtype_enforcement; - apc->eth_stats.hc_tx_err_sa_enforcement =3D resp.tx_err_SA_enforcement; - apc->eth_stats.hc_tx_err_sqpdid_enforcement =3D + ac->hc_stats.hc_tx_err_sa_enforcement =3D resp.tx_err_SA_enforcement; + ac->hc_stats.hc_tx_err_sqpdid_enforcement =3D resp.tx_err_SQPDID_enforcement; - apc->eth_stats.hc_tx_err_cqpdid_enforcement =3D + ac->hc_stats.hc_tx_err_cqpdid_enforcement =3D resp.tx_err_CQPDID_enforcement; - apc->eth_stats.hc_tx_err_mtu_violation =3D resp.tx_err_mtu_violation; - apc->eth_stats.hc_tx_err_inval_oob =3D resp.tx_err_inval_oob; - apc->eth_stats.hc_tx_bytes =3D resp.hc_tx_bytes; - apc->eth_stats.hc_tx_ucast_pkts =3D resp.hc_tx_ucast_pkts; - apc->eth_stats.hc_tx_ucast_bytes =3D resp.hc_tx_ucast_bytes; - apc->eth_stats.hc_tx_bcast_pkts =3D resp.hc_tx_bcast_pkts; - apc->eth_stats.hc_tx_bcast_bytes =3D resp.hc_tx_bcast_bytes; - apc->eth_stats.hc_tx_mcast_pkts =3D resp.hc_tx_mcast_pkts; - apc->eth_stats.hc_tx_mcast_bytes =3D resp.hc_tx_mcast_bytes; - apc->eth_stats.hc_tx_err_gdma =3D resp.tx_err_gdma; + ac->hc_stats.hc_tx_err_mtu_violation =3D resp.tx_err_mtu_violation; + ac->hc_stats.hc_tx_err_inval_oob =3D resp.tx_err_inval_oob; + ac->hc_stats.hc_tx_bytes =3D resp.hc_tx_bytes; + ac->hc_stats.hc_tx_ucast_pkts =3D resp.hc_tx_ucast_pkts; + ac->hc_stats.hc_tx_ucast_bytes =3D resp.hc_tx_ucast_bytes; + ac->hc_stats.hc_tx_bcast_pkts =3D resp.hc_tx_bcast_pkts; + ac->hc_stats.hc_tx_bcast_bytes =3D resp.hc_tx_bcast_bytes; + ac->hc_stats.hc_tx_mcast_pkts =3D resp.hc_tx_mcast_pkts; + ac->hc_stats.hc_tx_mcast_bytes =3D resp.hc_tx_mcast_bytes; + ac->hc_stats.hc_tx_err_gdma =3D resp.tx_err_gdma; } =20 void mana_query_phy_stats(struct mana_port_context *apc) diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/n= et/ethernet/microsoft/mana/mana_ethtool.c index a1afa75a9463..3dfd96146424 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c @@ -15,66 +15,69 @@ struct mana_stats_desc { static const struct mana_stats_desc mana_eth_stats[] =3D { {"stop_queue", offsetof(struct mana_ethtool_stats, stop_queue)}, {"wake_queue", offsetof(struct mana_ethtool_stats, wake_queue)}, - {"hc_rx_discards_no_wqe", offsetof(struct mana_ethtool_stats, + {"tx_cq_err", offsetof(struct mana_ethtool_stats, tx_cqe_err)}, + {"tx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, + tx_cqe_unknown_type)}, + {"rx_coalesced_err", offsetof(struct mana_ethtool_stats, + rx_coalesced_err)}, + {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, + rx_cqe_unknown_type)}, +}; + +static const struct mana_stats_desc mana_hc_stats[] =3D { + {"hc_rx_discards_no_wqe", offsetof(struct mana_ethtool_hc_stats, hc_rx_discards_no_wqe)}, - {"hc_rx_err_vport_disabled", offsetof(struct mana_ethtool_stats, + {"hc_rx_err_vport_disabled", offsetof(struct mana_ethtool_hc_stats, hc_rx_err_vport_disabled)}, - {"hc_rx_bytes", offsetof(struct mana_ethtool_stats, hc_rx_bytes)}, - {"hc_rx_ucast_pkts", offsetof(struct mana_ethtool_stats, + {"hc_rx_bytes", offsetof(struct mana_ethtool_hc_stats, hc_rx_bytes)}, + {"hc_rx_ucast_pkts", offsetof(struct mana_ethtool_hc_stats, hc_rx_ucast_pkts)}, - {"hc_rx_ucast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_rx_ucast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_rx_ucast_bytes)}, - {"hc_rx_bcast_pkts", offsetof(struct mana_ethtool_stats, + {"hc_rx_bcast_pkts", offsetof(struct mana_ethtool_hc_stats, hc_rx_bcast_pkts)}, - {"hc_rx_bcast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_rx_bcast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_rx_bcast_bytes)}, - {"hc_rx_mcast_pkts", offsetof(struct mana_ethtool_stats, - hc_rx_mcast_pkts)}, - {"hc_rx_mcast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_rx_mcast_pkts", offsetof(struct mana_ethtool_hc_stats, + hc_rx_mcast_pkts)}, + {"hc_rx_mcast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_rx_mcast_bytes)}, - {"hc_tx_err_gf_disabled", offsetof(struct mana_ethtool_stats, + {"hc_tx_err_gf_disabled", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_gf_disabled)}, - {"hc_tx_err_vport_disabled", offsetof(struct mana_ethtool_stats, + {"hc_tx_err_vport_disabled", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_vport_disabled)}, {"hc_tx_err_inval_vportoffset_pkt", - offsetof(struct mana_ethtool_stats, + offsetof(struct mana_ethtool_hc_stats, hc_tx_err_inval_vportoffset_pkt)}, - {"hc_tx_err_vlan_enforcement", offsetof(struct mana_ethtool_stats, + {"hc_tx_err_vlan_enforcement", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_vlan_enforcement)}, {"hc_tx_err_eth_type_enforcement", - offsetof(struct mana_ethtool_stats, hc_tx_err_eth_type_enforcement)}, - {"hc_tx_err_sa_enforcement", offsetof(struct mana_ethtool_stats, + offsetof(struct mana_ethtool_hc_stats, hc_tx_err_eth_type_enforcement)}, + {"hc_tx_err_sa_enforcement", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_sa_enforcement)}, {"hc_tx_err_sqpdid_enforcement", - offsetof(struct mana_ethtool_stats, hc_tx_err_sqpdid_enforcement)}, + offsetof(struct mana_ethtool_hc_stats, hc_tx_err_sqpdid_enforcement)}, {"hc_tx_err_cqpdid_enforcement", - offsetof(struct mana_ethtool_stats, hc_tx_err_cqpdid_enforcement)}, - {"hc_tx_err_mtu_violation", offsetof(struct mana_ethtool_stats, + offsetof(struct mana_ethtool_hc_stats, hc_tx_err_cqpdid_enforcement)}, + {"hc_tx_err_mtu_violation", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_mtu_violation)}, - {"hc_tx_err_inval_oob", offsetof(struct mana_ethtool_stats, + {"hc_tx_err_inval_oob", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_inval_oob)}, - {"hc_tx_err_gdma", offsetof(struct mana_ethtool_stats, + {"hc_tx_err_gdma", offsetof(struct mana_ethtool_hc_stats, hc_tx_err_gdma)}, - {"hc_tx_bytes", offsetof(struct mana_ethtool_stats, hc_tx_bytes)}, - {"hc_tx_ucast_pkts", offsetof(struct mana_ethtool_stats, + {"hc_tx_bytes", offsetof(struct mana_ethtool_hc_stats, hc_tx_bytes)}, + {"hc_tx_ucast_pkts", offsetof(struct mana_ethtool_hc_stats, hc_tx_ucast_pkts)}, - {"hc_tx_ucast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_tx_ucast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_tx_ucast_bytes)}, - {"hc_tx_bcast_pkts", offsetof(struct mana_ethtool_stats, + {"hc_tx_bcast_pkts", offsetof(struct mana_ethtool_hc_stats, hc_tx_bcast_pkts)}, - {"hc_tx_bcast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_tx_bcast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_tx_bcast_bytes)}, - {"hc_tx_mcast_pkts", offsetof(struct mana_ethtool_stats, + {"hc_tx_mcast_pkts", offsetof(struct mana_ethtool_hc_stats, hc_tx_mcast_pkts)}, - {"hc_tx_mcast_bytes", offsetof(struct mana_ethtool_stats, + {"hc_tx_mcast_bytes", offsetof(struct mana_ethtool_hc_stats, hc_tx_mcast_bytes)}, - {"tx_cq_err", offsetof(struct mana_ethtool_stats, tx_cqe_err)}, - {"tx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, - tx_cqe_unknown_type)}, - {"rx_coalesced_err", offsetof(struct mana_ethtool_stats, - rx_coalesced_err)}, - {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, - rx_cqe_unknown_type)}, }; =20 static const struct mana_stats_desc mana_phy_stats[] =3D { @@ -138,7 +141,7 @@ static int mana_get_sset_count(struct net_device *ndev,= int stringset) if (stringset !=3D ETH_SS_STATS) return -EINVAL; =20 - return ARRAY_SIZE(mana_eth_stats) + ARRAY_SIZE(mana_phy_stats) + + return ARRAY_SIZE(mana_eth_stats) + ARRAY_SIZE(mana_phy_stats) + ARRAY_SI= ZE(mana_hc_stats) + num_queues * (MANA_STATS_RX_COUNT + MANA_STATS_TX_COUNT); } =20 @@ -150,10 +153,12 @@ static void mana_get_strings(struct net_device *ndev,= u32 stringset, u8 *data) =20 if (stringset !=3D ETH_SS_STATS) return; - for (i =3D 0; i < ARRAY_SIZE(mana_eth_stats); i++) ethtool_puts(&data, mana_eth_stats[i].name); =20 + for (i =3D 0; i < ARRAY_SIZE(mana_hc_stats); i++) + ethtool_puts(&data, mana_hc_stats[i].name); + for (i =3D 0; i < ARRAY_SIZE(mana_phy_stats); i++) ethtool_puts(&data, mana_phy_stats[i].name); =20 @@ -186,6 +191,7 @@ static void mana_get_ethtool_stats(struct net_device *n= dev, struct mana_port_context *apc =3D netdev_priv(ndev); unsigned int num_queues =3D apc->num_queues; void *eth_stats =3D &apc->eth_stats; + void *hc_stats =3D &apc->ac->hc_stats; void *phy_stats =3D &apc->phy_stats; struct mana_stats_rx *rx_stats; struct mana_stats_tx *tx_stats; @@ -208,7 +214,7 @@ static void mana_get_ethtool_stats(struct net_device *n= dev, if (!apc->port_is_up) return; /* we call mana function to update stats from GDMA */ - mana_query_gf_stats(apc); + mana_query_gf_stats(apc->ac); =20 /* We call this mana function to get the phy stats from GDMA and includes * aggregate tx/rx drop counters, Per-TC(Traffic Channel) tx/rx and pause @@ -219,6 +225,9 @@ static void mana_get_ethtool_stats(struct net_device *n= dev, for (q =3D 0; q < ARRAY_SIZE(mana_eth_stats); q++) data[i++] =3D *(u64 *)(eth_stats + mana_eth_stats[q].offset); =20 + for (q =3D 0; q < ARRAY_SIZE(mana_hc_stats); q++) + data[i++] =3D *(u64 *)(hc_stats + mana_hc_stats[q].offset); + for (q =3D 0; q < ARRAY_SIZE(mana_phy_stats); q++) data[i++] =3D *(u64 *)(phy_stats + mana_phy_stats[q].offset); =20 diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 0921485565c0..519c4384c51f 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -375,6 +375,13 @@ struct mana_tx_qp { struct mana_ethtool_stats { u64 stop_queue; u64 wake_queue; + u64 tx_cqe_err; + u64 tx_cqe_unknown_type; + u64 rx_coalesced_err; + u64 rx_cqe_unknown_type; +}; + +struct mana_ethtool_hc_stats { u64 hc_rx_discards_no_wqe; u64 hc_rx_err_vport_disabled; u64 hc_rx_bytes; @@ -402,10 +409,6 @@ struct mana_ethtool_stats { u64 hc_tx_mcast_pkts; u64 hc_tx_mcast_bytes; u64 hc_tx_err_gdma; - u64 tx_cqe_err; - u64 tx_cqe_unknown_type; - u64 rx_coalesced_err; - u64 rx_cqe_unknown_type; }; =20 struct mana_ethtool_phy_stats { @@ -473,6 +476,7 @@ struct mana_context { u16 num_ports; u8 bm_hostmode; =20 + struct mana_ethtool_hc_stats hc_stats; struct mana_eq *eqs; struct dentry *mana_eqs_debugfs; =20 @@ -573,7 +577,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_r= xq *rxq, struct bpf_prog *mana_xdp_get(struct mana_port_context *apc); void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog); int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf); -void mana_query_gf_stats(struct mana_port_context *apc); +void mana_query_gf_stats(struct mana_context *ac); int mana_query_link_cfg(struct mana_port_context *apc); int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, int enable_clamping); --=20 2.34.1 From nobody Mon Dec 15 19:06:23 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B397330327; Wed, 29 Oct 2025 10:37:56 +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=1761734278; cv=none; b=JLxSWVMZ+lFT0BsFB9ffFJgVI7tV7gfsVikYtF+O6GevcTxKUH4nhNLBdpq+0MBowp9zh4WVAdD1hDntuHPA24Hq0llVvem5kXJ/6raT0a6eAR4+KO//eoCJbMxgpn7jiyU2pvqw0C9kmMTqX8vV2sRqxBK0/KDnC/U/Lx98/2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761734278; c=relaxed/simple; bh=h4ktVjJwrvb+bW+hTEgjMWw+BOzwEf7vjzxDc/TH23U=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References; b=qpmXbiRY0ec1uuyBury7ch3azMdtNFcDUKzcaRIJKqchvzLEBKn2TLxYv7cX9k6oP3Aag8m6ggUPtjZdZijvSQlsp9YdtnqvGoNVqAe2C4TJOVSiiZjywlxVuu6BbowzbDuj0xsBPY2fbm8cTJeiSBB7/g/YCaB7dUAbHUeJRY0= 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=oVqOBANR; 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="oVqOBANR" Received: by linux.microsoft.com (Postfix, from userid 1173) id 24176211CF97; Wed, 29 Oct 2025 03:37:56 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 24176211CF97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1761734276; bh=sFK0LEa0ZlLnJ1Tx9uM2+AFX9+Izg/RNjd0uSAEK018=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oVqOBANRtDzf05i5fW2QhJukQmI+aTusWxEvH5e5YOpwO5uoL3c7sZ0TK7UVFGiJq otpcFzKh+ILDLkzO5W/RreqrSTmytnzntEQuYi1gDXCL6GQSr4f6otjs8E2mE5RgSi Ii2BbiyKzcNN3siHsKu1nVak2RRYICcaaMeiKTNM= From: Erni Sri Satya Vennela To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, longli@microsoft.com, kotaranov@microsoft.com, horms@kernel.org, shradhagupta@linux.microsoft.com, ssengar@linux.microsoft.com, ernis@linux.microsoft.com, dipayanroy@linux.microsoft.com, shirazsaleem@microsoft.com, rosenp@gmail.com, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH net-next v2 2/2] net: mana: Add standard counter rx_missed_errors Date: Wed, 29 Oct 2025 03:37:52 -0700 Message-Id: <1761734272-32055-3-git-send-email-ernis@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1761734272-32055-1-git-send-email-ernis@linux.microsoft.com> References: <1761734272-32055-1-git-send-email-ernis@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Report standard counter stats->rx_missed_errors using hc_rx_discards_no_wqe from the hardware. Add a dedicated workqueue to periodically run mana_query_gf_stats every 2 seconds to get the latest info in eth_stats and define a driver capability flag to notify hardware of the periodic queries. To avoid repeated failures and log flooding, the workqueue is not rescheduled if mana_query_gf_stats fails on HWC timeout error and the stats are reset to 0. Other errors are transient which will not need a VF reset for recovery. Signed-off-by: Erni Sri Satya Vennela Reviewed-by: Haiyang Zhang Reviewed-by: Dipayaan Roy Reviewed-by: Shradha Gupta --- Changes in v2: * Update commit message. * Stop rescheduling workqueue only when HWC timeout is observed. * Introduce new variable in mana_context for detecting HWC timeout. * Warn once in mana_get_stat64 when HWC timeout is observed. --- drivers/net/ethernet/microsoft/mana/mana_en.c | 46 +++++++++++++++++-- .../ethernet/microsoft/mana/mana_ethtool.c | 2 - include/net/mana/gdma.h | 6 ++- include/net/mana/mana.h | 6 ++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index 009e869ef296..48df44889f05 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -494,6 +494,11 @@ static void mana_get_stats64(struct net_device *ndev, =20 netdev_stats_to_stats64(st, &ndev->stats); =20 + if (apc->ac->hwc_timeout_occurred) + netdev_warn_once(ndev, "HWC timeout occurred\n"); + + st->rx_missed_errors =3D apc->ac->hc_stats.hc_rx_discards_no_wqe; + for (q =3D 0; q < num_queues; q++) { rx_stats =3D &apc->rxqs[q]->stats; =20 @@ -2769,7 +2774,7 @@ int mana_config_rss(struct mana_port_context *apc, en= um TRI_STATE rx, return 0; } =20 -void mana_query_gf_stats(struct mana_context *ac) +int mana_query_gf_stats(struct mana_context *ac) { struct mana_query_gf_stat_resp resp =3D {}; struct mana_query_gf_stat_req req =3D {}; @@ -2812,14 +2817,14 @@ void mana_query_gf_stats(struct mana_context *ac) sizeof(resp)); if (err) { dev_err(dev, "Failed to query GF stats: %d\n", err); - return; + return err; } err =3D mana_verify_resp_hdr(&resp.hdr, MANA_QUERY_GF_STAT, sizeof(resp)); if (err || resp.hdr.status) { dev_err(dev, "Failed to query GF stats: %d, 0x%x\n", err, resp.hdr.status); - return; + return err; } =20 ac->hc_stats.hc_rx_discards_no_wqe =3D resp.rx_discards_nowqe; @@ -2854,6 +2859,8 @@ void mana_query_gf_stats(struct mana_context *ac) ac->hc_stats.hc_tx_mcast_pkts =3D resp.hc_tx_mcast_pkts; ac->hc_stats.hc_tx_mcast_bytes =3D resp.hc_tx_mcast_bytes; ac->hc_stats.hc_tx_err_gdma =3D resp.tx_err_gdma; + + return 0; } =20 void mana_query_phy_stats(struct mana_port_context *apc) @@ -3390,6 +3397,24 @@ int mana_rdma_service_event(struct gdma_context *gc,= enum gdma_service_type even return 0; } =20 +#define MANA_GF_STATS_PERIOD (2 * HZ) + +static void mana_gf_stats_work_handler(struct work_struct *work) +{ + struct mana_context *ac =3D + container_of(to_delayed_work(work), struct mana_context, gf_stats_work); + int err; + + err =3D mana_query_gf_stats(ac); + if (err =3D=3D -ETIMEDOUT) { + /* HWC timeout detected - reset stats and stop rescheduling */ + ac->hwc_timeout_occurred =3D true; + memset(&ac->hc_stats, 0, sizeof(ac->hc_stats)); + return; + } + queue_delayed_work(ac->gf_stats_wq, &ac->gf_stats_work, MANA_GF_STATS_PER= IOD); +} + int mana_probe(struct gdma_dev *gd, bool resuming) { struct gdma_context *gc =3D gd->gdma_context; @@ -3478,6 +3503,15 @@ int mana_probe(struct gdma_dev *gd, bool resuming) } =20 err =3D add_adev(gd, "eth"); + ac->gf_stats_wq =3D create_singlethread_workqueue("mana_gf_stats"); + if (!ac->gf_stats_wq) { + err =3D -ENOMEM; + goto out; + } + + INIT_DELAYED_WORK(&ac->gf_stats_work, mana_gf_stats_work_handler); + queue_delayed_work(ac->gf_stats_wq, &ac->gf_stats_work, MANA_GF_STATS_PER= IOD); + out: if (err) { mana_remove(gd, false); @@ -3501,6 +3535,12 @@ void mana_remove(struct gdma_dev *gd, bool suspendin= g) int err; int i; =20 + if (ac->gf_stats_wq) { + cancel_delayed_work_sync(&ac->gf_stats_work); + destroy_workqueue(ac->gf_stats_wq); + ac->gf_stats_wq =3D NULL; + } + /* adev currently doesn't support suspending, always remove it */ if (gd->adev) remove_adev(gd); diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/n= et/ethernet/microsoft/mana/mana_ethtool.c index 3dfd96146424..99e811208683 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c @@ -213,8 +213,6 @@ static void mana_get_ethtool_stats(struct net_device *n= dev, =20 if (!apc->port_is_up) return; - /* we call mana function to update stats from GDMA */ - mana_query_gf_stats(apc->ac); =20 /* We call this mana function to get the phy stats from GDMA and includes * aggregate tx/rx drop counters, Per-TC(Traffic Channel) tx/rx and pause diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 57df78cfbf82..88a81fb164a0 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -591,6 +591,9 @@ enum { /* Driver can self reset on FPGA Reconfig EQE notification */ #define GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE BIT(17) =20 +/* Driver can send HWC periodically to query stats */ +#define GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY BIT(21) + #define GDMA_DRV_CAP_FLAGS1 \ (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \ @@ -599,7 +602,8 @@ enum { GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP | \ GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT | \ GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \ - GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE) + GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \ + GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY) =20 #define GDMA_DRV_CAP_FLAGS2 0 =20 diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 519c4384c51f..79532490cee6 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -480,6 +480,10 @@ struct mana_context { struct mana_eq *eqs; struct dentry *mana_eqs_debugfs; =20 + struct workqueue_struct *gf_stats_wq; + struct delayed_work gf_stats_work; + bool hwc_timeout_occurred; + struct net_device *ports[MAX_PORTS_IN_MANA_DEV]; }; =20 @@ -577,7 +581,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_r= xq *rxq, struct bpf_prog *mana_xdp_get(struct mana_port_context *apc); void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog); int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf); -void mana_query_gf_stats(struct mana_context *ac); +int mana_query_gf_stats(struct mana_context *ac); int mana_query_link_cfg(struct mana_port_context *apc); int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, int enable_clamping); --=20 2.34.1