[package] base-files, ppp: fix interface shutdown
[openwrt.git] / target / linux / generic-2.6 / files / crypto / ocf / kirkwood / mvHal / dbg-trace.c
1 #include <linux/kernel.h>
2 #include <linux/slab.h>
3 #include <linux/time.h>
4 #include "dbg-trace.h"
5
6 #define TRACE_ARR_LEN 800
7 #define STR_LEN 128
8 struct trace {
9 struct timeval tv;
10 char str[STR_LEN];
11 unsigned int callback_val1;
12 unsigned int callback_val2;
13 char valid;
14 };
15 static unsigned int (*trc_callback1) (unsigned char) = NULL;
16 static unsigned int (*trc_callback2) (unsigned char) = NULL;
17 static unsigned char trc_param1 = 0;
18 static unsigned char trc_param2 = 0;
19 struct trace *trc_arr;
20 static int trc_index;
21 static int trc_active = 0;
22
23 void TRC_START()
24 {
25 trc_active = 1;
26 }
27
28 void TRC_STOP()
29 {
30 trc_active = 0;
31 }
32
33 void TRC_INIT(void *callback1, void *callback2, unsigned char callback1_param, unsigned char callback2_param)
34 {
35 printk("Marvell debug tracing is on\n");
36 trc_arr = (struct trace *)kmalloc(TRACE_ARR_LEN*sizeof(struct trace),GFP_KERNEL);
37 if(trc_arr == NULL)
38 {
39 printk("Can't allocate Debug Trace buffer\n");
40 return;
41 }
42 memset(trc_arr,0,TRACE_ARR_LEN*sizeof(struct trace));
43 trc_index = 0;
44 trc_callback1 = callback1;
45 trc_callback2 = callback2;
46 trc_param1 = callback1_param;
47 trc_param2 = callback2_param;
48 }
49 void TRC_REC(char *fmt,...)
50 {
51 va_list args;
52 struct trace *trc = &trc_arr[trc_index];
53
54 if(trc_active == 0)
55 return;
56
57 do_gettimeofday(&trc->tv);
58 if(trc_callback1)
59 trc->callback_val1 = trc_callback1(trc_param1);
60 if(trc_callback2)
61 trc->callback_val2 = trc_callback2(trc_param2);
62 va_start(args, fmt);
63 vsprintf(trc->str,fmt,args);
64 va_end(args);
65 trc->valid = 1;
66 if((++trc_index) == TRACE_ARR_LEN) {
67 trc_index = 0;
68 }
69 }
70 void TRC_OUTPUT(void)
71 {
72 int i,j;
73 struct trace *p;
74 printk("\n\nTrace %d items\n",TRACE_ARR_LEN);
75 for(i=0,j=trc_index; i<TRACE_ARR_LEN; i++,j++) {
76 if(j == TRACE_ARR_LEN)
77 j = 0;
78 p = &trc_arr[j];
79 if(p->valid) {
80 unsigned long uoffs;
81 struct trace *plast;
82 if(p == &trc_arr[0])
83 plast = &trc_arr[TRACE_ARR_LEN-1];
84 else
85 plast = p-1;
86 if(p->tv.tv_sec == ((plast)->tv.tv_sec))
87 uoffs = (p->tv.tv_usec - ((plast)->tv.tv_usec));
88 else
89 uoffs = (1000000 - ((plast)->tv.tv_usec)) +
90 ((p->tv.tv_sec - ((plast)->tv.tv_sec) - 1) * 1000000) +
91 p->tv.tv_usec;
92 printk("%03d: [+%ld usec]", j, (unsigned long)uoffs);
93 if(trc_callback1)
94 printk("[%u]",p->callback_val1);
95 if(trc_callback2)
96 printk("[%u]",p->callback_val2);
97 printk(": %s",p->str);
98 }
99 p->valid = 0;
100 }
101 memset(trc_arr,0,TRACE_ARR_LEN*sizeof(struct trace));
102 trc_index = 0;
103 }
104 void TRC_RELEASE(void)
105 {
106 kfree(trc_arr);
107 trc_index = 0;
108 }
109
110
This page took 0.06256 seconds and 5 git commands to generate.