Skip to contentSkip to conversation

mac80211: add hw 80211 encapsulation offloading support

PATCH Superseded John Crispin 2 participants 2 messages Jul 30, 2019 – Jul 31, 2019 mac80211

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/1 mac80211: add hw 80211 encapsulation offloading support

This patch adds a new transmit path for hardware that supports 802.11 encapsulation offloading. In those cases 802.3a frames get passed directly to the driver allowing to hardware to handle the encapsulation.

Certain features wont work and the patch masks these out.
* monitor interfaces are not supported if any of the vif is in encap mode.
* amsdu/non-linear frames wont work in encap offloading mode.
* TKIP countermeasures cannot be triggered and hence those keys are not accepted.

The patch defines a secondary netdev_ops struct that the device is assigned to the device if 802.11 encap support is available and enabled. The driver needs to enable the support on a per vif basis if it finds that all pre-reqs are meet.

---

Changes in V8
* fix double locking when setting frag threshold

Changes in V7
* dont mask out monitor support when encap is available. Instead turn encap of if a monitor device is brought up or already present

Changes in V6
* the conditional masking out monitor support was inverse

Changes in V5
* implement comments from Johannes

Changes in V4
* disable encap when TKIP is used instead of refusing TKIP
* use a flag inside tx_info instead of an extra element
* move 4addr detection into ieee80211_set_hw_80211_encap()
* ieee80211_tx_dequeue() was dropping out to early

Changes in V3
* rebase on latest kernel
* various code style clean ups
* give some of the variables and functions more obvious names
* move the code that disables support for non-linear frames to the core
* disable monitor and tkip support

 include/net/mac80211.h     |  25 +++++
 net/mac80211/cfg.c         |   6 ++
 net/mac80211/debugfs.c     |   1 +
 net/mac80211/ieee80211_i.h |  10 ++
 net/mac80211/iface.c       | 100 ++++++++++++++++++++
 net/mac80211/key.c         |   7 ++
 net/mac80211/main.c        |   4 +-
 net/mac80211/status.c      |  79 ++++++++++++++++
 net/mac80211/tx.c          | 187 ++++++++++++++++++++++++++++++++++++-
 9 files changed, 413 insertions(+), 6 deletions(-)
include/net/mac80211.h +25 -0
index bd91388797fc..4370c58465db 100644
@@ -822,6 +822,7 @@ enum mac80211_tx_control_flags {
 	IEEE80211_TX_CTRL_AMSDU			= BIT(3),
 	IEEE80211_TX_CTRL_FAST_XMIT		= BIT(4),
 	IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP	= BIT(5),
+	IEEE80211_TX_CTRL_HW_80211_ENCAP	= BIT(6),
 };
 
 /*
@@ -2280,6 +2281,9 @@ struct ieee80211_txq {
  *	aggregating MPDUs with the same keyid, allowing mac80211 to keep Tx
  *	A-MPDU sessions active while rekeying with Extended Key ID.
  *
+ * @IEEE80211_HW_SUPPORTS_80211_ENCAP: Hardware/driver supports 802.11
+ *	encap for data frames.
+ *
  * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  */
 enum ieee80211_hw_flags {
@@ -2332,6 +2336,7 @@ enum ieee80211_hw_flags {
 	IEEE80211_HW_SUPPORTS_MULTI_BSSID,
 	IEEE80211_HW_SUPPORTS_ONLY_HE_MULTI_BSSID,
 	IEEE80211_HW_AMPDU_KEYBORDER_SUPPORT,
+	IEEE80211_HW_SUPPORTS_80211_ENCAP,
 
 	/* keep last, obviously */
 	NUM_IEEE80211_HW_FLAGS
@@ -4628,6 +4633,25 @@ static inline void ieee80211_tx_status_ni(struct ieee80211_hw *hw,
 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
 				 struct sk_buff *skb);
 
+/**
+ * ieee80211_tx_status_8023 - transmit status callback for 802.3 frame format
+ *
+ * Call this function for all transmitted data frames after their transmit
+ * completion. This callback should only be called for data frames which
+ * are are using driver's (or hardware's) offload capability of encap/decap
+ * 802.11 frames.
+ *
+ * This function may not be called in IRQ context. Calls to this function
+ * for a single hardware must be synchronized against each other.
+ *
+ * @hw: the hardware the frame was transmitted by
+ * @vif: the interface for which the frame was transmitted
+ * @skb: the frame that was transmitted, owned by mac80211 after this call
+ */
+void ieee80211_tx_status_8023(struct ieee80211_hw *hw,
+			       struct ieee80211_vif *vif,
+			       struct sk_buff *skb);
+
 /**
  * ieee80211_report_low_ack - report non-responding station
  *
@@ -6408,4 +6432,5 @@ void ieee80211_nan_func_match(struct ieee80211_vif *vif,
 			      struct cfg80211_nan_match_params *match,
 			      gfp_t gfp);
 
+bool ieee80211_set_hw_80211_encap(struct ieee80211_vif *vif, bool enable);
 #endif /* MAC80211_H */
net/mac80211/cfg.c +6 -0
index 4d458067d80d..5be377b048c7 100644
@@ -2425,11 +2425,17 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
 {
 	struct ieee80211_local *local = wiphy_priv(wiphy);
+	struct ieee80211_sub_if_data *sdata;
 	int err;
 
 	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
 		ieee80211_check_fast_xmit_all(local);
 
+		mutex_lock(&local->iflist_mtx);
+		list_for_each_entry(sdata, &local->interfaces, list)
+			ieee80211_set_hw_80211_encap(&sdata->vif, false);
+		mutex_unlock(&local->iflist_mtx);
+
 		err = drv_set_frag_threshold(local, wiphy->frag_threshold);
 
 		if (err) {
net/mac80211/debugfs.c +1 -0
index 568b3b276931..87ece0640a43 100644
@@ -272,6 +272,7 @@ static const char *hw_flag_names[] = {
 	FLAG(SUPPORTS_MULTI_BSSID),
 	FLAG(SUPPORTS_ONLY_HE_MULTI_BSSID),
 	FLAG(AMPDU_KEYBORDER_SUPPORT),
+	FLAG(SUPPORTS_80211_ENCAP),
 #undef FLAG
 };
 
net/mac80211/ieee80211_i.h +10 -0
index 38769f5c3da4..eaa0423eaaf9 100644
@@ -984,6 +984,8 @@ struct ieee80211_sub_if_data {
 	} debugfs;
 #endif
 
+	bool hw_80211_encap;
+
 	/* must be last, dynamically sized area in this! */
 	struct ieee80211_vif vif;
 };
@@ -1731,6 +1733,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
 		     struct vif_params *params);
 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
 			     enum nl80211_iftype type);
+bool ieee80211_is_hw_80211_encap(struct ieee80211_local *local);
 void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata);
 void ieee80211_remove_interfaces(struct ieee80211_local *local);
 u32 ieee80211_idle_off(struct ieee80211_local *local);
@@ -1758,6 +1761,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
 					 struct net_device *dev);
 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
 				       struct net_device *dev);
+netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
+					    struct net_device *dev);
 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
 				  struct net_device *dev,
 				  u32 info_flags,
@@ -1941,6 +1946,11 @@ void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
 				 struct sk_buff *skb, int tid,
 				 enum nl80211_band band, u32 txdata_flags);
 
+/* sta_out needs to be checked for ERR_PTR() before using */
+int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
+			    struct sk_buff *skb,
+			    struct sta_info **sta_out);
+
 static inline void
 ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
 			  struct sk_buff *skb, int tid,
net/mac80211/iface.c +100 -0

112 lines not on this page · raw message

net/mac80211/key.c +7 -0
index 7dfee848abac..220726d56235 100644
@@ -176,6 +176,10 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
 		}
 	}
 
+	/* TKIP countermeasures wont work on encap offload mode */
+	if (key->conf.cipher == WLAN_CIPHER_SUITE_TKIP)
+		ieee80211_set_hw_80211_encap(&sdata->vif, false);
+
 	ret = drv_set_key(key->local, SET_KEY, sdata,
 			  sta ? &sta->sta : NULL, &key->conf);
 
@@ -202,6 +206,9 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
 			  key->conf.keyidx,
 			  sta ? sta->sta.addr : bcast_addr, ret);
 
+	if (sdata->hw_80211_encap)
+		return -EINVAL;
+
  out_unsupported:
 	switch (key->conf.cipher) {
 	case WLAN_CIPHER_SUITE_WEP40:
net/mac80211/main.c +3 -1
index 29b9d57df1a3..c248f57b7cc7 100644
@@ -997,7 +997,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 		hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
 	}
 
-	/* mac80211 always supports monitor */
+	/* mac80211 always supports monitor unless we do 802.11
+	 * encapsulation offloading.
+	 */
 	hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
 	hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
 
net/mac80211/status.c +79 -0

85 lines not on this page · raw message

net/mac80211/tx.c +182 -5

229 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#1 lore raw

Hi,

Just a few things, mostly questions I guess.

Quoted 8 lines

Certain features wont work and the patch masks these out.
* monitor interfaces are not supported if any of the vif is in encap mode.

heh.

Quoted 3 lines

Changes in V7
* dont mask out monitor support when encap is available. Instead turn encap of if a monitor device is brought up or already present

I think that means the commit log (quoted above) needs an update?

Quoted 10 lines

+/**
+ * ieee80211_tx_status_8023 - transmit status callback for 802.3 frame format
+ *
+ * Call this function for all transmitted data frames after their transmit
+ * completion. This callback should only be called for data frames which
+ * are are using driver's (or hardware's) offload capability of encap/decap
+ * 802.11 frames.
+ *
+ * This function may not be called in IRQ context. Calls to this function
+ * for a single hardware must be synchronized against each other.

I guess also against any other calls in the same tx status family?

include/net/mac80211.h void ieee80211_nan_func_match(struct ieee80211_vif *vif, · line 6435

Quoted 5 lines
include/net/mac80211.h +1 -0
@@ -6408,4 +6432,5 @@ void ieee80211_nan_func_match(struct ieee80211_vif *vif,
 			      struct cfg80211_nan_match_params *match,
 			      gfp_t gfp);
 
+bool ieee80211_set_hw_80211_encap(struct ieee80211_vif *vif, bool enable);

Please add some docs for that, when to call it, etc. Maybe there are context requirements (can only be called inside add_vif callback) etc?

Quoted 7 lines
net/mac80211/cfg.c +2 -0
+++ b/net/mac80211/cfg.c
@@ -2425,11 +2425,17 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
 {
 	struct ieee80211_local *local = wiphy_priv(wiphy);
+	struct ieee80211_sub_if_data *sdata;
 	int err;

net/mac80211/cfg.c static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, · line 2439

Quoted 10 lines
net/mac80211/cfg.c +5 -0
 
 	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
 		ieee80211_check_fast_xmit_all(local);
 
+		mutex_lock(&local->iflist_mtx);
+		list_for_each_entry(sdata, &local->interfaces, list)
+			ieee80211_set_hw_80211_encap(&sdata->vif, false);
+		mutex_unlock(&local->iflist_mtx);
+
 		err = drv_set_frag_threshold(local, wiphy->frag_threshold);

This isn't clear to me - what if the driver *does* support setting the fragmentation threshold, and maybe even implements it in offload mode?

Shouldn't the driver then reject it, and then we can turn it off, if it did?

net/mac80211/ieee80211_i.h int ieee80211_if_add(struct ieee80211_local *local, const char *name, · line 1736

Quoted 1 line
net/mac80211/ieee80211_i.h +1 -0
+bool ieee80211_is_hw_80211_encap(struct ieee80211_local *local);

Maybe that should be something like ieee80211_using_hw_encap() or something like that?

But a lot of this talks about *encapsulation*, isn't it relevant for *decapsulation* as well?
Then again, reading all this, I guess it only covers encapsulation so far.

net/mac80211/iface.c static const struct net_device_ops ieee80211_dataif_ops = { · line 1208

Quoted 10 lines
net/mac80211/iface.c +10 -0
+bool ieee80211_set_hw_80211_encap(struct ieee80211_vif *vif, bool enable)
+{
+	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+	struct ieee80211_local *local = sdata->local;
+	struct ieee80211_sub_if_data *iter;
+	struct ieee80211_key *key;
+
+	sdata_assert_lock(sdata);
+
+	mutex_lock_nested(&local->iflist_mtx, 1);

That can't be right. The _nested is just a lockdep annotation, and that only works for *different* mutexes, but it still deadlocks if you use the same ... e.g. you'd have to do this when you have

my_object *a, *b;

mutex_lock(&a->mtx);
mutex_lock(&b->mtx);

and you know this is OK, even if both mutexes have the same class (since those are the same objects), but I can't see how you'd have two different "local" instances actually nesting here.

net/mac80211/iface.c static const struct net_device_ops ieee80211_dataif_ops = { · line 1213

Quoted 5 lines
net/mac80211/iface.c +5 -0
+	list_for_each_entry(iter, &local->interfaces, list) {
+		if (vif->type == NL80211_IFTYPE_MONITOR)
+			__ieee80211_set_hw_80211_encap(iter, false);
+		else if (iter->vif.type == NL80211_IFTYPE_MONITOR)
+			enable = 0;

false

net/mac80211/iface.c static const struct net_device_ops ieee80211_dataif_ops = { · line 1223

Quoted 10 lines
net/mac80211/iface.c +10 -0
+	}
+	mutex_unlock(&local->iflist_mtx);
+
+	if (enable == sdata->hw_80211_encap)
+		return enable;
+
+	switch (vif->type) {
+	case NL80211_IFTYPE_STATION:
+		if (sdata->u.mgd.use_4addr)
+			enable = 0;

same here and more instances (also "return 0")

net/mac80211/iface.c static const struct net_device_ops ieee80211_dataif_ops = { · line 1262

Quoted 7 lines
net/mac80211/iface.c +7 -0
+bool ieee80211_is_hw_80211_encap(struct ieee80211_local *local)
+{
+	struct ieee80211_sub_if_data *sdata;
+	bool offloaded = false;
+
+	rcu_read_lock();
+	mutex_lock(&local->iflist_mtx);

You certainly cannot do that in this order.

net/mac80211/key.c static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) · line 179

Quoted 1 line
net/mac80211/key.c +1 -0
+	/* TKIP countermeasures wont work on encap offload mode */

"won't" (or maybe "don't")?

net/mac80211/main.c int ieee80211_register_hw(struct ieee80211_hw *hw) · line 1002

Quoted 9 lines

+++ b/net/mac80211/main.c

net/mac80211/main.c +3 -1
@@ -997,7 +997,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 		hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
 	}
 
-	/* mac80211 always supports monitor */
+	/* mac80211 always supports monitor unless we do 802.11
+	 * encapsulation offloading.
+	 */

not really true now, I think?

net/mac80211/status.c void ieee80211_tx_rate_update(struct ieee80211_hw *hw, · line 1198

Quoted 1 line
net/mac80211/status.c +1 -0
+	if (!sta || IS_ERR(sta)) {

IS_ERR_OR_NULL(), but can it even be NULL?

net/mac80211/tx.c netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, · line 4123

Quoted 1 line
net/mac80211/tx.c +1 -0
+	/* TODO: Handle frames requiring wifi tx status to be notified */

it'd be nice to address this, it shouldn't even be that hard?

net/mac80211/tx.c netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, · line 4179

Quoted 4 lines
net/mac80211/tx.c +4 -0
+	if (WARN_ON(dev->ieee80211_ptr->use_4addr)) {
+		kfree_skb(skb);
+		return NETDEV_TX_OK;
+	}

You have this a lot, but is it even worth it? I mean, the driver ought to know the interface is in 4-addr mode, and then *it* can decide whether it supports it in offload or not, rather than mac80211 deciding for it that it cannot possibly be done?

johannes