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

stmmac: review RX/TX ring management

This patch is to rework the ring management now optimized.
The indexes into the ring buffer are always incremented, and
the entry is accessed via doing a modulo to find the "real"
position in the ring.
It is inefficient, modulo is an expensive operation.

The formula [(entry + 1) & (size - 1)] is now adopted on
a ring that is power-of-2 in size.
Then, the number of elements cannot be set by command line but
it is fixed.
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 293e4365
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
{ {
struct stmmac_priv *priv = (struct stmmac_priv *)p; struct stmmac_priv *priv = (struct stmmac_priv *)p;
unsigned int txsize = priv->dma_tx_size; unsigned int entry = priv->cur_tx;
unsigned int entry = priv->cur_tx % txsize;
struct dma_desc *desc = priv->dma_tx + entry; struct dma_desc *desc = priv->dma_tx + entry;
unsigned int nopaged_len = skb_headlen(skb); unsigned int nopaged_len = skb_headlen(skb);
unsigned int bmax; unsigned int bmax;
...@@ -54,7 +53,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -54,7 +53,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
while (len != 0) { while (len != 0) {
priv->tx_skbuff[entry] = NULL; priv->tx_skbuff[entry] = NULL;
entry = (++priv->cur_tx) % txsize; entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
desc = priv->dma_tx + entry; desc = priv->dma_tx + entry;
if (len > bmax) { if (len > bmax) {
...@@ -82,6 +81,9 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -82,6 +81,9 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
len = 0; len = 0;
} }
} }
priv->cur_tx = entry;
return entry; return entry;
} }
...@@ -138,7 +140,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -138,7 +140,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
*/ */
p->des3 = (unsigned int)(priv->dma_rx_phy + p->des3 = (unsigned int)(priv->dma_rx_phy +
(((priv->dirty_rx) + 1) % (((priv->dirty_rx) + 1) %
priv->dma_rx_size) * DMA_RX_SIZE) *
sizeof(struct dma_desc)); sizeof(struct dma_desc));
} }
...@@ -151,10 +153,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -151,10 +153,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
* 1588-2002 time stamping is enabled, hence reinitialize it * 1588-2002 time stamping is enabled, hence reinitialize it
* to keep explicit chaining in the descriptor. * to keep explicit chaining in the descriptor.
*/ */
p->des3 = (unsigned int)(priv->dma_tx_phy + p->des3 = (unsigned int)((priv->dma_tx_phy +
(((priv->dirty_tx + 1) % ((priv->dirty_tx + 1) % DMA_TX_SIZE))
priv->dma_tx_size) * * sizeof(struct dma_desc));
sizeof(struct dma_desc)));
} }
const struct stmmac_mode_ops chain_mode_ops = { const struct stmmac_mode_ops chain_mode_ops = {
......
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
#define DWMAC_CORE_3_40 0x34 #define DWMAC_CORE_3_40 0x34
#define DWMAC_CORE_3_50 0x35 #define DWMAC_CORE_3_50 0x35
#define DMA_TX_SIZE 512
#define DMA_RX_SIZE 512
#define STMMAC_GET_ENTRY(x, size) ((x + 1) & (size - 1))
#undef FRAME_FILTER_DEBUG #undef FRAME_FILTER_DEBUG
/* #define FRAME_FILTER_DEBUG */ /* #define FRAME_FILTER_DEBUG */
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
{ {
struct stmmac_priv *priv = (struct stmmac_priv *)p; struct stmmac_priv *priv = (struct stmmac_priv *)p;
unsigned int txsize = priv->dma_tx_size; unsigned int entry = priv->cur_tx;
unsigned int entry = priv->cur_tx % txsize;
struct dma_desc *desc; struct dma_desc *desc;
unsigned int nopaged_len = skb_headlen(skb); unsigned int nopaged_len = skb_headlen(skb);
unsigned int bmax, len; unsigned int bmax, len;
...@@ -62,7 +61,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -62,7 +61,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
STMMAC_RING_MODE); STMMAC_RING_MODE);
wmb(); wmb();
priv->tx_skbuff[entry] = NULL; priv->tx_skbuff[entry] = NULL;
entry = (++priv->cur_tx) % txsize; entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
if (priv->extend_desc) if (priv->extend_desc)
desc = (struct dma_desc *)(priv->dma_etx + entry); desc = (struct dma_desc *)(priv->dma_etx + entry);
...@@ -90,6 +89,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -90,6 +89,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
STMMAC_RING_MODE); STMMAC_RING_MODE);
} }
priv->cur_tx = entry;
return entry; return entry;
} }
......
...@@ -54,7 +54,6 @@ struct stmmac_priv { ...@@ -54,7 +54,6 @@ struct stmmac_priv {
struct sk_buff **tx_skbuff; struct sk_buff **tx_skbuff;
unsigned int cur_tx; unsigned int cur_tx;
unsigned int dirty_tx; unsigned int dirty_tx;
unsigned int dma_tx_size;
u32 tx_count_frames; u32 tx_count_frames;
u32 tx_coal_frames; u32 tx_coal_frames;
u32 tx_coal_timer; u32 tx_coal_timer;
...@@ -71,7 +70,6 @@ struct stmmac_priv { ...@@ -71,7 +70,6 @@ struct stmmac_priv {
struct sk_buff **rx_skbuff; struct sk_buff **rx_skbuff;
unsigned int cur_rx; unsigned int cur_rx;
unsigned int dirty_rx; unsigned int dirty_rx;
unsigned int dma_rx_size;
unsigned int dma_buf_sz; unsigned int dma_buf_sz;
u32 rx_riwt; u32 rx_riwt;
int hwts_rx_en; int hwts_rx_en;
......
...@@ -71,15 +71,7 @@ static int phyaddr = -1; ...@@ -71,15 +71,7 @@ static int phyaddr = -1;
module_param(phyaddr, int, S_IRUGO); module_param(phyaddr, int, S_IRUGO);
MODULE_PARM_DESC(phyaddr, "Physical device address"); MODULE_PARM_DESC(phyaddr, "Physical device address");
#define DMA_TX_SIZE 256 #define STMMAC_TX_THRESH (DMA_TX_SIZE / 4)
static int dma_txsize = DMA_TX_SIZE;
module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
#define DMA_RX_SIZE 256
static int dma_rxsize = DMA_RX_SIZE;
module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
static int flow_ctrl = FLOW_OFF; static int flow_ctrl = FLOW_OFF;
module_param(flow_ctrl, int, S_IRUGO | S_IWUSR); module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
...@@ -134,10 +126,6 @@ static void stmmac_verify_args(void) ...@@ -134,10 +126,6 @@ static void stmmac_verify_args(void)
{ {
if (unlikely(watchdog < 0)) if (unlikely(watchdog < 0))
watchdog = TX_TIMEO; watchdog = TX_TIMEO;
if (unlikely(dma_rxsize < 0))
dma_rxsize = DMA_RX_SIZE;
if (unlikely(dma_txsize < 0))
dma_txsize = DMA_TX_SIZE;
if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB))) if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB)))
buf_sz = DEFAULT_BUFSIZE; buf_sz = DEFAULT_BUFSIZE;
if (unlikely(flow_ctrl > 1)) if (unlikely(flow_ctrl > 1))
...@@ -197,12 +185,28 @@ static void print_pkt(unsigned char *buf, int len) ...@@ -197,12 +185,28 @@ static void print_pkt(unsigned char *buf, int len)
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len);
} }
/* minimum number of free TX descriptors required to wake up TX process */
#define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
static inline u32 stmmac_tx_avail(struct stmmac_priv *priv) static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
{ {
return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1; unsigned avail;
if (priv->dirty_tx > priv->cur_tx)
avail = priv->dirty_tx - priv->cur_tx - 1;
else
avail = DMA_TX_SIZE - priv->cur_tx + priv->dirty_tx - 1;
return avail;
}
static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv)
{
unsigned dirty;
if (priv->dirty_rx <= priv->cur_rx)
dirty = priv->cur_rx - priv->dirty_rx;
else
dirty = DMA_RX_SIZE - priv->dirty_rx + priv->cur_rx;
return dirty;
} }
/** /**
...@@ -906,19 +910,16 @@ static void stmmac_display_ring(void *head, int size, int extend_desc) ...@@ -906,19 +910,16 @@ static void stmmac_display_ring(void *head, int size, int extend_desc)
static void stmmac_display_rings(struct stmmac_priv *priv) static void stmmac_display_rings(struct stmmac_priv *priv)
{ {
unsigned int txsize = priv->dma_tx_size;
unsigned int rxsize = priv->dma_rx_size;
if (priv->extend_desc) { if (priv->extend_desc) {
pr_info("Extended RX descriptor ring:\n"); pr_info("Extended RX descriptor ring:\n");
stmmac_display_ring((void *)priv->dma_erx, rxsize, 1); stmmac_display_ring((void *)priv->dma_erx, DMA_RX_SIZE, 1);
pr_info("Extended TX descriptor ring:\n"); pr_info("Extended TX descriptor ring:\n");
stmmac_display_ring((void *)priv->dma_etx, txsize, 1); stmmac_display_ring((void *)priv->dma_etx, DMA_TX_SIZE, 1);
} else { } else {
pr_info("RX descriptor ring:\n"); pr_info("RX descriptor ring:\n");
stmmac_display_ring((void *)priv->dma_rx, rxsize, 0); stmmac_display_ring((void *)priv->dma_rx, DMA_RX_SIZE, 0);
pr_info("TX descriptor ring:\n"); pr_info("TX descriptor ring:\n");
stmmac_display_ring((void *)priv->dma_tx, txsize, 0); stmmac_display_ring((void *)priv->dma_tx, DMA_TX_SIZE, 0);
} }
} }
...@@ -947,28 +948,26 @@ static int stmmac_set_bfsize(int mtu, int bufsize) ...@@ -947,28 +948,26 @@ static int stmmac_set_bfsize(int mtu, int bufsize)
static void stmmac_clear_descriptors(struct stmmac_priv *priv) static void stmmac_clear_descriptors(struct stmmac_priv *priv)
{ {
int i; int i;
unsigned int txsize = priv->dma_tx_size;
unsigned int rxsize = priv->dma_rx_size;
/* Clear the Rx/Tx descriptors */ /* Clear the Rx/Tx descriptors */
for (i = 0; i < rxsize; i++) for (i = 0; i < DMA_RX_SIZE; i++)
if (priv->extend_desc) if (priv->extend_desc)
priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic, priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic,
priv->use_riwt, priv->mode, priv->use_riwt, priv->mode,
(i == rxsize - 1)); (i == DMA_RX_SIZE - 1));
else else
priv->hw->desc->init_rx_desc(&priv->dma_rx[i], priv->hw->desc->init_rx_desc(&priv->dma_rx[i],
priv->use_riwt, priv->mode, priv->use_riwt, priv->mode,
(i == rxsize - 1)); (i == DMA_RX_SIZE - 1));
for (i = 0; i < txsize; i++) for (i = 0; i < DMA_TX_SIZE; i++)
if (priv->extend_desc) if (priv->extend_desc)
priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic, priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
priv->mode, priv->mode,
(i == txsize - 1)); (i == DMA_TX_SIZE - 1));
else else
priv->hw->desc->init_tx_desc(&priv->dma_tx[i], priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
priv->mode, priv->mode,
(i == txsize - 1)); (i == DMA_TX_SIZE - 1));
} }
/** /**
...@@ -1031,8 +1030,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1031,8 +1030,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
{ {
int i; int i;
struct stmmac_priv *priv = netdev_priv(dev); struct stmmac_priv *priv = netdev_priv(dev);
unsigned int txsize = priv->dma_tx_size;
unsigned int rxsize = priv->dma_rx_size;
unsigned int bfsize = 0; unsigned int bfsize = 0;
int ret = -ENOMEM; int ret = -ENOMEM;
...@@ -1044,10 +1041,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1044,10 +1041,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
priv->dma_buf_sz = bfsize; priv->dma_buf_sz = bfsize;
if (netif_msg_probe(priv))
pr_debug("%s: txsize %d, rxsize %d, bfsize %d\n", __func__,
txsize, rxsize, bfsize);
if (netif_msg_probe(priv)) { if (netif_msg_probe(priv)) {
pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__, pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__,
(u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy); (u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy);
...@@ -1055,7 +1048,7 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1055,7 +1048,7 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
/* RX INITIALIZATION */ /* RX INITIALIZATION */
pr_debug("\tSKB addresses:\nskb\t\tskb data\tdma data\n"); pr_debug("\tSKB addresses:\nskb\t\tskb data\tdma data\n");
} }
for (i = 0; i < rxsize; i++) { for (i = 0; i < DMA_RX_SIZE; i++) {
struct dma_desc *p; struct dma_desc *p;
if (priv->extend_desc) if (priv->extend_desc)
p = &((priv->dma_erx + i)->basic); p = &((priv->dma_erx + i)->basic);
...@@ -1072,26 +1065,26 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1072,26 +1065,26 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
(unsigned int)priv->rx_skbuff_dma[i]); (unsigned int)priv->rx_skbuff_dma[i]);
} }
priv->cur_rx = 0; priv->cur_rx = 0;
priv->dirty_rx = (unsigned int)(i - rxsize); priv->dirty_rx = (unsigned int)(i - DMA_RX_SIZE);
buf_sz = bfsize; buf_sz = bfsize;
/* Setup the chained descriptor addresses */ /* Setup the chained descriptor addresses */
if (priv->mode == STMMAC_CHAIN_MODE) { if (priv->mode == STMMAC_CHAIN_MODE) {
if (priv->extend_desc) { if (priv->extend_desc) {
priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy, priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy,
rxsize, 1); DMA_RX_SIZE, 1);
priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy, priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy,
txsize, 1); DMA_TX_SIZE, 1);
} else { } else {
priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy, priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy,
rxsize, 0); DMA_RX_SIZE, 0);
priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy, priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy,
txsize, 0); DMA_TX_SIZE, 0);
} }
} }
/* TX INITIALIZATION */ /* TX INITIALIZATION */
for (i = 0; i < txsize; i++) { for (i = 0; i < DMA_TX_SIZE; i++) {
struct dma_desc *p; struct dma_desc *p;
if (priv->extend_desc) if (priv->extend_desc)
p = &((priv->dma_etx + i)->basic); p = &((priv->dma_etx + i)->basic);
...@@ -1123,7 +1116,7 @@ static void dma_free_rx_skbufs(struct stmmac_priv *priv) ...@@ -1123,7 +1116,7 @@ static void dma_free_rx_skbufs(struct stmmac_priv *priv)
{ {
int i; int i;
for (i = 0; i < priv->dma_rx_size; i++) for (i = 0; i < DMA_RX_SIZE; i++)
stmmac_free_rx_buffers(priv, i); stmmac_free_rx_buffers(priv, i);
} }
...@@ -1131,7 +1124,7 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv) ...@@ -1131,7 +1124,7 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
{ {
int i; int i;
for (i = 0; i < priv->dma_tx_size; i++) { for (i = 0; i < DMA_TX_SIZE; i++) {
struct dma_desc *p; struct dma_desc *p;
if (priv->extend_desc) if (priv->extend_desc)
...@@ -1171,33 +1164,31 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv) ...@@ -1171,33 +1164,31 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
*/ */
static int alloc_dma_desc_resources(struct stmmac_priv *priv) static int alloc_dma_desc_resources(struct stmmac_priv *priv)
{ {
unsigned int txsize = priv->dma_tx_size;
unsigned int rxsize = priv->dma_rx_size;
int ret = -ENOMEM; int ret = -ENOMEM;
priv->rx_skbuff_dma = kmalloc_array(rxsize, sizeof(dma_addr_t), priv->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE, sizeof(dma_addr_t),
GFP_KERNEL); GFP_KERNEL);
if (!priv->rx_skbuff_dma) if (!priv->rx_skbuff_dma)
return -ENOMEM; return -ENOMEM;
priv->rx_skbuff = kmalloc_array(rxsize, sizeof(struct sk_buff *), priv->rx_skbuff = kmalloc_array(DMA_RX_SIZE, sizeof(struct sk_buff *),
GFP_KERNEL); GFP_KERNEL);
if (!priv->rx_skbuff) if (!priv->rx_skbuff)
goto err_rx_skbuff; goto err_rx_skbuff;
priv->tx_skbuff_dma = kmalloc_array(txsize, priv->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE,
sizeof(*priv->tx_skbuff_dma), sizeof(*priv->tx_skbuff_dma),
GFP_KERNEL); GFP_KERNEL);
if (!priv->tx_skbuff_dma) if (!priv->tx_skbuff_dma)
goto err_tx_skbuff_dma; goto err_tx_skbuff_dma;
priv->tx_skbuff = kmalloc_array(txsize, sizeof(struct sk_buff *), priv->tx_skbuff = kmalloc_array(DMA_TX_SIZE, sizeof(struct sk_buff *),
GFP_KERNEL); GFP_KERNEL);
if (!priv->tx_skbuff) if (!priv->tx_skbuff)
goto err_tx_skbuff; goto err_tx_skbuff;
if (priv->extend_desc) { if (priv->extend_desc) {
priv->dma_erx = dma_zalloc_coherent(priv->device, rxsize * priv->dma_erx = dma_zalloc_coherent(priv->device, DMA_RX_SIZE *
sizeof(struct sizeof(struct
dma_extended_desc), dma_extended_desc),
&priv->dma_rx_phy, &priv->dma_rx_phy,
...@@ -1205,31 +1196,31 @@ static int alloc_dma_desc_resources(struct stmmac_priv *priv) ...@@ -1205,31 +1196,31 @@ static int alloc_dma_desc_resources(struct stmmac_priv *priv)
if (!priv->dma_erx) if (!priv->dma_erx)
goto err_dma; goto err_dma;
priv->dma_etx = dma_zalloc_coherent(priv->device, txsize * priv->dma_etx = dma_zalloc_coherent(priv->device, DMA_TX_SIZE *
sizeof(struct sizeof(struct
dma_extended_desc), dma_extended_desc),
&priv->dma_tx_phy, &priv->dma_tx_phy,
GFP_KERNEL); GFP_KERNEL);
if (!priv->dma_etx) { if (!priv->dma_etx) {
dma_free_coherent(priv->device, priv->dma_rx_size * dma_free_coherent(priv->device, DMA_RX_SIZE *
sizeof(struct dma_extended_desc), sizeof(struct dma_extended_desc),
priv->dma_erx, priv->dma_rx_phy); priv->dma_erx, priv->dma_rx_phy);
goto err_dma; goto err_dma;
} }
} else { } else {
priv->dma_rx = dma_zalloc_coherent(priv->device, rxsize * priv->dma_rx = dma_zalloc_coherent(priv->device, DMA_RX_SIZE *
sizeof(struct dma_desc), sizeof(struct dma_desc),
&priv->dma_rx_phy, &priv->dma_rx_phy,
GFP_KERNEL); GFP_KERNEL);
if (!priv->dma_rx) if (!priv->dma_rx)
goto err_dma; goto err_dma;
priv->dma_tx = dma_zalloc_coherent(priv->device, txsize * priv->dma_tx = dma_zalloc_coherent(priv->device, DMA_TX_SIZE *
sizeof(struct dma_desc), sizeof(struct dma_desc),
&priv->dma_tx_phy, &priv->dma_tx_phy,
GFP_KERNEL); GFP_KERNEL);
if (!priv->dma_tx) { if (!priv->dma_tx) {
dma_free_coherent(priv->device, priv->dma_rx_size * dma_free_coherent(priv->device, DMA_RX_SIZE *
sizeof(struct dma_desc), sizeof(struct dma_desc),
priv->dma_rx, priv->dma_rx_phy); priv->dma_rx, priv->dma_rx_phy);
goto err_dma; goto err_dma;
...@@ -1258,16 +1249,16 @@ static void free_dma_desc_resources(struct stmmac_priv *priv) ...@@ -1258,16 +1249,16 @@ static void free_dma_desc_resources(struct stmmac_priv *priv)
/* Free DMA regions of consistent memory previously allocated */ /* Free DMA regions of consistent memory previously allocated */
if (!priv->extend_desc) { if (!priv->extend_desc) {
dma_free_coherent(priv->device, dma_free_coherent(priv->device,
priv->dma_tx_size * sizeof(struct dma_desc), DMA_TX_SIZE * sizeof(struct dma_desc),
priv->dma_tx, priv->dma_tx_phy); priv->dma_tx, priv->dma_tx_phy);
dma_free_coherent(priv->device, dma_free_coherent(priv->device,
priv->dma_rx_size * sizeof(struct dma_desc), DMA_RX_SIZE * sizeof(struct dma_desc),
priv->dma_rx, priv->dma_rx_phy); priv->dma_rx, priv->dma_rx_phy);
} else { } else {
dma_free_coherent(priv->device, priv->dma_tx_size * dma_free_coherent(priv->device, DMA_TX_SIZE *
sizeof(struct dma_extended_desc), sizeof(struct dma_extended_desc),
priv->dma_etx, priv->dma_tx_phy); priv->dma_etx, priv->dma_tx_phy);
dma_free_coherent(priv->device, priv->dma_rx_size * dma_free_coherent(priv->device, DMA_RX_SIZE *
sizeof(struct dma_extended_desc), sizeof(struct dma_extended_desc),
priv->dma_erx, priv->dma_rx_phy); priv->dma_erx, priv->dma_rx_phy);
} }
...@@ -1312,16 +1303,15 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) ...@@ -1312,16 +1303,15 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
*/ */
static void stmmac_tx_clean(struct stmmac_priv *priv) static void stmmac_tx_clean(struct stmmac_priv *priv)
{ {
unsigned int txsize = priv->dma_tx_size;
unsigned int bytes_compl = 0, pkts_compl = 0; unsigned int bytes_compl = 0, pkts_compl = 0;
unsigned int entry = priv->dirty_tx;
spin_lock(&priv->tx_lock); spin_lock(&priv->tx_lock);
priv->xstats.tx_clean++; priv->xstats.tx_clean++;
while (priv->dirty_tx != priv->cur_tx) { while (entry != priv->cur_tx) {
int last; int last;
unsigned int entry = priv->dirty_tx % txsize;
struct sk_buff *skb = priv->tx_skbuff[entry]; struct sk_buff *skb = priv->tx_skbuff[entry];
struct dma_desc *p; struct dma_desc *p;
...@@ -1378,16 +1368,17 @@ static void stmmac_tx_clean(struct stmmac_priv *priv) ...@@ -1378,16 +1368,17 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
priv->hw->desc->release_tx_desc(p, priv->mode); priv->hw->desc->release_tx_desc(p, priv->mode);
priv->dirty_tx++; entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
priv->dirty_tx = entry;
} }
netdev_completed_queue(priv->dev, pkts_compl, bytes_compl); netdev_completed_queue(priv->dev, pkts_compl, bytes_compl);
if (unlikely(netif_queue_stopped(priv->dev) && if (unlikely(netif_queue_stopped(priv->dev) &&
stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) { stmmac_tx_avail(priv) > STMMAC_TX_THRESH)) {
netif_tx_lock(priv->dev); netif_tx_lock(priv->dev);
if (netif_queue_stopped(priv->dev) && if (netif_queue_stopped(priv->dev) &&
stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) { stmmac_tx_avail(priv) > STMMAC_TX_THRESH) {
if (netif_msg_tx_done(priv)) if (netif_msg_tx_done(priv))
pr_debug("%s: restart transmit\n", __func__); pr_debug("%s: restart transmit\n", __func__);
netif_wake_queue(priv->dev); netif_wake_queue(priv->dev);
...@@ -1421,20 +1412,19 @@ static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv) ...@@ -1421,20 +1412,19 @@ static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv)
static void stmmac_tx_err(struct stmmac_priv *priv) static void stmmac_tx_err(struct stmmac_priv *priv)
{ {
int i; int i;
int txsize = priv->dma_tx_size;
netif_stop_queue(priv->dev); netif_stop_queue(priv->dev);
priv->hw->dma->stop_tx(priv->ioaddr); priv->hw->dma->stop_tx(priv->ioaddr);
dma_free_tx_skbufs(priv); dma_free_tx_skbufs(priv);
for (i = 0; i < txsize; i++) for (i = 0; i < DMA_TX_SIZE; i++)
if (priv->extend_desc) if (priv->extend_desc)
priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic, priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
priv->mode, priv->mode,
(i == txsize - 1)); (i == DMA_TX_SIZE - 1));
else else
priv->hw->desc->init_tx_desc(&priv->dma_tx[i], priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
priv->mode, priv->mode,
(i == txsize - 1)); (i == DMA_TX_SIZE - 1));
priv->dirty_tx = 0; priv->dirty_tx = 0;
priv->cur_tx = 0; priv->cur_tx = 0;
netdev_reset_queue(priv->dev); netdev_reset_queue(priv->dev);
...@@ -1811,9 +1801,6 @@ static int stmmac_open(struct net_device *dev) ...@@ -1811,9 +1801,6 @@ static int stmmac_open(struct net_device *dev)
memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
priv->xstats.threshold = tc; priv->xstats.threshold = tc;
/* Create and initialize the TX/RX descriptors chains. */
priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
ret = alloc_dma_desc_resources(priv); ret = alloc_dma_desc_resources(priv);
...@@ -1955,7 +1942,6 @@ static int stmmac_release(struct net_device *dev) ...@@ -1955,7 +1942,6 @@ static int stmmac_release(struct net_device *dev)
static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct stmmac_priv *priv = netdev_priv(dev); struct stmmac_priv *priv = netdev_priv(dev);
unsigned int txsize = priv->dma_tx_size;
int entry; int entry;
int i, csum_insertion = 0, is_jumbo = 0; int i, csum_insertion = 0, is_jumbo = 0;
int nfrags = skb_shinfo(skb)->nr_frags; int nfrags = skb_shinfo(skb)->nr_frags;
...@@ -1978,7 +1964,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -1978,7 +1964,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
if (priv->tx_path_in_lpi_mode) if (priv->tx_path_in_lpi_mode)
stmmac_disable_eee_mode(priv); stmmac_disable_eee_mode(priv);
entry = priv->cur_tx % txsize; entry = priv->cur_tx;
csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL); csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
...@@ -2013,7 +2000,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -2013,7 +2000,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
int len = skb_frag_size(frag); int len = skb_frag_size(frag);
priv->tx_skbuff[entry] = NULL; priv->tx_skbuff[entry] = NULL;
entry = (++priv->cur_tx) % txsize; entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
if (priv->extend_desc) if (priv->extend_desc)
desc = (struct dma_desc *)(priv->dma_etx + entry); desc = (struct dma_desc *)(priv->dma_etx + entry);
else else
...@@ -2056,17 +2044,21 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -2056,17 +2044,21 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
priv->hw->desc->set_tx_owner(first); priv->hw->desc->set_tx_owner(first);
wmb(); wmb();
priv->cur_tx++; entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
priv->cur_tx = entry;
if (netif_msg_pktdata(priv)) { if (netif_msg_pktdata(priv)) {
pr_debug("%s: curr %d dirty=%d entry=%d, first=%p, nfrags=%d", pr_debug("%s: curr %d dirty=%d entry=%d, first=%p, nfrags=%d",
__func__, (priv->cur_tx % txsize), __func__, (priv->cur_tx % DMA_TX_SIZE),
(priv->dirty_tx % txsize), entry, first, nfrags); (priv->dirty_tx % DMA_TX_SIZE), entry, first, nfrags);
if (priv->extend_desc) if (priv->extend_desc)
stmmac_display_ring((void *)priv->dma_etx, txsize, 1); stmmac_display_ring((void *)priv->dma_etx,
DMA_TX_SIZE, 1);
else else
stmmac_display_ring((void *)priv->dma_tx, txsize, 0); stmmac_display_ring((void *)priv->dma_tx,
DMA_TX_SIZE, 0);
pr_debug(">>> frame to be transmitted: "); pr_debug(">>> frame to be transmitted: ");
print_pkt(skb->data, skb->len); print_pkt(skb->data, skb->len);
...@@ -2128,11 +2120,11 @@ static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) ...@@ -2128,11 +2120,11 @@ static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
*/ */
static inline void stmmac_rx_refill(struct stmmac_priv *priv) static inline void stmmac_rx_refill(struct stmmac_priv *priv)
{ {
unsigned int rxsize = priv->dma_rx_size;
int bfsize = priv->dma_buf_sz; int bfsize = priv->dma_buf_sz;
unsigned int entry = priv->dirty_rx;
int dirty = stmmac_rx_dirty(priv);
for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) { while (dirty-- > 0) {
unsigned int entry = priv->dirty_rx % rxsize;
struct dma_desc *p; struct dma_desc *p;
if (priv->extend_desc) if (priv->extend_desc)
...@@ -2168,7 +2160,10 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv) ...@@ -2168,7 +2160,10 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
wmb(); wmb();
priv->hw->desc->set_rx_owner(p); priv->hw->desc->set_rx_owner(p);
wmb(); wmb();
entry = STMMAC_GET_ENTRY(entry, DMA_RX_SIZE);
} }
priv->dirty_rx = entry;
} }
/** /**
...@@ -2180,8 +2175,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv) ...@@ -2180,8 +2175,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
*/ */
static int stmmac_rx(struct stmmac_priv *priv, int limit) static int stmmac_rx(struct stmmac_priv *priv, int limit)
{ {
unsigned int rxsize = priv->dma_rx_size; unsigned int entry = priv->cur_rx;
unsigned int entry = priv->cur_rx % rxsize;
unsigned int next_entry; unsigned int next_entry;
unsigned int count = 0; unsigned int count = 0;
int coe = priv->hw->rx_csum; int coe = priv->hw->rx_csum;
...@@ -2189,9 +2183,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit) ...@@ -2189,9 +2183,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
if (netif_msg_rx_status(priv)) { if (netif_msg_rx_status(priv)) {
pr_debug("%s: descriptor ring:\n", __func__); pr_debug("%s: descriptor ring:\n", __func__);
if (priv->extend_desc) if (priv->extend_desc)
stmmac_display_ring((void *)priv->dma_erx, rxsize, 1); stmmac_display_ring((void *)priv->dma_erx,
DMA_RX_SIZE, 1);
else else
stmmac_display_ring((void *)priv->dma_rx, rxsize, 0); stmmac_display_ring((void *)priv->dma_rx,
DMA_RX_SIZE, 0);
} }
while (count < limit) { while (count < limit) {
int status; int status;
...@@ -2207,7 +2203,9 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit) ...@@ -2207,7 +2203,9 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
count++; count++;
next_entry = (++priv->cur_rx) % rxsize; priv->cur_rx = STMMAC_GET_ENTRY(priv->cur_rx, DMA_RX_SIZE);
next_entry = priv->cur_rx;
if (priv->extend_desc) if (priv->extend_desc)
prefetch(priv->dma_erx + next_entry); prefetch(priv->dma_erx + next_entry);
else else
...@@ -2567,19 +2565,17 @@ static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v) ...@@ -2567,19 +2565,17 @@ static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
{ {
struct net_device *dev = seq->private; struct net_device *dev = seq->private;
struct stmmac_priv *priv = netdev_priv(dev); struct stmmac_priv *priv = netdev_priv(dev);
unsigned int txsize = priv->dma_tx_size;
unsigned int rxsize = priv->dma_rx_size;
if (priv->extend_desc) { if (priv->extend_desc) {
seq_printf(seq, "Extended RX descriptor ring:\n"); seq_printf(seq, "Extended RX descriptor ring:\n");
sysfs_display_ring((void *)priv->dma_erx, rxsize, 1, seq); sysfs_display_ring((void *)priv->dma_erx, DMA_RX_SIZE, 1, seq);
seq_printf(seq, "Extended TX descriptor ring:\n"); seq_printf(seq, "Extended TX descriptor ring:\n");
sysfs_display_ring((void *)priv->dma_etx, txsize, 1, seq); sysfs_display_ring((void *)priv->dma_etx, DMA_TX_SIZE, 1, seq);
} else { } else {
seq_printf(seq, "RX descriptor ring:\n"); seq_printf(seq, "RX descriptor ring:\n");
sysfs_display_ring((void *)priv->dma_rx, rxsize, 0, seq); sysfs_display_ring((void *)priv->dma_rx, DMA_RX_SIZE, 0, seq);
seq_printf(seq, "TX descriptor ring:\n"); seq_printf(seq, "TX descriptor ring:\n");
sysfs_display_ring((void *)priv->dma_tx, txsize, 0, seq); sysfs_display_ring((void *)priv->dma_tx, DMA_TX_SIZE, 0, seq);
} }
return 0; return 0;
...@@ -3149,12 +3145,6 @@ static int __init stmmac_cmdline_opt(char *str) ...@@ -3149,12 +3145,6 @@ static int __init stmmac_cmdline_opt(char *str)
} else if (!strncmp(opt, "phyaddr:", 8)) { } else if (!strncmp(opt, "phyaddr:", 8)) {
if (kstrtoint(opt + 8, 0, &phyaddr)) if (kstrtoint(opt + 8, 0, &phyaddr))
goto err; goto err;
} else if (!strncmp(opt, "dma_txsize:", 11)) {
if (kstrtoint(opt + 11, 0, &dma_txsize))
goto err;
} else if (!strncmp(opt, "dma_rxsize:", 11)) {
if (kstrtoint(opt + 11, 0, &dma_rxsize))
goto err;
} else if (!strncmp(opt, "buf_sz:", 7)) { } else if (!strncmp(opt, "buf_sz:", 7)) {
if (kstrtoint(opt + 7, 0, &buf_sz)) if (kstrtoint(opt + 7, 0, &buf_sz))
goto err; goto err;
......
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