From patchwork Wed Nov 18 20:45:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402538 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SpSanl5o; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Cbvw90lVvz9sTc for ; Thu, 19 Nov 2020 07:45:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbgKRUpc (ORCPT ); Wed, 18 Nov 2020 15:45:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43587 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbgKRUpb (ORCPT ); Wed, 18 Nov 2020 15:45:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w/3365W+5YPdveY2z8dANCO+24TWinqEY1FQBLfd2v4=; b=SpSanl5own+FV0opchszRNesq9s2oywklf2ndknT/G0ckWgQZgRmK0lZOlPHGyBE9mveT+ 6vexamgmVEIweZpxJe2GucxVLsVKtig9lZZ2IHdD+PKOBxOs8yyh7Mi0eK9xnwNHoso5yg pPhgMDhva8ADWSb4jZLmz+rGREW5BJk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-W8kkNVb3OXWrfJcC1r4NVw-1; Wed, 18 Nov 2020 15:45:29 -0500 X-MC-Unique: W8kkNVb3OXWrfJcC1r4NVw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEC1A100960E; Wed, 18 Nov 2020 20:45:27 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF1EB19728; Wed, 18 Nov 2020 20:45:26 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 1/6] ethtool: add ETHTOOL_COALESCE_ALL_PARAMS define Date: Wed, 18 Nov 2020 21:45:17 +0100 Message-Id: <20201118204522.5660-2-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This bitmask represents all existing coalesce parameters. Signed-off-by: Antonio Cardace Reviewed-by: Michal Kubecek --- include/linux/ethtool.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 6408b446051f..e3da25b51ae4 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -215,6 +215,7 @@ bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, #define ETHTOOL_COALESCE_TX_USECS_HIGH BIT(19) #define ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH BIT(20) #define ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL BIT(21) +#define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(21, 0) #define ETHTOOL_COALESCE_USECS \ (ETHTOOL_COALESCE_RX_USECS | ETHTOOL_COALESCE_TX_USECS) From patchwork Wed Nov 18 20:45:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402539 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dPNgb7lN; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Cbvw93Yg1z9sVD for ; Thu, 19 Nov 2020 07:45:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727270AbgKRUpf (ORCPT ); Wed, 18 Nov 2020 15:45:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40224 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbgKRUpe (ORCPT ); Wed, 18 Nov 2020 15:45:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0UhY7JRNTWWwoTi7ac3CKN9eTMMoAP1D5/XRwRw6Fk=; b=dPNgb7lN4hqQvYhZmLyS0ceR5jdzZcD5fzsjxohRnOgbwbxQum+5POHZ34P1C2Dp96+MeX x80vRgem9pR+BzUiN0qNXrKf+1CH50mBnu+g8PZ+LIm/p3hS8tSRhfFXaEt5EWS0xndGnG vqAJ9y8X+F3YCRpWn2d1c8pWeitxZ4c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-7usO0bL2Mb24uykOPIJS4w-1; Wed, 18 Nov 2020 15:45:31 -0500 X-MC-Unique: 7usO0bL2Mb24uykOPIJS4w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A14B8144FA; Wed, 18 Nov 2020 20:45:30 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A69A19728; Wed, 18 Nov 2020 20:45:28 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 2/6] netdevsim: move ethtool pause params in separate struct Date: Wed, 18 Nov 2020 21:45:18 +0100 Message-Id: <20201118204522.5660-3-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This will help the refactoring in the next commit when coalesce and ring settings are added. Signed-off-by: Antonio Cardace Reviewed-by: Michal Kubecek --- drivers/net/netdevsim/ethtool.c | 16 ++++++++-------- drivers/net/netdevsim/netdevsim.h | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c index f1884d90a876..4f074bf85f5c 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -13,9 +13,9 @@ nsim_get_pause_stats(struct net_device *dev, { struct netdevsim *ns = netdev_priv(dev); - if (ns->ethtool.report_stats_rx) + if (ns->ethtool.pauseparam.report_stats_rx) pause_stats->rx_pause_frames = 1; - if (ns->ethtool.report_stats_tx) + if (ns->ethtool.pauseparam.report_stats_tx) pause_stats->tx_pause_frames = 2; } @@ -25,8 +25,8 @@ nsim_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) struct netdevsim *ns = netdev_priv(dev); pause->autoneg = 0; /* We don't support ksettings, so can't pretend */ - pause->rx_pause = ns->ethtool.rx; - pause->tx_pause = ns->ethtool.tx; + pause->rx_pause = ns->ethtool.pauseparam.rx; + pause->tx_pause = ns->ethtool.pauseparam.tx; } static int @@ -37,8 +37,8 @@ nsim_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) if (pause->autoneg) return -EINVAL; - ns->ethtool.rx = pause->rx_pause; - ns->ethtool.tx = pause->tx_pause; + ns->ethtool.pauseparam.rx = pause->rx_pause; + ns->ethtool.pauseparam.tx = pause->tx_pause; return 0; } @@ -58,7 +58,7 @@ void nsim_ethtool_init(struct netdevsim *ns) dir = debugfs_create_dir("pause", ethtool); debugfs_create_bool("report_stats_rx", 0600, dir, - &ns->ethtool.report_stats_rx); + &ns->ethtool.pauseparam.report_stats_rx); debugfs_create_bool("report_stats_tx", 0600, dir, - &ns->ethtool.report_stats_tx); + &ns->ethtool.pauseparam.report_stats_tx); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 827fc80f50a0..4b3023e49094 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -51,13 +51,17 @@ struct nsim_ipsec { u32 ok; }; -struct nsim_ethtool { +struct nsim_ethtool_pauseparam { bool rx; bool tx; bool report_stats_rx; bool report_stats_tx; }; +struct nsim_ethtool { + struct nsim_ethtool_pauseparam pauseparam; +}; + struct netdevsim { struct net_device *netdev; struct nsim_dev *nsim_dev; From patchwork Wed Nov 18 20:45:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402541 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=S0klO3Cv; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CbvwB1qNKz9sVH for ; Thu, 19 Nov 2020 07:45:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbgKRUpj (ORCPT ); Wed, 18 Nov 2020 15:45:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43518 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727204AbgKRUpj (ORCPT ); Wed, 18 Nov 2020 15:45:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZPDl3geZfPYNj4l6rGq2IBGQPhkzMj1PCW22C4x3ZA=; b=S0klO3CvQgcuaKC3do1dvNNJHamdRn53YZq4fdgsdO4vZI6bi/bQGS67V0nd2e+n7ynAWL NmsQFg+OdtHwPz61i0h7AE4oNB82J5yrWOQhWqtF5os9v/4yqjz1IbsQ06/rsh0xXQAEUb 6oXSyetJmuGBYGaVKtb09A65OPvDs1s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-HOvP90pGOya8upVN_OV65Q-1; Wed, 18 Nov 2020 15:45:33 -0500 X-MC-Unique: HOvP90pGOya8upVN_OV65Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 441FA100A613; Wed, 18 Nov 2020 20:45:32 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDFF41964E; Wed, 18 Nov 2020 20:45:30 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 3/6] netdevsim: support ethtool ring and coalesce settings Date: Wed, 18 Nov 2020 21:45:19 +0100 Message-Id: <20201118204522.5660-4-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add ethtool ring and coalesce settings support for testing. Signed-off-by: Antonio Cardace Reviewed-by: Michal Kubecek --- drivers/net/netdevsim/ethtool.c | 66 +++++++++++++++++++++++++++++-- drivers/net/netdevsim/netdevsim.h | 3 ++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c index 4f074bf85f5c..166f0d6cbcf7 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -42,18 +42,68 @@ nsim_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) return 0; } +static int nsim_get_coalesce(struct net_device *dev, + struct ethtool_coalesce *coal) +{ + struct netdevsim *ns = netdev_priv(dev); + + memcpy(coal, &ns->ethtool.coalesce, sizeof(ns->ethtool.coalesce)); + return 0; +} + +static int nsim_set_coalesce(struct net_device *dev, + struct ethtool_coalesce *coal) +{ + struct netdevsim *ns = netdev_priv(dev); + + memcpy(&ns->ethtool.coalesce, coal, sizeof(ns->ethtool.coalesce)); + return 0; +} + +static void nsim_get_ringparam(struct net_device *dev, + struct ethtool_ringparam *ring) +{ + struct netdevsim *ns = netdev_priv(dev); + + memcpy(ring, &ns->ethtool.ring, sizeof(ns->ethtool.ring)); +} + +static int nsim_set_ringparam(struct net_device *dev, + struct ethtool_ringparam *ring) +{ + struct netdevsim *ns = netdev_priv(dev); + + memcpy(&ns->ethtool.ring, ring, sizeof(ns->ethtool.ring)); + return 0; +} + static const struct ethtool_ops nsim_ethtool_ops = { - .get_pause_stats = nsim_get_pause_stats, - .get_pauseparam = nsim_get_pauseparam, - .set_pauseparam = nsim_set_pauseparam, + .supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS, + .get_pause_stats = nsim_get_pause_stats, + .get_pauseparam = nsim_get_pauseparam, + .set_pauseparam = nsim_set_pauseparam, + .set_coalesce = nsim_set_coalesce, + .get_coalesce = nsim_get_coalesce, + .get_ringparam = nsim_get_ringparam, + .set_ringparam = nsim_set_ringparam, }; +static void nsim_ethtool_ring_init(struct netdevsim *ns) +{ + ns->ethtool.ring.rx_max_pending = 4096; + ns->ethtool.ring.rx_jumbo_max_pending = 4096; + ns->ethtool.ring.rx_mini_max_pending = 4096; + ns->ethtool.ring.tx_max_pending = 4096; +} + void nsim_ethtool_init(struct netdevsim *ns) { struct dentry *ethtool, *dir; ns->netdev->ethtool_ops = &nsim_ethtool_ops; + nsim_ethtool_ring_init(ns); + ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir); dir = debugfs_create_dir("pause", ethtool); @@ -61,4 +111,14 @@ void nsim_ethtool_init(struct netdevsim *ns) &ns->ethtool.pauseparam.report_stats_rx); debugfs_create_bool("report_stats_tx", 0600, dir, &ns->ethtool.pauseparam.report_stats_tx); + + dir = debugfs_create_dir("ring", ethtool); + debugfs_create_u32("rx_max_pending", 0600, dir, + &ns->ethtool.ring.rx_max_pending); + debugfs_create_u32("rx_jumbo_max_pending", 0600, dir, + &ns->ethtool.ring.rx_jumbo_max_pending); + debugfs_create_u32("rx_mini_max_pending", 0600, dir, + &ns->ethtool.ring.rx_mini_max_pending); + debugfs_create_u32("tx_max_pending", 0600, dir, + &ns->ethtool.ring.tx_max_pending); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 4b3023e49094..b023dc0a4259 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,8 @@ struct nsim_ethtool_pauseparam { struct nsim_ethtool { struct nsim_ethtool_pauseparam pauseparam; + struct ethtool_coalesce coalesce; + struct ethtool_ringparam ring; }; struct netdevsim { From patchwork Wed Nov 18 20:45:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402542 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PlpZRALd; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CbvwB4s2Vz9sTc for ; Thu, 19 Nov 2020 07:45:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727292AbgKRUpj (ORCPT ); Wed, 18 Nov 2020 15:45:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30388 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727272AbgKRUpi (ORCPT ); Wed, 18 Nov 2020 15:45:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5nIiS4VXjK7crWMoMjKe+Kw8Quf3xc3QnFBb1artYkg=; b=PlpZRALdo8VHcOZGmCdKspF82pMiM5ALOrpxOwB6lo7vSdMqcHXBEtxbur7saeroG31HCK TTrWDB3zr+MtP2qwh9ruQi4XxlPdlyscF9so6dKHQa9v8YM2fWNvsNV/AlgHKMLHJoWOTj V2xTfuDr83xjSbTrprFYcDR+83bRMjs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-XnJ-xuRnO9SZSbKxjy1EFg-1; Wed, 18 Nov 2020 15:45:35 -0500 X-MC-Unique: XnJ-xuRnO9SZSbKxjy1EFg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 685A9100C602; Wed, 18 Nov 2020 20:45:34 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 103A719728; Wed, 18 Nov 2020 20:45:32 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 4/6] selftests: extract common functions in ethtool-common.sh Date: Wed, 18 Nov 2020 21:45:20 +0100 Message-Id: <20201118204522.5660-5-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Factor out some useful functions so that they can be reused by other ethtool-netdevsim scripts. Signed-off-by: Antonio Cardace --- .../drivers/net/netdevsim/ethtool-common.sh | 69 +++++++++++++++++++ .../drivers/net/netdevsim/ethtool-pause.sh | 63 +---------------- 2 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh new file mode 100644 index 000000000000..fa44cf6e732c --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +NSIM_ID=$((RANDOM % 1024)) +NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID +NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0 +NSIM_NETDEV= +num_passes=0 +num_errors=0 + +function cleanup_nsim { + if [ -e $NSIM_DEV_SYS ]; then + echo $NSIM_ID > /sys/bus/netdevsim/del_device + fi +} + +function cleanup { + cleanup_nsim +} + +trap cleanup EXIT + +function get_netdev_name { + local -n old=$1 + + new=$(ls /sys/class/net) + + for netdev in $new; do + for check in $old; do + [ $netdev == $check ] && break + done + + if [ $netdev != $check ]; then + echo $netdev + break + fi + done +} + +function check { + local code=$1 + local str=$2 + local exp_str=$3 + + if [ $code -ne 0 ]; then + ((num_errors++)) + return + fi + + if [ "$str" != "$exp_str" ]; then + echo -e "Expected: '$exp_str', got '$str'" + ((num_errors++)) + return + fi + + ((num_passes++)) +} + +function make_netdev { + # Make a netdevsim + old_netdevs=$(ls /sys/class/net) + + if ! $(lsmod | grep -q netdevsim); then + modprobe netdevsim + fi + + echo $NSIM_ID > /sys/bus/netdevsim/new_device + echo `get_netdev_name old_netdevs` +} diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh index 25c896b9e2eb..b4a7abfe5454 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh @@ -1,60 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0-only -NSIM_ID=$((RANDOM % 1024)) -NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID -NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0 -NSIM_NETDEV= -num_passes=0 -num_errors=0 - -function cleanup_nsim { - if [ -e $NSIM_DEV_SYS ]; then - echo $NSIM_ID > /sys/bus/netdevsim/del_device - fi -} - -function cleanup { - cleanup_nsim -} - -trap cleanup EXIT - -function get_netdev_name { - local -n old=$1 - - new=$(ls /sys/class/net) - - for netdev in $new; do - for check in $old; do - [ $netdev == $check ] && break - done - - if [ $netdev != $check ]; then - echo $netdev - break - fi - done -} - -function check { - local code=$1 - local str=$2 - local exp_str=$3 - - if [ $code -ne 0 ]; then - ((num_errors++)) - return - fi - - if [ "$str" != "$exp_str" ]; then - echo -e "Expected: '$exp_str', got '$str'" - ((num_errors++)) - return - fi - - ((num_passes++)) -} +source ethtool-common.sh # Bail if ethtool is too old if ! ethtool -h | grep include-stat 2>&1 >/dev/null; then @@ -62,13 +9,7 @@ if ! ethtool -h | grep include-stat 2>&1 >/dev/null; then exit 4 fi -# Make a netdevsim -old_netdevs=$(ls /sys/class/net) - -modprobe netdevsim -echo $NSIM_ID > /sys/bus/netdevsim/new_device - -NSIM_NETDEV=`get_netdev_name old_netdevs` +NSIM_NETDEV=$(make_netdev) set -o pipefail From patchwork Wed Nov 18 20:45:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402543 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gGoOXFxh; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CbvwC0LgYz9sTR for ; Thu, 19 Nov 2020 07:45:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727314AbgKRUpl (ORCPT ); Wed, 18 Nov 2020 15:45:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22424 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbgKRUpk (ORCPT ); Wed, 18 Nov 2020 15:45:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s1/NRA0IcfSE+sNP/YR+0YHuFh+fpJOX7TpxnHhSo2I=; b=gGoOXFxhJVDJmibl0OXjEd1znnOpm/qk0eu7+2XkGrPfrRMA2a63M8Iee74omOi1YWuCnx wWejjJY0AybKCpmiOAxirW5x6xAQjX8Zc0BNx5/31b4r/pCZyPgHXobk/EBz8/ZzFx5Ufx Fw3laewYrkWKtydFywxzki0PTyIM24E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-209-TK9s3u_iOaKzEWcUmcVU4A-1; Wed, 18 Nov 2020 15:45:37 -0500 X-MC-Unique: TK9s3u_iOaKzEWcUmcVU4A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 474371084D61; Wed, 18 Nov 2020 20:45:36 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0301719C59; Wed, 18 Nov 2020 20:45:34 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 5/6] selftests: refactor get_netdev_name function Date: Wed, 18 Nov 2020 21:45:21 +0100 Message-Id: <20201118204522.5660-6-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As pointed out by Michal Kubecek, getting the name with the previous approach was racy, it's better and easier to get the name of the device with this patch's approach. Essentialy the function doesn't need to exist anymore as it's a simple 'ls' command. Signed-off-by: Antonio Cardace --- .../drivers/net/netdevsim/ethtool-common.sh | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh index fa44cf6e732c..9f64d5c7107b 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh @@ -20,23 +20,6 @@ function cleanup { trap cleanup EXIT -function get_netdev_name { - local -n old=$1 - - new=$(ls /sys/class/net) - - for netdev in $new; do - for check in $old; do - [ $netdev == $check ] && break - done - - if [ $netdev != $check ]; then - echo $netdev - break - fi - done -} - function check { local code=$1 local str=$2 @@ -65,5 +48,6 @@ function make_netdev { fi echo $NSIM_ID > /sys/bus/netdevsim/new_device - echo `get_netdev_name old_netdevs` + # get new device name + ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/ } From patchwork Wed Nov 18 20:45:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Cardace X-Patchwork-Id: 1402544 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DBwsfnJh; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Cbvwh1dCyz9sSs for ; Thu, 19 Nov 2020 07:46:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727334AbgKRUps (ORCPT ); Wed, 18 Nov 2020 15:45:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55953 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbgKRUpq (ORCPT ); Wed, 18 Nov 2020 15:45:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605732344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rOO2G97HUrhXF6iV8OUekNvcw7/a/iFM+wMdy6+CSsY=; b=DBwsfnJhz6srskAHBQBWlYB1O6XPSOG1UCPNB8U+1ZnqUM5IyIaCVCBtcxq2mYdb9+bAl2 FzqVz2HyVc5zJeBrpZdXJutwm8ZmQ7h6qctobiVbkeUvtGb15ySTUh+DlDvCK+zEX1+hsZ prd0CSWc1ds2Tw/1uSKzTAWB5WFWXCA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-KpQurpnhPTWMN0Py9IQvHQ-1; Wed, 18 Nov 2020 15:45:40 -0500 X-MC-Unique: KpQurpnhPTWMN0Py9IQvHQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 658E36D585; Wed, 18 Nov 2020 20:45:38 +0000 (UTC) Received: from yoda.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0D1919C59; Wed, 18 Nov 2020 20:45:36 +0000 (UTC) From: Antonio Cardace To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Michal Kubecek Subject: [PATCH net-next v6 6/6] selftests: add ring and coalesce selftests Date: Wed, 18 Nov 2020 21:45:22 +0100 Message-Id: <20201118204522.5660-7-acardace@redhat.com> In-Reply-To: <20201118204522.5660-1-acardace@redhat.com> References: <20201118204522.5660-1-acardace@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add scripts to test ring and coalesce settings of netdevsim. Signed-off-by: Antonio Cardace --- .../drivers/net/netdevsim/ethtool-coalesce.sh | 132 ++++++++++++++++++ .../drivers/net/netdevsim/ethtool-ring.sh | 85 +++++++++++ 2 files changed, 217 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh new file mode 100755 index 000000000000..9adfba8f87e6 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh @@ -0,0 +1,132 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +source ethtool-common.sh + +function get_value { + local query="${SETTINGS_MAP[$1]}" + + echo $(ethtool -c $NSIM_NETDEV | \ + awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[ \t]/, "", $2); print $2}') +} + +function update_current_settings { + for key in ${!SETTINGS_MAP[@]}; do + CURRENT_SETTINGS[$key]=$(get_value $key) + done + echo ${CURRENT_SETTINGS[@]} +} + +if ! ethtool -h | grep -q coalesce; then + echo "SKIP: No --coalesce support in ethtool" + exit 4 +fi + +NSIM_NETDEV=$(make_netdev) + +set -o pipefail + +declare -A SETTINGS_MAP=( + ["rx-frames-low"]="rx-frame-low" + ["tx-frames-low"]="tx-frame-low" + ["rx-frames-high"]="rx-frame-high" + ["tx-frames-high"]="tx-frame-high" + ["rx-usecs"]="rx-usecs" + ["rx-frames"]="rx-frames" + ["rx-usecs-irq"]="rx-usecs-irq" + ["rx-frames-irq"]="rx-frames-irq" + ["tx-usecs"]="tx-usecs" + ["tx-frames"]="tx-frames" + ["tx-usecs-irq"]="tx-usecs-irq" + ["tx-frames-irq"]="tx-frames-irq" + ["stats-block-usecs"]="stats-block-usecs" + ["pkt-rate-low"]="pkt-rate-low" + ["rx-usecs-low"]="rx-usecs-low" + ["tx-usecs-low"]="tx-usecs-low" + ["pkt-rate-high"]="pkt-rate-high" + ["rx-usecs-high"]="rx-usecs-high" + ["tx-usecs-high"]="tx-usecs-high" + ["sample-interval"]="sample-interval" +) + +declare -A CURRENT_SETTINGS=( + ["rx-frames-low"]="" + ["tx-frames-low"]="" + ["rx-frames-high"]="" + ["tx-frames-high"]="" + ["rx-usecs"]="" + ["rx-frames"]="" + ["rx-usecs-irq"]="" + ["rx-frames-irq"]="" + ["tx-usecs"]="" + ["tx-frames"]="" + ["tx-usecs-irq"]="" + ["tx-frames-irq"]="" + ["stats-block-usecs"]="" + ["pkt-rate-low"]="" + ["rx-usecs-low"]="" + ["tx-usecs-low"]="" + ["pkt-rate-high"]="" + ["rx-usecs-high"]="" + ["tx-usecs-high"]="" + ["sample-interval"]="" +) + +declare -A EXPECTED_SETTINGS=( + ["rx-frames-low"]="" + ["tx-frames-low"]="" + ["rx-frames-high"]="" + ["tx-frames-high"]="" + ["rx-usecs"]="" + ["rx-frames"]="" + ["rx-usecs-irq"]="" + ["rx-frames-irq"]="" + ["tx-usecs"]="" + ["tx-frames"]="" + ["tx-usecs-irq"]="" + ["tx-frames-irq"]="" + ["stats-block-usecs"]="" + ["pkt-rate-low"]="" + ["rx-usecs-low"]="" + ["tx-usecs-low"]="" + ["pkt-rate-high"]="" + ["rx-usecs-high"]="" + ["tx-usecs-high"]="" + ["sample-interval"]="" +) + +# populate the expected settings map +for key in ${!SETTINGS_MAP[@]}; do + EXPECTED_SETTINGS[$key]=$(get_value $key) +done + +# test +for key in ${!SETTINGS_MAP[@]}; do + value=$((RANDOM % $((2**32-1)))) + + ethtool -C $NSIM_NETDEV "$key" "$value" + + EXPECTED_SETTINGS[$key]="$value" + expected=${EXPECTED_SETTINGS[@]} + current=$(update_current_settings) + + check $? "$current" "$expected" + set +x +done + +# bool settings which ethtool displays on the same line +ethtool -C $NSIM_NETDEV adaptive-rx on +s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: off") +check $? "$s" "" + +ethtool -C $NSIM_NETDEV adaptive-tx on +s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: on") +check $? "$s" "" + +if [ $num_errors -eq 0 ]; then + echo "PASSED all $((num_passes)) checks" + exit 0 +else + echo "FAILED $num_errors/$((num_errors+num_passes)) checks" + exit 1 +fi diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh new file mode 100755 index 000000000000..c969559ffa7a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +source ethtool-common.sh + +function get_value { + local query="${SETTINGS_MAP[$1]}" + + echo $(ethtool -g $NSIM_NETDEV | \ + tail -n +$CURR_SETT_LINE | \ + awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[\t ]/, "", $2); print $2}') +} + +function update_current_settings { + for key in ${!SETTINGS_MAP[@]}; do + CURRENT_SETTINGS[$key]=$(get_value $key) + done + echo ${CURRENT_SETTINGS[@]} +} + +if ! ethtool -h | grep -q set-ring >/dev/null; then + echo "SKIP: No --set-ring support in ethtool" + exit 4 +fi + +NSIM_NETDEV=$(make_netdev) + +set -o pipefail + +declare -A SETTINGS_MAP=( + ["rx"]="RX" + ["rx-mini"]="RX Mini" + ["rx-jumbo"]="RX Jumbo" + ["tx"]="TX" +) + +declare -A EXPECTED_SETTINGS=( + ["rx"]="" + ["rx-mini"]="" + ["rx-jumbo"]="" + ["tx"]="" +) + +declare -A CURRENT_SETTINGS=( + ["rx"]="" + ["rx-mini"]="" + ["rx-jumbo"]="" + ["tx"]="" +) + +MAX_VALUE=$((RANDOM % $((2**32-1)))) +RING_MAX_LIST=$(ls $NSIM_DEV_DFS/ethtool/ring/) + +for ring_max_entry in $RING_MAX_LIST; do + echo $MAX_VALUE > $NSIM_DEV_DFS/ethtool/ring/$ring_max_entry +done + +CURR_SETT_LINE=$(ethtool -g $NSIM_NETDEV | grep -i -m1 -n 'Current hardware settings' | cut -f1 -d:) + +# populate the expected settings map +for key in ${!SETTINGS_MAP[@]}; do + EXPECTED_SETTINGS[$key]=$(get_value $key) +done + +# test +for key in ${!SETTINGS_MAP[@]}; do + value=$((RANDOM % $MAX_VALUE)) + + ethtool -G $NSIM_NETDEV "$key" "$value" + + EXPECTED_SETTINGS[$key]="$value" + expected=${EXPECTED_SETTINGS[@]} + current=$(update_current_settings) + + check $? "$current" "$expected" + set +x +done + +if [ $num_errors -eq 0 ]; then + echo "PASSED all $((num_passes)) checks" + exit 0 +else + echo "FAILED $num_errors/$((num_errors+num_passes)) checks" + exit 1 +fi