diff mbox series

[net-next,06/15] net: sparx5: add constants to match data

Message ID 20241001-b4-sparx5-lan969x-switch-driver-v1-6-8c6896fdce66@microchip.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: sparx5: prepare for lan969x switch driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 12 this patch: 12
netdev/checkpatch warning CHECK: Macro argument 'const' may be better as '(const)' to avoid precedence issues
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Machon Oct. 1, 2024, 1:50 p.m. UTC
Add new struct sparx5_consts, containing all the chip constants that are
known to be different for Sparx5 and lan969x. Also add a macro to access
the constants.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
---
 .../net/ethernet/microchip/sparx5/sparx5_main.c    | 21 ++++++++++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_main.h    | 23 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

Comments

Jacob Keller Oct. 1, 2024, 5:56 p.m. UTC | #1
On 10/1/2024 6:50 AM, Daniel Machon wrote:
> Add new struct sparx5_consts, containing all the chip constants that are
> known to be different for Sparx5 and lan969x. Also add a macro to access
> the constants.
> 
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
> Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
> ---
>  .../net/ethernet/microchip/sparx5/sparx5_main.c    | 21 ++++++++++++++++++++
>  .../net/ethernet/microchip/sparx5/sparx5_main.h    | 23 ++++++++++++++++++++++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> index 9a8d2e8c02a5..5f3690a59ac1 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> @@ -953,11 +953,32 @@ static const struct sparx5_regs sparx5_regs = {
>  	.fsize = sparx5_fsize,
>  };
>  
> +static const struct sparx5_consts sparx5_consts = {
> +	.n_ports             = 65,
> +	.n_ports_all         = 70,
> +	.n_hsch_l1_elems     = 64,
> +	.n_hsch_queues       = 8,
> +	.n_lb_groups         = 10,
> +	.n_pgids             = 2113, /* (2048 + n_ports) */
> +	.n_sio_clks          = 3,
> +	.n_own_upsids        = 3,
> +	.n_auto_cals         = 7,
> +	.n_filters           = 1024,
> +	.n_gates             = 1024,
> +	.n_sdlbs             = 4096,
> +	.n_dsm_cal_taxis     = 8,
> +	.buf_size            = 4194280,
> +	.qres_max_prio_idx   = 630,
> +	.qres_max_colour_idx = 638,
> +	.tod_pin             = 4,
> +};
> +
>  static const struct sparx5_match_data sparx5_desc = {
>  	.iomap = sparx5_main_iomap,
>  	.iomap_size = ARRAY_SIZE(sparx5_main_iomap),
>  	.ioranges = 3,
>  	.regs = &sparx5_regs,
> +	.consts = &sparx5_consts,
>  };
>  
>  static const struct of_device_id mchp_sparx5_match[] = {
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> index 738b86999fd8..91f5a3be829e 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
> @@ -51,6 +51,8 @@ enum sparx5_vlan_port_type {
>  	SPX5_VLAN_PORT_TYPE_S_CUSTOM /* S-port using custom type */
>  };
>  
> +#define SPX5_CONST(const) sparx5->data->consts->const
> +

I'm not a fan of implicit dependency here. Whats the reason for having
it done this way vs passing something in as a parameter here?
Jakub Kicinski Oct. 2, 2024, 12:47 p.m. UTC | #2
On Tue, 1 Oct 2024 15:50:36 +0200 Daniel Machon wrote:
> +#define SPX5_CONST(const) sparx5->data->consts->const

This is way too ugly too live.
Please type the code out, there's no prize for having low LoC count.
Daniel Machon Oct. 2, 2024, 1:31 p.m. UTC | #3
> > +#define SPX5_CONST(const) sparx5->data->consts->const
> 
> This is way too ugly too live.
> Please type the code out, there's no prize for having low LoC count.
>

Hi Jakub,

By "type the code out" - are you saying that we should not be using a macro
for accessing the const at all? and rather just:

    struct sparx5_consts *consts = sparx5->data->consts;
    consts->some_var

or pass in the sparx5 pointer to the macro too, which was the concert that
Jacob raised.

Thanks.

/Daniel
Jakub Kicinski Oct. 2, 2024, 2:33 p.m. UTC | #4
On Wed, 2 Oct 2024 13:31:32 +0000 Daniel Machon wrote:
> By "type the code out" - are you saying that we should not be using a macro
> for accessing the const at all? and rather just:
> 
>     struct sparx5_consts *consts = sparx5->data->consts;
>     consts->some_var

This.

> or pass in the sparx5 pointer to the macro too, which was the concert that
> Jacob raised.

The implicit arguments are part of the ugliness, and should also go
away. But in this case the entire macro should go.
Daniel Machon Oct. 2, 2024, 6:28 p.m. UTC | #5
> > By "type the code out" - are you saying that we should not be using a macro
> > for accessing the const at all? and rather just:
> >
> >     struct sparx5_consts *consts = sparx5->data->consts;
> >     consts->some_var
> 
> This.
> 
> > or pass in the sparx5 pointer to the macro too, which was the concert that
> > Jacob raised.
> 
> The implicit arguments are part of the ugliness, and should also go
> away. But in this case the entire macro should go.

Ack.

Will get rid of the macro in v2.

/Daniel
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index 9a8d2e8c02a5..5f3690a59ac1 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
@@ -953,11 +953,32 @@  static const struct sparx5_regs sparx5_regs = {
 	.fsize = sparx5_fsize,
 };
 
+static const struct sparx5_consts sparx5_consts = {
+	.n_ports             = 65,
+	.n_ports_all         = 70,
+	.n_hsch_l1_elems     = 64,
+	.n_hsch_queues       = 8,
+	.n_lb_groups         = 10,
+	.n_pgids             = 2113, /* (2048 + n_ports) */
+	.n_sio_clks          = 3,
+	.n_own_upsids        = 3,
+	.n_auto_cals         = 7,
+	.n_filters           = 1024,
+	.n_gates             = 1024,
+	.n_sdlbs             = 4096,
+	.n_dsm_cal_taxis     = 8,
+	.buf_size            = 4194280,
+	.qres_max_prio_idx   = 630,
+	.qres_max_colour_idx = 638,
+	.tod_pin             = 4,
+};
+
 static const struct sparx5_match_data sparx5_desc = {
 	.iomap = sparx5_main_iomap,
 	.iomap_size = ARRAY_SIZE(sparx5_main_iomap),
 	.ioranges = 3,
 	.regs = &sparx5_regs,
+	.consts = &sparx5_consts,
 };
 
 static const struct of_device_id mchp_sparx5_match[] = {
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
index 738b86999fd8..91f5a3be829e 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
@@ -51,6 +51,8 @@  enum sparx5_vlan_port_type {
 	SPX5_VLAN_PORT_TYPE_S_CUSTOM /* S-port using custom type */
 };
 
+#define SPX5_CONST(const) sparx5->data->consts->const
+
 #define SPX5_PORTS             65
 #define SPX5_PORTS_ALL         70 /* Total number of ports */
 
@@ -238,6 +240,26 @@  struct sparx5_regs {
 	const unsigned int *fsize;
 };
 
+struct sparx5_consts {
+	u32 n_ports;             /* Number of front ports */
+	u32 n_ports_all;         /* Number of front ports + internal ports */
+	u32 n_hsch_l1_elems;     /* Number of HSCH layer 1 elements */
+	u32 n_hsch_queues;       /* Number of HSCH queues */
+	u32 n_lb_groups;         /* Number of leacky bucket groupd */
+	u32 n_pgids;             /* Number of PGID's */
+	u32 n_sio_clks;          /* Number of serial IO clocks */
+	u32 n_own_upsids;        /* Number of own UPSID's */
+	u32 n_auto_cals;         /* Number of auto calendars */
+	u32 n_filters;           /* Number of PSFP filters */
+	u32 n_gates;             /* Number of PSFP gates */
+	u32 n_sdlbs;             /* Number of service dual leaky buckets */
+	u32 n_dsm_cal_taxis;     /* Number of DSM calendar taxis */
+	u32 buf_size;            /* Amount of QLIM watermark memory */
+	u32 qres_max_prio_idx;   /* Maximum QRES prio index */
+	u32 qres_max_colour_idx; /* Maximum QRES colour index */
+	u32 tod_pin;             /* PTP TOD pin */
+};
+
 struct sparx5_main_io_resource {
 	enum sparx5_target id;
 	phys_addr_t offset;
@@ -246,6 +268,7 @@  struct sparx5_main_io_resource {
 
 struct sparx5_match_data {
 	const struct sparx5_regs *regs;
+	const struct sparx5_consts *consts;
 	const struct sparx5_main_io_resource *iomap;
 	int ioranges;
 	int iomap_size;