diff --git a/source/include/NetworkInterface.h b/source/include/NetworkInterface.h index 50b354ca9d..646f088d5f 100644 --- a/source/include/NetworkInterface.h +++ b/source/include/NetworkInterface.h @@ -48,7 +48,7 @@ */ /* The following function is defined only when BufferAllocation_1.c is linked in the project. */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ); +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ); BaseType_t xGetPhyLinkStatus( struct xNetworkInterface * pxInterface ); diff --git a/source/portable/BufferManagement/BufferAllocation_1.c b/source/portable/BufferManagement/BufferAllocation_1.c index dfb0ba0f44..566d94867c 100644 --- a/source/portable/BufferManagement/BufferAllocation_1.c +++ b/source/portable/BufferManagement/BufferAllocation_1.c @@ -70,6 +70,8 @@ static NetworkBufferDescriptor_t xNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DES * packet. No resizing will be done. */ const BaseType_t xBufferAllocFixedSize = pdTRUE; +static size_t uxMaxNetworkInterfaceAllocatedSizeBytes; + /* The semaphore used to obtain network buffers. */ static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; @@ -201,7 +203,10 @@ BaseType_t xNetworkBuffersInitialise( void ) /* Initialise all the network buffers. The buffer storage comes * from the network interface, and different hardware has different * requirements. */ - vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers ); + uxMaxNetworkInterfaceAllocatedSizeBytes = uxNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers ); + + /* The allocated buffer should hold atleast ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER bytes */ + configASSERT( ( uxMaxNetworkInterfaceAllocatedSizeBytes >= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) ); for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) { @@ -238,7 +243,7 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS UBaseType_t uxCount; if( ( xNetworkBufferSemaphore != NULL ) && - ( xRequestedSizeBytes <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) ) + ( xRequestedSizeBytes <= uxMaxNetworkInterfaceAllocatedSizeBytes ) ) { /* If there is a semaphore available, there is a network buffer * available. */ @@ -429,7 +434,7 @@ UBaseType_t uxGetNumberOfFreeNetworkBuffers( void ) NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, size_t xNewSizeBytes ) { - if( xNewSizeBytes <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) + if( xNewSizeBytes <= uxMaxNetworkInterfaceAllocatedSizeBytes ) { /* In BufferAllocation_1.c all network buffer are allocated with a * maximum size of 'ipTOTAL_ETHERNET_FRAME_SIZE'.No need to resize the diff --git a/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c b/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c index dabedde096..f88633478f 100644 --- a/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c +++ b/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c @@ -499,9 +499,10 @@ void xRxCallback( void ) #if ( ipUSE_STATIC_ALLOCATION == 1 ) -/* Next provide the vNetworkInterfaceAllocateRAMToBuffers() function, which - * simply fills in the pucEthernetBuffer member of each descriptor. */ - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +/* Next provide the uxNetworkInterfaceAllocateRAMToBuffers() function, which + * simply fills in the pucEthernetBuffer member of each descriptor and returns + * the allocated buffer size. */ + size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { BaseType_t x; @@ -515,6 +516,8 @@ void xRxCallback( void ) * future versions. */ *( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] ); } + + return( NETWORK_BUFFER_SIZE - ipBUFFER_PADDING ); } #endif /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */ diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index b79d1008f1..0e37bdd6f3 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -1409,7 +1409,7 @@ static void vCheckBuffersAndQueue( void ) /*-----------------------------------------------------------*/ extern uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * NETWORK_BUFFER_SIZE ]; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { uint8_t * ucRAMBuffer = ucNetworkPackets; uint32_t ulIndex; @@ -1422,6 +1422,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB } cache_clean_invalidate(); + + return( NETWORK_BUFFER_SIZE - ipBUFFER_PADDING ); } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c b/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c index 5f4e5742b4..0f5d8b03c8 100644 --- a/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c +++ b/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c @@ -332,7 +332,7 @@ BaseType_t xNetworkInterfaceInitialise( void ) static __attribute__( ( section( "._ramAHB32" ) ) ) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { uint8_t * ucRAMBuffer = ucNetworkPackets; uint32_t ul; @@ -343,6 +343,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); ucRAMBuffer += niBUFFER_1_PACKET_SIZE; } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c index d6a822fb0b..9ec1312a7b 100644 --- a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c +++ b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c @@ -372,11 +372,13 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB /* statically allocate the buffers */ /* allocating them as uint32_t's to force them into word alignment, a requirement of the DMA. */ __ALIGN_BEGIN static uint32_t buffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ ( ipBUFFER_PADDING + ENET_RXBUFF_SIZE ) / sizeof( uint32_t ) + 1 ] __ALIGN_END; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { for( int x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) { pxNetworkBuffers[ x ].pucEthernetBuffer = ( uint8_t * ) &buffers[ x ][ 0 ] + ipBUFFER_PADDING; buffers[ x ][ 0 ] = ( uint32_t ) &pxNetworkBuffers[ x ]; } + + return ENET_RXBUFF_SIZE; } diff --git a/source/portable/NetworkInterface/M487/NetworkInterface.c b/source/portable/NetworkInterface/M487/NetworkInterface.c index 32b3208031..579274620d 100644 --- a/source/portable/NetworkInterface/M487/NetworkInterface.c +++ b/source/portable/NetworkInterface/M487/NetworkInterface.c @@ -180,7 +180,7 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { uint8_t * ucRAMBuffer = ucNetworkPackets; uint32_t ul; @@ -191,6 +191,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); ucRAMBuffer += niBUFFER_1_PACKET_SIZE; } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } diff --git a/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c b/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c index 1c55f82dbf..30c90af281 100644 --- a/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c +++ b/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c @@ -368,7 +368,7 @@ static BaseType_t xMPS2_NetworkInterfaceOutput( NetworkInterface_t * pxInterface } /*-----------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { /* FIX ME if you want to use BufferAllocation_1.c, which uses statically * allocated network buffers. */ @@ -377,6 +377,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB * without implementing this function. */ configASSERT( xRxTaskHandle == ( TaskHandle_t ) 1 ); ( void ) pxNetworkBuffers; + return 0; } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c b/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c index ac68594ac2..57659541ca 100644 --- a/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c +++ b/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c @@ -485,7 +485,7 @@ static BaseType_t xLAN91C111_NetworkInterfaceOutput( NetworkInterface_t * pxInte } /*-----------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { /* FIX ME if you want to use BufferAllocation_1.c, which uses statically * allocated network buffers. */ @@ -494,6 +494,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB * without implementing this function. */ configASSERT( 0 ); ( void ) pxNetworkBuffers; + return 0; } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/MPS4_CS315/NetworkInterface.c b/source/portable/NetworkInterface/MPS4_CS315/NetworkInterface.c index ac68594ac2..57659541ca 100644 --- a/source/portable/NetworkInterface/MPS4_CS315/NetworkInterface.c +++ b/source/portable/NetworkInterface/MPS4_CS315/NetworkInterface.c @@ -485,7 +485,7 @@ static BaseType_t xLAN91C111_NetworkInterfaceOutput( NetworkInterface_t * pxInte } /*-----------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { /* FIX ME if you want to use BufferAllocation_1.c, which uses statically * allocated network buffers. */ @@ -494,6 +494,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB * without implementing this function. */ configASSERT( 0 ); ( void ) pxNetworkBuffers; + return 0; } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/RX/NetworkInterface.c b/source/portable/NetworkInterface/RX/NetworkInterface.c index 516da7b450..0aa3815a9b 100644 --- a/source/portable/NetworkInterface/RX/NetworkInterface.c +++ b/source/portable/NetworkInterface/RX/NetworkInterface.c @@ -416,13 +416,13 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters ) /*********************************************************************************************************************** - * Function Name: vNetworkInterfaceAllocateRAMToBuffers () + * Function Name: uxNetworkInterfaceAllocateRAMToBuffers () * Description : . * Arguments : pxNetworkBuffers * Return Value : none **********************************************************************************************************************/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { uint32_t ul; uint8_t * buffer_address; @@ -443,7 +443,9 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB *( ( unsigned * ) buffer_address ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); buffer_address += ETHER_CFG_BUFSIZE; } -} /* End of function vNetworkInterfaceAllocateRAMToBuffers() */ + + return( ETHER_CFG_BUFSIZE - ipBUFFER_PADDING ); +} /* End of function uxNetworkInterfaceAllocateRAMToBuffers() */ /*********************************************************************************************************************** * Function Name: prvLinkStatusChange () diff --git a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c index 2e06048bd0..6d466c08df 100644 --- a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c @@ -1377,7 +1377,7 @@ static BaseType_t xSTM32F_GetPhyLinkStatus( NetworkInterface_t * pxInterface ) /* Uncomment this in case BufferAllocation_1.c is used. */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static #if defined( STM32F7xx ) @@ -1393,6 +1393,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); ucRAMBuffer += ETH_MAX_PACKET_SIZE; } + return (ETH_MAX_PACKET_SIZE - ipBUFFER_PADDING); } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c index 6536b3085a..76c6eac448 100644 --- a/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c @@ -1034,7 +1034,7 @@ uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ETH_RX_BUF_SI #endif /* ( ipconfigZERO_COPY_RX_DRIVER != 0 || ipconfigZERO_COPY_TX_DRIVER != 0 ) */ __attribute__( ( aligned( 32 ) ) ); -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { uint8_t * ucRAMBuffer = ucNetworkPackets; uint32_t ul; @@ -1045,6 +1045,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); ucRAMBuffer += ETH_RX_BUF_SIZE; } + + return (ETH_RX_BUF_SIZE - ipBUFFER_PADDING); } /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/STM32/NetworkInterface.c b/source/portable/NetworkInterface/STM32/NetworkInterface.c index 3c432f7a49..de2abd39e4 100644 --- a/source/portable/NetworkInterface/STM32/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32/NetworkInterface.c @@ -1971,7 +1971,7 @@ void HAL_ETH_TxFreeCallback( uint32_t * pulBuff ) /*===========================================================================*/ /*---------------------------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ niEMAC_TOTAL_BUFFER_SIZE ] __ALIGNED( niEMAC_BUF_ALIGNMENT ) __attribute__( ( section( niEMAC_BUFFERS_SECTION ) ) ); @@ -1985,6 +1985,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( ucNetworkPackets[ uxIndex ][ ipBUFFER_PADDING ] ); *( ( uint32_t * ) &( ucNetworkPackets[ uxIndex ][ 0 ] ) ) = ( uint32_t ) ( &( pxNetworkBuffers[ uxIndex ] ) ); } + + return (niEMAC_TOTAL_BUFFER_SIZE - ipBUFFER_PADDING); } /*---------------------------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/TM4C/NetworkInterface.c b/source/portable/NetworkInterface/TM4C/NetworkInterface.c index 5a5a4f1cd3..bca3ae8573 100644 --- a/source/portable/NetworkInterface/TM4C/NetworkInterface.c +++ b/source/portable/NetworkInterface/TM4C/NetworkInterface.c @@ -57,7 +57,7 @@ #include "NetworkInterface.h" #include "phyHandling.h" -#define BUFFER_SIZE_WO_PADDING ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) +#define BUFFER_SIZE_WO_PADDING ( ipTOTAL_ETHERNET_FRAME_SIZE ) #define BUFFER_SIZE ( BUFFER_SIZE_WO_PADDING + ipBUFFER_PADDING ) #define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x7UL ) #define PHY_PHYS_ADDR 0 @@ -403,7 +403,7 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB return success; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +void uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { BaseType_t i; @@ -415,6 +415,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB /* Set the 'hidden' reference to the descriptor for use in DMA interrupts */ *( ( uint32_t * ) &_network_buffers[ i ][ 0 ] ) = ( uint32_t ) &( ( pxNetworkBuffers[ i ] ) ); } + + return( BUFFER_SIZE_ROUNDED_UP - ipBUFFER_PADDING ); } static BaseType_t _ethernet_mac_get( uint8_t * mac_address_bytes ) diff --git a/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c b/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c index bac7e4587c..07ee3b10b2 100644 --- a/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c +++ b/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c @@ -997,7 +997,7 @@ BaseType_t xGetPhyLinkStatus( void ) #define BUFFER_SIZE_ALLOC1 ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) #define BUFFER_SIZE_ALLOC1_ROUNDED_UP ( ( BUFFER_SIZE_ALLOC1 + 7 ) & ~0x07UL ) static uint8_t ucBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ BUFFER_SIZE_ALLOC1_ROUNDED_UP ]; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { BaseType_t x; @@ -1011,4 +1011,6 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB * future versions. */ *( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] ); } + + return( BUFFER_SIZE_ALLOC1_ROUNDED_UP - ipBUFFER_PADDING ); } diff --git a/source/portable/NetworkInterface/WinPCap/NetworkInterface.c b/source/portable/NetworkInterface/WinPCap/NetworkInterface.c index e7f8975a8a..80c8eb1f5e 100644 --- a/source/portable/NetworkInterface/WinPCap/NetworkInterface.c +++ b/source/portable/NetworkInterface/WinPCap/NetworkInterface.c @@ -946,7 +946,7 @@ static const char * prvRemoveSpaces( char * pcBuffer, #define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) #define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x07UL ) -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPacketBuffers = NULL; size_t uxIndex; @@ -979,4 +979,6 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); } } + + return( BUFFER_SIZE_ROUNDED_UP - ipBUFFER_PADDING ); } diff --git a/source/portable/NetworkInterface/Zynq/NetworkInterface.c b/source/portable/NetworkInterface/Zynq/NetworkInterface.c index a90c0d14ac..ba4cdc3f8d 100644 --- a/source/portable/NetworkInterface/Zynq/NetworkInterface.c +++ b/source/portable/NetworkInterface/Zynq/NetworkInterface.c @@ -490,7 +490,7 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, /*-----------------------------------------------------------*/ #if ( nicUSE_UNCACHED_MEMORY == 0 ) - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) + size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); uint8_t * ucRAMBuffer = ucNetworkPackets; @@ -502,9 +502,11 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); ucRAMBuffer += niBUFFER_1_PACKET_SIZE; } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } #else /* if ( nicUSE_UNCACHED_MEMORY == 0 ) */ - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) + size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPackets = NULL; @@ -525,6 +527,8 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, } } } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } #endif /* ( nicUSE_UNCACHED_MEMORY == 0 ) */ /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c b/source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c index 34b9d8d436..a9b9e2b03d 100644 --- a/source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c +++ b/source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c @@ -89,7 +89,7 @@ #endif #define TX_OFFSET ipconfigPACKET_FILLER_SIZE -#define dmaRX_TX_BUFFER_SIZE 1536 +#define dmaRX_TX_BUFFER_SIZE ( 1536 - ipBUFFER_PADDING ) /* Defined in NetworkInterface.c */ extern TaskHandle_t xEMACTaskHandles[ XPAR_XEMACPS_NUM_INSTANCES ]; diff --git a/source/portable/NetworkInterface/board_family/NetworkInterface.c b/source/portable/NetworkInterface/board_family/NetworkInterface.c index dfb1979c61..2a43e48d16 100644 --- a/source/portable/NetworkInterface/board_family/NetworkInterface.c +++ b/source/portable/NetworkInterface/board_family/NetworkInterface.c @@ -64,9 +64,10 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB return pdFALSE; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { /* FIX ME. */ + return 0; } BaseType_t xGetPhyLinkStatus( void ) diff --git a/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c b/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c index 234ee8cb7c..e2e67f0b52 100644 --- a/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c +++ b/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c @@ -335,7 +335,7 @@ static BaseType_t xNetworkInterfaceOutput( NetworkInterface_t * pxNetif, * Called when the BufferAllocation1 scheme is used. * @param [in,out] pxNetworkBuffers Pointer to an array of NetworkBufferDescriptor_t to populate. */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPacketBuffers = NULL; size_t uxIndex; @@ -368,6 +368,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); } } + + return( BUFFER_SIZE_ROUNDED_UP - ipBUFFER_PADDING ); } BaseType_t xGetPhyLinkStatus( NetworkInterface_t * pxNetif ) diff --git a/source/portable/NetworkInterface/linux/NetworkInterface.c b/source/portable/NetworkInterface/linux/NetworkInterface.c index a198be31cb..bb31a8d323 100644 --- a/source/portable/NetworkInterface/linux/NetworkInterface.c +++ b/source/portable/NetworkInterface/linux/NetworkInterface.c @@ -1098,7 +1098,7 @@ static void print_hex( unsigned const char * const bin_data, * Called when the BufferAllocation1 scheme is used. * @param [in,out] pxNetworkBuffers Pointer to an array of NetworkBufferDescriptor_t to populate. */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPacketBuffers = NULL; size_t uxIndex; @@ -1131,4 +1131,6 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); } } + + return( BUFFER_SIZE_ROUNDED_UP - ipBUFFER_PADDING ); } diff --git a/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c b/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c index 26baf2ddc9..d20d5b2973 100644 --- a/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c +++ b/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c @@ -181,9 +181,15 @@ BaseType_t xNetworkInterfaceInitialise( void ) return ( xInterfaceState == INTERFACE_UP && ret == WM_SUCCESS ) ? pdTRUE : pdFALSE; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { /* FIX ME. */ + + /* Hard force an assert as this driver cannot be used with BufferAllocation_1.c + * without implementing this function. */ + configASSERT( 0 ); + ( void ) pxNetworkBuffers; + return 0; } BaseType_t xGetPhyLinkStatus( void ) diff --git a/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c b/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c index bf97e3e276..ef060b3e22 100644 --- a/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c +++ b/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c @@ -599,7 +599,7 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, /*-----------------------------------------------------------*/ #if ( nicUSE_UNCACHED_MEMORY == 0 ) - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) + size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); uint8_t * ucRAMBuffer = ucNetworkPackets; @@ -611,9 +611,11 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, *( ( uintptr_t * ) ucRAMBuffer ) = ( uintptr_t ) &( pxNetworkBuffers[ ul ] ); ucRAMBuffer += niBUFFER_1_PACKET_SIZE; } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } #else /* if ( nicUSE_UNCACHED_MEMORY == 0 ) */ - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) + size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPackets = NULL; @@ -634,6 +636,8 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, } } } + + return( niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING ); } #endif /* ( nicUSE_UNCACHED_MEMORY == 0 ) */ /*-----------------------------------------------------------*/ diff --git a/source/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c b/source/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c index f56e18611b..73c0ec183b 100644 --- a/source/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c +++ b/source/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c @@ -68,9 +68,9 @@ #endif /* ( ipconfigNETWORK_MTU > 1526 ) */ #if ( USE_JUMBO_FRAMES == 1 ) - #define dmaRX_TX_BUFFER_SIZE 10240 + #define dmaRX_TX_BUFFER_SIZE ( 10240 - ipBUFFER_PADDING ) #else - #define dmaRX_TX_BUFFER_SIZE 1536 + #define dmaRX_TX_BUFFER_SIZE ( 1536 - ipBUFFER_PADDING ) #endif /* ( USE_JUMBO_FRAMES == 1 ) */ extern XScuGic xInterruptController; diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json index ff5898c18c..8e0123bdc9 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json @@ -4,7 +4,7 @@ "CBMCFLAGS": [ "--unwind {MINIMUM_PACKET_BYTES}", - "--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,vNetworkInterfaceAllocateRAMToBuffers.0:3" + "--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,uxNetworkInterfaceAllocateRAMToBuffers.0:3" ], "OBJS": [ diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c index 24762ed1cd..3d49a835f1 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c @@ -23,19 +23,28 @@ #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { + /* + * In the case of buffer allocation scheme 1 the network buffers are + * fixed size and its asserted in xNetworkBuffersInitialise call that the + * buffer is at least ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER bytes + * + * Refer: + * configASSERT( ( uxMaxNetworkInterfaceAllocatedSizeBytes >= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) ); + * + */ + size_t xAllocSize = ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER; + for( int x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) { NetworkBufferDescriptor_t * current = &pxNetworkBuffers[ x ]; - #if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 ) - current->pucEthernetBuffer = malloc( sizeof( ARPPacket_t ) + ( ipconfigETHERNET_MINIMUM_PACKET_BYTES - sizeof( ARPPacket_t ) ) ); - #else - current->pucEthernetBuffer = malloc( sizeof( ARPPacket_t ) ); - #endif + current->pucEthernetBuffer = malloc( xAllocSize ); __CPROVER_assume( current->pucEthernetBuffer != NULL ); current->xDataLength = sizeof( ARPPacket_t ); } + + return xAllocSize; } /* The code expects that the Semaphore creation relying on pvPortMalloc diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md index ea5eac78d4..7cc692c93d 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md @@ -16,7 +16,7 @@ this function: * xTaskPriorityDisinherit This proof checks ```FreeRTOS_OutputARPRequest``` in multiple configurations. -All assume the memory safety of vNetworkInterfaceAllocateRAMToBuffers. +All assume the memory safety of uxNetworkInterfaceAllocateRAMToBuffers. * The ```config_minimal_configuration``` proof sets ```ipconfigUSE_LINKED_RX_MESSAGES=0```. * The ```config_minimal_configuration_linked_rx_messages``` proof sets diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json index d37f17720e..42165fed64 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json @@ -4,7 +4,7 @@ "CBMCFLAGS": [ "--unwind {MINIMUM_PACKET_BYTES}", - "--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,vNetworkInterfaceAllocateRAMToBuffers.0:3" + "--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,uxNetworkInterfaceAllocateRAMToBuffers.0:3" ], "OBJS": [ diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md index 5d509a7e83..642d2a42be 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md @@ -18,7 +18,7 @@ this function: * pvPortMalloc * pvPortFree * xNetworkInterfaceOutput -* vNetworkInterfaceAllocateRAMToBuffers +* uxNetworkInterfaceAllocateRAMToBuffers This proof disables the tracing library in the header. @@ -29,7 +29,7 @@ This proof checks FreeRTOS_OutputARPRequest in multiple configuration: FreeRTOS_OutputARPRequest and FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c are memory save. This proof depends entirely of the implementation - correctness of vNetworkInterfaceAllocateRAMToBuffers. + correctness of uxNetworkInterfaceAllocateRAMToBuffers. * The proof in directory minimal_configuration_minimal_packet_size guarantees that using FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c