AM263Px MCU+ SDK: enet_types.h Source File

| AM263Px MCU+ SDK 26.00.00 |

enet_types.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) Texas Instruments Incorporated 2020
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
45 #ifndef ENET_TYPES_H_
46 #define ENET_TYPES_H_
47
48 /* ========================================================================== */
49 /* Include Files */
50 /* ========================================================================== */
51
52 #include <stdint.h>
53 #include <stdbool.h>
54 #include <drivers/hw_include/csl_types.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /* ========================================================================== */
61 /* Macros */
62 /* ========================================================================== */
63
73 /* Enet driver error codes are same as CSL's to maintain consistency */
74
76 #define ENET_SOK (CSL_PASS)
77
79 #define ENET_SINPROGRESS (1)
80
82 #define ENET_EFAIL (CSL_EFAIL)
83
85 #define ENET_EBADARGS (CSL_EBADARGS)
86
88 #define ENET_EINVALIDPARAMS (CSL_EINVALID_PARAMS)
89
91 #define ENET_ETIMEOUT (CSL_ETIMEOUT)
92
94 #define ENET_EALLOC (CSL_EALLOC)
95
97 #define ENET_EUNEXPECTED (CSL_EALLOC - 1)
98
100 #define ENET_EBUSY (CSL_EALLOC - 2)
101
103 #define ENET_EALREADYOPEN (CSL_EALLOC - 3)
104
106 #define ENET_EPERM (CSL_EALLOC - 4)
107
109 #define ENET_ENOTSUPPORTED (CSL_EALLOC - 5)
110
112 #define ENET_ENOTFOUND (CSL_EALLOC - 6)
113
115 #define ENET_EUNKNOWNIOCTL (CSL_EALLOC - 7)
116
118 #define ENET_EMALFORMEDIOCTL (CSL_EALLOC - 8)
119
123 #define ENET_ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
124
126 #define ENET_BIT(n) (1U << (n))
127
129 #define ENET_GET_BIT(val, n) (((val) & ENET_BIT(n)) >> (n))
130
132 #define ENET_IS_BIT_SET(val, n) (((val) & ENET_BIT(n)) != 0U)
133
135 #define ENET_NOT_ZERO(val) ((uint32_t)0U != (uint32_t)(val))
136
138 #define ENET_FEXT(reg, PER_REG_FIELD) \
139 (((reg) & PER_REG_FIELD##_MASK) >> PER_REG_FIELD##_SHIFT)
140
142 #define ENET_FINS(reg, PER_REG_FIELD, val) \
143 ((reg) = ((reg) & ~PER_REG_FIELD##_MASK) \
144 | (((val) << PER_REG_FIELD##_SHIFT) & PER_REG_FIELD##_MASK))
145
147 #define ENET_DIV_ROUNDUP(val, div) (((val) + (div) - 1) / (div))
148
150 #define ENET_VERSION_NONE (0xFFFFFFFFU)
151
153 #define ENET_MAC_ADDR_LEN (6U)
154
156 #define ENET_OUI_ADDR_LEN (3U)
157
159 #define ENET_IPv4_ADDR_LEN (4U)
160
162 #define ENET_IPv6_ADDR_LEN (16U)
163
165 #define ENET_PRI_NUM (8U)
166
168 #define ENET_PRI_MIN (0U)
169
171 #define ENET_PRI_MAX (ENET_PRI_NUM - 1U)
172
174 #define ENET_TOS_PRI_NUM (64U)
175
177 #define ENET_TOS_PRI_MIN (0U)
178
180 #define ENET_TOS_PRI_MAX (ENET_TOS_PRI_NUM - 1U)
181
183 #define ENET_VLAN_ID_MAX (4095U)
184
186 #define ENET_ETHERTYPE_PTP (0x88F7U)
187
189 #define ENET_RX_MTU_MAX (2016U)
190
192 #define ENET_ETHERTYPE_CUSTOMER_VLAN (0x8100U)
193
194 /* ========================================================================== */
195 /* Structures and Enums */
196 /* ========================================================================== */
197
201 typedef enum Enet_Type_e
202 {
204 ENET_NULL,
205
207 ENET_ICSSG_DUALMAC,
208
210 ENET_ICSSG_SWITCH,
211
213 ENET_GMAC_3G,
214
216 ENET_CPSW_2G,
217
219 ENET_CPSW_3G,
220
222 ENET_CPSW_5G,
223
225 ENET_CPSW_9G,
226
228 ENET_TYPE_COUNT,
229 } Enet_Type;
230
232 #define ENET_TYPE_NUM (ENET_TYPE_COUNT + 1U)
233
237 typedef enum Enet_Magic_e
238 {
240 ENET_MAGIC = 0xABABABABU,
241
243 ENET_NO_MAGIC = 0x0U,
244 } Enet_Magic;
245
249 typedef enum Enet_CrcType_e
250 {
252 ENET_CRC_ETHERNET = 0U,
253
255 ENET_CRC_CASTAGNOLI,
256 } Enet_CrcType;
257
267 typedef enum Enet_Event_e
268 {
270 ENET_EVT_NONE = 0U,
271
276 ENET_EVT_ASYNC_CMD_RESP = ENET_BIT(0U),
277
279 ENET_EVT_TIMESTAMP_SWPUSH = ENET_BIT(1U),
280
282 ENET_EVT_TIMESTAMP_HWPUSH = ENET_BIT(2U),
283
285 ENET_EVT_TIMESTAMP_ROLLOVER = ENET_BIT(3U),
286
288 ENET_EVT_TIMESTAMP_HALFROLLOVER = ENET_BIT(4U),
289
291 ENET_EVT_TIMESTAMP_RX = ENET_BIT(5U),
292
299 ENET_EVT_TIMESTAMP_TX = ENET_BIT(6U),
300
302 ENET_EVT_TIMESTAMP_COMP = ENET_BIT(7U),
303
305 ENET_EVT_TIMESTAMP_HOSTTX = ENET_BIT(8U),
306
309 ENET_EVT_ANY = 0xFFFFFFFFU,
310 } Enet_Event;
311
321 typedef struct Enet_Version_s
322 {
324 uint32_t maj;
325
327 uint32_t min;
328
330 uint32_t rtl;
331
333 uint32_t id;
334
336 uint32_t other1;
337
339 uint32_t other2;
340 } Enet_Version;
341
345 typedef enum Enet_Speed_e
346 {
348 ENET_SPEED_10MBIT = 0U,
349
351 ENET_SPEED_100MBIT,
352
354 ENET_SPEED_1GBIT,
355
357 ENET_SPEED_AUTO,
358 } Enet_Speed;
359
363 typedef enum Enet_Duplexity_e
364 {
366 ENET_DUPLEX_HALF = 0U,
367
369 ENET_DUPLEX_FULL,
370
372 ENET_DUPLEX_AUTO,
373 } Enet_Duplexity;
374
378 typedef enum Enet_VlanTagType_e
379 {
381 ENET_VLAN_TAG_TYPE_INNER = 0U,
382
384 ENET_VLAN_TAG_TYPE_OUTER,
385 } Enet_VlanTagType;
386
390 typedef struct Enet_VlanTag_s
391 {
393 uint16_t tpid;
394
396 uint8_t pcp;
397
399 uint8_t dei;
400
402 uint16_t vlanId;
403
405 Enet_VlanTagType tagType;
406 } Enet_VlanTag;
407
411 typedef enum Enet_MacPort_e
412 {
414 ENET_MAC_PORT_FIRST = 0U,
415
417 ENET_MAC_PORT_1 = ENET_MAC_PORT_FIRST,
418
420 ENET_MAC_PORT_2 = 1U,
421
423 ENET_MAC_PORT_3 = 2U,
424
426 ENET_MAC_PORT_4 = 3U,
427
429 ENET_MAC_PORT_5 = 4U,
430
432 ENET_MAC_PORT_6 = 5U,
433
435 ENET_MAC_PORT_7 = 6U,
436
438 ENET_MAC_PORT_8 = 7U,
439
441 ENET_MAC_PORT_LAST = ENET_MAC_PORT_8,
442 } Enet_MacPort;
443
454 typedef void (*Enet_EventCallback)(Enet_Event evt,
455 uint32_t evtNum,
456 void *evtCbArgs,
457 void *arg1,
458 void *arg2);
459
460 typedef void (*Enet_notifyCallback)(void *pArg);
461
462 typedef struct Enet_notify_t
463 {
464 Enet_notifyCallback cbFxn;
465 void* cbArg;
466 } Enet_notify_t;
467
469 #define ENET_MAC_PORT_NUM ((uint32_t)ENET_MAC_PORT_LAST + 1U)
470
477 #define ENET_MACPORT_NORM(n) ((n) - ENET_MAC_PORT_FIRST)
478
485 #define ENET_MACPORT_DENORM(n) ((Enet_MacPort)((n) + ENET_MAC_PORT_FIRST))
486
494 #define ENET_MACPORT_ID(n) ((n) - ENET_MAC_PORT_FIRST + 1U)
495
497 #define ENET_MAC_PORT_INV ((Enet_MacPort)0xFFFFU)
498
500 #define ENET_TRAFFIC_CLASS_INV ((uint32_t)0xFFFFU)
501
507 #define ENET_MACPORT_MASK(n) (ENET_BIT(ENET_MACPORT_NORM(n)))
508
509 /* ========================================================================== */
510 /* Global Variables Declarations */
511 /* ========================================================================== */
512
513 /* None */
514
515 /* ========================================================================== */
516 /* Function Declarations */
517 /* ========================================================================== */
518
526 static inline bool Enet_isCpswFamily(Enet_Type enetType);
527
535 static inline bool Enet_isIcssFamily(Enet_Type enetType);
536
537 /* ========================================================================== */
538 /* Deprecated Function Declarations */
539 /* ========================================================================== */
540
541 /* None */
542
543 /* ========================================================================== */
544 /* Static Function Definitions */
545 /* ========================================================================== */
546
547 static inline bool Enet_isCpswFamily(Enet_Type enetType)
548 {
549 return ((enetType == ENET_GMAC_3G) ||
550 (enetType == ENET_CPSW_2G) ||
551 (enetType == ENET_CPSW_3G) ||
552 (enetType == ENET_CPSW_5G) ||
553 (enetType == ENET_CPSW_9G));
554 }
555
556 static inline bool Enet_isIcssFamily(Enet_Type enetType)
557 {
558 return ((enetType == ENET_ICSSG_DUALMAC) ||
559 (enetType == ENET_ICSSG_SWITCH));
560 }
561
562 #ifdef __cplusplus
563 }
564 #endif
565
566 #endif /* ENET_TYPES_H_ */
567
Enet_notify_t::cbArg
void * cbArg
Definition: enet_types.h:465
Enet_VlanTag::vlanId
uint16_t vlanId
Definition: enet_types.h:402
ENET_EVT_TIMESTAMP_TX
@ ENET_EVT_TIMESTAMP_TX
Definition: enet_types.h:299
ENET_MAC_PORT_3
@ ENET_MAC_PORT_3
Definition: enet_types.h:423
ENET_CPSW_5G
@ ENET_CPSW_5G
Definition: enet_types.h:222
ENET_VLAN_TAG_TYPE_INNER
@ ENET_VLAN_TAG_TYPE_INNER
Definition: enet_types.h:381
Enet_VlanTagType
Enet_VlanTagType
Double tagging VLAN type.
Definition: enet_types.h:379
Enet_Speed
Enet_Speed
MAC interface speed.
Definition: enet_types.h:346
ENET_CRC_ETHERNET
@ ENET_CRC_ETHERNET
Definition: enet_types.h:252
ENET_MAC_PORT_LAST
@ ENET_MAC_PORT_LAST
Definition: enet_types.h:441
ENET_MAC_PORT_4
@ ENET_MAC_PORT_4
Definition: enet_types.h:426
Enet_Version::other1
uint32_t other1
Definition: enet_types.h:336
ENET_EVT_TIMESTAMP_SWPUSH
@ ENET_EVT_TIMESTAMP_SWPUSH
Definition: enet_types.h:279
ENET_MAC_PORT_8
@ ENET_MAC_PORT_8
Definition: enet_types.h:438
Enet_isCpswFamily
static bool Enet_isCpswFamily(Enet_Type enetType)
Check if Ethernet peripheral type is part of CPSW family.
Definition: enet_types.h:547
ENET_MAC_PORT_1
@ ENET_MAC_PORT_1
Definition: enet_types.h:417
Enet_MacPort
Enet_MacPort
MAC port.
Definition: enet_types.h:412
Enet_Event
Enet_Event
Ethernet events.
Definition: enet_types.h:268
ENET_MAC_PORT_6
@ ENET_MAC_PORT_6
Definition: enet_types.h:432
Enet_notify_t
Definition: enet_types.h:463
ENET_DUPLEX_AUTO
@ ENET_DUPLEX_AUTO
Definition: enet_types.h:372
ENET_GMAC_3G
@ ENET_GMAC_3G
Definition: enet_types.h:213
ENET_ICSSG_SWITCH
@ ENET_ICSSG_SWITCH
Definition: enet_types.h:210
ENET_EVT_TIMESTAMP_ROLLOVER
@ ENET_EVT_TIMESTAMP_ROLLOVER
Definition: enet_types.h:285
ENET_EVT_ASYNC_CMD_RESP
@ ENET_EVT_ASYNC_CMD_RESP
Definition: enet_types.h:276
ENET_BIT
#define ENET_BIT(n)
Macro to set bit at given bit position.
Definition: enet_types.h:126
ENET_CPSW_2G
@ ENET_CPSW_2G
Definition: enet_types.h:216
ENET_SPEED_10MBIT
@ ENET_SPEED_10MBIT
Definition: enet_types.h:348
ENET_MAGIC
@ ENET_MAGIC
Definition: enet_types.h:240
Enet_Magic
Enet_Magic
Enet driver magic value, used to indicate if driver is open or not.
Definition: enet_types.h:238
Enet_VlanTag
VLAN tag.
Definition: enet_types.h:391
ENET_DUPLEX_FULL
@ ENET_DUPLEX_FULL
Definition: enet_types.h:369
ENET_CPSW_3G
@ ENET_CPSW_3G
Definition: enet_types.h:219
Enet_VlanTag::tagType
Enet_VlanTagType tagType
Definition: enet_types.h:405
ENET_MAC_PORT_FIRST
@ ENET_MAC_PORT_FIRST
Definition: enet_types.h:414
ENET_CRC_CASTAGNOLI
@ ENET_CRC_CASTAGNOLI
Definition: enet_types.h:255
ENET_NULL
@ ENET_NULL
Definition: enet_types.h:204
Enet_Version::other2
uint32_t other2
Definition: enet_types.h:339
Enet_Duplexity
Enet_Duplexity
MAC interface duplexity.
Definition: enet_types.h:364
ENET_NO_MAGIC
@ ENET_NO_MAGIC
Definition: enet_types.h:243
Enet_VlanTag::dei
uint8_t dei
Definition: enet_types.h:399
Enet_isIcssFamily
static bool Enet_isIcssFamily(Enet_Type enetType)
Check if Ethernet peripheral type is part of ICSS family.
Definition: enet_types.h:556
Enet_Version
Version of a peripheral or module.
Definition: enet_types.h:322
Enet_Type
Enet_Type
Ethernet peripheral type.
Definition: enet_types.h:202
ENET_EVT_ANY
@ ENET_EVT_ANY
Definition: enet_types.h:309
ENET_SPEED_100MBIT
@ ENET_SPEED_100MBIT
Definition: enet_types.h:351
ENET_TYPE_COUNT
@ ENET_TYPE_COUNT
Definition: enet_types.h:228
Enet_Version::maj
uint32_t maj
Definition: enet_types.h:324
ENET_VLAN_TAG_TYPE_OUTER
@ ENET_VLAN_TAG_TYPE_OUTER
Definition: enet_types.h:384
ENET_DUPLEX_HALF
@ ENET_DUPLEX_HALF
Definition: enet_types.h:366
ENET_MAC_PORT_2
@ ENET_MAC_PORT_2
Definition: enet_types.h:420
ENET_ICSSG_DUALMAC
@ ENET_ICSSG_DUALMAC
Definition: enet_types.h:207
Enet_notify_t::cbFxn
Enet_notifyCallback cbFxn
Definition: enet_types.h:464
ENET_MAC_PORT_7
@ ENET_MAC_PORT_7
Definition: enet_types.h:435
ENET_SPEED_AUTO
@ ENET_SPEED_AUTO
Definition: enet_types.h:357
Enet_EventCallback
void(* Enet_EventCallback)(Enet_Event evt, uint32_t evtNum, void *evtCbArgs, void *arg1, void *arg2)
Event callback.
Definition: enet_types.h:454
ENET_SPEED_1GBIT
@ ENET_SPEED_1GBIT
Definition: enet_types.h:354
ENET_EVT_TIMESTAMP_HALFROLLOVER
@ ENET_EVT_TIMESTAMP_HALFROLLOVER
Definition: enet_types.h:288
Enet_Version::id
uint32_t id
Definition: enet_types.h:333
Enet_Version::rtl
uint32_t rtl
Definition: enet_types.h:330
ENET_EVT_TIMESTAMP_HWPUSH
@ ENET_EVT_TIMESTAMP_HWPUSH
Definition: enet_types.h:282
ENET_EVT_TIMESTAMP_RX
@ ENET_EVT_TIMESTAMP_RX
Definition: enet_types.h:291
ENET_CPSW_9G
@ ENET_CPSW_9G
Definition: enet_types.h:225
Enet_notifyCallback
void(* Enet_notifyCallback)(void *pArg)
Definition: enet_types.h:460
Enet_CrcType
Enet_CrcType
CRC type.
Definition: enet_types.h:250
ENET_EVT_NONE
@ ENET_EVT_NONE
Definition: enet_types.h:270
ENET_EVT_TIMESTAMP_HOSTTX
@ ENET_EVT_TIMESTAMP_HOSTTX
Definition: enet_types.h:305
ENET_MAC_PORT_5
@ ENET_MAC_PORT_5
Definition: enet_types.h:429
ENET_EVT_TIMESTAMP_COMP
@ ENET_EVT_TIMESTAMP_COMP
Definition: enet_types.h:302
Enet_Version::min
uint32_t min
Definition: enet_types.h:327
Enet_VlanTag::pcp
uint8_t pcp
Definition: enet_types.h:396
Enet_VlanTag::tpid
uint16_t tpid
Definition: enet_types.h:393