ksz8895_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8895_driver.h
3  * @brief KSZ8895 5-port Ethernet switch 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.0
29  **/
30 
31 #ifndef _KSZ8895_DRIVER_H
32 #define _KSZ8895_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Port identifiers
38 #define KSZ8895_PORT1 1
39 #define KSZ8895_PORT2 2
40 #define KSZ8895_PORT3 3
41 #define KSZ8895_PORT4 4
42 #define KSZ8895_PORT5 5
43 
44 //Port masks
45 #define KSZ8895_PORT_MASK 0x1F
46 #define KSZ8895_PORT1_MASK 0x01
47 #define KSZ8895_PORT2_MASK 0x02
48 #define KSZ8895_PORT3_MASK 0x04
49 #define KSZ8895_PORT4_MASK 0x08
50 #define KSZ8895_PORT5_MASK 0x10
51 
52 //SPI command byte
53 #define KSZ8895_SPI_CMD_WRITE 0x02
54 #define KSZ8895_SPI_CMD_READ 0x03
55 
56 //Size of static and dynamic MAC tables
57 #define KSZ8895_STATIC_MAC_TABLE_SIZE 32
58 #define KSZ8895_DYNAMIC_MAC_TABLE_SIZE 1024
59 #define KSZ8895_VLAN_TABLE_SIZE 4096
60 
61 //Tail tag rules (host to KSZ8895)
62 #define KSZ8895_TAIL_TAG_NORMAL_ADDR_LOOKUP 0x80
63 #define KSZ8895_TAIL_TAG_PORT_SEL 0x40
64 #define KSZ8895_TAIL_TAG_DEST_QUEUE 0x30
65 #define KSZ8895_TAIL_TAG_DEST_PORT4 0x08
66 #define KSZ8895_TAIL_TAG_DEST_PORT3 0x04
67 #define KSZ8895_TAIL_TAG_DEST_PORT2 0x02
68 #define KSZ8895_TAIL_TAG_DEST_PORT1 0x01
69 
70 //Tail tag rules (KSZ8895 to host)
71 #define KSZ8895_TAIL_TAG_SRC_PORT 0x03
72 
73 //KSZ8895 PHY registers
74 #define KSZ8895_BMCR 0x00
75 #define KSZ8895_BMSR 0x01
76 #define KSZ8895_PHYID1 0x02
77 #define KSZ8895_PHYID2 0x03
78 #define KSZ8895_ANAR 0x04
79 #define KSZ8895_ANLPAR 0x05
80 #define KSZ8895_LINKMD 0x1D
81 #define KSZ8895_PHYSCS 0x1F
82 
83 //KSZ8895 Switch registers
84 #define KSZ8895_CHIP_ID0 0x00
85 #define KSZ8895_CHIP_ID1 0x01
86 #define KSZ8895_GLOBAL_CTRL0 0x02
87 #define KSZ8895_GLOBAL_CTRL1 0x03
88 #define KSZ8895_GLOBAL_CTRL2 0x04
89 #define KSZ8895_GLOBAL_CTRL3 0x05
90 #define KSZ8895_GLOBAL_CTRL4 0x06
91 #define KSZ8895_GLOBAL_CTRL5 0x07
92 #define KSZ8895_GLOBAL_CTRL6 0x08
93 #define KSZ8895_GLOBAL_CTRL7 0x09
94 #define KSZ8895_GLOBAL_CTRL8 0x0A
95 #define KSZ8895_GLOBAL_CTRL9 0x0B
96 #define KSZ8895_GLOBAL_CTRL10 0x0C
97 #define KSZ8895_GLOBAL_CTRL11 0x0D
98 #define KSZ8895_PD_MGMT_CTRL1 0x0E
99 #define KSZ8895_PD_MGMT_CTRL2 0x0F
100 #define KSZ8895_PORT1_CTRL0 0x10
101 #define KSZ8895_PORT1_CTRL1 0x11
102 #define KSZ8895_PORT1_CTRL2 0x12
103 #define KSZ8895_PORT1_CTRL3 0x13
104 #define KSZ8895_PORT1_CTRL4 0x14
105 #define KSZ8895_PORT1_STAT0 0x19
106 #define KSZ8895_PORT1_PSCS 0x1A
107 #define KSZ8895_PORT1_LINKMD 0x1B
108 #define KSZ8895_PORT1_CTRL5 0x1C
109 #define KSZ8895_PORT1_CTRL6 0x1D
110 #define KSZ8895_PORT1_STAT1 0x1E
111 #define KSZ8895_PORT1_CTRL7_STAT2 0x1F
112 #define KSZ8895_PORT2_CTRL0 0x20
113 #define KSZ8895_PORT2_CTRL1 0x21
114 #define KSZ8895_PORT2_CTRL2 0x22
115 #define KSZ8895_PORT2_CTRL3 0x23
116 #define KSZ8895_PORT2_CTRL4 0x24
117 #define KSZ8895_PORT2_STAT0 0x29
118 #define KSZ8895_PORT2_PSCS 0x2A
119 #define KSZ8895_PORT2_LINKMD 0x2B
120 #define KSZ8895_PORT2_CTRL5 0x2C
121 #define KSZ8895_PORT2_CTRL6 0x2D
122 #define KSZ8895_PORT2_STAT1 0x2E
123 #define KSZ8895_PORT2_CTRL7_STAT2 0x2F
124 #define KSZ8895_PORT3_CTRL0 0x30
125 #define KSZ8895_PORT3_CTRL1 0x31
126 #define KSZ8895_PORT3_CTRL2 0x32
127 #define KSZ8895_PORT3_CTRL3 0x33
128 #define KSZ8895_PORT3_CTRL4 0x34
129 #define KSZ8895_PORT3_STAT0 0x39
130 #define KSZ8895_PORT3_PSCS 0x3A
131 #define KSZ8895_PORT3_LINKMD 0x3B
132 #define KSZ8895_PORT3_CTRL5 0x3C
133 #define KSZ8895_PORT3_CTRL6 0x3D
134 #define KSZ8895_PORT3_STAT1 0x3E
135 #define KSZ8895_PORT3_CTRL7_STAT2 0x3F
136 #define KSZ8895_PORT4_CTRL0 0x40
137 #define KSZ8895_PORT4_CTRL1 0x41
138 #define KSZ8895_PORT4_CTRL2 0x42
139 #define KSZ8895_PORT4_CTRL3 0x43
140 #define KSZ8895_PORT4_CTRL4 0x44
141 #define KSZ8895_PORT4_STAT0 0x49
142 #define KSZ8895_PORT4_PSCS 0x4A
143 #define KSZ8895_PORT4_LINKMD 0x4B
144 #define KSZ8895_PORT4_CTRL5 0x4C
145 #define KSZ8895_PORT4_CTRL6 0x4D
146 #define KSZ8895_PORT4_STAT1 0x4E
147 #define KSZ8895_PORT4_CTRL7_STAT2 0x4F
148 #define KSZ8895_PORT5_CTRL0 0x50
149 #define KSZ8895_PORT5_CTRL1 0x51
150 #define KSZ8895_PORT5_CTRL2 0x52
151 #define KSZ8895_PORT5_CTRL3 0x53
152 #define KSZ8895_PORT5_CTRL4 0x54
153 #define KSZ8895_RMII_MGMT_CTRL 0x57
154 #define KSZ8895_PORT5_STAT0 0x59
155 #define KSZ8895_PORT5_PSCS 0x5A
156 #define KSZ8895_PORT5_LINKMD 0x5B
157 #define KSZ8895_PORT5_CTRL5 0x5C
158 #define KSZ8895_PORT5_CTRL6 0x5D
159 #define KSZ8895_PORT5_STAT1 0x5E
160 #define KSZ8895_PORT5_CTRL7_STAT2 0x5F
161 #define KSZ8895_MAC_ADDR0 0x68
162 #define KSZ8895_MAC_ADDR1 0x69
163 #define KSZ8895_MAC_ADDR2 0x6A
164 #define KSZ8895_MAC_ADDR3 0x6B
165 #define KSZ8895_MAC_ADDR4 0x6C
166 #define KSZ8895_MAC_ADDR5 0x6D
167 #define KSZ8895_INDIRECT_CTRL0 0x6E
168 #define KSZ8895_INDIRECT_CTRL1 0x6F
169 #define KSZ8895_INDIRECT_DATA8 0x70
170 #define KSZ8895_INDIRECT_DATA7 0x71
171 #define KSZ8895_INDIRECT_DATA6 0x72
172 #define KSZ8895_INDIRECT_DATA5 0x73
173 #define KSZ8895_INDIRECT_DATA4 0x74
174 #define KSZ8895_INDIRECT_DATA3 0x75
175 #define KSZ8895_INDIRECT_DATA2 0x76
176 #define KSZ8895_INDIRECT_DATA1 0x77
177 #define KSZ8895_INDIRECT_DATA0 0x78
178 #define KSZ8895_INT_STAT 0x7C
179 #define KSZ8895_INT_MASK 0x7D
180 #define KSZ8895_GLOBAL_CTRL12 0x80
181 #define KSZ8895_GLOBAL_CTRL13 0x81
182 #define KSZ8895_GLOBAL_CTRL14 0x82
183 #define KSZ8895_GLOBAL_CTRL15 0x83
184 #define KSZ8895_GLOBAL_CTRL16 0x84
185 #define KSZ8895_GLOBAL_CTRL17 0x85
186 #define KSZ8895_GLOBAL_CTRL18 0x86
187 #define KSZ8895_GLOBAL_CTRL19 0x87
188 #define KSZ8895_ID 0x89
189 #define KSZ8895_TOS_PRIO_CTRL0 0x90
190 #define KSZ8895_TOS_PRIO_CTRL1 0x91
191 #define KSZ8895_TOS_PRIO_CTRL2 0x92
192 #define KSZ8895_TOS_PRIO_CTRL3 0x93
193 #define KSZ8895_TOS_PRIO_CTRL4 0x94
194 #define KSZ8895_TOS_PRIO_CTRL5 0x95
195 #define KSZ8895_TOS_PRIO_CTRL6 0x96
196 #define KSZ8895_TOS_PRIO_CTRL7 0x97
197 #define KSZ8895_TOS_PRIO_CTRL8 0x98
198 #define KSZ8895_TOS_PRIO_CTRL9 0x99
199 #define KSZ8895_TOS_PRIO_CTRL10 0x9A
200 #define KSZ8895_TOS_PRIO_CTRL11 0x9B
201 #define KSZ8895_TOS_PRIO_CTRL12 0x9C
202 #define KSZ8895_TOS_PRIO_CTRL13 0x9D
203 #define KSZ8895_TOS_PRIO_CTRL14 0x9E
204 #define KSZ8895_TOS_PRIO_CTRL15 0x9F
205 #define KSZ8895_PORT1_CTRL8 0xB0
206 #define KSZ8895_PORT1_CTRL9 0xB1
207 #define KSZ8895_PORT1_CTRL10 0xB2
208 #define KSZ8895_PORT1_CTRL11 0xB3
209 #define KSZ8895_PORT1_CTRL12 0xB4
210 #define KSZ8895_PORT1_CTRL13 0xB5
211 #define KSZ8895_PORT1_RATE_LIMIT_CTRL 0xB6
212 #define KSZ8895_PORT1_PRIO0_IG_LIMIT_CTRL1 0xB7
213 #define KSZ8895_PORT1_PRIO1_IG_LIMIT_CTRL2 0xB8
214 #define KSZ8895_PORT1_PRIO2_IG_LIMIT_CTRL3 0xB9
215 #define KSZ8895_PORT1_PRIO3_IG_LIMIT_CTRL4 0xBA
216 #define KSZ8895_PORT1_QUEUE0_EG_LIMIT_CTRL1 0xBB
217 #define KSZ8895_PORT1_QUEUE1_EG_LIMIT_CTRL2 0xBC
218 #define KSZ8895_PORT1_QUEUE2_EG_LIMIT_CTRL3 0xBD
219 #define KSZ8895_PORT1_QUEUE3_EG_LIMIT_CTRL4 0xBE
220 #define KSZ8895_TEST1 0xBF
221 #define KSZ8895_PORT2_CTRL8 0xC0
222 #define KSZ8895_PORT2_CTRL9 0xC1
223 #define KSZ8895_PORT2_CTRL10 0xC2
224 #define KSZ8895_PORT2_CTRL11 0xC3
225 #define KSZ8895_PORT2_CTRL12 0xC4
226 #define KSZ8895_PORT2_CTRL13 0xC5
227 #define KSZ8895_PORT2_RATE_LIMIT_CTRL 0xC6
228 #define KSZ8895_PORT2_PRIO0_IG_LIMIT_CTRL1 0xC7
229 #define KSZ8895_PORT2_PRIO1_IG_LIMIT_CTRL2 0xC8
230 #define KSZ8895_PORT2_PRIO2_IG_LIMIT_CTRL3 0xC9
231 #define KSZ8895_PORT2_PRIO3_IG_LIMIT_CTRL4 0xCA
232 #define KSZ8895_PORT2_QUEUE0_EG_LIMIT_CTRL1 0xCB
233 #define KSZ8895_PORT2_QUEUE1_EG_LIMIT_CTRL2 0xCC
234 #define KSZ8895_PORT2_QUEUE2_EG_LIMIT_CTRL3 0xCD
235 #define KSZ8895_PORT2_QUEUE3_EG_LIMIT_CTRL4 0xCE
236 #define KSZ8895_PORT3_CTRL8 0xD0
237 #define KSZ8895_PORT3_CTRL9 0xD1
238 #define KSZ8895_PORT3_CTRL10 0xD2
239 #define KSZ8895_PORT3_CTRL11 0xD3
240 #define KSZ8895_PORT3_CTRL12 0xD4
241 #define KSZ8895_PORT3_CTRL13 0xD5
242 #define KSZ8895_PORT3_RATE_LIMIT_CTRL 0xD6
243 #define KSZ8895_PORT3_PRIO0_IG_LIMIT_CTRL1 0xD7
244 #define KSZ8895_PORT3_PRIO1_IG_LIMIT_CTRL2 0xD8
245 #define KSZ8895_PORT3_PRIO2_IG_LIMIT_CTRL3 0xD9
246 #define KSZ8895_PORT3_PRIO3_IG_LIMIT_CTRL4 0xDA
247 #define KSZ8895_PORT3_QUEUE0_EG_LIMIT_CTRL1 0xDB
248 #define KSZ8895_PORT3_QUEUE1_EG_LIMIT_CTRL2 0xDC
249 #define KSZ8895_PORT3_QUEUE2_EG_LIMIT_CTRL3 0xDD
250 #define KSZ8895_PORT3_QUEUE3_EG_LIMIT_CTRL4 0xDE
251 #define KSZ8895_TEST2 0xDF
252 #define KSZ8895_PORT4_CTRL8 0xE0
253 #define KSZ8895_PORT4_CTRL9 0xE1
254 #define KSZ8895_PORT4_CTRL10 0xE2
255 #define KSZ8895_PORT4_CTRL11 0xE3
256 #define KSZ8895_PORT4_CTRL12 0xE4
257 #define KSZ8895_PORT4_CTRL13 0xE5
258 #define KSZ8895_PORT4_RATE_LIMIT_CTRL 0xE6
259 #define KSZ8895_PORT4_PRIO0_IG_LIMIT_CTRL1 0xE7
260 #define KSZ8895_PORT4_PRIO1_IG_LIMIT_CTRL2 0xE8
261 #define KSZ8895_PORT4_PRIO2_IG_LIMIT_CTRL3 0xE9
262 #define KSZ8895_PORT4_PRIO3_IG_LIMIT_CTRL4 0xEA
263 #define KSZ8895_PORT4_QUEUE0_EG_LIMIT_CTRL1 0xEB
264 #define KSZ8895_PORT4_QUEUE1_EG_LIMIT_CTRL2 0xEC
265 #define KSZ8895_PORT4_QUEUE2_EG_LIMIT_CTRL3 0xED
266 #define KSZ8895_PORT4_QUEUE3_EG_LIMIT_CTRL4 0xEE
267 #define KSZ8895_PORT3_COPPER_FIBER_CTRL 0xEF
268 #define KSZ8895_PORT5_CTRL8 0xF0
269 #define KSZ8895_PORT5_CTRL9 0xF1
270 #define KSZ8895_PORT5_CTRL10 0xF2
271 #define KSZ8895_PORT5_CTRL11 0xF3
272 #define KSZ8895_PORT5_CTRL12 0xF4
273 #define KSZ8895_PORT5_CTRL13 0xF5
274 #define KSZ8895_PORT5_RATE_LIMIT_CTRL 0xF6
275 #define KSZ8895_PORT5_PRIO0_IG_LIMIT_CTRL1 0xF7
276 #define KSZ8895_PORT5_PRIO1_IG_LIMIT_CTRL2 0xF8
277 #define KSZ8895_PORT5_PRIO2_IG_LIMIT_CTRL3 0xF9
278 #define KSZ8895_PORT5_PRIO3_IG_LIMIT_CTRL4 0xFA
279 #define KSZ8895_PORT5_QUEUE0_EG_LIMIT_CTRL1 0xFB
280 #define KSZ8895_PORT5_QUEUE1_EG_LIMIT_CTRL2 0xFC
281 #define KSZ8895_PORT5_QUEUE2_EG_LIMIT_CTRL3 0xFD
282 #define KSZ8895_PORT5_QUEUE3_EG_LIMIT_CTRL4 0xFE
283 #define KSZ8895_TEST3 0xFF
284 
285 //KSZ8895 Switch register access macros
286 #define KSZ8895_PORTn_CTRL0(port) (0x00 + ((port) * 0x10))
287 #define KSZ8895_PORTn_CTRL1(port) (0x01 + ((port) * 0x10))
288 #define KSZ8895_PORTn_CTRL2(port) (0x02 + ((port) * 0x10))
289 #define KSZ8895_PORTn_CTRL3(port) (0x03 + ((port) * 0x10))
290 #define KSZ8895_PORTn_CTRL4(port) (0x04 + ((port) * 0x10))
291 #define KSZ8895_PORTn_STAT0(port) (0x09 + ((port) * 0x10))
292 #define KSZ8895_PORTn_PSCS(port) (0x0A + ((port) * 0x10))
293 #define KSZ8895_PORTn_LINKMD(port) (0x0B + ((port) * 0x10))
294 #define KSZ8895_PORTn_CTRL5(port) (0x0C + ((port) * 0x10))
295 #define KSZ8895_PORTn_CTRL6(port) (0x0D + ((port) * 0x10))
296 #define KSZ8895_PORTn_STAT1(port) (0x0E + ((port) * 0x10))
297 #define KSZ8895_PORTn_CTRL7_STAT2(port) (0x0F + ((port) * 0x10))
298 #define KSZ8895_PORTn_CTRL8(port) (0xA0 + ((port) * 0x10))
299 #define KSZ8895_PORTn_CTRL9(port) (0xA1 + ((port) * 0x10))
300 #define KSZ8895_PORTn_CTRL10(port) (0xA2 + ((port) * 0x10))
301 #define KSZ8895_PORTn_CTRL11(port) (0xA3 + ((port) * 0x10))
302 #define KSZ8895_PORTn_CTRL12(port) (0xA4 + ((port) * 0x10))
303 #define KSZ8895_PORTn_CTRL13(port) (0xA5 + ((port) * 0x10))
304 #define KSZ8895_PORTn_RATE_LIMIT_CTRL(port) (0xA6 + ((port) * 0x10))
305 #define KSZ8895_PORTn_PRIO0_IG_LIMIT_CTRL1(port) (0xA7 + ((port) * 0x10))
306 #define KSZ8895_PORTn_PRIO1_IG_LIMIT_CTRL2(port) (0xA8 + ((port) * 0x10))
307 #define KSZ8895_PORTn_PRIO2_IG_LIMIT_CTRL3(port) (0xA9 + ((port) * 0x10))
308 #define KSZ8895_PORTn_PRIO3_IG_LIMIT_CTRL4(port) (0xAA + ((port) * 0x10))
309 #define KSZ8895_PORTn_QUEUE0_EG_LIMIT_CTRL1(port) (0xAB + ((port) * 0x10))
310 #define KSZ8895_PORTn_QUEUE1_EG_LIMIT_CTRL2(port) (0xAC + ((port) * 0x10))
311 #define KSZ8895_PORTn_QUEUE2_EG_LIMIT_CTRL3(port) (0xAD + ((port) * 0x10))
312 #define KSZ8895_PORTn_QUEUE3_EG_LIMIT_CTRL4(port) (0xAE + ((port) * 0x10))
313 
314 //MII Control register
315 #define KSZ8895_BMCR_RESET 0x8000
316 #define KSZ8895_BMCR_LOOPBACK 0x4000
317 #define KSZ8895_BMCR_FORCE_100 0x2000
318 #define KSZ8895_BMCR_AN_EN 0x1000
319 #define KSZ8895_BMCR_POWER_DOWN 0x0800
320 #define KSZ8895_BMCR_ISOLATE 0x0400
321 #define KSZ8895_BMCR_RESTART_AN 0x0200
322 #define KSZ8895_BMCR_FORCE_FULL_DUPLEX 0x0100
323 #define KSZ8895_BMCR_COL_TEST 0x0080
324 #define KSZ8895_BMCR_HP_MDIX 0x0020
325 #define KSZ8895_BMCR_FORCE_MDI 0x0010
326 #define KSZ8895_BMCR_AUTO_MDIX_DIS 0x0008
327 #define KSZ8895_BMCR_FAR_END_FAULT_DIS 0x0004
328 #define KSZ8895_BMCR_TRANSMIT_DIS 0x0002
329 #define KSZ8895_BMCR_LED_DIS 0x0001
330 
331 //MII Status register
332 #define KSZ8895_BMSR_100BT4 0x8000
333 #define KSZ8895_BMSR_100BTX_FD 0x4000
334 #define KSZ8895_BMSR_100BTX_HD 0x2000
335 #define KSZ8895_BMSR_10BT_FD 0x1000
336 #define KSZ8895_BMSR_10BT_HD 0x0800
337 #define KSZ8895_BMSR_PREAMBLE_SUPPR 0x0040
338 #define KSZ8895_BMSR_AN_COMPLETE 0x0020
339 #define KSZ8895_BMSR_FAR_END_FAULT 0x0010
340 #define KSZ8895_BMSR_AN_CAPABLE 0x0008
341 #define KSZ8895_BMSR_LINK_STATUS 0x0004
342 #define KSZ8895_BMSR_JABBER_TEST 0x0002
343 #define KSZ8895_BMSR_EXTENDED_CAPABLE 0x0001
344 
345 //PHYID High register
346 #define KSZ8895_PHYID1_DEFAULT 0x0022
347 
348 //PHYID Low register
349 #define KSZ8895_PHYID2_DEFAULT 0x1450
350 
351 //Advertisement Ability register
352 #define KSZ8895_ANAR_NEXT_PAGE 0x8000
353 #define KSZ8895_ANAR_REMOTE_FAULT 0x2000
354 #define KSZ8895_ANAR_PAUSE 0x0400
355 #define KSZ8895_ANAR_100BTX_FD 0x0100
356 #define KSZ8895_ANAR_100BTX_HD 0x0080
357 #define KSZ8895_ANAR_10BT_FD 0x0040
358 #define KSZ8895_ANAR_10BT_HD 0x0020
359 #define KSZ8895_ANAR_SELECTOR 0x001F
360 #define KSZ8895_ANAR_SELECTOR_DEFAULT 0x0001
361 
362 //Link Partner Ability register
363 #define KSZ8895_ANLPAR_NEXT_PAGE 0x8000
364 #define KSZ8895_ANLPAR_LP_ACK 0x4000
365 #define KSZ8895_ANLPAR_REMOTE_FAULT 0x2000
366 #define KSZ8895_ANLPAR_PAUSE 0x0400
367 #define KSZ8895_ANLPAR_100BTX_FD 0x0100
368 #define KSZ8895_ANLPAR_100BTX_HD 0x0080
369 #define KSZ8895_ANLPAR_10BT_FD 0x0040
370 #define KSZ8895_ANLPAR_10BT_HD 0x0020
371 
372 //LinkMD Control/Status register
373 #define KSZ8895_LINKMD_TEST_EN 0x8000
374 #define KSZ8895_LINKMD_RESULT 0x6000
375 #define KSZ8895_LINKMD_SHORT 0x1000
376 #define KSZ8895_LINKMD_FAULT_COUNT 0x01FF
377 
378 //PHY Special Control/Status register
379 #define KSZ8895_PHYSCS_OP_MODE 0x0700
380 #define KSZ8895_PHYSCS_OP_MODE_AN 0x0100
381 #define KSZ8895_PHYSCS_OP_MODE_10BT_HD 0x0200
382 #define KSZ8895_PHYSCS_OP_MODE_100BTX_HD 0x0300
383 #define KSZ8895_PHYSCS_OP_MODE_10BT_FD 0x0500
384 #define KSZ8895_PHYSCS_OP_MODE_100BTX_FD 0x0600
385 #define KSZ8895_PHYSCS_OP_MODE_ISOLATE 0x0700
386 #define KSZ8895_PHYSCS_POLRVS 0x0020
387 #define KSZ8895_PHYSCS_MDIX_STATUS 0x0010
388 #define KSZ8895_PHYSCS_FORCE_LINK 0x0008
389 #define KSZ8895_PHYSCS_PWRSAVE 0x0004
390 #define KSZ8895_PHYSCS_REMOTE_LOOPBACK 0x0002
391 
392 //Chip ID0 register
393 #define KSZ8895_CHIP_ID0_FAMILY_ID 0xFF
394 #define KSZ8895_CHIP_ID0_FAMILY_ID_DEFAULT 0x95
395 
396 //Chip ID1 / Start Switch register
397 #define KSZ8895_CHIP_ID1_CHIP_ID 0xF0
398 #define KSZ8895_CHIP_ID1_CHIP_ID_MQX_FQX_MLX 0x40
399 #define KSZ8895_CHIP_ID1_CHIP_ID_RQX 0x60
400 #define KSZ8895_CHIP_ID1_REVISION_ID 0x0E
401 #define KSZ8895_CHIP_ID1_START_SWITCH 0x01
402 
403 //Global Control 0 register
404 #define KSZ8895_GLOBAL_CTRL0_NEW_BACK_OFF_EN 0x80
405 #define KSZ8895_GLOBAL_CTRL0_FLUSH_DYNAMIC_MAC_TABLE 0x20
406 #define KSZ8895_GLOBAL_CTRL0_FLUSH_STATIC_MAC_TABLE 0x10
407 #define KSZ8895_GLOBAL_CTRL0_PHY_MII_RMII_EN 0x08
408 #define KSZ8895_GLOBAL_CTRL0_UNH_MODE 0x02
409 #define KSZ8895_GLOBAL_CTRL0_LINK_CHANGE_AGE 0x01
410 
411 //Global Control 1 register
412 #define KSZ8895_GLOBAL_CTRL1_PASS_ALL_FRAMES 0x80
413 #define KSZ8895_GLOBAL_CTRL1_2KB_PKT_SUPPORT 0x40
414 #define KSZ8895_GLOBAL_CTRL1_TX_FLOW_CTRL_DIS 0x20
415 #define KSZ8895_GLOBAL_CTRL1_RX_FLOW_CTRL_DIS 0x10
416 #define KSZ8895_GLOBAL_CTRL1_FRAME_LEN_CHECK_EN 0x08
417 #define KSZ8895_GLOBAL_CTRL1_AGING_EN 0x04
418 #define KSZ8895_GLOBAL_CTRL1_FAST_AGE_EN 0x02
419 #define KSZ8895_GLOBAL_CTRL1_AGGRESSIVE_BACK_OFF_EN 0x01
420 
421 //Global Control 2 register
422 #define KSZ8895_GLOBAL_CTRL2_UNI_VLAN_MISMATCH_DISCARD 0x80
423 #define KSZ8895_GLOBAL_CTRL2_MCAST_STORM_PROTECT_DIS 0x40
424 #define KSZ8895_GLOBAL_CTRL2_BACK_PRESSURE_MODE 0x20
425 #define KSZ8895_GLOBAL_CTRL2_FLOW_CTRL_FAIR_MODE 0x10
426 #define KSZ8895_GLOBAL_CTRL2_NO_EXCESSIVE_COL_DROP 0x08
427 #define KSZ8895_GLOBAL_CTRL2_HUGE_PKT_SUPPORT 0x04
428 #define KSZ8895_GLOBAL_CTRL2_MAX_PKT_SIZE_CHECK_DIS 0x02
429 
430 //Global Control 3 register
431 #define KSZ8895_GLOBAL_CTRL3_VLAN_EN 0x80
432 #define KSZ8895_GLOBAL_CTRL3_SW5_IGMP_SNOOP_EN 0x40
433 #define KSZ8895_GLOBAL_CTRL3_SW5_DIRECT_MODE_EN 0x20
434 #define KSZ8895_GLOBAL_CTRL3_SW5_PRE_TAG_EN 0x10
435 #define KSZ8895_GLOBAL_CTRL3_TAG_MASK_EN 0x02
436 #define KSZ8895_GLOBAL_CTRL3_SNIFF_MODE_SEL 0x01
437 
438 //Global Control 4 register
439 #define KSZ8895_GLOBAL_CTRL4_SW5_BACK_PRESSURE_EN 0x80
440 #define KSZ8895_GLOBAL_CTRL4_SW5_HALF_DUPLEX_MODE 0x40
441 #define KSZ8895_GLOBAL_CTRL4_SW5_FLOW_CTRL_EN 0x20
442 #define KSZ8895_GLOBAL_CTRL4_SW5_SPEED 0x10
443 #define KSZ8895_GLOBAL_CTRL4_NULL_VID_REPLACEMENT 0x08
444 #define KSZ8895_GLOBAL_CTRL4_BCAST_STORM_PROTECT_RATE_MSB 0x07
445 
446 //Global Control 5 register
447 #define KSZ8895_GLOBAL_CTRL5_BCAST_STORM_PROTECT_RATE_LSB 0xFF
448 
449 //Global Control 6 register
450 #define KSZ8895_GLOBAL_CTRL6_FACTORY_TESTING 0xFF
451 
452 //Global Control 7 register
453 #define KSZ8895_GLOBAL_CTRL7_FACTORY_TESTING 0xFF
454 
455 //Global Control 8 register
456 #define KSZ8895_GLOBAL_CTRL8_FACTORY_TESTING 0xFF
457 
458 //Global Control 9 register
459 #define KSZ8895_GLOBAL_CTRL9_SW5_REFCLK_EDGE_SEL 0x40
460 #define KSZ8895_GLOBAL_CTRL9_SW5_REFCLK_EDGE_SEL_RISING 0x00
461 #define KSZ8895_GLOBAL_CTRL9_SW5_REFCLK_EDGE_SEL_FALLING 0x40
462 #define KSZ8895_GLOBAL_CTRL9_PHY_PWR_SAVE 0x08
463 #define KSZ8895_GLOBAL_CTRL9_LED_MODE 0x02
464 #define KSZ8895_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL 0x01
465 #define KSZ8895_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL_FALLING 0x00
466 #define KSZ8895_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL_RISING 0x01
467 
468 //Global Control 10 register
469 #define KSZ8895_GLOBAL_CTRL10_CLK_MODE 0x40
470 #define KSZ8895_GLOBAL_CTRL10_CPU_CLK_SEL 0x30
471 #define KSZ8895_GLOBAL_CTRL10_RESTORE_PREAMBLE_EN 0x04
472 #define KSZ8895_GLOBAL_CTRL10_TAIL_TAG_EN 0x02
473 #define KSZ8895_GLOBAL_CTRL10_PASS_FLOW_CTRL_PKT 0x01
474 
475 //Global Control 11 register
476 #define KSZ8895_GLOBAL_CTRL11_FACTORY_TESTING 0xFF
477 
478 //Power-Down Management Control 1 register
479 #define KSZ8895_PD_MGMT_CTRL1_PLL_PWR_DOWN 0x20
480 #define KSZ8895_PD_MGMT_CTRL1_PWR_MGMT_MODE 0x18
481 #define KSZ8895_PD_MGMT_CTRL1_PWR_MGMT_MODE_NORMAL 0x00
482 #define KSZ8895_PD_MGMT_CTRL1_PWR_MGMT_MODE_ENERGY_DETECT 0x08
483 #define KSZ8895_PD_MGMT_CTRL1_PWR_MGMT_MODE_SOFT_PWR_DOWN 0x10
484 #define KSZ8895_PD_MGMT_CTRL1_PWR_MGMT_MODE_PWR_SAVING 0x18
485 
486 //Power-Down Management Control 2 register
487 #define KSZ8895_PD_MGMT_CTRL2_GO_SLEEP_TIME 0xFF
488 
489 //Port N Control 0 register
490 #define KSZ8895_PORTn_CTRL0_BCAST_STORM_PROTECT_EN 0x80
491 #define KSZ8895_PORTn_CTRL0_DIFFSERV_PRIO_CLASS_EN 0x40
492 #define KSZ8895_PORTn_CTRL0_802_1P_PRIO_CLASS_EN 0x20
493 #define KSZ8895_PORTn_CTRL0_PORT_PRIO_CLASS_EN 0x18
494 #define KSZ8895_PORTn_CTRL0_TAG_INSERTION 0x04
495 #define KSZ8895_PORTn_CTRL0_TAG_REMOVAL 0x02
496 #define KSZ8895_PORTn_CTRL0_TWO_QUEUE_SPLIT_EN 0x01
497 
498 //Port N Control 1 register
499 #define KSZ8895_PORTn_CTRL1_SNIFFER_PORT 0x80
500 #define KSZ8895_PORTn_CTRL1_RECEIVE_SNIFF 0x40
501 #define KSZ8895_PORTn_CTRL1_TRANSMIT_SNIFF 0x20
502 #define KSZ8895_PORTn_CTRL1_PORT_VLAN_MEMBERSHIP 0x1F
503 
504 //Port N Control 2 register
505 #define KSZ8895_PORTn_CTRL2_USER_PRIO_CEILING 0x80
506 #define KSZ8895_PORTn_CTRL2_INGRESS_VLAN_FILT 0x40
507 #define KSZ8895_PORTn_CTRL2_DISCARD_NON_PVID_PKT 0x20
508 #define KSZ8895_PORTn_CTRL2_FORCE_FLOW_CTRL 0x10
509 #define KSZ8895_PORTn_CTRL2_BACK_PRESSURE_EN 0x08
510 #define KSZ8895_PORTn_CTRL2_TRANSMIT_EN 0x04
511 #define KSZ8895_PORTn_CTRL2_RECEIVE_EN 0x02
512 #define KSZ8895_PORTn_CTRL2_LEARNING_DIS 0x01
513 
514 //Port N Control 3 register
515 #define KSZ8895_PORTn_CTRL3_DEFAULT_USER_PRIO 0xE0
516 #define KSZ8895_PORTn_CTRL3_DEFAULT_CFI 0x10
517 #define KSZ8895_PORTn_CTRL3_DEFAULT_VID_MSB 0x0F
518 
519 //Port N Control 4 register
520 #define KSZ8895_PORTn_CTRL4_DEFAULT_VID_LSB 0xFF
521 
522 //RMII Management Control register
523 #define KSZ8895_RMII_MGMT_CTRL_SW5_CLK_OUT_DIS 0x08
524 #define KSZ8895_RMII_MGMT_CTRL_P5_CLK_OUT_DIS 0x04
525 
526 //Port N Status 0 register
527 #define KSZ8895_PORTn_STAT0_HP_MDIX 0x80
528 #define KSZ8895_PORTn_STAT0_POLRVS 0x20
529 #define KSZ8895_PORTn_STAT0_TX_FLOW_CTRL_EN 0x10
530 #define KSZ8895_PORTn_STAT0_RX_FLOW_CTRL_EN 0x08
531 #define KSZ8895_PORTn_STAT0_OP_SPEED 0x04
532 #define KSZ8895_PORTn_STAT0_OP_DUPLEX 0x02
533 
534 //Port N PHY Special Control/Status register
535 #define KSZ8895_PORTn_PSCS_VCT_10M_SHORT 0x80
536 #define KSZ8895_PORTn_PSCS_VCT_RESULT 0x60
537 #define KSZ8895_PORTn_PSCS_VCT_EN 0x10
538 #define KSZ8895_PORTn_PSCS_FORCE_LNK 0x08
539 #define KSZ8895_PORTn_PSCS_PWRSAVE 0x04
540 #define KSZ8895_PORTn_PSCS_REMOTE_LOOPBACK 0x02
541 #define KSZ8895_PORTn_PSCS_VCT_FAULT_COUNT_MSB 0x01
542 
543 //Port N LinkMD Result register
544 #define KSZ8895_PORTn_LINKMD_VCT_FAULT_COUNT_LSB 0xFF
545 
546 //Port N Control 5 register
547 #define KSZ8895_PORTn_CTRL5_AN_DIS 0x80
548 #define KSZ8895_PORTn_CTRL5_FORCED_SPEED 0x40
549 #define KSZ8895_PORTn_CTRL5_FORCED_DUPLEX 0x20
550 #define KSZ8895_PORTn_CTRL5_ADV_FLOW_CTRL 0x10
551 #define KSZ8895_PORTn_CTRL5_ADV_100BT_FD 0x08
552 #define KSZ8895_PORTn_CTRL5_ADV_100BT_HD 0x04
553 #define KSZ8895_PORTn_CTRL5_ADV_10BT_FD 0x02
554 #define KSZ8895_PORTn_CTRL5_ADV_10BT_HD 0x01
555 
556 //Port N Control 6 register
557 #define KSZ8895_PORTn_CTRL6_LED_OFF 0x80
558 #define KSZ8895_PORTn_CTRL6_TX_DIS 0x40
559 #define KSZ8895_PORTn_CTRL6_RESTART_AN 0x20
560 #define KSZ8895_PORTn_CTRL6_FAR_END_FAULT_DIS 0x10
561 #define KSZ8895_PORTn_CTRL6_POWER_DOWN 0x08
562 #define KSZ8895_PORTn_CTRL6_AUTO_MDIX_DIS 0x04
563 #define KSZ8895_PORTn_CTRL6_FORCED_MDI 0x02
564 #define KSZ8895_PORTn_CTRL6_MAC_LOOPBACK 0x01
565 
566 //Port N Status 1 register
567 #define KSZ8895_PORTn_STAT1_MDIX_STATUS 0x80
568 #define KSZ8895_PORTn_STAT1_AN_DONE 0x40
569 #define KSZ8895_PORTn_STAT1_LINK_GOOD 0x20
570 #define KSZ8895_PORTn_STAT1_LP_FLOW_CTRL_CAPABLE 0x10
571 #define KSZ8895_PORTn_STAT1_LP_100BTX_FD_CAPABLE 0x08
572 #define KSZ8895_PORTn_STAT1_LP_100BTX_HF_CAPABLE 0x04
573 #define KSZ8895_PORTn_STAT1_LP_10BT_FD_CAPABLE 0x02
574 #define KSZ8895_PORTn_STAT1_LP_10BT_HD_CAPABLE 0x01
575 
576 //Port N Control 7 / Status 2 register
577 #define KSZ8895_PORTn_CTRL7_STAT2_PHY_LOOPBACK 0x80
578 #define KSZ8895_PORTn_CTRL7_STAT2_PHY_ISOLATE 0x20
579 #define KSZ8895_PORTn_CTRL7_STAT2_SOFT_RESET 0x10
580 #define KSZ8895_PORTn_CTRL7_STAT2_FORCE_LINK 0x08
581 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE 0x07
582 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE_AN 0x01
583 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE_10BT_HD 0x02
584 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE_100BTX_HD 0x03
585 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE_10BT_FD 0x05
586 #define KSZ8895_PORTn_CTRL7_STAT2_OP_MODE_100BTX_FD 0x06
587 
588 //Indirect Access Control 0 register
589 #define KSZ8895_INDIRECT_CTRL0_WRITE 0x00
590 #define KSZ8895_INDIRECT_CTRL0_READ 0x10
591 #define KSZ8895_INDIRECT_CTRL0_TABLE_SEL 0x0C
592 #define KSZ8895_INDIRECT_CTRL0_TABLE_SEL_STATIC_MAC 0x00
593 #define KSZ8895_INDIRECT_CTRL0_TABLE_SEL_VLAN 0x04
594 #define KSZ8895_INDIRECT_CTRL0_TABLE_SEL_DYNAMIC_MAC 0x08
595 #define KSZ8895_INDIRECT_CTRL0_TABLE_SEL_MIB_COUNTER 0x0C
596 #define KSZ8895_INDIRECT_CTRL0_ADDR_H 0x03
597 
598 //Indirect Access Control 1 register
599 #define KSZ8895_INDIRECT_CTRL1_ADDR_L 0xFF
600 
601 //Interrupt Status register
602 #define KSZ8895_INT_STAT_PORT5 0x10
603 #define KSZ8895_INT_STAT_PORT4 0x08
604 #define KSZ8895_INT_STAT_PORT3 0x04
605 #define KSZ8895_INT_STAT_PORT2 0x02
606 #define KSZ8895_INT_STAT_PORT1 0x01
607 
608 //Interrupt Mask register
609 #define KSZ8895_INT_MASK_PORT5 0x10
610 #define KSZ8895_INT_MASK_PORT4 0x08
611 #define KSZ8895_INT_MASK_PORT3 0x04
612 #define KSZ8895_INT_MASK_PORT2 0x02
613 #define KSZ8895_INT_MASK_PORT1 0x01
614 
615 //Global Control 12 register
616 #define KSZ8895_GLOBAL_CTRL12_TAG3 0xC0
617 #define KSZ8895_GLOBAL_CTRL12_TAG2 0x30
618 #define KSZ8895_GLOBAL_CTRL12_TAG1 0x0C
619 #define KSZ8895_GLOBAL_CTRL12_TAG0 0x03
620 
621 //Global Control 13 register
622 #define KSZ8895_GLOBAL_CTRL13_TAG7 0xC0
623 #define KSZ8895_GLOBAL_CTRL13_TAG6 0x30
624 #define KSZ8895_GLOBAL_CTRL13_TAG5 0x0C
625 #define KSZ8895_GLOBAL_CTRL13_TAG4 0x03
626 
627 //Global Control 14 register
628 #define KSZ8895_GLOBAL_CTRL14_PRI_2Q 0xC0
629 
630 //Global Control 15 register
631 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD 0x20
632 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP 0x1F
633 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_FILT 0x00
634 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT1 0x01
635 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT2 0x02
636 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT3 0x04
637 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT4 0x08
638 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT5 0x10
639 #define KSZ8895_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_ALL 0x1F
640 
641 //Global Control 16 register
642 #define KSZ8895_GLOBAL_CTRL16_CHIP_OUT_DRIVE_STRENGTH 0xC0
643 #define KSZ8895_GLOBAL_CTRL16_CHIP_OUT_DRIVE_STRENGTH_4MA 0x00
644 #define KSZ8895_GLOBAL_CTRL16_CHIP_OUT_DRIVE_STRENGTH_8MA 0x40
645 #define KSZ8895_GLOBAL_CTRL16_CHIP_OUT_DRIVE_STRENGTH_10MA 0x80
646 #define KSZ8895_GLOBAL_CTRL16_CHIP_OUT_DRIVE_STRENGTH_14MA 0xC0
647 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD 0x20
648 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP 0x1F
649 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_FILT 0x00
650 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT1 0x01
651 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT2 0x02
652 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT3 0x04
653 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT4 0x08
654 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT5 0x10
655 #define KSZ8895_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_ALL 0x1F
656 
657 //Global Control 17 register
658 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD 0x20
659 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP 0x1F
660 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_FILT 0x00
661 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT1 0x01
662 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT2 0x02
663 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT3 0x04
664 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT4 0x08
665 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT5 0x10
666 #define KSZ8895_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_ALL 0x1F
667 
668 //Global Control 18 register
669 #define KSZ8895_GLOBAL_CTRL18_SELF_ADDR_FILTER_EN 0x40
670 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD 0x20
671 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP 0x1F
672 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_FILT 0x00
673 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT1 0x01
674 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT2 0x02
675 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT3 0x04
676 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT4 0x08
677 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT5 0x10
678 #define KSZ8895_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_ALL 0x1F
679 
680 //Global Control 19 register
681 #define KSZ8895_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD 0x30
682 #define KSZ8895_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_16MS 0x00
683 #define KSZ8895_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_64MS 0x10
684 #define KSZ8895_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_256MS 0x20
685 #define KSZ8895_GLOBAL_CTRL19_QUEUE_BASED_EG_RATE_LIMITE_EN 0x08
686 #define KSZ8895_GLOBAL_CTRL19_INSERT_SRC_PORT_PVID_TAG_EN 0x04
687 
688 //Identification register
689 #define KSZ8895_ID_REVISION_ID 0xF0
690 #define KSZ8895_ID_REVISION_ID_MQX_RQX_FQX_REV_A2 0x40
691 #define KSZ8895_ID_REVISION_ID_ML_REV_B2 0x40
692 #define KSZ8895_ID_REVISION_ID_MQX_RQX_FQX_REV_A3 0x50
693 #define KSZ8895_ID_REVISION_ID_ML_REV_B3 0x50
694 #define KSZ8895_ID_REVISION_ID_MQX_RQX_FQX_REV_A4 0x60
695 
696 //Port N Control 9 register
697 #define KSZ8895_PORTn_CTRL9_FOUR_QUEUE_SPLIT_EN 0x02
698 #define KSZ8895_PORTn_CTRL9_DROPPING_TAG_EN 0x01
699 
700 //Port N Control 10 register
701 #define KSZ8895_PORTn_CTRL10_PORT_TX_QUEUE3_RATIO_EN 0x80
702 #define KSZ8895_PORTn_CTRL10_PORT_TX_QUEUE3_RATIO 0x7F
703 
704 //Port N Control 11 register
705 #define KSZ8895_PORTn_CTRL11_PORT_TX_QUEUE2_RATIO_EN 0x80
706 #define KSZ8895_PORTn_CTRL11_PORT_TX_QUEUE2_RATIO 0x7F
707 
708 //Port N Control 12 register
709 #define KSZ8895_PORTn_CTRL12_PORT_TX_QUEUE1_RATIO_EN 0x80
710 #define KSZ8895_PORTn_CTRL12_PORT_TX_QUEUE1_RATIO 0x7F
711 
712 //Port N Control 13 register
713 #define KSZ8895_PORTn_CTRL13_PORT_TX_QUEUE0_RATIO_EN 0x80
714 #define KSZ8895_PORTn_CTRL13_PORT_TX_QUEUE0_RATIO 0x7F
715 
716 //Port N Rate Limit Control register
717 #define KSZ8895_PORTn_RATE_LIMIT_CTRL_LIMIT_EN 0x10
718 #define KSZ8895_PORTn_RATE_LIMIT_CTRL_LIMIT_MODE 0x0C
719 #define KSZ8895_PORTn_RATE_LIMIT_CTRL_COUNT_IFG 0x02
720 #define KSZ8895_PORTn_RATE_LIMIT_CTRL_COUNT_PRE 0x01
721 
722 //Port 3 Copper or Fiber Control register
723 #define KSZ8895_PORT3_COPPER_FIBER_CTRL_FIBER_SEL 0x80
724 
725 //Testing 3 register
726 #define KSZ8895_TEST3_SW5_RMII_INV_SMTXC 0x40
727 #define KSZ8895_TEST3_SW5_RMII_INV_SMRXC 0x10
728 
729 //C++ guard
730 #ifdef __cplusplus
731 extern "C" {
732 #endif
733 
734 //CC-RX, CodeWarrior or Win32 compiler?
735 #if defined(__CCRX__)
736  #pragma pack
737 #elif defined(__CWCC__) || defined(_WIN32)
738  #pragma pack(push, 1)
739 #endif
740 
741 
742 /**
743  * @brief Static MAC table entry (read operation)
744  **/
745 
746 typedef struct
747 {
748 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
749  uint8_t fid : 7; //0
750  uint8_t useFid : 1;
751  uint8_t reserved : 1; //1
752  uint8_t override : 1;
753  uint8_t valid : 1;
754  uint8_t forwardPorts : 5;
755 #else
756  uint8_t useFid : 1; //0
757  uint8_t fid : 7;
758  uint8_t forwardPorts : 5; //1
759  uint8_t valid : 1;
760  uint8_t override : 1;
761  uint8_t reserved : 1;
762 #endif
765 
766 
767 /**
768  * @brief Static MAC table entry (write operation)
769  **/
770 
771 typedef struct
772 {
773  uint8_t fid; //0
774 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
775  uint8_t useFid : 1; //1
776  uint8_t override : 1;
777  uint8_t valid : 1;
778  uint8_t forwardPorts : 5;
779 #else
780  uint8_t forwardPorts : 5; //1
781  uint8_t valid : 1;
782  uint8_t override : 1;
783  uint8_t useFid : 1;
784 #endif
787 
788 
789 /**
790  * @brief Dynamic MAC table entry
791  **/
792 
793 typedef struct
794 {
795 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
796  uint8_t macEmpty : 1; //0
797  uint8_t numValidEntriesH : 7;
798  uint8_t numValidEntriesL : 3; //1
799  uint8_t timestamp : 2;
800  uint8_t sourcePort : 3;
801  uint8_t dataNotReady : 1; //2
802  uint8_t fid : 7;
803 #else
804  uint8_t numValidEntriesH : 7; //0
805  uint8_t macEmpty : 1;
806  uint8_t sourcePort : 3; //1
807  uint8_t timestamp : 2;
808  uint8_t numValidEntriesL : 3;
809  uint8_t fid : 7; //2
810  uint8_t dataNotReady : 1;
811 #endif
814 
815 
816 //CC-RX, CodeWarrior or Win32 compiler?
817 #if defined(__CCRX__)
818  #pragma unpack
819 #elif defined(__CWCC__) || defined(_WIN32)
820  #pragma pack(pop)
821 #endif
822 
823 //KSZ8895 Ethernet switch driver
824 extern const SwitchDriver ksz8895SwitchDriver;
825 
826 //KSZ8895 related functions
827 error_t ksz8895Init(NetInterface *interface);
828 void ksz8895InitHook(NetInterface *interface);
829 
830 void ksz8895Tick(NetInterface *interface);
831 
832 void ksz8895EnableIrq(NetInterface *interface);
833 void ksz8895DisableIrq(NetInterface *interface);
834 
835 void ksz8895EventHandler(NetInterface *interface);
836 
837 error_t ksz8895TagFrame(NetInterface *interface, NetBuffer *buffer,
838  size_t *offset, NetTxAncillary *ancillary);
839 
840 error_t ksz8895UntagFrame(NetInterface *interface, uint8_t **frame,
841  size_t *length, NetRxAncillary *ancillary);
842 
843 bool_t ksz8895GetLinkState(NetInterface *interface, uint8_t port);
844 uint32_t ksz8895GetLinkSpeed(NetInterface *interface, uint8_t port);
846 
847 void ksz8895SetPortState(NetInterface *interface, uint8_t port,
848  SwitchPortState state);
849 
851 
852 void ksz8895SetAgingTime(NetInterface *interface, uint32_t agingTime);
853 
854 void ksz8895EnableIgmpSnooping(NetInterface *interface, bool_t enable);
855 void ksz8895EnableMldSnooping(NetInterface *interface, bool_t enable);
856 void ksz8895EnableRsvdMcastTable(NetInterface *interface, bool_t enable);
857 
859  const SwitchFdbEntry *entry);
860 
862  const SwitchFdbEntry *entry);
863 
865  SwitchFdbEntry *entry);
866 
868 
870  SwitchFdbEntry *entry);
871 
872 void ksz8895FlushDynamicFdbTable(NetInterface *interface, uint8_t port);
873 
875  bool_t enable, uint32_t forwardPorts);
876 
877 void ksz8895WritePhyReg(NetInterface *interface, uint8_t port,
878  uint8_t address, uint16_t data);
879 
880 uint16_t ksz8895ReadPhyReg(NetInterface *interface, uint8_t port,
881  uint8_t address);
882 
883 void ksz8895DumpPhyReg(NetInterface *interface, uint8_t port);
884 
885 void ksz8895WriteSwitchReg(NetInterface *interface, uint8_t address,
886  uint8_t data);
887 
888 uint8_t ksz8895ReadSwitchReg(NetInterface *interface, uint8_t address);
889 
890 void ksz8895DumpSwitchReg(NetInterface *interface);
891 
892 //C++ guard
893 #ifdef __cplusplus
894 }
895 #endif
896 
897 #endif
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
uint16_t port
Definition: dns_common.h:267
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
MacAddr
Definition: ethernet.h:195
uint8_t reserved
Definition: ipv4.h:312
Ipv6Addr address[]
Definition: ipv6.h:316
void ksz8895FlushStaticFdbTable(NetInterface *interface)
Flush static MAC table.
void ksz8895DumpSwitchReg(NetInterface *interface)
Dump switch registers for debugging purpose.
void ksz8895EventHandler(NetInterface *interface)
KSZ8895 event handler.
void ksz8895SetUnknownMcastFwdPorts(NetInterface *interface, bool_t enable, uint32_t forwardPorts)
Set forward ports for unknown multicast packets.
void ksz8895EnableRsvdMcastTable(NetInterface *interface, bool_t enable)
Enable reserved multicast table.
void ksz8895EnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t ksz8895ReadPhyReg(NetInterface *interface, uint8_t port, uint8_t address)
Read PHY register.
const SwitchDriver ksz8895SwitchDriver
KSZ8895 Ethernet switch driver.
void ksz8895EnableIgmpSnooping(NetInterface *interface, bool_t enable)
Enable IGMP snooping.
void ksz8895InitHook(NetInterface *interface)
KSZ8895 custom configuration.
error_t ksz8895AddStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Add a new entry to the static MAC table.
uint32_t ksz8895GetLinkSpeed(NetInterface *interface, uint8_t port)
Get link speed.
void ksz8895FlushDynamicFdbTable(NetInterface *interface, uint8_t port)
Flush dynamic MAC table.
uint8_t ksz8895ReadSwitchReg(NetInterface *interface, uint8_t address)
Read switch register.
void ksz8895DisableIrq(NetInterface *interface)
Disable interrupts.
void ksz8895WritePhyReg(NetInterface *interface, uint8_t port, uint8_t address, uint16_t data)
Write PHY register.
SwitchPortState ksz8895GetPortState(NetInterface *interface, uint8_t port)
Get port state.
error_t ksz8895UntagFrame(NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
Decode tail tag from incoming Ethernet frame.
error_t ksz8895DeleteStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Remove an entry from the static MAC table.
error_t ksz8895TagFrame(NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
Add tail tag to Ethernet frame.
bool_t ksz8895GetLinkState(NetInterface *interface, uint8_t port)
Get link state.
void ksz8895WriteSwitchReg(NetInterface *interface, uint8_t address, uint8_t data)
Write switch register.
error_t ksz8895GetStaticFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the static MAC table.
void ksz8895SetAgingTime(NetInterface *interface, uint32_t agingTime)
Set aging time for dynamic filtering entries.
error_t ksz8895GetDynamicFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the dynamic MAC table.
void ksz8895DumpPhyReg(NetInterface *interface, uint8_t port)
Dump PHY registers for debugging purpose.
void ksz8895Tick(NetInterface *interface)
KSZ8895 timer handler.
NicDuplexMode ksz8895GetDuplexMode(NetInterface *interface, uint8_t port)
Get duplex mode.
void ksz8895EnableMldSnooping(NetInterface *interface, bool_t enable)
Enable MLD snooping.
void ksz8895SetPortState(NetInterface *interface, uint8_t port, SwitchPortState state)
Set port state.
error_t ksz8895Init(NetInterface *interface)
KSZ8895 Ethernet switch initialization.
#define NetInterface
Definition: net.h:36
#define NetRxAncillary
Definition: net_misc.h:40
#define NetTxAncillary
Definition: net_misc.h:36
Network interface controller abstraction layer.
NicDuplexMode
Duplex mode.
Definition: nic.h:122
SwitchPortState
Switch port state.
Definition: nic.h:134
Dynamic MAC table entry.
uint8_t numValidEntriesH
uint8_t sourcePort
MacAddr macAddr
uint8_t fid
uint8_t macEmpty
uint8_t numValidEntriesL
uint8_t timestamp
uint8_t dataNotReady
Static MAC table entry (read operation)
uint8_t forwardPorts
MacAddr macAddr
uint8_t valid
uint8_t useFid
uint8_t override
uint8_t fid
uint8_t reserved
Static MAC table entry (write operation)
uint8_t forwardPorts
MacAddr macAddr
uint8_t valid
uint8_t useFid
uint8_t override
uint8_t fid
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
Ethernet switch driver.
Definition: nic.h:322
Forwarding database entry.
Definition: nic.h:149
uint8_t length
Definition: tcp.h:368