lan9370_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan9370_driver.h
3  * @brief LAN9370 5-port 100Base-T1 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 _LAN9370_DRIVER_H
32 #define _LAN9370_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Port identifiers
38 #define LAN9370_PORT1 1
39 #define LAN9370_PORT2 2
40 #define LAN9370_PORT3 3
41 #define LAN9370_PORT4 4
42 #define LAN9370_PORT5 5
43 
44 //Port masks
45 #define LAN9370_PORT_MASK 0x1F
46 #define LAN9370_PORT1_MASK 0x01
47 #define LAN9370_PORT2_MASK 0x02
48 #define LAN9370_PORT3_MASK 0x04
49 #define LAN9370_PORT4_MASK 0x08
50 #define LAN9370_PORT5_MASK 0x10
51 
52 //SPI command byte
53 #define LAN9370_SPI_CMD_WRITE 0x40000000
54 #define LAN9370_SPI_CMD_READ 0x60000000
55 #define LAN9370_SPI_CMD_ADDR 0x001FFFE0
56 
57 //Size of static and dynamic MAC tables
58 #define LAN9370_STATIC_MAC_TABLE_SIZE 256
59 #define LAN9370_DYNAMIC_MAC_TABLE_SIZE 1024
60 
61 //Tail tag rules (host to LAN9370)
62 #define LAN9370_TAIL_TAG_VALID 0x2000
63 #define LAN9370_TAIL_TAG_NORMAL_ADDR_LOOKUP 0x1000
64 #define LAN9370_TAIL_TAG_PORT_BLOCKING_OVERRIDE 0x0800
65 #define LAN9370_TAIL_TAG_PRIORITY 0x0700
66 #define LAN9370_TAIL_TAG_DEST_PORT5 0x0010
67 #define LAN9370_TAIL_TAG_DEST_PORT4 0x0008
68 #define LAN9370_TAIL_TAG_DEST_PORT3 0x0004
69 #define LAN9370_TAIL_TAG_DEST_PORT2 0x0002
70 #define LAN9370_TAIL_TAG_DEST_PORT1 0x0001
71 
72 //Tail tag rules (LAN9370 to host)
73 #define LAN9370_TAIL_TAG_PTP_MSG 0x80
74 #define LAN9370_TAIL_TAG_SRC_PORT 0x07
75 
76 //LAN9370 PHY registers
77 #define LAN9370_BASIC_CONTROL 0x00
78 #define LAN9370_BASIC_STATUS 0x01
79 #define LAN9370_PHY_ID1 0x02
80 #define LAN9370_PHY_ID2 0x03
81 #define LAN9370_MASTER_SLAVE_CONTROL 0x09
82 #define LAN9370_MASTER_SLAVE_STATUS 0x0A
83 #define LAN9370_EXT_REG_CTL 0x14
84 #define LAN9370_EXT_REG_RD_DATA 0x15
85 #define LAN9370_EXT_REG_WR_DATA 0x16
86 
87 //LAN9370 Switch registers
88 #define LAN9370_CHIP_ID0 0x0000
89 #define LAN9370_CHIP_ID1 0x0001
90 #define LAN9370_CHIP_ID2 0x0002
91 #define LAN9370_CHIP_ID3 0x0003
92 #define LAN9370_GLOBAL_CTRL0 0x0007
93 #define LAN9370_SWITCH_OP 0x0300
94 #define LAN9370_SWITCH_LUE_CTRL0 0x0310
95 #define LAN9370_SWITCH_LUE_CTRL1 0x0311
96 #define LAN9370_SWITCH_LUE_CTRL2 0x0312
97 #define LAN9370_SWITCH_LUE_CTRL3 0x0313
98 #define LAN9370_SWITCH_LUE_AGE 0x0320
99 #define LAN9370_UNKONWN_MULTICAST_CTRL 0x0324
100 #define LAN9370_GLOBAL_PORT_MIRROR_SNOOP_CTRL 0x0370
101 #define LAN9370_ALU_TABLE_CTRL 0x0418
102 #define LAN9370_STATIC_MCAST_TABLE_CTRL 0x041C
103 #define LAN9370_ALU_TABLE_ENTRY1 0x0420
104 #define LAN9370_STATIC_TABLE_ENTRY1 0x0420
105 #define LAN9370_ALU_TABLE_ENTRY2 0x0424
106 #define LAN9370_STATIC_TABLE_ENTRY2 0x0424
107 #define LAN9370_ALU_TABLE_ENTRY3 0x0428
108 #define LAN9370_STATIC_TABLE_ENTRY3 0x0428
109 #define LAN9370_ALU_TABLE_ENTRY4 0x042C
110 #define LAN9370_STATIC_TABLE_ENTRY4 0x042C
111 #define LAN9370_IND_ADDR 0x075C
112 #define LAN9370_IND_DATA 0x0760
113 #define LAN9370_IND_CTRL 0x0768
114 #define LAN9370_VPHY_SPECIAL_CTRL 0x077C
115 #define LAN9370_PORT1_OP_CTRL0 0x1020
116 #define LAN9370_PORT1_STATUS 0x1030
117 #define LAN9370_PORT1_MAC_CTRL0 0x1400
118 #define LAN9370_PORT1_MSTP_STATE 0x1B04
119 #define LAN9370_PORT2_OP_CTRL0 0x2020
120 #define LAN9370_PORT2_STATUS 0x2030
121 #define LAN9370_PORT2_MAC_CTRL0 0x2400
122 #define LAN9370_PORT2_MSTP_STATE 0x2B04
123 #define LAN9370_PORT3_OP_CTRL0 0x3020
124 #define LAN9370_PORT3_STATUS 0x3030
125 #define LAN9370_PORT3_MAC_CTRL0 0x3400
126 #define LAN9370_PORT3_MSTP_STATE 0x3B04
127 #define LAN9370_PORT4_OP_CTRL0 0x4020
128 #define LAN9370_PORT4_STATUS 0x4030
129 #define LAN9370_PORT4_MAC_CTRL0 0x4400
130 #define LAN9370_PORT4_MSTP_STATE 0x4B04
131 #define LAN9370_PORT5_OP_CTRL0 0x5020
132 #define LAN9370_PORT5_STATUS 0x5030
133 #define LAN9370_PORT5_XMII_CTRL0 0x5300
134 #define LAN9370_PORT5_XMII_CTRL1 0x5301
135 #define LAN9370_PORT5_MAC_CTRL0 0x5400
136 #define LAN9370_PORT5_MSTP_STATE 0x5B04
137 
138 //LAN9370 Switch register access macros
139 #define LAN9370_PORTn_OP_CTRL0(port) (0x0020 + ((port) * 0x1000))
140 #define LAN9370_PORTn_STATUS(port) (0x0030 + ((port) * 0x1000))
141 #define LAN9370_PORTn_XMII_CTRL0(port) (0x0300 + ((port) * 0x1000))
142 #define LAN9370_PORTn_XMII_CTRL1(port) (0x0301 + ((port) * 0x1000))
143 #define LAN9370_PORTn_MAC_CTRL0(port) (0x0400 + ((port) * 0x1000))
144 #define LAN9370_PORTn_MSTP_STATE(port) (0x0B04 + ((port) * 0x1000))
145 #define LAN9370_PORTn_T1_PHY_REG(port, addr) (0x0100 + ((port) * 0x1000) + ((addr) * 4))
146 
147 //Basic Control register
148 #define LAN9370_BASIC_CONTROL_SW_RESET 0x8000
149 #define LAN9370_BASIC_CONTROL_LOOPBACK 0x4000
150 #define LAN9370_BASIC_CONTROL_SPEED_SEL_LSB 0x2000
151 #define LAN9370_BASIC_CONTROL_AN_EN 0x1000
152 #define LAN9370_BASIC_CONTROL_POWER_DOWN 0x0800
153 #define LAN9370_BASIC_CONTROL_ISOLATE 0x0400
154 #define LAN9370_BASIC_CONTROL_RESTART_AN 0x0200
155 #define LAN9370_BASIC_CONTROL_DUPLEX_MODE 0x0100
156 #define LAN9370_BASIC_CONTROL_COL_TEST 0x0080
157 #define LAN9370_BASIC_CONTROL_SPEED_SEL_MSB 0x0040
158 #define LAN9370_BASIC_CONTROL_UNIDIRECTIONAL_EN 0x0020
159 
160 //Basic Status register
161 #define LAN9370_BASIC_STATUS_100BT4 0x8000
162 #define LAN9370_BASIC_STATUS_100BTX_FD 0x4000
163 #define LAN9370_BASIC_STATUS_100BTX_HD 0x2000
164 #define LAN9370_BASIC_STATUS_10BT_FD 0x1000
165 #define LAN9370_BASIC_STATUS_10BT_HD 0x0800
166 #define LAN9370_BASIC_STATUS_100BT2_FD 0x0400
167 #define LAN9370_BASIC_STATUS_100BT2_HD 0x0200
168 #define LAN9370_BASIC_STATUS_EXTENDED_STATUS 0x0100
169 #define LAN9370_BASIC_STATUS_UNIDIRECTIONAL_EN 0x0080
170 #define LAN9370_BASIC_STATUS_MF_PREAMBLE_SUPPR 0x0040
171 #define LAN9370_BASIC_STATUS_AN_COMPLETE 0x0020
172 #define LAN9370_BASIC_STATUS_REMOTE_FAULT 0x0010
173 #define LAN9370_BASIC_STATUS_AN_CAPABLE 0x0008
174 #define LAN9370_BASIC_STATUS_LINK_STATUS 0x0004
175 #define LAN9370_BASIC_STATUS_JABBER_DETECT 0x0002
176 #define LAN9370_BASIC_STATUS_EXTENDED_CAPABLE 0x0001
177 
178 //PHY Identifier 1 register
179 #define LAN9370_PHY_ID1_PHY_ID_MSB 0xFFFF
180 #define LAN9370_PHY_ID1_PHY_ID_MSB_DEFAULT 0x0007
181 
182 //PHY Identifier 2 register
183 #define LAN9370_PHY_ID2_PHY_ID_LSB 0xFC00
184 #define LAN9370_PHY_ID2_PHY_ID_LSB_DEFAULT 0xC000
185 #define LAN9370_PHY_ID2_MODEL_NUM 0x03F0
186 #define LAN9370_PHY_ID2_MODEL_NUM_DEFAULT 0x0180
187 #define LAN9370_PHY_ID2_REVISION_NUM 0x000F
188 
189 //Master/Slave Control register
190 #define LAN9370_MASTER_SLAVE_CONTROL_TEST_MODE 0xE000
191 #define LAN9370_MASTER_SLAVE_CONTROL_MS_MAN_CONF_EN 0x1000
192 #define LAN9370_MASTER_SLAVE_CONTROL_MS_MAN_CONF_VAL 0x0800
193 #define LAN9370_MASTER_SLAVE_CONTROL_PORT_TYPE 0x0400
194 #define LAN9370_MASTER_SLAVE_CONTROL_1000BT_FD 0x0200
195 #define LAN9370_MASTER_SLAVE_CONTROL_1000BT_HD 0x0100
196 
197 //Master/Slave Status register
198 #define LAN9370_MASTER_SLAVE_STATUS_MS_CONF_FAULT 0x8000
199 #define LAN9370_MASTER_SLAVE_STATUS_MS_CONF_RES 0x4000
200 #define LAN9370_MASTER_SLAVE_STATUS_LOC_RCVR_STATUS 0x2000
201 #define LAN9370_MASTER_SLAVE_STATUS_REM_RCVR_STATUS 0x1000
202 #define LAN9370_MASTER_SLAVE_STATUS_LP_1000BT_FD 0x0800
203 #define LAN9370_MASTER_SLAVE_STATUS_LP_1000BT_HD 0x0400
204 #define LAN9370_MASTER_SLAVE_STATUS_IDLE_ERR_COUNT 0x00FF
205 
206 //Extended Register Control register
207 #define LAN9370_EXT_REG_CTL_READ_CONTROL 0x1000
208 #define LAN9370_EXT_REG_CTL_WRITE_CONTROL 0x0800
209 #define LAN9370_EXT_REG_CTL_REGISTER_BANK 0x0700
210 #define LAN9370_EXT_REG_CTL_REGISTER_BANK_MISC 0x0100
211 #define LAN9370_EXT_REG_CTL_REGISTER_BANK_PCS 0x0200
212 #define LAN9370_EXT_REG_CTL_REGISTER_BANK_AFE 0x0300
213 #define LAN9370_EXT_REG_CTL_REGISTER_BANK_DSP 0x0400
214 #define LAN9370_EXT_REG_CTL_REGISTER_ADDR 0x00FF
215 
216 //Global Chip ID 0 register
217 #define LAN9370_CHIP_ID0_DEFAULT 0x00
218 
219 //Global Chip ID 1 register
220 #define LAN9370_CHIP_ID1_DEFAULT 0x93
221 
222 //Global Chip ID 2 register
223 #define LAN9370_CHIP_ID2_DEFAULT 0x70
224 
225 //Global Chip ID 3 register
226 #define LAN9370_CHIP_ID3_REVISION_ID 0xF0
227 
228 //Global Control 0 register
229 #define LAN9370_GLOBAL_CTRL0_APB_PHY_REG_BLK 0x80
230 #define LAN9370_GLOBAL_CTRL0_SW_INI_DONE 0x10
231 
232 //Switch Operation register
233 #define LAN9370_SWITCH_OP_DOUBLE_TAG_EN 0x80
234 #define LAN9370_SWITCH_OP_OVER_TEMP_ADJ 0x70
235 #define LAN9370_SWITCH_OP_OVER_TEMP_FORCE 0x08
236 #define LAN9370_SWITCH_OP_OVER_TEMP_EN 0x04
237 #define LAN9370_SWITCH_OP_SOFT_HARD_RESET 0x02
238 #define LAN9370_SWITCH_OP_START_SWITCH 0x01
239 
240 //Switch Lookup Engine Control 0 register
241 #define LAN9370_SWITCH_LUE_CTRL0_VLAN_EN 0x80
242 #define LAN9370_SWITCH_LUE_CTRL0_DROP_INVALID_VID 0x40
243 #define LAN9370_SWITCH_LUE_CTRL0_AGE_COUNT 0x38
244 #define LAN9370_SWITCH_LUE_CTRL0_AGE_COUNT_DEFAULT 0x20
245 #define LAN9370_SWITCH_LUE_CTRL0_RESERVED_LUE_EN 0x04
246 #define LAN9370_SWITCH_LUE_CTRL0_HASH_OPTION 0x03
247 #define LAN9370_SWITCH_LUE_CTRL0_HASH_OPTION_NONE 0x00
248 #define LAN9370_SWITCH_LUE_CTRL0_HASH_OPTION_CRC 0x01
249 #define LAN9370_SWITCH_LUE_CTRL0_HASH_OPTION_XOR 0x02
250 
251 //Switch Lookup Engine Control 1 register
252 #define LAN9370_SWITCH_LUE_CTRL1_UNICAST_LEARNING_DIS 0x80
253 #define LAN9370_SWITCH_LUE_CTRL1_SELF_ADDR_FILT 0x40
254 #define LAN9370_SWITCH_LUE_CTRL1_FLUSH_ALU_TABLE 0x20
255 #define LAN9370_SWITCH_LUE_CTRL1_FLUSH_MSTP_ENTRIES 0x10
256 #define LAN9370_SWITCH_LUE_CTRL1_SRC_ADDR_FILT 0x08
257 #define LAN9370_SWITCH_LUE_CTRL1_AGING_EN 0x04
258 #define LAN9370_SWITCH_LUE_CTRL1_FAST_AGE_EN 0x02
259 #define LAN9370_SWITCH_LUE_CTRL1_LINK_DOWN_FLUSH 0x01
260 
261 //Switch Lookup Engine Control 2 register
262 #define LAN9370_SWITCH_LUE_CTRL2_MID_RANGE_AGE 0x80
263 #define LAN9370_SWITCH_LUE_CTRL2_LINK_DOWN_FLUSH_ACTIVATED 0x40
264 #define LAN9370_SWITCH_LUE_CTRL2_DYNAMIC_EGRESS_VLAN_FILTERING 0x20
265 #define LAN9370_SWITCH_LUE_CTRL2_STATIC_EGRESS_VLAN_FILTERING 0x10
266 #define LAN9370_SWITCH_LUE_CTRL2_FLUSH_OPTION 0x0C
267 #define LAN9370_SWITCH_LUE_CTRL2_FLUSH_OPTION_NONE 0x00
268 #define LAN9370_SWITCH_LUE_CTRL2_FLUSH_OPTION_DYNAMIC 0x04
269 #define LAN9370_SWITCH_LUE_CTRL2_FLUSH_OPTION_STATIC 0x08
270 #define LAN9370_SWITCH_LUE_CTRL2_FLUSH_OPTION_BOTH 0x0C
271 #define LAN9370_SWITCH_LUE_CTRL2_ALU_PRIORITY_GEN 0x03
272 
273 //Global Switch Lookup Engine Control 3 register
274 #define LAN9370_SWITCH_LUE_CTRL3_AGE_PERIOD_7_0 0xFF
275 #define LAN9370_SWITCH_LUE_CTRL3_AGE_PERIOD_7_0_DEFAULT 0x4B
276 
277 //Global Switch LUE Age Period register
278 #define LAN9370_SWITCH_LUE_AGE_AGE_PERIOD_19_8 0x0FFF
279 #define LAN9370_SWITCH_LUE_AGE_AGE_PERIOD_19_8_DEFAULT 0x0000
280 
281 //Unknown Multicast Control register
282 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD 0x80000000
283 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP 0x0000001F
284 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_PORT1 0x00000001
285 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_PORT2 0x00000002
286 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_PORT3 0x00000004
287 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_PORT4 0x00000008
288 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_PORT5 0x00000010
289 #define LAN9370_UNKONWN_MULTICAST_CTRL_FWD_MAP_ALL 0x0000001F
290 
291 //Global Port Mirroring and Snooping Control register
292 #define LAN9370_GLOBAL_PORT_MIRROR_SNOOP_CTRL_IGMP_SNOOP_EN 0x40
293 #define LAN9370_GLOBAL_PORT_MIRROR_SNOOP_CTRL_MLD_SNOOP_OPT 0x08
294 #define LAN9370_GLOBAL_PORT_MIRROR_SNOOP_CTRL_MLD_SNOOP_EN 0x04
295 #define LAN9370_GLOBAL_PORT_MIRROR_SNOOP_CTRL_SNIFF_MODE_SEL 0x01
296 
297 //ALU Table Access Control register
298 #define LAN9370_ALU_TABLE_CTRL_VALID_COUNT 0x3FFF0000
299 #define LAN9370_ALU_TABLE_CTRL_START_FINISH 0x00000080
300 #define LAN9370_ALU_TABLE_CTRL_VALID 0x00000040
301 #define LAN9370_ALU_TABLE_CTRL_VALID_ENTRY_OR_SEARCH_END 0x00000020
302 #define LAN9370_ALU_TABLE_CTRL_DIRECT 0x00000004
303 #define LAN9370_ALU_TABLE_CTRL_ACTION 0x00000003
304 #define LAN9370_ALU_TABLE_CTRL_ACTION_NOP 0x00000000
305 #define LAN9370_ALU_TABLE_CTRL_ACTION_WRITE 0x00000001
306 #define LAN9370_ALU_TABLE_CTRL_ACTION_READ 0x00000002
307 #define LAN9370_ALU_TABLE_CTRL_ACTION_SEARCH 0x00000003
308 
309 //Static Address and Reserved Multicast Table Control register
310 #define LAN9370_STATIC_MCAST_TABLE_CTRL_VALID_COUNT 0x1FF00000
311 #define LAN9370_STATIC_MCAST_TABLE_CTRL_TABLE_INDEX 0x0000FF00
312 #define LAN9370_STATIC_MCAST_TABLE_CTRL_START_FINISH 0x00000080
313 #define LAN9370_STATIC_MCAST_TABLE_CTRL_VALID 0x00000040
314 #define LAN9370_STATIC_MCAST_TABLE_CTRL_VALID_ENTRY_OR_SEARCH_END 0x00000020
315 #define LAN9370_STATIC_MCAST_TABLE_CTRL_DIRECT_ACCESS 0x00000008
316 #define LAN9370_STATIC_MCAST_TABLE_CTRL_TABLE_SELECT 0x00000004
317 #define LAN9370_STATIC_MCAST_TABLE_CTRL_TABLE_SELECT_STATIC 0x00000000
318 #define LAN9370_STATIC_MCAST_TABLE_CTRL_TABLE_SELECT_RESERVED 0x00000004
319 #define LAN9370_STATIC_MCAST_TABLE_CTRL_ACTION 0x00000003
320 #define LAN9370_STATIC_MCAST_TABLE_CTRL_ACTION_NOP 0x00000000
321 #define LAN9370_STATIC_MCAST_TABLE_CTRL_ACTION_WRITE 0x00000001
322 #define LAN9370_STATIC_MCAST_TABLE_CTRL_ACTION_READ 0x00000002
323 #define LAN9370_STATIC_MCAST_TABLE_CTRL_ACTION_SEARCH 0x00000003
324 
325 //ALU Table Entry 1 register
326 #define LAN9370_ALU_TABLE_ENTRY1_STATIC 0x80000000
327 #define LAN9370_ALU_TABLE_ENTRY1_SRC_FILTER 0x40000000
328 #define LAN9370_ALU_TABLE_ENTRY1_DES_FILTER 0x20000000
329 #define LAN9370_ALU_TABLE_ENTRY1_PRIORITY 0x1C000000
330 #define LAN9370_ALU_TABLE_ENTRY1_AGE_COUNT 0x1C000000
331 #define LAN9370_ALU_TABLE_ENTRY1_MSTP 0x00000007
332 
333 //ALU Table Entry 2 register
334 #define LAN9370_ALU_TABLE_ENTRY2_OVERRIDE 0x80000000
335 #define LAN9370_ALU_TABLE_ENTRY2_PORT_FORWARD 0x0000001F
336 #define LAN9370_ALU_TABLE_ENTRY2_PORT5_FORWARD 0x00000010
337 #define LAN9370_ALU_TABLE_ENTRY2_PORT4_FORWARD 0x00000008
338 #define LAN9370_ALU_TABLE_ENTRY2_PORT3_FORWARD 0x00000004
339 #define LAN9370_ALU_TABLE_ENTRY2_PORT2_FORWARD 0x00000002
340 #define LAN9370_ALU_TABLE_ENTRY2_PORT1_FORWARD 0x00000001
341 
342 //ALU Table Entry 3 register
343 #define LAN9370_ALU_TABLE_ENTRY3_FID 0x007F0000
344 #define LAN9370_ALU_TABLE_ENTRY3_MAC_ADDR_MSB 0x0000FFFF
345 
346 //ALU Table Entry 4 register
347 #define LAN9370_ALU_TABLE_ENTRY4_MAC_ADDR_LSB 0xFFFFFFFF
348 
349 //Static Address Table Entry 1 register
350 #define LAN9370_STATIC_TABLE_ENTRY1_VALID 0x80000000
351 #define LAN9370_STATIC_TABLE_ENTRY1_SRC_FILTER 0x40000000
352 #define LAN9370_STATIC_TABLE_ENTRY1_DES_FILTER 0x20000000
353 #define LAN9370_STATIC_TABLE_ENTRY1_PRIORITY 0x1C000000
354 #define LAN9370_STATIC_TABLE_ENTRY1_MSTP 0x00000007
355 
356 //Static Address Table Entry 2 register
357 #define LAN9370_STATIC_TABLE_ENTRY2_OVERRIDE 0x80000000
358 #define LAN9370_STATIC_TABLE_ENTRY2_USE_FID 0x40000000
359 #define LAN9370_STATIC_TABLE_ENTRY2_PORT_FORWARD 0x0000001F
360 #define LAN9370_STATIC_TABLE_ENTRY2_PORT5_FORWARD 0x00000010
361 #define LAN9370_STATIC_TABLE_ENTRY2_PORT4_FORWARD 0x00000008
362 #define LAN9370_STATIC_TABLE_ENTRY2_PORT3_FORWARD 0x00000004
363 #define LAN9370_STATIC_TABLE_ENTRY2_PORT2_FORWARD 0x00000002
364 #define LAN9370_STATIC_TABLE_ENTRY2_PORT1_FORWARD 0x00000001
365 
366 //Static Address Table Entry 3 register
367 #define LAN9370_STATIC_TABLE_ENTRY3_FID 0x007F0000
368 #define LAN9370_STATIC_TABLE_ENTRY3_MAC_ADDR_MSB 0x0000FFFF
369 
370 //Static Address Table Entry 4 register
371 #define LAN9370_STATIC_TABLE_ENTRY4_MAC_ADDR_LSB 0xFFFFFFFF
372 
373 //Indirect Control register
374 #define LAN9370_IND_CTRL_OP 0x0002
375 #define LAN9370_IND_CTRL_OP_READ 0x0000
376 #define LAN9370_IND_CTRL_OP_WRITE 0x0002
377 #define LAN9370_IND_CTRL_BUSY 0x0001
378 
379 //Virtual PHY Special Control/Status register
380 #define LAN9370_VPHY_SPECIAL_CTRL_SMI_INDIRECT_EN 0x8000
381 #define LAN9370_VPHY_SPECIAL_CTRL_SW_LOOPBACK 0x4000
382 #define LAN9370_VPHY_SPECIAL_CTRL_MDIO_INT_EN 0x2000
383 #define LAN9370_VPHY_SPECIAL_CTRL_SPI_INDIRECT_EN 0x1000
384 #define LAN9370_VPHY_SPECIAL_CTRL_MODE 0x0300
385 #define LAN9370_VPHY_SPECIAL_CTRL_MODE_RGMII 0x0000
386 #define LAN9370_VPHY_SPECIAL_CTRL_MODE_MII_PHY 0x0100
387 #define LAN9370_VPHY_SPECIAL_CTRL_MODE_SGMII 0x0200
388 #define LAN9370_VPHY_SPECIAL_CTRL_MODE_RMII_PHY 0x0300
389 #define LAN9370_VPHY_SPECIAL_CTRL_SW_COL_TEST 0x0080
390 #define LAN9370_VPHY_SPECIAL_CTRL_SPEED_DUPLEX_IND 0x001C
391 #define LAN9370_VPHY_SPECIAL_CTRL_SPEED_DUPLEX_IND_10_HD 0x0004
392 #define LAN9370_VPHY_SPECIAL_CTRL_SPEED_DUPLEX_IND_100_HD 0x0008
393 #define LAN9370_VPHY_SPECIAL_CTRL_SPEED_DUPLEX_IND_10_FD 0x0014
394 #define LAN9370_VPHY_SPECIAL_CTRL_SPEED_DUPLEX_IND_100_FD 0x0018
395 
396 //Port N Operation Control 0 register
397 #define LAN9370_PORTn_OP_CTRL0_LOCAL_LOOPBACK 0x80
398 #define LAN9370_PORTn_OP_CTRL0_REMOTE_LOOPBACK 0x40
399 #define LAN9370_PORTn_OP_CTRL0_K2L_INSERT_EN 0x20
400 #define LAN9370_PORTn_OP_CTRL0_K2L_DEBUG_EN 0x10
401 #define LAN9370_PORTn_OP_CTRL0_TAIL_TAG_EN 0x04
402 #define LAN9370_PORTn_OP_CTRL0_TX_QUEUE_SPLIT_EN 0x03
403 
404 //Port N Status register
405 #define LAN9370_PORTn_STATUS_SPEED 0x18
406 #define LAN9370_PORTn_STATUS_SPEED_10MBPS 0x00
407 #define LAN9370_PORTn_STATUS_SPEED_100MBPS 0x08
408 #define LAN9370_PORTn_STATUS_SPEED_1000MBPS 0x10
409 #define LAN9370_PORTn_STATUS_DUPLEX 0x04
410 #define LAN9370_PORTn_STATUS_TX_FLOW_CTRL_EN 0x02
411 #define LAN9370_PORTn_STATUS_RX_FLOW_CTRL_EN 0x01
412 
413 //XMII Port N Control 0 register
414 #define LAN9370_PORTn_XMII_CTRL0_DUPLEX 0x40
415 #define LAN9370_PORTn_XMII_CTRL0_TX_FLOW_CTRL_EN 0x20
416 #define LAN9370_PORTn_XMII_CTRL0_SPEED_10_100 0x10
417 #define LAN9370_PORTn_XMII_CTRL0_RX_FLOW_CTRL_EN 0x08
418 #define LAN9370_PORTn_XMII_CTRL0_CRS_COL_EN 0x02
419 #define LAN9370_PORTn_XMII_CTRL0_AUTO_COL_DET 0x01
420 
421 //Port N XMII Control 1 register
422 #define LAN9370_PORTn_XMII_CTRL1_RGMII_SPEED_1000 0x40
423 #define LAN9370_PORTn_XMII_CTRL1_SEL_EDGE 0x20
424 #define LAN9370_PORTn_XMII_CTRL1_RGMII_ID_IG 0x10
425 #define LAN9370_PORTn_XMII_CTRL1_RGMII_ID_EG 0x08
426 #define LAN9370_PORTn_XMII_CTRL1_MII_RMII_MODE 0x04
427 #define LAN9370_PORTn_XMII_CTRL1_MII_INTF_SEL 0x03
428 #define LAN9370_PORTn_XMII_CTRL1_MII_INTF_SEL_RGMII 0x00
429 #define LAN9370_PORTn_XMII_CTRL1_MII_INTF_SEL_RMII 0x01
430 #define LAN9370_PORTn_XMII_CTRL1_MII_INTF_SEL_MII 0x03
431 
432 //Port N MAC Control 0 register
433 #define LAN9370_PORTn_MAC_CTRL0_FR_LEN_CHK 0x04
434 #define LAN9370_PORTn_MAC_CTRL0_BCAST_STORM_EN 0x02
435 #define LAN9370_PORTn_MAC_CTRL0_JUMBO_PKT_EN 0x01
436 
437 //Port N MSTP State register
438 #define LAN9370_PORTn_MSTP_STATE_TRANSMIT_EN 0x04
439 #define LAN9370_PORTn_MSTP_STATE_RECEIVE_EN 0x02
440 #define LAN9370_PORTn_MSTP_STATE_LEARNING_DIS 0x01
441 
442 //C++ guard
443 #ifdef __cplusplus
444 extern "C" {
445 #endif
446 
447 //LAN9370 Ethernet switch driver
448 extern const SwitchDriver lan9370SwitchDriver;
449 
450 //LAN9370 related functions
451 error_t lan9370Init(NetInterface *interface);
452 void lan9370InitHook(NetInterface *interface);
453 
454 void lan9370Tick(NetInterface *interface);
455 
456 void lan9370EnableIrq(NetInterface *interface);
457 void lan9370DisableIrq(NetInterface *interface);
458 
459 void lan9370EventHandler(NetInterface *interface);
460 
461 error_t lan9370TagFrame(NetInterface *interface, NetBuffer *buffer,
462  size_t *offset, NetTxAncillary *ancillary);
463 
464 error_t lan9370UntagFrame(NetInterface *interface, uint8_t **frame,
465  size_t *length, NetRxAncillary *ancillary);
466 
467 bool_t lan9370GetLinkState(NetInterface *interface, uint8_t port);
468 uint32_t lan9370GetLinkSpeed(NetInterface *interface, uint8_t port);
470 
471 void lan9370SetPortState(NetInterface *interface, uint8_t port,
472  SwitchPortState state);
473 
475 
476 void lan9370SetAgingTime(NetInterface *interface, uint32_t agingTime);
477 
478 void lan9370EnableIgmpSnooping(NetInterface *interface, bool_t enable);
479 void lan9370EnableMldSnooping(NetInterface *interface, bool_t enable);
480 void lan9370EnableRsvdMcastTable(NetInterface *interface, bool_t enable);
481 
483  const SwitchFdbEntry *entry);
484 
486  const SwitchFdbEntry *entry);
487 
489  SwitchFdbEntry *entry);
490 
492 
494  SwitchFdbEntry *entry);
495 
496 void lan9370FlushDynamicFdbTable(NetInterface *interface, uint8_t port);
497 
499  bool_t enable, uint32_t forwardPorts);
500 
501 void lan9370WritePhyReg(NetInterface *interface, uint8_t port,
502  uint8_t address, uint16_t data);
503 
504 uint16_t lan9370ReadPhyReg(NetInterface *interface, uint8_t port,
505  uint8_t address);
506 
507 void lan9370DumpPhyReg(NetInterface *interface, uint8_t port);
508 
509 void lan9370WriteExtReg(NetInterface *interface, uint8_t port, uint8_t bank,
510  uint8_t addr, uint16_t data);
511 
512 uint16_t lan9370ReadExtReg(NetInterface *interface, uint8_t port, uint8_t bank,
513  uint8_t addr);
514 
515 void lan9370WriteSwitchReg8(NetInterface *interface, uint16_t address,
516  uint8_t data);
517 
518 uint8_t lan9370ReadSwitchReg8(NetInterface *interface, uint16_t address);
519 
520 void lan9370WriteSwitchReg16(NetInterface *interface, uint16_t address,
521  uint16_t data);
522 
523 uint16_t lan9370ReadSwitchReg16(NetInterface *interface, uint16_t address);
524 
525 void lan9370WriteSwitchReg32(NetInterface *interface, uint16_t address,
526  uint32_t data);
527 
528 uint32_t lan9370ReadSwitchReg32(NetInterface *interface, uint16_t address);
529 
530 //C++ guard
531 #ifdef __cplusplus
532 }
533 #endif
534 
535 #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
Ipv6Addr address[]
Definition: ipv6.h:316
void lan9370WriteExtReg(NetInterface *interface, uint8_t port, uint8_t bank, uint8_t addr, uint16_t data)
Write extended register.
void lan9370FlushDynamicFdbTable(NetInterface *interface, uint8_t port)
Flush dynamic MAC table.
void lan9370EnableIgmpSnooping(NetInterface *interface, bool_t enable)
Enable IGMP snooping.
uint32_t lan9370ReadSwitchReg32(NetInterface *interface, uint16_t address)
Read switch register (32 bits)
void lan9370SetUnknownMcastFwdPorts(NetInterface *interface, bool_t enable, uint32_t forwardPorts)
Set forward ports for unknown multicast packets.
uint32_t lan9370GetLinkSpeed(NetInterface *interface, uint8_t port)
Get link speed.
uint16_t lan9370ReadPhyReg(NetInterface *interface, uint8_t port, uint8_t address)
Read PHY register.
void lan9370DisableIrq(NetInterface *interface)
Disable interrupts.
error_t lan9370UntagFrame(NetInterface *interface, uint8_t **frame, size_t *length, NetRxAncillary *ancillary)
Decode tail tag from incoming Ethernet frame.
SwitchPortState lan9370GetPortState(NetInterface *interface, uint8_t port)
Get port state.
uint16_t lan9370ReadExtReg(NetInterface *interface, uint8_t port, uint8_t bank, uint8_t addr)
Read extended register.
void lan9370WriteSwitchReg32(NetInterface *interface, uint16_t address, uint32_t data)
Write switch register (32 bits)
error_t lan9370Init(NetInterface *interface)
LAN9370 Ethernet switch initialization.
void lan9370Tick(NetInterface *interface)
LAN9370 timer handler.
void lan9370EventHandler(NetInterface *interface)
LAN9370 event handler.
error_t lan9370TagFrame(NetInterface *interface, NetBuffer *buffer, size_t *offset, NetTxAncillary *ancillary)
Add tail tag to Ethernet frame.
void lan9370WritePhyReg(NetInterface *interface, uint8_t port, uint8_t address, uint16_t data)
Write PHY register.
error_t lan9370GetStaticFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the static MAC table.
void lan9370SetPortState(NetInterface *interface, uint8_t port, SwitchPortState state)
Set port state.
void lan9370SetAgingTime(NetInterface *interface, uint32_t agingTime)
Set aging time for dynamic filtering entries.
uint8_t lan9370ReadSwitchReg8(NetInterface *interface, uint16_t address)
Read switch register (8 bits)
void lan9370EnableMldSnooping(NetInterface *interface, bool_t enable)
Enable MLD snooping.
void lan9370EnableIrq(NetInterface *interface)
Enable interrupts.
error_t lan9370AddStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Add a new entry to the static MAC table.
void lan9370EnableRsvdMcastTable(NetInterface *interface, bool_t enable)
Enable reserved multicast table.
bool_t lan9370GetLinkState(NetInterface *interface, uint8_t port)
Get link state.
uint16_t lan9370ReadSwitchReg16(NetInterface *interface, uint16_t address)
Read switch register (16 bits)
void lan9370WriteSwitchReg8(NetInterface *interface, uint16_t address, uint8_t data)
Write switch register (8 bits)
void lan9370InitHook(NetInterface *interface)
LAN9370 custom configuration.
NicDuplexMode lan9370GetDuplexMode(NetInterface *interface, uint8_t port)
Get duplex mode.
error_t lan9370GetDynamicFdbEntry(NetInterface *interface, uint_t index, SwitchFdbEntry *entry)
Read an entry from the dynamic MAC table.
void lan9370WriteSwitchReg16(NetInterface *interface, uint16_t address, uint16_t data)
Write switch register (16 bits)
error_t lan9370DeleteStaticFdbEntry(NetInterface *interface, const SwitchFdbEntry *entry)
Remove an entry from the static MAC table.
void lan9370FlushStaticFdbTable(NetInterface *interface)
Flush static MAC table.
void lan9370DumpPhyReg(NetInterface *interface, uint8_t port)
Dump PHY registers for debugging purpose.
const SwitchDriver lan9370SwitchDriver
LAN9370 Ethernet switch driver.
Ipv4Addr addr
Definition: nbns_common.h:123
#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
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