From patchwork Tue Apr 1 16:53:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27557 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4BEFE20AEB for ; Tue, 1 Apr 2014 16:53:14 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id bj1sf27248893pad.11 for ; Tue, 01 Apr 2014 09:53:13 -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=b55w2o8aDqy+dd3+t6YMIY5oqndmrZtFVIfhJ23l5+Q=; b=dhKRYaeMmfYwr4DNPSvzpvePnCsy/sUbo+HY525UjGT5H71Kb11DF8cqsFOnrMq+Nq YhZViH5Bz+WKpSqVOGBqnIs2qptmV5p0fdfyBUipODrPNo/pxJTl6p7Gv64bLZHwynwf iMJTlb+PAiToeOTNhhVLlYv6eCWsOZmDJd9QoSWd2VYo/NAhSrmyEXtw4FVRkbUgznT5 J54bZzjV1UfEzvYnreg4oEp6LdQuAnffMv8sDeXeCW0qPjN09uRqhKH4VF5SEF6qkACu 4koSfeWv9U/Ro/joki0DK9cvyeXxla4W5VQTkLW8sw3PsbSTbSh7LRpM+BHennTid3Qd 9fVA== X-Gm-Message-State: ALoCoQmBbUQF1WA5sNp2xEnkq5xYDJbJixhJNv9fHdJx8cLqjaKJtvaV9OkQpszkxYwLaJ7NLxk+ X-Received: by 10.66.66.196 with SMTP id h4mr13317030pat.22.1396371193601; Tue, 01 Apr 2014 09:53:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.245 with SMTP id u108ls59242qge.79.gmail; Tue, 01 Apr 2014 09:53:13 -0700 (PDT) X-Received: by 10.221.39.196 with SMTP id tn4mr343559vcb.51.1396371193513; Tue, 01 Apr 2014 09:53:13 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id h18si3672101vco.88.2014.04.01.09.53.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 09:53:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id il7so9929408vcb.4 for ; Tue, 01 Apr 2014 09:53:13 -0700 (PDT) X-Received: by 10.52.104.33 with SMTP id gb1mr958389vdb.45.1396371193427; Tue, 01 Apr 2014 09:53:13 -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.12.8 with SMTP id v8csp253296vcv; Tue, 1 Apr 2014 09:53:13 -0700 (PDT) X-Received: by 10.66.180.200 with SMTP id dq8mr32502855pac.104.1396371191449; Tue, 01 Apr 2014 09:53:11 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id zt8si11560823pbc.316.2014.04.01.09.53.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 01 Apr 2014 09:53:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WV1vv-0002Eu-Ll; Tue, 01 Apr 2014 17:53:07 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" Subject: [PATCH 4/5] hw/net/stellaris_enet: Correctly implement the TR and THR registers Date: Tue, 1 Apr 2014 17:53:06 +0100 Message-Id: <1396371187-8567-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396371187-8567-1-git-send-email-peter.maydell@linaro.org> References: <1396371187-8567-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: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 --- hw/net/stellaris_enet.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index b99f93e..0210108 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,11 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, case 0x2c: /* MTXD */ s->mtxd = value & 0xff; break; + case 0x38: /* TR */ + stellaris_enet_send(s); + break; case 0x30: /* MRXD */ case 0x34: /* NP */ - case 0x38: /* TR */ /* Ignored. */ case 0x3c: /* Undocuented: Timestamp? */ /* Ignored. */