From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W08Ou-0000U4-KH for qemu-devel@nongnu.org; Mon, 06 Jan 2014 06:31:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W08Ot-0004RT-Kq for qemu-devel@nongnu.org; Mon, 06 Jan 2014 06:31:20 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:44223) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W08Ot-0004QZ-FP for qemu-devel@nongnu.org; Mon, 06 Jan 2014 06:31:19 -0500 From: Peter Maydell Date: Mon, 6 Jan 2014 11:30:48 +0000 Message-Id: <1389007857-14649-44-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1389007857-14649-1-git-send-email-peter.maydell@linaro.org> References: <1389007857-14649-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 43/52] char/cadence_uart: Fix can_receive logic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Blue Swirl , qemu-devel@nongnu.org, Aurelien Jarno From: Peter Crosthwaite The can_receive logic was only taking into account the RxFIFO occupancy. RxFIFO population is only used for the echo and normal modes however. Improve the logic to correctly return the true number of receivable characters based on the current mode: Normal mode: RxFIFO vacancy. Remote loopback: TxFIFO vacancy. Echo mode: The min of the TxFIFO and RxFIFO vacancies. Local Loopback: Return non-zero (to implement droppage) Signed-off-by: Peter Crosthwaite Message-id: 36a58440c9ca5080151e95765c2c81342de8a8df.1388626249.git.peter.crosthwaite@xilinx.com Signed-off-by: Peter Maydell --- hw/char/cadence_uart.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index 3eeadb1..3bcaf29 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -233,8 +233,16 @@ static void uart_parameters_setup(UartState *s) static int uart_can_receive(void *opaque) { UartState *s = (UartState *)opaque; + int ret = MAX(RX_FIFO_SIZE, TX_FIFO_SIZE); + uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE; - return RX_FIFO_SIZE - s->rx_count; + if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) { + ret = MIN(ret, RX_FIFO_SIZE - s->rx_count); + } + if (ch_mode == REMOTE_LOOPBACK || ch_mode == ECHO_MODE) { + ret = MIN(ret, TX_FIFO_SIZE - s->tx_count); + } + return ret; } static void uart_ctrl_update(UartState *s) -- 1.8.5