]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - net/dsa/tag_ocelot_8021q.c
net: dsa: tag_ocelot: break circular dependency with ocelot switch lib driver
[mirror_ubuntu-jammy-kernel.git] / net / dsa / tag_ocelot_8021q.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2020-2021 NXP
3 *
4 * An implementation of the software-defined tag_8021q.c tagger format, which
5 * also preserves full functionality under a vlan_filtering bridge. It does
6 * this by using the TCAM engines for:
7 * - pushing the RX VLAN as a second, outer tag, on egress towards the CPU port
8 * - redirecting towards the correct front port based on TX VLAN and popping
9 * that on egress
10 */
11 #include <linux/dsa/8021q.h>
12 #include <linux/dsa/ocelot.h>
13 #include <soc/mscc/ocelot.h>
14 #include <soc/mscc/ocelot_ptp.h>
15 #include "dsa_priv.h"
16
17 static struct sk_buff *ocelot_xmit(struct sk_buff *skb,
18 struct net_device *netdev)
19 {
20 struct dsa_port *dp = dsa_slave_to_port(netdev);
21 u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
22 u16 queue_mapping = skb_get_queue_mapping(skb);
23 u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
24 struct ocelot *ocelot = dp->ds->priv;
25 int port = dp->index;
26 u32 rew_op = 0;
27
28 rew_op = ocelot_ptp_rew_op(skb);
29 if (rew_op) {
30 if (!ocelot_can_inject(ocelot, 0))
31 return NULL;
32
33 ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb);
34 return NULL;
35 }
36
37 return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q,
38 ((pcp << VLAN_PRIO_SHIFT) | tx_vid));
39 }
40
41 static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
42 struct net_device *netdev)
43 {
44 int src_port, switch_id;
45
46 dsa_8021q_rcv(skb, &src_port, &switch_id);
47
48 skb->dev = dsa_master_find_slave(netdev, switch_id, src_port);
49 if (!skb->dev)
50 return NULL;
51
52 dsa_default_offload_fwd_mark(skb);
53
54 return skb;
55 }
56
57 static const struct dsa_device_ops ocelot_8021q_netdev_ops = {
58 .name = "ocelot-8021q",
59 .proto = DSA_TAG_PROTO_OCELOT_8021Q,
60 .xmit = ocelot_xmit,
61 .rcv = ocelot_rcv,
62 .needed_headroom = VLAN_HLEN,
63 .promisc_on_master = true,
64 };
65
66 MODULE_LICENSE("GPL v2");
67 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_OCELOT_8021Q);
68
69 module_dsa_tag_driver(ocelot_8021q_netdev_ops);