]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/net/dsa/sja1105/sja1105_ptp.h
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 ptp_clock_info caps
;
34 struct ptp_clock
*clock
;
35 struct sja1105_ptp_cmd cmd
;
36 /* Serializes all operations on the PTP hardware clock */
40 int sja1105_ptp_clock_register(struct dsa_switch
*ds
);
42 void sja1105_ptp_clock_unregister(struct dsa_switch
*ds
);
44 void sja1105et_ptp_cmd_packing(u8
*buf
, struct sja1105_ptp_cmd
*cmd
,
47 void sja1105pqrs_ptp_cmd_packing(u8
*buf
, struct sja1105_ptp_cmd
*cmd
,
50 int sja1105_get_ts_info(struct dsa_switch
*ds
, int port
,
51 struct ethtool_ts_info
*ts
);
53 void sja1105_ptp_txtstamp_skb(struct dsa_switch
*ds
, int slot
,
54 struct sk_buff
*clone
);
56 bool sja1105_port_rxtstamp(struct dsa_switch
*ds
, int port
,
57 struct sk_buff
*skb
, unsigned int type
);
59 bool sja1105_port_txtstamp(struct dsa_switch
*ds
, int port
,
60 struct sk_buff
*skb
, unsigned int type
);
62 int sja1105_hwtstamp_get(struct dsa_switch
*ds
, int port
, struct ifreq
*ifr
);
64 int sja1105_hwtstamp_set(struct dsa_switch
*ds
, int port
, struct ifreq
*ifr
);
66 int __sja1105_ptp_gettimex(struct dsa_switch
*ds
, u64
*ns
,
67 struct ptp_system_timestamp
*sts
);
69 int __sja1105_ptp_settime(struct dsa_switch
*ds
, u64 ns
,
70 struct ptp_system_timestamp
*ptp_sts
);
72 int __sja1105_ptp_adjtime(struct dsa_switch
*ds
, s64 delta
);
74 int sja1105_ptp_commit(struct dsa_switch
*ds
, struct sja1105_ptp_cmd
*cmd
,
75 sja1105_spi_rw_mode_t rw
);
79 struct sja1105_ptp_cmd
;
81 /* Structures cannot be empty in C. Bah!
82 * Keep the mutex as the only element, which is a bit more difficult to
83 * refactor out of sja1105_main.c anyway.
85 struct sja1105_ptp_data
{
89 static inline int sja1105_ptp_clock_register(struct dsa_switch
*ds
)
94 static inline void sja1105_ptp_clock_unregister(struct dsa_switch
*ds
) { }
96 static inline void sja1105_ptp_txtstamp_skb(struct dsa_switch
*ds
, int slot
,
97 struct sk_buff
*clone
)
101 static inline int __sja1105_ptp_gettimex(struct dsa_switch
*ds
, u64
*ns
,
102 struct ptp_system_timestamp
*sts
)
107 static inline int __sja1105_ptp_settime(struct dsa_switch
*ds
, u64 ns
,
108 struct ptp_system_timestamp
*ptp_sts
)
113 static inline int __sja1105_ptp_adjtime(struct dsa_switch
*ds
, s64 delta
)
118 static inline int sja1105_ptp_commit(struct dsa_switch
*ds
,
119 struct sja1105_ptp_cmd
*cmd
,
120 sja1105_spi_rw_mode_t rw
)
125 #define sja1105et_ptp_cmd_packing NULL
127 #define sja1105pqrs_ptp_cmd_packing NULL
129 #define sja1105_get_ts_info NULL
131 #define sja1105_port_rxtstamp NULL
133 #define sja1105_port_txtstamp NULL
135 #define sja1105_hwtstamp_get NULL
137 #define sja1105_hwtstamp_set NULL
139 #endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP) */
141 #endif /* _SJA1105_PTP_H */