Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp324460ybe; Tue, 10 Sep 2019 19:47:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPBDX0snEELX4cLu1/grKCRjKK7YBd0/upXLdj1hxpg48Xd0q5HC8pX/b0VQu6RtttpCl2 X-Received: by 2002:a17:906:1944:: with SMTP id b4mr27832675eje.44.1568170034590; Tue, 10 Sep 2019 19:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568170034; cv=none; d=google.com; s=arc-20160816; b=nRaYhWJ+r8kahDMTeqQ2o9gsSsy1+Nx95kcZ9sPOgz04joqbuTOrC33cG+tdgUiijE KM0OQSFmVCTbB0Plgnql4ednCymbAzq14GRv6bqnhmLVwLky5lPIr9pqyJZcilfRjhU4 22caNt8ZxCdBADLOwM6c/Ka1m/EOs1xLSuDU84B9/d5An/IXLBX9W/kl8MkJlUO1rInE izgwaV0CqeFJeg8A//EkR0hM7bl1+N/96YzxcGLzeJg955VMsGt+crOAkxosXwdBXemy X6aMzPXsX13h/tHpd28jWxQWEh3otThzYaAYKMKTcJHahLV0NNI+sCzhPDpccWlPaTSp WSDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=FuM6Ta6A2tlmUFXdVEQYGVy2fjqinxHTNMYadVV5sBU=; b=z7t5Vm8Dc+JmNNCwRSfXotaROfj/b4uo2mydHtJ6sdEl7DDQGfooke1G2fhV2fo33x EbntDpXWjuKtk6NxSJM0gL/eWAC2dDnciZBkNE+SoagvAXdoRuIDTarcSSIN+g4KNUlg L6YRW+ZpSbh24+Xw9fFLpRqoo5LnVpVdPqocrwWweU2Z2xQ3FQWk6Lqytcvype8+SP7x RcYkIP9GcVVSw8oCH81OUQiLon8m1Y7K3b0ovDxKG0UBXrS1+Qi4fdYIG6H0lNJk6yIK j9/M9WOEKjKSFKKilYQ2v5ZKCvZTn2rXko7R/PDC00h148oF9kOoZpoEfml3zbwYYCWL Fong== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12si10299974ejc.84.2019.09.10.19.46.51; Tue, 10 Sep 2019 19:47:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726724AbfIKCnH (ORCPT + 99 others); Tue, 10 Sep 2019 22:43:07 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51194 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726579AbfIKCnG (ORCPT ); Tue, 10 Sep 2019 22:43:06 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7AFF71699A46C51D7781; Wed, 11 Sep 2019 10:43:05 +0800 (CST) Received: from localhost.localdomain (10.67.212.132) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Wed, 11 Sep 2019 10:42:59 +0800 From: Huazhong Tan To: CC: , , , , , Subject: [PATCH V2 net-next 3/7] net: hns3: fix shaper parameter algorithm Date: Wed, 11 Sep 2019 10:40:35 +0800 Message-ID: <1568169639-43658-4-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568169639-43658-1-git-send-email-tanhuazhong@huawei.com> References: <1568169639-43658-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.132] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yonglong Liu Currently when hns3 driver configures the tm shaper to limit bandwidth below 20Mbit using the parameters calculated by hclge_shaper_para_calc(), the actual bandwidth limited by tm hardware module is not accurate enough, for example, 1.28 Mbit when the user is configuring 1 Mbit. This patch adjusts the ir_calc to be closer to ir, and always calculate the ir_b parameter when user is configuring a small bandwidth. Also, removes an unnecessary parenthesis when calculating denominator. Fixes: 848440544b41 ("net: hns3: Add support of TX Scheduler & Shaper to HNS3 driver") Signed-off-by: Yonglong Liu Signed-off-by: Huazhong Tan --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c index e829101..9f0e35f 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c @@ -81,16 +81,13 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level, return 0; } else if (ir_calc > ir) { /* Increasing the denominator to select ir_s value */ - while (ir_calc > ir) { + while (ir_calc >= ir && ir) { ir_s_calc++; ir_calc = DIVISOR_IR_B_126 / (tick * (1 << ir_s_calc)); } - if (ir_calc == ir) - *ir_b = 126; - else - *ir_b = (ir * tick * (1 << ir_s_calc) + - (DIVISOR_CLK >> 1)) / DIVISOR_CLK; + *ir_b = (ir * tick * (1 << ir_s_calc) + (DIVISOR_CLK >> 1)) / + DIVISOR_CLK; } else { /* Increasing the numerator to select ir_u value */ u32 numerator; @@ -104,7 +101,7 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level, if (ir_calc == ir) { *ir_b = 126; } else { - u32 denominator = (DIVISOR_CLK * (1 << --ir_u_calc)); + u32 denominator = DIVISOR_CLK * (1 << --ir_u_calc); *ir_b = (ir * tick + (denominator >> 1)) / denominator; } } -- 2.7.4