Skip to content

Commit

Permalink
ethernet: use core min/max MTU checking
Browse files Browse the repository at this point in the history
et131x: min_mtu 64, max_mtu 9216

altera_tse: min_mtu 64, max_mtu 1500

amd8111e: min_mtu 60, max_mtu 9000

bnad: min_mtu 46, max_mtu 9000

macb: min_mtu 68, max_mtu 1500 or 10240 depending on hardware capability

xgmac: min_mtu 46, max_mtu 9000

cxgb2: min_mtu 68, max_mtu 9582 (pm3393) or 9600 (vsc7326)

enic: min_mtu 68, max_mtu 9000

gianfar: min_mtu 50, max_mu 9586

hns_enet: min_mtu 68, max_mtu 9578 (v1) or 9706 (v2)

ksz884x: min_mtu 60, max_mtu 1894

myri10ge: min_mtu 68, max_mtu 9000

natsemi: min_mtu 64, max_mtu 2024

nfp: min_mtu 68, max_mtu hardware-specific

forcedeth: min_mtu 64, max_mtu 1500 or 9100, depending on hardware

pch_gbe: min_mtu 46, max_mtu 10300

pasemi_mac: min_mtu 64, max_mtu 9000

qcaspi: min_mtu 46, max_mtu 1500
- remove qcaspi_netdev_change_mtu as it is now redundant

rocker: min_mtu 68, max_mtu 9000

sxgbe: min_mtu 68, max_mtu 9000

stmmac: min_mtu 46, max_mtu depends on hardware

tehuti: min_mtu 60, max_mtu 16384
- driver had no max mtu checking, but product docs say 16k jumbo packets
  are supported by the hardware

netcp: min_mtu 68, max_mtu 9486
- remove netcp_ndo_change_mtu as it is now redundant

via-velocity: min_mtu 64, max_mtu 9000

octeon: min_mtu 46, max_mtu 65370

CC: [email protected]
CC: Mark Einon <[email protected]>
CC: Vince Bridgers <[email protected]>
CC: Rasesh Mody <[email protected]>
CC: Nicolas Ferre <[email protected]>
CC: Santosh Raspatur <[email protected]>
CC: Hariprasad S <[email protected]>
CC:  Christian Benvenuti <[email protected]>
CC: Sujith Sankar <[email protected]>
CC: Govindarajulu Varadarajan <[email protected]>
CC: Neel Patel <[email protected]>
CC: Claudiu Manoil <[email protected]>
CC: Yisen Zhuang <[email protected]>
CC: Salil Mehta <[email protected]>
CC: Hyong-Youb Kim <[email protected]>
CC: Jakub Kicinski <[email protected]>
CC: Olof Johansson <[email protected]>
CC: Jiri Pirko <[email protected]>
CC: Byungho An <[email protected]>
CC: Girish K S <[email protected]>
CC: Vipul Pandya <[email protected]>
CC: Giuseppe Cavallaro <[email protected]>
CC: Alexandre Torgue <[email protected]>
CC: Andy Gospodarek <[email protected]>
CC: Wingman Kwok <[email protected]>
CC: Murali Karicheri <[email protected]>
CC: Francois Romieu <[email protected]>
Signed-off-by: Jarod Wilson <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jarodwilson authored and davem330 committed Oct 18, 2016
1 parent 1281a2c commit 44770e1
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 222 deletions.
7 changes: 4 additions & 3 deletions drivers/net/ethernet/agere/et131x.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S
#define NUM_FBRS 2

#define MAX_PACKETS_HANDLED 256
#define ET131X_MIN_MTU 64
#define ET131X_MAX_MTU 9216

#define ALCATEL_MULTICAST_PKT 0x01000000
#define ALCATEL_BROADCAST_PKT 0x02000000
Expand Down Expand Up @@ -3869,9 +3871,6 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu)
int result = 0;
struct et131x_adapter *adapter = netdev_priv(netdev);

if (new_mtu < 64 || new_mtu > 9216)
return -EINVAL;

et131x_disable_txrx(netdev);

netdev->mtu = new_mtu;
Expand Down Expand Up @@ -3958,6 +3957,8 @@ static int et131x_pci_setup(struct pci_dev *pdev,

netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
netdev->netdev_ops = &et131x_netdev_ops;
netdev->min_mtu = ET131X_MIN_MTU;
netdev->max_mtu = ET131X_MAX_MTU;

SET_NETDEV_DEV(netdev, &pdev->dev);
netdev->ethtool_ops = &et131x_ethtool_ops;
Expand Down
1 change: 0 additions & 1 deletion drivers/net/ethernet/altera/altera_tse.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ struct altera_tse_private {
/* RX/TX MAC FIFO configs */
u32 tx_fifo_depth;
u32 rx_fifo_depth;
u32 max_mtu;

/* Hash filter settings */
u32 hash_filter;
Expand Down
14 changes: 3 additions & 11 deletions drivers/net/ethernet/altera/altera_tse_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,20 +994,11 @@ static void tse_set_mac(struct altera_tse_private *priv, bool enable)
*/
static int tse_change_mtu(struct net_device *dev, int new_mtu)
{
struct altera_tse_private *priv = netdev_priv(dev);
unsigned int max_mtu = priv->max_mtu;
unsigned int min_mtu = ETH_ZLEN + ETH_FCS_LEN;

if (netif_running(dev)) {
netdev_err(dev, "must be stopped to change its MTU\n");
return -EBUSY;
}

if ((new_mtu < min_mtu) || (new_mtu > max_mtu)) {
netdev_err(dev, "invalid MTU, max MTU is: %u\n", max_mtu);
return -EINVAL;
}

dev->mtu = new_mtu;
netdev_update_features(dev);

Expand Down Expand Up @@ -1446,15 +1437,16 @@ static int altera_tse_probe(struct platform_device *pdev)
of_property_read_bool(pdev->dev.of_node,
"altr,has-supplementary-unicast");

priv->dev->min_mtu = ETH_ZLEN + ETH_FCS_LEN;
/* Max MTU is 1500, ETH_DATA_LEN */
priv->max_mtu = ETH_DATA_LEN;
priv->dev->max_mtu = ETH_DATA_LEN;

/* Get the max mtu from the device tree. Note that the
* "max-frame-size" parameter is actually max mtu. Definition
* in the ePAPR v1.1 spec and usage differ, so go with usage.
*/
of_property_read_u32(pdev->dev.of_node, "max-frame-size",
&priv->max_mtu);
&priv->dev->max_mtu);

/* The DMA buffer size already accounts for an alignment bias
* to avoid unaligned access exceptions for the NIOS processor,
Expand Down
5 changes: 2 additions & 3 deletions drivers/net/ethernet/amd/amd8111e.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,9 +1556,6 @@ static int amd8111e_change_mtu(struct net_device *dev, int new_mtu)
struct amd8111e_priv *lp = netdev_priv(dev);
int err;

if ((new_mtu < AMD8111E_MIN_MTU) || (new_mtu > AMD8111E_MAX_MTU))
return -EINVAL;

if (!netif_running(dev)) {
/* new_mtu will be used
* when device starts netxt time
Expand Down Expand Up @@ -1874,6 +1871,8 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
dev->ethtool_ops = &ops;
dev->irq =pdev->irq;
dev->watchdog_timeo = AMD8111E_TX_TIMEOUT;
dev->min_mtu = AMD8111E_MIN_MTU;
dev->max_mtu = AMD8111E_MAX_MTU;
netif_napi_add(dev, &lp->napi, amd8111e_rx_poll, 32);

#if AMD8111E_VLAN_TAG_USED
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/ethernet/brocade/bna/bnad.c
Original file line number Diff line number Diff line change
Expand Up @@ -3296,9 +3296,6 @@ bnad_change_mtu(struct net_device *netdev, int new_mtu)
struct bnad *bnad = netdev_priv(netdev);
u32 rx_count = 0, frame, new_frame;

if (new_mtu + ETH_HLEN < ETH_ZLEN || new_mtu > BNAD_JUMBO_MTU)
return -EINVAL;

mutex_lock(&bnad->conf_mutex);

mtu = netdev->mtu;
Expand Down Expand Up @@ -3465,6 +3462,10 @@ bnad_netdev_init(struct bnad *bnad, bool using_dac)
netdev->mem_start = bnad->mmio_start;
netdev->mem_end = bnad->mmio_start + bnad->mmio_len - 1;

/* MTU range: 46 - 9000 */
netdev->min_mtu = ETH_ZLEN - ETH_HLEN;
netdev->max_mtu = BNAD_JUMBO_MTU;

netdev->netdev_ops = &bnad_netdev_ops;
bnad_set_ethtool_ops(netdev);
}
Expand Down
19 changes: 8 additions & 11 deletions drivers/net/ethernet/cadence/macb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define MACB_MAX_TX_LEN ((unsigned int)((1 << MACB_TX_FRMLEN_SIZE) - 1))
#define GEM_MAX_TX_LEN ((unsigned int)((1 << GEM_TX_FRMLEN_SIZE) - 1))

#define GEM_MTU_MIN_SIZE 68
#define GEM_MTU_MIN_SIZE ETH_MIN_MTU

#define MACB_WOL_HAS_MAGIC_PACKET (0x1 << 0)
#define MACB_WOL_ENABLED (0x1 << 1)
Expand Down Expand Up @@ -1986,19 +1986,9 @@ static int macb_close(struct net_device *dev)

static int macb_change_mtu(struct net_device *dev, int new_mtu)
{
struct macb *bp = netdev_priv(dev);
u32 max_mtu;

if (netif_running(dev))
return -EBUSY;

max_mtu = ETH_DATA_LEN;
if (bp->caps & MACB_CAPS_JUMBO)
max_mtu = gem_readl(bp, JML) - ETH_HLEN - ETH_FCS_LEN;

if ((new_mtu > max_mtu) || (new_mtu < GEM_MTU_MIN_SIZE))
return -EINVAL;

dev->mtu = new_mtu;

return 0;
Expand Down Expand Up @@ -3027,6 +3017,13 @@ static int macb_probe(struct platform_device *pdev)
goto err_out_free_netdev;
}

/* MTU range: 68 - 1500 or 10240 */
dev->min_mtu = GEM_MTU_MIN_SIZE;
if (bp->caps & MACB_CAPS_JUMBO)
dev->max_mtu = gem_readl(bp, JML) - ETH_HLEN - ETH_FCS_LEN;
else
dev->max_mtu = ETH_DATA_LEN;

mac = of_get_mac_address(np);
if (mac)
ether_addr_copy(bp->dev->dev_addr, mac);
Expand Down
20 changes: 5 additions & 15 deletions drivers/net/ethernet/calxeda/xgmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct xgmac_priv {
};

/* XGMAC Configuration Settings */
#define MAX_MTU 9000
#define XGMAC_MAX_MTU 9000
#define PAUSE_TIME 0x400

#define DMA_RX_RING_SZ 256
Expand Down Expand Up @@ -1360,20 +1360,6 @@ static void xgmac_set_rx_mode(struct net_device *dev)
*/
static int xgmac_change_mtu(struct net_device *dev, int new_mtu)
{
struct xgmac_priv *priv = netdev_priv(dev);
int old_mtu;

if ((new_mtu < 46) || (new_mtu > MAX_MTU)) {
netdev_err(priv->dev, "invalid MTU, max MTU is: %d\n", MAX_MTU);
return -EINVAL;
}

old_mtu = dev->mtu;

/* return early if the buffer sizes will not change */
if (old_mtu == new_mtu)
return 0;

/* Stop everything, get ready to change the MTU */
if (!netif_running(dev))
return 0;
Expand Down Expand Up @@ -1804,6 +1790,10 @@ static int xgmac_probe(struct platform_device *pdev)
ndev->features |= ndev->hw_features;
ndev->priv_flags |= IFF_UNICAST_FLT;

/* MTU range: 46 - 9000 */
ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
ndev->max_mtu = XGMAC_MAX_MTU;

/* Get the MAC address */
xgmac_get_mac_addr(priv->base, ndev->dev_addr, 0);
if (!is_valid_ether_addr(ndev->dev_addr))
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/ethernet/chelsio/cxgb/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ struct t1_rx_mode {
#define SPEED_INVALID 0xffff
#define DUPLEX_INVALID 0xff

/* Max frame size PM3393 can handle. Includes Ethernet header and CRC. */
#define PM3393_MAX_FRAME_SIZE 9600

#define VSC7326_MAX_MTU 9600

enum {
CHBT_BOARD_N110,
CHBT_BOARD_N210,
Expand Down
18 changes: 16 additions & 2 deletions drivers/net/ethernet/chelsio/cxgb/cxgb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,6 @@ static int t1_change_mtu(struct net_device *dev, int new_mtu)

if (!mac->ops->set_mtu)
return -EOPNOTSUPP;
if (new_mtu < 68)
return -EINVAL;
if ((ret = mac->ops->set_mtu(mac, new_mtu)))
return ret;
dev->mtu = new_mtu;
Expand Down Expand Up @@ -1101,6 +1099,22 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
netif_napi_add(netdev, &adapter->napi, t1_poll, 64);

netdev->ethtool_ops = &t1_ethtool_ops;

switch (bi->board) {
case CHBT_BOARD_CHT110:
case CHBT_BOARD_N110:
case CHBT_BOARD_N210:
case CHBT_BOARD_CHT210:
netdev->max_mtu = PM3393_MAX_FRAME_SIZE -
(ETH_HLEN + ETH_FCS_LEN);
break;
case CHBT_BOARD_CHN204:
netdev->max_mtu = VSC7326_MAX_MTU;
break;
default:
netdev->max_mtu = ETH_DATA_LEN;
break;
}
}

if (t1_init_sw_modules(adapter, bi) < 0) {
Expand Down
8 changes: 1 addition & 7 deletions drivers/net/ethernet/chelsio/cxgb/pm3393.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@

#define OFFSET(REG_ADDR) ((REG_ADDR) << 2)

/* Max frame size PM3393 can handle. Includes Ethernet header and CRC. */
#define MAX_FRAME_SIZE 9600

#define IPG 12
#define TXXG_CONF1_VAL ((IPG << SUNI1x10GEXP_BITOFF_TXXG_IPGT) | \
SUNI1x10GEXP_BITMSK_TXXG_32BIT_ALIGN | SUNI1x10GEXP_BITMSK_TXXG_CRCEN | \
Expand Down Expand Up @@ -331,10 +328,7 @@ static int pm3393_set_mtu(struct cmac *cmac, int mtu)
{
int enabled = cmac->instance->enabled;

/* MAX_FRAME_SIZE includes header + FCS, mtu doesn't */
mtu += 14 + 4;
if (mtu > MAX_FRAME_SIZE)
return -EINVAL;
mtu += ETH_HLEN + ETH_FCS_LEN;

/* Disable Rx/Tx MAC before configuring it. */
if (enabled)
Expand Down
5 changes: 0 additions & 5 deletions drivers/net/ethernet/chelsio/cxgb/vsc7326.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
/* 30 minutes for full statistics update */
#define MAJOR_UPDATE_TICKS (1800 / STATS_TICK_SECS)

#define MAX_MTU 9600

/* The egress WM value 0x01a01fff should be used only when the
* interface is down (MAC port disabled). This is a workaround
* for disabling the T2/MAC flow-control. When the interface is
Expand Down Expand Up @@ -452,9 +450,6 @@ static int mac_set_mtu(struct cmac *mac, int mtu)
{
int port = mac->instance->index;

if (mtu > MAX_MTU)
return -EINVAL;

/* max_len includes header and FCS */
vsc_write(mac->adapter, REG_MAX_LEN(port), mtu + 14 + 4);
return 0;
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/ethernet/cisco/enic/enic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,9 +1843,6 @@ static int enic_change_mtu(struct net_device *netdev, int new_mtu)
struct enic *enic = netdev_priv(netdev);
int running = netif_running(netdev);

if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
return -EINVAL;

if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic))
return -EOPNOTSUPP;

Expand Down Expand Up @@ -2751,6 +2748,10 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

netdev->priv_flags |= IFF_UNICAST_FLT;

/* MTU range: 68 - 9000 */
netdev->min_mtu = ENIC_MIN_MTU;
netdev->max_mtu = ENIC_MAX_MTU;

err = register_netdev(netdev);
if (err) {
dev_err(dev, "Cannot register net device, aborting\n");
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/cisco/enic/enic_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define ENIC_MIN_RQ_DESCS 64
#define ENIC_MAX_RQ_DESCS 4096

#define ENIC_MIN_MTU 68
#define ENIC_MIN_MTU ETH_MIN_MTU
#define ENIC_MAX_MTU 9000

#define ENIC_MULTICAST_PERFECT_FILTERS 32
Expand Down
9 changes: 3 additions & 6 deletions drivers/net/ethernet/freescale/gianfar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,10 @@ static int gfar_probe(struct platform_device *ofdev)

/* Fill in the dev structure */
dev->watchdog_timeo = TX_TIMEOUT;
/* MTU range: 50 - 9586 */
dev->mtu = 1500;
dev->min_mtu = 50;
dev->max_mtu = GFAR_JUMBO_FRAME_SIZE - ETH_HLEN;
dev->netdev_ops = &gfar_netdev_ops;
dev->ethtool_ops = &gfar_ethtool_ops;

Expand Down Expand Up @@ -2592,12 +2595,6 @@ static int gfar_set_mac_address(struct net_device *dev)
static int gfar_change_mtu(struct net_device *dev, int new_mtu)
{
struct gfar_private *priv = netdev_priv(dev);
int frame_size = new_mtu + ETH_HLEN;

if ((frame_size < 64) || (frame_size > GFAR_JUMBO_FRAME_SIZE)) {
netif_err(priv, drv, dev, "Invalid MTU setting\n");
return -EINVAL;
}

while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
cpu_relax();
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ int hns_mac_set_mtu(struct hns_mac_cb *mac_cb, u32 new_mtu)
if (mac_cb->mac_type == HNAE_PORT_DEBUG)
max_frm = MAC_MAX_MTU_DBG;

if ((new_mtu < MAC_MIN_MTU) || (new_frm > max_frm) ||
(new_frm > HNS_RCB_RING_MAX_BD_PER_PKT * buf_size))
if (new_frm > HNS_RCB_RING_MAX_BD_PER_PKT * buf_size)
return -EINVAL;

if (!drv->config_max_frame_length)
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/ethernet/hisilicon/hns/hns_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "hnae.h"
#include "hns_enet.h"
#include "hns_dsaf_mac.h"

#define NIC_MAX_Q_PER_VF 16
#define HNS_NIC_TX_TIMEOUT (5 * HZ)
Expand Down Expand Up @@ -1405,10 +1406,6 @@ static int hns_nic_change_mtu(struct net_device *ndev, int new_mtu)
struct hnae_handle *h = priv->ae_handle;
int ret;

/* MTU < 68 is an error and causes problems on some kernels */
if (new_mtu < 68)
return -EINVAL;

if (!h->dev->ops->set_mtu)
return -ENOTSUPP;

Expand Down Expand Up @@ -1953,14 +1950,20 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM;
ndev->vlan_features |= NETIF_F_SG | NETIF_F_GSO | NETIF_F_GRO;

/* MTU range: 68 - 9578 (v1) or 9706 (v2) */
ndev->min_mtu = MAC_MIN_MTU;
switch (priv->enet_ver) {
case AE_VERSION_2:
ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6;
ndev->max_mtu = MAC_MAX_MTU_V2 -
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
break;
default:
ndev->max_mtu = MAC_MAX_MTU -
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
break;
}

Expand Down
Loading

0 comments on commit 44770e1

Please sign in to comment.