From patchwork Sat May 20 00:58:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 764846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wV04W01dXz9s2Q for ; Sat, 20 May 2017 06:28:27 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 8EE368A173; Fri, 19 May 2017 20:28:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BdTg04aiQlkO; Fri, 19 May 2017 20:28:25 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 07A668A16E; Fri, 19 May 2017 20:28:25 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 0E7FF1C40AE for ; Fri, 19 May 2017 20:28:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0901088134 for ; Fri, 19 May 2017 20:28:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RjdwfwLn26WO for ; Fri, 19 May 2017 20:28:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by fraxinus.osuosl.org (Postfix) with ESMTPS id EFACA880EE for ; Fri, 19 May 2017 20:28:19 +0000 (UTC) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 May 2017 13:28:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,365,1491289200"; d="scan'208";a="104327610" Received: from anamdev.jf.intel.com ([10.166.29.110]) by fmsmga005.fm.intel.com with ESMTP; 19 May 2017 13:28:19 -0700 From: Amritha Nambiar To: intel-wired-lan@lists.osuosl.org Date: Fri, 19 May 2017 17:58:38 -0700 Message-ID: <149524191856.11022.14942959596600821849.stgit@anamdev.jf.intel.com> In-Reply-To: <149524122523.11022.4541073724650541658.stgit@anamdev.jf.intel.com> References: <149524122523.11022.4541073724650541658.stgit@anamdev.jf.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: netdev@vger.kernel.org Subject: [Intel-wired-lan] [PATCH 4/4] [next-queue]net: i40e: Add support to set max bandwidth rates for TCs offloaded via tc/mqprio 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: , Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" This patch enables setting up maximum Tx rates for the traffic classes in i40e. The maximum rate offloaded to the hardware through the mqprio framework is configured for the VSI. Configuring minimum Tx rate limit is not supported in the device. The minimum usable value for Tx rate is 50Mbps. Example: # tc qdisc add dev eth0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1\ queues 4@0 4@4 min_rate 0Mbit 0Mbit max_rate 55Mbit 60Mbit hw 2 To dump the bandwidth rates: # tc qdisc show dev eth0 qdisc mqprio 804a: root tc 2 map 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 queues:(0:3) (4:7) min rates:0bit 0bit max rates:55Mbit 60Mbit Signed-off-by: Amritha Nambiar Signed-off-by: Kiran Patil --- drivers/net/ethernet/intel/i40e/i40e.h | 2 + drivers/net/ethernet/intel/i40e/i40e_main.c | 102 ++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index a62f65a..83a060d 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -346,6 +346,8 @@ struct i40e_channel { u8 enabled_tc; struct i40e_aqc_vsi_properties_data info; + u32 max_tx_rate; + /* track this channel belongs to which VSI */ struct i40e_vsi *parent_vsi; }; diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 7f61d4f..3261dab 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -69,6 +69,8 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired); static void i40e_fdir_sb_setup(struct i40e_pf *pf); static int i40e_veb_get_bw_info(struct i40e_veb *veb); static int i40e_vsi_config_rss(struct i40e_vsi *vsi); +static int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 ch_seid, + u32 max_tx_rate); /* i40e_pci_tbl - PCI Device ID Table * @@ -5033,7 +5035,7 @@ static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, u8 *bw_share) { struct i40e_aqc_configure_vsi_tc_bw_data bw_data; - i40e_status ret; + i40e_status ret = 0; int i; bw_data.tc_valid_bits = enabled_tc; @@ -5041,8 +5043,20 @@ static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, bw_data.tc_bw_credits[i] = bw_share[i]; if ((vsi->back->flags & I40E_FLAG_TC_MQPRIO) || - !vsi->mqprio_qopt.qopt.hw) - return 0; + !vsi->mqprio_qopt.qopt.hw) { + if (vsi->mqprio_qopt.max_rate[0]) { + u32 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; + + max_tx_rate = (max_tx_rate * 8) / 1000000; + + ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); + if (ret) + dev_err(&vsi->back->pdev->dev, + "Failed to set tx rate (%u Mbps) for vsi->seid %u, error code %d.\n", + max_tx_rate, vsi->seid, ret); + } + return ret; + } ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, NULL); @@ -5297,6 +5311,71 @@ static void i40e_remove_queue_channel(struct i40e_vsi *vsi) } /** + * i40e_set_bw_limit - setup BW limit based on max_tx_rate + * @vsi: the VSI being setup + * @ch_seid: seid of the channel (VSI) + * @max_tx_rate: max TX rate to be configured as BW limit + * + * This function sets up BW limit for a given channel (ch_seid) + * based on max TX rate specified. + **/ +static int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 ch_seid, u32 max_tx_rate) +{ + struct i40e_pf *pf = vsi->back; + int speed = 0; + int ret = 0; + + switch (pf->hw.phy.link_info.link_speed) { + case I40E_LINK_SPEED_40GB: + speed = 40000; + break; + case I40E_LINK_SPEED_20GB: + speed = 20000; + break; + case I40E_LINK_SPEED_10GB: + speed = 10000; + break; + case I40E_LINK_SPEED_1GB: + speed = 1000; + break; + default: + break; + } + + if (max_tx_rate > speed) { + dev_err(&pf->pdev->dev, + "Invalid tx rate %d specified for channel seid %d.", + max_tx_rate, ch_seid); + return -EINVAL; + } + + if ((max_tx_rate < 50) && (max_tx_rate > 0)) { + dev_warn(&pf->pdev->dev, + "Setting tx rate to minimum usable value of 50Mbps.\n"); + max_tx_rate = 50; + } + +#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */ +#define I40E_MAX_BW_INACTIVE_ACCUM 1 + + /* TX rate credits are in values of 50Mbps, 0 is disabled*/ + ret = i40e_aq_config_vsi_bw_limit(&pf->hw, ch_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 (%u Mbps) for vsi->seid %u, error code %d.\n", + max_tx_rate, ch_seid, ret); + else + dev_info(&pf->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, + ch_seid); + return ret; +} + +/** * i40e_is_any_channel - channel exist or not * @vsi: ptr to VSI to which channels are associated with * @@ -5882,6 +5961,11 @@ int i40e_create_queue_channel(struct i40e_vsi *vsi, "Setup channel (id:%u) utilizing num_queues %d\n", ch->seid, ch->num_queue_pairs); + /* configure VSI for BW limit */ + if (ch->max_tx_rate) + if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate)) + return -EINVAL; + /* in case of VF, this will be main SRIOV VSI */ ch->parent_vsi = vsi; @@ -5918,6 +6002,13 @@ static int i40e_configure_queue_channel(struct i40e_vsi *vsi) vsi->tc_config.tc_info[i].qcount; ch->base_queue = vsi->tc_config.tc_info[i].qoffset; + ch->max_tx_rate = + vsi->mqprio_qopt.max_rate[i]; + + /* Bandwidth limit through tc interface is in bytes/s, + * change to Mbit/s + */ + ch->max_tx_rate = (ch->max_tx_rate * 8) / 1000000; list_add_tail(&ch->list, &vsi->ch_list); @@ -6346,8 +6437,11 @@ int i40e_validate_mqprio_queue_mapping(struct i40e_vsi *vsi, if (!mqprio_qopt->qopt.count[i]) return -EINVAL; - if (mqprio_qopt->min_rate[i] || mqprio_qopt->max_rate[i]) + if (mqprio_qopt->min_rate[i]) { + dev_err(&vsi->back->pdev->dev, + "Invalid min tx rate (greater than 0) specified\n"); return -EINVAL; + } if (i >= mqprio_qopt->qopt.num_tc - 1) break;