Commit 2c520b1c authored by Jose Abreu's avatar Jose Abreu Committed by David S. Miller

net: stmmac: Switch stmmac_mode_ops to generic HW Interface Helpers

Switch stmmac_mode_ops to generic Hardware Interface Helpers instead of
using hard-coded callbacks. This makes the code more readable and more
flexible.

No functional change.
Signed-off-by: default avatarJose Abreu <joabreu@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cc4c9001
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "stmmac.h" #include "stmmac.h"
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) static int jumbo_frm(void *p, struct sk_buff *skb, int csum)
{ {
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p; struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
unsigned int nopaged_len = skb_headlen(skb); unsigned int nopaged_len = skb_headlen(skb);
...@@ -93,7 +93,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -93,7 +93,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
return entry; return entry;
} }
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc) static unsigned int is_jumbo_frm(int len, int enh_desc)
{ {
unsigned int ret = 0; unsigned int ret = 0;
...@@ -105,7 +105,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc) ...@@ -105,7 +105,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
return ret; return ret;
} }
static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr, static void init_dma_chain(void *des, dma_addr_t phy_addr,
unsigned int size, unsigned int extend_desc) unsigned int size, unsigned int extend_desc)
{ {
/* /*
...@@ -135,7 +135,7 @@ static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr, ...@@ -135,7 +135,7 @@ static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
} }
} }
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) static void refill_desc3(void *priv_ptr, struct dma_desc *p)
{ {
struct stmmac_rx_queue *rx_q = (struct stmmac_rx_queue *)priv_ptr; struct stmmac_rx_queue *rx_q = (struct stmmac_rx_queue *)priv_ptr;
struct stmmac_priv *priv = rx_q->priv_data; struct stmmac_priv *priv = rx_q->priv_data;
...@@ -151,7 +151,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -151,7 +151,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
sizeof(struct dma_desc))); sizeof(struct dma_desc)));
} }
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) static void clean_desc3(void *priv_ptr, struct dma_desc *p)
{ {
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr; struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
struct stmmac_priv *priv = tx_q->priv_data; struct stmmac_priv *priv = tx_q->priv_data;
...@@ -169,9 +169,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -169,9 +169,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
} }
const struct stmmac_mode_ops chain_mode_ops = { const struct stmmac_mode_ops chain_mode_ops = {
.init = stmmac_init_dma_chain, .init = init_dma_chain,
.is_jumbo_frm = stmmac_is_jumbo_frm, .is_jumbo_frm = is_jumbo_frm,
.jumbo_frm = stmmac_jumbo_frm, .jumbo_frm = jumbo_frm,
.refill_desc3 = stmmac_refill_desc3, .refill_desc3 = refill_desc3,
.clean_desc3 = stmmac_clean_desc3, .clean_desc3 = clean_desc3,
}; };
...@@ -405,18 +405,6 @@ struct mii_regs { ...@@ -405,18 +405,6 @@ struct mii_regs {
unsigned int clk_csr_mask; unsigned int clk_csr_mask;
}; };
/* Helpers to manage the descriptors for chain and ring modes */
struct stmmac_mode_ops {
void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
unsigned int extend_desc);
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
int (*set_16kib_bfsize)(int mtu);
void (*init_desc3)(struct dma_desc *p);
void (*refill_desc3) (void *priv, struct dma_desc *p);
void (*clean_desc3) (void *priv, struct dma_desc *p);
};
struct mac_device_info { struct mac_device_info {
const struct stmmac_ops *mac; const struct stmmac_ops *mac;
const struct stmmac_desc_ops *desc; const struct stmmac_desc_ops *desc;
......
...@@ -391,4 +391,31 @@ struct stmmac_hwtimestamp { ...@@ -391,4 +391,31 @@ struct stmmac_hwtimestamp {
#define stmmac_get_systime(__priv, __args...) \ #define stmmac_get_systime(__priv, __args...) \
stmmac_do_void_callback(__priv, ptp, get_systime, __args) stmmac_do_void_callback(__priv, ptp, get_systime, __args)
/* Helpers to manage the descriptors for chain and ring modes */
struct stmmac_mode_ops {
void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
unsigned int extend_desc);
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
int (*set_16kib_bfsize)(int mtu);
void (*init_desc3)(struct dma_desc *p);
void (*refill_desc3) (void *priv, struct dma_desc *p);
void (*clean_desc3) (void *priv, struct dma_desc *p);
};
#define stmmac_mode_init(__priv, __args...) \
stmmac_do_void_callback(__priv, mode, init, __args)
#define stmmac_is_jumbo_frm(__priv, __args...) \
stmmac_do_callback(__priv, mode, is_jumbo_frm, __args)
#define stmmac_jumbo_frm(__priv, __args...) \
stmmac_do_callback(__priv, mode, jumbo_frm, __args)
#define stmmac_set_16kib_bfsize(__priv, __args...) \
stmmac_do_callback(__priv, mode, set_16kib_bfsize, __args)
#define stmmac_init_desc3(__priv, __args...) \
stmmac_do_void_callback(__priv, mode, init_desc3, __args)
#define stmmac_refill_desc3(__priv, __args...) \
stmmac_do_void_callback(__priv, mode, refill_desc3, __args)
#define stmmac_clean_desc3(__priv, __args...) \
stmmac_do_void_callback(__priv, mode, clean_desc3, __args)
#endif /* __STMMAC_HWIF_H__ */ #endif /* __STMMAC_HWIF_H__ */
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "stmmac.h" #include "stmmac.h"
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) static int jumbo_frm(void *p, struct sk_buff *skb, int csum)
{ {
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p; struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
unsigned int nopaged_len = skb_headlen(skb); unsigned int nopaged_len = skb_headlen(skb);
...@@ -99,7 +99,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) ...@@ -99,7 +99,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
return entry; return entry;
} }
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc) static unsigned int is_jumbo_frm(int len, int enh_desc)
{ {
unsigned int ret = 0; unsigned int ret = 0;
...@@ -109,7 +109,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc) ...@@ -109,7 +109,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
return ret; return ret;
} }
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) static void refill_desc3(void *priv_ptr, struct dma_desc *p)
{ {
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
...@@ -119,12 +119,12 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -119,12 +119,12 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
} }
/* In ring mode we need to fill the desc3 because it is used as buffer */ /* In ring mode we need to fill the desc3 because it is used as buffer */
static void stmmac_init_desc3(struct dma_desc *p) static void init_desc3(struct dma_desc *p)
{ {
p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB); p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB);
} }
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) static void clean_desc3(void *priv_ptr, struct dma_desc *p)
{ {
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr; struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
struct stmmac_priv *priv = tx_q->priv_data; struct stmmac_priv *priv = tx_q->priv_data;
...@@ -137,7 +137,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) ...@@ -137,7 +137,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
p->des3 = 0; p->des3 = 0;
} }
static int stmmac_set_16kib_bfsize(int mtu) static int set_16kib_bfsize(int mtu)
{ {
int ret = 0; int ret = 0;
if (unlikely(mtu >= BUF_SIZE_8KiB)) if (unlikely(mtu >= BUF_SIZE_8KiB))
...@@ -146,10 +146,10 @@ static int stmmac_set_16kib_bfsize(int mtu) ...@@ -146,10 +146,10 @@ static int stmmac_set_16kib_bfsize(int mtu)
} }
const struct stmmac_mode_ops ring_mode_ops = { const struct stmmac_mode_ops ring_mode_ops = {
.is_jumbo_frm = stmmac_is_jumbo_frm, .is_jumbo_frm = is_jumbo_frm,
.jumbo_frm = stmmac_jumbo_frm, .jumbo_frm = jumbo_frm,
.refill_desc3 = stmmac_refill_desc3, .refill_desc3 = refill_desc3,
.init_desc3 = stmmac_init_desc3, .init_desc3 = init_desc3,
.clean_desc3 = stmmac_clean_desc3, .clean_desc3 = clean_desc3,
.set_16kib_bfsize = stmmac_set_16kib_bfsize, .set_16kib_bfsize = set_16kib_bfsize,
}; };
...@@ -1161,9 +1161,8 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p, ...@@ -1161,9 +1161,8 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
else else
p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[i]); p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[i]);
if ((priv->hw->mode->init_desc3) && if (priv->dma_buf_sz == BUF_SIZE_16KiB)
(priv->dma_buf_sz == BUF_SIZE_16KiB)) stmmac_init_desc3(priv, p);
priv->hw->mode->init_desc3(p);
return 0; return 0;
} }
...@@ -1229,13 +1228,14 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1229,13 +1228,14 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
{ {
struct stmmac_priv *priv = netdev_priv(dev); struct stmmac_priv *priv = netdev_priv(dev);
u32 rx_count = priv->plat->rx_queues_to_use; u32 rx_count = priv->plat->rx_queues_to_use;
unsigned int bfsize = 0;
int ret = -ENOMEM; int ret = -ENOMEM;
int bfsize = 0;
int queue; int queue;
int i; int i;
if (priv->hw->mode->set_16kib_bfsize) bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu); if (bfsize < 0)
bfsize = 0;
if (bfsize < BUF_SIZE_16KiB) if (bfsize < BUF_SIZE_16KiB)
bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
...@@ -1279,13 +1279,11 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) ...@@ -1279,13 +1279,11 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
/* 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(rx_q->dma_erx, stmmac_mode_init(priv, rx_q->dma_erx,
rx_q->dma_rx_phy, rx_q->dma_rx_phy, DMA_RX_SIZE, 1);
DMA_RX_SIZE, 1);
else else
priv->hw->mode->init(rx_q->dma_rx, stmmac_mode_init(priv, rx_q->dma_rx,
rx_q->dma_rx_phy, rx_q->dma_rx_phy, DMA_RX_SIZE, 0);
DMA_RX_SIZE, 0);
} }
} }
...@@ -1332,13 +1330,11 @@ static int init_dma_tx_desc_rings(struct net_device *dev) ...@@ -1332,13 +1330,11 @@ static int init_dma_tx_desc_rings(struct net_device *dev)
/* 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(tx_q->dma_etx, stmmac_mode_init(priv, tx_q->dma_etx,
tx_q->dma_tx_phy, tx_q->dma_tx_phy, DMA_TX_SIZE, 1);
DMA_TX_SIZE, 1);
else else
priv->hw->mode->init(tx_q->dma_tx, stmmac_mode_init(priv, tx_q->dma_tx,
tx_q->dma_tx_phy, tx_q->dma_tx_phy, DMA_TX_SIZE, 0);
DMA_TX_SIZE, 0);
} }
for (i = 0; i < DMA_TX_SIZE; i++) { for (i = 0; i < DMA_TX_SIZE; i++) {
...@@ -1886,8 +1882,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv, u32 queue) ...@@ -1886,8 +1882,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv, u32 queue)
tx_q->tx_skbuff_dma[entry].map_as_page = false; tx_q->tx_skbuff_dma[entry].map_as_page = false;
} }
if (priv->hw->mode->clean_desc3) stmmac_clean_desc3(priv, tx_q, p);
priv->hw->mode->clean_desc3(tx_q, p);
tx_q->tx_skbuff_dma[entry].last_segment = false; tx_q->tx_skbuff_dma[entry].last_segment = false;
tx_q->tx_skbuff_dma[entry].is_jumbo = false; tx_q->tx_skbuff_dma[entry].is_jumbo = false;
...@@ -3099,11 +3094,11 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -3099,11 +3094,11 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
enh_desc = priv->plat->enh_desc; enh_desc = priv->plat->enh_desc;
/* To program the descriptors according to the size of the frame */ /* To program the descriptors according to the size of the frame */
if (enh_desc) if (enh_desc)
is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc); is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);
if (unlikely(is_jumbo) && likely(priv->synopsys_id < if (unlikely(is_jumbo) && likely(priv->synopsys_id <
DWMAC_CORE_4_00)) { DWMAC_CORE_4_00)) {
entry = priv->hw->mode->jumbo_frm(tx_q, skb, csum_insertion); entry = stmmac_jumbo_frm(priv, tx_q, skb, csum_insertion);
if (unlikely(entry < 0)) if (unlikely(entry < 0))
goto dma_map_err; goto dma_map_err;
} }
...@@ -3332,8 +3327,8 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue) ...@@ -3332,8 +3327,8 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
} else { } else {
p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[entry]); p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[entry]);
} }
if (priv->hw->mode->refill_desc3)
priv->hw->mode->refill_desc3(rx_q, p); stmmac_refill_desc3(priv, rx_q, p);
if (rx_q->rx_zeroc_thresh > 0) if (rx_q->rx_zeroc_thresh > 0)
rx_q->rx_zeroc_thresh--; rx_q->rx_zeroc_thresh--;
......
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