Skip to content

Commit 5aed85c

Browse files
ffainellidavem330
authored andcommitted
net: dsa: allow switches to work without tagging
In case switch port tagging is disabled (voluntarily, or the switch just does not support it), allow us to continue using the defined set of dsa_device_ops in net/dsa/slave.c. We introduce dsa_protocol_is_tagged() to check whether we need to override skb->protocol and go through the DSA-specifif packet_type function, or if we just go on and receive the SKB through the normal path. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0d8bcdd commit 5aed85c

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎include/linux/netdevice.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,10 +1784,10 @@ void dev_net_set(struct net_device *dev, struct net *net)
17841784
static inline bool netdev_uses_dsa(struct net_device *dev)
17851785
{
17861786
#ifdef CONFIG_NET_DSA
1787-
return dev->dsa_ptr != NULL;
1788-
#else
1789-
return false;
1787+
if (dev->dsa_ptr != NULL)
1788+
return dsa_uses_tagged_protocol(dev->dsa_ptr);
17901789
#endif
1790+
return false;
17911791
}
17921792

17931793
/**

‎include/net/dsa.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,9 @@ static inline void *ds_to_priv(struct dsa_switch *ds)
198198
return (void *)(ds + 1);
199199
}
200200

201+
static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
202+
{
203+
return dst->tag_protocol != 0;
204+
}
205+
201206
#endif

‎net/dsa/slave.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
181181
return dst->ops->xmit(skb, dev);
182182
}
183183

184+
static netdev_tx_t dsa_slave_notag_xmit(struct sk_buff *skb,
185+
struct net_device *dev)
186+
{
187+
struct dsa_slave_priv *p = netdev_priv(dev);
188+
189+
skb->dev = p->parent->dst->master_netdev;
190+
dev_queue_xmit(skb);
191+
192+
return NETDEV_TX_OK;
193+
}
194+
184195

185196
/* ethtool operations *******************************************************/
186197
static int
@@ -314,6 +325,11 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
314325
.ndo_do_ioctl = dsa_slave_ioctl,
315326
};
316327

328+
static const struct dsa_device_ops notag_netdev_ops = {
329+
.xmit = dsa_slave_notag_xmit,
330+
.rcv = NULL,
331+
};
332+
317333
static void dsa_slave_adjust_link(struct net_device *dev)
318334
{
319335
struct dsa_slave_priv *p = netdev_priv(dev);
@@ -415,7 +431,8 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
415431
break;
416432
#endif
417433
default:
418-
BUG();
434+
ds->dst->ops = &notag_netdev_ops;
435+
break;
419436
}
420437

421438
SET_NETDEV_DEV(slave_dev, parent);

0 commit comments

Comments
 (0)