linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example
@ 2019-07-08 19:02 Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 2/4] tty: n_gsm: update doc example to use header for N_GSM0710 define Martin Hundebøll
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Martin Hundebøll @ 2019-07-08 19:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel
  Cc: Martin Hundebøll, Sean Nyekjær, Esben Haabendal

The n_gsm driver handles registration of /dev/gsmttyX nodes, so there's
no need to do mknod manually.

Signed-off-by: Martin Hundebøll <martin@geanix.com>
---
 Documentation/serial/n_gsm.rst | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
index f3ad9fd26408..78f91ce06956 100644
--- a/Documentation/serial/n_gsm.rst
+++ b/Documentation/serial/n_gsm.rst
@@ -63,16 +63,6 @@ Major parts of the initialization program :
 	daemon(0,0);
 	pause();
 
-4. create the devices corresponding to the "virtual" serial ports (take care,
-   each modem has its configuration and some DLC have dedicated functions,
-   for example GPS), starting with minor 1 (DLC0 is reserved for the management
-   of the mux)::
-
-     MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
-     for i in `seq 1 4`; do
-	mknod /dev/ttygsm$i c $MAJOR $i
-     done
-
 5. use these devices as plain serial ports.
 
    for example, it's possible:
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] tty: n_gsm: update doc example to use header for N_GSM0710 define
  2019-07-08 19:02 [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Martin Hundebøll
@ 2019-07-08 19:02 ` Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base Martin Hundebøll
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Martin Hundebøll @ 2019-07-08 19:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel
  Cc: Martin Hundebøll, Sean Nyekjær, Esben Haabendal

There is no reason to gues the line discipline number when it is
available from tty.h

Signed-off-by: Martin Hundebøll <martin@geanix.com>
---
 Documentation/serial/n_gsm.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
index 78f91ce06956..a3ce1b269018 100644
--- a/Documentation/serial/n_gsm.rst
+++ b/Documentation/serial/n_gsm.rst
@@ -23,7 +23,7 @@ Major parts of the initialization program :
 (a good starting point is util-linux-ng/sys-utils/ldattach.c)::
 
   #include <linux/gsmmux.h>
-  #define N_GSM0710	21	/* GSM 0710 Mux */
+  #include <linux/tty.h>
   #define DEFAULT_SPEED	B115200
   #define SERIAL_PORT	/dev/ttyS0
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base
  2019-07-08 19:02 [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 2/4] tty: n_gsm: update doc example to use header for N_GSM0710 define Martin Hundebøll
@ 2019-07-08 19:02 ` Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty Martin Hundebøll
  2019-07-09  5:29 ` [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Jiri Slaby
  3 siblings, 0 replies; 8+ messages in thread
From: Martin Hundebøll @ 2019-07-08 19:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel
  Cc: Martin Hundebøll, Sean Nyekjær, Esben Haabendal

Make it obvious how the gsm mux number relates to the virtual tty lines
by using helper function instead of shifting 6 bits.

Signed-off-by: Martin Hundebøll <martin@geanix.com>
---
 drivers/tty/n_gsm.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index c4e16b31f9ab..cba06063c44a 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm)
 	kref_put(&gsm->ref, gsm_free_muxr);
 }
 
+static inline int mux_num_to_base(struct gsm_mux *gsm)
+{
+	return gsm->num * NUM_DLCI;
+}
+
+static inline unsigned int mux_line_to_num(int line)
+{
+	return line / NUM_DLCI;
+}
+
 /**
  *	gsm_alloc_mux		-	allocate a mux
  *
@@ -2361,7 +2371,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
 	else {
 		/* Don't register device 0 - this is the control channel and not
 		   a usable tty interface */
-		base = gsm->num << 6; /* Base for this MUX */
+		base = mux_num_to_base(gsm); /* Base for this MUX */
 		for (i = 1; i < NUM_DLCI; i++)
 			tty_register_device(gsm_tty_driver, base + i, NULL);
 	}
@@ -2380,7 +2390,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
 static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
 {
 	int i;
-	int base = gsm->num << 6; /* Base for this MUX */
+	int base = mux_num_to_base(gsm); /* Base for this MUX */
 
 	WARN_ON(tty != gsm->tty);
 	for (i = 1; i < NUM_DLCI; i++)
@@ -2908,7 +2918,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
 	struct gsm_mux *gsm;
 	struct gsm_dlci *dlci;
 	unsigned int line = tty->index;
-	unsigned int mux = line >> 6;
+	unsigned int mux = mux_line_to_num(line);
 	bool alloc = false;
 	int ret;
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty
  2019-07-08 19:02 [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 2/4] tty: n_gsm: update doc example to use header for N_GSM0710 define Martin Hundebøll
  2019-07-08 19:02 ` [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base Martin Hundebøll
@ 2019-07-08 19:02 ` Martin Hundebøll
  2019-07-09  5:35   ` Jiri Slaby
  2019-07-09 15:22   ` Alan Cox
  2019-07-09  5:29 ` [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Jiri Slaby
  3 siblings, 2 replies; 8+ messages in thread
From: Martin Hundebøll @ 2019-07-08 19:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel
  Cc: Martin Hundebøll, Sean Nyekjær, Esben Haabendal

Guessing the base tty for a gsm0710 multiplexed serial device is not
currently possible, which makes it racy to use with multiple modems.

Add a way to map the physical serial tty to its related mux devices
using a ioctl.

Signed-off-by: Martin Hundebøll <martin@geanix.com>
---
 Documentation/serial/n_gsm.rst | 8 ++++++++
 drivers/tty/n_gsm.c            | 6 ++++++
 include/uapi/linux/gsmmux.h    | 2 ++
 3 files changed, 16 insertions(+)

diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
index a3ce1b269018..bf5d7f82b5af 100644
--- a/Documentation/serial/n_gsm.rst
+++ b/Documentation/serial/n_gsm.rst
@@ -18,10 +18,12 @@ How to use it
 2. switch the serial line to using the n_gsm line discipline by using
    TIOCSETD ioctl,
 3. configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl,
+4. obtain base gsmtty number for the used serial port,
 
 Major parts of the initialization program :
 (a good starting point is util-linux-ng/sys-utils/ldattach.c)::
 
+  #include <stdio.h>
   #include <linux/gsmmux.h>
   #include <linux/tty.h>
   #define DEFAULT_SPEED	B115200
@@ -30,6 +32,7 @@ Major parts of the initialization program :
 	int ldisc = N_GSM0710;
 	struct gsm_config c;
 	struct termios configuration;
+	int base;
 
 	/* open the serial port connected to the modem */
 	fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
@@ -58,6 +61,11 @@ Major parts of the initialization program :
 	c.mtu = 127;
 	/* set the new configuration */
 	ioctl(fd, GSMIOC_SETCONF, &c);
+	/* get and print base gsmtty device node */
+	ioctl(fd, GSMIOC_GETBASE, &base);
+	/* the base node is used for mux control by the driver */
+	printf(first muxed line: /dev/gsmtty%i\n", base + 1);
+
 
 	/* and wait for ever to keep the line discipline enabled */
 	daemon(0,0);
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index cba06063c44a..93c24d9b582b 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2612,6 +2612,7 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file,
 {
 	struct gsm_config c;
 	struct gsm_mux *gsm = tty->disc_data;
+	int base;
 
 	switch (cmd) {
 	case GSMIOC_GETCONF:
@@ -2623,6 +2624,11 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file,
 		if (copy_from_user(&c, (void *)arg, sizeof(c)))
 			return -EFAULT;
 		return gsm_config(gsm, &c);
+	case GSMIOC_GETBASE:
+		base = mux_num_to_base(gsm);
+		if (copy_to_user((void *)arg, &base, sizeof(base)))
+			return -EFAULT;
+		return 0;
 	default:
 		return n_tty_ioctl_helper(tty, file, cmd, arg);
 	}
diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h
index 101d3c469acb..6eb63be3ed9e 100644
--- a/include/uapi/linux/gsmmux.h
+++ b/include/uapi/linux/gsmmux.h
@@ -37,5 +37,7 @@ struct gsm_netconfig {
 #define GSMIOC_ENABLE_NET      _IOW('G', 2, struct gsm_netconfig)
 #define GSMIOC_DISABLE_NET     _IO('G', 3)
 
+/* get the base tty number for a configured gsmmux tty */
+#define GSMIOC_GETBASE		_IOR('G', 4, int)
 
 #endif
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example
  2019-07-08 19:02 [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Martin Hundebøll
                   ` (2 preceding siblings ...)
  2019-07-08 19:02 ` [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty Martin Hundebøll
@ 2019-07-09  5:29 ` Jiri Slaby
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Slaby @ 2019-07-09  5:29 UTC (permalink / raw)
  To: Martin Hundebøll, Greg Kroah-Hartman, linux-kernel
  Cc: Esben Haabendal, Sean Nyekjær

On 08. 07. 19, 21:02, Martin Hundebøll  wrote:
> The n_gsm driver handles registration of /dev/gsmttyX nodes, so there's
> no need to do mknod manually.
> 
> Signed-off-by: Martin Hundebøll <martin@geanix.com>
> ---
>  Documentation/serial/n_gsm.rst | 10 ----------
>  1 file changed, 10 deletions(-)
> 
> diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
> index f3ad9fd26408..78f91ce06956 100644
> --- a/Documentation/serial/n_gsm.rst
> +++ b/Documentation/serial/n_gsm.rst
> @@ -63,16 +63,6 @@ Major parts of the initialization program :
>  	daemon(0,0);
>  	pause();
>  
> -4. create the devices corresponding to the "virtual" serial ports (take care,
> -   each modem has its configuration and some DLC have dedicated functions,
> -   for example GPS), starting with minor 1 (DLC0 is reserved for the management
> -   of the mux)::
> -
> -     MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
> -     for i in `seq 1 4`; do
> -	mknod /dev/ttygsm$i c $MAJOR $i
> -     done
> -
>  5. use these devices as plain serial ports.

So you should renumber the rest now...

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty
  2019-07-08 19:02 ` [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty Martin Hundebøll
@ 2019-07-09  5:35   ` Jiri Slaby
  2019-07-09 15:22   ` Alan Cox
  1 sibling, 0 replies; 8+ messages in thread
From: Jiri Slaby @ 2019-07-09  5:35 UTC (permalink / raw)
  To: Martin Hundebøll, Greg Kroah-Hartman, linux-kernel
  Cc: Esben Haabendal, Sean Nyekjær

On 08. 07. 19, 21:02, Martin Hundebøll  wrote:
> Guessing the base tty for a gsm0710 multiplexed serial device is not
> currently possible, which makes it racy to use with multiple modems.
> 
> Add a way to map the physical serial tty to its related mux devices
> using a ioctl.
...
> --- a/Documentation/serial/n_gsm.rst
> +++ b/Documentation/serial/n_gsm.rst
...
> @@ -58,6 +61,11 @@ Major parts of the initialization program :
>  	c.mtu = 127;
>  	/* set the new configuration */
>  	ioctl(fd, GSMIOC_SETCONF, &c);
> +	/* get and print base gsmtty device node */
> +	ioctl(fd, GSMIOC_GETBASE, &base);
> +	/* the base node is used for mux control by the driver */
> +	printf(first muxed line: /dev/gsmtty%i\n", base + 1);

Missing " there.

> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
...
> @@ -2623,6 +2624,11 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file,
>  		if (copy_from_user(&c, (void *)arg, sizeof(c)))
>  			return -EFAULT;
>  		return gsm_config(gsm, &c);
> +	case GSMIOC_GETBASE:
> +		base = mux_num_to_base(gsm);
> +		if (copy_to_user((void *)arg, &base, sizeof(base)))

put_user would be more appropriate (and easier) for an int here.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty
  2019-07-08 19:02 ` [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty Martin Hundebøll
  2019-07-09  5:35   ` Jiri Slaby
@ 2019-07-09 15:22   ` Alan Cox
  2019-07-10  9:51     ` Martin Hundebøll
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Cox @ 2019-07-09 15:22 UTC (permalink / raw)
  To: Martin Hundebøll
  Cc: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, Sean Nyekjær,
	Esben Haabendal

On Mon,  8 Jul 2019 21:02:52 +0200
Martin Hundebøll <martin@geanix.com> wrote:

> Guessing the base tty for a gsm0710 multiplexed serial device is not
> currently possible, which makes it racy to use with multiple modems.
> 
> Add a way to map the physical serial tty to its related mux devices
> using a ioctl.

That looks very sensible

> +	int base;
>  
>  	/* open the serial port connected to the modem */
>  	fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
> @@ -58,6 +61,11 @@ Major parts of the initialization program :
>  	c.mtu = 127;
>  	/* set the new configuration */
>  	ioctl(fd, GSMIOC_SETCONF, &c);
> +	/* get and print base gsmtty device node */
> +	ioctl(fd, GSMIOC_GETBASE, &base);

Can we at least use a specific sized type ? uint32_t or whatever is fine.

Alan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty
  2019-07-09 15:22   ` Alan Cox
@ 2019-07-10  9:51     ` Martin Hundebøll
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Hundebøll @ 2019-07-10  9:51 UTC (permalink / raw)
  To: Alan Cox
  Cc: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, Sean Nyekjær,
	Esben Haabendal

On 09/07/2019 17.22, Alan Cox wrote:
>> +	int base;
>>   
>>   	/* open the serial port connected to the modem */
>>   	fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
>> @@ -58,6 +61,11 @@ Major parts of the initialization program :
>>   	c.mtu = 127;
>>   	/* set the new configuration */
>>   	ioctl(fd, GSMIOC_SETCONF, &c);
>> +	/* get and print base gsmtty device node */
>> +	ioctl(fd, GSMIOC_GETBASE, &base);
> Can we at least use a specific sized type ? uint32_t or whatever is fine.

Sure.

I am also considering whether returning the base (i.e. the unexposed 
control line) just confuses users. It might be better to use 
GSMIOC_GETFIRST instead, which would then return 1 for the first mux, 
and 65 for the second, and so forth.

// Martin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-10  9:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 19:02 [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Martin Hundebøll
2019-07-08 19:02 ` [PATCH 2/4] tty: n_gsm: update doc example to use header for N_GSM0710 define Martin Hundebøll
2019-07-08 19:02 ` [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base Martin Hundebøll
2019-07-08 19:02 ` [PATCH 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty Martin Hundebøll
2019-07-09  5:35   ` Jiri Slaby
2019-07-09 15:22   ` Alan Cox
2019-07-10  9:51     ` Martin Hundebøll
2019-07-09  5:29 ` [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example Jiri Slaby

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).