AM263x MCU+ SDK  08.03.00
enet_dma.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 
47 #ifndef ENET_DMA_H_
48 #define ENET_DMA_H_
49 
50 /* ========================================================================== */
51 /* Include Files */
52 /* ========================================================================== */
53 
54 #include <stdint.h>
58 
59 #if defined(SOC_AM64X) || defined(SOC_AM243X)
60 #include <drivers/udma.h>
61 #include <include/dma/udma/enet_udma_types.h>
62 #include <include/dma/udma/enet_udma.h>
63 #include <include/dma/udma/enet_udma_psi.h>
64 #elif defined (SOC_AM273X) || defined(SOC_AWR294X) || defined(SOC_AM263X)
66 #else
67 #error "SOC not supported"
68 #endif
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 /* ========================================================================== */
75 /* Macros */
76 /* ========================================================================== */
77 
78 #if ((__ARM_ARCH == 7) && (__ARM_ARCH_PROFILE == 'R'))
79 
80 #define ENETDMA_CACHELINE_ALIGNMENT (32U)
81 #else
82 #error "Enet library compilation not supported on non cortex R cores. Update correct cache line size"
83 #endif
84 
85 
86 
87 #if defined(SOC_AM273X) || defined(SOC_AWR294X) || defined(SOC_AM263X)
88 
89 #define Enet_isCacheCoherent() (false)
90 #elif defined(SOC_AM64X) || defined(SOC_AM243X)
91 
92 #define Enet_isCacheCoherent() (Udma_isCacheCoherent())
93 #else
94 #error "SOC not supported"
95 #endif
96 
97 
103 #define ENET_DMA_STATS_HISTORY_CNT ((uint32_t)8U)
104 
115 typedef EnetDma_Pkt *(*EnetDma_AllocEthPktFxn)(uint32_t pktSize,
116  uint32_t alignSize,
117  void *appPriv);
118 
120 typedef void (*EnetDma_FreeEthPktFxn)(EnetDma_Pkt *pPktInfo);
121 
132 
133 
134 /* ========================================================================== */
135 /* Structures and Enums */
136 /* ========================================================================== */
137 
149 typedef struct EnetDma_CbStats_s
150 {
152  uint64_t dataNotifyCnt;
153 
156  uint64_t zeroNotifyCnt;
158  uint64_t totalPktCnt;
160  uint64_t totalCycleCnt;
161 
166 
169  uint64_t pktsPerNotify[ENET_DMA_STATS_HISTORY_CNT];
172 
175  uint64_t cycleCntPerNotify[ENET_DMA_STATS_HISTORY_CNT];
178 
181  uint64_t cycleCntPerPkt[ENET_DMA_STATS_HISTORY_CNT];
182 
186  uint64_t readyDmaDescQCnt[ENET_DMA_STATS_HISTORY_CNT];
188 
192 typedef struct EnetDma_DmaDescStats_s
193 {
195  uint64_t readyDmaDescEnq;
197  uint64_t freeDmaDescDeq;
199  uint64_t underFlowCnt;
201 
205 typedef struct EnetDma_RxChStats_s
206 {
214  uint64_t rxSubmitPktEnq;
220 
224 typedef struct EnetDma_TxChStats_s
225 {
233  uint64_t txSubmitPktEnq;
239 
242 /* ========================================================================== */
243 /* Global Variables Declarations */
244 /* ========================================================================== */
245 
246 /* None */
247 
248 /* ========================================================================== */
249 /* Function Declarations */
250 /* ========================================================================== */
251 
264  uint32_t instId,
265  const EnetDma_initCfg *pDmaCfg);
266 
277 
289  uint32_t instId,
290  const void *dmaCfg);
291 
299 int32_t EnetDma_close(EnetDma_Handle hEnetDma);
300 
310 void EnetDma_initRxChParams(void *pRxChCfg);
311 
331  const void *pRxChCfg);
332 
354  EnetDma_PktQ *fq,
355  EnetDma_PktQ *cq);
356 
369 
380 
390 void EnetDma_initTxChParams(void *pTxChCfg);
391 
411  const void *pTxChCfg);
412 
435  EnetDma_PktQ *fq,
436  EnetDma_PktQ *cq);
437 
450 
461 
474  EnetDma_PktQ *pRetrieveQ);
475 
488  EnetDma_Pkt **pPkt);
489 
503  EnetDma_PktQ *pSubmitQ);
504 
516  EnetDma_Pkt *pPkt);
517 
530  EnetDma_PktQ *pRetrieveQ);
531 
544  EnetDma_Pkt **pPkt);
545 
557  EnetDma_PktQ *pSubmitQ);
558 
570  EnetDma_Pkt *pPkt);
571 
580 
592  EnetDma_RxChStats *pStats);
593 
605  EnetDma_TxChStats *pStats);
606 
616 
626 
627 /* ========================================================================== */
628 /* Deprecated Function Declarations */
629 /* ========================================================================== */
630 
631 /* None */
632 
633 /* ========================================================================== */
634 /* Static Function Definitions */
635 /* ========================================================================== */
636 
637 /* None */
638 
639 #ifdef __cplusplus
640 }
641 #endif
642 
643 #endif /* ENET_DMA_H_ */
644 
EnetDma_TxChStats::txSubmitPktEnq
uint64_t txSubmitPktEnq
Definition: enet_dma.h:233
EnetDma_RxChStats::rxSubmitPktEnq
uint64_t rxSubmitPktEnq
Definition: enet_dma.h:214
EnetDma_disableRxEvent
int32_t EnetDma_disableRxEvent(EnetDma_RxChHandle hRxCh)
Disable RX channel packet reception event.
EnetDma_close
int32_t EnetDma_close(EnetDma_Handle hEnetDma)
Close Enet DMA (data path).
EnetDma_DmaDescStats::freeDmaDescDeq
uint64_t freeDmaDescDeq
Definition: enet_dma.h:197
EnetDma_retrieveTxPkt
int32_t EnetDma_retrieveTxPkt(EnetDma_TxChHandle hTxCh, EnetDma_Pkt **pPkt)
Retrieve single TX free (empty) packet from TX channel.
EnetDma_submitTxPktQ
int32_t EnetDma_submitTxPktQ(EnetDma_TxChHandle hTxCh, EnetDma_PktQ *pSubmitQ)
Submit a queue of ready (full) packets to TX channel.
EnetDma_RxChStats::rxRetrievePktDeq
uint64_t rxRetrievePktDeq
Definition: enet_dma.h:216
EnetDma_RxChStats::submitPktStats
EnetDma_CbStats submitPktStats
Definition: enet_dma.h:208
ENET_DMA_STATS_HISTORY_CNT
#define ENET_DMA_STATS_HISTORY_CNT
Enet DMA statistics configuration.
Definition: enet_dma.h:103
EnetDma_enableTxEvent
int32_t EnetDma_enableTxEvent(EnetDma_TxChHandle hTxCh)
Enable TX channel packet transmit completion event.
EnetDma_initRxChParams
void EnetDma_initRxChParams(void *pRxChCfg)
Initialize RX channel open parameters.
EnetDma_RxChStats
RX channel statistics.
Definition: enet_dma.h:206
EnetDma_RxChHandle
struct EnetCpdma_RxChObj_s * EnetDma_RxChHandle
Opaque handle that holds software state for Enet RX DMA channel.
Definition: enet_cpdma_types.h:92
enet_types.h
This file contains the basic types using across the Enet driver.
EnetDma_TxChStats
TX channel statistics.
Definition: enet_dma.h:225
EnetDma_getTxChStats
int32_t EnetDma_getTxChStats(EnetDma_TxChHandle hTxCh, EnetDma_TxChStats *pStats)
Get TX channel statistics.
EnetDma_RxChStats::retrievePktStats
EnetDma_CbStats retrievePktStats
Definition: enet_dma.h:210
EnetDma_getRxChStats
int32_t EnetDma_getRxChStats(EnetDma_RxChHandle hRxCh, EnetDma_RxChStats *pStats)
Get RX channel statistics.
enet_queue.h
This file contains the type definitions and helper macros for the Enet software queue.
EnetDma_CbStats::zeroNotifyCnt
uint64_t zeroNotifyCnt
Definition: enet_dma.h:156
EnetDma_CbStats::pktsPerNotifyMax
uint64_t pktsPerNotifyMax
Definition: enet_dma.h:165
EnetDma_TxChStats::txRetrievePktDeq
uint64_t txRetrievePktDeq
Definition: enet_dma.h:235
EnetDma_TxChStats::txSubmitPktOverFlowCnt
uint64_t txSubmitPktOverFlowCnt
Definition: enet_dma.h:237
EnetDma_resetRxChStats
int32_t EnetDma_resetRxChStats(EnetDma_RxChHandle hRxCh)
Reset RX channel statistics.
EnetDma_initPktInfo
void EnetDma_initPktInfo(EnetDma_Pkt *pktInfo)
Initialize packet information structure.
EnetDma_openTxCh
EnetDma_TxChHandle EnetDma_openTxCh(EnetDma_Handle hDma, const void *pTxChCfg)
Enet DMA open TX channel.
EnetDma_RxChStats::dmaDescStats
EnetDma_DmaDescStats dmaDescStats
Definition: enet_dma.h:212
EnetDma_TxChStats::dmaDescStats
EnetDma_DmaDescStats dmaDescStats
Definition: enet_dma.h:231
enet_dma_pktutils.h
Enet DMA utility API to check packet and descriptor ownership states during development and debug.
EnetDma_resetTxChStats
int32_t EnetDma_resetTxChStats(EnetDma_TxChHandle hTxCh)
Reset TX channel statistics.
EnetDma_CbStats::totalCycleCnt
uint64_t totalCycleCnt
Definition: enet_dma.h:160
EnetDma_initTxChParams
void EnetDma_initTxChParams(void *pTxChCfg)
Initialize TX channel open parameters.
EnetDma_initDmaCfg
EnetDma_Handle EnetDma_initDmaCfg(Enet_Type enetType, uint32_t instId, const EnetDma_initCfg *pDmaCfg)
Initialize data path.
EnetDma_retrieveRxPktQ
int32_t EnetDma_retrieveRxPktQ(EnetDma_RxChHandle hRxCh, EnetDma_PktQ *pRetrieveQ)
Retrieve queue of RX ready (full) packets from RX channel.
EnetDma_DmaDescStats::underFlowCnt
uint64_t underFlowCnt
Definition: enet_dma.h:199
EnetDma_retrieveRxPkt
int32_t EnetDma_retrieveRxPkt(EnetDma_RxChHandle hRxCh, EnetDma_Pkt **pPkt)
Retrieve single RX ready (full) packet (single) from RX channel.
EnetDma_enableRxEvent
int32_t EnetDma_enableRxEvent(EnetDma_RxChHandle hRxCh)
Enable RX channel packet reception event.
EnetDma_retrieveTxPktQ
int32_t EnetDma_retrieveTxPktQ(EnetDma_TxChHandle hTxCh, EnetDma_PktQ *pRetrieveQ)
Retrieve queue of TX free (empty) packets from TX channel.
EnetDma_TxChStats::retrievePktStats
EnetDma_CbStats retrievePktStats
Definition: enet_dma.h:229
EnetDma_CbStats::dataNotifyCnt
uint64_t dataNotifyCnt
Definition: enet_dma.h:152
EnetDma_submitTxPkt
int32_t EnetDma_submitTxPkt(EnetDma_TxChHandle hTxCh, EnetDma_Pkt *pPkt)
Submit a single ready (full) packet to TX channel.
Enet_Type
Enet_Type
Ethernet peripheral type.
Definition: enet_types.h:196
EnetDma_open
EnetDma_Handle EnetDma_open(Enet_Type enetType, uint32_t instId, const void *dmaCfg)
Set default data path parameters.
EnetDma_submitRxPkt
int32_t EnetDma_submitRxPkt(EnetDma_RxChHandle hRxCh, EnetDma_Pkt *pPkt)
Submit single RX free (empty) packet for reception to RX channel.
EnetDma_Handle
struct EnetCpdma_DrvObj_s * EnetDma_Handle
Opaque handle for Enet CPDMA driver object.
Definition: enet_cpdma_types.h:86
EnetDma_FreeEthPktFxn
void(* EnetDma_FreeEthPktFxn)(EnetDma_Pkt *pPktInfo)
Function pointer type for Ethernet packet free function.
Definition: enet_dma.h:120
EnetDma_submitRxPktQ
int32_t EnetDma_submitRxPktQ(EnetDma_RxChHandle hRxCh, EnetDma_PktQ *pSubmitQ)
Submit queue of RX free (empty) packets for reception to RX channel.
EnetDma_TxChHandle
struct EnetCpdma_TxChObj_s * EnetDma_TxChHandle
Opaque handle that holds software state for Enet TX DMA channel.
Definition: enet_cpdma_types.h:97
EnetDma_Pkt
struct EnetCpdma_PktInfo_s EnetDma_Pkt
Opaque handle that holds software state for Enet Packet Info.
Definition: enet_cpdma_types.h:102
EnetDma_CbStats::cycleCntPerPktMax
uint64_t cycleCntPerPktMax
Definition: enet_dma.h:177
EnetDma_DmaDescStats
DMA descriptor stats for the RX & TX channels.
Definition: enet_dma.h:193
EnetDma_TxChStats::submitPktStats
EnetDma_CbStats submitPktStats
Definition: enet_dma.h:227
EnetDma_openRxCh
EnetDma_RxChHandle EnetDma_openRxCh(EnetDma_Handle hDma, const void *pRxChCfg)
Enet DMA open RX channel.
EnetDma_CbStats::totalPktCnt
uint64_t totalPktCnt
Definition: enet_dma.h:158
EnetDma_initCfg
Config structure for Enet CPDMA Data Path initialization.
Definition: enet_cpdma.h:432
enet_cpdma.h
This file contains the type definitions and helper macros for the Enet CPDMA data path (DMA) interfac...
EnetDma_closeTxCh
int32_t EnetDma_closeTxCh(EnetDma_TxChHandle hTxCh, EnetDma_PktQ *fq, EnetDma_PktQ *cq)
Enet DMA close TX channel.
EnetDma_CbStats
Stats for packets submitted/retrieved in the DMA event callbacks functions.
Definition: enet_dma.h:150
EnetDma_PktQ
EnetQ EnetDma_PktQ
Packet queue.
Definition: enet_dma.h:131
EnetDma_disableTxEvent
int32_t EnetDma_disableTxEvent(EnetDma_TxChHandle hTxCh)
Disable TX channel packet transmit completion event.
EnetDma_closeRxCh
int32_t EnetDma_closeRxCh(EnetDma_RxChHandle hRxCh, EnetDma_PktQ *fq, EnetDma_PktQ *cq)
Enet DMA close RX channel.
EnetQ
Generic queue.
Definition: enet_queue.h:83
EnetDma_RxChStats::rxSubmitPktUnderFlowCnt
uint64_t rxSubmitPktUnderFlowCnt
Definition: enet_dma.h:218
EnetDma_DmaDescStats::readyDmaDescEnq
uint64_t readyDmaDescEnq
Definition: enet_dma.h:195
EnetDma_deinitDmaCfg
int32_t EnetDma_deinitDmaCfg(EnetDma_Handle hEnetUdma)
De-initialize data path.
EnetDma_CbStats::cycleCntPerNotifyMax
uint64_t cycleCntPerNotifyMax
Definition: enet_dma.h:171