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: 9264291 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 86F336048F for ; Thu, 4 Aug 2016 21:13:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76062276AE for ; Thu, 4 Aug 2016 21:13:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7D228407; Thu, 4 Aug 2016 21:13:45 +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 2A17F276AE for ; Thu, 4 Aug 2016 21:13:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966104AbcHDVNV (ORCPT ); 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: