2022-11-10 12:39:20

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v4 0/4] net: dsa: microchip: add MTU support for KSZ8 series

changes v4:
- remove per port max_frame cache
- remove port variable for ksz88* variants
- add KSZ9563_CHIP_ID
- not start a new line with an operator

changes v3:
- rename KSZ8863_LEGAL_PACKET_SIZE -> KSZ8_LEGAL_PACKET_SIZE

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

Oleksij Rempel (4):
net: dsa: microchip: move max mtu to one location
net: dsa: microchip: do not store max MTU for all ports
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 | 53 ++++++++++++++++++++++++-
drivers/net/dsa/microchip/ksz8795_reg.h | 3 ++
drivers/net/dsa/microchip/ksz9477.c | 19 +++------
drivers/net/dsa/microchip/ksz9477.h | 1 -
drivers/net/dsa/microchip/ksz9477_reg.h | 2 -
drivers/net/dsa/microchip/ksz_common.c | 29 +++++++++++---
drivers/net/dsa/microchip/ksz_common.h | 13 +++++-
8 files changed, 95 insertions(+), 26 deletions(-)

--
2.30.2



2022-11-10 12:56:13

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v4 1/4] net: dsa: microchip: move max mtu to one location

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

Signed-off-by: Oleksij Rempel <[email protected]>
Tested-by: Arun Ramadoss <[email protected]> (KSZ9893 and LAN937x)
---
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 | 22 +++++++++++++++++-----
drivers/net/dsa/microchip/ksz_common.h | 3 ++-
5 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 0d6b40968657..602d00671bef 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 8c8db315317d..49a5a236d958 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,
@@ -2500,10 +2499,23 @@ 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 KSZ9563_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 c6726cbd5465..27c26ee15af4 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -322,7 +322,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,
@@ -588,6 +587,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


2022-11-10 12:59:19

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v4 3/4] net: dsa: microchip: add ksz_rmw8() function

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

Signed-off-by: Oleksij Rempel <[email protected]>
Acked-by: Arun Ramadoss <[email protected]>
---
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 61228be299f9..5f404a444ce1 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -454,6 +454,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


2022-11-10 13:27:25

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v4 2/4] net: dsa: microchip: do not store max MTU for all ports

If we have global MTU configuration, it is enough to configure it on CPU
port only.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/dsa/microchip/ksz9477.c | 14 +++++---------
drivers/net/dsa/microchip/ksz_common.h | 1 -
2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 602d00671bef..f6e7968ab105 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -45,19 +45,15 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset,

int ksz9477_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;
+ u16 frame_size;

- /* Cache the per-port MTU setting */
- dev->ports[port].max_frame = frame_size;
+ if (!dsa_is_cpu_port(dev->ds, port))
+ return 0;

- for (i = 0; i < dev->info->port_cnt; i++)
- max_frame = max(max_frame, dev->ports[i].max_frame);
+ frame_size = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;

return regmap_update_bits(dev->regmap[1], REG_SW_MTU__2,
- REG_SW_MTU_MASK, max_frame);
+ REG_SW_MTU_MASK, frame_size);
}

static int ksz9477_wait_vlan_ctrl_ready(struct ksz_device *dev)
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 27c26ee15af4..61228be299f9 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -95,7 +95,6 @@ struct ksz_port {

struct ksz_port_mib mib;
phy_interface_t interface;
- u16 max_frame;
u32 rgmii_tx_val;
u32 rgmii_rx_val;
struct ksz_device *ksz_dev;
--
2.30.2


2022-11-10 15:26:12

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net-next v4 1/4] net: dsa: microchip: move max mtu to one location



On 11/10/2022 4:22 AM, Oleksij Rempel wrote:
> There are no HW specific registers, so we can process all of them
> in one location.
>
> Signed-off-by: Oleksij Rempel <[email protected]>
> Tested-by: Arun Ramadoss <[email protected]> (KSZ9893 and LAN937x)

This looks good to me, just one nit see below

[snip]

> @@ -2500,10 +2499,23 @@ 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 KSZ9563_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;

Rename to KSZ_MAX_FRAME_SIZE to denote this is a common constant?

> + }
>
> - 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 c6726cbd5465..27c26ee15af4 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -322,7 +322,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,
> @@ -588,6 +587,8 @@ static inline int is_lan937x(struct ksz_device *dev)
>
> #define PORT_SRC_PHY_INT 1
>
> +#define KSZ9477_MAX_FRAME_SIZE 9000\

And here are as well.
--
Florian

2022-11-10 15:27:36

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net-next v4 3/4] net: dsa: microchip: add ksz_rmw8() function



On 11/10/2022 4:22 AM, Oleksij Rempel wrote:
> Add ksz_rmw8(), it will be used in the next patch.
>
> Signed-off-by: Oleksij Rempel <[email protected]>
> Acked-by: Arun Ramadoss <[email protected]>

Reviewed-by: Florian Fainelli <[email protected]>
--
Florian

2022-11-10 15:28:10

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net-next v4 2/4] net: dsa: microchip: do not store max MTU for all ports



On 11/10/2022 4:22 AM, Oleksij Rempel wrote:
> If we have global MTU configuration, it is enough to configure it on CPU
> port only.
>
> Signed-off-by: Oleksij Rempel <[email protected]>

Reviewed-by: Florian Fainelli <[email protected]>
--
Florian

2022-11-11 05:37:57

by Oleksij Rempel

[permalink] [raw]
Subject: Re: [PATCH net-next v4 1/4] net: dsa: microchip: move max mtu to one location

Hi Florian,

On Thu, Nov 10, 2022 at 06:42:03AM -0800, Florian Fainelli wrote:
>
>
> On 11/10/2022 4:22 AM, Oleksij Rempel wrote:
> > There are no HW specific registers, so we can process all of them
> > in one location.
> >
> > Signed-off-by: Oleksij Rempel <[email protected]>
> > Tested-by: Arun Ramadoss <[email protected]> (KSZ9893 and LAN937x)
>
> This looks good to me, just one nit see below
>
> [snip]
>
> > @@ -2500,10 +2499,23 @@ 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 KSZ9563_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;
>
> Rename to KSZ_MAX_FRAME_SIZE to denote this is a common constant?

This is not so common. This list is extended by the patch 4, with two
more types of switches with different max frame size.

Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |