From patchwork Tue Sep 5 21:53:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13375133 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 4E2D3101CB for ; Tue, 5 Sep 2023 21:54:35 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2066.outbound.protection.outlook.com [40.107.20.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635FEFA; Tue, 5 Sep 2023 14:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QL4wGaLGAYnjGWtMZK8BRxqnMVll9NFECc/FB2zSQ55r3OmeQ9Ma9Az4IC/h6ehJ6mdvUwFYfubtObAB0uYhB82ED70Q0Q0X9UQGURB36l2mz0LNBvn+BvOEI+XklfHeCJtuN91qY72AtSOtaIuphakFVtJVrEg5sjpyUExZoxq31/ScDrV/bq1O2BZVH3nZbQYiXHwQFSoSl/cO09Xqw1JkrbmzPzBCv98d2U2FkhHnlM00n6ecLnajyVd1G2r2RK50DdZPc7MpT0ryMBMS1pjwLCfk0FNsJuMMoPMCbaW69kzRIBRm2lSBprrpMo8va20d5Tji6fdIis4jFMF8qA== 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=qfxDyEeqWpq/P6wjPuFiKe/vBOHvsv8ygeWRWpbIwYc=; b=O64Ptmq0hHR4UbgGBW0ON8ayDtIWHn/7lar3HdJ0BNO8Ayxw0OoktyabNpyAkYArIAa7EjVmgKNk5TWaP1PFb9RLrgbBP8YRzGFZWAnoAAmGm2Lt80wxKFHAdIVR/fT9DAsgX6EHw6eypGSdRBJxIkUVyUoaRgY9uzkZ5rYLmHXyB1+WFLftTX6geve9Nxa3x4mXFbzvCPjGtpGrNg34X5njJ+U3kdA1ngQjHP/KnrbvBs5GYXmjVaKROhzDpy95OLDZ3BE8iRuTkZZ4hoDZmKb+X+Krvgv8xGiRoDulsomP/zePLU5xy51ayDOgA0w+U6VQRsBvG1xUhixkZI+mYg== 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=qfxDyEeqWpq/P6wjPuFiKe/vBOHvsv8ygeWRWpbIwYc=; b=DVP2kLtX687wCKH7aL7r0QlMi31vFUInopOefcZTQmYsk6aHjp+g5u0kUgxf3mqcUQVk5O4JGZ2gJj6GLtiPcVnq1zAI3QT15lfP+TX2dv1AuNkyjxUOwq9MMRb9/LkkrcqHoxhAQaw92r1ULGBAbltP3em5JJ2OrpHO7arSAcY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AM0PR04MB6963.eurprd04.prod.outlook.com (2603:10a6:208:18b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30; Tue, 5 Sep 2023 21:53:52 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454%3]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 21:53:52 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Xiaoliang Yang , Andrew Lunn , Florian Fainelli , Yanan Yang , Vinicius Costa Gomes , linux-kernel@vger.kernel.org Subject: [PATCH net 1/3] net: dsa: sja1105: fix bandwidth discrepancy between tc-cbs software and offload Date: Wed, 6 Sep 2023 00:53:36 +0300 Message-Id: <20230905215338.4027793-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905215338.4027793-1-vladimir.oltean@nxp.com> References: <20230905215338.4027793-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR07CA0029.eurprd07.prod.outlook.com (2603:10a6:208:ac::42) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AM0PR04MB6963:EE_ X-MS-Office365-Filtering-Correlation-Id: afcd2e45-b584-4b2b-0538-08dbae5a9826 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /hx+njpJFrwhKr5GlDOwhkO++b0hMgFICGgXyd8F7efqJFD347EPggzF44Ziy/BNRg8xEwjyz7NQHDxEV4kOsGCcRkyCpJQZ29RW8VzMsVqVg4ZEHxuuEo+G9zTH81ySfUnladWvCvrwS19ybazFPO5ubBoh4O1dsQWBgCjs0plc43adSdGWTPdRLlqK33yjO8XC0vAB0J2pQz7QzdPOLnUaO28VJRSLEiEan0pD1CSoF+z/SIIfalrIyi1uECF5z7ay0cfdwCijXazZQz/5SjEiSIkmMQznS6e+KxxGrgudBwMIgx0K+jduJGqNS3TjXHYwTnzxA/jhkjtSG6HzwsFStAY5fQsMOwEVzuxW8QkYfmbrS6RwquWjmdgCPezaARxB8RE1oiqIQY4+uUj6aE+srkX5CH6rYazS9tFChbCoJ2P7qJl/5UN8IaTn2Z9Fb+HGQI+az5z2xv1BAc2suXQTxcJK9G1PmJOQ1f8IPK9rxc002poS+ftqYcP5BcwuCZFwNp5z4Vc4cpndG4psxgMSkSlD4MPFm2RRIiA9ZZbQP6O8FmCgDw9/l0W3cHR3PxdkQm2QFVda/DrpB+i8MmYxrwtoRG2/TOzB87Qiz2WuoR07lscuS5CEQ0n68Dep X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(366004)(346002)(376002)(39860400002)(396003)(451199024)(1800799009)(186009)(38100700002)(38350700002)(44832011)(83380400001)(5660300002)(36756003)(86362001)(41300700001)(6666004)(66476007)(66946007)(1076003)(66556008)(478600001)(2616005)(6512007)(8936002)(4326008)(6486002)(8676002)(26005)(316002)(52116002)(54906003)(6916009)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QZJe/oXMRCgb+JHhLZrU+yCW1lbbXkby6uRTTFOy05xjh4ZyWMSvWSVSDogwMBhSpIFkpK8Y+8q+FL4o8ezK6wU5WKUgVzHJKqGGGqFWEjNRHGD5825CJ1z5U4QUs0sHbnfVC3S2PqAoOivfe9RogkeXW7MUlTWNlW1tnZ71jMBPpQcnu4mPKQf6Dd9irVZEAyqxZo6FFRGKz9j+WkPNvbsX7/zt54xb8XGYpiTt/qe/S5ZFXwlZyOpuG3rt2DRoUoajnDZAxWbVo3y2hdwiRF8fQwPPL4mcWYhldidJka02CHoHzjTgZfO9oai3Uy6r6UdLjgUYX74w0gIBpzyh0Gf5REJIm/kjCa3GazKKgo8UGSs6ToGWHdlxwpIsCfZtkcxSTL/aNkKyTBrIwyYAb+ZTkjZaMs6r0XexTr/+q8l9+dAlhFHAJRzylYLxA9Ft/5Z0KQGFvK4umHIJlzmAO4SE1h7fYy+UDClCzuy0RivF2Cx6qWjoaCozScsH6UE7BhFwuuXKiPvGI3KFiUH8Oc2Qrl/NyIkk3Y/OuqppaCjzBrjMz3lCdLDiN0tTGUhCHItvh4jouQSvL6JRC0+hKZ7/GvbwNkOTSuXCtSyM5AK/C7SfLznEo8bg9Se82DDYZA3TWA1/Yugc0Spoe0J22/UFzxlQPwFoqsaKWvbUckI5BSsHNPke8ruujIvRLSNi5RQQPjVIYm1AvlJavhKZ30v+d8IQMYxbPjbXp93K9wtMdzjssFPw49MVBI4R/bPEe3QbjmhYghTmm6YiPk78EYVGOajsfeCeoT+sqkstP5GqSWB+HG8Xcq5RCN8yLGI7gfiwGPdeLER/G0YHc29V0+twkvPCNeiWQWJKerVWmIGccJZXV8Fol6CYkyShomWWijEzUWQUtydpXLvAu2lTgAdJGA9OsKavXa736lZk1uReV3ZvAlgejAsfGL9akvtP58G3CMuMzKeV2KYmNNhCGnvCVdpWLVYw4kvsCHiqrTbqA13bqYGOdbiKRt6GEtL4vX66XrAIukXvaT0kjjSCm65JQoZvug3rWNXsEAvDi/oaYcTDu3hMyHNaUraUV9gi5yNC0eGDSbameHNAnCC+ECSK8a3+qOA2jqWqk4DkNHQf96R0r82t+HOniq8g9qSsbNw1tl0Y8TtxvqOPjfY2GfIRNRChbFR58oBQEeGSHfAMDT5IxGJr83CGuA93Jux4rbvYXpsLTJRRsSVu/AgaDu7pyFCcX6p6ftRawE9JsQxtLfz12DYOKkJAW2xef5CCdi8TxNTV5C+VWHeIjngyHPfhws0NXf4BPzjNeKDRyLTxIIpPcasJZVqiDk82ShKTymEkSZYbxjcjF0mKC6cfCIDOYq1qluk7eshhPxrlp8/srdcNusPKMwWbTSdN72RJveMdk+sV9vqYEJR1fF30fjNw9LEDgBQswDjEzydzbj/pwhwl05VkR7lb5ziYWltIFtunVhitFmyMCBVxyTo0Ix2IyD/QoqsaDicpHCWDCZ6mJq8PhIfTAJe88+vgwPWU1b5l6f3ZK5cWeOHr9J0JA1Q0lG6f9j633Bt5/o5bxP0iPMEG/BAoyABXJcsU1Yv2Y0wT3AuMVCgfyWX1yYvskw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: afcd2e45-b584-4b2b-0538-08dbae5a9826 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 21:53:52.8626 (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: pUpxdNlpR1G9q7dKsuEDdIj05N21q39pvRfBuaTXh4xVElpghn89gRnvSNoOM7r+LKiNczx4CYDHkfrCqsGRTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6963 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org More careful measurement of the tc-cbs bandwidth shows that the stream bandwidth (effectively idleslope) increases, there is a larger and larger discrepancy between the rate limit obtained by the software Qdisc, and the rate limit obtained by its offloaded counterpart. The discrepancy becomes so large, that e.g. at an idleslope of 40000 (40Mbps), the offloaded cbs does not actually rate limit anything, and traffic will pass at line rate through a 100 Mbps port. The reason for the discrepancy is that the hardware documentation I've been following is incorrect. UM11040.pdf (for SJA1105P/Q/R/S) states about IDLE_SLOPE that it is "the rate (in unit of bytes/sec) at which the credit counter is increased". Cross-checking with UM10944.pdf (for SJA1105E/T) and UM11107.pdf (for SJA1110), the wording is different: "This field specifies the value, in bytes per second times link speed, by which the credit counter is increased". So there's an extra scaling for link speed that the driver is currently not accounting for, and apparently (empirically), that link speed is expressed in Kbps. I've pondered whether to pollute the sja1105_mac_link_up() implementation with CBS shaper reprogramming, but I don't think it is worth it. IMO, the UAPI exposed by tc-cbs requires user space to recalculate the sendslope anyway, since the formula for that depends on port_transmit_rate (see man tc-cbs), which is not an invariant from tc's perspective. So we use the offload->sendslope and offload->idleslope to deduce the original port_transmit_rate from the CBS formula, and use that value to scale the offload->sendslope and offload->idleslope to values that the hardware understands. Some numerical data points: 40Mbps stream, max interfering frame size 1500, port speed 100M --------------------------------------------------------------- tc-cbs parameters: idleslope 40000 sendslope -60000 locredit -900 hicredit 600 which result in hardware values: Before (doesn't work) After (works) credit_hi 600 600 credit_lo 900 900 send_slope 7500000 75 idle_slope 5000000 50 40Mbps stream, max interfering frame size 1500, port speed 1G ------------------------------------------------------------- tc-cbs parameters: idleslope 40000 sendslope -960000 locredit -1440 hicredit 60 which result in hardware values: Before (doesn't work) After (works) credit_hi 60 60 credit_lo 1440 1440 send_slope 120000000 120 idle_slope 5000000 5 5.12Mbps stream, max interfering frame size 1522, port speed 100M ----------------------------------------------------------------- tc-cbs parameters: idleslope 5120 sendslope -94880 locredit -1444 hicredit 77 which result in hardware values: Before (doesn't work) After (works) credit_hi 77 77 credit_lo 1444 1444 send_slope 11860000 118 idle_slope 640000 6 Tested on SJA1105T, SJA1105S and SJA1110A, at 1Gbps and 100Mbps. Fixes: 4d7525085a9b ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc") Reported-by: Yanan Yang Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 331bb1c6676a..3f17c17ff636 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2150,6 +2150,7 @@ static int sja1105_setup_tc_cbs(struct dsa_switch *ds, int port, { struct sja1105_private *priv = ds->priv; struct sja1105_cbs_entry *cbs; + s64 port_transmit_rate_kbps; int index; if (!offload->enable) @@ -2167,9 +2168,17 @@ static int sja1105_setup_tc_cbs(struct dsa_switch *ds, int port, */ cbs->credit_hi = offload->hicredit; cbs->credit_lo = abs(offload->locredit); - /* User space is in kbits/sec, hardware in bytes/sec */ - cbs->idle_slope = offload->idleslope * BYTES_PER_KBIT; - cbs->send_slope = abs(offload->sendslope * BYTES_PER_KBIT); + /* User space is in kbits/sec, while the hardware in bytes/sec times + * link speed. Since the given offload->sendslope is good only for the + * current link speed anyway, and user space is likely to reprogram it + * when that changes, don't even bother to track the port's link speed, + * but deduce the port transmit rate from idleslope - sendslope. + */ + port_transmit_rate_kbps = offload->idleslope - offload->sendslope; + cbs->idle_slope = div_s64(offload->idleslope * BYTES_PER_KBIT, + port_transmit_rate_kbps); + cbs->send_slope = div_s64(abs(offload->sendslope * BYTES_PER_KBIT), + port_transmit_rate_kbps); /* Convert the negative values from 64-bit 2's complement * to 32-bit 2's complement (for the case of 0x80000000 whose * negative is still negative). From patchwork Tue Sep 5 21:53:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13375134 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D2FDFDF6E for ; Tue, 5 Sep 2023 21:54:55 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2066.outbound.protection.outlook.com [40.107.20.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05C2CE61; Tue, 5 Sep 2023 14:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dHiFZjwCVtZpZL4ZS7F3qKJNNSbt3msEYXjxEBZHJkh3rGat4Onbn5AyHc6azjCzKI2GIYH+iTOARqH6wXLFPQcknlwCQoImk2iOHIfMA0d5NSTpLufFqA8ubvQKaMPDXc7kpchZaIFvHSF++gntFvMyMZUBHMNr7T3phdd4TCDwueX5zAkCfCh1gGuCgIBi6VPAQnu9jH5nqNn5VkDIpDN76VYGZz8XsCdedQCARQLoAQNVhIAhLbe8v0/0+tWsW6sdrQIv3ixrG5an5zWJFcjDZnk/Ih7/iYBz6uj235dg+lTXKpElKQyKbhj0DVe3y1tr1vZZHpxfQOQC4j7kdw== 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=ZdfPSZUm+yltE+KXBqLsk/Nr3ZkxQsjRhZtviSW+++g=; b=VAWlVIheF15jt0uik7A6+YZ8pAcSYg5CxY8U77QBd/uYIZzerixkv5Coo9PrvLD2/evTvHcnHpRVZFAEuriVyG7CNIDcYn9+Glx6uYJloxSyoM+DGqkrXqUBI3CFOHmvu38QQowKOarWi9jN62Bvj6nB5a7DDHtsR7N8s5Ziwg3oUnYd4vvSwXWDy/F9jV47FhedXXCDECkW91PICDh4tRFtISEG9IlngDnsFotRLLgAOknpoPky0mAGegiSWQs3Hr6dosFBswj75Z/erBjh1WnCwMVeNvIFDwIj0vxwy4sQUVKRKV9oRUhrYT951+TcRKRc5yKXJ+co3EUZQPo2Kw== 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=ZdfPSZUm+yltE+KXBqLsk/Nr3ZkxQsjRhZtviSW+++g=; b=HoUIDicxoHxrNkIn3MV32nLPv1rpGQmAITg1vPeH61TekFkcPTV/znT/3+ZQjsidTYNeL2BaNEscLWcnMhHBSaijGRF8SxBDl0vI5AxPX93ZU7vCh7f1fMjsqVcDxbjQb7KfwihQQs0+j2rZZsXdt9JMh/HHtFkUKX0BDb7dMbQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AM0PR04MB6963.eurprd04.prod.outlook.com (2603:10a6:208:18b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30; Tue, 5 Sep 2023 21:53:53 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454%3]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 21:53:53 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Xiaoliang Yang , Andrew Lunn , Florian Fainelli , Yanan Yang , Vinicius Costa Gomes , linux-kernel@vger.kernel.org Subject: [PATCH net 2/3] net: dsa: sja1105: fix -ENOSPC when replacing the same tc-cbs too many times Date: Wed, 6 Sep 2023 00:53:37 +0300 Message-Id: <20230905215338.4027793-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905215338.4027793-1-vladimir.oltean@nxp.com> References: <20230905215338.4027793-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR07CA0029.eurprd07.prod.outlook.com (2603:10a6:208:ac::42) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AM0PR04MB6963:EE_ X-MS-Office365-Filtering-Correlation-Id: ae1db77d-30e3-40b0-3780-08dbae5a98bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: du+nF1R6iNo2PkTcfddoHHoHQN049omP3FI2TzJXZUUiMwAGeEbI5c45dRg7AVMe3JU9cVAduQQSRz1cOXB9CIXbdwHUXsZbU0RYpLgPNm/Cn8wE/ZFM3ptcbRTkvsVgLPlSgBehhOgBf0DU4sUKm/RLnryV2BXEYSP9/4Hw3+o1cyhPvaTnR3PiNESwsV3f2H/tq98uvdx1carJhMa+1u/GaaN6d1/l0fSIq9lkBJTPxrUnogGin1VnjcE/LYnYwaRdiJIINT05McFTVgX/L59i6JKiG/0fEALnkhzJpsNfbg4CGuh4XOzXp1zowu0tsZkLWfWM2cS3Mudr2F7kD3DaEOWg+sEfiajPdJIfSa1+U8gb71oL7iIKAitP4p3ZXg+qVqB4ovED/SdVa/dyUJkGjNU0SXK6YxICtWbPNXvdBTAgL1p/8sBfx434rJNOgYNWZ56ok3bxZ7NezrxH8aNUYKnib7DY9d+Zr9QJ+5Zk2/yCJzs0cbykigJBkGpcrcrcg/xJWghkbZ74Nqia9WsaZJNhACZEz71tizLvoT8y3UY4uMU+oFDLPaCZdc69iNlLnzznp8Xpgu7hmxfVyPJyVYlLuZAr99t/KSqaXnDE5IlIJSr2k6oMB94mxSDy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(366004)(346002)(376002)(39860400002)(396003)(451199024)(1800799009)(186009)(38100700002)(38350700002)(44832011)(83380400001)(5660300002)(36756003)(86362001)(41300700001)(6666004)(66476007)(66946007)(1076003)(66556008)(478600001)(2616005)(6512007)(8936002)(4326008)(6486002)(8676002)(26005)(316002)(52116002)(54906003)(6916009)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FBSRR4QEET3r/58fD+XtvnTfcER81/zZOl1qVktQ1lygcoI/a/YdMy1w1Bjz0TTanjOaC9TczmjUJlaSBQJ2NzudGM+9yL5XdAa9RmejNhNSEZiUcNO7bJYn3bmQ02M0WNitnRZ1VuE/8f5FWuIiEYUO8P8ycjPCjojrTUWaxc8D2Dy4o6Hc3wT26RoHo141SChBdZJTRsMqG2vpbJC56THJ3lksE7U8ZQ2qQsmdw8HrM7tvcJz6QzuYWPKsC2VsKXyPrZWFmUcUOfGgrAPvs8jmJNPJw1aT3PL9qxMEkEVuJ6LSEPEtQIstVibRqImJINFs/2u11kJA6cXV7sfejDwfHN5K4swFOGi7uMsq7YmDlc6ZEi86lqCjqJwd6iMrmatvEA8Vvxw/QkAqZ4EQtJnwZgKRmrTFCqUWr4+0wpKKvoxZ73Ux7LoE5/97FE3b3PxnTc7cdCmCS8v3BcoQs4CeeLQ7XpvXPPAPJ9WSfcTz8DND5GtvD8Tb0eXVHNlSgrX1MCwwcA/MT3e2C33iYJjSlHGjSff8OeLMidIusHIrYXwB3L5Z2zrHtvIay1U6o8bJlDSBmfT9mV/q6z1RgONwMliVSoyNxpvBKOmck05Bn04ZUrD18LY1oypIHVt8m05uENtjZqzTLw9+S6hwrGmFn2SrVPxjWEGwmVFTt2PhKeSzqZDOjIoJhz9QVMAraotTbBPgti+Alsu6peaQtVM1dE+a5RsSEcUJijBKGlcqpQVw5JUPO3h+EWmVkKE5SvhYS3CjfRAvT4Ov5asLC3rpc6wm2EdwcuqYF4An/Nh3ExDPh8cxkP2iCUjD95vDRNSLTWoiWL8sGXD7bl/wuGL36U82Md6mAfR3aBs+/Qe10fz9DqcjPNbQ/46Yuzc0kW8bJcLdCURsJo4KSwe0IGo57aAP6OcRop4VdQNPbMOjr1rF2QjFvhEblHMMiTF/xHY3AT68PctamZvaclfmMeYckcluAE32Hbvj/22fDVHE0W01DmEY4TTgmzU3GH27tE+bPhZN9rzG36MD6DSemzzHZRFUHMSy/j+j3TrXy6VeRvpDF0GDniL3vu4nwF9kztOinW1iqdd+aeC2EPksnXgWjiQwt/246gJUWFunp+Zz3K75wFrMmhu6vXWb4qXpcb52Xtf9Im0jaAuPE7Y+dd6l97gd14jTk1fX65E6TfO/fHu/+S6C3H0Dwm3+X6L83bRB39GLfbYo5hGF3T81hHDr63mZ5HCXZeX1U+fBH15amOosXsJoz9m+JTDRB18WeGdcQzA/rKjgLJ3UnQDCWdcRGq5XjHwFHkc1uIKRDSpq4ByF7a68VyJp/hGK2AT/g2Goo6K/327ZCdvkraEegWm7Xa4376OndyqducP5nmJv/SYGGpA9fF4XvND38UGgRxX3hdyczlqCiYecKVhbiN6zChycdOPmYQg7PukKMtR6aXswdQyqVPIy+2/Vrgu5GXqtVGvn6yY1gcTXQeyATl+PNW+lE2ZCKd9uDclFkgSVBk97lifEvH360wTZsLsafkwxYXi8z6QKCSdQz4KK6mMThSsoFv7Onlg4CUEZvek9b8/TjmW7ZcZlCWf+TjMCk/GNK6OV2MPqsFZt7U63FQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae1db77d-30e3-40b0-3780-08dbae5a98bc X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 21:53:53.7319 (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: /yHiBRZNaxVO/+M7o1tC8J+APRXmQKSilJi1QyyxzcDLcXjfhrB1Re1iMGYqQfkfGsqNVRqIxGT0lFyHqbL3KQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6963 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org After running command [2] too many times in a row: [1] $ tc qdisc add dev sw2p0 root handle 1: mqprio num_tc 8 \ map 0 1 2 3 4 5 6 7 queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 hw 0 [2] $ tc qdisc replace dev sw2p0 parent 1:1 cbs offload 1 \ idleslope 120000 sendslope -880000 locredit -1320 hicredit 180 (aka more than priv->info->num_cbs_shapers times) we start seeing the following error message: Error: Specified device failed to setup cbs hardware offload. This comes from the fact that ndo_setup_tc(TC_SETUP_QDISC_CBS) presents the same API for the qdisc create and replace cases, and the sja1105 driver fails to distinguish between the 2. Thus, it always thinks that it must allocate the same shaper for a {port, queue} pair, when it may instead have to replace an existing one. Fixes: 4d7525085a9b ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 3f17c17ff636..d7f57f223031 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2116,6 +2116,18 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port, #define BYTES_PER_KBIT (1000LL / 8) +static int sja1105_find_cbs_shaper(struct sja1105_private *priv, + int port, int prio) +{ + int i; + + for (i = 0; i < priv->info->num_cbs_shapers; i++) + if (priv->cbs[i].port == port && priv->cbs[i].prio == prio) + return i; + + return -1; +} + static int sja1105_find_unused_cbs_shaper(struct sja1105_private *priv) { int i; @@ -2156,9 +2168,14 @@ static int sja1105_setup_tc_cbs(struct dsa_switch *ds, int port, if (!offload->enable) return sja1105_delete_cbs_shaper(priv, port, offload->queue); - index = sja1105_find_unused_cbs_shaper(priv); - if (index < 0) - return -ENOSPC; + /* The user may be replacing an existing shaper */ + index = sja1105_find_cbs_shaper(priv, port, offload->queue); + if (index < 0) { + /* That isn't the case - see if we can allocate a new one */ + index = sja1105_find_unused_cbs_shaper(priv); + if (index < 0) + return -ENOSPC; + } cbs = &priv->cbs[index]; cbs->port = port; From patchwork Tue Sep 5 21:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13375135 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D2235DDC2 for ; Tue, 5 Sep 2023 21:55:10 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2066.outbound.protection.outlook.com [40.107.20.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F1AE48; Tue, 5 Sep 2023 14:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fMDcuXeUDshjHgz8eZJdn+73WjarFh2S4Dz8pDZeQUQk+cET2pslmCMN05xZAUt0elN9yDKeoTnoeRkx9k1pnxnhcQiXBZQ8UgOUbd9Kp6D+AvbtGLTFO/VEHT+VKxW4aoVtT7hyqcljdoFzMqfIvVIT4RvlaCh3pwXzjvdzgVrb9ELSNd3YkA6cf/316pU8FBYBtI0nDQfddzKeEaiB4NSE0j8iNqyUKhR7rblqjBL3+Z1NHb7ob7jhaVt5FSg5swgz6OpEbXkoUSDuyVFvjTOQZQrHoGF+Rw89tXkAIrBnQTFeI6c7ZXX3FDqZcvfR9Sk1lVznES6hh84u4lno+A== 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=/NqVeKn/xUcWG7L/7aivMRpWX0KOY+CqKYET3VcoAVI=; b=m6gEeYI/TOQ7kfiq9B+GPPpTayxPn2O1teVk7hL6Vnfsuz5+nlpc6qjoCk3sY+izDwnfgEWBu+oxtgLJas2z2ySiPAfr6Ie5UVfevO2Lw1TfdwD0l8plzG4bzmcIyU++ACK6ARkzO4vCGNGzBifpVRUF+7habwvEMMvAOd2Toeo/0dPEnpeVVcNveMPyGz0eWs3BDN1llUdGbd8fuvoFokO9v1DmCuBW/wTmd//cXQ/n5OD0wICTZK0JQYvtU04+Sx8FrzuQdMncty7/LeQ2vTpu5rPcjJkTHWl+UnzSiy8KRObW7mlJ+SrETnTYIslIurB+SkYkgRwS7+9iKLjBoA== 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=/NqVeKn/xUcWG7L/7aivMRpWX0KOY+CqKYET3VcoAVI=; b=lcIq0e/hePabuDv4MqP0lEtI7Ip0uNHeAmtqbU80oq8xw3dqc1Wm9bQQ/kWaA7DncFa7R2w7JuRMl6RteC6MZwusGxVN8qsMwA5A4grAgQVA3NsO/g++XJCR4mkRQWg58D28kBjq+50J/xOcIa5BJcJr0D3iateiWzzEMXosVR8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AM0PR04MB6963.eurprd04.prod.outlook.com (2603:10a6:208:18b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30; Tue, 5 Sep 2023 21:53:54 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::568a:57ee:35b5:e454%3]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 21:53:54 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Xiaoliang Yang , Andrew Lunn , Florian Fainelli , Yanan Yang , Vinicius Costa Gomes , linux-kernel@vger.kernel.org Subject: [PATCH net 3/3] net: dsa: sja1105: complete tc-cbs offload support on SJA1110 Date: Wed, 6 Sep 2023 00:53:38 +0300 Message-Id: <20230905215338.4027793-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905215338.4027793-1-vladimir.oltean@nxp.com> References: <20230905215338.4027793-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR07CA0029.eurprd07.prod.outlook.com (2603:10a6:208:ac::42) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AM0PR04MB6963:EE_ X-MS-Office365-Filtering-Correlation-Id: ffada9da-9918-435e-5730-08dbae5a993f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LKMXqHV2fB4dsEFx2WjG2ZTQ7S/LCkgINwdHaaPFWF3hfoidUEda9irPSnLxdiqck4r+IDKuxhPTDzJC5OtFcz5Y1BjRAqyPYozU0lkSIf10qqy+OetirI7UPXqwr3gGnWHhQYv05f3V4zH+VFrk3vUmHclavFv3AGbtG09pBipKBiBL5OXqF3bCXU8bbxp13CYP7SML5a+E6bu65RyzqmoNhn/XwUecDuhTWuXdtaPUBeBfcZ4uab/x05t5My4BQLnAqNH07jcpfOSPCNk2kRMFrE4Q2fUEiIDuczqrqRA+0uneRinrkI7b/UcAvNmV2s3gBchvS69sc//oIIlZsWbxqBRiAvstSyMiR37cjGv8F7ceCGdugeiqkqHgACkTtX3ehWMf83PFGiMBZXQTqrxIAVVoWOv9Q8X222x3M75fZoJ6iTxxCGlz+hLo+q2Lhrm0pBy7p0QSSvAOEpOI/h6kUj9p/9H3Rw+XRzf9kA+r3L58NVt5fqYBocUwUmi1HsfIJGIEZ0LBw/WPC3EwhOAEWrh7anfpdFQtVY18wbi+mLSJT/uQutziwKSUSKzYm04Em11/q4zrzBqOEIwlA66NKjQIJ5liaBpY6BFbnuMWLMjRzk1kGO6R/Ld2/Qez X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(366004)(346002)(376002)(39860400002)(396003)(451199024)(1800799009)(186009)(38100700002)(38350700002)(44832011)(83380400001)(5660300002)(36756003)(86362001)(41300700001)(6666004)(66476007)(66946007)(1076003)(66556008)(478600001)(2616005)(6512007)(8936002)(4326008)(6486002)(8676002)(26005)(316002)(52116002)(54906003)(6916009)(6506007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VClfTtyRkbSQsxLeQMf59SVKlH1eq9qkOu3iJfcITal0egZQmlwlR58bhWzHFW9mxFcbtNnT2BQpjkaSd+CI7pXAagscHQHJqipzdasPboZp1fMMI6GQ9PlaQXYxUrbu9YVRcraDKNci8xJl2N1Oc7em9clNi5O3aOy1wG6mTI2z0yLUESQ6FnRzbUSLs83QKemLaKX/LdI0vzuG0ThgIHU2IdG5HrkNKRbksYoSOFZ/nJgu1NehhVjtJP1Y3mRFHP9PMhC1oF/0me5Kw5jgPyNcLtdcbGWkeA2jibbbowXBMdDoemHxAQQBJPywav2eMrazKSCESK7KVzDBxogy9SEt0N3ZYrZENPiIlSNbW+QguXaMtA5+xeAkI62syzmuKcmlMpd77JV0Tkfx+m+N8S4n+4IQ4teIpWUrD/mvZjYGLfuTmdFBRXkorSyUijZ5mOjmF8Jsck44c5HkuXdUF5Mbo+Zf1u7mAuvRM/UHaiOQxPxQSXPtRvbhsAFzLfP/Z2H4zR4HuXSQt6E51VCZKIX2d2A3pxzwfVXc1wK6N//0TI333AK07MoQgtpuI9VgTMoCphxNNAgdjXTmLcoX9mINUWx4TkjHKxu8JTgEGQqUVPwRZtBdKAAjg3QpEu1JLTw7/qL/DbYsAoBzFJ2NsIo+pmiUULHi+Finz/LG46poTIdelPY4Wn7xZmcpmslXAMwEooc6mJaM63r8ma/33KdjVbb+ShxLLd/72yw+lN2MYsIvOaAXx8N/Mk//oNOMxmSpCf4nlBYWxNusMzdxw+YZc5EKWw7rQGfbZvK4PcAKGHPrapgThP6k+f1iXdhxoE5V5X7YSiv0t21cTuGh7sIvFO40G/Fmb3jbPE/eISvY6uR8CGZUjNreH2d9XG0CKlmphjUwmkStPA7JctI8LGISDQJt+3qLmX8B4dO2VYh8CEHUuUcr0szKWeQk+qi8H1/qPsSFpe0+jMZAWNYz6+4oiV78FDTM11dqOmRIBhlCVG5R8q3EwGy/bKuqlsKNCDMX/QnJmvdUk1UOoch5xu9yIE2pNSkGOGATp2xBlAuTGy1uBCN+yn17Gvc+sI9GTMYo9UquIZB+J4+zg1WbGdywm0f6niBYJxTmiWd/5uiH/5WForFLoLOVtJ/sYR5dZ84YVhQnKAZCbifPHKqdJTgm5TNkolMdW4KRxtzkbmSUQw68efkFuXdWCqiQjOJxp6iFsDO72DTusz7gyW/gvjx5liPsexihbyp/Lnfvnxb0TQkax1r+FHmm9LXO8Qsgrvk5e8hUApKRwYjiXKyM5EO3kImEz3jNA1QKvRJeyq/lgsnzCOpi7NUomWuBDODw3/EEugZuxUbmKTplH/ma7KdQEkjzE4Szi1e+GZap1PPUwOH564so4g1q/FZN/ofha3KiMMYsWv/FHZeJzzVm+yFZ3vRnQiwf3+tC3Rfrahd2V/fQWfVtvaDVMXryokwTpbZHbW6G2f39OTvcjxEWIirJZ7Vqjaj1DcjpHgzSQdNg89NI8v9TyeoFvLxSrffSeYe50ZXaXZtq6pI/o3jHaY6MW5iKt/T+siLJKFgu2V978hOwXwALChmosJua8uJ+d5kBt3CVCdb9UvREOIAqOw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffada9da-9918-435e-5730-08dbae5a993f X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 21:53:54.6134 (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: hP/lMx/SPO4/LeBWqt6Z8WgBfZsld8fWi8DZiXQjH9FL/fRhR1cdcfvEmrSlWUb7p51tg3U3bIwmW3r3+frwyQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6963 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The blamed commit left this delta behind: struct sja1105_cbs_entry { - u64 port; - u64 prio; + u64 port; /* Not used for SJA1110 */ + u64 prio; /* Not used for SJA1110 */ u64 credit_hi; u64 credit_lo; u64 send_slope; u64 idle_slope; }; but did not actually implement tc-cbs offload fully for the new switch. The offload is accepted, but it doesn't work. The difference compared to earlier switch generations is that now, the table of CBS shapers is sparse, because there are many more shapers, so the mapping between a {port, prio} and a table index is static, rather than requiring us to store the port and prio into the sja1105_cbs_entry. So, the problem is that the code programs the CBS shaper parameters at a dynamic table index which is incorrect. All that needs to be done for SJA1110 CBS shapers to work is to bypass the logic which allocates shapers in a dense manner, as for SJA1105, and use the fixed mapping instead. Fixes: 3e77e59bf8cf ("net: dsa: sja1105: add support for the SJA1110 switch family") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105.h | 2 ++ drivers/net/dsa/sja1105/sja1105_main.c | 13 +++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h index dee35ba924ad..0617d5ccd3ff 100644 --- a/drivers/net/dsa/sja1105/sja1105.h +++ b/drivers/net/dsa/sja1105/sja1105.h @@ -132,6 +132,8 @@ struct sja1105_info { int max_frame_mem; int num_ports; bool multiple_cascade_ports; + /* Every {port, TXQ} has its own CBS shaper */ + bool fixed_cbs_mapping; enum dsa_tag_protocol tag_proto; const struct sja1105_dynamic_table_ops *dyn_ops; const struct sja1105_table_ops *static_ops; diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index d7f57f223031..a23d980d28f5 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2115,12 +2115,22 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port, } #define BYTES_PER_KBIT (1000LL / 8) +/* Port 0 (the uC port) does not have CBS shapers */ +#define SJA1110_FIXED_CBS(port, prio) ((((port) - 1) * SJA1105_NUM_TC) + (prio)) static int sja1105_find_cbs_shaper(struct sja1105_private *priv, int port, int prio) { int i; + if (priv->info->fixed_cbs_mapping) { + i = SJA1110_FIXED_CBS(port, prio); + if (i >= 0 && i < priv->info->num_cbs_shapers) + return i; + + return -1; + } + for (i = 0; i < priv->info->num_cbs_shapers; i++) if (priv->cbs[i].port == port && priv->cbs[i].prio == prio) return i; @@ -2132,6 +2142,9 @@ static int sja1105_find_unused_cbs_shaper(struct sja1105_private *priv) { int i; + if (priv->info->fixed_cbs_mapping) + return -1; + for (i = 0; i < priv->info->num_cbs_shapers; i++) if (!priv->cbs[i].idle_slope && !priv->cbs[i].send_slope) return i; diff --git a/drivers/net/dsa/sja1105/sja1105_spi.c b/drivers/net/dsa/sja1105/sja1105_spi.c index 5ce29c8057a4..834b5c1b4db0 100644 --- a/drivers/net/dsa/sja1105/sja1105_spi.c +++ b/drivers/net/dsa/sja1105/sja1105_spi.c @@ -781,6 +781,7 @@ const struct sja1105_info sja1110a_info = { .tag_proto = DSA_TAG_PROTO_SJA1110, .can_limit_mcast_flood = true, .multiple_cascade_ports = true, + .fixed_cbs_mapping = true, .ptp_ts_bits = 32, .ptpegr_ts_bytes = 8, .max_frame_mem = SJA1110_MAX_FRAME_MEMORY, @@ -831,6 +832,7 @@ const struct sja1105_info sja1110b_info = { .tag_proto = DSA_TAG_PROTO_SJA1110, .can_limit_mcast_flood = true, .multiple_cascade_ports = true, + .fixed_cbs_mapping = true, .ptp_ts_bits = 32, .ptpegr_ts_bytes = 8, .max_frame_mem = SJA1110_MAX_FRAME_MEMORY, @@ -881,6 +883,7 @@ const struct sja1105_info sja1110c_info = { .tag_proto = DSA_TAG_PROTO_SJA1110, .can_limit_mcast_flood = true, .multiple_cascade_ports = true, + .fixed_cbs_mapping = true, .ptp_ts_bits = 32, .ptpegr_ts_bytes = 8, .max_frame_mem = SJA1110_MAX_FRAME_MEMORY, @@ -931,6 +934,7 @@ const struct sja1105_info sja1110d_info = { .tag_proto = DSA_TAG_PROTO_SJA1110, .can_limit_mcast_flood = true, .multiple_cascade_ports = true, + .fixed_cbs_mapping = true, .ptp_ts_bits = 32, .ptpegr_ts_bytes = 8, .max_frame_mem = SJA1110_MAX_FRAME_MEMORY,