2 * Broadcom B43 wireless driver
3 * PPR (Power Per Rate) management
5 * Copyright (c) 2014 Rafał Miłecki <zajec5@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
21 #define ppr_for_each_entry(ppr, i, entry) \
22 for (i = 0, entry = &(ppr)->__all_rates[i]; \
23 i < B43_PPR_RATES_NUM; \
26 void b43_ppr_clear(struct b43_wldev
*dev
, struct b43_ppr
*ppr
)
28 memset(ppr
, 0, sizeof(*ppr
));
30 /* Compile-time PPR check */
31 BUILD_BUG_ON(sizeof(struct b43_ppr
) != B43_PPR_RATES_NUM
* sizeof(u8
));
34 void b43_ppr_add(struct b43_wldev
*dev
, struct b43_ppr
*ppr
, int diff
)
39 ppr_for_each_entry(ppr
, i
, rate
) {
40 *rate
= clamp_val(*rate
+ diff
, 0, 127);
44 void b43_ppr_apply_max(struct b43_wldev
*dev
, struct b43_ppr
*ppr
, u8 max
)
49 ppr_for_each_entry(ppr
, i
, rate
) {
50 *rate
= min(*rate
, max
);
54 void b43_ppr_apply_min(struct b43_wldev
*dev
, struct b43_ppr
*ppr
, u8 min
)
59 ppr_for_each_entry(ppr
, i
, rate
) {
60 *rate
= max(*rate
, min
);
64 u8
b43_ppr_get_max(struct b43_wldev
*dev
, struct b43_ppr
*ppr
)
70 ppr_for_each_entry(ppr
, i
, rate
) {
71 res
= max(*rate
, res
);
77 bool b43_ppr_load_max_from_sprom(struct b43_wldev
*dev
, struct b43_ppr
*ppr
,
80 struct b43_ppr_rates
*rates
= &ppr
->rates
;
81 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
82 struct b43_phy
*phy
= &dev
->phy
;
86 u8 extra_cdd_po
, extra_stbc_po
;
91 maxpwr
= min(sprom
->core_pwr_info
[0].maxpwr_2g
,
92 sprom
->core_pwr_info
[1].maxpwr_2g
);
93 sprom_ofdm_po
= sprom
->ofdm2gpo
;
94 sprom_mcs_po
= sprom
->mcs2gpo
;
95 extra_cdd_po
= (sprom
->cddpo
>> 0) & 0xf;
96 extra_stbc_po
= (sprom
->stbcpo
>> 0) & 0xf;
99 maxpwr
= min(sprom
->core_pwr_info
[0].maxpwr_5gl
,
100 sprom
->core_pwr_info
[1].maxpwr_5gl
);
101 sprom_ofdm_po
= sprom
->ofdm5glpo
;
102 sprom_mcs_po
= sprom
->mcs5glpo
;
103 extra_cdd_po
= (sprom
->cddpo
>> 8) & 0xf;
104 extra_stbc_po
= (sprom
->stbcpo
>> 8) & 0xf;
107 maxpwr
= min(sprom
->core_pwr_info
[0].maxpwr_5g
,
108 sprom
->core_pwr_info
[1].maxpwr_5g
);
109 sprom_ofdm_po
= sprom
->ofdm5gpo
;
110 sprom_mcs_po
= sprom
->mcs5gpo
;
111 extra_cdd_po
= (sprom
->cddpo
>> 4) & 0xf;
112 extra_stbc_po
= (sprom
->stbcpo
>> 4) & 0xf;
115 maxpwr
= min(sprom
->core_pwr_info
[0].maxpwr_5gh
,
116 sprom
->core_pwr_info
[1].maxpwr_5gh
);
117 sprom_ofdm_po
= sprom
->ofdm5ghpo
;
118 sprom_mcs_po
= sprom
->mcs5ghpo
;
119 extra_cdd_po
= (sprom
->cddpo
>> 12) & 0xf;
120 extra_stbc_po
= (sprom
->stbcpo
>> 12) & 0xf;
127 if (band
== B43_BAND_2G
) {
128 for (i
= 0; i
< 4; i
++) {
129 off
= ((sprom
->cck2gpo
>> (i
* 4)) & 0xf) * 2;
130 rates
->cck
[i
] = maxpwr
- off
;
135 for (i
= 0; i
< 8; i
++) {
136 off
= ((sprom_ofdm_po
>> (i
* 4)) & 0xf) * 2;
137 rates
->ofdm
[i
] = maxpwr
- off
;
141 rates
->mcs_20
[0] = rates
->ofdm
[0];
142 rates
->mcs_20
[1] = rates
->ofdm
[2];
143 rates
->mcs_20
[2] = rates
->ofdm
[3];
144 rates
->mcs_20
[3] = rates
->ofdm
[4];
145 rates
->mcs_20
[4] = rates
->ofdm
[5];
146 rates
->mcs_20
[5] = rates
->ofdm
[6];
147 rates
->mcs_20
[6] = rates
->ofdm
[7];
148 rates
->mcs_20
[7] = rates
->ofdm
[7];
151 for (i
= 0; i
< 4; i
++) {
152 off
= ((sprom_mcs_po
[0] >> (i
* 4)) & 0xf) * 2;
153 rates
->mcs_20_cdd
[i
] = maxpwr
- off
;
154 if (phy
->type
== B43_PHYTYPE_N
&& phy
->rev
>= 3)
155 rates
->mcs_20_cdd
[i
] -= extra_cdd_po
;
157 for (i
= 0; i
< 4; i
++) {
158 off
= ((sprom_mcs_po
[1] >> (i
* 4)) & 0xf) * 2;
159 rates
->mcs_20_cdd
[4 + i
] = maxpwr
- off
;
160 if (phy
->type
== B43_PHYTYPE_N
&& phy
->rev
>= 3)
161 rates
->mcs_20_cdd
[4 + i
] -= extra_cdd_po
;
165 rates
->ofdm_20_cdd
[0] = rates
->mcs_20_cdd
[0];
166 rates
->ofdm_20_cdd
[1] = rates
->mcs_20_cdd
[0];
167 rates
->ofdm_20_cdd
[2] = rates
->mcs_20_cdd
[1];
168 rates
->ofdm_20_cdd
[3] = rates
->mcs_20_cdd
[2];
169 rates
->ofdm_20_cdd
[4] = rates
->mcs_20_cdd
[3];
170 rates
->ofdm_20_cdd
[5] = rates
->mcs_20_cdd
[4];
171 rates
->ofdm_20_cdd
[6] = rates
->mcs_20_cdd
[5];
172 rates
->ofdm_20_cdd
[7] = rates
->mcs_20_cdd
[6];
175 for (i
= 0; i
< 4; i
++) {
176 off
= ((sprom_mcs_po
[0] >> (i
* 4)) & 0xf) * 2;
177 rates
->mcs_20_stbc
[i
] = maxpwr
- off
;
178 if (phy
->type
== B43_PHYTYPE_N
&& phy
->rev
>= 3)
179 rates
->mcs_20_stbc
[i
] -= extra_stbc_po
;
181 for (i
= 0; i
< 4; i
++) {
182 off
= ((sprom_mcs_po
[1] >> (i
* 4)) & 0xf) * 2;
183 rates
->mcs_20_stbc
[4 + i
] = maxpwr
- off
;
184 if (phy
->type
== B43_PHYTYPE_N
&& phy
->rev
>= 3)
185 rates
->mcs_20_stbc
[4 + i
] -= extra_stbc_po
;
189 for (i
= 0; i
< 4; i
++) {
190 off
= ((sprom_mcs_po
[2] >> (i
* 4)) & 0xf) * 2;
191 rates
->mcs_20_sdm
[i
] = maxpwr
- off
;
193 for (i
= 0; i
< 4; i
++) {
194 off
= ((sprom_mcs_po
[3] >> (i
* 4)) & 0xf) * 2;
195 rates
->mcs_20_sdm
[4 + i
] = maxpwr
- off
;