net: dsa: Make dsa_master_set_mtu() static
[platform/kernel/linux-starfive.git] / net / dsa / master.c
index c90ee32..d7d5145 100644 (file)
@@ -158,8 +158,36 @@ static void dsa_master_ethtool_teardown(struct net_device *dev)
        cpu_dp->orig_ethtool_ops = NULL;
 }
 
+static void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp)
+{
+       unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead;
+       int err;
+
+       rtnl_lock();
+       if (mtu <= dev->max_mtu) {
+               err = dev_set_mtu(dev, mtu);
+               if (err)
+                       netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n");
+       }
+       rtnl_unlock();
+}
+
+static void dsa_master_reset_mtu(struct net_device *dev)
+{
+       int err;
+
+       rtnl_lock();
+       err = dev_set_mtu(dev, ETH_DATA_LEN);
+       if (err)
+               netdev_dbg(dev,
+                          "Unable to reset MTU to exclude DSA overheads\n");
+       rtnl_unlock();
+}
+
 int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
 {
+       dsa_master_set_mtu(dev,  cpu_dp);
+
        /* If we use a tagging format that doesn't have an ethertype
         * field, make sure that all packets from this point on get
         * sent to the tag format's receive function.
@@ -174,6 +202,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
 void dsa_master_teardown(struct net_device *dev)
 {
        dsa_master_ethtool_teardown(dev);
+       dsa_master_reset_mtu(dev);
 
        dev->dsa_ptr = NULL;