Skip to content

Commit 8dce89a

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: ocelot: add tagger for Ocelot/Felix switches
While it is entirely possible that this tagger format is in fact more generic than just these 2 switch families, I don't have that knowledge. The Seville switch in NXP T1040 has a similar frame format, but there are enough differences (e.g. DEST field starts at bit 57 instead of 56) that calling this file tag_vitesse.c is a bit of a stretch at the moment. The frame format has been listed in a comment so that people who add support for further Vitesse switches can rework this tagger while keeping compatibility with Felix. The "ocelot" name was chosen instead of "felix" because even the Ocelot switch can act as a DSA device when it is used in NPI mode, and the Felix tagger format is almost identical. Currently it is only used for the Felix switch embedded in the NXP LS1028A chip. The ABI for this tagger should be considered "not stable" at the moment. The DSA tag is always placed before the Ethernet header and therefore, we are using the long prefix for RX tags to avoid putting the DSA master port in promiscuous mode. Once there will be an API in DSA for drivers to request DSA masters to be in promiscuous mode unconditionally, we will switch to the "no prefix" extraction frame header, which will save 16 padding bytes for each RX frame. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a030dfe commit 8dce89a

5 files changed

Lines changed: 246 additions & 0 deletions

File tree

‎MAINTAINERS‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17360,6 +17360,13 @@ S: Maintained
1736017360
F: drivers/input/serio/userio.c
1736117361
F: include/uapi/linux/userio.h
1736217362

17363+
VITESSE FELIX ETHERNET SWITCH DRIVER
17364+
M: Vladimir Oltean <vladimir.oltean@nxp.com>
17365+
M: Claudiu Manoil <claudiu.manoil@nxp.com>
17366+
L: netdev@vger.kernel.org
17367+
S: Maintained
17368+
F: net/dsa/tag_ocelot.c
17369+
1736317370
VIVID VIRTUAL VIDEO DRIVER
1736417371
M: Hans Verkuil <hverkuil@xs4all.nl>
1736517372
L: linux-media@vger.kernel.org

‎include/net/dsa.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct phylink_link_state;
4242
#define DSA_TAG_PROTO_8021Q_VALUE 12
4343
#define DSA_TAG_PROTO_SJA1105_VALUE 13
4444
#define DSA_TAG_PROTO_KSZ8795_VALUE 14
45+
#define DSA_TAG_PROTO_OCELOT_VALUE 15
4546

4647
enum dsa_tag_protocol {
4748
DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
@@ -59,6 +60,7 @@ enum dsa_tag_protocol {
5960
DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE,
6061
DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE,
6162
DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE,
63+
DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE,
6264
};
6365

6466
struct packet_type;

‎net/dsa/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ config NET_DSA_TAG_KSZ
7979
Say Y if you want to enable support for tagging frames for the
8080
Microchip 8795/9477/9893 families of switches.
8181

82+
config NET_DSA_TAG_OCELOT
83+
tristate "Tag driver for Ocelot family of switches"
84+
select PACKING
85+
help
86+
Say Y or M if you want to enable support for tagging frames for the
87+
Ocelot switches (VSC7511, VSC7512, VSC7513, VSC7514, VSC9959).
88+
8289
config NET_DSA_TAG_QCA
8390
tristate "Tag driver for Qualcomm Atheros QCA8K switches"
8491
help

‎net/dsa/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
1212
obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
1313
obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
1414
obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
15+
obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
1516
obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
1617
obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
1718
obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o

‎net/dsa/tag_ocelot.c‎

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright 2019 NXP Semiconductors
3+
*/
4+
#include <soc/mscc/ocelot.h>
5+
#include <linux/packing.h>
6+
#include "dsa_priv.h"
7+
8+
/* The CPU injection header and the CPU extraction header can have 3 types of
9+
* prefixes: long, short and no prefix. The format of the header itself is the
10+
* same in all 3 cases.
11+
*
12+
* Extraction with long prefix:
13+
*
14+
* +-------------------+-------------------+------+------+------------+-------+
15+
* | ff:ff:ff:ff:ff:ff | ff:ff:ff:ff:ff:ff | 8880 | 000a | extraction | frame |
16+
* | | | | | header | |
17+
* +-------------------+-------------------+------+------+------------+-------+
18+
* 48 bits 48 bits 16 bits 16 bits 128 bits
19+
*
20+
* Extraction with short prefix:
21+
*
22+
* +------+------+------------+-------+
23+
* | 8880 | 000a | extraction | frame |
24+
* | | | header | |
25+
* +------+------+------------+-------+
26+
* 16 bits 16 bits 128 bits
27+
*
28+
* Extraction with no prefix:
29+
*
30+
* +------------+-------+
31+
* | extraction | frame |
32+
* | header | |
33+
* +------------+-------+
34+
* 128 bits
35+
*
36+
*
37+
* Injection with long prefix:
38+
*
39+
* +-------------------+-------------------+------+------+------------+-------+
40+
* | any dmac | any smac | 8880 | 000a | injection | frame |
41+
* | | | | | header | |
42+
* +-------------------+-------------------+------+------+------------+-------+
43+
* 48 bits 48 bits 16 bits 16 bits 128 bits
44+
*
45+
* Injection with short prefix:
46+
*
47+
* +------+------+------------+-------+
48+
* | 8880 | 000a | injection | frame |
49+
* | | | header | |
50+
* +------+------+------------+-------+
51+
* 16 bits 16 bits 128 bits
52+
*
53+
* Injection with no prefix:
54+
*
55+
* +------------+-------+
56+
* | injection | frame |
57+
* | header | |
58+
* +------------+-------+
59+
* 128 bits
60+
*
61+
* The injection header looks like this (network byte order, bit 127
62+
* is part of lowest address byte in memory, bit 0 is part of highest
63+
* address byte):
64+
*
65+
* +------+------+------+------+------+------+------+------+
66+
* 127:120 |BYPASS| MASQ | MASQ_PORT |REW_OP|REW_OP|
67+
* +------+------+------+------+------+------+------+------+
68+
* 119:112 | REW_OP |
69+
* +------+------+------+------+------+------+------+------+
70+
* 111:104 | REW_VAL |
71+
* +------+------+------+------+------+------+------+------+
72+
* 103: 96 | REW_VAL |
73+
* +------+------+------+------+------+------+------+------+
74+
* 95: 88 | REW_VAL |
75+
* +------+------+------+------+------+------+------+------+
76+
* 87: 80 | REW_VAL |
77+
* +------+------+------+------+------+------+------+------+
78+
* 79: 72 | RSV |
79+
* +------+------+------+------+------+------+------+------+
80+
* 71: 64 | RSV | DEST |
81+
* +------+------+------+------+------+------+------+------+
82+
* 63: 56 | DEST |
83+
* +------+------+------+------+------+------+------+------+
84+
* 55: 48 | RSV |
85+
* +------+------+------+------+------+------+------+------+
86+
* 47: 40 | RSV | SRC_PORT | RSV |TFRM_TIMER|
87+
* +------+------+------+------+------+------+------+------+
88+
* 39: 32 | TFRM_TIMER | RSV |
89+
* +------+------+------+------+------+------+------+------+
90+
* 31: 24 | RSV | DP | POP_CNT | CPUQ |
91+
* +------+------+------+------+------+------+------+------+
92+
* 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
93+
* +------+------+------+------+------+------+------+------+
94+
* 15: 8 | PCP | DEI | VID |
95+
* +------+------+------+------+------+------+------+------+
96+
* 7: 0 | VID |
97+
* +------+------+------+------+------+------+------+------+
98+
*
99+
* And the extraction header looks like this:
100+
*
101+
* +------+------+------+------+------+------+------+------+
102+
* 127:120 | RSV | REW_OP |
103+
* +------+------+------+------+------+------+------+------+
104+
* 119:112 | REW_OP | REW_VAL |
105+
* +------+------+------+------+------+------+------+------+
106+
* 111:104 | REW_VAL |
107+
* +------+------+------+------+------+------+------+------+
108+
* 103: 96 | REW_VAL |
109+
* +------+------+------+------+------+------+------+------+
110+
* 95: 88 | REW_VAL |
111+
* +------+------+------+------+------+------+------+------+
112+
* 87: 80 | REW_VAL | LLEN |
113+
* +------+------+------+------+------+------+------+------+
114+
* 79: 72 | LLEN | WLEN |
115+
* +------+------+------+------+------+------+------+------+
116+
* 71: 64 | WLEN | RSV |
117+
* +------+------+------+------+------+------+------+------+
118+
* 63: 56 | RSV |
119+
* +------+------+------+------+------+------+------+------+
120+
* 55: 48 | RSV |
121+
* +------+------+------+------+------+------+------+------+
122+
* 47: 40 | RSV | SRC_PORT | ACL_ID |
123+
* +------+------+------+------+------+------+------+------+
124+
* 39: 32 | ACL_ID | RSV | SFLOW_ID |
125+
* +------+------+------+------+------+------+------+------+
126+
* 31: 24 |ACL_HIT| DP | LRN_FLAGS | CPUQ |
127+
* +------+------+------+------+------+------+------+------+
128+
* 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
129+
* +------+------+------+------+------+------+------+------+
130+
* 15: 8 | PCP | DEI | VID |
131+
* +------+------+------+------+------+------+------+------+
132+
* 7: 0 | VID |
133+
* +------+------+------+------+------+------+------+------+
134+
*/
135+
136+
static struct sk_buff *ocelot_xmit(struct sk_buff *skb,
137+
struct net_device *netdev)
138+
{
139+
struct dsa_port *dp = dsa_slave_to_port(netdev);
140+
u64 bypass, dest, src, qos_class;
141+
struct dsa_switch *ds = dp->ds;
142+
int port = dp->index;
143+
u8 *injection;
144+
145+
if (unlikely(skb_cow_head(skb, OCELOT_TAG_LEN) < 0)) {
146+
netdev_err(netdev, "Cannot make room for tag.\n");
147+
return NULL;
148+
}
149+
150+
injection = skb_push(skb, OCELOT_TAG_LEN);
151+
152+
memset(injection, 0, OCELOT_TAG_LEN);
153+
154+
src = dsa_upstream_port(ds, port);
155+
dest = BIT(port);
156+
bypass = true;
157+
qos_class = skb->priority;
158+
159+
packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
160+
packing(injection, &dest, 68, 56, OCELOT_TAG_LEN, PACK, 0);
161+
packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
162+
packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0);
163+
164+
return skb;
165+
}
166+
167+
static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
168+
struct net_device *netdev,
169+
struct packet_type *pt)
170+
{
171+
u64 src_port, qos_class;
172+
u8 *start = skb->data;
173+
u8 *extraction;
174+
175+
/* Revert skb->data by the amount consumed by the DSA master,
176+
* so it points to the beginning of the frame.
177+
*/
178+
skb_push(skb, ETH_HLEN);
179+
/* We don't care about the long prefix, it is just for easy entrance
180+
* into the DSA master's RX filter. Discard it now by moving it into
181+
* the headroom.
182+
*/
183+
skb_pull(skb, OCELOT_LONG_PREFIX_LEN);
184+
/* And skb->data now points to the extraction frame header.
185+
* Keep a pointer to it.
186+
*/
187+
extraction = skb->data;
188+
/* Now the EFH is part of the headroom as well */
189+
skb_pull(skb, OCELOT_TAG_LEN);
190+
/* Reset the pointer to the real MAC header */
191+
skb_reset_mac_header(skb);
192+
skb_reset_mac_len(skb);
193+
/* And move skb->data to the correct location again */
194+
skb_pull(skb, ETH_HLEN);
195+
196+
/* Remove from inet csum the extraction header */
197+
skb_postpull_rcsum(skb, start, OCELOT_LONG_PREFIX_LEN + OCELOT_TAG_LEN);
198+
199+
packing(extraction, &src_port, 46, 43, OCELOT_TAG_LEN, UNPACK, 0);
200+
packing(extraction, &qos_class, 19, 17, OCELOT_TAG_LEN, UNPACK, 0);
201+
202+
skb->dev = dsa_master_find_slave(netdev, 0, src_port);
203+
if (!skb->dev)
204+
/* The switch will reflect back some frames sent through
205+
* sockets opened on the bare DSA master. These will come back
206+
* with src_port equal to the index of the CPU port, for which
207+
* there is no slave registered. So don't print any error
208+
* message here (ignore and drop those frames).
209+
*/
210+
return NULL;
211+
212+
skb->offload_fwd_mark = 1;
213+
skb->priority = qos_class;
214+
215+
return skb;
216+
}
217+
218+
static struct dsa_device_ops ocelot_netdev_ops = {
219+
.name = "ocelot",
220+
.proto = DSA_TAG_PROTO_OCELOT,
221+
.xmit = ocelot_xmit,
222+
.rcv = ocelot_rcv,
223+
.overhead = OCELOT_TAG_LEN + OCELOT_LONG_PREFIX_LEN,
224+
};
225+
226+
MODULE_LICENSE("GPL v2");
227+
MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_OCELOT);
228+
229+
module_dsa_tag_driver(ocelot_netdev_ops);

0 commit comments

Comments
 (0)