diff mbox series

[net-next,v2,01/15] net: dsa: qca8k: make mib autocast feature optional

Message ID 20220719005726.8739-2-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: qca8k: code split for qca8k | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi July 19, 2022, 12:57 a.m. UTC
Some switch may not support mib autocast feature and require the legacy
way of reading the regs directly.
Make the mib autocast feature optional and permit to declare support for
it using match_data struct.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/dsa/qca/qca8k.c | 11 +++++++----
 drivers/net/dsa/qca/qca8k.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Vladimir Oltean July 19, 2022, 12:26 p.m. UTC | #1
On Tue, Jul 19, 2022 at 02:57:11AM +0200, Christian Marangi wrote:
> Some switch may not support mib autocast feature and require the legacy
> way of reading the regs directly.
> Make the mib autocast feature optional and permit to declare support for
> it using match_data struct.
> 
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
>  drivers/net/dsa/qca/qca8k.c | 11 +++++++----
>  drivers/net/dsa/qca/qca8k.h |  1 +
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/dsa/qca/qca8k.c b/drivers/net/dsa/qca/qca8k.c
> index 1cbb05b0323f..a57c53ce2f0c 100644
> --- a/drivers/net/dsa/qca/qca8k.c
> +++ b/drivers/net/dsa/qca/qca8k.c
> @@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
>  	u32 hi = 0;
>  	int ret;
>  
> -	if (priv->mgmt_master &&
> -	    qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
> -		return;
> -
>  	match_data = of_device_get_match_data(priv->dev);

I didn't notice at the time that you already call of_device_get_match_data()
at driver runtime, but please be aware that it is a relatively expensive
operation (takes raw spinlocks, iterates etc), or at least much more
expensive than it needs to be. What other drivers do is cache the result
of this function once in priv->info and just use priv->info, since it
won't change during the lifetime of the driver.

>  
> +	if (priv->mgmt_master && match_data->autocast_mib &&
> +	    match_data->autocast_mib(ds, port, data) > 0)
> +		return;
> +
>  	for (i = 0; i < match_data->mib_count; i++) {
>  		mib = &ar8327_mib[i];
>  		reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
> @@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = {
>  	.id = QCA8K_ID_QCA8327,
>  	.reduced_package = true,
>  	.mib_count = QCA8K_QCA832X_MIB_COUNT,
> +	.autocast_mib = qca8k_get_ethtool_stats_eth,

I thought you were going to create a dedicated sub-structure for
function pointers?

>  };
>  
>  static const struct qca8k_match_data qca8328 = {
>  	.id = QCA8K_ID_QCA8327,
>  	.mib_count = QCA8K_QCA832X_MIB_COUNT,
> +	.autocast_mib = qca8k_get_ethtool_stats_eth,
>  };
>  
>  static const struct qca8k_match_data qca833x = {
>  	.id = QCA8K_ID_QCA8337,
>  	.mib_count = QCA8K_QCA833X_MIB_COUNT,
> +	.autocast_mib = qca8k_get_ethtool_stats_eth,
>  };
>  
>  static const struct of_device_id qca8k_of_match[] = {
> diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
> index ec58d0e80a70..c3df0a56cda4 100644
> --- a/drivers/net/dsa/qca/qca8k.h
> +++ b/drivers/net/dsa/qca/qca8k.h
> @@ -328,6 +328,7 @@ struct qca8k_match_data {
>  	u8 id;
>  	bool reduced_package;
>  	u8 mib_count;
> +	int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data);
>  };
>  
>  enum {
> -- 
> 2.36.1
>
Christian Marangi July 19, 2022, 12:29 p.m. UTC | #2
On Tue, Jul 19, 2022 at 03:26:36PM +0300, Vladimir Oltean wrote:
> On Tue, Jul 19, 2022 at 02:57:11AM +0200, Christian Marangi wrote:
> > Some switch may not support mib autocast feature and require the legacy
> > way of reading the regs directly.
> > Make the mib autocast feature optional and permit to declare support for
> > it using match_data struct.
> > 
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/net/dsa/qca/qca8k.c | 11 +++++++----
> >  drivers/net/dsa/qca/qca8k.h |  1 +
> >  2 files changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/qca/qca8k.c b/drivers/net/dsa/qca/qca8k.c
> > index 1cbb05b0323f..a57c53ce2f0c 100644
> > --- a/drivers/net/dsa/qca/qca8k.c
> > +++ b/drivers/net/dsa/qca/qca8k.c
> > @@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
> >  	u32 hi = 0;
> >  	int ret;
> >  
> > -	if (priv->mgmt_master &&
> > -	    qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
> > -		return;
> > -
> >  	match_data = of_device_get_match_data(priv->dev);
> 
> I didn't notice at the time that you already call of_device_get_match_data()
> at driver runtime, but please be aware that it is a relatively expensive
> operation (takes raw spinlocks, iterates etc), or at least much more
> expensive than it needs to be. What other drivers do is cache the result
> of this function once in priv->info and just use priv->info, since it
> won't change during the lifetime of the driver.
>

Ok makes sense. Can I make a patch drop the use of
of_device_get_match_data and then apply this on top?

(we use of_device_get_match_data also in other functions)

> >  
> > +	if (priv->mgmt_master && match_data->autocast_mib &&
> > +	    match_data->autocast_mib(ds, port, data) > 0)
> > +		return;
> > +
> >  	for (i = 0; i < match_data->mib_count; i++) {
> >  		mib = &ar8327_mib[i];
> >  		reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
> > @@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = {
> >  	.id = QCA8K_ID_QCA8327,
> >  	.reduced_package = true,
> >  	.mib_count = QCA8K_QCA832X_MIB_COUNT,
> > +	.autocast_mib = qca8k_get_ethtool_stats_eth,
> 
> I thought you were going to create a dedicated sub-structure for
> function pointers?
> 

Sorry... totally forgot this as I was very busy with giving good series.
Will handle this in the next version.

(will be also useful later for the single dsa_switch_ops transition if
we want to put all of them there)

> >  };
> >  
> >  static const struct qca8k_match_data qca8328 = {
> >  	.id = QCA8K_ID_QCA8327,
> >  	.mib_count = QCA8K_QCA832X_MIB_COUNT,
> > +	.autocast_mib = qca8k_get_ethtool_stats_eth,
> >  };
> >  
> >  static const struct qca8k_match_data qca833x = {
> >  	.id = QCA8K_ID_QCA8337,
> >  	.mib_count = QCA8K_QCA833X_MIB_COUNT,
> > +	.autocast_mib = qca8k_get_ethtool_stats_eth,
> >  };
> >  
> >  static const struct of_device_id qca8k_of_match[] = {
> > diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
> > index ec58d0e80a70..c3df0a56cda4 100644
> > --- a/drivers/net/dsa/qca/qca8k.h
> > +++ b/drivers/net/dsa/qca/qca8k.h
> > @@ -328,6 +328,7 @@ struct qca8k_match_data {
> >  	u8 id;
> >  	bool reduced_package;
> >  	u8 mib_count;
> > +	int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data);
> >  };
> >  
> >  enum {
> > -- 
> > 2.36.1
> > 
>
Vladimir Oltean July 19, 2022, 1:36 p.m. UTC | #3
On Tue, Jul 19, 2022 at 02:29:30PM +0200, Christian Marangi wrote:
> Ok makes sense. Can I make a patch drop the use of
> of_device_get_match_data and then apply this on top?

Yes, that would be the idea, thanks.
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca/qca8k.c b/drivers/net/dsa/qca/qca8k.c
index 1cbb05b0323f..a57c53ce2f0c 100644
--- a/drivers/net/dsa/qca/qca8k.c
+++ b/drivers/net/dsa/qca/qca8k.c
@@ -2112,12 +2112,12 @@  qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
 	u32 hi = 0;
 	int ret;
 
-	if (priv->mgmt_master &&
-	    qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
-		return;
-
 	match_data = of_device_get_match_data(priv->dev);
 
+	if (priv->mgmt_master && match_data->autocast_mib &&
+	    match_data->autocast_mib(ds, port, data) > 0)
+		return;
+
 	for (i = 0; i < match_data->mib_count; i++) {
 		mib = &ar8327_mib[i];
 		reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
@@ -3260,16 +3260,19 @@  static const struct qca8k_match_data qca8327 = {
 	.id = QCA8K_ID_QCA8327,
 	.reduced_package = true,
 	.mib_count = QCA8K_QCA832X_MIB_COUNT,
+	.autocast_mib = qca8k_get_ethtool_stats_eth,
 };
 
 static const struct qca8k_match_data qca8328 = {
 	.id = QCA8K_ID_QCA8327,
 	.mib_count = QCA8K_QCA832X_MIB_COUNT,
+	.autocast_mib = qca8k_get_ethtool_stats_eth,
 };
 
 static const struct qca8k_match_data qca833x = {
 	.id = QCA8K_ID_QCA8337,
 	.mib_count = QCA8K_QCA833X_MIB_COUNT,
+	.autocast_mib = qca8k_get_ethtool_stats_eth,
 };
 
 static const struct of_device_id qca8k_of_match[] = {
diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
index ec58d0e80a70..c3df0a56cda4 100644
--- a/drivers/net/dsa/qca/qca8k.h
+++ b/drivers/net/dsa/qca/qca8k.h
@@ -328,6 +328,7 @@  struct qca8k_match_data {
 	u8 id;
 	bool reduced_package;
 	u8 mib_count;
+	int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data);
 };
 
 enum {