Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1254490ybh; Thu, 12 Mar 2020 20:49:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vshwsENwRbpppLNT55XAtW9mNp4CTI8Al1iSkk10k/BkD95IfSWdOcgxwE+T90//HbPTen1 X-Received: by 2002:aca:dac5:: with SMTP id r188mr5474716oig.176.1584071393793; Thu, 12 Mar 2020 20:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584071393; cv=none; d=google.com; s=arc-20160816; b=BIh7u9rw7K9S+u5FlAN3Obbc9JwlvRMzvSnEIuvT8ZsBBFXi6S86oL2HWvC9pi8YKC fRMX2xENaOFtyPlZw/7qFBG5rFKrUAEqeN2vAhAZo7z+McH/Vly8bJDxMNfPXYfuKFZH Vec5Mf8gprVmgfDhNB8ZOLbGmkHLs0hzYoA3MNXPVKyGiQafH2qWK9/yKrAeOuTQleON pRWRQJdMFKe34P1xH6q+xQedjshP1L4f5SyF6vGESkBU8Fz6s9i7CaKNYH+0OQ0hXqdE KFmAiwhjPHy29y9uoqbE9ybsHM41iR/B85cvN8OlhzZVLsJ78l0Ec5OZ7n+9ChyFtGe1 DAyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:authenticated-by; bh=hm26tF/aao1TEXJqaBP60Vo8NOCHQ1pU6uNEyfW8C/8=; b=Tgdtrbg26at6F1AYKaeUM/y7f7FQRqLJMLUpNtQ7vJoD3++634UjO+9dfyrzrn1se5 xOhrK1Iy0v9/6qw6757VIUCdquXoj329UfALPeRoSFjSWtVspa4YobQw2jkBWBwu+d/B GBDkPMhq3o4Xc+JqIuNoKqoVBf6coMbR3RnwdGR8+RhJUCa0EMHrxSQbAGOg5+CFeXHu HYn+v+12/og+88pklCFkX/6r5wNubX3Qvm2eYia48/SeVDwQQsx40qWYqV4fOP9j7QwQ 6kboBnklnw70lG4T8Lhq7gZb5HPxdYPfSXH7mBFYw8BsMXa1z8cYjvO5nphEk4GHd9CI u+mQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x24si4235000otq.261.2020.03.12.20.49.40; Thu, 12 Mar 2020 20:49:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726423AbgCMDt3 (ORCPT + 99 others); Thu, 12 Mar 2020 23:49:29 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:55848 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726254AbgCMDt3 (ORCPT ); Thu, 12 Mar 2020 23:49:29 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID 02D3nKXH014829, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (RTEXMB06.realtek.com.tw[172.21.6.99]) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id 02D3nKXH014829 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 11:49:20 +0800 Received: from RTEXMB04.realtek.com.tw (172.21.6.97) by RTEXMB06.realtek.com.tw (172.21.6.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Fri, 13 Mar 2020 11:49:20 +0800 Received: from localhost.localdomain (172.21.68.128) by RTEXMB04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Fri, 13 Mar 2020 11:49:20 +0800 From: To: CC: , , Subject: [PATCH v5 1/2] rtw88: add regulatory process strategy for different chipset Date: Fri, 13 Mar 2020 11:49:17 +0800 Message-ID: <20200313034918.22222-2-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313034918.22222-1-yhchuang@realtek.com> References: <20200313034918.22222-1-yhchuang@realtek.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.21.68.128] X-ClientProxiedBy: RTEXMB03.realtek.com.tw (172.21.6.96) To RTEXMB04.realtek.com.tw (172.21.6.97) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Tzu-En Huang If the country code in efuse is not set to a specific regulatory, then the efuse setting is WW (world-wide). For the country codes that are set to a specific country, the driver is not going to apply any new setting notified from the stack. For the country codes that are not set, which is treated as WW, the driver provides a customized WW regulatory through wiphy_apply_custom_regulatory(). But when there's any other regulatory found in IE, notified by NL80211_REGDOM_SET_BY_COUNTRY_IE, the driver will apply the setting found in the IE for 802.11d. We want all of the regulatory rules being set strictly, not to loose the restrictions of the country setting, so apply REGULATORY_STRICT_REG to all of the regulatory settings. For user notification (NL80211_REGDOM_SET_BY_USER), we'd like to default disable it because as FCC publication 594280 states: "In particular, users must not be relied on to set a country code or location code to ensure compliance". If any distributions or OSes want to set regulatory through user space tool (ex, iw reg set), then they should honor the compile flag option RTW88_REGD_USER_REG_HINTS. Signed-off-by: Tzu-En Huang Signed-off-by: Yan-Hsuan Chuang --- v3 -> v4 * squashed with "rtw88: support dynamic user regulatory setting" * modify the commit log v4 -> v5 * no change drivers/net/wireless/realtek/rtw88/Kconfig | 10 ++++ drivers/net/wireless/realtek/rtw88/main.c | 6 ++- drivers/net/wireless/realtek/rtw88/main.h | 1 + drivers/net/wireless/realtek/rtw88/regd.c | 61 ++++++++++++++++++---- 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/Kconfig b/drivers/net/wireless/realtek/rtw88/Kconfig index 33bd7ed797ff..04b84ec1dfc1 100644 --- a/drivers/net/wireless/realtek/rtw88/Kconfig +++ b/drivers/net/wireless/realtek/rtw88/Kconfig @@ -52,4 +52,14 @@ config RTW88_DEBUGFS If unsure, say Y to simplify debug problems +config RTW88_REGD_USER_REG_HINTS + bool "Realtek rtw88 user regulatory hints" + depends on RTW88_CORE + default n + help + Enable regulatoy user hints + + If unsure, say N. This should only be allowed on distributions + that need this to correct the regulatory. + endif diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c index 2f73820cd9ba..635d9964beaa 100644 --- a/drivers/net/wireless/realtek/rtw88/main.c +++ b/drivers/net/wireless/realtek/rtw88/main.c @@ -1510,8 +1510,10 @@ int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw) return ret; } - if (regulatory_hint(hw->wiphy, rtwdev->regd.alpha2)) - rtw_err(rtwdev, "regulatory_hint fail\n"); + if (!rtwdev->efuse.country_worldwide) { + if (regulatory_hint(hw->wiphy, rtwdev->efuse.country_code)) + rtw_err(rtwdev, "regulatory_hint fail\n"); + } rtw_debugfs_init(rtwdev); diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h index c074cef22120..5e0ee86048bd 100644 --- a/drivers/net/wireless/realtek/rtw88/main.h +++ b/drivers/net/wireless/realtek/rtw88/main.h @@ -1424,6 +1424,7 @@ struct rtw_efuse { u8 addr[ETH_ALEN]; u8 channel_plan; u8 country_code[2]; + bool country_worldwide; u8 rf_board_option; u8 rfe_option; u8 power_track_type; diff --git a/drivers/net/wireless/realtek/rtw88/regd.c b/drivers/net/wireless/realtek/rtw88/regd.c index 69744dd65968..500a02b97a9c 100644 --- a/drivers/net/wireless/realtek/rtw88/regd.c +++ b/drivers/net/wireless/realtek/rtw88/regd.c @@ -7,6 +7,18 @@ #include "debug.h" #include "phy.h" +static const struct ieee80211_regdomain rtw88_world_regdom = { + .n_reg_rules = 5, + .alpha2 = "99", + .reg_rules = { + REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0), + REG_RULE(2467 - 10, 2484 + 10, 40, 0, 20, NL80211_RRF_NO_IR), + REG_RULE(5180 - 10, 5240 + 10, 80, 0, 20, NL80211_RRF_NO_IR), + REG_RULE(5260 - 10, 5700 + 10, 80, 0, 20, + NL80211_RRF_NO_IR | NL80211_RRF_DFS), + REG_RULE(5745 - 10, 5825 + 10, 80, 0, 20, NL80211_RRF_NO_IR), + } +}; #define COUNTRY_CHPLAN_ENT(_alpha2, _chplan, _txpwr_regd) \ {.alpha2 = (_alpha2), \ .chplan = (_chplan), \ @@ -339,12 +351,31 @@ static struct rtw_regulatory rtw_regd_find_reg_by_name(char *alpha2) return rtw_defined_chplan; } +static bool rtw_regd_is_ww(struct rtw_regulatory *reg) +{ + if (reg->txpwr_regd == RTW_REGD_WW) + return true; + return false; +} + static int rtw_regd_notifier_apply(struct rtw_dev *rtwdev, struct wiphy *wiphy, struct regulatory_request *request) { - if (request->initiator == NL80211_REGDOM_SET_BY_USER) + if (request->initiator == NL80211_REGDOM_SET_BY_DRIVER) + return -EINVAL; + if (request->initiator == NL80211_REGDOM_SET_BY_USER && + !IS_ENABLED(CONFIG_RTW88_REGD_USER_REG_HINTS)) + return -EINVAL; + if (request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && + !rtw_regd_is_ww(&rtwdev->regd)) + return -EINVAL; + if (request->initiator == NL80211_REGDOM_SET_BY_CORE && + !rtwdev->efuse.country_worldwide) { + rtwdev->regd = + rtw_regd_find_reg_by_name(rtwdev->efuse.country_code); return 0; + } rtwdev->regd = rtw_regd_find_reg_by_name(request->alpha2); rtw_regd_apply_world_flags(wiphy, request->initiator); @@ -352,15 +383,22 @@ static int rtw_regd_notifier_apply(struct rtw_dev *rtwdev, } static int -rtw_regd_init_wiphy(struct rtw_regulatory *reg, struct wiphy *wiphy, +rtw_regd_init_wiphy(struct rtw_dev *rtwdev, struct wiphy *wiphy, void (*reg_notifier)(struct wiphy *wiphy, struct regulatory_request *request)) { + struct rtw_regulatory *reg = &rtwdev->regd; + wiphy->reg_notifier = reg_notifier; - wiphy->regulatory_flags &= ~REGULATORY_CUSTOM_REG; - wiphy->regulatory_flags &= ~REGULATORY_STRICT_REG; - wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS; + if (rtw_regd_is_ww(reg)) { + rtwdev->efuse.country_worldwide = true; + wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; + wiphy_apply_custom_regulatory(wiphy, &rtw88_world_regdom); + } else { + rtwdev->efuse.country_worldwide = false; + } + wiphy->regulatory_flags |= REGULATORY_STRICT_REG; rtw_regd_apply_hw_cap_flags(wiphy); @@ -377,7 +415,7 @@ int rtw_regd_init(struct rtw_dev *rtwdev, return -EINVAL; rtwdev->regd = rtw_regd_find_reg_by_name(rtwdev->efuse.country_code); - rtw_regd_init_wiphy(&rtwdev->regd, wiphy, reg_notifier); + rtw_regd_init_wiphy(rtwdev, wiphy, reg_notifier); return 0; } @@ -388,11 +426,12 @@ void rtw_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request) struct rtw_dev *rtwdev = hw->priv; struct rtw_hal *hal = &rtwdev->hal; - rtw_regd_notifier_apply(rtwdev, wiphy, request); - rtw_dbg(rtwdev, RTW_DBG_REGD, - "get alpha2 %c%c from initiator %d, mapping to chplan 0x%x, txregd %d\n", - request->alpha2[0], request->alpha2[1], request->initiator, - rtwdev->regd.chplan, rtwdev->regd.txpwr_regd); + if (!rtw_regd_notifier_apply(rtwdev, wiphy, request)) + rtw_dbg(rtwdev, RTW_DBG_REGD, + "get alpha2 %c%c from initiator %d, mapping to chplan 0x%x, txregd %d\n", + request->alpha2[0], request->alpha2[1], + request->initiator, rtwdev->regd.chplan, + rtwdev->regd.txpwr_regd); rtw_phy_set_tx_power_level(rtwdev, hal->current_channel); } -- 2.17.1