From patchwork Mon Sep 18 10:32:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 112900 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3501340qgf; Mon, 18 Sep 2017 03:35:05 -0700 (PDT) X-Received: by 10.107.131.155 with SMTP id n27mr18291150ioi.200.1505730904967; Mon, 18 Sep 2017 03:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505730904; cv=none; d=google.com; s=arc-20160816; b=O+Qu8LFJhdAdWxcOZziih/6BHeoirb9UBFYEdxvOKjZHCQsidYxuZx+JRdrcLQ4AlI mbWstcyMtfL2qwTN8stRNsogXcHWloYl502X/5pD3mBL+Drawe7q0lTLgi4rxB4d9wO0 XIpc10Veo8J8DDqcov64hlKtx2ydRDzJJKhfz4TDgVaUgUtAg4uIMJqC0BvQnYyRyPkB GLgUoFiNz4KEcp1v8KF3kV18NfuVs7WrICa8NT4jj28GqOv3Loy6/WMtL2T0vdPL5PQk rx9ZOQtIS7/gK/kdtqPRArFMPUMyLg2696+nKMiWXJI04BqsE5VsKyUZUdp0x5JI43V2 UcOQ== 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=a40v5+55P180YxPwHwhGDKMxD84rc0WqbBC5mwGwZIo=; b=mwKCp5WAB1xXVf4LM4fhC19fpV1En0LdQ1gZWWrhw8N28osmfwJXanO+XYjS5PFXeT KcggOkMp5Ixw2ZeFPrQSkgOn5UDY6+bLqb4eQHOJf9i7VYT7cVv9/RQRGQm4A2+rs7YE eYR28sApf4Uv4/EOroJLVv7G7ExBX3SUlxxZ+Hg2taNG1xvfL8S57UUTzssRyE4Xoahq DiMRUf0B6Tj715YdFb5KxLtje7IDOWFnZKTD67G+LQKQn4vx3/RMnjGzXZZ1gJ7JtvF9 HK/nT7H+BdCSE1nxuj0rnAEinzKXwRh14TM2ZoFsM88IBLaFdtqgCPL3v6qPWkGXI+hm T93Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RiG/ybc/; 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 m26si5700802ioi.291.2017.09.18.03.35.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Sep 2017 03:35:04 -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=RiG/ybc/; 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 1dttN3-000389-69; Mon, 18 Sep 2017 10:33:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dttN1-000350-JE for xen-devel@lists.xenproject.org; Mon, 18 Sep 2017 10:33:43 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id C4/44-26922-601AFB95; Mon, 18 Sep 2017 10:33:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsXiVRusr8uycH+ kwfZP1hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aHs+cYC35ZV5zdPYexgbFbp4uRk0NIYCqj xJm9/F2MXBwsAvOYJV6/WM4C4kgI9LNKLFz3iBGkSkIgTWLx21/sMPatf+1QdqXEic6fTBCTt CSOnprNCtIsJLCDSeLs7UlADgcHm4CJxKwOCZAaEQEliXurJoPVMwvUS2w79wtsvrBAnsTX16 /AZrIIqEr8+3SSFcTmFfCRuHbjNhPELjmJm+c6mUFsTqD4+fUPWCH2ekvM+3WFcQKj4AJGhlW MGsWpRWWpRbqGBnpJRZnpGSW5iZk5QJ6ZXm5qcXFiempOYlKxXnJ+7iZGYMAxAMEOxuPv4w4x SnIwKYnyikbujxTiS8pPqcxILM6ILyrNSS0+xCjDwaEkwbt6PlBOsCg1PbUiLTMHGPowaQkOH iUR3nUgad7igsTc4sx0iNQpRkuOfXtu/WHiWHH9NpDsuHn3D5MQS15+XqqUOG8dSIMASENGaR 7cOFh8XmKUlRLmZQQ6UIinILUoN7MEVf4VozgHo5Iw7zKQKTyZeSVwW18BHcQEdFDLjj0gB5U kIqSkGhhV9skeP8p47cyeU3N+vVopqZZV/y959YOd9zn3Sd7hrvjDYWZxT6/mUMCR1v0uN8w8 ZRheynM0dV14Ksuwc03s4423nCr/i56IcD8423Cvp8rGuYKTCzgVIvV6Lz932WtrfXme/ub7w bf/+RyXu//uauTC42skqkpn/Tiss/7k2gB+26yLBy2PK7EUZyQaajEXFScCANUT3nvKAgAA X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-4.tower-21.messagelabs.com!1505730819!77164974!1 X-Originating-IP: [74.125.83.47] 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 39507 invoked from network); 18 Sep 2017 10:33:40 -0000 Received: from mail-pg0-f47.google.com (HELO mail-pg0-f47.google.com) (74.125.83.47) by server-4.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Sep 2017 10:33:40 -0000 Received: by mail-pg0-f47.google.com with SMTP id v66so32724pgb.5 for ; Mon, 18 Sep 2017 03:33:40 -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=71xGGLc0Xz4xep+AAwWpw9wKhm4rwTN8GTzuJyNx6LE=; b=RiG/ybc/aG/vCGxT/zJXWo4R1llRsfc5BApj2GLhKhS9+pE419VT1qG2Zybcu2mzd0 gFJ3A2S192y23tNIbcs/VotJpPXP4jCnzAq8xRnlFTZcQg8x3bRHILXKBphNZ2SKi0Ke zhTsfWabFbB/nzJ90yr5d7NTca230YInPEqm4= 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=71xGGLc0Xz4xep+AAwWpw9wKhm4rwTN8GTzuJyNx6LE=; b=kZzcKEkpQzMuxBvlgeAzs7nkNHaO9sXnmZ9xB+j2UNE5DHuidAKAe5WhTd6ghB5LeE GDsbGHKoyI3EH8SNd1I9HlRe3p6qgw0RDgVI1zrmeIk05uxjAa44MNRd93ksFLgQ/NH3 wZN0eHYUgFCZ8b53LsGFimNn01HoEECOzGXfh0tD1pBw7sLdiB3kbu0UQFnFNCHmyCaY li/aX1pMQp59RyRbHDvZtMVFkt8Y9+hlKyJCvhE+jwo9GpayQ0e5VZ8nC8Cg+OqZPXrW Wp2lP7bHqjh64QNhuGF7cYr/A5PPMxd7mC/Zv1sYND4GCnAvodGOleQrMEvP+L0K+B2I gQzg== X-Gm-Message-State: AHPjjUj+zpavXTMCVXUnQmJPqnnFQgyshvuh080efwjyxP15TjrXBkwx 78DdxL9VKvc+lHQNHmwGgg== X-Google-Smtp-Source: AOwi7QAqN4n9hPbi6tJKZtYcCbSqnq6adAsFkSnL10HjxUdCMrgft89GRBwIYMMM3bF0GLS0GW9t9A== X-Received: by 10.99.106.67 with SMTP id f64mr5882663pgc.101.1505730819192; Mon, 18 Sep 2017 03:33:39 -0700 (PDT) Received: from blr-ubuntu-linaro.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id b7sm12937845pge.79.2017.09.18.03.33.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Sep 2017 03:33:38 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Mon, 18 Sep 2017 16:02:11 +0530 Message-Id: <1505730731-10947-28-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505730731-10947-1-git-send-email-bhupinder.thakur@linaro.org> References: <1505730731-10947-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Andre Przywara , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 27/27 v9] 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 executing '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 any register where the TX interrupt thresold can be set. 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 (as expected by the SBSA UART driver). 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;