linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/33] tty: summer cleanup
@ 2025-06-11 10:02 Jiri Slaby (SUSE)
  2025-06-11 10:02 ` [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Jiri Slaby (SUSE)
                   ` (32 more replies)
  0 siblings, 33 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Hi,

this is (yet) another series of various cleanup in tty of issues which
popped up at me during a larger rework.

Jiri Slaby (SUSE) (33):
  tty: introduce and use tty_port_tty_vhangup() helper
  powerpc/legacy_serial: cache serial port and info in add_legacy_port()
  powerpc/legacy_serial: use %pa for phys_addr_t prints
  m68k: remove unneeded tty includes
  powerpc/powermac: remove unneeded tty includes
  tty: vt: use sane types for userspace API
  tty: vt: use _IO() to define ioctl numbers
  serial: 8250: sanitize uart_port::serial_{in,out}() types
  serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code
  serial: 8250: invert conditions in RSA functions
  serial: 8250: put RSA functions to their namespace
  serial: 8250: move RSA functions to 8250_rsa.c
  serial: 8250: extract serial8250_startup_special()
  serial: 8250: extract serial8250_set_TRG_levels()
  serial: 8250: extract serial8250_THRE_test()
  serial: 8250: extract serial8250_initialize()
  serial: 8250: extract serial8250_clear_interrupts()
  serial: 8250: extract serial8250_set_mini()
  serial: 8250: extract serial8250_set_trigger_for_slow_speed()
  serial: 8250: extract serial8250_set_afe()
  serial: 8250: extract serial8250_set_errors_and_ignores
  serial: 8250: extract serial8250_set_ier()
  serial: 8250: extract serial8250_set_efr()
  serial: 8250: extract serial8250_set_fcr()
  serial: 8250: lcr compute cleanup
  serial: 8250: drop unused frac from serial8250_do_get_divisor()
  serial: 8250: extract serial_get_or_create_irq_info()
  serial: 8250: remove debug prints from ISR
  serial: 8250: drop DEBUG_AUTOCONF() macro
  serial: 8250: invert serial8250_register_8250_port() CIR condition
  serial: 8250: invert condition to avoid a goto label
  serial: 8250: use hashtable
  serial: 8250_omap: use uart_port pointer when available

 arch/m68k/amiga/config.c                |   2 -
 arch/m68k/apollo/config.c               |   2 -
 arch/m68k/atari/config.c                |   1 -
 arch/m68k/mac/config.c                  |   2 -
 arch/m68k/q40/config.c                  |   2 -
 arch/powerpc/kernel/legacy_serial.c     |  62 +-
 arch/powerpc/platforms/powermac/setup.c |   2 -
 drivers/isdn/capi/capi.c                |   8 +-
 drivers/staging/greybus/uart.c          |   7 +-
 drivers/tty/serial/8250/8250.h          |   8 +
 drivers/tty/serial/8250/8250_core.c     | 316 +++++-----
 drivers/tty/serial/8250/8250_dw.c       |  34 +-
 drivers/tty/serial/8250/8250_em.c       |   4 +-
 drivers/tty/serial/8250/8250_ingenic.c  |   8 +-
 drivers/tty/serial/8250/8250_ioc3.c     |   4 +-
 drivers/tty/serial/8250/8250_lpc18xx.c  |   2 +-
 drivers/tty/serial/8250/8250_omap.c     |  53 +-
 drivers/tty/serial/8250/8250_pci.c      |   6 +-
 drivers/tty/serial/8250/8250_port.c     | 736 +++++++++++-------------
 drivers/tty/serial/8250/8250_rsa.c      |  92 +++
 drivers/tty/serial/8250/8250_rt288x.c   |   4 +-
 drivers/tty/serial/8250/8250_uniphier.c |   4 +-
 drivers/tty/serial/serial_core.c        |   7 +-
 drivers/tty/tty_port.c                  |  12 +-
 drivers/usb/class/cdc-acm.c             |   7 +-
 drivers/usb/serial/usb-serial.c         |   7 +-
 include/linux/serial_8250.h             |   4 +-
 include/linux/serial_core.h             |   4 +-
 include/linux/tty_port.h                |  12 +-
 include/uapi/linux/vt.h                 |  78 +--
 net/bluetooth/rfcomm/tty.c              |   7 +-
 31 files changed, 751 insertions(+), 746 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:13   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port() Jiri Slaby (SUSE)
                   ` (31 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Karsten Keil,
	David Lin, Johan Hovold, Alex Elder, Oliver Neukum,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz, netdev,
	greybus-dev, linux-staging, linux-usb, linux-bluetooth

This code (tty_get -> vhangup -> tty_put) is repeated on few places.
Introduce a helper similar to tty_port_tty_hangup() (asynchronous) to
handle even vhangup (synchronous).

And use it on those places.

In fact, reuse the tty_port_tty_hangup()'s code and call tty_vhangup()
depending on a new bool parameter.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
---
Cc: netdev@vger.kernel.org
Cc: greybus-dev@lists.linaro.org
Cc: linux-staging@lists.linux.dev
Cc: linux-usb@vger.kernel.org
Cc: linux-bluetooth@vger.kernel.org
---
 drivers/isdn/capi/capi.c         |  8 +-------
 drivers/staging/greybus/uart.c   |  7 +------
 drivers/tty/serial/serial_core.c |  7 +------
 drivers/tty/tty_port.c           | 12 ++++++++----
 drivers/usb/class/cdc-acm.c      |  7 +------
 drivers/usb/serial/usb-serial.c  |  7 +------
 include/linux/tty_port.h         | 12 +++++++++++-
 net/bluetooth/rfcomm/tty.c       |  7 +------
 8 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 70dee9ad4bae..78e6e7748fb9 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -306,15 +306,9 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)
 static void capincci_free_minor(struct capincci *np)
 {
 	struct capiminor *mp = np->minorp;
-	struct tty_struct *tty;
 
 	if (mp) {
-		tty = tty_port_tty_get(&mp->port);
-		if (tty) {
-			tty_vhangup(tty);
-			tty_kref_put(tty);
-		}
-
+		tty_port_tty_vhangup(&mp->port);
 		capiminor_free(mp);
 	}
 }
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 308ed1ca9947..10df5c37c83e 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -916,7 +916,6 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
 {
 	struct gb_tty *gb_tty = gb_gbphy_get_data(gbphy_dev);
 	struct gb_connection *connection = gb_tty->connection;
-	struct tty_struct *tty;
 	int ret;
 
 	ret = gbphy_runtime_get_sync(gbphy_dev);
@@ -929,11 +928,7 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
 	wake_up_all(&gb_tty->wioctl);
 	mutex_unlock(&gb_tty->mutex);
 
-	tty = tty_port_tty_get(&gb_tty->port);
-	if (tty) {
-		tty_vhangup(tty);
-		tty_kref_put(tty);
-	}
+	tty_port_tty_vhangup(&gb_tty->port);
 
 	gb_connection_disable_rx(connection);
 	tty_unregister_device(gb_tty_driver, gb_tty->minor);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 1f7708a91fc6..d6485714eb0f 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3209,7 +3209,6 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
 	struct uart_state *state = drv->state + uport->line;
 	struct tty_port *port = &state->port;
 	struct uart_port *uart_port;
-	struct tty_struct *tty;
 
 	mutex_lock(&port->mutex);
 	uart_port = uart_port_check(state);
@@ -3228,11 +3227,7 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
 	 */
 	tty_port_unregister_device(port, drv->tty_driver, uport->line);
 
-	tty = tty_port_tty_get(port);
-	if (tty) {
-		tty_vhangup(port->tty);
-		tty_kref_put(tty);
-	}
+	tty_port_tty_vhangup(port);
 
 	/*
 	 * If the port is used as a console, unregister it
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 4af1fbf73f51..903eebdbe12d 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -396,15 +396,19 @@ EXPORT_SYMBOL(tty_port_hangup);
  * @port: tty port
  * @check_clocal: hang only ttys with %CLOCAL unset?
  */
-void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
+void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async)
 {
 	struct tty_struct *tty = tty_port_tty_get(port);
 
-	if (tty && (!check_clocal || !C_CLOCAL(tty)))
-		tty_hangup(tty);
+	if (tty && (!check_clocal || !C_CLOCAL(tty))) {
+		if (async)
+			tty_hangup(tty);
+		else
+			tty_vhangup(tty);
+	}
 	tty_kref_put(tty);
 }
-EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
+EXPORT_SYMBOL_GPL(__tty_port_tty_hangup);
 
 /**
  * tty_port_tty_wakeup - helper to wake up a tty
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index c2ecfa3c8349..f9171fbedf5c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1571,7 +1571,6 @@ static int acm_probe(struct usb_interface *intf,
 static void acm_disconnect(struct usb_interface *intf)
 {
 	struct acm *acm = usb_get_intfdata(intf);
-	struct tty_struct *tty;
 	int i;
 
 	/* sibling interface is already cleaning up */
@@ -1598,11 +1597,7 @@ static void acm_disconnect(struct usb_interface *intf)
 	usb_set_intfdata(acm->data, NULL);
 	mutex_unlock(&acm->mutex);
 
-	tty = tty_port_tty_get(&acm->port);
-	if (tty) {
-		tty_vhangup(tty);
-		tty_kref_put(tty);
-	}
+	tty_port_tty_vhangup(&acm->port);
 
 	cancel_delayed_work_sync(&acm->dwork);
 
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7266558d823a..c78ff40b1e5f 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1176,7 +1176,6 @@ static void usb_serial_disconnect(struct usb_interface *interface)
 	struct usb_serial *serial = usb_get_intfdata(interface);
 	struct device *dev = &interface->dev;
 	struct usb_serial_port *port;
-	struct tty_struct *tty;
 
 	/* sibling interface is cleaning up */
 	if (!serial)
@@ -1191,11 +1190,7 @@ static void usb_serial_disconnect(struct usb_interface *interface)
 
 	for (i = 0; i < serial->num_ports; ++i) {
 		port = serial->port[i];
-		tty = tty_port_tty_get(&port->port);
-		if (tty) {
-			tty_vhangup(tty);
-			tty_kref_put(tty);
-		}
+		tty_port_tty_vhangup(&port->port);
 		usb_serial_port_poison_urbs(port);
 		wake_up_interruptible(&port->port.delta_msr_wait);
 		cancel_work_sync(&port->work);
diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
index 08f89a598366..021f9a8415c0 100644
--- a/include/linux/tty_port.h
+++ b/include/linux/tty_port.h
@@ -232,7 +232,7 @@ bool tty_port_carrier_raised(struct tty_port *port);
 void tty_port_raise_dtr_rts(struct tty_port *port);
 void tty_port_lower_dtr_rts(struct tty_port *port);
 void tty_port_hangup(struct tty_port *port);
-void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
+void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async);
 void tty_port_tty_wakeup(struct tty_port *port);
 int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty,
 		struct file *filp);
@@ -251,4 +251,14 @@ static inline int tty_port_users(struct tty_port *port)
 	return port->count + port->blocked_open;
 }
 
+static inline void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
+{
+	__tty_port_tty_hangup(port, check_clocal, true);
+}
+
+static inline void tty_port_tty_vhangup(struct tty_port *port)
+{
+	__tty_port_tty_hangup(port, false, false);
+}
+
 #endif
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 21a5b5535ebc..827dfbe66085 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -438,7 +438,6 @@ static int __rfcomm_release_dev(void __user *arg)
 {
 	struct rfcomm_dev_req req;
 	struct rfcomm_dev *dev;
-	struct tty_struct *tty;
 
 	if (copy_from_user(&req, arg, sizeof(req)))
 		return -EFAULT;
@@ -464,11 +463,7 @@ static int __rfcomm_release_dev(void __user *arg)
 		rfcomm_dlc_close(dev->dlc, 0);
 
 	/* Shut down TTY synchronously before freeing rfcomm_dev */
-	tty = tty_port_tty_get(&dev->port);
-	if (tty) {
-		tty_vhangup(tty);
-		tty_kref_put(tty);
-	}
+	tty_port_tty_vhangup(&dev->port);
 
 	if (!test_bit(RFCOMM_TTY_OWNED, &dev->status))
 		tty_port_put(&dev->port);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
  2025-06-11 10:02 ` [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:15   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 03/33] powerpc/legacy_serial: use %pa for phys_addr_t prints Jiri Slaby (SUSE)
                   ` (30 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE),
	Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, linuxppc-dev

Caching the port and info in local variables makes the code more compact
and easier to understand.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/kernel/legacy_serial.c | 52 ++++++++++++++---------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index 1da2f6e7d2a1..d9080189c28c 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -77,6 +77,8 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
 				  phys_addr_t taddr, unsigned long irq,
 				  upf_t flags, int irq_check_parent)
 {
+	struct plat_serial8250_port *legacy_port;
+	struct legacy_serial_info *legacy_info;
 	const __be32 *clk, *spd, *rs;
 	u32 clock = BASE_BAUD * 16;
 	u32 shift = 0;
@@ -110,16 +112,17 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
 	if (index >= legacy_serial_count)
 		legacy_serial_count = index + 1;
 
+	legacy_port = &legacy_serial_ports[index];
+	legacy_info = &legacy_serial_infos[index];
+
 	/* Check if there is a port who already claimed our slot */
-	if (legacy_serial_infos[index].np != NULL) {
+	if (legacy_info->np != NULL) {
 		/* if we still have some room, move it, else override */
 		if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) {
 			printk(KERN_DEBUG "Moved legacy port %d -> %d\n",
 			       index, legacy_serial_count);
-			legacy_serial_ports[legacy_serial_count] =
-				legacy_serial_ports[index];
-			legacy_serial_infos[legacy_serial_count] =
-				legacy_serial_infos[index];
+			legacy_serial_ports[legacy_serial_count] = *legacy_port;
+			legacy_serial_infos[legacy_serial_count] = *legacy_info;
 			legacy_serial_count++;
 		} else {
 			printk(KERN_DEBUG "Replacing legacy port %d\n", index);
@@ -127,36 +130,33 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
 	}
 
 	/* Now fill the entry */
-	memset(&legacy_serial_ports[index], 0,
-	       sizeof(struct plat_serial8250_port));
+	memset(legacy_port, 0, sizeof(*legacy_port));
 	if (iotype == UPIO_PORT)
-		legacy_serial_ports[index].iobase = base;
+		legacy_port->iobase = base;
 	else
-		legacy_serial_ports[index].mapbase = base;
-
-	legacy_serial_ports[index].iotype = iotype;
-	legacy_serial_ports[index].uartclk = clock;
-	legacy_serial_ports[index].irq = irq;
-	legacy_serial_ports[index].flags = flags;
-	legacy_serial_ports[index].regshift = shift;
-	legacy_serial_infos[index].taddr = taddr;
-	legacy_serial_infos[index].np = of_node_get(np);
-	legacy_serial_infos[index].clock = clock;
-	legacy_serial_infos[index].speed = spd ? be32_to_cpup(spd) : 0;
-	legacy_serial_infos[index].irq_check_parent = irq_check_parent;
+		legacy_port->mapbase = base;
+
+	legacy_port->iotype = iotype;
+	legacy_port->uartclk = clock;
+	legacy_port->irq = irq;
+	legacy_port->flags = flags;
+	legacy_port->regshift = shift;
+	legacy_info->taddr = taddr;
+	legacy_info->np = of_node_get(np);
+	legacy_info->clock = clock;
+	legacy_info->speed = spd ? be32_to_cpup(spd) : 0;
+	legacy_info->irq_check_parent = irq_check_parent;
 
 	if (iotype == UPIO_TSI) {
-		legacy_serial_ports[index].serial_in = tsi_serial_in;
-		legacy_serial_ports[index].serial_out = tsi_serial_out;
+		legacy_port->serial_in = tsi_serial_in;
+		legacy_port->serial_out = tsi_serial_out;
 	}
 
-	printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n",
-	       index, np);
+	printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n", index, np);
 	printk(KERN_DEBUG "  %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
 	       (iotype == UPIO_PORT) ? "port" : "mem",
 	       (unsigned long long)base, (unsigned long long)taddr, irq,
-	       legacy_serial_ports[index].uartclk,
-	       legacy_serial_infos[index].speed);
+	       legacy_port->uartclk, legacy_info->speed);
 
 	return index;
 }
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 03/33] powerpc/legacy_serial: use %pa for phys_addr_t prints
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
  2025-06-11 10:02 ` [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Jiri Slaby (SUSE)
  2025-06-11 10:02 ` [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port() Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 10:02 ` [PATCH 04/33] m68k: remove unneeded tty includes Jiri Slaby (SUSE)
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE),
	Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy

It makes the code easier to read as casts are not needed.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/kernel/legacy_serial.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index d9080189c28c..a874eb8e000b 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -153,10 +153,9 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
 	}
 
 	printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n", index, np);
-	printk(KERN_DEBUG "  %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
+	printk(KERN_DEBUG "  %s=%pa, taddr=%pa, irq=%lx, clk=%d, speed=%d\n",
 	       (iotype == UPIO_PORT) ? "port" : "mem",
-	       (unsigned long long)base, (unsigned long long)taddr, irq,
-	       legacy_port->uartclk, legacy_info->speed);
+	       &base, &taddr, irq, legacy_port->uartclk, legacy_info->speed);
 
 	return index;
 }
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 04/33] m68k: remove unneeded tty includes
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (2 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 03/33] powerpc/legacy_serial: use %pa for phys_addr_t prints Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:22   ` Ilpo Järvinen
  2025-06-17 12:29   ` Geert Uytterhoeven
  2025-06-11 10:02 ` [PATCH 05/33] powerpc/powermac: " Jiri Slaby (SUSE)
                   ` (28 subsequent siblings)
  32 siblings, 2 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Geert Uytterhoeven,
	Joshua Thompson, linux-m68k

All these includes must have been cut & pasted. The code does not use
any tty or vt functionality at all.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Joshua Thompson <funaho@jurai.org>
Cc: linux-m68k@lists.linux-m68k.org
---
 arch/m68k/amiga/config.c  | 2 --
 arch/m68k/apollo/config.c | 2 --
 arch/m68k/atari/config.c  | 1 -
 arch/m68k/mac/config.c    | 2 --
 arch/m68k/q40/config.c    | 2 --
 5 files changed, 9 deletions(-)

diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 0147130dc34e..242d18e750b0 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -16,12 +16,10 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/seq_file.h>
-#include <linux/tty.h>
 #include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
-#include <linux/vt_kern.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/zorro.h>
diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index e161ecd76035..e324c5f671de 100644
--- a/arch/m68k/apollo/config.c
+++ b/arch/m68k/apollo/config.c
@@ -3,9 +3,7 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/rtc.h>
-#include <linux/vt_kern.h>
 #include <linux/interrupt.h>
 
 #include <asm/setup.h>
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index b48a0606a000..ee2d061efb2a 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -33,7 +33,6 @@
 #include <linux/ioport.h>
 #include <linux/platform_device.h>
 #include <linux/usb/isp116x.h>
-#include <linux/vt_kern.h>
 #include <linux/module.h>
 
 #include <asm/bootinfo.h>
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index d26c7f4f8c36..c0033f885ed4 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -15,7 +15,6 @@
 #include <linux/reboot.h>
 #include <linux/types.h>
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/console.h>
 #include <linux/interrupt.h>
 /* keyb */
@@ -23,7 +22,6 @@
 #include <linux/delay.h>
 /* keyb */
 #include <linux/init.h>
-#include <linux/vt_kern.h>
 #include <linux/platform_device.h>
 #include <linux/ata_platform.h>
 #include <linux/adb.h>
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index de7870ad2a30..5a4258697622 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -13,14 +13,12 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/console.h>
 #include <linux/linkage.h>
 #include <linux/init.h>
 #include <linux/major.h>
 #include <linux/serial_reg.h>
 #include <linux/rtc.h>
-#include <linux/vt_kern.h>
 #include <linux/bcd.h>
 #include <linux/platform_device.h>
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 05/33] powerpc/powermac: remove unneeded tty includes
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (3 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 04/33] m68k: remove unneeded tty includes Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:25   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 06/33] tty: vt: use sane types for userspace API Jiri Slaby (SUSE)
                   ` (27 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE),
	Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, linuxppc-dev

All these includes must have been cut & pasted. The code does not use
any tty or vt functionality at all.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/platforms/powermac/setup.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index e119ced05d10..eb092f293113 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -28,13 +28,11 @@
 #include <linux/ptrace.h>
 #include <linux/export.h>
 #include <linux/user.h>
-#include <linux/tty.h>
 #include <linux/string.h>
 #include <linux/delay.h>
 #include <linux/ioport.h>
 #include <linux/major.h>
 #include <linux/initrd.h>
-#include <linux/vt_kern.h>
 #include <linux/console.h>
 #include <linux/pci.h>
 #include <linux/adb.h>
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 06/33] tty: vt: use sane types for userspace API
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (4 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 05/33] powerpc/powermac: " Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 14:38   ` Nicolas Pitre
  2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
                   ` (26 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Nicolas Pitre

As discussed earlier (see the Link below), use the preferred ioctl types
in vt.h (__u8, __u16, ...).

These types are already used for the new VT_GETCONSIZECSRPOS.
Therefore, the necessary includes are already present. Since now, the
types are used for every structure defined in the header now.

Note the kernel is built with -funsigned-char, therefore 'char' becomes
'__u8' in here.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Nicolas Pitre <nico@fluxnic.net>
Link: https://lore.kernel.org/all/p7p83sq1-4ro2-o924-s9o2-30spr74n076o@syhkavp.arg/
---
 include/uapi/linux/vt.h | 44 ++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
index e5b0c492aa18..714483d68c69 100644
--- a/include/uapi/linux/vt.h
+++ b/include/uapi/linux/vt.h
@@ -19,11 +19,11 @@
 #define VT_OPENQRY	0x5600	/* find available vt */
 
 struct vt_mode {
-	char mode;		/* vt mode */
-	char waitv;		/* if set, hang on writes if not active */
-	short relsig;		/* signal to raise on release req */
-	short acqsig;		/* signal to raise on acquisition */
-	short frsig;		/* unused (set to 0) */
+	__u8 mode;		/* vt mode */
+	__u8 waitv;		/* if set, hang on writes if not active */
+	__s16 relsig;		/* signal to raise on release req */
+	__s16 acqsig;		/* signal to raise on acquisition */
+	__s16 frsig;		/* unused (set to 0) */
 };
 #define VT_GETMODE	0x5601	/* get mode of active vt */
 #define VT_SETMODE	0x5602	/* set mode of active vt */
@@ -32,9 +32,9 @@ struct vt_mode {
 #define		VT_ACKACQ	0x02	/* acknowledge switch */
 
 struct vt_stat {
-	unsigned short v_active;	/* active vt */
-	unsigned short v_signal;	/* signal to send */
-	unsigned short v_state;		/* vt bitmask */
+	__u16 v_active;	/* active vt */
+	__u16 v_signal;	/* signal to send */
+	__u16 v_state;		/* vt bitmask */
 };
 #define VT_GETSTATE	0x5603	/* get global vt state info */
 #define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
@@ -46,19 +46,19 @@ struct vt_stat {
 #define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
 
 struct vt_sizes {
-	unsigned short v_rows;		/* number of rows */
-	unsigned short v_cols;		/* number of columns */
-	unsigned short v_scrollsize;	/* number of lines of scrollback */
+	__u16 v_rows;		/* number of rows */
+	__u16 v_cols;		/* number of columns */
+	__u16 v_scrollsize;	/* number of lines of scrollback */
 };
 #define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
 
 struct vt_consize {
-	unsigned short v_rows;	/* number of rows */
-	unsigned short v_cols;	/* number of columns */
-	unsigned short v_vlin;	/* number of pixel rows on screen */
-	unsigned short v_clin;	/* number of pixel rows per character */
-	unsigned short v_vcol;	/* number of pixel columns on screen */
-	unsigned short v_ccol;	/* number of pixel columns per character */
+	__u16 v_rows;	/* number of rows */
+	__u16 v_cols;	/* number of columns */
+	__u16 v_vlin;	/* number of pixel rows on screen */
+	__u16 v_clin;	/* number of pixel rows per character */
+	__u16 v_vcol;	/* number of pixel columns on screen */
+	__u16 v_ccol;	/* number of pixel columns per character */
 };
 #define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
 #define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
@@ -66,21 +66,21 @@ struct vt_consize {
 #define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
 
 struct vt_event {
-	unsigned int event;
+	__u32 event;
 #define VT_EVENT_SWITCH		0x0001	/* Console switch */
 #define VT_EVENT_BLANK		0x0002	/* Screen blank */
 #define VT_EVENT_UNBLANK	0x0004	/* Screen unblank */
 #define VT_EVENT_RESIZE		0x0008	/* Resize display */
 #define VT_MAX_EVENT		0x000F
-	unsigned int oldev;		/* Old console */
-	unsigned int newev;		/* New console (if changing) */
-	unsigned int pad[4];		/* Padding for expansion */
+	__u32 oldev;		/* Old console */
+	__u32 newev;		/* New console (if changing) */
+	__u32 pad[4];		/* Padding for expansion */
 };
 
 #define VT_WAITEVENT	0x560E	/* Wait for an event */
 
 struct vt_setactivate {
-	unsigned int console;
+	__u32 console;
 	struct vt_mode mode;
 };
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (5 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 06/33] tty: vt: use sane types for userspace API Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:30   ` Ilpo Järvinen
                     ` (2 more replies)
  2025-06-11 10:02 ` [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types Jiri Slaby (SUSE)
                   ` (25 subsequent siblings)
  32 siblings, 3 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Nicolas Pitre

_IO*() is the proper way of defining ioctl numbers. All these vt numbers
were synthetically built up the same way the _IO() macro does.

So instead of implicit hex numbers, use _IO() properly.

To not change the pre-existing numbers, use only _IO() (and not _IOR()
or _IOW()). The latter would change the numbers indeed.

Objdump of vt_ioctl.o reveals no difference with this patch.

Again, VT_GETCONSIZECSRPOS already uses _IOR(), so everything is paved
for this patch.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Nicolas Pitre <nico@fluxnic.net>
---
 include/uapi/linux/vt.h | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
index 714483d68c69..b60fcdfb2746 100644
--- a/include/uapi/linux/vt.h
+++ b/include/uapi/linux/vt.h
@@ -14,9 +14,9 @@
 		/* Note: the ioctl VT_GETSTATE does not work for
 		   consoles 16 and higher (since it returns a short) */
 
-/* 0x56 is 'V', to avoid collision with termios and kd */
+/* 'V' to avoid collision with termios and kd */
 
-#define VT_OPENQRY	0x5600	/* find available vt */
+#define VT_OPENQRY		_IO('V', 0x00)	/* find available vt */
 
 struct vt_mode {
 	__u8 mode;		/* vt mode */
@@ -25,8 +25,8 @@ struct vt_mode {
 	__s16 acqsig;		/* signal to raise on acquisition */
 	__s16 frsig;		/* unused (set to 0) */
 };
-#define VT_GETMODE	0x5601	/* get mode of active vt */
-#define VT_SETMODE	0x5602	/* set mode of active vt */
+#define VT_GETMODE		_IO('V', 0x01)	/* get mode of active vt */
+#define VT_SETMODE		_IO('V', 0x02)	/* set mode of active vt */
 #define		VT_AUTO		0x00	/* auto vt switching */
 #define		VT_PROCESS	0x01	/* process controls switching */
 #define		VT_ACKACQ	0x02	/* acknowledge switch */
@@ -36,21 +36,21 @@ struct vt_stat {
 	__u16 v_signal;	/* signal to send */
 	__u16 v_state;		/* vt bitmask */
 };
-#define VT_GETSTATE	0x5603	/* get global vt state info */
-#define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
+#define VT_GETSTATE		_IO('V', 0x03)	/* get global vt state info */
+#define VT_SENDSIG		_IO('V', 0x04)	/* signal to send to bitmask of vts */
 
-#define VT_RELDISP	0x5605	/* release display */
+#define VT_RELDISP		_IO('V', 0x05)	/* release display */
 
-#define VT_ACTIVATE	0x5606	/* make vt active */
-#define VT_WAITACTIVE	0x5607	/* wait for vt active */
-#define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
+#define VT_ACTIVATE		_IO('V', 0x06)	/* make vt active */
+#define VT_WAITACTIVE		_IO('V', 0x07)	/* wait for vt active */
+#define VT_DISALLOCATE		_IO('V', 0x08)  /* free memory associated to vt */
 
 struct vt_sizes {
 	__u16 v_rows;		/* number of rows */
 	__u16 v_cols;		/* number of columns */
 	__u16 v_scrollsize;	/* number of lines of scrollback */
 };
-#define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
+#define VT_RESIZE		_IO('V', 0x09)	/* set kernel's idea of screensize */
 
 struct vt_consize {
 	__u16 v_rows;	/* number of rows */
@@ -60,10 +60,10 @@ struct vt_consize {
 	__u16 v_vcol;	/* number of pixel columns on screen */
 	__u16 v_ccol;	/* number of pixel columns per character */
 };
-#define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
-#define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
-#define VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
-#define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
+#define VT_RESIZEX		_IO('V', 0x0A)  /* set kernel's idea of screensize + more */
+#define VT_LOCKSWITCH		_IO('V', 0x0B)  /* disallow vt switching */
+#define VT_UNLOCKSWITCH		_IO('V', 0x0C)  /* allow vt switching */
+#define VT_GETHIFONTMASK	_IO('V', 0x0D)  /* return hi font mask */
 
 struct vt_event {
 	__u32 event;
@@ -77,14 +77,14 @@ struct vt_event {
 	__u32 pad[4];		/* Padding for expansion */
 };
 
-#define VT_WAITEVENT	0x560E	/* Wait for an event */
+#define VT_WAITEVENT		_IO('V', 0x0E)	/* Wait for an event */
 
 struct vt_setactivate {
 	__u32 console;
 	struct vt_mode mode;
 };
 
-#define VT_SETACTIVATE	0x560F	/* Activate and set the mode of a console */
+#define VT_SETACTIVATE		_IO('V', 0x0F)	/* Activate and set the mode of a console */
 
 /* get console size and cursor position */
 struct vt_consizecsrpos {
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (6 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 15:12   ` Andy Shevchenko
  2025-06-11 10:02 ` [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Jiri Slaby (SUSE)
                   ` (24 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE),
	Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Ilpo Järvinen, Andy Shevchenko,
	Paul Cercueil, Vladimir Zapolskiy, Kunihiko Hayashi,
	Masami Hiramatsu, linuxppc-dev, linux-mips, linux-arm-kernel

uart_port::{serial_in,serial_out} (and plat_serial8250_port::* likewise)
historically use:
* 'unsigned int' for 32-bit register values in reads and writes, and
* 'int' for offsets.

Make them sane such that:
* 'u32' is used for register values, and
* 'unsigned int' is used for offsets.

While at it, name hooks' parameters, so it is clear what is what.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Paul Cercueil <paul@crapouillou.net>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
---
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-mips@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/powerpc/kernel/legacy_serial.c     |  7 ++---
 drivers/tty/serial/8250/8250_dw.c       | 34 ++++++++++++-------------
 drivers/tty/serial/8250/8250_em.c       |  4 +--
 drivers/tty/serial/8250/8250_ingenic.c  |  8 +++---
 drivers/tty/serial/8250/8250_ioc3.c     |  4 +--
 drivers/tty/serial/8250/8250_lpc18xx.c  |  2 +-
 drivers/tty/serial/8250/8250_pci.c      |  6 ++---
 drivers/tty/serial/8250/8250_port.c     | 30 +++++++++++-----------
 drivers/tty/serial/8250/8250_rt288x.c   |  4 +--
 drivers/tty/serial/8250/8250_uniphier.c |  4 +--
 include/linux/serial_8250.h             |  4 +--
 include/linux/serial_core.h             |  4 +--
 12 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index a874eb8e000b..ae1906bfe8a5 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -54,9 +54,10 @@ static int legacy_serial_console = -1;
 static const upf_t legacy_port_flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
 	UPF_SHARE_IRQ | UPF_FIXED_PORT;
 
-static unsigned int tsi_serial_in(struct uart_port *p, int offset)
+static u32 tsi_serial_in(struct uart_port *p, unsigned int offset)
 {
-	unsigned int tmp;
+	u32 tmp;
+
 	offset = offset << p->regshift;
 	if (offset == UART_IIR) {
 		tmp = readl(p->membase + (UART_IIR & ~3));
@@ -65,7 +66,7 @@ static unsigned int tsi_serial_in(struct uart_port *p, int offset)
 		return readb(p->membase + offset);
 }
 
-static void tsi_serial_out(struct uart_port *p, int offset, int value)
+static void tsi_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	if (!((offset == UART_IER) && (value & UART_IER_UUE)))
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 1902f29444a1..0a22f0cb8896 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -67,8 +67,8 @@ struct dw8250_data {
 	struct dw8250_port_data	data;
 	const struct dw8250_platform_data *pdata;
 
-	int			msr_mask_on;
-	int			msr_mask_off;
+	u32			msr_mask_on;
+	u32			msr_mask_off;
 	struct clk		*clk;
 	struct clk		*pclk;
 	struct notifier_block	clk_notifier;
@@ -94,7 +94,7 @@ static inline struct dw8250_data *work_to_dw8250_data(struct work_struct *work)
 	return container_of(work, struct dw8250_data, clk_work);
 }
 
-static inline int dw8250_modify_msr(struct uart_port *p, int offset, int value)
+static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u32 value)
 {
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
 
@@ -145,7 +145,7 @@ static void dw8250_force_idle(struct uart_port *p)
  * routine. Hence, it must not call serial_port_out() or serial_out()
  * against the modified registers here, i.e. LCR.
  */
-static void dw8250_check_lcr(struct uart_port *p, int offset, int value)
+static void dw8250_check_lcr(struct uart_port *p, unsigned int offset, u32 value)
 {
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
 	void __iomem *addr = p->membase + (offset << p->regshift);
@@ -156,7 +156,7 @@ static void dw8250_check_lcr(struct uart_port *p, int offset, int value)
 
 	/* Make sure LCR write wasn't ignored */
 	while (tries--) {
-		unsigned int lcr = serial_port_in(p, offset);
+		u32 lcr = serial_port_in(p, offset);
 
 		if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR))
 			return;
@@ -205,13 +205,13 @@ static void dw8250_tx_wait_empty(struct uart_port *p)
 	}
 }
 
-static void dw8250_serial_out(struct uart_port *p, int offset, int value)
+static void dw8250_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	writeb(value, p->membase + (offset << p->regshift));
 	dw8250_check_lcr(p, offset, value);
 }
 
-static void dw8250_serial_out38x(struct uart_port *p, int offset, int value)
+static void dw8250_serial_out38x(struct uart_port *p, unsigned int offset, u32 value)
 {
 	/* Allow the TX to drain before we reconfigure */
 	if (offset == UART_LCR)
@@ -220,22 +220,22 @@ static void dw8250_serial_out38x(struct uart_port *p, int offset, int value)
 	dw8250_serial_out(p, offset, value);
 }
 
-static unsigned int dw8250_serial_in(struct uart_port *p, int offset)
+static u32 dw8250_serial_in(struct uart_port *p, unsigned int offset)
 {
-	unsigned int value = readb(p->membase + (offset << p->regshift));
+	u32 value = readb(p->membase + (offset << p->regshift));
 
 	return dw8250_modify_msr(p, offset, value);
 }
 
 #ifdef CONFIG_64BIT
-static unsigned int dw8250_serial_inq(struct uart_port *p, int offset)
+static u32 dw8250_serial_inq(struct uart_port *p, unsigned int offset)
 {
 	u8 value = __raw_readq(p->membase + (offset << p->regshift));
 
 	return dw8250_modify_msr(p, offset, value);
 }
 
-static void dw8250_serial_outq(struct uart_port *p, int offset, int value)
+static void dw8250_serial_outq(struct uart_port *p, unsigned int offset, u32 value)
 {
 	value &= 0xff;
 	__raw_writeq(value, p->membase + (offset << p->regshift));
@@ -246,28 +246,28 @@ static void dw8250_serial_outq(struct uart_port *p, int offset, int value)
 }
 #endif /* CONFIG_64BIT */
 
-static void dw8250_serial_out32(struct uart_port *p, int offset, int value)
+static void dw8250_serial_out32(struct uart_port *p, unsigned int offset, u32 value)
 {
 	writel(value, p->membase + (offset << p->regshift));
 	dw8250_check_lcr(p, offset, value);
 }
 
-static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
+static u32 dw8250_serial_in32(struct uart_port *p, unsigned int offset)
 {
-	unsigned int value = readl(p->membase + (offset << p->regshift));
+	u32 value = readl(p->membase + (offset << p->regshift));
 
 	return dw8250_modify_msr(p, offset, value);
 }
 
-static void dw8250_serial_out32be(struct uart_port *p, int offset, int value)
+static void dw8250_serial_out32be(struct uart_port *p, unsigned int offset, u32 value)
 {
 	iowrite32be(value, p->membase + (offset << p->regshift));
 	dw8250_check_lcr(p, offset, value);
 }
 
-static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)
+static u32 dw8250_serial_in32be(struct uart_port *p, unsigned int offset)
 {
-       unsigned int value = ioread32be(p->membase + (offset << p->regshift));
+       u32 value = ioread32be(p->membase + (offset << p->regshift));
 
        return dw8250_modify_msr(p, offset, value);
 }
diff --git a/drivers/tty/serial/8250/8250_em.c b/drivers/tty/serial/8250/8250_em.c
index 35094f884492..e90c71494944 100644
--- a/drivers/tty/serial/8250/8250_em.c
+++ b/drivers/tty/serial/8250/8250_em.c
@@ -59,7 +59,7 @@ static void serial8250_em_serial_out_helper(struct uart_port *p, int offset,
 	}
 }
 
-static unsigned int serial8250_em_serial_in(struct uart_port *p, int offset)
+static u32 serial8250_em_serial_in(struct uart_port *p, unsigned int offset)
 {
 	switch (offset) {
 	case UART_RX: /* RX @ 0x00 */
@@ -119,7 +119,7 @@ static void serial8250_em_reg_update(struct uart_port *p, int off, int value)
 	serial8250_em_serial_out_helper(p, UART_HCR0_EM, hcr0);
 }
 
-static void serial8250_em_serial_out(struct uart_port *p, int offset, int value)
+static void serial8250_em_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	switch (offset) {
 	case UART_TX:
diff --git a/drivers/tty/serial/8250/8250_ingenic.c b/drivers/tty/serial/8250/8250_ingenic.c
index a73dd3773640..94542fc143c2 100644
--- a/drivers/tty/serial/8250/8250_ingenic.c
+++ b/drivers/tty/serial/8250/8250_ingenic.c
@@ -168,9 +168,9 @@ OF_EARLYCON_DECLARE(jz4780_uart, "ingenic,jz4780-uart",
 OF_EARLYCON_DECLARE(x1000_uart, "ingenic,x1000-uart",
 		    ingenic_early_console_setup);
 
-static void ingenic_uart_serial_out(struct uart_port *p, int offset, int value)
+static void ingenic_uart_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
-	int ier;
+	u32 ier;
 
 	switch (offset) {
 	case UART_FCR:
@@ -206,9 +206,9 @@ static void ingenic_uart_serial_out(struct uart_port *p, int offset, int value)
 	writeb(value, p->membase + (offset << p->regshift));
 }
 
-static unsigned int ingenic_uart_serial_in(struct uart_port *p, int offset)
+static u32 ingenic_uart_serial_in(struct uart_port *p, unsigned int offset)
 {
-	unsigned int value;
+	u8 value;
 
 	value = readb(p->membase + (offset << p->regshift));
 
diff --git a/drivers/tty/serial/8250/8250_ioc3.c b/drivers/tty/serial/8250/8250_ioc3.c
index 499e80aa4cf9..3ebda9a5d07d 100644
--- a/drivers/tty/serial/8250/8250_ioc3.c
+++ b/drivers/tty/serial/8250/8250_ioc3.c
@@ -21,12 +21,12 @@ struct ioc3_8250_data {
 	int line;
 };
 
-static unsigned int ioc3_serial_in(struct uart_port *p, int offset)
+static u32 ioc3_serial_in(struct uart_port *p, unsigned int offset)
 {
 	return readb(p->membase + (offset ^ 3));
 }
 
-static void ioc3_serial_out(struct uart_port *p, int offset, int value)
+static void ioc3_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	writeb(value, p->membase + (offset ^ 3));
 }
diff --git a/drivers/tty/serial/8250/8250_lpc18xx.c b/drivers/tty/serial/8250/8250_lpc18xx.c
index d52445948da0..6c0489c9c253 100644
--- a/drivers/tty/serial/8250/8250_lpc18xx.c
+++ b/drivers/tty/serial/8250/8250_lpc18xx.c
@@ -67,7 +67,7 @@ static int lpc18xx_rs485_config(struct uart_port *port, struct ktermios *termios
 	return 0;
 }
 
-static void lpc18xx_uart_serial_out(struct uart_port *p, int offset, int value)
+static void lpc18xx_uart_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	/*
 	 * For DMA mode one must ensure that the UART_FCR_DMA_SELECT
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 73c200127b08..152f914c599d 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1751,7 +1751,7 @@ static int pci_fintek_init(struct pci_dev *dev)
 	return max_port;
 }
 
-static void f815xxa_mem_serial_out(struct uart_port *p, int offset, int value)
+static void f815xxa_mem_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	struct f815xxa_data *data = p->private_data;
 	unsigned long flags;
@@ -1846,10 +1846,10 @@ static void kt_handle_break(struct uart_port *p)
 	serial8250_clear_and_reinit_fifos(up);
 }
 
-static unsigned int kt_serial_in(struct uart_port *p, int offset)
+static u32 kt_serial_in(struct uart_port *p, unsigned int offset)
 {
 	struct uart_8250_port *up = up_to_u8250p(p);
-	unsigned int val;
+	u32 val;
 
 	/*
 	 * When the Intel ME (management engine) gets reset its serial
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 6d7b8c4667c9..f5407832e8a7 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -339,14 +339,14 @@ static void default_serial_dl_write(struct uart_8250_port *up, u32 value)
 }
 
 #ifdef CONFIG_HAS_IOPORT
-static unsigned int hub6_serial_in(struct uart_port *p, int offset)
+static u32 hub6_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	outb(p->hub6 - 1 + offset, p->iobase);
 	return inb(p->iobase + 1);
 }
 
-static void hub6_serial_out(struct uart_port *p, int offset, int value)
+static void hub6_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	outb(p->hub6 - 1 + offset, p->iobase);
@@ -354,73 +354,73 @@ static void hub6_serial_out(struct uart_port *p, int offset, int value)
 }
 #endif /* CONFIG_HAS_IOPORT */
 
-static unsigned int mem_serial_in(struct uart_port *p, int offset)
+static u32 mem_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	return readb(p->membase + offset);
 }
 
-static void mem_serial_out(struct uart_port *p, int offset, int value)
+static void mem_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	writeb(value, p->membase + offset);
 }
 
-static void mem16_serial_out(struct uart_port *p, int offset, int value)
+static void mem16_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	writew(value, p->membase + offset);
 }
 
-static unsigned int mem16_serial_in(struct uart_port *p, int offset)
+static u32 mem16_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	return readw(p->membase + offset);
 }
 
-static void mem32_serial_out(struct uart_port *p, int offset, int value)
+static void mem32_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	writel(value, p->membase + offset);
 }
 
-static unsigned int mem32_serial_in(struct uart_port *p, int offset)
+static u32 mem32_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	return readl(p->membase + offset);
 }
 
-static void mem32be_serial_out(struct uart_port *p, int offset, int value)
+static void mem32be_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	iowrite32be(value, p->membase + offset);
 }
 
-static unsigned int mem32be_serial_in(struct uart_port *p, int offset)
+static u32 mem32be_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	return ioread32be(p->membase + offset);
 }
 
 #ifdef CONFIG_HAS_IOPORT
-static unsigned int io_serial_in(struct uart_port *p, int offset)
+static u32 io_serial_in(struct uart_port *p, unsigned int offset)
 {
 	offset = offset << p->regshift;
 	return inb(p->iobase + offset);
 }
 
-static void io_serial_out(struct uart_port *p, int offset, int value)
+static void io_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	offset = offset << p->regshift;
 	outb(value, p->iobase + offset);
 }
 #endif
-static unsigned int no_serial_in(struct uart_port *p, int offset)
+static u32 no_serial_in(struct uart_port *p, unsigned int offset)
 {
-	return (unsigned int)-1;
+	return ~0U;
 }
 
-static void no_serial_out(struct uart_port *p, int offset, int value)
+static void no_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 }
 
diff --git a/drivers/tty/serial/8250/8250_rt288x.c b/drivers/tty/serial/8250/8250_rt288x.c
index 6415ca8d3adf..bf28b8a9a710 100644
--- a/drivers/tty/serial/8250/8250_rt288x.c
+++ b/drivers/tty/serial/8250/8250_rt288x.c
@@ -33,7 +33,7 @@ static const u8 au_io_out_map[5] = {
 	[UART_MCR]	= 6,
 };
 
-static unsigned int au_serial_in(struct uart_port *p, int offset)
+static u32 au_serial_in(struct uart_port *p, unsigned int offset)
 {
 	if (offset >= ARRAY_SIZE(au_io_in_map))
 		return UINT_MAX;
@@ -42,7 +42,7 @@ static unsigned int au_serial_in(struct uart_port *p, int offset)
 	return __raw_readl(p->membase + (offset << p->regshift));
 }
 
-static void au_serial_out(struct uart_port *p, int offset, int value)
+static void au_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	if (offset >= ARRAY_SIZE(au_io_out_map))
 		return;
diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8250/8250_uniphier.c
index 4874a9632db3..e3db60bf50c9 100644
--- a/drivers/tty/serial/8250/8250_uniphier.c
+++ b/drivers/tty/serial/8250/8250_uniphier.c
@@ -63,7 +63,7 @@ OF_EARLYCON_DECLARE(uniphier, "socionext,uniphier-uart",
  * The register map is slightly different from that of 8250.
  * IO callbacks must be overridden for correct access to FCR, LCR, MCR and SCR.
  */
-static unsigned int uniphier_serial_in(struct uart_port *p, int offset)
+static u32 uniphier_serial_in(struct uart_port *p, unsigned int offset)
 {
 	unsigned int valshift = 0;
 
@@ -92,7 +92,7 @@ static unsigned int uniphier_serial_in(struct uart_port *p, int offset)
 	return (readl(p->membase + offset) >> valshift) & 0xff;
 }
 
-static void uniphier_serial_out(struct uart_port *p, int offset, int value)
+static void uniphier_serial_out(struct uart_port *p, unsigned int offset, u32 value)
 {
 	unsigned int valshift = 0;
 	bool normal = false;
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index 144de7a7948d..01efdce0fda0 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -46,8 +46,8 @@ struct plat_serial8250_port {
 	unsigned int	type;		/* If UPF_FIXED_TYPE */
 	upf_t		flags;		/* UPF_* flags */
 	u16		bugs;		/* port bugs */
-	unsigned int	(*serial_in)(struct uart_port *, int);
-	void		(*serial_out)(struct uart_port *, int, int);
+	u32		(*serial_in)(struct uart_port *, unsigned int offset);
+	void		(*serial_out)(struct uart_port *, unsigned int offset, u32 val);
 	u32		(*dl_read)(struct uart_8250_port *up);
 	void		(*dl_write)(struct uart_8250_port *up, u32 value);
 	void		(*set_termios)(struct uart_port *,
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 914b5e97e056..d65b15449cfe 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -443,8 +443,8 @@ struct uart_port {
 	spinlock_t		lock;			/* port lock */
 	unsigned long		iobase;			/* in/out[bwl] */
 	unsigned char __iomem	*membase;		/* read/write[bwl] */
-	unsigned int		(*serial_in)(struct uart_port *, int);
-	void			(*serial_out)(struct uart_port *, int, int);
+	u32			(*serial_in)(struct uart_port *, unsigned int offset);
+	void			(*serial_out)(struct uart_port *, unsigned int offset, u32 val);
 	void			(*set_termios)(struct uart_port *,
 				               struct ktermios *new,
 				               const struct ktermios *old);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (7 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:42   ` Ilpo Järvinen
  2025-06-11 11:46   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 10/33] serial: 8250: invert conditions in RSA functions Jiri Slaby (SUSE)
                   ` (23 subsequent siblings)
  32 siblings, 2 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

All these:
  #ifdef CONFIG_SERIAL_8250_RSA
  ...
  #endif

in the 8250 generic code distract the reader. Introduce empty inlines to
handle the !CONFIG_SERIAL_8250_RSA case and handle the '#if's around the
RSA functions definitions.

This means rsa_autoconfig() and rsa_reset() functions were introduced to
contain the particular code.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 54 ++++++++++++++---------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index f5407832e8a7..233316a88df2 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -738,6 +738,9 @@ static int __enable_rsa(struct uart_8250_port *up)
 	return result;
 }
 
+/*
+ * If this is an RSA port, see if we can kick it up to the higher speed clock.
+ */
 static void enable_rsa(struct uart_8250_port *up)
 {
 	if (up->port.type == PORT_RSA) {
@@ -752,10 +755,9 @@ static void enable_rsa(struct uart_8250_port *up)
 }
 
 /*
- * Attempts to turn off the RSA FIFO.  Returns zero on failure.
- * It is unknown why interrupts were disabled in here.  However,
- * the caller is expected to preserve this behaviour by grabbing
- * the spinlock before calling this function.
+ * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
+ * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
+ * behaviour by grabbing the spinlock before calling this function.
  */
 static void disable_rsa(struct uart_8250_port *up)
 {
@@ -780,6 +782,25 @@ static void disable_rsa(struct uart_8250_port *up)
 		uart_port_unlock_irq(&up->port);
 	}
 }
+
+static void rsa_autoconfig(struct uart_8250_port *up)
+{
+	/* Only probe for RSA ports if we got the region. */
+	if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
+	    __enable_rsa(up))
+		up->port.type = PORT_RSA;
+}
+
+static void rsa_reset(struct uart_8250_port *up)
+{
+	if (up->port.type == PORT_RSA)
+		serial_out(up, UART_RSA_FRR, 0);
+}
+#else
+static inline void enable_rsa(struct uart_8250_port *up) {}
+static inline void disable_rsa(struct uart_8250_port *up) {}
+static inline void rsa_autoconfig(struct uart_8250_port *up) {}
+static inline void rsa_reset(struct uart_8250_port *up) {}
 #endif /* CONFIG_SERIAL_8250_RSA */
 
 /*
@@ -1267,14 +1288,7 @@ static void autoconfig(struct uart_8250_port *up)
 		break;
 	}
 
-#ifdef CONFIG_SERIAL_8250_RSA
-	/*
-	 * Only probe for RSA ports if we got the region.
-	 */
-	if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA &&
-	    __enable_rsa(up))
-		port->type = PORT_RSA;
-#endif
+	rsa_autoconfig(up);
 
 	serial_out(up, UART_LCR, save_lcr);
 
@@ -1289,10 +1303,7 @@ static void autoconfig(struct uart_8250_port *up)
 	/*
 	 * Reset the UART.
 	 */
-#ifdef CONFIG_SERIAL_8250_RSA
-	if (port->type == PORT_RSA)
-		serial_out(up, UART_RSA_FRR, 0);
-#endif
+	rsa_reset(up);
 	serial8250_out_MCR(up, save_mcr);
 	serial8250_clear_fifos(up);
 	serial_in(up, UART_RX);
@@ -2248,13 +2259,7 @@ int serial8250_do_startup(struct uart_port *port)
 				UART_DA830_PWREMU_MGMT_FREE);
 	}
 
-#ifdef CONFIG_SERIAL_8250_RSA
-	/*
-	 * If this is an RSA port, see if we can kick it up to the
-	 * higher speed clock.
-	 */
 	enable_rsa(up);
-#endif
 
 	/*
 	 * Clear the FIFO buffers and disable them.
@@ -2521,12 +2526,7 @@ void serial8250_do_shutdown(struct uart_port *port)
 			serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
 	serial8250_clear_fifos(up);
 
-#ifdef CONFIG_SERIAL_8250_RSA
-	/*
-	 * Reset the RSA board back to 115kbps compat mode.
-	 */
 	disable_rsa(up);
-#endif
 
 	/*
 	 * Read data port to reset things, and then unlink from
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 10/33] serial: 8250: invert conditions in RSA functions
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (8 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:45   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 11/33] serial: 8250: put RSA functions to their namespace Jiri Slaby (SUSE)
                   ` (22 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

The code can short-return in case something does not hold. So invert the
conditions and return in those cases immediately. This makes the code
flow more natural and less nested.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 59 +++++++++++++++++------------
 1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 233316a88df2..e7652d62ab2f 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -743,15 +743,16 @@ static int __enable_rsa(struct uart_8250_port *up)
  */
 static void enable_rsa(struct uart_8250_port *up)
 {
-	if (up->port.type == PORT_RSA) {
-		if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
-			uart_port_lock_irq(&up->port);
-			__enable_rsa(up);
-			uart_port_unlock_irq(&up->port);
-		}
-		if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
-			serial_out(up, UART_RSA_FRR, 0);
+	if (up->port.type != PORT_RSA)
+		return;
+
+	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
+		uart_port_lock_irq(&up->port);
+		__enable_rsa(up);
+		uart_port_unlock_irq(&up->port);
 	}
+	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
+		serial_out(up, UART_RSA_FRR, 0);
 }
 
 /*
@@ -764,37 +765,45 @@ static void disable_rsa(struct uart_8250_port *up)
 	unsigned char mode;
 	int result;
 
-	if (up->port.type == PORT_RSA &&
-	    up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
-		uart_port_lock_irq(&up->port);
+	if (up->port.type != PORT_RSA)
+		return;
 
-		mode = serial_in(up, UART_RSA_MSR);
-		result = !(mode & UART_RSA_MSR_FIFO);
+	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
+		return;
 
-		if (!result) {
-			serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
-			mode = serial_in(up, UART_RSA_MSR);
-			result = !(mode & UART_RSA_MSR_FIFO);
-		}
+	uart_port_lock_irq(&up->port);
+	mode = serial_in(up, UART_RSA_MSR);
+	result = !(mode & UART_RSA_MSR_FIFO);
 
-		if (result)
-			up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
-		uart_port_unlock_irq(&up->port);
+	if (!result) {
+		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
+		mode = serial_in(up, UART_RSA_MSR);
+		result = !(mode & UART_RSA_MSR_FIFO);
 	}
+
+	if (result)
+		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
+	uart_port_unlock_irq(&up->port);
 }
 
 static void rsa_autoconfig(struct uart_8250_port *up)
 {
 	/* Only probe for RSA ports if we got the region. */
-	if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
-	    __enable_rsa(up))
+	if (up->port.type != PORT_16550A)
+		return;
+	if (!(up->probe & UART_PROBE_RSA))
+		return;
+
+	if (__enable_rsa(up))
 		up->port.type = PORT_RSA;
 }
 
 static void rsa_reset(struct uart_8250_port *up)
 {
-	if (up->port.type == PORT_RSA)
-		serial_out(up, UART_RSA_FRR, 0);
+	if (up->port.type != PORT_RSA)
+		return;
+
+	serial_out(up, UART_RSA_FRR, 0);
 }
 #else
 static inline void enable_rsa(struct uart_8250_port *up) {}
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 11/33] serial: 8250: put RSA functions to their namespace
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (9 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 10/33] serial: 8250: invert conditions in RSA functions Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:54   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c Jiri Slaby (SUSE)
                   ` (21 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Prefix the functions with rsa_, not suffix.

This is a preparation for moving them out to 8250_rsa.c in the next
patch.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index e7652d62ab2f..d8a90818f431 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -718,7 +718,7 @@ static void serial8250_clear_IER(struct uart_8250_port *up)
  * Attempts to turn on the RSA FIFO.  Returns zero on failure.
  * We set the port uart clock rate if we succeed.
  */
-static int __enable_rsa(struct uart_8250_port *up)
+static int __rsa_enable(struct uart_8250_port *up)
 {
 	unsigned char mode;
 	int result;
@@ -741,14 +741,14 @@ static int __enable_rsa(struct uart_8250_port *up)
 /*
  * If this is an RSA port, see if we can kick it up to the higher speed clock.
  */
-static void enable_rsa(struct uart_8250_port *up)
+static void rsa_enable(struct uart_8250_port *up)
 {
 	if (up->port.type != PORT_RSA)
 		return;
 
 	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
 		uart_port_lock_irq(&up->port);
-		__enable_rsa(up);
+		__rsa_enable(up);
 		uart_port_unlock_irq(&up->port);
 	}
 	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
@@ -760,7 +760,7 @@ static void enable_rsa(struct uart_8250_port *up)
  * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
  * behaviour by grabbing the spinlock before calling this function.
  */
-static void disable_rsa(struct uart_8250_port *up)
+static void rsa_disable(struct uart_8250_port *up)
 {
 	unsigned char mode;
 	int result;
@@ -794,7 +794,7 @@ static void rsa_autoconfig(struct uart_8250_port *up)
 	if (!(up->probe & UART_PROBE_RSA))
 		return;
 
-	if (__enable_rsa(up))
+	if (__rsa_enable(up))
 		up->port.type = PORT_RSA;
 }
 
@@ -806,8 +806,8 @@ static void rsa_reset(struct uart_8250_port *up)
 	serial_out(up, UART_RSA_FRR, 0);
 }
 #else
-static inline void enable_rsa(struct uart_8250_port *up) {}
-static inline void disable_rsa(struct uart_8250_port *up) {}
+static inline void rsa_enable(struct uart_8250_port *up) {}
+static inline void rsa_disable(struct uart_8250_port *up) {}
 static inline void rsa_autoconfig(struct uart_8250_port *up) {}
 static inline void rsa_reset(struct uart_8250_port *up) {}
 #endif /* CONFIG_SERIAL_8250_RSA */
@@ -2268,7 +2268,7 @@ int serial8250_do_startup(struct uart_port *port)
 				UART_DA830_PWREMU_MGMT_FREE);
 	}
 
-	enable_rsa(up);
+	rsa_enable(up);
 
 	/*
 	 * Clear the FIFO buffers and disable them.
@@ -2535,7 +2535,7 @@ void serial8250_do_shutdown(struct uart_port *port)
 			serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
 	serial8250_clear_fifos(up);
 
-	disable_rsa(up);
+	rsa_disable(up);
 
 	/*
 	 * Read data port to reset things, and then unlink from
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (10 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 11/33] serial: 8250: put RSA functions to their namespace Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:49   ` Ilpo Järvinen
  2025-06-11 10:02 ` [PATCH 13/33] serial: 8250: extract serial8250_startup_special() Jiri Slaby (SUSE)
                   ` (20 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

They are RSA-specific, so should live in a preexisting 8250_rsa.c. Move
them there.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250.h      |  8 +++
 drivers/tty/serial/8250/8250_port.c | 99 -----------------------------
 drivers/tty/serial/8250/8250_rsa.c  | 92 +++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 99 deletions(-)

diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index 18530c31a598..cfe6ba286b45 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -318,8 +318,16 @@ static inline void serial8250_pnp_exit(void) { }
 
 #ifdef CONFIG_SERIAL_8250_RSA
 void univ8250_rsa_support(struct uart_ops *ops);
+void rsa_enable(struct uart_8250_port *up);
+void rsa_disable(struct uart_8250_port *up);
+void rsa_autoconfig(struct uart_8250_port *up);
+void rsa_reset(struct uart_8250_port *up);
 #else
 static inline void univ8250_rsa_support(struct uart_ops *ops) { }
+static inline void rsa_enable(struct uart_8250_port *up) {}
+static inline void rsa_disable(struct uart_8250_port *up) {}
+static inline void rsa_autoconfig(struct uart_8250_port *up) {}
+static inline void rsa_reset(struct uart_8250_port *up) {}
 #endif
 
 #ifdef CONFIG_SERIAL_8250_FINTEK
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index d8a90818f431..476f5fc50237 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -713,105 +713,6 @@ static void serial8250_clear_IER(struct uart_8250_port *up)
 		serial_out(up, UART_IER, 0);
 }
 
-#ifdef CONFIG_SERIAL_8250_RSA
-/*
- * Attempts to turn on the RSA FIFO.  Returns zero on failure.
- * We set the port uart clock rate if we succeed.
- */
-static int __rsa_enable(struct uart_8250_port *up)
-{
-	unsigned char mode;
-	int result;
-
-	mode = serial_in(up, UART_RSA_MSR);
-	result = mode & UART_RSA_MSR_FIFO;
-
-	if (!result) {
-		serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
-		mode = serial_in(up, UART_RSA_MSR);
-		result = mode & UART_RSA_MSR_FIFO;
-	}
-
-	if (result)
-		up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
-
-	return result;
-}
-
-/*
- * If this is an RSA port, see if we can kick it up to the higher speed clock.
- */
-static void rsa_enable(struct uart_8250_port *up)
-{
-	if (up->port.type != PORT_RSA)
-		return;
-
-	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
-		uart_port_lock_irq(&up->port);
-		__rsa_enable(up);
-		uart_port_unlock_irq(&up->port);
-	}
-	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
-		serial_out(up, UART_RSA_FRR, 0);
-}
-
-/*
- * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
- * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
- * behaviour by grabbing the spinlock before calling this function.
- */
-static void rsa_disable(struct uart_8250_port *up)
-{
-	unsigned char mode;
-	int result;
-
-	if (up->port.type != PORT_RSA)
-		return;
-
-	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
-		return;
-
-	uart_port_lock_irq(&up->port);
-	mode = serial_in(up, UART_RSA_MSR);
-	result = !(mode & UART_RSA_MSR_FIFO);
-
-	if (!result) {
-		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
-		mode = serial_in(up, UART_RSA_MSR);
-		result = !(mode & UART_RSA_MSR_FIFO);
-	}
-
-	if (result)
-		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
-	uart_port_unlock_irq(&up->port);
-}
-
-static void rsa_autoconfig(struct uart_8250_port *up)
-{
-	/* Only probe for RSA ports if we got the region. */
-	if (up->port.type != PORT_16550A)
-		return;
-	if (!(up->probe & UART_PROBE_RSA))
-		return;
-
-	if (__rsa_enable(up))
-		up->port.type = PORT_RSA;
-}
-
-static void rsa_reset(struct uart_8250_port *up)
-{
-	if (up->port.type != PORT_RSA)
-		return;
-
-	serial_out(up, UART_RSA_FRR, 0);
-}
-#else
-static inline void rsa_enable(struct uart_8250_port *up) {}
-static inline void rsa_disable(struct uart_8250_port *up) {}
-static inline void rsa_autoconfig(struct uart_8250_port *up) {}
-static inline void rsa_reset(struct uart_8250_port *up) {}
-#endif /* CONFIG_SERIAL_8250_RSA */
-
 /*
  * This is a quickie test to see how big the FIFO is.
  * It doesn't work at all the time, more's the pity.
diff --git a/drivers/tty/serial/8250/8250_rsa.c b/drivers/tty/serial/8250/8250_rsa.c
index 4c8b9671bd41..59d2ecf23068 100644
--- a/drivers/tty/serial/8250/8250_rsa.c
+++ b/drivers/tty/serial/8250/8250_rsa.c
@@ -107,6 +107,98 @@ void univ8250_rsa_support(struct uart_ops *ops)
 module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
 MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
 
+/*
+ * Attempts to turn on the RSA FIFO.  Returns zero on failure.
+ * We set the port uart clock rate if we succeed.
+ */
+static int __rsa_enable(struct uart_8250_port *up)
+{
+	unsigned char mode;
+	int result;
+
+	mode = serial_in(up, UART_RSA_MSR);
+	result = mode & UART_RSA_MSR_FIFO;
+
+	if (!result) {
+		serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
+		mode = serial_in(up, UART_RSA_MSR);
+		result = mode & UART_RSA_MSR_FIFO;
+	}
+
+	if (result)
+		up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
+
+	return result;
+}
+
+/*
+ * If this is an RSA port, see if we can kick it up to the higher speed clock.
+ */
+void rsa_enable(struct uart_8250_port *up)
+{
+	if (up->port.type != PORT_RSA)
+		return;
+
+	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
+		uart_port_lock_irq(&up->port);
+		__rsa_enable(up);
+		uart_port_unlock_irq(&up->port);
+	}
+	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
+		serial_out(up, UART_RSA_FRR, 0);
+}
+
+/*
+ * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
+ * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
+ * behaviour by grabbing the spinlock before calling this function.
+ */
+void rsa_disable(struct uart_8250_port *up)
+{
+	unsigned char mode;
+	int result;
+
+	if (up->port.type != PORT_RSA)
+		return;
+
+	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
+		return;
+
+	uart_port_lock_irq(&up->port);
+	mode = serial_in(up, UART_RSA_MSR);
+	result = !(mode & UART_RSA_MSR_FIFO);
+
+	if (!result) {
+		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
+		mode = serial_in(up, UART_RSA_MSR);
+		result = !(mode & UART_RSA_MSR_FIFO);
+	}
+
+	if (result)
+		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
+	uart_port_unlock_irq(&up->port);
+}
+
+void rsa_autoconfig(struct uart_8250_port *up)
+{
+	/* Only probe for RSA ports if we got the region. */
+	if (up->port.type != PORT_16550A)
+		return;
+	if (!(up->probe & UART_PROBE_RSA))
+		return;
+
+	if (__rsa_enable(up))
+		up->port.type = PORT_RSA;
+}
+
+void rsa_reset(struct uart_8250_port *up)
+{
+	if (up->port.type != PORT_RSA)
+		return;
+
+	serial_out(up, UART_RSA_FRR, 0);
+}
+
 #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
 #ifndef MODULE
 /*
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 13/33] serial: 8250: extract serial8250_startup_special()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (11 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c Jiri Slaby (SUSE)
@ 2025-06-11 10:02 ` Jiri Slaby (SUSE)
  2025-06-11 11:53   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels() Jiri Slaby (SUSE)
                   ` (19 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Let the serial8250_do_startup() code handle the special ports (16C950,
DA830, RSA) startup in a separate function:
serial8250_startup_special().

And instead of multiple if-else-if, use switch-case. So that it can be
easily checked for PORT_RSA now too.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 53 +++++++++++++++++------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 476f5fc50237..21ff56a31b56 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2111,27 +2111,13 @@ static void serial8250_put_poll_char(struct uart_port *port,
 
 #endif /* CONFIG_CONSOLE_POLL */
 
-int serial8250_do_startup(struct uart_port *port)
+static void serial8250_startup_special(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
 	unsigned long flags;
-	unsigned char iir;
-	int retval;
-	u16 lsr;
-
-	if (!port->fifosize)
-		port->fifosize = uart_config[port->type].fifo_size;
-	if (!up->tx_loadsz)
-		up->tx_loadsz = uart_config[port->type].tx_loadsz;
-	if (!up->capabilities)
-		up->capabilities = uart_config[port->type].flags;
-	up->mcr = 0;
-
-	if (port->iotype != up->cur_iotype)
-		set_io_from_upio(port);
 
-	serial8250_rpm_get(up);
-	if (port->type == PORT_16C950) {
+	switch (port->type) {
+	case PORT_16C950:
 		/*
 		 * Wake up and initialize UART
 		 *
@@ -2148,9 +2134,8 @@ int serial8250_do_startup(struct uart_port *port)
 		serial_port_out(port, UART_EFR, UART_EFR_ECB);
 		serial_port_out(port, UART_LCR, 0);
 		uart_port_unlock_irqrestore(port, flags);
-	}
-
-	if (port->type == PORT_DA830) {
+		break;
+	case PORT_DA830:
 		/*
 		 * Reset the port
 		 *
@@ -2167,9 +2152,35 @@ int serial8250_do_startup(struct uart_port *port)
 				UART_DA830_PWREMU_MGMT_UTRST |
 				UART_DA830_PWREMU_MGMT_URRST |
 				UART_DA830_PWREMU_MGMT_FREE);
+		break;
+	case PORT_RSA:
+		rsa_enable(up);
+		break;
 	}
+}
+
+int serial8250_do_startup(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	unsigned long flags;
+	unsigned char iir;
+	int retval;
+	u16 lsr;
+
+	if (!port->fifosize)
+		port->fifosize = uart_config[port->type].fifo_size;
+	if (!up->tx_loadsz)
+		up->tx_loadsz = uart_config[port->type].tx_loadsz;
+	if (!up->capabilities)
+		up->capabilities = uart_config[port->type].flags;
+	up->mcr = 0;
+
+	if (port->iotype != up->cur_iotype)
+		set_io_from_upio(port);
+
+	serial8250_rpm_get(up);
 
-	rsa_enable(up);
+	serial8250_startup_special(port);
 
 	/*
 	 * Clear the FIFO buffers and disable them.
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (12 preceding siblings ...)
  2025-06-11 10:02 ` [PATCH 13/33] serial: 8250: extract serial8250_startup_special() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:07   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 15/33] serial: 8250: extract serial8250_THRE_test() Jiri Slaby (SUSE)
                   ` (18 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_startup() contains peculiar trigger levels setup for
special ports (16850, ALTR_16550_*). Move this away to a separate
function: serial8250_set_TRG_levels().

And use switch-case instead of 'if's.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 77 +++++++++++++++--------------
 1 file changed, 41 insertions(+), 36 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 21ff56a31b56..c09a90b38d8f 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2159,6 +2159,46 @@ static void serial8250_startup_special(struct uart_port *port)
 	}
 }
 
+static void serial8250_set_TRG_levels(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	switch (port->type) {
+	/* For a XR16C850, we need to set the trigger levels */
+	case PORT_16850: {
+		u8 fctr;
+
+		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
+
+		fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
+		fctr |= UART_FCTR_TRGD;
+		serial_port_out(port, UART_FCTR, fctr | UART_FCTR_RX);
+		serial_port_out(port, UART_TRG, UART_TRG_96);
+		serial_port_out(port, UART_FCTR, fctr | UART_FCTR_TX);
+		serial_port_out(port, UART_TRG, UART_TRG_96);
+
+		serial_port_out(port, UART_LCR, 0);
+		break;
+	}
+	/* For the Altera 16550 variants, set TX threshold trigger level. */
+	case PORT_ALTR_16550_F32:
+	case PORT_ALTR_16550_F64:
+	case PORT_ALTR_16550_F128:
+		if (port->fifosize <= 1)
+			return;
+
+		/* Bounds checking of TX threshold (valid 0 to fifosize-2) */
+		if (up->tx_loadsz < 2 || up->tx_loadsz > port->fifosize) {
+			dev_err(port->dev, "TX FIFO Threshold errors, skipping\n");
+			return;
+		}
+		serial_port_out(port, UART_ALTR_AFR, UART_ALTR_EN_TXFIFO_LW);
+		serial_port_out(port, UART_ALTR_TX_LOW, port->fifosize - up->tx_loadsz);
+		port->handle_irq = serial8250_tx_threshold_handle_irq;
+		break;
+	}
+}
+
 int serial8250_do_startup(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
@@ -2208,42 +2248,7 @@ int serial8250_do_startup(struct uart_port *port)
 		goto out;
 	}
 
-	/*
-	 * For a XR16C850, we need to set the trigger levels
-	 */
-	if (port->type == PORT_16850) {
-		unsigned char fctr;
-
-		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
-
-		fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
-		serial_port_out(port, UART_FCTR,
-				fctr | UART_FCTR_TRGD | UART_FCTR_RX);
-		serial_port_out(port, UART_TRG, UART_TRG_96);
-		serial_port_out(port, UART_FCTR,
-				fctr | UART_FCTR_TRGD | UART_FCTR_TX);
-		serial_port_out(port, UART_TRG, UART_TRG_96);
-
-		serial_port_out(port, UART_LCR, 0);
-	}
-
-	/*
-	 * For the Altera 16550 variants, set TX threshold trigger level.
-	 */
-	if (((port->type == PORT_ALTR_16550_F32) ||
-	     (port->type == PORT_ALTR_16550_F64) ||
-	     (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) {
-		/* Bounds checking of TX threshold (valid 0 to fifosize-2) */
-		if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) {
-			dev_err(port->dev, "TX FIFO Threshold errors, skipping\n");
-		} else {
-			serial_port_out(port, UART_ALTR_AFR,
-					UART_ALTR_EN_TXFIFO_LW);
-			serial_port_out(port, UART_ALTR_TX_LOW,
-					port->fifosize - up->tx_loadsz);
-			port->handle_irq = serial8250_tx_threshold_handle_irq;
-		}
-	}
+	serial8250_set_TRG_levels(port);
 
 	/* Check if we need to have shared IRQs */
 	if (port->irq && (up->port.flags & UPF_SHARE_IRQ))
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 15/33] serial: 8250: extract serial8250_THRE_test()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (13 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:03   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 16/33] serial: 8250: extract serial8250_initialize() Jiri Slaby (SUSE)
                   ` (17 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_startup() contains a stand-alone code for probing THRE.
Furthermore, the code block is conditional (port->irq and test for
UPF_NO_THRE_TEST).

Move this code to a separate function. The conditional can be evaluated
easier there -- by a simple return in the beginning. So the indentation
level lowers and the code is overall more readable now.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 92 +++++++++++++++--------------
 1 file changed, 49 insertions(+), 43 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index c09a90b38d8f..5466286bb44f 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2199,6 +2199,54 @@ static void serial8250_set_TRG_levels(struct uart_port *port)
 	}
 }
 
+static void serial8250_THRE_test(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	unsigned long flags;
+	bool iir_noint1, iir_noint2;
+
+	if (!port->irq)
+		return;
+
+	if (up->port.flags & UPF_NO_THRE_TEST)
+		return;
+
+	if (port->irqflags & IRQF_SHARED)
+		disable_irq_nosync(port->irq);
+
+	/*
+	 * Test for UARTs that do not reassert THRE when the transmitter is idle and the interrupt
+	 * has already been cleared.  Real 16550s should always reassert this interrupt whenever the
+	 * transmitter is idle and the interrupt is enabled.  Delays are necessary to allow register
+	 * changes to become visible.
+	 *
+	 * Synchronize UART_IER access against the console.
+	 */
+	uart_port_lock_irqsave(port, &flags);
+
+	wait_for_xmitr(up, UART_LSR_THRE);
+	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
+	udelay(1); /* allow THRE to set */
+	iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
+	serial_port_out(port, UART_IER, 0);
+	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
+	udelay(1); /* allow a working UART time to re-assert THRE */
+	iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
+	serial_port_out(port, UART_IER, 0);
+
+	uart_port_unlock_irqrestore(port, flags);
+
+	if (port->irqflags & IRQF_SHARED)
+		enable_irq(port->irq);
+
+	/*
+	 * If the interrupt is not reasserted, or we otherwise don't trust the iir, setup a timer to
+	 * kick the UART on a regular basis.
+	 */
+	if ((!iir_noint1 && iir_noint2) || up->port.flags & UPF_BUG_THRE)
+		up->bugs |= UART_BUG_THRE;
+}
+
 int serial8250_do_startup(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
@@ -2258,49 +2306,7 @@ int serial8250_do_startup(struct uart_port *port)
 	if (retval)
 		goto out;
 
-	if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) {
-		unsigned char iir1;
-
-		if (port->irqflags & IRQF_SHARED)
-			disable_irq_nosync(port->irq);
-
-		/*
-		 * Test for UARTs that do not reassert THRE when the
-		 * transmitter is idle and the interrupt has already
-		 * been cleared.  Real 16550s should always reassert
-		 * this interrupt whenever the transmitter is idle and
-		 * the interrupt is enabled.  Delays are necessary to
-		 * allow register changes to become visible.
-		 *
-		 * Synchronize UART_IER access against the console.
-		 */
-		uart_port_lock_irqsave(port, &flags);
-
-		wait_for_xmitr(up, UART_LSR_THRE);
-		serial_port_out_sync(port, UART_IER, UART_IER_THRI);
-		udelay(1); /* allow THRE to set */
-		iir1 = serial_port_in(port, UART_IIR);
-		serial_port_out(port, UART_IER, 0);
-		serial_port_out_sync(port, UART_IER, UART_IER_THRI);
-		udelay(1); /* allow a working UART time to re-assert THRE */
-		iir = serial_port_in(port, UART_IIR);
-		serial_port_out(port, UART_IER, 0);
-
-		uart_port_unlock_irqrestore(port, flags);
-
-		if (port->irqflags & IRQF_SHARED)
-			enable_irq(port->irq);
-
-		/*
-		 * If the interrupt is not reasserted, or we otherwise
-		 * don't trust the iir, setup a timer to kick the UART
-		 * on a regular basis.
-		 */
-		if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) ||
-		    up->port.flags & UPF_BUG_THRE) {
-			up->bugs |= UART_BUG_THRE;
-		}
-	}
+	serial8250_THRE_test(port);
 
 	up->ops->setup_timer(up);
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 16/33] serial: 8250: extract serial8250_initialize()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (14 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 15/33] serial: 8250: extract serial8250_THRE_test() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:19   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts() Jiri Slaby (SUSE)
                   ` (16 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_startup() initializes the ports in the middle of the
function. This code can be separated to serial8250_initialize(), so that
serial8250_do_startup() can be readable again.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 103 ++++++++++++++--------------
 1 file changed, 50 insertions(+), 53 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 5466286bb44f..6851c197b31d 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2247,13 +2247,59 @@ static void serial8250_THRE_test(struct uart_port *port)
 		up->bugs |= UART_BUG_THRE;
 }
 
-int serial8250_do_startup(struct uart_port *port)
+static void serial8250_initialize(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
 	unsigned long flags;
-	unsigned char iir;
+	bool lsr_TEMT, iir_NOINT;
+
+	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
+
+	uart_port_lock_irqsave(port, &flags);
+	if (port->flags & UPF_FOURPORT) {
+		if (!port->irq)
+			port->mctrl |= TIOCM_OUT1;
+	} else {
+		/* Most PC uarts need OUT2 raised to enable interrupts. */
+		if (port->irq)
+			port->mctrl |= TIOCM_OUT2;
+	}
+
+	serial8250_set_mctrl(port, port->mctrl);
+
+	/*
+	 * Serial over Lan (SoL) hack:
+	 * Intel 8257x Gigabit ethernet chips have a 16550 emulation, to be used for Serial Over
+	 * Lan.  Those chips take a longer time than a normal serial device to signalize that a
+	 * transmission data was queued. Due to that, the above test generally fails. One solution
+	 * would be to delay the reading of iir. However, this is not reliable, since the timeout is
+	 * variable. So, let's just don't test if we receive TX irq.  This way, we'll never enable
+	 * UART_BUG_TXEN.
+	 */
+	if (!(port->quirks & UPQ_NO_TXEN_TEST)) {
+		/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
+		serial_port_out(port, UART_IER, UART_IER_THRI);
+		lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
+		iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
+		serial_port_out(port, UART_IER, 0);
+
+		if (lsr_TEMT && iir_NOINT) {
+			if (!(up->bugs & UART_BUG_TXEN)) {
+				up->bugs |= UART_BUG_TXEN;
+				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
+			}
+		} else {
+			up->bugs &= ~UART_BUG_TXEN;
+		}
+	}
+
+	uart_port_unlock_irqrestore(port, flags);
+}
+
+int serial8250_do_startup(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
 	int retval;
-	u16 lsr;
 
 	if (!port->fifosize)
 		port->fifosize = uart_config[port->type].fifo_size;
@@ -2310,56 +2356,7 @@ int serial8250_do_startup(struct uart_port *port)
 
 	up->ops->setup_timer(up);
 
-	/*
-	 * Now, initialize the UART
-	 */
-	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
-
-	uart_port_lock_irqsave(port, &flags);
-	if (up->port.flags & UPF_FOURPORT) {
-		if (!up->port.irq)
-			up->port.mctrl |= TIOCM_OUT1;
-	} else
-		/*
-		 * Most PC uarts need OUT2 raised to enable interrupts.
-		 */
-		if (port->irq)
-			up->port.mctrl |= TIOCM_OUT2;
-
-	serial8250_set_mctrl(port, port->mctrl);
-
-	/*
-	 * Serial over Lan (SoL) hack:
-	 * Intel 8257x Gigabit ethernet chips have a 16550 emulation, to be
-	 * used for Serial Over Lan.  Those chips take a longer time than a
-	 * normal serial device to signalize that a transmission data was
-	 * queued. Due to that, the above test generally fails. One solution
-	 * would be to delay the reading of iir. However, this is not
-	 * reliable, since the timeout is variable. So, let's just don't
-	 * test if we receive TX irq.  This way, we'll never enable
-	 * UART_BUG_TXEN.
-	 */
-	if (!(up->port.quirks & UPQ_NO_TXEN_TEST)) {
-		/*
-		 * Do a quick test to see if we receive an interrupt when we
-		 * enable the TX irq.
-		 */
-		serial_port_out(port, UART_IER, UART_IER_THRI);
-		lsr = serial_port_in(port, UART_LSR);
-		iir = serial_port_in(port, UART_IIR);
-		serial_port_out(port, UART_IER, 0);
-
-		if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
-			if (!(up->bugs & UART_BUG_TXEN)) {
-				up->bugs |= UART_BUG_TXEN;
-				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
-			}
-		} else {
-			up->bugs &= ~UART_BUG_TXEN;
-		}
-	}
-
-	uart_port_unlock_irqrestore(port, flags);
+	serial8250_initialize(port);
 
 	/*
 	 * Clear the interrupt registers again for luck, and clear the
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (15 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 16/33] serial: 8250: extract serial8250_initialize() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:27   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 18/33] serial: 8250: extract serial8250_set_mini() Jiri Slaby (SUSE)
                   ` (15 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

On three places in 8250_port.c, the interrupts are cleared by reading 4
registers. Extract this to a separate function:
serial8250_clear_interrupts(). And call it from all the places.

Note autoconfig_irq() now uses serial_port_in() instead of serial_in().
But they are the same, in fact (modulo parameter).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 6851c197b31d..a73f4db22feb 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -705,6 +705,15 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
 	serial8250_rpm_put(p);
 }
 
+/* Clear the interrupt registers. */
+static void serial8250_clear_interrupts(struct uart_port *port)
+{
+	serial_port_in(port, UART_LSR);
+	serial_port_in(port, UART_RX);
+	serial_port_in(port, UART_IIR);
+	serial_port_in(port, UART_MSR);
+}
+
 static void serial8250_clear_IER(struct uart_8250_port *up)
 {
 	if (up->capabilities & UART_CAP_UUE)
@@ -1275,10 +1284,7 @@ static void autoconfig_irq(struct uart_8250_port *up)
 	uart_port_lock_irq(port);
 	serial_out(up, UART_IER, UART_IER_ALL_INTR);
 	uart_port_unlock_irq(port);
-	serial_in(up, UART_LSR);
-	serial_in(up, UART_RX);
-	serial_in(up, UART_IIR);
-	serial_in(up, UART_MSR);
+	serial8250_clear_interrupts(port);
 	serial_out(up, UART_TX, 0xFF);
 	udelay(20);
 	irq = probe_irq_off(irqs);
@@ -2322,13 +2328,7 @@ int serial8250_do_startup(struct uart_port *port)
 	 */
 	serial8250_clear_fifos(up);
 
-	/*
-	 * Clear the interrupt registers.
-	 */
-	serial_port_in(port, UART_LSR);
-	serial_port_in(port, UART_RX);
-	serial_port_in(port, UART_IIR);
-	serial_port_in(port, UART_MSR);
+	serial8250_clear_interrupts(port);
 
 	/*
 	 * At this point, there's no way the LSR could still be 0xff;
@@ -2363,10 +2363,7 @@ int serial8250_do_startup(struct uart_port *port)
 	 * saved flags to avoid getting false values from polling
 	 * routines or the previous session.
 	 */
-	serial_port_in(port, UART_LSR);
-	serial_port_in(port, UART_RX);
-	serial_port_in(port, UART_IIR);
-	serial_port_in(port, UART_MSR);
+	serial8250_clear_interrupts(port);
 	up->lsr_saved_flags = 0;
 	up->msr_saved_flags = 0;
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 18/33] serial: 8250: extract serial8250_set_mini()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (16 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:29   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed() Jiri Slaby (SUSE)
                   ` (14 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of CSIZE for UART_CAP_MINI ports.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index a73f4db22feb..edfbaa6b7a1b 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2670,6 +2670,22 @@ void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk)
 }
 EXPORT_SYMBOL_GPL(serial8250_update_uartclk);
 
+static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	if (!(up->capabilities & UART_CAP_MINI))
+		return;
+
+	termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR);
+
+	tcflag_t csize = termios->c_cflag & CSIZE;
+	if (csize == CS5 || csize == CS6) {
+		termios->c_cflag &= ~CSIZE;
+		termios->c_cflag |= CS7;
+	}
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2679,14 +2695,8 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int baud, quot, frac = 0;
 
-	if (up->capabilities & UART_CAP_MINI) {
-		termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR);
-		if ((termios->c_cflag & CSIZE) == CS5 ||
-		    (termios->c_cflag & CSIZE) == CS6)
-			termios->c_cflag = (termios->c_cflag & ~CSIZE) | CS7;
-	}
+	serial8250_set_mini(port, termios);
 	cval = serial8250_compute_lcr(up, termios->c_cflag);
-
 	baud = serial8250_get_baud_rate(port, termios, old);
 	quot = serial8250_get_divisor(port, baud, &frac);
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (17 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 18/33] serial: 8250: extract serial8250_set_mini() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:34   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 20/33] serial: 8250: extract serial8250_set_afe() Jiri Slaby (SUSE)
                   ` (13 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of trigger level for slow speeds.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index edfbaa6b7a1b..52385314c426 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2686,6 +2686,24 @@ static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios
 	}
 }
 
+static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct ktermios *termios,
+						  unsigned int baud)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	if (!(up->capabilities & UART_CAP_FIFO))
+		return;
+	if (port->fifosize <= 1)
+		return;
+	if (baud >= 2400)
+		return;
+	if (up->dma)
+		return;
+
+	up->fcr &= ~UART_FCR_TRIGGER_MASK;
+	up->fcr |= UART_FCR_TRIGGER_1;
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2710,13 +2728,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_port_lock_irqsave(port, &flags);
 
 	up->lcr = cval;					/* Save computed LCR */
-
-	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-		if (baud < 2400 && !up->dma) {
-			up->fcr &= ~UART_FCR_TRIGGER_MASK;
-			up->fcr |= UART_FCR_TRIGGER_1;
-		}
-	}
+	serial8250_set_trigger_for_slow_speed(port, termios, baud);
 
 	/*
 	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 20/33] serial: 8250: extract serial8250_set_afe()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (18 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:35   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores Jiri Slaby (SUSE)
                   ` (12 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of MCR for UART_CAP_AFE ports.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 32 +++++++++++++++--------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 52385314c426..b15371838366 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2704,6 +2704,22 @@ static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct
 	up->fcr |= UART_FCR_TRIGGER_1;
 }
 
+/*
+ * MCR-based auto flow control. When AFE is enabled, RTS will be deasserted when the receive FIFO
+ * contains more characters than the trigger, or the MCR RTS bit is cleared.
+ */
+static void serial8250_set_afe(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	if (!(up->capabilities & UART_CAP_AFE))
+		return;
+
+	up->mcr &= ~UART_MCR_AFE;
+	if (termios->c_cflag & CRTSCTS)
+		up->mcr |= UART_MCR_AFE;
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2729,21 +2745,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	up->lcr = cval;					/* Save computed LCR */
 	serial8250_set_trigger_for_slow_speed(port, termios, baud);
-
-	/*
-	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
-	 * deasserted when the receive FIFO contains more characters than
-	 * the trigger, or the MCR RTS bit is cleared.
-	 */
-	if (up->capabilities & UART_CAP_AFE) {
-		up->mcr &= ~UART_MCR_AFE;
-		if (termios->c_cflag & CRTSCTS)
-			up->mcr |= UART_MCR_AFE;
-	}
-
-	/*
-	 * Update the per-port timeout.
-	 */
+	serial8250_set_afe(port, termios);
 	uart_update_timeout(port, termios->c_cflag, baud);
 
 	/*
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (19 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 20/33] serial: 8250: extract serial8250_set_afe() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:43   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 22/33] serial: 8250: extract serial8250_set_ier() Jiri Slaby (SUSE)
                   ` (11 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of ignore_status_mask and read_status_mask.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 67 ++++++++++++++---------------
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index b15371838366..6bb7f004d607 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2720,6 +2720,38 @@ static void serial8250_set_afe(struct uart_port *port, struct ktermios *termios)
 		up->mcr |= UART_MCR_AFE;
 }
 
+static void serial8250_set_errors_and_ignores(struct uart_port *port, struct ktermios *termios)
+{
+	/*
+	 * Specify which conditions may be considered for error handling and the ignoring of
+	 * characters. The actual ignoring of characters only occurs if the bit is set in
+	 * @ignore_status_mask as well.
+	 */
+	port->read_status_mask = UART_LSR_OE | UART_LSR_DR;
+	if (termios->c_iflag & INPCK)
+		port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
+	if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
+		port->read_status_mask |= UART_LSR_BI;
+
+	/* Characters to ignore */
+	port->ignore_status_mask = 0;
+	if (termios->c_iflag & IGNPAR)
+		port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
+	if (termios->c_iflag & IGNBRK) {
+		port->ignore_status_mask |= UART_LSR_BI;
+		/*
+		 * If we're ignoring parity and break indicators, ignore overruns too (for real raw
+		 * support).
+		 */
+		if (termios->c_iflag & IGNPAR)
+			port->ignore_status_mask |= UART_LSR_OE;
+	}
+
+	/* ignore all characters if CREAD is not set */
+	if ((termios->c_cflag & CREAD) == 0)
+		port->ignore_status_mask |= UART_LSR_DR;
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2747,40 +2779,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	serial8250_set_trigger_for_slow_speed(port, termios, baud);
 	serial8250_set_afe(port, termios);
 	uart_update_timeout(port, termios->c_cflag, baud);
-
-	/*
-	 * Specify which conditions may be considered for error
-	 * handling and the ignoring of characters. The actual
-	 * ignoring of characters only occurs if the bit is set
-	 * in @ignore_status_mask as well.
-	 */
-	port->read_status_mask = UART_LSR_OE | UART_LSR_DR;
-	if (termios->c_iflag & INPCK)
-		port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
-	if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
-		port->read_status_mask |= UART_LSR_BI;
-
-	/*
-	 * Characters to ignore
-	 */
-	port->ignore_status_mask = 0;
-	if (termios->c_iflag & IGNPAR)
-		port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
-	if (termios->c_iflag & IGNBRK) {
-		port->ignore_status_mask |= UART_LSR_BI;
-		/*
-		 * If we're ignoring parity and break indicators,
-		 * ignore overruns too (for real raw support).
-		 */
-		if (termios->c_iflag & IGNPAR)
-			port->ignore_status_mask |= UART_LSR_OE;
-	}
-
-	/*
-	 * ignore all characters if CREAD is not set
-	 */
-	if ((termios->c_cflag & CREAD) == 0)
-		port->ignore_status_mask |= UART_LSR_DR;
+	serial8250_set_errors_and_ignores(port, termios);
 
 	/*
 	 * CTS flow control flag and modem status interrupts
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 22/33] serial: 8250: extract serial8250_set_ier()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (20 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:47   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 23/33] serial: 8250: extract serial8250_set_efr() Jiri Slaby (SUSE)
                   ` (10 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of IER.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 31 ++++++++++++++++-------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 6bb7f004d607..2c045a4369fc 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2752,6 +2752,22 @@ static void serial8250_set_errors_and_ignores(struct uart_port *port, struct kte
 		port->ignore_status_mask |= UART_LSR_DR;
 }
 
+static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	/* CTS flow control flag and modem status interrupts */
+	up->ier &= ~UART_IER_MSI;
+	if (!(up->bugs & UART_BUG_NOMSR) && UART_ENABLE_MS(&up->port, termios->c_cflag))
+		up->ier |= UART_IER_MSI;
+	if (up->capabilities & UART_CAP_UUE)
+		up->ier |= UART_IER_UUE;
+	if (up->capabilities & UART_CAP_RTOIE)
+		up->ier |= UART_IER_RTOIE;
+
+	serial_port_out(port, UART_IER, up->ier);
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2780,20 +2796,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	serial8250_set_afe(port, termios);
 	uart_update_timeout(port, termios->c_cflag, baud);
 	serial8250_set_errors_and_ignores(port, termios);
-
-	/*
-	 * CTS flow control flag and modem status interrupts
-	 */
-	up->ier &= ~UART_IER_MSI;
-	if (!(up->bugs & UART_BUG_NOMSR) &&
-			UART_ENABLE_MS(&up->port, termios->c_cflag))
-		up->ier |= UART_IER_MSI;
-	if (up->capabilities & UART_CAP_UUE)
-		up->ier |= UART_IER_UUE;
-	if (up->capabilities & UART_CAP_RTOIE)
-		up->ier |= UART_IER_RTOIE;
-
-	serial_port_out(port, UART_IER, up->ier);
+	serial8250_set_ier(port, termios);
 
 	if (up->capabilities & UART_CAP_EFR) {
 		unsigned char efr = 0;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (21 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 22/33] serial: 8250: extract serial8250_set_ier() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 12:58   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 24/33] serial: 8250: extract serial8250_set_fcr() Jiri Slaby (SUSE)
                   ` (9 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of EFR for UART_CAP_EFR ports.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 2c045a4369fc..0f16398cc86f 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
 	serial_port_out(port, UART_IER, up->ier);
 }
 
+static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	u8 efr_reg = UART_EFR;
+	u8 efr = 0;
+
+	if (!(up->capabilities & UART_CAP_EFR))
+		return;
+
+	/*
+	 * TI16C752/Startech hardware flow control.  FIXME:
+	 * - TI16C752 requires control thresholds to be set.
+	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
+	 */
+	if (termios->c_cflag & CRTSCTS)
+		efr |= UART_EFR_CTS;
+
+	if (port->flags & UPF_EXAR_EFR)
+		efr_reg = UART_XR_EFR;
+
+	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
+	serial_port_out(port, efr_reg, efr);
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2797,24 +2821,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_update_timeout(port, termios->c_cflag, baud);
 	serial8250_set_errors_and_ignores(port, termios);
 	serial8250_set_ier(port, termios);
-
-	if (up->capabilities & UART_CAP_EFR) {
-		unsigned char efr = 0;
-		/*
-		 * TI16C752/Startech hardware flow control.  FIXME:
-		 * - TI16C752 requires control thresholds to be set.
-		 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
-		 */
-		if (termios->c_cflag & CRTSCTS)
-			efr |= UART_EFR_CTS;
-
-		serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
-		if (port->flags & UPF_EXAR_EFR)
-			serial_port_out(port, UART_XR_EFR, efr);
-		else
-			serial_port_out(port, UART_EFR, efr);
-	}
-
+	serial8250_set_efr(port, termios);
 	serial8250_set_divisor(port, baud, quot, frac);
 
 	/*
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 24/33] serial: 8250: extract serial8250_set_fcr()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (22 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 23/33] serial: 8250: extract serial8250_set_efr() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:01   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 25/33] serial: 8250: lcr compute cleanup Jiri Slaby (SUSE)
                   ` (8 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of FCR.

serial8250_do_set_termios() looks sane at this point.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 41 ++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 0f16398cc86f..85b75ff0699e 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2792,6 +2792,30 @@ static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
 	serial_port_out(port, efr_reg, efr);
 }
 
+static void serial8250_set_fcr(struct uart_port *port, struct ktermios *termios)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	bool is_16750 = port->type == PORT_16750;
+
+	if (is_16750)
+		serial_port_out(port, UART_FCR, up->fcr);
+
+	/*
+	 * LCR DLAB must be reset to enable 64-byte FIFO mode. If the FCR is written without DLAB
+	 * set, this mode will be disabled.
+	 */
+	serial_port_out(port, UART_LCR, up->lcr);
+
+	if (is_16750)
+		return;
+
+	/* emulated UARTs (Lucent Venus 167x) need two steps */
+	if (up->fcr & UART_FCR_ENABLE_FIFO)
+		serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
+
+	serial_port_out(port, UART_FCR, up->fcr);
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2823,22 +2847,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	serial8250_set_ier(port, termios);
 	serial8250_set_efr(port, termios);
 	serial8250_set_divisor(port, baud, quot, frac);
-
-	/*
-	 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
-	 * is written without DLAB set, this mode will be disabled.
-	 */
-	if (port->type == PORT_16750)
-		serial_port_out(port, UART_FCR, up->fcr);
-
-	serial_port_out(port, UART_LCR, up->lcr);	/* reset DLAB */
-	if (port->type != PORT_16750) {
-		/* emulated UARTs (Lucent Venus 167x) need two steps */
-		if (up->fcr & UART_FCR_ENABLE_FIFO)
-			serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
-		serial_port_out(port, UART_FCR, up->fcr);	/* set fcr */
-	}
+	serial8250_set_fcr(port, termios);
 	serial8250_set_mctrl(port, port->mctrl);
+
 	uart_port_unlock_irqrestore(port, flags);
 	serial8250_rpm_put(up);
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 25/33] serial: 8250: lcr compute cleanup
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (23 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 24/33] serial: 8250: extract serial8250_set_fcr() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:03   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor() Jiri Slaby (SUSE)
                   ` (7 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

* use 'lcr' as variable containing the "computed value" (and not 'cval')
* use 'u8' for the type (and not 'unsigned char')
* drop useless comment

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 85b75ff0699e..2af89038e50e 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2547,23 +2547,20 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
 	return serial8250_do_get_divisor(port, baud, frac);
 }
 
-static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
-					    tcflag_t c_cflag)
+static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, tcflag_t c_cflag)
 {
-	unsigned char cval;
-
-	cval = UART_LCR_WLEN(tty_get_char_size(c_cflag));
+	u8 lcr = UART_LCR_WLEN(tty_get_char_size(c_cflag));
 
 	if (c_cflag & CSTOPB)
-		cval |= UART_LCR_STOP;
+		lcr |= UART_LCR_STOP;
 	if (c_cflag & PARENB)
-		cval |= UART_LCR_PARITY;
+		lcr |= UART_LCR_PARITY;
 	if (!(c_cflag & PARODD))
-		cval |= UART_LCR_EPAR;
+		lcr |= UART_LCR_EPAR;
 	if (c_cflag & CMSPAR)
-		cval |= UART_LCR_SPAR;
+		lcr |= UART_LCR_SPAR;
 
-	return cval;
+	return lcr;
 }
 
 void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
@@ -2821,12 +2818,12 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
-	unsigned char cval;
 	unsigned long flags;
 	unsigned int baud, quot, frac = 0;
+	u8 lcr;
 
 	serial8250_set_mini(port, termios);
-	cval = serial8250_compute_lcr(up, termios->c_cflag);
+	lcr = serial8250_compute_lcr(up, termios->c_cflag);
 	baud = serial8250_get_baud_rate(port, termios, old);
 	quot = serial8250_get_divisor(port, baud, &frac);
 
@@ -2839,7 +2836,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	serial8250_rpm_get(up);
 	uart_port_lock_irqsave(port, &flags);
 
-	up->lcr = cval;					/* Save computed LCR */
+	up->lcr = lcr;
 	serial8250_set_trigger_for_slow_speed(port, termios, baud);
 	serial8250_set_afe(port, termios);
 	uart_update_timeout(port, termios->c_cflag, baud);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (24 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 25/33] serial: 8250: lcr compute cleanup Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:04   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info() Jiri Slaby (SUSE)
                   ` (6 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

'frac' is not used in the generic implementation of get_divisor. Drop it
from there. (Only some port->get_divisor() compute that and receive it
then to port->set_divisor()).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 2af89038e50e..6363915a1787 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2481,9 +2481,7 @@ static void serial8250_flush_buffer(struct uart_port *port)
 		serial8250_tx_dma_flush(up);
 }
 
-static unsigned int serial8250_do_get_divisor(struct uart_port *port,
-					      unsigned int baud,
-					      unsigned int *frac)
+static unsigned int serial8250_do_get_divisor(struct uart_port *port, unsigned int baud)
 {
 	upf_t magic_multiplier = port->flags & UPF_MAGIC_MULTIPLIER;
 	struct uart_8250_port *up = up_to_u8250p(port);
@@ -2544,7 +2542,7 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
 	if (port->get_divisor)
 		return port->get_divisor(port, baud, frac);
 
-	return serial8250_do_get_divisor(port, baud, frac);
+	return serial8250_do_get_divisor(port, baud);
 }
 
 static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, tcflag_t c_cflag)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info()
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (25 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:09   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 28/33] serial: 8250: remove debug prints from ISR Jiri Slaby (SUSE)
                   ` (5 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

This find-or-create-irq part of the serial_link_irq_chain()'s code is
logically bounded and self-standing. For easier-to-follow code flow,
extract the code to a separate function:
serial_get_or_create_irq_info().

This allows for an easier found-an-irq handling -- simple jump to the
'unlock' label and return. That results in one less 'if' levels.

Note when using guard()s in the upcoming patchset, the label can dropped
altogether.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_core.c | 37 ++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 7a6050f1c094..d42ceb6ffdc2 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -129,11 +129,15 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
 	}
 }
 
-static int serial_link_irq_chain(struct uart_8250_port *up)
+/*
+ * Either:
+ * - find the corresponding info in the hashtable and return it, or
+ * - allocate a new one, add it to the hashtable and return it.
+ */
+static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up)
 {
 	struct hlist_head *h;
 	struct irq_info *i;
-	int ret;
 
 	mutex_lock(&hash_mutex);
 
@@ -141,20 +145,31 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
 
 	hlist_for_each_entry(i, h, node)
 		if (i->irq == up->port.irq)
-			break;
+			goto unlock;
 
+	i = kzalloc(sizeof(*i), GFP_KERNEL);
 	if (i == NULL) {
-		i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
-		if (i == NULL) {
-			mutex_unlock(&hash_mutex);
-			return -ENOMEM;
-		}
-		spin_lock_init(&i->lock);
-		i->irq = up->port.irq;
-		hlist_add_head(&i->node, h);
+		i = ERR_PTR(-ENOMEM);
+		goto unlock;
 	}
+	spin_lock_init(&i->lock);
+	i->irq = up->port.irq;
+	hlist_add_head(&i->node, h);
+unlock:
 	mutex_unlock(&hash_mutex);
 
+	return i;
+}
+
+static int serial_link_irq_chain(struct uart_8250_port *up)
+{
+	struct irq_info *i;
+	int ret;
+
+	i = serial_get_or_create_irq_info(up);
+	if (IS_ERR(i))
+		return PTR_ERR(i);
+
 	spin_lock_irq(&i->lock);
 
 	if (i->head) {
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 28/33] serial: 8250: remove debug prints from ISR
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (26 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info() Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:09   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Jiri Slaby (SUSE)
                   ` (4 subsequent siblings)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

These are useless, we have tracing nowadays.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_core.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index d42ceb6ffdc2..2bac9c7827de 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -71,8 +71,6 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
 	struct list_head *l, *end = NULL;
 	int pass_counter = 0, handled = 0;
 
-	pr_debug("%s(%d): start\n", __func__, irq);
-
 	spin_lock(&i->lock);
 
 	l = i->head;
@@ -97,8 +95,6 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
 
 	spin_unlock(&i->lock);
 
-	pr_debug("%s(%d): end\n", __func__, irq);
-
 	return IRQ_RETVAL(handled);
 }
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (27 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 28/33] serial: 8250: remove debug prints from ISR Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:10   ` Ilpo Järvinen
  2025-06-17 11:32   ` Maciej W. Rozycki
  2025-06-11 10:03 ` [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Jiri Slaby (SUSE)
                   ` (3 subsequent siblings)
  32 siblings, 2 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

DEBUG_AUTOCONF() is always disabled (by "#if 0"), so one would need to
recompile the kernel to use it. And even if they did, they would find
out it is broken anyway:
  error: variable 'scratch' is used uninitialized whenever 'if' condition is false

Drop it.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 39 ++---------------------------
 1 file changed, 2 insertions(+), 37 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 6363915a1787..e93bfdac3d0e 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -38,15 +38,6 @@
 
 #include "8250.h"
 
-/*
- * Debugging.
- */
-#if 0
-#define DEBUG_AUTOCONF(fmt...)	printk(fmt)
-#else
-#define DEBUG_AUTOCONF(fmt...)	do { } while (0)
-#endif
-
 /*
  * Here we define the default xmit fifo size used for each type of UART.
  */
@@ -825,8 +816,6 @@ static void autoconfig_has_efr(struct uart_8250_port *up)
 	id3 = serial_icr_read(up, UART_ID3);
 	rev = serial_icr_read(up, UART_REV);
 
-	DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
-
 	if (id1 == 0x16 && id2 == 0xC9 &&
 	    (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
 		up->port.type = PORT_16C950;
@@ -850,7 +839,6 @@ static void autoconfig_has_efr(struct uart_8250_port *up)
 	 *  0x14 - XR16C854.
 	 */
 	id1 = autoconfig_read_divisor_id(up);
-	DEBUG_AUTOCONF("850id=%04x ", id1);
 
 	id2 = id1 >> 8;
 	if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
@@ -937,7 +925,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
 	if (serial_in(up, UART_EFR) == 0) {
 		serial_out(up, UART_EFR, 0xA8);
 		if (serial_in(up, UART_EFR) != 0) {
-			DEBUG_AUTOCONF("EFRv1 ");
 			up->port.type = PORT_16650;
 			up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
 		} else {
@@ -950,8 +937,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
 
 			if (status1 == UART_IIR_FIFO_ENABLED_16750)
 				up->port.type = PORT_16550A_FSL64;
-			else
-				DEBUG_AUTOCONF("Motorola 8xxx DUART ");
 		}
 		serial_out(up, UART_EFR, 0);
 		return;
@@ -963,7 +948,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
 	 */
 	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
 	if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
-		DEBUG_AUTOCONF("EFRv2 ");
 		autoconfig_has_efr(up);
 		return;
 	}
@@ -1026,8 +1010,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
 
 	serial_out(up, UART_LCR, 0);
 
-	DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
-
 	if (status1 == UART_IIR_FIFO_ENABLED_16550A &&
 	    status2 == UART_IIR_FIFO_ENABLED_16750) {
 		up->port.type = PORT_16750;
@@ -1056,17 +1038,10 @@ static void autoconfig_16550a(struct uart_8250_port *up)
 			 * It's an Xscale.
 			 * We'll leave the UART_IER_UUE bit set to 1 (enabled).
 			 */
-			DEBUG_AUTOCONF("Xscale ");
 			up->port.type = PORT_XSCALE;
 			up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE;
 			return;
 		}
-	} else {
-		/*
-		 * If we got here we couldn't force the IER_UUE bit to 0.
-		 * Log it and continue.
-		 */
-		DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
 	}
 	serial_out(up, UART_IER, iersave);
 
@@ -1098,9 +1073,6 @@ static void autoconfig(struct uart_8250_port *up)
 	if (!port->iobase && !port->mapbase && !port->membase)
 		return;
 
-	DEBUG_AUTOCONF("%s: autoconf (0x%04lx, 0x%p): ",
-		       port->name, port->iobase, port->membase);
-
 	/*
 	 * We really do need global IRQs disabled here - we're going to
 	 * be frobbing the chips IRQ enable register to see if it exists.
@@ -1147,9 +1119,7 @@ static void autoconfig(struct uart_8250_port *up)
 			 * We failed; there's nothing here
 			 */
 			uart_port_unlock_irqrestore(port, flags);
-			DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
-				       scratch2, scratch3);
-			goto out;
+			return;
 		}
 	}
 
@@ -1171,9 +1141,7 @@ static void autoconfig(struct uart_8250_port *up)
 		serial8250_out_MCR(up, save_mcr);
 		if (status1 != (UART_MSR_DCD | UART_MSR_CTS)) {
 			uart_port_unlock_irqrestore(port, flags);
-			DEBUG_AUTOCONF("LOOP test failed (%02x) ",
-				       status1);
-			goto out;
+			return;
 		}
 	}
 
@@ -1241,9 +1209,6 @@ static void autoconfig(struct uart_8250_port *up)
 		dev_warn(port->dev, "detected caps %08x should be %08x\n",
 			 old_capabilities, up->capabilities);
 	}
-out:
-	DEBUG_AUTOCONF("iir=%d ", scratch);
-	DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name);
 }
 
 static void autoconfig_irq(struct uart_8250_port *up)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (28 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:21   ` Ilpo Järvinen
  2025-06-18  5:48   ` Andy Shevchenko
  2025-06-11 10:03 ` [PATCH 31/33] serial: 8250: invert condition to avoid a goto label Jiri Slaby (SUSE)
                   ` (2 subsequent siblings)
  32 siblings, 2 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

There is no point in a long 'if' in serial8250_register_8250_port() to
just return ENOSPC for PORT_8250_CIR ports. Invert the condition and
return immediately.

'gpios' variable was moved to its set location.

And return ENODEV instead of ENOSPC. The latter is a leftover from the
previous find-uart 'if'. The former makes a lot more sense in this case.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_core.c | 253 ++++++++++++++--------------
 1 file changed, 127 insertions(+), 126 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 2bac9c7827de..10f25bae9f46 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -725,139 +725,140 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 		nr_uarts++;
 	}
 
-	if (uart->port.type != PORT_8250_CIR) {
-		struct mctrl_gpios *gpios;
-
-		if (uart->port.dev)
-			uart_remove_one_port(&serial8250_reg, &uart->port);
-
-		uart->port.ctrl_id	= up->port.ctrl_id;
-		uart->port.port_id	= up->port.port_id;
-		uart->port.iobase       = up->port.iobase;
-		uart->port.membase      = up->port.membase;
-		uart->port.irq          = up->port.irq;
-		uart->port.irqflags     = up->port.irqflags;
-		uart->port.uartclk      = up->port.uartclk;
-		uart->port.fifosize     = up->port.fifosize;
-		uart->port.regshift     = up->port.regshift;
-		uart->port.iotype       = up->port.iotype;
-		uart->port.flags        = up->port.flags | UPF_BOOT_AUTOCONF;
-		uart->bugs		= up->bugs;
-		uart->port.mapbase      = up->port.mapbase;
-		uart->port.mapsize      = up->port.mapsize;
-		uart->port.private_data = up->port.private_data;
-		uart->tx_loadsz		= up->tx_loadsz;
-		uart->capabilities	= up->capabilities;
-		uart->port.throttle	= up->port.throttle;
-		uart->port.unthrottle	= up->port.unthrottle;
-		uart->port.rs485_config	= up->port.rs485_config;
-		uart->port.rs485_supported = up->port.rs485_supported;
-		uart->port.rs485	= up->port.rs485;
-		uart->rs485_start_tx	= up->rs485_start_tx;
-		uart->rs485_stop_tx	= up->rs485_stop_tx;
-		uart->lsr_save_mask	= up->lsr_save_mask;
-		uart->dma		= up->dma;
-
-		/* Take tx_loadsz from fifosize if it wasn't set separately */
-		if (uart->port.fifosize && !uart->tx_loadsz)
-			uart->tx_loadsz = uart->port.fifosize;
-
-		if (up->port.dev) {
-			uart->port.dev = up->port.dev;
-			ret = uart_get_rs485_mode(&uart->port);
-			if (ret)
-				goto err;
-		}
+	if (uart->port.type == PORT_8250_CIR) {
+		ret = -ENODEV;
+		goto unlock;
+	}
 
-		if (up->port.flags & UPF_FIXED_TYPE)
-			uart->port.type = up->port.type;
+	if (uart->port.dev)
+		uart_remove_one_port(&serial8250_reg, &uart->port);
+
+	uart->port.ctrl_id	= up->port.ctrl_id;
+	uart->port.port_id	= up->port.port_id;
+	uart->port.iobase       = up->port.iobase;
+	uart->port.membase      = up->port.membase;
+	uart->port.irq          = up->port.irq;
+	uart->port.irqflags     = up->port.irqflags;
+	uart->port.uartclk      = up->port.uartclk;
+	uart->port.fifosize     = up->port.fifosize;
+	uart->port.regshift     = up->port.regshift;
+	uart->port.iotype       = up->port.iotype;
+	uart->port.flags        = up->port.flags | UPF_BOOT_AUTOCONF;
+	uart->bugs		= up->bugs;
+	uart->port.mapbase      = up->port.mapbase;
+	uart->port.mapsize      = up->port.mapsize;
+	uart->port.private_data = up->port.private_data;
+	uart->tx_loadsz		= up->tx_loadsz;
+	uart->capabilities	= up->capabilities;
+	uart->port.throttle	= up->port.throttle;
+	uart->port.unthrottle	= up->port.unthrottle;
+	uart->port.rs485_config	= up->port.rs485_config;
+	uart->port.rs485_supported = up->port.rs485_supported;
+	uart->port.rs485	= up->port.rs485;
+	uart->rs485_start_tx	= up->rs485_start_tx;
+	uart->rs485_stop_tx	= up->rs485_stop_tx;
+	uart->lsr_save_mask	= up->lsr_save_mask;
+	uart->dma		= up->dma;
+
+	/* Take tx_loadsz from fifosize if it wasn't set separately */
+	if (uart->port.fifosize && !uart->tx_loadsz)
+		uart->tx_loadsz = uart->port.fifosize;
+
+	if (up->port.dev) {
+		uart->port.dev = up->port.dev;
+		ret = uart_get_rs485_mode(&uart->port);
+		if (ret)
+			goto err;
+	}
 
-		/*
-		 * Only call mctrl_gpio_init(), if the device has no ACPI
-		 * companion device
-		 */
-		if (!has_acpi_companion(uart->port.dev)) {
-			gpios = mctrl_gpio_init(&uart->port, 0);
-			if (IS_ERR(gpios)) {
-				ret = PTR_ERR(gpios);
-				goto err;
-			} else {
-				uart->gpios = gpios;
-			}
-		}
+	if (up->port.flags & UPF_FIXED_TYPE)
+		uart->port.type = up->port.type;
 
-		serial8250_set_defaults(uart);
-
-		/* Possibly override default I/O functions.  */
-		if (up->port.serial_in)
-			uart->port.serial_in = up->port.serial_in;
-		if (up->port.serial_out)
-			uart->port.serial_out = up->port.serial_out;
-		if (up->port.handle_irq)
-			uart->port.handle_irq = up->port.handle_irq;
-		/*  Possibly override set_termios call */
-		if (up->port.set_termios)
-			uart->port.set_termios = up->port.set_termios;
-		if (up->port.set_ldisc)
-			uart->port.set_ldisc = up->port.set_ldisc;
-		if (up->port.get_mctrl)
-			uart->port.get_mctrl = up->port.get_mctrl;
-		if (up->port.set_mctrl)
-			uart->port.set_mctrl = up->port.set_mctrl;
-		if (up->port.get_divisor)
-			uart->port.get_divisor = up->port.get_divisor;
-		if (up->port.set_divisor)
-			uart->port.set_divisor = up->port.set_divisor;
-		if (up->port.startup)
-			uart->port.startup = up->port.startup;
-		if (up->port.shutdown)
-			uart->port.shutdown = up->port.shutdown;
-		if (up->port.pm)
-			uart->port.pm = up->port.pm;
-		if (up->port.handle_break)
-			uart->port.handle_break = up->port.handle_break;
-		if (up->dl_read)
-			uart->dl_read = up->dl_read;
-		if (up->dl_write)
-			uart->dl_write = up->dl_write;
-
-		if (uart->port.type != PORT_8250_CIR) {
-			if (uart_console_registered(&uart->port))
-				pm_runtime_get_sync(uart->port.dev);
-
-			if (serial8250_isa_config != NULL)
-				serial8250_isa_config(0, &uart->port,
-						&uart->capabilities);
-
-			serial8250_apply_quirks(uart);
-			ret = uart_add_one_port(&serial8250_reg,
-						&uart->port);
-			if (ret)
-				goto err;
-
-			ret = uart->port.line;
+	/*
+	 * Only call mctrl_gpio_init(), if the device has no ACPI
+	 * companion device
+	 */
+	if (!has_acpi_companion(uart->port.dev)) {
+		struct mctrl_gpios *gpios = mctrl_gpio_init(&uart->port, 0);
+		if (IS_ERR(gpios)) {
+			ret = PTR_ERR(gpios);
+			goto err;
 		} else {
-			dev_info(uart->port.dev,
-				"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
-				uart->port.iobase,
-				(unsigned long long)uart->port.mapbase,
-				uart->port.irq);
-
-			ret = 0;
+			uart->gpios = gpios;
 		}
+	}
 
-		if (!uart->lsr_save_mask)
-			uart->lsr_save_mask = LSR_SAVE_FLAGS;	/* Use default LSR mask */
+	serial8250_set_defaults(uart);
+
+	/* Possibly override default I/O functions.  */
+	if (up->port.serial_in)
+		uart->port.serial_in = up->port.serial_in;
+	if (up->port.serial_out)
+		uart->port.serial_out = up->port.serial_out;
+	if (up->port.handle_irq)
+		uart->port.handle_irq = up->port.handle_irq;
+	/*  Possibly override set_termios call */
+	if (up->port.set_termios)
+		uart->port.set_termios = up->port.set_termios;
+	if (up->port.set_ldisc)
+		uart->port.set_ldisc = up->port.set_ldisc;
+	if (up->port.get_mctrl)
+		uart->port.get_mctrl = up->port.get_mctrl;
+	if (up->port.set_mctrl)
+		uart->port.set_mctrl = up->port.set_mctrl;
+	if (up->port.get_divisor)
+		uart->port.get_divisor = up->port.get_divisor;
+	if (up->port.set_divisor)
+		uart->port.set_divisor = up->port.set_divisor;
+	if (up->port.startup)
+		uart->port.startup = up->port.startup;
+	if (up->port.shutdown)
+		uart->port.shutdown = up->port.shutdown;
+	if (up->port.pm)
+		uart->port.pm = up->port.pm;
+	if (up->port.handle_break)
+		uart->port.handle_break = up->port.handle_break;
+	if (up->dl_read)
+		uart->dl_read = up->dl_read;
+	if (up->dl_write)
+		uart->dl_write = up->dl_write;
 
-		/* Initialise interrupt backoff work if required */
-		if (up->overrun_backoff_time_ms > 0) {
-			uart->overrun_backoff_time_ms =
-				up->overrun_backoff_time_ms;
-			INIT_DELAYED_WORK(&uart->overrun_backoff,
-					serial_8250_overrun_backoff_work);
-		} else {
-			uart->overrun_backoff_time_ms = 0;
-		}
+	if (uart->port.type != PORT_8250_CIR) {
+		if (uart_console_registered(&uart->port))
+			pm_runtime_get_sync(uart->port.dev);
+
+		if (serial8250_isa_config != NULL)
+			serial8250_isa_config(0, &uart->port,
+					&uart->capabilities);
+
+		serial8250_apply_quirks(uart);
+		ret = uart_add_one_port(&serial8250_reg,
+					&uart->port);
+		if (ret)
+			goto err;
+
+		ret = uart->port.line;
+	} else {
+		dev_info(uart->port.dev,
+			"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
+			uart->port.iobase,
+			(unsigned long long)uart->port.mapbase,
+			uart->port.irq);
+
+		ret = 0;
+	}
+
+	if (!uart->lsr_save_mask)
+		uart->lsr_save_mask = LSR_SAVE_FLAGS;	/* Use default LSR mask */
+
+	/* Initialise interrupt backoff work if required */
+	if (up->overrun_backoff_time_ms > 0) {
+		uart->overrun_backoff_time_ms =
+			up->overrun_backoff_time_ms;
+		INIT_DELAYED_WORK(&uart->overrun_backoff,
+				serial_8250_overrun_backoff_work);
+	} else {
+		uart->overrun_backoff_time_ms = 0;
 	}
 
 unlock:
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 31/33] serial: 8250: invert condition to avoid a goto label
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (29 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-18  5:45   ` Andy Shevchenko
  2025-06-11 10:03 ` [PATCH 32/33] serial: 8250: use hashtable Jiri Slaby (SUSE)
  2025-06-11 10:03 ` [PATCH 33/33] serial: 8250_omap: use uart_port pointer when available Jiri Slaby (SUSE)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Use of "goto" in this code is frowned upon:
 +-------
 |if (port->type == PORT_UNKNOWN)
 |  goto out_unlock;
 |CODE;
 |out_unlock:
 +-------

Instead, simply do:
 +-------
 |if (port->type != PORT_UNKNOWN)
 |  CODE;
 +-------

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index e93bfdac3d0e..48c30e158cb8 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1184,19 +1184,17 @@ static void autoconfig(struct uart_8250_port *up)
 	up->capabilities = uart_config[port->type].flags;
 	up->tx_loadsz = uart_config[port->type].tx_loadsz;
 
-	if (port->type == PORT_UNKNOWN)
-		goto out_unlock;
-
-	/*
-	 * Reset the UART.
-	 */
-	rsa_reset(up);
-	serial8250_out_MCR(up, save_mcr);
-	serial8250_clear_fifos(up);
-	serial_in(up, UART_RX);
-	serial8250_clear_IER(up);
+	if (port->type != PORT_UNKNOWN) {
+		/*
+		 * Reset the UART.
+		 */
+		rsa_reset(up);
+		serial8250_out_MCR(up, save_mcr);
+		serial8250_clear_fifos(up);
+		serial_in(up, UART_RX);
+		serial8250_clear_IER(up);
+	}
 
-out_unlock:
 	uart_port_unlock_irqrestore(port, flags);
 
 	/*
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 32/33] serial: 8250: use hashtable
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (30 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 31/33] serial: 8250: invert condition to avoid a goto label Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  2025-06-11 13:25   ` Ilpo Järvinen
  2025-06-11 10:03 ` [PATCH 33/33] serial: 8250_omap: use uart_port pointer when available Jiri Slaby (SUSE)
  32 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Instead of open-coding the hash table, use the one provided by
hashtable.h. The semantics is the same, except the code needs not to
compute the hash bucket on its own.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_core.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 10f25bae9f46..a6ecb8575da4 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -13,6 +13,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/hashtable.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/ioport.h>
@@ -47,8 +48,8 @@ struct irq_info {
 	struct list_head	*head;
 };
 
-#define NR_IRQ_HASH		32	/* Can be adjusted later */
-static struct hlist_head irq_lists[NR_IRQ_HASH];
+#define IRQ_HASH_BITS		5	/* Can be adjusted later */
+static DEFINE_HASHTABLE(irq_lists, IRQ_HASH_BITS);
 static DEFINE_MUTEX(hash_mutex);	/* Used to walk the hash */
 
 /*
@@ -75,11 +76,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
 
 	l = i->head;
 	do {
-		struct uart_8250_port *up;
-		struct uart_port *port;
-
-		up = list_entry(l, struct uart_8250_port, list);
-		port = &up->port;
+		struct uart_8250_port *up = list_entry(l, struct uart_8250_port, list);
+		struct uart_port *port = &up->port;
 
 		if (port->handle_irq(port)) {
 			handled = 1;
@@ -132,14 +130,11 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
  */
 static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up)
 {
-	struct hlist_head *h;
 	struct irq_info *i;
 
 	mutex_lock(&hash_mutex);
 
-	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
-
-	hlist_for_each_entry(i, h, node)
+	hash_for_each_possible(irq_lists, i, node, up->port.irq)
 		if (i->irq == up->port.irq)
 			goto unlock;
 
@@ -150,7 +145,7 @@ static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_por
 	}
 	spin_lock_init(&i->lock);
 	i->irq = up->port.irq;
-	hlist_add_head(&i->node, h);
+	hash_add(irq_lists, &i->node, i->irq);
 unlock:
 	mutex_unlock(&hash_mutex);
 
@@ -189,13 +184,10 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
 static void serial_unlink_irq_chain(struct uart_8250_port *up)
 {
 	struct irq_info *i;
-	struct hlist_head *h;
 
 	mutex_lock(&hash_mutex);
 
-	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
-
-	hlist_for_each_entry(i, h, node)
+	hash_for_each_possible(irq_lists, i, node, up->port.irq)
 		if (i->irq == up->port.irq)
 			break;
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 33/33] serial: 8250_omap: use uart_port pointer when available
  2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
                   ` (31 preceding siblings ...)
  2025-06-11 10:03 ` [PATCH 32/33] serial: 8250: use hashtable Jiri Slaby (SUSE)
@ 2025-06-11 10:03 ` Jiri Slaby (SUSE)
  32 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-06-11 10:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

There are unnecessary "up->port." accesses on many places in 8250_omap.
"port" is avalable on most places, so instead simply use "port->".

And make port available in omap8250_restore_regs() too. It's used on
many places in there.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_omap.c | 53 +++++++++++++++--------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index 72ae08d6204f..6707f55bdbe7 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -176,7 +176,7 @@ static u32 uart_read(struct omap8250_priv *priv, u32 reg)
 static void __omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
-	struct omap8250_priv *priv = up->port.private_data;
+	struct omap8250_priv *priv = port->private_data;
 	u8 lcr;
 
 	serial8250_do_set_mctrl(port, mctrl);
@@ -303,12 +303,13 @@ static void omap8250_update_mdr1(struct uart_8250_port *up,
 
 static void omap8250_restore_regs(struct uart_8250_port *up)
 {
-	struct omap8250_priv *priv = up->port.private_data;
+	struct uart_port *port = &up->port;
+	struct omap8250_priv *priv = port->private_data;
 	struct uart_8250_dma	*dma = up->dma;
 	u8 mcr = serial8250_in_MCR(up);
 
 	/* Port locked to synchronize UART_IER access against the console. */
-	lockdep_assert_held_once(&up->port.lock);
+	lockdep_assert_held_once(&port->lock);
 
 	if (dma && dma->tx_running) {
 		/*
@@ -359,12 +360,12 @@ static void omap8250_restore_regs(struct uart_8250_port *up)
 
 	omap8250_update_mdr1(up, priv);
 
-	__omap8250_set_mctrl(&up->port, up->port.mctrl);
+	__omap8250_set_mctrl(port, port->mctrl);
 
 	serial_out(up, UART_OMAP_MDR3, priv->mdr3);
 
-	if (up->port.rs485.flags & SER_RS485_ENABLED &&
-	    up->port.rs485_config == serial8250_em485_config)
+	if (port->rs485.flags & SER_RS485_ENABLED &&
+	    port->rs485_config == serial8250_em485_config)
 		serial8250_em485_stop_tx(up, true);
 }
 
@@ -377,7 +378,7 @@ static void omap_8250_set_termios(struct uart_port *port,
 				  const struct ktermios *old)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
-	struct omap8250_priv *priv = up->port.private_data;
+	struct omap8250_priv *priv = port->private_data;
 	unsigned char cval = 0;
 	unsigned int baud;
 
@@ -418,39 +419,39 @@ static void omap_8250_set_termios(struct uart_port *port,
 	 * ignoring of characters only occurs if the bit is set
 	 * in @ignore_status_mask as well.
 	 */
-	up->port.read_status_mask = UART_LSR_OE | UART_LSR_DR;
+	port->read_status_mask = UART_LSR_OE | UART_LSR_DR;
 	if (termios->c_iflag & INPCK)
-		up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
+		port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
 	if (termios->c_iflag & (IGNBRK | PARMRK))
-		up->port.read_status_mask |= UART_LSR_BI;
+		port->read_status_mask |= UART_LSR_BI;
 
 	/*
 	 * Characters to ignore
 	 */
-	up->port.ignore_status_mask = 0;
+	port->ignore_status_mask = 0;
 	if (termios->c_iflag & IGNPAR)
-		up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
+		port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
 	if (termios->c_iflag & IGNBRK) {
-		up->port.ignore_status_mask |= UART_LSR_BI;
+		port->ignore_status_mask |= UART_LSR_BI;
 		/*
 		 * If we're ignoring parity and break indicators,
 		 * ignore overruns too (for real raw support).
 		 */
 		if (termios->c_iflag & IGNPAR)
-			up->port.ignore_status_mask |= UART_LSR_OE;
+			port->ignore_status_mask |= UART_LSR_OE;
 	}
 
 	/*
 	 * ignore all characters if CREAD is not set
 	 */
 	if ((termios->c_cflag & CREAD) == 0)
-		up->port.ignore_status_mask |= UART_LSR_DR;
+		port->ignore_status_mask |= UART_LSR_DR;
 
 	/*
 	 * Modem status interrupts
 	 */
 	up->ier &= ~UART_IER_MSI;
-	if (UART_ENABLE_MS(&up->port, termios->c_cflag))
+	if (UART_ENABLE_MS(port, termios->c_cflag))
 		up->ier |= UART_IER_MSI;
 
 	up->lcr = cval;
@@ -488,15 +489,15 @@ static void omap_8250_set_termios(struct uart_port *port,
 	priv->xoff = termios->c_cc[VSTOP];
 
 	priv->efr = 0;
-	up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
+	port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
 
-	if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW &&
+	if (termios->c_cflag & CRTSCTS && port->flags & UPF_HARD_FLOW &&
 	    !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) &&
 	    !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) {
 		/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */
-		up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
+		port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
 		priv->efr |= UART_EFR_CTS;
-	} else	if (up->port.flags & UPF_SOFT_FLOW) {
+	} else	if (port->flags & UPF_SOFT_FLOW) {
 		/*
 		 * OMAP rx s/w flow control is borked; the transmitter remains
 		 * stuck off even if rx flow control is subsequently disabled
@@ -508,7 +509,7 @@ static void omap_8250_set_termios(struct uart_port *port,
 		 * Transmit XON1, XOFF1
 		 */
 		if (termios->c_iflag & IXOFF) {
-			up->port.status |= UPSTAT_AUTOXOFF;
+			port->status |= UPSTAT_AUTOXOFF;
 			priv->efr |= OMAP_UART_SW_TX;
 		}
 	}
@@ -770,7 +771,7 @@ static int omap_8250_startup(struct uart_port *port)
 		uart_port_unlock_irq(port);
 	}
 
-	enable_irq(up->port.irq);
+	enable_irq(port->irq);
 
 	pm_runtime_mark_last_busy(port->dev);
 	pm_runtime_put_autosuspend(port->dev);
@@ -797,7 +798,7 @@ static void omap_8250_shutdown(struct uart_port *port)
 	up->ier = 0;
 	serial_out(up, UART_IER, 0);
 	uart_port_unlock_irq(port);
-	disable_irq_nosync(up->port.irq);
+	disable_irq_nosync(port->irq);
 	dev_pm_clear_wake_irq(port->dev);
 
 	serial8250_release_dma(up);
@@ -1310,7 +1311,7 @@ static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
 static int omap_8250_dma_handle_irq(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
-	struct omap8250_priv *priv = up->port.private_data;
+	struct omap8250_priv *priv = port->private_data;
 	u16 status;
 	u8 iir;
 
@@ -1332,8 +1333,8 @@ static int omap_8250_dma_handle_irq(struct uart_port *port)
 
 	serial8250_modem_status(up);
 	if (status & UART_LSR_THRE && up->dma->tx_err) {
-		if (uart_tx_stopped(&up->port) ||
-		    kfifo_is_empty(&up->port.state->port.xmit_fifo)) {
+		if (uart_tx_stopped(port) ||
+		    kfifo_is_empty(&port->state->port.xmit_fifo)) {
 			up->dma->tx_err = 0;
 			serial8250_tx_chars(up);
 		} else  {
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper
  2025-06-11 10:02 ` [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Jiri Slaby (SUSE)
@ 2025-06-11 11:13   ` Ilpo Järvinen
  2025-06-23  7:30     ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:13 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Karsten Keil, David Lin,
	Johan Hovold, Alex Elder, Oliver Neukum, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Netdev, greybus-dev,
	linux-staging, linux-usb, linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 8932 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> This code (tty_get -> vhangup -> tty_put) is repeated on few places.
> Introduce a helper similar to tty_port_tty_hangup() (asynchronous) to
> handle even vhangup (synchronous).
> 
> And use it on those places.
> 
> In fact, reuse the tty_port_tty_hangup()'s code and call tty_vhangup()
> depending on a new bool parameter.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>

Nice cleanup. I'm not sure if it's important enough to be mentioned in
Documentation/driver-api/tty/tty_port.rst .

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
> Cc: netdev@vger.kernel.org
> Cc: greybus-dev@lists.linaro.org
> Cc: linux-staging@lists.linux.dev
> Cc: linux-usb@vger.kernel.org
> Cc: linux-bluetooth@vger.kernel.org

> ---
>  drivers/isdn/capi/capi.c         |  8 +-------
>  drivers/staging/greybus/uart.c   |  7 +------
>  drivers/tty/serial/serial_core.c |  7 +------
>  drivers/tty/tty_port.c           | 12 ++++++++----
>  drivers/usb/class/cdc-acm.c      |  7 +------
>  drivers/usb/serial/usb-serial.c  |  7 +------
>  include/linux/tty_port.h         | 12 +++++++++++-
>  net/bluetooth/rfcomm/tty.c       |  7 +------
>  8 files changed, 25 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index 70dee9ad4bae..78e6e7748fb9 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -306,15 +306,9 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)
>  static void capincci_free_minor(struct capincci *np)
>  {
>  	struct capiminor *mp = np->minorp;
> -	struct tty_struct *tty;
>  
>  	if (mp) {
> -		tty = tty_port_tty_get(&mp->port);
> -		if (tty) {
> -			tty_vhangup(tty);
> -			tty_kref_put(tty);
> -		}
> -
> +		tty_port_tty_vhangup(&mp->port);
>  		capiminor_free(mp);
>  	}
>  }
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index 308ed1ca9947..10df5c37c83e 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -916,7 +916,6 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
>  {
>  	struct gb_tty *gb_tty = gb_gbphy_get_data(gbphy_dev);
>  	struct gb_connection *connection = gb_tty->connection;
> -	struct tty_struct *tty;
>  	int ret;
>  
>  	ret = gbphy_runtime_get_sync(gbphy_dev);
> @@ -929,11 +928,7 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
>  	wake_up_all(&gb_tty->wioctl);
>  	mutex_unlock(&gb_tty->mutex);
>  
> -	tty = tty_port_tty_get(&gb_tty->port);
> -	if (tty) {
> -		tty_vhangup(tty);
> -		tty_kref_put(tty);
> -	}
> +	tty_port_tty_vhangup(&gb_tty->port);
>  
>  	gb_connection_disable_rx(connection);
>  	tty_unregister_device(gb_tty_driver, gb_tty->minor);
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 1f7708a91fc6..d6485714eb0f 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -3209,7 +3209,6 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
>  	struct uart_state *state = drv->state + uport->line;
>  	struct tty_port *port = &state->port;
>  	struct uart_port *uart_port;
> -	struct tty_struct *tty;
>  
>  	mutex_lock(&port->mutex);
>  	uart_port = uart_port_check(state);
> @@ -3228,11 +3227,7 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
>  	 */
>  	tty_port_unregister_device(port, drv->tty_driver, uport->line);
>  
> -	tty = tty_port_tty_get(port);
> -	if (tty) {
> -		tty_vhangup(port->tty);
> -		tty_kref_put(tty);
> -	}
> +	tty_port_tty_vhangup(port);
>  
>  	/*
>  	 * If the port is used as a console, unregister it
> diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
> index 4af1fbf73f51..903eebdbe12d 100644
> --- a/drivers/tty/tty_port.c
> +++ b/drivers/tty/tty_port.c
> @@ -396,15 +396,19 @@ EXPORT_SYMBOL(tty_port_hangup);
>   * @port: tty port
>   * @check_clocal: hang only ttys with %CLOCAL unset?
>   */
> -void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
> +void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async)
>  {
>  	struct tty_struct *tty = tty_port_tty_get(port);
>  
> -	if (tty && (!check_clocal || !C_CLOCAL(tty)))
> -		tty_hangup(tty);
> +	if (tty && (!check_clocal || !C_CLOCAL(tty))) {
> +		if (async)
> +			tty_hangup(tty);
> +		else
> +			tty_vhangup(tty);
> +	}
>  	tty_kref_put(tty);
>  }
> -EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
> +EXPORT_SYMBOL_GPL(__tty_port_tty_hangup);
>  
>  /**
>   * tty_port_tty_wakeup - helper to wake up a tty
> diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
> index c2ecfa3c8349..f9171fbedf5c 100644
> --- a/drivers/usb/class/cdc-acm.c
> +++ b/drivers/usb/class/cdc-acm.c
> @@ -1571,7 +1571,6 @@ static int acm_probe(struct usb_interface *intf,
>  static void acm_disconnect(struct usb_interface *intf)
>  {
>  	struct acm *acm = usb_get_intfdata(intf);
> -	struct tty_struct *tty;
>  	int i;
>  
>  	/* sibling interface is already cleaning up */
> @@ -1598,11 +1597,7 @@ static void acm_disconnect(struct usb_interface *intf)
>  	usb_set_intfdata(acm->data, NULL);
>  	mutex_unlock(&acm->mutex);
>  
> -	tty = tty_port_tty_get(&acm->port);
> -	if (tty) {
> -		tty_vhangup(tty);
> -		tty_kref_put(tty);
> -	}
> +	tty_port_tty_vhangup(&acm->port);
>  
>  	cancel_delayed_work_sync(&acm->dwork);
>  
> diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
> index 7266558d823a..c78ff40b1e5f 100644
> --- a/drivers/usb/serial/usb-serial.c
> +++ b/drivers/usb/serial/usb-serial.c
> @@ -1176,7 +1176,6 @@ static void usb_serial_disconnect(struct usb_interface *interface)
>  	struct usb_serial *serial = usb_get_intfdata(interface);
>  	struct device *dev = &interface->dev;
>  	struct usb_serial_port *port;
> -	struct tty_struct *tty;
>  
>  	/* sibling interface is cleaning up */
>  	if (!serial)
> @@ -1191,11 +1190,7 @@ static void usb_serial_disconnect(struct usb_interface *interface)
>  
>  	for (i = 0; i < serial->num_ports; ++i) {
>  		port = serial->port[i];
> -		tty = tty_port_tty_get(&port->port);
> -		if (tty) {
> -			tty_vhangup(tty);
> -			tty_kref_put(tty);
> -		}
> +		tty_port_tty_vhangup(&port->port);
>  		usb_serial_port_poison_urbs(port);
>  		wake_up_interruptible(&port->port.delta_msr_wait);
>  		cancel_work_sync(&port->work);
> diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
> index 08f89a598366..021f9a8415c0 100644
> --- a/include/linux/tty_port.h
> +++ b/include/linux/tty_port.h
> @@ -232,7 +232,7 @@ bool tty_port_carrier_raised(struct tty_port *port);
>  void tty_port_raise_dtr_rts(struct tty_port *port);
>  void tty_port_lower_dtr_rts(struct tty_port *port);
>  void tty_port_hangup(struct tty_port *port);
> -void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
> +void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async);
>  void tty_port_tty_wakeup(struct tty_port *port);
>  int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty,
>  		struct file *filp);
> @@ -251,4 +251,14 @@ static inline int tty_port_users(struct tty_port *port)
>  	return port->count + port->blocked_open;
>  }
>  
> +static inline void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
> +{
> +	__tty_port_tty_hangup(port, check_clocal, true);
> +}
> +
> +static inline void tty_port_tty_vhangup(struct tty_port *port)
> +{
> +	__tty_port_tty_hangup(port, false, false);
> +}
> +
>  #endif
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index 21a5b5535ebc..827dfbe66085 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -438,7 +438,6 @@ static int __rfcomm_release_dev(void __user *arg)
>  {
>  	struct rfcomm_dev_req req;
>  	struct rfcomm_dev *dev;
> -	struct tty_struct *tty;
>  
>  	if (copy_from_user(&req, arg, sizeof(req)))
>  		return -EFAULT;
> @@ -464,11 +463,7 @@ static int __rfcomm_release_dev(void __user *arg)
>  		rfcomm_dlc_close(dev->dlc, 0);
>  
>  	/* Shut down TTY synchronously before freeing rfcomm_dev */
> -	tty = tty_port_tty_get(&dev->port);
> -	if (tty) {
> -		tty_vhangup(tty);
> -		tty_kref_put(tty);
> -	}
> +	tty_port_tty_vhangup(&dev->port);
>  
>  	if (!test_bit(RFCOMM_TTY_OWNED, &dev->status))
>  		tty_port_put(&dev->port);
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port()
  2025-06-11 10:02 ` [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port() Jiri Slaby (SUSE)
@ 2025-06-11 11:15   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:15 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 4542 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> Caching the port and info in local variables makes the code more compact
> and easier to understand.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: linuxppc-dev@lists.ozlabs.org

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

--
 i.

> ---
>  arch/powerpc/kernel/legacy_serial.c | 52 ++++++++++++++---------------
>  1 file changed, 26 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index 1da2f6e7d2a1..d9080189c28c 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -77,6 +77,8 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
>  				  phys_addr_t taddr, unsigned long irq,
>  				  upf_t flags, int irq_check_parent)
>  {
> +	struct plat_serial8250_port *legacy_port;
> +	struct legacy_serial_info *legacy_info;
>  	const __be32 *clk, *spd, *rs;
>  	u32 clock = BASE_BAUD * 16;
>  	u32 shift = 0;
> @@ -110,16 +112,17 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
>  	if (index >= legacy_serial_count)
>  		legacy_serial_count = index + 1;
>  
> +	legacy_port = &legacy_serial_ports[index];
> +	legacy_info = &legacy_serial_infos[index];
> +
>  	/* Check if there is a port who already claimed our slot */
> -	if (legacy_serial_infos[index].np != NULL) {
> +	if (legacy_info->np != NULL) {
>  		/* if we still have some room, move it, else override */
>  		if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) {
>  			printk(KERN_DEBUG "Moved legacy port %d -> %d\n",
>  			       index, legacy_serial_count);
> -			legacy_serial_ports[legacy_serial_count] =
> -				legacy_serial_ports[index];
> -			legacy_serial_infos[legacy_serial_count] =
> -				legacy_serial_infos[index];
> +			legacy_serial_ports[legacy_serial_count] = *legacy_port;
> +			legacy_serial_infos[legacy_serial_count] = *legacy_info;
>  			legacy_serial_count++;
>  		} else {
>  			printk(KERN_DEBUG "Replacing legacy port %d\n", index);
> @@ -127,36 +130,33 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
>  	}
>  
>  	/* Now fill the entry */
> -	memset(&legacy_serial_ports[index], 0,
> -	       sizeof(struct plat_serial8250_port));
> +	memset(legacy_port, 0, sizeof(*legacy_port));
>  	if (iotype == UPIO_PORT)
> -		legacy_serial_ports[index].iobase = base;
> +		legacy_port->iobase = base;
>  	else
> -		legacy_serial_ports[index].mapbase = base;
> -
> -	legacy_serial_ports[index].iotype = iotype;
> -	legacy_serial_ports[index].uartclk = clock;
> -	legacy_serial_ports[index].irq = irq;
> -	legacy_serial_ports[index].flags = flags;
> -	legacy_serial_ports[index].regshift = shift;
> -	legacy_serial_infos[index].taddr = taddr;
> -	legacy_serial_infos[index].np = of_node_get(np);
> -	legacy_serial_infos[index].clock = clock;
> -	legacy_serial_infos[index].speed = spd ? be32_to_cpup(spd) : 0;
> -	legacy_serial_infos[index].irq_check_parent = irq_check_parent;
> +		legacy_port->mapbase = base;
> +
> +	legacy_port->iotype = iotype;
> +	legacy_port->uartclk = clock;
> +	legacy_port->irq = irq;
> +	legacy_port->flags = flags;
> +	legacy_port->regshift = shift;
> +	legacy_info->taddr = taddr;
> +	legacy_info->np = of_node_get(np);
> +	legacy_info->clock = clock;
> +	legacy_info->speed = spd ? be32_to_cpup(spd) : 0;
> +	legacy_info->irq_check_parent = irq_check_parent;
>  
>  	if (iotype == UPIO_TSI) {
> -		legacy_serial_ports[index].serial_in = tsi_serial_in;
> -		legacy_serial_ports[index].serial_out = tsi_serial_out;
> +		legacy_port->serial_in = tsi_serial_in;
> +		legacy_port->serial_out = tsi_serial_out;
>  	}
>  
> -	printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n",
> -	       index, np);
> +	printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n", index, np);
>  	printk(KERN_DEBUG "  %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
>  	       (iotype == UPIO_PORT) ? "port" : "mem",
>  	       (unsigned long long)base, (unsigned long long)taddr, irq,
> -	       legacy_serial_ports[index].uartclk,
> -	       legacy_serial_infos[index].speed);
> +	       legacy_port->uartclk, legacy_info->speed);
>  
>  	return index;
>  }
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 04/33] m68k: remove unneeded tty includes
  2025-06-11 10:02 ` [PATCH 04/33] m68k: remove unneeded tty includes Jiri Slaby (SUSE)
@ 2025-06-11 11:22   ` Ilpo Järvinen
  2025-06-17 12:29   ` Geert Uytterhoeven
  1 sibling, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:22 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Geert Uytterhoeven,
	Joshua Thompson, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 3256 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> All these includes must have been cut & pasted. The code does not use
> any tty or vt functionality at all.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Joshua Thompson <funaho@jurai.org>
> Cc: linux-m68k@lists.linux-m68k.org

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

--
 i.

> ---
>  arch/m68k/amiga/config.c  | 2 --
>  arch/m68k/apollo/config.c | 2 --
>  arch/m68k/atari/config.c  | 1 -
>  arch/m68k/mac/config.c    | 2 --
>  arch/m68k/q40/config.c    | 2 --
>  5 files changed, 9 deletions(-)
> 
> diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
> index 0147130dc34e..242d18e750b0 100644
> --- a/arch/m68k/amiga/config.c
> +++ b/arch/m68k/amiga/config.c
> @@ -16,12 +16,10 @@
>  #include <linux/kernel.h>
>  #include <linux/mm.h>
>  #include <linux/seq_file.h>
> -#include <linux/tty.h>
>  #include <linux/clocksource.h>
>  #include <linux/console.h>
>  #include <linux/rtc.h>
>  #include <linux/init.h>
> -#include <linux/vt_kern.h>
>  #include <linux/delay.h>
>  #include <linux/interrupt.h>
>  #include <linux/zorro.h>
> diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
> index e161ecd76035..e324c5f671de 100644
> --- a/arch/m68k/apollo/config.c
> +++ b/arch/m68k/apollo/config.c
> @@ -3,9 +3,7 @@
>  #include <linux/types.h>
>  #include <linux/kernel.h>
>  #include <linux/mm.h>
> -#include <linux/tty.h>
>  #include <linux/rtc.h>
> -#include <linux/vt_kern.h>
>  #include <linux/interrupt.h>
>  
>  #include <asm/setup.h>
> diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
> index b48a0606a000..ee2d061efb2a 100644
> --- a/arch/m68k/atari/config.c
> +++ b/arch/m68k/atari/config.c
> @@ -33,7 +33,6 @@
>  #include <linux/ioport.h>
>  #include <linux/platform_device.h>
>  #include <linux/usb/isp116x.h>
> -#include <linux/vt_kern.h>
>  #include <linux/module.h>
>  
>  #include <asm/bootinfo.h>
> diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
> index d26c7f4f8c36..c0033f885ed4 100644
> --- a/arch/m68k/mac/config.c
> +++ b/arch/m68k/mac/config.c
> @@ -15,7 +15,6 @@
>  #include <linux/reboot.h>
>  #include <linux/types.h>
>  #include <linux/mm.h>
> -#include <linux/tty.h>
>  #include <linux/console.h>
>  #include <linux/interrupt.h>
>  /* keyb */
> @@ -23,7 +22,6 @@
>  #include <linux/delay.h>
>  /* keyb */
>  #include <linux/init.h>
> -#include <linux/vt_kern.h>
>  #include <linux/platform_device.h>
>  #include <linux/ata_platform.h>
>  #include <linux/adb.h>
> diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
> index de7870ad2a30..5a4258697622 100644
> --- a/arch/m68k/q40/config.c
> +++ b/arch/m68k/q40/config.c
> @@ -13,14 +13,12 @@
>  #include <linux/types.h>
>  #include <linux/kernel.h>
>  #include <linux/mm.h>
> -#include <linux/tty.h>
>  #include <linux/console.h>
>  #include <linux/linkage.h>
>  #include <linux/init.h>
>  #include <linux/major.h>
>  #include <linux/serial_reg.h>
>  #include <linux/rtc.h>
> -#include <linux/vt_kern.h>
>  #include <linux/bcd.h>
>  #include <linux/platform_device.h>
>  
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 05/33] powerpc/powermac: remove unneeded tty includes
  2025-06-11 10:02 ` [PATCH 05/33] powerpc/powermac: " Jiri Slaby (SUSE)
@ 2025-06-11 11:25   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:25 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> All these includes must have been cut & pasted. The code does not use
> any tty or vt functionality at all.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: linuxppc-dev@lists.ozlabs.org
> ---
>  arch/powerpc/platforms/powermac/setup.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
> index e119ced05d10..eb092f293113 100644
> --- a/arch/powerpc/platforms/powermac/setup.c
> +++ b/arch/powerpc/platforms/powermac/setup.c
> @@ -28,13 +28,11 @@
>  #include <linux/ptrace.h>
>  #include <linux/export.h>
>  #include <linux/user.h>
> -#include <linux/tty.h>
>  #include <linux/string.h>
>  #include <linux/delay.h>
>  #include <linux/ioport.h>
>  #include <linux/major.h>
>  #include <linux/initrd.h>
> -#include <linux/vt_kern.h>
>  #include <linux/console.h>
>  #include <linux/pci.h>
>  #include <linux/adb.h>

Seems true. I had to actually scan through the file as it does have some 
console related setup.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
@ 2025-06-11 11:30   ` Ilpo Järvinen
  2025-06-11 14:42   ` Nicolas Pitre
  2025-07-31 14:35   ` Christophe Leroy
  2 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:30 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel, Nicolas Pitre

[-- Attachment #1: Type: text/plain, Size: 4697 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
> were synthetically built up the same way the _IO() macro does.
> 
> So instead of implicit hex numbers, use _IO() properly.
> 
> To not change the pre-existing numbers, use only _IO() (and not _IOR()
> or _IOW()). The latter would change the numbers indeed.
> 
> Objdump of vt_ioctl.o reveals no difference with this patch.
> 
> Again, VT_GETCONSIZECSRPOS already uses _IOR(), so everything is paved
> for this patch.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Nicolas Pitre <nico@fluxnic.net>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  include/uapi/linux/vt.h | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
> index 714483d68c69..b60fcdfb2746 100644
> --- a/include/uapi/linux/vt.h
> +++ b/include/uapi/linux/vt.h
> @@ -14,9 +14,9 @@
>  		/* Note: the ioctl VT_GETSTATE does not work for
>  		   consoles 16 and higher (since it returns a short) */
>  
> -/* 0x56 is 'V', to avoid collision with termios and kd */
> +/* 'V' to avoid collision with termios and kd */
>  
> -#define VT_OPENQRY	0x5600	/* find available vt */
> +#define VT_OPENQRY		_IO('V', 0x00)	/* find available vt */
>  
>  struct vt_mode {
>  	__u8 mode;		/* vt mode */
> @@ -25,8 +25,8 @@ struct vt_mode {
>  	__s16 acqsig;		/* signal to raise on acquisition */
>  	__s16 frsig;		/* unused (set to 0) */
>  };
> -#define VT_GETMODE	0x5601	/* get mode of active vt */
> -#define VT_SETMODE	0x5602	/* set mode of active vt */
> +#define VT_GETMODE		_IO('V', 0x01)	/* get mode of active vt */
> +#define VT_SETMODE		_IO('V', 0x02)	/* set mode of active vt */
>  #define		VT_AUTO		0x00	/* auto vt switching */
>  #define		VT_PROCESS	0x01	/* process controls switching */
>  #define		VT_ACKACQ	0x02	/* acknowledge switch */
> @@ -36,21 +36,21 @@ struct vt_stat {
>  	__u16 v_signal;	/* signal to send */
>  	__u16 v_state;		/* vt bitmask */
>  };
> -#define VT_GETSTATE	0x5603	/* get global vt state info */
> -#define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
> +#define VT_GETSTATE		_IO('V', 0x03)	/* get global vt state info */
> +#define VT_SENDSIG		_IO('V', 0x04)	/* signal to send to bitmask of vts */
>  
> -#define VT_RELDISP	0x5605	/* release display */
> +#define VT_RELDISP		_IO('V', 0x05)	/* release display */
>  
> -#define VT_ACTIVATE	0x5606	/* make vt active */
> -#define VT_WAITACTIVE	0x5607	/* wait for vt active */
> -#define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
> +#define VT_ACTIVATE		_IO('V', 0x06)	/* make vt active */
> +#define VT_WAITACTIVE		_IO('V', 0x07)	/* wait for vt active */
> +#define VT_DISALLOCATE		_IO('V', 0x08)  /* free memory associated to vt */
>  
>  struct vt_sizes {
>  	__u16 v_rows;		/* number of rows */
>  	__u16 v_cols;		/* number of columns */
>  	__u16 v_scrollsize;	/* number of lines of scrollback */
>  };
> -#define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
> +#define VT_RESIZE		_IO('V', 0x09)	/* set kernel's idea of screensize */
>  
>  struct vt_consize {
>  	__u16 v_rows;	/* number of rows */
> @@ -60,10 +60,10 @@ struct vt_consize {
>  	__u16 v_vcol;	/* number of pixel columns on screen */
>  	__u16 v_ccol;	/* number of pixel columns per character */
>  };
> -#define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
> -#define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
> -#define VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
> -#define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
> +#define VT_RESIZEX		_IO('V', 0x0A)  /* set kernel's idea of screensize + more */
> +#define VT_LOCKSWITCH		_IO('V', 0x0B)  /* disallow vt switching */
> +#define VT_UNLOCKSWITCH		_IO('V', 0x0C)  /* allow vt switching */
> +#define VT_GETHIFONTMASK	_IO('V', 0x0D)  /* return hi font mask */
>  
>  struct vt_event {
>  	__u32 event;
> @@ -77,14 +77,14 @@ struct vt_event {
>  	__u32 pad[4];		/* Padding for expansion */
>  };
>  
> -#define VT_WAITEVENT	0x560E	/* Wait for an event */
> +#define VT_WAITEVENT		_IO('V', 0x0E)	/* Wait for an event */
>  
>  struct vt_setactivate {
>  	__u32 console;
>  	struct vt_mode mode;
>  };
>  
> -#define VT_SETACTIVATE	0x560F	/* Activate and set the mode of a console */
> +#define VT_SETACTIVATE		_IO('V', 0x0F)	/* Activate and set the mode of a console */
>  
>  /* get console size and cursor position */
>  struct vt_consizecsrpos {
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code
  2025-06-11 10:02 ` [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Jiri Slaby (SUSE)
@ 2025-06-11 11:42   ` Ilpo Järvinen
  2025-06-11 11:46   ` Ilpo Järvinen
  1 sibling, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:42 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> All these:
>   #ifdef CONFIG_SERIAL_8250_RSA
>   ...
>   #endif
> 
> in the 8250 generic code distract the reader. Introduce empty inlines to
> handle the !CONFIG_SERIAL_8250_RSA case and handle the '#if's around the
> RSA functions definitions.
> 
> This means rsa_autoconfig() and rsa_reset() functions were introduced to
> contain the particular code.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 54 ++++++++++++++---------------
>  1 file changed, 27 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index f5407832e8a7..233316a88df2 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -738,6 +738,9 @@ static int __enable_rsa(struct uart_8250_port *up)
>  	return result;
>  }
>  
> +/*
> + * If this is an RSA port, see if we can kick it up to the higher speed clock.
> + */
>  static void enable_rsa(struct uart_8250_port *up)
>  {
>  	if (up->port.type == PORT_RSA) {

In general, a good change but it would also be nice to reverse all these 
type check because then it would be immediately obvious the function does 
nothing if it's not PORT_RSA.

> @@ -752,10 +755,9 @@ static void enable_rsa(struct uart_8250_port *up)
>  }
>  
>  /*
> - * Attempts to turn off the RSA FIFO.  Returns zero on failure.
> - * It is unknown why interrupts were disabled in here.  However,
> - * the caller is expected to preserve this behaviour by grabbing
> - * the spinlock before calling this function.
> + * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
> + * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
> + * behaviour by grabbing the spinlock before calling this function.
>   */
>  static void disable_rsa(struct uart_8250_port *up)
>  {
> @@ -780,6 +782,25 @@ static void disable_rsa(struct uart_8250_port *up)
>  		uart_port_unlock_irq(&up->port);
>  	}
>  }
> +
> +static void rsa_autoconfig(struct uart_8250_port *up)
> +{
> +	/* Only probe for RSA ports if we got the region. */
> +	if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> +	    __enable_rsa(up))
> +		up->port.type = PORT_RSA;
> +}
> +
> +static void rsa_reset(struct uart_8250_port *up)
> +{
> +	if (up->port.type == PORT_RSA)
> +		serial_out(up, UART_RSA_FRR, 0);
> +}
> +#else
> +static inline void enable_rsa(struct uart_8250_port *up) {}
> +static inline void disable_rsa(struct uart_8250_port *up) {}
> +static inline void rsa_autoconfig(struct uart_8250_port *up) {}
> +static inline void rsa_reset(struct uart_8250_port *up) {}
>  #endif /* CONFIG_SERIAL_8250_RSA */
>  
>  /*
> @@ -1267,14 +1288,7 @@ static void autoconfig(struct uart_8250_port *up)
>  		break;
>  	}
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * Only probe for RSA ports if we got the region.
> -	 */
> -	if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> -	    __enable_rsa(up))
> -		port->type = PORT_RSA;
> -#endif
> +	rsa_autoconfig(up);
>  
>  	serial_out(up, UART_LCR, save_lcr);
>  
> @@ -1289,10 +1303,7 @@ static void autoconfig(struct uart_8250_port *up)
>  	/*
>  	 * Reset the UART.
>  	 */
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	if (port->type == PORT_RSA)
> -		serial_out(up, UART_RSA_FRR, 0);
> -#endif
> +	rsa_reset(up);
>  	serial8250_out_MCR(up, save_mcr);
>  	serial8250_clear_fifos(up);
>  	serial_in(up, UART_RX);
> @@ -2248,13 +2259,7 @@ int serial8250_do_startup(struct uart_port *port)
>  				UART_DA830_PWREMU_MGMT_FREE);
>  	}
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * If this is an RSA port, see if we can kick it up to the
> -	 * higher speed clock.
> -	 */
>  	enable_rsa(up);
> -#endif
>  
>  	/*
>  	 * Clear the FIFO buffers and disable them.
> @@ -2521,12 +2526,7 @@ void serial8250_do_shutdown(struct uart_port *port)
>  			serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
>  	serial8250_clear_fifos(up);
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * Reset the RSA board back to 115kbps compat mode.
> -	 */
>  	disable_rsa(up);
> -#endif
>  
>  	/*
>  	 * Read data port to reset things, and then unlink from
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 10/33] serial: 8250: invert conditions in RSA functions
  2025-06-11 10:02 ` [PATCH 10/33] serial: 8250: invert conditions in RSA functions Jiri Slaby (SUSE)
@ 2025-06-11 11:45   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:45 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3478 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> The code can short-return in case something does not hold. So invert the
> conditions and return in those cases immediately. This makes the code
> flow more natural and less nested.

Ah, never mind my comment on the previous patch :-).

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.


> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 59 +++++++++++++++++------------
>  1 file changed, 34 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 233316a88df2..e7652d62ab2f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -743,15 +743,16 @@ static int __enable_rsa(struct uart_8250_port *up)
>   */
>  static void enable_rsa(struct uart_8250_port *up)
>  {
> -	if (up->port.type == PORT_RSA) {
> -		if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> -			uart_port_lock_irq(&up->port);
> -			__enable_rsa(up);
> -			uart_port_unlock_irq(&up->port);
> -		}
> -		if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> -			serial_out(up, UART_RSA_FRR, 0);
> +	if (up->port.type != PORT_RSA)
> +		return;
> +
> +	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> +		uart_port_lock_irq(&up->port);
> +		__enable_rsa(up);
> +		uart_port_unlock_irq(&up->port);
>  	}
> +	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> +		serial_out(up, UART_RSA_FRR, 0);
>  }
>  
>  /*
> @@ -764,37 +765,45 @@ static void disable_rsa(struct uart_8250_port *up)
>  	unsigned char mode;
>  	int result;
>  
> -	if (up->port.type == PORT_RSA &&
> -	    up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
> -		uart_port_lock_irq(&up->port);
> +	if (up->port.type != PORT_RSA)
> +		return;
>  
> -		mode = serial_in(up, UART_RSA_MSR);
> -		result = !(mode & UART_RSA_MSR_FIFO);
> +	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
> +		return;
>  
> -		if (!result) {
> -			serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> -			mode = serial_in(up, UART_RSA_MSR);
> -			result = !(mode & UART_RSA_MSR_FIFO);
> -		}
> +	uart_port_lock_irq(&up->port);
> +	mode = serial_in(up, UART_RSA_MSR);
> +	result = !(mode & UART_RSA_MSR_FIFO);
>  
> -		if (result)
> -			up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> -		uart_port_unlock_irq(&up->port);
> +	if (!result) {
> +		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> +		mode = serial_in(up, UART_RSA_MSR);
> +		result = !(mode & UART_RSA_MSR_FIFO);
>  	}
> +
> +	if (result)
> +		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> +	uart_port_unlock_irq(&up->port);
>  }
>  
>  static void rsa_autoconfig(struct uart_8250_port *up)
>  {
>  	/* Only probe for RSA ports if we got the region. */
> -	if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> -	    __enable_rsa(up))
> +	if (up->port.type != PORT_16550A)
> +		return;
> +	if (!(up->probe & UART_PROBE_RSA))
> +		return;
> +
> +	if (__enable_rsa(up))
>  		up->port.type = PORT_RSA;
>  }
>  
>  static void rsa_reset(struct uart_8250_port *up)
>  {
> -	if (up->port.type == PORT_RSA)
> -		serial_out(up, UART_RSA_FRR, 0);
> +	if (up->port.type != PORT_RSA)
> +		return;
> +
> +	serial_out(up, UART_RSA_FRR, 0);
>  }
>  #else
>  static inline void enable_rsa(struct uart_8250_port *up) {}
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code
  2025-06-11 10:02 ` [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Jiri Slaby (SUSE)
  2025-06-11 11:42   ` Ilpo Järvinen
@ 2025-06-11 11:46   ` Ilpo Järvinen
  1 sibling, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:46 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 4290 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> All these:
>   #ifdef CONFIG_SERIAL_8250_RSA
>   ...
>   #endif
> 
> in the 8250 generic code distract the reader. Introduce empty inlines to
> handle the !CONFIG_SERIAL_8250_RSA case and handle the '#if's around the
> RSA functions definitions.
> 
> This means rsa_autoconfig() and rsa_reset() functions were introduced to
> contain the particular code.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 54 ++++++++++++++---------------
>  1 file changed, 27 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index f5407832e8a7..233316a88df2 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -738,6 +738,9 @@ static int __enable_rsa(struct uart_8250_port *up)
>  	return result;
>  }
>  
> +/*
> + * If this is an RSA port, see if we can kick it up to the higher speed clock.
> + */
>  static void enable_rsa(struct uart_8250_port *up)
>  {
>  	if (up->port.type == PORT_RSA) {
> @@ -752,10 +755,9 @@ static void enable_rsa(struct uart_8250_port *up)
>  }
>  
>  /*
> - * Attempts to turn off the RSA FIFO.  Returns zero on failure.
> - * It is unknown why interrupts were disabled in here.  However,
> - * the caller is expected to preserve this behaviour by grabbing
> - * the spinlock before calling this function.
> + * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
> + * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
> + * behaviour by grabbing the spinlock before calling this function.
>   */
>  static void disable_rsa(struct uart_8250_port *up)
>  {
> @@ -780,6 +782,25 @@ static void disable_rsa(struct uart_8250_port *up)
>  		uart_port_unlock_irq(&up->port);
>  	}
>  }
> +
> +static void rsa_autoconfig(struct uart_8250_port *up)
> +{
> +	/* Only probe for RSA ports if we got the region. */
> +	if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> +	    __enable_rsa(up))
> +		up->port.type = PORT_RSA;
> +}
> +
> +static void rsa_reset(struct uart_8250_port *up)
> +{
> +	if (up->port.type == PORT_RSA)
> +		serial_out(up, UART_RSA_FRR, 0);
> +}
> +#else
> +static inline void enable_rsa(struct uart_8250_port *up) {}
> +static inline void disable_rsa(struct uart_8250_port *up) {}
> +static inline void rsa_autoconfig(struct uart_8250_port *up) {}
> +static inline void rsa_reset(struct uart_8250_port *up) {}
>  #endif /* CONFIG_SERIAL_8250_RSA */
>  
>  /*
> @@ -1267,14 +1288,7 @@ static void autoconfig(struct uart_8250_port *up)
>  		break;
>  	}
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * Only probe for RSA ports if we got the region.
> -	 */
> -	if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> -	    __enable_rsa(up))
> -		port->type = PORT_RSA;
> -#endif
> +	rsa_autoconfig(up);
>  
>  	serial_out(up, UART_LCR, save_lcr);
>  
> @@ -1289,10 +1303,7 @@ static void autoconfig(struct uart_8250_port *up)
>  	/*
>  	 * Reset the UART.
>  	 */
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	if (port->type == PORT_RSA)
> -		serial_out(up, UART_RSA_FRR, 0);
> -#endif
> +	rsa_reset(up);
>  	serial8250_out_MCR(up, save_mcr);
>  	serial8250_clear_fifos(up);
>  	serial_in(up, UART_RX);
> @@ -2248,13 +2259,7 @@ int serial8250_do_startup(struct uart_port *port)
>  				UART_DA830_PWREMU_MGMT_FREE);
>  	}
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * If this is an RSA port, see if we can kick it up to the
> -	 * higher speed clock.
> -	 */
>  	enable_rsa(up);
> -#endif
>  
>  	/*
>  	 * Clear the FIFO buffers and disable them.
> @@ -2521,12 +2526,7 @@ void serial8250_do_shutdown(struct uart_port *port)
>  			serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
>  	serial8250_clear_fifos(up);
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -	/*
> -	 * Reset the RSA board back to 115kbps compat mode.
> -	 */
>  	disable_rsa(up);
> -#endif
>  
>  	/*
>  	 * Read data port to reset things, and then unlink from
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c
  2025-06-11 10:02 ` [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c Jiri Slaby (SUSE)
@ 2025-06-11 11:49   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:49 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 7889 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> They are RSA-specific, so should live in a preexisting 8250_rsa.c. Move
> them there.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

No unexpected change found in the diff-of-diffs,

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/8250/8250.h      |  8 +++
>  drivers/tty/serial/8250/8250_port.c | 99 -----------------------------
>  drivers/tty/serial/8250/8250_rsa.c  | 92 +++++++++++++++++++++++++++
>  3 files changed, 100 insertions(+), 99 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
> index 18530c31a598..cfe6ba286b45 100644
> --- a/drivers/tty/serial/8250/8250.h
> +++ b/drivers/tty/serial/8250/8250.h
> @@ -318,8 +318,16 @@ static inline void serial8250_pnp_exit(void) { }
>  
>  #ifdef CONFIG_SERIAL_8250_RSA
>  void univ8250_rsa_support(struct uart_ops *ops);
> +void rsa_enable(struct uart_8250_port *up);
> +void rsa_disable(struct uart_8250_port *up);
> +void rsa_autoconfig(struct uart_8250_port *up);
> +void rsa_reset(struct uart_8250_port *up);
>  #else
>  static inline void univ8250_rsa_support(struct uart_ops *ops) { }
> +static inline void rsa_enable(struct uart_8250_port *up) {}
> +static inline void rsa_disable(struct uart_8250_port *up) {}
> +static inline void rsa_autoconfig(struct uart_8250_port *up) {}
> +static inline void rsa_reset(struct uart_8250_port *up) {}
>  #endif
>  
>  #ifdef CONFIG_SERIAL_8250_FINTEK
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index d8a90818f431..476f5fc50237 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -713,105 +713,6 @@ static void serial8250_clear_IER(struct uart_8250_port *up)
>  		serial_out(up, UART_IER, 0);
>  }
>  
> -#ifdef CONFIG_SERIAL_8250_RSA
> -/*
> - * Attempts to turn on the RSA FIFO.  Returns zero on failure.
> - * We set the port uart clock rate if we succeed.
> - */
> -static int __rsa_enable(struct uart_8250_port *up)
> -{
> -	unsigned char mode;
> -	int result;
> -
> -	mode = serial_in(up, UART_RSA_MSR);
> -	result = mode & UART_RSA_MSR_FIFO;
> -
> -	if (!result) {
> -		serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
> -		mode = serial_in(up, UART_RSA_MSR);
> -		result = mode & UART_RSA_MSR_FIFO;
> -	}
> -
> -	if (result)
> -		up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
> -
> -	return result;
> -}
> -
> -/*
> - * If this is an RSA port, see if we can kick it up to the higher speed clock.
> - */
> -static void rsa_enable(struct uart_8250_port *up)
> -{
> -	if (up->port.type != PORT_RSA)
> -		return;
> -
> -	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> -		uart_port_lock_irq(&up->port);
> -		__rsa_enable(up);
> -		uart_port_unlock_irq(&up->port);
> -	}
> -	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> -		serial_out(up, UART_RSA_FRR, 0);
> -}
> -
> -/*
> - * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
> - * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
> - * behaviour by grabbing the spinlock before calling this function.
> - */
> -static void rsa_disable(struct uart_8250_port *up)
> -{
> -	unsigned char mode;
> -	int result;
> -
> -	if (up->port.type != PORT_RSA)
> -		return;
> -
> -	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
> -		return;
> -
> -	uart_port_lock_irq(&up->port);
> -	mode = serial_in(up, UART_RSA_MSR);
> -	result = !(mode & UART_RSA_MSR_FIFO);
> -
> -	if (!result) {
> -		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> -		mode = serial_in(up, UART_RSA_MSR);
> -		result = !(mode & UART_RSA_MSR_FIFO);
> -	}
> -
> -	if (result)
> -		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> -	uart_port_unlock_irq(&up->port);
> -}
> -
> -static void rsa_autoconfig(struct uart_8250_port *up)
> -{
> -	/* Only probe for RSA ports if we got the region. */
> -	if (up->port.type != PORT_16550A)
> -		return;
> -	if (!(up->probe & UART_PROBE_RSA))
> -		return;
> -
> -	if (__rsa_enable(up))
> -		up->port.type = PORT_RSA;
> -}
> -
> -static void rsa_reset(struct uart_8250_port *up)
> -{
> -	if (up->port.type != PORT_RSA)
> -		return;
> -
> -	serial_out(up, UART_RSA_FRR, 0);
> -}
> -#else
> -static inline void rsa_enable(struct uart_8250_port *up) {}
> -static inline void rsa_disable(struct uart_8250_port *up) {}
> -static inline void rsa_autoconfig(struct uart_8250_port *up) {}
> -static inline void rsa_reset(struct uart_8250_port *up) {}
> -#endif /* CONFIG_SERIAL_8250_RSA */
> -
>  /*
>   * This is a quickie test to see how big the FIFO is.
>   * It doesn't work at all the time, more's the pity.
> diff --git a/drivers/tty/serial/8250/8250_rsa.c b/drivers/tty/serial/8250/8250_rsa.c
> index 4c8b9671bd41..59d2ecf23068 100644
> --- a/drivers/tty/serial/8250/8250_rsa.c
> +++ b/drivers/tty/serial/8250/8250_rsa.c
> @@ -107,6 +107,98 @@ void univ8250_rsa_support(struct uart_ops *ops)
>  module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
>  MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
>  
> +/*
> + * Attempts to turn on the RSA FIFO.  Returns zero on failure.
> + * We set the port uart clock rate if we succeed.
> + */
> +static int __rsa_enable(struct uart_8250_port *up)
> +{
> +	unsigned char mode;
> +	int result;
> +
> +	mode = serial_in(up, UART_RSA_MSR);
> +	result = mode & UART_RSA_MSR_FIFO;
> +
> +	if (!result) {
> +		serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
> +		mode = serial_in(up, UART_RSA_MSR);
> +		result = mode & UART_RSA_MSR_FIFO;
> +	}
> +
> +	if (result)
> +		up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
> +
> +	return result;
> +}
> +
> +/*
> + * If this is an RSA port, see if we can kick it up to the higher speed clock.
> + */
> +void rsa_enable(struct uart_8250_port *up)
> +{
> +	if (up->port.type != PORT_RSA)
> +		return;
> +
> +	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> +		uart_port_lock_irq(&up->port);
> +		__rsa_enable(up);
> +		uart_port_unlock_irq(&up->port);
> +	}
> +	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> +		serial_out(up, UART_RSA_FRR, 0);
> +}
> +
> +/*
> + * Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
> + * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
> + * behaviour by grabbing the spinlock before calling this function.
> + */
> +void rsa_disable(struct uart_8250_port *up)
> +{
> +	unsigned char mode;
> +	int result;
> +
> +	if (up->port.type != PORT_RSA)
> +		return;
> +
> +	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
> +		return;
> +
> +	uart_port_lock_irq(&up->port);
> +	mode = serial_in(up, UART_RSA_MSR);
> +	result = !(mode & UART_RSA_MSR_FIFO);
> +
> +	if (!result) {
> +		serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> +		mode = serial_in(up, UART_RSA_MSR);
> +		result = !(mode & UART_RSA_MSR_FIFO);
> +	}
> +
> +	if (result)
> +		up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> +	uart_port_unlock_irq(&up->port);
> +}
> +
> +void rsa_autoconfig(struct uart_8250_port *up)
> +{
> +	/* Only probe for RSA ports if we got the region. */
> +	if (up->port.type != PORT_16550A)
> +		return;
> +	if (!(up->probe & UART_PROBE_RSA))
> +		return;
> +
> +	if (__rsa_enable(up))
> +		up->port.type = PORT_RSA;
> +}
> +
> +void rsa_reset(struct uart_8250_port *up)
> +{
> +	if (up->port.type != PORT_RSA)
> +		return;
> +
> +	serial_out(up, UART_RSA_FRR, 0);
> +}
> +
>  #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
>  #ifndef MODULE
>  /*
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 13/33] serial: 8250: extract serial8250_startup_special()
  2025-06-11 10:02 ` [PATCH 13/33] serial: 8250: extract serial8250_startup_special() Jiri Slaby (SUSE)
@ 2025-06-11 11:53   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:53 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 3117 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> Let the serial8250_do_startup() code handle the special ports (16C950,
> DA830, RSA) startup in a separate function:
> serial8250_startup_special().
> 
> And instead of multiple if-else-if, use switch-case. So that it can be
> easily checked for PORT_RSA now too.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

Another very nice cleanup for old cruft.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/8250/8250_port.c | 53 +++++++++++++++++------------
>  1 file changed, 32 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 476f5fc50237..21ff56a31b56 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2111,27 +2111,13 @@ static void serial8250_put_poll_char(struct uart_port *port,
>  
>  #endif /* CONFIG_CONSOLE_POLL */
>  
> -int serial8250_do_startup(struct uart_port *port)
> +static void serial8250_startup_special(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
>  	unsigned long flags;
> -	unsigned char iir;
> -	int retval;
> -	u16 lsr;
> -
> -	if (!port->fifosize)
> -		port->fifosize = uart_config[port->type].fifo_size;
> -	if (!up->tx_loadsz)
> -		up->tx_loadsz = uart_config[port->type].tx_loadsz;
> -	if (!up->capabilities)
> -		up->capabilities = uart_config[port->type].flags;
> -	up->mcr = 0;
> -
> -	if (port->iotype != up->cur_iotype)
> -		set_io_from_upio(port);
>  
> -	serial8250_rpm_get(up);
> -	if (port->type == PORT_16C950) {
> +	switch (port->type) {
> +	case PORT_16C950:
>  		/*
>  		 * Wake up and initialize UART
>  		 *
> @@ -2148,9 +2134,8 @@ int serial8250_do_startup(struct uart_port *port)
>  		serial_port_out(port, UART_EFR, UART_EFR_ECB);
>  		serial_port_out(port, UART_LCR, 0);
>  		uart_port_unlock_irqrestore(port, flags);
> -	}
> -
> -	if (port->type == PORT_DA830) {
> +		break;
> +	case PORT_DA830:
>  		/*
>  		 * Reset the port
>  		 *
> @@ -2167,9 +2152,35 @@ int serial8250_do_startup(struct uart_port *port)
>  				UART_DA830_PWREMU_MGMT_UTRST |
>  				UART_DA830_PWREMU_MGMT_URRST |
>  				UART_DA830_PWREMU_MGMT_FREE);
> +		break;
> +	case PORT_RSA:
> +		rsa_enable(up);
> +		break;
>  	}
> +}
> +
> +int serial8250_do_startup(struct uart_port *port)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	unsigned long flags;
> +	unsigned char iir;
> +	int retval;
> +	u16 lsr;
> +
> +	if (!port->fifosize)
> +		port->fifosize = uart_config[port->type].fifo_size;
> +	if (!up->tx_loadsz)
> +		up->tx_loadsz = uart_config[port->type].tx_loadsz;
> +	if (!up->capabilities)
> +		up->capabilities = uart_config[port->type].flags;
> +	up->mcr = 0;
> +
> +	if (port->iotype != up->cur_iotype)
> +		set_io_from_upio(port);
> +
> +	serial8250_rpm_get(up);
>  
> -	rsa_enable(up);
> +	serial8250_startup_special(port);
>  
>  	/*
>  	 * Clear the FIFO buffers and disable them.
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 11/33] serial: 8250: put RSA functions to their namespace
  2025-06-11 10:02 ` [PATCH 11/33] serial: 8250: put RSA functions to their namespace Jiri Slaby (SUSE)
@ 2025-06-11 11:54   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 11:54 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3348 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> Prefix the functions with rsa_, not suffix.
> 
> This is a preparation for moving them out to 8250_rsa.c in the next
> patch.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index e7652d62ab2f..d8a90818f431 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -718,7 +718,7 @@ static void serial8250_clear_IER(struct uart_8250_port *up)
>   * Attempts to turn on the RSA FIFO.  Returns zero on failure.
>   * We set the port uart clock rate if we succeed.
>   */
> -static int __enable_rsa(struct uart_8250_port *up)
> +static int __rsa_enable(struct uart_8250_port *up)
>  {
>  	unsigned char mode;
>  	int result;
> @@ -741,14 +741,14 @@ static int __enable_rsa(struct uart_8250_port *up)
>  /*
>   * If this is an RSA port, see if we can kick it up to the higher speed clock.
>   */
> -static void enable_rsa(struct uart_8250_port *up)
> +static void rsa_enable(struct uart_8250_port *up)
>  {
>  	if (up->port.type != PORT_RSA)
>  		return;
>  
>  	if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
>  		uart_port_lock_irq(&up->port);
> -		__enable_rsa(up);
> +		__rsa_enable(up);
>  		uart_port_unlock_irq(&up->port);
>  	}
>  	if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> @@ -760,7 +760,7 @@ static void enable_rsa(struct uart_8250_port *up)
>   * unknown why interrupts were disabled in here. However, the caller is expected to preserve this
>   * behaviour by grabbing the spinlock before calling this function.
>   */
> -static void disable_rsa(struct uart_8250_port *up)
> +static void rsa_disable(struct uart_8250_port *up)
>  {
>  	unsigned char mode;
>  	int result;
> @@ -794,7 +794,7 @@ static void rsa_autoconfig(struct uart_8250_port *up)
>  	if (!(up->probe & UART_PROBE_RSA))
>  		return;
>  
> -	if (__enable_rsa(up))
> +	if (__rsa_enable(up))
>  		up->port.type = PORT_RSA;
>  }
>  
> @@ -806,8 +806,8 @@ static void rsa_reset(struct uart_8250_port *up)
>  	serial_out(up, UART_RSA_FRR, 0);
>  }
>  #else
> -static inline void enable_rsa(struct uart_8250_port *up) {}
> -static inline void disable_rsa(struct uart_8250_port *up) {}
> +static inline void rsa_enable(struct uart_8250_port *up) {}
> +static inline void rsa_disable(struct uart_8250_port *up) {}
>  static inline void rsa_autoconfig(struct uart_8250_port *up) {}
>  static inline void rsa_reset(struct uart_8250_port *up) {}
>  #endif /* CONFIG_SERIAL_8250_RSA */
> @@ -2268,7 +2268,7 @@ int serial8250_do_startup(struct uart_port *port)
>  				UART_DA830_PWREMU_MGMT_FREE);
>  	}
>  
> -	enable_rsa(up);
> +	rsa_enable(up);
>  
>  	/*
>  	 * Clear the FIFO buffers and disable them.
> @@ -2535,7 +2535,7 @@ void serial8250_do_shutdown(struct uart_port *port)
>  			serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
>  	serial8250_clear_fifos(up);
>  
> -	disable_rsa(up);
> +	rsa_disable(up);
>  
>  	/*
>  	 * Read data port to reset things, and then unlink from
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 15/33] serial: 8250: extract serial8250_THRE_test()
  2025-06-11 10:03 ` [PATCH 15/33] serial: 8250: extract serial8250_THRE_test() Jiri Slaby (SUSE)
@ 2025-06-11 12:03   ` Ilpo Järvinen
  2025-06-12  8:54     ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:03 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_startup() contains a stand-alone code for probing THRE.
> Furthermore, the code block is conditional (port->irq and test for
> UPF_NO_THRE_TEST).
> 
> Move this code to a separate function. The conditional can be evaluated
> easier there -- by a simple return in the beginning. So the indentation
> level lowers and the code is overall more readable now.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 92 +++++++++++++++--------------
>  1 file changed, 49 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index c09a90b38d8f..5466286bb44f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2199,6 +2199,54 @@ static void serial8250_set_TRG_levels(struct uart_port *port)
>  	}
>  }
>  
> +static void serial8250_THRE_test(struct uart_port *port)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	unsigned long flags;
> +	bool iir_noint1, iir_noint2;
> +
> +	if (!port->irq)
> +		return;
> +
> +	if (up->port.flags & UPF_NO_THRE_TEST)
> +		return;
> +
> +	if (port->irqflags & IRQF_SHARED)
> +		disable_irq_nosync(port->irq);
> +
> +	/*
> +	 * Test for UARTs that do not reassert THRE when the transmitter is idle and the interrupt
> +	 * has already been cleared.  Real 16550s should always reassert this interrupt whenever the
> +	 * transmitter is idle and the interrupt is enabled.  Delays are necessary to allow register
> +	 * changes to become visible.

Very long comment lines are hard to read. (This is mostly not related to
line length limits, but with eye movement required.)

It may make sense to place some of the descriptive comment text into a 
function comment instead of placing them mid-function.

> +	 *
> +	 * Synchronize UART_IER access against the console.
> +	 */
> +	uart_port_lock_irqsave(port, &flags);
> +
> +	wait_for_xmitr(up, UART_LSR_THRE);
> +	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> +	udelay(1); /* allow THRE to set */

These comments mix visually into the code making this look a big wall of 
text overall. Maybe consider adding empty lines to the logic as well as
there are what looks clear steps in this logic.

> +	iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> +	serial_port_out(port, UART_IER, 0);
> +	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> +	udelay(1); /* allow a working UART time to re-assert THRE */
> +	iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> +	serial_port_out(port, UART_IER, 0);
> +
> +	uart_port_unlock_irqrestore(port, flags);
> +
> +	if (port->irqflags & IRQF_SHARED)
> +		enable_irq(port->irq);
> +
> +	/*
> +	 * If the interrupt is not reasserted, or we otherwise don't trust the iir, setup a timer to
> +	 * kick the UART on a regular basis.
> +	 */
> +	if ((!iir_noint1 && iir_noint2) || up->port.flags & UPF_BUG_THRE)
> +		up->bugs |= UART_BUG_THRE;
> +}
> +
>  int serial8250_do_startup(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
> @@ -2258,49 +2306,7 @@ int serial8250_do_startup(struct uart_port *port)
>  	if (retval)
>  		goto out;
>  
> -	if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) {
> -		unsigned char iir1;
> -
> -		if (port->irqflags & IRQF_SHARED)
> -			disable_irq_nosync(port->irq);
> -
> -		/*
> -		 * Test for UARTs that do not reassert THRE when the
> -		 * transmitter is idle and the interrupt has already
> -		 * been cleared.  Real 16550s should always reassert
> -		 * this interrupt whenever the transmitter is idle and
> -		 * the interrupt is enabled.  Delays are necessary to
> -		 * allow register changes to become visible.
> -		 *
> -		 * Synchronize UART_IER access against the console.
> -		 */
> -		uart_port_lock_irqsave(port, &flags);
> -
> -		wait_for_xmitr(up, UART_LSR_THRE);
> -		serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> -		udelay(1); /* allow THRE to set */
> -		iir1 = serial_port_in(port, UART_IIR);
> -		serial_port_out(port, UART_IER, 0);
> -		serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> -		udelay(1); /* allow a working UART time to re-assert THRE */
> -		iir = serial_port_in(port, UART_IIR);
> -		serial_port_out(port, UART_IER, 0);
> -
> -		uart_port_unlock_irqrestore(port, flags);
> -
> -		if (port->irqflags & IRQF_SHARED)
> -			enable_irq(port->irq);
> -
> -		/*
> -		 * If the interrupt is not reasserted, or we otherwise
> -		 * don't trust the iir, setup a timer to kick the UART
> -		 * on a regular basis.
> -		 */
> -		if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) ||
> -		    up->port.flags & UPF_BUG_THRE) {
> -			up->bugs |= UART_BUG_THRE;
> -		}
> -	}
> +	serial8250_THRE_test(port);
>  
>  	up->ops->setup_timer(up);
>  
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels()
  2025-06-11 10:03 ` [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels() Jiri Slaby (SUSE)
@ 2025-06-11 12:07   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:07 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4066 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_startup() contains peculiar trigger levels setup for
> special ports (16850, ALTR_16550_*). Move this away to a separate
> function: serial8250_set_TRG_levels().
> 
> And use switch-case instead of 'if's.

At this point of series I was already expecting this will come. :-)
Another nice cleanup.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 77 +++++++++++++++--------------
>  1 file changed, 41 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 21ff56a31b56..c09a90b38d8f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2159,6 +2159,46 @@ static void serial8250_startup_special(struct uart_port *port)
>  	}
>  }
>  
> +static void serial8250_set_TRG_levels(struct uart_port *port)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	switch (port->type) {
> +	/* For a XR16C850, we need to set the trigger levels */
> +	case PORT_16850: {
> +		u8 fctr;
> +
> +		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
> +
> +		fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
> +		fctr |= UART_FCTR_TRGD;
> +		serial_port_out(port, UART_FCTR, fctr | UART_FCTR_RX);
> +		serial_port_out(port, UART_TRG, UART_TRG_96);
> +		serial_port_out(port, UART_FCTR, fctr | UART_FCTR_TX);
> +		serial_port_out(port, UART_TRG, UART_TRG_96);
> +
> +		serial_port_out(port, UART_LCR, 0);
> +		break;
> +	}
> +	/* For the Altera 16550 variants, set TX threshold trigger level. */
> +	case PORT_ALTR_16550_F32:
> +	case PORT_ALTR_16550_F64:
> +	case PORT_ALTR_16550_F128:
> +		if (port->fifosize <= 1)
> +			return;
> +
> +		/* Bounds checking of TX threshold (valid 0 to fifosize-2) */
> +		if (up->tx_loadsz < 2 || up->tx_loadsz > port->fifosize) {
> +			dev_err(port->dev, "TX FIFO Threshold errors, skipping\n");
> +			return;
> +		}
> +		serial_port_out(port, UART_ALTR_AFR, UART_ALTR_EN_TXFIFO_LW);
> +		serial_port_out(port, UART_ALTR_TX_LOW, port->fifosize - up->tx_loadsz);
> +		port->handle_irq = serial8250_tx_threshold_handle_irq;
> +		break;
> +	}
> +}
> +
>  int serial8250_do_startup(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
> @@ -2208,42 +2248,7 @@ int serial8250_do_startup(struct uart_port *port)
>  		goto out;
>  	}
>  
> -	/*
> -	 * For a XR16C850, we need to set the trigger levels
> -	 */
> -	if (port->type == PORT_16850) {
> -		unsigned char fctr;
> -
> -		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
> -
> -		fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
> -		serial_port_out(port, UART_FCTR,
> -				fctr | UART_FCTR_TRGD | UART_FCTR_RX);
> -		serial_port_out(port, UART_TRG, UART_TRG_96);
> -		serial_port_out(port, UART_FCTR,
> -				fctr | UART_FCTR_TRGD | UART_FCTR_TX);
> -		serial_port_out(port, UART_TRG, UART_TRG_96);
> -
> -		serial_port_out(port, UART_LCR, 0);
> -	}
> -
> -	/*
> -	 * For the Altera 16550 variants, set TX threshold trigger level.
> -	 */
> -	if (((port->type == PORT_ALTR_16550_F32) ||
> -	     (port->type == PORT_ALTR_16550_F64) ||
> -	     (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) {
> -		/* Bounds checking of TX threshold (valid 0 to fifosize-2) */
> -		if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) {
> -			dev_err(port->dev, "TX FIFO Threshold errors, skipping\n");
> -		} else {
> -			serial_port_out(port, UART_ALTR_AFR,
> -					UART_ALTR_EN_TXFIFO_LW);
> -			serial_port_out(port, UART_ALTR_TX_LOW,
> -					port->fifosize - up->tx_loadsz);
> -			port->handle_irq = serial8250_tx_threshold_handle_irq;
> -		}
> -	}
> +	serial8250_set_TRG_levels(port);
>  
>  	/* Check if we need to have shared IRQs */
>  	if (port->irq && (up->port.flags & UPF_SHARE_IRQ))
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 16/33] serial: 8250: extract serial8250_initialize()
  2025-06-11 10:03 ` [PATCH 16/33] serial: 8250: extract serial8250_initialize() Jiri Slaby (SUSE)
@ 2025-06-11 12:19   ` Ilpo Järvinen
  2025-06-23  6:59     ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:19 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_startup() initializes the ports in the middle of the
> function. This code can be separated to serial8250_initialize(), so that
> serial8250_do_startup() can be readable again.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 103 ++++++++++++++--------------
>  1 file changed, 50 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 5466286bb44f..6851c197b31d 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2247,13 +2247,59 @@ static void serial8250_THRE_test(struct uart_port *port)
>  		up->bugs |= UART_BUG_THRE;
>  }
>  
> -int serial8250_do_startup(struct uart_port *port)
> +static void serial8250_initialize(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
>  	unsigned long flags;
> -	unsigned char iir;
> +	bool lsr_TEMT, iir_NOINT;

Has the coding style guidance changed at some point to be more liberal 
about lower/uppercase? To me it looks entirely unnecessary to capitalize 
these.

> +	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
> +
> +	uart_port_lock_irqsave(port, &flags);
> +	if (port->flags & UPF_FOURPORT) {
> +		if (!port->irq)
> +			port->mctrl |= TIOCM_OUT1;

I assume you're moving this too in some later patch.

I've no idea why drivers/tty/serial/sunsu.c checks for that flag as well.

> +	} else {
> +		/* Most PC uarts need OUT2 raised to enable interrupts. */
> +		if (port->irq)
> +			port->mctrl |= TIOCM_OUT2;
> +	}
> +
> +	serial8250_set_mctrl(port, port->mctrl);
> +
> +	/*
> +	 * Serial over Lan (SoL) hack:
> +	 * Intel 8257x Gigabit ethernet chips have a 16550 emulation, to be used for Serial Over
> +	 * Lan.  Those chips take a longer time than a normal serial device to signalize that a
> +	 * transmission data was queued. Due to that, the above test generally fails. One solution
> +	 * would be to delay the reading of iir. However, this is not reliable, since the timeout is

Ironically, you capitalized the variable names but here it still says 
"iir". IIRC, some comments in the other patches too have lowercased 
references to registers.

> +	 * variable. So, let's just don't test if we receive TX irq.  This way, we'll never enable
> +	 * UART_BUG_TXEN.
> +	 */
> +	if (!(port->quirks & UPQ_NO_TXEN_TEST)) {
> +		/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
> +		serial_port_out(port, UART_IER, UART_IER_THRI);
> +		lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
> +		iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> +		serial_port_out(port, UART_IER, 0);
> +
> +		if (lsr_TEMT && iir_NOINT) {
> +			if (!(up->bugs & UART_BUG_TXEN)) {
> +				up->bugs |= UART_BUG_TXEN;
> +				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
> +			}
> +		} else {
> +			up->bugs &= ~UART_BUG_TXEN;

Is this necessary at all as the line above is the only place setting this 
flag (AFAICT)? Maybe you address this in some later patch, if that's the 
case, please ignore my comment. :-)

> +		}
> +	}
> +
> +	uart_port_unlock_irqrestore(port, flags);
> +}

-- 
 i.



> +
> +int serial8250_do_startup(struct uart_port *port)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
>  	int retval;
> -	u16 lsr;
>  
>  	if (!port->fifosize)
>  		port->fifosize = uart_config[port->type].fifo_size;
> @@ -2310,56 +2356,7 @@ int serial8250_do_startup(struct uart_port *port)
>  
>  	up->ops->setup_timer(up);
>  
> -	/*
> -	 * Now, initialize the UART
> -	 */
> -	serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
> -
> -	uart_port_lock_irqsave(port, &flags);
> -	if (up->port.flags & UPF_FOURPORT) {
> -		if (!up->port.irq)
> -			up->port.mctrl |= TIOCM_OUT1;
> -	} else
> -		/*
> -		 * Most PC uarts need OUT2 raised to enable interrupts.
> -		 */
> -		if (port->irq)
> -			up->port.mctrl |= TIOCM_OUT2;
> -
> -	serial8250_set_mctrl(port, port->mctrl);
> -
> -	/*
> -	 * Serial over Lan (SoL) hack:
> -	 * Intel 8257x Gigabit ethernet chips have a 16550 emulation, to be
> -	 * used for Serial Over Lan.  Those chips take a longer time than a
> -	 * normal serial device to signalize that a transmission data was
> -	 * queued. Due to that, the above test generally fails. One solution
> -	 * would be to delay the reading of iir. However, this is not
> -	 * reliable, since the timeout is variable. So, let's just don't
> -	 * test if we receive TX irq.  This way, we'll never enable
> -	 * UART_BUG_TXEN.
> -	 */
> -	if (!(up->port.quirks & UPQ_NO_TXEN_TEST)) {
> -		/*
> -		 * Do a quick test to see if we receive an interrupt when we
> -		 * enable the TX irq.
> -		 */
> -		serial_port_out(port, UART_IER, UART_IER_THRI);
> -		lsr = serial_port_in(port, UART_LSR);
> -		iir = serial_port_in(port, UART_IIR);
> -		serial_port_out(port, UART_IER, 0);
> -
> -		if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
> -			if (!(up->bugs & UART_BUG_TXEN)) {
> -				up->bugs |= UART_BUG_TXEN;
> -				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
> -			}
> -		} else {
> -			up->bugs &= ~UART_BUG_TXEN;
> -		}
> -	}
> -
> -	uart_port_unlock_irqrestore(port, flags);
> +	serial8250_initialize(port);
>  
>  	/*
>  	 * Clear the interrupt registers again for luck, and clear the
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts()
  2025-06-11 10:03 ` [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts() Jiri Slaby (SUSE)
@ 2025-06-11 12:27   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:27 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 3241 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> On three places in 8250_port.c, the interrupts are cleared by reading 4
> registers. Extract this to a separate function:
> serial8250_clear_interrupts(). And call it from all the places.
> 
> Note autoconfig_irq() now uses serial_port_in() instead of serial_in().
> But they are the same, in fact (modulo parameter).
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 6851c197b31d..a73f4db22feb 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -705,6 +705,15 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
>  	serial8250_rpm_put(p);
>  }
>  
> +/* Clear the interrupt registers. */
> +static void serial8250_clear_interrupts(struct uart_port *port)
> +{
> +	serial_port_in(port, UART_LSR);
> +	serial_port_in(port, UART_RX);
> +	serial_port_in(port, UART_IIR);
> +	serial_port_in(port, UART_MSR);

Okay, although I'd call some of these "status" registers. Yes, one can use 
their status flags to trigger interrupts but it's not immediately obvious 
to me if the calling code really _only_ wants to clear interrupts or if it 
is also clearing stale status bits even if that's not explicitly 
mentioned. Especially, the one callsite which zeroes also the stored 
flags looks like it wants to get rid of stale status too (some status 
bits might have not yet migrated from the register to the cached flags).

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>


> +}
> +
>  static void serial8250_clear_IER(struct uart_8250_port *up)
>  {
>  	if (up->capabilities & UART_CAP_UUE)
> @@ -1275,10 +1284,7 @@ static void autoconfig_irq(struct uart_8250_port *up)
>  	uart_port_lock_irq(port);
>  	serial_out(up, UART_IER, UART_IER_ALL_INTR);
>  	uart_port_unlock_irq(port);
> -	serial_in(up, UART_LSR);
> -	serial_in(up, UART_RX);
> -	serial_in(up, UART_IIR);
> -	serial_in(up, UART_MSR);
> +	serial8250_clear_interrupts(port);
>  	serial_out(up, UART_TX, 0xFF);
>  	udelay(20);
>  	irq = probe_irq_off(irqs);
> @@ -2322,13 +2328,7 @@ int serial8250_do_startup(struct uart_port *port)
>  	 */
>  	serial8250_clear_fifos(up);
>  
> -	/*
> -	 * Clear the interrupt registers.
> -	 */
> -	serial_port_in(port, UART_LSR);
> -	serial_port_in(port, UART_RX);
> -	serial_port_in(port, UART_IIR);
> -	serial_port_in(port, UART_MSR);
> +	serial8250_clear_interrupts(port);
>  
>  	/*
>  	 * At this point, there's no way the LSR could still be 0xff;
> @@ -2363,10 +2363,7 @@ int serial8250_do_startup(struct uart_port *port)
>  	 * saved flags to avoid getting false values from polling
>  	 * routines or the previous session.
>  	 */
> -	serial_port_in(port, UART_LSR);
> -	serial_port_in(port, UART_RX);
> -	serial_port_in(port, UART_IIR);
> -	serial_port_in(port, UART_MSR);
> +	serial8250_clear_interrupts(port);
>  	up->lsr_saved_flags = 0;
>  	up->msr_saved_flags = 0;
>  
> 

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 18/33] serial: 8250: extract serial8250_set_mini()
  2025-06-11 10:03 ` [PATCH 18/33] serial: 8250: extract serial8250_set_mini() Jiri Slaby (SUSE)
@ 2025-06-11 12:29   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:29 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 2146 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of CSIZE for UART_CAP_MINI ports.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index a73f4db22feb..edfbaa6b7a1b 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2670,6 +2670,22 @@ void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk)
>  }
>  EXPORT_SYMBOL_GPL(serial8250_update_uartclk);
>  
> +static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	if (!(up->capabilities & UART_CAP_MINI))
> +		return;
> +
> +	termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR);
> +
> +	tcflag_t csize = termios->c_cflag & CSIZE;
> +	if (csize == CS5 || csize == CS6) {
> +		termios->c_cflag &= ~CSIZE;
> +		termios->c_cflag |= CS7;
> +	}
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2679,14 +2695,8 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	unsigned long flags;
>  	unsigned int baud, quot, frac = 0;
>  
> -	if (up->capabilities & UART_CAP_MINI) {
> -		termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR);
> -		if ((termios->c_cflag & CSIZE) == CS5 ||
> -		    (termios->c_cflag & CSIZE) == CS6)
> -			termios->c_cflag = (termios->c_cflag & ~CSIZE) | CS7;
> -	}
> +	serial8250_set_mini(port, termios);
>  	cval = serial8250_compute_lcr(up, termios->c_cflag);
> -
>  	baud = serial8250_get_baud_rate(port, termios, old);
>  	quot = serial8250_get_divisor(port, baud, &frac);
>  
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed()
  2025-06-11 10:03 ` [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed() Jiri Slaby (SUSE)
@ 2025-06-11 12:34   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:34 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 2067 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of trigger level for slow speeds.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index edfbaa6b7a1b..52385314c426 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2686,6 +2686,24 @@ static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios
>  	}
>  }
>  
> +static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct ktermios *termios,
> +						  unsigned int baud)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	if (!(up->capabilities & UART_CAP_FIFO))
> +		return;
> +	if (port->fifosize <= 1)
> +		return;
> +	if (baud >= 2400)
> +		return;
> +	if (up->dma)

Nit, I'd have put the DMA check before the speed check.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

> +		return;
> +
> +	up->fcr &= ~UART_FCR_TRIGGER_MASK;
> +	up->fcr |= UART_FCR_TRIGGER_1;
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2710,13 +2728,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	uart_port_lock_irqsave(port, &flags);
>  
>  	up->lcr = cval;					/* Save computed LCR */
> -
> -	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
> -		if (baud < 2400 && !up->dma) {
> -			up->fcr &= ~UART_FCR_TRIGGER_MASK;
> -			up->fcr |= UART_FCR_TRIGGER_1;
> -		}
> -	}
> +	serial8250_set_trigger_for_slow_speed(port, termios, baud);
>  
>  	/*
>  	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
> 

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 20/33] serial: 8250: extract serial8250_set_afe()
  2025-06-11 10:03 ` [PATCH 20/33] serial: 8250: extract serial8250_set_afe() Jiri Slaby (SUSE)
@ 2025-06-11 12:35   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:35 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2299 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of MCR for UART_CAP_AFE ports.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 32 +++++++++++++++--------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 52385314c426..b15371838366 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2704,6 +2704,22 @@ static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct
>  	up->fcr |= UART_FCR_TRIGGER_1;
>  }
>  
> +/*
> + * MCR-based auto flow control. When AFE is enabled, RTS will be deasserted when the receive FIFO
> + * contains more characters than the trigger, or the MCR RTS bit is cleared.
> + */
> +static void serial8250_set_afe(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	if (!(up->capabilities & UART_CAP_AFE))
> +		return;
> +
> +	up->mcr &= ~UART_MCR_AFE;
> +	if (termios->c_cflag & CRTSCTS)
> +		up->mcr |= UART_MCR_AFE;
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2729,21 +2745,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  
>  	up->lcr = cval;					/* Save computed LCR */
>  	serial8250_set_trigger_for_slow_speed(port, termios, baud);
> -
> -	/*
> -	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
> -	 * deasserted when the receive FIFO contains more characters than
> -	 * the trigger, or the MCR RTS bit is cleared.
> -	 */
> -	if (up->capabilities & UART_CAP_AFE) {
> -		up->mcr &= ~UART_MCR_AFE;
> -		if (termios->c_cflag & CRTSCTS)
> -			up->mcr |= UART_MCR_AFE;
> -	}
> -
> -	/*
> -	 * Update the per-port timeout.
> -	 */
> +	serial8250_set_afe(port, termios);
>  	uart_update_timeout(port, termios->c_cflag, baud);
>  
>  	/*
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores
  2025-06-11 10:03 ` [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores Jiri Slaby (SUSE)
@ 2025-06-11 12:43   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:43 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of ignore_status_mask and read_status_mask.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 67 ++++++++++++++---------------
>  1 file changed, 33 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index b15371838366..6bb7f004d607 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2720,6 +2720,38 @@ static void serial8250_set_afe(struct uart_port *port, struct ktermios *termios)
>  		up->mcr |= UART_MCR_AFE;
>  }
>  
> +static void serial8250_set_errors_and_ignores(struct uart_port *port, struct ktermios *termios)
> +{
> +	/*
> +	 * Specify which conditions may be considered for error handling and the ignoring of
> +	 * characters. The actual ignoring of characters only occurs if the bit is set in
> +	 * @ignore_status_mask as well.
> +	 */
> +	port->read_status_mask = UART_LSR_OE | UART_LSR_DR;
> +	if (termios->c_iflag & INPCK)
> +		port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
> +	if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
> +		port->read_status_mask |= UART_LSR_BI;
> +
> +	/* Characters to ignore */
> +	port->ignore_status_mask = 0;
> +	if (termios->c_iflag & IGNPAR)
> +		port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
> +	if (termios->c_iflag & IGNBRK) {
> +		port->ignore_status_mask |= UART_LSR_BI;
> +		/*
> +		 * If we're ignoring parity and break indicators, ignore overruns too (for real raw
> +		 * support).
> +		 */
> +		if (termios->c_iflag & IGNPAR)
> +			port->ignore_status_mask |= UART_LSR_OE;
> +	}
> +
> +	/* ignore all characters if CREAD is not set */
> +	if ((termios->c_cflag & CREAD) == 0)
> +		port->ignore_status_mask |= UART_LSR_DR;
> +}

Can this function be used also by 8250_omap.c or made reusable if not 
directly possible?

Inside non-8250 drivers there might even more duplication related to 
these. There might also be some duplication on the read character side
as I've feeling I've seen plenty of copy paste related these flags (or 
what looked copy paste).

>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2747,40 +2779,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	serial8250_set_trigger_for_slow_speed(port, termios, baud);
>  	serial8250_set_afe(port, termios);
>  	uart_update_timeout(port, termios->c_cflag, baud);
> -
> -	/*
> -	 * Specify which conditions may be considered for error
> -	 * handling and the ignoring of characters. The actual
> -	 * ignoring of characters only occurs if the bit is set
> -	 * in @ignore_status_mask as well.
> -	 */
> -	port->read_status_mask = UART_LSR_OE | UART_LSR_DR;
> -	if (termios->c_iflag & INPCK)
> -		port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
> -	if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
> -		port->read_status_mask |= UART_LSR_BI;
> -
> -	/*
> -	 * Characters to ignore
> -	 */
> -	port->ignore_status_mask = 0;
> -	if (termios->c_iflag & IGNPAR)
> -		port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
> -	if (termios->c_iflag & IGNBRK) {
> -		port->ignore_status_mask |= UART_LSR_BI;
> -		/*
> -		 * If we're ignoring parity and break indicators,
> -		 * ignore overruns too (for real raw support).
> -		 */
> -		if (termios->c_iflag & IGNPAR)
> -			port->ignore_status_mask |= UART_LSR_OE;
> -	}
> -
> -	/*
> -	 * ignore all characters if CREAD is not set
> -	 */
> -	if ((termios->c_cflag & CREAD) == 0)
> -		port->ignore_status_mask |= UART_LSR_DR;
> +	serial8250_set_errors_and_ignores(port, termios);
>  
>  	/*
>  	 * CTS flow control flag and modem status interrupts
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 22/33] serial: 8250: extract serial8250_set_ier()
  2025-06-11 10:03 ` [PATCH 22/33] serial: 8250: extract serial8250_set_ier() Jiri Slaby (SUSE)
@ 2025-06-11 12:47   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:47 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2387 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of IER.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 31 ++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 6bb7f004d607..2c045a4369fc 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2752,6 +2752,22 @@ static void serial8250_set_errors_and_ignores(struct uart_port *port, struct kte
>  		port->ignore_status_mask |= UART_LSR_DR;
>  }
>  
> +static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	/* CTS flow control flag and modem status interrupts */
> +	up->ier &= ~UART_IER_MSI;
> +	if (!(up->bugs & UART_BUG_NOMSR) && UART_ENABLE_MS(&up->port, termios->c_cflag))
> +		up->ier |= UART_IER_MSI;
> +	if (up->capabilities & UART_CAP_UUE)
> +		up->ier |= UART_IER_UUE;
> +	if (up->capabilities & UART_CAP_RTOIE)
> +		up->ier |= UART_IER_RTOIE;
> +
> +	serial_port_out(port, UART_IER, up->ier);
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2780,20 +2796,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	serial8250_set_afe(port, termios);
>  	uart_update_timeout(port, termios->c_cflag, baud);
>  	serial8250_set_errors_and_ignores(port, termios);
> -
> -	/*
> -	 * CTS flow control flag and modem status interrupts
> -	 */
> -	up->ier &= ~UART_IER_MSI;
> -	if (!(up->bugs & UART_BUG_NOMSR) &&
> -			UART_ENABLE_MS(&up->port, termios->c_cflag))
> -		up->ier |= UART_IER_MSI;
> -	if (up->capabilities & UART_CAP_UUE)
> -		up->ier |= UART_IER_UUE;
> -	if (up->capabilities & UART_CAP_RTOIE)
> -		up->ier |= UART_IER_RTOIE;
> -
> -	serial_port_out(port, UART_IER, up->ier);
> +	serial8250_set_ier(port, termios);
>  
>  	if (up->capabilities & UART_CAP_EFR) {
>  		unsigned char efr = 0;
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-11 10:03 ` [PATCH 23/33] serial: 8250: extract serial8250_set_efr() Jiri Slaby (SUSE)
@ 2025-06-11 12:58   ` Ilpo Järvinen
  2025-06-12 10:01     ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 12:58 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of EFR for UART_CAP_EFR ports.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
>  1 file changed, 25 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 2c045a4369fc..0f16398cc86f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
>  	serial_port_out(port, UART_IER, up->ier);
>  }
>  
> +static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	u8 efr_reg = UART_EFR;
> +	u8 efr = 0;
> +
> +	if (!(up->capabilities & UART_CAP_EFR))
> +		return;
> +
> +	/*
> +	 * TI16C752/Startech hardware flow control.  FIXME:
> +	 * - TI16C752 requires control thresholds to be set.
> +	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
> +	 */
> +	if (termios->c_cflag & CRTSCTS)
> +		efr |= UART_EFR_CTS;
> +
> +	if (port->flags & UPF_EXAR_EFR)

I wonder if it is possible to trigger this at all? Only 8250_exar.c sets 
this flag and does not contain have UART_CAP_EFR at all (nor uses 
UPF_BOOT_AUTOCONF)??

> +		efr_reg = UART_XR_EFR;
> +
> +	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
> +	serial_port_out(port, efr_reg, efr);
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2797,24 +2821,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	uart_update_timeout(port, termios->c_cflag, baud);
>  	serial8250_set_errors_and_ignores(port, termios);
>  	serial8250_set_ier(port, termios);
> -
> -	if (up->capabilities & UART_CAP_EFR) {
> -		unsigned char efr = 0;
> -		/*
> -		 * TI16C752/Startech hardware flow control.  FIXME:
> -		 * - TI16C752 requires control thresholds to be set.
> -		 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
> -		 */
> -		if (termios->c_cflag & CRTSCTS)
> -			efr |= UART_EFR_CTS;
> -
> -		serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
> -		if (port->flags & UPF_EXAR_EFR)
> -			serial_port_out(port, UART_XR_EFR, efr);
> -		else
> -			serial_port_out(port, UART_EFR, efr);
> -	}
> -
> +	serial8250_set_efr(port, termios);
>  	serial8250_set_divisor(port, baud, quot, frac);
>  
>  	/*
> 

-- 
 i.



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 24/33] serial: 8250: extract serial8250_set_fcr()
  2025-06-11 10:03 ` [PATCH 24/33] serial: 8250: extract serial8250_set_fcr() Jiri Slaby (SUSE)
@ 2025-06-11 13:01   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:01 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2788 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of FCR.
> 
> serial8250_do_set_termios() looks sane at this point.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/8250/8250_port.c | 41 ++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 0f16398cc86f..85b75ff0699e 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2792,6 +2792,30 @@ static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
>  	serial_port_out(port, efr_reg, efr);
>  }
>  
> +static void serial8250_set_fcr(struct uart_port *port, struct ktermios *termios)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	bool is_16750 = port->type == PORT_16750;
> +
> +	if (is_16750)
> +		serial_port_out(port, UART_FCR, up->fcr);
> +
> +	/*
> +	 * LCR DLAB must be reset to enable 64-byte FIFO mode. If the FCR is written without DLAB
> +	 * set, this mode will be disabled.
> +	 */
> +	serial_port_out(port, UART_LCR, up->lcr);
> +
> +	if (is_16750)
> +		return;
> +
> +	/* emulated UARTs (Lucent Venus 167x) need two steps */
> +	if (up->fcr & UART_FCR_ENABLE_FIFO)
> +		serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
> +
> +	serial_port_out(port, UART_FCR, up->fcr);
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2823,22 +2847,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	serial8250_set_ier(port, termios);
>  	serial8250_set_efr(port, termios);
>  	serial8250_set_divisor(port, baud, quot, frac);
> -
> -	/*
> -	 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
> -	 * is written without DLAB set, this mode will be disabled.
> -	 */
> -	if (port->type == PORT_16750)
> -		serial_port_out(port, UART_FCR, up->fcr);
> -
> -	serial_port_out(port, UART_LCR, up->lcr);	/* reset DLAB */
> -	if (port->type != PORT_16750) {
> -		/* emulated UARTs (Lucent Venus 167x) need two steps */
> -		if (up->fcr & UART_FCR_ENABLE_FIFO)
> -			serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
> -		serial_port_out(port, UART_FCR, up->fcr);	/* set fcr */
> -	}
> +	serial8250_set_fcr(port, termios);
>  	serial8250_set_mctrl(port, port->mctrl);
> +
>  	uart_port_unlock_irqrestore(port, flags);
>  	serial8250_rpm_put(up);
>  
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 25/33] serial: 8250: lcr compute cleanup
  2025-06-11 10:03 ` [PATCH 25/33] serial: 8250: lcr compute cleanup Jiri Slaby (SUSE)
@ 2025-06-11 13:03   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:03 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 2685 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> * use 'lcr' as variable containing the "computed value" (and not 'cval')
> * use 'u8' for the type (and not 'unsigned char')
> * drop useless comment
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/8250/8250_port.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 85b75ff0699e..2af89038e50e 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2547,23 +2547,20 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
>  	return serial8250_do_get_divisor(port, baud, frac);
>  }
>  
> -static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
> -					    tcflag_t c_cflag)
> +static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, tcflag_t c_cflag)
>  {
> -	unsigned char cval;
> -
> -	cval = UART_LCR_WLEN(tty_get_char_size(c_cflag));
> +	u8 lcr = UART_LCR_WLEN(tty_get_char_size(c_cflag));
>  
>  	if (c_cflag & CSTOPB)
> -		cval |= UART_LCR_STOP;
> +		lcr |= UART_LCR_STOP;
>  	if (c_cflag & PARENB)
> -		cval |= UART_LCR_PARITY;
> +		lcr |= UART_LCR_PARITY;
>  	if (!(c_cflag & PARODD))
> -		cval |= UART_LCR_EPAR;
> +		lcr |= UART_LCR_EPAR;
>  	if (c_cflag & CMSPAR)
> -		cval |= UART_LCR_SPAR;
> +		lcr |= UART_LCR_SPAR;
>  
> -	return cval;
> +	return lcr;
>  }
>  
>  void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
> @@ -2821,12 +2818,12 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
> -	unsigned char cval;
>  	unsigned long flags;
>  	unsigned int baud, quot, frac = 0;
> +	u8 lcr;
>  
>  	serial8250_set_mini(port, termios);
> -	cval = serial8250_compute_lcr(up, termios->c_cflag);
> +	lcr = serial8250_compute_lcr(up, termios->c_cflag);
>  	baud = serial8250_get_baud_rate(port, termios, old);
>  	quot = serial8250_get_divisor(port, baud, &frac);
>  
> @@ -2839,7 +2836,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	serial8250_rpm_get(up);
>  	uart_port_lock_irqsave(port, &flags);
>  
> -	up->lcr = cval;					/* Save computed LCR */
> +	up->lcr = lcr;
>  	serial8250_set_trigger_for_slow_speed(port, termios, baud);
>  	serial8250_set_afe(port, termios);
>  	uart_update_timeout(port, termios->c_cflag, baud);
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor()
  2025-06-11 10:03 ` [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor() Jiri Slaby (SUSE)
@ 2025-06-11 13:04   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:04 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1589 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> 'frac' is not used in the generic implementation of get_divisor. Drop it
> from there. (Only some port->get_divisor() compute that and receive it
> then to port->set_divisor()).
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 2af89038e50e..6363915a1787 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2481,9 +2481,7 @@ static void serial8250_flush_buffer(struct uart_port *port)
>  		serial8250_tx_dma_flush(up);
>  }
>  
> -static unsigned int serial8250_do_get_divisor(struct uart_port *port,
> -					      unsigned int baud,
> -					      unsigned int *frac)
> +static unsigned int serial8250_do_get_divisor(struct uart_port *port, unsigned int baud)
>  {
>  	upf_t magic_multiplier = port->flags & UPF_MAGIC_MULTIPLIER;
>  	struct uart_8250_port *up = up_to_u8250p(port);
> @@ -2544,7 +2542,7 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
>  	if (port->get_divisor)
>  		return port->get_divisor(port, baud, frac);
>  
> -	return serial8250_do_get_divisor(port, baud, frac);
> +	return serial8250_do_get_divisor(port, baud);
>  }
>  
>  static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, tcflag_t c_cflag)
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info()
  2025-06-11 10:03 ` [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info() Jiri Slaby (SUSE)
@ 2025-06-11 13:09   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:09 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 2668 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> This find-or-create-irq part of the serial_link_irq_chain()'s code is
> logically bounded and self-standing. For easier-to-follow code flow,
> extract the code to a separate function:
> serial_get_or_create_irq_info().
> 
> This allows for an easier found-an-irq handling -- simple jump to the
> 'unlock' label and return. That results in one less 'if' levels.
> 
> Note when using guard()s in the upcoming patchset, the label can dropped
> altogether.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_core.c | 37 ++++++++++++++++++++---------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 7a6050f1c094..d42ceb6ffdc2 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -129,11 +129,15 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
>  	}
>  }
>  
> -static int serial_link_irq_chain(struct uart_8250_port *up)
> +/*
> + * Either:
> + * - find the corresponding info in the hashtable and return it, or
> + * - allocate a new one, add it to the hashtable and return it.
> + */
> +static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up)
>  {
>  	struct hlist_head *h;
>  	struct irq_info *i;
> -	int ret;
>  
>  	mutex_lock(&hash_mutex);
>  
> @@ -141,20 +145,31 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
>  
>  	hlist_for_each_entry(i, h, node)
>  		if (i->irq == up->port.irq)
> -			break;
> +			goto unlock;
>  
> +	i = kzalloc(sizeof(*i), GFP_KERNEL);
>  	if (i == NULL) {
> -		i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
> -		if (i == NULL) {
> -			mutex_unlock(&hash_mutex);
> -			return -ENOMEM;
> -		}
> -		spin_lock_init(&i->lock);
> -		i->irq = up->port.irq;
> -		hlist_add_head(&i->node, h);
> +		i = ERR_PTR(-ENOMEM);
> +		goto unlock;
>  	}
> +	spin_lock_init(&i->lock);
> +	i->irq = up->port.irq;
> +	hlist_add_head(&i->node, h);
> +unlock:
>  	mutex_unlock(&hash_mutex);
>  
> +	return i;
> +}
> +
> +static int serial_link_irq_chain(struct uart_8250_port *up)
> +{
> +	struct irq_info *i;
> +	int ret;
> +
> +	i = serial_get_or_create_irq_info(up);
> +	if (IS_ERR(i))
> +		return PTR_ERR(i);
> +
>  	spin_lock_irq(&i->lock);
>  
>  	if (i->head) {
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

Unrelated to the patch, I didn't like the use of 'i' as a variable name 
to store a struct pointer.

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 28/33] serial: 8250: remove debug prints from ISR
  2025-06-11 10:03 ` [PATCH 28/33] serial: 8250: remove debug prints from ISR Jiri Slaby (SUSE)
@ 2025-06-11 13:09   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:09 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 1045 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> These are useless, we have tracing nowadays.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_core.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index d42ceb6ffdc2..2bac9c7827de 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -71,8 +71,6 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
>  	struct list_head *l, *end = NULL;
>  	int pass_counter = 0, handled = 0;
>  
> -	pr_debug("%s(%d): start\n", __func__, irq);
> -
>  	spin_lock(&i->lock);
>  
>  	l = i->head;
> @@ -97,8 +95,6 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
>  
>  	spin_unlock(&i->lock);
>  
> -	pr_debug("%s(%d): end\n", __func__, irq);
> -
>  	return IRQ_RETVAL(handled);
>  }
>  
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro
  2025-06-11 10:03 ` [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Jiri Slaby (SUSE)
@ 2025-06-11 13:10   ` Ilpo Järvinen
  2025-06-17 11:32   ` Maciej W. Rozycki
  1 sibling, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:10 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 5073 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> DEBUG_AUTOCONF() is always disabled (by "#if 0"), so one would need to
> recompile the kernel to use it. And even if they did, they would find
> out it is broken anyway:
>   error: variable 'scratch' is used uninitialized whenever 'if' condition is false
> 
> Drop it.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 39 ++---------------------------
>  1 file changed, 2 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 6363915a1787..e93bfdac3d0e 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -38,15 +38,6 @@
>  
>  #include "8250.h"
>  
> -/*
> - * Debugging.
> - */
> -#if 0
> -#define DEBUG_AUTOCONF(fmt...)	printk(fmt)
> -#else
> -#define DEBUG_AUTOCONF(fmt...)	do { } while (0)
> -#endif
> -
>  /*
>   * Here we define the default xmit fifo size used for each type of UART.
>   */
> @@ -825,8 +816,6 @@ static void autoconfig_has_efr(struct uart_8250_port *up)
>  	id3 = serial_icr_read(up, UART_ID3);
>  	rev = serial_icr_read(up, UART_REV);
>  
> -	DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
> -
>  	if (id1 == 0x16 && id2 == 0xC9 &&
>  	    (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
>  		up->port.type = PORT_16C950;
> @@ -850,7 +839,6 @@ static void autoconfig_has_efr(struct uart_8250_port *up)
>  	 *  0x14 - XR16C854.
>  	 */
>  	id1 = autoconfig_read_divisor_id(up);
> -	DEBUG_AUTOCONF("850id=%04x ", id1);
>  
>  	id2 = id1 >> 8;
>  	if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
> @@ -937,7 +925,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
>  	if (serial_in(up, UART_EFR) == 0) {
>  		serial_out(up, UART_EFR, 0xA8);
>  		if (serial_in(up, UART_EFR) != 0) {
> -			DEBUG_AUTOCONF("EFRv1 ");
>  			up->port.type = PORT_16650;
>  			up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
>  		} else {
> @@ -950,8 +937,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
>  
>  			if (status1 == UART_IIR_FIFO_ENABLED_16750)
>  				up->port.type = PORT_16550A_FSL64;
> -			else
> -				DEBUG_AUTOCONF("Motorola 8xxx DUART ");
>  		}
>  		serial_out(up, UART_EFR, 0);
>  		return;
> @@ -963,7 +948,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
>  	 */
>  	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
>  	if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
> -		DEBUG_AUTOCONF("EFRv2 ");
>  		autoconfig_has_efr(up);
>  		return;
>  	}
> @@ -1026,8 +1010,6 @@ static void autoconfig_16550a(struct uart_8250_port *up)
>  
>  	serial_out(up, UART_LCR, 0);
>  
> -	DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
> -
>  	if (status1 == UART_IIR_FIFO_ENABLED_16550A &&
>  	    status2 == UART_IIR_FIFO_ENABLED_16750) {
>  		up->port.type = PORT_16750;
> @@ -1056,17 +1038,10 @@ static void autoconfig_16550a(struct uart_8250_port *up)
>  			 * It's an Xscale.
>  			 * We'll leave the UART_IER_UUE bit set to 1 (enabled).
>  			 */
> -			DEBUG_AUTOCONF("Xscale ");
>  			up->port.type = PORT_XSCALE;
>  			up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE;
>  			return;
>  		}
> -	} else {
> -		/*
> -		 * If we got here we couldn't force the IER_UUE bit to 0.
> -		 * Log it and continue.
> -		 */
> -		DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
>  	}
>  	serial_out(up, UART_IER, iersave);
>  
> @@ -1098,9 +1073,6 @@ static void autoconfig(struct uart_8250_port *up)
>  	if (!port->iobase && !port->mapbase && !port->membase)
>  		return;
>  
> -	DEBUG_AUTOCONF("%s: autoconf (0x%04lx, 0x%p): ",
> -		       port->name, port->iobase, port->membase);
> -
>  	/*
>  	 * We really do need global IRQs disabled here - we're going to
>  	 * be frobbing the chips IRQ enable register to see if it exists.
> @@ -1147,9 +1119,7 @@ static void autoconfig(struct uart_8250_port *up)
>  			 * We failed; there's nothing here
>  			 */
>  			uart_port_unlock_irqrestore(port, flags);
> -			DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
> -				       scratch2, scratch3);
> -			goto out;
> +			return;
>  		}
>  	}
>  
> @@ -1171,9 +1141,7 @@ static void autoconfig(struct uart_8250_port *up)
>  		serial8250_out_MCR(up, save_mcr);
>  		if (status1 != (UART_MSR_DCD | UART_MSR_CTS)) {
>  			uart_port_unlock_irqrestore(port, flags);
> -			DEBUG_AUTOCONF("LOOP test failed (%02x) ",
> -				       status1);
> -			goto out;
> +			return;
>  		}
>  	}
>  
> @@ -1241,9 +1209,6 @@ static void autoconfig(struct uart_8250_port *up)
>  		dev_warn(port->dev, "detected caps %08x should be %08x\n",
>  			 old_capabilities, up->capabilities);
>  	}
> -out:
> -	DEBUG_AUTOCONF("iir=%d ", scratch);
> -	DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name);
>  }
>  
>  static void autoconfig_irq(struct uart_8250_port *up)
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-11 10:03 ` [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Jiri Slaby (SUSE)
@ 2025-06-11 13:21   ` Ilpo Järvinen
  2025-06-18  5:48   ` Andy Shevchenko
  1 sibling, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:21 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 10226 bytes --]

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> There is no point in a long 'if' in serial8250_register_8250_port() to
> just return ENOSPC for PORT_8250_CIR ports. Invert the condition and
> return immediately.
> 
> 'gpios' variable was moved to its set location.
> 
> And return ENODEV instead of ENOSPC. The latter is a leftover from the
> previous find-uart 'if'. The former makes a lot more sense in this case.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_core.c | 253 ++++++++++++++--------------
>  1 file changed, 127 insertions(+), 126 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 2bac9c7827de..10f25bae9f46 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -725,139 +725,140 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
>  		nr_uarts++;
>  	}
>  
> -	if (uart->port.type != PORT_8250_CIR) {
> -		struct mctrl_gpios *gpios;
> -
> -		if (uart->port.dev)
> -			uart_remove_one_port(&serial8250_reg, &uart->port);
> -
> -		uart->port.ctrl_id	= up->port.ctrl_id;
> -		uart->port.port_id	= up->port.port_id;
> -		uart->port.iobase       = up->port.iobase;
> -		uart->port.membase      = up->port.membase;
> -		uart->port.irq          = up->port.irq;
> -		uart->port.irqflags     = up->port.irqflags;
> -		uart->port.uartclk      = up->port.uartclk;
> -		uart->port.fifosize     = up->port.fifosize;
> -		uart->port.regshift     = up->port.regshift;
> -		uart->port.iotype       = up->port.iotype;
> -		uart->port.flags        = up->port.flags | UPF_BOOT_AUTOCONF;
> -		uart->bugs		= up->bugs;
> -		uart->port.mapbase      = up->port.mapbase;
> -		uart->port.mapsize      = up->port.mapsize;
> -		uart->port.private_data = up->port.private_data;
> -		uart->tx_loadsz		= up->tx_loadsz;
> -		uart->capabilities	= up->capabilities;
> -		uart->port.throttle	= up->port.throttle;
> -		uart->port.unthrottle	= up->port.unthrottle;
> -		uart->port.rs485_config	= up->port.rs485_config;
> -		uart->port.rs485_supported = up->port.rs485_supported;
> -		uart->port.rs485	= up->port.rs485;
> -		uart->rs485_start_tx	= up->rs485_start_tx;
> -		uart->rs485_stop_tx	= up->rs485_stop_tx;
> -		uart->lsr_save_mask	= up->lsr_save_mask;
> -		uart->dma		= up->dma;
> -
> -		/* Take tx_loadsz from fifosize if it wasn't set separately */
> -		if (uart->port.fifosize && !uart->tx_loadsz)
> -			uart->tx_loadsz = uart->port.fifosize;
> -
> -		if (up->port.dev) {
> -			uart->port.dev = up->port.dev;
> -			ret = uart_get_rs485_mode(&uart->port);
> -			if (ret)
> -				goto err;
> -		}
> +	if (uart->port.type == PORT_8250_CIR) {
> +		ret = -ENODEV;
> +		goto unlock;
> +	}
>  
> -		if (up->port.flags & UPF_FIXED_TYPE)
> -			uart->port.type = up->port.type;
> +	if (uart->port.dev)
> +		uart_remove_one_port(&serial8250_reg, &uart->port);
> +
> +	uart->port.ctrl_id	= up->port.ctrl_id;
> +	uart->port.port_id	= up->port.port_id;
> +	uart->port.iobase       = up->port.iobase;
> +	uart->port.membase      = up->port.membase;
> +	uart->port.irq          = up->port.irq;
> +	uart->port.irqflags     = up->port.irqflags;
> +	uart->port.uartclk      = up->port.uartclk;
> +	uart->port.fifosize     = up->port.fifosize;
> +	uart->port.regshift     = up->port.regshift;
> +	uart->port.iotype       = up->port.iotype;
> +	uart->port.flags        = up->port.flags | UPF_BOOT_AUTOCONF;
> +	uart->bugs		= up->bugs;
> +	uart->port.mapbase      = up->port.mapbase;
> +	uart->port.mapsize      = up->port.mapsize;
> +	uart->port.private_data = up->port.private_data;
> +	uart->tx_loadsz		= up->tx_loadsz;
> +	uart->capabilities	= up->capabilities;
> +	uart->port.throttle	= up->port.throttle;
> +	uart->port.unthrottle	= up->port.unthrottle;
> +	uart->port.rs485_config	= up->port.rs485_config;
> +	uart->port.rs485_supported = up->port.rs485_supported;
> +	uart->port.rs485	= up->port.rs485;
> +	uart->rs485_start_tx	= up->rs485_start_tx;
> +	uart->rs485_stop_tx	= up->rs485_stop_tx;
> +	uart->lsr_save_mask	= up->lsr_save_mask;
> +	uart->dma		= up->dma;
> +
> +	/* Take tx_loadsz from fifosize if it wasn't set separately */
> +	if (uart->port.fifosize && !uart->tx_loadsz)
> +		uart->tx_loadsz = uart->port.fifosize;
> +
> +	if (up->port.dev) {
> +		uart->port.dev = up->port.dev;
> +		ret = uart_get_rs485_mode(&uart->port);
> +		if (ret)
> +			goto err;
> +	}
>  
> -		/*
> -		 * Only call mctrl_gpio_init(), if the device has no ACPI
> -		 * companion device
> -		 */
> -		if (!has_acpi_companion(uart->port.dev)) {
> -			gpios = mctrl_gpio_init(&uart->port, 0);
> -			if (IS_ERR(gpios)) {
> -				ret = PTR_ERR(gpios);
> -				goto err;
> -			} else {
> -				uart->gpios = gpios;
> -			}
> -		}
> +	if (up->port.flags & UPF_FIXED_TYPE)
> +		uart->port.type = up->port.type;
>  
> -		serial8250_set_defaults(uart);
> -
> -		/* Possibly override default I/O functions.  */
> -		if (up->port.serial_in)
> -			uart->port.serial_in = up->port.serial_in;
> -		if (up->port.serial_out)
> -			uart->port.serial_out = up->port.serial_out;
> -		if (up->port.handle_irq)
> -			uart->port.handle_irq = up->port.handle_irq;
> -		/*  Possibly override set_termios call */
> -		if (up->port.set_termios)
> -			uart->port.set_termios = up->port.set_termios;
> -		if (up->port.set_ldisc)
> -			uart->port.set_ldisc = up->port.set_ldisc;
> -		if (up->port.get_mctrl)
> -			uart->port.get_mctrl = up->port.get_mctrl;
> -		if (up->port.set_mctrl)
> -			uart->port.set_mctrl = up->port.set_mctrl;
> -		if (up->port.get_divisor)
> -			uart->port.get_divisor = up->port.get_divisor;
> -		if (up->port.set_divisor)
> -			uart->port.set_divisor = up->port.set_divisor;
> -		if (up->port.startup)
> -			uart->port.startup = up->port.startup;
> -		if (up->port.shutdown)
> -			uart->port.shutdown = up->port.shutdown;
> -		if (up->port.pm)
> -			uart->port.pm = up->port.pm;
> -		if (up->port.handle_break)
> -			uart->port.handle_break = up->port.handle_break;
> -		if (up->dl_read)
> -			uart->dl_read = up->dl_read;
> -		if (up->dl_write)
> -			uart->dl_write = up->dl_write;
> -
> -		if (uart->port.type != PORT_8250_CIR) {
> -			if (uart_console_registered(&uart->port))
> -				pm_runtime_get_sync(uart->port.dev);
> -
> -			if (serial8250_isa_config != NULL)
> -				serial8250_isa_config(0, &uart->port,
> -						&uart->capabilities);
> -
> -			serial8250_apply_quirks(uart);
> -			ret = uart_add_one_port(&serial8250_reg,
> -						&uart->port);
> -			if (ret)
> -				goto err;
> -
> -			ret = uart->port.line;
> +	/*
> +	 * Only call mctrl_gpio_init(), if the device has no ACPI
> +	 * companion device
> +	 */
> +	if (!has_acpi_companion(uart->port.dev)) {
> +		struct mctrl_gpios *gpios = mctrl_gpio_init(&uart->port, 0);
> +		if (IS_ERR(gpios)) {
> +			ret = PTR_ERR(gpios);
> +			goto err;
>  		} else {
> -			dev_info(uart->port.dev,
> -				"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
> -				uart->port.iobase,
> -				(unsigned long long)uart->port.mapbase,
> -				uart->port.irq);
> -
> -			ret = 0;
> +			uart->gpios = gpios;
>  		}
> +	}
>  
> -		if (!uart->lsr_save_mask)
> -			uart->lsr_save_mask = LSR_SAVE_FLAGS;	/* Use default LSR mask */
> +	serial8250_set_defaults(uart);
> +
> +	/* Possibly override default I/O functions.  */
> +	if (up->port.serial_in)
> +		uart->port.serial_in = up->port.serial_in;
> +	if (up->port.serial_out)
> +		uart->port.serial_out = up->port.serial_out;
> +	if (up->port.handle_irq)
> +		uart->port.handle_irq = up->port.handle_irq;
> +	/*  Possibly override set_termios call */
> +	if (up->port.set_termios)
> +		uart->port.set_termios = up->port.set_termios;
> +	if (up->port.set_ldisc)
> +		uart->port.set_ldisc = up->port.set_ldisc;
> +	if (up->port.get_mctrl)
> +		uart->port.get_mctrl = up->port.get_mctrl;
> +	if (up->port.set_mctrl)
> +		uart->port.set_mctrl = up->port.set_mctrl;
> +	if (up->port.get_divisor)
> +		uart->port.get_divisor = up->port.get_divisor;
> +	if (up->port.set_divisor)
> +		uart->port.set_divisor = up->port.set_divisor;
> +	if (up->port.startup)
> +		uart->port.startup = up->port.startup;
> +	if (up->port.shutdown)
> +		uart->port.shutdown = up->port.shutdown;
> +	if (up->port.pm)
> +		uart->port.pm = up->port.pm;
> +	if (up->port.handle_break)
> +		uart->port.handle_break = up->port.handle_break;
> +	if (up->dl_read)
> +		uart->dl_read = up->dl_read;
> +	if (up->dl_write)
> +		uart->dl_write = up->dl_write;
>  
> -		/* Initialise interrupt backoff work if required */
> -		if (up->overrun_backoff_time_ms > 0) {
> -			uart->overrun_backoff_time_ms =
> -				up->overrun_backoff_time_ms;
> -			INIT_DELAYED_WORK(&uart->overrun_backoff,
> -					serial_8250_overrun_backoff_work);
> -		} else {
> -			uart->overrun_backoff_time_ms = 0;
> -		}
> +	if (uart->port.type != PORT_8250_CIR) {
> +		if (uart_console_registered(&uart->port))
> +			pm_runtime_get_sync(uart->port.dev);
> +
> +		if (serial8250_isa_config != NULL)
> +			serial8250_isa_config(0, &uart->port,
> +					&uart->capabilities);
> +
> +		serial8250_apply_quirks(uart);
> +		ret = uart_add_one_port(&serial8250_reg,
> +					&uart->port);
> +		if (ret)
> +			goto err;
> +
> +		ret = uart->port.line;
> +	} else {
> +		dev_info(uart->port.dev,
> +			"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
> +			uart->port.iobase,
> +			(unsigned long long)uart->port.mapbase,
> +			uart->port.irq);
> +
> +		ret = 0;
> +	}
> +
> +	if (!uart->lsr_save_mask)
> +		uart->lsr_save_mask = LSR_SAVE_FLAGS;	/* Use default LSR mask */
> +
> +	/* Initialise interrupt backoff work if required */
> +	if (up->overrun_backoff_time_ms > 0) {
> +		uart->overrun_backoff_time_ms =
> +			up->overrun_backoff_time_ms;
> +		INIT_DELAYED_WORK(&uart->overrun_backoff,
> +				serial_8250_overrun_backoff_work);
> +	} else {
> +		uart->overrun_backoff_time_ms = 0;
>  	}
>  
>  unlock:
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 32/33] serial: 8250: use hashtable
  2025-06-11 10:03 ` [PATCH 32/33] serial: 8250: use hashtable Jiri Slaby (SUSE)
@ 2025-06-11 13:25   ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-11 13:25 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: Greg Kroah-Hartman, linux-serial, LKML

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> Instead of open-coding the hash table, use the one provided by
> hashtable.h. The semantics is the same, except the code needs not to
> compute the hash bucket on its own.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_core.c | 24 ++++++++----------------
>  1 file changed, 8 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 10f25bae9f46..a6ecb8575da4 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -13,6 +13,7 @@
>   */
>  
>  #include <linux/acpi.h>
> +#include <linux/hashtable.h>
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/ioport.h>
> @@ -47,8 +48,8 @@ struct irq_info {
>  	struct list_head	*head;
>  };
>  
> -#define NR_IRQ_HASH		32	/* Can be adjusted later */
> -static struct hlist_head irq_lists[NR_IRQ_HASH];
> +#define IRQ_HASH_BITS		5	/* Can be adjusted later */
> +static DEFINE_HASHTABLE(irq_lists, IRQ_HASH_BITS);
>  static DEFINE_MUTEX(hash_mutex);	/* Used to walk the hash */
>  
>  /*
> @@ -75,11 +76,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
>  
>  	l = i->head;
>  	do {
> -		struct uart_8250_port *up;
> -		struct uart_port *port;
> -
> -		up = list_entry(l, struct uart_8250_port, list);
> -		port = &up->port;
> +		struct uart_8250_port *up = list_entry(l, struct uart_8250_port, list);
> +		struct uart_port *port = &up->port;

Isn't this entirely unrelated change/cleanup?

>  
>  		if (port->handle_irq(port)) {
>  			handled = 1;
> @@ -132,14 +130,11 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
>   */
>  static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up)
>  {
> -	struct hlist_head *h;
>  	struct irq_info *i;
>  
>  	mutex_lock(&hash_mutex);
>  
> -	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
> -
> -	hlist_for_each_entry(i, h, node)
> +	hash_for_each_possible(irq_lists, i, node, up->port.irq)
>  		if (i->irq == up->port.irq)
>  			goto unlock;
>  
> @@ -150,7 +145,7 @@ static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_por
>  	}
>  	spin_lock_init(&i->lock);
>  	i->irq = up->port.irq;
> -	hlist_add_head(&i->node, h);
> +	hash_add(irq_lists, &i->node, i->irq);
>  unlock:
>  	mutex_unlock(&hash_mutex);
>  
> @@ -189,13 +184,10 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
>  static void serial_unlink_irq_chain(struct uart_8250_port *up)
>  {
>  	struct irq_info *i;
> -	struct hlist_head *h;
>  
>  	mutex_lock(&hash_mutex);
>  
> -	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
> -
> -	hlist_for_each_entry(i, h, node)
> +	hash_for_each_possible(irq_lists, i, node, up->port.irq)
>  		if (i->irq == up->port.irq)
>  			break;
>  
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 06/33] tty: vt: use sane types for userspace API
  2025-06-11 10:02 ` [PATCH 06/33] tty: vt: use sane types for userspace API Jiri Slaby (SUSE)
@ 2025-06-11 14:38   ` Nicolas Pitre
  0 siblings, 0 replies; 91+ messages in thread
From: Nicolas Pitre @ 2025-06-11 14:38 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> As discussed earlier (see the Link below), use the preferred ioctl types
> in vt.h (__u8, __u16, ...).
> 
> These types are already used for the new VT_GETCONSIZECSRPOS.
> Therefore, the necessary includes are already present. Since now, the
> types are used for every structure defined in the header now.
> 
> Note the kernel is built with -funsigned-char, therefore 'char' becomes
> '__u8' in here.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Nicolas Pitre <nico@fluxnic.net>
> Link: https://lore.kernel.org/all/p7p83sq1-4ro2-o924-s9o2-30spr74n076o@syhkavp.arg/

Reviewed-by: Nicolas Pitre <npitre@baylibre.com>

> ---
>  include/uapi/linux/vt.h | 44 ++++++++++++++++++++---------------------
>  1 file changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
> index e5b0c492aa18..714483d68c69 100644
> --- a/include/uapi/linux/vt.h
> +++ b/include/uapi/linux/vt.h
> @@ -19,11 +19,11 @@
>  #define VT_OPENQRY	0x5600	/* find available vt */
>  
>  struct vt_mode {
> -	char mode;		/* vt mode */
> -	char waitv;		/* if set, hang on writes if not active */
> -	short relsig;		/* signal to raise on release req */
> -	short acqsig;		/* signal to raise on acquisition */
> -	short frsig;		/* unused (set to 0) */
> +	__u8 mode;		/* vt mode */
> +	__u8 waitv;		/* if set, hang on writes if not active */
> +	__s16 relsig;		/* signal to raise on release req */
> +	__s16 acqsig;		/* signal to raise on acquisition */
> +	__s16 frsig;		/* unused (set to 0) */
>  };
>  #define VT_GETMODE	0x5601	/* get mode of active vt */
>  #define VT_SETMODE	0x5602	/* set mode of active vt */
> @@ -32,9 +32,9 @@ struct vt_mode {
>  #define		VT_ACKACQ	0x02	/* acknowledge switch */
>  
>  struct vt_stat {
> -	unsigned short v_active;	/* active vt */
> -	unsigned short v_signal;	/* signal to send */
> -	unsigned short v_state;		/* vt bitmask */
> +	__u16 v_active;	/* active vt */
> +	__u16 v_signal;	/* signal to send */
> +	__u16 v_state;		/* vt bitmask */
>  };
>  #define VT_GETSTATE	0x5603	/* get global vt state info */
>  #define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
> @@ -46,19 +46,19 @@ struct vt_stat {
>  #define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
>  
>  struct vt_sizes {
> -	unsigned short v_rows;		/* number of rows */
> -	unsigned short v_cols;		/* number of columns */
> -	unsigned short v_scrollsize;	/* number of lines of scrollback */
> +	__u16 v_rows;		/* number of rows */
> +	__u16 v_cols;		/* number of columns */
> +	__u16 v_scrollsize;	/* number of lines of scrollback */
>  };
>  #define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
>  
>  struct vt_consize {
> -	unsigned short v_rows;	/* number of rows */
> -	unsigned short v_cols;	/* number of columns */
> -	unsigned short v_vlin;	/* number of pixel rows on screen */
> -	unsigned short v_clin;	/* number of pixel rows per character */
> -	unsigned short v_vcol;	/* number of pixel columns on screen */
> -	unsigned short v_ccol;	/* number of pixel columns per character */
> +	__u16 v_rows;	/* number of rows */
> +	__u16 v_cols;	/* number of columns */
> +	__u16 v_vlin;	/* number of pixel rows on screen */
> +	__u16 v_clin;	/* number of pixel rows per character */
> +	__u16 v_vcol;	/* number of pixel columns on screen */
> +	__u16 v_ccol;	/* number of pixel columns per character */
>  };
>  #define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
>  #define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
> @@ -66,21 +66,21 @@ struct vt_consize {
>  #define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
>  
>  struct vt_event {
> -	unsigned int event;
> +	__u32 event;
>  #define VT_EVENT_SWITCH		0x0001	/* Console switch */
>  #define VT_EVENT_BLANK		0x0002	/* Screen blank */
>  #define VT_EVENT_UNBLANK	0x0004	/* Screen unblank */
>  #define VT_EVENT_RESIZE		0x0008	/* Resize display */
>  #define VT_MAX_EVENT		0x000F
> -	unsigned int oldev;		/* Old console */
> -	unsigned int newev;		/* New console (if changing) */
> -	unsigned int pad[4];		/* Padding for expansion */
> +	__u32 oldev;		/* Old console */
> +	__u32 newev;		/* New console (if changing) */
> +	__u32 pad[4];		/* Padding for expansion */
>  };
>  
>  #define VT_WAITEVENT	0x560E	/* Wait for an event */
>  
>  struct vt_setactivate {
> -	unsigned int console;
> +	__u32 console;
>  	struct vt_mode mode;
>  };
>  
> -- 
> 2.49.0
> 
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
  2025-06-11 11:30   ` Ilpo Järvinen
@ 2025-06-11 14:42   ` Nicolas Pitre
  2025-07-31 14:35   ` Christophe Leroy
  2 siblings, 0 replies; 91+ messages in thread
From: Nicolas Pitre @ 2025-06-11 14:42 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
> were synthetically built up the same way the _IO() macro does.
> 
> So instead of implicit hex numbers, use _IO() properly.
> 
> To not change the pre-existing numbers, use only _IO() (and not _IOR()
> or _IOW()). The latter would change the numbers indeed.
> 
> Objdump of vt_ioctl.o reveals no difference with this patch.
> 
> Again, VT_GETCONSIZECSRPOS already uses _IOR(), so everything is paved
> for this patch.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Nicolas Pitre <nico@fluxnic.net>

Reviewed-by: Nicolas Pitre <npitre@baylibre.com>

> ---
>  include/uapi/linux/vt.h | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
> index 714483d68c69..b60fcdfb2746 100644
> --- a/include/uapi/linux/vt.h
> +++ b/include/uapi/linux/vt.h
> @@ -14,9 +14,9 @@
>  		/* Note: the ioctl VT_GETSTATE does not work for
>  		   consoles 16 and higher (since it returns a short) */
>  
> -/* 0x56 is 'V', to avoid collision with termios and kd */
> +/* 'V' to avoid collision with termios and kd */
>  
> -#define VT_OPENQRY	0x5600	/* find available vt */
> +#define VT_OPENQRY		_IO('V', 0x00)	/* find available vt */
>  
>  struct vt_mode {
>  	__u8 mode;		/* vt mode */
> @@ -25,8 +25,8 @@ struct vt_mode {
>  	__s16 acqsig;		/* signal to raise on acquisition */
>  	__s16 frsig;		/* unused (set to 0) */
>  };
> -#define VT_GETMODE	0x5601	/* get mode of active vt */
> -#define VT_SETMODE	0x5602	/* set mode of active vt */
> +#define VT_GETMODE		_IO('V', 0x01)	/* get mode of active vt */
> +#define VT_SETMODE		_IO('V', 0x02)	/* set mode of active vt */
>  #define		VT_AUTO		0x00	/* auto vt switching */
>  #define		VT_PROCESS	0x01	/* process controls switching */
>  #define		VT_ACKACQ	0x02	/* acknowledge switch */
> @@ -36,21 +36,21 @@ struct vt_stat {
>  	__u16 v_signal;	/* signal to send */
>  	__u16 v_state;		/* vt bitmask */
>  };
> -#define VT_GETSTATE	0x5603	/* get global vt state info */
> -#define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
> +#define VT_GETSTATE		_IO('V', 0x03)	/* get global vt state info */
> +#define VT_SENDSIG		_IO('V', 0x04)	/* signal to send to bitmask of vts */
>  
> -#define VT_RELDISP	0x5605	/* release display */
> +#define VT_RELDISP		_IO('V', 0x05)	/* release display */
>  
> -#define VT_ACTIVATE	0x5606	/* make vt active */
> -#define VT_WAITACTIVE	0x5607	/* wait for vt active */
> -#define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
> +#define VT_ACTIVATE		_IO('V', 0x06)	/* make vt active */
> +#define VT_WAITACTIVE		_IO('V', 0x07)	/* wait for vt active */
> +#define VT_DISALLOCATE		_IO('V', 0x08)  /* free memory associated to vt */
>  
>  struct vt_sizes {
>  	__u16 v_rows;		/* number of rows */
>  	__u16 v_cols;		/* number of columns */
>  	__u16 v_scrollsize;	/* number of lines of scrollback */
>  };
> -#define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
> +#define VT_RESIZE		_IO('V', 0x09)	/* set kernel's idea of screensize */
>  
>  struct vt_consize {
>  	__u16 v_rows;	/* number of rows */
> @@ -60,10 +60,10 @@ struct vt_consize {
>  	__u16 v_vcol;	/* number of pixel columns on screen */
>  	__u16 v_ccol;	/* number of pixel columns per character */
>  };
> -#define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
> -#define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
> -#define VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
> -#define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
> +#define VT_RESIZEX		_IO('V', 0x0A)  /* set kernel's idea of screensize + more */
> +#define VT_LOCKSWITCH		_IO('V', 0x0B)  /* disallow vt switching */
> +#define VT_UNLOCKSWITCH		_IO('V', 0x0C)  /* allow vt switching */
> +#define VT_GETHIFONTMASK	_IO('V', 0x0D)  /* return hi font mask */
>  
>  struct vt_event {
>  	__u32 event;
> @@ -77,14 +77,14 @@ struct vt_event {
>  	__u32 pad[4];		/* Padding for expansion */
>  };
>  
> -#define VT_WAITEVENT	0x560E	/* Wait for an event */
> +#define VT_WAITEVENT		_IO('V', 0x0E)	/* Wait for an event */
>  
>  struct vt_setactivate {
>  	__u32 console;
>  	struct vt_mode mode;
>  };
>  
> -#define VT_SETACTIVATE	0x560F	/* Activate and set the mode of a console */
> +#define VT_SETACTIVATE		_IO('V', 0x0F)	/* Activate and set the mode of a console */
>  
>  /* get console size and cursor position */
>  struct vt_consizecsrpos {
> -- 
> 2.49.0
> 
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types
  2025-06-11 10:02 ` [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types Jiri Slaby (SUSE)
@ 2025-06-11 15:12   ` Andy Shevchenko
  2025-06-23  6:55     ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-11 15:12 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Ilpo Järvinen, Paul Cercueil, Vladimir Zapolskiy,
	Kunihiko Hayashi, Masami Hiramatsu, linuxppc-dev, linux-mips,
	linux-arm-kernel

On Wed, Jun 11, 2025 at 12:02:54PM +0200, Jiri Slaby (SUSE) wrote:
> uart_port::{serial_in,serial_out} (and plat_serial8250_port::* likewise)
> historically use:
> * 'unsigned int' for 32-bit register values in reads and writes, and
> * 'int' for offsets.
> 
> Make them sane such that:
> * 'u32' is used for register values, and
> * 'unsigned int' is used for offsets.
> 
> While at it, name hooks' parameters, so it is clear what is what.

At a glance this looks just mechanical change. Have you used coccinelle for
that?

As for the whole idea, I like it,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

...

> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Paul Cercueil <paul@crapouillou.net>
> Cc: Vladimir Zapolskiy <vz@mleia.com>
> Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>

These also can be moved under '---' :-)

> ---
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-mips@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> ---

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 15/33] serial: 8250: extract serial8250_THRE_test()
  2025-06-11 12:03   ` Ilpo Järvinen
@ 2025-06-12  8:54     ` Jiri Slaby
  2025-06-12  9:18       ` Ilpo Järvinen
  0 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby @ 2025-06-12  8:54 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: Greg Kroah-Hartman, linux-serial, LKML

On 11. 06. 25, 14:03, Ilpo Järvinen wrote:
> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
...
>> +	/*
>> +	 * Test for UARTs that do not reassert THRE when the transmitter is idle and the interrupt
>> +	 * has already been cleared.  Real 16550s should always reassert this interrupt whenever the
>> +	 * transmitter is idle and the interrupt is enabled.  Delays are necessary to allow register
>> +	 * changes to become visible.
> 
> Very long comment lines are hard to read. (This is mostly not related to
> line length limits, but with eye movement required.)
> 
> It may make sense to place some of the descriptive comment text into a
> function comment instead of placing them mid-function.
> 
>> +	 *
>> +	 * Synchronize UART_IER access against the console.
>> +	 */
>> +	uart_port_lock_irqsave(port, &flags);
>> +
>> +	wait_for_xmitr(up, UART_LSR_THRE);
>> +	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
>> +	udelay(1); /* allow THRE to set */
> 
> These comments mix visually into the code making this look a big wall of
> text overall. Maybe consider adding empty lines to the logic as well as
> there are what looks clear steps in this logic.


What about this:
> /*
>  * Test for UARTs that do not reassert THRE when the transmitter is idle and the
>  * interrupt has already been cleared. Real 16550s should always reassert this
>  * interrupt whenever the transmitter is idle and the interrupt is enabled.
>  * Delays are necessary to allow register changes to become visible.
>  */
> static void serial8250_THRE_test(struct uart_port *port)
> {       
>         struct uart_8250_port *up = up_to_u8250p(port);
>         unsigned long flags;
>         bool iir_noint1, iir_noint2;
> 
>         if (!port->irq)
>                 return;
>                         
>         if (up->port.flags & UPF_NO_THRE_TEST)
>                 return;
>         
>         if (port->irqflags & IRQF_SHARED)
>                 disable_irq_nosync(port->irq);
>         
>         /* Synchronize UART_IER access against the console. */
>         uart_port_lock_irqsave(port, &flags);
>         
>         wait_for_xmitr(up, UART_LSR_THRE);
>         serial_port_out_sync(port, UART_IER, UART_IER_THRI);
>         /* allow THRE to set */
>         udelay(1); 
> 
>         iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
>         serial_port_out(port, UART_IER, 0);
>         serial_port_out_sync(port, UART_IER, UART_IER_THRI);
>         /* allow a working UART time to re-assert THRE */
>         udelay(1); 
> 
>         iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
>         serial_port_out(port, UART_IER, 0);
> 
>         uart_port_unlock_irqrestore(port, flags);
> 
>         if (port->irqflags & IRQF_SHARED)
>                 enable_irq(port->irq); 
>                         
>         /*
>          * If the interrupt is not reasserted, or we otherwise don't trust the
>          * iir, setup a timer to kick the UART on a regular basis.
>          */
>         if ((!iir_noint1 && iir_noint2) || up->port.flags & UPF_BUG_THRE)
>                 up->bugs |= UART_BUG_THRE;
> }
> 

?

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 15/33] serial: 8250: extract serial8250_THRE_test()
  2025-06-12  8:54     ` Jiri Slaby
@ 2025-06-12  9:18       ` Ilpo Järvinen
  0 siblings, 0 replies; 91+ messages in thread
From: Ilpo Järvinen @ 2025-06-12  9:18 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 3548 bytes --]

On Thu, 12 Jun 2025, Jiri Slaby wrote:

> On 11. 06. 25, 14:03, Ilpo Järvinen wrote:
> > On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> ...
> > > +	/*
> > > +	 * Test for UARTs that do not reassert THRE when the transmitter is
> > > idle and the interrupt
> > > +	 * has already been cleared.  Real 16550s should always reassert this
> > > interrupt whenever the
> > > +	 * transmitter is idle and the interrupt is enabled.  Delays are
> > > necessary to allow register
> > > +	 * changes to become visible.
> > 
> > Very long comment lines are hard to read. (This is mostly not related to
> > line length limits, but with eye movement required.)
> > 
> > It may make sense to place some of the descriptive comment text into a
> > function comment instead of placing them mid-function.
> > 
> > > +	 *
> > > +	 * Synchronize UART_IER access against the console.
> > > +	 */
> > > +	uart_port_lock_irqsave(port, &flags);
> > > +
> > > +	wait_for_xmitr(up, UART_LSR_THRE);
> > > +	serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> > > +	udelay(1); /* allow THRE to set */
> > 
> > These comments mix visually into the code making this look a big wall of
> > text overall. Maybe consider adding empty lines to the logic as well as
> > there are what looks clear steps in this logic.
> 
> 
> What about this:
> > /*
> >  * Test for UARTs that do not reassert THRE when the transmitter is idle and
> > the
> >  * interrupt has already been cleared. Real 16550s should always reassert
> > this
> >  * interrupt whenever the transmitter is idle and the interrupt is enabled.
> >  * Delays are necessary to allow register changes to become visible.
> >  */
> > static void serial8250_THRE_test(struct uart_port *port)
> > {               struct uart_8250_port *up = up_to_u8250p(port);
> >         unsigned long flags;
> >         bool iir_noint1, iir_noint2;
> > 
> >         if (!port->irq)
> >                 return;
> >                                 if (up->port.flags & UPF_NO_THRE_TEST)
> >                 return;
> >                 if (port->irqflags & IRQF_SHARED)
> >                 disable_irq_nosync(port->irq);
> >                 /* Synchronize UART_IER access against the console. */
> >         uart_port_lock_irqsave(port, &flags);
> >                 wait_for_xmitr(up, UART_LSR_THRE);
> >         serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> >         /* allow THRE to set */
> >         udelay(1); 
> >         iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> >         serial_port_out(port, UART_IER, 0);
> >         serial_port_out_sync(port, UART_IER, UART_IER_THRI);
> >         /* allow a working UART time to re-assert THRE */
> >         udelay(1); 
> >         iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
> >         serial_port_out(port, UART_IER, 0);
> > 
> >         uart_port_unlock_irqrestore(port, flags);
> > 
> >         if (port->irqflags & IRQF_SHARED)
> >                 enable_irq(port->irq);                                 /*
> >          * If the interrupt is not reasserted, or we otherwise don't trust
> > the
> >          * iir, setup a timer to kick the UART on a regular basis.
> >          */
> >         if ((!iir_noint1 && iir_noint2) || up->port.flags & UPF_BUG_THRE)
> >                 up->bugs |= UART_BUG_THRE;
> > }
> > 
> 
> ?

I don't know what part exactly you wanted to ask about but it looks mostly 
fine (sans what is broken due to email).

-- 
 i.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-11 12:58   ` Ilpo Järvinen
@ 2025-06-12 10:01     ` Jiri Slaby
  2025-06-12 10:04       ` Jiri Slaby
  2025-06-12 18:54       ` Andy Shevchenko
  0 siblings, 2 replies; 91+ messages in thread
From: Jiri Slaby @ 2025-06-12 10:01 UTC (permalink / raw)
  To: Ilpo Järvinen, Andy Shevchenko
  Cc: Greg Kroah-Hartman, linux-serial, LKML

On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
>> serial8250_do_set_termios() consists of many registers and up flags
>> settings. Extract all these into separate functions. This time, setting
>> of EFR for UART_CAP_EFR ports.
>>
>> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
>> ---
>>   drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++++------------
>>   1 file changed, 25 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
>> index 2c045a4369fc..0f16398cc86f 100644
>> --- a/drivers/tty/serial/8250/8250_port.c
>> +++ b/drivers/tty/serial/8250/8250_port.c
>> @@ -2768,6 +2768,30 @@ static void serial8250_set_ier(struct uart_port *port, struct ktermios *termios)
>>   	serial_port_out(port, UART_IER, up->ier);
>>   }
>>   
>> +static void serial8250_set_efr(struct uart_port *port, struct ktermios *termios)
>> +{
>> +	struct uart_8250_port *up = up_to_u8250p(port);
>> +	u8 efr_reg = UART_EFR;
>> +	u8 efr = 0;
>> +
>> +	if (!(up->capabilities & UART_CAP_EFR))
>> +		return;
>> +
>> +	/*
>> +	 * TI16C752/Startech hardware flow control.  FIXME:
>> +	 * - TI16C752 requires control thresholds to be set.
>> +	 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
>> +	 */
>> +	if (termios->c_cflag & CRTSCTS)
>> +		efr |= UART_EFR_CTS;
>> +
>> +	if (port->flags & UPF_EXAR_EFR)
> 
> I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
> this flag and does not contain UART_CAP_EFR at all (nor uses
> UPF_BOOT_AUTOCONF)??

Impossible as far as I can tell nowadays. Likely since:
commit 6be254c2113d18984bae002b3b3dfc133cf56ac5
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Wed Jul 31 20:05:56 2019 +0300

     serial: 8250_exar: No need to autoconfigure Exar ports

Andy?

The question is whether we need the code or we can drop it 8-).

> 
>> +		efr_reg = UART_XR_EFR;
>> +
>> +	serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
>> +	serial_port_out(port, efr_reg, efr);
>> +}
>> +
>>   void
>>   serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>>   		          const struct ktermios *old)


-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-12 10:01     ` Jiri Slaby
@ 2025-06-12 10:04       ` Jiri Slaby
  2025-06-12 13:33         ` Andy Shevchenko
  2025-06-12 18:54       ` Andy Shevchenko
  1 sibling, 1 reply; 91+ messages in thread
From: Jiri Slaby @ 2025-06-12 10:04 UTC (permalink / raw)
  To: Ilpo Järvinen, Andy Shevchenko
  Cc: Greg Kroah-Hartman, linux-serial, LKML

On 12. 06. 25, 12:01, Jiri Slaby wrote:
> The question is whether we need the code or we can drop it 8-).

As it is now, we could drop UPF_EXAR_EFR altogether, right?

-- 
js
suse labs


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-12 10:04       ` Jiri Slaby
@ 2025-06-12 13:33         ` Andy Shevchenko
  0 siblings, 0 replies; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-12 13:33 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Ilpo Järvinen, Greg Kroah-Hartman, linux-serial, LKML

On Thu, Jun 12, 2025 at 12:04:27PM +0200, Jiri Slaby wrote:
> On 12. 06. 25, 12:01, Jiri Slaby wrote:
> > The question is whether we need the code or we can drop it 8-).
> 
> As it is now, we could drop UPF_EXAR_EFR altogether, right?

Let me check. It might be that there is a lurking regression nobody reported so far.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-12 10:01     ` Jiri Slaby
  2025-06-12 10:04       ` Jiri Slaby
@ 2025-06-12 18:54       ` Andy Shevchenko
  2025-06-23  7:20         ` Jiri Slaby
  1 sibling, 1 reply; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-12 18:54 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Ilpo Järvinen, Greg Kroah-Hartman, linux-serial, LKML

On Thu, Jun 12, 2025 at 12:01:29PM +0200, Jiri Slaby wrote:
> On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
> > On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

...

> > > +	if (port->flags & UPF_EXAR_EFR)
> > 
> > I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
> > this flag and does not contain UART_CAP_EFR at all (nor uses
> > UPF_BOOT_AUTOCONF)??

The file indeed does not contain it, BUT it sets it implicitly (via port type).
So, this is not a dead code. Please, do not remove it.

If you find a good way how to move it to the 8250_exar.c, I will appreciate
that solution. Ideally 8250_port.c should be quirk-free module.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro
  2025-06-11 10:03 ` [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Jiri Slaby (SUSE)
  2025-06-11 13:10   ` Ilpo Järvinen
@ 2025-06-17 11:32   ` Maciej W. Rozycki
  2025-06-17 11:42     ` Greg Kroah-Hartman
  1 sibling, 1 reply; 91+ messages in thread
From: Maciej W. Rozycki @ 2025-06-17 11:32 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Ilpo Järvinen, Greg Kroah-Hartman, linux-serial,
	linux-kernel

On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> DEBUG_AUTOCONF() is always disabled (by "#if 0"), so one would need to
> recompile the kernel to use it. And even if they did, they would find
> out it is broken anyway:
>   error: variable 'scratch' is used uninitialized whenever 'if' condition is false

 This is removing useful debugging aids.

 The issue with compilation is related to commit 3398cc4f2b15 ("serial: 
8250: Add IIR FIFOs enabled field properly"), which removed the assignment 
of IIR to `scratch' (although a path did exist before it that bypassed the 
assignment anyway), and can be trivially fixed by bringing the assignment 
back and moving the debug statement next to it.

 I agree that "#if 0" isn't very useful as it requires patching the source 
to activate; changing it to "#ifdef DEBUG" would make more sense nowadays.

  Maciej

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro
  2025-06-17 11:32   ` Maciej W. Rozycki
@ 2025-06-17 11:42     ` Greg Kroah-Hartman
  2025-06-17 13:21       ` Maciej W. Rozycki
  0 siblings, 1 reply; 91+ messages in thread
From: Greg Kroah-Hartman @ 2025-06-17 11:42 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Jiri Slaby (SUSE), Ilpo Järvinen, linux-serial, linux-kernel

On Tue, Jun 17, 2025 at 12:32:48PM +0100, Maciej W. Rozycki wrote:
> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
> > DEBUG_AUTOCONF() is always disabled (by "#if 0"), so one would need to
> > recompile the kernel to use it. And even if they did, they would find
> > out it is broken anyway:
> >   error: variable 'scratch' is used uninitialized whenever 'if' condition is false
> 
>  This is removing useful debugging aids.

How can it be "useful" if it's broken and no one has ever reported that?

>  The issue with compilation is related to commit 3398cc4f2b15 ("serial: 
> 8250: Add IIR FIFOs enabled field properly"), which removed the assignment 
> of IIR to `scratch' (although a path did exist before it that bypassed the 
> assignment anyway), and can be trivially fixed by bringing the assignment 
> back and moving the debug statement next to it.

So it's been broken for over 2 years and no one has asked for it to be
fixed?

>  I agree that "#if 0" isn't very useful as it requires patching the source 
> to activate; changing it to "#ifdef DEBUG" would make more sense nowadays.

No, dynamic debugging is the proper solution, not build-time stuff.  If
you really need/want this, add it back in that way, not this old-style
"let's rebuild the whole kernel" type of thing.  This isn't the 1990's
anymore :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 04/33] m68k: remove unneeded tty includes
  2025-06-11 10:02 ` [PATCH 04/33] m68k: remove unneeded tty includes Jiri Slaby (SUSE)
  2025-06-11 11:22   ` Ilpo Järvinen
@ 2025-06-17 12:29   ` Geert Uytterhoeven
  1 sibling, 0 replies; 91+ messages in thread
From: Geert Uytterhoeven @ 2025-06-17 12:29 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Joshua Thompson, linux-m68k

On Wed, 11 Jun 2025 at 12:03, Jiri Slaby (SUSE) <jirislaby@kernel.org> wrote:
> All these includes must have been cut & pasted. The code does not use
> any tty or vt functionality at all.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

Since GregKH seems to be eager to pick up this series:
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro
  2025-06-17 11:42     ` Greg Kroah-Hartman
@ 2025-06-17 13:21       ` Maciej W. Rozycki
  0 siblings, 0 replies; 91+ messages in thread
From: Maciej W. Rozycki @ 2025-06-17 13:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby (SUSE), Ilpo Järvinen, linux-serial, linux-kernel

On Tue, 17 Jun 2025, Greg Kroah-Hartman wrote:

> > > DEBUG_AUTOCONF() is always disabled (by "#if 0"), so one would need to
> > > recompile the kernel to use it. And even if they did, they would find
> > > out it is broken anyway:
> > >   error: variable 'scratch' is used uninitialized whenever 'if' condition is false
> > 
> >  This is removing useful debugging aids.
> 
> How can it be "useful" if it's broken and no one has ever reported that?

 It's broken in a trivial way and would be fixed by a competent developer 
in no time.  If no one has reported the breakage, it means no one has used 
this code in a way that would trigger it, e.g. -Wno-error in effect would 
mask the compilation issue.  I'm fairly sure I used this code while making 
changes to the OxSemi Tornado backend a couple of years ago.

> >  The issue with compilation is related to commit 3398cc4f2b15 ("serial: 
> > 8250: Add IIR FIFOs enabled field properly"), which removed the assignment 
> > of IIR to `scratch' (although a path did exist before it that bypassed the 
> > assignment anyway), and can be trivially fixed by bringing the assignment 
> > back and moving the debug statement next to it.
> 
> So it's been broken for over 2 years and no one has asked for it to be
> fixed?

 Well, what can I say beyond the obvious?  That debugging a mature driver 
doesn't happen all the time?  This would typically happen when adding a 
new chip-specific backend, and I don't think new variants of 8250-style 
serial ports appear that often nowadays.

 You can argue one can insert these debug statements back if they need it, 
but someone already made this effort years ago, so why waste it?  To save 
a handful of source lines?  It doesn't seem a good justification to me.

> >  I agree that "#if 0" isn't very useful as it requires patching the source 
> > to activate; changing it to "#ifdef DEBUG" would make more sense nowadays.
> 
> No, dynamic debugging is the proper solution, not build-time stuff.  If
> you really need/want this, add it back in that way, not this old-style
> "let's rebuild the whole kernel" type of thing.  This isn't the 1990's
> anymore :)

 There's no need to rebuild everything, handing CFLAGS_8250_port.o=-DDEBUG 
to `make' only causes the named object to be recompiled.  I use it all the 
time, also to pass other compilation flags if needed (call me outdated if 
you prefer).

 Any kind of run-time selectable debugging would bloat the kernel binary 
unnecessarily for everyone, for the corner case of driver development or 
debugging.  Unless made optional at configuration or build time, but then 
we're back to the "1990's solution" with little to no gain over the local 
CFLAGS override.

 And if working on a piece of code, then rebuilding it sooner or later 
seems inevitable anyway, so what's the deal?

  Maciej

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 31/33] serial: 8250: invert condition to avoid a goto label
  2025-06-11 10:03 ` [PATCH 31/33] serial: 8250: invert condition to avoid a goto label Jiri Slaby (SUSE)
@ 2025-06-18  5:45   ` Andy Shevchenko
  0 siblings, 0 replies; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-18  5:45 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

On Wed, Jun 11, 2025 at 12:03:17PM +0200, Jiri Slaby (SUSE) wrote:
> Use of "goto" in this code is frowned upon:
>  +-------
>  |if (port->type == PORT_UNKNOWN)
>  |  goto out_unlock;
>  |CODE;
>  |out_unlock:
>  +-------
> 
> Instead, simply do:
>  +-------
>  |if (port->type != PORT_UNKNOWN)
>  |  CODE;
>  +-------

Wouldn't this patch be a churn since you mentioned a guard()() conversion?
Basically with guard() in place the code would be better to change if it's
left as is.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-11 10:03 ` [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Jiri Slaby (SUSE)
  2025-06-11 13:21   ` Ilpo Järvinen
@ 2025-06-18  5:48   ` Andy Shevchenko
  2025-06-20 21:48     ` Maciej S. Szmigiero
  1 sibling, 1 reply; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-18  5:48 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel

On Wed, Jun 11, 2025 at 12:03:16PM +0200, Jiri Slaby (SUSE) wrote:
> There is no point in a long 'if' in serial8250_register_8250_port() to
> just return ENOSPC for PORT_8250_CIR ports. Invert the condition and
> return immediately.
> 
> 'gpios' variable was moved to its set location.
> 
> And return ENODEV instead of ENOSPC. The latter is a leftover from the
> previous find-uart 'if'. The former makes a lot more sense in this case.

...

> +	if (uart->port.type == PORT_8250_CIR) {
> +		ret = -ENODEV;
> +		goto unlock;
> +	}

> +	if (up->port.flags & UPF_FIXED_TYPE)
> +		uart->port.type = up->port.type;

> +	if (uart->port.type != PORT_8250_CIR) {

I admit that there tons of mysterious ways of UART initialisation, but can you
elaborate how this is not a always-true conditional?

> +		if (uart_console_registered(&uart->port))
> +			pm_runtime_get_sync(uart->port.dev);
> +
> +		if (serial8250_isa_config != NULL)
> +			serial8250_isa_config(0, &uart->port,
> +					&uart->capabilities);
> +
> +		serial8250_apply_quirks(uart);
> +		ret = uart_add_one_port(&serial8250_reg,
> +					&uart->port);
> +		if (ret)
> +			goto err;
> +
> +		ret = uart->port.line;
> +	} else {
> +		dev_info(uart->port.dev,
> +			"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
> +			uart->port.iobase,
> +			(unsigned long long)uart->port.mapbase,
> +			uart->port.irq);
> +
> +		ret = 0;
> +	}

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-18  5:48   ` Andy Shevchenko
@ 2025-06-20 21:48     ` Maciej S. Szmigiero
  2025-06-21 19:08       ` Andy Shevchenko
  0 siblings, 1 reply; 91+ messages in thread
From: Maciej S. Szmigiero @ 2025-06-20 21:48 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jiri Slaby (SUSE), Ilpo Järvinen, gregkh, linux-serial,
	linux-kernel

On 18.06.2025 07:48, Andy Shevchenko wrote:
> On Wed, Jun 11, 2025 at 12:03:16PM +0200, Jiri Slaby (SUSE) wrote:
>> There is no point in a long 'if' in serial8250_register_8250_port() to
>> just return ENOSPC for PORT_8250_CIR ports. Invert the condition and
>> return immediately.
>>
>> 'gpios' variable was moved to its set location.
>>
>> And return ENODEV instead of ENOSPC. The latter is a leftover from the
>> previous find-uart 'if'. The former makes a lot more sense in this case.
> 
> ...
> 
>> +	if (uart->port.type == PORT_8250_CIR) {
>> +		ret = -ENODEV;
>> +		goto unlock;
>> +	}
> 
>> +	if (up->port.flags & UPF_FIXED_TYPE)
>> +		uart->port.type = up->port.type;
> 
>> +	if (uart->port.type != PORT_8250_CIR) {
> 
> I admit that there tons of mysterious ways of UART initialisation, but can you
> elaborate how this is not a always-true conditional?
> 

Careful here, someone had an idea in the past that this is indeed
a dead code/branch and ended causing a regression [1].

It would definitely make sense to add a comment describing the code
flow there though as it proven to bewilder people.

Thanks,
Maciej

[1]: https://lore.kernel.org/lkml/c599065a-60f5-070e-c1e3-12b3ab2cbf0a@suse.com/


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-20 21:48     ` Maciej S. Szmigiero
@ 2025-06-21 19:08       ` Andy Shevchenko
  2025-06-23  7:05         ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-21 19:08 UTC (permalink / raw)
  To: Maciej S. Szmigiero
  Cc: Andy Shevchenko, Jiri Slaby (SUSE), Ilpo Järvinen, gregkh,
	linux-serial, linux-kernel

Fri, Jun 20, 2025 at 11:48:09PM +0200, Maciej S. Szmigiero kirjoitti:
> On 18.06.2025 07:48, Andy Shevchenko wrote:
> > On Wed, Jun 11, 2025 at 12:03:16PM +0200, Jiri Slaby (SUSE) wrote:

...

> > > +	if (uart->port.type == PORT_8250_CIR) {
> > > +		ret = -ENODEV;
> > > +		goto unlock;
> > > +	}
> > 
> > > +	if (up->port.flags & UPF_FIXED_TYPE)
> > > +		uart->port.type = up->port.type;
> > 
> > > +	if (uart->port.type != PORT_8250_CIR) {
> > 
> > I admit that there tons of mysterious ways of UART initialisation, but can you
> > elaborate how this is not a always-true conditional?
> 
> Careful here, someone had an idea in the past that this is indeed
> a dead code/branch and ended causing a regression [1].


> It would definitely make sense to add a comment describing the code
> flow there though as it proven to bewilder people.

Yes, this is my point between the lines. I left the code that may affect the
type change and the second check needs a comment explaining these cases, if any.
"If any" defines "always-true" or not conditional. W//o a comment this code
tends to be updated again and lead to a regression.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types
  2025-06-11 15:12   ` Andy Shevchenko
@ 2025-06-23  6:55     ` Jiri Slaby
  0 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby @ 2025-06-23  6:55 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: gregkh, linux-serial, linux-kernel, Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Ilpo Järvinen, Paul Cercueil, Vladimir Zapolskiy,
	Kunihiko Hayashi, Masami Hiramatsu, linuxppc-dev, linux-mips,
	linux-arm-kernel

On 11. 06. 25, 17:12, Andy Shevchenko wrote:
> On Wed, Jun 11, 2025 at 12:02:54PM +0200, Jiri Slaby (SUSE) wrote:
>> uart_port::{serial_in,serial_out} (and plat_serial8250_port::* likewise)
>> historically use:
>> * 'unsigned int' for 32-bit register values in reads and writes, and
>> * 'int' for offsets.
>>
>> Make them sane such that:
>> * 'u32' is used for register values, and
>> * 'unsigned int' is used for offsets.
>>
>> While at it, name hooks' parameters, so it is clear what is what.
> 
> At a glance this looks just mechanical change. Have you used coccinelle for
> that?

No, I haven't managed to learn that :P. But I used 
https://github.com/jirislaby/clang-struct.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 16/33] serial: 8250: extract serial8250_initialize()
  2025-06-11 12:19   ` Ilpo Järvinen
@ 2025-06-23  6:59     ` Jiri Slaby
  0 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby @ 2025-06-23  6:59 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: Greg Kroah-Hartman, linux-serial, LKML

On 11. 06. 25, 14:19, Ilpo Järvinen wrote:
>> +	 * variable. So, let's just don't test if we receive TX irq.  This way, we'll never enable
>> +	 * UART_BUG_TXEN.
>> +	 */
>> +	if (!(port->quirks & UPQ_NO_TXEN_TEST)) {
>> +		/* Do a quick test to see if we receive an interrupt when we enable the TX irq. */
>> +		serial_port_out(port, UART_IER, UART_IER_THRI);
>> +		lsr_TEMT = serial_port_in(port, UART_LSR) & UART_LSR_TEMT;
>> +		iir_NOINT = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT;
>> +		serial_port_out(port, UART_IER, 0);
>> +
>> +		if (lsr_TEMT && iir_NOINT) {
>> +			if (!(up->bugs & UART_BUG_TXEN)) {
>> +				up->bugs |= UART_BUG_TXEN;
>> +				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
>> +			}
>> +		} else {
>> +			up->bugs &= ~UART_BUG_TXEN;
> 
> Is this necessary at all as the line above is the only place setting this
> flag (AFAICT)?

TBH, I don't know. I guess it is unnecessary but it is there since this 
UART_BUG_TXEN was added. /me shrugs.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-21 19:08       ` Andy Shevchenko
@ 2025-06-23  7:05         ` Jiri Slaby
  2025-06-23  7:17           ` Andy Shevchenko
  0 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby @ 2025-06-23  7:05 UTC (permalink / raw)
  To: Andy Shevchenko, Maciej S. Szmigiero
  Cc: Andy Shevchenko, Ilpo Järvinen, gregkh, linux-serial,
	linux-kernel

On 21. 06. 25, 21:08, Andy Shevchenko wrote:
> Fri, Jun 20, 2025 at 11:48:09PM +0200, Maciej S. Szmigiero kirjoitti:
>> On 18.06.2025 07:48, Andy Shevchenko wrote:
>>> On Wed, Jun 11, 2025 at 12:03:16PM +0200, Jiri Slaby (SUSE) wrote:
> 
> ...
> 
>>>> +	if (uart->port.type == PORT_8250_CIR) {
>>>> +		ret = -ENODEV;
>>>> +		goto unlock;
>>>> +	}
>>>
>>>> +	if (up->port.flags & UPF_FIXED_TYPE)
>>>> +		uart->port.type = up->port.type;
>>>
>>>> +	if (uart->port.type != PORT_8250_CIR) {
>>>
>>> I admit that there tons of mysterious ways of UART initialisation, but can you
>>> elaborate how this is not a always-true conditional?
>>
>> Careful here, someone had an idea in the past that this is indeed
>> a dead code/branch and ended causing a regression [1].

Right, I was confused too, but then I noticed there is:
   uart->port.type = up->port.type;
in between the tests.

>> It would definitely make sense to add a comment describing the code
>> flow there though as it proven to bewilder people.
> 
> Yes, this is my point between the lines. I left the code that may affect the
> type change and the second check needs a comment explaining these cases, if any.
> "If any" defines "always-true" or not conditional. W//o a comment this code
> tends to be updated again and lead to a regression.

ACK, I will.

-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition
  2025-06-23  7:05         ` Jiri Slaby
@ 2025-06-23  7:17           ` Andy Shevchenko
  0 siblings, 0 replies; 91+ messages in thread
From: Andy Shevchenko @ 2025-06-23  7:17 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Andy Shevchenko, Maciej S. Szmigiero, Ilpo Järvinen, gregkh,
	linux-serial, linux-kernel

On Mon, Jun 23, 2025 at 09:05:46AM +0200, Jiri Slaby wrote:
> On 21. 06. 25, 21:08, Andy Shevchenko wrote:
> > Fri, Jun 20, 2025 at 11:48:09PM +0200, Maciej S. Szmigiero kirjoitti:
> > > On 18.06.2025 07:48, Andy Shevchenko wrote:
> > > > On Wed, Jun 11, 2025 at 12:03:16PM +0200, Jiri Slaby (SUSE) wrote:

...

> > > > > +	if (uart->port.type == PORT_8250_CIR) {
> > > > > +		ret = -ENODEV;
> > > > > +		goto unlock;
> > > > > +	}
> > > > 
> > > > > +	if (up->port.flags & UPF_FIXED_TYPE)
> > > > > +		uart->port.type = up->port.type;
> > > > 
> > > > > +	if (uart->port.type != PORT_8250_CIR) {
> > > > 
> > > > I admit that there tons of mysterious ways of UART initialisation, but can you
> > > > elaborate how this is not a always-true conditional?
> > > 
> > > Careful here, someone had an idea in the past that this is indeed
> > > a dead code/branch and ended causing a regression [1].
> 
> Right, I was confused too, but then I noticed there is:
>   uart->port.type = up->port.type;
> in between the tests.
> 
> > > It would definitely make sense to add a comment describing the code
> > > flow there though as it proven to bewilder people.
> > 
> > Yes, this is my point between the lines. I left the code that may affect the
> > type change and the second check needs a comment explaining these cases, if any.
> > "If any" defines "always-true" or not conditional. W//o a comment this code
> > tends to be updated again and lead to a regression.
> 
> ACK, I will.

Thanks!

Looking at the code again, I think it deserves actually two comments, on top of
each of the checks against PORT_8250_CIR.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 23/33] serial: 8250: extract serial8250_set_efr()
  2025-06-12 18:54       ` Andy Shevchenko
@ 2025-06-23  7:20         ` Jiri Slaby
  0 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby @ 2025-06-23  7:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Ilpo Järvinen, Greg Kroah-Hartman, linux-serial, LKML

On 12. 06. 25, 20:54, Andy Shevchenko wrote:
> On Thu, Jun 12, 2025 at 12:01:29PM +0200, Jiri Slaby wrote:
>> On 11. 06. 25, 14:58, Ilpo Järvinen wrote:
>>> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
> ...
> 
>>>> +	if (port->flags & UPF_EXAR_EFR)
>>>
>>> I wonder if it is possible to trigger this at all? Only 8250_exar.c sets
>>> this flag and does not contain UART_CAP_EFR at all (nor uses
>>> UPF_BOOT_AUTOCONF)??
> 
> The file indeed does not contain it, BUT it sets it implicitly (via port type).
> So, this is not a dead code. Please, do not remove it.

Ah, both PORT_XR17D15X and PORT_XR17V35X set UART_CAP_EFR in uart_config[].

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper
  2025-06-11 11:13   ` Ilpo Järvinen
@ 2025-06-23  7:30     ` Jiri Slaby
  0 siblings, 0 replies; 91+ messages in thread
From: Jiri Slaby @ 2025-06-23  7:30 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Karsten Keil, David Lin,
	Johan Hovold, Alex Elder, Oliver Neukum, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Netdev, greybus-dev,
	linux-staging, linux-usb, linux-bluetooth

On 11. 06. 25, 13:13, Ilpo Järvinen wrote:
> On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> 
>> This code (tty_get -> vhangup -> tty_put) is repeated on few places.
>> Introduce a helper similar to tty_port_tty_hangup() (asynchronous) to
>> handle even vhangup (synchronous).
>>
>> And use it on those places.
>>
>> In fact, reuse the tty_port_tty_hangup()'s code and call tty_vhangup()
>> depending on a new bool parameter.
>>
>> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
>> Cc: Karsten Keil <isdn@linux-pingi.de>
>> Cc: David Lin <dtwlin@gmail.com>
>> Cc: Johan Hovold <johan@kernel.org>
>> Cc: Alex Elder <elder@kernel.org>
>> Cc: Oliver Neukum <oneukum@suse.com>
>> Cc: Marcel Holtmann <marcel@holtmann.org>
>> Cc: Johan Hedberg <johan.hedberg@gmail.com>
>> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> 
> Nice cleanup. I'm not sure if it's important enough to be mentioned in
> Documentation/driver-api/tty/tty_port.rst .

At minimum I broke tty_port_tty_hangup()'s kernel-doc:
/**
  * tty_port_tty_hangup - helper to hang up a tty
  * @port: tty port
  * @check_clocal: hang only ttys with %CLOCAL unset?
  */
  void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, 
bool async)


doc says tty_port_tty_hangup(), code says __tty_port_tty_hangup(). Fix 
coming, incl. vhangup addition.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
  2025-06-11 11:30   ` Ilpo Järvinen
  2025-06-11 14:42   ` Nicolas Pitre
@ 2025-07-31 14:35   ` Christophe Leroy
  2025-07-31 14:41     ` Christophe Leroy
  2 siblings, 1 reply; 91+ messages in thread
From: Christophe Leroy @ 2025-07-31 14:35 UTC (permalink / raw)
  To: Jiri Slaby (SUSE), gregkh, Christian Zigotzky
  Cc: linux-serial, linux-kernel, Nicolas Pitre,
	linuxppc-dev@lists.ozlabs.org

Hi Jiri,

Le 11/06/2025 à 12:02, Jiri Slaby (SUSE) a écrit :
> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
> were synthetically built up the same way the _IO() macro does.
> 
> So instead of implicit hex numbers, use _IO() properly.
> 
> To not change the pre-existing numbers, use only _IO() (and not _IOR()
> or _IOW()). The latter would change the numbers indeed.

On powerpc your assumption is wrong, because _IOC_NONE is not 0:

$ git grep _IOC_NONE arch/powerpc/
arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE 1U

Therefore the value changes even with _IO(), leading to failure of Xorg 
as reported by Christian.

Christophe

> 
> Objdump of vt_ioctl.o reveals no difference with this patch.
> 
> Again, VT_GETCONSIZECSRPOS already uses _IOR(), so everything is paved
> for this patch.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Nicolas Pitre <nico@fluxnic.net>
> ---
>   include/uapi/linux/vt.h | 34 +++++++++++++++++-----------------
>   1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
> index 714483d68c69..b60fcdfb2746 100644
> --- a/include/uapi/linux/vt.h
> +++ b/include/uapi/linux/vt.h
> @@ -14,9 +14,9 @@
>   		/* Note: the ioctl VT_GETSTATE does not work for
>   		   consoles 16 and higher (since it returns a short) */
>   
> -/* 0x56 is 'V', to avoid collision with termios and kd */
> +/* 'V' to avoid collision with termios and kd */
>   
> -#define VT_OPENQRY	0x5600	/* find available vt */
> +#define VT_OPENQRY		_IO('V', 0x00)	/* find available vt */
>   
>   struct vt_mode {
>   	__u8 mode;		/* vt mode */
> @@ -25,8 +25,8 @@ struct vt_mode {
>   	__s16 acqsig;		/* signal to raise on acquisition */
>   	__s16 frsig;		/* unused (set to 0) */
>   };
> -#define VT_GETMODE	0x5601	/* get mode of active vt */
> -#define VT_SETMODE	0x5602	/* set mode of active vt */
> +#define VT_GETMODE		_IO('V', 0x01)	/* get mode of active vt */
> +#define VT_SETMODE		_IO('V', 0x02)	/* set mode of active vt */
>   #define		VT_AUTO		0x00	/* auto vt switching */
>   #define		VT_PROCESS	0x01	/* process controls switching */
>   #define		VT_ACKACQ	0x02	/* acknowledge switch */
> @@ -36,21 +36,21 @@ struct vt_stat {
>   	__u16 v_signal;	/* signal to send */
>   	__u16 v_state;		/* vt bitmask */
>   };
> -#define VT_GETSTATE	0x5603	/* get global vt state info */
> -#define VT_SENDSIG	0x5604	/* signal to send to bitmask of vts */
> +#define VT_GETSTATE		_IO('V', 0x03)	/* get global vt state info */
> +#define VT_SENDSIG		_IO('V', 0x04)	/* signal to send to bitmask of vts */
>   
> -#define VT_RELDISP	0x5605	/* release display */
> +#define VT_RELDISP		_IO('V', 0x05)	/* release display */
>   
> -#define VT_ACTIVATE	0x5606	/* make vt active */
> -#define VT_WAITACTIVE	0x5607	/* wait for vt active */
> -#define VT_DISALLOCATE	0x5608  /* free memory associated to vt */
> +#define VT_ACTIVATE		_IO('V', 0x06)	/* make vt active */
> +#define VT_WAITACTIVE		_IO('V', 0x07)	/* wait for vt active */
> +#define VT_DISALLOCATE		_IO('V', 0x08)  /* free memory associated to vt */
>   
>   struct vt_sizes {
>   	__u16 v_rows;		/* number of rows */
>   	__u16 v_cols;		/* number of columns */
>   	__u16 v_scrollsize;	/* number of lines of scrollback */
>   };
> -#define VT_RESIZE	0x5609	/* set kernel's idea of screensize */
> +#define VT_RESIZE		_IO('V', 0x09)	/* set kernel's idea of screensize */
>   
>   struct vt_consize {
>   	__u16 v_rows;	/* number of rows */
> @@ -60,10 +60,10 @@ struct vt_consize {
>   	__u16 v_vcol;	/* number of pixel columns on screen */
>   	__u16 v_ccol;	/* number of pixel columns per character */
>   };
> -#define VT_RESIZEX      0x560A  /* set kernel's idea of screensize + more */
> -#define VT_LOCKSWITCH   0x560B  /* disallow vt switching */
> -#define VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
> -#define VT_GETHIFONTMASK 0x560D  /* return hi font mask */
> +#define VT_RESIZEX		_IO('V', 0x0A)  /* set kernel's idea of screensize + more */
> +#define VT_LOCKSWITCH		_IO('V', 0x0B)  /* disallow vt switching */
> +#define VT_UNLOCKSWITCH		_IO('V', 0x0C)  /* allow vt switching */
> +#define VT_GETHIFONTMASK	_IO('V', 0x0D)  /* return hi font mask */
>   
>   struct vt_event {
>   	__u32 event;
> @@ -77,14 +77,14 @@ struct vt_event {
>   	__u32 pad[4];		/* Padding for expansion */
>   };
>   
> -#define VT_WAITEVENT	0x560E	/* Wait for an event */
> +#define VT_WAITEVENT		_IO('V', 0x0E)	/* Wait for an event */
>   
>   struct vt_setactivate {
>   	__u32 console;
>   	struct vt_mode mode;
>   };
>   
> -#define VT_SETACTIVATE	0x560F	/* Activate and set the mode of a console */
> +#define VT_SETACTIVATE		_IO('V', 0x0F)	/* Activate and set the mode of a console */
>   
>   /* get console size and cursor position */
>   struct vt_consizecsrpos {


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-07-31 14:35   ` Christophe Leroy
@ 2025-07-31 14:41     ` Christophe Leroy
  2025-07-31 20:58       ` Nicolas Pitre
  0 siblings, 1 reply; 91+ messages in thread
From: Christophe Leroy @ 2025-07-31 14:41 UTC (permalink / raw)
  To: Jiri Slaby (SUSE), gregkh, Christian Zigotzky
  Cc: linux-serial, linux-kernel, Nicolas Pitre,
	linuxppc-dev@lists.ozlabs.org



Le 31/07/2025 à 16:35, Christophe Leroy a écrit :
> Hi Jiri,
> 
> Le 11/06/2025 à 12:02, Jiri Slaby (SUSE) a écrit :
>> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
>> were synthetically built up the same way the _IO() macro does.
>>
>> So instead of implicit hex numbers, use _IO() properly.
>>
>> To not change the pre-existing numbers, use only _IO() (and not _IOR()
>> or _IOW()). The latter would change the numbers indeed.
> 
> On powerpc your assumption is wrong, because _IOC_NONE is not 0:
> 
> $ git grep _IOC_NONE arch/powerpc/
> arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE 1U
> 
> Therefore the value changes even with _IO(), leading to failure of Xorg 
> as reported by Christian.
> 

And is likely an issue on the 4 following architectures:

$ git grep _IOC_NONE arch/ | grep 1U
arch/alpha/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
arch/mips/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
arch/sparc/include/uapi/asm/ioctl.h:#define _IOC_NONE        1U


Christophe


^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-07-31 14:41     ` Christophe Leroy
@ 2025-07-31 20:58       ` Nicolas Pitre
  2025-08-01  4:47         ` Jiri Slaby
  0 siblings, 1 reply; 91+ messages in thread
From: Nicolas Pitre @ 2025-07-31 20:58 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Jiri Slaby (SUSE), gregkh, Christian Zigotzky, linux-serial,
	linux-kernel, linuxppc-dev@lists.ozlabs.org

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

On Thu, 31 Jul 2025, Christophe Leroy wrote:

> 
> 
> Le 31/07/2025 à 16:35, Christophe Leroy a écrit :
> > Hi Jiri,
> > 
> > Le 11/06/2025 à 12:02, Jiri Slaby (SUSE) a écrit :
> >> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
> >> were synthetically built up the same way the _IO() macro does.
> >>
> >> So instead of implicit hex numbers, use _IO() properly.
> >>
> >> To not change the pre-existing numbers, use only _IO() (and not _IOR()
> >> or _IOW()). The latter would change the numbers indeed.
> > 
> > On powerpc your assumption is wrong, because _IOC_NONE is not 0:
> > 
> > $ git grep _IOC_NONE arch/powerpc/
> > arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE 1U
> > 
> > Therefore the value changes even with _IO(), leading to failure of Xorg as
> > reported by Christian.
> > 
> 
> And is likely an issue on the 4 following architectures:
> 
> $ git grep _IOC_NONE arch/ | grep 1U
> arch/alpha/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> arch/mips/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> arch/sparc/include/uapi/asm/ioctl.h:#define _IOC_NONE        1U

IMHO this one patch could simply be reverted and the "old" code let be.


Nicolas

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-07-31 20:58       ` Nicolas Pitre
@ 2025-08-01  4:47         ` Jiri Slaby
  2025-08-01  7:38           ` Greg KH
  0 siblings, 1 reply; 91+ messages in thread
From: Jiri Slaby @ 2025-08-01  4:47 UTC (permalink / raw)
  To: Nicolas Pitre, Christophe Leroy
  Cc: gregkh, Christian Zigotzky, linux-serial, linux-kernel,
	linuxppc-dev@lists.ozlabs.org

On 31. 07. 25, 22:58, Nicolas Pitre wrote:
> On Thu, 31 Jul 2025, Christophe Leroy wrote:
> 
>>
>>
>> Le 31/07/2025 à 16:35, Christophe Leroy a écrit :
>>> Hi Jiri,
>>>
>>> Le 11/06/2025 à 12:02, Jiri Slaby (SUSE) a écrit :
>>>> _IO*() is the proper way of defining ioctl numbers. All these vt numbers
>>>> were synthetically built up the same way the _IO() macro does.
>>>>
>>>> So instead of implicit hex numbers, use _IO() properly.
>>>>
>>>> To not change the pre-existing numbers, use only _IO() (and not _IOR()
>>>> or _IOW()). The latter would change the numbers indeed.
>>>
>>> On powerpc your assumption is wrong, because _IOC_NONE is not 0:
>>>
>>> $ git grep _IOC_NONE arch/powerpc/
>>> arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE 1U
>>>
>>> Therefore the value changes even with _IO(), leading to failure of Xorg as
>>> reported by Christian.
>>>
>>
>> And is likely an issue on the 4 following architectures:
>>
>> $ git grep _IOC_NONE arch/ | grep 1U
>> arch/alpha/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
>> arch/mips/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
>> arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
>> arch/sparc/include/uapi/asm/ioctl.h:#define _IOC_NONE        1U
> 
> IMHO this one patch could simply be reverted and the "old" code let be.

Oh, right -- it's easy to revert (no conflicts).

We could use _IOC(0, 'V', number, 0) directly, but I am not sure, that's 
worth it.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers
  2025-08-01  4:47         ` Jiri Slaby
@ 2025-08-01  7:38           ` Greg KH
  0 siblings, 0 replies; 91+ messages in thread
From: Greg KH @ 2025-08-01  7:38 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Nicolas Pitre, Christophe Leroy, Christian Zigotzky, linux-serial,
	linux-kernel, linuxppc-dev@lists.ozlabs.org

On Fri, Aug 01, 2025 at 06:47:46AM +0200, Jiri Slaby wrote:
> On 31. 07. 25, 22:58, Nicolas Pitre wrote:
> > On Thu, 31 Jul 2025, Christophe Leroy wrote:
> > 
> > > 
> > > 
> > > Le 31/07/2025 à 16:35, Christophe Leroy a écrit :
> > > > Hi Jiri,
> > > > 
> > > > Le 11/06/2025 à 12:02, Jiri Slaby (SUSE) a écrit :
> > > > > _IO*() is the proper way of defining ioctl numbers. All these vt numbers
> > > > > were synthetically built up the same way the _IO() macro does.
> > > > > 
> > > > > So instead of implicit hex numbers, use _IO() properly.
> > > > > 
> > > > > To not change the pre-existing numbers, use only _IO() (and not _IOR()
> > > > > or _IOW()). The latter would change the numbers indeed.
> > > > 
> > > > On powerpc your assumption is wrong, because _IOC_NONE is not 0:
> > > > 
> > > > $ git grep _IOC_NONE arch/powerpc/
> > > > arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE 1U
> > > > 
> > > > Therefore the value changes even with _IO(), leading to failure of Xorg as
> > > > reported by Christian.
> > > > 
> > > 
> > > And is likely an issue on the 4 following architectures:
> > > 
> > > $ git grep _IOC_NONE arch/ | grep 1U
> > > arch/alpha/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> > > arch/mips/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> > > arch/powerpc/include/uapi/asm/ioctl.h:#define _IOC_NONE	1U
> > > arch/sparc/include/uapi/asm/ioctl.h:#define _IOC_NONE        1U
> > 
> > IMHO this one patch could simply be reverted and the "old" code let be.
> 
> Oh, right -- it's easy to revert (no conflicts).
> 
> We could use _IOC(0, 'V', number, 0) directly, but I am not sure, that's
> worth it.

Great, can someone send me a revert?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 91+ messages in thread

end of thread, other threads:[~2025-08-01  7:38 UTC | newest]

Thread overview: 91+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 10:02 [PATCH 00/33] tty: summer cleanup Jiri Slaby (SUSE)
2025-06-11 10:02 ` [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Jiri Slaby (SUSE)
2025-06-11 11:13   ` Ilpo Järvinen
2025-06-23  7:30     ` Jiri Slaby
2025-06-11 10:02 ` [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port() Jiri Slaby (SUSE)
2025-06-11 11:15   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 03/33] powerpc/legacy_serial: use %pa for phys_addr_t prints Jiri Slaby (SUSE)
2025-06-11 10:02 ` [PATCH 04/33] m68k: remove unneeded tty includes Jiri Slaby (SUSE)
2025-06-11 11:22   ` Ilpo Järvinen
2025-06-17 12:29   ` Geert Uytterhoeven
2025-06-11 10:02 ` [PATCH 05/33] powerpc/powermac: " Jiri Slaby (SUSE)
2025-06-11 11:25   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 06/33] tty: vt: use sane types for userspace API Jiri Slaby (SUSE)
2025-06-11 14:38   ` Nicolas Pitre
2025-06-11 10:02 ` [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Jiri Slaby (SUSE)
2025-06-11 11:30   ` Ilpo Järvinen
2025-06-11 14:42   ` Nicolas Pitre
2025-07-31 14:35   ` Christophe Leroy
2025-07-31 14:41     ` Christophe Leroy
2025-07-31 20:58       ` Nicolas Pitre
2025-08-01  4:47         ` Jiri Slaby
2025-08-01  7:38           ` Greg KH
2025-06-11 10:02 ` [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types Jiri Slaby (SUSE)
2025-06-11 15:12   ` Andy Shevchenko
2025-06-23  6:55     ` Jiri Slaby
2025-06-11 10:02 ` [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Jiri Slaby (SUSE)
2025-06-11 11:42   ` Ilpo Järvinen
2025-06-11 11:46   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 10/33] serial: 8250: invert conditions in RSA functions Jiri Slaby (SUSE)
2025-06-11 11:45   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 11/33] serial: 8250: put RSA functions to their namespace Jiri Slaby (SUSE)
2025-06-11 11:54   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c Jiri Slaby (SUSE)
2025-06-11 11:49   ` Ilpo Järvinen
2025-06-11 10:02 ` [PATCH 13/33] serial: 8250: extract serial8250_startup_special() Jiri Slaby (SUSE)
2025-06-11 11:53   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels() Jiri Slaby (SUSE)
2025-06-11 12:07   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 15/33] serial: 8250: extract serial8250_THRE_test() Jiri Slaby (SUSE)
2025-06-11 12:03   ` Ilpo Järvinen
2025-06-12  8:54     ` Jiri Slaby
2025-06-12  9:18       ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 16/33] serial: 8250: extract serial8250_initialize() Jiri Slaby (SUSE)
2025-06-11 12:19   ` Ilpo Järvinen
2025-06-23  6:59     ` Jiri Slaby
2025-06-11 10:03 ` [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts() Jiri Slaby (SUSE)
2025-06-11 12:27   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 18/33] serial: 8250: extract serial8250_set_mini() Jiri Slaby (SUSE)
2025-06-11 12:29   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed() Jiri Slaby (SUSE)
2025-06-11 12:34   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 20/33] serial: 8250: extract serial8250_set_afe() Jiri Slaby (SUSE)
2025-06-11 12:35   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores Jiri Slaby (SUSE)
2025-06-11 12:43   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 22/33] serial: 8250: extract serial8250_set_ier() Jiri Slaby (SUSE)
2025-06-11 12:47   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 23/33] serial: 8250: extract serial8250_set_efr() Jiri Slaby (SUSE)
2025-06-11 12:58   ` Ilpo Järvinen
2025-06-12 10:01     ` Jiri Slaby
2025-06-12 10:04       ` Jiri Slaby
2025-06-12 13:33         ` Andy Shevchenko
2025-06-12 18:54       ` Andy Shevchenko
2025-06-23  7:20         ` Jiri Slaby
2025-06-11 10:03 ` [PATCH 24/33] serial: 8250: extract serial8250_set_fcr() Jiri Slaby (SUSE)
2025-06-11 13:01   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 25/33] serial: 8250: lcr compute cleanup Jiri Slaby (SUSE)
2025-06-11 13:03   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor() Jiri Slaby (SUSE)
2025-06-11 13:04   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info() Jiri Slaby (SUSE)
2025-06-11 13:09   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 28/33] serial: 8250: remove debug prints from ISR Jiri Slaby (SUSE)
2025-06-11 13:09   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Jiri Slaby (SUSE)
2025-06-11 13:10   ` Ilpo Järvinen
2025-06-17 11:32   ` Maciej W. Rozycki
2025-06-17 11:42     ` Greg Kroah-Hartman
2025-06-17 13:21       ` Maciej W. Rozycki
2025-06-11 10:03 ` [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Jiri Slaby (SUSE)
2025-06-11 13:21   ` Ilpo Järvinen
2025-06-18  5:48   ` Andy Shevchenko
2025-06-20 21:48     ` Maciej S. Szmigiero
2025-06-21 19:08       ` Andy Shevchenko
2025-06-23  7:05         ` Jiri Slaby
2025-06-23  7:17           ` Andy Shevchenko
2025-06-11 10:03 ` [PATCH 31/33] serial: 8250: invert condition to avoid a goto label Jiri Slaby (SUSE)
2025-06-18  5:45   ` Andy Shevchenko
2025-06-11 10:03 ` [PATCH 32/33] serial: 8250: use hashtable Jiri Slaby (SUSE)
2025-06-11 13:25   ` Ilpo Järvinen
2025-06-11 10:03 ` [PATCH 33/33] serial: 8250_omap: use uart_port pointer when available Jiri Slaby (SUSE)

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).