1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
7 #if IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP)
9 /* Timestamps are in units of 8 ns clock ticks (equivalent to
10 * a fixed 125 MHz clock).
12 #define SJA1105_TICK_NS 8
14 static inline s64
ns_to_sja1105_ticks(s64 ns
)
16 return ns
/ SJA1105_TICK_NS
;
19 static inline s64
sja1105_ticks_to_ns(s64 ticks
)
21 return ticks
* SJA1105_TICK_NS
;
24 struct sja1105_ptp_cmd
{
25 u64 ptpstrtsch
; /* start schedule */
26 u64 ptpstopsch
; /* stop schedule */
27 u64 resptp
; /* reset */
28 u64 corrclk4ts
; /* use the corrected clock for timestamps */
29 u64 ptpclkadd
; /* enum sja1105_ptp_clk_mode */
32 struct sja1105_ptp_data
{
33 struct sk_buff_head skb_rxtstamp_queue
;
34 struct ptp_clock_info caps
;
35 struct ptp_clock
*clock
;
36 struct sja1105_ptp_cmd cmd
;
37 /* Serializes all operations on the PTP hardware clock */
41 int sja1105_ptp_clock_register(struct dsa_switch
*ds
);
43 void sja1105_ptp_clock_unregister(struct dsa_switch
*ds
);
45 void sja1105et_ptp_cmd_packing(u8
*buf
, struct sja1105_ptp_cmd
*cmd
,
48 void sja1105pqrs_ptp_cmd_packing(u8
*buf
, struct sja1105_ptp_cmd
*cmd
,
51 int sja1105_get_ts_info(struct dsa_switch
*ds
, int port
,
52 struct ethtool_ts_info
*ts
);
54 void sja1105_ptp_txtstamp_skb(struct dsa_switch
*ds
, int slot
,
55 struct sk_buff
*clone
);
57 bool sja1105_port_rxtstamp(struct dsa_switch
*ds
, int port
,
58 struct sk_buff
*skb
, unsigned int type
);
60 bool sja1105_port_txtstamp(struct dsa_switch
*ds
, int port
,
61 struct sk_buff
*skb
, unsigned int type
);
63 int sja1105_hwtstamp_get(struct dsa_switch
*ds
, int port
, struct ifreq
*ifr
);
65 int sja1105_hwtstamp_set(struct dsa_switch
*ds
, int port
, struct ifreq
*ifr
);
67 int __sja1105_ptp_gettimex(struct dsa_switch
*ds
, u64
*ns
,
68 struct ptp_system_timestamp
*sts
);
70 int __sja1105_ptp_settime(struct dsa_switch
*ds
, u64 ns
,
71 struct ptp_system_timestamp
*ptp_sts
);
73 int __sja1105_ptp_adjtime(struct dsa_switch
*ds
, s64 delta
);
75 int sja1105_ptp_commit(struct dsa_switch
*ds
, struct sja1105_ptp_cmd
*cmd
,
76 sja1105_spi_rw_mode_t rw
);
80 struct sja1105_ptp_cmd
;
82 /* Structures cannot be empty in C. Bah!
83 * Keep the mutex as the only element, which is a bit more difficult to
84 * refactor out of sja1105_main.c anyway.
86 struct sja1105_ptp_data
{
90 static inline int sja1105_ptp_clock_register(struct dsa_switch
*ds
)
95 static inline void sja1105_ptp_clock_unregister(struct dsa_switch
*ds
) { }
97 static inline void sja1105_ptp_txtstamp_skb(struct dsa_switch
*ds
, int slot
,
98 struct sk_buff
*clone
)
102 static inline int __sja1105_ptp_gettimex(struct dsa_switch
*ds
, u64
*ns
,
103 struct ptp_system_timestamp
*sts
)
108 static inline int __sja1105_ptp_settime(struct dsa_switch
*ds
, u64 ns
,
109 struct ptp_system_timestamp
*ptp_sts
)
114 static inline int __sja1105_ptp_adjtime(struct dsa_switch
*ds
, s64 delta
)
119 static inline int sja1105_ptp_commit(struct dsa_switch
*ds
,
120 struct sja1105_ptp_cmd
*cmd
,
121 sja1105_spi_rw_mode_t rw
)
126 #define sja1105et_ptp_cmd_packing NULL
128 #define sja1105pqrs_ptp_cmd_packing NULL
130 #define sja1105_get_ts_info NULL
132 #define sja1105_port_rxtstamp NULL
134 #define sja1105_port_txtstamp NULL
136 #define sja1105_hwtstamp_get NULL
138 #define sja1105_hwtstamp_set NULL
140 #endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP) */
142 #endif /* _SJA1105_PTP_H */