lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190221171758.10322-4-martin.kepplinger@ginzinger.com>
Date:   Thu, 21 Feb 2019 18:17:53 +0100
From:   Martin Kepplinger <martin.kepplinger@...zinger.com>
To:     <gregkh@...uxfoundation.org>, <robh+dt@...nel.org>,
        <mark.rutland@....com>, <jslaby@...e.com>, <corbet@....net>,
        <richard.genoud@...il.com>, <nicolas.ferre@...rochip.com>,
        <alexandre.belloni@...tlin.com>, <ludovic.desroches@...rochip.com>,
        <mcoquelin.stm32@...il.com>, <alexandre.torgue@...com>,
        <linux-serial@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>,
        <linux-stm32@...md-mailman.stormreply.com>
CC:     <linux-kernel@...r.kernel.org>,
        Martin Kepplinger <martin.kepplinger@...zinger.com>
Subject: [PATCH v2 4/9] serial: 8250: add support for rs485 RTS delays in microseconds

Read struct serial_rs485's flag SER_RS485_DELAY_IN_USEC and apply the delay
accordingly.

Signed-off-by: Martin Kepplinger <martin.kepplinger@...zinger.com>
---
 drivers/tty/serial/8250/8250_omap.c | 13 +++++++++++--
 drivers/tty/serial/8250/8250_port.c | 25 +++++++++++++++++++++----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index 0a8316632d75..cbce43ac60b1 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -720,8 +720,17 @@ static int omap_8250_rs485_config(struct uart_port *port,
 	struct uart_8250_port *up = up_to_u8250p(port);
 
 	/* Clamp the delays to [0, 100ms] */
-	rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
-	rs485->delay_rts_after_send  = min(rs485->delay_rts_after_send, 100U);
+	if (rs485->flags & SER_RS485_DELAY_IN_USEC) {
+		rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+						   100000U);
+		rs485->delay_rts_after_send  = min(rs485->delay_rts_after_send,
+						   100000U);
+	} else {
+		rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+						   100U);
+		rs485->delay_rts_after_send  = min(rs485->delay_rts_after_send,
+						   100U);
+	}
 
 	port->rs485 = *rs485;
 
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index d2f3310abe54..0cee4aa8323d 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1483,6 +1483,15 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
 	hrtimer_start(hrt, t, HRTIMER_MODE_REL);
 }
 
+static void start_hrtimer_us(struct hrtimer *hrt, unsigned long usec)
+{
+	long sec = usec / 1000000;
+	long nsec = (usec % 1000000) * 1000000000;
+	ktime_t t = ktime_set(sec, nsec);
+
+	hrtimer_start(hrt, t, HRTIMER_MODE_REL);
+}
+
 static void __stop_tx_rs485(struct uart_8250_port *p)
 {
 	struct uart_8250_em485 *em485 = p->em485;
@@ -1493,8 +1502,12 @@ static void __stop_tx_rs485(struct uart_8250_port *p)
 	 */
 	if (p->port.rs485.delay_rts_after_send > 0) {
 		em485->active_timer = &em485->stop_tx_timer;
-		start_hrtimer_ms(&em485->stop_tx_timer,
-				   p->port.rs485.delay_rts_after_send);
+		if (p->port.rs485.flags & SER_RS485_DELAY_IN_USEC)
+			start_hrtimer_us(&em485->stop_tx_timer,
+					 p->port.rs485.delay_rts_after_send);
+		else
+			start_hrtimer_ms(&em485->stop_tx_timer,
+					 p->port.rs485.delay_rts_after_send);
 	} else {
 		__do_stop_tx_rs485(p);
 	}
@@ -1600,8 +1613,12 @@ static inline void start_tx_rs485(struct uart_port *port)
 
 		if (up->port.rs485.delay_rts_before_send > 0) {
 			em485->active_timer = &em485->start_tx_timer;
-			start_hrtimer_ms(&em485->start_tx_timer,
-					 up->port.rs485.delay_rts_before_send);
+			if (up->port.rs485.flags & SER_RS485_DELAY_IN_USEC)
+				start_hrtimer_us(&em485->start_tx_timer,
+					up->port.rs485.delay_rts_before_send);
+			else
+				start_hrtimer_ms(&em485->start_tx_timer,
+					up->port.rs485.delay_rts_before_send);
 			return;
 		}
 	}
-- 
2.20.1


Download attachment "smime.p7s" of type "application/x-pkcs7-signature" (3616 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ