Skip to content

Commit

Permalink
ethernet/realtek: use core min/max MTU checking
Browse files Browse the repository at this point in the history
8139cp: min_mtu 60, max_mtu 4096

8139too: min_mtu 68, max_mtu 1770

r8169: min_mtu 60, max_mtu depends on chipset, 1500 to 9k-ish

CC: netdev@vger.kernel.org
CC: Realtek linux nic maintainers <nic_swsd@realtek.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jarod Wilson authored and David S. Miller committed Oct 18, 2016
1 parent caff2a8 commit c7315a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions drivers/net/ethernet/realtek/8139cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,10 +1277,6 @@ static int cp_change_mtu(struct net_device *dev, int new_mtu)
{
struct cp_private *cp = netdev_priv(dev);

/* check for invalid MTU, according to hardware limits */
if (new_mtu < CP_MIN_MTU || new_mtu > CP_MAX_MTU)
return -EINVAL;

/* if network interface not up, no need for complexity */
if (!netif_running(dev)) {
dev->mtu = new_mtu;
Expand Down Expand Up @@ -2010,6 +2006,10 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
NETIF_F_HIGHDMA;

/* MTU range: 60 - 4096 */
dev->min_mtu = CP_MIN_MTU;
dev->max_mtu = CP_MAX_MTU;

rc = register_netdev(dev);
if (rc)
goto err_out_iomap;
Expand Down
13 changes: 4 additions & 9 deletions drivers/net/ethernet/realtek/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,19 +924,10 @@ static int rtl8139_set_features(struct net_device *dev, netdev_features_t featur
return 0;
}

static int rtl8139_change_mtu(struct net_device *dev, int new_mtu)
{
if (new_mtu < 68 || new_mtu > MAX_ETH_DATA_SIZE)
return -EINVAL;
dev->mtu = new_mtu;
return 0;
}

static const struct net_device_ops rtl8139_netdev_ops = {
.ndo_open = rtl8139_open,
.ndo_stop = rtl8139_close,
.ndo_get_stats64 = rtl8139_get_stats64,
.ndo_change_mtu = rtl8139_change_mtu,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = rtl8139_set_mac_address,
.ndo_start_xmit = rtl8139_start_xmit,
Expand Down Expand Up @@ -1022,6 +1013,10 @@ static int rtl8139_init_one(struct pci_dev *pdev,
dev->hw_features |= NETIF_F_RXALL;
dev->hw_features |= NETIF_F_RXFCS;

/* MTU range: 68 - 1770 */
dev->min_mtu = ETH_MIN_MTU;
dev->max_mtu = MAX_ETH_DATA_SIZE;

/* tp zeroed and aligned in alloc_etherdev */
tp = netdev_priv(dev);

Expand Down
8 changes: 4 additions & 4 deletions drivers/net/ethernet/realtek/r8169.c
Original file line number Diff line number Diff line change
Expand Up @@ -6673,10 +6673,6 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
{
struct rtl8169_private *tp = netdev_priv(dev);

if (new_mtu < ETH_ZLEN ||
new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max)
return -EINVAL;

if (new_mtu > ETH_DATA_LEN)
rtl_hw_jumbo_enable(tp);
else
Expand Down Expand Up @@ -8430,6 +8426,10 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
dev->hw_features |= NETIF_F_RXALL;
dev->hw_features |= NETIF_F_RXFCS;

/* MTU range: 60 - hw-specific max */
dev->min_mtu = ETH_ZLEN;
dev->max_mtu = rtl_chip_infos[chipset].jumbo_max;

tp->hw_start = cfg->hw_start;
tp->event_slow = cfg->event_slow;

Expand Down

0 comments on commit c7315a9

Please sign in to comment.