diff options
Diffstat (limited to 'lib/avtp_pipeline/platform')
11 files changed, 904 insertions, 2 deletions
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 |