]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: bcmgenet: bcmgenet_hw_params clean up
authorDoug Berger <opendmb@gmail.com>
Thu, 6 Mar 2025 19:26:29 +0000 (11:26 -0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 8 Mar 2025 03:33:46 +0000 (19:33 -0800)
The entries of the bcmgenet_hw_params array are broken out to
remove unused and duplicate entries and are made read only since
they should not change for a specific version of the GENET
hardware.

Signed-off-by: Doug Berger <opendmb@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://patch.msgid.link/20250306192643.2383632-2-opendmb@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/genet/bcmgenet.c
drivers/net/ethernet/broadcom/genet/bcmgenet.h

index 3e93f957430b2d6cbe5c4648b845f565b5b02d41..0c717a724c4e14ce57c1fa261bf3182280c0d20d 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * Broadcom GENET (Gigabit Ethernet) controller driver
  *
- * Copyright (c) 2014-2024 Broadcom
+ * Copyright (c) 2014-2025 Broadcom
  */
 
 #define pr_fmt(fmt)                            "bcmgenet: " fmt
@@ -3726,123 +3726,106 @@ static const struct net_device_ops bcmgenet_netdev_ops = {
        .ndo_change_carrier     = bcmgenet_change_carrier,
 };
 
-/* Array of GENET hardware parameters/characteristics */
-static struct bcmgenet_hw_params bcmgenet_hw_params[] = {
-       [GENET_V1] = {
-               .tx_queues = 0,
-               .tx_bds_per_q = 0,
-               .rx_queues = 0,
-               .rx_bds_per_q = 0,
-               .bp_in_en_shift = 16,
-               .bp_in_mask = 0xffff,
-               .hfb_filter_cnt = 16,
-               .qtag_mask = 0x1F,
-               .hfb_offset = 0x1000,
-               .rdma_offset = 0x2000,
-               .tdma_offset = 0x3000,
-               .words_per_bd = 2,
-       },
-       [GENET_V2] = {
-               .tx_queues = 4,
-               .tx_bds_per_q = 32,
-               .rx_queues = 0,
-               .rx_bds_per_q = 0,
-               .bp_in_en_shift = 16,
-               .bp_in_mask = 0xffff,
-               .hfb_filter_cnt = 16,
-               .qtag_mask = 0x1F,
-               .tbuf_offset = 0x0600,
-               .hfb_offset = 0x1000,
-               .hfb_reg_offset = 0x2000,
-               .rdma_offset = 0x3000,
-               .tdma_offset = 0x4000,
-               .words_per_bd = 2,
-               .flags = GENET_HAS_EXT,
-       },
-       [GENET_V3] = {
-               .tx_queues = 4,
-               .tx_bds_per_q = 32,
-               .rx_queues = 0,
-               .rx_bds_per_q = 0,
-               .bp_in_en_shift = 17,
-               .bp_in_mask = 0x1ffff,
-               .hfb_filter_cnt = 48,
-               .hfb_filter_size = 128,
-               .qtag_mask = 0x3F,
-               .tbuf_offset = 0x0600,
-               .hfb_offset = 0x8000,
-               .hfb_reg_offset = 0xfc00,
-               .rdma_offset = 0x10000,
-               .tdma_offset = 0x11000,
-               .words_per_bd = 2,
-               .flags = GENET_HAS_EXT | GENET_HAS_MDIO_INTR |
-                        GENET_HAS_MOCA_LINK_DET,
-       },
-       [GENET_V4] = {
-               .tx_queues = 4,
-               .tx_bds_per_q = 32,
-               .rx_queues = 0,
-               .rx_bds_per_q = 0,
-               .bp_in_en_shift = 17,
-               .bp_in_mask = 0x1ffff,
-               .hfb_filter_cnt = 48,
-               .hfb_filter_size = 128,
-               .qtag_mask = 0x3F,
-               .tbuf_offset = 0x0600,
-               .hfb_offset = 0x8000,
-               .hfb_reg_offset = 0xfc00,
-               .rdma_offset = 0x2000,
-               .tdma_offset = 0x4000,
-               .words_per_bd = 3,
-               .flags = GENET_HAS_40BITS | GENET_HAS_EXT |
-                        GENET_HAS_MDIO_INTR | GENET_HAS_MOCA_LINK_DET,
-       },
-       [GENET_V5] = {
-               .tx_queues = 4,
-               .tx_bds_per_q = 32,
-               .rx_queues = 0,
-               .rx_bds_per_q = 0,
-               .bp_in_en_shift = 17,
-               .bp_in_mask = 0x1ffff,
-               .hfb_filter_cnt = 48,
-               .hfb_filter_size = 128,
-               .qtag_mask = 0x3F,
-               .tbuf_offset = 0x0600,
-               .hfb_offset = 0x8000,
-               .hfb_reg_offset = 0xfc00,
-               .rdma_offset = 0x2000,
-               .tdma_offset = 0x4000,
-               .words_per_bd = 3,
-               .flags = GENET_HAS_40BITS | GENET_HAS_EXT |
-                        GENET_HAS_MDIO_INTR | GENET_HAS_MOCA_LINK_DET,
-       },
+/* GENET hardware parameters/characteristics */
+static const struct bcmgenet_hw_params bcmgenet_hw_params_v1 = {
+       .tx_queues = 0,
+       .tx_bds_per_q = 0,
+       .rx_queues = 0,
+       .rx_bds_per_q = 0,
+       .bp_in_en_shift = 16,
+       .bp_in_mask = 0xffff,
+       .hfb_filter_cnt = 16,
+       .qtag_mask = 0x1F,
+       .hfb_offset = 0x1000,
+       .rdma_offset = 0x2000,
+       .tdma_offset = 0x3000,
+       .words_per_bd = 2,
+};
+
+static const struct bcmgenet_hw_params bcmgenet_hw_params_v2 = {
+       .tx_queues = 4,
+       .tx_bds_per_q = 32,
+       .rx_queues = 0,
+       .rx_bds_per_q = 0,
+       .bp_in_en_shift = 16,
+       .bp_in_mask = 0xffff,
+       .hfb_filter_cnt = 16,
+       .qtag_mask = 0x1F,
+       .tbuf_offset = 0x0600,
+       .hfb_offset = 0x1000,
+       .hfb_reg_offset = 0x2000,
+       .rdma_offset = 0x3000,
+       .tdma_offset = 0x4000,
+       .words_per_bd = 2,
+       .flags = GENET_HAS_EXT,
+};
+
+static const struct bcmgenet_hw_params bcmgenet_hw_params_v3 = {
+       .tx_queues = 4,
+       .tx_bds_per_q = 32,
+       .rx_queues = 0,
+       .rx_bds_per_q = 0,
+       .bp_in_en_shift = 17,
+       .bp_in_mask = 0x1ffff,
+       .hfb_filter_cnt = 48,
+       .hfb_filter_size = 128,
+       .qtag_mask = 0x3F,
+       .tbuf_offset = 0x0600,
+       .hfb_offset = 0x8000,
+       .hfb_reg_offset = 0xfc00,
+       .rdma_offset = 0x10000,
+       .tdma_offset = 0x11000,
+       .words_per_bd = 2,
+       .flags = GENET_HAS_EXT | GENET_HAS_MDIO_INTR |
+                GENET_HAS_MOCA_LINK_DET,
+};
+
+static const struct bcmgenet_hw_params bcmgenet_hw_params_v4 = {
+       .tx_queues = 4,
+       .tx_bds_per_q = 32,
+       .rx_queues = 0,
+       .rx_bds_per_q = 0,
+       .bp_in_en_shift = 17,
+       .bp_in_mask = 0x1ffff,
+       .hfb_filter_cnt = 48,
+       .hfb_filter_size = 128,
+       .qtag_mask = 0x3F,
+       .tbuf_offset = 0x0600,
+       .hfb_offset = 0x8000,
+       .hfb_reg_offset = 0xfc00,
+       .rdma_offset = 0x2000,
+       .tdma_offset = 0x4000,
+       .words_per_bd = 3,
+       .flags = GENET_HAS_40BITS | GENET_HAS_EXT |
+                GENET_HAS_MDIO_INTR | GENET_HAS_MOCA_LINK_DET,
 };
 
 /* Infer hardware parameters from the detected GENET version */
 static void bcmgenet_set_hw_params(struct bcmgenet_priv *priv)
 {
-       struct bcmgenet_hw_params *params;
+       const struct bcmgenet_hw_params *params;
        u32 reg;
        u8 major;
        u16 gphy_rev;
 
-       if (GENET_IS_V5(priv) || GENET_IS_V4(priv)) {
-               bcmgenet_dma_regs = bcmgenet_dma_regs_v3plus;
-               genet_dma_ring_regs = genet_dma_ring_regs_v4;
-       } else if (GENET_IS_V3(priv)) {
+       /* default to latest values */
+       params = &bcmgenet_hw_params_v4;
+       bcmgenet_dma_regs = bcmgenet_dma_regs_v3plus;
+       genet_dma_ring_regs = genet_dma_ring_regs_v4;
+       if (GENET_IS_V3(priv)) {
+               params = &bcmgenet_hw_params_v3;
                bcmgenet_dma_regs = bcmgenet_dma_regs_v3plus;
                genet_dma_ring_regs = genet_dma_ring_regs_v123;
        } else if (GENET_IS_V2(priv)) {
+               params = &bcmgenet_hw_params_v2;
                bcmgenet_dma_regs = bcmgenet_dma_regs_v2;
                genet_dma_ring_regs = genet_dma_ring_regs_v123;
        } else if (GENET_IS_V1(priv)) {
+               params = &bcmgenet_hw_params_v1;
                bcmgenet_dma_regs = bcmgenet_dma_regs_v1;
                genet_dma_ring_regs = genet_dma_ring_regs_v123;
        }
-
-       /* enum genet_version starts at 1 */
-       priv->hw_params = &bcmgenet_hw_params[priv->version];
-       params = priv->hw_params;
+       priv->hw_params = params;
 
        /* Read GENET HW version */
        reg = bcmgenet_sys_readl(priv, SYS_REV_CTRL);
index 43b923c48b14f40e0cf9cdd6b6f3ac16c301ef97..1078a31ac794fe4b8355a79e93905cbf5c04ae4e 100644 (file)
@@ -596,7 +596,7 @@ struct bcmgenet_priv {
        struct bcmgenet_rx_ring rx_rings[DESC_INDEX + 1];
 
        /* other misc variables */
-       struct bcmgenet_hw_params *hw_params;
+       const struct bcmgenet_hw_params *hw_params;
        unsigned autoneg_pause:1;
        unsigned tx_pause:1;
        unsigned rx_pause:1;