Skip to content

Commit cc4c900

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Switch stmmac_hwtimestamp to generic HW Interface Helpers
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 <[email protected]> Cc: David S. Miller <[email protected]> Cc: Joao Pinto <[email protected]> Cc: Giuseppe Cavallaro <[email protected]> Cc: Alexandre Torgue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c10d4c8 commit cc4c900

File tree

5 files changed

+56
-50
lines changed

5 files changed

+56
-50
lines changed

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,6 @@ extern const struct stmmac_desc_ops ndesc_ops;
383383

384384
struct mac_device_info;
385385

386-
/* PTP and HW Timer helpers */
387-
struct stmmac_hwtimestamp {
388-
void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
389-
u32 (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
390-
int gmac4);
391-
int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
392-
int (*config_addend) (void __iomem *ioaddr, u32 addend);
393-
int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
394-
int add_sub, int gmac4);
395-
u64(*get_systime) (void __iomem *ioaddr);
396-
};
397-
398386
extern const struct stmmac_hwtimestamp stmmac_ptp;
399387
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
400388

drivers/net/ethernet/stmicro/stmmac/hwif.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,29 @@ struct stmmac_ops {
366366
#define stmmac_safety_feat_dump(__priv, __args...) \
367367
stmmac_do_callback(__priv, mac, safety_feat_dump, __args)
368368

369+
/* PTP and HW Timer helpers */
370+
struct stmmac_hwtimestamp {
371+
void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
372+
void (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
373+
int gmac4, u32 *ssinc);
374+
int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
375+
int (*config_addend) (void __iomem *ioaddr, u32 addend);
376+
int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
377+
int add_sub, int gmac4);
378+
void (*get_systime) (void __iomem *ioaddr, u64 *systime);
379+
};
380+
381+
#define stmmac_config_hw_tstamping(__priv, __args...) \
382+
stmmac_do_void_callback(__priv, ptp, config_hw_tstamping, __args)
383+
#define stmmac_config_sub_second_increment(__priv, __args...) \
384+
stmmac_do_void_callback(__priv, ptp, config_sub_second_increment, __args)
385+
#define stmmac_init_systime(__priv, __args...) \
386+
stmmac_do_callback(__priv, ptp, init_systime, __args)
387+
#define stmmac_config_addend(__priv, __args...) \
388+
stmmac_do_callback(__priv, ptp, config_addend, __args)
389+
#define stmmac_adjust_systime(__priv, __args...) \
390+
stmmac_do_callback(__priv, ptp, adjust_systime, __args)
391+
#define stmmac_get_systime(__priv, __args...) \
392+
stmmac_do_void_callback(__priv, ptp, get_systime, __args)
393+
369394
#endif /* __STMMAC_HWIF_H__ */

drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
#include "common.h"
2525
#include "stmmac_ptp.h"
2626

27-
static void stmmac_config_hw_tstamping(void __iomem *ioaddr, u32 data)
27+
static void config_hw_tstamping(void __iomem *ioaddr, u32 data)
2828
{
2929
writel(data, ioaddr + PTP_TCR);
3030
}
3131

32-
static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr,
33-
u32 ptp_clock, int gmac4)
32+
static void config_sub_second_increment(void __iomem *ioaddr,
33+
u32 ptp_clock, int gmac4, u32 *ssinc)
3434
{
3535
u32 value = readl(ioaddr + PTP_TCR);
3636
unsigned long data;
@@ -57,10 +57,11 @@ static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr,
5757

5858
writel(reg_value, ioaddr + PTP_SSIR);
5959

60-
return data;
60+
if (ssinc)
61+
*ssinc = data;
6162
}
6263

63-
static int stmmac_init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
64+
static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
6465
{
6566
int limit;
6667
u32 value;
@@ -85,7 +86,7 @@ static int stmmac_init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
8586
return 0;
8687
}
8788

88-
static int stmmac_config_addend(void __iomem *ioaddr, u32 addend)
89+
static int config_addend(void __iomem *ioaddr, u32 addend)
8990
{
9091
u32 value;
9192
int limit;
@@ -109,8 +110,8 @@ static int stmmac_config_addend(void __iomem *ioaddr, u32 addend)
109110
return 0;
110111
}
111112

112-
static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
113-
int add_sub, int gmac4)
113+
static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
114+
int add_sub, int gmac4)
114115
{
115116
u32 value;
116117
int limit;
@@ -152,7 +153,7 @@ static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
152153
return 0;
153154
}
154155

155-
static u64 stmmac_get_systime(void __iomem *ioaddr)
156+
static void get_systime(void __iomem *ioaddr, u64 *systime)
156157
{
157158
u64 ns;
158159

@@ -161,14 +162,15 @@ static u64 stmmac_get_systime(void __iomem *ioaddr)
161162
/* Get the TSS and convert sec time value to nanosecond */
162163
ns += readl(ioaddr + PTP_STSR) * 1000000000ULL;
163164

164-
return ns;
165+
if (systime)
166+
*systime = ns;
165167
}
166168

167169
const struct stmmac_hwtimestamp stmmac_ptp = {
168-
.config_hw_tstamping = stmmac_config_hw_tstamping,
169-
.init_systime = stmmac_init_systime,
170-
.config_sub_second_increment = stmmac_config_sub_second_increment,
171-
.config_addend = stmmac_config_addend,
172-
.adjust_systime = stmmac_adjust_systime,
173-
.get_systime = stmmac_get_systime,
170+
.config_hw_tstamping = config_hw_tstamping,
171+
.init_systime = init_systime,
172+
.config_sub_second_increment = config_sub_second_increment,
173+
.config_addend = config_addend,
174+
.adjust_systime = adjust_systime,
175+
.get_systime = get_systime,
174176
};

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,18 +707,18 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
707707
priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
708708

709709
if (!priv->hwts_tx_en && !priv->hwts_rx_en)
710-
priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, 0);
710+
stmmac_config_hw_tstamping(priv, priv->ptpaddr, 0);
711711
else {
712712
value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
713713
tstamp_all | ptp_v2 | ptp_over_ethernet |
714714
ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
715715
ts_master_en | snap_type_sel);
716-
priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, value);
716+
stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
717717

718718
/* program Sub Second Increment reg */
719-
sec_inc = priv->hw->ptp->config_sub_second_increment(
720-
priv->ptpaddr, priv->plat->clk_ptp_rate,
721-
priv->plat->has_gmac4);
719+
stmmac_config_sub_second_increment(priv,
720+
priv->ptpaddr, priv->plat->clk_ptp_rate,
721+
priv->plat->has_gmac4, &sec_inc);
722722
temp = div_u64(1000000000ULL, sec_inc);
723723

724724
/* calculate default added value:
@@ -728,15 +728,14 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
728728
*/
729729
temp = (u64)(temp << 32);
730730
priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
731-
priv->hw->ptp->config_addend(priv->ptpaddr,
732-
priv->default_addend);
731+
stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
733732

734733
/* initialize system time */
735734
ktime_get_real_ts64(&now);
736735

737736
/* lower 32 bits of tv_sec are safe until y2106 */
738-
priv->hw->ptp->init_systime(priv->ptpaddr, (u32)now.tv_sec,
739-
now.tv_nsec);
737+
stmmac_init_systime(priv, priv->ptpaddr,
738+
(u32)now.tv_sec, now.tv_nsec);
740739
}
741740

742741
return copy_to_user(ifr->ifr_data, &config,

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ static int stmmac_adjust_freq(struct ptp_clock_info *ptp, s32 ppb)
4949
addend = neg_adj ? (addend - diff) : (addend + diff);
5050

5151
spin_lock_irqsave(&priv->ptp_lock, flags);
52-
53-
priv->hw->ptp->config_addend(priv->ptpaddr, addend);
54-
52+
stmmac_config_addend(priv, priv->ptpaddr, addend);
5553
spin_unlock_irqrestore(&priv->ptp_lock, flags);
5654

5755
return 0;
@@ -84,10 +82,8 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
8482
nsec = reminder;
8583

8684
spin_lock_irqsave(&priv->ptp_lock, flags);
87-
88-
priv->hw->ptp->adjust_systime(priv->ptpaddr, sec, nsec, neg_adj,
89-
priv->plat->has_gmac4);
90-
85+
stmmac_adjust_systime(priv, priv->ptpaddr, sec, nsec, neg_adj,
86+
priv->plat->has_gmac4);
9187
spin_unlock_irqrestore(&priv->ptp_lock, flags);
9288

9389
return 0;
@@ -110,9 +106,7 @@ static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts)
110106
u64 ns;
111107

112108
spin_lock_irqsave(&priv->ptp_lock, flags);
113-
114-
ns = priv->hw->ptp->get_systime(priv->ptpaddr);
115-
109+
stmmac_get_systime(priv, priv->ptpaddr, &ns);
116110
spin_unlock_irqrestore(&priv->ptp_lock, flags);
117111

118112
*ts = ns_to_timespec64(ns);
@@ -137,9 +131,7 @@ static int stmmac_set_time(struct ptp_clock_info *ptp,
137131
unsigned long flags;
138132

139133
spin_lock_irqsave(&priv->ptp_lock, flags);
140-
141-
priv->hw->ptp->init_systime(priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
142-
134+
stmmac_init_systime(priv, priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
143135
spin_unlock_irqrestore(&priv->ptp_lock, flags);
144136

145137
return 0;

0 commit comments

Comments
 (0)