Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4156073pxk; Tue, 8 Sep 2020 12:06:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsSlD+EnKVKvQGlbBatmKLgPn99fLD4f85yalfplX3tPbdhHoMFJ94eiSzPVaDWTuoVcET X-Received: by 2002:aa7:c158:: with SMTP id r24mr435853edp.61.1599591999530; Tue, 08 Sep 2020 12:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599591999; cv=none; d=google.com; s=arc-20160816; b=bp0AeFWppIIaZvXF+PFVFu48ZYBYZuHjtVsfQHQI6h52FWg9hwQUp4eutRMaP47PnK g4FfgK7P9Q3R99D8JWwyueKUQXYW90QABRsWc7fM/jEtilCiEvkZlq69uKtHuVDVWE4d 6I+BUjSyAo3/yfFbj0FVy+ULogMpmsuMhoM1Fk+Mt3b/lUfmbdl1swiR7HYbwq3qXFaE n0JbQVgvi73mlHgtWyTohSJPW1jgs40WJh8FywCs06CxH34iK/Kx0BqZHOyIJldTUEAt z9KMBSLgrN72GquyJVv/G7Cv/kpHjF6t+rtEYCE/P+CkKKT4OAcU1PgHYYXbLqOA4BjJ /f1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NogUGzYc+49+rw+avD1guP+heDez9hn6QDeQomtx444=; b=U6gpXMq2BfAqtIyJY0VQl3ao4I8C1XXWDXnZC82wX9waaFnm8TKYjDXYSE8fLbeVek PCuX2XTwNrW58x8R26aBL9U5BOgWCjaIF+L/IZ0sdTElPnV8nqOIZ4HV+WryJX8erptq 9asmNVMKX8SwznVSijBv5UZP1TbYQLSOLpWnGEV7PlAcM+ILusocshjQnBbXKSu2u0+j 7Bei9zQKjKikQ1LFz4uSC3zjdz9srGGXZPKCZGo9GMlVgZpPgpdJN4Bn50mPQvCOvF7U OnuyoRDgufBvhaUBL1MrqhjXv9sPcsLw3KwRciP50sybKVSp4s7ryUhBKMpn3jBVxqBp lPYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si13321844ejx.11.2020.09.08.12.06.15; Tue, 08 Sep 2020 12:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731362AbgIHTEl (ORCPT + 99 others); Tue, 8 Sep 2020 15:04:41 -0400 Received: from mail.adapt-ip.com ([173.164.178.19]:52680 "EHLO web.adapt-ip.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731365AbgIHTDc (ORCPT ); Tue, 8 Sep 2020 15:03:32 -0400 Received: from localhost (localhost [127.0.0.1]) by web.adapt-ip.com (Postfix) with ESMTP id 145A44F9AD6; Tue, 8 Sep 2020 19:03:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at web.adapt-ip.com Received: from web.adapt-ip.com ([127.0.0.1]) by localhost (web.adapt-ip.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id SVgKjfAK4VGB; Tue, 8 Sep 2020 19:03:24 +0000 (UTC) Received: from atlas.ibsgaard.io (c-73-223-60-234.hsd1.ca.comcast.net [73.223.60.234]) (Authenticated sender: thomas@adapt-ip.com) by web.adapt-ip.com (Postfix) with ESMTPSA id 05A2D4F9AE0; Tue, 8 Sep 2020 19:03:20 +0000 (UTC) From: Thomas Pedersen To: Johannes Berg Cc: linux-wireless , Thomas Pedersen Subject: [PATCH v3 03/22] cfg80211: regulatory: handle S1G channels Date: Tue, 8 Sep 2020 12:03:04 -0700 Message-Id: <20200908190323.15814-4-thomas@adapt-ip.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200908190323.15814-1-thomas@adapt-ip.com> References: <20200908190323.15814-1-thomas@adapt-ip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org S1G channels have a minimum bandwidth of 1Mhz, and there is a 1:1 mapping of allowed bandwidth to channel number. Signed-off-by: Thomas Pedersen --- v2: - drop the freq_reg_info() interface changes and move the check for S1G band inside. Fixes a driver compile error. - fix iterating past bws[] in __freq_reg_info() by setting initial element to 0. Reported-by: kernel test robot v3: - use ARRAY_SIZE() --- net/wireless/reg.c | 70 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index dcd3d39a5372..2864ca2c3cfd 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -1617,9 +1617,11 @@ __freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 min_bw) { const struct ieee80211_regdomain *regd = reg_get_regdomain(wiphy); const struct ieee80211_reg_rule *reg_rule = NULL; + const u32 bws[] = {0, 1, 2, 4, 5, 8, 10, 16, 20}; + int i = ARRAY_SIZE(bws) - 1; u32 bw; - for (bw = MHZ_TO_KHZ(20); bw >= min_bw; bw = bw / 2) { + for (bw = MHZ_TO_KHZ(bws[i]); bw >= min_bw; bw = MHZ_TO_KHZ(bws[i--])) { reg_rule = freq_reg_info_regd(center_freq, regd, bw); if (!IS_ERR(reg_rule)) return reg_rule; @@ -1631,7 +1633,9 @@ __freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 min_bw) const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy, u32 center_freq) { - return __freq_reg_info(wiphy, center_freq, MHZ_TO_KHZ(20)); + u32 min_bw = center_freq < MHZ_TO_KHZ(1000) ? 1 : 20; + + return __freq_reg_info(wiphy, center_freq, MHZ_TO_KHZ(min_bw)); } EXPORT_SYMBOL(freq_reg_info); @@ -1659,6 +1663,7 @@ static uint32_t reg_rule_to_chan_bw_flags(const struct ieee80211_regdomain *regd { const struct ieee80211_freq_range *freq_range = NULL; u32 max_bandwidth_khz, center_freq_khz, bw_flags = 0; + bool is_s1g = chan->band == NL80211_BAND_S1GHZ; freq_range = ®_rule->freq_range; @@ -1678,16 +1683,57 @@ static uint32_t reg_rule_to_chan_bw_flags(const struct ieee80211_regdomain *regd MHZ_TO_KHZ(20))) bw_flags |= IEEE80211_CHAN_NO_20MHZ; - if (max_bandwidth_khz < MHZ_TO_KHZ(10)) - bw_flags |= IEEE80211_CHAN_NO_10MHZ; - if (max_bandwidth_khz < MHZ_TO_KHZ(20)) - bw_flags |= IEEE80211_CHAN_NO_20MHZ; - if (max_bandwidth_khz < MHZ_TO_KHZ(40)) - bw_flags |= IEEE80211_CHAN_NO_HT40; - if (max_bandwidth_khz < MHZ_TO_KHZ(80)) - bw_flags |= IEEE80211_CHAN_NO_80MHZ; - if (max_bandwidth_khz < MHZ_TO_KHZ(160)) - bw_flags |= IEEE80211_CHAN_NO_160MHZ; + if (is_s1g) { + /* S1G is strict about non overlapping channels. We can + * calculate which bandwidth is allowed per channel by finding + * the largest bandwidth which cleanly divides the freq_range. + */ + int edge_offset; + int ch_bw = max_bandwidth_khz; + + while (ch_bw) { + edge_offset = (center_freq_khz - ch_bw / 2) - + freq_range->start_freq_khz; + if (edge_offset % ch_bw == 0) { + switch (KHZ_TO_MHZ(ch_bw)) { + case 1: + bw_flags |= IEEE80211_CHAN_1MHZ; + break; + case 2: + bw_flags |= IEEE80211_CHAN_2MHZ; + break; + case 4: + bw_flags |= IEEE80211_CHAN_4MHZ; + break; + case 8: + bw_flags |= IEEE80211_CHAN_8MHZ; + break; + case 16: + bw_flags |= IEEE80211_CHAN_16MHZ; + break; + default: + /* If we got here, no bandwidths fit on + * this frequency, ie. band edge. + */ + bw_flags |= IEEE80211_CHAN_DISABLED; + break; + } + break; + } + ch_bw /= 2; + } + } else { + if (max_bandwidth_khz < MHZ_TO_KHZ(10)) + bw_flags |= IEEE80211_CHAN_NO_10MHZ; + if (max_bandwidth_khz < MHZ_TO_KHZ(20)) + bw_flags |= IEEE80211_CHAN_NO_20MHZ; + if (max_bandwidth_khz < MHZ_TO_KHZ(40)) + bw_flags |= IEEE80211_CHAN_NO_HT40; + if (max_bandwidth_khz < MHZ_TO_KHZ(80)) + bw_flags |= IEEE80211_CHAN_NO_80MHZ; + if (max_bandwidth_khz < MHZ_TO_KHZ(160)) + bw_flags |= IEEE80211_CHAN_NO_160MHZ; + } return bw_flags; } -- 2.20.1