Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jarod Wilson and committed by
David S. Miller
67bef942 60d2d8dd

+46 -50
-1
drivers/net/ethernet/atheros/alx/hw.h
··· 351 351 #define ALX_MAX_JUMBO_PKT_SIZE (9*1024) 352 352 #define ALX_MAX_TSO_PKT_SIZE (7*1024) 353 353 #define ALX_MAX_FRAME_SIZE ALX_MAX_JUMBO_PKT_SIZE 354 - #define ALX_MIN_FRAME_SIZE (ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) 355 354 356 355 #define ALX_MAX_RX_QUEUES 8 357 356 #define ALX_MAX_TX_QUEUES 4
+3 -7
drivers/net/ethernet/atheros/alx/main.c
··· 892 892 hw->smb_timer = 400; 893 893 hw->mtu = alx->dev->mtu; 894 894 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); 895 898 alx->tx_ringsz = 256; 896 899 alx->rx_ringsz = 512; 897 900 hw->imt = 200; ··· 996 993 { 997 994 struct alx_priv *alx = netdev_priv(netdev); 998 995 int max_frame = ALX_MAX_FRAME_LEN(mtu); 999 - 1000 - if ((max_frame < ALX_MIN_FRAME_SIZE) || 1001 - (max_frame > ALX_MAX_FRAME_SIZE)) 1002 - return -EINVAL; 1003 - 1004 - if (netdev->mtu == mtu) 1005 - return 0; 1006 996 1007 997 netdev->mtu = mtu; 1008 998 alx->hw.mtu = mtu;
+25 -14
drivers/net/ethernet/atheros/atl1c/atl1c_main.c
··· 519 519 return 0; 520 520 } 521 521 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 + 522 542 /** 523 543 * atl1c_change_mtu - Change the Maximum Transfer Unit 524 544 * @netdev: network interface device structure ··· 549 529 static int atl1c_change_mtu(struct net_device *netdev, int new_mtu) 550 530 { 551 531 struct atl1c_adapter *adapter = netdev_priv(netdev); 552 - struct atl1c_hw *hw = &adapter->hw; 553 - int old_mtu = netdev->mtu; 554 - int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; 555 532 556 - /* Fast Ethernet controller doesn't support jumbo packet */ 557 - if (((hw->nic_type == athr_l2c || 558 - hw->nic_type == athr_l2c_b || 559 - hw->nic_type == athr_l2c_b2) && new_mtu > ETH_DATA_LEN) || 560 - max_frame < ETH_ZLEN + ETH_FCS_LEN || 561 - max_frame > MAX_JUMBO_FRAME_SIZE) { 562 - if (netif_msg_link(adapter)) 563 - dev_warn(&adapter->pdev->dev, "invalid MTU setting\n"); 564 - return -EINVAL; 565 - } 566 533 /* set MTU */ 567 - if (old_mtu != new_mtu && netif_running(netdev)) { 534 + if (netif_running(netdev)) { 568 535 while (test_and_set_bit(__AT_RESETTING, &adapter->flags)) 569 536 msleep(1); 570 537 netdev->mtu = new_mtu; ··· 2518 2511 2519 2512 netdev->netdev_ops = &atl1c_netdev_ops; 2520 2513 netdev->watchdog_timeo = AT_TX_WATCHDOG; 2514 + netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN); 2521 2515 atl1c_set_ethtool_ops(netdev); 2522 2516 2523 2517 /* TODO: add when ready */ ··· 2621 2613 dev_err(&pdev->dev, "net device private data init failed\n"); 2622 2614 goto err_sw_init; 2623 2615 } 2616 + /* set max MTU */ 2617 + atl1c_set_max_mtu(netdev); 2618 + 2624 2619 atl1c_reset_pcie(&adapter->hw, ATL1C_PCIE_L0S_L1_DISABLE); 2625 2620 2626 2621 /* Init GPHY as early as possible due to power saving issue */
+5 -7
drivers/net/ethernet/atheros/atl1e/atl1e_main.c
··· 439 439 static int atl1e_change_mtu(struct net_device *netdev, int new_mtu) 440 440 { 441 441 struct atl1e_adapter *adapter = netdev_priv(netdev); 442 - int old_mtu = netdev->mtu; 443 442 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; 444 443 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 - } 450 444 /* set MTU */ 451 - if (old_mtu != new_mtu && netif_running(netdev)) { 445 + if (netif_running(netdev)) { 452 446 while (test_and_set_bit(__AT_RESETTING, &adapter->flags)) 453 447 msleep(1); 454 448 netdev->mtu = new_mtu; ··· 2266 2272 netdev->netdev_ops = &atl1e_netdev_ops; 2267 2273 2268 2274 netdev->watchdog_timeo = AT_TX_WATCHDOG; 2275 + /* MTU range: 42 - 8170 */ 2276 + netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN); 2277 + netdev->max_mtu = MAX_JUMBO_FRAME_SIZE - 2278 + (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); 2269 2279 atl1e_set_ethtool_ops(netdev); 2270 2280 2271 2281 netdev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO |
+6 -9
drivers/net/ethernet/atheros/atlx/atl1.c
··· 2701 2701 static int atl1_change_mtu(struct net_device *netdev, int new_mtu) 2702 2702 { 2703 2703 struct atl1_adapter *adapter = netdev_priv(netdev); 2704 - int old_mtu = netdev->mtu; 2705 2704 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; 2706 - 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 2705 2714 2706 adapter->hw.max_frame_size = max_frame; 2715 2707 adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3; ··· 2709 2717 adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8; 2710 2718 2711 2719 netdev->mtu = new_mtu; 2712 - if ((old_mtu != new_mtu) && netif_running(netdev)) { 2720 + if (netif_running(netdev)) { 2713 2721 atl1_down(adapter); 2714 2722 atl1_up(adapter); 2715 2723 } ··· 3022 3030 3023 3031 /* is this valid? see atl1_setup_mac_ctrl() */ 3024 3032 netdev->features |= NETIF_F_RXCSUM; 3033 + 3034 + /* MTU range: 42 - 10218 */ 3035 + netdev->min_mtu = ETH_ZLEN - (ETH_HLEN + VLAN_HLEN); 3036 + netdev->max_mtu = MAX_JUMBO_FRAME_SIZE - 3037 + (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); 3025 3038 3026 3039 /* 3027 3040 * patch for some L1 of old version,
+7 -9
drivers/net/ethernet/atheros/atlx/atl2.c
··· 253 253 254 254 /* set MTU */ 255 255 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); 257 257 258 258 /* 1590 */ 259 259 ATL2_WRITE_REG(hw, REG_TX_CUT_THRESH, 0x177); ··· 925 925 struct atl2_adapter *adapter = netdev_priv(netdev); 926 926 struct atl2_hw *hw = &adapter->hw; 927 927 928 - if ((new_mtu < 40) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE))) 929 - return -EINVAL; 930 - 931 928 /* 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); 937 933 938 934 return 0; 939 935 } ··· 1394 1398 netdev->netdev_ops = &atl2_netdev_ops; 1395 1399 netdev->ethtool_ops = &atl2_ethtool_ops; 1396 1400 netdev->watchdog_timeo = 5 * HZ; 1401 + netdev->min_mtu = 40; 1402 + netdev->max_mtu = ETH_DATA_LEN + VLAN_HLEN; 1397 1403 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); 1398 1404 1399 1405 netdev->mem_start = mmio_start;
-3
drivers/net/ethernet/atheros/atlx/atl2.h
··· 228 228 #define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x000F /* Everything */ 229 229 230 230 /* The size (in bytes) of a ethernet packet */ 231 - #define ENET_HEADER_SIZE 14 232 231 #define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* with FCS */ 233 232 #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* with FCS */ 234 - #define ETHERNET_FCS_SIZE 4 235 233 #define MAX_JUMBO_FRAME_SIZE 0x2000 236 - #define VLAN_SIZE 4 237 234 238 235 struct tx_pkt_header { 239 236 unsigned pkt_size:11;