linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
@ 2023-04-24  7:52 D. Starke
  2023-04-24  7:52 ` [PATCH v3 2/8] tty: n_gsm: add missing description to gsm_config D. Starke
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 'restart' to 'gsm_dlci_config' to force a channel reset
after ioctl setting regardless of whether the changes made require this or
not.

Note that the parameter is limited to the values 0 and 1 to allow future
additions here.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c         | 4 ++++
 include/uapi/linux/gsmmux.h | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-2-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index b411a26cc092..00f692e2e810 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->restart > 1)   /* 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->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..33ee7b857c52 100644
--- a/include/uapi/linux/gsmmux.h
+++ b/include/uapi/linux/gsmmux.h
@@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */
+	__u32 reserved[7];	/* For future use, must be initialized to zero */
 };
 
 #define GSMIOC_GETCONF_DLCI	_IOWR('G', 7, struct gsm_dlci_config)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 2/8] tty: n_gsm: add missing description to gsm_config
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 3/8] tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config D. Starke
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

Currently, all available structure fields in gsmmux.h except those
for gsm_config are commented.

Fix this by adding appropriate comments to the not commented fields.
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.

Converting the other fields to kernel doc format remains an open task for
future patches.

Link: https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516
Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 include/uapi/linux/gsmmux.h | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

v2 -> v3:
Changed added comments to kernel doc format as remarked in the review.
Added remark regarding remaining documentation fields to commit message.

Link: https://lore.kernel.org/all/ZEEd_oOvJYranmzN@kroah.com/

diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h
index 33ee7b857c52..d3b9b37a9082 100644
--- a/include/uapi/linux/gsmmux.h
+++ b/include/uapi/linux/gsmmux.h
@@ -6,6 +6,28 @@
 #include <linux/ioctl.h>
 #include <linux/types.h>
 
+/**
+ * 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;
@@ -19,7 +41,7 @@ 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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 3/8] tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
  2023-04-24  7:52 ` [PATCH v3 2/8] tty: n_gsm: add missing description to gsm_config D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 4/8] tty: n_gsm: add open_error counter to gsm_mux D. Starke
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-4-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 00f692e2e810..9a2cf3e14678 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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 4/8] tty: n_gsm: add open_error counter to gsm_mux
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
  2023-04-24  7:52 ` [PATCH v3 2/8] tty: n_gsm: add missing description to gsm_config D. Starke
  2023-04-24  7:52 ` [PATCH v3 3/8] tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 5/8] tty: n_gsm: increase malformed counter for malformed control frames D. Starke
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

v2 -> v3:
Merged
commit 2b3174c96696 ("n_gsm: Use array_index_nospec() with index that comes from userspace")
No other changes.

Link: https://lore.kernel.org/all/20230420085017.7314-5-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 9a2cf3e14678..6b6fafb1098a 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 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 5/8] tty: n_gsm: increase malformed counter for malformed control frames
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
                   ` (2 preceding siblings ...)
  2023-04-24  7:52 ` [PATCH v3 4/8] tty: n_gsm: add open_error counter to gsm_mux D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 6/8] tty: n_gsm: increase gsm_mux unsupported counted where appropriate D. Starke
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-6-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 6b6fafb1098a..10fc02133efa 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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 6/8] tty: n_gsm: increase gsm_mux unsupported counted where appropriate
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
                   ` (3 preceding siblings ...)
  2023-04-24  7:52 ` [PATCH v3 5/8] tty: n_gsm: increase malformed counter for malformed control frames D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 7/8] tty: n_gsm: cleanup gsm_control_command and gsm_control_reply D. Starke
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 3 +++
 1 file changed, 3 insertions(+)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-7-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 10fc02133efa..941489230f9f 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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 7/8] tty: n_gsm: cleanup gsm_control_command and gsm_control_reply
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
                   ` (4 preceding siblings ...)
  2023-04-24  7:52 ` [PATCH v3 6/8] tty: n_gsm: increase gsm_mux unsupported counted where appropriate D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24  7:52 ` [PATCH v3 8/8] tty: n_gsm: add DLCI specific rx/tx statistics D. Starke
  2023-04-24 10:54 ` [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config Greg KH
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-8-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 941489230f9f..6bfcaf8fe54c 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);
 }
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 8/8] tty: n_gsm: add DLCI specific rx/tx statistics
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
                   ` (5 preceding siblings ...)
  2023-04-24  7:52 ` [PATCH v3 7/8] tty: n_gsm: cleanup gsm_control_command and gsm_control_reply D. Starke
@ 2023-04-24  7:52 ` D. Starke
  2023-04-24 10:54 ` [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config Greg KH
  7 siblings, 0 replies; 13+ messages in thread
From: D. Starke @ 2023-04-24  7:52 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby, ilpo.jarvinen
  Cc: linux-kernel, Daniel Starke

From: Daniel Starke <daniel.starke@siemens.com>

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 <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

v2 -> v3:
No changes.

Link: https://lore.kernel.org/all/20230420085017.7314-9-daniel.starke@siemens.com/

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 6bfcaf8fe54c..7377a37320af 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -186,6 +186,9 @@ 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 +1219,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 +1287,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 +1466,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 +1494,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 +1859,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 +1944,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 +2310,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 +2345,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 +2367,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 +2446,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 +2807,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 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
  2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
                   ` (6 preceding siblings ...)
  2023-04-24  7:52 ` [PATCH v3 8/8] tty: n_gsm: add DLCI specific rx/tx statistics D. Starke
@ 2023-04-24 10:54 ` Greg KH
  2023-04-24 11:03   ` Starke, Daniel
  7 siblings, 1 reply; 13+ messages in thread
From: Greg KH @ 2023-04-24 10:54 UTC (permalink / raw)
  To: D. Starke; +Cc: linux-serial, jirislaby, ilpo.jarvinen, linux-kernel

On Mon, Apr 24, 2023 at 09:52:44AM +0200, D. Starke wrote:
> From: Daniel Starke <daniel.starke@siemens.com>
> 
> 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 'restart' to 'gsm_dlci_config' to force a channel reset
> after ioctl setting regardless of whether the changes made require this or
> not.
> 
> Note that the parameter is limited to the values 0 and 1 to allow future
> additions here.
> 
> Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
> ---
>  drivers/tty/n_gsm.c         | 4 ++++
>  include/uapi/linux/gsmmux.h | 3 ++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> v2 -> v3:
> No changes.
> 
> Link: https://lore.kernel.org/all/20230420085017.7314-2-daniel.starke@siemens.com/
> 
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index b411a26cc092..00f692e2e810 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->restart > 1)   /* 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->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..33ee7b857c52 100644
> --- a/include/uapi/linux/gsmmux.h
> +++ b/include/uapi/linux/gsmmux.h
> @@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */

Why are you using a full 32 bits for just 1 bit of data here?  Why not
use a bitfield?

And what happened to the request to turn the documentation for this
structure into proper kerneldoc format?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
  2023-04-24 10:54 ` [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config Greg KH
@ 2023-04-24 11:03   ` Starke, Daniel
  2023-04-24 12:54     ` Greg KH
  0 siblings, 1 reply; 13+ messages in thread
From: Starke, Daniel @ 2023-04-24 11:03 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-serial@vger.kernel.org, jirislaby@kernel.org,
	ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org

> > --- a/include/uapi/linux/gsmmux.h
> > +++ b/include/uapi/linux/gsmmux.h
> > @@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */
> 
> Why are you using a full 32 bits for just 1 bit of data here?  Why not
> use a bitfield?

The ioctrl guide states:
  Bitfields and enums generally work as one would expect them to,
  but some properties of them are implementation-defined, so it is better
  to avoid them completely in ioctl interfaces.

Therefore, I tried to avoid them here.

> And what happened to the request to turn the documentation for this
> structure into proper kerneldoc format?

That applied to patch 2/8 and is unrelated to this patch. Another patch
will need to fix this.

Link: https://lore.kernel.org/all/20230424075251.5216-2-daniel.starke@siemens.com/

Best regards,
Daniel Starke

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
  2023-04-24 11:03   ` Starke, Daniel
@ 2023-04-24 12:54     ` Greg KH
  2023-04-24 13:20       ` Ilpo Järvinen
  0 siblings, 1 reply; 13+ messages in thread
From: Greg KH @ 2023-04-24 12:54 UTC (permalink / raw)
  To: Starke, Daniel
  Cc: linux-serial@vger.kernel.org, jirislaby@kernel.org,
	ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org

On Mon, Apr 24, 2023 at 11:03:26AM +0000, Starke, Daniel wrote:
> > > --- a/include/uapi/linux/gsmmux.h
> > > +++ b/include/uapi/linux/gsmmux.h
> > > @@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */
> > 
> > Why are you using a full 32 bits for just 1 bit of data here?  Why not
> > use a bitfield?
> 
> The ioctrl guide states:
>   Bitfields and enums generally work as one would expect them to,
>   but some properties of them are implementation-defined, so it is better
>   to avoid them completely in ioctl interfaces.
> 
> Therefore, I tried to avoid them here.

Then use a u8?

> > And what happened to the request to turn the documentation for this
> > structure into proper kerneldoc format?
> 
> That applied to patch 2/8 and is unrelated to this patch. Another patch
> will need to fix this.
> 
> Link: https://lore.kernel.org/all/20230424075251.5216-2-daniel.starke@siemens.com/

It's kind of related in that the format is not right :)

As it's a few weeks before I am allowed to even apply this, please
rework the series a bit.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
  2023-04-24 12:54     ` Greg KH
@ 2023-04-24 13:20       ` Ilpo Järvinen
  2023-04-24 16:41         ` Greg Kroah-Hartman
  0 siblings, 1 reply; 13+ messages in thread
From: Ilpo Järvinen @ 2023-04-24 13:20 UTC (permalink / raw)
  To: Starke, Daniel
  Cc: linux-serial@vger.kernel.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, Greg Kroah-Hartman

On Mon, 24 Apr 2023, Greg KH wrote:

> On Mon, Apr 24, 2023 at 11:03:26AM +0000, Starke, Daniel wrote:
> > > > --- a/include/uapi/linux/gsmmux.h
> > > > +++ b/include/uapi/linux/gsmmux.h
> > > > @@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */
> > > 
> > > Why are you using a full 32 bits for just 1 bit of data here?  Why not
> > > use a bitfield?
> > 
> > The ioctrl guide states:
> >   Bitfields and enums generally work as one would expect them to,
> >   but some properties of them are implementation-defined, so it is better
> >   to avoid them completely in ioctl interfaces.
> > 
> > Therefore, I tried to avoid them here.
> 
> Then use a u8?

To add further, I think that the ioctl guidance tries to say that C 
bitfields using :number postfix are not a good idea, not that much to 
disallow flag like content within an integer type.

-- 
 i.

> > > And what happened to the request to turn the documentation for this
> > > structure into proper kerneldoc format?
> > 
> > That applied to patch 2/8 and is unrelated to this patch. Another patch
> > will need to fix this.
> > 
> > Link: https://lore.kernel.org/all/20230424075251.5216-2-daniel.starke@siemens.com/
> 
> It's kind of related in that the format is not right :)
> 
> As it's a few weeks before I am allowed to even apply this, please
> rework the series a bit.
> 
> thanks,
> 
> greg k-h
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config
  2023-04-24 13:20       ` Ilpo Järvinen
@ 2023-04-24 16:41         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2023-04-24 16:41 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Starke, Daniel, linux-serial@vger.kernel.org,
	jirislaby@kernel.org, linux-kernel@vger.kernel.org

On Mon, Apr 24, 2023 at 04:20:00PM +0300, Ilpo Järvinen wrote:
> On Mon, 24 Apr 2023, Greg KH wrote:
> 
> > On Mon, Apr 24, 2023 at 11:03:26AM +0000, Starke, Daniel wrote:
> > > > > --- a/include/uapi/linux/gsmmux.h
> > > > > +++ b/include/uapi/linux/gsmmux.h
> > > > > @@ -58,7 +58,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 restart;		/* Force DLCI channel reset? */
> > > > 
> > > > Why are you using a full 32 bits for just 1 bit of data here?  Why not
> > > > use a bitfield?
> > > 
> > > The ioctrl guide states:
> > >   Bitfields and enums generally work as one would expect them to,
> > >   but some properties of them are implementation-defined, so it is better
> > >   to avoid them completely in ioctl interfaces.
> > > 
> > > Therefore, I tried to avoid them here.
> > 
> > Then use a u8?
> 
> To add further, I think that the ioctl guidance tries to say that C 
> bitfields using :number postfix are not a good idea, not that much to 
> disallow flag like content within an integer type.

Agreed.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-04-24 16:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24  7:52 [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config D. Starke
2023-04-24  7:52 ` [PATCH v3 2/8] tty: n_gsm: add missing description to gsm_config D. Starke
2023-04-24  7:52 ` [PATCH v3 3/8] tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config D. Starke
2023-04-24  7:52 ` [PATCH v3 4/8] tty: n_gsm: add open_error counter to gsm_mux D. Starke
2023-04-24  7:52 ` [PATCH v3 5/8] tty: n_gsm: increase malformed counter for malformed control frames D. Starke
2023-04-24  7:52 ` [PATCH v3 6/8] tty: n_gsm: increase gsm_mux unsupported counted where appropriate D. Starke
2023-04-24  7:52 ` [PATCH v3 7/8] tty: n_gsm: cleanup gsm_control_command and gsm_control_reply D. Starke
2023-04-24  7:52 ` [PATCH v3 8/8] tty: n_gsm: add DLCI specific rx/tx statistics D. Starke
2023-04-24 10:54 ` [PATCH v3 1/8] tty: n_gsm: add restart parameter to DLC specific ioctl config Greg KH
2023-04-24 11:03   ` Starke, Daniel
2023-04-24 12:54     ` Greg KH
2023-04-24 13:20       ` Ilpo Järvinen
2023-04-24 16:41         ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).