hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
/******************************************************************************
 *
 * Copyright(c) 2019 Realtek Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 ******************************************************************************/
 
#include "mcc.h"
 
u32 mac_reset_mcc_group(struct mac_ax_adapter *adapter, u8 group)
{
   struct fwcmd_reset_mcc_group *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (adapter->sm.mcc_group[group] != MAC_AX_MCC_STATE_ERROR) {
       PLTFM_MSG_ERR("[ERR]%s: state != error\n", __func__);
       return MACPROCERR;
   }
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   adapter->sm.mcc_group[group] = MAC_AX_MCC_STATE_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_reset_mcc_group));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_reset_mcc_group *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_RESET_MCC_GROUP_GROUP));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_RESET_MCC_GROUP, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_reset_mcc_request(struct mac_ax_adapter *adapter, u8 group)
{
   if (adapter->sm.mcc_request[group] != MAC_AX_MCC_REQ_FAIL) {
       PLTFM_MSG_ERR("[ERR]%s: state != req fail\n", __func__);
       return MACPROCERR;
   }
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   adapter->sm.mcc_request[group] = MAC_AX_MCC_REQ_IDLE;
 
   return MACSUCCESS;
}
 
u32 mac_add_mcc(struct mac_ax_adapter *adapter, struct mac_ax_mcc_role *info)
{
   struct fwcmd_add_mcc *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (!(adapter->sm.mcc_group[info->group] == MAC_AX_MCC_EMPTY ||
         adapter->sm.mcc_group[info->group] == MAC_AX_MCC_ADD_DONE)) {
       PLTFM_MSG_ERR("[ERR]%s: state != empty or add done\n",
                 __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_group[info->group] = MAC_AX_MCC_STATE_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_add_mcc));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_add_mcc *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(info->macid, FWCMD_H2C_ADD_MCC_MACID) |
           SET_WORD(info->central_ch_seg0,
                FWCMD_H2C_ADD_MCC_CENTRAL_CH_SEG0) |
           SET_WORD(info->central_ch_seg1,
                FWCMD_H2C_ADD_MCC_CENTRAL_CH_SEG1) |
           SET_WORD(info->primary_ch, FWCMD_H2C_ADD_MCC_PRIMARY_CH));
 
   ptr->dword1 =
   cpu_to_le32((info->dis_tx_null ? FWCMD_H2C_ADD_MCC_DIS_TX_NULL : 0) |
           (info->dis_sw_retry ? FWCMD_H2C_ADD_MCC_DIS_SW_RETRY : 0) |
           (info->in_curr_ch ? FWCMD_H2C_ADD_MCC_IN_CURR_CH : 0) |
           SET_WORD(info->bandwidth, FWCMD_H2C_ADD_MCC_BANDWIDTH) |
           SET_WORD(info->group, FWCMD_H2C_ADD_MCC_GROUP) |
           SET_WORD(info->c2h_rpt, FWCMD_H2C_ADD_MCC_C2H_RPT) |
           SET_WORD(info->sw_retry_count,
                FWCMD_H2C_ADD_MCC_SW_RETRY_COUNT) |
           SET_WORD(info->tx_null_early,
                FWCMD_H2C_ADD_MCC_TX_NULL_EARLY) |
           (info->btc_in_2g ? FWCMD_H2C_ADD_MCC_BTC_IN_2G : 0) |
           (info->pta_en ? FWCMD_H2C_ADD_MCC_PTA_EN : 0) |
           (info->rfk_by_pass ? FWCMD_H2C_ADD_MCC_RFK_BY_PASS : 0));
 
   ptr->dword2 =
   cpu_to_le32(SET_WORD(info->duration, FWCMD_H2C_ADD_MCC_DURATION));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_ADD_MCC, 0, 0);
 
   ptr->dword3 =
   cpu_to_le32((info->courtesy_en ? FWCMD_H2C_ADD_MCC_COURTESY_EN : 0) |
           SET_WORD(info->courtesy_num,
                FWCMD_H2C_ADD_MCC_COURTESY_NUM) |
           SET_WORD(info->courtesy_target,
                FWCMD_H2C_ADD_MCC_COURTESY_TARGET));
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_start_mcc(struct mac_ax_adapter *adapter,
         struct mac_ax_mcc_start *info)
{
   struct fwcmd_start_mcc *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
   u32 group = info->group;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, info->group);
       return MACNOITEM;
   }
 
   if (adapter->sm.mcc_group[info->group] != MAC_AX_MCC_ADD_DONE) {
       PLTFM_MSG_ERR("[ERR]%s: state != add done\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_group[info->group] = MAC_AX_MCC_STATE_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_start_mcc));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_start_mcc *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(info->group, FWCMD_H2C_START_MCC_GROUP) |
           (info->btc_in_group ? FWCMD_H2C_START_MCC_BTC_IN_GROUP : 0) |
           SET_WORD(info->old_group_action,
                FWCMD_H2C_START_MCC_OLD_GROUP_ACTION) |
           SET_WORD(info->old_group, FWCMD_H2C_START_MCC_OLD_GROUP) |
           SET_WORD(info->macid, FWCMD_H2C_START_MCC_MACID));
 
   ptr->dword1 =
   cpu_to_le32(SET_WORD(info->tsf_low, FWCMD_H2C_START_MCC_TSF_LOW));
 
   ptr->dword2 =
   cpu_to_le32(SET_WORD(info->tsf_high, FWCMD_H2C_START_MCC_TSF_HIGH));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_START_MCC, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_stop_mcc(struct mac_ax_adapter *adapter, u8 group, u8 macid,
        u8 prev_groups)
{
   struct fwcmd_stop_mcc *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   if (adapter->sm.mcc_group[group] != MAC_AX_MCC_START_DONE) {
       PLTFM_MSG_ERR("[ERR]%s: state != start done\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_group[group] = MAC_AX_MCC_STATE_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_stop_mcc));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_stop_mcc *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_STOP_MCC_GROUP) |
           SET_WORD(macid, FWCMD_H2C_STOP_MCC_MACID) |
           (prev_groups ? FWCMD_H2C_STOP_MCC_PREV_GROUPS : 0));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_STOP_MCC, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_del_mcc_group(struct mac_ax_adapter *adapter, u8 group,
             u8 prev_groups)
{
   struct fwcmd_del_mcc_group *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   if (!(adapter->sm.mcc_group[group] == MAC_AX_MCC_ADD_DONE ||
         adapter->sm.mcc_group[group] == MAC_AX_MCC_STOP_DONE)) {
       PLTFM_MSG_ERR("[ERR]%s: state != add or stop done\n",
                 __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_group[group] = MAC_AX_MCC_STATE_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_del_mcc_group));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_del_mcc_group *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_DEL_MCC_GROUP_GROUP) |
           (prev_groups ? FWCMD_H2C_DEL_MCC_GROUP_PREV_GROUPS : 0));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_DEL_MCC_GROUP, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_mcc_request_tsf(struct mac_ax_adapter *adapter, u8 group,
           u8 macid_x, u8 macid_y)
{
   struct fwcmd_mcc_req_tsf *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   if (adapter->sm.mcc_request[group] != MAC_AX_MCC_REQ_IDLE) {
       PLTFM_MSG_ERR("[ERR]%s: state != req idle\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_request[group] = MAC_AX_MCC_REQ_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_mcc_req_tsf));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_mcc_req_tsf *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_MCC_REQ_TSF_GROUP) |
           SET_WORD(macid_x, FWCMD_H2C_MCC_REQ_TSF_MACID_X) |
           SET_WORD(macid_y, FWCMD_H2C_MCC_REQ_TSF_MACID_Y));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_MCC_REQ_TSF, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err: %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_mcc_macid_bitmap(struct mac_ax_adapter *adapter, u8 group,
            u8 macid, u8 *bitmap, u8 len)
{
   struct fwcmd_mcc_macid_bitmap *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   if (adapter->sm.mcc_request[group] != MAC_AX_MCC_REQ_IDLE) {
       PLTFM_MSG_ERR("[ERR]%s: state != req idle\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_request[group] = MAC_AX_MCC_REQ_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, len + 4);
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_mcc_macid_bitmap *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_MCC_MACID_BITMAP_GROUP) |
           SET_WORD(macid, FWCMD_H2C_MCC_MACID_BITMAP_MACID) |
           SET_WORD(len, FWCMD_H2C_MCC_MACID_BITMAP_BITMAP_LENGTH));
 
   PLTFM_MEMCPY((u8 *)ptr + sizeof(u32), bitmap, len);
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_MCC_MACID_BITMAP, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx error %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_mcc_sync_enable(struct mac_ax_adapter *adapter, u8 group,
           u8 source, u8 target, u8 offset)
{
   struct fwcmd_mcc_sync *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   if (adapter->sm.mcc_request[group] != MAC_AX_MCC_REQ_IDLE) {
       PLTFM_MSG_ERR("[ERR]%s: state != req idle\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_request[group] = MAC_AX_MCC_REQ_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_mcc_sync));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_mcc_sync *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(group, FWCMD_H2C_MCC_SYNC_GROUP) |
           SET_WORD(source, FWCMD_H2C_MCC_SYNC_MACID_SOURCE) |
           SET_WORD(target, FWCMD_H2C_MCC_SYNC_MACID_TARGET) |
           SET_WORD(offset, FWCMD_H2C_MCC_SYNC_SYNC_OFFSET));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_MCC_SYNC, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx error %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_mcc_set_duration(struct mac_ax_adapter *adapter,
            struct mac_ax_mcc_duration_info *info)
{
   struct fwcmd_mcc_set_duration *ptr;
   #if MAC_AX_PHL_H2C
   struct rtw_h2c_pkt *h2cb;
   #else
   struct h2c_buf *h2cb;
   #endif
   u8 *buf;
   u32 ret = 0;
 
   if (adapter->sm.mcc_request[info->group] != MAC_AX_MCC_REQ_IDLE) {
       PLTFM_MSG_ERR("[ERR]%s: state != req idle\n", __func__);
       return MACPROCERR;
   }
 
   adapter->sm.mcc_request[info->group] = MAC_AX_MCC_REQ_H2C_SENT;
 
   h2cb = h2cb_alloc(adapter, H2CB_CLASS_DATA);
   if (!h2cb) {
       PLTFM_MSG_ERR("[ERR]%s: H2C alloc fail\n", __func__);
       return MACNPTR;
   }
 
   buf = h2cb_put(h2cb, sizeof(struct fwcmd_mcc_set_duration));
   if (!buf) {
       PLTFM_MSG_ERR("[ERR]%s: H2C put fail\n", __func__);
       ret = MACNOBUF;
       goto fail;
   }
 
   ptr = (struct fwcmd_mcc_set_duration *)buf;
   ptr->dword0 =
   cpu_to_le32(SET_WORD(info->group, FWCMD_H2C_MCC_SET_DURATION_GROUP) |
           (info->btc_in_group ?
            FWCMD_H2C_MCC_SET_DURATION_BTC_IN_GROUP : 0) |
           SET_WORD(info->start_macid,
                FWCMD_H2C_MCC_SET_DURATION_START_MACID) |
           SET_WORD(info->macid_x,
                FWCMD_H2C_MCC_SET_DURATION_MACID_X) |
           SET_WORD(info->macid_y,
                FWCMD_H2C_MCC_SET_DURATION_MACID_Y));
   ptr->dword1 =
   cpu_to_le32(SET_WORD(info->start_tsf_low,
                FWCMD_H2C_MCC_SET_DURATION_START_TSF_LOW));
 
   ptr->dword2 =
   cpu_to_le32(SET_WORD(info->start_tsf_high,
                FWCMD_H2C_MCC_SET_DURATION_START_TSF_HIGH));
 
   ptr->dword3 =
   cpu_to_le32(SET_WORD(info->duration_x,
                FWCMD_H2C_MCC_SET_DURATION_DURATION_X));
 
   ptr->dword4 =
   cpu_to_le32(SET_WORD(info->duration_y,
                FWCMD_H2C_MCC_SET_DURATION_DURATION_Y));
 
   ret = h2c_pkt_set_hdr(adapter, h2cb,
                 FWCMD_TYPE_H2C, FWCMD_H2C_CAT_MAC,
                 FWCMD_H2C_CL_MCC,
                 FWCMD_H2C_FUNC_MCC_SET_DURATION, 0, 0);
 
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Set H2C HDR fail\n", __func__);
       goto fail;
   }
 
   ret = h2c_pkt_build_txd(adapter, h2cb);
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: Build H2C TXD fail\n", __func__);
       goto fail;
   }
 
   #if MAC_AX_PHL_H2C
   ret = PLTFM_TX(h2cb);
   #else
   ret = PLTFM_TX(h2cb->data, h2cb->len);
   #endif
   if (ret) {
       PLTFM_MSG_ERR("[ERR]%s: platform tx err %d\n", __func__, ret);
       goto fail;
   }
 
   h2cb_free(adapter, h2cb);
 
   return MACSUCCESS;
fail:
   h2cb_free(adapter, h2cb);
 
   return ret;
}
 
u32 mac_get_mcc_status_rpt(struct mac_ax_adapter *adapter,
              u8 group, u8 *status, u32 *tsf_high, u32 *tsf_low)
{
   struct mac_ax_mcc_group_info *mcc_info = &adapter->mcc_group_info;
 
   if (adapter->sm.mcc_group[group] == MAC_AX_MCC_EMPTY) {
       PLTFM_MSG_ERR("[ERR]%s: state = empty\n", __func__);
       return MACPROCERR;
   }
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   *status = mcc_info->groups[group].rpt_status;
   PLTFM_MSG_TRACE("[TRACE]%s: mcc status: %d\n", __func__, *status);
 
   *tsf_high = mcc_info->groups[group].rpt_tsf_high;
   *tsf_low = mcc_info->groups[group].rpt_tsf_low;
 
   PLTFM_MSG_TRACE("[TRACE]%s: report tsf_high: 0x%x\n",
           __func__, *tsf_high);
   PLTFM_MSG_TRACE("[TRACE]%s: report tsf_low: 0x%x\n",
           __func__, *tsf_low);
 
   return MACSUCCESS;
}
 
u32 mac_get_mcc_tsf_rpt(struct mac_ax_adapter *adapter, u8 group,
           u32 *tsf_x_high, u32 *tsf_x_low,
           u32 *tsf_y_high, u32 *tsf_y_low)
{
   struct mac_ax_mcc_group_info *mcc_info = &adapter->mcc_group_info;
 
   if (group > MCC_GROUP_ID_MAX) {
       PLTFM_MSG_ERR("[ERR]%s: invalid group: %d\n", __func__, group);
       return MACNOITEM;
   }
 
   *tsf_x_high = mcc_info->groups[group].tsf_x_high;
   *tsf_x_low = mcc_info->groups[group].tsf_x_low;
   PLTFM_MSG_TRACE("[TRACE]%s: tsf_x_high: 0x%x\n", __func__, *tsf_x_high);
   PLTFM_MSG_TRACE("[TRACE]%s: tsf_x_low: 0x%x\n", __func__, *tsf_x_low);
 
   *tsf_y_high = mcc_info->groups[group].tsf_y_high;
   *tsf_y_low += mcc_info->groups[group].tsf_y_low;
   PLTFM_MSG_TRACE("[TRACE]%s: tsf_y_high: 0x%x\n", __func__, *tsf_y_high);
   PLTFM_MSG_TRACE("[TRACE]%s: tsf_y_low: 0x%x\n", __func__, *tsf_y_low);
 
   adapter->sm.mcc_request[group] = MAC_AX_MCC_REQ_IDLE;
 
   return MACSUCCESS;
}
 
u32 mac_get_mcc_group(struct mac_ax_adapter *adapter, u8 *pget_group)
{
   struct mac_ax_state_mach *sm = &adapter->sm;
   u8 group_idx;
 
   for (group_idx = 0; group_idx <= MCC_GROUP_ID_MAX; group_idx++) {
       if (sm->mcc_group[group_idx] == MAC_AX_MCC_EMPTY) {
           *pget_group = group_idx;
           PLTFM_MSG_TRACE("[TRACE]%s: get mcc empty group %u\n",
                   __func__, *pget_group);
           return MACSUCCESS;
       }
   }
   return MACMCCGPFL;
}
 
u32 mac_check_add_mcc_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_group[group] == MAC_AX_MCC_ADD_DONE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_start_mcc_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_group[group] == MAC_AX_MCC_START_DONE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_stop_mcc_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_group[group] == MAC_AX_MCC_STOP_DONE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_del_mcc_group_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_group[group] == MAC_AX_MCC_EMPTY)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_mcc_request_tsf_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_request[group] == MAC_AX_MCC_REQ_DONE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_mcc_macid_bitmap_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_request[group] == MAC_AX_MCC_REQ_IDLE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_mcc_sync_enable_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_request[group] == MAC_AX_MCC_REQ_IDLE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}
 
u32 mac_check_mcc_set_duration_done(struct mac_ax_adapter *adapter, u8 group)
{
   PLTFM_MSG_TRACE("[TRACE]%s: group %d curr state: %d\n", __func__,
           group, adapter->sm.mcc_group[group]);
 
   if (adapter->sm.mcc_request[group] == MAC_AX_MCC_REQ_IDLE)
       return MACSUCCESS;
   else
       return MACPROCBUSY;
}