ethernet/atheros: use core min/max MTU checking
[platform/kernel/linux-starfive.git] / drivers / net / ethernet / atheros / atl1c / atl1c_main.c
index a3200ea..773d3b7 100644 (file)
@@ -519,6 +519,26 @@ static int atl1c_set_features(struct net_device *netdev,
        return 0;
 }
 
+static void atl1c_set_max_mtu(struct net_device *netdev)
+{
+       struct atl1c_adapter *adapter = netdev_priv(netdev);
+       struct atl1c_hw *hw = &adapter->hw;
+
+       switch (hw->nic_type) {
+       /* These (GbE) devices support jumbo packets, max_mtu 6122 */
+       case athr_l1c:
+       case athr_l1d:
+       case athr_l1d_2:
+               netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
+                                 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
+               break;
+       /* The 10/100 devices don't support jumbo packets, max_mtu 1500 */
+       default:
+               netdev->max_mtu = ETH_DATA_LEN;
+               break;
+       }
+}
+
 /**
  * atl1c_change_mtu - Change the Maximum Transfer Unit
  * @netdev: network interface device structure
@@ -529,22 +549,9 @@ static int atl1c_set_features(struct net_device *netdev,
 static int atl1c_change_mtu(struct net_device *netdev, int new_mtu)
 {
        struct atl1c_adapter *adapter = netdev_priv(netdev);
-       struct atl1c_hw *hw = &adapter->hw;
-       int old_mtu   = netdev->mtu;
-       int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
-
-       /* Fast Ethernet controller doesn't support jumbo packet */
-       if (((hw->nic_type == athr_l2c ||
-             hw->nic_type == athr_l2c_b ||
-             hw->nic_type == athr_l2c_b2) && new_mtu > ETH_DATA_LEN) ||
-             max_frame < ETH_ZLEN + ETH_FCS_LEN ||
-             max_frame > MAX_JUMBO_FRAME_SIZE) {
-               if (netif_msg_link(adapter))
-                       dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
-               return -EINVAL;
-       }
+
        /* set MTU */
-       if (old_mtu != new_mtu && netif_running(netdev)) {
+       if (netif_running(netdev)) {
                while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
                        msleep(1);
                netdev->mtu = new_mtu;
@@ -2511,6 +2518,7 @@ static int atl1c_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
 
        netdev->netdev_ops = &atl1c_netdev_ops;
        netdev->watchdog_timeo = AT_TX_WATCHDOG;
+       netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
        atl1c_set_ethtool_ops(netdev);
 
        /* TODO: add when ready */
@@ -2613,6 +2621,9 @@ static int atl1c_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                dev_err(&pdev->dev, "net device private data init failed\n");
                goto err_sw_init;
        }
+       /* set max MTU */
+       atl1c_set_max_mtu(netdev);
+
        atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE);
 
        /* Init GPHY as early as possible due to power saving issue  */