From patchwork Tue Aug 2 12:20:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Markowski X-Patchwork-Id: 9256537 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EAE0F60754 for ; Tue, 2 Aug 2016 12:21:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB2582851C for ; Tue, 2 Aug 2016 12:21:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFDDB28523; Tue, 2 Aug 2016 12:21:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6548C2851C for ; Tue, 2 Aug 2016 12:21:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUYhV-0007O2-51; Tue, 02 Aug 2016 12:21:37 +0000 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUYhM-0007Bx-S2 for ath10k@lists.infradead.org; Tue, 02 Aug 2016 12:21:33 +0000 Received: by mail-lf0-x232.google.com with SMTP id f93so137065724lfi.2 for ; Tue, 02 Aug 2016 05:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Koy0GF1d9jdl/gUTkvjKq2HHQS6Phyrua0eUtJ8w74k=; b=WiWxN4+9f8Hc2k53Dn+ubgxpn7aNFrbnqcqBLUBmGRoQnwjbSYBiCphyc3plN1WPZk FHWyYWy5hWlkBTq9YPvmTRpEAdGLrXrN9HBpfhZweMe28wshtlIERIumYHcBV7K1PJqq vxtdO0jxFTiqT8uaTYlOnzUtwGxVCt4mUUNLY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Koy0GF1d9jdl/gUTkvjKq2HHQS6Phyrua0eUtJ8w74k=; b=VlrZeUgiAx3Clx+3kjce71aJJNgbcbs3u2YA80PZqTfrvLuH/i5KFxTQlx8G0VC1LS aRJm0GfzmupzCKaIgMu0hqMUSElg4fR8TrJ69Os2o8dSVPxqJf+CkN4yR5Eja9pkcb+8 Yetxa4BQnh/IJbateydr4q5GDzraHq++Tqd3nZPXM1zReKamtKFBhbUwzEB+w9p9Fnbf MTToP+a24G8FvHvgOEA8lCCrwYMocnYWIJR6whMP97RONX9j5a4msrksC117hUYltbhq RSSdCiWIouNx5EdVpu2VE1iQs0zn6u+mKIA25sSu4nXyHM1cnZKbD56YV15lFHH8StsI 9nIA== X-Gm-Message-State: AEkooutqsMKId54VqJPOEmxRxSviuJYFmZlSk5vf3SZevJn6tUF/Zt8dyL57/xiiqjGPxnhoI45AB0fIR5MeTBmfea/a2FwLMrGtE3zL+OQW5crkAZTPhr4fsUu/GVLJ4JtmrbkdI4UhfOR+Xu38fk69UpRjm0XqAXbn8/gMV8dZRL1ybVjljw07AFWhGepamOOo6ZM= X-Received: by 10.25.205.137 with SMTP id d131mr20225460lfg.189.1470140466297; Tue, 02 Aug 2016 05:21:06 -0700 (PDT) Received: from uw000975.eu.tieto.com ([91.198.246.10]) by smtp.gmail.com with ESMTPSA id 98sm445633lja.37.2016.08.02.05.21.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Aug 2016 05:21:05 -0700 (PDT) From: Bartosz Markowski To: ath10k@lists.infradead.org Subject: [PATCH 2/2] ath10k: add platform regulatory domain support Date: Tue, 2 Aug 2016 14:20:54 +0200 Message-Id: <1470140454-3899-3-git-send-email-bartosz.markowski@tieto.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1470140454-3899-1-git-send-email-bartosz.markowski@tieto.com> References: <1470140454-3899-1-git-send-email-bartosz.markowski@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160802_052129_244345_ACFCA6F9 X-CRM114-Status: GOOD ( 16.33 ) X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-wireless@vger.kernel.org, Bartosz Markowski MIME-Version: 1.0 Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This overrides whatever regulatory the device EEPROM contains and uses what the platform says instead - in this implementation the ACPI driver. In case the hint is not programmed or corrupted (0xffff) the device falls back to the eeprom programmed settings. Signed-off-by: Bartosz Markowski --- drivers/net/wireless/ath/ath10k/core.h | 1 + drivers/net/wireless/ath/ath10k/mac.c | 117 +++++++++++++++++++++++++++++++++ drivers/net/wireless/ath/ath10k/wmi.c | 2 +- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index 30ae5bf81611..1df7c600a2bb 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -692,6 +692,7 @@ struct ath10k { u32 phy_capability; u32 hw_min_tx_power; u32 hw_max_tx_power; + u32 hw_eeprom_rd; u32 ht_cap_info; u32 vht_cap_info; u32 num_rf_chains; diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c index fb8e38df9446..b6b8a0b2046b 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -19,6 +19,7 @@ #include #include +#include #include "hif.h" #include "core.h" @@ -7751,6 +7752,116 @@ struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) return arvif_iter.arvif; } +#ifdef CONFIG_ACPI +#define WRD_METHOD "WRDD" +#define WRDD_WIFI (0x07) + +static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd) +{ + union acpi_object *mcc_pkg; + union acpi_object *domain_type; + union acpi_object *mcc_value; + u32 i; + + if (wrdd->type != ACPI_TYPE_PACKAGE || + wrdd->package.count < 2 || + wrdd->package.elements[0].type != ACPI_TYPE_INTEGER || + wrdd->package.elements[0].integer.value != 0) { + ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n"); + return 0; + } + + for (i = 1; i < wrdd->package.count; ++i) { + mcc_pkg = &wrdd->package.elements[i]; + + if (mcc_pkg->type != ACPI_TYPE_PACKAGE) + continue; + if (mcc_pkg->package.count < 2) + continue; + if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER || + mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) + continue; + + domain_type = &mcc_pkg->package.elements[0]; + if (domain_type->integer.value != WRDD_WIFI) + continue; + + mcc_value = &mcc_pkg->package.elements[1]; + return mcc_value->integer.value; + } + return 0; +} + +static u16 ath10k_mac_get_wrdd_regulatory(struct ath10k *ar) +{ + u16 rd; + acpi_handle root_handle; + acpi_handle handle; + struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL}; + acpi_status status; + u32 alpha2_code; + char alpha2[3]; + struct pci_dev *pdev = to_pci_dev(ar->dev); + + root_handle = ACPI_HANDLE(&pdev->dev); + if (!root_handle) { + ath10k_warn(ar, "failed to get root port acpi handle\n"); + return -1; + } + + status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle); + if (ACPI_FAILURE(status)) { + ath10k_warn(ar, "failed to get wrd method %d\n", status); + return -1; + } + + status = acpi_evaluate_object(handle, NULL, NULL, &wrdd); + if (ACPI_FAILURE(status)) { + ath10k_warn(ar, "failed to call wrdc %d\n", status); + return -1; + } + + alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer); + kfree(wrdd.pointer); + if (!alpha2_code) + return -1; + + alpha2[0] = (alpha2_code >> 8) & 0xff; + alpha2[1] = (alpha2_code >> 0) & 0xff; + alpha2[2] = '\0'; + + ath10k_info(ar, "regulatory hint from WRDD (alpha2-code): %s\n", alpha2); + + rd = ath_regd_find_country_by_name(alpha2); + if (rd == 0xffff) + return rd; + + rd |= COUNTRY_ERD_FLAG; + return rd; +} + +#else +static u16 ath10k_mac_get_wrdd_regulatory(struct ath10k *ar) +{ + /* fallback to default eeprom settings */ + return -1; +} +#endif + +static int ath10k_mac_init_rd(struct ath10k *ar) +{ + u16 rd; + + rd = ath10k_mac_get_wrdd_regulatory(ar); + if (rd == 0xffff) { + ath10k_info(ar, "fallback to eeprom programmed regulatory settings\n"); + rd = ar->hw_eeprom_rd; + } + + ar->ath_common.regulatory.current_rd = rd; + return 0; +} + int ath10k_mac_register(struct ath10k *ar) { static const u32 cipher_suites[] = { @@ -7974,6 +8085,12 @@ int ath10k_mac_register(struct ath10k *ar) ar->running_fw->fw_file.fw_features)) ar->ops->wake_tx_queue = NULL; + ret = ath10k_mac_init_rd(ar); + if (ret) { + ath10k_err(ar, "failed to derive regdom: %d\n", ret); + goto err_dfs_detector_exit; + } + ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, ath10k_reg_notifier); if (ret) { diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c index 169cd2e783eb..e9aadc85ad1b 100644 --- a/drivers/net/wireless/ath/ath10k/wmi.c +++ b/drivers/net/wireless/ath/ath10k/wmi.c @@ -4635,7 +4635,7 @@ static void ath10k_wmi_event_service_ready_work(struct work_struct *work) ar->fw_version_build = (__le32_to_cpu(arg.sw_ver1) & 0x0000ffff); ar->phy_capability = __le32_to_cpu(arg.phy_capab); ar->num_rf_chains = __le32_to_cpu(arg.num_rf_chains); - ar->ath_common.regulatory.current_rd = __le32_to_cpu(arg.eeprom_rd); + ar->hw_eeprom_rd = __le32_to_cpu(arg.eeprom_rd); ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ", arg.service_map, arg.service_map_len);