| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ath.c,v 1.102.4.1 2009/08/07 06:43:27 snj Exp $ */ | | 1 | /* $NetBSD: ath.c,v 1.102.4.2 2009/08/07 06:48:09 snj Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting | | 4 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer, | | 11 | * notice, this list of conditions and the following disclaimer, |
12 | * without modification. | | 12 | * without modification. |
13 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | | 13 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
14 | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any | | 14 | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any |
| @@ -31,27 +31,27 @@ | | | @@ -31,27 +31,27 @@ |
31 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 31 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | | 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
34 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 34 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
36 | * THE POSSIBILITY OF SUCH DAMAGES. | | 36 | * THE POSSIBILITY OF SUCH DAMAGES. |
37 | */ | | 37 | */ |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | #ifdef __FreeBSD__ | | 40 | #ifdef __FreeBSD__ |
41 | __FBSDID("$FreeBSD: src/sys/dev/ath/if_ath.c,v 1.104 2005/09/16 10:09:23 ru Exp $"); | | 41 | __FBSDID("$FreeBSD: src/sys/dev/ath/if_ath.c,v 1.104 2005/09/16 10:09:23 ru Exp $"); |
42 | #endif | | 42 | #endif |
43 | #ifdef __NetBSD__ | | 43 | #ifdef __NetBSD__ |
44 | __KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.102.4.1 2009/08/07 06:43:27 snj Exp $"); | | 44 | __KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.102.4.2 2009/08/07 06:48:09 snj Exp $"); |
45 | #endif | | 45 | #endif |
46 | | | 46 | |
47 | /* | | 47 | /* |
48 | * Driver for the Atheros Wireless LAN controller. | | 48 | * Driver for the Atheros Wireless LAN controller. |
49 | * | | 49 | * |
50 | * This software is derived from work of Atsushi Onoe; his contribution | | 50 | * This software is derived from work of Atsushi Onoe; his contribution |
51 | * is greatly appreciated. | | 51 | * is greatly appreciated. |
52 | */ | | 52 | */ |
53 | | | 53 | |
54 | #include "opt_inet.h" | | 54 | #include "opt_inet.h" |
55 | | | 55 | |
56 | #ifdef __NetBSD__ | | 56 | #ifdef __NetBSD__ |
57 | #include "bpfilter.h" | | 57 | #include "bpfilter.h" |
| @@ -510,48 +510,60 @@ ath_attach(u_int16_t devid, struct ath_s | | | @@ -510,48 +510,60 @@ ath_attach(u_int16_t devid, struct ath_s |
510 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_AES_OCB)) | | 510 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_AES_OCB)) |
511 | ic->ic_caps |= IEEE80211_C_AES; | | 511 | ic->ic_caps |= IEEE80211_C_AES; |
512 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_AES_CCM)) | | 512 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_AES_CCM)) |
513 | ic->ic_caps |= IEEE80211_C_AES_CCM; | | 513 | ic->ic_caps |= IEEE80211_C_AES_CCM; |
514 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_CKIP)) | | 514 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_CKIP)) |
515 | ic->ic_caps |= IEEE80211_C_CKIP; | | 515 | ic->ic_caps |= IEEE80211_C_CKIP; |
516 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_TKIP)) { | | 516 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_TKIP)) { |
517 | ic->ic_caps |= IEEE80211_C_TKIP; | | 517 | ic->ic_caps |= IEEE80211_C_TKIP; |
518 | /* | | 518 | /* |
519 | * Check if h/w does the MIC and/or whether the | | 519 | * Check if h/w does the MIC and/or whether the |
520 | * separate key cache entries are required to | | 520 | * separate key cache entries are required to |
521 | * handle both tx+rx MIC keys. | | 521 | * handle both tx+rx MIC keys. |
522 | */ | | 522 | */ |
523 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_MIC)) { | | 523 | if (ath_hal_ciphersupported(ah, HAL_CIPHER_MIC)) |
524 | ic->ic_caps |= IEEE80211_C_TKIPMIC; | | 524 | ic->ic_caps |= IEEE80211_C_TKIPMIC; |
525 | /* | | | |
526 | * Check if h/w does MIC correctly when | | | |
527 | * WMM is turned on. | | | |
528 | */ | | | |
529 | if (ath_hal_wmetkipmic(ah)) | | | |
530 | ic->ic_caps |= IEEE80211_C_WME_TKIPMIC; | | | |
531 | } | | | |
532 | | | 525 | |
533 | /* | | 526 | /* |
534 | * If the h/w supports storing tx+rx MIC keys | | 527 | * If the h/w supports storing tx+rx MIC keys |
535 | * in one cache slot automatically enable use. | | 528 | * in one cache slot automatically enable use. |
536 | */ | | 529 | */ |
537 | if (ath_hal_tkipsplit(ah) || | | 530 | if (ath_hal_hastkipsplit(ah) || |
538 | !ath_hal_settkipsplit(ah, AH_FALSE)) | | 531 | !ath_hal_settkipsplit(ah, AH_FALSE)) |
539 | sc->sc_splitmic = 1; | | 532 | sc->sc_splitmic = 1; |
| | | 533 | |
| | | 534 | /* |
| | | 535 | * If the h/w can do TKIP MIC together with WME then |
| | | 536 | * we use it; otherwise we force the MIC to be done |
| | | 537 | * in software by the net80211 layer. |
| | | 538 | */ |
| | | 539 | if (ath_hal_haswmetkipmic(ah)) |
| | | 540 | ic->ic_caps |= IEEE80211_C_WME_TKIPMIC; |
540 | } | | 541 | } |
541 | sc->sc_hasclrkey = ath_hal_ciphersupported(ah, HAL_CIPHER_CLR); | | 542 | sc->sc_hasclrkey = ath_hal_ciphersupported(ah, HAL_CIPHER_CLR); |
542 | #if 0 | | | |
543 | sc->sc_mcastkey = ath_hal_getmcastkeysearch(ah); | | 543 | sc->sc_mcastkey = ath_hal_getmcastkeysearch(ah); |
544 | #endif | | 544 | /* |
| | | 545 | * Mark key cache slots associated with global keys |
| | | 546 | * as in use. If we knew TKIP was not to be used we |
| | | 547 | * could leave the +32, +64, and +32+64 slots free. |
| | | 548 | */ |
| | | 549 | for (i = 0; i < IEEE80211_WEP_NKID; i++) { |
| | | 550 | setbit(sc->sc_keymap, i); |
| | | 551 | setbit(sc->sc_keymap, i+64); |
| | | 552 | if (sc->sc_splitmic) { |
| | | 553 | setbit(sc->sc_keymap, i+32); |
| | | 554 | setbit(sc->sc_keymap, i+32+64); |
| | | 555 | } |
| | | 556 | } |
545 | /* | | 557 | /* |
546 | * TPC support can be done either with a global cap or | | 558 | * TPC support can be done either with a global cap or |
547 | * per-packet support. The latter is not available on | | 559 | * per-packet support. The latter is not available on |
548 | * all parts. We're a bit pedantic here as all parts | | 560 | * all parts. We're a bit pedantic here as all parts |
549 | * support a global cap. | | 561 | * support a global cap. |
550 | */ | | 562 | */ |
551 | if (ath_hal_hastpc(ah) || ath_hal_hastxpowlimit(ah)) | | 563 | if (ath_hal_hastpc(ah) || ath_hal_hastxpowlimit(ah)) |
552 | ic->ic_caps |= IEEE80211_C_TXPMGT; | | 564 | ic->ic_caps |= IEEE80211_C_TXPMGT; |
553 | | | 565 | |
554 | /* | | 566 | /* |
555 | * Mark WME capability only if we have sufficient | | 567 | * Mark WME capability only if we have sufficient |
556 | * hardware queues to do proper priority scheduling. | | 568 | * hardware queues to do proper priority scheduling. |
557 | */ | | 569 | */ |
| @@ -938,69 +950,77 @@ ath_chan2flags(struct ieee80211com *ic, | | | @@ -938,69 +950,77 @@ ath_chan2flags(struct ieee80211com *ic, |
938 | KASSERT(modeflags[mode] != 0, ("mode %u undefined", mode)); | | 950 | KASSERT(modeflags[mode] != 0, ("mode %u undefined", mode)); |
939 | return modeflags[mode]; | | 951 | return modeflags[mode]; |
940 | #undef N | | 952 | #undef N |
941 | } | | 953 | } |
942 | | | 954 | |
943 | static int | | 955 | static int |
944 | ath_ifinit(struct ifnet *ifp) | | 956 | ath_ifinit(struct ifnet *ifp) |
945 | { | | 957 | { |
946 | struct ath_softc *sc = (struct ath_softc *)ifp->if_softc; | | 958 | struct ath_softc *sc = (struct ath_softc *)ifp->if_softc; |
947 | | | 959 | |
948 | return ath_init(sc); | | 960 | return ath_init(sc); |
949 | } | | 961 | } |
950 | | | 962 | |
| | | 963 | static void |
| | | 964 | ath_settkipmic(struct ath_softc *sc) |
| | | 965 | { |
| | | 966 | struct ieee80211com *ic = &sc->sc_ic; |
| | | 967 | struct ath_hal *ah = sc->sc_ah; |
| | | 968 | |
| | | 969 | if ((ic->ic_caps & IEEE80211_C_TKIP) && |
| | | 970 | !(ic->ic_caps & IEEE80211_C_WME_TKIPMIC)) { |
| | | 971 | if (ic->ic_flags & IEEE80211_F_WME) { |
| | | 972 | (void)ath_hal_settkipmic(ah, AH_FALSE); |
| | | 973 | ic->ic_caps &= ~IEEE80211_C_TKIPMIC; |
| | | 974 | } else { |
| | | 975 | (void)ath_hal_settkipmic(ah, AH_TRUE); |
| | | 976 | ic->ic_caps |= IEEE80211_C_TKIPMIC; |
| | | 977 | } |
| | | 978 | } |
| | | 979 | } |
| | | 980 | |
951 | static int | | 981 | static int |
952 | ath_init(struct ath_softc *sc) | | 982 | ath_init(struct ath_softc *sc) |
953 | { | | 983 | { |
954 | struct ifnet *ifp = &sc->sc_if; | | 984 | struct ifnet *ifp = &sc->sc_if; |
955 | struct ieee80211com *ic = &sc->sc_ic; | | 985 | struct ieee80211com *ic = &sc->sc_ic; |
956 | struct ath_hal *ah = sc->sc_ah; | | 986 | struct ath_hal *ah = sc->sc_ah; |
957 | HAL_STATUS status; | | 987 | HAL_STATUS status; |
958 | int error = 0; | | 988 | int error = 0; |
959 | | | 989 | |
960 | DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n", | | 990 | DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n", |
961 | __func__, ifp->if_flags); | | 991 | __func__, ifp->if_flags); |
962 | | | 992 | |
963 | if (device_is_active(sc->sc_dev)) { | | 993 | if (device_is_active(sc->sc_dev)) { |
964 | ATH_LOCK(sc); | | 994 | ATH_LOCK(sc); |
965 | } else if (!pmf_device_resume_self(sc->sc_dev)) | | 995 | } else if (!pmf_device_resume_self(sc->sc_dev)) |
966 | return ENXIO; | | 996 | return ENXIO; |
967 | else | | 997 | else |
968 | ATH_LOCK(sc); | | 998 | ATH_LOCK(sc); |
969 | | | 999 | |
970 | /* | | 1000 | /* |
971 | * Stop anything previously setup. This is safe | | 1001 | * Stop anything previously setup. This is safe |
972 | * whether this is the first time through or not. | | 1002 | * whether this is the first time through or not. |
973 | */ | | 1003 | */ |
974 | ath_stop_locked(ifp, 0); | | 1004 | ath_stop_locked(ifp, 0); |
975 | | | 1005 | |
976 | int dummy; /* XXX: gcc */ | | | |
977 | /* Whether we should enable h/w TKIP MIC */ | | | |
978 | if ((ic->ic_caps & IEEE80211_C_WME) && | | | |
979 | ((ic->ic_caps & IEEE80211_C_WME_TKIPMIC) || | | | |
980 | !(ic->ic_flags & IEEE80211_F_WME))) { | | | |
981 | dummy = ath_hal_settkipmic(ah, AH_TRUE); | | | |
982 | } else { | | | |
983 | dummy = ath_hal_settkipmic(ah, AH_FALSE); | | | |
984 | } | | | |
985 | | | | |
986 | | | | |
987 | /* | | 1006 | /* |
988 | * The basic interface to setting the hardware in a good | | 1007 | * The basic interface to setting the hardware in a good |
989 | * state is ``reset''. On return the hardware is known to | | 1008 | * state is ``reset''. On return the hardware is known to |
990 | * be powered up and with interrupts disabled. This must | | 1009 | * be powered up and with interrupts disabled. This must |
991 | * be followed by initialization of the appropriate bits | | 1010 | * be followed by initialization of the appropriate bits |
992 | * and then setup of the interrupt mask. | | 1011 | * and then setup of the interrupt mask. |
993 | */ | | 1012 | */ |
| | | 1013 | ath_settkipmic(sc); |
994 | sc->sc_curchan.channel = ic->ic_curchan->ic_freq; | | 1014 | sc->sc_curchan.channel = ic->ic_curchan->ic_freq; |
995 | sc->sc_curchan.channelFlags = ath_chan2flags(ic, ic->ic_curchan); | | 1015 | sc->sc_curchan.channelFlags = ath_chan2flags(ic, ic->ic_curchan); |
996 | if (!ath_hal_reset(ah, ic->ic_opmode, &sc->sc_curchan, AH_FALSE, &status)) { | | 1016 | if (!ath_hal_reset(ah, ic->ic_opmode, &sc->sc_curchan, AH_FALSE, &status)) { |
997 | if_printf(ifp, "unable to reset hardware; hal status %u\n", | | 1017 | if_printf(ifp, "unable to reset hardware; hal status %u\n", |
998 | status); | | 1018 | status); |
999 | error = EIO; | | 1019 | error = EIO; |
1000 | goto done; | | 1020 | goto done; |
1001 | } | | 1021 | } |
1002 | | | 1022 | |
1003 | /* | | 1023 | /* |
1004 | * This is needed only to setup initial state | | 1024 | * This is needed only to setup initial state |
1005 | * but it's best done after a reset. | | 1025 | * but it's best done after a reset. |
1006 | */ | | 1026 | */ |
| @@ -1160,26 +1180,27 @@ ath_reset(struct ifnet *ifp) | | | @@ -1160,26 +1180,27 @@ ath_reset(struct ifnet *ifp) |
1160 | HAL_STATUS status; | | 1180 | HAL_STATUS status; |
1161 | | | 1181 | |
1162 | /* | | 1182 | /* |
1163 | * Convert to a HAL channel description with the flags | | 1183 | * Convert to a HAL channel description with the flags |
1164 | * constrained to reflect the current operating mode. | | 1184 | * constrained to reflect the current operating mode. |
1165 | */ | | 1185 | */ |
1166 | c = ic->ic_curchan; | | 1186 | c = ic->ic_curchan; |
1167 | sc->sc_curchan.channel = c->ic_freq; | | 1187 | sc->sc_curchan.channel = c->ic_freq; |
1168 | sc->sc_curchan.channelFlags = ath_chan2flags(ic, c); | | 1188 | sc->sc_curchan.channelFlags = ath_chan2flags(ic, c); |
1169 | | | 1189 | |
1170 | ath_hal_intrset(ah, 0); /* disable interrupts */ | | 1190 | ath_hal_intrset(ah, 0); /* disable interrupts */ |
1171 | ath_draintxq(sc); /* stop xmit side */ | | 1191 | ath_draintxq(sc); /* stop xmit side */ |
1172 | ath_stoprecv(sc); /* stop recv side */ | | 1192 | ath_stoprecv(sc); /* stop recv side */ |
| | | 1193 | ath_settkipmic(sc); /* configure TKIP MIC handling */ |
1173 | /* NB: indicate channel change so we do a full reset */ | | 1194 | /* NB: indicate channel change so we do a full reset */ |
1174 | if (!ath_hal_reset(ah, ic->ic_opmode, &sc->sc_curchan, AH_TRUE, &status)) | | 1195 | if (!ath_hal_reset(ah, ic->ic_opmode, &sc->sc_curchan, AH_TRUE, &status)) |
1175 | if_printf(ifp, "%s: unable to reset hardware; hal status %u\n", | | 1196 | if_printf(ifp, "%s: unable to reset hardware; hal status %u\n", |
1176 | __func__, status); | | 1197 | __func__, status); |
1177 | ath_update_txpow(sc); /* update tx power state */ | | 1198 | ath_update_txpow(sc); /* update tx power state */ |
1178 | ath_restore_diversity(sc); | | 1199 | ath_restore_diversity(sc); |
1179 | sc->sc_calinterval = 1; | | 1200 | sc->sc_calinterval = 1; |
1180 | sc->sc_caltries = 0; | | 1201 | sc->sc_caltries = 0; |
1181 | if (ath_startrecv(sc) != 0) /* restart recv */ | | 1202 | if (ath_startrecv(sc) != 0) /* restart recv */ |
1182 | if_printf(ifp, "%s: unable to start recv logic\n", __func__); | | 1203 | if_printf(ifp, "%s: unable to start recv logic\n", __func__); |
1183 | /* | | 1204 | /* |
1184 | * We may be doing a reset in response to an ioctl | | 1205 | * We may be doing a reset in response to an ioctl |
1185 | * that changes the channel so update any state that | | 1206 | * that changes the channel so update any state that |
| @@ -1502,41 +1523,45 @@ ath_keyset_tkip(struct ath_softc *sc, co | | | @@ -1502,41 +1523,45 @@ ath_keyset_tkip(struct ath_softc *sc, co |
1502 | | | 1523 | |
1503 | memcpy(hk->kv_mic, k->wk_rxmic, sizeof(hk->kv_mic)); | | 1524 | memcpy(hk->kv_mic, k->wk_rxmic, sizeof(hk->kv_mic)); |
1504 | KEYPRINTF(sc, k->wk_keyix+32, hk, mac); | | 1525 | KEYPRINTF(sc, k->wk_keyix+32, hk, mac); |
1505 | /* XXX delete tx key on failure? */ | | 1526 | /* XXX delete tx key on failure? */ |
1506 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix+32), | | 1527 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix+32), |
1507 | hk, mac); | | 1528 | hk, mac); |
1508 | } else { | | 1529 | } else { |
1509 | /* | | 1530 | /* |
1510 | * Room for both TX+RX MIC keys in one key cache | | 1531 | * Room for both TX+RX MIC keys in one key cache |
1511 | * slot, just set key at the first index; the HAL | | 1532 | * slot, just set key at the first index; the HAL |
1512 | * will handle the reset. | | 1533 | * will handle the reset. |
1513 | */ | | 1534 | */ |
1514 | memcpy(hk->kv_mic, k->wk_rxmic, sizeof(hk->kv_mic)); | | 1535 | memcpy(hk->kv_mic, k->wk_rxmic, sizeof(hk->kv_mic)); |
1515 | #if HAL_ABI_VERSION > 0x06052200 | | | |
1516 | memcpy(hk->kv_txmic, k->wk_txmic, sizeof(hk->kv_txmic)); | | 1536 | memcpy(hk->kv_txmic, k->wk_txmic, sizeof(hk->kv_txmic)); |
1517 | #endif | | | |
1518 | KEYPRINTF(sc, k->wk_keyix, hk, mac); | | 1537 | KEYPRINTF(sc, k->wk_keyix, hk, mac); |
1519 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), hk, mac); | | 1538 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), hk, mac); |
1520 | } | | 1539 | } |
1521 | } else if (k->wk_flags & IEEE80211_KEY_XR) { | | 1540 | } else if (k->wk_flags & IEEE80211_KEY_XMIT) { |
1522 | /* | | 1541 | if (sc->sc_splitmic) { |
1523 | * TX/RX key goes at first index. | | 1542 | /* |
1524 | * The hal handles the MIC keys are index+64. | | 1543 | * NB: must pass MIC key in expected location when |
1525 | */ | | 1544 | * the keycache only holds one MIC key per entry. |
1526 | memcpy(hk->kv_mic, k->wk_flags & IEEE80211_KEY_XMIT ? | | 1545 | */ |
1527 | k->wk_txmic : k->wk_rxmic, sizeof(hk->kv_mic)); | | 1546 | memcpy(hk->kv_mic, k->wk_txmic, sizeof(hk->kv_txmic)); |
| | | 1547 | } else |
| | | 1548 | memcpy(hk->kv_txmic, k->wk_txmic, sizeof(hk->kv_txmic)); |
1528 | KEYPRINTF(sc, k->wk_keyix, hk, mac); | | 1549 | KEYPRINTF(sc, k->wk_keyix, hk, mac); |
1529 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), hk, mac); | | 1550 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), hk, mac); |
| | | 1551 | } else if (k->wk_flags & IEEE80211_KEY_RECV) { |
| | | 1552 | memcpy(hk->kv_mic, k->wk_rxmic, sizeof(hk->kv_mic)); |
| | | 1553 | KEYPRINTF(sc, k->wk_keyix, hk, mac); |
| | | 1554 | return ath_hal_keyset(ah, k->wk_keyix, hk, mac); |
1530 | } | | 1555 | } |
1531 | return 0; | | 1556 | return 0; |
1532 | #undef IEEE80211_KEY_XR | | 1557 | #undef IEEE80211_KEY_XR |
1533 | } | | 1558 | } |
1534 | | | 1559 | |
1535 | /* | | 1560 | /* |
1536 | * Set a net80211 key into the hardware. This handles the | | 1561 | * Set a net80211 key into the hardware. This handles the |
1537 | * potential distribution of key state to multiple key | | 1562 | * potential distribution of key state to multiple key |
1538 | * cache slots for TKIP with hardware MIC support. | | 1563 | * cache slots for TKIP with hardware MIC support. |
1539 | */ | | 1564 | */ |
1540 | static int | | 1565 | static int |
1541 | ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, | | 1566 | ath_keyset(struct ath_softc *sc, const struct ieee80211_key *k, |
1542 | const u_int8_t mac0[IEEE80211_ADDR_LEN], | | 1567 | const u_int8_t mac0[IEEE80211_ADDR_LEN], |
| @@ -1576,27 +1601,27 @@ ath_keyset(struct ath_softc *sc, const s | | | @@ -1576,27 +1601,27 @@ ath_keyset(struct ath_softc *sc, const s |
1576 | if ((k->wk_flags & IEEE80211_KEY_GROUP) && sc->sc_mcastkey) { | | 1601 | if ((k->wk_flags & IEEE80211_KEY_GROUP) && sc->sc_mcastkey) { |
1577 | /* | | 1602 | /* |
1578 | * Group keys on hardware that supports multicast frame | | 1603 | * Group keys on hardware that supports multicast frame |
1579 | * key search use a mac that is the sender's address with | | 1604 | * key search use a mac that is the sender's address with |
1580 | * the high bit set instead of the app-specified address. | | 1605 | * the high bit set instead of the app-specified address. |
1581 | */ | | 1606 | */ |
1582 | IEEE80211_ADDR_COPY(gmac, bss->ni_macaddr); | | 1607 | IEEE80211_ADDR_COPY(gmac, bss->ni_macaddr); |
1583 | gmac[0] |= 0x80; | | 1608 | gmac[0] |= 0x80; |
1584 | mac = gmac; | | 1609 | mac = gmac; |
1585 | } else | | 1610 | } else |
1586 | mac = mac0; | | 1611 | mac = mac0; |
1587 | | | 1612 | |
1588 | if ((hk.kv_type == HAL_CIPHER_TKIP && | | 1613 | if ((hk.kv_type == HAL_CIPHER_TKIP && |
1589 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0) && sc->sc_splitmic) { | | 1614 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0)) { |
1590 | return ath_keyset_tkip(sc, k, &hk, mac); | | 1615 | return ath_keyset_tkip(sc, k, &hk, mac); |
1591 | } else { | | 1616 | } else { |
1592 | KEYPRINTF(sc, k->wk_keyix, &hk, mac); | | 1617 | KEYPRINTF(sc, k->wk_keyix, &hk, mac); |
1593 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), &hk, mac); | | 1618 | return ath_hal_keyset(ah, ATH_KEY(k->wk_keyix), &hk, mac); |
1594 | } | | 1619 | } |
1595 | #undef N | | 1620 | #undef N |
1596 | } | | 1621 | } |
1597 | | | 1622 | |
1598 | /* | | 1623 | /* |
1599 | * Allocate tx/rx key slots for TKIP. We allocate two slots for | | 1624 | * Allocate tx/rx key slots for TKIP. We allocate two slots for |
1600 | * each key, one for decrypt/encrypt and the other for the MIC. | | 1625 | * each key, one for decrypt/encrypt and the other for the MIC. |
1601 | */ | | 1626 | */ |
1602 | static u_int16_t | | 1627 | static u_int16_t |
| @@ -1641,26 +1666,74 @@ key_alloc_2pair(struct ath_softc *sc, | | | @@ -1641,26 +1666,74 @@ key_alloc_2pair(struct ath_softc *sc, |
1641 | __func__, keyix, keyix+64, | | 1666 | __func__, keyix, keyix+64, |
1642 | keyix+32, keyix+32+64); | | 1667 | keyix+32, keyix+32+64); |
1643 | *txkeyix = keyix; | | 1668 | *txkeyix = keyix; |
1644 | *rxkeyix = keyix+32; | | 1669 | *rxkeyix = keyix+32; |
1645 | return keyix; | | 1670 | return keyix; |
1646 | } | | 1671 | } |
1647 | } | | 1672 | } |
1648 | DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__); | | 1673 | DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__); |
1649 | return IEEE80211_KEYIX_NONE; | | 1674 | return IEEE80211_KEYIX_NONE; |
1650 | #undef N | | 1675 | #undef N |
1651 | } | | 1676 | } |
1652 | | | 1677 | |
1653 | /* | | 1678 | /* |
| | | 1679 | * Allocate tx/rx key slots for TKIP. We allocate two slots for |
| | | 1680 | * each key, one for decrypt/encrypt and the other for the MIC. |
| | | 1681 | */ |
| | | 1682 | static int |
| | | 1683 | key_alloc_pair(struct ath_softc *sc, ieee80211_keyix *txkeyix, |
| | | 1684 | ieee80211_keyix *rxkeyix) |
| | | 1685 | { |
| | | 1686 | #define N(a) (sizeof(a)/sizeof(a[0])) |
| | | 1687 | u_int i, keyix; |
| | | 1688 | |
| | | 1689 | KASSERT(!sc->sc_splitmic, ("key cache split")); |
| | | 1690 | /* XXX could optimize */ |
| | | 1691 | for (i = 0; i < N(sc->sc_keymap)/4; i++) { |
| | | 1692 | uint8_t b = sc->sc_keymap[i]; |
| | | 1693 | if (b != 0xff) { |
| | | 1694 | /* |
| | | 1695 | * One or more slots in this byte are free. |
| | | 1696 | */ |
| | | 1697 | keyix = i*NBBY; |
| | | 1698 | while (b & 1) { |
| | | 1699 | again: |
| | | 1700 | keyix++; |
| | | 1701 | b >>= 1; |
| | | 1702 | } |
| | | 1703 | if (isset(sc->sc_keymap, keyix+64)) { |
| | | 1704 | /* full pair unavailable */ |
| | | 1705 | /* XXX statistic */ |
| | | 1706 | if (keyix == (i+1)*NBBY) { |
| | | 1707 | /* no slots were appropriate, advance */ |
| | | 1708 | continue; |
| | | 1709 | } |
| | | 1710 | goto again; |
| | | 1711 | } |
| | | 1712 | setbit(sc->sc_keymap, keyix); |
| | | 1713 | setbit(sc->sc_keymap, keyix+64); |
| | | 1714 | DPRINTF(sc, ATH_DEBUG_KEYCACHE, |
| | | 1715 | "%s: key pair %u,%u\n", |
| | | 1716 | __func__, keyix, keyix+64); |
| | | 1717 | *txkeyix = *rxkeyix = keyix; |
| | | 1718 | return 1; |
| | | 1719 | } |
| | | 1720 | } |
| | | 1721 | DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__); |
| | | 1722 | return 0; |
| | | 1723 | #undef N |
| | | 1724 | } |
| | | 1725 | |
| | | 1726 | /* |
1654 | * Allocate a single key cache slot. | | 1727 | * Allocate a single key cache slot. |
1655 | */ | | 1728 | */ |
1656 | static int | | 1729 | static int |
1657 | key_alloc_single(struct ath_softc *sc, | | 1730 | key_alloc_single(struct ath_softc *sc, |
1658 | ieee80211_keyix *txkeyix, ieee80211_keyix *rxkeyix) | | 1731 | ieee80211_keyix *txkeyix, ieee80211_keyix *rxkeyix) |
1659 | { | | 1732 | { |
1660 | #define N(a) (sizeof(a)/sizeof(a[0])) | | 1733 | #define N(a) (sizeof(a)/sizeof(a[0])) |
1661 | u_int i, keyix; | | 1734 | u_int i, keyix; |
1662 | | | 1735 | |
1663 | /* XXX try i,i+32,i+64,i+32+64 to minimize key pair conflicts */ | | 1736 | /* XXX try i,i+32,i+64,i+32+64 to minimize key pair conflicts */ |
1664 | for (i = 0; i < N(sc->sc_keymap); i++) { | | 1737 | for (i = 0; i < N(sc->sc_keymap); i++) { |
1665 | u_int8_t b = sc->sc_keymap[i]; | | 1738 | u_int8_t b = sc->sc_keymap[i]; |
1666 | if (b != 0xff) { | | 1739 | if (b != 0xff) { |
| @@ -1725,28 +1798,31 @@ ath_key_alloc(struct ieee80211com *ic, c | | | @@ -1725,28 +1798,31 @@ ath_key_alloc(struct ieee80211com *ic, c |
1725 | } | | 1798 | } |
1726 | | | 1799 | |
1727 | /* | | 1800 | /* |
1728 | * We allocate two pair for TKIP when using the h/w to do | | 1801 | * We allocate two pair for TKIP when using the h/w to do |
1729 | * the MIC. For everything else, including software crypto, | | 1802 | * the MIC. For everything else, including software crypto, |
1730 | * we allocate a single entry. Note that s/w crypto requires | | 1803 | * we allocate a single entry. Note that s/w crypto requires |
1731 | * a pass-through slot on the 5211 and 5212. The 5210 does | | 1804 | * a pass-through slot on the 5211 and 5212. The 5210 does |
1732 | * not support pass-through cache entries and we map all | | 1805 | * not support pass-through cache entries and we map all |
1733 | * those requests to slot 0. | | 1806 | * those requests to slot 0. |
1734 | */ | | 1807 | */ |
1735 | if (k->wk_flags & IEEE80211_KEY_SWCRYPT) { | | 1808 | if (k->wk_flags & IEEE80211_KEY_SWCRYPT) { |
1736 | return key_alloc_single(sc, keyix, rxkeyix); | | 1809 | return key_alloc_single(sc, keyix, rxkeyix); |
1737 | } else if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_TKIP && | | 1810 | } else if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_TKIP && |
1738 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && sc->sc_splitmic) { | | 1811 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0) { |
1739 | return key_alloc_2pair(sc, keyix, rxkeyix); | | 1812 | if (sc->sc_splitmic) |
| | | 1813 | return key_alloc_2pair(sc, keyix, rxkeyix); |
| | | 1814 | else |
| | | 1815 | return key_alloc_pair(sc, keyix, rxkeyix); |
1740 | } else { | | 1816 | } else { |
1741 | return key_alloc_single(sc, keyix, rxkeyix); | | 1817 | return key_alloc_single(sc, keyix, rxkeyix); |
1742 | } | | 1818 | } |
1743 | } | | 1819 | } |
1744 | | | 1820 | |
1745 | /* | | 1821 | /* |
1746 | * Delete an entry in the key cache allocated by ath_key_alloc. | | 1822 | * Delete an entry in the key cache allocated by ath_key_alloc. |
1747 | */ | | 1823 | */ |
1748 | static int | | 1824 | static int |
1749 | ath_key_delete(struct ieee80211com *ic, const struct ieee80211_key *k) | | 1825 | ath_key_delete(struct ieee80211com *ic, const struct ieee80211_key *k) |
1750 | { | | 1826 | { |
1751 | struct ath_softc *sc = ic->ic_ifp->if_softc; | | 1827 | struct ath_softc *sc = ic->ic_ifp->if_softc; |
1752 | struct ath_hal *ah = sc->sc_ah; | | 1828 | struct ath_hal *ah = sc->sc_ah; |
| @@ -1764,31 +1840,33 @@ ath_key_delete(struct ieee80211com *ic, | | | @@ -1764,31 +1840,33 @@ ath_key_delete(struct ieee80211com *ic, |
1764 | /* | | 1840 | /* |
1765 | * Handle split tx/rx keying required for TKIP with h/w MIC. | | 1841 | * Handle split tx/rx keying required for TKIP with h/w MIC. |
1766 | */ | | 1842 | */ |
1767 | if (cip->ic_cipher == IEEE80211_CIPHER_TKIP && | | 1843 | if (cip->ic_cipher == IEEE80211_CIPHER_TKIP && |
1768 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && sc->sc_splitmic) | | 1844 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && sc->sc_splitmic) |
1769 | ath_hal_keyreset(ah, keyix+32); /* RX key */ | | 1845 | ath_hal_keyreset(ah, keyix+32); /* RX key */ |
1770 | if (keyix >= IEEE80211_WEP_NKID) { | | 1846 | if (keyix >= IEEE80211_WEP_NKID) { |
1771 | /* | | 1847 | /* |
1772 | * Don't touch keymap entries for global keys so | | 1848 | * Don't touch keymap entries for global keys so |
1773 | * they are never considered for dynamic allocation. | | 1849 | * they are never considered for dynamic allocation. |
1774 | */ | | 1850 | */ |
1775 | clrbit(sc->sc_keymap, keyix); | | 1851 | clrbit(sc->sc_keymap, keyix); |
1776 | if (cip->ic_cipher == IEEE80211_CIPHER_TKIP && | | 1852 | if (cip->ic_cipher == IEEE80211_CIPHER_TKIP && |
1777 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0 && | | 1853 | (k->wk_flags & IEEE80211_KEY_SWMIC) == 0) { |
1778 | sc->sc_splitmic) { | | | |
1779 | clrbit(sc->sc_keymap, keyix+64); /* TX key MIC */ | | 1854 | clrbit(sc->sc_keymap, keyix+64); /* TX key MIC */ |
1780 | clrbit(sc->sc_keymap, keyix+32); /* RX key */ | | 1855 | if (sc->sc_splitmic) { |
1781 | clrbit(sc->sc_keymap, keyix+32+64); /* RX key MIC */ | | 1856 | /* +32 for RX key, +32+64 for RX key MIC */ |
| | | 1857 | clrbit(sc->sc_keymap, keyix+32); |
| | | 1858 | clrbit(sc->sc_keymap, keyix+32+64); |
| | | 1859 | } |
1782 | } | | 1860 | } |
1783 | } | | 1861 | } |
1784 | return 1; | | 1862 | return 1; |
1785 | } | | 1863 | } |
1786 | | | 1864 | |
1787 | /* | | 1865 | /* |
1788 | * Set the key cache contents for the specified key. Key cache | | 1866 | * Set the key cache contents for the specified key. Key cache |
1789 | * slot(s) must already have been allocated by ath_key_alloc. | | 1867 | * slot(s) must already have been allocated by ath_key_alloc. |
1790 | */ | | 1868 | */ |
1791 | static int | | 1869 | static int |
1792 | ath_key_set(struct ieee80211com *ic, const struct ieee80211_key *k, | | 1870 | ath_key_set(struct ieee80211com *ic, const struct ieee80211_key *k, |
1793 | const u_int8_t mac[IEEE80211_ADDR_LEN]) | | 1871 | const u_int8_t mac[IEEE80211_ADDR_LEN]) |
1794 | { | | 1872 | { |
| @@ -2972,27 +3050,27 @@ ath_rx_proc(void *arg, int npending) | | | @@ -2972,27 +3050,27 @@ ath_rx_proc(void *arg, int npending) |
2972 | /* | | 3050 | /* |
2973 | * Must provide the virtual address of the current | | 3051 | * Must provide the virtual address of the current |
2974 | * descriptor, the physical address, and the virtual | | 3052 | * descriptor, the physical address, and the virtual |
2975 | * address of the next descriptor in the h/w chain. | | 3053 | * address of the next descriptor in the h/w chain. |
2976 | * This allows the HAL to look ahead to see if the | | 3054 | * This allows the HAL to look ahead to see if the |
2977 | * hardware is done with a descriptor by checking the | | 3055 | * hardware is done with a descriptor by checking the |
2978 | * done bit in the following descriptor and the address | | 3056 | * done bit in the following descriptor and the address |
2979 | * of the current descriptor the DMA engine is working | | 3057 | * of the current descriptor the DMA engine is working |
2980 | * on. All this is necessary because of our use of | | 3058 | * on. All this is necessary because of our use of |
2981 | * a self-linked list to avoid rx overruns. | | 3059 | * a self-linked list to avoid rx overruns. |
2982 | */ | | 3060 | */ |
2983 | status = ath_hal_rxprocdesc(ah, ds, | | 3061 | status = ath_hal_rxprocdesc(ah, ds, |
2984 | bf->bf_daddr, PA2DESC(sc, ds->ds_link), | | 3062 | bf->bf_daddr, PA2DESC(sc, ds->ds_link), |
2985 | tsf, &ds->ds_rxstat); | | 3063 | &ds->ds_rxstat); |
2986 | #ifdef AR_DEBUG | | 3064 | #ifdef AR_DEBUG |
2987 | if (sc->sc_debug & ATH_DEBUG_RECV_DESC) | | 3065 | if (sc->sc_debug & ATH_DEBUG_RECV_DESC) |
2988 | ath_printrxbuf(bf, status == HAL_OK); | | 3066 | ath_printrxbuf(bf, status == HAL_OK); |
2989 | #endif | | 3067 | #endif |
2990 | if (status == HAL_EINPROGRESS) | | 3068 | if (status == HAL_EINPROGRESS) |
2991 | break; | | 3069 | break; |
2992 | STAILQ_REMOVE_HEAD(&sc->sc_rxbuf, bf_list); | | 3070 | STAILQ_REMOVE_HEAD(&sc->sc_rxbuf, bf_list); |
2993 | if (ds->ds_rxstat.rs_more) { | | 3071 | if (ds->ds_rxstat.rs_more) { |
2994 | /* | | 3072 | /* |
2995 | * Frame spans multiple descriptors; this | | 3073 | * Frame spans multiple descriptors; this |
2996 | * cannot happen yet as we don't support | | 3074 | * cannot happen yet as we don't support |
2997 | * jumbograms. If not in monitor mode, | | 3075 | * jumbograms. If not in monitor mode, |
2998 | * discard the frame. | | 3076 | * discard the frame. |
| @@ -4291,27 +4369,27 @@ ath_stoprecv(struct ath_softc *sc) | | | @@ -4291,27 +4369,27 @@ ath_stoprecv(struct ath_softc *sc) |
4291 | ath_hal_setrxfilter(ah, 0); /* clear recv filter */ | | 4369 | ath_hal_setrxfilter(ah, 0); /* clear recv filter */ |
4292 | ath_hal_stopdmarecv(ah); /* disable DMA engine */ | | 4370 | ath_hal_stopdmarecv(ah); /* disable DMA engine */ |
4293 | DELAY(3000); /* 3ms is long enough for 1 frame */ | | 4371 | DELAY(3000); /* 3ms is long enough for 1 frame */ |
4294 | if (sc->sc_debug & (ATH_DEBUG_RESET | ATH_DEBUG_FATAL)) { | | 4372 | if (sc->sc_debug & (ATH_DEBUG_RESET | ATH_DEBUG_FATAL)) { |
4295 | struct ath_buf *bf; | | 4373 | struct ath_buf *bf; |
4296 | | | 4374 | |
4297 | printf("%s: rx queue %p, link %p\n", __func__, | | 4375 | printf("%s: rx queue %p, link %p\n", __func__, |
4298 | (void *)(uintptr_t) ath_hal_getrxbuf(ah), sc->sc_rxlink); | | 4376 | (void *)(uintptr_t) ath_hal_getrxbuf(ah), sc->sc_rxlink); |
4299 | STAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { | | 4377 | STAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { |
4300 | struct ath_desc *ds = bf->bf_desc; | | 4378 | struct ath_desc *ds = bf->bf_desc; |
4301 | tsf = ath_hal_gettsf64(sc->sc_ah); | | 4379 | tsf = ath_hal_gettsf64(sc->sc_ah); |
4302 | HAL_STATUS status = ath_hal_rxprocdesc(ah, ds, | | 4380 | HAL_STATUS status = ath_hal_rxprocdesc(ah, ds, |
4303 | bf->bf_daddr, PA2DESC(sc, ds->ds_link), | | 4381 | bf->bf_daddr, PA2DESC(sc, ds->ds_link), |
4304 | tsf, &ds->ds_rxstat); | | 4382 | &ds->ds_rxstat); |
4305 | if (status == HAL_OK || (sc->sc_debug & ATH_DEBUG_FATAL)) | | 4383 | if (status == HAL_OK || (sc->sc_debug & ATH_DEBUG_FATAL)) |
4306 | ath_printrxbuf(bf, status == HAL_OK); | | 4384 | ath_printrxbuf(bf, status == HAL_OK); |
4307 | } | | 4385 | } |
4308 | } | | 4386 | } |
4309 | sc->sc_rxlink = NULL; /* just in case */ | | 4387 | sc->sc_rxlink = NULL; /* just in case */ |
4310 | #undef PA2DESC | | 4388 | #undef PA2DESC |
4311 | } | | 4389 | } |
4312 | | | 4390 | |
4313 | /* | | 4391 | /* |
4314 | * Enable the receive h/w following a reset. | | 4392 | * Enable the receive h/w following a reset. |
4315 | */ | | 4393 | */ |
4316 | static int | | 4394 | static int |
4317 | ath_startrecv(struct ath_softc *sc) | | 4395 | ath_startrecv(struct ath_softc *sc) |