Bryan Whitehead | 07624df | 2018-08-09 15:36:10 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* Copyright (C) 2018 Microchip Technology Inc. */ |
| 3 | |
| 4 | #ifndef _LAN743X_PTP_H |
| 5 | #define _LAN743X_PTP_H |
| 6 | |
| 7 | #include "linux/ptp_clock_kernel.h" |
| 8 | #include "linux/netdevice.h" |
| 9 | |
| 10 | struct lan743x_adapter; |
| 11 | |
| 12 | /* GPIO */ |
| 13 | struct lan743x_gpio { |
| 14 | /* gpio_lock: used to prevent concurrent access to gpio settings */ |
| 15 | spinlock_t gpio_lock; |
| 16 | |
| 17 | int used_bits; |
| 18 | int output_bits; |
| 19 | int ptp_bits; |
| 20 | u32 gpio_cfg0; |
| 21 | u32 gpio_cfg1; |
| 22 | u32 gpio_cfg2; |
| 23 | u32 gpio_cfg3; |
| 24 | }; |
| 25 | |
| 26 | int lan743x_gpio_init(struct lan743x_adapter *adapter); |
| 27 | |
| 28 | void lan743x_ptp_isr(void *context); |
| 29 | bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter); |
| 30 | void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter); |
| 31 | void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter, |
| 32 | struct sk_buff *skb, bool ignore_sync); |
| 33 | int lan743x_ptp_init(struct lan743x_adapter *adapter); |
| 34 | int lan743x_ptp_open(struct lan743x_adapter *adapter); |
| 35 | void lan743x_ptp_close(struct lan743x_adapter *adapter); |
| 36 | void lan743x_ptp_update_latency(struct lan743x_adapter *adapter, |
| 37 | u32 link_speed); |
| 38 | |
| 39 | int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 40 | |
| 41 | #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4) |
| 42 | |
| 43 | #define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1) |
| 44 | #define PTP_FLAG_ISR_ENABLED BIT(2) |
| 45 | |
| 46 | struct lan743x_ptp { |
| 47 | int flags; |
| 48 | |
| 49 | /* command_lock: used to prevent concurrent ptp commands */ |
| 50 | struct mutex command_lock; |
| 51 | |
Bryan Whitehead | 07624df | 2018-08-09 15:36:10 -0400 | [diff] [blame] | 52 | struct ptp_clock *ptp_clock; |
| 53 | struct ptp_clock_info ptp_clock_info; |
| 54 | struct ptp_pin_desc pin_config[1]; |
Bryan Whitehead | 07624df | 2018-08-09 15:36:10 -0400 | [diff] [blame] | 55 | |
| 56 | #define LAN743X_PTP_NUMBER_OF_EVENT_CHANNELS (2) |
| 57 | unsigned long used_event_ch; |
| 58 | |
| 59 | int perout_event_ch; |
| 60 | int perout_gpio_bit; |
| 61 | |
| 62 | /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */ |
| 63 | spinlock_t tx_ts_lock; |
| 64 | int pending_tx_timestamps; |
| 65 | struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; |
| 66 | unsigned int tx_ts_ignore_sync_queue; |
| 67 | int tx_ts_skb_queue_size; |
| 68 | u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; |
| 69 | u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; |
| 70 | u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; |
| 71 | int tx_ts_queue_size; |
| 72 | }; |
| 73 | |
| 74 | #endif /* _LAN743X_PTP_H */ |