2 * Copyright (c) 2011-2014 Espressif System.
9 #include <linux/kernel.h>
10 #include <linux/etherdevice.h>
11 #include <linux/workqueue.h>
12 #include <linux/completion.h>
13 #include <linux/nl80211.h>
14 #include <linux/ieee80211.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
17 #include <linux/kthread.h>
18 #include <linux/mmc/host.h>
19 #include <net/cfg80211.h>
20 #include <net/mac80211.h>
21 #include <net/genetlink.h>
26 #include "esp_debug.h"
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
32 #include <net/regulatory.h>
35 static int queue_flag = 0;
37 static u32 connected_nl;
38 static struct genl_info info_copy;
39 static struct esp_sip *sip_copy = NULL;
40 static u8 *sdio_buff = NULL;
41 static struct sdiotest_param sdioTest;
42 static u8 *sdiotest_buf = NULL;
47 printk(KERN_DEBUG "esp_sdio: error occured in %s\n", __func__); \
50 /* ESP TEST netlinf family */
51 static struct genl_family test_genl_family = {
52 .id = GENL_ID_GENERATE,
56 .maxattr = TEST_ATTR_MAX,
59 struct loopback_param_s {
64 static struct loopback_param_s loopback_param;
65 u32 get_loopback_num()
67 return loopback_param.packet_num;
72 return loopback_param.packet_id;
75 void inc_loopback_id()
77 loopback_param.packet_id++;
80 #define REGISTER_REPLY(info) \
81 memcpy((char *)&info_copy, (char *)(info), sizeof(struct genl_info))
84 static void sip_send_test_cmd(struct esp_sip *sip, struct sk_buff *skb)
87 skb_queue_tail(&sip->epub->txq, skb);
89 skb_queue_head(&sip->epub->txq, skb);
91 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
92 if(sif_get_ate_config() == 0){
93 ieee80211_queue_work(sip->epub->hw, &sip->epub->tx_work);
95 queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
98 queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
103 static int esp_test_cmd_reply(struct genl_info *info, u32 cmd_type, char *reply_info)
108 /*directly send ask_info to target, and waiting for report*/
109 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
113 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
114 hdr = genlmsg_put(skb, info->snd_portid, info->snd_seq, &test_genl_family, 0, cmd_type);
116 hdr = genlmsg_put(skb, info->snd_pid, info->snd_seq, &test_genl_family, 0, cmd_type);
119 goto nla_put_failure;
121 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
122 nla_put_string(skb, TEST_ATTR_STR, reply_info);
124 NLA_PUT_STRING(skb, TEST_ATTR_STR, reply_info);
126 genlmsg_end(skb, hdr);
127 genlmsg_reply(skb, info);
137 static int esp_test_echo(struct sk_buff *skb_2,
138 struct genl_info *info)
146 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
147 connected_nl = info->snd_portid;
148 printk(KERN_DEBUG "esp_sdio: received a echo, "
149 "from portid %d\n", info->snd_portid);
151 connected_nl = info->snd_pid;
152 esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a echo, "
153 "from pid %d\n", info->snd_pid);
158 echo_info = nla_data(info->attrs[TEST_ATTR_STR]);
160 if (strncmp(echo_info, "queue_head", 10) == 0) {
161 esp_dbg(ESP_DBG_ERROR, "echo : change to queue head");
164 if (strncmp(echo_info, "queue_tail", 10) == 0) {
165 esp_dbg(ESP_DBG_ERROR, "echo : change to queue head");
169 res=esp_test_cmd_reply(info, TEST_CMD_ECHO, echo_info);
176 static int esp_test_sdiospeed(struct sk_buff *skb_2,
177 struct genl_info *info)
185 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
186 connected_nl = info->snd_portid;
188 connected_nl = info->snd_pid;
191 speed_info = nla_data(info->attrs[TEST_ATTR_STR]);
192 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
193 esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a sdio speed %s, "
194 "from portid %d\n", speed_info, info->snd_portid);
196 esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a sdio speed %s, "
197 "from pid %d\n", speed_info, info->snd_pid);
199 if (!strcmp(speed_info, "high")) {
200 sif_platform_target_speed(1);
201 } else if (!strcmp(speed_info, "low")) {
202 sif_platform_target_speed(0);
204 esp_dbg(ESP_DBG_ERROR, "%s: %s unsupported\n", __func__, speed_info);
207 res=esp_test_cmd_reply(info, TEST_CMD_SDIOSPEED, speed_info);
214 static void * ate_done_data;
215 static char ate_reply_str[128];
216 void esp_test_ate_done_cb(char *ep)
218 memset(ate_reply_str, 0, sizeof(ate_reply_str));
219 strcpy(ate_reply_str, ep);
221 esp_dbg(ESP_DBG_ERROR, "%s %s\n", __func__, ate_reply_str);
224 complete(ate_done_data);
227 static int esp_test_ate(struct sk_buff *skb_2,
228 struct genl_info *info)
230 char *ate_info = NULL;
235 bool stop_sdt = false;
237 DECLARE_COMPLETION_ONSTACK(complete);
243 ate_done_data = &complete;
244 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
245 connected_nl = info->snd_portid;
247 connected_nl = info->snd_pid;
250 //esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a ate cmd, "
251 // "from pid %d\n", info->snd_pid);
254 ate_info = nla_data(info->attrs[TEST_ATTR_STR]);
258 len = nla_len(info->attrs[TEST_ATTR_STR]);
260 //esp_dbg(ESP_DBG_ERROR, "%s str %s len %d cmd %d\n", __func__, ate_info, len, SIP_CMD_ATE);
262 skb = sip_alloc_ctrl_skbuf(SIP, (sizeof(struct sip_hdr)+len), SIP_CMD_ATE);
266 //atecmd = (struct sip_cmd_ate*)(skb->data + sizeof(struct sip_hdr));
267 str = (char *)(skb->data + sizeof(struct sip_hdr));
269 strcpy(str, ate_info);
270 //esp_dbg(ESP_DBG_ERROR, "%s cmdstr %s \n", __func__, str);
272 if (atomic_read(&sdioTest.start)) {
273 atomic_set(&sdioTest.start, 0);
276 //esp_dbg(ESP_DBG_ERROR, "%s stop sdt \n", __func__);
279 sip_send_test_cmd(SIP, skb);
280 //esp_dbg(ESP_DBG_ERROR, "%s sent cmd \n", __func__);
282 wait_for_completion(&complete);
284 //esp_dbg(ESP_DBG_ERROR, "%s completed \n", __func__);
286 esp_test_cmd_reply(info, TEST_CMD_ATE, ate_reply_str);
289 //esp_dbg(ESP_DBG_ERROR, "%s restart sdt \n", __func__);
290 atomic_set(&sdioTest.start, 1);
291 wake_up_process(sdioTest.thread);
300 static int esp_process_sdio_test(struct sdiotest_param *param)
302 //#define sdiotest_BASE_ADDR 0x7f80 //MAC 5.0
303 #define SDIOTEST_FLAG_ADDR 0xc000
304 #define SDIOTEST_BASE_ADDR (SDIOTEST_FLAG_ADDR+4) //MAC 6.0
305 #define SDIO_BUF_SIZE (16*1024-4)
308 static int counter = 0;
310 //esp_dbg(ESP_DBG_ERROR, "idle_period %d mode %d addr 0x%08x\n", param->idle_period,
311 // param->mode, param->addr);
312 if (sdioTest.mode == 1) { //read mode
313 ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, SDIO_BUF_SIZE, ESP_SIF_SYNC);
315 } else if ((sdioTest.mode >= 3)&&(sdioTest.mode <= 7)) { //write mode
316 ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, SDIO_BUF_SIZE, ESP_SIF_SYNC);
318 } else if (sdioTest.mode == 3) { //read & write mode
319 ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 16*1024, ESP_SIF_SYNC);
321 ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 16*1024, ESP_SIF_SYNC);
323 } else if (sdioTest.mode == 2) { //byte read mode(to test sdio_cmd)
324 ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 8, ESP_SIF_SYNC);
327 if (sdioTest.idle_period > 1000) {
328 show_buf(sdiotest_buf, 128);
329 } else if (sdioTest.idle_period == 0) {
330 if (sdioTest.mode == 1) {//read mode
331 if (!(counter++%5000)) {
332 esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
334 } else if (sdioTest.mode == 2) { //byte read mode
335 if (!(counter++%5000)) {
336 esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
340 if (!(counter++%30000)) {
341 esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
345 if (!(counter++%1000)) {
346 esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
352 esp_dbg(ESP_DBG_ERROR, "%s mode %d err %d \n", __func__, sdioTest.mode, ret);
357 static int esp_test_sdiotest_thread(void *param)
359 struct sdiotest_param *testParam = (struct sdiotest_param *)param;
360 struct sched_param schedParam = { .sched_priority = 1 };
361 unsigned long idle_period = MAX_SCHEDULE_TIMEOUT;
364 sched_setscheduler(current, SCHED_FIFO, &schedParam);
366 while (!kthread_should_stop()) {
368 if (0 == atomic_read(&testParam->start)) {
369 esp_dbg(ESP_DBG_ERROR, "%s suspend\n", __func__);
370 set_current_state(TASK_INTERRUPTIBLE);
371 if (!kthread_should_stop())
372 schedule_timeout(MAX_SCHEDULE_TIMEOUT);
373 set_current_state(TASK_RUNNING);
376 if (testParam->idle_period)
377 idle_period = msecs_to_jiffies(testParam->idle_period);
381 ret = esp_process_sdio_test(testParam);
384 * Give other threads a chance to run in the presence of
388 set_current_state(TASK_INTERRUPTIBLE);
389 if (!kthread_should_stop())
390 schedule_timeout(2*HZ);
391 set_current_state(TASK_RUNNING);
392 atomic_set(&testParam->start, 0);
395 //esp_dbg(ESP_DBG_ERROR, "%s idle_period %lu\n", __func__, idle_period);
397 set_current_state(TASK_INTERRUPTIBLE);
398 if (!kthread_should_stop()) {
399 schedule_timeout(idle_period);
401 set_current_state(TASK_RUNNING);
406 esp_dbg(ESP_DBG_ERROR, "%s exit\n", __func__);
412 static int esp_test_sdiotest(struct sk_buff *skb_2,
413 struct genl_info *info)
420 u32 data_mask = 0xffffffff;
421 u8 * sdio_test_flag = NULL;
423 bool stop_sdt = false;
428 start = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
429 esp_dbg(ESP_DBG_ERROR, "%s start 0x%08x\n", __func__, start);
430 para_num = start & 0xf;
435 esp_dbg(ESP_DBG_ERROR, "%s paranum %d start %u\n", __func__, para_num, start);
439 if ((para_num--) > 0) {
440 sdioTest.mode = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
441 if ((sdioTest.mode >= 3)&&(sdioTest.mode <= 7)) { // write mode, fill the test buf
442 data_mask = (sdioTest.mode == 3)? 0xffffffff : (0x11111111<<(sdioTest.mode-4));
443 for (i = 0; i<SDIO_BUF_SIZE/ 4; i++) {
444 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
446 *(u32 *)&sdiotest_buf[i*4] = get_random_int() & data_mask;
448 *(u32 *)&sdiotest_buf[i*4] = random32() & data_mask;
452 esp_dbg(ESP_DBG_ERROR, "%s mode %d \n", __func__, sdioTest.mode);
455 if ((para_num--) > 0) {
456 sdioTest.addr = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
457 esp_dbg(ESP_DBG_ERROR, "%s addr 0x%x \n", __func__, sdioTest.addr);
460 if ((para_num--) > 0) {
461 sdioTest.idle_period = nla_get_u32(info->attrs[TEST_ATTR_PARA3]);
462 esp_dbg(ESP_DBG_ERROR, "%s idle_period %u \n", __func__, sdioTest.idle_period);
466 esp_test_cmd_reply(info, TEST_CMD_SDIOTEST, reply_str);
471 //esp_dbg(ESP_DBG_ERROR, "%s start== 1\n", __func__);
473 if((sdioTest.mode == 8)|(sdioTest.mode == 9)) {
475 if (atomic_read(&sdioTest.start)) {
476 atomic_set(&sdioTest.start, 0);
481 sdio_test_flag = kzalloc(4, GFP_KERNEL);
482 if (sdio_test_flag == NULL) {
483 esp_dbg(ESP_DBG_ERROR, "no mem for sdio_tst_flag!!\n");
487 if(sdioTest.mode == 8){
488 ret = esp_common_read_with_addr(SIP->epub, sdioTest.addr, sdio_test_flag, 4, ESP_SIF_SYNC);
490 esp_dbg(ESP_DBG_ERROR, "%s sdio read: 0x%x 0x%x\n", __func__, sdioTest.addr, *(u32 *)sdio_test_flag);
493 *(u32 *)sdio_test_flag = sdioTest.idle_period;
495 ret = esp_common_write_with_addr(SIP->epub, sdioTest.addr, sdio_test_flag, 4, ESP_SIF_SYNC);
497 esp_dbg(ESP_DBG_ERROR, "%s sdio : write 0x%x 0x%x done!\n", __func__, sdioTest.addr, *(u32 *)sdio_test_flag);
500 kfree(sdio_test_flag);
501 sdio_test_flag = NULL;
504 //set flag to inform firmware sdio-test start
505 sdio_test_flag = kzalloc(4, GFP_KERNEL);
506 if (sdio_test_flag == NULL) {
507 esp_dbg(ESP_DBG_ERROR, "no mem for sdio_tst_flag!!\n");
511 *(u32 *)sdio_test_flag = 0x56781234;
512 if (atomic_read(&sdioTest.start)) {
513 atomic_set(&sdioTest.start, 0);
516 //esp_dbg(ESP_DBG_ERROR, "%s stop sdt \n", __func__);
518 ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_FLAG_ADDR, sdio_test_flag, 4, ESP_SIF_SYNC);
521 //esp_dbg(ESP_DBG_ERROR, "%s restart sdt \n", __func__);
522 atomic_set(&sdioTest.start, 1);
523 wake_up_process(sdioTest.thread);
526 //esp_dbg(ESP_SHOW, "%s sdio_test_flag sent to target \n", __func__);
527 //esp_dbg(ESP_DBG_ERROR, "%s sdio_test_flag sent to target \n", __func__);
528 kfree(sdio_test_flag);
529 sdio_test_flag = NULL;
531 atomic_set(&sdioTest.start, 1);
532 if (sdioTest.thread == NULL) {
533 sdioTest.thread = kthread_run(esp_test_sdiotest_thread,
537 wake_up_process(sdioTest.thread);
539 strcpy(reply_str, "sdt started\n");
542 //esp_dbg(ESP_DBG_ERROR, "%s start== 0\n", __func__);
544 atomic_set(&sdioTest.start, 0);
545 strcpy(reply_str, "sdt stopped\n");
557 static int esp_test_ask(struct sk_buff *skb_2,
558 struct genl_info *info)
567 ask_info = nla_data(info->attrs[TEST_ATTR_STR]);
569 /*directly send ask_info to target, and waiting for report*/
570 res=esp_test_cmd_reply(info, TEST_CMD_ASK, "ok");
577 static int esp_test_sleep(struct sk_buff *skb_2,
578 struct genl_info *info)
580 struct sip_cmd_sleep *sleepcmd;
581 struct sk_buff *skb = NULL;
587 skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_cmd_sleep), SIP_CMD_SLEEP);
591 sleepcmd = (struct sip_cmd_sleep *)(skb->data + sizeof(struct sip_tx_info));
592 sleepcmd->sleep_mode = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
593 sleepcmd->sleep_tm_ms = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
594 sleepcmd->wakeup_tm_ms = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
595 sleepcmd->sleep_times = nla_get_u32(info->attrs[TEST_ATTR_PARA3]);
597 sip_send_test_cmd(SIP, skb);
599 /*directly send ask_info to target, and waiting for report*/
600 res=esp_test_cmd_reply(info, TEST_CMD_SLEEP, "ok");
607 static int esp_test_wakeup(struct sk_buff *skb_2,
608 struct genl_info *info)
610 struct sip_cmd_wakeup *wakeupcmd;
611 struct sk_buff *skb = NULL;
617 skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_cmd_wakeup), SIP_CMD_WAKEUP);
620 wakeupcmd = (struct sip_cmd_wakeup *)(skb->data + sizeof(struct sip_tx_info));
621 wakeupcmd->check_data = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
623 /*directly send reply_info to target, and waiting for report*/
624 REGISTER_REPLY(info);
625 //res=esp_test_cmd_reply(info, TEST_CMD_WAKEUP, "ok");
627 sip_send_test_cmd(SIP, skb);
634 static int esp_test_loopback(struct sk_buff *skb_2,
635 struct genl_info *info)
643 txpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
644 rxpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
645 loopback_param.packet_num = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
646 loopback_param.packet_id=0;
647 REGISTER_REPLY(info);
648 return sip_send_loopback_mblk(SIP, txpacket_len, rxpacket_len, 0);
655 u8 probe_req_frm[] = {0x40,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x03,0x8F,0x11,0x22,0x88,
656 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x01,0x08,0x82,0x84,0x8B,0x96,
657 0x0C,0x12,0x18,0x24,0x32,0x04,0x30,0x48,0x60,0x6C
661 static int sip_send_tx_frame(struct esp_sip *sip, u32 packet_len)
664 struct sk_buff *skb = NULL;
668 skb = alloc_skb(packet_len, GFP_KERNEL);
669 skb->len = packet_len;
671 /* fill up pkt payload */
672 for (i = 0; i < skb->len; i++) {
676 if(sif_get_ate_config() == 0){
677 sip_tx_data_pkt_enqueue(sip->epub, skb);
678 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
679 ieee80211_queue_work(sip->epub->hw, &sip->epub->tx_work);
681 queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
684 skb_queue_tail(&sip->epub->txq, skb);
685 queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
691 static int esp_test_tx(struct sk_buff *skb_2,
692 struct genl_info *info)
700 txpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
701 REGISTER_REPLY(info);
702 sip_send_tx_frame(SIP, txpacket_len);
703 res=esp_test_cmd_reply(info, TEST_CMD_TX, "tx out");
710 static int esp_test_genl(struct sk_buff *skb_2,
711 struct genl_info *info)
713 struct sip_cmd_debug *dbgcmd;
714 struct sk_buff *skb = NULL;
720 skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_hdr) + sizeof(struct sip_cmd_debug), SIP_CMD_DEBUG);
724 dbgcmd = (struct sip_cmd_debug *)(skb->data + sizeof(struct sip_hdr));
725 dbgcmd->cmd_type = nla_get_u32(info->attrs[TEST_ATTR_CMD_TYPE]);
726 dbgcmd->para_num = nla_get_u32(info->attrs[TEST_ATTR_PARA_NUM]);
727 esp_dbg(ESP_DBG_ERROR, "%s dbgcmdType %d paraNum %d\n", __func__, dbgcmd->cmd_type, dbgcmd->para_num);
728 for (i=0; i<dbgcmd->para_num; i++)
729 dbgcmd->para[i] = nla_get_u32(info->attrs[TEST_ATTR_PARA(i)]);
731 /*directly send reply_info to target, and waiting for report*/
732 REGISTER_REPLY(info);
734 sip_send_test_cmd(SIP, skb);
741 static int esp_test_sdio_wr(struct sk_buff *skb_2,
742 struct genl_info *info)
745 u32 func_no, addr, value;
750 func_no = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
751 addr = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
752 value = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
755 res = esp_common_writebyte_with_addr(SIP->epub, addr, (u8)value, ESP_SIF_SYNC);
757 memcpy(sdio_buff, (u8 *)&value, 4);
758 res = esp_common_write_with_addr(SIP->epub, addr, sdio_buff, 4, ESP_SIF_SYNC);
761 /*directly send reply_info to target, and waiting for report*/
762 REGISTER_REPLY(info);
764 esp_test_cmd_reply(info, TEST_CMD_SDIO_WR, "write ok!");
766 esp_test_cmd_reply(info, TEST_CMD_SDIO_WR, "write fail!");
773 static int esp_test_sdio_rd(struct sk_buff *skb_2,
774 struct genl_info *info)
777 u32 func_no, addr, value;
783 func_no = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
784 addr = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
787 memset(sdio_buff, 0, 4);
788 res = esp_common_readbyte_with_addr(SIP->epub, addr, &sdio_buff[0], ESP_SIF_SYNC);
790 res = esp_common_read_with_addr(SIP->epub, addr, sdio_buff, 4, ESP_SIF_SYNC);
792 memcpy((u8 *)&value, sdio_buff, 4);
794 /*directly send reply_info to target, and waiting for report*/
795 REGISTER_REPLY(info);
797 sprintf((char *)&value_str, "0x%x", value);
798 esp_test_cmd_reply(info, TEST_CMD_SDIO_RD, value_str);
800 esp_test_cmd_reply(info, TEST_CMD_SDIO_RD, "read fail!");
807 /* TEST_CMD netlink policy */
809 static struct nla_policy test_genl_policy[TEST_ATTR_MAX + 1] = {
810 [TEST_ATTR_CMD_NAME]= { .type = NLA_NUL_STRING, .len = GENL_NAMSIZ - 1 },
811 [TEST_ATTR_CMD_TYPE] = { .type = NLA_U32 },
812 [TEST_ATTR_PARA_NUM] = { .type = NLA_U32 },
813 [TEST_ATTR_PARA0] = { .type = NLA_U32 },
814 [TEST_ATTR_PARA1] = { .type = NLA_U32 },
815 [TEST_ATTR_PARA2] = { .type = NLA_U32 },
816 [TEST_ATTR_PARA3] = { .type = NLA_U32 },
817 [TEST_ATTR_PARA4] = { .type = NLA_U32 },
818 [TEST_ATTR_PARA5] = { .type = NLA_U32 },
819 [TEST_ATTR_PARA6] = { .type = NLA_U32 },
820 [TEST_ATTR_PARA7] = { .type = NLA_U32 },
821 [TEST_ATTR_STR] = { .type = NLA_NUL_STRING, .len = 256-1 },
824 /* Generic Netlink operations array */
825 static struct genl_ops esp_test_ops[] = {
827 .cmd = TEST_CMD_ECHO,
828 .policy = test_genl_policy,
829 .doit = esp_test_echo,
830 .flags = GENL_ADMIN_PERM,
834 .policy = test_genl_policy,
835 .doit = esp_test_ask,
836 .flags = GENL_ADMIN_PERM,
839 .cmd = TEST_CMD_SLEEP,
840 .policy = test_genl_policy,
841 .doit = esp_test_sleep,
842 .flags = GENL_ADMIN_PERM,
845 .cmd = TEST_CMD_WAKEUP,
846 .policy = test_genl_policy,
847 .doit = esp_test_wakeup,
848 .flags = GENL_ADMIN_PERM,
851 .cmd = TEST_CMD_LOOPBACK,
852 .policy = test_genl_policy,
853 .doit = esp_test_loopback,
854 .flags = GENL_ADMIN_PERM,
858 .policy = test_genl_policy,
860 .flags = GENL_ADMIN_PERM,
863 .cmd = TEST_CMD_DEBUG,
864 .policy = test_genl_policy,
865 .doit = esp_test_genl,
866 .flags = GENL_ADMIN_PERM,
869 .cmd = TEST_CMD_SDIO_WR,
870 .policy = test_genl_policy,
871 .doit = esp_test_sdio_wr,
872 .flags = GENL_ADMIN_PERM,
875 .cmd = TEST_CMD_SDIO_RD,
876 .policy = test_genl_policy,
877 .doit = esp_test_sdio_rd,
878 .flags = GENL_ADMIN_PERM,
882 .policy = test_genl_policy,
883 .doit = esp_test_ate,
884 .flags = GENL_ADMIN_PERM,
887 .cmd = TEST_CMD_SDIOTEST,
888 .policy = test_genl_policy,
889 .doit = esp_test_sdiotest,
890 .flags = GENL_ADMIN_PERM,
893 .cmd = TEST_CMD_SDIOSPEED,
894 .policy = test_genl_policy,
895 .doit = esp_test_sdiospeed,
896 .flags = GENL_ADMIN_PERM,
900 static int esp_test_netlink_notify(struct notifier_block *nb,
904 struct netlink_notify *notify = _notify;
906 if (state != NETLINK_URELEASE)
909 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
910 if (notify->portid == connected_nl) {
912 if (notify->pid == connected_nl) {
914 esp_dbg(ESP_DBG_ERROR, "esp_sdio: user released netlink"
922 static struct notifier_block test_netlink_notifier = {
923 .notifier_call = esp_test_netlink_notify,
926 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
928 * copy from net/netlink/genetlink.c(linux kernel 2.6.32)
930 * genl_register_family_with_ops - register a generic netlink family
931 * @family: generic netlink family
932 * @ops: operations to be registered
933 * @n_ops: number of elements to register
935 * Registers the specified family and operations from the specified table.
936 * Only one family may be registered with the same family name or identifier.
938 * The family id may equal GENL_ID_GENERATE causing an unique id to
939 * be automatically generated and assigned.
941 * Either a doit or dumpit callback must be specified for every registered
942 * operation or the function will fail. Only one operation structure per
943 * command identifier may be registered.
945 * See include/net/genetlink.h for more documenation on the operations
948 * This is equivalent to calling genl_register_family() followed by
949 * genl_register_ops() for every operation entry in the table taking
950 * care to unregister the family on error path.
952 * Return 0 on success or a negative error code.
954 int genl_register_family_with_ops(struct genl_family *family,
955 struct genl_ops *ops, size_t n_ops)
959 err = genl_register_family(family);
963 for (i = 0; i < n_ops; ++i, ++ops) {
964 err = genl_register_ops(family, ops);
970 genl_unregister_family(family);
975 int test_init_netlink(struct esp_sip *sip)
978 esp_dbg(ESP_DBG_ERROR, "esp_sdio: initializing netlink\n");
981 /* temp buffer for sdio test */
982 sdio_buff = kzalloc(8, GFP_KERNEL);
983 sdiotest_buf = kzalloc(16*1024, GFP_KERNEL);
985 rc = genl_register_family_with_ops(&test_genl_family,
986 esp_test_ops, ARRAY_SIZE(esp_test_ops));
990 rc = netlink_register_notifier(&test_netlink_notifier);
997 esp_dbg(ESP_DBG_ERROR, "esp_sdio: error occured in %s\n", __func__);
1003 kfree(sdiotest_buf);
1004 sdiotest_buf = NULL;
1009 void test_exit_netlink(void)
1013 if (sdio_buff == NULL)
1020 if (sdioTest.thread) {
1021 kthread_stop(sdioTest.thread);
1022 sdioTest.thread = NULL;
1025 kfree(sdiotest_buf);
1026 sdiotest_buf = NULL;
1028 esp_dbg(ESP_DBG_ERROR, "esp_sdio: closing netlink\n");
1029 /* unregister the notifier */
1030 netlink_unregister_notifier(&test_netlink_notifier);
1031 /* unregister the family */
1032 ret = genl_unregister_family(&test_genl_family);
1034 esp_dbg(ESP_DBG_ERROR, "esp_sdio: "
1035 "unregister family %i\n", ret);
1037 void esp_test_cmd_event(u32 cmd_type, char *reply_info)
1039 esp_test_cmd_reply(&info_copy, cmd_type, reply_info);
1042 void esp_stability_test(char *filename,struct esp_pub *epub)
1049 char test_res_str[560];
1050 char *tx_buf = kzalloc(512*32, GFP_KERNEL);
1051 char *rx_buf = kzalloc(512*32, GFP_KERNEL);
1053 struct esp_spi_ctrl *sctrl = NULL;
1054 struct spi_device *spi = NULL;
1059 sctrl = (struct esp_spi_ctrl *)epub->sif;
1084 for(i = 0;i<count;i++)
1091 spi_bus_lock(spi->master);
1092 sif_spi_write_bytes(spi, 0x8010, tx_buf, count, NOT_DUMMYMODE);
1093 spi_bus_unlock(spi->master);
1094 memset(rx_buf,0xff,count);
1096 spi_bus_lock(spi->master);
1097 sif_spi_read_bytes(spi, 0x8010, tx_buf, count, NOT_DUMMYMODE);
1098 spi_bus_unlock(spi->master);
1101 esp_common_write_with_addr((epub), 0x8010, tx_buf, count, ESP_SIF_SYNC);
1102 memset(rx_buf,0xff,count);
1103 esp_common_read_with_addr((epub), 0x8010, rx_buf, count, ESP_SIF_SYNC);
1105 for(i =0;i<count;i++)
1107 if(tx_buf[i] !=rx_buf[i])
1109 printk("-----------tx_buf--------------\n");
1110 show_buf(tx_buf,count);
1111 printk("-----------rx_buf-------------\n");
1112 show_buf(rx_buf,count);
1113 printk("--rx_buf != tx_buf----i= %d----\n",i);
1115 sprintf(test_res_str, "error, count = %d !!!\n", count);
1117 printk("%s\n", test_res_str);
1119 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1127 request_init_conf();
1129 if(sif_get_ate_config() == 0)
1132 sprintf(test_res_str, "ok, count = %d !!!\n", count);
1134 printk("%s\n", test_res_str);
1136 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1142 if(sif_get_ate_config() == 3)
1144 sprintf(test_res_str, "error, count = %d !!!\n", count);
1146 printk("%s\n", test_res_str);
1148 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1156 sprintf(test_res_str, "ok, count = %d !!!\n", count);
1157 printk("%s\n", test_res_str);
1159 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1166 void esp_rate_test(char *filename,struct esp_pub *epub)
1168 char *tx_buf = kzalloc(512*32, GFP_KERNEL);
1169 char *rx_buf = kzalloc(512*32, GFP_KERNEL);
1170 char test_res_str[560];
1171 unsigned long jiffies_start_rw;
1172 unsigned long jiffies_end_rw;
1173 unsigned long test_time_rw;
1174 unsigned long jiffies_start_read;
1175 unsigned long jiffies_end_read;
1176 unsigned long test_time_read;
1177 unsigned long jiffies_start_write;
1178 unsigned long jiffies_end_write;
1179 unsigned long test_time_write;
1182 memset(tx_buf,0x0,512*32);
1184 esp_common_write_with_addr((epub), 0x8010, tx_buf, 512*32, ESP_SIF_SYNC);
1185 jiffies_start_rw = jiffies;
1188 esp_common_write_with_addr((epub), 0x8010, tx_buf, 512*32, ESP_SIF_SYNC);
1189 esp_common_read_with_addr((epub), 0x8010, rx_buf, 512*32, ESP_SIF_SYNC);
1191 jiffies_end_rw = jiffies;
1192 test_time_rw = jiffies_to_msecs(jiffies_end_rw - jiffies_start_rw);
1195 jiffies_start_read = jiffies;
1197 esp_common_read_with_addr((epub), 0x8010, rx_buf, 512*32, ESP_SIF_SYNC);
1198 esp_common_read_with_addr((epub), 0x8010, rx_buf, 512*32, ESP_SIF_SYNC);
1200 jiffies_end_read = jiffies;
1201 test_time_read = jiffies_to_msecs(jiffies_end_read - jiffies_start_read);
1204 jiffies_start_write = jiffies;
1206 esp_common_write_with_addr((epub), 0x8010, tx_buf, 512*32, ESP_SIF_SYNC);
1207 esp_common_write_with_addr((epub), 0x8010, tx_buf, 512*32, ESP_SIF_SYNC);
1209 jiffies_end_write = jiffies;
1210 test_time_write = jiffies_to_msecs(jiffies_end_write - jiffies_start_write);
1212 sprintf(test_res_str, "ok,rw_time=%lu,read_time=%lu,write_time=%lu !!!\n",test_time_rw,test_time_read,test_time_write);
1214 printk("%s\n", test_res_str);
1216 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1223 void esp_resp_test(char *filename,struct esp_pub *epub)
1230 char *test_res_str = kzalloc(1024,GFP_KERNEL);
1231 char *tx_buf = kzalloc(512*32, GFP_KERNEL);
1232 char *rx_buf = kzalloc(512*32, GFP_KERNEL);
1233 struct esp_spi_ctrl *sctrl = NULL;
1234 struct spi_device *spi = NULL;
1235 struct esp_spi_resp *spi_resp;
1240 sctrl = (struct esp_spi_ctrl *)epub->sif;
1264 for(i = 0;i<count;i++)
1270 spi_bus_lock(spi->master);
1271 sif_spi_write_bytes(spi, 0x8010, tx_buf, count, NOT_DUMMYMODE);
1272 spi_bus_unlock(spi->master);
1273 memset(rx_buf,0xff,count);
1275 spi_bus_lock(spi->master);
1276 sif_spi_read_bytes(spi, 0x8010, rx_buf, count, NOT_DUMMYMODE);
1277 spi_bus_unlock(spi->master);
1278 for(i =0;i<count;i++)
1280 if(tx_buf[i] !=rx_buf[i])
1282 printk("-----------tx_buf------\n");
1283 show_buf(tx_buf,count);
1284 printk("-----------rx_buf------\n");
1285 show_buf(rx_buf,count);
1286 printk("------rx_buf != tx_buf--i = %d----\n",i);
1288 sprintf(test_res_str, "error, count = %d !!!\n", count);
1290 printk("%s\n", test_res_str);
1292 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1300 esp_common_write_with_addr((epub), 0x8010, tx_buf, count, ESP_SIF_SYNC);
1301 memset(rx_buf,0xff,count);
1302 esp_common_read_with_addr((epub), 0x8010, rx_buf, count, ESP_SIF_SYNC);
1304 for(i =0;i<count;i++)
1306 if(tx_buf[i] !=rx_buf[i])
1308 printk("-----------tx_buf--------------\n");
1309 show_buf(tx_buf,count);
1310 printk("-----------rx_buf-------------\n");
1311 show_buf(rx_buf,count);
1312 printk("------------------rx_buf != tx_buf------i = %d-------------\n",i);
1314 sprintf(test_res_str, "error, count = %d !!!\n", count);
1316 printk("%s\n", test_res_str);
1318 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1328 spi_resp = sif_get_spi_resp();
1330 sprintf(test_res_str, "ok, max_dataW_resp_size=%d--max_dataR_resp_size=%d--max_block_dataW_resp_size=%d--max_block_dataR_resp_size=%d--max_cmd_resp_size=%d-- !!!\n",
1331 spi_resp->max_dataW_resp_size,spi_resp->max_dataR_resp_size,spi_resp->max_block_dataW_resp_size,spi_resp->max_block_dataR_resp_size,spi_resp->max_cmd_resp_size);
1333 printk("%s\n", test_res_str);
1335 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1340 kfree(test_res_str);
1344 void esp_noisefloor_test(char *filename,struct esp_pub *epub)
1346 char *tx_buf = kzalloc(512*32, GFP_KERNEL);
1347 char *rx_buf = kzalloc(512*32, GFP_KERNEL);
1348 char *res_buf = kzalloc(128, GFP_KERNEL);
1349 char test_res_str[560];
1350 unsigned long jiffies_start;
1353 for(i = 0;i<512*32;i++)
1355 tx_buf[i]=(i*11)^0X5A;
1358 jiffies_start = jiffies;
1360 while(jiffies_to_msecs(jiffies - jiffies_start) < 6000){
1361 esp_common_write_with_addr((epub), 0x9010, tx_buf, 512*32, ESP_SIF_SYNC);
1362 memset(rx_buf,0xff,512*32);
1363 esp_common_read_with_addr((epub), 0x9010, rx_buf, 512*32, ESP_SIF_SYNC);
1367 esp_common_read_with_addr((epub), 0x14, res_buf,128 , ESP_SIF_SYNC);
1369 if ( (res_buf[38] && 0xf) == (0xa && 0xf) )
1371 sprintf(test_res_str, "ok, APST RN:%d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; %d,%d; APED\n",
1372 res_buf[40]-400,res_buf[0]-400, //chanell 1
1373 res_buf[41]-400,res_buf[1]-400,
1374 res_buf[42]-400,res_buf[2]-400,
1375 res_buf[43]-400,res_buf[3]-400,
1376 res_buf[100]-400,res_buf[4]-400,
1377 res_buf[101]-400,res_buf[5]-400,
1378 res_buf[102]-400,res_buf[6]-400,
1379 res_buf[103]-400,res_buf[7]-400,
1380 res_buf[104]-400,res_buf[16]-400,
1381 res_buf[105]-400,res_buf[17]-400,
1382 res_buf[106]-400,res_buf[18]-400,
1383 res_buf[107]-400,res_buf[19]-400,
1384 res_buf[36]-400,res_buf[20]-400,
1385 res_buf[37]-400,res_buf[21]-400);
1389 sprintf(test_res_str, "error !!!\n");
1392 printk("%s\n", test_res_str);
1394 esp_readwrite_file(filename, NULL, test_res_str, strlen(test_res_str));
1401 void esp_test_init(struct esp_pub *epub)
1405 if (mod_eagle_path_get() == NULL)
1406 sprintf(filename, "%s/%s", FWPATH, "test_results");
1408 sprintf(filename, "%s/%s", mod_eagle_path_get(), "test_results");
1411 sif_had_io_enable(epub);
1412 sif_unlock_bus(epub);
1414 if(sif_get_ate_config() == 2){
1415 esp_stability_test(filename,epub);
1417 } else if(sif_get_ate_config() == 4){
1418 esp_rate_test(filename,epub);
1421 else if(sif_get_ate_config() == 5){
1422 esp_resp_test(filename,epub);
1425 else if(sif_get_ate_config() == 6){
1426 esp_noisefloor_test(filename,epub);
1430 #endif //ifdef TEST_MODE