ksz8794_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8794_driver.h
3  * @brief KSZ8794 4-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 _KSZ8794_DRIVER_H
32 #define _KSZ8794_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Port identifiers
38 #define KSZ8794_PORT1 1
39 #define KSZ8794_PORT2 2
40 #define KSZ8794_PORT3 3
41 #define KSZ8794_PORT_RESERVED 4
42 #define KSZ8794_PORT4 5
43 
44 //Port masks
45 #define KSZ8794_PORT_MASK 0x17
46 #define KSZ8794_PORT1_MASK 0x01
47 #define KSZ8794_PORT2_MASK 0x02
48 #define KSZ8794_PORT3_MASK 0x04
49 #define KSZ8794_PORT4_MASK 0x10
50 
51 //SPI command byte
52 #define KSZ8794_SPI_CMD_WRITE 0x4000
53 #define KSZ8794_SPI_CMD_READ 0x6000
54 #define KSZ8794_SPI_CMD_ADDR 0x1FFE
55 
56 //Size of static and dynamic MAC tables
57 #define KSZ8794_STATIC_MAC_TABLE_SIZE 32
58 #define KSZ8794_DYNAMIC_MAC_TABLE_SIZE 1024
59 
60 //Tail tag rules (host to KSZ8794)
61 #define KSZ8794_TAIL_TAG_NORMAL_ADDR_LOOKUP 0x80
62 #define KSZ8794_TAIL_TAG_PORT_SEL 0x40
63 #define KSZ8794_TAIL_TAG_DEST_QUEUE 0x30
64 #define KSZ8794_TAIL_TAG_DEST_PORT3 0x04
65 #define KSZ8794_TAIL_TAG_DEST_PORT2 0x02
66 #define KSZ8794_TAIL_TAG_DEST_PORT1 0x01
67 
68 //Tail tag rules (KSZ8794 to host)
69 #define KSZ8794_TAIL_TAG_SRC_PORT 0x03
70 
71 //KSZ8794 PHY registers
72 #define KSZ8794_BMCR 0x00
73 #define KSZ8794_BMSR 0x01
74 #define KSZ8794_PHYID1 0x02
75 #define KSZ8794_PHYID2 0x03
76 #define KSZ8794_ANAR 0x04
77 #define KSZ8794_ANLPAR 0x05
78 #define KSZ8794_LINKMD 0x1D
79 #define KSZ8794_PHYSCS 0x1F
80 
81 //KSZ8794 Switch registers
82 #define KSZ8794_CHIP_ID0 0x00
83 #define KSZ8794_CHIP_ID1 0x01
84 #define KSZ8794_GLOBAL_CTRL0 0x02
85 #define KSZ8794_GLOBAL_CTRL1 0x03
86 #define KSZ8794_GLOBAL_CTRL2 0x04
87 #define KSZ8794_GLOBAL_CTRL3 0x05
88 #define KSZ8794_GLOBAL_CTRL4 0x06
89 #define KSZ8794_GLOBAL_CTRL5 0x07
90 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL 0x08
91 #define KSZ8794_GLOBAL_CTRL7 0x09
92 #define KSZ8794_GLOBAL_CTRL8 0x0A
93 #define KSZ8794_GLOBAL_CTRL9 0x0B
94 #define KSZ8794_GLOBAL_CTRL10 0x0C
95 #define KSZ8794_GLOBAL_CTRL11 0x0D
96 #define KSZ8794_PD_MGMT_CTRL1 0x0E
97 #define KSZ8794_PD_MGMT_CTRL2 0x0F
98 #define KSZ8794_PORT1_CTRL0 0x10
99 #define KSZ8794_PORT1_CTRL1 0x11
100 #define KSZ8794_PORT1_CTRL2 0x12
101 #define KSZ8794_PORT1_CTRL3 0x13
102 #define KSZ8794_PORT1_CTRL4 0x14
103 #define KSZ8794_PORT1_CTRL5 0x15
104 #define KSZ8794_PORT1_CTRL7 0x17
105 #define KSZ8794_PORT1_STAT0 0x18
106 #define KSZ8794_PORT1_STAT1 0x19
107 #define KSZ8794_PORT1_PHY_CTRL8 0x1A
108 #define KSZ8794_PORT1_LINKMD 0x1B
109 #define KSZ8794_PORT1_CTRL9 0x1C
110 #define KSZ8794_PORT1_CTRL10 0x1D
111 #define KSZ8794_PORT1_STAT2 0x1E
112 #define KSZ8794_PORT1_CTRL11_STAT3 0x1F
113 #define KSZ8794_PORT2_CTRL0 0x20
114 #define KSZ8794_PORT2_CTRL1 0x21
115 #define KSZ8794_PORT2_CTRL2 0x22
116 #define KSZ8794_PORT2_CTRL3 0x23
117 #define KSZ8794_PORT2_CTRL4 0x24
118 #define KSZ8794_PORT2_CTRL5 0x25
119 #define KSZ8794_PORT2_CTRL7 0x27
120 #define KSZ8794_PORT2_STAT0 0x28
121 #define KSZ8794_PORT2_STAT1 0x29
122 #define KSZ8794_PORT2_PHY_CTRL8 0x2A
123 #define KSZ8794_PORT2_LINKMD 0x2B
124 #define KSZ8794_PORT2_CTRL9 0x2C
125 #define KSZ8794_PORT2_CTRL10 0x2D
126 #define KSZ8794_PORT2_STAT2 0x2E
127 #define KSZ8794_PORT2_CTRL11_STAT3 0x2F
128 #define KSZ8794_PORT3_CTRL0 0x30
129 #define KSZ8794_PORT3_CTRL1 0x31
130 #define KSZ8794_PORT3_CTRL2 0x32
131 #define KSZ8794_PORT3_CTRL3 0x33
132 #define KSZ8794_PORT3_CTRL4 0x34
133 #define KSZ8794_PORT3_CTRL5 0x35
134 #define KSZ8794_PORT3_CTRL7 0x37
135 #define KSZ8794_PORT3_STAT0 0x38
136 #define KSZ8794_PORT3_STAT1 0x39
137 #define KSZ8794_PORT3_PHY_CTRL8 0x3A
138 #define KSZ8794_PORT3_LINKMD 0x3B
139 #define KSZ8794_PORT3_CTRL9 0x3C
140 #define KSZ8794_PORT3_CTRL10 0x3D
141 #define KSZ8794_PORT3_STAT2 0x3E
142 #define KSZ8794_PORT3_CTRL11_STAT3 0x3F
143 #define KSZ8794_PORT4_CTRL0 0x50
144 #define KSZ8794_PORT4_CTRL1 0x51
145 #define KSZ8794_PORT4_CTRL2 0x52
146 #define KSZ8794_PORT4_CTRL3 0x53
147 #define KSZ8794_PORT4_CTRL4 0x54
148 #define KSZ8794_PORT4_CTRL5 0x55
149 #define KSZ8794_PORT4_IF_CTRL6 0x56
150 #define KSZ8794_MAC_ADDR0 0x68
151 #define KSZ8794_MAC_ADDR1 0x69
152 #define KSZ8794_MAC_ADDR2 0x6A
153 #define KSZ8794_MAC_ADDR3 0x6B
154 #define KSZ8794_MAC_ADDR4 0x6C
155 #define KSZ8794_MAC_ADDR5 0x6D
156 #define KSZ8794_INDIRECT_CTRL0 0x6E
157 #define KSZ8794_INDIRECT_CTRL1 0x6F
158 #define KSZ8794_INDIRECT_DATA8 0x70
159 #define KSZ8794_INDIRECT_DATA7 0x71
160 #define KSZ8794_INDIRECT_DATA6 0x72
161 #define KSZ8794_INDIRECT_DATA5 0x73
162 #define KSZ8794_INDIRECT_DATA4 0x74
163 #define KSZ8794_INDIRECT_DATA3 0x75
164 #define KSZ8794_INDIRECT_DATA2 0x76
165 #define KSZ8794_INDIRECT_DATA1 0x77
166 #define KSZ8794_INDIRECT_DATA0 0x78
167 #define KSZ8794_INT_STAT 0x7C
168 #define KSZ8794_INT_MASK 0x7D
169 #define KSZ8794_ACL_INT_STAT 0x7E
170 #define KSZ8794_ACL_INT_CTRL 0x7F
171 #define KSZ8794_GLOBAL_CTRL12 0x80
172 #define KSZ8794_GLOBAL_CTRL13 0x81
173 #define KSZ8794_GLOBAL_CTRL14 0x82
174 #define KSZ8794_GLOBAL_CTRL15 0x83
175 #define KSZ8794_GLOBAL_CTRL16 0x84
176 #define KSZ8794_GLOBAL_CTRL17 0x85
177 #define KSZ8794_GLOBAL_CTRL18 0x86
178 #define KSZ8794_GLOBAL_CTRL19 0x87
179 #define KSZ8794_TOS_PRIO_CTRL0 0x90
180 #define KSZ8794_TOS_PRIO_CTRL1 0x91
181 #define KSZ8794_TOS_PRIO_CTRL2 0x92
182 #define KSZ8794_TOS_PRIO_CTRL3 0x93
183 #define KSZ8794_TOS_PRIO_CTRL4 0x94
184 #define KSZ8794_TOS_PRIO_CTRL5 0x95
185 #define KSZ8794_TOS_PRIO_CTRL6 0x96
186 #define KSZ8794_TOS_PRIO_CTRL7 0x97
187 #define KSZ8794_TOS_PRIO_CTRL8 0x98
188 #define KSZ8794_TOS_PRIO_CTRL9 0x99
189 #define KSZ8794_TOS_PRIO_CTRL10 0x9A
190 #define KSZ8794_TOS_PRIO_CTRL11 0x9B
191 #define KSZ8794_TOS_PRIO_CTRL12 0x9C
192 #define KSZ8794_TOS_PRIO_CTRL13 0x9D
193 #define KSZ8794_TOS_PRIO_CTRL14 0x9E
194 #define KSZ8794_TOS_PRIO_CTRL15 0x9F
195 #define KSZ8794_INDIRECT_BYTE 0xA0
196 #define KSZ8794_GLOBAL_CTRL20 0xA3
197 #define KSZ8794_GLOBAL_CTRL21 0xA4
198 #define KSZ8794_PORT1_CTRL12 0xB0
199 #define KSZ8794_PORT1_CTRL13 0xB1
200 #define KSZ8794_PORT1_CTRL14 0xB2
201 #define KSZ8794_PORT1_CTRL15 0xB3
202 #define KSZ8794_PORT1_CTRL16 0xB4
203 #define KSZ8794_PORT1_CTRL17 0xB5
204 #define KSZ8794_PORT1_RATE_LIMIT_CTRL 0xB6
205 #define KSZ8794_PORT1_PRIO0_IG_LIMIT_CTRL1 0xB7
206 #define KSZ8794_PORT1_PRIO1_IG_LIMIT_CTRL2 0xB8
207 #define KSZ8794_PORT1_PRIO2_IG_LIMIT_CTRL3 0xB9
208 #define KSZ8794_PORT1_PRIO3_IG_LIMIT_CTRL4 0xBA
209 #define KSZ8794_PORT1_QUEUE0_EG_LIMIT_CTRL1 0xBB
210 #define KSZ8794_PORT1_QUEUE1_EG_LIMIT_CTRL2 0xBC
211 #define KSZ8794_PORT1_QUEUE2_EG_LIMIT_CTRL3 0xBD
212 #define KSZ8794_PORT1_QUEUE3_EG_LIMIT_CTRL4 0xBE
213 #define KSZ8794_TEST 0xBF
214 #define KSZ8794_PORT2_CTRL12 0xC0
215 #define KSZ8794_PORT2_CTRL13 0xC1
216 #define KSZ8794_PORT2_CTRL14 0xC2
217 #define KSZ8794_PORT2_CTRL15 0xC3
218 #define KSZ8794_PORT2_CTRL16 0xC4
219 #define KSZ8794_PORT2_CTRL17 0xC5
220 #define KSZ8794_PORT2_RATE_LIMIT_CTRL 0xC6
221 #define KSZ8794_PORT2_PRIO0_IG_LIMIT_CTRL1 0xC7
222 #define KSZ8794_PORT2_PRIO1_IG_LIMIT_CTRL2 0xC8
223 #define KSZ8794_PORT2_PRIO2_IG_LIMIT_CTRL3 0xC9
224 #define KSZ8794_PORT2_PRIO3_IG_LIMIT_CTRL4 0xCA
225 #define KSZ8794_PORT2_QUEUE0_EG_LIMIT_CTRL1 0xCB
226 #define KSZ8794_PORT2_QUEUE1_EG_LIMIT_CTRL2 0xCC
227 #define KSZ8794_PORT2_QUEUE2_EG_LIMIT_CTRL3 0xCD
228 #define KSZ8794_PORT2_QUEUE3_EG_LIMIT_CTRL4 0xCE
229 #define KSZ8794_PORT3_CTRL12 0xD0
230 #define KSZ8794_PORT3_CTRL13 0xD1
231 #define KSZ8794_PORT3_CTRL14 0xD2
232 #define KSZ8794_PORT3_CTRL15 0xD3
233 #define KSZ8794_PORT3_CTRL16 0xD4
234 #define KSZ8794_PORT3_CTRL17 0xD5
235 #define KSZ8794_PORT3_RATE_LIMIT_CTRL 0xD6
236 #define KSZ8794_PORT3_PRIO0_IG_LIMIT_CTRL1 0xD7
237 #define KSZ8794_PORT3_PRIO1_IG_LIMIT_CTRL2 0xD8
238 #define KSZ8794_PORT3_PRIO2_IG_LIMIT_CTRL3 0xD9
239 #define KSZ8794_PORT3_PRIO3_IG_LIMIT_CTRL4 0xDA
240 #define KSZ8794_PORT3_QUEUE0_EG_LIMIT_CTRL1 0xDB
241 #define KSZ8794_PORT3_QUEUE1_EG_LIMIT_CTRL2 0xDC
242 #define KSZ8794_PORT3_QUEUE2_EG_LIMIT_CTRL3 0xDD
243 #define KSZ8794_PORT3_QUEUE3_EG_LIMIT_CTRL4 0xDE
244 #define KSZ8794_TEST2 0xDF
245 #define KSZ8794_TEST3 0xEF
246 #define KSZ8794_PORT4_CTRL12 0xF0
247 #define KSZ8794_PORT4_CTRL13 0xF1
248 #define KSZ8794_PORT4_CTRL14 0xF2
249 #define KSZ8794_PORT4_CTRL15 0xF3
250 #define KSZ8794_PORT4_CTRL16 0xF4
251 #define KSZ8794_PORT4_CTRL17 0xF5
252 #define KSZ8794_PORT4_RATE_LIMIT_CTRL 0xF6
253 #define KSZ8794_PORT4_PRIO0_IG_LIMIT_CTRL1 0xF7
254 #define KSZ8794_PORT4_PRIO1_IG_LIMIT_CTRL2 0xF8
255 #define KSZ8794_PORT4_PRIO2_IG_LIMIT_CTRL3 0xF9
256 #define KSZ8794_PORT4_PRIO3_IG_LIMIT_CTRL4 0xFA
257 #define KSZ8794_PORT4_QUEUE0_EG_LIMIT_CTRL1 0xFB
258 #define KSZ8794_PORT4_QUEUE1_EG_LIMIT_CTRL2 0xFC
259 #define KSZ8794_PORT4_QUEUE2_EG_LIMIT_CTRL3 0xFD
260 #define KSZ8794_PORT4_QUEUE3_EG_LIMIT_CTRL4 0xFE
261 #define KSZ8794_TEST4 0xFF
262 
263 //KSZ8794 Switch register access macros
264 #define KSZ8794_PORTn_CTRL0(port) (0x00 + ((port) * 0x10))
265 #define KSZ8794_PORTn_CTRL1(port) (0x01 + ((port) * 0x10))
266 #define KSZ8794_PORTn_CTRL2(port) (0x02 + ((port) * 0x10))
267 #define KSZ8794_PORTn_CTRL3(port) (0x03 + ((port) * 0x10))
268 #define KSZ8794_PORTn_CTRL4(port) (0x04 + ((port) * 0x10))
269 #define KSZ8794_PORTn_CTRL5(port) (0x05 + ((port) * 0x10))
270 #define KSZ8794_PORTn_CTRL7(port) (0x07 + ((port) * 0x10))
271 #define KSZ8794_PORTn_STAT0(port) (0x08 + ((port) * 0x10))
272 #define KSZ8794_PORTn_STAT1(port) (0x09 + ((port) * 0x10))
273 #define KSZ8794_PORTn_PHY_CTRL8(port) (0x0A + ((port) * 0x10))
274 #define KSZ8794_PORTn_LINKMD(port) (0x0B + ((port) * 0x10))
275 #define KSZ8794_PORTn_CTRL9(port) (0x0C + ((port) * 0x10))
276 #define KSZ8794_PORTn_CTRL10(port) (0x0D + ((port) * 0x10))
277 #define KSZ8794_PORTn_STAT2(port) (0x0E + ((port) * 0x10))
278 #define KSZ8794_PORTn_CTRL11_STAT3(port) (0x0F + ((port) * 0x10))
279 #define KSZ8794_PORTn_CTRL12(port) (0xA0 + ((port) * 0x10))
280 #define KSZ8794_PORTn_CTRL13(port) (0xA1 + ((port) * 0x10))
281 #define KSZ8794_PORTn_CTRL14(port) (0xA2 + ((port) * 0x10))
282 #define KSZ8794_PORTn_CTRL15(port) (0xA3 + ((port) * 0x10))
283 #define KSZ8794_PORTn_CTRL16(port) (0xA4 + ((port) * 0x10))
284 #define KSZ8794_PORTn_CTRL17(port) (0xA5 + ((port) * 0x10))
285 #define KSZ8794_PORTn_RATE_LIMIT_CTRL(port) (0xA6 + ((port) * 0x10))
286 #define KSZ8794_PORTn_PRIO0_IG_LIMIT_CTRL1(port) (0xA7 + ((port) * 0x10))
287 #define KSZ8794_PORTn_PRIO1_IG_LIMIT_CTRL2(port) (0xA8 + ((port) * 0x10))
288 #define KSZ8794_PORTn_PRIO2_IG_LIMIT_CTRL3(port) (0xA9 + ((port) * 0x10))
289 #define KSZ8794_PORTn_PRIO3_IG_LIMIT_CTRL4(port) (0xAA + ((port) * 0x10))
290 #define KSZ8794_PORTn_QUEUE0_EG_LIMIT_CTRL1(port) (0xAB + ((port) * 0x10))
291 #define KSZ8794_PORTn_QUEUE1_EG_LIMIT_CTRL2(port) (0xAC + ((port) * 0x10))
292 #define KSZ8794_PORTn_QUEUE2_EG_LIMIT_CTRL3(port) (0xAD + ((port) * 0x10))
293 #define KSZ8794_PORTn_QUEUE3_EG_LIMIT_CTRL4(port) (0xAE + ((port) * 0x10))
294 
295 //Basic Control register
296 #define KSZ8794_BMCR_RESET 0x8000
297 #define KSZ8794_BMCR_LOOPBACK 0x4000
298 #define KSZ8794_BMCR_FORCE_100 0x2000
299 #define KSZ8794_BMCR_AN_EN 0x1000
300 #define KSZ8794_BMCR_POWER_DOWN 0x0800
301 #define KSZ8794_BMCR_ISOLATE 0x0400
302 #define KSZ8794_BMCR_RESTART_AN 0x0200
303 #define KSZ8794_BMCR_FORCE_FULL_DUPLEX 0x0100
304 #define KSZ8794_BMCR_HP_MDIX 0x0020
305 #define KSZ8794_BMCR_FORCE_MDI 0x0010
306 #define KSZ8794_BMCR_AUTO_MDIX_DIS 0x0008
307 #define KSZ8794_BMCR_FAR_END_FAULT_DIS 0x0004
308 #define KSZ8794_BMCR_TRANSMIT_DIS 0x0002
309 #define KSZ8794_BMCR_LED_DIS 0x0001
310 
311 //Basic Status register
312 #define KSZ8794_BMSR_100BT4 0x8000
313 #define KSZ8794_BMSR_100BTX_FD 0x4000
314 #define KSZ8794_BMSR_100BTX_HD 0x2000
315 #define KSZ8794_BMSR_10BT_FD 0x1000
316 #define KSZ8794_BMSR_10BT_HD 0x0800
317 #define KSZ8794_BMSR_AN_COMPLETE 0x0020
318 #define KSZ8794_BMSR_FAR_END_FAULT 0x0010
319 #define KSZ8794_BMSR_AN_CAPABLE 0x0008
320 #define KSZ8794_BMSR_LINK_STATUS 0x0004
321 #define KSZ8794_BMSR_EXTENDED_CAPABLE 0x0001
322 
323 //PHYID High register
324 #define KSZ8794_PHYID1_DEFAULT 0x0022
325 
326 //PHYID Low register
327 #define KSZ8794_PHYID2_DEFAULT 0x1550
328 
329 //Advertisement Ability register
330 #define KSZ8794_ANAR_PAUSE 0x0400
331 #define KSZ8794_ANAR_100BTX_FD 0x0100
332 #define KSZ8794_ANAR_100BTX_HD 0x0080
333 #define KSZ8794_ANAR_10BT_FD 0x0040
334 #define KSZ8794_ANAR_10BT_HD 0x0020
335 #define KSZ8794_ANAR_SELECTOR 0x001F
336 #define KSZ8794_ANAR_SELECTOR_DEFAULT 0x0001
337 
338 //Link Partner Ability register
339 #define KSZ8794_ANLPAR_PAUSE 0x0400
340 #define KSZ8794_ANLPAR_100BTX_FD 0x0100
341 #define KSZ8794_ANLPAR_100BTX_HD 0x0080
342 #define KSZ8794_ANLPAR_10BT_FD 0x0040
343 #define KSZ8794_ANLPAR_10BT_HD 0x0020
344 
345 //LinkMD Control/Status register
346 #define KSZ8794_LINKMD_TEST_EN 0x8000
347 #define KSZ8794_LINKMD_RESULT 0x6000
348 #define KSZ8794_LINKMD_SHORT 0x1000
349 #define KSZ8794_LINKMD_FAULT_COUNT 0x01FF
350 
351 //PHY Special Control/Status register
352 #define KSZ8794_PHYSCS_OP_MODE 0x0700
353 #define KSZ8794_PHYSCS_OP_MODE_AN 0x0100
354 #define KSZ8794_PHYSCS_OP_MODE_10BT_HD 0x0200
355 #define KSZ8794_PHYSCS_OP_MODE_100BTX_HD 0x0300
356 #define KSZ8794_PHYSCS_OP_MODE_10BT_FD 0x0500
357 #define KSZ8794_PHYSCS_OP_MODE_100BTX_FD 0x0600
358 #define KSZ8794_PHYSCS_OP_MODE_ISOLATE 0x0700
359 #define KSZ8794_PHYSCS_POLRVS 0x0020
360 #define KSZ8794_PHYSCS_MDIX_STATUS 0x0010
361 #define KSZ8794_PHYSCS_FORCE_LINK 0x0008
362 #define KSZ8794_PHYSCS_PWRSAVE 0x0004
363 #define KSZ8794_PHYSCS_REMOTE_LOOPBACK 0x0002
364 
365 //Chip ID0 register
366 #define KSZ8794_CHIP_ID0_FAMILY_ID 0xFF
367 #define KSZ8794_CHIP_ID0_FAMILY_ID_DEFAULT 0x87
368 
369 //Chip ID1 / Start Switch register
370 #define KSZ8794_CHIP_ID1_CHIP_ID 0xF0
371 #define KSZ8794_CHIP_ID1_CHIP_ID_DEFAULT 0x60
372 #define KSZ8794_CHIP_ID1_REVISION_ID 0x0E
373 #define KSZ8794_CHIP_ID1_START_SWITCH 0x01
374 
375 //Global Control 0 register
376 #define KSZ8794_GLOBAL_CTRL0_NEW_BACK_OFF_EN 0x80
377 #define KSZ8794_GLOBAL_CTRL0_GLOBAL_SOFT_RESET_EN 0x40
378 #define KSZ8794_GLOBAL_CTRL0_FLUSH_DYNAMIC_MAC_TABLE 0x20
379 #define KSZ8794_GLOBAL_CTRL0_FLUSH_STATIC_MAC_TABLE 0x10
380 #define KSZ8794_GLOBAL_CTRL0_UNH_MODE 0x02
381 #define KSZ8794_GLOBAL_CTRL0_LINK_CHANGE_AGE 0x01
382 
383 //Global Control 1 register
384 #define KSZ8794_GLOBAL_CTRL1_2KB_PKT_SUPPORT 0x40
385 #define KSZ8794_GLOBAL_CTRL1_TX_FLOW_CTRL_DIS 0x20
386 #define KSZ8794_GLOBAL_CTRL1_RX_FLOW_CTRL_DIS 0x10
387 #define KSZ8794_GLOBAL_CTRL1_FRAME_LEN_CHECK_EN 0x08
388 #define KSZ8794_GLOBAL_CTRL1_AGING_EN 0x04
389 #define KSZ8794_GLOBAL_CTRL1_FAST_AGE_EN 0x02
390 #define KSZ8794_GLOBAL_CTRL1_AGGRESSIVE_BACK_OFF_EN 0x01
391 
392 //Global Control 2 register
393 #define KSZ8794_GLOBAL_CTRL2_UNI_VLAN_MISMATCH_DISCARD 0x80
394 #define KSZ8794_GLOBAL_CTRL2_MCAST_STORM_PROTECT_DIS 0x40
395 #define KSZ8794_GLOBAL_CTRL2_BACK_PRESSURE_MODE 0x20
396 #define KSZ8794_GLOBAL_CTRL2_FLOW_CTRL_FAIR_MODE 0x10
397 #define KSZ8794_GLOBAL_CTRL2_NO_EXCESSIVE_COL_DROP 0x08
398 #define KSZ8794_GLOBAL_CTRL2_MAX_PKT_SIZE_CHECK_DIS 0x02
399 
400 //Global Control 3 register
401 #define KSZ8794_GLOBAL_CTRL3_VLAN_EN 0x80
402 #define KSZ8794_GLOBAL_CTRL3_SW5_IGMP_SNOOP_EN 0x40
403 #define KSZ8794_GLOBAL_CTRL3_SNIFF_MODE_SEL 0x01
404 
405 //Global Control 4 register
406 #define KSZ8794_GLOBAL_CTRL4_SW4_BACK_PRESSURE_EN 0x80
407 #define KSZ8794_GLOBAL_CTRL4_SW4_HALF_DUPLEX_MODE 0x40
408 #define KSZ8794_GLOBAL_CTRL4_SW4_FLOW_CTRL_EN 0x20
409 #define KSZ8794_GLOBAL_CTRL4_SW4_SPEED 0x10
410 #define KSZ8794_GLOBAL_CTRL4_NULL_VID_REPLACEMENT 0x08
411 #define KSZ8794_GLOBAL_CTRL4_BCAST_STORM_PROTECT_RATE_MSB 0x07
412 
413 //Global Control 5 register
414 #define KSZ8794_GLOBAL_CTRL5_BCAST_STORM_PROTECT_RATE_LSB 0xFF
415 
416 //Global Control 6 MIB Control register
417 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_FLUSH_COUNTER 0x80
418 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_FREEZE_COUNTER 0x40
419 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_CONTROL_EN 0x1F
420 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_CONTROL_EN_PORT1 0x01
421 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_CONTROL_EN_PORT2 0x02
422 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_CONTROL_EN_PORT3 0x04
423 #define KSZ8794_GLOBAL_CTRL6_MIB_CTRL_CONTROL_EN_PORT4 0x10
424 
425 //Global Control 7 register
426 #define KSZ8794_GLOBAL_CTRL7_FACTORY_TESTING 0xFF
427 
428 //Global Control 8 register
429 #define KSZ8794_GLOBAL_CTRL8_FACTORY_TESTING 0xFF
430 
431 //Global Control 9 register
432 #define KSZ8794_GLOBAL_CTRL9_SW4_REFCLK_EDGE_SEL 0x40
433 #define KSZ8794_GLOBAL_CTRL9_SW4_REFCLK_EDGE_SEL_RISING 0x00
434 #define KSZ8794_GLOBAL_CTRL9_SW4_REFCLK_EDGE_SEL_FALLING 0x40
435 #define KSZ8794_GLOBAL_CTRL9_LED_MODE 0x30
436 #define KSZ8794_GLOBAL_CTRL9_LED_MODE_LED0_LNK_ACT_LED1_SPD 0x00
437 #define KSZ8794_GLOBAL_CTRL9_LED_MODE_LED0_LNK_LED1_ACT 0x10
438 #define KSZ8794_GLOBAL_CTRL9_LED_MODE_LED0_LNK_ACT_LED1_DPLX 0x20
439 #define KSZ8794_GLOBAL_CTRL9_LED_MODE_LED0_LNK_LED1_ACT_DPLX 0x30
440 #define KSZ8794_GLOBAL_CTRL9_REFCLKO_ENABLE 0x02
441 #define KSZ8794_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL 0x01
442 #define KSZ8794_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL_FALLING 0x00
443 #define KSZ8794_GLOBAL_CTRL9_SPI_READ_CLK_EDGE_SEL_RISING 0x01
444 
445 //Global Control 10 register
446 #define KSZ8794_GLOBAL_CTRL10_TAIL_TAG_EN 0x02
447 #define KSZ8794_GLOBAL_CTRL10_PASS_FLOW_CTRL_PKT 0x01
448 
449 //Global Control 11 register
450 #define KSZ8794_GLOBAL_CTRL11_FACTORY_TESTING 0xFF
451 
452 //Power-Down Management Control 1 register
453 #define KSZ8794_PD_MGMT_CTRL1_PLL_PWR_DOWN 0x20
454 #define KSZ8794_PD_MGMT_CTRL1_PWR_MGMT_MODE 0x18
455 #define KSZ8794_PD_MGMT_CTRL1_PWR_MGMT_MODE_NORMAL 0x00
456 #define KSZ8794_PD_MGMT_CTRL1_PWR_MGMT_MODE_ENERGY_DETECT 0x08
457 #define KSZ8794_PD_MGMT_CTRL1_PWR_MGMT_MODE_SOFT_PWR_DOWN 0x10
458 
459 //Power-Down Management Control 2 register
460 #define KSZ8794_PD_MGMT_CTRL2_GO_SLEEP_TIME 0xFF
461 
462 //Port N Control 0 register
463 #define KSZ8794_PORTn_CTRL0_BCAST_STORM_PROTECT_EN 0x80
464 #define KSZ8794_PORTn_CTRL0_DIFFSERV_PRIO_CLASS_EN 0x40
465 #define KSZ8794_PORTn_CTRL0_802_1P_PRIO_CLASS_EN 0x20
466 #define KSZ8794_PORTn_CTRL0_PORT_PRIO_CLASS_EN 0x18
467 #define KSZ8794_PORTn_CTRL0_TAG_INSERTION 0x04
468 #define KSZ8794_PORTn_CTRL0_TAG_REMOVAL 0x02
469 #define KSZ8794_PORTn_CTRL0_TWO_QUEUE_SPLIT_EN 0x01
470 
471 //Port N Control 1 register
472 #define KSZ8794_PORTn_CTRL1_SNIFFER_PORT 0x80
473 #define KSZ8794_PORTn_CTRL1_RECEIVE_SNIFF 0x40
474 #define KSZ8794_PORTn_CTRL1_TRANSMIT_SNIFF 0x20
475 #define KSZ8794_PORTn_CTRL1_PORT_VLAN_MEMBERSHIP 0x1F
476 
477 //Port N Control 2 register
478 #define KSZ8794_PORTn_CTRL2_USER_PRIO_CEILING 0x80
479 #define KSZ8794_PORTn_CTRL2_INGRESS_VLAN_FILT 0x40
480 #define KSZ8794_PORTn_CTRL2_DISCARD_NON_PVID_PKT 0x20
481 #define KSZ8794_PORTn_CTRL2_FORCE_FLOW_CTRL 0x10
482 #define KSZ8794_PORTn_CTRL2_BACK_PRESSURE_EN 0x08
483 #define KSZ8794_PORTn_CTRL2_TRANSMIT_EN 0x04
484 #define KSZ8794_PORTn_CTRL2_RECEIVE_EN 0x02
485 #define KSZ8794_PORTn_CTRL2_LEARNING_DIS 0x01
486 
487 //Port N Control 3 register
488 #define KSZ8794_PORTn_CTRL3_DEFAULT_USER_PRIO 0xE0
489 #define KSZ8794_PORTn_CTRL3_DEFAULT_CFI 0x10
490 #define KSZ8794_PORTn_CTRL3_DEFAULT_VID_MSB 0x0F
491 
492 //Port N Control 4 register
493 #define KSZ8794_PORTn_CTRL4_DEFAULT_VID_LSB 0xFF
494 
495 //Port 4 Interface Control 6 register
496 #define KSZ8794_PORT4_IF_CTRL6_RMII_CLK_SEL 0x80
497 #define KSZ8794_PORT4_IF_CTRL6_IS_1GBPS 0x40
498 #define KSZ8794_PORT4_IF_CTRL6_RGMII_ID_IG_EN 0x10
499 #define KSZ8794_PORT4_IF_CTRL6_RGMII_ID_EG_EN 0x08
500 #define KSZ8794_PORT4_IF_CTRL6_MII_MODE_SEL 0x04
501 #define KSZ8794_PORT4_IF_CTRL6_MII_MODE_SEL_PHY 0x00
502 #define KSZ8794_PORT4_IF_CTRL6_MII_MODE_SEL_MAC 0x04
503 #define KSZ8794_PORT4_IF_CTRL6_IF_MODE_SEL 0x03
504 #define KSZ8794_PORT4_IF_CTRL6_IF_MODE_SEL_MII 0x00
505 #define KSZ8794_PORT4_IF_CTRL6_IF_MODE_SEL_RMII 0x01
506 #define KSZ8794_PORT4_IF_CTRL6_IF_MODE_SEL_RGMII 0x03
507 
508 //Port N Status 0 register
509 #define KSZ8794_PORTn_STAT0_LP_FLOW_CTRL_CAPABLE 0x30
510 #define KSZ8794_PORTn_STAT0_LP_100BTX_FD_CAPABLE 0x08
511 #define KSZ8794_PORTn_STAT0_LP_100BTX_HF_CAPABLE 0x04
512 #define KSZ8794_PORTn_STAT0_LP_10BT_FD_CAPABLE 0x02
513 #define KSZ8794_PORTn_STAT0_LP_10BT_HD_CAPABLE 0x01
514 
515 //Port N Status 1 register
516 #define KSZ8794_PORTn_STAT1_HP_MDIX 0x80
517 #define KSZ8794_PORTn_STAT1_FACTORY_TESTING 0x40
518 #define KSZ8794_PORTn_STAT1_POLRVS 0x20
519 #define KSZ8794_PORTn_STAT1_TX_FLOW_CTRL_EN 0x10
520 #define KSZ8794_PORTn_STAT1_RX_FLOW_CTRL_EN 0x08
521 #define KSZ8794_PORTn_STAT1_OP_SPEED 0x04
522 #define KSZ8794_PORTn_STAT1_OP_DUPLEX 0x02
523 
524 //Port N Control 9 register
525 #define KSZ8794_PORTn_CTRL9_AN_DIS 0x80
526 #define KSZ8794_PORTn_CTRL9_FORCED_SPEED 0x40
527 #define KSZ8794_PORTn_CTRL9_FORCED_DUPLEX 0x20
528 
529 //Port N Control 10 register
530 #define KSZ8794_PORTn_CTRL10_LED_OFF 0x80
531 #define KSZ8794_PORTn_CTRL10_TX_DIS 0x40
532 #define KSZ8794_PORTn_CTRL10_RESTART_AN 0x20
533 #define KSZ8794_PORTn_CTRL10_POWER_DOWN 0x08
534 #define KSZ8794_PORTn_CTRL10_AUTO_MDIX_DIS 0x04
535 #define KSZ8794_PORTn_CTRL10_FORCED_MDI 0x02
536 #define KSZ8794_PORTn_CTRL10_MAC_LOOPBACK 0x01
537 
538 //Port N Status 2 register
539 #define KSZ8794_PORTn_STAT2_MDIX_STATUS 0x80
540 #define KSZ8794_PORTn_STAT2_AN_DONE 0x40
541 #define KSZ8794_PORTn_STAT2_LINK_GOOD 0x20
542 
543 //Port N Control 11 / Status 3 register
544 #define KSZ8794_PORTn_CTRL11_STAT3_PHY_LOOPBACK 0x80
545 #define KSZ8794_PORTn_CTRL11_STAT3_PHY_ISOLATE 0x20
546 #define KSZ8794_PORTn_CTRL11_STAT3_SOFT_RESET 0x10
547 #define KSZ8794_PORTn_CTRL11_STAT3_FORCE_LINK 0x08
548 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE 0x07
549 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE_AN 0x01
550 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE_10BT_HD 0x02
551 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE_100BTX_HD 0x03
552 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE_10BT_FD 0x05
553 #define KSZ8794_PORTn_CTRL11_STAT3_OP_MODE_100BTX_FD 0x06
554 
555 //Indirect Access Control 0 register
556 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL 0xE0
557 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL_INDIRECT_MODE 0x00
558 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL_EEE 0x20
559 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL_ACL 0x40
560 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL_PME 0x80
561 #define KSZ8794_INDIRECT_CTRL0_FUNC_SEL_LINKMD 0xA0
562 #define KSZ8794_INDIRECT_CTRL0_WRITE 0x00
563 #define KSZ8794_INDIRECT_CTRL0_READ 0x10
564 #define KSZ8794_INDIRECT_CTRL0_TABLE_SEL 0x0C
565 #define KSZ8794_INDIRECT_CTRL0_TABLE_SEL_STATIC_MAC 0x00
566 #define KSZ8794_INDIRECT_CTRL0_TABLE_SEL_VLAN 0x04
567 #define KSZ8794_INDIRECT_CTRL0_TABLE_SEL_DYNAMIC_MAC 0x08
568 #define KSZ8794_INDIRECT_CTRL0_TABLE_SEL_MIB_COUNTER 0x0C
569 #define KSZ8794_INDIRECT_CTRL0_ADDR_11_8 0x0F
570 #define KSZ8794_INDIRECT_CTRL0_ADDR_9_8 0x03
571 
572 //Indirect Access Control 1 register
573 #define KSZ8794_INDIRECT_CTRL1_ADDR_7_0 0xFF
574 
575 //Interrupt Status register
576 #define KSZ8794_INT_STAT_PME 0x10
577 #define KSZ8794_INT_STAT_PORT3 0x04
578 #define KSZ8794_INT_STAT_PORT2 0x02
579 #define KSZ8794_INT_STAT_PORT1 0x01
580 
581 //Interrupt Mask register
582 #define KSZ8794_INT_MASK_PME 0x10
583 #define KSZ8794_INT_MASK_PORT3 0x04
584 #define KSZ8794_INT_MASK_PORT2 0x02
585 #define KSZ8794_INT_MASK_PORT1 0x01
586 
587 //ACL Interrupt Status register
588 #define KSZ8794_ACL_INT_STAT_PORT4 0x08
589 #define KSZ8794_ACL_INT_STAT_PORT3 0x04
590 #define KSZ8794_ACL_INT_STAT_PORT2 0x02
591 #define KSZ8794_ACL_INT_STAT_PORT1 0x01
592 
593 //ACL Interrupt Control register
594 #define KSZ8794_ACL_INT_CTRL_PORT4 0x08
595 #define KSZ8794_ACL_INT_CTRL_PORT3 0x04
596 #define KSZ8794_ACL_INT_CTRL_PORT2 0x02
597 #define KSZ8794_ACL_INT_CTRL_PORT1 0x01
598 
599 //Global Control 12 register
600 #define KSZ8794_GLOBAL_CTRL12_TAG3 0xC0
601 #define KSZ8794_GLOBAL_CTRL12_TAG2 0x30
602 #define KSZ8794_GLOBAL_CTRL12_TAG1 0x0C
603 #define KSZ8794_GLOBAL_CTRL12_TAG0 0x03
604 
605 //Global Control 13 register
606 #define KSZ8794_GLOBAL_CTRL13_TAG7 0xC0
607 #define KSZ8794_GLOBAL_CTRL13_TAG6 0x30
608 #define KSZ8794_GLOBAL_CTRL13_TAG5 0x0C
609 #define KSZ8794_GLOBAL_CTRL13_TAG4 0x03
610 
611 //Global Control 14 register
612 #define KSZ8794_GLOBAL_CTRL14_PRI_2Q 0xC0
613 
614 //Global Control 15 register
615 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD 0x20
616 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP 0x1F
617 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_FILT 0x00
618 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT1 0x01
619 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT2 0x02
620 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT3 0x04
621 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_PORT4 0x10
622 #define KSZ8794_GLOBAL_CTRL15_UNKNOWN_UNICAST_FWD_MAP_ALL 0x1F
623 
624 //Global Control 16 register
625 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD 0x20
626 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP 0x1F
627 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_FILT 0x00
628 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT1 0x01
629 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT2 0x02
630 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT3 0x04
631 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_PORT4 0x10
632 #define KSZ8794_GLOBAL_CTRL16_UNKNOWN_MCAST_FWD_MAP_ALL 0x17
633 
634 //Global Control 17 register
635 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD 0x20
636 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP 0x1F
637 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_FILT 0x00
638 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT1 0x01
639 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT2 0x02
640 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT3 0x04
641 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_PORT4 0x10
642 #define KSZ8794_GLOBAL_CTRL17_UNKNOWN_VID_FWD_MAP_ALL 0x17
643 
644 //Global Control 18 register
645 #define KSZ8794_GLOBAL_CTRL18_SELF_ADDR_FILTER_EN 0x40
646 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD 0x20
647 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP 0x1F
648 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_FILT 0x00
649 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT1 0x01
650 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT2 0x02
651 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT3 0x04
652 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_PORT4 0x10
653 #define KSZ8794_GLOBAL_CTRL18_UNKNOWN_IP_MCAST_FWD_MAP_ALL 0x17
654 
655 //Global Control 19 register
656 #define KSZ8794_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD 0x30
657 #define KSZ8794_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_16MS 0x00
658 #define KSZ8794_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_64MS 0x10
659 #define KSZ8794_GLOBAL_CTRL19_IG_RATE_LIMIT_PERIOD_256MS 0x20
660 #define KSZ8794_GLOBAL_CTRL19_QUEUE_BASED_EG_RATE_LIMITE_EN 0x08
661 #define KSZ8794_GLOBAL_CTRL19_INSERT_SRC_PORT_PVID_TAG_EN 0x04
662 
663 //Global Control 20 register
664 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH 0x70
665 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_2MA 0x00
666 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_4MA 0x10
667 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_8MA 0x20
668 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_12MA 0x30
669 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_16MA 0x40
670 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_20MA 0x50
671 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_24MA 0x60
672 #define KSZ8794_GLOBAL_CTRL20_HIGH_SPEED_DRIVE_STRENGTH_28MA 0x70
673 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH 0x07
674 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_2MA 0x00
675 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_4MA 0x01
676 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_8MA 0x02
677 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_12MA 0x03
678 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_16MA 0x04
679 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_20MA 0x05
680 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_24MA 0x06
681 #define KSZ8794_GLOBAL_CTRL20_LOW_SPEED_DRIVE_STRENGTH_28MA 0x07
682 
683 //Global Control 21 register
684 #define KSZ8794_GLOBAL_CTRL21_MLD_SNOOP_OPT 0x08
685 #define KSZ8794_GLOBAL_CTRL21_MLD_SNOOP_EN 0x04
686 
687 //C++ guard
688 #ifdef __cplusplus
689 extern "C" {
690 #endif
691 
692 //CC-RX, CodeWarrior or Win32 compiler?
693 #if defined(__CCRX__)
694  #pragma pack
695 #elif defined(__CWCC__) || defined(_WIN32)
696  #pragma pack(push, 1)
697 #endif
698 
699 
700 /**
701  * @brief Static MAC table entry (read operation)
702  **/
703 
704 typedef struct
705 {
706 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
707  uint8_t fid : 7; //0
708  uint8_t useFid : 1;
709  uint8_t reserved : 1; //1
710  uint8_t override : 1;
711  uint8_t valid : 1;
712  uint8_t forwardPorts : 5;
713 #else
714  uint8_t useFid : 1; //0
715  uint8_t fid : 7;
716  uint8_t forwardPorts : 5; //1
717  uint8_t valid : 1;
718  uint8_t override : 1;
719  uint8_t reserved : 1;
720 #endif
723 
724 
725 /**
726  * @brief Static MAC table entry (write operation)
727  **/
728 
729 typedef struct
730 {
731  uint8_t fid; //0
732 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
733  uint8_t useFid : 1; //1
734  uint8_t override : 1;
735  uint8_t valid : 1;
736  uint8_t forwardPorts : 5;
737 #else
738  uint8_t forwardPorts : 5; //1
739  uint8_t valid : 1;
740  uint8_t override : 1;
741  uint8_t useFid : 1;
742 #endif
745 
746 
747 /**
748  * @brief Dynamic MAC table entry
749  **/
750 
751 typedef struct
752 {
753 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
754  uint8_t macEmpty : 1; //0
755  uint8_t numValidEntriesH : 7;
756  uint8_t numValidEntriesL : 3; //1
757  uint8_t timestamp : 2;
758  uint8_t sourcePort : 3;
759  uint8_t dataNotReady : 1; //2
760  uint8_t fid : 7;
761 #else
762  uint8_t numValidEntriesH : 7; //0
763  uint8_t macEmpty : 1;
764  uint8_t sourcePort : 3; //1
765  uint8_t timestamp : 2;
766  uint8_t numValidEntriesL : 3;
767  uint8_t fid : 7; //2
768  uint8_t dataNotReady : 1;
769 #endif
772 
773 
774 //CC-RX, CodeWarrior or Win32 compiler?
775 #if defined(__CCRX__)
776  #pragma unpack
777 #elif defined(__CWCC__) || defined(_WIN32)
778  #pragma pack(pop)
779 #endif
780 
781 //KSZ8794 Ethernet switch driver
782 extern const SwitchDriver ksz8794SwitchDriver;
783 
784 //KSZ8794 related functions
785 error_t ksz8794Init(NetInterface *interface);
786 void ksz8794InitHook(NetInterface *interface);
787 
788 void ksz8794Tick(NetInterface *interface);
789 
790 void ksz8794EnableIrq(NetInterface *interface);
791 void ksz8794DisableIrq(NetInterface *interface);
792 
793 void ksz8794EventHandler(NetInterface *interface);
794 
795 error_t ksz8794TagFrame(NetInterface *interface, NetBuffer *buffer,
796  size_t *offset, NetTxAncillary *ancillary);
797 
798 error_t ksz8794UntagFrame(NetInterface *interface, uint8_t **frame,
799  size_t *length, NetRxAncillary *ancillary);
800 
801 bool_t ksz8794GetLinkState(NetInterface *interface, uint8_t port);
802 uint32_t ksz8794GetLinkSpeed(NetInterface *interface, uint8_t port);
804 
805 void ksz8794SetPortState(NetInterface *interface, uint8_t port,
806  SwitchPortState state);
807 
809 
810 void ksz8794SetAgingTime(NetInterface *interface, uint32_t agingTime);
811 
812 void ksz8794EnableIgmpSnooping(NetInterface *interface, bool_t enable);
813 void ksz8794EnableMldSnooping(NetInterface *interface, bool_t enable);
814 void ksz8794EnableRsvdMcastTable(NetInterface *interface, bool_t enable);
815 
817  const SwitchFdbEntry *entry);
818 
820  const SwitchFdbEntry *entry);
821 
823  SwitchFdbEntry *entry);
824 
826 
828  SwitchFdbEntry *entry);
829 
830 void ksz8794FlushDynamicFdbTable(NetInterface *interface, uint8_t port);
831 
833  bool_t enable, uint32_t forwardPorts);
834 
835 void ksz8794WritePhyReg(NetInterface *interface, uint8_t port,
836  uint8_t address, uint16_t data);
837 
838 uint16_t ksz8794ReadPhyReg(NetInterface *interface, uint8_t port,
839  uint8_t address);
840 
841 void ksz8794DumpPhyReg(NetInterface *interface, uint8_t port);
842 
843 void ksz8794WriteSwitchReg(NetInterface *interface, uint16_t address,
844  uint8_t data);
845 
846 uint8_t ksz8794ReadSwitchReg(NetInterface *interface, uint16_t address);
847 
848 void ksz8794DumpSwitchReg(NetInterface *interface);
849 
850 //C++ guard
851 #ifdef __cplusplus
852 }
853 #endif
854 
855 #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 ksz8794DisableIrq(NetInterface *interface)
Disable interrupts.
uint8_t ksz8794ReadSwitchReg(NetInterface *interface, uint16_t address)
Read switch register.
uint32_t ksz8794GetLinkSpeed(NetInterface *interface, uint8_t port)
Get link speed.
void ksz8794EnableRsvdMcastTable(NetInterface *interface, bool_t enable)
Enable reserved multicast table.
error_t ksz8794DeleteStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Remove an entry from the static MAC table.
error_t ksz8794UntagFrame(NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
Decode tail tag from incoming Ethernet frame.
error_t ksz8794GetDynamicFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the dynamic MAC table.
error_t ksz8794GetStaticFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the static MAC table.
void ksz8794DumpPhyReg(NetInterface *interface, uint8_t port)
Dump PHY registers for debugging purpose.
void ksz8794EnableIrq(NetInterface *interface)
Enable interrupts.
void ksz8794EnableMldSnooping(NetInterface *interface, bool_t enable)
Enable MLD snooping.
void ksz8794WriteSwitchReg(NetInterface *interface, uint16_t address, uint8_t data)
Write switch register.
error_t ksz8794AddStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Add a new entry to the static MAC table.
SwitchPortState ksz8794GetPortState(NetInterface *interface, uint8_t port)
Get port state.
uint16_t ksz8794ReadPhyReg(NetInterface *interface, uint8_t port, uint8_t address)
Read PHY register.
void ksz8794FlushStaticFdbTable(NetInterface *interface)
Flush static MAC table.
bool_t ksz8794GetLinkState(NetInterface *interface, uint8_t port)
Get link state.
NicDuplexMode ksz8794GetDuplexMode(NetInterface *interface, uint8_t port)
Get duplex mode.
void ksz8794SetAgingTime(NetInterface *interface, uint32_t agingTime)
Set aging time for dynamic filtering entries.
void ksz8794SetPortState(NetInterface *interface, uint8_t port, SwitchPortState state)
Set port state.
error_t ksz8794Init(NetInterface *interface)
KSZ8794 Ethernet switch initialization.
void ksz8794FlushDynamicFdbTable(NetInterface *interface, uint8_t port)
Flush dynamic MAC table.
void ksz8794WritePhyReg(NetInterface *interface, uint8_t port, uint8_t address, uint16_t data)
Write PHY register.
void ksz8794EventHandler(NetInterface *interface)
KSZ8794 event handler.
const SwitchDriver ksz8794SwitchDriver
KSZ8794 Ethernet switch driver.
void ksz8794Tick(NetInterface *interface)
KSZ8794 timer handler.
void ksz8794InitHook(NetInterface *interface)
KSZ8794 custom configuration.
void ksz8794EnableIgmpSnooping(NetInterface *interface, bool_t enable)
Enable IGMP snooping.
void ksz8794DumpSwitchReg(NetInterface *interface)
Dump switch registers for debugging purpose.
error_t ksz8794TagFrame(NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
Add tail tag to Ethernet frame.
void ksz8794SetUnknownMcastFwdPorts(NetInterface *interface, bool_t enable, uint32_t forwardPorts)
Set forward ports for unknown multicast packets.
#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