From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu4mr-0001U9-Lr for qemu-devel@nongnu.org; Fri, 20 Dec 2013 13:27:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vu4mk-0000g4-23 for qemu-devel@nongnu.org; Fri, 20 Dec 2013 13:27:01 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:48838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu4mj-0000ft-Sr for qemu-devel@nongnu.org; Fri, 20 Dec 2013 13:26:54 -0500 Received: by mail-pa0-f49.google.com with SMTP id kx10so2959016pab.36 for ; Fri, 20 Dec 2013 10:26:53 -0800 (PST) From: Roy Franz Date: Fri, 20 Dec 2013 10:26:37 -0800 Message-Id: <1387563997-1845-3-git-send-email-roy.franz@linaro.org> In-Reply-To: <1387563997-1845-1-git-send-email-roy.franz@linaro.org> References: <1387563997-1845-1-git-send-email-roy.franz@linaro.org> Subject: [Qemu-devel] [PATCH 2/2] net: Fix lan9118 buffer length handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, stefanha@redhat.com, aliguori@amazon.com Cc: Roy Franz , peter.maydell@linaro.org, patches@linaro.org The 9118 ethernet controller supports transmission of multi-buffer packets with arbitrary byte alignment of the start and end bytes. All writes to the packet fifo are 32 bits, so the controller discards bytes at the beginning and end of each buffer based on the 'Data start offset' and 'Buffer size' of the TX command 'A' format. This patch uses the provided buffer length to limit the bytes transmitted. Previously all the bytes of the last 32-bit word written to the TX fifo were added to the internal transmit buffer structure resulting in more bytes being transmitted than were submitted to the hardware in the command. This resulted in extra bytes being inserted into the middle of multi-buffer packets when the non-final buffers had non-32bit aligned ending addresses. Signed-off-by: Roy Franz --- hw/net/lan9118.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index c5d6f14..712bb41 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -773,11 +773,10 @@ static void tx_fifo_push(lan9118_state *s, uint32_t val) in FIFO words. Empirical results show it to be little-endian. */ /* TODO: FIFO overflow checking. */ - while (n--) { + while (n-- && s->txp->buffer_size--) { s->txp->data[s->txp->len] = val & 0xff; s->txp->len++; val >>= 8; - s->txp->buffer_size--; } s->txp->fifo_used++; } -- 1.7.10.4