]>
Commit | Line | Data |
---|---|---|
8dce89aa | 1 | // SPDX-License-Identifier: GPL-2.0 |
3c9cfb52 | 2 | /* Copyright 2019 NXP |
8dce89aa | 3 | */ |
40d3f295 | 4 | #include <linux/dsa/ocelot.h> |
8dce89aa | 5 | #include <soc/mscc/ocelot.h> |
8dce89aa VO |
6 | #include "dsa_priv.h" |
7 | ||
7c4bb540 VO |
8 | static void ocelot_xmit_common(struct sk_buff *skb, struct net_device *netdev, |
9 | __be32 ifh_prefix, void **ifh) | |
8dce89aa VO |
10 | { |
11 | struct dsa_port *dp = dsa_slave_to_port(netdev); | |
8dce89aa | 12 | struct dsa_switch *ds = dp->ds; |
7c4bb540 VO |
13 | void *injection; |
14 | __be32 *prefix; | |
39e5308b | 15 | u32 rew_op = 0; |
8dce89aa | 16 | |
67c24049 | 17 | injection = skb_push(skb, OCELOT_TAG_LEN); |
5124197c VO |
18 | prefix = skb_push(skb, OCELOT_SHORT_PREFIX_LEN); |
19 | ||
7c4bb540 VO |
20 | *prefix = ifh_prefix; |
21 | memset(injection, 0, OCELOT_TAG_LEN); | |
22 | ocelot_ifh_set_bypass(injection, 1); | |
23 | ocelot_ifh_set_src(injection, ds->num_ports); | |
40d3f295 | 24 | ocelot_ifh_set_qos_class(injection, skb->priority); |
8dce89aa | 25 | |
39e5308b YL |
26 | rew_op = ocelot_ptp_rew_op(skb); |
27 | if (rew_op) | |
28 | ocelot_ifh_set_rew_op(injection, rew_op); | |
c0bcf537 | 29 | |
7c4bb540 VO |
30 | *ifh = injection; |
31 | } | |
32 | ||
33 | static struct sk_buff *ocelot_xmit(struct sk_buff *skb, | |
34 | struct net_device *netdev) | |
35 | { | |
36 | struct dsa_port *dp = dsa_slave_to_port(netdev); | |
37 | void *injection; | |
38 | ||
39 | ocelot_xmit_common(skb, netdev, cpu_to_be32(0x8880000a), &injection); | |
1f778d50 | 40 | ocelot_ifh_set_dest(injection, BIT_ULL(dp->index)); |
7c4bb540 VO |
41 | |
42 | return skb; | |
43 | } | |
44 | ||
45 | static struct sk_buff *seville_xmit(struct sk_buff *skb, | |
46 | struct net_device *netdev) | |
47 | { | |
48 | struct dsa_port *dp = dsa_slave_to_port(netdev); | |
49 | void *injection; | |
50 | ||
51 | ocelot_xmit_common(skb, netdev, cpu_to_be32(0x88800005), &injection); | |
1f778d50 | 52 | seville_ifh_set_dest(injection, BIT_ULL(dp->index)); |
7c4bb540 | 53 | |
8dce89aa VO |
54 | return skb; |
55 | } | |
56 | ||
57 | static struct sk_buff *ocelot_rcv(struct sk_buff *skb, | |
29a097b7 | 58 | struct net_device *netdev) |
8dce89aa VO |
59 | { |
60 | u64 src_port, qos_class; | |
ea440cd2 | 61 | u64 vlan_tci, tag_type; |
8dce89aa | 62 | u8 *start = skb->data; |
8a678bb2 | 63 | struct dsa_port *dp; |
8dce89aa | 64 | u8 *extraction; |
ea440cd2 | 65 | u16 vlan_tpid; |
8dce89aa VO |
66 | |
67 | /* Revert skb->data by the amount consumed by the DSA master, | |
68 | * so it points to the beginning of the frame. | |
69 | */ | |
70 | skb_push(skb, ETH_HLEN); | |
5124197c | 71 | /* We don't care about the short prefix, it is just for easy entrance |
8dce89aa VO |
72 | * into the DSA master's RX filter. Discard it now by moving it into |
73 | * the headroom. | |
74 | */ | |
5124197c | 75 | skb_pull(skb, OCELOT_SHORT_PREFIX_LEN); |
8dce89aa VO |
76 | /* And skb->data now points to the extraction frame header. |
77 | * Keep a pointer to it. | |
78 | */ | |
79 | extraction = skb->data; | |
80 | /* Now the EFH is part of the headroom as well */ | |
81 | skb_pull(skb, OCELOT_TAG_LEN); | |
82 | /* Reset the pointer to the real MAC header */ | |
83 | skb_reset_mac_header(skb); | |
84 | skb_reset_mac_len(skb); | |
85 | /* And move skb->data to the correct location again */ | |
86 | skb_pull(skb, ETH_HLEN); | |
87 | ||
88 | /* Remove from inet csum the extraction header */ | |
5124197c | 89 | skb_postpull_rcsum(skb, start, OCELOT_TOTAL_TAG_LEN); |
8dce89aa | 90 | |
40d3f295 VO |
91 | ocelot_xfh_get_src_port(extraction, &src_port); |
92 | ocelot_xfh_get_qos_class(extraction, &qos_class); | |
93 | ocelot_xfh_get_tag_type(extraction, &tag_type); | |
94 | ocelot_xfh_get_vlan_tci(extraction, &vlan_tci); | |
8dce89aa VO |
95 | |
96 | skb->dev = dsa_master_find_slave(netdev, 0, src_port); | |
97 | if (!skb->dev) | |
98 | /* The switch will reflect back some frames sent through | |
99 | * sockets opened on the bare DSA master. These will come back | |
100 | * with src_port equal to the index of the CPU port, for which | |
101 | * there is no slave registered. So don't print any error | |
102 | * message here (ignore and drop those frames). | |
103 | */ | |
104 | return NULL; | |
105 | ||
bea79078 | 106 | dsa_default_offload_fwd_mark(skb); |
8dce89aa VO |
107 | skb->priority = qos_class; |
108 | ||
ea440cd2 VO |
109 | /* Ocelot switches copy frames unmodified to the CPU. However, it is |
110 | * possible for the user to request a VLAN modification through | |
111 | * VCAP_IS1_ACT_VID_REPLACE_ENA. In this case, what will happen is that | |
112 | * the VLAN ID field from the Extraction Header gets updated, but the | |
113 | * 802.1Q header does not (the classified VLAN only becomes visible on | |
114 | * egress through the "port tag" of front-panel ports). | |
115 | * So, for traffic extracted by the CPU, we want to pick up the | |
116 | * classified VLAN and manually replace the existing 802.1Q header from | |
117 | * the packet with it, so that the operating system is always up to | |
118 | * date with the result of tc-vlan actions. | |
119 | * NOTE: In VLAN-unaware mode, we don't want to do that, we want the | |
120 | * frame to remain unmodified, because the classified VLAN is always | |
121 | * equal to the pvid of the ingress port and should not be used for | |
122 | * processing. | |
123 | */ | |
8a678bb2 | 124 | dp = dsa_slave_to_port(skb->dev); |
ea440cd2 VO |
125 | vlan_tpid = tag_type ? ETH_P_8021AD : ETH_P_8021Q; |
126 | ||
8a678bb2 | 127 | if (dsa_port_is_vlan_filtering(dp) && |
ea440cd2 VO |
128 | eth_hdr(skb)->h_proto == htons(vlan_tpid)) { |
129 | u16 dummy_vlan_tci; | |
130 | ||
131 | skb_push_rcsum(skb, ETH_HLEN); | |
132 | __skb_vlan_pop(skb, &dummy_vlan_tci); | |
133 | skb_pull_rcsum(skb, ETH_HLEN); | |
134 | __vlan_hwaccel_put_tag(skb, htons(vlan_tpid), vlan_tci); | |
135 | } | |
136 | ||
8dce89aa VO |
137 | return skb; |
138 | } | |
139 | ||
2fa3888b | 140 | static const struct dsa_device_ops ocelot_netdev_ops = { |
8dce89aa VO |
141 | .name = "ocelot", |
142 | .proto = DSA_TAG_PROTO_OCELOT, | |
143 | .xmit = ocelot_xmit, | |
144 | .rcv = ocelot_rcv, | |
4e500251 | 145 | .needed_headroom = OCELOT_TOTAL_TAG_LEN, |
5124197c | 146 | .promisc_on_master = true, |
8dce89aa VO |
147 | }; |
148 | ||
7c4bb540 | 149 | DSA_TAG_DRIVER(ocelot_netdev_ops); |
8dce89aa VO |
150 | MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_OCELOT); |
151 | ||
7c4bb540 VO |
152 | static const struct dsa_device_ops seville_netdev_ops = { |
153 | .name = "seville", | |
154 | .proto = DSA_TAG_PROTO_SEVILLE, | |
155 | .xmit = seville_xmit, | |
156 | .rcv = ocelot_rcv, | |
4e500251 | 157 | .needed_headroom = OCELOT_TOTAL_TAG_LEN, |
7c4bb540 VO |
158 | .promisc_on_master = true, |
159 | }; | |
160 | ||
161 | DSA_TAG_DRIVER(seville_netdev_ops); | |
162 | MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_SEVILLE); | |
163 | ||
164 | static struct dsa_tag_driver *ocelot_tag_driver_array[] = { | |
165 | &DSA_TAG_DRIVER_NAME(ocelot_netdev_ops), | |
166 | &DSA_TAG_DRIVER_NAME(seville_netdev_ops), | |
167 | }; | |
168 | ||
169 | module_dsa_tag_drivers(ocelot_tag_driver_array); | |
170 | ||
171 | MODULE_LICENSE("GPL v2"); |