From patchwork Thu Aug 4 21:11:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 73315 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1599403qga; Thu, 4 Aug 2016 14:12:31 -0700 (PDT) X-Received: by 10.66.142.105 with SMTP id rv9mr10741789pab.33.1470345150938; Thu, 04 Aug 2016 14:12:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l29si16400082pfk.67.2016.08.04.14.12.30; Thu, 04 Aug 2016 14:12:30 -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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966273AbcHDVMN (ORCPT + 27 others); Thu, 4 Aug 2016 17:12:13 -0400 Received: from mail-lf0-f49.google.com ([209.85.215.49]:35834 "EHLO mail-lf0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966130AbcHDVMF (ORCPT ); Thu, 4 Aug 2016 17:12:05 -0400 Received: by mail-lf0-f49.google.com with SMTP id f93so190787577lfi.2 for ; Thu, 04 Aug 2016 14:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SLOD4qj1IclZ8t0ojOIkmJc33ht4OwNQRGLAJDjsjxU=; b=SgsypmvcyaM+XcP0sCW98CBvJSQ3Y3VaC5d5QvgnJ3gr2P90i6XTyVsB7+HUEC3aE4 ovGT0WeMYWYnOq9lcYtizqvmkz7NHJ0Vxdkgzg5yPsmDE2r2GzBfdTqLYlL2RVioaY2j UWCoGwI31/noURY6oMPElR2sjxhfFmQwIJxSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SLOD4qj1IclZ8t0ojOIkmJc33ht4OwNQRGLAJDjsjxU=; b=E2XPlPxn6+i03ND8icG5Q2o8wRpoJFvY8YC93sN6jGTBfLlQSJ2QXs6hmGzrADFhc/ 5uGNULfpeGy3UddiAINR2e9igjA1puE63SAYOzohO1p1K1eFxBpxyBVVgUiLAoooH42n r+kJbkhX6yOCE9smTXfJbPZ7y3Yt0FiF1/Pj5vfOS9ubhR43ut4072DZ2qeXLubkkeCn JV+timI2WSiCwS1yzIK0APPgo/m+jdGnsriJNXlxCgMMStVvXPBR9JVdQveWLfQvL1HQ jkCcR4ROH+gJz81oZ+p17JnN7pGF49yzvQ8eNDUr2Cpyct19qMCSRgY4Phbjd7RUEzuj YEww== X-Gm-Message-State: AEkoous3nuaydmdZbFuEDkjPWwisPo7RH0NsP0F8/KVzSLdZ4IYu4pNd+nbgR5ZCqxzlktfi X-Received: by 10.25.170.78 with SMTP id t75mr24463620lfe.133.1470345124007; Thu, 04 Aug 2016 14:12:04 -0700 (PDT) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id o10sm2672255lfo.47.2016.08.04.14.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Aug 2016 14:12:03 -0700 (PDT) From: Ivan Khoronzhuk To: netdev@vger.kernel.org, mugunthanvnm@ti.com Cc: linux-omap@vger.kernel.org, grygorii.strashko@ti.com, linux-kernel@vger.kernel.org, Ivan Khoronzhuk Subject: [PATCH 1/2] net: core: ethtool: add per queue bandwidth command Date: Fri, 5 Aug 2016 00:11:50 +0300 Message-Id: <1470345113-804-2-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470345113-804-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1470345113-804-1-git-send-email-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Ivan Khoronzhuk --- include/linux/ethtool.h | 4 ++ include/uapi/linux/ethtool.h | 2 + net/core/ethtool.c | 102 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) -- 1.9.1 diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 9ded8c6..7e64c17 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -273,6 +273,8 @@ bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, * a TX queue has this number, return -EINVAL. If only a RX queue or a TX * queue has this number, ignore the inapplicable fields. * Returns a negative error code or zero. + * @get_per_queue_bandwidth: get per-queue bandwidth + * @set_per_queue_bandwidth: set per-queue bandwidth * @get_link_ksettings: When defined, takes precedence over the * %get_settings method. Get various device settings * including Ethernet link settings. The %cmd and @@ -368,6 +370,8 @@ struct ethtool_ops { struct ethtool_coalesce *); int (*set_per_queue_coalesce)(struct net_device *, u32, struct ethtool_coalesce *); + int (*get_per_queue_bandwidth)(struct net_device *, u32, int *); + int (*set_per_queue_bandwidth)(struct net_device *, u32, int); int (*get_link_ksettings)(struct net_device *, struct ethtool_link_ksettings *); int (*set_link_ksettings)(struct net_device *, diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index b8f38e8..0fcfe9e 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -1314,6 +1314,8 @@ struct ethtool_per_queue_op { #define ETHTOOL_GLINKSETTINGS 0x0000004c /* Get ethtool_link_settings */ #define ETHTOOL_SLINKSETTINGS 0x0000004d /* Set ethtool_link_settings */ +#define ETHTOOL_GBANDWIDTH 0x0000004e /* Get ethtool per queue bandwidth */ +#define ETHTOOL_SBANDWIDTH 0x0000004f /* Set ethtool per queue bandwidth */ /* compatibility with older code */ diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 9774898..f31d539 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -2346,6 +2346,102 @@ static int ethtool_get_per_queue_coalesce(struct net_device *dev, return 0; } +static int +ethtool_get_per_queue_bandwidth(struct net_device *dev, + void __user *useraddr, + struct ethtool_per_queue_op *per_queue_opt) +{ + u32 bit; + int ret; + DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); + + if (!dev->ethtool_ops->get_per_queue_bandwidth) + return -EOPNOTSUPP; + + useraddr += sizeof(*per_queue_opt); + + bitmap_from_u32array(queue_mask, + MAX_NUM_QUEUE, + per_queue_opt->queue_mask, + DIV_ROUND_UP(MAX_NUM_QUEUE, 32)); + + for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { + int bandwidth; + + ret = dev->ethtool_ops->get_per_queue_bandwidth(dev, bit, + &bandwidth); + if (ret != 0) + return ret; + if (copy_to_user(useraddr, &bandwidth, sizeof(bandwidth))) + return -EFAULT; + useraddr += sizeof(bandwidth); + } + + return 0; +} + +static int +ethtool_set_per_queue_bandwidth(struct net_device *dev, + void __user *useraddr, + struct ethtool_per_queue_op *per_queue_opt) +{ + u32 bit; + int n_queue; + int i, ret = 0; + int *backup = NULL, *tmp = NULL; + DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); + + if ((!dev->ethtool_ops->set_per_queue_bandwidth) || + (!dev->ethtool_ops->get_per_queue_bandwidth)) + return -EOPNOTSUPP; + + useraddr += sizeof(*per_queue_opt); + + bitmap_from_u32array(queue_mask, + MAX_NUM_QUEUE, + per_queue_opt->queue_mask, + DIV_ROUND_UP(MAX_NUM_QUEUE, 32)); + n_queue = bitmap_weight(queue_mask, MAX_NUM_QUEUE); + tmp = kmalloc_array(n_queue, sizeof(*backup), GFP_KERNEL); + if (!tmp) + return -ENOMEM; + backup = tmp; + + for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { + int bandwidth; + + ret = dev->ethtool_ops->get_per_queue_bandwidth(dev, bit, tmp); + if (ret != 0) + goto roll_back; + + tmp++; + + if (copy_from_user(&bandwidth, useraddr, sizeof(bandwidth))) { + ret = -EFAULT; + goto roll_back; + } + + ret = dev->ethtool_ops->set_per_queue_bandwidth(dev, bit, + bandwidth); + if (ret != 0) + goto roll_back; + + useraddr += sizeof(bandwidth); + } + +roll_back: + if (ret != 0) { + tmp = backup; + for_each_set_bit(i, queue_mask, bit) { + dev->ethtool_ops->set_per_queue_bandwidth(dev, i, *tmp); + tmp++; + } + } + kfree(backup); + + return ret; +} + static int ethtool_set_per_queue_coalesce(struct net_device *dev, void __user *useraddr, struct ethtool_per_queue_op *per_queue_opt) @@ -2417,6 +2513,12 @@ static int ethtool_set_per_queue(struct net_device *dev, void __user *useraddr) return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt); case ETHTOOL_SCOALESCE: return ethtool_set_per_queue_coalesce(dev, useraddr, &per_queue_opt); + case ETHTOOL_GBANDWIDTH: + return ethtool_get_per_queue_bandwidth(dev, useraddr, + &per_queue_opt); + case ETHTOOL_SBANDWIDTH: + return ethtool_set_per_queue_bandwidth(dev, useraddr, + &per_queue_opt); default: return -EOPNOTSUPP; };