[PATCH 005/510] beceem: cleanup debug level infrastructure

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

 



From: Stephen Hemminger <stephen.hemminger@xxxxxxxxxx>

Add module parameter to control debug level and do code cleanup
The whole debug stuff should eventually be removed.

Signed-off-by: Stephen Hemminger <shemminger@xxxxxxxxxx>
---
 drivers/staging/bcm/Debug.c         |   59 +++++++++++++++----------------
 drivers/staging/bcm/Debug.h         |   66 ++++++++++++++---------------------
 drivers/staging/bcm/InterfaceInit.c |    7 +++-
 3 files changed, 61 insertions(+), 71 deletions(-)

diff --git a/drivers/staging/bcm/Debug.c b/drivers/staging/bcm/Debug.c
index 2703f30..9f7f70c 100644
--- a/drivers/staging/bcm/Debug.c
+++ b/drivers/staging/bcm/Debug.c
@@ -1,41 +1,40 @@
 #include "headers.h"
 
-static UINT current_debug_level=BCM_SCREAM;
-
-int bcm_print_buffer( UINT debug_level, const char *function_name,
-				  char *file_name, int line_number, unsigned char *buffer, int bufferlen, enum _BASE_TYPE base)
+void bcm_print_buffer(UINT debug_level, const char *function_name,
+		      const char *file_name, int line_number,
+		      const unsigned char *buffer, int bufferlen,
+		      BASE_TYPE base)
 {
+	int i;
 	static const char * const buff_dump_base[] = {
 		"DEC", "HEX", "OCT", "BIN"
 	};
-	if(debug_level>=current_debug_level)
-	{
-		int i=0;
-		printk("\n%s:%s:%d:Buffer dump of size 0x%x in the %s:\n", file_name, function_name, line_number, bufferlen, buff_dump_base[1]);
-		for(;i<bufferlen;i++)
-		{
-			if(i && !(i%16) )
-				printk("\n");
-			switch(base)
-			{
-				case BCM_BASE_TYPE_DEC:
-					printk("%03d ", buffer[i]);
-					break;
-				case BCM_BASE_TYPE_OCT:
-					printk("%0x03o ", buffer[i]);
-					break;
-				case BCM_BASE_TYPE_BIN:
-					printk("%02x ", buffer[i]);
-					break;
-				case BCM_BASE_TYPE_HEX:
-				default:
-					printk("%02X ", buffer[i]);
-					break;
-			}
+
+	if(debug_level < BCM_SCREAM)
+		return;
+
+	printk("\n" KERN_DEBUG "%s:%s:%d:Buffer dump of size 0x%x in the %s:\n",
+	       file_name, function_name, line_number, bufferlen, buff_dump_base[1]);
+
+	for(i = 0; i < bufferlen;i++) {
+		if(i && !(i%16) )
+			printk("\n");
+		switch(base) {
+		case BCM_BASE_TYPE_DEC:
+			printk("%03d ", buffer[i]);
+			break;
+		case BCM_BASE_TYPE_OCT:
+			printk("%0x03o ", buffer[i]);
+			break;
+		case BCM_BASE_TYPE_BIN:
+			printk("%02x ", buffer[i]);
+			break;
+		case BCM_BASE_TYPE_HEX:
+		default:
+			printk("%02X ", buffer[i]);
+			break;
 		}
 		printk("\n");
 	}
-	return 0;
 }
 
-
diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
index b384115..58e46a6 100644
--- a/drivers/staging/bcm/Debug.h
+++ b/drivers/staging/bcm/Debug.h
@@ -18,11 +18,9 @@ typedef enum _BASE_TYPE
 	BCM_BASE_TYPE_NONE,
 } BASE_TYPE, *PBASE_TYPE;
 
-int bcm_print_buffer( UINT debug_level, const char *function_name,
-				  char *file_name, int line_number, unsigned char *buffer, int bufferlen, BASE_TYPE base);
-
-
-
+void bcm_print_buffer(UINT debug_level, const char *function_name,
+		      const char *file_name, int line_number,
+		      const unsigned char *buffer, int bufferlen, BASE_TYPE base);
 
 
 //--------------------------------------------------------------------------------
@@ -229,44 +227,32 @@ typedef struct _S_BCM_DEBUG_STATE {
 
 //--- Only for direct printk's; "hidden" to API.
 #define DBG_TYPE_PRINTK		3
-#define PRINTKS_ON			1	// "hidden" from API, set to 0 to turn off all printk's
-
-#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) do { \
-	if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) {	\
-		printk ("%s:" string, __FUNCTION__, ##args);	\
-		printk("\n");	\
-	} else if (!Adapter)			\
-		;							\
-	else {							\
-		if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level) &&	\
-		   ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \
-		   		if (dbg_level & DBG_NO_FUNC_PRINT)		\
-					printk (string, ##args);						\
-				else	\
-					{												\
-					printk ("%s:" string, __FUNCTION__, ##args);	\
-					printk("\n"); \
-					} \
-		}	\
-		}	\
-} while (0)
 
-#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,  buffer, bufferlen) do { \
-		if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) {	\
-			bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX);	\
-		} else if (!Adapter)			\
-			;							\
-		else {							\
-			if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level)  && \
-			   ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \
-					if (dbg_level & DBG_NO_FUNC_PRINT)		\
-						bcm_print_buffer( dbg_level, NULL, NULL, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX);						\
-					else												\
-						bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX);	\
-			}	\
-		}	\
+#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
+	do {								\
+		if (DBG_TYPE_PRINTK == Type)				\
+			pr_info("%s:" string "\n", __func__, ##args);	\
+		else if (Adapter &&					\
+			 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
+			 (Type & Adapter->stDebugState.type) &&		\
+			 (SubType & Adapter->stDebugState.subtype[Type])) { \
+			if (dbg_level & DBG_NO_FUNC_PRINT)		\
+				printk(KERN_DEBUG string, ##args);	\
+			else						\
+				printk(KERN_DEBUG "%s:" string "\n", __func__, ##args);	\
+		}							\
 	} while (0)
 
+#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level,  buffer, bufferlen) do { \
+	if (DBG_TYPE_PRINTK == Type ||					\
+	    (Adapter &&							\
+	     (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level  && \
+	     (Type & Adapter->stDebugState.type) &&			\
+	     (SubType & Adapter->stDebugState.subtype[Type])))		\
+		bcm_print_buffer(dbg_level, __func__, __FILE__, __LINE__, \
+				 buffer, bufferlen, BCM_BASE_TYPE_HEX);	\
+} while(0)
+
 
 #define BCM_SHOW_DEBUG_BITMAP(Adapter)	do { \
 	int i;									\
diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c
index 958d16a..f810bfd 100644
--- a/drivers/staging/bcm/InterfaceInit.c
+++ b/drivers/staging/bcm/InterfaceInit.c
@@ -11,6 +11,11 @@ static struct usb_device_id InterfaceUsbtable[] = {
 };
 MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
 
+static unsigned int debug_level = DBG_LVL_CURR;
+module_param(debug_level, uint, 0644);
+MODULE_PARM_DESC(debug_level, "Debug level (0=none,...,7=all)");
+
+
 VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
 {
 	INT i = 0;
@@ -198,7 +203,7 @@ usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
     /* Init default driver debug state */
 
-    psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
+	psAdapter->stDebugState.debug_level = debug_level;
 	psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
 	memset (psAdapter->stDebugState.subtype, 0, sizeof (psAdapter->stDebugState.subtype));
 
-- 
1.7.3.2

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux