Skip to contentSkip to conversation

Serial core controller port device name fixes

PATCH Superseded Tony Lindgren 2 participants 6 messages Jul 21, 2023 TTY layer and serial drivers

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Serial core controller port device name fixes

A few issues have been found with device naming for the serial core controller port device. These issues currently mostly affect the output for /sys/bus/serial-base/devices, but need to be also fixed to avoid port addressing issues later on.

Changes since v2:
- Fix my email script as it had started to drop linux-serial as noted by Greg

- Explain why we're changing ctrl_id as requested by Greg

Changes since v1:
- Port id cannot be negative as noted by Jiri

- Controller id cannot be negative as noted by Andy

- Port name is missing the controller instance as noted by Andy

Tony Lindgren (3):
serial: core: Controller id cannot be negative
serial: core: Fix serial core port id to not use port->line
serial: core: Fix serial core controller port name to show controller
id

 drivers/tty/serial/8250/8250_core.c  |  2 ++
 drivers/tty/serial/serial_base_bus.c | 33 ++++++++++++++++++----------
 include/linux/serial_core.h          |  3 ++-
 3 files changed, 25 insertions(+), 13 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v3 1/3 serial: core: Controller id cannot be negative

The controller id cannot be negative. Let's fix the ctrl_id in preparation for adding port port_id to fix the device name.

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 include/linux/serial_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/serial_core.h +1 -1
@@ -459,7 +459,7 @@ struct uart_port {
 						struct serial_rs485 *rs485);
 	int			(*iso7816_config)(struct uart_port *,
 						  struct serial_iso7816 *iso7816);
-	int			ctrl_id;		/* optional serial core controller id */
+	unsigned int		ctrl_id;		/* optional serial core controller id */
 	unsigned int		irq;			/* irq number */
 	unsigned long		irqflags;		/* irq flags  */
 	unsigned int		uartclk;		/* base uart clock */
Signature · 1 line
2.41.0
#2 lore raw

PATCH v3 2/3 serial: core: Fix serial core port id to not use port->line

In reply to Tony Lindgren

The serial core port id should be serial core controller specific port instance, which is not always the port->line index.

For example, 8250 driver maps a number of legacy ports, and when a hardware specific device driver takes over, we typically have one driver instance for each port. Let's instead add port->port_id to keep track serial ports mapped to each serial core controller instance.

Currently this is only a cosmetic issue for the serial core port device names. The issue can be noticed looking at /sys/bus/serial-base/devices for example though. Let's fix the issue to avoid port addressing issues later on.

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 drivers/tty/serial/8250/8250_core.c  | 2 ++
 drivers/tty/serial/serial_base_bus.c | 2 +-
 include/linux/serial_core.h          | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +2 -0
@@ -497,6 +497,7 @@ static struct uart_8250_port *serial8250_setup_port(int index)
 
 	up = &serial8250_ports[index];
 	up->port.line = index;
+	up->port.port_id = index;
 
 	serial8250_init_port(up);
 	if (!base_ops)
@@ -1040,6 +1041,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 			uart_remove_one_port(&serial8250_reg, &uart->port);
 
 		uart->port.ctrl_id	= up->port.ctrl_id;
+		uart->port.port_id	= up->port.port_id;
 		uart->port.iobase       = up->port.iobase;
 		uart->port.membase      = up->port.membase;
 		uart->port.irq          = up->port.irq;
drivers/tty/serial/serial_base_bus.c +1 -1
@@ -136,7 +136,7 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 	err = serial_base_device_init(port, &port_dev->dev,
 				      &ctrl_dev->dev, &serial_port_type,
 				      serial_base_port_release,
-				      port->line);
+				      port->port_id);
 	if (err)
 		goto err_put_device;
 
include/linux/serial_core.h +1 -0
@@ -460,6 +460,7 @@ struct uart_port {
 	int			(*iso7816_config)(struct uart_port *,
 						  struct serial_iso7816 *iso7816);
 	unsigned int		ctrl_id;		/* optional serial core controller id */
+	unsigned int		port_id;		/* optional serial core port id */
 	unsigned int		irq;			/* irq number */
 	unsigned long		irqflags;		/* irq flags  */
 	unsigned int		uartclk;		/* base uart clock */
Signature · 1 line
2.41.0
#3 lore raw

PATCH v3 3/3 serial: core: Fix serial core controller port name to show controller id

In reply to Tony Lindgren

We are missing the serial core controller id for the serial core port name. Let's fix the issue for sane /sys/bus/serial-core/devices, and to avoid issues addressing serial ports later on.

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 drivers/tty/serial/serial_base_bus.c | 33 ++++++++++++++++++----------
 1 file changed, 21 insertions(+), 12 deletions(-)
drivers/tty/serial/serial_base_bus.c +21 -12
@@ -19,6 +19,14 @@
 
 static bool serial_base_initialized;
 
+static const struct device_type serial_ctrl_type = {
+	.name = "ctrl",
+};
+
+static const struct device_type serial_port_type = {
+	.name = "port",
+};
+
 static int serial_base_match(struct device *dev, struct device_driver *drv)
 {
 	int len = strlen(drv->name);
@@ -48,7 +56,8 @@ static int serial_base_device_init(struct uart_port *port,
 				   struct device *parent_dev,
 				   const struct device_type *type,
 				   void (*release)(struct device *dev),
-				   int id)
+				   unsigned int ctrl_id,
+				   unsigned int port_id)
 {
 	device_initialize(dev);
 	dev->type = type;
@@ -61,13 +70,17 @@ static int serial_base_device_init(struct uart_port *port,
 		return -EPROBE_DEFER;
 	}
 
-	return dev_set_name(dev, "%s.%s.%d", type->name, dev_name(port->dev), id);
+	if (type == &serial_ctrl_type)
+		return dev_set_name(dev, "%s.%s.%d", type->name,
+				    dev_name(port->dev), ctrl_id);
+	else if (type == &serial_port_type)
+		return dev_set_name(dev, "%s.%s.%d.%d", type->name,
+				    dev_name(port->dev), ctrl_id,
+				    port_id);
+	else
+		return -EINVAL;
 }
 
-static const struct device_type serial_ctrl_type = {
-	.name = "ctrl",
-};
-
 static void serial_base_ctrl_release(struct device *dev)
 {
 	struct serial_ctrl_device *ctrl_dev = to_serial_base_ctrl_device(dev);
@@ -96,7 +109,7 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
 	err = serial_base_device_init(port, &ctrl_dev->dev,
 				      parent, &serial_ctrl_type,
 				      serial_base_ctrl_release,
-				      port->ctrl_id);
+				      port->ctrl_id, 0);
 	if (err)
 		goto err_put_device;
 
@@ -112,10 +125,6 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
 	return ERR_PTR(err);
 }
 
-static const struct device_type serial_port_type = {
-	.name = "port",
-};
-
 static void serial_base_port_release(struct device *dev)
 {
 	struct serial_port_device *port_dev = to_serial_base_port_device(dev);
@@ -136,7 +145,7 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 	err = serial_base_device_init(port, &port_dev->dev,
 				      &ctrl_dev->dev, &serial_port_type,
 				      serial_base_port_release,
-				      port->port_id);
+				      port->ctrl_id, port->port_id);
 	if (err)
 		goto err_put_device;
 
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH v3 3/3] serial: core: Fix serial core controller port name to show controller id

Quoted 3 lines · Tony Lindgren

We are missing the serial core controller id for the serial core port name. Let's fix the issue for sane /sys/bus/serial-core/devices, and to avoid issues addressing serial ports later on.

...

drivers/tty/serial/serial_base_bus.c static int serial_base_device_init(struct uart_port *port, · line 80

Quoted 8 lines
drivers/tty/serial/serial_base_bus.c +7 -0
+	if (type == &serial_ctrl_type)
+		return dev_set_name(dev, "%s.%s.%d", type->name,
 
+	else if (type == &serial_port_type)
+		return dev_set_name(dev, "%s.%s.%d.%d", type->name,
+				    dev_name(port->dev), ctrl_id,
+				    port_id);
+	else

Redundant 'else' in both cases.

Quoted 1 line
drivers/tty/serial/serial_base_bus.c +1 -0
+		return -EINVAL;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on the v3 series
#5 lore raw
In reply to Tony Lindgren
Quoted 4 lines · Tony Lindgren

A few issues have been found with device naming for the serial core controller port device. These issues currently mostly affect the output for /sys/bus/serial-base/devices, but need to be also fixed to avoid port addressing issues later on.

With the addressed change,

for the entire series, good fixes!

Signature · 2 lines
With Best Regards,
Andy Shevchenko