am64x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file am64x_eth_driver.h
3  * @brief AM64x Ethernet MAC 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 _AM64X_ETH_DRIVER_H
32 #define _AM64X_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //CPSW ports
38 #define CPSW_PORT0 0
39 #define CPSW_PORT1 1
40 #define CPSW_PORT2 2
41 
42 //CPSW channels
43 #define CPSW_CH0 0
44 #define CPSW_CH1 1
45 #define CPSW_CH2 2
46 #define CPSW_CH3 3
47 #define CPSW_CH4 4
48 #define CPSW_CH5 5
49 #define CPSW_CH6 6
50 #define CPSW_CH7 7
51 
52 //Number of entries in the ALE table
53 #define CPSW_ALE_MAX_ENTRIES 512
54 
55 //ALE table entry
56 #define CPSW_ALE_WORD1_ENTRY_TYPE_MASK (3 << 28)
57 #define CPSW_ALE_WORD1_ENTRY_TYPE_FREE (0 << 28)
58 #define CPSW_ALE_WORD1_ENTRY_TYPE_ADDR (1 << 28)
59 #define CPSW_ALE_WORD1_ENTRY_TYPE_VLAN (2 << 28)
60 #define CPSW_ALE_WORD1_ENTRY_TYPE_VLAN_ADDR (3 << 28)
61 #define CPSW_ALE_WORD1_MULTICAST (1 << 8)
62 
63 //Unicast address table entry
64 #define CPSW_ALE_WORD2_TRUNK (1 << 4)
65 #define CPSW_ALE_WORD2_PORT_NUMBER_MASK (3 << 2)
66 #define CPSW_ALE_WORD2_PORT_NUMBER(n) ((n) << 2)
67 #define CPSW_ALE_WORD2_BLOCK (1 << 1)
68 #define CPSW_ALE_WORD2_SECURE (1 << 0)
69 #define CPSW_ALE_WORD1_UNICAST_TYPE_MASK (3 << 30)
70 #define CPSW_ALE_WORD1_UNICAST_TYPE(n) ((n) << 30)
71 
72 //Multicast address table entry
73 #define CPSW_ALE_WORD2_PORT_MASK_MASK (3 << 2)
74 #define CPSW_ALE_WORD2_PORT_MASK(n) ((n) << 2)
75 #define CPSW_ALE_WORD2_SUPER (1 << 1)
76 #define CPSW_ALE_WORD1_MCAST_FWD_STATE_MASK (3 << 30)
77 #define CPSW_ALE_WORD1_MCAST_FWD_STATE(n) ((n) << 30)
78 
79 //VLAN table entry
80 #define CPSW_ALE_WORD2_NO_LEARN_MASK_MASK (7 << 2)
81 #define CPSW_ALE_WORD2_NO_LEARN_MASK(n) ((n) << 2)
82 #define CPSW_ALE_WORD2_VLAN_FORCE_INGRESS_CHECK (7 << 1)
83 #define CPSW_ALE_WORD1_VLAN_ID_MASK (4095 << 16)
84 #define CPSW_ALE_WORD1_VLAN_ID(n) ((n) << 16)
85 #define CPSW_ALE_WORD1_NOFRAG (1 << 15)
86 #define CPSW_ALE_WORD1_REG_MCAST_FLOOD_INDEX_MASK (7 << 4)
87 #define CPSW_ALE_WORD1_REG_MCAST_FLOOD_INDEX(n) ((n) << 4)
88 #define CPSW_ALE_WORD0_FORCE_UNTAG_EGRESS_MASK (7 << 24)
89 #define CPSW_ALE_WORD0_FORCE_UNTAG_EGRESS(n) ((n) << 24)
90 #define CPSW_ALE_WORD0_LMTNXTHDR (1 << 23)
91 #define CPSW_ALE_WORD0_UREGMSK_MASK (7 << 12)
92 #define CPSW_ALE_WORD0_UREGMSK(n) ((n) << 12)
93 #define CPSW_ALE_WORD0_VLAN_MEMBER_LIST_MASK (7 << 0)
94 #define CPSW_ALE_WORD0_VLAN_MEMBER_LIST(n) ((n) << 0)
95 
96 //C++ guard
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
100 
101 
102 /**
103  * @brief ALE table entry
104  **/
105 
106 typedef struct
107 {
108  uint32_t word2;
109  uint32_t word1;
110  uint32_t word0;
111 } Am64xAleEntry;
112 
113 
114 /**
115  * @brief Enhanced TX DMA descriptor
116  **/
117 
118 typedef struct
119 {
120  uint32_t tdes0;
121  uint32_t tdes1;
122  uint32_t tdes2;
123  uint32_t tdes3;
124  uint32_t tdes4;
125  uint32_t tdes5;
126  uint32_t tdes6;
127  uint32_t tdes7;
129 
130 
131 /**
132  * @brief Enhanced RX DMA descriptor
133  **/
134 
135 typedef struct
136 {
137  uint32_t rdes0;
138  uint32_t rdes1;
139  uint32_t rdes2;
140  uint32_t rdes3;
141  uint32_t rdes4;
142  uint32_t rdes5;
143  uint32_t rdes6;
144  uint32_t rdes7;
146 
147 
148 //AM64x Ethernet MAC driver
149 extern const NicDriver am64xEthPort1Driver;
150 extern const NicDriver am64xEthPort2Driver;
151 
152 //AM64x Ethernet MAC related functions
155 void am64xEthInitInstance(NetInterface *interface);
156 void am64xEthInitGpio(NetInterface *interface);
157 
158 void am64xEthTick(NetInterface *interface);
159 
160 void am64xEthEnableIrq(NetInterface *interface);
161 void am64xEthDisableIrq(NetInterface *interface);
162 void am64xEthRxIrqHandler(void *arg);
163 void am64xEthEventHandler(NetInterface *interface);
164 
166  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
167 
170 
171 void am64xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
172  uint8_t regAddr, uint16_t data);
173 
174 uint16_t am64xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
175  uint8_t regAddr);
176 
177 void am64xEthWriteEntry(uint_t index, const Am64xAleEntry *entry);
178 void am64xEthReadEntry(uint_t index, Am64xAleEntry *entry);
179 
183 
187 
188 //C++ guard
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif
error_t am64xEthInitPort2(NetInterface *interface)
AM64x Ethernet MAC initialization (port 2)
const NicDriver am64xEthPort2Driver
AM64x Ethernet MAC driver (port2)
uint_t am64xEthFindVlanEntry(uint_t vlanId)
Search the ALE table for the specified VLAN entry.
void am64xEthReadEntry(uint_t index, Am64xAleEntry *entry)
Read an ALE table entry.
uint16_t am64xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void am64xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void am64xEthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t am64xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
error_t am64xEthAddVlanEntry(uint_t port, uint_t vlanId)
Add a VLAN entry in the ALE table.
void am64xEthInitGpio(NetInterface *interface)
GPIO configuration.
void am64xEthTick(NetInterface *interface)
AM64x Ethernet MAC timer handler.
void am64xEthInitInstance(NetInterface *interface)
Initialize CPSW instance.
void am64xEthEventHandler(NetInterface *interface)
AM64x Ethernet MAC event handler.
void am64xEthWriteEntry(uint_t index, const Am64xAleEntry *entry)
Write an ALE table entry.
error_t am64xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
uint_t am64xEthFindFreeEntry(void)
Find a free entry in the ALE table.
error_t am64xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
uint_t am64xEthFindVlanAddrEntry(uint_t vlanId, MacAddr *macAddr)
Search the ALE table for the specified VLAN/address entry.
void am64xEthEnableIrq(NetInterface *interface)
Enable interrupts.
const NicDriver am64xEthPort1Driver
AM64x Ethernet MAC driver (port1)
error_t am64xEthInitPort1(NetInterface *interface)
AM64x Ethernet MAC initialization (port 1)
error_t am64xEthAddVlanAddrEntry(uint_t port, uint_t vlanId, MacAddr *macAddr)
Add a VLAN/address entry in the ALE table.
error_t am64xEthDeleteVlanAddrEntry(uint_t port, uint_t vlanId, MacAddr *macAddr)
Remove a VLAN/address entry from the ALE table.
void am64xEthRxIrqHandler(void *arg)
AM64x Ethernet MAC receive interrupt.
unsigned int uint_t
Definition: compiler_port.h:50
uint8_t opcode
Definition: dns_common.h:188
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
uint16_t regAddr
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
Network interface controller abstraction layer.
ALE table entry.
Enhanced RX DMA descriptor.
Enhanced TX DMA descriptor.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
NIC driver.
Definition: nic.h:283