tty: n_gsm: remove obsolete mknod doc example
Subsystems (2)
PATCH v3 1/4 tty: n_gsm: remove obsolete mknod doc example
The n_gsm driver handles registration of /dev/gsmttyX nodes, so there's no need to do mknod manually.
--- Documentation/serial/n_gsm.rst | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
Documentation/serial/n_gsm.rst +2 -12
@@ -63,24 +63,14 @@ 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. +4. use these devices as plain serial ports. for example, it's possible: - and to use gnokii to send / receive SMS on ttygsm1 - to use ppp to establish a datalink on ttygsm2 -6. first close all virtual ports before closing the physical port. +5. first close all virtual ports before closing the physical port. Note that after closing the physical port the modem is still in multiplexing mode. This may prevent a successful re-opening of the port later. To avoid
Signature · 1 line
2.22.0
PATCH v3 2/4 tty: n_gsm: update doc example to use header for N_GSM0710 define
There is no reason to gues the line discipline number when it is available from tty.h
--- Documentation/serial/n_gsm.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/serial/n_gsm.rst +1 -1
@@ -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
Signature · 1 line
2.22.0
PATCH v3 3/4 tty: n_gsm: add helpers to convert mux-num to/from tty-base
In reply to Martin HundebøllMake it obvious how the gsm mux number relates to the virtual tty lines by using helper functions instead of shifting 6 bits.
---
Changes since v2:
* use unsigned integers in both helper functions
drivers/tty/n_gsm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/tty/n_gsm.c +15 -4
@@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm)kref_put (&gsm->ref, gsm_free_muxr); } +static inline unsigned int mux_num_to_base (struct gsm_mux *gsm) +{ +return gsm->num *NUM_DLCI ; +} + +static inline unsigned int mux_line_to_num (unsigned int line) +{ +return line /NUM_DLCI ; +} +/** * gsm_alloc_mux - allocate a mux *
@@ -2351,7 +2361,8 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len)static int gsmld_attach_gsm (struct tty_struct *tty,struct gsm_mux *gsm) { -int ret, i, base; +unsigned int base; +int ret, i; gsm->tty =tty_kref_get (tty); gsm->output = gsmld_output;
@@ -2361,7 +2372,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 ); }
@@ -2379,8 +2390,8 @@ 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) { +unsigned int base =mux_num_to_base (gsm);/* Base for this MUX */ int i; -int base = gsm->num <<6 ;/* Base for this MUX */ WARN_ON (tty != gsm->tty);for (i =1 ; i <NUM_DLCI ; i++)
@@ -2908,7 +2919,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;
Signature · 1 line
2.22.0
PATCH v3 4/4 tty: n_gsm: add ioctl to map serial device to mux'ed tty
In reply to Martin HundebøllGuessing the first 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 an ioctl.
---
Changes since v2:
* rename IOCTL from GSMIOC_GETBASE to GSMIOC_GETFIRST
* return first usable line instead of private control line
* return uint32_t instead of int
Changes since v1:
* use put_user() instead of copy_to_user()
* add missing opening quote
Documentation/serial/n_gsm.rst | 11 +++++++++-- drivers/tty/n_gsm.c | 4 ++++ include/uapi/linux/gsmmux.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-)
Documentation/serial/n_gsm.rst +9 -2
@@ -18,10 +18,13 @@ 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 <stdint.h> #include <linux/gsmmux.h> #include <linux/tty.h> #define DEFAULT_SPEED B115200
@@ -30,6 +33,7 @@ Major parts of the initialization program : int ldisc = N_GSM0710; struct gsm_config c; struct termios configuration; + uint32_t first; /* open the serial port connected to the modem */ fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
@@ -58,19 +62,22 @@ Major parts of the initialization program : c.mtu = 127; /* set the new configuration */ ioctl(fd, GSMIOC_SETCONF, &c); + /* get first gsmtty device node */ + ioctl(fd, GSMIOC_GETFIRST, &first); + printf("first muxed line: /dev/gsmtty%i\n", first); /* and wait for ever to keep the line discipline enabled */ daemon(0,0); pause(); -4. use these devices as plain serial ports. +5. use these devices as plain serial ports. for example, it's possible: - and to use gnokii to send / receive SMS on ttygsm1 - to use ppp to establish a datalink on ttygsm2 -5. first close all virtual ports before closing the physical port. +6. first close all virtual ports before closing the physical port. Note that after closing the physical port the modem is still in multiplexing mode. This may prevent a successful re-opening of the port later. To avoid
drivers/tty/n_gsm.c +4 -0
@@ -2613,6 +2613,7 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file, {struct gsm_config c;struct gsm_mux *gsm = tty->disc_data; +unsigned int base;switch (cmd) {case GSMIOC_GETCONF :
@@ -2624,6 +2625,9 @@ 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_GETFIRST : + base =mux_num_to_base (gsm); +return put_user (base +1 , (uint32_t __user *)arg);default :return n_tty_ioctl_helper (tty, file, cmd, arg); }
include/uapi/linux/gsmmux.h +2 -0
@@ -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_GETFIRST _IOR('G', 4, uint32_t)#endif
Signature · 1 line
2.22.0
Greg Kroah-Hartman
maintainerRe: [PATCHv3 4/4] tty: n_gsm: add ioctl to map serial device to mux'ed tty
Quoted 28 lines · Martin Hundebøll
Guessing the first 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 an ioctl.
Signed-off-by Martin Hundebøll <[email protected]>---
Changes since v2:
* rename IOCTL fromGSMIOC_GETBASEtoGSMIOC_GETFIRST
* return first usable line instead of private control line
* returnuint32_tinstead of intChanges since v1:
* useput_user()instead ofcopy_to_user()
* add missing opening quoteDocumentation/serial/n_gsm.rst | 11 +++++++++-- drivers/tty/n_gsm.c | 4 ++++ include/uapi/linux/gsmmux.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-)Documentation/serial/n_gsm.rst +0
-0
Documentation/serial/n_gsm.rst How to use it · line 21
Quoted 4 lines
Documentation/serial/n_gsm.rst +1
-0@@ -18,10 +18,13 @@ 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,
As this file is in .rst format, do we need the enumerated list anymore?
Just a meta-comment...
Quoted 73 lines
Documentation/serial/n_gsm.rst +8
-2Major parts of the initialization program : (a good starting point is util-linux-ng/sys-utils/ldattach.c):: + #include <stdio.h> + #include <stdint.h> #include <linux/gsmmux.h> #include <linux/tty.h> #define DEFAULT_SPEED B115200@@ -30,6 +33,7 @@ Major parts of the initialization program : int ldisc = N_GSM0710; struct gsm_config c; struct termios configuration; + uint32_t first; /* open the serial port connected to the modem */ fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);@@ -58,19 +62,22 @@ Major parts of the initialization program : c.mtu = 127; /* set the new configuration */ ioctl(fd, GSMIOC_SETCONF, &c); + /* get first gsmtty device node */ + ioctl(fd, GSMIOC_GETFIRST, &first); + printf("first muxed line: /dev/gsmtty%i\n", first); /* and wait for ever to keep the line discipline enabled */ daemon(0,0); pause(); -4. use these devices as plain serial ports. +5. use these devices as plain serial ports. for example, it's possible: - and to use gnokii to send / receive SMS on ttygsm1 - to use ppp to establish a datalink on ttygsm2 -5. first close all virtual ports before closing the physical port. +6. first close all virtual ports before closing the physical port. Note that after closing the physical port the modem is still in multiplexing mode. This may prevent a successful re-opening of the port later. To avoiddrivers/tty/n_gsm.c +4
-0@@ -2613,6 +2613,7 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file, {struct gsm_config c;struct gsm_mux *gsm = tty->disc_data; +unsigned int base;switch (cmd) {case GSMIOC_GETCONF :@@ -2624,6 +2625,9 @@ 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_GETFIRST : + base =mux_num_to_base (gsm); +return put_user (base +1 , (uint32_t __user *)arg);drivers/tty/n_gsm.c +0
-0default :return n_tty_ioctl_helper (tty, file, cmd, arg); }include/uapi/linux/gsmmux.h +0
-0
include/uapi/linux/gsmmux.h struct gsm_netconfig { · line 41
Quoted 5 lines
include/uapi/linux/gsmmux.h +2
-0@@ -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_GETFIRST _IOR('G', 4, uint32_t)
Variables that cross the boundry from user/kernel should use the correct type. That would be "__u32" here.
thanks.
greg k-h