Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp761013rwb; Mon, 26 Sep 2022 05:38:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UYNfrNdkH3IFe1yskWWdqGfb31TX9h6RR3jPHdegU3RJvjxAlt+IIEsCGtS0aAGslizDH X-Received: by 2002:a17:90b:33d2:b0:203:15e7:1571 with SMTP id lk18-20020a17090b33d200b0020315e71571mr36117472pjb.186.1664195904642; Mon, 26 Sep 2022 05:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664195904; cv=none; d=google.com; s=arc-20160816; b=pmlXt90zFTjlWZ3WNjIjJNPoHsrnAgpYvTNVmDsm9yLT8mcA8xU9Vy+uXCDYhL9vd1 Atj0dq3HBC9sjPUwN0GbIObbOthkg6M5Ib22gWo8Po4unXp/+nIsmv7GahdxjRC8OCVY TINHeazR5faGIMfKZyUFyW2cgFGB/ZmB4YzCZmoTLz0W3aoctR1NeZ1JAcqCbTE/+qGn Ps9qx0CSgC3wKdZvAeQeRbhJaJkeSbiPSIHqugK8ErZPJ1F+C6WXLhaNeVw0pgqqlBAT xWTdxwwPtB1Q5mFRI7Y+d4Zp6hFZSnDFxi1RRPyde3hkEyNqSaoOu5Xjniz0iREbzRYU 9loA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U5ebLK6p54b+vul4cFsEwlF1EuXnfHKs1rnXp3CfQKQ=; b=ihB64ls8ftQzEVRrbilZdx9xTOi0nepyrvanYJ0dPYFM7zLDJ6P/fcmmWuGVUWDHxe 7uQk9FHS5oFdNARcmF1OzwrMJLyVUABZaS7J6GDqmv+3i8/+XhV0p46oLJ4F9zt/ptqY joJg7ayS3fCXSuDOPSDF/Dhv9iGBGEKiLXj72oRvoDLeA6s+Fn/jnG+sYFC8t0cz7I+f 1N5bgUGosaWVHFHx+JVwtcAkxiFer0JbvIC13sa8bLpt8wGflD17pN1kVXz5L988IIlO j6twD4ECjh58IynWJF+4afnqOc1U5F9ZBOT+eVcyKtV5mP9S9P7Cpdh1vgzZKaLSTx9i 3AFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cgJBad8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a63544e000000b0043447486c84si17283289pgm.875.2022.09.26.05.38.12; Mon, 26 Sep 2022 05:38:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cgJBad8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235857AbiIZKbH (ORCPT + 99 others); Mon, 26 Sep 2022 06:31:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235731AbiIZK3A (ORCPT ); Mon, 26 Sep 2022 06:29:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86494371B7; Mon, 26 Sep 2022 03:19:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0060AB80915; Mon, 26 Sep 2022 10:19:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4485DC433C1; Mon, 26 Sep 2022 10:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187549; bh=QrpR7eGmWGJOFeCxljvXhM5dhUNxn0kd5pVLLRFuS/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgJBad8oV+ZvGIk7d/ZeuKl4Tryqf67/EkyTmJwYGcaXY3Evoq4tOY8glRWF9AaGq Ehev3tBm272mhc2r/2OjfVbUIeme46W3CevdPWgsjWGqbMPKInTWi1n+2gzbr9KZ5Q CAeWQ5BW2NO3GhMEjCXylExmEdE8k0kqFmq9xtqE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Jaron , Andrii Staikov , Bharathi Sreenivas , Tony Nguyen , Sasha Levin Subject: [PATCH 4.19 43/58] i40e: Fix set max_tx_rate when it is lower than 1 Mbps Date: Mon, 26 Sep 2022 12:12:02 +0200 Message-Id: <20220926100743.020399776@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Jaron [ Upstream commit 198eb7e1b81d8ba676d0f4f120c092032ae69a8e ] While converting max_tx_rate from bytes to Mbps, this value was set to 0, if the original value was lower than 125000 bytes (1 Mbps). This would cause no transmission rate limiting to occur. This happened due to lack of check of max_tx_rate against the 1 Mbps value for max_tx_rate and the following division by 125000. Fix this issue by adding a helper i40e_bw_bytes_to_mbits() which sets max_tx_rate to minimum usable value of 50 Mbps, if its value is less than 1 Mbps, otherwise do the required conversion by dividing by 125000. Fixes: 5ecae4120a6b ("i40e: Refactor VF BW rate limiting") Signed-off-by: Michal Jaron Signed-off-by: Andrii Staikov Tested-by: Bharathi Sreenivas Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/i40e/i40e_main.c | 32 +++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 85337806efc7..9669d8c8b6c7 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -5487,6 +5487,26 @@ static int i40e_get_link_speed(struct i40e_vsi *vsi) } } +/** + * i40e_bw_bytes_to_mbits - Convert max_tx_rate from bytes to mbits + * @vsi: Pointer to vsi structure + * @max_tx_rate: max TX rate in bytes to be converted into Mbits + * + * Helper function to convert units before send to set BW limit + **/ +static u64 i40e_bw_bytes_to_mbits(struct i40e_vsi *vsi, u64 max_tx_rate) +{ + if (max_tx_rate < I40E_BW_MBPS_DIVISOR) { + dev_warn(&vsi->back->pdev->dev, + "Setting max tx rate to minimum usable value of 50Mbps.\n"); + max_tx_rate = I40E_BW_CREDIT_DIVISOR; + } else { + do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); + } + + return max_tx_rate; +} + /** * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate * @vsi: VSI to be configured @@ -5509,10 +5529,10 @@ int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate) max_tx_rate, seid); return -EINVAL; } - if (max_tx_rate && max_tx_rate < 50) { + if (max_tx_rate && max_tx_rate < I40E_BW_CREDIT_DIVISOR) { dev_warn(&pf->pdev->dev, "Setting max tx rate to minimum usable value of 50Mbps.\n"); - max_tx_rate = 50; + max_tx_rate = I40E_BW_CREDIT_DIVISOR; } /* Tx rate credits are in values of 50Mbps, 0 is disabled */ @@ -6949,9 +6969,9 @@ static int i40e_setup_tc(struct net_device *netdev, void *type_data) if (pf->flags & I40E_FLAG_TC_MQPRIO) { if (vsi->mqprio_qopt.max_rate[0]) { - u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; + u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi, + vsi->mqprio_qopt.max_rate[0]); - do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); if (!ret) { u64 credits = max_tx_rate; @@ -9613,10 +9633,10 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired) } if (vsi->mqprio_qopt.max_rate[0]) { - u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; + u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi, + vsi->mqprio_qopt.max_rate[0]); u64 credits = 0; - do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); if (ret) goto end_unlock; -- 2.35.1