* [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
@ 2024-08-15 12:59 Vadim Fedorenko
2024-08-15 12:59 ` [PATCH net v3 2/2] docs: ABI: update OCP TimeCard sysfs entries Vadim Fedorenko
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2024-08-15 12:59 UTC (permalink / raw)
To: Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon, Jiri Slaby,
Greg Kroah-Hartman
Cc: Vadim Fedorenko, netdev
Starting v6.8 the serial port subsystem changed the hierarchy of devices
and symlinks are not working anymore. Previous discussion made it clear
that the idea of symlinks for tty devices was wrong by design. Implement
additional attributes to expose the information. Fixes tag points to the
commit which introduced the change.
Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
---
v2 -> v3:
- replace serial ports definitions with array and enum for index
- replace pointer math with direct array access
- nit in documentation spelling
v1 -> v2:
- add Documentation/ABI changes
---
drivers/ptp/ptp_ocp.c | 158 +++++++++++++++++++++++++-----------------
1 file changed, 96 insertions(+), 62 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index ee2ced88ab34..7d50b49bf684 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -316,6 +316,15 @@ struct ptp_ocp_serial_port {
#define OCP_SERIAL_LEN 6
#define OCP_SMA_NUM 4
+enum {
+ PORT_GNSS,
+ PORT_GNSS2,
+ PORT_MAC, /* miniature atomic clock */
+ PORT_NMEA,
+
+ PORT_NUM_MAX
+};
+
struct ptp_ocp {
struct pci_dev *pdev;
struct device dev;
@@ -357,10 +366,7 @@ struct ptp_ocp {
struct delayed_work sync_work;
int id;
int n_irqs;
- struct ptp_ocp_serial_port gnss_port;
- struct ptp_ocp_serial_port gnss2_port;
- struct ptp_ocp_serial_port mac_port; /* miniature atomic clock */
- struct ptp_ocp_serial_port nmea_port;
+ struct ptp_ocp_serial_port port[PORT_NUM_MAX];
bool fw_loader;
u8 fw_tag;
u16 fw_version;
@@ -655,28 +661,28 @@ static struct ocp_resource ocp_fb_resource[] = {
},
},
{
- OCP_SERIAL_RESOURCE(gnss_port),
+ OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 115200,
},
},
{
- OCP_SERIAL_RESOURCE(gnss2_port),
+ OCP_SERIAL_RESOURCE(port[PORT_GNSS2]),
.offset = 0x00170000 + 0x1000, .irq_vec = 4,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 115200,
},
},
{
- OCP_SERIAL_RESOURCE(mac_port),
+ OCP_SERIAL_RESOURCE(port[PORT_MAC]),
.offset = 0x00180000 + 0x1000, .irq_vec = 5,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 57600,
},
},
{
- OCP_SERIAL_RESOURCE(nmea_port),
+ OCP_SERIAL_RESOURCE(port[PORT_NMEA]),
.offset = 0x00190000 + 0x1000, .irq_vec = 10,
},
{
@@ -740,7 +746,7 @@ static struct ocp_resource ocp_art_resource[] = {
.offset = 0x01000000, .size = 0x10000,
},
{
- OCP_SERIAL_RESOURCE(gnss_port),
+ OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 115200,
@@ -839,7 +845,7 @@ static struct ocp_resource ocp_art_resource[] = {
},
},
{
- OCP_SERIAL_RESOURCE(mac_port),
+ OCP_SERIAL_RESOURCE(port[PORT_MAC]),
.offset = 0x00190000, .irq_vec = 7,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 9600,
@@ -950,14 +956,14 @@ static struct ocp_resource ocp_adva_resource[] = {
.offset = 0x00220000, .size = 0x1000,
},
{
- OCP_SERIAL_RESOURCE(gnss_port),
+ OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 9600,
},
},
{
- OCP_SERIAL_RESOURCE(mac_port),
+ OCP_SERIAL_RESOURCE(port[PORT_MAC]),
.offset = 0x00180000 + 0x1000, .irq_vec = 5,
.extra = &(struct ptp_ocp_serial_port) {
.baud = 115200,
@@ -3346,6 +3352,54 @@ static EXT_ATTR_RO(freq, frequency, 1);
static EXT_ATTR_RO(freq, frequency, 2);
static EXT_ATTR_RO(freq, frequency, 3);
+static ssize_t
+ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct dev_ext_attribute *ea = to_ext_attr(attr);
+ struct ptp_ocp *bp = dev_get_drvdata(dev);
+ struct ptp_ocp_serial_port *port;
+
+ return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
+}
+
+static umode_t
+ptp_ocp_timecard_tty_is_visible(struct kobject *kobj, struct attribute *attr, int n)
+{
+ struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj));
+ struct ptp_ocp_serial_port *port;
+ struct device_attribute *dattr;
+ struct dev_ext_attribute *ea;
+
+ if (strncmp(attr->name, "tty", 3))
+ return attr->mode;
+
+ dattr = container_of(attr, struct device_attribute, attr);
+ ea = container_of(dattr, struct dev_ext_attribute, attr);
+ port = &bp->port[(uintptr_t)ea->var];
+ return port->line == -1 ? 0 : 0444;
+}
+#define EXT_TTY_ATTR_RO(_name, _val) \
+ struct dev_ext_attribute dev_attr_tty##_name = \
+ { __ATTR(tty##_name, 0444, ptp_ocp_tty_show, NULL), (void *)_val }
+
+static EXT_TTY_ATTR_RO(GNSS, PORT_GNSS);
+static EXT_TTY_ATTR_RO(GNSS2, PORT_GNSS2);
+static EXT_TTY_ATTR_RO(MAC, PORT_MAC);
+static EXT_TTY_ATTR_RO(NMEA, PORT_NMEA);
+static struct attribute *ptp_ocp_timecard_tty_attrs[] = {
+ &dev_attr_ttyGNSS.attr.attr,
+ &dev_attr_ttyGNSS2.attr.attr,
+ &dev_attr_ttyMAC.attr.attr,
+ &dev_attr_ttyNMEA.attr.attr,
+ NULL,
+};
+
+static const struct attribute_group ptp_ocp_timecard_tty_group = {
+ .name = "tty",
+ .attrs = ptp_ocp_timecard_tty_attrs,
+ .is_visible = ptp_ocp_timecard_tty_is_visible,
+};
+
static ssize_t
serialnum_show(struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -3775,6 +3829,7 @@ static const struct attribute_group fb_timecard_group = {
static const struct ocp_attr_group fb_timecard_groups[] = {
{ .cap = OCP_CAP_BASIC, .group = &fb_timecard_group },
+ { .cap = OCP_CAP_BASIC, .group = &ptp_ocp_timecard_tty_group },
{ .cap = OCP_CAP_SIGNAL, .group = &fb_timecard_signal0_group },
{ .cap = OCP_CAP_SIGNAL, .group = &fb_timecard_signal1_group },
{ .cap = OCP_CAP_SIGNAL, .group = &fb_timecard_signal2_group },
@@ -3814,6 +3869,7 @@ static const struct attribute_group art_timecard_group = {
static const struct ocp_attr_group art_timecard_groups[] = {
{ .cap = OCP_CAP_BASIC, .group = &art_timecard_group },
+ { .cap = OCP_CAP_BASIC, .group = &ptp_ocp_timecard_tty_group },
{ },
};
@@ -3841,6 +3897,7 @@ static const struct attribute_group adva_timecard_group = {
static const struct ocp_attr_group adva_timecard_groups[] = {
{ .cap = OCP_CAP_BASIC, .group = &adva_timecard_group },
+ { .cap = OCP_CAP_BASIC, .group = &ptp_ocp_timecard_tty_group },
{ .cap = OCP_CAP_SIGNAL, .group = &fb_timecard_signal0_group },
{ .cap = OCP_CAP_SIGNAL, .group = &fb_timecard_signal1_group },
{ .cap = OCP_CAP_FREQ, .group = &fb_timecard_freq0_group },
@@ -3960,16 +4017,16 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)
bp = dev_get_drvdata(dev);
seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp));
- if (bp->gnss_port.line != -1)
+ if (bp->port[PORT_GNSS].line != -1)
seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1",
- bp->gnss_port.line);
- if (bp->gnss2_port.line != -1)
+ bp->port[PORT_GNSS].line);
+ if (bp->port[PORT_GNSS2].line != -1)
seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2",
- bp->gnss2_port.line);
- if (bp->mac_port.line != -1)
- seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port.line);
- if (bp->nmea_port.line != -1)
- seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port.line);
+ bp->port[PORT_GNSS2].line);
+ if (bp->port[PORT_MAC].line != -1)
+ seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->port[PORT_MAC].line);
+ if (bp->port[PORT_NMEA].line != -1)
+ seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->port[PORT_NMEA].line);
memset(sma_val, 0xff, sizeof(sma_val));
if (bp->sma_map1) {
@@ -4279,7 +4336,7 @@ ptp_ocp_dev_release(struct device *dev)
static int
ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
{
- int err;
+ int i, err;
mutex_lock(&ptp_ocp_lock);
err = idr_alloc(&ptp_ocp_idr, bp, 0, 0, GFP_KERNEL);
@@ -4292,10 +4349,10 @@ ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
bp->ptp_info = ptp_ocp_clock_info;
spin_lock_init(&bp->lock);
- bp->gnss_port.line = -1;
- bp->gnss2_port.line = -1;
- bp->mac_port.line = -1;
- bp->nmea_port.line = -1;
+
+ for (i = 0; i < PORT_NUM_MAX; i++)
+ bp->port[i].line = -1;
+
bp->pdev = pdev;
device_initialize(&bp->dev);
@@ -4352,22 +4409,6 @@ ptp_ocp_complete(struct ptp_ocp *bp)
struct pps_device *pps;
char buf[32];
- if (bp->gnss_port.line != -1) {
- sprintf(buf, "ttyS%d", bp->gnss_port.line);
- ptp_ocp_link_child(bp, buf, "ttyGNSS");
- }
- if (bp->gnss2_port.line != -1) {
- sprintf(buf, "ttyS%d", bp->gnss2_port.line);
- ptp_ocp_link_child(bp, buf, "ttyGNSS2");
- }
- if (bp->mac_port.line != -1) {
- sprintf(buf, "ttyS%d", bp->mac_port.line);
- ptp_ocp_link_child(bp, buf, "ttyMAC");
- }
- if (bp->nmea_port.line != -1) {
- sprintf(buf, "ttyS%d", bp->nmea_port.line);
- ptp_ocp_link_child(bp, buf, "ttyNMEA");
- }
sprintf(buf, "ptp%d", ptp_clock_index(bp->ptp));
ptp_ocp_link_child(bp, buf, "ptp");
@@ -4419,20 +4460,21 @@ ptp_ocp_info(struct ptp_ocp *bp)
ptp_ocp_phc_info(bp);
- ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port.line,
- bp->gnss_port.baud);
- ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port.line,
- bp->gnss2_port.baud);
- ptp_ocp_serial_info(dev, "MAC", bp->mac_port.line, bp->mac_port.baud);
- if (bp->nmea_out && bp->nmea_port.line != -1) {
- bp->nmea_port.baud = -1;
+ ptp_ocp_serial_info(dev, "GNSS", bp->port[PORT_GNSS].line,
+ bp->port[PORT_GNSS].baud);
+ ptp_ocp_serial_info(dev, "GNSS2", bp->port[PORT_GNSS2].line,
+ bp->port[PORT_GNSS2].baud);
+ ptp_ocp_serial_info(dev, "MAC", bp->port[PORT_MAC].line,
+ bp->port[PORT_MAC].baud);
+ if (bp->nmea_out && bp->port[PORT_NMEA].line != -1) {
+ bp->port[PORT_NMEA].baud = -1;
reg = ioread32(&bp->nmea_out->uart_baud);
if (reg < ARRAY_SIZE(nmea_baud))
- bp->nmea_port.baud = nmea_baud[reg];
+ bp->port[PORT_NMEA].baud = nmea_baud[reg];
- ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port.line,
- bp->nmea_port.baud);
+ ptp_ocp_serial_info(dev, "NMEA", bp->port[PORT_NMEA].line,
+ bp->port[PORT_NMEA].baud);
}
}
@@ -4441,9 +4483,6 @@ ptp_ocp_detach_sysfs(struct ptp_ocp *bp)
{
struct device *dev = &bp->dev;
- sysfs_remove_link(&dev->kobj, "ttyGNSS");
- sysfs_remove_link(&dev->kobj, "ttyGNSS2");
- sysfs_remove_link(&dev->kobj, "ttyMAC");
sysfs_remove_link(&dev->kobj, "ptp");
sysfs_remove_link(&dev->kobj, "pps");
}
@@ -4473,14 +4512,9 @@ ptp_ocp_detach(struct ptp_ocp *bp)
for (i = 0; i < 4; i++)
if (bp->signal_out[i])
ptp_ocp_unregister_ext(bp->signal_out[i]);
- if (bp->gnss_port.line != -1)
- serial8250_unregister_port(bp->gnss_port.line);
- if (bp->gnss2_port.line != -1)
- serial8250_unregister_port(bp->gnss2_port.line);
- if (bp->mac_port.line != -1)
- serial8250_unregister_port(bp->mac_port.line);
- if (bp->nmea_port.line != -1)
- serial8250_unregister_port(bp->nmea_port.line);
+ for (i = 0; i < PORT_NUM_MAX; i++)
+ if (bp->port[i].line != -1)
+ serial8250_unregister_port(bp->port[i].line);
platform_device_unregister(bp->spi_flash);
platform_device_unregister(bp->i2c_ctrl);
if (bp->i2c_clk)
--
2.43.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net v3 2/2] docs: ABI: update OCP TimeCard sysfs entries
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
@ 2024-08-15 12:59 ` Vadim Fedorenko
2024-08-15 13:41 ` [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Greg Kroah-Hartman
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2024-08-15 12:59 UTC (permalink / raw)
To: Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon, Jiri Slaby,
Greg Kroah-Hartman
Cc: Vadim Fedorenko, netdev
Update documentation according to the changes in the driver.
New attributes group tty is exposed and ttyGNSS, ttyGNSS2, ttyMAC and
ttyNMEA are moved to this group. Also, these attributes are no more
links to the devices but rather simple text files containing names of
tty devices.
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
---
Documentation/ABI/testing/sysfs-timecard | 31 ++++++++++++++----------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-timecard b/Documentation/ABI/testing/sysfs-timecard
index 220478156297..3ae41b7634ac 100644
--- a/Documentation/ABI/testing/sysfs-timecard
+++ b/Documentation/ABI/testing/sysfs-timecard
@@ -258,24 +258,29 @@ Description: (RW) When retrieving the PHC with the PTP SYS_OFFSET_EXTENDED
the estimated point where the FPGA latches the PHC time. This
value may be changed by writing an unsigned integer.
-What: /sys/class/timecard/ocpN/ttyGNSS
-What: /sys/class/timecard/ocpN/ttyGNSS2
-Date: September 2021
+What: /sys/class/timecard/ocpN/tty
+Date: August 2024
+Contact: Vadim Fedorenko <vadim.fedorenko@linux.dev>
+Description: (RO) Directory containing the sysfs nodes for TTY attributes
+
+What: /sys/class/timecard/ocpN/tty/ttyGNSS
+What: /sys/class/timecard/ocpN/tty/ttyGNSS2
+Date: August 2024
Contact: Jonathan Lemon <jonathan.lemon@gmail.com>
-Description: These optional attributes link to the TTY serial ports
- associated with the GNSS devices.
+Description: (RO) These optional attributes contain names of the TTY serial
+ ports associated with the GNSS devices.
-What: /sys/class/timecard/ocpN/ttyMAC
-Date: September 2021
+What: /sys/class/timecard/ocpN/tty/ttyMAC
+Date: August 2024
Contact: Jonathan Lemon <jonathan.lemon@gmail.com>
-Description: This optional attribute links to the TTY serial port
- associated with the Miniature Atomic Clock.
+Description: (RO) This optional attribute contains name of the TTY serial
+ port associated with the Miniature Atomic Clock.
-What: /sys/class/timecard/ocpN/ttyNMEA
-Date: September 2021
+What: /sys/class/timecard/ocpN/tty/ttyNMEA
+Date: August 2024
Contact: Jonathan Lemon <jonathan.lemon@gmail.com>
-Description: This optional attribute links to the TTY serial port
- which outputs the PHC time in NMEA ZDA format.
+Description: (RO) This optional attribute contains name of the TTY serial
+ port which outputs the PHC time in NMEA ZDA format.
What: /sys/class/timecard/ocpN/utc_tai_offset
Date: September 2021
--
2.43.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
2024-08-15 12:59 ` [PATCH net v3 2/2] docs: ABI: update OCP TimeCard sysfs entries Vadim Fedorenko
@ 2024-08-15 13:41 ` Greg Kroah-Hartman
2024-08-15 15:06 ` Vadim Fedorenko
2024-08-15 13:54 ` Simon Horman
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2024-08-15 13:41 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon, Jiri Slaby,
netdev
On Thu, Aug 15, 2024 at 05:59:04AM -0700, Vadim Fedorenko wrote:
> Starting v6.8 the serial port subsystem changed the hierarchy of devices
> and symlinks are not working anymore. Previous discussion made it clear
> that the idea of symlinks for tty devices was wrong by design. Implement
> additional attributes to expose the information. Fixes tag points to the
> commit which introduced the change.
>
> Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Complicated fixes, nice! Thanks for doing this. One question:
> +static ssize_t
> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct dev_ext_attribute *ea = to_ext_attr(attr);
> + struct ptp_ocp *bp = dev_get_drvdata(dev);
> + struct ptp_ocp_serial_port *port;
> +
> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
"uintptr_t"? That's not a normal kernel type. var is of type "void *"
so can't this just be "int" here? Or am I reading this wrong?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
2024-08-15 12:59 ` [PATCH net v3 2/2] docs: ABI: update OCP TimeCard sysfs entries Vadim Fedorenko
2024-08-15 13:41 ` [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Greg Kroah-Hartman
@ 2024-08-15 13:54 ` Simon Horman
2024-08-15 14:05 ` Vadim Fedorenko
2024-08-16 5:26 ` Jiri Slaby
2024-08-16 12:03 ` kernel test robot
4 siblings, 1 reply; 9+ messages in thread
From: Simon Horman @ 2024-08-15 13:54 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon, Jiri Slaby,
Greg Kroah-Hartman, netdev
On Thu, Aug 15, 2024 at 05:59:04AM -0700, Vadim Fedorenko wrote:
> Starting v6.8 the serial port subsystem changed the hierarchy of devices
> and symlinks are not working anymore. Previous discussion made it clear
> that the idea of symlinks for tty devices was wrong by design. Implement
> additional attributes to expose the information. Fixes tag points to the
> commit which introduced the change.
Hi Vadim,
Would it be possible to provide a link to the discussion(s)?
>
> Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
...
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
...
> @@ -3346,6 +3352,54 @@ static EXT_ATTR_RO(freq, frequency, 1);
> static EXT_ATTR_RO(freq, frequency, 2);
> static EXT_ATTR_RO(freq, frequency, 3);
>
> +static ssize_t
> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct dev_ext_attribute *ea = to_ext_attr(attr);
> + struct ptp_ocp *bp = dev_get_drvdata(dev);
> + struct ptp_ocp_serial_port *port;
nit: Port is unused in this function, it should be removed.
> +
> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
> +}
...
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 13:54 ` Simon Horman
@ 2024-08-15 14:05 ` Vadim Fedorenko
0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2024-08-15 14:05 UTC (permalink / raw)
To: Simon Horman, Vadim Fedorenko
Cc: Jakub Kicinski, Jonathan Lemon, Jiri Slaby, Greg Kroah-Hartman,
netdev
On 15/08/2024 14:54, Simon Horman wrote:
> On Thu, Aug 15, 2024 at 05:59:04AM -0700, Vadim Fedorenko wrote:
>> Starting v6.8 the serial port subsystem changed the hierarchy of devices
>> and symlinks are not working anymore. Previous discussion made it clear
>> that the idea of symlinks for tty devices was wrong by design. Implement
>> additional attributes to expose the information. Fixes tag points to the
>> commit which introduced the change.
>
> Hi Vadim,
>
> Would it be possible to provide a link to the discussion(s)?
>
Hi Simon,
Yeah, sure:
the initial RFC of serial port subsystem changes is
https://lore.kernel.org/linux-serial/20231024113624.54364-1-tony@atomide.com/
the merged version is (serial port subsystem):
https://lore.kernel.org/linux-serial/20231113080758.30346-1-tony@atomide.com/
The first update to ptp_ocp driver is
https://lore.kernel.org/linux-serial/20240510110405.15115-1-vadim.fedorenko@linux.dev/
>>
>> Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
>> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
>
> ...
>
>> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
>
> ...
>
>> @@ -3346,6 +3352,54 @@ static EXT_ATTR_RO(freq, frequency, 1);
>> static EXT_ATTR_RO(freq, frequency, 2);
>> static EXT_ATTR_RO(freq, frequency, 3);
>>
>> +static ssize_t
>> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
>> +{
>> + struct dev_ext_attribute *ea = to_ext_attr(attr);
>> + struct ptp_ocp *bp = dev_get_drvdata(dev);
>> + struct ptp_ocp_serial_port *port;
>
> nit: Port is unused in this function, it should be removed.
Ah, yeah, it was last second change, didn't clean it fully,
thanks for pointing.
>
>> +
>> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
>> +}
>
> ...
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 13:41 ` [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Greg Kroah-Hartman
@ 2024-08-15 15:06 ` Vadim Fedorenko
0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2024-08-15 15:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Vadim Fedorenko
Cc: Jakub Kicinski, Jonathan Lemon, Jiri Slaby, netdev
On 15/08/2024 14:41, Greg Kroah-Hartman wrote:
> On Thu, Aug 15, 2024 at 05:59:04AM -0700, Vadim Fedorenko wrote:
>> Starting v6.8 the serial port subsystem changed the hierarchy of devices
>> and symlinks are not working anymore. Previous discussion made it clear
>> that the idea of symlinks for tty devices was wrong by design. Implement
>> additional attributes to expose the information. Fixes tag points to the
>> commit which introduced the change.
>>
>> Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
>> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
>
> Complicated fixes, nice! Thanks for doing this. One question:
>
>> +static ssize_t
>> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
>> +{
>> + struct dev_ext_attribute *ea = to_ext_attr(attr);
>> + struct ptp_ocp *bp = dev_get_drvdata(dev);
>> + struct ptp_ocp_serial_port *port;
>> +
>> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
>
> "uintptr_t"? That's not a normal kernel type. var is of type "void *"
> so can't this just be "int" here? Or am I reading this wrong?
Well, yes, looks like it can be used as pure int provided enum is int
and we simply use "void *" as a transport.
I'll send v4 with this fix and the one Simon pointed in 24hr (as per
netdev policy).
Thanks!
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
` (2 preceding siblings ...)
2024-08-15 13:54 ` Simon Horman
@ 2024-08-16 5:26 ` Jiri Slaby
2024-08-16 18:48 ` Vadim Fedorenko
2024-08-16 12:03 ` kernel test robot
4 siblings, 1 reply; 9+ messages in thread
From: Jiri Slaby @ 2024-08-16 5:26 UTC (permalink / raw)
To: Vadim Fedorenko, Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon,
Greg Kroah-Hartman
Cc: netdev
On 15. 08. 24, 14:59, Vadim Fedorenko wrote:
> Starting v6.8 the serial port subsystem changed the hierarchy of devices
> and symlinks are not working anymore. Previous discussion made it clear
> that the idea of symlinks for tty devices was wrong by design.
Care to link it here?
> Implement
> additional attributes to expose the information. Fixes tag points to the
> commit which introduced the change.
...
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -316,6 +316,15 @@ struct ptp_ocp_serial_port {
> #define OCP_SERIAL_LEN 6
> #define OCP_SMA_NUM 4
>
> +enum {
> + PORT_GNSS,
> + PORT_GNSS2,
> + PORT_MAC, /* miniature atomic clock */
> + PORT_NMEA,
> +
> + PORT_NUM_MAX
> +};
> +
The conversion to the array needs to go to a separate patch, apparently.
> +static ssize_t
> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct dev_ext_attribute *ea = to_ext_attr(attr);
> + struct ptp_ocp *bp = dev_get_drvdata(dev);
> + struct ptp_ocp_serial_port *port;
> +
> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
uintptr_t is unusual as Greg points out. It is a correct type per C99 to
cast from/to pointers, but we usually do "unsigned long". (int wouldn't
work as it has a different size (on 64bit).)
But looking at the code, uintptr_t is used all over. So perhaps use that
to be consistent?
> @@ -3960,16 +4017,16 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)
> bp = dev_get_drvdata(dev);
>
> seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp));
> - if (bp->gnss_port.line != -1)
> + if (bp->port[PORT_GNSS].line != -1)
> seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1",
> - bp->gnss_port.line);
> - if (bp->gnss2_port.line != -1)
> + bp->port[PORT_GNSS].line);
> + if (bp->port[PORT_GNSS2].line != -1)
> seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2",
> - bp->gnss2_port.line);
> - if (bp->mac_port.line != -1)
> - seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port.line);
> - if (bp->nmea_port.line != -1)
> - seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port.line);
> + bp->port[PORT_GNSS2].line);
> + if (bp->port[PORT_MAC].line != -1)
> + seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->port[PORT_MAC].line);
> + if (bp->port[PORT_NMEA].line != -1)
> + seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->port[PORT_NMEA].line);
Perhaps you can introduce some to_name() function (mapping enum -> const
char *)? Can this code be then a three-line for loop?
> @@ -4419,20 +4460,21 @@ ptp_ocp_info(struct ptp_ocp *bp)
>
> ptp_ocp_phc_info(bp);
>
> - ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port.line,
> - bp->gnss_port.baud);
> - ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port.line,
> - bp->gnss2_port.baud);
> - ptp_ocp_serial_info(dev, "MAC", bp->mac_port.line, bp->mac_port.baud);
> - if (bp->nmea_out && bp->nmea_port.line != -1) {
> - bp->nmea_port.baud = -1;
> + ptp_ocp_serial_info(dev, "GNSS", bp->port[PORT_GNSS].line,
> + bp->port[PORT_GNSS].baud);
> + ptp_ocp_serial_info(dev, "GNSS2", bp->port[PORT_GNSS2].line,
> + bp->port[PORT_GNSS2].baud);
> + ptp_ocp_serial_info(dev, "MAC", bp->port[PORT_MAC].line,
> + bp->port[PORT_MAC].baud);
> + if (bp->nmea_out && bp->port[PORT_NMEA].line != -1) {
> + bp->port[PORT_NMEA].baud = -1;
>
> reg = ioread32(&bp->nmea_out->uart_baud);
> if (reg < ARRAY_SIZE(nmea_baud))
> - bp->nmea_port.baud = nmea_baud[reg];
> + bp->port[PORT_NMEA].baud = nmea_baud[reg];
>
> - ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port.line,
> - bp->nmea_port.baud);
> + ptp_ocp_serial_info(dev, "NMEA", bp->port[PORT_NMEA].line,
> + bp->port[PORT_NMEA].baud);
Maybe even here with if (iterator == PORT_NMEA)?
--
js
suse labs
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
` (3 preceding siblings ...)
2024-08-16 5:26 ` Jiri Slaby
@ 2024-08-16 12:03 ` kernel test robot
4 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2024-08-16 12:03 UTC (permalink / raw)
To: Vadim Fedorenko, Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon,
Jiri Slaby, Greg Kroah-Hartman
Cc: oe-kbuild-all, netdev
Hi Vadim,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/docs-ABI-update-OCP-TimeCard-sysfs-entries/20240815-210131
base: net/main
patch link: https://lore.kernel.org/r/20240815125905.1667148-1-vadfed%40meta.com
patch subject: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20240816/202408161934.aQsUDy88-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240816/202408161934.aQsUDy88-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408161934.aQsUDy88-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/ptp/ptp_ocp.c: In function 'ptp_ocp_tty_show':
>> drivers/ptp/ptp_ocp.c:3360:37: warning: unused variable 'port' [-Wunused-variable]
3360 | struct ptp_ocp_serial_port *port;
| ^~~~
vim +/port +3360 drivers/ptp/ptp_ocp.c
3354
3355 static ssize_t
3356 ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
3357 {
3358 struct dev_ext_attribute *ea = to_ext_attr(attr);
3359 struct ptp_ocp *bp = dev_get_drvdata(dev);
> 3360 struct ptp_ocp_serial_port *port;
3361
3362 return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
3363 }
3364
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information
2024-08-16 5:26 ` Jiri Slaby
@ 2024-08-16 18:48 ` Vadim Fedorenko
0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2024-08-16 18:48 UTC (permalink / raw)
To: Jiri Slaby, Vadim Fedorenko, Jakub Kicinski, Jonathan Lemon,
Greg Kroah-Hartman
Cc: netdev
On 16/08/2024 06:26, Jiri Slaby wrote:
> On 15. 08. 24, 14:59, Vadim Fedorenko wrote:
>> Starting v6.8 the serial port subsystem changed the hierarchy of devices
>> and symlinks are not working anymore. Previous discussion made it clear
>> that the idea of symlinks for tty devices was wrong by design.
>
> Care to link it here?
Sure, with the next version.
>
>> Implement
>> additional attributes to expose the information. Fixes tag points to the
>> commit which introduced the change.
> ...
>> --- a/drivers/ptp/ptp_ocp.c
>> +++ b/drivers/ptp/ptp_ocp.c
>> @@ -316,6 +316,15 @@ struct ptp_ocp_serial_port {
>> #define OCP_SERIAL_LEN 6
>> #define OCP_SMA_NUM 4
>> +enum {
>> + PORT_GNSS,
>> + PORT_GNSS2,
>> + PORT_MAC, /* miniature atomic clock */
>> + PORT_NMEA,
>> +
>> + PORT_NUM_MAX
>> +};
>> +
>
> The conversion to the array needs to go to a separate patch, apparently.
I'm not sure here. I'm trying to fix the regression introduced back in
6.8. The conversion to the array itself doesn't solve the issue, it's
pure net-next material. But the simple fix was NACKed previously, that's
why I had to introduce such a big change. I would like to keep these
changes all together in one patch.
>
>> +static ssize_t
>> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr,
>> char *buf)
>> +{
>> + struct dev_ext_attribute *ea = to_ext_attr(attr);
>> + struct ptp_ocp *bp = dev_get_drvdata(dev);
>> + struct ptp_ocp_serial_port *port;
>> +
>> + return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line);
>
> uintptr_t is unusual as Greg points out. It is a correct type per C99 to
> cast from/to pointers, but we usually do "unsigned long". (int wouldn't
> work as it has a different size (on 64bit).)
>
> But looking at the code, uintptr_t is used all over. So perhaps use that
> to be consistent?
so, now I'm lost. I'm ok with both options, just let me know which one
will have no objections to be merged...
>
>> @@ -3960,16 +4017,16 @@ ptp_ocp_summary_show(struct seq_file *s, void
>> *data)
>> bp = dev_get_drvdata(dev);
>> seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp-
>> >ptp));
>> - if (bp->gnss_port.line != -1)
>> + if (bp->port[PORT_GNSS].line != -1)
>> seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1",
>> - bp->gnss_port.line);
>> - if (bp->gnss2_port.line != -1)
>> + bp->port[PORT_GNSS].line);
>> + if (bp->port[PORT_GNSS2].line != -1)
>> seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2",
>> - bp->gnss2_port.line);
>> - if (bp->mac_port.line != -1)
>> - seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port.line);
>> - if (bp->nmea_port.line != -1)
>> - seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port.line);
>> + bp->port[PORT_GNSS2].line);
>> + if (bp->port[PORT_MAC].line != -1)
>> + seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp-
>> >port[PORT_MAC].line);
>> + if (bp->port[PORT_NMEA].line != -1)
>> + seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp-
>> >port[PORT_NMEA].line);
>
> Perhaps you can introduce some to_name() function (mapping enum -> const
> char *)? Can this code be then a three-line for loop?
yeah, I can do it, for sure.
>
>> @@ -4419,20 +4460,21 @@ ptp_ocp_info(struct ptp_ocp *bp)
>> ptp_ocp_phc_info(bp);
>> - ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port.line,
>> - bp->gnss_port.baud);
>> - ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port.line,
>> - bp->gnss2_port.baud);
>> - ptp_ocp_serial_info(dev, "MAC", bp->mac_port.line, bp-
>> >mac_port.baud);
>> - if (bp->nmea_out && bp->nmea_port.line != -1) {
>> - bp->nmea_port.baud = -1;
>> + ptp_ocp_serial_info(dev, "GNSS", bp->port[PORT_GNSS].line,
>> + bp->port[PORT_GNSS].baud);
>> + ptp_ocp_serial_info(dev, "GNSS2", bp->port[PORT_GNSS2].line,
>> + bp->port[PORT_GNSS2].baud);
>> + ptp_ocp_serial_info(dev, "MAC", bp->port[PORT_MAC].line,
>> + bp->port[PORT_MAC].baud);
>> + if (bp->nmea_out && bp->port[PORT_NMEA].line != -1) {
>> + bp->port[PORT_NMEA].baud = -1;
>> reg = ioread32(&bp->nmea_out->uart_baud);
>> if (reg < ARRAY_SIZE(nmea_baud))
>> - bp->nmea_port.baud = nmea_baud[reg];
>> + bp->port[PORT_NMEA].baud = nmea_baud[reg];
>> - ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port.line,
>> - bp->nmea_port.baud);
>> + ptp_ocp_serial_info(dev, "NMEA", bp->port[PORT_NMEA].line,
>> + bp->port[PORT_NMEA].baud);
>
> Maybe even here with if (iterator == PORT_NMEA)?
>
Should be ok, will make it in the next revision.
Thanks,
Vadim
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-08-16 18:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15 12:59 [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Vadim Fedorenko
2024-08-15 12:59 ` [PATCH net v3 2/2] docs: ABI: update OCP TimeCard sysfs entries Vadim Fedorenko
2024-08-15 13:41 ` [PATCH net v3 1/2] ptp: ocp: adjust sysfs entries to expose tty information Greg Kroah-Hartman
2024-08-15 15:06 ` Vadim Fedorenko
2024-08-15 13:54 ` Simon Horman
2024-08-15 14:05 ` Vadim Fedorenko
2024-08-16 5:26 ` Jiri Slaby
2024-08-16 18:48 ` Vadim Fedorenko
2024-08-16 12:03 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).