rtl8211f_driver.h
Go to the documentation of this file.
1 /**
2  * @file rtl8211f_driver.h
3  * @brief RTL8211F Gigabit Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _RTL8211F_DRIVER_H
32 #define _RTL8211F_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef RTL8211F_PHY_ADDR
39  #define RTL8211F_PHY_ADDR 1
40 #elif (RTL8211F_PHY_ADDR < 0 || RTL8211F_PHY_ADDR > 31)
41  #error RTL8211F_PHY_ADDR parameter is not valid
42 #endif
43 
44 //RTL8211F PHY registers
45 #define RTL8211F_BMCR 0x00
46 #define RTL8211F_BMSR 0x01
47 #define RTL8211F_PHYID1 0x02
48 #define RTL8211F_PHYID2 0x03
49 #define RTL8211F_ANAR 0x04
50 #define RTL8211F_ANLPAR 0x05
51 #define RTL8211F_ANER 0x06
52 #define RTL8211F_ANNPTR 0x07
53 #define RTL8211F_ANNPRR 0x08
54 #define RTL8211F_GBCR 0x09
55 #define RTL8211F_GBSR 0x0A
56 #define RTL8211F_MMDACR 0x0D
57 #define RTL8211F_MMDAADR 0x0E
58 #define RTL8211F_GBESR 0x0F
59 #define RTL8211F_INER 0x12
60 #define RTL8211F_PHYCR1 0x18
61 #define RTL8211F_PHYCR2 0x19
62 #define RTL8211F_PHYSR 0x1A
63 #define RTL8211F_INSR 0x1D
64 #define RTL8211F_PAGSR 0x1F
65 
66 //RTL8211F MMD registers
67 #define RTL8211F_PC1R 0x03, 0x00
68 #define RTL8211F_PS1R 0x03, 0x01
69 #define RTL8211F_EEECR 0x03, 0x14
70 #define RTL8211F_EEEWER 0x03, 0x16
71 #define RTL8211F_EEEAR 0x07, 0x3C
72 #define RTL8211F_EEELPAR 0x07, 0x3D
73 
74 //Basic Mode Control register
75 #define RTL8211F_BMCR_RESET 0x8000
76 #define RTL8211F_BMCR_LOOPBACK 0x4000
77 #define RTL8211F_BMCR_SPEED_SEL_LSB 0x2000
78 #define RTL8211F_BMCR_AN_EN 0x1000
79 #define RTL8211F_BMCR_POWER_DOWN 0x0800
80 #define RTL8211F_BMCR_ISOLATE 0x0400
81 #define RTL8211F_BMCR_RESTART_AN 0x0200
82 #define RTL8211F_BMCR_DUPLEX_MODE 0x0100
83 #define RTL8211F_BMCR_COL_TEST 0x0080
84 #define RTL8211F_BMCR_SPEED_SEL_MSB 0x0040
85 #define RTL8211F_BMCR_UNI_DIR_EN 0x0020
86 
87 //Basic Mode Status register
88 #define RTL8211F_BMSR_100BT4 0x8000
89 #define RTL8211F_BMSR_100BTX_FD 0x4000
90 #define RTL8211F_BMSR_100BTX_HD 0x2000
91 #define RTL8211F_BMSR_10BT_FD 0x1000
92 #define RTL8211F_BMSR_10BT_HD 0x0800
93 #define RTL8211F_BMSR_100BT2_FD 0x0400
94 #define RTL8211F_BMSR_100BT2_HD 0x0200
95 #define RTL8211F_BMSR_EXTENDED_STATUS 0x0100
96 #define RTL8211F_BMSR_UNI_DIR_CAPABLE 0x0080
97 #define RTL8211F_BMSR_PREAMBLE_SUPPR 0x0040
98 #define RTL8211F_BMSR_AN_COMPLETE 0x0020
99 #define RTL8211F_BMSR_REMOTE_FAULT 0x0010
100 #define RTL8211F_BMSR_AN_CAPABLE 0x0008
101 #define RTL8211F_BMSR_LINK_STATUS 0x0004
102 #define RTL8211F_BMSR_JABBER_DETECT 0x0002
103 #define RTL8211F_BMSR_EXTENDED_CAPABLE 0x0001
104 
105 //PHY Identifier 1 register
106 #define RTL8211F_PHYID1_OUI_MSB 0xFFFF
107 #define RTL8211F_PHYID1_OUI_MSB_DEFAULT 0x001C
108 
109 //PHY Identifier 2 register
110 #define RTL8211F_PHYID2_OUI_LSB 0xFC00
111 #define RTL8211F_PHYID2_OUI_LSB_DEFAULT 0xC800
112 #define RTL8211F_PHYID2_MODEL_NUM 0x03F0
113 #define RTL8211F_PHYID2_MODEL_NUM_DEFAULT 0x0110
114 #define RTL8211F_PHYID2_REVISION_NUM 0x000F
115 #define RTL8211F_PHYID2_REVISION_NUM_DEFAULT 0x0006
116 
117 //Auto-Negotiation Advertisement register
118 #define RTL8211F_ANAR_NEXT_PAGE 0x8000
119 #define RTL8211F_ANAR_REMOTE_FAULT 0x2000
120 #define RTL8211F_ANAR_ASYM_PAUSE 0x0800
121 #define RTL8211F_ANAR_PAUSE 0x0400
122 #define RTL8211F_ANAR_100BT4 0x0200
123 #define RTL8211F_ANAR_100BTX_FD 0x0100
124 #define RTL8211F_ANAR_100BTX_HD 0x0080
125 #define RTL8211F_ANAR_10BT_FD 0x0040
126 #define RTL8211F_ANAR_10BT_HD 0x0020
127 #define RTL8211F_ANAR_SELECTOR 0x001F
128 #define RTL8211F_ANAR_SELECTOR_DEFAULT 0x0001
129 
130 //Auto-Negotiation Link Partner Ability register
131 #define RTL8211F_ANLPAR_NEXT_PAGE 0x8000
132 #define RTL8211F_ANLPAR_ACK 0x4000
133 #define RTL8211F_ANLPAR_REMOTE_FAULT 0x2000
134 #define RTL8211F_ANLPAR_ASYM_PAUSE 0x0800
135 #define RTL8211F_ANLPAR_PAUSE 0x0400
136 #define RTL8211F_ANLPAR_100BT4 0x0200
137 #define RTL8211F_ANLPAR_100BTX_FD 0x0100
138 #define RTL8211F_ANLPAR_100BTX_HD 0x0080
139 #define RTL8211F_ANLPAR_10BT_FD 0x0040
140 #define RTL8211F_ANLPAR_10BT_HD 0x0020
141 #define RTL8211F_ANLPAR_SELECTOR 0x001F
142 #define RTL8211F_ANLPAR_SELECTOR_DEFAULT 0x0001
143 
144 //Auto-Negotiation Expansion register
145 #define RTL8211F_ANER_RX_NP_LOCATION_ABLE 0x0040
146 #define RTL8211F_ANER_RX_NP_LOCATION 0x0020
147 #define RTL8211F_ANER_PAR_DETECT_FAULT 0x0010
148 #define RTL8211F_ANER_LP_NEXT_PAGE_ABLE 0x0008
149 #define RTL8211F_ANER_NEXT_PAGE_ABLE 0x0004
150 #define RTL8211F_ANER_PAGE_RECEIVED 0x0002
151 #define RTL8211F_ANER_LP_AN_ABLE 0x0001
152 
153 //Auto-Negotiation Next Page Transmit register
154 #define RTL8211F_ANNPTR_NEXT_PAGE 0x8000
155 #define RTL8211F_ANNPTR_MSG_PAGE 0x2000
156 #define RTL8211F_ANNPTR_ACK2 0x1000
157 #define RTL8211F_ANNPTR_TOGGLE 0x0800
158 #define RTL8211F_ANNPTR_MESSAGE 0x07FF
159 
160 //Auto-Negotiation Next Page Receive register
161 #define RTL8211F_ANNPRR_NEXT_PAGE 0x8000
162 #define RTL8211F_ANNPRR_ACK 0x4000
163 #define RTL8211F_ANNPRR_MSG_PAGE 0x2000
164 #define RTL8211F_ANNPRR_ACK2 0x1000
165 #define RTL8211F_ANNPRR_TOGGLE 0x0800
166 #define RTL8211F_ANNPRR_MESSAGE 0x07FF
167 
168 //1000Base-T Control register
169 #define RTL8211F_GBCR_TEST_MODE 0xE000
170 #define RTL8211F_GBCR_MS_MAN_CONF_EN 0x1000
171 #define RTL8211F_GBCR_MS_MAN_CONF_VAL 0x0800
172 #define RTL8211F_GBCR_PORT_TYPE 0x0400
173 #define RTL8211F_GBCR_1000BT_FD 0x0200
174 
175 //1000Base-T Status register
176 #define RTL8211F_GBSR_MS_CONF_FAULT 0x8000
177 #define RTL8211F_GBSR_MS_CONF_RES 0x4000
178 #define RTL8211F_GBSR_LOCAL_RECEIVER_STATUS 0x2000
179 #define RTL8211F_GBSR_REMOTE_RECEIVER_STATUS 0x1000
180 #define RTL8211F_GBSR_LP_1000BT_FD 0x0800
181 #define RTL8211F_GBSR_LP_1000BT_HD 0x0400
182 #define RTL8211F_GBSR_IDLE_ERR_COUNT 0x00FF
183 
184 //MMD Access Control register
185 #define RTL8211F_MMDACR_FUNC 0xC000
186 #define RTL8211F_MMDACR_FUNC_ADDR 0x0000
187 #define RTL8211F_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
188 #define RTL8211F_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
189 #define RTL8211F_MMDACR_FUNC_DATA_POST_INC_W 0xC000
190 #define RTL8211F_MMDACR_DEVAD 0x001F
191 
192 //1000Base-T Extended Status register
193 #define RTL8211F_GBESR_1000BX_FD 0x8000
194 #define RTL8211F_GBESR_1000BX_HD 0x4000
195 #define RTL8211F_GBESR_1000BT_FD 0x2000
196 #define RTL8211F_GBESR_1000BT_HD 0x1000
197 
198 //Interrupt Enable register
199 #define RTL8211F_INER_JABBER 0x0400
200 #define RTL8211F_INER_ALDPS_STATE 0x0200
201 #define RTL8211F_INER_PME 0x0080
202 #define RTL8211F_INER_PHY_REG_ACCESS 0x0020
203 #define RTL8211F_INER_LINK_STATUS 0x0010
204 #define RTL8211F_INER_AN_COMPLETE 0x0008
205 #define RTL8211F_INER_PAGE_RECEIVED 0x0004
206 #define RTL8211F_INER_AN_ERROR 0x0001
207 
208 //PHY Specific Control 1 register
209 #define RTL8211F_PHYCR1_PHYAD_0_EN 0x2000
210 #define RTL8211F_PHYCR1_MDI_MODE_MANUAL_CONFIG 0x0200
211 #define RTL8211F_PHYCR1_MDI_MODE 0x0100
212 #define RTL8211F_PHYCR1_TX_CRS_EN 0x0080
213 #define RTL8211F_PHYCR1_PHYAD_NON_ZERO_DETECT 0x0040
214 #define RTL8211F_PHYCR1_PREAMBLE_CHECK_EN 0x0010
215 #define RTL8211F_PHYCR1_JABBER_DETECT_EN 0x0008
216 #define RTL8211F_PHYCR1_ALDPS_EN 0x0004
217 
218 //PHY Specific Control 2 register
219 #define RTL8211F_PHYCR2_CLKOUT_FREQ_SEL 0x0800
220 #define RTL8211F_PHYCR2_CLKOUT_SSC_EN 0x0080
221 #define RTL8211F_PHYCR2_RXC_SSC_EN 0x0008
222 #define RTL8211F_PHYCR2_RXC_EN 0x0002
223 #define RTL8211F_PHYCR2_CLKOUT_EN 0x0001
224 
225 //PHY Specific Status register
226 #define RTL8211F_PHYSR_ALDPS_STATE 0x4000
227 #define RTL8211F_PHYSR_MDI_PLUG 0x2000
228 #define RTL8211F_PHYSR_NWAY_EN 0x1000
229 #define RTL8211F_PHYSR_MASTER_MODE 0x0800
230 #define RTL8211F_PHYSR_EEE_CAPABLE 0x0100
231 #define RTL8211F_PHYSR_RX_FLOW_EN 0x0080
232 #define RTL8211F_PHYSR_TX_FLOW_EN 0x0040
233 #define RTL8211F_PHYSR_SPEED 0x0030
234 #define RTL8211F_PHYSR_SPEED_10MBPS 0x0000
235 #define RTL8211F_PHYSR_SPEED_100MBPS 0x0010
236 #define RTL8211F_PHYSR_SPEED_1000MBPS 0x0020
237 #define RTL8211F_PHYSR_DUPLEX 0x0008
238 #define RTL8211F_PHYSR_LINK 0x0004
239 #define RTL8211F_PHYSR_MDI_CROSSOVER_STATUS 0x0002
240 #define RTL8211F_PHYSR_JABBER 0x0001
241 
242 //Interrupt Status register
243 #define RTL8211F_INSR_JABBER 0x0400
244 #define RTL8211F_INSR_ALDPS_STATE 0x0200
245 #define RTL8211F_INSR_PME 0x0080
246 #define RTL8211F_INSR_PHY_REG_ACCESS 0x0020
247 #define RTL8211F_INSR_LINK_STATUS 0x0010
248 #define RTL8211F_INSR_AN_COMPLETE 0x0008
249 #define RTL8211F_INSR_PAGE_RECEIVED 0x0004
250 #define RTL8211F_INSR_AN_ERROR 0x0001
251 
252 //Page Select register
253 #define RTL8211F_PAGSR_PAGE_SEL 0x0007
254 
255 //PCS Control 1 register
256 #define RTL8211F_PC1R_CLK_STOP_EN 0x0400
257 
258 //PCS Status 1 register
259 #define RTL8211F_PS1R_TX_LPI_RCVD 0x0800
260 #define RTL8211F_PS1R_RX_LPI_RCVD 0x0400
261 #define RTL8211F_PS1R_TX_LPI_IND 0x0200
262 #define RTL8211F_PS1R_RX_LPI_IND 0x0100
263 #define RTL8211F_PS1R_CLK_STOP_CAPABLE 0x0040
264 
265 //EEE Capability register
266 #define RTL8211F_EEECR_1000BT_EEE 0x0004
267 #define RTL8211F_EEECR_100BTX_EEE 0x0002
268 
269 //EEE Advertisement register
270 #define RTL8211F_EEEAR_1000BT_EEE 0x0004
271 #define RTL8211F_EEEAR_100BTX_EEE 0x0002
272 
273 //EEE Link Partner Ability register
274 #define RTL8211F_EEELPAR_LP_1000BT_EEE 0x0004
275 #define RTL8211F_EEELPAR_LP_100BTX_EEE 0x0002
276 
277 //C++ guard
278 #ifdef __cplusplus
279 extern "C" {
280 #endif
281 
282 //RTL8211F Ethernet PHY driver
283 extern const PhyDriver rtl8211fPhyDriver;
284 
285 //RTL8211F related functions
286 error_t rtl8211fInit(NetInterface *interface);
287 void rtl8211fInitHook(NetInterface *interface);
288 
289 void rtl8211fTick(NetInterface *interface);
290 
291 void rtl8211fEnableIrq(NetInterface *interface);
292 void rtl8211fDisableIrq(NetInterface *interface);
293 
294 void rtl8211fEventHandler(NetInterface *interface);
295 
296 void rtl8211fWritePhyReg(NetInterface *interface, uint8_t address,
297  uint16_t data);
298 
299 uint16_t rtl8211fReadPhyReg(NetInterface *interface, uint8_t address);
300 
301 void rtl8211fDumpPhyReg(NetInterface *interface);
302 
303 void rtl8211fWriteMmdReg(NetInterface *interface, uint8_t devAddr,
304  uint16_t regAddr, uint16_t data);
305 
306 uint16_t rtl8211fReadMmdReg(NetInterface *interface, uint8_t devAddr,
307  uint16_t regAddr);
308 
309 //C++ guard
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 #endif
void rtl8211fWriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
void rtl8211fWritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void rtl8211fDumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint16_t rtl8211fReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
void rtl8211fTick(NetInterface *interface)
RTL8211F timer handler.
void rtl8211fEnableIrq(NetInterface *interface)
Enable interrupts.
const PhyDriver rtl8211fPhyDriver
RTL8211F Ethernet PHY driver.
error_t rtl8211fInit(NetInterface *interface)
RTL8211F PHY transceiver initialization.
uint16_t regAddr
void rtl8211fDisableIrq(NetInterface *interface)
Disable interrupts.
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
uint16_t rtl8211fReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
void rtl8211fInitHook(NetInterface *interface)
RTL8211F custom configuration.
void rtl8211fEventHandler(NetInterface *interface)
RTL8211F event handler.