Skip to contentSkip to conversation

rt2x00: implement reconfig_complete

PATCH In review Stanislaw Gruszka 2 participants 3 messages Nov 28, 2019 – Dec 18, 2019 Ralink RT2X00 wireless LAN driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 rt2x00: implement reconfig_complete

mac80211 has .reconfig_complete that can be used as indicator of HW restart end. This will allow to configure keys/IV differently for HW restart and normal configuration.

---
 drivers/net/wireless/ralink/rt2x00/rt2800pci.c |  1 +
 drivers/net/wireless/ralink/rt2x00/rt2800soc.c |  1 +
 drivers/net/wireless/ralink/rt2x00/rt2800usb.c |  1 +
 drivers/net/wireless/ralink/rt2x00/rt2x00.h    |  2 ++
 drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 11 -----------
 drivers/net/wireless/ralink/rt2x00/rt2x00mac.c | 20 ++++++++++++++++++++
 6 files changed, 25 insertions(+), 11 deletions(-)
drivers/net/wireless/ralink/rt2x00/rt2800pci.c +1 -0
index a23c26574002..3868c07672bd 100644
@@ -311,6 +311,7 @@ static const struct ieee80211_ops rt2800pci_mac80211_ops = {
 	.get_survey		= rt2800_get_survey,
 	.get_ringparam		= rt2x00mac_get_ringparam,
 	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
+	.reconfig_complete	= rt2x00mac_reconfig_complete,
 };
 
 static const struct rt2800_ops rt2800pci_rt2800_ops = {
drivers/net/wireless/ralink/rt2x00/rt2800soc.c +1 -0
index 7b931bb96a9e..bbfe1425c0ee 100644
@@ -156,6 +156,7 @@ static const struct ieee80211_ops rt2800soc_mac80211_ops = {
 	.get_survey		= rt2800_get_survey,
 	.get_ringparam		= rt2x00mac_get_ringparam,
 	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
+	.reconfig_complete	= rt2x00mac_reconfig_complete,
 };
 
 static const struct rt2800_ops rt2800soc_rt2800_ops = {
drivers/net/wireless/ralink/rt2x00/rt2800usb.c +1 -0
index 0dfb55c69b73..4cc64fe481a7 100644
@@ -654,6 +654,7 @@ static const struct ieee80211_ops rt2800usb_mac80211_ops = {
 	.get_survey		= rt2800_get_survey,
 	.get_ringparam		= rt2x00mac_get_ringparam,
 	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
+	.reconfig_complete	= rt2x00mac_reconfig_complete,
 };
 
 static const struct rt2800_ops rt2800usb_rt2800_ops = {
drivers/net/wireless/ralink/rt2x00/rt2x00.h +2 -0
index a90a518b40d3..ea8a34ecae14 100644
@@ -1439,6 +1439,8 @@ void rt2x00mac_tx(struct ieee80211_hw *hw,
 		  struct sk_buff *skb);
 int rt2x00mac_start(struct ieee80211_hw *hw);
 void rt2x00mac_stop(struct ieee80211_hw *hw);
+void rt2x00mac_reconfig_complete(struct ieee80211_hw *hw,
+				 enum ieee80211_reconfig_type reconfig_type);
 int rt2x00mac_add_interface(struct ieee80211_hw *hw,
 			    struct ieee80211_vif *vif);
 void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c +0 -11
index c3eab767bc21..7f9e43a4f805 100644
@@ -1255,16 +1255,6 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
 {
 	int retval = 0;
 
-	if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) {
-		/*
-		 * This is special case for ieee80211_restart_hw(), otherwise
-		 * mac80211 never call start() two times in row without stop();
-		 */
-		set_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
-		rt2x00dev->ops->lib->pre_reset_hw(rt2x00dev);
-		rt2x00lib_stop(rt2x00dev);
-	}
-
 	/*
 	 * If this is the first interface which is added,
 	 * we should load the firmware now.
@@ -1292,7 +1282,6 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
 	set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags);
 
 out:
-	clear_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
 	return retval;
 }
 
drivers/net/wireless/ralink/rt2x00/rt2x00mac.c +20 -0
index beb20c5faf5f..32efbc8e9f92 100644
@@ -165,6 +165,15 @@ int rt2x00mac_start(struct ieee80211_hw *hw)
 	if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
 		return 0;
 
+	if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) {
+		/*
+		 * This is special case for ieee80211_restart_hw(), otherwise
+		 * mac80211 never call start() two times in row without stop();
+		 */
+		set_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
+		rt2x00dev->ops->lib->pre_reset_hw(rt2x00dev);
+		rt2x00lib_stop(rt2x00dev);
+	}
 	return rt2x00lib_start(rt2x00dev);
 }
 EXPORT_SYMBOL_GPL(rt2x00mac_start);
@@ -180,6 +189,17 @@ void rt2x00mac_stop(struct ieee80211_hw *hw)
 }
 EXPORT_SYMBOL_GPL(rt2x00mac_stop);
 
+void
+rt2x00mac_reconfig_complete(struct ieee80211_hw *hw,
+			    enum ieee80211_reconfig_type reconfig_type)
+{
+	struct rt2x00_dev *rt2x00dev = hw->priv;
+
+	if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
+		clear_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
+}
+EXPORT_SYMBOL_GPL(rt2x00mac_reconfig_complete);
+
 int rt2x00mac_add_interface(struct ieee80211_hw *hw,
 			    struct ieee80211_vif *vif)
 {
Signature · 1 line
2.13.5
#1 lore raw

PATCH 2/2 rt2x00: use RESET state bit to prevent IV changes on restart

We can not set IV when we are under reset. Previously we read previous IV value from registers and zeroed IV registers when key was deleted, but this could possibly not work if DEL_KEY command was not performed.

Now when we have ->reconfig_complete ops and we fully mark mac80211 reset state via DEVICE_STATE_RESET flag, we can just skip setting IV when keys are set during reset.

---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ralink/rt2x00/rt2800lib.c +9 -12
index f1cdcd61c54a..590e4fa9e5e4 100644
@@ -1652,20 +1652,17 @@ static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
 		rt2800_register_write(rt2x00dev, offset, reg);
 	}
 
-	offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
+	if (test_bit(DEVICE_STATE_RESET, &rt2x00dev->flags))
+		return;
 
-	if (crypto->cmd == SET_KEY) {
-		rt2800_register_multiread(rt2x00dev, offset,
-					  &iveiv_entry, sizeof(iveiv_entry));
-		if ((crypto->cipher == CIPHER_TKIP) ||
-		    (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
-		    (crypto->cipher == CIPHER_AES))
-			iveiv_entry.iv[3] |= 0x20;
-		iveiv_entry.iv[3] |= key->keyidx << 6;
-	} else {
-		memset(&iveiv_entry, 0, sizeof(iveiv_entry));
-	}
+	offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
 
+	memset(&iveiv_entry, 0, sizeof(iveiv_entry));
+	if ((crypto->cipher == CIPHER_TKIP) ||
+	    (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
+	    (crypto->cipher == CIPHER_AES))
+		iveiv_entry.iv[3] |= 0x20;
+	iveiv_entry.iv[3] |= key->keyidx << 6;
 	rt2800_register_multiwrite(rt2x00dev, offset,
 				   &iveiv_entry, sizeof(iveiv_entry));
 }
Signature · 1 line
2.13.5
#2 lore raw
In reply to Stanislaw Gruszka
Quoted 5 lines · Stanislaw Gruszka

mac80211 has .reconfig_complete that can be used as indicator of HW restart end. This will allow to configure keys/IV differently for HW restart and normal configuration.

2 patches applied to wireless-drivers-next.git, thanks.

57f9807d1ea2 rt2x00: implement reconfig_complete
2d52378a0ad0 rt2x00: use RESET state bit to prevent IV changes on restart

Signature · 3 lines
https://patchwork.kernel.org/patch/11265643/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches