Skip to contentSkip to conversation

net: dsa: ksz: Add Microchip KSZ87xx support

PATCH Superseded Marek Vasut 3 participants 9 messages Jul 24, 2019 – Jul 25, 2019

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover net: dsa: ksz: Add Microchip KSZ87xx support

This series adds support for Microchip KSZ87xx switches, which are slightly simpler compared to KSZ9xxx .

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Vivien Didelot <[email protected]>
Cc Woojung Huh <[email protected]>

Marek Vasut (1):
dt-bindings: net: dsa: ksz: document Microchip KSZ87xx family switches

Tristram Ha (2):
net: dsa: ksz: Add KSZ8795 tag code
net: dsa: ksz: Add Microchip KSZ8795 DSA driver

 .../devicetree/bindings/net/dsa/ksz.txt       |    3 +
 drivers/net/dsa/microchip/Kconfig             |   18 +
 drivers/net/dsa/microchip/Makefile            |    2 +
 drivers/net/dsa/microchip/ksz8795.c           | 1360 +++++++++++++++++
 drivers/net/dsa/microchip/ksz8795_reg.h       | 1004 ++++++++++++
 drivers/net/dsa/microchip/ksz8795_spi.c       |  104 ++
 drivers/net/dsa/microchip/ksz_common.h        |   28 +
 drivers/net/dsa/microchip/ksz_priv.h          |    1 +
 include/net/dsa.h                             |    2 +
 net/dsa/Kconfig                               |    7 +
 net/dsa/tag_ksz.c                             |   62 +
 11 files changed, 2591 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/ksz8795.c
 create mode 100644 drivers/net/dsa/microchip/ksz8795_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz8795_spi.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 dt-bindings: net: dsa: ksz: document Microchip KSZ87xx family switches

Document Microchip KSZ87xx family switches. These include KSZ8765 - 5 port switch
KSZ8794 - 4 port switch
KSZ8795 - 5 port switch

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Rob Herring <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Vivien Didelot <[email protected]>
Cc Woojung Huh <[email protected]>
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/net/dsa/ksz.txt +3 -0
index 4ac21cef370e..5e8429b6f9ca 100644
@@ -5,6 +5,9 @@ Required properties:
 
 - compatible: For external switch chips, compatible string must be exactly one
   of the following:
+  - "microchip,ksz8765"
+  - "microchip,ksz8794"
+  - "microchip,ksz8795"
   - "microchip,ksz9477"
   - "microchip,ksz9897"
   - "microchip,ksz9896"
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 net: dsa: ksz: Add KSZ8795 tag code

In reply to Marek Vasut

From: Tristram Ha <[email protected]>

Add DSA tag code for Microchip KSZ8795 switch. The switch is simpler and the tag is only 1 byte, instead of 2 as is the case with KSZ9477.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Vivien Didelot <[email protected]>
Cc Woojung Huh <[email protected]>
---
 include/net/dsa.h |  2 ++
 net/dsa/Kconfig   |  7 ++++++
 net/dsa/tag_ksz.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)
include/net/dsa.h +2 -0
index 1e8650fa8acc..147b757ef8ea 100644
@@ -41,6 +41,7 @@ struct phylink_link_state;
 #define DSA_TAG_PROTO_TRAILER_VALUE		11
 #define DSA_TAG_PROTO_8021Q_VALUE		12
 #define DSA_TAG_PROTO_SJA1105_VALUE		13
+#define DSA_TAG_PROTO_KSZ8795_VALUE		14
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -57,6 +58,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
 	DSA_TAG_PROTO_SJA1105		= DSA_TAG_PROTO_SJA1105_VALUE,
+	DSA_TAG_PROTO_KSZ8795		= DSA_TAG_PROTO_KSZ8795_VALUE,
 };
 
 struct packet_type;
net/dsa/Kconfig +7 -0
index 6e942dda1bcd..423fa4370608 100644
@@ -77,6 +77,13 @@ config NET_DSA_TAG_KSZ_COMMON
 	tristate
 	default n
 
+config NET_DSA_TAG_KSZ8795
+	tristate "Tag driver for Microchip 8795 family of switches"
+	select NET_DSA_TAG_KSZ_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Microchip 8795 family of switches.
+
 config NET_DSA_TAG_KSZ
 	tristate "Tag driver for Microchip 9893 family of switches"
 	select NET_DSA_TAG_KSZ_COMMON
net/dsa/tag_ksz.c +62 -0

74 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 net: dsa: ksz: Add Microchip KSZ8795 DSA driver

In reply to Marek Vasut

From: Tristram Ha <[email protected]>

Add Microchip KSZ8795 DSA driver.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Vivien Didelot <[email protected]>
Cc Woojung Huh <[email protected]>
---
 drivers/net/dsa/microchip/Kconfig       |   18 +
 drivers/net/dsa/microchip/Makefile      |    2 +
 drivers/net/dsa/microchip/ksz8795.c     | 1360 +++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz8795_reg.h | 1004 +++++++++++++++++
 drivers/net/dsa/microchip/ksz8795_spi.c |  104 ++
 drivers/net/dsa/microchip/ksz_common.h  |   28 +
 drivers/net/dsa/microchip/ksz_priv.h    |    1 +
 7 files changed, 2517 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/ksz8795.c
 create mode 100644 drivers/net/dsa/microchip/ksz8795_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz8795_spi.c
drivers/net/dsa/microchip/Kconfig +18 -0
index fe0a13b79c4b..d990c7128991 100644
@@ -16,3 +16,21 @@ config NET_DSA_MICROCHIP_KSZ9477_SPI
 	select REGMAP_SPI
 	help
 	  Select to enable support for registering switches configured through SPI.
+
+menuconfig NET_DSA_MICROCHIP_KSZ8795
+	tristate "Microchip KSZ8795 series switch support"
+	depends on NET_DSA
+	select NET_DSA_TAG_KSZ8795
+	select NET_DSA_MICROCHIP_KSZ_COMMON
+	help
+	  This driver adds support for Microchip KSZ8795 switch chips.
+
+config NET_DSA_MICROCHIP_KSZ8795_SPI
+	tristate "KSZ8795 series SPI connected switch driver"
+	depends on NET_DSA_MICROCHIP_KSZ8795 && SPI
+	select REGMAP_SPI
+	help
+	  This driver accesses KSZ8795 chip through SPI.
+
+	  It is required to use the KSZ8795 switch driver as the only access
+	  is through SPI.
drivers/net/dsa/microchip/Makefile +2 -0
index 68451b02f775..e3d799b95d7d 100644
@@ -2,3 +2,5 @@
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_common.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477)		+= ksz9477.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI)	+= ksz9477_spi.o
+obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795)		+= ksz8795.o
+obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI)	+= ksz8795_spi.o
drivers/net/dsa/microchip/ksz8795.c new file +1360 -0

1,360 lines not on this page · raw message

drivers/net/dsa/microchip/ksz8795_reg.h new file +1004 -0

1,004 lines not on this page · raw message

drivers/net/dsa/microchip/ksz8795_spi.c new file +104 -0

104 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_common.h +28 -0
index ee7096d8af07..84fed4a2578b 100644
@@ -68,6 +68,22 @@ static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
 	return ret;
 }
 
+static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
+{
+	u32 value[2];
+	int ret;
+
+	ret = regmap_bulk_read(dev->regmap[2], reg, value, 2);
+	if (!ret) {
+		/* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
+		value[0] = swab32(value[0]);
+		value[1] = swab32(value[1]);
+		*val = swab64((u64)*value);
+	}
+
+	return ret;
+}
+
 static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
 {
 	return regmap_write(dev->regmap[0], reg, value);
@@ -83,6 +99,18 @@ static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
 	return regmap_write(dev->regmap[2], reg, value);
 }
 
+static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
+{
+	u32 val[2];
+
+	/* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
+	value = swab64(value);
+	val[0] = swab32(value & 0xffffffffULL);
+	val[1] = swab32(value >> 32ULL);
+
+	return regmap_bulk_write(dev->regmap[2], reg, val, 2);
+}
+
 static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
 			      u8 *data)
 {
drivers/net/dsa/microchip/ksz_priv.h +1 -0
index beacf0e40f42..44c16aaf775c 100644
@@ -150,6 +150,7 @@ int ksz_switch_register(struct ksz_device *dev,
 			const struct ksz_dev_ops *ops);
 void ksz_switch_remove(struct ksz_device *dev);
 
+int ksz8795_switch_register(struct ksz_device *dev);
 int ksz9477_switch_register(struct ksz_device *dev);
 
 #endif
Signature · 1 line
2.20.1
maintainer
#4 lore raw

Re: [PATCH 3/3] net: dsa: ksz: Add Microchip KSZ8795 DSA driver

From: Marek Vasut <[email protected]>
Date: Wed, 24 Jul 2019 15:40:48 +0200

drivers/net/dsa/microchip/ksz8795.c line 128

Quoted 7 lines
drivers/net/dsa/microchip/ksz8795.c new file +7 -0
+static void ksz8795_r_mib_cnt(struct ksz_device *dev, int port, u16 addr,
+			      u64 *cnt)
+{
+	u32 data;
+	u16 ctrl_addr;
+	u8 check;
+	int loop;

Reverse christmas tree for these local variable declarations.

drivers/net/dsa/microchip/ksz8795.c line 159

Quoted 7 lines
drivers/net/dsa/microchip/ksz8795.c new file +7 -0
+static void ksz8795_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
+			      u64 *dropped, u64 *cnt)
+{
+	u32 data;
+	u16 ctrl_addr;
+	u8 check;
+	int loop;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 297

Quoted 9 lines
drivers/net/dsa/microchip/ksz8795.c new file +9 -0
+static int ksz8795_r_dyn_mac_table(struct ksz_device *dev, u16 addr,
+				   u8 *mac_addr, u8 *fid, u8 *src_port,
+				   u8 *timestamp, u16 *entries)
+{
+	u32 data_hi;
+	u32 data_lo;
+	u16 ctrl_addr;
+	int rc;
+	u8 data;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 352

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static int ksz8795_r_sta_mac_table(struct ksz_device *dev, u16 addr,
+				   struct alu_struct *alu)
+{
+	u64 data;
+	u32 data_hi;
+	u32 data_lo;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 382

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static void ksz8795_w_sta_mac_table(struct ksz_device *dev, u16 addr,
+				    struct alu_struct *alu)
+{
+	u64 data;
+	u32 data_hi;
+	u32 data_lo;

Likewise.

Quoted 1 line

+static inline void ksz8795_from_vlan(u16 vlan, u8 *fid, u8 *member, u8 *valid)

Never use the inline directive in foo.c files, let the compiler decide.

Quoted 1 line

+static inline void ksz8795_to_vlan(u8 fid, u8 member, u8 valid, u16 *vlan)

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 438

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static void ksz8795_r_vlan_table(struct ksz_device *dev, u16 vid, u16 *vlan)
+{
+	u64 buf;
+	u16 *data = (u16 *)&buf;
+	u16 addr;
+	int index;

Reverse christmas tree please.

drivers/net/dsa/microchip/ksz8795.c line 451

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static void ksz8795_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan)
+{
+	u64 buf;
+	u16 *data = (u16 *)&buf;
+	u16 addr;
+	int index;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 470

Quoted 10 lines
drivers/net/dsa/microchip/ksz8795.c new file +10 -0
+static void ksz8795_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
+{
+	struct ksz_port *port;
+	u8 ctrl;
+	u8 restart;
+	u8 link;
+	u8 speed;
+	u8 p = phy;
+	u16 data = 0;
+	int processed = true;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 563

Quoted 7 lines
drivers/net/dsa/microchip/ksz8795.c new file +7 -0
+static void ksz8795_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
+{
+	u8 ctrl;
+	u8 restart;
+	u8 speed;
+	u8 data;
+	u8 p = phy;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 698

Quoted 8 lines
drivers/net/dsa/microchip/ksz8795.c new file +8 -0
+static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port,
+				       u8 state)
+{
+	struct ksz_device *dev = ds->priv;
+	struct ksz_port *p = &dev->ports[port];
+	u8 data;
+	int member = -1;
+	int forward = dev->member;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 778

Quoted 7 lines
drivers/net/dsa/microchip/ksz8795.c new file +7 -0
+static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
+{
+	struct ksz_port *p;
+	int cnt;
+	int first;
+	int index;
+	u8 learn[TOTAL_PORT_NUM];

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 827

Quoted 11 lines
drivers/net/dsa/microchip/ksz8795.c new file +11 -0
+static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
+				  const struct switchdev_obj_port_vlan *vlan)
+{
+	struct ksz_device *dev = ds->priv;
+	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
+	u16 data;
+	u16 vid;
+	u8 fid;
+	u8 member;
+	u8 valid;
+	u16 new_pvid = 0;

Likewise. And seriously, combine all of the same typed variables onto one line to compress the space a bit:

	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	struct ksz_device *dev = ds->priv;
	u16 data, vid, new_pvid = 0;
	u8 fid, member, valid;

Doesn't that look like 1,000 times nicer? :-)

drivers/net/dsa/microchip/ksz8795.c line 870

Quoted 12 lines
drivers/net/dsa/microchip/ksz8795.c new file +12 -0
+static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port,
+				 const struct switchdev_obj_port_vlan *vlan)
+{
+	struct ksz_device *dev = ds->priv;
+	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
+	u16 data;
+	u16 vid;
+	u16 pvid;
+	u8 fid;
+	u8 member;
+	u8 valid;
+	u16 new_pvid = 0;

Again, same thing.

drivers/net/dsa/microchip/ksz8795.c line 963

Quoted 5 lines
drivers/net/dsa/microchip/ksz8795.c new file +5 -0
+static void ksz8795_port_setup(struct ksz_device *dev, int port, bool cpu_port)
+{
+	u8 data8;
+	u8 member;
+	struct ksz_port *p = &dev->ports[port];

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 1033

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static void ksz8795_config_cpu_port(struct dsa_switch *ds)
+{
+	struct ksz_device *dev = ds->priv;
+	struct ksz_port *p;
+	int i;
+	u8 remote;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 1088

Quoted 9 lines
drivers/net/dsa/microchip/ksz8795.c new file +9 -0
+static int ksz8795_setup(struct dsa_switch *ds)
+{
+	u8 data8;
+	u16 data16;
+	u32 value;
+	int i;
+	struct alu_struct alu;
+	struct ksz_device *dev = ds->priv;
+	int ret = 0;

Likewise.

drivers/net/dsa/microchip/ksz8795.c line 1193

Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c new file +6 -0
+static int ksz8795_switch_detect(struct ksz_device *dev)
+{
+	u16 id16;
+	u8 id1;
+	u8 id2;
+	int ret;

Likewise.

maintainer
#5 lore raw

Re: [PATCH 3/3] net: dsa: ksz: Add Microchip KSZ8795 DSA driver

In reply to Marek Vasut

drivers/net/dsa/microchip/ksz8795.c line 957

Quoted 12 lines · Marek Vasut

From: Tristram Ha <[email protected]>

drivers/net/dsa/microchip/ksz8795.c new file +11 -0
+static void ksz8795_phy_setup(struct ksz_device *dev, int port,
+			      struct phy_device *phy)
+{
+	if (port < dev->phy_port_cnt) {
+		/*
+		 * SUPPORTED_Asym_Pause and SUPPORTED_Pause can be removed to
+		 * disable flow control when rate limiting is used.
+		 */
+		linkmode_copy(phy->advertising, phy->supported);
+	}
+}

Hi Marek

Do you know why this is needed?

Thanks
Andrew

#6 lore raw

Re: [PATCH 3/3] net: dsa: ksz: Add Microchip KSZ8795 DSA driver

Quoted 16 lines · Andrew Lunn

drivers/net/dsa/microchip/ksz8795.c line 957

Quoted 12 lines · Marek Vasut

From: Tristram Ha <[email protected]>

drivers/net/dsa/microchip/ksz8795.c new file +11 -0
+static void ksz8795_phy_setup(struct ksz_device *dev, int port,
+			      struct phy_device *phy)
+{
+	if (port < dev->phy_port_cnt) {
+		/*
+		 * SUPPORTED_Asym_Pause and SUPPORTED_Pause can be removed to
+		 * disable flow control when rate limiting is used.
+		 */
+		linkmode_copy(phy->advertising, phy->supported);
+	}
+}

Hi Marek

Quoted 1 line

Do you know why this is needed?

Unfortunately, no.

It seems it copies supported features of the PHY to advertised features of the PHY for ports which are downstream (i.e. not the CPU port).

maintainer
#7 lore raw

Re: [PATCH 3/3] net: dsa: ksz: Add Microchip KSZ8795 DSA driver

Quoted 17 lines · Marek Vasut
Quoted 16 lines · Andrew Lunn

drivers/net/dsa/microchip/ksz8795.c line 957

Quoted 12 lines · Marek Vasut

From: Tristram Ha <[email protected]>

drivers/net/dsa/microchip/ksz8795.c new file +11 -0
+static void ksz8795_phy_setup(struct ksz_device *dev, int port,
+			      struct phy_device *phy)
+{
+	if (port < dev->phy_port_cnt) {
+		/*
+		 * SUPPORTED_Asym_Pause and SUPPORTED_Pause can be removed to
+		 * disable flow control when rate limiting is used.
+		 */
+		linkmode_copy(phy->advertising, phy->supported);
+	}
+}

Hi Marek

Quoted 6 lines
Quoted 1 line

Do you know why this is needed?

Unfortunately, no.

It seems it copies supported features of the PHY to advertised features of the PHY for ports which are downstream (i.e. not the CPU port).

Hi Marek

Could you test it without this copy? Do you get sensible values from ethtool? Does the pause configuration look sensible?

Thanks
Andrew

#8 lore raw

Re: [PATCH 3/3] net: dsa: ksz: Add Microchip KSZ8795 DSA driver

Quoted 22 lines · Andrew Lunn
Quoted 21 lines · Marek Vasut
Quoted 16 lines · Andrew Lunn

drivers/net/dsa/microchip/ksz8795.c line 957

Quoted 12 lines · Marek Vasut

From: Tristram Ha <[email protected]>

drivers/net/dsa/microchip/ksz8795.c new file +11 -0
+static void ksz8795_phy_setup(struct ksz_device *dev, int port,
+			      struct phy_device *phy)
+{
+	if (port < dev->phy_port_cnt) {
+		/*
+		 * SUPPORTED_Asym_Pause and SUPPORTED_Pause can be removed to
+		 * disable flow control when rate limiting is used.
+		 */
+		linkmode_copy(phy->advertising, phy->supported);
+	}
+}

Hi Marek

Quoted 1 line

Do you know why this is needed?

Unfortunately, no.

Quoted 7 lines
Quoted 2 lines

It seems it copies supported features of the PHY to advertised features of the PHY for ports which are downstream (i.e. not the CPU port).

Hi Marek

Could you test it without this copy? Do you get sensible values from ethtool? Does the pause configuration look sensible?

They do look OK even without the code.