From patchwork Tue Apr 1 22:14:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27582 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3F3C520AEB for ; Tue, 1 Apr 2014 22:15:03 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id to1sf37697783ieb.9 for ; Tue, 01 Apr 2014 15:15:03 -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=F3lJRG6aWiCraeg3lKs8jBDY27EWWD7ixMEZqluTXCo=; b=kMSJhqv5PE4w4W36ZCvQ1g2yDbUjvxX/9dkWs01Rh6AnJFOeY5VfiwWgKISgI8FImf N5LzRhHVQVpDPEdtGpMMpqgyT8aH/aM7vWql9m5N5JrT8b2/IiISquLhS1l726MNS4/a WnlVXe7O4xjHWRQ5PgBZJbQ6SfLqpjDId2troORP9I0iFBE2zNk/q2EVsIHmCw1RxrKO 6R0Ms+Ur+rVp685ypdBzM0iLWKSWkMOUgWFURvZLFbX13fwRa0BymQG0YXkyp0w74eMU d1Rk9hhF6DGkfMX3lSyDQFJ5wsh8K7nQSboXlg/MqUAysNhl2agQeYWDM8ixKEIgcGIh iArg== X-Gm-Message-State: ALoCoQnFZBMBHJiuV3NqYxEd33IyklJ6bjecWPtcfKRBq3TMS1G9uc6SrOmJCTrQN5EICl25Z9eL X-Received: by 10.183.1.7 with SMTP id bc7mr12325664obd.47.1396390502976; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.100 with SMTP id b91ls146766qgf.26.gmail; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) X-Received: by 10.52.163.145 with SMTP id yi17mr2475099vdb.46.1396390502898; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id gs7si4012788vdc.110.2014.04.01.15.15.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 15:15:02 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 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.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so10753646vcb.14 for ; Tue, 01 Apr 2014 15:15:02 -0700 (PDT) X-Received: by 10.52.12.36 with SMTP id v4mr13147646vdb.20.1396390502766; Tue, 01 Apr 2014 15:15:02 -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 v8csp273747vcv; Tue, 1 Apr 2014 15:15:02 -0700 (PDT) X-Received: by 10.112.205.35 with SMTP id ld3mr22908320lbc.1.1396390499452; Tue, 01 Apr 2014 15:14:59 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id g7si11569541lab.166.2014.04.01.15.14.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 01 Apr 2014 15:14:59 -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 1WV6xL-0002KO-Ts; Tue, 01 Apr 2014 23:14:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" Subject: [PATCH v2 4/7] hw/net/stellaris_enet: Correctly implement the TR and THR registers Date: Tue, 1 Apr 2014 23:14:52 +0100 Message-Id: <1396390495-8908-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396390495-8908-1-git-send-email-peter.maydell@linaro.org> References: <1396390495-8908-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.169 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 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 47787fd..db6e43e 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. */