net: axienet: Handle jumbo frames for lesser frame sizes

In the current implementation, jumbo frames are supported only
for the frame sizes > 16K. This patch corrects this logic to
handle jumbo frames for lesser frame sizes (< 16K) ensuring jumbo frame
MTU is within the limit of max frame size configured in the h/w
design.

Signed-off-by: Srikanth Thokala <sthokal@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Srikanth Thokala 2015-05-05 11:25:57 +02:00 committed by David S. Miller
parent 80c775accd
commit f080a8c35d
2 changed files with 27 additions and 28 deletions

View file

@ -11,16 +11,16 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/if_vlan.h>
/* Packet size info */ /* Packet size info */
#define XAE_HDR_SIZE 14 /* Size of Ethernet header */ #define XAE_HDR_SIZE 14 /* Size of Ethernet header */
#define XAE_HDR_VLAN_SIZE 18 /* Size of an Ethernet hdr + VLAN */
#define XAE_TRL_SIZE 4 /* Size of Ethernet trailer (FCS) */ #define XAE_TRL_SIZE 4 /* Size of Ethernet trailer (FCS) */
#define XAE_MTU 1500 /* Max MTU of an Ethernet frame */ #define XAE_MTU 1500 /* Max MTU of an Ethernet frame */
#define XAE_JUMBO_MTU 9000 /* Max MTU of a jumbo Eth. frame */ #define XAE_JUMBO_MTU 9000 /* Max MTU of a jumbo Eth. frame */
#define XAE_MAX_FRAME_SIZE (XAE_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE) #define XAE_MAX_FRAME_SIZE (XAE_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
#define XAE_MAX_VLAN_FRAME_SIZE (XAE_MTU + XAE_HDR_VLAN_SIZE + XAE_TRL_SIZE) #define XAE_MAX_VLAN_FRAME_SIZE (XAE_MTU + VLAN_ETH_HLEN + XAE_TRL_SIZE)
#define XAE_MAX_JUMBO_FRAME_SIZE (XAE_JUMBO_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE) #define XAE_MAX_JUMBO_FRAME_SIZE (XAE_JUMBO_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
/* Configuration options */ /* Configuration options */
@ -407,8 +407,7 @@ struct axidma_bd {
* Txed/Rxed in the existing hardware. If jumbo option is * Txed/Rxed in the existing hardware. If jumbo option is
* supported, the maximum frame size would be 9k. Else it is * supported, the maximum frame size would be 9k. Else it is
* 1522 bytes (assuming support for basic VLAN) * 1522 bytes (assuming support for basic VLAN)
* @jumbo_support: Stores hardware configuration for jumbo support. If hardware * @rxmem: Stores rx memory size for jumbo frame handling.
* can handle jumbo packets, this entry will be 1, else 0.
*/ */
struct axienet_local { struct axienet_local {
struct net_device *ndev; struct net_device *ndev;
@ -446,7 +445,7 @@ struct axienet_local {
u32 rx_bd_ci; u32 rx_bd_ci;
u32 max_frm_size; u32 max_frm_size;
u32 jumbo_support; u32 rxmem;
int csum_offload_on_tx_path; int csum_offload_on_tx_path;
int csum_offload_on_rx_path; int csum_offload_on_rx_path;

View file

@ -471,14 +471,16 @@ static void axienet_device_reset(struct net_device *ndev)
__axienet_device_reset(lp, &ndev->dev, XAXIDMA_RX_CR_OFFSET); __axienet_device_reset(lp, &ndev->dev, XAXIDMA_RX_CR_OFFSET);
lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE; lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE;
lp->options |= XAE_OPTION_VLAN;
lp->options &= (~XAE_OPTION_JUMBO); lp->options &= (~XAE_OPTION_JUMBO);
if ((ndev->mtu > XAE_MTU) && if ((ndev->mtu > XAE_MTU) &&
(ndev->mtu <= XAE_JUMBO_MTU) && (ndev->mtu <= XAE_JUMBO_MTU)) {
(lp->jumbo_support)) { lp->max_frm_size = ndev->mtu + VLAN_ETH_HLEN +
lp->max_frm_size = ndev->mtu + XAE_HDR_VLAN_SIZE + XAE_TRL_SIZE;
XAE_TRL_SIZE;
lp->options |= XAE_OPTION_JUMBO; if (lp->max_frm_size <= lp->rxmem)
lp->options |= XAE_OPTION_JUMBO;
} }
if (axienet_dma_bd_init(ndev)) { if (axienet_dma_bd_init(ndev)) {
@ -1027,15 +1029,15 @@ static int axienet_change_mtu(struct net_device *ndev, int new_mtu)
if (netif_running(ndev)) if (netif_running(ndev))
return -EBUSY; return -EBUSY;
if (lp->jumbo_support) {
if ((new_mtu > XAE_JUMBO_MTU) || (new_mtu < 64)) if ((new_mtu + VLAN_ETH_HLEN +
return -EINVAL; XAE_TRL_SIZE) > lp->rxmem)
ndev->mtu = new_mtu; return -EINVAL;
} else {
if ((new_mtu > XAE_MTU) || (new_mtu < 64)) if ((new_mtu > XAE_JUMBO_MTU) || (new_mtu < 64))
return -EINVAL; return -EINVAL;
ndev->mtu = new_mtu;
} ndev->mtu = new_mtu;
return 0; return 0;
} }
@ -1556,16 +1558,14 @@ static int axienet_of_probe(struct platform_device *op)
} }
} }
/* For supporting jumbo frames, the Axi Ethernet hardware must have /* For supporting jumbo frames, the Axi Ethernet hardware must have
* a larger Rx/Tx Memory. Typically, the size must be more than or * a larger Rx/Tx Memory. Typically, the size must be large so that
* equal to 16384 bytes, so that we can enable jumbo option and start * we can enable jumbo option and start supporting jumbo frames.
* supporting jumbo frames. Here we check for memory allocated for * Here we check for memory allocated for Rx/Tx in the hardware from
* Rx/Tx in the hardware from the device-tree and accordingly set * the device-tree and accordingly set flags.
* flags. */ */
p = (__be32 *) of_get_property(op->dev.of_node, "xlnx,rxmem", NULL); p = (__be32 *) of_get_property(op->dev.of_node, "xlnx,rxmem", NULL);
if (p) { if (p)
if ((be32_to_cpup(p)) >= 0x4000) lp->rxmem = be32_to_cpup(p);
lp->jumbo_support = 1;
}
p = (__be32 *) of_get_property(op->dev.of_node, "xlnx,phy-type", NULL); p = (__be32 *) of_get_property(op->dev.of_node, "xlnx,phy-type", NULL);
if (p) if (p)
lp->phy_type = be32_to_cpup(p); lp->phy_type = be32_to_cpup(p);