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;
......
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