From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLIgl-0002QB-6D for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLIgj-0002JC-OI for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:55 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:35357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLIgj-0002Iv-LC for qemu-devel@nongnu.org; Tue, 01 Nov 2011 14:03:53 -0400 Received: by qadc12 with SMTP id c12so7581813qad.4 for ; Tue, 01 Nov 2011 11:03:53 -0700 (PDT) Message-ID: <4EB03486.4070007@codemonkey.ws> Date: Tue, 01 Nov 2011 13:03:50 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1319753427-19528-1-git-send-email-jcmvbkbc@gmail.com> In-Reply-To: <1319753427-19528-1-git-send-email-jcmvbkbc@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] opencores_eth: fix RX path: FCS, padding and TL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Filippov Cc: qemu-devel@nongnu.org On 10/27/2011 05:10 PM, Max Filippov wrote: > OpenCores 10/100 Mbps Ethernet MAC specification doesn't clearly state > whether FCS is counted in the RX frame length or not. Looks like it is. > Append zero FCS to the received frames. > > Get rid of big static buffer for RX frame padding, optimize it for the > most common MINFL value range. > > Set RXD_TL for the long frames only when HUGEN bit is set. > > Signed-off-by: Max Filippov Applied. Thanks. Regards, Anthony Liguori > --- > hw/opencores_eth.c | 29 ++++++++++++++++++++++++----- > 1 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/hw/opencores_eth.c b/hw/opencores_eth.c > index 64b616e..2c1e475 100644 > --- a/hw/opencores_eth.c > +++ b/hw/opencores_eth.c > @@ -382,6 +382,7 @@ static ssize_t open_eth_receive(VLANClientState *nc, > OpenEthState *s = DO_UPCAST(NICState, nc, nc)->opaque; > size_t maxfl = GET_REGFIELD(s, PACKETLEN, MAXFL); > size_t minfl = GET_REGFIELD(s, PACKETLEN, MINFL); > + size_t fcsl = 4; > bool miss = true; > > trace_open_eth_receive((unsigned)size); > @@ -418,6 +419,7 @@ static ssize_t open_eth_receive(VLANClientState *nc, > #else > { > #endif > + static const uint8_t zero[64] = {0}; > desc *desc = rx_desc(s); > size_t copy_size = GET_REGBIT(s, MODER, HUGEN) ? 65536 : maxfl; > > @@ -426,11 +428,13 @@ static ssize_t open_eth_receive(VLANClientState *nc, > > if (copy_size> size) { > copy_size = size; > + } else { > + fcsl = 0; > } > if (miss) { > desc->len_flags |= RXD_M; > } > - if (size> maxfl) { > + if (GET_REGBIT(s, MODER, HUGEN)&& size> maxfl) { > desc->len_flags |= RXD_TL; > } > #ifdef USE_RECSMALL > @@ -442,13 +446,28 @@ static ssize_t open_eth_receive(VLANClientState *nc, > cpu_physical_memory_write(desc->buf_ptr, buf, copy_size); > > if (GET_REGBIT(s, MODER, PAD)&& copy_size< minfl) { > - static const uint8_t zero[65536] = {0}; > + if (minfl - copy_size> fcsl) { > + fcsl = 0; > + } else { > + fcsl -= minfl - copy_size; > + } > + while (copy_size< minfl) { > + size_t zero_sz = minfl - copy_size< sizeof(zero) ? > + minfl - copy_size : sizeof(zero); > > - cpu_physical_memory_write(desc->buf_ptr + copy_size, > - zero, minfl - copy_size); > - copy_size = minfl; > + cpu_physical_memory_write(desc->buf_ptr + copy_size, > + zero, zero_sz); > + copy_size += zero_sz; > + } > } > > + /* There's no FCS in the frames handed to us by the QEMU, zero fill it. > + * Don't do it if the frame is cut at the MAXFL or padded with 4 or > + * more bytes to the MINFL. > + */ > + cpu_physical_memory_write(desc->buf_ptr + copy_size, zero, fcsl); > + copy_size += fcsl; > + > SET_FIELD(desc->len_flags, RXD_LEN, copy_size); > > if ((desc->len_flags& RXD_WRAP) || s->rx_desc == 0x7f) {