diff options
Diffstat (limited to 'lib/avtp_pipeline')
23 files changed, 1055 insertions, 16 deletions
diff --git a/lib/avtp_pipeline/avtp/openavb_avtp.c b/lib/avtp_pipeline/avtp/openavb_avtp.c index 82932d23..83886078 100644 --- a/lib/avtp_pipeline/avtp/openavb_avtp.c +++ b/lib/avtp_pipeline/avtp/openavb_avtp.c @@ -338,6 +338,10 @@ openavbRC openavbAvtpTx(void *pv, bool bSend, bool txBlockingInIntf) timeNsec = item->pAvtpTime->timeNsec; openavbMediaQTailUnlock(pStream->pMediaQ); } +#elif ATL_LAUNCHTIME_ENABLED + if( pStream->pMapCB->map_lt_calc_cb ) { + pStream->pMapCB->map_lt_calc_cb(pStream->pMediaQ, &timeNsec); + } #endif // Call mapping module to move data into AVTP frame @@ -354,6 +358,10 @@ openavbRC openavbAvtpTx(void *pv, bool bSend, bool txBlockingInIntf) timeNsec = item->pAvtpTime->timeNsec; openavbMediaQTailUnlock(pStream->pMediaQ); } +#elif ATL_LAUNCHTIME_ENABLED + if( pStream->pMapCB->map_lt_calc_cb ) { + pStream->pMapCB->map_lt_calc_cb(pStream->pMediaQ, &timeNsec); + } #endif // Blocking in interface mode. Pull from media queue for tx first diff --git a/lib/avtp_pipeline/avtp_pipeline.mk b/lib/avtp_pipeline/avtp_pipeline.mk index e08ac9b9..6e9565ca 100644 --- a/lib/avtp_pipeline/avtp_pipeline.mk +++ b/lib/avtp_pipeline/avtp_pipeline.mk @@ -1,7 +1,8 @@ AVB_FEATURE_ENDPOINT ?= 1 IGB_LAUNCHTIME_ENABLED ?= 0 +ATL_LAUNCHTIME_ENABLED ?= 1 AVB_FEATURE_GSTREAMER ?= 0 -PLATFORM_TOOLCHAIN ?= generic +PLATFORM_TOOLCHAIN ?= x86_aqc_linux .PHONY: all clean @@ -23,5 +24,6 @@ build/Makefile: -DCMAKE_TOOLCHAIN_FILE=../platform/Linux/$(PLATFORM_TOOLCHAIN).cmake \ -DAVB_FEATURE_ENDPOINT=$(AVB_FEATURE_ENDPOINT) \ -DIGB_LAUNCHTIME_ENABLED=$(IGB_LAUNCHTIME_ENABLED) \ + -DATL_LAUNCHTIME_ENABLED=$(ATL_LAUNCHTIME_ENABLED) \ -DAVB_FEATURE_GSTREAMER=$(AVB_FEATURE_GSTREAMER) \ .. diff --git a/lib/avtp_pipeline/include/openavb_log_pub.h b/lib/avtp_pipeline/include/openavb_log_pub.h index 846c169e..6d824af4 100644 --- a/lib/avtp_pipeline/include/openavb_log_pub.h +++ b/lib/avtp_pipeline/include/openavb_log_pub.h @@ -182,6 +182,16 @@ void avbLogInit(void); void avbLogExit(void); +void __avbLogFn( + int level, + const char *tag, + const char *company, + const char *component, + const char *path, + int line, + const char *fmt, + va_list args); + void avbLogFn( int level, const char *tag, diff --git a/lib/avtp_pipeline/include/openavb_map_pub.h b/lib/avtp_pipeline/include/openavb_map_pub.h index 02a58957..4f360454 100755 --- a/lib/avtp_pipeline/include/openavb_map_pub.h +++ b/lib/avtp_pipeline/include/openavb_map_pub.h @@ -177,6 +177,17 @@ typedef void (*openavb_map_set_src_bitrate_cb_t)(media_q_t *pMediaQ, unsigned in */ typedef unsigned int (*openavb_map_get_max_interval_frames_cb_t)(media_q_t *pMediaQ, SRClassIdx_t sr_class); +#if ATL_LAUNCHTIME_ENABLED +/** This talker callback will be called for each AVB observation interval to calculate a launchtime of packet. + * + * \param pMediaQ A pointer to the media queue for this stream + * \param pData pointer to data + * \param lt launchtime of media q item + * \return One of enum \ref tx_cb_ret_t values. + */ +typedef bool (*openavb_map_lt_calc_cb_t)(media_q_t *pMediaQ, U64 *lt); +#endif + /** Mapping callbacks structure. */ typedef struct { @@ -208,6 +219,11 @@ typedef struct { openavb_map_set_src_bitrate_cb_t map_set_src_bitrate_cb; /// Max interval frames callback. openavb_map_get_max_interval_frames_cb_t map_get_max_interval_frames_cb; + +#if ATL_LAUNCHTIME_ENABLED + // Launchtime calculation + openavb_map_lt_calc_cb_t map_lt_calc_cb; +#endif } openavb_map_cb_t; /** Main initialization entry point into the mapping module. diff --git a/lib/avtp_pipeline/map_uncmp_audio/openavb_map_uncmp_audio.c b/lib/avtp_pipeline/map_uncmp_audio/openavb_map_uncmp_audio.c index ca342b2b..6b703478 100755 --- a/lib/avtp_pipeline/map_uncmp_audio/openavb_map_uncmp_audio.c +++ b/lib/avtp_pipeline/map_uncmp_audio/openavb_map_uncmp_audio.c @@ -149,7 +149,10 @@ typedef struct { U8 DBC; avb_audio_mcr_t audioMcr; - +#if ATL_LAUNCHTIME_ENABLED + // Transmit interval in nanoseconds. + U32 txIntervalNs; +#endif } pvt_data_t; static void x_calculateSizes(media_q_t *pMediaQ) @@ -232,6 +235,10 @@ static void x_calculateSizes(media_q_t *pMediaQ) pPubMapInfo->packetSampleSizeBytes = 4; +#if ATL_LAUNCHTIME_ENABLED + pPvtData->txIntervalNs = 1000000000u / pPvtData->txInterval; + AVB_LOGF_INFO("LT interval ns:%d", pPvtData->txIntervalNs); +#endif AVB_LOGF_INFO("Rate:%d", pPubMapInfo->audioRate); AVB_LOGF_INFO("Bits:%d", pPubMapInfo->audioBitDepth); AVB_LOGF_INFO("Channels:%d", pPubMapInfo->audioChannels); @@ -395,6 +402,42 @@ void openavbMapUncmpAudioAVDECCInitCB(media_q_t *pMediaQ, U16 configIdx, U16 des AVB_TRACE_EXIT(AVB_TRACE_MAP); } +#if ATL_LAUNCHTIME_ENABLED +#define ATL_LT_OFFSET 500000 +bool openavbMapUncmpLaunchtimCalculationCB(media_q_t *pMediaQ, U64 *lt) +{ +static U64 last_time = 0; + bool res = false; + media_q_item_t* pMediaQItem; + pvt_data_t *pPvtData = pMediaQ->pPvtMapInfo; + AVB_TRACE_ENTRY(AVB_TRACE_INTF); + if (!lt) { + AVB_LOG_ERROR("Mapping module launchtime argument incorrect."); + return false; + } + if (!pPvtData) { + AVB_LOG_ERROR("Private mapping module data not allocated."); + return false; + } + + pMediaQItem = openavbMediaQTailLock(pMediaQ, true); + if (pMediaQItem) { + if (pMediaQItem->readIdx == 0) { + last_time = pMediaQItem->pAvtpTime->timeNsec; + *lt = last_time + ATL_LT_OFFSET; + res = true; + } else if( last_time != 0 ) { + last_time += pPvtData->txIntervalNs; + *lt = last_time + ATL_LT_OFFSET; + res = true; + } + openavbMediaQTailUnlock(pMediaQ); + } + AVB_TRACE_EXIT(AVB_TRACE_INTF); + return res; +} +#endif + // A call to this callback indicates that this mapping module will be // a talker. Any talker initialization can be done in this function. void openavbMapUncmpAudioTxInitCB(media_q_t *pMediaQ) @@ -737,6 +780,9 @@ extern DLL_EXPORT bool openavbMapUncmpAudioInitialize(media_q_t *pMediaQ, openav pMapCB->map_rx_cb = openavbMapUncmpAudioRxCB; pMapCB->map_end_cb = openavbMapUncmpAudioEndCB; pMapCB->map_gen_end_cb = openavbMapUncmpAudioGenEndCB; +#if ATL_LAUNCHTIME_ENABLED + pMapCB->map_lt_calc_cb = openavbMapUncmpLaunchtimCalculationCB; +#endif pPvtData->itemCount = 20; pPvtData->txInterval = 0; diff --git a/lib/avtp_pipeline/mcs/openavb_mcs.c b/lib/avtp_pipeline/mcs/openavb_mcs.c index 51d7fe9a..441fc52c 100644 --- a/lib/avtp_pipeline/mcs/openavb_mcs.c +++ b/lib/avtp_pipeline/mcs/openavb_mcs.c @@ -65,7 +65,7 @@ void openavbMcsAdvance(mcs_t *mediaClockSynth) if (mediaClockSynth->tickCount % mediaClockSynth->correctionInterval == 0) { mediaClockSynth->edgeTime += mediaClockSynth->correctionAmount; } -#if !IGB_LAUNCHTIME_ENABLED +#if !IGB_LAUNCHTIME_ENABLED && !ATL_LAUNCHTIME_ENABLED IF_LOG_INTERVAL(8000) { U64 nowNS; CLOCK_GETTIME64(OPENAVB_CLOCK_WALLTIME, &nowNS); diff --git a/lib/avtp_pipeline/openavb_common/CMakeLists.txt b/lib/avtp_pipeline/openavb_common/CMakeLists.txt index e5f7d7f4..80dacfda 100644 --- a/lib/avtp_pipeline/openavb_common/CMakeLists.txt +++ b/lib/avtp_pipeline/openavb_common/CMakeLists.txt @@ -4,9 +4,16 @@ if (AVB_FEATURE_IGB) ${AVB_SRC_DIR}/../common/avb_igb.c ) endif () +if (AVB_FEATURE_ATL) + message("-- common ATL library included") + SET (ATL_FILES + ${AVB_SRC_DIR}/../common/avb_atl.c + ) +endif () SET (SRC_FILES ${SRC_FILES} ${AVB_SRC_DIR}/../common/avb_gptp.c ${AVB_SRC_DIR}/openavb_common/mrp_client.c ${IGB_FILES} + ${ATL_FILES} PARENT_SCOPE ) diff --git a/lib/avtp_pipeline/openavb_common/mrp_client.c b/lib/avtp_pipeline/openavb_common/mrp_client.c index 1a285b5f..c7b28e63 100644 --- a/lib/avtp_pipeline/openavb_common/mrp_client.c +++ b/lib/avtp_pipeline/openavb_common/mrp_client.c @@ -615,7 +615,7 @@ int mrp_get_domain(int *class_a_id, int *a_priority, u_int16_t * a_vid, *b_priority = domain_class_b_priority; *b_vid = domain_class_b_vid; } - return domain_a_valid && domain_b_valid ? 0 : -1; + return domain_a_valid || domain_b_valid ? 0 : -1; } int mrp_join_vlan() diff --git a/lib/avtp_pipeline/platform/Linux/CMakeLists.txt b/lib/avtp_pipeline/platform/Linux/CMakeLists.txt index 14f427cc..43818e8a 100644 --- a/lib/avtp_pipeline/platform/Linux/CMakeLists.txt +++ b/lib/avtp_pipeline/platform/Linux/CMakeLists.txt @@ -90,6 +90,7 @@ if (DEFINED AVB_FEATURE_AVDECC) set ( AVB_FEATURE_GSTREAMER 0 ) set ( AVB_FEATURE_ENDPOINT 0 ) set ( AVB_FEATURE_IGB 0 ) + set ( AVB_FEATURE_ATL 0 ) set ( IGB_LAUNCHTIME_ENABLED 0 ) endif () endif () @@ -112,6 +113,7 @@ if (NOT DEFINED AVB_FEATURE_AVDECC) endif () if (NOT DEFINED AVB_FEATURE_IGB) set ( AVB_FEATURE_IGB 1 ) + set ( AVB_FEATURE_ATL 0 ) endif () # Default launchtime feature @@ -122,6 +124,12 @@ else () endif () set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIGB_LAUNCHTIME_ENABLED=${IGB_LAUNCHTIME_ENABLED}" ) +# Default launchtime feature for ATL +if (NOT DEFINED ATL_LAUNCHTIME_ENABLED) + set ( ATL_LAUNCHTIME_ENABLED 1 ) +endif () +set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DATL_LAUNCHTIME_ENABLED=${ATL_LAUNCHTIME_ENABLED}" ) + # Export feature flags for sub-builds if (AVB_FEATURE_FQTSS) @@ -138,8 +146,15 @@ if (AVB_FEATURE_AVDECC) endif () if (AVB_FEATURE_IGB) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_IGB=1" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_ATL=0" ) else () set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_IGB=0" ) +endif() +if (AVB_FEATURE_ATL) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_IGB=0" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_ATL=1" ) +else () + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_ATL=0" ) endif () #Export Platform defines @@ -266,6 +281,9 @@ if ( AVB_FEATURE_PCAP ) if ( AVB_FEATURE_IGB ) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_IGB" ) endif () + if ( AVB_FEATURE_ATL ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAVB_FEATURE_ATL" ) + endif () endif () add_subdirectory ( util ) diff --git a/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.c b/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.c new file mode 100644 index 00000000..9424ea96 --- /dev/null +++ b/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.c @@ -0,0 +1,271 @@ +/************************************************************************************************************* +Copyright (c) 2019, Aquantia Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#include "atl_rawsock.h" +#include "pcap_rawsock.h" +#include "simple_rawsock.h" +#include "avb.h" +#include "openavb_atl.h" +#include "avb_sched.h" + +#include "openavb_trace.h" + +#define AVB_LOG_COMPONENT "Raw Socket" +#include "openavb_log.h" + +// needed for gptplocaltime() +extern gPtpTimeData gPtpTD; + +void *atlRawsockOpen(atl_rawsock_t* rawsock, const char *ifname, bool rx_mode, bool tx_mode, U16 ethertype, U32 frame_size, U32 num_frames) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK); + + if (!pcapRawsockOpen((pcap_rawsock_t*)rawsock, ifname, rx_mode, + tx_mode, ethertype, frame_size, num_frames)) + { + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK); + return NULL; + } + + if (tx_mode) { + // Deal with frame size. + if (frame_size == 0) { + // use interface MTU as max frames size, if none specified + rawsock->base.frameSize = ATL_MTU; + } + else if (frame_size > ATL_MTU) { + AVB_LOGF_ERROR("Creating rawsock; requested frame size exceeds %d", ATL_MTU); + atlRawsockClose(rawsock); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK); + return NULL; + } else { + rawsock->base.frameSize = frame_size; + } + + // ATL setup + rawsock->atl_dev = atlAcquireDevice(ifname); + + // select class B queue by default + rawsock->queue = 1; + } + + // fill virtual functions table + rawsock_cb_t *cb = &rawsock->base.cb; + cb->close = atlRawsockClose; + cb->getTxFrame = atlRawsockGetTxFrame; + cb->relTxFrame = atlRawsockRelTxFrame; + cb->txSetMark = atlRawsockTxSetMark; + cb->txFrameReady = atlRawsockTxFrameReady; + cb->send = atlRawsockSend; + cb->txBufLevel = atlRawsockTxBufLevel; + cb->getTXOutOfBuffers = atlRawsockGetTXOutOfBuffers; + cb->getTXOutOfBuffersCyclic = atlRawsockGetTXOutOfBuffersCyclic; + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK); + return rawsock; +} + +void atlRawsockClose(void *pvRawsock) +{ + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + if (rawsock->atl_dev) { + atlReleaseDevice(rawsock->atl_dev); + } + + pcapRawsockClose((pcap_rawsock_t*)rawsock); +} + +bool atlRawsockTxSetMark(void *pvRawsock, int mark) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + if (!VALID_TX_RAWSOCK(rawsock)) { + AVB_LOG_ERROR("Setting TX mark; invalid argument passed"); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return FALSE; + } + + int fwmarkClass = TC_AVB_MARK_CLASS(mark); + + if (fwmarkClass == SR_CLASS_A) { + rawsock->queue = 0; + } else if (fwmarkClass == SR_CLASS_B) { + rawsock->queue = 1; + } else { + AVB_LOGF_ERROR("fwmarkClass %d is not proper SR_CLASS", fwmarkClass); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return FALSE; + } + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return TRUE; +} + +// Get a buffer from the ring to use for TX +U8 *atlRawsockGetTxFrame(void *pvRawsock, bool blocking, unsigned int *len) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + + if (!VALID_TX_RAWSOCK(rawsock) || len == NULL) { + AVB_LOG_ERROR("Getting TX frame; bad arguments"); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return NULL; + } + + U8 *ret = NULL; + int bBufferBusyReported = 0; + U32 iterationCount = 10; + + do { + rawsock->tx_packet = atlGetTxPacket(rawsock->atl_dev); + if (!rawsock->tx_packet && blocking) { + if (0 == bBufferBusyReported) { + if (!rawsock->txOutOfBuffer) { + AVB_LOGF_DEBUG("Getting TX frame (%p): TX buffer busy", rawsock); + } + ++rawsock->txOutOfBuffer; + ++rawsock->txOutOfBufferCyclic; + } else if (1 == bBufferBusyReported) { + AVB_LOGF_DEBUG("Getting TX frame (%p): TX buffer busy after usleep(10) verify if there are any late frames", rawsock); + } + ++bBufferBusyReported; + usleep(10); + } + } while (!rawsock->tx_packet && blocking && iterationCount--); + + if (rawsock->tx_packet) { + *len = rawsock->base.frameSize; + ret = rawsock->tx_packet->vaddr; + } + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return ret; +} + +// Release a TX frame, without marking it as ready to send +bool atlRawsockRelTxFrame(void *pvRawsock, U8 *pBuffer) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + if (!VALID_TX_RAWSOCK(rawsock) || pBuffer == NULL) { + AVB_LOG_ERROR("Releasing TX frame; invalid argument"); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return FALSE; + } + + atlRelTxPacket(rawsock->atl_dev, rawsock->queue, rawsock->tx_packet); + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return TRUE; +} + +// Release a TX frame, and mark it as ready to send +bool atlRawsockTxFrameReady(void *pvRawsock, U8 *pBuffer, unsigned int len, U64 timeNsec) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + + if (!VALID_TX_RAWSOCK(rawsock)) { + AVB_LOG_ERROR("Send; invalid argument"); + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return -1; + } + + int err; + + rawsock->tx_packet->len = len; + +#if ATL_LAUNCHTIME_ENABLED + gptpmaster2local(&gPtpTD, timeNsec, &rawsock->tx_packet->attime); +#else + rawsock->tx_packet->attime = 0; +#endif + err = atl_xmit(rawsock->atl_dev, rawsock->queue, &rawsock->tx_packet); + if (err) { + AVB_LOGF_ERROR("atl_xmit failed: %s", strerror(err)); + } + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return !err; +} +// Send all packets that are ready (i.e. tell kernel to send them) +int atlRawsockSend(void *pvRawsock) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + + // atlRawsock sends frames in atlRawsockTxFrameReady + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return 1; +} + +int atlRawsockTxBufLevel(void *pvRawsock) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK_DETAIL); + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + + int nInUse = atlTxBufLevel(rawsock->atl_dev); + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK_DETAIL); + return nInUse; +} + +unsigned long atlRawsockGetTXOutOfBuffers(void *pvRawsock) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK); + unsigned long counter = 0; + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + + if(VALID_TX_RAWSOCK(rawsock)) { + counter = rawsock->txOutOfBuffer; + } + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK); + return counter; +} + +unsigned long atlRawsockGetTXOutOfBuffersCyclic(void *pvRawsock) +{ + AVB_TRACE_ENTRY(AVB_TRACE_RAWSOCK); + unsigned long counter = 0; + atl_rawsock_t *rawsock = (atl_rawsock_t*)pvRawsock; + + if(VALID_TX_RAWSOCK(rawsock)) { + counter = rawsock->txOutOfBufferCyclic; + rawsock->txOutOfBufferCyclic = 0; + } + + AVB_TRACE_EXIT(AVB_TRACE_RAWSOCK); + return counter; +} + diff --git a/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.h b/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.h new file mode 100644 index 00000000..76e8de11 --- /dev/null +++ b/lib/avtp_pipeline/platform/Linux/rawsock/atl_rawsock.h @@ -0,0 +1,67 @@ +/************************************************************************************************************* +Copyright (c) 2019, Aquantia Corporation +All rights reserved + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ +#ifndef ATL_RAWSOCK_H +#define ATL_RAWSOCK_H + +#include "rawsock_impl.h" +#include <pcap/pcap.h> +#include "atl.h" + +typedef struct { + base_rawsock_t base; + pcap_t *handle; + device_t *atl_dev; + struct atl_packet *tx_packet; + int queue; + unsigned long txOutOfBuffer; + unsigned long txOutOfBufferCyclic; +} atl_rawsock_t; + +void *atlRawsockOpen(atl_rawsock_t* rawsock, const char *ifname, bool rx_mode, bool tx_mode, U16 ethertype, U32 frame_size, U32 num_frames); + +void atlRawsockClose(void *pvRawsock); + +bool atlRawsockTxSetMark(void *pvRawsock, int mark); + +U8 *atlRawsockGetTxFrame(void *pvRawsock, bool blocking, unsigned int *len); + +bool atlRawsockRelTxFrame(void *pvRawsock, U8 *pBuffer); + +bool atlRawsockTxFrameReady(void *pvRawsock, U8 *pBuffer, unsigned int len, U64 timeNsec); + +int atlRawsockSend(void *pvRawsock); + +int atlRawsockTxBufLevel(void *pvRawsock); + +unsigned long atlRawsockGetTXOutOfBuffers(void *pvRawsock); + +unsigned long atlRawsockGetTXOutOfBuffersCyclic(void *pvRawsock); + +#endif diff --git a/lib/avtp_pipeline/platform/Linux/rawsock/openavb_rawsock.c b/lib/avtp_pipeline/platform/Linux/rawsock/openavb_rawsock.c index c05053a5..bc67cd80 100644 --- a/lib/avtp_pipeline/platform/Linux/rawsock/openavb_rawsock.c +++ b/lib/avtp_pipeline/platform/Linux/rawsock/openavb_rawsock.c @@ -37,6 +37,9 @@ https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. #if AVB_FEATURE_IGB #include "igb_rawsock.h" #endif +#if AVB_FEATURE_ATL +#include "atl_rawsock.h" +#endif #endif #include "openavb_rawsock.h" @@ -79,6 +82,8 @@ void *openavbRawsockOpen(const char *ifname_uri, bool rx_mode, bool tx_mode, U16 #if AVB_FEATURE_PCAP #if AVB_FEATURE_IGB char proto[IF_NAMESIZE] = "igb"; +#elif AVB_FEATURE_ATL + char proto[IF_NAMESIZE] = "atl"; #else char proto[IF_NAMESIZE] = "pcap"; #endif @@ -166,6 +171,21 @@ void *openavbRawsockOpen(const char *ifname_uri, bool rx_mode, bool tx_mode, U16 // call constructor pvRawsock = igbRawsockOpen((igb_rawsock_t*)rawsock, ifname, rx_mode, tx_mode, ethertype, frame_size, num_frames); #endif +#if AVB_FEATURE_ATL + } else if (strcmp(proto, "atl") == 0) { + + AVB_LOG_INFO("Using *atl* implementation"); + + // allocate memory for rawsock object + atl_rawsock_t *rawsock = calloc(1, sizeof(atl_rawsock_t)); + if (!rawsock) { + AVB_LOG_ERROR("Creating rawsock; malloc failed"); + return NULL; + } + + // call constructor + pvRawsock = atlRawsockOpen((atl_rawsock_t*)rawsock, ifname, rx_mode, tx_mode, ethertype, frame_size, num_frames); +#endif #endif } else { AVB_LOGF_ERROR("Unknown proto %s specified.", proto); diff --git a/lib/avtp_pipeline/platform/Linux/x86_aqc_linux.cmake b/lib/avtp_pipeline/platform/Linux/x86_aqc_linux.cmake new file mode 100644 index 00000000..8be9aaf2 --- /dev/null +++ b/lib/avtp_pipeline/platform/Linux/x86_aqc_linux.cmake @@ -0,0 +1,52 @@ + +if (AVB_FEATURE_AVDECC) + set ( AVB_FEATURE_GSTREAMER 0 ) + set ( AVB_FEATURE_PCAP 0 ) + set ( AVB_FEATURE_IGB 0 ) + set ( AVB_FEATURE_ATL 0 ) +else () + set ( AVB_FEATURE_PCAP 1 ) + set ( AVB_FEATURE_ATL 1 ) + set ( AVB_FEATURE_IGB 0 ) + + set ( GSTREAMER_1_0 0 ) +endif () + + +# and another kernel sources +#set ( LINUX_KERNEL_DIR "/usr/src/kernel" ) + +# build configuration +set ( OPENAVB_HAL "x86_aqc" ) +set ( OPENAVB_OSAL "Linux" ) +set ( OPENAVB_TCAL "GNU" ) +set ( OPENAVB_PLATFORM "${OPENAVB_HAL}-${OPENAVB_OSAL}" ) + +# Platform Additions +set ( PLATFORM_INCLUDE_DIRECTORIES + ${CMAKE_SOURCE_DIR}/platform/x86_aqc/include +if (AVB_FEATURE_ATL) + ${CMAKE_SOURCE_DIR}/../atl_avb/lib +endif () + ${CMAKE_SOURCE_DIR}/openavb_common + ${CMAKE_SOURCE_DIR}/../../daemons/common + ${CMAKE_SOURCE_DIR}/../../daemons/mrpd + ${CMAKE_SOURCE_DIR}/../../daemons/maap/common +) + +if (AVB_FEATURE_ATL) + set ( PLATFORM_LINK_DIRECTORIES + ${CMAKE_SOURCE_DIR}/../atl_avb/lib + ) +endif () + +if (AVB_FEATURE_ATL) + set ( PLATFORM_LINK_LIBRARIES + atl + pci + ) +endif () + +# TODO_OPENAVB : need this? +# Set platform specific define +#set ( PLATFORM_DEFINE "AVB_DELAY_TWEAK_USEC=15" ) diff --git a/lib/avtp_pipeline/platform/Linux/x86_i210_linux.cmake b/lib/avtp_pipeline/platform/Linux/x86_i210_linux.cmake index 48e62223..2b2f7714 100644 --- a/lib/avtp_pipeline/platform/Linux/x86_i210_linux.cmake +++ b/lib/avtp_pipeline/platform/Linux/x86_i210_linux.cmake @@ -3,9 +3,11 @@ if (AVB_FEATURE_AVDECC) set ( AVB_FEATURE_GSTREAMER 0 ) set ( AVB_FEATURE_PCAP 0 ) set ( AVB_FEATURE_IGB 0 ) + set ( AVB_FEATURE_ATL 0 ) else () set ( AVB_FEATURE_PCAP 1 ) set ( AVB_FEATURE_IGB 1 ) + set ( AVB_FEATURE_ATL 0 ) set ( GSTREAMER_1_0 0 ) endif () @@ -24,7 +26,7 @@ set ( OPENAVB_PLATFORM "${OPENAVB_HAL}-${OPENAVB_OSAL}" ) set ( PLATFORM_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/platform/x86_i210/include if (AVB_FEATURE_IGB) - ${CMAKE_SOURCE_DIR}/../igb + ${CMAKE_SOURCE_DIR}/../igb_avb/lib endif () ${CMAKE_SOURCE_DIR}/openavb_common ${CMAKE_SOURCE_DIR}/../../daemons/common @@ -34,7 +36,7 @@ endif () if (AVB_FEATURE_IGB) set ( PLATFORM_LINK_DIRECTORIES - ${CMAKE_SOURCE_DIR}/../igb + ${CMAKE_SOURCE_DIR}/../igb_avb/lib ) endif () diff --git a/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.c b/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.c new file mode 100644 index 00000000..13236986 --- /dev/null +++ b/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.c @@ -0,0 +1,63 @@ +/************************************************************************************************************* +Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company +Copyright (c) 2016-2017, Harman International Industries, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#define AVB_LOG_COMPONENT "MCR" +#include "openavb_pub.h" +#include "openavb_log.h" + +#include "openavb_mcr_hal.h" + + +bool halInitMCR(U32 packetRate, U32 pushInterval, U32 timestampInterval, U32 recoveryInterval) +{ + return TRUE; +} + +bool halCloseMCR(void) +{ + return TRUE; +} + +bool halPushMCR(void) +{ + return TRUE; +} + +void halAdjustMCRNSec(S32 adjNSec) +{ +} + +void halAdjustMCRGranularityNSec(U32 adjGranularityNSec) +{ +} + + + diff --git a/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.h b/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.h new file mode 100644 index 00000000..c6db6044 --- /dev/null +++ b/lib/avtp_pipeline/platform/x86_aqc/mcr/openavb_mcr_hal.h @@ -0,0 +1,38 @@ +/************************************************************************************************************* +Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company +Copyright (c) 2016-2017, Harman International Industries, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#ifndef OPENAVB_MCR_HAL_H +#define OPENAVB_MCR_HAL_H + +#include "openavb_platform.h" +#include "openavb_mcr_hal_pub.h" + +#endif // OPENAVB_MCR_HAL_H diff --git a/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.c b/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.c new file mode 100644 index 00000000..d881204f --- /dev/null +++ b/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.c @@ -0,0 +1,278 @@ +/************************************************************************************************************* +Copyright (c) 2019, Aquantia Corporation +All rights reserved + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#include "openavb_atl.h" +#include "openavb_osal.h" +#include "avb_atl.h" +#include "atl.h" + +#define AVB_LOG_COMPONENT "HAL Ethernet" +#include "openavb_pub.h" +#include "openavb_log.h" +#include "openavb_trace.h" + + +static pthread_mutex_t gAtlDeviceMutex = PTHREAD_MUTEX_INITIALIZER; +#define LOCK() pthread_mutex_lock(&gAtlDeviceMutex) +#define UNLOCK() pthread_mutex_unlock(&gAtlDeviceMutex) + +static struct atl_dma_alloc g_pages[ATL_PAGES]; +static struct atl_packet *g_free_packets; + +static device_t *atl_dev = NULL; +static int atl_dev_users = 0; // time uses it + +static int g_totalBuffers = 0; +static int g_usedBuffers = -1; + +static int count_packets(struct atl_packet *packet) +{ + int count=0; + while (packet) { + count++; + packet = packet->next; + } + return count; +} + +static struct atl_packet* alloc_page(device_t* dev, struct atl_dma_alloc *a_page) +{ + int err = atl_dma_malloc_page(dev, a_page); + if (err) { + AVB_LOGF_ERROR("atl_dma_malloc_page failed: %s", strerror(err)); + return NULL; + } + + struct atl_packet *free_packets; + struct atl_packet a_packet; + + a_packet.attime = a_packet.flags = 0; + a_packet.map.paddr = a_page->dma_paddr; + a_packet.map.mmap_size = a_page->mmap_size; + a_packet.offset = 0; + a_packet.vaddr = a_page->dma_vaddr + a_packet.offset; + a_packet.len = ATL_MTU; + a_packet.next = NULL; + + free_packets = NULL; + + /* divide the dma page into buffers for packets */ + int i; + for (i = 0; i < a_page->mmap_size / ATL_MTU; i++) { + struct atl_packet *tmp_packet = malloc(sizeof(struct atl_packet)); + if (!tmp_packet) { + AVB_LOG_ERROR("failed to allocate atl_packet memory!"); + return false; + } + *tmp_packet = a_packet; + tmp_packet->offset = (i * ATL_MTU); + tmp_packet->vaddr += tmp_packet->offset; + tmp_packet->next = free_packets; + memset(tmp_packet->vaddr, 0, ATL_MTU); + free_packets = tmp_packet; + } + return free_packets; +} + +device_t *atlAcquireDevice(const char *ifname) +{ + AVB_TRACE_ENTRY(AVB_TRACE_HAL_ETHER); + + LOCK(); + if (!atl_dev) { + device_t *tmp_dev = calloc(1, sizeof(device_t)); + const char *complex_ifname = NULL; + if (!tmp_dev) { + AVB_LOGF_ERROR("Cannot allocate memory for device: %s", strerror(errno)); + goto unlock; + } + + complex_ifname = strchr(ifname, 0x3a); + if( complex_ifname != NULL && strlen(complex_ifname) > 1 ) { + tmp_dev->ifname = strdup(&complex_ifname[1]); + } else { + tmp_dev->ifname = strdup(ifname); + } + +#ifdef AVB_LOG_ON + atl_init_avb_log(&__avbLogFn, "AQ_AVTP"); +#endif // AVB_LOG_ON + + int err = pci_connect(tmp_dev); + if (err) { + AVB_LOGF_ERROR("connect failed (%s) - are you running as root?", strerror(err)); + goto unlock; + } + + err = atl_init(tmp_dev); + if (err) { + AVB_LOGF_ERROR("init failed (%s) - is the driver really loaded?", strerror(err)); + atl_detach(tmp_dev); + goto unlock; + } + + + int i; + for (i = 0; i < ATL_PAGES; i++) { + struct atl_packet* free_packets = alloc_page(tmp_dev, &g_pages[i]); + if (!g_free_packets) { + g_free_packets = free_packets; + } else { + struct atl_packet* last_packet = g_free_packets; + while (last_packet->next) { + last_packet = last_packet->next; + } + last_packet->next = free_packets; + } + } + + g_totalBuffers = count_packets(g_free_packets); + + AVB_LOGF_INFO("TX buffers: %d", g_totalBuffers); + + AVB_LOGF_INFO("ATL launch time feature is %s", ATL_LAUNCHTIME_ENABLED ? "ENABLED" : "DISABLED"); + + atl_dev = tmp_dev; +unlock: + if (!atl_dev) + free(tmp_dev); + } + + if (atl_dev) { + atl_dev_users += 1; + AVB_LOGF_DEBUG("atl_dev_users %d", atl_dev_users); + } + UNLOCK(); + + AVB_TRACE_EXIT(AVB_TRACE_HAL_ETHER); + return atl_dev; +} + +void atlReleaseDevice(device_t* dev) +{ + AVB_TRACE_ENTRY(AVB_TRACE_HAL_ETHER); + + struct atl_packet *cleaned_packets; + struct atl_packet *tmp_packet; + + LOCK(); + + atl_dev_users -= 1; + AVB_LOGF_DEBUG("atl_dev_users %d", atl_dev_users); + + if (atl_dev && atl_dev_users <= 0) { + int i; + + atl_stop_tx(dev, 0, &cleaned_packets); + + tmp_packet = cleaned_packets; + + while( tmp_packet ) { + cleaned_packets = tmp_packet->next; + if( tmp_packet->extra ) { + free(tmp_packet->extra); + } + free(tmp_packet); + tmp_packet = cleaned_packets; + } + + tmp_packet = g_free_packets; + while( tmp_packet ) { + g_free_packets = tmp_packet->next; + if( tmp_packet->extra ) { + free(tmp_packet->extra); + } + free(tmp_packet); + tmp_packet = g_free_packets; + } + + for (i = 0; i < ATL_PAGES; i++) + atl_dma_free_page(atl_dev, &g_pages[i]); + + atl_detach(atl_dev); + free(atl_dev); + atl_dev = NULL; + g_free_packets = NULL; + } + + UNLOCK(); + + AVB_TRACE_EXIT(AVB_TRACE_HAL_ETHER); +} + +struct atl_packet *atlGetTxPacket(device_t* dev) +{ + AVB_TRACE_ENTRY(AVB_TRACE_HAL_ETHER); + + LOCK(); + + struct atl_packet* tx_packet = g_free_packets; + if (!tx_packet && atl_dev) { + struct atl_packet *cleaned_packets; + atl_clean(dev, &cleaned_packets); + while (cleaned_packets) { + struct atl_packet *tmp_packet = cleaned_packets; + cleaned_packets = cleaned_packets->next; + tmp_packet->next = g_free_packets; + g_free_packets = tmp_packet; + } + tx_packet = g_free_packets; + + g_usedBuffers = g_totalBuffers - count_packets(g_free_packets); + } + + if (tx_packet) { + g_free_packets = tx_packet->next; + tx_packet->next = NULL; + } + UNLOCK(); + AVB_TRACE_EXIT(AVB_TRACE_HAL_ETHER); + return tx_packet; +} + +void atlRelTxPacket(device_t* dev, int queue, struct atl_packet *tx_packet) +{ + AVB_TRACE_ENTRY(AVB_TRACE_HAL_ETHER); + + LOCK(); + tx_packet->next = g_free_packets; + g_free_packets = tx_packet; + + UNLOCK(); + + AVB_TRACE_EXIT(AVB_TRACE_HAL_ETHER); +} + +int atlTxBufLevel(device_t *dev) +{ + AVB_TRACE_ENTRY(AVB_TRACE_HAL_ETHER); + AVB_TRACE_EXIT(AVB_TRACE_HAL_ETHER); + return g_usedBuffers; +} diff --git a/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.h b/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.h new file mode 100644 index 00000000..b6cd95c8 --- /dev/null +++ b/lib/avtp_pipeline/platform/x86_aqc/openavb_atl.h @@ -0,0 +1,54 @@ +/************************************************************************************************************* +Copyright (c) 2019, Aquantia Corporation +All rights reserved + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#ifndef OPENAVB_ATL_H +#define OPENAVB_ATL_H 1 + +#include "openavb_platform.h" +#include "openavb_types_base.h" + +#include "atl.h" + +#define ATL_MTU 1522 + +// how many pages to alloc for tx buffers (2 frames fit in one page) +#define ATL_PAGES 2 + +device_t *atlAcquireDevice(const char *ifname); + +void atlReleaseDevice(device_t *atl_dev); + +struct atl_packet *atlGetTxPacket(device_t* dev); + +void atlRelTxPacket(device_t* dev, int queue, struct atl_packet *tx_packet); + +int atlTxBufLevel(device_t *dev); + +#endif // OPENAVB_ATL_H diff --git a/lib/avtp_pipeline/platform/x86_aqc/openavb_hal.h b/lib/avtp_pipeline/platform/x86_aqc/openavb_hal.h new file mode 100644 index 00000000..10114eb4 --- /dev/null +++ b/lib/avtp_pipeline/platform/x86_aqc/openavb_hal.h @@ -0,0 +1,39 @@ +/************************************************************************************************************* +Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company +Copyright (c) 2016-2017, Harman International Industries, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Attributions: The inih library portion of the source code is licensed from +Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt. +Complete license and copyright information can be found at +https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. +*************************************************************************************************************/ + +#ifndef _OPENAVB_HAL_H +#define _OPENAVB_HAL_H + +// Note this remains for backwards compatabilty with older prots. See openavb_mcr_hall_pub.h for newer APIs +// halPushMCR() API not defined +#define HAL_PUSH_MCR(mcrTimeStampPtr) FALSE + +#endif // _OPENAVB_HAL_H diff --git a/lib/avtp_pipeline/qmgr/openavb_qmgr.c b/lib/avtp_pipeline/qmgr/openavb_qmgr.c index 5c054eb2..bc25ffa9 100644 --- a/lib/avtp_pipeline/qmgr/openavb_qmgr.c +++ b/lib/avtp_pipeline/qmgr/openavb_qmgr.c @@ -46,6 +46,9 @@ https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175. #if (AVB_FEATURE_IGB) #include "openavb_igb.h" #endif +#if (AVB_FEATURE_ATL) +#include "openavb_atl.h" +#endif #define AVB_DEFAULT_QDISC_MODE AVB_SHAPER_HWQ_PER_CLASS @@ -56,6 +59,9 @@ typedef struct { #if (AVB_FEATURE_IGB) device_t *igb_dev; #endif +#if (AVB_FEATURE_ATL) + device_t *atl_dev; +#endif int mode; int ifindex; char ifname[IFNAMSIZ + 10]; // Include space for the socket type prefix (e.g. "simple:eth0") @@ -69,6 +75,9 @@ static qdisc_data_t qdisc_data = { #if (AVB_FEATURE_IGB) NULL, #endif +#if (AVB_FEATURE_ATL) + NULL, +#endif 0, 0, {0}, 0, 0, 0, 0 }; @@ -103,13 +112,13 @@ static qmgrStream_t qmgr_streams[MAX_AVB_STREAMS]; static bool setupHWQueue(int nClass, unsigned classBytesPerSec) { int err = 0; -#if (AVB_FEATURE_IGB) +#if (AVB_FEATURE_IGB) || (AVB_FEATURE_ATL) U32 class_a_bytes_per_sec, class_b_bytes_per_sec; #endif AVB_TRACE_ENTRY(AVB_TRACE_QUEUE_MANAGER); -#if (AVB_FEATURE_IGB) +#if (AVB_FEATURE_IGB) || (AVB_FEATURE_ATL) if (nClass == SR_CLASS_A) { class_a_bytes_per_sec = classBytesPerSec; class_b_bytes_per_sec = qmgr_classes[SR_CLASS_B].classBytesPerSec; @@ -117,9 +126,17 @@ static bool setupHWQueue(int nClass, unsigned classBytesPerSec) class_a_bytes_per_sec = qmgr_classes[SR_CLASS_A].classBytesPerSec; class_b_bytes_per_sec = classBytesPerSec; } +#if (AVB_FEATURE_IGB) err = igb_set_class_bandwidth2(qdisc_data.igb_dev, class_a_bytes_per_sec, class_b_bytes_per_sec); if (err) AVB_LOGF_ERROR("Adding stream; igb_set_class_bandwidth failed: %s", strerror(err)); +#else // (AVB_FEATURE_ATL) + err = atl_set_class_bandwidth(qdisc_data.atl_dev, + class_a_bytes_per_sec, + class_b_bytes_per_sec); + if (err) + AVB_LOGF_ERROR("Adding stream; atl_set_class_bandwidth failed: %s", strerror(err)); +#endif #endif AVB_TRACE_EXIT(AVB_TRACE_QUEUE_MANAGER); @@ -268,6 +285,14 @@ bool openavbQmgrInitialize(int mode, int ifindex, const char* ifname, unsigned m } else #endif +#if (AVB_FEATURE_ATL) + if ( qdisc_data.mode != AVB_SHAPER_DISABLED + && (qdisc_data.atl_dev = atlAcquireDevice(ifname)) == 0) + { + AVB_LOG_ERROR("Initializing QMgr; unable to acquire atl device"); + } + else +#endif { // Initialize data for classes and streams memset(qmgr_classes, 0, sizeof(qmgr_classes)); @@ -315,6 +340,10 @@ void openavbQmgrFinalize(void) igbReleaseDevice(qdisc_data.igb_dev); qdisc_data.igb_dev = NULL; #endif +#if (AVB_FEATURE_ATL) + atlReleaseDevice(qdisc_data.atl_dev); + qdisc_data.atl_dev = NULL; +#endif } UNLOCK(); diff --git a/lib/avtp_pipeline/rawsock/CMakeLists.txt b/lib/avtp_pipeline/rawsock/CMakeLists.txt index e3e0f49e..7fac0725 100644 --- a/lib/avtp_pipeline/rawsock/CMakeLists.txt +++ b/lib/avtp_pipeline/rawsock/CMakeLists.txt @@ -10,6 +10,13 @@ if (AVB_FEATURE_PCAP) ${AVB_HAL_DIR}/openavb_igb.c ) endif () + if (AVB_FEATURE_ATL) + message("-- Rawsock ATL enabled") + SET (ATL_FILES + ${AVB_OSAL_DIR}/rawsock/atl_rawsock.c + ${AVB_HAL_DIR}/openavb_atl.c + ) + endif () endif () SET (SRC_FILES ${SRC_FILES} ${AVB_SRC_DIR}/rawsock/rawsock_impl.c @@ -19,5 +26,6 @@ SET (SRC_FILES ${SRC_FILES} ${AVB_OSAL_DIR}/rawsock/sendmmsg_rawsock.c ${PCAP_FILES} ${IGB_FILES} + ${ATL_FILES} PARENT_SCOPE ) diff --git a/lib/avtp_pipeline/tl/openavb_talker.c b/lib/avtp_pipeline/tl/openavb_talker.c index 24fdacdd..6794e167 100644 --- a/lib/avtp_pipeline/tl/openavb_talker.c +++ b/lib/avtp_pipeline/tl/openavb_talker.c @@ -238,7 +238,7 @@ static inline bool talkerDoStream(tl_state_t *pTLState) // sleep until the next interval SLEEP_UNTIL_NSEC(pTalkerData->nextCycleNS); } else { -#if !IGB_LAUNCHTIME_ENABLED +#if !IGB_LAUNCHTIME_ENABLED && !ATL_LAUNCHTIME_ENABLED SPIN_UNTIL_NSEC(pTalkerData->nextCycleNS); #endif } diff --git a/lib/avtp_pipeline/util/openavb_log.c b/lib/avtp_pipeline/util/openavb_log.c index 5d32843f..46d827cf 100644 --- a/lib/avtp_pipeline/util/openavb_log.c +++ b/lib/avtp_pipeline/util/openavb_log.c @@ -243,7 +243,7 @@ extern void DLL_EXPORT avbLogExit() logOutputFd = NULL; } -extern void DLL_EXPORT avbLogFn( +void __avbLogFn( int level, const char *tag, const char *company, @@ -251,12 +251,9 @@ extern void DLL_EXPORT avbLogFn( const char *path, int line, const char *fmt, - ...) + va_list args) { if (level <= AVB_LOG_LEVEL) { - va_list args; - va_start(args, fmt); - LOG_LOCK(); vsprintf(msg, fmt, args); @@ -313,12 +310,26 @@ extern void DLL_EXPORT avbLogFn( } } - va_end(args); - LOG_UNLOCK(); } } +extern void DLL_EXPORT avbLogFn( + int level, + const char *tag, + const char *company, + const char *component, + const char *path, + int line, + const char *fmt, + ...) +{ + va_list args; + va_start(args, fmt); + __avbLogFn(level, tag, company, component, path, line, fmt, args); + va_end(args); +} + extern void DLL_EXPORT avbLogRT(int level, bool bBegin, bool bItem, bool bEnd, char *pFormat, log_rt_datatype_t dataType, void *pVar) { if (logRTQueue) { |