Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /* Copyright (C) 2018 Microchip Technology Inc. */
0003 
0004 #ifndef _LAN743X_PTP_H
0005 #define _LAN743X_PTP_H
0006 
0007 #include "linux/ptp_clock_kernel.h"
0008 #include "linux/netdevice.h"
0009 
0010 #define LAN7430_N_LED           4
0011 #define LAN7430_N_GPIO          4   /* multiplexed with PHY LEDs */
0012 #define LAN7431_N_GPIO          12
0013 
0014 #define LAN743X_PTP_N_GPIO      LAN7431_N_GPIO
0015 
0016 /* the number of periodic outputs is limited by number of
0017  * PTP clock event channels
0018  */
0019 #define LAN743X_PTP_N_EVENT_CHAN    2
0020 #define LAN743X_PTP_N_PEROUT        LAN743X_PTP_N_EVENT_CHAN
0021 #define LAN743X_PTP_N_EXTTS     4
0022 #define LAN743X_PTP_N_PPS       0
0023 #define PCI11X1X_PTP_IO_MAX_CHANNELS    8
0024 
0025 struct lan743x_adapter;
0026 
0027 /* GPIO */
0028 struct lan743x_gpio {
0029     /* gpio_lock: used to prevent concurrent access to gpio settings */
0030     spinlock_t gpio_lock;
0031 
0032     int used_bits;
0033     int output_bits;
0034     int ptp_bits;
0035     u32 gpio_cfg0;
0036     u32 gpio_cfg1;
0037     u32 gpio_cfg2;
0038     u32 gpio_cfg3;
0039 };
0040 
0041 int lan743x_gpio_init(struct lan743x_adapter *adapter);
0042 
0043 void lan743x_ptp_isr(void *context);
0044 bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter);
0045 void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter);
0046 void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,
0047                   struct sk_buff *skb, bool ignore_sync);
0048 int lan743x_ptp_init(struct lan743x_adapter *adapter);
0049 int lan743x_ptp_open(struct lan743x_adapter *adapter);
0050 void lan743x_ptp_close(struct lan743x_adapter *adapter);
0051 void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,
0052                 u32 link_speed);
0053 
0054 int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
0055 
0056 #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4)
0057 
0058 #define PTP_FLAG_PTP_CLOCK_REGISTERED       BIT(1)
0059 #define PTP_FLAG_ISR_ENABLED            BIT(2)
0060 
0061 struct lan743x_ptp_perout {
0062     int  event_ch;  /* PTP event channel (0=channel A, 1=channel B) */
0063     int  gpio_pin;  /* GPIO pin where output appears */
0064 };
0065 
0066 struct lan743x_extts {
0067     int flags;
0068     struct timespec64 ts;
0069 };
0070 
0071 struct lan743x_ptp {
0072     int flags;
0073 
0074     /* command_lock: used to prevent concurrent ptp commands */
0075     struct mutex    command_lock;
0076 
0077     struct ptp_clock *ptp_clock;
0078     struct ptp_clock_info ptp_clock_info;
0079     struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO];
0080 
0081     unsigned long used_event_ch;
0082     struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT];
0083     int ptp_io_perout[LAN743X_PTP_N_PEROUT]; /* PTP event channel (0=channel A, 1=channel B) */
0084     struct lan743x_extts extts[LAN743X_PTP_N_EXTTS];
0085 
0086     bool leds_multiplexed;
0087     bool led_enabled[LAN7430_N_LED];
0088 
0089     /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */
0090     spinlock_t  tx_ts_lock;
0091     int pending_tx_timestamps;
0092     struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
0093     unsigned int    tx_ts_ignore_sync_queue;
0094     int tx_ts_skb_queue_size;
0095     u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
0096     u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
0097     u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
0098     int tx_ts_queue_size;
0099 };
0100 
0101 #endif /* _LAN743X_PTP_H */