1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <linux/version.h>
37#include <linux/kernel.h>
38#include <linux/sched.h>
39#include <linux/kthread.h>
40#include <linux/delay.h>
41#include <linux/module.h>
42#include <linux/init.h>
43#include <linux/proc_fs.h>
44#include <linux/string.h>
45#include <linux/uaccess.h>
46
47#include "dbg.h"
48#include "mt6575_sd.h"
49#include <linux/seq_file.h>
50
51static char cmd_buf[256];
52
53
54unsigned int sd_debug_zone[4] = {
55 0,
56 0,
57 0,
58 0
59};
60
61#if defined(MT6575_SD_DEBUG)
62
63#define TICKS_ONE_MS (13000)
64u32 gpt_enable;
65u32 sdio_pro_enable;
66u32 sdio_pro_time;
67struct sdio_profile sdio_perfomance = {0};
68
69#if 0
70void msdc_init_gpt(void)
71{
72 GPT_CONFIG config;
73
74 config.num = GPT6;
75 config.mode = GPT_FREE_RUN;
76 config.clkSrc = GPT_CLK_SRC_SYS;
77 config.clkDiv = GPT_CLK_DIV_1;
78
79 if (GPT_Config(config) == FALSE)
80 return;
81
82 GPT_Start(GPT6);
83}
84#endif
85
86u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
87{
88 u32 ret = 0;
89
90 if (new_H32 == old_H32) {
91 ret = new_L32 - old_L32;
92 } else if (new_H32 == (old_H32 + 1)) {
93 if (new_L32 > old_L32)
94 printk("msdc old_L<0x%x> new_L<0x%x>\n", old_L32, new_L32);
95 ret = (0xffffffff - old_L32);
96 ret += new_L32;
97 } else {
98 printk("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
99 }
100
101 return ret;
102}
103
104void msdc_sdio_profile(struct sdio_profile *result)
105{
106 struct cmd_profile *cmd;
107 u32 i;
108
109 printk("sdio === performance dump ===\n");
110 printk("sdio === total execute tick<%d> time<%dms> Tx<%dB> Rx<%dB>\n",
111 result->total_tc, result->total_tc / TICKS_ONE_MS,
112 result->total_tx_bytes, result->total_rx_bytes);
113
114
115 cmd = &result->cmd52_rx;
116 printk("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc,
117 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
118 cmd = &result->cmd52_tx;
119 printk("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc,
120 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
121
122
123 for (i = 0; i < 512; i++) {
124 cmd = &result->cmd53_rx_byte[i];
125 if (cmd->count) {
126 printk("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
127 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
128 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
129 }
130 }
131 for (i = 0; i < 100; i++) {
132 cmd = &result->cmd53_rx_blk[i];
133 if (cmd->count) {
134 printk("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
135 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
136 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
137 }
138 }
139
140
141 for (i = 0; i < 512; i++) {
142 cmd = &result->cmd53_tx_byte[i];
143 if (cmd->count) {
144 printk("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
145 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
146 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
147 }
148 }
149 for (i = 0; i < 100; i++) {
150 cmd = &result->cmd53_tx_blk[i];
151 if (cmd->count) {
152 printk("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
153 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
154 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
155 }
156 }
157
158 printk("sdio === performance dump done ===\n");
159}
160
161
162void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
163{
164 struct sdio_profile *result = &sdio_perfomance;
165 struct cmd_profile *cmd;
166 u32 block;
167
168 if (sdio_pro_enable == 0)
169 return;
170
171 if (opcode == 52) {
172 cmd = bRx ? &result->cmd52_rx : &result->cmd52_tx;
173 } else if (opcode == 53) {
174 if (sizes < 512) {
175 cmd = bRx ? &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
176 } else {
177 block = sizes / 512;
178 if (block >= 99) {
179 printk("cmd53 error blocks\n");
180 while (1)
181 ;
182 }
183 cmd = bRx ? &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
184 }
185 } else {
186 return;
187 }
188
189
190 if (ticks > cmd->max_tc)
191 cmd->max_tc = ticks;
192 if (cmd->min_tc == 0 || ticks < cmd->min_tc)
193 cmd->min_tc = ticks;
194 cmd->tot_tc += ticks;
195 cmd->tot_bytes += sizes;
196 cmd->count++;
197
198 if (bRx)
199 result->total_rx_bytes += sizes;
200 else
201 result->total_tx_bytes += sizes;
202 result->total_tc += ticks;
203
204
205 if (result->total_tc >= sdio_pro_time * TICKS_ONE_MS * 1000) {
206 msdc_sdio_profile(result);
207 memset(result, 0, sizeof(struct sdio_profile));
208 }
209}
210
211
212static int msdc_debug_proc_read(struct seq_file *s, void *p)
213{
214 seq_puts(s, "\n=========================================\n");
215 seq_puts(s, "Index<0> + Id + Zone\n");
216 seq_puts(s, "-> PWR<9> WRN<8> | FIO<7> OPS<6> FUN<5> CFG<4> | INT<3> RSP<2> CMD<1> DMA<0>\n");
217 seq_puts(s, "-> echo 0 3 0x3ff >msdc_bebug -> host[3] debug zone set to 0x3ff\n");
218 seq_printf(s, "-> MSDC[0] Zone: 0x%.8x\n", sd_debug_zone[0]);
219 seq_printf(s, "-> MSDC[1] Zone: 0x%.8x\n", sd_debug_zone[1]);
220 seq_printf(s, "-> MSDC[2] Zone: 0x%.8x\n", sd_debug_zone[2]);
221 seq_printf(s, "-> MSDC[3] Zone: 0x%.8x\n", sd_debug_zone[3]);
222
223 seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n");
224 seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
225 seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n", sdio_pro_enable, sdio_pro_time);
226 seq_puts(s, "=========================================\n\n");
227
228 return 0;
229}
230
231static ssize_t msdc_debug_proc_write(struct file *file,
232 const char __user *buf,
233 size_t count, loff_t *data)
234{
235 int ret;
236
237 int cmd, p1, p2;
238 int id, zone;
239 int mode, size;
240
241 if (count == 0)
242 return -1;
243 if (count > 255)
244 count = 255;
245
246 if (copy_from_user(cmd_buf, buf, count))
247 return -EFAULT;
248
249 cmd_buf[count] = '\0';
250 printk("msdc Write %s\n", cmd_buf);
251
252 sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
253
254 if (cmd == SD_TOOL_ZONE) {
255 id = p1;
256 zone = p2;
257 zone &= 0x3ff;
258 printk("msdc host_id<%d> zone<0x%.8x>\n", id, zone);
259 if (id >= 0 && id <= 3) {
260 sd_debug_zone[id] = zone;
261 } else if (id == 4) {
262 sd_debug_zone[0] = sd_debug_zone[1] = zone;
263 sd_debug_zone[2] = sd_debug_zone[3] = zone;
264 } else {
265 printk("msdc host_id error when set debug zone\n");
266 }
267 } else if (cmd == SD_TOOL_SDIO_PROFILE) {
268 if (p1 == 1) {
269 if (gpt_enable == 0) {
270
271 gpt_enable = 1;
272 }
273 sdio_pro_enable = 1;
274 if (p2 == 0)
275 p2 = 1;
276 if (p2 >= 30)
277 p2 = 30;
278 sdio_pro_time = p2;
279 } else if (p1 == 0) {
280
281 sdio_pro_enable = 0;
282 }
283 }
284
285 return count;
286}
287
288static int msdc_debug_show(struct inode *inode, struct file *file)
289{
290 return single_open(file, msdc_debug_proc_read, NULL);
291}
292
293static const struct file_operations msdc_debug_fops = {
294 .owner = THIS_MODULE,
295 .open = msdc_debug_show,
296 .read = seq_read,
297 .write = msdc_debug_proc_write,
298 .llseek = seq_lseek,
299 .release = single_release,
300};
301
302void msdc_debug_proc_init(void)
303{
304 proc_create("msdc_debug", 0660, NULL, &msdc_debug_fops);
305}
306EXPORT_SYMBOL_GPL(msdc_debug_proc_init);
307#endif
308