From patchwork Sat Jun 8 14:35:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolei Wang X-Patchwork-Id: 13691016 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67F79C25B76 for ; Sat, 8 Jun 2024 14:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=8qRu+EbmOyZKrD91AXZcKg8r3/y7LnT+Rw9yAF9E5mk=; b=jUZH0/n9xDxUah dGPLJ8JUEJWN7jRewS8FO8KLmD+BXOuWiEvUod1y3gHlTvbaEhJ0Iw3hIR9fnM3rjBgSuOq1M4Eod xbDGYR8YEMOmA/rJE9otoYbhM8hBeRInQpQqi+V/AkJKS4nfoDo80RYB5FPjM3QPb7cpHWa3DVdMU CnYJUsJ4lO7jtNM0eEFqbEIySo0w6wIXB+n3fEHc+29f57/8bAPsbu2WYXxPsd4wD/4tXsyNR/E29 owgo8IQzawCKu5GBip1QczagMTBcyk7XObEUYhspZ6X1D7sxrUbgM1GJToj+MMc/PbyzbhWJKaTi/ VLcCCE8Yl8p5StdXgaQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFxAx-000000006fk-4BgN; Sat, 08 Jun 2024 14:36:12 +0000 Received: from mx0a-0064b401.pphosted.com ([205.220.166.238]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFxAu-000000006eP-3EGs for linux-arm-kernel@lists.infradead.org; Sat, 08 Jun 2024 14:36:10 +0000 Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 458ER4mj030089; Sat, 8 Jun 2024 07:35:47 -0700 Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3ymptg02dp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Jun 2024 07:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g3hW28OPCci4sb7VW1aUasE9RzhYoDucT6B4jaIUhJG2D+n5K8qlJRdksxsy6Q/zSzh5RJHVvF0QeBsAGOJ+43v89CopwoYIsB/7iOB4YAUwPX9J0ll4VhD340xNSW98hjs8qLWvXyJU5qsQ6BffZraQcruhVRkmeTHvdFYRSCsB4GsdLPym3oOO6qpAHuGZ8yNCLBwTTM+VXW/tW1NseFesry1ktZwJEr3mzJLBEDRPR9ZKR03dItWVEZ3o2e15i319pwQVkC3v0UvtxzOwvgTKjjUgcZPVTbEgSGdB064MCNmoi58PApH5ctYTDMjqo5G1fduA653K3PSDHgKJqw== 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=sFJEl64zBMSAgZ+Z+2VWJ8FB4Fnp91WtS2ddtwyfWjM=; b=n2V/dHRyc8f1C+G1IpwH4jBMI5S0L9OMiD/C1JZHZp9BPyNL/oTN3oAony8XSlfjhIOoFLGv3EDVXuVnPTUTxnRwcHIv3jSBGRKvt1/bRLpcxwW5qemDKVmY3uyEJpnILC+X28c7Apdbsu/eE4RSL2wCDWiJdk1YFvmpfPJuaBfqRoth3BBIzJ05weKpIN4Sofbt5jkm5Grop80/VlQCRiMpiJMwIWjYS+1aSo26uEpMexb8wZZIPsZ3nlZ6B6GYHNU4hwDyTLrLEAqpZYKfa5d76qfNZulHvkvnKd3RIkW1srV4LDJQnPt6zIPXVif1LwcO7XuyF95E+4FM3Dxm+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) by MW4PR11MB7103.namprd11.prod.outlook.com (2603:10b6:303:225::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.33; Sat, 8 Jun 2024 14:35:44 +0000 Received: from MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::3c2c:a17f:2516:4dc8]) by MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::3c2c:a17f:2516:4dc8%4]) with mapi id 15.20.7633.036; Sat, 8 Jun 2024 14:35:44 +0000 From: Xiaolei Wang To: olteanv@gmail.com, linux@armlinux.org.uk, andrew@lunn.ch, alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, wojciech.drewek@intel.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [net v5 PATCH] net: stmmac: replace priv->speed with the portTransmitRate from the tc-cbs parameters Date: Sat, 8 Jun 2024 22:35:24 +0800 Message-Id: <20240608143524.2065736-1-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SGXP274CA0005.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::17) To MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW5PR11MB5764:EE_|MW4PR11MB7103:EE_ X-MS-Office365-Filtering-Correlation-Id: 74a498f1-77bf-4eb3-2f96-08dc87c84795 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|52116005|7416005|366007|38350700005|921011; X-Microsoft-Antispam-Message-Info: ULbgkA4yGR1jRqPLIZ22u5SeZ79vkDC/6ifv+l3IxUpx18j9aBiJolXa57bgrKl6N0mPeBofVSNrds6kmZjlw5VaIyO2N2mfz51o4Da96RJB1oO+zeTuEaVhlPvj687JyLxyUjHD6Krfi9+hfbLarK2ai6sHCRAtIIW8GCVTKq8Pd2gbGcwNusDWYJqOztPB66bF72A1LN+4hhLNSVI09L3sT2rMNH6f7QRLkL5Ua7pDQjAItUP2mvhWz1XnWLCgc+Yik2HqA4X6RT7G6aiSe/10lviPePqvSFlMVNdX2XvQtc3Kf2sNXOJ4E2FJN4aHhqw8RNN6UrWG2jUGJeQeGDeWpZBZ27xkIj23KNhE+nOqautVGOIriC0cF7FWWqisqUv9OIwZ56LRvhhJIg5wyNvGco8xIe4vDVZxSKPNRqi6fxg2fj3cK3zzkz2TXr9D2esNtDwZbJR8SEcr00jQY/v9ZFHUyC11KkxyR9OGEuYlKjJl5fJJarLI6hQQufazSXkDqXT8pm3tJPp0qxA3gWFB9X8uZbRkEi+++dv3eJ5sPatN7DCvzEOgrORlpseOCS69LKTO7xu/ck+B0AfiJZo+KoYOQPmRI3NYlZ4hspI339two5WA6LjrhVvWUot/Fra60Q7YGPaojjyfTXzoz/hWwRNPvkPLjS4BnketBYBHkBEJi3/sX4WeDQfr8fucYXn9rnV/TEJA4A3kuOFwdGXFEFHcUWWK9xKoXaiojAFj0hHpiZgtWlEQgiMAO/4B4NRbCg+6PG8KimEdDz2Ht/NWeALh94Syq/FFDe+YEFZMiSja/IKh2tw5TBQbQ1FAMiW8hu0Qe5Mj11LCqEkl6bHUGetYCKyZAMQIVvLIeQ+KLzDCGxtUVAvtYT79ObDt/kRoanyZGhWod72k5iYRY96SMCBdqFafPhlobcvhEAMwWlyWZvFijKXNNyFnxKnWBd25xhaWgDp0u32NMBq8P0UfgWEfqObWaoD0psfiboE72O71W5sdcX1AkufukV1hrkd8wAJIFl5zM/c3mSk8bKiqc89wx+TTw2+cj9mWimGTDEkLfEcBXkLldCbZwB8hflp4MQrH02wzTmGogBOnyuCRuDR5FjDLcxHpcPXOKjERYr/TE5nR1EeQZj436NkEM8njL9ctY1OMptZCZ/e3IQzos0W3hod/tykRBjl3dPJhhzk1pq/Fy7YkKew23U2BsIzy511QDY/oaWj+gr2YufxsPIbM/dxoLZrHRmvgaEjq3Qc2XRwBDJYlpfdEKjxHkefzStTWtbYugqlSNnJgKs2HYYCK96aFRVAhX5yQ/RIlnpILquKDNaLxrKZ9WzMvArWU5WE9+Jd5XrYJgVmpOA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5764.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(52116005)(7416005)(366007)(38350700005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k0esxgQ8xYZ6LVEx0T5Ij8rbgVIzjnakxaAujAq0g2Z2XNrjknQaMej3H62k8p+QG2p98JZlmy6AvHCiDN3wBo5uSF+FpzZzBzZt49JwGN+y7YId8U4sqml7HojayVQc9lCbTdVmSmBzEYqc1gv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xw+BDdOwunNVrD5wbX8w/o9vCRJcZPcD7wHmxMFFDNNkhabUjDYorZcAw8qzFoFtlN5zIjsZ+IJ3SZZu9RFqFDvZKoE+MNMH47Yrhn2HcBdFiogcJOrQUE3O41UrwgtVER57aYoeKRfBj73iFxQgi89Upa/4MFdFoDXSE8+BQ/04SVSBRJMyOBz9Xf3X0+ABZXpZEKcoqVZm1CGED6g6i/MPBLzpmfM/T9o0TpmadVZZeK8Y07QZbKs9IkrbYysL0R+w6WEQ3gqjBYjN+Ad2fWoIKOyOseQm3JqNQEsU6pqwbrYzVAKj4fzif9fBDe0p9rEaxz52vmsEqzoCAnQiss9clGj67AfCVf5FmkDCl3GMCDMsSuE5cZTJnjhsiRu1rzbf1cT6Bwizw== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74a498f1-77bf-4eb3-2f96-08dc87c84795 X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5764.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2024 14:35:44.5449 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eS1KMmMifW60rLnqA516P2awO/bc8ll314lOnlDsX0rvpdhcr8ZGUrZ9LCP9NpKzoN/Om2SmufDhYE1ey11NpHaOBRVexQFNMCtEY9GHMkc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB7103 X-Proofpoint-ORIG-GUID: 8zXWOovOOEywRzjEMXQFd83gt5BqRgvO X-Proofpoint-GUID: 8zXWOovOOEywRzjEMXQFd83gt5BqRgvO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-08_08,2024-06-06_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.21.0-2405170001 definitions=main-2406080110 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240608_073608_837894_73FF82B4 X-CRM114-Status: GOOD ( 15.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The current cbs parameter depends on speed after uplinking, which is not needed and will report a configuration error if the port is not initially connected. The UAPI exposed by tc-cbs requires userspace to recalculate the send slope anyway, because the formula depends on port_transmit_rate (see man tc-cbs), which is not an invariant from tc's perspective. Therefore, we use offload->sendslope and offload->idleslope to derive the original port_transmit_rate from the CBS formula. Fixes: 1f705bc61aee ("net: stmmac: Add support for CBS QDISC") Signed-off-by: Xiaolei Wang Reviewed-by: Wojciech Drewek Reviewed-by: Vladimir Oltean --- Change log: v1: https://patchwork.kernel.org/project/linux-arm-kernel/patch/20240528092010.439089-1-xiaolei.wang@windriver.com/ v2: Update CBS parameters when speed changes after linking up https://patchwork.kernel.org/project/linux-arm-kernel/patch/20240530061453.561708-1-xiaolei.wang@windriver.com/ v3: replace priv->speed with the portTransmitRate from the tc-cbs parameters suggested by Vladimir Oltean link: https://patchwork.kernel.org/project/linux-arm-kernel/patch/20240607103327.438455-1-xiaolei.wang@windriver.com/ v4: Delete speed_div variable, delete redundant port_transmit_rate_kbps = qopt->idleslope - qopt->sendslope; and update commit log https://patchwork.kernel.org/project/linux-arm-kernel/patch/20240608044557.1380550-1-xiaolei.wang@windriver.com/ v5: use reverse Christmas tree (RCT) variable ordering and If the portTransmitRate(idleSlope - sendSlope) parameter is invalid, add an error output to avoid user misunderstanding .../net/ethernet/stmicro/stmmac/stmmac_tc.c | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index 222540b55480..1562fbdd0a04 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -343,10 +343,11 @@ static int tc_setup_cbs(struct stmmac_priv *priv, struct tc_cbs_qopt_offload *qopt) { u32 tx_queues_count = priv->plat->tx_queues_to_use; + s64 port_transmit_rate_kbps; u32 queue = qopt->queue; - u32 ptr, speed_div; u32 mode_to_use; u64 value; + u32 ptr; int ret; /* Queue 0 is not AVB capable */ @@ -355,30 +356,26 @@ static int tc_setup_cbs(struct stmmac_priv *priv, if (!priv->dma_cap.av) return -EOPNOTSUPP; + port_transmit_rate_kbps = qopt->idleslope - qopt->sendslope; + /* Port Transmit Rate and Speed Divider */ - switch (priv->speed) { + switch (div_s64(port_transmit_rate_kbps, 1000)) { case SPEED_10000: - ptr = 32; - speed_div = 10000000; - break; case SPEED_5000: ptr = 32; - speed_div = 5000000; break; case SPEED_2500: - ptr = 8; - speed_div = 2500000; - break; case SPEED_1000: ptr = 8; - speed_div = 1000000; break; case SPEED_100: ptr = 4; - speed_div = 100000; break; default: - return -EOPNOTSUPP; + netdev_err(priv->dev, + "Invalid portTransmitRate %lld (idleSlope - sendSlope)\n", + port_transmit_rate_kbps); + return -EINVAL; } mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use; @@ -398,10 +395,10 @@ static int tc_setup_cbs(struct stmmac_priv *priv, } /* Final adjustments for HW */ - value = div_s64(qopt->idleslope * 1024ll * ptr, speed_div); + value = div_s64(qopt->idleslope * 1024ll * ptr, port_transmit_rate_kbps); priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0); - value = div_s64(-qopt->sendslope * 1024ll * ptr, speed_div); + value = div_s64(-qopt->sendslope * 1024ll * ptr, port_transmit_rate_kbps); priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0); value = qopt->hicredit * 1024ll * 8;