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 | |
Ravi Sarawadi | 511222c | 2024-05-06 09:58:52 -0700 | [diff] [blame^] | 146 | /* |
| 147 | * Function 12: Control Enablement 802.11be on certificated modules |
| 148 | * Bit 0 |
| 149 | * 0 - 11BE disabled for China Mainland |
| 150 | * 1 - 11BE enabled for China Mainland |
| 151 | * |
| 152 | * Bit 1 |
| 153 | * 0 - 11BE disabled for South Korea |
| 154 | * 1 - 11BE enabled for South Korea |
| 155 | * |
| 156 | * Bit 2:27 - Reserved (shall be set to zeroes) |
| 157 | * |
| 158 | * Bit 28:31 - 11BE enablement revision |
| 159 | * |
| 160 | */ |
| 161 | static void wifi_dsm_11be_country_enablement(void *args) |
| 162 | { |
| 163 | struct dsm_profile *dsm_config = (struct dsm_profile *)args; |
| 164 | |
| 165 | acpigen_write_return_integer(dsm_config->enablement_11be); |
| 166 | } |
| 167 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 168 | static void wifi_dsm_ddrrfim_func3_cb(void *ptr) |
| 169 | { |
| 170 | const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr; |
Simon Yang | 59b383e | 2023-12-28 14:42:21 +0800 | [diff] [blame] | 171 | acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1); |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 172 | } |
| 173 | |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 174 | static void (*wifi_dsm_callbacks[])(void *) = { |
| 175 | NULL, /* Function 0 */ |
| 176 | wifi_dsm_srd_active_channels, /* Function 1 */ |
| 177 | wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */ |
| 178 | wifi_dsm_supported_ultra_high_band, /* Function 3 */ |
| 179 | wifi_dsm_regulatory_configurations, /* Function 4 */ |
| 180 | wifi_dsm_uart_configurations, /* Function 5 */ |
| 181 | wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */ |
| 182 | wifi_dsm_unii4_control_enable, /* Function 7 */ |
Ravi Sarawadi | 511222c | 2024-05-06 09:58:52 -0700 | [diff] [blame^] | 183 | NULL, /* Function 8 */ |
| 184 | NULL, /* Function 9 */ |
| 185 | NULL, /* Function 10 */ |
| 186 | NULL, /* Function 11 */ |
| 187 | wifi_dsm_11be_country_enablement, /* Function 12 */ |
Sugnan Prabhu S | d70f481 | 2021-08-25 17:36:44 +0530 | [diff] [blame] | 188 | }; |
| 189 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 190 | /* |
| 191 | * The current DSM2 table is only exporting one function (function 3), some more |
| 192 | * functions are reserved so marking them NULL. |
| 193 | */ |
| 194 | static void (*wifi_dsm2_callbacks[])(void *) = { |
| 195 | NULL, /* Function 0 */ |
| 196 | NULL, /* Function 1 */ |
| 197 | NULL, /* Function 2 */ |
| 198 | wifi_dsm_ddrrfim_func3_cb, /* Function 3 */ |
| 199 | }; |
| 200 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 201 | 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] | 202 | { |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 203 | const uint8_t *sar_table = &sar->sar_table[0]; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 204 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 205 | return sar_table + (sar->chains_count * sar->subbands_count * set_num); |
| 206 | } |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 207 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 208 | static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num) |
| 209 | { |
| 210 | const uint8_t *wgds_table = &wgds->wgds_table[0]; |
| 211 | |
| 212 | return wgds_table + (wgds->bands_count * set_num); |
| 213 | } |
| 214 | |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 215 | static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num) |
| 216 | { |
| 217 | const uint8_t *ppag_table = &ppag->ppag_table[0]; |
| 218 | |
| 219 | return ppag_table + (ppag->bands_count * set_num); |
| 220 | } |
| 221 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 222 | static void sar_emit_wrds(const struct sar_profile *sar) |
| 223 | { |
| 224 | int i; |
| 225 | size_t package_size, table_size; |
| 226 | const uint8_t *set; |
| 227 | |
| 228 | if (sar == NULL) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 229 | return; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * Name ("WRDS", Package () { |
| 233 | * Revision, |
| 234 | * Package () { |
| 235 | * Domain Type, // 0x7:WiFi |
| 236 | * WiFi SAR BIOS, // BIOS SAR Enable/disable |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 237 | * SAR Table Set // Set#1 of SAR Table |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 238 | * } |
| 239 | * }) |
| 240 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 241 | if (sar->revision > MAX_SAR_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 242 | printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 243 | return; |
| 244 | } |
| 245 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 246 | acpigen_write_name("WRDS"); |
| 247 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 248 | acpigen_write_dword(sar->revision); |
| 249 | |
| 250 | table_size = sar->chains_count * sar->subbands_count; |
| 251 | /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */ |
| 252 | package_size = 1 + 1 + table_size; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 253 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 254 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 255 | acpigen_write_dword(1); |
| 256 | |
| 257 | set = sar_fetch_set(sar, 0); |
| 258 | for (i = 0; i < table_size; i++) |
| 259 | acpigen_write_byte(set[i]); |
| 260 | |
| 261 | acpigen_write_package_end(); |
| 262 | acpigen_write_package_end(); |
| 263 | } |
| 264 | |
| 265 | static void sar_emit_ewrd(const struct sar_profile *sar) |
| 266 | { |
| 267 | int i; |
| 268 | size_t package_size, set_num, table_size; |
| 269 | const uint8_t *set; |
| 270 | |
| 271 | if (sar == NULL) |
| 272 | return; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * Name ("EWRD", Package () { |
| 276 | * Revision, |
| 277 | * Package () { |
| 278 | * Domain Type, // 0x7:WiFi |
| 279 | * Dynamic SAR Enable, // Dynamic SAR Enable/disable |
| 280 | * Extended SAR sets, // Number of optional SAR table sets |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 281 | * SAR Table Set, // Set#2 of SAR Table |
| 282 | * SAR Table Set, // Set#3 of SAR Table |
| 283 | * SAR Table Set // Set#4 of SAR Table |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 284 | * } |
| 285 | * }) |
| 286 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 287 | if (sar->revision > MAX_SAR_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 288 | printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 289 | return; |
| 290 | } |
| 291 | |
| 292 | if (sar->dsar_set_count == 0) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 293 | printk(BIOS_WARNING, "DSAR set count is 0\n"); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 294 | return; |
| 295 | } |
| 296 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 297 | acpigen_write_name("EWRD"); |
| 298 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 299 | acpigen_write_dword(sar->revision); |
| 300 | |
| 301 | table_size = sar->chains_count * sar->subbands_count; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 302 | /* |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 303 | * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count' |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 304 | * + number of bytes for Set#2 & 3 & 4 |
| 305 | */ |
Matt Chen | 07e6b5f | 2021-11-04 18:13:25 +0800 | [diff] [blame] | 306 | package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT; |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 307 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 308 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 309 | acpigen_write_dword(1); |
| 310 | acpigen_write_dword(sar->dsar_set_count); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 311 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 312 | for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) { |
| 313 | set = sar_fetch_set(sar, set_num); |
| 314 | for (i = 0; i < table_size; i++) |
| 315 | acpigen_write_byte(set[i]); |
| 316 | } |
| 317 | |
| 318 | /* wifi driver always expects 3 DSAR sets */ |
| 319 | for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++) |
| 320 | acpigen_write_byte(0); |
| 321 | |
| 322 | acpigen_write_package_end(); |
| 323 | acpigen_write_package_end(); |
| 324 | } |
| 325 | |
| 326 | static void sar_emit_wgds(struct geo_profile *wgds) |
| 327 | { |
| 328 | int i; |
| 329 | size_t package_size, set_num; |
| 330 | const uint8_t *set; |
| 331 | |
| 332 | if (wgds == NULL) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 333 | return; |
| 334 | |
| 335 | /* |
| 336 | * Name ("WGDS", Package() { |
| 337 | * Revision, |
| 338 | * Package() { |
| 339 | * DomainType, // 0x7:WiFi |
| 340 | * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max |
| 341 | * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset |
| 342 | * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset |
| 343 | * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max |
| 344 | * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset |
| 345 | * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 346 | * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max |
| 347 | * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset |
| 348 | * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 349 | * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max |
| 350 | * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset |
| 351 | * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset |
| 352 | * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max |
| 353 | * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset |
| 354 | * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 355 | * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max |
| 356 | * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset |
| 357 | * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 358 | * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max |
| 359 | * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset |
| 360 | * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset |
| 361 | * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max |
| 362 | * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset |
| 363 | * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 364 | * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max |
| 365 | * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset |
| 366 | * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 367 | * } |
| 368 | * }) |
| 369 | */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 370 | if (wgds->revision > MAX_GEO_OFFSET_REVISION) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 371 | printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 372 | return; |
| 373 | } |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 374 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 375 | package_size = 1 + wgds->chains_count * wgds->bands_count; |
| 376 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 377 | acpigen_write_name("WGDS"); |
| 378 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 379 | acpigen_write_dword(wgds->revision); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 380 | /* Emit 'Domain Type' + |
| 381 | * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS) |
| 382 | */ |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 383 | acpigen_write_package(package_size); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 384 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 385 | |
| 386 | for (set_num = 0; set_num < wgds->chains_count; set_num++) { |
| 387 | set = wgds_fetch_set(wgds, set_num); |
| 388 | for (i = 0; i < wgds->bands_count; i++) |
| 389 | acpigen_write_byte(set[i]); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 392 | acpigen_write_package_end(); |
| 393 | acpigen_write_package_end(); |
| 394 | } |
| 395 | |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 396 | static void sar_emit_ppag(struct gain_profile *ppag) |
| 397 | { |
| 398 | int i; |
| 399 | size_t package_size, set_num; |
| 400 | const uint8_t *set; |
| 401 | |
| 402 | if (ppag == NULL) |
| 403 | return; |
| 404 | |
| 405 | /* |
| 406 | * Name ("PPAG", Package () { |
| 407 | * Revision, |
| 408 | * Package () { |
| 409 | * Domain Type, // 0x7:WiFi |
| 410 | * PPAG Mode, // Defines the mode of ANT_gain control to be used |
| 411 | * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A |
| 412 | * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B |
| 413 | * } |
| 414 | * }) |
| 415 | */ |
| 416 | if (ppag->revision > MAX_ANT_GAINS_REVISION) { |
| 417 | printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | package_size = 1 + 1 + ppag->chains_count * ppag->bands_count; |
| 422 | |
| 423 | acpigen_write_name("PPAG"); |
| 424 | acpigen_write_package(2); |
| 425 | acpigen_write_dword(ppag->revision); |
| 426 | acpigen_write_package(package_size); |
| 427 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
| 428 | acpigen_write_dword(ppag->mode); |
| 429 | |
| 430 | for (set_num = 0; set_num < ppag->chains_count; set_num++) { |
| 431 | set = ppag_fetch_set(ppag, set_num); |
| 432 | for (i = 0; i < ppag->bands_count; i++) |
| 433 | acpigen_write_byte(set[i]); |
| 434 | } |
| 435 | |
| 436 | acpigen_write_package_end(); |
| 437 | acpigen_write_package_end(); |
| 438 | } |
| 439 | |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 440 | static void sar_emit_wtas(struct avg_profile *wtas) |
| 441 | { |
| 442 | int i; |
| 443 | size_t package_size; |
| 444 | |
| 445 | if (wtas == NULL) |
| 446 | return; |
| 447 | |
| 448 | /* |
| 449 | * Name (WTAS, Package() { |
| 450 | * { |
| 451 | * Revision, |
| 452 | * Package() |
| 453 | * { |
| 454 | * DomainType, // 0x7:WiFi |
| 455 | * WifiTASSelection, // Enable/Disable the TAS feature |
| 456 | * WifiTASListEntries, // No. of blocked countries not approved by OEM to |
| 457 | * BlockedListEntry1, support this feature |
| 458 | * BlockedListEntry2, |
| 459 | * BlockedListEntry3, |
| 460 | * BlockedListEntry4, |
| 461 | * BlockedListEntry5, |
| 462 | * BlockedListEntry6, |
| 463 | * BlockedListEntry7, |
| 464 | * BlockedListEntry8, |
| 465 | * BlockedListEntry9, |
| 466 | * BlockedListEntry10, |
| 467 | * BlockedListEntry11, |
| 468 | * BlockedListEntry12, |
| 469 | * BlockedListEntry13, |
| 470 | * BlockedListEntry14, |
| 471 | * BlockedListEntry15, |
| 472 | * BlockedListEntry16, |
| 473 | * } |
| 474 | * }) |
| 475 | */ |
| 476 | package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY; |
| 477 | |
| 478 | acpigen_write_name("WTAS"); |
| 479 | acpigen_write_package(2); |
| 480 | acpigen_write_dword(wtas->revision); |
| 481 | acpigen_write_package(package_size); |
| 482 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
Sugnan Prabhu S | 627c844 | 2021-09-06 15:05:56 +0530 | [diff] [blame] | 483 | acpigen_write_byte(wtas->tas_selection); |
| 484 | acpigen_write_byte(wtas->tas_list_size); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 485 | for (i = 0; i < MAX_DENYLIST_ENTRY; i++) |
Sugnan Prabhu S | 627c844 | 2021-09-06 15:05:56 +0530 | [diff] [blame] | 486 | acpigen_write_word(wtas->deny_list_entry[i]); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 487 | |
| 488 | acpigen_write_package_end(); |
| 489 | acpigen_write_package_end(); |
| 490 | } |
| 491 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 492 | 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] | 493 | { |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 494 | union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} }; |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR |
| 498 | * ACPI tables are currently used only by Intel WiFi devices. |
| 499 | */ |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 500 | 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] | 501 | return; |
| 502 | |
Martin Roth | 3e25f85 | 2023-09-04 15:37:07 -0600 | [diff] [blame] | 503 | /* Retrieve the SAR limits data */ |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 504 | if (get_wifi_sar_limits(&sar_limits) < 0) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 505 | printk(BIOS_ERR, "failed getting SAR limits!\n"); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 506 | return; |
| 507 | } |
| 508 | |
| 509 | sar_emit_wrds(sar_limits.sar); |
| 510 | sar_emit_ewrd(sar_limits.sar); |
| 511 | sar_emit_wgds(sar_limits.wgds); |
Sugnan Prabhu S | d1fc832 | 2021-08-31 07:11:35 +0530 | [diff] [blame] | 512 | sar_emit_ppag(sar_limits.ppag); |
Sugnan Prabhu S | cc50770 | 2021-08-31 07:19:30 +0530 | [diff] [blame] | 513 | sar_emit_wtas(sar_limits.wtas); |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 514 | |
| 515 | /* copy the dsm data to be later used for creating _DSM function */ |
| 516 | if (sar_limits.dsm != NULL) |
Meera Ravindranath | f337537 | 2022-11-10 11:27:00 +0530 | [diff] [blame] | 517 | memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile)); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 518 | |
| 519 | free(sar_limits.sar); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 522 | 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] | 523 | { |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 524 | /* Device */ |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 525 | acpigen_write_device(path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 526 | acpi_device_write_uid(dev); |
| 527 | |
| 528 | if (dev->chip_ops) |
| 529 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 530 | |
| 531 | /* Address */ |
| 532 | acpigen_write_ADR_pci_device(dev); |
| 533 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 534 | acpigen_pop_len(); /* Device */ |
| 535 | } |
| 536 | |
| 537 | static void wifi_ssdt_write_properties(const struct device *dev, const char *scope) |
| 538 | { |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 539 | const struct drivers_wifi_generic_config *config = dev->chip_info; |
Angel Pons | 1e124b9 | 2022-04-03 21:10:26 +0200 | [diff] [blame] | 540 | |
| 541 | 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] | 542 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 543 | /* Scope */ |
| 544 | acpigen_write_scope(scope); |
| 545 | |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 546 | if (config) { |
| 547 | /* Wake capabilities */ |
| 548 | acpigen_write_PRW(config->wake, ACPI_S3); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 549 | |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 550 | /* Add _DSD for DmaProperty property. */ |
Kapil Porwal | 0b20a17 | 2022-11-26 20:10:47 +0530 | [diff] [blame] | 551 | if (config->add_acpi_dma_property) |
| 552 | acpi_device_add_dma_property(NULL); |
Tim Wawrzynczak | 3babc8e | 2022-01-25 14:05:20 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 555 | /* Fill regulatory domain structure */ |
| 556 | if (CONFIG(HAVE_REGULATORY_DOMAIN)) { |
| 557 | /* |
| 558 | * Name ("WRDD", Package () { |
| 559 | * WRDD_REVISION, // Revision |
| 560 | * Package () { |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 561 | * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 562 | * wifi_regulatory_domain() // Country Identifier |
| 563 | * } |
| 564 | * }) |
| 565 | */ |
| 566 | acpigen_write_name("WRDD"); |
| 567 | acpigen_write_package(2); |
| 568 | acpigen_write_integer(WRDD_REVISION); |
| 569 | acpigen_write_package(2); |
Sugnan Prabhu S | fcb4f2d | 2021-07-30 20:12:22 +0530 | [diff] [blame] | 570 | acpigen_write_dword(DOMAIN_TYPE_WIFI); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 571 | acpigen_write_dword(wifi_regulatory_domain()); |
| 572 | acpigen_pop_len(); |
| 573 | acpigen_pop_len(); |
| 574 | } |
| 575 | |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 576 | struct dsm_uuid dsm_ids[MAX_DSM_FUNCS]; |
| 577 | /* We will need a copy dsm data to be used later for creating _DSM function */ |
| 578 | struct dsm_profile dsm = {0}; |
| 579 | uint8_t dsm_count = 0; |
| 580 | |
Martin Roth | 3e25f85 | 2023-09-04 15:37:07 -0600 | [diff] [blame] | 581 | /* Fill Wifi SAR related ACPI structures */ |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 582 | if (CONFIG(USE_SAR)) { |
| 583 | emit_sar_acpi_structures(dev, &dsm); |
| 584 | |
| 585 | if (dsm.supported_functions != 0) { |
| 586 | for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++) |
| 587 | if (!(dsm.supported_functions & (1 << i))) |
| 588 | wifi_dsm_callbacks[i] = NULL; |
| 589 | |
| 590 | dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID; |
| 591 | dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0]; |
| 592 | dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks); |
Meera Ravindranath | f337537 | 2022-11-10 11:27:00 +0530 | [diff] [blame] | 593 | dsm_ids[dsm_count].arg = &dsm; |
Varshit B Pandya | b6ebcdf | 2022-02-03 18:35:18 +0530 | [diff] [blame] | 594 | dsm_count++; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | if (is_cnvi_ddr_rfim_enabled) { |
| 599 | dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID; |
| 600 | dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0]; |
| 601 | dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks); |
| 602 | dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled; |
| 603 | dsm_count++; |
| 604 | } |
| 605 | |
| 606 | acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 607 | |
David Ruth | ea8330e | 2023-12-06 21:39:54 +0000 | [diff] [blame] | 608 | /* |
| 609 | * Fill MediaTek MTCL related ACPI structure iff the device type is PCI, |
| 610 | * the device has the MediaTek vendor ID, and the MTCL feature is |
| 611 | * configured. |
| 612 | */ |
| 613 | if (CONFIG(USE_MTCL)) { |
| 614 | if (dev->path.type == DEVICE_PATH_PCI && |
| 615 | dev->vendor == PCI_VID_MEDIATEK) |
| 616 | write_mtcl_function(); |
| 617 | } |
| 618 | |
| 619 | acpigen_write_scope_end(); /* Scope */ |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 620 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 621 | printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "", |
| 622 | dev_path(dev)); |
| 623 | } |
| 624 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 625 | void wifi_pcie_fill_ssdt(const struct device *dev) |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 626 | { |
| 627 | const char *path; |
| 628 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 629 | path = acpi_device_path(dev); |
| 630 | if (!path) |
| 631 | return; |
| 632 | |
| 633 | wifi_ssdt_write_device(dev, path); |
Reka Norman | 9392819 | 2022-07-22 08:01:19 +1000 | [diff] [blame] | 634 | wifi_ssdt_write_properties(dev, path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 637 | const char *wifi_pcie_acpi_name(const struct device *dev) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 638 | { |
| 639 | static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN]; |
| 640 | |
| 641 | /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */ |
| 642 | snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X", |
| 643 | (dev_path_encode(dev) & 0xff)); |
| 644 | return wifi_acpi_name; |
| 645 | } |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 646 | |
| 647 | void wifi_cnvi_fill_ssdt(const struct device *dev) |
| 648 | { |
| 649 | const char *path; |
Angel Pons | 1e124b9 | 2022-04-03 21:10:26 +0200 | [diff] [blame] | 650 | if (!dev) |
| 651 | return; |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 652 | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 653 | path = acpi_device_path(dev->upstream->dev); |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 654 | if (!path) |
| 655 | return; |
| 656 | |
| 657 | wifi_ssdt_write_properties(dev, path); |
| 658 | } |