Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp372912ybh; Wed, 11 Mar 2020 02:46:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvs2t40ErsfDUHWK0GZ3lBuAQppnUlmkUYToIhbH+n1/9mnceyDYYMgHNjAsHUO051S7M7a X-Received: by 2002:aca:7517:: with SMTP id q23mr1316997oic.23.1583920018108; Wed, 11 Mar 2020 02:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583920018; cv=none; d=google.com; s=arc-20160816; b=bhCImRNQrXily5BUiXpneAGBsoEDfDZ1VmkvnZpxOlHF820Ia2Qz3jvGYuv1iFa1jy w9VN5jJraMBQyeJpcWkv6SFdK/eT2watxzxoMuXFq13YSzbxaVwSz2SIGXNrtXIcxduZ TatA3EqIOVtbgPq4oKwF+mq4ObL8vmsiyxLMqqGX+R1Vh6xNTqM8sN46soqI6t9QdHHT BWv15BudHEYkumFVnqmXr35AR8HjnFn1nnDm8Sg1q3HwM4KONTiAX9kjtR20cF4B+JX4 r1zvCpbuTbLCtNdTfw/OOS3R0YK7kY1kNu7ehBFvts84LeeDCdvsV4Eb/+XxLCszdMwC 4jgQ== 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=bde7EShzCNHd/UMwYFAAskJ0p3GnPa7rOE0Xtr/YnaU=; b=QjuvLA8OA3gGl+MX0lNYz9rgWspkqmzVDIYF+oyJtWVTY1fnayBsX0OyjcxtcqRjp3 3ArCyLvt1N68+rhmlo9T5nd5hfUCQ0ps+rJZIgZuQ5GgNCcuXHLX8YxOW5HfPpDeP97M qkYRJA79sADnwPqxc1ANSm/ihs4frERwXfyAhEwwDjNU7sGq/Sp14QYsUxMEYcwZ1tax aPezaQegp1VEjKt7zdA94Reb0XpJYPn2oYJNuGxfkN567tathJpzftIqQE+uFFQXhfni 2xJrMT3l1JSMx5+uJNZdU65ZEFRySndxzV3ek88C4y8i7nZtwUZ+3YnGDWFHBLwfxdKG ooeA== 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 s21si16628otp.225.2020.03.11.02.46.48; Wed, 11 Mar 2020 02:46:58 -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 S1728559AbgCKJpf (ORCPT + 99 others); Wed, 11 Mar 2020 05:45:35 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:51076 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbgCKJpf (ORCPT ); Wed, 11 Mar 2020 05:45:35 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID 02B9jRBf019757, 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 02B9jRBf019757 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2020 17:45:27 +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; Wed, 11 Mar 2020 17:45:27 +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; Wed, 11 Mar 2020 17:45:26 +0800 From: To: CC: , , Subject: [PATCH v4 1/2] rtw88: add regulatory process strategy for different chipset Date: Wed, 11 Mar 2020 17:45:23 +0800 Message-ID: <20200311094524.18884-2-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311094524.18884-1-yhchuang@realtek.com> References: <20200311094524.18884-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 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