Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Tim Wawrzynczak | d40a4c2 | 2021-02-25 13:14:49 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen_pci.h> |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <sar.h> |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 9 | #include <stdlib.h> |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 10 | #include <wrdd.h> |
| 11 | |
| 12 | #include "chip.h" |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 13 | #include "wifi.h" |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 14 | #include "wifi_private.h" |
| 15 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 16 | /* WIFI Domain type */ |
| 17 | #define DOMAIN_TYPE_WIFI 0x7 |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 18 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 19 | /* Maximum number DSM UUID bifurcations in _DSM */ |
| 20 | #define MAX_DSM_FUNCS 2 |
| 21 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 22 | /* |
| 23 | * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0' |
| 24 | * The above representation returns unique and consistent name every time |
| 25 | * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is |
| 26 | * chosen since it contains the bus address of the device. |
| 27 | */ |
| 28 | #define WIFI_ACPI_NAME_MAX_LEN 5 |
| 29 | |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 30 | /* Unique ID for the WIFI _DSM */ |
| 31 | #define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE" |
| 32 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 33 | /* Unique ID for CnviDdrRfim entry in WIFI _DSM */ |
| 34 | #define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD" |
| 35 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 36 | __weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 37 | { |
| 38 | return -1; |
| 39 | } |
| 40 | |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 41 | /* |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 42 | * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD |
| 43 | * Channels: 149, 153, 157, 161, 165 |
| 44 | * 0 - ETSI 5.8GHz SRD active scan |
| 45 | * 1 - ETSI 5.8GHz SRD passive scan |
| 46 | * 2 - ETSI 5.8GHz SRD disabled |
| 47 | */ |
| 48 | static void wifi_dsm_srd_active_channels(void *args) |
| 49 | { |
| 50 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 51 | |
| 52 | acpigen_write_return_integer(dsm_config->disable_active_sdr_channels); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Function 2 : Supported Indonesia 5.15-5.35 GHz Band |
| 57 | * 0 - Set 5.115-5.35GHz to Disable in Indonesia |
| 58 | * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia |
| 59 | * 2 - Reserved |
| 60 | */ |
| 61 | static void wifi_dsm_indonasia_5Ghz_band_enable(void *args) |
| 62 | { |
| 63 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 64 | |
| 65 | acpigen_write_return_integer(dsm_config->support_indonesia_5g_band); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz. |
| 70 | * Bit 0: |
| 71 | * 0 - No override; use device settings 0 |
| 72 | * 1 - Force disable all countries that are not defined in the following bits |
| 73 | * |
| 74 | * Bit 1: |
| 75 | * 0 No override; USA 6GHz disable 0 |
| 76 | * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA) |
| 77 | */ |
| 78 | static void wifi_dsm_supported_ultra_high_band(void *args) |
| 79 | { |
| 80 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 81 | |
| 82 | acpigen_write_return_integer(dsm_config->support_ultra_high_band); |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Function 4: Regulatory Special Configurations Enablements |
| 87 | */ |
| 88 | static void wifi_dsm_regulatory_configurations(void *args) |
| 89 | { |
| 90 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 91 | |
| 92 | acpigen_write_return_integer(dsm_config->regulatory_configurations); |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Function 5: M.2 UART Interface Configuration |
| 97 | */ |
| 98 | static void wifi_dsm_uart_configurations(void *args) |
| 99 | { |
| 100 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 101 | |
| 102 | acpigen_write_return_integer(dsm_config->uart_configurations); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Function 6: Control Enablement 11ax on certificated modules |
| 107 | * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification |
| 108 | * 0 - None. Work with Wi-Fi FW/OTP definitions [Default] |
| 109 | * 1 - Apply changes. |
| 110 | * |
| 111 | * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1 |
| 112 | * 0 - Disable 11Ax on country Ukraine [Default] |
| 113 | * 1 - Enable 11Ax on country Ukraine |
| 114 | * |
| 115 | * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification |
| 116 | * 0 - None. Work with Wi-Fi FW/OTP definitions [Default] |
| 117 | * 1 - Apply changes. |
| 118 | * |
| 119 | * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1 |
| 120 | * 0 - Disable 11Ax on country Russia [Default] |
| 121 | * 1 - Enable 11Ax on country Russia |
| 122 | * |
| 123 | * Bit 31:04 - Reserved |
| 124 | * |
| 125 | * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions |
| 126 | */ |
| 127 | static void wifi_dsm_ukrane_russia_11ax_enable(void *args) |
| 128 | { |
| 129 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 130 | |
| 131 | acpigen_write_return_integer(dsm_config->enablement_11ax); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Function 7: Control Enablement UNII-4 over certificate modules |
| 136 | */ |
| 137 | static void wifi_dsm_unii4_control_enable(void *args) |
| 138 | { |
| 139 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 140 | |
| 141 | acpigen_write_return_integer(dsm_config->unii_4); |
| 142 | } |
| 143 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 144 | static void wifi_dsm_ddrrfim_func3_cb(void *ptr) |
| 145 | { |
| 146 | const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr; |
| 147 | acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 1 : 0); |
| 148 | } |
| 149 | |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 150 | static void (*wifi_dsm_callbacks[])(void *) = { |
| 151 | NULL, /* Function 0 */ |
| 152 | wifi_dsm_srd_active_channels, /* Function 1 */ |
| 153 | wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */ |
| 154 | wifi_dsm_supported_ultra_high_band, /* Function 3 */ |
| 155 | wifi_dsm_regulatory_configurations, /* Function 4 */ |
| 156 | wifi_dsm_uart_configurations, /* Function 5 */ |
| 157 | wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */ |
| 158 | wifi_dsm_unii4_control_enable, /* Function 7 */ |
| 159 | }; |
| 160 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 161 | /* |
| 162 | * The current DSM2 table is only exporting one function (function 3), some more |
| 163 | * functions are reserved so marking them NULL. |
| 164 | */ |
| 165 | static void (*wifi_dsm2_callbacks[])(void *) = { |
| 166 | NULL, /* Function 0 */ |
| 167 | NULL, /* Function 1 */ |
| 168 | NULL, /* Function 2 */ |
| 169 | wifi_dsm_ddrrfim_func3_cb, /* Function 3 */ |
| 170 | }; |
| 171 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 172 | static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 173 | { |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 174 | const uint8_t *sar_table = &sar->sar_table[0]; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 175 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 176 | return sar_table + (sar->chains_count * sar->subbands_count * set_num); |
| 177 | } |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 178 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 179 | static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num) |
| 180 | { |
| 181 | const uint8_t *wgds_table = &wgds->wgds_table[0]; |
| 182 | |
| 183 | return wgds_table + (wgds->bands_count * set_num); |
| 184 | } |
| 185 | |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 186 | static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num) |
| 187 | { |
| 188 | const uint8_t *ppag_table = &ppag->ppag_table[0]; |
| 189 | |
| 190 | return ppag_table + (ppag->bands_count * set_num); |
| 191 | } |
| 192 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 193 | static void sar_emit_wrds(const struct sar_profile *sar) |
| 194 | { |
| 195 | int i; |
| 196 | size_t package_size, table_size; |
| 197 | const uint8_t *set; |
| 198 | |
| 199 | if (sar == NULL) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 200 | return; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * Name ("WRDS", Package () { |
| 204 | * Revision, |
| 205 | * Package () { |
| 206 | * Domain Type, // 0x7:WiFi |
| 207 | * WiFi SAR BIOS, // BIOS SAR Enable/disable |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 208 | * SAR Table Set // Set#1 of SAR Table |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 209 | * } |
| 210 | * }) |
| 211 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 212 | if (sar->revision > MAX_SAR_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 213 | printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 214 | return; |
| 215 | } |
| 216 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 217 | acpigen_write_name("WRDS"); |
| 218 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 219 | acpigen_write_dword(sar->revision); |
| 220 | |
| 221 | table_size = sar->chains_count * sar->subbands_count; |
| 222 | /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */ |
| 223 | package_size = 1 + 1 + table_size; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 224 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 225 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 226 | acpigen_write_dword(1); |
| 227 | |
| 228 | set = sar_fetch_set(sar, 0); |
| 229 | for (i = 0; i < table_size; i++) |
| 230 | acpigen_write_byte(set[i]); |
| 231 | |
| 232 | acpigen_write_package_end(); |
| 233 | acpigen_write_package_end(); |
| 234 | } |
| 235 | |
| 236 | static void sar_emit_ewrd(const struct sar_profile *sar) |
| 237 | { |
| 238 | int i; |
| 239 | size_t package_size, set_num, table_size; |
| 240 | const uint8_t *set; |
| 241 | |
| 242 | if (sar == NULL) |
| 243 | return; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Name ("EWRD", Package () { |
| 247 | * Revision, |
| 248 | * Package () { |
| 249 | * Domain Type, // 0x7:WiFi |
| 250 | * Dynamic SAR Enable, // Dynamic SAR Enable/disable |
| 251 | * Extended SAR sets, // Number of optional SAR table sets |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 252 | * SAR Table Set, // Set#2 of SAR Table |
| 253 | * SAR Table Set, // Set#3 of SAR Table |
| 254 | * SAR Table Set // Set#4 of SAR Table |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 255 | * } |
| 256 | * }) |
| 257 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 258 | if (sar->revision > MAX_SAR_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 259 | printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
| 263 | if (sar->dsar_set_count == 0) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 264 | printk(BIOS_WARNING, "DSAR set count is 0\n"); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 268 | acpigen_write_name("EWRD"); |
| 269 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 270 | acpigen_write_dword(sar->revision); |
| 271 | |
| 272 | table_size = sar->chains_count * sar->subbands_count; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 273 | /* |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 274 | * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count' |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 275 | * + number of bytes for Set#2 & 3 & 4 |
| 276 | */ |
Matt Chen | 07e6b5f | 2021-11-04 18:13:25 +0800 | [diff] [blame] | 277 | package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 278 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 279 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 280 | acpigen_write_dword(1); |
| 281 | acpigen_write_dword(sar->dsar_set_count); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 282 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 283 | for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) { |
| 284 | set = sar_fetch_set(sar, set_num); |
| 285 | for (i = 0; i < table_size; i++) |
| 286 | acpigen_write_byte(set[i]); |
| 287 | } |
| 288 | |
| 289 | /* wifi driver always expects 3 DSAR sets */ |
| 290 | for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++) |
| 291 | acpigen_write_byte(0); |
| 292 | |
| 293 | acpigen_write_package_end(); |
| 294 | acpigen_write_package_end(); |
| 295 | } |
| 296 | |
| 297 | static void sar_emit_wgds(struct geo_profile *wgds) |
| 298 | { |
| 299 | int i; |
| 300 | size_t package_size, set_num; |
| 301 | const uint8_t *set; |
| 302 | |
| 303 | if (wgds == NULL) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 304 | return; |
| 305 | |
| 306 | /* |
| 307 | * Name ("WGDS", Package() { |
| 308 | * Revision, |
| 309 | * Package() { |
| 310 | * DomainType, // 0x7:WiFi |
| 311 | * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max |
| 312 | * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset |
| 313 | * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset |
| 314 | * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max |
| 315 | * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset |
| 316 | * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 317 | * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max |
| 318 | * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset |
| 319 | * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 320 | * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max |
| 321 | * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset |
| 322 | * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset |
| 323 | * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max |
| 324 | * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset |
| 325 | * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 326 | * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max |
| 327 | * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset |
| 328 | * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 329 | * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max |
| 330 | * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset |
| 331 | * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset |
| 332 | * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max |
| 333 | * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset |
| 334 | * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 335 | * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max |
| 336 | * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset |
| 337 | * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 338 | * } |
| 339 | * }) |
| 340 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 341 | if (wgds->revision > MAX_GEO_OFFSET_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 342 | printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 343 | return; |
| 344 | } |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 345 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 346 | package_size = 1 + wgds->chains_count * wgds->bands_count; |
| 347 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 348 | acpigen_write_name("WGDS"); |
| 349 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 350 | acpigen_write_dword(wgds->revision); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 351 | /* Emit 'Domain Type' + |
| 352 | * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS) |
| 353 | */ |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 354 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 355 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 356 | |
| 357 | for (set_num = 0; set_num < wgds->chains_count; set_num++) { |
| 358 | set = wgds_fetch_set(wgds, set_num); |
| 359 | for (i = 0; i < wgds->bands_count; i++) |
| 360 | acpigen_write_byte(set[i]); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 363 | acpigen_write_package_end(); |
| 364 | acpigen_write_package_end(); |
| 365 | } |
| 366 | |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 367 | static void sar_emit_ppag(struct gain_profile *ppag) |
| 368 | { |
| 369 | int i; |
| 370 | size_t package_size, set_num; |
| 371 | const uint8_t *set; |
| 372 | |
| 373 | if (ppag == NULL) |
| 374 | return; |
| 375 | |
| 376 | /* |
| 377 | * Name ("PPAG", Package () { |
| 378 | * Revision, |
| 379 | * Package () { |
| 380 | * Domain Type, // 0x7:WiFi |
| 381 | * PPAG Mode, // Defines the mode of ANT_gain control to be used |
| 382 | * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A |
| 383 | * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B |
| 384 | * } |
| 385 | * }) |
| 386 | */ |
| 387 | if (ppag->revision > MAX_ANT_GAINS_REVISION) { |
| 388 | printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | package_size = 1 + 1 + ppag->chains_count * ppag->bands_count; |
| 393 | |
| 394 | acpigen_write_name("PPAG"); |
| 395 | acpigen_write_package(2); |
| 396 | acpigen_write_dword(ppag->revision); |
| 397 | acpigen_write_package(package_size); |
| 398 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 399 | acpigen_write_dword(ppag->mode); |
| 400 | |
| 401 | for (set_num = 0; set_num < ppag->chains_count; set_num++) { |
| 402 | set = ppag_fetch_set(ppag, set_num); |
| 403 | for (i = 0; i < ppag->bands_count; i++) |
| 404 | acpigen_write_byte(set[i]); |
| 405 | } |
| 406 | |
| 407 | acpigen_write_package_end(); |
| 408 | acpigen_write_package_end(); |
| 409 | } |
| 410 | |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 411 | static void sar_emit_wtas(struct avg_profile *wtas) |
| 412 | { |
| 413 | int i; |
| 414 | size_t package_size; |
| 415 | |
| 416 | if (wtas == NULL) |
| 417 | return; |
| 418 | |
| 419 | /* |
| 420 | * Name (WTAS, Package() { |
| 421 | * { |
| 422 | * Revision, |
| 423 | * Package() |
| 424 | * { |
| 425 | * DomainType, // 0x7:WiFi |
| 426 | * WifiTASSelection, // Enable/Disable the TAS feature |
| 427 | * WifiTASListEntries, // No. of blocked countries not approved by OEM to |
| 428 | * BlockedListEntry1, support this feature |
| 429 | * BlockedListEntry2, |
| 430 | * BlockedListEntry3, |
| 431 | * BlockedListEntry4, |
| 432 | * BlockedListEntry5, |
| 433 | * BlockedListEntry6, |
| 434 | * BlockedListEntry7, |
| 435 | * BlockedListEntry8, |
| 436 | * BlockedListEntry9, |
| 437 | * BlockedListEntry10, |
| 438 | * BlockedListEntry11, |
| 439 | * BlockedListEntry12, |
| 440 | * BlockedListEntry13, |
| 441 | * BlockedListEntry14, |
| 442 | * BlockedListEntry15, |
| 443 | * BlockedListEntry16, |
| 444 | * } |
| 445 | * }) |
| 446 | */ |
| 447 | package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY; |
| 448 | |
| 449 | acpigen_write_name("WTAS"); |
| 450 | acpigen_write_package(2); |
| 451 | acpigen_write_dword(wtas->revision); |
| 452 | acpigen_write_package(package_size); |
| 453 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
Sugnan Prabhu S | 627c844 | 2021-09-06 15:05:56 +0530 | [diff] [blame] | 454 | acpigen_write_byte(wtas->tas_selection); |
| 455 | acpigen_write_byte(wtas->tas_list_size); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 456 | for (i = 0; i < MAX_DENYLIST_ENTRY; i++) |
Sugnan Prabhu S | 627c844 | 2021-09-06 15:05:56 +0530 | [diff] [blame] | 457 | acpigen_write_word(wtas->deny_list_entry[i]); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 458 | |
| 459 | acpigen_write_package_end(); |
| 460 | acpigen_write_package_end(); |
| 461 | } |
| 462 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 463 | static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm) |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 464 | { |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 465 | union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} }; |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR |
| 469 | * ACPI tables are currently used only by Intel WiFi devices. |
| 470 | */ |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 471 | if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL) |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 472 | return; |
| 473 | |
| 474 | /* Retrieve the sar limits data */ |
| 475 | if (get_wifi_sar_limits(&sar_limits) < 0) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 476 | printk(BIOS_ERR, "failed getting SAR limits!\n"); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
| 480 | sar_emit_wrds(sar_limits.sar); |
| 481 | sar_emit_ewrd(sar_limits.sar); |
| 482 | sar_emit_wgds(sar_limits.wgds); |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 483 | sar_emit_ppag(sar_limits.ppag); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 484 | sar_emit_wtas(sar_limits.wtas); |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 485 | |
| 486 | /* copy the dsm data to be later used for creating _DSM function */ |
| 487 | if (sar_limits.dsm != NULL) |
Meera Ravindranath | f337537 | 2022-11-10 11:27:00 +0530 | [diff] [blame] | 488 | memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile)); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 489 | |
| 490 | free(sar_limits.sar); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 493 | static void wifi_ssdt_write_device(const struct device *dev, const char *path) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 494 | { |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 495 | /* Device */ |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 496 | acpigen_write_device(path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 497 | acpi_device_write_uid(dev); |
| 498 | |
| 499 | if (dev->chip_ops) |
| 500 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 501 | |
| 502 | /* Address */ |
| 503 | acpigen_write_ADR_pci_device(dev); |
| 504 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 505 | acpigen_pop_len(); /* Device */ |
| 506 | } |
| 507 | |
| 508 | static void wifi_ssdt_write_properties(const struct device *dev, const char *scope) |
| 509 | { |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 510 | const struct drivers_wifi_generic_config *config = dev->chip_info; |
Angel Pons | 1e124b9 | 2022-04-03 21:10:26 +0200 | [diff] [blame] | 511 | |
| 512 | bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim; |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 513 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 514 | /* Scope */ |
| 515 | acpigen_write_scope(scope); |
| 516 | |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 517 | if (config) { |
| 518 | /* Wake capabilities */ |
| 519 | acpigen_write_PRW(config->wake, ACPI_S3); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 520 | |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 521 | /* Add _DSD for DmaProperty property. */ |
Kapil Porwal | 0b20a17 | 2022-11-26 20:10:47 +0530 | [diff] [blame] | 522 | if (config->add_acpi_dma_property) |
| 523 | acpi_device_add_dma_property(NULL); |
Tim Wawrzynczak | 3babc8e | 2022-01-25 14:05:20 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 526 | /* Fill regulatory domain structure */ |
| 527 | if (CONFIG(HAVE_REGULATORY_DOMAIN)) { |
| 528 | /* |
| 529 | * Name ("WRDD", Package () { |
| 530 | * WRDD_REVISION, // Revision |
| 531 | * Package () { |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 532 | * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 533 | * wifi_regulatory_domain() // Country Identifier |
| 534 | * } |
| 535 | * }) |
| 536 | */ |
| 537 | acpigen_write_name("WRDD"); |
| 538 | acpigen_write_package(2); |
| 539 | acpigen_write_integer(WRDD_REVISION); |
| 540 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 541 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 542 | acpigen_write_dword(wifi_regulatory_domain()); |
| 543 | acpigen_pop_len(); |
| 544 | acpigen_pop_len(); |
| 545 | } |
| 546 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 547 | struct dsm_uuid dsm_ids[MAX_DSM_FUNCS]; |
| 548 | /* We will need a copy dsm data to be used later for creating _DSM function */ |
| 549 | struct dsm_profile dsm = {0}; |
| 550 | uint8_t dsm_count = 0; |
| 551 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 552 | /* Fill Wifi sar related ACPI structures */ |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 553 | if (CONFIG(USE_SAR)) { |
| 554 | emit_sar_acpi_structures(dev, &dsm); |
| 555 | |
| 556 | if (dsm.supported_functions != 0) { |
| 557 | for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++) |
| 558 | if (!(dsm.supported_functions & (1 << i))) |
| 559 | wifi_dsm_callbacks[i] = NULL; |
| 560 | |
| 561 | dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID; |
| 562 | dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0]; |
| 563 | dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks); |
Meera Ravindranath | f337537 | 2022-11-10 11:27:00 +0530 | [diff] [blame] | 564 | dsm_ids[dsm_count].arg = &dsm; |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 565 | dsm_count++; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if (is_cnvi_ddr_rfim_enabled) { |
| 570 | dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID; |
| 571 | dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0]; |
| 572 | dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks); |
| 573 | dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled; |
| 574 | dsm_count++; |
| 575 | } |
| 576 | |
| 577 | acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 578 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 579 | acpigen_pop_len(); /* Scope */ |
| 580 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 581 | printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "", |
| 582 | dev_path(dev)); |
| 583 | } |
| 584 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 585 | void wifi_pcie_fill_ssdt(const struct device *dev) |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 586 | { |
| 587 | const char *path; |
| 588 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 589 | path = acpi_device_path(dev); |
| 590 | if (!path) |
| 591 | return; |
| 592 | |
| 593 | wifi_ssdt_write_device(dev, path); |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 594 | wifi_ssdt_write_properties(dev, path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 597 | const char *wifi_pcie_acpi_name(const struct device *dev) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 598 | { |
| 599 | static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN]; |
| 600 | |
| 601 | /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */ |
| 602 | snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X", |
| 603 | (dev_path_encode(dev) & 0xff)); |
| 604 | return wifi_acpi_name; |
| 605 | } |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 606 | |
| 607 | void wifi_cnvi_fill_ssdt(const struct device *dev) |
| 608 | { |
| 609 | const char *path; |
Angel Pons | 1e124b9 | 2022-04-03 21:10:26 +0200 | [diff] [blame] | 610 | if (!dev) |
| 611 | return; |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 612 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 613 | path = acpi_device_path(dev->bus->dev); |
| 614 | if (!path) |
| 615 | return; |
| 616 | |
| 617 | wifi_ssdt_write_properties(dev, path); |
| 618 | } |