From patchwork Fri Feb 3 14:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 52545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp883025wrn; Fri, 3 Feb 2023 06:58:18 -0800 (PST) X-Google-Smtp-Source: AK7set+YiUOxN7gKNBq264Fw5mZ6i/EODm6VpY4wU7AYP1KojysPwvzXfHSqc+0T0QXmGl6luS9u X-Received: by 2002:a05:6a20:7d87:b0:bc:e1ce:605d with SMTP id v7-20020a056a207d8700b000bce1ce605dmr15704340pzj.20.1675436298673; Fri, 03 Feb 2023 06:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675436298; cv=none; d=google.com; s=arc-20160816; b=XeREfRhY8f7DvAebRIzM5kPLcJBF/eqP0sy6WyTv4VFJlUKTj4vDIdJQchPeX5ocpJ 3D1ErVV3RVwayuA5gGCUUATssaw4ZuR8OMsEnLxFpMlLVXn9XaaE6WxAP10IUnoA1a5i Svj613mDsNB+BMFxnaf5ZcddDxj7OMkOQ59lI+cWrLhlOrdeIJCdcu590uaYsTTFDjnG lj8oGYEV0XgT5MygmGNj9f4Kn1BqBXhO39wgDr/Mdr3VBQt1MpJEZ2+znU4AYtOaFK5a SCNZ5AYRCRYjlTmNFyX+r9jrnf7P8+1vgzI0TxbDYK13FZm2p9mU+3JRkaiGue7AQxab nD6w== 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=soWeu6gkV3NEcYNRrfIYl154ZKDvANaWKtl+GG89qaE=; b=aU3Sn2iV76BWZ0jBIlreBwxh1HMBLZmxoa4IUteEhV8jR3OxqaB+r3RUHWqPIn31HR qSglC8xAbNZKz0VNFIsLndef0isYeQ52wEWHBisK0goDWiyiBGIvuwhJF8ej2JMqIiIW SV5kI57NlUOxkCE9zVu5hEglZ1gqxGA+XhpdR70Gxh6OswwSXoAdKFxOKdDFm1vIJSo1 GJqbaW3ScaJKCkzT1XXcz5iFipfZKIwc9pxLxFza5J5SH3qbWOWCtiK58aJR6NIbVZGX iv2FB5e/yi8+sM/2JCtyitABmeWtNBDOb6/+oKqk/psGxb+dVO5A1U7dD5mKoeYci/gY 2hmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Zoq+elDa; 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 d29-20020a63735d000000b004e07c92165bsi3096296pgn.240.2023.02.03.06.58.06; Fri, 03 Feb 2023 06:58:18 -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=Zoq+elDa; 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 S233282AbjBCOux (ORCPT + 99 others); Fri, 3 Feb 2023 09:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbjBCOus (ORCPT ); Fri, 3 Feb 2023 09:50:48 -0500 Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DBA573058 for ; Fri, 3 Feb 2023 06:50:45 -0800 (PST) Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20230203145043e8dbe453e4aaf29f1c for ; Fri, 03 Feb 2023 15:50:43 +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=soWeu6gkV3NEcYNRrfIYl154ZKDvANaWKtl+GG89qaE=; b=Zoq+elDa54uNPWIqcLTvhC6h8SEmYAp7+CC2tc+BukBRK8JfKgI6Lc6sKWeADUWMCy979s mK2dnRwPYk5zS953sx2RfMHa+lhFKXzeRrj/cbjY7ymzsk84F7gMo3+IejoLYtCOI1CJ/e/l k/v9BOA0ogvP2xpqH6oJyjLHgPsIs=; 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 v3 4/4] tty: n_gsm: add TIOCMIWAIT support Date: Fri, 3 Feb 2023 15:50:23 +0100 Message-Id: <20230203145023.6012-4-daniel.starke@siemens.com> In-Reply-To: <20230203145023.6012-1-daniel.starke@siemens.com> References: <20230203145023.6012-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=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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756822292243125379?= X-GMAIL-MSGID: =?utf-8?q?1756822292243125379?= 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(-) v2 -> v3: Added appropriate cast of arg in gsm_wait_modem_change() call as remarked in the review. No other changes. Link: https://lore.kernel.org/all/Y9vZOsAuzKjBNArJ@kroah.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index cf1ab7d619d9..aa3488280f1b 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, (u32)arg); default: return -ENOIOCTLCMD; }