Skip to content

Commit 5312b93

Browse files
committed
Merge branch 'dsa-tag-cleanups'
Marek Vasut says: ==================== net: dsa: ksz: Clean up the tag code in prep for more switches Clean up the KSZ DSA tag code in preparation for adding more switches. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 036b9e7 + 8a75b9d commit 5312b93

File tree

7 files changed

+90
-48
lines changed

7 files changed

+90
-48
lines changed

drivers/net/dsa/microchip/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ config NET_DSA_MICROCHIP_KSZ_COMMON
44
menuconfig NET_DSA_MICROCHIP_KSZ9477
55
tristate "Microchip KSZ9477 series switch support"
66
depends on NET_DSA
7-
select NET_DSA_TAG_KSZ
7+
select NET_DSA_TAG_KSZ9477
88
select NET_DSA_MICROCHIP_KSZ_COMMON
99
help
1010
This driver adds support for Microchip KSZ9477 switch chips.

drivers/net/dsa/microchip/ksz9477.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static int ksz9477_reset_switch(struct ksz_device *dev)
262262
static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
263263
int port)
264264
{
265-
return DSA_TAG_PROTO_KSZ;
265+
return DSA_TAG_PROTO_KSZ9477;
266266
}
267267

268268
static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)

include/net/dsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum dsa_tag_protocol {
3636
DSA_TAG_PROTO_DSA,
3737
DSA_TAG_PROTO_EDSA,
3838
DSA_TAG_PROTO_GSWIP,
39-
DSA_TAG_PROTO_KSZ,
39+
DSA_TAG_PROTO_KSZ9477,
4040
DSA_TAG_PROTO_LAN9303,
4141
DSA_TAG_PROTO_MTK,
4242
DSA_TAG_PROTO_QCA,

net/dsa/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ config NET_DSA_TAG_GSWIP
4444
config NET_DSA_TAG_KSZ
4545
bool
4646

47+
config NET_DSA_TAG_KSZ9477
48+
bool
49+
select NET_DSA_TAG_KSZ
50+
4751
config NET_DSA_TAG_LAN9303
4852
bool
4953

net/dsa/dsa.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
5555
#ifdef CONFIG_NET_DSA_TAG_GSWIP
5656
[DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops,
5757
#endif
58-
#ifdef CONFIG_NET_DSA_TAG_KSZ
59-
[DSA_TAG_PROTO_KSZ] = &ksz_netdev_ops,
58+
#ifdef CONFIG_NET_DSA_TAG_KSZ9477
59+
[DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops,
6060
#endif
6161
#ifdef CONFIG_NET_DSA_TAG_LAN9303
6262
[DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops,
@@ -91,8 +91,8 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
9191
#ifdef CONFIG_NET_DSA_TAG_GSWIP
9292
[DSA_TAG_PROTO_GSWIP] = "gswip",
9393
#endif
94-
#ifdef CONFIG_NET_DSA_TAG_KSZ
95-
[DSA_TAG_PROTO_KSZ] = "ksz",
94+
#ifdef CONFIG_NET_DSA_TAG_KSZ9477
95+
[DSA_TAG_PROTO_KSZ9477] = "ksz9477",
9696
#endif
9797
#ifdef CONFIG_NET_DSA_TAG_LAN9303
9898
[DSA_TAG_PROTO_LAN9303] = "lan9303",

net/dsa/dsa_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extern const struct dsa_device_ops edsa_netdev_ops;
210210
extern const struct dsa_device_ops gswip_netdev_ops;
211211

212212
/* tag_ksz.c */
213-
extern const struct dsa_device_ops ksz_netdev_ops;
213+
extern const struct dsa_device_ops ksz9477_netdev_ops;
214214

215215
/* tag_lan9303.c */
216216
extern const struct dsa_device_ops lan9303_netdev_ops;

net/dsa/tag_ksz.c

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,26 @@
1414
#include <net/dsa.h>
1515
#include "dsa_priv.h"
1616

17-
/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
18-
* ---------------------------------------------------------------------------
19-
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
20-
* ---------------------------------------------------------------------------
21-
* tag0 : Prioritization (not used now)
22-
* tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
23-
*
24-
* For Egress (KSZ -> Host), 1 byte is added before FCS.
25-
* ---------------------------------------------------------------------------
26-
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|FCS(4bytes)
27-
* ---------------------------------------------------------------------------
28-
* tag0 : zero-based value represents port
29-
* (eg, 0x00=port1, 0x02=port3, 0x06=port7)
30-
*/
31-
32-
#define KSZ_INGRESS_TAG_LEN 2
33-
#define KSZ_EGRESS_TAG_LEN 1
17+
/* Typically only one byte is used for tail tag. */
18+
#define KSZ_EGRESS_TAG_LEN 1
3419

35-
static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
20+
static struct sk_buff *ksz_common_xmit(struct sk_buff *skb,
21+
struct net_device *dev, int len)
3622
{
37-
struct dsa_port *dp = dsa_slave_to_port(dev);
3823
struct sk_buff *nskb;
3924
int padlen;
40-
u8 *tag;
4125

4226
padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
4327

44-
if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
28+
if (skb_tailroom(skb) >= padlen + len) {
4529
/* Let dsa_slave_xmit() free skb */
4630
if (__skb_put_padto(skb, skb->len + padlen, false))
4731
return NULL;
4832

4933
nskb = skb;
5034
} else {
5135
nskb = alloc_skb(NET_IP_ALIGN + skb->len +
52-
padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
36+
padlen + len, GFP_ATOMIC);
5337
if (!nskb)
5438
return NULL;
5539
skb_reserve(nskb, NET_IP_ALIGN);
@@ -70,34 +54,88 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
7054
consume_skb(skb);
7155
}
7256

73-
tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN);
74-
tag[0] = 0;
75-
tag[1] = 1 << dp->index; /* destination port */
76-
7757
return nskb;
7858
}
7959

80-
static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev,
81-
struct packet_type *pt)
60+
static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
61+
struct net_device *dev,
62+
unsigned int port, unsigned int len)
8263
{
83-
u8 *tag;
84-
int source_port;
64+
skb->dev = dsa_master_find_slave(dev, 0, port);
65+
if (!skb->dev)
66+
return NULL;
8567

86-
tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
68+
pskb_trim_rcsum(skb, skb->len - len);
8769

88-
source_port = tag[0] & 7;
70+
return skb;
71+
}
8972

90-
skb->dev = dsa_master_find_slave(dev, 0, source_port);
91-
if (!skb->dev)
73+
/*
74+
* For Ingress (Host -> KSZ9477), 2 bytes are added before FCS.
75+
* ---------------------------------------------------------------------------
76+
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
77+
* ---------------------------------------------------------------------------
78+
* tag0 : Prioritization (not used now)
79+
* tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
80+
*
81+
* For Egress (KSZ9477 -> Host), 1 byte is added before FCS.
82+
* ---------------------------------------------------------------------------
83+
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|FCS(4bytes)
84+
* ---------------------------------------------------------------------------
85+
* tag0 : zero-based value represents port
86+
* (eg, 0x00=port1, 0x02=port3, 0x06=port7)
87+
*/
88+
89+
#define KSZ9477_INGRESS_TAG_LEN 2
90+
#define KSZ9477_PTP_TAG_LEN 4
91+
#define KSZ9477_PTP_TAG_INDICATION 0x80
92+
93+
#define KSZ9477_TAIL_TAG_OVERRIDE BIT(9)
94+
#define KSZ9477_TAIL_TAG_LOOKUP BIT(10)
95+
96+
static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,
97+
struct net_device *dev)
98+
{
99+
struct dsa_port *dp = dsa_slave_to_port(dev);
100+
struct sk_buff *nskb;
101+
u16 *tag;
102+
u8 *addr;
103+
104+
nskb = ksz_common_xmit(skb, dev, KSZ9477_INGRESS_TAG_LEN);
105+
if (!nskb)
92106
return NULL;
93107

94-
pskb_trim_rcsum(skb, skb->len - KSZ_EGRESS_TAG_LEN);
108+
/* Tag encoding */
109+
tag = skb_put(nskb, KSZ9477_INGRESS_TAG_LEN);
110+
addr = skb_mac_header(nskb);
95111

96-
return skb;
112+
*tag = BIT(dp->index);
113+
114+
if (is_link_local_ether_addr(addr))
115+
*tag |= KSZ9477_TAIL_TAG_OVERRIDE;
116+
117+
*tag = cpu_to_be16(*tag);
118+
119+
return nskb;
120+
}
121+
122+
static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
123+
struct packet_type *pt)
124+
{
125+
/* Tag decoding */
126+
u8 *tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
127+
unsigned int port = tag[0] & 7;
128+
unsigned int len = KSZ_EGRESS_TAG_LEN;
129+
130+
/* Extra 4-bytes PTP timestamp */
131+
if (tag[0] & KSZ9477_PTP_TAG_INDICATION)
132+
len += KSZ9477_PTP_TAG_LEN;
133+
134+
return ksz_common_rcv(skb, dev, port, len);
97135
}
98136

99-
const struct dsa_device_ops ksz_netdev_ops = {
100-
.xmit = ksz_xmit,
101-
.rcv = ksz_rcv,
102-
.overhead = KSZ_INGRESS_TAG_LEN,
137+
const struct dsa_device_ops ksz9477_netdev_ops = {
138+
.xmit = ksz9477_xmit,
139+
.rcv = ksz9477_rcv,
140+
.overhead = KSZ9477_INGRESS_TAG_LEN,
103141
};

0 commit comments

Comments
 (0)