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