From patchwork Thu Oct 26 22:45:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13437992 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 025DE3C699 for ; Thu, 26 Oct 2023 22:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="aLrpUXoK" Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7511F1BE for ; Thu, 26 Oct 2023 15:55:39 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c9de3f66e5so11383465ad.3 for ; Thu, 26 Oct 2023 15:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698360938; x=1698965738; 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=Pbc4bXkrSBEUPPj8b1MmjbwM7HeKerKO1Eee8euUgnA=; b=aLrpUXoKMY6GpbTLSSBufYh+0vbeMxPb4CTP5tgKMMuH79wVgXjcPeBlHMvzIE07M2 YANpZxT/LwLKsqVgmCmpmuaMxSnzZb46Umso+WnpaheFmC7Dyjny966nMW3dTRi+0XId e50ABSKCT7Hnojdy8AC51VMi1OmNsrRVEk5oM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698360938; x=1698965738; 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=Pbc4bXkrSBEUPPj8b1MmjbwM7HeKerKO1Eee8euUgnA=; b=pkRlSAJe4fZF8f+qWf2nARwGhQj0cCgSxfdMX5nAoq2qnPpPqAovFblYjIBOlJE3i5 ziF9AeNwe7nId38vV3IIoNqxzL98Bn5Ayur1QBFF+Ka8Ex0uhLw99i4nZtq5Vv6IxgXp 3cf/jhRbGgyBvMc0AlzmldP56GgUiPQ9qn+zuxLfoJHdZWwL4DLXrUXtJarKdgM06z9a wrzDHRTh3u1+Z9fBniL9PbSbQ+Gc9aJdhKd5D8e3ecWF61igLkZ1oEY7DcdJGpHE5QOd teIETvmFaauZetq3aoewo8i/+NG/hV5dz79+77CIuirPkKYPmtxh/8QIDqQeschM1t8p iG9A== X-Gm-Message-State: AOJu0YyO2FeezI0zhbKAE97qV2JIEQsgvM5RcN85yN3vrKwjWCU6siGS FeSfibyR4Lxf9y7kY/yX54R+4THaBQv7qCkiW67/0UsUbuV9XHtE60PZ4A3E9SZ7bm3V52g8hlC HpIwhHkJOFLuhhBRukYWjwgP7xP9iEYAV7NnkX05UORWuMhO/9mbeibxJMqrKv7wMlJEAiUcj/9 /Eo0rEMU0qioAM X-Google-Smtp-Source: AGHT+IHgz2L3+MtwaF8wXHpmQ5hhoVIfkmyxFrXbOfrSnQmXG+IahRaYVM2z350727SZpTA/AR5IKg== X-Received: by 2002:a17:902:eb52:b0:1c7:65e3:e605 with SMTP id i18-20020a170902eb5200b001c765e3e605mr937619pli.36.1698360938447; Thu, 26 Oct 2023 15:55:38 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id o1-20020a170902d4c100b001c9b5b63e36sm206295plg.32.2023.10.26.15.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 15:55:37 -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 v2 1/5] net: ethtool: Make RXNFC walking code accept a callback Date: Thu, 26 Oct 2023 15:45:05 -0700 Message-Id: <20231026224509.112353-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026224509.112353-1-florian.fainelli@broadcom.com> References: <20231026224509.112353-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 Reviewed-by: Jacob Keller --- 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;