lan743x_ptp.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright (C) 2018 Microchip Technology Inc. */
  3. #ifndef _LAN743X_PTP_H
  4. #define _LAN743X_PTP_H
  5. #include "linux/ptp_clock_kernel.h"
  6. #include "linux/netdevice.h"
  7. #define LAN7430_N_LED 4
  8. #define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */
  9. #define LAN7431_N_GPIO 12
  10. #define LAN743X_PTP_N_GPIO LAN7431_N_GPIO
  11. /* the number of periodic outputs is limited by number of
  12. * PTP clock event channels
  13. */
  14. #define LAN743X_PTP_N_EVENT_CHAN 2
  15. #define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN
  16. #define LAN743X_PTP_N_EXTTS 4
  17. #define LAN743X_PTP_N_PPS 0
  18. #define PCI11X1X_PTP_IO_MAX_CHANNELS 8
  19. struct lan743x_adapter;
  20. /* GPIO */
  21. struct lan743x_gpio {
  22. /* gpio_lock: used to prevent concurrent access to gpio settings */
  23. spinlock_t gpio_lock;
  24. int used_bits;
  25. int output_bits;
  26. int ptp_bits;
  27. u32 gpio_cfg0;
  28. u32 gpio_cfg1;
  29. u32 gpio_cfg2;
  30. u32 gpio_cfg3;
  31. };
  32. int lan743x_gpio_init(struct lan743x_adapter *adapter);
  33. void lan743x_ptp_isr(void *context);
  34. bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter);
  35. void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter);
  36. void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,
  37. struct sk_buff *skb, bool ignore_sync);
  38. int lan743x_ptp_init(struct lan743x_adapter *adapter);
  39. int lan743x_ptp_open(struct lan743x_adapter *adapter);
  40. void lan743x_ptp_close(struct lan743x_adapter *adapter);
  41. void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,
  42. u32 link_speed);
  43. int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  44. #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4)
  45. #define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1)
  46. #define PTP_FLAG_ISR_ENABLED BIT(2)
  47. struct lan743x_ptp_perout {
  48. int event_ch; /* PTP event channel (0=channel A, 1=channel B) */
  49. int gpio_pin; /* GPIO pin where output appears */
  50. };
  51. struct lan743x_extts {
  52. int flags;
  53. struct timespec64 ts;
  54. };
  55. struct lan743x_ptp {
  56. int flags;
  57. /* command_lock: used to prevent concurrent ptp commands */
  58. struct mutex command_lock;
  59. struct ptp_clock *ptp_clock;
  60. struct ptp_clock_info ptp_clock_info;
  61. struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO];
  62. unsigned long used_event_ch;
  63. struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT];
  64. int ptp_io_perout[LAN743X_PTP_N_PEROUT]; /* PTP event channel (0=channel A, 1=channel B) */
  65. struct lan743x_extts extts[LAN743X_PTP_N_EXTTS];
  66. bool leds_multiplexed;
  67. bool led_enabled[LAN7430_N_LED];
  68. /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */
  69. spinlock_t tx_ts_lock;
  70. int pending_tx_timestamps;
  71. struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
  72. unsigned int tx_ts_ignore_sync_queue;
  73. int tx_ts_skb_queue_size;
  74. u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
  75. u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
  76. u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
  77. int tx_ts_queue_size;
  78. };
  79. #endif /* _LAN743X_PTP_H */