From patchwork Wed May 17 15:56:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 379F7C77B7F for ; Wed, 17 May 2023 15:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231622AbjEQP6h (ORCPT ); Wed, 17 May 2023 11:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbjEQP6f (ORCPT ); Wed, 17 May 2023 11:58:35 -0400 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 B27B91724 for ; Wed, 17 May 2023 08:58:29 -0700 (PDT) Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20230517155826de848ee94e0e735b0f for ; Wed, 17 May 2023 17:58:26 +0200 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=myO+P8WOEjna9leIj0Mi2o9ZV1FzreaUuCy/6birCxg=; b=h3OcECnT2RGiwr8E/X3Favf64LAC/N6yEQ2xq/npJpR5AyqhgZAu5fG3ZH8xpYBRo1jNlM 747whGj63viyftONRAziDSdytMJNK+SJ97KtC6j0dQs9hSv+u9HPd5bHvzk/BRBO+pwWYQT7 I3eOpTDThIN85c2OlwXNn5ZV4fx+E=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 01/10] tty: n_gsm: add restart flag to DLC specific ioctl config Date: Wed, 17 May 2023 17:56:55 +0200 Message-Id: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke Currently, changing the parameters of a DLCI gives no direct control to the user whether this should trigger a channel reset or not. The decision is solely made by the driver based on the assumption which parameter changes are compatible or not. Therefore, the user has no means to perform an automatic channel reset after parameter configuration for non-conflicting changes. Add the parameter 'flags' to 'gsm_dlci_config' to force a channel reset after ioctl setting regardless of whether the changes made require this or not by setting this to 'GSM_FL_RESTART'. Note that 'GSM_FL_RESTART' is currently the only allow flag to allow additions here. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 4 ++++ include/uapi/linux/gsmmux.h | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) v4 -> v5: Changed GSM_FL_RESTART comment to be more specific about its use as suggested in the review comment. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/DB9PR10MB5881B63FBBA7912DF5A7A6A8E0789@DB9PR10MB5881.EURPRD10.PROD.OUTLOOK.COM/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index b411a26cc092..66edcf65a4dd 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2532,6 +2532,8 @@ static int gsm_dlci_config(struct gsm_dlci *dlci, struct gsm_dlci_config *dc, in return -EINVAL; if (dc->k > 7) return -EINVAL; + if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ + return -EINVAL; /* * See what is needed for reconfiguration @@ -2546,6 +2548,8 @@ static int gsm_dlci_config(struct gsm_dlci *dlci, struct gsm_dlci_config *dc, in /* Requires care */ if (dc->priority != dlci->prio) need_restart = true; + if (dc->flags & GSM_FL_RESTART) + need_restart = true; if ((open && gsm->wait_config) || need_restart) need_open = true; diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index eb67884e5f38..e56e2d7ea6eb 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -2,10 +2,22 @@ #ifndef _LINUX_GSMMUX_H #define _LINUX_GSMMUX_H +#include #include #include #include +/* + * flags definition for n_gsm + * + * Used by: + * struct gsm_dlci_config.flags + */ +/* Forces a DLCI reset if set. Otherwise, a DLCI reset is only done if + * incompatible settings were provided. Always cleared on retrieval. + */ +#define GSM_FL_RESTART _BITUL(0) + struct gsm_config { unsigned int adaption; @@ -58,7 +70,8 @@ struct gsm_dlci_config { __u32 priority; /* Priority (0 for default value) */ __u32 i; /* Frame type (1 = UIH, 2 = UI) */ __u32 k; /* Window size (0 for default value) */ - __u32 reserved[8]; /* For future use, must be initialized to zero */ + __u32 flags; /* DLCI specific flags. */ + __u32 reserved[7]; /* For future use, must be initialized to zero */ }; #define GSMIOC_GETCONF_DLCI _IOWR('G', 7, struct gsm_dlci_config) From patchwork Wed May 17 15:56:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89594C77B7A for ; Wed, 17 May 2023 15:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjEQP6g (ORCPT ); Wed, 17 May 2023 11:58:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbjEQP6f (ORCPT ); Wed, 17 May 2023 11:58:35 -0400 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 B41FD5FC4 for ; Wed, 17 May 2023 08:58:29 -0700 (PDT) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 202305171558278b63668634e5926596 for ; Wed, 17 May 2023 17:58:27 +0200 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=OXqc2YuyxMs+ABmAjJ+9qlfVsi/iQdg+2Fg6AhB/Pzg=; b=UnHYpu9kzd4Vn0PK8DuM3EXGSfJPqUwmsiLTjiu+HrNrRARSJxEleMiizc94jFooCmByBm qaj6DNUBsAD8eCXF4+ArWZ7lKRUDXtWpiLLRkrft7MVGaVGhY2bGTl6buRjoQm6t7erVVVDt iNHgLvBsbKzqxXx5FS+pzps3tdYV4=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 02/10] tty: n_gsm: add missing description to structs in gsmmux.h Date: Wed, 17 May 2023 17:56:56 +0200 Message-Id: <20230517155704.5701-2-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke Currently, all available structure fields in gsmmux.h except those for gsm_config are commented. Furthermore, no kernel doc comments are used. Fix this by adding appropriate comments to the not commented fields of gsm_config. Convert the comments of the other structs to kernel doc format. Note that 'mru' and 'mtu' refer to the size without basic/advanced option mode header and byte stuffing as defined in the standard in chapter 5.7.2. Link: https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516 Signed-off-by: Daniel Starke --- include/uapi/linux/gsmmux.h | 104 +++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 20 deletions(-) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-2-daniel.starke@siemens.com/ diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index e56e2d7ea6eb..3bd6f03a8293 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -18,6 +18,28 @@ */ #define GSM_FL_RESTART _BITUL(0) +/** + * struct gsm_config - n_gsm basic configuration parameters + * + * This structure is used in combination with GSMIOC_GETCONF and GSMIOC_SETCONF + * to retrieve and set the basic parameters of an n_gsm ldisc. + * struct gsm_config_ext can be used to configure extended ldisc parameters. + * + * All timers are in units of 1/100th of a second. + * + * @adaption: Convergence layer type + * @encapsulation: Framing (0 = basic option, 1 = advanced option) + * @initiator: Initiator or responder + * @t1: Acknowledgment timer + * @t2: Response timer for multiplexer control channel + * @t3: Response timer for wake-up procedure + * @n2: Maximum number of retransmissions + * @mru: Maximum incoming frame payload size + * @mtu: Maximum outgoing frame payload size + * @k: Window size + * @i: Frame type (1 = UIH, 2 = UI) + * @unused: Can not be used + */ struct gsm_config { unsigned int adaption; @@ -31,18 +53,32 @@ struct gsm_config unsigned int mtu; unsigned int k; unsigned int i; - unsigned int unused[8]; /* Can not be used */ + unsigned int unused[8]; }; #define GSMIOC_GETCONF _IOR('G', 0, struct gsm_config) #define GSMIOC_SETCONF _IOW('G', 1, struct gsm_config) +/** + * struct gsm_netconfig - n_gsm network configuration parameters + * + * This structure is used in combination with GSMIOC_ENABLE_NET and + * GSMIOC_DISABLE_NET to enable or disable a network data connection + * over a mux virtual tty channel. This is for modems that support + * data connections with raw IP frames instead of PPP. + * + * @adaption: Adaption to use in network mode. + * @protocol: Protocol to use - only ETH_P_IP supported. + * @unused2: Can not be used. + * @if_name: Interface name format string. + * @unused: Can not be used. + */ struct gsm_netconfig { - unsigned int adaption; /* Adaption to use in network mode */ - unsigned short protocol;/* Protocol to use - only ETH_P_IP supported */ - unsigned short unused2; /* Can not be used */ - char if_name[IFNAMSIZ]; /* interface name format string */ - __u8 unused[28]; /* Can not be used */ + unsigned int adaption; + unsigned short protocol; + unsigned short unused2; + char if_name[IFNAMSIZ]; + __u8 unused[28]; }; #define GSMIOC_ENABLE_NET _IOW('G', 2, struct gsm_netconfig) @@ -51,27 +87,55 @@ struct gsm_netconfig { /* get the base tty number for a configured gsmmux tty */ #define GSMIOC_GETFIRST _IOR('G', 4, __u32) +/** + * struct gsm_config_ext - n_gsm extended configuration parameters + * + * This structure is used in combination with GSMIOC_GETCONF_EXT and + * GSMIOC_SETCONF_EXT to retrieve and set the extended parameters of an + * n_gsm ldisc. + * + * All timers are in units of 1/100th of a second. + * + * @keep_alive: Control channel keep-alive in 1/100th of a second (0 to disable). + * @wait_config: Wait for DLCI config before opening virtual link? + * @reserved: For future use, must be initialized to zero. + */ struct gsm_config_ext { - __u32 keep_alive; /* Control channel keep-alive in 1/100th of a - * second (0 to disable) - */ - __u32 wait_config; /* Wait for DLCI config before opening virtual link? */ - __u32 reserved[6]; /* For future use, must be initialized to zero */ + __u32 keep_alive; + __u32 wait_config; + __u32 reserved[6]; }; #define GSMIOC_GETCONF_EXT _IOR('G', 5, struct gsm_config_ext) #define GSMIOC_SETCONF_EXT _IOW('G', 6, struct gsm_config_ext) -/* Set channel accordingly before calling GSMIOC_GETCONF_DLCI. */ +/** + * struct gsm_dlci_config - n_gsm channel configuration parameters + * + * This structure is used in combination with GSMIOC_GETCONF_DLCI and + * GSMIOC_SETCONF_DLCI to retrieve and set the channel specific parameters + * of an n_gsm ldisc. + * + * Set the channel accordingly before calling GSMIOC_GETCONF_DLCI. + * + * @channel: DLCI (0 for the associated DLCI). + * @adaption: Convergence layer type. + * @mtu: Maximum transfer unit. + * @priority: Priority (0 for default value). + * @i: Frame type (1 = UIH, 2 = UI). + * @k: Window size (0 for default value). + * @flags: DLCI specific flags. + * @reserved: For future use, must be initialized to zero. + */ struct gsm_dlci_config { - __u32 channel; /* DLCI (0 for the associated DLCI) */ - __u32 adaption; /* Convergence layer type */ - __u32 mtu; /* Maximum transfer unit */ - __u32 priority; /* Priority (0 for default value) */ - __u32 i; /* Frame type (1 = UIH, 2 = UI) */ - __u32 k; /* Window size (0 for default value) */ - __u32 flags; /* DLCI specific flags. */ - __u32 reserved[7]; /* For future use, must be initialized to zero */ + __u32 channel; + __u32 adaption; + __u32 mtu; + __u32 priority; + __u32 i; + __u32 k; + __u32 flags; + __u32 reserved[7]; }; #define GSMIOC_GETCONF_DLCI _IOWR('G', 7, struct gsm_dlci_config) From patchwork Wed May 17 15:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 620C4C77B75 for ; Wed, 17 May 2023 15:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjEQP6y (ORCPT ); Wed, 17 May 2023 11:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbjEQP6i (ORCPT ); Wed, 17 May 2023 11:58:38 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D73040EF for ; Wed, 17 May 2023 08:58:29 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 202305171558275de52a7b8d6f9c52ba for ; Wed, 17 May 2023 17:58:28 +0200 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=hLYDLew2BnYtz1yW2u/0Fx5TXlG323HFpawW+DCWpzs=; b=Fqfhp1cD0EJa9fFC2xJ8Z/9CSQcupvI8O/bp8c5vIAutEnR19ycF8fvP4O+gmlkgOXkf/n lrRDLnfjngvNIs/8gf95e539zjWt88BJ8mhLaEMzCk9Xox9AADDI9OtfmX6/PNMa9RoNpiPU xjH1rHgia9rJCIlM1UatJ154LFEpU=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 03/10] tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config Date: Wed, 17 May 2023 17:56:57 +0200 Message-Id: <20230517155704.5701-3-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke The variable 'ret' is not used before assignment from gsm_activate_mux(). Still it gets initialized to zero at declaration. Fix this as remarked in the link below by moving the declaration to the first assignment. Link: https://lore.kernel.org/all/b42bc4d1-cc9d-d115-c981-aaa053bdc59f@kernel.org/ Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-3-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 66edcf65a4dd..ebb71957f783 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3277,7 +3277,6 @@ static void gsm_copy_config_values(struct gsm_mux *gsm, static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) { - int ret = 0; int need_close = 0; int need_restart = 0; @@ -3356,7 +3355,7 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) * and removing from the mux array */ if (gsm->dead) { - ret = gsm_activate_mux(gsm); + int ret = gsm_activate_mux(gsm); if (ret) return ret; if (gsm->initiator) From patchwork Wed May 17 15:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9DA5C7EE23 for ; Wed, 17 May 2023 15:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbjEQP6i (ORCPT ); Wed, 17 May 2023 11:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbjEQP6h (ORCPT ); Wed, 17 May 2023 11:58:37 -0400 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 700EE55AE for ; Wed, 17 May 2023 08:58:30 -0700 (PDT) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20230517155828dfba45f4a01c2f7f75 for ; Wed, 17 May 2023 17:58:28 +0200 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=NAdU0ZFkKL/GxTNJIYcpoMVLuevkFQ3Dl3nGDNVQ2BE=; b=CtvJC2T0MgZgMjGIQvNbo1nopjh3gRiRhHZp5Vy3jg3TSKm3bMkMaemumLw0IUD8EZgYHU 3gm8oN5jUrTdYn5CPB42c9LKYWOFFE90dusFscLuP+4t6AAfGroGPYz4CpDoRo0lieWU3enU mLkMGmCYvZagE8c03kxMuCjlnzMoE=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 04/10] tty: n_gsm: add open_error counter to gsm_mux Date: Wed, 17 May 2023 17:56:58 +0200 Message-Id: <20230517155704.5701-4-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke Extend the n_gsm link statistics by a failed link open counter in preparation for an upcoming patch which will expose these. This counter is increased whenever an attempt to open the control channel failed. This is true in the following cases: - new DLCI allocation failed - connection request (SAMB) with invalid CR flag has been received - connection response (UA) timed out - parameter negotiation timed out or failed Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-4-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index ebb71957f783..186f463f0f11 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -339,6 +339,7 @@ struct gsm_mux { unsigned long bad_fcs; unsigned long malformed; unsigned long io_error; + unsigned long open_error; unsigned long bad_size; unsigned long unsupported; }; @@ -1730,25 +1731,32 @@ static void gsm_control_negotiation(struct gsm_mux *gsm, unsigned int cr, struct gsm_dlci *dlci; struct gsm_dlci_param_bits *params; - if (dlen < sizeof(struct gsm_dlci_param_bits)) + if (dlen < sizeof(struct gsm_dlci_param_bits)) { + gsm->open_error++; return; + } /* Invalid DLCI? */ params = (struct gsm_dlci_param_bits *)data; addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); - if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) + if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { + gsm->open_error++; return; + } dlci = gsm->dlci[addr]; /* Too late for parameter negotiation? */ - if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) + if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { + gsm->open_error++; return; + } /* Process the received parameters */ if (gsm_process_negotiation(gsm, addr, cr, params) != 0) { /* Negotiation failed. Close the link. */ if (debug & DBG_ERRORS) pr_info("%s PN failed\n", __func__); + gsm->open_error++; gsm_dlci_close(dlci); return; } @@ -1768,6 +1776,7 @@ static void gsm_control_negotiation(struct gsm_mux *gsm, unsigned int cr, } else { if (debug & DBG_ERRORS) pr_info("%s PN in invalid state\n", __func__); + gsm->open_error++; } } @@ -2221,6 +2230,7 @@ static void gsm_dlci_t1(struct timer_list *t) dlci->retries--; mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } else { + gsm->open_error++; gsm_dlci_begin_close(dlci); /* prevent half open link */ } break; @@ -2236,6 +2246,7 @@ static void gsm_dlci_t1(struct timer_list *t) dlci->mode = DLCI_MODE_ADM; gsm_dlci_open(dlci); } else { + gsm->open_error++; gsm_dlci_begin_close(dlci); /* prevent half open link */ } @@ -2757,12 +2768,16 @@ static void gsm_queue(struct gsm_mux *gsm) switch (gsm->control) { case SABM|PF: - if (cr == 1) + if (cr == 1) { + gsm->open_error++; goto invalid; + } if (dlci == NULL) dlci = gsm_dlci_alloc(gsm, address); - if (dlci == NULL) + if (dlci == NULL) { + gsm->open_error++; return; + } if (dlci->dead) gsm_response(gsm, address, DM|PF); else { From patchwork Wed May 17 15:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 148C6C77B7F for ; Wed, 17 May 2023 15:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231676AbjEQP6z (ORCPT ); Wed, 17 May 2023 11:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjEQP6y (ORCPT ); Wed, 17 May 2023 11:58:54 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC17A72B2 for ; Wed, 17 May 2023 08:58:30 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20230517155829cf70f7be4e52fa5dd1 for ; Wed, 17 May 2023 17:58:29 +0200 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=E9IwZtdfkhkPpswS1gYiZOwz+Ap7dZzs6d4A7WBwoPE=; b=ioRufgCk8NB5DNeaUoJVm9cmWHMmWgBGFMClospy6Ao5HltN4+fhPsfdnk4znAq71vXbac tgRBS3uEJXEPJHwq1kSKiEsSR4ARUTcXTw00Vqz7NEKYYXdkewOrGg9tEZMXsK+mLwjlZzCY inSnh6ULQ45hbJaaWRWJY9ewOoBpc=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 05/10] tty: n_gsm: increase malformed counter for malformed control frames Date: Wed, 17 May 2023 17:56:59 +0200 Message-Id: <20230517155704.5701-5-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke The malformed counter in gsm_mux is already increased in case of errors detected in gsm_queue() and gsm1_receive(). gsm_dlci_command() also detects a case for a malformed frame but does not increase the malformed counter yet. Fix this by also increasing the gsm_mux malformed counter in case of a malformed frame in gsm_dlci_command(). Note that the malformed counter is not yet exposed and only set internally. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-5-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 186f463f0f11..5b6a03668c78 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2455,8 +2455,10 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len) data += dlen; /* Malformed command? */ - if (clen > len) + if (clen > len) { + dlci->gsm->malformed++; return; + } if (command & 1) gsm_control_message(dlci->gsm, command, data, clen); From patchwork Wed May 17 15:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06A65C77B7F for ; Wed, 17 May 2023 15:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232037AbjEQP7A (ORCPT ); Wed, 17 May 2023 11:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjEQP6y (ORCPT ); Wed, 17 May 2023 11:58:54 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E627DAA for ; Wed, 17 May 2023 08:58:31 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 202305171558295a5879b3ee6acdab54 for ; Wed, 17 May 2023 17:58:29 +0200 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=ZT7+g7B3Lbu99drej4ZddyowwBxP0nuUx4VS88186Es=; b=OTmSarLUw0pA6xy7u7l5FKpEmDX8pQVAYcMCiPvj+Ym0KglLFhEbIYSI5nHazJw1MZDMwZ 0rRkoy2A9ftyynVqELLWBaJVUfAg+ithhLgwK91W35/0K1Q3c6vcyTUp1CSWL5MQ09Pmgykr MdNtXdpV6aK7mbTefE9a9Yk+KauzU=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 06/10] tty: n_gsm: increase gsm_mux unsupported counted where appropriate Date: Wed, 17 May 2023 17:57:00 +0200 Message-Id: <20230517155704.5701-6-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke The structure gsm_mux contains the 'unsupported' field. However, there is currently no place in the code which increases this counter. Increase the 'unsupported' statistics counter in the following case: - an unsupported frame type has been requested by the peer via parameter negotiation - a control frame with an unsupported but known command has been received Note that we have no means to detect an inconsistent/unsupported adaptation sufficient accuracy as this changes the structure of the UI/UIH frames. E.g. a one byte header is added in case of convergence layer type 2 instead of 1 and contains the modem signal octet with the state of the signal lines. There is no checksum or other value which indicates of this field is correct or should be present. Therefore, we can only assume protocol correctness here. See also 'gsm_dlci_data()' where this is handled. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 3 +++ 1 file changed, 3 insertions(+) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-6-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5b6a03668c78..42a8507aae4a 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1590,6 +1590,7 @@ static int gsm_process_negotiation(struct gsm_mux *gsm, unsigned int addr, if (debug & DBG_ERRORS) pr_info("%s unsupported I frame request in PN\n", __func__); + gsm->unsupported++; return -EINVAL; default: if (debug & DBG_ERRORS) @@ -1897,6 +1898,8 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, /* Optional unsupported commands */ case CMD_RPN: /* Remote port negotiation */ case CMD_SNC: /* Service negotiation command */ + gsm->unsupported++; + fallthrough; default: /* Reply to bad commands with an NSC */ buf[0] = command; From patchwork Wed May 17 15:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72CDDC77B7A for ; Wed, 17 May 2023 15:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbjEQP7F (ORCPT ); Wed, 17 May 2023 11:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjEQP7A (ORCPT ); Wed, 17 May 2023 11:59:00 -0400 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 8C1407DA1 for ; Wed, 17 May 2023 08:58:34 -0700 (PDT) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 2023051715583076c3e5effb9f815987 for ; Wed, 17 May 2023 17:58:30 +0200 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=8JZ3aNj2YfHl3YwKHBbNEj8X9wcN9oM57BAa2nlT+Po=; b=ABTv8j70Np0JRokN+q2Jfx+1JhRLSh7J7PBOYernGtJzjh9JrozrFbXSB8JOIX29YvhnwD dE4QNPFJUV03D8FpAuYyTXbLPlkgCG50l+RouAdDcMAyIkmK8oenN3gnN7aMJ2ZzhV/FD/lX TgwG3yiwuvWSoMfXqo5rwXqbVqg3c=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 07/10] tty: n_gsm: cleanup gsm_control_command and gsm_control_reply Date: Wed, 17 May 2023 17:57:01 +0200 Message-Id: <20230517155704.5701-7-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke There are multiple places in gsm_control_command and gsm_control_reply that derive the specific DLCI handle directly out of the DLCI table in gsm. Add a local variable which holds this handle and use it instead to improve code readability. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) v4 -> v5: No changes. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/20230426080315.7595-7-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 42a8507aae4a..62bff4474b57 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1451,15 +1451,16 @@ static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, int dlen) { struct gsm_msg *msg; + struct gsm_dlci *dlci = gsm->dlci[0]; - msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->dlci[0]->ftype); + msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); if (msg == NULL) return -ENOMEM; msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ msg->data[1] = (dlen << 1) | EA; memcpy(msg->data + 2, data, dlen); - gsm_data_queue(gsm->dlci[0], msg); + gsm_data_queue(dlci, msg); return 0; } @@ -1478,14 +1479,15 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, int dlen) { struct gsm_msg *msg; + struct gsm_dlci *dlci = gsm->dlci[0]; - msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->dlci[0]->ftype); + msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); if (msg == NULL) return; msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ msg->data[1] = (dlen << 1) | EA; memcpy(msg->data + 2, data, dlen); - gsm_data_queue(gsm->dlci[0], msg); + gsm_data_queue(dlci, msg); } /** From patchwork Wed May 17 15:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3605C77B7A for ; Wed, 17 May 2023 15:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbjEQP7B (ORCPT ); Wed, 17 May 2023 11:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231941AbjEQP6y (ORCPT ); Wed, 17 May 2023 11:58:54 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41B59728A for ; Wed, 17 May 2023 08:58:33 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 2023051715583118a1465d4bce0a9f52 for ; Wed, 17 May 2023 17:58:31 +0200 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=Sa2/lDymF7guLu5/iTBwB/pVI82RAGaOTwCGzH2ZfJs=; b=GGbH5S9CVsn0iyn2AM467c9w4vL3Ia8lP4NQfMoFErGuzQ9vWcRrvigDC/YCnFkNy0ovoD 6NLoU6f4pviCO6yg2TCfBg2K0TCGQb1bv+UwaHmGcReOhouc2p3s/Vf94URSYEU8vbJajS+U IXTkWiALiGAJtR4DlF9uPIYctR8wg=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 08/10] tty: n_gsm: add DLCI specific rx/tx statistics Date: Wed, 17 May 2023 17:57:02 +0200 Message-Id: <20230517155704.5701-8-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke Add counters for the number of data bytes received/transmitted per DLCI in for preparation for an upcoming patch which will expose these values to the user. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) v4 -> v5: Added blank line before comment of new tx/rx fields in struct gsm_dlci as suggested in the review. The remarked upcoming patch which exposes these flags is now included in patch 9/10. This has been done as recommended in the review. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/DB9PR10MB5881A7A09725EAF8FDB5F35BE0789@DB9PR10MB5881.EURPRD10.PROD.OUTLOOK.COM/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 62bff4474b57..511f22489754 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -186,6 +186,10 @@ struct gsm_dlci { void (*data)(struct gsm_dlci *dlci, const u8 *data, int len); void (*prev_data)(struct gsm_dlci *dlci, const u8 *data, int len); struct net_device *net; /* network interface, if created */ + + /* Statistics (not currently exposed) */ + u64 tx; /* Data bytes sent on this DLCI */ + u64 rx; /* Data bytes received on this DLCI */ }; /* @@ -1216,6 +1220,7 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) tty_port_tty_wakeup(&dlci->port); __gsm_data_queue(dlci, msg); + dlci->tx += len; /* Bytes of data we used up */ return size; } @@ -1283,6 +1288,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, memcpy(dp, dlci->skb->data, len); skb_pull(dlci->skb, len); __gsm_data_queue(dlci, msg); + dlci->tx += len; if (last) { dev_kfree_skb_any(dlci->skb); dlci->skb = NULL; @@ -1461,6 +1467,7 @@ static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, msg->data[1] = (dlen << 1) | EA; memcpy(msg->data + 2, data, dlen); gsm_data_queue(dlci, msg); + dlci->tx += dlen; return 0; } @@ -1488,6 +1495,7 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, msg->data[1] = (dlen << 1) | EA; memcpy(msg->data + 2, data, dlen); gsm_data_queue(dlci, msg); + dlci->tx += dlen; } /** @@ -1852,10 +1860,13 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, const u8 *data, int clen) { u8 buf[1]; + struct gsm_dlci *dlci = gsm->dlci[0]; + + if (dlci) + dlci->rx += clen; switch (command) { case CMD_CLD: { - struct gsm_dlci *dlci = gsm->dlci[0]; /* Modem wishes to close down */ if (dlci) { dlci->dead = true; @@ -1934,6 +1945,8 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, ctrl = gsm->pending_cmd; dlci = gsm->dlci[0]; + if (dlci) + dlci->rx += clen; command |= 1; /* Does the reply match our command */ if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { @@ -2298,6 +2311,9 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlci) need_pn = true; } + dlci->tx = 0; + dlci->rx = 0; + switch (dlci->state) { case DLCI_CLOSED: case DLCI_WAITING_CONFIG: @@ -2330,6 +2346,9 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlci) */ static void gsm_dlci_set_opening(struct gsm_dlci *dlci) { + dlci->tx = 0; + dlci->rx = 0; + switch (dlci->state) { case DLCI_CLOSED: case DLCI_WAITING_CONFIG: @@ -2349,6 +2368,9 @@ static void gsm_dlci_set_opening(struct gsm_dlci *dlci) */ static void gsm_dlci_set_wait_config(struct gsm_dlci *dlci) { + dlci->tx = 0; + dlci->rx = 0; + switch (dlci->state) { case DLCI_CLOSED: case DLCI_CLOSING: @@ -2425,6 +2447,7 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) fallthrough; case 1: /* Line state will go via DLCI 0 controls only */ default: + dlci->rx += clen; tty_insert_flip_string(port, data, clen); tty_flip_buffer_push(port); } @@ -2785,6 +2808,7 @@ static void gsm_queue(struct gsm_mux *gsm) gsm->open_error++; return; } + dlci->rx += gsm->len; if (dlci->dead) gsm_response(gsm, address, DM|PF); else { From patchwork Wed May 17 15:57:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 729E4C77B75 for ; Wed, 17 May 2023 15:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231993AbjEQP7G (ORCPT ); Wed, 17 May 2023 11:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbjEQP7A (ORCPT ); Wed, 17 May 2023 11:59:00 -0400 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 A031E7DB4 for ; Wed, 17 May 2023 08:58:34 -0700 (PDT) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 202305171558310addda4a0e58bc7b4c for ; Wed, 17 May 2023 17:58:31 +0200 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=I8rIrez1vOp3Ee2KwKlOwpZ0Tbuw1W2GBhq4oZuF5uE=; b=U3dT0lEv/7vXDxEa2b4ExjZOaQ6BgZLNqITOvBauRtuUiF7rnDZHSlc9pIhMevI9NSeHua 7ofnwszIsoQLYl5LcBeC6SW3oQzirPWxoKG+0k1BfwXkMcQ8x7hSKzYvCPXOaVuQWGVkmLcv sXiQ3CZlypLDEZ3YbQrI1f1s3NdCQ=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 09/10] tty: n_gsm: expose configuration and statistics via proc fs Date: Wed, 17 May 2023 17:57:03 +0200 Message-Id: <20230517155704.5701-9-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke The n_gsm mux collects various statistics about the mux and its channels. These are currently not exposed to the user. There exists already a proc fs path for tty ldiscs (/proc/tty/ldisc). Extend this path by an 'n_gsm' node and create a proc file for each mux instance if active. The file exposes protocol statistics and channel states and configuration to the user. Mutex based locks are introduced to avoid inconsistent states. The following shows an example output: tty:ttyS1 flags: initiator:1 mode:1 mru:64 mtu:64 t1:10 t2:34 t3:10 n2:3 k:2 wc:0 ka:100 bad_fcs:0 malformed:0 io_error:0 open_error:0 bad_size:0 unsupported:0 dlci:0 state:OPEN cl:2 prio:0 i:UIH k:2 mtu:64 tx:35 rx:35 Description: tty: The underlying device used by this mux. flags: Tty flags relevant to the mux protocol. initiator: 0 for responder, 1 for initiator. mode: 0 for basic option mode, 1 for advanced option mode mru: Maximum receive unit size. mtu: Maximum transmission unit size. t1: Acknowledgment timer. t2: Response timer for multiplexer control channel. t3: Response timer for wake-up procedure. n2: Maximum number of retransmissions. k: Window size. wc: Wait for configuration before starting parameter negotiation? ka: Control channel keep-alive timer (0 if disabled). bad_fcs: Number of bad FCS. malformed: Number of malformed frames. io_error: Number of I/O errors on the underlying tty. open_error: Number of failed DLCI open attempts. bad_size: Number of n_gsm frames with bad size. unsupported: Number of malformed control frames. dlci: Related channel number. state: Current channel state. Possible values are CLOSED, WAITING_CONFIG, CONFIGURE, OPENING, OPEN and CLOSING. cl: Convergence layer type. prio: Priority. i: Framing. Possible values are UI and UIH. k: Window size. mtu: Maximum transmission unit size. tx: Transmitted payload size in bytes (incl. convergence layer type header). rx: Received payload size in bytes (incl. convergence layer type header). All timers are in 1/100th of a second units. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 207 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 196 insertions(+), 11 deletions(-) v4 -> v5: Newly added patch to expose the collected statistics to the user via proc fs. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/DB9PR10MB5881A7A09725EAF8FDB5F35BE0789@DB9PR10MB5881.EURPRD10.PROD.OUTLOOK.COM/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 511f22489754..30f73ab2491f 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -46,10 +46,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -187,7 +189,7 @@ struct gsm_dlci { void (*prev_data)(struct gsm_dlci *dlci, const u8 *data, int len); struct net_device *net; /* network interface, if created */ - /* Statistics (not currently exposed) */ + /* Statistics (exposed via proc file) */ u64 tx; /* Data bytes sent on this DLCI */ u64 rx; /* Data bytes received on this DLCI */ }; @@ -272,6 +274,7 @@ enum gsm_mux_state { struct gsm_mux { struct tty_struct *tty; /* The tty our ldisc is bound to */ + struct proc_dir_entry *proc; /* Associated proc fs entry */ spinlock_t lock; struct mutex mutex; unsigned int num; @@ -339,7 +342,7 @@ struct gsm_mux { bool wait_config; /* Wait for configuration by ioctl before DLCI open */ u32 keep_alive; /* Control channel keep-alive in 10ms */ - /* Statistics (not currently exposed) */ + /* Statistics (exposed via proc file) */ unsigned long bad_fcs; unsigned long malformed; unsigned long io_error; @@ -357,6 +360,7 @@ struct gsm_mux { #define MAX_MUX 4 /* 256 minors */ static struct gsm_mux *gsm_mux[MAX_MUX]; /* GSM muxes */ static DEFINE_SPINLOCK(gsm_mux_lock); +static DEFINE_MUTEX(gsm_mux_mutex); static struct tty_driver *gsm_tty_driver; @@ -3079,6 +3083,153 @@ static void gsm_error(struct gsm_mux *gsm) gsm->io_error++; } +/* + * Entry to the proc file system in tty/ldisc/n_gsm/ + */ + +static struct proc_dir_entry *proc_gsm; + +/** + * gsm_proc_print_flag - check and print termios flag + * @m: output handle + * @flags: termios flags + * @val: flag to check and print + * @str: string representation of val + * @first: does not need separator? + */ +static bool gsm_proc_print_flag(struct seq_file *m, unsigned short flags, + int val, const char *str, bool first) +{ + if ((flags & val) == 0) + return first; + if (!first) + seq_putc(m, '|'); + seq_puts(m, str); + return false; +} + +#define gsm_proc_print_flag_str(m, flags, val) \ + (first = gsm_proc_print_flag((m), (flags), (val), __stringify(val), first)) + +/** + * gsm_proc_show - output proc file + * @m: output handle + * @v: result from start + * + * Handles the output of /proc/tty/ldisc/n_gsm/mux%d + */ +static int gsm_proc_show(struct seq_file *m, void *v) +{ + struct gsm_mux *gsm = m->private; + struct gsm_dlci *dlci = NULL; + unsigned short flags; + int i; + bool first = true; + const char *state, *ftype; + + if (!gsm) + return -ENODEV; + + /* The proc file may get removed in gsm_cleanup_mux() if the connection + * was closed. Early out here to avoid a deadlock. + */ + if (!mutex_trylock(&gsm_mux_mutex)) + return -EBUSY; + if (!mutex_trylock(&gsm->mutex)) { + mutex_unlock(&gsm_mux_mutex); + return -EBUSY; + } + + seq_printf(m, "tty:%s flags:", tty_name(gsm->tty)); + flags = gsm->tty->termios.c_iflag; + gsm_proc_print_flag_str(m, flags, IGNBRK); + gsm_proc_print_flag_str(m, flags, IXON); + gsm_proc_print_flag_str(m, flags, IXOFF); + flags = gsm->tty->termios.c_cflag; + gsm_proc_print_flag_str(m, flags, CLOCAL); + gsm_proc_print_flag_str(m, flags, CRTSCTS); + seq_putc(m, '\n'); + + seq_printf(m, "initiator:%d mode:%d mru:%u mtu:%u t1:%d t2:%d t3:%d", + gsm->initiator, gsm->encoding, gsm->mru, gsm->mtu, gsm->t1, + gsm->t2, gsm->t3); + seq_printf(m, " n2:%d k:%d wc:%d ka:%u", gsm->n2, gsm->k, + gsm->wait_config ? 1 : 0, gsm->keep_alive); + if (gsm->dead) + seq_puts(m, " DEAD"); + seq_putc(m, '\n'); + + seq_printf(m, "bad_fcs:%lu malformed:%lu io_error:%lu open_error:%lu", + gsm->bad_fcs, gsm->malformed, gsm->io_error, + gsm->open_error); + seq_printf(m, " bad_size:%lu unsupported:%lu\n\n", gsm->bad_size, + gsm->unsupported); + + for (i = 0; i < NUM_DLCI; i++) { + dlci = gsm->dlci[i]; + if (!dlci) + continue; + switch (dlci->state) { + case DLCI_CLOSED: + state = "CLOSED"; + break; + case DLCI_WAITING_CONFIG: + state = "WAITING_CONFIG"; + break; + case DLCI_CONFIGURE: + state = "CONFIGURE"; + break; + case DLCI_OPENING: + state = "OPENING"; + break; + case DLCI_OPEN: + state = "OPEN"; + break; + case DLCI_CLOSING: + state = "CLOSING"; + break; + default: + state = "???"; + break; + } + switch (dlci->ftype) { + case UI: + ftype = "UI"; + break; + case UIH: + ftype = "UIH"; + break; + default: + ftype = "???"; + break; + } + seq_printf(m, "dlci:%d state:%s cl:%d prio:%d i:%s k:%d mtu:%u", + i, state, dlci->adaption, dlci->prio, ftype, dlci->k, + dlci->mtu); + seq_printf(m, " tx:%llu rx:%llu", dlci->tx, dlci->rx); + if (dlci->dead) + seq_puts(m, " DEAD"); + seq_putc(m, '\n'); + } + + mutex_unlock(&gsm->mutex); + mutex_unlock(&gsm_mux_mutex); + + return 0; +} + +static int gsm_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, gsm_proc_show, pde_data(inode)); +} + +static const struct proc_ops gsm_proc_ops = { + .proc_open = gsm_proc_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = single_release, +}; + /** * gsm_cleanup_mux - generic GSM protocol cleanup * @gsm: our mux @@ -3131,6 +3282,9 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) kfree(txq); INIT_LIST_HEAD(&gsm->tx_data_list); + + if (gsm->proc) + proc_remove(gsm->proc); } /** @@ -3145,6 +3299,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) static int gsm_activate_mux(struct gsm_mux *gsm) { struct gsm_dlci *dlci; + char pbuf[8]; int ret; dlci = gsm_dlci_alloc(gsm, 0); @@ -3162,6 +3317,9 @@ static int gsm_activate_mux(struct gsm_mux *gsm) gsm->has_devices = true; gsm->dead = false; /* Tty opens are now permissible */ + + if (proc_gsm && snprintf(pbuf, sizeof(pbuf), "mux%u", gsm->num) > 0) + gsm->proc = proc_create_data(pbuf, 0444, proc_gsm, &gsm_proc_ops, gsm); return 0; } @@ -3596,6 +3754,8 @@ static void gsmld_close(struct tty_struct *tty) { struct gsm_mux *gsm = tty->disc_data; + mutex_lock(&gsm_mux_mutex); + /* The ldisc locks and closes the port before calling our close. This * means we have no way to do a proper disconnect. We will not bother * to do one. @@ -3607,6 +3767,8 @@ static void gsmld_close(struct tty_struct *tty) gsmld_flush_buffer(tty); /* Do other clean up here */ mux_put(gsm); + + mutex_unlock(&gsm_mux_mutex); } /** @@ -3622,14 +3784,20 @@ static void gsmld_close(struct tty_struct *tty) static int gsmld_open(struct tty_struct *tty) { struct gsm_mux *gsm; + int ret = 0; - if (tty->ops->write == NULL) - return -EINVAL; + mutex_lock(&gsm_mux_mutex); + if (tty->ops->write == NULL) { + ret = -EINVAL; + goto err_unlock; + } /* Attach our ldisc data */ gsm = gsm_alloc_mux(); - if (gsm == NULL) - return -ENOMEM; + if (gsm == NULL) { + ret = -ENOMEM; + goto err_unlock; + } tty->disc_data = gsm; tty->receive_room = 65536; @@ -3645,7 +3813,9 @@ static int gsmld_open(struct tty_struct *tty) else gsm->receive = gsm1_receive; - return 0; +err_unlock: + mutex_unlock(&gsm_mux_mutex); + return ret; } /** @@ -3769,17 +3939,24 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, struct gsm_mux *gsm = tty->disc_data; unsigned int base, addr; struct gsm_dlci *dlci; + int ret = 0; switch (cmd) { case GSMIOC_GETCONF: gsm_copy_config_values(gsm, &c); + mutex_lock(&gsm_mux_mutex); if (copy_to_user((void __user *)arg, &c, sizeof(c))) - return -EFAULT; - return 0; + ret = -EFAULT; + mutex_unlock(&gsm_mux_mutex); + break; case GSMIOC_SETCONF: + mutex_lock(&gsm_mux_mutex); if (copy_from_user(&c, (void __user *)arg, sizeof(c))) - return -EFAULT; - return gsm_config(gsm, &c); + ret = -EFAULT; + else + ret = gsm_config(gsm, &c); + mutex_unlock(&gsm_mux_mutex); + break; case GSMIOC_GETFIRST: base = mux_num_to_base(gsm); return put_user(base + 1, (__u32 __user *)arg); @@ -3824,6 +4001,7 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, default: return n_tty_ioctl_helper(tty, cmd, arg); } + return ret; } /* @@ -4497,7 +4675,9 @@ static void gsmtty_cleanup(struct tty_struct *tty) dlci_put(dlci); dlci_put(gsm->dlci[0]); + mutex_lock(&gsm_mux_mutex); mux_put(gsm); + mutex_unlock(&gsm_mux_mutex); } /* Virtual ttys for the demux */ @@ -4556,6 +4736,9 @@ static int __init gsm_init(void) status = -EBUSY; goto err_put_driver; } + + proc_gsm = proc_mkdir_mode("tty/ldisc/n_gsm", 0555, NULL); + pr_debug("gsm_init: loaded as %d,%d.\n", gsm_tty_driver->major, gsm_tty_driver->minor_start); return 0; @@ -4569,6 +4752,8 @@ static int __init gsm_init(void) static void __exit gsm_exit(void) { tty_unregister_ldisc(&tty_ldisc_packet); + if (proc_gsm) + proc_remove(proc_gsm); tty_unregister_driver(gsm_tty_driver); tty_driver_kref_put(gsm_tty_driver); } From patchwork Wed May 17 15:57:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 683237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 116A1C77B7F for ; Wed, 17 May 2023 15:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbjEQP7G (ORCPT ); Wed, 17 May 2023 11:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231993AbjEQP67 (ORCPT ); Wed, 17 May 2023 11:58:59 -0400 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 34E946E8B for ; Wed, 17 May 2023 08:58:34 -0700 (PDT) Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 2023051715583256c3cc5cf1e6e2746d for ; Wed, 17 May 2023 17:58:32 +0200 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=sXrwJ9Suw+eRO3K7fPMPI+/OulstW6ToHU5QLmyRPdg=; b=poCQmV7v3sTU0jmYQLtrkyfHOnvWb/Pxh9cnrogAs+k9+cjXKKth4xhS48mQXkXHoDZf3Q yTAlJNEIId/7caobzzxczFOarsi/blCvxQ0OO+7dGDWKli7XJs8+VmpRVW4ejoGvc8ixJTtI kMchkQlzQWnlJswdZPBAF18HGXqGk=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, felix-haase@siemens.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v5 10/10] tty: n_gsm: add restart flag to extended ioctl config Date: Wed, 17 May 2023 17:57:04 +0200 Message-Id: <20230517155704.5701-10-daniel.starke@siemens.com> In-Reply-To: <20230517155704.5701-1-daniel.starke@siemens.com> References: <20230517155704.5701-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Starke Currently, changing the parameters of the n_gsm mux gives no direct control to the user whether this should trigger a mux reset or not. The decision is solely made by the driver based on the assumption which parameter changes are compatible or not. Therefore, the user has no means to perform an automatic mux reset after parameter configuration for non-conflicting changes. Add the parameter 'flags' to 'gsm_config_ext' to force a mux reset after ioctl setting regardless of whether the changes made require this or not by setting this to 'GSM_FL_RESTART'. This is done similar to 'GSM_FL_RESTART' in gsm_dlci_config.flags. Note that 'GSM_FL_RESTART' is currently the only allowed flag to allow additions here. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 23 +++++++++++++++++++++++ include/uapi/linux/gsmmux.h | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) v4 -> v5: Newly added patch. This adds the missing equivalent from struct gsm_dlci_config to struct gsm_config_ext. See also the link below regarding the initial remark for this. Please note that I cannot response to emails until August 7th. Felix Haase will take over from our side for questions regarding this patch series or the n_gsm. Link: https://lore.kernel.org/all/cd7c33c8-2634-382d-cf62-3785e391af2@linux.intel.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 30f73ab2491f..362a42bdc072 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3578,6 +3578,7 @@ static void gsm_copy_config_ext_values(struct gsm_mux *gsm, static int gsm_config_ext(struct gsm_mux *gsm, struct gsm_config_ext *ce) { + bool need_restart = false; unsigned int i; /* @@ -3587,6 +3588,20 @@ static int gsm_config_ext(struct gsm_mux *gsm, struct gsm_config_ext *ce) for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) if (ce->reserved[i]) return -EINVAL; + if (ce->flags & ~GSM_FL_RESTART) + return -EINVAL; + + /* Requires care */ + if (ce->flags & GSM_FL_RESTART) + need_restart = true; + + /* + * Close down what is needed, restart and initiate the new + * configuration. On the first time there is no DLCI[0] + * and closing or cleaning up is not necessary. + */ + if (need_restart) + gsm_cleanup_mux(gsm, true); /* * Setup the new configuration values @@ -3594,6 +3609,14 @@ static int gsm_config_ext(struct gsm_mux *gsm, struct gsm_config_ext *ce) gsm->wait_config = ce->wait_config ? true : false; gsm->keep_alive = ce->keep_alive; + if (gsm->dead) { + int ret = gsm_activate_mux(gsm); + if (ret) + return ret; + if (gsm->initiator) + gsm_dlci_begin_open(gsm->dlci[0]); + } + return 0; } diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index 3bd6f03a8293..4c878d84dbda 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -11,6 +11,7 @@ * flags definition for n_gsm * * Used by: + * struct gsm_config_ext.flags * struct gsm_dlci_config.flags */ /* Forces a DLCI reset if set. Otherwise, a DLCI reset is only done if @@ -98,12 +99,14 @@ struct gsm_netconfig { * * @keep_alive: Control channel keep-alive in 1/100th of a second (0 to disable). * @wait_config: Wait for DLCI config before opening virtual link? + * @flags: Mux specific flags. * @reserved: For future use, must be initialized to zero. */ struct gsm_config_ext { __u32 keep_alive; __u32 wait_config; - __u32 reserved[6]; + __u32 flags; + __u32 reserved[5]; }; #define GSMIOC_GETCONF_EXT _IOR('G', 5, struct gsm_config_ext)