From patchwork Wed May 11 11:39:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12846076 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 077F4C433F5 for ; Wed, 11 May 2022 11:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbiEKLjt (ORCPT ); Wed, 11 May 2022 07:39:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiEKLjs (ORCPT ); Wed, 11 May 2022 07:39:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2100.outbound.protection.outlook.com [40.107.244.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC6A92415D9 for ; Wed, 11 May 2022 04:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fFvaVusNnoqqc9xzF0ZnCPI3ksNCVnVOWVhE3HTOJx7kANdeG+t/iK2mnwdJSummnrmWUNPNKJUhTRR49YZerX2K/vH6ZuF1cn6WnaALHkKe2u1In2IZAuiST+y9ZCXTpCsB/9Bnv/M5Poe9WyEaJjwBaC/Ovr6VPwH1TqD2rFMAsRKFmyuni4bXKLYpYjcgxlHqsrdjRSRzuL3OYWOLCkDMiLl41sqpVpCz4/1JkSW9dkv8PjXfQZJRG9Gp79jSZfx6hrOj8KJtUbib8RpprKxwFJWCaXMrLoGVYfEpl6ezlDc1ffc4s0lfrxqNPpHUkF80g/oU1AICQvK4I6iMZw== 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=UD8JUBXtuOzT442mdVYvqQBcI0P85Hw7Wue1ZWqEB/E=; b=NMwjcljBz51Jceb0cG40U8YvqoAYG9nZFty+xCWLJ55Ka2dl0MWkkIitir/JyH1mqc/GLjofn9EwQQEWV4jrK6a9N+9kIIrc0Z6NfRvU603PMyDS3xjjYnQgjwwvRwsqk47y5gkaR0/PK7klEgNqBgCbNSDOjGIzlOlNWVIKVH6JBgKpbROKX3ijRM/GnCmdblu/N3s83IGX7HlOVlZDq1BjiYTi+ZojBgCQ/AxBZV7FiuVU4LC6OJ6SKC4L3M1ceCO1aeAyJZUoR/1AsBF4XYPgVytvmbYyLGtLVdkTumgRt2e+GuEEou0P2yIz6oT47tLcVMgTrjbwb/QElmrqdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UD8JUBXtuOzT442mdVYvqQBcI0P85Hw7Wue1ZWqEB/E=; b=B0QLXM+YHMpE91/y6am25onCrlRWEr+m0DuRPuUG+J+YYoqP1HyuoN1QBc/L2q9SAokc2E3VIghvwu+xzp/9f8RMdDCMlcXH9lVNprOs8j8jAX3k6n9o2KMEHpEHu1+/+lpFvpg0XvxpRtv1oY0py5uOUAmH/e7JIofUba5oTAA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by DM6PR13MB2972.namprd13.prod.outlook.com (2603:10b6:5:19a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.12; Wed, 11 May 2022 11:39:46 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94%3]) with mapi id 15.20.5250.012; Wed, 11 May 2022 11:39:46 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Bin Chen Subject: [PATCH v2 net-next 1/2] rtnetlink: verify rate parameters for calls to ndo_set_vf_rate Date: Wed, 11 May 2022 13:39:31 +0200 Message-Id: <20220511113932.92114-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220511113932.92114-1-simon.horman@corigine.com> References: <20220511113932.92114-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR10CA0054.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1f89618-c9e6-4ff8-ad77-08da3342f2d2 X-MS-TrafficTypeDiagnostic: DM6PR13MB2972:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4TJvui7Q8x8TwJ/bNs/OU44Nasse/WE45pYd2qk6oFNkIOvCOodL6U9INi5lygXr6+PAHVqhYq4viLk0cEYfzsdnqzJYwfByoC8GkaV5GgMBoY5BFKNdX5ZFxluiteuOrOC3k2qeEg740+zqM2vsoE2fBsD7YUP9jP0Iu8lHbUXYSLuLlt8LKaZ688Zweoe6dqi2m4ysqKbFyGYNh+jNwANCoUNJDaFuDYJ8PniXdCGgPLZMqv3F/0SGDpHl9DwwMfQ7+hDU2x11ngotORuNp2oOUisPbseEf6f8c5b7ELdDMKiTVuK4rKya4troVqVvngD7xrwhiN06pA/YnekkFAlGw8zgZck2QzTg9O9FjHsd4W1G1aMlBaCCJ0V/QGbs0bjxcSNMygskayIK+dC2iRBNueHB5UeozppzDw+v7noTjliykY+grrlPS+8KjObvsB+E6pBOFE4LQCL8fYVOsNoCA4KE4E3KeTTyqvPdvQrFd5tu5SVnhpk+OUnKW+0JOBhxMFKQ3/Md7eI3WxHmq1yEabIyh/sph++xUdX2MoX6t4/qd4N/tUrki+ombvnlyXeK/3xYqYgePnWNOxo8WuGu4k+PvpbYXRYc8RVLNCTPxC613ZKHvtQBT1+NN+0txMGeuuZXVXWSjAB/pLQ2tA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(376002)(346002)(366004)(136003)(396003)(39840400004)(15650500001)(38100700002)(1076003)(508600001)(107886003)(6486002)(83380400001)(110136005)(316002)(186003)(8676002)(52116002)(6666004)(6506007)(36756003)(2906002)(6512007)(66556008)(66476007)(44832011)(66946007)(2616005)(5660300002)(86362001)(8936002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: DMyJRQgy/D/ST0IhKsiKZHVHP3LhW72w7PD3L/XrVXW89slwCNE4c+FYWr7gujgR3Uzv8ax4Crt1Cq3vQb5QqAnFkiPYecriUhs1yqnCCjwBOaCSYKAeC0arVHff9gfclTwrNC59k2gSYXXas0k6jP8hSLoztfLR2rjWDzkW5o1mfhz4aZmf0HQN1bSTaE7qPEt6imJv2bMWfhLPp1axiDD0aYvIVeM9lI4P38m2eP6WHv5V9xiquOwN27NrqgqeNUTxX4VZVOR3d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WkGJYBx9gVAm165MWM73U3SLrychkyB0LogLCGUaQwDBybvwUYmxo40fBmTIKbKw/XistPk4Eg54FQngSwa5XLvEL29RRPZpUdgL9hjIPXbOczYLre+QFiF1A6kBuKaAQ6r2vrGAAumRl8qa4CHXsGpVds1sMIB7hybNEuVUmjkMgK35880qI9QsWRbL34VW6EPCgYcufWxp1BpCStMT+zXOW7R8oF05BBQfmcIIiDTz3BmOcDInCLYjsGM1U0Vv1afdaAe5ZnXj7MnqHhVMeInXSyKjvjDnW+Ly8QhUvtyeX52RUy8cdjPv4AWOhIuy5u0j1rX8tKOmPJoMbYajIM5QvFtiJytF37E8fzTOoqBhJLs3EP7+JgoR2LRULuI8vRwesTMM7IjMr/UbRqIF+0rSwgvpdHEYtSGTLRJJyianHy5gPuTW4xJKOl6fix X-MS-Exchange-AntiSpam-MessageData-1: ZiyKlzIZYo4gYwQDGq54GFsecyRRq+0na74= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1f89618-c9e6-4ff8-ad77-08da3342f2d2 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2022 11:39:46.3771 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bj1NwwKCZWyOV5AbKOmFECRUh/Z5a8B8VSEoXCPyDZzEi5s7BLkoq84zeW2cvG2YwOw+LfqZtZzYP4am1//ioq8TIoKW0ksB1oN4KEuti6E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB2972 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Bin Chen When calling ndo_set_vf_rate() the max_tx_rate parameter may be zero, in which case the setting is cleared, or it must be greater or equal to min_tx_rate. Enforce this requirement on all calls to ndo_set_vf_rate via a wrapper which also only calls ndo_set_vf_rate() if defined by the driver. Based on work by Jakub Kicinski Signed-off-by: Bin Chen Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman --- net/core/rtnetlink.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 6aff02df9ba5..bdc891326102 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2306,6 +2306,19 @@ static int rtnl_ensure_unique_netns(struct nlattr *tb[], return -EINVAL; } +static int rtnl_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate, + int max_tx_rate) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (!ops->ndo_set_vf_rate) + return -EOPNOTSUPP; + if (max_tx_rate && max_tx_rate < min_tx_rate) + return -EINVAL; + + return ops->ndo_set_vf_rate(dev, vf, min_tx_rate, max_tx_rate); +} + static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) { @@ -2443,11 +2456,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb) if (err < 0) return err; - err = -EOPNOTSUPP; - if (ops->ndo_set_vf_rate) - err = ops->ndo_set_vf_rate(dev, ivt->vf, - ivf.min_tx_rate, - ivt->rate); + err = rtnl_set_vf_rate(dev, ivt->vf, + ivf.min_tx_rate, ivt->rate); if (err < 0) return err; } @@ -2457,11 +2467,9 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb) if (ivt->vf >= INT_MAX) return -EINVAL; - err = -EOPNOTSUPP; - if (ops->ndo_set_vf_rate) - err = ops->ndo_set_vf_rate(dev, ivt->vf, - ivt->min_tx_rate, - ivt->max_tx_rate); + + err = rtnl_set_vf_rate(dev, ivt->vf, + ivt->min_tx_rate, ivt->max_tx_rate); if (err < 0) return err; } From patchwork Wed May 11 11:39:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12846077 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 7FE09C433F5 for ; Wed, 11 May 2022 11:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbiEKLkF (ORCPT ); Wed, 11 May 2022 07:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232149AbiEKLjw (ORCPT ); Wed, 11 May 2022 07:39:52 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2117.outbound.protection.outlook.com [40.107.244.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A153B2415EF for ; Wed, 11 May 2022 04:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BcPyL/0f0JhWMalqh7bArRmp4HGwctMxC5Rup3RXGn/BKP/a+EQysKSO2Za/fpFakLaf4hZTWkS6+uuSvNY5wWKHbWKiGL69M4z/Eou7Mcg2soD9XdGu0JoBtm2QKNDFo9/NM2Dkd++SHTWPjQ/EwwvP9/eYi7QEnFS7cGH8CN7HonU0egdBI70geAHTj7za4AHHNPK2E7RdBv4mvLJSpW+AX72MtjWB/SP8/ygHqkS/LV9tQgCoTK9OkUc7aZt+mdB6haOhtMQUS1a7hA/zA5CHkxbO9Hfu788I+8/p7Ei2CALx99GERcJqEDoypP8adrtoSwN6Y6KkFxG64w+e2g== 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=QrBMgqr416+ZL4uNfJKoIOnZbLMK9w/iGZWDF9V7ORY=; b=eaxyLZjmS7F8cuFGJws91laoOPBHFRXtFF+1QmHchPmtykbdkSofKavq5uNzDAVhX59w6MhaTX0R/TmTcUTGGIkFUCljZqQLJSPITCVkTp4e1U49f0lAGBZHWOts9kx2UbiFziHh7oa+NTyc/TUAXHMcKqr2AXJL4KxiQUeTxQuCdRsIn3reAuXkT77To+m9wcWCx7S1tFpAxmPFWeQHSEkZuQOMI01DTHL1cnMNTNgRIgr5aTYOT+quUQGIEOmRqKi1wQYUWZxlXe9hoViGtxPVpoL9zANj7T8bOZdNBDqhOEsh32Bcp1ibwkO708kmEbLS5MVT3SaezbqPD3L4KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QrBMgqr416+ZL4uNfJKoIOnZbLMK9w/iGZWDF9V7ORY=; b=TB+gLrcI0PDPU3GZXLnj81MklFNkk89XjCMEjTGbnFl88WHgcr06DjEtw5IIhxcKcMY/5Y9+syIYZ86KUylV2gsBIAEXn7mHfysfs6hKeYg0k/fYj/17/HZqouNkR3SB+iga2PYGL+JHtACWX71v/bTNOECLl0zLPtbQQTfYCr8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BN6PR1301MB1988.namprd13.prod.outlook.com (2603:10b6:405:33::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.4; Wed, 11 May 2022 11:39:47 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94%3]) with mapi id 15.20.5250.012; Wed, 11 May 2022 11:39:47 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Bin Chen Subject: [PATCH v2 net-next 2/2] nfp: VF rate limit support Date: Wed, 11 May 2022 13:39:32 +0200 Message-Id: <20220511113932.92114-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220511113932.92114-1-simon.horman@corigine.com> References: <20220511113932.92114-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR10CA0054.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ba9144b-28dd-4bb1-0502-08da3342f3b3 X-MS-TrafficTypeDiagnostic: BN6PR1301MB1988:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nl29gWwiS2V+vDDXC32rZrEPqkkTd0Y1gNIq64hUvCxQ49dhkHIpetYktF0mrs4E6vMjZ3qNYkBzFt7RpxSUdgbRd2QO9vwngMX8HdsHgQOXmo0LqLgODjUh3CbG88re14Zj8dqvUu38BsTgQNXpy7o4h+0MOq/G1mqxpxjL6xReVyXMyCMkyKwXzb2M9sJA9lPjkt8G3jq5dpanQpuumJsNw0ElUGAlmipxhuDqGjkAMkdiUC2/5Wihh5oyomX90521hq8LLpXNT5yJLsRn54LxMeY06fyVHkWVCOK2ThJnOuj9kaBUooFvTAYvHOWApiJsi+kz4nbTtutZ0RGJhD/5G3oWYT3kUAJH1F+2TFhFqYEmEofpYnW7l7TtnGg7E2Z0fe3TOAsJmPovufdNOOt/THfGVePMXntffEwZ/aOxbZ97hXXxMeV/bfNPqbr6G97+cn4nlZdFsiz1/DOBLkaaR3jMedJ7gMr7eEiPcRuNOAkW/NZL4m6PEDHIPnvkRoOJXHycywYze6UGzQkl/YzI6b5oHiNF5hwxIDiWACX3I6jlPRgQTXqqpnzOOILsReESbrtQVuQI5oRw0fik+A7AVWnlqYdOuqWy1JEfxvDVPKxJ65dmG1GT4ij/kt3ZuISw17HBKI+yYcm2Uc+L7A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(376002)(396003)(39840400004)(346002)(136003)(6486002)(4326008)(6666004)(66946007)(66476007)(66556008)(508600001)(52116002)(83380400001)(2906002)(36756003)(8676002)(8936002)(44832011)(1076003)(107886003)(186003)(6512007)(316002)(5660300002)(2616005)(6506007)(38100700002)(86362001)(110136005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: jiw1a9ly6SQEmOBVKapsxNm5uc6xqtCr9xayOq2tprN5OiPjxbQXQT83VArU9ykFj+6lgw1LtFtWSEwhWyqxHQ16pECpIo+5JPM8gCpjvdgvPWD++hr44nB/Qr93eE29ISEwvQvESzt9JkDB/cvCtxwJ4w4dtcwpPei5yACf0RTH4zYn+ocAiezjo1OisQLBUbFizER/4mXGIS2uTf+Hb6fyFbI3khR1uHr2V+9/8+EblatA18QOLYBBslQy1ucSGbzO4UcLJMcBvur+MZ2C6cpLV5DcLgKzfrCKGPbC3tcLcTa1D/Y7KOP3Mn5ZQcsErxJ88UAHBm3s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cfIrIlDXg+pidGysX2UXD6r+o5712PbSaolEpDDmHC2G36mskdKANT9FdYrA7cpCvZUz0pGGRKK4foy1taPa7iugG3zjeDaLuMT26rOnHgu8H4KHjKg+pe9GdSp9xsqqeMtFavukJbMZGonozbDljw9n+8fxSz3ZYaBkBW89zP2tBq1tm+e7lUP0jAjJteNu+tXgPRVWFEpZcPtSFY/1nwtQd5/aEHhEoBPUbxppPx/vefLwnEFpw7OuZ6CT/eLxhQt6ZlZahY4uKtzGoAFA7sxgvMjCbeimNraSkZWbyxNId77zAGzWIgdIyypnIlwToV6hgFl2weZFIYyR5TIiI4ywcwznvIBPAcpUzewmj4+52Fa3polNfLhY6TLV4UKZljdx+bGw3 X-MS-Exchange-AntiSpam-MessageData-1: J/7edkECwyBdbgQn3eiwFMSYkTZFlOARDpE= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ba9144b-28dd-4bb1-0502-08da3342f3b3 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2022 11:39:47.7050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BtP/BYSu63ALND6xCQEavLApRQzmKccaZHmj/VaXxdD+mvuqeejEUIC1duUqpPhhzChF/p0C1fWlT43Mz+VAADnMPvlcpLwFNjuWwfB+kc8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1301MB1988 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Bin Chen Add VF rate limit feature This patch enhances the NFP driver to supports assignment of both max_tx_rate and min_tx_rate to VFs The template of configurations below is all supported. e.g. # ip link set $DEV vf $VF_NUM max_tx_rate $RATE_VALUE # ip link set $DEV vf $VF_NUM min_tx_rate $RATE_VALUE # ip link set $DEV vf $VF_NUM max_tx_rate $RATE_VALUE \ min_tx_rate $RATE_VALUE # ip link set $DEV vf $VF_NUM min_tx_rate $RATE_VALUE \ max_tx_rate $RATE_VALUE The max RATE_VALUE is limited to 0xFFFF which is about 63Gbps (using 1024 for 1G) Signed-off-by: Bin Chen Signed-off-by: Louis Peens Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman --- .../ethernet/netronome/nfp/nfp_net_common.c | 1 + .../ethernet/netronome/nfp/nfp_net_sriov.c | 48 ++++++++++++++++++- .../ethernet/netronome/nfp/nfp_net_sriov.h | 9 ++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index e3594a5c2a85..4e56a99087fa 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -1903,6 +1903,7 @@ const struct net_device_ops nfp_nfd3_netdev_ops = { .ndo_vlan_rx_kill_vid = nfp_net_vlan_rx_kill_vid, .ndo_set_vf_mac = nfp_app_set_vf_mac, .ndo_set_vf_vlan = nfp_app_set_vf_vlan, + .ndo_set_vf_rate = nfp_app_set_vf_rate, .ndo_set_vf_spoofchk = nfp_app_set_vf_spoofchk, .ndo_set_vf_trust = nfp_app_set_vf_trust, .ndo_get_vf_config = nfp_app_get_vf_config, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c b/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c index 4627715a5e32..54af30961351 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c @@ -142,6 +142,37 @@ int nfp_app_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos, return nfp_net_sriov_update(app, vf, update, "vlan"); } +int nfp_app_set_vf_rate(struct net_device *netdev, int vf, + int min_tx_rate, int max_tx_rate) +{ + struct nfp_app *app = nfp_app_from_netdev(netdev); + u32 vf_offset, ratevalue; + int err; + + err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_RATE, "rate"); + if (err) + return err; + + if (max_tx_rate >= NFP_NET_VF_RATE_MAX || + min_tx_rate >= NFP_NET_VF_RATE_MAX) { + nfp_warn(app->cpp, "tx-rate exceeds %d.\n", + NFP_NET_VF_RATE_MAX); + return -EINVAL; + } + + vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ; + ratevalue = FIELD_PREP(NFP_NET_VF_CFG_MAX_RATE, + max_tx_rate ? max_tx_rate : + NFP_NET_VF_RATE_MAX) | + FIELD_PREP(NFP_NET_VF_CFG_MIN_RATE, min_tx_rate); + + writel(ratevalue, + app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_RATE); + + return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_RATE, + "rate"); +} + int nfp_app_set_vf_spoofchk(struct net_device *netdev, int vf, bool enable) { struct nfp_app *app = nfp_app_from_netdev(netdev); @@ -228,9 +259,8 @@ int nfp_app_get_vf_config(struct net_device *netdev, int vf, struct ifla_vf_info *ivi) { struct nfp_app *app = nfp_app_from_netdev(netdev); - unsigned int vf_offset; + u32 vf_offset, mac_hi, rate; u32 vlan_tag; - u32 mac_hi; u16 mac_lo; u8 flags; int err; @@ -261,5 +291,19 @@ int nfp_app_get_vf_config(struct net_device *netdev, int vf, ivi->trusted = FIELD_GET(NFP_NET_VF_CFG_CTRL_TRUST, flags); ivi->linkstate = FIELD_GET(NFP_NET_VF_CFG_CTRL_LINK_STATE, flags); + err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_RATE, "rate"); + if (!err) { + rate = readl(app->pf->vfcfg_tbl2 + vf_offset + + NFP_NET_VF_CFG_RATE); + + ivi->max_tx_rate = FIELD_GET(NFP_NET_VF_CFG_MAX_RATE, rate); + ivi->min_tx_rate = FIELD_GET(NFP_NET_VF_CFG_MIN_RATE, rate); + + if (ivi->max_tx_rate == NFP_NET_VF_RATE_MAX) + ivi->max_tx_rate = 0; + if (ivi->min_tx_rate == NFP_NET_VF_RATE_MAX) + ivi->min_tx_rate = 0; + } + return 0; } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.h b/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.h index 7b72cc083476..2d445fa199dc 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_sriov.h @@ -20,6 +20,7 @@ #define NFP_NET_VF_CFG_MB_CAP_LINK_STATE (0x1 << 3) #define NFP_NET_VF_CFG_MB_CAP_TRUST (0x1 << 4) #define NFP_NET_VF_CFG_MB_CAP_VLAN_PROTO (0x1 << 5) +#define NFP_NET_VF_CFG_MB_CAP_RATE (0x1 << 6) #define NFP_NET_VF_CFG_MB_RET 0x2 #define NFP_NET_VF_CFG_MB_UPD 0x4 #define NFP_NET_VF_CFG_MB_UPD_MAC (0x1 << 0) @@ -28,6 +29,7 @@ #define NFP_NET_VF_CFG_MB_UPD_LINK_STATE (0x1 << 3) #define NFP_NET_VF_CFG_MB_UPD_TRUST (0x1 << 4) #define NFP_NET_VF_CFG_MB_UPD_VLAN_PROTO (0x1 << 5) +#define NFP_NET_VF_CFG_MB_UPD_RATE (0x1 << 6) #define NFP_NET_VF_CFG_MB_VF_NUM 0x7 /* VF config entry @@ -48,10 +50,17 @@ #define NFP_NET_VF_CFG_VLAN_PROT 0xffff0000 #define NFP_NET_VF_CFG_VLAN_QOS 0xe000 #define NFP_NET_VF_CFG_VLAN_VID 0x0fff +#define NFP_NET_VF_CFG_RATE 0xc +#define NFP_NET_VF_CFG_MIN_RATE 0x0000ffff +#define NFP_NET_VF_CFG_MAX_RATE 0xffff0000 + +#define NFP_NET_VF_RATE_MAX 0xffff int nfp_app_set_vf_mac(struct net_device *netdev, int vf, u8 *mac); int nfp_app_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos, __be16 vlan_proto); +int nfp_app_set_vf_rate(struct net_device *netdev, int vf, int min_tx_rate, + int max_tx_rate); int nfp_app_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting); int nfp_app_set_vf_trust(struct net_device *netdev, int vf, bool setting); int nfp_app_set_vf_link_state(struct net_device *netdev, int vf,