From patchwork Wed Feb 1 08:01:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 51217 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp145178wrn; Wed, 1 Feb 2023 00:08:53 -0800 (PST) X-Google-Smtp-Source: AK7set8nj/Iaqu4fVhRVyCWsDWMDTs/3kGPFtlpUFGnhUb9HgFoNbO1v/muLYZITPC2Xq+7qTwdg X-Received: by 2002:a05:6a21:3a86:b0:be:e908:3292 with SMTP id zv6-20020a056a213a8600b000bee9083292mr1662671pzb.15.1675238933035; Wed, 01 Feb 2023 00:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675238933; cv=none; d=google.com; s=arc-20160816; b=gMSxc883hdgsUDdrEmYukt68RoyGlgnSrtqddxm/ykR94MDYVLJAeRCKirjwN82iYF y4icjauptw5G27ujfhWGjl/wjbAkn5eNrLoZOl3BqN2Xp3qMvtFE0KKGCda9ZBm5abz5 7bzXt+cvIyhwTK0ymVACX6kCeEwQDVRvulDgLa7ThET1/PUtX2QO5oJldmL/C2pMBccU 7hYPuhbaKUBVqGPx5PD4Kk7FbLhuInOa2BBNcByXq0cQf/ZBD94ESeka4cPrVRzA7v5Z LIZxqKDL7zITVhVL8j1qYQCVXD3CeXCv6YCYLbkiWKDiryDg3N0xUTZrsO70PDltUxs2 ryJw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=cIy7cLtY1cHgn+gV5HomsZ9rqRnyEdD4Bro76hK5UPk=; b=A2yh91+8cyG4C+dJXiLZchI0w0B1XrUYIuJx+zEoT6JH0LuCCkAFUlH2eG35XRjP/6 r/ZAF51/rbaJlXSiRBuQgnPnZN05Xr4NhZV5teZ5mJKw+zC1kTvoee12fiEgTzM4pH/u RWlMt6bvKb7amHfL0TxCvcmipunBCVOoh0wn3BYuaNOKjinVJTb41fGEPowcnqdhfmpo 4xl3f8v2f2OmKZChBvMKkqCWOVcTOgwEPubjxZVsaKRJMBQtiBbxkG9IJrBUE2vxtmyb 4XmwCJsJFfHRJlA2cQ78Yf9dMztNymhC+Jkvwi7krXIaUsRj2senpdfdlAgY0oAa+MGJ RrwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Uz05oBpx; 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 t4-20020a637804000000b00476f3facb4csi18696133pgc.221.2023.02.01.00.08.40; Wed, 01 Feb 2023 00:08:53 -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=Uz05oBpx; 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 S231681AbjBAIEl (ORCPT + 99 others); Wed, 1 Feb 2023 03:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbjBAIEk (ORCPT ); Wed, 1 Feb 2023 03:04:40 -0500 X-Greylist: delayed 72 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 01 Feb 2023 00:04:18 PST Received: from mta-65-227.siemens.flowmailer.net (mta-65-227.siemens.flowmailer.net [185.136.65.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE1229174 for ; Wed, 1 Feb 2023 00:04:18 -0800 (PST) Received: by mta-65-227.siemens.flowmailer.net with ESMTPSA id 202302010803029fb2de38b4d1f1a50f for ; Wed, 01 Feb 2023 09:03:03 +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; bh=cIy7cLtY1cHgn+gV5HomsZ9rqRnyEdD4Bro76hK5UPk=; b=Uz05oBpxbitSj3UUJdh6LKGxLPbwT+z2bxZu/GMfEDtDKKGGqjIkHXq6/XyTa7WOYK3vHB VXM5Hx3ZneHlZjjuSawMysj9wallxohe7gDyAL/szxTaWg8GdrZ01GJjd977q7UoP73vkT+I hDGF4V0zr0b+lk9akD9+OFBDcQFRA=; 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 1/3] tty: n_gsm: add keep alive support Date: Wed, 1 Feb 2023 09:01:49 +0100 Message-Id: <20230201080151.2068-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?1756615339866595333?= X-GMAIL-MSGID: =?utf-8?q?1756615339866595333?= From: Daniel Starke n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010. See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516 The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to the newer 27.010 here. Chapters 5.4.6.3.4 and 5.1.8.1.3 describe the test command which can be used to test the mux connection between both sides. Currently, no algorithm is implemented to make use of this command. This requires that each multiplexed upper layer protocol supervises the underlying muxer connection to handle possible connection losses. Introduce an ioctl parameter and functions to optionally enable keep alive handling via the test command as described in chapter 5.4.6.3.4. A single incrementing octet is being used to distinguish between multiple retries. Retry count and interval are taken from the general parameters N2 and T2. Note that support for the test command is mandatory and already present in the muxer implementation since the very first version. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 89 +++++++++++++++++++++++++++++++++---- include/uapi/linux/gsmmux.h | 3 +- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5783801d6524..98577b54f1fd 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -318,13 +318,19 @@ struct gsm_mux { struct gsm_control *pending_cmd;/* Our current pending command */ spinlock_t control_lock; /* Protects the pending command */ + /* Keep-alive */ + struct timer_list ka_timer; /* Keep-alive response timer */ + u8 ka_num; /* Keep-alive match pattern */ + int ka_retries; /* Keep-alive retry counter */ + /* Configuration */ - int adaption; /* 1 or 2 supported */ - u8 ftype; /* UI or UIH */ - int t1, t2; /* Timers in 1/100th of a sec */ - unsigned int t3; /* Power wake-up timer in seconds. */ - int n2; /* Retry count */ - u8 k; /* Window size */ + int adaption; /* 1 or 2 supported */ + u8 ftype; /* UI or UIH */ + int t1, t2; /* Timers in 1/100th of a sec */ + unsigned int t3; /* Power wake-up timer in seconds. */ + int n2; /* Retry count */ + u8 k; /* Window size */ + unsigned int keep_alive; /* Control channel keep-alive in ms */ /* Statistics (not currently exposed) */ unsigned long bad_fcs; @@ -1897,11 +1903,13 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, const u8 *data, int clen) { struct gsm_control *ctrl; + struct gsm_dlci *dlci; unsigned long flags; spin_lock_irqsave(&gsm->control_lock, flags); ctrl = gsm->pending_cmd; + dlci = gsm->dlci[0]; command |= 1; /* Does the reply match our command */ if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { @@ -1916,10 +1924,57 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, /* Or did we receive the PN response to our PN command */ } else if (command == CMD_PN) { gsm_control_negotiation(gsm, 0, data, clen); + /* Or did we receive the TEST response to our TEST command */ + } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { + gsm->ka_retries = -1; /* trigger new keep-alive message */ + if (dlci && !dlci->dead) + mod_timer(&gsm->ka_timer, + jiffies + gsm->keep_alive * HZ / 100); } spin_unlock_irqrestore(&gsm->control_lock, flags); } +/** + * gsm_control_keep_alive - check timeout or start keep-alive + * @t: timer contained in our gsm object + * + * Called off the keep-alive timer expiry signaling that our link + * partner is not responding anymore. Link will be closed. + * This is also called to startup our timer. + */ + +static void gsm_control_keep_alive(struct timer_list *t) +{ + struct gsm_mux *gsm = from_timer(gsm, t, ka_timer); + unsigned long flags; + + spin_lock_irqsave(&gsm->control_lock, flags); + if (gsm->ka_num && gsm->ka_retries == 0) { + /* Keep-alive expired -> close the link */ + if (debug & DBG_ERRORS) + pr_info("%s keep-alive timed out\n", __func__); + spin_unlock_irqrestore(&gsm->control_lock, flags); + if (gsm->dlci[0]) + gsm_dlci_begin_close(gsm->dlci[0]); + } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { + if (gsm->ka_retries > 0) { + /* T2 expired for keep-alive -> resend */ + gsm->ka_retries--; + } else { + /* Start keep-alive timer */ + gsm->ka_num++; + if (!gsm->ka_num) + gsm->ka_num++; + gsm->ka_retries = gsm->n2; + } + gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, + sizeof(gsm->ka_num)); + mod_timer(&gsm->ka_timer, + jiffies + gsm->t2 * HZ / 100); + spin_unlock_irqrestore(&gsm->control_lock, flags); + } +} + /** * gsm_control_transmit - send control packet * @gsm: gsm mux @@ -2061,8 +2116,10 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) /* Ensure that gsmtty_open() can return. */ tty_port_set_initialized(&dlci->port, false); wake_up_interruptible(&dlci->port.open_wait); - } else + } else { + del_timer(&dlci->gsm->ka_timer); dlci->gsm->dead = true; + } /* A DLCI 0 close is a MUX termination so we need to kick that back to userspace somehow */ gsm_dlci_data_kick(dlci); @@ -2078,6 +2135,8 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) static void gsm_dlci_open(struct gsm_dlci *dlci) { + struct gsm_mux *gsm = dlci->gsm; + /* Note that SABM UA .. SABM UA first UA lost can mean that we go open -> open */ del_timer(&dlci->t1); @@ -2087,8 +2146,15 @@ static void gsm_dlci_open(struct gsm_dlci *dlci) if (debug & DBG_ERRORS) pr_debug("DLCI %d goes open.\n", dlci->addr); /* Send current modem state */ - if (dlci->addr) + if (dlci->addr) { gsm_modem_update(dlci, 0); + } else { + /* Start keep-alive control */ + gsm->ka_num = 0; + gsm->ka_retries = -1; + mod_timer(&gsm->ka_timer, + jiffies + gsm->keep_alive * HZ / 100); + } gsm_dlci_data_kick(dlci); wake_up(&dlci->gsm->event); } @@ -2840,6 +2906,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) /* Finish outstanding timers, making sure they are done */ del_timer_sync(&gsm->kick_timer); del_timer_sync(&gsm->t2_timer); + del_timer_sync(&gsm->ka_timer); /* Finish writing to ldisc */ flush_work(&gsm->tx_work); @@ -2987,6 +3054,7 @@ static struct gsm_mux *gsm_alloc_mux(void) INIT_LIST_HEAD(&gsm->tx_data_list); timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); + timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); INIT_WORK(&gsm->tx_work, gsmld_write_task); init_waitqueue_head(&gsm->event); spin_lock_init(&gsm->control_lock); @@ -3003,6 +3071,7 @@ static struct gsm_mux *gsm_alloc_mux(void) gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ gsm->mtu = 64; gsm->dead = true; /* Avoid early tty opens */ + gsm->keep_alive = 0; /* Disabled */ /* Store the instance to the mux array or abort if no space is * available. @@ -3046,6 +3115,7 @@ static void gsm_copy_config_values(struct gsm_mux *gsm, c->mru = gsm->mru; c->mtu = gsm->mtu; c->k = gsm->k; + c->keep_alive = gsm->keep_alive; } static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) @@ -3094,6 +3164,8 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) need_restart = 1; if (c->mtu != gsm->mtu) need_restart = 1; + if (c->keep_alive != gsm->keep_alive) + need_restart = true; /* * Close down what is needed, restart and initiate the new @@ -3109,6 +3181,7 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; gsm->adaption = c->adaption; gsm->n2 = c->n2; + gsm->keep_alive = c->keep_alive; if (c->i == 1) gsm->ftype = UIH; diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index cb8693b39cb7..b64360aca1f9 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -19,7 +19,8 @@ struct gsm_config unsigned int mtu; unsigned int k; unsigned int i; - unsigned int unused[8]; /* Padding for expansion without + unsigned int keep_alive; + unsigned int unused[7]; /* Padding for expansion without breaking stuff */ }; From patchwork Wed Feb 1 08:01:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 51218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp145222wrn; Wed, 1 Feb 2023 00:09:00 -0800 (PST) X-Google-Smtp-Source: AK7set+LEwoTuqhxCiUe+vpQAtCOEdsrDqZ9T37WhQw6MQZB2zfQ7oQReUuYAkFmz6+XKo749+rE X-Received: by 2002:a05:6a20:8b9e:b0:b8:bc13:c838 with SMTP id m30-20020a056a208b9e00b000b8bc13c838mr1451516pzh.53.1675238940582; Wed, 01 Feb 2023 00:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675238940; cv=none; d=google.com; s=arc-20160816; b=0A4G2ZvVqSQCst2AvxpxUcE8B+wwb/Wc2w9X7AGMNfxayoGl2H7dMyGo0IJqAq+O4R 8uf1Fpu4RMQWAt6jOywQdwOKoUS77Vyc8fWYD1+iGMLDiIFkpQV4qf1MrXjz1y8Ctti8 CgsIiMO6ud8dmj7VmpN7EPUEqdjEiBP2litE9JfkPLIXwX+z8W34XtznesH8w0IkpDmb j7NRARQLLT7zMM0rGHmFIs0PZu+kXMXGkPSxnc4rkkxm8lryKZvaeBnz7WzIKvAb0W9A dVTWpsPI4F3shZlmuwz6s2yYI/0efsz4n5J3Sz3KoAr1QxuCT1x2nBsWfoCMSU8pM/sq F3kQ== 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=elcIhDVoOIB5QTRWadNTq7kGuOttosLIVV3EInhEIOg=; b=CYs70aSzBokYlCd29JOt9W0s1njOOugjEIOrTAb7IlUQ648lgoSfNMSo9JBr+oFdmU YeD40gy7a1w9RDZo6U3C0XJnm0VdIEpQhfr3xc5U9+ARBB/lvh1KDv+YMGDOfQJUT0Wr SZuolxjzjX7ZhUuFrDTmMYqfsz9yVFtQVDiXIB0/1Vcq2f5yYxwnbjY8J0Jkzt+hxxAd z0c/KQBfpeevHeleaXBR1ARdp61QDZwIp70STaPoduPgWpWQk5X0RKfSS7Kcippppig/ YdHhSsPjTd3jv2GxJ2AuI5zWr5cDilXwz/SA+Ou0WOUB5y7JM2KqjHQ/RDzTZtnyexed S5rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=QJe70xUc; 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 m18-20020a637112000000b004df4af6841asi17459801pgc.84.2023.02.01.00.08.48; Wed, 01 Feb 2023 00:09:00 -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=QJe70xUc; 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 S231252AbjBAIDR (ORCPT + 99 others); Wed, 1 Feb 2023 03:03:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbjBAIDL (ORCPT ); Wed, 1 Feb 2023 03:03:11 -0500 Received: from mta-64-227.siemens.flowmailer.net (mta-64-227.siemens.flowmailer.net [185.136.64.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC9E6A5CA for ; Wed, 1 Feb 2023 00:03:06 -0800 (PST) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20230201080303835fe8e237f386372a for ; Wed, 01 Feb 2023 09:03:03 +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=elcIhDVoOIB5QTRWadNTq7kGuOttosLIVV3EInhEIOg=; b=QJe70xUcaVZtN3xPn+QwR2XYEcGRuSBwTC2ObW7olOzpwnfJc5IaGj+3/eQmFMfHqcztxI 0FdkTBkwL9U5auLn8njpo0dqTsVOYZRs1JH6V0wchnd0LvBi3uAR13SH4h1LbdK91tTkF70R wcdijkWIqqQawVw0xlj6s9rf07foM=; 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 2/3] tty: n_gsm: add RING/CD control support Date: Wed, 1 Feb 2023 09:01:50 +0100 Message-Id: <20230201080151.2068-2-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 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?1756615347190366751?= X-GMAIL-MSGID: =?utf-8?q?1756615347190366751?= From: Daniel Starke The status lines ring and carrier detect are used by the modem to signal incoming calls (RING) or an established connection (CD). This is implemented as physical lines on a standard RS232 connection. However, the muxer protocol encodes these status lines as modem bits IC and DV. These incoming lines are masked by tty driver (see tty_io.c) and cannot be set by a user application. Allow setting RING via TIOCM_OUT1 and CD via TIOCM_OUT2 to allow implementation of a modem or modem emulator. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 98577b54f1fd..118511c1fa37 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -546,6 +546,11 @@ static u8 gsm_encode_modem(const struct gsm_dlci *dlci) modembits |= MDM_IC; if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) modembits |= MDM_DV; + /* special mappings for passive side to operate as UE */ + if (dlci->modem_tx & TIOCM_OUT1) + modembits |= MDM_IC; + if (dlci->modem_tx & TIOCM_OUT2) + modembits |= MDM_DV; return modembits; } From patchwork Wed Feb 1 08:01:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 51214 Return-Path: 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 + 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 ); 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 ; Wed, 1 Feb 2023 00:03:06 -0800 (PST) Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 202302010803040276ac9c295431dc68 for ; 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" 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 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 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?1756615266506197867?= X-GMAIL-MSGID: =?utf-8?q?1756615266506197867?= 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. Signed-off-by: Daniel Starke --- 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 + * @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; }