From 285fbdaa3f2652909fae888ef54ef2afa8a821ad Mon Sep 17 00:00:00 2001 From: Emil Popov Date: Fri, 13 Oct 2023 14:26:45 -0400 Subject: [PATCH 1/4] Fixes and issue with the SAME70 port where and error in gmac_dev_write() causes the counting xTXDescriptorSemaphore to not be returned and eventually exhausting it. --- .../portable/NetworkInterface/DriverSAM/NetworkInterface.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index 7ad92f940b..be59ce243d 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -651,6 +651,12 @@ static BaseType_t prvSAM_NetworkInterfaceOutput( NetworkInterface_t * pxInterfac if( ulResult != GMAC_OK ) { TX_STAT_INCREMENT( tx_write_fail ); + + /* On a successful write to GMAC, the ownership of the TX descriptor will eventually get returned back to the network + * driver and prvEMACHandlerTask will give back the xTXDescriptorSemaphore counting semaphore. In this case however, + * writing to the GMAC failed, so there will be no EMAC_IF_TX_EVENT sent to prvEMACHandlerTask and the counting + * semaphore will not be given back. Give it back now. */ + xSemaphoreGive( xTXDescriptorSemaphore ); } #if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) From a8d206352d96c299dece733a279d409099c9956e Mon Sep 17 00:00:00 2001 From: tony-josi-aws Date: Wed, 18 Oct 2023 13:10:56 +0530 Subject: [PATCH 2/4] fix formatting --- .../NetworkInterface/DriverSAM/NetworkInterface.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index be59ce243d..58732871eb 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -652,11 +652,11 @@ static BaseType_t prvSAM_NetworkInterfaceOutput( NetworkInterface_t * pxInterfac { TX_STAT_INCREMENT( tx_write_fail ); - /* On a successful write to GMAC, the ownership of the TX descriptor will eventually get returned back to the network - * driver and prvEMACHandlerTask will give back the xTXDescriptorSemaphore counting semaphore. In this case however, - * writing to the GMAC failed, so there will be no EMAC_IF_TX_EVENT sent to prvEMACHandlerTask and the counting - * semaphore will not be given back. Give it back now. */ - xSemaphoreGive( xTXDescriptorSemaphore ); + /* On a successful write to GMAC, the ownership of the TX descriptor will eventually get returned back to the network + * driver and prvEMACHandlerTask will give back the xTXDescriptorSemaphore counting semaphore. In this case however, + * writing to the GMAC failed, so there will be no EMAC_IF_TX_EVENT sent to prvEMACHandlerTask and the counting + * semaphore will not be given back. Give it back now. */ + xSemaphoreGive( xTXDescriptorSemaphore ); } #if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) From cb12473a3f5dc97b398aade95c7fe258f42527e8 Mon Sep 17 00:00:00 2001 From: Emil Popov Date: Wed, 18 Oct 2023 11:45:39 -0400 Subject: [PATCH 3/4] Allows release of the network buffer if gmac_dev_write() fails and the ero-copy driver is being used. Thanks @htibosch --- .../NetworkInterface/DriverSAM/NetworkInterface.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index 58732871eb..fa371ee36f 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -661,8 +661,12 @@ static BaseType_t prvSAM_NetworkInterfaceOutput( NetworkInterface_t * pxInterfac #if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) { - /* Confirm that the pxDescriptor may be kept by the driver. */ - bReleaseAfterSend = pdFALSE; + if( ulResult == GMAC_OK ) + { + /* The message was send in a zero-copy way. + * It will be released after a succeful transmission. */ + bReleaseAfterSend = pdFALSE; + } } #endif /* ipconfigZERO_COPY_TX_DRIVER */ /* Not interested in a call-back after TX. */ From 7f0cad98534537c225b50ed09449e8f21675df51 Mon Sep 17 00:00:00 2001 From: ActoryOu Date: Thu, 19 Oct 2023 11:08:54 +0800 Subject: [PATCH 4/4] Fix typo --- source/portable/NetworkInterface/DriverSAM/NetworkInterface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index fa371ee36f..81f654e033 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -664,7 +664,7 @@ static BaseType_t prvSAM_NetworkInterfaceOutput( NetworkInterface_t * pxInterfac if( ulResult == GMAC_OK ) { /* The message was send in a zero-copy way. - * It will be released after a succeful transmission. */ + * It will be released after a successful transmission. */ bReleaseAfterSend = pdFALSE; } }