Skip to content

Commit 1441dc9

Browse files
committed
Merge branch 'ethernet-use-core-min-max-mtu'
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 <[email protected]>
2 parents 60d2d8d + 44770e1 commit 1441dc9

File tree

102 files changed

+480
-744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+480
-744
lines changed

drivers/net/ethernet/agere/et131x.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S
176176
#define NUM_FBRS 2
177177

178178
#define MAX_PACKETS_HANDLED 256
179+
#define ET131X_MIN_MTU 64
180+
#define ET131X_MAX_MTU 9216
179181

180182
#define ALCATEL_MULTICAST_PKT 0x01000000
181183
#define ALCATEL_BROADCAST_PKT 0x02000000
@@ -3869,9 +3871,6 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu)
38693871
int result = 0;
38703872
struct et131x_adapter *adapter = netdev_priv(netdev);
38713873

3872-
if (new_mtu < 64 || new_mtu > 9216)
3873-
return -EINVAL;
3874-
38753874
et131x_disable_txrx(netdev);
38763875

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

39593958
netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
39603959
netdev->netdev_ops = &et131x_netdev_ops;
3960+
netdev->min_mtu = ET131X_MIN_MTU;
3961+
netdev->max_mtu = ET131X_MAX_MTU;
39613962

39623963
SET_NETDEV_DEV(netdev, &pdev->dev);
39633964
netdev->ethtool_ops = &et131x_ethtool_ops;

drivers/net/ethernet/altera/altera_tse.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ struct altera_tse_private {
443443
/* RX/TX MAC FIFO configs */
444444
u32 tx_fifo_depth;
445445
u32 rx_fifo_depth;
446-
u32 max_mtu;
447446

448447
/* Hash filter settings */
449448
u32 hash_filter;

drivers/net/ethernet/altera/altera_tse_main.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -994,20 +994,11 @@ static void tse_set_mac(struct altera_tse_private *priv, bool enable)
994994
*/
995995
static int tse_change_mtu(struct net_device *dev, int new_mtu)
996996
{
997-
struct altera_tse_private *priv = netdev_priv(dev);
998-
unsigned int max_mtu = priv->max_mtu;
999-
unsigned int min_mtu = ETH_ZLEN + ETH_FCS_LEN;
1000-
1001997
if (netif_running(dev)) {
1002998
netdev_err(dev, "must be stopped to change its MTU\n");
1003999
return -EBUSY;
10041000
}
10051001

1006-
if ((new_mtu < min_mtu) || (new_mtu > max_mtu)) {
1007-
netdev_err(dev, "invalid MTU, max MTU is: %u\n", max_mtu);
1008-
return -EINVAL;
1009-
}
1010-
10111002
dev->mtu = new_mtu;
10121003
netdev_update_features(dev);
10131004

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

1440+
priv->dev->min_mtu = ETH_ZLEN + ETH_FCS_LEN;
14491441
/* Max MTU is 1500, ETH_DATA_LEN */
1450-
priv->max_mtu = ETH_DATA_LEN;
1442+
priv->dev->max_mtu = ETH_DATA_LEN;
14511443

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

14591451
/* The DMA buffer size already accounts for an alignment bias
14601452
* to avoid unaligned access exceptions for the NIOS processor,

drivers/net/ethernet/amd/amd8111e.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,6 @@ static int amd8111e_change_mtu(struct net_device *dev, int new_mtu)
15561556
struct amd8111e_priv *lp = netdev_priv(dev);
15571557
int err;
15581558

1559-
if ((new_mtu < AMD8111E_MIN_MTU) || (new_mtu > AMD8111E_MAX_MTU))
1560-
return -EINVAL;
1561-
15621559
if (!netif_running(dev)) {
15631560
/* new_mtu will be used
15641561
* when device starts netxt time
@@ -1874,6 +1871,8 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
18741871
dev->ethtool_ops = &ops;
18751872
dev->irq =pdev->irq;
18761873
dev->watchdog_timeo = AMD8111E_TX_TIMEOUT;
1874+
dev->min_mtu = AMD8111E_MIN_MTU;
1875+
dev->max_mtu = AMD8111E_MAX_MTU;
18771876
netif_napi_add(dev, &lp->napi, amd8111e_rx_poll, 32);
18781877

18791878
#if AMD8111E_VLAN_TAG_USED

drivers/net/ethernet/atheros/alx/hw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ struct alx_rrd {
351351
#define ALX_MAX_JUMBO_PKT_SIZE (9*1024)
352352
#define ALX_MAX_TSO_PKT_SIZE (7*1024)
353353
#define ALX_MAX_FRAME_SIZE ALX_MAX_JUMBO_PKT_SIZE
354-
#define ALX_MIN_FRAME_SIZE (ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN)
355354

356355
#define ALX_MAX_RX_QUEUES 8
357356
#define ALX_MAX_TX_QUEUES 4

drivers/net/ethernet/atheros/alx/main.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ static int alx_init_sw(struct alx_priv *alx)
892892
hw->smb_timer = 400;
893893
hw->mtu = alx->dev->mtu;
894894
alx->rxbuf_size = ALX_MAX_FRAME_LEN(hw->mtu);
895+
/* MTU range: 34 - 9256 */
896+
alx->dev->min_mtu = 34;
897+
alx->dev->max_mtu = ALX_MAX_FRAME_LEN(ALX_MAX_FRAME_SIZE);
895898
alx->tx_ringsz = 256;
896899
alx->rx_ringsz = 512;
897900
hw->imt = 200;
@@ -994,13 +997,6 @@ static int alx_change_mtu(struct net_device *netdev, int mtu)
994997
struct alx_priv *alx = netdev_priv(netdev);
995998
int max_frame = ALX_MAX_FRAME_LEN(mtu);
996999

997-
if ((max_frame < ALX_MIN_FRAME_SIZE) ||
998-
(max_frame > ALX_MAX_FRAME_SIZE))
999-
return -EINVAL;
1000-
1001-
if (netdev->mtu == mtu)
1002-
return 0;
1003-
10041000
netdev->mtu = mtu;
10051001
alx->hw.mtu = mtu;
10061002
alx->rxbuf_size = max(max_frame, ALX_DEF_RXBUF_SIZE);

drivers/net/ethernet/atheros/atl1c/atl1c_main.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,26 @@ static int atl1c_set_features(struct net_device *netdev,
519519
return 0;
520520
}
521521

522+
static void atl1c_set_max_mtu(struct net_device *netdev)
523+
{
524+
struct atl1c_adapter *adapter = netdev_priv(netdev);
525+
struct atl1c_hw *hw = &adapter->hw;
526+
527+
switch (hw->nic_type) {
528+
/* These (GbE) devices support jumbo packets, max_mtu 6122 */
529+
case athr_l1c:
530+
case athr_l1d:
531+
case athr_l1d_2:
532+
netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
533+
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
534+
break;
535+
/* The 10/100 devices don't support jumbo packets, max_mtu 1500 */
536+
default:
537+
netdev->max_mtu = ETH_DATA_LEN;
538+
break;
539+
}
540+
}
541+
522542
/**
523543
* atl1c_change_mtu - Change the Maximum Transfer Unit
524544
* @netdev: network interface device structure
@@ -529,22 +549,9 @@ static int atl1c_set_features(struct net_device *netdev,
529549
static int atl1c_change_mtu(struct net_device *netdev, int new_mtu)
530550
{
531551
struct atl1c_adapter *adapter = netdev_priv(netdev);
532-
struct atl1c_hw *hw = &adapter->hw;
533-
int old_mtu = netdev->mtu;
534-
int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
535-
536-
/* Fast Ethernet controller doesn't support jumbo packet */
537-
if (((hw->nic_type == athr_l2c ||
538-
hw->nic_type == athr_l2c_b ||
539-
hw->nic_type == athr_l2c_b2) && new_mtu > ETH_DATA_LEN) ||
540-
max_frame < ETH_ZLEN + ETH_FCS_LEN ||
541-
max_frame > MAX_JUMBO_FRAME_SIZE) {
542-
if (netif_msg_link(adapter))
543-
dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
544-
return -EINVAL;
545-
}
552+
546553
/* set MTU */
547-
if (old_mtu != new_mtu && netif_running(netdev)) {
554+
if (netif_running(netdev)) {
548555
while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
549556
msleep(1);
550557
netdev->mtu = new_mtu;
@@ -2511,6 +2518,7 @@ static int atl1c_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
25112518

25122519
netdev->netdev_ops = &atl1c_netdev_ops;
25132520
netdev->watchdog_timeo = AT_TX_WATCHDOG;
2521+
netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
25142522
atl1c_set_ethtool_ops(netdev);
25152523

25162524
/* TODO: add when ready */
@@ -2613,6 +2621,9 @@ static int atl1c_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
26132621
dev_err(&pdev->dev, "net device private data init failed\n");
26142622
goto err_sw_init;
26152623
}
2624+
/* set max MTU */
2625+
atl1c_set_max_mtu(netdev);
2626+
26162627
atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE);
26172628

26182629
/* Init GPHY as early as possible due to power saving issue */

drivers/net/ethernet/atheros/atl1e/atl1e_main.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,10 @@ static int atl1e_set_features(struct net_device *netdev,
439439
static int atl1e_change_mtu(struct net_device *netdev, int new_mtu)
440440
{
441441
struct atl1e_adapter *adapter = netdev_priv(netdev);
442-
int old_mtu = netdev->mtu;
443442
int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
444443

445-
if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
446-
(max_frame > MAX_JUMBO_FRAME_SIZE)) {
447-
netdev_warn(adapter->netdev, "invalid MTU setting\n");
448-
return -EINVAL;
449-
}
450444
/* set MTU */
451-
if (old_mtu != new_mtu && netif_running(netdev)) {
445+
if (netif_running(netdev)) {
452446
while (test_and_set_bit(__AT_RESETTING, &adapter->flags))
453447
msleep(1);
454448
netdev->mtu = new_mtu;
@@ -2272,6 +2266,10 @@ static int atl1e_init_netdev(struct net_device *netdev, struct pci_dev *pdev)
22722266
netdev->netdev_ops = &atl1e_netdev_ops;
22732267

22742268
netdev->watchdog_timeo = AT_TX_WATCHDOG;
2269+
/* MTU range: 42 - 8170 */
2270+
netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
2271+
netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
2272+
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
22752273
atl1e_set_ethtool_ops(netdev);
22762274

22772275
netdev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO |

drivers/net/ethernet/atheros/atlx/atl1.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,23 +2701,15 @@ static void atl1_reset_dev_task(struct work_struct *work)
27012701
static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
27022702
{
27032703
struct atl1_adapter *adapter = netdev_priv(netdev);
2704-
int old_mtu = netdev->mtu;
27052704
int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
27062705

2707-
if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
2708-
(max_frame > MAX_JUMBO_FRAME_SIZE)) {
2709-
if (netif_msg_link(adapter))
2710-
dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
2711-
return -EINVAL;
2712-
}
2713-
27142706
adapter->hw.max_frame_size = max_frame;
27152707
adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3;
27162708
adapter->rx_buffer_len = (max_frame + 7) & ~7;
27172709
adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8;
27182710

27192711
netdev->mtu = new_mtu;
2720-
if ((old_mtu != new_mtu) && netif_running(netdev)) {
2712+
if (netif_running(netdev)) {
27212713
atl1_down(adapter);
27222714
atl1_up(adapter);
27232715
}
@@ -3031,6 +3023,11 @@ static int atl1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
30313023
/* is this valid? see atl1_setup_mac_ctrl() */
30323024
netdev->features |= NETIF_F_RXCSUM;
30333025

3026+
/* MTU range: 42 - 10218 */
3027+
netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN);
3028+
netdev->max_mtu = MAX_JUMBO_FRAME_SIZE -
3029+
(ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
3030+
30343031
/*
30353032
* patch for some L1 of old version,
30363033
* the final version of L1 may not need these

drivers/net/ethernet/atheros/atlx/atl2.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static int atl2_configure(struct atl2_adapter *adapter)
253253

254254
/* set MTU */
255255
ATL2_WRITE_REG(hw, REG_MTU, adapter->netdev->mtu +
256-
ENET_HEADER_SIZE + VLAN_SIZE + ETHERNET_FCS_SIZE);
256+
ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
257257

258258
/* 1590 */
259259
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)
925925
struct atl2_adapter *adapter = netdev_priv(netdev);
926926
struct atl2_hw *hw = &adapter->hw;
927927

928-
if ((new_mtu < 40) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE)))
929-
return -EINVAL;
930-
931928
/* set MTU */
932-
if (hw->max_frame_size != new_mtu) {
933-
netdev->mtu = new_mtu;
934-
ATL2_WRITE_REG(hw, REG_MTU, new_mtu + ENET_HEADER_SIZE +
935-
VLAN_SIZE + ETHERNET_FCS_SIZE);
936-
}
929+
netdev->mtu = new_mtu;
930+
hw->max_frame_size = new_mtu;
931+
ATL2_WRITE_REG(hw, REG_MTU, new_mtu + ETH_HLEN +
932+
VLAN_HLEN + ETH_FCS_LEN);
937933

938934
return 0;
939935
}
@@ -1398,6 +1394,8 @@ static int atl2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
13981394
netdev->netdev_ops = &atl2_netdev_ops;
13991395
netdev->ethtool_ops = &atl2_ethtool_ops;
14001396
netdev->watchdog_timeo = 5 * HZ;
1397+
netdev->min_mtu = 40;
1398+
netdev->max_mtu = ETH_DATA_LEN + VLAN_HLEN;
14011399
strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
14021400

14031401
netdev->mem_start = mmio_start;

drivers/net/ethernet/atheros/atlx/atl2.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,9 @@ static void atl2_force_ps(struct atl2_hw *hw);
228228
#define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x000F /* Everything */
229229

230230
/* The size (in bytes) of a ethernet packet */
231-
#define ENET_HEADER_SIZE 14
232231
#define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* with FCS */
233232
#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* with FCS */
234-
#define ETHERNET_FCS_SIZE 4
235233
#define MAX_JUMBO_FRAME_SIZE 0x2000
236-
#define VLAN_SIZE 4
237234

238235
struct tx_pkt_header {
239236
unsigned pkt_size:11;

drivers/net/ethernet/broadcom/b44.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
#define B44_TX_TIMEOUT (5 * HZ)
6060

6161
/* hardware minimum and maximum for a single frame's data payload */
62-
#define B44_MIN_MTU 60
63-
#define B44_MAX_MTU 1500
62+
#define B44_MIN_MTU ETH_ZLEN
63+
#define B44_MAX_MTU ETH_DATA_LEN
6464

6565
#define B44_RX_RING_SIZE 512
6666
#define B44_DEF_RX_RING_PENDING 200
@@ -1064,9 +1064,6 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
10641064
{
10651065
struct b44 *bp = netdev_priv(dev);
10661066

1067-
if (new_mtu < B44_MIN_MTU || new_mtu > B44_MAX_MTU)
1068-
return -EINVAL;
1069-
10701067
if (!netif_running(dev)) {
10711068
/* We'll just catch it later when the
10721069
* device is up'd.
@@ -2377,6 +2374,8 @@ static int b44_init_one(struct ssb_device *sdev,
23772374
dev->netdev_ops = &b44_netdev_ops;
23782375
netif_napi_add(dev, &bp->napi, b44_poll, 64);
23792376
dev->watchdog_timeo = B44_TX_TIMEOUT;
2377+
dev->min_mtu = B44_MIN_MTU;
2378+
dev->max_mtu = B44_MAX_MTU;
23802379
dev->irq = sdev->irq;
23812380
dev->ethtool_ops = &b44_ethtool_ops;
23822381

0 commit comments

Comments
 (0)