linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings
@ 2022-08-22  7:21 D. Starke
  2022-08-22  7:21 ` [PATCH 2/6] tty: n_gsm: name gsm tty device minors D. Starke
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

Add an enumeration for the gsm mux encoding types to improve code
readability and to avoid invalid values. Only two values are defined by the
standard:
- basic option mode
- advanced option mode (uses ISO HDLC standard transparency mechanism)

Also remove redundant configuration in gsmld_open(). The same value is
already set in gsm_alloc_mux() which is also called in gsmld_open().

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index caa5c14ed57f..5bf09d129357 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -184,6 +184,11 @@ struct gsm_control {
 	int error;	/* Error if any */
 };
 
+enum gsm_encoding {
+	GSM_BASIC_OPT,
+	GSM_ADV_OPT,
+};
+
 enum gsm_mux_state {
 	GSM_SEARCH,
 	GSM_START,
@@ -230,7 +235,7 @@ struct gsm_mux {
 	unsigned int address;
 	unsigned int count;
 	bool escape;
-	int encoding;
+	enum gsm_encoding encoding;
 	u8 control;
 	u8 fcs;
 	u8 *txframe;			/* TX framing buffer */
@@ -694,7 +699,7 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
 	*dp++ = (addr << 2) | (ocr << 1) | EA;
 	*dp++ = control;
 
-	if (gsm->encoding == 0)
+	if (gsm->encoding == GSM_BASIC_OPT)
 		*dp++ = EA; /* Length of data = 0 */
 
 	*dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data);
@@ -813,7 +818,7 @@ static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg)
 	int len, ret;
 
 
-	if (gsm->encoding == 0) {
+	if (gsm->encoding == GSM_BASIC_OPT) {
 		gsm->txframe[0] = GSM0_SOF;
 		memcpy(gsm->txframe + 1, msg->data, msg->len);
 		gsm->txframe[msg->len + 1] = GSM0_SOF;
@@ -965,7 +970,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
 	u8 *fcs = dp + msg->len;
 
 	/* Fill in the header */
-	if (gsm->encoding == 0) {
+	if (gsm->encoding == GSM_BASIC_OPT) {
 		if (msg->len < 128)
 			*--dp = (msg->len << 1) | EA;
 		else {
@@ -2508,7 +2513,7 @@ static int gsm_activate_mux(struct gsm_mux *gsm)
 	spin_lock_init(&gsm->control_lock);
 	spin_lock_init(&gsm->tx_lock);
 
-	if (gsm->encoding == 0)
+	if (gsm->encoding == GSM_BASIC_OPT)
 		gsm->receive = gsm0_receive;
 	else
 		gsm->receive = gsm1_receive;
@@ -2618,7 +2623,7 @@ static struct gsm_mux *gsm_alloc_mux(void)
 	gsm->n2 = N2;
 	gsm->ftype = UIH;
 	gsm->adaption = 1;
-	gsm->encoding = 1;
+	gsm->encoding = GSM_ADV_OPT;
 	gsm->mru = 64;	/* Default to encoding 1 so these should be 64 */
 	gsm->mtu = 64;
 	gsm->dead = true;	/* Avoid early tty opens */
@@ -2651,7 +2656,7 @@ static void gsm_copy_config_values(struct gsm_mux *gsm,
 {
 	memset(c, 0, sizeof(*c));
 	c->adaption = gsm->adaption;
-	c->encapsulation = gsm->encoding;
+	c->encapsulation = (int)gsm->encoding;
 	c->initiator = gsm->initiator;
 	c->t1 = gsm->t1;
 	c->t2 = gsm->t2;
@@ -2719,7 +2724,7 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)
 	gsm->initiator = c->initiator;
 	gsm->mru = c->mru;
 	gsm->mtu = c->mtu;
-	gsm->encoding = c->encapsulation;
+	gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT;
 	gsm->adaption = c->adaption;
 	gsm->n2 = c->n2;
 
@@ -2942,8 +2947,6 @@ static int gsmld_open(struct tty_struct *tty)
 	tty->receive_room = 65536;
 
 	/* Attach the initial passive connection */
-	gsm->encoding = 1;
-
 	gsmld_attach_gsm(tty, gsm);
 
 	timer_setup(&gsm->kick_timer, gsm_kick_timer, 0);
@@ -3345,7 +3348,7 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
 	struct gsm_control *ctrl;
 	int len = 2;
 
-	if (dlci->gsm->encoding != 0)
+	if (dlci->gsm->encoding != GSM_BASIC_OPT)
 		return 0;
 
 	modembits[0] = (dlci->addr << 2) | 2 | EA;  /* DLCI, Valid, EA */
@@ -3374,7 +3377,7 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
 		/* Send convergence layer type 2 empty data frame. */
 		gsm_modem_upd_via_data(dlci, brk);
 		return 0;
-	} else if (dlci->gsm->encoding == 0) {
+	} else if (dlci->gsm->encoding == GSM_BASIC_OPT) {
 		/* Send as MSC control message. */
 		return gsm_modem_upd_via_msc(dlci, brk);
 	}
@@ -3398,8 +3401,8 @@ static int gsm_carrier_raised(struct tty_port *port)
 	 * Basic mode with control channel in ADM mode may not respond
 	 * to CMD_MSC at all and modem_rx is empty.
 	 */
-	if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM &&
-	    !dlci->modem_rx)
+	if (gsm->encoding == GSM_BASIC_OPT &&
+	    gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx)
 		return 1;
 
 	return dlci->modem_rx & TIOCM_CD;
-- 
2.34.1


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

* [PATCH 2/6] tty: n_gsm: name gsm tty device minors
  2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
@ 2022-08-22  7:21 ` D. Starke
  2022-08-22  7:21 ` [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() D. Starke
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

Add a macro which defines the possible number of virtual devices for n_gsm
to improve code readability.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 5bf09d129357..ed399d57b197 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -164,6 +164,9 @@ struct gsm_dlci {
 	struct net_device *net; /* network interface, if created */
 };
 
+/* Total number of supported devices */
+#define GSM_TTY_MINORS		256
+
 /* DLCI 0, 62/63 are special or reserved see gsmtty_open */
 
 #define NUM_DLCI		64
@@ -3748,7 +3751,7 @@ static int __init gsm_init(void)
 		return status;
 	}
 
-	gsm_tty_driver = tty_alloc_driver(256, TTY_DRIVER_REAL_RAW |
+	gsm_tty_driver = tty_alloc_driver(GSM_TTY_MINORS, TTY_DRIVER_REAL_RAW |
 			TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
 	if (IS_ERR(gsm_tty_driver)) {
 		pr_err("gsm_init: tty allocation failed.\n");
-- 
2.34.1


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

* [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val()
  2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
  2022-08-22  7:21 ` [PATCH 2/6] tty: n_gsm: name gsm tty device minors D. Starke
@ 2022-08-22  7:21 ` D. Starke
  2022-08-22 14:05   ` kernel test robot
  2022-08-22  7:21 ` [PATCH 4/6] tty: n_gsm: introduce gsm_control_command() function D. Starke
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

Replace the use of gsm_read_ea() with gsm_read_ea_val() where applicable to
improve code readability and avoid errors like in the past.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 97 +++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 47 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index ed399d57b197..c87525b70e81 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -1418,18 +1418,13 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
 	unsigned int modem = 0;
 	struct gsm_dlci *dlci;
 	int len = clen;
-	int slen;
+	int cl = clen;
 	const u8 *dp = data;
 	struct tty_struct *tty;
 
-	while (gsm_read_ea(&addr, *dp++) == 0) {
-		len--;
-		if (len == 0)
-			return;
-	}
-	/* Must be at least one byte following the EA */
-	len--;
-	if (len <= 0)
+	len = gsm_read_ea_val(&addr, data, cl);
+
+	if (len < 1)
 		return;
 
 	addr >>= 1;
@@ -1438,15 +1433,21 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen)
 		return;
 	dlci = gsm->dlci[addr];
 
-	slen = len;
-	while (gsm_read_ea(&modem, *dp++) == 0) {
-		len--;
-		if (len == 0)
-			return;
-	}
-	len--;
+	/* Must be at least one byte following the EA */
+	if ((cl - len) < 1)
+		return;
+
+	dp += len;
+	cl -= len;
+
+	/* get the modem status */
+	len = gsm_read_ea_val(&modem, dp, cl);
+
+	if (len < 1)
+		return;
+
 	tty = tty_port_tty_get(&dlci->port);
-	gsm_process_modem(tty, dlci, modem, slen - len);
+	gsm_process_modem(tty, dlci, modem, cl);
 	if (tty) {
 		tty_wakeup(tty);
 		tty_kref_put(tty);
@@ -1921,8 +1922,7 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
 	struct tty_port *port = &dlci->port;
 	struct tty_struct *tty;
 	unsigned int modem = 0;
-	int len = clen;
-	int slen = 0;
+	int len;
 
 	if (debug & 16)
 		pr_debug("%d bytes for tty\n", len);
@@ -1933,24 +1933,22 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
 	case 3:		/* Packetised uininterruptible voice/data */
 		break;
 	case 2:		/* Asynchronous serial with line state in each frame */
-		while (gsm_read_ea(&modem, *data++) == 0) {
-			len--;
-			slen++;
-			if (len == 0)
-				return;
-		}
-		len--;
-		slen++;
+		len = gsm_read_ea_val(&modem, data, clen);
+		if (len < 1)
+			return;
 		tty = tty_port_tty_get(port);
 		if (tty) {
-			gsm_process_modem(tty, dlci, modem, slen);
+			gsm_process_modem(tty, dlci, modem, len);
 			tty_wakeup(tty);
 			tty_kref_put(tty);
 		}
+		/* Skip processed modem data */
+		data += len;
+		clen -= len;
 		fallthrough;
 	case 1:		/* Line state will go via DLCI 0 controls only */
 	default:
-		tty_insert_flip_string(port, data, len);
+		tty_insert_flip_string(port, data, clen);
 		tty_flip_buffer_push(port);
 	}
 }
@@ -1971,24 +1969,29 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
 {
 	/* See what command is involved */
 	unsigned int command = 0;
-	while (len-- > 0) {
-		if (gsm_read_ea(&command, *data++) == 1) {
-			int clen = *data++;
-			len--;
-			/* FIXME: this is properly an EA */
-			clen >>= 1;
-			/* Malformed command ? */
-			if (clen > len)
-				return;
-			if (command & 1)
-				gsm_control_message(dlci->gsm, command,
-								data, clen);
-			else
-				gsm_control_response(dlci->gsm, command,
-								data, clen);
-			return;
-		}
-	}
+	const u8 *dp = data;
+	int clen = 0;
+	int dlen;
+
+	/* read the command */
+	dlen = gsm_read_ea_val(&command, dp, len);
+	len -= dlen;
+	dp += dlen;
+
+	/* read any control data */
+	dlen = gsm_read_ea_val(&clen, dp, len);
+	len -= dlen;
+	dp += dlen;
+
+	/* Malformed command? */
+	if (clen > len)
+		return;
+
+	if (command & 1)
+		gsm_control_message(dlci->gsm, command, dp, clen);
+	else
+		gsm_control_response(dlci->gsm, command, dp, clen);
+	return;
 }
 
 /**
-- 
2.34.1


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

* [PATCH 4/6] tty: n_gsm: introduce gsm_control_command() function
  2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
  2022-08-22  7:21 ` [PATCH 2/6] tty: n_gsm: name gsm tty device minors D. Starke
  2022-08-22  7:21 ` [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() D. Starke
@ 2022-08-22  7:21 ` D. Starke
  2022-08-22  7:21 ` [PATCH 5/6] tty: n_gsm: name the debug bits D. Starke
  2022-08-22  7:21 ` [PATCH 6/6] tty: n_gsm: add debug bit for user payload D. Starke
  4 siblings, 0 replies; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

Move the content of gsm_control_transmit() to a new function
gsm_control_command() with a more generic signature and analog to
gsm_control_reply(). Use this within gsm_control_transmit().

This is needed to simplify upcoming functional additions.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index c87525b70e81..71599198eb6d 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -1316,6 +1316,28 @@ static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
  */
 
 
+/**
+ *	gsm_control_command	-	send a command frame to a control
+ *	@gsm: gsm channel
+ *	@cmd: the command to use
+ *	@data: data to follow encoded info
+ *	@dlen: length of data
+ *
+ *	Encode up and queue a UI/UIH frame containing our command.
+ */
+static int gsm_control_command(struct gsm_mux *gsm, int cmd, u8 *data, int dlen)
+{
+	struct gsm_msg *msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->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);
+	return 0;
+}
+
 /**
  *	gsm_control_reply	-	send a response frame to a control
  *	@gsm: gsm channel
@@ -1623,13 +1645,7 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command,
 
 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl)
 {
-	struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 2, gsm->ftype);
-	if (msg == NULL)
-		return;
-	msg->data[0] = (ctrl->cmd << 1) | CR | EA;	/* command */
-	msg->data[1] = (ctrl->len << 1) | EA;
-	memcpy(msg->data + 2, ctrl->data, ctrl->len);
-	gsm_data_queue(gsm->dlci[0], msg);
+	gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len);
 }
 
 /**
-- 
2.34.1


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

* [PATCH 5/6] tty: n_gsm: name the debug bits
  2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
                   ` (2 preceding siblings ...)
  2022-08-22  7:21 ` [PATCH 4/6] tty: n_gsm: introduce gsm_control_command() function D. Starke
@ 2022-08-22  7:21 ` D. Starke
  2022-08-22  7:21 ` [PATCH 6/6] tty: n_gsm: add debug bit for user payload D. Starke
  4 siblings, 0 replies; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

Introduce defines to name the various debug bits used within the code to
improve readability and to make its specific use clear.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 71599198eb6d..e8f10a5f0a8a 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -63,6 +63,13 @@
 static int debug;
 module_param(debug, int, 0600);
 
+/* Module debug bits */
+#define DBG_DUMP	(1 << 0) /* Data transmission dump. */
+#define DBG_CD_ON	(1 << 1) /* Always assume CD line on. */
+#define DBG_DATA	(1 << 2) /* Data transmission details. */
+#define DBG_ERRORS	(1 << 3) /* Details for fail conditions. */
+#define DBG_TTY		(1 << 4) /* Transmission statistics for DLCI TTYs. */
+
 /* Defaults: these are from the specification */
 
 #define T1	10		/* 100mS */
@@ -535,7 +542,7 @@ static int gsm_register_devices(struct tty_driver *driver, unsigned int index)
 		 */
 		dev = tty_register_device(gsm_tty_driver, base + i, NULL);
 		if (IS_ERR(dev)) {
-			if (debug & 8)
+			if (debug & DBG_ERRORS)
 				pr_info("%s failed to register device minor %u",
 					__func__, base + i);
 			for (i--; i >= 1; i--)
@@ -589,7 +596,7 @@ static void gsm_unregister_devices(struct tty_driver *driver,
 static void gsm_print_packet(const char *hdr, int addr, int cr,
 					u8 control, const u8 *data, int dlen)
 {
-	if (!(debug & 1))
+	if (!(debug & DBG_DUMP))
 		return;
 
 	pr_info("%s %d) %c: ", hdr, addr, "RC"[cr]);
@@ -833,7 +840,7 @@ static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg)
 		len += 2;
 	}
 
-	if (debug & 4)
+	if (debug & DBG_DATA)
 		gsm_hex_dump_bytes(__func__, gsm->txframe, len);
 	gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data,
 			 msg->len);
@@ -1765,7 +1772,7 @@ static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control)
 static void gsm_dlci_close(struct gsm_dlci *dlci)
 {
 	del_timer(&dlci->t1);
-	if (debug & 8)
+	if (debug & DBG_ERRORS)
 		pr_debug("DLCI %d goes closed.\n", dlci->addr);
 	dlci->state = DLCI_CLOSED;
 	/* Prevent us from sending data before the link is up again */
@@ -1799,7 +1806,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci)
 	/* This will let a tty open continue */
 	dlci->state = DLCI_OPEN;
 	dlci->constipated = false;
-	if (debug & 8)
+	if (debug & DBG_ERRORS)
 		pr_debug("DLCI %d goes open.\n", dlci->addr);
 	/* Send current modem state */
 	if (dlci->addr)
@@ -1835,7 +1842,7 @@ static void gsm_dlci_t1(struct timer_list *t)
 			gsm_command(dlci->gsm, dlci->addr, SABM|PF);
 			mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
 		} else if (!dlci->addr && gsm->control == (DM | PF)) {
-			if (debug & 8)
+			if (debug & DBG_ERRORS)
 				pr_info("DLCI %d opening in ADM mode.\n",
 					dlci->addr);
 			dlci->mode = DLCI_MODE_ADM;
@@ -1940,7 +1947,7 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
 	unsigned int modem = 0;
 	int len;
 
-	if (debug & 16)
+	if (debug & DBG_TTY)
 		pr_debug("%d bytes for tty\n", len);
 	switch (dlci->adaption)  {
 	/* Unsupported types */
@@ -2030,7 +2037,7 @@ static void gsm_kick_timer(struct timer_list *t)
 		sent = gsm_dlci_data_sweep(gsm);
 	spin_unlock_irqrestore(&gsm->tx_lock, flags);
 
-	if (sent && debug & 4)
+	if (sent && debug & DBG_DATA)
 		pr_info("%s TX queue stalled\n", __func__);
 }
 
@@ -2164,7 +2171,7 @@ static void gsm_queue(struct gsm_mux *gsm)
 
 	if (gsm->fcs != GOOD_FCS) {
 		gsm->bad_fcs++;
-		if (debug & 4)
+		if (debug & DBG_DATA)
 			pr_debug("BAD FCS %02x\n", gsm->fcs);
 		return;
 	}
@@ -2790,7 +2797,7 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len)
 		set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags);
 		return -ENOSPC;
 	}
-	if (debug & 4)
+	if (debug & DBG_DATA)
 		gsm_hex_dump_bytes(__func__, data, len);
 	return gsm->tty->ops->write(gsm->tty, data, len);
 }
@@ -2877,7 +2884,7 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
 	struct gsm_mux *gsm = tty->disc_data;
 	char flags = TTY_NORMAL;
 
-	if (debug & 4)
+	if (debug & DBG_DATA)
 		gsm_hex_dump_bytes(__func__, cp, count);
 
 	for (; count; count--, cp++) {
@@ -3416,7 +3423,7 @@ static int gsm_carrier_raised(struct tty_port *port)
 	/* Not yet open so no carrier info */
 	if (dlci->state != DLCI_OPEN)
 		return 0;
-	if (debug & 2)
+	if (debug & DBG_CD_ON)
 		return 1;
 
 	/*
-- 
2.34.1


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

* [PATCH 6/6] tty: n_gsm: add debug bit for user payload
  2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
                   ` (3 preceding siblings ...)
  2022-08-22  7:21 ` [PATCH 5/6] tty: n_gsm: name the debug bits D. Starke
@ 2022-08-22  7:21 ` D. Starke
  4 siblings, 0 replies; 7+ messages in thread
From: D. Starke @ 2022-08-22  7:21 UTC (permalink / raw)
  To: linux-serial, gregkh, jirislaby; +Cc: linux-kernel, Daniel Starke

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

A debug bit to output a complete transmission dump exists. Sometimes only
the user frames are relevant. Add an additional bit which limits the
transmission dump output to user data frames if set.

Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
---
 drivers/tty/n_gsm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index e8f10a5f0a8a..676034fb1190 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -69,6 +69,7 @@ module_param(debug, int, 0600);
 #define DBG_DATA	(1 << 2) /* Data transmission details. */
 #define DBG_ERRORS	(1 << 3) /* Details for fail conditions. */
 #define DBG_TTY		(1 << 4) /* Transmission statistics for DLCI TTYs. */
+#define DBG_PAYLOAD	(1 << 5) /* Limits DBG_DUMP to payload frames. */
 
 /* Defaults: these are from the specification */
 
@@ -598,6 +599,10 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,
 {
 	if (!(debug & DBG_DUMP))
 		return;
+	/* Only show user payload frames if debug & DBG_PAYLOAD */
+	if (!(debug & DBG_PAYLOAD) && addr != 0)
+		if ((control & ~PF) == UI || (control & ~PF) == UIH)
+			return;
 
 	pr_info("%s %d) %c: ", hdr, addr, "RC"[cr]);
 
-- 
2.34.1


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

* Re: [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val()
  2022-08-22  7:21 ` [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() D. Starke
@ 2022-08-22 14:05   ` kernel test robot
  0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2022-08-22 14:05 UTC (permalink / raw)
  To: D. Starke, linux-serial, gregkh, jirislaby
  Cc: llvm, kbuild-all, linux-kernel, Daniel Starke

Hi Starke",

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tty/tty-testing]
[also build test WARNING on linus/master v6.0-rc2 next-20220822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/D-Starke/tty-n_gsm-add-enumeration-for-gsm-encodings/20220822-152532
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: i386-randconfig-a003-20220822 (https://download.01.org/0day-ci/archive/20220822/202208222147.WfFRmf1r-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/66ec0ad14dba76f793ec89ecdc7e6d7b3c550873
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review D-Starke/tty-n_gsm-add-enumeration-for-gsm-encodings/20220822-152532
        git checkout 66ec0ad14dba76f793ec89ecdc7e6d7b3c550873
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/tty/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/tty/n_gsm.c:1928:34: warning: variable 'len' is uninitialized when used here [-Wuninitialized]
                   pr_debug("%d bytes for tty\n", len);
                                                  ^~~
   include/linux/printk.h:588:26: note: expanded from macro 'pr_debug'
           dynamic_pr_debug(fmt, ##__VA_ARGS__)
                                   ^~~~~~~~~~~
   include/linux/dynamic_debug.h:163:22: note: expanded from macro 'dynamic_pr_debug'
                              pr_fmt(fmt), ##__VA_ARGS__)
                                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:152:56: note: expanded from macro '_dynamic_func_call'
           __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
                                                                 ^~~~~~~~~~~
   include/linux/dynamic_debug.h:134:15: note: expanded from macro '__dynamic_func_call'
                   func(&id, ##__VA_ARGS__);               \
                               ^~~~~~~~~~~
   drivers/tty/n_gsm.c:1925:9: note: initialize the variable 'len' to silence this warning
           int len;
                  ^
                   = 0
   1 warning generated.


vim +/len +1928 drivers/tty/n_gsm.c

e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1907  
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1908  /**
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1909   *	gsm_dlci_data		-	data arrived
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1910   *	@dlci: channel
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1911   *	@data: block of bytes received
724ac070ffc7a1 drivers/tty/n_gsm.c  Jiri Slaby          2020-08-18  1912   *	@clen: length of received block
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1913   *
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1914   *	A UI or UIH frame has arrived which contains data for a channel
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1915   *	other than the control channel. If the relevant virtual tty is
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1916   *	open we shovel the bits down it, if not we drop them.
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1917   */
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1918  
4feb7a4a124444 drivers/tty/n_gsm.c  Tony Lindgren       2019-01-13  1919  static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1920  {
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1921  	/* krefs .. */
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1922  	struct tty_port *port = &dlci->port;
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1923  	struct tty_struct *tty;
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1924  	unsigned int modem = 0;
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1925  	int len;
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1926  
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1927  	if (debug & 16)
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03 @1928  		pr_debug("%d bytes for tty\n", len);
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1929  	switch (dlci->adaption)  {
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1930  	/* Unsupported types */
3e913eebdfbb56 drivers/tty/n_gsm.c  Gustavo A. R. Silva 2019-02-25  1931  	case 4:		/* Packetised interruptible data */
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1932  		break;
3e913eebdfbb56 drivers/tty/n_gsm.c  Gustavo A. R. Silva 2019-02-25  1933  	case 3:		/* Packetised uininterruptible voice/data */
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1934  		break;
3e913eebdfbb56 drivers/tty/n_gsm.c  Gustavo A. R. Silva 2019-02-25  1935  	case 2:		/* Asynchronous serial with line state in each frame */
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1936  		len = gsm_read_ea_val(&modem, data, clen);
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1937  		if (len < 1)
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1938  			return;
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1939  		tty = tty_port_tty_get(port);
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1940  		if (tty) {
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1941  			gsm_process_modem(tty, dlci, modem, len);
1adf6fee58ca25 drivers/tty/n_gsm.c  Daniel Starke       2022-04-14  1942  			tty_wakeup(tty);
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1943  			tty_kref_put(tty);
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1944  		}
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1945  		/* Skip processed modem data */
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1946  		data += len;
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1947  		clen -= len;
df561f6688fef7 drivers/tty/n_gsm.c  Gustavo A. R. Silva 2020-08-23  1948  		fallthrough;
3e913eebdfbb56 drivers/tty/n_gsm.c  Gustavo A. R. Silva 2019-02-25  1949  	case 1:		/* Line state will go via DLCI 0 controls only */
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1950  	default:
66ec0ad14dba76 drivers/tty/n_gsm.c  Daniel Starke       2022-08-22  1951  		tty_insert_flip_string(port, data, clen);
2e124b4a390ca8 drivers/tty/n_gsm.c  Jiri Slaby          2013-01-03  1952  		tty_flip_buffer_push(port);
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1953  	}
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1954  }
e1eaea46bb4020 drivers/char/n_gsm.c Alan Cox            2010-03-26  1955  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-08-22 14:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22  7:21 [PATCH 1/6] tty: n_gsm: add enumeration for gsm encodings D. Starke
2022-08-22  7:21 ` [PATCH 2/6] tty: n_gsm: name gsm tty device minors D. Starke
2022-08-22  7:21 ` [PATCH 3/6] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() D. Starke
2022-08-22 14:05   ` kernel test robot
2022-08-22  7:21 ` [PATCH 4/6] tty: n_gsm: introduce gsm_control_command() function D. Starke
2022-08-22  7:21 ` [PATCH 5/6] tty: n_gsm: name the debug bits D. Starke
2022-08-22  7:21 ` [PATCH 6/6] tty: n_gsm: add debug bit for user payload D. Starke

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).