From patchwork Sat Dec 18 21:49:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Foster X-Patchwork-Id: 12686441 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 04BAAC4332F for ; Sat, 18 Dec 2021 21:50:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234620AbhLRVuQ (ORCPT ); Sat, 18 Dec 2021 16:50:16 -0500 Received: from mail-mw2nam10on2096.outbound.protection.outlook.com ([40.107.94.96]:43520 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234479AbhLRVuK (ORCPT ); Sat, 18 Dec 2021 16:50:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jW2U9RYaK324VctffosFqWhu64K4ApKPz2wSJx8ELGgrwrgE+ss6BFZCvOqC3hp5g7rfTzXcrnOyK2Gr1Cn+gSXWZRN7iME+N/Xd6MU+XC/Zh3ULuq3AMOVO+gE010D3F9LorbCW+uuTZXTgaDw9XkQOr03YUciFn2ZA+7XVcIWyLHnKHuDBRidxj2gpnPtYx1FCaisbkIBg6h3K9PRAnzUCfalyu1rcgkG2r/A1b8b1JhbbnMF3gf7kQeEqmSWTzEtlWaDd9Y5JXsLkrZpfYDZBxr2zvR4j3AQORXRnO3EgyTig0l0jHCeDmCm/nT2kpubnnQv5TQCZvViB8arJnA== 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=gMKqmCj/Dixm2MwPAU5k40NXtdtFq9m8iCvAqRZtU4U=; b=H7pUESj1I+6fO68mnVLp1F3HBJ2Pgd36vvKMczBfQeoauJnexvQoaLd919MvhYm06szANHI26Ot5WuaO3PiVnyjEt0gfyE8+at3+Bo1WtuCwQfWPCVhW+AU1x1lkpF/BeX8IqZ5uQFFv9cRIh2uZM7aOtijK50AO+a4fZ+FTy803y7l5w3ywbWWS4DGaPRRiHgzpEBpCKBJ9FpRddWm8P/S8Cr8Lmh/iXwsqzz21/EJoLda9bkDNHaSd/+oYOreNSkX1Oaf38OQWOCJDfmvuAzkTKsIpq+FP7cswero8eQNepEe45sbQ77zsGw4TIbsV8sKhjcaWKQq0o/igYU3jzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=in-advantage.com; dmarc=pass action=none header.from=in-advantage.com; dkim=pass header.d=in-advantage.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inadvantage.onmicrosoft.com; s=selector2-inadvantage-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gMKqmCj/Dixm2MwPAU5k40NXtdtFq9m8iCvAqRZtU4U=; b=fhjOOX5Gj77HrQU/6BamxX7bMByYz9WcFcXy5r7Q2mPsr1gIz1wqbQgQH61qifyT3f3vvnLfYUK3vZ1++vVnGmbLb14zd6NeN6h92NJIKbIf48EvjtaTcvmX4CIxNP5lLpP/x9MSZjHKINvKw7QJgt55qEkE7K6IGwDcbESLMyI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=in-advantage.com; Received: from MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) by CO6PR10MB5633.namprd10.prod.outlook.com (2603:10b6:303:148::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.17; Sat, 18 Dec 2021 21:50:08 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::2d52:2a96:7e6c:460f]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::2d52:2a96:7e6c:460f%4]) with mapi id 15.20.4801.017; Sat, 18 Dec 2021 21:50:07 +0000 From: Colin Foster To: linux-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Russell King , Heiner Kallweit , Jakub Kicinski , "David S. Miller" , Florian Fainelli , Vivien Didelot , Andrew Lunn , UNGLinuxDriver@microchip.com, Alexandre Belloni , Claudiu Manoil , Vladimir Oltean , Lee Jones Subject: [RFC v5 net-next 03/13] net: mscc: ocelot: expose ocelot wm functions Date: Sat, 18 Dec 2021 13:49:44 -0800 Message-Id: <20211218214954.109755-4-colin.foster@in-advantage.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218214954.109755-1-colin.foster@in-advantage.com> References: <20211218214954.109755-1-colin.foster@in-advantage.com> X-ClientProxiedBy: MWHPR02CA0011.namprd02.prod.outlook.com (2603:10b6:300:4b::21) To MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87fe480e-3039-4d0f-e28b-08d9c2705b63 X-MS-TrafficTypeDiagnostic: CO6PR10MB5633:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4T5HjLC9ZTes8pxQQI52OeRSxYAjauutj1joaUO5O9KKmzO0ESu/0ClfjOvVxqxbN/rgd8IXnvFsOUoXGIjPbmRxF4z4y2ua74AIzQRINtHDAHRbEoDzz9A+4krGenXZmcGZnIfDZxZAjs7ia/+GfSZz9aTgiaIUHZ3SofqkgUIXI1NhsqG08YBeW4FyPjiJKfK0OOiStg3cC40NyhtmV3Sak+r+YTW8v9IJPQW1hoNjJhP8Mbo8Y3noJ1wAmgiva1I7QvKTvMvA8t1a9YEp++y/TGJbHcw9ep2fB3dQi68tK5XjrlNl7YlPOepmLsYhT/D4IUMWp/697KyyeKk7jVohCZ+tl6x8Ha+pzCJTkIbPIUuYqFFbaUDrOKPJgS2OQtfUc3XTBb3qy7chsFuYRx0VY5ifdOaIuQg/qq+1Qpx74zDQijFWOAc2cFFztqjdvr4L2KA2wpF3KoJQ4+rBUT2bwYfshcsc8IXi8OH0GLroj5CS75D0S0JbytRwlds9BnQ9cjXpJrMZfYSICvNtDkPuwlYXhzUVDUrTI2OeXAAnES7zDyXN9htXx4iy4BiJd9p6pBwwieobvqMZGJZBHKzp9y3nplqLd/aEtrDSNuMQs/ipsyABiMAF6mQy/7g0Fk428Nae1knuUCx6tYw+kgxHgcUV1pxwG9hIz8yw3QgiE7LwqFt+eIXVJwa/2b+2JD5FLOFlic3b5Ud9UklQkQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2351.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39830400003)(396003)(366004)(346002)(376002)(136003)(6486002)(6506007)(7416002)(2906002)(36756003)(6512007)(26005)(86362001)(66556008)(66476007)(186003)(1076003)(6666004)(4326008)(83380400001)(66946007)(2616005)(44832011)(8936002)(8676002)(316002)(54906003)(38100700002)(5660300002)(508600001)(52116002)(38350700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ff9IuBx0xjSi2U5kmCUlA0+57HgecFLJ0jPthUdWgZdwQXYVoWL7l0SI1ComcTVDyE39cu68FvC2NF75zHbu7sH+LLhexh+5OjBYj8MNFkC4BXF81QDSdUAwBh9qYeaEy1KFmnu9K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u9Mf0PKMYLQIcwsGo1ksA2JDPTb1gBdIbodh8D5cjA2O8Kj0Epzh7a0cjfCotjermICA3qQeQddvQMfSiiljjnEhO3aDSDW6KSELw55SJv2gtJNwiQGH7K1QrvbmPBy9OOhWdPBP96FdvIFl/jI6o0pm7k4Uw2bD9f9y7ZnUsX/kSsZ/WcvvD/0cIPopsAvjZOkLHbHMySiWAFSw7Wl1mx2tL4IIGuXM94DF/IwdT+miFwTfX02IUV0xfwsGJd2f1w/3e60x9ZHWht7cQpQ5M3SQ458Y1EbRCLgWl2wFtC8kIDVKFOLF3aOadC715I7W8VGoBYfTYFYf2wA22rxvOhF4WUHzK/pduktUHLxopoJiLcH6eFr1CmLaaGIm2YZkVsj5wtq3ojtgQuMSht+7CVxkazUuiNLEO8BDUqJ4j1aeFJafYAYgKBcmcW+qZN4AxDq/G69gR7hWSNIglzQG5bXM2XuAKGg== X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87fe480e-3039-4d0f-e28b-08d9c2705b63 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2021 21:50:07.7690 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 48e842ca-fbd8-4633-a79d-0c955a7d3aae X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: spVaGF8tmTSzzLpxKTWumXd961pg+fzReTzo5McUBUHs0GPdhNDsvbj0YQ0erJgpyWm5eXlWt6cFQlMZ6Jt9AGlofW/m24OEZnUT0r2GJHo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5633 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Expose ocelot_wm functions so they can be shared with other drivers. Signed-off-by: Colin Foster Reviewed-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_devlink.c | 31 ++++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot_vsc7514.c | 28 ------------------- include/soc/mscc/ocelot.h | 5 ++++ 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_devlink.c b/drivers/net/ethernet/mscc/ocelot_devlink.c index b8737efd2a85..d9ea75a14f2f 100644 --- a/drivers/net/ethernet/mscc/ocelot_devlink.c +++ b/drivers/net/ethernet/mscc/ocelot_devlink.c @@ -487,6 +487,37 @@ static void ocelot_watermark_init(struct ocelot *ocelot) ocelot_setup_sharing_watermarks(ocelot); } +/* Watermark encode + * Bit 8: Unit; 0:1, 1:16 + * Bit 7-0: Value to be multiplied with unit + */ +u16 ocelot_wm_enc(u16 value) +{ + WARN_ON(value >= 16 * BIT(8)); + + if (value >= BIT(8)) + return BIT(8) | (value / 16); + + return value; +} +EXPORT_SYMBOL(ocelot_wm_enc); + +u16 ocelot_wm_dec(u16 wm) +{ + if (wm & BIT(8)) + return (wm & GENMASK(7, 0)) * 16; + + return wm; +} +EXPORT_SYMBOL(ocelot_wm_dec); + +void ocelot_wm_stat(u32 val, u32 *inuse, u32 *maxuse) +{ + *inuse = (val & GENMASK(23, 12)) >> 12; + *maxuse = val & GENMASK(11, 0); +} +EXPORT_SYMBOL(ocelot_wm_stat); + /* Pool size and type are fixed up at runtime. Keeping this structure to * look up the cell size multipliers. */ diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 4f4a495a60ad..5e526545ef67 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -307,34 +307,6 @@ static int ocelot_reset(struct ocelot *ocelot) return 0; } -/* Watermark encode - * Bit 8: Unit; 0:1, 1:16 - * Bit 7-0: Value to be multiplied with unit - */ -static u16 ocelot_wm_enc(u16 value) -{ - WARN_ON(value >= 16 * BIT(8)); - - if (value >= BIT(8)) - return BIT(8) | (value / 16); - - return value; -} - -static u16 ocelot_wm_dec(u16 wm) -{ - if (wm & BIT(8)) - return (wm & GENMASK(7, 0)) * 16; - - return wm; -} - -static void ocelot_wm_stat(u32 val, u32 *inuse, u32 *maxuse) -{ - *inuse = (val & GENMASK(23, 12)) >> 12; - *maxuse = val & GENMASK(11, 0); -} - static const struct ocelot_ops ocelot_ops = { .reset = ocelot_reset, .wm_enc = ocelot_wm_enc, diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index a641c9cc6f3f..37bc9d647bc2 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -812,6 +812,11 @@ void ocelot_deinit(struct ocelot *ocelot); void ocelot_init_port(struct ocelot *ocelot, int port); void ocelot_deinit_port(struct ocelot *ocelot, int port); +/* Watermark interface */ +u16 ocelot_wm_enc(u16 value); +u16 ocelot_wm_dec(u16 wm); +void ocelot_wm_stat(u32 val, u32 *inuse, u32 *maxuse); + /* DSA callbacks */ void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data); void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);