-
Notifications
You must be signed in to change notification settings - Fork 184
/
fw.c
2478 lines (2031 loc) · 65.8 KB
/
fw.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
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2018-2019 Realtek Corporation
*/
#include <linux/iopoll.h>
#include "main.h"
#include "coex.h"
#include "fw.h"
#include "tx.h"
#include "reg.h"
#include "sec.h"
#include "debug.h"
#include "util.h"
#include "wow.h"
#include "ps.h"
#include "phy.h"
#include "mac.h"
static const struct rtw_hw_reg_desc fw_h2c_regs[] = {
{REG_FWIMR, MASKDWORD, "FWIMR"},
{REG_FWIMR, BIT_FS_H2CCMD_INT_EN, "FWIMR enable"},
{REG_FWISR, MASKDWORD, "FWISR"},
{REG_FWISR, BIT_FS_H2CCMD_INT, "FWISR enable"},
{REG_HMETFR, BIT_INT_BOX_ALL, "BoxBitMap"},
{REG_HMEBOX0, MASKDWORD, "MSG 0"},
{REG_HMEBOX0_EX, MASKDWORD, "MSG_EX 0"},
{REG_HMEBOX1, MASKDWORD, "MSG 1"},
{REG_HMEBOX1_EX, MASKDWORD, "MSG_EX 1"},
{REG_HMEBOX2, MASKDWORD, "MSG 2"},
{REG_HMEBOX2_EX, MASKDWORD, "MSG_EX 2"},
{REG_HMEBOX3, MASKDWORD, "MSG 3"},
{REG_HMEBOX3_EX, MASKDWORD, "MSG_EX 3"},
{REG_FT1IMR, MASKDWORD, "FT1IMR"},
{REG_FT1IMR, BIT_FS_H2C_CMD_OK_INT_EN, "FT1IMR enable"},
{REG_FT1ISR, MASKDWORD, "FT1ISR"},
{REG_FT1ISR, BIT_FS_H2C_CMD_OK_INT, "FT1ISR enable "},
};
static const struct rtw_hw_reg_desc fw_c2h_regs[] = {
{REG_FWIMR, MASKDWORD, "FWIMR"},
{REG_FWIMR, BIT_FS_H2CCMD_INT_EN, "CPWM"},
{REG_FWIMR, BIT_FS_HRCV_INT_EN, "HRECV"},
{REG_FWISR, MASKDWORD, "FWISR"},
{REG_FWISR, BIT_FS_H2CCMD_INT, "CPWM"},
{REG_FWISR, BIT_FS_HRCV_INT, "HRECV"},
{REG_CPWM, MASKDWORD, "REG_CPWM"},
};
static const struct rtw_hw_reg_desc fw_core_regs[] = {
{REG_ARFR2_V1, MASKDWORD, "EPC"},
{REG_ARFRH2_V1, MASKDWORD, "BADADDR"},
{REG_ARFR3_V1, MASKDWORD, "CAUSE"},
{REG_ARFR3_V1, BIT_EXC_CODE, "ExcCode"},
{REG_ARFRH3_V1, MASKDWORD, "Status"},
{REG_ARFR4, MASKDWORD, "SP"},
{REG_ARFRH4, MASKDWORD, "RA"},
{REG_FW_DBG6, MASKDWORD, "DBG 6"},
{REG_FW_DBG7, MASKDWORD, "DBG 7"},
};
static void _rtw_fw_dump_dbg_info(struct rtw_dev *rtwdev,
const struct rtw_hw_reg_desc regs[], u32 size)
{
const struct rtw_hw_reg_desc *reg;
u32 val;
int i;
for (i = 0; i < size; i++) {
reg = ®s[i];
val = rtw_read32_mask(rtwdev, reg->addr, reg->mask);
rtw_dbg(rtwdev, RTW_DBG_FW, "[%s]addr:0x%x mask:0x%x value:0x%x\n",
reg->desc, reg->addr, reg->mask, val);
}
}
void rtw_fw_dump_dbg_info(struct rtw_dev *rtwdev)
{
int i;
if (!rtw_dbg_is_enabled(rtwdev, RTW_DBG_FW))
return;
_rtw_fw_dump_dbg_info(rtwdev, fw_h2c_regs, ARRAY_SIZE(fw_h2c_regs));
_rtw_fw_dump_dbg_info(rtwdev, fw_c2h_regs, ARRAY_SIZE(fw_c2h_regs));
for (i = 0 ; i < RTW_DEBUG_DUMP_TIMES; i++) {
rtw_dbg(rtwdev, RTW_DBG_FW, "Firmware Coredump %dth\n", i + 1);
_rtw_fw_dump_dbg_info(rtwdev, fw_core_regs, ARRAY_SIZE(fw_core_regs));
}
}
static void rtw_fw_c2h_cmd_handle_ext(struct rtw_dev *rtwdev,
struct sk_buff *skb)
{
struct rtw_c2h_cmd *c2h;
u8 sub_cmd_id;
c2h = get_c2h_from_skb(skb);
sub_cmd_id = c2h->payload[0];
switch (sub_cmd_id) {
case C2H_CCX_RPT:
rtw_tx_report_handle(rtwdev, skb, C2H_CCX_RPT);
break;
case C2H_SCAN_STATUS_RPT:
rtw_hw_scan_status_report(rtwdev, skb);
break;
case C2H_CHAN_SWITCH:
rtw_hw_scan_chan_switch(rtwdev, skb);
break;
default:
break;
}
}
static u16 get_max_amsdu_len(u32 bit_rate)
{
/* lower than ofdm, do not aggregate */
if (bit_rate < 550)
return 1;
/* lower than 20M 2ss mcs8, make it small */
if (bit_rate < 1800)
return 1200;
/* lower than 40M 2ss mcs9, make it medium */
if (bit_rate < 4000)
return 2600;
/* not yet 80M 2ss mcs8/9, make it twice regular packet size */
if (bit_rate < 7000)
return 3500;
/* unlimited */
return 0;
}
struct rtw_fw_iter_ra_data {
struct rtw_dev *rtwdev;
u8 *payload;
u8 length;
};
static void rtw_fw_ra_report_iter(void *data, struct ieee80211_sta *sta)
{
struct rtw_fw_iter_ra_data *ra_data = data;
struct rtw_c2h_ra_rpt *ra_rpt = (struct rtw_c2h_ra_rpt *)ra_data->payload;
struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;
u8 mac_id, rate, sgi, bw;
u8 mcs, nss;
u32 bit_rate;
mac_id = ra_rpt->mac_id;
if (si->mac_id != mac_id)
return;
si->ra_report.txrate.flags = 0;
rate = u8_get_bits(ra_rpt->rate_sgi, RTW_C2H_RA_RPT_RATE);
sgi = u8_get_bits(ra_rpt->rate_sgi, RTW_C2H_RA_RPT_SGI);
if (ra_data->length >= offsetofend(typeof(*ra_rpt), bw))
bw = ra_rpt->bw;
else
bw = si->bw_mode;
if (rate < DESC_RATEMCS0) {
si->ra_report.txrate.legacy = rtw_desc_to_bitrate(rate);
goto legacy;
}
rtw_desc_to_mcsrate(rate, &mcs, &nss);
if (rate >= DESC_RATEVHT1SS_MCS0)
si->ra_report.txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
else if (rate >= DESC_RATEMCS0)
si->ra_report.txrate.flags |= RATE_INFO_FLAGS_MCS;
if (rate >= DESC_RATEMCS0) {
si->ra_report.txrate.mcs = mcs;
si->ra_report.txrate.nss = nss;
}
if (sgi)
si->ra_report.txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
if (bw == RTW_CHANNEL_WIDTH_80)
si->ra_report.txrate.bw = RATE_INFO_BW_80;
else if (bw == RTW_CHANNEL_WIDTH_40)
si->ra_report.txrate.bw = RATE_INFO_BW_40;
else
si->ra_report.txrate.bw = RATE_INFO_BW_20;
legacy:
bit_rate = cfg80211_calculate_bitrate(&si->ra_report.txrate);
si->ra_report.desc_rate = rate;
si->ra_report.bit_rate = bit_rate;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
sta->deflink.agg.max_rc_amsdu_len = get_max_amsdu_len(bit_rate);
#else
sta->max_rc_amsdu_len = get_max_amsdu_len(bit_rate);
#endif
}
static void rtw_fw_ra_report_handle(struct rtw_dev *rtwdev, u8 *payload,
u8 length)
{
struct rtw_c2h_ra_rpt *ra_rpt = (struct rtw_c2h_ra_rpt *)payload;
struct rtw_fw_iter_ra_data ra_data;
if (WARN(length < rtwdev->chip->c2h_ra_report_size,
"invalid ra report c2h length %d\n", length))
return;
rtwdev->dm_info.tx_rate = u8_get_bits(ra_rpt->rate_sgi,
RTW_C2H_RA_RPT_RATE);
ra_data.rtwdev = rtwdev;
ra_data.payload = payload;
ra_data.length = length;
rtw_iterate_stas_atomic(rtwdev, rtw_fw_ra_report_iter, &ra_data);
}
struct rtw_beacon_filter_iter_data {
struct rtw_dev *rtwdev;
u8 *payload;
};
static void rtw_fw_bcn_filter_notify_vif_iter(void *data,
struct ieee80211_vif *vif)
{
struct rtw_beacon_filter_iter_data *iter_data = data;
struct rtw_dev *rtwdev = iter_data->rtwdev;
u8 *payload = iter_data->payload;
u8 type = GET_BCN_FILTER_NOTIFY_TYPE(payload);
u8 event = GET_BCN_FILTER_NOTIFY_EVENT(payload);
s8 sig = (s8)GET_BCN_FILTER_NOTIFY_RSSI(payload);
switch (type) {
case BCN_FILTER_NOTIFY_SIGNAL_CHANGE:
event = event ? NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH :
NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
ieee80211_cqm_rssi_notify(vif, event, sig, GFP_KERNEL);
break;
case BCN_FILTER_CONNECTION_LOSS:
ieee80211_connection_loss(vif);
break;
case BCN_FILTER_CONNECTED:
rtwdev->beacon_loss = false;
break;
case BCN_FILTER_NOTIFY_BEACON_LOSS:
rtwdev->beacon_loss = true;
rtw_leave_lps(rtwdev);
break;
}
}
static void rtw_fw_bcn_filter_notify(struct rtw_dev *rtwdev, u8 *payload,
u8 length)
{
struct rtw_beacon_filter_iter_data dev_iter_data;
dev_iter_data.rtwdev = rtwdev;
dev_iter_data.payload = payload;
rtw_iterate_vifs(rtwdev, rtw_fw_bcn_filter_notify_vif_iter,
&dev_iter_data);
}
static void rtw_fw_scan_result(struct rtw_dev *rtwdev, u8 *payload,
u8 length)
{
struct rtw_dm_info *dm_info = &rtwdev->dm_info;
dm_info->scan_density = payload[0];
rtw_dbg(rtwdev, RTW_DBG_FW, "scan.density = %x\n",
dm_info->scan_density);
}
static void rtw_fw_adaptivity_result(struct rtw_dev *rtwdev, u8 *payload,
u8 length)
{
const struct rtw_hw_reg_offset *edcca_th = rtwdev->chip->edcca_th;
struct rtw_c2h_adaptivity *result = (struct rtw_c2h_adaptivity *)payload;
rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY,
"Adaptivity: density %x igi %x l2h_th_init %x l2h %x h2l %x option %x\n",
result->density, result->igi, result->l2h_th_init, result->l2h,
result->h2l, result->option);
rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY, "Reg Setting: L2H %x H2L %x\n",
rtw_read32_mask(rtwdev, edcca_th[EDCCA_TH_L2H_IDX].hw_reg.addr,
edcca_th[EDCCA_TH_L2H_IDX].hw_reg.mask),
rtw_read32_mask(rtwdev, edcca_th[EDCCA_TH_H2L_IDX].hw_reg.addr,
edcca_th[EDCCA_TH_H2L_IDX].hw_reg.mask));
rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY, "EDCCA Flag %s\n",
rtw_read32_mask(rtwdev, REG_EDCCA_REPORT, BIT_EDCCA_FLAG) ?
"Set" : "Unset");
}
void rtw_fw_c2h_cmd_handle(struct rtw_dev *rtwdev, struct sk_buff *skb)
{
struct rtw_c2h_cmd *c2h;
u32 pkt_offset;
u8 len;
pkt_offset = *((u32 *)skb->cb);
c2h = (struct rtw_c2h_cmd *)(skb->data + pkt_offset);
len = skb->len - pkt_offset - 2;
mutex_lock(&rtwdev->mutex);
if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags))
goto unlock;
switch (c2h->id) {
case C2H_CCX_TX_RPT:
rtw_tx_report_handle(rtwdev, skb, C2H_CCX_TX_RPT);
break;
case C2H_BT_INFO:
rtw_coex_bt_info_notify(rtwdev, c2h->payload, len);
break;
case C2H_BT_HID_INFO:
rtw_coex_bt_hid_info_notify(rtwdev, c2h->payload, len);
break;
case C2H_WLAN_INFO:
rtw_coex_wl_fwdbginfo_notify(rtwdev, c2h->payload, len);
break;
case C2H_BCN_FILTER_NOTIFY:
rtw_fw_bcn_filter_notify(rtwdev, c2h->payload, len);
break;
case C2H_HALMAC:
rtw_fw_c2h_cmd_handle_ext(rtwdev, skb);
break;
case C2H_RA_RPT:
rtw_fw_ra_report_handle(rtwdev, c2h->payload, len);
break;
case C2H_ADAPTIVITY:
rtw_fw_adaptivity_result(rtwdev, c2h->payload, len);
break;
default:
rtw_dbg(rtwdev, RTW_DBG_FW, "C2H 0x%x isn't handled\n", c2h->id);
break;
}
unlock:
mutex_unlock(&rtwdev->mutex);
}
void rtw_fw_c2h_cmd_rx_irqsafe(struct rtw_dev *rtwdev, u32 pkt_offset,
struct sk_buff *skb)
{
struct rtw_c2h_cmd *c2h;
u8 len;
c2h = (struct rtw_c2h_cmd *)(skb->data + pkt_offset);
len = skb->len - pkt_offset - 2;
*((u32 *)skb->cb) = pkt_offset;
rtw_dbg(rtwdev, RTW_DBG_FW, "recv C2H, id=0x%02x, seq=0x%02x, len=%d\n",
c2h->id, c2h->seq, len);
switch (c2h->id) {
case C2H_BT_MP_INFO:
rtw_coex_info_response(rtwdev, skb);
break;
case C2H_WLAN_RFON:
complete(&rtwdev->lps_leave_check);
dev_kfree_skb_any(skb);
break;
case C2H_SCAN_RESULT:
complete(&rtwdev->fw_scan_density);
rtw_fw_scan_result(rtwdev, c2h->payload, len);
dev_kfree_skb_any(skb);
break;
default:
/* pass offset for further operation */
*((u32 *)skb->cb) = pkt_offset;
skb_queue_tail(&rtwdev->c2h_queue, skb);
ieee80211_queue_work(rtwdev->hw, &rtwdev->c2h_work);
break;
}
}
EXPORT_SYMBOL(rtw_fw_c2h_cmd_rx_irqsafe);
void rtw_fw_c2h_cmd_isr(struct rtw_dev *rtwdev)
{
if (rtw_read8(rtwdev, REG_MCU_TST_CFG) == VAL_FW_TRIGGER)
rtw_fw_recovery(rtwdev);
else
rtw_warn(rtwdev, "unhandled firmware c2h interrupt\n");
}
EXPORT_SYMBOL(rtw_fw_c2h_cmd_isr);
static void rtw_fw_send_h2c_command_register(struct rtw_dev *rtwdev,
struct rtw_h2c_register *h2c)
{
u32 box_reg, box_ex_reg;
u8 box_state, box;
int ret;
rtw_dbg(rtwdev, RTW_DBG_FW, "send H2C content %08x %08x\n", h2c->w0,
h2c->w1);
lockdep_assert_held(&rtwdev->mutex);
box = rtwdev->h2c.last_box_num;
switch (box) {
case 0:
box_reg = REG_HMEBOX0;
box_ex_reg = REG_HMEBOX0_EX;
break;
case 1:
box_reg = REG_HMEBOX1;
box_ex_reg = REG_HMEBOX1_EX;
break;
case 2:
box_reg = REG_HMEBOX2;
box_ex_reg = REG_HMEBOX2_EX;
break;
case 3:
box_reg = REG_HMEBOX3;
box_ex_reg = REG_HMEBOX3_EX;
break;
default:
WARN(1, "invalid h2c mail box number\n");
return;
}
ret = read_poll_timeout_atomic(rtw_read8, box_state,
!((box_state >> box) & 0x1), 100, 3000,
false, rtwdev, REG_HMETFR);
if (ret) {
rtw_err(rtwdev, "failed to send h2c command\n");
rtw_fw_dump_dbg_info(rtwdev);
return;
}
rtw_write32(rtwdev, box_ex_reg, h2c->w1);
rtw_write32(rtwdev, box_reg, h2c->w0);
if (++rtwdev->h2c.last_box_num >= 4)
rtwdev->h2c.last_box_num = 0;
}
static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev,
u8 *h2c)
{
struct rtw_h2c_cmd *h2c_cmd = (struct rtw_h2c_cmd *)h2c;
u8 box;
u8 box_state;
u32 box_reg, box_ex_reg;
int ret;
rtw_dbg(rtwdev, RTW_DBG_FW,
"send H2C content %02x%02x%02x%02x %02x%02x%02x%02x\n",
h2c[3], h2c[2], h2c[1], h2c[0],
h2c[7], h2c[6], h2c[5], h2c[4]);
lockdep_assert_held(&rtwdev->mutex);
box = rtwdev->h2c.last_box_num;
switch (box) {
case 0:
box_reg = REG_HMEBOX0;
box_ex_reg = REG_HMEBOX0_EX;
break;
case 1:
box_reg = REG_HMEBOX1;
box_ex_reg = REG_HMEBOX1_EX;
break;
case 2:
box_reg = REG_HMEBOX2;
box_ex_reg = REG_HMEBOX2_EX;
break;
case 3:
box_reg = REG_HMEBOX3;
box_ex_reg = REG_HMEBOX3_EX;
break;
default:
WARN(1, "invalid h2c mail box number\n");
return;
}
ret = read_poll_timeout_atomic(rtw_read8, box_state,
!((box_state >> box) & 0x1), 100, 3000,
false, rtwdev, REG_HMETFR);
if (ret) {
rtw_err(rtwdev, "failed to send h2c command\n");
return;
}
rtw_write32(rtwdev, box_ex_reg, le32_to_cpu(h2c_cmd->msg_ext));
rtw_write32(rtwdev, box_reg, le32_to_cpu(h2c_cmd->msg));
if (++rtwdev->h2c.last_box_num >= 4)
rtwdev->h2c.last_box_num = 0;
}
void rtw_fw_h2c_cmd_dbg(struct rtw_dev *rtwdev, u8 *h2c)
{
rtw_fw_send_h2c_command(rtwdev, h2c);
}
static void rtw_fw_send_h2c_packet(struct rtw_dev *rtwdev, u8 *h2c_pkt)
{
int ret;
lockdep_assert_held(&rtwdev->mutex);
FW_OFFLOAD_H2C_SET_SEQ_NUM(h2c_pkt, rtwdev->h2c.seq);
ret = rtw_hci_write_data_h2c(rtwdev, h2c_pkt, H2C_PKT_SIZE);
if (ret)
rtw_err(rtwdev, "failed to send h2c packet\n");
rtwdev->h2c.seq++;
}
void
rtw_fw_send_general_info(struct rtw_dev *rtwdev)
{
struct rtw_fifo_conf *fifo = &rtwdev->fifo;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u16 total_size = H2C_PKT_HDR_SIZE + 4;
if (rtw_chip_wcpu_11n(rtwdev))
return;
rtw_h2c_pkt_set_header(h2c_pkt, H2C_PKT_GENERAL_INFO);
SET_PKT_H2C_TOTAL_LEN(h2c_pkt, total_size);
GENERAL_INFO_SET_FW_TX_BOUNDARY(h2c_pkt,
fifo->rsvd_fw_txbuf_addr -
fifo->rsvd_boundary);
rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
}
void
rtw_fw_send_phydm_info(struct rtw_dev *rtwdev)
{
struct rtw_hal *hal = &rtwdev->hal;
struct rtw_efuse *efuse = &rtwdev->efuse;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u16 total_size = H2C_PKT_HDR_SIZE + 8;
u8 fw_rf_type = 0;
if (rtw_chip_wcpu_11n(rtwdev))
return;
if (hal->rf_type == RF_1T1R)
fw_rf_type = FW_RF_1T1R;
else if (hal->rf_type == RF_2T2R)
fw_rf_type = FW_RF_2T2R;
rtw_h2c_pkt_set_header(h2c_pkt, H2C_PKT_PHYDM_INFO);
SET_PKT_H2C_TOTAL_LEN(h2c_pkt, total_size);
PHYDM_INFO_SET_REF_TYPE(h2c_pkt, efuse->rfe_option);
PHYDM_INFO_SET_RF_TYPE(h2c_pkt, fw_rf_type);
PHYDM_INFO_SET_CUT_VER(h2c_pkt, hal->cut_version);
PHYDM_INFO_SET_RX_ANT_STATUS(h2c_pkt, hal->antenna_tx);
PHYDM_INFO_SET_TX_ANT_STATUS(h2c_pkt, hal->antenna_rx);
rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
}
void rtw_fw_do_iqk(struct rtw_dev *rtwdev, struct rtw_iqk_para *para)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u16 total_size = H2C_PKT_HDR_SIZE + 1;
rtw_h2c_pkt_set_header(h2c_pkt, H2C_PKT_IQK);
SET_PKT_H2C_TOTAL_LEN(h2c_pkt, total_size);
IQK_SET_CLEAR(h2c_pkt, para->clear);
IQK_SET_SEGMENT_IQK(h2c_pkt, para->segment_iqk);
rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
}
EXPORT_SYMBOL(rtw_fw_do_iqk);
void rtw_fw_inform_rfk_status(struct rtw_dev *rtwdev, bool start)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_WIFI_CALIBRATION);
RFK_SET_INFORM_START(h2c_pkt, start);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
EXPORT_SYMBOL(rtw_fw_inform_rfk_status);
void rtw_fw_query_bt_info(struct rtw_dev *rtwdev)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_QUERY_BT_INFO);
SET_QUERY_BT_INFO(h2c_pkt, true);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_default_port(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
{
struct rtw_h2c_register h2c = {};
if (rtwvif->net_type != RTW_NET_MGD_LINKED)
return;
/* Leave LPS before default port H2C so FW timer is correct */
rtw_leave_lps(rtwdev);
h2c.w0 = u32_encode_bits(H2C_CMD_DEFAULT_PORT, RTW_H2C_W0_CMDID) |
u32_encode_bits(rtwvif->port, RTW_H2C_DEFAULT_PORT_W0_PORTID) |
u32_encode_bits(rtwvif->mac_id, RTW_H2C_DEFAULT_PORT_W0_MACID);
rtw_fw_send_h2c_command_register(rtwdev, &h2c);
}
void rtw_fw_wl_ch_info(struct rtw_dev *rtwdev, u8 link, u8 ch, u8 bw)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_WL_CH_INFO);
SET_WL_CH_INFO_LINK(h2c_pkt, link);
SET_WL_CH_INFO_CHNL(h2c_pkt, ch);
SET_WL_CH_INFO_BW(h2c_pkt, bw);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_query_bt_mp_info(struct rtw_dev *rtwdev,
struct rtw_coex_info_req *req)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_QUERY_BT_MP_INFO);
SET_BT_MP_INFO_SEQ(h2c_pkt, req->seq);
SET_BT_MP_INFO_OP_CODE(h2c_pkt, req->op_code);
SET_BT_MP_INFO_PARA1(h2c_pkt, req->para1);
SET_BT_MP_INFO_PARA2(h2c_pkt, req->para2);
SET_BT_MP_INFO_PARA3(h2c_pkt, req->para3);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_force_bt_tx_power(struct rtw_dev *rtwdev, u8 bt_pwr_dec_lvl)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u8 index = 0 - bt_pwr_dec_lvl;
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_FORCE_BT_TX_POWER);
SET_BT_TX_POWER_INDEX(h2c_pkt, index);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_bt_ignore_wlan_action(struct rtw_dev *rtwdev, bool enable)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_IGNORE_WLAN_ACTION);
SET_IGNORE_WLAN_ACTION_EN(h2c_pkt, enable);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_coex_tdma_type(struct rtw_dev *rtwdev,
u8 para1, u8 para2, u8 para3, u8 para4, u8 para5)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_COEX_TDMA_TYPE);
SET_COEX_TDMA_TYPE_PARA1(h2c_pkt, para1);
SET_COEX_TDMA_TYPE_PARA2(h2c_pkt, para2);
SET_COEX_TDMA_TYPE_PARA3(h2c_pkt, para3);
SET_COEX_TDMA_TYPE_PARA4(h2c_pkt, para4);
SET_COEX_TDMA_TYPE_PARA5(h2c_pkt, para5);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_coex_query_hid_info(struct rtw_dev *rtwdev, u8 sub_id, u8 data)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_QUERY_BT_HID_INFO);
SET_COEX_QUERY_HID_INFO_SUBID(h2c_pkt, sub_id);
SET_COEX_QUERY_HID_INFO_DATA1(h2c_pkt, data);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_bt_wifi_control(struct rtw_dev *rtwdev, u8 op_code, u8 *data)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_BT_WIFI_CONTROL);
SET_BT_WIFI_CONTROL_OP_CODE(h2c_pkt, op_code);
SET_BT_WIFI_CONTROL_DATA1(h2c_pkt, *data);
SET_BT_WIFI_CONTROL_DATA2(h2c_pkt, *(data + 1));
SET_BT_WIFI_CONTROL_DATA3(h2c_pkt, *(data + 2));
SET_BT_WIFI_CONTROL_DATA4(h2c_pkt, *(data + 3));
SET_BT_WIFI_CONTROL_DATA5(h2c_pkt, *(data + 4));
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_send_rssi_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u8 rssi = ewma_rssi_read(&si->avg_rssi);
bool stbc_en = si->stbc_en ? true : false;
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RSSI_MONITOR);
SET_RSSI_INFO_MACID(h2c_pkt, si->mac_id);
SET_RSSI_INFO_RSSI(h2c_pkt, rssi);
SET_RSSI_INFO_STBC(h2c_pkt, stbc_en);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)
void rtw_fw_send_ra_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si,
bool reset_ra_mask)
#else
void rtw_fw_send_ra_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si)
#endif
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
bool disable_pt = true;
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
bool reset_ra_mask = true;
#endif
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RA_INFO);
SET_RA_INFO_MACID(h2c_pkt, si->mac_id);
SET_RA_INFO_RATE_ID(h2c_pkt, si->rate_id);
SET_RA_INFO_INIT_RA_LVL(h2c_pkt, si->init_ra_lv);
SET_RA_INFO_SGI_EN(h2c_pkt, si->sgi_enable);
SET_RA_INFO_BW_MODE(h2c_pkt, si->bw_mode);
SET_RA_INFO_LDPC(h2c_pkt, !!si->ldpc_en);
SET_RA_INFO_NO_UPDATE(h2c_pkt, !reset_ra_mask);
SET_RA_INFO_VHT_EN(h2c_pkt, si->vht_enable);
SET_RA_INFO_DIS_PT(h2c_pkt, disable_pt);
SET_RA_INFO_RA_MASK0(h2c_pkt, (si->ra_mask & 0xff));
SET_RA_INFO_RA_MASK1(h2c_pkt, (si->ra_mask & 0xff00) >> 8);
SET_RA_INFO_RA_MASK2(h2c_pkt, (si->ra_mask & 0xff0000) >> 16);
SET_RA_INFO_RA_MASK3(h2c_pkt, (si->ra_mask & 0xff000000) >> 24);
si->init_ra_lv = 0;
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_media_status_report(struct rtw_dev *rtwdev, u8 mac_id, bool connect)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_MEDIA_STATUS_RPT);
MEDIA_STATUS_RPT_SET_OP_MODE(h2c_pkt, connect);
MEDIA_STATUS_RPT_SET_MACID(h2c_pkt, mac_id);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_update_wl_phy_info(struct rtw_dev *rtwdev)
{
struct rtw_traffic_stats *stats = &rtwdev->stats;
struct rtw_dm_info *dm_info = &rtwdev->dm_info;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_WL_PHY_INFO);
SET_WL_PHY_INFO_TX_TP(h2c_pkt, stats->tx_throughput);
SET_WL_PHY_INFO_RX_TP(h2c_pkt, stats->rx_throughput);
SET_WL_PHY_INFO_TX_RATE_DESC(h2c_pkt, dm_info->tx_rate);
SET_WL_PHY_INFO_RX_RATE_DESC(h2c_pkt, dm_info->curr_rx_rate);
SET_WL_PHY_INFO_RX_EVM(h2c_pkt, dm_info->rx_evm_dbm[RF_PATH_A]);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_beacon_filter_config(struct rtw_dev *rtwdev, bool connect,
struct ieee80211_vif *vif)
{
struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
struct ieee80211_sta *sta = ieee80211_find_sta(vif, bss_conf->bssid);
static const u8 rssi_min = 0, rssi_max = 100, rssi_offset = 100;
struct rtw_sta_info *si =
sta ? (struct rtw_sta_info *)sta->drv_priv : NULL;
s32 thold = RTW_DEFAULT_CQM_THOLD;
u32 hyst = RTW_DEFAULT_CQM_HYST;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_BCN_FILTER))
return;
if (bss_conf->cqm_rssi_thold)
thold = bss_conf->cqm_rssi_thold;
if (bss_conf->cqm_rssi_hyst)
hyst = bss_conf->cqm_rssi_hyst;
if (!connect) {
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_BCN_FILTER_OFFLOAD_P1);
SET_BCN_FILTER_OFFLOAD_P1_ENABLE(h2c_pkt, connect);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
return;
}
if (!si)
return;
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_BCN_FILTER_OFFLOAD_P0);
ether_addr_copy(&h2c_pkt[1], bss_conf->bssid);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
memset(h2c_pkt, 0, sizeof(h2c_pkt));
thold = clamp_t(s32, thold + rssi_offset, rssi_min, rssi_max);
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_BCN_FILTER_OFFLOAD_P1);
SET_BCN_FILTER_OFFLOAD_P1_ENABLE(h2c_pkt, connect);
SET_BCN_FILTER_OFFLOAD_P1_OFFLOAD_MODE(h2c_pkt,
BCN_FILTER_OFFLOAD_MODE_DEFAULT);
SET_BCN_FILTER_OFFLOAD_P1_THRESHOLD(h2c_pkt, thold);
SET_BCN_FILTER_OFFLOAD_P1_BCN_LOSS_CNT(h2c_pkt, BCN_LOSS_CNT);
SET_BCN_FILTER_OFFLOAD_P1_MACID(h2c_pkt, si->mac_id);
SET_BCN_FILTER_OFFLOAD_P1_HYST(h2c_pkt, hyst);
SET_BCN_FILTER_OFFLOAD_P1_BCN_INTERVAL(h2c_pkt, bss_conf->beacon_int);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_pwr_mode(struct rtw_dev *rtwdev)
{
struct rtw_lps_conf *conf = &rtwdev->lps_conf;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_SET_PWR_MODE);
SET_PWR_MODE_SET_MODE(h2c_pkt, conf->mode);
SET_PWR_MODE_SET_RLBM(h2c_pkt, conf->rlbm);
SET_PWR_MODE_SET_SMART_PS(h2c_pkt, conf->smart_ps);
SET_PWR_MODE_SET_AWAKE_INTERVAL(h2c_pkt, conf->awake_interval);
SET_PWR_MODE_SET_PORT_ID(h2c_pkt, conf->port_id);
SET_PWR_MODE_SET_PWR_STATE(h2c_pkt, conf->state);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_keep_alive_cmd(struct rtw_dev *rtwdev, bool enable)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
struct rtw_fw_wow_keep_alive_para mode = {
.adopt = true,
.pkt_type = KEEP_ALIVE_NULL_PKT,
.period = 5,
};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_KEEP_ALIVE);
SET_KEEP_ALIVE_ENABLE(h2c_pkt, enable);
SET_KEEP_ALIVE_ADOPT(h2c_pkt, mode.adopt);
SET_KEEP_ALIVE_PKT_TYPE(h2c_pkt, mode.pkt_type);
SET_KEEP_ALIVE_CHECK_PERIOD(h2c_pkt, mode.period);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_disconnect_decision_cmd(struct rtw_dev *rtwdev, bool enable)
{
struct rtw_wow_param *rtw_wow = &rtwdev->wow;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
struct rtw_fw_wow_disconnect_para mode = {
.adopt = true,
.period = 30,
.retry_count = 5,
};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_DISCONNECT_DECISION);
if (test_bit(RTW_WOW_FLAG_EN_DISCONNECT, rtw_wow->flags)) {
SET_DISCONNECT_DECISION_ENABLE(h2c_pkt, enable);
SET_DISCONNECT_DECISION_ADOPT(h2c_pkt, mode.adopt);
SET_DISCONNECT_DECISION_CHECK_PERIOD(h2c_pkt, mode.period);
SET_DISCONNECT_DECISION_TRY_PKT_NUM(h2c_pkt, mode.retry_count);
}
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_wowlan_ctrl_cmd(struct rtw_dev *rtwdev, bool enable)
{
struct rtw_wow_param *rtw_wow = &rtwdev->wow;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_WOWLAN);
SET_WOWLAN_FUNC_ENABLE(h2c_pkt, enable);
if (rtw_wow_mgd_linked(rtwdev)) {
if (test_bit(RTW_WOW_FLAG_EN_MAGIC_PKT, rtw_wow->flags))
SET_WOWLAN_MAGIC_PKT_ENABLE(h2c_pkt, enable);
if (test_bit(RTW_WOW_FLAG_EN_DISCONNECT, rtw_wow->flags))
SET_WOWLAN_DEAUTH_WAKEUP_ENABLE(h2c_pkt, enable);
if (test_bit(RTW_WOW_FLAG_EN_REKEY_PKT, rtw_wow->flags))
SET_WOWLAN_REKEY_WAKEUP_ENABLE(h2c_pkt, enable);
if (rtw_wow->pattern_cnt)
SET_WOWLAN_PATTERN_MATCH_ENABLE(h2c_pkt, enable);
}
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_aoac_global_info_cmd(struct rtw_dev *rtwdev,
u8 pairwise_key_enc,
u8 group_key_enc)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_AOAC_GLOBAL_INFO);
SET_AOAC_GLOBAL_INFO_PAIRWISE_ENC_ALG(h2c_pkt, pairwise_key_enc);
SET_AOAC_GLOBAL_INFO_GROUP_ENC_ALG(h2c_pkt, group_key_enc);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_remote_wake_ctrl_cmd(struct rtw_dev *rtwdev, bool enable)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_REMOTE_WAKE_CTRL);
SET_REMOTE_WAKECTRL_ENABLE(h2c_pkt, enable);
if (rtw_wow_no_link(rtwdev))
SET_REMOTE_WAKE_CTRL_NLO_OFFLOAD_EN(h2c_pkt, enable);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
static u8 rtw_get_rsvd_page_location(struct rtw_dev *rtwdev,
enum rtw_rsvd_packet_type type)
{
struct rtw_rsvd_page *rsvd_pkt;
u8 location = 0;
list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
if (type == rsvd_pkt->type)
location = rsvd_pkt->page;
}
return location;
}
void rtw_fw_set_nlo_info(struct rtw_dev *rtwdev, bool enable)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u8 loc_nlo;
loc_nlo = rtw_get_rsvd_page_location(rtwdev, RSVD_NLO_INFO);
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_NLO_INFO);
SET_NLO_FUN_EN(h2c_pkt, enable);
if (enable) {
if (rtw_get_lps_deep_mode(rtwdev) != LPS_DEEP_MODE_NONE)
SET_NLO_PS_32K(h2c_pkt, enable);
SET_NLO_IGNORE_SECURITY(h2c_pkt, enable);
SET_NLO_LOC_NLO_INFO(h2c_pkt, loc_nlo);
}
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_recover_bt_device(struct rtw_dev *rtwdev)
{
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RECOVER_BT_DEV);
SET_RECOVER_BT_DEV_EN(h2c_pkt, 1);
rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
}
void rtw_fw_set_pg_info(struct rtw_dev *rtwdev)
{
struct rtw_lps_conf *conf = &rtwdev->lps_conf;
u8 h2c_pkt[H2C_PKT_SIZE] = {0};