From f8b30859856a964ed76934a8a6d480d0b52b252c Mon Sep 17 00:00:00 2001 From: Asbjoern Sloth Toennesen Date: Tue, 13 Sep 2016 19:12:36 +0000 Subject: [PATCH] staging: octeon: use defines instead of magic numbers The ugly magic number 65392 is waiting for CVMX_IPD_MAX_MTU to appear in the mips tree. Signed-off-by: Asbjoern Sloth Toennesen Signed-off-by: Greg Kroah-Hartman --- drivers/staging/octeon/ethernet.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c index 5f746b88522d..790477c085e0 100644 --- a/drivers/staging/octeon/ethernet.c +++ b/drivers/staging/octeon/ethernet.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include @@ -39,6 +41,8 @@ #include #include +#define OCTEON_MAX_MTU 65392 + static int num_packet_buffers = 1024; module_param(num_packet_buffers, int, 0444); MODULE_PARM_DESC(num_packet_buffers, "\n" @@ -249,19 +253,21 @@ static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu) struct octeon_ethernet *priv = netdev_priv(dev); int interface = INTERFACE(priv->port); #if IS_ENABLED(CONFIG_VLAN_8021Q) - int vlan_bytes = 4; + int vlan_bytes = VLAN_HLEN; #else int vlan_bytes = 0; #endif + int mtu_overhead = ETH_HLEN + ETH_FCS_LEN + vlan_bytes; /* * Limit the MTU to make sure the ethernet packets are between * 64 bytes and 65535 bytes. */ - if ((new_mtu + 14 + 4 + vlan_bytes < 64) || - (new_mtu + 14 + 4 + vlan_bytes > 65392)) { + if ((new_mtu + mtu_overhead < VLAN_ETH_ZLEN) || + (new_mtu + mtu_overhead > OCTEON_MAX_MTU)) { pr_err("MTU must be between %d and %d.\n", - 64 - 14 - 4 - vlan_bytes, 65392 - 14 - 4 - vlan_bytes); + VLAN_ETH_ZLEN - mtu_overhead, + OCTEON_MAX_MTU - mtu_overhead); return -EINVAL; } dev->mtu = new_mtu; @@ -271,7 +277,7 @@ static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu) CVMX_HELPER_INTERFACE_MODE_SPI)) { int index = INDEX(priv->port); /* Add ethernet header and FCS, and VLAN if configured. */ - int max_packet = new_mtu + 14 + 4 + vlan_bytes; + int max_packet = new_mtu + mtu_overhead; if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN58XX)) { @@ -286,7 +292,7 @@ static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu) union cvmx_pip_frm_len_chkx frm_len_chk; frm_len_chk.u64 = 0; - frm_len_chk.s.minlen = 64; + frm_len_chk.s.minlen = VLAN_ETH_ZLEN; frm_len_chk.s.maxlen = max_packet; cvmx_write_csr(CVMX_PIP_FRM_LEN_CHKX(interface), frm_len_chk.u64); -- 2.39.5