Commit 5312b93b authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 036b9e7c 8a75b9d4
...@@ -4,7 +4,7 @@ config NET_DSA_MICROCHIP_KSZ_COMMON ...@@ -4,7 +4,7 @@ config NET_DSA_MICROCHIP_KSZ_COMMON
menuconfig NET_DSA_MICROCHIP_KSZ9477 menuconfig NET_DSA_MICROCHIP_KSZ9477
tristate "Microchip KSZ9477 series switch support" tristate "Microchip KSZ9477 series switch support"
depends on NET_DSA depends on NET_DSA
select NET_DSA_TAG_KSZ select NET_DSA_TAG_KSZ9477
select NET_DSA_MICROCHIP_KSZ_COMMON select NET_DSA_MICROCHIP_KSZ_COMMON
help help
This driver adds support for Microchip KSZ9477 switch chips. This driver adds support for Microchip KSZ9477 switch chips.
......
...@@ -262,7 +262,7 @@ static int ksz9477_reset_switch(struct ksz_device *dev) ...@@ -262,7 +262,7 @@ static int ksz9477_reset_switch(struct ksz_device *dev)
static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds, static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
int port) int port)
{ {
return DSA_TAG_PROTO_KSZ; return DSA_TAG_PROTO_KSZ9477;
} }
static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg) static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
......
...@@ -36,7 +36,7 @@ enum dsa_tag_protocol { ...@@ -36,7 +36,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_DSA, DSA_TAG_PROTO_DSA,
DSA_TAG_PROTO_EDSA, DSA_TAG_PROTO_EDSA,
DSA_TAG_PROTO_GSWIP, DSA_TAG_PROTO_GSWIP,
DSA_TAG_PROTO_KSZ, DSA_TAG_PROTO_KSZ9477,
DSA_TAG_PROTO_LAN9303, DSA_TAG_PROTO_LAN9303,
DSA_TAG_PROTO_MTK, DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_QCA, DSA_TAG_PROTO_QCA,
......
...@@ -44,6 +44,10 @@ config NET_DSA_TAG_GSWIP ...@@ -44,6 +44,10 @@ config NET_DSA_TAG_GSWIP
config NET_DSA_TAG_KSZ config NET_DSA_TAG_KSZ
bool bool
config NET_DSA_TAG_KSZ9477
bool
select NET_DSA_TAG_KSZ
config NET_DSA_TAG_LAN9303 config NET_DSA_TAG_LAN9303
bool bool
......
...@@ -55,8 +55,8 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = { ...@@ -55,8 +55,8 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
#ifdef CONFIG_NET_DSA_TAG_GSWIP #ifdef CONFIG_NET_DSA_TAG_GSWIP
[DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops, [DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops,
#endif #endif
#ifdef CONFIG_NET_DSA_TAG_KSZ #ifdef CONFIG_NET_DSA_TAG_KSZ9477
[DSA_TAG_PROTO_KSZ] = &ksz_netdev_ops, [DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops,
#endif #endif
#ifdef CONFIG_NET_DSA_TAG_LAN9303 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops, [DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops,
...@@ -91,8 +91,8 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops) ...@@ -91,8 +91,8 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
#ifdef CONFIG_NET_DSA_TAG_GSWIP #ifdef CONFIG_NET_DSA_TAG_GSWIP
[DSA_TAG_PROTO_GSWIP] = "gswip", [DSA_TAG_PROTO_GSWIP] = "gswip",
#endif #endif
#ifdef CONFIG_NET_DSA_TAG_KSZ #ifdef CONFIG_NET_DSA_TAG_KSZ9477
[DSA_TAG_PROTO_KSZ] = "ksz", [DSA_TAG_PROTO_KSZ9477] = "ksz9477",
#endif #endif
#ifdef CONFIG_NET_DSA_TAG_LAN9303 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = "lan9303", [DSA_TAG_PROTO_LAN9303] = "lan9303",
......
...@@ -210,7 +210,7 @@ extern const struct dsa_device_ops edsa_netdev_ops; ...@@ -210,7 +210,7 @@ extern const struct dsa_device_ops edsa_netdev_ops;
extern const struct dsa_device_ops gswip_netdev_ops; extern const struct dsa_device_ops gswip_netdev_ops;
/* tag_ksz.c */ /* tag_ksz.c */
extern const struct dsa_device_ops ksz_netdev_ops; extern const struct dsa_device_ops ksz9477_netdev_ops;
/* tag_lan9303.c */ /* tag_lan9303.c */
extern const struct dsa_device_ops lan9303_netdev_ops; extern const struct dsa_device_ops lan9303_netdev_ops;
......
...@@ -14,34 +14,18 @@ ...@@ -14,34 +14,18 @@
#include <net/dsa.h> #include <net/dsa.h>
#include "dsa_priv.h" #include "dsa_priv.h"
/* For Ingress (Host -> KSZ), 2 bytes are added before FCS. /* Typically only one byte is used for tail tag. */
* --------------------------------------------------------------------------- #define KSZ_EGRESS_TAG_LEN 1
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
* ---------------------------------------------------------------------------
* tag0 : Prioritization (not used now)
* tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
*
* For Egress (KSZ -> Host), 1 byte is added before FCS.
* ---------------------------------------------------------------------------
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|FCS(4bytes)
* ---------------------------------------------------------------------------
* tag0 : zero-based value represents port
* (eg, 0x00=port1, 0x02=port3, 0x06=port7)
*/
#define KSZ_INGRESS_TAG_LEN 2
#define KSZ_EGRESS_TAG_LEN 1
static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *ksz_common_xmit(struct sk_buff *skb,
struct net_device *dev, int len)
{ {
struct dsa_port *dp = dsa_slave_to_port(dev);
struct sk_buff *nskb; struct sk_buff *nskb;
int padlen; int padlen;
u8 *tag;
padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len; padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) { if (skb_tailroom(skb) >= padlen + len) {
/* Let dsa_slave_xmit() free skb */ /* Let dsa_slave_xmit() free skb */
if (__skb_put_padto(skb, skb->len + padlen, false)) if (__skb_put_padto(skb, skb->len + padlen, false))
return NULL; return NULL;
...@@ -49,7 +33,7 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -49,7 +33,7 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
nskb = skb; nskb = skb;
} else { } else {
nskb = alloc_skb(NET_IP_ALIGN + skb->len + nskb = alloc_skb(NET_IP_ALIGN + skb->len +
padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC); padlen + len, GFP_ATOMIC);
if (!nskb) if (!nskb)
return NULL; return NULL;
skb_reserve(nskb, NET_IP_ALIGN); skb_reserve(nskb, NET_IP_ALIGN);
...@@ -70,34 +54,88 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -70,34 +54,88 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
consume_skb(skb); consume_skb(skb);
} }
tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN);
tag[0] = 0;
tag[1] = 1 << dp->index; /* destination port */
return nskb; return nskb;
} }
static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
struct packet_type *pt) struct net_device *dev,
unsigned int port, unsigned int len)
{ {
u8 *tag; skb->dev = dsa_master_find_slave(dev, 0, port);
int source_port; if (!skb->dev)
return NULL;
tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN; pskb_trim_rcsum(skb, skb->len - len);
source_port = tag[0] & 7; return skb;
}
skb->dev = dsa_master_find_slave(dev, 0, source_port); /*
if (!skb->dev) * For Ingress (Host -> KSZ9477), 2 bytes are added before FCS.
* ---------------------------------------------------------------------------
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
* ---------------------------------------------------------------------------
* tag0 : Prioritization (not used now)
* tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
*
* For Egress (KSZ9477 -> Host), 1 byte is added before FCS.
* ---------------------------------------------------------------------------
* DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag0(1byte)|FCS(4bytes)
* ---------------------------------------------------------------------------
* tag0 : zero-based value represents port
* (eg, 0x00=port1, 0x02=port3, 0x06=port7)
*/
#define KSZ9477_INGRESS_TAG_LEN 2
#define KSZ9477_PTP_TAG_LEN 4
#define KSZ9477_PTP_TAG_INDICATION 0x80
#define KSZ9477_TAIL_TAG_OVERRIDE BIT(9)
#define KSZ9477_TAIL_TAG_LOOKUP BIT(10)
static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,
struct net_device *dev)
{
struct dsa_port *dp = dsa_slave_to_port(dev);
struct sk_buff *nskb;
u16 *tag;
u8 *addr;
nskb = ksz_common_xmit(skb, dev, KSZ9477_INGRESS_TAG_LEN);
if (!nskb)
return NULL; return NULL;
pskb_trim_rcsum(skb, skb->len - KSZ_EGRESS_TAG_LEN); /* Tag encoding */
tag = skb_put(nskb, KSZ9477_INGRESS_TAG_LEN);
addr = skb_mac_header(nskb);
return skb; *tag = BIT(dp->index);
if (is_link_local_ether_addr(addr))
*tag |= KSZ9477_TAIL_TAG_OVERRIDE;
*tag = cpu_to_be16(*tag);
return nskb;
}
static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt)
{
/* Tag decoding */
u8 *tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
unsigned int port = tag[0] & 7;
unsigned int len = KSZ_EGRESS_TAG_LEN;
/* Extra 4-bytes PTP timestamp */
if (tag[0] & KSZ9477_PTP_TAG_INDICATION)
len += KSZ9477_PTP_TAG_LEN;
return ksz_common_rcv(skb, dev, port, len);
} }
const struct dsa_device_ops ksz_netdev_ops = { const struct dsa_device_ops ksz9477_netdev_ops = {
.xmit = ksz_xmit, .xmit = ksz9477_xmit,
.rcv = ksz_rcv, .rcv = ksz9477_rcv,
.overhead = KSZ_INGRESS_TAG_LEN, .overhead = KSZ9477_INGRESS_TAG_LEN,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment