From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Doug Berger <opendmb@gmail.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Tariq Toukan <tariqt@nvidia.com>, Gal Pressman <gal@nvidia.com>,
Willem de Bruijn <willemb@google.com>,
Daniil Tatianin <d-tatianin@yandex-team.ru>,
Simon Horman <horms@kernel.org>,
Justin Chen <justin.chen@broadcom.com>,
Ratheesh Kannoth <rkannoth@marvell.com>,
Joe Damato <jdamato@fastly.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
Jiri Pirko <jiri@resnulli.us>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next v2 1/5] net: ethtool: Make RXNFC walking code accept a callback
Date: Thu, 26 Oct 2023 15:45:05 -0700 [thread overview]
Message-ID: <20231026224509.112353-2-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20231026224509.112353-1-florian.fainelli@broadcom.com>
[-- Attachment #1: Type: text/plain, Size: 2940 bytes --]
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 <florian.fainelli@broadcom.com>
---
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;
--
2.34.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
next prev parent reply other threads:[~2023-10-26 22:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-26 22:45 [PATCH net-next v2 0/5] WAKE_FILTER for Broadcom PHY (v2) Florian Fainelli
2023-10-26 22:45 ` Florian Fainelli [this message]
2023-10-26 23:18 ` [PATCH net-next v2 1/5] net: ethtool: Make RXNFC walking code accept a callback Jacob Keller
2023-10-26 22:45 ` [PATCH net-next v2 2/5] net: ethtool: Add validation for WAKE_FILTER Florian Fainelli
2023-10-26 23:19 ` Jacob Keller
2023-10-26 22:45 ` [PATCH net-next v2 3/5] net: phy: Add pluming for ethtool_{get,set}_rxnfc Florian Fainelli
2023-10-26 23:20 ` Jacob Keller
2023-10-26 23:32 ` Florian Fainelli
2023-10-27 2:53 ` Jakub Kicinski
2023-10-26 22:45 ` [PATCH net-next v2 4/5] net: phy: broadcom: Add support for WAKE_FILTER Florian Fainelli
2023-10-26 23:22 ` Jacob Keller
2023-10-26 22:45 ` [PATCH net-next v2 5/5] net: bcmgenet: Interrogate PHY for WAKE_FILTER programming Florian Fainelli
2023-10-26 23:23 ` Jacob Keller
2023-10-26 23:52 ` Florian Fainelli
[not found] ` <6456509b-9df7-47e3-b941-c307594a80d2@intel.com>
2023-10-27 17:15 ` Florian Fainelli
2023-10-27 17:36 ` Jacob Keller
2023-10-27 18:31 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231026224509.112353-2-florian.fainelli@broadcom.com \
--to=florian.fainelli@broadcom.com \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=d-tatianin@yandex-team.ru \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=jiri@resnulli.us \
--cc=justin.chen@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mailhol.vincent@wanadoo.fr \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=pabeni@redhat.com \
--cc=rkannoth@marvell.com \
--cc=tariqt@nvidia.com \
--cc=vladimir.oltean@nxp.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®