From: Bhupinder Thakur <bhupinder.thakur@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: Andre Przywara <andre.przywara@arm.com>,
Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH 27/27 v11] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt
Date: Wed, 27 Sep 2017 11:43:36 +0530 [thread overview]
Message-ID: <1506492816-25954-28-git-send-email-bhupinder.thakur@linaro.org> (raw)
In-Reply-To: <1506492816-25954-1-git-send-email-bhupinder.thakur@linaro.org>
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 <bhupinder.thakur@linaro.org>
---
CC: Julien Grall <julien.grall@arm.com>
CC: Andre Przywara <andre.przywara@arm.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
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;
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-09-27 6:14 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 6:13 [PATCH 00/27 v11] SBSA UART emulation support in Xen Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 01/27 v11] xen/arm: vpl011: Define common ring buffer helper functions in console.h Bhupinder Thakur
2017-09-29 20:10 ` Stefano Stabellini
2017-09-29 21:35 ` Julien Grall
2017-09-29 21:46 ` Stefano Stabellini
2017-10-03 22:27 ` Stefano Stabellini
2017-09-27 6:13 ` [PATCH 02/27 v11] xen/arm: vpl011: Add SBSA UART emulation in Xen Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 03/27 v11] xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 04/27 v11] xen/arm: vpl011: Add support for vuart in libxl Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 05/27 v11] xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 06/27 v11] xen/arm: vpl011: Add a new domctl API to initialize vpl011 Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 07/27 v11] xen/arm: vpl011: Add a new vuart node in the xenstore Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 08/27 v11] xen/arm: vpl011: Modify xenconsole to define and use a new console structure Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 09/27 v11] xen/arm: vpl011: Rename the console structure field conspath to xspath Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 10/27 v11] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 11/27 v11] xen/arm: vpl011: Add a new console_init function in xenconsole Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 12/27 v11] xen/arm: vpl011: Add a new buffer_available " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 13/27 v11] xen/arm: vpl011: Add a new maybe_add_console_evtchn_fd " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 14/27 v11] xen/arm: vpl011: Add a new maybe_add_console_tty_fd " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 15/27 v11] xen/arm: vpl011: Add a new console_evtchn_unmask " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 16/27 v11] xen/arm: vpl011: Add a new handle_console_ring " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 17/27 v11] xen/arm: vpl011: Add a new handle_console_tty " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 18/27 v11] xen/arm: vpl011: Add a new console_cleanup " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 19/27 v11] xen/arm: vpl011: Add a new console_open_log " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 20/27 v11] xen/arm: vpl011: Add a new console_close_evtchn " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 21/27 v11] xen/arm: vpl011: Add support for multiple consoles " Bhupinder Thakur
2017-10-04 14:03 ` Boris Ostrovsky
2017-10-04 14:06 ` Wei Liu
2017-10-04 14:28 ` Boris Ostrovsky
2017-10-04 14:29 ` Wei Liu
2017-10-04 14:52 ` Boris Ostrovsky
2017-09-27 6:13 ` [PATCH 22/27 v11] xen/arm: vpl011: Add support for vuart console " Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 23/27 v11] xen/arm: vpl011: Add a new vuart console type to xenconsole client Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 24/27 v11] xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 25/27 v11] xen/arm: vpl011: Update documentation for vuart console support Bhupinder Thakur
2017-09-27 6:13 ` [PATCH 26/27 v11] xen/arm: vpl011: Fix the slow early console SBSA UART output Bhupinder Thakur
2017-09-27 6:13 ` Bhupinder Thakur [this message]
2017-10-09 17:18 ` [PATCH 27/27 v11] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt Andre Przywara
2017-10-12 9:33 ` Bhupinder Thakur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1506492816-25954-28-git-send-email-bhupinder.thakur@linaro.org \
--to=bhupinder.thakur@linaro.org \
--cc=andre.przywara@arm.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).