mimxrt1170_eth3_driver.h
Go to the documentation of this file.
1 /**
2  * @file mimxrt1170_eth3_driver.h
3  * @brief NXP i.MX RT1170 Gigabit Ethernet MAC driver (ENET_QOS instance)
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 _MIMXRT1170_ETH3_DRIVER_H
32 #define _MIMXRT1170_ETH3_DRIVER_H
33 
34 //Number of TX buffers
35 #ifndef MIMXRT1170_ETH3_TX_BUFFER_COUNT
36  #define MIMXRT1170_ETH3_TX_BUFFER_COUNT 8
37 #elif (MIMXRT1170_ETH3_TX_BUFFER_COUNT < 1)
38  #error MIMXRT1170_ETH3_TX_BUFFER_COUNT parameter is not valid
39 #endif
40 
41 //TX buffer size
42 #ifndef MIMXRT1170_ETH3_TX_BUFFER_SIZE
43  #define MIMXRT1170_ETH3_TX_BUFFER_SIZE 1536
44 #elif (MIMXRT1170_ETH3_TX_BUFFER_SIZE != 1536)
45  #error MIMXRT1170_ETH3_TX_BUFFER_SIZE parameter is not valid
46 #endif
47 
48 //Number of RX buffers
49 #ifndef MIMXRT1170_ETH3_RX_BUFFER_COUNT
50  #define MIMXRT1170_ETH3_RX_BUFFER_COUNT 8
51 #elif (MIMXRT1170_ETH3_RX_BUFFER_COUNT < 1)
52  #error MIMXRT1170_ETH3_RX_BUFFER_COUNT parameter is not valid
53 #endif
54 
55 //RX buffer size
56 #ifndef MIMXRT1170_ETH3_RX_BUFFER_SIZE
57  #define MIMXRT1170_ETH3_RX_BUFFER_SIZE 1536
58 #elif (MIMXRT1170_ETH3_RX_BUFFER_SIZE != 1536)
59  #error MIMXRT1170_ETH3_RX_BUFFER_SIZE parameter is not valid
60 #endif
61 
62 //Interrupt priority grouping
63 #ifndef MIMXRT1170_ETH3_IRQ_PRIORITY_GROUPING
64  #define MIMXRT1170_ETH3_IRQ_PRIORITY_GROUPING 3
65 #elif (MIMXRT1170_ETH3_IRQ_PRIORITY_GROUPING < 0)
66  #error MIMXRT1170_ETH3_IRQ_PRIORITY_GROUPING parameter is not valid
67 #endif
68 
69 //Ethernet interrupt group priority
70 #ifndef MIMXRT1170_ETH3_IRQ_GROUP_PRIORITY
71  #define MIMXRT1170_ETH3_IRQ_GROUP_PRIORITY 12
72 #elif (MIMXRT1170_ETH3_IRQ_GROUP_PRIORITY < 0)
73  #error MIMXRT1170_ETH3_IRQ_GROUP_PRIORITY parameter is not valid
74 #endif
75 
76 //Ethernet interrupt subpriority
77 #ifndef MIMXRT1170_ETH3_IRQ_SUB_PRIORITY
78  #define MIMXRT1170_ETH3_IRQ_SUB_PRIORITY 0
79 #elif (MIMXRT1170_ETH3_IRQ_SUB_PRIORITY < 0)
80  #error MIMXRT1170_ETH3_IRQ_SUB_PRIORITY parameter is not valid
81 #endif
82 
83 //Name of the section where to place DMA buffers
84 #ifndef MIMXRT1170_ETH3_RAM_SECTION
85  #define MIMXRT1170_ETH3_RAM_SECTION ".ram_no_cache"
86 #endif
87 
88 //Transmit normal descriptor (read format)
89 #define ENET_TDES0_BUF1AP 0xFFFFFFFF
90 #define ENET_TDES1_BUF2AP 0xFFFFFFFF
91 #define ENET_TDES2_IOC 0x80000000
92 #define ENET_TDES2_TTSE 0x40000000
93 #define ENET_TDES2_B2L 0x3FFF0000
94 #define ENET_TDES2_VTIR 0x0000C000
95 #define ENET_TDES2_B1L 0x00003FFF
96 #define ENET_TDES3_OWN 0x80000000
97 #define ENET_TDES3_CTXT 0x40000000
98 #define ENET_TDES3_FD 0x20000000
99 #define ENET_TDES3_LD 0x10000000
100 #define ENET_TDES3_CPC 0x0C000000
101 #define ENET_TDES3_SAIC 0x03800000
102 #define ENET_TDES3_SLOTNUM_THL 0x00780000
103 #define ENET_TDES3_TSE 0x00040000
104 #define ENET_TDES3_CIC 0x00030000
105 #define ENET_TDES3_FL 0x00007FFF
106 #define ENET_TDES3_TPL 0w0003FFFF
107 
108 //Transmit normal descriptor (write-back format)
109 #define ENET_TDES0_TTSL 0xFFFFFFFF
110 #define ENET_TDES1_TTSH 0xFFFFFFFF
111 #define ENET_TDES3_OWN 0x80000000
112 #define ENET_TDES3_CTXT 0x40000000
113 #define ENET_TDES3_FD 0x20000000
114 #define ENET_TDES3_LD 0x10000000
115 #define ENET_TDES3_TTSS 0x00020000
116 #define ENET_TDES3_ES 0x00008000
117 #define ENET_TDES3_JT 0x00004000
118 #define ENET_TDES3_FF 0x00002000
119 #define ENET_TDES3_PCE 0x00001000
120 #define ENET_TDES3_LOC 0x00000800
121 #define ENET_TDES3_NC 0x00000400
122 #define ENET_TDES3_LC 0x00000200
123 #define ENET_TDES3_EC 0x00000100
124 #define ENET_TDES3_CC 0x000000F0
125 #define ENET_TDES3_ED 0x00000008
126 #define ENET_TDES3_UF 0x00000004
127 #define ENET_TDES3_DB 0x00000002
128 #define ENET_TDES3_IHE 0x00000001
129 
130 //Transmit context descriptor
131 #define ENET_TDES0_TTSL 0xFFFFFFFF
132 #define ENET_TDES1_TTSH 0xFFFFFFFF
133 #define ENET_TDES2_IVT 0xFFFF0000
134 #define ENET_TDES2_MSS 0x00003FFF
135 #define ENET_TDES3_OWN 0x80000000
136 #define ENET_TDES3_CTXT 0x40000000
137 #define ENET_TDES3_OSTC 0x08000000
138 #define ENET_TDES3_TCMSSV 0x04000000
139 #define ENET_TDES3_CDE 0x00800000
140 #define ENET_TDES3_IVLTV 0x00020000
141 #define ENET_TDES3_VLTV 0x00010000
142 #define ENET_TDES3_VT 0x0000FFFF
143 
144 //Receive normal descriptor (read format)
145 #define ENET_RDES0_BUF1AP 0xFFFFFFFF
146 #define ENET_RDES2_BUF2AP 0xFFFFFFFF
147 #define ENET_RDES3_OWN 0x80000000
148 #define ENET_RDES3_IOC 0x40000000
149 #define ENET_RDES3_BUF2V 0x02000000
150 #define ENET_RDES3_BUF1V 0x01000000
151 
152 //Receive normal descriptor (write-back format)
153 #define ENET_RDES0_IVT 0xFFFF0000
154 #define ENET_RDES0_OVT 0x0000FFFF
155 #define ENET_RDES1_OPC 0xFFFF0000
156 #define ENET_RDES1_TD 0x00008000
157 #define ENET_RDES1_TSA 0x00004000
158 #define ENET_RDES1_PV 0x00002000
159 #define ENET_RDES1_PFT 0x00001000
160 #define ENET_RDES1_PMT 0x00000F00
161 #define ENET_RDES1_IPCE 0x00000080
162 #define ENET_RDES1_IPCB 0x00000040
163 #define ENET_RDES1_IPV6 0x00000020
164 #define ENET_RDES1_IPV4 0x00000010
165 #define ENET_RDES1_IPHE 0x00000008
166 #define ENET_RDES1_PT 0x00000007
167 #define ENET_RDES2_L3L4FM 0xE0000000
168 #define ENET_RDES2_L4FM 0x10000000
169 #define ENET_RDES2_L3FM 0x08000000
170 #define ENET_RDES2_MADRM 0x07F80000
171 #define ENET_RDES2_HF 0x00040000
172 #define ENET_RDES2_DAF 0x00020000
173 #define ENET_RDES2_SAF 0x00010000
174 #define ENET_RDES2_OTS 0x00008000
175 #define ENET_RDES2_ITS 0x00004000
176 #define ENET_RDES2_ARPRN 0x00000400
177 #define ENET_RDES2_HL 0x000003FF
178 #define ENET_RDES3_OWN 0x80000000
179 #define ENET_RDES3_CTXT 0x40000000
180 #define ENET_RDES3_FD 0x20000000
181 #define ENET_RDES3_LD 0x10000000
182 #define ENET_RDES3_RS2V 0x08000000
183 #define ENET_RDES3_RS1V 0x04000000
184 #define ENET_RDES3_RS0V 0x02000000
185 #define ENET_RDES3_CE 0x01000000
186 #define ENET_RDES3_GP 0x00800000
187 #define ENET_RDES3_RWT 0x00400000
188 #define ENET_RDES3_OE 0x00200000
189 #define ENET_RDES3_RE 0x00100000
190 #define ENET_RDES3_DE 0x00080000
191 #define ENET_RDES3_LT 0x00070000
192 #define ENET_RDES3_ES 0x00008000
193 #define ENET_RDES3_PL 0x00007FFF
194 
195 //Receive context descriptor
196 #define ENET_RDES0_RTSL 0xFFFFFFFF
197 #define ENET_RDES1_RTSH 0xFFFFFFFF
198 #define ENET_RDES3_OWN 0x80000000
199 #define ENET_RDES3_CTXT 0x40000000
200 
201 //C++ guard
202 #ifdef __cplusplus
203 extern "C" {
204 #endif
205 
206 
207 /**
208  * @brief Transmit descriptor
209  **/
210 
211 typedef struct
212 {
213  uint32_t tdes0;
214  uint32_t tdes1;
215  uint32_t tdes2;
216  uint32_t tdes3;
218 
219 
220 /**
221  * @brief Receive descriptor
222  **/
223 
224 typedef struct
225 {
226  uint32_t rdes0;
227  uint32_t rdes1;
228  uint32_t rdes2;
229  uint32_t rdes3;
231 
232 
233 //i.MX RT1170 Ethernet MAC driver (ENET_QOS instance)
234 extern const NicDriver mimxrt1170Eth3Driver;
235 
236 //i.MX RT1170 Ethernet MAC related functions
238 void mimxrt1170Eth3InitGpio(NetInterface *interface);
239 void mimxrt1170Eth3InitDmaDesc(NetInterface *interface);
240 
241 void mimxrt1170Eth3Tick(NetInterface *interface);
242 
243 void mimxrt1170Eth3EnableIrq(NetInterface *interface);
244 void mimxrt1170Eth3DisableIrq(NetInterface *interface);
246 
248  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
249 
251 
254 
255 void mimxrt1170Eth3WritePhyReg(uint8_t opcode, uint8_t phyAddr,
256  uint8_t regAddr, uint16_t data);
257 
258 uint16_t mimxrt1170Eth3ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
259  uint8_t regAddr);
260 
261 //C++ guard
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif
void mimxrt1170Eth3Tick(NetInterface *interface)
i.MX RT1170 Ethernet MAC timer handler
uint8_t opcode
Definition: dns_common.h:188
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:222
error_t mimxrt1170Eth3Init(NetInterface *interface)
i.MX RT1170 Ethernet MAC initialization
void mimxrt1170Eth3InitDmaDesc(NetInterface *interface)
Initialize buffer descriptors.
error_t mimxrt1170Eth3UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
const NicDriver mimxrt1170Eth3Driver
i.MX RT1170 Ethernet MAC driver (ENET_QOS instance)
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
error_t mimxrt1170Eth3ReceivePacket(NetInterface *interface)
Receive a packet.
void mimxrt1170Eth3InitGpio(NetInterface *interface)
GPIO configuration.
uint16_t mimxrt1170Eth3ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
error_t mimxrt1170Eth3SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void mimxrt1170Eth3DisableIrq(NetInterface *interface)
Disable interrupts.
uint16_t regAddr
void mimxrt1170Eth3WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void mimxrt1170Eth3EventHandler(NetInterface *interface)
i.MX RT1170 Ethernet MAC event handler
void mimxrt1170Eth3EnableIrq(NetInterface *interface)
Enable interrupts.
NIC driver.
Definition: nic.h:286
error_t mimxrt1170Eth3UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.