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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
/**
******************************************************************************
*
* @file ecrnx_usb.c
*
* @brief ECRNX usb init and management function
*
* Copyright (C) ESWIN 2015-2020
*
******************************************************************************
*/
#include <linux/module.h>
#include <linux/kthread.h>
#include "core.h"
//#include "debug.h"
#include "ecrnx_utils.h"
#include "ecrnx_cmds.h"
#include "ecrnx_defs.h"
#include "ecrnx_msg_rx.h"
#include "ipc_host.h"
#include "ipc_shared.h"
#include "ecrnx_events.h"
#include "ecrnx_usb.h"
#ifdef CONFIG_TEST_ESWIN_USB
#include "debug.h"
#endif
#ifdef CONFIG_ECRNX_WIFO_CAIL
#include "ecrnx_amt.h"
#endif
#define USB_ADDR_DATA (unsigned int)(0x200)
#ifdef CONFIG_ECRNX_SOFTMAC
#define FW_STR "lmac"
#elif defined CONFIG_ECRNX_FULLMAC
#define FW_STR "fmac"
#endif
#if defined(CONFIG_ECRNX_DEBUGFS_CUSTOM)
#include "ecrnx_debugfs_func.h"
#endif
extern const int nx_txdesc_cnt_msk[];
struct vendor_radiotap_hdr {
u8 oui[3];
u8 subns;
u16 len;
u8 data[];
};
#ifdef CONFIG_WEXT_PRIV
extern void priv_copy_data_wakeup(struct ecrnx_hw *ecrnx_hw, struct sk_buff *skb);
#endif
/**
* @brief: ipc_host_rxdesc_handler: Handle the reception of a Rx Descriptor
* Called from general IRQ handler when status %IPC_IRQ_E2A_RXDESC is set
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_rxdesc_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
u8 ret = 0;
// LMAC has triggered an IT saying that a reception has occurred.
// Then we first need to check the validity of the current hostbuf, and the validity
// of the next hostbufs too, because it is likely that several hostbufs have been
// filled within the time needed for this irq handling
#ifdef CONFIG_ECRNX_FULLMAC
// call the external function to indicate that a RX descriptor is received
ret = env->cb.recv_data_ind(env->pthis, skb);
#else
// call the external function to indicate that a RX packet is received
ret = env->cb.recv_data_ind(env->pthis, skb);
#endif //(CONFIG_ECRNX_FULLMAC)
//ECRNX_DBG("%s exit!!", __func__);
return ret;
}
/**
* @brief: usb_host_radar_handler Handle the reception of radar events
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_radar_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
int ret = 0;
#ifdef CONFIG_ECRNX_RADAR
// LMAC has triggered an IT saying that a radar event has been sent to upper layer.
// Then we first need to check the validity of the current msg buf, and the validity
// of the next buffers too, because it is likely that several buffers have been
// filled within the time needed for this irq handling
// call the external function to indicate that a RX packet is received
spin_lock(&((struct ecrnx_hw *)env->pthis)->radar.lock);
ret = env->cb.recv_radar_ind(env->pthis, skb);
spin_unlock(&((struct ecrnx_hw *)env->pthis)->radar.lock);
#endif /* CONFIG_ECRNX_RADAR */
return ret;
}
/**
* @brief: usb_host_unsup_rx_vec_handler Handle the reception of unsupported rx vector
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_unsup_rx_vec_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
return env->cb.recv_unsup_rx_vec_ind(env->pthis, skb);
}
/**
* @brief: usb_host_msg_handler Handler for firmware message
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_msg_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
// LMAC has triggered an IT saying that a message has been sent to upper layer.
// Then we first need to check the validity of the current msg buf, and the validity
// of the next buffers too, because it is likely that several buffers have been
// filled within the time needed for this irq handling
// call the external function to indicate that a RX packet is received
return env->cb.recv_msg_ind(env->pthis, skb->data);
}
/**
* @brief: usb_host_msgack_handler Handle the reception of message acknowledgement
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_msgack_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
ptr_addr hostid = *(ptr_addr *)skb->data;
ASSERT_ERR(hostid);
env->msga2e_hostid = NULL;
env->cb.recv_msgack_ind(env->pthis, (void*)hostid);
return 0;
}
/**
* @brief: usb_host_dbg_handler Handle the reception of Debug event
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
static int usb_host_dbg_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
// LMAC has triggered an IT saying that a DBG message has been sent to upper layer.
// Then we first need to check the validity of the current buffer, and the validity
// of the next buffers too, because it is likely that several buffers have been
// filled within the time needed for this irq handling
// call the external function to indicate that a RX packet is received
return env->cb.recv_dbg_ind(env->pthis, skb);
}
/**
* @brief: usb_host_tx_cfm_handler Handle the reception of TX confirmation
* @param {env} pointer to the usb Host environment
* @param {queue_idx} index of the hardware on which the confirmation has been received
* @param {user_pos} index of the user position
* @return: none
*/
static int usb_host_tx_cfm_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
ptr_addr host_id;
struct sk_buff *skb_cfm;
struct ecrnx_txhdr *txhdr;
#ifdef CONFIG_ECRNX_FULLMAC
struct tx_cfm_tag *cfm;
cfm = (struct tx_cfm_tag *)skb->data;
//host_id = cfm->hostid;
memcpy((uint8_t *)&host_id, (uint8_t *)cfm->hostid, sizeof(ptr_addr));
if (host_id == 0) {
return 0;
}
ECRNX_DBG("%s:hostid(tx_skb):0x%08x, rx_skb: 0x%x \n", __func__, host_id, skb);
skb_cfm = (struct sk_buff *)host_id;
txhdr = (struct ecrnx_txhdr *)(*((ptr_addr*)skb_cfm->data - 1));
memcpy(&txhdr->hw_hdr.cfm, cfm, sizeof(*cfm));
#elif defined CONFIG_ECRNX_SOFTMAC
//TODO:
#endif
return env->cb.send_data_cfm(env->pthis, (void*)txhdr);
}
#ifdef CONFIG_ECRNX_WIFO_CAIL
/**
* @brief: usb_host_amt_rx_handler Handle the reception of rx frame
* @param {frm_type} received frame type
* @param {skb} received skb data
* @return: none
*/
void usb_host_amt_rx_handler(uint32_t frm_type, struct sk_buff *skb)
{
int need_free = 0;
ECRNX_DBG("%s enter, frame type: %d!!", __func__, frm_type);
if(!skb)
{
ECRNX_ERR("usb_host_amt_rx_handler input param error!! \n!");
return;
}
if (frm_type != USB_FRM_TYPE_RXDESC)
{
skb_pull(skb, SKB_DATA_COM_HD_OFFSET); //delete the frame common header
}
ECRNX_DBG("skb:0x%08x, skb_len:%d, frame type: %d!!", skb->data,skb->len, frm_type);
switch (frm_type)
{
case USB_FRM_TYPE_IWPRIV:
{
/*printk("vif_start:%d, vif_monitor:%d \n", ecrnx_hw->vif_started, ecrnx_hw->monitor_vif);
print_hex_dump(KERN_INFO, "iwpriv-cfm:", DUMP_PREFIX_ADDRESS, 32, 1,
skb->data, skb->len, false);*/
amt_vif.rxlen = skb->len;
memset(amt_vif.rxdata, 0, ECRNX_RXSIZE);
memcpy(amt_vif.rxdata, skb->data, skb->len);
amt_vif.rxdatas = 1;
wake_up(&amt_vif.rxdataq);
need_free = 1;
break;
}
default:
need_free = 1;
break;
}
if (need_free && skb) { // free the skb
ECRNX_DBG("skb free: 0x%x !! \n", skb);
dev_kfree_skb(skb);
}
ECRNX_DBG("%s exit!!", __func__);
return;
}
#endif
/**
* @brief: usb_host_rx_handler Handle the reception of rx frame
* @param {frm_type} received frame type
* @param {env} pointer to the usb Host environment
* @param {skb} received skb data
* @return: none
*/
void usb_host_rx_handler(uint32_t frm_type, struct ipc_host_env_tag *env, struct sk_buff *skb)
{
int ret = 1;
//ECRNX_DBG("%s enter, frame type: %d!!", __func__, frm_type);
if(!env || !skb)
{
ECRNX_ERR("usb_host_rx_handler input param error!! \n!");
return;
}
((struct ecrnx_hw *)env->pthis)->usb_rx++;
if (frm_type != USB_FRM_TYPE_RXDESC)
{
skb_pull(skb, SKB_DATA_COM_HD_OFFSET); //delete the frame common header
}
//ECRNX_DBG("skb:0x%08x, skb_len:%d, frame type: %d!!", skb->data,skb->len, frm_type);
switch (frm_type)
{
case USB_FRM_TYPE_RXDESC:
{
// handle the RX descriptor reception
usb_host_rxdesc_handler(env, skb); //just for current only one endpoint test
break;
}
case USB_FRM_TYPE_MSG_ACK:
{
if(1 == skb->len)
{
ECRNX_PRINT("MSG_ACK len: 1");
break;
}
ret = usb_host_msgack_handler(env, skb);
break;
}
case USB_FRM_TYPE_MSG:
{
ret = usb_host_msg_handler(env, skb);
break;
}
case USB_FRM_TYPE_TXCFM:
{
if(!env->pthis)
{
ECRNX_ERR("env->pthis ptr error!! \n!");
break;
}
/* add the spinlock which was missed during porting.
when skb->len more than 24 and skb contans more than one data cfm.
data cfm structure length is 24 byte.
*/
spin_lock_bh(&((struct ecrnx_hw *)env->pthis)->tx_lock);
while(skb->len > sizeof(struct tx_cfm_tag))
{
ret = usb_host_tx_cfm_handler(env, skb);
skb_pull(skb, sizeof(struct tx_cfm_tag));
}
ret = usb_host_tx_cfm_handler(env, skb);
spin_unlock_bh(&((struct ecrnx_hw *)env->pthis)->tx_lock);
break;
}
case USB_FRM_TYPE_UNSUP_RX_VEC:
{
// handle the unsupported rx vector reception
ret = usb_host_unsup_rx_vec_handler(env, skb);
break;
}
case USB_FRM_TYPE_RADAR:
{
// handle the radar event reception
ret = usb_host_radar_handler(env, skb);
break;
}
case USB_FRM_TYPE_TBTT_SEC:
{
env->cb.sec_tbtt_ind(env->pthis);
break;
}
case USB_FRM_TYPE_TBTT_PRIM:
{
env->cb.prim_tbtt_ind(env->pthis);
break;
}
case USB_FRM_TYPE_DBG:
{
ECRNX_DBG("--%s:USB_FRM_TYPE_DBG, len:%d, slave:%s \n", __func__, skb->len, skb->data);
ret = usb_host_dbg_handler(env, skb);
break;
}
case USB_FRM_TYPE_IWPRIV:
{
#ifdef CONFIG_WEXT_PRIV
#if 0
struct ecrnx_hw *ecrnx_hw = (struct ecrnx_hw *)env->pthis;
struct ecrnx_vif* ecrnx_vif = ecrnx_hw->vif_table[0];
printk("vif_start:%d, vif_monitor:%d \n", ecrnx_hw->vif_started, ecrnx_hw->monitor_vif);
print_hex_dump(KERN_INFO, "iwpriv-cfm:", DUMP_PREFIX_ADDRESS, 32, 1,
skb->data, skb->len, false);
ecrnx_vif->rxlen = skb->len;
memcpy(ecrnx_vif->rxdata, skb->data, skb->len);
ecrnx_vif->rxdatas = 1;
wake_up(&ecrnx_vif->rxdataq);
#else
priv_copy_data_wakeup((struct ecrnx_hw *)env->pthis, skb);
#endif
#endif
ret = 0;
break;
}
#if defined(CONFIG_ECRNX_DEBUGFS_CUSTOM)
case USB_FRM_DEBUG_FS:
{
uint32_t debugfs_type = ((uint32_t*)skb->data)[0];
debugfs_resp.debugfs_type = debugfs_type;
if((debugfs_type != SLAVE_LOG_LEVEL) && \
(debugfs_type < SLAVE_DEBUGFS_MAX)){
debugfs_resp.rxlen = skb->len-4;
memcpy(debugfs_resp.rxdata, skb->data+4, debugfs_resp.rxlen);
ECRNX_DBG("%s - wake_up()\n", __func__);
debugfs_resp.rxdatas = 1;
wake_up(&debugfs_resp.rxdataq);
}
break;
}
#endif
default:
ret = 0;
break;
}
if (!ret && skb) { // free the skb
ECRNX_DBG("skb free: 0x%x, ret: %d!! \n", skb, ret);
dev_kfree_skb(skb);
}
//ECRNX_DBG("%s exit!!", __func__);
return;
}
/**
* @brief: ecrnx_usb_init Initialize usb interface.
* @param {ecrnx_hw} Main driver data
* @return: u8
*/
u8 ecrnx_usb_init(struct ecrnx_hw *ecrnx_hw)
{
ECRNX_DBG("%s entry!!", __func__);
// Save the pointer to the register base
ecrnx_hw->ipc_env->pthis = (void*)ecrnx_hw;
ECRNX_DBG("%s exit!!", __func__);
return 0;
}
/**
* @brief: ecrnx_usb_deinit DeInitialize usb interface.
* @param {ecrnx_hw} Main driver data
* @return: none
*/
void ecrnx_usb_deinit(struct ecrnx_hw *ecrnx_hw)
{
ECRNX_DBG(ECRNX_FN_ENTRY_STR);
memset(ecrnx_hw, 0, sizeof(struct ecrnx_hw));
}
|