Improve wwan qcdm compatibility with user-space tools
Subsystems (3)
v2 cover Improve wwan qcdm compatibility with user-space tools
Historically, Qualcomm diagnostic port was a serial device, so user-space tools were developed using tty specific features. One of the most common tool is, for example, ModemManager libqcdm, available at
https://gitlab.freedesktop.org/mobile-broadband/ModemManager
which requires tcgetattr/tcsetattr and the possibility to get exclusive device access to properly work.
The wwan qcdm is not really a tty device, but, besides the lack of tty functions, it behaves as a standard serial Qualcomm diagnostic port, so, as c230035c2f2f ("net: wwan: core: implement terminal ioctls for AT port"), this series add support for terminal ioctls also for qcdm ports and implement the exclusive open mode feature to improve compatibility with user-space tools.
This is an incremental change which should not affect the existing tools using wwan which do not rely on the implemented features.
V2: fixed race condition highlighted by Sashiko at
https://sashiko.dev/#/patchset/20260717081935.2071083-1-dnlplm%40gmail.com
Daniele Palmas (2):
net: wwan: add minimalistic IOCTls support also to QCDM port
net: wwan: add exclusive open mode capability to AT and QCDM ports
drivers/net/wwan/wwan_core.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 net: wwan: add minimalistic IOCTls support also to QCDM port
Upstream libqcdm requires IOCTLs support to work, so add the current AT minimalistic support also to the QCDM port.
--- drivers/net/wwan/wwan_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wwan/wwan_core.c +2 -1
@@ -1046,7 +1046,8 @@ static long wwan_port_fops_ioctl(struct file *filp, unsigned int cmd,struct wwan_port *port = filp->private_data;int res; -if (port->type ==WWAN_PORT_AT ) {/* AT port specific IOCTLs */ +if (port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) { +/* AT and QCDM port specific IOCTLs */ res =wwan_port_fops_at_ioctl (port, cmd, arg);if (res != -ENOIOCTLCMD )return res;
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 1/2] net: wwan: add minimalistic IOCTls support also to QCDM port
Quoted 5 lines · Daniele Palmas
Upstream libqcdm requires IOCTLs support to work, so add the current AT minimalistic support also to the QCDM port.
Signed-off-by Daniele Palmas <[email protected]>
I wonder whether it would be better to introduce a dedicated flag (e.g. WWAN_PORT_TTY_EMU) instead of checking the port type each time. This could scale better if the list of special cases grows. That said, for now this looks good to me.
Quoted 21 lines
--- drivers/net/wwan/wwan_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/wwan/wwan_core.c +2
-2@@ -1046,7 +1046,8 @@ static long wwan_port_fops_ioctl(struct file *filp, unsigned int cmd,struct wwan_port *port = filp->private_data;int res; -if (port->type ==WWAN_PORT_AT ) {/* AT port specific IOCTLs */ +if (port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) { +/* AT and QCDM port specific IOCTLs */ res =wwan_port_fops_at_ioctl (port, cmd, arg);if (res != -ENOIOCTLCMD )return res; --2.43.0
PATCH v2 2/2 net: wwan: add exclusive open mode capability to AT and QCDM ports
In reply to Daniele PalmasAdd exclusive open mode capability to AT and QCDM ports to improve compatibility with user-space tools using the Qualcomm diagnostic device (e.g. libqcdm).
--- drivers/net/wwan/wwan_core.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/net/wwan/wwan_core.c +29 -1
@@ -22,6 +22,7 @@#include <linux/termios.h> #include <linux/gnss.h> #include <linux/wwan.h> +#include <linux/tty.h> #include <net/rtnetlink.h> #include <uapi/linux/wwan.h>
@@ -79,7 +80,7 @@ struct wwan_device {* @data_lock: Port specific data access serialization * @headroom_len: SKB reserved headroom size * @frag_len: Length to fragment packet -* @at_data: AT port specific data +* @at_data: AT/QCDM port specific data * @gnss: Pointer to GNSS device associated with this port */ struct wwan_port {
@@ -98,6 +99,7 @@ struct wwan_port {struct {struct ktermios termios;int mdmbits; +unsigned long flags; } at_data;struct gnss_device *gnss; };
@@ -748,6 +750,14 @@ static int wwan_port_op_start(struct wwan_port *port) goto out_unlock; } +/* Check exclusive open mode for AT and QCDM ports */ +if ((port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) && +test_bit (TTY_EXCLUSIVE , &port->at_data.flags) && + !capable (CAP_SYS_ADMIN )) { + ret = -EBUSY ; + goto out_unlock; + } +/* If port is already started, don't start again */ if (!port->start_count) ret = port->ops->start (port);
@@ -769,6 +779,8 @@ static void wwan_port_op_stop(struct wwan_port *port)if (port->ops) port->ops->stop (port);skb_queue_purge (&port->rxq); +if (port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); }mutex_unlock (&port->ops_lock); }
@@ -1031,6 +1043,22 @@ static long wwan_port_fops_at_ioctl(struct wwan_port *port, unsigned int cmd,break ; } +case TIOCEXCL : +set_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCNXCL : +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCGEXCL : + { +int excl =test_bit (TTY_EXCLUSIVE , &port->at_data.flags); + + ret =put_user (excl, (int __user *)arg); +break ; + } +default : ret = -ENOIOCTLCMD ; }
Signature · 1 line
2.43.0
Loic Poulain
maintainerRe: [PATCH net-next v2 2/2] net: wwan: add exclusive open mode capability to AT and QCDM ports
Quoted 40 lines · Daniele Palmas
Add exclusive open mode capability to AT and QCDM ports to improve compatibility with user-space tools using the Qualcomm diagnostic device (e.g. libqcdm).
Signed-off-by Daniele Palmas <[email protected]>--- drivers/net/wwan/wwan_core.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)drivers/net/wwan/wwan_core.c +3
-1@@ -22,6 +22,7 @@#include <linux/termios.h> #include <linux/gnss.h> #include <linux/wwan.h> +#include <linux/tty.h> #include <net/rtnetlink.h> #include <uapi/linux/wwan.h> @@ -79,7 +80,7 @@ struct wwan_device {* @data_lock: Port specific data access serialization * @headroom_len: SKB reserved headroom size * @frag_len: Length to fragment packet -* @at_data: AT port specific data +* @at_data: AT/QCDM port specific data * @gnss: Pointer to GNSS device associated with this port */ struct wwan_port {@@ -98,6 +99,7 @@ struct wwan_port {struct {struct ktermios termios;int mdmbits; +unsigned long flags; } at_data;struct gnss_device *gnss; };
drivers/net/wwan/wwan_core.c static int wwan_port_op_start(struct wwan_port *port) · line 759
Quoted 10 lines
drivers/net/wwan/wwan_core.c +7
-0@@ -748,6 +750,14 @@ static int wwan_port_op_start(struct wwan_port *port) goto out_unlock; } +/* Check exclusive open mode for AT and QCDM ports */ +if ((port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) && +test_bit (TTY_EXCLUSIVE , &port->at_data.flags) && + !capable (CAP_SYS_ADMIN )) { + ret = -EBUSY ; + goto out_unlock; + }
I would recommend simplifying this by relying on the already existing wwan_port flag introducing a WWAN_PORT_EXCLUSIVE. This would also eliminate the need to check the port type in the condition above.
Quoted 39 lines
drivers/net/wwan/wwan_core.c +19
-1+/* If port is already started, don't start again */ if (!port->start_count) ret = port->ops->start (port);@@ -769,6 +779,8 @@ static void wwan_port_op_stop(struct wwan_port *port)if (port->ops) port->ops->stop (port);skb_queue_purge (&port->rxq); +if (port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); }mutex_unlock (&port->ops_lock); }@@ -1031,6 +1043,22 @@ static long wwan_port_fops_at_ioctl(struct wwan_port *port, unsigned int cmd,break ; } +case TIOCEXCL : +set_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCNXCL : +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCGEXCL : + { +int excl =test_bit (TTY_EXCLUSIVE , &port->at_data.flags); + + ret =put_user (excl, (int __user *)arg); +break ; + } +default : ret = -ENOIOCTLCMD ; } --2.43.0
Re: [PATCH net-next v2 2/2] net: wwan: add exclusive open mode capability to AT and QCDM ports
Hi Loic,
Il giorno mer 22 lug 2026 alle ore 11:41 Loic Poulain <[email protected]> ha scritto:
Quoted 45 lines · Daniele Palmas
Quoted 43 lines
Add exclusive open mode capability to AT and QCDM ports to improve compatibility with user-space tools using the Qualcomm diagnostic device (e.g. libqcdm).
Signed-off-by Daniele Palmas <[email protected]>--- drivers/net/wwan/wwan_core.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)drivers/net/wwan/wwan_core.c +3
-1@@ -22,6 +22,7 @@#include <linux/termios.h> #include <linux/gnss.h> #include <linux/wwan.h> +#include <linux/tty.h> #include <net/rtnetlink.h> #include <uapi/linux/wwan.h> @@ -79,7 +80,7 @@ struct wwan_device {* @data_lock: Port specific data access serialization * @headroom_len: SKB reserved headroom size * @frag_len: Length to fragment packet -* @at_data: AT port specific data +* @at_data: AT/QCDM port specific data * @gnss: Pointer to GNSS device associated with this port */ struct wwan_port {@@ -98,6 +99,7 @@ struct wwan_port {struct {struct ktermios termios;int mdmbits; +unsigned long flags; } at_data;struct gnss_device *gnss; };@@ -748,6 +750,14 @@ static int wwan_port_op_start(struct wwan_port *port) goto out_unlock; }
Quoted 12 lines
drivers/net/wwan/wwan_core.c static int wwan_port_op_start(struct wwan_port *port) · line 759
Quoted 7 lines
drivers/net/wwan/wwan_core.c +7
-0+/* Check exclusive open mode for AT and QCDM ports */ +if ((port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) && +test_bit (TTY_EXCLUSIVE , &port->at_data.flags) && + !capable (CAP_SYS_ADMIN )) { + ret = -EBUSY ; + goto out_unlock; + }I would recommend simplifying this by relying on the already existing
wwan_portflag introducing aWWAN_PORT_EXCLUSIVE. This would also eliminate the need to check the port type in the condition above.
Thanks for the hint, I'm following-up with a simplified version.
Regards,
Daniele
Quoted 39 lines
Quoted 39 lines
drivers/net/wwan/wwan_core.c +19
-1+/* If port is already started, don't start again */ if (!port->start_count) ret = port->ops->start (port);@@ -769,6 +779,8 @@ static void wwan_port_op_stop(struct wwan_port *port)if (port->ops) port->ops->stop (port);skb_queue_purge (&port->rxq); +if (port->type ==WWAN_PORT_AT || port->type ==WWAN_PORT_QCDM ) +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); }mutex_unlock (&port->ops_lock); }@@ -1031,6 +1043,22 @@ static long wwan_port_fops_at_ioctl(struct wwan_port *port, unsigned int cmd,break ; } +case TIOCEXCL : +set_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCNXCL : +clear_bit (TTY_EXCLUSIVE , &port->at_data.flags); +break ; + +case TIOCGEXCL : + { +int excl =test_bit (TTY_EXCLUSIVE , &port->at_data.flags); + + ret =put_user (excl, (int __user *)arg); +break ; + } +default : ret = -ENOIOCTLCMD ; } --2.43.0