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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
/**
******************************************************************************
*
* @file ecrnx_sdio.c
*
* @brief ECRNX sdio init and management function
*
* Copyright (C) ESWIN 2015-2020
*
******************************************************************************
*/
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.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_sdio.h"
#ifdef CONFIG_TEST_ESWIN_SDIO
#include "debug.h"
#endif
#ifdef CONFIG_ECRNX_WIFO_CAIL
#include "ecrnx_amt.h"
#endif
#define SDIO_ADDR_DATA (unsigned int)(0x200)
#ifdef CONFIG_ECRNX_SOFTMAC
#define FW_STR "lmac"
#elif defined CONFIG_ECRNX_FULLMAC
#define FW_STR "fmac"
#endif
sdio_rx_buf_t sdio_rx_buff;
extern const int nx_txdesc_cnt_msk[];
struct vendor_radiotap_hdr {
u8 oui[3];
u8 subns;
u16 len;
u8 data[];
};
/**
* @brief: sdio_rx_buf_init: Initialization the sdio rx buffer
* @param {void} void
* @return: none
*/
static void sdio_rx_buf_init(void)
{
uint8_t i = 0;
ECRNX_DBG("%s entry!!", __func__);
memset(&sdio_rx_buff, 0, sizeof(sdio_rx_buf_t));
for(i = 0; i < SDIO_RXBUF_CNT; i++)
{
sdio_rx_buff.ecrnx_sdio_rx_skb[i].skb = dev_alloc_skb(SDIO_RXBUF_SIZE);
skb_put(sdio_rx_buff.ecrnx_sdio_rx_skb[i].skb, SDIO_RXBUF_SIZE);
}
#ifdef CONFIG_TEST_ESWIN_SDIO
sdio_rx_tx_test_schedule();
#endif
ECRNX_DBG("%s exit!!", __func__);
}
/**
* @brief: sdio_rx_buf_deinit: Deinitialization the sdio rx buffer
* @param {void} void
* @return: none
*/
static void sdio_rx_buf_deinit(void)
{
uint8_t i = 0;
memset(&sdio_rx_buff, 0, sizeof(sdio_rx_buf_t));
for(i = 0; i < SDIO_RXBUF_CNT; i++)
{
if(sdio_rx_buff.ecrnx_sdio_rx_skb[i].skb)
{
dev_kfree_skb(sdio_rx_buff.ecrnx_sdio_rx_skb[i].skb);
}
}
}
/**
* @brief: sdio_rx_buf_push: push a skb element to sdio rx buffer
* @param {skb} skb data need to push
* @param {recv_len} skb data length
* @return: sk_buff
*/
struct sk_buff * sdio_rx_buf_push(struct sk_buff *skb, uint16_t recv_len)
{
uint8_t index = 0;
ECRNX_DBG("%s enter, skb: %d, skb_data:%d, skb_len:%d", __func__, skb, skb->data, recv_len);
if(atomic_read(&sdio_rx_buff.suspend))
{
return NULL;
}
if(sdio_rx_buff.sdio_host_rx_buff_used >= SDIO_RXBUF_CNT)
{
ECRNX_PRINT("no enough space \n");
return NULL;
}
if((!skb) || (!recv_len) || (recv_len > SDIO_RXBUF_SIZE))
{
ECRNX_PRINT("rx data is error \n");
return NULL;
}
atomic_set(&sdio_rx_buff.suspend, 1);
do
{
if(!sdio_rx_buff.ecrnx_sdio_rx_skb[index].flag) //find a index to store the data
{
break;
}
index++;
}while(index < SDIO_RXBUF_CNT);
sdio_rx_buff.sdio_host_rx_buff_used++;
sdio_rx_buff.ecrnx_sdio_rx_skb[index].flag = true;
sdio_rx_buff.ecrnx_sdio_rx_skb[index].data_len = recv_len;
memcpy(sdio_rx_buff.ecrnx_sdio_rx_skb[index].skb->data, skb->data, recv_len);
atomic_set(&sdio_rx_buff.suspend, 0);
return sdio_rx_buff.ecrnx_sdio_rx_skb[index].skb;
}
/**
* @brief: sdio_rx_buf_pop: pop a skb element from sdio rx buffer
* @param {void}
* @return: sk_buff
*/
struct sk_buff* sdio_rx_buf_pop(void)
{
uint8_t index = 0;
struct sk_buff *skb= NULL;
if(atomic_read(&sdio_rx_buff.suspend))
{
ECRNX_PRINT("sdio suspend! \n");
return NULL;
}
if(sdio_rx_buff.sdio_host_rx_buff_used <= 0)
{
ECRNX_PRINT("no data in memory \n");
return NULL;
}
atomic_set(&sdio_rx_buff.suspend, 1);
do
{
if(sdio_rx_buff.ecrnx_sdio_rx_skb[index].flag) //find a index to pop the data
{
break;
}
index++;
}while(index < SDIO_RXBUF_CNT);
if(index != SDIO_RXBUF_CNT)
{
skb = sdio_rx_buff.ecrnx_sdio_rx_skb[index].skb;
sdio_rx_buff.ecrnx_sdio_rx_skb[index].flag = false;
sdio_rx_buff.sdio_host_rx_buff_used = (sdio_rx_buff.sdio_host_rx_buff_used > 0)? sdio_rx_buff.sdio_host_rx_buff_used-1: 0;
}
atomic_set(&sdio_rx_buff.suspend, 0);
return skb;
}
/**
* @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 sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_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: sdio_host_radar_handler Handle the reception of radar events
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_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: sdio_host_unsup_rx_vec_handler Handle the reception of unsupported rx vector
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_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: sdio_host_msg_handler Handler for firmware message
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_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: sdio_host_msgack_handler Handle the reception of message acknowledgement
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_host_msgack_handler(struct ipc_host_env_tag *env, struct sk_buff *skb)
{
uint64_t hostid = *(uint64_t *)skb->data;
ASSERT_ERR(hostid);
env->msga2e_hostid = NULL;
env->cb.recv_msgack_ind(env->pthis, hostid);
return 0;
}
/**
* @brief: sdio_host_dbg_handler Handle the reception of Debug event
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
static int sdio_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: sdio_host_tx_cfm_handler Handle the reception of TX confirmation
* @param {env} pointer to the sdio 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 sdio_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;
ECRNX_DBG("%s, skb: 0x%08x \n", __func__, skb);
#ifdef CONFIG_ECRNX_FULLMAC
struct tx_cfm_tag *cfm;
cfm = (struct tx_cfm_tag *)skb->data;
memcpy((uint8_t *)&host_id, (uint8_t *)cfm->hostid, sizeof(ptr_addr));
ECRNX_DBG("--%s--hostid 0x%08x, skb: 0x%x \n", __func__, host_id, skb);
if (host_id == 0) {
return 0;
}
skb_cfm = (struct sk_buff *)host_id;
txhdr = (struct ecrnx_txhdr *)skb_cfm->data;
memcpy(&txhdr->hw_hdr.cfm, cfm, sizeof(*cfm));
#elif defined CONFIG_ECRNX_SOFTMAC
//TODO:
#endif
return env->cb.send_data_cfm(env->pthis, host_id);
//return 0;
}
#ifdef CONFIG_ECRNX_WIFO_CAIL
/**
* @brief: sdio_host_rx_handler Handle the reception of rx frame
* @param {frm_type} received frame type
* @param {skb} received skb data
* @return: none
**/
void sdio_host_amt_rx_handler(uint32_t frm_type, struct sk_buff *skb)
{
int need_free = 0;
ECRNX_PRINT("%s enter, frame type: %d, len %d.!!", __func__, frm_type, skb->len);
if (frm_type != SDIO_FRM_TYPE_RXDESC)
{
skb_pull(skb, SKB_DATA_COM_HD_OFFSET); //delete the frame common header
}
switch (frm_type)
{
case SDIO_FRM_TYPE_IWPRIV:
{
/*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 > ECRNX_RXSIZE ? ECRNX_RXSIZE : 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: sdio_host_rx_handler Handle the reception of rx frame
* @param {frm_type} received frame type
* @param {env} pointer to the sdio Host environment
* @param {skb} received skb data
* @return: none
*/
void sdio_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 (frm_type != SDIO_FRM_TYPE_RXDESC)
{
skb_pull(skb, SKB_DATA_COM_HD_OFFSET); //delete the frame common header
}
switch (frm_type)
{
case SDIO_FRM_TYPE_RXDESC:
{
sdio_host_rxdesc_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_MSG_ACK:
{
ret = sdio_host_msgack_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_MSG:
{
ret = sdio_host_msg_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_TXCFM:
{
/* add the spinlock which was missed during porting. */
spin_lock_bh(&((struct ecrnx_hw *)env->pthis)->tx_lock);
while(skb->len > sizeof(struct tx_cfm_tag))
{
ret = sdio_host_tx_cfm_handler(env, skb);
skb_pull(skb, sizeof(struct tx_cfm_tag));
}
ret = sdio_host_tx_cfm_handler(env, skb);
spin_unlock_bh(&((struct ecrnx_hw *)env->pthis)->tx_lock);
break;
}
case SDIO_FRM_TYPE_UNSUP_RX_VEC:
{
// handle the unsupported rx vector reception
ret = sdio_host_unsup_rx_vec_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_RADAR:
{
// handle the radar event reception
ret = sdio_host_radar_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_TBTT_SEC:
{
env->cb.sec_tbtt_ind(env->pthis);
break;
}
case SDIO_FRM_TYPE_TBTT_PRIM:
{
env->cb.prim_tbtt_ind(env->pthis);
break;
}
case SDIO_FRM_TYPE_DBG:
{
ret = sdio_host_dbg_handler(env, skb);
break;
}
case SDIO_FRM_TYPE_UPDATE:
{
ret = 0;
break;
}
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: rcv_skb_convert convert the sdio received skb to the ecrnx handled skb.
* @param {src_rxu_state} received rxu state in skb
* @param {src_rxu_state} received rx header in skb
* @param {src_rxu_state} handled hw rxhdr in skb
* @param {src_rxu_state} handled rx desc tag in skb
* @return: u8
*/
u8 rcv_skb_convert(struct rxu_stat_mm* src_rxu_state, \
struct rx_hd* src_rx_hd, \
struct sk_buff *skb, \
struct hw_rxhdr* dst_hw_rxhdr,\
struct rxdesc_tag* dst_rxdesc_tag)
{
ECRNX_DBG("%s enter!!", __func__);
#if 0
uint16_t index = 0;
if (!skb || !skb->data){
ECRNX_PRINT("RX data invalid \n");
return -1;
}
//copy the rxu state and rx header, repush process need to used them
memcpy(src_rxu_state, skb->data, sizeof(struct rxu_stat_mm));
memcpy(src_rx_hd, skb->data + sizeof(struct rxu_stat_mm), sizeof(struct rx_hd));
/*copy the hw vector and rxu state */
memcpy(dst_hw_rxhdr, skb->data + sizeof(struct rxu_stat_mm), sizeof(struct rx_hd));
memcpy(&dst_hw_rxhdr->phy_info, \
skb->data + SKB_DATA_TAG_OFFSET, \
sizeof(struct rxu_stat_mm) - SKB_DATA_TAG_OFFSET);
memcpy(dst_rxdesc_tag, skb->data + SKB_DATA_COM_HD_OFFSET + 2, sizeof(struct rxdesc_tag)); //two byte msdu_mode
/*recove the hdr to skb data*/
skb_pull(skb, SKB_DATA_HD_OFFSET); //delete the frame type and amsdu flag
skb_push(skb, sizeof(struct hw_rxhdr));
memcpy(skb->data, dst_hw_rxhdr, sizeof(struct hw_rxhdr)); //put hw header to skb
skb_push(skb, sizeof(struct rxdesc_tag));
memcpy(skb->data, dst_rxdesc_tag, sizeof(struct rxdesc_tag)); //put rx desc tag to skb
for(index = 0; index < sizeof(struct hw_rxhdr) + sizeof(struct rxdesc_tag); index++)
{
ECRNX_DBG("0x%x ", skb->data[index]);
}
#endif
ECRNX_DBG("%s exit!!", __func__);
return 0;
}
/**
* @brief: ecrnx_sdio_init Initialize sdio interface.
* @param {ecrnx_hw} Main driver data
* @return: u8
*/
u8 ecrnx_sdio_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;
#ifdef CONFIG_TEST_ESWIN_SDIO
ecrnx_hw_set((void*)ecrnx_hw);
#endif
ECRNX_DBG("%s exit!!", __func__);
return 0;
}
/**
* @brief: ecrnx_sdio_deinit DeInitialize sdio interface.
* @param {ecrnx_hw} Main driver data
* @return: none
*/
void ecrnx_sdio_deinit(struct ecrnx_hw *ecrnx_hw)
{
ECRNX_DBG(ECRNX_FN_ENTRY_STR);
sdio_rx_buf_deinit();
memset(ecrnx_hw, 0, sizeof(struct ecrnx_hw));
memset(&sdio_rx_buff, 0, sizeof(sdio_rx_buf_t));
}
|