Skip to contentSkip to conversation

serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers

PATCH Superseded Yoshihiro YUNOMAE 3 participants 8 messages Apr 15, 2014 – Apr 17, 2014

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers

Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control or sending communication devices. For the latter uses, normally small data will be exchanged, so user applications want to receive data unit as soon as possible for real-time tendency. If we have a sensor which sends a 1 byte data each time and must control a device based on the sensor feedback, the RX interrupt should be triggered for each data.

According to HW specification of serial UART devices, RX interrupt trigger can be changed, but the trigger is hard-coded. For example, RX interrupt trigger in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets the trigger to only 8bytes.

This patch makes some devices change RX interrupt trigger from userland.

<How to use>
- Read current setting

 # cat /sys/dev/char/4\:64/rx_int_trig
 8

- Write user setting

 # echo 1 > /sys/dev/char/4\:64/rx_int_trig
 # cat /sys/dev/char/4\:64/rx_int_trig
 1

<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)

Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself

Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)

Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()

Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[] in convert_fcr2val() and convert_val2rxtrig()

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Jingoo Han <[email protected]>
Cc Aaron Sierra <[email protected]>
Cc Stephen Warren <[email protected]>
---
 drivers/tty/serial/8250/8250.h      |    7 +
 drivers/tty/serial/8250/8250_core.c |  184 ++++++++++++++++++++++++++++++++---
 drivers/tty/serial/serial_core.c    |   18 ++-
 include/linux/serial_8250.h         |    2 
 include/linux/serial_core.h         |    4 +
 5 files changed, 193 insertions(+), 22 deletions(-)
drivers/tty/serial/8250/8250.h +7 -0
index 1ebf853..ab5d812 100644
@@ -12,6 +12,7 @@
  */
 
 #include <linux/serial_8250.h>
+#include <linux/serial_reg.h>
 #include <linux/dmaengine.h>
 
 struct uart_8250_dma {
@@ -55,11 +56,17 @@ struct old_serial_port {
 	unsigned long irqflags;
 };
 
+#define FCR_RX_TRIG_OFFSET	6
+#define FCR_RX_TRIG_BITS(x)	(((x) >> FCR_RX_TRIG_OFFSET) & 0x3)
+#define FCR_RX_TRIG_MAX_STATE	\
+((FCR_RX_TRIG_BITS(UART_FCR_R_TRIG_11))-(FCR_RX_TRIG_BITS(UART_FCR_R_TRIG_00)))
+
 struct serial8250_config {
 	const char	*name;
 	unsigned short	fifo_size;
 	unsigned short	tx_loadsz;
 	unsigned char	fcr;
+	unsigned char	rx_trig_byte[FCR_RX_TRIG_MAX_STATE];
 	unsigned int	flags;
 };
 
drivers/tty/serial/8250/8250_core.c +169 -15

271 lines not on this page · raw message

drivers/tty/serial/serial_core.c +11 -7
index 2cf5649..41ac44b 100644
@@ -2548,15 +2548,16 @@ static struct attribute *tty_dev_attrs[] = {
 	NULL,
 	};
 
-static const struct attribute_group tty_dev_attr_group = {
+static struct attribute_group tty_dev_attr_group = {
 	.attrs = tty_dev_attrs,
 	};
 
-static const struct attribute_group *tty_dev_attr_groups[] = {
-	&tty_dev_attr_group,
-	NULL
-	};
-
+static void make_uport_attr_grps(struct uart_port *uport)
+{
+	uport->attr_grps[0] = &tty_dev_attr_group;
+	if (uport->dev_spec_attr_group)
+		uport->attr_grps[1] = uport->dev_spec_attr_group;
+}
 
 /**
  *	uart_add_one_port - attach a driver-defined port structure
@@ -2607,12 +2608,15 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 
 	uart_configure_port(drv, state, uport);
 
+	make_uport_attr_grps(uport);
+
 	/*
 	 * Register the port whether it's detected or not.  This allows
 	 * setserial to be used to alter this port's parameters.
 	 */
 	tty_dev = tty_port_register_device_attr(port, drv->tty_driver,
-			uport->line, uport->dev, port, tty_dev_attr_groups);
+			uport->line, uport->dev, port,
+			(const struct attribute_group **)uport->attr_grps);
 	if (likely(!IS_ERR(tty_dev))) {
 		device_set_wakeup_capable(tty_dev, 1);
 	} else {
include/linux/serial_8250.h +2 -0
index af47a8a..8d0c215 100644
@@ -74,8 +74,10 @@ struct uart_8250_port {
 	struct list_head	list;		/* ports on this IRQ */
 	unsigned short		capabilities;	/* port capabilities */
 	unsigned short		bugs;		/* port bugs */
+	bool			fifo_bug;	/* min RX trigger if enabled */
 	unsigned int		tx_loadsz;	/* transmit fifo load size */
 	unsigned char		acr;
+	unsigned char		fcr;
 	unsigned char		ier;
 	unsigned char		lcr;
 	unsigned char		mcr;
include/linux/serial_core.h +4 -0
index f729be9..7e3122f 100644
@@ -113,6 +113,8 @@ struct uart_icount {
 
 typedef unsigned int __bitwise__ upf_t;
 
+#define MAX_ATTR_GRPS		3
+
 struct uart_port {
 	spinlock_t		lock;			/* port lock */
 	unsigned long		iobase;			/* in/out[bwl] */
@@ -195,6 +197,8 @@ struct uart_port {
 	unsigned int		line;			/* port index */
 	resource_size_t		mapbase;		/* for ioremap */
 	struct device		*dev;			/* parent device */
+	struct attribute_group	*dev_spec_attr_group;	/* specific attribute */
+	struct attribute_group	*attr_grps[MAX_ATTR_GRPS];/* all attr. groups */
 	unsigned char		hub6;			/* this should be in the 8250 driver */
 	unsigned char		suspended;
 	unsigned char		irq_wake;
#1 lore raw

PATCH 1/1 serial/uart/8250: Add tunable RX interrupt trigger I/F of FIFO buffers

/* I found a bug in V5, so I resend this as V5.1. Please do not review V5. */

Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control or sending communication devices. For the latter uses, normally small data will be exchanged, so user applications want to receive data unit as soon as possible for real-time tendency. If we have a sensor which sends a 1 byte data each time and must control a device based on the sensor feedback, the RX interrupt should be triggered for each data.

According to HW specification of serial UART devices, RX interrupt trigger can be changed, but the trigger is hard-coded. For example, RX interrupt trigger in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets the trigger to only 8bytes.

This patch makes some devices change RX interrupt trigger from userland.

<How to use>
- Read current setting

 # cat /sys/dev/char/4\:64/rx_int_trig
 8

- Write user setting

 # echo 1 > /sys/dev/char/4\:64/rx_int_trig
 # cat /sys/dev/char/4\:64/rx_int_trig
 1

<Support uart devices>
- 16550A and Tegra (1, 4, 8, or 14 bytes)
- 16650V2 (8, 16, 24, or 28 bytes)
- 16654 (8, 16, 56, or 60 bytes)
- 16750 (1, 16, 32, or 56 bytes)

Changed in V2:
- Use _IOW for TIOCSFIFORTRIG definition
- Pass the interrupt trigger value itself

Changes in V3:
- Change I/F from ioctl(2) to sysfs(rx_int_trig)

Changes in V4:
- Introduce fifo_bug flag in uart_8250_port structure
This is enabled only when parity is enabled and UART_BUG_PARITY is enabled for up->bugs. If this flag is enabled, user cannot set RX trigger.
- Return -EOPNOTSUPP when it does not support device at convert_fcr2val() and at convert_val2rxtrig()
- Set the nearest lower RX trigger when users input a meaningless value at convert_val2rxtrig()
- Check whether p->fcr is existing at serial8250_clear_and_reinit_fifos()
- Set fcr = up->fcr in the begging of serial8250_do_set_termios()

Changes in V5:
- Support Tegra, 16650V2, 16654, and 16750
- Store default FCR value to up->fcr when the port is first created
- Add rx_trig_byte[] in uart_config[] for each device and use rx_trig_byte[] in convert_fcr2val() and convert_val2rxtrig()

Changes in V5.1:
- Fix FCR_RX_TRIG_MAX_STATE definition

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Jingoo Han <[email protected]>
Cc Aaron Sierra <[email protected]>
Cc Stephen Warren <[email protected]>
---
 drivers/tty/serial/8250/8250.h      |    6 +
 drivers/tty/serial/8250/8250_core.c |  184 ++++++++++++++++++++++++++++++++---
 drivers/tty/serial/serial_core.c    |   18 ++-
 include/linux/serial_8250.h         |    2 
 include/linux/serial_core.h         |    4 +
 5 files changed, 192 insertions(+), 22 deletions(-)
drivers/tty/serial/8250/8250.h +6 -0
index 1ebf853..0025694 100644
@@ -12,6 +12,7 @@
  */
 
 #include <linux/serial_8250.h>
+#include <linux/serial_reg.h>
 #include <linux/dmaengine.h>
 
 struct uart_8250_dma {
@@ -55,11 +56,16 @@ struct old_serial_port {
 	unsigned long irqflags;
 };
 
+#define FCR_RX_TRIG_OFFSET	6
+#define FCR_RX_TRIG_BITS(x)	(((x) >> FCR_RX_TRIG_OFFSET) & 0x3)
+#define FCR_RX_TRIG_MAX_STATE	4
+
 struct serial8250_config {
 	const char	*name;
 	unsigned short	fifo_size;
 	unsigned short	tx_loadsz;
 	unsigned char	fcr;
+	unsigned char	rx_trig_byte[FCR_RX_TRIG_MAX_STATE];
 	unsigned int	flags;
 };
 
drivers/tty/serial/8250/8250_core.c +169 -15

271 lines not on this page · raw message

drivers/tty/serial/serial_core.c +11 -7
index 2cf5649..41ac44b 100644
@@ -2548,15 +2548,16 @@ static struct attribute *tty_dev_attrs[] = {
 	NULL,
 	};
 
-static const struct attribute_group tty_dev_attr_group = {
+static struct attribute_group tty_dev_attr_group = {
 	.attrs = tty_dev_attrs,
 	};
 
-static const struct attribute_group *tty_dev_attr_groups[] = {
-	&tty_dev_attr_group,
-	NULL
-	};
-
+static void make_uport_attr_grps(struct uart_port *uport)
+{
+	uport->attr_grps[0] = &tty_dev_attr_group;
+	if (uport->dev_spec_attr_group)
+		uport->attr_grps[1] = uport->dev_spec_attr_group;
+}
 
 /**
  *	uart_add_one_port - attach a driver-defined port structure
@@ -2607,12 +2608,15 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 
 	uart_configure_port(drv, state, uport);
 
+	make_uport_attr_grps(uport);
+
 	/*
 	 * Register the port whether it's detected or not.  This allows
 	 * setserial to be used to alter this port's parameters.
 	 */
 	tty_dev = tty_port_register_device_attr(port, drv->tty_driver,
-			uport->line, uport->dev, port, tty_dev_attr_groups);
+			uport->line, uport->dev, port,
+			(const struct attribute_group **)uport->attr_grps);
 	if (likely(!IS_ERR(tty_dev))) {
 		device_set_wakeup_capable(tty_dev, 1);
 	} else {
include/linux/serial_8250.h +2 -0
index af47a8a..8d0c215 100644
@@ -74,8 +74,10 @@ struct uart_8250_port {
 	struct list_head	list;		/* ports on this IRQ */
 	unsigned short		capabilities;	/* port capabilities */
 	unsigned short		bugs;		/* port bugs */
+	bool			fifo_bug;	/* min RX trigger if enabled */
 	unsigned int		tx_loadsz;	/* transmit fifo load size */
 	unsigned char		acr;
+	unsigned char		fcr;
 	unsigned char		ier;
 	unsigned char		lcr;
 	unsigned char		mcr;
include/linux/serial_core.h +4 -0
index f729be9..7e3122f 100644
@@ -113,6 +113,8 @@ struct uart_icount {
 
 typedef unsigned int __bitwise__ upf_t;
 
+#define MAX_ATTR_GRPS		3
+
 struct uart_port {
 	spinlock_t		lock;			/* port lock */
 	unsigned long		iobase;			/* in/out[bwl] */
@@ -195,6 +197,8 @@ struct uart_port {
 	unsigned int		line;			/* port index */
 	resource_size_t		mapbase;		/* for ioremap */
 	struct device		*dev;			/* parent device */
+	struct attribute_group	*dev_spec_attr_group;	/* specific attribute */
+	struct attribute_group	*attr_grps[MAX_ATTR_GRPS];/* all attr. groups */
 	unsigned char		hub6;			/* this should be in the 8250 driver */
 	unsigned char		suspended;
 	unsigned char		irq_wake;
#2 lore raw

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2683

Quoted 10 lines
drivers/tty/serial/8250/8250_core.c +9 -0
+static int convert_val2rxtrig(struct uart_8250_port *up, unsigned char val)
+{
+	const struct serial8250_config *conf_type = &uart_config[up->port.type];
+	int i;
+
+	if (!conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(UART_FCR_R_TRIG_00)]) {
+		pr_info("Not support RX-trigger setting for this serial %s\n",
+			conf_type->name);
+		return -EOPNOTSUPP;

We don't want the pr_info here - otherwise users can flood the logs. The err code is sufficient.

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2689

Quoted 4 lines
drivers/tty/serial/8250/8250_core.c +4 -0
+	for (i = 1; i < FCR_RX_TRIG_MAX_STATE; i++) {
+		if (val < conf_type->rx_trig_byte[i])
+			/* Use the nearest lower value */
+			return (--i) << FCR_RX_TRIG_OFFSET;

Odd case here - your 16654 entry has a minimum of 8 so if I pass 1 then it'll return -1 ? I guess for that case the best we can do is to set 8.

Other trivial thing to tweak - you have "uaser" in spot instead of "user".

With those two fixed it looks good to me.

Alan

#3 lore raw

Hi Alan,

Thank you for your review.

Quoted 13 lines · One Thousand Gnomes

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2683

Quoted 10 lines
drivers/tty/serial/8250/8250_core.c +9 -0
+static int convert_val2rxtrig(struct uart_8250_port *up, unsigned char val)
+{
+	const struct serial8250_config *conf_type = &uart_config[up->port.type];
+	int i;
+
+	if (!conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(UART_FCR_R_TRIG_00)]) {
+		pr_info("Not support RX-trigger setting for this serial %s\n",
+			conf_type->name);
+		return -EOPNOTSUPP;

We don't want the pr_info here - otherwise users can flood the logs. The err code is sufficient.

OK, I'll delete this pr_info().

Quoted 7 lines

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2689

Quoted 4 lines
drivers/tty/serial/8250/8250_core.c +4 -0
+	for (i = 1; i < FCR_RX_TRIG_MAX_STATE; i++) {
+		if (val < conf_type->rx_trig_byte[i])
+			/* Use the nearest lower value */
+			return (--i) << FCR_RX_TRIG_OFFSET;

Odd case here - your 16654 entry has a minimum of 8 so if I pass 1 then it'll return -1 ? I guess for that case the best we can do is to set 8.

No, in that case, this function returns 0.

Note that the "i" starts from 1, so the minimal value is 0. Actually convert_val2rxtrig() returns the index of rx_trig_byte, and when val == 1, it returns 0 and caller gets rx_trig_byte[0] == 8.

Quoted 1 line

Other trivial thing to tweak - you have "uaser" in spot instead of "user".

Oops, I'll fix it.

Thanks,
Yoshihiro YUNOMAE

Quoted 9 lines

With those two fixed it looks good to me.

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
Yoshihiro YUNOMAE
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#4 lore raw
In reply to Yoshihiro YUNOMAE
Quoted 16 lines · Yoshihiro YUNOMAE

/* I found a bug in V5, so I resend this as V5.1. Please do not review V5. */

Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control or sending communication devices. For the latter uses, normally small data will be exchanged, so user applications want to receive data unit as soon as possible for real-time tendency. If we have a sensor which sends a 1 byte data each time and must control a device based on the sensor feedback, the RX interrupt should be triggered for each data.

According to HW specification of serial UART devices, RX interrupt trigger can be changed, but the trigger is hard-coded. For example, RX interrupt trigger in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets the trigger to only 8bytes.

drivers/tty/serial/8250/8250.h struct old_serial_port { · line 59

Quoted 2 lines
drivers/tty/serial/8250/8250.h +1 -0
 
+#define FCR_RX_TRIG_OFFSET	6

Isn't "SHIFT" the usual term rather than "OFFSET". Why not add this define into include/uapi/linux/serial_reg.h, along with all the other UART_FCR_TRIGGER_* defines?

Quoted 1 line

+#define FCR_RX_TRIG_BITS(x) (((x) >> FCR_RX_TRIG_OFFSET) & 0x3)

Perhaps use UART_FCR_TRIGGER_MASK rather than a hard-coded "3" (and then you'd have to mask before shifting).

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +0 -1
@@ -2275,10 +2276,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-		fcr = uart_config[port->type].fcr;

drivers/tty/serial/8250/8250_core.c serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, · line 2284

Quoted 10 lines
drivers/tty/serial/8250/8250_core.c +5 -3
-		if ((baud < 2400 && !up->dma) || fifo_bug) {
-			fcr &= ~UART_FCR_TRIGGER_MASK;
-			fcr |= UART_FCR_TRIGGER_1;
+		/* NOTE: If fifo_bug is not set, a uaser can set RX_trigger. */
+		if ((baud < 2400 && !up->dma &&
+		    (up->fcr == uart_config[port->type].fcr)) || up->fifo_bug) {
+			up->fcr &= ~UART_FCR_TRIGGER_MASK;
+			up->fcr |= UART_FCR_TRIGGER_1;
 		}
 	}

Does the "(up->fcr == uart_config[port->type].fcr)" term prevent the user from changing the trigger level multiple times? Perhaps this is intended?

Quoted 1 line

+static int convert_fcr2val(struct uart_8250_port *up)

"val" is rather generic here, and doesn't describe what the function is doing. What about fcr_get_rxtrig_bytes()?

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2670

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +6 -0
+{
+	const struct serial8250_config *conf_type = &uart_config[up->port.type];
+	unsigned char rx_trig_raw = up->fcr & UART_FCR_TRIGGER_MASK;
+	unsigned char val;
+
+	val = conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(rx_trig_raw)];

Given that FCR_RX_TRIG_BITS() does all the required shifting/masking, why not just:

	val = conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(up->fcr)];
Quoted 1 line

+static int convert_val2rxtrig(struct uart_8250_port *up, unsigned char val)

Perhaps name this bytes_to_fcr_txtrig()?

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2808

Quoted 8 lines
drivers/tty/serial/8250/8250_core.c +8 -0
+static void register_dev_spec_attr_grp(struct uart_8250_port *up)
+{
+	switch (up->port.type) {
+	case PORT_16550A:
+	case PORT_16650V2:
+	case PORT_16654:
+	case PORT_16750:
+	case PORT_TEGRA:

Why not replace that with:

const struct serial8250_config *conf_type = &uart_config[up->port.type]; if (conf_type->rx_trig_byte[0]) {

(or something like that anyway)

That means this switch statement doesn't need to be updated when new UART types are modified to set up the rx_trig_byte field.

#5 lore raw

Hi Stephen,

Thank you for your review.

Quoted 16 lines · Stephen Warren
Quoted 14 lines · Yoshihiro YUNOMAE

/* I found a bug in V5, so I resend this as V5.1. Please do not review V5. */

Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control or sending communication devices. For the latter uses, normally small data will be exchanged, so user applications want to receive data unit as soon as possible for real-time tendency. If we have a sensor which sends a 1 byte data each time and must control a device based on the sensor feedback, the RX interrupt should be triggered for each data.

According to HW specification of serial UART devices, RX interrupt trigger can be changed, but the trigger is hard-coded. For example, RX interrupt trigger in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets the trigger to only 8bytes.

Quoted 5 lines

drivers/tty/serial/8250/8250.h struct old_serial_port { · line 59

Quoted 3 lines
drivers/tty/serial/8250/8250.h +1 -0
 
+#define FCR_RX_TRIG_OFFSET	6

Isn't "SHIFT" the usual term rather than "OFFSET". Why not add this

OK, I'll rename this.

Quoted 2 lines

define into include/uapi/linux/serial_reg.h, along with all the other UART_FCR_TRIGGER_* defines?

I thought these definition will not be used in userland. I'll move these in serial_reg.h.

Quoted 4 lines
Quoted 1 line

+#define FCR_RX_TRIG_BITS(x) (((x) >> FCR_RX_TRIG_OFFSET) & 0x3)

Perhaps use UART_FCR_TRIGGER_MASK rather than a hard-coded "3" (and then you'd have to mask before shifting).

OK, I'll define FCR_RX_TRIG_BITS as follows:

#define UART_FCR_R_TRIG_SHIFT 6

#define UART_FCR_R_TRIG_BITS(x) \
    (((x) & UART_FCR_TRIGGER_MASK) >> UART_FCR_R_TRIG_SHIFT)
Quoted 4 lines
Quoted 3 lines
drivers/tty/serial/8250/8250_core.c +0 -0
@@ -2275,10 +2276,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
Quoted 16 lines

drivers/tty/serial/8250/8250_core.c serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, · line 2334

Quoted 12 lines
drivers/tty/serial/8250/8250_core.c +5 -4
  	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-		fcr = uart_config[port->type].fcr;
-		if ((baud < 2400 && !up->dma) || fifo_bug) {
-			fcr &= ~UART_FCR_TRIGGER_MASK;
-			fcr |= UART_FCR_TRIGGER_1;
+		/* NOTE: If fifo_bug is not set, a uaser can set RX_trigger. */
+		if ((baud < 2400 && !up->dma &&
+		    (up->fcr == uart_config[port->type].fcr)) || up->fifo_bug) {
+			up->fcr &= ~UART_FCR_TRIGGER_MASK;
+			up->fcr |= UART_FCR_TRIGGER_1;
  		}
  	}

Does the "(up->fcr == uart_config[port->type].fcr)" term prevent the user from changing the trigger level multiple times? Perhaps this is intended?

No, this means that if a user changed FCR value before setting termios, use the changed value because the user think changed value is always set. But, I thought this is not straightforward and it cannot help when the user want to use default FCR value.
Could I add FCR changed flag(user_changed_fcr) in uart_8250_port structure and check the flag here?
Or shouldn't the driver check the user changing?

Quoted 4 lines

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2664

Quoted 1 line
drivers/tty/serial/8250/8250_core.c +1 -0
+static int convert_fcr2val(struct uart_8250_port *up)

"val" is rather generic here, and doesn't describe what the function is doing. What about fcr_get_rxtrig_bytes()?

Sure.

Quoted 11 lines

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2670

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +6 -0
+{
+	const struct serial8250_config *conf_type = &uart_config[up->port.type];
+	unsigned char rx_trig_raw = up->fcr & UART_FCR_TRIGGER_MASK;
+	unsigned char val;
+
+	val = conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(rx_trig_raw)];

Given that FCR_RX_TRIG_BITS() does all the required shifting/masking, why not just:

	val = conf_type->rx_trig_byte[FCR_RX_TRIG_BITS(up->fcr)];

That's true. I'll fix it.

Quoted 3 lines
Quoted 1 line

+static int convert_val2rxtrig(struct uart_8250_port *up, unsigned char val)

Perhaps name this bytes_to_fcr_txtrig()?

OK, I'll rename it to bytes_to_fcr_rxtrig().

Quoted 11 lines

drivers/tty/serial/8250/8250_core.c static int serial8250_request_port(struct uart_port *port) · line 2808

Quoted 8 lines
drivers/tty/serial/8250/8250_core.c +8 -0
+static void register_dev_spec_attr_grp(struct uart_8250_port *up)
+{
+	switch (up->port.type) {
+	case PORT_16550A:
+	case PORT_16650V2:
+	case PORT_16654:
+	case PORT_16750:
+	case PORT_TEGRA:

Why not replace that with:

Quoted 7 lines

const struct serial8250_config *conf_type = &uart_config[up->port.type]; if (conf_type->rx_trig_byte[0]) {

(or something like that anyway)

That means this switch statement doesn't need to be updated when new UART types are modified to set up the rx_trig_byte field.

Nice idea! I'll use your idea.

Thanks,
Yoshihiro YUNOMAE

Signature · 4 lines
Yoshihiro YUNOMAE
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#6 lore raw
Quoted 53 lines · Yoshihiro YUNOMAE

Hi Stephen,

Thank you for your review.

Quoted 44 lines · Stephen Warren
Quoted 32 lines · Yoshihiro YUNOMAE

/* I found a bug in V5, so I resend this as V5.1. Please do not review V5. */

Add tunable RX interrupt trigger I/F of FIFO buffers.
Serial devices are used as not only message communication devices but control
or sending communication devices. For the latter uses, normally small data
will be exchanged, so user applications want to receive data unit as soon as
possible for real-time tendency. If we have a sensor which sends a 1 byte data
each time and must control a device based on the sensor feedback, the RX interrupt should be triggered for each data.

According to HW specification of serial UART devices, RX interrupt trigger
can be changed, but the trigger is hard-coded. For example, RX interrupt trigger
in 16550A can be set to 1, 4, 8, or 14 bytes for HW, but current driver sets
the trigger to only 8bytes.

drivers/tty/serial/8250/8250_core.c +0 -2
@@ -2275,10 +2276,9 @@ serial8250_do_set_termios(struct uart_port
 *port, struct ktermios *termios,
 
      if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-        fcr = uart_config[port->type].fcr;
-        if ((baud < 2400 && !up->dma) || fifo_bug) {

drivers/tty/serial/8250/8250_core.c serial8250_do_set_termios(struct uart_port · line 2334

Quoted 10 lines
drivers/tty/serial/8250/8250_core.c +5 -2
-            fcr &= ~UART_FCR_TRIGGER_MASK;
-            fcr |= UART_FCR_TRIGGER_1;
+        /* NOTE: If fifo_bug is not set, a uaser can set RX_trigger. */
+        if ((baud < 2400 && !up->dma &&
+            (up->fcr == uart_config[port->type].fcr)) ||
 up->fifo_bug) {
+            up->fcr &= ~UART_FCR_TRIGGER_MASK;
+            up->fcr |= UART_FCR_TRIGGER_1;
          }
      }
Quoted 3 lines

Does the "(up->fcr == uart_config[port->type].fcr)" term prevent the user from changing the trigger level multiple times? Perhaps this is intended?

Quoted 7 lines

No, this means that if a user changed FCR value before setting termios, use the changed value because the user think changed value is always set. But, I thought this is not straightforward and it cannot help when the user want to use default FCR value.
Could I add FCR changed flag(user_changed_fcr) in uart_8250_port structure and check the flag here?
Or shouldn't the driver check the user changing?

Oh, I wasn't aware that the user could change FCR directly. To be honest, I'm not sure of the best way to resolve that kind of conflict...

#7 lore raw

Hi Stephen,

Thank you for your reply.

Quoted 33 lines · Stephen Warren
Quoted 24 lines · Yoshihiro YUNOMAE
Quoted 20 lines
Quoted 9 lines
drivers/tty/serial/8250/8250_core.c +0 -2
@@ -2275,10 +2276,9 @@ serial8250_do_set_termios(struct uart_port
 *port, struct ktermios *termios,
 
       if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-        fcr = uart_config[port->type].fcr;
-        if ((baud < 2400 && !up->dma) || fifo_bug) {

drivers/tty/serial/8250/8250_core.c serial8250_do_set_termios(struct uart_port · line 2334

Quoted 10 lines
drivers/tty/serial/8250/8250_core.c +5 -2
-            fcr &= ~UART_FCR_TRIGGER_MASK;
-            fcr |= UART_FCR_TRIGGER_1;
+        /* NOTE: If fifo_bug is not set, a uaser can set RX_trigger. */
+        if ((baud < 2400 && !up->dma &&
+            (up->fcr == uart_config[port->type].fcr)) ||
 up->fifo_bug) {
+            up->fcr &= ~UART_FCR_TRIGGER_MASK;
+            up->fcr |= UART_FCR_TRIGGER_1;
           }
       }
Quoted 3 lines

Does the "(up->fcr == uart_config[port->type].fcr)" term prevent the user from changing the trigger level multiple times? Perhaps this is intended?

Quoted 7 lines

No, this means that if a user changed FCR value before setting termios, use the changed value because the user think changed value is always set. But, I thought this is not straightforward and it cannot help when the user want to use default FCR value.
Could I add FCR changed flag(user_changed_fcr) in uart_8250_port structure and check the flag here?
Or shouldn't the driver check the user changing?

Quoted 2 lines

Oh, I wasn't aware that the user could change FCR directly. To be honest, I'm not sure of the best way to resolve that kind of conflict...

OK. For simplicity, I don't implement the checking.
Even if FCR is changed here, users can change it any time, so this is not so big problem, I think.

Thanks,
Yoshihiro YUNOMAE

Signature · 4 lines
Yoshihiro YUNOMAE
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]