Skip to contentSkip to conversation

cfg80211: Add nl80211 antenna configuration

PATCH Superseded Bruno Randolf 2 participants 9 messages Jun 7, 2010 – Jun 8, 2010

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 cfg80211: Add nl80211 antenna configuration

Allow setting TX and RX antenna configuration via nl80211.

The antenna configuration is defined as a bitmap of allowed antennas to use for either receiving or transmitting. Separate bitmaps are used for RX and TX to allow using different antennas for receiving and transmitting. The bitmap is 8 bit, each bit representing one antenna.

If multiple receive antennas are selected, the driver may use diversity or multiple 802.11 rx chains, according to the chipset capabilities.

If multiple transmit antennas are selected, the driver has to send on all selected antennas, making this mode of operation only possible on 802.11n chipsets with multiple tx chains. If the transmit antenna bitmap is set to the special value zero (0) the driver should select the TX antenna based on the antenna which was used for receiving (TX antenna follows RX diversity).

Drivers should reject configurations they cannot support.

While covering the standard modes "fixed antenna A", "fixed antenna B", "diversity" this API allows for a more flexible antenna configuration, as follows:

Send on antenna 1, receive on antenna 2 (or vice versa):

This can be used to have a low gain antenna for TX in order to keep within the regulatory constraints and a high gain antenna for RX in order to receive weaker signals ("speak softly, but listen harder"). This can be useful for legal long-shot outdoor links. Another usage of this is: Having a low noise preamp on antenna A and a power amplifier on the other antenna. This way transmit noise is mostly kept out of the low noise receive channel. (This would be bitmaps: tx 0b01 rx 0b10).

Another simiar setup would be: Use RX diversity on both antennas, but always send on antenna A. Again that would allow us to benefit from a higher gain RX antenna, while staying within the legal limits. (This would be tx 0 rx 0b11).

And finally there can be special experimental setups in research and development where more than 2 antennas are available. It's good to keep the API flexible.

---
 include/linux/nl80211.h |   22 +++++++++
 include/net/cfg80211.h  |    3 +
 net/wireless/nl80211.c  |  116 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+), 0 deletions(-)
include/linux/nl80211.h +22 -0
index 64fb32b..ace33de 100644
@@ -341,6 +341,9 @@
  *	of any other interfaces, and other interfaces will again take
  *	precedence when they are used.
  *
+ * @NL80211_CMD_SET_ANTENNA: Set a bitmap of antennas to use.
+ * @NL80211_CMD_GET_ANTENNA: Get antenna configuration from driver.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -441,6 +444,9 @@ enum nl80211_commands {
 
 	NL80211_CMD_SET_CHANNEL,
 
+	NL80211_CMD_SET_ANTENNA,
+	NL80211_CMD_GET_ANTENNA,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
@@ -725,6 +731,19 @@ enum nl80211_commands {
  * @NL80211_ATTR_AP_ISOLATE: (AP mode) Do not forward traffic between stations
  *	connected to this BSS.
  *
+ * @NL80211_ATTR_ANTENNA_TX: Bitmap of allowed antennas to use for transmitting.
+ *	Each bit represents one antenna, starting with antenna 1 at the first
+ *	bit. If the bitmap is zero (0), the TX antenna follows RX diversity.
+ *	If multiple antennas are selected all selected antennas have to be used
+ *	for transmitting (801.11n multiple tx chains).
+ *	Drivers may reject configurations they cannot support.
+ *
+ * @NL80211_ATTR_ANTENNA_RX: Bitmap of allowed antennas to use for receiving.
+ *	Each bit represents one antenna, starting with antenna 1 at the first
+ *	bit. If multiple antennas are selected in the bitmap, the driver should
+ *	use diversity or 802.11n multiple rx chains between these antennas.
+ *	Drivers may reject configurations they cannot support.
+ *
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
  */
@@ -882,6 +901,9 @@ enum nl80211_attrs {
 
 	NL80211_ATTR_AP_ISOLATE,
 
+	NL80211_ATTR_ANTENNA_TX,
+	NL80211_ATTR_ANTENNA_RX,
+
 	/* add attributes here, update the policy in nl80211.c */
 
 	__NL80211_ATTR_AFTER_LAST,
include/net/cfg80211.h +3 -0
index 0c3c214..f65bd6b 100644
@@ -1177,6 +1177,9 @@ struct cfg80211_ops {
 	int	(*set_cqm_rssi_config)(struct wiphy *wiphy,
 				       struct net_device *dev,
 				       s32 rssi_thold, u32 rssi_hyst);
+
+	int	(*set_antenna)(struct wiphy *wiphy, u8 tx_ant, u8 rx_ant);
+	int	(*get_antenna)(struct wiphy *wiphy, u8 *tx_ant, u8 *rx_ant);
 };
 
 /*
net/wireless/nl80211.c +116 -0

140 lines not on this page · raw message

#1 lore raw

PATCH v3 2/3 mac80211: Add antenna configuration

Allow antenna configuration by calling driver's function for it.

---
 include/net/mac80211.h      |    2 ++
 net/mac80211/cfg.c          |   16 ++++++++++++++
 net/mac80211/driver-ops.h   |   23 ++++++++++++++++++++
 net/mac80211/driver-trace.h |   50 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 0 deletions(-)
include/net/mac80211.h +2 -0
index e3c1d47..e0688a9 100644
@@ -1732,6 +1732,8 @@ struct ieee80211_ops {
 	void (*flush)(struct ieee80211_hw *hw, bool drop);
 	void (*channel_switch)(struct ieee80211_hw *hw,
 			       struct ieee80211_channel_switch *ch_switch);
+	int (*set_antenna)(struct ieee80211_hw *hw, u8 tx_ant, u8 rx_ant);
+	int (*get_antenna)(struct ieee80211_hw *hw, u8 *tx_ant, u8 *rx_ant);
 };
 
 /**
net/mac80211/cfg.c +16 -0
index 952845e..2e4d947 100644
@@ -1560,6 +1560,20 @@ static int ieee80211_action(struct wiphy *wiphy, struct net_device *dev,
 				    buf, len, cookie);
 }
 
+static int ieee80211_set_antenna(struct wiphy *wiphy, u8 tx_ant, u8 rx_ant)
+{
+	struct ieee80211_local *local = wiphy_priv(wiphy);
+
+	return drv_set_antenna(local, tx_ant, rx_ant);
+}
+
+static int ieee80211_get_antenna(struct wiphy *wiphy, u8 *tx_ant, u8 *rx_ant)
+{
+	struct ieee80211_local *local = wiphy_priv(wiphy);
+
+	return drv_get_antenna(local, tx_ant, rx_ant);
+}
+
 struct cfg80211_ops mac80211_config_ops = {
 	.add_virtual_intf = ieee80211_add_iface,
 	.del_virtual_intf = ieee80211_del_iface,
@@ -1611,4 +1625,6 @@ struct cfg80211_ops mac80211_config_ops = {
 	.cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
 	.action = ieee80211_action,
 	.set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
+	.set_antenna = ieee80211_set_antenna,
+	.get_antenna = ieee80211_get_antenna,
 };
net/mac80211/driver-ops.h +23 -0
index d1139e4..edb4b4e 100644
@@ -393,4 +393,27 @@ static inline void drv_channel_switch(struct ieee80211_local *local,
 	trace_drv_channel_switch(local, ch_switch);
 }
 
+
+static inline int drv_set_antenna(struct ieee80211_local *local,
+				  u8 tx_ant, u8 rx_ant)
+{
+	int ret = -EOPNOTSUPP;
+	might_sleep();
+	if (local->ops->set_antenna)
+		ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
+	trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
+	return ret;
+}
+
+static inline int drv_get_antenna(struct ieee80211_local *local,
+				  u8 *tx_ant, u8 *rx_ant)
+{
+	int ret = -EOPNOTSUPP;
+	might_sleep();
+	if (local->ops->get_antenna)
+		ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
+	trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
+	return ret;
+}
+
 #endif /* __MAC80211_DRIVER_OPS */
net/mac80211/driver-trace.h +50 -0

56 lines not on this page · raw message

#2 lore raw

PATCH v3 3/3 ath5k: Add support for antenna configuration

In reply to Bruno Randolf

Support setting the antenna configuration via cfg/mac80211. At the moment only allow the simple pre-defined configurations we already have (fixed antenna A/B or diversity), but more advanced settings are possible to implement.

---
 drivers/net/wireless/ath/ath5k/base.c |   34 +++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
drivers/net/wireless/ath/ath5k/base.c +34 -0
index 9d37c1a..12ba9a1 100644
@@ -256,6 +256,8 @@ static void ath5k_sw_scan_start(struct ieee80211_hw *hw);
 static void ath5k_sw_scan_complete(struct ieee80211_hw *hw);
 static void ath5k_set_coverage_class(struct ieee80211_hw *hw,
 		u8 coverage_class);
+static int ath5k_set_antenna(struct ieee80211_hw *hw, u8 tx_ant, u8 rx_ant);
+static int ath5k_get_antenna(struct ieee80211_hw *hw, u8 *tx_ant, u8 *rx_ant);
 
 static const struct ieee80211_ops ath5k_hw_ops = {
 	.tx 		= ath5k_tx,
@@ -277,6 +279,8 @@ static const struct ieee80211_ops ath5k_hw_ops = {
 	.sw_scan_start	= ath5k_sw_scan_start,
 	.sw_scan_complete = ath5k_sw_scan_complete,
 	.set_coverage_class = ath5k_set_coverage_class,
+	.set_antenna	= ath5k_set_antenna,
+	.get_antenna	= ath5k_get_antenna,
 };
 
 /*
@@ -3482,3 +3486,33 @@ static void ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
 	ath5k_hw_set_coverage_class(sc->ah, coverage_class);
 	mutex_unlock(&sc->lock);
 }
+
+static int ath5k_set_antenna(struct ieee80211_hw *hw, u8 tx_ant, u8 rx_ant)
+{
+	struct ath5k_softc *sc = hw->priv;
+
+	if (tx_ant == 1 && rx_ant == 1)
+		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
+	else if (tx_ant == 2 && rx_ant == 2)
+		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
+	else if (tx_ant == 0 && rx_ant == 3)
+		ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
+	else
+		return -EINVAL;
+	return 0;
+}
+
+static int ath5k_get_antenna(struct ieee80211_hw *hw, u8 *tx_ant, u8 *rx_ant)
+{
+	struct ath5k_softc *sc = hw->priv;
+
+	switch (sc->ah->ah_ant_mode) {
+	case AR5K_ANTMODE_FIXED_A:
+		*tx_ant = 1; *rx_ant = 1; break;
+	case AR5K_ANTMODE_FIXED_B:
+		*tx_ant = 2; *rx_ant = 2; break;
+	case AR5K_ANTMODE_DEFAULT:
+		*tx_ant = 0; *rx_ant = 3; break;
+	}
+	return 0;
+}
maintainer
#3 lore raw
In reply to Bruno Randolf

net/wireless/nl80211.c out: · line 5019

Quoted 7 lines · Bruno Randolf
net/wireless/nl80211.c +7 -0
+static int nl80211_get_antenna(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg80211_registered_device *rdev;
+	struct sk_buff *msg;
+	void *hdr;
+	int res;
+	u8 tx_ant, rx_ant;

You should probably set them both to 0 here,

net/wireless/nl80211.c out: · line 5052

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+	res = rdev->ops->get_antenna(&rdev->wiphy, &tx_ant, &rx_ant);
+	if (res)
+		goto free_msg;

and complain about the driver if they still are after this.

johannes

#4 lore raw
Quoted 10 lines · On Monday 07 June 2010 18:03:28 you wrote:

net/wireless/nl80211.c out: · line 5019

Quoted 7 lines · Bruno Randolf

+static int nl80211_get_antenna(struct sk_buff *skb, struct genl_info *info) +{

net/wireless/nl80211.c +5 -0
+	struct cfg80211_registered_device *rdev;
+	struct sk_buff *msg;
+	void *hdr;
+	int res;
+	u8 tx_ant, rx_ant;

You should probably set them both to 0 here,

ok.

Quoted 5 lines

net/wireless/nl80211.c out: · line 5052

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+	res = rdev->ops->get_antenna(&rdev->wiphy, &tx_ant, &rx_ant);
+	if (res)
+		goto free_msg;

and complain about the driver if they still are after this.

would that be a WARN_ON?

thanks,
bruno

maintainer
#5 lore raw
Quoted 7 lines · Bruno Randolf
Quoted 5 lines

net/wireless/nl80211.c out: · line 5052

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+	res = rdev->ops->get_antenna(&rdev->wiphy, &tx_ant, &rx_ant);
+	if (res)
+		goto free_msg;

and complain about the driver if they still are after this.

would that be a WARN_ON?

Yeah I suppose so.

johannes

maintainer
#6 lore raw
In reply to Bruno Randolf
Quoted 1 line · Bruno Randolf

+ * @NL80211_CMD_GET_ANTENNA: Get antenna configuration from driver.

Since we already have runtime configuration and capability information as part of the wiphy information printout, remind me again what was wrong with adding antenna information there as well rather than having a separate command to retrieve it?

As far as differentiating that information is concerned, you can easily implement an iw "get antenna" command by just partially printing the wiphy information, for example, no?

johannes

#7 lore raw
Quoted 11 lines · On Monday 07 June 2010 18:05:14 you wrote:
Quoted 1 line · Bruno Randolf

+ * @NL80211_CMD_GET_ANTENNA: Get antenna configuration from driver.

Since we already have runtime configuration and capability information as part of the wiphy information printout, remind me again what was wrong with adding antenna information there as well rather than having a separate command to retrieve it?

As far as differentiating that information is concerned, you can easily implement an iw "get antenna" command by just partially printing the wiphy information, for example, no?

i don't particularly care about where the antenna information is printed exactly, so anything will be fine with me.

but when i look at the wiphy info, it shows mostly capability information, like the list of supported frequencies, list of bitrates, supported interface modes, supported commands. the only exception is coverage class, which is the only runtime configuration as far as i can see. therefore i thought it doesnt fit there well.

maybe another command for getting runtime configuration like channel(s), fixed bitrates, essid, bssid, RTS/CTS, fraqmentation, txpower, power management, antenna settings, etc... would make sense? allthough in this list antenna is probably the only one which is per phy and not per interface...

i can leave the 'antenna get' command out until this is clarified.

bruno

maintainer
#8 lore raw
Quoted 9 lines · Bruno Randolf

i don't particularly care about where the antenna information is printed exactly, so anything will be fine with me.

but when i look at the wiphy info, it shows mostly capability information, like the list of supported frequencies, list of bitrates, supported interface modes, supported commands. the only exception is coverage class, which is the only runtime configuration as far as i can see. therefore i thought it doesnt fit there well.

Quoted 4 lines

maybe another command for getting runtime configuration like channel(s), fixed bitrates, essid, bssid, RTS/CTS, fraqmentation, txpower, power management, antenna settings, etc... would make sense? allthough in this list antenna is probably the only one which is per phy and not per interface...

Right so there isn't much runtime stuff in the list now. I don't see anything inherently bad in adding more though, since userspace can selectively look at the attributes, and it's not like it's a huge amount of data?

johannes