rtl8211f_driver.h
Go to the documentation of this file.
1 /**
2  * @file rtl8211f_driver.h
3  * @brief RTL8211F Gigabit Ethernet PHY transceiver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.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 //Basic Mode Control register
67 #define RTL8211F_BMCR_RESET 0x8000
68 #define RTL8211F_BMCR_LOOPBACK 0x4000
69 #define RTL8211F_BMCR_SPEED_SEL_LSB 0x2000
70 #define RTL8211F_BMCR_AN_EN 0x1000
71 #define RTL8211F_BMCR_POWER_DOWN 0x0800
72 #define RTL8211F_BMCR_ISOLATE 0x0400
73 #define RTL8211F_BMCR_RESTART_AN 0x0200
74 #define RTL8211F_BMCR_DUPLEX_MODE 0x0100
75 #define RTL8211F_BMCR_COL_TEST 0x0080
76 #define RTL8211F_BMCR_SPEED_SEL_MSB 0x0040
77 #define RTL8211F_BMCR_UNI_DIR_EN 0x0020
78 
79 //Basic Mode Status register
80 #define RTL8211F_BMSR_100BT4 0x8000
81 #define RTL8211F_BMSR_100BTX_FD 0x4000
82 #define RTL8211F_BMSR_100BTX_HD 0x2000
83 #define RTL8211F_BMSR_10BT_FD 0x1000
84 #define RTL8211F_BMSR_10BT_HD 0x0800
85 #define RTL8211F_BMSR_100BT2_FD 0x0400
86 #define RTL8211F_BMSR_100BT2_HD 0x0200
87 #define RTL8211F_BMSR_EXTENDED_STATUS 0x0100
88 #define RTL8211F_BMSR_UNI_DIR_CAPABLE 0x0080
89 #define RTL8211F_BMSR_PREAMBLE_SUPPR 0x0040
90 #define RTL8211F_BMSR_AN_COMPLETE 0x0020
91 #define RTL8211F_BMSR_REMOTE_FAULT 0x0010
92 #define RTL8211F_BMSR_AN_CAPABLE 0x0008
93 #define RTL8211F_BMSR_LINK_STATUS 0x0004
94 #define RTL8211F_BMSR_JABBER_DETECT 0x0002
95 #define RTL8211F_BMSR_EXTENDED_CAPABLE 0x0001
96 
97 //PHY Identifier 1 register
98 #define RTL8211F_PHYID1_OUI_MSB 0xFFFF
99 #define RTL8211F_PHYID1_OUI_MSB_DEFAULT 0x001C
100 
101 //PHY Identifier 2 register
102 #define RTL8211F_PHYID2_OUI_LSB 0xFC00
103 #define RTL8211F_PHYID2_OUI_LSB_DEFAULT 0xC800
104 #define RTL8211F_PHYID2_MODEL_NUM 0x03F0
105 #define RTL8211F_PHYID2_MODEL_NUM_DEFAULT 0x0110
106 #define RTL8211F_PHYID2_REVISION_NUM 0x000F
107 #define RTL8211F_PHYID2_REVISION_NUM_DEFAULT 0x0006
108 
109 //Auto-Negotiation Advertisement register
110 #define RTL8211F_ANAR_NEXT_PAGE 0x8000
111 #define RTL8211F_ANAR_REMOTE_FAULT 0x2000
112 #define RTL8211F_ANAR_ASYM_PAUSE 0x0800
113 #define RTL8211F_ANAR_PAUSE 0x0400
114 #define RTL8211F_ANAR_100BT4 0x0200
115 #define RTL8211F_ANAR_100BTX_FD 0x0100
116 #define RTL8211F_ANAR_100BTX_HD 0x0080
117 #define RTL8211F_ANAR_10BT_FD 0x0040
118 #define RTL8211F_ANAR_10BT_HD 0x0020
119 #define RTL8211F_ANAR_SELECTOR 0x001F
120 #define RTL8211F_ANAR_SELECTOR_DEFAULT 0x0001
121 
122 //Auto-Negotiation Link Partner Ability register
123 #define RTL8211F_ANLPAR_NEXT_PAGE 0x8000
124 #define RTL8211F_ANLPAR_ACK 0x4000
125 #define RTL8211F_ANLPAR_REMOTE_FAULT 0x2000
126 #define RTL8211F_ANLPAR_ASYM_PAUSE 0x0800
127 #define RTL8211F_ANLPAR_PAUSE 0x0400
128 #define RTL8211F_ANLPAR_100BT4 0x0200
129 #define RTL8211F_ANLPAR_100BTX_FD 0x0100
130 #define RTL8211F_ANLPAR_100BTX_HD 0x0080
131 #define RTL8211F_ANLPAR_10BT_FD 0x0040
132 #define RTL8211F_ANLPAR_10BT_HD 0x0020
133 #define RTL8211F_ANLPAR_SELECTOR 0x001F
134 #define RTL8211F_ANLPAR_SELECTOR_DEFAULT 0x0001
135 
136 //Auto-Negotiation Expansion register
137 #define RTL8211F_ANER_RX_NP_LOCATION_ABLE 0x0040
138 #define RTL8211F_ANER_RX_NP_LOCATION 0x0020
139 #define RTL8211F_ANER_PAR_DETECT_FAULT 0x0010
140 #define RTL8211F_ANER_LP_NEXT_PAGE_ABLE 0x0008
141 #define RTL8211F_ANER_NEXT_PAGE_ABLE 0x0004
142 #define RTL8211F_ANER_PAGE_RECEIVED 0x0002
143 #define RTL8211F_ANER_LP_AN_ABLE 0x0001
144 
145 //Auto-Negotiation Next Page Transmit register
146 #define RTL8211F_ANNPTR_NEXT_PAGE 0x8000
147 #define RTL8211F_ANNPTR_MSG_PAGE 0x2000
148 #define RTL8211F_ANNPTR_ACK2 0x1000
149 #define RTL8211F_ANNPTR_TOGGLE 0x0800
150 #define RTL8211F_ANNPTR_MESSAGE 0x07FF
151 
152 //Auto-Negotiation Next Page Receive register
153 #define RTL8211F_ANNPRR_NEXT_PAGE 0x8000
154 #define RTL8211F_ANNPRR_ACK 0x4000
155 #define RTL8211F_ANNPRR_MSG_PAGE 0x2000
156 #define RTL8211F_ANNPRR_ACK2 0x1000
157 #define RTL8211F_ANNPRR_TOGGLE 0x0800
158 #define RTL8211F_ANNPRR_MESSAGE 0x07FF
159 
160 //1000Base-T Control register
161 #define RTL8211F_GBCR_TEST_MODE 0xE000
162 #define RTL8211F_GBCR_MS_MAN_CONF_EN 0x1000
163 #define RTL8211F_GBCR_MS_MAN_CONF_VAL 0x0800
164 #define RTL8211F_GBCR_PORT_TYPE 0x0400
165 #define RTL8211F_GBCR_1000BT_FD 0x0200
166 
167 //1000Base-T Status register
168 #define RTL8211F_GBSR_MS_CONF_FAULT 0x8000
169 #define RTL8211F_GBSR_MS_CONF_RES 0x4000
170 #define RTL8211F_GBSR_LOCAL_RECEIVER_STATUS 0x2000
171 #define RTL8211F_GBSR_REMOTE_RECEIVER_STATUS 0x1000
172 #define RTL8211F_GBSR_LP_1000BT_FD 0x0800
173 #define RTL8211F_GBSR_LP_1000BT_HD 0x0400
174 #define RTL8211F_GBSR_IDLE_ERR_COUNT 0x00FF
175 
176 //MMD Access Control register
177 #define RTL8211F_MMDACR_FUNC 0xC000
178 #define RTL8211F_MMDACR_FUNC_ADDR 0x0000
179 #define RTL8211F_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
180 #define RTL8211F_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
181 #define RTL8211F_MMDACR_FUNC_DATA_POST_INC_W 0xC000
182 #define RTL8211F_MMDACR_DEVAD 0x001F
183 
184 //1000Base-T Extended Status register
185 #define RTL8211F_GBESR_1000BX_FD 0x8000
186 #define RTL8211F_GBESR_1000BX_HD 0x4000
187 #define RTL8211F_GBESR_1000BT_FD 0x2000
188 #define RTL8211F_GBESR_1000BT_HD 0x1000
189 
190 //Interrupt Enable register
191 #define RTL8211F_INER_JABBER 0x0400
192 #define RTL8211F_INER_ALDPS_STATE 0x0200
193 #define RTL8211F_INER_PME 0x0080
194 #define RTL8211F_INER_PHY_REG_ACCESS 0x0020
195 #define RTL8211F_INER_LINK_STATUS 0x0010
196 #define RTL8211F_INER_AN_COMPLETE 0x0008
197 #define RTL8211F_INER_PAGE_RECEIVED 0x0004
198 #define RTL8211F_INER_AN_ERROR 0x0001
199 
200 //PHY Specific Control 1 register
201 #define RTL8211F_PHYCR1_PHYAD_0_EN 0x2000
202 #define RTL8211F_PHYCR1_MDI_MODE_MANUAL_CONFIG 0x0200
203 #define RTL8211F_PHYCR1_MDI_MODE 0x0100
204 #define RTL8211F_PHYCR1_TX_CRS_EN 0x0080
205 #define RTL8211F_PHYCR1_PHYAD_NON_ZERO_DETECT 0x0040
206 #define RTL8211F_PHYCR1_PREAMBLE_CHECK_EN 0x0010
207 #define RTL8211F_PHYCR1_JABBER_DETECT_EN 0x0008
208 #define RTL8211F_PHYCR1_ALDPS_EN 0x0004
209 
210 //PHY Specific Control 2 register
211 #define RTL8211F_PHYCR2_CLKOUT_FREQ_SEL 0x0800
212 #define RTL8211F_PHYCR2_CLKOUT_SSC_EN 0x0080
213 #define RTL8211F_PHYCR2_RXC_SSC_EN 0x0008
214 #define RTL8211F_PHYCR2_RXC_EN 0x0002
215 #define RTL8211F_PHYCR2_CLKOUT_EN 0x0001
216 
217 //PHY Specific Status register
218 #define RTL8211F_PHYSR_ALDPS_STATE 0x4000
219 #define RTL8211F_PHYSR_MDI_PLUG 0x2000
220 #define RTL8211F_PHYSR_NWAY_EN 0x1000
221 #define RTL8211F_PHYSR_MASTER_MODE 0x0800
222 #define RTL8211F_PHYSR_EEE_CAPABLE 0x0100
223 #define RTL8211F_PHYSR_RX_FLOW_EN 0x0080
224 #define RTL8211F_PHYSR_TX_FLOW_EN 0x0040
225 #define RTL8211F_PHYSR_SPEED 0x0030
226 #define RTL8211F_PHYSR_SPEED_10MBPS 0x0000
227 #define RTL8211F_PHYSR_SPEED_100MBPS 0x0010
228 #define RTL8211F_PHYSR_SPEED_1000MBPS 0x0020
229 #define RTL8211F_PHYSR_DUPLEX 0x0008
230 #define RTL8211F_PHYSR_LINK 0x0004
231 #define RTL8211F_PHYSR_MDI_CROSSOVER_STATUS 0x0002
232 #define RTL8211F_PHYSR_JABBER 0x0001
233 
234 //Interrupt Status register
235 #define RTL8211F_INSR_JABBER 0x0400
236 #define RTL8211F_INSR_ALDPS_STATE 0x0200
237 #define RTL8211F_INSR_PME 0x0080
238 #define RTL8211F_INSR_PHY_REG_ACCESS 0x0020
239 #define RTL8211F_INSR_LINK_STATUS 0x0010
240 #define RTL8211F_INSR_AN_COMPLETE 0x0008
241 #define RTL8211F_INSR_PAGE_RECEIVED 0x0004
242 #define RTL8211F_INSR_AN_ERROR 0x0001
243 
244 //Page Select register
245 #define RTL8211F_PAGSR_PAGE_SEL 0x0007
246 
247 //C++ guard
248 #ifdef __cplusplus
249  extern "C" {
250 #endif
251 
252 //RTL8211F Ethernet PHY driver
253 extern const PhyDriver rtl8211fPhyDriver;
254 
255 //RTL8211F related functions
256 error_t rtl8211fInit(NetInterface *interface);
257 
258 void rtl8211fTick(NetInterface *interface);
259 
260 void rtl8211fEnableIrq(NetInterface *interface);
261 void rtl8211fDisableIrq(NetInterface *interface);
262 
263 void rtl8211fEventHandler(NetInterface *interface);
264 
265 void rtl8211fWritePhyReg(NetInterface *interface, uint8_t address,
266  uint16_t data);
267 
268 uint16_t rtl8211fReadPhyReg(NetInterface *interface, uint8_t address);
269 
270 void rtl8211fDumpPhyReg(NetInterface *interface);
271 
272 //C++ guard
273 #ifdef __cplusplus
274  }
275 #endif
276 
277 #endif
const PhyDriver rtl8211fPhyDriver
RTL8211F Ethernet PHY driver.
void rtl8211fTick(NetInterface *interface)
RTL8211F timer handler.
PHY driver.
Definition: nic.h:214
void rtl8211fDumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void rtl8211fEventHandler(NetInterface *interface)
RTL8211F event handler.
Ipv6Addr address
void rtl8211fWritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t
Error codes.
Definition: error.h:42
uint8_t data[]
Definition: dtls_misc.h:169
#define NetInterface
Definition: net.h:36
void rtl8211fDisableIrq(NetInterface *interface)
Disable interrupts.
error_t rtl8211fInit(NetInterface *interface)
RTL8211F PHY transceiver initialization.
Network interface controller abstraction layer.
void rtl8211fEnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t rtl8211fReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.