tc3xx_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file tc3xx_eth_driver.h
3  * @brief Infineon AURIX TriCore TC3xx 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.4
29  **/
30 
31 #ifndef _TC3XX_ETH_DRIVER_H
32 #define _TC3XX_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef TC3XX_ETH_TX_BUFFER_COUNT
39  #define TC3XX_ETH_TX_BUFFER_COUNT 3
40 #elif (TC3XX_ETH_TX_BUFFER_COUNT < 1)
41  #error TC3XX_ETH_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef TC3XX_ETH_TX_BUFFER_SIZE
46  #define TC3XX_ETH_TX_BUFFER_SIZE 1536
47 #elif (TC3XX_ETH_TX_BUFFER_SIZE != 1536)
48  #error TC3XX_ETH_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef TC3XX_ETH_RX_BUFFER_COUNT
53  #define TC3XX_ETH_RX_BUFFER_COUNT 6
54 #elif (TC3XX_ETH_RX_BUFFER_COUNT < 1)
55  #error TC3XX_ETH_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef TC3XX_ETH_RX_BUFFER_SIZE
60  #define TC3XX_ETH_RX_BUFFER_SIZE 1536
61 #elif (TC3XX_ETH_RX_BUFFER_SIZE != 1536)
62  #error TC3XX_ETH_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Ethernet interrupt priority
66 #ifndef TC3XX_ETH_IRQ_PRIORITY
67  #define TC3XX_ETH_IRQ_PRIORITY 10
68 #elif (TC3XX_ETH_IRQ_PRIORITY < 0)
69  #error TC3XX_ETH_IRQ_PRIORITY parameter is not valid
70 #endif
71 
72 //DMA_CH_STATUS register
73 #define ETH_DMA_CH_STATUS_REB 0x00380000
74 #define ETH_DMA_CH_STATUS_TEB 0x00070000
75 #define ETH_DMA_CH_STATUS_NIS 0x00008000
76 #define ETH_DMA_CH_STATUS_AIS 0x00004000
77 #define ETH_DMA_CH_STATUS_CDE 0x00002000
78 #define ETH_DMA_CH_STATUS_FBE 0x00001000
79 #define ETH_DMA_CH_STATUS_ERI 0x00000800
80 #define ETH_DMA_CH_STATUS_ETI 0x00000400
81 #define ETH_DMA_CH_STATUS_RWT 0x00000200
82 #define ETH_DMA_CH_STATUS_RPS 0x00000100
83 #define ETH_DMA_CH_STATUS_RBU 0x00000080
84 #define ETH_DMA_CH_STATUS_RI 0x00000040
85 #define ETH_DMA_CH_STATUS_TBU 0x00000004
86 #define ETH_DMA_CH_STATUS_TPS 0x00000002
87 #define ETH_DMA_CH_STATUS_TI 0x00000001
88 
89 //DMA_CH_INTERRUPT_ENABLE register
90 #define ETH_DMA_CH_INTERRUPT_ENABLE_NIE 0x00008000
91 #define ETH_DMA_CH_INTERRUPT_ENABLE_AIE 0x00004000
92 #define ETH_DMA_CH_INTERRUPT_ENABLE_CDEE 0x00002000
93 #define ETH_DMA_CH_INTERRUPT_ENABLE_FBEE 0x00001000
94 #define ETH_DMA_CH_INTERRUPT_ENABLE_ERIE 0x00000800
95 #define ETH_DMA_CH_INTERRUPT_ENABLE_ETIE 0x00000400
96 #define ETH_DMA_CH_INTERRUPT_ENABLE_RWTE 0x00000200
97 #define ETH_DMA_CH_INTERRUPT_ENABLE_RSE 0x00000100
98 #define ETH_DMA_CH_INTERRUPT_ENABLE_RBUE 0x00000080
99 #define ETH_DMA_CH_INTERRUPT_ENABLE_RIE 0x00000040
100 #define ETH_DMA_CH_INTERRUPT_ENABLE_TBUE 0x00000004
101 #define ETH_DMA_CH_INTERRUPT_ENABLE_TXSE 0x00000002
102 #define ETH_DMA_CH_INTERRUPT_ENABLE_TIE 0x00000001
103 
104 //MAC_ADDRESSi_HIGH register
105 #define ETH_MAC_ADDRESS_HIGH_AE 0x80000000
106 #define ETH_MAC_ADDRESS_HIGH_SA 0x40000000
107 #define ETH_MAC_ADDRESS_HIGH_MBC 0x3F000000
108 #define ETH_MAC_ADDRESS_HIGH_DCS 0x00030000
109 #define ETH_MAC_ADDRESS_HIGH_ADDRHI 0x0000FFFF
110 
111 //Transmit normal descriptor (read format)
112 #define ETH_TDES0_BUF1AP 0xFFFFFFFF
113 #define ETH_TDES1_BUF2AP 0xFFFFFFFF
114 #define ETH_TDES2_IOC 0x80000000
115 #define ETH_TDES2_TTSE 0x40000000
116 #define ETH_TDES2_B2L 0x3FFF0000
117 #define ETH_TDES2_B1L 0x00003FFF
118 #define ETH_TDES3_OWN 0x80000000
119 #define ETH_TDES3_CTXT 0x40000000
120 #define ETH_TDES3_FD 0x20000000
121 #define ETH_TDES3_LD 0x10000000
122 #define ETH_TDES3_CPC 0x0C000000
123 #define ETH_TDES3_SLOTNUM 0x00780000
124 #define ETH_TDES3_CIC 0x00030000
125 #define ETH_TDES3_FL 0x00007FFF
126 
127 //Transmit normal descriptor (write-back format)
128 #define ETH_TDES0_TTSL 0xFFFFFFFF
129 #define ETH_TDES1_TTSH 0xFFFFFFFF
130 #define ETH_TDES3_OWN 0x80000000
131 #define ETH_TDES3_CTXT 0x40000000
132 #define ETH_TDES3_FD 0x20000000
133 #define ETH_TDES3_LD 0x10000000
134 #define ETH_TDES3_TTSS 0x00020000
135 #define ETH_TDES3_ES 0x00008000
136 #define ETH_TDES3_JT 0x00004000
137 #define ETH_TDES3_FF 0x00002000
138 #define ETH_TDES3_PCE 0x00001000
139 #define ETH_TDES3_LOC 0x00000800
140 #define ETH_TDES3_NC 0x00000400
141 #define ETH_TDES3_LC 0x00000200
142 #define ETH_TDES3_EC 0x00000100
143 #define ETH_TDES3_CC 0x000000F0
144 #define ETH_TDES3_ED 0x00000008
145 #define ETH_TDES3_UF 0x00000004
146 #define ETH_TDES3_DB 0x00000002
147 #define ETH_TDES3_IHE 0x00000001
148 
149 //Receive normal descriptor (read format)
150 #define ETH_RDES0_BUF1AP 0xFFFFFFFF
151 #define ETH_RDES2_BUF2AP 0xFFFFFFFF
152 #define ETH_RDES3_OWN 0x80000000
153 #define ETH_RDES3_IOC 0x40000000
154 #define ETH_RDES3_BUF2V 0x02000000
155 #define ETH_RDES3_BUF1V 0x01000000
156 
157 //Receive normal descriptor (write-back format)
158 #define ETH_RDES1_OPC 0xFFFF0000
159 #define ETH_RDES1_TD 0x00008000
160 #define ETH_RDES1_TSA 0x00004000
161 #define ETH_RDES1_PV 0x00002000
162 #define ETH_RDES1_PFT 0x00001000
163 #define ETH_RDES1_PMT 0x00000F00
164 #define ETH_RDES1_IPCE 0x00000080
165 #define ETH_RDES1_IPCB 0x00000040
166 #define ETH_RDES1_IPV6 0x00000020
167 #define ETH_RDES1_IPV4 0x00000010
168 #define ETH_RDES1_IPHE 0x00000008
169 #define ETH_RDES1_PT 0x00000007
170 #define ETH_RDES2_MADRM 0x07F80000
171 #define ETH_RDES2_DAF 0x00020000
172 #define ETH_RDES2_SAF 0x00010000
173 #define ETH_RDES3_OWN 0x80000000
174 #define ETH_RDES3_CTXT 0x40000000
175 #define ETH_RDES3_FD 0x20000000
176 #define ETH_RDES3_LD 0x10000000
177 #define ETH_RDES3_RS2V 0x08000000
178 #define ETH_RDES3_RS1V 0x04000000
179 #define ETH_RDES3_RS0V 0x02000000
180 #define ETH_RDES3_CE 0x01000000
181 #define ETH_RDES3_GP 0x00800000
182 #define ETH_RDES3_RWT 0x00400000
183 #define ETH_RDES3_OE 0x00200000
184 #define ETH_RDES3_RE 0x00100000
185 #define ETH_RDES3_DE 0x00080000
186 #define ETH_RDES3_LT 0x00070000
187 #define ETH_RDES3_ES 0x00008000
188 #define ETH_RDES3_PL 0x00007FFF
189 
190 //Get CPU core identifier
191 #define ETH_CPU_ID() (_mfcr(CPU_CORE_ID) & IFX_CPU_CORE_ID_CORE_ID_MSK)
192 
193 //Convert a local DSPR address to a global DSPR address
194 #define ETH_GLOBAL_DSPR_ADDR(address) \
195  ((((uint32_t) (address) & 0xF0000000) == 0xD0000000) ? \
196  ((((uint32_t) (address) & 0x000FFFFF) | 0x70000000) - (ETH_CPU_ID() * 0x10000000)) : \
197  (uint32_t) (address))
198 
199 //C++ guard
200 #ifdef __cplusplus
201 extern "C" {
202 #endif
203 
204 
205 /**
206  * @brief Transmit DMA descriptor
207  **/
208 
209 typedef struct
210 {
211  uint32_t tdes0;
212  uint32_t tdes1;
213  uint32_t tdes2;
214  uint32_t tdes3;
216 
217 
218 /**
219  * @brief Receive DMA descriptor
220  **/
221 
222 typedef struct
223 {
224  uint32_t rdes0;
225  uint32_t rdes1;
226  uint32_t rdes2;
227  uint32_t rdes3;
229 
230 
231 //TC3xx Ethernet MAC driver
232 extern const NicDriver tc3xxEthDriver;
233 
234 //TC3xx Ethernet MAC related functions
235 error_t tc3xxEthInit(NetInterface *interface);
236 void tc3xxEthInitGpio(NetInterface *interface);
237 void tc3xxEthInitDmaDesc(NetInterface *interface);
238 
239 void tc3xxEthTick(NetInterface *interface);
240 
241 void tc3xxEthEnableIrq(NetInterface *interface);
242 void tc3xxEthDisableIrq(NetInterface *interface);
243 void tc3xxEthIrqHandler(int_t arg);
244 void tc3xxEthEventHandler(NetInterface *interface);
245 
247  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
248 
250 
253 
254 void tc3xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
255  uint8_t regAddr, uint16_t data);
256 
257 uint16_t tc3xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
258  uint8_t regAddr);
259 
260 //C++ guard
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif
Receive DMA descriptor.
uint8_t opcode
Definition: dns_common.h:188
uint16_t tc3xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
signed int int_t
Definition: compiler_port.h:49
void tc3xxEthTick(NetInterface *interface)
TC3xx Ethernet MAC timer handler.
error_t tc3xxEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:222
void tc3xxEthIrqHandler(int_t arg)
TC3xx Ethernet MAC interrupt service routine.
Transmit DMA descriptor.
error_t tc3xxEthReceivePacket(NetInterface *interface)
Receive a packet.
error_t
Error codes.
Definition: error.h:43
void tc3xxEthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
void tc3xxEthInitGpio(NetInterface *interface)
GPIO configuration.
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
error_t tc3xxEthInit(NetInterface *interface)
TC3xx Ethernet MAC initialization.
void tc3xxEthEnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t regAddr
Network interface controller abstraction layer.
void tc3xxEthEventHandler(NetInterface *interface)
TC3xx Ethernet MAC event handler.
void tc3xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
const NicDriver tc3xxEthDriver
TC3xx Ethernet MAC driver.
error_t tc3xxEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
NIC driver.
Definition: nic.h:286
void tc3xxEthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t tc3xxEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.