1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Microchip KSZ PTP Implementation 3 * 4 * Copyright (C) 2020 ARRI Lighting 5 * Copyright (C) 2022 Microchip Technology Inc. 6 */ 7 8 #ifndef _NET_DSA_DRIVERS_KSZ_PTP_H 9 #define _NET_DSA_DRIVERS_KSZ_PTP_H 10 11 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP) 12 13 #include <linux/ptp_clock_kernel.h> 14 15 #define KSZ_PTP_N_GPIO 2 16 17 enum ksz_ptp_tou_mode { 18 KSZ_PTP_TOU_IDLE, 19 KSZ_PTP_TOU_PEROUT, 20 }; 21 22 struct ksz_ptp_data { 23 struct ptp_clock_info caps; 24 struct ptp_clock *clock; 25 struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO]; 26 /* Serializes all operations on the PTP hardware clock */ 27 struct mutex lock; 28 /* lock for accessing the clock_time */ 29 spinlock_t clock_lock; 30 struct timespec64 clock_time; 31 enum ksz_ptp_tou_mode tou_mode; 32 struct timespec64 perout_target_time_first; /* start of first pulse */ 33 struct timespec64 perout_period; 34 }; 35 36 int ksz_ptp_clock_register(struct dsa_switch *ds); 37 38 void ksz_ptp_clock_unregister(struct dsa_switch *ds); 39 40 int ksz_get_ts_info(struct dsa_switch *ds, int port, 41 struct kernel_ethtool_ts_info *ts); 42 int ksz8463_get_ts_info(struct dsa_switch *ds, int port, 43 struct kernel_ethtool_ts_info *ts); 44 int ksz_hwtstamp_get(struct dsa_switch *ds, int port, 45 struct kernel_hwtstamp_config *config); 46 int ksz_hwtstamp_set(struct dsa_switch *ds, int port, 47 struct kernel_hwtstamp_config *config, 48 struct netlink_ext_ack *extack); 49 int ksz8463_hwtstamp_set(struct dsa_switch *ds, int port, 50 struct kernel_hwtstamp_config *config, 51 struct netlink_ext_ack *extack); 52 void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb); 53 void ksz_port_deferred_xmit(struct kthread_work *work); 54 bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, 55 unsigned int type); 56 int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p); 57 void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p); 58 int ksz8463_ptp_irq_setup(struct dsa_switch *ds); 59 void ksz8463_ptp_irq_free(struct dsa_switch *ds); 60 61 #else 62 63 struct ksz_ptp_data { 64 /* Serializes all operations on the PTP hardware clock */ 65 struct mutex lock; 66 }; 67 68 static inline int ksz_ptp_clock_register(struct dsa_switch *ds) 69 { 70 return 0; 71 } 72 73 static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { } 74 75 static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p) 76 { 77 return 0; 78 } 79 80 static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {} 81 82 static inline int ksz8463_ptp_irq_setup(struct dsa_switch *ds) 83 { 84 return 0; 85 } 86 87 static inline void ksz8463_ptp_irq_free(struct dsa_switch *ds) {} 88 89 #define ksz_get_ts_info NULL 90 #define ksz8463_get_ts_info NULL 91 92 #define ksz_hwtstamp_get NULL 93 94 #define ksz_hwtstamp_set NULL 95 #define ksz8463_hwtstamp_set NULL 96 97 #define ksz_port_rxtstamp NULL 98 99 #define ksz_port_txtstamp NULL 100 101 #define ksz_port_deferred_xmit NULL 102 103 #endif /* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */ 104 105 #endif 106