From patchwork Thu Feb 2 14:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 51984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp290297wrn; Thu, 2 Feb 2023 07:05:30 -0800 (PST) X-Google-Smtp-Source: AK7set8vxXT70lmy7JxunkoCPVruGV+VI7yIKeuXKCbohdHyNaBkekxRTsFUsJFY0I7M1g+gN6yS X-Received: by 2002:a05:6a20:a001:b0:b8:c5b3:bfc with SMTP id p1-20020a056a20a00100b000b8c5b30bfcmr7468762pzj.39.1675350330611; Thu, 02 Feb 2023 07:05:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675350330; cv=none; d=google.com; s=arc-20160816; b=exFwqvS6SwYdIwxoWmohHnKnvQiJyB6KK7qb6EwERCuABMEgJuZr39V/lNAT2Mv1jT qmtPOonlkB+VaEelRQh56EvvdFueSBH8ZqcNZT0MMZCfj9A5wYiqFY6RmxzuE4B0F1i9 3avOO/stu9C3Qg4Ff5wf98GTHslC08cn/gv7h0q8gocKb6U9J2XrNMKyTUw3hklQTeov yJ8GRG7qEEVt/RL4mBDvSHCN2nsl455szcNI33nd1BTrPUnHs6RGOh8tNkhf6CetL8JV CKoRcVScFH375azpZHJFkN5i3mY/0NwTArmm8HG1XePQaZtKKodQy/twSkxFii9/PaiK R9iw== 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=YdcoFftLnFR/AK9G1BlGcWmP90uXq6edhg1S5lsCyRU=; b=n/L//50MS3sM6ekYBAqiPUfPSkPPtMO6XBUR+Lp3FmbKfiwVJvNUVZr3NFvfXMzVj6 kcP603CZ80cRQ0M3NCayPt+7+6nXdWg/PTgoVLfJEfPVQcXfv/eZLvLUXmxtO8IUDmy2 z7c2I3xs6Q5UAk+vc271VoL+yrSr+BVxNTsxvY0qmGJrG9spTUXXzqcq4QSIziruWB76 c11cuJFHpCbhh2ftg26LhLFu4zOdeS2OS+mschEHVg8MmYLcg/Th7rIuxvuMOLnXTwDB O7Ua/iefX5Q1RH2UhFZK9rLyMzreNSGlLnhV7YigL0lMTnPkyY1DiGaDlRs9Pp8TTW/O 5RZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=MD6mRlsf; 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 p29-20020a63741d000000b004ae2bd6b8casi22422879pgc.808.2023.02.02.07.05.08; Thu, 02 Feb 2023 07:05:30 -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=MD6mRlsf; 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 S232007AbjBBPCQ (ORCPT + 99 others); Thu, 2 Feb 2023 10:02:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbjBBPCL (ORCPT ); Thu, 2 Feb 2023 10:02:11 -0500 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 02 Feb 2023 07:01:59 PST Received: from mta-64-225.siemens.flowmailer.net (mta-64-225.siemens.flowmailer.net [185.136.64.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39220222D4 for ; Thu, 2 Feb 2023 07:01:57 -0800 (PST) Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 20230202150052df0c5fd652493057c5 for ; Thu, 02 Feb 2023 16:00:53 +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=YdcoFftLnFR/AK9G1BlGcWmP90uXq6edhg1S5lsCyRU=; b=MD6mRlsfiPecqm31pMlgpw6gJKBqmkfeIeoKLZUgIDHWTJrsd5fABfT62ZY/IgJysdDBw3 2DxsnoEXD41hpz5D36YnHIOJ2o8sEi6WcWdrRs8IuKjP1VeaaoBAXVwQYrq4UfOhj64/+3R1 GOHE6T5TFODzYf7MpD2NkhkMd9ANI=; From: "D. Starke" 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 Subject: [PATCH v2 3/3] tty: n_gsm: add TIOCMIWAIT support Date: Thu, 2 Feb 2023 15:59:34 +0100 Message-Id: <20230202145934.22641-3-daniel.starke@siemens.com> In-Reply-To: <20230202145934.22641-1-daniel.starke@siemens.com> References: <20230202145934.22641-1-daniel.starke@siemens.com> MIME-Version: 1.0 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=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756732148090794395?= X-GMAIL-MSGID: =?utf-8?q?1756732148090794395?= From: Daniel Starke Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the user to wait for virtual modem signals like RING. More work is needed to support also TIOCGICOUNT. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) v1 -> v2: A remark regarding TIOCGICOUNT has been added to the commit message. Wake ups in gsm_dlci_close() and gsm_dlci_begin_close() have been added to cope with closed DLCI during TIOCMIWAIT. gsm_wait_modem_change() has been properly commented to highlight all use cases. Furthermore, the function has been simplified and a DLCI state condition added to the wait_event_interruptible() call to deal with DLCI termination during TIOCMIWAIT correctly. Link: https://lore.kernel.org/all/Y9pgT4VcW3oGaSbY@kroah.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index cf1ab7d619d9..4f710a6309a7 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); } /** @@ -2129,7 +2130,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) /* A DLCI 0 close is a MUX termination so we need to kick that back to userspace somehow */ gsm_dlci_data_kick(dlci); - wake_up(&dlci->gsm->event); + wake_up_all(&dlci->gsm->event); } /** @@ -2339,6 +2340,7 @@ static void gsm_dlci_begin_close(struct gsm_dlci *dlci) dlci->state = DLCI_CLOSING; gsm_command(dlci->gsm, dlci->addr, DISC|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); + wake_up_interruptible(&gsm->event); } /** @@ -3877,6 +3879,33 @@ 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 + * + * The function returns if: + * - any given modem status line bit changed + * - the wait event function got interrupted (e.g. by a signal) + * - the underlying DLCI was closed + * - the underlying ldisc device was removed + */ +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) +{ + struct gsm_mux *gsm = dlci->gsm; + u32 old = dlci->modem_rx; + int ret; + + ret = wait_event_interruptible(gsm->event, gsm->dead || + dlci->state != DLCI_OPEN || + (old ^ dlci->modem_rx) & mask); + if (gsm->dead) + return -ENODEV; + if (dlci->state != DLCI_OPEN) + return -EL2NSYNC; + return ret; +} + static bool gsm_carrier_raised(struct tty_port *port) { struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); @@ -4136,6 +4165,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; }