Message ID | 20230201080151.2068-3-daniel.starke@siemens.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp144716wrn; Wed, 1 Feb 2023 00:07:43 -0800 (PST) X-Google-Smtp-Source: AK7set+lh4dWPfkTfroQLhBvFn7rvP3X1DuTC/AJCngZ3Imn7npMNXQwuSSfl4y+We/QIOTmmj3V X-Received: by 2002:a17:906:d7ab:b0:878:7c18:8fd9 with SMTP id pk11-20020a170906d7ab00b008787c188fd9mr1397020ejb.44.1675238863488; Wed, 01 Feb 2023 00:07:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675238863; cv=none; d=google.com; s=arc-20160816; b=e315cj6pmU8i06xio5URBBrKKa8omtyxAUuII6CNXLxpLOTT9bH6UaoDP16jyOBuCa J6Ovp2l0ZhAk4u3ld9fgO8bC+0rCviz+Hi5jc3AdaQIqdbxLnJVtYBhXjQWU4NjhWIct rXI2e9ryrNtDcb+HP3VObDCJgBr/Y4HTdD1x31jt1UIaORWx8XOeiKii8faMHyHIglKg GMBWiFhyLm8O3/8Uuvlpsr5gmH8M6FM1sv0dPpywEv9EP/TvX7DppJvZNaaLfpfJLZZB H0u7rbcbWpzWGzVJgiW5411/zi6Z9auUQY3yrvOwiz5REBq+kIB1aN/QsS4QddGk1BhE F3Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uIC7wmtM876zS1feMXVcrIfYaMgU0Q3UqvmHnO01y6Y=; b=X77kC1p0m0L593i98HVUcx0uMd9tKS9nMFjlUMjVHDoXwfO3uxCBGRu6eH0s51zNGd JwT4yJWa/omaL6oKkeV+3R2WzW/8HSVLko6Yf4wsikbJ1BgTrOXoGRseoaWRhzR72UgU o8sXrJTUsaihiu83qwtpe6A40/RmxLyE4UbVUE17MKLciTUyxoRtDLS9hqJN+ST8W88o dP5gAVP1H+BNI0DtUgtrqcPGT22oQQb2vpQ7MPV+w1L/dg10U1CjKBeZ+3/H5yUPIx19 hoRNoSKhUmLc/QoRB+yxYdiTG4Alp45F0zK2qytTTSu2FPjmpmowV8dFP0cDB+j6ml4J ssUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=O2u9ft1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m27-20020a170906599b00b0088b19f45d4csi6990696ejs.370.2023.02.01.00.07.20; Wed, 01 Feb 2023 00:07:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=O2u9ft1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbjBAIDO (ORCPT <rfc822;duw91626@gmail.com> + 99 others); Wed, 1 Feb 2023 03:03:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjBAIDL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 1 Feb 2023 03:03:11 -0500 Received: from mta-64-228.siemens.flowmailer.net (mta-64-228.siemens.flowmailer.net [185.136.64.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 582CCDBC8 for <linux-kernel@vger.kernel.org>; Wed, 1 Feb 2023 00:03:06 -0800 (PST) Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 202302010803040276ac9c295431dc68 for <linux-kernel@vger.kernel.org>; Wed, 01 Feb 2023 09:03:04 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=uIC7wmtM876zS1feMXVcrIfYaMgU0Q3UqvmHnO01y6Y=; b=O2u9ft1yxfdTxZQA9nNo0NnO3ioyzSgxYzVJls+h4GVMPuK6EJGWExnF+UlNBcEXPpcFUP HqaMr6UEtNq6QtP8mHhQyD/lU9AkGweDQVLM8F2qNmqTx6jV6dfGraONpwBsaxSzYAupChqj 24rg5yORQen+qJd0p0M8R3OQ/2tXE=; From: "D. Starke" <daniel.starke@siemens.com> To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke <daniel.starke@siemens.com> Subject: [PATCH 3/3] tty: n_gsm: add TIOCMIWAIT support Date: Wed, 1 Feb 2023 09:01:51 +0100 Message-Id: <20230201080151.2068-3-daniel.starke@siemens.com> In-Reply-To: <20230201080151.2068-1-daniel.starke@siemens.com> References: <20230201080151.2068-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756615266506197867?= X-GMAIL-MSGID: =?utf-8?q?1756615266506197867?= |
Series |
[1/3] tty: n_gsm: add keep alive support
|
|
Commit Message
D. Starke
Feb. 1, 2023, 8:01 a.m. UTC
From: Daniel Starke <daniel.starke@siemens.com> Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the user to wait for virtual modem signals like RING. Signed-off-by: Daniel Starke <daniel.starke@siemens.com> --- drivers/tty/n_gsm.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
Comments
On Wed, Feb 01, 2023 at 09:01:51AM +0100, D. Starke wrote: > From: Daniel Starke <daniel.starke@siemens.com> > > Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the > user to wait for virtual modem signals like RING. > > Signed-off-by: Daniel Starke <daniel.starke@siemens.com> > --- > drivers/tty/n_gsm.c | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c > index 118511c1fa37..48fb7dad44cd 100644 > --- a/drivers/tty/n_gsm.c > +++ b/drivers/tty/n_gsm.c > @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, > if (brk & 0x01) > tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); > dlci->modem_rx = mlines; > + wake_up_interruptible(&dlci->gsm->event); > } > > /** > @@ -3848,6 +3849,35 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) > return -EPROTONOSUPPORT; > } > > +/** > + * gsm_wait_modem_change - wait for modem status line change No need for tabs. Or for kernel doc for static functions, but that's not a big deal. > + * @dlci: channel > + * @mask: modem status line bits > + */ > + No blank line please, didn't checkpatch warn about that? > +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) > +{ > + struct gsm_mux *gsm = dlci->gsm; > + u32 old = dlci->modem_rx & mask; > + int ret; > + > + if (gsm->dead) > + return -ENODEV; > + > + do { > + ret = wait_event_interruptible(gsm->event, gsm->dead > + || old ^ (dlci->modem_rx & mask)); > + if (ret) > + return ret; > + if (dlci->state != DLCI_OPEN) > + return -EL2NSYNC; > + if (gsm->dead) > + return -ENODEV; > + } while ((old ^ (dlci->modem_rx & mask)) == 0); No way to break out of the loop if it goes for forever? thanks, greg k-h
> > Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the > > user to wait for virtual modem signals like RING. > > > > Signed-off-by: Daniel Starke <daniel.starke@siemens.com> > > --- > > drivers/tty/n_gsm.c | 32 ++++++++++++++++++++++++++++++++ > > 1 file changed, 32 insertions(+) > > > > diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c > > index 118511c1fa37..48fb7dad44cd 100644 > > --- a/drivers/tty/n_gsm.c > > +++ b/drivers/tty/n_gsm.c > > @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, > > if (brk & 0x01) > > tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); > > dlci->modem_rx = mlines; > > + wake_up_interruptible(&dlci->gsm->event); > > } > > > > /** > > @@ -3848,6 +3849,35 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) > > return -EPROTONOSUPPORT; > > } > > > > +/** > > + * gsm_wait_modem_change - wait for modem status line change > > No need for tabs. > > Or for kernel doc for static functions, but that's not a big deal. All other functions follow the same style here. Nevertheless, I will replace the tabs with spaces. Originally, I had planned a code clean-up after committing all the changes from my original RFC. > > + * @dlci: channel > > + * @mask: modem status line bits > > + */ > > + > > No blank line please, didn't checkpatch warn about that? No, checkpatch did not warn about this and all other functions follow the same style. I will remove the blank line. > > +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) > > +{ > > + struct gsm_mux *gsm = dlci->gsm; > > + u32 old = dlci->modem_rx & mask; > > + int ret; > > + > > + if (gsm->dead) > > + return -ENODEV; > > + > > + do { > > + ret = wait_event_interruptible(gsm->event, gsm->dead > > + || old ^ (dlci->modem_rx & mask)); > > + if (ret) > > + return ret; > > + if (dlci->state != DLCI_OPEN) > > + return -EL2NSYNC; > > + if (gsm->dead) > > + return -ENODEV; > > + } while ((old ^ (dlci->modem_rx & mask)) == 0); > > No way to break out of the loop if it goes for forever? I assume that this is the expected behavior for TIOCMIWAIT. The functions returns if: - the requested modem signal changed - the wait function got interrupted (e.g. by a signal) - the underlying DLCI was closed - the underlying ldisc device was removed I can add that the function returns immediate if a mask has been passed which matches no modem signal if this is preferred? Best regards, Daniel Starke
On Wed, Feb 01, 2023 at 09:30:28AM +0000, Starke, Daniel wrote: > > > Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the > > > user to wait for virtual modem signals like RING. > > > > > > Signed-off-by: Daniel Starke <daniel.starke@siemens.com> > > > --- > > > drivers/tty/n_gsm.c | 32 ++++++++++++++++++++++++++++++++ > > > 1 file changed, 32 insertions(+) > > > > > > diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c > > > index 118511c1fa37..48fb7dad44cd 100644 > > > --- a/drivers/tty/n_gsm.c > > > +++ b/drivers/tty/n_gsm.c > > > @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, > > > if (brk & 0x01) > > > tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); > > > dlci->modem_rx = mlines; > > > + wake_up_interruptible(&dlci->gsm->event); > > > } > > > > > > /** > > > @@ -3848,6 +3849,35 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) > > > return -EPROTONOSUPPORT; > > > } > > > > > > +/** > > > + * gsm_wait_modem_change - wait for modem status line change > > > > No need for tabs. > > > > Or for kernel doc for static functions, but that's not a big deal. > > All other functions follow the same style here. Nevertheless, I will > replace the tabs with spaces. Originally, I had planned a code clean-up > after committing all the changes from my original RFC. Ah, ok, nevermind then, I didn't see that as it's not in the diffs. Cleaning up later is fine. > > > +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) > > > +{ > > > + struct gsm_mux *gsm = dlci->gsm; > > > + u32 old = dlci->modem_rx & mask; > > > + int ret; > > > + > > > + if (gsm->dead) > > > + return -ENODEV; > > > + > > > + do { > > > + ret = wait_event_interruptible(gsm->event, gsm->dead > > > + || old ^ (dlci->modem_rx & mask)); > > > + if (ret) > > > + return ret; > > > + if (dlci->state != DLCI_OPEN) > > > + return -EL2NSYNC; > > > + if (gsm->dead) > > > + return -ENODEV; > > > + } while ((old ^ (dlci->modem_rx & mask)) == 0); > > > > No way to break out of the loop if it goes for forever? > > I assume that this is the expected behavior for TIOCMIWAIT. The functions > returns if: > - the requested modem signal changed > - the wait function got interrupted (e.g. by a signal) > - the underlying DLCI was closed > - the underlying ldisc device was removed Hm, I guess you are right. But wow, reading that wait_event_interruptible() condition is crazy, please document that really well to explain this properly so you will be able to understand it in a year when you next have to fix it up :) > I can add that the function returns immediate if a mask has been passed > which matches no modem signal if this is preferred? I don't think that would work, try it on some existing serial ports to see what they do. thanks, greg k-h
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 118511c1fa37..48fb7dad44cd 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, if (brk & 0x01) tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); dlci->modem_rx = mlines; + wake_up_interruptible(&dlci->gsm->event); } /** @@ -3848,6 +3849,35 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) return -EPROTONOSUPPORT; } +/** + * gsm_wait_modem_change - wait for modem status line change + * @dlci: channel + * @mask: modem status line bits + */ + +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) +{ + struct gsm_mux *gsm = dlci->gsm; + u32 old = dlci->modem_rx & mask; + int ret; + + if (gsm->dead) + return -ENODEV; + + do { + ret = wait_event_interruptible(gsm->event, gsm->dead + || old ^ (dlci->modem_rx & mask)); + if (ret) + return ret; + if (dlci->state != DLCI_OPEN) + return -EL2NSYNC; + if (gsm->dead) + return -ENODEV; + } while ((old ^ (dlci->modem_rx & mask)) == 0); + + return 0; +} + static bool gsm_carrier_raised(struct tty_port *port) { struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); @@ -4107,6 +4137,8 @@ static int gsmtty_ioctl(struct tty_struct *tty, gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); return 0; + case TIOCMIWAIT: + return gsm_wait_modem_change(dlci, arg); default: return -ENOIOCTLCMD; }