From patchwork Wed Oct 25 17:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436492 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAD01C683 for ; Wed, 25 Oct 2023 17:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="NGV53MPA" Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A353B138 for ; Wed, 25 Oct 2023 10:34:37 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7781b176131so2620485a.1 for ; Wed, 25 Oct 2023 10:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255276; x=1698860076; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=RyE3i5t9k7g5+3Y7P+D0v4H0c3MYDysKEdDAXf+58QE=; b=NGV53MPAEnGNp5d4Agl4zWVwTe1ZNPxkIG5wXIkegTzDwRKibSmCA2S3mjG2JD910f DKd7cMvBRR1p6IV81BNkYf+DZQdKee60+vTZBZ+Lnp+Vq8N2GdGHgioRj1D3vFN+w6yR uZzPnl/+X1bgZQHzYnMEC79W+eepvwMZGXmbM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255276; x=1698860076; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RyE3i5t9k7g5+3Y7P+D0v4H0c3MYDysKEdDAXf+58QE=; b=HuDRf/KgTHQCJ1OxB9FvfLu8YRBqyYGbDfLrLr8YudkZ/CkNv/3gdDczmEXopyCDW8 fW2mRRKXh2Uc608gXGkSh47X5N0rjsadAGMytuVM9riGJXNeBSBMzrC4wdT2P5RrmS4D 1lI+o8EaDUUj+97kfoEvo83mmuhmOQxKlJaYTHLJBAoa3gf4cmnfwk3w/oG9+zHzlhWq cwR/7BsAwuPbXXPurYbDihwmxQijgvzgoYPrLjRzrcYnYl51H3JjjMkwnew5XhqjAUd3 M7EjD8HlQ6hl4C538EmqJ2W9CwCwpRbMaFslhA64gMsIel10mMAhpEl15S6R5fMIto+p N63A== X-Gm-Message-State: AOJu0YyxH3VNVflYT5NaAt3AGEUn3f2VrTo3ajS7GKoCiSaCNs3+Bxxo JJc45I3bfITTW6nVo5SwiD2/7vGgwlzwLcEGgPE6IZ4A+vwcA0Vxjen5mxETNLAu50ASMdspdwh HXWCgSs2uabAC+4c5nbiYWQnxPdR6rKpFaL56pysY3UQvR4j3cmXgX/zTGIm8L/H0rBqRWwrVs7 A95DzlFgl5nXRg X-Google-Smtp-Source: AGHT+IGPGGduNorc5Zru7sVUkApuBtefzcmppO5LF+rUA+P2lmGkGG/tn6kg3TC9a+SlMaFkuAF7hg== X-Received: by 2002:a05:620a:2947:b0:76f:1318:d7d1 with SMTP id n7-20020a05620a294700b0076f1318d7d1mr17479300qkp.75.1698255275882; Wed, 25 Oct 2023 10:34:35 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:35 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 1/5] net: ethtool: Make RXNFC walking code accept a callback Date: Wed, 25 Oct 2023 10:32:56 -0700 Message-Id: <20231025173300.1776832-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org In preparation for iterating over RXNFC rules for a different purpose, factor the generic code that already does that by allowing a callback to be specified. The body of ethtool_get_max_rxnfc_channel() now accepts a callback as an argument and is renamed to __ethtool_for_each_rxnfc(). Signed-off-by: Florian Fainelli --- net/ethtool/common.c | 54 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index b4419fb6df6a..143dae872fb2 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -536,12 +536,24 @@ static int ethtool_get_rxnfc_rule_count(struct net_device *dev) return info.rule_cnt; } -int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) +/** + * __ethtool_for_each_rxnfc: Iterate over each RXNFC rule installed + * @dev: network device + * @cb: callback to analyze an %ethtool_rxnfc rule + * @priv: private pointer passed to the callback + * + * @cb is supposed to return the following: + * < 0 on error + * == 0 to continue + * > 0 to stop iterating + */ +static int __ethtool_for_each_rxnfc(struct net_device *dev, + int (*cb)(struct ethtool_rxnfc *info, + void *priv), void *priv) { const struct ethtool_ops *ops = dev->ethtool_ops; struct ethtool_rxnfc *info; int err, i, rule_cnt; - u64 max_ring = 0; if (!ops->get_rxnfc) return -EOPNOTSUPP; @@ -570,16 +582,14 @@ int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) if (err) goto err_free_info; - if (rule_info.fs.ring_cookie != RX_CLS_FLOW_DISC && - rule_info.fs.ring_cookie != RX_CLS_FLOW_WAKE && - !(rule_info.flow_type & FLOW_RSS) && - !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie)) - max_ring = - max_t(u64, max_ring, rule_info.fs.ring_cookie); + err = cb(&rule_info, priv); + if (err < 0) + goto err_free_info; + if (err > 0) + break; } kvfree(info); - *max = max_ring; return 0; err_free_info: @@ -587,6 +597,32 @@ int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) return err; } +static int __ethtool_get_max_rxnfc_channel(struct ethtool_rxnfc *rule_info, + void *priv) +{ + u64 *max_ring = priv; + + if (rule_info->fs.ring_cookie != RX_CLS_FLOW_DISC && + rule_info->fs.ring_cookie != RX_CLS_FLOW_WAKE && + !(rule_info->flow_type & FLOW_RSS) && + !ethtool_get_flow_spec_ring_vf(rule_info->fs.ring_cookie)) + *max_ring = + max_t(u64, *max_ring, rule_info->fs.ring_cookie); + + return 0; +} + +int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) +{ + u64 max_ring = 0; + int ret; + + ret = __ethtool_for_each_rxnfc(dev, __ethtool_get_max_rxnfc_channel, + &max_ring); + *max = max_ring; + return ret; +} + int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max) { u32 dev_size, current_max = 0;