net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / usb / debug.c
1 #include <linux/timer.h>
2 #include "ecrnx_utils.h"
3 #include "ecrnx_defs.h"
4 #include "ecrnx_msg_rx.h"
5 #include "ecrnx_usb.h"
6 #include "core.h"
7 #include "debug.h"
8 #include "usb.h"
9 #include "ecrnx_rx.h"
10
11
12 //kernal timer param
13 static struct timer_list tm;
14 static int counter = 0;
15
16 //rx param
17 struct sk_buff *skb = NULL;
18 struct ecrnx_hw *g_ecrnx_hw = NULL;
19
20 //tx param
21 struct ecrnx_vif vif;
22 struct ecrnx_sta sta;
23 struct cfg80211_mgmt_tx_params params;
24
25 static void test_timer_handler(struct timer_list * lt);
26
27 void ecrnx_hw_set(void* init_ecrnx_hw)
28 {
29     g_ecrnx_hw = (struct ecrnx_hw *)init_ecrnx_hw;
30 }
31
32 static int sdio_rx_param_init(void)
33 {
34     struct rxu_stat_mm rxu_state;
35     struct rx_hd  rx_head;
36     struct ethhdr eth_hd;
37     int res, index = 0;
38     uint8_t *ptr = NULL;
39     uint16_t head_len = sizeof(struct ethhdr);
40     ECRNX_DBG("%s entry!!", __func__);
41     memset(&rxu_state, 0, sizeof(struct rxu_stat_mm));
42     memset(&rx_head, 0, sizeof(struct rx_hd));
43     memset(&eth_hd, 0, sizeof(struct ethhdr));
44
45     rxu_state.comm_hd.frm_type = USB_FRM_TYPE_RXDESC;
46     //rxu_state.comm_hd.frm_type = USB_FRM_TYPE_MSG;
47     if(rxu_state.comm_hd.frm_type == USB_FRM_TYPE_RXDESC)
48     {
49         head_len += sizeof(struct rxu_stat_mm) + sizeof(struct rx_hd);
50     }
51     else
52     {
53         head_len += sizeof(dispatch_hdr_t);
54     }
55
56     skb = dev_alloc_skb(FRAME_SIZE + head_len);
57     skb_reserve(skb, head_len);
58     ptr = skb_put(skb, FRAME_SIZE); //ptr is skb tail
59     memset(skb->data, 0x0f, FRAME_SIZE); //payload
60     skb_push(skb, sizeof(struct ethhdr));
61
62     for( index = 0; index < ETH_ALEN; index++)
63     {
64         eth_hd.h_dest[index] = index;
65         eth_hd.h_source[index] = index;
66     }
67
68     eth_hd.h_proto = ETH_P_80221; //ETHERTYPE_IP;
69     memcpy(skb->data, &eth_hd, sizeof(struct ethhdr));
70
71     if(rxu_state.comm_hd.frm_type == USB_FRM_TYPE_RXDESC)
72     {
73         //data frame, need header, rxu state
74         //rx head
75         skb_push(skb, sizeof(struct rx_hd));
76         rx_head.frmlen = FRAME_SIZE + head_len;
77         rx_head.ampdu_stat_info = 0; 
78         //...
79         memcpy(skb->data , &rx_head, sizeof(struct rx_hd));
80
81         //rxu state
82         skb_push(skb, sizeof(struct rxu_stat_mm));
83         rxu_state.msdu_mode = 0x01;
84         rxu_state.host_id = 0x0001;
85         rxu_state.frame_len  = rx_head.frmlen;
86         rxu_state.status = RX_STAT_MONITOR;
87         //rxu_state.phy_info.info1 = 1 | (1 << 8) | (2450 << 16);
88         //rxu_state.phy_info.info2 = 2450 | (2450 << 16);
89 #ifdef CONFIG_ECRNX_FULLMAC
90         //rxu_state.flags = 0;
91 #endif
92         //rxu_state.pattern = ecrnx_rxbuff_pattern;
93         memcpy(skb->data, &rxu_state, sizeof(struct rxu_stat_mm));
94     }
95     else
96     {
97         //message frame, don't need header
98         skb_push(skb, sizeof(dispatch_hdr_t)); //rxu state
99         memcpy(skb->data, &rxu_state.comm_hd, sizeof(dispatch_hdr_t));
100     }
101
102     for(index = 0; index < head_len; index++)
103     {
104         ECRNX_DBG("0x%x ", skb->data[index]);
105     }
106
107     ECRNX_DBG("%s exit, skb_len:%d, type: %d!!", __func__, skb->len, (skb->data[1] << 8) | skb->data[0]);
108
109     return res;
110 }
111
112 extern int ecrnx_start_mgmt_xmit(struct ecrnx_vif *vif, \
113                         struct ecrnx_sta *sta, \
114                         struct cfg80211_mgmt_tx_params *params, \
115                         bool offchan, \
116                         u64 *cookie);
117
118 /*
119 struct cfg80211_mgmt_tx_params {
120         struct ieee80211_channel *chan;
121         bool offchan;
122         unsigned int wait;
123         const u8 *buf;
124         size_t len;
125         bool no_cck;
126         bool dont_wait_for_ack;
127         int n_csa_offsets;
128         const u16 *csa_offsets;
129 };
130 */
131 static void sdio_tx_param_init(void)
132 {
133     u8 send_buf[FRAME_SIZE] = {0x00, 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
134
135     params.len = FRAME_SIZE;
136     params.buf = (const u8 *)send_buf;
137     params.n_csa_offsets = 10;
138     params.csa_offsets = (const u16 *)send_buf;
139     params.no_cck = 0;
140
141     vif.ecrnx_hw = g_ecrnx_hw;
142 }
143
144 void sdio_rx_tx_test_schedule(void)
145 {
146     ECRNX_DBG("%s entry!!", __func__);
147     tm.function = test_timer_handler;
148     tm.expires = jiffies + HZ * 10;
149     add_timer(&tm);
150     
151     sdio_rx_param_init();
152     sdio_tx_param_init();
153     ECRNX_DBG("%s exit!!", __func__);
154 }
155
156 static void test_timer_handler(struct timer_list * lt)
157 {
158     ECRNX_DBG("%s, counter:%d\n", __FUNCTION__, counter);
159
160     if(counter%2)
161     {
162         u64 cookie;
163         //ecrnx_start_mgmt_xmit(&vif, NULL, &params, false, &cookie);
164     }
165     else
166     {
167         ecrnx_rx_callback(g_ecrnx_hw, skb, 1);
168     }
169
170     if(lt)
171     {
172         counter++;
173     }
174
175     if(counter < 5)
176     {
177         //tm.expires = jiffies +1 * HZ / 1000/10;  //100us
178         tm.expires = jiffies +1 * HZ;
179         add_timer(&tm);
180     }
181     else
182     {
183         counter = 0;
184         del_timer(&tm);
185     }
186 }
187