Commit 22ad3838 authored by Giuseppe Cavallaro's avatar Giuseppe Cavallaro Committed by David S. Miller

stmmac: do not perform zero-copy for rx frames

This patch is to allow this driver to copy tiny frames during the reception
process. This is giving more stability while stressing the driver on STi
embedded systems.
Signed-off-by: default avatarGiuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: default avatarAlexandre TORGUE <alexandre.torgue@st.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8ecd80a5
...@@ -74,6 +74,7 @@ struct stmmac_priv { ...@@ -74,6 +74,7 @@ struct stmmac_priv {
unsigned int cur_rx; unsigned int cur_rx;
unsigned int dirty_rx; unsigned int dirty_rx;
unsigned int dma_buf_sz; unsigned int dma_buf_sz;
unsigned int rx_copybreak;
u32 rx_riwt; u32 rx_riwt;
int hwts_rx_en; int hwts_rx_en;
dma_addr_t *rx_skbuff_dma; dma_addr_t *rx_skbuff_dma;
......
...@@ -781,6 +781,43 @@ static int stmmac_get_ts_info(struct net_device *dev, ...@@ -781,6 +781,43 @@ static int stmmac_get_ts_info(struct net_device *dev,
return ethtool_op_get_ts_info(dev, info); return ethtool_op_get_ts_info(dev, info);
} }
static int stmmac_get_tunable(struct net_device *dev,
const struct ethtool_tunable *tuna, void *data)
{
struct stmmac_priv *priv = netdev_priv(dev);
int ret = 0;
switch (tuna->id) {
case ETHTOOL_RX_COPYBREAK:
*(u32 *)data = priv->rx_copybreak;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int stmmac_set_tunable(struct net_device *dev,
const struct ethtool_tunable *tuna,
const void *data)
{
struct stmmac_priv *priv = netdev_priv(dev);
int ret = 0;
switch (tuna->id) {
case ETHTOOL_RX_COPYBREAK:
priv->rx_copybreak = *(u32 *)data;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static const struct ethtool_ops stmmac_ethtool_ops = { static const struct ethtool_ops stmmac_ethtool_ops = {
.begin = stmmac_check_if_running, .begin = stmmac_check_if_running,
.get_drvinfo = stmmac_ethtool_getdrvinfo, .get_drvinfo = stmmac_ethtool_getdrvinfo,
...@@ -803,6 +840,8 @@ static const struct ethtool_ops stmmac_ethtool_ops = { ...@@ -803,6 +840,8 @@ static const struct ethtool_ops stmmac_ethtool_ops = {
.get_ts_info = stmmac_get_ts_info, .get_ts_info = stmmac_get_ts_info,
.get_coalesce = stmmac_get_coalesce, .get_coalesce = stmmac_get_coalesce,
.set_coalesce = stmmac_set_coalesce, .set_coalesce = stmmac_set_coalesce,
.get_tunable = stmmac_get_tunable,
.set_tunable = stmmac_set_tunable,
}; };
void stmmac_set_ethtool_ops(struct net_device *netdev) void stmmac_set_ethtool_ops(struct net_device *netdev)
......
...@@ -91,6 +91,8 @@ static int buf_sz = DEFAULT_BUFSIZE; ...@@ -91,6 +91,8 @@ static int buf_sz = DEFAULT_BUFSIZE;
module_param(buf_sz, int, S_IRUGO | S_IWUSR); module_param(buf_sz, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(buf_sz, "DMA buffer size"); MODULE_PARM_DESC(buf_sz, "DMA buffer size");
#define STMMAC_RX_COPYBREAK 256
static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
NETIF_MSG_LINK | NETIF_MSG_IFUP | NETIF_MSG_LINK | NETIF_MSG_IFUP |
NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
...@@ -1808,6 +1810,7 @@ static int stmmac_open(struct net_device *dev) ...@@ -1808,6 +1810,7 @@ static int stmmac_open(struct net_device *dev)
priv->xstats.threshold = tc; priv->xstats.threshold = tc;
priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
priv->rx_copybreak = STMMAC_RX_COPYBREAK;
ret = alloc_dma_desc_resources(priv); ret = alloc_dma_desc_resources(priv);
if (ret < 0) { if (ret < 0) {
...@@ -2159,8 +2162,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv) ...@@ -2159,8 +2162,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
struct sk_buff *skb; struct sk_buff *skb;
skb = netdev_alloc_skb_ip_align(priv->dev, bfsize); skb = netdev_alloc_skb_ip_align(priv->dev, bfsize);
if (unlikely(!skb))
if (unlikely(skb == NULL))
break; break;
priv->rx_skbuff[entry] = skb; priv->rx_skbuff[entry] = skb;
...@@ -2282,9 +2284,36 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit) ...@@ -2282,9 +2284,36 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
pr_debug("\tframe size %d, COE: %d\n", pr_debug("\tframe size %d, COE: %d\n",
frame_len, status); frame_len, status);
} }
if (unlikely(frame_len < priv->rx_copybreak)) {
skb = netdev_alloc_skb_ip_align(priv->dev,
frame_len);
if (unlikely(!skb)) {
if (net_ratelimit())
dev_warn(priv->device,
"packet dropped\n");
priv->dev->stats.rx_dropped++;
break;
}
dma_sync_single_for_cpu(priv->device,
priv->rx_skbuff_dma
[entry], frame_len,
DMA_FROM_DEVICE);
skb_copy_to_linear_data(skb,
priv->
rx_skbuff[entry]->data,
frame_len);
skb_put(skb, frame_len);
dma_sync_single_for_device(priv->device,
priv->rx_skbuff_dma
[entry], frame_len,
DMA_FROM_DEVICE);
} else {
skb = priv->rx_skbuff[entry]; skb = priv->rx_skbuff[entry];
if (unlikely(!skb)) { if (unlikely(!skb)) {
pr_err("%s: Inconsistent Rx descriptor chain\n", pr_err("%s: Inconsistent Rx chain\n",
priv->dev->name); priv->dev->name);
priv->dev->stats.rx_dropped++; priv->dev->stats.rx_dropped++;
break; break;
...@@ -2292,12 +2321,14 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit) ...@@ -2292,12 +2321,14 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
prefetch(skb->data - NET_IP_ALIGN); prefetch(skb->data - NET_IP_ALIGN);
priv->rx_skbuff[entry] = NULL; priv->rx_skbuff[entry] = NULL;
stmmac_get_rx_hwtstamp(priv, entry, skb);
skb_put(skb, frame_len); skb_put(skb, frame_len);
dma_unmap_single(priv->device, dma_unmap_single(priv->device,
priv->rx_skbuff_dma[entry], priv->rx_skbuff_dma[entry],
priv->dma_buf_sz, DMA_FROM_DEVICE); priv->dma_buf_sz,
DMA_FROM_DEVICE);
}
stmmac_get_rx_hwtstamp(priv, entry, skb);
if (netif_msg_pktdata(priv)) { if (netif_msg_pktdata(priv)) {
pr_debug("frame received (%dbytes)", frame_len); pr_debug("frame received (%dbytes)", frame_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment