From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DFCB26463A; Wed, 11 Jun 2025 10:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636207; cv=none; b=aKSYiPNb2J2bAbZandYCCZ4jYSE4ZMXL4gFlWe9a+vJKWPE+n2cGLnFc7Cri2RJl0et5hfnJPhEBUbnqiwFOC2LObVxThUZufRcOBMr39+nbdAwlLsxZksEGDiaYg8+i0pFU/oswyrsV6Pq/CB5dBLjY/6flO81ESFccVV5uB/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636207; c=relaxed/simple; bh=KpqxD4POGHfy23PplJeilT9uuVSTNzfSBk37cW0+nQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QDlNdixQpjPhkbTYGbuSJxMzJU70g+25Z7vCDQOMSXOsi2eUzNKeHy+nWMRc7y6pCmjbhBZ7rplHV8k4md09iDSr+PeFFWMp2Lzv4B97IMXlUJXoW/8849nVSdyUp79FB61M2884WNBeA7qO2tmEknffsPPV+ySQxc4PdL1Ae5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rU7fDQ+5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rU7fDQ+5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A41EC4CEF4; Wed, 11 Jun 2025 10:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636206; bh=KpqxD4POGHfy23PplJeilT9uuVSTNzfSBk37cW0+nQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rU7fDQ+5pTYxH0ytcyrwQgoHOCsVbLm5NnmPR4QFM0EM7EYgtNRw+LFFxwP/Hhvao RIt1V9+ZnGAgKnDI6H/E4rtFQMXK/OetCGUZs/5SVxBGM3dOb202foEfio4q9rZdM8 /9O1Q0cFZ39DFXyVVZ9SHjAtKdBm9c4dRuuf2uOdhp6eKCde1oiDfHR1ENgAK1nG8C yXw+d0dOokqHgp6SFTQPGfBbmouyYt6/EtfGIqbM3KdlFyrIEEaieGuf750zrtL3+Q xe4o9rTBfWY92n/+czgIgmUxYeaQUROIjdvAi5IkXrVpA5nAA/Kd5+4no3uz4J2TAB r3iVHsKUHwmXg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Karsten Keil , David Lin , Johan Hovold , Alex Elder , Oliver Neukum , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , netdev@vger.kernel.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org Subject: [PATCH 01/33] tty: introduce and use tty_port_tty_vhangup() helper Date: Wed, 11 Jun 2025 12:02:47 +0200 Message-ID: <20250611100319.186924-2-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Cc: Karsten Keil Cc: David Lin Cc: Johan Hovold Cc: Alex Elder Cc: Oliver Neukum Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Reviewed-by: Ilpo J=C3=A4rvinen --- 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 =3D np->minorp; - struct tty_struct *tty; =20 if (mp) { - tty =3D 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_d= ev) { struct gb_tty *gb_tty =3D gb_gbphy_get_data(gbphy_dev); struct gb_connection *connection =3D gb_tty->connection; - struct tty_struct *tty; int ret; =20 ret =3D 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); =20 - tty =3D tty_port_tty_get(&gb_tty->port); - if (tty) { - tty_vhangup(tty); - tty_kref_put(tty); - } + tty_port_tty_vhangup(&gb_tty->port); =20 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_c= ore.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_d= river *drv, struct uart_state *state =3D drv->state + uport->line; struct tty_port *port =3D &state->port; struct uart_port *uart_port; - struct tty_struct *tty; =20 mutex_lock(&port->mutex); uart_port =3D 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); =20 - tty =3D tty_port_tty_get(port); - if (tty) { - tty_vhangup(port->tty); - tty_kref_put(tty); - } + tty_port_tty_vhangup(port); =20 /* * 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 =3D tty_port_tty_get(port); =20 - 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); =20 /** * 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 =3D usb_get_intfdata(intf); - struct tty_struct *tty; int i; =20 /* sibling interface is already cleaning up */ @@ -1598,11 +1597,7 @@ static void acm_disconnect(struct usb_interface *int= f) usb_set_intfdata(acm->data, NULL); mutex_unlock(&acm->mutex); =20 - tty =3D tty_port_tty_get(&acm->port); - if (tty) { - tty_vhangup(tty); - tty_kref_put(tty); - } + tty_port_tty_vhangup(&acm->port); =20 cancel_delayed_work_sync(&acm->dwork); =20 diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-seria= l.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_interfac= e *interface) struct usb_serial *serial =3D usb_get_intfdata(interface); struct device *dev =3D &interface->dev; struct usb_serial_port *port; - struct tty_struct *tty; =20 /* sibling interface is cleaning up */ if (!serial) @@ -1191,11 +1190,7 @@ static void usb_serial_disconnect(struct usb_interfa= ce *interface) =20 for (i =3D 0; i < serial->num_ports; ++i) { port =3D serial->port[i]; - tty =3D 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; } =20 +static inline void tty_port_tty_hangup(struct tty_port *port, bool check_c= local) +{ + __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; =20 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); =20 /* Shut down TTY synchronously before freeing rfcomm_dev */ - tty =3D tty_port_tty_get(&dev->port); - if (tty) { - tty_vhangup(tty); - tty_kref_put(tty); - } + tty_port_tty_vhangup(&dev->port); =20 if (!test_bit(RFCOMM_TTY_OWNED, &dev->status)) tty_port_put(&dev->port); --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 935B6267AF7; Wed, 11 Jun 2025 10:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636209; cv=none; b=ToIrtw/gPDz9HZy1OXGIyMG5N3LT20yt+B9zsgR7ip/HwXmIjgfV9LOobo79xddpxMz/z9fdaO82MIOGNosEJO/QHB7m7Zhj4NBq7m5RqMWqmIcNgt6DtpS/JrxVhzG2lUZ4CPQBoGGTfpwgBxg2TI7QtHHgCtTTZ0+uDoScw74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636209; c=relaxed/simple; bh=8bnFg7Ex1c31Wg8ZGfwLvn1m/DM1vD49g1g+c7qmqE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4nWYoIG8V6LV4TQwXiJ5WDp4E0R1QtTMI+SvM+FJ/j8sy+x3VN68e+41E4p3mCoyAkyzHZDJY5Sv3xJO/NKPNiI5oLtV4v390wqyUIkV6Zyxi4f0vwEWr1lhSteK7poe1F5tQKUw2YY498pW8aKkwLwXaVZ35KQqhMi7TWgZec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rfgyq3tc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rfgyq3tc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19293C4CEF5; Wed, 11 Jun 2025 10:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636209; bh=8bnFg7Ex1c31Wg8ZGfwLvn1m/DM1vD49g1g+c7qmqE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfgyq3tczjfCxpExT7x4sCS2GTkABalaCVdcqQW2DYDoWoLPGVpvmAbLHZwZh7kye Q+km2FU/OK951dY5/AobofzeH1DR1H52TR/vJs4yaCvod/K7io9IlMom970gOaP4lq HDVquE2oKLHj7taHe+S2EjUKCc44HiAKq9XF4H/u7jcCURN0oTMaHv3D0MLgdWs7Hq UMoSztVaQPk3xRXeQL1NjWzGVGypSVRfRHL6uExX/LqU5wPqhH+7typ8d6ThDjMnFC Llk1oy7xE4FbxT1NgdJYE20McAHnWNOUQJN+BoedB2vMU5BiImvnnTebP7Ih6QtMxU buXjjXwmjgi3Q== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 02/33] powerpc/legacy_serial: cache serial port and info in add_legacy_port() Date: Wed, 11 Jun 2025 12:02:48 +0200 Message-ID: <20250611100319.186924-3-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Caching the port and info in local variables makes the code more compact and easier to understand. Signed-off-by: Jiri Slaby (SUSE) Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Ilpo J=C3=A4rvinen --- 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/lega= cy_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 =3D BASE_BAUD * 16; u32 shift =3D 0; @@ -110,16 +112,17 @@ static int __init add_legacy_port(struct device_node = *np, int want_index, if (index >=3D legacy_serial_count) legacy_serial_count =3D index + 1; =20 + legacy_port =3D &legacy_serial_ports[index]; + legacy_info =3D &legacy_serial_infos[index]; + /* Check if there is a port who already claimed our slot */ - if (legacy_serial_infos[index].np !=3D NULL) { + if (legacy_info->np !=3D 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] =3D - legacy_serial_ports[index]; - legacy_serial_infos[legacy_serial_count] =3D - legacy_serial_infos[index]; + legacy_serial_ports[legacy_serial_count] =3D *legacy_port; + legacy_serial_infos[legacy_serial_count] =3D *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, } =20 /* Now fill the entry */ - memset(&legacy_serial_ports[index], 0, - sizeof(struct plat_serial8250_port)); + memset(legacy_port, 0, sizeof(*legacy_port)); if (iotype =3D=3D UPIO_PORT) - legacy_serial_ports[index].iobase =3D base; + legacy_port->iobase =3D base; else - legacy_serial_ports[index].mapbase =3D base; - - legacy_serial_ports[index].iotype =3D iotype; - legacy_serial_ports[index].uartclk =3D clock; - legacy_serial_ports[index].irq =3D irq; - legacy_serial_ports[index].flags =3D flags; - legacy_serial_ports[index].regshift =3D shift; - legacy_serial_infos[index].taddr =3D taddr; - legacy_serial_infos[index].np =3D of_node_get(np); - legacy_serial_infos[index].clock =3D clock; - legacy_serial_infos[index].speed =3D spd ? be32_to_cpup(spd) : 0; - legacy_serial_infos[index].irq_check_parent =3D irq_check_parent; + legacy_port->mapbase =3D base; + + legacy_port->iotype =3D iotype; + legacy_port->uartclk =3D clock; + legacy_port->irq =3D irq; + legacy_port->flags =3D flags; + legacy_port->regshift =3D shift; + legacy_info->taddr =3D taddr; + legacy_info->np =3D of_node_get(np); + legacy_info->clock =3D clock; + legacy_info->speed =3D spd ? be32_to_cpup(spd) : 0; + legacy_info->irq_check_parent =3D irq_check_parent; =20 if (iotype =3D=3D UPIO_TSI) { - legacy_serial_ports[index].serial_in =3D tsi_serial_in; - legacy_serial_ports[index].serial_out =3D tsi_serial_out; + legacy_port->serial_in =3D tsi_serial_in; + legacy_port->serial_out =3D tsi_serial_out; } =20 - 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=3D%llx, taddr=3D%llx, irq=3D%lx, clk=3D%d, speed= =3D%d\n", (iotype =3D=3D 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); =20 return index; } --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 812A12620CD; Wed, 11 Jun 2025 10:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636211; cv=none; b=pnG1DeSG//lynAsNkOdJDqOtS9gQ0zNrvA7LplwwHgMJGrpbaWDPwO6KeifmWdLcqRtjhDi4oro1jSWQm2Jm1S3HH7dxKq+Z+n3wvqVBnHkaDLaNpdT+se+K+7w+2PYnQAzplKAArFa0i9aDBGsuCCBsseJOv4fx1x/KBfoyWCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636211; c=relaxed/simple; bh=yxtl7EkAbzex+676ZNuv1dtaZF4rmNGRTIkf1D3Ud1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VD0bu8Z8LigphlHswkMiFGsI8PMYr8KG28zIiBaJkZtjQwbyhLwBNG7RTsZq1FIpymUHIFyzM9yJZVpGUOy1DvzJt6I0YwWtdMg+2L5X+Wvtgh7tiCB3xlj/Qzqic/CmrvI8/KJa++1l2behLkZM8elkTfI3r3s6ApfTs2TRcaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CNUOYO7f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CNUOYO7f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 863D8C4CEEE; Wed, 11 Jun 2025 10:03:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636211; bh=yxtl7EkAbzex+676ZNuv1dtaZF4rmNGRTIkf1D3Ud1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CNUOYO7fgfGC6GZ+qBkpFyS167m1YE+R5rSbIl9pzS0PKWVB2GP5whyUKGJFTfaO6 dWF1dYOGPR+3vhRLVo26E3rrCxpb5v3wKCog5JfbU+rggD6CZjYG9H9k1/7ilYnjL6 aoNo/OgvGoB8OrX0Wvck31pFeaLwSDQLDlAYHG9gxAPQv28I6swlx3rcsnawbna8MC 04Y85mry8Heh/bArpPqF0O39h3HYfLztHrnyXyWArr2qPViq2DmGZl0g7dNDnOPlVs q7ui1Nm3XUc5qGGz3/J4vDcj7BqdMKsS0ZS1pxaqOaPYOR50uBIU0/YohflJ+0DsSi NspBeOWDUssPw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy Subject: [PATCH 03/33] powerpc/legacy_serial: use %pa for phys_addr_t prints Date: Wed, 11 Jun 2025 12:02:49 +0200 Message-ID: <20250611100319.186924-4-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It makes the code easier to read as casts are not needed. Signed-off-by: Jiri Slaby (SUSE) Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy --- 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/lega= cy_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, } =20 printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n", index, np); - printk(KERN_DEBUG " %s=3D%llx, taddr=3D%llx, irq=3D%lx, clk=3D%d, speed= =3D%d\n", + printk(KERN_DEBUG " %s=3D%pa, taddr=3D%pa, irq=3D%lx, clk=3D%d, speed=3D= %d\n", (iotype =3D=3D 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); =20 return index; } --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DADA5268FE3; Wed, 11 Jun 2025 10:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636214; cv=none; b=TSPfXOvEbCU6Yysk9jepG9EDLivInGBNQP/vcR0wZI66R7v6o13WbrPZwGqKem296Y97dNwX4phUvcOsLOuMrQ/I7bRzP1gqEDcLTwI+F5G+XW7cOdjmGpg54ap9yHUpJi6oM7A0p7QELM1bFJYCL8Q+Kk42MElYGAM0XGNV6HQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636214; c=relaxed/simple; bh=1Y4FzCo2NXl7c/uhn5imstUY3/t8FVzQeKAbJ6gBnw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Puj9WXkhoVjJziIMNIZq7Jd5fCy6zFYvoWDQ4gtIvaFsBJv7aUMyzu9sipBsn4RHAKy4WIAaEIrDroviLqJGN3os54KHQ8GoMRSLrU7F2Nqs85LqOmUMNzMOhfDes1JQOYfWQURO2/OLAXt93Nqui7b7bTvT7BaZ8MTTdIfJUYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PEBsnaz3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PEBsnaz3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85E4C4CEEE; Wed, 11 Jun 2025 10:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636213; bh=1Y4FzCo2NXl7c/uhn5imstUY3/t8FVzQeKAbJ6gBnw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEBsnaz3HFBeb6TLd44ARGPr1njs48kgrOk8UmpNQ9H/Mf4p9EEA58bcbHQfkB0YA v6V7kryKz6vtl8E53F+yVU5Kjt8pAJ9zjgLJYChIYmswnZiYBT8BZXePN6xzWvD886 /NPx8ASjPIzGL76qv2mFyowgjwnWRnFfXpik2wa+trTX7Swuj/lPhGOQEoE19BcyVY /xCU+oxXn/t6qmjgzof55tVILyLhqIUNLo8n+nxRxxtI1N69oNvZzhOTH27pplBVRr 3/Q1ACd8ytmrcVMGHmYoz5sMFxF2jrzOV2wYyEoOg1lKiUek8sVZ3vGDIVf9Ia2S2Q J5pxKySzUTZnw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Geert Uytterhoeven , Joshua Thompson , linux-m68k@lists.linux-m68k.org Subject: [PATCH 04/33] m68k: remove unneeded tty includes Date: Wed, 11 Jun 2025 12:02:50 +0200 Message-ID: <20250611100319.186924-5-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Cc: Geert Uytterhoeven Cc: Joshua Thompson Cc: linux-m68k@lists.linux-m68k.org Acked-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven Reviewed-by: Ilpo J=C3=A4rvinen --- 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 #include #include -#include #include #include #include #include -#include #include #include #include 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 #include #include -#include #include -#include #include =20 #include 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 #include #include -#include #include =20 #include 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 #include #include -#include #include #include /* keyb */ @@ -23,7 +22,6 @@ #include /* keyb */ #include -#include #include #include #include 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 #include #include -#include #include #include #include #include #include #include -#include #include #include =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0736A26980C; Wed, 11 Jun 2025 10:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636216; cv=none; b=I8FevkhiuTYDKmibuq+7y04lCkuQiWt9+nDtFqF7gJArzGH/nRxZ9KCq1rq0E9nSxd5J/5JIGqiLoA1PdFXbg+Pc3fZ9s87hPTU8plvBQ4W39/EuEIXvhIF/Pbj2laRtDR9h2pgPwQlCOcYufanXCemfl9dA13ApTyxhc/8TWiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636216; c=relaxed/simple; bh=xpdDYrvECMUpAFvfX9wlypgtkzObQJ4+g7Id2+pjsRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DWBAlj8GOO+rgvV/A9WFcUbRBtgIp+zaMpJ89TzVkGc/KS7EutuWSjdi9Cwi8YXdxHpBVaJVDE0zrxNy92bfez2GiWhABvGWpY94IrmxP5pXryUNGC968LHsixeOb1rzD527+ABYkht+8hXL/HmqCOTWdpmd5OAMS4iIhDb1tgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q/uBsIAO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q/uBsIAO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC70EC4CEF2; Wed, 11 Jun 2025 10:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636215; bh=xpdDYrvECMUpAFvfX9wlypgtkzObQJ4+g7Id2+pjsRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q/uBsIAOyPBot3EUTqSSUaJTbkIUqq3Tv1y31ih14lKsxANAk2Dg2UX8StEuqONUK +AX7H5qsHobFYOtAAYp6ZB3dnuaWUyxC9bStGISrVs0LS1eVyxHXKjn4JrVEOj5xfA P5pG7dQfyc22j8OMseUj5QlZpZS5vTLVi90ZIkzZrolUpJWVtWDIILnnwkKa+0kBP7 rOjxmVTriix+ZE5zKM/rtJf7C49KOOlxqc9LZj90uxuwjUL2CfnzSIW57kD+lw7G5Q 0/47f36oj9kPpZuC2Ghl+ZdlbaKM2UsMXbtcpR1oHOu9yX8iaVUZnFlMe8xdP6c725 FZr3MowarnW9Q== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 05/33] powerpc/powermac: remove unneeded tty includes Date: Wed, 11 Jun 2025 12:02:51 +0200 Message-ID: <20250611100319.186924-6-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Ilpo J=C3=A4rvinen --- arch/powerpc/platforms/powermac/setup.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platfor= ms/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 #include #include -#include #include #include #include #include #include -#include #include #include #include --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0C2D262FDD; Wed, 11 Jun 2025 10:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636219; cv=none; b=npMMzx4zF5ut5lHoyKfN/127Ywkjzi4kXp+J6ZChyzoPsLpYDQbwpy8UemUYCd7E0bRaf8MAqmym7iC0no1AWGJc0D5CXybjjdicrcmzFZM0VYQ+cx4mhMV7qvlnp+glFzswDt/hVpneWAPIgfdeKOXmxgo0mQC87mYR19rE7vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636219; c=relaxed/simple; bh=5Q0CjVoicAIw0CDdGWTMCIuANCo4rMmJyghB0nFaP1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9ZDHcSD2ysGIfk0jbwSMHm3y3YZuw13LkB5fBTS8OtzCucrkrRPRn7BEHXJ5LB6b5iMiJAVYsjhaJXMZp4XkXII3fuc57pXc34AiSTFIot4svikiMgnEcbb9Fyz3LGnqDVYredTj5a1WXgYxye40MSmbLJcD2gjCrtgchdCd54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SOplSrJd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SOplSrJd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55CE1C4CEEE; Wed, 11 Jun 2025 10:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636217; bh=5Q0CjVoicAIw0CDdGWTMCIuANCo4rMmJyghB0nFaP1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SOplSrJd9ABgii074v4h7w8xZcMHgkS4jAd4Flp6KNdVqWwLyH9u1pBHyS7Qitu+T 9LCDjr46Eb1MvWP8QUHWzO7a8sWxjhDcLuyWcE0iloXKFD3MJoURyp9NaYnHuQd5uW AskGJLSerSGHW0LFUl2GgTnMt12/6yBgj68kJG/MK9sqzCNcjmfa4PRwvxJJq4eShl n5wDmRyEr/x48q71ifIVGnTuwiaUM4bLpTqil83uBZ6Oke9xCDvem9QMr/pswth2Tf AiMbedhAJx8nuKmumqXUN3y0RHdpO+BlKSQQbTirJ3CWj2WmFjrkre2ZLK5G2Q8DOW QyS4zbEX35KZw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Nicolas Pitre Subject: [PATCH 06/33] tty: vt: use sane types for userspace API Date: Wed, 11 Jun 2025 12:02:52 +0200 Message-ID: <20250611100319.186924-7-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Cc: Nicolas Pitre Link: https://lore.kernel.org/all/p7p83sq1-4ro2-o924-s9o2-30spr74n076o@syhk= avp.arg/ Reviewed-by: Nicolas Pitre --- 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 */ =20 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 */ =20 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 */ =20 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 */ =20 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 */ =20 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 */ }; =20 #define VT_WAITEVENT 0x560E /* Wait for an event */ =20 struct vt_setactivate { - unsigned int console; + __u32 console; struct vt_mode mode; }; =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0CAA262FDF; Wed, 11 Jun 2025 10:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636219; cv=none; b=OcCkGkZdP7OyJt8VcnZ2ApYCMWHA3Umcy6iToSLcHZH3fO6MXMMtnpWOj3dJzG+AxTZL/0AgjpvrlhvuRaPsV3ioFuSTpxCN9eb9PBzQS6m52NaB592X5yodxcQnlOJ7XWSpujlSSnhtFe1LqaOu/IlK4OjwWQtWIOlAT0NmngI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636219; c=relaxed/simple; bh=VGXfIDzE2QNN2PICBkzKgVdMlq8Xdmxeh79OvSTS4Hw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qKcbcq4CiAyyQPP7a/AL9sX42tofUnrXTBKd2/YkVbdeNbdIX8YNfFNtZRHKosPW4egek51AXnXl9Bl8oHr+QRjCKiv+CF1YIIZEpT4gnyiO6Pv7CdhLJD0NuHXqfPh5JteyNvZ/OOIiitDXWWIul5WR2WQANiBZNARpvKFv9w0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZBP+po5F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZBP+po5F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F402C4CEF1; Wed, 11 Jun 2025 10:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636219; bh=VGXfIDzE2QNN2PICBkzKgVdMlq8Xdmxeh79OvSTS4Hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBP+po5FrOngYY8KfC+BWJK4n+Nwghk3WZvyldHV2CMjWPhvaV8a+GcWhhaoa6eO9 PXSGR8LEVubAh/KVTNQ0Q3lco5MZ/Nzytvjq7xmPxlFVUi/S+hlN9b5a7PB04h8jz3 21nHFahYX/Z+V3ByqFUf2Rte5dbm00a2t43TPZnwqVpZQpZXz9wZWMlKjvQOU+zd+R PfwAWk8bPpGdQu+5DUsbaslsP1wn1DO4IbxPEIye4hWod3ulC8wHdGRiE4urhwUrrX wM5RKhc4nfBHGnQ6X9HPgPHWbLpNFi6yEsteO3cdfbCYXLe2m3gCJjojzvLkqh0L9y 6mlfI7zvX6x5A== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Nicolas Pitre Subject: [PATCH 07/33] tty: vt: use _IO() to define ioctl numbers Date: Wed, 11 Jun 2025 12:02:53 +0200 Message-ID: <20250611100319.186924-8-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" _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) Cc: Nicolas Pitre Reviewed-by: Ilpo J=C3=A4rvinen Reviewed-by: Nicolas Pitre --- 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) */ =20 -/* 0x56 is 'V', to avoid collision with termios and kd */ +/* 'V' to avoid collision with termios and kd */ =20 -#define VT_OPENQRY 0x5600 /* find available vt */ +#define VT_OPENQRY _IO('V', 0x00) /* find available vt */ =20 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 */ =20 -#define VT_RELDISP 0x5605 /* release display */ +#define VT_RELDISP _IO('V', 0x05) /* release display */ =20 -#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 */ =20 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 */ =20 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 + m= ore */ +#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 */ =20 struct vt_event { __u32 event; @@ -77,14 +77,14 @@ struct vt_event { __u32 pad[4]; /* Padding for expansion */ }; =20 -#define VT_WAITEVENT 0x560E /* Wait for an event */ +#define VT_WAITEVENT _IO('V', 0x0E) /* Wait for an event */ =20 struct vt_setactivate { __u32 console; struct vt_mode mode; }; =20 -#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 c= onsole */ =20 /* get console size and cursor position */ struct vt_consizecsrpos { --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3BE026988E; Wed, 11 Jun 2025 10:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636223; cv=none; b=o3BGm0oejt4nl7Uc8beVrDfm654dIXLilStTAhF7BOrYz7vmVglYldLxgi9fyWJj4NomAenCa2+9j8bFU0l02o12vIsf1j9iU7btKkxyzLIG5/I0BXyx/NVb8fXKoJzgJCw/djK1sUYVN7nVAcvDnSJeDR7VT5b0smuzB46zIj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636223; c=relaxed/simple; bh=WnNh6Rm9Jg/5QW7kY8rxY/asPnz6gmr/Wc6rb4KEVVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BC5X46EWZoaQQnHFjo30tAkn6ph+ogkKNTkiiTVsqf0b8i0oQuX9rPOmHQJIzc7VOVwhaTPEU/mkGZ3TtMf4eccPBZh/xcy/Q4oCDVM2yQ+V4toO7keoyZTjJIQ8jb5TFczfOVhthsCD7CkuIuuZFgwN7FCuCv4t4lrFy5Xy8z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gSHzIZMV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gSHzIZMV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCB90C4CEF2; Wed, 11 Jun 2025 10:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636223; bh=WnNh6Rm9Jg/5QW7kY8rxY/asPnz6gmr/Wc6rb4KEVVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gSHzIZMVLV69bRYINCRFNUMLUTYDU0vxl6UqXKftZ/QTsTnzxo/aO5jQhccphsJOg Cv0pVQAf4rsYJq/ATeNFZ6C3MDdu+0RtwXwHFr9o2gFMg3EYEVLvgjZ7aLYINPVmXi JwYCSpcY4yEwRLB6HMif7MihNAipdZiaUfLsduDnMzeurlLmXvNAJGxu5W3u46Htni sdBolxL+Z7eDSPM6ijoUZmqYPKbrXwMiy2vvnC5yvZQ3XO2hfyjgTnuXvyOX1beo61 0TdqK5YHneN6JW2SQF8z+Bdt3v3Y8DfxPQTcNBSsvHzO1oVtTVJnpL1mjhz/4zwsfu SavGm0vQjveew== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , Paul Cercueil , Vladimir Zapolskiy , Kunihiko Hayashi , Masami Hiramatsu , linuxppc-dev@lists.ozlabs.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 08/33] serial: 8250: sanitize uart_port::serial_{in,out}() types Date: Wed, 11 Jun 2025 12:02:54 +0200 Message-ID: <20250611100319.186924-9-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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) Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: "Ilpo J=C3=A4rvinen" Cc: Andy Shevchenko Cc: Paul Cercueil Cc: Vladimir Zapolskiy Cc: Kunihiko Hayashi Cc: Masami Hiramatsu Reviewed-by: Andy Shevchenko --- 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/lega= cy_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 =3D -1; static const upf_t legacy_port_flags =3D UPF_BOOT_AUTOCONF | UPF_SKIP_TEST= | UPF_SHARE_IRQ | UPF_FIXED_PORT; =20 -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 =3D offset << p->regshift; if (offset =3D=3D UART_IIR) { tmp =3D readl(p->membase + (UART_IIR & ~3)); @@ -65,7 +66,7 @@ static unsigned int tsi_serial_in(struct uart_port *p, in= t offset) return readb(p->membase + offset); } =20 -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 v= alue) { offset =3D offset << p->regshift; if (!((offset =3D=3D UART_IER) && (value & UART_IER_UUE))) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/82= 50_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; =20 - 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(str= uct work_struct *work) return container_of(work, struct dw8250_data, clk_work); } =20 -static inline int dw8250_modify_msr(struct uart_port *p, int offset, int v= alue) +static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offs= et, u32 value) { struct dw8250_data *d =3D to_dw8250_data(p->private_data); =20 @@ -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 =3D to_dw8250_data(p->private_data); void __iomem *addr =3D p->membase + (offset << p->regshift); @@ -156,7 +156,7 @@ static void dw8250_check_lcr(struct uart_port *p, int o= ffset, int value) =20 /* Make sure LCR write wasn't ignored */ while (tries--) { - unsigned int lcr =3D serial_port_in(p, offset); + u32 lcr =3D serial_port_in(p, offset); =20 if ((value & ~UART_LCR_SPAR) =3D=3D (lcr & ~UART_LCR_SPAR)) return; @@ -205,13 +205,13 @@ static void dw8250_tx_wait_empty(struct uart_port *p) } } =20 -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, u3= 2 value) { writeb(value, p->membase + (offset << p->regshift)); dw8250_check_lcr(p, offset, value); } =20 -static void dw8250_serial_out38x(struct uart_port *p, int offset, int valu= e) +static void dw8250_serial_out38x(struct uart_port *p, unsigned int offset,= u32 value) { /* Allow the TX to drain before we reconfigure */ if (offset =3D=3D 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); } =20 -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 =3D readb(p->membase + (offset << p->regshift)); + u32 value =3D readb(p->membase + (offset << p->regshift)); =20 return dw8250_modify_msr(p, offset, value); } =20 #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 =3D __raw_readq(p->membase + (offset << p->regshift)); =20 return dw8250_modify_msr(p, offset, value); } =20 -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, u= 32 value) { value &=3D 0xff; __raw_writeq(value, p->membase + (offset << p->regshift)); @@ -246,28 +246,28 @@ static void dw8250_serial_outq(struct uart_port *p, i= nt offset, int value) } #endif /* CONFIG_64BIT */ =20 -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); } =20 -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 =3D readl(p->membase + (offset << p->regshift)); + u32 value =3D readl(p->membase + (offset << p->regshift)); =20 return dw8250_modify_msr(p, offset, value); } =20 -static void dw8250_serial_out32be(struct uart_port *p, int offset, int val= ue) +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); } =20 -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 =3D ioread32be(p->membase + (offset << p->regshi= ft)); + u32 value =3D ioread32be(p->membase + (offset << p->regshift)); =20 return dw8250_modify_msr(p, offset, value); } diff --git a/drivers/tty/serial/8250/8250_em.c b/drivers/tty/serial/8250/82= 50_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_p= ort *p, int offset, } } =20 -static unsigned int serial8250_em_serial_in(struct uart_port *p, int offse= t) +static u32 serial8250_em_serial_in(struct uart_port *p, unsigned int offse= t) { 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); } =20 -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 off= set, u32 value) { switch (offset) { case UART_TX: diff --git a/drivers/tty/serial/8250/8250_ingenic.c b/drivers/tty/serial/82= 50/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); =20 -static void ingenic_uart_serial_out(struct uart_port *p, int offset, int v= alue) +static void ingenic_uart_serial_out(struct uart_port *p, unsigned int offs= et, u32 value) { - int ier; + u32 ier; =20 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)); } =20 -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; =20 value =3D readb(p->membase + (offset << p->regshift)); =20 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; }; =20 -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)); } =20 -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/82= 50/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, s= truct ktermios *termios return 0; } =20 -static void lpc18xx_uart_serial_out(struct uart_port *p, int offset, int v= alue) +static void lpc18xx_uart_serial_out(struct uart_port *p, unsigned int offs= et, 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/8= 250_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; } =20 -static void f815xxa_mem_serial_out(struct uart_port *p, int offset, int va= lue) +static void f815xxa_mem_serial_out(struct uart_port *p, unsigned int offse= t, u32 value) { struct f815xxa_data *data =3D 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); } =20 -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 =3D up_to_u8250p(p); - unsigned int val; + u32 val; =20 /* * 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) } =20 #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 =3D offset << p->regshift; outb(p->hub6 - 1 + offset, p->iobase); return inb(p->iobase + 1); } =20 -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 =3D 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 */ =20 -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 =3D offset << p->regshift; return readb(p->membase + offset); } =20 -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 v= alue) { offset =3D offset << p->regshift; writeb(value, p->membase + offset); } =20 -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 =3D offset << p->regshift; writew(value, p->membase + offset); } =20 -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 =3D offset << p->regshift; return readw(p->membase + offset); } =20 -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 =3D offset << p->regshift; writel(value, p->membase + offset); } =20 -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 =3D offset << p->regshift; return readl(p->membase + offset); } =20 -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, u= 32 value) { offset =3D offset << p->regshift; iowrite32be(value, p->membase + offset); } =20 -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 =3D offset << p->regshift; return ioread32be(p->membase + offset); } =20 #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 =3D offset << p->regshift; return inb(p->iobase + offset); } =20 -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 va= lue) { offset =3D 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; } =20 -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 va= lue) { } =20 diff --git a/drivers/tty/serial/8250/8250_rt288x.c b/drivers/tty/serial/825= 0/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] =3D { [UART_MCR] =3D 6, }; =20 -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 >=3D 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)); } =20 -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 va= lue) { if (offset >=3D ARRAY_SIZE(au_io_out_map)) return; diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8= 250/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 =3D 0; =20 @@ -92,7 +92,7 @@ static unsigned int uniphier_serial_in(struct uart_port *= p, int offset) return (readl(p->membase + offset) >> valshift) & 0xff; } =20 -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 =3D 0; bool normal =3D 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); --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 355242638A2; Wed, 11 Jun 2025 10:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636225; cv=none; b=PFGv6nmcrE6HXdr4EsO/yX/N9TqBoE3oG0AexSobY//lVXYtdP0GoM4+8c6GAi63sPfjOEnrylj9OGUovKG7mQ3fGROBopTVoDqO+KVySi8p3++8mUtn1SDfopff9kvPIJbWAYhN30xEAXJvGYj+s8SssNzzoQ5aUGfo3+kj41s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636225; c=relaxed/simple; bh=0bsacJEh4/kwfEk4/swnlI17ttTGNYzZGHJ2+pD578k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uZ7MfNxzqg4yNRVv0YcE4CJpCSXE2RQTW633zZ0oDQf4Nj6l6AK6mB/+4NOXXc9HbswzBT0OBUSeEd2dkBuXV4KaezzMNFEBl8qtmGXk5U5Se330SBlYFuE1kSIxDj72DrA8dWbx0i+hWeDjame5LN+8luxNz+PjKXpn5sTpeOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PPCLUFhd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PPCLUFhd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB84BC4CEF5; Wed, 11 Jun 2025 10:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636224; bh=0bsacJEh4/kwfEk4/swnlI17ttTGNYzZGHJ2+pD578k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPCLUFhdE/Ddd87gvpZi9E+fuqdXWd/5NvItu5GZA0En0YsJXj3biGJRHzJ0PUteV /zDo/lsvTTWws3djFcPt9m9370l292Fd2qbT2ICHxw+pl/hr9DkU9CdK5eLvZv6JOV wHTfP4QExkAJ33QBV6bskN9q7kGwB4D7mFzExmJqChKCNtmcvBpI9+bXxHiz9cL/O2 4sIRavH1l6P9ZStfAx7xz0WiIOHSZZFls20Uu76ZDpendrMWzBm0QkG/QhQLmEiDGA 7iEYpo5cr0kfclfdwINdCnEdlIT8nHr8U+kTW0ZaRqHsGzbI/7IyKadvO8DXvN9CWM W6F1YrX6ybxhg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 09/33] serial: 8250: remove CONFIG_SERIAL_8250_RSA inline macros from code Date: Wed, 11 Jun 2025 12:02:55 +0200 Message-ID: <20250611100319.186924-10-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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; } =20 +/* + * If this is an RSA port, see if we can kick it up to the higher speed cl= ock. + */ static void enable_rsa(struct uart_8250_port *up) { if (up->port.type =3D=3D PORT_RSA) { @@ -752,10 +755,9 @@ static void enable_rsa(struct uart_8250_port *up) } =20 /* - * 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 115k= bps compat mode. It is + * unknown why interrupts were disabled in here. However, the caller is ex= pected 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 =3D=3D PORT_16550A && up->probe & UART_PROBE_RSA && + __enable_rsa(up)) + up->port.type =3D PORT_RSA; +} + +static void rsa_reset(struct uart_8250_port *up) +{ + if (up->port.type =3D=3D 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 */ =20 /* @@ -1267,14 +1288,7 @@ static void autoconfig(struct uart_8250_port *up) break; } =20 -#ifdef CONFIG_SERIAL_8250_RSA - /* - * Only probe for RSA ports if we got the region. - */ - if (port->type =3D=3D PORT_16550A && up->probe & UART_PROBE_RSA && - __enable_rsa(up)) - port->type =3D PORT_RSA; -#endif + rsa_autoconfig(up); =20 serial_out(up, UART_LCR, save_lcr); =20 @@ -1289,10 +1303,7 @@ static void autoconfig(struct uart_8250_port *up) /* * Reset the UART. */ -#ifdef CONFIG_SERIAL_8250_RSA - if (port->type =3D=3D 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); } =20 -#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 =20 /* * 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); =20 -#ifdef CONFIG_SERIAL_8250_RSA - /* - * Reset the RSA board back to 115kbps compat mode. - */ disable_rsa(up); -#endif =20 /* * Read data port to reset things, and then unlink from --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE99826A1DD; Wed, 11 Jun 2025 10:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636226; cv=none; b=ZholNl16PK3wzmZjjpZPl93ygEhU9vMiHexK6gfvaSSub5pkx5A4HbE7ZcI5vyDCrov1OCA1L6dwm69Fsf/QhrKL/UACZQtaz3ZUO5pG2dn3+N/3wFcejDcEH4Bwzk8Hawd0Exx1PATrcscgpF1Mm8GBpF1Z7GTsuXs+qLFF8uU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636226; c=relaxed/simple; bh=zADBZh3/I+6iFXqflCXcndvocrGLcKPL2i3MplPDgAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xe7t1rA2/HrIfeyDtiacbW1vU9OomAzWQO7IiXaB0yTvi5l3SlSVmo2C9PhzEST3icCCE6xoZibrrhoV9MmfO70lGiRlV3aXAl4idM15LuBQRw5z+8gp8WQAwg85P3LeYy5W/P3NyTl7fMDmSvAw5E3kusDHVMI3sBv2acGlEgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hr7dYY7X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hr7dYY7X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37EB0C4CEF1; Wed, 11 Jun 2025 10:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636226; bh=zADBZh3/I+6iFXqflCXcndvocrGLcKPL2i3MplPDgAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hr7dYY7XREUs/MaaLoarDIL48Blok43CyLjPM6/8jdwGrV29QOCSt+n4h8em2tmbI dSz6h8XpWGA5H9bZS/XdpdjeDJbHktO8jFi8UY20txhpZo8T39Sx5/AWaaF7+1kx1t pP8vtg8hi+d+p1GQ/qgUmm5J2B21H6dHbB0O7MNu+f1TYWHeKkKEBsMDD96tpiCo7O d+B60IXh+moyYQ0mCHBCu+keyreTput1FZzObn/29vdSGNYoNkF5Ucm3WUYXnWYXci uoA3WM0jblfKIg239E28LrvWQIwu3iJKFDtm0T8q4mxTd4fycsAQ/TfQ5nCLDO3efI WhmGVS3Kdjxqw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 10/33] serial: 8250: invert conditions in RSA functions Date: Wed, 11 Jun 2025 12:02:56 +0200 Message-ID: <20250611100319.186924-11-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 =3D=3D PORT_RSA) { - if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { - uart_port_lock_irq(&up->port); - __enable_rsa(up); - uart_port_unlock_irq(&up->port); - } - if (up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) - serial_out(up, UART_RSA_FRR, 0); + if (up->port.type !=3D PORT_RSA) + return; + + if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { + uart_port_lock_irq(&up->port); + __enable_rsa(up); + uart_port_unlock_irq(&up->port); } + if (up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) + serial_out(up, UART_RSA_FRR, 0); } =20 /* @@ -764,37 +765,45 @@ static void disable_rsa(struct uart_8250_port *up) unsigned char mode; int result; =20 - if (up->port.type =3D=3D PORT_RSA && - up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) { - uart_port_lock_irq(&up->port); + if (up->port.type !=3D PORT_RSA) + return; =20 - mode =3D serial_in(up, UART_RSA_MSR); - result =3D !(mode & UART_RSA_MSR_FIFO); + if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) + return; =20 - if (!result) { - serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); - mode =3D serial_in(up, UART_RSA_MSR); - result =3D !(mode & UART_RSA_MSR_FIFO); - } + uart_port_lock_irq(&up->port); + mode =3D serial_in(up, UART_RSA_MSR); + result =3D !(mode & UART_RSA_MSR_FIFO); =20 - if (result) - up->port.uartclk =3D 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 =3D serial_in(up, UART_RSA_MSR); + result =3D !(mode & UART_RSA_MSR_FIFO); } + + if (result) + up->port.uartclk =3D SERIAL_RSA_BAUD_BASE_LO * 16; + uart_port_unlock_irq(&up->port); } =20 static void rsa_autoconfig(struct uart_8250_port *up) { /* Only probe for RSA ports if we got the region. */ - if (up->port.type =3D=3D PORT_16550A && up->probe & UART_PROBE_RSA && - __enable_rsa(up)) + if (up->port.type !=3D PORT_16550A) + return; + if (!(up->probe & UART_PROBE_RSA)) + return; + + if (__enable_rsa(up)) up->port.type =3D PORT_RSA; } =20 static void rsa_reset(struct uart_8250_port *up) { - if (up->port.type =3D=3D PORT_RSA) - serial_out(up, UART_RSA_FRR, 0); + if (up->port.type !=3D PORT_RSA) + return; + + serial_out(up, UART_RSA_FRR, 0); } #else static inline void enable_rsa(struct uart_8250_port *up) {} --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4728E26B0B6; Wed, 11 Jun 2025 10:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636228; cv=none; b=tr2AkjVq97SplxdxufI136CaNXbNHNDcYYSoEyaMw3h7C+TswoIofQ3NMJG9Jy/eamD8anLRjep4Sa2cozfeDAI6IlOXVnPMG9TrEZ0tCpZW3S+OQ1W0wGGB4Ik1yVJ70LfkuUlreoEEn27BEiksSxpO99/0+3jnfl4PjPmSfms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636228; c=relaxed/simple; bh=aqVbkfTUA8V0nJKIHfTwYOHOebwoKHiR0JhSOS93pEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEsEVRqjo1JU/ohoRdTkG5YGaGU0ooe984SxSoa9VCwKFYwRNuhZrrnoaKE/1H1OE+hFqPzoyuqmuzgPzlSn1iev/5YUvRFuaIoHqCb2YOtKGy8xKNRTHtDkQO4xD13SzGumOU/9q36YpHBPBE10f0iYSrybfgrSH9Mzy76ASeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RnsbPBGB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RnsbPBGB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8C19C4CEF2; Wed, 11 Jun 2025 10:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636227; bh=aqVbkfTUA8V0nJKIHfTwYOHOebwoKHiR0JhSOS93pEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RnsbPBGBj7fVaW1UbWAmfdSlz5Pr134lZUnuDQyOIebvYMpelbuPfwD7RViLD/rlp 3SHhEF/8Lf++vh2FNDBl9fTypxkw2eeA3otWdodQfdpXsTm02CI9RT2S0/jzwa7iUe r5g5XRMbY7i4ANAOhN9nUXCoucihI9s/PVMyoZt+vy0l/AksaHBmTHWWWB+xfYROd3 lm0Cd1kG88PGnvakZE4HNaZ7orZg0DyonQb14C3uHJUynd9wqAfVmLs35rqrec6WiB vSQZkNnpwb87t6ToPR9UqXq1mNsc4+QCvotDBfWWRaXLdHdAv4SFtsvZNfYM2BixvJ GodV9n0sie+ww== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 11/33] serial: 8250: put RSA functions to their namespace Date: Wed, 11 Jun 2025 12:02:57 +0200 Message-ID: <20250611100319.186924-12-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 cl= ock. */ -static void enable_rsa(struct uart_8250_port *up) +static void rsa_enable(struct uart_8250_port *up) { if (up->port.type !=3D PORT_RSA) return; =20 if (up->port.uartclk !=3D 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 =3D=3D 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 ex= pected 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; =20 - if (__enable_rsa(up)) + if (__rsa_enable(up)) up->port.type =3D PORT_RSA; } =20 @@ -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); } =20 - enable_rsa(up); + rsa_enable(up); =20 /* * 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); =20 - disable_rsa(up); + rsa_disable(up); =20 /* * Read data port to reset things, and then unlink from --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE7B026B96A; Wed, 11 Jun 2025 10:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636230; cv=none; b=MWVYb2SQByi9juPOwc+IseWrQImh/YUu899EBjkAPUYw48oEsXrfXj0ulRSqLOiBYeasZpP413uGtJ1JclyQXJvXU16X5gReiFBZr7ZTPMGj4hcQ40zOmccyACeDljfb4JmH0jwuyhD3xoh2tgYqsJTlga9b7v828z8NF0V9rmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636230; c=relaxed/simple; bh=08ufG9vWt1WGuJKkmahEWPaJTsUJqrGw7oYBQIVD+5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VMxB7C9TLMsaR5dojfk671B5SvNO8MZhm4BcpghLhvARbpgU4030kdbJxCs3GIV7pNu68NRtFmWyO0mALnL/mbK9TNvE/kulnF4Q0X5lZa52tXnkMSBB+r5zFmFBZ/uR5t+5gdVwzgwXnjYLDdz/3w1whJntlLAyLNT2Ux3vleA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ys6DIfQY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ys6DIfQY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4482AC4CEF1; Wed, 11 Jun 2025 10:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636229; bh=08ufG9vWt1WGuJKkmahEWPaJTsUJqrGw7oYBQIVD+5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ys6DIfQYTbzDgcRQZ5ZJDXevPDh4kRT8rZEN9AuR9DDfyCuP3/3gHvLp9lap5e9tX AHAcT+67ljasNt6WG/3BQwb9S21T1g9OIi8u9Ro7saVdvCHbXwYPJObp0QJtLWzPi2 0d/cDHV88290UVEelgqBP5lsQgf1F6MtDX9rsJhZ5Remt5LuUCCXmx9LoNNTbLNX3P jqFjPv8BBBVEB9uKZ+ldo0jpEiHHNcjvlffiqFUzbOAl3azVOYsoONZfmoM1EW614z cJgDNDZBgEfsyYTwVSlTvxopvYub44/QufS9YQnMNLiQuVt8eyaG+R2eKuAhcfmEG8 7xKDfWoRTcVZw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 12/33] serial: 8250: move RSA functions to 8250_rsa.c Date: Wed, 11 Jun 2025 12:02:58 +0200 Message-ID: <20250611100319.186924-13-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" They are RSA-specific, so should live in a preexisting 8250_rsa.c. Move them there. Signed-off-by: Jiri Slaby (SUSE) Reviewed-by: Ilpo J=C3=A4rvinen --- 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) { } =20 #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 =20 #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_por= t *up) serial_out(up, UART_IER, 0); } =20 -#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 =3D serial_in(up, UART_RSA_MSR); - result =3D mode & UART_RSA_MSR_FIFO; - - if (!result) { - serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); - mode =3D serial_in(up, UART_RSA_MSR); - result =3D mode & UART_RSA_MSR_FIFO; - } - - if (result) - up->port.uartclk =3D SERIAL_RSA_BAUD_BASE * 16; - - return result; -} - -/* - * If this is an RSA port, see if we can kick it up to the higher speed cl= ock. - */ -static void rsa_enable(struct uart_8250_port *up) -{ - if (up->port.type !=3D PORT_RSA) - return; - - if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { - uart_port_lock_irq(&up->port); - __rsa_enable(up); - uart_port_unlock_irq(&up->port); - } - if (up->port.uartclk =3D=3D 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 115k= bps compat mode. It is - * unknown why interrupts were disabled in here. However, the caller is ex= pected 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 !=3D PORT_RSA) - return; - - if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) - return; - - uart_port_lock_irq(&up->port); - mode =3D serial_in(up, UART_RSA_MSR); - result =3D !(mode & UART_RSA_MSR_FIFO); - - if (!result) { - serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); - mode =3D serial_in(up, UART_RSA_MSR); - result =3D !(mode & UART_RSA_MSR_FIFO); - } - - if (result) - up->port.uartclk =3D 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 !=3D PORT_16550A) - return; - if (!(up->probe & UART_PROBE_RSA)) - return; - - if (__rsa_enable(up)) - up->port.type =3D PORT_RSA; -} - -static void rsa_reset(struct uart_8250_port *up) -{ - if (up->port.type !=3D 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/8= 250_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"); =20 +/* + * 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 =3D serial_in(up, UART_RSA_MSR); + result =3D mode & UART_RSA_MSR_FIFO; + + if (!result) { + serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); + mode =3D serial_in(up, UART_RSA_MSR); + result =3D mode & UART_RSA_MSR_FIFO; + } + + if (result) + up->port.uartclk =3D SERIAL_RSA_BAUD_BASE * 16; + + return result; +} + +/* + * If this is an RSA port, see if we can kick it up to the higher speed cl= ock. + */ +void rsa_enable(struct uart_8250_port *up) +{ + if (up->port.type !=3D PORT_RSA) + return; + + if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { + uart_port_lock_irq(&up->port); + __rsa_enable(up); + uart_port_unlock_irq(&up->port); + } + if (up->port.uartclk =3D=3D 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 115k= bps compat mode. It is + * unknown why interrupts were disabled in here. However, the caller is ex= pected 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 !=3D PORT_RSA) + return; + + if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) + return; + + uart_port_lock_irq(&up->port); + mode =3D serial_in(up, UART_RSA_MSR); + result =3D !(mode & UART_RSA_MSR_FIFO); + + if (!result) { + serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); + mode =3D serial_in(up, UART_RSA_MSR); + result =3D !(mode & UART_RSA_MSR_FIFO); + } + + if (result) + up->port.uartclk =3D 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 !=3D PORT_16550A) + return; + if (!(up->probe & UART_PROBE_RSA)) + return; + + if (__rsa_enable(up)) + up->port.type =3D PORT_RSA; +} + +void rsa_reset(struct uart_8250_port *up) +{ + if (up->port.type !=3D PORT_RSA) + return; + + serial_out(up, UART_RSA_FRR, 0); +} + #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS #ifndef MODULE /* --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 581D026C393; Wed, 11 Jun 2025 10:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636231; cv=none; b=CRtZypHlgYXwalV7WjUoFXVvKzQgi1bMhGGZ7x1/fTVpUUubTv09MeannEZsb+4DLmIEOGUCuGcEC8R5pgTQ4d6sGzxeg5y+bsDrK7go3KiRTNo99QsuQbolR+cEM/ewDb0mTLVQM0hl9QmVPcC3Xwj4GMxp9FaQ7v3OVskucZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636231; c=relaxed/simple; bh=y5IGopF9dCwKo6ZEh6UR60f6BBfB6HOuprnQtQedge0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PaJBGmzRMTwyIFfQgjX4y+MH4pcXRjSmP/vHn9WasHb/NCdflx9Nv6CGJXi6cUcv4BeY5YGCy2tnbM2WuavI8RZJvTD1h8dg6ZXJ8Q2Ewqid1XCZ4KJWJgUoEMcQKREVmRIiptc2htJa3V7Fwes5jAHKDPrzXPD3nc6ft3sQrs8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cm9WQMtw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cm9WQMtw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3E67C4CEF2; Wed, 11 Jun 2025 10:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636230; bh=y5IGopF9dCwKo6ZEh6UR60f6BBfB6HOuprnQtQedge0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cm9WQMtwBXImNIFVydHSxEhhHAvoXXJkbl+rVbf6bu9I7gSpXhuI6suNKCzdDDURn MWYVa+sr+shw/ZKXPm69rPzZ4eJXV7VrYjyGZQSA+L0spqHkoN6JJRSq8LBtNxkXrQ gvywt/OcFhN/MEDIaUBYInuNZGXRNxCYa+19yv503URlc9C/6xPGTDl8CNG+k0Dyld d9sJuTbb7vwm9TW9sR4vRU0RXKPWT9ATNOc98QV5QrA+friMyVGeulD4Y1regsOx4Z KjTUc3iwxSChEiAzdNguW6qDCQUgIhAbpNwsRDcK+TdfGpUZzMNw0KHAxQ854pOUPx jxiAbq/kWHojA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 13/33] serial: 8250: extract serial8250_startup_special() Date: Wed, 11 Jun 2025 12:02:59 +0200 Message-ID: <20250611100319.186924-14-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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_po= rt *port, =20 #endif /* CONFIG_CONSOLE_POLL */ =20 -int serial8250_do_startup(struct uart_port *port) +static void serial8250_startup_special(struct uart_port *port) { struct uart_8250_port *up =3D up_to_u8250p(port); unsigned long flags; - unsigned char iir; - int retval; - u16 lsr; - - if (!port->fifosize) - port->fifosize =3D uart_config[port->type].fifo_size; - if (!up->tx_loadsz) - up->tx_loadsz =3D uart_config[port->type].tx_loadsz; - if (!up->capabilities) - up->capabilities =3D uart_config[port->type].flags; - up->mcr =3D 0; - - if (port->iotype !=3D up->cur_iotype) - set_io_from_upio(port); =20 - serial8250_rpm_get(up); - if (port->type =3D=3D 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 =3D=3D 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 =3D up_to_u8250p(port); + unsigned long flags; + unsigned char iir; + int retval; + u16 lsr; + + if (!port->fifosize) + port->fifosize =3D uart_config[port->type].fifo_size; + if (!up->tx_loadsz) + up->tx_loadsz =3D uart_config[port->type].tx_loadsz; + if (!up->capabilities) + up->capabilities =3D uart_config[port->type].flags; + up->mcr =3D 0; + + if (port->iotype !=3D up->cur_iotype) + set_io_from_upio(port); + + serial8250_rpm_get(up); =20 - rsa_enable(up); + serial8250_startup_special(port); =20 /* * Clear the FIFO buffers and disable them. --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E21F26C3AD; Wed, 11 Jun 2025 10:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636232; cv=none; b=KU/q4cdgB/5c8f4A+qD9iwpaW3Uohk7RPaDvCVZ31O+Ms8utCjOPQlgIiWBWMoiHWOInR4O3NAIhKGofxAD5Mynd0kQDNYdEMjmRPTRQhh2gAcxJcX3h2dRtdiDYYTmerjX/NeyarPKqLNcGnF1ubfsxf6KCeCmF6IDC+NO/J/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636232; c=relaxed/simple; bh=tbi25yz4ZSThWLio+Que2+49CMR0gxF2qcWOskJMf08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LOErYE1siMZuoOuPb5i3naWGKwfamyVX/slpn8XkIUbfkuJzTXkzgnVcMcpJpxW3P7LIDJXbbpRdyV0ArkLSiA6sFE343ErHvTZX1ETv4RY6OWOA0/lIDtEgKz7xprMWvhRUt7ysZasoIcZq6ZOfYww0YDg4oTR6RHcnljbr6xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cayj+Goq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cayj+Goq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FCC2C4CEEE; Wed, 11 Jun 2025 10:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636232; bh=tbi25yz4ZSThWLio+Que2+49CMR0gxF2qcWOskJMf08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cayj+GoqLyG91E6KovFtTZ5NmY3xZTn1Q//Yt+SoBQUtdb1uu8dbFqeczjzyAGe5M UtQdJ4IeTXoa0KyLfFoYTrC55idNKpiYJy8XHOTLurpsUh5PoTM/yj0GvEpHvxyaWZ PnIDkiP5UODret+UhZLPgz28hu2W0Saehiduk6/FL8fxl5FjE4ds7XGaI1a1A8eCqv WX6qVpqZVA/7yYmPdRzqhrnV2diiV92jv//xQ0h0zUeEEwHrDEeY4ZwhjnIbAm2PBo OybVK2MNULq844r1U4QQ5kzYiWNwZVaxzMTxdySYXSxBqXK/LF3loEdmv1W1Nw9ACf ZuZRjaMl3/BUg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 14/33] serial: 8250: extract serial8250_set_TRG_levels() Date: Wed, 11 Jun 2025 12:03:00 +0200 Message-ID: <20250611100319.186924-15-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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_p= ort *port) } } =20 +static void serial8250_set_TRG_levels(struct uart_port *port) +{ + struct uart_8250_port *up =3D 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 =3D serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); + fctr |=3D 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 <=3D 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 =3D serial8250_tx_threshold_handle_irq; + break; + } +} + int serial8250_do_startup(struct uart_port *port) { struct uart_8250_port *up =3D up_to_u8250p(port); @@ -2208,42 +2248,7 @@ int serial8250_do_startup(struct uart_port *port) goto out; } =20 - /* - * For a XR16C850, we need to set the trigger levels - */ - if (port->type =3D=3D PORT_16850) { - unsigned char fctr; - - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); - - fctr =3D 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 =3D=3D PORT_ALTR_16550_F32) || - (port->type =3D=3D PORT_ALTR_16550_F64) || - (port->type =3D=3D 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 =3D serial8250_tx_threshold_handle_irq; - } - } + serial8250_set_TRG_levels(port); =20 /* Check if we need to have shared IRQs */ if (port->irq && (up->port.flags & UPF_SHARE_IRQ)) --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F0026D4E2; Wed, 11 Jun 2025 10:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636234; cv=none; b=Ans+1wFny1/9I9mj5yMmtawvrZ29FpIMp8NY7yDDej3paXq2yIUj2q03HFjEQmXK4M3cXYEAnDQOpWwAuMv91Hs6TloQwZxwcu9+HCi3dkmMB5HtHJ/HgPDNrKeZ497Il92lx/Gh5N2yT/4FPdsNdSyFIQQMPbfC5rhzSYxHYtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636234; c=relaxed/simple; bh=ux5Y5OYcWn8VeMYcmbr4S7y2Gif49OHeQpMD/bE4dJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hbLJOxK7ewpZZLHNEQsA1uBlEbK6r0BATUU+I60+uDeWD9sPL7xLXE42fLx/AKpLbx01FMBUnMWhtD4PEcG5zajNoJnrMpX7rYBFiQpXsN7E87hQ5wpkDJmviBK+iUtVzLYp4yAjyXwbjg7iY9DoQCC8UtB2JiSmEW7B3czL+eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SJtYnya9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SJtYnya9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF4EBC4CEEE; Wed, 11 Jun 2025 10:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636233; bh=ux5Y5OYcWn8VeMYcmbr4S7y2Gif49OHeQpMD/bE4dJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJtYnya9JY7rCLaNJ1+A7uI31O7UYoUKU9RIoW+PeR2o1FWlZUu6tEH3iHYGBltmo eJsFKUtuAuSRiHFJnkXkz098si0MA+wae1picc+wa9BAl5cPxh3ucl6bDOUh2PADYL IxNdqbbX+TcFgIRa38X/uCSoZCuJ3wrC5fTUXpKZSxUG8ywmTaMoefZJtIvh0dGoZl 7fOp/Ed3esloo8H3lz2wY1WMbd3dpnNB23nvqSqbIN3DAT4PqmmYcFEeasN1DF+HcR 4BcS8rYmDc9oWbPd8T0VmcMepGcSnXsUeZeamrNkWXFuezApl8ovePgOpmZkP7aGn5 qvlAAaI4QOfjA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 15/33] serial: 8250: extract serial8250_THRE_test() Date: Wed, 11 Jun 2025 12:03:01 +0200 Message-ID: <20250611100319.186924-16-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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_po= rt *port) } } =20 +static void serial8250_THRE_test(struct uart_port *port) +{ + struct uart_8250_port *up =3D 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 int= errupt whenever the + * transmitter is idle and the interrupt is enabled. Delays are necessar= y 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 =3D 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 =3D 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 ii= r, setup a timer to + * kick the UART on a regular basis. + */ + if ((!iir_noint1 && iir_noint2) || up->port.flags & UPF_BUG_THRE) + up->bugs |=3D UART_BUG_THRE; +} + int serial8250_do_startup(struct uart_port *port) { struct uart_8250_port *up =3D up_to_u8250p(port); @@ -2258,49 +2306,7 @@ int serial8250_do_startup(struct uart_port *port) if (retval) goto out; =20 - 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 =3D 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 =3D 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 |=3D UART_BUG_THRE; - } - } + serial8250_THRE_test(port); =20 up->ops->setup_timer(up); =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87B0126D4CF; Wed, 11 Jun 2025 10:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636235; cv=none; b=CawwFcmxHGUbM2NnDibwTlf39Beu6CLYBQvEiIgvqDWfjaxkRQ8Ao3WCp3HySa0qcJKONxIBp4ufl4oo78KG2AaXVdnfUASU+zpknsJK3+B5979jIpopeIYxAduhbt+SmKJ+Ee9iWOqEiy0RQVDiXu8Q+rd6Bg6i7gNhl+CTVIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636235; c=relaxed/simple; bh=CJJIgIthaFgjPVGuHvtpvz2/RwmOxERQHI/tN+4R/YE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tFOughUG1twH8Tr4+b0r+mtpEgkQklzfLfNdghbnXUtXwTcYQ85DDVL58SGjasSzQHIB4mNVxBu2nv/+3ncLLcZ/c4bmZGCh8PaP/7H83xBU2N77WkEcCTOphCeEi3bw59pT5G+rwh7KHJkg4URQT9DnoOq4HbjQs1HoOl9Jjnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ka3gV/tS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ka3gV/tS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B158C4CEEE; Wed, 11 Jun 2025 10:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636235; bh=CJJIgIthaFgjPVGuHvtpvz2/RwmOxERQHI/tN+4R/YE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ka3gV/tSNLFwlUT+oes4SIHL4tKWfUya78ek45/ZyoC4xB5DB+f0EPF0nGTbtaDgU 6+QCHcsgDqfGaDxGQFaLAef9HQjBpU7okrwPEP3WRSOFLxKiq0sgv4oKRuysn6Bcyz IAH8vtPf7bJGEqV/U94aTM3lbbCTqhCgcrooOioAMxvbZd44SzNymixLy3k+jYpY+6 aQUtbczjyprJaxsPbTPx7GYBKjqD6RugAGD6Qkck4Zv1KwWrjBML3hJWYtBYbDyUlH +D1QtSI1pA/L/BXKMHfY4mEvl8XzNfAVBlWBMux3RKnBdPR1LU2FOvmjwC/Mv2SOyY 7HhAl95tIrc3A== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 16/33] serial: 8250: extract serial8250_initialize() Date: Wed, 11 Jun 2025 12:03:02 +0200 Message-ID: <20250611100319.186924-17-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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 |=3D UART_BUG_THRE; } =20 -int serial8250_do_startup(struct uart_port *port) +static void serial8250_initialize(struct uart_port *port) { struct uart_8250_port *up =3D 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 |=3D TIOCM_OUT1; + } else { + /* Most PC uarts need OUT2 raised to enable interrupts. */ + if (port->irq) + port->mctrl |=3D 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 si= gnalize that a + * transmission data was queued. Due to that, the above test generally fa= ils. One solution + * would be to delay the reading of iir. However, this is not reliable, s= ince the timeout is + * variable. So, let's just don't test if we receive TX irq. This way, w= e'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 =3D serial_port_in(port, UART_LSR) & UART_LSR_TEMT; + iir_NOINT =3D 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 |=3D UART_BUG_TXEN; + dev_dbg(port->dev, "enabling bad tx status workarounds\n"); + } + } else { + up->bugs &=3D ~UART_BUG_TXEN; + } + } + + uart_port_unlock_irqrestore(port, flags); +} + +int serial8250_do_startup(struct uart_port *port) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); int retval; - u16 lsr; =20 if (!port->fifosize) port->fifosize =3D uart_config[port->type].fifo_size; @@ -2310,56 +2356,7 @@ int serial8250_do_startup(struct uart_port *port) =20 up->ops->setup_timer(up); =20 - /* - * 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 |=3D TIOCM_OUT1; - } else - /* - * Most PC uarts need OUT2 raised to enable interrupts. - */ - if (port->irq) - up->port.mctrl |=3D 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 =3D serial_port_in(port, UART_LSR); - iir =3D 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 |=3D UART_BUG_TXEN; - dev_dbg(port->dev, "enabling bad tx status workarounds\n"); - } - } else { - up->bugs &=3D ~UART_BUG_TXEN; - } - } - - uart_port_unlock_irqrestore(port, flags); + serial8250_initialize(port); =20 /* * Clear the interrupt registers again for luck, and clear the --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 169E826E71E; Wed, 11 Jun 2025 10:03:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636237; cv=none; b=DnG7GKJbUbGVWN52NMulseX14RqSTGeStMfFC4WfUKj1ZBCYo4DbcKRFwpEJARd0xvQKiKWfntGzAyK8t6c2Phgf3QO1kCYgDzlejdHQ5QFxWYYTkPhmqsi2l1fDp0YIqtE98C3x2yzcOy/RfNio3gfKVs/Qvz4UiTF9RntPcJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636237; c=relaxed/simple; bh=JdzKrio3EtFrI1IOdFlxX4OF4VPG1PDPzdE0atRSivE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XRkwPTbRKgrwMNpsMANvpv31QZb1pCv8DeNMyHuNKwo1NhX1yopKn6mHnidGtyvqtGZOImV5x+YgbsBntmWlvRr/6b+fv87B3wVznYL8rolEfBM/RnWNaFZqwDdHte5IC7JcQ8XDSOjExBaG1KZkg59lwzpw/3QJVO3T6Zdjid0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V07hw66b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V07hw66b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB4DBC4CEF2; Wed, 11 Jun 2025 10:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636237; bh=JdzKrio3EtFrI1IOdFlxX4OF4VPG1PDPzdE0atRSivE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V07hw66bgqRQnFUhXu4wLWW7KUrpu/dThYLLlg6JnDeQnUwMaKGowFFpaYU1wdVje N+SLbNh7EsPdd20SaGZFRld2jUFfWVgoqLdopkj4A+EeO6xrrCdoOB0Rq4DcH2SGWV Rp7f/KWhOmTMwS7E6cVoKyZH5exXd9Z4gs9ZtpDAgsIkpJIAmMDyUUUMLVUUspBrvG p3QSFZncys7WUCNQ4Th2HQmW4d5dR1R9ccw0wfWgpEuLTg97ZAwjoPr2TU0WsOeW3h 2DwoKMkhZWswotkZbMnwpRQKIrajhv5pKgmgx5syMpd1VLSpQK6OHPQZaa909zWOSl XJY6HHtjaWesw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 17/33] serial: 8250: extract serial8250_clear_interrupts() Date: Wed, 11 Jun 2025 12:03:03 +0200 Message-ID: <20250611100319.186924-18-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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); } =20 +/* 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 =3D probe_irq_off(irqs); @@ -2322,13 +2328,7 @@ int serial8250_do_startup(struct uart_port *port) */ serial8250_clear_fifos(up); =20 - /* - * 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); =20 /* * 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 =3D 0; up->msr_saved_flags =3D 0; =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9663A26FA4E; Wed, 11 Jun 2025 10:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636238; cv=none; b=Etlg5dXoqtBWe/tH09jRaaepB+bwKYnBgh9LTM4Wybs8qZfNSlyAc/TACI4IhhocOvpIvYZmdPvHktdpHwohqRGy+9MHsSRL50xuJDXyY5y9Pw7NvBvpaQgmUC2qb7LqY9V3vFd+KKYYpRKbB66ZliQwD/1uP8Ds7Z4Qd43kYgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636238; c=relaxed/simple; bh=xaJJlQcxKm++tvGMXyDRzn8B2BvesW+EjNbVHmVVJug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CtgDt6Sb3yPOuIFZYPSZfM8D3DB77aFoR++VUoqo9agKWb0JxEJhCdyJhxXMD04e1i8Yur4ASKmuhXU7vcWcCJ4IYTFnTnllZRQtSrsqF0BYeEL4XBWkbjnC8VllBFC58ZnLWPXhemYy63Nkb/quTuLti64s2M20M4XXLmGMa7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eKPjiF70; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eKPjiF70" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67DCCC4CEEE; Wed, 11 Jun 2025 10:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636238; bh=xaJJlQcxKm++tvGMXyDRzn8B2BvesW+EjNbVHmVVJug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKPjiF70Z9ktWH2DzYCR1IMSJdDGOIOyBvbS1GMXPfZUKNaIeSw8l2dnIw31Lhyxy H2pCQ00z3f/6QmiOJYTP/RqLwKmw2cHiB8dIVl3JXeiPIHJyuNjEr+i6xy6SqAMnmL 9ypC+euhuc0TZ2x97nAZoFuMPF5gDQbZPm/y6QZAky6N990Gqcq+nRr92luIJ86B43 ZTEj1HDtQbbIFGzpcc9K3lVd9NqbNjy3uBjd5EAeTolVDRo+6bIrmo6+y3iyrOJKjV ZOy9L4AWe9t7Duzx3ZyiiNWInkvWr2AEuFsbrVEH/sRliH2uQiFszGJUW6LqNlr8Ex ZzQZdi0qgvNYg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 18/33] serial: 8250: extract serial8250_set_mini() Date: Wed, 11 Jun 2025 12:03:04 +0200 Message-ID: <20250611100319.186924-19-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 *por= t, unsigned int uartclk) } EXPORT_SYMBOL_GPL(serial8250_update_uartclk); =20 +static void serial8250_set_mini(struct uart_port *port, struct ktermios *t= ermios) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + + if (!(up->capabilities & UART_CAP_MINI)) + return; + + termios->c_cflag &=3D ~(CSTOPB | PARENB | PARODD | CMSPAR); + + tcflag_t csize =3D termios->c_cflag & CSIZE; + if (csize =3D=3D CS5 || csize =3D=3D CS6) { + termios->c_cflag &=3D ~CSIZE; + termios->c_cflag |=3D 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, st= ruct ktermios *termios, unsigned long flags; unsigned int baud, quot, frac =3D 0; =20 - if (up->capabilities & UART_CAP_MINI) { - termios->c_cflag &=3D ~(CSTOPB | PARENB | PARODD | CMSPAR); - if ((termios->c_cflag & CSIZE) =3D=3D CS5 || - (termios->c_cflag & CSIZE) =3D=3D CS6) - termios->c_cflag =3D (termios->c_cflag & ~CSIZE) | CS7; - } + serial8250_set_mini(port, termios); cval =3D serial8250_compute_lcr(up, termios->c_cflag); - baud =3D serial8250_get_baud_rate(port, termios, old); quot =3D serial8250_get_divisor(port, baud, &frac); =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82E7826FD87; Wed, 11 Jun 2025 10:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636240; cv=none; b=WEZuNkg5qzJIPCacfcPu9JY9RtKHARe/Su/Dx4r9MwgO8d1nONo8G8KZuNKfAQgqIAQSg+EvnxLeAdTFTE2AQi/fMZWR2AsIqRev6IBv74wPkLq+7VfLEcY93oNtb9ZCoTmvBD6KLOpn4DrfSd+KUz6si73HKUtgIlagkf0EHYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636240; c=relaxed/simple; bh=yk7rS8uj6HMJ5l7KaUfXbIeHDknoyAKWxylgblqDUG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=leBbbmn0AARrxgyq7x8/g4qjG6LWRt+CrFRDZ9wSjXB2BE1GNImvbqNO5GxrkhNwUm389gUYeE3cmezrWKBo01yewL2QtEo0cf9p6TTLuH6T4usbBvydwiP3DQDjfQHpGbglfRKZhMf5rFqOeL954Ee4q/1vSmeKgW1g/xQ6xWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LzCpjg+y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LzCpjg+y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7E88C4CEEE; Wed, 11 Jun 2025 10:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636240; bh=yk7rS8uj6HMJ5l7KaUfXbIeHDknoyAKWxylgblqDUG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzCpjg+yH5ePv7DpJE9qCDkCezIZ3nXkckOKrFjKY4uCS3G3ogR2KfEFaWR+4JtY0 /JXZqz+kZ6aZsQTMns/CJm2ZGM5d2U1QN36GjrCdZ3Rb8e18uPntcmZONR8v08DsjF p+b5wQ7bSaFQZfYcggCFBf23LTJKS0m+WTb/vAfiz9j00MlzzfenvQ27f6su6JiOTK 0BqIDNjAJmZAw1jB2PWmg0mKkfB6U8kfNIJiAjp2FfuJBe08kLhfwS6xuRpHFlY7cB iYnpNW4KSOnU6CaVemsUtnuYAstzzJzm70ia701MIw53l9i9z1XSnMudPZvGVwXw8P LMgqSdWDv83NA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed() Date: Wed, 11 Jun 2025 12:03:05 +0200 Message-ID: <20250611100319.186924-20-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 *po= rt, struct ktermios *termios } } =20 +static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, = struct ktermios *termios, + unsigned int baud) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + + if (!(up->capabilities & UART_CAP_FIFO)) + return; + if (port->fifosize <=3D 1) + return; + if (baud >=3D 2400) + return; + if (up->dma) + return; + + up->fcr &=3D ~UART_FCR_TRIGGER_MASK; + up->fcr |=3D 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, st= ruct ktermios *termios, uart_port_lock_irqsave(port, &flags); =20 up->lcr =3D cval; /* Save computed LCR */ - - if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { - if (baud < 2400 && !up->dma) { - up->fcr &=3D ~UART_FCR_TRIGGER_MASK; - up->fcr |=3D UART_FCR_TRIGGER_1; - } - } + serial8250_set_trigger_for_slow_speed(port, termios, baud); =20 /* * MCR-based auto flow control. When AFE is enabled, RTS will be --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F1C326FDB6; Wed, 11 Jun 2025 10:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636242; cv=none; b=BdBafX4msV86/eqnQMmwZaz5B0BrgPlmJEEwBapjnAK+Ic4CfT6jsw4h48Cww2cd8hz4W18xI5iTu/ScBV+FBEB2U5EHUz2GuVdRTCmdmd8y8qDF8ItjtdvOlNNRUSPbkE7uuJXFz+yxESUa4zYe2gxuUDU8jbodWS4icmDJWa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636242; c=relaxed/simple; bh=WOJjaorRqfEH2qZy3pWluuuC4luyiJuKzvdIlQZ69oI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LFjlbLsDavGBcj4erDSqacmw7EuZlbDc1HgQDDaBABleK+wSe7PnUM5Qr01atzb+BiC5ljcFWtisP2rqAn0UeSIYomyMCt/ErY309nv4QcZZpU8M99S2NEmUhRoGRxMQu9jK3+nxf+lF1FJ3NbT12SyCqgbIV/HZA4mg9gZOl6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a2uzF4ej; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a2uzF4ej" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 747FBC4CEF1; Wed, 11 Jun 2025 10:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636241; bh=WOJjaorRqfEH2qZy3pWluuuC4luyiJuKzvdIlQZ69oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a2uzF4ej6ZKn2ohQOliTICTjUUuhpjL+JVGw1fmltPdRZxH5zvz8K7DRc65lY7o4e 4ljKZgq6sXCp5IFO4BMLnhxDddhTnoNGDwc5kvWqW0r8+btDQuT79bkgo5SKn/eikf QvRIJbefRLV7rfR6tf9DocaTVgEA4U0CEpIcT+mm0Onn8aDhZIh7gLfIL2QTdGP4iN ilvz+GfvWI9Q+YZI6L1hW0sCUagaXejNUHNCBNYKbit8lrcFAo6qHXhXF3PJ4d/ti/ nhZHWwy6p9QaUnHWE2WRtwYAcbwsv+5zlzMoDpn9kbimQ+kII2tAtEDyvvT+HW17jM Gf2YHS5xCzQUQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 20/33] serial: 8250: extract serial8250_set_afe() Date: Wed, 11 Jun 2025 12:03:06 +0200 Message-ID: <20250611100319.186924-21-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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(st= ruct uart_port *port, struct up->fcr |=3D UART_FCR_TRIGGER_1; } =20 +/* + * MCR-based auto flow control. When AFE is enabled, RTS will be deasserte= d when the receive FIFO + * contains more characters than the trigger, or the MCR RTS bit is cleare= d. + */ +static void serial8250_set_afe(struct uart_port *port, struct ktermios *te= rmios) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + + if (!(up->capabilities & UART_CAP_AFE)) + return; + + up->mcr &=3D ~UART_MCR_AFE; + if (termios->c_cflag & CRTSCTS) + up->mcr |=3D 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, st= ruct ktermios *termios, =20 up->lcr =3D 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 &=3D ~UART_MCR_AFE; - if (termios->c_cflag & CRTSCTS) - up->mcr |=3D UART_MCR_AFE; - } - - /* - * Update the per-port timeout. - */ + serial8250_set_afe(port, termios); uart_update_timeout(port, termios->c_cflag, baud); =20 /* --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F2632701C5; Wed, 11 Jun 2025 10:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636243; cv=none; b=XfIAOxRjmzPAydFjsD+UFNE1lrITXYYe/K+aXg6tu/2Yp9q7BV69wT6bi89tLyeXVnCyrk1R4CN7F9OfBxeLduYclqyQAb2Nqoute1zkXVczjg7bjMfFUk1iLzfZ7bbg7sjtJDSfmlekuV/3tdMNdDis8+Eu2cdDkJMTNu0HuH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636243; c=relaxed/simple; bh=YgGgl4hmHOZF95YQRTmyFWWejDONs+53HuHseWC5klE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CLUWfbVK8GH31AJLfN4bFiCLG7Nc/QCMPiRuhFDgrt/pOh26W+WH9LHIGWfM4U+6CPMDVKSclHW5bcxj9rkfnRFijOWD8i7zFhLRIVQs5C0grfG04YEJxXL2TSDmUYGekjtIRPOpqa5FrACwFJaid5zsv4Kc9Ku4bgcbrzkSmGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qq+T7KpH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qq+T7KpH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00BFEC4CEF2; Wed, 11 Jun 2025 10:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636243; bh=YgGgl4hmHOZF95YQRTmyFWWejDONs+53HuHseWC5klE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qq+T7KpHhafK7EOTBRBJ+f05Py20OBwKTETYGDRqmkdoIFcKHzNEgTh/YEji5SNVJ Bwqaf/G5ixol0J5/C6Qj6dFBmEYgmn+Fk/zXBGd86Owb2VQ++fbrK7LHMeid1QIgVJ hCRu5DsRtkVvbc0JjXhGPs7OlZ1YEj9RQe70pBtjnh7uLwTrp1VYkg2rZp7fDVgO9n T4/SvHhbTcf5CVsR3w+4665edl2kADGXbL2tZIjWFUq6+uC3VRO1M5k9ph0UGqUk+i fsDCG5mcCNDkl6z6LCB2xsBwvB3zin+Il10OCkKfgHQTC86TBVMkdgByUvRQ8+I0gQ OWI1ZgcKt2ebw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 21/33] serial: 8250: extract serial8250_set_errors_and_ignores Date: Wed, 11 Jun 2025 12:03:07 +0200 Message-ID: <20250611100319.186924-22-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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 *por= t, struct ktermios *termios) up->mcr |=3D UART_MCR_AFE; } =20 +static void serial8250_set_errors_and_ignores(struct uart_port *port, stru= ct 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 i= s set in + * @ignore_status_mask as well. + */ + port->read_status_mask =3D UART_LSR_OE | UART_LSR_DR; + if (termios->c_iflag & INPCK) + port->read_status_mask |=3D UART_LSR_FE | UART_LSR_PE; + if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) + port->read_status_mask |=3D UART_LSR_BI; + + /* Characters to ignore */ + port->ignore_status_mask =3D 0; + if (termios->c_iflag & IGNPAR) + port->ignore_status_mask |=3D UART_LSR_PE | UART_LSR_FE; + if (termios->c_iflag & IGNBRK) { + port->ignore_status_mask |=3D UART_LSR_BI; + /* + * If we're ignoring parity and break indicators, ignore overruns too (f= or real raw + * support). + */ + if (termios->c_iflag & IGNPAR) + port->ignore_status_mask |=3D UART_LSR_OE; + } + + /* ignore all characters if CREAD is not set */ + if ((termios->c_cflag & CREAD) =3D=3D 0) + port->ignore_status_mask |=3D 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, st= ruct 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 =3D UART_LSR_OE | UART_LSR_DR; - if (termios->c_iflag & INPCK) - port->read_status_mask |=3D UART_LSR_FE | UART_LSR_PE; - if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) - port->read_status_mask |=3D UART_LSR_BI; - - /* - * Characters to ignore - */ - port->ignore_status_mask =3D 0; - if (termios->c_iflag & IGNPAR) - port->ignore_status_mask |=3D UART_LSR_PE | UART_LSR_FE; - if (termios->c_iflag & IGNBRK) { - port->ignore_status_mask |=3D 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 |=3D UART_LSR_OE; - } - - /* - * ignore all characters if CREAD is not set - */ - if ((termios->c_cflag & CREAD) =3D=3D 0) - port->ignore_status_mask |=3D UART_LSR_DR; + serial8250_set_errors_and_ignores(port, termios); =20 /* * CTS flow control flag and modem status interrupts --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2259926FDB6; Wed, 11 Jun 2025 10:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636245; cv=none; b=H3Nhe5GC4zr1uflLQhLDJwxfXIGEmE48lWZI8N3u02G6sWhz6Ni/cF9hc+5/yTotMbzsoyNuTSbvBSk4agYuLVBuYr5HTs1DLiP0J2agHqvf75Cz986VOfp6MEvLRQUhkl3ojUSw0SNSiAYDTPMSKDZ2u53WF68JFsO3zXlIplA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636245; c=relaxed/simple; bh=KipqVa0cNBWMnucUp3kii6iZVqiqOBeiBoGWeEe2I+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WO5342wB4cp9cfUitZw2fPwQdkWpHP85o9h3XweCmv4tC0OMXFq+OWNnqEPQx7NnowN6ZIlplSongqUoJpqFX6fg3eNqjWWf1FIuK0MSnkeedmYiv4cB8w9vumridmncr0zUas+N4oGSl1Zx9xPRp54aGnmG2ZngvNKEjlIk8YY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m1FFDVyv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m1FFDVyv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83431C4CEF2; Wed, 11 Jun 2025 10:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636244; bh=KipqVa0cNBWMnucUp3kii6iZVqiqOBeiBoGWeEe2I+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m1FFDVyvU0mI35SVPNWaLTNLsnlFtr+TbnyNSm/+UKPx9Yh5RoD++TiBwYTVxWFMZ umaJ28++7YMaWxWyOdabGxBGE4XPULVq0ku0FmT5TPw6yzB2WfhpVNc8j0HB6I0oVH DdBUbJwOCe8Z8/8AcqbQvs4IcGZGXheNGYn7Hp6CzLXbqZoq8QaT39m7u1LEHQdU6i xXbwRD3EAi6mGA3sxL5ZUqNIy5oqFjpMlSv8eRCOsMK2q4U4EluFYV9skH3eNcdz3q ud+MFGmXdrzW1qaETBitbuyeISU1pjCzEq9/1ID7YXOiXxLnzafcYfBfONYpdo0tqM 4DSfgw0yWn+MA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 22/33] serial: 8250: extract serial8250_set_ier() Date: Wed, 11 Jun 2025 12:03:08 +0200 Message-ID: <20250611100319.186924-23-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 |=3D UART_LSR_DR; } =20 +static void serial8250_set_ier(struct uart_port *port, struct ktermios *te= rmios) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + + /* CTS flow control flag and modem status interrupts */ + up->ier &=3D ~UART_IER_MSI; + if (!(up->bugs & UART_BUG_NOMSR) && UART_ENABLE_MS(&up->port, termios->c_= cflag)) + up->ier |=3D UART_IER_MSI; + if (up->capabilities & UART_CAP_UUE) + up->ier |=3D UART_IER_UUE; + if (up->capabilities & UART_CAP_RTOIE) + up->ier |=3D 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, st= ruct 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 &=3D ~UART_IER_MSI; - if (!(up->bugs & UART_BUG_NOMSR) && - UART_ENABLE_MS(&up->port, termios->c_cflag)) - up->ier |=3D UART_IER_MSI; - if (up->capabilities & UART_CAP_UUE) - up->ier |=3D UART_IER_UUE; - if (up->capabilities & UART_CAP_RTOIE) - up->ier |=3D UART_IER_RTOIE; - - serial_port_out(port, UART_IER, up->ier); + serial8250_set_ier(port, termios); =20 if (up->capabilities & UART_CAP_EFR) { unsigned char efr =3D 0; --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E532270EA9; Wed, 11 Jun 2025 10:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636246; cv=none; b=u7BJgmnuca7MeqOzL1UADfhMEF1pnTrQFktWL520W/km1rml1iEzkFRsgpWvDNg2qqiridGYxnLNdqBJ+w3YVHoUAflsbyWxTjlZqdVztJ76X45qmealHpBj4kL8x2M4Dn6tlNbNlXzOtrRP0bIQy1MzA5ZxQuLTO90TABMXjCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636246; c=relaxed/simple; bh=KrS7UF/iteN9keGU/ybxP25+KoQLtb2QJ16P7m4vfEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X4hHBG4s8m4RKJiV2hGH11QalNPGerwAzNnpxz/xJU8HcAY/wjhpLe1cf90Ac3Izusrb0OmUwH7FQztgJ/+xpMcRKk+NwV8MMPymyYHzvNBT2zHvaoF13MsJDu4Zi/O0utiPu4wJ5bpx/FOeueFqfvUOG+eU8fn55ZnN1CjzkqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D/WyqptG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D/WyqptG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F5F8C4CEF3; Wed, 11 Jun 2025 10:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636246; bh=KrS7UF/iteN9keGU/ybxP25+KoQLtb2QJ16P7m4vfEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/WyqptGLktSWxJ7sJTg1Sy/x8+bdTam74nE48tsEyn/FBqPUgc8Jij6GhobGzSMj vEKLNVMQBqwEazYhqMRoXAie/NYz9n8+PWpR07sbGchBdxTGNCqXfHpEUCDpuHB8vY tJjojNMpbNhM2h0nQxonPrC69ZmiW8UoKSMUdbzcJice/6M3PtaFtWdNULDBFA53+5 P1tbaIRw7GqKEWTedDaKz/44KzSPQ3cnt7moG9bMhubW1SWCvAoNIf8mL68SE2YOhr zK2nWNI/DEet06fN1dVj9pqVsvLlDoWjfXdbF+gJ0JrLqwMlSpOLSM54lHgM7LU7qg fjyFDTFSNNbcg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 23/33] serial: 8250: extract serial8250_set_efr() Date: Wed, 11 Jun 2025 12:03:09 +0200 Message-ID: <20250611100319.186924-24-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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 *por= t, struct ktermios *termios) serial_port_out(port, UART_IER, up->ier); } =20 +static void serial8250_set_efr(struct uart_port *port, struct ktermios *te= rmios) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + u8 efr_reg =3D UART_EFR; + u8 efr =3D 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 |=3D UART_EFR_CTS; + + if (port->flags & UPF_EXAR_EFR) + efr_reg =3D 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, st= ruct 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 =3D 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 |=3D 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); =20 /* --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC024271459; Wed, 11 Jun 2025 10:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636247; cv=none; b=E7Aw975TAyMmZtBWs3nAjHQ/u+6k4L5jhbbxxzqQEgY4yV1DNX0+opZml2TMKXT1pPYJG7st934RJ5zKk7Rni9T/GbM4+zZRslwk3hCvo3FUFI4haTzeqoHv62qusMLVMQ317AHobOl+K+lI0r4sHmbBtElnTB+tcmI0hddVjs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636247; c=relaxed/simple; bh=5B9gtT24AhZTBn2vPPhlNepVtn42Uh/A5PW08+jvO5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oR3dvG19MQYEYOIwMifaOUieWolQ5W1EZhaJve4KJvSja3rKoaAdnWZYHakzogDINl961dGbunWcBBwkeX084ipPGDZypoVGAEUy5wipUYgaWmVl6u8/vj8Ubssd1FhY6FwsQCjbwtsU7sHVH3rvSPnFM44m6JjL/smqzAdw7l4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zxv4gPpW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zxv4gPpW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F078C4CEF2; Wed, 11 Jun 2025 10:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636247; bh=5B9gtT24AhZTBn2vPPhlNepVtn42Uh/A5PW08+jvO5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zxv4gPpWgFvLjzLmYnQ3cquLENkKoOTX/ehXCKDU6iMcea2ZPfx66eM8aVlf+8EX6 dScbD1wctf/RXSRTUAUC6oWjdFA63brw73wfkPsqXlvpfQwF97kMf+VRKJNYleMogf t+VTzP6qTjihIRPBmPyt+Yge3FBQmh4RKqBl27JtU5KWUlo3r94A/NwVuzdKS5hzWa y0ut4oa/7yoRnu+hI66y/6lJ9YIo8hdt43appQNQDqNl2yIq1CN1Z3mDHfy5WyzQ1l z1yq1FC0BPE06zyz9TwYmF6KH9CjGvgKQBQAYBM5WidcM61382/s7ysw/B8+HGZ33s c4sSnyEIhkKIg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 24/33] serial: 8250: extract serial8250_set_fcr() Date: Wed, 11 Jun 2025 12:03:10 +0200 Message-ID: <20250611100319.186924-25-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 *por= t, struct ktermios *termios) serial_port_out(port, efr_reg, efr); } =20 +static void serial8250_set_fcr(struct uart_port *port, struct ktermios *te= rmios) +{ + struct uart_8250_port *up =3D up_to_u8250p(port); + bool is_16750 =3D port->type =3D=3D 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 writ= ten 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, st= ruct 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 =3D=3D PORT_16750) - serial_port_out(port, UART_FCR, up->fcr); - - serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ - if (port->type !=3D 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); =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 498AA271A7B; Wed, 11 Jun 2025 10:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636249; cv=none; b=qSrjWpWPRsNpSyJTC0wSXua8+sZuixjltf5uVXv2SM24EXnODim2k/hqA+Ayu3EsopCTVLr0LnjqSNnoFPrnUlTVb+/wtYy80FZJWqQ6deeSOAMLV5dD45c+zLlWNoQY1obSot7M5aQMGFP7AChjbr0mFGLhn6fhz0gCLJFZI7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636249; c=relaxed/simple; bh=qOAKptBoRTWs5a8BW/VyavKeswkJR7m83lczPmzKOiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NNxN0+BIp/Kgip26JxK9UkK7lJYLWifMqzH9kEF1bUq76pS80FZtcWj7fUztmiC46yeU/eIaANuRKuROXSb4r1W1IW3HxswQJFlM8kHGCDcq9JSNgV7g/Nf1zPQc8H0faSGIlDv26lsSAhtvHI5HIVpdBwbmZOIznY/Rw+k2Aiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IwwD5uu6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IwwD5uu6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ADD5C4CEEE; Wed, 11 Jun 2025 10:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636249; bh=qOAKptBoRTWs5a8BW/VyavKeswkJR7m83lczPmzKOiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwwD5uu6pRuAxXG9puQ9zlX4OMPPGoOeVfEdOTXu9JlAiKa4JNR7qyWW5eZzo2YZa py09/UXcOowDzc5RlMkOTHfdSDCJGWiZzyE3cyWaPSnWEaHo8twFc1NpVi/D2GbTvY 1Lt8bJ7ZHaub8nUj/j1g0m7bWB3NPkNlfxJjDD7q1/y1p0iR12FM/PHmBbCaxfvT8X EgC+VVC0vJNoKcUU0mjp8OdBzIETbt0Z7OQVhypV/KZbGtjJTDyRG5D35PlP1zFaHm Y0el/RCq1UNXzQ/ppMeZSYNaO8XzPCoGUi5RwKxl8oahhy61YaqeradPtYU2FsMB6e aRfTL02mTbVWg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 25/33] serial: 8250: lcr compute cleanup Date: Wed, 11 Jun 2025 12:03:11 +0200 Message-ID: <20250611100319.186924-26-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" * 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 u= art_port *port, return serial8250_do_get_divisor(port, baud, frac); } =20 -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, tcf= lag_t c_cflag) { - unsigned char cval; - - cval =3D UART_LCR_WLEN(tty_get_char_size(c_cflag)); + u8 lcr =3D UART_LCR_WLEN(tty_get_char_size(c_cflag)); =20 if (c_cflag & CSTOPB) - cval |=3D UART_LCR_STOP; + lcr |=3D UART_LCR_STOP; if (c_cflag & PARENB) - cval |=3D UART_LCR_PARITY; + lcr |=3D UART_LCR_PARITY; if (!(c_cflag & PARODD)) - cval |=3D UART_LCR_EPAR; + lcr |=3D UART_LCR_EPAR; if (c_cflag & CMSPAR) - cval |=3D UART_LCR_SPAR; + lcr |=3D UART_LCR_SPAR; =20 - return cval; + return lcr; } =20 void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud, @@ -2821,12 +2818,12 @@ serial8250_do_set_termios(struct uart_port *port, s= truct ktermios *termios, const struct ktermios *old) { struct uart_8250_port *up =3D up_to_u8250p(port); - unsigned char cval; unsigned long flags; unsigned int baud, quot, frac =3D 0; + u8 lcr; =20 serial8250_set_mini(port, termios); - cval =3D serial8250_compute_lcr(up, termios->c_cflag); + lcr =3D serial8250_compute_lcr(up, termios->c_cflag); baud =3D serial8250_get_baud_rate(port, termios, old); quot =3D serial8250_get_divisor(port, baud, &frac); =20 @@ -2839,7 +2836,7 @@ serial8250_do_set_termios(struct uart_port *port, str= uct ktermios *termios, serial8250_rpm_get(up); uart_port_lock_irqsave(port, &flags); =20 - up->lcr =3D cval; /* Save computed LCR */ + up->lcr =3D lcr; serial8250_set_trigger_for_slow_speed(port, termios, baud); serial8250_set_afe(port, termios); uart_update_timeout(port, termios->c_cflag, baud); --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8B27272E5A; Wed, 11 Jun 2025 10:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636250; cv=none; b=P8sVxIu4K8EyVJk7qOd68pwCHfwOWzZcT0wxVawkwZyCHrZ8psVnVj3FrSUEW4qnjBG43htGXK3APXsSyqMbRWHcJ+cIjUwdgU58gpSoCL1NhRy3XMy2MIf33k1WuEwXnT2sHboQprxZCDkSuA1N5zfB8dupsSb0kdNiq1mJuJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636250; c=relaxed/simple; bh=5iZ1B5ZkaY5ZLX/qDcX1g+zAgRyPtiYm0Fa29q1Y75c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgxBjiPRcstUgdPBMjkQsWWTT3qeIG8KijbQTK3EqkZnvBBd1s/+KB4vZWWj+D5vfPPBwUJIqjcpUhuVdE+U7k2s5DGZspwMeiyM6+SoVJ/UQk3mcwJqVND9unY2opEDulEdwNait6xIA9RNV4cUGXmttofbpCjV8eKqgxXyDrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AtVAmJRo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AtVAmJRo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B278C4CEF2; Wed, 11 Jun 2025 10:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636250; bh=5iZ1B5ZkaY5ZLX/qDcX1g+zAgRyPtiYm0Fa29q1Y75c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AtVAmJRolfNj5x09ChZgJSMCbHzPtttsgnXsR95rt1SWJIV8U/We3OY8S19l0JjXV yJJrn74vXcmn7tf96eGQdl3AnvMw3U2GoSYE9H0fpBc984cZ6puMFhNqhIksf16OQi BoG7RqRZydtm7T3dWCGs9fz4bPvMPT2B1941Lil7YfiwT0owo0s5KO3O8gF5lUZQvB K4TzhwL5585but1APU8zyoKqZT9R4AcsoGoz1A9AkEno5XMtiv5WrgTGJREPf3c02v c0jGmLXZutbryYcZNliGB2IUHNNOypnJ82lVkwOvolovG0zIdOZ5ys1RsFEywf/+Df xIZsrlBjvyeVQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 26/33] serial: 8250: drop unused frac from serial8250_do_get_divisor() Date: Wed, 11 Jun 2025 12:03:12 +0200 Message-ID: <20250611100319.186924-27-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" '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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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); } =20 -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, unsi= gned int baud) { upf_t magic_multiplier =3D port->flags & UPF_MAGIC_MULTIPLIER; struct uart_8250_port *up =3D up_to_u8250p(port); @@ -2544,7 +2542,7 @@ static unsigned int serial8250_get_divisor(struct uar= t_port *port, if (port->get_divisor) return port->get_divisor(port, baud, frac); =20 - return serial8250_do_get_divisor(port, baud, frac); + return serial8250_do_get_divisor(port, baud); } =20 static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, tcf= lag_t c_cflag) --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5595D2741B0; Wed, 11 Jun 2025 10:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636252; cv=none; b=Xvp3M+dbTsOMkM0UKO+gprz0TyX3JZsArebKgmbaLb3FtLhrDTzj7FvNFNG2iWL9x7nc2nOzj+XApVtU6h9zRLCLL/RFqngYlXasqtyzfJ7HEN8DMGm6G1qAb/L9jvhuB3nZF1FciIDsPmed0YAwnJB52cF1bZUJeDWNlGyHpWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636252; c=relaxed/simple; bh=rKS+4K+FzL8vD+6uKlsTZAKIzZuyv6esLcxPlYOcUz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lBV3iIl0pU4VN7eQ1UFB28DLRNtIivrdRvPkq8i/CTSXIlUwthuTr7AxZ0jPyTOpPDOrNK95sMzc8lLM6cR7Z61IR2vOLddMRrc0HYEkDOTY2829xZH8V50oswfSd0zCWSmpHBmklvvTM9j0iXtOp3vRgf+csjprjR3DQP8j4R4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JkGoraFe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JkGoraFe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26DB8C4CEEE; Wed, 11 Jun 2025 10:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636252; bh=rKS+4K+FzL8vD+6uKlsTZAKIzZuyv6esLcxPlYOcUz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkGoraFewgN/0jEinfQQORzp7pjyDQZcTWLx+TnJwwhZzEWWsiOVS/mpvWtsDs0Fz vnNfgM7UG3gutvJM7W2K2LqRPRPVxM4Vsh0cE+mZ6QHfrc54WBqcld1fU99xlkaoCH +4zwAvOaylq9bc/xU6NzjbUaw1HI5Apds7ajAMPUd4AFNBbT1Tg+BZiF6c8MrUn0uU v5aI+cW1ZMNQIJ1yPQSeaEfVOH5HKQBbkJia/MACp/mqAfPAq/2pTSLuEgMEN8aQhk xSSjIv4FKf0anoN14blA0drnm7pY0p565TsTCMl3sak1x9wlPD/jDrrq1u5ywo5PdY h0MI9AaiEHxXA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 27/33] serial: 8250: extract serial_get_or_create_irq_info() Date: Wed, 11 Jun 2025 12:03:13 +0200 Message-ID: <20250611100319.186924-28-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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, stru= ct uart_8250_port *up) } } =20 -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_82= 50_port *up) { struct hlist_head *h; struct irq_info *i; - int ret; =20 mutex_lock(&hash_mutex); =20 @@ -141,20 +145,31 @@ static int serial_link_irq_chain(struct uart_8250_por= t *up) =20 hlist_for_each_entry(i, h, node) if (i->irq =3D=3D up->port.irq) - break; + goto unlock; =20 + i =3D kzalloc(sizeof(*i), GFP_KERNEL); if (i =3D=3D NULL) { - i =3D kzalloc(sizeof(struct irq_info), GFP_KERNEL); - if (i =3D=3D NULL) { - mutex_unlock(&hash_mutex); - return -ENOMEM; - } - spin_lock_init(&i->lock); - i->irq =3D up->port.irq; - hlist_add_head(&i->node, h); + i =3D ERR_PTR(-ENOMEM); + goto unlock; } + spin_lock_init(&i->lock); + i->irq =3D up->port.irq; + hlist_add_head(&i->node, h); +unlock: mutex_unlock(&hash_mutex); =20 + return i; +} + +static int serial_link_irq_chain(struct uart_8250_port *up) +{ + struct irq_info *i; + int ret; + + i =3D serial_get_or_create_irq_info(up); + if (IS_ERR(i)) + return PTR_ERR(i); + spin_lock_irq(&i->lock); =20 if (i->head) { --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2927274650; Wed, 11 Jun 2025 10:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636253; cv=none; b=F9lyGhfaPKY/uIURIGR0DSgy9RaeQhHl4G+bTcDVPU+4s0bx4JU5MIgA50jvgySlApZ8Vw6U0bzsaP5fsFEq8JBtb1TGbwPuDIfIo2O/DU9PmwwMAqJz5mZRp9k6KrR41k37c5n447wPtjwR/ipoRGYJ502NDNZ3mBknrsqpQUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636253; c=relaxed/simple; bh=tyMGFJEDosv2AewzwsSSsJRZRuSG65ioJg7V4YuZYN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G4s/e6TwRSbthWaROkY6VnQ8cFXEoJqgZ0CEd7K8p6OrJTapuGNJyUgGsfhgC5gxUpz3KUFRIW1zErjN00AoOlDzpE1JF7SdFuSplamW3vT0oWqzDUbrXyhEZBByqKuRP/EeQxnNkfqI8d2LCsU4pkVRllJkFaQFx47+2Nj4ge4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d2ovLDOm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d2ovLDOm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6E91C4CEEE; Wed, 11 Jun 2025 10:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636253; bh=tyMGFJEDosv2AewzwsSSsJRZRuSG65ioJg7V4YuZYN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2ovLDOmCuPzSNM/4DBiYK4KPylviAUTRCaJFIyNzTKrUF48tUSSa/p0MKY5djlJ3 YbVVVB6XsF3OMI4tiaOxqT8TG0nuBY3luCNRDS9NU2fWFv72ATsaz4w1qdZszPtkMp XSUYJhmZNRITeC8qp8yw8Dag4t3zrkmV1tDSifi+QjFTgGwwamxzSVjvjTcXkUAjGh 0N0jofKjShz2fdmQGKdZFURE6Z7YAycqhA6p6KcoDkUuT4tgnJ0UalcnVE35WM5sRI BWqrqzatF1NVgcGT3+R9F/S6NJckD/TdRYToDgzrQ2zX1u78ZW7EvN4OGYYacguvMx RQH0kFQwRmGng== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 28/33] serial: 8250: remove debug prints from ISR Date: Wed, 11 Jun 2025 12:03:14 +0200 Message-ID: <20250611100319.186924-29-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These are useless, we have tracing nowadays. Signed-off-by: Jiri Slaby (SUSE) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 *de= v_id) struct list_head *l, *end =3D NULL; int pass_counter =3D 0, handled =3D 0; =20 - pr_debug("%s(%d): start\n", __func__, irq); - spin_lock(&i->lock); =20 l =3D i->head; @@ -97,8 +95,6 @@ static irqreturn_t serial8250_interrupt(int irq, void *de= v_id) =20 spin_unlock(&i->lock); =20 - pr_debug("%s(%d): end\n", __func__, irq); - return IRQ_RETVAL(handled); } =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A10E6274676; Wed, 11 Jun 2025 10:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636255; cv=none; b=SmKxIoriejl5QCubPDtiBtkp8Uur0JIwC/0hRYFBJ47r1ssD7rrJD0TMdxepqhzK8nDtYtM7airh1OD9oPe8wWq6wQSNdZeeMcmX48gL0VoegMrZCKGVVnDrKF4vpzm3rzLcZzqYCS6mvDfjegHBBL2AN/Prg4AznKE1DN4ltFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636255; c=relaxed/simple; bh=/pmfUrZUdBfKWuAWDNedV43TaddT3zUC0Xn4iWMbi6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AcYa/j/cQNLqBW3eEoaZrdN2OlnYir+Jb1nuILHy6Se6B5miF9HpfDd/i4bnHgxkig8E3wDtquV6W00ITibPXzCAERSRlTuc13KJSbQypkCEXtEIfJyHSo7bLsV+WKcyVRY/RBcWgmWDdmvt5s1ERtKCFdu3UYFv29P4egWqs+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bY2CsjGy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bY2CsjGy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32E05C4CEEE; Wed, 11 Jun 2025 10:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636255; bh=/pmfUrZUdBfKWuAWDNedV43TaddT3zUC0Xn4iWMbi6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bY2CsjGyKXjOmsqONsJFd2Vlwrfu5mSsTfjM+dacdICNsmkIYDD+/OzESSj1/CkLK A7YhuswTiRwTnhz9qflVzw2JwU+TPlgrC5tr2wgrUBJs6LAFa7NbLpT7M/y5ZwK/lu P/rbJf1QqzygDvNtOSDHwDfvwoG36zmQHecb3zT88xzt7crVaHtNMNvtEmHVMmFGey c6NAL59LERm4FYH3mnX3IdqE1m1eTSzvsHSfn9/BP3NxMSfFKoVYiQiy6AN7/hx/kW 0tcRzTeYRdSgG3och6vfBi1PFGuvbGSU2h5r/jgVJx/FlCAA41mcuxQrMv8qKMwSyq T2FVuSB/KMLWg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 29/33] serial: 8250: drop DEBUG_AUTOCONF() macro Date: Wed, 11 Jun 2025 12:03:15 +0200 Message-ID: <20250611100319.186924-30-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 i= s false Drop it. Signed-off-by: Jiri Slaby (SUSE) Reviewed-by: Ilpo J=C3=A4rvinen --- 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 @@ =20 #include "8250.h" =20 -/* - * 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 *u= p) id3 =3D serial_icr_read(up, UART_ID3); rev =3D serial_icr_read(up, UART_REV); =20 - DEBUG_AUTOCONF("950id=3D%02x:%02x:%02x:%02x ", id1, id2, id3, rev); - if (id1 =3D=3D 0x16 && id2 =3D=3D 0xC9 && (id3 =3D=3D 0x50 || id3 =3D=3D 0x52 || id3 =3D=3D 0x54)) { up->port.type =3D PORT_16C950; @@ -850,7 +839,6 @@ static void autoconfig_has_efr(struct uart_8250_port *u= p) * 0x14 - XR16C854. */ id1 =3D autoconfig_read_divisor_id(up); - DEBUG_AUTOCONF("850id=3D%04x ", id1); =20 id2 =3D id1 >> 8; if (id2 =3D=3D 0x10 || id2 =3D=3D 0x12 || id2 =3D=3D 0x14) { @@ -937,7 +925,6 @@ static void autoconfig_16550a(struct uart_8250_port *up) if (serial_in(up, UART_EFR) =3D=3D 0) { serial_out(up, UART_EFR, 0xA8); if (serial_in(up, UART_EFR) !=3D 0) { - DEBUG_AUTOCONF("EFRv1 "); up->port.type =3D PORT_16650; up->capabilities |=3D UART_CAP_EFR | UART_CAP_SLEEP; } else { @@ -950,8 +937,6 @@ static void autoconfig_16550a(struct uart_8250_port *up) =20 if (status1 =3D=3D UART_IIR_FIFO_ENABLED_16750) up->port.type =3D 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) =3D=3D 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) =20 serial_out(up, UART_LCR, 0); =20 - DEBUG_AUTOCONF("iir1=3D%d iir2=3D%d ", status1, status2); - if (status1 =3D=3D UART_IIR_FIFO_ENABLED_16550A && status2 =3D=3D UART_IIR_FIFO_ENABLED_16750) { up->port.type =3D 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 =3D PORT_XSCALE; up->capabilities |=3D 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); =20 @@ -1098,9 +1073,6 @@ static void autoconfig(struct uart_8250_port *up) if (!port->iobase && !port->mapbase && !port->membase) return; =20 - 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; } } =20 @@ -1171,9 +1141,7 @@ static void autoconfig(struct uart_8250_port *up) serial8250_out_MCR(up, save_mcr); if (status1 !=3D (UART_MSR_DCD | UART_MSR_CTS)) { uart_port_unlock_irqrestore(port, flags); - DEBUG_AUTOCONF("LOOP test failed (%02x) ", - status1); - goto out; + return; } } =20 @@ -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=3D%d ", scratch); - DEBUG_AUTOCONF("type=3D%s\n", uart_config[port->type].name); } =20 static void autoconfig_irq(struct uart_8250_port *up) --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 630022749FA; Wed, 11 Jun 2025 10:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636257; cv=none; b=GxvtYBezPGudTrTb2wDciKp4Y86Knn7xproqbX1Q+59zo4H9GS8xpuju9O81WtE8SXOWgTZ1/DXJCdwLD3dv6EJhWDONk3+mZauHVVUri1htZIyp3I5XWCTqv1c4CK0XBsjB12BKEnaY+2e9FuPY3ZRm1MAnCMlp3K/A/c36ttw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636257; c=relaxed/simple; bh=yv/RaTW9MuC3s3vDA052dackvAJiP/l11cLARUKG7co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PCbdlFjX0VN6d5a3E0LTVNfjPvxB75gqScJ+hTiIEk06OVf05CXg0KXHIfDHIaF64h7qHW68O3HQNQK90X/ZenXBioNQ7Q9wGDRdo8Z4Eq5xEy66vbte/21ZmPrwm341kj4OxmI9BvL14GcQjMNCBHrak47VErjJZqjckpsyGMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b8HB5jaP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b8HB5jaP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3442C4CEF2; Wed, 11 Jun 2025 10:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636256; bh=yv/RaTW9MuC3s3vDA052dackvAJiP/l11cLARUKG7co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b8HB5jaPPkKuGtW0E9IQaFvuvkR8d3NDRMLU1z6KIyzqOwqEYU95JgcmCwdhj27Sq aNpSybkuRyfFZCS/mRZJxHZHspA2RwFCd6JVxNnxPGIdt1a05pinCcaC0P1RZBczc6 mt6EzpDgeEbTOviIwQczx/w53gMnpFeiB6IZ3U8FO4QxUGSXwOJwcTKp0Cxq/wWEib bNShiXHD3+qM0dgX6itMcDSXWDgkYUQD+dbPNzy9hesMhnvUARJAJcpkjdeqIM+XfV GXBnjN6TQoCsHb3iYSqom2K9RvClS+aCHXtyQWANcy2yT6Zbrd9wwKWSwyyYYGzzwr DjblzLYqsdufQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 30/33] serial: 8250: invert serial8250_register_8250_port() CIR condition Date: Wed, 11 Jun 2025 12:03:16 +0200 Message-ID: <20250611100319.186924-31-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Ilpo J=C3=A4rvinen --- 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++; } =20 - if (uart->port.type !=3D PORT_8250_CIR) { - struct mctrl_gpios *gpios; - - if (uart->port.dev) - uart_remove_one_port(&serial8250_reg, &uart->port); - - uart->port.ctrl_id =3D up->port.ctrl_id; - uart->port.port_id =3D up->port.port_id; - uart->port.iobase =3D up->port.iobase; - uart->port.membase =3D up->port.membase; - uart->port.irq =3D up->port.irq; - uart->port.irqflags =3D up->port.irqflags; - uart->port.uartclk =3D up->port.uartclk; - uart->port.fifosize =3D up->port.fifosize; - uart->port.regshift =3D up->port.regshift; - uart->port.iotype =3D up->port.iotype; - uart->port.flags =3D up->port.flags | UPF_BOOT_AUTOCONF; - uart->bugs =3D up->bugs; - uart->port.mapbase =3D up->port.mapbase; - uart->port.mapsize =3D up->port.mapsize; - uart->port.private_data =3D up->port.private_data; - uart->tx_loadsz =3D up->tx_loadsz; - uart->capabilities =3D up->capabilities; - uart->port.throttle =3D up->port.throttle; - uart->port.unthrottle =3D up->port.unthrottle; - uart->port.rs485_config =3D up->port.rs485_config; - uart->port.rs485_supported =3D up->port.rs485_supported; - uart->port.rs485 =3D up->port.rs485; - uart->rs485_start_tx =3D up->rs485_start_tx; - uart->rs485_stop_tx =3D up->rs485_stop_tx; - uart->lsr_save_mask =3D up->lsr_save_mask; - uart->dma =3D up->dma; - - /* Take tx_loadsz from fifosize if it wasn't set separately */ - if (uart->port.fifosize && !uart->tx_loadsz) - uart->tx_loadsz =3D uart->port.fifosize; - - if (up->port.dev) { - uart->port.dev =3D up->port.dev; - ret =3D uart_get_rs485_mode(&uart->port); - if (ret) - goto err; - } + if (uart->port.type =3D=3D PORT_8250_CIR) { + ret =3D -ENODEV; + goto unlock; + } =20 - if (up->port.flags & UPF_FIXED_TYPE) - uart->port.type =3D up->port.type; + if (uart->port.dev) + uart_remove_one_port(&serial8250_reg, &uart->port); + + uart->port.ctrl_id =3D up->port.ctrl_id; + uart->port.port_id =3D up->port.port_id; + uart->port.iobase =3D up->port.iobase; + uart->port.membase =3D up->port.membase; + uart->port.irq =3D up->port.irq; + uart->port.irqflags =3D up->port.irqflags; + uart->port.uartclk =3D up->port.uartclk; + uart->port.fifosize =3D up->port.fifosize; + uart->port.regshift =3D up->port.regshift; + uart->port.iotype =3D up->port.iotype; + uart->port.flags =3D up->port.flags | UPF_BOOT_AUTOCONF; + uart->bugs =3D up->bugs; + uart->port.mapbase =3D up->port.mapbase; + uart->port.mapsize =3D up->port.mapsize; + uart->port.private_data =3D up->port.private_data; + uart->tx_loadsz =3D up->tx_loadsz; + uart->capabilities =3D up->capabilities; + uart->port.throttle =3D up->port.throttle; + uart->port.unthrottle =3D up->port.unthrottle; + uart->port.rs485_config =3D up->port.rs485_config; + uart->port.rs485_supported =3D up->port.rs485_supported; + uart->port.rs485 =3D up->port.rs485; + uart->rs485_start_tx =3D up->rs485_start_tx; + uart->rs485_stop_tx =3D up->rs485_stop_tx; + uart->lsr_save_mask =3D up->lsr_save_mask; + uart->dma =3D up->dma; + + /* Take tx_loadsz from fifosize if it wasn't set separately */ + if (uart->port.fifosize && !uart->tx_loadsz) + uart->tx_loadsz =3D uart->port.fifosize; + + if (up->port.dev) { + uart->port.dev =3D up->port.dev; + ret =3D uart_get_rs485_mode(&uart->port); + if (ret) + goto err; + } =20 - /* - * Only call mctrl_gpio_init(), if the device has no ACPI - * companion device - */ - if (!has_acpi_companion(uart->port.dev)) { - gpios =3D mctrl_gpio_init(&uart->port, 0); - if (IS_ERR(gpios)) { - ret =3D PTR_ERR(gpios); - goto err; - } else { - uart->gpios =3D gpios; - } - } + if (up->port.flags & UPF_FIXED_TYPE) + uart->port.type =3D up->port.type; =20 - serial8250_set_defaults(uart); - - /* Possibly override default I/O functions. */ - if (up->port.serial_in) - uart->port.serial_in =3D up->port.serial_in; - if (up->port.serial_out) - uart->port.serial_out =3D up->port.serial_out; - if (up->port.handle_irq) - uart->port.handle_irq =3D up->port.handle_irq; - /* Possibly override set_termios call */ - if (up->port.set_termios) - uart->port.set_termios =3D up->port.set_termios; - if (up->port.set_ldisc) - uart->port.set_ldisc =3D up->port.set_ldisc; - if (up->port.get_mctrl) - uart->port.get_mctrl =3D up->port.get_mctrl; - if (up->port.set_mctrl) - uart->port.set_mctrl =3D up->port.set_mctrl; - if (up->port.get_divisor) - uart->port.get_divisor =3D up->port.get_divisor; - if (up->port.set_divisor) - uart->port.set_divisor =3D up->port.set_divisor; - if (up->port.startup) - uart->port.startup =3D up->port.startup; - if (up->port.shutdown) - uart->port.shutdown =3D up->port.shutdown; - if (up->port.pm) - uart->port.pm =3D up->port.pm; - if (up->port.handle_break) - uart->port.handle_break =3D up->port.handle_break; - if (up->dl_read) - uart->dl_read =3D up->dl_read; - if (up->dl_write) - uart->dl_write =3D up->dl_write; - - if (uart->port.type !=3D PORT_8250_CIR) { - if (uart_console_registered(&uart->port)) - pm_runtime_get_sync(uart->port.dev); - - if (serial8250_isa_config !=3D NULL) - serial8250_isa_config(0, &uart->port, - &uart->capabilities); - - serial8250_apply_quirks(uart); - ret =3D uart_add_one_port(&serial8250_reg, - &uart->port); - if (ret) - goto err; - - ret =3D 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 =3D mctrl_gpio_init(&uart->port, 0); + if (IS_ERR(gpios)) { + ret =3D 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 =3D 0; + uart->gpios =3D gpios; } + } =20 - if (!uart->lsr_save_mask) - uart->lsr_save_mask =3D 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 =3D up->port.serial_in; + if (up->port.serial_out) + uart->port.serial_out =3D up->port.serial_out; + if (up->port.handle_irq) + uart->port.handle_irq =3D up->port.handle_irq; + /* Possibly override set_termios call */ + if (up->port.set_termios) + uart->port.set_termios =3D up->port.set_termios; + if (up->port.set_ldisc) + uart->port.set_ldisc =3D up->port.set_ldisc; + if (up->port.get_mctrl) + uart->port.get_mctrl =3D up->port.get_mctrl; + if (up->port.set_mctrl) + uart->port.set_mctrl =3D up->port.set_mctrl; + if (up->port.get_divisor) + uart->port.get_divisor =3D up->port.get_divisor; + if (up->port.set_divisor) + uart->port.set_divisor =3D up->port.set_divisor; + if (up->port.startup) + uart->port.startup =3D up->port.startup; + if (up->port.shutdown) + uart->port.shutdown =3D up->port.shutdown; + if (up->port.pm) + uart->port.pm =3D up->port.pm; + if (up->port.handle_break) + uart->port.handle_break =3D up->port.handle_break; + if (up->dl_read) + uart->dl_read =3D up->dl_read; + if (up->dl_write) + uart->dl_write =3D up->dl_write; =20 - /* Initialise interrupt backoff work if required */ - if (up->overrun_backoff_time_ms > 0) { - uart->overrun_backoff_time_ms =3D - up->overrun_backoff_time_ms; - INIT_DELAYED_WORK(&uart->overrun_backoff, - serial_8250_overrun_backoff_work); - } else { - uart->overrun_backoff_time_ms =3D 0; - } + if (uart->port.type !=3D PORT_8250_CIR) { + if (uart_console_registered(&uart->port)) + pm_runtime_get_sync(uart->port.dev); + + if (serial8250_isa_config !=3D NULL) + serial8250_isa_config(0, &uart->port, + &uart->capabilities); + + serial8250_apply_quirks(uart); + ret =3D uart_add_one_port(&serial8250_reg, + &uart->port); + if (ret) + goto err; + + ret =3D 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 =3D 0; + } + + if (!uart->lsr_save_mask) + uart->lsr_save_mask =3D 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 =3D + up->overrun_backoff_time_ms; + INIT_DELAYED_WORK(&uart->overrun_backoff, + serial_8250_overrun_backoff_work); + } else { + uart->overrun_backoff_time_ms =3D 0; } =20 unlock: --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BC20274FDF; Wed, 11 Jun 2025 10:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636258; cv=none; b=E5yDhaxPNoTyUS30xH62qbRcud4cCmnTIwqafVObslDBBcTwY1ktG85ndkOKsn+kb+RbQkvHABNO5c8GY8pmJyJDOoPUsNcTUOMZvxkcasCyetciSU84VbV92DKKcKUYpIV+uQATlvmsjeIFZX8as+s0emAhFav0sKO8nRiyn2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636258; c=relaxed/simple; bh=XRkrlnSCwcbeRXUXQj1MvWIxyQPXeoOAi0mv2fldBwA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HFcESSPiAQvDUAY0/cyPcOnJf2EFUw2kX9MPpaB/fzutxAIicJcAB81J954dOxZTHrKXWQIWxm9efV7VthDkIH1auDobkxsvcQM1urhseIO919yO45oTJqablPIfZDMpOqq0ruNnK4Ea/qzXWz1OPUQ/dkg0UROXgEwPEw+662w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HB1y23eo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HB1y23eo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EA1FC4CEF1; Wed, 11 Jun 2025 10:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636258; bh=XRkrlnSCwcbeRXUXQj1MvWIxyQPXeoOAi0mv2fldBwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HB1y23eo9kJPYp7Gg1YiD6RrGgCeljBmKeelQ/JAzvWiWlAetVD7LZPzJniAcmX1a pIqx/NkXcVQtveFRuKiXcLedsm/V6Vs/ofoI174WWYdTi4GsMfhptSgEcXnLcu+u9X GdSNuGUJ41pW6VxZq/l4JpbZajGESSOdfeuE2fpzHSgnwV7IG6xsj11tYleQnf7MZa 5W5vG1XEMS408DGUCNxd+oQkY6x/2rsUBk10Ktqnc3rzdt+mKzLzctfvDtauxOsL6M 0NlpHjLejf53enA/eu7w26AzrrhqSmRbeHIc6+WvJAwbxRe3F81F+bii+ygFBmtV4O RFQcagv45b3/Q== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 31/33] serial: 8250: invert condition to avoid a goto label Date: Wed, 11 Jun 2025 12:03:17 +0200 Message-ID: <20250611100319.186924-32-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use of "goto" in this code is frowned upon: +------- |if (port->type =3D=3D PORT_UNKNOWN) | goto out_unlock; |CODE; |out_unlock: +------- Instead, simply do: +------- |if (port->type !=3D PORT_UNKNOWN) | CODE; +------- Signed-off-by: Jiri Slaby (SUSE) --- 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 =3D uart_config[port->type].flags; up->tx_loadsz =3D uart_config[port->type].tx_loadsz; =20 - if (port->type =3D=3D 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 !=3D 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); + } =20 -out_unlock: uart_port_unlock_irqrestore(port, flags); =20 /* --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED1A627511A; Wed, 11 Jun 2025 10:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636260; cv=none; b=eMXcoChgkhD8Re0uvDhD7J8TUax4guvEmXkTefcXom7cy4ao2aULXnuzByj6qHABos/9zMQI8zrzunkBCD2OxHteM8eOZY+b2ztQGPiKXJ2aVfpBo6c2D1cdHp2isP5GepbUaYyS0YCAzhW8vCBTtyIAF4NCKIOgKephHhP9KoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636260; c=relaxed/simple; bh=mkbFe4ug8CJGhd1eJ9syIXDg0PrhGmkItDExnX2ZtgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a9jh7RA59D5mLbooSg5bv/hCkoINVMAbxuywJYxJZGgUx804Fwl1QOvOnh+E85IoGxPoQwlNC3aJYKCaPX8YpFYalR8OLH56j25mOn9P+Lw5igN/s2BNFiELrhuuPaCMqC0Bk89hETv8Ggb0hkkkOyJPtgcSBJTcJSOjReIYQ4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TdfbvpAO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TdfbvpAO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF547C4CEEE; Wed, 11 Jun 2025 10:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636259; bh=mkbFe4ug8CJGhd1eJ9syIXDg0PrhGmkItDExnX2ZtgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdfbvpAOhZh2f6lZQOKeTNEYGu87bfs1WFtonZBREsYRqXhOjffFVrx7+ju7gm81L T5XMyP0zf/4nTXtKjE9ElznFuPvcN0vfdgvnA/4dnWdq6abzPnFJyWOCbbaPwz30gk wKEp+2GfJtKYPWqZlpUdLhuYFF7hZZHqmcpYJPjPPEBAX3XVpWeLqqUBlVDRMufTIs Z/tPhwmY79XC2QpTdwT6T4FWetFgz7x+0uOd+yd/MJawgTkVF00c6jVkTP+22MSbpJ KrtWgDbTZeQBQyUg/OJmnQET9tltduQMz6On+yAuIQN1fZDYloztgu8lHE+Q9rM1FN Eq/5irU9VWWYg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 32/33] serial: 8250: use hashtable Date: Wed, 11 Jun 2025 12:03:18 +0200 Message-ID: <20250611100319.186924-33-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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 @@ */ =20 #include +#include #include #include #include @@ -47,8 +48,8 @@ struct irq_info { struct list_head *head; }; =20 -#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 */ =20 /* @@ -75,11 +76,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *d= ev_id) =20 l =3D i->head; do { - struct uart_8250_port *up; - struct uart_port *port; - - up =3D list_entry(l, struct uart_8250_port, list); - port =3D &up->port; + struct uart_8250_port *up =3D list_entry(l, struct uart_8250_port, list); + struct uart_port *port =3D &up->port; =20 if (port->handle_irq(port)) { handled =3D 1; @@ -132,14 +130,11 @@ static void serial_do_unlink(struct irq_info *i, stru= ct uart_8250_port *up) */ static struct irq_info *serial_get_or_create_irq_info(const struct uart_82= 50_port *up) { - struct hlist_head *h; struct irq_info *i; =20 mutex_lock(&hash_mutex); =20 - h =3D &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 =3D=3D up->port.irq) goto unlock; =20 @@ -150,7 +145,7 @@ static struct irq_info *serial_get_or_create_irq_info(c= onst struct uart_8250_por } spin_lock_init(&i->lock); i->irq =3D up->port.irq; - hlist_add_head(&i->node, h); + hash_add(irq_lists, &i->node, i->irq); unlock: mutex_unlock(&hash_mutex); =20 @@ -189,13 +184,10 @@ static int serial_link_irq_chain(struct uart_8250_por= t *up) static void serial_unlink_irq_chain(struct uart_8250_port *up) { struct irq_info *i; - struct hlist_head *h; =20 mutex_lock(&hash_mutex); =20 - h =3D &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 =3D=3D up->port.irq) break; =20 --=20 2.49.0 From nobody Sat Oct 11 04:24:11 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7992327603B; Wed, 11 Jun 2025 10:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636261; cv=none; b=qOCCzlC20AhhCcB6QkczZrC6rM9YPyfVPnHiNHJkem7p1YFyJmwDE4RXiDYNivRedew/qfiiTpDuD/1GOewj5M4vGUZgtZoZsCi/5Wxjshjn6hvtLbmsmqKBAAXrGpLjrsKEeayrQwcHvOVtbJHeYt5MdmI1ecdON65CaFC01+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749636261; c=relaxed/simple; bh=MANMkRvyaEm4TFMefQFhtP9hAEWswU83yvGivjHb7QI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=saBZHGOGpiIfajgAO0yupticJD7Mvzv9q1pgcslzywQSHmgzA8KSg9+3IMq2XvEW0VeGSW8guOZciYncNg25yIWpodb97KBVInUjFKOJ+s/ZXpIn38U0CdUguyBwtDuCQpz4RWMT+sRTp5K/0neFdhOfDhL+3T1FXJ+xzccD6x4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CR/ZTJ+Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CR/ZTJ+Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BFA7C4CEEE; Wed, 11 Jun 2025 10:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749636261; bh=MANMkRvyaEm4TFMefQFhtP9hAEWswU83yvGivjHb7QI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CR/ZTJ+ZcmGKEnb9ZkxE0xcgQAw9muJk8UDpS9Q2wepnQ3ZMxBZ8d136jIFhulonv 1/PFEbkNDbvn72bs/13ariMYZ69iBRtLnVqArI6aFatTQqxCJvRc598cJTFDuapr1t Wv3HEk82mTY1Y+ulFFHtiPMHKefruAjRkkeEey+zKAnQMy7YtSNQZP7HO1X0Dtczbr cquNCKlf99c/R0NAvuGR87ZCxwzGpMnv2zgjbTKl4sGbFuTE95O+R1dfXUA7PL4d+O /zvxaVArfLI/ayCjSrRJDBA+lPFTKAYQy7ap4RfzlOTtlATGwYXSHdK/CJdsj72+a0 xvv9uIZUReCyQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 33/33] serial: 8250_omap: use uart_port pointer when available Date: Wed, 11 Jun 2025 12:03:19 +0200 Message-ID: <20250611100319.186924-34-jirislaby@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611100319.186924-1-jirislaby@kernel.org> References: <20250611100319.186924-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- 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 re= g) static void __omap8250_set_mctrl(struct uart_port *port, unsigned int mctr= l) { struct uart_8250_port *up =3D up_to_u8250p(port); - struct omap8250_priv *priv =3D up->port.private_data; + struct omap8250_priv *priv =3D port->private_data; u8 lcr; =20 serial8250_do_set_mctrl(port, mctrl); @@ -303,12 +303,13 @@ static void omap8250_update_mdr1(struct uart_8250_por= t *up, =20 static void omap8250_restore_regs(struct uart_8250_port *up) { - struct omap8250_priv *priv =3D up->port.private_data; + struct uart_port *port =3D &up->port; + struct omap8250_priv *priv =3D port->private_data; struct uart_8250_dma *dma =3D up->dma; u8 mcr =3D serial8250_in_MCR(up); =20 /* Port locked to synchronize UART_IER access against the console. */ - lockdep_assert_held_once(&up->port.lock); + lockdep_assert_held_once(&port->lock); =20 if (dma && dma->tx_running) { /* @@ -359,12 +360,12 @@ static void omap8250_restore_regs(struct uart_8250_po= rt *up) =20 omap8250_update_mdr1(up, priv); =20 - __omap8250_set_mctrl(&up->port, up->port.mctrl); + __omap8250_set_mctrl(port, port->mctrl); =20 serial_out(up, UART_OMAP_MDR3, priv->mdr3); =20 - if (up->port.rs485.flags & SER_RS485_ENABLED && - up->port.rs485_config =3D=3D serial8250_em485_config) + if (port->rs485.flags & SER_RS485_ENABLED && + port->rs485_config =3D=3D serial8250_em485_config) serial8250_em485_stop_tx(up, true); } =20 @@ -377,7 +378,7 @@ static void omap_8250_set_termios(struct uart_port *por= t, const struct ktermios *old) { struct uart_8250_port *up =3D up_to_u8250p(port); - struct omap8250_priv *priv =3D up->port.private_data; + struct omap8250_priv *priv =3D port->private_data; unsigned char cval =3D 0; unsigned int baud; =20 @@ -418,39 +419,39 @@ static void omap_8250_set_termios(struct uart_port *p= ort, * ignoring of characters only occurs if the bit is set * in @ignore_status_mask as well. */ - up->port.read_status_mask =3D UART_LSR_OE | UART_LSR_DR; + port->read_status_mask =3D UART_LSR_OE | UART_LSR_DR; if (termios->c_iflag & INPCK) - up->port.read_status_mask |=3D UART_LSR_FE | UART_LSR_PE; + port->read_status_mask |=3D UART_LSR_FE | UART_LSR_PE; if (termios->c_iflag & (IGNBRK | PARMRK)) - up->port.read_status_mask |=3D UART_LSR_BI; + port->read_status_mask |=3D UART_LSR_BI; =20 /* * Characters to ignore */ - up->port.ignore_status_mask =3D 0; + port->ignore_status_mask =3D 0; if (termios->c_iflag & IGNPAR) - up->port.ignore_status_mask |=3D UART_LSR_PE | UART_LSR_FE; + port->ignore_status_mask |=3D UART_LSR_PE | UART_LSR_FE; if (termios->c_iflag & IGNBRK) { - up->port.ignore_status_mask |=3D UART_LSR_BI; + port->ignore_status_mask |=3D 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 |=3D UART_LSR_OE; + port->ignore_status_mask |=3D UART_LSR_OE; } =20 /* * ignore all characters if CREAD is not set */ if ((termios->c_cflag & CREAD) =3D=3D 0) - up->port.ignore_status_mask |=3D UART_LSR_DR; + port->ignore_status_mask |=3D UART_LSR_DR; =20 /* * Modem status interrupts */ up->ier &=3D ~UART_IER_MSI; - if (UART_ENABLE_MS(&up->port, termios->c_cflag)) + if (UART_ENABLE_MS(port, termios->c_cflag)) up->ier |=3D UART_IER_MSI; =20 up->lcr =3D cval; @@ -488,15 +489,15 @@ static void omap_8250_set_termios(struct uart_port *p= ort, priv->xoff =3D termios->c_cc[VSTOP]; =20 priv->efr =3D 0; - up->port.status &=3D ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); + port->status &=3D ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); =20 - 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 |=3D UPSTAT_AUTOCTS | UPSTAT_AUTORTS; + port->status |=3D UPSTAT_AUTOCTS | UPSTAT_AUTORTS; priv->efr |=3D 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 *por= t, * Transmit XON1, XOFF1 */ if (termios->c_iflag & IXOFF) { - up->port.status |=3D UPSTAT_AUTOXOFF; + port->status |=3D UPSTAT_AUTOXOFF; priv->efr |=3D OMAP_UART_SW_TX; } } @@ -770,7 +771,7 @@ static int omap_8250_startup(struct uart_port *port) uart_port_unlock_irq(port); } =20 - enable_irq(up->port.irq); + enable_irq(port->irq); =20 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 =3D 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); =20 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 =3D up_to_u8250p(port); - struct omap8250_priv *priv =3D up->port.private_data; + struct omap8250_priv *priv =3D port->private_data; u16 status; u8 iir; =20 @@ -1332,8 +1333,8 @@ static int omap_8250_dma_handle_irq(struct uart_port = *port) =20 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 =3D 0; serial8250_tx_chars(up); } else { --=20 2.49.0