From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (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 436685AEC41 for ; Fri, 16 Oct 2026 18:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.67.36.66 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792173647; cv=none; b=UWTtLtWk/fxjuRRMe8+Zf8vXCvG2ei13kv6mE4ZPs7Lv1EqSz4pDTal7B1S+TTnjA6U7SJN/NJZDL5F58quJQyfLpPcmhyor73Dh7z2TAPPCzzwJ/G5/YvU2SgsQx8Il64DGm3hIwWFErBb3pewACchbaUbuHUvM23oErvxavgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792173647; c=relaxed/simple; bh=4tlu3TzAuVWKPdQj53zjpnPlL2jlauwQHoBS/RJfI9c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qT5d4G20LxK0FHO31ZcWW8H+Lbe/4DIj4t5sjhcKzRxSv/bKAP3Cyt+tmR/KIUV9PKvq03WlzCEh24Qcdq7BHWOe2NvHGvjrbydUOixvQlPTNPLGq7OhADCPMYYpscXvx36s4w1RnBtrCEgSNZ26REYg8MInEknCdJGSV0RZvSE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de; spf=pass smtp.mailfrom=posteo.de; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b=FxSB6F+I; arc=none smtp.client-ip=185.67.36.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b="FxSB6F+I" Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id BA39D240101 for ; Fri, 16 Oct 2026 20:00:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.de; s=1984.8680eb; t=1792173636; bh=RtLzcITxruOsU4cSXs43zZTDJWiqIUlJ3CALd8khcnw=; h=From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:To:Cc:Autocrypt:OpenPGP:From; b=FxSB6F+IoQ8sPzAT/VVH4yyyAu8OQJ6ea2nEen0Okhc1IezF7Am5Zi9xFP+y/KQ0W FqeRz4kuUtL/EBaSQfiHAa71DwTvIKCvDJ6I8p493TQ+bdtGYQbWBSw8Hwtni1FENm gLJNWgvbnM2IfhUaDPisCoYuBaI+UeJCNiYepidf/GfE/dle6qPOP/hXJOBVtRuVLF HCUgrmi5/8ZHX40XIi8zY6KhDhQaExWv96RsGp/kaZhqut694Y2aFeJScp2bsNDhhZ W96dYrnjlEwqZ0TEm1nH/h+nBDoJgWPPJfS1/ox7QSHPeSlFbRYDLsgTSlQYdTJA+l iTj2XaevtrMkg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4j5t5X34Qdz9rxL; Fri, 16 Oct 2026 20:00:32 +0200 (CEST) From: Markus Probst Date: Fri, 16 Oct 2026 18:00:35 +0000 Subject: [PATCH v4 2/4] tty: serdev: Export functions to pause receive_buf callback calls Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261016-rust_serdev_probe_refactor-v4-2-46832e034757@posteo.de> References: <20261016-rust_serdev_probe_refactor-v4-0-46832e034757@posteo.de> In-Reply-To: <20261016-rust_serdev_probe_refactor-v4-0-46832e034757@posteo.de> To: Ayush Singh , Johan Hovold , Alex Elder , Greg Kroah-Hartman , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Eric Biggers , Ard Biesheuvel , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Uladzislau Rezki , Jiri Slaby , "Rafael J. Wysocki" Cc: greybus-dev@lists.linaro.org, linux-serial@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Markus Probst X-Developer-Signature: v=1; a=openpgp-sha256; l=6336; i=markus.probst@posteo.de; h=from:subject:message-id; bh=4tlu3TzAuVWKPdQj53zjpnPlL2jlauwQHoBS/RJfI9c=; b=owEBiQJ2/ZANAwAIATR2H/jnrUPSAcsmYgBq0mY454g8FAyHJKC3cJp5/9tYoB4fdh4z6dcx7 gujhrYB5EGJAk8EAAEIADkWIQSCdBjE9KxY53IwxHM0dh/4561D0gUCatJmOBsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDIACgkQNHYf+OetQ9IUSw/+KPVzvBFfe+eMGJLbryaduVFohIsJUP/ oF8uenEbhx+jacu9PD3RDX+wVQCMlnbNIUZHmwI+hEDzropEibGJLE79FmERoioLRQLiRJV+5h7 j/LjJ3jGYnBJZpRjgfeNZ+HXt4zSdTV4VIrCqAkWtuBwH8CV/HuJoNQgbBsFdEiZulOr242W2dS Ufvw4Bx/85MCUxbgkfacWal8sZYB/cfLjnlp1gXQ4Wjh1yHBqFFvP3gYK/N9xUYAjtw+HLtL0Bw Fpi4v3xf0eVVvm7xSOQdEowWlKZUlMRtorwqKZHJnt8Boei9ka4luL2qbHxBnBDjUDph4qK/QA9 GtfSCHdsQUO1eH01+YDbTulS+R9/vNq+mLZrnTrHqCpXXueujkaRITU4j3/rSWNhGE6DSxP/isM TcHRS4eIr0/5cONxssyRDBgqE5mAIT9z8nvcvWin4VpV51wCzJGhelt/PfvtnP6yOMraOnMa084 EiRNYXE60dd8kbpkZMHi+QFpqB7GJzred22TmLbL/H+9Kpex7NHZh89vq6Cc5ttA3ff76BIAFkn xQE4dtVbrgZGjIRX5kBaZl08FZHuXHtDQX65v+ZYvDUiIdCYpbN1h9xdKteZKe+cJ2HfX8Wo2HW 8Xj26HRNTP7mrEJZbeoFz1kYCUDnL9QfyAJW7mHJ8pJPUwlwAufo= X-Developer-Key: i=markus.probst@posteo.de; a=openpgp; fpr=827418C4F4AC58E77230C47334761FF8E7AD43D2 Autocrypt: addr=markus.probst@posteo.de; prefer-encrypt=mutual; keydata=xsFNBGiDvXgBEADAXUceKafpl46S35UmDh2wRvvx+UfZbcTjeQOlSwKP7YVJ4JOZrVs93qReNLkO WguIqPBxR9blQ4nyYrqSCV+MMw/3ifyXIm6Pw2YRUDg+WTEOjTixRCoWDgUj1nOsvJ9tVAm76Ww+ /pAnepVRafMID0rqEfD9oGv1YrfpeFJhyE2zUw3SyyNLIKWD6QeLRhKQRbSnsXhGLFBXCqt9k5JA RhgQof9zvztcCVlT5KVvuyfC4H+HzeGmu9201BVyihJwKdcKPq+n/aY5FUVxNTgtI9f8wIbmfAja oT1pjXSp+dszakA98fhONM98pOq723o/1ZGMZukyXFfsDGtA3BB79HoopHKujLGWAGskzClwTjRQ xBqxh/U/lL1pc+0xPWikTNCmtziCOvv0KA0arDOMQlyFvImzX6oGVgE4ksKQYbMZ3Ikw6L1Rv1J+ FvN0aNwOKgL2ztBRYscUGcQvA0Zo1fGCAn/BLEJvQYShWKeKqjyncVGoXFsz2AcuFKe1pwETSsN6 OZncjy32e4ktgs07cWBfx0v62b8md36jau+B6RVnnodaA8++oXl3FRwiEW8XfXWIjy4umIv93tb8 8ekYsfOfWkTSewZYXGoqe4RtK80ulMHb/dh2FZQIFyRdN4HOmB4FYO5sEYFr9YjHLmDkrUgNodJC XCe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EET3PdcKFYtS+ruV1Cp5V0q4kCfI5jk25iiz8grM2wOzVSsc l1mEkhiEPH87HP0whhb544iioSnumd3HJKL7dzhRegsMizatupp8D65A2JziW0WKopa1iw9fti3A aBeNN4ijKZchBXHPgVx+YtWRHfcm4l8= OpenPGP: url=https://posteo.de/keys/markus.probst@posteo.de.asc; preference=encrypt These functions will be used to simply the serdev rust abstraction. It also contributes to the fixing of 2 race conditions in the serdev rust abstraction. Signed-off-by: Markus Probst --- drivers/tty/serdev/core.c | 44 ++++++++++++++++++++++++++++++++++++- drivers/tty/serdev/serdev-ttyport.c | 38 ++++++++++++++++++++++++++++++++ include/linux/serdev.h | 6 +++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 77e8e1d4d2a6..af1470e33620 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -191,6 +191,45 @@ void serdev_device_close(struct serdev_device *serdev) } EXPORT_SYMBOL_GPL(serdev_device_close); +/** + * serdev_device_pause_rx() - pause data receive + * @serdev: serdev device + * + * Pause calls to receive_buf. + * + * Note that if a call to receive_buf is currently executed, the function will + * sleep until it has finished. + */ +void serdev_device_pause_rx(struct serdev_device *serdev) +{ + struct serdev_controller *ctrl = serdev->ctrl; + + if (!ctrl || !ctrl->ops->pause_rx) + return; + + ctrl->ops->pause_rx(ctrl); +} +EXPORT_SYMBOL_GPL(serdev_device_pause_rx); + +/** + * serdev_device_resume_rx() - resume data receive + * @serdev: serdev device + * + * Resume calls to receive_buf. + * + * This can be called even if not paused to ensure data receive is active. + */ +void serdev_device_resume_rx(struct serdev_device *serdev) +{ + struct serdev_controller *ctrl = serdev->ctrl; + + if (!ctrl || !ctrl->ops->resume_rx) + return; + + ctrl->ops->resume_rx(ctrl); +} +EXPORT_SYMBOL_GPL(serdev_device_resume_rx); + static void devm_serdev_device_close(void *serdev) { serdev_device_close(serdev); @@ -402,6 +441,7 @@ EXPORT_SYMBOL_GPL(serdev_device_break_ctl); static int serdev_drv_probe(struct device *dev) { const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); + struct serdev_device *sdev = to_serdev_device(dev); int ret; ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON | @@ -409,7 +449,9 @@ static int serdev_drv_probe(struct device *dev) if (ret) return ret; - return sdrv->probe(to_serdev_device(dev)); + serdev_device_resume_rx(sdev); + + return sdrv->probe(sdev); } static void serdev_drv_remove(struct device *dev) diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index 125a17a0bea5..e164ee7edc12 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -7,8 +7,10 @@ #include #include #include +#include "../tty.h" #define SERPORT_ACTIVE 1 +#define SERPORT_PAUSE_RX 2 struct serport { struct tty_port *port; @@ -36,6 +38,9 @@ static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp, if (!test_bit(SERPORT_ACTIVE, &serport->flags)) return 0; + if (test_bit(SERPORT_PAUSE_RX, &serport->flags)) + return 0; + ret = serdev_controller_receive_buf(ctrl, cp, count); dev_WARN_ONCE(&ctrl->dev, ret > count, @@ -185,6 +190,37 @@ static bool ttyport_close(struct serdev_controller *ctrl) return true; } +static void ttyport_pause_rx(struct serdev_controller *ctrl) +{ + struct serport *serport = serdev_controller_get_drvdata(ctrl); + struct tty_struct *tty = serport->tty; + + guard(mutex)(&serport->lock); + + scoped_guard(mutex, &serport->receive_lock) + set_bit(SERPORT_PAUSE_RX, &serport->flags); + + if (test_bit(SERPORT_ACTIVE, &serport->flags)) + tty_buffer_cancel_work(tty->port); +} + +static void ttyport_resume_rx(struct serdev_controller *ctrl) +{ + struct serport *serport = serdev_controller_get_drvdata(ctrl); + struct tty_struct *tty = serport->tty; + + guard(mutex)(&serport->lock); + + if (!test_bit(SERPORT_PAUSE_RX, &serport->flags)) + return; + + scoped_guard(mutex, &serport->receive_lock) + clear_bit(SERPORT_PAUSE_RX, &serport->flags); + + if (test_bit(SERPORT_ACTIVE, &serport->flags)) + tty_buffer_restart_work(tty->port); +} + static unsigned int ttyport_set_baudrate(struct serdev_controller *ctrl, unsigned int speed) { struct serport *serport = serdev_controller_get_drvdata(ctrl); @@ -289,6 +325,8 @@ static const struct serdev_controller_ops ctrl_ops = { .get_tiocm = ttyport_get_tiocm, .set_tiocm = ttyport_set_tiocm, .break_ctl = ttyport_break_ctl, + .pause_rx = ttyport_pause_rx, + .resume_rx = ttyport_resume_rx, }; struct device *serdev_tty_port_register(struct tty_port *port, diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 0f4e81c0950d..02773554e759 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -89,6 +89,8 @@ struct serdev_controller_ops { int (*get_tiocm)(struct serdev_controller *); int (*set_tiocm)(struct serdev_controller *, unsigned int, unsigned int); int (*break_ctl)(struct serdev_controller *ctrl, unsigned int break_state); + void (*pause_rx)(struct serdev_controller *ctrl); + void (*resume_rx)(struct serdev_controller *ctrl); }; /** @@ -194,6 +196,8 @@ static inline size_t serdev_controller_receive_buf(struct serdev_controller *ctr int serdev_device_open(struct serdev_device *); void serdev_device_close(struct serdev_device *); int devm_serdev_device_open(struct device *, struct serdev_device *); +void serdev_device_pause_rx(struct serdev_device *serdev); +void serdev_device_resume_rx(struct serdev_device *serdev); unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int); void serdev_device_set_flow_control(struct serdev_device *, bool); int serdev_device_write_buf(struct serdev_device *, const u8 *, size_t); @@ -233,6 +237,8 @@ static inline int serdev_device_open(struct serdev_device *sdev) return -ENODEV; } static inline void serdev_device_close(struct serdev_device *sdev) {} +static inline void serdev_device_pause_rx(struct serdev_device *serdev) {} +static inline void serdev_device_resume_rx(struct serdev_device *serdev) {} static inline unsigned int serdev_device_set_baudrate(struct serdev_device *sdev, unsigned int baudrate) { return 0; -- 2.55.0