[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240422065114.3185505-4-christoph.fritz@hexdev.de>
Date: Mon, 22 Apr 2024 08:51:06 +0200
From: Christoph Fritz <christoph.fritz@...dev.de>
To: Oliver Hartkopp <socketcan@...tkopp.net>,
Marc Kleine-Budde <mkl@...gutronix.de>,
Vincent Mailhol <mailhol.vincent@...adoo.fr>,
"David S . Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Jiri Kosina <jikos@...nel.org>,
Benjamin Tissoires <bentiss@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jirislaby@...nel.org>
Cc: Andreas Lauser <andreas.lauser@...cedes-benz.com>,
Jonathan Corbet <corbet@....net>,
linux-can@...r.kernel.org,
netdev@...r.kernel.org,
devicetree@...r.kernel.org,
linux-input@...r.kernel.org,
linux-serial@...r.kernel.org
Subject: [PATCH 03/11] tty: serdev: Add flag buffer aware receive_buf_fp()
This patch introduces an additional receive buffer callback variation
besides the already existing receive_buf(). This new callback function
also passes the flag buffer (TTY_NORMAL, TTY_BREAK, and friends).
If defined, this function gets prioritized and called instead of the
standard receive_buf().
An alternative approach could have been to enhance the receive_buf()
function and update all drivers that use it.
Signed-off-by: Christoph Fritz <christoph.fritz@...dev.de>
---
drivers/tty/serdev/serdev-ttyport.c | 2 +-
include/linux/serdev.h | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
index 3d7ae7fa50186..bb47691afdb21 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -32,7 +32,7 @@ static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
return 0;
- ret = serdev_controller_receive_buf(ctrl, cp, count);
+ ret = serdev_controller_receive_buf(ctrl, cp, fp, count);
dev_WARN_ONCE(&ctrl->dev, ret > count,
"receive_buf returns %zu (count = %zu)\n",
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index ff78efc1f60df..c6ef5a8988e07 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -23,11 +23,17 @@ struct serdev_device;
* struct serdev_device_ops - Callback operations for a serdev device
* @receive_buf: Function called with data received from device;
* returns number of bytes accepted; may sleep.
+ * @receive_buf_fp: Function called with data and flag buffer received
+ * from device; If defined, this function gets called
+ * instead of @receive_buf;
+ * returns number of bytes accepted; may sleep.
* @write_wakeup: Function called when ready to transmit more data; must
* not sleep.
*/
struct serdev_device_ops {
size_t (*receive_buf)(struct serdev_device *, const u8 *, size_t);
+ ssize_t (*receive_buf_fp)(struct serdev_device *, const u8 *,
+ const u8 *, size_t);
void (*write_wakeup)(struct serdev_device *);
};
@@ -186,15 +192,20 @@ static inline void serdev_controller_write_wakeup(struct serdev_controller *ctrl
}
static inline size_t serdev_controller_receive_buf(struct serdev_controller *ctrl,
- const u8 *data,
+ const u8 *data, const u8 *fp,
size_t count)
{
struct serdev_device *serdev = ctrl->serdev;
- if (!serdev || !serdev->ops->receive_buf)
+ if (!serdev || !serdev->ops)
return 0;
- return serdev->ops->receive_buf(serdev, data, count);
+ if (serdev->ops->receive_buf_fp)
+ return serdev->ops->receive_buf_fp(serdev, data, fp, count);
+ else if (serdev->ops->receive_buf)
+ return serdev->ops->receive_buf(serdev, data, count);
+
+ return 0;
}
#if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)
--
2.39.2
Powered by blists - more mailing lists