2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* eth_tx_flow.cpp
|
|
|
|
|
|
*
|
2023-06-08 12:27:49 +03:00
|
|
|
|
* Created on: 7 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
|
2023-05-03 14:01:32 +03:00
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#include "free_rtos/ethernet/eth_tx_flow.hpp"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
|
|
#include <networking/enet/core/include/core/enet_soc.h>
|
|
|
|
|
|
#include <networking/enet/core/include/core/enet_queue.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_board.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_appmemutils.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_appmemutils_cfg.h>
|
|
|
|
|
|
#include <networking/enet/utils/include/enet_apputils.h>
|
|
|
|
|
|
|
2024-01-19 14:57:14 +03:00
|
|
|
|
#include <task.h>
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
|
/**
|
2023-06-08 12:27:49 +03:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sysconfig.
|
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <build_name>/syscfg
|
2023-05-03 14:01:32 +03:00
|
|
|
|
*/
|
|
|
|
|
|
#include "ti_enet_config.h"
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-08 12:27:49 +03:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> p_packet_queue
|
2023-05-03 14:01:32 +03:00
|
|
|
|
*/
|
2023-10-27 13:20:33 +03:00
|
|
|
|
static void eth_initTxFreePktQ(void * appPriv, EnetDma_PktQ * p_packet_queue, uint32_t qCount)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
|
|
|
|
|
EnetDma_Pkt *pPktInfo;
|
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize TX EthPkts and queue them to txFreePktInfoQ */
|
2023-10-27 13:20:33 +03:00
|
|
|
|
for (i = 0U; i < qCount; i++)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-05-03 14:01:32 +03:00
|
|
|
|
pPktInfo = EnetMem_allocEthPkt(appPriv,
|
|
|
|
|
|
ENET_MEM_LARGE_POOL_PKT_SIZE,
|
|
|
|
|
|
ENETDMA_CACHELINE_ALIGNMENT);
|
|
|
|
|
|
EnetAppUtils_assert(pPktInfo != NULL);
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-05-03 14:01:32 +03:00
|
|
|
|
ENET_UTILS_SET_PKT_APP_STATE(&pPktInfo->pktState, ENET_PKTSTATE_APP_WITH_FREEQ);
|
2023-06-08 12:27:49 +03:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> p_packet_queue
|
2023-05-03 14:01:32 +03:00
|
|
|
|
EnetQueue_enq(p_packet_queue, &pPktInfo->node);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetAppUtils_print("initQs() txFreePktInfoQ initialized with %d pkts\r\n",
|
|
|
|
|
|
EnetQueue_getQCount(p_packet_queue));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
void free_rtos::txIsrHandler(void *appData)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EthTxFlow * tx_flow = (EthTxFlow *)appData;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
if(tx_flow == nullptr) {
|
|
|
|
|
|
return;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
tx_flow->retrieveFreeTxPktQ();
|
|
|
|
|
|
tx_flow->sem_[EthTxFlow::e_signalTxPkt].post();
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free_rtos::EthTxFlow::EthTxFlow() :
|
2024-02-16 17:06:59 +03:00
|
|
|
|
default_port_id_{e_ethMac0},
|
2023-05-03 14:01:32 +03:00
|
|
|
|
open_{false},
|
|
|
|
|
|
tx_ch_num_{0}
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetQueue_initQ(&tx_free_pktq_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
bool free_rtos::EthTxFlow::open(TEthMacPorts port_id, int32_t enetDmaTxChId)
|
2023-05-03 14:01:32 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
if (port_id >= e_ethMacTotal) {
|
2023-05-03 14:01:32 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetApp_GetDmaHandleInArgs txInArgs;
|
|
|
|
|
|
EnetApp_GetTxDmaHandleOutArgs txChInfo;
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: opening flow...\r\n", port_id);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
port_data_[port_id].tx_pkt_counter = 0;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
if (open_) {
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: tx flow is already open. Do nothing.\r\n", port_id);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Open the TX channel */
|
2024-02-16 17:06:59 +03:00
|
|
|
|
txInArgs.notifyCb = txIsrHandler;
|
|
|
|
|
|
txInArgs.cbArg = this;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
EnetApp_getTxDmaHandle(enetDmaTxChId, &txInArgs, &txChInfo);
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
default_port_id_ = port_id;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
tx_ch_num_ = txChInfo.txChNum;
|
|
|
|
|
|
dma_handle_ = txChInfo.hTxCh;
|
|
|
|
|
|
|
|
|
|
|
|
EnetAppUtils_assert(txChInfo.useGlobalEvt == true);
|
2023-10-27 13:20:33 +03:00
|
|
|
|
EnetAppUtils_assert(txChInfo.maxNumTxPkts >= ENET_SYSCFG_TOTAL_NUM_TX_PKT);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
if (dma_handle_ == nullptr)
|
|
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: failed to open tx dma flow\r\n", port_id);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
EnetAppUtils_assert(dma_handle_ != nullptr);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-27 13:20:33 +03:00
|
|
|
|
eth_initTxFreePktQ(this, &tx_free_pktq_, ENET_SYSCFG_TOTAL_NUM_TX_PKT);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
open_= true;
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: tx flow open successfully\r\n", port_id);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_rtos::EthTxFlow::enable(TEthMacPorts port_id) {
|
|
|
|
|
|
if (port_id >= e_ethMacTotal) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
port_data_[port_id].tx_enable = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_rtos::EthTxFlow::disable(TEthMacPorts port_id) {
|
|
|
|
|
|
if (port_id >= e_ethMacTotal) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
port_data_[port_id].tx_enable = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
void free_rtos::EthTxFlow::retrieveFreeTxPktQ()
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetDma_PktQ txFreeQ;
|
|
|
|
|
|
EnetDma_Pkt *pktInfo;
|
|
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_initQ(&txFreeQ);
|
|
|
|
|
|
|
|
|
|
|
|
status = EnetDma_retrieveTxPktQ(dma_handle_, &txFreeQ);
|
|
|
|
|
|
|
|
|
|
|
|
if (status != ENET_SOK)
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetAppUtils_print("retrieveFreeTxPktQ() failed to retrieve pkts: %d\r\n", status);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetAppUtils_validatePacketState( &txFreeQ,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_DRIVER,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_FREEQ);
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_append(&tx_free_pktq_, &txFreeQ);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetDma_Pkt* free_rtos::EthTxFlow::getTxPktInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
EnetDma_Pkt *txPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&tx_free_pktq_);
|
|
|
|
|
|
|
|
|
|
|
|
while(txPktInfo == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
sem_[EthTxFlow::e_signalTxPkt].pend();
|
|
|
|
|
|
txPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&tx_free_pktq_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return txPktInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
bool free_rtos::EthTxFlow::send(TEthMacPorts port_id, uint8_t * p_data, uint32_t len)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (port_id >= e_ethMacTotal) {
|
2024-01-19 14:57:14 +03:00
|
|
|
|
EnetAppUtils_print("Wrong port id\r\n");
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!port_data_[port_id].tx_enable) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetDma_PktQ txSubmitQ;
|
|
|
|
|
|
EnetDma_Pkt *txPktInfo;
|
|
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_initQ(&txSubmitQ);
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
txPktInfo = getTxPktInfo();
|
2023-10-26 10:21:41 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
if (txPktInfo == NULL)
|
2024-01-19 14:57:14 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: Drop due to TX pkt not available\r\n", port_id);
|
2024-01-19 14:57:14 +03:00
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
memcpy(txPktInfo->sgList.list[0].bufPtr, p_data, len);
|
|
|
|
|
|
|
|
|
|
|
|
txPktInfo->sgList.list[0].segmentFilledLen = len;
|
|
|
|
|
|
txPktInfo->sgList.numScatterSegments = 1;
|
|
|
|
|
|
txPktInfo->chkSumInfo = 0U;
|
|
|
|
|
|
txPktInfo->appPriv = nullptr;
|
|
|
|
|
|
txPktInfo->tsInfo.txPktSeqId = 0;
|
|
|
|
|
|
txPktInfo->txPktTc = 0; /// Traffic class IPv6
|
|
|
|
|
|
txPktInfo->tsInfo.enableHostTxTs = false;
|
|
|
|
|
|
txPktInfo->txPortNum = (Enet_MacPort)port_id;
|
|
|
|
|
|
|
|
|
|
|
|
EnetDma_checkPktState( &txPktInfo->pktState,
|
|
|
|
|
|
ENET_PKTSTATE_MODULE_APP,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_FREEQ,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_DRIVER);
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_enq(&txSubmitQ, &txPktInfo->node);
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
status = EnetDma_submitTxPktQ(dma_handle_, &txSubmitQ);
|
2024-02-16 17:06:59 +03:00
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
if (status != ENET_SOK)
|
|
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: Failed to submit TX pkt queue: %d\r\n", port_id, status);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
++port_data_[port_id].tx_pkt_counter;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-24 14:02:04 +03:00
|
|
|
|
bool free_rtos::EthTxFlow::send(TxFlowHandlerArgs& handlerArgs, uint32_t numScatterSegments)
|
2023-06-08 12:27:49 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
TEthMacPorts port_id = handlerArgs.port_id;
|
|
|
|
|
|
|
|
|
|
|
|
if (port_id >= e_ethMacTotal) {
|
2023-10-26 10:21:41 +03:00
|
|
|
|
EnetAppUtils_print("Wrong port id\r\n");
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
if (port_data_[port_id].tx_enable == false) {
|
2023-06-08 12:27:49 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnetDma_PktQ txSubmitQ;
|
|
|
|
|
|
EnetDma_Pkt *txPktInfo;
|
|
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_initQ(&txSubmitQ);
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
txPktInfo = getTxPktInfo();
|
2023-10-26 10:21:41 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
if (txPktInfo == NULL)
|
2024-01-19 14:57:14 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: Drop due to TX pkt not available\r\n", port_id);
|
2024-01-19 14:57:14 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
return false;
|
2023-06-08 12:27:49 +03:00
|
|
|
|
}
|
2024-02-16 17:06:59 +03:00
|
|
|
|
|
|
|
|
|
|
for(size_t scatter_segment = 0; scatter_segment < numScatterSegments; scatter_segment++)
|
2023-06-08 12:27:49 +03:00
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
handlerArgs.buffer = txPktInfo->sgList.list[scatter_segment].bufPtr;
|
|
|
|
|
|
txPktInfo->sgList.list[scatter_segment].segmentFilledLen = handlerArgs.stack_handler->Sender(handlerArgs, scatter_segment);
|
2023-06-08 12:27:49 +03:00
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
txPktInfo->sgList.numScatterSegments = numScatterSegments;
|
|
|
|
|
|
txPktInfo->chkSumInfo = 0U;
|
|
|
|
|
|
txPktInfo->appPriv = nullptr;
|
|
|
|
|
|
txPktInfo->tsInfo.txPktSeqId = 0;
|
|
|
|
|
|
txPktInfo->txPktTc = 0; /// Traffic class IPv6
|
|
|
|
|
|
txPktInfo->tsInfo.enableHostTxTs = false;
|
|
|
|
|
|
txPktInfo->txPortNum = (Enet_MacPort)port_id;
|
|
|
|
|
|
|
|
|
|
|
|
EnetDma_checkPktState( &txPktInfo->pktState,
|
|
|
|
|
|
ENET_PKTSTATE_MODULE_APP,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_FREEQ,
|
|
|
|
|
|
ENET_PKTSTATE_APP_WITH_DRIVER);
|
|
|
|
|
|
|
|
|
|
|
|
EnetQueue_enq(&txSubmitQ, &txPktInfo->node);
|
|
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
status = EnetDma_submitTxPktQ(dma_handle_, &txSubmitQ);
|
2024-02-16 17:06:59 +03:00
|
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
|
if (status != ENET_SOK)
|
|
|
|
|
|
{
|
2024-02-16 17:06:59 +03:00
|
|
|
|
EnetAppUtils_print("tx_flow %u: Failed to submit TX pkt queue: %d\r\n", port_id, status);
|
2023-06-08 12:27:49 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-16 17:06:59 +03:00
|
|
|
|
++port_data_[handlerArgs.port_id].tx_pkt_counter;
|
2023-06-08 12:27:49 +03:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|