]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: dsa: microchip: lan937x: add MTU and fast_age support
authorArun Ramadoss <arun.ramadoss@microchip.com>
Fri, 1 Jul 2022 15:09:54 +0000 (20:39 +0530)
committerDavid S. Miller <davem@davemloft.net>
Sat, 2 Jul 2022 15:34:05 +0000 (16:34 +0100)
This patch add the support for port_max_mtu, port_change_mtu and
port_fast_age dsa functionality.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/microchip/ksz_common.c
drivers/net/dsa/microchip/lan937x.h
drivers/net/dsa/microchip/lan937x_main.c
drivers/net/dsa/microchip/lan937x_reg.h

index 67bb4bff4d9b1fbdf827f29a7854e9ec6c34b432..fb0de48a3f5e51ab119ba1c76311658c0043ff7c 100644 (file)
@@ -206,6 +206,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
        .setup = lan937x_setup,
        .get_port_addr = ksz9477_get_port_addr,
        .cfg_port_member = ksz9477_cfg_port_member,
+       .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
        .port_setup = lan937x_port_setup,
        .r_phy = lan937x_r_phy,
        .w_phy = lan937x_w_phy,
@@ -224,6 +225,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
        .fdb_del = ksz9477_fdb_del,
        .mdb_add = ksz9477_mdb_add,
        .mdb_del = ksz9477_mdb_del,
+       .change_mtu = lan937x_change_mtu,
        .max_mtu = ksz9477_max_mtu,
        .config_cpu_port = lan937x_config_cpu_port,
        .enable_stp_addr = ksz9477_enable_stp_addr,
index 370203406a057d10b1a87624b415c211c2dd2ee6..50563874600dd30703ffd654dccf47775c63bc87 100644 (file)
@@ -14,4 +14,5 @@ int lan937x_switch_init(struct ksz_device *dev);
 void lan937x_switch_exit(struct ksz_device *dev);
 void lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
 void lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
+int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu);
 #endif
index 7090947cf52c90c1ebfde5c53f4e98fad8ba058f..5917cc11ba59f82ac65150a7cba2611f5c77418a 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/of_net.h>
 #include <linux/of_mdio.h>
 #include <linux/if_bridge.h>
+#include <linux/if_vlan.h>
 #include <linux/math.h>
 #include <net/dsa.h>
 #include <net/switchdev.h>
@@ -284,6 +285,33 @@ void lan937x_config_cpu_port(struct dsa_switch *ds)
        }
 }
 
+int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu)
+{
+       struct dsa_switch *ds = dev->ds;
+       int ret;
+
+       new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN;
+
+       if (dsa_is_cpu_port(ds, port))
+               new_mtu += LAN937X_TAG_LEN;
+
+       if (new_mtu >= FR_MIN_SIZE)
+               ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0,
+                                      PORT_JUMBO_PACKET, true);
+       else
+               ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0,
+                                      PORT_JUMBO_PACKET, false);
+       if (ret < 0) {
+               dev_err(ds->dev, "failed to enable jumbo\n");
+               return ret;
+       }
+
+       /* Write the frame size in PORT_MAX_FR_SIZE register */
+       ksz_pwrite16(dev, port, PORT_MAX_FR_SIZE, new_mtu);
+
+       return 0;
+}
+
 int lan937x_setup(struct dsa_switch *ds)
 {
        struct ksz_device *dev = ds->priv;
index 7a0fa25959506efe2fcf58b02f80ae3fc590260c..19f3aa3442289cf56e25ccd885a26cfd24bee310 100644 (file)
 #define PORT_BACK_PRESSURE             BIT(3)
 #define PORT_PASS_ALL                  BIT(0)
 
+#define PORT_MAX_FR_SIZE               0x404
+#define FR_MIN_SIZE            1522
+
 /* 8 - Classification and Policing */
 #define REG_PORT_MRI_PRIO_CTRL         0x0801
 #define PORT_HIGHEST_PRIO              BIT(7)
 
 #define P_PRIO_CTRL                    REG_PORT_MRI_PRIO_CTRL
 
+#define LAN937X_TAG_LEN                        2
+
 #endif