1 From 9fc469b2943d9b1ff2a7800f823e7cd7a5cac0ca Mon Sep 17 00:00:00 2001
2 From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
3 Date: Fri, 9 Feb 2024 02:03:47 -0300
4 Subject: net: dsa: realtek: embed dsa_switch into realtek_priv
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Embed dsa_switch within realtek_priv to eliminate the need for a second
12 Suggested-by: Alvin Šipraga <alsi@bang-olufsen.dk>
13 Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
14 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
15 Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
18 drivers/net/dsa/realtek/realtek.h | 2 +-
19 drivers/net/dsa/realtek/rtl8365mb.c | 15 +++++++++------
20 drivers/net/dsa/realtek/rtl8366rb.c | 3 ++-
21 drivers/net/dsa/realtek/rtl83xx.c | 15 +++++++--------
22 4 files changed, 19 insertions(+), 16 deletions(-)
24 --- a/drivers/net/dsa/realtek/realtek.h
25 +++ b/drivers/net/dsa/realtek/realtek.h
26 @@ -61,7 +61,7 @@ struct realtek_priv {
27 const struct realtek_variant *variant;
29 spinlock_t lock; /* Locks around command writes */
30 - struct dsa_switch *ds;
31 + struct dsa_switch ds;
32 struct irq_domain *irqdomain;
35 --- a/drivers/net/dsa/realtek/rtl8365mb.c
36 +++ b/drivers/net/dsa/realtek/rtl8365mb.c
37 @@ -870,6 +870,7 @@ static int rtl8365mb_ext_config_rgmii(st
39 const struct rtl8365mb_extint *extint =
40 rtl8365mb_get_port_extint(priv, port);
41 + struct dsa_switch *ds = &priv->ds;
42 struct device_node *dn;
45 @@ -880,7 +881,7 @@ static int rtl8365mb_ext_config_rgmii(st
49 - dp = dsa_to_port(priv->ds, port);
50 + dp = dsa_to_port(ds, port);
53 /* Set the RGMII TX/RX delay
54 @@ -1534,6 +1535,7 @@ static void rtl8365mb_get_stats64(struct
55 static void rtl8365mb_stats_setup(struct realtek_priv *priv)
57 struct rtl8365mb *mb = priv->chip_data;
58 + struct dsa_switch *ds = &priv->ds;
61 /* Per-chip global mutex to protect MIB counter access, since doing
62 @@ -1544,7 +1546,7 @@ static void rtl8365mb_stats_setup(struct
63 for (i = 0; i < priv->num_ports; i++) {
64 struct rtl8365mb_port *p = &mb->ports[i];
66 - if (dsa_is_unused_port(priv->ds, i))
67 + if (dsa_is_unused_port(ds, i))
70 /* Per-port spinlock to protect the stats64 data */
71 @@ -1560,12 +1562,13 @@ static void rtl8365mb_stats_setup(struct
72 static void rtl8365mb_stats_teardown(struct realtek_priv *priv)
74 struct rtl8365mb *mb = priv->chip_data;
75 + struct dsa_switch *ds = &priv->ds;
78 for (i = 0; i < priv->num_ports; i++) {
79 struct rtl8365mb_port *p = &mb->ports[i];
81 - if (dsa_is_unused_port(priv->ds, i))
82 + if (dsa_is_unused_port(ds, i))
85 cancel_delayed_work_sync(&p->mib_work);
86 @@ -1964,7 +1967,7 @@ static int rtl8365mb_setup(struct dsa_sw
87 dev_info(priv->dev, "no interrupt support\n");
89 /* Configure CPU tagging */
90 - dsa_switch_for_each_cpu_port(cpu_dp, priv->ds) {
91 + dsa_switch_for_each_cpu_port(cpu_dp, ds) {
92 cpu->mask |= BIT(cpu_dp->index);
94 if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS)
95 @@ -1979,7 +1982,7 @@ static int rtl8365mb_setup(struct dsa_sw
96 for (i = 0; i < priv->num_ports; i++) {
97 struct rtl8365mb_port *p = &mb->ports[i];
99 - if (dsa_is_unused_port(priv->ds, i))
100 + if (dsa_is_unused_port(ds, i))
103 /* Forward only to the CPU */
104 @@ -1996,7 +1999,7 @@ static int rtl8365mb_setup(struct dsa_sw
105 * ports will still forward frames to the CPU despite being
106 * administratively down by default.
108 - rtl8365mb_port_stp_state_set(priv->ds, i, BR_STATE_DISABLED);
109 + rtl8365mb_port_stp_state_set(ds, i, BR_STATE_DISABLED);
111 /* Set up per-port private data */
113 --- a/drivers/net/dsa/realtek/rtl8366rb.c
114 +++ b/drivers/net/dsa/realtek/rtl8366rb.c
115 @@ -1565,6 +1565,7 @@ static int rtl8366rb_get_mc_index(struct
117 static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index)
119 + struct dsa_switch *ds = &priv->ds;
120 struct rtl8366rb *rb;
123 @@ -1589,7 +1590,7 @@ static int rtl8366rb_set_mc_index(struct
124 * not drop any untagged or C-tagged frames. Make sure to update the
127 - if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)))
128 + if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
129 ret = rtl8366rb_drop_untagged(priv, port, !pvid_enabled);
132 --- a/drivers/net/dsa/realtek/rtl83xx.c
133 +++ b/drivers/net/dsa/realtek/rtl83xx.c
134 @@ -218,7 +218,7 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_probe, REAL
136 int rtl83xx_register_switch(struct realtek_priv *priv)
138 - struct dsa_switch *ds;
139 + struct dsa_switch *ds = &priv->ds;
142 ret = priv->ops->detect(priv);
143 @@ -227,15 +227,10 @@ int rtl83xx_register_switch(struct realt
147 - ds = devm_kzalloc(priv->dev, sizeof(*ds), GFP_KERNEL);
153 ds->ops = priv->variant->ds_ops;
154 ds->num_ports = priv->num_ports;
157 ret = dsa_register_switch(ds);
159 @@ -258,7 +253,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_register_sw
161 void rtl83xx_unregister_switch(struct realtek_priv *priv)
163 - dsa_unregister_switch(priv->ds);
164 + struct dsa_switch *ds = &priv->ds;
166 + dsa_unregister_switch(ds);
168 EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA);
170 @@ -275,7 +272,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_
172 void rtl83xx_shutdown(struct realtek_priv *priv)
174 - dsa_switch_shutdown(priv->ds);
175 + struct dsa_switch *ds = &priv->ds;
177 + dsa_switch_shutdown(ds);
179 dev_set_drvdata(priv->dev, NULL);