Skip to content

Commit

Permalink
Merge branch 'ethernet-use-core-min-max-mtu'
Browse files Browse the repository at this point in the history
Jarod Wilson says:

====================
ethernet: use core min/max MTU checking

Now that the network stack core min/max MTU checking infrastructure is in
place, time to start making drivers use it. We'll start with the easiest
ones, the ethernet drivers, split roughly by vendor, with a catch-all
patch at the end.

For the most part, every patch does the same essential thing: removes the
MTU range checking from the drivers' ndo_change_mtu function, puts those
ranges into the core net_device min_mtu and max_mtu fields, and where
possible, removes ndo_change_mtu functions entirely.

These patches have all been built through the 0-day build infrastructure
provided by Intel, on top of net-next as of October 17.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 18, 2016
2 parents 60d2d8d + 44770e1 commit 1441dc9
Show file tree
Hide file tree
Showing 102 changed files with 480 additions and 744 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
1 change: 0 additions & 1 deletion drivers/net/ethernet/atheros/alx/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ struct alx_rrd {
#define ALX_MAX_JUMBO_PKT_SIZE (9*1024)
#define ALX_MAX_TSO_PKT_SIZE (7*1024)
#define ALX_MAX_FRAME_SIZE ALX_MAX_JUMBO_PKT_SIZE
#define ALX_MIN_FRAME_SIZE (ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN)

#define ALX_MAX_RX_QUEUES 8
#define ALX_MAX_TX_QUEUES 4
Expand Down
10 changes: 3 additions & 7 deletions drivers/net/ethernet/atheros/alx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@ static int alx_init_sw(struct alx_priv *alx)
hw->smb_timer = 400;
hw->mtu = alx->dev->mtu;
alx->rxbuf_size = ALX_MAX_FRAME_LEN(hw->mtu);
/* MTU range: 34 - 9256 */
alx->dev->min_mtu = 34;
alx->dev->max_mtu = ALX_MAX_FRAME_LEN(ALX_MAX_FRAME_SIZE);
alx->tx_ringsz = 256;
alx->rx_ringsz = 512;
hw->imt = 200;
Expand Down Expand Up @@ -994,13 +997,6 @@ static int alx_change_mtu(struct net_device *netdev, int mtu)
struct alx_priv *alx = netdev_priv(netdev);
int max_frame = ALX_MAX_FRAME_LEN(mtu);

if ((max_frame < ALX_MIN_FRAME_SIZE) ||
(max_frame > ALX_MAX_FRAME_SIZE))
return -EINVAL;

if (netdev->mtu == mtu)
return 0;

netdev->mtu = mtu;
alx->hw.mtu = mtu;
alx->rxbuf_size = max(max_frame, ALX_DEF_RXBUF_SIZE);
Expand Down
41 changes: 26 additions & 15 deletions drivers/net/ethernet/atheros/atl1c/atl1c_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
12 changes: 5 additions & 7 deletions drivers/net/ethernet/atheros/atl1e/atl1e_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,10 @@ static int atl1e_set_features(struct net_device *netdev,
static int atl1e_change_mtu(struct net_device *netdev, int new_mtu)
{
struct atl1e_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)) {
netdev_warn(adapter->netdev, "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;
Expand Down Expand Up @@ -2272,6 +2266,10 @@ static int atl1e_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
netdev->netdev_ops = &atl1e_netdev_ops;

netdev->watchdog_timeo = AT_TX_WATCHDOG;
/* MTU range: 42 - 8170 */
netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
atl1e_set_ethtool_ops(netdev);

netdev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO |
Expand Down
15 changes: 6 additions & 9 deletions drivers/net/ethernet/atheros/atlx/atl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions drivers/net/ethernet/atheros/atlx/atl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/ethernet/atheros/atlx/atl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions drivers/net/ethernet/broadcom/b44.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
#define B44_TX_TIMEOUT (5 * HZ)

/* hardware minimum and maximum for a single frame's data payload */
#define B44_MIN_MTU 60
#define B44_MAX_MTU 1500
#define B44_MIN_MTU ETH_ZLEN
#define B44_MAX_MTU ETH_DATA_LEN

#define B44_RX_RING_SIZE 512
#define B44_DEF_RX_RING_PENDING 200
Expand Down Expand Up @@ -1064,9 +1064,6 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
{
struct b44 *bp = netdev_priv(dev);

if (new_mtu < B44_MIN_MTU || new_mtu > B44_MAX_MTU)
return -EINVAL;

if (!netif_running(dev)) {
/* We'll just catch it later when the
* device is up'd.
Expand Down Expand Up @@ -2377,6 +2374,8 @@ static int b44_init_one(struct ssb_device *sdev,
dev->netdev_ops = &b44_netdev_ops;
netif_napi_add(dev, &bp->napi, b44_poll, 64);
dev->watchdog_timeo = B44_TX_TIMEOUT;
dev->min_mtu = B44_MIN_MTU;
dev->max_mtu = B44_MAX_MTU;
dev->irq = sdev->irq;
dev->ethtool_ops = &b44_ethtool_ops;

Expand Down
Loading

0 comments on commit 1441dc9

Please sign in to comment.