]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: stmmac: Switch stmmac_hwtimestamp to generic HW Interface Helpers
authorJose Abreu <Jose.Abreu@synopsys.com>
Mon, 16 Apr 2018 15:08:15 +0000 (16:08 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Apr 2018 22:49:55 +0000 (18:49 -0400)
Switch stmmac_hwtimestamp 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/common.h
drivers/net/ethernet/stmicro/stmmac/hwif.h
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

index 0e0b6f19104d7c2ce88c897667356a296ded2079..7291561ad217c8eabee6e227205ad964e2d01f97 100644 (file)
@@ -383,18 +383,6 @@ extern const struct stmmac_desc_ops ndesc_ops;
 
 struct mac_device_info;
 
-/* PTP and HW Timer helpers */
-struct stmmac_hwtimestamp {
-       void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
-       u32 (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
-                                          int gmac4);
-       int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
-       int (*config_addend) (void __iomem *ioaddr, u32 addend);
-       int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
-                              int add_sub, int gmac4);
-        u64(*get_systime) (void __iomem *ioaddr);
-};
-
 extern const struct stmmac_hwtimestamp stmmac_ptp;
 extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
 
index 9575135c06998ef6294551ffbd251402acb27959..e23c0a3448bbada7a2e47a847ca1db0ab4893e5e 100644 (file)
@@ -366,4 +366,29 @@ struct stmmac_ops {
 #define stmmac_safety_feat_dump(__priv, __args...) \
        stmmac_do_callback(__priv, mac, safety_feat_dump, __args)
 
+/* PTP and HW Timer helpers */
+struct stmmac_hwtimestamp {
+       void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
+       void (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
+                                          int gmac4, u32 *ssinc);
+       int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
+       int (*config_addend) (void __iomem *ioaddr, u32 addend);
+       int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
+                              int add_sub, int gmac4);
+       void (*get_systime) (void __iomem *ioaddr, u64 *systime);
+};
+
+#define stmmac_config_hw_tstamping(__priv, __args...) \
+       stmmac_do_void_callback(__priv, ptp, config_hw_tstamping, __args)
+#define stmmac_config_sub_second_increment(__priv, __args...) \
+       stmmac_do_void_callback(__priv, ptp, config_sub_second_increment, __args)
+#define stmmac_init_systime(__priv, __args...) \
+       stmmac_do_callback(__priv, ptp, init_systime, __args)
+#define stmmac_config_addend(__priv, __args...) \
+       stmmac_do_callback(__priv, ptp, config_addend, __args)
+#define stmmac_adjust_systime(__priv, __args...) \
+       stmmac_do_callback(__priv, ptp, adjust_systime, __args)
+#define stmmac_get_systime(__priv, __args...) \
+       stmmac_do_void_callback(__priv, ptp, get_systime, __args)
+
 #endif /* __STMMAC_HWIF_H__ */
index 08c19ebd530674972ceb9ebcb41cd7af4b3fb58d..8d9cc2157afd103c4d0282c8b74973d6c8f6256e 100644 (file)
 #include "common.h"
 #include "stmmac_ptp.h"
 
-static void stmmac_config_hw_tstamping(void __iomem *ioaddr, u32 data)
+static void config_hw_tstamping(void __iomem *ioaddr, u32 data)
 {
        writel(data, ioaddr + PTP_TCR);
 }
 
-static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr,
-                                             u32 ptp_clock, int gmac4)
+static void config_sub_second_increment(void __iomem *ioaddr,
+               u32 ptp_clock, int gmac4, u32 *ssinc)
 {
        u32 value = readl(ioaddr + PTP_TCR);
        unsigned long data;
@@ -57,10 +57,11 @@ static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr,
 
        writel(reg_value, ioaddr + PTP_SSIR);
 
-       return data;
+       if (ssinc)
+               *ssinc = data;
 }
 
-static int stmmac_init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
+static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
 {
        int limit;
        u32 value;
@@ -85,7 +86,7 @@ static int stmmac_init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
        return 0;
 }
 
-static int stmmac_config_addend(void __iomem *ioaddr, u32 addend)
+static int config_addend(void __iomem *ioaddr, u32 addend)
 {
        u32 value;
        int limit;
@@ -109,8 +110,8 @@ static int stmmac_config_addend(void __iomem *ioaddr, u32 addend)
        return 0;
 }
 
-static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
-                                int add_sub, int gmac4)
+static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
+               int add_sub, int gmac4)
 {
        u32 value;
        int limit;
@@ -152,7 +153,7 @@ static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
        return 0;
 }
 
-static u64 stmmac_get_systime(void __iomem *ioaddr)
+static void get_systime(void __iomem *ioaddr, u64 *systime)
 {
        u64 ns;
 
@@ -161,14 +162,15 @@ static u64 stmmac_get_systime(void __iomem *ioaddr)
        /* Get the TSS and convert sec time value to nanosecond */
        ns += readl(ioaddr + PTP_STSR) * 1000000000ULL;
 
-       return ns;
+       if (systime)
+               *systime = ns;
 }
 
 const struct stmmac_hwtimestamp stmmac_ptp = {
-       .config_hw_tstamping = stmmac_config_hw_tstamping,
-       .init_systime = stmmac_init_systime,
-       .config_sub_second_increment = stmmac_config_sub_second_increment,
-       .config_addend = stmmac_config_addend,
-       .adjust_systime = stmmac_adjust_systime,
-       .get_systime = stmmac_get_systime,
+       .config_hw_tstamping = config_hw_tstamping,
+       .init_systime = init_systime,
+       .config_sub_second_increment = config_sub_second_increment,
+       .config_addend = config_addend,
+       .adjust_systime = adjust_systime,
+       .get_systime = get_systime,
 };
index 2b521035185d358fa87189585095bca96f44a7a6..896a1e76f2ec0a364a704f51e5d8f47f8ab650ce 100644 (file)
@@ -707,18 +707,18 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
        priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
 
        if (!priv->hwts_tx_en && !priv->hwts_rx_en)
-               priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, 0);
+               stmmac_config_hw_tstamping(priv, priv->ptpaddr, 0);
        else {
                value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
                         tstamp_all | ptp_v2 | ptp_over_ethernet |
                         ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
                         ts_master_en | snap_type_sel);
-               priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, value);
+               stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
 
                /* program Sub Second Increment reg */
-               sec_inc = priv->hw->ptp->config_sub_second_increment(
-                       priv->ptpaddr, priv->plat->clk_ptp_rate,
-                       priv->plat->has_gmac4);
+               stmmac_config_sub_second_increment(priv,
+                               priv->ptpaddr, priv->plat->clk_ptp_rate,
+                               priv->plat->has_gmac4, &sec_inc);
                temp = div_u64(1000000000ULL, sec_inc);
 
                /* calculate default added value:
@@ -728,15 +728,14 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
                 */
                temp = (u64)(temp << 32);
                priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
-               priv->hw->ptp->config_addend(priv->ptpaddr,
-                                            priv->default_addend);
+               stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
 
                /* initialize system time */
                ktime_get_real_ts64(&now);
 
                /* lower 32 bits of tv_sec are safe until y2106 */
-               priv->hw->ptp->init_systime(priv->ptpaddr, (u32)now.tv_sec,
-                                           now.tv_nsec);
+               stmmac_init_systime(priv, priv->ptpaddr,
+                               (u32)now.tv_sec, now.tv_nsec);
        }
 
        return copy_to_user(ifr->ifr_data, &config,
index e471a903c6543f8f29c817cc0f7c8b5c474e3cec..7d3a5c7f5db6bee097b5f2a0fb03c9bee3930315 100644 (file)
@@ -49,9 +49,7 @@ static int stmmac_adjust_freq(struct ptp_clock_info *ptp, s32 ppb)
        addend = neg_adj ? (addend - diff) : (addend + diff);
 
        spin_lock_irqsave(&priv->ptp_lock, flags);
-
-       priv->hw->ptp->config_addend(priv->ptpaddr, addend);
-
+       stmmac_config_addend(priv, priv->ptpaddr, addend);
        spin_unlock_irqrestore(&priv->ptp_lock, flags);
 
        return 0;
@@ -84,10 +82,8 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
        nsec = reminder;
 
        spin_lock_irqsave(&priv->ptp_lock, flags);
-
-       priv->hw->ptp->adjust_systime(priv->ptpaddr, sec, nsec, neg_adj,
-                                     priv->plat->has_gmac4);
-
+       stmmac_adjust_systime(priv, priv->ptpaddr, sec, nsec, neg_adj,
+                       priv->plat->has_gmac4);
        spin_unlock_irqrestore(&priv->ptp_lock, flags);
 
        return 0;
@@ -110,9 +106,7 @@ static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts)
        u64 ns;
 
        spin_lock_irqsave(&priv->ptp_lock, flags);
-
-       ns = priv->hw->ptp->get_systime(priv->ptpaddr);
-
+       stmmac_get_systime(priv, priv->ptpaddr, &ns);
        spin_unlock_irqrestore(&priv->ptp_lock, flags);
 
        *ts = ns_to_timespec64(ns);
@@ -137,9 +131,7 @@ static int stmmac_set_time(struct ptp_clock_info *ptp,
        unsigned long flags;
 
        spin_lock_irqsave(&priv->ptp_lock, flags);
-
-       priv->hw->ptp->init_systime(priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
-
+       stmmac_init_systime(priv, priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
        spin_unlock_irqrestore(&priv->ptp_lock, flags);
 
        return 0;