ptp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Marvell 88E6xxx Switch PTP support
  3. *
  4. * Copyright (c) 2008 Marvell Semiconductor
  5. *
  6. * Copyright (c) 2017 National Instruments
  7. * Erik Hons <erik.hons@ni.com>
  8. * Brandon Streiff <brandon.streiff@ni.com>
  9. * Dane Wagner <dane.wagner@ni.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. #ifndef _MV88E6XXX_PTP_H
  17. #define _MV88E6XXX_PTP_H
  18. #include "chip.h"
  19. /* Offset 0x00: TAI Global Config */
  20. #define MV88E6XXX_TAI_CFG 0x00
  21. #define MV88E6XXX_TAI_CFG_CAP_OVERWRITE 0x8000
  22. #define MV88E6XXX_TAI_CFG_CAP_CTR_START 0x4000
  23. #define MV88E6XXX_TAI_CFG_EVREQ_FALLING 0x2000
  24. #define MV88E6XXX_TAI_CFG_TRIG_ACTIVE_LO 0x1000
  25. #define MV88E6XXX_TAI_CFG_IRL_ENABLE 0x0400
  26. #define MV88E6XXX_TAI_CFG_TRIG_IRQ_EN 0x0200
  27. #define MV88E6XXX_TAI_CFG_EVREQ_IRQ_EN 0x0100
  28. #define MV88E6XXX_TAI_CFG_TRIG_LOCK 0x0080
  29. #define MV88E6XXX_TAI_CFG_BLOCK_UPDATE 0x0008
  30. #define MV88E6XXX_TAI_CFG_MULTI_PTP 0x0004
  31. #define MV88E6XXX_TAI_CFG_TRIG_MODE_ONESHOT 0x0002
  32. #define MV88E6XXX_TAI_CFG_TRIG_ENABLE 0x0001
  33. /* Offset 0x01: Timestamp Clock Period (ps) */
  34. #define MV88E6XXX_TAI_CLOCK_PERIOD 0x01
  35. /* Offset 0x02/0x03: Trigger Generation Amount */
  36. #define MV88E6XXX_TAI_TRIG_GEN_AMOUNT_LO 0x02
  37. #define MV88E6XXX_TAI_TRIG_GEN_AMOUNT_HI 0x03
  38. /* Offset 0x04: Clock Compensation */
  39. #define MV88E6XXX_TAI_TRIG_CLOCK_COMP 0x04
  40. /* Offset 0x05: Trigger Configuration */
  41. #define MV88E6XXX_TAI_TRIG_CFG 0x05
  42. /* Offset 0x06: Ingress Rate Limiter Clock Generation Amount */
  43. #define MV88E6XXX_TAI_IRL_AMOUNT 0x06
  44. /* Offset 0x07: Ingress Rate Limiter Compensation */
  45. #define MV88E6XXX_TAI_IRL_COMP 0x07
  46. /* Offset 0x08: Ingress Rate Limiter Compensation */
  47. #define MV88E6XXX_TAI_IRL_COMP_PS 0x08
  48. /* Offset 0x09: Event Status */
  49. #define MV88E6XXX_TAI_EVENT_STATUS 0x09
  50. #define MV88E6XXX_TAI_EVENT_STATUS_CAP_TRIG 0x4000
  51. #define MV88E6XXX_TAI_EVENT_STATUS_ERROR 0x0200
  52. #define MV88E6XXX_TAI_EVENT_STATUS_VALID 0x0100
  53. #define MV88E6XXX_TAI_EVENT_STATUS_CTR_MASK 0x00ff
  54. /* Offset 0x0A/0x0B: Event Time */
  55. #define MV88E6XXX_TAI_EVENT_TIME_LO 0x0a
  56. #define MV88E6XXX_TAI_EVENT_TYPE_HI 0x0b
  57. /* Offset 0x0E/0x0F: PTP Global Time */
  58. #define MV88E6XXX_TAI_TIME_LO 0x0e
  59. #define MV88E6XXX_TAI_TIME_HI 0x0f
  60. /* Offset 0x10/0x11: Trig Generation Time */
  61. #define MV88E6XXX_TAI_TRIG_TIME_LO 0x10
  62. #define MV88E6XXX_TAI_TRIG_TIME_HI 0x11
  63. /* Offset 0x12: Lock Status */
  64. #define MV88E6XXX_TAI_LOCK_STATUS 0x12
  65. /* Offset 0x00: Ether Type */
  66. #define MV88E6XXX_PTP_GC_ETYPE 0x00
  67. /* 6165 Global Control Registers */
  68. /* Offset 0x00: Ether Type */
  69. #define MV88E6XXX_PTP_GC_ETYPE 0x00
  70. /* Offset 0x01: Message ID */
  71. #define MV88E6XXX_PTP_GC_MESSAGE_ID 0x01
  72. /* Offset 0x02: Time Stamp Arrive Time */
  73. #define MV88E6XXX_PTP_GC_TS_ARR_PTR 0x02
  74. /* Offset 0x03: Port Arrival Interrupt Enable */
  75. #define MV88E6XXX_PTP_GC_PORT_ARR_INT_EN 0x03
  76. /* Offset 0x04: Port Departure Interrupt Enable */
  77. #define MV88E6XXX_PTP_GC_PORT_DEP_INT_EN 0x04
  78. /* Offset 0x05: Configuration */
  79. #define MV88E6XXX_PTP_GC_CONFIG 0x05
  80. #define MV88E6XXX_PTP_GC_CONFIG_DIS_OVERWRITE BIT(1)
  81. #define MV88E6XXX_PTP_GC_CONFIG_DIS_TS BIT(0)
  82. /* Offset 0x8: Interrupt Status */
  83. #define MV88E6XXX_PTP_GC_INT_STATUS 0x08
  84. /* Offset 0x9/0xa: Global Time */
  85. #define MV88E6XXX_PTP_GC_TIME_LO 0x09
  86. #define MV88E6XXX_PTP_GC_TIME_HI 0x0A
  87. /* 6165 Per Port Registers */
  88. /* Offset 0: Arrival Time 0 Status */
  89. #define MV88E6165_PORT_PTP_ARR0_STS 0x00
  90. /* Offset 0x01/0x02: PTP Arrival 0 Time */
  91. #define MV88E6165_PORT_PTP_ARR0_TIME_LO 0x01
  92. #define MV88E6165_PORT_PTP_ARR0_TIME_HI 0x02
  93. /* Offset 0x03: PTP Arrival 0 Sequence ID */
  94. #define MV88E6165_PORT_PTP_ARR0_SEQID 0x03
  95. /* Offset 0x04: PTP Arrival 1 Status */
  96. #define MV88E6165_PORT_PTP_ARR1_STS 0x04
  97. /* Offset 0x05/0x6E: PTP Arrival 1 Time */
  98. #define MV88E6165_PORT_PTP_ARR1_TIME_LO 0x05
  99. #define MV88E6165_PORT_PTP_ARR1_TIME_HI 0x06
  100. /* Offset 0x07: PTP Arrival 1 Sequence ID */
  101. #define MV88E6165_PORT_PTP_ARR1_SEQID 0x07
  102. /* Offset 0x08: PTP Departure Status */
  103. #define MV88E6165_PORT_PTP_DEP_STS 0x08
  104. /* Offset 0x09/0x0a: PTP Deperture Time */
  105. #define MV88E6165_PORT_PTP_DEP_TIME_LO 0x09
  106. #define MV88E6165_PORT_PTP_DEP_TIME_HI 0x0a
  107. /* Offset 0x0b: PTP Departure Sequence ID */
  108. #define MV88E6165_PORT_PTP_DEP_SEQID 0x0b
  109. /* Offset 0x0d: Port Status */
  110. #define MV88E6164_PORT_STATUS 0x0d
  111. #ifdef CONFIG_NET_DSA_MV88E6XXX_PTP
  112. long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp);
  113. int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip);
  114. void mv88e6xxx_ptp_free(struct mv88e6xxx_chip *chip);
  115. #define ptp_to_chip(ptp) container_of(ptp, struct mv88e6xxx_chip, \
  116. ptp_clock_info)
  117. extern const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops;
  118. extern const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops;
  119. #else /* !CONFIG_NET_DSA_MV88E6XXX_PTP */
  120. static inline long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp)
  121. {
  122. return -1;
  123. }
  124. static inline int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
  125. {
  126. return 0;
  127. }
  128. static inline void mv88e6xxx_ptp_free(struct mv88e6xxx_chip *chip)
  129. {
  130. }
  131. static const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {};
  132. static const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {};
  133. #endif /* CONFIG_NET_DSA_MV88E6XXX_PTP */
  134. #endif /* _MV88E6XXX_PTP_H */