[qca-ssdk] Add debug print for ioctl from shell

Change-Id: I30a1af812a873cb99f4641c952665897a8f91e8b
Signed-off-by: linchen <linchen@codeaurora.org>
diff --git a/include/init/ssdk_plat.h b/include/init/ssdk_plat.h
index 74507b3..0965c41 100755
--- a/include/init/ssdk_plat.h
+++ b/include/init/ssdk_plat.h
@@ -232,6 +232,16 @@
 			printk(fmt, ##__VA_ARGS__); \
 		} \
 	} while(0)
+#define SSDK_DUMP_BUF(lev, buf, len) \
+	do {\
+		if (SSDK_LOG_LEVEL_##lev <= ssdk_log_level) {\
+			a_uint32_t i_buf = 0;\
+			for(i_buf=0; i_buf<(len); i_buf++) {\
+				printk("%08lx ", *((buf)+i_buf));\
+			}\
+			printk("\n");\
+		}\
+	} while(0)
 
 #define SSDK_ERROR(fmt, ...) __SSDK_LOG_FUN(ERROR, fmt, ##__VA_ARGS__)
 #define SSDK_WARN(fmt, ...)  __SSDK_LOG_FUN(WARN, fmt, ##__VA_ARGS__)
diff --git a/src/sal/sd/linux/uk_interface/sw_api_ks_ioctl.c b/src/sal/sd/linux/uk_interface/sw_api_ks_ioctl.c
index 7191069..2988a6e 100755
--- a/src/sal/sd/linux/uk_interface/sw_api_ks_ioctl.c
+++ b/src/sal/sd/linux/uk_interface/sw_api_ks_ioctl.c
@@ -43,6 +43,8 @@
 #include <linux/module.h>
 #endif
 #include <linux/mutex.h>
+#include "ssdk_init.h"
+#include "ssdk_plat.h"
 
 static int
 switch_open(struct inode * inode,struct file * file);
@@ -99,17 +101,28 @@
             buf_head += (p->data_size + credit) / offset;
 
             if (buf_head > (SW_MAX_API_BUF / offset))
+            {
+                SSDK_ERROR("Lengh of command is more than cmd buffer\n");
                 return SW_NO_RESOURCE;
+            }
 
             if (p->param_type & SW_PARAM_IN)
             {
-                if (copy_from_user((a_uint8_t*)(cmd_buf[i]), (void __USER *)args[i + 2], ((p->data_size + credit) / offset) * offset))
+                if (copy_from_user((a_uint8_t*)(cmd_buf[i]), (void __USER *)args[i + 2],
+				((p->data_size + credit) / offset) * offset))
+                {
+                    SSDK_ERROR("copy_from_user fail\n");
                     return SW_NO_RESOURCE;
+                }
+                SSDK_DEBUG("Input parameter %d: ", i);
+                SSDK_DUMP_BUF(DEBUG, (unsigned long *)cmd_buf[i],
+                                        ((p->data_size + credit) / offset));
             }
         }
         else
         {
             cmd_buf[i] = args[i + 2];
+            SSDK_DEBUG("Input parameter %d: %ld\n", i, cmd_buf[i]);
         }
         p++;
     }
@@ -127,9 +140,15 @@
     {
         if (p->param_type & SW_PARAM_OUT)
         {
-            if (copy_to_user
-                    ((void __USER *) args[i + 2], (unsigned long *) cmd_buf[i], ((p->data_size + credit) / offset) * offset))
+            SSDK_DEBUG("Output parameter %d: ", i);
+            SSDK_DUMP_BUF(DEBUG, (unsigned long *)cmd_buf[i],
+				((p->data_size + credit) / offset));
+            if (copy_to_user((void __USER *) args[i + 2], (unsigned long *) cmd_buf[i],
+				((p->data_size + credit) / offset) * offset))
+            {
+                SSDK_ERROR("copy_to_user fail\n");
                 return SW_NO_RESOURCE;
+            }
         }
         p++;
     }
@@ -147,6 +166,7 @@
     sw_error_t rv;
     sw_api_t sw_api;
 
+    SSDK_DEBUG("api_id is %ld\n", api_id);
     sw_api.api_id = api_id;
     rv = sw_api_get(&sw_api);
     SW_OUT_ON_ERROR(rv);
@@ -229,8 +249,10 @@
     sw_error_t rv = SW_NO_RESOURCE;
     void __user *argp = (void __user *)arg;
 
+    SSDK_DEBUG("Recieved IOCTL call\n");
     if (copy_from_user(args, argp, sizeof (args)))
     {
+        SSDK_ERROR("copy_from_user fail\n");
         return SW_NO_RESOURCE;
     }
 
@@ -243,6 +265,7 @@
     if (copy_to_user
             ((void __USER *) args[1],  &rtn, sizeof (unsigned long)))
     {
+        SSDK_ERROR("copy_to_user fail\n");
         rv = SW_NO_RESOURCE;
     }
 
diff --git a/src/sal/sd/linux/uk_interface/sw_api_ks_netlink.c b/src/sal/sd/linux/uk_interface/sw_api_ks_netlink.c
index 145c7cd..3ad5da1 100755
--- a/src/sal/sd/linux/uk_interface/sw_api_ks_netlink.c
+++ b/src/sal/sd/linux/uk_interface/sw_api_ks_netlink.c
@@ -52,7 +52,7 @@
 static wait_queue_head_t pid_child_wait[PID_TAB_MAX];
 static struct semaphore pid_tab_sem;
 
-static a_uint32_t *cmd_buf = NULL;
+static unsigned long *cmd_buf = NULL;
 static struct semaphore api_sem;
 static struct sock *ssdk_nl_sk = NULL;
 static struct sk_buff * skb_array[PID_TAB_MAX] = {0};