Skip to contentSkip to conversation

serdev: BREAK/FRAME/PARITY/OVERRUN notification prototype V2

PATCH In review Magnus Damm 3 participants 4 messages Dec 12, 2021 – Dec 31, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serdev: BREAK/FRAME/PARITY/OVERRUN notification prototype V2

From: Magnus Damm <[email protected]>

Allow serdev device drivers get notified by hardware errors such as BREAK, FRAME, PARITY and OVERRUN.

With this patch, in the event of an error detected in the UART device driver the serdev_device_driver will get the newly introduced ->error() callback invoked if serdev_device_set_error_mask() has previously been used to enable the type of error. The errors are taken straight from the TTY layer and fed into the serdev_device_driver after filtering out only enabled errors.

Without this patch the hardware errors never reach the serdev_device_driver.

---

Applies to linux-5.16-rc4

Change since V1:
- Use __set_bit() instead of set_bit() in ttyport_receive_buf()
- Switch to assign_bit() in ttyport_set_error_mask()

Thanks to Geert for feedback!

The following prototype patch is using serdev error notifications:
[PATCH] r8a77995 Draak SCIF0 LED and KEY Serdev prototype V2

 drivers/tty/serdev/core.c           |   11 +++++++
 drivers/tty/serdev/serdev-ttyport.c |   49 +++++++++++++++++++++++++++++++++++
 include/linux/serdev.h              |   22 +++++++++++++++
 3 files changed, 82 insertions(+)
drivers/tty/serdev/core.c +11 -0
@@ -349,6 +349,17 @@ unsigned int serdev_device_set_baudrate(
 }
 EXPORT_SYMBOL_GPL(serdev_device_set_baudrate);
 
+void serdev_device_set_error_mask(struct serdev_device *serdev, unsigned long mask)
+{
+	struct serdev_controller *ctrl = serdev->ctrl;
+
+	if (!ctrl || !ctrl->ops->set_error_mask)
+		return;
+
+	ctrl->ops->set_error_mask(ctrl, mask);
+}
+EXPORT_SYMBOL_GPL(serdev_device_set_error_mask);
+
 void serdev_device_set_flow_control(struct serdev_device *serdev, bool enable)
 {
 	struct serdev_controller *ctrl = serdev->ctrl;
drivers/tty/serdev/serdev-ttyport.c +49 -0

84 lines not on this page · raw message

include/linux/serdev.h +22 -0
@@ -19,12 +19,15 @@ struct serdev_device;
 
 /**
  * struct serdev_device_ops - Callback operations for a serdev device
+ * @error:		Function called with errors received from device;
+ *			may sleep.
  * @receive_buf:	Function called with data received from device;
  *			returns number of bytes accepted; may sleep.
  * @write_wakeup:	Function called when ready to transmit more data; must
  *			not sleep.
  */
 struct serdev_device_ops {
+	void (*error)(struct serdev_device *, unsigned long);
 	int (*receive_buf)(struct serdev_device *, const unsigned char *, size_t);
 	void (*write_wakeup)(struct serdev_device *);
 };
@@ -76,6 +79,11 @@ enum serdev_parity {
 	SERDEV_PARITY_ODD,
 };
 
+#define SERDEV_ERROR_BREAK 0
+#define SERDEV_ERROR_FRAME 1
+#define SERDEV_ERROR_PARITY 2
+#define SERDEV_ERROR_OVERRUN 3
+
 /*
  * serdev controller structures
  */
@@ -85,6 +93,7 @@ struct serdev_controller_ops {
 	int (*write_room)(struct serdev_controller *);
 	int (*open)(struct serdev_controller *);
 	void (*close)(struct serdev_controller *);
+	void (*set_error_mask)(struct serdev_controller *, unsigned long);
 	void (*set_flow_control)(struct serdev_controller *, bool);
 	int (*set_parity)(struct serdev_controller *, enum serdev_parity);
 	unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int);
@@ -190,12 +199,24 @@ static inline int serdev_controller_rece
 	return serdev->ops->receive_buf(serdev, data, count);
 }
 
+static inline void serdev_controller_error(struct serdev_controller *ctrl,
+					   unsigned long errors)
+{
+	struct serdev_device *serdev = ctrl->serdev;
+
+	if (!serdev || !serdev->ops->error)
+		return;
+
+	serdev->ops->error(serdev, errors);
+}
+
 #if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)
 
 int serdev_device_open(struct serdev_device *);
 void serdev_device_close(struct serdev_device *);
 int devm_serdev_device_open(struct device *, struct serdev_device *);
 unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int);
+void serdev_device_set_error_mask(struct serdev_device *, unsigned long);
 void serdev_device_set_flow_control(struct serdev_device *, bool);
 int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t);
 void serdev_device_wait_until_sent(struct serdev_device *, long);
@@ -238,6 +259,7 @@ static inline unsigned int serdev_device
 {
 	return 0;
 }
+static inline void serdev_device_set_error_mask(struct serdev_device *sdev, unsigned long mask) {}
 static inline void serdev_device_set_flow_control(struct serdev_device *sdev, bool enable) {}
 static inline int serdev_device_write_buf(struct serdev_device *serdev,
 					  const unsigned char *buf,
maintainer
#1 lore raw
Quoted 18 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Allow serdev device drivers get notified by hardware errors such as BREAK, FRAME, PARITY and OVERRUN.

With this patch, in the event of an error detected in the UART device driver the serdev_device_driver will get the newly introduced ->error() callback invoked if serdev_device_set_error_mask() has previously been used to enable the type of error. The errors are taken straight from the TTY layer and fed into the serdev_device_driver after filtering out only enabled errors.

Without this patch the hardware errors never reach the serdev_device_driver.

---

Applies to linux-5.16-rc4

Quoted 8 lines

Change since V1:
- Use __set_bit() instead of set_bit() in ttyport_receive_buf()
- Switch to assign_bit() in ttyport_set_error_mask()

Thanks to Geert for feedback!

The following prototype patch is using serdev error notifications:
[PATCH] r8a77995 Draak SCIF0 LED and KEY Serdev prototype V2

Looks good, now applied to my tty tree.

thanks,

greg k-h

#2 lore raw
Quoted 23 lines · Greg Kroah-Hartman
Quoted 22 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Allow serdev device drivers get notified by hardware errors such as BREAK, FRAME, PARITY and OVERRUN.

With this patch, in the event of an error detected in the UART device driver the serdev_device_driver will get the newly introduced ->error() callback invoked if serdev_device_set_error_mask() has previously been used to enable the type of error. The errors are taken straight from the TTY layer and fed into the serdev_device_driver after filtering out only enabled errors.

Without this patch the hardware errors never reach the serdev_device_driver.

---

Applies to linux-5.16-rc4

Change since V1:
- Use __set_bit() instead of set_bit() in ttyport_receive_buf()
- Switch to assign_bit() in ttyport_set_error_mask()

Quoted 6 lines
Quoted 4 lines

Thanks to Geert for feedback!

The following prototype patch is using serdev error notifications:
[PATCH] r8a77995 Draak SCIF0 LED and KEY Serdev prototype V2

Looks good, now applied to my tty tree.

I really don't think this is ready to be merged. There's been no discussion about the design of this interface and importantly there are no users (there was an RFC floating around but that one too has issues).

Some of the problems with this patch include:

- performance penalty for all serdev drivers due to unconditional per character processing
- flagged characters are still being forwarded to the consumer (e.g. NUL chars inserted on breaks)
- it only works with some broken serial drivers which do not honour TTY_DRIVER_REAL_RAW
- interface basically limited to the hacky led/input driver mentioned above since it does not match flags with characters

I suggest reverting for now.

Johan

maintainer
#3 lore raw
Quoted 46 lines · Johan Hovold
Quoted 23 lines · Greg Kroah-Hartman
Quoted 22 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Allow serdev device drivers get notified by hardware errors such as BREAK, FRAME, PARITY and OVERRUN.

With this patch, in the event of an error detected in the UART device driver the serdev_device_driver will get the newly introduced ->error() callback invoked if serdev_device_set_error_mask() has previously been used to enable the type of error. The errors are taken straight from the TTY layer and fed into the serdev_device_driver after filtering out only enabled errors.

Without this patch the hardware errors never reach the serdev_device_driver.

---

Applies to linux-5.16-rc4

Change since V1:
- Use __set_bit() instead of set_bit() in ttyport_receive_buf()
- Switch to assign_bit() in ttyport_set_error_mask()

Quoted 6 lines
Quoted 4 lines

Thanks to Geert for feedback!

The following prototype patch is using serdev error notifications:
[PATCH] r8a77995 Draak SCIF0 LED and KEY Serdev prototype V2

Looks good, now applied to my tty tree.

I really don't think this is ready to be merged. There's been no discussion about the design of this interface and importantly there are no users (there was an RFC floating around but that one too has issues).

Some of the problems with this patch include:

- performance penalty for all serdev drivers due to unconditional per character processing
- flagged characters are still being forwarded to the consumer (e.g. NUL chars inserted on breaks)
- it only works with some broken serial drivers which do not honour TTY_DRIVER_REAL_RAW
- interface basically limited to the hacky led/input driver mentioned above since it does not match flags with characters

Quoted 1 line

I suggest reverting for now.

No problem, will go revert it right now, thanks for looking at it.

greg k-h