From patchwork Wed Sep 27 06:13:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 114339 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4665501qgf; Tue, 26 Sep 2017 23:17:09 -0700 (PDT) X-Received: by 10.107.1.16 with SMTP id 16mr472747iob.211.1506493029077; Tue, 26 Sep 2017 23:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506493029; cv=none; d=google.com; s=arc-20160816; b=MQdKpZcm/zzsBf9cBhbhEtzIBL3osIgmqfa7w4vocItklaO/cMDXAM2187Xl7A/Xqe YT7THDcSMg1ktnqv9wPrjg0obo+KSP/ePkSI7xCLvUzmWcudryTwviAG0Rnenit9TRi1 TlpCXcLE//mKv+FDfpuW0i8H1ipIC6Sag9xf0IIWf3BGL0baQF80nxdbAQGWDD9Ze4Ya k3tEU0oGSK9F7TwUXKVTiWv8SiRLI8OpMemqHouq85RlPFss1X5a+USO1GTmzxMNAJhv fA5Yr++Jv+m3EwCcyrcLbwI4gK/DuT3sgS5GVIdKyKpXBGH6HSx4SOz7RbtPmjwKnxTv mW8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=x80X3cVOF2GtV72izfuKrNXUD0dopJtWWYJ3ZCBIDco=; b=rUZZqi/NmgxJ2+X6ucNILbVcqo8ifgA8QXsy0+br/RegzSXZFKX+KBWV6rBMCRNuAS bJyi3A5elmmX47epYSYF4oqJpb6odPrKjcijUCB6cuwT1CadjbwyyxL4wFEp+RfBRSRY vvAuLylnN0Z2kzorpwv7usyxxADAo2MvH9l8MUCDhNtmCvqjEa7oGt76P75XOhb+FSxg FLWyEf0vB/z5UzyD9qg3LuNpOLOS6XhQZ/JijHwBpJ7nePaXgUaqYrPgOuPQfHFzB7UD T/2Iro3EG4NAaFgpHXm8Lk2+SfZlPK6bq2253RUQHt8Hbx6+MpXJkirkhyekqNQnbH7W rIiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HBO4JTgb; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 206si8746736ioc.276.2017.09.26.23.17.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Sep 2017 23:17:09 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HBO4JTgb; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dx5cB-0003ZZ-Sq; Wed, 27 Sep 2017 06:14:35 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dx5cA-0003Vr-JJ for xen-devel@lists.xenproject.org; Wed, 27 Sep 2017 06:14:34 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 94/16-03423-9C14BC95; Wed, 27 Sep 2017 06:14:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRWlGSWpSXmKPExsVyMfTAOt2Tjqc jDc5d5LX4vmUykwOjx+EPV1gCGKNYM/OS8isSWDN2/BcuuGRdsezmApYGxtfaXYxcHEICMxgl Js69xwzisAjMY5a4dusXmCMh0M8qseXGbKYuRk4gJ0/iwI3lUHaaxM6de5kh7AqJdTd/s4DYQ gJaEkdPzWaFGLuCSeLvuT9ACQ4ONgETiVkdEiA1IgJKEvdWTQabwyxQL7Ht3C9GEFtYIF/i99 49rCA2i4CqxKPWd2A1vAI+Ev+nLmKB2CUncfNcJ9heTqD46f7bbBB7vSUurexnncAouICRYRW jRnFqUVlqka6RsV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJSsV5yfu4mRmDAMQDBDsY/8wMP MUpyMCmJ8tb8PxUpxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3nsPpSCHBotT01Iq0zBxg6MOkJ Th4lER4o0DSvMUFibnFmekQqVOMrhwX7lz6w8TxpfcGkDyw5xaQXHH9NpDsuHn3D5MQS15+Xq qUOG8VSLMASHNGaR7caFjcXmKUlRLmZQQ6VoinILUoN7MEVf4VozgHo5Iw712QKTyZeSVwF7w COo4J6LjeqSdAjitJREhJNTDys3T65h74bnb4tXmUVs/SxBcSf74t6XLSmHXnXmV2O+NsvxXL WFbEcUXNevLf+Eey5F3dH++mOkjlH2+fPnvK+mNpu9f8mPV7i/Ev4bNbG7/nSnR5GoYxv2O6X BDYsSP+xpm82asVds/iF45LnDnp/rKM76vi91gsuCPhbv/jVZl8sMubJodWJZbijERDLeai4k QAfISMMdYCAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-3.tower-21.messagelabs.com!1506492871!81307899!1 X-Originating-IP: [209.85.192.174] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31974 invoked from network); 27 Sep 2017 06:14:32 -0000 Received: from mail-pf0-f174.google.com (HELO mail-pf0-f174.google.com) (209.85.192.174) by server-3.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 27 Sep 2017 06:14:32 -0000 Received: by mail-pf0-f174.google.com with SMTP id z84so6755983pfi.2 for ; Tue, 26 Sep 2017 23:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ShLFdjyBwOXeMOQr3lQ1MFu6ReaYVbjCfilIir6inKk=; b=HBO4JTgbmHQptbKGVlhlh7HSLAmwQl/QmetJe8kK0QQfwj+xAJTtx/z8wv+iYIZIzG P5wiLMFHYtEDE3FAoelPVV9PF8LPZnTK9+9fEX3JyYfq/4pyLdYjPVIHd0ijuXgt+D2R YeR9Y3HMlSoND4vNe3bPCz5Ra1dpcA/pepwos= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ShLFdjyBwOXeMOQr3lQ1MFu6ReaYVbjCfilIir6inKk=; b=t2iDOzGOjSYC2QDJjUtsfWcPUJshx7/x4FssFgV/H7sd4RaTbpRoYfE06rGlZ6M4Yd ZhgzxwJyHBvVXFTbwZj3OY8AP+IwIdcIyhhL6MMCHOxHv7R+7hIjSqpmhhsdiLBRmrQI tQrea6LL1CLbONJemiJpQ4zzXaCwRh2iQHly8v51bZIufcGYoWofQzzfIdkfrz1CYaWM Evyp2ohz739mVUdM04sAE+9glhLF9l3GmssAoYBvO8bdAG7gA1Jj7jIj4/AiYsSj/3TB qTk1xR3JbiVGsZR8TvTy2K1ssS886HY/7lxHgtKZfDXErwc9JmoTk7QOFcUdnT4BrD5N EySg== X-Gm-Message-State: AHPjjUgmYZE4wqYUh4ebVL6AUlRQvmhQWFIPA8Q7/+z89zpHLKSihn5Z eRgER5Vth7tEif6fcGnWfvHpwHfw+v4= X-Google-Smtp-Source: AOwi7QDSeSYBQA/v/aVYo7QcrwIAUH17BDQh6BjviwIaXHJnufjzNgGMSdMTp5/oliviVPBLCpzRIQ== X-Received: by 10.98.68.206 with SMTP id m75mr335102pfi.163.1506492871288; Tue, 26 Sep 2017 23:14:31 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com (h3.248.139.40.ip.windstream.net. [40.139.248.3]) by smtp.gmail.com with ESMTPSA id s187sm18013485pgb.82.2017.09.26.23.14.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 23:14:30 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Wed, 27 Sep 2017 11:43:36 +0530 Message-Id: <1506492816-25954-28-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506492816-25954-1-git-send-email-bhupinder.thakur@linaro.org> References: <1506492816-25954-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Andre Przywara , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 27/27 v11] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" This patch fixes the issue observed when pl011 patches were tested on the junos hardware by Andre/Julien. It was observed that when large output is generated such as on running 'find /', output was getting truncated intermittently due to OUT ring buffer getting full. This issue was due to the fact that the SBSA UART driver expects that when a TX interrupt is asserted then the FIFO queue should be atleast half empty and that it can write N bytes in the FIFO, where N is half the FIFO queue size, without the bytes getting dropped due to FIFO getting full. The SBSA UART emulation logic was asserting the TX interrupt as soon as any space became available in the FIFO and the SBSA UART driver tried to write more data (upto 16 bytes) in the FIFO expecting that there is enough space available leading to dropped bytes. The SBSA spec [1] does not specify when the TX interrupt should be asserted or de-asserted. Due to lack of clarity on the expected behavior, it is assumed for now that TX interrupt should be asserted only when the FIFO goes half empty. TBD: Once the SBSA spec is updated with the expected behavior, the implementation will be modified to align with the spec requirement. [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf Signed-off-by: Bhupinder Thakur --- CC: Julien Grall CC: Andre Przywara CC: Stefano Stabellini Changes since v8: - Used variables fifo_level/fifo_threshold for more clarity - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number - Renamed ring_qsize variables to fifo_level for consistency xen/arch/arm/vpl011.c | 87 ++++++++++++++++++++++++++++++-------------- xen/include/asm-arm/vpl011.h | 2 + 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 36794d8..1f97261 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -91,20 +91,24 @@ static uint8_t vpl011_read_data(struct domain *d) */ if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 ) { + unsigned int fifo_level; + data = intf->in[xencons_mask(in_cons, sizeof(intf->in))]; in_cons += 1; smp_mb(); intf->in_cons = in_cons; + + fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in)); + + if ( fifo_level == 0 ) + { + vpl011->uartfr |= RXFE; + vpl011->uartris &= ~RXI; + } } else gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n"); - if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == 0 ) - { - vpl011->uartfr |= RXFE; - vpl011->uartris &= ~RXI; - } - vpl011->uartfr &= ~RXFF; vpl011_update_interrupt_status(d); @@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, uint8_t data) if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) != sizeof (intf->out) ) { + unsigned int fifo_level, fifo_threshold; + intf->out[xencons_mask(out_prod, sizeof(intf->out))] = data; out_prod += 1; smp_wmb(); intf->out_prod = out_prod; - } - else - gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n"); - if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) == - sizeof (intf->out) ) - { - vpl011->uartfr |= TXFF; - vpl011->uartris &= ~TXI; + fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out)); + + if ( fifo_level == sizeof (intf->out) ) + { + vpl011->uartfr |= TXFF; + + /* + * This bit is set only when FIFO becomes full. This ensures that + * the SBSA UART driver can write the early console data as fast as + * possible, without waiting for the BUSY bit to get cleared before + * writing each byte. + */ + vpl011->uartfr |= BUSY; + } /* - * This bit is set only when FIFO becomes full. This ensures that - * the SBSA UART driver can write the early console data as fast as - * possible, without waiting for the BUSY bit to get cleared before - * writing each byte. + * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark which + * is the trigger level for asserting/de-assterting the TX interrupt. */ - vpl011->uartfr |= BUSY; + fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2; + + if ( fifo_level <= fifo_threshold ) + vpl011->uartris |= TXI; + else + vpl011->uartris &= ~TXI; } + else + gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n"); vpl011->uartfr &= ~TXFE; @@ -342,7 +359,7 @@ static void vpl011_data_avail(struct domain *d) struct vpl011 *vpl011 = &d->arch.vpl011; struct xencons_interface *intf = vpl011->ring_buf; XENCONS_RING_IDX in_cons, in_prod, out_cons, out_prod; - XENCONS_RING_IDX in_ring_qsize, out_ring_qsize; + XENCONS_RING_IDX in_fifo_level, out_fifo_level; VPL011_LOCK(d, flags); @@ -353,37 +370,51 @@ static void vpl011_data_avail(struct domain *d) smp_rmb(); - in_ring_qsize = xencons_queued(in_prod, + in_fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in)); - out_ring_qsize = xencons_queued(out_prod, + out_fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out)); /* Update the uart rx state if the buffer is not empty. */ - if ( in_ring_qsize != 0 ) + if ( in_fifo_level != 0 ) { vpl011->uartfr &= ~RXFE; - if ( in_ring_qsize == sizeof(intf->in) ) + + if ( in_fifo_level == sizeof(intf->in) ) vpl011->uartfr |= RXFF; + vpl011->uartris |= RXI; } /* Update the uart tx state if the buffer is not full. */ - if ( out_ring_qsize != sizeof(intf->out) ) + if ( out_fifo_level != sizeof(intf->out) ) { + unsigned int out_fifo_threshold; + vpl011->uartfr &= ~TXFF; - vpl011->uartris |= TXI; /* - * Clear the BUSY bit as soon as space becomes available + * Clear the BUSY bit as soon as space becomes avaliable * so that the SBSA UART driver can start writing more data * without any further delay. */ vpl011->uartfr &= ~BUSY; - if ( out_ring_qsize == 0 ) + /* + * Set the TXI bit only when there is space for fifo_size/2 bytes which + * is the trigger level for asserting/de-assterting the TX interrupt. + */ + out_fifo_threshold = sizeof(intf->out) - SBSA_UART_FIFO_SIZE/2; + + if ( out_fifo_level <= out_fifo_threshold ) + vpl011->uartris |= TXI; + else + vpl011->uartris &= ~TXI; + + if ( out_fifo_level == 0 ) vpl011->uartfr |= TXFE; } diff --git a/xen/include/asm-arm/vpl011.h b/xen/include/asm-arm/vpl011.h index 1b583da..db95ff8 100644 --- a/xen/include/asm-arm/vpl011.h +++ b/xen/include/asm-arm/vpl011.h @@ -28,6 +28,8 @@ #define VPL011_LOCK(d,flags) spin_lock_irqsave(&(d)->arch.vpl011.lock, flags) #define VPL011_UNLOCK(d,flags) spin_unlock_irqrestore(&(d)->arch.vpl011.lock, flags) +#define SBSA_UART_FIFO_SIZE 32 + struct vpl011 { void *ring_buf; struct page_info *ring_page;