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