ethernet/atheros: use core min/max MTU checking
atl2: min_mtu 40, max_mtu 1504 - Remove a few redundant defines that already have equivalents in if_ether.h. atl1: min_mtu 42, max_mtu 10218 atl1e: min_mtu 42, max_mtu 8170 atl1c: min_mtu 42, max_mtu 6122/1500 - GbE hardware gets a max_mtu of 6122, slower hardware gets 1500. alx: min_mtu 34, max_mtu 9256 - Not so sure that minimum MTU number is really what was intended, but that's what the math actually makes it out to be, due to max_frame manipulations and comparison in alx_change_mtu, rather than just comparing new_mtu. (I think 68 was the intended min_mtu value). CC: netdev@vger.kernel.org CC: Jay Cliburn <jcliburn@gmail.com> CC: Chris Snook <chris.snook@gmail.com> Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
60d2d8dd9e
commit
67bef94280
@@ -2701,23 +2701,15 @@ static void atl1_reset_dev_task(struct work_struct *work)
|
||||
static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
|
||||
{
|
||||
struct atl1_adapter *adapter = netdev_priv(netdev);
|
||||
int old_mtu = netdev->mtu;
|
||||
int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
|
||||
|
||||
if ((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;
|
||||
}
|
||||
|
||||
adapter->hw.max_frame_size = max_frame;
|
||||
adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3;
|
||||
adapter->rx_buffer_len = (max_frame + 7) & ~7;
|
||||
adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8;
|
||||
|
||||
netdev->mtu = new_mtu;
|
||||
if ((old_mtu != new_mtu) && netif_running(netdev)) {
|
||||
if (netif_running(netdev)) {
|
||||
atl1_down(adapter);
|
||||
atl1_up(adapter);
|
||||
}
|
||||
@@ -3031,6 +3023,11 @@ static int atl1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
/* is this valid? see atl1_setup_mac_ctrl() */
|
||||
netdev->features |= NETIF_F_RXCSUM;
|
||||
|
||||
/* MTU range: 42 - 10218 */
|
||||
netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
|
||||
netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
|
||||
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
|
||||
|
||||
/*
|
||||
* patch for some L1 of old version,
|
||||
* the final version of L1 may not need these
|
||||
|
@@ -253,7 +253,7 @@ static int atl2_configure(struct atl2_adapter *adapter)
|
||||
|
||||
/* set MTU */
|
||||
ATL2_WRITE_REG(hw, REG_MTU, adapter->netdev->mtu +
|
||||
ENET_HEADER_SIZE + VLAN_SIZE + ETHERNET_FCS_SIZE);
|
||||
ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
|
||||
|
||||
/* 1590 */
|
||||
ATL2_WRITE_REG(hw, REG_TX_CUT_THRESH, 0x177);
|
||||
@@ -925,15 +925,11 @@ static int atl2_change_mtu(struct net_device *netdev, int new_mtu)
|
||||
struct atl2_adapter *adapter = netdev_priv(netdev);
|
||||
struct atl2_hw *hw = &adapter->hw;
|
||||
|
||||
if ((new_mtu < 40) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE)))
|
||||
return -EINVAL;
|
||||
|
||||
/* set MTU */
|
||||
if (hw->max_frame_size != new_mtu) {
|
||||
netdev->mtu = new_mtu;
|
||||
ATL2_WRITE_REG(hw, REG_MTU, new_mtu + ENET_HEADER_SIZE +
|
||||
VLAN_SIZE + ETHERNET_FCS_SIZE);
|
||||
}
|
||||
netdev->mtu = new_mtu;
|
||||
hw->max_frame_size = new_mtu;
|
||||
ATL2_WRITE_REG(hw, REG_MTU, new_mtu + ETH_HLEN +
|
||||
VLAN_HLEN + ETH_FCS_LEN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1398,6 +1394,8 @@ static int atl2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
netdev->netdev_ops = &atl2_netdev_ops;
|
||||
netdev->ethtool_ops = &atl2_ethtool_ops;
|
||||
netdev->watchdog_timeo = 5 * HZ;
|
||||
netdev->min_mtu = 40;
|
||||
netdev->max_mtu = ETH_DATA_LEN + VLAN_HLEN;
|
||||
strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
|
||||
|
||||
netdev->mem_start = mmio_start;
|
||||
|
@@ -228,12 +228,9 @@ static void atl2_force_ps(struct atl2_hw *hw);
|
||||
#define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x000F /* Everything */
|
||||
|
||||
/* The size (in bytes) of a ethernet packet */
|
||||
#define ENET_HEADER_SIZE 14
|
||||
#define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* with FCS */
|
||||
#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* with FCS */
|
||||
#define ETHERNET_FCS_SIZE 4
|
||||
#define MAX_JUMBO_FRAME_SIZE 0x2000
|
||||
#define VLAN_SIZE 4
|
||||
|
||||
struct tx_pkt_header {
|
||||
unsigned pkt_size:11;
|
||||
|
Reference in New Issue
Block a user