From patchwork Thu Aug 4 21:11:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 73319 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1599909qga; Thu, 4 Aug 2016 14:13:45 -0700 (PDT) X-Received: by 10.98.56.207 with SMTP id f198mr129278990pfa.83.1470345225756; Thu, 04 Aug 2016 14:13:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w87si16379083pfj.166.2016.08.04.14.13.45; Thu, 04 Aug 2016 14:13:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966104AbcHDVNV (ORCPT + 4 others); Thu, 4 Aug 2016 17:13:21 -0400 Received: from mail-lf0-f48.google.com ([209.85.215.48]:34269 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966178AbcHDVMJ (ORCPT ); Thu, 4 Aug 2016 17:12:09 -0400 Received: by mail-lf0-f48.google.com with SMTP id l69so190442118lfg.1 for ; Thu, 04 Aug 2016 14:12:08 -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=rTg/6X5bLT/Mb1BRbvEz7CZ5BnYSTKnuF1P1rVUsP/I=; b=HJxQYJYKAvJSYt+HYD5uck2t/hGKJIyzvP7GI43Tkj8vzbL+QGKS126kU1ro9i44sk RqpE23frvwt9ZfBVJpXV/rZgfK5R1Pvlxr/bxkB/A+oncg3lHHorGux34FbqFzq80N50 rqWuE2st4hKqlnlzI36j9wTVtcEUaaO2vPwac= 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=rTg/6X5bLT/Mb1BRbvEz7CZ5BnYSTKnuF1P1rVUsP/I=; b=WaCfVXtgBlx2q/zH5qU9H8rOhN+nDr/rmtBFNBcqDHDH7QUuD9eohInYLx7+FPObcr o+OEumhesCd4MM4E15RAv5jSvLcd8y9VWFRgSSggxNhHKLVLWZpID6X4UzLQNvemSFw3 9vP83H16LA3qi/R8Ll7O2NtFDQUfCh9nCZAuv5v3wYS9gq6VAhOlnaTHejwF1JsdXSZZ 60K9uXsDpWyLmtb0+C9/52Hg5jsCOS0VmX7vidmytz6KXGsgEFHQIMT3uVIIXKnYxqHu 6DEXR3mho5v69VBLf7tN/qfG+u/X5/NJivOrtv1gWLYQUqxDa473s7ZXMoBJOt90Pm9U xbMw== X-Gm-Message-State: AEkoousJE66xtt1TYrbPASrTceLUUZ/uPDa70eUV56CCtfzJMC4Y8wrpZKHlwkY1D8iggo7S X-Received: by 10.25.157.146 with SMTP id g140mr19923405lfe.172.1470345127482; Thu, 04 Aug 2016 14:12:07 -0700 (PDT) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id o10sm2672255lfo.47.2016.08.04.14.12.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Aug 2016 14:12:06 -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 2/2] net: core: ethtool: add ringparam perqueue command Date: Fri, 5 Aug 2016 00:11:53 +0300 Message-Id: <1470345113-804-5-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 It useful feature to be able to configure number of buffers for every queue. Signed-off-by: Ivan Khoronzhuk --- include/linux/ethtool.h | 4 ++ net/core/ethtool.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 7e64c17..7109736 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -372,6 +372,10 @@ struct ethtool_ops { 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_per_queue_ringparam)(struct net_device *, u32, + struct ethtool_ringparam *); + int (*set_per_queue_ringparam)(struct net_device *, u32, + struct ethtool_ringparam *); int (*get_link_ksettings)(struct net_device *, struct ethtool_link_ksettings *); int (*set_link_ksettings)(struct net_device *, diff --git a/net/core/ethtool.c b/net/core/ethtool.c index f31d539..42a7cb3 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -2347,6 +2347,104 @@ static int ethtool_get_per_queue_coalesce(struct net_device *dev, } static int +ethtool_get_per_queue_ringparam(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_ringparam) + 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) { + struct ethtool_ringparam + ringparam = { .cmd = ETHTOOL_GRINGPARAM }; + + ret = dev->ethtool_ops->get_per_queue_ringparam(dev, bit, + &ringparam); + if (ret != 0) + return ret; + if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) + return -EFAULT; + useraddr += sizeof(ringparam); + } + + return 0; +} + +static int +ethtool_set_per_queue_ringparam(struct net_device *dev, + void __user *useraddr, + struct ethtool_per_queue_op *per_queue_opt) +{ + struct ethtool_ringparam *backup = NULL, *tmp = NULL; + DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); + int i, ret = 0; + int n_queue; + u32 bit; + + if ((!dev->ethtool_ops->set_per_queue_ringparam) || + (!dev->ethtool_ops->get_per_queue_ringparam)) + 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) { + struct ethtool_ringparam + ringparam = { .cmd = ETHTOOL_SRINGPARAM }; + + ret = dev->ethtool_ops->get_per_queue_ringparam(dev, bit, tmp); + if (ret != 0) + goto roll_back; + + tmp++; + + if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) { + ret = -EFAULT; + goto roll_back; + } + + ret = dev->ethtool_ops->set_per_queue_ringparam(dev, bit, + &ringparam); + if (ret != 0) + goto roll_back; + + useraddr += sizeof(ringparam); + } + +roll_back: + if (ret != 0) { + tmp = backup; + for_each_set_bit(i, queue_mask, bit) { + dev->ethtool_ops->set_per_queue_ringparam(dev, i, tmp); + tmp++; + } + } + kfree(backup); + + return ret; +} + +static int ethtool_get_per_queue_bandwidth(struct net_device *dev, void __user *useraddr, struct ethtool_per_queue_op *per_queue_opt) @@ -2509,6 +2607,12 @@ static int ethtool_set_per_queue(struct net_device *dev, void __user *useraddr) return -EFAULT; switch (per_queue_opt.sub_command) { + case ETHTOOL_GRINGPARAM: + return ethtool_get_per_queue_ringparam(dev, useraddr, + &per_queue_opt); + case ETHTOOL_SRINGPARAM: + return ethtool_set_per_queue_ringparam(dev, useraddr, + &per_queue_opt); case ETHTOOL_GCOALESCE: return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt); case ETHTOOL_SCOALESCE: