From 5b3b5aa16024ab417c2d8cea5dc693ea71be3638 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 29 Dec 2012 09:22:37 +0000 Subject: [PATCH] Zero-copy for STM32 MAC driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4985 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/AT91SAM7/mac_lld.h | 5 +++++ os/hal/platforms/STM32/mac_lld.c | 27 +++++++++++++++++++++------ os/hal/platforms/STM32/mac_lld.h | 2 -- readme.txt | 2 ++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/os/hal/platforms/AT91SAM7/mac_lld.h b/os/hal/platforms/AT91SAM7/mac_lld.h index 33613b45d..475180c9d 100644 --- a/os/hal/platforms/AT91SAM7/mac_lld.h +++ b/os/hal/platforms/AT91SAM7/mac_lld.h @@ -35,6 +35,11 @@ /* Driver constants. */ /*===========================================================================*/ +/** + * @brief This implementation does not support the zero-copy mode API. + */ +#define MAC_SUPPORTS_ZERO_COPY FALSE + #define EMAC_RECEIVE_BUFFERS_SIZE 128 /* Do not modify */ #define EMAC_TRANSMIT_BUFFERS_SIZE MAC_BUFFERS_SIZE #define EMAC_RECEIVE_DESCRIPTORS \ diff --git a/os/hal/platforms/STM32/mac_lld.c b/os/hal/platforms/STM32/mac_lld.c index 25a5155ee..9573e991f 100644 --- a/os/hal/platforms/STM32/mac_lld.c +++ b/os/hal/platforms/STM32/mac_lld.c @@ -624,18 +624,26 @@ bool_t mac_lld_poll_link_status(MACDriver *macp) { * on the first call then scale the value down subtracting * the amount of data already copied into the previous * buffers. - * @param[out] sizep pointer to variable receiving the real buffer size. - * The returned value can be less than the amount - * requested, this means that more buffers must be - * requested in order to fill the frame data entirely. + * @param[out] sizep pointer to variable receiving the buffer size, it is + * zero when the last buffer has already been returned. + * Note that a returned size lower than the amount + * requested means that more buffers must be requested + * in order to fill the frame data entirely. * @return Pointer to the returned buffer. + * @retval NULL if the buffer chain has been entirely scanned. * * @notapi */ uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp, size_t size, size_t *sizep) { - (void)tdp; (void)size; (void)sizep; + + if (tdp->offset == 0) { + *sizep = tdp->size; + tdp->offset = size; + return (uint8_t *)tdp->physdesc->tdes2; + } + *sizep = 0; return NULL; } @@ -655,7 +663,14 @@ uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp, */ const uint8_t *mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp, size_t *sizep) { - (void)rdp; (void)sizep; + + if (rdp->size > 0) { + *sizep = rdp->size; + rdp->offset = rdp->size; + rdp->size = 0; + return (uint8_t *)rdp->physdesc->rdes2; + } + *sizep = 0; return NULL; } #endif /* MAC_USE_ZERO_COPY */ diff --git a/os/hal/platforms/STM32/mac_lld.h b/os/hal/platforms/STM32/mac_lld.h index 59c39ac17..f765f1699 100644 --- a/os/hal/platforms/STM32/mac_lld.h +++ b/os/hal/platforms/STM32/mac_lld.h @@ -291,7 +291,6 @@ typedef struct { * @brief Available space size. */ size_t size; - /* End of the mandatory fields.*/ /** * @brief Pointer to the physical descriptor. */ @@ -310,7 +309,6 @@ typedef struct { * @brief Available data size. */ size_t size; - /* End of the mandatory fields.*/ /** * @brief Pointer to the physical descriptor. */ diff --git a/readme.txt b/readme.txt index 259825234..db64b628c 100644 --- a/readme.txt +++ b/readme.txt @@ -90,6 +90,8 @@ (backported to 2.4.3). - FIX: Fixed wrong SPI path in platform_f105_f107.mk (bug 3598151). - FIX: Fixed PHY powerdown issues not fixed (bug 3596911). +- NEW: Added zero-copy capability to the STM32 MAC driver (experimental and + not tested yet). - NEW: Added an optional zero-copy mode API to the MAC driver model. - NEW: Added EXT driver to the STM32F3xx platform. - NEW: Improved the STM32 EXT driver to support more than 32 channels.