netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/3] net: dsa: microchip: add MTU support for KSZ8 series
@ 2022-11-07 13:57 Oleksij Rempel
  2022-11-07 13:57 ` [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location Oleksij Rempel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Oleksij Rempel @ 2022-11-07 13:57 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, Arun.Ramadoss

changes v2:
- add ksz_rmw8() helper
- merge all max MTUs to one location

Oleksij Rempel (3):
  net: dsa: microchip: move max mtu to one location
  net: dsa: microchip: add ksz_rmw8() function
  net: dsa: microchip: ksz8: add MTU configuration support

 drivers/net/dsa/microchip/ksz8.h        |  1 +
 drivers/net/dsa/microchip/ksz8795.c     | 57 ++++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 ++
 drivers/net/dsa/microchip/ksz9477.c     |  5 ---
 drivers/net/dsa/microchip/ksz9477.h     |  1 -
 drivers/net/dsa/microchip/ksz9477_reg.h |  2 -
 drivers/net/dsa/microchip/ksz_common.c  | 28 +++++++++---
 drivers/net/dsa/microchip/ksz_common.h  | 12 +++++-
 8 files changed, 93 insertions(+), 16 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location
  2022-11-07 13:57 [PATCH net-next v2 0/3] net: dsa: microchip: add MTU support for KSZ8 series Oleksij Rempel
@ 2022-11-07 13:57 ` Oleksij Rempel
  2022-11-08  5:15   ` Arun.Ramadoss
  2022-11-07 13:57 ` [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function Oleksij Rempel
  2022-11-07 13:57 ` [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support Oleksij Rempel
  2 siblings, 1 reply; 7+ messages in thread
From: Oleksij Rempel @ 2022-11-07 13:57 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, Arun.Ramadoss

There are no HW specific registers, so we can process all of them
in one location.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c     |  5 -----
 drivers/net/dsa/microchip/ksz9477.h     |  1 -
 drivers/net/dsa/microchip/ksz9477_reg.h |  2 --
 drivers/net/dsa/microchip/ksz_common.c  | 21 ++++++++++++++++-----
 drivers/net/dsa/microchip/ksz_common.h  |  3 ++-
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index a6a0321a8931..e3adb126fdff 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -60,11 +60,6 @@ int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
 				  REG_SW_MTU_MASK, max_frame);
 }
 
-int ksz9477_max_mtu(struct ksz_device *dev, int port)
-{
-	return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
-}
-
 static int ksz9477_wait_vlan_ctrl_ready(struct ksz_device *dev)
 {
 	unsigned int val;
diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h
index 00862c4cfb7f..7c5bb3032772 100644
--- a/drivers/net/dsa/microchip/ksz9477.h
+++ b/drivers/net/dsa/microchip/ksz9477.h
@@ -50,7 +50,6 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,
 int ksz9477_mdb_del(struct ksz_device *dev, int port,
 		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
 int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu);
-int ksz9477_max_mtu(struct ksz_device *dev, int port);
 void ksz9477_config_cpu_port(struct dsa_switch *ds);
 int ksz9477_enable_stp_addr(struct ksz_device *dev);
 int ksz9477_reset_switch(struct ksz_device *dev);
diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h
index 53c68d286dd3..cc457fa64939 100644
--- a/drivers/net/dsa/microchip/ksz9477_reg.h
+++ b/drivers/net/dsa/microchip/ksz9477_reg.h
@@ -1615,6 +1615,4 @@
 #define PTP_TRIG_UNIT_M			(BIT(MAX_TRIG_UNIT) - 1)
 #define PTP_TS_UNIT_M			(BIT(MAX_TIMESTAMP_UNIT) - 1)
 
-#define KSZ9477_MAX_FRAME_SIZE		9000
-
 #endif /* KSZ9477_REGS_H */
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index d612181b3226..486ad03d0acf 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -14,6 +14,7 @@
 #include <linux/phy.h>
 #include <linux/etherdevice.h>
 #include <linux/if_bridge.h>
+#include <linux/if_vlan.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/of_mdio.h>
@@ -206,7 +207,6 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mdb_add = ksz9477_mdb_add,
 	.mdb_del = ksz9477_mdb_del,
 	.change_mtu = ksz9477_change_mtu,
-	.max_mtu = ksz9477_max_mtu,
 	.phylink_mac_link_up = ksz9477_phylink_mac_link_up,
 	.config_cpu_port = ksz9477_config_cpu_port,
 	.enable_stp_addr = ksz9477_enable_stp_addr,
@@ -243,7 +243,6 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
 	.mdb_add = ksz9477_mdb_add,
 	.mdb_del = ksz9477_mdb_del,
 	.change_mtu = lan937x_change_mtu,
-	.max_mtu = ksz9477_max_mtu,
 	.phylink_mac_link_up = ksz9477_phylink_mac_link_up,
 	.config_cpu_port = lan937x_config_cpu_port,
 	.enable_stp_addr = ksz9477_enable_stp_addr,
@@ -2473,10 +2472,22 @@ static int ksz_max_mtu(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
 
-	if (!dev->dev_ops->max_mtu)
-		return -EOPNOTSUPP;
+	switch (dev->chip_id) {
+	case KSZ8563_CHIP_ID:
+	case KSZ9477_CHIP_ID:
+	case KSZ9567_CHIP_ID:
+	case KSZ9893_CHIP_ID:
+	case KSZ9896_CHIP_ID:
+	case KSZ9897_CHIP_ID:
+	case LAN9370_CHIP_ID:
+	case LAN9371_CHIP_ID:
+	case LAN9372_CHIP_ID:
+	case LAN9373_CHIP_ID:
+	case LAN9374_CHIP_ID:
+		return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
+	}
 
-	return dev->dev_ops->max_mtu(dev, port);
+	return -EOPNOTSUPP;
 }
 
 static void ksz_set_xmii(struct ksz_device *dev, int port,
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 9cfa179575ce..7de5070637ec 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -320,7 +320,6 @@ struct ksz_dev_ops {
 	void (*get_caps)(struct ksz_device *dev, int port,
 			 struct phylink_config *config);
 	int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
-	int (*max_mtu)(struct ksz_device *dev, int port);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	void (*phylink_mac_config)(struct ksz_device *dev, int port,
@@ -585,6 +584,8 @@ static inline int is_lan937x(struct ksz_device *dev)
 
 #define PORT_SRC_PHY_INT		1
 
+#define KSZ9477_MAX_FRAME_SIZE		9000
+
 /* Regmap tables generation */
 #define KSZ_SPI_OP_RD		3
 #define KSZ_SPI_OP_WR		2
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function
  2022-11-07 13:57 [PATCH net-next v2 0/3] net: dsa: microchip: add MTU support for KSZ8 series Oleksij Rempel
  2022-11-07 13:57 ` [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location Oleksij Rempel
@ 2022-11-07 13:57 ` Oleksij Rempel
  2022-11-08  5:19   ` Arun.Ramadoss
  2022-11-07 13:57 ` [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support Oleksij Rempel
  2 siblings, 1 reply; 7+ messages in thread
From: Oleksij Rempel @ 2022-11-07 13:57 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, Arun.Ramadoss

Add ksz_rmw8(), it will be used in the next patch.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 7de5070637ec..85ce6ec573ba 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -453,6 +453,11 @@ static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
 	return regmap_bulk_write(dev->regmap[2], reg, val, 2);
 }
 
+static inline int ksz_rmw8(struct ksz_device *dev, int offset, u8 mask, u8 val)
+{
+	return regmap_update_bits(dev->regmap[0], offset, mask, val);
+}
+
 static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
 			     u8 *data)
 {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support
  2022-11-07 13:57 [PATCH net-next v2 0/3] net: dsa: microchip: add MTU support for KSZ8 series Oleksij Rempel
  2022-11-07 13:57 ` [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location Oleksij Rempel
  2022-11-07 13:57 ` [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function Oleksij Rempel
@ 2022-11-07 13:57 ` Oleksij Rempel
  2022-11-08  5:28   ` Arun.Ramadoss
  2 siblings, 1 reply; 7+ messages in thread
From: Oleksij Rempel @ 2022-11-07 13:57 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev, Arun.Ramadoss

Make MTU configurable on KSZ87xx and KSZ88xx series of switches.

Before this patch, pre-configured behavior was different on different
switch series, due to opposite meaning of the same bit:
- KSZ87xx: Reg 4, Bit 1 - if 1, max frame size is 1532; if 0 - 1514
- KSZ88xx: Reg 4, Bit 1 - if 1, max frame size is 1514; if 0 - 1532

Since the code was telling "... SW_LEGAL_PACKET_DISABLE, true)", I
assume, the idea was to set max frame size to 1532.

With this patch, by setting MTU size 1500, both switch series will be
configured to the 1532 frame limit.

This patch was tested on KSZ8873.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8.h        |  1 +
 drivers/net/dsa/microchip/ksz8795.c     | 57 ++++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 ++
 drivers/net/dsa/microchip/ksz_common.c  |  7 +++
 drivers/net/dsa/microchip/ksz_common.h  |  4 ++
 5 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h
index 8582b4b67d98..ea05abfbd51d 100644
--- a/drivers/net/dsa/microchip/ksz8.h
+++ b/drivers/net/dsa/microchip/ksz8.h
@@ -57,5 +57,6 @@ int ksz8_reset_switch(struct ksz_device *dev);
 int ksz8_switch_detect(struct ksz_device *dev);
 int ksz8_switch_init(struct ksz_device *dev);
 void ksz8_switch_exit(struct ksz_device *dev);
+int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu);
 
 #endif
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index bd3b133e7085..804f421d1829 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -76,6 +76,61 @@ int ksz8_reset_switch(struct ksz_device *dev)
 	return 0;
 }
 
+static int ksz8863_change_mtu(struct ksz_device *dev, int port, int max_frame)
+{
+	u8 ctrl2 = 0;
+
+	if (max_frame <= KSZ8863_LEGAL_PACKET_SIZE)
+		ctrl2 |= KSZ8863_LEGAL_PACKET_ENABLE;
+	else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE)
+		ctrl2 |= KSZ8863_HUGE_PACKET_ENABLE;
+
+	return ksz_rmw8(dev, REG_SW_CTRL_2, KSZ8863_LEGAL_PACKET_ENABLE
+			| KSZ8863_HUGE_PACKET_ENABLE, ctrl2);
+}
+
+static int ksz8795_change_mtu(struct ksz_device *dev, int port, int max_frame)
+{
+	u8 ctrl1 = 0, ctrl2 = 0;
+	int ret;
+
+	if (max_frame > KSZ8863_LEGAL_PACKET_SIZE)
+		ctrl2 |= SW_LEGAL_PACKET_DISABLE;
+	else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE)
+		ctrl1 |= SW_HUGE_PACKET;
+
+	ret = ksz_rmw8(dev, REG_SW_CTRL_1, SW_HUGE_PACKET, ctrl1);
+	if (ret)
+		return ret;
+
+	return ksz_rmw8(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, ctrl2);
+}
+
+int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu)
+{
+	u16 frame_size, max_frame = 0;
+	int i;
+
+	frame_size = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
+
+	/* Cache the per-port MTU setting */
+	dev->ports[port].max_frame = frame_size;
+
+	for (i = 0; i < dev->info->port_cnt; i++)
+		max_frame = max(max_frame, dev->ports[i].max_frame);
+
+	switch (dev->chip_id) {
+	case KSZ8795_CHIP_ID:
+	case KSZ8794_CHIP_ID:
+	case KSZ8765_CHIP_ID:
+		return ksz8795_change_mtu(dev, port, max_frame);
+	case KSZ8830_CHIP_ID:
+		return ksz8863_change_mtu(dev, port, max_frame);
+	}
+
+	return -EOPNOTSUPP;
+}
+
 static void ksz8795_set_prio_queue(struct ksz_device *dev, int port, int queue)
 {
 	u8 hi, lo;
@@ -1233,8 +1288,6 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)
 	masks = dev->info->masks;
 	regs = dev->info->regs;
 
-	/* Switch marks the maximum frame with extra byte as oversize. */
-	ksz_cfg(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, true);
 	ksz_cfg(dev, regs[S_TAIL_TAG_CTRL], masks[SW_TAIL_TAG_ENABLE], true);
 
 	p = &dev->ports[dev->cpu_port];
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 77487d611824..7a57c6088f80 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -48,6 +48,9 @@
 #define NO_EXC_COLLISION_DROP		BIT(3)
 #define SW_LEGAL_PACKET_DISABLE		BIT(1)
 
+#define KSZ8863_HUGE_PACKET_ENABLE	BIT(2)
+#define KSZ8863_LEGAL_PACKET_ENABLE	BIT(1)
+
 #define REG_SW_CTRL_3			0x05
  #define WEIGHTED_FAIR_QUEUE_ENABLE	BIT(3)
 
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 486ad03d0acf..188c66145df7 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -172,6 +172,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.reset = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
+	.change_mtu = ksz8_change_mtu,
 };
 
 static void ksz9477_phylink_mac_link_up(struct ksz_device *dev, int port,
@@ -2473,6 +2474,12 @@ static int ksz_max_mtu(struct dsa_switch *ds, int port)
 	struct ksz_device *dev = ds->priv;
 
 	switch (dev->chip_id) {
+	case KSZ8795_CHIP_ID:
+	case KSZ8794_CHIP_ID:
+	case KSZ8765_CHIP_ID:
+		return KSZ8795_HUGE_PACKET_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
+	case KSZ8830_CHIP_ID:
+		return KSZ8863_HUGE_PACKET_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
 	case KSZ8563_CHIP_ID:
 	case KSZ9477_CHIP_ID:
 	case KSZ9567_CHIP_ID:
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 85ce6ec573ba..17a13fd3b92e 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -589,6 +589,10 @@ static inline int is_lan937x(struct ksz_device *dev)
 
 #define PORT_SRC_PHY_INT		1
 
+#define KSZ8795_HUGE_PACKET_SIZE	2000
+#define KSZ8863_HUGE_PACKET_SIZE	1916
+#define KSZ8863_NORMAL_PACKET_SIZE	1536
+#define KSZ8863_LEGAL_PACKET_SIZE	1518
 #define KSZ9477_MAX_FRAME_SIZE		9000
 
 /* Regmap tables generation */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location
  2022-11-07 13:57 ` [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location Oleksij Rempel
@ 2022-11-08  5:15   ` Arun.Ramadoss
  0 siblings, 0 replies; 7+ messages in thread
From: Arun.Ramadoss @ 2022-11-08  5:15 UTC (permalink / raw)
  To: olteanv, UNGLinuxDriver, vivien.didelot, andrew, f.fainelli,
	kuba, edumazet, pabeni, o.rempel, Woojung.Huh, davem
  Cc: linux-kernel, netdev, kernel

On Mon, 2022-11-07 at 14:57 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> There are no HW specific registers, so we can process all of them
> in one location.

Tested in KSZ9893 and LAN937x by changing the mtu to max_mtu using
ifconfig. It works fine.

> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz9477.c     |  5 -----
>  drivers/net/dsa/microchip/ksz9477.h     |  1 -
>  drivers/net/dsa/microchip/ksz9477_reg.h |  2 --
>  drivers/net/dsa/microchip/ksz_common.c  | 21 ++++++++++++++++-----
>  drivers/net/dsa/microchip/ksz_common.h  |  3 ++-
>  5 files changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477.c
> b/drivers/net/dsa/microchip/ksz9477.c
> index a6a0321a8931..e3adb126fdff 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -60,11 +60,6 @@ int ksz9477_change_mtu(struct ksz_device *dev, int
> port, int mtu)
>                                   REG_SW_MTU_MASK, max_frame);
>  }
> 
> -int ksz9477_max_mtu(struct ksz_device *dev, int port)
> -{
> -       return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
> -}
> -
>  static int ksz9477_wait_vlan_ctrl_ready(struct ksz_device *dev)
>  {
>         unsigned int val;
> diff --git a/drivers/net/dsa/microchip/ksz9477.h
> b/drivers/net/dsa/microchip/ksz9477.h
> index 00862c4cfb7f..7c5bb3032772 100644
> --- a/drivers/net/dsa/microchip/ksz9477.h
> +++ b/drivers/net/dsa/microchip/ksz9477.h
> @@ -50,7 +50,6 @@ int ksz9477_mdb_add(struct ksz_device *dev, int
> port,
>  int ksz9477_mdb_del(struct ksz_device *dev, int port,
>                     const struct switchdev_obj_port_mdb *mdb, struct
> dsa_db db);
>  int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu);
> -int ksz9477_max_mtu(struct ksz_device *dev, int port);
>  void ksz9477_config_cpu_port(struct dsa_switch *ds);
>  int ksz9477_enable_stp_addr(struct ksz_device *dev);
>  int ksz9477_reset_switch(struct ksz_device *dev);
> diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h
> b/drivers/net/dsa/microchip/ksz9477_reg.h
> index 53c68d286dd3..cc457fa64939 100644
> --- a/drivers/net/dsa/microchip/ksz9477_reg.h
> +++ b/drivers/net/dsa/microchip/ksz9477_reg.h
> @@ -1615,6 +1615,4 @@
>  #define PTP_TRIG_UNIT_M                        (BIT(MAX_TRIG_UNIT) -
> 1)
>  #define PTP_TS_UNIT_M                  (BIT(MAX_TIMESTAMP_UNIT) - 1)
> 
> -#define KSZ9477_MAX_FRAME_SIZE         9000
> -
>  #endif /* KSZ9477_REGS_H */
> diff --git a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index d612181b3226..486ad03d0acf 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -14,6 +14,7 @@
>  #include <linux/phy.h>
>  #include <linux/etherdevice.h>
>  #include <linux/if_bridge.h>
> +#include <linux/if_vlan.h>
>  #include <linux/irq.h>
>  #include <linux/irqdomain.h>
>  #include <linux/of_mdio.h>
> @@ -206,7 +207,6 @@ static const struct ksz_dev_ops ksz9477_dev_ops =
> {
>         .mdb_add = ksz9477_mdb_add,
>         .mdb_del = ksz9477_mdb_del,
>         .change_mtu = ksz9477_change_mtu,
> -       .max_mtu = ksz9477_max_mtu,
>         .phylink_mac_link_up = ksz9477_phylink_mac_link_up,
>         .config_cpu_port = ksz9477_config_cpu_port,
>         .enable_stp_addr = ksz9477_enable_stp_addr,
> @@ -243,7 +243,6 @@ static const struct ksz_dev_ops lan937x_dev_ops =
> {
>         .mdb_add = ksz9477_mdb_add,
>         .mdb_del = ksz9477_mdb_del,
>         .change_mtu = lan937x_change_mtu,
> -       .max_mtu = ksz9477_max_mtu,
>         .phylink_mac_link_up = ksz9477_phylink_mac_link_up,
>         .config_cpu_port = lan937x_config_cpu_port,
>         .enable_stp_addr = ksz9477_enable_stp_addr,
> @@ -2473,10 +2472,22 @@ static int ksz_max_mtu(struct dsa_switch *ds,
> int port)
>  {
>         struct ksz_device *dev = ds->priv;
> 
> -       if (!dev->dev_ops->max_mtu)
> -               return -EOPNOTSUPP;
> +       switch (dev->chip_id) {
> +       case KSZ8563_CHIP_ID:
> +       case KSZ9477_CHIP_ID:
> +       case KSZ9567_CHIP_ID:
> +       case KSZ9893_CHIP_ID:
> +       case KSZ9896_CHIP_ID:
> +       case KSZ9897_CHIP_ID:
> +       case LAN9370_CHIP_ID:
> +       case LAN9371_CHIP_ID:
> +       case LAN9372_CHIP_ID:
> +       case LAN9373_CHIP_ID:
> +       case LAN9374_CHIP_ID:
> +               return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN -
> ETH_FCS_LEN;
> +       }
> 
> -       return dev->dev_ops->max_mtu(dev, port);
> +       return -EOPNOTSUPP;
>  }
> 
>  static void ksz_set_xmii(struct ksz_device *dev, int port,
> diff --git a/drivers/net/dsa/microchip/ksz_common.h
> b/drivers/net/dsa/microchip/ksz_common.h
> index 9cfa179575ce..7de5070637ec 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -320,7 +320,6 @@ struct ksz_dev_ops {
>         void (*get_caps)(struct ksz_device *dev, int port,
>                          struct phylink_config *config);
>         int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
> -       int (*max_mtu)(struct ksz_device *dev, int port);
>         void (*freeze_mib)(struct ksz_device *dev, int port, bool
> freeze);
>         void (*port_init_cnt)(struct ksz_device *dev, int port);
>         void (*phylink_mac_config)(struct ksz_device *dev, int port,
> @@ -585,6 +584,8 @@ static inline int is_lan937x(struct ksz_device
> *dev)
> 
>  #define PORT_SRC_PHY_INT               1
> 
> +#define KSZ9477_MAX_FRAME_SIZE         9000
> +
>  /* Regmap tables generation */
>  #define KSZ_SPI_OP_RD          3
>  #define KSZ_SPI_OP_WR          2
> --
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function
  2022-11-07 13:57 ` [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function Oleksij Rempel
@ 2022-11-08  5:19   ` Arun.Ramadoss
  0 siblings, 0 replies; 7+ messages in thread
From: Arun.Ramadoss @ 2022-11-08  5:19 UTC (permalink / raw)
  To: olteanv, UNGLinuxDriver, vivien.didelot, andrew, f.fainelli,
	kuba, edumazet, pabeni, o.rempel, Woojung.Huh, davem
  Cc: linux-kernel, netdev, kernel

On Mon, 2022-11-07 at 14:57 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Add ksz_rmw8(), it will be used in the next patch.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz_common.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.h
> b/drivers/net/dsa/microchip/ksz_common.h
> index 7de5070637ec..85ce6ec573ba 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -453,6 +453,11 @@ static inline int ksz_write64(struct ksz_device
> *dev, u32 reg, u64 value)
>         return regmap_bulk_write(dev->regmap[2], reg, val, 2);
>  }
> 
> +static inline int ksz_rmw8(struct ksz_device *dev, int offset, u8
> mask, u8 val)
> +{
> +       return regmap_update_bits(dev->regmap[0], offset, mask, val);
> +}
> +

Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com>

>  static inline int ksz_pread8(struct ksz_device *dev, int port, int
> offset,
>                              u8 *data)
>  {
> --
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support
  2022-11-07 13:57 ` [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support Oleksij Rempel
@ 2022-11-08  5:28   ` Arun.Ramadoss
  0 siblings, 0 replies; 7+ messages in thread
From: Arun.Ramadoss @ 2022-11-08  5:28 UTC (permalink / raw)
  To: olteanv, UNGLinuxDriver, vivien.didelot, andrew, f.fainelli,
	kuba, edumazet, pabeni, o.rempel, Woojung.Huh, davem
  Cc: linux-kernel, netdev, kernel

On Mon, 2022-11-07 at 14:57 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> Make MTU configurable on KSZ87xx and KSZ88xx series of switches.
> 
> Before this patch, pre-configured behavior was different on different
> switch series, due to opposite meaning of the same bit:
> - KSZ87xx: Reg 4, Bit 1 - if 1, max frame size is 1532; if 0 - 1514
> - KSZ88xx: Reg 4, Bit 1 - if 1, max frame size is 1514; if 0 - 1532
> 
> Since the code was telling "... SW_LEGAL_PACKET_DISABLE, true)", I
> assume, the idea was to set max frame size to 1532.
> 
> With this patch, by setting MTU size 1500, both switch series will be
> configured to the 1532 frame limit.
> 
> This patch was tested on KSZ8873.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz8.h        |  1 +
>  drivers/net/dsa/microchip/ksz8795.c     | 57
> ++++++++++++++++++++++++-
>  drivers/net/dsa/microchip/ksz8795_reg.h |  3 ++
>  drivers/net/dsa/microchip/ksz_common.c  |  7 +++
>  drivers/net/dsa/microchip/ksz_common.h  |  4 ++
>  5 files changed, 70 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8.h
> b/drivers/net/dsa/microchip/ksz8.h
> index 8582b4b67d98..ea05abfbd51d 100644
> --- a/drivers/net/dsa/microchip/ksz8.h
> +++ b/drivers/net/dsa/microchip/ksz8.h
> @@ -57,5 +57,6 @@ int ksz8_reset_switch(struct ksz_device *dev);
>  int ksz8_switch_detect(struct ksz_device *dev);
>  int ksz8_switch_init(struct ksz_device *dev);
>  void ksz8_switch_exit(struct ksz_device *dev);
> +int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu);
> 
>  #endif
> diff --git a/drivers/net/dsa/microchip/ksz8795.c
> b/drivers/net/dsa/microchip/ksz8795.c
> index bd3b133e7085..804f421d1829 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -76,6 +76,61 @@ int ksz8_reset_switch(struct ksz_device *dev)
>         return 0;
>  }
> 
> +static int ksz8863_change_mtu(struct ksz_device *dev, int port, int
> max_frame)
> +{
> +       u8 ctrl2 = 0;
> +
> +       if (max_frame <= KSZ8863_LEGAL_PACKET_SIZE)
> +               ctrl2 |= KSZ8863_LEGAL_PACKET_ENABLE;
> +       else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE)
> +               ctrl2 |= KSZ8863_HUGE_PACKET_ENABLE;
> +
> +       return ksz_rmw8(dev, REG_SW_CTRL_2,
> KSZ8863_LEGAL_PACKET_ENABLE
> +                       | KSZ8863_HUGE_PACKET_ENABLE, ctrl2);
> +}
> +
> +static int ksz8795_change_mtu(struct ksz_device *dev, int port, int
> max_frame)
> +{
> +       u8 ctrl1 = 0, ctrl2 = 0;
> +       int ret;
> +
> +       if (max_frame > KSZ8863_LEGAL_PACKET_SIZE)
> +               ctrl2 |= SW_LEGAL_PACKET_DISABLE;
> +       else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE)
> +               ctrl1 |= SW_HUGE_PACKET;
Suggestion:
Since we are using the macro KSZ8863_LEGAL_PACKET_SIZE for ksz8795 as
well, it will be good to have common name for macro like
KSZ8_LEGAL_PACKET_SIZE which will avoid the confusion later.

> +
> +       ret = ksz_rmw8(dev, REG_SW_CTRL_1, SW_HUGE_PACKET, ctrl1);
> +       if (ret)
> +               return ret;
> +
> +       return ksz_rmw8(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE,
> ctrl2);
> +}
> +
> +int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu)
> +{
> +       u16 frame_size, max_frame = 0;
> +       int i;
> +
> +       frame_size = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
> +
> +       /* Cache the per-port MTU setting */
> +       dev->ports[port].max_frame = frame_size;
> +
> +       for (i = 0; i < dev->info->port_cnt; i++)
> +               max_frame = max(max_frame, dev->ports[i].max_frame);
> +
> +       switch (dev->chip_id) {
> +       case KSZ8795_CHIP_ID:
> +       case KSZ8794_CHIP_ID:
> +       case KSZ8765_CHIP_ID:
> +               return ksz8795_change_mtu(dev, port, max_frame);
> +       case KSZ8830_CHIP_ID:
> +               return ksz8863_change_mtu(dev, port, max_frame);
> +       }
> +
> +       return -EOPNOTSUPP;
> +}
> +
>  static void ksz8795_set_prio_queue(struct ksz_device *dev, int port,
> int queue)
>  {
>         u8 hi, lo;
> @@ -1233,8 +1288,6 @@ void ksz8_config_cpu_port(struct dsa_switch
> *ds)
>         masks = dev->info->masks;
>         regs = dev->info->regs;
> 
> -       /* Switch marks the maximum frame with extra byte as
> oversize. */
> -       ksz_cfg(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, true);
>         ksz_cfg(dev, regs[S_TAIL_TAG_CTRL],
> masks[SW_TAIL_TAG_ENABLE], true);
> 
>         p = &dev->ports[dev->cpu_port];
> diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h
> b/drivers/net/dsa/microchip/ksz8795_reg.h
> index 77487d611824..7a57c6088f80 100644
> --- a/drivers/net/dsa/microchip/ksz8795_reg.h
> +++ b/drivers/net/dsa/microchip/ksz8795_reg.h
> @@ -48,6 +48,9 @@
>  #define NO_EXC_COLLISION_DROP          BIT(3)
>  #define SW_LEGAL_PACKET_DISABLE                BIT(1)
> 
> +#define KSZ8863_HUGE_PACKET_ENABLE     BIT(2)
> +#define KSZ8863_LEGAL_PACKET_ENABLE    BIT(1)
> +
>  #define REG_SW_CTRL_3                  0x05
>   #define WEIGHTED_FAIR_QUEUE_ENABLE    BIT(3)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index 486ad03d0acf..188c66145df7 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -172,6 +172,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
>         .reset = ksz8_reset_switch,
>         .init = ksz8_switch_init,
>         .exit = ksz8_switch_exit,
> +       .change_mtu = ksz8_change_mtu,
>  };
> 
>  static void ksz9477_phylink_mac_link_up(struct ksz_device *dev, int
> port,
> @@ -2473,6 +2474,12 @@ static int ksz_max_mtu(struct dsa_switch *ds,
> int port)
>         struct ksz_device *dev = ds->priv;
> 
>         switch (dev->chip_id) {
> +       case KSZ8795_CHIP_ID:
> +       case KSZ8794_CHIP_ID:
> +       case KSZ8765_CHIP_ID:
> +               return KSZ8795_HUGE_PACKET_SIZE - VLAN_ETH_HLEN -
> ETH_FCS_LEN;
> +       case KSZ8830_CHIP_ID:
> +               return KSZ8863_HUGE_PACKET_SIZE - VLAN_ETH_HLEN -
> ETH_FCS_LEN;
>         case KSZ8563_CHIP_ID:
>         case KSZ9477_CHIP_ID:
>         case KSZ9567_CHIP_ID:
> diff --git a/drivers/net/dsa/microchip/ksz_common.h
> b/drivers/net/dsa/microchip/ksz_common.h
> index 85ce6ec573ba..17a13fd3b92e 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -589,6 +589,10 @@ static inline int is_lan937x(struct ksz_device
> *dev)
> 
>  #define PORT_SRC_PHY_INT               1
> 
> +#define KSZ8795_HUGE_PACKET_SIZE       2000
> +#define KSZ8863_HUGE_PACKET_SIZE       1916
> +#define KSZ8863_NORMAL_PACKET_SIZE     1536
> +#define KSZ8863_LEGAL_PACKET_SIZE      1518
>  #define KSZ9477_MAX_FRAME_SIZE         9000
> 
>  /* Regmap tables generation */
> --
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-08  5:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 13:57 [PATCH net-next v2 0/3] net: dsa: microchip: add MTU support for KSZ8 series Oleksij Rempel
2022-11-07 13:57 ` [PATCH net-next v2 1/3] net: dsa: microchip: move max mtu to one location Oleksij Rempel
2022-11-08  5:15   ` Arun.Ramadoss
2022-11-07 13:57 ` [PATCH net-next v2 2/3] net: dsa: microchip: add ksz_rmw8() function Oleksij Rempel
2022-11-08  5:19   ` Arun.Ramadoss
2022-11-07 13:57 ` [PATCH net-next v2 3/3] net: dsa: microchip: ksz8: add MTU configuration support Oleksij Rempel
2022-11-08  5:28   ` Arun.Ramadoss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).