Skip to contentSkip to conversation

dsa: add support for original DSA tagging format

PATCH In review Lennert Buytenhek 3 participants 7 messages Sep 29, 2008 – Oct 5, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/6 dsa: add support for original DSA tagging format

Most of the DSA switches currently in the field do not support the Ethertype DSA tagging format that one of the previous patches added support for, but only the original DSA tagging format.

The original DSA tagging format carries the same information as the Ethertype DSA tagging format, but with the difference that it does not have an ethertype field. In other words, when receiving a packet that is tagged with an original DSA tag, there is no way of telling in eth_type_trans() that this packet is in fact a DSA-tagged packet.

This patch adds a hook into eth_type_trans() which is only compiled in if support for a switch chip that doesn't support Ethertype DSA is selected, and which checks whether there is a DSA switch driver instance attached to this network device which uses the old tag format. If so, it sets the protocol field to ETH_P_DSA without looking at the packet, so that the packet ends up in the right place.

---
 include/linux/if_ether.h  |    1 +
 include/linux/netdevice.h |   11 +++
 include/net/dsa.h         |    2 +
 net/dsa/Kconfig           |    4 +
 net/dsa/Makefile          |    1 +
 net/dsa/dsa.c             |   16 ++++
 net/dsa/dsa_priv.h        |    4 +
 net/dsa/mv88e6123_61_65.c |   17 +++--
 net/dsa/slave.c           |    5 +
 net/dsa/tag_dsa.c         |  194 +++++++++++++++++++++++++++++++++++++++++++++
 net/ethernet/eth.c        |   10 +++
 11 files changed, 258 insertions(+), 7 deletions(-)
 create mode 100644 net/dsa/tag_dsa.c
include/linux/if_ether.h +1 -0
index a85f5a2..864982b 100644
@@ -100,6 +100,7 @@
 #define ETH_P_ECONET	0x0018		/* Acorn Econet			*/
 #define ETH_P_HDLC	0x0019		/* HDLC frames			*/
 #define ETH_P_ARCNET	0x001A		/* 1A for ArcNet :-)            */
+#define ETH_P_DSA	0x001B		/* Distributed Switch Arch.	*/
 
 /*
  *	This is an Ethernet frame header.
include/linux/netdevice.h +11 -0
index f67435d..5226308 100644
@@ -42,6 +42,7 @@
 #include <linux/workqueue.h>
 
 #include <net/net_namespace.h>
+#include <net/dsa.h>
 
 struct vlan_group;
 struct ethtool_ops;
@@ -801,6 +802,16 @@ void dev_net_set(struct net_device *dev, struct net *net)
 #endif
 }
 
+static inline int netdev_uses_dsa_tags(struct net_device *dev)
+{
+#ifdef CONFIG_NET_DSA_TAG_DSA
+	if (dev->dsa_ptr != NULL)
+		return dsa_uses_dsa_tags(dev->dsa_ptr);
+#endif
+
+	return 0;
+}
+
 /**
  *	netdev_priv - access network device private data
  *	@dev: network device
include/net/dsa.h +2 -0
index 96eb2f3..a331f64 100644
@@ -20,5 +20,7 @@ struct dsa_platform_data {
 	char		*port_names[DSA_MAX_PORTS];
 };
 
+int dsa_uses_dsa_tags(void *dsa_ptr);
+
 
 #endif
net/dsa/Kconfig +4 -0
index 7cf55e5..6b68016 100644
@@ -10,6 +10,10 @@ menuconfig NET_DSA
 if NET_DSA
 
 # tagging formats
+config NET_DSA_TAG_DSA
+	bool
+	default n
+
 config NET_DSA_TAG_EDSA
 	bool
 	default n
net/dsa/Makefile +1 -0
index b59a6f6..8b92123 100644
@@ -1,4 +1,5 @@
 # tagging formats
+obj-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
 obj-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
 
 # switch drivers
net/dsa/dsa.c +16 -0
index a010e41..d16a66e 100644
@@ -203,6 +203,22 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
 }
 
 
+/* hooks for ethertype-less tagging formats *********************************/
+/*
+ * The original DSA tag format and some other tag formats have no
+ * ethertype, which means that we need to add a little hack to the
+ * networking receive path to make sure that received frames get
+ * the right ->protocol assigned to them when one of those tag
+ * formats is in use.
+ */
+int dsa_uses_dsa_tags(void *dsa_ptr)
+{
+	struct dsa_switch *ds = dsa_ptr;
+
+	return !!(ds->tag_type == TAG_TYPE_DSA);
+}
+
+
 /* link polling *************************************************************/
 static void dsa_link_poll_work(struct work_struct *ugly)
 {
net/dsa/dsa_priv.h +4 -0
index 5233aba..385a380 100644
@@ -18,6 +18,7 @@
 #include <net/dsa.h>
 
 enum dsa_tag_type {
+	TAG_TYPE_DSA,
 	TAG_TYPE_EDSA,
 };
 
@@ -101,6 +102,9 @@ void unregister_switch_driver(struct dsa_switch_driver *type);
 void dsa_slave_mii_bus_init(struct dsa_switch *ds);
 struct net_device *dsa_slave_create(struct dsa_switch *ds, int port);
 
+/* tag_dsa.c */
+int dsa_xmit(struct sk_buff *skb, struct net_device *dev);
+
 /* tag_edsa.c */
 int edsa_xmit(struct sk_buff *skb, struct net_device *dev);
 
net/dsa/mv88e6123_61_65.c +10 -7
index b53233d..e8cc553 100644
@@ -192,15 +192,18 @@ static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p)
 
 	/*
 	 * Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
-	 * configure the EDSA tagging mode if this is the CPU port,
-	 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
-	 * tunneling, determine priority by looking at 802.1p and IP
-	 * priority fields (IP prio has precedence), and set STP state
-	 * to Forwarding.  Finally, if this is the CPU port, additionally
-	 * enable forwarding of unknown unicast and multicast addresses.
+	 * configure the requested (DSA/EDSA) tagging mode if this is
+	 * the CPU port, disable Header mode, enable IGMP/MLD snooping,
+	 * disable VLAN tunneling, determine priority by looking at
+	 * 802.1p and IP priority fields (IP prio has precedence), and
+	 * set STP state to Forwarding.  Finally, if this is the CPU
+	 * port, additionally enable forwarding of unknown unicast and
+	 * multicast addresses.
 	 */
 	REG_WRITE(addr, 0x04,
-			(p == ds->cpu_port) ? 0x373f : 0x0433);
+			(p == ds->cpu_port) ?
+			 (ds->tag_type == TAG_TYPE_DSA) ? 0x053f : 0x373f :
+			 0x0433);
 
 	/*
 	 * Port Control 1: disable trunking.  Also, if this is the
net/dsa/slave.c +5 -0
index afc8ef0..ac8ed09 100644
@@ -238,6 +238,11 @@ struct net_device *dsa_slave_create(struct dsa_switch *ds, int port)
 	slave_dev->open = dsa_slave_open;
 	slave_dev->stop = dsa_slave_close;
 	switch (ds->tag_type) {
+#ifdef CONFIG_NET_DSA_TAG_DSA
+	case TAG_TYPE_DSA:
+		slave_dev->hard_start_xmit = dsa_xmit;
+		break;
+#endif
 #ifdef CONFIG_NET_DSA_TAG_EDSA
 	case TAG_TYPE_EDSA:
 		slave_dev->hard_start_xmit = edsa_xmit;
net/dsa/tag_dsa.c new file +194 -0

194 lines not on this page · raw message

net/ethernet/eth.c +10 -0
index a80839b..e0aca95 100644
@@ -57,6 +57,7 @@
 #include <net/sock.h>
 #include <net/ipv6.h>
 #include <net/ip.h>
+#include <net/dsa.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
@@ -184,6 +185,15 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
 			skb->pkt_type = PACKET_OTHERHOST;
 	}
 
+	/*
+	 * Some variants of DSA tagging don't have an ethertype field
+	 * at all, so we check here whether one of those tagging
+	 * variants has been configured on the receiving interface,
+	 * and if so, set skb->protocol without looking at the packet.
+	 */
+	if (netdev_uses_dsa_tags(dev))
+		return htons(ETH_P_DSA);
+
 	if (ntohs(eth->h_proto) >= 1536)
 		return eth->h_proto;
 
Signature · 1 line
1.5.6.4
#1 lore raw
Quoted 10 lines · Lennert Buytenhek

Most of the DSA switches currently in the field do not support the Ethertype DSA tagging format that one of the previous patches added support for, but only the original DSA tagging format.

The original DSA tagging format carries the same information as the Ethertype DSA tagging format, but with the difference that it does not have an ethertype field. In other words, when receiving a packet that is tagged with an original DSA tag, there is no way of telling in eth_type_trans() that this packet is in fact a DSA-tagged packet.

Quoted 6 lines

This patch adds a hook into eth_type_trans() which is only compiled in if support for a switch chip that doesn't support Ethertype DSA is selected, and which checks whether there is a DSA switch driver instance attached to this network device which uses the old tag format. If so, it sets the protocol field to ETH_P_DSA without looking at the packet, so that the packet ends up in the right place.

[...]

Why should this go in eth_type_trans()? Why don't you put the hook into the specific network driver(s) that need it?

For that matter, why should dsa_ptr go in struct net_device and not in the private state for the specific network drivers that need it?

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw
Quoted 16 lines · Ben Hutchings
Quoted 10 lines

Most of the DSA switches currently in the field do not support the Ethertype DSA tagging format that one of the previous patches added support for, but only the original DSA tagging format.

The original DSA tagging format carries the same information as the Ethertype DSA tagging format, but with the difference that it does not have an ethertype field. In other words, when receiving a packet that is tagged with an original DSA tag, there is no way of telling in eth_type_trans() that this packet is in fact a DSA-tagged packet.

Quoted 6 lines

This patch adds a hook into eth_type_trans() which is only compiled in if support for a switch chip that doesn't support Ethertype DSA is selected, and which checks whether there is a DSA switch driver instance attached to this network device which uses the old tag format. If so, it sets the protocol field to ETH_P_DSA without looking at the packet, so that the packet ends up in the right place.

Quoted 7 lines

[...]

Why should this go in eth_type_trans()? Why don't you put the hook into the specific network driver(s) that need it?

For that matter, why should dsa_ptr go in struct net_device and not in the private state for the specific network drivers that need it?

DSA is just another protocol. Putting hooks in specific network driver to handle a certain protocol doesn't seem like the right thing to do to me.

#3 lore raw
Quoted 23 lines · Lennert Buytenhek
Quoted 21 lines · Ben Hutchings
Quoted 10 lines

Most of the DSA switches currently in the field do not support the Ethertype DSA tagging format that one of the previous patches added support for, but only the original DSA tagging format.

The original DSA tagging format carries the same information as the Ethertype DSA tagging format, but with the difference that it does not have an ethertype field. In other words, when receiving a packet that is tagged with an original DSA tag, there is no way of telling in eth_type_trans() that this packet is in fact a DSA-tagged packet.

Quoted 6 lines

This patch adds a hook into eth_type_trans() which is only compiled in if support for a switch chip that doesn't support Ethertype DSA is selected, and which checks whether there is a DSA switch driver instance attached to this network device which uses the old tag format. If so, it sets the protocol field to ETH_P_DSA without looking at the packet, so that the packet ends up in the right place.

[...]

Why should this go in eth_type_trans()? Why don't you put the hook into the specific network driver(s) that need it?

Quoted 6 lines
Quoted 2 lines

For that matter, why should dsa_ptr go in struct net_device and not in the private state for the specific network drivers that need it?

DSA is just another protocol. Putting hooks in specific network driver to handle a certain protocol doesn't seem like the right thing to do to me.

If it's just another protocol then put dsa_ptr along with the other protocol pointers (ip_ptr etc.).

For those drivers that work with the original DSA tagging format, it's apparently not just another protocol.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw
Quoted 24 lines · Ben Hutchings
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines

Most of the DSA switches currently in the field do not support the Ethertype DSA tagging format that one of the previous patches added support for, but only the original DSA tagging format.

The original DSA tagging format carries the same information as the Ethertype DSA tagging format, but with the difference that it does not have an ethertype field. In other words, when receiving a packet that is tagged with an original DSA tag, there is no way of telling in eth_type_trans() that this packet is in fact a DSA-tagged packet.

Quoted 6 lines

This patch adds a hook into eth_type_trans() which is only compiled in if support for a switch chip that doesn't support Ethertype DSA is selected, and which checks whether there is a DSA switch driver instance attached to this network device which uses the old tag format. If so, it sets the protocol field to ETH_P_DSA without looking at the packet, so that the packet ends up in the right place.

[...]

Why should this go in eth_type_trans()? Why don't you put the hook into the specific network driver(s) that need it?

For that matter, why should dsa_ptr go in struct net_device and not in the private state for the specific network drivers that need it?

Quoted 6 lines
Quoted 3 lines

DSA is just another protocol. Putting hooks in specific network driver to handle a certain protocol doesn't seem like the right thing to do to me.

If it's just another protocol then put dsa_ptr along with the other protocol pointers (ip_ptr etc.).

OK, I'll do that.

Quoted 2 lines

For those drivers that work with the original DSA tagging format, it's apparently not just another protocol.

The original DSA tagging format can work with any NIC, as long as you hook up that NIC directly to a DSA switch chip instead of to a PHY. In embedded designs you mostly see platform bus drivers like mv643xx_eth and gianfar and such, but there's no reason you can't do it with any other MAC that exposes a (R)(G)MII interface.

The only reason that eth_type_trans() needs a hack is that the original DSA tagging format has information starting right after the ethernet source address, so there's no way to tell that original DSA tagged frames are in fact original DSA tagged frames. (The way we tell is by having the DSA switch driver decide -- it configures the directly attached switch chip to always send DSA tagged packets to the cpu's switch port, and then forces all packets received on the underlying ethernet device to get ETH_P_DSA assigned to skb->protocol.)

#5 lore raw
In reply to Lennert Buytenhek

Please use stronger types..

Quoted 1 line

+static inline int netdev_uses_dsa_tags(struct net_device *dev)

I would use:
static inline bool netdev_uses_dsa_tags(const struct net_device *dev)

Quoted 1 line

+int dsa_uses_dsa_tags(void *dsa_ptr);

extern bool dsa_uses_dsa_tags(const struct dsa_switch *dsa);

#6 lore raw
Quoted 10 lines · Stephen Hemminger

Please use stronger types..

Quoted 1 line

+static inline int netdev_uses_dsa_tags(struct net_device *dev)

I would use:
static inline bool netdev_uses_dsa_tags(const struct net_device *dev)

Quoted 1 line

+int dsa_uses_dsa_tags(void *dsa_ptr);

extern bool dsa_uses_dsa_tags(const struct dsa_switch *dsa);

OK. Did the same thing for the trailer tag support.