aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <lrodriguez@atheros.com>2009-11-04 20:21:01 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-11 17:09:09 -0500
commit7e86c1048a9f5f1e157daf28411f3526f0b9f7b6 (patch)
tree35ad3decc5ac70d0cda31a003d1c0719b9e61281
parent1e875e9f16e3138d0e23cbf806a6d9520b622db2 (diff)
ath9k: move driver keymap, keymax and splitmic to common
This will make sharing code easier between ath9k and ath9k_htc. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/ath/ath.h14
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h13
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c136
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c2
4 files changed, 85 insertions, 80 deletions
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index 4af13628bafe..9e05648356fe 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -21,6 +21,16 @@
21#include <linux/if_ether.h> 21#include <linux/if_ether.h>
22#include <net/mac80211.h> 22#include <net/mac80211.h>
23 23
24/*
25 * The key cache is used for h/w cipher state and also for
26 * tracking station state such as the current tx antenna.
27 * We also setup a mapping table between key cache slot indices
28 * and station state to short-circuit node lookups on rx.
29 * Different parts have different size key caches. We handle
30 * up to ATH_KEYMAX entries (could dynamically allocate state).
31 */
32#define ATH_KEYMAX 128 /* max key cache size we handle */
33
24static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 34static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
25 35
26struct ath_ani { 36struct ath_ani {
@@ -89,6 +99,10 @@ struct ath_common {
89 99
90 u32 rx_bufsize; 100 u32 rx_bufsize;
91 101
102 u32 keymax;
103 DECLARE_BITMAP(keymap, ATH_KEYMAX);
104 u8 splitmic;
105
92 struct ath_regulatory regulatory; 106 struct ath_regulatory regulatory;
93 const struct ath_ops *ops; 107 const struct ath_ops *ops;
94 const struct ath_bus_ops *bus_ops; 108 const struct ath_bus_ops *bus_ops;
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 377b0eac5e4c..88969cbae132 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -492,16 +492,6 @@ struct ath_led {
492#define ATH_CHAN_MAX 255 492#define ATH_CHAN_MAX 255
493#define IEEE80211_WEP_NKID 4 /* number of key ids */ 493#define IEEE80211_WEP_NKID 4 /* number of key ids */
494 494
495/*
496 * The key cache is used for h/w cipher state and also for
497 * tracking station state such as the current tx antenna.
498 * We also setup a mapping table between key cache slot indices
499 * and station state to short-circuit node lookups on rx.
500 * Different parts have different size key caches. We handle
501 * up to ATH_KEYMAX entries (could dynamically allocate state).
502 */
503#define ATH_KEYMAX 128 /* max key cache size we handle */
504
505#define ATH_TXPOWER_MAX 100 /* .5 dBm units */ 495#define ATH_TXPOWER_MAX 100 /* .5 dBm units */
506#define ATH_RSSI_DUMMY_MARKER 0x127 496#define ATH_RSSI_DUMMY_MARKER 0x127
507#define ATH_RATE_DUMMY_MARKER 0 497#define ATH_RATE_DUMMY_MARKER 0
@@ -562,9 +552,6 @@ struct ath_softc {
562 u16 curtxpow; 552 u16 curtxpow;
563 u8 nbcnvifs; 553 u8 nbcnvifs;
564 u16 nvifs; 554 u16 nvifs;
565 u32 keymax;
566 DECLARE_BITMAP(keymap, ATH_KEYMAX);
567 u8 splitmic;
568 bool ps_enabled; 555 bool ps_enabled;
569 unsigned long ps_usecount; 556 unsigned long ps_usecount;
570 enum ath9k_int imask; 557 enum ath9k_int imask;
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 01ac8974eb07..3c02b977a613 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -733,10 +733,11 @@ static u32 ath_get_extchanmode(struct ath_softc *sc,
733 return chanmode; 733 return chanmode;
734} 734}
735 735
736static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key, 736static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
737 struct ath9k_keyval *hk, const u8 *addr, 737 struct ath9k_keyval *hk, const u8 *addr,
738 bool authenticator) 738 bool authenticator)
739{ 739{
740 struct ath_hw *ah = common->ah;
740 const u8 *key_rxmic; 741 const u8 *key_rxmic;
741 const u8 *key_txmic; 742 const u8 *key_txmic;
742 743
@@ -756,42 +757,42 @@ static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
756 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); 757 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
757 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic)); 758 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
758 } 759 }
759 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr); 760 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
760 } 761 }
761 if (!sc->splitmic) { 762 if (!common->splitmic) {
762 /* TX and RX keys share the same key cache entry. */ 763 /* TX and RX keys share the same key cache entry. */
763 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); 764 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
764 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic)); 765 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
765 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr); 766 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
766 } 767 }
767 768
768 /* Separate key cache entries for TX and RX */ 769 /* Separate key cache entries for TX and RX */
769 770
770 /* TX key goes at first index, RX key at +32. */ 771 /* TX key goes at first index, RX key at +32. */
771 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic)); 772 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
772 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) { 773 if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
773 /* TX MIC entry failed. No need to proceed further */ 774 /* TX MIC entry failed. No need to proceed further */
774 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, 775 ath_print(common, ATH_DBG_FATAL,
775 "Setting TX MIC Key Failed\n"); 776 "Setting TX MIC Key Failed\n");
776 return 0; 777 return 0;
777 } 778 }
778 779
779 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); 780 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
780 /* XXX delete tx key on failure? */ 781 /* XXX delete tx key on failure? */
781 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr); 782 return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
782} 783}
783 784
784static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc) 785static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
785{ 786{
786 int i; 787 int i;
787 788
788 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) { 789 for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
789 if (test_bit(i, sc->keymap) || 790 if (test_bit(i, common->keymap) ||
790 test_bit(i + 64, sc->keymap)) 791 test_bit(i + 64, common->keymap))
791 continue; /* At least one part of TKIP key allocated */ 792 continue; /* At least one part of TKIP key allocated */
792 if (sc->splitmic && 793 if (common->splitmic &&
793 (test_bit(i + 32, sc->keymap) || 794 (test_bit(i + 32, common->keymap) ||
794 test_bit(i + 64 + 32, sc->keymap))) 795 test_bit(i + 64 + 32, common->keymap)))
795 continue; /* At least one part of TKIP key allocated */ 796 continue; /* At least one part of TKIP key allocated */
796 797
797 /* Found a free slot for a TKIP key */ 798 /* Found a free slot for a TKIP key */
@@ -800,60 +801,60 @@ static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
800 return -1; 801 return -1;
801} 802}
802 803
803static int ath_reserve_key_cache_slot(struct ath_softc *sc) 804static int ath_reserve_key_cache_slot(struct ath_common *common)
804{ 805{
805 int i; 806 int i;
806 807
807 /* First, try to find slots that would not be available for TKIP. */ 808 /* First, try to find slots that would not be available for TKIP. */
808 if (sc->splitmic) { 809 if (common->splitmic) {
809 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) { 810 for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
810 if (!test_bit(i, sc->keymap) && 811 if (!test_bit(i, common->keymap) &&
811 (test_bit(i + 32, sc->keymap) || 812 (test_bit(i + 32, common->keymap) ||
812 test_bit(i + 64, sc->keymap) || 813 test_bit(i + 64, common->keymap) ||
813 test_bit(i + 64 + 32, sc->keymap))) 814 test_bit(i + 64 + 32, common->keymap)))
814 return i; 815 return i;
815 if (!test_bit(i + 32, sc->keymap) && 816 if (!test_bit(i + 32, common->keymap) &&
816 (test_bit(i, sc->keymap) || 817 (test_bit(i, common->keymap) ||
817 test_bit(i + 64, sc->keymap) || 818 test_bit(i + 64, common->keymap) ||
818 test_bit(i + 64 + 32, sc->keymap))) 819 test_bit(i + 64 + 32, common->keymap)))
819 return i + 32; 820 return i + 32;
820 if (!test_bit(i + 64, sc->keymap) && 821 if (!test_bit(i + 64, common->keymap) &&
821 (test_bit(i , sc->keymap) || 822 (test_bit(i , common->keymap) ||
822 test_bit(i + 32, sc->keymap) || 823 test_bit(i + 32, common->keymap) ||
823 test_bit(i + 64 + 32, sc->keymap))) 824 test_bit(i + 64 + 32, common->keymap)))
824 return i + 64; 825 return i + 64;
825 if (!test_bit(i + 64 + 32, sc->keymap) && 826 if (!test_bit(i + 64 + 32, common->keymap) &&
826 (test_bit(i, sc->keymap) || 827 (test_bit(i, common->keymap) ||
827 test_bit(i + 32, sc->keymap) || 828 test_bit(i + 32, common->keymap) ||
828 test_bit(i + 64, sc->keymap))) 829 test_bit(i + 64, common->keymap)))
829 return i + 64 + 32; 830 return i + 64 + 32;
830 } 831 }
831 } else { 832 } else {
832 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) { 833 for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
833 if (!test_bit(i, sc->keymap) && 834 if (!test_bit(i, common->keymap) &&
834 test_bit(i + 64, sc->keymap)) 835 test_bit(i + 64, common->keymap))
835 return i; 836 return i;
836 if (test_bit(i, sc->keymap) && 837 if (test_bit(i, common->keymap) &&
837 !test_bit(i + 64, sc->keymap)) 838 !test_bit(i + 64, common->keymap))
838 return i + 64; 839 return i + 64;
839 } 840 }
840 } 841 }
841 842
842 /* No partially used TKIP slots, pick any available slot */ 843 /* No partially used TKIP slots, pick any available slot */
843 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) { 844 for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
844 /* Do not allow slots that could be needed for TKIP group keys 845 /* Do not allow slots that could be needed for TKIP group keys
845 * to be used. This limitation could be removed if we know that 846 * to be used. This limitation could be removed if we know that
846 * TKIP will not be used. */ 847 * TKIP will not be used. */
847 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID) 848 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
848 continue; 849 continue;
849 if (sc->splitmic) { 850 if (common->splitmic) {
850 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID) 851 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
851 continue; 852 continue;
852 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID) 853 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
853 continue; 854 continue;
854 } 855 }
855 856
856 if (!test_bit(i, sc->keymap)) 857 if (!test_bit(i, common->keymap))
857 return i; /* Found a free slot for a key */ 858 return i; /* Found a free slot for a key */
858 } 859 }
859 860
@@ -861,11 +862,12 @@ static int ath_reserve_key_cache_slot(struct ath_softc *sc)
861 return -1; 862 return -1;
862} 863}
863 864
864static int ath_key_config(struct ath_softc *sc, 865static int ath_key_config(struct ath_common *common,
865 struct ieee80211_vif *vif, 866 struct ieee80211_vif *vif,
866 struct ieee80211_sta *sta, 867 struct ieee80211_sta *sta,
867 struct ieee80211_key_conf *key) 868 struct ieee80211_key_conf *key)
868{ 869{
870 struct ath_hw *ah = common->ah;
869 struct ath9k_keyval hk; 871 struct ath9k_keyval hk;
870 const u8 *mac = NULL; 872 const u8 *mac = NULL;
871 int ret = 0; 873 int ret = 0;
@@ -911,48 +913,50 @@ static int ath_key_config(struct ath_softc *sc,
911 mac = sta->addr; 913 mac = sta->addr;
912 914
913 if (key->alg == ALG_TKIP) 915 if (key->alg == ALG_TKIP)
914 idx = ath_reserve_key_cache_slot_tkip(sc); 916 idx = ath_reserve_key_cache_slot_tkip(common);
915 else 917 else
916 idx = ath_reserve_key_cache_slot(sc); 918 idx = ath_reserve_key_cache_slot(common);
917 if (idx < 0) 919 if (idx < 0)
918 return -ENOSPC; /* no free key cache entries */ 920 return -ENOSPC; /* no free key cache entries */
919 } 921 }
920 922
921 if (key->alg == ALG_TKIP) 923 if (key->alg == ALG_TKIP)
922 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac, 924 ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
923 vif->type == NL80211_IFTYPE_AP); 925 vif->type == NL80211_IFTYPE_AP);
924 else 926 else
925 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac); 927 ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
926 928
927 if (!ret) 929 if (!ret)
928 return -EIO; 930 return -EIO;
929 931
930 set_bit(idx, sc->keymap); 932 set_bit(idx, common->keymap);
931 if (key->alg == ALG_TKIP) { 933 if (key->alg == ALG_TKIP) {
932 set_bit(idx + 64, sc->keymap); 934 set_bit(idx + 64, common->keymap);
933 if (sc->splitmic) { 935 if (common->splitmic) {
934 set_bit(idx + 32, sc->keymap); 936 set_bit(idx + 32, common->keymap);
935 set_bit(idx + 64 + 32, sc->keymap); 937 set_bit(idx + 64 + 32, common->keymap);
936 } 938 }
937 } 939 }
938 940
939 return idx; 941 return idx;
940} 942}
941 943
942static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key) 944static void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
943{ 945{
944 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx); 946 struct ath_hw *ah = common->ah;
947
948 ath9k_hw_keyreset(ah, key->hw_key_idx);
945 if (key->hw_key_idx < IEEE80211_WEP_NKID) 949 if (key->hw_key_idx < IEEE80211_WEP_NKID)
946 return; 950 return;
947 951
948 clear_bit(key->hw_key_idx, sc->keymap); 952 clear_bit(key->hw_key_idx, common->keymap);
949 if (key->alg != ALG_TKIP) 953 if (key->alg != ALG_TKIP)
950 return; 954 return;
951 955
952 clear_bit(key->hw_key_idx + 64, sc->keymap); 956 clear_bit(key->hw_key_idx + 64, common->keymap);
953 if (sc->splitmic) { 957 if (common->splitmic) {
954 clear_bit(key->hw_key_idx + 32, sc->keymap); 958 clear_bit(key->hw_key_idx + 32, common->keymap);
955 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap); 959 clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
956 } 960 }
957} 961}
958 962
@@ -1679,19 +1683,19 @@ static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
1679 } 1683 }
1680 1684
1681 /* Get the hardware key cache size. */ 1685 /* Get the hardware key cache size. */
1682 sc->keymax = ah->caps.keycache_size; 1686 common->keymax = ah->caps.keycache_size;
1683 if (sc->keymax > ATH_KEYMAX) { 1687 if (common->keymax > ATH_KEYMAX) {
1684 ath_print(common, ATH_DBG_ANY, 1688 ath_print(common, ATH_DBG_ANY,
1685 "Warning, using only %u entries in %u key cache\n", 1689 "Warning, using only %u entries in %u key cache\n",
1686 ATH_KEYMAX, sc->keymax); 1690 ATH_KEYMAX, common->keymax);
1687 sc->keymax = ATH_KEYMAX; 1691 common->keymax = ATH_KEYMAX;
1688 } 1692 }
1689 1693
1690 /* 1694 /*
1691 * Reset the key cache since some parts do not 1695 * Reset the key cache since some parts do not
1692 * reset the contents on initial power up. 1696 * reset the contents on initial power up.
1693 */ 1697 */
1694 for (i = 0; i < sc->keymax; i++) 1698 for (i = 0; i < common->keymax; i++)
1695 ath9k_hw_keyreset(ah, (u16) i); 1699 ath9k_hw_keyreset(ah, (u16) i);
1696 1700
1697 /* default to MONITOR mode */ 1701 /* default to MONITOR mode */
@@ -1788,7 +1792,7 @@ static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
1788 ATH9K_CIPHER_MIC, NULL) 1792 ATH9K_CIPHER_MIC, NULL)
1789 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT, 1793 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1790 0, NULL)) 1794 0, NULL))
1791 sc->splitmic = 1; 1795 common->splitmic = 1;
1792 1796
1793 /* turn on mcast key search if possible */ 1797 /* turn on mcast key search if possible */
1794 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL)) 1798 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
@@ -2917,7 +2921,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
2917 2921
2918 switch (cmd) { 2922 switch (cmd) {
2919 case SET_KEY: 2923 case SET_KEY:
2920 ret = ath_key_config(sc, vif, sta, key); 2924 ret = ath_key_config(common, vif, sta, key);
2921 if (ret >= 0) { 2925 if (ret >= 0) {
2922 key->hw_key_idx = ret; 2926 key->hw_key_idx = ret;
2923 /* push IV and Michael MIC generation to stack */ 2927 /* push IV and Michael MIC generation to stack */
@@ -2930,7 +2934,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
2930 } 2934 }
2931 break; 2935 break;
2932 case DISABLE_KEY: 2936 case DISABLE_KEY:
2933 ath_key_delete(sc, key); 2937 ath_key_delete(common, key);
2934 break; 2938 break;
2935 default: 2939 default:
2936 ret = -EINVAL; 2940 ret = -EINVAL;
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index c4a8663af3ff..3abefb580a47 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -856,7 +856,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
856 && !decrypt_error && skb->len >= hdrlen + 4) { 856 && !decrypt_error && skb->len >= hdrlen + 4) {
857 keyix = skb->data[hdrlen + 3] >> 6; 857 keyix = skb->data[hdrlen + 3] >> 6;
858 858
859 if (test_bit(keyix, sc->keymap)) 859 if (test_bit(keyix, common->keymap))
860 rxs->flag |= RX_FLAG_DECRYPTED; 860 rxs->flag |= RX_FLAG_DECRYPTED;
861 } 861 }
862 if (ah->sw_mgmt_crypto && 862 if (ah->sw_mgmt_crypto &&