Skip to contentSkip to conversation

net: dsa: Modify tag_ksz.c so that tail tag code can be used by other KSZ switch drivers

PATCH In review [email protected] 2 participants 2 messages Dec 6, 2017

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

PATCH v3 1/1 net: dsa: Modify tag_ksz.c so that tail tag code can be used by other KSZ switch drivers

From: Tristram Ha <[email protected]>

Modify tag_ksz.c so that tail tag code can be used by other KSZ switch drivers.

---
v3
- For latest KSZ9477 patch

v2
- No new feature is introduced

v1
- Switch driver code is not accessed from tag_ksz.c

 drivers/net/dsa/microchip/Kconfig   |  2 +-
 drivers/net/dsa/microchip/ksz9477.c |  2 +-
 include/net/dsa.h                   |  2 +-
 net/dsa/Kconfig                     |  4 ++
 net/dsa/dsa.c                       |  4 +-
 net/dsa/dsa_priv.h                  |  2 +-
 net/dsa/tag_ksz.c                   | 90 ++++++++++++++++++++++++-------------
 7 files changed, 70 insertions(+), 36 deletions(-)
drivers/net/dsa/microchip/Kconfig +1 -1
index 5a8660d..ab8f9f6 100644
@@ -1,7 +1,7 @@
 menuconfig MICROCHIP_KSZ9477
 	tristate "Microchip KSZ9477 series switch support"
 	depends on NET_DSA
-	select NET_DSA_TAG_KSZ
+	select NET_DSA_TAG_KSZ9477
 	help
 	  This driver adds support for Microchip KSZ9477 switch chips.
 
drivers/net/dsa/microchip/ksz9477.c +1 -1
index 8bae36b1..ca1ccea 100644
@@ -344,7 +344,7 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
 static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
 						      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)
include/net/dsa.h +1 -1
index 8198efc..2b1a222 100644
@@ -32,7 +32,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_BRCM_PREPEND,
 	DSA_TAG_PROTO_DSA,
 	DSA_TAG_PROTO_EDSA,
-	DSA_TAG_PROTO_KSZ,
+	DSA_TAG_PROTO_KSZ9477,
 	DSA_TAG_PROTO_LAN9303,
 	DSA_TAG_PROTO_MTK,
 	DSA_TAG_PROTO_QCA,
net/dsa/Kconfig +4 -0
index 03c3bdf..809b0e2 100644
@@ -32,6 +32,10 @@ config NET_DSA_TAG_EDSA
 config NET_DSA_TAG_KSZ
 	bool
 
+config NET_DSA_TAG_KSZ9477
+	bool
+	select NET_DSA_TAG_KSZ
+
 config NET_DSA_TAG_LAN9303
 	bool
 
net/dsa/dsa.c +2 -2
index 6a9d0f5..92056a7 100644
@@ -53,8 +53,8 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 #ifdef CONFIG_NET_DSA_TAG_EDSA
 	[DSA_TAG_PROTO_EDSA] = &edsa_netdev_ops,
 #endif
-#ifdef CONFIG_NET_DSA_TAG_KSZ
-	[DSA_TAG_PROTO_KSZ] = &ksz_netdev_ops,
+#ifdef CONFIG_NET_DSA_TAG_KSZ9477
+	[DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops,
 #endif
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
 	[DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops,
net/dsa/dsa_priv.h +1 -1
index 7d03669..a2955a8 100644
@@ -200,7 +200,7 @@ static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
 extern const struct dsa_device_ops edsa_netdev_ops;
 
 /* tag_ksz.c */
-extern const struct dsa_device_ops ksz_netdev_ops;
+extern const struct dsa_device_ops ksz9477_netdev_ops;
 
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
net/dsa/tag_ksz.c +60 -30

134 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

net/dsa/tag_ksz.c static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) · line 115

Quoted 13 lines · On Tue, Dec 05, 2017 at 05:47:14PM -0800, [email protected] wrote:
net/dsa/tag_ksz.c +13 -0
+static int ksz9477_get_tag(u8 *tag, int *port)
+{
+	*port = tag[0] & 7;
+	return KSZ_EGRESS_TAG_LEN;
+}
+
+static void ksz9477_set_tag(void *ptr, u8 *addr, int p)
+{
+	u16 *tag = (u16 *)ptr;
+
+	*tag = 1 << p;
+	*tag = cpu_to_be16(*tag);
+}

Hi Tristram

It would be more normal to create an ops structure

struct ksz_tag_ops {
       int (*get_tag)(u8 *tag, int *port);
       void (*set_tag)(void *ptr, u8 *addr, int p)
};
static const struct ksz_tag_ops ksz9477_tag_ops = {
       .get_tag = ksz9477_get_tag,
       .set_tag = ksz9477_set_tag,
}

and then pass this to the functions.

It might even be possible to make this more generic, use it for other tag drivers.

Andrew