general_phy.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-10-08 zhujiale the first version
  9. */
  10. #ifndef __PHY_GENERAL_H__
  11. #define __PHY_GENERAL_H__
  12. /* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
  13. #define SPEED_10 10
  14. #define SPEED_100 100
  15. #define SPEED_1000 1000
  16. #define SPEED_2500 2500
  17. #define SPEED_10000 10000
  18. /* Advertisement control register. */
  19. #define RT_ADVERTISE_SLCT 0x001f /* Selector bits */
  20. #define RT_ADVERTISE_CSMA 0x0001 /* Only selector supported */
  21. #define RT_ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
  22. #define RT_ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
  23. #define RT_ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
  24. #define RT_ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
  25. #define RT_ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
  26. #define RT_ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
  27. #define RT_ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
  28. #define RT_ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
  29. #define RT_ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
  30. #define RT_ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
  31. #define RT_ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */
  32. #define RT_ADVERTISE_RESV 0x1000 /* Unused... */
  33. #define RT_ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
  34. #define RT_ADVERTISE_LPACK 0x4000 /* Ack link partners response */
  35. #define RT_ADVERTISE_NPAGE 0x8000 /* Next page bit */
  36. #define RT_ADVERTISE_FULL (RT_ADVERTISE_100FULL | RT_ADVERTISE_10FULL | \
  37. RT_ADVERTISE_CSMA)
  38. #define RT_ADVERTISE_ALL (RT_ADVERTISE_10HALF | RT_ADVERTISE_10FULL | \
  39. RT_ADVERTISE_100HALF | RT_ADVERTISE_100FULL)
  40. /* Indicates what features are advertised by the interface. */
  41. #define RT_ADVERTISED__10baseT_Half (1 << 0)
  42. #define RT_ADVERTISED__10baseT_Full (1 << 1)
  43. #define RT_ADVERTISED__100baseT_Half (1 << 2)
  44. #define RT_ADVERTISED__100baseT_Full (1 << 3)
  45. #define RT_ADVERTISED__1000baseT_Half (1 << 4)
  46. #define RT_ADVERTISED__1000baseT_Full (1 << 5)
  47. #define RT_ADVERTISED__Autoneg (1 << 6)
  48. #define RT_ADVERTISED__TP (1 << 7)
  49. #define RT_ADVERTISED__AUI (1 << 8)
  50. #define RT_ADVERTISED__MII (1 << 9)
  51. #define RT_ADVERTISED__FIBRE (1 << 10)
  52. #define RT_ADVERTISED__BNC (1 << 11)
  53. #define RT_ADVERTISED__10000baseT_Full (1 << 12)
  54. #define RT_ADVERTISED__Pause (1 << 13)
  55. #define RT_ADVERTISED__Asym_Pause (1 << 14)
  56. #define RT_ADVERTISED__2500baseX_Full (1 << 15)
  57. #define RT_ADVERTISED__Backplane (1 << 16)
  58. #define RT_ADVERTISED__1000baseKX_Full (1 << 17)
  59. #define RT_ADVERTISED__10000baseKX4_Full (1 << 18)
  60. #define RT_ADVERTISED__10000baseKR_Full (1 << 19)
  61. #define RT_ADVERTISED__10000baseR_FEC (1 << 20)
  62. #define RT_ADVERTISED__1000baseX_Half (1 << 21)
  63. #define RT_ADVERTISED__1000baseX_Full (1 << 22)
  64. /* Basic mode status register. */
  65. #define RT_BMSR_ERCAP 0x0001 /* Ext-reg capability */
  66. #define RT_BMSR_JCD 0x0002 /* Jabber detected */
  67. #define RT_BMSR_LSTATUS 0x0004 /* Link status */
  68. #define RT_BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
  69. #define RT_BMSR_RFAULT 0x0010 /* Remote fault detected */
  70. #define RT_BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
  71. #define RT_BMSR_RESV 0x00c0 /* Unused... */
  72. #define RT_BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
  73. #define RT_BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */
  74. #define RT_BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */
  75. #define RT_BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
  76. #define RT_BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
  77. #define RT_BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
  78. #define RT_BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
  79. #define RT_BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
  80. /* 1000BASE-T Control register */
  81. #define RT_ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
  82. #define RT_ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */
  83. #define CTL1000_AS_MASTER 0x0800
  84. #define CTL1000_ENABLE_MASTER 0x1000
  85. /* Duplex, half or full. */
  86. #define DUPLEX_HALF 0x00
  87. #define DUPLEX_FULL 0x01
  88. #define AUTONEG_DISABLE 0x00
  89. #define AUTONEG_ENABLE 0x01
  90. #define RT_PHY_1000BTSR_MSCF 0x8000
  91. #define RT_PHY_1000BTSR_MSCR 0x4000
  92. #define RT_PHY_1000BTSR_LRS 0x2000
  93. #define RT_PHY_1000BTSR_RRS 0x1000
  94. #define RT_PHY_1000BTSR_1000FD 0x0800
  95. #define RT_PHY_1000BTSR_1000HD 0x0400
  96. /* Link partner ability register. */
  97. #define RT_LINK_PARTNER__SLCT 0x001f /* Same as advertise selector */
  98. #define RT_LINK_PARTNER__10HALF 0x0020 /* Can do 10mbps half-duplex */
  99. #define RT_LINK_PARTNER__1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */
  100. #define RT_LINK_PARTNER__10FULL 0x0040 /* Can do 10mbps full-duplex */
  101. #define RT_LINK_PARTNER__1000XHALF 0x0040 /* Can do 1000BASE-X half-duplex */
  102. #define RT_LINK_PARTNER__100HALF 0x0080 /* Can do 100mbps half-duplex */
  103. #define RT_LINK_PARTNER__1000XPAUSE 0x0080 /* Can do 1000BASE-X pause */
  104. #define RT_LINK_PARTNER__100FULL 0x0100 /* Can do 100mbps full-duplex */
  105. #define RT_LINK_PARTNER__1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/
  106. #define RT_LINK_PARTNER__100BASE4 0x0200 /* Can do 100mbps 4k packets */
  107. #define RT_LINK_PARTNER__PAUSE_CAP 0x0400 /* Can pause */
  108. #define RT_LINK_PARTNER__PAUSE_ASYM 0x0800 /* Can pause asymetrically */
  109. #define RT_LINK_PARTNER__RESV 0x1000 /* Unused... */
  110. #define RT_LINK_PARTNER__RFAULT 0x2000 /* Link partner faulted */
  111. #define RT_LINK_PARTNER__LPACK 0x4000 /* Link partner acked us */
  112. #define RT_LINK_PARTNER__NPAGE 0x8000 /* Next page bit */
  113. #define RT_LINK_PARTNER__DUPLEX (RT_LINK_PARTNER__10FULL | RT_LINK_PARTNER__100FULL)
  114. #define RT_LINK_PARTNER__100 (RT_LINK_PARTNER__100FULL | RT_LINK_PARTNER__100HALF | RT_LINK_PARTNER__100BASE4)
  115. /* Expansion register for auto-negotiation. */
  116. #define RT_EXPANSION_REG_NWAY 0x0001 /* Can do N-way auto-nego */
  117. #define RT_EXPANSION_REG_LCWP 0x0002 /* Got new RX page code word */
  118. #define RT_EXPANSION_REG_ENABLENPAGE 0x0004 /* This enables npage words */
  119. #define RT_EXPANSION_REG_NPCAPABLE 0x0008 /* Link partner supports npage */
  120. #define RT_EXPANSION_REG_MFAULTS 0x0010 /* Multiple faults detected */
  121. #define RT_EXPANSION_REG_RESV 0xffe0 /* Unused... */
  122. #define RT_SUPORT_1000B_XFULL 0x8000 /* Can do 1000BX Full */
  123. #define RT_SUPORT_1000B_XHALF 0x4000 /* Can do 1000BX Half */
  124. #define RT_SUPORT_1000B_TFULL 0x2000 /* Can do 1000BT Full */
  125. #define RT_SUPORT_1000B_THALF 0x1000 /* Can do 1000BT Half */
  126. #define RT_PHY_ANEG_TIMEOUT 4000
  127. struct rt_phy_device;
  128. int rt_genphy_parse_link(struct rt_phy_device *phydev);
  129. int rt_genphy_config_aneg(struct rt_phy_device *phydev);
  130. int rt_genphy_update_link(struct rt_phy_device *phydev);
  131. int rt_genphy_startup(struct rt_phy_device *phydev);
  132. int rt_genphy_config(struct rt_phy_device *phydev);
  133. #endif