OSDN Git Service

Add rtl8821ce driver version 5.5.2
[android-x86/external-kernel-drivers.git] / rtl8821ce / hal / phydm / txbf / phydm_hal_txbf_api.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15
16 #include "mp_precomp.h"
17 #include "phydm_precomp.h"
18
19 #if (defined(CONFIG_BB_TXBF_API))
20 #if (RTL8822B_SUPPORT == 1 || RTL8192F_SUPPORT == 1 ||\
21         RTL8822C_SUPPORT == 1 || RTL8198F_SUPPORT == 1 || RTL8814B_SUPPORT == 1)
22 /*@Add by YuChen for 8822B MU-MIMO API*/
23
24 /*this function is only used for BFer*/
25 u8 phydm_get_ndpa_rate(void *dm_void)
26 {
27         struct dm_struct *dm = (struct dm_struct *)dm_void;
28         u8 ndpa_rate = ODM_RATE6M;
29
30         if (dm->rssi_min >= 30) /*@link RSSI > 30%*/
31                 ndpa_rate = ODM_RATE24M;
32         else if (dm->rssi_min <= 25)
33                 ndpa_rate = ODM_RATE6M;
34
35         PHYDM_DBG(dm, DBG_TXBF, "[%s] ndpa_rate = 0x%x\n", __func__, ndpa_rate);
36
37         return ndpa_rate;
38 }
39
40 /*this function is only used for BFer*/
41 u8 phydm_get_beamforming_sounding_info(void *dm_void, u16 *throughput,
42                                        u8 total_bfee_num, u8 *tx_rate)
43 {
44         u8 idx = 0;
45         u8 snddecision = 0xff;
46         struct dm_struct *dm = (struct dm_struct *)dm_void;
47
48         for (idx = 0; idx < total_bfee_num; idx++) {
49                 if (dm->support_ic_type & (ODM_RTL8814A)) {
50                         if ((tx_rate[idx] >= ODM_RATEVHTSS3MCS7 &&
51                              tx_rate[idx] <= ODM_RATEVHTSS3MCS9))
52                                 snddecision = snddecision & ~(1 << idx);
53                 } else if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8822C |
54                            ODM_RTL8812 | ODM_RTL8192F)) {
55                         if ((tx_rate[idx] >= ODM_RATEVHTSS2MCS7 &&
56                              tx_rate[idx] <= ODM_RATEVHTSS2MCS9))
57                                 snddecision = snddecision & ~(1 << idx);
58                 } else if (dm->support_ic_type & (ODM_RTL8814B)) {
59                         if ((tx_rate[idx] >= ODM_RATEVHTSS4MCS7 &&
60                              tx_rate[idx] <= ODM_RATEVHTSS4MCS9))
61                                 snddecision = snddecision & ~(1 << idx);
62                 }
63         }
64
65         for (idx = 0; idx < total_bfee_num; idx++) {
66                 if (throughput[idx] <= 10)
67                         snddecision = snddecision & ~(1 << idx);
68         }
69
70         PHYDM_DBG(dm, DBG_TXBF, "[%s] soundingdecision = 0x%x\n", __func__,
71                   snddecision);
72
73         return snddecision;
74 }
75
76 /*this function is only used for BFer*/
77 u8 phydm_get_mu_bfee_snding_decision(void *dm_void, u16 throughput)
78 {
79         u8 snding_score = 0;
80         struct dm_struct *dm = (struct dm_struct *)dm_void;
81
82         /*throughput unit is Mbps*/
83         if (throughput >= 500)
84                 snding_score = 100;
85         else if (throughput >= 450)
86                 snding_score = 90;
87         else if (throughput >= 400)
88                 snding_score = 80;
89         else if (throughput >= 350)
90                 snding_score = 70;
91         else if (throughput >= 300)
92                 snding_score = 60;
93         else if (throughput >= 250)
94                 snding_score = 50;
95         else if (throughput >= 200)
96                 snding_score = 40;
97         else if (throughput >= 150)
98                 snding_score = 30;
99         else if (throughput >= 100)
100                 snding_score = 20;
101         else if (throughput >= 50)
102                 snding_score = 10;
103         else
104                 snding_score = 0;
105
106         PHYDM_DBG(dm, DBG_TXBF, "[%s] snding_score = 0x%x\n", __func__,
107                   snding_score);
108
109         return snding_score;
110 }
111
112 #endif
113 #if (DM_ODM_SUPPORT_TYPE != ODM_AP)
114 u8 beamforming_get_htndp_tx_rate(void *dm_void, u8 bfer_str_num)
115 {
116         struct dm_struct *dm = (struct dm_struct *)dm_void;
117         u8 nr_index = 0;
118         u8 ndp_tx_rate;
119 /*@Find nr*/
120 #if (RTL8814A_SUPPORT == 1)
121         if (dm->support_ic_type & ODM_RTL8814A)
122                 nr_index = tx_bf_nr(hal_txbf_8814a_get_ntx(dm), bfer_str_num);
123         else
124 #endif
125                 nr_index = tx_bf_nr(1, bfer_str_num);
126
127         switch (nr_index) {
128         case 1:
129                 ndp_tx_rate = ODM_MGN_MCS8;
130                 break;
131
132         case 2:
133                 ndp_tx_rate = ODM_MGN_MCS16;
134                 break;
135
136         case 3:
137                 ndp_tx_rate = ODM_MGN_MCS24;
138                 break;
139
140         default:
141                 ndp_tx_rate = ODM_MGN_MCS8;
142                 break;
143         }
144
145         return ndp_tx_rate;
146 }
147
148 u8 beamforming_get_vht_ndp_tx_rate(void *dm_void, u8 bfer_str_num)
149 {
150         struct dm_struct *dm = (struct dm_struct *)dm_void;
151         u8 nr_index = 0;
152         u8 ndp_tx_rate;
153 /*@Find nr*/
154 #if (RTL8814A_SUPPORT == 1)
155         if (dm->support_ic_type & ODM_RTL8814A)
156                 nr_index = tx_bf_nr(hal_txbf_8814a_get_ntx(dm), bfer_str_num);
157         else
158 #endif
159                 nr_index = tx_bf_nr(1, bfer_str_num);
160
161         switch (nr_index) {
162         case 1:
163                 ndp_tx_rate = ODM_MGN_VHT2SS_MCS0;
164                 break;
165
166         case 2:
167                 ndp_tx_rate = ODM_MGN_VHT3SS_MCS0;
168                 break;
169
170         case 3:
171                 ndp_tx_rate = ODM_MGN_VHT4SS_MCS0;
172                 break;
173
174         default:
175                 ndp_tx_rate = ODM_MGN_VHT2SS_MCS0;
176                 break;
177         }
178
179         return ndp_tx_rate;
180 }
181 #endif
182
183 #endif