From patchwork Thu Sep 19 09:23:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 1164492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Yryc3Td4z9sPD; Thu, 19 Sep 2019 19:24:24 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iAsfj-0004mw-Oi; Thu, 19 Sep 2019 09:24:19 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iAsfZ-0004fD-I7 for kernel-team@lists.ubuntu.com; Thu, 19 Sep 2019 09:24:09 +0000 Received: from mail-io1-f70.google.com ([209.85.166.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iAsfY-0001Fd-M6 for kernel-team@lists.ubuntu.com; Thu, 19 Sep 2019 09:24:08 +0000 Received: by mail-io1-f70.google.com with SMTP id g8so4244119iop.19 for ; Thu, 19 Sep 2019 02:24:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2U1jfCvsoIrye1FkWuTEUxNlLMuNN07ynukeccKHhh0=; b=l3UhmfSpuCJ+ToKIQzPeeNM9IrafT7LpnHbXw24OUPeaJRKJzzQxCdH/GHdGqT7Nmh T5x4e0osZxcWSgxn3CiTtgF2BppQvfsBEmystT8/1+tsviB0p4yo7yE8eu4j1AcONvQl tKZOccAFK4TrrSmrH4vWjLzWzmwTLdW6938fCO5rfIAF0keEZ+xAwdd9Q4tUlwPLtqEf Fxz7kNovx6sHEQd92E3H49bREqTa/S9Dy8FRaH2ICTIo0YMMRsvR8tXz9sIOw3aCCtvZ VhPTnKPBwb0QtMgC6sEuA9gV4onz0eB+vNLRq7eVEExWut+XL7K7yU+nniIU1GaSJSgd ZKQA== X-Gm-Message-State: APjAAAWaEiXjgLP30apKo/7r4oB5LeWYC4whJ2fgECfT1jC5R8S4KfOT NGpo8Kp3uUDTvOU6pfha4tRVM0LKp0DRg3tCfJscCo8mOYWfOLJFwad/aVfkSgQf1bWTl+wAomI BwGfJwnhsi32GqdYT3n0bpFEP9e5a9Cb2Fa8nnJQDkA== X-Received: by 2002:a5e:8c15:: with SMTP id n21mr10539041ioj.246.1568885046943; Thu, 19 Sep 2019 02:24:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLLJIUD87eOd3LLVbPrpN0qoVBNlfD7llcjHyOVChGyGkWuyICI2eW10veByHULl9O3MP7kw== X-Received: by 2002:a5e:8c15:: with SMTP id n21mr10538985ioj.246.1568885046040; Thu, 19 Sep 2019 02:24:06 -0700 (PDT) Received: from kbuntu2.fuzzbuzz.org (dhcp-24-53-242-107.cable.user.start.ca. [24.53.242.107]) by smtp.gmail.com with ESMTPSA id d9sm798937ioq.9.2019.09.19.02.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 02:24:05 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [SRU][Xenial/gcp][PATCH 11/11] virtio_net: ethtool tx napi configuration Date: Thu, 19 Sep 2019 05:23:53 -0400 Message-Id: <20190919092353.29993-12-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190919092353.29993-1-khalid.elmously@canonical.com> References: <20190919092353.29993-1-khalid.elmously@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Wang BugLink: https://bugs.launchpad.net/bugs/1810457 Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame. Toggle tx napi through setting tx-frames. So as to not interfere with possible future interrupt moderation, value 1 means tx napi while value 0 means not. Only allow the switching when device is down for simplicity. Link: https://patchwork.ozlabs.org/patch/948149/ Suggested-by: Jason Wang Signed-off-by: Willem de Bruijn Signed-off-by: Jason Wang Signed-off-by: David S. Miller (cherry picked from commit 0c465be183c7c57a26446df6ea96d8676b865f92) Signed-off-by: Khalid Elmously --- drivers/net/virtio_net.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 8735dbca54b5..9b251015e170 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1942,6 +1942,53 @@ static int virtnet_get_link_ksettings(struct net_device *dev, return 0; } +static int virtnet_set_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec) +{ + struct ethtool_coalesce ec_default = { + .cmd = ETHTOOL_SCOALESCE, + .rx_max_coalesced_frames = 1, + }; + struct virtnet_info *vi = netdev_priv(dev); + int i, napi_weight; + + if (ec->tx_max_coalesced_frames > 1) + return -EINVAL; + + ec_default.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; + napi_weight = ec->tx_max_coalesced_frames ? NAPI_POLL_WEIGHT : 0; + + /* disallow changes to fields not explicitly tested above */ + if (memcmp(ec, &ec_default, sizeof(ec_default))) + return -EINVAL; + + if (napi_weight ^ vi->sq[0].napi.weight) { + if (dev->flags & IFF_UP) + return -EBUSY; + for (i = 0; i < vi->max_queue_pairs; i++) + vi->sq[i].napi.weight = napi_weight; + } + + return 0; +} + +static int virtnet_get_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec) +{ + struct ethtool_coalesce ec_default = { + .cmd = ETHTOOL_GCOALESCE, + .rx_max_coalesced_frames = 1, + }; + struct virtnet_info *vi = netdev_priv(dev); + + memcpy(ec, &ec_default, sizeof(ec_default)); + + if (vi->sq[0].napi.weight) + ec->tx_max_coalesced_frames = 1; + + return 0; +} + static void virtnet_init_settings(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); @@ -1959,6 +2006,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ts_info = ethtool_op_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, + .set_coalesce = virtnet_set_coalesce, + .get_coalesce = virtnet_get_coalesce, }; static void virtnet_freeze_down(struct virtio_device *vdev)