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: 9264293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DA016048F for ; Thu, 4 Aug 2016 21:13:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C7C2276AE for ; Thu, 4 Aug 2016 21:13:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1123728407; Thu, 4 Aug 2016 21:13:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93277276AE for ; Thu, 4 Aug 2016 21:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966195AbcHDVMJ (ORCPT ); Thu, 4 Aug 2016 17:12:09 -0400 Received: from mail-lf0-f54.google.com ([209.85.215.54]:34248 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966143AbcHDVMF (ORCPT ); Thu, 4 Aug 2016 17:12:05 -0400 Received: by mail-lf0-f54.google.com with SMTP id l69so190441222lfg.1 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=bUWx2kVlD7McAfQH9JTdBQYXTcx4CViF7pXV7vZrhfjsbhIFP2NV4B/Z2Bm0hkR+SQ oAOFtMhibutyRwmi2C8fnzubEVLawGZbU+uQJNbUOUaDSJdlDN1J1MXiKvZEdhFYwcKU YHzgmPTHh+nm837agxRtuuY4gnLQxiogUGSvfLObL2h5EPlRGFXmAqH+29RS9nivToDu ByELqfkcKHhoK8L5Td+vHBaWe2VOdKcKV/UYpZwmvSY8WyxrbzZqTv/6x1vhCUUwkK02 m/QJYsgvZEvEYHCmoOrEjsXNC4atFWvGBToGuFFFxqmhdfrlTFetm2RJjrLvc/qrMi3/ 5ZNw== X-Gm-Message-State: AEkooutrdsMWFQT5hyFQMF7lWIUk1XniM0ohi1ITjCCpBPSsC36Gg1Y3vmoDv6gNjvHYM4O+ 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-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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; };