[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e7edc87b-3c1b-1b10-9c4f-0a7b114dd2fe@intel.com>
Date: Wed, 12 Apr 2023 14:16:19 -0700
From: Jacob Keller <jacob.e.keller@...el.com>
To: Vladimir Oltean <vladimir.oltean@....com>, <netdev@...r.kernel.org>
CC: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
"Claudiu Manoil" <claudiu.manoil@....com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
<UNGLinuxDriver@...rochip.com>,
Colin Foster <colin.foster@...advantage.com>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next 2/8] net: mscc: ocelot: refactor enum ocelot_reg
decoding to helper
On 4/12/2023 5:47 AM, Vladimir Oltean wrote:
> ocelot_io.c duplicates the decoding of an enum ocelot_reg (which holds
> an enum ocelot_target in the upper bits and an index into a regmap array
> in the lower bits) 4 times.
>
> We'd like to reuse that logic once more, from ocelot.c. In order to do
> that, let's consolidate the existing 4 instances into a header
> accessible both by ocelot.c as well as by ocelot_io.c.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
> ---
> drivers/net/ethernet/mscc/ocelot.h | 9 ++++++++
> drivers/net/ethernet/mscc/ocelot_io.c | 30 ++++++++++++++-------------
> 2 files changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h
> index 9e0f2e4ed556..14440a3b04c3 100644
> --- a/drivers/net/ethernet/mscc/ocelot.h
> +++ b/drivers/net/ethernet/mscc/ocelot.h
> @@ -74,6 +74,15 @@ struct ocelot_multicast {
> struct ocelot_pgid *pgid;
> };
>
> +static inline void ocelot_reg_to_target_addr(struct ocelot *ocelot,
> + enum ocelot_reg reg,
> + enum ocelot_target *target,
> + u32 *addr)
> +{
> + *target = reg >> TARGET_OFFSET;
> + *addr = ocelot->map[*target][reg & REG_MASK];
> +}
> +
Ok this takes a reg and returns it split into target and address, so you
can't just directly return the value.
You could do this with two separate functions, but thats not really any
better. I do wish it was easier to return tuples from a C function, but
alas...
Reviewed-by: Jacob Keller <jacob.e.keller@...el.com>
Powered by blists - more mailing lists