AM64x INDUSTRIAL COMMUNICATIONS SDK  11.00.00
lre_common.h
Go to the documentation of this file.
1 
51 #ifndef LRE_COMMON_H_
52 #define LRE_COMMON_H_
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58 
59 /* ========================================================================== */
60 /* Include Files */
61 /* ========================================================================== */
62 
63 #include <enet.h>
64 #include <enet_cfg.h>
65 #include <include/core/enet_dma.h>
66 #include <include/core/enet_base.h>
67 #include <utils/include/enet_ethutils.h>
68 #include <utils/include/enet_appmemutils.h>
69 #include <utils/include/enet_apputils.h>
70 #include <kernel/dpl/TaskP.h>
71 #include <kernel/dpl/ClockP.h>
72 #include <kernel/dpl/SemaphoreP.h>
73 #include <per/icssg.h>
74 #include <priv/per/icssg_priv.h>
75 
76 /* ========================================================================== */
77 /* Macros & Typedefs */
78 /* ========================================================================== */
79 
80 #define LRE_MANUFACTURER "Texas Instruments"
81 #define LRE_VERSION_NAME "1.0.0.1"
82 #define LRE_NODE_NAME "TI"
83 
84 #define LRE_SUP_SEND_HANDLER_TASK_PRIORITY (7U)
85 #define LRE_SUP_SEND_HANDLER_TASK_STACK (3 * 1024)
86 #define LRE_SUP_RCV_HANDLER_TASK_PRIORITY (7U)
87 #define LRE_SUP_RCV_HANDLER_TASK_STACK (8 * 1024)
88 
89 #define ETHER_TYPE_LRE_SUP ( 0x88FB )
91 #define LRE_FRAME_MIN_SIZE ( 66 )
92 #define LRE_FRAME_VLAN_MIN_SIZE ( 70 )
93 #define ICSS_EMAC_MAXMTU_HSR 1528
94 
95 /* --- LRE Supervision frame related Defines --- */
96 
98 #define LRE_SUP_PATH_VERSION ( 0x0001 )
99 
101 #define LRE_TLV1_TYPE_PRP_DUP_DISCARD ( 20 )
102 
104 #define LRE_TLV1_TYPE_PRP_DUP_ACCEPT ( 21 )
105 
107 #define LRE_TLV1_TYPE_HSR ( 23 )
108 
110 #define LRE_TLV2_TYPE_REDBOX_MAC ( 30 )
111 
113 #define LRE_TLV0_TYPE ( 0 )
114 
116 #define LRE_TLV0_LENGTH ( 0 )
117 
118 /* --- LRE Nodetable related Defines --- */
119 
121 #define NT_TOTAL_ENTRIES 256
122 
124 #define NT_BUCKET_SIZE 8
125 
127 #define NT_NUM_OF_BUCKETS (NT_TOTAL_ENTRIES/NT_BUCKET_SIZE)
128 
131 #define LRE_NODE_FORGET_TIME 60
132 
134 #define LRE_PORT_A 0U
135 
137 #define LRE_PORT_B 1U
138 
140 #define LRE_NODESTABLE_ENTRY_INVALID 0U
141 
143 #define LRE_NODESTABLE_ENTRY_VALID 1U
144 
145 
146 /* ========================================================================== */
147 /* Structures and Enums */
148 /* ========================================================================== */
149 
153 typedef enum Lre_Mode_e
154 {
157 
160 
163 } Lre_Mode;
164 
168 typedef struct
169 {
170  /* Port A & Port B counters (members aligned to icssg offsets) */
172  uint32_t cntUniqueA;
174  uint32_t cntUniqueB;
175 
179  uint32_t cntDuplicateA;
183  uint32_t cntDuplicateB;
184 
188  uint32_t cntMultiA;
192  uint32_t cntMultiB;
193 
195  uint32_t cntRxA;
197  uint32_t cntRxB;
198 
200  uint32_t cntTxA;
202  uint32_t cntTxB;
203 
205  uint32_t cntOwnRxA;
207  uint32_t cntOwnRxB;
208 
210  uint32_t cntErrWrongLanA;
212  uint32_t cntErrWrongLanB;
213 
215  uint32_t cntErrorsA;
217  uint32_t cntErrorsB;
218 
219  /* Port C counters */
221  uint32_t cntUniqueC;
225  uint32_t cntDuplicateC;
229  uint32_t cntMultiC;
231  uint32_t cntRxC;
233  uint32_t cntTxC;
235  /* Only applicable to HSR RedBoxes in HSR-PRP configuration */
236  uint32_t cntErrWrongLanC;
238  uint32_t cntErrorsC;
239 
240  /* Node Table related counters */
242  uint32_t cntNodes;
244  /* Only applicable to HSR RedBoxes in HSR-PRP configuration */
245  uint32_t cntProxyNodes;
246 
247 } lreStatistics;
248 
249 /*
250 * HSR PRP Supervision Frame Format
251 *
252 * Octet[0-5] Destination MAC address = multicast (01-15-4E-00-01-XX)
253 * Octet[6-11] Source MAC address (MAC address of the node)
254 * Octet[12-17] Supervision frame tag = 0x88FB
255 * Octet[18-25] TLV1
256 * Octet[26-33] TLV2
257 * Octet[34-35] TLV0
258 * Octet[36-65] Padding to 70 octets
259 */
260 
264 typedef struct
265 {
267  uint16_t ether_type;
268 
270  uint16_t path_and_ver;
271 
273  uint16_t seq_nr;
274 } SUP_TAG;
275 
279 typedef struct
280 {
282  uint8_t type;
283 
285  uint8_t length;
286 
288  uint8_t dan_mac[ETH_MAC_ADDR_LEN];
289 } TLV1_TAG;
290 
294 typedef struct
295 {
297  uint8_t type;
298 
300  uint8_t length;
301 
303  uint8_t redbox_mac[ETH_MAC_ADDR_LEN];
304 } TLV2_TAG;
305 
309 typedef struct
310 {
312  uint8_t type;
313 
315  uint8_t length;
316 } TLV0_TAG;
317 
321 typedef struct /* Use packed attribute for direct memory mapping */
322 {
324  uint8_t dst[ETH_MAC_ADDR_LEN];
325 
327  uint8_t src[ETH_MAC_ADDR_LEN];
328 
331 
334 
337 
340 
341 } __attribute__((packed)) SupervisionFrame;
342 
346 typedef struct
347 {
350 
353 
355  uint32_t filterNum;
356 
358  uint32_t classifierNum;
359 
360  /* Destination multicast address for HSR/PRP supervision */
361  uint8_t dstMac[ETH_MAC_ADDR_LEN];
362 
363  /* Source MAC address of the node */
364  uint8_t srcMac[ETH_MAC_ADDR_LEN];
365 
367  EnetDma_RxChHandle hRxCh[2];
368 
370  EnetDma_PktQ rxReadyQ[2];
371 
373  EnetDma_PktQ rxFreeQ[2];
374 
376  EnetDma_TxChHandle hTxCh;
377 
379  EnetDma_PktQ txFreePktInfoQ;
380 
382  EnetDma_PktQ txSubmitQ;
383 
385  SupervisionFrame svFrame;
386 
388  uint16_t supSeqNr;
389 
392 
396 
399 
401  TaskP_Object taskSendSupHandlerObj;
402 
404  TaskP_Object taskRcvSupHandlerObj;
405 
407  ClockP_Object supTimerObj;
408 
410  SemaphoreP_Object sendSupSem;
411 
413  SemaphoreP_Object rcvSupSem;
414 
416  uint8_t lreSendSupFrameTaskStack[LRE_SUP_SEND_HANDLER_TASK_STACK] __attribute__ ((aligned(32)));
417 
419  uint8_t lreRcvSupFrameTaskStack[LRE_SUP_SEND_HANDLER_TASK_STACK] __attribute__ ((aligned(32)));
420 
422 
426 typedef enum Lre_NodeType_e
427 {
430 
433 
436 
439 
442 
445 
448 
451 
454 
457 
460 
463 
467 
468 /* --- Node Table Data Structures --- */
469 
473 typedef struct {
475  uint8_t macAddress[ETH_MAC_ADDR_LEN];
476 
478  uint16_t lastSeqNumber;
479 
481  uint32_t cntRxSupA;
482 
484  uint32_t cntRxSupB;
485 
488  uint32_t timeLastSeenA;
489 
492  uint32_t timeLastSeenB;
493 
496  uint8_t entry_valid;
497 
500 } NodeInfo;
501 
505 typedef struct {
507 } NodeBucket;
508 
512 typedef struct {
514  uint32_t nodesCount;
515 } NodesTable;
516 
520 typedef struct {
523 
524 
528 typedef struct {
532 
536 typedef struct Lre_Obj_s {
538  Enet_Handle hEnet;
539 
542 
544  PRUICSS_Handle pruicssHandle;
545 
548 
551 
554 } Lre_Obj;
555 
561 typedef struct Lre_Obj_s *Lre_Handle;
562 
563 
564 /* ========================================================================== */
565 /* Global Variables Declarations */
566 /* ========================================================================== */
567 
568 /* None */
569 
570 /* ========================================================================== */
571 /* Function Declarations */
572 /* ========================================================================== */
573 
584 void LRE_open(Lre_Handle lreHandle);
585 
596 int32_t LRE_supervisionInit(Lre_Handle lreHandle);
597 
606 
618 void LRE_updateNodeEntry(NodesTable *table, const uint8_t *src_mac, uint16_t sequence_number, uint8_t port, Lre_NodeType node_type);
619 
628 
637 
646 
655 
662 
663 
668 #ifdef __cplusplus
669 }
670 #endif
671 
672 #endif /* LRE_COMMON_H_ */
NodesTable::nodesCount
uint32_t nodesCount
Definition: lre_common.h:514
lreStatistics::cntMultiC
uint32_t cntMultiC
Definition: lre_common.h:229
NodeBucket
Structure for a single bucket in the hash table.
Definition: lre_common.h:505
NT_NODE_TYPE_SANA
@ NT_NODE_TYPE_SANA
Definition: lre_common.h:456
Lre_Obj::svObj
Lre_supervisionObj svObj
Definition: lre_common.h:547
Lre_supervisionObj::supSeqNr
uint16_t supSeqNr
Definition: lre_common.h:388
LRE_nodesTableInit
void LRE_nodesTableInit(Lre_nodestableObj *ntObj)
Initializes the nodestable.
LRE_updateNodeEntry
void LRE_updateNodeEntry(NodesTable *table, const uint8_t *src_mac, uint16_t sequence_number, uint8_t port, Lre_NodeType node_type)
Updates the node entry in the node table.
SUP_TAG
Supervision Frame Tag.
Definition: hsrPrp_red_common.h:107
Lre_nodestableObj
Structure for the complete nodestable handling.
Definition: lre_common.h:520
NT_NODE_TYPE_SANAB
@ NT_NODE_TYPE_SANAB
Definition: lre_common.h:462
__attribute__
struct __attribute__((packed)) cpmDesc
Definition: iRtcDrv.h:85
LRE_printNodesTable
void LRE_printNodesTable(Lre_Handle lreHandle)
Prints the current state of the node table.
lreStatistics::cntTxA
uint32_t cntTxA
Definition: lre_common.h:200
NT_NODE_PRP_TYPE_VDAN_DUP_DISCARD
@ NT_NODE_PRP_TYPE_VDAN_DUP_DISCARD
Definition: lre_common.h:444
NT_NODE_PRP_TYPE_REDBOX_DUP_ACCEPT
@ NT_NODE_PRP_TYPE_REDBOX_DUP_ACCEPT
Definition: lre_common.h:435
Lre_supervisionObj::taskSendSupHandlerObj
TaskP_Object taskSendSupHandlerObj
Definition: lre_common.h:401
Lre_supervisionObj::txFreePktInfoQ
EnetDma_PktQ txFreePktInfoQ
Definition: lre_common.h:379
lreStatistics::cntRxA
uint32_t cntRxA
Definition: lre_common.h:195
Lre_Obj::ntObj
Lre_nodestableObj ntObj
Definition: lre_common.h:550
__attribute__::tlv2
TLV2_TAG tlv2
Definition: lre_common.h:336
Lre_Obj::lreMode
Lre_Mode lreMode
Definition: lre_common.h:541
Lre_supervisionObj::__attribute__
uint8_t lreSendSupFrameTaskStack[LRE_SUP_SEND_HANDLER_TASK_STACK] __attribute__((aligned(32)))
Lre_Obj::pruicssHandle
PRUICSS_Handle pruicssHandle
Definition: lre_common.h:544
lreStatistics::cntUniqueA
uint32_t cntUniqueA
Definition: lre_common.h:172
NodeInfo::entry_valid
uint8_t entry_valid
Definition: lre_common.h:496
lreStatistics::cntMultiA
uint32_t cntMultiA
Definition: lre_common.h:188
lreStatistics::cntUniqueB
uint32_t cntUniqueB
Definition: lre_common.h:174
lreStatistics::cntOwnRxB
uint32_t cntOwnRxB
Definition: lre_common.h:207
NodeInfo::timeLastSeenB
uint32_t timeLastSeenB
Definition: lre_common.h:492
NT_NODE_PRP_TYPE_VDAN_DUP_ACCEPT
@ NT_NODE_PRP_TYPE_VDAN_DUP_ACCEPT
Definition: lre_common.h:441
NT_NODE_PRP_TYPE_DAN_DUP_DISCARD
@ NT_NODE_PRP_TYPE_DAN_DUP_DISCARD
Definition: lre_common.h:432
LRE_open
void LRE_open(Lre_Handle lreHandle)
Opens the LRE driver.
LRE_checkNodeTimeouts
void LRE_checkNodeTimeouts(NodesTable *table)
Checks the node timeouts.
LRE_MODE_HSR
@ LRE_MODE_HSR
Definition: lre_common.h:162
TLV1_TAG
TLV1 Tag.
Definition: hsrPrp_red_common.h:117
__attribute__::tlv1
TLV1_TAG tlv1
Definition: lre_common.h:333
lreStatistics::cntErrorsB
uint32_t cntErrorsB
Definition: lre_common.h:217
Lre_supervisionObj::NodeForgetTime_ms
uint64_t NodeForgetTime_ms
Definition: lre_common.h:395
lreStatistics::cntRxC
uint32_t cntRxC
Definition: lre_common.h:231
lreStatistics::cntErrWrongLanA
uint32_t cntErrWrongLanA
Definition: lre_common.h:210
Lre_supervisionObj::classifierNum
uint32_t classifierNum
Definition: lre_common.h:358
NodeInfo::timeLastSeenA
uint32_t timeLastSeenA
Definition: lre_common.h:488
LRE_supervisionInit
int32_t LRE_supervisionInit(Lre_Handle lreHandle)
Initializes the LRE supervision object.
NodeInfo::type
Lre_NodeType type
Definition: lre_common.h:499
NT_NODE_TYPE_SANB
@ NT_NODE_TYPE_SANB
Definition: lre_common.h:459
NT_NODE_HSR_TYPE_VDAN
@ NT_NODE_HSR_TYPE_VDAN
Definition: lre_common.h:450
Lre_supervisionObj
Object for supervision frame handling.
Definition: lre_common.h:347
Lre_statisticsObj::statistics
lreStatistics statistics
Definition: lre_common.h:530
Lre_supervisionObj::supTimerObj
ClockP_Object supTimerObj
Definition: lre_common.h:407
Lre_supervisionObj::lifecheckPeriod_ms
uint64_t lifecheckPeriod_ms
Definition: lre_common.h:398
NT_NODE_PRP_TYPE_REDBOX_DUP_DISCARD
@ NT_NODE_PRP_TYPE_REDBOX_DUP_DISCARD
Definition: lre_common.h:438
lreStatistics::cntUniqueC
uint32_t cntUniqueC
Definition: lre_common.h:221
__attribute__::supTag
SUP_TAG supTag
Definition: lre_common.h:330
Lre_supervisionObj::txSubmitQ
EnetDma_PktQ txSubmitQ
Definition: lre_common.h:382
LRE_MODE_PRP_DUP_ACCEPT
@ LRE_MODE_PRP_DUP_ACCEPT
Definition: lre_common.h:159
lreStatistics::cntRxB
uint32_t cntRxB
Definition: lre_common.h:197
lreStatistics::cntDuplicateB
uint32_t cntDuplicateB
Definition: lre_common.h:183
lreStatistics
LRE Interface Statistics.
Definition: lre_common.h:169
lreStatistics::cntTxB
uint32_t cntTxB
Definition: lre_common.h:202
Lre_supervisionObj::rcvSupSem
SemaphoreP_Object rcvSupSem
Definition: lre_common.h:413
lreStatistics::cntProxyNodes
uint32_t cntProxyNodes
Definition: lre_common.h:245
Lre_Mode
Lre_Mode
LRE Mode Enum.
Definition: lre_common.h:154
LRE_getStatistics
void LRE_getStatistics(Lre_Handle lreHandle)
Updates the LRE statistics.
lreStatistics::cntNodes
uint32_t cntNodes
Definition: lre_common.h:242
lreStatistics::cntErrWrongLanC
uint32_t cntErrWrongLanC
Definition: lre_common.h:236
__attribute__::tlv0
TLV0_TAG tlv0
Definition: lre_common.h:339
TLV2_TAG::length
uint8_t length
Definition: lre_common.h:300
Lre_supervisionObj::svFrame
SupervisionFrame svFrame
Definition: lre_common.h:385
Lre_Handle
struct Lre_Obj_s * Lre_Handle
LRE hsr-prp driver handle.
Definition: lre_common.h:561
NodeInfo::lastSeqNumber
uint16_t lastSeqNumber
Definition: lre_common.h:478
TLV2_TAG
TLV2 Tag.
Definition: hsrPrp_red_common.h:127
Lre_Obj::hEnet
Enet_Handle hEnet
Definition: lre_common.h:538
NT_NUM_OF_BUCKETS
#define NT_NUM_OF_BUCKETS
Definition: lre_common.h:127
Lre_supervisionObj::__attribute__
uint8_t lreRcvSupFrameTaskStack[LRE_SUP_SEND_HANDLER_TASK_STACK] __attribute__((aligned(32)))
lreStatistics::cntDuplicateC
uint32_t cntDuplicateC
Definition: lre_common.h:225
NodeInfo::cntRxSupA
uint32_t cntRxSupA
Definition: lre_common.h:481
LRE_supervisionDeinit
void LRE_supervisionDeinit(Lre_Handle lreHandle)
Deinitializes the supervision module.
Lre_supervisionObj::filterNum
uint32_t filterNum
Definition: lre_common.h:355
Lre_Obj
Structure for HSR/PRP redundancy handle members.
Definition: lre_common.h:536
NT_NODE_HSR_TYPE_REDBOX
@ NT_NODE_HSR_TYPE_REDBOX
Definition: lre_common.h:453
TLV0_TAG
TLV0 Tag.
Definition: hsrPrp_red_common.h:137
lreStatistics::cntMultiB
uint32_t cntMultiB
Definition: lre_common.h:192
NodesTable
Structure for the nodestable hash table.
Definition: lre_common.h:512
Lre_supervisionObj::taskRcvSupHandlerObj
TaskP_Object taskRcvSupHandlerObj
Definition: lre_common.h:404
NT_NODE_HSR_TYPE_DAN
@ NT_NODE_HSR_TYPE_DAN
Definition: lre_common.h:447
NT_NODE_PRP_TYPE_DAN_DUP_ACCEPT
@ NT_NODE_PRP_TYPE_DAN_DUP_ACCEPT
Definition: lre_common.h:429
NodeInfo
Structure to hold information about a single node.
Definition: lre_common.h:473
lreStatistics::cntErrorsC
uint32_t cntErrorsC
Definition: lre_common.h:238
lreStatistics::cntOwnRxA
uint32_t cntOwnRxA
Definition: lre_common.h:205
Lre_Obj::statsObj
Lre_statisticsObj statsObj
Definition: lre_common.h:553
lreStatistics::cntErrWrongLanB
uint32_t cntErrWrongLanB
Definition: lre_common.h:212
NT_NODE_TYPE_END
@ NT_NODE_TYPE_END
Definition: lre_common.h:465
Lre_statisticsObj
Structure for statistics counters.
Definition: lre_common.h:528
Lre_supervisionObj::enableSupSendByDriver
uint32_t enableSupSendByDriver
Definition: lre_common.h:349
Lre_supervisionObj::clkTimerPeriod_ms
uint64_t clkTimerPeriod_ms
Definition: lre_common.h:391
LRE_SUP_SEND_HANDLER_TASK_STACK
#define LRE_SUP_SEND_HANDLER_TASK_STACK
Definition: lre_common.h:85
lreStatistics::cntDuplicateA
uint32_t cntDuplicateA
Definition: lre_common.h:179
LRE_statisticsInit
void LRE_statisticsInit(Lre_Handle lreHandle)
Initializes the statistics object.
Lre_NodeType
Lre_NodeType
LRE Remote Node Entry Type Enum.
Definition: lre_common.h:427
NodeInfo::cntRxSupB
uint32_t cntRxSupB
Definition: lre_common.h:484
Lre_supervisionObj::enableSupRcvByDriver
uint32_t enableSupRcvByDriver
Definition: lre_common.h:352
NT_BUCKET_SIZE
#define NT_BUCKET_SIZE
Definition: lre_common.h:124
Lre_supervisionObj::sendSupSem
SemaphoreP_Object sendSupSem
Definition: lre_common.h:410
lreStatistics::cntErrorsA
uint32_t cntErrorsA
Definition: lre_common.h:215
lreStatistics::cntTxC
uint32_t cntTxC
Definition: lre_common.h:233
TLV1_TAG::length
uint8_t length
Definition: lre_common.h:285
Lre_supervisionObj::hTxCh
EnetDma_TxChHandle hTxCh
Definition: lre_common.h:376
Lre_nodestableObj::nodesTable
NodesTable nodesTable
Definition: lre_common.h:521
LRE_MODE_PRP_DUP_DISCARD
@ LRE_MODE_PRP_DUP_DISCARD
Definition: lre_common.h:156