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