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