hwtstamp.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Marvell 88E6xxx Switch hardware timestamping 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_HWTSTAMP_H
  17. #define _MV88E6XXX_HWTSTAMP_H
  18. #include "chip.h"
  19. /* Global 6352 PTP registers */
  20. /* Offset 0x00: PTP EtherType */
  21. #define MV88E6XXX_PTP_ETHERTYPE 0x00
  22. /* Offset 0x01: Message Type Timestamp Enables */
  23. #define MV88E6XXX_PTP_MSGTYPE 0x01
  24. #define MV88E6XXX_PTP_MSGTYPE_SYNC 0x0001
  25. #define MV88E6XXX_PTP_MSGTYPE_DELAY_REQ 0x0002
  26. #define MV88E6XXX_PTP_MSGTYPE_PDLAY_REQ 0x0004
  27. #define MV88E6XXX_PTP_MSGTYPE_PDLAY_RES 0x0008
  28. #define MV88E6XXX_PTP_MSGTYPE_ALL_EVENT 0x000f
  29. /* Offset 0x02: Timestamp Arrival Capture Pointers */
  30. #define MV88E6XXX_PTP_TS_ARRIVAL_PTR 0x02
  31. /* Offset 0x05: PTP Global Configuration */
  32. #define MV88E6165_PTP_CFG 0x05
  33. #define MV88E6165_PTP_CFG_TSPEC_MASK 0xf000
  34. #define MV88E6165_PTP_CFG_DISABLE_TS_OVERWRITE BIT(1)
  35. #define MV88E6165_PTP_CFG_DISABLE_PTP BIT(0)
  36. /* Offset 0x07: PTP Global Configuration */
  37. #define MV88E6341_PTP_CFG 0x07
  38. #define MV88E6341_PTP_CFG_UPDATE 0x8000
  39. #define MV88E6341_PTP_CFG_IDX_MASK 0x7f00
  40. #define MV88E6341_PTP_CFG_DATA_MASK 0x00ff
  41. #define MV88E6341_PTP_CFG_MODE_IDX 0x0
  42. #define MV88E6341_PTP_CFG_MODE_TS_AT_PHY 0x00
  43. #define MV88E6341_PTP_CFG_MODE_TS_AT_MAC 0x80
  44. /* Offset 0x08: PTP Interrupt Status */
  45. #define MV88E6XXX_PTP_IRQ_STATUS 0x08
  46. /* Per-Port 6352 PTP Registers */
  47. /* Offset 0x00: PTP Configuration 0 */
  48. #define MV88E6XXX_PORT_PTP_CFG0 0x00
  49. #define MV88E6XXX_PORT_PTP_CFG0_TSPEC_SHIFT 12
  50. #define MV88E6XXX_PORT_PTP_CFG0_TSPEC_MASK 0xf000
  51. #define MV88E6XXX_PORT_PTP_CFG0_TSPEC_1588 0x0000
  52. #define MV88E6XXX_PORT_PTP_CFG0_TSPEC_8021AS 0x1000
  53. #define MV88E6XXX_PORT_PTP_CFG0_DISABLE_TSPEC_MATCH 0x0800
  54. #define MV88E6XXX_PORT_PTP_CFG0_DISABLE_OVERWRITE 0x0002
  55. #define MV88E6XXX_PORT_PTP_CFG0_DISABLE_PTP 0x0001
  56. /* Offset 0x01: PTP Configuration 1 */
  57. #define MV88E6XXX_PORT_PTP_CFG1 0x01
  58. /* Offset 0x02: PTP Configuration 2 */
  59. #define MV88E6XXX_PORT_PTP_CFG2 0x02
  60. #define MV88E6XXX_PORT_PTP_CFG2_EMBED_ARRIVAL 0x1000
  61. #define MV88E6XXX_PORT_PTP_CFG2_DEP_IRQ_EN 0x0002
  62. #define MV88E6XXX_PORT_PTP_CFG2_ARR_IRQ_EN 0x0001
  63. /* Offset 0x03: PTP LED Configuration */
  64. #define MV88E6XXX_PORT_PTP_LED_CFG 0x03
  65. /* Offset 0x08: PTP Arrival 0 Status */
  66. #define MV88E6XXX_PORT_PTP_ARR0_STS 0x08
  67. /* Offset 0x09/0x0A: PTP Arrival 0 Time */
  68. #define MV88E6XXX_PORT_PTP_ARR0_TIME_LO 0x09
  69. #define MV88E6XXX_PORT_PTP_ARR0_TIME_HI 0x0a
  70. /* Offset 0x0B: PTP Arrival 0 Sequence ID */
  71. #define MV88E6XXX_PORT_PTP_ARR0_SEQID 0x0b
  72. /* Offset 0x0C: PTP Arrival 1 Status */
  73. #define MV88E6XXX_PORT_PTP_ARR1_STS 0x0c
  74. /* Offset 0x0D/0x0E: PTP Arrival 1 Time */
  75. #define MV88E6XXX_PORT_PTP_ARR1_TIME_LO 0x0d
  76. #define MV88E6XXX_PORT_PTP_ARR1_TIME_HI 0x0e
  77. /* Offset 0x0F: PTP Arrival 1 Sequence ID */
  78. #define MV88E6XXX_PORT_PTP_ARR1_SEQID 0x0f
  79. /* Offset 0x10: PTP Departure Status */
  80. #define MV88E6XXX_PORT_PTP_DEP_STS 0x10
  81. /* Offset 0x11/0x12: PTP Deperture Time */
  82. #define MV88E6XXX_PORT_PTP_DEP_TIME_LO 0x11
  83. #define MV88E6XXX_PORT_PTP_DEP_TIME_HI 0x12
  84. /* Offset 0x13: PTP Departure Sequence ID */
  85. #define MV88E6XXX_PORT_PTP_DEP_SEQID 0x13
  86. /* Status fields for arrival and depature timestamp status registers */
  87. #define MV88E6XXX_PTP_TS_STATUS_MASK 0x0006
  88. #define MV88E6XXX_PTP_TS_STATUS_NORMAL 0x0000
  89. #define MV88E6XXX_PTP_TS_STATUS_OVERWITTEN 0x0002
  90. #define MV88E6XXX_PTP_TS_STATUS_DISCARDED 0x0004
  91. #define MV88E6XXX_PTP_TS_VALID 0x0001
  92. #ifdef CONFIG_NET_DSA_MV88E6XXX_PTP
  93. int mv88e6xxx_port_hwtstamp_set(struct dsa_switch *ds, int port,
  94. struct ifreq *ifr);
  95. int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port,
  96. struct ifreq *ifr);
  97. bool mv88e6xxx_port_rxtstamp(struct dsa_switch *ds, int port,
  98. struct sk_buff *clone, unsigned int type);
  99. bool mv88e6xxx_port_txtstamp(struct dsa_switch *ds, int port,
  100. struct sk_buff *clone, unsigned int type);
  101. int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port,
  102. struct ethtool_ts_info *info);
  103. int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip);
  104. void mv88e6xxx_hwtstamp_free(struct mv88e6xxx_chip *chip);
  105. int mv88e6352_hwtstamp_port_enable(struct mv88e6xxx_chip *chip, int port);
  106. int mv88e6352_hwtstamp_port_disable(struct mv88e6xxx_chip *chip, int port);
  107. int mv88e6165_global_enable(struct mv88e6xxx_chip *chip);
  108. int mv88e6165_global_disable(struct mv88e6xxx_chip *chip);
  109. #else /* !CONFIG_NET_DSA_MV88E6XXX_PTP */
  110. static inline int mv88e6xxx_port_hwtstamp_set(struct dsa_switch *ds,
  111. int port, struct ifreq *ifr)
  112. {
  113. return -EOPNOTSUPP;
  114. }
  115. static inline int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds,
  116. int port, struct ifreq *ifr)
  117. {
  118. return -EOPNOTSUPP;
  119. }
  120. static inline bool mv88e6xxx_port_rxtstamp(struct dsa_switch *ds, int port,
  121. struct sk_buff *clone,
  122. unsigned int type)
  123. {
  124. return false;
  125. }
  126. static inline bool mv88e6xxx_port_txtstamp(struct dsa_switch *ds, int port,
  127. struct sk_buff *clone,
  128. unsigned int type)
  129. {
  130. return false;
  131. }
  132. static inline int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port,
  133. struct ethtool_ts_info *info)
  134. {
  135. return -EOPNOTSUPP;
  136. }
  137. static inline int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip)
  138. {
  139. return 0;
  140. }
  141. static inline void mv88e6xxx_hwtstamp_free(struct mv88e6xxx_chip *chip)
  142. {
  143. }
  144. #endif /* CONFIG_NET_DSA_MV88E6XXX_PTP */
  145. #endif /* _MV88E6XXX_HWTSTAMP_H */