From nobody Sun Nov 24 04:57:02 2024 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A26D216A31; Thu, 7 Nov 2024 16:09:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995754; cv=none; b=KwWsK8WshGKmb7tkOCvUOjE3Rf1lQDBkmu9kLoGLMEO53x3y/IalGkZvRaCFOZqjvVBjmrv5U6H6J1nDlaFZFx/G2rr31CEin//fFdXf/aGU9RZDjqc63lIVM0/PLGYTkXx5v88WqNAFDynOt0H2PWLyx67YMsu8qhkQLXOpJB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995754; c=relaxed/simple; bh=WtBdocasD8l/EFERPOqguZgLTv3WwrgYVBIhVHQX4Sg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RIy389O58U9VeLC2QWbb9z+XiTmBZquWpIk/Y8uHjinBovLJKWaedOkyrocdy2aQSWr+Lgomt8sSPVR/wYYrqA+YJiSe+hlDg/4OiD9BGzxDd20XBOWRW+Zw2XsKP15bwWAU+PEFp3Xr/CA3c30aql8+n2YzCmM52ycWM1CeGBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=fNQZNFvv; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="fNQZNFvv" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A7CZbsh016982; Thu, 7 Nov 2024 08:09:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=pfpt0220; bh=HKQVOurKvt4qN+FjWNzkO27z+ yvuk65wCZo4EbStPoc=; b=fNQZNFvvM8+IczLpR+vF+5Ql+MSmOibaUdRBsJ49u i53ySrv898uZFE2Lg0wCdT+zI4O8FcFdkCn0NHwpbxNZgybxZnG0Uu4hdAYEzcGD NxV4icHdLSk77N+3Ho9Gm0ph33HTLLF9pyTA1j95unuNe920F+6VoXhFEg5tfCX9 qHWG86h/259gLKFpYRmIXjLkljHBlHqm+2RlY5wGZPrhTpPykykue5siC1PAgajQ 1NN2UTfQfeE6j0yh2XQ/a9RikkQ47oV2l0IN0KQBVzQ3KxPBT1D1qPSqNH/xNDCd dDP78MNBfxxQ9JSAf5J68XZl/hciVDmSYRCL8uEzcLGMg== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42rwpngh4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Nov 2024 08:09:05 -0800 (PST) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 7 Nov 2024 08:09:04 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 7 Nov 2024 08:09:04 -0800 Received: from hyd1soter3.marvell.com (unknown [10.29.37.12]) by maili.marvell.com (Postfix) with ESMTP id 035233F7050; Thu, 7 Nov 2024 08:09:00 -0800 (PST) From: Geetha sowjanya To: , CC: , , , , , , , , Subject: [net-next PATCH v12 05/12] octeontx2-pf: Get VF stats via representor Date: Thu, 7 Nov 2024 21:38:32 +0530 Message-ID: <20241107160839.23707-6-gakula@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241107160839.23707-1-gakula@marvell.com> References: <20241107160839.23707-1-gakula@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: JzToMYiOujazRBsp8SCAC4vJBcbPe76I X-Proofpoint-ORIG-GUID: JzToMYiOujazRBsp8SCAC4vJBcbPe76I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds support to export VF port statistics via representor netdev. Defines new mbox "NIX_LF_STATS" to fetch VF hw stats. Signed-off-by: Geetha sowjanya Reviewed-by: Simon Horman --- v11-v12: - Moved nix_stat_lf_tx/rx structure to common file. .../net/ethernet/marvell/octeontx2/af/mbox.h | 32 +++++++++ .../marvell/octeontx2/af/rvu_debugfs.c | 27 -------- .../ethernet/marvell/octeontx2/af/rvu_rep.c | 43 ++++++++++++ .../marvell/octeontx2/af/rvu_struct.h | 26 ++++++++ .../marvell/octeontx2/nic/otx2_common.h | 27 -------- .../net/ethernet/marvell/octeontx2/nic/rep.c | 65 +++++++++++++++++++ .../net/ethernet/marvell/octeontx2/nic/rep.h | 14 ++++ 7 files changed, 180 insertions(+), 54 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h b/drivers/net= /ethernet/marvell/octeontx2/af/mbox.h index 10d5712b0077..8fd4b585d3b4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h @@ -321,6 +321,7 @@ M(NIX_MCAST_GRP_DESTROY, 0x802c, nix_mcast_grp_destroy,= nix_mcast_grp_destroy_re M(NIX_MCAST_GRP_UPDATE, 0x802d, nix_mcast_grp_update, \ nix_mcast_grp_update_req, \ nix_mcast_grp_update_rsp) \ +M(NIX_LF_STATS, 0x802e, nix_lf_stats, nix_stats_req, nix_stats_rsp) \ /* MCS mbox IDs (range 0xA000 - 0xBFFF) */ \ M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req, \ mcs_alloc_rsrc_rsp) \ @@ -1366,6 +1367,37 @@ struct nix_bandprof_get_hwinfo_rsp { u32 policer_timeunit; }; =20 +struct nix_stats_req { + struct mbox_msghdr hdr; + u8 reset; + u16 pcifunc; + u64 rsvd; +}; + +struct nix_stats_rsp { + struct mbox_msghdr hdr; + u16 pcifunc; + struct { + u64 octs; + u64 ucast; + u64 bcast; + u64 mcast; + u64 drop; + u64 drop_octs; + u64 drop_mcast; + u64 drop_bcast; + u64 err; + u64 rsvd[5]; + } rx; + struct { + u64 ucast; + u64 bcast; + u64 mcast; + u64 drop; + u64 octs; + } tx; +}; + /* NPC mbox message structs */ =20 #define NPC_MCAM_ENTRY_INVALID 0xFFFF diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/driv= ers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c index 8c700ee4a82b..148144f5b61d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c @@ -45,33 +45,6 @@ enum { CGX_STAT18, }; =20 -/* NIX TX stats */ -enum nix_stat_lf_tx { - TX_UCAST =3D 0x0, - TX_BCAST =3D 0x1, - TX_MCAST =3D 0x2, - TX_DROP =3D 0x3, - TX_OCTS =3D 0x4, - TX_STATS_ENUM_LAST, -}; - -/* NIX RX stats */ -enum nix_stat_lf_rx { - RX_OCTS =3D 0x0, - RX_UCAST =3D 0x1, - RX_BCAST =3D 0x2, - RX_MCAST =3D 0x3, - RX_DROP =3D 0x4, - RX_DROP_OCTS =3D 0x5, - RX_FCS =3D 0x6, - RX_ERR =3D 0x7, - RX_DRP_BCAST =3D 0x8, - RX_DRP_MCAST =3D 0x9, - RX_DRP_L3BCAST =3D 0xa, - RX_DRP_L3MCAST =3D 0xb, - RX_STATS_ENUM_LAST, -}; - static char *cgx_rx_stats_fields[] =3D { [CGX_STAT0] =3D "Received packets", [CGX_STAT1] =3D "Octets of received packets", diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_rep.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_rep.c index c1132d68259e..9ac663e05bb6 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_rep.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_rep.c @@ -14,6 +14,49 @@ #include "rvu.h" #include "rvu_reg.h" =20 +#define RVU_LF_RX_STATS(reg) \ + rvu_read64(rvu, blkaddr, NIX_AF_LFX_RX_STATX(nixlf, reg)) + +#define RVU_LF_TX_STATS(reg) \ + rvu_read64(rvu, blkaddr, NIX_AF_LFX_TX_STATX(nixlf, reg)) + +int rvu_mbox_handler_nix_lf_stats(struct rvu *rvu, + struct nix_stats_req *req, + struct nix_stats_rsp *rsp) +{ + u16 pcifunc =3D req->pcifunc; + int nixlf, blkaddr, err; + struct msg_req rst_req; + struct msg_rsp rst_rsp; + + err =3D nix_get_nixlf(rvu, pcifunc, &nixlf, &blkaddr); + if (err) + return 0; + + if (req->reset) { + rst_req.hdr.pcifunc =3D pcifunc; + return rvu_mbox_handler_nix_stats_rst(rvu, &rst_req, &rst_rsp); + } + rsp->rx.octs =3D RVU_LF_RX_STATS(RX_OCTS); + rsp->rx.ucast =3D RVU_LF_RX_STATS(RX_UCAST); + rsp->rx.bcast =3D RVU_LF_RX_STATS(RX_BCAST); + rsp->rx.mcast =3D RVU_LF_RX_STATS(RX_MCAST); + rsp->rx.drop =3D RVU_LF_RX_STATS(RX_DROP); + rsp->rx.err =3D RVU_LF_RX_STATS(RX_ERR); + rsp->rx.drop_octs =3D RVU_LF_RX_STATS(RX_DROP_OCTS); + rsp->rx.drop_mcast =3D RVU_LF_RX_STATS(RX_DRP_MCAST); + rsp->rx.drop_bcast =3D RVU_LF_RX_STATS(RX_DRP_BCAST); + + rsp->tx.octs =3D RVU_LF_TX_STATS(TX_OCTS); + rsp->tx.ucast =3D RVU_LF_TX_STATS(TX_UCAST); + rsp->tx.bcast =3D RVU_LF_TX_STATS(TX_BCAST); + rsp->tx.mcast =3D RVU_LF_TX_STATS(TX_MCAST); + rsp->tx.drop =3D RVU_LF_TX_STATS(TX_DROP); + + rsp->pcifunc =3D req->pcifunc; + return 0; +} + static u16 rvu_rep_get_vlan_id(struct rvu *rvu, u16 pcifunc) { int id; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_struct.h b/drive= rs/net/ethernet/marvell/octeontx2/af/rvu_struct.h index fc8da2090657..77ac94cb2ec4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_struct.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_struct.h @@ -823,4 +823,30 @@ enum nix_tx_vtag_op { #define VTAG_STRIP BIT_ULL(4) #define VTAG_CAPTURE BIT_ULL(5) =20 +/* NIX TX stats */ +enum nix_stat_lf_tx { + TX_UCAST =3D 0x0, + TX_BCAST =3D 0x1, + TX_MCAST =3D 0x2, + TX_DROP =3D 0x3, + TX_OCTS =3D 0x4, + TX_STATS_ENUM_LAST, +}; + +/* NIX RX stats */ +enum nix_stat_lf_rx { + RX_OCTS =3D 0x0, + RX_UCAST =3D 0x1, + RX_BCAST =3D 0x2, + RX_MCAST =3D 0x3, + RX_DROP =3D 0x4, + RX_DROP_OCTS =3D 0x5, + RX_FCS =3D 0x6, + RX_ERR =3D 0x7, + RX_DRP_BCAST =3D 0x8, + RX_DRP_MCAST =3D 0x9, + RX_DRP_L3BCAST =3D 0xa, + RX_DRP_L3MCAST =3D 0xb, + RX_STATS_ENUM_LAST, +}; #endif /* RVU_STRUCT_H */ diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/dri= vers/net/ethernet/marvell/octeontx2/nic/otx2_common.h index ed2bbe72647a..ae0eb08b276c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h @@ -121,33 +121,6 @@ enum otx2_errcodes_re { ERRCODE_IL4_CSUM =3D 0x22, }; =20 -/* NIX TX stats */ -enum nix_stat_lf_tx { - TX_UCAST =3D 0x0, - TX_BCAST =3D 0x1, - TX_MCAST =3D 0x2, - TX_DROP =3D 0x3, - TX_OCTS =3D 0x4, - TX_STATS_ENUM_LAST, -}; - -/* NIX RX stats */ -enum nix_stat_lf_rx { - RX_OCTS =3D 0x0, - RX_UCAST =3D 0x1, - RX_BCAST =3D 0x2, - RX_MCAST =3D 0x3, - RX_DROP =3D 0x4, - RX_DROP_OCTS =3D 0x5, - RX_FCS =3D 0x6, - RX_ERR =3D 0x7, - RX_DRP_BCAST =3D 0x8, - RX_DRP_MCAST =3D 0x9, - RX_DRP_L3BCAST =3D 0xa, - RX_DRP_L3MCAST =3D 0xb, - RX_STATS_ENUM_LAST, -}; - struct otx2_dev_stats { u64 rx_bytes; u64 rx_frames; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net= /ethernet/marvell/octeontx2/nic/rep.c index 50cebd0af524..197aa21759b5 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c @@ -28,6 +28,68 @@ MODULE_DESCRIPTION(DRV_STRING); MODULE_LICENSE("GPL"); MODULE_DEVICE_TABLE(pci, rvu_rep_id_table); =20 +static void rvu_rep_get_stats(struct work_struct *work) +{ + struct delayed_work *del_work =3D to_delayed_work(work); + struct nix_stats_req *req; + struct nix_stats_rsp *rsp; + struct rep_stats *stats; + struct otx2_nic *priv; + struct rep_dev *rep; + int err; + + rep =3D container_of(del_work, struct rep_dev, stats_wrk); + priv =3D rep->mdev; + + mutex_lock(&priv->mbox.lock); + req =3D otx2_mbox_alloc_msg_nix_lf_stats(&priv->mbox); + if (!req) { + mutex_unlock(&priv->mbox.lock); + return; + } + req->pcifunc =3D rep->pcifunc; + err =3D otx2_sync_mbox_msg_busy_poll(&priv->mbox); + if (err) + goto exit; + + rsp =3D (struct nix_stats_rsp *) + otx2_mbox_get_rsp(&priv->mbox.mbox, 0, &req->hdr); + + if (IS_ERR(rsp)) { + err =3D PTR_ERR(rsp); + goto exit; + } + + stats =3D &rep->stats; + stats->rx_bytes =3D rsp->rx.octs; + stats->rx_frames =3D rsp->rx.ucast + rsp->rx.bcast + + rsp->rx.mcast; + stats->rx_drops =3D rsp->rx.drop; + stats->rx_mcast_frames =3D rsp->rx.mcast; + stats->tx_bytes =3D rsp->tx.octs; + stats->tx_frames =3D rsp->tx.ucast + rsp->tx.bcast + rsp->tx.mcast; + stats->tx_drops =3D rsp->tx.drop; +exit: + mutex_unlock(&priv->mbox.lock); +} + +static void rvu_rep_get_stats64(struct net_device *dev, + struct rtnl_link_stats64 *stats) +{ + struct rep_dev *rep =3D netdev_priv(dev); + + stats->rx_packets =3D rep->stats.rx_frames; + stats->rx_bytes =3D rep->stats.rx_bytes; + stats->rx_dropped =3D rep->stats.rx_drops; + stats->multicast =3D rep->stats.rx_mcast_frames; + + stats->tx_packets =3D rep->stats.tx_frames; + stats->tx_bytes =3D rep->stats.tx_bytes; + stats->tx_dropped =3D rep->stats.tx_drops; + + schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100)); +} + static int rvu_eswitch_config(struct otx2_nic *priv, u8 ena) { struct esw_cfg_req *req; @@ -87,6 +149,7 @@ static const struct net_device_ops rvu_rep_netdev_ops = =3D { .ndo_open =3D rvu_rep_open, .ndo_stop =3D rvu_rep_stop, .ndo_start_xmit =3D rvu_rep_xmit, + .ndo_get_stats64 =3D rvu_rep_get_stats64, }; =20 static int rvu_rep_napi_init(struct otx2_nic *priv, @@ -290,6 +353,8 @@ int rvu_rep_create(struct otx2_nic *priv, struct netlin= k_ext_ack *extack) free_netdev(ndev); goto exit; } + + INIT_DELAYED_WORK(&rep->stats_wrk, rvu_rep_get_stats); } err =3D rvu_rep_napi_init(priv, extack); if (err) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.h b/drivers/net= /ethernet/marvell/octeontx2/nic/rep.h index c04874c4d4c6..5d39bf636655 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.h +++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.h @@ -17,9 +17,23 @@ #define PCI_DEVID_RVU_REP 0xA0E0 =20 #define RVU_MAX_REP OTX2_MAX_CQ_CNT + +struct rep_stats { + u64 rx_bytes; + u64 rx_frames; + u64 rx_drops; + u64 rx_mcast_frames; + + u64 tx_bytes; + u64 tx_frames; + u64 tx_drops; +}; + struct rep_dev { struct otx2_nic *mdev; struct net_device *netdev; + struct rep_stats stats; + struct delayed_work stats_wrk; u16 rep_id; u16 pcifunc; }; --=20 2.25.1