From patchwork Thu Jan 19 12:27:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13107814 X-Patchwork-Delegate: kuba@kernel.org 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 9AA33C00A5A for ; Thu, 19 Jan 2023 12:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbjASM3T (ORCPT ); Thu, 19 Jan 2023 07:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbjASM2E (ORCPT ); Thu, 19 Jan 2023 07:28:04 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2079.outbound.protection.outlook.com [40.107.14.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9190F71F17; Thu, 19 Jan 2023 04:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S3IZUkN22D2m87LpMXMKotSGmSTUr3aTwK3oBKv8Li8JskXSDjW2oyXnb2idQRXH4R0htJM2cYwmg/dCqObSEUxs3F4Q8//AsoHlUOMdkbRP8ZMX4xCDLlTg+Mh9aBYgkfhamNOAZct7exLstBZbPG9EJ6DNnSv5AmRgJOMPX+XH/5/ZZuYe8VJOzeF5tV2pVYDFBeqHNoFp/nNkDHgqAPZJ1NyJCze136vRcMQP+p2bNVBY1Nj3KXbahxwyZ9fz5VqjMLr+3jsp+ftCpcVgEq2Al0KEmE/4/f56ktZ/AtGDlnx3CUUHMlR98soslYXrOG11XpTDmID3OKmt2pUJkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M+vYijF6RivZml5xLzO5xYG1FrZUa+bWRjEFZw72mzg=; b=YCvIcBp0GhzhbqPUbMZCm8ZKEMT4iX0puBimk0Cgui1HTPcyu4ZLMFGUmtrNlnuf3q9/dCtyvNi4/LYyG8kTf3GEghx7jbKVtNrPsXUdCHiZ7cx1TehnJ2g395NV0QKDqGZmsUYONt4ZuX06kdtMnUMYZznwF+rhLR5VNkW4yK63766MhH/gwkDICPkOeZ/1r3vZ1XXzkWLZdicKcCQwQPZ/Kn2QcbSpJQqHcxLJoiBZbm/J4lS/bEDagdFS2a76JAG0f8sRBmSdu2sUlSgrbNOJo4LEGFxl2y8ydczW+mTTE8QkgSXqNBp6knW1COvQKiSwueYBg6oRrGpwnNnUKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M+vYijF6RivZml5xLzO5xYG1FrZUa+bWRjEFZw72mzg=; b=XuxVV5CyRDH1NdCdTNoGV/12elTr9pbjpt/Cq8QAZoRDdkTLm0r0nl773Pc4Zsq1TUlNsAcvHtWqTxwdIUH2Ol/slHGB97QbHSJ1511bEdrca7hdtiZiY/HEXmzKzBfgQUQxU6pnCojD0iKUWPnxdiH2gXX0lMD3hGdMmknguCQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by PAXPR04MB9376.eurprd04.prod.outlook.com (2603:10a6:102:2b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.24; Thu, 19 Jan 2023 12:28:00 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%4]) with mapi id 15.20.6002.024; Thu, 19 Jan 2023 12:27:59 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Michal Kubecek , Claudiu Manoil , Vinicius Costa Gomes , Xiaoliang Yang , Kurt Kanzenbach , Rui Sousa , Ferenc Fejes , Pranavi Somisetty , Harini Katakam , Colin Foster , UNGLinuxDriver@microchip.com, Alexandre Belloni , Andrew Lunn , Florian Fainelli Subject: [PATCH v4 net-next 10/12] net: mscc: ocelot: hide access to ocelot_stats_layout behind a helper Date: Thu, 19 Jan 2023 14:27:02 +0200 Message-Id: <20230119122705.73054-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119122705.73054-1-vladimir.oltean@nxp.com> References: <20230119122705.73054-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM8P189CA0020.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:218::25) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PAXPR04MB9376:EE_ X-MS-Office365-Filtering-Correlation-Id: 29047ac0-37ef-4995-2b7a-08dafa1899f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y2WfE8iYJN6c4PSFZljXYuktCXh1Ln4QITlmguO61OPbOUjAnslMEzyg7F++/7A+2OZPUSzU2cetXqzuFgGfzyH0nVa4UgBFy7orv11B4yhESzHT59GlIg8YekSCv0PhNU49eeaRow41ol85U6gB9xUF6Izr3JwPqDekEf9jiuD+dmrt0JhYTI7ojBQkI76jJQ6BglW7oeoP0P/tgVCLJfZucIqgEBXfyO0+4Ri2pTXf1Iqp/0VFfvreHlnOYx54xxDYBrlwlgInATqS16UDqOTkS2gX5Hhl+JtmmCDdcG2H6jG+bzILaYsGy22ok2zY7YgvRastZGE7LD214cTrPVTzjw/zvIjav1Rdx8ESrGQxaQZAXRCoSaGQo6A17IkIcPIWhsVSRoYGLFpvFwYLy4ksv8urIJ1P5jx7DIssN5sVLeiHGVCP/0mZrXAxX2QuWAgVjO6y+R/E6WOoX4Sl5ehw5A1u7V5YYZ+7sTWVEa0UZMhxRtQ9YOCe95ILNUrysZ9rLnvsSMug0n8lpqQPsmhjvFr+XMHCVNVs0419iX6zGYnzhOFttWAx/DUvlbRHVKtntC88DneJZOYbZ6Ddhj1FSBls1HAnd/mmIdBi88X631j7xUqueeCgiIELkYVIpIL/CVZTii6ZsCsUoGtGmILFhdaWUtW1SdIAVsBF2c7w2ZfQeJOj0uVJdAI/9cCCJzjeQJn6Yxjl72CqMcqAog== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(376002)(136003)(346002)(366004)(451199015)(6506007)(66946007)(66476007)(44832011)(66556008)(7416002)(8936002)(5660300002)(2906002)(38350700002)(38100700002)(316002)(6666004)(54906003)(52116002)(86362001)(36756003)(4326008)(6486002)(478600001)(6916009)(41300700001)(8676002)(26005)(1076003)(6512007)(186003)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0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wvGXCa6JrvW73SFuY1noepaS+j9t8kgqPTJAzCvwm0T+DwuaO5mZoqykglRQaanyrsCDhKIFdFXMhjbeaG7QWpX1VEd2T+u9t/buTY0u2Nbcw7V4AAPQnhUtt2hblSqSiFEBsvQjz7QAgvuJCMFOl/oVDfamOetXZozVrGNrSUvgTy7T9M6ePKl3UXbuqnGTxHWx+1L2saBjPj1dWEOQa7rN8kAE9oGUmvmRipETmvTzhyCKH+eMs+Bz9kLMcYnXQ0WcWpOpT7gEqyQQ2vq7HYMGW7btPa5dA2ZDk72CYkUb6vP1S1r2G+DyXLY8+RyL6I+UUha8ay5PcO5n7gxM56BsCza2buo1T6xckNT71v3Hueh0G/JmBQf/XR/Ld58ik9Tn039t7Y96xKBouu8m6YH0ifWkcDtMoLTk9KDiCSO/61UFdSRKAcd1kjI369JGm03ojIlrs0VpGiSQXfN9z57ytrCer5XvWZXVlXNg49dcdcZPAVrmM7KtxcjfGXWESBDP5dGZ3Q4JLjXPwCGeof5UcutGXShLugpFbzSU+VwUGSg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29047ac0-37ef-4995-2b7a-08dafa1899f9 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2023 12:27:59.8561 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /uTlCyRQBC6WR6bHOudwUyiRu/QpOFwOf9rs79DAGA8MEFJ52h7UnyqXBmMsnCZfualruhQpfWdtRzSdFzik8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9376 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Some hardware instances of the ocelot driver support the MAC Merge layer, which gives access to an extra preemptible MAC. This has implications upon the statistics. There will be a stats layout when MM isn't supported, and a different one when it is. The ocelot_stats_layout() helper will return the correct one. In preparation of that, refactor the existing code to use this helper. Signed-off-by: Vladimir Oltean --- v2->v4: none v1->v2: patch is new (v1 was written for enetc) drivers/net/ethernet/mscc/ocelot_stats.c | 40 +++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c index 01306172b7f7..551e3cbfae79 100644 --- a/drivers/net/ethernet/mscc/ocelot_stats.c +++ b/drivers/net/ethernet/mscc/ocelot_stats.c @@ -228,6 +228,12 @@ static const struct ocelot_stat_layout ocelot_stats_layout[OCELOT_NUM_STATS] = { OCELOT_COMMON_STATS, }; +static const struct ocelot_stat_layout * +ocelot_get_stats_layout(struct ocelot *ocelot) +{ + return ocelot_stats_layout; +} + /* Read the counters from hardware and keep them in region->buf. * Caller must hold &ocelot->stat_view_lock. */ @@ -306,16 +312,19 @@ static void ocelot_check_stats_work(struct work_struct *work) void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data) { + const struct ocelot_stat_layout *layout; int i; if (sset != ETH_SS_STATS) return; + layout = ocelot_get_stats_layout(ocelot); + for (i = 0; i < OCELOT_NUM_STATS; i++) { - if (ocelot_stats_layout[i].name[0] == '\0') + if (layout[i].name[0] == '\0') continue; - memcpy(data, ocelot_stats_layout[i].name, ETH_GSTRING_LEN); + memcpy(data, layout[i].name, ETH_GSTRING_LEN); data += ETH_GSTRING_LEN; } } @@ -350,13 +359,16 @@ static void ocelot_port_stats_run(struct ocelot *ocelot, int port, void *priv, int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) { + const struct ocelot_stat_layout *layout; int i, num_stats = 0; if (sset != ETH_SS_STATS) return -EOPNOTSUPP; + layout = ocelot_get_stats_layout(ocelot); + for (i = 0; i < OCELOT_NUM_STATS; i++) - if (ocelot_stats_layout[i].name[0] != '\0') + if (layout[i].name[0] != '\0') num_stats++; return num_stats; @@ -366,14 +378,17 @@ EXPORT_SYMBOL(ocelot_get_sset_count); static void ocelot_port_ethtool_stats_cb(struct ocelot *ocelot, int port, void *priv) { + const struct ocelot_stat_layout *layout; u64 *data = priv; int i; + layout = ocelot_get_stats_layout(ocelot); + /* Copy all supported counters */ for (i = 0; i < OCELOT_NUM_STATS; i++) { int index = port * OCELOT_NUM_STATS + i; - if (ocelot_stats_layout[i].name[0] == '\0') + if (layout[i].name[0] == '\0') continue; *data++ = ocelot->stats[index]; @@ -602,16 +617,19 @@ EXPORT_SYMBOL(ocelot_port_get_stats64); static int ocelot_prepare_stats_regions(struct ocelot *ocelot) { struct ocelot_stats_region *region = NULL; + const struct ocelot_stat_layout *layout; unsigned int last = 0; int i; INIT_LIST_HEAD(&ocelot->stats_regions); + layout = ocelot_get_stats_layout(ocelot); + for (i = 0; i < OCELOT_NUM_STATS; i++) { - if (!ocelot_stats_layout[i].reg) + if (!layout[i].reg) continue; - if (region && ocelot_stats_layout[i].reg == last + 4) { + if (region && layout[i].reg == last + 4) { region->count++; } else { region = devm_kzalloc(ocelot->dev, sizeof(*region), @@ -620,17 +638,17 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot) return -ENOMEM; /* enum ocelot_stat must be kept sorted in the same - * order as ocelot_stats_layout[i].reg in order to have - * efficient bulking + * order as layout[i].reg in order to have efficient + * bulking */ - WARN_ON(last >= ocelot_stats_layout[i].reg); + WARN_ON(last >= layout[i].reg); - region->base = ocelot_stats_layout[i].reg; + region->base = layout[i].reg; region->count = 1; list_add_tail(®ion->node, &ocelot->stats_regions); } - last = ocelot_stats_layout[i].reg; + last = layout[i].reg; } list_for_each_entry(region, &ocelot->stats_regions, node) {