ksz9031_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz9031_driver.h
3  * @brief KSZ9031 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.6
29  **/
30 
31 #ifndef _KSZ9031_DRIVER_H
32 #define _KSZ9031_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ9031_PHY_ADDR
39  #define KSZ9031_PHY_ADDR 7
40 #elif (KSZ9031_PHY_ADDR < 0 || KSZ9031_PHY_ADDR > 31)
41  #error KSZ9031_PHY_ADDR parameter is not valid
42 #endif
43 
44 //KSZ9031 PHY registers
45 #define KSZ9031_BMCR 0x00
46 #define KSZ9031_BMSR 0x01
47 #define KSZ9031_PHYID1 0x02
48 #define KSZ9031_PHYID2 0x03
49 #define KSZ9031_ANAR 0x04
50 #define KSZ9031_ANLPAR 0x05
51 #define KSZ9031_ANER 0x06
52 #define KSZ9031_ANNPR 0x07
53 #define KSZ9031_ANLPNPR 0x08
54 #define KSZ9031_GBCR 0x09
55 #define KSZ9031_GBSR 0x0A
56 #define KSZ9031_MMDACR 0x0D
57 #define KSZ9031_MMDAADR 0x0E
58 #define KSZ9031_GBESR 0x0F
59 #define KSZ9031_RLB 0x11
60 #define KSZ9031_LINKMD 0x12
61 #define KSZ9031_DPMAPCSS 0x13
62 #define KSZ9031_RXERCTR 0x15
63 #define KSZ9031_ICSR 0x1B
64 #define KSZ9031_AUTOMDI 0x1C
65 #define KSZ9031_PHYCON 0x1F
66 
67 //Basic Control register
68 #define KSZ9031_BMCR_RESET 0x8000
69 #define KSZ9031_BMCR_LOOPBACK 0x4000
70 #define KSZ9031_BMCR_SPEED_SEL_LSB 0x2000
71 #define KSZ9031_BMCR_AN_EN 0x1000
72 #define KSZ9031_BMCR_POWER_DOWN 0x0800
73 #define KSZ9031_BMCR_ISOLATE 0x0400
74 #define KSZ9031_BMCR_RESTART_AN 0x0200
75 #define KSZ9031_BMCR_DUPLEX_MODE 0x0100
76 #define KSZ9031_BMCR_SPEED_SEL_MSB 0x0040
77 
78 //Basic Status register
79 #define KSZ9031_BMSR_100BT4 0x8000
80 #define KSZ9031_BMSR_100BTX_FD 0x4000
81 #define KSZ9031_BMSR_100BTX_HD 0x2000
82 #define KSZ9031_BMSR_10BT_FD 0x1000
83 #define KSZ9031_BMSR_10BT_HD 0x0800
84 #define KSZ9031_BMSR_EXTENDED_STATUS 0x0100
85 #define KSZ9031_BMSR_NO_PREAMBLE 0x0040
86 #define KSZ9031_BMSR_AN_COMPLETE 0x0020
87 #define KSZ9031_BMSR_REMOTE_FAULT 0x0010
88 #define KSZ9031_BMSR_AN_CAPABLE 0x0008
89 #define KSZ9031_BMSR_LINK_STATUS 0x0004
90 #define KSZ9031_BMSR_JABBER_DETECT 0x0002
91 #define KSZ9031_BMSR_EXTENDED_CAPABLE 0x0001
92 
93 //PHY Identifier 1 register
94 #define KSZ9031_PHYID1_PHY_ID_MSB 0xFFFF
95 #define KSZ9031_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
96 
97 //PHY Identifier 2 register
98 #define KSZ9031_PHYID2_PHY_ID_LSB 0xFC00
99 #define KSZ9031_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
100 #define KSZ9031_PHYID2_MODEL_NUM 0x03F0
101 #define KSZ9031_PHYID2_MODEL_NUM_DEFAULT 0x0220
102 #define KSZ9031_PHYID2_REVISION_NUM 0x000F
103 
104 //Auto-Negotiation Advertisement register
105 #define KSZ9031_ANAR_NEXT_PAGE 0x8000
106 #define KSZ9031_ANAR_REMOTE_FAULT 0x2000
107 #define KSZ9031_ANAR_PAUSE 0x0C00
108 #define KSZ9031_ANAR_100BT4 0x0200
109 #define KSZ9031_ANAR_100BTX_FD 0x0100
110 #define KSZ9031_ANAR_100BTX_HD 0x0080
111 #define KSZ9031_ANAR_10BT_FD 0x0040
112 #define KSZ9031_ANAR_10BT_HD 0x0020
113 #define KSZ9031_ANAR_SELECTOR 0x001F
114 #define KSZ9031_ANAR_SELECTOR_DEFAULT 0x0001
115 
116 //Auto-Negotiation Link Partner Ability register
117 #define KSZ9031_ANLPAR_NEXT_PAGE 0x8000
118 #define KSZ9031_ANLPAR_ACK 0x4000
119 #define KSZ9031_ANLPAR_REMOTE_FAULT 0x2000
120 #define KSZ9031_ANLPAR_PAUSE 0x0C00
121 #define KSZ9031_ANLPAR_100BT4 0x0200
122 #define KSZ9031_ANLPAR_100BTX_FD 0x0100
123 #define KSZ9031_ANLPAR_100BTX_HD 0x0080
124 #define KSZ9031_ANLPAR_10BT_FD 0x0040
125 #define KSZ9031_ANLPAR_10BT_HD 0x0020
126 #define KSZ9031_ANLPAR_SELECTOR 0x001F
127 #define KSZ9031_ANLPAR_SELECTOR_DEFAULT 0x0001
128 
129 //Auto-Negotiation Expansion register
130 #define KSZ9031_ANER_PAR_DETECT_FAULT 0x0010
131 #define KSZ9031_ANER_LP_NEXT_PAGE_ABLE 0x0008
132 #define KSZ9031_ANER_NEXT_PAGE_ABLE 0x0004
133 #define KSZ9031_ANER_PAGE_RECEIVED 0x0002
134 #define KSZ9031_ANER_LP_AN_ABLE 0x0001
135 
136 //Auto-Negotiation Next Page register
137 #define KSZ9031_ANNPR_NEXT_PAGE 0x8000
138 #define KSZ9031_ANNPR_MSG_PAGE 0x2000
139 #define KSZ9031_ANNPR_ACK2 0x1000
140 #define KSZ9031_ANNPR_TOGGLE 0x0800
141 #define KSZ9031_ANNPR_MESSAGE 0x07FF
142 
143 //Link Partner Next Page Ability register
144 #define KSZ9031_ANLPNPR_NEXT_PAGE 0x8000
145 #define KSZ9031_ANLPNPR_ACK 0x4000
146 #define KSZ9031_ANLPNPR_MSG_PAGE 0x2000
147 #define KSZ9031_ANLPNPR_ACK2 0x1000
148 #define KSZ9031_ANLPNPR_TOGGLE 0x0800
149 #define KSZ9031_ANLPNPR_MESSAGE 0x07FF
150 
151 //1000BASE-T Control register
152 #define KSZ9031_GBCR_TEST_MODE 0xE000
153 #define KSZ9031_GBCR_MS_MAN_CONF_EN 0x1000
154 #define KSZ9031_GBCR_MS_MAN_CONF_VAL 0x0800
155 #define KSZ9031_GBCR_PORT_TYPE 0x0400
156 #define KSZ9031_GBCR_1000BT_FD 0x0200
157 #define KSZ9031_GBCR_1000BT_HD 0x0100
158 
159 //1000BASE-T Status register
160 #define KSZ9031_GBSR_MS_CONF_FAULT 0x8000
161 #define KSZ9031_GBSR_MS_CONF_RES 0x4000
162 #define KSZ9031_GBSR_LOCAL_RECEIVER_STATUS 0x2000
163 #define KSZ9031_GBSR_REMOTE_RECEIVER_STATUS 0x1000
164 #define KSZ9031_GBSR_LP_1000BT_FD 0x0800
165 #define KSZ9031_GBSR_LP_1000BT_HD 0x0400
166 #define KSZ9031_GBSR_IDLE_ERR_COUNT 0x00FF
167 
168 //MMD Access Control register
169 #define KSZ9031_MMDACR_FUNC 0xC000
170 #define KSZ9031_MMDACR_FUNC_ADDR 0x0000
171 #define KSZ9031_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
172 #define KSZ9031_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
173 #define KSZ9031_MMDACR_FUNC_DATA_POST_INC_W 0xC000
174 #define KSZ9031_MMDACR_DEVAD 0x001F
175 
176 //Extended Status register
177 #define KSZ9031_GBESR_1000BX_FD 0x8000
178 #define KSZ9031_GBESR_1000BX_HD 0x4000
179 #define KSZ9031_GBESR_1000BT_FD 0x2000
180 #define KSZ9031_GBESR_1000BT_HD 0x1000
181 
182 //Remote Loopback register
183 #define KSZ9031_RLB_REMOTE_LOOPBACK 0x0100
184 
185 //LinkMD Cable Diagnostic register
186 #define KSZ9031_LINKMD_TEST_EN 0x8000
187 #define KSZ9031_LINKMD_PAIR 0x3000
188 #define KSZ9031_LINKMD_PAIR_A 0x0000
189 #define KSZ9031_LINKMD_PAIR_B 0x1000
190 #define KSZ9031_LINKMD_PAIR_C 0x2000
191 #define KSZ9031_LINKMD_PAIR_D 0x3000
192 #define KSZ9031_LINKMD_STATUS 0x0300
193 #define KSZ9031_LINKMD_STATUS_NORMAL 0x0000
194 #define KSZ9031_LINKMD_STATUS_OPEN 0x0100
195 #define KSZ9031_LINKMD_STATUS_SHORT 0x0200
196 #define KSZ9031_LINKMD_FAULT_DATA 0x00FF
197 
198 //Digital PMA/PCS Status register
199 #define KSZ9031_DPMAPCSS_1000BT_LINK_STATUS 0x0004
200 #define KSZ9031_DPMAPCSS_100BTX_LINK_STATUS 0x0002
201 
202 //Interrupt Control/Status register
203 #define KSZ9031_ICSR_JABBER_IE 0x8000
204 #define KSZ9031_ICSR_RECEIVE_ERROR_IE 0x4000
205 #define KSZ9031_ICSR_PAGE_RECEIVED_IE 0x2000
206 #define KSZ9031_ICSR_PAR_DETECT_FAULT_IE 0x1000
207 #define KSZ9031_ICSR_LP_ACK_IE 0x0800
208 #define KSZ9031_ICSR_LINK_DOWN_IE 0x0400
209 #define KSZ9031_ICSR_REMOTE_FAULT_IE 0x0200
210 #define KSZ9031_ICSR_LINK_UP_IE 0x0100
211 #define KSZ9031_ICSR_JABBER_IF 0x0080
212 #define KSZ9031_ICSR_RECEIVE_ERROR_IF 0x0040
213 #define KSZ9031_ICSR_PAGE_RECEIVED_IF 0x0020
214 #define KSZ9031_ICSR_PAR_DETECT_FAULT_IF 0x0010
215 #define KSZ9031_ICSR_LP_ACK_IF 0x0008
216 #define KSZ9031_ICSR_LINK_DOWN_IF 0x0004
217 #define KSZ9031_ICSR_REMOTE_FAULT_IF 0x0002
218 #define KSZ9031_ICSR_LINK_UP_IF 0x0001
219 
220 //Auto MDI/MDI-X register
221 #define KSZ9031_AUTOMDI_MDI_SET 0x0080
222 #define KSZ9031_AUTOMDI_SWAP_OFF 0x0040
223 
224 //PHY Control register
225 #define KSZ9031_PHYCON_INT_LEVEL 0x4000
226 #define KSZ9031_PHYCON_JABBER_EN 0x0200
227 #define KSZ9031_PHYCON_SPEED_1000BT 0x0040
228 #define KSZ9031_PHYCON_SPEED_100BTX 0x0020
229 #define KSZ9031_PHYCON_SPEED_10BT 0x0010
230 #define KSZ9031_PHYCON_DUPLEX_STATUS 0x0008
231 #define KSZ9031_PHYCON_1000BT_MS_STATUS 0x0004
232 #define KSZ9031_PHYCON_LINK_STATUS_CHECK_FAIL 0x0001
233 
234 //C++ guard
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 //KSZ9031 Ethernet PHY driver
240 extern const PhyDriver ksz9031PhyDriver;
241 
242 //KSZ9031 related functions
243 error_t ksz9031Init(NetInterface *interface);
244 
245 void ksz9031Tick(NetInterface *interface);
246 
247 void ksz9031EnableIrq(NetInterface *interface);
248 void ksz9031DisableIrq(NetInterface *interface);
249 
250 void ksz9031EventHandler(NetInterface *interface);
251 
252 void ksz9031WritePhyReg(NetInterface *interface, uint8_t address,
253  uint16_t data);
254 
255 uint16_t ksz9031ReadPhyReg(NetInterface *interface, uint8_t address);
256 
257 void ksz9031DumpPhyReg(NetInterface *interface);
258 
259 //C++ guard
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif
PHY driver.
Definition: nic.h:214
void ksz9031EventHandler(NetInterface *interface)
KSZ9031 event handler.
void ksz9031DisableIrq(NetInterface *interface)
Disable interrupts.
void ksz9031Tick(NetInterface *interface)
KSZ9031 timer handler.
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
void ksz9031DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void ksz9031EnableIrq(NetInterface *interface)
Enable interrupts.
const PhyDriver ksz9031PhyDriver
KSZ9031 Ethernet PHY driver.
void ksz9031WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
Network interface controller abstraction layer.
Ipv6Addr address
uint16_t ksz9031ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
uint8_t data[]
Definition: dtls_misc.h:176
error_t ksz9031Init(NetInterface *interface)
KSZ9031 PHY transceiver initialization.