From patchwork Tue Oct 17 15:49:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 827104 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=osuosl.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yGft43VxQz9t32 for ; Wed, 18 Oct 2017 02:55:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0925087542; Tue, 17 Oct 2017 15:55:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id owE9wZJhKiyL; Tue, 17 Oct 2017 15:55:35 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 8986287519; Tue, 17 Oct 2017 15:55:35 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 227C61C0359 for ; Tue, 17 Oct 2017 15:55:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E5B552FDC7 for ; Tue, 17 Oct 2017 15:55:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IDA72PA9Cn-P for ; Tue, 17 Oct 2017 15:55:30 +0000 (UTC) X-Greylist: delayed 00:05:10 by SQLgrey-1.7.6 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) by silver.osuosl.org (Postfix) with ESMTPS id AAA6F2FDA8 for ; Tue, 17 Oct 2017 15:55:29 +0000 (UTC) Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0McFi3-1dlZhT2bW3-00JWYr; Tue, 17 Oct 2017 17:50:04 +0200 From: Arnd Bergmann To: Jeff Kirsher Date: Tue, 17 Oct 2017 17:49:48 +0200 Message-Id: <20171017155001.318184-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:jJQ7nZmcSySy6bHGzi0hT+yP4/fsBP62qcbD1OxWlmZmKYqAYwA veRpJNc/oeZ2BjMtzySEXSutu7GM2NjLppykJOkdUjAgeFSUNs1V21UD7kXdmuZK4SbDZS+ s31L6AQdWJe3vPxRqbz6+FiUINE+2YVfE/rpQ1tYf8K7kEJhmHEDf7MDBknguIcSwgisW4e JX5nFpy7xOzo02IK/8+3A== X-UI-Out-Filterresults: notjunk:1; V01:K0:KOj1hQxrLeM=:6KFS0Ta49wrEHW7EMGV9bc BsN3dQwHT17VcLykMMXRq78cQ8w9+18ybssDJLVUR0QNCRzaSOI2hgRSfs3akH5A01/Ay/V8f fk1wXqd8YC6HTSTCP6KJYT/QmK892d89M+zGJRNjLBgeYy/h6rbsLTYRvI5apMF4DDG5dQRQz 9X7ZmiM3D7dym/hohsXnlZdWo3Y4YQLvDxxxgoggwhbsnNzCfcm5Jg2Jb/I/cC7IVgO+OhO3k x68uvFK3BjQEzicWkX38HSVOYOtUwoXgAQh4Q9yDL3fCibuEfXARssjfRxq5qNp2MlHLLlz7a JlXCON2Yb/RZ/TAqfQfFKVHIIWmOYF+lXM+z7mea1px0LUwEPwmg5dd221X1DbPs5PaAbK/Zy B2zg+0laqfKImU7moj/+E2lDaqI5LxIRyUleAtXwob1U4kGDCCA1X9elNTPJ12tmXLGx4lpJn 3t3AsPcWsRLO9e2kcSyKOPBArUNStJ1iwUsd2jrav25GoPzAfm98pfNY/IOQIjJOj+opaRa5S RKhGLNg1yy3yjfEvhveDgiJlsAi5Tq/5v7R3n9wzfagabQ9jswVMbr7x9gjKrSHKTWxU4e9ku vL1OkYUh76kpWzUZqNGkJ06iGPnSdaZEBUUHPEFcQoi1D9iUsg4UglHTOfxUFLLnMD18YEFbl 85KgCsoQgboPCp5CF1Uc7JegpQnwYWOZ+0cbAsRWdJPIoVVuFQrs6Uv/HAYM7wAsKcCv86Q7U 3T9zDUG4zhFAmFb9aEmB3F3bQ5hvkhU+g/zgcw== Cc: Arnd Bergmann , netdev@vger.kernel.org, Mitch Williams , linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Filip Sadowski , "David S. Miller" Subject: [Intel-wired-lan] [PATCH] [v2] i40e: avoid 64-bit division where possible X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" The new bandwidth calculation caused a link error on 32-bit architectures, like ERROR: "__aeabi_uldivmod" [drivers/net/ethernet/intel/i40e/i40e.ko] undefined! The problem is the max_tx_rate calculation that uses 64-bit integers. This is not really necessary since the numbers are in MBit/s so they won't be higher than 40000 for the highest support rate, and are guaranteed to not exceed 2^32 in future generations either. Another patch from Alan Brady fixed the link error by adding many calls to do_div(), which makes the code less efficent and less readable than necessary. This changes the representation to 'u32' when dealing with MBit/s and uses div_u64() to convert from u64 numbers in byte/s, reverting parts of Alan's earlier fix that have become obsolete now. Fixes: 2027d4deacb1 ("i40e: Add support setting TC max bandwidth rates") Fixes: 73983b5ae011 ("i40e: fix u64 division usage") Cc: Alan Brady Signed-off-by: Arnd Bergmann Reviewed-by: Alexander Duyck --- drivers/net/ethernet/intel/i40e/i40e.h | 4 +- drivers/net/ethernet/intel/i40e/i40e_main.c | 70 +++++++++++------------------ 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index c3f13120f3ce..c7aa0c982273 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -407,7 +407,7 @@ struct i40e_channel { u8 enabled_tc; struct i40e_aqc_vsi_properties_data info; - u64 max_tx_rate; + u32 max_tx_rate; /* in Mbits/s */ /* track this channel belongs to which VSI */ struct i40e_vsi *parent_vsi; @@ -1101,5 +1101,5 @@ static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi) } int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch); -int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate); +int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u32 max_tx_rate); #endif /* _I40E_H_ */ diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 3ceda140170d..57682cc78508 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -5448,17 +5448,16 @@ int i40e_get_link_speed(struct i40e_vsi *vsi) * * Helper function to set BW limit for a given VSI **/ -int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate) +int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u32 max_tx_rate) { struct i40e_pf *pf = vsi->back; - u64 credits = 0; int speed = 0; int ret = 0; speed = i40e_get_link_speed(vsi); if (max_tx_rate > speed) { dev_err(&pf->pdev->dev, - "Invalid max tx rate %llu specified for VSI seid %d.", + "Invalid max tx rate %u specified for VSI seid %d.", max_tx_rate, seid); return -EINVAL; } @@ -5469,13 +5468,12 @@ int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate) } /* Tx rate credits are in values of 50Mbps, 0 is disabled */ - credits = max_tx_rate; - do_div(credits, I40E_BW_CREDIT_DIVISOR); - ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits, + ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, + max_tx_rate / I40E_BW_CREDIT_DIVISOR, I40E_MAX_BW_INACTIVE_ACCUM, NULL); if (ret) dev_err(&pf->pdev->dev, - "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n", + "Failed set tx rate (%u Mbps) for vsi->seid %u, err %s aq_err %s\n", max_tx_rate, seid, i40e_stat_str(&pf->hw, ret), i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); return ret; @@ -6158,17 +6156,13 @@ int i40e_create_queue_channel(struct i40e_vsi *vsi, /* configure VSI for BW limit */ if (ch->max_tx_rate) { - u64 credits = ch->max_tx_rate; - if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate)) return -EINVAL; - do_div(credits, I40E_BW_CREDIT_DIVISOR); dev_dbg(&pf->pdev->dev, - "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", + "Set tx rate of %u Mbps (count of 50Mbps %u) for vsi->seid %u\n", ch->max_tx_rate, - credits, - ch->seid); + ch->max_tx_rate / I40E_BW_CREDIT_DIVISOR, ch->seid); } /* in case of VF, this will be main SRIOV VSI */ @@ -6189,7 +6183,6 @@ int i40e_create_queue_channel(struct i40e_vsi *vsi, static int i40e_configure_queue_channels(struct i40e_vsi *vsi) { struct i40e_channel *ch; - u64 max_rate = 0; int ret = 0, i; /* Create app vsi with the TCs. Main VSI with TC0 is already set up */ @@ -6211,9 +6204,8 @@ static int i40e_configure_queue_channels(struct i40e_vsi *vsi) /* Bandwidth limit through tc interface is in bytes/s, * change to Mbit/s */ - max_rate = vsi->mqprio_qopt.max_rate[i]; - do_div(max_rate, I40E_BW_MBPS_DIVISOR); - ch->max_tx_rate = max_rate; + ch->max_tx_rate = div_u64(vsi->mqprio_qopt.max_rate[i], + I40E_BW_CREDIT_DIVISOR); list_add_tail(&ch->list, &vsi->ch_list); @@ -6643,7 +6635,6 @@ static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi, struct tc_mqprio_qopt_offload *mqprio_qopt) { u64 sum_max_rate = 0; - u64 max_rate = 0; int i; if (mqprio_qopt->qopt.offset[0] != 0 || @@ -6658,9 +6649,8 @@ static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi, "Invalid min tx rate (greater than 0) specified\n"); return -EINVAL; } - max_rate = mqprio_qopt->max_rate[i]; - do_div(max_rate, I40E_BW_MBPS_DIVISOR); - sum_max_rate += max_rate; + sum_max_rate += div_u64(mqprio_qopt->max_rate[i], + I40E_BW_CREDIT_DIVISOR); if (i >= mqprio_qopt->qopt.num_tc - 1) break; @@ -6804,18 +6794,14 @@ 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]; - - do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); + u32 max_tx_rate = div_u64(vsi->mqprio_qopt.max_rate[0], + I40E_BW_CREDIT_DIVISOR); ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); if (!ret) { - u64 credits = max_tx_rate; - - do_div(credits, I40E_BW_CREDIT_DIVISOR); dev_dbg(&vsi->back->pdev->dev, - "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", + "Set tx rate of %u Mbps (count of 50Mbps %u) for vsi->seid %u\n", max_tx_rate, - credits, + max_tx_rate / I40E_BW_CREDIT_DIVISOR, vsi->seid); } else { need_reset = true; @@ -9024,15 +9010,12 @@ static int i40e_rebuild_channels(struct i40e_vsi *vsi) return ret; } if (ch->max_tx_rate) { - u64 credits = ch->max_tx_rate; - if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate)) return -EINVAL; - do_div(credits, I40E_BW_CREDIT_DIVISOR); dev_dbg(&vsi->back->pdev->dev, - "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", + "Set tx rate of %u Mbps (count of 50Mbps %u) for vsi->seid %u\n", ch->max_tx_rate, ch->max_tx_rate / I40E_BW_CREDIT_DIVISOR, ch->seid); @@ -9314,21 +9297,18 @@ 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 credits = 0; + u32 max_tx_rate = div_u64(vsi->mqprio_qopt.max_rate[0], + I40E_BW_CREDIT_DIVISOR); - do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); - if (ret) + if (!ret) + dev_dbg(&vsi->back->pdev->dev, + "Set tx rate of %u Mbps (count of 50Mbps %u) for vsi->seid %u\n", + max_tx_rate, + max_tx_rate / I40E_BW_CREDIT_DIVISOR, + vsi->seid); + else goto end_unlock; - - credits = max_tx_rate; - do_div(credits, I40E_BW_CREDIT_DIVISOR); - dev_dbg(&vsi->back->pdev->dev, - "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", - max_tx_rate, - credits, - vsi->seid); } ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);