103 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ */2/* Copyright (C) 2018 Microchip Technology Inc. */3 4#ifndef _LAN743X_PTP_H5#define _LAN743X_PTP_H6 7#include "linux/ptp_clock_kernel.h"8#include "linux/netdevice.h"9 10#define LAN7430_N_LED 411#define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */12#define LAN7431_N_GPIO 1213 14#define LAN743X_PTP_N_GPIO LAN7431_N_GPIO15 16/* the number of periodic outputs is limited by number of17 * PTP clock event channels18 */19#define LAN743X_PTP_N_EVENT_CHAN 220#define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN21#define LAN743X_PTP_N_EXTTS 422#define LAN743X_PTP_N_PPS 023#define PCI11X1X_PTP_IO_MAX_CHANNELS 824#define PTP_CMD_CTL_TIMEOUT_CNT 5025 26struct lan743x_adapter;27 28/* GPIO */29struct lan743x_gpio {30 /* gpio_lock: used to prevent concurrent access to gpio settings */31 spinlock_t gpio_lock;32 33 int used_bits;34 int output_bits;35 int ptp_bits;36 u32 gpio_cfg0;37 u32 gpio_cfg1;38 u32 gpio_cfg2;39 u32 gpio_cfg3;40};41 42int lan743x_gpio_init(struct lan743x_adapter *adapter);43 44void lan743x_ptp_isr(void *context);45bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter);46void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter);47void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,48 struct sk_buff *skb, bool ignore_sync);49int lan743x_ptp_init(struct lan743x_adapter *adapter);50int lan743x_ptp_open(struct lan743x_adapter *adapter);51void lan743x_ptp_close(struct lan743x_adapter *adapter);52void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,53 u32 link_speed);54 55int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);56 57#define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4)58 59#define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1)60#define PTP_FLAG_ISR_ENABLED BIT(2)61 62struct lan743x_ptp_perout {63 int event_ch; /* PTP event channel (0=channel A, 1=channel B) */64 int gpio_pin; /* GPIO pin where output appears */65};66 67struct lan743x_extts {68 int flags;69 struct timespec64 ts;70};71 72struct lan743x_ptp {73 int flags;74 75 /* command_lock: used to prevent concurrent ptp commands */76 struct mutex command_lock;77 78 struct ptp_clock *ptp_clock;79 struct ptp_clock_info ptp_clock_info;80 struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO];81 82 unsigned long used_event_ch;83 struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT];84 int ptp_io_perout[LAN743X_PTP_N_PEROUT]; /* PTP event channel (0=channel A, 1=channel B) */85 struct lan743x_extts extts[LAN743X_PTP_N_EXTTS];86 87 bool leds_multiplexed;88 bool led_enabled[LAN7430_N_LED];89 90 /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */91 spinlock_t tx_ts_lock;92 int pending_tx_timestamps;93 struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];94 unsigned int tx_ts_ignore_sync_queue;95 int tx_ts_skb_queue_size;96 u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];97 u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];98 u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];99 int tx_ts_queue_size;100};101 102#endif /* _LAN743X_PTP_H */103