Skip to contentSkip to conversation

ath: Move key cache functions to ath common

PATCH In review Bruno Randolf 4 participants 18 messages Sep 8, 2010 – Sep 15, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ath: Move key cache functions to ath common

The following series moves the key cache management functions from ath9k to the common ath/key.c so we can also use them from ath5k. Both ath5k and ath9k are changed to use the common key functions.

This is necessary since HW encryption in ath5k was broken for AP mode and software encryption was enabled as a workaround (in "ath5k: temporarily disable crypto for AP mode", 65b5a69860ed3bc4224368b804d381cd9cafa90a). Using software encryption has a performance impact, which we would like to avoid, especially on embedded boards, which is where AP configurations are most common. On embedded AP boards we definetly want to make use of the chipsets HW encryption.

The symptom of the broken HW encryption was that when two clients connected to one AP with WPA (AES or TKIP) as soon as the second client connected, the first one was not able to send or receive packets.

Rather than trying to fix the ath5k implementation, i think it makes more sense to share this code between ath5k and ath9k.

This series was tested with ath5k (AR5414) in AP and station mode and with ath9k 9160 in AP mode, both with TKIP and AES. ath9k_htc was compile tested only.

bruno

---

Bruno Randolf (8):
ath: Copy cryptographic capability flags into ath
ath: Copy key cache management functions from ath9k to ath
ath5k: Use common ath key management functions
ath5k: Remove old ath5k key handling functions ath/ath9k: Replace common->splitmic with a flag
ath5k: Use common crypt capabilities flags
ath9k: Use common ath key management functions
ath9k: Use common crypt capabilities flags

 drivers/net/wireless/ath/Makefile             |    3
 drivers/net/wireless/ath/ath.h                |   39 ++
 drivers/net/wireless/ath/ath5k/ath5k.h        |    7
 drivers/net/wireless/ath/ath5k/attach.c       |   13 -
 drivers/net/wireless/ath/ath5k/base.c         |   35 +-
 drivers/net/wireless/ath/ath5k/pcu.c          |  191 --------
 drivers/net/wireless/ath/ath5k/reg.h          |   42 --
 drivers/net/wireless/ath/ath9k/common.c       |  270 ------------
 drivers/net/wireless/ath/ath9k/common.h       |    6
 drivers/net/wireless/ath/ath9k/htc_drv_init.c |    2
 drivers/net/wireless/ath/ath9k/htc_drv_main.c |    4
 drivers/net/wireless/ath/ath9k/hw.c           |  288 -------------
 drivers/net/wireless/ath/ath9k/hw.h           |   46 +-
 drivers/net/wireless/ath/ath9k/init.c         |    6
 drivers/net/wireless/ath/ath9k/mac.h          |   21 -
 drivers/net/wireless/ath/ath9k/main.c         |    4
 drivers/net/wireless/ath/ath9k/phy.h          |    3
 drivers/net/wireless/ath/key.c                |  568
+++++++++++++++++++++++++
 drivers/net/wireless/ath/reg.h                |   23 +
 19 files changed, 686 insertions(+), 885 deletions(-)
 create mode 100644 drivers/net/wireless/ath/key.c

--

#1 lore raw

PATCH 1/8 ath: Copy cryptographic capability flags into ath

This will be used later in this patch series.

---
 drivers/net/wireless/ath/ath.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/net/wireless/ath/ath.h +10 -0
index a706202..057fdd7 100644
@@ -71,6 +71,15 @@ struct ath_regulatory {
 	struct reg_dmn_pair_mapping *regpair;
 };
 
+enum ath_crypt_caps {
+	ATH_CRYPT_CAP_MIC_AESCCM		= BIT(0),
+	ATH_CRYPT_CAP_MIC_CKIP			= BIT(1),
+	ATH_CRYPT_CAP_MIC_TKIP			= BIT(2),
+	ATH_CRYPT_CAP_CIPHER_AESCCM		= BIT(3),
+	ATH_CRYPT_CAP_CIPHER_CKIP		= BIT(4),
+	ATH_CRYPT_CAP_CIPHER_TKIP		= BIT(5),
+};
+
 /**
  * struct ath_ops - Register read/write operations
  *
@@ -121,6 +130,7 @@ struct ath_common {
 	DECLARE_BITMAP(keymap, ATH_KEYMAX);
 	DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
 	u8 splitmic;
+	enum ath_crypt_caps crypt_caps;
 
 	struct ath_regulatory regulatory;
 	const struct ath_ops *ops;
#2 lore raw

PATCH 2/8 ath: Copy key cache management functions from ath9k to ath

In reply to Bruno Randolf

Copied the key cache management functions from ath9k (common.c and hw.c) to ath/key.c so we can use them from ath5k, later.

Minor changes have been made:
- renamed ath9k_* to ath_*
- replaced ah->caps.keycache_size with common->keymax
- removed ATH9K_IS_MIC_ENABLED since it is always true.
- the AR_PCU_MIC_NEW_LOC_ENA flag is replaced with (splitmic == 0).

---
 drivers/net/wireless/ath/Makefile |    3 
 drivers/net/wireless/ath/ath.h    |   27 ++
 drivers/net/wireless/ath/key.c    |  568 +++++++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/reg.h    |   23 +
 4 files changed, 620 insertions(+), 1 deletions(-)
 create mode 100644 drivers/net/wireless/ath/key.c
drivers/net/wireless/ath/Makefile +2 -1
index 8113a50..9df4406 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_ATH_COMMON)	+= ath.o
 
 ath-objs :=	main.o \
 		regd.o \
-		hw.o
+		hw.o \
+		key.o
 
 ath-$(CONFIG_ATH_DEBUG) += debug.o
drivers/net/wireless/ath/ath.h +27 -0
index 057fdd7..fb24f66 100644
@@ -80,6 +80,27 @@ enum ath_crypt_caps {
 	ATH_CRYPT_CAP_CIPHER_TKIP		= BIT(5),
 };
 
+struct ath_keyval {
+	u8 kv_type;
+	u8 kv_pad;
+	u16 kv_len;
+	u8 kv_val[16]; /* TK */
+	u8 kv_mic[8]; /* Michael MIC key */
+	u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
+			 * supports both MIC keys in the same key cache entry;
+			 * in that case, kv_mic is the RX key) */
+};
+
+enum ath_cipher {
+	ATH_CIPHER_WEP = 0,
+	ATH_CIPHER_AES_OCB = 1,
+	ATH_CIPHER_AES_CCM = 2,
+	ATH_CIPHER_CKIP = 3,
+	ATH_CIPHER_TKIP = 4,
+	ATH_CIPHER_CLR = 5,
+	ATH_CIPHER_MIC = 127
+};
+
 /**
  * struct ath_ops - Register read/write operations
  *
@@ -142,5 +163,11 @@ struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
 				gfp_t gfp_mask);
 
 void ath_hw_setbssidmask(struct ath_common *common);
+void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key);
+int ath_key_config(struct ath_common *common,
+			  struct ieee80211_vif *vif,
+			  struct ieee80211_sta *sta,
+			  struct ieee80211_key_conf *key);
+bool ath_hw_keyreset(struct ath_common *common, u16 entry);
 
 #endif /* ATH_H */
drivers/net/wireless/ath/key.c new file +568 -0

568 lines not on this page · raw message

drivers/net/wireless/ath/reg.h +23 -0
index dfe1fbe..e798ef4 100644
@@ -24,4 +24,27 @@
 #define AR_BSSMSKL		0x80e0
 #define AR_BSSMSKU		0x80e4
 
+#define AR_KEYTABLE_0           0x8800
+#define AR_KEYTABLE(_n)         (AR_KEYTABLE_0 + ((_n)*32))
+#define AR_KEY_CACHE_SIZE       128
+#define AR_RSVD_KEYTABLE_ENTRIES 4
+#define AR_KEY_TYPE             0x00000007
+#define AR_KEYTABLE_TYPE_40     0x00000000
+#define AR_KEYTABLE_TYPE_104    0x00000001
+#define AR_KEYTABLE_TYPE_128    0x00000003
+#define AR_KEYTABLE_TYPE_TKIP   0x00000004
+#define AR_KEYTABLE_TYPE_AES    0x00000005
+#define AR_KEYTABLE_TYPE_CCM    0x00000006
+#define AR_KEYTABLE_TYPE_CLR    0x00000007
+#define AR_KEYTABLE_ANT         0x00000008
+#define AR_KEYTABLE_VALID       0x00008000
+#define AR_KEYTABLE_KEY0(_n)    (AR_KEYTABLE(_n) + 0)
+#define AR_KEYTABLE_KEY1(_n)    (AR_KEYTABLE(_n) + 4)
+#define AR_KEYTABLE_KEY2(_n)    (AR_KEYTABLE(_n) + 8)
+#define AR_KEYTABLE_KEY3(_n)    (AR_KEYTABLE(_n) + 12)
+#define AR_KEYTABLE_KEY4(_n)    (AR_KEYTABLE(_n) + 16)
+#define AR_KEYTABLE_TYPE(_n)    (AR_KEYTABLE(_n) + 20)
+#define AR_KEYTABLE_MAC0(_n)    (AR_KEYTABLE(_n) + 24)
+#define AR_KEYTABLE_MAC1(_n)    (AR_KEYTABLE(_n) + 28)
+
 #endif /* ATH_REGISTERS_H */
#3 lore raw

PATCH 3/8 ath5k: Use common ath key management functions

In reply to Bruno Randolf

Use common ath key management functions in ath5k. This fixes problems with HW encryption in AP mode, which was broken in the ath5k implementation.

Before (with the ath5k implementation) only one client could connect to the AP using HW encryption and WPA. When a second client connected, the first client was not able to send/receive any more packets. Because of the problems with HW encryption, software encryption was always used in AP mode, which resulted in a high CPU load (and/or low thruput) on embedded devices. Instead of trying to fix the implementation in ath5k it makes more sense to share the code with ath9k.

This also enables HW encryption for AP mode again.

---
 drivers/net/wireless/ath/ath5k/attach.c |    3 +++
 drivers/net/wireless/ath/ath5k/base.c   |   33 +++++++++++++------------------
 2 files changed, 17 insertions(+), 19 deletions(-)
drivers/net/wireless/ath/ath5k/attach.c +3 -0
index aabad4f..eb125d6 100644
@@ -314,6 +314,9 @@ int ath5k_hw_attach(struct ath5k_softc *sc)
 	}
 
 	/* Crypto settings */
+	common->keymax = (sc->ah->ah_version == AR5K_AR5210 ?
+			  AR5K_KEYTABLE_SIZE_5210 : AR5K_KEYTABLE_SIZE_5211);
+
 	ah->ah_aes_support = srev >= AR5K_SREV_AR5212_V4 &&
 		(ee->ee_version >= AR5K_EEPROM_VERSION_5_0 &&
 		 !AR5K_EEPROM_AES_DIS(ee->ee_misc5));
drivers/net/wireless/ath/ath5k/base.c +14 -19
index 116ac66..9e907da 100644
@@ -2574,6 +2574,7 @@ static int
 ath5k_init(struct ath5k_softc *sc)
 {
 	struct ath5k_hw *ah = sc->ah;
+	struct ath_common *common = ath5k_hw_common(ah);
 	int ret, i;
 
 	mutex_lock(&sc->lock);
@@ -2609,8 +2610,8 @@ ath5k_init(struct ath5k_softc *sc)
 	 * Reset the key cache since some parts do not reset the
 	 * contents on initial power up or resume from suspend.
 	 */
-	for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
-		ath5k_hw_reset_key(ah, i);
+	for (i = 0; i < common->keymax; i++)
+		ath_hw_keyreset(common, (u16)i);
 
 	ath5k_hw_set_ack_bitrate_high(ah, true);
 	ret = 0;
@@ -3291,9 +3292,6 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	if (modparam_nohwcrypt)
 		return -EOPNOTSUPP;
 
-	if (sc->opmode == NL80211_IFTYPE_AP)
-		return -EOPNOTSUPP;
-
 	switch (key->cipher) {
 	case WLAN_CIPHER_SUITE_WEP40:
 	case WLAN_CIPHER_SUITE_WEP104:
@@ -3302,7 +3300,6 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	case WLAN_CIPHER_SUITE_CCMP:
 		if (sc->ah->ah_aes_support)
 			break;
-
 		return -EOPNOTSUPP;
 	default:
 		WARN_ON(1);
@@ -3313,27 +3310,25 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
 	switch (cmd) {
 	case SET_KEY:
-		ret = ath5k_hw_set_key(sc->ah, key->keyidx, key,
-				       sta ? sta->addr : NULL);
-		if (ret) {
-			ATH5K_ERR(sc, "can't set the key\n");
-			goto unlock;
+		ret = ath_key_config(common, vif, sta, key);
+		if (ret >= 0) {
+			key->hw_key_idx = ret;
+			/* push IV and Michael MIC generation to stack */
+			key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+			if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
+				key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
+			if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
+				key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
+			ret = 0;
 		}
-		__set_bit(key->keyidx, common->keymap);
-		key->hw_key_idx = key->keyidx;
-		key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
-			       IEEE80211_KEY_FLAG_GENERATE_MMIC);
 		break;
 	case DISABLE_KEY:
-		ath5k_hw_reset_key(sc->ah, key->keyidx);
-		__clear_bit(key->keyidx, common->keymap);
+		ath_key_delete(common, key);
 		break;
 	default:
 		ret = -EINVAL;
-		goto unlock;
 	}
 
-unlock:
 	mmiowb();
 	mutex_unlock(&sc->lock);
 	return ret;
#4 lore raw

Re: [PATCH 3/8] ath5k: Use common ath key management functions

Quoted 2 lines · Bruno Randolf

Use common ath key management functions in ath5k. This fixes problems with HW encryption in AP mode, which was broken in the ath5k implementation.

We went from this:

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3325

Quoted 2 lines
drivers/net/wireless/ath/ath5k/base.c +0 -2
-		key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
-			       IEEE80211_KEY_FLAG_GENERATE_MMIC);

to:

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3319

Quoted 4 lines
drivers/net/wireless/ath/ath5k/base.c +4 -0
+			/* push IV and Michael MIC generation to stack */
+			key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+			if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
+				key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;

There's no need to special case the flags based on whether the cipher is TKIP; mac80211 does this already.

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3321

Quoted 2 lines
drivers/net/wireless/ath/ath5k/base.c +2 -0
+			if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
+				key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;

Ditto, this already only affects CCMP in mac80211 (btw, why can't we do management frames in hardware?) so it can be more simply written as:

key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |

               IEEE80211_KEY_FLAG_GENERATE_MMIC |
               IEEE80211_KEY_FLAG_SW_MGMT);
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#5 lore raw

Re: [ath5k-devel] [PATCH 3/8] ath5k: Use common ath key management functions

Quoted 24 lines · On Sun September 12 2010 02:22:50 [email protected] wrote:
Quoted 3 lines · Bruno Randolf

Use common ath key management functions in ath5k. This fixes problems with HW encryption in AP mode, which was broken in the ath5k implementation.

We went from this:

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3325

Quoted 2 lines
drivers/net/wireless/ath/ath5k/base.c +0 -2
-		key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
-			       IEEE80211_KEY_FLAG_GENERATE_MMIC);

to:

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3319

Quoted 4 lines
drivers/net/wireless/ath/ath5k/base.c +4 -0
+			/* push IV and Michael MIC generation to stack */
+			key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+			if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
+				key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;

There's no need to special case the flags based on whether the cipher is TKIP; mac80211 does this already.

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3321

Quoted 2 lines
drivers/net/wireless/ath/ath5k/base.c +2 -0
+			if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
+				key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;

Ditto, this already only affects CCMP in mac80211 (btw, why can't we do management frames in hardware?) so it can be more simply written as:

Quoted 3 lines

key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |

               IEEE80211_KEY_FLAG_GENERATE_MMIC |
               IEEE80211_KEY_FLAG_SW_MGMT);

i just copied the code from ath9k, but you're right - i'll simplify it and send a patch v2.

i don't know wether we can encrypt management frames in HW, so until this is sorted out, i disabled it.

bruno

#6 lore raw

Re: [ath5k-devel] [PATCH 3/8] ath5k: Use common ath key management functions

Quoted 2 lines · Bruno Randolf

i don't know wether we can encrypt management frames in HW, so until this is sorted out, i disabled it.

I don't think any of the hardware supported by ath5k would be able to do this. IEEE 802.11w design changes in CCMP for management frames are more recent than the hardware designs supported by ath5k..

Signature · 1 line
Jouni Malinen                                            PGP id EFC895FA
#7 lore raw

PATCH 4/8 ath5k: Remove old ath5k key handling functions

In reply to Bruno Randolf

Remove the old ath5k key handling functions, since we now use the key management in ath common.

---
 drivers/net/wireless/ath/ath5k/ath5k.h |    5 -
 drivers/net/wireless/ath/ath5k/pcu.c   |  191 --------------------------------
 drivers/net/wireless/ath/ath5k/reg.h   |   42 -------
 3 files changed, 0 insertions(+), 238 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +0 -5
index f399c4d..932ed56 100644
@@ -1207,11 +1207,6 @@ void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high);
 unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec);
 unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock);
 unsigned int ath5k_hw_get_clockrate(struct ath5k_hw *ah);
-/* Key table (WEP) functions */
-int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry);
-int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
-		     const struct ieee80211_key_conf *key, const u8 *mac);
-int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac);
 
 /* Queue Control Unit, DFS Control Unit Functions */
 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
drivers/net/wireless/ath/ath5k/pcu.c +0 -191

197 lines not on this page · raw message

drivers/net/wireless/ath/ath5k/reg.h +0 -42

50 lines not on this page · raw message

#9 lore raw

PATCH 5/8 ath/ath9k: Replace common->splitmic with a flag

In reply to Bruno Randolf

Replace common->splitmic with ATH_CRYPT_CAP_MIC_COMBINED flag.

splitmic has to be used when the ATH_CRYPT_CAP_MIC_COMBINED capability flag is not set.

---
 drivers/net/wireless/ath/ath.h          |    2 +-
 drivers/net/wireless/ath/ath9k/common.c |   12 ++++++------
 drivers/net/wireless/ath/ath9k/init.c   |    4 ++--
 drivers/net/wireless/ath/key.c          |   14 +++++++-------
 4 files changed, 16 insertions(+), 16 deletions(-)
drivers/net/wireless/ath/ath.h +1 -1
index fb24f66..c558407 100644
@@ -78,6 +78,7 @@ enum ath_crypt_caps {
 	ATH_CRYPT_CAP_CIPHER_AESCCM		= BIT(3),
 	ATH_CRYPT_CAP_CIPHER_CKIP		= BIT(4),
 	ATH_CRYPT_CAP_CIPHER_TKIP		= BIT(5),
+	ATH_CRYPT_CAP_MIC_COMBINED		= BIT(6),
 };
 
 struct ath_keyval {
@@ -150,7 +151,6 @@ struct ath_common {
 	u32 keymax;
 	DECLARE_BITMAP(keymap, ATH_KEYMAX);
 	DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
-	u8 splitmic;
 	enum ath_crypt_caps crypt_caps;
 
 	struct ath_regulatory regulatory;
drivers/net/wireless/ath/ath9k/common.c +6 -6
index 2dab64b..2db24eb 100644
@@ -174,7 +174,7 @@ static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
 		}
 		return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
 	}
-	if (!common->splitmic) {
+	if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
 		/* TX and RX keys share the same key cache entry. */
 		memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
 		memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
@@ -205,7 +205,7 @@ static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
 		if (test_bit(i, common->keymap) ||
 		    test_bit(i + 64, common->keymap))
 			continue; /* At least one part of TKIP key allocated */
-		if (common->splitmic &&
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) &&
 		    (test_bit(i + 32, common->keymap) ||
 		     test_bit(i + 64 + 32, common->keymap)))
 			continue; /* At least one part of TKIP key allocated */
@@ -225,7 +225,7 @@ static int ath_reserve_key_cache_slot(struct ath_common *common,
 		return ath_reserve_key_cache_slot_tkip(common);
 
 	/* First, try to find slots that would not be available for TKIP. */
-	if (common->splitmic) {
+	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 		for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
 			if (!test_bit(i, common->keymap) &&
 			    (test_bit(i + 32, common->keymap) ||
@@ -266,7 +266,7 @@ static int ath_reserve_key_cache_slot(struct ath_common *common,
 		 * TKIP will not be used. */
 		if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
 			continue;
-		if (common->splitmic) {
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 			if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
 				continue;
 			if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
@@ -374,7 +374,7 @@ int ath9k_cmn_key_config(struct ath_common *common,
 		set_bit(idx + 64, common->keymap);
 		set_bit(idx, common->tkip_keymap);
 		set_bit(idx + 64, common->tkip_keymap);
-		if (common->splitmic) {
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 			set_bit(idx + 32, common->keymap);
 			set_bit(idx + 64 + 32, common->keymap);
 			set_bit(idx + 32, common->tkip_keymap);
@@ -407,7 +407,7 @@ void ath9k_cmn_key_delete(struct ath_common *common,
 	clear_bit(key->hw_key_idx, common->tkip_keymap);
 	clear_bit(key->hw_key_idx + 64, common->tkip_keymap);
 
-	if (common->splitmic) {
+	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 		ath9k_hw_keyreset(ah, key->hw_key_idx + 32);
 		clear_bit(key->hw_key_idx + 32, common->keymap);
 		clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
drivers/net/wireless/ath/ath9k/init.c +2 -2
index 3dbff8d..d41e41d 100644
@@ -389,8 +389,8 @@ static void ath9k_init_crypto(struct ath_softc *sc)
 	 * With split mic keys the number of stations is limited
 	 * to 27 otherwise 59.
 	 */
-	if (!(sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA))
-		common->splitmic = 1;
+	if (sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
+		common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
 }
 
 static int ath9k_init_btcoex(struct ath_softc *sc)
drivers/net/wireless/ath/key.c +7 -7
index e45b854..bd21a4d 100644
@@ -201,7 +201,7 @@ bool ath_hw_set_keycache_entry(struct ath_common *common, u16 entry,
 		/* Write MAC address for the entry */
 		(void) ath_hw_keysetmac(common, entry, mac);
 
-		if (common->splitmic == 0) {
+		if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
 			/*
 			 * TKIP uses two key cache entries:
 			 * Michael MIC TX/RX keys in the same key cache entry
@@ -327,7 +327,7 @@ static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
 		}
 		return ath_hw_set_keycache_entry(common, keyix, hk, addr);
 	}
-	if (!common->splitmic) {
+	if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
 		/* TX and RX keys share the same key cache entry. */
 		memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
 		memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
@@ -358,7 +358,7 @@ static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
 		if (test_bit(i, common->keymap) ||
 		    test_bit(i + 64, common->keymap))
 			continue; /* At least one part of TKIP key allocated */
-		if (common->splitmic &&
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) &&
 		    (test_bit(i + 32, common->keymap) ||
 		     test_bit(i + 64 + 32, common->keymap)))
 			continue; /* At least one part of TKIP key allocated */
@@ -378,7 +378,7 @@ static int ath_reserve_key_cache_slot(struct ath_common *common,
 		return ath_reserve_key_cache_slot_tkip(common);
 
 	/* First, try to find slots that would not be available for TKIP. */
-	if (common->splitmic) {
+	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 		for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
 			if (!test_bit(i, common->keymap) &&
 			    (test_bit(i + 32, common->keymap) ||
@@ -419,7 +419,7 @@ static int ath_reserve_key_cache_slot(struct ath_common *common,
 		 * TKIP will not be used. */
 		if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
 			continue;
-		if (common->splitmic) {
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 			if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
 				continue;
 			if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
@@ -526,7 +526,7 @@ int ath_key_config(struct ath_common *common,
 		set_bit(idx + 64, common->keymap);
 		set_bit(idx, common->tkip_keymap);
 		set_bit(idx + 64, common->tkip_keymap);
-		if (common->splitmic) {
+		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 			set_bit(idx + 32, common->keymap);
 			set_bit(idx + 64 + 32, common->keymap);
 			set_bit(idx + 32, common->tkip_keymap);
@@ -556,7 +556,7 @@ void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
 	clear_bit(key->hw_key_idx, common->tkip_keymap);
 	clear_bit(key->hw_key_idx + 64, common->tkip_keymap);
 
-	if (common->splitmic) {
+	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
 		ath_hw_keyreset(common, key->hw_key_idx + 32);
 		clear_bit(key->hw_key_idx + 32, common->keymap);
 		clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
Acked-by Bob Copeland on v1 5/8
#10 lore raw

Re: [PATCH 5/8] ath/ath9k: Replace common->splitmic with a flag

Quoted 6 lines · Bruno Randolf

Replace common->splitmic with ATH_CRYPT_CAP_MIC_COMBINED flag.

splitmic has to be used when the ATH_CRYPT_CAP_MIC_COMBINED capability flag is not set.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#11 lore raw

PATCH 6/8 ath5k: Use common crypt capabilities flags

In reply to Bruno Randolf

Replace ah_aes_support and ah_combined_mic with common ath_crypt_caps ATH_CRYPT_CAP_CIPHER_AESCCM and ATH_CRYPT_CAP_MIC_COMBINED.

---
 drivers/net/wireless/ath/ath5k/ath5k.h  |    2 --
 drivers/net/wireless/ath/ath5k/attach.c |   10 ++++++----
 drivers/net/wireless/ath/ath5k/base.c   |    2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +0 -2
index 932ed56..50209ae 100644
@@ -1028,8 +1028,6 @@ struct ath5k_hw {
 	bool			ah_turbo;
 	bool			ah_calibration;
 	bool			ah_single_chip;
-	bool			ah_aes_support;
-	bool			ah_combined_mic;
 
 	enum ath5k_version	ah_version;
 	enum ath5k_radio	ah_radio;
drivers/net/wireless/ath/ath5k/attach.c +6 -4
index eb125d6..a0e0820 100644
@@ -317,12 +317,14 @@ int ath5k_hw_attach(struct ath5k_softc *sc)
 	common->keymax = (sc->ah->ah_version == AR5K_AR5210 ?
 			  AR5K_KEYTABLE_SIZE_5210 : AR5K_KEYTABLE_SIZE_5211);
 
-	ah->ah_aes_support = srev >= AR5K_SREV_AR5212_V4 &&
-		(ee->ee_version >= AR5K_EEPROM_VERSION_5_0 &&
-		 !AR5K_EEPROM_AES_DIS(ee->ee_misc5));
+	if (srev >= AR5K_SREV_AR5212_V4 &&
+	    (ee->ee_version >= AR5K_EEPROM_VERSION_5_0 &&
+	    !AR5K_EEPROM_AES_DIS(ee->ee_misc5)))
+		common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM |
+					ATH_CRYPT_CAP_MIC_AESCCM;
 
 	if (srev >= AR5K_SREV_AR2414) {
-		ah->ah_combined_mic = true;
+		common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
 		AR5K_REG_ENABLE_BITS(ah, AR5K_MISC_MODE,
 			AR5K_MISC_MODE_COMBINED_MIC);
 	}
drivers/net/wireless/ath/ath5k/base.c +1 -1
index 9e907da..f8c699d 100644
@@ -3298,7 +3298,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	case WLAN_CIPHER_SUITE_TKIP:
 		break;
 	case WLAN_CIPHER_SUITE_CCMP:
-		if (sc->ah->ah_aes_support)
+		if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
 			break;
 		return -EOPNOTSUPP;
 	default:
#12 lore raw

Re: [PATCH 6/8] ath5k: Use common crypt capabilities flags

Quoted 8 lines · Bruno Randolf

Replace ah_aes_support and ah_combined_mic with common ath_crypt_caps ATH_CRYPT_CAP_CIPHER_AESCCM and ATH_CRYPT_CAP_MIC_COMBINED.

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3303

Quoted 7 lines
drivers/net/wireless/ath/ath5k/base.c +1 -1
@@ -3298,7 +3298,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	case WLAN_CIPHER_SUITE_TKIP:
 		break;
 	case WLAN_CIPHER_SUITE_CCMP:
-		if (sc->ah->ah_aes_support)
+		if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
 			break;
 		return -EOPNOTSUPP;

This could be done by the common code too, right?

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#13 lore raw

Re: [PATCH 6/8] ath5k: Use common crypt capabilities flags

Quoted 18 lines · On Sun September 12 2010 02:27:52 you wrote:
Quoted 17 lines · Bruno Randolf

Replace ah_aes_support and ah_combined_mic with common ath_crypt_caps ATH_CRYPT_CAP_CIPHER_AESCCM and ATH_CRYPT_CAP_MIC_COMBINED.

drivers/net/wireless/ath/ath5k/base.c +1 -1
@@ -3298,7 +3298,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum
 set_key_cmd cmd,
 
 	case WLAN_CIPHER_SUITE_TKIP:
 		break;
 
 	case WLAN_CIPHER_SUITE_CCMP:
-		if (sc->ah->ah_aes_support)
+		if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
Quoted 5 lines

drivers/net/wireless/ath/ath5k/base.c ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, · line 3303

Quoted 3 lines
drivers/net/wireless/ath/ath5k/base.c +0 -0
 			break;
 
 		return -EOPNOTSUPP;

This could be done by the common code too, right?

yes... ath9k doesn't do this, but i left the old code because i wasn't sure if we need it or not. can we sort this out in a following patch?

bruno

#14 lore raw

Re: [ath5k-devel] [PATCH 6/8] ath5k: Use common crypt capabilities flags

Quoted 19 lines · Bruno Randolf
Quoted 18 lines · On Sun September 12 2010 02:27:52 you wrote:
Quoted 17 lines · Bruno Randolf

Replace ah_aes_support and ah_combined_mic with common ath_crypt_caps ATH_CRYPT_CAP_CIPHER_AESCCM and ATH_CRYPT_CAP_MIC_COMBINED.

drivers/net/wireless/ath/ath5k/base.c +0 -0
@@ -3298,7 +3298,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum
 set_key_cmd cmd,
 

    case WLAN_CIPHER_SUITE_TKIP:
            break;

    case WLAN_CIPHER_SUITE_CCMP:
-           if (sc->ah->ah_aes_support)
+           if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

                    break;

            return -EOPNOTSUPP;

This could be done by the common code too, right?

yes... ath9k doesn't do this, but i left the old code because i wasn't sure if we need it or not. can we sort this out in a following patch?

Yeah, I guess only certain ath5k chipsets do CCMP while all ath9k ones do.. for sure, follow-up patches are fine for my minor comments, none of them affect functionality.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#15 lore raw

PATCH 7/8 ath9k: Use common ath key management functions

In reply to Bruno Randolf

Use key management functions which have been moved to ath/key.c and remove ath9k copies of these functions and other now unused definitions.

---
 drivers/net/wireless/ath/ath9k/common.c       |  270 ------------------------
 drivers/net/wireless/ath/ath9k/common.h       |    6 -
 drivers/net/wireless/ath/ath9k/htc_drv_init.c |    2 
 drivers/net/wireless/ath/ath9k/htc_drv_main.c |    4 
 drivers/net/wireless/ath/ath9k/hw.c           |  276 -------------------------
 drivers/net/wireless/ath/ath9k/hw.h           |    6 -
 drivers/net/wireless/ath/ath9k/init.c         |    2 
 drivers/net/wireless/ath/ath9k/mac.h          |   21 --
 drivers/net/wireless/ath/ath9k/main.c         |    4 
 drivers/net/wireless/ath/ath9k/phy.h          |    3 
 10 files changed, 6 insertions(+), 588 deletions(-)
drivers/net/wireless/ath/ath9k/common.c +0 -270
index 2db24eb..f43a2d9 100644
@@ -148,276 +148,6 @@ struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
 }
 EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
 
-static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
-			   struct ath9k_keyval *hk, const u8 *addr,
-			   bool authenticator)
-{
-	struct ath_hw *ah = common->ah;
-	const u8 *key_rxmic;
-	const u8 *key_txmic;
-
-	key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
-	key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
-
-	if (addr == NULL) {
-		/*
-		 * Group key installation - only two key cache entries are used
-		 * regardless of splitmic capability since group key is only
-		 * used either for TX or RX.
-		 */
-		if (authenticator) {
-			memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
-			memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
-		} else {
-			memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
-			memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
-		}
-		return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
-	}
-	if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
-		/* TX and RX keys share the same key cache entry. */
-		memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
-		memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
-		return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
-	}
-
-	/* Separate key cache entries for TX and RX */
-
-	/* TX key goes at first index, RX key at +32. */
-	memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
-	if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
-		/* TX MIC entry failed. No need to proceed further */
-		ath_print(common, ATH_DBG_FATAL,
-			  "Setting TX MIC Key Failed\n");
-		return 0;
-	}
-
-	memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
-	/* XXX delete tx key on failure? */
-	return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
-}
-
-static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
-{
-	int i;
-
-	for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
-		if (test_bit(i, common->keymap) ||
-		    test_bit(i + 64, common->keymap))
-			continue; /* At least one part of TKIP key allocated */
-		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) &&
-		    (test_bit(i + 32, common->keymap) ||
-		     test_bit(i + 64 + 32, common->keymap)))
-			continue; /* At least one part of TKIP key allocated */
-
-		/* Found a free slot for a TKIP key */
-		return i;
-	}
-	return -1;
-}
-
-static int ath_reserve_key_cache_slot(struct ath_common *common,
-				      u32 cipher)
-{
-	int i;
-
-	if (cipher == WLAN_CIPHER_SUITE_TKIP)
-		return ath_reserve_key_cache_slot_tkip(common);
-
-	/* First, try to find slots that would not be available for TKIP. */
-	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
-		for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
-			if (!test_bit(i, common->keymap) &&
-			    (test_bit(i + 32, common->keymap) ||
-			     test_bit(i + 64, common->keymap) ||
-			     test_bit(i + 64 + 32, common->keymap)))
-				return i;
-			if (!test_bit(i + 32, common->keymap) &&
-			    (test_bit(i, common->keymap) ||
-			     test_bit(i + 64, common->keymap) ||
-			     test_bit(i + 64 + 32, common->keymap)))
-				return i + 32;
-			if (!test_bit(i + 64, common->keymap) &&
-			    (test_bit(i , common->keymap) ||
-			     test_bit(i + 32, common->keymap) ||
-			     test_bit(i + 64 + 32, common->keymap)))
-				return i + 64;
-			if (!test_bit(i + 64 + 32, common->keymap) &&
-			    (test_bit(i, common->keymap) ||
-			     test_bit(i + 32, common->keymap) ||
-			     test_bit(i + 64, common->keymap)))
-				return i + 64 + 32;
-		}
-	} else {
-		for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
-			if (!test_bit(i, common->keymap) &&
-			    test_bit(i + 64, common->keymap))
-				return i;
-			if (test_bit(i, common->keymap) &&
-			    !test_bit(i + 64, common->keymap))
-				return i + 64;
-		}
-	}
-
-	/* No partially used TKIP slots, pick any available slot */
-	for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
-		/* Do not allow slots that could be needed for TKIP group keys
-		 * to be used. This limitation could be removed if we know that
-		 * TKIP will not be used. */
-		if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
-			continue;
-		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
-			if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
-				continue;
-			if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
-				continue;
-		}
-
-		if (!test_bit(i, common->keymap))
-			return i; /* Found a free slot for a key */
-	}
-
-	/* No free slot found */
-	return -1;
-}
-
-/*
- * Configure encryption in the HW.
- */
-int ath9k_cmn_key_config(struct ath_common *common,
-			 struct ieee80211_vif *vif,
-			 struct ieee80211_sta *sta,
-			 struct ieee80211_key_conf *key)
-{
-	struct ath_hw *ah = common->ah;
-	struct ath9k_keyval hk;
-	const u8 *mac = NULL;
-	u8 gmac[ETH_ALEN];
-	int ret = 0;
-	int idx;
-
-	memset(&hk, 0, sizeof(hk));
-
-	switch (key->cipher) {
-	case WLAN_CIPHER_SUITE_WEP40:
-	case WLAN_CIPHER_SUITE_WEP104:
-		hk.kv_type = ATH9K_CIPHER_WEP;
-		break;
-	case WLAN_CIPHER_SUITE_TKIP:
-		hk.kv_type = ATH9K_CIPHER_TKIP;
-		break;
-	case WLAN_CIPHER_SUITE_CCMP:
-		hk.kv_type = ATH9K_CIPHER_AES_CCM;
-		break;
-	default:
-		return -EOPNOTSUPP;
-	}
-
-	hk.kv_len = key->keylen;
-	memcpy(hk.kv_val, key->key, key->keylen);
-
-	if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
-		switch (vif->type) {
-		case NL80211_IFTYPE_AP:
-			memcpy(gmac, vif->addr, ETH_ALEN);
-			gmac[0] |= 0x01;
-			mac = gmac;
-			idx = ath_reserve_key_cache_slot(common, key->cipher);
-			break;
-		case NL80211_IFTYPE_ADHOC:
-			if (!sta) {
-				idx = key->keyidx;
-				break;
-			}
-			memcpy(gmac, sta->addr, ETH_ALEN);
-			gmac[0] |= 0x01;
-			mac = gmac;
-			idx = ath_reserve_key_cache_slot(common, key->cipher);
-			break;
-		default:
-			idx = key->keyidx;
-			break;
-		}
-	} else if (key->keyidx) {
-		if (WARN_ON(!sta))
-			return -EOPNOTSUPP;
-		mac = sta->addr;
-
-		if (vif->type != NL80211_IFTYPE_AP) {
-			/* Only keyidx 0 should be used with unicast key, but
-			 * allow this for client mode for now. */
-			idx = key->keyidx;
-		} else
-			return -EIO;
-	} else {
-		if (WARN_ON(!sta))
-			return -EOPNOTSUPP;
-		mac = sta->addr;
-
-		idx = ath_reserve_key_cache_slot(common, key->cipher);
-	}
-
-	if (idx < 0)
-		return -ENOSPC; /* no free key cache entries */
-
-	if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
-		ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
-				      vif->type == NL80211_IFTYPE_AP);
-	else
-		ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
-
-	if (!ret)
-		return -EIO;
-
-	set_bit(idx, common->keymap);
-	if (key->cipher == WLAN_CIPHER_SUITE_TKIP) {
-		set_bit(idx + 64, common->keymap);
-		set_bit(idx, common->tkip_keymap);
-		set_bit(idx + 64, common->tkip_keymap);
-		if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
-			set_bit(idx + 32, common->keymap);
-			set_bit(idx + 64 + 32, common->keymap);
-			set_bit(idx + 32, common->tkip_keymap);
-			set_bit(idx + 64 + 32, common->tkip_keymap);
-		}
-	}
-
-	return idx;
-}
-EXPORT_SYMBOL(ath9k_cmn_key_config);
-
-/*
- * Delete Key.
- */
-void ath9k_cmn_key_delete(struct ath_common *common,
-			  struct ieee80211_key_conf *key)
-{
-	struct ath_hw *ah = common->ah;
-
-	ath9k_hw_keyreset(ah, key->hw_key_idx);
-	if (key->hw_key_idx < IEEE80211_WEP_NKID)
-		return;
-
-	clear_bit(key->hw_key_idx, common->keymap);
-	if (key->cipher != WLAN_CIPHER_SUITE_TKIP)
-		return;
-
-	clear_bit(key->hw_key_idx + 64, common->keymap);
-
-	clear_bit(key->hw_key_idx, common->tkip_keymap);
-	clear_bit(key->hw_key_idx + 64, common->tkip_keymap);
-
-	if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
-		ath9k_hw_keyreset(ah, key->hw_key_idx + 32);
-		clear_bit(key->hw_key_idx + 32, common->keymap);
-		clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
-
-		clear_bit(key->hw_key_idx + 32, common->tkip_keymap);
-		clear_bit(key->hw_key_idx + 64 + 32, common->tkip_keymap);
-	}
-}
-EXPORT_SYMBOL(ath9k_cmn_key_delete);
-
 int ath9k_cmn_count_streams(unsigned int chainmask, int max)
 {
 	int streams = 0;
drivers/net/wireless/ath/ath9k/common.h +0 -6
index 4aa4e7d..fea3b33 100644
@@ -66,12 +66,6 @@ void ath9k_cmn_update_ichannel(struct ieee80211_hw *hw,
 			       struct ath9k_channel *ichan);
 struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
 					       struct ath_hw *ah);
-int ath9k_cmn_key_config(struct ath_common *common,
-			 struct ieee80211_vif *vif,
-			 struct ieee80211_sta *sta,
-			 struct ieee80211_key_conf *key);
-void ath9k_cmn_key_delete(struct ath_common *common,
-			  struct ieee80211_key_conf *key);
 int ath9k_cmn_count_streams(unsigned int chainmask, int max);
 void ath9k_cmn_btcoex_bt_stomp(struct ath_common *common,
 				  enum ath_stomp_type stomp_type);
drivers/net/wireless/ath/ath9k/htc_drv_init.c +1 -1
index 695e2b0..2b762be 100644
@@ -566,7 +566,7 @@ static void ath9k_init_crypto(struct ath9k_htc_priv *priv)
 	 * reset the contents on initial power up.
 	 */
 	for (i = 0; i < common->keymax; i++)
-		ath9k_hw_keyreset(priv->ah, (u16) i);
+		ath_hw_keyreset(common, (u16) i);
 }
 
 static void ath9k_init_channels_rates(struct ath9k_htc_priv *priv)
drivers/net/wireless/ath/ath9k/htc_drv_main.c +2 -2
index f467207..8c353dd 100644
@@ -1591,7 +1591,7 @@ static int ath9k_htc_set_key(struct ieee80211_hw *hw,
 
 	switch (cmd) {
 	case SET_KEY:
-		ret = ath9k_cmn_key_config(common, vif, sta, key);
+		ret = ath_key_config(common, vif, sta, key);
 		if (ret >= 0) {
 			key->hw_key_idx = ret;
 			/* push IV and Michael MIC generation to stack */
@@ -1605,7 +1605,7 @@ static int ath9k_htc_set_key(struct ieee80211_hw *hw,
 		}
 		break;
 	case DISABLE_KEY:
-		ath9k_cmn_key_delete(common, key);
+		ath_key_delete(common, key);
 		break;
 	default:
 		ret = -EINVAL;
drivers/net/wireless/ath/ath9k/hw.c +0 -276

282 lines not on this page · raw message

drivers/net/wireless/ath/ath9k/hw.h +0 -6
index 1601dd4..1bee964 100644
@@ -874,12 +874,6 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
 int ath9k_hw_fill_cap_info(struct ath_hw *ah);
 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan);
 
-/* Key Cache Management */
-bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry);
-bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
-				 const struct ath9k_keyval *k,
-				 const u8 *mac);
-
 /* GPIO / RFKILL / Antennae */
 void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio);
 u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio);
drivers/net/wireless/ath/ath9k/init.c +1 -1
index d41e41d..f235508 100644
@@ -381,7 +381,7 @@ static void ath9k_init_crypto(struct ath_softc *sc)
 	 * reset the contents on initial power up.
 	 */
 	for (i = 0; i < common->keymax; i++)
-		ath9k_hw_keyreset(sc->sc_ah, (u16) i);
+		ath_hw_keyreset(common, (u16) i);
 
 	/*
 	 * Check whether the separate key cache entries
drivers/net/wireless/ath/ath9k/mac.h +0 -21
index 2633896..7c1a34d 100644
@@ -660,17 +660,6 @@ struct ath9k_11n_rate_series {
 	u32 RateFlags;
 };
 
-struct ath9k_keyval {
-	u8 kv_type;
-	u8 kv_pad;
-	u16 kv_len;
-	u8 kv_val[16]; /* TK */
-	u8 kv_mic[8]; /* Michael MIC key */
-	u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
-			 * supports both MIC keys in the same key cache entry;
-			 * in that case, kv_mic is the RX key) */
-};
-
 enum ath9k_key_type {
 	ATH9K_KEY_TYPE_CLEAR,
 	ATH9K_KEY_TYPE_WEP,
@@ -678,16 +667,6 @@ enum ath9k_key_type {
 	ATH9K_KEY_TYPE_TKIP,
 };
 
-enum ath9k_cipher {
-	ATH9K_CIPHER_WEP = 0,
-	ATH9K_CIPHER_AES_OCB = 1,
-	ATH9K_CIPHER_AES_CCM = 2,
-	ATH9K_CIPHER_CKIP = 3,
-	ATH9K_CIPHER_TKIP = 4,
-	ATH9K_CIPHER_CLR = 5,
-	ATH9K_CIPHER_MIC = 127
-};
-
 struct ath_hw;
 struct ath9k_channel;
 
drivers/net/wireless/ath/ath9k/main.c +2 -2
index 1165f90..de7c5a5 100644
@@ -1777,7 +1777,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
 
 	switch (cmd) {
 	case SET_KEY:
-		ret = ath9k_cmn_key_config(common, vif, sta, key);
+		ret = ath_key_config(common, vif, sta, key);
 		if (ret >= 0) {
 			key->hw_key_idx = ret;
 			/* push IV and Michael MIC generation to stack */
@@ -1791,7 +1791,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
 		}
 		break;
 	case DISABLE_KEY:
-		ath9k_cmn_key_delete(common, key);
+		ath_key_delete(common, key);
 		break;
 	default:
 		ret = -EINVAL;
drivers/net/wireless/ath/ath9k/phy.h +0 -3
index e724c2c..17969af 100644
@@ -45,9 +45,6 @@
 		}							\
 	} while (0)
 
-#define ATH9K_IS_MIC_ENABLED(ah)					\
-	((ah)->sta_id1_defaults & AR_STA_ID1_CRPT_MIC_ENABLE)
-
 #define ANTSWAP_AB 0x0001
 #define REDUCE_CHAIN_0 0x00000050
 #define REDUCE_CHAIN_1 0x00000051
#16 lore raw

PATCH 8/8 ath9k: Use common crypt capabilities flags

In reply to Bruno Randolf

Use common crypt capabilities flags from common ath and remove corresponding ath9k HW capabilities flags.

---
 drivers/net/wireless/ath/ath9k/hw.c |   12 +++++------
 drivers/net/wireless/ath/ath9k/hw.h |   40 +++++++++++++++--------------------
 2 files changed, 23 insertions(+), 29 deletions(-)
drivers/net/wireless/ath/ath9k/hw.c +6 -6
index 14fb082..b126f2e 100644
@@ -1864,13 +1864,13 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
 	pCap->low_5ghz_chan = 4920;
 	pCap->high_5ghz_chan = 6100;
 
-	pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
-	pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
-	pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
+	common->crypt_caps &= ~ATH_CRYPT_CAP_CIPHER_CKIP;
+	common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_TKIP;
+	common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
 
-	pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
-	pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
-	pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
+	common->crypt_caps &= ~ATH_CRYPT_CAP_MIC_CKIP;
+	common->crypt_caps |= ATH_CRYPT_CAP_MIC_TKIP;
+	common->crypt_caps |= ATH_CRYPT_CAP_MIC_AESCCM;
 
 	if (ah->config.ht_enable)
 		pCap->hw_caps |= ATH9K_HW_CAP_HT;
drivers/net/wireless/ath/ath9k/hw.h +17 -23
index 1bee964..2a8ef09 100644
@@ -181,29 +181,23 @@ enum wireless_mode {
 };
 
 enum ath9k_hw_caps {
-	ATH9K_HW_CAP_MIC_AESCCM                 = BIT(0),
-	ATH9K_HW_CAP_MIC_CKIP                   = BIT(1),
-	ATH9K_HW_CAP_MIC_TKIP                   = BIT(2),
-	ATH9K_HW_CAP_CIPHER_AESCCM              = BIT(3),
-	ATH9K_HW_CAP_CIPHER_CKIP                = BIT(4),
-	ATH9K_HW_CAP_CIPHER_TKIP                = BIT(5),
-	ATH9K_HW_CAP_VEOL                       = BIT(6),
-	ATH9K_HW_CAP_BSSIDMASK                  = BIT(7),
-	ATH9K_HW_CAP_MCAST_KEYSEARCH            = BIT(8),
-	ATH9K_HW_CAP_HT                         = BIT(9),
-	ATH9K_HW_CAP_GTT                        = BIT(10),
-	ATH9K_HW_CAP_FASTCC                     = BIT(11),
-	ATH9K_HW_CAP_RFSILENT                   = BIT(12),
-	ATH9K_HW_CAP_CST                        = BIT(13),
-	ATH9K_HW_CAP_ENHANCEDPM                 = BIT(14),
-	ATH9K_HW_CAP_AUTOSLEEP                  = BIT(15),
-	ATH9K_HW_CAP_4KB_SPLITTRANS             = BIT(16),
-	ATH9K_HW_CAP_EDMA			= BIT(17),
-	ATH9K_HW_CAP_RAC_SUPPORTED		= BIT(18),
-	ATH9K_HW_CAP_LDPC			= BIT(19),
-	ATH9K_HW_CAP_FASTCLOCK			= BIT(20),
-	ATH9K_HW_CAP_SGI_20			= BIT(21),
-	ATH9K_HW_CAP_PAPRD			= BIT(22),
+	ATH9K_HW_CAP_VEOL                       = BIT(0),
+	ATH9K_HW_CAP_BSSIDMASK                  = BIT(1),
+	ATH9K_HW_CAP_MCAST_KEYSEARCH            = BIT(2),
+	ATH9K_HW_CAP_HT                         = BIT(3),
+	ATH9K_HW_CAP_GTT                        = BIT(4),
+	ATH9K_HW_CAP_FASTCC                     = BIT(5),
+	ATH9K_HW_CAP_RFSILENT                   = BIT(6),
+	ATH9K_HW_CAP_CST                        = BIT(7),
+	ATH9K_HW_CAP_ENHANCEDPM                 = BIT(8),
+	ATH9K_HW_CAP_AUTOSLEEP                  = BIT(9),
+	ATH9K_HW_CAP_4KB_SPLITTRANS             = BIT(10),
+	ATH9K_HW_CAP_EDMA			= BIT(11),
+	ATH9K_HW_CAP_RAC_SUPPORTED		= BIT(12),
+	ATH9K_HW_CAP_LDPC			= BIT(13),
+	ATH9K_HW_CAP_FASTCLOCK			= BIT(14),
+	ATH9K_HW_CAP_SGI_20			= BIT(15),
+	ATH9K_HW_CAP_PAPRD			= BIT(16),
 };
 
 struct ath9k_hw_capabilities {
#17 lore raw
In reply to Bruno Randolf
Quoted 3 lines · Bruno Randolf

The following series moves the key cache management functions from ath9k to the common ath/key.c so we can also use them from ath5k. Both ath5k and ath9k are changed to use the common key functions.

Nice, I always wanted us to do this :) ... looks good.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com