From patchwork Wed Mar 21 02:52:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 888524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405ZHj2wgKz9ryG for ; Wed, 21 Mar 2018 13:58:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="BzwFBisi"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 405ZHj1FVWzF1ZS for ; Wed, 21 Mar 2018 13:58:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="BzwFBisi"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 405ZDg1y23zF1Zk; Wed, 21 Mar 2018 13:55:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="BzwFBisi"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 405ZDg0Ll9z9s16; Wed, 21 Mar 2018 13:55:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1521600947; bh=t/Xx6xq47cCweFWjVlDpDlMcGm8cYsBP3OHU0r8Sbwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BzwFBisimno/juqfABiZyfvoN3lLYqc/RVKsJchyizroB0F10QNMHwtfjSBX41Gi/ +93bLCQeFdwml79ZuZEd0g/q7Q6hxo/VG5Bi9uAmkU28sCMfTJYh4bvS5ulfJIoUx+ I0G6w9UWtm0IC5keGBqLAPReM1jVTa6bgRJQfxb9lrv621SAkRaT+TOrDvmaCqz4y3 5LlLM9tjY57AFVcCEBf9bmS/+SyvDhTK1Y8E2XlGIO3rziDvC6F8iL8mdhsod0RpKm FY+1hyT+OtN5bsNTpO3QcjLrTU8qBHW8FEuOHonimDzGCah/FvQHrYNHLeQ7YF0QsX g6JgH0Pkb3UGQ== From: Jeremy Kerr To: linux-serial@vger.kernel.org Subject: [PATCH 1/5] serial: Introduce UPSTAT_SYNC_FIFO for synchronised FIFOs Date: Wed, 21 Mar 2018 10:52:37 +0800 Message-Id: <20180321025241.19785-2-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321025241.19785-1-jk@ozlabs.org> References: <20180321025241.19785-1-jk@ozlabs.org> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, Greg Kroah-Hartman , openbmc@lists.ozlabs.org, Jiri Slaby , Jeremy Kerr Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" This change adds a flag to indicate that a UART is has an external means of synchronising its FIFO, without needing CTSRTS or XON/XOFF. This allows us to use the throttle/unthrottle callbacks, without having to claim other methods of flow control. Signed-off-by: Jeremy Kerr Tested-by: Eddie James --- drivers/tty/serial/serial_core.c | 4 ++-- include/linux/serial_core.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f534a40aebde..8f3dfc8b5307 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -678,7 +678,7 @@ static void uart_throttle(struct tty_struct *tty) if (C_CRTSCTS(tty)) mask |= UPSTAT_AUTORTS; - if (port->status & mask) { + if (port->status & (mask | UPSTAT_SYNC_FIFO)) { port->ops->throttle(port); mask &= ~port->status; } @@ -707,7 +707,7 @@ static void uart_unthrottle(struct tty_struct *tty) if (C_CRTSCTS(tty)) mask |= UPSTAT_AUTORTS; - if (port->status & mask) { + if (port->status & (mask | UPSTAT_SYNC_FIFO)) { port->ops->unthrottle(port); mask &= ~port->status; } diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 1775500294bb..bf600ae0290d 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -232,6 +232,7 @@ struct uart_port { #define UPSTAT_AUTORTS ((__force upstat_t) (1 << 2)) #define UPSTAT_AUTOCTS ((__force upstat_t) (1 << 3)) #define UPSTAT_AUTOXOFF ((__force upstat_t) (1 << 4)) +#define UPSTAT_SYNC_FIFO ((__force upstat_t) (1 << 5)) int hw_stopped; /* sw-assisted CTS flow state */ unsigned int mctrl; /* current modem ctrl settings */ From patchwork Wed Mar 21 02:52:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 888527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405ZJZ0Rl1z9ryG for ; Wed, 21 Mar 2018 13:59:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Y+R3Rp3C"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 405ZJY5LwhzF1WP for ; Wed, 21 Mar 2018 13:59:09 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Y+R3Rp3C"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 405ZDh12c3zF1bT; Wed, 21 Mar 2018 13:55:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Y+R3Rp3C"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 405ZDg5zxXz9s02; Wed, 21 Mar 2018 13:55:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1521600947; bh=PE5IOMnQR4fNaptlpqlDri4hA0/3384Cfz3j8Gz6plo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+R3Rp3CCWZ0m29gn6ge+jI8q0Cor9FvIdJOA0OqexOTnElmKIgrThSdYAmFuB8it /J+7in3RAhuuZaZr9wh+Xjc5b3P9JOco0ureGUHcsPv6O1GRwuWkg0wL/H2nRgf1fe 1F9C5+G8UbezEs9zhV7UyNrxjE/cFO+q/fFUC9XYaV4BD0VGbMs2jQs6u+uBDFaRi1 LlBfeGzwkU6kueSG/5IBrAJaxHNsx3YMyH0KB240uFimGoI0v7eIswGlp9/Tl9zViK 7NP1iNS3sLkhVOLLPt+sgkiFkDSTcnz3CT+wkMQNeypYpPQYCm4sR8JZzvK99+25Q8 frlE6OGfjC2Yw== From: Jeremy Kerr To: linux-serial@vger.kernel.org Subject: [PATCH 2/5] serial: expose buf_overrun count through proc interface Date: Wed, 21 Mar 2018 10:52:38 +0800 Message-Id: <20180321025241.19785-3-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321025241.19785-1-jk@ozlabs.org> References: <20180321025241.19785-1-jk@ozlabs.org> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, Greg Kroah-Hartman , openbmc@lists.ozlabs.org, Jiri Slaby , Jeremy Kerr Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" The buf_overrun count is only every written, and not exposed to userspace anywhere. This means that dropped characters due to flip buffer overruns are never visible to userspace. The /proc/tty/driver/serial file exports a bunch of metrics (including hardware overruns) already, so add the buf_overrun (as "bo:") to this file. Signed-off-by: Jeremy Kerr Tested-by: Eddie James --- drivers/tty/serial/serial_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 8f3dfc8b5307..fc677534b510 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1780,6 +1780,8 @@ static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i) seq_printf(m, " brk:%d", uport->icount.brk); if (uport->icount.overrun) seq_printf(m, " oe:%d", uport->icount.overrun); + if (uport->icount.buf_overrun) + seq_printf(m, " bo:%d", uport->icount.buf_overrun); #define INFOBIT(bit, str) \ if (uport->mctrl & (bit)) \ From patchwork Wed Mar 21 02:52:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 888530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405ZLT5Vqzz9s02 for ; Wed, 21 Mar 2018 14:00:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ZPyuUYtx"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 405ZLT3bmTzF1Wm for ; Wed, 21 Mar 2018 14:00:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ZPyuUYtx"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 405ZDh3vxYzF1Zv; Wed, 21 Mar 2018 13:55:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ZPyuUYtx"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 405ZDh0Wx7z9s1c; Wed, 21 Mar 2018 13:55:47 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1521600948; bh=YWvCm9vfNybsF6T2DBiOuTu306t7bmW50RSYwIpP9DY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZPyuUYtxIkYEprkA6/+oDC1DC5IGbTzZ/iZb2FNmphSsyw1RSPtf6kejwcmfx0Hv4 8d+34kS5JzbHHSxD2QMc/aGFvgRGAWgY+UXaNlSpAz7j3X1ZMjw1RR7mfjL6CCZrUq FrSNFiYkaKWpISUK1vWKXiYMlGcELE/K113DswQILBBZlNQtPnHHaTRaydoZqdl49k rDhQ3wbbCZi7nlJylWupRw0F1AMDyDv961C4IbKYniQgyP1p3eLjkilCDmBFPecZBw WYbdCIV0MBWXiLwY92w/zkZHdnKK3THZyYp3U2nm60xeR6TJSo0jVF4bJims3qejA8 gA1hxBmTdmEeQ== From: Jeremy Kerr To: linux-serial@vger.kernel.org Subject: [PATCH 3/5] serial/8250: export serial8250_read_char Date: Wed, 21 Mar 2018 10:52:39 +0800 Message-Id: <20180321025241.19785-4-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321025241.19785-1-jk@ozlabs.org> References: <20180321025241.19785-1-jk@ozlabs.org> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, Greg Kroah-Hartman , openbmc@lists.ozlabs.org, Jiri Slaby , Jeremy Kerr Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Currently, we export serial8250_rx_chars, which does a whole bunch of reads from the 8250 data register, without any form of flow control between reads. An upcoming change to the aspeed vuart driver implements more fine-grained flow control in the interrupt handler, requiring character-at-a-time control over the rx path. This change exports serial8250_read_char to allow this. Signed-off-by: Jeremy Kerr Tested-by: Eddie James --- drivers/tty/serial/8250/8250_port.c | 3 ++- include/linux/serial_8250.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index a5fe0e66c607..ea435406936c 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1650,7 +1650,7 @@ static void serial8250_enable_ms(struct uart_port *port) serial8250_rpm_put(up); } -static void serial8250_read_char(struct uart_8250_port *up, unsigned char lsr) +void serial8250_read_char(struct uart_8250_port *up, unsigned char lsr) { struct uart_port *port = &up->port; unsigned char ch; @@ -1710,6 +1710,7 @@ static void serial8250_read_char(struct uart_8250_port *up, unsigned char lsr) uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); } +EXPORT_SYMBOL_GPL(serial8250_read_char); /* * serial8250_rx_chars: processes according to the passed in LSR diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index 61fbb440449c..4639a3608614 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -162,6 +162,7 @@ extern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl); extern int fsl8250_handle_irq(struct uart_port *port); int serial8250_handle_irq(struct uart_port *port, unsigned int iir); unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr); +void serial8250_read_char(struct uart_8250_port *up, unsigned char lsr); void serial8250_tx_chars(struct uart_8250_port *up); unsigned int serial8250_modem_status(struct uart_8250_port *up); void serial8250_init_port(struct uart_8250_port *up); From patchwork Wed Mar 21 02:52:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 888521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405ZG01Kkzz9ryG for ; Wed, 21 Mar 2018 13:56:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="CUQjXHlu"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 405ZFz6HgNzF1gt for ; Wed, 21 Mar 2018 13:56:55 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="CUQjXHlu"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 405ZDg4tPpzF1Zv; Wed, 21 Mar 2018 13:55:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="CUQjXHlu"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 405ZDf65gkz9s0W; Wed, 21 Mar 2018 13:55:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1521600946; bh=Le4vV5w0IrSmHwWEsMPfIKMowxE3uI3FfFDpZcvSdYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CUQjXHluld+XhU1v2vbipGg6gHdA2/MMzWQVGCBuyrTYa1F5U4ndtQKQuVvuQyaS2 qEFuUHGWsUxffVHmF3P3yig/MkG4pkS9aco3UzooGsZhvmm5zYZXML4cqDOTaUy+ty QDPU7hCLHbcJngSdFnDch3NMwqO22RJhPZLgScO73zWTjhC0TjtF3BWKNitMzHuPmV wRBIH6MsifUu4ymZ7MPUk7MZ8sbePO5AA1AJOxfPpKMUT4nchtKrUDRFnpr7RNybRx pFZVWeTdET9Tp9KT0ClOJDrRElm4Uk66oksB0I6YJNvxRYPeqJeXwcV6O6UdK7IlyN DDdB8tWj+IihQ== From: Jeremy Kerr To: linux-serial@vger.kernel.org Subject: [PATCH 4/5] serial/aspeed-vuart: Implement rx throttling Date: Wed, 21 Mar 2018 10:52:40 +0800 Message-Id: <20180321025241.19785-5-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321025241.19785-1-jk@ozlabs.org> References: <20180321025241.19785-1-jk@ozlabs.org> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, Greg Kroah-Hartman , openbmc@lists.ozlabs.org, Jiri Slaby , Jeremy Kerr Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" The aspeed VUART runs at LPC bus frequency, rather than being restricted to a typical UART baud rate. This means that the VUART can receive a lot of data, which can overrun tty flip buffers, and/or cause a large amount of interrupt traffic. This change implements the uart_port->throttle & unthrottle callbacks, implemented by disabling the receiver line status & received data available IRQs. Signed-off-by: Jeremy Kerr Tested-by: Eddie James --- drivers/tty/serial/8250/8250_aspeed_vuart.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c index 33a801353114..50c082b4a1ac 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -183,6 +183,30 @@ static void aspeed_vuart_shutdown(struct uart_port *uart_port) serial8250_do_shutdown(uart_port); } +static void aspeed_vuart_set_throttle(struct uart_port *port, bool throttle) +{ + unsigned char irqs = UART_IER_RLSI | UART_IER_RDI; + struct uart_8250_port *up = up_to_u8250p(port); + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + up->ier &= ~irqs; + if (!throttle) + up->ier |= irqs; + serial_out(up, UART_IER, up->ier); + spin_unlock_irqrestore(&port->lock, flags); +} + +static void aspeed_vuart_throttle(struct uart_port *port) +{ + aspeed_vuart_set_throttle(port, true); +} + +static void aspeed_vuart_unthrottle(struct uart_port *port) +{ + aspeed_vuart_set_throttle(port, false); +} + static int aspeed_vuart_probe(struct platform_device *pdev) { struct uart_8250_port port; @@ -212,6 +236,9 @@ static int aspeed_vuart_probe(struct platform_device *pdev) port.port.mapsize = resource_size(res); port.port.startup = aspeed_vuart_startup; port.port.shutdown = aspeed_vuart_shutdown; + port.port.throttle = aspeed_vuart_throttle; + port.port.unthrottle = aspeed_vuart_unthrottle; + port.port.status = UPSTAT_SYNC_FIFO; port.port.dev = &pdev->dev; rc = sysfs_create_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); From patchwork Wed Mar 21 02:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 888519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405ZDp64NWz9s0W for ; Wed, 21 Mar 2018 13:55:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="wU1iDksF"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 405ZDp47s4zF1bT for ; Wed, 21 Mar 2018 13:55:54 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="wU1iDksF"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 405ZDg6bZxzF1bM; Wed, 21 Mar 2018 13:55:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="wU1iDksF"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 405ZDg2L6wz9s1S; Wed, 21 Mar 2018 13:55:47 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1521600947; bh=zRxiBbLgIUpoe42OYoI8JgogSroQFB7xGf8iM22NQRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wU1iDksFbLJ+8G+2FIN7QVTkOJK2dfkSdsuLLUiBO9t1gcEAsB7A02qopPqlgv3F+ DF2FafcjEpduc7hQy72tg1mYWP5VPXFVuNNIJ59+5ijNVqxYu9vgk78RaHh92S80Rx xTelIMRZbVSj4wK0GXDd5owJ35I8+exnOhn8nXA+jE/ts65B9ONz3aEUNk1VIGfm7h XBNEZ9OKE+Uin5pzjytgvgE6lz3CGSfBFE18yP4MvwqbNoqUt2nipBeOIbwdlPe0Hu C2JOwpOEivp3lRoaBhmhBeH2AcH/P4QfT85tj7ytfm36tlTIXZ1A+PDrPz7qxZ0F98 uT+4nCfPA5DnA== From: Jeremy Kerr To: linux-serial@vger.kernel.org Subject: [PATCH 5/5] serial/aspeed-vuart: Implement quick throttle mechanism Date: Wed, 21 Mar 2018 10:52:41 +0800 Message-Id: <20180321025241.19785-6-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321025241.19785-1-jk@ozlabs.org> References: <20180321025241.19785-1-jk@ozlabs.org> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, Greg Kroah-Hartman , openbmc@lists.ozlabs.org, Jiri Slaby , Jeremy Kerr Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Although we populate the ->throttle and ->unthrottle UART operations, these may not be called until the ldisc has had a chance to schedule and check buffer space. This means that we may overflow the flip buffers without ever hitting the ldisc's throttle threshold. This change implements an interrupt-based throttle, where we check for space in the flip buffers before reading characters from the UART's FIFO. If there's no space available, we disable the RX interrupt and schedule a timer to check for space later. This prevents a case where we drop characters under heavy RX load. Signed-off-by: Jeremy Kerr Tested-by: Eddie James --- drivers/tty/serial/8250/8250_aspeed_vuart.c | 103 ++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c index 50c082b4a1ac..bc2b63578e58 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include "8250.h" @@ -32,8 +34,16 @@ struct aspeed_vuart { void __iomem *regs; struct clk *clk; int line; + struct timer_list unthrottle_timer; }; +/* + * If we fill the tty flip buffers, we throttle the data ready interrupt + * to prevent dropped characters. This timeout defines how long we wait + * to (conditionally, depending on buffer state) unthrottle. + */ +static const int unthrottle_timeout = HZ/10; + /* * The VUART is basically two UART 'front ends' connected by their FIFO * (no actual serial line in between). One is on the BMC side (management @@ -183,17 +193,23 @@ static void aspeed_vuart_shutdown(struct uart_port *uart_port) serial8250_do_shutdown(uart_port); } -static void aspeed_vuart_set_throttle(struct uart_port *port, bool throttle) +static void __aspeed_vuart_set_throttle(struct uart_8250_port *up, + bool throttle) { unsigned char irqs = UART_IER_RLSI | UART_IER_RDI; - struct uart_8250_port *up = up_to_u8250p(port); - unsigned long flags; - spin_lock_irqsave(&port->lock, flags); up->ier &= ~irqs; if (!throttle) up->ier |= irqs; serial_out(up, UART_IER, up->ier); +} +static void aspeed_vuart_set_throttle(struct uart_port *port, bool throttle) +{ + struct uart_8250_port *up = up_to_u8250p(port); + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + __aspeed_vuart_set_throttle(up, throttle); spin_unlock_irqrestore(&port->lock, flags); } @@ -207,6 +223,81 @@ static void aspeed_vuart_unthrottle(struct uart_port *port) aspeed_vuart_set_throttle(port, false); } +static void aspeed_vuart_unthrottle_exp(unsigned long data) +{ + struct uart_8250_port *up = (void *)data; + struct aspeed_vuart *vuart = up->port.private_data; + + if (!tty_buffer_space_avail(&up->port.state->port)) { + mod_timer(&vuart->unthrottle_timer, unthrottle_timeout); + return; + } + + aspeed_vuart_unthrottle(&up->port); +} + +/* + * Custom interrupt handler to manage finer-grained flow control. Although we + * have throttle/unthrottle callbacks, we've seen that the VUART device can + * deliver characters faster than the ldisc has a chance to check buffer space + * against the throttle threshold. This results in dropped characters before + * the throttle. + * + * We do this by checking for flip buffer space before RX. If we have no space, + * throttle now and schedule an unthrottle for later, once the ldisc has had + * a chance to drain the buffers. + */ +static int aspeed_vuart_handle_irq(struct uart_port *port) { struct + uart_8250_port *up = up_to_u8250p(port); unsigned int iir, lsr; + unsigned long flags; int space, count; + + iir = serial_port_in(port, UART_IIR); + + if (iir & UART_IIR_NO_INT) + return 0; + + spin_lock_irqsave(&port->lock, flags); + + lsr = serial_port_in(port, UART_LSR); + + if (lsr & (UART_LSR_DR | UART_LSR_BI)) { + space = tty_buffer_space_avail(&port->state->port); + + if (!space) { + /* throttle and schedule an unthrottle later */ + struct aspeed_vuart *vuart = port->private_data; + __aspeed_vuart_set_throttle(up, true); + + if (!timer_pending(&vuart->unthrottle_timer)) { + vuart->unthrottle_timer.data = + (unsigned long)up; + mod_timer(&vuart->unthrottle_timer, + unthrottle_timeout); + } + + } else { + count = min(space, 256); + + do { + serial8250_read_char(up, lsr); + lsr = serial_in(up, UART_LSR); + if (--count == 0) + break; + } while (lsr & (UART_LSR_DR | UART_LSR_BI)); + + tty_flip_buffer_push(&port->state->port); + } + } + + serial8250_modem_status(up); + if (lsr & UART_LSR_THRE) + serial8250_tx_chars(up); + + spin_unlock_irqrestore(&port->lock, flags); + + return 1; +} + static int aspeed_vuart_probe(struct platform_device *pdev) { struct uart_8250_port port; @@ -223,6 +314,8 @@ static int aspeed_vuart_probe(struct platform_device *pdev) return -ENOMEM; vuart->dev = &pdev->dev; + setup_timer(&vuart->unthrottle_timer, + aspeed_vuart_unthrottle_exp, (unsigned long)vuart); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); vuart->regs = devm_ioremap_resource(&pdev->dev, res); @@ -284,6 +377,7 @@ static int aspeed_vuart_probe(struct platform_device *pdev) port.port.irq = irq_of_parse_and_map(np, 0); port.port.irqflags = IRQF_SHARED; + port.port.handle_irq = aspeed_vuart_handle_irq; port.port.iotype = UPIO_MEM; port.port.type = PORT_16550A; port.port.uartclk = clk; @@ -323,6 +417,7 @@ static int aspeed_vuart_remove(struct platform_device *pdev) { struct aspeed_vuart *vuart = platform_get_drvdata(pdev); + del_timer_sync(&vuart->unthrottle_timer); aspeed_vuart_set_enabled(vuart, false); serial8250_unregister_port(vuart->line); sysfs_remove_group(&vuart->dev->kobj, &aspeed_vuart_attr_group);