forked from initdc/eswin_6600u
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecrnx_msg_tx.c
executable file
·2482 lines (2031 loc) · 84.5 KB
/
ecrnx_msg_tx.c
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
******************************************************************************
*
* @file ecrnx_msg_tx.c
*
* @brief TX function definitions
*
* Copyright (C) ESWIN 2015-2020
*
******************************************************************************
*/
#include "ecrnx_msg_tx.h"
#include "ecrnx_mod_params.h"
#include "reg_access.h"
#ifdef CONFIG_ECRNX_BFMER
#include "ecrnx_bfmer.h"
#endif //(CONFIG_ECRNX_BFMER)
#include "ecrnx_compat.h"
#include "ecrnx_defs.h"
#include "ecrnx_calibration_data.h"
#include "eswin_utils.h"
#include "core.h"
const struct mac_addr mac_addr_bcst = {{0xFFFF, 0xFFFF, 0xFFFF}};
/* Default MAC Rx filters that can be changed by mac80211
* (via the configure_filter() callback) */
#define ECRNX_MAC80211_CHANGEABLE ( \
NXMAC_ACCEPT_BA_BIT | \
NXMAC_ACCEPT_BAR_BIT | \
NXMAC_ACCEPT_OTHER_DATA_FRAMES_BIT | \
NXMAC_ACCEPT_PROBE_REQ_BIT | \
NXMAC_ACCEPT_PS_POLL_BIT \
)
/* Default MAC Rx filters that cannot be changed by mac80211 */
#define ECRNX_MAC80211_NOT_CHANGEABLE ( \
NXMAC_ACCEPT_QO_S_NULL_BIT | \
NXMAC_ACCEPT_Q_DATA_BIT | \
NXMAC_ACCEPT_DATA_BIT | \
NXMAC_ACCEPT_OTHER_MGMT_FRAMES_BIT | \
NXMAC_ACCEPT_MY_UNICAST_BIT | \
NXMAC_ACCEPT_BROADCAST_BIT | \
NXMAC_ACCEPT_BEACON_BIT | \
NXMAC_ACCEPT_PROBE_RESP_BIT \
)
/* Default MAC Rx filter */
#define ECRNX_DEFAULT_RX_FILTER (ECRNX_MAC80211_CHANGEABLE | ECRNX_MAC80211_NOT_CHANGEABLE)
const int bw2chnl[] = {
[NL80211_CHAN_WIDTH_20_NOHT] = PHY_CHNL_BW_20,
[NL80211_CHAN_WIDTH_20] = PHY_CHNL_BW_20,
[NL80211_CHAN_WIDTH_40] = PHY_CHNL_BW_40,
[NL80211_CHAN_WIDTH_80] = PHY_CHNL_BW_80,
[NL80211_CHAN_WIDTH_160] = PHY_CHNL_BW_160,
[NL80211_CHAN_WIDTH_80P80] = PHY_CHNL_BW_80P80,
};
const int chnl2bw[] = {
[PHY_CHNL_BW_20] = NL80211_CHAN_WIDTH_20,
[PHY_CHNL_BW_40] = NL80211_CHAN_WIDTH_40,
[PHY_CHNL_BW_80] = NL80211_CHAN_WIDTH_80,
[PHY_CHNL_BW_160] = NL80211_CHAN_WIDTH_160,
[PHY_CHNL_BW_80P80] = NL80211_CHAN_WIDTH_80P80,
};
/*****************************************************************************/
/*
* Parse the ampdu density to retrieve the value in usec, according to the
* values defined in ieee80211.h
*/
static inline u8 ecrnx_ampdudensity2usec(u8 ampdudensity)
{
switch (ampdudensity) {
case IEEE80211_HT_MPDU_DENSITY_NONE:
return 0;
/* 1 microsecond is our granularity */
case IEEE80211_HT_MPDU_DENSITY_0_25:
case IEEE80211_HT_MPDU_DENSITY_0_5:
case IEEE80211_HT_MPDU_DENSITY_1:
return 1;
case IEEE80211_HT_MPDU_DENSITY_2:
return 2;
case IEEE80211_HT_MPDU_DENSITY_4:
return 4;
case IEEE80211_HT_MPDU_DENSITY_8:
return 8;
case IEEE80211_HT_MPDU_DENSITY_16:
return 16;
default:
return 0;
}
}
static inline bool use_pairwise_key(struct cfg80211_crypto_settings *crypto)
{
if ((crypto->cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
(crypto->cipher_group == WLAN_CIPHER_SUITE_WEP104))
return false;
return true;
}
static inline bool is_non_blocking_msg(int id)
{
return ((id == MM_TIM_UPDATE_REQ) || (id == ME_RC_SET_RATE_REQ) ||
(id == MM_BFMER_ENABLE_REQ) || (id == ME_TRAFFIC_IND_REQ) ||
(id == TDLS_PEER_TRAFFIC_IND_REQ) ||
(id == MESH_PATH_CREATE_REQ) || (id == MESH_PROXY_ADD_REQ) ||
(id == SM_EXTERNAL_AUTH_REQUIRED_RSP));
}
/**
* copy_connect_ies -- Copy Association Elements in the the request buffer
* send to the firmware
*
* @vif: Vif that received the connection request
* @req: Connection request to send to the firmware
* @sme: Connection info
*
* For driver that do not use userspace SME (like this one) the host connection
* request doesn't explicitly mentions that the connection can use FT over the
* air. if FT is possible, send the FT elements (as received in update_ft_ies callback)
* to the firmware
*
* In all other cases simply copy the list povided by the user space in the
* request buffer
*/
static void copy_connect_ies(struct ecrnx_vif *vif, struct sm_connect_req *req,
struct cfg80211_connect_params *sme)
{
if ((sme->auth_type == NL80211_AUTHTYPE_FT) && !(vif->sta.flags & ECRNX_STA_FT_OVER_DS))
{
const struct ecrnx_element *rsne, *fte, *mde;
uint8_t *pos;
rsne = cfg80211_find_ecrnx_elem(WLAN_EID_RSN, vif->sta.ft_assoc_ies,
vif->sta.ft_assoc_ies_len);
fte = cfg80211_find_ecrnx_elem(WLAN_EID_FAST_BSS_TRANSITION, vif->sta.ft_assoc_ies,
vif->sta.ft_assoc_ies_len);
mde = cfg80211_find_ecrnx_elem(WLAN_EID_MOBILITY_DOMAIN,
vif->sta.ft_assoc_ies, vif->sta.ft_assoc_ies_len);
pos = (uint8_t *)req->ie_buf;
// We can use FT over the air
memcpy(&vif->sta.ft_target_ap, sme->bssid, ETH_ALEN);
if (rsne) {
memcpy(pos, rsne, sizeof(struct ecrnx_element) + rsne->datalen);
pos += sizeof(struct ecrnx_element) + rsne->datalen;
}
memcpy(pos, mde, sizeof(struct ecrnx_element) + mde->datalen);
pos += sizeof(struct ecrnx_element) + mde->datalen;
if (fte) {
memcpy(pos, fte, sizeof(struct ecrnx_element) + fte->datalen);
pos += sizeof(struct ecrnx_element) + fte->datalen;
}
req->ie_len = pos - (uint8_t *)req->ie_buf;
}
else
{
memcpy(req->ie_buf, sme->ie, sme->ie_len);
req->ie_len = sme->ie_len;
}
}
/**
* update_connect_req -- Return the length of the association request IEs
*
* @vif: Vif that received the connection request
* @sme: Connection info
*
* Return the ft_ie_len in case of FT.
* FT over the air is possible if:
* - auth_type = AUTOMATIC (if already set to FT then it means FT over DS)
* - already associated to a FT BSS
* - Target Mobility domain is the same as the curent one
*
* If FT is not possible return ie length of the connection info
*/
static int update_connect_req(struct ecrnx_vif *vif, struct cfg80211_connect_params *sme)
{
if ((vif->sta.ap) &&
(vif->sta.ft_assoc_ies) &&
(sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC))
{
const struct ecrnx_element *rsne, *fte, *mde, *mde_req;
int ft_ie_len = 0;
mde_req = cfg80211_find_ecrnx_elem(WLAN_EID_MOBILITY_DOMAIN,
sme->ie, sme->ie_len);
mde = cfg80211_find_ecrnx_elem(WLAN_EID_MOBILITY_DOMAIN,
vif->sta.ft_assoc_ies, vif->sta.ft_assoc_ies_len);
if (!mde || !mde_req ||
memcmp(mde, mde_req, sizeof(struct ecrnx_element) + mde->datalen))
{
return sme->ie_len;
}
ft_ie_len += sizeof(struct ecrnx_element) + mde->datalen;
rsne = cfg80211_find_ecrnx_elem(WLAN_EID_RSN, vif->sta.ft_assoc_ies,
vif->sta.ft_assoc_ies_len);
fte = cfg80211_find_ecrnx_elem(WLAN_EID_FAST_BSS_TRANSITION, vif->sta.ft_assoc_ies,
vif->sta.ft_assoc_ies_len);
if (rsne && fte)
{
ft_ie_len += 2 * sizeof(struct ecrnx_element) + rsne->datalen + fte->datalen;
sme->auth_type = NL80211_AUTHTYPE_FT;
return ft_ie_len;
}
else if (rsne || fte)
{
netdev_warn(vif->ndev, "Missing RSNE or FTE element, skip FT over air");
}
else
{
sme->auth_type = NL80211_AUTHTYPE_FT;
return ft_ie_len;
}
}
return sme->ie_len;
}
static inline u8_l get_chan_flags(uint32_t flags)
{
u8_l chan_flags = 0;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
if (flags & IEEE80211_CHAN_PASSIVE_SCAN)
#else
if (flags & IEEE80211_CHAN_NO_IR)
chan_flags |= CHAN_NO_IR;
if (flags & IEEE80211_CHAN_RADAR)
chan_flags |= CHAN_RADAR;
#endif
return chan_flags;
}
static inline s8_l chan_to_fw_pwr(int power)
{
return power > 127 ? 127 : (s8_l)power;
}
static void cfg80211_to_ecrnx_chan(const struct cfg80211_chan_def *chandef,
struct mac_chan_op *chan)
{
if(chandef && chandef->chan){
chan->band = chandef->chan->band;
chan->type = bw2chnl[chandef->width];
chan->prim20_freq = chandef->chan->center_freq;
chan->center1_freq = chandef->center_freq1;
chan->center2_freq = chandef->center_freq2;
chan->flags = get_chan_flags(chandef->chan->flags);
chan->tx_power = chan_to_fw_pwr(chandef->chan->max_power);
}
}
static inline void limit_chan_bw(u8_l *bw, u16_l primary, u16_l *center1)
{
int oft, new_oft = 10;
if (*bw <= PHY_CHNL_BW_40)
return;
oft = *center1 - primary;
*bw = PHY_CHNL_BW_40;
if (oft < 0)
new_oft = new_oft * -1;
if (abs(oft) == 10 || abs(oft) == 50)
new_oft = new_oft * -1;
*center1 = primary + new_oft;
}
/**
******************************************************************************
* @brief Allocate memory for a message
*
* This primitive allocates memory for a message that has to be sent. The memory
* is allocated dynamically on the heap and the length of the variable parameter
* structure has to be provided in order to allocate the correct size.
*
* Several additional parameters are provided which will be preset in the message
* and which may be used internally to choose the kind of memory to allocate.
*
* The memory allocated will be automatically freed by the kernel, after the
* pointer has been sent to ke_msg_send(). If the message is not sent, it must
* be freed explicitly with ke_msg_free().
*
* Allocation failure is considered critical and should not happen.
*
* @param[in] id Message identifier
* @param[in] dest_id Destination Task Identifier
* @param[in] src_id Source Task Identifier
* @param[in] param_len Size of the message parameters to be allocated
*
* @return Pointer to the parameter member of the ke_msg. If the parameter
* structure is empty, the pointer will point to the end of the message
* and should not be used (except to retrieve the message pointer or to
* send the message)
******************************************************************************
*/
static inline void *ecrnx_msg_zalloc(lmac_msg_id_t const id,
lmac_task_id_t const dest_id,
lmac_task_id_t const src_id,
uint16_t const param_len)
{
struct lmac_msg *msg;
gfp_t flags;
if (is_non_blocking_msg(id) && in_atomic())
flags = GFP_ATOMIC;
else
flags = GFP_KERNEL;
msg = (struct lmac_msg *)kzalloc(sizeof(struct lmac_msg) + param_len,
flags);
if (msg == NULL) {
ecrnx_printk_err(KERN_CRIT "%s: msg allocation failed\n", __func__);
return NULL;
}
ecrnx_printk_msg("%s msg:0x%p, param:0x%p, id:0x%x, src_id:0x%x, dst_id:0x%x \n", __func__, msg, msg->param, id, src_id, dest_id);
msg->id = id;
msg->dest_id = dest_id;
msg->src_id = src_id;
msg->param_len = param_len;
return msg->param;
}
static void ecrnx_msg_free(struct ecrnx_hw *ecrnx_hw, const void *msg_params)
{
struct lmac_msg *msg = container_of((void *)msg_params,
struct lmac_msg, param);
ecrnx_printk_msg("%s msg:%p \n", __func__, msg);
/* Free the message */
kfree(msg);
}
static int ecrnx_send_msg(struct ecrnx_hw *ecrnx_hw, const void *msg_params,
int reqcfm, lmac_msg_id_t reqid, void *cfm)
{
struct lmac_msg *msg;
struct ecrnx_cmd *cmd;
bool nonblock;
int ret;
//ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
msg = container_of((void *)msg_params, struct lmac_msg, param);
if (!test_bit(ECRNX_DEV_STARTED, &ecrnx_hw->flags) &&
reqid != MM_RESET_CFM && reqid != MM_VERSION_CFM &&
reqid != MM_START_CFM && reqid != MM_SET_IDLE_CFM &&
reqid != ME_CONFIG_CFM && reqid != MM_SET_PS_MODE_CFM &&
reqid != ME_CHAN_CONFIG_CFM && reqid != MM_SET_GAIN_DELTA_CFM &&
reqid != MM_GET_CAL_RESULT_CFM && reqid != MM_SET_MACADRR_CFM) {
ecrnx_printk_err(KERN_CRIT "%s: bypassing (ECRNX_DEV_RESTARTING set) 0x%02x\n",
__func__, reqid);
kfree(msg);
return -EBUSY;
} else if (!ecrnx_hw->ipc_env) {
ecrnx_printk_err(KERN_CRIT "%s: bypassing (restart must have failed)\n", __func__);
kfree(msg);
return -EBUSY;
}
nonblock = is_non_blocking_msg(msg->id);
#if defined(CONFIG_ECRNX_ESWIN_USB)
if(register_status == false){
ecrnx_printk_err(KERN_CRIT "%s: register_status is false; \n", __func__);
kfree(msg);
return -ENODEV;
}
#endif
cmd = kzalloc(sizeof(struct ecrnx_cmd), nonblock ? GFP_ATOMIC : GFP_KERNEL);
if(!cmd) {
ecrnx_printk_err("no memory!\n");
return -ENOMEM;
}
cmd->result = -EINTR;
cmd->id = msg->id;
cmd->reqid = reqid;
cmd->a2e_msg = msg;
cmd->e2a_msg = cfm;
if (nonblock)
cmd->flags = ECRNX_CMD_FLAG_NONBLOCK;
if (reqcfm)
cmd->flags |= ECRNX_CMD_FLAG_REQ_CFM;
if(ecrnx_hw->wiphy != NULL)
{
ecrnx_printk_msg("%s inqueue, cmd:0x%p, cmd_flag:0x%x, msg:0x%p \n", __func__, cmd, cmd->flags, cmd->a2e_msg);
ret = ecrnx_hw->cmd_mgr.queue(&ecrnx_hw->cmd_mgr, cmd);
}
if (!ret)
ret = cmd->result;
if (!nonblock)
kfree(cmd);
ecrnx_printk_msg("%s ret:%d \n", __func__, ret);
return ret;
}
/******************************************************************************
* Control messages handling functions (SOFTMAC and FULLMAC)
*****************************************************************************/
int ecrnx_send_reset(struct ecrnx_hw *ecrnx_hw)
{
void *void_param;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* RESET REQ has no parameter */
void_param = ecrnx_msg_zalloc(MM_RESET_REQ, TASK_MM, DRV_TASK_ID, 0);
if (!void_param)
return -ENOMEM;
return ecrnx_send_msg(ecrnx_hw, void_param, 1, MM_RESET_CFM, NULL);
}
int ecrnx_send_start(struct ecrnx_hw *ecrnx_hw)
{
struct mm_start_req *start_req_param;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the START REQ message */
start_req_param = ecrnx_msg_zalloc(MM_START_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_start_req));
if (!start_req_param)
return -ENOMEM;
/* Set parameters for the START message */
memcpy(&start_req_param->phy_cfg, &ecrnx_hw->phy.cfg, sizeof(ecrnx_hw->phy.cfg));
start_req_param->uapsd_timeout = (u32_l)ecrnx_hw->mod_params->uapsd_timeout;
start_req_param->lp_clk_accuracy = (u16_l)ecrnx_hw->mod_params->lp_clk_ppm;
start_req_param->tx_timeout[AC_BK] = (u16_l)ecrnx_hw->mod_params->tx_to_bk;
start_req_param->tx_timeout[AC_BE] = (u16_l)ecrnx_hw->mod_params->tx_to_be;
start_req_param->tx_timeout[AC_VI] = (u16_l)ecrnx_hw->mod_params->tx_to_vi;
start_req_param->tx_timeout[AC_VO] = (u16_l)ecrnx_hw->mod_params->tx_to_vo;
/* Send the START REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, start_req_param, 1, MM_START_CFM, NULL);
}
int ecrnx_send_version_req(struct ecrnx_hw *ecrnx_hw, struct mm_version_cfm *cfm)
{
void *void_param;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* VERSION REQ has no parameter */
void_param = ecrnx_msg_zalloc(MM_VERSION_REQ, TASK_MM, DRV_TASK_ID, 0);
if (!void_param)
return -ENOMEM;
return ecrnx_send_msg(ecrnx_hw, void_param, 1, MM_VERSION_CFM, cfm);
}
int ecrnx_send_add_if(struct ecrnx_hw *ecrnx_hw, const unsigned char *mac,
enum nl80211_iftype iftype, bool p2p, struct mm_add_if_cfm *cfm)
{
struct mm_add_if_req *add_if_req_param;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the ADD_IF_REQ message */
add_if_req_param = ecrnx_msg_zalloc(MM_ADD_IF_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_add_if_req));
if (!add_if_req_param)
return -ENOMEM;
/* Set parameters for the ADD_IF_REQ message */
memcpy(&(add_if_req_param->addr.array[0]), mac, ETH_ALEN);
switch (iftype) {
case NL80211_IFTYPE_P2P_CLIENT:
add_if_req_param->p2p = true;
add_if_req_param->type = MM_STA;
break;
case NL80211_IFTYPE_STATION:
add_if_req_param->type = MM_STA;
break;
case NL80211_IFTYPE_ADHOC:
add_if_req_param->type = MM_IBSS;
break;
case NL80211_IFTYPE_P2P_GO:
add_if_req_param->p2p = true;
add_if_req_param->type = MM_AP;
break;
case NL80211_IFTYPE_AP:
add_if_req_param->type = MM_AP;
break;
case NL80211_IFTYPE_MESH_POINT:
add_if_req_param->type = MM_MESH_POINT;
break;
case NL80211_IFTYPE_AP_VLAN:
return -1;
case NL80211_IFTYPE_MONITOR:
add_if_req_param->type = MM_MONITOR;
break;
default:
add_if_req_param->type = MM_STA;
break;
}
/* Send the ADD_IF_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, add_if_req_param, 1, MM_ADD_IF_CFM, cfm);
}
int ecrnx_send_remove_if(struct ecrnx_hw *ecrnx_hw, u8 vif_index)
{
struct mm_remove_if_req *remove_if_req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_REMOVE_IF_REQ message */
remove_if_req = ecrnx_msg_zalloc(MM_REMOVE_IF_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remove_if_req));
if (!remove_if_req)
return -ENOMEM;
/* Set parameters for the MM_REMOVE_IF_REQ message */
remove_if_req->inst_nbr = vif_index;
/* Send the MM_REMOVE_IF_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, remove_if_req, 1, MM_REMOVE_IF_CFM, NULL);
}
int ecrnx_send_set_channel(struct ecrnx_hw *ecrnx_hw, int phy_idx,
struct mm_set_channel_cfm *cfm)
{
struct mm_set_channel_req *req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
if (phy_idx >= ecrnx_hw->phy.cnt)
return -ENOTSUPP;
req = ecrnx_msg_zalloc(MM_SET_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_channel_req));
if (!req)
return -ENOMEM;
if (phy_idx == 0) {
/* On FULLMAC only setting channel of secondary chain */
wiphy_err(ecrnx_hw->wiphy, "Trying to set channel of primary chain");
return 0;
} else {
req->chan = ecrnx_hw->phy.sec_chan;
}
req->index = phy_idx;
if (ecrnx_hw->phy.limit_bw)
limit_chan_bw(&req->chan.type, req->chan.prim20_freq, &req->chan.center1_freq);
/*ecrnx_printk_cfg("mac80211: freq=%d(c1:%d - c2:%d)/width=%d - band=%d\n"
" hw(%d): prim20=%d(c1:%d - c2:%d)/ type=%d - band=%d\n",
center_freq, center_freq1, center_freq2, width, band,
phy_idx, req->chan.prim20_freq, req->chan.center1_freq,
req->chan.center2_freq, req->chan.type, req->chan.band);*/
/* Send the MM_SET_CHANNEL_REQ REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, MM_SET_CHANNEL_CFM, cfm);
}
int ecrnx_send_key_add(struct ecrnx_hw *ecrnx_hw, u8 vif_idx, u8 sta_idx, bool pairwise,
u8 *key, u8 key_len, u8 key_idx, u8 cipher_suite,
struct mm_key_add_cfm *cfm)
{
struct mm_key_add_req *key_add_req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_KEY_ADD_REQ message */
key_add_req = ecrnx_msg_zalloc(MM_KEY_ADD_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_key_add_req));
if (!key_add_req)
return -ENOMEM;
/* Set parameters for the MM_KEY_ADD_REQ message */
if (sta_idx != 0xFF) {
/* Pairwise key */
key_add_req->sta_idx = sta_idx;
} else {
/* Default key */
key_add_req->sta_idx = sta_idx;
key_add_req->key_idx = (u8_l)key_idx; /* only useful for default keys */
}
key_add_req->pairwise = pairwise;
key_add_req->inst_nbr = vif_idx;
key_add_req->key.length = key_len;
memcpy(&(key_add_req->key.array[0]), key, key_len);
key_add_req->cipher_suite = cipher_suite;
ecrnx_printk_msg("%s: sta_idx:%d key_idx:%d inst_nbr:%d cipher:%d key_len:%d\n", __func__,
key_add_req->sta_idx, key_add_req->key_idx, key_add_req->inst_nbr,
key_add_req->cipher_suite, key_add_req->key.length);
#if defined(CONFIG_ECRNX_DBG) || defined(CONFIG_DYNAMIC_DEBUG)
print_hex_dump_bytes("key: ", DUMP_PREFIX_OFFSET, key_add_req->key.array, key_add_req->key.length);
#endif
/* Send the MM_KEY_ADD_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, key_add_req, 1, MM_KEY_ADD_CFM, cfm);
}
int ecrnx_send_key_del(struct ecrnx_hw *ecrnx_hw, uint8_t hw_key_idx)
{
struct mm_key_del_req *key_del_req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_KEY_DEL_REQ message */
key_del_req = ecrnx_msg_zalloc(MM_KEY_DEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_key_del_req));
if (!key_del_req)
return -ENOMEM;
/* Set parameters for the MM_KEY_DEL_REQ message */
key_del_req->hw_key_idx = hw_key_idx;
/* Send the MM_KEY_DEL_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, key_del_req, 1, MM_KEY_DEL_CFM, NULL);
}
int ecrnx_send_bcn_change(struct ecrnx_hw *ecrnx_hw, u8 vif_idx, dma_addr_t bcn_addr,
u16 bcn_len, u16 tim_oft, u16 tim_len, u16 *csa_oft)
{
struct mm_bcn_change_req *req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_BCN_CHANGE_REQ message */
req = ecrnx_msg_zalloc(MM_BCN_CHANGE_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_bcn_change_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_BCN_CHANGE_REQ message */
req->bcn_ptr = bcn_addr;
req->bcn_len = bcn_len;
req->tim_oft = tim_oft;
req->tim_len = tim_len;
req->inst_nbr = vif_idx;
if (csa_oft) {
int i;
for (i = 0; i < BCN_MAX_CSA_CPT; i++) {
req->csa_oft[i] = csa_oft[i];
}
}
/* Send the MM_BCN_CHANGE_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, MM_BCN_CHANGE_CFM, NULL);
}
int ecrnx_send_roc(struct ecrnx_hw *ecrnx_hw, struct ecrnx_vif *vif,
struct ieee80211_channel *chan, unsigned int duration)
{
struct mm_remain_on_channel_req *req;
struct cfg80211_chan_def chandef;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Create channel definition structure */
cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
/* Build the MM_REMAIN_ON_CHANNEL_REQ message */
req = ecrnx_msg_zalloc(MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remain_on_channel_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
req->op_code = MM_ROC_OP_START;
req->vif_index = vif->vif_index;
req->duration_ms = duration;
cfg80211_to_ecrnx_chan(&chandef, &req->chan);
/* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, MM_REMAIN_ON_CHANNEL_CFM, NULL);
}
int ecrnx_send_cancel_roc(struct ecrnx_hw *ecrnx_hw)
{
struct mm_remain_on_channel_req *req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_REMAIN_ON_CHANNEL_REQ message */
req = ecrnx_msg_zalloc(MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remain_on_channel_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
req->op_code = MM_ROC_OP_CANCEL;
/* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, MM_REMAIN_ON_CHANNEL_CFM, NULL);
}
int ecrnx_send_set_power(struct ecrnx_hw *ecrnx_hw, u8 vif_idx, s8 pwr,
struct mm_set_power_cfm *cfm)
{
struct mm_set_power_req *req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_SET_POWER_REQ message */
req = ecrnx_msg_zalloc(MM_SET_POWER_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_power_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_SET_POWER_REQ message */
req->inst_nbr = vif_idx;
req->power = pwr;
/* Send the MM_SET_POWER_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, MM_SET_POWER_CFM, cfm);
}
int ecrnx_send_set_edca(struct ecrnx_hw *ecrnx_hw, u8 hw_queue, u32 param,
bool uapsd, u8 inst_nbr)
{
struct mm_set_edca_req *set_edca_req;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_SET_EDCA_REQ message */
set_edca_req = ecrnx_msg_zalloc(MM_SET_EDCA_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_edca_req));
if (!set_edca_req)
return -ENOMEM;
/* Set parameters for the MM_SET_EDCA_REQ message */
set_edca_req->ac_param = param;
set_edca_req->uapsd = uapsd;
set_edca_req->hw_queue = hw_queue;
set_edca_req->inst_nbr = inst_nbr;
/* Send the MM_SET_EDCA_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, set_edca_req, 1, MM_SET_EDCA_CFM, NULL);
}
#ifdef CONFIG_ECRNX_P2P_DEBUGFS
int ecrnx_send_p2p_oppps_req(struct ecrnx_hw *ecrnx_hw, struct ecrnx_vif *ecrnx_vif,
u8 ctw, struct mm_set_p2p_oppps_cfm *cfm)
{
struct mm_set_p2p_oppps_req *p2p_oppps_req;
int error;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the MM_SET_P2P_OPPPS_REQ message */
p2p_oppps_req = ecrnx_msg_zalloc(MM_SET_P2P_OPPPS_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_p2p_oppps_req));
if (!p2p_oppps_req) {
return -ENOMEM;
}
/* Fill the message parameters */
p2p_oppps_req->vif_index = ecrnx_vif->vif_index;
p2p_oppps_req->ctwindow = ctw;
/* Send the MM_P2P_OPPPS_REQ message to LMAC FW */
error = ecrnx_send_msg(ecrnx_hw, p2p_oppps_req, 1, MM_SET_P2P_OPPPS_CFM, cfm);
return (error);
}
int ecrnx_send_p2p_noa_req(struct ecrnx_hw *ecrnx_hw, struct ecrnx_vif *ecrnx_vif,
int count, int interval, int duration, bool dyn_noa,
struct mm_set_p2p_noa_cfm *cfm)
{
struct mm_set_p2p_noa_req *p2p_noa_req;
int error;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Param check */
if (count > 255)
count = 255;
if (duration >= interval) {
dev_err(ecrnx_hw->dev, "Invalid p2p NOA config: interval=%d <= duration=%d\n",
interval, duration);
return -EINVAL;
}
/* Build the MM_SET_P2P_NOA_REQ message */
p2p_noa_req = ecrnx_msg_zalloc(MM_SET_P2P_NOA_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_p2p_noa_req));
if (!p2p_noa_req) {
return -ENOMEM;
}
/* Fill the message parameters */
p2p_noa_req->vif_index = ecrnx_vif->vif_index;
p2p_noa_req->noa_inst_nb = 0;
p2p_noa_req->count = count;
if (count) {
p2p_noa_req->duration_us = duration * 1024;
p2p_noa_req->interval_us = interval * 1024;
p2p_noa_req->start_offset = (interval - duration - 10) * 1024;
p2p_noa_req->dyn_noa = dyn_noa;
}
/* Send the MM_SET_2P_NOA_REQ message to LMAC FW */
error = ecrnx_send_msg(ecrnx_hw, p2p_noa_req, 1, MM_SET_P2P_NOA_CFM, cfm);
return (error);
}
#endif /* CONFIG_ECRNX_P2P_DEBUGFS */
/******************************************************************************
* Control messages handling functions (FULLMAC only)
*****************************************************************************/
#ifdef CONFIG_ECRNX_FULLMAC
int ecrnx_send_me_config_req(struct ecrnx_hw *ecrnx_hw)
{
struct me_config_req *req;
struct wiphy *wiphy = ecrnx_hw->wiphy;
#ifdef CONFIG_ECRNX_5G
struct ieee80211_sta_ht_cap *ht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap;
struct ieee80211_sta_vht_cap *vht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap;
#else
struct ieee80211_sta_ht_cap *ht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap;
struct ieee80211_sta_vht_cap *vht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0) && defined(CONFIG_ECRNX_HE)
struct ieee80211_sta_he_cap const *he_cap;
#endif
uint8_t *ht_mcs = (uint8_t *)&ht_cap->mcs;
int i;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the ME_CONFIG_REQ message */
req = ecrnx_msg_zalloc(ME_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_config_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_CONFIG_REQ message */
req->ht_supp = ht_cap->ht_supported;
req->vht_supp = vht_cap->vht_supported;
req->ht_cap.ht_capa_info = cpu_to_le16(ht_cap->cap);
req->ht_cap.a_mpdu_param = ht_cap->ampdu_factor |
(ht_cap->ampdu_density <<
IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
for (i = 0; i < sizeof(ht_cap->mcs); i++)
req->ht_cap.mcs_rate[i] = ht_mcs[i];
req->ht_cap.ht_extended_capa = 0;
req->ht_cap.tx_beamforming_capa = 0;
req->ht_cap.asel_capa = 0;
req->vht_cap.vht_capa_info = cpu_to_le32(vht_cap->cap);
req->vht_cap.rx_highest = cpu_to_le16(vht_cap->vht_mcs.rx_highest);
req->vht_cap.rx_mcs_map = cpu_to_le16(vht_cap->vht_mcs.rx_mcs_map);
req->vht_cap.tx_highest = cpu_to_le16(vht_cap->vht_mcs.tx_highest);
req->vht_cap.tx_mcs_map = cpu_to_le16(vht_cap->vht_mcs.tx_mcs_map);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0) && defined(CONFIG_ECRNX_HE)
#ifdef CONFIG_ECRNX_5G
if (wiphy->bands[NL80211_BAND_5GHZ]->iftype_data != NULL) {
he_cap = &wiphy->bands[NL80211_BAND_5GHZ]->iftype_data->he_cap;
#else
if (wiphy->bands[NL80211_BAND_2GHZ]->iftype_data != NULL) {
he_cap = &wiphy->bands[NL80211_BAND_2GHZ]->iftype_data->he_cap;
#endif
req->he_supp = he_cap->has_he;
for (i = 0; i < ARRAY_SIZE(he_cap->he_cap_elem.mac_cap_info); i++) {
req->he_cap.mac_cap_info[i] = he_cap->he_cap_elem.mac_cap_info[i];
}
for (i = 0; i < ARRAY_SIZE(he_cap->he_cap_elem.phy_cap_info); i++) {
req->he_cap.phy_cap_info[i] = he_cap->he_cap_elem.phy_cap_info[i];
}
req->he_cap.mcs_supp.rx_mcs_80 = cpu_to_le16(he_cap->he_mcs_nss_supp.rx_mcs_80);
req->he_cap.mcs_supp.tx_mcs_80 = cpu_to_le16(he_cap->he_mcs_nss_supp.tx_mcs_80);
req->he_cap.mcs_supp.rx_mcs_160 = cpu_to_le16(he_cap->he_mcs_nss_supp.rx_mcs_160);
req->he_cap.mcs_supp.tx_mcs_160 = cpu_to_le16(he_cap->he_mcs_nss_supp.tx_mcs_160);
req->he_cap.mcs_supp.rx_mcs_80p80 = cpu_to_le16(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
req->he_cap.mcs_supp.tx_mcs_80p80 = cpu_to_le16(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
for (i = 0; i < MAC_HE_PPE_THRES_MAX_LEN; i++) {
req->he_cap.ppe_thres[i] = he_cap->ppe_thres[i];
}
req->he_ul_on = ecrnx_hw->mod_params->he_ul_on;
}
#else
req->he_ul_on = false;
req->he_supp = ecrnx_he_cap.has_he;
for (i = 0; i < ARRAY_SIZE(ecrnx_he_cap.he_cap_elem.mac_cap_info); i++) {
req->he_cap.mac_cap_info[i] = ecrnx_he_cap.he_cap_elem.mac_cap_info[i];
}
for (i = 0; i < ARRAY_SIZE(ecrnx_he_cap.he_cap_elem.phy_cap_info); i++) {
req->he_cap.phy_cap_info[i] = ecrnx_he_cap.he_cap_elem.phy_cap_info[i];
}
req->he_cap.mcs_supp.rx_mcs_80 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.rx_mcs_80);
req->he_cap.mcs_supp.tx_mcs_80 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.tx_mcs_80);
req->he_cap.mcs_supp.rx_mcs_160 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.rx_mcs_160);
req->he_cap.mcs_supp.tx_mcs_160 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.tx_mcs_160);
req->he_cap.mcs_supp.rx_mcs_80p80 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.rx_mcs_80p80);
req->he_cap.mcs_supp.tx_mcs_80p80 = cpu_to_le16(ecrnx_he_cap.he_mcs_nss_supp.tx_mcs_80p80);
for (i = 0; i < MAC_HE_PPE_THRES_MAX_LEN; i++) {
req->he_cap.ppe_thres[i] = ecrnx_he_cap.ppe_thres[i];
}
#endif
req->ps_on = ecrnx_hw->mod_params->ps_on;
req->dpsm = ecrnx_hw->mod_params->dpsm;
/**
* set sleep_flag for sdio slave.
* bit0: MODEM_SLEEP
* bit1: WFI_SLEEP
* bit2: LIGHT_SLEEP
* bit3: DEEP_SLEEP
*/
req->sleep_flag = 0x5;
req->tx_lft = ecrnx_hw->mod_params->tx_lft;
req->ant_div_on = ecrnx_hw->mod_params->ant_div;
if (ecrnx_hw->mod_params->use_80)
req->phy_bw_max = PHY_CHNL_BW_80;
else if (ecrnx_hw->mod_params->use_2040)
req->phy_bw_max = PHY_CHNL_BW_40;
else
req->phy_bw_max = PHY_CHNL_BW_20;
req->custom_macrule = ecrnx_hw->mod_params->custom_macrule;
wiphy_info(wiphy, "HT supp %d, VHT supp %d, HE supp %d\n", req->ht_supp,
req->vht_supp,
req->he_supp);
/* Send the ME_CONFIG_REQ message to LMAC FW */
return ecrnx_send_msg(ecrnx_hw, req, 1, ME_CONFIG_CFM, NULL);
}
int ecrnx_send_me_chan_config_req(struct ecrnx_hw *ecrnx_hw)
{
struct me_chan_config_req *req;
struct wiphy *wiphy = ecrnx_hw->wiphy;
int i;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* Build the ME_CHAN_CONFIG_REQ message */
req = ecrnx_msg_zalloc(ME_CHAN_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_chan_config_req));
if (!req)
return -ENOMEM;
req->chan2G4_cnt= 0;
if (wiphy->bands[NL80211_BAND_2GHZ] != NULL) {
struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_2GHZ];
for (i = 0; i < b->n_channels; i++) {
req->chan2G4[req->chan2G4_cnt].flags = 0;
if (b->channels[i].flags & IEEE80211_CHAN_DISABLED)
req->chan2G4[req->chan2G4_cnt].flags |= CHAN_DISABLED;
req->chan2G4[req->chan2G4_cnt].flags |= get_chan_flags(b->channels[i].flags);
req->chan2G4[req->chan2G4_cnt].band = NL80211_BAND_2GHZ;
req->chan2G4[req->chan2G4_cnt].freq = b->channels[i].center_freq;
req->chan2G4[req->chan2G4_cnt].tx_power = chan_to_fw_pwr(b->channels[i].max_power);
req->chan2G4_cnt++;
if (req->chan2G4_cnt == MAC_DOMAINCHANNEL_24G_MAX)
break;
}
}
req->chan5G_cnt = 0;
#ifdef CONFIG_ECRNX_5G
if (wiphy->bands[NL80211_BAND_5GHZ] != NULL) {
struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_5GHZ];
for (i = 0; i < b->n_channels; i++) {
req->chan5G[req->chan5G_cnt].flags = 0;
if (b->channels[i].flags & IEEE80211_CHAN_DISABLED)
req->chan5G[req->chan5G_cnt].flags |= CHAN_DISABLED;
req->chan5G[req->chan5G_cnt].flags |= get_chan_flags(b->channels[i].flags);
req->chan5G[req->chan5G_cnt].band = NL80211_BAND_5GHZ;
req->chan5G[req->chan5G_cnt].freq = b->channels[i].center_freq;