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