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 12 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 ptp_perout_request perout_request; 33 }; 34 35 void ksz_ptp_set_caps(struct dsa_switch *ds); 36 void ksz8463_ptp_set_caps(struct dsa_switch *ds); 37 int ksz_ptp_clock_register(struct dsa_switch *ds); 38 39 void ksz_ptp_clock_unregister(struct dsa_switch *ds); 40 41 int ksz_get_ts_info(struct dsa_switch *ds, int port, 42 struct kernel_ethtool_ts_info *ts); 43 int ksz8463_get_ts_info(struct dsa_switch *ds, int port, 44 struct kernel_ethtool_ts_info *ts); 45 int ksz_hwtstamp_get(struct dsa_switch *ds, int port, 46 struct kernel_hwtstamp_config *config); 47 int ksz_hwtstamp_set(struct dsa_switch *ds, int port, 48 struct kernel_hwtstamp_config *config, 49 struct netlink_ext_ack *extack); 50 int ksz8463_hwtstamp_set(struct dsa_switch *ds, int port, 51 struct kernel_hwtstamp_config *config, 52 struct netlink_ext_ack *extack); 53 void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb); 54 void ksz_port_deferred_xmit(struct kthread_work *work); 55 bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, 56 unsigned int type); 57 int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p); 58 void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p); 59 int ksz8463_ptp_irq_setup(struct dsa_switch *ds); 60 void ksz8463_ptp_irq_free(struct dsa_switch *ds); 61 62 #else 63 64 struct ksz_ptp_data { 65 /* Serializes all operations on the PTP hardware clock */ 66 struct mutex lock; 67 }; 68 69 static inline void ksz_ptp_set_caps(struct dsa_switch *ds) { } 70 static inline void ksz8463_ptp_set_caps(struct dsa_switch *ds) { } 71 static inline int ksz_ptp_clock_register(struct dsa_switch *ds) 72 { 73 return 0; 74 } 75 76 static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { } 77 78 static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p) 79 { 80 return 0; 81 } 82 83 static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {} 84 85 static inline int ksz8463_ptp_irq_setup(struct dsa_switch *ds) 86 { 87 return 0; 88 } 89 90 static inline void ksz8463_ptp_irq_free(struct dsa_switch *ds) {} 91 92 #define ksz_get_ts_info NULL 93 #define ksz8463_get_ts_info NULL 94 95 #define ksz_hwtstamp_get NULL 96 97 #define ksz_hwtstamp_set NULL 98 #define ksz8463_hwtstamp_set NULL 99 100 #define ksz_port_rxtstamp NULL 101 102 #define ksz_port_txtstamp NULL 103 104 #define ksz_port_deferred_xmit NULL 105 106 #endif /* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */ 107 108 #endif 109