From patchwork Tue May 13 15:31:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 30068 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D42D320369 for ; Tue, 13 May 2014 15:34:35 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id i57sf1595116yha.8 for ; Tue, 13 May 2014 08:34:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Ufk0yL7DNe5A8PQfBMleyi0Wym8sQ4vyDBY8XniNYqY=; b=RhjAB0pQ/wliaxCoCq94jZN9Dt4NhTBOwOymru2VezAu18IV8aVVO4Adv/q+pTKXBo KSPuSO7o0uig7JRm7sUGqt/9dTQuk0JmD8Ev/MwvsfF7jcCtJgaR4whOTO+TB/veeJHj JG5h5/YR5iEzoMBrpg5rYsLiIF0cBGPP7EWYQsHYqQppAXt0QYrGj34sL3hFNUXDYzDl YM7vbbnHEKXj/mNI42QF9bI0oc0fq+d6Os7urXmwovZ+ttIcYUR2ZL/H7GO/SMBEzGFY 8EnQFw71mRL2cPKXpbhKrJD8UD4PPHn1c53zNc8SamQSq5yFgKTanioVb5rx54sHKUC5 b7dg== X-Gm-Message-State: ALoCoQn3erlMynO11mJd7Lwoj7l7xXXavRyUsjZanC6NZ8CeKlRbpsfRdRwEYUFpDwkNaOkgZqtv X-Received: by 10.58.245.132 with SMTP id xo4mr16743594vec.11.1399995275622; Tue, 13 May 2014 08:34:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.164 with SMTP id r33ls1979623qgr.2.gmail; Tue, 13 May 2014 08:34:35 -0700 (PDT) X-Received: by 10.52.145.211 with SMTP id sw19mr353611vdb.75.1399995275544; Tue, 13 May 2014 08:34:35 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id ek16si2710664vcb.101.2014.05.13.08.34.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 08:34:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id hq16so697350vcb.9 for ; Tue, 13 May 2014 08:34:35 -0700 (PDT) X-Received: by 10.220.5.129 with SMTP id 1mr716371vcv.71.1399995275455; Tue, 13 May 2014 08:34:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp160600vcb; Tue, 13 May 2014 08:34:34 -0700 (PDT) X-Received: by 10.180.93.226 with SMTP id cx2mr21719395wib.16.1399995274456; Tue, 13 May 2014 08:34:34 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id hb7si5782372wjc.71.2014.05.13.08.34.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 08:34:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:45875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEiv-000359-0w for patch@linaro.org; Tue, 13 May 2014 11:34:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEgK-00082E-Iz for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkEgJ-0006Af-Ik for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:52 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEgJ-00066p-CU for qemu-devel@nongnu.org; Tue, 13 May 2014 11:31:51 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WkEg7-0006wR-DP; Tue, 13 May 2014 16:31:39 +0100 From: Peter Maydell To: Anthony Liguori Date: Tue, 13 May 2014 16:31:28 +0100 Message-Id: <1399995099-26635-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399995099-26635-1-git-send-email-peter.maydell@linaro.org> References: <1399995099-26635-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 06/17] hw/net/stellaris_enet: Correctly implement the TR and THR registers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Packet transmission for the stellaris ethernet controller can be triggered in one of two ways: * by setting a threshold value in the THR register; when the FIFO fill level reaches the threshold, the h/w starts transmitting. Software has to finish filling the FIFO before the transmit process completes to avoid a (silent) underrun * by software writing to the TR register to explicitly trigger transmission Since QEMU transmits packets instantaneously (from the guest's point of view), implement "transmit based on threshold" with our existing mechanism of "transmit as soon as we have the whole packet", with the additional wrinkle that we don't transmit if the packet size is below the specified threshold, and implement "transmit by specific request" properly. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- hw/net/stellaris_enet.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index b99f93e..2079fc6 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -109,6 +109,15 @@ static inline bool stellaris_txpacket_complete(stellaris_enet_state *s) return s->tx_fifo_len >= framelen; } +/* Return true if the TX FIFO threshold is enabled and the FIFO + * has filled enough to reach it. + */ +static inline bool stellaris_tx_thr_reached(stellaris_enet_state *s) +{ + return (s->thr < 0x3f && + (s->tx_fifo_len >= 4 * (s->thr * 8 + 1))); +} + /* Send the packet currently in the TX FIFO */ static void stellaris_enet_send(stellaris_enet_state *s) { @@ -309,7 +318,7 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, s->tx_fifo[s->tx_fifo_len++] = value >> 24; } - if (stellaris_txpacket_complete(s)) { + if (stellaris_tx_thr_reached(s) && stellaris_txpacket_complete(s)) { stellaris_enet_send(s); } break; @@ -338,9 +347,13 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, case 0x2c: /* MTXD */ s->mtxd = value & 0xff; break; + case 0x38: /* TR */ + if (value & 1) { + stellaris_enet_send(s); + } + break; case 0x30: /* MRXD */ case 0x34: /* NP */ - case 0x38: /* TR */ /* Ignored. */ case 0x3c: /* Undocuented: Timestamp? */ /* Ignored. */