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

Vladimir Oltean
2022-07-19T13:06:02Z

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
>