net: stmmac: Switch stmmac_mode_ops to generic HW Interface Helpers
authorJose Abreu <Jose.Abreu@synopsys.com>
Mon, 16 Apr 2018 15:08:16 +0000 (16:08 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Apr 2018 22:50:03 +0000 (18:50 -0400)
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: Jose 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: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/chain_mode.c
drivers/net/ethernet/stmicro/stmmac/common.h
drivers/net/ethernet/stmicro/stmmac/hwif.h
drivers/net/ethernet/stmicro/stmmac/ring_mode.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index ca0f9c205f9dc6c067551bca8b18396dd3c0a570..b9c9003060c503df1d724d77cff85e5bb6ae8fbe 100644 (file)
@@ -24,7 +24,7 @@
 
 #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;
        unsigned int nopaged_len = skb_headlen(skb);
@@ -93,7 +93,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
        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;
 
@@ -105,7 +105,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
        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)
 {
        /*
@@ -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_priv *priv = rx_q->priv_data;
@@ -151,7 +151,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
                                      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_priv *priv = tx_q->priv_data;
@@ -169,9 +169,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
 }
 
 const struct stmmac_mode_ops chain_mode_ops = {
-       .init = stmmac_init_dma_chain,
-       .is_jumbo_frm = stmmac_is_jumbo_frm,
-       .jumbo_frm = stmmac_jumbo_frm,
-       .refill_desc3 = stmmac_refill_desc3,
-       .clean_desc3 = stmmac_clean_desc3,
+       .init = init_dma_chain,
+       .is_jumbo_frm = is_jumbo_frm,
+       .jumbo_frm = jumbo_frm,
+       .refill_desc3 = refill_desc3,
+       .clean_desc3 = clean_desc3,
 };
index 7291561ad217c8eabee6e227205ad964e2d01f97..59673c6d2e52dc19b3584f28f4aa492319e19cb4 100644 (file)
@@ -405,18 +405,6 @@ struct mii_regs {
        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 {
        const struct stmmac_ops *mac;
        const struct stmmac_desc_ops *desc;
index e23c0a3448bbada7a2e47a847ca1db0ab4893e5e..f81ded4a9946cf33dca4dfde15304652cb94aa34 100644 (file)
@@ -391,4 +391,31 @@ struct stmmac_hwtimestamp {
 #define stmmac_get_systime(__priv, __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__ */
index 808ca758d0aeb888c3b7df825dd8fd92643e93ee..a7ffc73fffe82b057d2d5d036dc3c52a6e7e53e7 100644 (file)
@@ -24,7 +24,7 @@
 
 #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;
        unsigned int nopaged_len = skb_headlen(skb);
@@ -99,7 +99,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
        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;
 
@@ -109,7 +109,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
        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;
 
@@ -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 */
-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);
 }
 
-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_priv *priv = tx_q->priv_data;
@@ -137,7 +137,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
                p->des3 = 0;
 }
 
-static int stmmac_set_16kib_bfsize(int mtu)
+static int set_16kib_bfsize(int mtu)
 {
        int ret = 0;
        if (unlikely(mtu >= BUF_SIZE_8KiB))
@@ -146,10 +146,10 @@ static int stmmac_set_16kib_bfsize(int mtu)
 }
 
 const struct stmmac_mode_ops ring_mode_ops = {
-       .is_jumbo_frm = stmmac_is_jumbo_frm,
-       .jumbo_frm = stmmac_jumbo_frm,
-       .refill_desc3 = stmmac_refill_desc3,
-       .init_desc3 = stmmac_init_desc3,
-       .clean_desc3 = stmmac_clean_desc3,
-       .set_16kib_bfsize = stmmac_set_16kib_bfsize,
+       .is_jumbo_frm = is_jumbo_frm,
+       .jumbo_frm = jumbo_frm,
+       .refill_desc3 = refill_desc3,
+       .init_desc3 = init_desc3,
+       .clean_desc3 = clean_desc3,
+       .set_16kib_bfsize = set_16kib_bfsize,
 };
index 896a1e76f2ec0a364a704f51e5d8f47f8ab650ce..90363a8b15db549baf41e60856b565a3f864433c 100644 (file)
@@ -1161,9 +1161,8 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
        else
                p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[i]);
 
-       if ((priv->hw->mode->init_desc3) &&
-           (priv->dma_buf_sz == BUF_SIZE_16KiB))
-               priv->hw->mode->init_desc3(p);
+       if (priv->dma_buf_sz == BUF_SIZE_16KiB)
+               stmmac_init_desc3(priv, p);
 
        return 0;
 }
@@ -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);
        u32 rx_count = priv->plat->rx_queues_to_use;
-       unsigned int bfsize = 0;
        int ret = -ENOMEM;
+       int bfsize = 0;
        int queue;
        int i;
 
-       if (priv->hw->mode->set_16kib_bfsize)
-               bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
+       bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
+       if (bfsize < 0)
+               bfsize = 0;
 
        if (bfsize < BUF_SIZE_16KiB)
                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)
                /* Setup the chained descriptor addresses */
                if (priv->mode == STMMAC_CHAIN_MODE) {
                        if (priv->extend_desc)
-                               priv->hw->mode->init(rx_q->dma_erx,
-                                                    rx_q->dma_rx_phy,
-                                                    DMA_RX_SIZE, 1);
+                               stmmac_mode_init(priv, rx_q->dma_erx,
+                                               rx_q->dma_rx_phy, DMA_RX_SIZE, 1);
                        else
-                               priv->hw->mode->init(rx_q->dma_rx,
-                                                    rx_q->dma_rx_phy,
-                                                    DMA_RX_SIZE, 0);
+                               stmmac_mode_init(priv, rx_q->dma_rx,
+                                               rx_q->dma_rx_phy, DMA_RX_SIZE, 0);
                }
        }
 
@@ -1332,13 +1330,11 @@ static int init_dma_tx_desc_rings(struct net_device *dev)
                /* Setup the chained descriptor addresses */
                if (priv->mode == STMMAC_CHAIN_MODE) {
                        if (priv->extend_desc)
-                               priv->hw->mode->init(tx_q->dma_etx,
-                                                    tx_q->dma_tx_phy,
-                                                    DMA_TX_SIZE, 1);
+                               stmmac_mode_init(priv, tx_q->dma_etx,
+                                               tx_q->dma_tx_phy, DMA_TX_SIZE, 1);
                        else
-                               priv->hw->mode->init(tx_q->dma_tx,
-                                                    tx_q->dma_tx_phy,
-                                                    DMA_TX_SIZE, 0);
+                               stmmac_mode_init(priv, tx_q->dma_tx,
+                                               tx_q->dma_tx_phy, DMA_TX_SIZE, 0);
                }
 
                for (i = 0; i < DMA_TX_SIZE; i++) {
@@ -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;
                }
 
-               if (priv->hw->mode->clean_desc3)
-                       priv->hw->mode->clean_desc3(tx_q, p);
+               stmmac_clean_desc3(priv, tx_q, p);
 
                tx_q->tx_skbuff_dma[entry].last_segment = 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)
        enh_desc = priv->plat->enh_desc;
        /* To program the descriptors according to the size of the frame */
        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 <
                                         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))
                        goto dma_map_err;
        }
@@ -3332,8 +3327,8 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
                        } else {
                                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)
                                rx_q->rx_zeroc_thresh--;