Skip to contentSkip to conversation

nl80211: add common API to configure SAR power limitations.

RFC In review Carl Huang 6 participants 20 messages Sep 22, 2020 – Nov 5, 2020

Subsystems (3)
lore
Share & tools
lore

Carl Huang

author
#0 lore raw

RFC 1/2 nl80211: add common API to configure SAR power limitations.

NL80211_CMD_SET_SAR_SPECS is added to configure SAR from user space. NL80211_ATTR_SAR_SPEC is used to pass the SAR power specification when used with NL80211_CMD_SET_SAR_SPECS.

Wireless driver needs to register SAR type, supported frequency ranges to wiphy, so user space can query it. The index in frequency range is used to specify which sub band the power limitation applies to. The SAR type is for compatibility, so later other SAR mechanism can be implemented without breaking the user space SAR applications.

Normal process is user space quries the SAR capability, and gets the index of supported frequency ranges and associates the power limitation with this index and sends to kernel.

Here is an example of message send to kernel:
8c 00 00 00 08 00 03 00 15 00 00 00 38 00 26 81
08 00 01 00 00 00 00 00 2c 00 02 80 14 00 01 80
05 00 02 00 00 00 00 00 05 00 01 00 38 00 00 00
14 00 02 80 05 00 02 00 01 00 00 00 05 00 01 00
48 00 00 00

NL80211_CMD_SET_SAR_SPECS:  0x8c
NL80211_ATTR_SAR_SPEC:  0x8126 (NLA_NESTED)
NL80211_SAR_ATTR_TYPE:  0x00 (NL80211_SAR_TYPE_POWER)
NL80211_SAR_ATTR_SPECS: 0x8002 (NLA_NESTED)
freq range 0 power: 0x38 in 0.25dbm unit (14dbm)
freq range 1 power: 0x48 in 0.25dbm unit (18dbm)
---
 include/net/cfg80211.h       |  52 +++++++++++++
 include/net/mac80211.h       |   2 +
 include/uapi/linux/nl80211.h |  86 +++++++++++++++++++++
 net/mac80211/cfg.c           |  12 +++
 net/wireless/nl80211.c       | 173 +++++++++++++++++++++++++++++++++++++++++++
 net/wireless/rdev-ops.h      |  12 +++
 net/wireless/trace.h         |  19 +++++
 7 files changed, 356 insertions(+)
include/net/cfg80211.h +52 -0
index c9bce9b..94f09dd 100644
@@ -1663,6 +1663,55 @@ struct station_info {
 	u8 connected_to_as;
 };
 
+/**
+ * struct cfg80211_sar_sub_specs - sub specs limit
+ * @power: value in 0.25dbm
+ * @freq_range_index: index the power limitation applies to
+ */
+struct cfg80211_sar_sub_specs {
+	u8 power;
+	u8 freq_range_index;
+};
+
+/**
+ * struct cfg80211_sar_specs - sar limit specs
+ * @type: it's set with power in 0.25dbm or other types
+ * @num_sub_specs: number of sar sub specs
+ * @sub_specs: memory to hold the sar sub specs
+ */
+struct cfg80211_sar_specs {
+	enum nl80211_sar_type type;
+	u16 num_sub_specs;
+	struct cfg80211_sar_sub_specs *sub_specs;
+};
+
+
+/**
+ * @struct cfg80211_sar_chan_ranges - sar frequency ranges
+ * @index: the index of this range. It's used to specify
+ *	the frequency range when setting SAR power limitation
+ * @start_freq:  start channel frequency in kHZ. For example,
+ *	2.4G channel 1 is represented as 2412000
+ * @end_freq:    end channel frequency in kHZ
+ */
+struct cfg80211_sar_freq_ranges {
+	u8 index;
+	u32 start_freq;
+	u32 end_freq;
+};
+
+/**
+ * struct cfg80211_sar_capa - sar limit capability
+ * @type: it's set via power in 0.25dbm or other types
+ * @num_freq_ranges: number of frequency ranges
+ * @chan_ranges: memory to hold the channel ranges.
+ */
+struct cfg80211_sar_capa {
+	enum nl80211_sar_type type;
+	u8 num_freq_ranges;
+	const struct cfg80211_sar_freq_ranges *freq_ranges;
+};
+
 #if IS_ENABLED(CONFIG_CFG80211)
 /**
  * cfg80211_get_station - retrieve information about a given station
@@ -4153,6 +4202,7 @@ struct cfg80211_ops {
 				  struct cfg80211_tid_config *tid_conf);
 	int	(*reset_tid_config)(struct wiphy *wiphy, struct net_device *dev,
 				    const u8 *peer, u8 tids);
+	int	(*set_sar_specs)(struct wiphy *wiphy, struct cfg80211_sar_specs *sar);
 };
 
 /*
@@ -4919,6 +4969,8 @@ struct wiphy {
 
 	u8 max_data_retry_count;
 
+	const struct cfg80211_sar_capa *sar_capa;
+
 	char priv[] __aligned(NETDEV_ALIGN);
 };
 
include/net/mac80211.h +2 -0
index ec148b3..df758ee 100644
@@ -4125,6 +4125,8 @@ struct ieee80211_ops {
 	int (*reset_tid_config)(struct ieee80211_hw *hw,
 				struct ieee80211_vif *vif,
 				struct ieee80211_sta *sta, u8 tids);
+	int (*set_sar_specs)(struct ieee80211_hw *hw,
+			     const struct cfg80211_sar_specs *sar);
 };
 
 /**
include/uapi/linux/nl80211.h +86 -0

114 lines not on this page · raw message

net/mac80211/cfg.c +12 -0
index b4e39e3..cc74322 100644
@@ -3993,6 +3993,17 @@ static int ieee80211_reset_tid_config(struct wiphy *wiphy,
 	return ret;
 }
 
+static int ieee80211_set_sar_specs(struct wiphy *wiphy,
+				   struct cfg80211_sar_specs *sar)
+{
+	struct ieee80211_local *local = wiphy_priv(wiphy);
+
+	if (!local->ops->set_sar_specs)
+		return -EOPNOTSUPP;
+
+	return local->ops->set_sar_specs(&local->hw, sar);
+}
+
 const struct cfg80211_ops mac80211_config_ops = {
 	.add_virtual_intf = ieee80211_add_iface,
 	.del_virtual_intf = ieee80211_del_iface,
@@ -4096,4 +4107,5 @@ const struct cfg80211_ops mac80211_config_ops = {
 	.probe_mesh_link = ieee80211_probe_mesh_link,
 	.set_tid_config = ieee80211_set_tid_config,
 	.reset_tid_config = ieee80211_reset_tid_config,
+	.set_sar_specs = ieee80211_set_sar_specs,
 };
net/wireless/nl80211.c +173 -0

215 lines not on this page · raw message

net/wireless/rdev-ops.h +12 -0
index 950d574..d9931c5 100644
@@ -1356,4 +1356,16 @@ static inline int rdev_reset_tid_config(struct cfg80211_registered_device *rdev,
 	return ret;
 }
 
+static inline int rdev_set_sar_specs(struct cfg80211_registered_device *rdev,
+				     struct cfg80211_sar_specs *sar)
+{
+	int ret;
+
+	trace_rdev_set_sar_specs(&rdev->wiphy, sar);
+	ret = rdev->ops->set_sar_specs(&rdev->wiphy, sar);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+
+	return ret;
+}
+
 #endif /* __CFG80211_RDEV_OPS */
net/wireless/trace.h +19 -0
index 6e218a0..116be64 100644
@@ -3547,6 +3547,25 @@ TRACE_EVENT(rdev_reset_tid_config,
 	TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", peer: " MAC_PR_FMT ", tids: 0x%x",
 		  WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(peer), __entry->tids)
 );
+
+TRACE_EVENT(rdev_set_sar_specs,
+	TP_PROTO(struct wiphy *wiphy, struct cfg80211_sar_specs *sar),
+	TP_ARGS(wiphy, sar),
+	TP_STRUCT__entry(
+		WIPHY_ENTRY
+		__field(u16, type)
+		__field(u16, num)
+	),
+	TP_fast_assign(
+		WIPHY_ASSIGN;
+		__entry->type = sar->type;
+		__entry->num = sar->num_sub_specs;
+
+	),
+	TP_printk(WIPHY_PR_FMT ", Set type:%d, num_specs:%d",
+		  WIPHY_PR_ARG, __entry->type, __entry->num)
+);
+
 #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
 
 #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.7.4
author
#1 lore raw

RFC 2/2 ath10k: allow dynamic SAR power limits via common API

ath10k assigns ath10k_mac_set_sar_specs to ath10k_ops, and this function is called when user space application calls NL80211_CMD_SET_SAR_SPECS. ath10k also registers SAR type, and supported frequency ranges to wiphy so user space can query SAR capabilities.

ath10k_mac_set_sar_specs further sets the power to firmware to limit the TX power.

This feature is controlled by hw parameter: dynamic_sar_support.

---
 drivers/net/wireless/ath/ath10k/core.c |  16 +++++
 drivers/net/wireless/ath/ath10k/core.h |   3 +
 drivers/net/wireless/ath/ath10k/hw.h   |   2 +
 drivers/net/wireless/ath/ath10k/mac.c  | 106 +++++++++++++++++++++++++++++++++
 4 files changed, 127 insertions(+)
drivers/net/wireless/ath/ath10k/core.c +16 -0
index 5f4e121..fe53ca9 100644
@@ -90,6 +90,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = true,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA988X_HW_2_0_VERSION,
@@ -124,6 +125,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = true,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9887_HW_1_0_VERSION,
@@ -159,6 +161,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA6174_HW_3_2_VERSION,
@@ -189,6 +192,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.tx_stats_over_pktlog = false,
 		.bmi_large_size_download = true,
 		.supports_peer_stats_info = true,
+		.dynamic_sar_support = true,
 	},
 	{
 		.id = QCA6174_HW_2_1_VERSION,
@@ -223,6 +227,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA6174_HW_2_1_VERSION,
@@ -257,6 +262,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA6174_HW_3_0_VERSION,
@@ -291,6 +297,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA6174_HW_3_2_VERSION,
@@ -329,6 +336,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.fw_diag_ce_download = true,
 		.tx_stats_over_pktlog = false,
 		.supports_peer_stats_info = true,
+		.dynamic_sar_support = true,
 	},
 	{
 		.id = QCA99X0_HW_2_0_DEV_VERSION,
@@ -369,6 +377,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9984_HW_1_0_DEV_VERSION,
@@ -416,6 +425,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9888_HW_2_0_DEV_VERSION,
@@ -460,6 +470,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9377_HW_1_0_DEV_VERSION,
@@ -494,6 +505,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9377_HW_1_1_DEV_VERSION,
@@ -530,6 +542,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = true,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA9377_HW_1_1_DEV_VERSION,
@@ -557,6 +570,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.ast_skid_limit = 0x10,
 		.num_wds_entries = 0x20,
 		.uart_pin_workaround = true,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = QCA4019_HW_1_0_DEV_VERSION,
@@ -598,6 +612,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = true,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = false,
 	},
 	{
 		.id = WCN3990_HW_1_0_DEV_VERSION,
@@ -625,6 +640,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.hw_filter_reset_required = false,
 		.fw_diag_ce_download = false,
 		.tx_stats_over_pktlog = false,
+		.dynamic_sar_support = true,
 	},
 };
 
drivers/net/wireless/ath/ath10k/core.h +3 -0
index 4cf5bd4..f90c34a 100644
@@ -1281,6 +1281,9 @@ struct ath10k {
 	bool coex_support;
 	int coex_gpio_pin;
 
+	u32 tx_power_2g_limit;
+	u32 tx_power_5g_limit;
+
 	/* must be last */
 	u8 drv_priv[] __aligned(sizeof(void *));
 };
drivers/net/wireless/ath/ath10k/hw.h +2 -0
index c6ded21..6b03c77 100644
@@ -623,6 +623,8 @@ struct ath10k_hw_params {
 
 	/* provides bitrates for sta_statistics using WMI_TLV_PEER_STATS_INFO_EVENTID */
 	bool supports_peer_stats_info;
+
+	bool dynamic_sar_support;
 };
 
 struct htt_rx_desc;
drivers/net/wireless/ath/ath10k/mac.c +106 -0

136 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

Re: [RFC 2/2] ath10k: allow dynamic SAR power limits via common API

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Carl,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on ath6kl/ath-next]
[cannot apply to mac80211-next/master mac80211/master v5.9-rc6 next-20200921] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Carl-Huang/nl80211-add-common-API-to-configure-SAR-power-limitations/20200922-135108
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git ath-next
config: i386-randconfig-a006-20200921 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/net/wireless/ath/ath10k/mac.c:2906:5: warning: no previous prototype for 'ath10k_mac_set_sar_power' [-Wmissing-prototypes]
    2906 | int ath10k_mac_set_sar_power(struct ath10k *ar)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~

# https://github.com/0day-ci/linux/commit/194580acc67fccc13b7f388334db0ec31897ab5a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Carl-Huang/nl80211-add-common-API-to-configure-SAR-power-limitations/20200922-135108 git checkout 194580acc67fccc13b7f388334db0ec31897ab5a
vim +/ath10k_mac_set_sar_power +2906 drivers/net/wireless/ath/ath10k/mac.c

2905

> 2906	int ath10k_mac_set_sar_power(struct ath10k *ar)

2907 {
2908 int ret;
2909
2910 if (!ar->hw_params.dynamic_sar_support)
2911 return 0;
2912
2913 if (ar->tx_power_2g_limit == 0 || ar->tx_power_5g_limit == 0)
2914 return 0;
2915
2916 if (!ath10k_mac_is_connected(ar))
2917 return 0;
2918
2919 ret = ath10k_wmi_pdev_set_param(ar,
2920 ar->wmi.pdev_param->txpower_limit2g,
2921 ar->tx_power_2g_limit);
2922 if (ret) {
2923 ath10k_warn(ar, "failed to set 2.4G txpower %d: %d\n",
2924 ar->tx_power_2g_limit, ret);
2925 return ret;
2926 }
2927
2928 ret = ath10k_wmi_pdev_set_param(ar,
2929 ar->wmi.pdev_param->txpower_limit5g,
2930 ar->tx_power_5g_limit);
2931 if (ret) {
2932 ath10k_warn(ar, "failed to set 5G txpower %d: %d\n",
2933 ar->tx_power_5g_limit, ret);
2934 return ret;
2935 }
2936
2937 ath10k_dbg(ar, ATH10K_DBG_MAC, "set txpower 2G:%d, 5G:%d successfully\n",
2938 ar->tx_power_2g_limit, ar->tx_power_5g_limit);
2939
2940 return ret;
2941 }
2942

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [RFC 2/2] ath10k: allow dynamic SAR power limits via common API

In reply to Carl Huang
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Carl,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on ath6kl/ath-next]
[cannot apply to mac80211-next/master mac80211/master v5.9-rc6 next-20200922] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Carl-Huang/nl80211-add-common-API-to-configure-SAR-power-limitations/20200922-135108
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git ath-next
config: x86_64-randconfig-a012-20200922 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 6a6b06f5262bb96523eceef4a42fe8e60ae2a630)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/net/wireless/ath/ath10k/mac.c:2906:5: warning: no previous prototype for function 'ath10k_mac_set_sar_power' [-Wmissing-prototypes]
   int ath10k_mac_set_sar_power(struct ath10k *ar)
       ^

drivers/net/wireless/ath/ath10k/mac.c:2906:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int ath10k_mac_set_sar_power(struct ath10k *ar)
^
static
1 warning generated.

# https://github.com/0day-ci/linux/commit/194580acc67fccc13b7f388334db0ec31897ab5a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Carl-Huang/nl80211-add-common-API-to-configure-SAR-power-limitations/20200922-135108 git checkout 194580acc67fccc13b7f388334db0ec31897ab5a
vim +/ath10k_mac_set_sar_power +2906 drivers/net/wireless/ath/ath10k/mac.c

2905

> 2906	int ath10k_mac_set_sar_power(struct ath10k *ar)

2907 {
2908 int ret;
2909
2910 if (!ar->hw_params.dynamic_sar_support)
2911 return 0;
2912
2913 if (ar->tx_power_2g_limit == 0 || ar->tx_power_5g_limit == 0)
2914 return 0;
2915
2916 if (!ath10k_mac_is_connected(ar))
2917 return 0;
2918
2919 ret = ath10k_wmi_pdev_set_param(ar,
2920 ar->wmi.pdev_param->txpower_limit2g,
2921 ar->tx_power_2g_limit);
2922 if (ret) {
2923 ath10k_warn(ar, "failed to set 2.4G txpower %d: %d\n",
2924 ar->tx_power_2g_limit, ret);
2925 return ret;
2926 }
2927
2928 ret = ath10k_wmi_pdev_set_param(ar,
2929 ar->wmi.pdev_param->txpower_limit5g,
2930 ar->tx_power_5g_limit);
2931 if (ret) {
2932 ath10k_warn(ar, "failed to set 5G txpower %d: %d\n",
2933 ar->tx_power_5g_limit, ret);
2934 return ret;
2935 }
2936
2937 ath10k_dbg(ar, ATH10K_DBG_MAC, "set txpower 2G:%d, 5G:%d successfully\n",
2938 ar->tx_power_2g_limit, ar->tx_power_5g_limit);
2939
2940 return ret;
2941 }
2942

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#7 lore raw
In reply to Carl Huang
Quoted 4 lines · Carl Huang

NL80211_CMD_SET_SAR_SPECS is added to configure SAR from user space. NL80211_ATTR_SAR_SPEC is used to pass the SAR power specification when used with NL80211_CMD_SET_SAR_SPECS.

Quoted 8 lines

Wireless driver needs to register SAR type, supported frequency ranges to wiphy, so user space can query it. The index in frequency range is used to specify which sub band the power limitation applies to. The SAR type is for compatibility, so later other SAR mechanism can be implemented without breaking the user space SAR applications.

Normal process is user space quries the SAR capability, and

typo: queries

Quoted 9 lines

gets the index of supported frequency ranges and associates the power limitation with this index and sends to kernel.

Here is an example of message send to kernel:
8c 00 00 00 08 00 03 00 15 00 00 00 38 00 26 81
08 00 01 00 00 00 00 00 2c 00 02 80 14 00 01 80
05 00 02 00 00 00 00 00 05 00 01 00 38 00 00 00
14 00 02 80 05 00 02 00 01 00 00 00 05 00 01 00
48 00 00 00

Heh, that's not super useful, though that doesn't matter much I guess :)

Quoted 6 lines
NL80211_CMD_SET_SAR_SPECS:  0x8c
NL80211_ATTR_SAR_SPEC:  0x8126 (NLA_NESTED)
NL80211_SAR_ATTR_TYPE:  0x00 (NL80211_SAR_TYPE_POWER)
NL80211_SAR_ATTR_SPECS: 0x8002 (NLA_NESTED)
freq range 0 power: 0x38 in 0.25dbm unit (14dbm)
freq range 1 power: 0x48 in 0.25dbm unit (18dbm)

that makes more sense :)

Quoted 3 lines

+/**
+ * struct cfg80211_sar_sub_specs - sub specs limit
+ * @power: value in 0.25dbm

I guess the documentation should state that it's a power limit, or something?

Quoted 7 lines

+ * @freq_range_index: index the power limitation applies to
+ */

include/net/cfg80211.h +5 -0
+struct cfg80211_sar_sub_specs {
+	u8 power;
+	u8 freq_range_index;
+};
+

include/net/cfg80211.h struct station_info { · line 1685

Quoted 10 lines
include/net/cfg80211.h +10 -0
+/**
+ * struct cfg80211_sar_specs - sar limit specs
+ * @type: it's set with power in 0.25dbm or other types
+ * @num_sub_specs: number of sar sub specs
+ * @sub_specs: memory to hold the sar sub specs
+ */
+struct cfg80211_sar_specs {
+	enum nl80211_sar_type type;
+	u16 num_sub_specs;
+	struct cfg80211_sar_sub_specs *sub_specs;

Wouldn't it make more sense to just have sub_specs[] and inline? The pointers here are bigger than many of the sub-specs I guess...

Also, is num_sub_specs even needed? It seems we could just require that userspace sends all of them all the time?

include/net/cfg80211.h struct station_info { · line 1698

Quoted 2 lines
include/net/cfg80211.h +2 -0
+struct cfg80211_sar_freq_ranges {
+	u8 index;

Does an index here make sense?

Quoted 4 lines
include/net/cfg80211.h +4 -0
+	u32 start_freq;
+	u32 end_freq;
+};
+

include/net/cfg80211.h struct station_info { · line 1712

Quoted 10 lines
include/net/cfg80211.h +10 -0
+/**
+ * struct cfg80211_sar_capa - sar limit capability
+ * @type: it's set via power in 0.25dbm or other types
+ * @num_freq_ranges: number of frequency ranges
+ * @chan_ranges: memory to hold the channel ranges.
+ */
+struct cfg80211_sar_capa {
+	enum nl80211_sar_type type;
+	u8 num_freq_ranges;
+	const struct cfg80211_sar_freq_ranges *freq_ranges;

You end up with an array here, so some kind of index is implicit, the array index. I don't see why you'd want to have a separate index *within* the frequency range, then you just have to check those make sense, etc.?

Quoted 3 lines

+ * @NL80211_ATTR_SAR_SPEC: SAR power limitation specification when
+ * used with %NL80211_CMD_SET_SAR_SPECS. It contains array of
+ * %nl80211_sar_specs_attrs.

I think I know what you mean (a nested array where each item has attributes from &enum nl80211_sar_specs_attrs), but could state that a bit clearer.

Quoted 1 line

+#define NL80211_SAR_ALL_FREQ_RNAGES 0xff

typo

Quoted 1 line

+#define NUM_MAX_NL80211_SAR_FREQ_RANGES 0xfe

but I'm not sure what these are used for in the first place, they seem more like internal implementation details?

Quoted 10 lines

+/**
+ * nl80211_sar_specs_attrs - Attributes for SAR power limit specs
+ *
+ * @NL80211_SAR_ATTR_SPECS_POWER: Required (u32)value to specify the actual
+ * power limit value in units of 0.25 dBm if type is
+ * NL80211_SAR_TYPE_POWER. (i.e., a value of 44 represents 11 dBm)
+ *
+ * @NL80211_SAR_ATTR_SPECS_FREQ_RANGES_INDEX: optional (u32) value to specify the
+ * index of exported freq ranges table. If this attribute is not present, then
+ * the power is applied to all freq ranges, i.e, all bands

Especially since this says "[i]f this attribute is not present".

Does that make sense though? It seems possible to just use the nesting entry as the index, and just require userspace to set up all indexes if it wants to apply to all of them, why bother having to deal with that case in the kernel and perhaps even drivers?

Quoted 2 lines

+ * @NL80211_SAR_ATTR_SPECS_START_FREQ: Required (u32) value to specify the start
+ * frequency of this range to register SAR capability to wihpy and the unit

typo: wiphy

Quoted 1 line

+ * is kHZ

kHz

Quoted 3 lines

+ *
+ * @NL80211_SAR_ATTR_SPECS_END_FREQ: Required (u32) value to specify the end frequency
+ * of this range to register SAR capability to wiphy and the unit is kHZ

kHz

But hm, are you mixing the capability advertisement and the actual request into the same attributes? Perhaps that makes sense, but the documentation could be a bit clearer IMHO.

Quoted 1 line

+++ b/net/mac80211/cfg.c

The mac80211 bits could probably be in a separate patch, just for clarity.

net/wireless/nl80211.c nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { · line 372

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+static const struct nla_policy
+sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = {
+		[NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_U8 },

double indentation?

net/wireless/nl80211.c nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { · line 374

Quoted 2 lines
net/wireless/nl80211.c +2 -0
+		[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX] =
+			NLA_POLICY_MAX(NLA_U8, NUM_MAX_NL80211_SAR_FREQ_RANGES),

I don't see a good reason to limit to 0xfe? The kernel could just use a wider datatype internally.

Anyway, I'm not sure the attribute is even needed, see above.

net/wireless/nl80211.c static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, · line 1873

Quoted 5 lines
net/wireless/nl80211.c +1 -0
@@ -1856,6 +1870,8 @@ static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
 			goto nla_put_failure;
 	}
 
+	CMD(set_sar_specs, SET_SAR_SPECS);

Don't add to _unsplit() please.

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2073

Quoted 1 line
net/wireless/nl80211.c +1 -0
+	specs = nla_nest_start_noflag(msg, NL80211_SAR_ATTR_SPECS);

Don't use _noflag() please, that's just for backward compatibility.

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2079

Quoted 6 lines
net/wireless/nl80211.c +6 -0
+	if (!specs)
+		goto fail;
+
+	/* report supported freq_ranges */
+	for (i = 0; i < num_freq_ranges; i++) {
+		sub_freq_range = nla_nest_start_noflag(msg, i + 1);

Same here.

net/wireless/nl80211.c static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, · line 2667

Quoted 6 lines
net/wireless/nl80211.c +2 -0
@@ -2598,6 +2663,9 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
 		if (nl80211_put_tid_config_support(rdev, msg))
 			goto nla_put_failure;
 
+		if (nl80211_put_sar_specs(rdev, msg))
+			goto nla_put_failure;

Perhaps better to have a separate message (case entry) since it might get fairly big?

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14582

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+	sar_spec = kzalloc(sizeof(*sar_spec) +
+			   specs * sizeof(struct cfg80211_sar_sub_specs),
+			   GFP_KERNEL);
+	if (!sar_spec)
+		return -ENOMEM;
+
+	sar_spec->sub_specs = (struct cfg80211_sar_sub_specs *)
+			((char *)sar_spec + sizeof(*sar_spec));

If you anyway set the pointer there then you can actually just make it a [] array instead of having the pointer in the first place ... would be equivalent but save you from these contortions :)

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+	specs = 0;
+	sar_spec->type = type;
+
+	nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
+		if (nla_parse(spec,
+			      NL80211_SAR_ATTR_SPECS_MAX,
+			      nla_data(spec_list),
+			      nla_len(spec_list),
+			      sar_specs_policy,
+			      NULL)) {

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14602

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+			err = -EINVAL;
+			goto error;
+		}
+
+		/* for power type, power value must be presented */
+		if (!spec[NL80211_SAR_ATTR_SPECS_POWER] &&
+		    type == NL80211_SAR_TYPE_POWER) {
+			err = -EINVAL;
+			goto error;
+		}

Somewhere you should probably also check that the type matches the advertised type.

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+		power = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_POWER]);
+		sar_spec->sub_specs[specs].power = power;
+
+		/* if NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX isn't present,
+		 * then the power applies to all bands. But it's only valid
+		 * for the first entry.
+		 */
+		if (!spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]) {

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14621

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+			if (specs) {
+				err = -EINVAL;
+				goto error;
+			} else {
+				sar_spec->sub_specs[specs].freq_range_index =
+					NL80211_SAR_ALL_FREQ_RNAGES;
+				specs++;
+				break;
+			}
+		}

Yeah... not sure I see this as being worth it, vs. userspace just filling all the possible entries.

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14634

Quoted 12 lines
net/wireless/nl80211.c +12 -0
+		index = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]);
+		sar_spec->sub_specs[specs].freq_range_index = index;
+		specs++;
+	}
+
+	sar_spec->num_sub_specs = specs;
+
+	rdev->cur_cmd_info = info;
+	if (rdev->ops->set_sar_specs)
+		err = rdev_set_sar_specs(rdev, sar_spec);
+	else
+		err = -EOPNOTSUPP;

Might be worth checking this early and avoiding the allocation and all?

OTOH, that gives you error checking even if the driver was completely confused and advertised sar specs without the method ...

johannes

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#9 lore raw

From: [email protected]

There are few more additional comments here.

Quoted 3 lines

+ * @NL80211_CMD_SET_SAR_SPECS: SAR power limitation configuration is
+ *     passed using %NL80211_ATTR_SAR_SPEC.
+ *

This command requires NL80211_ATTR_IFINDEX, probably should be better to add this in the comment ?

Quoted 6 lines
net/wireless/nl80211.c +6 -0
+static int
+nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
+                     struct sk_buff *msg)
+{
+       struct nlattr *sar_capa, *specs, *sub_freq_range;
+       u8  num_freq_ranges;

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2068

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+       int i;
+
+       if (!rdev->wiphy.sar_capa)
+               return 0;
+
+       num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
+
+       sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
+       if (!sar_capa)
+               return -ENOSPC;

I see some places nla_nest_start_noflag being used and here nla_nest_start. Whats the specific reason to do that ? In the newer Kernel versions, I believe nla_nest_start is preferred.

Quoted 10 lines

+               power = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_POWER]);
+               sar_spec->sub_specs[specs].power = power;
+
+               /* if NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX isn't present,
+                * then the power applies to all bands. But it's only valid
+                * for the first entry.
+                */
+               if (!spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]) {
+                       if (specs) {
+                               err = -EINVAL;

Quoted 8 lines

+                               goto error;
+                       } else {
+                               sar_spec->sub_specs[specs].freq_range_index =
+                                       NL80211_SAR_ALL_FREQ_RNAGES;
+                               specs++;
+                               break;
+                       }
+               }

Here I see you are assigning same power to all freq band if for the first band the freq index is not provided. Is there any specific reason to only check the first here ? Probably this logic should move into specific drivers. Thoughts ?

-Abhishek

author
#10 lore raw
Quoted 10 lines · Abhishek Kumar

From: [email protected]

There are few more additional comments here.

Quoted 3 lines

+ * @NL80211_CMD_SET_SAR_SPECS: SAR power limitation configuration is
+ *     passed using %NL80211_ATTR_SAR_SPEC.
+ *

This command requires NL80211_ATTR_IFINDEX, probably should be better to add this in the comment ?

Per Johannes's comments, this explicit index is not required. Are you fine with it?

Instead, user-space application records the array index when querying the SAR capability. When set, the nested array index will be used to set the power. This requires user-space has a strict mapping of index. and NL80211_ATTR_IFINDEX is to be removed.

Quoted 12 lines
Quoted 12 lines
net/wireless/nl80211.c +12 -0
+static int
+nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
+                     struct sk_buff *msg)
+{
+       struct nlattr *sar_capa, *specs, *sub_freq_range;
+       u8  num_freq_ranges;
+       int i;
+
+       if (!rdev->wiphy.sar_capa)
+               return 0;
+
+       num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
Quoted 9 lines
Quoted 4 lines

+
+       sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
+       if (!sar_capa)
+               return -ENOSPC;

I see some places nla_nest_start_noflag being used and here nla_nest_start. Whats the specific reason to do that ? In the newer Kernel versions, I believe nla_nest_start is preferred.

This will be addressed in next version.

Quoted 23 lines
Quoted 14 lines

+               power = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_POWER]);
+               sar_spec->sub_specs[specs].power = power; +
+               /* if NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX isn't present,
+                * then the power applies to all bands. But it's only valid
+                * for the first entry.
+                */
+               if (!spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]) {
+                       if (specs) {
+                               err = -EINVAL;
+                               goto error;

Quoted 8 lines

+                       } else {
+
sar_spec->sub_specs[specs].freq_range_index =
+                                       NL80211_SAR_ALL_FREQ_RNAGES;
+                               specs++;
+                               break;
+                       }
+               }

Quoted 5 lines

Here I see you are assigning same power to all freq band if for the first band the freq index is not provided. Is there any specific reason to only check the first
here ? Probably this logic should move into specific drivers. Thoughts ?

This logic will be removed per Johannes's comments.

Please read Johannes's comments. If you agree with him and has no other advices, then I will post the second version of it.

Quoted 7 lines

-Abhishek

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

maintainer
#11 lore raw
Quoted 15 lines · Carl Huang
Quoted 11 lines · Abhishek Kumar

From: [email protected]

There are few more additional comments here.

Quoted 3 lines

+ * @NL80211_CMD_SET_SAR_SPECS: SAR power limitation configuration is
+ * passed using %NL80211_ATTR_SAR_SPEC.
+ *

This command requires NL80211_ATTR_IFINDEX, probably should be better to add
this in the comment ?

Per Johannes's comments, this explicit index is not required. Are you fine with it?

Quoted 7 lines

Instead, user-space application records the array index when querying the SAR
capability. When set, the nested array index will be used to set the power.
This requires user-space has a strict mapping of index. and NL80211_ATTR_IFINDEX
is to be removed.

Wait, what? The IFINDEX is still required, that identifies the interface
- though it probably shouldn't be required, this should be per wiphy, so you could also use ATTR_WIPHY_IDX?

You're thinking of ... something
else. NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX perhaps?

johannes

#12 lore raw
Quoted 25 lines · Johannes Berg
Quoted 15 lines · Carl Huang
Quoted 11 lines · Abhishek Kumar

From: [email protected]

There are few more additional comments here.

Quoted 3 lines

+ * @NL80211_CMD_SET_SAR_SPECS: SAR power limitation configuration is
+ * passed using %NL80211_ATTR_SAR_SPEC.
+ *

This command requires NL80211_ATTR_IFINDEX, probably should be better to add
this in the comment ?

Per Johannes's comments, this explicit index is not required. Are you fine with it?

Quoted 7 lines

Instead, user-space application records the array index when querying the SAR
capability. When set, the nested array index will be used to set the power.
This requires user-space has a strict mapping of index. and NL80211_ATTR_IFINDEX
is to be removed.

Quoted 6 lines

Wait, what? The IFINDEX is still required, that identifies the interface
- though it probably shouldn't be required, this should be per wiphy, so you could also use ATTR_WIPHY_IDX?

You're thinking of ... something
else. NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX perhaps?

Yes, probably the index mapping that you are talking about is using NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX .

I think Johannes has already covered most of the comments. I have one last one mentioned below.

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
+                     struct sk_buff *msg)
+{
+       struct nlattr *sar_capa, *specs, *sub_freq_range;
+       u8  num_freq_ranges;
+       int i;
+
+       if (!rdev->wiphy.sar_capa)

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2071

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+               return 0;
+
+       num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
+
+       sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
+       if (!sar_capa)
+               return -ENOSPC;
+
+       if (nla_put_u16(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type))
+               goto fail;

The nla_put_u16 NL80211_SAR_ATTR_TYPE here uses u16 whereas in the to get this property below it uses nla_get_u32 . I think this should be consistent ?

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14569

Quoted 7 lines
net/wireless/nl80211.c +7 -0
+       if (!tb[NL80211_SAR_ATTR_TYPE])
+               return -EINVAL;
+
+       type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]);
+
+       if (!tb[NL80211_SAR_ATTR_SPECS])
+               return -EINVAL;

As mentioned above the get and put for NL80211_SAR_ATTR_TYPE is not consistent.

-Abhishek

author
#13 lore raw
Quoted 31 lines · Abhishek Kumar
Quoted 30 lines · Johannes Berg
Quoted 15 lines · Carl Huang
Quoted 11 lines · Abhishek Kumar

From: [email protected]

There are few more additional comments here.

Quoted 3 lines

+ * @NL80211_CMD_SET_SAR_SPECS: SAR power limitation configuration is
+ * passed using %NL80211_ATTR_SAR_SPEC.
+ *

This command requires NL80211_ATTR_IFINDEX, probably should be better to add
this in the comment ?

Per Johannes's comments, this explicit index is not required. Are you fine with it?

Quoted 7 lines

Instead, user-space application records the array index when querying the SAR
capability. When set, the nested array index will be used to set the power.
This requires user-space has a strict mapping of index. and NL80211_ATTR_IFINDEX
is to be removed.

Wait, what? The IFINDEX is still required, that identifies the interface
- though it probably shouldn't be required, this should be per wiphy, so
you could also use ATTR_WIPHY_IDX?

Quoted 6 lines
Quoted 2 lines

You're thinking of ... something
else. NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX perhaps?

Yes, probably the index mapping that you are talking about is using NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX .

You're right. I just remembered Johannes's comments to remove the NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX and made mistake here.

Quoted 27 lines

I think Johannes has already covered most of the comments. I have one last one mentioned below.

Quoted 17 lines
(quoted diff) +17 -0
+nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
+                     struct sk_buff *msg)
+{
+       struct nlattr *sar_capa, *specs, *sub_freq_range;
+       u8  num_freq_ranges;
+       int i;
+
+       if (!rdev->wiphy.sar_capa)
+               return 0;
+
+       num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
+
+       sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
+       if (!sar_capa)
+               return -ENOSPC;
+
+       if (nla_put_u16(msg, NL80211_SAR_ATTR_TYPE, 
Quoted 2 lines

rdev->wiphy.sar_capa->type))
+ goto fail;

The nla_put_u16 NL80211_SAR_ATTR_TYPE here uses u16 whereas in the to get this property below it uses nla_get_u32 . I think this should be consistent ?

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+       if (!tb[NL80211_SAR_ATTR_TYPE])
+               return -EINVAL;
+
+       type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]);
+
+       if (!tb[NL80211_SAR_ATTR_SPECS])
+               return -EINVAL;

As mentioned above the get and put for NL80211_SAR_ATTR_TYPE is not consistent.

Correct. Thanks for pointing out and it will be fixed in next version.

Quoted 6 lines

-Abhishek

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

author
#14 lore raw
In reply to Johannes Berg
Quoted 12 lines · Johannes Berg
Quoted 11 lines · Carl Huang

NL80211_CMD_SET_SAR_SPECS is added to configure SAR from user space. NL80211_ATTR_SAR_SPEC is used to pass the SAR power specification when used with NL80211_CMD_SET_SAR_SPECS.

Wireless driver needs to register SAR type, supported frequency ranges to wiphy, so user space can query it. The index in frequency range is used to specify which sub band the power limitation applies to. The SAR type is for compatibility, so later other SAR mechanism can be implemented without breaking the user space SAR applications.

Quoted 4 lines
Quoted 1 line

Normal process is user space quries the SAR capability, and

typo: queries

sure, I'll fix it in v2.

Quoted 12 lines
Quoted 9 lines

gets the index of supported frequency ranges and associates the power limitation with this index and sends to kernel.

Here is an example of message send to kernel:
8c 00 00 00 08 00 03 00 15 00 00 00 38 00 26 81
08 00 01 00 00 00 00 00 2c 00 02 80 14 00 01 80
05 00 02 00 00 00 00 00 05 00 01 00 38 00 00 00
14 00 02 80 05 00 02 00 01 00 00 00 05 00 01 00
48 00 00 00

Heh, that's not super useful, though that doesn't matter much I guess :)

Quoted 9 lines
Quoted 6 lines
NL80211_CMD_SET_SAR_SPECS:  0x8c
NL80211_ATTR_SAR_SPEC:  0x8126 (NLA_NESTED)
NL80211_SAR_ATTR_TYPE:  0x00 (NL80211_SAR_TYPE_POWER)
NL80211_SAR_ATTR_SPECS: 0x8002 (NLA_NESTED)
freq range 0 power: 0x38 in 0.25dbm unit (14dbm)
freq range 1 power: 0x48 in 0.25dbm unit (18dbm)

that makes more sense :)

As this is an explanation of the message above, is it good to keep the message?

Quoted 28 lines
Quoted 3 lines

+/**
+ * struct cfg80211_sar_sub_specs - sub specs limit
+ * @power: value in 0.25dbm

I guess the documentation should state that it's a power limit, or something?

Quoted 7 lines

+ * @freq_range_index: index the power limitation applies to
+ */

include/net/cfg80211.h +5 -0
+struct cfg80211_sar_sub_specs {
+	u8 power;
+	u8 freq_range_index;
+};
+

include/net/cfg80211.h struct station_info { · line 1685

Quoted 10 lines
include/net/cfg80211.h +10 -0
+/**
+ * struct cfg80211_sar_specs - sar limit specs
+ * @type: it's set with power in 0.25dbm or other types
+ * @num_sub_specs: number of sar sub specs
+ * @sub_specs: memory to hold the sar sub specs
+ */
+struct cfg80211_sar_specs {
+	enum nl80211_sar_type type;
+	u16 num_sub_specs;
+	struct cfg80211_sar_sub_specs *sub_specs;

Wouldn't it make more sense to just have sub_specs[] and inline? The pointers here are bigger than many of the sub-specs I guess...

Quoted 3 lines

Also, is num_sub_specs even needed? It seems we could just require that userspace sends all of them all the time?

Agree as long as user space sends all of them.

Quoted 5 lines

include/net/cfg80211.h struct station_info { · line 1698

Quoted 2 lines
include/net/cfg80211.h +2 -0
+struct cfg80211_sar_freq_ranges {
+	u8 index;

Does an index here make sense?

With agreement from Google, it's OK to remove it.

Quoted 20 lines
Quoted 4 lines
include/net/cfg80211.h +4 -0
+	u32 start_freq;
+	u32 end_freq;
+};
+

include/net/cfg80211.h struct station_info { · line 1712

Quoted 10 lines
include/net/cfg80211.h +10 -0
+/**
+ * struct cfg80211_sar_capa - sar limit capability
+ * @type: it's set via power in 0.25dbm or other types
+ * @num_freq_ranges: number of frequency ranges
+ * @chan_ranges: memory to hold the channel ranges.
+ */
+struct cfg80211_sar_capa {
+	enum nl80211_sar_type type;
+	u8 num_freq_ranges;
+	const struct cfg80211_sar_freq_ranges *freq_ranges;

You end up with an array here, so some kind of index is implicit, the array index. I don't see why you'd want to have a separate index *within* the frequency range, then you just have to check those make sense, etc.?

Quoted 8 lines
Quoted 3 lines

+ * @NL80211_ATTR_SAR_SPEC: SAR power limitation specification when
+ * used with %NL80211_CMD_SET_SAR_SPECS. It contains array of
+ * %nl80211_sar_specs_attrs.

I think I know what you mean (a nested array where each item has attributes from &enum nl80211_sar_specs_attrs), but could state that a bit clearer.

I'll try to describe it more clear in v2.

Quoted 4 lines
Quoted 1 line

+#define NL80211_SAR_ALL_FREQ_RNAGES 0xff

typo

sure, will fix in v2.

Quoted 5 lines
Quoted 1 line

+#define NUM_MAX_NL80211_SAR_FREQ_RANGES 0xfe

but I'm not sure what these are used for in the first place, they seem more like internal implementation details?

In v1 design, userspace doesn't need to specify all the sub bands if the a power limitation applies to all sub bands, so NL80211_SAR_ALL_FREQ_RNAGES is defined for this purpose. To distinguish from NL80211_SAR_ALL_FREQ_RNAGES, the maximum number of freq ranges should not exceed (NL80211_SAR_ALL_FREQ_RNAGES - 1), so define NUM_MAX_NL80211_SAR_FREQ_RANGES as 0xfe.

It's right these two definitions are internal, userspace doesn't use them.

Again as user-space will sends all the ranges, let me remove these 2 definitions.

Quoted 14 lines
Quoted 5 lines

+/**
+ * nl80211_sar_specs_attrs - Attributes for SAR power limit specs
+ *
+ * @NL80211_SAR_ATTR_SPECS_POWER: Required (u32)value to specify the actual

Quoted 8 lines

+ * power limit value in units of 0.25 dBm if type is
+ * NL80211_SAR_TYPE_POWER. (i.e., a value of 44 represents 11 dBm)
+ *
+ * @NL80211_SAR_ATTR_SPECS_FREQ_RANGES_INDEX: optional (u32) value to specify the
+ * index of exported freq ranges table. If this attribute is not
present, then
+ * the power is applied to all freq ranges, i.e, all bands

Quoted 7 lines

Especially since this says "[i]f this attribute is not present".

Does that make sense though? It seems possible to just use the nesting entry as the index, and just require userspace to set up all indexes if it wants to apply to all of them, why bother having to deal with that case in the kernel and perhaps even drivers?

Ok, let me drop it in v2.

Johannes, want to confirm with you "nesting entry as the index". Do you mean that kernel take the first entry as index 0, then second entry as index 1 and etc?

Quoted 11 lines
Quoted 4 lines

+ * @NL80211_SAR_ATTR_SPECS_START_FREQ: Required (u32) value to specify the start
+ * frequency of this range to register SAR capability to wihpy and
the unit

typo: wiphy

Quoted 1 line

+ * is kHZ

kHz

Will fix it in v2.

Quoted 23 lines
Quoted 5 lines

+ *
+ * @NL80211_SAR_ATTR_SPECS_END_FREQ: Required (u32) value to specify the end frequency
+ * of this range to register SAR capability to wiphy and the unit is
kHZ

kHz

But hm, are you mixing the capability advertisement and the actual request into the same attributes? Perhaps that makes sense, but the documentation could be a bit clearer IMHO.

Quoted 1 line

+++ b/net/mac80211/cfg.c

The mac80211 bits could probably be in a separate patch, just for clarity.

net/wireless/nl80211.c nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { · line 372

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+static const struct nla_policy
+sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = {
+		[NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_U8 },

double indentation?

Quoted 8 lines

net/wireless/nl80211.c nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { · line 374

Quoted 2 lines
net/wireless/nl80211.c +2 -0
+		[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX] =
+			NLA_POLICY_MAX(NLA_U8, NUM_MAX_NL80211_SAR_FREQ_RANGES),

I don't see a good reason to limit to 0xfe? The kernel could just use a wider datatype internally.

Anyway, I'm not sure the attribute is even needed, see above.

If userspace has to sends all the sub bands, then NL80211_SAR_ALL_FREQ_RNAGES is not required, and therefore NUM_MAX_NL80211_SAR_FREQ_RANGES is also not required.

I'll delete these 2 definitions, and change policy to { .type = NLA_U8 }

Quoted 9 lines

net/wireless/nl80211.c static int nl80211_add_commands_unsplit(struct · line 1874

Quoted 6 lines
net/wireless/nl80211.c +1 -0
@@ -1856,6 +1870,8 @@ static int nl80211_add_commands_unsplit(struct 
 cfg80211_registered_device *rdev,
 			goto nla_put_failure;
 	}
 
+	CMD(set_sar_specs, SET_SAR_SPECS);

Don't add to _unsplit() please.

Do you mean add it to below block?
if (state->split) {
...
CMD(set_sar_specs, SET_SAR_SPECS);
}

Quoted 4 lines

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2073

Quoted 1 line
net/wireless/nl80211.c +1 -0
+	specs = nla_nest_start_noflag(msg, NL80211_SAR_ATTR_SPECS);

Don't use _noflag() please, that's just for backward compatibility.

sure.

Quoted 20 lines

net/wireless/nl80211.c nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, · line 2079

Quoted 6 lines
net/wireless/nl80211.c +6 -0
+	if (!specs)
+		goto fail;
+
+	/* report supported freq_ranges */
+	for (i = 0; i < num_freq_ranges; i++) {
+		sub_freq_range = nla_nest_start_noflag(msg, i + 1);

Same here.

net/wireless/nl80211.c static int nl80211_send_wiphy(struct · line 2668

Quoted 7 lines
net/wireless/nl80211.c +2 -0
@@ -2598,6 +2663,9 @@ static int nl80211_send_wiphy(struct 
 cfg80211_registered_device *rdev,
 		if (nl80211_put_tid_config_support(rdev, msg))
 			goto nla_put_failure;
 
+		if (nl80211_put_sar_specs(rdev, msg))
+			goto nla_put_failure;

Perhaps better to have a separate message (case entry) since it might get fairly big?

Quoted 13 lines

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14582

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+	sar_spec = kzalloc(sizeof(*sar_spec) +
+			   specs * sizeof(struct cfg80211_sar_sub_specs),
+			   GFP_KERNEL);
+	if (!sar_spec)
+		return -ENOMEM;
+
+	sar_spec->sub_specs = (struct cfg80211_sar_sub_specs *)
+			((char *)sar_spec + sizeof(*sar_spec));

If you anyway set the pointer there then you can actually just make it a [] array instead of having the pointer in the first place ... would be equivalent but save you from these contortions :)

Right.

Quoted 15 lines
Quoted 15 lines
net/wireless/nl80211.c +15 -0
+	specs = 0;
+	sar_spec->type = type;
+
+	nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
+		if (nla_parse(spec,
+			      NL80211_SAR_ATTR_SPECS_MAX,
+			      nla_data(spec_list),
+			      nla_len(spec_list),
+			      sar_specs_policy,
+			      NULL)) {
+			err = -EINVAL;
+			goto error;
+		}
+
+		/* for power type, power value must be presented */
Quoted 9 lines

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14602

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+		if (!spec[NL80211_SAR_ATTR_SPECS_POWER] &&
+		    type == NL80211_SAR_TYPE_POWER) {
+			err = -EINVAL;
+			goto error;
+		}

Somewhere you should probably also check that the type matches the advertised type.

Agree.

Quoted 13 lines
Quoted 13 lines
net/wireless/nl80211.c +13 -0
+		power = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_POWER]);
+		sar_spec->sub_specs[specs].power = power;
+
+		/* if NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX isn't present,
+		 * then the power applies to all bands. But it's only valid
+		 * for the first entry.
+		 */
+		if (!spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]) {
+			if (specs) {
+				err = -EINVAL;
+				goto error;
+			} else {
+				sar_spec->sub_specs[specs].freq_range_index =
Quoted 9 lines

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14621

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+					NL80211_SAR_ALL_FREQ_RNAGES;
+				specs++;
+				break;
+			}
+		}

Yeah... not sure I see this as being worth it, vs. userspace just filling all the possible entries.

Yes, let me remove this logic in v2.

Quoted 15 lines

net/wireless/nl80211.c static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, · line 14634

Quoted 12 lines
net/wireless/nl80211.c +12 -0
+		index = nla_get_u8(spec[NL80211_SAR_ATTR_SPECS_FREQ_RANGE_INDEX]);
+		sar_spec->sub_specs[specs].freq_range_index = index;
+		specs++;
+	}
+
+	sar_spec->num_sub_specs = specs;
+
+	rdev->cur_cmd_info = info;
+	if (rdev->ops->set_sar_specs)
+		err = rdev_set_sar_specs(rdev, sar_spec);
+	else
+		err = -EOPNOTSUPP;

Might be worth checking this early and avoiding the allocation and all?

Quoted 3 lines

OTOH, that gives you error checking even if the driver was completely confused and advertised sar specs without the method ...

Here, it checks whether mac80211 layer implements the function. It's ieee80211_set_sar_specs to check whether driver has implemented set_sar function.

I'll move the check to the beginning of this function.

Quoted 1 line

johannes

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#15 lore raw
Quoted 8 lines · Carl Huang
Quoted 6 lines · Johannes Berg

include/net/cfg80211.h struct station_info { · line 1698

Quoted 2 lines · Carl Huang
include/net/cfg80211.h +2 -0
+struct cfg80211_sar_freq_ranges {
+    u8 index;

Does an index here make sense?

With agreement from Google, it's OK to remove it.

I'm not sure "Google" is the arbiter of the nl80211 API, even if we are the current planned users ;)

But I think I agree with Johannes, that given the other plans (user space must send all bands all the time; dropping the "apply to all bands" support), an index isn't really necessary in either the user space API or the internal representation handed down to drivers. All bands should be specified, in order.

Brian

Quoted 3 lines
Quoted 3 lines

include/net/cfg80211.h struct station_info { · line 1701

Quoted 3 lines
include/net/cfg80211.h +3 -0
+    u32 start_freq;
+    u32 end_freq;
+};

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#4 lore raw

Re: [RFC 2/2] ath10k: allow dynamic SAR power limits via common API

In reply to Carl Huang

Hi,

Quoted 19 lines · Carl Huang

ath10k assigns ath10k_mac_set_sar_specs to ath10k_ops, and this function is called when user space application calls NL80211_CMD_SET_SAR_SPECS. ath10k also registers SAR type, and supported frequency ranges to wiphy so user space can query SAR capabilities.

ath10k_mac_set_sar_specs further sets the power to firmware to limit the TX power.

This feature is controlled by hw parameter: dynamic_sar_support.

---

drivers/net/wireless/ath/ath10k/mac.c +0 -0
index 2e3eb5b..830c61f 100644

drivers/net/wireless/ath/ath10k/mac.c static struct ieee80211_rate ath10k_rates_rev2[] = { · line 85

Quoted 5 lines
drivers/net/wireless/ath/ath10k/mac.c +2 -0
@@ -81,6 +81,17 @@ static struct ieee80211_rate ath10k_rates_rev2[] = {
 	{ .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
 };
 
+static const struct cfg80211_sar_freq_ranges ath10k_sar_freq_ranges[] = {
+	{ .index = 0, .start_freq = 2412000, .end_freq = 2484000 },

2412 MHz is a center frequency, but other parts of the nl80211 API use band edges. For example:

* @NL80211_ATTR_FREQ_RANGE_START: starting frequencry for the regulatory
* rule in KHz. This is not a center of frequency but an actual regulatory
* band edge.
* @NL80211_ATTR_FREQ_RANGE_END: ending frequency for the regulatory rule
* in KHz. This is not a center a frequency but an actual regulatory
* band edge.

Seems like we should improve the nl80211.h docs (patch 1) and make these edges (this patch).

Quoted 19 lines
drivers/net/wireless/ath/ath10k/mac.c +12 -0
+	{ .index = 1, .start_freq = 2484000, .end_freq = 5865000 },
+};
+
+static const struct cfg80211_sar_capa ath10k_sar_capa = {
+	.type = NL80211_SAR_TYPE_POWER,
+	.num_freq_ranges = (ARRAY_SIZE(ath10k_sar_freq_ranges)),
+	.freq_ranges = &ath10k_sar_freq_ranges[0],
+};
+
 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
 
 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
@@ -2880,6 +2891,95 @@ static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
 	return 0;
 }
 
+static bool ath10k_mac_is_connected(struct ath10k *ar)
+{
+	struct ath10k_vif *arvif;

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2906

Quoted 10 lines
drivers/net/wireless/ath/ath10k/mac.c +10 -0
+
+	list_for_each_entry(arvif, &ar->arvifs, list) {
+		if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_STA)
+			return true;
+	}
+
+	return false;
+}
+
+int ath10k_mac_set_sar_power(struct ath10k *ar)

This function should be static.

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2911

Quoted 5 lines
drivers/net/wireless/ath/ath10k/mac.c +5 -0
+{
+	int ret;
+
+	if (!ar->hw_params.dynamic_sar_support)
+		return 0;

return -EOPNOTSUPP ?

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2913

Quoted 2 lines
drivers/net/wireless/ath/ath10k/mac.c +2 -0
+
+	if (ar->tx_power_2g_limit == 0 || ar->tx_power_5g_limit == 0)

ath10k_mac_txpower_recalc() doesn't care about this -- why should you? This also seems especially weird, because one of the 2 could be valid nonzero values, and yet you're silently rejecting it. Regardless, the following seems wrong:

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2914

Quoted 1 line
drivers/net/wireless/ath/ath10k/mac.c +1 -0
+		return 0;

This should probably be an error.

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2917

Quoted 3 lines
drivers/net/wireless/ath/ath10k/mac.c +3 -0
+
+	if (!ath10k_mac_is_connected(ar))
+		return 0;

Note to self (since this wasn't obvious to me the first read-through):
you're calling this function from ath10k_bss_assoc() too, so even if you weren't connected the first time around, it'll get called later.

Quoted 8 lines
drivers/net/wireless/ath/ath10k/mac.c +8 -0
+
+	ret = ath10k_wmi_pdev_set_param(ar,
+					ar->wmi.pdev_param->txpower_limit2g,
+					ar->tx_power_2g_limit);
+	if (ret) {
+		ath10k_warn(ar, "failed to set 2.4G txpower %d: %d\n",
+			    ar->tx_power_2g_limit, ret);
+		return ret;

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2935

Quoted 10 lines
drivers/net/wireless/ath/ath10k/mac.c +10 -0
+	}
+
+	ret = ath10k_wmi_pdev_set_param(ar,
+					ar->wmi.pdev_param->txpower_limit5g,
+					ar->tx_power_5g_limit);
+	if (ret) {
+		ath10k_warn(ar, "failed to set 5G txpower %d: %d\n",
+			    ar->tx_power_5g_limit, ret);
+		return ret;
+	}

Hmm, so these are the same params configured by ath10k_mac_txpower_recalc(), except that we're not taking into account the limitations in ath10k_mac_txpower_recalc() (and vice versa) -- isn't that bad? Should we be merging the SAR limitation into ath10k_mac_txpower_recalc() and calling that instead?

Brian

Quoted 7 lines
drivers/net/wireless/ath/ath10k/mac.c +7 -0
+
+	ath10k_dbg(ar, ATH10K_DBG_MAC, "set txpower 2G:%d, 5G:%d successfully\n",
+		   ar->tx_power_2g_limit, ar->tx_power_5g_limit);
+
+	return ret;
+}
+
#17 lore raw
In reply to Johannes Berg
Quoted 4 lines · Johannes Berg
Quoted 1 line

+#define NUM_MAX_NL80211_SAR_FREQ_RANGES 0xfe

but I'm not sure what these are used for in the first place, they seem more like internal implementation details?

I think the MAX value does have some utility in the API -- as mentioned in other comments, if we're requiring that user space must SET all ranges at the same time, then we need an expected way for user space to SET a "don't care" or "MAX" or "null" value for a band. So if there's some new band (e.g., 6 GHz?) that user space was not previously aware of, it will know to use this placeholder.

I think that's kind of approximately what the purpose of this was? It's not super clear in the documentation, so maybe that should be clarified in writing in v2.

Brian

#18 lore raw
In reply to Carl Huang

Hi Carl,

Sorry, I lied; I have a few more notes after spending another day looking at this:

include/net/cfg80211.h struct station_info { · line 1669

Quoted 10 lines · Carl Huang
include/net/cfg80211.h +7 -0
@@ -1663,6 +1663,55 @@ struct station_info {
+/**
+ * @struct cfg80211_sar_chan_ranges - sar frequency ranges
+ * @index: the index of this range. It's used to specify
+ *	the frequency range when setting SAR power limitation
+ * @start_freq:  start channel frequency in kHZ. For example,
+ *	2.4G channel 1 is represented as 2412000
+ * @end_freq:    end channel frequency in kHZ

If you accept my comments in nl80211.h, you'll want to change this too.

Quoted 9 lines
include/net/cfg80211.h +6 -0
+ */
+struct cfg80211_sar_freq_ranges {
+	u8 index;
+	u32 start_freq;
+	u32 end_freq;
+};
 

include/uapi/linux/nl80211.h enum nl80211_iftype_akm_attributes { · line 7076

Quoted 7 lines
include/uapi/linux/nl80211.h +6 -0
 
+ * @NL80211_SAR_ATTR_SPECS_START_FREQ: Required (u32) value to specify the start
+ *	frequency of this range to register SAR capability to wihpy and the unit
+ *	is kHZ
+ *
+ * @NL80211_SAR_ATTR_SPECS_END_FREQ: Required (u32) value to specify the end frequency
+ *	of this range to register SAR capability to wiphy and the unit is kHZ

The documentation here isn't clear whether these are center frequencies or band edges. The cfg80211 comments do though (center freq). However, this is inconsistent with NL80211_ATTR_FREQ_RANGE_START and NL80211_ATTR_FREQ_RANGE_END -- I'd suggest being consistent?

net/mac80211/cfg.c static const struct genl_ops nl80211_ops[] = { · line 15504

Quoted 13 lines
net/mac80211/cfg.c +6 -0
@@ -15331,6 +15496,14 @@ static const struct genl_ops nl80211_ops[] = {
 		.internal_flags = NL80211_FLAG_NEED_NETDEV |
 				  NL80211_FLAG_NEED_RTNL,
 	},
+	{
+		.cmd = NL80211_CMD_SET_SAR_SPECS,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = nl80211_set_sar_specs,
+		.flags = GENL_UNS_ADMIN_PERM,
+		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |

Is there a reason this needs to be UP? CMD_SET_WIPHY (which can also configure TX power, a little differently) does not. Seems like this could just be NL80211_FLAG_NEED_NETDEV -- or maybe not even that, if we switch this to a WIPHY command like Johannes noted.

Brian

Quoted 3 lines
net/mac80211/cfg.c +2 -0
+				  NL80211_FLAG_NEED_RTNL,
+	},
 };
author
#5 lore raw

Re: [RFC 2/2] ath10k: allow dynamic SAR power limits via common API

In reply to Brian Norris
Quoted 65 lines · Brian Norris

Hi,

Quoted 19 lines · Carl Huang

ath10k assigns ath10k_mac_set_sar_specs to ath10k_ops, and this function is called when user space application calls NL80211_CMD_SET_SAR_SPECS. ath10k also registers SAR type, and supported frequency ranges to wiphy so user space can query SAR capabilities.

ath10k_mac_set_sar_specs further sets the power to firmware to limit the TX power.

This feature is controlled by hw parameter: dynamic_sar_support.

---

drivers/net/wireless/ath/ath10k/mac.c +0 -0
index 2e3eb5b..830c61f 100644

drivers/net/wireless/ath/ath10k/mac.c static struct ieee80211_rate ath10k_rates_rev2[] = · line 87

Quoted 7 lines
drivers/net/wireless/ath/ath10k/mac.c +2 -0
@@ -81,6 +81,17 @@ static struct ieee80211_rate ath10k_rates_rev2[] = 
 {
 	{ .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
 };
 
+static const struct cfg80211_sar_freq_ranges ath10k_sar_freq_ranges[] 
 = {
+	{ .index = 0, .start_freq = 2412000, .end_freq = 2484000 },

2412 MHz is a center frequency, but other parts of the nl80211 API use band edges. For example:

* @NL80211_ATTR_FREQ_RANGE_START: starting frequencry for the
regulatory
* rule in KHz. This is not a center of frequency but an actual
regulatory
* band edge.
* @NL80211_ATTR_FREQ_RANGE_END: ending frequency for the regulatory
rule
* in KHz. This is not a center a frequency but an actual
regulatory
* band edge.

Seems like we should improve the nl80211.h docs (patch 1) and make these edges (this patch).

Quoted 18 lines
drivers/net/wireless/ath/ath10k/mac.c +9 -0
+	{ .index = 1, .start_freq = 2484000, .end_freq = 5865000 },
+};
+
+static const struct cfg80211_sar_capa ath10k_sar_capa = {
+	.type = NL80211_SAR_TYPE_POWER,
+	.num_freq_ranges = (ARRAY_SIZE(ath10k_sar_freq_ranges)),
+	.freq_ranges = &ath10k_sar_freq_ranges[0],
+};
+
 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4

#define ath10k_a_rates (ath10k_rates +
ATH10K_MAC_FIRST_OFDM_RATE_IDX)

drivers/net/wireless/ath/ath10k/mac.c +0 -0
@@ -2880,6 +2891,95 @@ static int ath10k_mac_vif_recalc_txbf(struct 
 ath10k *ar,
 	return 0;
 }
 
Quoted 16 lines

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2906

Quoted 13 lines
drivers/net/wireless/ath/ath10k/mac.c +13 -0
+static bool ath10k_mac_is_connected(struct ath10k *ar)
+{
+	struct ath10k_vif *arvif;
+
+	list_for_each_entry(arvif, &ar->arvifs, list) {
+		if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_STA)
+			return true;
+	}
+
+	return false;
+}
+
+int ath10k_mac_set_sar_power(struct ath10k *ar)

This function should be static.

Right.

Quoted 8 lines

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2911

Quoted 5 lines
drivers/net/wireless/ath/ath10k/mac.c +5 -0
+{
+	int ret;
+
+	if (!ar->hw_params.dynamic_sar_support)
+		return 0;

return -EOPNOTSUPP ?

sure

Quoted 8 lines

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct · line 2914

Quoted 2 lines
drivers/net/wireless/ath/ath10k/mac.c +2 -0
+
+	if (ar->tx_power_2g_limit == 0 || ar->tx_power_5g_limit == 0)

ath10k_mac_txpower_recalc() doesn't care about this -- why should you? This also seems especially weird, because one of the 2 could be valid nonzero values, and yet you're silently rejecting it. Regardless, the following seems wrong:

Per current design, it's required for userspace to always set meaningful power limitations.

Now in V2, 0 will be treated as "don't have SAR on this range".

Quoted 28 lines

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct · line 2915

Quoted 1 line
drivers/net/wireless/ath/ath10k/mac.c +1 -0
+		return 0;

This should probably be an error.

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2917

Quoted 3 lines
drivers/net/wireless/ath/ath10k/mac.c +3 -0
+
+	if (!ath10k_mac_is_connected(ar))
+		return 0;

Note to self (since this wasn't obvious to me the first read-through):
you're calling this function from ath10k_bss_assoc() too, so even if you weren't connected the first time around, it'll get called later.

Quoted 16 lines
drivers/net/wireless/ath/ath10k/mac.c +16 -0
+
+	ret = ath10k_wmi_pdev_set_param(ar,
+					ar->wmi.pdev_param->txpower_limit2g,
+					ar->tx_power_2g_limit);
+	if (ret) {
+		ath10k_warn(ar, "failed to set 2.4G txpower %d: %d\n",
+			    ar->tx_power_2g_limit, ret);
+		return ret;
+	}
+
+	ret = ath10k_wmi_pdev_set_param(ar,
+					ar->wmi.pdev_param->txpower_limit5g,
+					ar->tx_power_5g_limit);
+	if (ret) {
+		ath10k_warn(ar, "failed to set 5G txpower %d: %d\n",
+			    ar->tx_power_5g_limit, ret);
Quoted 9 lines

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct · line 2936

Quoted 2 lines
drivers/net/wireless/ath/ath10k/mac.c +2 -0
+		return ret;
+	}

Hmm, so these are the same params configured by ath10k_mac_txpower_recalc(), except that we're not taking into account the limitations in ath10k_mac_txpower_recalc() (and vice versa) -- isn't that bad? Should we be merging the SAR limitation into ath10k_mac_txpower_recalc() and calling that instead?

Good suggestions.

Quoted 10 lines

Brian

drivers/net/wireless/ath/ath10k/mac.c static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, · line 2942

Quoted 8 lines
drivers/net/wireless/ath/ath10k/mac.c +7 -0
+
+	ath10k_dbg(ar, ATH10K_DBG_MAC, "set txpower 2G:%d, 5G:%d 
 successfully\n",
+		   ar->tx_power_2g_limit, ar->tx_power_5g_limit);
+
+	return ret;
+}
+

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

author
#19 lore raw
In reply to Brian Norris
Quoted 6 lines · Brian Norris

Hi Carl,

Sorry, I lied; I have a few more notes after spending another day looking at this:

On Tue, Sep 22, 2020 at 01:49:34PM +0800, Carl Huang wrote:

Quoted 13 lines

include/net/cfg80211.h struct station_info { · line 1669

Quoted 10 lines
include/net/cfg80211.h +7 -0
@@ -1663,6 +1663,55 @@ struct station_info {
+/**
+ * @struct cfg80211_sar_chan_ranges - sar frequency ranges
+ * @index: the index of this range. It's used to specify
+ *	the frequency range when setting SAR power limitation
+ * @start_freq:  start channel frequency in kHZ. For example,
+ *	2.4G channel 1 is represented as 2412000
+ * @end_freq:    end channel frequency in kHZ

If you accept my comments in nl80211.h, you'll want to change this too.

Yes.

Quoted 21 lines
Quoted 12 lines
include/net/cfg80211.h +6 -0
+ */
+struct cfg80211_sar_freq_ranges {
+	u8 index;
+	u32 start_freq;
+	u32 end_freq;
+};
 
include/uapi/linux/nl80211.h +1 -0
 
+ * @NL80211_SAR_ATTR_SPECS_START_FREQ: Required (u32) value to 

specify the start

Quoted 8 lines

+ * frequency of this range to register SAR capability to wihpy and
the unit
+ * is kHZ
+ *
+ * @NL80211_SAR_ATTR_SPECS_END_FREQ: Required (u32) value to specify the end frequency
+ * of this range to register SAR capability to wiphy and the unit is
kHZ

Quoted 5 lines

The documentation here isn't clear whether these are center frequencies or band edges. The cfg80211 comments do though (center freq). However, this is inconsistent with NL80211_ATTR_FREQ_RANGE_START and NL80211_ATTR_FREQ_RANGE_END -- I'd suggest being consistent?

Yes. Will change to band edge.

Quoted 20 lines
Quoted 4 lines

net/mac80211/cfg.c static const struct genl_ops nl80211_ops[] = · line 15505

Quoted 10 lines
net/mac80211/cfg.c +6 -0
@@ -15331,6 +15496,14 @@ static const struct genl_ops nl80211_ops[] = 
 {
 		.internal_flags = NL80211_FLAG_NEED_NETDEV |
 				  NL80211_FLAG_NEED_RTNL,
 	},
+	{
+		.cmd = NL80211_CMD_SET_SAR_SPECS,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = nl80211_set_sar_specs,
+		.flags = GENL_UNS_ADMIN_PERM,
+		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |

Is there a reason this needs to be UP? CMD_SET_WIPHY (which can also configure TX power, a little differently) does not. Seems like this could just be NL80211_FLAG_NEED_NETDEV -- or maybe not even that, if we switch this to a WIPHY command like Johannes noted.

Will change to NL80211_FLAG_NEED_WIPHY.

Quoted 10 lines

Brian

net/mac80211/cfg.c static const struct genl_ops nl80211_ops[] = · line 15508

Quoted 3 lines
net/mac80211/cfg.c +2 -0
+				  NL80211_FLAG_NEED_RTNL,
+	},
 };

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

author
#16 lore raw
In reply to Brian Norris
Quoted 13 lines · Brian Norris
Quoted 8 lines · Carl Huang
Quoted 6 lines · Johannes Berg

include/net/cfg80211.h struct station_info { · line 1698

Quoted 2 lines · Carl Huang
include/net/cfg80211.h +2 -0
+struct cfg80211_sar_freq_ranges {
+    u8 index;

Does an index here make sense?

With agreement from Google, it's OK to remove it.

I'm not sure "Google" is the arbiter of the nl80211 API, even if we are the current planned users ;)

Quoted 8 lines

But I think I agree with Johannes, that given the other plans (user space must send all bands all the time; dropping the "apply to all bands" support), an index isn't really necessary in either the user space API or the internal representation handed down to drivers. All bands should be specified, in order.

Brian

The index here will be removed.

But let's keep the explicit index in SET command. I think it adds no burden to userspace but has flexibility to skip some ranges as we remove "all or nothing" limitation.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

include/net/cfg80211.h struct station_info { · line 1701

Quoted 3 lines
include/net/cfg80211.h +3 -0
+    u32 start_freq;
+    u32 end_freq;
+};

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#6 lore raw

Re: [RFC 2/2] ath10k: allow dynamic SAR power limits via common API

In reply to Carl Huang
Quoted 11 lines · Carl Huang
Quoted 8 lines · Brian Norris
Quoted 1 line · Carl Huang

+ if (ar->tx_power_2g_limit == 0 || ar->tx_power_5g_limit == 0)

ath10k_mac_txpower_recalc() doesn't care about this -- why should you? This also seems especially weird, because one of the 2 could be valid nonzero values, and yet you're silently rejecting it. Regardless, the following seems wrong:

Per current design, it's required for userspace to always set meaningful power limitations.

Well, that wasn't specified anywhere (in the docs nor in the nl80211 implementation); if one wanted to enforce that, it should probably go in the nl80211 layer, not the driver implementation. Otherwise, we're very prone to varying driver implementations (not a good thing).

Quoted 1 line

Now in V2, 0 will be treated as "don't have SAR on this range".

OK... I guess that's reasonable, although that should be explicitly called out in nl80211.h.

Brian