Skip to content

Commit 994d2cb

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: tag_sja1105: be dsa_loop-safe
Add support for tag_sja1105 running on non-sja1105 DSA ports, by making sure that every time we dereference dp->priv, we check the switch's dsa_switch_ops (otherwise we access a struct sja1105_port structure that is in fact something else). This adds an unconditional build-time dependency between sja1105 being built as module => tag_sja1105 must also be built as module. This was there only for PTP before. Some sane defaults must also take place when not running on sja1105 hardware. These are: - sja1105_xmit_tpid: the sja1105 driver uses different VLAN protocols depending on VLAN awareness and switch revision (when an encapsulated VLAN must be sent). Default to 0x8100. - sja1105_rcv_meta_state_machine: this aggregates PTP frames with their metadata timestamp frames. When running on non-sja1105 hardware, don't do that and accept all frames unmodified. - sja1105_defer_xmit: calls sja1105_port_deferred_xmit in sja1105_main.c which writes a management route over SPI. When not running on sja1105 hardware, bypass the SPI write and send the frame as-is. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 93e2716 commit 994d2cb

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull
2929
#define SJA1105_DEFAULT_VLAN (VLAN_N_VID - 1)
3030

31-
static const struct dsa_switch_ops sja1105_switch_ops;
32-
3331
static void sja1105_hw_reset(struct gpio_desc *gpio, unsigned int pulse_len,
3432
unsigned int startup_delay)
3533
{
@@ -3100,7 +3098,7 @@ static void sja1105_teardown(struct dsa_switch *ds)
31003098
sja1105_static_config_free(&priv->static_config);
31013099
}
31023100

3103-
static const struct dsa_switch_ops sja1105_switch_ops = {
3101+
const struct dsa_switch_ops sja1105_switch_ops = {
31043102
.get_tag_protocol = sja1105_get_tag_protocol,
31053103
.setup = sja1105_setup,
31063104
.teardown = sja1105_teardown,
@@ -3149,6 +3147,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
31493147
.port_bridge_tx_fwd_offload = dsa_tag_8021q_bridge_tx_fwd_offload,
31503148
.port_bridge_tx_fwd_unoffload = dsa_tag_8021q_bridge_tx_fwd_unoffload,
31513149
};
3150+
EXPORT_SYMBOL_GPL(sja1105_switch_ops);
31523151

31533152
static const struct of_device_id sja1105_dt_ids[];
31543153

include/linux/dsa/sja1105.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@ static inline void sja1110_process_meta_tstamp(struct dsa_switch *ds, int port,
8888

8989
#endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP) */
9090

91+
#if IS_ENABLED(CONFIG_NET_DSA_SJA1105)
92+
93+
extern const struct dsa_switch_ops sja1105_switch_ops;
94+
95+
static inline bool dsa_port_is_sja1105(struct dsa_port *dp)
96+
{
97+
return dp->ds->ops == &sja1105_switch_ops;
98+
}
99+
100+
#else
101+
102+
static inline bool dsa_port_is_sja1105(struct dsa_port *dp)
103+
{
104+
return false;
105+
}
106+
107+
#endif
108+
91109
#endif /* _NET_DSA_SJA1105_H */

net/dsa/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ config NET_DSA_TAG_LAN9303
138138

139139
config NET_DSA_TAG_SJA1105
140140
tristate "Tag driver for NXP SJA1105 switches"
141-
depends on (NET_DSA_SJA1105 && NET_DSA_SJA1105_PTP) || !NET_DSA_SJA1105 || !NET_DSA_SJA1105_PTP
141+
depends on NET_DSA_SJA1105 || !NET_DSA_SJA1105
142142
select PACKING
143143
help
144144
Say Y or M if you want to enable support for tagging frames with the

net/dsa/tag_sja1105.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,14 @@ static inline bool sja1105_is_meta_frame(const struct sk_buff *skb)
116116
}
117117

118118
/* Calls sja1105_port_deferred_xmit in sja1105_main.c */
119-
static struct sk_buff *sja1105_defer_xmit(struct sja1105_port *sp,
119+
static struct sk_buff *sja1105_defer_xmit(struct dsa_port *dp,
120120
struct sk_buff *skb)
121121
{
122+
struct sja1105_port *sp = dp->priv;
123+
124+
if (!dsa_port_is_sja1105(dp))
125+
return skb;
126+
122127
/* Increase refcount so the kfree_skb in dsa_slave_xmit
123128
* won't really free the packet.
124129
*/
@@ -128,8 +133,13 @@ static struct sk_buff *sja1105_defer_xmit(struct sja1105_port *sp,
128133
return NULL;
129134
}
130135

131-
static u16 sja1105_xmit_tpid(struct sja1105_port *sp)
136+
static u16 sja1105_xmit_tpid(struct dsa_port *dp)
132137
{
138+
struct sja1105_port *sp = dp->priv;
139+
140+
if (unlikely(!dsa_port_is_sja1105(dp)))
141+
return ETH_P_8021Q;
142+
133143
return sp->xmit_tpid;
134144
}
135145

@@ -155,7 +165,7 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
155165
*/
156166
tx_vid = dsa_8021q_bridge_tx_fwd_offload_vid(dp->bridge_num);
157167

158-
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp->priv), tx_vid);
168+
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp), tx_vid);
159169
}
160170

161171
static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
@@ -174,9 +184,9 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
174184
* is the .port_deferred_xmit driver callback.
175185
*/
176186
if (unlikely(sja1105_is_link_local(skb)))
177-
return sja1105_defer_xmit(dp->priv, skb);
187+
return sja1105_defer_xmit(dp, skb);
178188

179-
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp->priv),
189+
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp),
180190
((pcp << VLAN_PRIO_SHIFT) | tx_vid));
181191
}
182192

@@ -200,7 +210,7 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
200210
* tag_8021q TX VLANs.
201211
*/
202212
if (likely(!sja1105_is_link_local(skb)))
203-
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp->priv),
213+
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp),
204214
((pcp << VLAN_PRIO_SHIFT) | tx_vid));
205215

206216
skb_push(skb, SJA1110_HEADER_LEN);
@@ -265,16 +275,16 @@ static struct sk_buff
265275
bool is_link_local,
266276
bool is_meta)
267277
{
268-
struct sja1105_port *sp;
269-
struct dsa_port *dp;
270-
271-
dp = dsa_slave_to_port(skb->dev);
272-
sp = dp->priv;
273-
274278
/* Step 1: A timestampable frame was received.
275279
* Buffer it until we get its meta frame.
276280
*/
277281
if (is_link_local) {
282+
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
283+
struct sja1105_port *sp = dp->priv;
284+
285+
if (unlikely(!dsa_port_is_sja1105(dp)))
286+
return skb;
287+
278288
if (!test_bit(SJA1105_HWTS_RX_EN, &sp->data->state))
279289
/* Do normal processing. */
280290
return skb;
@@ -307,8 +317,13 @@ static struct sk_buff
307317
* frame, which serves no further purpose).
308318
*/
309319
} else if (is_meta) {
320+
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
321+
struct sja1105_port *sp = dp->priv;
310322
struct sk_buff *stampable_skb;
311323

324+
if (unlikely(!dsa_port_is_sja1105(dp)))
325+
return skb;
326+
312327
/* Drop the meta frame if we're not in the right state
313328
* to process it.
314329
*/

0 commit comments

Comments
 (0)