[PATCH 2/2] [Telephony/Mux]: n_gsm: Add Debug define for extra levels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Improve the debug print out by adding extra debug levels
that allows to be verbose and ease the debugging. For example,
they allow to display the content of the TX or RX frames, the
protocol data or/and the content of the frames.The new levels
macros are clearer to understand than the
previous numbers.

Signed-off-by: Gwenn Bourree <gwenn.bourree@xxxxxxxxx>
---
 drivers/tty/n_gsm.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 2983ae2..bb204a2 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -66,18 +66,20 @@
 static int debug;
 module_param(debug, int, 0600);
 
+/* Extra debug levels */
+#define GSMDBG_VERBOSE_PACKET_REPORT(x) ((x) & BIT(0))
+#define GSMDBG_FORCE_CARRIER(x)         ((x) & BIT(1))
+#define GSMDBG_DATA_FULL_REPORT(x)      ((x) & BIT(2))
+#define GSMDBG_DLCI_STREAM_REPORT(x)    ((x) & BIT(3))
+#define GSMDBG_DLCI_DATA_REPORT(x)      ((x) & BIT(4))
+#define GSMDBG_DATA_LEN_REPORT(x)       ((x) & BIT(5))
+
 /* Defaults: these are from the specification */
 
 #define T1	10		/* 100mS */
 #define T2	34		/* 333mS */
 #define N2	3		/* Retry 3 times */
 
-/* Use long timers for testing at low speed with debug on */
-#ifdef DEBUG_TIMING
-#define T1	100
-#define T2	200
-#endif
-
 /*
  * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64
byte
  * limits so this is plenty
@@ -461,7 +463,7 @@ static u8 gsm_encode_modem(const struct gsm_dlci
*dlci)
 static void gsm_print_packet(const char *hdr, int addr, int cr,
 					u8 control, const u8 *data, int dlen)
 {
-	if (!(debug & 1))
+	if (!GSMDBG_VERBOSE_PACKET_REPORT(debug))
 		return;
 
 	pr_info("%s %d) %c: ", hdr, addr, "RC"[cr]);
@@ -1463,7 +1465,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci)
 	del_timer(&dlci->t1);
 	/* This will let a tty open continue */
 	dlci->state = DLCI_OPEN;
-	if (debug & 8)
+	if (GSMDBG_DLCI_STREAM_REPORT(debug))
 		pr_debug("DLCI %d goes open.\n", dlci->addr);
 	wake_up(&dlci->gsm->event);
 }
@@ -1568,8 +1570,8 @@ static void gsm_dlci_data(struct gsm_dlci *dlci,
u8 *data, int clen)
 	unsigned int modem = 0;
 	int len = clen;
 
-	if (debug & 16)
-		pr_debug("%d bytes for tty\n", len);
+	if (GSMDBG_DLCI_DATA_REPORT(debug))
+		pr_debug("%s: %d bytes for tty\n", __func__, len);
 	switch (dlci->adaption)  {
 	/* Unsupported types */
 	/* Packetised interruptible data */
@@ -1774,7 +1776,7 @@ static void gsm_queue(struct gsm_mux *gsm)
 	}
 	if (gsm->fcs != GOOD_FCS) {
 		gsm->bad_fcs++;
-		if (debug & 4)
+		if (GSMDBG_DATA_FULL_REPORT(debug))
 			pr_debug("BAD FCS %02x\n", gsm->fcs);
 		return;
 	}
@@ -1937,6 +1939,7 @@ static void gsm0_receive(struct gsm_mux *gsm,
unsigned char c)
 			gsm->state = GSM_SEARCH;
 			break;
 		}
+		pr_debug("wait for GSM0_SOF, while got 0x%x\n", (u32)c);
 		break;
 	}
 }
@@ -2226,9 +2229,12 @@ 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)
-		print_hex_dump_bytes("gsmld_output: ", DUMP_PREFIX_OFFSET,
+	if (GSMDBG_DATA_FULL_REPORT(debug))
+		print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
 				     data, len);
+	else if (GSMDBG_DATA_LEN_REPORT(debug))
+		pr_debug("n_gsm: >> %d bytes\n", len);
+
 	gsm->tty->ops->write(gsm->tty, data, len);
 	return len;
 }
@@ -2293,9 +2299,11 @@ static void gsmld_receive_buf(struct tty_struct
*tty, const unsigned char *cp,
 	int i;
 	char flags = TTY_NORMAL;
 
-	if (debug & 4)
-		print_hex_dump_bytes("gsmld_receive: ", DUMP_PREFIX_OFFSET,
+	if (GSMDBG_DATA_FULL_REPORT(debug))
+		print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
 				     cp, count);
+	else if (GSMDBG_DATA_LEN_REPORT(debug))
+		pr_debug("n_gsm: << %d bytes\n", count);
 
 	for (i = count, dp = cp, f = fp; i; i--, dp++) {
 		if (f)
@@ -2891,7 +2899,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 (GSMDBG_FORCE_CARRIER(debug))
 		return 1;
 	return dlci->modem_rx & TIOCM_CD;
 }
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux