From nobody Sun May 5 23:38:32 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CE0FC4321E for ; Mon, 5 Dec 2022 07:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbiLEHFq (ORCPT ); Mon, 5 Dec 2022 02:05:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbiLEHFk (ORCPT ); Mon, 5 Dec 2022 02:05:40 -0500 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E11DDC74E; Sun, 4 Dec 2022 23:05:38 -0800 (PST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B50UjE4018131; Sun, 4 Dec 2022 23:05:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=CpNFlSq8bxVo+CgJQDKSAXMnU7E4NUQxMDf/tmLOSLE=; b=Af/1LdA4Mw2wWVYcQFVi02p0ld0uKp6vRRZJHW/SkwAsTBqklE1v28dJilKlbsuM/wDG 4Gg+2CLUEPVmXzEl4199PbIV2ntKjUhFAdfkv+Ti8FCDrke2GdQ20votBVSqDhVxKIMB TK522ObnPGEbETwgWYmxBNQTNcdKlNjbd2K3FaDqXaAXzP7NUlEJRczcuSGjJ6Euf/oz myUKo+WrkKIrFpHo7oRmgUcDa1baeSDAxFRom880rWKqhpM8P6oACmLNxsU7YPHiHwee wReKRQck1djcRVlgRU+pyOJXmjs/crIMB0e8/THO1yrMzqYPTaZSVIBV/Kbs+HieAvSo cg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3m84pumnvy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 04 Dec 2022 23:05:31 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 4 Dec 2022 23:05:29 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 4 Dec 2022 23:05:29 -0800 Received: from hyd1soter3.marvell.com (unknown [10.29.37.12]) by maili.marvell.com (Postfix) with ESMTP id 25A943F7098; Sun, 4 Dec 2022 23:05:25 -0800 (PST) From: Hariprasad Kelam To: , CC: , , , , , , , , Subject: [net-next Patch v4 1/4] octeontx2-af: Support variable number of lmacs Date: Mon, 5 Dec 2022 12:35:18 +0530 Message-ID: <20221205070521.21860-2-hkelam@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221205070521.21860-1-hkelam@marvell.com> References: <20221205070521.21860-1-hkelam@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QE8NdAeQHlj6zenYOJQzQm0BnEBH4z9N X-Proofpoint-GUID: QE8NdAeQHlj6zenYOJQzQm0BnEBH4z9N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-05_01,2022-12-01_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rakesh Babu Saladi Most of the code in CGX/RPM driver assumes that max lmacs per given MAC as always, 4 and the number of MAC blocks also as 4. With this assumption, the max number of interfaces supported is hardcoded to 16. This creates a problem as next gen CN10KB silicon MAC supports 8 lmacs per MAC block. This patch solves the problem by using "max lmac per MAC block" value from constant csrs and uses cgx_cnt_max value which is populated based number of MAC blocks supported by silicon. Signed-off-by: Rakesh Babu Saladi Signed-off-by: Hariprasad Kelam Signed-off-by: Sunil Kovvuri Goutham --- .../net/ethernet/marvell/octeontx2/af/cgx.c | 35 ++++++++----------- .../net/ethernet/marvell/octeontx2/af/cgx.h | 6 ++-- .../marvell/octeontx2/af/lmac_common.h | 5 ++- .../net/ethernet/marvell/octeontx2/af/rvu.h | 2 +- .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 26 ++++++++------ .../marvell/octeontx2/af/rvu_debugfs.c | 2 +- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 2 +- .../marvell/octeontx2/af/rvu_npc_hash.c | 4 ++- 8 files changed, 42 insertions(+), 40 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/= ethernet/marvell/octeontx2/af/cgx.c index c8724bfa86b0..fa5a1e88cb84 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -78,7 +78,7 @@ static bool is_dev_rpm(void *cgxd) =20 bool is_lmac_valid(struct cgx *cgx, int lmac_id) { - if (!cgx || lmac_id < 0 || lmac_id >=3D MAX_LMAC_PER_CGX) + if (!cgx || lmac_id < 0 || lmac_id >=3D cgx->max_lmac_per_mac) return false; return test_bit(lmac_id, &cgx->lmac_bmap); } @@ -90,7 +90,7 @@ static int get_sequence_id_of_lmac(struct cgx *cgx, int l= mac_id) { int tmp, id =3D 0; =20 - for_each_set_bit(tmp, &cgx->lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(tmp, &cgx->lmac_bmap, cgx->max_lmac_per_mac) { if (tmp =3D=3D lmac_id) break; id++; @@ -121,7 +121,7 @@ u64 cgx_read(struct cgx *cgx, u64 lmac, u64 offset) =20 struct lmac *lmac_pdata(u8 lmac_id, struct cgx *cgx) { - if (!cgx || lmac_id >=3D MAX_LMAC_PER_CGX) + if (!cgx || lmac_id >=3D cgx->max_lmac_per_mac) return NULL; =20 return cgx->lmac_idmap[lmac_id]; @@ -1395,7 +1395,7 @@ int cgx_get_fwdata_base(u64 *base) if (!cgx) return -ENXIO; =20 - first_lmac =3D find_first_bit(&cgx->lmac_bmap, MAX_LMAC_PER_CGX); + first_lmac =3D find_first_bit(&cgx->lmac_bmap, cgx->max_lmac_per_mac); req =3D FIELD_SET(CMDREG_ID, CGX_CMD_GET_FWD_BASE, req); err =3D cgx_fwi_cmd_generic(req, &resp, cgx, first_lmac); if (!err) @@ -1484,7 +1484,7 @@ static int cgx_fwi_link_change(struct cgx *cgx, int l= mac_id, bool enable) =20 static inline int cgx_fwi_read_version(u64 *resp, struct cgx *cgx) { - int first_lmac =3D find_first_bit(&cgx->lmac_bmap, MAX_LMAC_PER_CGX); + int first_lmac =3D find_first_bit(&cgx->lmac_bmap, cgx->max_lmac_per_mac); u64 req =3D 0; =20 req =3D FIELD_SET(CMDREG_ID, CGX_CMD_GET_FW_VER, req); @@ -1522,7 +1522,7 @@ static void cgx_lmac_linkup_work(struct work_struct *= work) int i, err; =20 /* Do Link up for all the enabled lmacs */ - for_each_set_bit(i, &cgx->lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(i, &cgx->lmac_bmap, cgx->max_lmac_per_mac) { err =3D cgx_fwi_link_change(cgx, i, true); if (err) dev_info(dev, "cgx port %d:%d Link up command failed\n", @@ -1542,14 +1542,6 @@ int cgx_lmac_linkup_start(void *cgxd) return 0; } =20 -static void cgx_lmac_get_fifolen(struct cgx *cgx) -{ - u64 cfg; - - cfg =3D cgx_read(cgx, 0, CGX_CONST); - cgx->mac_ops->fifo_len =3D FIELD_GET(CGX_CONST_RXFIFO_SIZE, cfg); -} - static int cgx_configure_interrupt(struct cgx *cgx, struct lmac *lmac, int cnt, bool req_free) { @@ -1604,17 +1596,14 @@ static int cgx_lmac_init(struct cgx *cgx) u64 lmac_list; int i, err; =20 - cgx_lmac_get_fifolen(cgx); - - cgx->lmac_count =3D cgx->mac_ops->get_nr_lmacs(cgx); /* lmac_list specifies which lmacs are enabled * when bit n is set to 1, LMAC[n] is enabled */ if (cgx->mac_ops->non_contiguous_serdes_lane) lmac_list =3D cgx_read(cgx, 0, CGXX_CMRX_RX_LMACS) & 0xFULL; =20 - if (cgx->lmac_count > MAX_LMAC_PER_CGX) - cgx->lmac_count =3D MAX_LMAC_PER_CGX; + if (cgx->lmac_count > cgx->max_lmac_per_mac) + cgx->lmac_count =3D cgx->max_lmac_per_mac; =20 for (i =3D 0; i < cgx->lmac_count; i++) { lmac =3D kzalloc(sizeof(struct lmac), GFP_KERNEL); @@ -1692,7 +1681,7 @@ static int cgx_lmac_exit(struct cgx *cgx) } =20 /* Free all lmac related resources */ - for_each_set_bit(i, &cgx->lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(i, &cgx->lmac_bmap, cgx->max_lmac_per_mac) { lmac =3D cgx->lmac_idmap[i]; if (!lmac) continue; @@ -1708,6 +1697,12 @@ static int cgx_lmac_exit(struct cgx *cgx) =20 static void cgx_populate_features(struct cgx *cgx) { + u64 cfg; + + cfg =3D cgx_read(cgx, 0, CGX_CONST); + cgx->mac_ops->fifo_len =3D FIELD_GET(CGX_CONST_RXFIFO_SIZE, cfg); + cgx->max_lmac_per_mac =3D FIELD_GET(CGX_CONST_MAX_LMACS, cfg); + if (is_dev_rpm(cgx)) cgx->hw_features =3D (RVU_LMAC_FEAT_DMACF | RVU_MAC_RPM | RVU_LMAC_FEAT_FC | RVU_LMAC_FEAT_PTP); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h b/drivers/net/= ethernet/marvell/octeontx2/af/cgx.h index 0b06788b8d80..ce66c7271e3a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h @@ -18,11 +18,8 @@ /* PCI BAR nos */ #define PCI_CFG_REG_BAR_NUM 0 =20 -#define CGX_ID_MASK 0x7 -#define MAX_LMAC_PER_CGX 4 +#define CGX_ID_MASK 0xF #define MAX_DMAC_ENTRIES_PER_CGX 32 -#define CGX_FIFO_LEN 65536 /* 64K for both Rx & Tx */ -#define CGX_OFFSET(x) ((x) * MAX_LMAC_PER_CGX) =20 /* Registers */ #define CGXX_CMRX_CFG 0x00 @@ -57,6 +54,7 @@ #define CGXX_SCRATCH1_REG 0x1058 #define CGX_CONST 0x2000 #define CGX_CONST_RXFIFO_SIZE GENMASK_ULL(23, 0) +#define CGX_CONST_MAX_LMACS GENMASK_ULL(31, 24) #define CGXX_SPUX_CONTROL1 0x10000 #define CGXX_SPUX_LNX_FEC_CORR_BLOCKS 0x10700 #define CGXX_SPUX_LNX_FEC_UNCORR_BLOCKS 0x10800 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/driv= ers/net/ethernet/marvell/octeontx2/af/lmac_common.h index 52b6016789fa..697cfec74aa1 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h @@ -128,7 +128,10 @@ struct cgx { struct pci_dev *pdev; u8 cgx_id; u8 lmac_count; - struct lmac *lmac_idmap[MAX_LMAC_PER_CGX]; + /* number of LMACs per MAC could be 4 or 8 */ + u8 max_lmac_per_mac; +#define MAX_LMAC_COUNT 8 + struct lmac *lmac_idmap[MAX_LMAC_COUNT]; struct work_struct cgx_cmd_work; struct workqueue_struct *cgx_cmd_workq; struct list_head cgx_list; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/= ethernet/marvell/octeontx2/af/rvu.h index f718cbd32a94..04333f127282 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -478,7 +478,7 @@ struct rvu { u8 cgx_mapped_pfs; u8 cgx_cnt_max; /* CGX port count max */ u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */ - u16 *cgxlmac2pf_map; /* bitmap of mapped pfs for + u64 *cgxlmac2pf_map; /* bitmap of mapped pfs for * every cgx lmac port */ unsigned long pf_notify_bmap; /* Flags for PF notification */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_cgx.c index addc69f4b65c..8d9f9bbc262b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c @@ -55,8 +55,9 @@ bool is_mac_feature_supported(struct rvu *rvu, int pf, in= t feature) return (cgx_features_get(cgxd) & feature); } =20 +#define CGX_OFFSET(x) ((x) * rvu->hw->lmac_per_cgx) /* Returns bitmap of mapped PFs */ -static u16 cgxlmac_to_pfmap(struct rvu *rvu, u8 cgx_id, u8 lmac_id) +static u64 cgxlmac_to_pfmap(struct rvu *rvu, u8 cgx_id, u8 lmac_id) { return rvu->cgxlmac2pf_map[CGX_OFFSET(cgx_id) + lmac_id]; } @@ -71,7 +72,8 @@ int cgxlmac_to_pf(struct rvu *rvu, int cgx_id, int lmac_i= d) if (!pfmap) return -ENODEV; else - return find_first_bit(&pfmap, 16); + return find_first_bit(&pfmap, + rvu->cgx_cnt_max * rvu->hw->lmac_per_cgx); } =20 static u8 cgxlmac_id_to_bmap(u8 cgx_id, u8 lmac_id) @@ -129,14 +131,14 @@ static int rvu_map_cgx_lmac_pf(struct rvu *rvu) if (!cgx_cnt_max) return 0; =20 - if (cgx_cnt_max > 0xF || MAX_LMAC_PER_CGX > 0xF) + if (cgx_cnt_max > 0xF || rvu->hw->lmac_per_cgx > 0xF) return -EINVAL; =20 /* Alloc map table * An additional entry is required since PF id starts from 1 and * hence entry at offset 0 is invalid. */ - size =3D (cgx_cnt_max * MAX_LMAC_PER_CGX + 1) * sizeof(u8); + size =3D (cgx_cnt_max * rvu->hw->lmac_per_cgx + 1) * sizeof(u8); rvu->pf2cgxlmac_map =3D devm_kmalloc(rvu->dev, size, GFP_KERNEL); if (!rvu->pf2cgxlmac_map) return -ENOMEM; @@ -145,9 +147,10 @@ static int rvu_map_cgx_lmac_pf(struct rvu *rvu) memset(rvu->pf2cgxlmac_map, 0xFF, size); =20 /* Reverse map table */ - rvu->cgxlmac2pf_map =3D devm_kzalloc(rvu->dev, - cgx_cnt_max * MAX_LMAC_PER_CGX * sizeof(u16), - GFP_KERNEL); + rvu->cgxlmac2pf_map =3D + devm_kzalloc(rvu->dev, + cgx_cnt_max * rvu->hw->lmac_per_cgx * sizeof(u64), + GFP_KERNEL); if (!rvu->cgxlmac2pf_map) return -ENOMEM; =20 @@ -156,7 +159,7 @@ static int rvu_map_cgx_lmac_pf(struct rvu *rvu) if (!rvu_cgx_pdata(cgx, rvu)) continue; lmac_bmap =3D cgx_get_lmac_bmap(rvu_cgx_pdata(cgx, rvu)); - for_each_set_bit(iter, &lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(iter, &lmac_bmap, rvu->hw->lmac_per_cgx) { lmac =3D cgx_get_lmacid(rvu_cgx_pdata(cgx, rvu), iter); rvu->pf2cgxlmac_map[pf] =3D cgxlmac_id_to_bmap(cgx, lmac); @@ -235,7 +238,8 @@ static void cgx_notify_pfs(struct cgx_link_event *event= , struct rvu *rvu) pfmap =3D cgxlmac_to_pfmap(rvu, event->cgx_id, event->lmac_id); =20 do { - pfid =3D find_first_bit(&pfmap, 16); + pfid =3D find_first_bit(&pfmap, + rvu->cgx_cnt_max * rvu->hw->lmac_per_cgx); clear_bit(pfid, &pfmap); =20 /* check if notification is enabled */ @@ -310,7 +314,7 @@ static int cgx_lmac_event_handler_init(struct rvu *rvu) if (!cgxd) continue; lmac_bmap =3D cgx_get_lmac_bmap(cgxd); - for_each_set_bit(lmac, &lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(lmac, &lmac_bmap, rvu->hw->lmac_per_cgx) { err =3D cgx_lmac_evh_register(&cb, cgxd, lmac); if (err) dev_err(rvu->dev, @@ -396,7 +400,7 @@ int rvu_cgx_exit(struct rvu *rvu) if (!cgxd) continue; lmac_bmap =3D cgx_get_lmac_bmap(cgxd); - for_each_set_bit(lmac, &lmac_bmap, MAX_LMAC_PER_CGX) + for_each_set_bit(lmac, &lmac_bmap, rvu->hw->lmac_per_cgx) cgx_lmac_evh_unregister(cgxd, lmac); } =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/driv= ers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c index 0eb3085c4c21..fa280ebd3052 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c @@ -2613,7 +2613,7 @@ static void rvu_dbg_cgx_init(struct rvu *rvu) rvu->rvu_dbg.cgx =3D debugfs_create_dir(dname, rvu->rvu_dbg.cgx_root); =20 - for_each_set_bit(lmac_id, &lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(lmac_id, &lmac_bmap, rvu->hw->lmac_per_cgx) { /* lmac debugfs dir */ sprintf(dname, "lmac%d", lmac_id); rvu->rvu_dbg.lmac =3D diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_nix.c index a62c1b322012..de489e7366da 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -4109,7 +4109,7 @@ static void nix_link_config(struct rvu *rvu, int blka= ddr, =20 /* Get LMAC id's from bitmap */ lmac_bmap =3D cgx_get_lmac_bmap(rvu_cgx_pdata(cgx, rvu)); - for_each_set_bit(iter, &lmac_bmap, MAX_LMAC_PER_CGX) { + for_each_set_bit(iter, &lmac_bmap, rvu->hw->lmac_per_cgx) { lmac_fifo_len =3D rvu_cgx_get_lmac_fifolen(rvu, cgx, iter); if (!lmac_fifo_len) { dev_err(rvu->dev, diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c b/dri= vers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c index 00aef8f5ac29..f69102d20c90 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c @@ -1956,7 +1956,9 @@ int rvu_npc_exact_init(struct rvu *rvu) /* Install SDP drop rule */ drop_mcam_idx =3D &table->num_drop_rules; =20 - max_lmac_cnt =3D rvu->cgx_cnt_max * MAX_LMAC_PER_CGX + PF_CGXMAP_BASE; + max_lmac_cnt =3D rvu->cgx_cnt_max * rvu->hw->lmac_per_cgx + + PF_CGXMAP_BASE; + for (i =3D PF_CGXMAP_BASE; i < max_lmac_cnt; i++) { if (rvu->pf2cgxlmac_map[i] =3D=3D 0xFF) continue; --=20 2.17.1 From nobody Sun May 5 23:38:32 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFE4EC47088 for ; Mon, 5 Dec 2022 07:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbiLEHGB (ORCPT ); Mon, 5 Dec 2022 02:06:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231673AbiLEHFq (ORCPT ); Mon, 5 Dec 2022 02:05:46 -0500 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBE1D11E; Sun, 4 Dec 2022 23:05:44 -0800 (PST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B4Lf3Sc012167; Sun, 4 Dec 2022 23:05:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=bPE4OdvmsWxfPMVI5QVP2HWGItHFOOsD4H09tD+WEFc=; b=lUe8qrJS7oLOMpZx+4L9jKQazbHtv/uqebiRXPgYR0gu9evJNQ+l55anp5Iz1UfqF0KM DwRCnlcenZWV/JRgO8hkBDDxzNrAu+pIW3LShtrnNcY9iOLZr8qNSwOJn9s4yb0a6QOQ FTNI7lAqA7lKYYJ9H4OqiY/1WVuNBMh5Zt1Q5mN7Ex4/dxeclqQPiIl6QEyIrdL0dGmp 5cClaanKk9C9Qyg+tYevG66cjTFUtHYmhFSMpTOrdxrHkkWnKAPe+aqar46z3Qb8UiO2 bJSuYxwnOat2MlJ3EcSUZaa/s/hpmn+nqFGvu15w+K5bzipJguz97kAXljxqxutSJQIW qg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3m84pumnw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 04 Dec 2022 23:05:34 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 4 Dec 2022 23:05:33 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 4 Dec 2022 23:05:32 -0800 Received: from hyd1soter3.marvell.com (unknown [10.29.37.12]) by maili.marvell.com (Postfix) with ESMTP id C52353F707A; Sun, 4 Dec 2022 23:05:29 -0800 (PST) From: Hariprasad Kelam To: , CC: , , , , , , , , Subject: [net-next Patch v4 2/4] octeontx2-af: cn10kb: Add RPM_USX MAC support Date: Mon, 5 Dec 2022 12:35:19 +0530 Message-ID: <20221205070521.21860-3-hkelam@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221205070521.21860-1-hkelam@marvell.com> References: <20221205070521.21860-1-hkelam@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Ra_gDhZyYQ7HpNEg6jihBw8KtuwMw7hh X-Proofpoint-GUID: Ra_gDhZyYQ7HpNEg6jihBw8KtuwMw7hh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-05_01,2022-12-01_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" OcteonTx2's next gen platform the CN10KB has RPM_USX MAC which has a different serdes when compared to RPM MAC. Though the underlying HW is different, the CSR interface has been designed largely inline with RPM MAC, with few exceptions though. So we are using the same CGX driver for RPM_USX MAC as well and will have a different set of APIs for RPM_USX where ever necessary. The RPM and RPM_USX blocks support a different number of LMACS. RPM_USX support 8 LMACS per MAC block whereas legacy RPM supports only 4 LMACS per MAC. with this RPM_USX support double the number of DMAC filters and fifo size. This patch adds initial support for CN10KB's RPM_USX MAC i.e registering the driver and defining MAC operations (mac_ops). Adds the logic to configure internal loopback and pause frames and assign FIFO length to LMACS. Kernel reads lmac features like lmac type, autoneg, etc from shared firmware data this structure only supports 4 lmacs per MAC, this patch extends this structure to accommodate 8 lmacs. Signed-off-by: Hariprasad Kelam Signed-off-by: Sunil Kovvuri Goutham --- .../net/ethernet/marvell/octeontx2/af/cgx.c | 38 +++- .../net/ethernet/marvell/octeontx2/af/cgx.h | 3 +- .../marvell/octeontx2/af/lmac_common.h | 7 +- .../net/ethernet/marvell/octeontx2/af/rpm.c | 204 ++++++++++++++++-- .../net/ethernet/marvell/octeontx2/af/rpm.h | 22 ++ .../net/ethernet/marvell/octeontx2/af/rvu.h | 10 +- .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 19 +- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 8 +- 8 files changed, 270 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/= ethernet/marvell/octeontx2/af/cgx.c index fa5a1e88cb84..242c5b0eb15d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -64,6 +64,7 @@ static int cgx_fwi_link_change(struct cgx *cgx, int lmac_= id, bool en); static const struct pci_device_id cgx_id_table[] =3D { { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_CGX) }, { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CN10K_RPM) }, + { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CN10KB_RPM) }, { 0, } /* end of table */ }; =20 @@ -73,7 +74,8 @@ static bool is_dev_rpm(void *cgxd) { struct cgx *cgx =3D cgxd; =20 - return (cgx->pdev->device =3D=3D PCI_DEVID_CN10K_RPM); + return (cgx->pdev->device =3D=3D PCI_DEVID_CN10K_RPM) || + (cgx->pdev->device =3D=3D PCI_DEVID_CN10KB_RPM); } =20 bool is_lmac_valid(struct cgx *cgx, int lmac_id) @@ -485,7 +487,7 @@ int cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind) if (!is_lmac_valid(cgx, lmac_id)) return -ENODEV; =20 - cgx_write(cgx, lmac_id, CGXX_CMRX_RX_ID_MAP, (pkind & 0x3F)); + cgx_write(cgx, lmac_id, cgx->mac_ops->rxid_map_offset, (pkind & 0x3F)); return 0; } =20 @@ -1224,7 +1226,7 @@ static inline void link_status_user_format(u64 lstat, linfo->speed =3D cgx_speed_mbps[FIELD_GET(RESP_LINKSTAT_SPEED, lstat)]; linfo->an =3D FIELD_GET(RESP_LINKSTAT_AN, lstat); linfo->fec =3D FIELD_GET(RESP_LINKSTAT_FEC, lstat); - linfo->lmac_type_id =3D cgx_get_lmac_type(cgx, lmac_id); + linfo->lmac_type_id =3D FIELD_GET(RESP_LINKSTAT_LMAC_TYPE, lstat); lmac_string =3D cgx_lmactype_string[linfo->lmac_type_id]; strncpy(linfo->lmac_type, lmac_string, LMACTYPE_STR_LEN - 1); } @@ -1599,8 +1601,14 @@ static int cgx_lmac_init(struct cgx *cgx) /* lmac_list specifies which lmacs are enabled * when bit n is set to 1, LMAC[n] is enabled */ - if (cgx->mac_ops->non_contiguous_serdes_lane) - lmac_list =3D cgx_read(cgx, 0, CGXX_CMRX_RX_LMACS) & 0xFULL; + if (cgx->mac_ops->non_contiguous_serdes_lane) { + if (is_dev_rpm2(cgx)) + lmac_list =3D + cgx_read(cgx, 0, RPM2_CMRX_RX_LMACS) & 0xFFULL; + else + lmac_list =3D + cgx_read(cgx, 0, CGXX_CMRX_RX_LMACS) & 0xFULL; + } =20 if (cgx->lmac_count > cgx->max_lmac_per_mac) cgx->lmac_count =3D cgx->max_lmac_per_mac; @@ -1624,7 +1632,9 @@ static int cgx_lmac_init(struct cgx *cgx) =20 lmac->cgx =3D cgx; lmac->mac_to_index_bmap.max =3D - MAX_DMAC_ENTRIES_PER_CGX / cgx->lmac_count; + cgx->mac_ops->dmac_filter_count / + cgx->lmac_count; + err =3D rvu_alloc_bitmap(&lmac->mac_to_index_bmap); if (err) goto err_name_free; @@ -1711,6 +1721,15 @@ static void cgx_populate_features(struct cgx *cgx) RVU_LMAC_FEAT_PTP | RVU_LMAC_FEAT_DMACF); } =20 +static u8 cgx_get_rxid_mapoffset(struct cgx *cgx) +{ + if (cgx->pdev->subsystem_device =3D=3D PCI_SUBSYS_DEVID_CNF10KB_RPM || + is_dev_rpm2(cgx)) + return 0x80; + else + return 0x60; +} + static struct mac_ops cgx_mac_ops =3D { .name =3D "cgx", .csr_offset =3D 0, @@ -1723,6 +1742,7 @@ static struct mac_ops cgx_mac_ops =3D { .non_contiguous_serdes_lane =3D false, .rx_stats_cnt =3D 9, .tx_stats_cnt =3D 18, + .dmac_filter_count =3D 32, .get_nr_lmacs =3D cgx_get_nr_lmacs, .get_lmac_type =3D cgx_get_lmac_type, .lmac_fifo_len =3D cgx_get_lmac_fifo_len, @@ -1754,11 +1774,13 @@ static int cgx_probe(struct pci_dev *pdev, const st= ruct pci_device_id *id) pci_set_drvdata(pdev, cgx); =20 /* Use mac_ops to get MAC specific features */ - if (pdev->device =3D=3D PCI_DEVID_CN10K_RPM) - cgx->mac_ops =3D rpm_get_mac_ops(); + if (is_dev_rpm(cgx)) + cgx->mac_ops =3D rpm_get_mac_ops(cgx); else cgx->mac_ops =3D &cgx_mac_ops; =20 + cgx->mac_ops->rxid_map_offset =3D cgx_get_rxid_mapoffset(cgx); + err =3D pci_enable_device(pdev); if (err) { dev_err(dev, "Failed to enable PCI device\n"); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h b/drivers/net/= ethernet/marvell/octeontx2/af/cgx.h index ce66c7271e3a..fb2d37676d84 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h @@ -19,7 +19,6 @@ #define PCI_CFG_REG_BAR_NUM 0 =20 #define CGX_ID_MASK 0xF -#define MAX_DMAC_ENTRIES_PER_CGX 32 =20 /* Registers */ #define CGXX_CMRX_CFG 0x00 @@ -53,7 +52,7 @@ #define CGXX_SCRATCH0_REG 0x1050 #define CGXX_SCRATCH1_REG 0x1058 #define CGX_CONST 0x2000 -#define CGX_CONST_RXFIFO_SIZE GENMASK_ULL(23, 0) +#define CGX_CONST_RXFIFO_SIZE GENMASK_ULL(55, 32) #define CGX_CONST_MAX_LMACS GENMASK_ULL(31, 24) #define CGXX_SPUX_CONTROL1 0x10000 #define CGXX_SPUX_LNX_FEC_CORR_BLOCKS 0x10700 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/driv= ers/net/ethernet/marvell/octeontx2/af/lmac_common.h index 697cfec74aa1..386fb73ad366 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h @@ -75,6 +75,11 @@ struct mac_ops { /* RPM & CGX differs in number of Receive/transmit stats */ u8 rx_stats_cnt; u8 tx_stats_cnt; + /* Unlike CN10K which shares same CSR offset with CGX + * CNF10KB has different csr offset + */ + u64 rxid_map_offset; + u8 dmac_filter_count; /* Incase of RPM get number of lmacs from RPMX_CMR_RX_LMACS[LMAC_EXIST] * number of setbits in lmac_exist tells number of lmacs */ @@ -153,6 +158,6 @@ struct lmac *lmac_pdata(u8 lmac_id, struct cgx *cgx); int cgx_fwi_cmd_send(u64 req, u64 *resp, struct lmac *lmac); int cgx_fwi_cmd_generic(u64 req, u64 *resp, struct cgx *cgx, int lmac_id); bool is_lmac_valid(struct cgx *cgx, int lmac_id); -struct mac_ops *rpm_get_mac_ops(void); +struct mac_ops *rpm_get_mac_ops(struct cgx *cgx); =20 #endif /* LMAC_COMMON_H */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c b/drivers/net/= ethernet/marvell/octeontx2/af/rpm.c index a70e1153fa04..a15a59d5dff8 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c @@ -8,7 +8,7 @@ #include "cgx.h" #include "lmac_common.h" =20 -static struct mac_ops rpm_mac_ops =3D { +static struct mac_ops rpm_mac_ops =3D { .name =3D "rpm", .csr_offset =3D 0x4e00, .lmac_offset =3D 20, @@ -20,6 +20,7 @@ static struct mac_ops rpm_mac_ops =3D { .non_contiguous_serdes_lane =3D true, .rx_stats_cnt =3D 43, .tx_stats_cnt =3D 34, + .dmac_filter_count =3D 32, .get_nr_lmacs =3D rpm_get_nr_lmacs, .get_lmac_type =3D rpm_get_lmac_type, .lmac_fifo_len =3D rpm_get_lmac_fifo_len, @@ -37,9 +38,49 @@ static struct mac_ops rpm_mac_ops =3D { .mac_get_pfc_frm_cfg =3D rpm_lmac_get_pfc_frm_cfg, }; =20 -struct mac_ops *rpm_get_mac_ops(void) +static struct mac_ops rpm2_mac_ops =3D { + .name =3D "rpm", + .csr_offset =3D RPM2_CSR_OFFSET, + .lmac_offset =3D 20, + .int_register =3D RPM2_CMRX_SW_INT, + .int_set_reg =3D RPM2_CMRX_SW_INT_ENA_W1S, + .irq_offset =3D 1, + .int_ena_bit =3D BIT_ULL(0), + .lmac_fwi =3D RPM_LMAC_FWI, + .non_contiguous_serdes_lane =3D true, + .rx_stats_cnt =3D 43, + .tx_stats_cnt =3D 34, + .dmac_filter_count =3D 64, + .get_nr_lmacs =3D rpm2_get_nr_lmacs, + .get_lmac_type =3D rpm_get_lmac_type, + .lmac_fifo_len =3D rpm2_get_lmac_fifo_len, + .mac_lmac_intl_lbk =3D rpm_lmac_internal_loopback, + .mac_get_rx_stats =3D rpm_get_rx_stats, + .mac_get_tx_stats =3D rpm_get_tx_stats, + .mac_enadis_rx_pause_fwding =3D rpm_lmac_enadis_rx_pause_fwding, + .mac_get_pause_frm_status =3D rpm_lmac_get_pause_frm_status, + .mac_enadis_pause_frm =3D rpm_lmac_enadis_pause_frm, + .mac_pause_frm_config =3D rpm_lmac_pause_frm_config, + .mac_enadis_ptp_config =3D rpm_lmac_ptp_config, + .mac_rx_tx_enable =3D rpm_lmac_rx_tx_enable, + .mac_tx_enable =3D rpm_lmac_tx_enable, + .pfc_config =3D rpm_lmac_pfc_config, + .mac_get_pfc_frm_cfg =3D rpm_lmac_get_pfc_frm_cfg, +}; + +bool is_dev_rpm2(void *rpmd) +{ + rpm_t *rpm =3D rpmd; + + return (rpm->pdev->device =3D=3D PCI_DEVID_CN10KB_RPM); +} + +struct mac_ops *rpm_get_mac_ops(rpm_t *rpm) { - return &rpm_mac_ops; + if (is_dev_rpm2(rpm)) + return &rpm2_mac_ops; + else + return &rpm_mac_ops; } =20 static void rpm_write(rpm_t *rpm, u64 lmac, u64 offset, u64 val) @@ -52,6 +93,16 @@ static u64 rpm_read(rpm_t *rpm, u64 lmac, u64 offset) return cgx_read(rpm, lmac, offset); } =20 +/* Read HW major version to determine RPM + * MAC type 100/USX + */ +static bool is_mac_rpmusx(void *rpmd) +{ + rpm_t *rpm =3D rpmd; + + return rpm_read(rpm, 0, RPMX_CONST1) & 0x700ULL; +} + int rpm_get_nr_lmacs(void *rpmd) { rpm_t *rpm =3D rpmd; @@ -59,6 +110,13 @@ int rpm_get_nr_lmacs(void *rpmd) return hweight8(rpm_read(rpm, 0, CGXX_CMRX_RX_LMACS) & 0xFULL); } =20 +int rpm2_get_nr_lmacs(void *rpmd) +{ + rpm_t *rpm =3D rpmd; + + return hweight8(rpm_read(rpm, 0, RPM2_CMRX_RX_LMACS) & 0xFFULL); +} + int rpm_lmac_tx_enable(void *rpmd, int lmac_id, bool enable) { rpm_t *rpm =3D rpmd; @@ -222,6 +280,46 @@ static void rpm_cfg_pfc_quanta_thresh(rpm_t *rpm, int = lmac_id, } } =20 +static void rpm2_lmac_cfg_bp(rpm_t *rpm, int lmac_id, u8 tx_pause, u8 rx_p= ause) +{ + u64 cfg; + + cfg =3D rpm_read(rpm, lmac_id, RPM2_CMR_RX_OVR_BP); + if (tx_pause) { + /* Configure CL0 Pause Quanta & threshold + * for 802.3X frames + */ + rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 1, true); + cfg &=3D ~RPM2_CMR_RX_OVR_BP_EN; + } else { + /* Disable all Pause Quanta & threshold values */ + rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xffff, false); + cfg |=3D RPM2_CMR_RX_OVR_BP_EN; + cfg &=3D ~RPM2_CMR_RX_OVR_BP_BP; + } + rpm_write(rpm, lmac_id, RPM2_CMR_RX_OVR_BP, cfg); +} + +static void rpm_lmac_cfg_bp(rpm_t *rpm, int lmac_id, u8 tx_pause, u8 rx_pa= use) +{ + u64 cfg; + + cfg =3D rpm_read(rpm, 0, RPMX_CMR_RX_OVR_BP); + if (tx_pause) { + /* Configure CL0 Pause Quanta & threshold for + * 802.3X frames + */ + rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 1, true); + cfg &=3D ~RPMX_CMR_RX_OVR_BP_EN(lmac_id); + } else { + /* Disable all Pause Quanta & threshold values */ + rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xffff, false); + cfg |=3D RPMX_CMR_RX_OVR_BP_EN(lmac_id); + cfg &=3D ~RPMX_CMR_RX_OVR_BP_BP(lmac_id); + } + rpm_write(rpm, 0, RPMX_CMR_RX_OVR_BP, cfg); +} + int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id, u8 tx_pause, u8 rx_pause) { @@ -243,18 +341,11 @@ int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id= , u8 tx_pause, cfg |=3D tx_pause ? 0x0 : RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE; rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg); =20 - cfg =3D rpm_read(rpm, 0, RPMX_CMR_RX_OVR_BP); - if (tx_pause) { - /* Configure CL0 Pause Quanta & threshold for 802.3X frames */ - rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 1, true); - cfg &=3D ~RPMX_CMR_RX_OVR_BP_EN(lmac_id); - } else { - /* Disable all Pause Quanta & threshold values */ - rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xffff, false); - cfg |=3D RPMX_CMR_RX_OVR_BP_EN(lmac_id); - cfg &=3D ~RPMX_CMR_RX_OVR_BP_BP(lmac_id); - } - rpm_write(rpm, 0, RPMX_CMR_RX_OVR_BP, cfg); + if (is_dev_rpm2(rpm)) + rpm2_lmac_cfg_bp(rpm, lmac_id, tx_pause, rx_pause); + else + rpm_lmac_cfg_bp(rpm, lmac_id, tx_pause, rx_pause); + return 0; } =20 @@ -278,13 +369,16 @@ void rpm_lmac_pause_frm_config(void *rpmd, int lmac_i= d, bool enable) cfg |=3D RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE; rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg); =20 + /* Enable channel mask for all LMACS */ + if (is_dev_rpm2(rpm)) + rpm_write(rpm, lmac_id, RPM2_CMR_CHAN_MSK_OR, 0xffff); + else + rpm_write(rpm, 0, RPMX_CMR_CHAN_MSK_OR, ~0ULL); + /* Disable all PFC classes */ cfg =3D rpm_read(rpm, lmac_id, RPMX_CMRX_PRT_CBFC_CTL); cfg =3D FIELD_SET(RPM_PFC_CLASS_MASK, 0, cfg); rpm_write(rpm, lmac_id, RPMX_CMRX_PRT_CBFC_CTL, cfg); - - /* Enable channel mask for all LMACS */ - rpm_write(rpm, 0, RPMX_CMR_CHAN_MSK_OR, ~0ULL); } =20 int rpm_get_rx_stats(void *rpmd, int lmac_id, int idx, u64 *rx_stat) @@ -292,7 +386,7 @@ int rpm_get_rx_stats(void *rpmd, int lmac_id, int idx, = u64 *rx_stat) rpm_t *rpm =3D rpmd; u64 val_lo, val_hi; =20 - if (!rpm || lmac_id >=3D rpm->lmac_count) + if (!is_lmac_valid(rpm, lmac_id)) return -ENODEV; =20 mutex_lock(&rpm->lock); @@ -320,7 +414,7 @@ int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, = u64 *tx_stat) rpm_t *rpm =3D rpmd; u64 val_lo, val_hi; =20 - if (!rpm || lmac_id >=3D rpm->lmac_count) + if (!is_lmac_valid(rpm, lmac_id)) return -ENODEV; =20 mutex_lock(&rpm->lock); @@ -380,13 +474,71 @@ u32 rpm_get_lmac_fifo_len(void *rpmd, int lmac_id) return 0; } =20 +static int rpmusx_lmac_internal_loopback(rpm_t *rpm, int lmac_id, bool ena= ble) +{ + u64 cfg; + + cfg =3D rpm_read(rpm, lmac_id, RPM2_USX_PCSX_CONTROL1); + + if (enable) + cfg |=3D RPM2_USX_PCS_LBK; + else + cfg &=3D ~RPM2_USX_PCS_LBK; + rpm_write(rpm, lmac_id, RPM2_USX_PCSX_CONTROL1, cfg); + + return 0; +} + +u32 rpm2_get_lmac_fifo_len(void *rpmd, int lmac_id) +{ + u64 hi_perf_lmac, lmac_info; + rpm_t *rpm =3D rpmd; + u8 num_lmacs; + u32 fifo_len; + + lmac_info =3D rpm_read(rpm, 0, RPM2_CMRX_RX_LMACS); + /* LMACs are divided into two groups and each group + * gets half of the FIFO + * Group0 lmac_id range {0..3} + * Group1 lmac_id range {4..7} + */ + fifo_len =3D rpm->mac_ops->fifo_len / 2; + + if (lmac_id < 4) { + num_lmacs =3D hweight8(lmac_info & 0xF); + hi_perf_lmac =3D (lmac_info >> 8) & 0x3ULL; + } else { + num_lmacs =3D hweight8(lmac_info & 0xF0); + hi_perf_lmac =3D (lmac_info >> 10) & 0x3ULL; + hi_perf_lmac +=3D 4; + } + + switch (num_lmacs) { + case 1: + return fifo_len; + case 2: + return fifo_len / 2; + case 3: + /* LMAC marked as hi_perf gets half of the FIFO + * and rest 1/4th + */ + if (lmac_id =3D=3D hi_perf_lmac) + return fifo_len / 2; + return fifo_len / 4; + case 4: + default: + return fifo_len / 4; + } + return 0; +} + int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable) { rpm_t *rpm =3D rpmd; u8 lmac_type; u64 cfg; =20 - if (!rpm || lmac_id >=3D rpm->lmac_count) + if (!is_lmac_valid(rpm, lmac_id)) return -ENODEV; lmac_type =3D rpm->mac_ops->get_lmac_type(rpm, lmac_id); =20 @@ -395,6 +547,9 @@ int rpm_lmac_internal_loopback(void *rpmd, int lmac_id,= bool enable) return 0; } =20 + if (is_dev_rpm2(rpm) && is_mac_rpmusx(rpm)) + return rpmusx_lmac_internal_loopback(rpm, lmac_id, enable); + cfg =3D rpm_read(rpm, lmac_id, RPMX_MTI_PCS100X_CONTROL1); =20 if (enable) @@ -439,8 +594,8 @@ void rpm_lmac_ptp_config(void *rpmd, int lmac_id, bool = enable) =20 int rpm_lmac_pfc_config(void *rpmd, int lmac_id, u8 tx_pause, u8 rx_pause,= u16 pfc_en) { + u64 cfg, class_en, pfc_class_mask_cfg; rpm_t *rpm =3D rpmd; - u64 cfg, class_en; =20 if (!is_lmac_valid(rpm, lmac_id)) return -ENODEV; @@ -476,7 +631,10 @@ int rpm_lmac_pfc_config(void *rpmd, int lmac_id, u8 tx= _pause, u8 rx_pause, u16 p =20 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg); =20 - rpm_write(rpm, lmac_id, RPMX_CMRX_PRT_CBFC_CTL, class_en); + pfc_class_mask_cfg =3D is_dev_rpm2(rpm) ? RPM2_CMRX_PRT_CBFC_CTL : + RPMX_CMRX_PRT_CBFC_CTL; + + rpm_write(rpm, lmac_id, pfc_class_mask_cfg, class_en); =20 return 0; } diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h b/drivers/net/= ethernet/marvell/octeontx2/af/rpm.h index 77f2ef9e1425..fc20a35bd8f9 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h @@ -12,11 +12,14 @@ =20 /* PCI device IDs */ #define PCI_DEVID_CN10K_RPM 0xA060 +#define PCI_SUBSYS_DEVID_CNF10KB_RPM 0xBC00 +#define PCI_DEVID_CN10KB_RPM 0xA09F =20 /* Registers */ #define RPMX_CMRX_CFG 0x00 #define RPMX_RX_TS_PREPEND BIT_ULL(22) #define RPMX_TX_PTP_1S_SUPPORT BIT_ULL(17) +#define RPMX_CMRX_RX_ID_MAP 0x80 #define RPMX_CMRX_SW_INT 0x180 #define RPMX_CMRX_SW_INT_W1S 0x188 #define RPMX_CMRX_SW_INT_ENA_W1S 0x198 @@ -76,11 +79,28 @@ #define RPMX_MTI_MAC100X_XIF_MODE 0x8100 #define RPMX_ONESTEP_ENABLE BIT_ULL(5) #define RPMX_TS_BINARY_MODE BIT_ULL(11) +#define RPMX_CONST1 0x2008 + +/* CN10KB CSR Declaration */ +#define RPM2_CMRX_SW_INT 0x1b0 +#define RPM2_CMRX_SW_INT_ENA_W1S 0x1b8 +#define RPM2_CMR_CHAN_MSK_OR 0x3120 +#define RPM2_CMR_RX_OVR_BP_EN BIT_ULL(2) +#define RPM2_CMR_RX_OVR_BP_BP BIT_ULL(1) +#define RPM2_CMR_RX_OVR_BP 0x3130 +#define RPM2_CSR_OFFSET 0x3e00 +#define RPM2_CMRX_PRT_CBFC_CTL 0x6510 +#define RPM2_CMRX_RX_LMACS 0x100 +#define RPM2_CMRX_RX_LOGL_XON 0x3100 +#define RPM2_CMRX_RX_STAT2 0x3010 +#define RPM2_USX_PCSX_CONTROL1 0x80000 +#define RPM2_USX_PCS_LBK BIT_ULL(14) =20 /* Function Declarations */ int rpm_get_nr_lmacs(void *rpmd); u8 rpm_get_lmac_type(void *rpmd, int lmac_id); u32 rpm_get_lmac_fifo_len(void *rpmd, int lmac_id); +u32 rpm2_get_lmac_fifo_len(void *rpmd, int lmac_id); int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable); void rpm_lmac_enadis_rx_pause_fwding(void *rpmd, int lmac_id, bool enable); int rpm_lmac_get_pause_frm_status(void *cgxd, int lmac_id, u8 *tx_pause, @@ -97,4 +117,6 @@ int rpm_lmac_pfc_config(void *rpmd, int lmac_id, u8 tx_p= ause, u8 rx_pause, u16 pfc_en); int rpm_lmac_get_pfc_frm_cfg(void *rpmd, int lmac_id, u8 *tx_pause, u8 *rx_pause); +int rpm2_get_nr_lmacs(void *rpmd); +bool is_dev_rpm2(void *rpmd); #endif /* RPM_H */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/= ethernet/marvell/octeontx2/af/rvu.h index 04333f127282..7f0a64731c67 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -410,9 +410,15 @@ struct rvu_fwdata { u32 ptp_ext_tstamp; #define FWDATA_RESERVED_MEM 1022 u64 reserved[FWDATA_RESERVED_MEM]; -#define CGX_MAX 5 +#define CGX_MAX 9 #define CGX_LMACS_MAX 4 - struct cgx_lmac_fwdata_s cgx_fw_data[CGX_MAX][CGX_LMACS_MAX]; +#define CGX_LMACS_USX 8 + union { + struct cgx_lmac_fwdata_s + cgx_fw_data[CGX_MAX][CGX_LMACS_MAX]; + struct cgx_lmac_fwdata_s + cgx_fw_data_usx[CGX_MAX][CGX_LMACS_USX]; + }; /* Do not add new fields below this line */ }; =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_cgx.c index 8d9f9bbc262b..53580e0381c9 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c @@ -472,6 +472,7 @@ void rvu_cgx_disable_dmac_entries(struct rvu *rvu, u16 = pcifunc) { int pf =3D rvu_get_pf(pcifunc); int i =3D 0, lmac_count =3D 0; + struct mac_ops *mac_ops; u8 max_dmac_filters; u8 cgx_id, lmac_id; void *cgx_dev; @@ -487,7 +488,12 @@ void rvu_cgx_disable_dmac_entries(struct rvu *rvu, u16= pcifunc) rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); cgx_dev =3D cgx_get_pdata(cgx_id); lmac_count =3D cgx_get_lmac_cnt(cgx_dev); - max_dmac_filters =3D MAX_DMAC_ENTRIES_PER_CGX / lmac_count; + + mac_ops =3D get_mac_ops(cgx_dev); + if (!mac_ops) + return; + + max_dmac_filters =3D mac_ops->dmac_filter_count / lmac_count; =20 for (i =3D 0; i < max_dmac_filters; i++) cgx_lmac_addr_del(cgx_id, lmac_id, i); @@ -1114,8 +1120,15 @@ int rvu_mbox_handler_cgx_get_aux_link_info(struct rv= u *rvu, struct msg_req *req, =20 rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); =20 - memcpy(&rsp->fwdata, &rvu->fwdata->cgx_fw_data[cgx_id][lmac_id], - sizeof(struct cgx_lmac_fwdata_s)); + if (rvu->hw->lmac_per_cgx =3D=3D CGX_LMACS_USX) + memcpy(&rsp->fwdata, + &rvu->fwdata->cgx_fw_data_usx[cgx_id][lmac_id], + sizeof(struct cgx_lmac_fwdata_s)); + else + memcpy(&rsp->fwdata, + &rvu->fwdata->cgx_fw_data[cgx_id][lmac_id], + sizeof(struct cgx_lmac_fwdata_s)); + return 0; } =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_nix.c index de489e7366da..6b8747ebc08c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -3197,8 +3197,12 @@ static void rvu_get_lbk_link_max_frs(struct rvu *rvu= , u16 *max_mtu) =20 static void rvu_get_lmac_link_max_frs(struct rvu *rvu, u16 *max_mtu) { - /* RPM supports FIFO len 128 KB */ - if (rvu_cgx_get_fifolen(rvu) =3D=3D 0x20000) + int fifo_size =3D rvu_cgx_get_fifolen(rvu); + + /* RPM supports FIFO len 128 KB and RPM2 supports double the + * FIFO len to accommodate 8 LMACS + */ + if (fifo_size =3D=3D 0x20000 || fifo_size =3D=3D 0x40000) *max_mtu =3D CN10K_LMAC_LINK_MAX_FRS; else *max_mtu =3D NIC_HW_MAX_FRS; --=20 2.17.1 From nobody Sun May 5 23:38:32 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B644C4321E for ; Mon, 5 Dec 2022 07:06:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231751AbiLEHGG (ORCPT ); Mon, 5 Dec 2022 02:06:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbiLEHF4 (ORCPT ); Mon, 5 Dec 2022 02:05:56 -0500 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8680612773; Sun, 4 Dec 2022 23:05:46 -0800 (PST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B4NglHr004633; Sun, 4 Dec 2022 23:05:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=o178hs8EWCD0IbOg9ahb5PN61oe8D6hlFxhmtoqx+qk=; b=M1BLrjk5VWLAgD1Y/Bj8EOY36OHw35UKrlTlQfT5vbudCne34TzYk54s4iGjQAJyn/dF wCI9ShtJLV7P+uSBCpIWtcGK318/44DXK90kaQs8HAxxNs5tPa1gmUOtUoYG1ms8mp+V hm1U2WqjVZDqKr9C+8di8kF1m4k+I9Q6s3FaVQCE8+cgl9P9nWd91xa9DFlXxjFNRaif XDY1/VDVVtATZ+EjWexo80DNDK1DhqKGeWhOi7up1TnrA4rZwOst50xPnwz4/XEE2RbI u1xQWI80AM1tG49v1UxnUv8hFG4KZQ1eTrAijWTovsK4qrxvpfABLCK9toTQ1gi6TFd/ Ew== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3m84pumnwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 04 Dec 2022 23:05:38 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 4 Dec 2022 23:05:36 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 4 Dec 2022 23:05:36 -0800 Received: from hyd1soter3.marvell.com (unknown [10.29.37.12]) by maili.marvell.com (Postfix) with ESMTP id 6A4B73F709C; Sun, 4 Dec 2022 23:05:33 -0800 (PST) From: Hariprasad Kelam To: , CC: , , , , , , , , Subject: [net-next Patch v4 3/4] octeontx2-pf: ethtool: Implement get_fec_stats Date: Mon, 5 Dec 2022 12:35:20 +0530 Message-ID: <20221205070521.21860-4-hkelam@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221205070521.21860-1-hkelam@marvell.com> References: <20221205070521.21860-1-hkelam@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Bmg5bieOkwz3cBr2VPBGdCJMhQGy9qAF X-Proofpoint-GUID: Bmg5bieOkwz3cBr2VPBGdCJMhQGy9qAF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-05_01,2022-12-01_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch registers a callback for get_fec_stats such that FEC stats can be queried from the below command "ethtool -I --show-fec eth0" Signed-off-by: Hariprasad Kelam Signed-off-by: Sunil Kovvuri Goutham --- v3 * Dont remove existing FEC stats support over ethtool statistics (ethtool -S) v4 * Update MAC fec stats first instead of updating them on otx2_get_fwdata failure. .../marvell/octeontx2/nic/otx2_ethtool.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/dr= ivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c index 0eb74e8c553d..0f8d1a69139f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c @@ -1268,6 +1268,39 @@ static int otx2_set_link_ksettings(struct net_device= *netdev, return err; } +static void otx2_get_fec_stats(struct net_device *netdev, + struct ethtool_fec_stats *fec_stats) +{ + struct otx2_nic *pfvf =3D netdev_priv(netdev); + struct cgx_fw_data *rsp; + + otx2_update_lmac_fec_stats(pfvf); + + /* Report MAC FEC stats */ + fec_stats->corrected_blocks.total =3D pfvf->hw.cgx_fec_corr_blks; + fec_stats->uncorrectable_blocks.total =3D pfvf->hw.cgx_fec_uncorr_blks; + + rsp =3D otx2_get_fwdata(pfvf); + if (!IS_ERR(rsp) && rsp->fwdata.phy.misc.has_fec_stats && + !otx2_get_phy_fec_stats(pfvf)) { + /* Fetch fwdata again because it's been recently populated with + * latest PHY FEC stats. + */ + rsp =3D otx2_get_fwdata(pfvf); + if (!IS_ERR(rsp)) { + struct fec_stats_s *p =3D &rsp->fwdata.phy.fec_stats; + + if (pfvf->linfo.fec =3D=3D OTX2_FEC_BASER) { + fec_stats->corrected_blocks.total =3D p->brfec_corr_blks; + fec_stats->uncorrectable_blocks.total =3D p->brfec_uncorr_blks; + } else { + fec_stats->corrected_blocks.total =3D p->rsfec_corr_cws; + fec_stats->uncorrectable_blocks.total =3D p->rsfec_uncorr_cws; + } + } + } +} + static const struct ethtool_ops otx2_ethtool_ops =3D { .supported_coalesce_params =3D ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES | @@ -1298,6 +1331,7 @@ static const struct ethtool_ops otx2_ethtool_ops =3D { .get_pauseparam =3D otx2_get_pauseparam, .set_pauseparam =3D otx2_set_pauseparam, .get_ts_info =3D otx2_get_ts_info, + .get_fec_stats =3D otx2_get_fec_stats, .get_fecparam =3D otx2_get_fecparam, .set_fecparam =3D otx2_set_fecparam, .get_link_ksettings =3D otx2_get_link_ksettings, -- 2.17.1 From nobody Sun May 5 23:38:32 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB5D1C47089 for ; Mon, 5 Dec 2022 07:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbiLEHGJ (ORCPT ); Mon, 5 Dec 2022 02:06:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbiLEHF7 (ORCPT ); Mon, 5 Dec 2022 02:05:59 -0500 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D589814085; Sun, 4 Dec 2022 23:05:49 -0800 (PST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B4NmnKW014129; Sun, 4 Dec 2022 23:05:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=EEHLQDJqY4pf2q9ETg4Y+uD1vZVXrRTOAJ8XDXPyWjA=; b=TB4iRH+nXMB+zW3C7j6tX7Yvbusy+ER/Y/w0+9gFP6UZJPkRN25rYa2I+WEakG18QNvT sG1LD/PZyaOrufHyFzJ1BaS+YHHsOdzAnCPyf5HNXvE3OY72Bn4QS+qLVdEWl8cze7Qd LxbEjYBETMijOq6T8M8xM0/is3echQ/AuikDbSqQUTHwRdCPWKlhIJW2wLd7N9EP3d7i p9sc2zGPZAI2/5UMeJyn2X4HkKmLgW/ogy/R6XWcK2BR3pzT39Ae2SyRTgjh21pvlsRk ZpZwSRJfu2yL/56V5gQSfGCQn3IKBwQgSGHsNwyNKBk5fow9PxuS1awK10MxiaPOu0g3 FA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3m84pumnwt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 04 Dec 2022 23:05:42 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 4 Dec 2022 23:05:40 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 4 Dec 2022 23:05:40 -0800 Received: from hyd1soter3.marvell.com (unknown [10.29.37.12]) by maili.marvell.com (Postfix) with ESMTP id 11D333F707A; Sun, 4 Dec 2022 23:05:36 -0800 (PST) From: Hariprasad Kelam To: , CC: , , , , , , , , Subject: [net-next Patch v4 4/4] octeontx2-af: Add FEC stats for RPM/RPM_USX block Date: Mon, 5 Dec 2022 12:35:21 +0530 Message-ID: <20221205070521.21860-5-hkelam@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221205070521.21860-1-hkelam@marvell.com> References: <20221205070521.21860-1-hkelam@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FCnS32R0SV7bKTs8yMc1gfUmpSf1bE8Q X-Proofpoint-GUID: FCnS32R0SV7bKTs8yMc1gfUmpSf1bE8Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-05_01,2022-12-01_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CN10K silicon MAC block RPM and CN10KB silicon MAC block RPM_USX both support BASER and RSFEC modes. Also MAC (CGX) on OcteonTx2 silicon variants and MAC (RPM) on OcteonTx3 CN10K are different and FEC stats need to be read differently. CN10KB MAC block (RPM_USX) fec csr offsets are same as CN10K MAC block (RPM) mac_ops points to same fn(). Upper layer interface between RVU AF and PF netdev is kept same. Based on silicon variant appropriate fn() pointer is called to read FEC stats Signed-off-by: Hariprasad Kelam Signed-off-by: Sunil Kovvuri Goutham --- .../net/ethernet/marvell/octeontx2/af/cgx.c | 5 ++ .../marvell/octeontx2/af/lmac_common.h | 3 + .../net/ethernet/marvell/octeontx2/af/rpm.c | 58 +++++++++++++++++++ .../net/ethernet/marvell/octeontx2/af/rpm.h | 14 ++++- .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 4 +- 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/= ethernet/marvell/octeontx2/af/cgx.c index 242c5b0eb15d..b2b71fe80d61 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -742,6 +742,10 @@ int cgx_get_fec_stats(void *cgxd, int lmac_id, struct = cgx_fec_stats_rsp *rsp) =20 if (!cgx || lmac_id >=3D cgx->lmac_count) return -ENODEV; + + if (cgx->lmac_idmap[lmac_id]->link_info.fec =3D=3D OTX2_FEC_NONE) + return 0; + fec_stats_count =3D cgx_set_fec_stats_count(&cgx->lmac_idmap[lmac_id]->link_info); if (cgx->lmac_idmap[lmac_id]->link_info.fec =3D=3D OTX2_FEC_BASER) { @@ -1749,6 +1753,7 @@ static struct mac_ops cgx_mac_ops =3D { .mac_lmac_intl_lbk =3D cgx_lmac_internal_loopback, .mac_get_rx_stats =3D cgx_get_rx_stats, .mac_get_tx_stats =3D cgx_get_tx_stats, + .get_fec_stats =3D cgx_get_fec_stats, .mac_enadis_rx_pause_fwding =3D cgx_lmac_enadis_rx_pause_fwding, .mac_get_pause_frm_status =3D cgx_lmac_get_pause_frm_status, .mac_enadis_pause_frm =3D cgx_lmac_enadis_pause_frm, diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/driv= ers/net/ethernet/marvell/octeontx2/af/lmac_common.h index 386fb73ad366..39aaf0e4467d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h @@ -126,6 +126,9 @@ struct mac_ops { int (*mac_get_pfc_frm_cfg)(void *cgxd, int lmac_id, u8 *tx_pause, u8 *rx_pause); =20 + /* FEC stats */ + int (*get_fec_stats)(void *cgxd, int lmac_id, + struct cgx_fec_stats_rsp *rsp); }; =20 struct cgx { diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c b/drivers/net/= ethernet/marvell/octeontx2/af/rpm.c index a15a59d5dff8..de0d88dd10d6 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c @@ -27,6 +27,7 @@ static struct mac_ops rpm_mac_ops =3D { .mac_lmac_intl_lbk =3D rpm_lmac_internal_loopback, .mac_get_rx_stats =3D rpm_get_rx_stats, .mac_get_tx_stats =3D rpm_get_tx_stats, + .get_fec_stats =3D rpm_get_fec_stats, .mac_enadis_rx_pause_fwding =3D rpm_lmac_enadis_rx_pause_fwding, .mac_get_pause_frm_status =3D rpm_lmac_get_pause_frm_status, .mac_enadis_pause_frm =3D rpm_lmac_enadis_pause_frm, @@ -57,6 +58,7 @@ static struct mac_ops rpm2_mac_ops =3D { .mac_lmac_intl_lbk =3D rpm_lmac_internal_loopback, .mac_get_rx_stats =3D rpm_get_rx_stats, .mac_get_tx_stats =3D rpm_get_tx_stats, + .get_fec_stats =3D rpm_get_fec_stats, .mac_enadis_rx_pause_fwding =3D rpm_lmac_enadis_rx_pause_fwding, .mac_get_pause_frm_status =3D rpm_lmac_get_pause_frm_status, .mac_enadis_pause_frm =3D rpm_lmac_enadis_pause_frm, @@ -655,3 +657,59 @@ int rpm_lmac_get_pfc_frm_cfg(void *rpmd, int lmac_id,= u8 *tx_pause, u8 *rx_paus =20 return 0; } + +int rpm_get_fec_stats(void *rpmd, int lmac_id, struct cgx_fec_stats_rsp *r= sp) +{ + u64 val_lo, val_hi; + rpm_t *rpm =3D rpmd; + u64 cfg; + + if (!is_lmac_valid(rpm, lmac_id)) + return -ENODEV; + + if (rpm->lmac_idmap[lmac_id]->link_info.fec =3D=3D OTX2_FEC_NONE) + return 0; + + if (rpm->lmac_idmap[lmac_id]->link_info.fec =3D=3D OTX2_FEC_BASER) { + val_lo =3D rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_VL0_CCW_LO); + val_hi =3D rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_CW_HI); + rsp->fec_corr_blks =3D (val_hi << 16 | val_lo); + + val_lo =3D rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_VL0_NCCW_LO); + val_hi =3D rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_CW_HI); + rsp->fec_uncorr_blks =3D (val_hi << 16 | val_lo); + + /* 50G uses 2 Physical serdes lines */ + if (rpm->lmac_idmap[lmac_id]->link_info.lmac_type_id =3D=3D + LMAC_MODE_50G_R) { + val_lo =3D rpm_read(rpm, lmac_id, + RPMX_MTI_FCFECX_VL1_CCW_LO); + val_hi =3D rpm_read(rpm, lmac_id, + RPMX_MTI_FCFECX_CW_HI); + rsp->fec_corr_blks +=3D (val_hi << 16 | val_lo); + + val_lo =3D rpm_read(rpm, lmac_id, + RPMX_MTI_FCFECX_VL1_NCCW_LO); + val_hi =3D rpm_read(rpm, lmac_id, + RPMX_MTI_FCFECX_CW_HI); + rsp->fec_uncorr_blks +=3D (val_hi << 16 | val_lo); + } + } else { + /* enable RS-FEC capture */ + cfg =3D rpm_read(rpm, 0, RPMX_MTI_STAT_STATN_CONTROL); + cfg |=3D RPMX_RSFEC_RX_CAPTURE | BIT(lmac_id); + rpm_write(rpm, 0, RPMX_MTI_STAT_STATN_CONTROL, cfg); + + val_lo =3D rpm_read(rpm, 0, + RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_2); + val_hi =3D rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC); + rsp->fec_corr_blks =3D (val_hi << 32 | val_lo); + + val_lo =3D rpm_read(rpm, 0, + RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_3); + val_hi =3D rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC); + rsp->fec_uncorr_blks =3D (val_hi << 32 | val_lo); + } + + return 0; +} diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h b/drivers/net/= ethernet/marvell/octeontx2/af/rpm.h index fc20a35bd8f9..22147b4c2137 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h @@ -25,7 +25,6 @@ #define RPMX_CMRX_SW_INT_ENA_W1S 0x198 #define RPMX_CMRX_LINK_CFG 0x1070 #define RPMX_MTI_PCS100X_CONTROL1 0x20000 -#define RPMX_MTI_LPCSX_CONTROL1 0x30000 #define RPMX_MTI_PCS_LBK BIT_ULL(14) #define RPMX_MTI_LPCSX_CONTROL(id) (0x30000 | ((id) * 0x100)) =20 @@ -81,6 +80,18 @@ #define RPMX_TS_BINARY_MODE BIT_ULL(11) #define RPMX_CONST1 0x2008 =20 +/* FEC stats */ +#define RPMX_MTI_STAT_STATN_CONTROL 0x10018 +#define RPMX_MTI_STAT_DATA_HI_CDC 0x10038 +#define RPMX_RSFEC_RX_CAPTURE BIT_ULL(27) +#define RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_2 0x40050 +#define RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_3 0x40058 +#define RPMX_MTI_FCFECX_VL0_CCW_LO 0x38618 +#define RPMX_MTI_FCFECX_VL0_NCCW_LO 0x38620 +#define RPMX_MTI_FCFECX_VL1_CCW_LO 0x38628 +#define RPMX_MTI_FCFECX_VL1_NCCW_LO 0x38630 +#define RPMX_MTI_FCFECX_CW_HI 0x38638 + /* CN10KB CSR Declaration */ #define RPM2_CMRX_SW_INT 0x1b0 #define RPM2_CMRX_SW_INT_ENA_W1S 0x1b8 @@ -119,4 +130,5 @@ int rpm_lmac_get_pfc_frm_cfg(void *rpmd, int lmac_id, u= 8 *tx_pause, u8 *rx_pause); int rpm2_get_nr_lmacs(void *rpmd); bool is_dev_rpm2(void *rpmd); +int rpm_get_fec_stats(void *cgxd, int lmac_id, struct cgx_fec_stats_rsp *r= sp); #endif /* RPM_H */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_cgx.c index 53580e0381c9..438b212fb54a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c @@ -579,6 +579,7 @@ int rvu_mbox_handler_cgx_fec_stats(struct rvu *rvu, struct cgx_fec_stats_rsp *rsp) { int pf =3D rvu_get_pf(req->hdr.pcifunc); + struct mac_ops *mac_ops; u8 cgx_idx, lmac; void *cgxd; =20 @@ -587,7 +588,8 @@ int rvu_mbox_handler_cgx_fec_stats(struct rvu *rvu, rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_idx, &lmac); =20 cgxd =3D rvu_cgx_pdata(cgx_idx, rvu); - return cgx_get_fec_stats(cgxd, lmac, rsp); + mac_ops =3D get_mac_ops(cgxd); + return mac_ops->get_fec_stats(cgxd, lmac, rsp); } =20 int rvu_mbox_handler_cgx_mac_addr_set(struct rvu *rvu, --=20 2.17.1