]> git.ipfire.org Git - thirdparty/openwrt.git/blob
4cb55f2da9f876af55376d8a94005e6dfa73a368
[thirdparty/openwrt.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Embed dsa_switch within realtek_priv to eliminate the need for a second
10 memory allocation.
11
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>
17 ---
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(-)
23
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;
28
29 spinlock_t lock; /* Locks around command writes */
30 - struct dsa_switch *ds;
31 + struct dsa_switch ds;
32 struct irq_domain *irqdomain;
33 bool leds_disabled;
34
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
38 {
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;
43 struct dsa_port *dp;
44 int tx_delay = 0;
45 @@ -880,7 +881,7 @@ static int rtl8365mb_ext_config_rgmii(st
46 if (!extint)
47 return -ENODEV;
48
49 - dp = dsa_to_port(priv->ds, port);
50 + dp = dsa_to_port(ds, port);
51 dn = dp->dn;
52
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)
56 {
57 struct rtl8365mb *mb = priv->chip_data;
58 + struct dsa_switch *ds = &priv->ds;
59 int i;
60
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];
65
66 - if (dsa_is_unused_port(priv->ds, i))
67 + if (dsa_is_unused_port(ds, i))
68 continue;
69
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)
73 {
74 struct rtl8365mb *mb = priv->chip_data;
75 + struct dsa_switch *ds = &priv->ds;
76 int i;
77
78 for (i = 0; i < priv->num_ports; i++) {
79 struct rtl8365mb_port *p = &mb->ports[i];
80
81 - if (dsa_is_unused_port(priv->ds, i))
82 + if (dsa_is_unused_port(ds, i))
83 continue;
84
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");
88
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);
93
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];
98
99 - if (dsa_is_unused_port(priv->ds, i))
100 + if (dsa_is_unused_port(ds, i))
101 continue;
102
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.
107 */
108 - rtl8365mb_port_stp_state_set(priv->ds, i, BR_STATE_DISABLED);
109 + rtl8365mb_port_stp_state_set(ds, i, BR_STATE_DISABLED);
110
111 /* Set up per-port private data */
112 p->priv = priv;
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
116
117 static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index)
118 {
119 + struct dsa_switch *ds = &priv->ds;
120 struct rtl8366rb *rb;
121 bool pvid_enabled;
122 int ret;
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
125 * filtering setting.
126 */
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);
130
131 return ret;
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
135 */
136 int rtl83xx_register_switch(struct realtek_priv *priv)
137 {
138 - struct dsa_switch *ds;
139 + struct dsa_switch *ds = &priv->ds;
140 int ret;
141
142 ret = priv->ops->detect(priv);
143 @@ -227,15 +227,10 @@ int rtl83xx_register_switch(struct realt
144 return ret;
145 }
146
147 - ds = devm_kzalloc(priv->dev, sizeof(*ds), GFP_KERNEL);
148 - if (!ds)
149 - return -ENOMEM;
150 -
151 ds->priv = priv;
152 ds->dev = priv->dev;
153 ds->ops = priv->variant->ds_ops;
154 ds->num_ports = priv->num_ports;
155 - priv->ds = ds;
156
157 ret = dsa_register_switch(ds);
158 if (ret) {
159 @@ -258,7 +253,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_register_sw
160 */
161 void rtl83xx_unregister_switch(struct realtek_priv *priv)
162 {
163 - dsa_unregister_switch(priv->ds);
164 + struct dsa_switch *ds = &priv->ds;
165 +
166 + dsa_unregister_switch(ds);
167 }
168 EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA);
169
170 @@ -275,7 +272,9 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_
171 */
172 void rtl83xx_shutdown(struct realtek_priv *priv)
173 {
174 - dsa_switch_shutdown(priv->ds);
175 + struct dsa_switch *ds = &priv->ds;
176 +
177 + dsa_switch_shutdown(ds);
178
179 dev_set_drvdata(priv->dev, NULL);
180 }