Skip to contentSkip to conversation

mt76: mt7921: add .set_sar_specs support

PATCH Superseded [email protected] 2 participants 2 messages Jun 21, 2021 – Jun 22, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

PATCH v2 1/1 mt76: mt7921: add .set_sar_specs support

From: YN Chen <[email protected]>

add .set_sar_specs to allow configuring SAR power limitations on the frequency ranges from the userland.

---
v2: 1. loop enhancement with considering no overlapping freqs
2. error handling for devm_kcalloc
3. sanity check without acquire lock

---
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++
 .../net/wireless/mediatek/mt76/mt76_connac.h  |  5 +++
 .../wireless/mediatek/mt76/mt76_connac_mcu.c  | 26 +++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/init.c  | 33 ++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 41 +++++++++++++++++++
 5 files changed, 105 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
index 25c5ceef5257..63ce5242c4d5 100644
@@ -636,6 +636,9 @@ struct mt76_phy {
 		struct sk_buff **tail;
 		u16 seqno;
 	} rx_amsdu[__MT_RXQ_MAX];
+
+	void *frp_data;
+	u8 num_frps;
 };
 
 struct mt76_dev {
drivers/net/wireless/mediatek/mt76/mt76_connac.h +5 -0
index f49d97d0a1c5..95c7d1cac7c4 100644
@@ -83,6 +83,11 @@ struct mt76_connac_coredump {
 	unsigned long last_activity;
 };
 
+struct mt76_connac_freq_range_power {
+	const struct cfg80211_sar_freq_ranges *range;
+	s8 power;
+};
+
 extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
 
 static inline bool is_mt7921(struct mt76_dev *dev)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +25 -1
index 5c3a81e5f559..497de1d91c7c 100644
@@ -1749,6 +1749,26 @@ mt76_connac_mcu_build_sku(struct mt76_dev *dev, s8 *sku,
 	}
 }
 
+static s8 mt76_connac_get_sar_power(struct mt76_phy *phy,
+				    struct ieee80211_channel *chan,
+				    s8 target_power)
+{
+	struct mt76_connac_freq_range_power *frp = phy->frp_data;
+	int freq, i;
+
+	freq = ieee80211_channel_to_frequency(chan->hw_value, chan->band);
+	for (i = 0 ; i < phy->num_frps; i++) {
+		if (frp[i].range &&
+		    freq >= frp[i].range->start_freq &&
+		    freq < frp[i].range->end_freq) {
+			target_power = min_t(s8, frp[i].power, target_power);
+			break;
+		}
+	}
+
+	return target_power;
+}
+
 static int
 mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
 				  enum nl80211_band band)
@@ -1816,9 +1836,13 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
 				.hw_value = ch_list[idx],
 				.band = band,
 			};
+			s8 sar_power;
+
+			sar_power = mt76_connac_get_sar_power(phy, &chan,
+							      tx_power);
 
 			mt76_get_rate_power_limits(phy, &chan, &limits,
-						   tx_power);
+						   sar_power);
 
 			tx_power_tlv.last_msg = ch_list[idx] == last_ch;
 			sku_tlbv.channel = ch_list[idx];
drivers/net/wireless/mediatek/mt76/mt7921/init.c +31 -2
index a9ce10b98827..c11a5b925209 100644
@@ -24,6 +24,20 @@ static const struct ieee80211_iface_combination if_comb[] = {
 	}
 };
 
+const struct cfg80211_sar_freq_ranges mt7921_sar_freq_ranges[] = {
+	{ .start_freq = 2402, .end_freq = 2494, },
+	{ .start_freq = 5150, .end_freq = 5350, },
+	{ .start_freq = 5350, .end_freq = 5470, },
+	{ .start_freq = 5470, .end_freq = 5725, },
+	{ .start_freq = 5725, .end_freq = 5950, },
+};
+
+static const struct cfg80211_sar_capa mt7921_sar_capa = {
+	.type = NL80211_SAR_TYPE_POWER,
+	.num_freq_ranges = ARRAY_SIZE(mt7921_sar_freq_ranges),
+	.freq_ranges = &mt7921_sar_freq_ranges[0],
+};
+
 static void
 mt7921_regd_notifier(struct wiphy *wiphy,
 		     struct regulatory_request *request)
@@ -41,7 +55,7 @@ mt7921_regd_notifier(struct wiphy *wiphy,
 	mt7921_mutex_release(dev);
 }
 
-static void
+static int
 mt7921_init_wiphy(struct ieee80211_hw *hw)
 {
 	struct mt7921_phy *phy = mt7921_hw_phy(hw);
@@ -75,6 +89,16 @@ mt7921_init_wiphy(struct ieee80211_hw *hw)
 	wiphy->max_sched_scan_reqs = 1;
 	wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
 	wiphy->reg_notifier = mt7921_regd_notifier;
+	wiphy->sar_capa = &mt7921_sar_capa;
+
+	phy->mt76->frp_data = devm_kcalloc(dev->mt76.dev,
+					   wiphy->sar_capa->num_freq_ranges,
+					   sizeof(struct mt76_connac_freq_range_power),
+					   GFP_KERNEL);
+	if (!phy->mt76->frp_data)
+		return -ENOMEM;
+
+	phy->mt76->num_frps = wiphy->sar_capa->num_freq_ranges;
 
 	wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
 			   NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
@@ -92,6 +116,8 @@ mt7921_init_wiphy(struct ieee80211_hw *hw)
 		ieee80211_hw_set(hw, CONNECTION_MONITOR);
 
 	hw->max_tx_fragments = 4;
+
+	return 0;
 }
 
 static void
@@ -207,7 +233,10 @@ int mt7921_register_device(struct mt7921_dev *dev)
 	if (ret)
 		return ret;
 
-	mt7921_init_wiphy(hw);
+	ret = mt7921_init_wiphy(hw);
+	if (ret)
+		return ret;
+
 	dev->mphy.sband_2g.sband.ht_cap.cap |=
 			IEEE80211_HT_CAP_LDPC_CODING |
 			IEEE80211_HT_CAP_MAX_AMSDU;
drivers/net/wireless/mediatek/mt76/mt7921/main.c +41 -0

51 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 122 lines · On Tue, 2021-06-22 at 07:07 +0800, [email protected] wrote:

From: YN Chen <[email protected]>

add .set_sar_specs to allow configuring SAR power limitations on the frequency ranges from the userland.

---
v2: 1. loop enhancement with considering no overlapping freqs
2. error handling for devm_kcalloc
3. sanity check without acquire lock

---
 drivers/net/wireless/mediatek/mt76/mt76.h     |  3 ++
 .../net/wireless/mediatek/mt76/mt76_connac.h  |  5 +++
 .../wireless/mediatek/mt76/mt76_connac_mcu.c  | 26 +++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/init.c  | 33 ++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 41
+++++++++++++++++++
 5 files changed, 105 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
index 25c5ceef5257..63ce5242c4d5 100644
@@ -636,6 +636,9 @@ struct mt76_phy {
 		struct sk_buff **tail;
 		u16 seqno;
 	} rx_amsdu[__MT_RXQ_MAX];
+
+	void *frp_data;
+	u8 num_frps;
 };
 
 struct mt76_dev {
drivers/net/wireless/mediatek/mt76/mt76_connac.h +5 -0
index f49d97d0a1c5..95c7d1cac7c4 100644
@@ -83,6 +83,11 @@ struct mt76_connac_coredump {
 	unsigned long last_activity;
 };
 
+struct mt76_connac_freq_range_power {
+	const struct cfg80211_sar_freq_ranges *range;
+	s8 power;
+};
+
 extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
 
 static inline bool is_mt7921(struct mt76_dev *dev)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +20 -0
index 5c3a81e5f559..497de1d91c7c 100644
@@ -1749,6 +1749,26 @@ mt76_connac_mcu_build_sku(struct mt76_dev
 *dev, s8 *sku,
 	}
 }
 
+static s8 mt76_connac_get_sar_power(struct mt76_phy *phy,
+				    struct ieee80211_channel *chan,
+				    s8 target_power)
+{
+	struct mt76_connac_freq_range_power *frp = phy->frp_data;
+	int freq, i;
+
+	freq = ieee80211_channel_to_frequency(chan->hw_value, chan-
 >band);
+	for (i = 0 ; i < phy->num_frps; i++) {
+		if (frp[i].range &&
+		    freq >= frp[i].range->start_freq &&
+		    freq < frp[i].range->end_freq) {
+			target_power = min_t(s8, frp[i].power,
 target_power);
+			break;
+		}
+	}
+
+	return target_power;
+}
+

static int mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,

drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +5 -1
 				  enum nl80211_band band)
@@ -1816,9 +1836,13 @@ mt76_connac_mcu_rate_txpower_band(struct
 mt76_phy *phy,
 				.hw_value = ch_list[idx],
 				.band = band,
 			};
+			s8 sar_power;
+
+			sar_power = mt76_connac_get_sar_power(phy,
 &chan,
+							      tx_power)
 ;
 
 			mt76_get_rate_power_limits(phy, &chan, &limits,
-						   tx_power);
+						   sar_power);

tx_power_tlv.last_msg = ch_list[idx] ==
last_ch;

drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +0 -0
 			sku_tlbv.channel = ch_list[idx];
drivers/net/wireless/mediatek/mt76/mt7921/init.c +5 -0
index a9ce10b98827..c11a5b925209 100644
@@ -24,6 +24,20 @@ static const struct ieee80211_iface_combination
 if_comb[] = {
 	}
 };
 
+const struct cfg80211_sar_freq_ranges mt7921_sar_freq_ranges[] = {
+	{ .start_freq = 2402, .end_freq = 2494, },
+	{ .start_freq = 5150, .end_freq = 5350, },
+	{ .start_freq = 5350, .end_freq = 5470, },
+	{ .start_freq = 5470, .end_freq = 5725, },

drivers/net/wireless/mediatek/mt76/mt7921/init.c static const struct ieee80211_iface_combination · line 42

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +9 -0
+	{ .start_freq = 5725, .end_freq = 5950, },
+};
+
+static const struct cfg80211_sar_capa mt7921_sar_capa = {
+	.type = NL80211_SAR_TYPE_POWER,
+	.num_freq_ranges = ARRAY_SIZE(mt7921_sar_freq_ranges),
+	.freq_ranges = &mt7921_sar_freq_ranges[0],
+};
+
 

Nowthat we have frps in mt76.h we can make these SAR chunk sharable as well to provide a common ground to other mt76 station devices might require set_sar_spec.

Ryder
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek