From patchwork Thu May 8 11:53:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 29836 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D7E120A67 for ; Thu, 8 May 2014 11:53:22 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id if11sf7393916vcb.4 for ; Thu, 08 May 2014 04:53:21 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Ufk0yL7DNe5A8PQfBMleyi0Wym8sQ4vyDBY8XniNYqY=; b=Q0FHycPAEWjWjg5ESiNCqdRd5PaNiN94k/6xrtESwuNyaPqcAKzkPF8slF/DbFgF3k mQdDwO5Gsqj8b7Rth9O+XmpXR1anlQZS74KNyeI5lzpJL72p0ICp/n2BSau+dB1jjT67 B4k//y8bw5rUOkkh4QzjqXSDNR4dVe/yi41AG6yK4PMZoBSiJiFIjHDrR1J4tUx3PVNo J5KHWP3iJYf3A33BCxZUmRZtvP3bbMmF3Gnf9mEoDfU5VPw1V4RD6QNBw+ZSON7gwgLM QWP/B/rsT/Qe288rlzPe+eUk8k6OmuUt+D6JRAL1SyyhPjQE9Bb/m+uLFv7ye5mA1ghT PNdw== X-Gm-Message-State: ALoCoQnGqm4PjVSo1rX7j51k7dCfxVL3WDmw8GIawng5jNR4rUzMDNRujLCHPiglulH0vPzZTwKy X-Received: by 10.236.206.15 with SMTP id k15mr1258199yho.44.1399550001897; Thu, 08 May 2014 04:53:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.112 with SMTP id n103ls3802800qga.86.gmail; Thu, 08 May 2014 04:53:21 -0700 (PDT) X-Received: by 10.58.211.229 with SMTP id nf5mr859448vec.19.1399550001815; Thu, 08 May 2014 04:53:21 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id gu9si133246vdc.124.2014.05.08.04.53.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 May 2014 04:53:21 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id db12so3011654veb.25 for ; Thu, 08 May 2014 04:53:21 -0700 (PDT) X-Received: by 10.58.126.4 with SMTP id mu4mr2563609veb.0.1399550001740; Thu, 08 May 2014 04:53:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp392526vcb; Thu, 8 May 2014 04:53:21 -0700 (PDT) X-Received: by 10.194.5.5 with SMTP id o5mr2868784wjo.16.1399550000772; Thu, 08 May 2014 04:53:20 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id j7si805095wia.90.2014.05.08.04.53.20 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 08 May 2014 04:53:20 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WiMsu-0004sn-49; Thu, 08 May 2014 12:53:08 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" Subject: [PATCH v4 4/7] hw/net/stellaris_enet: Correctly implement the TR and THR registers Date: Thu, 8 May 2014 12:53:04 +0100 Message-Id: <1399549987-18729-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399549987-18729-1-git-send-email-peter.maydell@linaro.org> References: <1399549987-18729-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. */